nub.cpp

Go to the documentation of this file.
00001 #ifndef NUB_IMPLEMENTATION_FILE
00002 #define NUB_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : nub                                                               *
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 "color.h"
00020 #include "nub.h"
00021 #include "wp_implementation.h"
00022 
00023 #include <basis/guards.h>
00024 
00025 #include <X11/IntrinsicP.h>
00026 
00027 nub::nub(window_handle parent, window_handle w)
00028 #ifdef __XWINDOWS__
00029 : i_am_realized(false), _parent(parent), _self(w)
00030 #elif defined(MS_WINDOWS)
00031 #elif defined(OS_2)
00032 #endif
00033 { if (!parent) non_continuable_error("nub", "nub", "my parent cannot be NIL"); }
00034 
00035 nub::~nub()
00036 { if ( (_parent != _self) && _self) XtDestroyWidget(_self); }
00037 
00038 window_handle nub::parent() const { return _parent; }
00039 
00040 window_handle nub::self() const { return _self; }
00041 
00042 void nub::parent(window_handle w)
00043 {
00044   if (!w) non_continuable_error("nub", "parent set", "my parent cannot be NIL");
00045   _parent = w;
00046 }
00047 
00048 void nub::self(window_handle w) { _self = w; }
00049 
00050 #ifdef __XWINDOWS__
00051 
00052 bool nub::realized() const { return i_am_realized; }
00053 
00054 void nub::map() { XMapWindow(display(), window()); }
00055 
00056 void nub::unmap() { XUnmapWindow(display(), window()); }
00057 
00058 c_rectangle nub::device_dimensions() const
00059 {
00060   if (!_self) non_continuable_error("nub", "device_dimensions", "NIL self");
00061   argument_list wargs;
00062   int x, y, width, height;
00063   wargs.add(XtNx, XtArgVal(&x));
00064   wargs.add(XtNy, XtArgVal(&y));
00065   wargs.add(XtNwidth, XtArgVal(&width));
00066   wargs.add(XtNheight, XtArgVal(&height));
00067   XtGetValues(_self, wargs.generate(), wargs.number());
00068   return c_rectangle(c_point(x, y), c_point(x, y) + c_point(width, height));
00069 }
00070 
00071 Display *nub::display()
00072 {
00073   if (!_self) non_continuable_error("nub", "display", "NIL self");
00074   return XtDisplay(_self);
00075 }
00076 
00077 Window nub::window()
00078 {
00079   if (!_self) non_continuable_error("nub", "window", "NIL self");
00080   return XtWindow(_self);
00081 }
00082 
00083 Visual *nub::visual()
00084 {
00085   if (!_self) non_continuable_error("nub", "visual", "NIL self");
00086   return DefaultVisual(display(), screen());
00087 }
00088 
00089 int nub::screen()
00090 {
00091   if (!_self) non_continuable_error("nub", "visual", "NIL self");
00092   return DefaultScreen(display());
00093 }
00094 
00095 void nub::disengage()
00096 {
00097   if (!_self) non_continuable_error("nub", "disengage", "NIL self");
00098   XtUnmanageChild(_self);
00099 }
00100 
00101 void nub::engage()
00102 {
00103   if (!_self) non_continuable_error("nub", "engage", "NIL self");
00104   XtManageChild(_self);
00105 }
00106 
00107 void nub::device_dimensions(const c_rectangle &initial_size)
00108 {
00109   c_rectangle init_size(initial_size.order());
00110     // order in case someone is confused about vertices and origin.
00111   if (!_self) non_continuable_error("nub", "device_dimensions set", "NIL self");
00112   XtMoveWidget(_self, short(init_size.vertex_1().x()),
00113       short(init_size.vertex_1().y()));
00114   if (init_size.vertex_1() != init_size.vertex_2())
00115     XtResizeWidget(_self, (unsigned short)init_size.width(), 
00116        (unsigned short)init_size.height(), 1);
00117 }
00118 
00119 void nub::add_origin(argument_list &wargs, const c_point &origin)
00120 { wargs.add(XmNx, int(origin.x())); wargs.add(XmNy, int(origin.y())); }
00121 
00122 void nub::add_dimensions(argument_list &wargs, const c_rectangle &initial_size)
00123 {
00124   c_rectangle init_size(initial_size.order());
00125   c_point origin(init_size.vertex_1());
00126   add_origin(wargs, origin);
00127   int width = int(init_size.width());
00128   int height = int(init_size.height());
00129   if (width < 1) width = 1;
00130   if (height < 1) height = 1;
00131   wargs.add(XmNwidth, width);
00132   wargs.add(XmNheight, height);
00133 }
00134 
00135 void nub::realize()
00136 {
00137   if (!_self) non_continuable_error("nub", "realize", "NIL self");
00138   if (!i_am_realized) {
00139 // XtMoveWidget(_self, 9999, 9999);
00140 // needs to be done from perspective of more reasonable construction.
00141     XtRealizeWidget(_self);
00142     i_am_realized = true;
00143   }
00144 }
00145 
00146 void nub::set_foreground(const color &new_foreground)
00147 {
00148   argument_list wargs;
00149   wargs.add(XmNforeground, new_foreground.index());
00150   wargs.apply(self());
00151 }
00152 
00153 void nub::set_background(const color &new_background)
00154 {
00155   argument_list wargs;
00156   wargs.add(XmNbackground, new_background.index());
00157   wargs.apply(self());
00158 }
00159 
00160 #elif defined(MS_WINDOWS)
00161 #elif defined(OS_2)
00162 #endif
00163 
00164 
00165 #endif //NUB_IMPLEMENTATION_FILE
00166 

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