src/widget.cpp

Go to the documentation of this file.
00001 // Copyright (c) 2003 - 2004 Anselm R. Garbe <anselmg at t-online.de>
00002 // See ../LICENSE.txt for license details.
00003 //
00004 // $Id: widget.cpp 2 2007-05-16 10:38:27Z eg $
00005 
00006 #include "widget.h"
00007 
00008 #include "cursors.h"
00009 #include "kernel.h"
00010 #include "monitor.h"
00011 #include "xcore.h"
00012 #include "xfont.h"
00013 
00014 Widget::Widget(Monitor *monitor, Rectangle *rect, bool initWindowAndGC)
00015     : Rectangle(*rect)
00016 {
00017     monitor_ = monitor;
00018     isVisible_ = false;
00019     if (initWindowAndGC) {
00020         initWindow();
00021         initGC();
00022     }
00023     else {
00024         window_ = 0;
00025         gc_ = 0;
00026     }
00027 }
00028 
00029 Widget::~Widget() {
00030     XCORE->free(gc_);
00031     XCORE->destroy(window_);
00032 }
00033 
00034 Monitor *Widget::monitor() const  {
00035     return monitor_;
00036 }
00037 
00038 Window Widget::window() const {
00039     return window_;
00040 }
00041 
00042 GC Widget::gc() const {
00043     return gc_;
00044 }
00045 
00046 void Widget::show() {
00047     isVisible_ = true;
00048     XCORE->showRaised(window_);
00049 }
00050 
00051 void Widget::hide() {
00052     isVisible_ = false;
00053     XCORE->hide(window_);
00054 }
00055 
00056 bool Widget::isVisible() const {
00057     return isVisible_;
00058 }
00059 
00060 void Widget::initWindow() {
00061     Kernel *kernel = KERNEL;
00062 
00063     XSetWindowAttributes attr;
00064     attr.override_redirect = 1;
00065     attr.background_pixmap = ParentRelative;
00066 
00067     window_ = XCORE->createWindow(monitor_->rootWindow(), &attr,
00068                                   x(), y(), width(), height(),
00069                                   CWOverrideRedirect | CWBackPixmap);
00070     XCORE->selectEvents(window_,
00071                  ExposureMask | ButtonPressMask | ButtonReleaseMask |
00072                  PointerMotionMask | SubstructureRedirectMask |
00073                  SubstructureNotifyMask);
00074 
00075     kernel->installCursor(Cursors::NORMAL_CURSOR, window_);
00076 }
00077 
00078 void Widget::initGC() {
00079     unsigned long mask = 0;
00080     XGCValues gcv;
00081 
00082     mask = GCForeground | GCBackground |
00083            GCFunction | GCLineWidth | GCLineStyle;
00084 
00085     gcv.function = GXcopy;
00086     gcv.line_width = 1;
00087     gcv.line_style = LineSolid;
00088     if (monitor_->font()->type() == WFont::NORMAL) {
00089         gcv.font = ((XFont *)monitor_->font())->font()->fid;
00090         mask |= GCFont;
00091     }
00092 
00093     gc_ = XCORE->createGC(window_, mask, &gcv);
00094 }
00095 
00096 void Widget::resize() {
00097     XCORE->moveResize(window_, this);
00098 }

Generated on Thu May 24 15:19:32 2007 for ncwm by  doxygen 1.5.1