CVS: tvision/classes/x11 x11src.cc,1.63.2.38,1.63.2.39
Brought to you by:
set
From: Salvador E. T. <se...@us...> - 2017-08-01 14:10:44
|
Update of /cvsroot/tvision/tvision/classes/x11 In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv2537/classes/x11 Modified Files: Tag: r2_0_1u x11src.cc Log Message: * Added: [TVCodePage] Functions to convert the app cp to and from UTF8 (convertStrUTF8_2_CP and convertStrCP_2_UTF8). * Added: [X11] Support for copy/paste using UTF8. Index: x11src.cc =================================================================== RCS file: /cvsroot/tvision/tvision/classes/x11/x11src.cc,v retrieving revision 1.63.2.38 retrieving revision 1.63.2.39 diff -C2 -d -r1.63.2.38 -r1.63.2.39 *** x11src.cc 31 Jul 2017 22:47:49 -0000 1.63.2.38 --- x11src.cc 1 Aug 2017 14:10:40 -0000 1.63.2.39 *************** *** 1,4 **** /* X11 screen routines. ! Copyright (c) 2001-2012 by Salvador E. Tropea (SET) Covered by the GPL license. Thanks to José Ángel Sánchez Caso (JASC). He implemented a first X11 --- 1,4 ---- /* X11 screen routines. ! Copyright (c) 2001-2017 by Salvador E. Tropea (SET) Covered by the GPL license. Thanks to José Ángel Sánchez Caso (JASC). He implemented a first X11 *************** *** 123,127 **** /* Clipboard properties */ Atom TScreenX11::XA_TARGETS; ! Atom TScreenX11::XA_MULTIPLE; ulong TScreenX11::colorMap[16]; XImage *TScreenX11::ximgFont[256]; /* Our "font" is just a collection of images */ --- 123,127 ---- /* Clipboard properties */ Atom TScreenX11::XA_TARGETS; ! Atom TScreenX11::XA_UTF8_STRING; ulong TScreenX11::colorMap[16]; XImage *TScreenX11::ximgFont[256]; /* Our "font" is just a collection of images */ *************** *** 1659,1663 **** XA_TARGETS=XInternAtom(disp,"TARGETS",False); ! XA_MULTIPLE=XInternAtom(disp,"MULTIPLE",False); /* Initialize the Input Context for international support */ --- 1659,1663 ---- XA_TARGETS=XInternAtom(disp,"TARGETS",False); ! XA_UTF8_STRING=XInternAtom(disp,"UTF8_STRING",False); /* Initialize the Input Context for international support */ *************** *** 2014,2034 **** if (req->target==XA_TARGETS) { // This is a request of the supported formats ! Atom targets[]={XA_TARGETS,XA_MULTIPLE,XA_STRING}; XChangeProperty(disp,req->requestor,req->property,XA_ATOM,32,PropModeReplace, (const uchar *)targets,3); } ! else if (req->target==XA_MULTIPLE) ! { ! printf("XA_MULTIPLE, please contact author\n"); ! respond.xselection.property=None; ! } ! else if (req->target==XA_STRING && TVX11Clipboard::buffer) { XChangeProperty(disp,req->requestor,req->property,XA_STRING, ! 8/*bits*/,PropModeReplace, (const uchar *)TVX11Clipboard::buffer, TVX11Clipboard::length); } ! else // Strings only please { //printf("Unknown target (%s)\n",XGetAtomName(disp,req->target)); --- 2014,2044 ---- if (req->target==XA_TARGETS) { // This is a request of the supported formats ! Atom targets[]={XA_TARGETS,XA_UTF8_STRING,XA_STRING}; XChangeProperty(disp,req->requestor,req->property,XA_ATOM,32,PropModeReplace, (const uchar *)targets,3); } ! else if (TVX11Clipboard::buffer && req->target==XA_STRING) { XChangeProperty(disp,req->requestor,req->property,XA_STRING, ! 8,PropModeReplace, (const uchar *)TVX11Clipboard::buffer, TVX11Clipboard::length); } ! else if (TVX11Clipboard::buffer && req->target==XA_UTF8_STRING) ! {// Convert the buffer to UTF8 ! int cnvLen=TVCodePage::convertStrCP_2_UTF8(NULL,TVX11Clipboard::buffer,TVX11Clipboard::length); ! if (cnvLen==-1) ! // The selection can't be represented using UTF8 ! respond.xselection.property=None; ! else ! { ! char *data=new char[cnvLen+1]; ! TVCodePage::convertStrCP_2_UTF8(data,TVX11Clipboard::buffer,TVX11Clipboard::length); ! XChangeProperty(disp,req->requestor,req->property,XA_UTF8_STRING, ! 8,PropModeReplace,(const uchar *)data,cnvLen); ! delete[] data; ! } ! } ! else // Unsupported target or no selection { //printf("Unknown target (%s)\n",XGetAtomName(disp,req->target)); *************** *** 2318,2322 **** __("No data"), __("X11 error"), ! __("Another application holds the clipboard") }; --- 2328,2333 ---- __("No data"), __("X11 error"), ! __("Another application holds the clipboard"), ! __("Malformed UTF8 string") }; *************** *** 2396,2399 **** --- 2407,2411 ---- unsigned char *data; + // Find who owns the selection owner=XGetSelectionOwner(TScreenX11::disp,clip); if (owner==None) *************** *** 2403,2410 **** return NULL; } ! // What a hell should I use as property here? I use XA_STRING because it was ! // used by the example. BTW the example failed with Eterm. ! XConvertSelection(TScreenX11::disp,clip,XA_STRING,XA_STRING,TScreenX11::mainWin, ! CurrentTime); XFlush(TScreenX11::disp); SEMAPHORE_OFF; --- 2415,2421 ---- return NULL; } ! // Ask for the data as an UTF8 string ! Atom target=TScreenX11::XA_UTF8_STRING; ! XConvertSelection(TScreenX11::disp,clip,target,target,TScreenX11::mainWin,CurrentTime); XFlush(TScreenX11::disp); SEMAPHORE_OFF; *************** *** 2414,2426 **** TScreenX11::ProcessGenericEvents(); ! if (property!=XA_STRING) ! { ! TVOSClipboard::error=x11clipWrongType; ! return NULL; } // Check the size SEMAPHORE_ON; Atom type; ! XGetWindowProperty(TScreenX11::disp,TScreenX11::mainWin,XA_STRING,0,0,0, AnyPropertyType,&type,&format,&len,&bytes,&data); if (bytes<=0) --- 2425,2451 ---- TScreenX11::ProcessGenericEvents(); ! // The owner could reply with None if UTF8 isn't supported or the selection can't be ! // converted to a string ! if (property!=target) ! {// Try again with a plain string ! target=XA_STRING; ! SEMAPHORE_ON; ! XConvertSelection(TScreenX11::disp,clip,target,target,TScreenX11::mainWin,CurrentTime); ! XFlush(TScreenX11::disp); ! SEMAPHORE_OFF; ! waiting=1; ! while (waiting) ! if (!IS_SECOND_THREAD_ON) ! TScreenX11::ProcessGenericEvents(); ! if (property!=target) ! {// The selection can't be pasted as a string ! TVOSClipboard::error=x11clipWrongType; ! return NULL; ! } } // Check the size SEMAPHORE_ON; Atom type; ! XGetWindowProperty(TScreenX11::disp,TScreenX11::mainWin,property,0,0,0, AnyPropertyType,&type,&format,&len,&bytes,&data); if (bytes<=0) *************** *** 2430,2434 **** return NULL; } ! result=XGetWindowProperty(TScreenX11::disp,TScreenX11::mainWin,XA_STRING, 0,bytes,0,AnyPropertyType,&type,&format,&len, &dummy,&data); --- 2455,2460 ---- return NULL; } ! // Now get the selection ! result=XGetWindowProperty(TScreenX11::disp,TScreenX11::mainWin,property, 0,bytes,0,AnyPropertyType,&type,&format,&len, &dummy,&data); *************** *** 2440,2448 **** return NULL; } ! char *ret=new char[bytes+1]; ! memcpy(ret,data,bytes); ! ret[bytes]=0; XFree(data); - lenRet=bytes; SEMAPHORE_OFF; //printf("Recibiendo: `%s' %ld\n",ret,bytes); --- 2466,2494 ---- return NULL; } ! // Copy the selection to a local buffer ! char *ret=NULL; ! if (target==TScreenX11::XA_UTF8_STRING) ! {// Convert the UTF8 string to the app codepage ! int cnvLen=TVCodePage::convertStrUTF8_2_CP(NULL,(const char *)data,bytes); ! if (cnvLen!=-1) ! { ! ret=new char[cnvLen+1]; ! lenRet=cnvLen; ! TVCodePage::convertStrUTF8_2_CP(ret,(const char *)data,bytes); ! } ! else ! TVOSClipboard::error=x11clipUTF8Error; ! //printf("UTF8 data: %s ret: %s\n",data,ret); ! } ! else ! {// Just make a copy ! ret=new char[bytes+1]; ! memcpy(ret,data,bytes); ! ret[bytes]=0; ! lenRet=bytes; ! //printf("String: %s\n",ret); ! } ! // Release the data XFree(data); SEMAPHORE_OFF; //printf("Recibiendo: `%s' %ld\n",ret,bytes); |