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