New method for richedit

New method for richedit

Postby Silvio.Falconi » Fri Jul 01, 2016 10:17 am

Image

choosesymbols(oRtf)
now it is a function but I must converte it on method to use with richedit class
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7034
Joined: Thu Oct 18, 2012 7:17 pm

Re: New method for richedit

Postby Antonio Linares » Fri Jul 01, 2016 11:36 am

very good
regards, saludos

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

Re: New method for richedit

Postby Silvio.Falconi » Sat Jul 02, 2016 9:44 am

Antonio,
I made the new method for richedit but not run here
when I insert the object into rtf give me another charset

If I use the same code from a function run good Why ?

New method for richedit
Code: Select all  Expand view

METHOD RTFChooseSymbols(aArrayFont,cFont,nSize,nTypeFont) CLASS TRichEdit


   // aArrayFont   an array with all fonts
   // cFont        fontname current
   // nSize        size fonts current
   // nTypeFont    nCharSet  ( 1,2)


   Local oDlg
   Local nBottom      := 26
   Local nRight       := 56
   Local nWidth       := Max( nRight * DLG_CHARPIX_W, 180 )
   Local nHeight      := nBottom * DLG_CHARPIX_H
   Local arrayChars   := CreateTableAscii()
   Local lOk          := .F.

   Local oFont        := TFont():New( cFont, 0,nSize,,,,,,,,, nTypeFont,,,,, )
   Local aGet[2]
   Local oBrow
   Local cTitle       :="Insert the symbol"

  DEFINE DIALOG oDlg      ;
   TITLE cTitle   ;
   SIZE nWidth, nHeight  PIXEL

   @ 12,06 say "Font:"  SIZE 100,20 OF oDlg PIXEL
    @ 10,30 COMBOBOX aGet[1] VAR cFont ITEMS aArrayFont SIZE 80,90 OF oDlg PIXEL ;
    ON CHANGE (cFont:= CreateFontGrid(cFont,nTypeFont,oFont,nSize ),;
               oBrow:SetFont( cFont ),;
               oBrow:KeyDown( VK_HOME, 0 ),;
               oBrow:setfocus())


   @ 12,150 say "Type:"  SIZE 100,20 OF oDlg PIXEL
    @ 10,170 COMBOBOX aGet[2] VAR nTypeFont ITEMS {"1","2"} SIZE 40,90 OF oDlg PIXEL ;
      ON CHANGE (cFont:= CreateFontGrid( cFont,nTypeFont,oFont,nSize),;
               oBrow:SetFont( cFont ),;
               oBrow:KeyDown( VK_HOME, 0 ),;
               oBrow:setfocus())


    @ 25,06 XBROWSE oBrow OF oDlg PIXEL;
           ARRAY arrayChars  SIZE 211,144 NOBORDER

          oBrow:SetFont( CreateFontGrid( cFont,nTypeFont,oFont,nSize ) )
          oBrow:lHeader         := .F.
          oBrow:lRecordSelector := .F.
          oBrow:bLDblClick      := { ||( ::SetFontName(cFont ),;
                                         ::InsertRTF( arrayChars[ oBrow:nArrayAt ][ oBrow:nColSel ] ) ,;
                                         ::setfocus()   ) }
          oBrow:CreateFromCode()


       @ 176,126 Button"Insert" SIZE 60,12 OF oDlg PIXEL   ACTION ( lOk := .T., oDlg:End() )
      ACTIVATE DIALOG oDlg CENTER


      if lOk
         ::SetFontName( cFont )
         ::SetFontSize( nSize )
                ::InsertRTF( arrayChars[ oBrow:nArrayAt ][ oBrow:nColSel ] )
         ::setfocus()
   endif
Return nil
//-------------------------------------------------------------------------------------------//

 STATIC Function CreateTableAscii()

   local aData := Array( 12,20 )    // 12,20
   local x  := 1
   local i  := 15
   local j  := 0

   Do while i < 255
      j++
      aData[ x ][ j ] := chr( i )
      if j = 20
         j := 0
         x++
      endif
      i++
   enddo

