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