1 //
2 // "$Id: Fl_Window.cxx 5251 2006-06-28 10:23:33Z matt $"
3 //
4 // Window widget class for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2005 by Bill Spitzak and others.
7 //
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.
12 //
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.
17 //
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 // USA.
22 //
23 // Please report all bugs and problems on the following page:
24 //
25 // http://www.fltk.org/str.php
26 //
27
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
32
33 #include <FL/Fl.H>
34 #include <FL/Fl_Window.H>
35 #include <stdlib.h>
36 #include "flstring.h"
37
38 #ifdef __APPLE_QUARTZ__
39 #include <FL/fl_draw.H>
40 #endif
41
_Fl_Window()42 void Fl_Window::_Fl_Window() {
43 type(FL_WINDOW);
44 box(FL_FLAT_BOX);
45 if (Fl::scheme_bg_) {
46 labeltype(FL_NORMAL_LABEL);
47 align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
48 image(Fl::scheme_bg_);
49 } else {
50 labeltype(FL_NO_LABEL);
51 }
52 i = 0;
53 xclass_ = 0;
54 icon_ = 0;
55 iconlabel_ = 0;
56 resizable(0);
57 size_range_set = 0;
58 minw = maxw = minh = maxh = 0;
59 callback((Fl_Callback*)default_callback);
60 }
61
Fl_Window(int X,int Y,int W,int H,const char * l)62 Fl_Window::Fl_Window(int X,int Y,int W, int H, const char *l)
63 : Fl_Group(X, Y, W, H, l) {
64 cursor_default = FL_CURSOR_DEFAULT;
65 cursor_fg = FL_BLACK;
66 cursor_bg = FL_WHITE;
67
68 _Fl_Window();
69 set_flag(FL_FORCE_POSITION);
70 }
71
Fl_Window(int W,int H,const char * l)72 Fl_Window::Fl_Window(int W, int H, const char *l)
73 // fix common user error of a missing end() with current(0):
74 : Fl_Group((Fl_Group::current(0),0), 0, W, H, l) {
75 cursor_default = FL_CURSOR_DEFAULT;
76 cursor_fg = FL_BLACK;
77 cursor_bg = FL_WHITE;
78
79 _Fl_Window();
80 clear_visible();
81 }
82
window() const83 Fl_Window *Fl_Widget::window() const {
84 for (Fl_Widget *o = parent(); o; o = o->parent())
85 if (o->type() >= FL_WINDOW) return (Fl_Window*)o;
86 return 0;
87 }
88
x_root() const89 int Fl_Window::x_root() const {
90 Fl_Window *p = window();
91 if (p) return p->x_root() + x();
92 return x();
93 }
94
y_root() const95 int Fl_Window::y_root() const {
96 Fl_Window *p = window();
97 if (p) return p->y_root() + y();
98 return y();
99 }
100
draw()101 void Fl_Window::draw() {
102 const char *savelabel = label();
103 int saveflags = flags();
104 int savex = x(); x(0);
105 int savey = y(); y(0);
106 // Make sure we don't draw the window title in the window background...
107 clear_flag(COPIED_LABEL); // do not free copied labels!
108 Fl_Widget::label(0);
109 Fl_Group::draw();
110 #ifdef __APPLE_QUARTZ__
111 if (!parent() && resizable() && (!size_range_set || minh!=maxh || minw!=maxw)) {
112 int dx = Fl::box_dw(box())-Fl::box_dx(box());
113 int dy = Fl::box_dh(box())-Fl::box_dy(box());
114 if (dx<=0) dx = 1;
115 if (dy<=0) dy = 1;
116 int x1 = w()-dx-1, x2 = x1, y1 = h()-dx-1, y2 = y1;
117 Fl_Color c[4] = {
118 color(),
119 fl_color_average(color(), FL_WHITE, 0.7f),
120 fl_color_average(color(), FL_BLACK, 0.6f),
121 fl_color_average(color(), FL_BLACK, 0.8f),
122 };
123 int i;
124 for (i=dx; i<12; i++) {
125 fl_color(c[i&3]);
126 fl_line(x1--, y1, x2, y2--);
127 }
128 }
129 #endif
130 // Restore the label...
131 Fl_Widget::label(savelabel);
132 set_flag(saveflags);
133 y(savey);
134 x(savex);
135 }
136
label(const char * name)137 void Fl_Window::label(const char *name) {
138 label(name, iconlabel());
139 }
140
copy_label(const char * a)141 void Fl_Window::copy_label(const char *a) {
142 if (flags() & COPIED_LABEL) {
143 free((void *)label());
144 clear_flag(COPIED_LABEL);
145 }
146 if (a) a = strdup(a);
147 label(a, iconlabel());
148 set_flag(COPIED_LABEL);
149 }
150
151
iconlabel(const char * iname)152 void Fl_Window::iconlabel(const char *iname) {
153 uchar saveflags = flags();
154 label(label(), iname);
155 set_flag(saveflags);
156 }
157
158 // the Fl::atclose pointer is provided for back compatability. You
159 // can now just change the callback for the window instead.
160
default_atclose(Fl_Window * window,void * v)161 void Fl::default_atclose(Fl_Window* window, void* v) {
162 window->hide();
163 Fl_Widget::default_callback(window, v); // put on Fl::read_queue()
164 }
165
166 void (*Fl::atclose)(Fl_Window*, void*) = default_atclose;
167
default_callback(Fl_Window * win,void * v)168 void Fl_Window::default_callback(Fl_Window* win, void* v) {
169 Fl::atclose(win, v);
170 }
171
current()172 Fl_Window *Fl_Window::current() {
173 return current_;
174 }
175
176
177 //
178 // End of "$Id: Fl_Window.cxx 5251 2006-06-28 10:23:33Z matt $".
179 //
180