worker.cpp

Go to the documentation of this file.
00001 #ifndef WORKER_IMPLEMENTATION_FILE
00002 #define WORKER_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : worker                                                            *
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 //hmmm: move to header.
00019 
00020 //   attach()
00021 //
00022 //     Registers this worker with its manager (by adding the worker to a list
00023 //     that is maintained by the manager).  This is a windowing system
00024 //     independent call.  Until this is done, the manager will not know that
00025 //     it should redraw the worker when it needs to redraw itself.
00026 //
00027 //   detach()
00028 //
00029 //     Disconnects this worker from the manager.
00030 //
00031 //   ask_for_dimensions()
00032 //
00033 //     Retrieves the size of the worker as the underlying windowing system
00034 //     currently reports that size.  The size is returned in universal
00035 //     coordinates.  This does not work until the object has been realized
00036 //     on the screen.
00037 
00038 #include "argument_list.h"
00039 #include "worker.h"
00040 #include "wp_implementation.h"
00041 
00042 #include <basis/function.h>
00043 #include <basis/guards.h>
00044 
00045 worker::worker(manager &root, const c_rectangle &dim, window_handle a_self,
00046    const color &f, const color &b)
00047 : nub(root.self(), a_self),
00048   drawable(dim.vertex_1(), f),
00049   _root(root),
00050   _background(b),
00051   _dimensions(dim)
00052 {
00053   background(_background);
00054   foreground(f);
00055     // called because drawable does not add colors to the palette.
00056 }
00057 
00058 worker::worker(const worker &to_copy)
00059 : nub(to_copy.parent(), to_copy.self()),
00060   drawable(to_copy),
00061   _root(to_copy._root),
00062   _background(to_copy._background),
00063   _dimensions(to_copy._dimensions)
00064 {}
00065 
00066 worker::~worker() { erase(); detach(); }
00067 
00068 manager &worker::root() const { return _root; }
00069 
00070 palette &worker::colormap() const { return _root; }
00071 
00072 color worker::background() const { return _background; }
00073 
00074 color worker::foreground() const { return drawable::foreground(); }
00075 
00076 void worker::attach()
00077 {
00078   FUNCDEF("attach");
00079   for (int i = 0; i < _root.contents.elements(); i++)
00080     if (_root.contents.get(i) == this) {
00081 LOG("worker::attach: adding worker again!");
00082       return;
00083     }
00084   _root.contents.add(this);
00085 }
00086 
00087 void worker::detach()
00088 {
00089   FUNCDEF("detach");
00090   if (!_root.contents.remove(this))
00091     LOG("worker::detach: not found in contents");
00092 }
00093 
00094 c_rectangle worker::dimensions() const { return _dimensions; }
00095 
00096 void worker::draw()
00097 {
00098   if (!visible()) {
00099     if (!realized()) {
00100       realize();
00101       foreground(_foreground);
00102       background(_background);
00103         // fg & bg called again in case no self() existed at construction time.
00104       if (self() && (_dimensions.vertex_1() == _dimensions.vertex_2()) )
00105         dimensions(ask_for_dimensions());
00106       else if (self()) dimensions(_dimensions);
00107       else non_continuable_error(class_name(), "draw", "worker's self is NIL");
00108       attach();
00109     } else map();
00110     engage();
00111     set_visible();
00112   }
00113 }
00114 
00115 void worker::erase()
00116 {
00117   if (visible()) {
00118     disengage();
00119     unmap();
00120     set_invisible();
00121   }
00122 }
00123 
00124 void worker::foreground(const color &new_foreground)
00125 {
00126   color fg(new_foreground);
00127   _root.add(fg);
00128   drawable::foreground(fg);
00129   if (self()) {
00130 #ifdef __XWINDOWS__
00131     disengage();
00132     set_foreground(fg);
00133     engage();
00134 #elif defined(MS_WINDOWS)
00135 #elif defined(OS_2)
00136 #endif
00137   }
00138 }
00139 
00140 void worker::background(const color &new_background)
00141 {
00142   color bg(new_background);
00143   _root.add(bg);
00144   _background = bg;
00145 #ifdef __XWINDOWS__
00146   if (self()) {
00147     disengage();
00148     set_background(bg);
00149     engage();
00150   }
00151 #elif defined(MS_WINDOWS)
00152 #elif defined(OS_2)
00153 #endif
00154 }
00155 
00156 void worker::dimensions(const c_rectangle &new_size)
00157 {
00158   _dimensions = new_size;
00159   disengage();
00160   device_dimensions(_root.universe_to_device(new_size));
00161   engage();
00162 }
00163 
00164 c_rectangle worker::ask_for_dimensions()
00165 {
00166   c_rectangle dev_size(device_dimensions());
00167   c_rectangle fake_univ_dim(_root.device_to_universe(dev_size));
00168   fake_univ_dim -= fake_univ_dim.vertex_1();
00169   c_rectangle univ_dim(fake_univ_dim + drawable::origin());
00170   return univ_dim;
00171 }
00172 
00173 void worker::set_origin(const c_point &new_origin)
00174 {
00175   c_rectangle new_dim(dimensions());
00176   new_dim -= drawable::origin();
00177   new_dim += new_origin;
00178   drawable::set_origin(new_origin);
00179   dimensions(new_dim);
00180 }
00181 
00182 #endif //WORKER_IMPLEMENTATION_FILE
00183 

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