00001 /*======================================================================= 00002 * Copyright 1991-1996, Silicon Graphics, Inc. 00003 * ALL RIGHTS RESERVED 00004 * 00005 * UNPUBLISHED -- Rights reserved under the copyright laws of the United 00006 * States. Use of a copyright notice is precautionary only and does not 00007 * imply publication or disclosure. 00008 * 00009 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: 00010 * Use, duplication or disclosure by the Government is subject to restrictions 00011 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights 00012 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or 00013 * in similar or successor clauses in the FAR, or the DOD or NASA FAR 00014 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., 00015 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. 00016 * 00017 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY 00018 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, 00019 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY 00020 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON 00021 * GRAPHICS, INC. 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Author : David Mott (MMM yyyy) 00025 **=======================================================================*/ 00026 /*======================================================================= 00027 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00028 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00029 *** *** 00030 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00031 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00032 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00033 *** *** 00034 *** RESTRICTED RIGHTS LEGEND *** 00035 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00036 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00037 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00038 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00039 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00040 *** *** 00041 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00042 *** BORDEAUX, FRANCE *** 00043 *** ALL RIGHTS RESERVED *** 00044 **=======================================================================*/ 00045 /*======================================================================= 00046 ** Modified by : VSG (MMM YYYY) 00047 **=======================================================================*/ 00048 00049 00050 #ifdef _WIN32 00051 # include <Inventor/Win/SoWinClipboard.h> 00052 #else // _WIN32 00053 00054 #ifndef _SO_XT_CLIPBOARD_ 00055 #define _SO_XT_CLIPBOARD_ 00056 00057 #include <X11/Xatom.h> 00058 #include <X11/Intrinsic.h> 00059 #include <Inventor/SbBasic.h> 00060 #include <Inventor/Xt/SoXtDef.h> 00061 00062 class SbDict; 00063 class SoByteStream; 00064 class SoNode; 00065 class SoPath; 00066 class SoPathList; 00067 class SoSelection; 00068 class SoXtImportInterestList; 00069 class SbString; 00070 class SbPList; 00071 00072 00073 // callback function prototypes 00074 typedef void SoXtClipboardPasteCB(void *userData, SoPathList *pathList); 00075 typedef void SoXtClipboardImportCB( 00076 void *userData, 00077 Atom dataType, 00078 void *data, 00079 uint32_t numBytes); 00080 00081 00082 // The CLIPBOARD selection atom is not a predefined atom in X11 R4. 00083 // However, it is widely recognized. We define it to 0 here for 00084 // convenience. Internally, when SoXtClipboard sees _XA_CLIPBOARD_, 00085 // it will use XInternAtom(d, "CLIPBOARD", False). 00086 00087 #define _XA_CLIPBOARD_ ((Atom) 0) 00088 00090 // 00091 // Class: SoXtClipboard 00092 // 00093 // 00095 00113 class SoXtClipboard { 00114 public: 00115 // Constructor. 00116 // The selection atom determines which X selection atom data transfers 00117 // should happen through. Default is _XA_CLIPBOARD_. (wsh uses XA_PRIMARY). 00118 00125 SoXtClipboard(SoWidget w, Atom selectionAtom = _XA_CLIPBOARD_); 00126 00130 ~SoXtClipboard(); 00131 00132 // 00133 // These methods transfer inventor scene graphs as the data. 00134 // 00135 00136 // Copy - these routines copy the passed data into a byte stream, 00137 // and make the data available to any X client which requests it. 00138 // The eventTime should be the time stamp from the event which 00139 // triggered the copy request. 00140 // 00141 // The standard Inventor targets will be exported: 00142 // INVENTOR_2_1 00143 // INVENTOR_2_1_FILE 00144 // VRML_1_0 00145 // VRML_1_0_FILE 00146 // INVENTOR 00147 // INVENTOR_FILE 00148 // INVENTOR_2_0 00149 // INVENTOR_2_0_FILE 00150 00163 void copy(SoNode *node, Time eventTime); 00164 00170 void copy(SoPath *path, Time eventTime); 00171 00177 void copy(SoPathList *pathList, Time eventTime); 00178 00179 // This copies non-Inventor data to the clipboard 00180 void copy(Atom dataType, void *data, uint32_t numBytes, Time eventTime); 00181 00182 // Paste - make a request to the X server so we can import data for paste. 00183 // A paste is asynchronous - when this routine is called, it simply 00184 // makes a request to the X server for data to paste, then returns. 00185 // Once the data is delivered, the pasteDoneFunc will be called and passed 00186 // the user data along with a list of paths that were pasted. The app 00187 // should delete this path list when it is done with it. 00188 // The eventTime should be the time stamp from the event which 00189 // triggered the paste request. 00190 // 00191 // The standard Inventor targets will be recognized: 00192 // INVENTOR_2_1 00193 // INVENTOR_2_1_FILE 00194 // VRML_1_0 00195 // VRML_1_0_FILE 00196 // INVENTOR 00197 // INVENTOR_FILE 00198 // INVENTOR_2_0 00199 // INVENTOR_2_0_FILE 00200 // XA_STRING - if the string describes ascii Inventor data 00201 00212 void paste(Time eventTime, 00213 SoXtClipboardPasteCB *pasteDoneFunc, 00214 void *userData = NULL); 00215 00216 // This extends the paste interest to recognize an additional target as 00217 // specified by 'dataType'. The pasteImportFunc will be called when this 00218 // type of data is pasted. This may be called multiple times to register 00219 // interest in more than one extension. 00220 // 00221 // Passing NULL as the pasteImportFunc will remove paste interest for that 00222 // data type (even if the data type is one of the defaults). 00223 // 00224 // This should be called before paste() so that paste() will look for data 00225 // types that have been specified here. 00226 // 00227 // The dataType atom can be created with XmInternAtom, e.g.: 00228 // XmInternAtom(XtDisplay(widget),"INVENTOR",False); 00229 // 00230 // The order is important - first things added to the list are the first 00231 // things searched for at paste time. (The default interest types come first.) 00232 00249 void addPasteInterest( 00250 Atom dataType, 00251 SoXtClipboardImportCB *pasteImportFunc, 00252 void *userData = NULL); 00253 00254 private: 00255 00256 // Convert the passed Inventor 2.1 data to a different format, specified by 00257 // the Atom desiredType. The data will be malloc'd here and placed in returnData, 00258 // with returnNumBytes describing the data length. This returns TRUE if successful. 00259 static SbBool convertData( 00260 SoWidget widget, 00261 void *srcData, 00262 uint32_t srcNumBytes, 00263 Atom desiredType, 00264 char **returnData, 00265 uint32_t *returnNumBytes); 00266 00267 private: 00268 // Sets a flag indicating whether the paste callback can and 00269 // should be passed an empty path list after a paste request is 00270 // made. For compatibility, this flag is FALSE by default, meaning 00271 // that the callback will never be invoked with an empty path list. 00272 void setEmptyListOK(SbBool flag) { emptyListOK = flag; } 00273 SbBool isEmptyListOK() const { return emptyListOK; } 00274 00275 private: 00276 SoWidget widget; // the widget to associated data with 00277 Atom clipboardAtom; // which selection: XA_PRIMARY, XA_SECONDARY, etc. 00278 Time eventTime; // time of the event which caused the copy/paste 00279 00280 // Paste callback info 00281 SoXtClipboardPasteCB *callbackFunc; 00282 void *userData; 00283 00284 // There can only be one owner of each X selection at any one time. 00285 // We use the selection atom as the key, and 'this' as the data. 00286 // We set the owner for each selection in this list for exportSelection. 00287 static SbDict *selOwnerList; 00288 00289 // All the overloaded copy functions call this one. 00290 void copy(SoByteStream *byteStream, Time t); 00291 00292 // This describes what data types we look for during paste. 00293 SoXtImportInterestList *pasteInterest; 00294 SbPList *copyInterest; 00295 00296 // This is called by exportSelection 00297 void getExportTargets( 00298 char **value, 00299 uint32_t *length); 00300 00301 Atom chooseFromImportTargets( 00302 Atom *supportedTargets, 00303 int length); 00304 00305 static SbBool writeToFile( 00306 SbString &tmpfile, 00307 void *srcData, 00308 uint32_t srcNumBytes); 00309 00310 // Read the file if it is in Inventor format and add its data to the pathList. 00311 static void readFile(SoPathList *&pathList, const char *filename); 00312 00313 // Read target data we just imported via paste or drop if it is in Inventor format. 00314 // This returns a newly allocated path list. This will free data when done. 00315 static SoPathList *readData( 00316 SoWidget w, 00317 Atom target, 00318 void *data, 00319 uint32_t numBytes); 00320 private: 00321 SoByteStream *copyBuffer; // copy/paste storage buffer 00322 Atom copyDataType; 00323 SbBool emptyListOK; 00324 00325 // This handles the default cases of paste 00326 void pasteImport(Atom dataType, void *data, uint32_t numBytes); 00327 static void pasteImportCB( 00328 void *userData, Atom dataType, 00329 void *data, uint32_t numBytes) 00330 { ((SoXtClipboard *)userData)->pasteImport(dataType, data, numBytes); } 00331 00332 // Copy and paste callback functions - these are called by the X server. 00333 // importSelection is called when we import data to paste. 00334 // exportSelection is called when we send data for someone else to paste. 00335 // loseSelection is called when we no longer own the selection. 00336 static void importSelection( 00337 SoWidget w, 00338 SoXtClipboard *clipboard, 00339 Atom *selAtom, 00340 Atom *type, 00341 char *value, 00342 uint32_t *length, 00343 int *format); 00344 00345 static Boolean exportSelection( 00346 SoWidget w, 00347 Atom *xselection, 00348 Atom *target, 00349 Atom *type, 00350 char **value, 00351 uint32_t *length, 00352 int *format); 00353 00354 static void loseSelection( 00355 SoWidget w, 00356 Atom *xselection); 00357 00358 static void importSelectionTargets( 00359 SoWidget w, 00360 SoXtClipboard *clipboard, 00361 Atom *selAtom, 00362 Atom *type, 00363 char *value, 00364 uint32_t *length, 00365 int *format); 00366 00367 }; 00368 00369 #endif /* _SO_XT_CLIPBOARD_ */ 00370 00371 #endif // _WIN32 00372 00373 00374