|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 // 00002 // "$Id: Fl_Window.cxx 8198 2011-01-06 10:24:58Z manolo $" 00003 // 00004 // Window widget class for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 00028 // The Fl_Window is a window in the fltk library. 00029 // This is the system-independent portions. The huge amount of 00030 // crap you need to do to communicate with X is in Fl_x.cxx, the 00031 // equivalent (but totally different) crap for MSWindows is in Fl_win32.cxx 00032 #include <config.h> 00033 #include <FL/Fl.H> 00034 #include <FL/x.H> 00035 #include <FL/Fl_Window.H> 00036 #include <stdlib.h> 00037 #include "flstring.h" 00038 00039 #ifdef __APPLE_QUARTZ__ 00040 #include <FL/fl_draw.H> 00041 #endif 00042 00043 char *Fl_Window::default_xclass_ = 0L; 00044 00045 void Fl_Window::_Fl_Window() { 00046 type(FL_WINDOW); 00047 box(FL_FLAT_BOX); 00048 if (Fl::scheme_bg_) { 00049 labeltype(FL_NORMAL_LABEL); 00050 align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE | FL_ALIGN_CLIP); 00051 image(Fl::scheme_bg_); 00052 } else { 00053 labeltype(FL_NO_LABEL); 00054 } 00055 i = 0; 00056 xclass_ = 0; 00057 icon_ = 0; 00058 iconlabel_ = 0; 00059 resizable(0); 00060 size_range_set = 0; 00061 minw = maxw = minh = maxh = 0; 00062 callback((Fl_Callback*)default_callback); 00063 } 00064 00065 Fl_Window::Fl_Window(int X,int Y,int W, int H, const char *l) 00066 : Fl_Group(X, Y, W, H, l) { 00067 cursor_default = FL_CURSOR_DEFAULT; 00068 cursor_fg = FL_BLACK; 00069 cursor_bg = FL_WHITE; 00070 00071 _Fl_Window(); 00072 set_flag(FORCE_POSITION); 00073 } 00074 00075 Fl_Window::Fl_Window(int W, int H, const char *l) 00076 // fix common user error of a missing end() with current(0): 00077 : Fl_Group((Fl_Group::current(0),0), 0, W, H, l) { 00078 cursor_default = FL_CURSOR_DEFAULT; 00079 cursor_fg = FL_BLACK; 00080 cursor_bg = FL_WHITE; 00081 00082 _Fl_Window(); 00083 clear_visible(); 00084 } 00085 00086 Fl_Window *Fl_Widget::window() const { 00087 for (Fl_Widget *o = parent(); o; o = o->parent()) 00088 if (o->type() >= FL_WINDOW) return (Fl_Window*)o; 00089 return 0; 00090 } 00092 int Fl_Window::x_root() const { 00093 Fl_Window *p = window(); 00094 if (p) return p->x_root() + x(); 00095 return x(); 00096 } 00098 int Fl_Window::y_root() const { 00099 Fl_Window *p = window(); 00100 if (p) return p->y_root() + y(); 00101 return y(); 00102 } 00103 00104 void Fl_Window::draw() { 00105 00106 // The following is similar to Fl_Group::draw(), but ... 00107 // - we draw the box with x=0 and y=0 instead of x() and y() 00108 // - we don't draw a label 00109 00110 if (damage() & ~FL_DAMAGE_CHILD) { // draw the entire thing 00111 draw_box(box(),0,0,w(),h(),color()); // draw box with x/y = 0 00112 } 00113 draw_children(); 00114 00115 #ifdef __APPLE_QUARTZ__ 00116 // on OS X, windows have no frame. To resize a window, we drag the lower right 00117 // corner. This code draws a little ribbed triangle for dragging. 00118 extern CGContextRef fl_gc; 00119 if (fl_gc && !parent() && resizable() && (!size_range_set || minh!=maxh || minw!=maxw)) { 00120 int dx = Fl::box_dw(box())-Fl::box_dx(box()); 00121 int dy = Fl::box_dh(box())-Fl::box_dy(box()); 00122 if (dx<=0) dx = 1; 00123 if (dy<=0) dy = 1; 00124 int x1 = w()-dx-1, x2 = x1, y1 = h()-dx-1, y2 = y1; 00125 Fl_Color c[4] = { 00126 color(), 00127 fl_color_average(color(), FL_WHITE, 0.7f), 00128 fl_color_average(color(), FL_BLACK, 0.6f), 00129 fl_color_average(color(), FL_BLACK, 0.8f), 00130 }; 00131 int i; 00132 for (i=dx; i<12; i++) { 00133 fl_color(c[i&3]); 00134 fl_line(x1--, y1, x2, y2--); 00135 } 00136 } 00137 #endif 00138 00139 # if defined(FLTK_USE_CAIRO) 00140 Fl::cairo_make_current(this); // checkout if an update is necessary 00141 # endif 00142 } 00143 00144 void Fl_Window::label(const char *name) { 00145 label(name, iconlabel()); 00146 } 00147 00148 void Fl_Window::copy_label(const char *a) { 00149 if (flags() & COPIED_LABEL) { 00150 free((void *)label()); 00151 clear_flag(COPIED_LABEL); 00152 } 00153 if (a) a = strdup(a); 00154 label(a, iconlabel()); 00155 set_flag(COPIED_LABEL); 00156 } 00157 00158 00159 void Fl_Window::iconlabel(const char *iname) { 00160 label(label(), iname); 00161 } 00162 00163 // the Fl::atclose pointer is provided for back compatibility. You 00164 // can now just change the callback for the window instead. 00165 00167 void Fl::default_atclose(Fl_Window* window, void* v) { 00168 window->hide(); 00169 Fl_Widget::default_callback(window, v); // put on Fl::read_queue() 00170 } 00172 void (*Fl::atclose)(Fl_Window*, void*) = default_atclose; 00174 void Fl_Window::default_callback(Fl_Window* win, void* v) { 00175 Fl::atclose(win, v); 00176 } 00177 00179 Fl_Window *Fl_Window::current() { 00180 return current_; 00181 } 00182 00188 const char *Fl_Window::default_xclass() 00189 { 00190 if (default_xclass_) { 00191 return default_xclass_; 00192 } else { 00193 return "FLTK"; 00194 } 00195 } 00196 00217 void Fl_Window::default_xclass(const char *xc) 00218 { 00219 if (default_xclass_) { 00220 free(default_xclass_); 00221 default_xclass_ = 0L; 00222 } 00223 if (xc) { 00224 default_xclass_ = strdup(xc); 00225 } 00226 } 00227 00252 void Fl_Window::xclass(const char *xc) 00253 { 00254 if (xclass_) { 00255 free(xclass_); 00256 xclass_ = 0L; 00257 } 00258 if (xc) { 00259 xclass_ = strdup(xc); 00260 if (!default_xclass_) { 00261 default_xclass(xc); 00262 } 00263 } 00264 } 00265 00271 const char *Fl_Window::xclass() const 00272 { 00273 if (xclass_) { 00274 return xclass_; 00275 } else { 00276 return default_xclass(); 00277 } 00278 } 00279 00280 00281 // 00282 // End of "$Id: Fl_Window.cxx 8198 2011-01-06 10:24:58Z manolo $". 00283 //