SetClipboardData to UTF-8

SetClipboardData to UTF-8

Postby frose » Thu Jun 29, 2023 6:19 am

wondering how to set the clipboard data to UTF-8.
Using now:
Code: Select all  Expand view  RUN
HB_CDPSELECT( "UTF8" )
FW_SetUnicode( .T. )
SetClipboardData( CF_TEXT, "Ärzte" )

cValue := GetClpData( CF_TEXT )
 

cValue is:
Code: Select all  Expand view  RUN
Ärzte
:(
Does someone know it, then please give me a hint.
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: SetClipboardData to UTF-8

Postby nageswaragunupudi » Thu Jun 29, 2023 2:06 pm

Copying data correctly to clipboard but there is problem in pasting, i.e, GetClpData
We are looking to all the issues raised by you.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: SetClipboardData to UTF-8

Postby karinha » Thu Jun 29, 2023 2:08 pm

Code: Select all  Expand view  RUN

// C:\FWH..\SAMPLES\FROSE3UT.PRG

#include "FiveWin.ch"

REQUEST HB_LANG_PT
REQUEST HB_CODEPAGE_PT850

static oWnd

FUNCTION Main()

   LOCAL oBar

   // Germany?
   HB_LANGSELECT( 'PT' )     // Default language is now Portuguese
   HB_SETCODEPAGE( "PT850" )

   FW_SetUnicode( .T. )

   // Harbour (not xHarbour) to display unicode filenames
   HB_SETCODEPAGE( "UTF8" )  // ???
   // HB_CDPSELECT( "UTF8" )

   DEFINE WINDOW oWnd TITLE "3D objects"

   DEFINE BUTTONBAR oBar _3D OF oWnd

   DEFINE BUTTON OF oBar ACTION BuildClip()

   SET MESSAGE OF oWnd TO "3D Objects" NOINSET CLOCK DATE KEYBOARD

   ACTIVATE WINDOW oWnd

RETURN NIL

FUNCTION BuildClip()

   LOCAL cList := ""
   LOCAL cText := "Ärzte"
   LOCAL oClp

   // Open Editor and CTRL+V
   DEFINE CLIPBOARD oClp OF oWnd

   oClp:SetText( cText )

   oClp:End()

   IF IsUtf8( cText ) // No comprendo. No funciona.

      ? cText

   ELSE

      QUIT

   ENDIF

RETURN NIL

// fin / end
 
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7831
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: SetClipboardData to UTF-8

Postby nageswaragunupudi » Thu Jun 29, 2023 4:42 pm

Can you make a small bugfix in fwh\source\function\imgtxtio.prg
You see this code at line no: 3850
Code: Select all  Expand view  RUN
     if !Empty( uData ) .and. IsTextUnicode( uData )

Please change it as
Code: Select all  Expand view  RUN
     if !Empty( uData )


Then, please run this program:
Code: Select all  Expand view  RUN
#include "fivewin.ch"

function Main()

   local cText, cPaste

   FW_SetUnicode( .T. )

   cText := "Ärzte"
   FW_CopyToClipBoard( cText )
   ? "Copied to ClipBoard " + cText
   cPaste := FW_GetClipboardData()
   ? "Copied : " + cText, "Pasted : " + cPaste, ;
     "Compare",cText == cPaste 

return nil


This is working correctly for me on many Unicode language texts.
Once this runs ok for you, please test with many different combinations of text and provide your valuable feedback.
Note: Hereafter please use the above functions
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: SetClipboardData to UTF-8

Postby Jimmy » Fri Jun 30, 2023 7:26 am

moin,
frose wrote:wondering how to set the clipboard data to UTF-8.
Using now:
Does someone know it, then please give me a hint.

try this
Code: Select all  Expand view  RUN
#include "Fivewin.ch"
#define CF_TEXT 1
#define CF_UNICODETEXT 13

PROCEDURE MAIN
LOCAL cValue := "Hello"

    HB_CDPSELECT( "UTF8" )
    FW_SetUnicode( .T. )
    * SetClipboardData( CF_TEXT , "Ärzte" )
    CopyToClipboard( "Ärzte" )
    * ? cValue := GetClpData(CF_TEXT)
    ? cValue := TextFromClipboard()
RETURN


Code: Select all  Expand view  RUN
FUNCTION CopyToClipboard( cText )
LOCAL oClip := TClipBoard() :New()

   IF oClip:Open()
      oClip:SetText( cText )
      oClip:Close()
   ENDIF

   oClip:End()
RETURN nil


Code: Select all  Expand view  RUN
FUNCTION TextFromClipboard()
LOCAL cText := ""
LOCAL oClip := TClipBoard() :New()

   IF oClip:Open()
      cText := oClip:GetText()
      oClip:Close()

      IF CRLF $ cText
         cText := TRIM( STRTRAN( cText, CRLF, "" ) )
      ENDIF
   ENDIF

   oClip:End()
RETURN cText
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: SetClipboardData to UTF-8

Postby frose » Fri Jun 30, 2023 8:30 am

nageswaragunupudi wrote:Can you make a small bugfix...

Almost ok:
Image
Code: Select all  Expand view  RUN
Ágota Kristóf
ängstlichen
Ärzte
Åsa Böker
Íngrid Betancourt
Ñejo
Ólafur Arnalds
Ölsardinen
Øresund Space Collective
überbewertet
Überblick
Анастасия Варнавская
벤자민 (Benzamin)
수지 Suzy

Hex codes:
C3 81 67 6F 74 61 20 4B 72 69 73 74 C3 B3 66 0D 0A C3 A4 6E 67 73 74 6C 69 63 68 65 6E 0D 0A C3 84 72 7A 74 65 0D 0A C3 85 73 61 20 42 C3 B6 6B 65 72 0D 0A C3 8D 6E 67 72 69 64 20 42 65 74 61 6E 63 6F 75 72 74 0D 0A C3 91 65 6A 6F 0D 0A C3 93 6C 61 66 75 72 20 41 72 6E 61 6C 64 73 0D 0A C3 96 6C 73 61 72 64 69 6E 65 6E 0D 0A C3 98 72 65 73 75 6E 64 20 53 70 61 63 65 20 43 6F 6C 6C 65 63 74 69 76 65 0D 0A C3 BC 62 65 72 62 65 77 65 72 74 65 74 0D 0A C3 9C 62 65 72 62 6C 69 63 6B 0D 0A D0 90 D0 BD D0 B0 D1 81 D1 82 D0 B0 D1 81 D0 B8 D1 8F 20 D0 92 D0 B0 D1 80 D0 BD D0 B0 D0 B2 D1 81 D0 BA D0 B0 D1 8F 0D 0A EB B2 A4 EC 9E 90 EB AF BC 20 28 42 65 6E 7A 61 6D 69 6E 29 0D 0A EC 88 98 EC A7 80 20 53 75 7A 79

I only found one term that has problems when combined with other terms that contain at least ONE multibyte character.
Alone ok:
Code: Select all  Expand view  RUN
Þráinn Bertelsson

Hex codes:
C3 9E 72 E1 69 6E 6E 20 42 65 72 74 65 6C 73 73 6F 6E

Two other terms are ok:
Code: Select all  Expand view  RUN

벤자민 (Benzamin)
Анастасия Варнавская

Hex codes:
EB B2 A4 EC 9E 90 EB AF BC 20 28 42 65 6E 7A 61 6D 69 6E 29 0D 0A D0 90 D0 BD D0 B0 D1 81 D1 82 D0 B0 D1 81 D0 B8 D1 8F 20 D0 92 D0 B0 D1 80 D0 BD D0 B0 D0 B2 D1 81 D0 BA D0 B0 D1 8F

Combined NOT ok:
Code: Select all  Expand view  RUN
Þráinn Bertelsson
Анастасия Варнавская
벤자민 (Benzamin)

Hex codes:
C3 9E 72 E1 69 6E 6E 20 42 65 72 74 65 6C 73 73 6F 6E 0D 0A D0 90 D0 BD D0 B0 D1 81 D1 82 D0 B0 D1 81 D0 B8 D1 8F 20 D0 92 D0 B0 D1 80 D0 BD D0 B0 D0 B2 D1 81 D0 BA D0 B0 D1 8F 0D 0A EB B2 A4 EC 9E 90 EB AF BC 20 28 42 65 6E 7A 61 6D 69 6E 29

The order does not matter.
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: SetClipboardData to UTF-8

Postby frose » Fri Jun 30, 2023 8:59 am

One more.
Single terms ok:
Code: Select all  Expand view  RUN
Thráinn Bertelsson

Hex codes:
54 68 72 C3 A1 69 6E 6E 20 42 65 72 74 65 6C 73 73 6F 6E

Code: Select all  Expand view  RUN
Þráinn Bertelsson

Hex codes:
DE 72 E1 69 6E 6E 20 42 65 72 74 65 6C 73 73 6F 6E

Together not ok:
Code: Select all  Expand view  RUN
Þráinn Bertelsson
Thráinn Bertelsson
Thrainn Bertelsson

Hex codes:
DE 72 E1 69 6E 6E 20 42 65 72 74 65 6C 73 73 6F 6E 0D 0A 54 68 72 C3 A1 69 6E 6E 20 42 65 72 74 65 6C 73 73 6F 6E 0D 0A 54 68 72 61 69 6E 6E 20 42 65 72 74 65 6C 73 73 6F 6E
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: SetClipboardData to UTF-8

Postby nageswaragunupudi » Fri Jun 30, 2023 11:08 am

Please run this program as it is:
Code: Select all  Expand view  RUN
#include "fivewin.ch"

function main()

   local cText, cPaste
   local aText[ 4 ]

   FW_SetUnicode( .t. )

TEXT INTO aText[ 1 ]
Ágota Kristóf
ängstlichen
Ärzte
Åsa Böker
Íngrid Betancourt
Ñejo
Ólafur Arnalds
Ölsardinen
Øresund Space Collective
überbewertet
Überblick
Анастасия Варнавская
벤자민 (Benzamin)
수지 Suzy
ENDTEXT
   aText[ 2 ] := "Þráinn Bertelsson"

TEXT INTO aText[ 3 ]
벤자민 (Benzamin)
Анастасия Варнавская
ENDTEXT

TEXT INTO aText[ 4 ]
Þráinn Bertelsson
Анастасия Варнавская
벤자민 (Benzamin)
ENDTEXT
 

   FOR EACH cText IN aText
 
      FW_CopyToClipBoard( cText )
      cPaste := FW_GetClipBoardData()
 
     ? "Original Text :" + CRLF + ;
        cText + CRLF + ;
       "Pasted from Clipboard :" + ;
       cPaste + CRLF + ;
       "Compare : " + ;
       If( cText == cPaste, "EXACTLY EQUAL", "Diiferent" )

   NEXT

return nil

// USE THESE CLIPBOARD FUNCTIONS ONLY

static function FW_CopyToClipBoard( uValue, nFormat )

   local lCopied  := .f.

   if HB_ISPOINTER( uValue ) // assumes GDI+ Image object
      GDIPLUSImageToClipBoard( uValue )
      return .t.
   endif

   if uValue != nil
      if Empty( nFormat ) .and. HB_ISARRAY( uValue ) .and. ;
         AScan( uValue, { |u| ValType( u ) != "C" } ) == 0
            nFormat  := 15
      endif
      DEFAULT nFormat := If( HB_ISSTRING( uValue ), 1, ;
                         If( HB_ISNUMERIC( uValue ) .and. ISHBITMAP( uValue ), 2, nil ) )
      if Empty( nFormat )
         if ValType( uValue ) $ "AH"
            uValue   := FW_ValToExp( uValue )
         else
            uValue   := cValToChar( uValue )
         endif
         nFormat  := 1
      endif

      if nFormat != nil
         if OpenClipBoard( GetDeskTopWindow() )
            EmptyClipboard()
            if nFormat == 1 .and. IsUtf8( uValue )
               uValue    := utf8toutf16( uValue )
               if !( Right( uValue, 2 ) == Chr( 0 ) + Chr( 0 ) )
                  uValue    += ( Chr( 0 ) + Chr( 0 ) )
               endif
               lCopied  := SetClipboardData( 13, uValue )
            elseif nFormat == 15
               if !HB_ISARRAY( uValue )
                  uValue   := { uValue }
               endif
               lCopied  := SetClipboardData( 15, uValue )
            else
               lCopied  := SetClipboardData( nFormat, uValue )
            endif
            CloseClipboard()
         endif
      endif
   endif

return lCopied

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

static function FW_GetClipBoardData( nFormat ) // [@nFormat]

   local uData, lCopied

   if nFormat == 3; nFormat := 14; endif
   if !Empty( nFormat := GetClipContentFormat( nFormat ) )
      if OpenClipBoard( GetDeskTopWindow() )
         uData := GetClpData( nFormat )
         EmptyClipboard()
         CloseClipboard()
      endif
   endif

   do case
   case nFormat == 15   // CF_HDROP
      uData := If( Empty( uData ), {}, DragQueryFiles( uData ) )
   case nFormat == 13    // CF_UNICODETEXT
      if !Empty( uData ) //.and. IsTextUnicode( uData )
         uData := UTF16TOUTF8( uData )
      endif
   endcase

return uData

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


Image

Please use an editor which treats all UTF8 text correctly for Unicode programs
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: SetClipboardData to UTF-8

Postby nageswaragunupudi » Fri Jun 30, 2023 12:30 pm

I tried to copy your text from the webpage to notepad (utf8).
Image

Second line not copied correctly.
What is happening?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: SetClipboardData to UTF-8

Postby nageswaragunupudi » Fri Jun 30, 2023 12:56 pm

Mr Froze
In your postings above, you were also posting hex codes.
May I know how were you deriving those hex codes?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: SetClipboardData to UTF-8

Postby frose » Sat Jul 01, 2023 8:27 am

nageswaragunupudi wrote:Second line not copied correctly.
What is happening?

Mr. Rao,
yes, it must be something if the values are extracted from a TXBrowse!
I will explore this and come back to it.
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: SetClipboardData to UTF-8

Postby frose » Sat Jul 01, 2023 8:28 am

nageswaragunupudi wrote:May I know how were you deriving those hex codes?


Code: Select all  Expand view  RUN
StrToHex( cVar1, " " )
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: SetClipboardData to UTF-8

Postby frose » Sat Jul 01, 2023 8:35 am

nageswaragunupudi wrote:Please run this program as it is:
...

Yes all compares are 'exactly equal', so that we can assume, that the clipboard runs well under UTF-8 :D
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: SetClipboardData to UTF-8

Postby nageswaragunupudi » Sat Jul 01, 2023 8:56 am

frose wrote:
nageswaragunupudi wrote:Please run this program as it is:
...

Yes all compares are 'exactly equal', so that we can assume, that the clipboard runs well under UTF-8 :D


From now onwards, please use the above two functions.
I noticed a small bug in TClipboard class and do not use it till it is fixed (for Unicode only)
Both the above functions are available in FWH2204 but the second function requires a fix. Fixed in the version under release.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: SetClipboardData to UTF-8

Postby frose » Sat Jul 01, 2023 3:24 pm

frose wrote:
nageswaragunupudi wrote:Second line not copied correctly.
What is happening?

Mr. Rao,
yes, it must be something if the values are extracted from a TXBrowse!
I will explore this and come back to it.

Have cleaned up the source code, now it works :oops:
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 100 guests