Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoXtComponent.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** Modified by : Alain Dumesny (MMM yyyy)
26**=======================================================================*/
27/*=======================================================================
28 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
29 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
30 *** ***
31 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
32 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
33 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
34 *** ***
35 *** RESTRICTED RIGHTS LEGEND ***
36 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
37 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
38 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
39 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
40 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
41 *** ***
42 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (MMM YYYY)
48**=======================================================================*/
49
50
51#ifdef SOQT
53#elif defined _WIN32
55#else // _WIN32
56
57#ifndef _SO_XT_COMPONENT_H_
58#define _SO_XT_COMPONENT_H_
59
60#include <X11/Intrinsic.h>
61#include <Inventor/SbLinear.h>
62#include <Inventor/SbString.h>
64#include <Inventor/Xt/SoXtDef.h>
65
66class SbDict;
67class SoXtComponent;
68class SoCallbackList;
69
70typedef void SoXtComponentCB( void* data, SoXtComponent* v );
71typedef void SoXtComponentVisibilityCB( void* data, SbBool b );
72
145{
146
147 public:
148
158 static void displayHelp( const char* filename, UINT contextID );
159
163 virtual void show();
164
168 virtual void hide();
169
181
187 SoWidget getWidget() const { return _baseWidget; }
188
194 SbBool isTopLevelShell() const { return m_guiComponent->isTopLevelShell(); }
195
200 SoWidget getShellWidget() const { return m_guiComponent->isTopLevelShell() ? parentWidget : NULL; }
201
205 SoWidget getParentWidget() const { return parentWidget; }
206
210 void setSize( const SbVec2s& size );
211
216
221
225 SbBool isFullScreen(void) const;
226
233
239
243 inline Display* getDisplay();
244
253 SoNONUNICODE void setTitle( const char* newTitle );
254
255
262 void setTitle( const SbString& newTitle );
263
268 return m_guiComponent->getTitle(); }
269
278 SoNONUNICODE void setIconTitle( const char* newIconTitle );
279
286 void setIconTitle( const SbString& newIconTitle );
287
292 return m_guiComponent->getIconTitle(); }
293
294
304 void setWindowCloseCallback( SoXtComponentCB* func, void* data = NULL )
305 { windowCloseFunc = func; windowCloseData = data; }
306
312
318 return m_guiComponent->getWidgetName(); }
319
325 return m_guiComponent->getClassName(); }
326
327
328 private:
329
330 virtual ~SoXtComponent();
331
332 // Deprecated. Replaced by getWidget().
333 SoWidget baseWidget() const { return getWidget(); }
334
335 virtual void posChanged( const SbVec2i32&, const SbVec2i32& ) {};
336
337 SoGuiComponent* getGuiComponent() const;
338
339 private:
340 //
341 // If `parent` widget is suplied AND `buildInsideParent` is TRUE, this
342 // component will build inside the given parent widget, else
343 // it will create its own topLevelShell widget (component resides in
344 // its own window).
345 // The topLevelShell can either be created under the given
346 // parent shell (`parent` != NULL) or under the main window.
347 //
348 // The name is used for looking up X resource values. If NULL,
349 // then this component inherits resource values defined for its class.
350 //
351 // Calling setBaseWidget is needed for looking up Xt like
352 // resources in the widget tree. It will use the class name of
353 // the Inventor component (e.g. SoXtRenderArea) instead of
354 // the class name of the Motif widget this component employs
355 // (e.g. XmForm).
356 //
357 // Thus apps are able to do this in their app-defaults file:
358 //
359 // *SoXtRenderArea*BackgroundColor: salmon
360 //
361 SoXtComponent( SoWidget parent = NULL,
362 const char* name = NULL,
363 SbBool buildInsideParent = TRUE,
364 SbBool sync = TRUE );
365
366 SoXtComponent( SoWidget parent,
367 const char* name,
368 SbBool buildInsideParent,
369 SbBool sync,
370 SoGuiComponent* guiComponent );
371
372 // Subclasses need to call this method passing the top most
373 // widget after it has been created.
374 void setBaseWidget( SoWidget w );
375
376 // Subclasses need to set the class name in the constructor
377 // before the widget is built.
378 void setClassName( const SbString &n ) { m_guiComponent->setClassName( n ); }
379
380 // this routine is called whenever the top level shell widget receives
381 // a close action (WM_DELETE_WINDOW message) from the window manager.
382 // Instead of destroying the widget (default shell behavior) this
383 // routine is used, which by default calls exit(0) if it is the main
384 // window else calls hide() on the component.
385 //
386 virtual void windowCloseAction();
387
388 // Support for doing things right after the widget is realized
389 // for the first time.
390 // The base class will set the window and icon title for shell widgets.
391 virtual void afterRealizeHook();
392 SbBool firstRealize;
393
394 //
395 // Subclasses should redefine these routines to return the appropriate
396 // default information. Those are used when creating the widget to set
397 // the name (used for resources), window title and window icon
398 // name. Those default values are only used if the user didn't
399 // explicitly specify them.
400 //
401 virtual SbString getDefaultWidgetName() const;
402 virtual SbString getDefaultTitle() const;
403 virtual SbString getDefaultIconTitle() const;
404
405 //
406 // Register widget - should be called by subclasses after
407 // they have created their top most widget (which is passed here),
408 // and before they build any child widgets. Calling this method
409 // ensures that the widgets name and class will be used when
410 // calls are made to get X resource values for this widget.
411 //
412 // *** NOTE ***
413 // ALL subclasses should register their top most widget within the
414 // component, whether they retrieve resources or not, so that children
415 // widgets can get X resources properly.
416 // Unregister the widget when the widget is destroyed.
417 //
418 void registerWidget( SoWidget w );
419 void unregisterWidget( SoWidget w );
420
421 // subclasses can add a callback to be called whenever the component
422 // becomes visible or become hidden (like when it is iconified).
423 // Sublcasses should use this to attach or detach any sensors they
424 // have, or stop any ongoing anymation.
425 void addVisibilityChangeCallback( SoXtComponentVisibilityCB* func, void* userData = NULL );
426 void removeVisibilityChangeCallback( SoXtComponentVisibilityCB* func, void* userData = NULL );
427
428 //
429 // This method can be used by subclasses to open a component help
430 // card. The name of the file should be supplied withought a path
431 // name. By default the file will be searched using:
432 // 1) current working directory
433 // 2) SO_HELP_DIR environment variable
434 // 3) /usr/share/help/Inventor
435 // 4) else bring a no help card found dialog
436 //
437 void openHelpCard( const char* cardName );
438
439 // This method is used to get label from resources for Localisation.
440 static SbString getlabel( unsigned int whatisit );// const;
441
442
443
444 private:
445
446 void constructorCommon( SoWidget parent, const char* name, SbBool buildInsideParent, SbBool sync );
447
448 // Call a web browser to open the passed URL
449 SbBool callWebBrowser( const char* url ) const;
450
451 // widgetDestroyed is called when the widget is destroyed.
452 // There is no way to reconstruct the widget tree, so calling
453 // this simply generates an error. The component should be
454 // deleted to dispose of the widget.
455 virtual void widgetDestroyed();
456
457 SbBool createdShell; // TRUE if we created that toplevel shell
458 SoWidget parentWidget; // topLevel shell if in its own window
459 SoWidget _baseWidget; // returned by getWidget()
460 SbVec2s size; // size of the '_baseWidget' and 'shell' (if toplevel)
461
462 // visibiltity stuff
463 SbBool visibleState;
464 SbBool ShellMapped, widgetMapped;
465 SoCallbackList* visibiltyCBList;
466 void checkForVisibilityChange();
467 static void widgetStructureNotifyCB( SoWidget w, SoXtComponent* p, XEvent* xe, Boolean* b );
468 static void shellStructureNotifyCB( SoWidget w, SoXtComponent* p, XEvent* xe, Boolean* b );
469 static void widgetDestroyedCB( SoWidget w, XtPointer clientData, XtPointer p );
470
471 // window close action data
472 SoXtComponentCB* windowCloseFunc;
473 void* windowCloseData;
474 static void windowCloseActionCB( SoWidget w, SoXtComponent* v, void* data );
475
476 // The widget dictionary maps widgets to SoXtComponents. It's used
477 // by getComponent(), and kept up to date by registerWidget().
478 static SbDict* widgetDictionary;
479
480 // For fullscreen mode.
481 Dimension posX, posY, width, height;
482 int m_decorationHints;
483 int m_functionHints;
484
485 SoGuiComponent* m_guiComponent;
486
487};
488
489// Inline routines
490Display*
492{
493 return (_baseWidget != NULL ? XtDisplay(_baseWidget) : NULL);
494}
495
496#endif // _SO_XT_COMPONENT_H_
497
498#endif // _WIN32
499
500
#define TRUE
Possible value of SbBool.
Definition SbBase.h:77
virtual SbGlContextHelper::Display getDisplay()=0
Returns the Display corresponding to this graphics device.
union _XEvent XEvent
Definition SoQtDef.h:120
char Boolean
Definition SoQtDef.h:119
void * XtPointer
Definition SoQtDef.h:118
#define SoWidget
Definition SoQtDef.h:40
virtual void enable(QWidget *w, XtEventHandler f, XtPointer data, void *unused=NULL)
SoWidget getWidget()
UINT * XtDisplay(SoWidget w)
#define SoXtComponent
Definition SoXt2SoQt.h:48
#define SoXtComponentVisibilityCB
Definition SoXt2SoQt.h:50
#define SoXtComponentCB
Definition SoXt2SoQt.h:49
void SoXtComponentCB(void *data, SoXtComponent *v)
void SoXtComponentVisibilityCB(void *data, SbBool b)
Class for smart character strings.
Definition SbString.h:202
2D vector class.
Definition SbVec.h:517
2D vector class.
Definition SbVec.h:700
Manages a list of callbacks and associated data.
Abstract base class for all Open Inventor components.
SbBool isFullScreen(void) const
Queries if the viewer is in fullscreen mode.
SbVec2s getSize()
Convenience routine on the widget.
void setSize(const SbVec2s &size)
Convenience routine on the widget.
SoWidget getShellWidget() const
Returns the shell widget (NULL if the shell hasn't been created by this component).
void setWindowCloseCallback(SoXtComponentCB *func, void *data=NULL)
Sets which callback to call when the user closes this component (double click in the upper left corne...
virtual void show()
This shows the component.
static SoXtComponent * getComponent(SoWidget w)
This returns the SoXtComponent for this widget.
void setFullScreenEnable(const SbBool enable)
Enables/disables fullscreen mode.
SbString getClassName() const
Returns the class name.
SbString getWidgetName() const
Returns the widget name.
SoNONUNICODE void setIconTitle(const char *newIconTitle)
Sets icon title.
SbString getTitle() const
Gets window title.
Display * getDisplay()
Returns the X display associated with this components widget.
static void displayHelp(const char *filename, UINT contextID)
Static method to display the specified topic of the specified help file.
SbBool isVisible()
Returns TRUE if this component is mapped onto the screen.
SoWidget getWidget() const
This returns the base widget for this component.
SbBool isFullScreenEnable() const
Queries if it is possible to put the viewer in fullscreen mode.
SoWidget getParentWidget() const
Returns the parent widget, be it a shell or not.
SoNONUNICODE void setTitle(const char *newTitle)
Sets window title.
SbBool isTopLevelShell() const
Returns TRUE if this component is a top level shell component (has its own window).
SbString getIconTitle() const
Gets icon title.
SbBool setFullScreen(const SbBool enable)
Switches the viewer into (or out of) fullscreen mode.
void setIconTitle(const SbString &newIconTitle)
Sets icon title.
virtual void hide()
This hides the component.
void setTitle(const SbString &newTitle)
Sets window title.
int SbBool
Boolean type.
Definition SbBase.h:87
size_t size() const
unsigned int UINT
Definition port.h:357