]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/window.cpp
Useful little fix that automatically hides the busy cursor in modal dialogs.
[wxWidgets.git] / src / gtk / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: window.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling, Julian Smart
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation "window.h"
13 #endif
14
15 #include "wx/defs.h"
16 #include "wx/window.h"
17 #include "wx/dc.h"
18 #include "wx/frame.h"
19 #include "wx/app.h"
20 #include "wx/layout.h"
21 #include "wx/utils.h"
22 #include "wx/dialog.h"
23 #include "wx/msgdlg.h"
24
25 #if wxUSE_DRAG_AND_DROP
26 #include "wx/dnd.h"
27 #endif
28
29 #if wxUSE_TOOLTIPS
30 #include "wx/tooltip.h"
31 #endif
32
33 #include "wx/menu.h"
34 #include "wx/statusbr.h"
35 #include "wx/intl.h"
36 #include "wx/settings.h"
37 #include "wx/log.h"
38
39 #include <math.h>
40
41 #include "gdk/gdk.h"
42 #include "gtk/gtk.h"
43 #include "gdk/gdkprivate.h"
44 #include "gdk/gdkkeysyms.h"
45 #include "wx/gtk/win_gtk.h"
46
47 #include "gdk/gdkx.h"
48
49 //-----------------------------------------------------------------------------
50 // documentation on internals
51 //-----------------------------------------------------------------------------
52
53 /*
54 I have been asked several times about writing some documentation about
55 the GTK port of wxWindows, especially its internal structures. Obviously,
56 you cannot understand wxGTK without knowing a little about the GTK, but
57 some more information about what the wxWindow, which is the base class
58 for all other window classes, does seems required as well.
59
60 What does wxWindow do? It contains the common interface for the following
61 jobs of its descendants:
62
63 1) Define the rudimentary behaviour common to all window classes, such as
64 resizing, intercepting user input (so as to make it possible to use these
65 events for special purposes in a derived class), window names etc.
66
67 2) Provide the possibility to contain and manage children, if the derived
68 class is allowed to contain children, which holds true for those window
69 classes which do not display a native GTK widget. To name them, these
70 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
71 work classes are a special case and are handled a bit differently from
72 the rest. The same holds true for the wxNotebook class.
73
74 3) Provide the possibility to draw into a client area of a window. This,
75 too, only holds true for classes that do not display a native GTK widget
76 as above.
77
78 4) Provide the entire mechanism for scrolling widgets. This actual inter-
79 face for this is usually in wxScrolledWindow, but the GTK implementation
80 is in this class.
81
82 5) A multitude of helper or extra methods for special purposes, such as
83 Drag'n'Drop, managing validators etc.
84
85 Normally one might expect, that one wxWindows window would always correspond
86 to one GTK widget. Under GTK, there is no such allround widget that has all
87 the functionality. Moreover, the GTK defines a client area as a different
88 widget from the actual widget you are handling. Last but not least some
89 special classes (e.g. wxFrame) handle different categories of widgets and
90 still have the possibility to draw something in the client area.
91 It was therefore required to write a special purpose GTK widget, that would
92 represent a client area in the sense of wxWindows capable to do the jobs
93 2), 3) and 4). I have written this class and it resides in win_gtk.c of
94 this directory.
95
96 All windows must have a widget, with which they interact with other under-
97 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
98 thw wxWindow class has a member variable called m_widget which holds a
99 pointer to this widget. When the window class represents a GTK native widget,
100 this is (in most cases) the only GTK widget the class manages. E.g. the
101 wxStatitText class handles only a GtkLabel widget a pointer to which you
102 can find in m_widget (defined in wxWindow)
103
104 When the class has a client area for drawing into and for containing children
105 it has to handle the client area widget (of the type GtkMyFixed, defined in
106 win_gtk.c), but there could be any number of widgets, handled by a class
107 The common rule for all windows is only, that the widget that interacts with
108 the rest of GTK must be referenced in m_widget and all other widgets must be
109 children of this widget on the GTK level. The top-most widget, which also
110 represents the client area, must be in the m_wxwindow field and must be of
111 the type GtkMyFixed.
112
113 As I said, the window classes that display a GTK native widget only have
114 one widget, so in the case of e.g. the wxButton class m_widget holds a
115 pointer to a GtkButton widget. But windows with client areas (for drawing
116 and children) have a m_widget field that is a pointer to a GtkScrolled-
117 Window and a m_wxwindow field that is pointer to a GtkMyFixed and this
118 one is (in the GTK sense) a child of the GtkScrolledWindow.
119
120 If the m_wxwindow field is set, then all input to this widget is inter-
121 cepted and sent to the wxWindows class. If not, all input to the widget
122 that gets pointed to by m_widget gets intercepted and sent to the class.
123
124 */
125
126 //-----------------------------------------------------------------------------
127 // data
128 //-----------------------------------------------------------------------------
129
130 extern wxList wxPendingDelete;
131 extern bool g_blockEventsOnDrag;
132 extern bool g_blockEventsOnScroll;
133 extern wxCursor g_globalCursor;
134 static wxWindow *g_captureWindow = (wxWindow*) NULL;
135 static wxWindow *g_focusWindow = (wxWindow*) NULL;
136
137 /* hack: we need something to pass to gtk_menu_popup, so we store the time of
138 the last click here */
139 static guint32 gs_timeLastClick = 0;
140
141 //-----------------------------------------------------------------------------
142 // debug
143 //-----------------------------------------------------------------------------
144
145 #ifdef __WXDEBUG__
146
147 static gint gtk_debug_focus_in_callback( GtkWidget *WXUNUSED(widget),
148 GdkEvent *WXUNUSED(event),
149 const wxChar *name )
150 {
151 /*
152 static bool s_done = FALSE;
153 if ( !s_done )
154 {
155 wxLog::AddTraceMask("focus");
156 s_done = TRUE;
157 }
158 wxLogTrace(_T("FOCUS NOW AT: %s"), name);
159 */
160
161 return FALSE;
162 }
163
164 void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window )
165 {
166 wxString tmp = name;
167 tmp += _T(" FROM ");
168 tmp += window;
169
170 wxChar *s = new wxChar[tmp.Length()+1];
171
172 wxStrcpy( s, tmp );
173
174 gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event",
175 GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback), (gpointer)s );
176 }
177
178 #endif // Debug
179
180 //-----------------------------------------------------------------------------
181 // missing gdk functions
182 //-----------------------------------------------------------------------------
183
184 void
185 gdk_window_warp_pointer (GdkWindow *window,
186 gint x,
187 gint y)
188 {
189 GdkWindowPrivate *priv;
190
191 if (!window)
192 window = (GdkWindow*) &gdk_root_parent;
193
194 priv = (GdkWindowPrivate*) window;
195
196 if (!priv->destroyed)
197 {
198 XWarpPointer (priv->xdisplay,
199 None, /* not source window -> move from anywhere */
200 priv->xwindow, /* dest window */
201 0, 0, 0, 0, /* not source window -> move from anywhere */
202 x, y );
203 }
204 }
205
206 //-----------------------------------------------------------------------------
207 // idle system
208 //-----------------------------------------------------------------------------
209
210 extern void wxapp_install_idle_handler();
211 extern bool g_isIdle;
212
213 //-----------------------------------------------------------------------------
214 // key event conversion routines
215 //-----------------------------------------------------------------------------
216
217 #if (GTK_MINOR_VERSION == 0)
218 /* these functions are copied verbatim from GTK 1.2 */
219 static void
220 gdkx_XConvertCase (KeySym symbol,
221 KeySym *lower,
222 KeySym *upper)
223 {
224 register KeySym sym = symbol;
225
226 g_return_if_fail (lower != NULL);
227 g_return_if_fail (upper != NULL);
228
229 *lower = sym;
230 *upper = sym;
231
232 switch (sym >> 8)
233 {
234 #if defined (GDK_A) && defined (GDK_Ooblique)
235 case 0: /* Latin 1 */
236 if ((sym >= GDK_A) && (sym <= GDK_Z))
237 *lower += (GDK_a - GDK_A);
238 else if ((sym >= GDK_a) && (sym <= GDK_z))
239 *upper -= (GDK_a - GDK_A);
240 else if ((sym >= GDK_Agrave) && (sym <= GDK_Odiaeresis))
241 *lower += (GDK_agrave - GDK_Agrave);
242 else if ((sym >= GDK_agrave) && (sym <= GDK_odiaeresis))
243 *upper -= (GDK_agrave - GDK_Agrave);
244 else if ((sym >= GDK_Ooblique) && (sym <= GDK_Thorn))
245 *lower += (GDK_oslash - GDK_Ooblique);
246 else if ((sym >= GDK_oslash) && (sym <= GDK_thorn))
247 *upper -= (GDK_oslash - GDK_Ooblique);
248 break;
249 #endif /* LATIN1 */
250
251 #if defined (GDK_Aogonek) && defined (GDK_tcedilla)
252 case 1: /* Latin 2 */
253 /* Assume the KeySym is a legal value (ignore discontinuities) */
254 if (sym == GDK_Aogonek)
255 *lower = GDK_aogonek;
256 else if (sym >= GDK_Lstroke && sym <= GDK_Sacute)
257 *lower += (GDK_lstroke - GDK_Lstroke);
258 else if (sym >= GDK_Scaron && sym <= GDK_Zacute)
259 *lower += (GDK_scaron - GDK_Scaron);
260 else if (sym >= GDK_Zcaron && sym <= GDK_Zabovedot)
261 *lower += (GDK_zcaron - GDK_Zcaron);
262 else if (sym == GDK_aogonek)
263 *upper = GDK_Aogonek;
264 else if (sym >= GDK_lstroke && sym <= GDK_sacute)
265 *upper -= (GDK_lstroke - GDK_Lstroke);
266 else if (sym >= GDK_scaron && sym <= GDK_zacute)
267 *upper -= (GDK_scaron - GDK_Scaron);
268 else if (sym >= GDK_zcaron && sym <= GDK_zabovedot)
269 *upper -= (GDK_zcaron - GDK_Zcaron);
270 else if (sym >= GDK_Racute && sym <= GDK_Tcedilla)
271 *lower += (GDK_racute - GDK_Racute);
272 else if (sym >= GDK_racute && sym <= GDK_tcedilla)
273 *upper -= (GDK_racute - GDK_Racute);
274 break;
275 #endif /* LATIN2 */
276
277 #if defined (GDK_Hstroke) && defined (GDK_Cabovedot)
278 case 2: /* Latin 3 */
279 /* Assume the KeySym is a legal value (ignore discontinuities) */
280 if (sym >= GDK_Hstroke && sym <= GDK_Hcircumflex)
281 *lower += (GDK_hstroke - GDK_Hstroke);
282 else if (sym >= GDK_Gbreve && sym <= GDK_Jcircumflex)
283 *lower += (GDK_gbreve - GDK_Gbreve);
284 else if (sym >= GDK_hstroke && sym <= GDK_hcircumflex)
285 *upper -= (GDK_hstroke - GDK_Hstroke);
286 else if (sym >= GDK_gbreve && sym <= GDK_jcircumflex)
287 *upper -= (GDK_gbreve - GDK_Gbreve);
288 else if (sym >= GDK_Cabovedot && sym <= GDK_Scircumflex)
289 *lower += (GDK_cabovedot - GDK_Cabovedot);
290 else if (sym >= GDK_cabovedot && sym <= GDK_scircumflex)
291 *upper -= (GDK_cabovedot - GDK_Cabovedot);
292 break;
293 #endif /* LATIN3 */
294
295 #if defined (GDK_Rcedilla) && defined (GDK_Amacron)
296 case 3: /* Latin 4 */
297 /* Assume the KeySym is a legal value (ignore discontinuities) */
298 if (sym >= GDK_Rcedilla && sym <= GDK_Tslash)
299 *lower += (GDK_rcedilla - GDK_Rcedilla);
300 else if (sym >= GDK_rcedilla && sym <= GDK_tslash)
301 *upper -= (GDK_rcedilla - GDK_Rcedilla);
302 else if (sym == GDK_ENG)
303 *lower = GDK_eng;
304 else if (sym == GDK_eng)
305 *upper = GDK_ENG;
306 else if (sym >= GDK_Amacron && sym <= GDK_Umacron)
307 *lower += (GDK_amacron - GDK_Amacron);
308 else if (sym >= GDK_amacron && sym <= GDK_umacron)
309 *upper -= (GDK_amacron - GDK_Amacron);
310 break;
311 #endif /* LATIN4 */
312
313 #if defined (GDK_Serbian_DJE) && defined (GDK_Cyrillic_yu)
314 case 6: /* Cyrillic */
315 /* Assume the KeySym is a legal value (ignore discontinuities) */
316 if (sym >= GDK_Serbian_DJE && sym <= GDK_Serbian_DZE)
317 *lower -= (GDK_Serbian_DJE - GDK_Serbian_dje);
318 else if (sym >= GDK_Serbian_dje && sym <= GDK_Serbian_dze)
319 *upper += (GDK_Serbian_DJE - GDK_Serbian_dje);
320 else if (sym >= GDK_Cyrillic_YU && sym <= GDK_Cyrillic_HARDSIGN)
321 *lower -= (GDK_Cyrillic_YU - GDK_Cyrillic_yu);
322 else if (sym >= GDK_Cyrillic_yu && sym <= GDK_Cyrillic_hardsign)
323 *upper += (GDK_Cyrillic_YU - GDK_Cyrillic_yu);
324 break;
325 #endif /* CYRILLIC */
326
327 #if defined (GDK_Greek_ALPHAaccent) && defined (GDK_Greek_finalsmallsigma)
328 case 7: /* Greek */
329 /* Assume the KeySym is a legal value (ignore discontinuities) */
330 if (sym >= GDK_Greek_ALPHAaccent && sym <= GDK_Greek_OMEGAaccent)
331 *lower += (GDK_Greek_alphaaccent - GDK_Greek_ALPHAaccent);
332 else if (sym >= GDK_Greek_alphaaccent && sym <= GDK_Greek_omegaaccent &&
333 sym != GDK_Greek_iotaaccentdieresis &&
334 sym != GDK_Greek_upsilonaccentdieresis)
335 *upper -= (GDK_Greek_alphaaccent - GDK_Greek_ALPHAaccent);
336 else if (sym >= GDK_Greek_ALPHA && sym <= GDK_Greek_OMEGA)
337 *lower += (GDK_Greek_alpha - GDK_Greek_ALPHA);
338 else if (sym >= GDK_Greek_alpha && sym <= GDK_Greek_omega &&
339 sym != GDK_Greek_finalsmallsigma)
340 *upper -= (GDK_Greek_alpha - GDK_Greek_ALPHA);
341 break;
342 #endif /* GREEK */
343 }
344 }
345
346 static guint
347 gdk_keyval_to_upper (guint keyval)
348 {
349 if (keyval)
350 {
351 KeySym lower_val = 0;
352 KeySym upper_val = 0;
353
354 gdkx_XConvertCase (keyval, &lower_val, &upper_val);
355 return upper_val;
356 }
357 return 0;
358 }
359 #endif
360
361 static long map_to_unmodified_wx_keysym( KeySym keysym )
362 {
363 guint key_code = 0;
364
365 switch (keysym)
366 {
367 case GDK_Shift_L:
368 case GDK_Shift_R: key_code = WXK_SHIFT; break;
369 case GDK_Control_L:
370 case GDK_Control_R: key_code = WXK_CONTROL; break;
371 case GDK_Meta_L:
372 case GDK_Meta_R:
373 case GDK_Alt_L:
374 case GDK_Alt_R:
375 case GDK_Super_L:
376 case GDK_Super_R: key_code = WXK_ALT; break;
377 case GDK_Menu: key_code = WXK_MENU; break;
378 case GDK_Help: key_code = WXK_HELP; break;
379 case GDK_BackSpace: key_code = WXK_BACK; break;
380 case GDK_ISO_Left_Tab:
381 case GDK_Tab: key_code = WXK_TAB; break;
382 case GDK_Linefeed: key_code = WXK_RETURN; break;
383 case GDK_Clear: key_code = WXK_CLEAR; break;
384 case GDK_Return: key_code = WXK_RETURN; break;
385 case GDK_Pause: key_code = WXK_PAUSE; break;
386 case GDK_Scroll_Lock: key_code = WXK_SCROLL; break;
387 case GDK_Escape: key_code = WXK_ESCAPE; break;
388 case GDK_Delete: key_code = WXK_DELETE; break;
389 case GDK_Home: key_code = WXK_HOME; break;
390 case GDK_Left: key_code = WXK_LEFT; break;
391 case GDK_Up: key_code = WXK_UP; break;
392 case GDK_Right: key_code = WXK_RIGHT; break;
393 case GDK_Down: key_code = WXK_DOWN; break;
394 case GDK_Prior: key_code = WXK_PRIOR; break;
395 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
396 case GDK_Next: key_code = WXK_NEXT; break;
397 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
398 case GDK_End: key_code = WXK_END; break;
399 case GDK_Begin: key_code = WXK_HOME; break;
400 case GDK_Select: key_code = WXK_SELECT; break;
401 case GDK_Print: key_code = WXK_PRINT; break;
402 case GDK_Execute: key_code = WXK_EXECUTE; break;
403 case GDK_Insert: key_code = WXK_INSERT; break;
404 case GDK_Num_Lock: key_code = WXK_NUMLOCK; break;
405
406 case GDK_KP_0: key_code = WXK_NUMPAD0; break;
407 case GDK_KP_1: key_code = WXK_NUMPAD1; break;
408 case GDK_KP_2: key_code = WXK_NUMPAD2; break;
409 case GDK_KP_3: key_code = WXK_NUMPAD3; break;
410 case GDK_KP_4: key_code = WXK_NUMPAD4; break;
411 case GDK_KP_5: key_code = WXK_NUMPAD5; break;
412 case GDK_KP_6: key_code = WXK_NUMPAD6; break;
413 case GDK_KP_7: key_code = WXK_NUMPAD7; break;
414 case GDK_KP_8: key_code = WXK_NUMPAD8; break;
415 case GDK_KP_9: key_code = WXK_NUMPAD9; break;
416 case GDK_KP_Space: key_code = WXK_NUMPAD_SPACE; break;
417 case GDK_KP_Tab: key_code = WXK_NUMPAD_TAB; break;
418 case GDK_KP_Enter: key_code = WXK_NUMPAD_ENTER; break;
419 case GDK_KP_F1: key_code = WXK_NUMPAD_F1; break;
420 case GDK_KP_F2: key_code = WXK_NUMPAD_F2; break;
421 case GDK_KP_F3: key_code = WXK_NUMPAD_F3; break;
422 case GDK_KP_F4: key_code = WXK_NUMPAD_F4; break;
423 case GDK_KP_Home: key_code = WXK_NUMPAD_HOME; break;
424 case GDK_KP_Left: key_code = WXK_NUMPAD_LEFT; break;
425 case GDK_KP_Up: key_code = WXK_NUMPAD_UP; break;
426 case GDK_KP_Right: key_code = WXK_NUMPAD_RIGHT; break;
427 case GDK_KP_Down: key_code = WXK_NUMPAD_DOWN; break;
428 case GDK_KP_Prior: key_code = WXK_NUMPAD_PRIOR; break;
429 // case GDK_KP_Page_Up: key_code = WXK_NUMPAD_PAGEUP; break;
430 case GDK_KP_Next: key_code = WXK_NUMPAD_NEXT; break;
431 // case GDK_KP_Page_Down: key_code = WXK_NUMPAD_PAGEDOWN; break;
432 case GDK_KP_End: key_code = WXK_NUMPAD_END; break;
433 case GDK_KP_Begin: key_code = WXK_NUMPAD_BEGIN; break;
434 case GDK_KP_Insert: key_code = WXK_NUMPAD_INSERT; break;
435 case GDK_KP_Delete: key_code = WXK_NUMPAD_DELETE; break;
436 case GDK_KP_Equal: key_code = WXK_NUMPAD_EQUAL; break;
437 case GDK_KP_Multiply: key_code = WXK_NUMPAD_MULTIPLY; break;
438 case GDK_KP_Add: key_code = WXK_NUMPAD_ADD; break;
439 case GDK_KP_Separator: key_code = WXK_NUMPAD_SEPARATOR; break;
440 case GDK_KP_Subtract: key_code = WXK_NUMPAD_SUBTRACT; break;
441 case GDK_KP_Decimal: key_code = WXK_NUMPAD_DECIMAL; break;
442 case GDK_KP_Divide: key_code = WXK_NUMPAD_DIVIDE; break;
443
444 case GDK_F1: key_code = WXK_F1; break;
445 case GDK_F2: key_code = WXK_F2; break;
446 case GDK_F3: key_code = WXK_F3; break;
447 case GDK_F4: key_code = WXK_F4; break;
448 case GDK_F5: key_code = WXK_F5; break;
449 case GDK_F6: key_code = WXK_F6; break;
450 case GDK_F7: key_code = WXK_F7; break;
451 case GDK_F8: key_code = WXK_F8; break;
452 case GDK_F9: key_code = WXK_F9; break;
453 case GDK_F10: key_code = WXK_F10; break;
454 case GDK_F11: key_code = WXK_F11; break;
455 case GDK_F12: key_code = WXK_F12; break;
456 default:
457 {
458 if (keysym <= 0xFF)
459 {
460 guint upper = gdk_keyval_to_upper( keysym );
461 keysym = (upper != 0 ? upper : keysym ); /* to be MSW compatible */
462 key_code = keysym;
463 }
464 }
465 }
466
467 return (key_code);
468 }
469
470 static long map_to_wx_keysym( KeySym keysym )
471 {
472 guint key_code = 0;
473
474 switch (keysym)
475 {
476 case GDK_Menu: key_code = WXK_MENU; break;
477 case GDK_Help: key_code = WXK_HELP; break;
478 case GDK_BackSpace: key_code = WXK_BACK; break;
479 case GDK_ISO_Left_Tab:
480 case GDK_Tab: key_code = WXK_TAB; break;
481 case GDK_Linefeed: key_code = WXK_RETURN; break;
482 case GDK_Clear: key_code = WXK_CLEAR; break;
483 case GDK_Return: key_code = WXK_RETURN; break;
484 case GDK_Pause: key_code = WXK_PAUSE; break;
485 case GDK_Scroll_Lock: key_code = WXK_SCROLL; break;
486 case GDK_Escape: key_code = WXK_ESCAPE; break;
487 case GDK_Delete: key_code = WXK_DELETE; break;
488 case GDK_Home: key_code = WXK_HOME; break;
489 case GDK_Left: key_code = WXK_LEFT; break;
490 case GDK_Up: key_code = WXK_UP; break;
491 case GDK_Right: key_code = WXK_RIGHT; break;
492 case GDK_Down: key_code = WXK_DOWN; break;
493 case GDK_Prior: key_code = WXK_PRIOR; break;
494 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
495 case GDK_Next: key_code = WXK_NEXT; break;
496 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
497 case GDK_End: key_code = WXK_END; break;
498 case GDK_Begin: key_code = WXK_HOME; break;
499 case GDK_Select: key_code = WXK_SELECT; break;
500 case GDK_Print: key_code = WXK_PRINT; break;
501 case GDK_Execute: key_code = WXK_EXECUTE; break;
502 case GDK_Insert: key_code = WXK_INSERT; break;
503 case GDK_Num_Lock: key_code = WXK_NUMLOCK; break;
504
505 case GDK_KP_0: key_code = '0'; break;
506 case GDK_KP_1: key_code = '1'; break;
507 case GDK_KP_2: key_code = '2'; break;
508 case GDK_KP_3: key_code = '3'; break;
509 case GDK_KP_4: key_code = '4'; break;
510 case GDK_KP_5: key_code = '5'; break;
511 case GDK_KP_6: key_code = '6'; break;
512 case GDK_KP_7: key_code = '7'; break;
513 case GDK_KP_8: key_code = '8'; break;
514 case GDK_KP_9: key_code = '9'; break;
515 case GDK_KP_Space: key_code = ' '; break;
516 case GDK_KP_Tab: key_code = WXK_TAB; break; /* or '\t' ??? */
517 case GDK_KP_Enter: key_code = WXK_RETURN; break; /* or '\r' ??? */
518 case GDK_KP_F1: key_code = WXK_NUMPAD_F1; break;
519 case GDK_KP_F2: key_code = WXK_NUMPAD_F2; break;
520 case GDK_KP_F3: key_code = WXK_NUMPAD_F3; break;
521 case GDK_KP_F4: key_code = WXK_NUMPAD_F4; break;
522 case GDK_KP_Home: key_code = WXK_HOME; break;
523 case GDK_KP_Left: key_code = WXK_LEFT; break;
524 case GDK_KP_Up: key_code = WXK_UP; break;
525 case GDK_KP_Right: key_code = WXK_RIGHT; break;
526 case GDK_KP_Down: key_code = WXK_DOWN; break;
527 case GDK_KP_Prior: key_code = WXK_PRIOR; break;
528 // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
529 case GDK_KP_Next: key_code = WXK_NEXT; break;
530 // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
531 case GDK_KP_End: key_code = WXK_END; break;
532 case GDK_KP_Begin: key_code = WXK_HOME; break;
533 case GDK_KP_Insert: key_code = WXK_INSERT; break;
534 case GDK_KP_Delete: key_code = WXK_DELETE; break;
535 case GDK_KP_Equal: key_code = '='; break;
536 case GDK_KP_Multiply: key_code = '*'; break;
537 case GDK_KP_Add: key_code = '+'; break;
538 case GDK_KP_Separator: key_code = ','; break;
539 case GDK_KP_Subtract: key_code = '-'; break;
540 case GDK_KP_Decimal: key_code = '.'; break;
541 case GDK_KP_Divide: key_code = '/'; break;
542
543 case GDK_F1: key_code = WXK_F1; break;
544 case GDK_F2: key_code = WXK_F2; break;
545 case GDK_F3: key_code = WXK_F3; break;
546 case GDK_F4: key_code = WXK_F4; break;
547 case GDK_F5: key_code = WXK_F5; break;
548 case GDK_F6: key_code = WXK_F6; break;
549 case GDK_F7: key_code = WXK_F7; break;
550 case GDK_F8: key_code = WXK_F8; break;
551 case GDK_F9: key_code = WXK_F9; break;
552 case GDK_F10: key_code = WXK_F10; break;
553 case GDK_F11: key_code = WXK_F11; break;
554 case GDK_F12: key_code = WXK_F12; break;
555 default:
556 {
557 if (keysym <= 0xFF)
558 {
559 key_code = keysym;
560 }
561 }
562 }
563
564 return (key_code);
565 }
566
567 //-----------------------------------------------------------------------------
568 // local code (see below)
569 //-----------------------------------------------------------------------------
570
571 #if (GTK_MINOR_VERSION > 0)
572
573 static void draw_frame( GtkWidget *widget, wxWindow *win )
574 {
575 if (!win->m_hasVMT)
576 return;
577
578 int dw = 0;
579 int dh = 0;
580
581 if (win->HasScrolling())
582 {
583 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(widget);
584 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(widget)->klass );
585
586 /*
587 GtkWidget *hscrollbar = scroll_window->hscrollbar;
588 GtkWidget *vscrollbar = scroll_window->vscrollbar;
589
590 we use this instead: range.slider_width = 11 + 2*2pts edge
591 */
592
593 if (scroll_window->vscrollbar_visible)
594 {
595 dw += 15; /* dw += vscrollbar->allocation.width; */
596 dw += scroll_class->scrollbar_spacing;
597 }
598
599 if (scroll_window->hscrollbar_visible)
600 {
601 dh += 15; /* dh += hscrollbar->allocation.height; */
602 dh += scroll_class->scrollbar_spacing;
603 }
604 }
605
606 int dx = 0;
607 int dy = 0;
608 if (GTK_WIDGET_NO_WINDOW (widget))
609 {
610 dx += widget->allocation.x;
611 dy += widget->allocation.y;
612 }
613
614 if (win->HasFlag(wxRAISED_BORDER))
615 {
616 gtk_draw_shadow( widget->style,
617 widget->window,
618 GTK_STATE_NORMAL,
619 GTK_SHADOW_OUT,
620 dx, dy,
621 win->m_width-dw, win->m_height-dh );
622 return;
623 }
624
625 if (win->HasFlag(wxSUNKEN_BORDER))
626 {
627 gtk_draw_shadow( widget->style,
628 widget->window,
629 GTK_STATE_NORMAL,
630 GTK_SHADOW_IN,
631 dx, dy,
632 win->m_width-dw, win->m_height-dh );
633 return;
634 }
635 }
636
637 //-----------------------------------------------------------------------------
638 // "expose_event" of m_widget
639 //-----------------------------------------------------------------------------
640
641 static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxWindow *win )
642 {
643 if (gdk_event->count > 0) return;
644 draw_frame( widget, win );
645 }
646
647 //-----------------------------------------------------------------------------
648 // "draw" of m_wxwindow
649 //-----------------------------------------------------------------------------
650
651 static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxWindow *win )
652 {
653 draw_frame( widget, win );
654 }
655
656 #endif // GTK_MINOR_VERSION > 0
657
658 //-----------------------------------------------------------------------------
659 // "expose_event" of m_wxwindow
660 //-----------------------------------------------------------------------------
661
662 static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxWindow *win )
663 {
664 if (!win->m_hasVMT)
665 return;
666
667 if (gdk_event->window != win->m_wxwindow->window)
668 return;
669
670 win->GetUpdateRegion().Union( gdk_event->area.x,
671 gdk_event->area.y,
672 gdk_event->area.width,
673 gdk_event->area.height );
674
675 if (gdk_event->count > 0)
676 return;
677
678 wxPaintEvent event( win->GetId() );
679 event.SetEventObject( win );
680 win->GetEventHandler()->ProcessEvent( event );
681
682 /*
683 wxPrintf( "OnExpose from " );
684 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
685 wxPrintf( win->GetClassInfo()->GetClassName() );
686 wxPrintf( " %d %d %d %d\n", (int)gdk_event->area.x,
687 (int)gdk_event->area.y,
688 (int)gdk_event->area.width,
689 (int)gdk_event->area.height );
690 */
691
692 win->GetUpdateRegion().Clear();
693 }
694
695 //-----------------------------------------------------------------------------
696 // "draw" of m_wxwindow
697 //-----------------------------------------------------------------------------
698
699 static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxWindow *win )
700 {
701 if (g_isIdle)
702 wxapp_install_idle_handler();
703
704 if (!win->m_hasVMT)
705 return;
706
707 win->GetUpdateRegion().Union( rect->x, rect->y,
708 rect->width, rect->height );
709
710 wxPaintEvent event( win->GetId() );
711 event.SetEventObject( win );
712
713 /*
714 wxPrintf( "OnDraw from " );
715 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
716 printf( win->GetClassInfo()->GetClassName() );
717 wxPrintf( " %d %d %d %d\n", (int)rect->x,
718 (int)rect->y,
719 (int)rect->width,
720 (int)rect->height );
721 */
722
723 win->GetEventHandler()->ProcessEvent( event );
724
725 win->GetUpdateRegion().Clear();
726 }
727
728 //-----------------------------------------------------------------------------
729 // "key_press_event" from any window
730 //-----------------------------------------------------------------------------
731
732 static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win )
733 {
734 if (g_isIdle)
735 wxapp_install_idle_handler();
736
737 if (!win->m_hasVMT) return FALSE;
738 if (g_blockEventsOnDrag) return FALSE;
739
740 /*
741 printf( "KeyDown-ScanCode is: %d.\n", gdk_event->keyval );
742 if (gdk_event->state & GDK_SHIFT_MASK)
743 printf( "ShiftDown.\n" );
744 else
745 printf( "ShiftUp.\n" );
746 if (gdk_event->state & GDK_CONTROL_MASK)
747 printf( "ControlDown.\n" );
748 else
749 printf( "ControlUp.\n" );
750 printf( "\n" );
751 */
752 int x = 0;
753 int y = 0;
754 GdkModifierType state;
755 if (gdk_event->window) gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
756
757 long key_code = map_to_unmodified_wx_keysym( gdk_event->keyval );
758
759 /* sending unknown key events doesn't really make sense */
760 if (key_code == 0) return FALSE;
761
762 bool ret = FALSE;
763
764 wxKeyEvent event( wxEVT_KEY_DOWN );
765 event.SetTimestamp( gdk_event->time );
766 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
767 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
768 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
769 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
770 event.m_keyCode = key_code;
771 event.m_scanCode = gdk_event->keyval;
772 event.m_x = x;
773 event.m_y = y;
774 event.SetEventObject( win );
775 ret = win->GetEventHandler()->ProcessEvent( event );
776
777 key_code = map_to_wx_keysym( gdk_event->keyval );
778
779 #if wxUSE_ACCEL
780 if (!ret)
781 {
782 wxWindow *ancestor = win;
783 while (ancestor)
784 {
785 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
786 if (command != -1)
787 {
788 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
789 ret = ancestor->GetEventHandler()->ProcessEvent( command_event );
790 break;
791 }
792 ancestor = ancestor->GetParent();
793 }
794 }
795 #endif // wxUSE_ACCEL
796 /* wxMSW doesn't send char events with Alt pressed */
797 /* Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
798 will only be sent if it is not a menu accelerator. */
799 if ((key_code != 0) && ! ret )
800 {
801 wxKeyEvent event2( wxEVT_CHAR );
802 event2.SetTimestamp( gdk_event->time );
803 event2.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
804 event2.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
805 event2.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
806 event2.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
807 event2.m_keyCode = key_code;
808 event2.m_scanCode = gdk_event->keyval;
809 event2.m_x = x;
810 event2.m_y = y;
811 event2.SetEventObject( win );
812 ret = (ret || win->GetEventHandler()->ProcessEvent( event2 ));
813 }
814
815
816 /* win is a control: tab can be propagated up */
817 if ( (!ret) &&
818 ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab)) &&
819 (win->HasFlag(wxTE_PROCESS_TAB) == 0))
820 {
821 wxNavigationKeyEvent new_event;
822 /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
823 new_event.SetDirection( (gdk_event->keyval == GDK_Tab) );
824 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
825 new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) );
826 new_event.SetCurrentFocus( win );
827 ret = win->GetEventHandler()->ProcessEvent( new_event );
828 }
829
830 /* generate wxID_CANCEL if <esc> has been pressed (typically in dialogs) */
831 if ( (!ret) &&
832 (gdk_event->keyval == GDK_Escape) )
833 {
834 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
835 new_event.SetEventObject( win );
836 ret = win->GetEventHandler()->ProcessEvent( new_event );
837 }
838
839 #if (GTK_MINOR_VERSION > 0)
840 /* pressing F10 will activate the menu bar of the top frame */
841 if ( (!ret) &&
842 (gdk_event->keyval == GDK_F10) )
843 {
844 wxWindow *ancestor = win;
845 while (ancestor)
846 {
847 if (wxIsKindOf(ancestor,wxFrame))
848 {
849 wxFrame *frame = (wxFrame*) ancestor;
850 wxMenuBar *menubar = frame->GetMenuBar();
851 if (menubar)
852 {
853 wxNode *node = menubar->GetMenus().First();
854 if (node)
855 {
856 // doesn't work correctly
857 // wxMenu *firstMenu = (wxMenu*) node->Data();
858 // gtk_menu_item_select( GTK_MENU_ITEM(firstMenu->m_owner) );
859 // ret = TRUE;
860 break;
861 }
862 }
863 }
864 ancestor = ancestor->GetParent();
865 }
866 }
867 #endif
868
869 /*
870 Damn, I forgot why this didn't work, but it didn't work.
871
872 // win is a panel: up can be propagated to the panel
873 if ((!ret) && (win->m_wxwindow) && (win->m_parent) && (win->m_parent->AcceptsFocus()) &&
874 (gdk_event->keyval == GDK_Up))
875 {
876 win->m_parent->SetFocus();
877 ret = TRUE;
878 }
879
880 // win is a panel: left/right can be propagated to the panel
881 if ((!ret) && (win->m_wxwindow) &&
882 ((gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Left) ||
883 (gdk_event->keyval == GDK_Up) || (gdk_event->keyval == GDK_Down)))
884 {
885 wxNavigationKeyEvent new_event;
886 new_event.SetDirection( (gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Down) );
887 new_event.SetCurrentFocus( win );
888 ret = win->GetEventHandler()->ProcessEvent( new_event );
889 }
890 */
891
892 if (ret)
893 {
894 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
895 return TRUE;
896 }
897
898 return FALSE;
899 }
900
901 //-----------------------------------------------------------------------------
902 // "key_release_event" from any window
903 //-----------------------------------------------------------------------------
904
905 static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win )
906 {
907 if (g_isIdle)
908 wxapp_install_idle_handler();
909
910 if (!win->m_hasVMT) return FALSE;
911 if (g_blockEventsOnDrag) return FALSE;
912
913 /*
914 printf( "KeyUp-ScanCode is: %d.\n", gdk_event->keyval );
915 if (gdk_event->state & GDK_SHIFT_MASK)
916 printf( "ShiftDown.\n" );
917 else
918 printf( "ShiftUp.\n" );
919 if (gdk_event->state & GDK_CONTROL_MASK)
920 printf( "ControlDown.\n" );
921 else
922 printf( "ControlUp.\n" );
923 printf( "\n" );
924 */
925
926 long key_code = map_to_unmodified_wx_keysym( gdk_event->keyval );
927
928 /* sending unknown key events doesn't really make sense */
929 if (key_code == 0) return FALSE;
930
931 int x = 0;
932 int y = 0;
933 GdkModifierType state;
934 if (gdk_event->window) gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
935
936 wxKeyEvent event( wxEVT_KEY_UP );
937 event.SetTimestamp( gdk_event->time );
938 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
939 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
940 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
941 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
942 event.m_keyCode = key_code;
943 event.m_scanCode = gdk_event->keyval;
944 event.m_x = x;
945 event.m_y = y;
946 event.SetEventObject( win );
947
948 if (win->GetEventHandler()->ProcessEvent( event ))
949 {
950 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_release_event" );
951 return TRUE;
952 }
953
954 return FALSE;
955 }
956
957 //-----------------------------------------------------------------------------
958 // "button_press_event"
959 //-----------------------------------------------------------------------------
960
961 static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
962 {
963 if (g_isIdle)
964 wxapp_install_idle_handler();
965
966 /*
967 wxPrintf( _T("1) OnButtonPress from ") );
968 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
969 wxPrintf( win->GetClassInfo()->GetClassName() );
970 wxPrintf( _T(".\n") );
971 */
972 if (!win->m_hasVMT) return FALSE;
973 if (g_blockEventsOnDrag) return TRUE;
974 if (g_blockEventsOnScroll) return TRUE;
975
976 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
977
978 if (win->m_wxwindow)
979 {
980 if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow) && !GTK_WIDGET_HAS_FOCUS (win->m_wxwindow) )
981 {
982 gtk_widget_grab_focus (win->m_wxwindow);
983
984 /*
985 wxPrintf( _T("GrabFocus from ") );
986 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
987 wxPrintf( win->GetClassInfo()->GetClassName() );
988 wxPrintf( _T(".\n") );
989 */
990
991 }
992 }
993
994 /*
995 wxPrintf( _T("2) OnButtonPress from ") );
996 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
997 wxPrintf( win->GetClassInfo()->GetClassName() );
998 wxPrintf( _T(".\n") );
999 */
1000
1001 wxEventType event_type = wxEVT_LEFT_DOWN;
1002
1003 if (gdk_event->button == 1)
1004 {
1005 switch (gdk_event->type)
1006 {
1007 case GDK_BUTTON_PRESS: event_type = wxEVT_LEFT_DOWN; break;
1008 case GDK_2BUTTON_PRESS: event_type = wxEVT_LEFT_DCLICK; break;
1009 default: break;
1010 }
1011 }
1012 else if (gdk_event->button == 2)
1013 {
1014 switch (gdk_event->type)
1015 {
1016 case GDK_BUTTON_PRESS: event_type = wxEVT_MIDDLE_DOWN; break;
1017 case GDK_2BUTTON_PRESS: event_type = wxEVT_MIDDLE_DCLICK; break;
1018 default: break;
1019 }
1020 }
1021 else if (gdk_event->button == 3)
1022 {
1023 switch (gdk_event->type)
1024 {
1025 case GDK_BUTTON_PRESS: event_type = wxEVT_RIGHT_DOWN; break;
1026 case GDK_2BUTTON_PRESS: event_type = wxEVT_RIGHT_DCLICK; break;
1027 default: break;
1028 }
1029 }
1030
1031 wxMouseEvent event( event_type );
1032 event.SetTimestamp( gdk_event->time );
1033 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
1034 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
1035 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
1036 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
1037 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
1038 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
1039 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
1040
1041 event.m_x = (long)gdk_event->x;
1042 event.m_y = (long)gdk_event->y;
1043
1044 // Some control don't have their own X window and thus cannot get
1045 // any events.
1046
1047 if (!g_captureWindow)
1048 {
1049 wxNode *node = win->GetChildren().First();
1050 while (node)
1051 {
1052 wxWindow *child = (wxWindow*)node->Data();
1053
1054 if (child->m_isStaticBox)
1055 {
1056 // wxStaticBox is transparent in the box itself
1057 int x = event.m_x;
1058 int y = event.m_y;
1059 int xx1 = child->m_x;
1060 int yy1 = child->m_y;
1061 int xx2 = child->m_x + child->m_width;
1062 int yy2 = child->m_x + child->m_height;
1063
1064 // left
1065 if (((x >= xx1) && (x <= xx1+10) && (y >= yy1) && (y <= yy2)) ||
1066 // right
1067 ((x >= xx2-10) && (x <= xx2) && (y >= yy1) && (y <= yy2)) ||
1068 // top
1069 ((x >= xx1) && (x <= xx2) && (y >= yy1) && (y <= yy1+10)) ||
1070 // bottom
1071 ((x >= xx1) && (x <= xx2) && (y >= yy2-1) && (y <= yy2)))
1072 {
1073 win = child;
1074 event.m_x -= child->m_x;
1075 event.m_y -= child->m_y;
1076 break;
1077 }
1078
1079 }
1080 else
1081 {
1082 if ((child->m_wxwindow == (GtkWidget*) NULL) &&
1083 (child->m_x <= event.m_x) &&
1084 (child->m_y <= event.m_y) &&
1085 (child->m_x+child->m_width >= event.m_x) &&
1086 (child->m_y+child->m_height >= event.m_y))
1087 {
1088 win = child;
1089 event.m_x -= child->m_x;
1090 event.m_y -= child->m_y;
1091 break;
1092 }
1093 }
1094 node = node->Next();
1095 }
1096 }
1097
1098 event.SetEventObject( win );
1099
1100 gs_timeLastClick = gdk_event->time;
1101
1102 if (win->GetEventHandler()->ProcessEvent( event ))
1103 {
1104 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_press_event" );
1105 return TRUE;
1106 }
1107
1108 return FALSE;
1109 }
1110
1111 //-----------------------------------------------------------------------------
1112 // "button_release_event"
1113 //-----------------------------------------------------------------------------
1114
1115 static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
1116 {
1117 if (g_isIdle)
1118 wxapp_install_idle_handler();
1119
1120 if (!win->m_hasVMT) return FALSE;
1121 if (g_blockEventsOnDrag) return FALSE;
1122 if (g_blockEventsOnScroll) return FALSE;
1123
1124 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
1125
1126 /*
1127 printf( "OnButtonRelease from " );
1128 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1129 printf( win->GetClassInfo()->GetClassName() );
1130 printf( ".\n" );
1131 */
1132
1133 wxEventType event_type = wxEVT_NULL;
1134
1135 switch (gdk_event->button)
1136 {
1137 case 1: event_type = wxEVT_LEFT_UP; break;
1138 case 2: event_type = wxEVT_MIDDLE_UP; break;
1139 case 3: event_type = wxEVT_RIGHT_UP; break;
1140 }
1141
1142 wxMouseEvent event( event_type );
1143 event.SetTimestamp( gdk_event->time );
1144 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
1145 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
1146 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
1147 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
1148 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
1149 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
1150 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
1151 event.m_x = (long)gdk_event->x;
1152 event.m_y = (long)gdk_event->y;
1153
1154 // Some control don't have their own X window and thus cannot get
1155 // any events.
1156
1157 if (!g_captureWindow)
1158 {
1159 wxNode *node = win->GetChildren().First();
1160 while (node)
1161 {
1162 wxWindow *child = (wxWindow*)node->Data();
1163
1164 if (child->m_isStaticBox)
1165 {
1166 // wxStaticBox is transparent in the box itself
1167 int x = event.m_x;
1168 int y = event.m_y;
1169 int xx1 = child->m_x;
1170 int yy1 = child->m_y;
1171 int xx2 = child->m_x + child->m_width;
1172 int yy2 = child->m_x + child->m_height;
1173
1174 // left
1175 if (((x >= xx1) && (x <= xx1+10) && (y >= yy1) && (y <= yy2)) ||
1176 // right
1177 ((x >= xx2-10) && (x <= xx2) && (y >= yy1) && (y <= yy2)) ||
1178 // top
1179 ((x >= xx1) && (x <= xx2) && (y >= yy1) && (y <= yy1+10)) ||
1180 // bottom
1181 ((x >= xx1) && (x <= xx2) && (y >= yy2-1) && (y <= yy2)))
1182 {
1183 win = child;
1184 event.m_x -= child->m_x;
1185 event.m_y -= child->m_y;
1186 break;
1187 }
1188
1189 }
1190 else
1191 {
1192 if ((child->m_wxwindow == (GtkWidget*) NULL) &&
1193 (child->m_x <= event.m_x) &&
1194 (child->m_y <= event.m_y) &&
1195 (child->m_x+child->m_width >= event.m_x) &&
1196 (child->m_y+child->m_height >= event.m_y))
1197 {
1198 win = child;
1199 event.m_x -= child->m_x;
1200 event.m_y -= child->m_y;
1201 break;
1202 }
1203 }
1204 node = node->Next();
1205 }
1206 }
1207
1208 event.SetEventObject( win );
1209
1210 if (win->GetEventHandler()->ProcessEvent( event ))
1211 {
1212 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_release_event" );
1213 return TRUE;
1214 }
1215
1216 return FALSE;
1217 }
1218
1219 //-----------------------------------------------------------------------------
1220 // "motion_notify_event"
1221 //-----------------------------------------------------------------------------
1222
1223 static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxWindow *win )
1224 {
1225 if (g_isIdle)
1226 wxapp_install_idle_handler();
1227
1228 if (!win->m_hasVMT) return FALSE;
1229 if (g_blockEventsOnDrag) return FALSE;
1230 if (g_blockEventsOnScroll) return FALSE;
1231
1232 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
1233
1234 if (gdk_event->is_hint)
1235 {
1236 int x = 0;
1237 int y = 0;
1238 GdkModifierType state;
1239 gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
1240 gdk_event->x = x;
1241 gdk_event->y = y;
1242 gdk_event->state = state;
1243 }
1244
1245 /*
1246 printf( "OnMotion from " );
1247 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1248 printf( win->GetClassInfo()->GetClassName() );
1249 printf( ".\n" );
1250 */
1251
1252 wxMouseEvent event( wxEVT_MOTION );
1253 event.SetTimestamp( gdk_event->time );
1254 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
1255 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
1256 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
1257 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
1258 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
1259 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
1260 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
1261
1262 event.m_x = (long)gdk_event->x;
1263 event.m_y = (long)gdk_event->y;
1264
1265 // Some control don't have their own X window and thus cannot get
1266 // any events.
1267
1268 if (!g_captureWindow)
1269 {
1270 wxNode *node = win->GetChildren().First();
1271 while (node)
1272 {
1273 wxWindow *child = (wxWindow*)node->Data();
1274
1275 if (child->m_isStaticBox)
1276 {
1277 // wxStaticBox is transparent in the box itself
1278 int x = event.m_x;
1279 int y = event.m_y;
1280 int xx1 = child->m_x;
1281 int yy1 = child->m_y;
1282 int xx2 = child->m_x + child->m_width;
1283 int yy2 = child->m_x + child->m_height;
1284
1285 // left
1286 if (((x >= xx1) && (x <= xx1+10) && (y >= yy1) && (y <= yy2)) ||
1287 // right
1288 ((x >= xx2-10) && (x <= xx2) && (y >= yy1) && (y <= yy2)) ||
1289 // top
1290 ((x >= xx1) && (x <= xx2) && (y >= yy1) && (y <= yy1+10)) ||
1291 // bottom
1292 ((x >= xx1) && (x <= xx2) && (y >= yy2-1) && (y <= yy2)))
1293 {
1294 win = child;
1295 event.m_x -= child->m_x;
1296 event.m_y -= child->m_y;
1297 break;
1298 }
1299
1300 }
1301 else
1302 {
1303 if ((child->m_wxwindow == (GtkWidget*) NULL) &&
1304 (child->m_x <= event.m_x) &&
1305 (child->m_y <= event.m_y) &&
1306 (child->m_x+child->m_width >= event.m_x) &&
1307 (child->m_y+child->m_height >= event.m_y))
1308 {
1309 win = child;
1310 event.m_x -= child->m_x;
1311 event.m_y -= child->m_y;
1312 break;
1313 }
1314 }
1315 node = node->Next();
1316 }
1317 }
1318
1319 event.SetEventObject( win );
1320
1321 if (win->GetEventHandler()->ProcessEvent( event ))
1322 {
1323 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "motion_notify_event" );
1324 return TRUE;
1325 }
1326
1327 return FALSE;
1328 }
1329
1330 //-----------------------------------------------------------------------------
1331 // "focus_in_event"
1332 //-----------------------------------------------------------------------------
1333
1334 static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win )
1335 {
1336 if (g_isIdle)
1337 wxapp_install_idle_handler();
1338
1339 if (!win->m_hasVMT) return FALSE;
1340 if (g_blockEventsOnDrag) return FALSE;
1341
1342 g_focusWindow = win;
1343
1344 if (win->m_wxwindow)
1345 {
1346 if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow))
1347 {
1348 GTK_WIDGET_SET_FLAGS (win->m_wxwindow, GTK_HAS_FOCUS);
1349 /*
1350 printf( "SetFocus flag from " );
1351 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1352 printf( win->GetClassInfo()->GetClassName() );
1353 printf( ".\n" );
1354 */
1355 }
1356 }
1357
1358
1359 /*
1360 printf( "OnSetFocus from " );
1361 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1362 printf( win->GetClassInfo()->GetClassName() );
1363 printf( " " );
1364 printf( WXSTRINGCAST win->GetLabel() );
1365 printf( ".\n" );
1366 */
1367
1368 wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() );
1369 event.SetEventObject( win );
1370
1371 if (win->GetEventHandler()->ProcessEvent( event ))
1372 {
1373 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_in_event" );
1374 return TRUE;
1375 }
1376
1377 return FALSE;
1378 }
1379
1380 //-----------------------------------------------------------------------------
1381 // "focus_out_event"
1382 //-----------------------------------------------------------------------------
1383
1384 static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win )
1385 {
1386 if (g_isIdle)
1387 wxapp_install_idle_handler();
1388
1389 if (!win->m_hasVMT) return FALSE;
1390 if (g_blockEventsOnDrag) return FALSE;
1391
1392 if (win->m_wxwindow)
1393 {
1394 if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow))
1395 GTK_WIDGET_UNSET_FLAGS (win->m_wxwindow, GTK_HAS_FOCUS);
1396 }
1397
1398 /*
1399 printf( "OnKillFocus from " );
1400 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1401 printf( win->GetClassInfo()->GetClassName() );
1402 printf( ".\n" );
1403 */
1404
1405 wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() );
1406 event.SetEventObject( win );
1407
1408 if (win->GetEventHandler()->ProcessEvent( event ))
1409 {
1410 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_out_event" );
1411 return TRUE;
1412 }
1413
1414 return FALSE;
1415 }
1416
1417 //-----------------------------------------------------------------------------
1418 // "enter_notify_event"
1419 //-----------------------------------------------------------------------------
1420
1421 static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win )
1422 {
1423 if (g_isIdle)
1424 wxapp_install_idle_handler();
1425
1426 if (!win->m_hasVMT) return FALSE;
1427 if (g_blockEventsOnDrag) return FALSE;
1428
1429 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
1430
1431 wxMouseEvent event( wxEVT_ENTER_WINDOW );
1432 #if (GTK_MINOR_VERSION > 0)
1433 event.SetTimestamp( gdk_event->time );
1434 #endif
1435 event.SetEventObject( win );
1436
1437 int x = 0;
1438 int y = 0;
1439 GdkModifierType state = (GdkModifierType)0;
1440
1441 gdk_window_get_pointer( widget->window, &x, &y, &state );
1442
1443 event.m_shiftDown = (state & GDK_SHIFT_MASK);
1444 event.m_controlDown = (state & GDK_CONTROL_MASK);
1445 event.m_altDown = (state & GDK_MOD1_MASK);
1446 event.m_metaDown = (state & GDK_MOD2_MASK);
1447 event.m_leftDown = (state & GDK_BUTTON1_MASK);
1448 event.m_middleDown = (state & GDK_BUTTON2_MASK);
1449 event.m_rightDown = (state & GDK_BUTTON3_MASK);
1450
1451 event.m_x = (long)x;
1452 event.m_y = (long)y;
1453
1454 if (win->GetEventHandler()->ProcessEvent( event ))
1455 {
1456 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "enter_notify_event" );
1457 return TRUE;
1458 }
1459
1460 return FALSE;
1461 }
1462
1463 //-----------------------------------------------------------------------------
1464 // "leave_notify_event"
1465 //-----------------------------------------------------------------------------
1466
1467 static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win )
1468 {
1469 if (g_isIdle)
1470 wxapp_install_idle_handler();
1471
1472 if (!win->m_hasVMT) return FALSE;
1473 if (g_blockEventsOnDrag) return FALSE;
1474
1475 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
1476
1477 wxMouseEvent event( wxEVT_LEAVE_WINDOW );
1478 #if (GTK_MINOR_VERSION > 0)
1479 event.SetTimestamp( gdk_event->time );
1480 #endif
1481 event.SetEventObject( win );
1482
1483 int x = 0;
1484 int y = 0;
1485 GdkModifierType state = (GdkModifierType)0;
1486
1487 gdk_window_get_pointer( widget->window, &x, &y, &state );
1488
1489 event.m_shiftDown = (state & GDK_SHIFT_MASK);
1490 event.m_controlDown = (state & GDK_CONTROL_MASK);
1491 event.m_altDown = (state & GDK_MOD1_MASK);
1492 event.m_metaDown = (state & GDK_MOD2_MASK);
1493 event.m_leftDown = (state & GDK_BUTTON1_MASK);
1494 event.m_middleDown = (state & GDK_BUTTON2_MASK);
1495 event.m_rightDown = (state & GDK_BUTTON3_MASK);
1496
1497 event.m_x = (long)x;
1498 event.m_y = (long)y;
1499
1500 if (win->GetEventHandler()->ProcessEvent( event ))
1501 {
1502 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "leave_notify_event" );
1503 return TRUE;
1504 }
1505
1506 return FALSE;
1507 }
1508
1509 //-----------------------------------------------------------------------------
1510 // "value_changed" from m_vAdjust
1511 //-----------------------------------------------------------------------------
1512
1513 static void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
1514 {
1515 if (g_isIdle)
1516 wxapp_install_idle_handler();
1517
1518 if (g_blockEventsOnDrag) return;
1519
1520 if (!win->m_hasVMT) return;
1521
1522 float diff = win->m_vAdjust->value - win->m_oldVerticalPos;
1523 if (fabs(diff) < 0.2) return;
1524 win->m_oldVerticalPos = win->m_vAdjust->value;
1525
1526 wxEventType command = wxEVT_NULL;
1527
1528 float line_step = win->m_vAdjust->step_increment;
1529 float page_step = win->m_vAdjust->page_increment;
1530
1531 if (win->IsScrolling())
1532 {
1533 command = wxEVT_SCROLLWIN_THUMBTRACK;
1534 }
1535 else
1536 {
1537 if (fabs(win->m_vAdjust->value-win->m_vAdjust->lower) < 0.2) command = wxEVT_SCROLLWIN_BOTTOM;
1538 else if (fabs(win->m_vAdjust->value-win->m_vAdjust->upper) < 0.2) command = wxEVT_SCROLLWIN_TOP;
1539 else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLLWIN_LINEDOWN;
1540 else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLLWIN_LINEUP;
1541 else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLLWIN_PAGEDOWN;
1542 else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLLWIN_PAGEUP;
1543 else command = wxEVT_SCROLLWIN_THUMBTRACK;
1544 }
1545
1546 int value = (int)(win->m_vAdjust->value+0.5);
1547
1548 wxScrollWinEvent event( command, value, wxVERTICAL );
1549 event.SetEventObject( win );
1550 win->GetEventHandler()->ProcessEvent( event );
1551 }
1552
1553 //-----------------------------------------------------------------------------
1554 // "value_changed" from m_hAdjust
1555 //-----------------------------------------------------------------------------
1556
1557 static void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
1558 {
1559 if (g_isIdle)
1560 wxapp_install_idle_handler();
1561
1562 if (g_blockEventsOnDrag) return;
1563 if (!win->m_hasVMT) return;
1564
1565 float diff = win->m_hAdjust->value - win->m_oldHorizontalPos;
1566 if (fabs(diff) < 0.2) return;
1567 win->m_oldHorizontalPos = win->m_hAdjust->value;
1568
1569 wxEventType command = wxEVT_NULL;
1570
1571 float line_step = win->m_hAdjust->step_increment;
1572 float page_step = win->m_hAdjust->page_increment;
1573
1574 if (win->IsScrolling())
1575 {
1576 command = wxEVT_SCROLLWIN_THUMBTRACK;
1577 }
1578 else
1579 {
1580 if (fabs(win->m_hAdjust->value-win->m_hAdjust->lower) < 0.2) command = wxEVT_SCROLLWIN_BOTTOM;
1581 else if (fabs(win->m_hAdjust->value-win->m_hAdjust->upper) < 0.2) command = wxEVT_SCROLLWIN_TOP;
1582 else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLLWIN_LINEDOWN;
1583 else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLLWIN_LINEUP;
1584 else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLLWIN_PAGEDOWN;
1585 else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLLWIN_PAGEUP;
1586 else command = wxEVT_SCROLLWIN_THUMBTRACK;
1587 }
1588
1589 int value = (int)(win->m_hAdjust->value+0.5);
1590
1591 wxScrollWinEvent event( command, value, wxHORIZONTAL );
1592 event.SetEventObject( win );
1593 win->GetEventHandler()->ProcessEvent( event );
1594 }
1595
1596 //-----------------------------------------------------------------------------
1597 // "changed" from m_vAdjust
1598 //-----------------------------------------------------------------------------
1599
1600 static void gtk_window_vscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
1601 {
1602 if (g_isIdle)
1603 wxapp_install_idle_handler();
1604
1605 if (g_blockEventsOnDrag) return;
1606 if (!win->m_hasVMT) return;
1607
1608 wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK;
1609 int value = (int)(win->m_vAdjust->value+0.5);
1610
1611 wxScrollWinEvent event( command, value, wxVERTICAL );
1612 event.SetEventObject( win );
1613 win->GetEventHandler()->ProcessEvent( event );
1614 }
1615
1616 //-----------------------------------------------------------------------------
1617 // "changed" from m_hAdjust
1618 //-----------------------------------------------------------------------------
1619
1620 static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
1621 {
1622 if (g_isIdle)
1623 wxapp_install_idle_handler();
1624
1625 if (g_blockEventsOnDrag) return;
1626 if (!win->m_hasVMT) return;
1627
1628 wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK;
1629 int value = (int)(win->m_hAdjust->value+0.5);
1630
1631 wxScrollWinEvent event( command, value, wxHORIZONTAL );
1632 event.SetEventObject( win );
1633 win->GetEventHandler()->ProcessEvent( event );
1634 }
1635
1636 //-----------------------------------------------------------------------------
1637 // "button_press_event" from scrollbar
1638 //-----------------------------------------------------------------------------
1639
1640 static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget),
1641 GdkEventButton *WXUNUSED(gdk_event),
1642 wxWindow *win )
1643 {
1644 if (g_isIdle)
1645 wxapp_install_idle_handler();
1646
1647 // don't test here as we can release the mouse while being over
1648 // a different window then the slider
1649 //
1650 // if (gdk_event->window != widget->slider) return FALSE;
1651
1652 win->SetScrolling( TRUE );
1653
1654 return FALSE;
1655 }
1656
1657 //-----------------------------------------------------------------------------
1658 // "button_release_event" from scrollbar
1659 //-----------------------------------------------------------------------------
1660
1661 static gint gtk_scrollbar_button_release_callback( GtkRange *widget,
1662 GdkEventButton *WXUNUSED(gdk_event),
1663 wxWindow *win )
1664 {
1665
1666 // don't test here as we can release the mouse while being over
1667 // a different window then the slider
1668 //
1669 // if (gdk_event->window != widget->slider) return FALSE;
1670
1671 GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(win->m_widget);
1672
1673 if (widget == GTK_RANGE(scrolledWindow->vscrollbar))
1674 gtk_signal_emit_by_name( GTK_OBJECT(win->m_hAdjust), "value_changed" );
1675 else
1676 gtk_signal_emit_by_name( GTK_OBJECT(win->m_vAdjust), "value_changed" );
1677
1678 win->SetScrolling( FALSE );
1679
1680 return FALSE;
1681 }
1682
1683 // ----------------------------------------------------------------------------
1684 // this wxWindowBase function is implemented here (in platform-specific file)
1685 // because it is static and so couldn't be made virtual
1686 // ----------------------------------------------------------------------------
1687
1688 wxWindow *wxWindowBase::FindFocus()
1689 {
1690 return g_focusWindow;
1691 }
1692
1693 //-----------------------------------------------------------------------------
1694 // "realize" from m_widget
1695 //-----------------------------------------------------------------------------
1696
1697 /* we cannot set colours, fonts and cursors before the widget has
1698 been realized, so we do this directly after realization */
1699
1700 static gint
1701 gtk_window_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win )
1702 {
1703 if (g_isIdle)
1704 wxapp_install_idle_handler();
1705
1706 if (win->m_delayedFont)
1707 win->SetFont( win->GetFont() );
1708
1709 if (win->m_delayedBackgroundColour)
1710 win->SetBackgroundColour( win->GetBackgroundColour() );
1711
1712 if (win->m_delayedForegroundColour)
1713 win->SetForegroundColour( win->GetForegroundColour() );
1714
1715 win->SetCursor( win->GetCursor() );
1716
1717 wxWindowCreateEvent event( win );
1718 event.SetEventObject( win );
1719 win->GetEventHandler()->ProcessEvent( event );
1720
1721 return FALSE;
1722 }
1723
1724 //-----------------------------------------------------------------------------
1725 // InsertChild for wxWindow.
1726 //-----------------------------------------------------------------------------
1727
1728 /* Callback for wxWindow. This very strange beast has to be used because
1729 * C++ has no virtual methods in a constructor. We have to emulate a
1730 * virtual function here as wxNotebook requires a different way to insert
1731 * a child in it. I had opted for creating a wxNotebookPage window class
1732 * which would have made this superfluous (such in the MDI window system),
1733 * but no-one was listening to me... */
1734
1735 static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child )
1736 {
1737 gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow),
1738 GTK_WIDGET(child->m_widget),
1739 child->m_x,
1740 child->m_y,
1741 child->m_width,
1742 child->m_height );
1743
1744 if (parent->HasFlag(wxTAB_TRAVERSAL))
1745 {
1746 /* we now allow a window to get the focus as long as it
1747 doesn't have any children. */
1748 GTK_WIDGET_UNSET_FLAGS( parent->m_wxwindow, GTK_CAN_FOCUS );
1749 }
1750 }
1751
1752 //-----------------------------------------------------------------------------
1753 // global functions
1754 //-----------------------------------------------------------------------------
1755
1756 wxWindow* wxGetActiveWindow()
1757 {
1758 return g_focusWindow;
1759 }
1760
1761 //-----------------------------------------------------------------------------
1762 // wxWindow
1763 //-----------------------------------------------------------------------------
1764
1765 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
1766
1767 void wxWindow::Init()
1768 {
1769 // common init
1770 InitBase();
1771
1772 // GTK specific
1773 m_widget = (GtkWidget *) NULL;
1774 m_wxwindow = (GtkWidget *) NULL;
1775
1776 // position/size
1777 m_x = 0;
1778 m_y = 0;
1779 m_width = 0;
1780 m_height = 0;
1781
1782 m_sizeSet = FALSE;
1783 m_hasVMT = FALSE;
1784 m_needParent = TRUE;
1785 m_isBeingDeleted = FALSE;
1786
1787 m_hasScrolling = FALSE;
1788 m_isScrolling = FALSE;
1789
1790 m_hAdjust = (GtkAdjustment*) NULL;
1791 m_vAdjust = (GtkAdjustment*) NULL;
1792 m_oldHorizontalPos = 0.0;
1793 m_oldVerticalPos = 0.0;
1794
1795 m_resizing = FALSE;
1796 m_scrollGC = (GdkGC*) NULL;
1797 m_widgetStyle = (GtkStyle*) NULL;
1798
1799 m_insertCallback = (wxInsertChildFunction) NULL;
1800
1801 m_isStaticBox = FALSE;
1802 m_isRadioButton = FALSE;
1803 m_acceptsFocus = FALSE;
1804 }
1805
1806 wxWindow::wxWindow()
1807 {
1808 Init();
1809 }
1810
1811 wxWindow::wxWindow( wxWindow *parent, wxWindowID id,
1812 const wxPoint &pos, const wxSize &size,
1813 long style, const wxString &name )
1814 {
1815 Init();
1816
1817 Create( parent, id, pos, size, style, name );
1818 }
1819
1820 bool wxWindow::Create( wxWindow *parent, wxWindowID id,
1821 const wxPoint &pos, const wxSize &size,
1822 long style, const wxString &name )
1823 {
1824 if (!PreCreation( parent, pos, size ) ||
1825 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
1826 {
1827 wxFAIL_MSG( _T("wxWindow creation failed") );
1828 return FALSE;
1829 }
1830
1831 m_insertCallback = wxInsertChildInWindow;
1832
1833 m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
1834 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
1835
1836 #ifdef __WXDEBUG__
1837 debug_focus_in( m_widget, _T("wxWindow::m_widget"), name );
1838 #endif
1839
1840 GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget);
1841
1842 #ifdef __WXDEBUG__
1843 debug_focus_in( scrolledWindow->hscrollbar, _T("wxWindow::hsrcollbar"), name );
1844 debug_focus_in( scrolledWindow->vscrollbar, _T("wxWindow::vsrcollbar"), name );
1845 #endif
1846
1847 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
1848 scroll_class->scrollbar_spacing = 0;
1849
1850 gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1851
1852 m_hAdjust = gtk_range_get_adjustment( GTK_RANGE(scrolledWindow->hscrollbar) );
1853 m_vAdjust = gtk_range_get_adjustment( GTK_RANGE(scrolledWindow->vscrollbar) );
1854
1855 m_wxwindow = gtk_myfixed_new();
1856
1857 #ifdef __WXDEBUG__
1858 debug_focus_in( m_wxwindow, _T("wxWindow::m_wxwindow"), name );
1859 #endif
1860
1861 gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
1862
1863 #if (GTK_MINOR_VERSION > 0)
1864 GtkMyFixed *myfixed = GTK_MYFIXED(m_wxwindow);
1865
1866 if (HasFlag(wxRAISED_BORDER))
1867 {
1868 gtk_myfixed_set_shadow_type( myfixed, GTK_SHADOW_OUT );
1869 }
1870 else if (HasFlag(wxSUNKEN_BORDER))
1871 {
1872 gtk_myfixed_set_shadow_type( myfixed, GTK_SHADOW_IN );
1873 }
1874 else
1875 {
1876 gtk_myfixed_set_shadow_type( myfixed, GTK_SHADOW_NONE );
1877 }
1878 #else // GTK_MINOR_VERSION == 0
1879 GtkViewport *viewport = GTK_VIEWPORT(scrolledWindow->viewport);
1880
1881 if (HasFlag(wxRAISED_BORDER))
1882 {
1883 gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_OUT );
1884 }
1885 else if (HasFlag(wxSUNKEN_BORDER))
1886 {
1887 gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_IN );
1888 }
1889 else
1890 {
1891 gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE );
1892 }
1893 #endif // GTK_MINOR_VERSION
1894
1895 if (HasFlag(wxTAB_TRAVERSAL))
1896 {
1897 /* we now allow a window to get the focus as long as it
1898 doesn't have any children. */
1899 GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
1900 m_acceptsFocus = FALSE;
1901 }
1902 else
1903 {
1904 GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
1905 m_acceptsFocus = TRUE;
1906 }
1907
1908 #if (GTK_MINOR_VERSION == 0)
1909 // shut the viewport up
1910 gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
1911 gtk_viewport_set_vadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
1912 #endif // GTK_MINOR_VERSION == 0
1913
1914 // I _really_ don't want scrollbars in the beginning
1915 m_vAdjust->lower = 0.0;
1916 m_vAdjust->upper = 1.0;
1917 m_vAdjust->value = 0.0;
1918 m_vAdjust->step_increment = 1.0;
1919 m_vAdjust->page_increment = 1.0;
1920 m_vAdjust->page_size = 5.0;
1921 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
1922 m_hAdjust->lower = 0.0;
1923 m_hAdjust->upper = 1.0;
1924 m_hAdjust->value = 0.0;
1925 m_hAdjust->step_increment = 1.0;
1926 m_hAdjust->page_increment = 1.0;
1927 m_hAdjust->page_size = 5.0;
1928 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
1929
1930 // these handlers block mouse events to any window during scrolling such as
1931 // motion events and prevent GTK and wxWindows from fighting over where the
1932 // slider should be
1933
1934 gtk_signal_connect( GTK_OBJECT(scrolledWindow->vscrollbar), "button_press_event",
1935 (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this );
1936
1937 gtk_signal_connect( GTK_OBJECT(scrolledWindow->hscrollbar), "button_press_event",
1938 (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this );
1939
1940 gtk_signal_connect( GTK_OBJECT(scrolledWindow->vscrollbar), "button_release_event",
1941 (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this );
1942
1943 gtk_signal_connect( GTK_OBJECT(scrolledWindow->hscrollbar), "button_release_event",
1944 (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this );
1945
1946 // these handlers get notified when screen updates are required either when
1947 // scrolling or when the window size (and therefore scrollbar configuration)
1948 // has changed
1949
1950 gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed",
1951 (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this );
1952 gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed",
1953 (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this );
1954
1955 gtk_signal_connect( GTK_OBJECT(m_hAdjust), "changed",
1956 (GtkSignalFunc) gtk_window_hscroll_change_callback, (gpointer) this );
1957 gtk_signal_connect(GTK_OBJECT(m_vAdjust), "changed",
1958 (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this );
1959
1960 gtk_widget_show( m_wxwindow );
1961
1962 if (m_parent)
1963 m_parent->DoAddChild( this );
1964
1965 PostCreation();
1966
1967 Show( TRUE );
1968
1969 return TRUE;
1970 }
1971
1972 wxWindow::~wxWindow()
1973 {
1974 m_isBeingDeleted = TRUE;
1975 m_hasVMT = FALSE;
1976
1977 if (m_widget)
1978 Show( FALSE );
1979
1980 DestroyChildren();
1981
1982 if (m_parent)
1983 m_parent->RemoveChild( this );
1984
1985 if (m_widgetStyle)
1986 {
1987 gtk_style_unref( m_widgetStyle );
1988 m_widgetStyle = (GtkStyle*) NULL;
1989 }
1990
1991 if (m_scrollGC)
1992 {
1993 gdk_gc_unref( m_scrollGC );
1994 m_scrollGC = (GdkGC*) NULL;
1995 }
1996
1997 if (m_wxwindow)
1998 {
1999 gtk_widget_destroy( m_wxwindow );
2000 m_wxwindow = (GtkWidget*) NULL;
2001 }
2002
2003 if (m_widget)
2004 {
2005 gtk_widget_destroy( m_widget );
2006 m_widget = (GtkWidget*) NULL;
2007 }
2008 }
2009
2010 bool wxWindow::PreCreation( wxWindow *parent, const wxPoint &pos, const wxSize &size )
2011 {
2012 wxCHECK_MSG( !m_needParent || parent, FALSE, _T("Need complete parent.") );
2013
2014 /* this turns -1 into 20 so that a minimal window is
2015 visible even although -1,-1 has been given as the
2016 size of the window. the same trick is used in other
2017 ports and should make debugging easier */
2018 m_width = WidthDefault(size.x);
2019 m_height = HeightDefault(size.y);
2020
2021 m_x = (int)pos.x;
2022 m_y = (int)pos.y;
2023
2024 /* some reasonable defaults */
2025 if (!parent)
2026 {
2027 if (m_x == -1)
2028 {
2029 m_x = (gdk_screen_width () - m_width) / 2;
2030 if (m_x < 10) m_x = 10;
2031 }
2032 if (m_y == -1)
2033 {
2034 m_y = (gdk_screen_height () - m_height) / 2;
2035 if (m_y < 10) m_y = 10;
2036 }
2037 }
2038
2039 return TRUE;
2040 }
2041
2042 void wxWindow::PostCreation()
2043 {
2044 wxASSERT_MSG( (m_widget != NULL), _T("invalid window") );
2045
2046 if (m_wxwindow)
2047 {
2048 /* these get reported to wxWindows -> wxPaintEvent */
2049 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event",
2050 GTK_SIGNAL_FUNC(gtk_window_expose_callback), (gpointer)this );
2051
2052 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw",
2053 GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this );
2054
2055 #if (GTK_MINOR_VERSION > 0)
2056 /* these are called when the "sunken" or "raised" borders are drawn */
2057 gtk_signal_connect( GTK_OBJECT(m_widget), "expose_event",
2058 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
2059
2060 gtk_signal_connect( GTK_OBJECT(m_widget), "draw",
2061 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
2062 #endif
2063 }
2064
2065 GtkWidget *connect_widget = GetConnectWidget();
2066
2067 ConnectWidget( connect_widget );
2068
2069 /* we cannot set colours, fonts and cursors before the widget has
2070 been realized, so we do this directly after realization */
2071 gtk_signal_connect( GTK_OBJECT(connect_widget), "realize",
2072 GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this );
2073
2074 m_hasVMT = TRUE;
2075 }
2076
2077 void wxWindow::ConnectWidget( GtkWidget *widget )
2078 {
2079 gtk_signal_connect( GTK_OBJECT(widget), "key_press_event",
2080 GTK_SIGNAL_FUNC(gtk_window_key_press_callback), (gpointer)this );
2081
2082 gtk_signal_connect( GTK_OBJECT(widget), "key_release_event",
2083 GTK_SIGNAL_FUNC(gtk_window_key_release_callback), (gpointer)this );
2084
2085 gtk_signal_connect( GTK_OBJECT(widget), "button_press_event",
2086 GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this );
2087
2088 gtk_signal_connect( GTK_OBJECT(widget), "button_release_event",
2089 GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
2090
2091 gtk_signal_connect( GTK_OBJECT(widget), "motion_notify_event",
2092 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
2093
2094 gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event",
2095 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
2096
2097 gtk_signal_connect( GTK_OBJECT(widget), "focus_out_event",
2098 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
2099
2100 gtk_signal_connect( GTK_OBJECT(widget), "enter_notify_event",
2101 GTK_SIGNAL_FUNC(gtk_window_enter_callback), (gpointer)this );
2102
2103 gtk_signal_connect( GTK_OBJECT(widget), "leave_notify_event",
2104 GTK_SIGNAL_FUNC(gtk_window_leave_callback), (gpointer)this );
2105 }
2106
2107 bool wxWindow::Destroy()
2108 {
2109 wxASSERT_MSG( (m_widget != NULL), _T("invalid window") );
2110
2111 m_hasVMT = FALSE;
2112
2113 return wxWindowBase::Destroy();
2114 }
2115
2116 void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
2117 {
2118 wxASSERT_MSG( (m_widget != NULL), _T("invalid window") );
2119 wxASSERT_MSG( (m_parent != NULL), _T("wxWindow::SetSize requires parent.\n") );
2120
2121 if (m_resizing) return; /* I don't like recursions */
2122 m_resizing = TRUE;
2123
2124 if (m_parent->m_wxwindow == NULL) /* i.e. wxNotebook */
2125 {
2126 /* don't set the size for children of wxNotebook, just take the values. */
2127 m_x = x;
2128 m_y = y;
2129 m_width = width;
2130 m_height = height;
2131 }
2132 else
2133 {
2134 if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0)
2135 {
2136 if (x != -1) m_x = x;
2137 if (y != -1) m_y = y;
2138 if (width != -1) m_width = width;
2139 if (height != -1) m_height = height;
2140 }
2141 else
2142 {
2143 m_x = x;
2144 m_y = y;
2145 m_width = width;
2146 m_height = height;
2147 }
2148
2149 if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH)
2150 {
2151 if (width == -1) m_width = 80;
2152 }
2153
2154 if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT)
2155 {
2156 if (height == -1) m_height = 26;
2157 }
2158
2159 if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
2160 if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
2161 if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth;
2162 if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight;
2163
2164 int border = 0;
2165 int bottom_border = 0;
2166
2167 if (GTK_WIDGET_CAN_DEFAULT(m_widget))
2168 {
2169 /* the default button has a border around it */
2170 border = 6;
2171 bottom_border = 5;
2172 }
2173
2174 /* this is the result of hours of debugging: the following code
2175 means that if we have a m_wxwindow and we set the size of
2176 m_widget, m_widget (which is a GtkScrolledWindow) does NOT
2177 automatically propagate its size down to its m_wxwindow,
2178 which is its client area. therefore, we have to tell the
2179 client area directly that it has to resize itself.
2180 this will lead to that m_widget (GtkScrolledWindow) will
2181 calculate how much size it needs for scrollbars etc and
2182 it will then call XXX_size_allocate of its child, which
2183 is m_wxwindow. m_wxwindow in turn will do the same with its
2184 children and so on. problems can arise if this happens
2185 before all the children have been realized as some widgets
2186 stupidy need to be realized during XXX_size_allocate (e.g.
2187 GtkNotebook) and they will segv if called otherwise. this
2188 emergency is tested in gtk_myfixed_size_allocate. Normally
2189 this shouldn't be needed and only gtk_widget_queue_resize()
2190 should be enough to provoke a resize at the next appropriate
2191 moment, but this seems to fail, e.g. when a wxNotebook contains
2192 a wxSplitterWindow: the splitter window's children won't
2193 show up properly resized then. */
2194
2195 gtk_myfixed_set_size( GTK_MYFIXED(m_parent->m_wxwindow),
2196 m_widget,
2197 m_x-border,
2198 m_y-border,
2199 m_width+2*border,
2200 m_height+border+bottom_border );
2201 }
2202
2203 m_sizeSet = TRUE;
2204
2205 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
2206 event.SetEventObject( this );
2207 GetEventHandler()->ProcessEvent( event );
2208
2209 m_resizing = FALSE;
2210 }
2211
2212 void wxWindow::OnInternalIdle()
2213 {
2214 wxCursor cursor = m_cursor;
2215 if (g_globalCursor.Ok()) cursor = g_globalCursor;
2216
2217 if (cursor.Ok() && m_currentGdkCursor != cursor)
2218 {
2219 m_currentGdkCursor = cursor;
2220
2221 if (m_wxwindow)
2222 {
2223 GdkWindow *window = m_wxwindow->window;
2224 if (window)
2225 gdk_window_set_cursor( window, cursor.GetCursor() );
2226
2227 if (!g_globalCursor.Ok())
2228 cursor = *wxSTANDARD_CURSOR;
2229
2230 window = m_widget->window;
2231 if (window)
2232 gdk_window_set_cursor( window, cursor.GetCursor() );
2233 }
2234 else
2235 {
2236 GdkWindow *window = m_widget->window;
2237 if (window)
2238 gdk_window_set_cursor( window, cursor.GetCursor() );
2239 }
2240 }
2241
2242 UpdateWindowUI();
2243 }
2244
2245 void wxWindow::DoGetSize( int *width, int *height ) const
2246 {
2247 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2248
2249 if (width) (*width) = m_width;
2250 if (height) (*height) = m_height;
2251 }
2252
2253 void wxWindow::DoSetClientSize( int width, int height )
2254 {
2255 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2256
2257 if (!m_wxwindow)
2258 {
2259 SetSize( width, height );
2260 }
2261 else
2262 {
2263 int dw = 0;
2264 int dh = 0;
2265
2266 #if (GTK_MINOR_VERSION == 0)
2267 if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
2268 {
2269 if (HasScrolling())
2270 {
2271 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
2272 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
2273
2274 GtkWidget *viewport = scroll_window->viewport;
2275 GtkStyleClass *viewport_class = viewport->style->klass;
2276
2277 dw += 2 * viewport_class->xthickness;
2278 dh += 2 * viewport_class->ythickness;
2279 }
2280 }
2281 #else
2282 if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
2283 {
2284 /* when using GTK 1.2 we set the border size to 2 */
2285 dw += 2 * 2;
2286 dh += 2 * 2;
2287 }
2288 #endif
2289
2290 if (HasScrolling())
2291 {
2292 /*
2293 GtkWidget *hscrollbar = scroll_window->hscrollbar;
2294 GtkWidget *vscrollbar = scroll_window->vscrollbar;
2295
2296 we use this instead: range.slider_width = 11 + 2*2pts edge
2297 */
2298
2299 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
2300 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
2301
2302 if (scroll_window->vscrollbar_visible)
2303 {
2304 dw += 15; /* dw += vscrollbar->allocation.width; */
2305 dw += scroll_class->scrollbar_spacing;
2306 }
2307
2308 if (scroll_window->hscrollbar_visible)
2309 {
2310 dh += 15; /* dh += hscrollbar->allocation.height; */
2311 dh += scroll_class->scrollbar_spacing;
2312 }
2313 }
2314
2315 SetSize( width+dw, height+dh );
2316 }
2317 }
2318
2319 void wxWindow::DoGetClientSize( int *width, int *height ) const
2320 {
2321 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2322
2323 if (!m_wxwindow)
2324 {
2325 if (width) (*width) = m_width;
2326 if (height) (*height) = m_height;
2327 }
2328 else
2329 {
2330 int dw = 0;
2331 int dh = 0;
2332
2333 #if (GTK_MINOR_VERSION == 0)
2334 if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
2335 {
2336 if (HasScrolling())
2337 {
2338 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
2339 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
2340
2341 GtkWidget *viewport = scroll_window->viewport;
2342 GtkStyleClass *viewport_class = viewport->style->klass;
2343
2344 dw += 2 * viewport_class->xthickness;
2345 dh += 2 * viewport_class->ythickness;
2346 }
2347 }
2348 #else
2349 if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
2350 {
2351 /* when using GTK 1.2 we set the border size to 2 */
2352 dw += 2 * 2;
2353 dh += 2 * 2;
2354 }
2355 #endif
2356 if (HasScrolling())
2357 {
2358 /*
2359 GtkWidget *hscrollbar = scroll_window->hscrollbar;
2360 GtkWidget *vscrollbar = scroll_window->vscrollbar;
2361
2362 we use this instead: range.slider_width = 11 + 2*2pts edge
2363 */
2364
2365 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
2366 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
2367
2368 if (scroll_window->vscrollbar_visible)
2369 {
2370 dw += 15; /* dw += vscrollbar->allocation.width; */
2371 dw += scroll_class->scrollbar_spacing;
2372 }
2373
2374 if (scroll_window->hscrollbar_visible)
2375 {
2376 dh += 15; /* dh += hscrollbar->allocation.height; */
2377 dh += scroll_class->scrollbar_spacing;
2378 }
2379 }
2380
2381 if (width) (*width) = m_width - dw;
2382 if (height) (*height) = m_height - dh;
2383 }
2384 }
2385
2386 void wxWindow::DoGetPosition( int *x, int *y ) const
2387 {
2388 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2389
2390 if (x) (*x) = m_x;
2391 if (y) (*y) = m_y;
2392 }
2393
2394 void wxWindow::DoClientToScreen( int *x, int *y ) const
2395 {
2396 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2397
2398 if (!m_widget->window) return;
2399
2400 GdkWindow *source = (GdkWindow *) NULL;
2401 if (m_wxwindow)
2402 source = m_wxwindow->window;
2403 else
2404 source = m_widget->window;
2405
2406 int org_x = 0;
2407 int org_y = 0;
2408 gdk_window_get_origin( source, &org_x, &org_y );
2409
2410 if (!m_wxwindow)
2411 {
2412 if (GTK_WIDGET_NO_WINDOW (m_widget))
2413 {
2414 org_x += m_widget->allocation.x;
2415 org_y += m_widget->allocation.y;
2416 }
2417 }
2418
2419 if (x) *x += org_x;
2420 if (y) *y += org_y;
2421 }
2422
2423 void wxWindow::DoScreenToClient( int *x, int *y ) const
2424 {
2425 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2426
2427 if (!m_widget->window) return;
2428
2429 GdkWindow *source = (GdkWindow *) NULL;
2430 if (m_wxwindow)
2431 source = m_wxwindow->window;
2432 else
2433 source = m_widget->window;
2434
2435 int org_x = 0;
2436 int org_y = 0;
2437 gdk_window_get_origin( source, &org_x, &org_y );
2438
2439 if (!m_wxwindow)
2440 {
2441 if (GTK_WIDGET_NO_WINDOW (m_widget))
2442 {
2443 org_x += m_widget->allocation.x;
2444 org_y += m_widget->allocation.y;
2445 }
2446 }
2447
2448 if (x) *x -= org_x;
2449 if (y) *y -= org_y;
2450 }
2451
2452 bool wxWindow::Show( bool show )
2453 {
2454 wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") );
2455
2456 if (!wxWindowBase::Show(show))
2457 {
2458 // nothing to do
2459 return FALSE;
2460 }
2461
2462 if (show)
2463 gtk_widget_show( m_widget );
2464 else
2465 gtk_widget_hide( m_widget );
2466
2467 return TRUE;
2468 }
2469
2470 bool wxWindow::Enable( bool enable )
2471 {
2472 wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") );
2473
2474 if (!wxWindowBase::Enable(enable))
2475 {
2476 // nothing to do
2477 return FALSE;
2478 }
2479
2480 gtk_widget_set_sensitive( m_widget, enable );
2481 if ( m_wxwindow )
2482 gtk_widget_set_sensitive( m_wxwindow, enable );
2483
2484 return TRUE;
2485 }
2486
2487 int wxWindow::GetCharHeight() const
2488 {
2489 wxCHECK_MSG( (m_widget != NULL), 12, _T("invalid window") );
2490
2491 wxCHECK_MSG( m_font.Ok(), 12, _T("invalid font") );
2492
2493 GdkFont *font = m_font.GetInternalFont( 1.0 );
2494
2495 return font->ascent + font->descent;
2496 }
2497
2498 int wxWindow::GetCharWidth() const
2499 {
2500 wxCHECK_MSG( (m_widget != NULL), 8, _T("invalid window") );
2501
2502 wxCHECK_MSG( m_font.Ok(), 8, _T("invalid font") );
2503
2504 GdkFont *font = m_font.GetInternalFont( 1.0 );
2505
2506 return gdk_string_width( font, "H" );
2507 }
2508
2509 void wxWindow::GetTextExtent( const wxString& string,
2510 int *x,
2511 int *y,
2512 int *descent,
2513 int *externalLeading,
2514 const wxFont *theFont ) const
2515 {
2516 wxFont fontToUse = m_font;
2517 if (theFont) fontToUse = *theFont;
2518
2519 wxCHECK_RET( fontToUse.Ok(), _T("invalid font") );
2520
2521 GdkFont *font = fontToUse.GetInternalFont( 1.0 );
2522 if (x) (*x) = gdk_string_width( font, string.mbc_str() );
2523 if (y) (*y) = font->ascent + font->descent;
2524 if (descent) (*descent) = font->descent;
2525 if (externalLeading) (*externalLeading) = 0; // ??
2526 }
2527
2528 void wxWindow::SetFocus()
2529 {
2530 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2531
2532 GtkWidget *connect_widget = GetConnectWidget();
2533 if (connect_widget)
2534 {
2535 if (GTK_WIDGET_CAN_FOCUS(connect_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ )
2536 {
2537 gtk_widget_grab_focus (connect_widget);
2538 }
2539 else if (GTK_IS_CONTAINER(connect_widget))
2540 {
2541 gtk_container_focus( GTK_CONTAINER(connect_widget), GTK_DIR_TAB_FORWARD );
2542 }
2543 else
2544 {
2545 }
2546 }
2547 }
2548
2549 bool wxWindow::AcceptsFocus() const
2550 {
2551 return m_acceptsFocus && wxWindowBase::AcceptsFocus();
2552 }
2553
2554 bool wxWindow::Reparent( wxWindow *newParent )
2555 {
2556 wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") );
2557
2558 wxWindow *oldParent = m_parent;
2559
2560 if ( !wxWindowBase::Reparent(newParent) )
2561 return FALSE;
2562
2563 if (oldParent)
2564 {
2565 gtk_container_remove( GTK_CONTAINER(oldParent->m_wxwindow), m_widget );
2566 }
2567
2568 if (newParent)
2569 {
2570 /* insert GTK representation */
2571 (*(newParent->m_insertCallback))(newParent, this);
2572 }
2573
2574 return TRUE;
2575 }
2576
2577 void wxWindow::DoAddChild(wxWindow *child)
2578 {
2579 wxASSERT_MSG( (m_widget != NULL), _T("invalid window") );
2580
2581 wxASSERT_MSG( (child != NULL), _T("invalid child window") );
2582
2583 wxASSERT_MSG( (m_insertCallback != NULL), _T("invalid child insertion function") );
2584
2585 /* add to list */
2586 AddChild( child );
2587
2588 /* insert GTK representation */
2589 (*m_insertCallback)(this, child);
2590 }
2591
2592 void wxWindow::Raise()
2593 {
2594 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2595
2596 if (!m_widget->window) return;
2597
2598 gdk_window_raise( m_widget->window );
2599 }
2600
2601 void wxWindow::Lower()
2602 {
2603 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2604
2605 if (!m_widget->window) return;
2606
2607 gdk_window_lower( m_widget->window );
2608 }
2609
2610 bool wxWindow::SetCursor( const wxCursor &cursor )
2611 {
2612 wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") );
2613
2614 if (!wxWindowBase::SetCursor(cursor))
2615 {
2616 // don't leave if the GTK widget has just
2617 // been realized
2618 if (!m_delayedCursor) return FALSE;
2619 }
2620
2621 GtkWidget *connect_widget = GetConnectWidget();
2622 if (!connect_widget->window)
2623 {
2624 // indicate that a new style has been set
2625 // but it couldn't get applied as the
2626 // widget hasn't been realized yet.
2627 m_delayedCursor = TRUE;
2628
2629 // pretend we have done something
2630 return TRUE;
2631 }
2632
2633 // gdk_window_set_cursor( connect_widget->window, GetCursor().GetCursor() );
2634
2635 // cursor was set
2636 return TRUE;
2637 }
2638
2639 void wxWindow::WarpPointer( int x, int y )
2640 {
2641 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2642
2643 GtkWidget *connect_widget = GetConnectWidget();
2644 if (connect_widget->window)
2645 {
2646 /* we provide this function ourselves as it is
2647 missing in GDK */
2648 gdk_window_warp_pointer( connect_widget->window, x, y );
2649 }
2650 }
2651
2652 void wxWindow::Refresh( bool eraseBackground, const wxRect *rect )
2653 {
2654 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2655
2656 if (!m_widget->window) return;
2657
2658 if (eraseBackground && m_wxwindow && m_wxwindow->window)
2659 {
2660 if (rect)
2661 {
2662 gdk_window_clear_area( m_wxwindow->window,
2663 rect->x, rect->y,
2664 rect->width, rect->height );
2665 }
2666 else
2667 {
2668 gdk_window_clear( m_wxwindow->window );
2669 }
2670 }
2671
2672 if (!rect)
2673 {
2674 if (m_wxwindow)
2675 gtk_widget_draw( m_wxwindow, (GdkRectangle*) NULL );
2676 else
2677 gtk_widget_draw( m_widget, (GdkRectangle*) NULL );
2678 }
2679 else
2680 {
2681 GdkRectangle gdk_rect;
2682 gdk_rect.x = rect->x;
2683 gdk_rect.y = rect->y;
2684 gdk_rect.width = rect->width;
2685 gdk_rect.height = rect->height;
2686
2687 if (m_wxwindow)
2688 gtk_widget_draw( m_wxwindow, &gdk_rect );
2689 else
2690 gtk_widget_draw( m_widget, &gdk_rect );
2691 }
2692 }
2693
2694 void wxWindow::Clear()
2695 {
2696 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
2697
2698 if (!m_widget->window) return;
2699
2700 if (m_wxwindow && m_wxwindow->window)
2701 {
2702 gdk_window_clear( m_wxwindow->window );
2703 }
2704 }
2705
2706 #if wxUSE_TOOLTIPS
2707 void wxWindow::DoSetToolTip( wxToolTip *tip )
2708 {
2709 wxWindowBase::DoSetToolTip(tip);
2710
2711 if (m_tooltip)
2712 m_tooltip->Apply( this );
2713 }
2714
2715 void wxWindow::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
2716 {
2717 gtk_tooltips_set_tip( tips, GetConnectWidget(), wxConvCurrent->cWX2MB(tip), (gchar*) NULL );
2718 }
2719 #endif // wxUSE_TOOLTIPS
2720
2721 bool wxWindow::SetBackgroundColour( const wxColour &colour )
2722 {
2723 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
2724
2725 if (!wxWindowBase::SetBackgroundColour(colour))
2726 {
2727 // don't leave if the GTK widget has just
2728 // been realized
2729 if (!m_delayedBackgroundColour) return FALSE;
2730 }
2731
2732 GtkWidget *connect_widget = GetConnectWidget();
2733 if (!connect_widget->window)
2734 {
2735 // indicate that a new style has been set
2736 // but it couldn't get applied as the
2737 // widget hasn't been realized yet.
2738 m_delayedBackgroundColour = TRUE;
2739
2740 // pretend we have done something
2741 return TRUE;
2742 }
2743
2744 if (m_wxwindow && m_wxwindow->window)
2745 {
2746 /* wxMSW doesn't clear the window here. I don't do that either to
2747 provide compatibility. call Clear() to do the job. */
2748
2749 m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_wxwindow->window ) );
2750 gdk_window_set_background( m_wxwindow->window, m_backgroundColour.GetColor() );
2751 }
2752
2753 wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
2754 if (sysbg == m_backgroundColour)
2755 {
2756 m_backgroundColour = wxNullColour;
2757 ApplyWidgetStyle();
2758 m_backgroundColour = sysbg;
2759 }
2760 else
2761 {
2762 ApplyWidgetStyle();
2763 }
2764
2765 return TRUE;
2766 }
2767
2768 bool wxWindow::SetForegroundColour( const wxColour &colour )
2769 {
2770 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
2771
2772 if (!wxWindowBase::SetForegroundColour(colour))
2773 {
2774 // don't leave if the GTK widget has just
2775 // been realized
2776 if (!m_delayedForegroundColour) return FALSE;
2777 }
2778
2779 GtkWidget *connect_widget = GetConnectWidget();
2780 if (!connect_widget->window)
2781 {
2782 // indicate that a new style has been set
2783 // but it couldn't get applied as the
2784 // widget hasn't been realized yet.
2785 m_delayedForegroundColour = TRUE;
2786
2787 // pretend we have done something
2788 return TRUE;
2789 }
2790
2791 wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
2792 if ( sysbg == m_backgroundColour )
2793 {
2794 m_backgroundColour = wxNullColour;
2795 ApplyWidgetStyle();
2796 m_backgroundColour = sysbg;
2797 }
2798 else
2799 {
2800 ApplyWidgetStyle();
2801 }
2802
2803 return TRUE;
2804 }
2805
2806 GtkStyle *wxWindow::GetWidgetStyle()
2807 {
2808 if (m_widgetStyle) gtk_style_unref( m_widgetStyle );
2809
2810 m_widgetStyle = gtk_style_copy( gtk_widget_get_style( m_widget ) );
2811
2812 return m_widgetStyle;
2813 }
2814
2815 void wxWindow::SetWidgetStyle()
2816 {
2817 GtkStyle *style = GetWidgetStyle();
2818
2819 gdk_font_unref( style->font );
2820 style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
2821
2822 if (m_foregroundColour.Ok())
2823 {
2824 m_foregroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
2825 style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor();
2826 style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor();
2827 style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor();
2828 }
2829
2830 if (m_backgroundColour.Ok())
2831 {
2832 m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
2833 style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
2834 style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
2835 style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
2836 style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
2837 style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
2838 style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
2839 style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
2840 style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
2841 }
2842 }
2843
2844 void wxWindow::ApplyWidgetStyle()
2845 {
2846 }
2847
2848 //-----------------------------------------------------------------------------
2849 // Pop-up menu stuff
2850 //-----------------------------------------------------------------------------
2851
2852 static void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting )
2853 {
2854 *is_waiting = FALSE;
2855 }
2856
2857 static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
2858 {
2859 menu->SetInvokingWindow( win );
2860 wxNode *node = menu->GetItems().First();
2861 while (node)
2862 {
2863 wxMenuItem *menuitem = (wxMenuItem*)node->Data();
2864 if (menuitem->IsSubMenu())
2865 {
2866 SetInvokingWindow( menuitem->GetSubMenu(), win );
2867 }
2868 node = node->Next();
2869 }
2870 }
2871
2872 static gint gs_pop_x = 0;
2873 static gint gs_pop_y = 0;
2874
2875 static void pop_pos_callback( GtkMenu * WXUNUSED(menu),
2876 gint *x, gint *y,
2877 wxWindow *win )
2878 {
2879 win->ClientToScreen( &gs_pop_x, &gs_pop_y );
2880 *x = gs_pop_x;
2881 *y = gs_pop_y;
2882 }
2883
2884 bool wxWindow::DoPopupMenu( wxMenu *menu, int x, int y )
2885 {
2886 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
2887
2888 wxCHECK_MSG( menu != NULL, FALSE, _T("invalid popup-menu") );
2889
2890 SetInvokingWindow( menu, this );
2891
2892 menu->UpdateUI();
2893
2894 gs_pop_x = x;
2895 gs_pop_y = y;
2896
2897 bool is_waiting = TRUE;
2898
2899 gtk_signal_connect( GTK_OBJECT(menu->m_menu), "hide",
2900 GTK_SIGNAL_FUNC(gtk_pop_hide_callback), (gpointer)&is_waiting );
2901
2902 gtk_menu_popup(
2903 GTK_MENU(menu->m_menu),
2904 (GtkWidget *) NULL, // parent menu shell
2905 (GtkWidget *) NULL, // parent menu item
2906 (GtkMenuPositionFunc) pop_pos_callback,
2907 (gpointer) this, // client data
2908 0, // button used to activate it
2909 0 //gs_timeLastClick // the time of activation
2910 );
2911
2912 while (is_waiting)
2913 {
2914 while (gtk_events_pending())
2915 gtk_main_iteration();
2916 }
2917
2918 return TRUE;
2919 }
2920
2921 #if wxUSE_DRAG_AND_DROP
2922
2923 void wxWindow::SetDropTarget( wxDropTarget *dropTarget )
2924 {
2925 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
2926
2927 GtkWidget *dnd_widget = GetConnectWidget();
2928
2929 if (m_dropTarget) m_dropTarget->UnregisterWidget( dnd_widget );
2930
2931 if (m_dropTarget) delete m_dropTarget;
2932 m_dropTarget = dropTarget;
2933
2934 if (m_dropTarget) m_dropTarget->RegisterWidget( dnd_widget );
2935 }
2936
2937 #endif // wxUSE_DRAG_AND_DROP
2938
2939 GtkWidget* wxWindow::GetConnectWidget()
2940 {
2941 GtkWidget *connect_widget = m_widget;
2942 if (m_wxwindow) connect_widget = m_wxwindow;
2943
2944 return connect_widget;
2945 }
2946
2947 bool wxWindow::IsOwnGtkWindow( GdkWindow *window )
2948 {
2949 if (m_wxwindow) return (window == m_wxwindow->window);
2950 return (window == m_widget->window);
2951 }
2952
2953 bool wxWindow::SetFont( const wxFont &font )
2954 {
2955 wxCHECK_MSG( m_widget != NULL, FALSE, _T( "invalid window") );
2956
2957 if (!wxWindowBase::SetFont(font))
2958 {
2959 // don't leave if the GTK widget has just
2960 // been realized
2961 if (!m_delayedFont) return FALSE;
2962 }
2963
2964 GtkWidget *connect_widget = GetConnectWidget();
2965 if (!connect_widget->window)
2966 {
2967 // indicate that a new style has been set
2968 // but it couldn't get applied as the
2969 // widget hasn't been realized yet.
2970 m_delayedFont = TRUE;
2971
2972 // pretend we have done something
2973 return TRUE;
2974 }
2975
2976 wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
2977 if ( sysbg == m_backgroundColour )
2978 {
2979 m_backgroundColour = wxNullColour;
2980 ApplyWidgetStyle();
2981 m_backgroundColour = sysbg;
2982 }
2983 else
2984 {
2985 ApplyWidgetStyle();
2986 }
2987
2988 return TRUE;
2989 }
2990
2991 void wxWindow::CaptureMouse()
2992 {
2993 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
2994
2995 wxCHECK_RET( g_captureWindow == NULL, _T("CaptureMouse called twice") );
2996
2997 GtkWidget *connect_widget = GetConnectWidget();
2998 if (!connect_widget->window) return;
2999
3000 gdk_pointer_grab( connect_widget->window, FALSE,
3001 (GdkEventMask)
3002 (GDK_BUTTON_PRESS_MASK |
3003 GDK_BUTTON_RELEASE_MASK |
3004 GDK_POINTER_MOTION_MASK),
3005 (GdkWindow *) NULL,
3006 m_cursor.GetCursor(),
3007 GDK_CURRENT_TIME );
3008 g_captureWindow = this;
3009 }
3010
3011 void wxWindow::ReleaseMouse()
3012 {
3013 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3014
3015 wxCHECK_RET( g_captureWindow, _T("ReleaseMouse called twice") );
3016
3017 GtkWidget *connect_widget = GetConnectWidget();
3018 if (!connect_widget->window) return;
3019
3020 gdk_pointer_ungrab ( GDK_CURRENT_TIME );
3021 g_captureWindow = (wxWindow*) NULL;
3022 }
3023
3024 bool wxWindow::IsRetained() const
3025 {
3026 return FALSE;
3027 }
3028
3029 void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible,
3030 int range, bool refresh )
3031 {
3032 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3033
3034 wxCHECK_RET( m_wxwindow != NULL, _T("window needs client area for scrolling") );
3035
3036 m_hasScrolling = TRUE;
3037
3038 if (orient == wxHORIZONTAL)
3039 {
3040 float fpos = (float)pos;
3041 float frange = (float)range;
3042 float fthumb = (float)thumbVisible;
3043 if (fpos > frange-fthumb) fpos = frange-fthumb;
3044 if (fpos < 0.0) fpos = 0.0;
3045
3046 if ((fabs(frange-m_hAdjust->upper) < 0.2) &&
3047 (fabs(fthumb-m_hAdjust->page_size) < 0.2))
3048 {
3049 SetScrollPos( orient, pos, refresh );
3050 return;
3051 }
3052
3053 m_oldHorizontalPos = fpos;
3054
3055 m_hAdjust->lower = 0.0;
3056 m_hAdjust->upper = frange;
3057 m_hAdjust->value = fpos;
3058 m_hAdjust->step_increment = 1.0;
3059 m_hAdjust->page_increment = (float)(wxMax(fthumb,0));
3060 m_hAdjust->page_size = fthumb;
3061 }
3062 else
3063 {
3064 float fpos = (float)pos;
3065 float frange = (float)range;
3066 float fthumb = (float)thumbVisible;
3067 if (fpos > frange-fthumb) fpos = frange-fthumb;
3068 if (fpos < 0.0) fpos = 0.0;
3069
3070 if ((fabs(frange-m_vAdjust->upper) < 0.2) &&
3071 (fabs(fthumb-m_vAdjust->page_size) < 0.2))
3072 {
3073 SetScrollPos( orient, pos, refresh );
3074 return;
3075 }
3076
3077 m_oldVerticalPos = fpos;
3078
3079 m_vAdjust->lower = 0.0;
3080 m_vAdjust->upper = frange;
3081 m_vAdjust->value = fpos;
3082 m_vAdjust->step_increment = 1.0;
3083 m_vAdjust->page_increment = (float)(wxMax(fthumb,0));
3084 m_vAdjust->page_size = fthumb;
3085 }
3086
3087 if (orient == wxHORIZONTAL)
3088 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
3089 else
3090 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
3091 }
3092
3093 void wxWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) )
3094 {
3095 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3096
3097 wxCHECK_RET( m_wxwindow != NULL, _T("window needs client area for scrolling") );
3098
3099 if (orient == wxHORIZONTAL)
3100 {
3101 float fpos = (float)pos;
3102 if (fpos > m_hAdjust->upper - m_hAdjust->page_size) fpos = m_hAdjust->upper - m_hAdjust->page_size;
3103 if (fpos < 0.0) fpos = 0.0;
3104 m_oldHorizontalPos = fpos;
3105
3106 if (fabs(fpos-m_hAdjust->value) < 0.2) return;
3107 m_hAdjust->value = fpos;
3108 }
3109 else
3110 {
3111 float fpos = (float)pos;
3112 if (fpos > m_vAdjust->upper - m_vAdjust->page_size) fpos = m_vAdjust->upper - m_vAdjust->page_size;
3113 if (fpos < 0.0) fpos = 0.0;
3114 m_oldVerticalPos = fpos;
3115
3116 if (fabs(fpos-m_vAdjust->value) < 0.2) return;
3117 m_vAdjust->value = fpos;
3118 }
3119
3120 if (!m_isScrolling) /* prevent recursion */
3121 {
3122 if (m_wxwindow->window)
3123 {
3124 if (orient == wxHORIZONTAL)
3125 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" );
3126 else
3127 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" );
3128 }
3129 }
3130 }
3131
3132 int wxWindow::GetScrollThumb( int orient ) const
3133 {
3134 wxCHECK_MSG( m_widget != NULL, 0, _T("invalid window") );
3135
3136 wxCHECK_MSG( m_wxwindow != NULL, 0, _T("window needs client area for scrolling") );
3137
3138 if (orient == wxHORIZONTAL)
3139 return (int)(m_hAdjust->page_size+0.5);
3140 else
3141 return (int)(m_vAdjust->page_size+0.5);
3142 }
3143
3144 int wxWindow::GetScrollPos( int orient ) const
3145 {
3146 wxCHECK_MSG( m_widget != NULL, 0, _T("invalid window") );
3147
3148 wxCHECK_MSG( m_wxwindow != NULL, 0, _T("window needs client area for scrolling") );
3149
3150 if (orient == wxHORIZONTAL)
3151 return (int)(m_hAdjust->value+0.5);
3152 else
3153 return (int)(m_vAdjust->value+0.5);
3154 }
3155
3156 int wxWindow::GetScrollRange( int orient ) const
3157 {
3158 wxCHECK_MSG( m_widget != NULL, 0, _T("invalid window") );
3159
3160 wxCHECK_MSG( m_wxwindow != NULL, 0, _T("window needs client area for scrolling") );
3161
3162 if (orient == wxHORIZONTAL)
3163 return (int)(m_hAdjust->upper+0.5);
3164 else
3165 return (int)(m_vAdjust->upper+0.5);
3166 }
3167
3168 void wxWindow::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) )
3169 {
3170 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3171
3172 wxCHECK_RET( m_wxwindow != NULL, _T("window needs client area for scrolling") );
3173
3174 if (!m_scrollGC)
3175 {
3176 m_scrollGC = gdk_gc_new( m_wxwindow->window );
3177 gdk_gc_set_exposures( m_scrollGC, TRUE );
3178 }
3179
3180 wxNode *node = m_children.First();
3181 while (node)
3182 {
3183 wxWindow *child = (wxWindow*) node->Data();
3184 int sx = 0;
3185 int sy = 0;
3186 child->GetSize( &sx, &sy );
3187 child->SetSize( child->m_x + dx, child->m_y + dy, sx, sy, wxSIZE_ALLOW_MINUS_ONE );
3188 node = node->Next();
3189 }
3190
3191 int cw = 0;
3192 int ch = 0;
3193 GetClientSize( &cw, &ch );
3194 int w = cw - abs(dx);
3195 int h = ch - abs(dy);
3196
3197 if ((h < 0) || (w < 0))
3198 {
3199 Refresh();
3200 }
3201 else
3202 {
3203 int s_x = 0;
3204 int s_y = 0;
3205 if (dx < 0) s_x = -dx;
3206 if (dy < 0) s_y = -dy;
3207 int d_x = 0;
3208 int d_y = 0;
3209 if (dx > 0) d_x = dx;
3210 if (dy > 0) d_y = dy;
3211
3212 gdk_window_copy_area( m_wxwindow->window, m_scrollGC, d_x, d_y,
3213 m_wxwindow->window, s_x, s_y, w, h );
3214
3215 wxRect rect;
3216 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
3217 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
3218 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
3219 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
3220
3221 Refresh( TRUE, &rect );
3222 }
3223 }
3224
3225 void wxWindow::SetScrolling(bool scroll)
3226 {
3227 m_isScrolling = g_blockEventsOnScroll = scroll;
3228 }