Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoXtClipboard.h
Go to the documentation of this file.
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-2014 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
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
74typedef void SoXtClipboardPasteCB(void *userData, SoPathList *pathList);
76 void *userData,
77 Atom dataType,
78 void *data,
79 uint32_t numBytes);
80
81
82// The CLIPBOARD selection atom is not a predefined atom in X11 R4.
83// However, it is widely recognized. We define it to 0 here for
84// convenience. Internally, when SoXtClipboard sees _XA_CLIPBOARD_,
85// it will use XInternAtom(d, "CLIPBOARD", False).
86
87#define _XA_CLIPBOARD_ ((Atom) 0)
88
90//
91// Class: SoXtClipboard
92//
93//
95
113 public:
114 // Constructor.
115 // The selection atom determines which X selection atom data transfers
116 // should happen through. Default is _XA_CLIPBOARD_. (wsh uses XA_PRIMARY).
117
125
130
143 void copy(SoNode *node, Time eventTime);
144
150 void copy(SoPath *path, Time eventTime);
151
157 void copy(SoPathList *pathList, Time eventTime);
158
159 // This copies non-Inventor data to the clipboard
160 void copy(Atom dataType, void *data, uint32_t numBytes, Time eventTime);
161
172 void paste(Time eventTime,
173 SoXtClipboardPasteCB *pasteDoneFunc,
174 void *userData = NULL);
175
176 // This extends the paste interest to recognize an additional target as
177 // specified by 'dataType'. The pasteImportFunc will be called when this
178 // type of data is pasted. This may be called multiple times to register
179 // interest in more than one extension.
180 //
181 // Passing NULL as the pasteImportFunc will remove paste interest for that
182 // data type (even if the data type is one of the defaults).
183 //
184 // This should be called before paste() so that paste() will look for data
185 // types that have been specified here.
186 //
187 // The dataType atom can be created with XmInternAtom, e.g.:
188 // XmInternAtom(XtDisplay(widget),"INVENTOR",False);
189 //
190 // The order is important - first things added to the list are the first
191 // things searched for at paste time. (The default interest types come first.)
192
210 Atom dataType,
211 SoXtClipboardImportCB *pasteImportFunc,
212 void *userData = NULL);
213
214 private:
215
216 // Convert the passed Inventor 2.1 data to a different format, specified by
217 // the Atom desiredType. The data will be malloc'd here and placed in returnData,
218 // with returnNumBytes describing the data length. This returns TRUE if successful.
219 static SbBool convertData(
220 SoWidget widget,
221 void *srcData,
222 uint32_t srcNumBytes,
223 Atom desiredType,
224 char **returnData,
225 uint32_t *returnNumBytes);
226
227 private:
228 // Sets a flag indicating whether the paste callback can and
229 // should be passed an empty path list after a paste request is
230 // made. For compatibility, this flag is FALSE by default, meaning
231 // that the callback will never be invoked with an empty path list.
232 void setEmptyListOK(SbBool flag) { emptyListOK = flag; }
233 SbBool isEmptyListOK() const { return emptyListOK; }
234
235 private:
236 SoWidget widget; // the widget to associated data with
237 Atom clipboardAtom; // which selection: XA_PRIMARY, XA_SECONDARY, etc.
238 Time eventTime; // time of the event which caused the copy/paste
239
240 // Paste callback info
241 SoXtClipboardPasteCB *callbackFunc;
242 void *userData;
243
244 // There can only be one owner of each X selection at any one time.
245 // We use the selection atom as the key, and 'this' as the data.
246 // We set the owner for each selection in this list for exportSelection.
247 static SbDict *selOwnerList;
248
249 // All the overloaded copy functions call this one.
250 void copy(SoByteStream *byteStream, Time t);
251
252 // This describes what data types we look for during paste.
253 SoXtImportInterestList *pasteInterest;
254 SbPList *copyInterest;
255
256 // This is called by exportSelection
257 void getExportTargets(
258 char **value,
259 uint32_t *length);
260
261 Atom chooseFromImportTargets(
262 Atom *supportedTargets,
263 int length);
264
265 static SbBool writeToFile(
266 SbString &tmpfile,
267 void *srcData,
268 uint32_t srcNumBytes);
269
270 // Read the file if it is in Inventor format and add its data to the pathList.
271 static void readFile(SoPathList *&pathList, const char *filename);
272
273 // Read target data we just imported via paste or drop if it is in Inventor format.
274 // This returns a newly allocated path list. This will free data when done.
275 static SoPathList *readData(
276 SoWidget w,
277 Atom target,
278 void *data,
279 uint32_t numBytes);
280 private:
281 SoByteStream *copyBuffer; // copy/paste storage buffer
282 Atom copyDataType;
283 SbBool emptyListOK;
284
285 // This handles the default cases of paste
286 void pasteImport(Atom dataType, void *data, uint32_t numBytes);
287 static void pasteImportCB(
288 void *userData, Atom dataType,
289 void *data, uint32_t numBytes)
290 { ((SoXtClipboard *)userData)->pasteImport(dataType, data, numBytes); }
291
292 // Copy and paste callback functions - these are called by the X server.
293 // importSelection is called when we import data to paste.
294 // exportSelection is called when we send data for someone else to paste.
295 // loseSelection is called when we no longer own the selection.
296 static void importSelection(
297 SoWidget w,
298 SoXtClipboard *clipboard,
299 Atom *selAtom,
300 Atom *type,
301 char *value,
302 uint32_t *length,
303 int *format);
304
305 static Boolean exportSelection(
306 SoWidget w,
307 Atom *xselection,
308 Atom *target,
309 Atom *type,
310 char **value,
311 uint32_t *length,
312 int *format);
313
314 static void loseSelection(
315 SoWidget w,
316 Atom *xselection);
317
318 static void importSelectionTargets(
319 SoWidget w,
320 SoXtClipboard *clipboard,
321 Atom *selAtom,
322 Atom *type,
323 char *value,
324 uint32_t *length,
325 int *format);
326
327};
328
329#endif /* _SO_XT_CLIPBOARD_ */
330
331#endif // _WIN32
332
333
char Boolean
Definition SoQtDef.h:119
#define SoWidget
Definition SoQtDef.h:40
#define _XA_CLIPBOARD_
#define Atom
Definition SoWinDef.h:92
#define Time
Definition SoWinDef.h:93
#define SoXtClipboardPasteCB
Definition SoXt2SoQt.h:40
void SoXtClipboardImportCB(void *userData, Atom dataType, void *data, uint32_t numBytes)
void SoXtClipboardPasteCB(void *userData, SoPathList *pathList)
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 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