[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: fix for QClipboard on X11
From:       Takumi ASAKI <asataku () osk3 ! 3web ! ne ! jp>
Date:       2000-09-23 16:48:02
[Download RAW message or body]

------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

In message <Pine.BSF.4.21.0009202034290.20904-200000@reticent.troll.no>
	"Bradley T. Hughes" <bhughes@trolltech.com> wrote:

>This patch is against a clean 2.2.0 tree, and adds multibyte selection
>capabilities (and a small 64 bit cleanness fix as well)...

This patch is not work for multibyte (COMPOUND_TEXT, CTEXT).

Because QClipboard::event() wants to support XA_STRING and COMPOUND_TEXT.
But it calls QClipboardWatcher::encodedData with "text/plain".
QClipboardWatcher::encodedData calls getDataInFormat with XA_STRING.
So, never calls getDataInforMat with COMPOUND_TEXT.

I wrote additional patch for QClipboard.

It support COMPOUND_TEXT and UTF8_STRING.
About UTF8_STRING, please look at
http://www.dcs.ed.ac.uk/home/jec/programs/xfsft/UTF8-selections.text

-- 
  Che Che - Bye Bye
          From: Takumi ASAKI <asataku@osk3.3web.ne.jp>
          URL: http://www3.osk.3web.ne.jp/~asataku/

------- =_aaaaaaaaaa0
Content-Type: text/plain; name="qt-2.2.0-qclipboard-20000923.diff";
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

diff -cr qt-2.2.0.orig/src/kernel/qclipboard_x11.cpp qt-2.2.0/src/kernel/qclipboard_x11.cpp
*** qt-2.2.0.orig/src/kernel/qclipboard_x11.cpp	Sat Sep 23 16:58:15 2000
--- qt-2.2.0/src/kernel/qclipboard_x11.cpp	Sat Sep 23 18:10:57 2000
***************
*** 477,482 ****
--- 477,483 ----
  	    static Atom xa_multiple = *qt_xdnd_str_to_atom( "MULTIPLE" );
  	    static Atom xa_text = *qt_xdnd_str_to_atom("TEXT");
  	    static Atom xa_compound = *qt_xdnd_str_to_atom("COMPOUND_TEXT");
+ 	    static Atom xa_utf8 = *qt_xdnd_str_to_atom("UTF8_STRING");
  	    struct AtomPair { Atom target; Atom property; } *multi = 0;
  	    int nmulti = 0;
  	    int imulti = -1;
***************
*** 514,520 ****
  		    if (d->source()->provides("image/pbm")) atoms++;
  		    
  		    // local 8 bit and compound (multibyte) text
! 		    if (d->source()->provides("text/plain")) atoms += 2;
  		    
  #ifdef QT_CLIPBOARD_DEBUG
  		    qDebug("qclipboard_x11.cpp:%d: %d provided types", __LINE__, atoms);
--- 515,521 ----
  		    if (d->source()->provides("image/pbm")) atoms++;
  		    
  		    // local 8 bit and compound (multibyte) text
! 		    if (d->source()->provides("text/plain")) atoms += 3;
  		    
  #ifdef QT_CLIPBOARD_DEBUG
  		    qDebug("qclipboard_x11.cpp:%d: %d provided types", __LINE__, atoms);
***************
*** 550,555 ****
--- 551,557 ----
  
  		    // we support local 8bit strings and compound (multibyte) text
  		    if ( d->source()->provides("text/plain") ) {
+ 			atarget[n++] = xa_utf8;
  			atarget[n++] = xa_compound;
  			atarget[n++] = XA_STRING;
  		    }
***************
*** 569,575 ****
  		    if ( target == XA_STRING || target == xa_text ) {
  			fmt = "text/plain";
  		    } else if ( target == xa_compound ) {
! 			fmt = "text/plain";
  			data = d->source()->encodedData(fmt);
  			char *list[] = { data.data() };
  
--- 571,577 ----
  		    if ( target == XA_STRING || target == xa_text ) {
  			fmt = "text/plain";
  		    } else if ( target == xa_compound ) {
! 			fmt = "COMPOUND_TEXT";
  			data = d->source()->encodedData(fmt);
  			char *list[] = { data.data() };
  
***************
*** 682,687 ****
--- 684,730 ----
      // TODO: record these once
      static Atom xa_targets = *qt_xdnd_str_to_atom( "TARGETS" );
      QByteArray targets = getDataInFormat(xa_targets);
+ 
+     Atom* target = (Atom*)targets.data();
+     int natoms = targets.size()/sizeof(Atom);
+ 
+     static Atom xa_utf8 = *qt_xdnd_str_to_atom( "UTF8_STRING" );
+     static Atom xa_compound = *qt_xdnd_str_to_atom( "COMPOUND_TEXT" );
+     static Atom xa_text = *qt_xdnd_str_to_atom( "TEXT" );
+ 
+     int n_utf8 = -1;
+     int n_compound = -1;
+     int dn = 0;
+     for (int i = 0; i < natoms; i++) {
+         if (target[i] == xa_utf8) {
+             n_utf8 = i;
+             dn++;
+         }
+         if (target[i] == xa_compound) {
+             n_compound = i;
+             dn++;
+         }
+     }
+     if (dn > 0) {
+         int maxn = (n_utf8 > n_compound) ? n_utf8 : n_compound;
+         int minn = (n_utf8 < n_compound) ? n_utf8 : n_compound;
+         for (int i = 0; i < maxn; i++) {
+             if (target[i] == XA_STRING || target[i] == xa_text ||
+                 target[i] == xa_compound) {
+                 int k = 1;
+                 for (int j = maxn; j > i + (dn - 1); j--) {
+                     if (j-k == minn) {
+                         k++;
+                     }
+                     target[j] = target[j-k];
+                 }
+                 if (n_utf8 >= 0) target[i++] = xa_utf8;
+                 if (n_compound >= 0) target[i++] = xa_compound;
+                 break;
+             }
+         }
+     }
+ 
      if ( targets.size()/sizeof(Atom) > (uint)n ) {
  	Atom* target = (Atom*)targets.data();
  	if ( *target == XA_PIXMAP )
***************
*** 703,708 ****
--- 746,758 ----
      Atom fmtatom = 0;
  
      if ( 0==qstrcmp(fmt,"text/plain") ) {
+ #if 0
+         fmtatom = *qt_xdnd_str_to_atom("COMPOUND_TEXT");
+         QByteArray ctext = getDataInFormat(fmtatom);
+         if (ctext.size() != 0) {
+             return ctext;
+         }
+ #endif
     	fmtatom = XA_STRING;
      } else if ( 0==qstrcmp(fmt,"image/ppm") ) {
  	fmtatom = XA_PIXMAP;
diff -cr qt-2.2.0.orig/src/kernel/qdragobject.cpp qt-2.2.0/src/kernel/qdragobject.cpp
*** qt-2.2.0.orig/src/kernel/qdragobject.cpp	Mon Sep  4 02:38:13 2000
--- qt-2.2.0/src/kernel/qdragobject.cpp	Sat Sep 23 17:08:19 2000
***************
*** 733,739 ****
  		    }
  		}
  	    }
! 	}
      }
      return FALSE;
  }
--- 733,757 ----
  		    }
  		}
  	    }
! 	} else if ( 0==qstricmp(mime,"UTF8_STRING")) {
!             QByteArray payload;
!             payload = e->encodedData(mime);
!             // qDebug("QTextDrag::decode(): UTF8_STRING %d", payload.size());
!             if ( payload.size() ) {
!                 str = QString::fromUtf8(payload, payload.size());
!                 subtype = "plain;charset=UTF-8";
!                 return TRUE;
!             }
! 	} else if ( 0==qstricmp(mime,"COMPOUND_TEXT")) {
!             QByteArray payload;
!             payload = e->encodedData(mime);
!             // qDebug("QTextDrag::decode(): COMPOUND_TEXT %d", payload.size());
!             if ( payload.size() ) {
!                 str = QString::fromLocal8Bit(payload, payload.size());
!                 subtype = "plain";
!                 return TRUE;
!             }
!         }
      }
      return FALSE;
  }

------- =_aaaaaaaaaa0--
 
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic