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-2014 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 00112 class SoXtClipboard { 00113 public: 00114 // Constructor. 00115 // The selection atom determines which X selection atom data transfers 00116 // should happen through. Default is _XA_CLIPBOARD_. (wsh uses XA_PRIMARY). 00117 00124 SoXtClipboard(SoWidget w, Atom selectionAtom = _XA_CLIPBOARD_); 00125 00129 ~SoXtClipboard(); 00130 00143 void copy(SoNode *node, Time eventTime); 00144 00150 void copy(SoPath *path, Time eventTime); 00151 00157 void copy(SoPathList *pathList, Time eventTime); 00158 00159 // This copies non-Inventor data to the clipboard 00160 void copy(Atom dataType, void *data, uint32_t numBytes, Time eventTime); 00161 00172 void paste(Time eventTime, 00173 SoXtClipboardPasteCB *pasteDoneFunc, 00174 void *userData = NULL); 00175 00176 // This extends the paste interest to recognize an additional target as 00177 // specified by 'dataType'. The pasteImportFunc will be called when this 00178 // type of data is pasted. This may be called multiple times to register 00179 // interest in more than one extension. 00180 // 00181 // Passing NULL as the pasteImportFunc will remove paste interest for that 00182 // data type (even if the data type is one of the defaults). 00183 // 00184 // This should be called before paste() so that paste() will look for data 00185 // types that have been specified here. 00186 // 00187 // The dataType atom can be created with XmInternAtom, e.g.: 00188 // XmInternAtom(XtDisplay(widget),"INVENTOR",False); 00189 // 00190 // The order is important - first things added to the list are the first 00191 // things searched for at paste time. (The default interest types come first.) 00192 00209 void addPasteInterest( 00210 Atom dataType, 00211 SoXtClipboardImportCB *pasteImportFunc, 00212 void *userData = NULL); 00213 00214 private: 00215 00216 // Convert the passed Inventor 2.1 data to a different format, specified by 00217 // the Atom desiredType. The data will be malloc'd here and placed in returnData, 00218 // with returnNumBytes describing the data length. This returns TRUE if successful. 00219 static SbBool convertData( 00220 SoWidget widget, 00221 void *srcData, 00222 uint32_t srcNumBytes, 00223 Atom desiredType, 00224 char **returnData, 00225 uint32_t *returnNumBytes); 00226 00227 private: 00228 // Sets a flag indicating whether the paste callback can and 00229 // should be passed an empty path list after a paste request is 00230 // made. For compatibility, this flag is FALSE by default, meaning 00231 // that the callback will never be invoked with an empty path list. 00232 void setEmptyListOK(SbBool flag) { emptyListOK = flag; } 00233 SbBool isEmptyListOK() const { return emptyListOK; } 00234 00235 private: 00236 SoWidget widget; // the widget to associated data with 00237 Atom clipboardAtom; // which selection: XA_PRIMARY, XA_SECONDARY, etc. 00238 Time eventTime; // time of the event which caused the copy/paste 00239 00240 // Paste callback info 00241 SoXtClipboardPasteCB *callbackFunc; 00242 void *userData; 00243 00244 // There can only be one owner of each X selection at any one time. 00245 // We use the selection atom as the key, and 'this' as the data. 00246 // We set the owner for each selection in this list for exportSelection. 00247 static SbDict *selOwnerList; 00248 00249 // All the overloaded copy functions call this one. 00250 void copy(SoByteStream *byteStream, Time t); 00251 00252 // This describes what data types we look for during paste. 00253 SoXtImportInterestList *pasteInterest; 00254 SbPList *copyInterest; 00255 00256 // This is called by exportSelection 00257 void getExportTargets( 00258 char **value, 00259 uint32_t *length); 00260 00261 Atom chooseFromImportTargets( 00262 Atom *supportedTargets, 00263 int length); 00264 00265 static SbBool writeToFile( 00266 SbString &tmpfile, 00267 void *srcData, 00268 uint32_t srcNumBytes); 00269 00270 // Read the file if it is in Inventor format and add its data to the pathList. 00271 static void readFile(SoPathList *&pathList, const char *filename); 00272 00273 // Read target data we just imported via paste or drop if it is in Inventor format. 00274 // This returns a newly allocated path list. This will free data when done. 00275 static SoPathList *readData( 00276 SoWidget w, 00277 Atom target, 00278 void *data, 00279 uint32_t numBytes); 00280 private: 00281 SoByteStream *copyBuffer; // copy/paste storage buffer 00282 Atom copyDataType; 00283 SbBool emptyListOK; 00284 00285 // This handles the default cases of paste 00286 void pasteImport(Atom dataType, void *data, uint32_t numBytes); 00287 static void pasteImportCB( 00288 void *userData, Atom dataType, 00289 void *data, uint32_t numBytes) 00290 { ((SoXtClipboard *)userData)->pasteImport(dataType, data, numBytes); } 00291 00292 // Copy and paste callback functions - these are called by the X server. 00293 // importSelection is called when we import data to paste. 00294 // exportSelection is called when we send data for someone else to paste. 00295 // loseSelection is called when we no longer own the selection. 00296 static void importSelection( 00297 SoWidget w, 00298 SoXtClipboard *clipboard, 00299 Atom *selAtom, 00300 Atom *type, 00301 char *value, 00302 uint32_t *length, 00303 int *format); 00304 00305 static Boolean exportSelection( 00306 SoWidget w, 00307 Atom *xselection, 00308 Atom *target, 00309 Atom *type, 00310 char **value, 00311 uint32_t *length, 00312 int *format); 00313 00314 static void loseSelection( 00315 SoWidget w, 00316 Atom *xselection); 00317 00318 static void importSelectionTargets( 00319 SoWidget w, 00320 SoXtClipboard *clipboard, 00321 Atom *selAtom, 00322 Atom *type, 00323 char *value, 00324 uint32_t *length, 00325 int *format); 00326 00327 }; 00328 00329 #endif /* _SO_XT_CLIPBOARD_ */ 00330 00331 #endif // _WIN32 00332 00333 00334