return aData
//-------------------------------------------------------------------------------------------//

STATIC Function CreateFontGrid(cname,nTypeFont,oFont,nSize)
   if oFont<> NIL
     * oFont:End()
      RELEASE FONT oFont
   endif

   oFont := TFont():New( cname, 0,nSize,,,,,,,,, nTypeFont,,,,, )

return oFont
 


this is a mistery!!! it's very strange!!!
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7034
Joined: Thu Oct 18, 2012 7:17 pm

Re: New method for richedit

Postby Antonio Linares » Sat Jul 02, 2016 10:22 am

Silvio,

> If I use the same code from a function run good Why ?

Please show the code for the function, thanks
regards, saludos

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

Re: New method for richedit

Postby Silvio.Falconi » Sat Jul 02, 2016 10:52 am

on function I use your memoedit test ( hDLL = LoadLibrary( 'riched20.dll' ))



Code: Select all  Expand view

#include "FiveWin.ch"
#include "constant.ch"

#include "richedit.ch"

static ofont, cFont,nTypeFont,nSize



function Main()

   local cTitle := "Test Rich Edit insert Symbol"
   local cText := "Thanks to Cristobal and Nages"

   RichEdit( @cText, cTitle )

   MsgInfo( cText )

return nil



 function RichEdit( cText, cTitle, nTop, nLeft, nBottom, nRight )

   local oFont, oDlg, oMemo
   local hDLL
   local uTemp := If( ! Empty( cText ), cText, '' )
   local lRich := .F., lGTF := .F., lSaved := .F.

   DEFAULT nTop := 9, nLeft := 9, nBottom := 27, nRight := 71.5,;
           cTitle := "RichEdit"

   DEFINE FONT oFont NAME "Ms Sans Serif" SIZE 0, -10

   DEFINE DIALOG oDlg FROM nTop, nLeft TO nBottom, nRight ;
      TITLE cTitle FONT oFont
   oDlg:lTruePixel   := .f.

   hDLL  = LoadLibrary( 'riched20.dll' )

   @ 30, 3 RICHEDIT oMemo VAR uTemp OF oDlg PIXEL SIZE 200, 200

   oDlg:oClient = oMemo

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( BuildRichEditBar( oDlg, oMemo,;
                { | c | lSaved := .T., cText := c } ), oDlg:ReSize() )

   oFont:End()

   if hDLL != nil
      FreeLibrary( hDLL )
   endif

return lSaved

static function BuildRichEditBar( oWnd, oRtf )

   local oBar, oBtn, oBullet, oBold, oItalic, oNumber, oUnderline, oCursor
   local lBold := .F., lItalic := .F., lUnderline := .F., lBullet := .F.,;
         lNumber := .F.

   DEFINE CURSOR oCursor HAND

   DEFINE BUTTONBAR oBar OF oWnd SIZE 26, 27 2010

   DEFINE BUTTON oBtn OF oBar ;
          MESSAGE "Choose a Symbol" TOOLTIP "New" NOBORDER ;
          ACTION  ChooseSymbols(oRTF)



   oBar:bLClicked := { || nil }
   oBar:bRClicked := { || nil }

   AEval( oBar:aControls, { |x| x:oCursor := oCursor } )

return nil


