2 // "$Id: Fl_Window.cxx 8472 2011-02-25 08:44:47Z AlbrechtS $"
4 // Window widget class for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // The Fl_Window is a window in the fltk library.
29 // This is the system-independent portions. The huge amount of
30 // crap you need to do to communicate with X is in Fl_x.cxx, the
31 // equivalent (but totally different) crap for MSWindows is in Fl_win32.cxx
35 #include <FL/Fl_Window.H>
39 #include <FL/Fl_Cairo.H>
41 #include <FL/fl_draw.H>
43 char *Fl_Window::default_xclass_
= 0L;
45 void Fl_Window::_Fl_Window() {
49 align(FL_ALIGN_IMAGE_BACKDROP
);
50 image(Fl::scheme_bg_
);
53 labeltype(FL_NO_LABEL
);
61 minw
= maxw
= minh
= maxh
= 0;
62 callback((Fl_Callback
*)default_callback
);
65 Fl_Window::Fl_Window(int X
,int Y
,int W
, int H
, const char *l
)
66 : Fl_Group(X
, Y
, W
, H
, l
) {
67 cursor_default
= FL_CURSOR_DEFAULT
;
72 set_flag(FORCE_POSITION
);
75 Fl_Window::Fl_Window(int W
, int H
, const char *l
)
76 // fix common user error of a missing end() with current(0):
77 : Fl_Group((Fl_Group::current(0),0), 0, W
, H
, l
) {
78 cursor_default
= FL_CURSOR_DEFAULT
;
86 Fl_Window
*Fl_Widget::window() const {
87 for (Fl_Widget
*o
= parent(); o
; o
= o
->parent())
88 if (o
->type() >= FL_WINDOW
) return (Fl_Window
*)o
;
91 /** Gets the x position of the window on the screen */
92 int Fl_Window::x_root() const {
93 Fl_Window
*p
= window();
94 if (p
) return p
->x_root() + x();
97 /** Gets the y position of the window on the screen */
98 int Fl_Window::y_root() const {
99 Fl_Window
*p
= window();
100 if (p
) return p
->y_root() + y();
104 void Fl_Window::draw() {
105 // The following is similar to Fl_Group::draw(), but ...
106 // - we draw the box with x=0 and y=0 instead of x() and y()
107 // - we don't draw a label
109 if ( damage() & ~FL_DAMAGE_CHILD
) { // draw the entire thing
110 // /* always draw the box because the children may be transparent */
112 /* workaround for ZynAddSubFX */
113 FL_NO_BOX
== box() && NULL
== Fl::scheme_bg_
116 0,0,w(),h(),color()); // draw box with x/y = 0
120 if (fl_gc
&& !parent() && resizable() && (!size_range_set
|| minh
!=maxh
|| minw
!=maxw
)) {
121 int dx
= Fl::box_dw(box())-Fl::box_dx(box());
122 int dy
= Fl::box_dh(box())-Fl::box_dy(box());
125 int x1
= w()-dx
-1, x2
= x1
, y1
= h()-dx
-1, y2
= y1
;
128 fl_color_average(color(), FL_WHITE
, 0.7f
),
129 fl_color_average(color(), FL_BLACK
, 0.6f
),
130 fl_color_average(color(), FL_BLACK
, 0.8f
),
133 for (i
=dx
; i
<12; i
++) {
135 fl_line(x1
--, y1
, x2
, y2
--);
140 void Fl_Window::label(const char *name
) {
141 label(name
, iconlabel());
144 void Fl_Window::copy_label(const char *a
) {
145 if (flags() & COPIED_LABEL
) {
146 free((void *)label());
147 clear_flag(COPIED_LABEL
);
149 if (a
) a
= strdup(a
);
150 label(a
, iconlabel());
151 set_flag(COPIED_LABEL
);
155 void Fl_Window::iconlabel(const char *iname
) {
156 label(label(), iname
);
159 // the Fl::atclose pointer is provided for back compatibility. You
160 // can now just change the callback for the window instead.
162 /** Default callback for window widgets. It hides the window and then calls the default widget callback. */
163 void Fl::default_atclose(Fl_Window
* window
, void* v
) {
165 Fl_Widget::default_callback(window
, v
); // put on Fl::read_queue()
167 /** Back compatibility: default window callback handler \see Fl::set_atclose() */
168 void (*Fl::atclose
)(Fl_Window
*, void*) = default_atclose
;
169 /** Back compatibility: Sets the default callback v for win to call on close event */
170 void Fl_Window::default_callback(Fl_Window
* win
, void* v
) {
174 /** Returns the last window that was made current. \see Fl_Window::make_current() */
175 Fl_Window
*Fl_Window::current() {
179 /** Returns the default xclass.
181 \see Fl_Window::default_xclass(const char *)
184 const char *Fl_Window::default_xclass()
186 if (default_xclass_
) {
187 return default_xclass_
;
193 /** Sets the default window xclass.
195 The default xclass is used for all windows that don't have their
196 own xclass set before show() is called. You can change the default
197 xclass whenever you want, but this only affects windows that are
198 created (and shown) after this call.
200 The given string \p xc is copied. You can use a local variable or
201 free the string immediately after this call.
203 If you don't call this, the default xclass for all windows will be "FLTK".
204 You can reset the default xclass by specifying NULL for \p xc.
206 If you call Fl_Window::xclass(const char *) for any window, then
207 this also sets the default xclass, unless it has been set before.
209 \param[in] xc default xclass for all windows subsequently created
211 \see Fl_Window::xclass(const char *)
213 void Fl_Window::default_xclass(const char *xc
)
215 if (default_xclass_
) {
216 free(default_xclass_
);
217 default_xclass_
= 0L;
220 default_xclass_
= strdup(xc
);
224 /** Sets the xclass for this window.
226 A string used to tell the system what type of window this is. Mostly
227 this identifies the picture to draw in the icon. This only works if
228 called \e before calling show().
230 <I>Under X</I>, this is turned into a XA_WM_CLASS pair by truncating at
231 the first non-alphanumeric character and capitalizing the first character,
232 and the second one if the first is 'x'. Thus "foo" turns into "foo, Foo",
233 and "xprog.1" turns into "xprog, XProg".
235 <I>Under Microsoft Windows</I>, this string is used as the name of the
236 WNDCLASS structure, though it is not clear if this can have any
239 \since FLTK 1.3 the passed string is copied. You can use a local
240 variable or free the string immediately after this call. Note that
241 FLTK 1.1 stores the \e pointer without copying the string.
243 If the default xclass has not yet been set, this also sets the
244 default xclass for all windows created subsequently.
246 \see Fl_Window::default_xclass(const char *)
248 void Fl_Window::xclass(const char *xc
)
255 xclass_
= strdup(xc
);
256 if (!default_xclass_
) {
262 /** Returns the xclass for this window, or a default.
264 \see Fl_Window::default_xclass(const char *)
265 \see Fl_Window::xclass(const char *)
267 const char *Fl_Window::xclass() const
272 return default_xclass();
276 /** Gets the current icon window target dependent data. */
277 const void *Fl_Window::icon() const {
281 /** Sets the current icon window target dependent data. */
282 void Fl_Window::icon(const void * ic
) {
288 // End of "$Id: Fl_Window.cxx 8472 2011-02-25 08:44:47Z AlbrechtS $".