Multiple RTF controls each with its own bar

Multiple RTF controls each with its own bar

Postby hua » Wed Oct 12, 2022 2:07 am

How to code multiple RTF controls on a dialog with each having its own bar?

TIA

Image
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Multiple RTF controls each with its own bar

Postby cnavarro » Sun Oct 16, 2022 2:38 am

I don't know if I understood your problem correctly
Do you mean that you can customize the buttonbar of each RICHEDIT control?
Please put the code of the program in the image above to be able to work on it.
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Multiple RTF controls each with its own bar

Postby Antonio Linares » Sun Oct 16, 2022 6:38 am

Dear Hua,

If I properly understood you, you have to do the following:

1. use "RichEdi5.ch" instead of "RichEdit.ch"

2. Do the REDEFINEs this way:

REDEFINE RICHEDIT5 ::hoGets["edu_1"] VAR ::hGets["edu_1"] ID 301 OF ::oFolder:aDialogs[1] BARBUTTON

Please notice the use of RICHEDIT5 and BARBUTTON

3. Finally to keep visible the buttonbars all the time do this:
Code: Select all  Expand view
      ACTIVATE DIALOG ::oDlg CENTERED ;
          ON INIT ( o:hoTitles[ "edu_1" ]:AddText( 15, 20, "First",,,,, oFont3 ),;
                    o:hoGets["edu_1"]:oBar:Move( 0, 0 ), o:hoGets["edu_1"]:oBar:Show(), o:hoGets["edu_1"]:lBar := .F., .T. )

4. There is a problem in the Class as the ButtonBar can't be visible all the time or the user will overwrite the bar, so better don't use this:
o:hoGets["edu_1"]:oBar:Show(), o:hoGets["edu_1"]:lBar := .F.

5. You can hide the bar when the user types doing:
o:hoGets["edu_1"]:bKeyDown = { || o:hoGets["edu_1"]:oBar:Hide() }
to show the buttonbar again, the user must move the mouse over the top of the richedit
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Multiple RTF controls each with its own bar

Postby cnavarro » Sun Oct 16, 2022 3:49 pm

Thanks Antonio
When I implemented the TRichEdt5 class, and added the option to have a buttonbar included in the control, the idea was also to have the possibility that the user could define his own buttonbar.
To do this, it is simple:
1.- Add the DATA bBuildBar to the class
Code: Select all  Expand view

   DATA   bBuildBar
 

2.- Change in the New method
Code: Select all  Expand view

   ::bBuildBar  := { || BuildRichEditBar( Self, Self, , , .T. ) }
   if ::lBar
      ::oBar := XEval( ::bBuildBar, ::oWnd, Self ) // BuildRichEditBar( Self, Self, , , .T. )
      //::oTop := ::oBar
      ::oBar:Hide()
   endif
 

3.- Change in the Redefine method
Code: Select all  Expand view

   ::bBuildBar  := { || BuildRichEditBar( Self, Self, , , .T. ) }
   if ::lBar
      ::bInit := { || ::oBar := XEval( ::bBuildBar, ::oWnd, Self ), ::oBar:Hide() }
   endif
 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Multiple RTF controls each with its own bar

Postby hua » Tue Oct 18, 2022 9:46 am

cnavarro wrote:I don't know if I understood your problem correctly
Do you mean that you can customize the buttonbar of each RICHEDIT control?
Please put the code of the program in the image above to be able to work on it.


There 2 goals I would like to achieve with regards to the RTF control:
1. To have each oRtf have its own buttonbar
2. Each oRtf supports all the basic shortcut keys common in Windows when doing editing such as Ctrl+B for Bold, Ctrl-I for Italic, Ctrl-C for Copy, Ctrl-V for Paste, etc.

Below is the requested source.
Code: Select all  Expand view

#include "fivewin.CH"
#include "ttitle.ch"
#include "RichEdi5.ch"

procedure main()
  hr():activate()
return
//----------------------------------------------------------------------
class hr
  data oDlg, oSay, hRtfDll
  data oDbPerson, oFolder
  data hoTitles, hoGets, hGets init {=>}

  method activate()
  method createTitle(oTitle, oFont)
  method refresh()
