fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

Fl_Window.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
3 //
4 // Window widget class for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
19 // The Fl_Window is a window in the fltk library.
20 // This is the system-independent portions. The huge amount of
21 // crap you need to do to communicate with X is in Fl_x.cxx, the
22 // equivalent (but totally different) crap for MSWindows is in Fl_win32.cxx
23 #include <config.h>
24 #include <FL/Fl.H>
25 #include <FL/x.H>
26 #include <FL/Fl_RGB_Image.H>
27 #include <FL/Fl_Window.H>
28 #include <stdlib.h>
29 #include "flstring.h"
30 
31 #ifdef __APPLE_QUARTZ__
32 #include <FL/fl_draw.H>
33 #endif
34 
36 
38  type(FL_WINDOW);
40  if (Fl::scheme_bg_) {
44  } else {
46  }
47  i = 0;
48  xclass_ = 0;
49  icon_ = new icon_data;
50  memset(icon_, 0, sizeof(*icon_));
51  iconlabel_ = 0;
52  resizable(0);
53  size_range_set = 0;
54  minw = maxw = minh = maxh = 0;
55  shape_data_ = NULL;
56 
57 #if FLTK_ABI_VERSION >= 10301
58  no_fullscreen_x = 0;
59  no_fullscreen_y = 0;
60  no_fullscreen_w = w();
61  no_fullscreen_h = h();
62 #endif
63 
64 #if FLTK_ABI_VERSION >= 10303
69 #endif
70 
72 }
73 
74 Fl_Window::Fl_Window(int X,int Y,int W, int H, const char *l)
75 : Fl_Group(X, Y, W, H, l) {
77 
78  _Fl_Window();
80 }
81 
82 Fl_Window::Fl_Window(int W, int H, const char *l)
83 // fix common user error of a missing end() with current(0):
84  : Fl_Group((Fl_Group::current(0),0), 0, W, H, l) {
86 
87  _Fl_Window();
88  clear_visible();
89 }
90 
92  hide();
93  if (xclass_) {
94  free(xclass_);
95  }
96  free_icons();
97  delete icon_;
98  if (shape_data_) {
100 #if defined(__APPLE__)
101  if (shape_data_->mask) {
102  CGImageRelease(shape_data_->mask);
103  }
104 #endif
105  delete shape_data_;
106  }
107 }
108 
109 
119  for (Fl_Widget *o = parent(); o; o = o->parent())
120  if (o->type() >= FL_WINDOW) return (Fl_Window*)o;
121  return 0;
122 }
123 
131  const Fl_Widget *w = this;
132  while (w->parent()) { w = w->parent(); } // walk up the widget hierarchy to top-level item
133  return const_cast<Fl_Widget*>(w)->as_window(); // return if window, or NULL if not
134 }
135 
141 Fl_Window* Fl_Widget::top_window_offset(int& xoff, int& yoff) const {
142  xoff = yoff = 0;
143  const Fl_Widget *w = this;
144  while (w && w->window()) {
145  xoff += w->x(); // accumulate offsets
146  yoff += w->y();
147  w = w->window(); // walk up window hierarchy
148  }
149  return const_cast<Fl_Widget*>(w)->as_window();
150 }
151 
153 int Fl_Window::x_root() const {
154  Fl_Window *p = window();
155  if (p) return p->x_root() + x();
156  return x();
157 }
159 int Fl_Window::y_root() const {
160  Fl_Window *p = window();
161  if (p) return p->y_root() + y();
162  return y();
163 }
164 
165 void Fl_Window::label(const char *name) {
166  label(name, iconlabel()); // platform dependent
167 }
168 
170 void Fl_Window::copy_label(const char *a) {
172  label(label(), iconlabel()); // platform dependent
173 }
174 
175 void Fl_Window::iconlabel(const char *iname) {
176  label(label(), iname); // platform dependent
177 }
178 
179 // the Fl::atclose pointer is provided for back compatibility. You
180 // can now just change the callback for the window instead.
181 
184  window->hide();
185  Fl_Widget::default_callback(window, v); // put on Fl::read_queue()
186 }
188 void (*Fl::atclose)(Fl_Window*, void*) = default_atclose;
191  Fl::atclose(win, v);
192 }
193 
196  return current_;
197 }
198 
205 {
206  if (default_xclass_) {
207  return default_xclass_;
208  } else {
209  return "FLTK";
210  }
211 }
212 
233 void Fl_Window::default_xclass(const char *xc)
234 {
235  if (default_xclass_) {
237  default_xclass_ = 0L;
238  }
239  if (xc) {
240  default_xclass_ = strdup(xc);
241  }
242 }
243 
268 void Fl_Window::xclass(const char *xc)
269 {
270  if (xclass_) {
271  free(xclass_);
272  xclass_ = 0L;
273  }
274  if (xc) {
275  xclass_ = strdup(xc);
276  if (!default_xclass_) {
277  default_xclass(xc);
278  }
279  }
280 }
281 
287 const char *Fl_Window::xclass() const
288 {
289  if (xclass_) {
290  return xclass_;
291  } else {
292  return default_xclass();
293  }
294 }
295 
307  if (icon)
308  default_icons(&icon, 1);
309  else
310  default_icons(&icon, 0);
311 }
312 
331 void Fl_Window::default_icons(const Fl_RGB_Image *icons[], int count) {
332  Fl_X::set_default_icons(icons, count);
333 }
334 
353  if (icon)
354  icons(&icon, 1);
355  else
356  icons(&icon, 0);
357 }
358 
380 void Fl_Window::icons(const Fl_RGB_Image *icons[], int count) {
381  free_icons();
382 
383  if (count > 0) {
384  icon_->icons = new Fl_RGB_Image*[count];
385  icon_->count = count;
386  // FIXME: Fl_RGB_Image lacks const modifiers on methods
387  for (int i = 0;i < count;i++)
389  }
390 
391  if (i)
392  i->set_icons();
393 }
394 
398 const void *Fl_Window::icon() const {
399  return icon_->legacy_icon;
400 }
401 
405 void Fl_Window::icon(const void * ic) {
406  free_icons();
407  icon_->legacy_icon = ic;
408 }
409 
414  int i;
415 
416  icon_->legacy_icon = 0L;
417 
418  if (icon_->icons) {
419  for (i = 0;i < icon_->count;i++)
420  delete icon_->icons[i];
421  delete [] icon_->icons;
422  icon_->icons = 0L;
423  }
424 
425  icon_->count = 0;
426 
427 #ifdef WIN32
428  if (icon_->big_icon)
429  DestroyIcon(icon_->big_icon);
430  if (icon_->small_icon)
431  DestroyIcon(icon_->small_icon);
432 
433  icon_->big_icon = NULL;
434  icon_->small_icon = NULL;
435 #endif
436 }
437 
438 
439 #ifndef __APPLE__
440 
502  if (!shown()) return;
503  while (!i || i->wait_for_expose) {
504  Fl::wait();
505  }
506 }
507 #endif // ! __APPLE__
508 
509 //
510 // End of "$Id$".
511 //
Fl_Window::minw
int minw
Definition: Fl_Window.H:113
Fl_Widget::FORCE_POSITION
don't let the window manager position the window (Fl_Window)
Definition: Fl_Widget.H:160
Fl_Widget::y
int y() const
Definition: Fl_Widget.H:289
Fl_Group::resizable
Fl_Widget * resizable() const
Definition: Fl_Group.H:152
Fl_Window::y_root
int y_root() const
Definition: Fl_Window.cxx:159
Fl.H
Fl_Window::icon_data::icons
Fl_RGB_Image ** icons
Definition: Fl_Window.H:101
Fl_Widget::align
Fl_Align align() const
Definition: Fl_Widget.H:348
FL_NO_LABEL
does nothing
Definition: Enumerations.H:765
Fl_Widget::top_window_offset
Fl_Window * top_window_offset(int &xoff, int &yoff) const
Definition: Fl_Window.cxx:141
Fl::default_atclose
static void default_atclose(Fl_Window *, void *)
Definition: Fl_Window.cxx:183
Fl_Window::icon_data::count
int count
Definition: Fl_Window.H:102
FL_CURSOR_DEFAULT
Definition: Enumerations.H:1049
Fl_Menu_Window::hide
void hide()
Definition: Fl_Menu_Window.cxx:90
Fl_Window::current
static Fl_Window * current()
Definition: Fl_Window.cxx:195
Fl_Window::cursor_default
Fl_Cursor cursor_default
Definition: Fl_Window.H:117
Fl_RGB_Image.H
Fl_Widget::window
Fl_Window * window() const
Definition: Fl_Window.cxx:118
x.H
Fl::atclose
static void(* atclose)(Fl_Window *, void *)
Definition: Fl.H:1128
free
void free()
H
static int H
Definition: Fl_Tooltip.cxx:76
Fl_Window::minh
int minh
Definition: Fl_Window.H:113
Fl_Widget::set_flag
void set_flag(unsigned int c)
Definition: Fl_Widget.H:149
Fl_Widget::x
int x() const
Definition: Fl_Widget.H:284
NULL
#define NULL
Definition: forms.H:34
Fl_Window::no_fullscreen_y
static int no_fullscreen_y
Definition: Fl_Window.H:70
window
static Fl_TooltipBox * window
Definition: Fl_Tooltip.cxx:75
Fl_Window::_Fl_Window
void _Fl_Window()
Definition: Fl_Window.cxx:37
Fl_Window::Fl_Window
Fl_Window(const Fl_Window &)
Fl_Window::icon_data::legacy_icon
const void * legacy_icon
Definition: Fl_Window.H:100
FL_WINDOW
#define FL_WINDOW
window type id all subclasses have type() >= this
Definition: Fl_Window.H:33
Fl_Widget::labeltype
Fl_Labeltype labeltype() const
Definition: Fl_Widget.H:456
Fl_Callback
void() Fl_Callback(Fl_Widget *, void *)
Definition: Fl_Widget.H:49
Fl_Window::icon_
struct icon_data * icon_
Definition: Fl_Window.H:111
Fl_Window::size_range_set
uchar size_range_set
Definition: Fl_Window.H:115
icon
static Fl_Box * icon
Definition: fl_ask.cxx:48
Fl_Window::default_icon
static void default_icon(const Fl_RGB_Image *)
Definition: Fl_Window.cxx:306
Fl_Widget::w
int w() const
Definition: Fl_Widget.H:294
FL_ALIGN_INSIDE
const Fl_Align FL_ALIGN_INSIDE
Definition: Enumerations.H:843
Fl_Window.H
Fl_Widget::clear_visible
void clear_visible()
Definition: Fl_Widget.H:702
Fl_Window::~Fl_Window
virtual ~Fl_Window()
Definition: Fl_Window.cxx:91
Fl_Window::xclass
const char * xclass() const
Definition: Fl_Window.cxx:287
Fl_Widget::copy_label
void copy_label(const char *new_label)
Definition: Fl_Widget.cxx:324
p
static menustate * p
Definition: Fl_Menu.cxx:606
FL_FLAT_BOX
a flat box
Definition: Enumerations.H:606
fl_draw.H
utility header to pull drawing functions together
Fl_Window::copy_label
void copy_label(const char *a)
Definition: Fl_Window.cxx:170
Fl_Window
Definition: Fl_Window.H:57
Fl_RGB_Image::copy
virtual Fl_Image * copy(int W, int H)
Definition: Fl_Image.cxx:346
Fl_Window::fullscreen_screen_bottom
static int fullscreen_screen_bottom
Definition: Fl_Window.H:86
Fl_Window::wait_for_expose
void wait_for_expose()
Definition: Fl_Window.cxx:501
Fl_Window::icons
void icons(const Fl_RGB_Image *[], int)
Definition: Fl_win32.cxx:2441
Fl_Widget
Definition: Fl_Widget.H:101
Fl_Group
Definition: Fl_Group.H:41
Fl_Widget::box
Fl_Boxtype box() const
Definition: Fl_Widget.H:363
Fl_Widget::h
int h() const
Definition: Fl_Widget.H:299
Fl_Window::xclass_
char * xclass_
Definition: Fl_Window.H:110
Fl_Window::shown
int shown()
Definition: Fl_Window.H:485
Fl_Window::hide
virtual void hide()
Definition: Fl.cxx:1546
Fl_Window::iconlabel_
const char * iconlabel_
Definition: Fl_Window.H:109
Fl_Window::label
const char * label() const
Definition: Fl_Window.H:450
Fl_Window::iconlabel
const char * iconlabel() const
Definition: Fl_Window.H:452
Fl_Widget::default_callback
static void default_callback(Fl_Widget *cb, void *d)
Definition: Fl_Widget.cxx:39
Fl_Widget::callback
Fl_Callback_p callback() const
Definition: Fl_Widget.H:561
Fl_Window::shape_data_type::todelete_
Fl_Bitmap * todelete_
auxiliary bitmap image
Definition: Fl_Window.H:133
Fl::wait
static int wait()
Definition: Fl.cxx:666
Fl_Window::icon_data
Definition: Fl_Window.H:99
FL_ALIGN_CENTER
const Fl_Align FL_ALIGN_CENTER
Definition: Enumerations.H:830
Fl_Window::shape_data_
static shape_data_type * shape_data_
non-null means the window has a non-rectangular shape
Definition: Fl_Window.H:139
Fl_Window::default_xclass_
static char * default_xclass_
Definition: Fl_Window.H:59
Fl_Window::fullscreen_screen_right
static int fullscreen_screen_right
Definition: Fl_Window.H:94
FL_NORMAL_LABEL
draws the text (0)
Definition: Enumerations.H:764
Fl_Window::maxh
int maxh
Definition: Fl_Window.H:113
Fl_Widget::type
uchar type() const
Definition: Fl_Widget.H:274
Fl_Widget::parent
Fl_Group * parent() const
Definition: Fl_Widget.H:254
Fl::scheme_bg_
static Fl_Image * scheme_bg_
Definition: Fl.H:262
Fl_Window::default_xclass
static const char * default_xclass()
Definition: Fl_Window.cxx:204
Fl_Window::free_icons
void free_icons()
Definition: Fl_Window.cxx:413
Y
static int Y
Definition: Fl_Tooltip.cxx:76
flstring.h
Fl_Window::i
Fl_X * i
Definition: Fl_Window.H:97
Fl_Window::default_icons
static void default_icons(const Fl_RGB_Image *[], int)
Definition: Fl_win32.cxx:2420
Fl_Window::maxw
int maxw
Definition: Fl_Window.H:113
Fl_Window::default_callback
static void default_callback(Fl_Window *, void *v)
Definition: Fl_Window.cxx:190
Fl_Window::no_fullscreen_w
static int no_fullscreen_w
Definition: Fl_Window.H:74
Fl_Window::fullscreen_screen_left
static int fullscreen_screen_left
Definition: Fl_Window.H:90
Fl_Window::icon
const void * icon() const
Definition: Fl_Window.cxx:398
Fl_Window::x_root
int x_root() const
Definition: Fl_Window.cxx:153
Fl_Window::current_
static Fl_Window * current_
Definition: Fl_Window.H:168
Fl_Widget::top_window
Fl_Window * top_window() const
Definition: Fl_Window.cxx:130
name
static const char * name
Definition: Fl_arg.cxx:53
Fl_RGB_Image
Definition: Fl_Image.H:202
Fl_Window::no_fullscreen_x
static int no_fullscreen_x
Definition: Fl_Window.H:66
Fl_Window::no_fullscreen_h
static int no_fullscreen_h
Definition: Fl_Window.H:78
Fl_Widget::image
Fl_Image * image()
Definition: Fl_Widget.H:514
Fl_Window::fullscreen_screen_top
static int fullscreen_screen_top
Definition: Fl_Window.H:82
FL_ALIGN_CLIP
const Fl_Align FL_ALIGN_CLIP
Definition: Enumerations.H:849