manager.cpp

Go to the documentation of this file.
00001 #ifndef MANAGER_IMPLEMENTATION_FILE
00002 #define MANAGER_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : manager                                                           *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "argument_list.h"
00019 #include "manager.h"
00020 #include "system_string.h"
00021 #include "worker.h"
00022 #include "wp_implementation.h"
00023 
00024 #include <basis/function.h>
00025 #include <basis/guards.h>
00026 #include <geometric/warper.cpp>
00027 
00028 #include <stdlib.h>
00029 
00030 #ifdef __XWINDOWS__
00031   #include <Xm/DrawingA.h>
00032   #include <Xm/BulletinB.h>
00033 #elif defined(MS_WINDOWS)
00034 #elif defined(OS_2)
00035 #endif
00036 
00037 manager::manager(const istring &named, const c_rectangle &universe,
00038    const c_rectangle &deskview, const c_rectangle &initial_size,
00039    const color &f, const color &b, origin_vertex desktop_corner,
00040    origin_vertex univ_corner)
00041 : drawable(initial_size.vertex_1(), f),
00042   c_rectangle_warper(universe, initial_size, univ_corner, desktop_corner),
00043   nub(nub_init(named), NIL),
00044   desktop(parent(), deskview, desktop_corner),
00045   palette(realize(true, initial_size)? parent() : parent()),
00046   _origin(initial_size.vertex_1()),
00047   contents(c_point(0, 0)),
00048   die(false),
00049   _background(b)
00050 {
00051   // adjust the background color to the available color set.
00052   add(_background);
00053   // adjust the foreground color also.
00054   color fore = foreground(); add(fore); foreground(fore);
00055   draw();
00056   dimensions(initial_size);
00057   name(named);
00058 }
00059 
00060 manager::~manager()
00061 {
00062 //  contents.erase();
00063   erase();
00064 
00065 #ifdef __XWINDOWS__
00066   Display *display_to_shut_down(display());
00067   XtDestroyWidget(parent());
00068   XtCloseDisplay(display_to_shut_down);
00069 #elif defined(MS_WINDOWS)
00070 #elif defined(OS_2)
00071 #endif
00072 }
00073 
00074 void manager::shut_down() { die = true; }
00075 
00076 c_rectangle manager::dimensions() const { return system_2(); }
00077 
00078 c_rectangle manager::universe() const { return system_1(); }
00079 
00080 c_rectangle_warper::origin_vertex manager::universe_corner() const { return origin_1(); }
00081 
00082 color manager::background() const { return _background; }
00083 
00084 color manager::foreground() const { return drawable::foreground(); }
00085 
00086 istring manager::name() const { return _name; }
00087 
00088 window_handle manager::nub_init(const istring &formal(name))
00089 {
00090 #ifdef __XWINDOWS__
00091   window_handle to_return = XtInitialize(__argv[0], "manager", NIL, 0,
00092       &__argc, __argv);
00093   return to_return;
00094 #elif defined(MS_WINDOWS)
00095 #elif defined(OS_2)
00096 #endif
00097 }
00098 
00099 void manager::name(const istring &new_name)
00100 {
00101   _name = new_name;
00102 /*
00103   XTextProperty to_send;
00104   to_send.value = (unsigned char *)(char *)new_name;
00105   to_send.encoding = STRING;
00106   to_send.nitems = 1;
00107   XSetWMName(display(), window(), &to_send);
00108 */
00109   argument_list wargs;
00110   wargs.add((char *)"*title", new_name);
00111   wargs.apply(parent());
00112 }
00113 
00114 bool manager::realize(bool to_flow, const c_rectangle &size)
00115 {
00116 #ifdef __XWINDOWS__
00117   argument_list wargs;
00118   add_dimensions(wargs, view_to_device(size));
00119     // the dimensions are added here before calling dimensions in the
00120     // assignment section of the constructor to keep the window showing
00121     // up with a different size than intended initially.  the manager's
00122     // dimensions call cannot be used in centerline since it's virtual.
00123   self(XtCreateManagedWidget
00124        ("layout_holder", xmBulletinBoardWidgetClass, parent(),
00125        wargs.generate(), wargs.number()));
00126   XtRealizeWidget(parent());
00127   wargs.apply(parent());
00128     // X seems to like getting them again.  probably some option like don't
00129     // autoplace the window needs to be set in wargs, because the origin
00130     // is being ignored otherwise.
00131   nub::realize();
00132 #elif defined(MS_WINDOWS)
00133 #elif defined(OS_2)
00134 #endif
00135   return to_flow;
00136 }
00137 
00138 void manager::poll()
00139 {
00140   while (!die) {
00141 #ifdef __XWINDOWS__
00142     XEvent event; XtNextEvent(&event); XtDispatchEvent(&event);
00143 #elif defined(MS_WINDOWS)
00144 #elif defined(OS_2)
00145 #endif
00146   }
00147 }
00148 
00149 bool manager::poll_and_return(int maximum_events)
00150 {
00151   if (die) return false;
00152 #ifdef __XWINDOWS__
00153   XEvent event;
00154   while (maximum_events-- >= 0) {
00155     if (!XtPending()) break;
00156 //LOG("x event supposedly pending");
00157     XtNextEvent(&event);
00158     XtDispatchEvent(&event);
00159     if (die) break;
00160 //LOG("after x event dispatched");
00161   }
00162   return die? false : true;
00163 #elif defined(MS_WINDOWS)
00164 #elif defined(OS_2)
00165 #endif
00166 }
00167 
00168 void manager::dimensions(const c_rectangle &new_size)
00169 {
00170   _origin = new_size.vertex_1();
00171   system_2(new_size, origin_2());
00172   { 
00173     c_rectangle in_dev(view_to_device(new_size));
00174     nub temp(parent(), parent());
00175       // safe due to UNSPOKEN policy in nub of not zapping widget for
00176       // parent and self equal.
00177     temp.device_dimensions(in_dev);
00178   }
00179   {
00180     argument_list wargs;
00181     c_rectangle bull_dim(universe());
00182     bull_dim = universe_to_device(bull_dim);
00183     add_dimensions(wargs, bull_dim);
00184     disengage();
00185     wargs.apply(self());
00186     engage();
00187   }
00188 }
00189 
00190 void manager::draw()
00191 {
00192   if (!visible()) {
00193 #ifdef __XWINDOWS__
00194     if (!realized()) nub::realize();
00195     else XMapWindow(display(), window());
00196 #elif defined(MS_WINDOWS)
00197 #elif defined(OS_2)
00198 #endif
00199     set_visible();
00200   }
00201   redraw_part(dimensions());
00202 }
00203 
00204 void manager::erase()
00205 {
00206   if (visible()) {
00207 #ifdef __XWINDOWS__
00208     XUnmapWindow(display(), window());
00209 #elif defined(MS_WINDOWS)
00210 #elif defined(OS_2)
00211 #endif
00212     set_invisible();
00213   }
00214 }
00215 
00216 void manager::redraw_part(const c_rectangle &to_redraw)
00217   { contents.draw_intersecting(to_redraw); }
00218 
00219 c_point manager::universe_to_device(const c_point &in_universe) const
00220 {
00221   return universe_to_device(c_rectangle(in_universe, in_universe)).vertex_1();
00222 }
00223 
00224 c_point manager::device_to_universe(const c_point &in_device) const
00225 {
00226   return device_to_universe(c_rectangle(in_device, in_device)).vertex_1();
00227 }
00228 
00229 c_rectangle manager::universe_to_device(const c_rectangle &in_universe) const
00230 {
00231   c_rectangle in_view(to_system_2(in_universe));
00232   c_rectangle in_dev(view_to_device(in_view));
00233   c_rectangle relative(in_dev - view_to_device(dimensions()).vertex_1());
00234     // the entire dimensions rectangle is converted to make sure we get
00235     // the right orientation of the origin's vertex.
00236   return relative;
00237 }
00238 
00239 c_rectangle manager::device_to_universe(const c_rectangle &in_device) const
00240 {
00241   c_rectangle in_view
00242     (device_to_view(in_device + view_to_device(dimensions()).vertex_1()));
00243   c_rectangle in_univ(to_system_1(in_view));
00244   return in_univ;
00245 }
00246 
00247 // ARGH!  fonts in x windows are a maze.
00248 
00249 #ifdef __XWINDOWS__
00250 c_point manager::text_size(const istring &to_measure)
00251 {
00252   FUNCDEF("text_size");
00253 LOG("in text size");
00254   XFontStruct *font = XLoadQueryFont(display(), "lucidasans-bold-10");
00255   if (!font) non_continuable_error(class_name(), "text_size", "font not loaded");
00256 LOG("textsize queried.");
00257   XmFontList fonts = XmFontListCreate(font, (char *)"manager_fonts");
00258   if (!fonts) non_continuable_error(class_name(), "text_size", "font list not created");
00259 LOG("textsize created.");
00260   Dimension width, height;
00261 LOG("textsize dimmed.");
00262   system_string to_meas(to_measure);
00263   XmStringExtent(fonts, to_meas, &width, &height);
00264 LOG("textsize string extented.");
00265   return c_point(width, height);
00266 }
00267 #endif
00268 
00269 void manager::foreground(const color &new_foreground)
00270 {
00271   color fg(new_foreground);
00272   add(fg);
00273   drawable::foreground(fg);
00274   set_foreground(fg);
00275 }
00276 
00277 void manager::background(const color &new_background)
00278 {
00279   color bg(new_background);
00280   add(bg);
00281   _background = bg;
00282   set_background(bg);
00283 }
00284 
00285 
00286 #endif //MANAGER_IMPLEMENTATION_FILE
00287 

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