endclass
//----------------------------------------------------------------------
method activate() class HR
  LOCAL cNotes, oBtnOK, oBtnCnl, oBtnPrn, oSay, oldarea := select()

  LOCAL cTitl := "Title On FolderEx", oFont3, oFnt

  local omfont2 :=TFont():New( "TIMES NEW ROMAN", 0, -24, .F., .f., 0, 1, 650,.T.,,, 0, 3, 2, 1 )

  LOCAL bReturn := <||
                          oFnt:end()
                          oMFont2:end()
                          oFont3:end()
                   >

  local cGet := "", oTitle, cName, o := self

  DEFINE FONT oFnt NAME "SYSTEM_FIXED_FONT" SIZE 0, -12
  DEFINE FONT oFont3 NAME "Verdana" SIZE 0, -20 bold


  ::hGets["edu_1"] := ""
  ::hGets["edu_2"] := ""
  ::hGets["edu_3"] := ""

  ::hRtfDll := LoadLibrary( "Riched20.dll" )
  DEFINE DIALOG ::oDlg RESOURCE "hr" TITLE cTitl FONT oFnt

    REDEFINE FOLDEREX ::oFolder ID 110 OF ::oDlg   ;
     PROMPT "&Education", "&Others" DIALOGS "hr_edu", "Sub1" BOTTOM

       ::oFolder:aDialogs[1]:lTransparent := .f.
       ::oFolder:aDialogs[2]:lTransparent := .f.

       // sub- folders
       REDEFINE TITLE ::hoTitles["edu_1"] ID 102 of ::oFolder:aDialogs[1] SHADOW BOTTOMRIGHT
       REDEFINE RICHEDIT5 ::hoGets["edu_1"] VAR ::hGets["edu_1"] ID 301 OF ::oFolder:aDialogs[1] BARBUTTON

       REDEFINE TITLE ::hoTitles["edu_2"] ID 104 of ::oFolder:aDialogs[1] SHADOW BOTTOMRIGHT
       REDEFINE RICHEDIT5 ::hoGets["edu_2"] VAR ::hGets["edu_1"] ID 105 OF ::oFolder:aDialogs[1] BARBUTTON

       REDEFINE TITLE ::hoTitles["edu_3"] ID 101 of ::oFolder:aDialogs[1] SHADOW BOTTOMRIGHT
       REDEFINE RICHEDIT5 ::hoGets["edu_3"] VAR ::hGets["edu_1"] ID 106 OF ::oFolder:aDialogs[1] BARBUTTON



       REDEFINE BUTTON oBtnOK ID 111 OF ::oDlg                                          ;
          ACTION (                                                                    ;
                   oBtnCnl:click()                                                    ;
                 )

       REDEFINE BUTTON oBtnCnl ID 112 OF ::oDlg                                     ;
          ACTION (                                                                        ;
                   ::oDlg:End()                                                             ;
                 )                                                                        ;

       REDEFINE BUTTON oBtnPrn ID 113 OF ::oDlg

       ACTIVATE DIALOG ::oDlg CENTERED                                                    ;
          ON INIT (                                                                       ;
                    o:refresh(),                                                          ;
                    o:CreateTitle(o:hoTitles["edu_1"], oFont3, "Formal Education"),       ;
                    o:CreateTitle(o:hoTitles["edu_2"], oFont3, "Tertiary Education"),     ;
                    o:CreateTitle(o:hoTitles["edu_3"], oFont3, "Professional Education")  ;
                  )

       EVAL( bReturn )
       FreeLibrary( ::hRtfDll )

RETURN (NIL)
//---------------------------------------------------------------------------
method refresh() class HR
/*
  ::oSay:varput(trim(::oDbPerson:name)+" ("+ trim(::oDbPerson:empno) + ")")

  ::hoGets["edu_1"]:LoadRtf( ::oDbPerson:rtf_edu1 )
  ::hoGets["edu_2"]:LoadRtf( ::oDbPerson:rtf_edu2 )
  ::hoGets["edu_3"]:LoadRtf( ::oDbPerson:rtf_edu3 )
*/

  ::oDlg:update()
return nil
//----------------------------------------------------------------------
method CreateTitle(  oTitle, oFont, cText ) class HR

   @ 2, 55 TITLETEXT OF oTitle TEXT cText FONT oFont
*   @ 10, 10 TITLEIMG OF oTitle RESNAME "users" SIZE 30, 30 REFLEX TRANSPARENT

return nil
//---------------------------------------------------------------------------
 


Code: Select all  Expand view

hr DIALOG 45, 30, 434, 393
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
FONT 10, "System"
{
 CONTROL "", 110, "TFolderEx", WS_VISIBLE | WS_TABSTOP, 4, 52, 424, 304
 CONTROL "&Ok", 111, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 132, 369, 50, 14
 CONTROL "&Cancel", 112, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 192, 369, 50, 14
 CONTROL "&Print", 113, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 253, 369, 50, 14
}

hr_edu DIALOG 23, 82, 292, 351
STYLE WS_CHILD
{
 CONTROL "Custom control", 102, "TTITLE", WS_CHILD | WS_VISIBLE, 4, 2, 284, 20
 CONTROL "", 301, "RichEdit50W", ES_LEFT | ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP | ES_WANTRETURN, 3, 24, 286, 88
 CONTROL "", 105, "RichEdit50W", ES_LEFT | ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP | ES_WANTRETURN, 2, 143, 286, 88
 CONTROL "Custom control", 104, "TTITLE", WS_CHILD | WS_VISIBLE, 3, 121, 284, 20
 CONTROL "", 106, "RichEdit50W", ES_LEFT | ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP | ES_WANTRETURN, 2, 258, 286, 88
 CONTROL "Custom control", 101, "TTITLE", WS_CHILD | WS_VISIBLE, 3, 236, 284, 20
}

SUB1 DIALOG 23, 82, 292, 167
STYLE WS_CHILD
{
 CONTROL "", 301, "EDIT", ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 3, 2, 286, 162
}
 
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Multiple RTF controls each with its own bar

Postby hua » Tue Oct 18, 2022 9:49 am

Antonio Linares wrote:Dear Hua,

If I properly understood you, you have to do the following:

1. use "RichEdi5.ch" instead of "RichEdit.ch"

...


Thanks for the reply Antonio.
I managed to change to use RTF5 but when I add the clause BUTTONBAR I get an error when compiling
I was using FWH1912 if that helps.

TIA
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 95 guests