Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoWin.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : VSG (MMM YYYY)
22**=======================================================================*/
23
24
25#ifndef _SO_WIN_
26#define _SO_WIN_
27
28#ifdef _WIN32
29# include <Inventor/Win/SoWinBeginStrict.h>
30# include <string.h>
31# include <windows.h>
32# include <memory>
33# include <Inventor/Win/SoXt2SoWin.h>
34# include <Inventor/Win/SoWinDef.h>
35# include <Inventor/SbBasic.h>
36# include <SoVersion.h>
37# include <Inventor/Gui/SoGui.h>
38# define RESOURCE_DLL "Error: SoWin resources not loaded\n Cannot find InventorR.DLL"
39#else
40# include <Xm/Xm.h>
41#endif
42#include <Inventor/threads/SbThreadMutex.h>
43#include <Inventor/helpers/SbGlContextHelper.h>
44
45#include <Inventor/Win/SoInventorWinLibName.h>
46
47#include <Inventor/SoModule.h>
48SO_MODULE_HEADER(SoInventorWin, __INVENTORWINDLL)
49
50#ifndef InventorWin_EXPORTS
51#ifndef OIV_DISABLE_AUTOLINK
52# pragma comment(lib,__INVENTORWINLIB)
53#endif
54#endif
55
56#include <Inventor/SbBasic.h>
57#include <Inventor/SbLinear.h>
58#include <Inventor/sys/SoDynamicLibManager.h>
59
60class SbPList;
61class SoEvent;
62class SoWinEventHandler;
63class SoOffscreenRenderer;
64class SoConsole;
65class SbConfig;
66class SoAction;
67
68#ifdef _WIN32
69// Under _WIN32 certain messages are only sent to the toplevel window
70// (unlike X where any window can get any event), so SoWin provides an
71// additional service. Other SoWin classes can register a "message
72// hook" to request that any time a particular message is sent to the
73// toplevel window it will also be sent to that class's window proc.
74// This mechanism (generally) requires the cooperation of the app in
75// calling SoWin::IsInventorMessage in its message loop (similar to the
76// existing Windows requirement to call IsDialogMessage and so on).
77class SoWinMessageHook;
78
79// Define some undocumented Windows messages used in SoWinGLWidget
80// (supposedly will be defined in NT 3.51 and/or Windows95)
81#ifndef WM_ENTERSIZEMOVE
82#define WM_ENTERSIZEMOVE 0x0231
83#endif
84#ifndef WM_EXITSIZEMOVE
85#define WM_EXITSIZEMOVE 0x0232
86#endif
87
88// Need this decl for error handler (see comments there)
89class SoError;
90
91extern CRITICAL_SECTION SoWinGLSection;
92
93#define SOWIN_ENTER_GL_SECTION()\
94EnterCriticalSection(&SoWinGLSection)
95
96#define SOWIN_LEAVE_GL_SECTION()\
97LeaveCriticalSection(&SoWinGLSection)
98
99#define SOWIN_LEAVE_GL_SECTIONR()\
100{\
101LeaveCriticalSection(&SoWinGLSection);\
102return;\
103}
104
105#define SOWIN_LEAVE_GL_SECTIONRV(v)\
106{\
107LeaveCriticalSection(&SoWinGLSection);\
108return v;\
109}
110
111#define SOWIN_TIMER_MSG SoWin::wmTimerMsg
112#define SOWIN_WORK_MSG SoWin::wmWorkMsg
113
114#else
115
116#define SOWIN_ENTER_GL_SECTION()
117#define SOWIN_LEAVE_GL_SECTION()
118#define SOWIN_LEAVE_GL_SECTIONR()
119#define SOWIN_LEAVE_GL_SECTIONRV(v)
120
121#endif //_WIN32
122
145class SoWin {
146
147 public:
156 static SoWidget init(const char *appName,
157 const char *className = "Inventor");
158
166 static void init( SoWidget topLevelWidget );
167
173 static void init();
174
175#if 1 SoDEPRECATED
182 static SoWidget threadInit(const char *appName, const char *className = "Inventor");
183SoDEPRECATED
191 static void threadInit(SoWidget topLevelWidget);
192SoDEPRECATED
200 static void threadInit();
201#endif
206 static bool isInitialized();
207
269 static void finish();
270
278 static int mainLoop();
279
288 static void exit(int returnCode = 0);
289
294 static SbBool nextEvent(XtAppContext appContext, XEvent *event);
295
301
310
315 static SoWidget getTopLevelWidget();
316
317 //
318 // Convenience routines
319 //
320
326 static void show(SoWidget w);
327
333 static void hide(SoWidget w);
334
338 static XmString encodeString(char *s);
339
343 static char *decodeString(XmString xs);
344
348 static void setWidgetSize(SoWidget w, const SbVec2s &size);
352 static SbVec2s getWidgetSize(SoWidget w);
353
354 // Convenience routine which will return the ShellWidget
355 // containing the given widget. The widget tree is traversed up until
356 // a shell widget is found (using XtIsShell()).
362 static SoWidget getShellWidget(SoWidget w);
363
369 static void createSimpleErrorDialog(SoWidget widget, char *dialogTitle,
370 char *errorStr1, char *errorStr2 = NULL);
371
375 static void getPopupArgs(UINT *d, int scr, ArgList args, int *n);
376
380 static void addColormapToShell(SoWidget widget, SoWidget shell);
381
388
396 static void doIdleTasks(void);
397
398 private:
403 static bool peekEvent(XEvent *event);
404
405 // This method is obsolete.
406 // Processes message hooks defined by SoWin classes so they can get
407 // notification of messages that are only passed to toplevel window.
408 // Intended to be called by app as first thing in its window proc
409 // (at this we consider this better than subclassing toplevel window).
410 //
411 // SoWin::windowProc makes this call when SoWin creates toplevel window.
412 static LRESULT isInventorMessage(HWND hwnd, UINT message,
413 WPARAM wParam, LPARAM lParam);
414
415 // called when thread terminates
416 static void terminate(long terminateSyncTime = 100);
417
418 // This method processes thread messages. It returns TRUE
419 // if a message was processed.
420 static SbBool PreTranslateMessage(MSG *event);
421
422 static UINT wmTimerMsg;
423 static UINT wmWorkMsg;
424
425 // Add/remove the passed event handler for X extension device events
426 // (Xt does not handle extension events.)
427 // Extension event types are queried from the server at runtime.
428 static void addExtensionEventHandler(SoWidget w,
429 int extensionEventType,
430 XtEventHandler proc,
431 XtPointer clientData);
432 static void removeExtensionEventHandler(SoWidget w,
433 int extensionEventType,
434 XtEventHandler proc,
435 XtPointer clientData);
436
437 // register a class and add it to the registered class list.
438 static ATOM registerClass(WNDCLASS *pWndClass, char *actualClassName);
439
440 // get information about a class if it has been registered
441 static SbBool getClassInfo(HINSTANCE hDll, const char *className,
442 char *actualClassName, WNDCLASS *pClassInfo);
443
444 // Called at DLL process detach
445 static void unregisterProcessClasses();
446
447 // Message hook functions (see long comment above)
448 static void addMessageHook(Hwnd hwnd, UINT msg);
449 static void removeMessageHook(Hwnd hwnd, UINT msg);
450
451 // These member functions only exist to let the Inventor WinMain
452 // function save these values for when we actually get around to
453 // creating a window (or windows). --mmh
454
455 static void setInstance(Hinst hInst);
456 static Hinst getInstance(void);
457
458 static const SoDynamicLibManager::SafeLibraryHandle& getResDllSafeHandle();
459
460 static void setPrevInstance(Hinst hInst);
461
462 static void setCmdLine(LPSTR cmdLine);
463
464 static void setCmdShow(int cmdShow);
465
466 // _WIN32 needs this get method for the SoWinEventHandler::xtTimerCallback
467 // because we can't specify "client data" when we create the timer.
468
469 static SoWinEventHandler *getEventHandler();
470
471 // _WIN32 needs this method to identify so-called User Interface (UI)
472 // threads (as opposed to Worker threads). Any thread that creates a
473 // window is obligated to process messages for that window (and any
474 // others it created) and is considered a UI thread. Therefore any
475 // thread that creates an Open Inventor viewer is a UI thread.
476 // Worker threads are typically not associated with any window and do
477 // not process messages, therefore SoWin does not allow them to
478 // schedule timers. A worker thread might be used to compute data
479 // and modify a scene graph.
480 //
481 // All classes derived from SoWinComponent should call this method.
482 // If called with no parameter, uses the current thread id.
483
484 static void registerUIThread(uint32_t threadId = 0);
485
486 static void forwardQueryPalette(Window hWnd);
487 static void forwardPaletteChanged(Window hWnd);
488
489 static SbBool handleCtl3DMessage();
490
491 static void setHandleCtl3DMessage(SbBool n);
492
493 static void Ctl3dColorChange();
494
495 // Note: The default error handler in SoError writes to stderr,
496 // which is generally the "bit bucket" for _WIN32 apps, so we
497 // setup this handler which pops up a message dialog. --mmh
498 static void errorHandlerCB(const SoError *error, void *data);
499 static void errorHandlerCBMessageBox(const SoError *error, void *userData);
500
501 // Access to shared offscreen renderer for UI components
502 static SoOffscreenRenderer *getOffscreenRenderer();
503
504 // Make sure offscreen renderer's bitmap is at least this big.
505 // Returns actual current size.
506 static SbVec2s &updateRendererSize(SbVec2s size);
507
508 // MP
509 static SbConfig * getConfig(void);
510 static void setConfig(SbConfig *);
511 static void setConfigFilename(char*);
512 static char * getConfigFilename(void);
513
514 static void addAccelerator(ACCEL accel);
515
516 private:
517 static FARPROC m_procCtl3dColorChange;
518 static HINSTANCE m_hCtl3d;
519 static void getExtensionEventHandler(XEvent *event, SoWidget &w,
520 XtEventHandler &proc,
521 XtPointer &clientData);
522 // register mutex
523 static SbThreadMutex *registerMutex;
524
525 private:
526 static void activeLoop();
527
528 static int s_returnCode;
529
530 static bool internalMainWidget;
531 static SoWidget mainWidget;
532 static SoWinEventHandler *eventHandler;
533 static SbPList *handlerList;
534
535 // flag indicates whether or not we are processing CTL3D messages
536 static SbBool nHandleCtl3D;
537
538 // Message hook list
539 static SbPList *msgHookList;
540
541 // Resource DLL
542 static void loadResourceDll();
543
544 // Save initial values passed into WinMain function.
545 static Hinst hInstance;
546 static Hinst hPrevInstance;
547 static LPTSTR lpszCmdLine;
548 static int nCmdShow;
549 static SoDynamicLibManager::SafeLibraryHandle hResDll;
550
551 // List of classes registered by SoWin
552 struct RegisteredClassStruct
553 {
554 Hinst hinstance;
556 };
557 static SbPList registeredClassList;
558
560 friend class SoWinTimerManager;
561 friend class SoWinEventHandler;
563
564 static HWND createThreadWindow(SoWinTimerManager *pTimerManager);
565
566 // SoWin contains the generic window proc for Inventor windows.
567 // Among other things, it converts appropriate messages into
568 // Inventor events.
569 //
570 // SoWin also provides a winmain function for Inventor programs
571 // that only make SoWin calls, but it is not a member function.
572 // It is a separate entity in the library so it is only linked
573 // in when the app doesn't have its own winmain.
574 static LRESULT CALLBACK WindowProc(Hwnd hwnd, UINT message,
575 WPARAM wParam, LPARAM lParam);
576
577 // Offscreen renderer for UI components to share
578 // (reduces number of on-screen OpenGL contexts required).
579 static SoOffscreenRenderer *m_pRenderer;
580
581 static SoConsole *errorConsole;
582 static SbBool s_useOldErrorHandler;
583
584 static SbConfig *config;
585 static char *configFile;
586
587 static HACCEL m_haccel;
588
589 static int s_initRefCount;
590 static bool shouldExit;
591};
592
593
595//
596// #duplicated nextEvent(XtAppContext appContext, XEvent * event)
597//
599
600#ifdef _WIN32
601# include <Inventor/Win/SoWinEndStrict.h>
602#endif
603
604#endif /* _SO_WIN_ */
605
List of generic (void *) pointers.
Definition SbPList.h:77
Class for smart character strings.
Definition SbString.h:202
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
2D vector class.
Definition SbVec.h:700
Abstract base class for all actions.
Definition SoAction.h:132
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Creates a Win32 ...
Definition SoConsole.h:67
Error handling base class.
Definition SoError.h:109
Base class for all events.
Definition SoEvent.h:116
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Routines for Ope...
Definition SoWin.h:145
static void show(SoWidget w)
Convenience routine to show the passed window handle.
static XtAppContext getAppContext()
This method is included for portability only.
static SoConsole * getErrorConsole(void)
Returns the VSG error console.
static void doIdleTasks(void)
If you use SoWin::mainLoop or SoWin::nextEvent, Inventor automatically calls this when the Windows me...
static SbBool nextEvent(XtAppContext appContext, XEvent *event)
Get the nextEvent by calling GetMessage.
static SoDEPRECATED SoWidget threadInit(const char *appName, const char *className="Inventor")
This method calls XXX::threadInit(), rather than XXX::init().
static void setWidgetSize(SoWidget w, const SbVec2s &size)
Convenience routine to set the size of the given window.
static void exit(int returnCode=0)
Tells the main event loop to exit with a return code.
static void init()
This alternate form of init does not require a top level window.
static SoWidget init(const char *appName, const char *className="Inventor")
This is called to initialize Open Inventor and Windows, and bind Open Inventor with Windows message h...
static SoWidget getTopLevelWidget()
Returns information based on the initial window handle returned by or passed to init.
static bool isInitialized()
Returns TRUE if SoWin module is currently initialized.
static SbVec2s getWidgetSize(SoWidget w)
Convenience routine to get the size of the given window.
static SoDEPRECATED void threadInit(SoWidget topLevelWidget)
This method calls XXX::threadInit(), rather than XXX::init().
static SbGlContextHelper::Display getDisplay()
This method is included for portability only.
static SoWidget getShellWidget(SoWidget w)
Convenience routine which will return the topmost window containing the given window handle.
static void getPopupArgs(UINT *d, int scr, ArgList args, int *n)
This method is included for portability only.
static char * decodeString(XmString xs)
This method is included for portability only.
static Boolean dispatchEvent(XEvent *event)
Dispatch the passed message to a handler.
static SoDEPRECATED void threadInit()
This method calls XXX::threadInit(), rather than XXX::init().
static void addColormapToShell(SoWidget widget, SoWidget shell)
This method is included for portability only.
static XmString encodeString(char *s)
This method is included for portability only.
static void finish()
Frees Open Inventor's internal static memory allocations.
static void createSimpleErrorDialog(SoWidget widget, char *dialogTitle, char *errorStr1, char *errorStr2=NULL)
Convenience routine which brings a simple Windows error dialog box displaying the given error string(...
static void init(SoWidget topLevelWidget)
This alternate form of init allows the application to initialize Windows.
static int mainLoop()
Enters the main event loop and waits until exit() is called or a WM_QUIT message is sent to the messa...
static void hide(SoWidget w)
Convenience routine to hide the passed window handle.
int SbBool
Boolean type.
Definition SbBase.h:87
union _XEvent XEvent
Definition SoQtDef.h:126
char Boolean
Definition SoQtDef.h:124
struct _XtAppStruct * XtAppContext
Definition SoQtDef.h:130
void * XtPointer
Definition SoQtDef.h:122