adding special characters in a get

adding special characters in a get

Postby plantenkennis » Fri May 14, 2021 2:18 pm

Hello Antonio and Manuel,

I have a function to add a richtext, but in this function I can not type any special characters like ä, é

Is there a solution for it?

Here is my code:

Code: Select all  Expand view  RUN

FUNCTION RK_EditRichNotes(cTekst)

   LOCAL oDlg, cText := ''
   LOCAL oGet
   
   DEFINE DIALOG oDlg TITLE 'Aantekening' FROM 0, 0 TO 500, 600
     
   @ 35, 20 GET oGet VAR cText MEMO OF oDlg ;
      SIZE 560, 460
     
    oGet:SetRichText(.t.)
    oGet:SetImportGraf(.t.)
    oGet:AddHRuler()
    oGet:SetUndo(.t.)
    IF LEN(ALLTRIM(cTekst)) > 0
        cText := cTekst
        oGet:SetAttributedString(cText)
    ENDIF
    oGet:GoTop()
           
         
   @ 5, 500 BUTTON oBtnOk PROMPT 'Ok' OF oDlg ACTION cAanteken := oGet:GetRTF(), oDlg:END()
    oBtnOk:SetFont( 'Arial', 14 )
   
ACTIVATE DIALOG oDlg CENTERED

RETURN NIL
 
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: adding special characters in a get

Postby mastintin » Sun May 16, 2021 5:10 pm

Hello.
I see your code ....
cTekst is string from RTF content ?
oGet:SetAttributedString(cText) is only for set content from RTF ( copy RTF code in var and paste into text view ) .
the property method for text is oGet:setText( cTekst ) but it was not planned for text with special characters .
I create code for this .....

in mget.prg add this code ...
Code: Select all  Expand view  RUN

 METHOD SetUTF8Text( cText ) INLINE TxtSetUTF8Text( ::hWnd, cText )

 



in mgets.m add this code ....
Code: Select all  Expand view  RUN


HB_FUNC( TXTSETUTF8TEXT )
{
    TextView * memo = ( TextView * ) hb_parnl( 1 );
    NSString * string = [ [ [ NSString alloc ] initWithCString: HB_ISCHAR( 2 ) ? hb_parc( 2 ) : "" encoding:  NSUTF8StringEncoding ] autorelease ];
   
    [ memo setString : string ];
}

 




in your sample change :

//oGet:SetAttributedString(cTekst)
oGet:setutf8Text( cTekst )

for me this is ok.
regards
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: adding special characters in a get

Postby plantenkennis » Tue May 18, 2021 1:18 pm

Hello Manuel,

Thanks for your reply. Yes the cTekst is a string with RTF content.

Do I need to rebuild the libs after the suggested changes? Because now I get an error:
Code: Select all  Expand view  RUN

Message not found: TMULTIGET:SETUTF8TEXT
 
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: adding special characters in a get

Postby Antonio Linares » Tue May 18, 2021 3:39 pm

René,

Yes, you have to rebuild FiveMac once you include the suggested changes in its source code
regards, saludos

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

Re: adding special characters in a get

Postby plantenkennis » Sun May 23, 2021 3:16 pm

Hello Manuel and Antonio,

I have made the suggested changes to the files and rebuild the libs. However in the get I see all the special characters from the RichText. And I am still not able to put in characters like ä, é ....
Here is my code:
Code: Select all  Expand view  RUN

FUNCTION RK_EditRichNotes(cTekst)

   LOCAL oDlg, cText := ''
   LOCAL oGet
   
   DEFINE DIALOG oDlg TITLE 'Aantekening' FROM 0, 0 TO 500, 600
     
   @ 35, 20 GET oGet VAR cText MEMO OF oDlg ;
      SIZE 560, 460
     
    oGet:SetRichText(.t.)
    oGet:SetImportGraf(.t.)
    oGet:AddHRuler()
    oGet:SetUndo(.t.)
    IF LEN(ALLTRIM(cTekst)) > 0
        cText := cTekst
        oGet:setutf8Text( cText )
