Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SoQt.h
1 #ifndef SOQT_H
2 #define SOQT_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/Qt/SoQtBasic.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 <stdlib.h>
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 
69 #include <Inventor/SbBasic.h>
70 #include <Inventor/SbLinear.h>
71 #include <Inventor/SbString.h>
72 #include <Inventor/SoDB.h>
73 #include <Inventor/errors/SoDebugError.h>
74 
75 // *************************************************************************
76 
77 class SOQT_DLL_API SoQt
78 {
79 
80 public:
81  static QWidget* init(const char * appname, const char * classname = "SoQt");
82  static QWidget* init(int & argc, char ** argv,
83  const char * appname, const char * classname = "SoQt");
84  static void init(QWidget* toplevelwidget);
85 
86  static void mainLoop(void);
87  static void exitMainLoop(void);
88  static void done(void);
89 
90  static QWidget* getTopLevelWidget(void);
91  static QWidget* getShellWidget(const QWidget* w);
92 
93  static void show(QWidget* const widget);
94  static void hide(QWidget* const widget);
95 
96  static void setWidgetSize(QWidget* const widget, const SbVec2s size);
97  static SbVec2s getWidgetSize(const QWidget* widget);
98 
99  static void createSimpleErrorDialog(QWidget* widget,
100  const char * title,
101  const char * string1,
102  const char * string2 = NULL);
103 
104  static void getVersionInfo(int * major = NULL,
105  int * minor = NULL,
106  int * micro = NULL);
107  static const char * getVersionString(void);
108  static const char * getVersionToolkitString(void);
109 
110  enum FatalErrors {
111  UNSPECIFIED_ERROR = 0,
113  INTERNAL_ASSERT
114  };
115  typedef void FatalErrorCB(const SbString errmsg, SoQt::FatalErrors errcode,
116  void * userdata);
117  static FatalErrorCB * setFatalErrorHandler(SoQt::FatalErrorCB * cb,
118  void * userdata);
119 
120  static SbBool isDebugLibrary(void);
121  static SbBool isCompatible(unsigned int major, unsigned int minor);
122 
123  enum ABIType { DLL, LIB, UNKNOWN };
124  static ABIType getABIType(void);
125 
126  static void lockGL(void);
127  static void unlockGL(void);
128 
129 private:
130  // Since the class consists solely of static functions, hide the
131  // default constructor and the destructor so nobody can instantiate
132  // it.
133  SoQt(void);
134  virtual ~SoQt();
135 
136  friend class SoGuiP;
137  friend class SoQtP;
138 
139 
140  // FIXME!: audit and remove as much as possible of the remaining
141  // toolkit specific parts below. 20020117 mortene.
142 
143 #ifdef __COIN_SOWIN__
144 public:
145  static void doIdleTasks(void);
146 #endif // __COIN_SOWIN__
147 
148 #ifdef __COIN_SOXT__
149 public:
150  static void nextEvent(XtAppContext, XEvent *);
151  static Boolean dispatchEvent(XEvent * event);
152  static XtAppContext getAppContext(void);
153  static Display * getDisplay(void);
154  static XmString encodeString(const char * const str);
155  static char * decodeString(XmString xstring);
156  static void getPopupArgs(Display * display, int screen,
157  ArgList args, int * n);
158 
159  static void registerColormapLoad(Widget widget, Widget shell);
160  static void addColormapToShell(Widget widget, Widget shell);
161  static void removeColormapFromShell(Widget widget, Widget shell);
162 
163  static void addExtensionEventHandler(Widget widget,
164  int eventType, XtEventHandler proc,
165  XtPointer clientData);
166  static void removeExtensionEventHandler(Widget widget,
167  int eventType, XtEventHandler proc,
168  XtPointer clientData);
169 
170 protected:
171  static void getExtensionEventHandler(XEvent * event, Widget & widget,
172  XtEventHandler & proc,
173  XtPointer & clientData);
174 #endif // __COIN_SOXT__
175 
176 #ifdef __COIN_SOGTK__
177 public:
178  friend class SoGtkComponent;
179  enum SoGtkComponentAction { CREATION, DESTRUCTION, CHANGE };
180  typedef void SoGtkComponentActionCallback(SoGtkComponent *, SoGtk::SoGtkComponentAction, void *);
181 
182  static void addComponentActionCallback(SoGtkComponentActionCallback *, void *);
183  static void removeComponentActionCallback(SoGtkComponentActionCallback *, void *);
184 
185  static int getComponents(SbPList & components);
186 
187 protected:
188  static void invokeComponentActionCallbacks(SoGtkComponent * component,
189  SoGtkComponentAction action);
190 
191  static gint componentCreation(SoGtkComponent * component);
192  static gint componentDestruction(SoGtkComponent * component);
193  static gint componentChange(SoGtkComponent * component);
194 
195 private:
196  static gint timerSensorCB(gpointer data);
197  static gint idleSensorCB(gpointer data);
198  static gint delaySensorCB(gpointer data);
199 
200  static GtkWidget * mainWidget;
201  static SbPList * components;
202  static SbPList * component_callbacks;
203 #endif // __COIN_SOGTK__
204 };
205 
206 // *************************************************************************
207 // Here's something InventorWin provides for convenience. Belongs more
208 // in the application code domain, imo, but we provide these macros
209 // for better compile time compatibility with InventorWin. -mortene
210 
211 #define SOQT_ENTER_GL_SECTION() do { SoQt::lockGL(); } while(FALSE)
212 #define SOQT_LEAVE_GL_SECTION() do { SoQt::unlockGL(); } while(FALSE)
213 
214 // *************************************************************************
215 
216 #endif // ! SOQT_H
The SoQt class takes care of Qt initialization and event dispatching.
Definition: SoQt.h:77
ABIType
Definition: SoQt.h:123
FatalErrors
Definition: SoQt.h:110
Definition: SoQt.h:112
void FatalErrorCB(const SbString errmsg, SoQt::FatalErrors errcode, void *userdata)
Definition: SoQt.h:115