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