Open Inventor Release 2024.1.2
 
Loading...
Searching...
No Matches
SoXtClipboard.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : David Mott (MMM yyyy)
25**=======================================================================*/
26/*=======================================================================
27 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
28 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
29 *** ***
30 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
31 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
32 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
33 *** ***
34 *** RESTRICTED RIGHTS LEGEND ***
35 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
36 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
37 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
38 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
39 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
40 *** ***
41 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49
50#ifdef _WIN32
51# include <Inventor/Win/SoWinClipboard.h>
52#else // _WIN32
53
54#ifndef _SO_XT_CLIPBOARD_
55#define _SO_XT_CLIPBOARD_
56
57#include <X11/Xatom.h>
58#include <X11/Intrinsic.h>
59#include <Inventor/SbBasic.h>
60#include <Inventor/Xt/SoXtDef.h>
61
62class SbDict;
63class SoByteStream;
64class SoNode;
65class SoPath;
66class SoPathList;
67class SoSelection;
68class SoXtImportInterestList;
69class SbString;
70class SbPList;
71
72
73// callback function prototypes
75typedef void SoXtClipboardPasteCB(void *userData, SoPathList *pathList);
78 void *userData,
79 Atom dataType,
80 void *data,
81 uint32_t numBytes);
82
83
84// The CLIPBOARD selection atom is not a predefined atom in X11 R4.
85// However, it is widely recognized. We define it to 0 here for
86// convenience. Internally, when SoXtClipboard sees _XA_CLIPBOARD_,
87// it will use XInternAtom(d, "CLIPBOARD", False).
88
89#define _XA_CLIPBOARD_ ((Atom) 0)
90
92//
93// Class: SoXtClipboard
94//
95//
97
115 public:
116 // Constructor.
117 // The selection atom determines which X selection atom data transfers
118 // should happen through. Default is _XA_CLIPBOARD_. (wsh uses XA_PRIMARY).
119
126 SoXtClipboard(SoWidget w, Atom selectionAtom = _XA_CLIPBOARD_);
127
132
145 void copy(SoNode *node, Time eventTime);
146
152 void copy(SoPath *path, Time eventTime);
153
159 void copy(SoPathList *pathList, Time eventTime);
160
161 // This copies non-Inventor data to the clipboard
162 void copy(Atom dataType, void *data, uint32_t numBytes, Time eventTime);
163
174 void paste(Time eventTime,
175 SoXtClipboardPasteCB *pasteDoneFunc,
176 void *userData = NULL);
177
178 // This extends the paste interest to recognize an additional target as
179 // specified by 'dataType'. The pasteImportFunc will be called when this
180 // type of data is pasted. This may be called multiple times to register
181 // interest in more than one extension.
182 //
183 // Passing NULL as the pasteImportFunc will remove paste interest for that
184 // data type (even if the data type is one of the defaults).
185 //
186 // This should be called before paste() so that paste() will look for data
187 // types that have been specified here.
188 //
189 // The dataType atom can be created with XmInternAtom, e.g.:
190 // XmInternAtom(XtDisplay(widget),"INVENTOR",False);
191 //
192 // The order is important - first things added to the list are the first
193 // things searched for at paste time. (The default interest types come first.)
194
212 Atom dataType,
213 SoXtClipboardImportCB *pasteImportFunc,
214 void *userData = NULL);
215
216 private:
217
218 // Convert the passed Inventor 2.1 data to a different format, specified by
219 // the Atom desiredType. The data will be malloc'd here and placed in returnData,
220 // with returnNumBytes describing the data length. This returns TRUE if successful.
221 static SbBool convertData(
222 SoWidget widget,
223 void *srcData,
224 uint32_t srcNumBytes,
225 Atom desiredType,
226 char **returnData,
227 uint32_t *returnNumBytes);
228
229 private:
230 // Sets a flag indicating whether the paste callback can and
231 // should be passed an empty path list after a paste request is
232 // made. For compatibility, this flag is FALSE by default, meaning
233 // that the callback will never be invoked with an empty path list.
234 void setEmptyListOK(SbBool flag) { emptyListOK = flag; }
235 SbBool isEmptyListOK() const { return emptyListOK; }
236
237 private:
238 SoWidget widget; // the widget to associated data with
239 Atom clipboardAtom; // which selection: XA_PRIMARY, XA_SECONDARY, etc.
240 Time eventTime; // time of the event which caused the copy/paste
241
242 // Paste callback info
243 SoXtClipboardPasteCB *callbackFunc;
244 void *userData;
245
246 // There can only be one owner of each X selection at any one time.
247 // We use the selection atom as the key, and 'this' as the data.
248 // We set the owner for each selection in this list for exportSelection.
249 static SbDict *selOwnerList;
250
251 // All the overloaded copy functions call this one.
252 void copy(SoByteStream *byteStream, Time t);
253
254 // This describes what data types we look for during paste.
255 SoXtImportInterestList *pasteInterest;
256 SbPList *copyInterest;
257
258 // This is called by exportSelection
259 void getExportTargets(
260 char **value,
261 uint32_t *length);
262
263 Atom chooseFromImportTargets(
264 Atom *supportedTargets,
265 int length);
266
267 static SbBool writeToFile(
268 SbString &tmpfile,
269 void *srcData,
270 uint32_t srcNumBytes);
271
272 // Read the file if it is in Inventor format and add its data to the pathList.
273 static void readFile(SoPathList *&pathList, const char *filename);
274
275 // Read target data we just imported via paste or drop if it is in Inventor format.
276 // This returns a newly allocated path list. This will free data when done.
277 static SoPathList *readData(
278 SoWidget w,
279 Atom target,
280 void *data,
281 uint32_t numBytes);
282 private:
283 SoByteStream *copyBuffer; // copy/paste storage buffer
284 Atom copyDataType;
285 SbBool emptyListOK;
286
287 // This handles the default cases of paste
288 void pasteImport(Atom dataType, void *data, uint32_t numBytes);
289 static void pasteImportCB(
290 void *userData, Atom dataType,
291 void *data, uint32_t numBytes)
292 { ((SoXtClipboard *)userData)->pasteImport(dataType, data, numBytes); }
293
294 // Copy and paste callback functions - these are called by the X server.
295 // importSelection is called when we import data to paste.
296 // exportSelection is called when we send data for someone else to paste.
297 // loseSelection is called when we no longer own the selection.
298 static void importSelection(
299 SoWidget w,
300 SoXtClipboard *clipboard,
301 Atom *selAtom,
302 Atom *type,
303 char *value,
304 uint32_t *length,
305 int *format);
306
307 static Boolean exportSelection(
308 SoWidget w,
309 Atom *xselection,
310 Atom *target,
311 Atom *type,
312 char **value,
313 uint32_t *length,
314 int *format);
315
316 static void loseSelection(
317 SoWidget w,
318 Atom *xselection);
319
320 static void importSelectionTargets(
321 SoWidget w,
322 SoXtClipboard *clipboard,
323 Atom *selAtom,
324 Atom *type,
325 char *value,
326 uint32_t *length,
327 int *format);
328
329};
330
331#endif /* _SO_XT_CLIPBOARD_ */
332
333#endif // _WIN32
334
335
List of generic (void *) pointers.
Definition SbPList.h:77
Class for smart character strings.
Definition SbString.h:202
Converts scene graph objects to character byte streams.
Abstract base class for all database nodes.
Definition SoNode.h:145
Path that points to a list of hierarchical nodes.
Definition SoPath.h:187
Maintains a list of pointers to paths.
Definition SoPathList.h:81
Manages a list of selected objects.
Supports copy/paste for Open Inventor using the Xt clipboard.
~SoXtClipboard()
Destructor.
void copy(SoNode *node, Time eventTime)
This copies the passed scene graph object, and tells the X server that the clipboard now owns the sel...
void addPasteInterest(Atom dataType, SoXtClipboardImportCB *pasteImportFunc, void *userData=NULL)
This extends the paste interest to recognize an additional target as specified by dataType.
void copy(SoPath *path, Time eventTime)
This copies the passed scene graph object, and tells the X server that the clipboard now owns the sel...
void copy(Atom dataType, void *data, uint32_t numBytes, Time eventTime)
void SoXtClipboardImportCB(void *userData, Atom dataType, void *data, uint32_t numBytes)
void SoXtClipboardPasteCB(void *userData, SoPathList *pathList)
void copy(SoPathList *pathList, Time eventTime)
This copies the passed scene graph object, and tells the X server that the clipboard now owns the sel...
SoXtClipboard(SoWidget w, Atom selectionAtom=_XA_CLIPBOARD_)
Constructor.
void paste(Time eventTime, SoXtClipboardPasteCB *pasteDoneFunc, void *userData=NULL)
This makes a request to the X server for data to paste from the selection atom specified in the const...
int SbBool
Boolean type.
Definition SbBase.h:87
char Boolean
Definition SoQtDef.h:124