]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/window.cpp
Blind fix for bug #1209944, wxFileConfig constructor corrupts the stack
[wxWidgets.git] / src / gtk1 / window.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: gtk/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#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
12 #pragma implementation "window.h"
13#endif
14
15// For compilers that support precompilation, includes "wx.h".
16#include "wx/wxprec.h"
17
18#ifdef __VMS
19#define XWarpPointer XWARPPOINTER
20#endif
21
22#include "wx/window.h"
23#include "wx/dcclient.h"
24#include "wx/frame.h"
25#include "wx/app.h"
26#include "wx/layout.h"
27#include "wx/utils.h"
28#include "wx/dialog.h"
29#include "wx/msgdlg.h"
30#include "wx/module.h"
31#include "wx/combobox.h"
32
33#if wxUSE_DRAG_AND_DROP
34 #include "wx/dnd.h"
35#endif
36
37#if wxUSE_TOOLTIPS
38 #include "wx/tooltip.h"
39#endif
40
41#if wxUSE_CARET
42 #include "wx/caret.h"
43#endif // wxUSE_CARET
44
45#if wxUSE_TEXTCTRL
46 #include "wx/textctrl.h"
47#endif
48
49#include "wx/menu.h"
50#include "wx/statusbr.h"
51#include "wx/intl.h"
52#include "wx/settings.h"
53#include "wx/log.h"
54#include "wx/fontutil.h"
55
56#ifdef __WXDEBUG__
57 #include "wx/thread.h"
58#endif
59
60#include "wx/math.h"
61#include <ctype.h>
62
63#include "wx/gtk/private.h"
64#include <gdk/gdkprivate.h>
65#include <gdk/gdkkeysyms.h>
66#include <gdk/gdkx.h>
67
68#include <gtk/gtk.h>
69#include <gtk/gtkprivate.h>
70
71#include "wx/gtk/win_gtk.h"
72
73#ifdef __WXGTK20__
74#include <pango/pangox.h>
75#endif
76
77
78#ifdef __WXGTK20__
79 #ifdef HAVE_XIM
80 #undef HAVE_XIM
81 #endif
82#endif
83
84#ifdef __WXGTK20__
85extern GtkContainerClass *pizza_parent_class;
86#endif
87
88//-----------------------------------------------------------------------------
89// documentation on internals
90//-----------------------------------------------------------------------------
91
92/*
93 I have been asked several times about writing some documentation about
94 the GTK port of wxWidgets, especially its internal structures. Obviously,
95 you cannot understand wxGTK without knowing a little about the GTK, but
96 some more information about what the wxWindow, which is the base class
97 for all other window classes, does seems required as well.
98
99 I)
100
101 What does wxWindow do? It contains the common interface for the following
102 jobs of its descendants:
103
104 1) Define the rudimentary behaviour common to all window classes, such as
105 resizing, intercepting user input (so as to make it possible to use these
106 events for special purposes in a derived class), window names etc.
107
108 2) Provide the possibility to contain and manage children, if the derived
109 class is allowed to contain children, which holds true for those window
110 classes which do not display a native GTK widget. To name them, these
111 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
112 work classes are a special case and are handled a bit differently from
113 the rest. The same holds true for the wxNotebook class.
114
115 3) Provide the possibility to draw into a client area of a window. This,
116 too, only holds true for classes that do not display a native GTK widget
117 as above.
118
119 4) Provide the entire mechanism for scrolling widgets. This actual inter-
120 face for this is usually in wxScrolledWindow, but the GTK implementation
121 is in this class.
122
123 5) A multitude of helper or extra methods for special purposes, such as
124 Drag'n'Drop, managing validators etc.
125
126 6) Display a border (sunken, raised, simple or none).
127
128 Normally one might expect, that one wxWidgets window would always correspond
129 to one GTK widget. Under GTK, there is no such allround widget that has all
130 the functionality. Moreover, the GTK defines a client area as a different
131 widget from the actual widget you are handling. Last but not least some
132 special classes (e.g. wxFrame) handle different categories of widgets and
133 still have the possibility to draw something in the client area.
134 It was therefore required to write a special purpose GTK widget, that would
135 represent a client area in the sense of wxWidgets capable to do the jobs
136 2), 3) and 4). I have written this class and it resides in win_gtk.c of
137 this directory.
138
139 All windows must have a widget, with which they interact with other under-
140 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
141 thw wxWindow class has a member variable called m_widget which holds a
142 pointer to this widget. When the window class represents a GTK native widget,
143 this is (in most cases) the only GTK widget the class manages. E.g. the
144 wxStaticText class handles only a GtkLabel widget a pointer to which you
145 can find in m_widget (defined in wxWindow)
146
147 When the class has a client area for drawing into and for containing children
148 it has to handle the client area widget (of the type GtkPizza, defined in
149 win_gtk.c), but there could be any number of widgets, handled by a class
150 The common rule for all windows is only, that the widget that interacts with
151 the rest of GTK must be referenced in m_widget and all other widgets must be
152 children of this widget on the GTK level. The top-most widget, which also
153 represents the client area, must be in the m_wxwindow field and must be of
154 the type GtkPizza.
155
156 As I said, the window classes that display a GTK native widget only have
157 one widget, so in the case of e.g. the wxButton class m_widget holds a
158 pointer to a GtkButton widget. But windows with client areas (for drawing
159 and children) have a m_widget field that is a pointer to a GtkScrolled-
160 Window and a m_wxwindow field that is pointer to a GtkPizza and this
161 one is (in the GTK sense) a child of the GtkScrolledWindow.
162
163 If the m_wxwindow field is set, then all input to this widget is inter-
164 cepted and sent to the wxWidgets class. If not, all input to the widget
165 that gets pointed to by m_widget gets intercepted and sent to the class.
166
167 II)
168
169 The design of scrolling in wxWidgets is markedly different from that offered
170 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
171 clicking on a scrollbar belonging to scrolled window will inevitably move
172 the window. In wxWidgets, the scrollbar will only emit an event, send this
173 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
174 which actually moves the window and its subchildren. Note that GtkPizza
175 memorizes how much it has been scrolled but that wxWidgets forgets this
176 so that the two coordinates systems have to be kept in synch. This is done
177 in various places using the pizza->xoffset and pizza->yoffset values.
178
179 III)
180
181 Singularily the most broken code in GTK is the code that is supposes to
182 inform subwindows (child windows) about new positions. Very often, duplicate
183 events are sent without changes in size or position, equally often no
184 events are sent at all (All this is due to a bug in the GtkContainer code
185 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
186 GTK's own system and it simply waits for size events for toplevel windows
187 and then iterates down the respective size events to all window. This has
188 the disadvantage, that windows might get size events before the GTK widget
189 actually has the reported size. This doesn't normally pose any problem, but
190 the OpenGl drawing routines rely on correct behaviour. Therefore, I have
191 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
192 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
193 window that is used for OpenGl output really has that size (as reported by
194 GTK).
195
196 IV)
197
198 If someone at some point of time feels the immense desire to have a look at,
199 change or attempt to optimse the Refresh() logic, this person will need an
200 intimate understanding of what a "draw" and what an "expose" events are and
201 what there are used for, in particular when used in connection with GTK's
202 own windowless widgets. Beware.
203
204 V)
205
206 Cursors, too, have been a constant source of pleasure. The main difficulty
207 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
208 for the parent. To prevent this from doing too much harm, I use idle time
209 to set the cursor over and over again, starting from the toplevel windows
210 and ending with the youngest generation (speaking of parent and child windows).
211 Also don't forget that cursors (like much else) are connected to GdkWindows,
212 not GtkWidgets and that the "window" field of a GtkWidget might very well
213 point to the GdkWindow of the parent widget (-> "window less widget") and
214 that the two obviously have very different meanings.
215
216*/
217
218//-----------------------------------------------------------------------------
219// data
220//-----------------------------------------------------------------------------
221
222extern wxList wxPendingDelete;
223extern bool g_blockEventsOnDrag;
224extern bool g_blockEventsOnScroll;
225extern wxCursor g_globalCursor;
226
227static GdkGC *g_eraseGC = NULL;
228
229// mouse capture state: the window which has it and if the mouse is currently
230// inside it
231static wxWindowGTK *g_captureWindow = (wxWindowGTK*) NULL;
232static bool g_captureWindowHasMouse = FALSE;
233
234wxWindowGTK *g_focusWindow = (wxWindowGTK*) NULL;
235
236// the last window which had the focus - this is normally never NULL (except
237// if we never had focus at all) as even when g_focusWindow is NULL it still
238// keeps its previous value
239wxWindowGTK *g_focusWindowLast = (wxWindowGTK*) NULL;
240
241// If a window get the focus set but has not been realized
242// yet, defer setting the focus to idle time.
243wxWindowGTK *g_delayedFocus = (wxWindowGTK*) NULL;
244
245// hack: we need something to pass to gtk_menu_popup, so we store the time of
246// the last click here
247static guint32 gs_timeLastClick = 0;
248
249extern bool g_mainThreadLocked;
250
251//-----------------------------------------------------------------------------
252// debug
253//-----------------------------------------------------------------------------
254
255#ifdef __WXDEBUG__
256
257#if wxUSE_THREADS
258# define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
259#else
260# define DEBUG_MAIN_THREAD
261#endif
262#else
263#define DEBUG_MAIN_THREAD
264#endif // Debug
265
266// the trace mask used for the focus debugging messages
267#define TRACE_FOCUS _T("focus")
268
269//-----------------------------------------------------------------------------
270// missing gdk functions
271//-----------------------------------------------------------------------------
272
273void
274gdk_window_warp_pointer (GdkWindow *window,
275 gint x,
276 gint y)
277{
278#ifndef __WXGTK20__
279 GdkWindowPrivate *priv;
280#endif
281
282 if (!window)
283 window = GDK_ROOT_PARENT();
284
285#ifdef __WXGTK20__
286 if (!GDK_WINDOW_DESTROYED(window))
287 {
288 XWarpPointer (GDK_WINDOW_XDISPLAY(window),
289 None, /* not source window -> move from anywhere */
290 GDK_WINDOW_XID(window), /* dest window */
291 0, 0, 0, 0, /* not source window -> move from anywhere */
292 x, y );
293 }
294#else
295 priv = (GdkWindowPrivate*) window;
296
297 if (!priv->destroyed)
298 {
299 XWarpPointer (priv->xdisplay,
300 None, /* not source window -> move from anywhere */
301 priv->xwindow, /* dest window */
302 0, 0, 0, 0, /* not source window -> move from anywhere */
303 x, y );
304 }
305#endif
306}
307
308//-----------------------------------------------------------------------------
309// idle system
310//-----------------------------------------------------------------------------
311
312extern void wxapp_install_idle_handler();
313extern bool g_isIdle;
314
315//-----------------------------------------------------------------------------
316// local code (see below)
317//-----------------------------------------------------------------------------
318
319// returns the child of win which currently has focus or NULL if not found
320//
321// Note: can't be static, needed by textctrl.cpp.
322wxWindow *wxFindFocusedChild(wxWindowGTK *win)
323{
324 wxWindow *winFocus = wxWindowGTK::FindFocus();
325 if ( !winFocus )
326 return (wxWindow *)NULL;
327
328 if ( winFocus == win )
329 return (wxWindow *)win;
330
331 for ( wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
332 node;
333 node = node->GetNext() )
334 {
335 wxWindow *child = wxFindFocusedChild(node->GetData());
336 if ( child )
337 return child;
338 }
339
340 return (wxWindow *)NULL;
341}
342
343static void draw_frame( GtkWidget *widget, wxWindowGTK *win )
344{
345 // wxUniversal widgets draw the borders and scrollbars themselves
346#ifndef __WXUNIVERSAL__
347 if (!win->m_hasVMT)
348 return;
349
350 int dw = 0;
351 int dh = 0;
352
353 if (win->m_hasScrolling)
354 {
355 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(widget);
356
357 GtkRequisition vscroll_req;
358 vscroll_req.width = 2;
359 vscroll_req.height = 2;
360 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window->vscrollbar) )->size_request )
361 (scroll_window->vscrollbar, &vscroll_req );
362
363 GtkRequisition hscroll_req;
364 hscroll_req.width = 2;
365 hscroll_req.height = 2;
366 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window->hscrollbar) )->size_request )
367 (scroll_window->hscrollbar, &hscroll_req );
368
369 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(widget) );
370
371 if (scroll_window->vscrollbar_visible)
372 {
373 dw += vscroll_req.width;
374 dw += scroll_class->scrollbar_spacing;
375 }
376
377 if (scroll_window->hscrollbar_visible)
378 {
379 dh += hscroll_req.height;
380 dh += scroll_class->scrollbar_spacing;
381 }
382 }
383
384 int dx = 0;
385 int dy = 0;
386 if (GTK_WIDGET_NO_WINDOW (widget))
387 {
388 dx += widget->allocation.x;
389 dy += widget->allocation.y;
390 }
391
392 if (win->HasFlag(wxRAISED_BORDER))
393 {
394 gtk_draw_shadow( widget->style,
395 widget->window,
396 GTK_STATE_NORMAL,
397 GTK_SHADOW_OUT,
398 dx, dy,
399 widget->allocation.width-dw, widget->allocation.height-dh );
400 return;
401 }
402
403 if (win->HasFlag(wxSUNKEN_BORDER))
404 {
405 gtk_draw_shadow( widget->style,
406 widget->window,
407 GTK_STATE_NORMAL,
408 GTK_SHADOW_IN,
409 dx, dy,
410 widget->allocation.width-dw, widget->allocation.height-dh );
411 return;
412 }
413
414 if (win->HasFlag(wxSIMPLE_BORDER))
415 {
416 GdkGC *gc;
417 gc = gdk_gc_new( widget->window );
418 gdk_gc_set_foreground( gc, &widget->style->black );
419 gdk_draw_rectangle( widget->window, gc, FALSE,
420 dx, dy,
421 widget->allocation.width-dw-1, widget->allocation.height-dh-1 );
422 gdk_gc_unref( gc );
423 return;
424 }
425#endif // __WXUNIVERSAL__
426}
427
428//-----------------------------------------------------------------------------
429// "expose_event" of m_widget
430//-----------------------------------------------------------------------------
431
432extern "C" {
433static gint gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxWindowGTK *win )
434{
435 if (gdk_event->count > 0) return FALSE;
436
437 draw_frame( widget, win );
438
439#ifdef __WXGTK20__
440
441 (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, gdk_event);
442
443#endif
444 return TRUE;
445}
446}
447
448//-----------------------------------------------------------------------------
449// "draw" of m_widget
450//-----------------------------------------------------------------------------
451
452#ifndef __WXGTK20__
453
454extern "C" {
455static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxWindowGTK *win )
456{
457 draw_frame( widget, win );
458}
459}
460
461#endif // GTK+ < 2.0
462
463//-----------------------------------------------------------------------------
464// "size_request" of m_widget
465//-----------------------------------------------------------------------------
466
467// make it extern because wxStaticText needs to disconnect this one
468extern "C" {
469void wxgtk_window_size_request_callback(GtkWidget *widget,
470 GtkRequisition *requisition,
471 wxWindow *win)
472{
473 int w, h;
474 win->GetSize( &w, &h );
475 if (w < 2)
476 w = 2;
477 if (h < 2)
478 h = 2;
479
480 requisition->height = h;
481 requisition->width = w;
482}
483}
484
485extern "C" {
486static
487void wxgtk_combo_size_request_callback(GtkWidget *widget,
488 GtkRequisition *requisition,
489 wxComboBox *win)
490{
491 // This callback is actually hooked into the text entry
492 // of the combo box, not the GtkHBox.
493
494 int w, h;
495 win->GetSize( &w, &h );
496 if (w < 2)
497 w = 2;
498 if (h < 2)
499 h = 2;
500
501 GtkCombo *gcombo = GTK_COMBO(win->m_widget);
502
503 GtkRequisition entry_req;
504 entry_req.width = 2;
505 entry_req.height = 2;
506 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo->button) )->size_request )
507 (gcombo->button, &entry_req );
508
509 requisition->width = w - entry_req.width;
510 requisition->height = entry_req.height;
511}
512}
513
514//-----------------------------------------------------------------------------
515// "expose_event" of m_wxwindow
516//-----------------------------------------------------------------------------
517
518extern "C" {
519static int gtk_window_expose_callback( GtkWidget *widget,
520 GdkEventExpose *gdk_event,
521 wxWindow *win )
522{
523 DEBUG_MAIN_THREAD
524
525 if (g_isIdle)
526 wxapp_install_idle_handler();
527
528#ifdef __WXGTK20__
529 // This callback gets called in drawing-idle time under
530 // GTK 2.0, so we don't need to defer anything to idle
531 // time anymore.
532
533 GtkPizza *pizza = GTK_PIZZA( widget );
534 if (gdk_event->window != pizza->bin_window) return FALSE;
535
536#if 0
537 if (win->GetName())
538 {
539 wxPrintf( wxT("OnExpose from ") );
540 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
541 wxPrintf( win->GetClassInfo()->GetClassName() );
542 wxPrintf( wxT(" %d %d %d %d\n"), (int)gdk_event->area.x,
543 (int)gdk_event->area.y,
544 (int)gdk_event->area.width,
545 (int)gdk_event->area.height );
546 }
547
548 gtk_paint_box
549 (
550 win->m_wxwindow->style,
551 pizza->bin_window,
552 GTK_STATE_NORMAL,
553 GTK_SHADOW_OUT,
554 (GdkRectangle*) NULL,
555 win->m_wxwindow,
556 (char *)"button", // const_cast
557 20,20,24,24
558 );
559#endif
560
561 win->GetUpdateRegion() = wxRegion( gdk_event->region );
562
563 win->GtkSendPaintEvents();
564
565
566 // Let parent window draw window less widgets
567 (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, gdk_event);
568#else
569 // This gets called immediately after an expose event
570 // under GTK 1.2 so we collect the calls and wait for
571 // the idle handler to pick things up.
572
573 win->GetUpdateRegion().Union( gdk_event->area.x,
574 gdk_event->area.y,
575 gdk_event->area.width,
576 gdk_event->area.height );
577 win->m_clearRegion.Union( gdk_event->area.x,
578 gdk_event->area.y,
579 gdk_event->area.width,
580 gdk_event->area.height );
581
582 // Actual redrawing takes place in idle time.
583 // win->GtkUpdate();
584#endif
585
586 return FALSE;
587}
588}
589
590//-----------------------------------------------------------------------------
591// "event" of m_wxwindow
592//-----------------------------------------------------------------------------
593
594#ifndef __WXGTK20__
595
596// GTK thinks it is clever and filters out a certain amount of "unneeded"
597// expose events. We need them, of course, so we override the main event
598// procedure in GtkWidget by giving our own handler for all system events.
599// There, we look for expose events ourselves whereas all other events are
600// handled normally.
601
602extern "C" {
603static
604gint gtk_window_event_event_callback( GtkWidget *widget,
605 GdkEventExpose *event,
606 wxWindow *win )
607{
608 if (event->type == GDK_EXPOSE)
609 {
610 gint ret = gtk_window_expose_callback( widget, event, win );
611 return ret;
612 }
613
614 return FALSE;
615}
616}
617
618#endif // !GTK+ 2
619
620//-----------------------------------------------------------------------------
621// "draw" of m_wxwindow
622//-----------------------------------------------------------------------------
623
624#ifndef __WXGTK20__
625
626// This callback is a complete replacement of the gtk_pizza_draw() function,
627// which is disabled.
628
629extern "C" {
630static void gtk_window_draw_callback( GtkWidget *widget,
631 GdkRectangle *rect,
632 wxWindow *win )
633{
634 DEBUG_MAIN_THREAD
635
636 if (g_isIdle)
637 wxapp_install_idle_handler();
638
639 // if there are any children we must refresh everything
640 //
641 // VZ: why?
642 if ( !win->HasFlag(wxFULL_REPAINT_ON_RESIZE) &&
643 win->GetChildren().IsEmpty() )
644 {
645 return;
646 }
647
648#if 0
649 if (win->GetName())
650 {
651 wxPrintf( wxT("OnDraw from ") );
652 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
653 wxPrintf( win->GetClassInfo()->GetClassName() );
654 wxPrintf( wxT(" %d %d %d %d\n"), (int)rect->x,
655 (int)rect->y,
656 (int)rect->width,
657 (int)rect->height );
658 }
659#endif
660
661#ifndef __WXUNIVERSAL__
662 GtkPizza *pizza = GTK_PIZZA (widget);
663
664 if (win->GetThemeEnabled() && win->GetBackgroundStyle() == wxBG_STYLE_SYSTEM)
665 {
666 wxWindow *parent = win->GetParent();
667 while (parent && !parent->IsTopLevel())
668 parent = parent->GetParent();
669 if (!parent)
670 parent = win;
671
672 gtk_paint_flat_box (parent->m_widget->style,
673 pizza->bin_window,
674 GTK_STATE_NORMAL,
675 GTK_SHADOW_NONE,
676 rect,
677 parent->m_widget,
678 (char *)"base",
679 0, 0, -1, -1);
680 }
681#endif
682
683 win->m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height );
684 win->GetUpdateRegion().Union( rect->x, rect->y, rect->width, rect->height );
685
686 // Update immediately, not in idle time.
687 win->GtkUpdate();
688
689#ifndef __WXUNIVERSAL__
690 // Redraw child widgets
691 GList *children = pizza->children;
692 while (children)
693 {
694 GtkPizzaChild *child = (GtkPizzaChild*) children->data;
695 children = children->next;
696
697 GdkRectangle child_area;
698 if (gtk_widget_intersect (child->widget, rect, &child_area))
699 {
700 gtk_widget_draw (child->widget, &child_area /* (GdkRectangle*) NULL*/ );
701 }
702 }
703#endif
704}
705}
706
707#endif
708
709//-----------------------------------------------------------------------------
710// "key_press_event" from any window
711//-----------------------------------------------------------------------------
712
713// set WXTRACE to this to see the key event codes on the console
714#define TRACE_KEYS _T("keyevent")
715
716// translates an X key symbol to WXK_XXX value
717//
718// if isChar is true it means that the value returned will be used for EVT_CHAR
719// event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
720// for example, while if it is false it means that the value is going to be
721// used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
722// WXK_NUMPAD_DIVIDE
723static long wxTranslateKeySymToWXKey(KeySym keysym, bool isChar)
724{
725 long key_code;
726
727 switch ( keysym )
728 {
729 // Shift, Control and Alt don't generate the CHAR events at all
730 case GDK_Shift_L:
731 case GDK_Shift_R:
732 key_code = isChar ? 0 : WXK_SHIFT;
733 break;
734 case GDK_Control_L:
735 case GDK_Control_R:
736 key_code = isChar ? 0 : WXK_CONTROL;
737 break;
738 case GDK_Meta_L:
739 case GDK_Meta_R:
740 case GDK_Alt_L:
741 case GDK_Alt_R:
742 case GDK_Super_L:
743 case GDK_Super_R:
744 key_code = isChar ? 0 : WXK_ALT;
745 break;
746
747 // neither do the toggle modifies
748 case GDK_Scroll_Lock:
749 key_code = isChar ? 0 : WXK_SCROLL;
750 break;
751
752 case GDK_Caps_Lock:
753 key_code = isChar ? 0 : WXK_CAPITAL;
754 break;
755
756 case GDK_Num_Lock:
757 key_code = isChar ? 0 : WXK_NUMLOCK;
758 break;
759
760
761 // various other special keys
762 case GDK_Menu:
763 key_code = WXK_MENU;
764 break;
765
766 case GDK_Help:
767 key_code = WXK_HELP;
768 break;
769
770 case GDK_BackSpace:
771 key_code = WXK_BACK;
772 break;
773
774 case GDK_ISO_Left_Tab:
775 case GDK_Tab:
776 key_code = WXK_TAB;
777 break;
778
779 case GDK_Linefeed:
780 case GDK_Return:
781 key_code = WXK_RETURN;
782 break;
783
784 case GDK_Clear:
785 key_code = WXK_CLEAR;
786 break;
787
788 case GDK_Pause:
789 key_code = WXK_PAUSE;
790 break;
791
792 case GDK_Select:
793 key_code = WXK_SELECT;
794 break;
795
796 case GDK_Print:
797 key_code = WXK_PRINT;
798 break;
799
800 case GDK_Execute:
801 key_code = WXK_EXECUTE;
802 break;
803
804 case GDK_Escape:
805 key_code = WXK_ESCAPE;
806 break;
807
808 // cursor and other extended keyboard keys
809 case GDK_Delete:
810 key_code = WXK_DELETE;
811 break;
812
813 case GDK_Home:
814 key_code = WXK_HOME;
815 break;
816
817 case GDK_Left:
818 key_code = WXK_LEFT;
819 break;
820
821 case GDK_Up:
822 key_code = WXK_UP;
823 break;
824
825 case GDK_Right:
826 key_code = WXK_RIGHT;
827 break;
828
829 case GDK_Down:
830 key_code = WXK_DOWN;
831 break;
832
833 case GDK_Prior: // == GDK_Page_Up
834 key_code = WXK_PRIOR;
835 break;
836
837 case GDK_Next: // == GDK_Page_Down
838 key_code = WXK_NEXT;
839 break;
840
841 case GDK_End:
842 key_code = WXK_END;
843 break;
844
845 case GDK_Begin:
846 key_code = WXK_HOME;
847 break;
848
849 case GDK_Insert:
850 key_code = WXK_INSERT;
851 break;
852
853
854 // numpad keys
855 case GDK_KP_0:
856 case GDK_KP_1:
857 case GDK_KP_2:
858 case GDK_KP_3:
859 case GDK_KP_4:
860 case GDK_KP_5:
861 case GDK_KP_6:
862 case GDK_KP_7:
863 case GDK_KP_8:
864 case GDK_KP_9:
865 key_code = (isChar ? '0' : WXK_NUMPAD0) + keysym - GDK_KP_0;
866 break;
867
868 case GDK_KP_Space:
869 key_code = isChar ? ' ' : WXK_NUMPAD_SPACE;
870 break;
871
872 case GDK_KP_Tab:
873 key_code = isChar ? WXK_TAB : WXK_NUMPAD_TAB;
874 break;
875
876 case GDK_KP_Enter:
877 key_code = isChar ? WXK_RETURN : WXK_NUMPAD_ENTER;
878 break;
879
880 case GDK_KP_F1:
881 key_code = isChar ? WXK_F1 : WXK_NUMPAD_F1;
882 break;
883
884 case GDK_KP_F2:
885 key_code = isChar ? WXK_F2 : WXK_NUMPAD_F2;
886 break;
887
888 case GDK_KP_F3:
889 key_code = isChar ? WXK_F3 : WXK_NUMPAD_F3;
890 break;
891
892 case GDK_KP_F4:
893 key_code = isChar ? WXK_F4 : WXK_NUMPAD_F4;
894 break;
895
896 case GDK_KP_Home:
897 key_code = isChar ? WXK_HOME : WXK_NUMPAD_HOME;
898 break;
899
900 case GDK_KP_Left:
901 key_code = isChar ? WXK_LEFT : WXK_NUMPAD_LEFT;
902 break;
903
904 case GDK_KP_Up:
905 key_code = isChar ? WXK_UP : WXK_NUMPAD_UP;
906 break;
907
908 case GDK_KP_Right:
909 key_code = isChar ? WXK_RIGHT : WXK_NUMPAD_RIGHT;
910 break;
911
912 case GDK_KP_Down:
913 key_code = isChar ? WXK_DOWN : WXK_NUMPAD_DOWN;
914 break;
915
916 case GDK_KP_Prior: // == GDK_KP_Page_Up
917 key_code = isChar ? WXK_PRIOR : WXK_NUMPAD_PRIOR;
918 break;
919
920 case GDK_KP_Next: // == GDK_KP_Page_Down
921 key_code = isChar ? WXK_NEXT : WXK_NUMPAD_NEXT;
922 break;
923
924 case GDK_KP_End:
925 key_code = isChar ? WXK_END : WXK_NUMPAD_END;
926 break;
927
928 case GDK_KP_Begin:
929 key_code = isChar ? WXK_HOME : WXK_NUMPAD_BEGIN;
930 break;
931
932 case GDK_KP_Insert:
933 key_code = isChar ? WXK_INSERT : WXK_NUMPAD_INSERT;
934 break;
935
936 case GDK_KP_Delete:
937 key_code = isChar ? WXK_DELETE : WXK_NUMPAD_DELETE;
938 break;
939
940 case GDK_KP_Equal:
941 key_code = isChar ? '=' : WXK_NUMPAD_EQUAL;
942 break;
943
944 case GDK_KP_Multiply:
945 key_code = isChar ? '*' : WXK_NUMPAD_MULTIPLY;
946 break;
947
948 case GDK_KP_Add:
949 key_code = isChar ? '+' : WXK_NUMPAD_ADD;
950 break;
951
952 case GDK_KP_Separator:
953 // FIXME: what is this?
954 key_code = isChar ? '.' : WXK_NUMPAD_SEPARATOR;
955 break;
956
957 case GDK_KP_Subtract:
958 key_code = isChar ? '-' : WXK_NUMPAD_SUBTRACT;
959 break;
960
961 case GDK_KP_Decimal:
962 key_code = isChar ? '.' : WXK_NUMPAD_DECIMAL;
963 break;
964
965 case GDK_KP_Divide:
966 key_code = isChar ? '/' : WXK_NUMPAD_DIVIDE;
967 break;
968
969
970 // function keys
971 case GDK_F1:
972 case GDK_F2:
973 case GDK_F3:
974 case GDK_F4:
975 case GDK_F5:
976 case GDK_F6:
977 case GDK_F7:
978 case GDK_F8:
979 case GDK_F9:
980 case GDK_F10:
981 case GDK_F11:
982 case GDK_F12:
983 key_code = WXK_F1 + keysym - GDK_F1;
984 break;
985
986 default:
987 key_code = 0;
988 }
989
990 return key_code;
991}
992
993static inline bool wxIsAsciiKeysym(KeySym ks)
994{
995 return ks < 256;
996}
997
998static void wxFillOtherKeyEventFields(wxKeyEvent& event,
999 wxWindowGTK *win,
1000 GdkEventKey *gdk_event)
1001{
1002 int x = 0;
1003 int y = 0;
1004 GdkModifierType state;
1005 if (gdk_event->window)
1006 gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
1007
1008 event.SetTimestamp( gdk_event->time );
1009 event.SetId(win->GetId());
1010 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK) != 0;
1011 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK) != 0;
1012 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK) != 0;
1013 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK) != 0;
1014 event.m_scanCode = gdk_event->keyval;
1015 event.m_rawCode = (wxUint32) gdk_event->keyval;
1016 event.m_rawFlags = 0;
1017#if wxUSE_UNICODE
1018 event.m_uniChar = gdk_keyval_to_unicode(gdk_event->keyval);
1019#endif
1020 wxGetMousePosition( &x, &y );
1021 win->ScreenToClient( &x, &y );
1022 event.m_x = x;
1023 event.m_y = y;
1024 event.SetEventObject( win );
1025}
1026
1027
1028static bool
1029wxTranslateGTKKeyEventToWx(wxKeyEvent& event,
1030 wxWindowGTK *win,
1031 GdkEventKey *gdk_event)
1032{
1033 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
1034 // but only event->keyval which is quite useless to us, so remember
1035 // the last character from GDK_KEY_PRESS and reuse it as last resort
1036 //
1037 // NB: should be MT-safe as we're always called from the main thread only
1038 static struct
1039 {
1040 KeySym keysym;
1041 long keycode;
1042 } s_lastKeyPress = { 0, 0 };
1043
1044 KeySym keysym = gdk_event->keyval;
1045
1046 wxLogTrace(TRACE_KEYS, _T("Key %s event: keysym = %ld"),
1047 event.GetEventType() == wxEVT_KEY_UP ? _T("release")
1048 : _T("press"),
1049 keysym);
1050
1051 long key_code = wxTranslateKeySymToWXKey(keysym, FALSE /* !isChar */);
1052
1053 if ( !key_code )
1054 {
1055 // do we have the translation or is it a plain ASCII character?
1056 if ( (gdk_event->length == 1) || wxIsAsciiKeysym(keysym) )
1057 {
1058 // we should use keysym if it is ASCII as X does some translations
1059 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
1060 // which we don't want here (but which we do use for OnChar())
1061 if ( !wxIsAsciiKeysym(keysym) )
1062 {
1063 keysym = (KeySym)gdk_event->string[0];
1064 }
1065
1066 // we want to always get the same key code when the same key is
1067 // pressed regardless of the state of the modifies, i.e. on a
1068 // standard US keyboard pressing '5' or '%' ('5' key with
1069 // Shift) should result in the same key code in OnKeyDown():
1070 // '5' (although OnChar() will get either '5' or '%').
1071 //
1072 // to do it we first translate keysym to keycode (== scan code)
1073 // and then back but always using the lower register
1074 Display *dpy = (Display *)wxGetDisplay();
1075 KeyCode keycode = XKeysymToKeycode(dpy, keysym);
1076
1077 wxLogTrace(TRACE_KEYS, _T("\t-> keycode %d"), keycode);
1078
1079 KeySym keysymNormalized = XKeycodeToKeysym(dpy, keycode, 0);
1080
1081 // use the normalized, i.e. lower register, keysym if we've
1082 // got one
1083 key_code = keysymNormalized ? keysymNormalized : keysym;
1084
1085 // as explained above, we want to have lower register key codes
1086 // normally but for the letter keys we want to have the upper ones
1087 //
1088 // NB: don't use XConvertCase() here, we want to do it for letters
1089 // only
1090 key_code = toupper(key_code);
1091 }
1092 else // non ASCII key, what to do?
1093 {
1094 // by default, ignore it
1095 key_code = 0;
1096
1097 // but if we have cached information from the last KEY_PRESS
1098 if ( gdk_event->type == GDK_KEY_RELEASE )
1099 {
1100 // then reuse it
1101 if ( keysym == s_lastKeyPress.keysym )
1102 {
1103 key_code = s_lastKeyPress.keycode;
1104 }
1105 }
1106 }
1107
1108 if ( gdk_event->type == GDK_KEY_PRESS )
1109 {
1110 // remember it to be reused for KEY_UP event later
1111 s_lastKeyPress.keysym = keysym;
1112 s_lastKeyPress.keycode = key_code;
1113 }
1114 }
1115
1116 wxLogTrace(TRACE_KEYS, _T("\t-> wxKeyCode %ld"), key_code);
1117
1118 // sending unknown key events doesn't really make sense
1119 if ( !key_code )
1120 return FALSE;
1121
1122 // now fill all the other fields
1123 wxFillOtherKeyEventFields(event, win, gdk_event);
1124
1125 event.m_keyCode = key_code;
1126
1127 return TRUE;
1128}
1129
1130
1131#ifdef __WXGTK20__
1132struct wxGtkIMData
1133{
1134 GtkIMContext *context;
1135 GdkEventKey *lastKeyEvent;
1136
1137 wxGtkIMData()
1138 {
1139 context = gtk_im_multicontext_new();
1140 lastKeyEvent = NULL;
1141 }
1142 ~wxGtkIMData()
1143 {
1144 g_object_unref(context);
1145 }
1146};
1147#endif
1148
1149extern "C" {
1150static gint gtk_window_key_press_callback( GtkWidget *widget,
1151 GdkEventKey *gdk_event,
1152 wxWindow *win )
1153{
1154 DEBUG_MAIN_THREAD
1155
1156 if (g_isIdle)
1157 wxapp_install_idle_handler();
1158
1159 if (!win->m_hasVMT)
1160 return FALSE;
1161 if (g_blockEventsOnDrag)
1162 return FALSE;
1163
1164
1165 wxKeyEvent event( wxEVT_KEY_DOWN );
1166 bool ret = false;
1167 bool return_after_IM = false;
1168
1169 if( wxTranslateGTKKeyEventToWx(event, win, gdk_event) )
1170 {
1171 // Emit KEY_DOWN event
1172 ret = win->GetEventHandler()->ProcessEvent( event );
1173 }
1174 else
1175 {
1176 // Return after IM processing as we cannot do
1177 // anything with it anyhow.
1178 return_after_IM = true;
1179 }
1180
1181#ifdef __WXGTK20__
1182 // 2005.01.26 modified by Hong Jen Yee (hzysoft@sina.com.tw):
1183 // When we get a key_press event here, it could be originate
1184 // from the current widget or its child widgets. However, only the widget
1185 // with the INPUT FOCUS can generate the INITIAL key_press event. That is,
1186 // if the CURRENT widget doesn't have the FOCUS at all, this event definitely
1187 // originated from its child widgets and shouldn't be passed to IM context.
1188 // In fact, what a GTK+ IM should do is filtering keyEvents and convert them
1189 // into text input ONLY WHEN THE WIDGET HAS INPUT FOCUS. Besides, when current
1190 // widgets has both IM context and input focus, the event should be filtered
1191 // by gtk_im_context_filter_keypress().
1192 // Then, we should, according to GTK+ 2.0 API doc, return whatever it returns.
1193 if ((!ret) && (win->m_imData != NULL) && ( wxWindow::FindFocus() == win ))
1194 {
1195 // We should let GTK+ IM filter key event first. According to GTK+ 2.0 API
1196 // docs, if IM filter returns true, no further processing should be done.
1197 // we should send the key_down event anyway.
1198 bool intercepted_by_IM = gtk_im_context_filter_keypress(win->m_imData->context, gdk_event);
1199 win->m_imData->lastKeyEvent = NULL;
1200 if (intercepted_by_IM)
1201 {
1202 wxLogTrace(TRACE_KEYS, _T("Key event intercepted by IM"));
1203 return true;
1204 }
1205 }
1206#endif
1207 if (return_after_IM)
1208 return false;
1209
1210#ifndef __WXGTK20__
1211 // This is for GTK+ 1.2 only. The char event generatation for GTK+ 2.0 is done
1212 // in the "commit" handler.
1213
1214 // 2005.02.02 modified by Hong Jen Yee (hzysoft@sina.com.tw).
1215 // In GTK+ 1.2, strings sent by IMs are also regarded as key_press events whose
1216 // keyCodes cannot be recognized by wxWidgets. These MBCS strings, however, are
1217 // composed of more than one character, which means gdk_event->length will always
1218 // greater than one. When gtk_event->length == 1, this may be an ASCII character
1219 // and can be translated by wx. However, when MBCS characters are sent by IM,
1220 // gdk_event->length will >= 2. So neither should we pass it to accelerator table,
1221 // nor should we pass it to controls. The following explanation was excerpted
1222 // from GDK documentation.
1223 // gint length : the length of string.
1224 // gchar *string : a null-terminated multi-byte string containing the composed
1225 // characters resulting from the key press. When text is being input, in a GtkEntry
1226 // for example, it is these characters which should be added to the input buffer.
1227 // When using Input Methods to support internationalized text input, the composed
1228 // characters appear here after the pre-editing has been completed.
1229
1230 if ( (!ret) && (gdk_event->length > 1) ) // If this event contains a pre-edited string from IM.
1231 {
1232 // We should translate this key event into wxEVT_CHAR not wxEVT_KEY_DOWN.
1233 #if wxUSE_UNICODE // GTK+ 1.2 is not UTF-8 based.
1234 const wxWCharBuffer string = wxConvLocal.cMB2WC( gdk_event->string );
1235 if( !string )
1236 return false;
1237 #else
1238 const char* string = gdk_event->string;
1239 #endif
1240
1241 // Implement OnCharHook by checking ancesteror top level windows
1242 wxWindow *parent = win;
1243 while (parent && !parent->IsTopLevel())
1244 parent = parent->GetParent();
1245
1246 for( const wxChar* pstr = string; *pstr; pstr++ )
1247 {
1248 #if wxUSE_UNICODE
1249 event.m_uniChar = *pstr;
1250 // Backward compatible for ISO-8859-1
1251 event.m_keyCode = *pstr < 256 ? event.m_uniChar : 0;
1252 #else
1253 event.m_keyCode = *pstr;
1254 #endif
1255 if (parent)
1256 {
1257 event.SetEventType( wxEVT_CHAR_HOOK );
1258 ret = parent->GetEventHandler()->ProcessEvent( event );
1259 }
1260 if (!ret)
1261 {
1262 event.SetEventType(wxEVT_CHAR);
1263 win->GetEventHandler()->ProcessEvent( event );
1264 }
1265 }
1266 return true;
1267 }
1268
1269#endif // #ifndef __WXGTK20__
1270
1271#if wxUSE_ACCEL
1272 if (!ret)
1273 {
1274 wxWindowGTK *ancestor = win;
1275 while (ancestor)
1276 {
1277 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1278 if (command != -1)
1279 {
1280 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1281 ret = ancestor->GetEventHandler()->ProcessEvent( command_event );
1282 break;
1283 }
1284 if (ancestor->IsTopLevel())
1285 break;
1286 ancestor = ancestor->GetParent();
1287 }
1288 }
1289#endif // wxUSE_ACCEL
1290
1291 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
1292 // will only be sent if it is not in an accelerator table.
1293 if (!ret)
1294 {
1295 long key_code;
1296 KeySym keysym = gdk_event->keyval;
1297 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
1298 key_code = wxTranslateKeySymToWXKey(keysym, TRUE /* isChar */);
1299 if ( !key_code )
1300 {
1301 if ( wxIsAsciiKeysym(keysym) )
1302 {
1303 // ASCII key
1304 key_code = (unsigned char)keysym;
1305 }
1306 // gdk_event->string is actually deprecated
1307 else if ( gdk_event->length == 1 )
1308 {
1309 key_code = (unsigned char)gdk_event->string[0];
1310 }
1311 }
1312
1313 if ( key_code )
1314 {
1315 wxLogTrace(TRACE_KEYS, _T("Char event: %ld"), key_code);
1316
1317 event.m_keyCode = key_code;
1318
1319 // Implement OnCharHook by checking ancesteror top level windows
1320 wxWindow *parent = win;
1321 while (parent && !parent->IsTopLevel())
1322 parent = parent->GetParent();
1323 if (parent)
1324 {
1325 event.SetEventType( wxEVT_CHAR_HOOK );
1326 ret = parent->GetEventHandler()->ProcessEvent( event );
1327 }
1328
1329 if (!ret)
1330 {
1331 event.SetEventType(wxEVT_CHAR);
1332 ret = win->GetEventHandler()->ProcessEvent( event );
1333 }
1334 }
1335 }
1336
1337
1338
1339
1340
1341 // win is a control: tab can be propagated up
1342 if ( !ret &&
1343 ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab)) &&
1344// VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1345// have this style, yet choose not to process this particular TAB in which
1346// case TAB must still work as a navigational character
1347// JS: enabling again to make consistent with other platforms
1348// (with wxTE_PROCESS_TAB you have to call Navigate to get default
1349// navigation behaviour)
1350#if wxUSE_TEXTCTRL
1351 (! (win->HasFlag(wxTE_PROCESS_TAB) && win->IsKindOf(CLASSINFO(wxTextCtrl)) )) &&
1352#endif
1353 win->GetParent() && (win->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
1354 {
1355 wxNavigationKeyEvent new_event;
1356 new_event.SetEventObject( win->GetParent() );
1357 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
1358 new_event.SetDirection( (gdk_event->keyval == GDK_Tab) );
1359 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
1360 new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) );
1361 new_event.SetCurrentFocus( win );
1362 ret = win->GetParent()->GetEventHandler()->ProcessEvent( new_event );
1363 }
1364
1365 // generate wxID_CANCEL if <esc> has been pressed (typically in dialogs)
1366 if ( !ret &&
1367 (gdk_event->keyval == GDK_Escape) )
1368 {
1369 // however only do it if we have a Cancel button in the dialog,
1370 // otherwise the user code may get confused by the events from a
1371 // non-existing button and, worse, a wxButton might get button event
1372 // from another button which is not really expected
1373 wxWindow *winForCancel = win,
1374 *btnCancel = NULL;
1375 while ( winForCancel )
1376 {
1377 btnCancel = winForCancel->FindWindow(wxID_CANCEL);
1378 if ( btnCancel )
1379 {
1380 // found a cancel button
1381 break;
1382 }
1383
1384 if ( winForCancel->IsTopLevel() )
1385 {
1386 // no need to look further
1387 break;
1388 }
1389
1390 // maybe our parent has a cancel button?
1391 winForCancel = winForCancel->GetParent();
1392 }
1393
1394 if ( btnCancel )
1395 {
1396 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
1397 event.SetEventObject(btnCancel);
1398 ret = btnCancel->GetEventHandler()->ProcessEvent(event);
1399 }
1400 }
1401
1402 if (ret)
1403 {
1404 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
1405 return TRUE;
1406 }
1407
1408 return FALSE;
1409}
1410}
1411
1412#ifdef __WXGTK20__
1413extern "C" {
1414static void gtk_wxwindow_commit_cb (GtkIMContext *context,
1415 const gchar *str,
1416 wxWindow *window)
1417{
1418 wxKeyEvent event( wxEVT_KEY_DOWN );
1419
1420 // take modifiers, cursor position, timestamp etc. from the last
1421 // key_press_event that was fed into Input Method:
1422 if (window->m_imData->lastKeyEvent)
1423 {
1424 wxFillOtherKeyEventFields(event,
1425 window, window->m_imData->lastKeyEvent);
1426 }
1427
1428#if wxUSE_UNICODE
1429 const wxWCharBuffer data = wxConvUTF8.cMB2WC( (char*)str );
1430#else
1431 const wxWCharBuffer wdata = wxConvUTF8.cMB2WC( (char*)str );
1432 const wxCharBuffer data = wxConvLocal.cWC2MB( wdata );
1433#endif // wxUSE_UNICODE
1434 if( !(const wxChar*)data )
1435 return;
1436
1437 bool ret = false;
1438
1439 // Implement OnCharHook by checking ancestor top level windows
1440 wxWindow *parent = window;
1441 while (parent && !parent->IsTopLevel())
1442 parent = parent->GetParent();
1443
1444 for( const wxChar* pstr = data; *pstr; pstr++ )
1445 {
1446#if wxUSE_UNICODE
1447 event.m_uniChar = *pstr;
1448 // Backward compatible for ISO-8859-1
1449 event.m_keyCode = *pstr < 256 ? event.m_uniChar : 0;
1450 wxLogTrace(TRACE_KEYS, _T("IM sent character '%c'"), event.m_uniChar);
1451#else
1452 event.m_keyCode = *pstr;
1453#endif // wxUSE_UNICODE
1454 if (parent)
1455 {
1456 event.SetEventType( wxEVT_CHAR_HOOK );
1457 ret = parent->GetEventHandler()->ProcessEvent( event );
1458 }
1459
1460 if (!ret)
1461 {
1462 event.SetEventType(wxEVT_CHAR);
1463 ret = window->GetEventHandler()->ProcessEvent( event );
1464 }
1465 }
1466}
1467}
1468#endif
1469
1470
1471//-----------------------------------------------------------------------------
1472// "key_release_event" from any window
1473//-----------------------------------------------------------------------------
1474
1475extern "C" {
1476static gint gtk_window_key_release_callback( GtkWidget *widget,
1477 GdkEventKey *gdk_event,
1478 wxWindowGTK *win )
1479{
1480 DEBUG_MAIN_THREAD
1481
1482 if (g_isIdle)
1483 wxapp_install_idle_handler();
1484
1485 if (!win->m_hasVMT)
1486 return FALSE;
1487
1488 if (g_blockEventsOnDrag)
1489 return FALSE;
1490
1491 wxKeyEvent event( wxEVT_KEY_UP );
1492 if ( !wxTranslateGTKKeyEventToWx(event, win, gdk_event) )
1493 {
1494 // unknown key pressed, ignore (the event would be useless anyhow
1495 return FALSE;
1496 }
1497
1498 if ( !win->GetEventHandler()->ProcessEvent( event ) )
1499 return FALSE;
1500
1501 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_release_event" );
1502 return TRUE;
1503}
1504}
1505
1506// ============================================================================
1507// the mouse events
1508// ============================================================================
1509
1510// ----------------------------------------------------------------------------
1511// mouse event processing helpers
1512// ----------------------------------------------------------------------------
1513
1514// init wxMouseEvent with the info from GdkEventXXX struct
1515template<typename T> void InitMouseEvent(wxWindowGTK *win,
1516 wxMouseEvent& event,
1517 T *gdk_event)
1518{
1519 event.SetTimestamp( gdk_event->time );
1520 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
1521 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
1522 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
1523 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
1524 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
1525 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
1526 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
1527 if (event.GetEventType() == wxEVT_MOUSEWHEEL)
1528 {
1529 event.m_linesPerAction = 3;
1530 event.m_wheelDelta = 120;
1531 if (((GdkEventButton*)gdk_event)->button == 4)
1532 event.m_wheelRotation = 120;
1533 else if (((GdkEventButton*)gdk_event)->button == 5)
1534 event.m_wheelRotation = -120;
1535 }
1536
1537 wxPoint pt = win->GetClientAreaOrigin();
1538 event.m_x = (wxCoord)gdk_event->x - pt.x;
1539 event.m_y = (wxCoord)gdk_event->y - pt.y;
1540
1541 event.SetEventObject( win );
1542 event.SetId( win->GetId() );
1543 event.SetTimestamp( gdk_event->time );
1544}
1545
1546static void AdjustEventButtonState(wxMouseEvent& event)
1547{
1548 // GDK reports the old state of the button for a button press event, but
1549 // for compatibility with MSW and common sense we want m_leftDown be TRUE
1550 // for a LEFT_DOWN event, not FALSE, so we will invert
1551 // left/right/middleDown for the corresponding click events
1552
1553 if ((event.GetEventType() == wxEVT_LEFT_DOWN) ||
1554 (event.GetEventType() == wxEVT_LEFT_DCLICK) ||
1555 (event.GetEventType() == wxEVT_LEFT_UP))
1556 {
1557 event.m_leftDown = !event.m_leftDown;
1558 return;
1559 }
1560
1561 if ((event.GetEventType() == wxEVT_MIDDLE_DOWN) ||
1562 (event.GetEventType() == wxEVT_MIDDLE_DCLICK) ||
1563 (event.GetEventType() == wxEVT_MIDDLE_UP))
1564 {
1565 event.m_middleDown = !event.m_middleDown;
1566 return;
1567 }
1568
1569 if ((event.GetEventType() == wxEVT_RIGHT_DOWN) ||
1570 (event.GetEventType() == wxEVT_RIGHT_DCLICK) ||
1571 (event.GetEventType() == wxEVT_RIGHT_UP))
1572 {
1573 event.m_rightDown = !event.m_rightDown;
1574 return;
1575 }
1576}
1577
1578// find the window to send the mouse event too
1579static
1580wxWindowGTK *FindWindowForMouseEvent(wxWindowGTK *win, wxCoord& x, wxCoord& y)
1581{
1582 wxCoord xx = x;
1583 wxCoord yy = y;
1584
1585 if (win->m_wxwindow)
1586 {
1587 GtkPizza *pizza = GTK_PIZZA(win->m_wxwindow);
1588 xx += pizza->xoffset;
1589 yy += pizza->yoffset;
1590 }
1591
1592 wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
1593 while (node)
1594 {
1595 wxWindowGTK *child = node->GetData();
1596
1597 node = node->GetNext();
1598 if (!child->IsShown())
1599 continue;
1600
1601 if (child->IsTransparentForMouse())
1602 {
1603 // wxStaticBox is transparent in the box itself
1604 int xx1 = child->m_x;
1605 int yy1 = child->m_y;
1606 int xx2 = child->m_x + child->m_width;
1607 int yy2 = child->m_y + child->m_height;
1608
1609 // left
1610 if (((xx >= xx1) && (xx <= xx1+10) && (yy >= yy1) && (yy <= yy2)) ||
1611 // right
1612 ((xx >= xx2-10) && (xx <= xx2) && (yy >= yy1) && (yy <= yy2)) ||
1613 // top
1614 ((xx >= xx1) && (xx <= xx2) && (yy >= yy1) && (yy <= yy1+10)) ||
1615 // bottom
1616 ((xx >= xx1) && (xx <= xx2) && (yy >= yy2-1) && (yy <= yy2)))
1617 {
1618 win = child;
1619 x -= child->m_x;
1620 y -= child->m_y;
1621 break;
1622 }
1623
1624 }
1625 else
1626 {
1627 if ((child->m_wxwindow == (GtkWidget*) NULL) &&
1628 (child->m_x <= xx) &&
1629 (child->m_y <= yy) &&
1630 (child->m_x+child->m_width >= xx) &&
1631 (child->m_y+child->m_height >= yy))
1632 {
1633 win = child;
1634 x -= child->m_x;
1635 y -= child->m_y;
1636 break;
1637 }
1638 }
1639 }
1640
1641 return win;
1642}
1643
1644//-----------------------------------------------------------------------------
1645// "button_press_event"
1646//-----------------------------------------------------------------------------
1647
1648extern "C" {
1649static gint gtk_window_button_press_callback( GtkWidget *widget,
1650 GdkEventButton *gdk_event,
1651 wxWindowGTK *win )
1652{
1653 DEBUG_MAIN_THREAD
1654
1655 if (g_isIdle)
1656 wxapp_install_idle_handler();
1657
1658/*
1659 wxPrintf( wxT("1) OnButtonPress from ") );
1660 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1661 wxPrintf( win->GetClassInfo()->GetClassName() );
1662 wxPrintf( wxT(".\n") );
1663*/
1664 if (!win->m_hasVMT) return FALSE;
1665 if (g_blockEventsOnDrag) return TRUE;
1666 if (g_blockEventsOnScroll) return TRUE;
1667
1668 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
1669
1670 if (win->m_wxwindow && (g_focusWindow != win) && win->AcceptsFocus())
1671 {
1672 gtk_widget_grab_focus( win->m_wxwindow );
1673/*
1674 wxPrintf( wxT("GrabFocus from ") );
1675 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1676 wxPrintf( win->GetClassInfo()->GetClassName() );
1677 wxPrintf( wxT(".\n") );
1678*/
1679 }
1680
1681 // GDK sends surplus button down event
1682 // before a double click event. We
1683 // need to filter these out.
1684 if (gdk_event->type == GDK_BUTTON_PRESS)
1685 {
1686 GdkEvent *peek_event = gdk_event_peek();
1687 if (peek_event)
1688 {
1689 if ((peek_event->type == GDK_2BUTTON_PRESS) ||
1690 (peek_event->type == GDK_3BUTTON_PRESS))
1691 {
1692 gdk_event_free( peek_event );
1693 return TRUE;
1694 }
1695 else
1696 {
1697 gdk_event_free( peek_event );
1698 }
1699 }
1700 }
1701
1702 wxEventType event_type = wxEVT_NULL;
1703
1704 // GdkDisplay is a GTK+ 2.2.0 thing
1705#if defined(__WXGTK20__) && GTK_CHECK_VERSION(2, 2, 0)
1706 if ( gdk_event->type == GDK_2BUTTON_PRESS &&
1707 gdk_event->button >= 1 && gdk_event->button <= 3 )
1708 {
1709 // Reset GDK internal timestamp variables in order to disable GDK
1710 // triple click events. GDK will then next time believe no button has
1711 // been clicked just before, and send a normal button click event.
1712 GdkDisplay* display = gtk_widget_get_display (widget);
1713 display->button_click_time[1] = 0;
1714 display->button_click_time[0] = 0;
1715 }
1716#endif // GTK 2+
1717
1718 if (gdk_event->button == 1)
1719 {
1720 // note that GDK generates triple click events which are not supported
1721 // by wxWidgets but still have to be passed to the app as otherwise
1722 // clicks would simply go missing
1723 switch (gdk_event->type)
1724 {
1725 // we shouldn't get triple clicks at all for GTK2 because we
1726 // suppress them artificially using the code above but we still
1727 // should map them to something for GTK1 and not just ignore them
1728 // as this would lose clicks
1729 case GDK_3BUTTON_PRESS: // we could also map this to DCLICK...
1730 case GDK_BUTTON_PRESS:
1731 event_type = wxEVT_LEFT_DOWN;
1732 break;
1733
1734 case GDK_2BUTTON_PRESS:
1735 event_type = wxEVT_LEFT_DCLICK;
1736 break;
1737
1738 default:
1739 // just to silence gcc warnings
1740 ;
1741 }
1742 }
1743 else if (gdk_event->button == 2)
1744 {
1745 switch (gdk_event->type)
1746 {
1747 case GDK_3BUTTON_PRESS:
1748 case GDK_BUTTON_PRESS:
1749 event_type = wxEVT_MIDDLE_DOWN;
1750 break;
1751
1752 case GDK_2BUTTON_PRESS:
1753 event_type = wxEVT_MIDDLE_DCLICK;
1754 break;
1755
1756 default:
1757 ;
1758 }
1759 }
1760 else if (gdk_event->button == 3)
1761 {
1762 switch (gdk_event->type)
1763 {
1764 case GDK_3BUTTON_PRESS:
1765 case GDK_BUTTON_PRESS:
1766 event_type = wxEVT_RIGHT_DOWN;
1767 break;
1768
1769 case GDK_2BUTTON_PRESS:
1770 event_type = wxEVT_RIGHT_DCLICK;
1771 break;
1772
1773 default:
1774 ;
1775 }
1776 }
1777 else if (gdk_event->button == 4 || gdk_event->button == 5)
1778 {
1779 if (gdk_event->type == GDK_BUTTON_PRESS )
1780 {
1781 event_type = wxEVT_MOUSEWHEEL;
1782 }
1783 }
1784
1785 if ( event_type == wxEVT_NULL )
1786 {
1787 // unknown mouse button or click type
1788 return FALSE;
1789 }
1790
1791 wxMouseEvent event( event_type );
1792 InitMouseEvent( win, event, gdk_event );
1793
1794 AdjustEventButtonState(event);
1795
1796 // wxListBox actually get mouse events from the item, so we need to give it
1797 // a chance to correct this
1798 win->FixUpMouseEvent(widget, event.m_x, event.m_y);
1799
1800 // find the correct window to send the event too: it may be a different one
1801 // from the one which got it at GTK+ level because some control don't have
1802 // their own X window and thus cannot get any events.
1803 if ( !g_captureWindow )
1804 win = FindWindowForMouseEvent(win, event.m_x, event.m_y);
1805
1806 gs_timeLastClick = gdk_event->time;
1807
1808#ifndef __WXGTK20__
1809 if (event_type == wxEVT_LEFT_DCLICK)
1810 {
1811 // GTK 1.2 crashes when intercepting double
1812 // click events from both wxSpinButton and
1813 // wxSpinCtrl
1814 if (GTK_IS_SPIN_BUTTON(win->m_widget))
1815 {
1816 // Just disable this event for now.
1817 return FALSE;
1818 }
1819 }
1820#endif
1821
1822 if (win->GetEventHandler()->ProcessEvent( event ))
1823 {
1824 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_press_event" );
1825 return TRUE;
1826 }
1827
1828 if (event_type == wxEVT_RIGHT_DOWN)
1829 {
1830 // generate a "context menu" event: this is similar to right mouse
1831 // click under many GUIs except that it is generated differently
1832 // (right up under MSW, ctrl-click under Mac, right down here) and
1833 //
1834 // (a) it's a command event and so is propagated to the parent
1835 // (b) under some ports it can be generated from kbd too
1836 // (c) it uses screen coords (because of (a))
1837 wxContextMenuEvent evtCtx(
1838 wxEVT_CONTEXT_MENU,
1839 win->GetId(),
1840 win->ClientToScreen(event.GetPosition()));
1841 evtCtx.SetEventObject(win);
1842 return win->GetEventHandler()->ProcessEvent(evtCtx);
1843 }
1844
1845 return FALSE;
1846}
1847}
1848
1849//-----------------------------------------------------------------------------
1850// "button_release_event"
1851//-----------------------------------------------------------------------------
1852
1853extern "C" {
1854static gint gtk_window_button_release_callback( GtkWidget *widget,
1855 GdkEventButton *gdk_event,
1856 wxWindowGTK *win )
1857{
1858 DEBUG_MAIN_THREAD
1859
1860 if (g_isIdle)
1861 wxapp_install_idle_handler();
1862
1863 if (!win->m_hasVMT) return FALSE;
1864 if (g_blockEventsOnDrag) return FALSE;
1865 if (g_blockEventsOnScroll) return FALSE;
1866
1867 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
1868
1869 wxEventType event_type = wxEVT_NULL;
1870
1871 switch (gdk_event->button)
1872 {
1873 case 1:
1874 event_type = wxEVT_LEFT_UP;
1875 break;
1876
1877 case 2:
1878 event_type = wxEVT_MIDDLE_UP;
1879 break;
1880
1881 case 3:
1882 event_type = wxEVT_RIGHT_UP;
1883 break;
1884
1885 default:
1886 // unknwon button, don't process
1887 return FALSE;
1888 }
1889
1890 wxMouseEvent event( event_type );
1891 InitMouseEvent( win, event, gdk_event );
1892
1893 AdjustEventButtonState(event);
1894
1895 // same wxListBox hack as above
1896 win->FixUpMouseEvent(widget, event.m_x, event.m_y);
1897
1898 if ( !g_captureWindow )
1899 win = FindWindowForMouseEvent(win, event.m_x, event.m_y);
1900
1901 if (win->GetEventHandler()->ProcessEvent( event ))
1902 {
1903 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_release_event" );
1904 return TRUE;
1905 }
1906
1907 return FALSE;
1908}
1909}
1910
1911//-----------------------------------------------------------------------------
1912// "motion_notify_event"
1913//-----------------------------------------------------------------------------
1914
1915extern "C" {
1916static gint gtk_window_motion_notify_callback( GtkWidget *widget,
1917 GdkEventMotion *gdk_event,
1918 wxWindowGTK *win )
1919{
1920 DEBUG_MAIN_THREAD
1921
1922 if (g_isIdle)
1923 wxapp_install_idle_handler();
1924
1925 if (!win->m_hasVMT) return FALSE;
1926 if (g_blockEventsOnDrag) return FALSE;
1927 if (g_blockEventsOnScroll) return FALSE;
1928
1929 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
1930
1931 if (gdk_event->is_hint)
1932 {
1933 int x = 0;
1934 int y = 0;
1935 GdkModifierType state;
1936 gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
1937 gdk_event->x = x;
1938 gdk_event->y = y;
1939 }
1940
1941/*
1942 printf( "OnMotion from " );
1943 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1944 printf( win->GetClassInfo()->GetClassName() );
1945 printf( ".\n" );
1946*/
1947
1948 wxMouseEvent event( wxEVT_MOTION );
1949 InitMouseEvent(win, event, gdk_event);
1950
1951 if ( g_captureWindow )
1952 {
1953 // synthetize a mouse enter or leave event if needed
1954 GdkWindow *winUnderMouse = gdk_window_at_pointer(NULL, NULL);
1955 // This seems to be necessary and actually been added to
1956 // GDK itself in version 2.0.X
1957 gdk_flush();
1958
1959 bool hasMouse = winUnderMouse == gdk_event->window;
1960 if ( hasMouse != g_captureWindowHasMouse )
1961 {
1962 // the mouse changed window
1963 g_captureWindowHasMouse = hasMouse;
1964
1965 wxMouseEvent event(g_captureWindowHasMouse ? wxEVT_ENTER_WINDOW
1966 : wxEVT_LEAVE_WINDOW);
1967 InitMouseEvent(win, event, gdk_event);
1968 event.SetEventObject(win);
1969 win->GetEventHandler()->ProcessEvent(event);
1970 }
1971 }
1972 else // no capture
1973 {
1974 win = FindWindowForMouseEvent(win, event.m_x, event.m_y);
1975 }
1976
1977 if (win->GetEventHandler()->ProcessEvent( event ))
1978 {
1979 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "motion_notify_event" );
1980 return TRUE;
1981 }
1982
1983 return FALSE;
1984}
1985}
1986
1987#ifdef __WXGTK20__
1988//-----------------------------------------------------------------------------
1989// "mouse_wheel_event"
1990//-----------------------------------------------------------------------------
1991
1992extern "C" {
1993static gint gtk_window_wheel_callback (GtkWidget * widget,
1994 GdkEventScroll * gdk_event,
1995 wxWindowGTK * win)
1996{
1997 DEBUG_MAIN_THREAD
1998
1999 if (g_isIdle)
2000 wxapp_install_idle_handler();
2001
2002 wxEventType event_type = wxEVT_NULL;
2003 if (gdk_event->direction == GDK_SCROLL_UP)
2004 event_type = wxEVT_MOUSEWHEEL;
2005 else if (gdk_event->direction == GDK_SCROLL_DOWN)
2006 event_type = wxEVT_MOUSEWHEEL;
2007 else
2008 return FALSE;
2009
2010 wxMouseEvent event( event_type );
2011 // Can't use InitMouse macro because scroll events don't have button
2012 event.SetTimestamp( gdk_event->time );
2013 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
2014 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
2015 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
2016 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
2017 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
2018 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
2019 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
2020 event.m_linesPerAction = 3;
2021 event.m_wheelDelta = 120;
2022 if (gdk_event->direction == GDK_SCROLL_UP)
2023 event.m_wheelRotation = 120;
2024 else
2025 event.m_wheelRotation = -120;
2026
2027 wxPoint pt = win->GetClientAreaOrigin();
2028 event.m_x = (wxCoord)gdk_event->x - pt.x;
2029 event.m_y = (wxCoord)gdk_event->y - pt.y;
2030
2031 event.SetEventObject( win );
2032 event.SetId( win->GetId() );
2033 event.SetTimestamp( gdk_event->time );
2034
2035 if (win->GetEventHandler()->ProcessEvent( event ))
2036 {
2037 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "scroll_event" );
2038 return TRUE;
2039 }
2040
2041 return FALSE;
2042}
2043}
2044
2045//-----------------------------------------------------------------------------
2046// "popup-menu"
2047//-----------------------------------------------------------------------------
2048extern "C" {
2049static gboolean wxgtk_window_popup_menu_callback(GtkWidget*, wxWindowGTK* win)
2050{
2051 wxContextMenuEvent event(
2052 wxEVT_CONTEXT_MENU,
2053 win->GetId(),
2054 wxPoint(-1, -1));
2055 event.SetEventObject(win);
2056 return win->GetEventHandler()->ProcessEvent(event);
2057}
2058}
2059#endif // __WXGTK20__
2060
2061//-----------------------------------------------------------------------------
2062// "focus_in_event"
2063//-----------------------------------------------------------------------------
2064
2065// send the wxChildFocusEvent and wxFocusEvent, common code of
2066// gtk_window_focus_in_callback() and SetFocus()
2067static bool DoSendFocusEvents(wxWindow *win)
2068{
2069 // Notify the parent keeping track of focus for the kbd navigation
2070 // purposes that we got it.
2071 wxChildFocusEvent eventChildFocus(win);
2072 (void)win->GetEventHandler()->ProcessEvent(eventChildFocus);
2073
2074 wxFocusEvent eventFocus(wxEVT_SET_FOCUS, win->GetId());
2075 eventFocus.SetEventObject(win);
2076
2077 return win->GetEventHandler()->ProcessEvent(eventFocus);
2078}
2079
2080extern "C" {
2081static gint gtk_window_focus_in_callback( GtkWidget *widget,
2082 GdkEvent *WXUNUSED(event),
2083 wxWindow *win )
2084{
2085 DEBUG_MAIN_THREAD
2086
2087 if (g_isIdle)
2088 wxapp_install_idle_handler();
2089
2090#ifdef __WXGTK20__
2091 if (win->m_imData)
2092 gtk_im_context_focus_in(win->m_imData->context);
2093#endif
2094
2095 g_focusWindowLast =
2096 g_focusWindow = win;
2097
2098 wxLogTrace(TRACE_FOCUS,
2099 _T("%s: focus in"), win->GetName().c_str());
2100
2101#ifdef HAVE_XIM
2102 if (win->m_ic)
2103 gdk_im_begin(win->m_ic, win->m_wxwindow->window);
2104#endif
2105
2106#if wxUSE_CARET
2107 // caret needs to be informed about focus change
2108 wxCaret *caret = win->GetCaret();
2109 if ( caret )
2110 {
2111 caret->OnSetFocus();
2112 }
2113#endif // wxUSE_CARET
2114
2115 // does the window itself think that it has the focus?
2116 if ( !win->m_hasFocus )
2117 {
2118 // not yet, notify it
2119 win->m_hasFocus = TRUE;
2120
2121 if ( DoSendFocusEvents(win) )
2122 {
2123 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_in_event" );
2124 return TRUE;
2125 }
2126 }
2127
2128 return FALSE;
2129}
2130}
2131
2132//-----------------------------------------------------------------------------
2133// "focus_out_event"
2134//-----------------------------------------------------------------------------
2135
2136extern "C" {
2137static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk_event, wxWindowGTK *win )
2138{
2139 DEBUG_MAIN_THREAD
2140
2141 if (g_isIdle)
2142 wxapp_install_idle_handler();
2143
2144#ifdef __WXGTK20__
2145 if (win->m_imData)
2146 gtk_im_context_focus_out(win->m_imData->context);
2147#endif
2148
2149 wxLogTrace( TRACE_FOCUS,
2150 _T("%s: focus out"), win->GetName().c_str() );
2151
2152
2153 wxWindowGTK *winFocus = wxFindFocusedChild(win);
2154 if ( winFocus )
2155 win = winFocus;
2156
2157 g_focusWindow = (wxWindowGTK *)NULL;
2158
2159#ifdef HAVE_XIM
2160 if (win->m_ic)
2161 gdk_im_end();
2162#endif
2163
2164#if wxUSE_CARET
2165 // caret needs to be informed about focus change
2166 wxCaret *caret = win->GetCaret();
2167 if ( caret )
2168 {
2169 caret->OnKillFocus();
2170 }
2171#endif // wxUSE_CARET
2172
2173 // don't send the window a kill focus event if it thinks that it doesn't
2174 // have focus already
2175 if ( win->m_hasFocus )
2176 {
2177 win->m_hasFocus = FALSE;
2178
2179 wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() );
2180 event.SetEventObject( win );
2181
2182 // even if we did process the event in wx code, still let GTK itself
2183 // process it too as otherwise bad things happen, especially in GTK2
2184 // where the text control simply aborts the program if it doesn't get
2185 // the matching focus out event
2186 (void)win->GetEventHandler()->ProcessEvent( event );
2187 }
2188
2189 return FALSE;
2190}
2191}
2192
2193//-----------------------------------------------------------------------------
2194// "enter_notify_event"
2195//-----------------------------------------------------------------------------
2196
2197extern "C" {
2198static
2199gint gtk_window_enter_callback( GtkWidget *widget,
2200 GdkEventCrossing *gdk_event,
2201 wxWindowGTK *win )
2202{
2203 DEBUG_MAIN_THREAD
2204
2205 if (g_isIdle)
2206 wxapp_install_idle_handler();
2207
2208 if (!win->m_hasVMT) return FALSE;
2209 if (g_blockEventsOnDrag) return FALSE;
2210
2211 // Event was emitted after a grab
2212 if (gdk_event->mode != GDK_CROSSING_NORMAL) return FALSE;
2213
2214 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
2215
2216 int x = 0;
2217 int y = 0;
2218 GdkModifierType state = (GdkModifierType)0;
2219
2220 gdk_window_get_pointer( widget->window, &x, &y, &state );
2221
2222 wxMouseEvent event( wxEVT_ENTER_WINDOW );
2223 InitMouseEvent(win, event, gdk_event);
2224 wxPoint pt = win->GetClientAreaOrigin();
2225 event.m_x = x + pt.x;
2226 event.m_y = y + pt.y;
2227
2228 if (win->GetEventHandler()->ProcessEvent( event ))
2229 {
2230 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "enter_notify_event" );
2231 return TRUE;
2232 }
2233
2234 return FALSE;
2235}
2236}
2237
2238//-----------------------------------------------------------------------------
2239// "leave_notify_event"
2240//-----------------------------------------------------------------------------
2241
2242extern "C" {
2243static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindowGTK *win )
2244{
2245 DEBUG_MAIN_THREAD
2246
2247 if (g_isIdle)
2248 wxapp_install_idle_handler();
2249
2250 if (!win->m_hasVMT) return FALSE;
2251 if (g_blockEventsOnDrag) return FALSE;
2252
2253 // Event was emitted after an ungrab
2254 if (gdk_event->mode != GDK_CROSSING_NORMAL) return FALSE;
2255
2256 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
2257
2258 wxMouseEvent event( wxEVT_LEAVE_WINDOW );
2259 event.SetTimestamp( gdk_event->time );
2260 event.SetEventObject( win );
2261
2262 int x = 0;
2263 int y = 0;
2264 GdkModifierType state = (GdkModifierType)0;
2265
2266 gdk_window_get_pointer( widget->window, &x, &y, &state );
2267
2268 event.m_shiftDown = (state & GDK_SHIFT_MASK) != 0;
2269 event.m_controlDown = (state & GDK_CONTROL_MASK) != 0;
2270 event.m_altDown = (state & GDK_MOD1_MASK) != 0;
2271 event.m_metaDown = (state & GDK_MOD2_MASK) != 0;
2272 event.m_leftDown = (state & GDK_BUTTON1_MASK) != 0;
2273 event.m_middleDown = (state & GDK_BUTTON2_MASK) != 0;
2274 event.m_rightDown = (state & GDK_BUTTON3_MASK) != 0;
2275
2276 wxPoint pt = win->GetClientAreaOrigin();
2277 event.m_x = x + pt.x;
2278 event.m_y = y + pt.y;
2279
2280 if (win->GetEventHandler()->ProcessEvent( event ))
2281 {
2282 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "leave_notify_event" );
2283 return TRUE;
2284 }
2285
2286 return FALSE;
2287}
2288}
2289
2290//-----------------------------------------------------------------------------
2291// "value_changed" from m_vAdjust
2292//-----------------------------------------------------------------------------
2293
2294extern "C" {
2295static void gtk_window_vscroll_callback( GtkAdjustment *adjust,
2296 SCROLLBAR_CBACK_ARG
2297 wxWindowGTK *win )
2298{
2299 DEBUG_MAIN_THREAD
2300
2301 if (g_isIdle)
2302 wxapp_install_idle_handler();
2303
2304 if (g_blockEventsOnDrag) return;
2305
2306 if (!win->m_hasVMT) return;
2307
2308 float diff = adjust->value - win->m_oldVerticalPos;
2309 if (fabs(diff) < 0.2) return;
2310
2311 win->m_oldVerticalPos = adjust->value;
2312
2313#ifndef __WXGTK20__
2314 GtkScrolledWindow *sw = GTK_SCROLLED_WINDOW(win->m_widget);
2315#endif
2316 wxEventType command = GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw->vscrollbar));
2317
2318 int value = (int)(adjust->value+0.5);
2319
2320 wxScrollWinEvent event( command, value, wxVERTICAL );
2321 event.SetEventObject( win );
2322 win->GetEventHandler()->ProcessEvent( event );
2323}
2324}
2325
2326//-----------------------------------------------------------------------------
2327// "value_changed" from m_hAdjust
2328//-----------------------------------------------------------------------------
2329
2330extern "C" {
2331static void gtk_window_hscroll_callback( GtkAdjustment *adjust,
2332 SCROLLBAR_CBACK_ARG
2333 wxWindowGTK *win )
2334{
2335 DEBUG_MAIN_THREAD
2336
2337 if (g_isIdle)
2338 wxapp_install_idle_handler();
2339
2340 if (g_blockEventsOnDrag) return;
2341 if (!win->m_hasVMT) return;
2342
2343 float diff = adjust->value - win->m_oldHorizontalPos;
2344 if (fabs(diff) < 0.2) return;
2345
2346#ifndef __WXGTK20__
2347 GtkScrolledWindow *sw = GTK_SCROLLED_WINDOW(win->m_widget);
2348#endif
2349 wxEventType command = GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw->hscrollbar));
2350
2351 win->m_oldHorizontalPos = adjust->value;
2352
2353 int value = (int)(adjust->value+0.5);
2354
2355 wxScrollWinEvent event( command, value, wxHORIZONTAL );
2356 event.SetEventObject( win );
2357 win->GetEventHandler()->ProcessEvent( event );
2358}
2359}
2360
2361//-----------------------------------------------------------------------------
2362// "button_press_event" from scrollbar
2363//-----------------------------------------------------------------------------
2364
2365extern "C" {
2366static gint gtk_scrollbar_button_press_callback( GtkRange *widget,
2367 GdkEventButton *gdk_event,
2368 wxWindowGTK *win)
2369{
2370 DEBUG_MAIN_THREAD
2371
2372 if (g_isIdle)
2373 wxapp_install_idle_handler();
2374
2375
2376 g_blockEventsOnScroll = TRUE;
2377
2378 // FIXME: there is no 'slider' field in GTK+ 2.0 any more
2379#ifndef __WXGTK20__
2380 win->m_isScrolling = (gdk_event->window == widget->slider);
2381#endif
2382
2383 return FALSE;
2384}
2385}
2386
2387//-----------------------------------------------------------------------------
2388// "button_release_event" from scrollbar
2389//-----------------------------------------------------------------------------
2390
2391extern "C" {
2392static gint gtk_scrollbar_button_release_callback( GtkRange *widget,
2393 GdkEventButton *WXUNUSED(gdk_event),
2394 wxWindowGTK *win)
2395{
2396 DEBUG_MAIN_THREAD
2397
2398// don't test here as we can release the mouse while being over
2399// a different window than the slider
2400//
2401// if (gdk_event->window != widget->slider) return FALSE;
2402
2403 g_blockEventsOnScroll = FALSE;
2404
2405 if (win->m_isScrolling)
2406 {
2407 wxEventType command = wxEVT_SCROLLWIN_THUMBRELEASE;
2408 int value = -1;
2409 int dir = -1;
2410
2411 GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(win->m_widget);
2412 if (widget == GTK_RANGE(scrolledWindow->hscrollbar))
2413 {
2414 value = (int)(win->m_hAdjust->value+0.5);
2415 dir = wxHORIZONTAL;
2416 }
2417 if (widget == GTK_RANGE(scrolledWindow->vscrollbar))
2418 {
2419 value = (int)(win->m_vAdjust->value+0.5);
2420 dir = wxVERTICAL;
2421 }
2422
2423 wxScrollWinEvent event( command, value, dir );
2424 event.SetEventObject( win );
2425 win->GetEventHandler()->ProcessEvent( event );
2426 }
2427
2428 win->m_isScrolling = FALSE;
2429
2430 return FALSE;
2431}
2432}
2433
2434// ----------------------------------------------------------------------------
2435// this wxWindowBase function is implemented here (in platform-specific file)
2436// because it is static and so couldn't be made virtual
2437// ----------------------------------------------------------------------------
2438
2439wxWindow *wxWindowBase::DoFindFocus()
2440{
2441 // the cast is necessary when we compile in wxUniversal mode
2442 return (wxWindow *)g_focusWindow;
2443}
2444
2445//-----------------------------------------------------------------------------
2446// "realize" from m_widget
2447//-----------------------------------------------------------------------------
2448
2449/* We cannot set colours and fonts before the widget has
2450 been realized, so we do this directly after realization. */
2451
2452extern "C" {
2453static gint
2454gtk_window_realized_callback( GtkWidget *m_widget, wxWindow *win )
2455{
2456 DEBUG_MAIN_THREAD
2457
2458 if (g_isIdle)
2459 wxapp_install_idle_handler();
2460
2461#ifdef __WXGTK20__
2462 if (win->m_imData)
2463 {
2464 GtkPizza *pizza = GTK_PIZZA( m_widget );
2465 gtk_im_context_set_client_window( win->m_imData->context,
2466 pizza->bin_window );
2467 }
2468#endif
2469
2470 wxWindowCreateEvent event( win );
2471 event.SetEventObject( win );
2472 win->GetEventHandler()->ProcessEvent( event );
2473
2474 return FALSE;
2475}
2476}
2477
2478//-----------------------------------------------------------------------------
2479// "size_allocate"
2480//-----------------------------------------------------------------------------
2481
2482extern "C" {
2483static
2484void gtk_window_size_callback( GtkWidget *WXUNUSED(widget),
2485 GtkAllocation *WXUNUSED(alloc),
2486 wxWindow *win )
2487{
2488 if (g_isIdle)
2489 wxapp_install_idle_handler();
2490
2491 if (!win->m_hasScrolling) return;
2492
2493 int client_width = 0;
2494 int client_height = 0;
2495 win->GetClientSize( &client_width, &client_height );
2496 if ((client_width == win->m_oldClientWidth) && (client_height == win->m_oldClientHeight))
2497 return;
2498
2499 win->m_oldClientWidth = client_width;
2500 win->m_oldClientHeight = client_height;
2501
2502 if (!win->m_nativeSizeEvent)
2503 {
2504 wxSizeEvent event( win->GetSize(), win->GetId() );
2505 event.SetEventObject( win );
2506 win->GetEventHandler()->ProcessEvent( event );
2507 }
2508}
2509}
2510
2511
2512#ifdef HAVE_XIM
2513 #define WXUNUSED_UNLESS_XIM(param) param
2514#else
2515 #define WXUNUSED_UNLESS_XIM(param) WXUNUSED(param)
2516#endif
2517
2518/* Resize XIM window */
2519
2520extern "C" {
2521static
2522void gtk_wxwindow_size_callback( GtkWidget* WXUNUSED_UNLESS_XIM(widget),
2523 GtkAllocation* WXUNUSED_UNLESS_XIM(alloc),
2524 wxWindowGTK* WXUNUSED_UNLESS_XIM(win) )
2525{
2526 if (g_isIdle)
2527 wxapp_install_idle_handler();
2528
2529#ifdef HAVE_XIM
2530 if (!win->m_ic)
2531 return;
2532
2533 if (gdk_ic_get_style (win->m_ic) & GDK_IM_PREEDIT_POSITION)
2534 {
2535 gint width, height;
2536
2537 gdk_window_get_size (widget->window, &width, &height);
2538 win->m_icattr->preedit_area.width = width;
2539 win->m_icattr->preedit_area.height = height;
2540 gdk_ic_set_attr (win->m_ic, win->m_icattr, GDK_IC_PREEDIT_AREA);
2541 }
2542#endif // HAVE_XIM
2543}
2544}
2545
2546//-----------------------------------------------------------------------------
2547// "realize" from m_wxwindow
2548//-----------------------------------------------------------------------------
2549
2550/* Initialize XIM support */
2551
2552extern "C" {
2553static gint
2554gtk_wxwindow_realized_callback( GtkWidget * WXUNUSED_UNLESS_XIM(widget),
2555 wxWindowGTK * WXUNUSED_UNLESS_XIM(win) )
2556{
2557 if (g_isIdle)
2558 wxapp_install_idle_handler();
2559
2560#ifdef HAVE_XIM
2561 if (win->m_ic) return FALSE;
2562 if (!widget) return FALSE;
2563 if (!gdk_im_ready()) return FALSE;
2564
2565 win->m_icattr = gdk_ic_attr_new();
2566 if (!win->m_icattr) return FALSE;
2567
2568 gint width, height;
2569 GdkEventMask mask;
2570 GdkColormap *colormap;
2571 GdkICAttr *attr = win->m_icattr;
2572 unsigned attrmask = GDK_IC_ALL_REQ;
2573 GdkIMStyle style;
2574 GdkIMStyle supported_style = (GdkIMStyle)
2575 (GDK_IM_PREEDIT_NONE |
2576 GDK_IM_PREEDIT_NOTHING |
2577 GDK_IM_PREEDIT_POSITION |
2578 GDK_IM_STATUS_NONE |
2579 GDK_IM_STATUS_NOTHING);
2580
2581 if (widget->style && widget->style->font->type != GDK_FONT_FONTSET)
2582 supported_style = (GdkIMStyle)(supported_style & ~GDK_IM_PREEDIT_POSITION);
2583
2584 attr->style = style = gdk_im_decide_style (supported_style);
2585 attr->client_window = widget->window;
2586
2587 if ((colormap = gtk_widget_get_colormap (widget)) !=
2588 gtk_widget_get_default_colormap ())
2589 {
2590 attrmask |= GDK_IC_PREEDIT_COLORMAP;
2591 attr->preedit_colormap = colormap;
2592 }
2593
2594 attrmask |= GDK_IC_PREEDIT_FOREGROUND;
2595 attrmask |= GDK_IC_PREEDIT_BACKGROUND;
2596 attr->preedit_foreground = widget->style->fg[GTK_STATE_NORMAL];
2597 attr->preedit_background = widget->style->base[GTK_STATE_NORMAL];
2598
2599 switch (style & GDK_IM_PREEDIT_MASK)
2600 {
2601 case GDK_IM_PREEDIT_POSITION:
2602 if (widget->style && widget->style->font->type != GDK_FONT_FONTSET)
2603 {
2604 g_warning ("over-the-spot style requires fontset");
2605 break;
2606 }
2607
2608 gdk_window_get_size (widget->window, &width, &height);
2609
2610 attrmask |= GDK_IC_PREEDIT_POSITION_REQ;
2611 attr->spot_location.x = 0;
2612 attr->spot_location.y = height;
2613 attr->preedit_area.x = 0;
2614 attr->preedit_area.y = 0;
2615 attr->preedit_area.width = width;
2616 attr->preedit_area.height = height;
2617 attr->preedit_fontset = widget->style->font;
2618
2619 break;
2620 }
2621
2622 win->m_ic = gdk_ic_new (attr, (GdkICAttributesType)attrmask);
2623
2624 if (win->m_ic == NULL)
2625 g_warning ("Can't create input context.");
2626 else
2627 {
2628 mask = gdk_window_get_events (widget->window);
2629 mask = (GdkEventMask)(mask | gdk_ic_get_events (win->m_ic));
2630 gdk_window_set_events (widget->window, mask);
2631
2632 if (GTK_WIDGET_HAS_FOCUS(widget))
2633 gdk_im_begin (win->m_ic, widget->window);
2634 }
2635#endif // HAVE_XIM
2636
2637 return FALSE;
2638}
2639}
2640
2641//-----------------------------------------------------------------------------
2642// InsertChild for wxWindowGTK.
2643//-----------------------------------------------------------------------------
2644
2645/* Callback for wxWindowGTK. This very strange beast has to be used because
2646 * C++ has no virtual methods in a constructor. We have to emulate a
2647 * virtual function here as wxNotebook requires a different way to insert
2648 * a child in it. I had opted for creating a wxNotebookPage window class
2649 * which would have made this superfluous (such in the MDI window system),
2650 * but no-one was listening to me... */
2651
2652static void wxInsertChildInWindow( wxWindowGTK* parent, wxWindowGTK* child )
2653{
2654 /* the window might have been scrolled already, do we
2655 have to adapt the position */
2656 GtkPizza *pizza = GTK_PIZZA(parent->m_wxwindow);
2657 child->m_x += pizza->xoffset;
2658 child->m_y += pizza->yoffset;
2659
2660 gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow),
2661 GTK_WIDGET(child->m_widget),
2662 child->m_x,
2663 child->m_y,
2664 child->m_width,
2665 child->m_height );
2666}
2667
2668//-----------------------------------------------------------------------------
2669// global functions
2670//-----------------------------------------------------------------------------
2671
2672wxWindow *wxGetActiveWindow()
2673{
2674 return wxWindow::FindFocus();
2675}
2676
2677//-----------------------------------------------------------------------------
2678// wxWindowGTK
2679//-----------------------------------------------------------------------------
2680
2681// in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2682// method
2683#ifdef __WXUNIVERSAL__
2684 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK, wxWindowBase)
2685#else // __WXGTK__
2686 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
2687#endif // __WXUNIVERSAL__/__WXGTK__
2688
2689void wxWindowGTK::Init()
2690{
2691 // GTK specific
2692 m_widget = (GtkWidget *) NULL;
2693 m_wxwindow = (GtkWidget *) NULL;
2694 m_focusWidget = (GtkWidget *) NULL;
2695
2696 // position/size
2697 m_x = 0;
2698 m_y = 0;
2699 m_width = 0;
2700 m_height = 0;
2701
2702 m_sizeSet = FALSE;
2703 m_hasVMT = FALSE;
2704 m_needParent = TRUE;
2705 m_isBeingDeleted = FALSE;
2706
2707 m_noExpose = FALSE;
2708 m_nativeSizeEvent = FALSE;
2709
2710 m_hasScrolling = FALSE;
2711 m_isScrolling = FALSE;
2712
2713 m_hAdjust = (GtkAdjustment*) NULL;
2714 m_vAdjust = (GtkAdjustment*) NULL;
2715 m_oldHorizontalPos =
2716 m_oldVerticalPos = 0.0;
2717 m_oldClientWidth =
2718 m_oldClientHeight = 0;
2719
2720 m_resizing = FALSE;
2721
2722 m_insertCallback = (wxInsertChildFunction) NULL;
2723
2724 m_acceptsFocus = FALSE;
2725 m_hasFocus = FALSE;
2726
2727 m_clipPaintRegion = FALSE;
2728
2729 m_needsStyleChange = false;
2730
2731 m_cursor = *wxSTANDARD_CURSOR;
2732
2733#ifdef __WXGTK20__
2734 m_imData = NULL;
2735 m_x11Context = NULL;
2736 m_dirtyTabOrder = false;
2737#else
2738#ifdef HAVE_XIM
2739 m_ic = (GdkIC*) NULL;
2740 m_icattr = (GdkICAttr*) NULL;
2741#endif
2742#endif
2743}
2744
2745wxWindowGTK::wxWindowGTK()
2746{
2747 Init();
2748}
2749
2750wxWindowGTK::wxWindowGTK( wxWindow *parent,
2751 wxWindowID id,
2752 const wxPoint &pos,
2753 const wxSize &size,
2754 long style,
2755 const wxString &name )
2756{
2757 Init();
2758
2759 Create( parent, id, pos, size, style, name );
2760}
2761
2762bool wxWindowGTK::Create( wxWindow *parent,
2763 wxWindowID id,
2764 const wxPoint &pos,
2765 const wxSize &size,
2766 long style,
2767 const wxString &name )
2768{
2769 if (!PreCreation( parent, pos, size ) ||
2770 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
2771 {
2772 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2773 return FALSE;
2774 }
2775
2776 m_insertCallback = wxInsertChildInWindow;
2777
2778 m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
2779 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
2780
2781 GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget);
2782
2783 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget) );
2784 scroll_class->scrollbar_spacing = 0;
2785
2786 gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
2787
2788 m_hAdjust = gtk_range_get_adjustment( GTK_RANGE(scrolledWindow->hscrollbar) );
2789 m_vAdjust = gtk_range_get_adjustment( GTK_RANGE(scrolledWindow->vscrollbar) );
2790
2791 m_wxwindow = gtk_pizza_new();
2792
2793#ifndef __WXUNIVERSAL__
2794 GtkPizza *pizza = GTK_PIZZA(m_wxwindow);
2795
2796 if (HasFlag(wxRAISED_BORDER))
2797 {
2798 gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_OUT );
2799 }
2800 else if (HasFlag(wxSUNKEN_BORDER))
2801 {
2802 gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_IN );
2803 }
2804 else if (HasFlag(wxSIMPLE_BORDER))
2805 {
2806 gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_THIN );
2807 }
2808 else
2809 {
2810 gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_NONE );
2811 }
2812#endif // __WXUNIVERSAL__
2813
2814 gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
2815
2816 GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
2817 m_acceptsFocus = TRUE;
2818
2819 // I _really_ don't want scrollbars in the beginning
2820 m_vAdjust->lower = 0.0;
2821 m_vAdjust->upper = 1.0;
2822 m_vAdjust->value = 0.0;
2823 m_vAdjust->step_increment = 1.0;
2824 m_vAdjust->page_increment = 1.0;
2825 m_vAdjust->page_size = 5.0;
2826 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
2827 m_hAdjust->lower = 0.0;
2828 m_hAdjust->upper = 1.0;
2829 m_hAdjust->value = 0.0;
2830 m_hAdjust->step_increment = 1.0;
2831 m_hAdjust->page_increment = 1.0;
2832 m_hAdjust->page_size = 5.0;
2833 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
2834
2835 // these handlers block mouse events to any window during scrolling such as
2836 // motion events and prevent GTK and wxWidgets from fighting over where the
2837 // slider should be
2838
2839 gtk_signal_connect( GTK_OBJECT(scrolledWindow->vscrollbar), "button_press_event",
2840 (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this );
2841
2842 gtk_signal_connect( GTK_OBJECT(scrolledWindow->hscrollbar), "button_press_event",
2843 (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this );
2844
2845 gtk_signal_connect( GTK_OBJECT(scrolledWindow->vscrollbar), "button_release_event",
2846 (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this );
2847
2848 gtk_signal_connect( GTK_OBJECT(scrolledWindow->hscrollbar), "button_release_event",
2849 (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this );
2850
2851 // these handlers get notified when screen updates are required either when
2852 // scrolling or when the window size (and therefore scrollbar configuration)
2853 // has changed
2854
2855 gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed",
2856 (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this );
2857 gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed",
2858 (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this );
2859
2860 gtk_widget_show( m_wxwindow );
2861
2862 if (m_parent)
2863 m_parent->DoAddChild( this );
2864
2865 m_focusWidget = m_wxwindow;
2866
2867 PostCreation();
2868
2869 return TRUE;
2870}
2871
2872wxWindowGTK::~wxWindowGTK()
2873{
2874 SendDestroyEvent();
2875
2876 if (g_focusWindow == this)
2877 g_focusWindow = NULL;
2878
2879 if ( g_delayedFocus == this )
2880 g_delayedFocus = NULL;
2881
2882 m_isBeingDeleted = TRUE;
2883 m_hasVMT = FALSE;
2884
2885 if (m_widget)
2886 Show( FALSE );
2887
2888 DestroyChildren();
2889
2890#ifdef HAVE_XIM
2891 if (m_ic)
2892 gdk_ic_destroy (m_ic);
2893 if (m_icattr)
2894 gdk_ic_attr_destroy (m_icattr);
2895#endif
2896
2897 if (m_wxwindow)
2898 {
2899 gtk_widget_destroy( m_wxwindow );
2900 m_wxwindow = (GtkWidget*) NULL;
2901 }
2902
2903 if (m_widget)
2904 {
2905 gtk_widget_destroy( m_widget );
2906 m_widget = (GtkWidget*) NULL;
2907 }
2908
2909#ifdef __WXGTK20__
2910 delete m_imData;
2911#endif
2912}
2913
2914bool wxWindowGTK::PreCreation( wxWindowGTK *parent, const wxPoint &pos, const wxSize &size )
2915{
2916 wxCHECK_MSG( !m_needParent || parent, FALSE, wxT("Need complete parent.") );
2917
2918 // Use either the given size, or the default if -1 is given.
2919 // See wxWindowBase for these functions.
2920 m_width = WidthDefault(size.x) ;
2921 m_height = HeightDefault(size.y);
2922
2923 m_x = (int)pos.x;
2924 m_y = (int)pos.y;
2925
2926 return TRUE;
2927}
2928
2929void wxWindowGTK::PostCreation()
2930{
2931 wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") );
2932
2933 if (m_wxwindow)
2934 {
2935 if (!m_noExpose)
2936 {
2937 // these get reported to wxWidgets -> wxPaintEvent
2938
2939 gtk_pizza_set_external( GTK_PIZZA(m_wxwindow), TRUE );
2940
2941 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event",
2942 GTK_SIGNAL_FUNC(gtk_window_expose_callback), (gpointer)this );
2943
2944#ifndef __WXGTK20__
2945 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw",
2946 GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this );
2947
2948 if (!HasFlag(wxFULL_REPAINT_ON_RESIZE))
2949 {
2950 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "event",
2951 GTK_SIGNAL_FUNC(gtk_window_event_event_callback), (gpointer)this );
2952 }
2953#else
2954 // gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow), !HasFlag( wxFULL_REPAINT_ON_RESIZE ) );
2955#endif
2956 }
2957
2958#ifdef __WXGTK20__
2959 // Create input method handler
2960 m_imData = new wxGtkIMData;
2961
2962 // Cannot handle drawing preedited text yet
2963 gtk_im_context_set_use_preedit( m_imData->context, FALSE );
2964
2965 g_signal_connect (G_OBJECT (m_imData->context), "commit",
2966 G_CALLBACK (gtk_wxwindow_commit_cb), this);
2967#endif
2968
2969 // these are called when the "sunken" or "raised" borders are drawn
2970 gtk_signal_connect( GTK_OBJECT(m_widget), "expose_event",
2971 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
2972
2973#ifndef __WXGTK20__
2974 gtk_signal_connect( GTK_OBJECT(m_widget), "draw",
2975 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
2976#endif
2977 }
2978
2979 // focus handling
2980
2981 if (!GTK_IS_WINDOW(m_widget))
2982 {
2983 if (m_focusWidget == NULL)
2984 m_focusWidget = m_widget;
2985
2986 gtk_signal_connect( GTK_OBJECT(m_focusWidget), "focus_in_event",
2987 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
2988
2989 gtk_signal_connect_after( GTK_OBJECT(m_focusWidget), "focus_out_event",
2990 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
2991 }
2992
2993 // connect to the various key and mouse handlers
2994
2995 GtkWidget *connect_widget = GetConnectWidget();
2996
2997 ConnectWidget( connect_widget );
2998
2999 /* We cannot set colours, fonts and cursors before the widget has
3000 been realized, so we do this directly after realization */
3001 gtk_signal_connect( GTK_OBJECT(connect_widget), "realize",
3002 GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this );
3003
3004 if (m_wxwindow)
3005 {
3006 // Catch native resize events
3007 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "size_allocate",
3008 GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this );
3009
3010 // Initialize XIM support
3011 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "realize",
3012 GTK_SIGNAL_FUNC(gtk_wxwindow_realized_callback), (gpointer) this );
3013
3014 // And resize XIM window
3015 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "size_allocate",
3016 GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback), (gpointer)this );
3017 }
3018
3019 if (GTK_IS_COMBO(m_widget))
3020 {
3021 GtkCombo *gcombo = GTK_COMBO(m_widget);
3022
3023 gtk_signal_connect( GTK_OBJECT(gcombo->entry), "size_request",
3024 GTK_SIGNAL_FUNC(wxgtk_combo_size_request_callback),
3025 (gpointer) this );
3026 }
3027 else
3028 {
3029 // This is needed if we want to add our windows into native
3030 // GTK controls, such as the toolbar. With this callback, the
3031 // toolbar gets to know the correct size (the one set by the
3032 // programmer). Sadly, it misbehaves for wxComboBox.
3033 gtk_signal_connect( GTK_OBJECT(m_widget), "size_request",
3034 GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback),
3035 (gpointer) this );
3036 }
3037
3038 InheritAttributes();
3039
3040 m_hasVMT = TRUE;
3041
3042 // unless the window was created initially hidden (i.e. Hide() had been
3043 // called before Create()), we should show it at GTK+ level as well
3044 if ( IsShown() )
3045 gtk_widget_show( m_widget );
3046}
3047
3048void wxWindowGTK::ConnectWidget( GtkWidget *widget )
3049{
3050 gtk_signal_connect( GTK_OBJECT(widget), "key_press_event",
3051 GTK_SIGNAL_FUNC(gtk_window_key_press_callback), (gpointer)this );
3052
3053 gtk_signal_connect( GTK_OBJECT(widget), "key_release_event",
3054 GTK_SIGNAL_FUNC(gtk_window_key_release_callback), (gpointer)this );
3055
3056 gtk_signal_connect( GTK_OBJECT(widget), "button_press_event",
3057 GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this );
3058
3059 gtk_signal_connect( GTK_OBJECT(widget), "button_release_event",
3060 GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
3061
3062 gtk_signal_connect( GTK_OBJECT(widget), "motion_notify_event",
3063 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
3064
3065#ifdef __WXGTK20__
3066 gtk_signal_connect( GTK_OBJECT(widget), "scroll_event",
3067 GTK_SIGNAL_FUNC(gtk_window_wheel_callback), (gpointer)this );
3068 g_signal_connect(widget, "popup_menu",
3069 G_CALLBACK(wxgtk_window_popup_menu_callback), this);
3070#endif
3071
3072 gtk_signal_connect( GTK_OBJECT(widget), "enter_notify_event",
3073 GTK_SIGNAL_FUNC(gtk_window_enter_callback), (gpointer)this );
3074
3075 gtk_signal_connect( GTK_OBJECT(widget), "leave_notify_event",
3076 GTK_SIGNAL_FUNC(gtk_window_leave_callback), (gpointer)this );
3077}
3078
3079bool wxWindowGTK::Destroy()
3080{
3081 wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") );
3082
3083 m_hasVMT = FALSE;
3084
3085 return wxWindowBase::Destroy();
3086}
3087
3088void wxWindowGTK::DoMoveWindow(int x, int y, int width, int height)
3089{
3090 gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), m_widget, x, y, width, height );
3091}
3092
3093void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags )
3094{
3095 wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") );
3096 wxASSERT_MSG( (m_parent != NULL), wxT("wxWindowGTK::SetSize requires parent.\n") );
3097
3098/*
3099 printf( "DoSetSize: name %s, x,y,w,h: %d,%d,%d,%d \n", GetName().c_str(), x,y,width,height );
3100*/
3101
3102 if (m_resizing) return; /* I don't like recursions */
3103 m_resizing = TRUE;
3104
3105 int currentX, currentY;
3106 GetPosition(&currentX, &currentY);
3107 if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
3108 x = currentX;
3109 if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
3110 y = currentY;
3111 AdjustForParentClientOrigin(x, y, sizeFlags);
3112
3113 if (m_parent->m_wxwindow == NULL) /* i.e. wxNotebook */
3114 {
3115 /* don't set the size for children of wxNotebook, just take the values. */
3116 m_x = x;
3117 m_y = y;
3118 m_width = width;
3119 m_height = height;
3120 }
3121 else
3122 {
3123 GtkPizza *pizza = GTK_PIZZA(m_parent->m_wxwindow);
3124 if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0)
3125 {
3126 if (x != -1) m_x = x + pizza->xoffset;
3127 if (y != -1) m_y = y + pizza->yoffset;
3128 }
3129 else
3130 {
3131 m_x = x + pizza->xoffset;
3132 m_y = y + pizza->yoffset;
3133 }
3134
3135 // calculate the best size if we should auto size the window
3136 if ( ((sizeFlags & wxSIZE_AUTO_WIDTH) && width == -1) ||
3137 ((sizeFlags & wxSIZE_AUTO_HEIGHT) && height == -1) )
3138 {
3139 const wxSize sizeBest = GetBestSize();
3140 if ( (sizeFlags & wxSIZE_AUTO_WIDTH) && width == -1 )
3141 width = sizeBest.x;
3142 if ( (sizeFlags & wxSIZE_AUTO_HEIGHT) && height == -1 )
3143 height = sizeBest.y;
3144 }
3145
3146 if (width != -1)
3147 m_width = width;
3148 if (height != -1)
3149 m_height = height;
3150
3151 int minWidth = GetMinWidth(),
3152 minHeight = GetMinHeight(),
3153 maxWidth = GetMaxWidth(),
3154 maxHeight = GetMaxHeight();
3155
3156 if ((minWidth != -1) && (m_width < minWidth)) m_width = minWidth;
3157 if ((minHeight != -1) && (m_height < minHeight)) m_height = minHeight;
3158 if ((maxWidth != -1) && (m_width > maxWidth)) m_width = maxWidth;
3159 if ((maxHeight != -1) && (m_height > maxHeight)) m_height = maxHeight;
3160
3161 int left_border = 0;
3162 int right_border = 0;
3163 int top_border = 0;
3164 int bottom_border = 0;
3165
3166 /* the default button has a border around it */
3167 if (GTK_WIDGET_CAN_DEFAULT(m_widget))
3168 {
3169#ifdef __WXGTK20__
3170 GtkBorder *default_border = NULL;
3171 gtk_widget_style_get( m_widget, "default_border", &default_border, NULL );
3172 if (default_border)
3173 {
3174 left_border += default_border->left;
3175 right_border += default_border->right;
3176 top_border += default_border->top;
3177 bottom_border += default_border->bottom;
3178 g_free( default_border );
3179 }
3180#else
3181 left_border = 6;
3182 right_border = 6;
3183 top_border = 6;
3184 bottom_border = 5;
3185#endif
3186 }
3187
3188 DoMoveWindow( m_x-top_border,
3189 m_y-left_border,
3190 m_width+left_border+right_border,
3191 m_height+top_border+bottom_border );
3192 }
3193
3194 if (m_hasScrolling)
3195 {
3196 /* Sometimes the client area changes size without the
3197 whole windows's size changing, but if the whole
3198 windows's size doesn't change, no wxSizeEvent will
3199 normally be sent. Here we add an extra test if
3200 the client test has been changed and this will
3201 be used then. */
3202 GetClientSize( &m_oldClientWidth, &m_oldClientHeight );
3203 }
3204
3205/*
3206 wxPrintf( "OnSize sent from " );
3207 if (GetClassInfo() && GetClassInfo()->GetClassName())
3208 wxPrintf( GetClassInfo()->GetClassName() );
3209 wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height );
3210*/
3211
3212 if (!m_nativeSizeEvent)
3213 {
3214 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
3215 event.SetEventObject( this );
3216 GetEventHandler()->ProcessEvent( event );
3217 }
3218
3219 m_resizing = FALSE;
3220}
3221
3222void wxWindowGTK::OnInternalIdle()
3223{
3224#ifdef __WXGTK20__
3225 if ( m_dirtyTabOrder )
3226 RealizeTabOrder();
3227#endif
3228 // Update style if the window was not yet realized
3229 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
3230 if (m_needsStyleChange)
3231 {
3232 SetBackgroundStyle(GetBackgroundStyle());
3233 m_needsStyleChange = false;
3234 }
3235
3236 // Update invalidated regions.
3237 GtkUpdate();
3238
3239 wxCursor cursor = m_cursor;
3240 if (g_globalCursor.Ok()) cursor = g_globalCursor;
3241
3242 if (cursor.Ok())
3243 {
3244 /* I now set the cursor anew in every OnInternalIdle call
3245 as setting the cursor in a parent window also effects the
3246 windows above so that checking for the current cursor is
3247 not possible. */
3248
3249 if (m_wxwindow)
3250 {
3251 GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window;
3252 if (window)
3253 gdk_window_set_cursor( window, cursor.GetCursor() );
3254
3255 if (!g_globalCursor.Ok())
3256 cursor = *wxSTANDARD_CURSOR;
3257
3258 window = m_widget->window;
3259 if ((window) && !(GTK_WIDGET_NO_WINDOW(m_widget)))
3260 gdk_window_set_cursor( window, cursor.GetCursor() );
3261
3262 }
3263 else
3264 {
3265
3266 GdkWindow *window = m_widget->window;
3267 if ((window) && !(GTK_WIDGET_NO_WINDOW(m_widget)))
3268 gdk_window_set_cursor( window, cursor.GetCursor() );
3269
3270 }
3271 }
3272
3273 if (wxUpdateUIEvent::CanUpdate(this))
3274 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
3275}
3276
3277void wxWindowGTK::DoGetSize( int *width, int *height ) const
3278{
3279 wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
3280
3281 if (width) (*width) = m_width;
3282 if (height) (*height) = m_height;
3283}
3284
3285void wxWindowGTK::DoSetClientSize( int width, int height )
3286{
3287 wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
3288
3289 if (!m_wxwindow)
3290 {
3291 SetSize( width, height );
3292 }
3293 else
3294 {
3295 int dw = 0;
3296 int dh = 0;
3297
3298#ifndef __WXUNIVERSAL__
3299 if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
3300 {
3301 /* when using GTK 1.2 we set the shadow border size to 2 */
3302 dw += 2 * 2;
3303 dh += 2 * 2;
3304 }
3305 if (HasFlag(wxSIMPLE_BORDER))
3306 {
3307 /* when using GTK 1.2 we set the simple border size to 1 */
3308 dw += 1 * 2;
3309 dh += 1 * 2;
3310 }
3311#endif // __WXUNIVERSAL__
3312
3313 if (m_hasScrolling)
3314 {
3315 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
3316
3317 GtkRequisition vscroll_req;
3318 vscroll_req.width = 2;
3319 vscroll_req.height = 2;
3320 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window->vscrollbar) )->size_request )
3321 (scroll_window->vscrollbar, &vscroll_req );
3322
3323 GtkRequisition hscroll_req;
3324 hscroll_req.width = 2;
3325 hscroll_req.height = 2;
3326 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window->hscrollbar) )->size_request )
3327 (scroll_window->hscrollbar, &hscroll_req );
3328
3329 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget) );
3330
3331 if (scroll_window->vscrollbar_visible)
3332 {
3333 dw += vscroll_req.width;
3334 dw += scroll_class->scrollbar_spacing;
3335 }
3336
3337 if (scroll_window->hscrollbar_visible)
3338 {
3339 dh += hscroll_req.height;
3340 dh += scroll_class->scrollbar_spacing;
3341 }
3342 }
3343
3344 SetSize( width+dw, height+dh );
3345 }
3346}
3347
3348void wxWindowGTK::DoGetClientSize( int *width, int *height ) const
3349{
3350 wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
3351
3352 if (!m_wxwindow)
3353 {
3354 if (width) (*width) = m_width;
3355 if (height) (*height) = m_height;
3356 }
3357 else
3358 {
3359 int dw = 0;
3360 int dh = 0;
3361
3362#ifndef __WXUNIVERSAL__
3363 if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
3364 {
3365 /* when using GTK 1.2 we set the shadow border size to 2 */
3366 dw += 2 * 2;
3367 dh += 2 * 2;
3368 }
3369 if (HasFlag(wxSIMPLE_BORDER))
3370 {
3371 /* when using GTK 1.2 we set the simple border size to 1 */
3372 dw += 1 * 2;
3373 dh += 1 * 2;
3374 }
3375#endif // __WXUNIVERSAL__
3376
3377 if (m_hasScrolling)
3378 {
3379 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
3380
3381 GtkRequisition vscroll_req;
3382 vscroll_req.width = 2;
3383 vscroll_req.height = 2;
3384 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window->vscrollbar) )->size_request )
3385 (scroll_window->vscrollbar, &vscroll_req );
3386
3387 GtkRequisition hscroll_req;
3388 hscroll_req.width = 2;
3389 hscroll_req.height = 2;
3390 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window->hscrollbar) )->size_request )
3391 (scroll_window->hscrollbar, &hscroll_req );
3392
3393 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget) );
3394
3395 if (scroll_window->vscrollbar_visible)
3396 {
3397 dw += vscroll_req.width;
3398 dw += scroll_class->scrollbar_spacing;
3399 }
3400
3401 if (scroll_window->hscrollbar_visible)
3402 {
3403 dh += hscroll_req.height;
3404 dh += scroll_class->scrollbar_spacing;
3405 }
3406 }
3407
3408 if (width) (*width) = m_width - dw;
3409 if (height) (*height) = m_height - dh;
3410 }
3411
3412/*
3413 printf( "GetClientSize, name %s ", GetName().c_str() );
3414 if (width) printf( " width = %d", (*width) );
3415 if (height) printf( " height = %d", (*height) );
3416 printf( "\n" );
3417*/
3418}
3419
3420void wxWindowGTK::DoGetPosition( int *x, int *y ) const
3421{
3422 wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
3423
3424 int dx = 0;
3425 int dy = 0;
3426 if (m_parent && m_parent->m_wxwindow)
3427 {
3428 GtkPizza *pizza = GTK_PIZZA(m_parent->m_wxwindow);
3429 dx = pizza->xoffset;
3430 dy = pizza->yoffset;
3431 }
3432
3433 if (x) (*x) = m_x - dx;
3434 if (y) (*y) = m_y - dy;
3435}
3436
3437void wxWindowGTK::DoClientToScreen( int *x, int *y ) const
3438{
3439 wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
3440
3441 if (!m_widget->window) return;
3442
3443 GdkWindow *source = (GdkWindow *) NULL;
3444 if (m_wxwindow)
3445 source = GTK_PIZZA(m_wxwindow)->bin_window;
3446 else
3447 source = m_widget->window;
3448
3449 int org_x = 0;
3450 int org_y = 0;
3451 gdk_window_get_origin( source, &org_x, &org_y );
3452
3453 if (!m_wxwindow)
3454 {
3455 if (GTK_WIDGET_NO_WINDOW (m_widget))
3456 {
3457 org_x += m_widget->allocation.x;
3458 org_y += m_widget->allocation.y;
3459 }
3460 }
3461
3462 if (x) *x += org_x;
3463 if (y) *y += org_y;
3464}
3465
3466void wxWindowGTK::DoScreenToClient( int *x, int *y ) const
3467{
3468 wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
3469
3470 if (!m_widget->window) return;
3471
3472 GdkWindow *source = (GdkWindow *) NULL;
3473 if (m_wxwindow)
3474 source = GTK_PIZZA(m_wxwindow)->bin_window;
3475 else
3476 source = m_widget->window;
3477
3478 int org_x = 0;
3479 int org_y = 0;
3480 gdk_window_get_origin( source, &org_x, &org_y );
3481
3482 if (!m_wxwindow)
3483 {
3484 if (GTK_WIDGET_NO_WINDOW (m_widget))
3485 {
3486 org_x += m_widget->allocation.x;
3487 org_y += m_widget->allocation.y;
3488 }
3489 }
3490
3491 if (x) *x -= org_x;
3492 if (y) *y -= org_y;
3493}
3494
3495bool wxWindowGTK::Show( bool show )
3496{
3497 wxCHECK_MSG( (m_widget != NULL), FALSE, wxT("invalid window") );
3498
3499 if (!wxWindowBase::Show(show))
3500 {
3501 // nothing to do
3502 return FALSE;
3503 }
3504
3505 if (show)
3506 gtk_widget_show( m_widget );
3507 else
3508 gtk_widget_hide( m_widget );
3509
3510 wxShowEvent eventShow(GetId(), show);
3511 eventShow.SetEventObject(this);
3512
3513 GetEventHandler()->ProcessEvent(eventShow);
3514
3515 return TRUE;
3516}
3517
3518static void wxWindowNotifyEnable(wxWindowGTK* win, bool enable)
3519{
3520 win->OnParentEnable(enable);
3521
3522 // Recurse, so that children have the opportunity to Do The Right Thing
3523 // and reset colours that have been messed up by a parent's (really ancestor's)
3524 // Enable call
3525 for ( wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
3526 node;
3527 node = node->GetNext() )
3528 {
3529 wxWindow *child = node->GetData();
3530 if (!child->IsKindOf(CLASSINFO(wxDialog)) && !child->IsKindOf(CLASSINFO(wxFrame)))
3531 wxWindowNotifyEnable(child, enable);
3532 }
3533}
3534
3535bool wxWindowGTK::Enable( bool enable )
3536{
3537 wxCHECK_MSG( (m_widget != NULL), FALSE, wxT("invalid window") );
3538
3539 if (!wxWindowBase::Enable(enable))
3540 {
3541 // nothing to do
3542 return FALSE;
3543 }
3544
3545 gtk_widget_set_sensitive( m_widget, enable );
3546 if ( m_wxwindow )
3547 gtk_widget_set_sensitive( m_wxwindow, enable );
3548
3549 wxWindowNotifyEnable(this, enable);
3550
3551 return TRUE;
3552}
3553
3554int wxWindowGTK::GetCharHeight() const
3555{
3556 wxCHECK_MSG( (m_widget != NULL), 12, wxT("invalid window") );
3557
3558 wxFont font = GetFont();
3559 wxCHECK_MSG( font.Ok(), 12, wxT("invalid font") );
3560
3561#ifdef __WXGTK20__
3562 PangoContext *context = NULL;
3563 if (m_widget)
3564 context = gtk_widget_get_pango_context( m_widget );
3565
3566 if (!context)
3567 return 0;
3568
3569 PangoFontDescription *desc = font.GetNativeFontInfo()->description;
3570 PangoLayout *layout = pango_layout_new(context);
3571 pango_layout_set_font_description(layout, desc);
3572 pango_layout_set_text(layout, "H", 1);
3573 PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
3574
3575 PangoRectangle rect;
3576 pango_layout_line_get_extents(line, NULL, &rect);
3577
3578 g_object_unref( G_OBJECT( layout ) );
3579
3580 return (int) PANGO_PIXELS(rect.height);
3581#else
3582 GdkFont *gfont = font.GetInternalFont( 1.0 );
3583
3584 return gfont->ascent + gfont->descent;
3585#endif
3586}
3587
3588int wxWindowGTK::GetCharWidth() const
3589{
3590 wxCHECK_MSG( (m_widget != NULL), 8, wxT("invalid window") );
3591
3592 wxFont font = GetFont();
3593 wxCHECK_MSG( font.Ok(), 8, wxT("invalid font") );
3594
3595#ifdef __WXGTK20__
3596 PangoContext *context = NULL;
3597 if (m_widget)
3598 context = gtk_widget_get_pango_context( m_widget );
3599
3600 if (!context)
3601 return 0;
3602
3603 PangoFontDescription *desc = font.GetNativeFontInfo()->description;
3604 PangoLayout *layout = pango_layout_new(context);
3605 pango_layout_set_font_description(layout, desc);
3606 pango_layout_set_text(layout, "g", 1);
3607 PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
3608
3609 PangoRectangle rect;
3610 pango_layout_line_get_extents(line, NULL, &rect);
3611
3612 g_object_unref( G_OBJECT( layout ) );
3613
3614 return (int) PANGO_PIXELS(rect.width);
3615#else
3616 GdkFont *gfont = font.GetInternalFont( 1.0 );
3617
3618 return gdk_string_width( gfont, "g" );
3619#endif
3620}
3621
3622void wxWindowGTK::GetTextExtent( const wxString& string,
3623 int *x,
3624 int *y,
3625 int *descent,
3626 int *externalLeading,
3627 const wxFont *theFont ) const
3628{
3629 wxFont fontToUse = theFont ? *theFont : GetFont();
3630
3631 wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") );
3632
3633 if (string.IsEmpty())
3634 {
3635 if (x) (*x) = 0;
3636 if (y) (*y) = 0;
3637 return;
3638 }
3639
3640#ifdef __WXGTK20__
3641 PangoContext *context = NULL;
3642 if (m_widget)
3643 context = gtk_widget_get_pango_context( m_widget );
3644
3645 if (!context)
3646 {
3647 if (x) (*x) = 0;
3648 if (y) (*y) = 0;
3649 return;
3650 }
3651
3652 PangoFontDescription *desc = fontToUse.GetNativeFontInfo()->description;
3653 PangoLayout *layout = pango_layout_new(context);
3654 pango_layout_set_font_description(layout, desc);
3655 {
3656#if wxUSE_UNICODE
3657 const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
3658 pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
3659#else
3660 const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string );
3661 const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
3662 pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
3663#endif
3664 }
3665
3666 PangoRectangle rect;
3667 pango_layout_get_extents(layout, NULL, &rect);
3668
3669 if (x) (*x) = (wxCoord) PANGO_PIXELS(rect.width);
3670 if (y) (*y) = (wxCoord) PANGO_PIXELS(rect.height);
3671 if (descent)
3672 {
3673 PangoLayoutIter *iter = pango_layout_get_iter(layout);
3674 int baseline = pango_layout_iter_get_baseline(iter);
3675 pango_layout_iter_free(iter);
3676 *descent = *y - PANGO_PIXELS(baseline);
3677 }
3678 if (externalLeading) (*externalLeading) = 0; // ??
3679
3680 g_object_unref( G_OBJECT( layout ) );
3681#else
3682 GdkFont *font = fontToUse.GetInternalFont( 1.0 );
3683 if (x) (*x) = gdk_string_width( font, wxGTK_CONV( string ) );
3684 if (y) (*y) = font->ascent + font->descent;
3685 if (descent) (*descent) = font->descent;
3686 if (externalLeading) (*externalLeading) = 0; // ??
3687#endif
3688}
3689
3690void wxWindowGTK::SetFocus()
3691{
3692 wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
3693 if ( m_hasFocus )
3694 {
3695 // don't do anything if we already have focus
3696 return;
3697 }
3698
3699 if (m_wxwindow)
3700 {
3701 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow))
3702 {
3703 gtk_widget_grab_focus (m_wxwindow);
3704 }
3705 }
3706 else if (m_widget)
3707 {
3708#ifdef __WXGTK20__
3709 if (GTK_IS_CONTAINER(m_widget))
3710 {
3711 gtk_widget_child_focus( m_widget, GTK_DIR_TAB_FORWARD );
3712 }
3713 else
3714#endif
3715 if (GTK_WIDGET_CAN_FOCUS(m_widget) && !GTK_WIDGET_HAS_FOCUS (m_widget) )
3716 {
3717
3718 if (!GTK_WIDGET_REALIZED(m_widget))
3719 {
3720 // we can't set the focus to the widget now so we remember that
3721 // it should be focused and will do it later, during the idle
3722 // time, as soon as we can
3723 wxLogTrace(TRACE_FOCUS,
3724 _T("Delaying setting focus to %s(%s)"),
3725 GetClassInfo()->GetClassName(), GetLabel().c_str());
3726
3727 g_delayedFocus = this;
3728 }
3729 else
3730 {
3731 wxLogTrace(TRACE_FOCUS,
3732 _T("Setting focus to %s(%s)"),
3733 GetClassInfo()->GetClassName(), GetLabel().c_str());
3734
3735 gtk_widget_grab_focus (m_widget);
3736 }
3737 }
3738 else
3739#ifndef __WXGTK20__
3740 if (GTK_IS_CONTAINER(m_widget))
3741 {
3742 gtk_container_focus( GTK_CONTAINER(m_widget), GTK_DIR_TAB_FORWARD );
3743 }
3744 else
3745#endif
3746 {
3747 wxLogTrace(TRACE_FOCUS,
3748 _T("Can't set focus to %s(%s)"),
3749 GetClassInfo()->GetClassName(), GetLabel().c_str());
3750 }
3751 }
3752}
3753
3754bool wxWindowGTK::AcceptsFocus() const
3755{
3756 return m_acceptsFocus && wxWindowBase::AcceptsFocus();
3757}
3758
3759bool wxWindowGTK::Reparent( wxWindowBase *newParentBase )
3760{
3761 wxCHECK_MSG( (m_widget != NULL), FALSE, wxT("invalid window") );
3762
3763 wxWindowGTK *oldParent = m_parent,
3764 *newParent = (wxWindowGTK *)newParentBase;
3765
3766 wxASSERT( GTK_IS_WIDGET(m_widget) );
3767
3768 if ( !wxWindowBase::Reparent(newParent) )
3769 return FALSE;
3770
3771 wxASSERT( GTK_IS_WIDGET(m_widget) );
3772
3773 /* prevent GTK from deleting the widget arbitrarily */
3774 gtk_widget_ref( m_widget );
3775
3776 if (oldParent)
3777 {
3778 gtk_container_remove( GTK_CONTAINER(m_widget->parent), m_widget );
3779 }
3780
3781 wxASSERT( GTK_IS_WIDGET(m_widget) );
3782
3783 if (newParent)
3784 {
3785 /* insert GTK representation */
3786 (*(newParent->m_insertCallback))(newParent, this);
3787 }
3788
3789 /* reverse: prevent GTK from deleting the widget arbitrarily */
3790 gtk_widget_unref( m_widget );
3791
3792 return TRUE;
3793}
3794
3795void wxWindowGTK::DoAddChild(wxWindowGTK *child)
3796{
3797 wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") );
3798
3799 wxASSERT_MSG( (child != NULL), wxT("invalid child window") );
3800
3801 wxASSERT_MSG( (m_insertCallback != NULL), wxT("invalid child insertion function") );
3802
3803 /* add to list */
3804 AddChild( child );
3805
3806 /* insert GTK representation */
3807 (*m_insertCallback)(this, child);
3808}
3809
3810#ifdef __WXGTK20__
3811
3812void wxWindowGTK::AddChild(wxWindowBase *child)
3813{
3814 wxWindowBase::AddChild(child);
3815 m_dirtyTabOrder = true;
3816 if (g_isIdle)
3817 wxapp_install_idle_handler();
3818}
3819
3820void wxWindowGTK::RemoveChild(wxWindowBase *child)
3821{
3822 wxWindowBase::RemoveChild(child);
3823 m_dirtyTabOrder = true;
3824 if (g_isIdle)
3825 wxapp_install_idle_handler();
3826}
3827
3828void wxWindowGTK::DoMoveInTabOrder(wxWindow *win, MoveKind move)
3829{
3830 wxWindowBase::DoMoveInTabOrder(win, move);
3831 m_dirtyTabOrder = true;
3832 if (g_isIdle)
3833 wxapp_install_idle_handler();
3834}
3835
3836void wxWindowGTK::RealizeTabOrder()
3837{
3838 if (m_wxwindow)
3839 {
3840 if (m_children.size() > 0)
3841 {
3842 GList *chain = NULL;
3843
3844 for (wxWindowList::const_iterator i = m_children.begin();
3845 i != m_children.end(); ++i)
3846 {
3847 chain = g_list_prepend(chain, (*i)->m_widget);
3848 }
3849
3850 chain = g_list_reverse(chain);
3851
3852 gtk_container_set_focus_chain(GTK_CONTAINER(m_wxwindow), chain);
3853 g_list_free(chain);
3854 }
3855 else
3856 {
3857 gtk_container_unset_focus_chain(GTK_CONTAINER(m_wxwindow));
3858 }
3859 }
3860
3861 m_dirtyTabOrder = false;
3862}
3863
3864#endif // __WXGTK20__
3865
3866void wxWindowGTK::Raise()
3867{
3868 wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
3869
3870 if (m_wxwindow && m_wxwindow->window)
3871 {
3872 gdk_window_raise( m_wxwindow->window );
3873 }
3874 else if (m_widget->window)
3875 {
3876 gdk_window_raise( m_widget->window );
3877 }
3878}
3879
3880void wxWindowGTK::Lower()
3881{
3882 wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
3883
3884 if (m_wxwindow && m_wxwindow->window)
3885 {
3886 gdk_window_lower( m_wxwindow->window );
3887 }
3888 else if (m_widget->window)
3889 {
3890 gdk_window_lower( m_widget->window );
3891 }
3892}
3893
3894bool wxWindowGTK::SetCursor( const wxCursor &cursor )
3895{
3896 wxCHECK_MSG( (m_widget != NULL), FALSE, wxT("invalid window") );
3897
3898 if (cursor == m_cursor)
3899 return FALSE;
3900
3901 if (g_isIdle)
3902 wxapp_install_idle_handler();
3903
3904 if (cursor == wxNullCursor)
3905 return wxWindowBase::SetCursor( *wxSTANDARD_CURSOR );
3906 else
3907 return wxWindowBase::SetCursor( cursor );
3908}
3909
3910void wxWindowGTK::WarpPointer( int x, int y )
3911{
3912 wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
3913
3914 // We provide this function ourselves as it is
3915 // missing in GDK (top of this file).
3916
3917 GdkWindow *window = (GdkWindow*) NULL;
3918 if (m_wxwindow)
3919 window = GTK_PIZZA(m_wxwindow)->bin_window;
3920 else
3921 window = GetConnectWidget()->window;
3922
3923 if (window)
3924 gdk_window_warp_pointer( window, x, y );
3925}
3926
3927
3928void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect )
3929{
3930 if (!m_widget)
3931 return;
3932 if (!m_widget->window)
3933 return;
3934
3935#ifndef __WXGTK20__
3936 if (g_isIdle)
3937 wxapp_install_idle_handler();
3938
3939 wxRect myRect;
3940 if (m_wxwindow && rect)
3941 {
3942 myRect.SetSize(wxSize( m_wxwindow->allocation.width,
3943 m_wxwindow->allocation.height));
3944 if ( myRect.Intersect(*rect).IsEmpty() )
3945 {
3946 // nothing to do, rectangle is empty
3947 return;
3948 }
3949
3950 rect = &myRect;
3951 }
3952
3953 // schedule the area for later updating in GtkUpdate()
3954 if (eraseBackground && m_wxwindow && m_wxwindow->window)
3955 {
3956 if (rect)
3957 {
3958 m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height );
3959 }
3960 else
3961 {
3962 m_clearRegion.Clear();
3963 m_clearRegion.Union( 0, 0, m_wxwindow->allocation.width, m_wxwindow->allocation.height );
3964 }
3965 }
3966
3967 if (rect)
3968 {
3969 if (m_wxwindow)
3970 {
3971 m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height );
3972 }
3973 else
3974 {
3975 GdkRectangle gdk_rect;
3976 gdk_rect.x = rect->x;
3977 gdk_rect.y = rect->y;
3978 gdk_rect.width = rect->width;
3979 gdk_rect.height = rect->height;
3980 gtk_widget_draw( m_widget, &gdk_rect );
3981 }
3982 }
3983 else
3984 {
3985 if (m_wxwindow)
3986 {
3987 m_updateRegion.Clear();
3988 m_updateRegion.Union( 0, 0, m_wxwindow->allocation.width, m_wxwindow->allocation.height );
3989 }
3990 else
3991 {
3992 gtk_widget_draw( m_widget, (GdkRectangle*) NULL );
3993 }
3994 }
3995#else // GTK+ 2
3996 if (m_wxwindow)
3997 {
3998 GdkRectangle gdk_rect,
3999 *p;
4000 if (rect)
4001 {
4002 gdk_rect.x = rect->x;
4003 gdk_rect.y = rect->y;
4004 gdk_rect.width = rect->width;
4005 gdk_rect.height = rect->height;
4006 p = &gdk_rect;
4007 }
4008 else // invalidate everything
4009 {
4010 p = NULL;
4011 }
4012
4013 gdk_window_invalidate_rect( GTK_PIZZA(m_wxwindow)->bin_window, p, TRUE );
4014 }
4015#endif // GTK+ 1/2
4016}
4017
4018void wxWindowGTK::Update()
4019{
4020 GtkUpdate();
4021
4022 // when we call Update() we really want to update the window immediately on
4023 // screen, even if itmeans flushing the entire queue and hence slowing down
4024 // everything -- but it should still be done, it's just that Update() should
4025 // be called very rarely
4026 gdk_flush();
4027}
4028
4029void wxWindowGTK::GtkUpdate()
4030{
4031#ifdef __WXGTK20__
4032 if (m_wxwindow && GTK_PIZZA(m_wxwindow)->bin_window)
4033 gdk_window_process_updates( GTK_PIZZA(m_wxwindow)->bin_window, FALSE );
4034#else
4035 if (!m_updateRegion.IsEmpty())
4036 GtkSendPaintEvents();
4037#endif
4038
4039 // for consistency with other platforms (and also because it's convenient
4040 // to be able to update an entire TLW by calling Update() only once), we
4041 // should also update all our children here
4042 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
4043 node;
4044 node = node->GetNext() )
4045 {
4046 node->GetData()->GtkUpdate();
4047 }
4048}
4049
4050void wxWindowGTK::GtkSendPaintEvents()
4051{
4052 if (!m_wxwindow)
4053 {
4054#ifndef __WXGTK20__
4055 m_clearRegion.Clear();
4056#endif
4057 m_updateRegion.Clear();
4058 return;
4059 }
4060
4061 // Clip to paint region in wxClientDC
4062 m_clipPaintRegion = TRUE;
4063
4064 // widget to draw on
4065 GtkPizza *pizza = GTK_PIZZA (m_wxwindow);
4066
4067 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM))
4068 {
4069 // find ancestor from which to steal background
4070 wxWindow *parent = wxGetTopLevelParent((wxWindow *)this);
4071 if (!parent)
4072 parent = (wxWindow*)this;
4073
4074 if (GTK_WIDGET_MAPPED(parent->m_widget))
4075 {
4076 wxRegionIterator upd( m_updateRegion );
4077 while (upd)
4078 {
4079 GdkRectangle rect;
4080 rect.x = upd.GetX();
4081 rect.y = upd.GetY();
4082 rect.width = upd.GetWidth();
4083 rect.height = upd.GetHeight();
4084
4085 gtk_paint_flat_box( parent->m_widget->style,
4086 pizza->bin_window,
4087 (GtkStateType)GTK_WIDGET_STATE(m_wxwindow),
4088 GTK_SHADOW_NONE,
4089 &rect,
4090 parent->m_widget,
4091 (char *)"base",
4092 0, 0, -1, -1 );
4093
4094 ++upd;
4095 }
4096 }
4097 }
4098 else
4099
4100#ifdef __WXGTK20__
4101 {
4102 wxWindowDC dc( (wxWindow*)this );
4103 dc.SetClippingRegion( m_updateRegion );
4104
4105 wxEraseEvent erase_event( GetId(), &dc );
4106 erase_event.SetEventObject( this );
4107
4108 GetEventHandler()->ProcessEvent(erase_event);
4109 }
4110#else
4111 // if (!m_clearRegion.IsEmpty()) // Always send an erase event under GTK 1.2
4112 {
4113 wxWindowDC dc( (wxWindow*)this );
4114 if (m_clearRegion.IsEmpty())
4115 dc.SetClippingRegion( m_updateRegion );
4116 else
4117 dc.SetClippingRegion( m_clearRegion );
4118
4119 wxEraseEvent erase_event( GetId(), &dc );
4120 erase_event.SetEventObject( this );
4121
4122 if (!GetEventHandler()->ProcessEvent(erase_event) && GetBackgroundStyle() != wxBG_STYLE_CUSTOM)
4123 {
4124 if (!g_eraseGC)
4125 {
4126 g_eraseGC = gdk_gc_new( pizza->bin_window );
4127 gdk_gc_set_fill( g_eraseGC, GDK_SOLID );
4128 }
4129 gdk_gc_set_foreground( g_eraseGC, GetBackgroundColour().GetColor() );
4130
4131 wxRegionIterator upd( m_clearRegion );
4132 while (upd)
4133 {
4134 gdk_draw_rectangle( pizza->bin_window, g_eraseGC, 1,
4135 upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() );
4136 upd ++;
4137 }
4138 }
4139 m_clearRegion.Clear();
4140 }
4141#endif
4142
4143 wxNcPaintEvent nc_paint_event( GetId() );
4144 nc_paint_event.SetEventObject( this );
4145 GetEventHandler()->ProcessEvent( nc_paint_event );
4146
4147 wxPaintEvent paint_event( GetId() );
4148 paint_event.SetEventObject( this );
4149 GetEventHandler()->ProcessEvent( paint_event );
4150
4151 m_clipPaintRegion = FALSE;
4152
4153#ifndef __WXUNIVERSAL__
4154#ifndef __WXGTK20__
4155 // The following code will result in all window-less widgets
4156 // being redrawn because the wxWidgets class is allowed to
4157 // paint over the window-less widgets.
4158
4159 GList *children = pizza->children;
4160 while (children)
4161 {
4162 GtkPizzaChild *child = (GtkPizzaChild*) children->data;
4163 children = children->next;
4164
4165 if (GTK_WIDGET_NO_WINDOW (child->widget) &&
4166 GTK_WIDGET_DRAWABLE (child->widget))
4167 {
4168 // Get intersection of widget area and update region
4169 wxRegion region( m_updateRegion );
4170
4171 GdkEventExpose gdk_event;
4172 gdk_event.type = GDK_EXPOSE;
4173 gdk_event.window = pizza->bin_window;
4174 gdk_event.count = 0;
4175
4176 wxRegionIterator upd( m_updateRegion );
4177 while (upd)
4178 {
4179 GdkRectangle rect;
4180 rect.x = upd.GetX();
4181 rect.y = upd.GetY();
4182 rect.width = upd.GetWidth();
4183 rect.height = upd.GetHeight();
4184
4185 if (gtk_widget_intersect (child->widget, &rect, &gdk_event.area))
4186 {
4187 gtk_widget_event (child->widget, (GdkEvent*) &gdk_event);
4188 }
4189
4190 upd ++;
4191 }
4192 }
4193 }
4194#endif
4195#endif
4196
4197 m_updateRegion.Clear();
4198}
4199
4200void wxWindowGTK::ClearBackground()
4201{
4202 wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
4203
4204#ifndef __WXGTK20__
4205 if (m_wxwindow && m_wxwindow->window)
4206 {
4207 m_clearRegion.Clear();
4208 wxSize size( GetClientSize() );
4209 m_clearRegion.Union( 0,0,size.x,size.y );
4210
4211 // Better do this in idle?
4212 GtkUpdate();
4213 }
4214#endif
4215}
4216
4217#if wxUSE_TOOLTIPS
4218void wxWindowGTK::DoSetToolTip( wxToolTip *tip )
4219{
4220 wxWindowBase::DoSetToolTip(tip);
4221
4222 if (m_tooltip)
4223 m_tooltip->Apply( (wxWindow *)this );
4224}
4225
4226void wxWindowGTK::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
4227{
4228 wxString tmp( tip );
4229 gtk_tooltips_set_tip( tips, GetConnectWidget(), wxGTK_CONV(tmp), (gchar*) NULL );
4230}
4231#endif // wxUSE_TOOLTIPS
4232
4233bool wxWindowGTK::SetBackgroundColour( const wxColour &colour )
4234{
4235 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid window") );
4236
4237 if (!wxWindowBase::SetBackgroundColour(colour))
4238 return false;
4239
4240 if (colour.Ok())
4241 {
4242 // We need the pixel value e.g. for background clearing.
4243 m_backgroundColour.CalcPixel(gtk_widget_get_colormap(m_widget));
4244 }
4245
4246 // apply style change (forceStyle=true so that new style is applied
4247 // even if the bg colour changed from valid to wxNullColour)
4248 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM)
4249 ApplyWidgetStyle(true);
4250
4251 return true;
4252}
4253
4254bool wxWindowGTK::SetForegroundColour( const wxColour &colour )
4255{
4256 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid window") );
4257
4258 if (!wxWindowBase::SetForegroundColour(colour))
4259 {
4260 return false;
4261 }
4262
4263 if (colour.Ok())
4264 {
4265 // We need the pixel value e.g. for background clearing.
4266 m_foregroundColour.CalcPixel(gtk_widget_get_colormap(m_widget));
4267 }
4268
4269 // apply style change (forceStyle=true so that new style is applied
4270 // even if the bg colour changed from valid to wxNullColour):
4271 ApplyWidgetStyle(true);
4272
4273 return true;
4274}
4275
4276#ifdef __WXGTK20__
4277PangoContext *wxWindowGTK::GtkGetPangoDefaultContext()
4278{
4279 return gtk_widget_get_pango_context( m_widget );
4280}
4281
4282PangoContext *wxWindowGTK::GtkGetPangoX11Context()
4283{
4284 if (!m_x11Context)
4285 m_x11Context = pango_x_get_context( gdk_display );
4286
4287 return m_x11Context;
4288}
4289#endif
4290
4291GtkRcStyle *wxWindowGTK::CreateWidgetStyle(bool forceStyle)
4292{
4293 // do we need to apply any changes at all?
4294 if ( !forceStyle &&
4295 !m_font.Ok() &&
4296 !m_foregroundColour.Ok() && !m_backgroundColour.Ok() )
4297 {
4298 return NULL;
4299 }
4300
4301 GtkRcStyle *style = gtk_rc_style_new();
4302
4303 if ( m_font.Ok() )
4304 {
4305#ifdef __WXGTK20__
4306 style->font_desc =
4307 pango_font_description_copy( m_font.GetNativeFontInfo()->description );
4308#else
4309 wxString xfontname = m_font.GetNativeFontInfo()->GetXFontName();
4310 style->fontset_name = g_strdup(xfontname.c_str());
4311#endif
4312 }
4313
4314 if ( m_foregroundColour.Ok() )
4315 {
4316 GdkColor *fg = m_foregroundColour.GetColor();
4317
4318 style->fg[GTK_STATE_NORMAL] = *fg;
4319 style->color_flags[GTK_STATE_NORMAL] = GTK_RC_FG;
4320
4321 style->fg[GTK_STATE_PRELIGHT] = *fg;
4322 style->color_flags[GTK_STATE_PRELIGHT] = GTK_RC_FG;
4323
4324 style->fg[GTK_STATE_ACTIVE] = *fg;
4325 style->color_flags[GTK_STATE_ACTIVE] = GTK_RC_FG;
4326 }
4327
4328 if ( m_backgroundColour.Ok() )
4329 {
4330 GdkColor *bg = m_backgroundColour.GetColor();
4331
4332 style->bg[GTK_STATE_NORMAL] = *bg;
4333 style->base[GTK_STATE_NORMAL] = *bg;
4334 style->color_flags[GTK_STATE_NORMAL] = (GtkRcFlags)
4335 (style->color_flags[GTK_STATE_NORMAL] | GTK_RC_BG | GTK_RC_BASE);
4336
4337 style->bg[GTK_STATE_PRELIGHT] = *bg;
4338 style->base[GTK_STATE_PRELIGHT] = *bg;
4339 style->color_flags[GTK_STATE_PRELIGHT] = (GtkRcFlags)
4340 (style->color_flags[GTK_STATE_PRELIGHT] | GTK_RC_BG | GTK_RC_BASE);
4341
4342 style->bg[GTK_STATE_ACTIVE] = *bg;
4343 style->base[GTK_STATE_ACTIVE] = *bg;
4344 style->color_flags[GTK_STATE_ACTIVE] = (GtkRcFlags)
4345 (style->color_flags[GTK_STATE_ACTIVE] | GTK_RC_BG | GTK_RC_BASE);
4346
4347 style->bg[GTK_STATE_INSENSITIVE] = *bg;
4348 style->base[GTK_STATE_INSENSITIVE] = *bg;
4349 style->color_flags[GTK_STATE_INSENSITIVE] = (GtkRcFlags)
4350 (style->color_flags[GTK_STATE_INSENSITIVE] | GTK_RC_BG | GTK_RC_BASE);
4351 }
4352
4353 return style;
4354}
4355
4356void wxWindowGTK::ApplyWidgetStyle(bool forceStyle)
4357{
4358 GtkRcStyle *style = CreateWidgetStyle(forceStyle);
4359 if ( style )
4360 {
4361 DoApplyWidgetStyle(style);
4362 gtk_rc_style_unref(style);
4363 }
4364
4365 // Style change may affect GTK+'s size calculation:
4366 InvalidateBestSize();
4367}
4368
4369void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle *style)
4370{
4371 if (m_wxwindow)
4372 gtk_widget_modify_style(m_wxwindow, style);
4373 else
4374 gtk_widget_modify_style(m_widget, style);
4375}
4376
4377bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style)
4378{
4379 wxWindowBase::SetBackgroundStyle(style);
4380
4381 if (style == wxBG_STYLE_CUSTOM)
4382 {
4383 GdkWindow *window = (GdkWindow*) NULL;
4384 if (m_wxwindow)
4385 window = GTK_PIZZA(m_wxwindow)->bin_window;
4386 else
4387 window = GetConnectWidget()->window;
4388
4389 if (window)
4390 {
4391 // Make sure GDK/X11 doesn't refresh the window
4392 // automatically.
4393 gdk_window_set_back_pixmap( window, None, False );
4394#ifdef __X__
4395 Display* display = GDK_WINDOW_DISPLAY(window);
4396 XFlush(display);
4397#endif
4398 m_needsStyleChange = false;
4399 }
4400 else
4401 // Do in OnIdle, because the window is not yet available
4402 m_needsStyleChange = true;
4403
4404 // Don't apply widget style, or we get a grey background
4405 }
4406 else
4407 {
4408 // apply style change (forceStyle=true so that new style is applied
4409 // even if the bg colour changed from valid to wxNullColour):
4410 ApplyWidgetStyle(true);
4411 }
4412 return true;
4413}
4414
4415//-----------------------------------------------------------------------------
4416// Pop-up menu stuff
4417//-----------------------------------------------------------------------------
4418
4419#if wxUSE_MENUS_NATIVE
4420
4421extern "C"
4422void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting )
4423{
4424 *is_waiting = FALSE;
4425}
4426
4427void SetInvokingWindow( wxMenu *menu, wxWindow* win )
4428{
4429 menu->SetInvokingWindow( win );
4430
4431 wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
4432 while (node)
4433 {
4434 wxMenuItem *menuitem = node->GetData();
4435 if (menuitem->IsSubMenu())
4436 {
4437 SetInvokingWindow( menuitem->GetSubMenu(), win );
4438 }
4439
4440 node = node->GetNext();
4441 }
4442}
4443
4444extern "C" void wxPopupMenuPositionCallback( GtkMenu *menu,
4445 gint *x, gint *y,
4446#ifdef __WXGTK20__
4447 gboolean * WXUNUSED(whatever),
4448#endif
4449 gpointer user_data )
4450{
4451 // ensure that the menu appears entirely on screen
4452 GtkRequisition req;
4453 gtk_widget_get_child_requisition(GTK_WIDGET(menu), &req);
4454
4455 wxSize sizeScreen = wxGetDisplaySize();
4456 wxPoint *pos = (wxPoint*)user_data;
4457
4458 gint xmax = sizeScreen.x - req.width,
4459 ymax = sizeScreen.y - req.height;
4460
4461 *x = pos->x < xmax ? pos->x : xmax;
4462 *y = pos->y < ymax ? pos->y : ymax;
4463}
4464
4465bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
4466{
4467 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
4468
4469 wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );
4470
4471 // NOTE: if you change this code, you need to update
4472 // the same code in taskbar.cpp as well. This
4473 // is ugly code duplication, I know,
4474
4475 SetInvokingWindow( menu, this );
4476
4477 menu->UpdateUI();
4478
4479 bool is_waiting = true;
4480
4481 gulong handler = gtk_signal_connect( GTK_OBJECT(menu->m_menu),
4482 "hide",
4483 GTK_SIGNAL_FUNC(gtk_pop_hide_callback),
4484 (gpointer)&is_waiting );
4485
4486 wxPoint pos;
4487 gpointer userdata;
4488 GtkMenuPositionFunc posfunc;
4489 if ( x == -1 && y == -1 )
4490 {
4491 // use GTK's default positioning algorithm
4492 userdata = NULL;
4493 posfunc = NULL;
4494 }
4495 else
4496 {
4497 pos = ClientToScreen(wxPoint(x, y));
4498 userdata = &pos;
4499 posfunc = wxPopupMenuPositionCallback;
4500 }
4501
4502 gtk_menu_popup(
4503 GTK_MENU(menu->m_menu),
4504 (GtkWidget *) NULL, // parent menu shell
4505 (GtkWidget *) NULL, // parent menu item
4506 posfunc, // function to position it
4507 userdata, // client data
4508 0, // button used to activate it
4509#ifdef __WXGTK20__
4510 gtk_get_current_event_time()
4511#else
4512 gs_timeLastClick // the time of activation
4513#endif
4514 );
4515
4516 while (is_waiting)
4517 {
4518 gtk_main_iteration();
4519 }
4520
4521 gtk_signal_disconnect(GTK_OBJECT(menu->m_menu), handler);
4522
4523 return true;
4524}
4525
4526#endif // wxUSE_MENUS_NATIVE
4527
4528#if wxUSE_DRAG_AND_DROP
4529
4530void wxWindowGTK::SetDropTarget( wxDropTarget *dropTarget )
4531{
4532 wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
4533
4534 GtkWidget *dnd_widget = GetConnectWidget();
4535
4536 if (m_dropTarget) m_dropTarget->UnregisterWidget( dnd_widget );
4537
4538 if (m_dropTarget) delete m_dropTarget;
4539 m_dropTarget = dropTarget;
4540
4541 if (m_dropTarget) m_dropTarget->RegisterWidget( dnd_widget );
4542}
4543
4544#endif // wxUSE_DRAG_AND_DROP
4545
4546GtkWidget* wxWindowGTK::GetConnectWidget()
4547{
4548 GtkWidget *connect_widget = m_widget;
4549 if (m_wxwindow) connect_widget = m_wxwindow;
4550
4551 return connect_widget;
4552}
4553
4554bool wxWindowGTK::IsOwnGtkWindow( GdkWindow *window )
4555{
4556 if (m_wxwindow)
4557 return (window == GTK_PIZZA(m_wxwindow)->bin_window);
4558
4559 return (window == m_widget->window);
4560}
4561
4562bool wxWindowGTK::SetFont( const wxFont &font )
4563{
4564 wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid window") );
4565
4566 if (!wxWindowBase::SetFont(font))
4567 return false;
4568
4569 // apply style change (forceStyle=true so that new style is applied
4570 // even if the font changed from valid to wxNullFont):
4571 ApplyWidgetStyle(true);
4572
4573 return true;
4574}
4575
4576void wxWindowGTK::DoCaptureMouse()
4577{
4578 wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
4579
4580 GdkWindow *window = (GdkWindow*) NULL;
4581 if (m_wxwindow)
4582 window = GTK_PIZZA(m_wxwindow)->bin_window;
4583 else
4584 window = GetConnectWidget()->window;
4585
4586 wxCHECK_RET( window, _T("CaptureMouse() failed") );
4587
4588 wxCursor* cursor = & m_cursor;
4589 if (!cursor->Ok())
4590 cursor = wxSTANDARD_CURSOR;
4591
4592 gdk_pointer_grab( window, FALSE,
4593 (GdkEventMask)
4594 (GDK_BUTTON_PRESS_MASK |
4595 GDK_BUTTON_RELEASE_MASK |
4596 GDK_POINTER_MOTION_HINT_MASK |
4597 GDK_POINTER_MOTION_MASK),
4598 (GdkWindow *) NULL,
4599 cursor->GetCursor(),
4600 (guint32)GDK_CURRENT_TIME );
4601 g_captureWindow = this;
4602 g_captureWindowHasMouse = TRUE;
4603}
4604
4605void wxWindowGTK::DoReleaseMouse()
4606{
4607 wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
4608
4609 wxCHECK_RET( g_captureWindow, wxT("can't release mouse - not captured") );
4610
4611 g_captureWindow = (wxWindowGTK*) NULL;
4612
4613 GdkWindow *window = (GdkWindow*) NULL;
4614 if (m_wxwindow)
4615 window = GTK_PIZZA(m_wxwindow)->bin_window;
4616 else
4617 window = GetConnectWidget()->window;
4618
4619 if (!window)
4620 return;
4621
4622 gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME );
4623}
4624
4625/* static */
4626wxWindow *wxWindowBase::GetCapture()
4627{
4628 return (wxWindow *)g_captureWindow;
4629}
4630
4631bool wxWindowGTK::IsRetained() const
4632{
4633 return FALSE;
4634}
4635
4636void wxWindowGTK::SetScrollbar( int orient, int pos, int thumbVisible,
4637 int range, bool refresh )
4638{
4639 wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
4640
4641 wxCHECK_RET( m_wxwindow != NULL, wxT("window needs client area for scrolling") );
4642
4643 m_hasScrolling = TRUE;
4644
4645 if (orient == wxHORIZONTAL)
4646 {
4647 float fpos = (float)pos;
4648 float frange = (float)range;
4649 float fthumb = (float)thumbVisible;
4650 if (fpos > frange-fthumb) fpos = frange-fthumb;
4651 if (fpos < 0.0) fpos = 0.0;
4652
4653 if ((fabs(frange-m_hAdjust->upper) < 0.2) &&
4654 (fabs(fthumb-m_hAdjust->page_size) < 0.2))
4655 {
4656 SetScrollPos( orient, pos, refresh );
4657 return;
4658 }
4659
4660 m_oldHorizontalPos = fpos;
4661
4662 m_hAdjust->lower = 0.0;
4663 m_hAdjust->upper = frange;
4664 m_hAdjust->value = fpos;
4665 m_hAdjust->step_increment = 1.0;
4666 m_hAdjust->page_increment = (float)(wxMax(fthumb,0));
4667 m_hAdjust->page_size = fthumb;
4668 }
4669 else
4670 {
4671 float fpos = (float)pos;
4672 float frange = (float)range;
4673 float fthumb = (float)thumbVisible;
4674 if (fpos > frange-fthumb) fpos = frange-fthumb;
4675 if (fpos < 0.0) fpos = 0.0;
4676
4677 if ((fabs(frange-m_vAdjust->upper) < 0.2) &&
4678 (fabs(fthumb-m_vAdjust->page_size) < 0.2))
4679 {
4680 SetScrollPos( orient, pos, refresh );
4681 return;
4682 }
4683
4684 m_oldVerticalPos = fpos;
4685
4686 m_vAdjust->lower = 0.0;
4687 m_vAdjust->upper = frange;
4688 m_vAdjust->value = fpos;
4689 m_vAdjust->step_increment = 1.0;
4690 m_vAdjust->page_increment = (float)(wxMax(fthumb,0));
4691 m_vAdjust->page_size = fthumb;
4692 }
4693
4694 if (orient == wxHORIZONTAL)
4695 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
4696 else
4697 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
4698}
4699
4700void wxWindowGTK::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) )
4701{
4702 wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
4703
4704 wxCHECK_RET( m_wxwindow != NULL, wxT("window needs client area for scrolling") );
4705
4706 if (orient == wxHORIZONTAL)
4707 {
4708 float fpos = (float)pos;
4709 if (fpos > m_hAdjust->upper - m_hAdjust->page_size) fpos = m_hAdjust->upper - m_hAdjust->page_size;
4710 if (fpos < 0.0) fpos = 0.0;
4711 m_oldHorizontalPos = fpos;
4712
4713 if (fabs(fpos-m_hAdjust->value) < 0.2) return;
4714 m_hAdjust->value = fpos;
4715 }
4716 else
4717 {
4718 float fpos = (float)pos;
4719 if (fpos > m_vAdjust->upper - m_vAdjust->page_size) fpos = m_vAdjust->upper - m_vAdjust->page_size;
4720 if (fpos < 0.0) fpos = 0.0;
4721 m_oldVerticalPos = fpos;
4722
4723 if (fabs(fpos-m_vAdjust->value) < 0.2) return;
4724 m_vAdjust->value = fpos;
4725 }
4726
4727 if (m_wxwindow->window)
4728 {
4729 if (orient == wxHORIZONTAL)
4730 {
4731 gtk_signal_disconnect_by_func( GTK_OBJECT(m_hAdjust),
4732 (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this );
4733
4734 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" );
4735
4736 gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed",
4737 (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this );
4738 }
4739 else
4740 {
4741 gtk_signal_disconnect_by_func( GTK_OBJECT(m_vAdjust),
4742 (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this );
4743
4744 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" );
4745
4746 gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed",
4747 (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this );
4748 }
4749 }
4750}
4751
4752int wxWindowGTK::GetScrollThumb( int orient ) const
4753{
4754 wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid window") );
4755
4756 wxCHECK_MSG( m_wxwindow != NULL, 0, wxT("window needs client area for scrolling") );
4757
4758 if (orient == wxHORIZONTAL)
4759 return (int)(m_hAdjust->page_size+0.5);
4760 else
4761 return (int)(m_vAdjust->page_size+0.5);
4762}
4763
4764int wxWindowGTK::GetScrollPos( int orient ) const
4765{
4766 wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid window") );
4767
4768 wxCHECK_MSG( m_wxwindow != NULL, 0, wxT("window needs client area for scrolling") );
4769
4770 if (orient == wxHORIZONTAL)
4771 return (int)(m_hAdjust->value+0.5);
4772 else
4773 return (int)(m_vAdjust->value+0.5);
4774}
4775
4776int wxWindowGTK::GetScrollRange( int orient ) const
4777{
4778 wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid window") );
4779
4780 wxCHECK_MSG( m_wxwindow != NULL, 0, wxT("window needs client area for scrolling") );
4781
4782 if (orient == wxHORIZONTAL)
4783 return (int)(m_hAdjust->upper+0.5);
4784 else
4785 return (int)(m_vAdjust->upper+0.5);
4786}
4787
4788void wxWindowGTK::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) )
4789{
4790 wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
4791
4792 wxCHECK_RET( m_wxwindow != NULL, wxT("window needs client area for scrolling") );
4793
4794 // No scrolling requested.
4795 if ((dx == 0) && (dy == 0)) return;
4796
4797#ifndef __WXGTK20__
4798 if (!m_updateRegion.IsEmpty())
4799 {
4800 m_updateRegion.Offset( dx, dy );
4801
4802 int cw = 0;
4803 int ch = 0;
4804 GetClientSize( &cw, &ch );
4805 m_updateRegion.Intersect( 0, 0, cw, ch );
4806 }
4807
4808 if (!m_clearRegion.IsEmpty())
4809 {
4810 m_clearRegion.Offset( dx, dy );
4811
4812 int cw = 0;
4813 int ch = 0;
4814 GetClientSize( &cw, &ch );
4815 m_clearRegion.Intersect( 0, 0, cw, ch );
4816 }
4817#endif
4818
4819 m_clipPaintRegion = TRUE;
4820
4821 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow), -dx, -dy );
4822
4823 m_clipPaintRegion = FALSE;
4824}
4825
4826
4827// Find the wxWindow at the current mouse position, also returning the mouse
4828// position.
4829wxWindow* wxFindWindowAtPointer(wxPoint& pt)
4830{
4831 pt = wxGetMousePosition();
4832 wxWindow* found = wxFindWindowAtPoint(pt);
4833 return found;
4834}
4835
4836// Get the current mouse position.
4837wxPoint wxGetMousePosition()
4838{
4839 /* This crashes when used within wxHelpContext,
4840 so we have to use the X-specific implementation below.
4841 gint x, y;
4842 GdkModifierType *mask;
4843 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4844
4845 return wxPoint(x, y);
4846 */
4847
4848 int x, y;
4849 GdkWindow* windowAtPtr = gdk_window_at_pointer(& x, & y);
4850
4851 Display *display = windowAtPtr ? GDK_WINDOW_XDISPLAY(windowAtPtr) : GDK_DISPLAY();
4852 Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display));
4853 Window rootReturn, childReturn;
4854 int rootX, rootY, winX, winY;
4855 unsigned int maskReturn;
4856
4857 XQueryPointer (display,
4858 rootWindow,
4859 &rootReturn,
4860 &childReturn,
4861 &rootX, &rootY, &winX, &winY, &maskReturn);
4862 return wxPoint(rootX, rootY);
4863
4864}
4865
4866// ----------------------------------------------------------------------------
4867// wxDCModule
4868// ----------------------------------------------------------------------------
4869
4870class wxWinModule : public wxModule
4871{
4872public:
4873 bool OnInit();
4874 void OnExit();
4875
4876private:
4877 DECLARE_DYNAMIC_CLASS(wxWinModule)
4878};
4879
4880IMPLEMENT_DYNAMIC_CLASS(wxWinModule, wxModule)
4881
4882bool wxWinModule::OnInit()
4883{
4884 // g_eraseGC = gdk_gc_new( GDK_ROOT_PARENT() );
4885 // gdk_gc_set_fill( g_eraseGC, GDK_SOLID );
4886
4887 return TRUE;
4888}
4889
4890void wxWinModule::OnExit()
4891{
4892 if (g_eraseGC)
4893 gdk_gc_unref( g_eraseGC );
4894}
4895
4896// vi:sts=4:sw=4:et