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