00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _SO_WIN_
00026 #define _SO_WIN_
00027
00028 #ifdef _WIN32
00029 # include <Inventor/Win/SoWinBeginStrict.h>
00030 # include <string.h>
00031 # include <windows.h>
00032 # include <memory>
00033 # include <Inventor/Win/SoXt2SoWin.h>
00034 # include <Inventor/Win/SoWinDef.h>
00035 # include <Inventor/SbBasic.h>
00036 # include <SoVersion.h>
00037 # define RESOURCE_DLL "Error: SoWin resources not loaded\n Cannot find InventorR.DLL"
00038 #else
00039 # include <Xm/Xm.h>
00040 #endif
00041 #include <Inventor/threads/SbThreadMutex.h>
00042 #include <Inventor/helpers/SbGlContextHelper.h>
00043
00044 #include <Inventor/Win/SoInventorWinLibName.h>
00045
00046 #include <Inventor/SoModule.h>
00047 SO_MODULE_HEADER(SoInventorWin, __INVENTORWINDLL)
00048
00049 #ifndef InventorWin_EXPORTS
00050 #ifndef OIV_DISABLE_AUTOLINK
00051 # pragma comment(lib,__INVENTORWINLIB)
00052 #endif
00053 #endif
00054
00055 #include <Inventor/SbBasic.h>
00056 #include <Inventor/SbLinear.h>
00057 #include <Inventor/sys/SoDynamicLibManager.h>
00058
00059 class SbPList;
00060 class SoEvent;
00061 class SoWinEventHandler;
00062 class SoOffscreenRenderer;
00063 class SoConsole;
00064 class SbConfig;
00065 class SoAction;
00066
00067 #ifdef _WIN32
00068
00069
00070
00071
00072
00073
00074
00075
00076 class SoWinMessageHook;
00077
00078
00079
00080 #ifndef WM_ENTERSIZEMOVE
00081 #define WM_ENTERSIZEMOVE 0x0231
00082 #endif
00083 #ifndef WM_EXITSIZEMOVE
00084 #define WM_EXITSIZEMOVE 0x0232
00085 #endif
00086
00087
00088 class SoError;
00089
00090 extern CRITICAL_SECTION SoWinGLSection;
00091
00092 #define SOWIN_ENTER_GL_SECTION()\
00093 EnterCriticalSection(&SoWinGLSection)
00094
00095 #define SOWIN_LEAVE_GL_SECTION()\
00096 LeaveCriticalSection(&SoWinGLSection)
00097
00098 #define SOWIN_LEAVE_GL_SECTIONR()\
00099 {\
00100 LeaveCriticalSection(&SoWinGLSection);\
00101 return;\
00102 }
00103
00104 #define SOWIN_LEAVE_GL_SECTIONRV(v)\
00105 {\
00106 LeaveCriticalSection(&SoWinGLSection);\
00107 return v;\
00108 }
00109
00110 #define SOWIN_TIMER_MSG SoWin::wmTimerMsg
00111 #define SOWIN_WORK_MSG SoWin::wmWorkMsg
00112
00113 #else
00114
00115 #define SOWIN_ENTER_GL_SECTION()
00116 #define SOWIN_LEAVE_GL_SECTION()
00117 #define SOWIN_LEAVE_GL_SECTIONR()
00118 #define SOWIN_LEAVE_GL_SECTIONRV(v)
00119
00120 #endif //_WIN32
00121
00144 class SoWin {
00145
00146 public:
00155 static SoWidget init(const char *appName,
00156 const char *className = "Inventor");
00157
00165 static void init( SoWidget topLevelWidget );
00166
00172 static void init();
00173
00174 #if 1 SoDEPRECATED
00181 static SoWidget threadInit(const char *appName, const char *className = "Inventor");
00182 SoDEPRECATED
00190 static void threadInit(SoWidget topLevelWidget);
00191 SoDEPRECATED
00199 static void threadInit();
00200 #endif
00205 static bool isInitialized();
00206
00268 static void finish();
00269
00274 static void mainLoop();
00275
00280 static SbBool nextEvent(XtAppContext appContext, XEvent *event);
00281
00286 static Boolean dispatchEvent(XEvent *event);
00287
00291 static XtAppContext getAppContext();
00295 static SbGlContextHelper::Display getDisplay();
00296
00301 static SoWidget getTopLevelWidget();
00302
00303
00304
00305
00306
00312 static void show(SoWidget w);
00313
00319 static void hide(SoWidget w);
00320
00324 static XmString encodeString(char *s);
00325
00329 static char *decodeString(XmString xs);
00330
00334 static void setWidgetSize(SoWidget w, const SbVec2s &size);
00338 static SbVec2s getWidgetSize(SoWidget w);
00339
00340
00341
00342
00348 static SoWidget getShellWidget(SoWidget w);
00349
00355 static void createSimpleErrorDialog(SoWidget widget, char *dialogTitle,
00356 char *errorStr1, char *errorStr2 = NULL);
00357
00361 static void getPopupArgs(UINT *d, int scr, ArgList args, int *n);
00362
00366 static void addColormapToShell(SoWidget widget, SoWidget shell);
00367
00373 static SoConsole *getErrorConsole(void);
00374
00382 static void doIdleTasks(void);
00383
00384 private:
00389 static bool peekEvent(XEvent *event);
00390
00391
00392
00393
00394
00395
00396
00397
00398 static LRESULT isInventorMessage(HWND hwnd, UINT message,
00399 WPARAM wParam, LPARAM lParam);
00400
00401
00402 static void terminate(long terminateSyncTime = 100);
00403
00404
00405
00406 static SbBool PreTranslateMessage(MSG *event);
00407
00408 static UINT wmTimerMsg;
00409 static UINT wmWorkMsg;
00410
00411
00412
00413
00414 static void addExtensionEventHandler(SoWidget w,
00415 int extensionEventType,
00416 XtEventHandler proc,
00417 XtPointer clientData);
00418 static void removeExtensionEventHandler(SoWidget w,
00419 int extensionEventType,
00420 XtEventHandler proc,
00421 XtPointer clientData);
00422
00423
00424 static ATOM registerClass(WNDCLASS *pWndClass, char *actualClassName);
00425
00426
00427 static SbBool getClassInfo(HINSTANCE hDll, const char *className,
00428 char *actualClassName, WNDCLASS *pClassInfo);
00429
00430
00431 static void unregisterProcessClasses();
00432
00433
00434 static void addMessageHook(Hwnd hwnd, UINT msg);
00435 static void removeMessageHook(Hwnd hwnd, UINT msg);
00436
00437
00438
00439
00440
00441 static void setInstance(Hinst hInst);
00442 static Hinst getInstance(void);
00443
00444 static const SoDynamicLibManager::SafeLibraryHandle& getResDllSafeHandle();
00445
00446 static void setPrevInstance(Hinst hInst);
00447
00448 static void setCmdLine(LPSTR cmdLine);
00449
00450 static void setCmdShow(int cmdShow);
00451
00452
00453
00454
00455 static SoWinEventHandler *getEventHandler();
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470 static void registerUIThread(uint32_t threadId = 0);
00471
00472 static void forwardQueryPalette(Window hWnd);
00473 static void forwardPaletteChanged(Window hWnd);
00474
00475 static SbBool handleCtl3DMessage();
00476
00477 static void setHandleCtl3DMessage(SbBool n);
00478
00479 static void Ctl3dColorChange();
00480
00481
00482
00483
00484 static void errorHandlerCB(const SoError *error, void *data);
00485 static void errorHandlerCBMessageBox(const SoError *error, void *userData);
00486
00487
00488 static SoOffscreenRenderer *getOffscreenRenderer();
00489
00490
00491
00492 static SbVec2s &updateRendererSize(SbVec2s size);
00493
00494
00495 static SbConfig * getConfig(void);
00496 static void setConfig(SbConfig *);
00497 static void setConfigFilename(char*);
00498 static char * getConfigFilename(void);
00499
00500 static void addAccelerator(ACCEL accel);
00501
00502 private:
00503 static FARPROC m_procCtl3dColorChange;
00504 static HINSTANCE m_hCtl3d;
00505 static void getExtensionEventHandler(XEvent *event, SoWidget &w,
00506 XtEventHandler &proc,
00507 XtPointer &clientData);
00508
00509 static SbThreadMutex *registerMutex;
00510
00511 private:
00512 static void activeLoop();
00513
00514 static bool internalMainWidget;
00515 static SoWidget mainWidget;
00516 static SoWinEventHandler *eventHandler;
00517 static SbPList *handlerList;
00518
00519
00520 static SbBool nHandleCtl3D;
00521
00522
00523 static SbPList *msgHookList;
00524
00525
00526 static void loadResourceDll();
00527
00528
00529 static Hinst hInstance;
00530 static Hinst hPrevInstance;
00531 static LPTSTR lpszCmdLine;
00532 static int nCmdShow;
00533 static SoDynamicLibManager::SafeLibraryHandle hResDll;
00534
00535
00536 struct RegisteredClassStruct
00537 {
00538 Hinst hinstance;
00539 SbString* className;
00540 };
00541 static SbPList registeredClassList;
00542
00543 friend class SoWinTimerManager;
00544 friend class SoWinEventHandler;
00545
00546 static HWND createThreadWindow(SoWinTimerManager *pTimerManager);
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556 static LRESULT CALLBACK WindowProc(Hwnd hwnd, UINT message,
00557 WPARAM wParam, LPARAM lParam);
00558
00559
00560
00561 static SoOffscreenRenderer *m_pRenderer;
00562
00563 static SoConsole *errorConsole;
00564 static SbBool s_useOldErrorHandler;
00565
00566 static SbConfig *config;
00567 static char *configFile;
00568
00569 static HACCEL m_haccel;
00570
00571 static int s_initRefCount;
00572 static bool shouldExit;
00573 };
00574
00575
00577
00578
00579
00581
00582 #ifdef _WIN32
00583 # include <Inventor/Win/SoWinEndStrict.h>
00584 #endif
00585
00586 #endif
00587
00588