Panda3D

windowProperties.cxx

00001 // Filename: windowProperties.cxx
00002 // Created by:  drose (13Aug02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "windowProperties.h"
00016 #include "config_display.h"
00017 #include "nativeWindowHandle.h"
00018 
00019 WindowProperties *WindowProperties::_default_properties = NULL;
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: WindowProperties::Constructor
00023 //       Access: Published
00024 //  Description:
00025 ////////////////////////////////////////////////////////////////////
00026 WindowProperties::
00027 WindowProperties() {
00028   clear();
00029 }
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //     Function: WindowProperties::Copy Assignment Operator
00033 //       Access: Published
00034 //  Description:
00035 ////////////////////////////////////////////////////////////////////
00036 void WindowProperties::
00037 operator = (const WindowProperties &copy) {
00038   _specified = copy._specified;
00039   _x_origin = copy._x_origin;
00040   _y_origin = copy._y_origin;
00041   _x_size = copy._x_size;
00042   _y_size = copy._y_size;
00043   _title = copy._title;
00044   _icon_filename = copy._icon_filename;
00045   _cursor_filename = copy._cursor_filename;
00046   _z_order = copy._z_order;
00047   _flags = copy._flags;
00048   _mouse_mode = copy._mouse_mode;
00049   _parent_window = copy._parent_window;
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: WindowProperties::get_config_properties
00054 //       Access: Published, Static
00055 //  Description: Returns a WindowProperties structure with all of the
00056 //               default values filled in according to the user's
00057 //               config file.
00058 ////////////////////////////////////////////////////////////////////
00059 WindowProperties WindowProperties::
00060 get_config_properties() {
00061   WindowProperties props;
00062 
00063   props.set_open(true);
00064 
00065   if (win_size.get_num_words() == 1) {
00066     props.set_size(win_size[0], win_size[0]);
00067   } else if (win_size.get_num_words() >= 2) {
00068     props.set_size(win_size[0], win_size[1]);
00069   }
00070 
00071   if (win_origin.get_num_words() >= 2) {
00072     props.set_origin(win_origin[0], win_origin[1]);
00073   }
00074 
00075   props.set_fullscreen(fullscreen);
00076   props.set_undecorated(undecorated);
00077   props.set_fixed_size(win_fixed_size);
00078   props.set_cursor_hidden(cursor_hidden);
00079   if (!icon_filename.empty()) {
00080     props.set_icon_filename(icon_filename);
00081   }
00082   if (!cursor_filename.empty()) {
00083     props.set_cursor_filename(cursor_filename);
00084   }
00085   if (z_order.has_value()) {
00086     props.set_z_order(z_order);
00087   }
00088   props.set_title(window_title);
00089   if (parent_window_handle.get_value() != 0) {
00090     props.set_parent_window(NativeWindowHandle::make_int(parent_window_handle));
00091   } else if (!subprocess_window.empty()) {
00092     props.set_parent_window(NativeWindowHandle::make_subprocess(subprocess_window));
00093   }
00094   props.set_mouse_mode(M_absolute);
00095 
00096   return props;
00097 }
00098 
00099 ////////////////////////////////////////////////////////////////////
00100 //     Function: WindowProperties::get_default
00101 //       Access: Published, Static
00102 //  Description: Returns the "default" WindowProperties.  If
00103 //               set_default() has been called, this returns that
00104 //               WindowProperties structure; otherwise, this returns
00105 //               get_config_properties().
00106 ////////////////////////////////////////////////////////////////////
00107 WindowProperties WindowProperties::
00108 get_default() {
00109   if (_default_properties != NULL) {
00110     return *_default_properties;
00111   } else {
00112     return get_config_properties();
00113   }
00114 }
00115 
00116 ////////////////////////////////////////////////////////////////////
00117 //     Function: WindowProperties::set_default
00118 //       Access: Published, Static
00119 //  Description: Replaces the "default" WindowProperties with the
00120 //               specified structure.  The specified WindowProperties
00121 //               will be returned by future calls to get_default(),
00122 //               until clear_default() is called.
00123 //
00124 //               Note that this completely replaces the default
00125 //               properties; it is not additive.
00126 ////////////////////////////////////////////////////////////////////
00127 void WindowProperties::
00128 set_default(const WindowProperties &default_properties) {
00129   if (_default_properties == NULL) {
00130     _default_properties = new WindowProperties;
00131   }
00132   (*_default_properties) = default_properties;
00133 }
00134 
00135 ////////////////////////////////////////////////////////////////////
00136 //     Function: WindowProperties::clear_default
00137 //       Access: Published, Static
00138 //  Description: Returns the "default" WindowProperties to whatever
00139 //               is specified in the user's config file.
00140 ////////////////////////////////////////////////////////////////////
00141 void WindowProperties::
00142 clear_default() {
00143   if (_default_properties != NULL) {
00144     delete _default_properties;
00145     _default_properties = NULL;
00146   }
00147 }
00148 
00149 ////////////////////////////////////////////////////////////////////
00150 //     Function: WindowProperties::size
00151 //       Access: Published, Static
00152 //  Description: Returns a WindowProperties structure with only the
00153 //               size specified.  The size is the only property that
00154 //               matters to buffers.
00155 ////////////////////////////////////////////////////////////////////
00156 WindowProperties WindowProperties::
00157 size(int x_size, int y_size) {
00158   WindowProperties props;
00159   props.set_size(x_size, y_size);
00160   return props;
00161 }
00162 
00163 ////////////////////////////////////////////////////////////////////
00164 //     Function: WindowProperties::operator == 
00165 //       Access: Published
00166 //  Description:
00167 ////////////////////////////////////////////////////////////////////
00168 bool WindowProperties::
00169 operator == (const WindowProperties &other) const {
00170   return (_specified == other._specified &&
00171           _flags == other._flags &&
00172           _x_origin == other._x_origin &&
00173           _y_origin == other._y_origin &&
00174           _x_size == other._x_size &&
00175           _y_size == other._y_size &&
00176           _z_order == other._z_order &&
00177           _title == other._title &&
00178           _icon_filename == other._icon_filename &&
00179           _cursor_filename == other._cursor_filename &&
00180           _mouse_mode == other._mouse_mode &&
00181           _parent_window == other._parent_window);
00182 }
00183 
00184 ////////////////////////////////////////////////////////////////////
00185 //     Function: WindowProperties::clear
00186 //       Access: Published
00187 //  Description: Unsets all properties that have been specified so
00188 //               far, and resets the WindowProperties structure to its
00189 //               initial empty state.
00190 ////////////////////////////////////////////////////////////////////
00191 void WindowProperties::
00192 clear() {
00193   _specified = 0;
00194   _x_origin = 0;
00195   _y_origin = 0;
00196   _x_size = 0;
00197   _y_size = 0;
00198   _title = string();
00199   _icon_filename = Filename();
00200   _cursor_filename = Filename();
00201   _z_order = Z_normal;
00202   _flags = 0;
00203   _mouse_mode = M_absolute;
00204   _parent_window = NULL;
00205 }
00206 
00207 ////////////////////////////////////////////////////////////////////
00208 //     Function: WindowProperties::set_parent_window
00209 //       Access: Published
00210 //  Description: Specifies the window that this window should be
00211 //               attached to.
00212 //
00213 //               This is a deprecated variant on this method, and
00214 //               exists only for backward compatibility.  Future code
00215 //               should use the version of set_parent_window() below
00216 //               that receives a WindowHandle object; that interface
00217 //               is much more robust.
00218 //
00219 //               In this deprecated variant, the actual value for
00220 //               "parent" is platform-specific.  On Windows, it is the
00221 //               HWND of the parent window, cast to an unsigned
00222 //               integer.  On X11, it is the Window pointer of the
00223 //               parent window, similarly cast.  On OSX, this is the
00224 //               NSWindow pointer, which doesn't appear to work at
00225 //               all.
00226 ////////////////////////////////////////////////////////////////////
00227 void WindowProperties::
00228 set_parent_window(size_t parent) {
00229   if (parent == 0) {
00230     set_parent_window((WindowHandle *)NULL);
00231   } else {
00232     PT(WindowHandle) handle = NativeWindowHandle::make_int(parent);
00233     set_parent_window(handle);
00234   }
00235 }
00236 
00237 ////////////////////////////////////////////////////////////////////
00238 //     Function: WindowProperties::add_properties
00239 //       Access: Published
00240 //  Description: Sets any properties that are explicitly specified in
00241 //               other on this object.  Leaves other properties
00242 //               unchanged.
00243 ////////////////////////////////////////////////////////////////////
00244 void WindowProperties::
00245 add_properties(const WindowProperties &other) {
00246   if (other.has_origin()) {
00247     set_origin(other.get_x_origin(), other.get_y_origin());
00248   }
00249   if (other.has_size()) {
00250     set_size(other.get_x_size(), other.get_y_size());
00251   }
00252   if (other.has_title()) {
00253     set_title(other.get_title());
00254   }
00255   if (other.has_undecorated()) {
00256     set_undecorated(other.get_undecorated());
00257   }
00258   if (other.has_fixed_size()) {
00259     set_fixed_size(other.get_fixed_size());
00260   }
00261   if (other.has_fullscreen()) {
00262     set_fullscreen(other.get_fullscreen());
00263   }
00264   if (other.has_foreground()) {
00265     set_foreground(other.get_foreground());
00266   }
00267   if (other.has_minimized()) {
00268     set_minimized(other.get_minimized());
00269   }
00270   if (other.has_raw_mice()) {
00271     set_raw_mice(other.get_raw_mice());
00272   }
00273   if (other.has_open()) {
00274     set_open(other.get_open());
00275   }
00276   if (other.has_cursor_hidden()) {
00277     set_cursor_hidden(other.get_cursor_hidden());
00278   }
00279   if (other.has_icon_filename()) {
00280     set_icon_filename(other.get_icon_filename());
00281   }
00282   if (other.has_cursor_filename()) {
00283     set_cursor_filename(other.get_cursor_filename());
00284   }
00285   if (other.has_z_order()) {
00286     set_z_order(other.get_z_order());
00287   }
00288   if (other.has_mouse_mode()) {
00289     set_mouse_mode(other.get_mouse_mode());
00290   }
00291   if (other.has_parent_window()) {
00292     set_parent_window(other.get_parent_window());
00293   }
00294 }
00295 
00296 ////////////////////////////////////////////////////////////////////
00297 //     Function: WindowProperties::output
00298 //       Access: Published
00299 //  Description: Sets any properties that are explicitly specified in
00300 //               other on this object.  Leaves other properties
00301 //               unchanged.
00302 ////////////////////////////////////////////////////////////////////
00303 void WindowProperties::
00304 output(ostream &out) const {
00305   if (has_origin()) {
00306     out << "origin=(" << get_x_origin() << ", " << get_y_origin() << ") ";
00307   }
00308   if (has_size()) {
00309     out << "size=(" << get_x_size() << ", " << get_y_size() << ") ";
00310   }
00311   if (has_title()) {
00312     out << "title=\"" << get_title() << "\"" << " ";
00313   }
00314   if (has_undecorated()) {
00315     out << (get_undecorated() ? "undecorated " : "!undecorated ");
00316   }
00317   if (has_fixed_size()) {
00318     out << (get_fixed_size() ? "fixed_size " : "!fixed_size ");
00319   }
00320   if (has_fullscreen()) {
00321     out << (get_fullscreen() ? "fullscreen " : "!fullscreen ");
00322   }
00323   if (has_foreground()) {
00324     out << (get_foreground() ? "foreground " : "!foreground ");
00325   }
00326   if (has_minimized()) {
00327     out << (get_minimized() ? "minimized " : "!minimized ");
00328   }
00329   if (has_raw_mice()) {
00330     out << (get_raw_mice() ? "raw_mice " : "!raw_mice ");
00331   }
00332   if (has_open()) {
00333     out << (get_open() ? "open " : "!open ");
00334   }
00335   if (has_cursor_hidden()) {
00336     out << (get_cursor_hidden() ? "cursor_hidden " : "!cursor_hidden ");
00337   }
00338   if (has_icon_filename()) {
00339     out << "icon:" << get_icon_filename() << " ";
00340   }
00341   if (has_cursor_filename()) {
00342     out << "cursor:" << get_cursor_filename() << " ";
00343   }
00344   if (has_z_order()) {
00345     out << get_z_order() << " ";
00346   }
00347   if (has_mouse_mode()) {
00348     out << get_mouse_mode() << " ";
00349   }
00350   if (has_parent_window()) {
00351     if (get_parent_window() == NULL) {
00352       out << "parent:none ";
00353     } else {
00354       out << "parent:" << *get_parent_window() << " ";
00355     }
00356   }
00357 }
00358 
00359 ostream &
00360 operator << (ostream &out, WindowProperties::ZOrder z_order) {
00361   switch (z_order) {
00362   case WindowProperties::Z_bottom:
00363     return out << "bottom";
00364 
00365   case WindowProperties::Z_normal:
00366     return out << "normal";
00367 
00368   case WindowProperties::Z_top:
00369     return out << "top";
00370   }
00371 
00372   return out << "**invalid WindowProperties::ZOrder(" << (int)z_order << ")**";
00373 }
00374 
00375 istream &
00376 operator >> (istream &in, WindowProperties::ZOrder &z_order) {
00377   string word;
00378   in >> word;
00379 
00380   if (word == "bottom") {
00381     z_order = WindowProperties::Z_bottom;
00382 
00383   } else if (word == "top") {
00384     z_order = WindowProperties::Z_top;
00385 
00386   } else if (word == "normal") {
00387     z_order = WindowProperties::Z_normal;
00388 
00389   } else {
00390     display_cat.warning()
00391       << "Unknown z-order: " << word << "\n";
00392     z_order = WindowProperties::Z_normal;
00393   }
00394 
00395   return in;
00396 }
00397 
00398 //
00399 // MouseMode operators
00400 //
00401 
00402 ostream &
00403 operator << (ostream &out, WindowProperties::MouseMode mode) {
00404   switch (mode) {
00405   case WindowProperties::M_absolute:
00406     return out << "absolute";
00407   case WindowProperties::M_relative:
00408     return out << "relative";
00409   }
00410   return out << "**invalid WindowProperties::MouseMode(" << (int)mode << ")**";
00411 }
00412 
00413 istream &
00414 operator >> (istream &in, WindowProperties::MouseMode &mode) {
00415   string word;
00416   in >> word;
00417 
00418   if (word == "absolute") {
00419     mode = WindowProperties::M_absolute;
00420   } else if (word == "relative") {
00421     mode = WindowProperties::M_relative;
00422   } else {
00423     display_cat.warning()
00424       << "Unknown mouse mode: " << word << "\n";
00425     mode = WindowProperties::M_absolute;
00426   }
00427 
00428   return in;
00429 }
 All Classes Functions Variables Enumerations