*       oGet:SetAttributedString(cText)
    ENDIF
    oGet:GoTop()
           
         
   @ 5, 500 BUTTON oBtnOk PROMPT 'Ok' OF oDlg ACTION cAanteken := oGet:GetRTF(), oDlg:END()
    oBtnOk:SetFont( 'Arial', 14 )
   
ACTIVATE DIALOG oDlg CENTERED

RETURN NIL
 


This only happens when I use the GET in combination with MEMO. I get to see this:
Code: Select all  Expand view  RUN

{\rtf1\ansi\ansicpg1200\deff0\nouicompat\deflang1043{\fonttbl{\f0\fnil\fcharset0 ArialMT;}{\f1\froman\fprq2\fcharset0 ArialMT;}}
{\colortbl ;\red0\green0\blue0;}
{\*\generator Riched20 10.0.10240}\viewkind4\uc1
\pard\cf1\f0\fs24 De grootst sierwaarde van deze boom is de donkerbruine bast die afschilfert in grote losse \par
krullen, waardoor de oranje onderlaag tevoorschijn komt.\par
\cf0\f1 Deze kleine boom heeft een bruine afschilferende bast. Het is een langzame groeier en daarom ook geschikt voor de wat kleinere tuin. Het kleine blad verkleurt in de herfst schitterend oranjerood. De bloei wordt gevolgd door gevleugelde nootvruchten die in trosjes aan de boom hangen.\par
Mooi als solitair met een onderbeplanting van bijvoorbeeld zegge (Carex morrowii) of sneeuwster-aster (Aster divaricatus). De wortel concurrentie van de Acer griseum is vrij groot, om die reden willen andere planten onder deze boom niet altijd makkelijk groeien.\cf1\f0\par
}
 
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: adding special characters in a get

Postby Antonio Linares » Mon May 24, 2021 4:42 pm

René,

Are you able to paste those characters in the memo ?
regards, saludos

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

Re: adding special characters in a get

Postby plantenkennis » Wed May 26, 2021 3:09 pm

Hello Antonio,
I have made an example.

If I use the oGet:setutf8Text( cText ) all the richtext formatting is shown and I can't put in characters like ä,é...

If I use the oGet:SetAttributedString(cText) the richtext formatting is NOT shown (so this is correct) but I still can't put in characters like ä, é...

IF I define the GET without MEMO I can put in the special characters. But then I can not set lists or text centered.

Code: Select all  Expand view  RUN

#include "FiveMac.ch"

function Main()

   LOCAL oWnd, cText := ''
   LOCAL oGet
   LOCAL cTekst := '{\rtf1\ansi\ansicpg1200\deff0\nouicompat\deflang1043{\fonttbl{\f0\fnil\fcharset0 ArialMT;}{\f1\froman\fprq2\fcharset0 ArialMT;}}{\colortbl ;\red0\green0\blue0;}{\*\generator Riched20 10.0.10240}\viewkind4\uc1\pard\cf1\f0\fs24 This is a RichText\cf1\f0\par}'
   
   DEFINE WINDOW oWnd TITLE 'RichNotes' FROM 0, 0 TO 500, 600
     
   @ 35, 20 GET oGet VAR cText MEMO OF oWnd ;
      SIZE 560, 460
     
   oGet:SetRichText(.t.)
   oGet:SetImportGraf(.t.)
   oGet:AddHRuler()
   oGet:SetUndo(.t.)
   IF LEN(ALLTRIM(cTekst)) > 0
      cText := cTekst
     oGet:setutf8Text( cText )
*      oGet:SetAttributedString(cText)
   ENDIF
   oGet:GoTop()
           
         
   @ 5, 500 BUTTON oBtnOk PROMPT 'Ok' OF oWnd ACTION MsgInfo(oGet:GetRTF(), 'richtext'), MsgInfo(oGet:GetText(), 'normal text')
      oBtnOk:SetFont( 'Arial', 14 )
   
ACTIVATE WINDOW oWnd CENTERED

           
return nil

 
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands


Return to FiveMac / FivePhone (iPhone, iPad)

Who is online

Users browsing this forum: No registered users and 3 guests