Panda3D
windowProperties.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file windowProperties.cxx
10  * @author drose
11  * @date 2002-08-13
12  */
13 
14 #include "windowProperties.h"
15 #include "config_display.h"
16 #include "nativeWindowHandle.h"
17 
18 using std::istream;
19 using std::ostream;
20 using std::string;
21 
22 WindowProperties *WindowProperties::_default_properties = nullptr;
23 
24 /**
25  *
26  */
27 WindowProperties::
28 WindowProperties() {
29  clear();
30 }
31 
32 /**
33  *
34  */
35 void WindowProperties::
36 operator = (const WindowProperties &copy) {
37  _specified = copy._specified;
38  _origin = copy._origin;
39  _size = copy._size;
40  _title = copy._title;
41  _icon_filename = copy._icon_filename;
42  _cursor_filename = copy._cursor_filename;
43  _z_order = copy._z_order;
44  _flags = copy._flags;
45  _mouse_mode = copy._mouse_mode;
46  _parent_window = copy._parent_window;
47 }
48 
49 /**
50  * Returns a WindowProperties structure with all of the default values filled
51  * in according to the user's config file.
52  */
53 WindowProperties WindowProperties::
54 get_config_properties() {
55  WindowProperties props;
56 
57  props.set_open(true);
58 
59  if (win_size.get_num_words() == 1) {
60  props.set_size(win_size[0], win_size[0]);
61  } else if (win_size.get_num_words() >= 2) {
62  props.set_size(win_size[0], win_size[1]);
63  }
64 
65  if (win_origin.get_num_words() >= 2) {
66  props.set_origin(win_origin[0], win_origin[1]);
67  }
68 
69  props.set_fullscreen(fullscreen);
70  props.set_undecorated(undecorated);
71  props.set_fixed_size(win_fixed_size);
72  props.set_cursor_hidden(cursor_hidden);
73  if (!icon_filename.empty()) {
74  props.set_icon_filename(icon_filename);
75  }
76  if (!cursor_filename.empty()) {
77  props.set_cursor_filename(cursor_filename);
78  }
79  if (z_order.has_value()) {
80  props.set_z_order(z_order);
81  }
82  props.set_title(window_title);
83  if (parent_window_handle.get_value() != 0) {
84  props.set_parent_window(NativeWindowHandle::make_int(parent_window_handle));
85  } else if (!subprocess_window.empty()) {
86  props.set_parent_window(NativeWindowHandle::make_subprocess(subprocess_window));
87  }
88  props.set_mouse_mode(M_absolute);
89 
90  return props;
91 }
92 
93 /**
94  * Returns the "default" WindowProperties. If set_default() has been called,
95  * this returns that WindowProperties structure; otherwise, this returns
96  * get_config_properties().
97  */
98 WindowProperties WindowProperties::
99 get_default() {
100  if (_default_properties != nullptr) {
101  return *_default_properties;
102  } else {
103  return get_config_properties();
104  }
105 }
106 
107 /**
108  * Replaces the "default" WindowProperties with the specified structure. The
109  * specified WindowProperties will be returned by future calls to
110  * get_default(), until clear_default() is called.
111  *
112  * Note that this completely replaces the default properties; it is not
113  * additive.
114  */
116 set_default(const WindowProperties &default_properties) {
117  if (_default_properties == nullptr) {
118  _default_properties = new WindowProperties;
119  }
120  (*_default_properties) = default_properties;
121 }
122 
123 /**
124  * Returns the "default" WindowProperties to whatever is specified in the
125  * user's config file.
126  */
129  if (_default_properties != nullptr) {
130  delete _default_properties;
131  _default_properties = nullptr;
132  }
133 }
134 
135 /**
136  * Returns a WindowProperties structure with only the size specified. The
137  * size is the only property that matters to buffers.
138  *
139  * @deprecated in the Python API, use WindowProperties(size=(x, y)) instead.
140  */
142 size(const LVecBase2i &size) {
143  WindowProperties props;
144  props.set_size(size);
145  return props;
146 }
148 size(int x_size, int y_size) {
149  WindowProperties props;
150  props.set_size(x_size, y_size);
151  return props;
152 }
153 
154 /**
155  *
156  */
157 bool WindowProperties::
158 operator == (const WindowProperties &other) const {
159  return (_specified == other._specified &&
160  _flags == other._flags &&
161  _origin == other._origin &&
162  _size == other._size &&
163  _z_order == other._z_order &&
164  _title == other._title &&
165  _icon_filename == other._icon_filename &&
166  _cursor_filename == other._cursor_filename &&
167  _mouse_mode == other._mouse_mode &&
168  _parent_window == other._parent_window);
169 }
170 
171 /**
172  * Unsets all properties that have been specified so far, and resets the
173  * WindowProperties structure to its initial empty state.
174  */
176 clear() {
177  _specified = 0;
178  _origin = LPoint2i::zero();
179  _size = LVector2i::zero();
180  _title = string();
181  _icon_filename = Filename();
182  _cursor_filename = Filename();
183  _z_order = Z_normal;
184  _flags = 0;
185  _mouse_mode = M_absolute;
186  _parent_window = nullptr;
187 }
188 
189 /**
190  * Specifies the window that this window should be attached to.
191  *
192  * This is a deprecated variant on this method, and exists only for backward
193  * compatibility. Future code should use the version of set_parent_window()
194  * below that receives a WindowHandle object; that interface is much more
195  * robust.
196  *
197  * In this deprecated variant, the actual value for "parent" is platform-
198  * specific. On Windows, it is the HWND of the parent window, cast to an
199  * unsigned integer. On X11, it is the Window pointer of the parent window,
200  * similarly cast. On OSX, this is the NSWindow pointer, which doesn't appear
201  * to work at all.
202  */
204 set_parent_window(size_t parent) {
205  if (parent == 0) {
206  set_parent_window(nullptr);
207  } else {
208  PT(WindowHandle) handle = NativeWindowHandle::make_int(parent);
209  set_parent_window(handle);
210  }
211 }
212 
213 /**
214  * Sets any properties that are explicitly specified in other on this object.
215  * Leaves other properties unchanged.
216  */
219  if (other.has_origin()) {
220  set_origin(other.get_origin());
221  }
222  if (other.has_size()) {
223  set_size(other.get_size());
224  }
225  if (other.has_title()) {
226  set_title(other.get_title());
227  }
228  if (other.has_undecorated()) {
230  }
231  if (other.has_fixed_size()) {
233  }
234  if (other.has_fullscreen()) {
236  }
237  if (other.has_foreground()) {
239  }
240  if (other.has_minimized()) {
241  set_minimized(other.get_minimized());
242  }
243  if (other.has_raw_mice()) {
244  set_raw_mice(other.get_raw_mice());
245  }
246  if (other.has_open()) {
247  set_open(other.get_open());
248  }
249  if (other.has_cursor_hidden()) {
251  }
252  if (other.has_icon_filename()) {
254  }
255  if (other.has_cursor_filename()) {
257  }
258  if (other.has_z_order()) {
259  set_z_order(other.get_z_order());
260  }
261  if (other.has_mouse_mode()) {
263  }
264  if (other.has_parent_window()) {
266  }
267 }
268 
269 /**
270  * Sets any properties that are explicitly specified in other on this object.
271  * Leaves other properties unchanged.
272  */
274 output(ostream &out) const {
275  if (has_origin()) {
276  out << "origin=(" << get_x_origin() << ", " << get_y_origin() << ") ";
277  }
278  if (has_size()) {
279  out << "size=(" << get_x_size() << ", " << get_y_size() << ") ";
280  }
281  if (has_title()) {
282  out << "title=\"" << get_title() << "\"" << " ";
283  }
284  if (has_undecorated()) {
285  out << (get_undecorated() ? "undecorated " : "!undecorated ");
286  }
287  if (has_fixed_size()) {
288  out << (get_fixed_size() ? "fixed_size " : "!fixed_size ");
289  }
290  if (has_fullscreen()) {
291  out << (get_fullscreen() ? "fullscreen " : "!fullscreen ");
292  }
293  if (has_foreground()) {
294  out << (get_foreground() ? "foreground " : "!foreground ");
295  }
296  if (has_minimized()) {
297  out << (get_minimized() ? "minimized " : "!minimized ");
298  }
299  if (has_raw_mice()) {
300  out << (get_raw_mice() ? "raw_mice " : "!raw_mice ");
301  }
302  if (has_open()) {
303  out << (get_open() ? "open " : "!open ");
304  }
305  if (has_cursor_hidden()) {
306  out << (get_cursor_hidden() ? "cursor_hidden " : "!cursor_hidden ");
307  }
308  if (has_icon_filename()) {
309  out << "icon:" << get_icon_filename() << " ";
310  }
311  if (has_cursor_filename()) {
312  out << "cursor:" << get_cursor_filename() << " ";
313  }
314  if (has_z_order()) {
315  out << get_z_order() << " ";
316  }
317  if (has_mouse_mode()) {
318  out << get_mouse_mode() << " ";
319  }
320  if (has_parent_window()) {
321  if (get_parent_window() == nullptr) {
322  out << "parent:none ";
323  } else {
324  out << "parent:" << *get_parent_window() << " ";
325  }
326  }
327 }
328 
329 ostream &
330 operator << (ostream &out, WindowProperties::ZOrder z_order) {
331  switch (z_order) {
332  case WindowProperties::Z_bottom:
333  return out << "bottom";
334 
335  case WindowProperties::Z_normal:
336  return out << "normal";
337 
338  case WindowProperties::Z_top:
339  return out << "top";
340  }
341 
342  return out << "**invalid WindowProperties::ZOrder(" << (int)z_order << ")**";
343 }
344 
345 istream &
346 operator >> (istream &in, WindowProperties::ZOrder &z_order) {
347  string word;
348  in >> word;
349 
350  if (word == "bottom") {
351  z_order = WindowProperties::Z_bottom;
352 
353  } else if (word == "top") {
354  z_order = WindowProperties::Z_top;
355 
356  } else if (word == "normal") {
357  z_order = WindowProperties::Z_normal;
358 
359  } else {
360  display_cat.warning()
361  << "Unknown z-order: " << word << "\n";
362  z_order = WindowProperties::Z_normal;
363  }
364 
365  return in;
366 }
367 
368 // MouseMode operators
369 
370 ostream &
371 operator << (ostream &out, WindowProperties::MouseMode mode) {
372  switch (mode) {
373  case WindowProperties::M_absolute:
374  return out << "absolute";
375  case WindowProperties::M_relative:
376  return out << "relative";
377  case WindowProperties::M_confined:
378  return out << "confined";
379  }
380  return out << "**invalid WindowProperties::MouseMode(" << (int)mode << ")**";
381 }
382 
383 istream &
384 operator >> (istream &in, WindowProperties::MouseMode &mode) {
385  string word;
386  in >> word;
387 
388  if (word == "absolute") {
389  mode = WindowProperties::M_absolute;
390  } else if (word == "relative") {
391  mode = WindowProperties::M_relative;
392  } else if (word == "confined") {
393  mode = WindowProperties::M_confined;
394  } else {
395  display_cat.warning()
396  << "Unknown mouse mode: " << word << "\n";
397  mode = WindowProperties::M_absolute;
398  }
399 
400  return in;
401 }
has_cursor_filename
Returns true if set_cursor_filename() has been specified.
set_mouse_mode
Specifies the mode in which the window is to operate its mouse pointer.
get_mouse_mode
See set_mouse_mode().
has_icon_filename
Returns true if set_icon_filename() has been specified.
has_minimized
Returns true if set_minimized() has been specified.
void clear()
Unsets all properties that have been specified so far, and resets the WindowProperties structure to i...
set_cursor_hidden
Specifies whether the mouse cursor should be visible.
set_parent_window
Specifies the window that this window should be attached to.
get_open
Returns true if the window is open.
This object represents a window on the desktop, not necessarily a Panda window.
Definition: windowHandle.h:34
get_fixed_size
Returns true if the window cannot be resized by the user, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_size
Specifies the requested size of the window, in pixels.
get_cursor_hidden
Returns true if the mouse cursor is invisible.
get_parent_window
Returns the parent window specification, or NULL if there is no parent window specified.
get_foreground
Returns true if the window is in the foreground.
set_fullscreen
Specifies whether the window should be opened in fullscreen mode (true) or normal windowed mode (fals...
set_z_order
Specifies the relative ordering of the window with respect to other windows.
void set_raw_mice(bool raw_mice)
Specifies whether the window should read the raw mouse devices.
get_origin
Returns the coordinates of the window's top-left corner, not including decorations.
set_minimized
Specifies whether the window should be created minimized (true), or normal (false).
set_fixed_size
Specifies whether the window should be resizable by the user.
get_cursor_filename
Returns the icon filename associated with the mouse cursor.
has_parent_window
Checks the S_parent_window specification from the properties.
int get_y_origin() const
Returns the y coordinate of the window's top-left corner, not including decorations.
static WindowProperties size(const LVecBase2i &size)
Returns a WindowProperties structure with only the size specified.
get_title
Returns the window's title.
set_undecorated
Specifies whether the window should be created with a visible title and border (false,...
has_fullscreen
Returns true if set_fullscreen() has been specified.
get_value
Returns the variable's value.
size_t get_num_words() const
Returns the number of words in the variable's value.
set_cursor_filename
Specifies the file that contains the icon to associate with the mouse cursor when it is within the wi...
static void clear_default()
Returns the "default" WindowProperties to whatever is specified in the user's config file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
has_z_order
Returns true if the window z_order has been specified, false otherwise.
A container for the various kinds of properties we might ask to have on a graphics window before we o...
has_open
Returns true if set_open() has been specified.
get_undecorated
Returns true if the window has no border.
has_origin
Returns true if the window origin has been specified, false otherwise.
has_fixed_size
Returns true if set_fixed_size() has been specified.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
set_origin
Specifies the origin on the screen (in pixels, relative to the top-left corner) at which the window s...
get_icon_filename
Returns the icon filename associated with the window.
set_icon_filename
Specifies the file that contains the icon to associate with the window when it is minimized.
get_config_properties
Returns a WindowProperties structure with all of the default values filled in according to the user's...
get_minimized
Returns true if the window is minimized.
get_size
Returns size in pixels of the useful part of the window, not including decorations.
bool get_raw_mice() const
Returns true if the window reads the raw mice.
void output(std::ostream &out) const
Sets any properties that are explicitly specified in other on this object.
has_cursor_hidden
Returns true if set_cursor_hidden() has been specified.
void add_properties(const WindowProperties &other)
Sets any properties that are explicitly specified in other on this object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool has_raw_mice() const
Returns true if set_raw_mice() has been specified.
has_undecorated
Returns true if set_undecorated() has been specified.
has_title
Returns true if the window title has been specified, false otherwise.
set_default
Replaces the "default" WindowProperties with the specified structure.
int get_y_size() const
Returns size in pixels in the y dimension of the useful part of the window, not including decorations...
int get_x_size() const
Returns size in pixels in the x dimension of the useful part of the window, not including decorations...
get_fullscreen
Returns true if the window is in fullscreen mode.
set_open
Specifies whether the window should be open.
int get_x_origin() const
Returns the x coordinate of the window's top-left corner, not including decorations.
get_z_order
Returns the window's z_order.
has_size
Returns true if the window size has been specified, false otherwise.
has_foreground
Returns true if set_foreground() has been specified.
set_title
Specifies the title that should be assigned to the window.
set_foreground
Specifies whether the window should be opened in the foreground (true), or left in the background (fa...