Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://coin3d.github.io
https://www.kongsberg.com/en/kogt/
SoWin.h
1 #ifndef SOWIN_H
2 #define SOWIN_H
3 
4 //
5 
6 /**************************************************************************\
7  * Copyright (c) Kongsberg Oil & Gas Technologies AS
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are
12  * met:
13  *
14  * Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  *
17  * Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in the
19  * documentation and/or other materials provided with the distribution.
20  *
21  * Neither the name of the copyright holder nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 \**************************************************************************/
37 
38 #include <Inventor/Win/SoWinBasic.h>
39 
40 // FIXME: use configure defines for the header files.
41 // 20020613 mortene.
42 
43 #ifdef __COIN_SOQT__
44 
45 #if QT_VERSION >= 0x040000
46 #include <QtCore/QObject>
47 #else
48 #include <qobject.h>
49 #endif
50 
51 #endif // __COIN_SOQT__
52 #ifdef __COIN_SOXT__
53 #include <X11/Intrinsic.h>
54 #include <Xm/Xm.h>
55 #endif // __COIN_SOXT__
56 #ifdef __COIN_SOGTK__
57 // Fetch stdlib.h, so NULL is defined before glib.h is (indirectly)
58 // included. Otherwise we get a compile error with KCC on some
59 // systems.
60 #include <cstdlib>
61 #include <gtk/gtk.h>
62 class SoGtkComponent;
63 class SbPList;
64 #endif // __COIN_SOGTK__
65 #ifdef __COIN_SOWIN__
66 #include <windows.h>
67 #endif // __COIN_SOWIN__
68 #ifdef __COIN_SOWX__
69 #include <wx/wx.h>
70 #endif // __COIN_SOWX__
71 
72 #include <Inventor/SbBasic.h>
73 #include <Inventor/SbLinear.h>
74 #include <Inventor/SbString.h>
75 #include <Inventor/SoDB.h>
76 #include <Inventor/errors/SoDebugError.h>
77 
78 // *************************************************************************
79 
80 class SOWIN_DLL_API SoWin
81 {
82 
83 public:
84  static HWND init(const char * appname, const char * classname = "SoWin");
85  static HWND init(int & argc, char ** argv,
86  const char * appname, const char * classname = "SoWin");
87  static void init(HWND toplevelwidget);
88 
89  static void mainLoop(void);
90  static void exitMainLoop(void);
91  static void done(void);
92 
93  static HWND getTopLevelWidget(void);
94  static HWND getShellWidget(const HWND w);
95 
96  static void show(HWND const widget);
97  static void hide(HWND const widget);
98 
99  static void setWidgetSize(HWND const widget, const SbVec2s size);
100  static SbVec2s getWidgetSize(const HWND widget);
101 
102  static void createSimpleErrorDialog(HWND widget,
103  const char * title,
104  const char * string1,
105  const char * string2 = NULL);
106 
107  static void getVersionInfo(int * major = NULL,
108  int * minor = NULL,
109  int * micro = NULL);
110  static const char * getVersionString(void);
111  static const char * getVersionToolkitString(void);
112 
113  enum FatalErrors {
114  UNSPECIFIED_ERROR = 0,
116  INTERNAL_ASSERT
117  };
118  typedef void FatalErrorCB(const SbString errmsg, SoWin::FatalErrors errcode,
119  void * userdata);
120  static FatalErrorCB * setFatalErrorHandler(SoWin::FatalErrorCB * cb,
121  void * userdata);
122 
123  static SbBool isDebugLibrary(void);
124  static SbBool isCompatible(unsigned int major, unsigned int minor);
125 
126  enum ABIType { DLL, LIB, UNKNOWN };
127  static ABIType getABIType(void);
128 
129  static void lockGL(void);
130  static void unlockGL(void);
131 
132 private:
133  // Since the class consists solely of static functions, hide the
134  // default constructor and the destructor so nobody can instantiate
135  // it.
136  SoWin(void);
137  virtual ~SoWin();
138 
139  friend class SoGuiP;
140  friend class SoWinP;
141 
142 
143  // FIXME!: audit and remove as much as possible of the remaining
144  // toolkit specific parts below. 20020117 mortene.
145 
146 #ifdef __COIN_SOWIN__
147 public:
148  static void doIdleTasks(void);
149 #endif // __COIN_SOWIN__
150 
151 #ifdef __COIN_SOXT__
152 public:
153  static void nextEvent(XtAppContext, XEvent *);
154  static Boolean dispatchEvent(XEvent * event);
155  static XtAppContext getAppContext(void);
156  static Display * getDisplay(void);
157  static XmString encodeString(const char * const str);
158  static char * decodeString(XmString xstring);
159  static void getPopupArgs(Display * display, int screen,
160  ArgList args, int * n);
161 
162  static void registerColormapLoad(Widget widget, Widget shell);
163  static void addColormapToShell(Widget widget, Widget shell);
164  static void removeColormapFromShell(Widget widget, Widget shell);
165 
166  static void addExtensionEventHandler(Widget widget,
167  int eventType, XtEventHandler proc,
168  XtPointer clientData);
169  static void removeExtensionEventHandler(Widget widget,
170  int eventType, XtEventHandler proc,
171  XtPointer clientData);
172 
173 protected:
174  static void getExtensionEventHandler(XEvent * event, Widget & widget,
175  XtEventHandler & proc,
176  XtPointer & clientData);
177 #endif // __COIN_SOXT__
178 
179 #ifdef __COIN_SOGTK__
180 public:
181  friend class SoGtkComponent;
182  enum SoGtkComponentAction { CREATION, DESTRUCTION, CHANGE };
183  typedef void SoGtkComponentActionCallback(SoGtkComponent *, SoGtk::SoGtkComponentAction, void *);
184 
185  static void addComponentActionCallback(SoGtkComponentActionCallback *, void *);
186  static void removeComponentActionCallback(SoGtkComponentActionCallback *, void *);
187 
188  static int getComponents(SbPList & components);
189 
190 protected:
191  static void invokeComponentActionCallbacks(SoGtkComponent * component,
192  SoGtkComponentAction action);
193 
194  static gint componentCreation(SoGtkComponent * component);
195  static gint componentDestruction(SoGtkComponent * component);
196  static gint componentChange(SoGtkComponent * component);
197 
198 private:
199  static gint timerSensorCB(gpointer data);
200  static gint idleSensorCB(gpointer data);
201  static gint delaySensorCB(gpointer data);
202 
203  static GtkWidget * mainWidget;
204  static SbPList * components;
205  static SbPList * component_callbacks;
206 #endif // __COIN_SOGTK__
207 };
208 
209 // *************************************************************************
210 // Here's something InventorWin provides for convenience. Belongs more
211 // in the application code domain, imo, but we provide these macros
212 // for better compile time compatibility with InventorWin. -mortene
213 
214 #define SOWIN_ENTER_GL_SECTION() do { SoWin::lockGL(); } while(FALSE)
215 #define SOWIN_LEAVE_GL_SECTION() do { SoWin::unlockGL(); } while(FALSE)
216 
217 // *************************************************************************
218 
219 #endif // ! SOWIN_H
The SoWin class takes care of Win initialization and event dispatching.
Definition: SoWin.h:80
Definition: SoWin.h:115
FatalErrors
Definition: SoWin.h:113
void FatalErrorCB(const SbString errmsg, SoWin::FatalErrors errcode, void *userdata)
Definition: SoWin.h:118
ABIType
Definition: SoWin.h:126