00001 /*======================================================================= 00002 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00003 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00004 *** *** 00005 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00006 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00007 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00008 *** *** 00009 *** RESTRICTED RIGHTS LEGEND *** 00010 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00011 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00012 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00013 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00014 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00015 *** *** 00016 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : VSG (MMM YYYY) 00022 **=======================================================================*/ 00023 00024 00025 00026 #ifndef _SO_WIN_CLIPBOARD_ 00027 #define _SO_WIN_CLIPBOARD_ 00028 00029 #include <Inventor/sys/port.h> 00030 00031 #include <Inventor/Win/SoWin.h> 00032 00033 #include <Inventor/Win/SoWinBeginStrict.h> 00034 00035 00036 class SbDict; 00037 class SoByteStream; 00038 class SoNode; 00039 class SoPath; 00040 class SoPathList; 00041 class SoSelection; 00042 00043 00044 // callback function prototypes 00048 typedef void SoWinClipboardPasteCB(void *userData, SoPathList *pathList); 00049 00050 00051 // The CLIPBOARD selection atom is not a predefined atom in X11 R4. 00052 // However, it is widely recognized. We define it to 0 here for 00053 // convenience. Internally, when SoWinClipboard sees _XA_CLIPBOARD_, 00054 // it will use XInternAtom(d, "CLIPBOARD", False). 00055 00056 #define _XA_CLIPBOARD_ ((Atom) 0) 00057 00058 #define XA_STRING ((Atom) 1) 00059 00060 00062 // 00063 // Class: SoWinClipboard 00064 // 00065 // 00067 00089 class SoWinClipboard { 00090 public: 00091 // Constructor. 00092 // The selection atom determines which X selection atom data transfers 00093 // should happen through. Default is _XA_CLIPBOARD_. (wsh uses XA_PRIMARY). 00094 00101 SoWinClipboard(SoWidget w, Atom selectionAtom = _XA_CLIPBOARD_); 00102 00106 ~SoWinClipboard(); 00107 00108 // 00109 // These methods transfer inventor scene graphs as the data. 00110 // 00111 // Data types supported for export (so another process can paste): 00112 // INVENTOR, XA_STRING 00113 // (and someday: POSTSCRIPT, IMAGE) 00114 // 00115 // Data types supported for import (so this process can paste): 00116 // INVENTOR, XA_STRING (pasted as an SoText2 node) 00117 // 00118 00119 // Copy - these routines copy the passed data into a byte stream, 00120 // and make the data available to any X client which requests it. 00121 // The eventTime should be the time stamp from the event which 00122 // triggered the copy request. 00123 00158 void copy(SoNode *node, Time eventTime); 00159 00164 void copy(SoPath *path, Time eventTime); 00165 00170 void copy(SoPathList *pathList, Time eventTime); 00171 00172 // Paste - make a request to the X server so we can import data for paste. 00173 // A paste is asynchronous - when this routine is called, it simply 00174 // makes a request to the X server for data to paste, then returns. 00175 // Once the data is delivered, the pasteDoneFunc will be called and passed 00176 // the user data along with a list of paths that were pasted. The app 00177 // should delete this path list when it is done with it. 00178 // The eventTime should be the time stamp from the event which 00179 // triggered the paste request. 00180 00188 void paste(Time eventTime, 00189 SoWinClipboardPasteCB *pasteDoneFunc, 00190 void *userData = NULL); 00191 00192 private: 00193 static void exitClass(); 00194 00195 private: 00196 SoWidget widget; // the widget to associated data with 00197 Atom selAtom; // which selection: XA_PRIMARY, XA_SECONDARY, etc. 00198 Time eventTime; // time of the event which caused the copy/paste 00199 00200 // Paste callback info 00201 SoWinClipboardPasteCB *callbackFunc; 00202 void *userData; 00203 00204 // Atoms supported for copy and paste targets: 00205 static Atom TARGETSatom; // XInternAtom(d, "TARGETS", False); 00206 static Atom INVENTORatom; // XInternAtom(d, "INVENTOR", False); 00207 // XA_STRING 00208 00209 static Atom *supportedTargets; 00210 00211 // There can only be one owner of each X selection at any one time. 00212 // We use the selection atom as the key, and 'this' as the data. 00213 // We set the owner for each selection in this list for exportSelection. 00214 static SbDict *selOwnerList; 00215 00216 // Return the clipboard data in binary or ascii form. 00217 SoByteStream *getBinaryBuffer(); 00218 SoByteStream *getAsciiBuffer(); 00219 00220 // All the overloaded copy functions call this one. 00221 void copy(SoByteStream *byteStream, Time t); 00222 00223 private: 00224 SoByteStream *binaryBuffer; // copy/paste storage buffer 00225 SoByteStream *asciiBuffer; // ascii version of storage buffer 00226 00227 // Copy and paste callback functions - these are called by the X server. 00228 // importSelection is called when we import data to paste. 00229 // exportSelection is called when we send data for someone else to paste. 00230 // loseSelection is called when we no longer own the selection. 00231 static void importSelection( 00232 SoWidget w, 00233 SoWinClipboard *clipboard, 00234 Atom *selAtom, 00235 Atom *type, 00236 char *value, 00237 size_t *length, 00238 int *format); 00239 00240 static Boolean exportSelection( 00241 SoWidget w, 00242 Atom *xselection, 00243 Atom *target, 00244 Atom *type, 00245 char **value, 00246 size_t *length, 00247 int *format); 00248 00249 static void loseSelection( 00250 SoWidget w, 00251 Atom *xselection); 00252 00253 static void importSelectionTargets( 00254 SoWidget w, 00255 SoWinClipboard *clipboard, 00256 Atom *selAtom, 00257 Atom *type, 00258 char *value, 00259 unsigned long *length, 00260 int *format); 00261 00262 }; 00263 00264 #include <Inventor/Win/SoWinEndStrict.h> 00265 00266 #endif /* _SO_WIN_CLIPBOARD_ */ 00267 00268