29
29
// warning: the Apple Quartz version still uses some Quickdraw calls,
30
// mostly to get around the single active context in QD and
30
// mostly to get around the single active context in QD and
31
31
// to implement clipping. This should be changed into pure
32
32
// Quartz calls in the near future.
35
/* We require Windows 2000 features (e.g. VK definitions) */
37
# if !defined(WINVER) || (WINVER < 0x0500)
41
# define WINVER 0x0500
43
# if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
47
# define _WIN32_WINNT 0x0500
51
// recent versions of MinGW warn: "Please include winsock2.h before windows.h",
52
// hence we must include winsock2.h before FL/Fl.H (A.S. Dec. 2010, IMM May 2011)
53
#if defined(WIN32) && !defined(__CYGWIN__)
54
# include <winsock2.h>
35
58
#include <FL/Fl_Window.H>
59
#include <FL/Fl_Tooltip.H>
37
#include <FL/Fl_Tooltip.H>
40
64
#include <stdlib.h>
41
65
#include "flstring.h"
43
#if defined(__APPLE__)
44
#import <Cocoa/Cocoa.h>
47
67
#if defined(DEBUG) || defined(DEBUG_WATCH)
48
68
# include <stdio.h>
49
69
#endif // DEBUG || DEBUG_WATCH
55
75
void fl_cleanup_pens(void);
56
76
void fl_release_dc(HWND,HDC);
57
77
void fl_cleanup_dc_list(void);
78
#elif defined(__APPLE__)
79
extern double fl_mac_flush_and_wait(double time_to_wait, char in_idle);
85
#if defined(__APPLE__) || defined(FL_DOXYGEN)
86
const char *Fl_Mac_App_Menu::about = "About ";
87
const char *Fl_Mac_App_Menu::print = "Print Front Window";
88
const char *Fl_Mac_App_Menu::services = "Services";
89
const char *Fl_Mac_App_Menu::hide = "Hide ";
90
const char *Fl_Mac_App_Menu::hide_others = "Hide Others";
91
const char *Fl_Mac_App_Menu::show = "Show All";
92
const char *Fl_Mac_App_Menu::quit = "Quit ";
64
95
Fl_Widget *Fl::belowmouse_,
134
Returns whether or not the mouse event is inside the given rectangle.
135
Returns non-zero if the current event_x and event_y
136
put it inside the widget or inside an arbitrary bounding box. You
137
should always call this rather than doing your own comparison so you
138
are consistent about edge effects.
168
/** Returns whether or not the mouse event is inside the given rectangle.
170
Returns non-zero if the current Fl::event_x() and Fl::event_y()
171
put it inside the given arbitrary bounding box.
173
You should always call this rather than doing your own comparison
174
so you are consistent about edge effects.
176
To find out, whether the event is inside a child widget of the
177
current window, you can use Fl::event_inside(const Fl_Widget *).
179
\param[in] xx,yy,ww,hh bounding box
180
\return non-zero, if mouse event is inside
140
182
int Fl::event_inside(int xx,int yy,int ww,int hh) /*const*/ {
141
183
int mx = e_x - xx;
143
185
return (mx >= 0 && mx < ww && my >= 0 && my < hh);
146
/** Returns whether or not the mouse event is inside the given widget.
147
Returns non-zero if the current event_x and event_y
148
put it inside the widget or inside an arbitrary bounding box. You
149
should always call this rather than doing your own comparison so you
150
are consistent about edge effects.
188
/** Returns whether or not the mouse event is inside a given child widget.
190
Returns non-zero if the current Fl::event_x() and Fl::event_y()
191
put it inside the given child widget's bounding box.
193
This method can only be used to check whether the mouse event is
194
inside a \b child widget of the window that handles the event, and
195
there must not be an intermediate subwindow (i.e. the widget must
196
not be inside a subwindow of the current window). However, it is
197
valid if the widget is inside a nested Fl_Group.
199
You must not use it with the window itself as the \p o argument
200
in a window's handle() method.
202
\note The mentioned restrictions are necessary, because this method
203
does not transform coordinates of child widgets, and thus the given
204
widget \p o must be within the \e same window that is handling the
205
current event. Otherwise the results are undefined.
207
You should always call this rather than doing your own comparison
208
so you are consistent about edge effects.
210
\see Fl::event_inside(int, int, int, int)
212
\param[in] o child widget to be tested
213
\return non-zero, if mouse event is inside the widget
152
215
int Fl::event_inside(const Fl_Widget *o) /*const*/ {
153
216
int mx = e_x - o->x();
291
355
waits for events. This is different than an idle callback because it
292
356
is only called once, then FLTK calls the system and tells it not to
293
357
return until an event happens.
295
359
This can be used by code that wants to monitor the
296
360
application's state, such as to keep a display up to date. The
297
361
advantage of using a check callback is that it is called only when no
298
362
events are pending. If events are coming in quickly, whole blocks of
299
363
them will be processed before this is called once. This can save
300
364
significant time and avoid the application falling behind the events.
305
369
bool state_changed; // anything that changes the display turns this on
307
371
void callback(void*) {
308
372
if (!state_changed) return;
309
373
state_changed = false;
310
374
do_expensive_calculation();
311
375
widget->redraw();
315
379
Fl::add_check(callback);
316
380
return Fl::run();
505
583
repeatedly to "run" your program. You can also check what happened
506
584
each time after this returns, which is quite useful for managing
509
587
What this really does is call all idle callbacks, all elapsed
510
588
timeouts, call Fl::flush() to get the screen to update, and
511
589
then wait some time (zero if there are idle callbacks, the shortest of
512
590
all pending timeouts, or infinity), for any events from the user or
513
591
any Fl::add_fd() callbacks. It then handles the events and
514
592
calls the callbacks and then returns.
516
The return value of the first form is non-zero if there are
517
any visible windows - this may change in future versions of
520
The second form waits a maximum of <i>time</i>
521
seconds. <i>It can return much sooner if something happens.</i>
594
The return value of Fl::wait() is non-zero if there are any
595
visible windows - this may change in future versions of FLTK.
597
Fl::wait(time) waits a maximum of \e time seconds.
598
<i>It can return much sooner if something happens.</i>
523
600
The return value is positive if an event or fd happens before the
524
601
time elapsed. It is zero if nothing happens (on Win32 this will only
525
return zero if <i>time</i> is zero). It is negative if an error
602
return zero if \e time is zero). It is negative if an error
526
603
occurs (this will happen on UNIX if a signal happens).
691
768
////////////////////////////////////////////////////////////////
692
769
// Event handlers:
694
772
struct handler_link {
695
773
int (*handle)(int);
696
774
handler_link *next;
699
778
static handler_link *handlers = 0;
702
782
Install a function to parse unrecognized events. If FLTK cannot
703
783
figure out what to do with an event, it calls each of these functions
704
784
(most recent first) until one of them returns non-zero. If none of
705
them returns non zero then the event is ignored. Events that cause
785
them returns non-zero then the event is ignored. Events that cause
706
786
this to be called are:
708
- FL_SHORTCUT events that are not recognized by any widget.
788
- FL_SHORTCUT events that are not recognized by any widget.
709
789
This lets you provide global shortcut keys.
710
790
- System events that FLTK does not recognize. See fl_xevent.
711
- \e Some other events when the widget FLTK selected returns
712
zero from its handle() method. Exactly which ones may change
791
- \e Some other events when the widget FLTK selected returns
792
zero from its handle() method. Exactly which ones may change
713
793
in future versions, however.
795
\see Fl::remove_handler(Fl_Event_Handler)
796
\see Fl::event_dispatch(Fl_Event_Dispatch d)
797
\see Fl::handle(int, Fl_Window*)
715
799
void Fl::add_handler(Fl_Event_Handler ha) {
716
800
handler_link *l = new handler_link;
794
889
Sets the widget that is below the mouse. This is for
795
highlighting buttons. It is not used to send FL_PUSH or
890
highlighting buttons. It is not used to send FL_PUSH or
796
891
FL_MOVE directly, for several obscure reasons, but those events
797
typically go to this widget. This is also the first widget tried for
892
typically go to this widget. This is also the first widget tried for
798
893
FL_SHORTCUT events.
800
895
If you change the belowmouse widget, the previous one and all
801
896
parents (that don't contain the new widget) are sent FL_LEAVE
802
897
events. Changing this does \e not send FL_ENTER to this
803
898
or any widget, because sending FL_ENTER is supposed to \e test
804
if the widget wants the mouse (by it returning non-zero from
899
if the widget wants the mouse (by it returning non-zero from
807
902
void Fl::belowmouse(Fl_Widget *o) {
1050
\brief Set a new event dispatch function.
1052
The event dispatch function is called after native events are converted to
1053
FLTK events, but before they are handled by FLTK. If the dispatch function
1054
Fl_Event_Dispatch \p d is set, it is up to the dispatch function to call
1055
Fl::handle_(int, Fl_Window*) or to ignore the event.
1057
The dispatch function itself must return 0 if it ignored the event,
1058
or non-zero if it used the event. If you call Fl::handle_(), then
1059
this will return the correct value.
1061
The event dispatch can be used to handle exceptions in FLTK events and
1062
callbacks before they reach the native event handler:
1065
int myHandler(int e, Fl_Window *w) {
1067
return Fl::handle_(e, w);
1074
Fl::event_dispatch(myHandler);
1080
\param d new dispatch function, or NULL
1081
\see Fl::add_handler(Fl_Event_Handler)
1082
\see Fl::handle(int, Fl_Window*)
1083
\see Fl::handle_(int, Fl_Window*)
1085
void Fl::event_dispatch(Fl_Event_Dispatch d)
1092
\brief Return the current event dispatch function.
1094
Fl_Event_Dispatch Fl::event_dispatch()
1101
\brief Handle events from the window system.
1103
This is called from the native event dispatch after native events have been
1104
converted to FLTK notation. This function calls Fl::handle_(int, Fl_Window*)
1105
unless the user sets a dispatch function. If a user dispatch function is set,
1106
the user must make sure that Fl::handle_() is called, or the event will be
1109
\param e the event type (Fl::event_number() is not yet set)
1110
\param window the window that caused this event
1111
\return 0 if the event was not handled
1113
\see Fl::add_handler(Fl_Event_Handler)
1114
\see Fl::event_dispatch(Fl_Event_Dispatch)
953
1116
int Fl::handle(int e, Fl_Window* window)
1119
return e_dispatch(e, window);
1121
return handle_(e, window);
955
Sends the event to a window for processing. Returns non-zero if any
956
widget uses the event.
1127
\brief Handle events from the window system.
1129
This function is called from the native event dispatch, unless the user sets
1130
another dispatch function. In that case, the user dispatch function must
1131
decide when to call Fl::handle_(int, Fl_Window*)
1133
\param e the event type (Fl::event_number() is not yet set)
1134
\param window the window that caused this event
1135
\return 0 if the event was not handled
1137
\see Fl::event_dispatch(Fl_Event_Dispatch)
1139
int Fl::handle_(int e, Fl_Window* window)
960
1142
if (fl_local_grab) return fl_local_grab(e);
1017
1199
if (modal() && wi != modal()) wi = 0;
1018
1200
if (grab()) wi = grab();
1019
{Fl_Widget* pbm = belowmouse();
1020
int ret = (wi && send(e, wi, window));
1021
if (pbm != belowmouse()) {
1202
Fl_Widget* pbm = belowmouse();
1204
if (fl_mac_os_version < 100500) {
1205
// before 10.5, mouse moved events aren't sent to borderless windows such as tooltips
1206
Fl_Window *tooltip = Fl_Tooltip::current_window();
1208
if (tooltip && tooltip->shown() ) { // check if a tooltip window is currently opened
1209
// check if mouse is inside the tooltip
1210
inside = (Fl::event_x_root() >= tooltip->x() && Fl::event_x_root() < tooltip->x() + tooltip->w() &&
1211
Fl::event_y_root() >= tooltip->y() && Fl::event_y_root() < tooltip->y() + tooltip->h() );
1213
// if inside, send event to tooltip window instead of background window
1214
if (inside) ret = send(e, tooltip, window);
1215
else ret = (wi && send(e, wi, window));
1218
ret = (wi && send(e, wi, window));
1219
if (pbm != belowmouse()) {
1023
1221
printf("Fl::handle(e=%d, window=%p);\n", e, window);
1024
1222
#endif // DEBUG
1351
1553
Fl::copy(text, len, 0);
1354
/** Backward compatibility only:
1355
Set things up so the receiver widget will be called with an FL_PASTE event some
1356
time in the future for the specified clipboard. The reciever
1357
should be prepared to be called \e directly by this, or for
1358
it to happen \e later, or possibly <i>not at all</i>. This
1359
allows the window system to take as long as necessary to retrieve
1360
the paste buffer (or even to screw up completely) without complex
1361
and error-prone synchronization code in FLTK.
1556
/** Backward compatibility only.
1557
This calls Fl::paste(receiver, 0);
1362
1558
\see Fl::paste(Fl_Widget &receiver, int clipboard)
1364
1560
void Fl::paste(Fl_Widget &receiver) {
1392
1588
W += 5; // Add a little to the size of the label to cover overflow
1395
if (align() & FL_ALIGN_BOTTOM) {
1396
window()->damage(FL_DAMAGE_EXPOSE, x(), y() + h(), w(), H);
1397
} else if (align() & FL_ALIGN_TOP) {
1398
window()->damage(FL_DAMAGE_EXPOSE, x(), y() - H, w(), H);
1399
} else if (align() & FL_ALIGN_LEFT) {
1400
window()->damage(FL_DAMAGE_EXPOSE, x() - W, y(), W, h());
1401
} else if (align() & FL_ALIGN_RIGHT) {
1402
window()->damage(FL_DAMAGE_EXPOSE, x() + w(), y(), W, h());
1404
window()->damage(FL_DAMAGE_ALL);
1592
// This assumes that measure() returns the correct outline, which it does
1593
// not in all possible cases of alignment combinedwith image and symbols.
1594
switch (align() & 0x0f) {
1595
case FL_ALIGN_TOP_LEFT:
1596
window()->damage(FL_DAMAGE_EXPOSE, x(), y()-H, W, H); break;
1598
window()->damage(FL_DAMAGE_EXPOSE, x()+(w()-W)/2, y()-H, W, H); break;
1599
case FL_ALIGN_TOP_RIGHT:
1600
window()->damage(FL_DAMAGE_EXPOSE, x()+w()-W, y()-H, W, H); break;
1601
case FL_ALIGN_LEFT_TOP:
1602
window()->damage(FL_DAMAGE_EXPOSE, x()-W, y(), W, H); break;
1603
case FL_ALIGN_RIGHT_TOP:
1604
window()->damage(FL_DAMAGE_EXPOSE, x()+w(), y(), W, H); break;
1606
window()->damage(FL_DAMAGE_EXPOSE, x()-W, y()+(h()-H)/2, W, H); break;
1607
case FL_ALIGN_RIGHT:
1608
window()->damage(FL_DAMAGE_EXPOSE, x()+w(), y()+(h()-H)/2, W, H); break;
1609
case FL_ALIGN_LEFT_BOTTOM:
1610
window()->damage(FL_DAMAGE_EXPOSE, x()-W, y()+h()-H, W, H); break;
1611
case FL_ALIGN_RIGHT_BOTTOM:
1612
window()->damage(FL_DAMAGE_EXPOSE, x()+w(), y()+h()-H, W, H); break;
1613
case FL_ALIGN_BOTTOM_LEFT:
1614
window()->damage(FL_DAMAGE_EXPOSE, x(), y()+h(), W, H); break;
1615
case FL_ALIGN_BOTTOM:
1616
window()->damage(FL_DAMAGE_EXPOSE, x()+(w()-W)/2, y()+h(), W, H); break;
1617
case FL_ALIGN_BOTTOM_RIGHT:
1618
window()->damage(FL_DAMAGE_EXPOSE, x()+w()-W, y()+h(), W, H); break;
1620
window()->damage(FL_DAMAGE_ALL); break;
1407
1623
// The label is inside the widget, so just redraw the widget itself...
1912
\brief FLTK library options management.
1914
This function needs to be documented in more detail. It can be used for more
1915
optional settings, such as using a native file chooser instead of the FLTK one
1916
wherever possible, disabling tooltips, disabling visible focus, disabling
1917
FLTK file chooser preview, etc. .
1919
There should be a command line option interface.
1921
There should be an application that manages options system wide, per user, and
1924
\note As of FLTK 1.3.0, options can be managed within fluid, using the menu
1925
<i>Edit/Global FLTK Settings</i>.
1927
\param opt which option
1928
\return true or false
1929
\see enum Fl::Fl_Option
1930
\see Fl::option(Fl_Option, bool)
1934
bool Fl::option(Fl_Option opt)
1936
if (!options_read_) {
1938
{ // first, read the system wide preferences
1939
Fl_Preferences prefs(Fl_Preferences::SYSTEM, "fltk.org", "fltk");
1940
Fl_Preferences opt_prefs(prefs, "options");
1941
opt_prefs.get("ArrowFocus", tmp, 0); // default: off
1942
options_[OPTION_ARROW_FOCUS] = tmp;
1943
//opt_prefs.get("NativeFilechooser", tmp, 1); // default: on
1944
//options_[OPTION_NATIVE_FILECHOOSER] = tmp;
1945
//opt_prefs.get("FilechooserPreview", tmp, 1); // default: on
1946
//options_[OPTION_FILECHOOSER_PREVIEW] = tmp;
1947
opt_prefs.get("VisibleFocus", tmp, 1); // default: on
1948
options_[OPTION_VISIBLE_FOCUS] = tmp;
1949
opt_prefs.get("DNDText", tmp, 1); // default: on
1950
options_[OPTION_DND_TEXT] = tmp;
1951
opt_prefs.get("ShowTooltips", tmp, 1); // default: on
1952
options_[OPTION_SHOW_TOOLTIPS] = tmp;
1954
{ // next, check the user preferences
1955
// override system options only, if the option is set ( >= 0 )
1956
Fl_Preferences prefs(Fl_Preferences::USER, "fltk.org", "fltk");
1957
Fl_Preferences opt_prefs(prefs, "options");
1958
opt_prefs.get("ArrowFocus", tmp, -1);
1959
if (tmp >= 0) options_[OPTION_ARROW_FOCUS] = tmp;
1960
//opt_prefs.get("NativeFilechooser", tmp, -1);
1961
//if (tmp >= 0) options_[OPTION_NATIVE_FILECHOOSER] = tmp;
1962
//opt_prefs.get("FilechooserPreview", tmp, -1);
1963
//if (tmp >= 0) options_[OPTION_FILECHOOSER_PREVIEW] = tmp;
1964
opt_prefs.get("VisibleFocus", tmp, -1);
1965
if (tmp >= 0) options_[OPTION_VISIBLE_FOCUS] = tmp;
1966
opt_prefs.get("DNDText", tmp, -1);
1967
if (tmp >= 0) options_[OPTION_DND_TEXT] = tmp;
1968
opt_prefs.get("ShowTooltips", tmp, -1);
1969
if (tmp >= 0) options_[OPTION_SHOW_TOOLTIPS] = tmp;
1971
{ // now, if the developer has registered this app, we could as for per-application preferences
1975
if (opt<0 || opt>=OPTION_LAST)
1977
return (bool)(options_[opt]!=0);
1981
\brief Override an option while the application is running.
1983
This function does not change any system or user settings.
1985
\param opt which option
1986
\param val set to true or false
1987
\see enum Fl::Fl_Option
1988
\see bool Fl::option(Fl_Option)
1990
void Fl::option(Fl_Option opt, bool val)
1992
if (opt<0 || opt>=OPTION_LAST)
1994
if (!options_read_) {
1995
// first read this option, so we don't override our setting later
1998
options_[opt] = val;
1695
2002
// Helper class Fl_Widget_Tracker
1698
2005
The constructor adds a widget to the watch list.
1700
Fl_Widget_Tracker::Fl_Widget_Tracker(Fl_Widget *wi) {
2007
Fl_Widget_Tracker::Fl_Widget_Tracker(Fl_Widget *wi)
1703
2010
Fl::watch_widget_pointer(wp_); // add pointer to watch list