manager.h

Go to the documentation of this file.
00001 #ifndef MANAGER_CLASS
00002 #define MANAGER_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : manager                                                           *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *  Purpose:                                                                   *
00010 *                                                                             *
00011 *    Manages the details involved in starting up the window manager that      *
00012 *  supports the windows parts library.                                        *
00013 *                                                                             *
00014 *******************************************************************************
00015 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
00016 * redistribute it and/or modify it under the terms of the GNU General Public  *
00017 * License as published by the Free Software Foundation; either version 2 of   *
00018 * the License or (at your option) any later version.  This is online at:      *
00019 *     http://www.fsf.org/copyleft/gpl.html                                    *
00020 * Please send any updates to: fred@gruntose.com                               *
00021 \*****************************************************************************/
00022 
00023 #include "desktop.h"
00024 #include "nub.h"
00025 #include "palette.h"
00026 #include "picture.h"
00027 
00028 #include <geometric/cartesian_objects.h>
00029 
00030 const c_rectangle default_universe = c_rectangle(0, 0, 1000, 1000);
00031   // The default universe coordinate system has an origin at (0,0) and the
00032   // opposite corner is 1000 units to the right and 1000 units upward from it.
00033 
00034 const c_rectangle default_desktop_view = c_rectangle(0, 0, 100, 100);
00035   // The initial view of the desktop as seen by the manager.
00036 
00037 const c_rectangle default_manager_size = c_rectangle(10, 10, 90, 90);
00038   // The default_size for the manager in desktop_view coordinates.
00039 
00040 class WP_PASSIVE_CLASS_STYLE manager
00041 : public drawable, public c_rectangle_warper, public nub,
00042   public desktop, public palette
00043 {
00044 public:
00045   manager(const istring &name,
00046           const c_rectangle &initial_universe = default_universe,
00047           const c_rectangle &initial_view = default_desktop_view,
00048           const c_rectangle &initial_size = default_manager_size,
00049           const color &foreground = colors::WHITE,
00050           const color &background = colors::BLACK,
00051           origin_vertex view_corner = BOTTOM_LEFT,
00052           origin_vertex universe_corner = BOTTOM_LEFT);
00053     // Once a manager is constructed, windowing objects can be created and
00054     // attached to it.  Multiple managers may be used within one program.
00055     // The "name" is the application name.  The argument array "argv" will be
00056     // destructively manipulated by the initialization function.  The initial
00057     // universal coordinates are represented by "initial_universe", where an
00058     // implicit ordering is used to define the coordinate system: the first
00059     // vertex of the rectangle is the origin, while the second is the extent
00060     // of the universal coordinates away from that origin. All objects
00061     // connected to this manager are described in the universal coordinates.
00062     // The "initial_size" is how large the root window will be initially
00063     // (measured in the desktop view coordinates).
00064 
00065   ~manager();
00066     // Shuts down the window manager.
00067 
00068   IMPLEMENT_CLASS_NAME("manager");
00069 
00070   void poll();
00071     // Causes the window system to go into interactive mode where only user
00072     // requests are processed.  When the system is in this mode, event
00073     // functions and callbacks are the only active functions.  The system will
00074     // not return control to the invoker of poll until the user asks for a
00075     // system shutdown (which causes some function to invoke the shut_down
00076     // method on this class) or until the system shuts down due to a fatal
00077     // error.
00078 
00079   bool poll_and_return(int maximum_events);
00080     // Causes the window system to process as many underlying windowing system
00081     // events as are available (to the maximum of "maximum_events"), but does
00082     // not wait if no events are ready.  If the windowing system is still
00083     // alive, then true is returned.
00084 
00085   void shut_down();
00086     // Causes the manager to stop polling and close down the program.
00087 
00088   c_rectangle universe() const;
00089   origin_vertex universe_corner() const;
00090     // The universe is how the internal span of pixels contained in the manager
00091     // is represented to objects that are placed on the manager.
00092 
00093   virtual void draw();
00094   virtual void erase();
00095 
00096   istring name() const;
00097   void name(const istring &new_name);
00098     // Observes or modifies the title of the canvas.
00099 
00100   c_rectangle dimensions() const;
00101   void dimensions(const c_rectangle &new_location);
00102     // Observes or modifies the manager's size (in desktop view coordinates).
00103 
00104   // The "device" coordinates below are relative to the origin of the manager.
00105   // If one has been passed a point in absolute device coordinates, then
00106   // these functions can be used if the origin for this manager (in device
00107   // coordinates) is subtracted from it.  (the safe way to do this is:
00108   //   devcoord - mang.view_to_device(mang.dimensions()).vertex_1();
00109   // because the origin may be interpreted differently by the device.)
00110   c_point universe_to_device(const c_point &in_universe) const;
00111   c_point device_to_universe(const c_point &in_device) const;
00112 
00113   c_rectangle universe_to_device(const c_rectangle &in_universe) const;
00114   c_rectangle device_to_universe(const c_rectangle &in_device) const;
00115 
00116   virtual void redraw_part(const c_rectangle &to_redraw);
00117     // Causes the portion of the manager that intersects with the rectangle
00118     // (in universal coordinates) to be redrawn.
00119 
00120   color foreground() const;
00121   virtual void foreground(const color &new_foreground);
00122     // observes or modifies the foreground color of the manager.  the color
00123     // is returned by the modifier after being added to the colormap.
00124 
00125   color background() const;
00126   virtual void background(const color &new_background);
00127 
00128   c_point text_size(const istring &to_measure);
00129     // Returns the size of a character string in universal coordinates.
00130 
00131 private:
00132   c_point _origin;
00133   picture contents;
00134   bool die;
00135   color _background;
00136   friend class worker;
00137   istring _name;
00138  
00139   window_handle nub_init(const istring &name);
00140   bool realize(bool to_flow, const c_rectangle &initial_size);
00141 };
00142 
00143 #endif

Generated on Fri Nov 28 04:29:05 2008 for HOOPLE Libraries by  doxygen 1.5.1