HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_Window.h
Go to the documentation of this file.
1 
2 #ifndef __RE_Window_h__
3 #define __RE_Window_h__
4 
5 #include "RE_API.h"
6 #include "RE_IDType.h"
7 #include "RE_Types.h"
8 
9 #include <UT/UT_Lock.h>
10 #include <UT/UT_Rect.h>
11 #include <UT/UT_ValArray.h>
12 
13 #include <utility>
14 
15 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
16 class RE_Visual;
17 #endif
18 class RE_Server;
19 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
20 class RE_Render;
21 #endif
22 #if defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
23 class RE_WindowList;
24 #endif
25 
26 class QWidget;
27 
28 
30 {
32  alwaysOnTop:1,
33  maximized:1,
34  fullscreen:1;
35 };
36 
38 {
39 public:
40  RE_Window(RE_Server *server,
42  RE_VisualType visType = RE_NORMAL_VIS);
43 
44  virtual ~RE_Window();
45 
46  void setName(const char *name);
47  void setIconName(const char *name);
48 
49  void setParentWindow(RE_Window *parent);
50  const RE_Window *getParentWindow() const { return parentWindow; }
51 
52  void setDialogParentHint(RE_IDType parent_hint);
53 
54  // TODO: No need for getServer(). Move getVisual() to RE_GLDrawable.
55  RE_Server *getServer() { return myServer; }
56 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
58  { return myVisualResource; }
59 
60  RE_Render *getRender();
61  void setRender(RE_Render *r) { myRender = r; }
62 #endif
63 
64  // Opens a window but does not show it immediately.
65  // Call showWindow to show the window.
66  RE_IDType openWindow();
67  void showWindow();
68  void closeWindow();
69 
70  void initMaxSize(int w, int h );
71  void initMinSize(int w, int h );
72 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
73  void initVisual( RE_Visual *visual );
74 #endif
75  void setLimitPositions(bool limitpos)
76  { myLimitPositions = limitpos; }
77  bool getLimitPositions() const
78  { return myLimitPositions; }
79 
80  void moveWindow(int x, int y);
81  void sizeWindow(int w, int h);
82 
83  // Set the window's opacity (0.0 - 1.0).
84  // Values less than 1.0 will make the window translucent.
85  void setWindowOpacity(fpreal opacity);
86 
87 
88  // Maximize the window and/or mark it as maximized so that when openWindow
89  // is called, it can open the window maximized.
90  void maximizeWindow();
91  void restoreWindow();
92 
93  bool isMaximized() const;
94 
95  // Set the window as fullscreen. Depending on the windowing system, this
96  // either informs the window manager to set us as fullscreen or simply
97  // sets borders up so that higher-level classes can do the fullscreening
98  // themselves.
99  void fullscreenWindow(bool full);
100  bool isFullscreenWindow() const;
101  void lowerWindow();
102  void raiseWindow();
103 
104  // Show/Hide the Window Frame/ Titlebar
105  void setHasWindowFrame(bool b);
106  bool hasWindowFrame() const;
107 
108  int getBorderWidth() const
109  { return myLeftBorder+myRightBorder; }
110  int getBorderHeight() const
111  { return myTopBorder+myBottomBorder; }
112  int getBorderTopSize() const
113  { return myTopBorder; }
114  int getBorderLeftSize() const
115  { return myLeftBorder; }
117  { return myBottomBorder; }
118  int getBorderRightSize() const
119  { return myRightBorder; }
120 
121  UT_DimRect findLocation() const;
122 
123  // Sets the window to sit on top of all other windows, or turns off that
124  // state, depending on whether newstate is true or false.
125  void setWindowAlwaysOnTop(bool newstate);
126  int getWindowAlwaysOnTop() const { return winFlags.alwaysOnTop; }
127 
128  void setWindowFloatOnTop(bool on_top);
129 
130  RE_DisplayMode getMode() const;
131 
133  { return myVisualType; }
134  void setVisualType(RE_VisualType t) { myVisualType = t; }
135 
136  // changes to the type will not occur until the window is opened again.
138  { myWindowType = t; }
139 
140  RE_WindowType getWindowType( bool extra=false) const;
141 
142 
143 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
144  void setWindowID(RE_IDType id) { myWindowID = id; }
146  { return myWindowID; }
147 #else
148  RE_IDType getWindowID() const;
149 #endif
150  int matchID( RE_IDType wid ) const
151  { return wid == myWindowID; }
152 
153  virtual RE_IDType getBufferID() const { return 0; }
154 
155 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
156  OGLDrawable getGraphicsDrawable() const { return myDrawable; }
157  void setGraphicsDrawable(OGLDrawable d) { myDrawable = d; }
158 #endif
159 
160 
161  void setIMESupport(bool enable);
162 
163  /// Return the Qt main window.
164  static QWidget * mainQtWindow();
165 
166  /// Initialize the given widget window with the desired
167  /// Houdini window properties, look and feel.
168  static void initQtWindow(
169  QWidget &window, RE_WindowType win_type,
170  bool always_on_top);
171 
172  /// Create a Qt window widget for the given window type.
173  /// The caller takes ownership of the returned object.
174  static QWidget * createQtWindow(RE_WindowType win_type);
175 
176  /// Returns true if Houdini or any of its sub windows are focused
177  static bool appActive();
178 
179  void setWindowBorders(int left, int right, int top, int bottom)
180  {
181  myLeftBorder = left;
182  myRightBorder = right;
183  myTopBorder = top;
184  myBottomBorder = bottom;
185  }
186 
187  // This is called by the native window to inform that it has changed its
188  // maximized state.
189  void updateMaximizedFlag(bool is_maximized)
190  {
191  winFlags.maximized = is_maximized;
192  }
193 
194  static bool isTabFocusEnabled();
195  static void enableTabFocus(bool enable);
196 
197  /// Return the string tag used to identify whether a Qt widget is the
198  /// window for an RE_Window object.
199  static const char * windowTag() { return "RE_Window"; }
200 
201 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
202  bool isQuadBufferStereo() const;
203 #endif
204 
205  /// Return the screen number containing this window.
206  /// If the underlying platform window has not been created
207  /// yet then return the primary screen number.
208  int screen() const;
209 
210  /// Get screen-to-window scale.
211  fpreal screenToDeviceScale() const;
212 
213  /// Get Default Window Border Sizes
214  static const int* getDefaultWindowBorderSizes();
215  static int getDefaultWindowTitleBarHeight();
216 
217 #if defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
218  static RE_WindowList *getWindowList();
219 #endif
220 
221 private:
222  /// Initialize window borders.
223  void initBorderSizes_();
224 
225  /// Move the underlying Qt window to the position specified by myFrame.
226  void moveQtWindow_();
227 
228 #if defined(WIN32)
229  /// Add the Always On Top menu item to the window's system menu.
230  void addAlwaysOnTopSystemMenuItem_();
231 #endif
232 
233 private:
234 #if defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
235  QWidget *getOrCreateQtWindow_() const;
236 #endif
237 
238  RE_Server *myServer;
239 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
240  RE_Render *myRender;
241  RE_Visual *myVisualResource;
242 #endif
243  RE_VisualType myVisualType;
244 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
245  RE_IDType myWindowID;
246 #else
247  mutable RE_IDType myWindowID;
248 #endif
249 
250 #if defined(WIN32)
251  // This widget is for stashing away the Qt window when it closes and
252  // detaches from its parent window. There's a limitation on Windows
253  // where a Qt window cannot be gracefully detached from the parent.
254  // The workaround is to instead reparent the Qt window instead of
255  // completely detaching it.
256  QWidget *myStashWidget;
257 #endif
258 
259  UT_String myName;
260  UT_String myIconName;
261 
262  // Window geometry in native screen coordinates and scaling.
263  UT_DimRect myFrame;
264 
265  using IntPair = std::pair<int, int>;
266 
267  // Window sizes in native screen scaling.
268  IntPair myMinSize;
269  IntPair myMaxSize;
270 
271 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
272  OGLDrawable myDrawable;
273 #endif
274 
275 
276  unsigned long myIconPixmap;
277  RE_WindowFlags winFlags;
278  RE_Window *parentWindow;
279  RE_IDType myDialogParentHint;
280 
281  RE_WindowType myWindowType;
282 
283  int myLeftBorder;
284  int myTopBorder;
285  int myRightBorder;
286  int myBottomBorder;
287 
288  unsigned int myLimitPositions:1;
289 
290  fpreal myWindowOpacity;
291 
292 #if defined(WIN32)
293  bool myAddedAlwaysOnTopMenuItem;
294 #endif
295 };
296 
298 {
299 public:
301  { }
303  { }
304 
305  void lock()
306  { myLock.lock(); }
307  void unlock()
308  { myLock.unlock(); }
310  { lock(); myWindows.append(w); unlock(); }
312  { lock(); myWindows.findAndRemove(w); unlock(); }
313  int getNumWindows() const
314  { return myWindows.entries(); }
316  { return myWindows(index); }
317  void removeWindow(RE_IDType wid);
318  RE_Window *isWindowHere(RE_IDType wid);
319 
320 private:
321  UT_ValArray<RE_Window *> myWindows;
322  UT_Lock myLock;
323 };
324 
325 #endif
void * RE_IDType
Definition: RE_IDType.h:20
GLfloat GLfloat GLfloat top
Definition: glew.h:15525
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GLboolean enable
Definition: glew.h:2750
void setRender(RE_Render *r)
Definition: RE_Window.h:61
void removeWindow(RE_Window *w)
Definition: RE_Window.h:311
const RE_Window * getParentWindow() const
Definition: RE_Window.h:50
bool isOriginReadjusted
Definition: RE_Window.h:31
#define RE_API
Definition: RE_API.h:10
void setWindowID(RE_IDType id)
Definition: RE_Window.h:144
RE_VisualType getVisualType() const
Definition: RE_Window.h:132
GLint left
Definition: glcorearb.h:2004
int getBorderLeftSize() const
Definition: RE_Window.h:114
int getBorderWidth() const
Definition: RE_Window.h:108
void setWindowType(RE_WindowType t)
Definition: RE_Window.h:137
void addWindow(RE_Window *w)
Definition: RE_Window.h:309
GLuint const GLchar * name
Definition: glcorearb.h:785
RE_Window * getWindow(int index) const
Definition: RE_Window.h:315
int getWindowAlwaysOnTop() const
Definition: RE_Window.h:126
GLdouble GLdouble t
Definition: glew.h:1403
GLfloat right
Definition: glew.h:15525
GLint GLenum GLint x
Definition: glcorearb.h:408
bool alwaysOnTop
Definition: RE_Window.h:31
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
OGLDrawable getGraphicsDrawable() const
Definition: RE_Window.h:156
void setGraphicsDrawable(OGLDrawable d)
Definition: RE_Window.h:157
void unlock()
Definition: RE_Window.h:307
int getBorderBottomSize() const
Definition: RE_Window.h:116
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
void setVisualType(RE_VisualType t)
Definition: RE_Window.h:134
virtual RE_IDType getBufferID() const
Definition: RE_Window.h:153
int matchID(RE_IDType wid) const
Definition: RE_Window.h:150
GLint GLint bottom
Definition: glcorearb.h:2004
int getNumWindows() const
Definition: RE_Window.h:313
int getBorderRightSize() const
Definition: RE_Window.h:118
GLuint id
Definition: glcorearb.h:654
RE_DisplayMode
Definition: RE_Types.h:553
void setLimitPositions(bool limitpos)
Definition: RE_Window.h:75
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
bool maximized
Definition: RE_Window.h:31
fpreal64 fpreal
Definition: SYS_Types.h:277
RE_Visual * getVisual()
Definition: RE_Window.h:57
int getBorderHeight() const
Definition: RE_Window.h:110
GLuint index
Definition: glcorearb.h:785
RE_VisualType
Definition: RE_Types.h:603
void lock()
Definition: RE_Window.h:305
bool fullscreen
Definition: RE_Window.h:31
int getBorderTopSize() const
Definition: RE_Window.h:112
void updateMaximizedFlag(bool is_maximized)
Definition: RE_Window.h:189
void setWindowBorders(int left, int right, int top, int bottom)
Definition: RE_Window.h:179
RE_WindowType
Definition: RE_Types.h:20
GLboolean r
Definition: glcorearb.h:1221
static const char * windowTag()
Definition: RE_Window.h:199
bool getLimitPositions() const
Definition: RE_Window.h:77
RE_IDType getWindowID() const
Definition: RE_Window.h:145
GLint y
Definition: glcorearb.h:102
RE_Server * getServer()
Definition: RE_Window.h:55