Changeset 46313 in vbox for trunk/src/VBox/GuestHost
- Timestamp:
- May 29, 2013 2:13:03 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 86079
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp
r46307 r46313 54 54 #include <VBox/HostServices/VBoxClipboardSvc.h> 55 55 56 static Atom clipGetAtom( Widget widget, const char *pszName);56 static Atom clipGetAtom(CLIPBACKEND *pCtx, const char *pszName); 57 57 58 58 /** The different clipboard formats which we support. */ … … 105 105 * @param widget a valid Xt widget 106 106 */ 107 static Atom clipAtomForX11Format( Widget widget, CLIPX11FORMAT format)108 { 109 return clipGetAtom( widget, g_aFormats[format].pcszAtom);107 static Atom clipAtomForX11Format(CLIPBACKEND *pCtx, CLIPX11FORMAT format) 108 { 109 return clipGetAtom(pCtx, g_aFormats[format].pcszAtom); 110 110 } 111 111 … … 126 126 * @param widget a valid Xt widget 127 127 */ 128 static CLIPX11FORMAT clipFindX11FormatByAtom( Widget widget, Atom atomFormat)128 static CLIPX11FORMAT clipFindX11FormatByAtom(CLIPBACKEND *pCtx, Atom atomFormat) 129 129 { 130 130 for (unsigned i = 0; i < RT_ELEMENTS(g_aFormats); ++i) 131 if (clipAtomForX11Format( widget, i) == atomFormat)131 if (clipAtomForX11Format(pCtx, i) == atomFormat) 132 132 return i; 133 133 return NIL_CLIPX11FORMAT; … … 273 273 /** Convert an atom name string to an X11 atom, looking it up in a cache 274 274 * before asking the server */ 275 static Atom clipGetAtom( Widget widget, const char *pszName)275 static Atom clipGetAtom(CLIPBACKEND *pCtx, const char *pszName) 276 276 { 277 277 AssertPtrReturn(pszName, None); 278 Atom retval = None; 279 XrmValue nameVal, atomVal; 280 nameVal.addr = (char *) pszName; 281 nameVal.size = strlen(pszName); 282 atomVal.size = sizeof(Atom); 283 atomVal.addr = (char *) &retval; 284 XtConvertAndStore(widget, XtRString, &nameVal, XtRAtom, &atomVal); 285 return retval; 278 return XInternAtom(XtDisplay(pCtx->widget), pszName, False); 286 279 } 287 280 … … 354 347 for (unsigned i = 0; i < cTargets; ++i) 355 348 { 356 CLIPX11FORMAT format = clipFindX11FormatByAtom(pCtx->widget, 357 pTargets[i]); 349 CLIPX11FORMAT format = clipFindX11FormatByAtom(pCtx, pTargets[i]); 358 350 if (format != NIL_CLIPX11FORMAT) 359 351 { … … 376 368 Atom targets[2]; 377 369 CLIPX11FORMAT x11Format; 378 targets[0] = clipGetAtom( NULL, "text/plain");379 targets[1] = clipGetAtom( NULL, "TARGETS");370 targets[0] = clipGetAtom(pCtx, "text/plain"); 371 targets[1] = clipGetAtom(pCtx, "TARGETS"); 380 372 x11Format = clipGetTextFormatFromTargets(pCtx, targets, 3); 381 373 if (clipRealFormatForX11Format(x11Format) != TEXT) 382 374 success = false; 383 targets[0] = clipGetAtom( NULL, "UTF8_STRING");384 targets[1] = clipGetAtom( NULL, "text/plain");375 targets[0] = clipGetAtom(pCtx, "UTF8_STRING"); 376 targets[1] = clipGetAtom(pCtx, "text/plain"); 385 377 x11Format = clipGetTextFormatFromTargets(pCtx, targets, 3); 386 378 if (clipRealFormatForX11Format(x11Format) != UTF8) … … 408 400 for (unsigned i = 0; i < cTargets; ++i) 409 401 { 410 CLIPX11FORMAT format = clipFindX11FormatByAtom(pCtx->widget, 411 pTargets[i]); 402 CLIPX11FORMAT format = clipFindX11FormatByAtom(pCtx, pTargets[i]); 412 403 if (format != NIL_CLIPX11FORMAT) 413 404 { … … 527 518 pCtx->fBusy = true; 528 519 XtGetSelectionValue(pCtx->widget, 529 clipGetAtom(pCtx ->widget, "CLIPBOARD"),530 clipGetAtom(pCtx ->widget, "TARGETS"),520 clipGetAtom(pCtx, "CLIPBOARD"), 521 clipGetAtom(pCtx, "TARGETS"), 531 522 clipConvertX11Targets, pCtx, 532 523 CurrentTime); … … 730 721 /* Enable clipboard update notification */ 731 722 pCtx->fixesSelectInput(pDisplay, XtWindow(pCtx->widget), 732 clipGetAtom(pCtx ->widget, "CLIPBOARD"),723 clipGetAtom(pCtx, "CLIPBOARD"), 733 724 7 /* All XFixes*Selection*NotifyMask flags */); 734 725 #endif … … 912 903 if (format != NIL_CLIPX11FORMAT) 913 904 { 914 atomTargets[cTargets] = clipAtomForX11Format(pCtx->widget, 915 format); 905 atomTargets[cTargets] = clipAtomForX11Format(pCtx, format); 916 906 ++cTargets; 917 907 } 918 908 } while (format != NIL_CLIPX11FORMAT); 919 909 /* We always offer these */ 920 atomTargets[cTargets] = clipGetAtom(pCtx ->widget, "TARGETS");921 atomTargets[cTargets + 1] = clipGetAtom(pCtx ->widget, "MULTIPLE");922 atomTargets[cTargets + 2] = clipGetAtom(pCtx ->widget, "TIMESTAMP");910 atomTargets[cTargets] = clipGetAtom(pCtx, "TARGETS"); 911 atomTargets[cTargets + 1] = clipGetAtom(pCtx, "MULTIPLE"); 912 atomTargets[cTargets + 2] = clipGetAtom(pCtx, "TIMESTAMP"); 923 913 *atomTypeReturn = XA_ATOM; 924 914 *pValReturn = (XtPointer)atomTargets; … … 1080 1070 * @param selType the atom in question 1081 1071 */ 1082 static bool clipIsSupportedSelectionType( Widget widget, Atom selType)1083 { 1084 return( (selType == clipGetAtom( widget, "CLIPBOARD"))1085 || (selType == clipGetAtom( widget, "PRIMARY")));1072 static bool clipIsSupportedSelectionType(CLIPBACKEND *pCtx, Atom selType) 1073 { 1074 return( (selType == clipGetAtom(pCtx, "CLIPBOARD")) 1075 || (selType == clipGetAtom(pCtx, "PRIMARY"))); 1086 1076 } 1087 1077 … … 1110 1100 { 1111 1101 int rc = VINF_SUCCESS; 1112 CLIPX11FORMAT x11Format = clipFindX11FormatByAtom(pCtx->widget, 1113 *atomTarget); 1102 CLIPX11FORMAT x11Format = clipFindX11FormatByAtom(pCtx, *atomTarget); 1114 1103 CLIPFORMAT format = clipRealFormatForX11Format(x11Format); 1115 1104 if ( ((format == UTF8) || (format == TEXT)) … … 1180 1169 if (!pCtx) 1181 1170 return false; 1182 if (!clipIsSupportedSelectionType(pCtx ->widget, *atomSelection))1171 if (!clipIsSupportedSelectionType(pCtx, *atomSelection)) 1183 1172 return false; 1184 if (*atomTarget == clipGetAtom(pCtx ->widget, "TARGETS"))1173 if (*atomTarget == clipGetAtom(pCtx, "TARGETS")) 1185 1174 rc = clipCreateX11Targets(pCtx, atomTypeReturn, pValReturn, 1186 1175 pcLenReturn, piFormatReturn); … … 1216 1205 static void clipGrabX11CB(CLIPBACKEND *pCtx, uint32_t u32Formats) 1217 1206 { 1218 if (XtOwnSelection(pCtx->widget, clipGetAtom(pCtx ->widget, "CLIPBOARD"),1207 if (XtOwnSelection(pCtx->widget, clipGetAtom(pCtx, "CLIPBOARD"), 1219 1208 CurrentTime, clipXtConvertSelectionProc, NULL, 0)) 1220 1209 { 1221 1210 pCtx->vboxFormats = u32Formats; 1222 1211 /* Grab the middle-button paste selection too. */ 1223 XtOwnSelection(pCtx->widget, clipGetAtom(pCtx ->widget, "PRIMARY"),1212 XtOwnSelection(pCtx->widget, clipGetAtom(pCtx, "PRIMARY"), 1224 1213 CurrentTime, clipXtConvertSelectionProc, NULL, 0); 1225 1214 #ifndef TESTCASE … … 1227 1216 * ourselves. */ 1228 1217 XSetSelectionOwner(XtDisplay(pCtx->widget), 1229 clipGetAtom(pCtx ->widget, "CLIPBOARD"),1218 clipGetAtom(pCtx, "CLIPBOARD"), 1230 1219 XtWindow(pCtx->widget), CurrentTime); 1231 1220 XSetSelectionOwner(XtDisplay(pCtx->widget), 1232 clipGetAtom(pCtx ->widget, "PRIMARY"),1221 clipGetAtom(pCtx, "PRIMARY"), 1233 1222 XtWindow(pCtx->widget), CurrentTime); 1234 1223 #endif … … 1564 1553 /* Send out a request for the data to the current clipboard 1565 1554 * owner */ 1566 XtGetSelectionValue(pCtx->widget, clipGetAtom(pCtx->widget, "CLIPBOARD"), 1567 clipAtomForX11Format(pCtx->widget, 1568 pCtx->X11TextFormat), 1555 XtGetSelectionValue(pCtx->widget, clipGetAtom(pCtx, "CLIPBOARD"), 1556 clipAtomForX11Format(pCtx, pCtx->X11TextFormat), 1569 1557 clipConvertX11CB, 1570 1558 reinterpret_cast<XtPointer>(pReq), … … 1580 1568 /* Send out a request for the data to the current clipboard 1581 1569 * owner */ 1582 XtGetSelectionValue(pCtx->widget, clipGetAtom(pCtx ->widget, "CLIPBOARD"),1583 clipAtomForX11Format(pCtx ->widget,1570 XtGetSelectionValue(pCtx->widget, clipGetAtom(pCtx, "CLIPBOARD"), 1571 clipAtomForX11Format(pCtx, 1584 1572 pCtx->X11BitmapFormat), 1585 1573 clipConvertX11CB, … … 1762 1750 /* This just looks for the atom names in a couple of tables and returns an 1763 1751 * index with an offset added. */ 1764 Boolean XtConvertAndStore(Widget widget, _Xconst _XtString from_type, 1765 XrmValue* from, _Xconst _XtString to_type, 1766 XrmValue* to_in_out) 1767 { 1768 Boolean rc = False; 1769 /* What we support is: */ 1770 AssertReturn(from_type == XtRString, False); 1771 AssertReturn(to_type == XtRAtom, False); 1752 Atom XInternAtom(Display *, const char *pcsz, int) 1753 { 1754 Atom atom = 0; 1772 1755 for (unsigned i = 0; i < RT_ELEMENTS(g_aFormats); ++i) 1773 if (!strcmp(from->addr, g_aFormats[i].pcszAtom)) 1774 { 1775 *(Atom *)(to_in_out->addr) = (Atom) (i + 0x1000); 1776 rc = True; 1777 } 1756 if (!strcmp(pcsz, g_aFormats[i].pcszAtom)) 1757 atom = (Atom) (i + 0x1000); 1778 1758 for (unsigned i = 0; i < RT_ELEMENTS(g_apszSupAtoms); ++i) 1779 if (!strcmp(from->addr, g_apszSupAtoms[i])) 1780 { 1781 *(Atom *)(to_in_out->addr) = (Atom) (i + 0x2000); 1782 rc = True; 1783 } 1784 Assert(rc == True); /* Have we missed any atoms? */ 1785 return rc; 1759 if (!strcmp(pcsz, g_apszSupAtoms[i])) 1760 atom = (Atom) (i + 0x2000); 1761 Assert(atom); /* Have we missed any atoms? */ 1762 return atom; 1786 1763 } 1787 1764 … … 1803 1780 int format = 0; 1804 1781 Atom type = XA_STRING; 1805 if ( ( selection != clipGetAtom(NULL, "PRIMARY")1806 && selection != clipGetAtom(NULL, "CLIPBOARD")1807 && selection != clipGetAtom(NULL, "TARGETS"))1782 if ( ( selection != XInternAtom(NULL, "PRIMARY", 0) 1783 && selection != XInternAtom(NULL, "CLIPBOARD", 0) 1784 && selection != XInternAtom(NULL, "TARGETS", 0)) 1808 1785 || ( target != g_selTarget[0] 1809 && target != clipGetAtom(NULL, "TARGETS")))1786 && target != XInternAtom(NULL, "TARGETS", 0))) 1810 1787 { 1811 1788 /* Otherwise this is probably a caller error. */ … … 1816 1793 } 1817 1794 XtPointer pValue = NULL; 1818 if (target == clipGetAtom(NULL, "TARGETS"))1795 if (target == XInternAtom(NULL, "TARGETS", 0)) 1819 1796 { 1820 1797 if (g_fTargetsFailure) … … 1877 1854 XtSelectionDoneProc done) 1878 1855 { 1879 if (selection != clipGetAtom(NULL, "CLIPBOARD"))1856 if (selection != XInternAtom(NULL, "CLIPBOARD", 0)) 1880 1857 return True; /* We don't really care about this. */ 1881 1858 g_ownsSel = true; /* Always succeed. */ … … 1899 1876 int *format) 1900 1877 { 1901 Atom target = clipGetAtom(NULL, pcszTarget);1878 Atom target = XInternAtom(NULL, pcszTarget, 0); 1902 1879 if (target == 0) 1903 1880 return false; … … 1911 1888 if (!g_pfnSelConvert) 1912 1889 return false; 1913 Atom clipAtom = clipGetAtom(NULL, "CLIPBOARD");1890 Atom clipAtom = XInternAtom(NULL, "CLIPBOARD", 0); 1914 1891 if (!g_pfnSelConvert(TEST_WIDGET, &clipAtom, &target, type, 1915 1892 value, length, format)) … … 1925 1902 unsigned long count, int format) 1926 1903 { 1927 Atom clipAtom = clipGetAtom(NULL, "CLIPBOARD");1928 g_selTarget[0] = clipGetAtom(NULL, pcszTarget);1904 Atom clipAtom = XInternAtom(NULL, "CLIPBOARD", 0); 1905 g_selTarget[0] = XInternAtom(NULL, pcszTarget, 0); 1929 1906 g_selType = type; 1930 1907 g_pSelData = data; … … 2360 2337 sizeof("hello world") * 2); 2361 2338 testStringFromVBox(hTest, pCtx, "UTF8_STRING", 2362 clipGetAtom( NULL, "UTF8_STRING"), "hello world");2339 clipGetAtom(pCtx, "UTF8_STRING"), "hello world"); 2363 2340 /* With an embedded carriage return */ 2364 2341 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\nworld", 2365 2342 sizeof("hello\r\nworld") * 2); 2366 2343 testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8", 2367 clipGetAtom( NULL, "text/plain;charset=UTF-8"),2344 clipGetAtom(pCtx, "text/plain;charset=UTF-8"), 2368 2345 "hello\nworld"); 2369 2346 /* With an embedded CRCRLF */ … … 2371 2348 sizeof("hello\r\r\nworld") * 2); 2372 2349 testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8", 2373 clipGetAtom( NULL, "text/plain;charset=UTF-8"),2350 clipGetAtom(pCtx, "text/plain;charset=UTF-8"), 2374 2351 "hello\r\nworld"); 2375 2352 /* With an embedded CRLFCR */ … … 2377 2354 sizeof("hello\r\n\rworld") * 2); 2378 2355 testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8", 2379 clipGetAtom( NULL, "text/plain;charset=UTF-8"),2356 clipGetAtom(pCtx, "text/plain;charset=UTF-8"), 2380 2357 "hello\n\rworld"); 2381 2358 /* An empty string */ 2382 2359 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2); 2383 2360 testStringFromVBox(hTest, pCtx, "text/plain;charset=utf-8", 2384 clipGetAtom( NULL, "text/plain;charset=utf-8"), "");2361 clipGetAtom(pCtx, "text/plain;charset=utf-8"), ""); 2385 2362 /* With an embedded Utf-8 character. */ 2386 2363 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "100\xE2\x82\xAC" /* 100 Euro */, 2387 2364 10); 2388 2365 testStringFromVBox(hTest, pCtx, "STRING", 2389 clipGetAtom( NULL, "STRING"), "100\xE2\x82\xAC");2366 clipGetAtom(pCtx, "STRING"), "100\xE2\x82\xAC"); 2390 2367 /* A non-zero-terminated string */ 2391 2368 clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world", 2392 2369 sizeof("hello world") * 2 - 2); 2393 testStringFromVBox(hTest, pCtx, "TEXT", clipGetAtom( NULL, "TEXT"),2370 testStringFromVBox(hTest, pCtx, "TEXT", clipGetAtom(pCtx, "TEXT"), 2394 2371 "hello world"); 2395 2372
Note:
See TracChangeset
for help on using the changeset viewer.