Function ChooseSymbols(oRTF)
   Local oDlg
   Local aArrayFont

   Local nBottom      := 26
   Local nRight       := 56
   Local nWidth       := Max( nRight * DLG_CHARPIX_W, 180 )
   Local nHeight      := nBottom * DLG_CHARPIX_H
   Local aGet[5]
   Loca  nFontname    := 184
   Local oBrow
   Local cChartoCopy  := ""
   Local arrayChars
    Local lOk  := .F.


    nTypeFont := 2
    nSize     :=  -32

    FW_SetUnicode( .T. )

   arrayChars   := CreateTableAscii()

  DEFINE DIALOG oDlg      ;
   TITLE "Insert the symbol"   ;
   SIZE nWidth, nHeight  PIXEL


    aArrayFont := aGetFont( oDlg )
    oFont:= CreateFontGrid(aArrayFont[ nFontname ],nTypeFont)



    @ 12,06 say "Font:"  SIZE 100,20 OF oDlg PIXEL
    @ 10,30 COMBOBOX aGet[1] VAR nFontname ITEMS aArrayFont SIZE 80,90 OF oDlg PIXEL ;
    ON CHANGE (cFont:= CreateFontGrid( aArrayFont[ nFontname ],nTypeFont ),;
               oBrow:SetFont( cFont ),;
               oBrow:KeyDown( VK_HOME, 0 ),;
               oBrow:setfocus())


   @ 12,150 say "Type:"  SIZE 100,20 OF oDlg PIXEL
    @ 10,170 COMBOBOX aGet[2] VAR nTypeFont ITEMS {"1","2"} SIZE 40,90 OF oDlg PIXEL ;
      ON CHANGE (cFont:= CreateFontGrid( aArrayFont[ nFontname ],nTypeFont),;
               oBrow:SetFont( cFont ),;
               oBrow:KeyDown( VK_HOME, 0 ),;
               oBrow:setfocus())


    @ 25,06 XBROWSE oBrow OF oDlg PIXEL;
           ARRAY arrayChars  SIZE 211,144 NOBORDER



       WITH OBJECT oBrow
          :SetFont( CreateFontGrid( aArrayFont[ nFontname ],nTypeFont ) )
          :lHeader         := .F.
          :lRecordSelector := .F.
          :bLDblClick      := { ||( oRtf:SetFontName(aArrayFont[ nFontname ] ),;
                                    oRtf:SetFocus() ,;
                                    oRtf:InsertRTF( arrayChars[ oBrow:nArrayAt ][ oBrow:nColSel ] ) ) }
          :CreateFromCode()
       END

       @ 176,126 Button"Insert" SIZE 60,12 OF oDlg PIXEL   ACTION ( lOk := .T., oDlg:End() )
      ACTIVATE DIALOG oDlg CENTER


      if lOk
         oRtf:SetFontName( aArrayFont[ nFontname ] )
         oRtf:SetFontSize( -32 )
         oRtf:SetFocus()
         oRtf:InsertRTF( arrayChars[ oBrow:nArrayAt ][ oBrow:nColSel ] )
   endif


Return nil
//-------------------------------------------------------------//
// create the fonts array
//-------------------------------------------------------------//

function aGetFont( oWnd )

   local aFont    := {}
   local hDC      := GetDC( oWnd:hWnd)
   local nCounter := 0

   if hDC != 0

      while ( empty( aFont := GetFontNames( hDC ) ) ) .AND. ( ++nCounter ) < 5
      end while

      if empty( aFont )
         msgAlert( i18n("Error al obtener las fuentes.") + CRLF + ;
                    i18n("Sólo podrá usar las fuentes predefinidas.") )
      else
         aSort( aFont,,, { |x, y| upper( x ) < upper( y ) } )
      endif

   else

      msgAlert( i18n("Error al procesar el manejador de la ventana.") + CRLF + ;
                i18n("Sólo podrá usar las fuentes predefinidas.") )

   endif



   ReleaseDC( oWnd:hWnd, hDC )

   return aFont

 //--------------------------------------------------------------//

Function CreateTableAscii()

   local aData := Array( 25, 10 )    // 12,20
   local x  := 1
   local i  := 15
   local j  := 0

   Do while i < 255
      j++
      aData[ x ][ j ] := chr( i )
      if j = 10
         j := 0
         x++
      endif
      i++
   enddo

return aData

 //--------------------------------------------------------------//

Function CreateFontGrid(cname,nTypeFont)
   if oFont<> NIL
      oFont:End()
   endif

    oFont := TFont():New( cname, 0,nSize,,,,,,,,, nTypeFont,,,,, )
return oFont

 //--------------------------------------------------------------//

 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7034
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 99 guests