1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/window.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Julian Smart
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
14 #define XWarpPointer XWARPPOINTER
17 #include "wx/window.h"
25 #include "wx/dcclient.h"
27 #include "wx/dialog.h"
28 #include "wx/settings.h"
29 #include "wx/msgdlg.h"
32 #include "wx/layout.h"
33 #include "wx/module.h"
34 #include "wx/combobox.h"
36 #if wxUSE_DRAG_AND_DROP
41 #include "wx/tooltip.h"
49 #include "wx/textctrl.h"
52 #include "wx/statusbr.h"
53 #include "wx/fontutil.h"
56 #include "wx/thread.h"
62 #include "wx/gtk1/private.h"
63 #include <gdk/gdkprivate.h>
64 #include <gdk/gdkkeysyms.h>
68 #include <gtk/gtkprivate.h>
70 #include "wx/gtk1/win_gtk.h"
72 //-----------------------------------------------------------------------------
73 // documentation on internals
74 //-----------------------------------------------------------------------------
77 I have been asked several times about writing some documentation about
78 the GTK port of wxWidgets, especially its internal structures. Obviously,
79 you cannot understand wxGTK without knowing a little about the GTK, but
80 some more information about what the wxWindow, which is the base class
81 for all other window classes, does seems required as well.
85 What does wxWindow do? It contains the common interface for the following
86 jobs of its descendants:
88 1) Define the rudimentary behaviour common to all window classes, such as
89 resizing, intercepting user input (so as to make it possible to use these
90 events for special purposes in a derived class), window names etc.
92 2) Provide the possibility to contain and manage children, if the derived
93 class is allowed to contain children, which holds true for those window
94 classes which do not display a native GTK widget. To name them, these
95 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
96 work classes are a special case and are handled a bit differently from
97 the rest. The same holds true for the wxNotebook class.
99 3) Provide the possibility to draw into a client area of a window. This,
100 too, only holds true for classes that do not display a native GTK widget
103 4) Provide the entire mechanism for scrolling widgets. This actual inter-
104 face for this is usually in wxScrolledWindow, but the GTK implementation
107 5) A multitude of helper or extra methods for special purposes, such as
108 Drag'n'Drop, managing validators etc.
110 6) Display a border (sunken, raised, simple or none).
112 Normally one might expect, that one wxWidgets window would always correspond
113 to one GTK widget. Under GTK, there is no such allround widget that has all
114 the functionality. Moreover, the GTK defines a client area as a different
115 widget from the actual widget you are handling. Last but not least some
116 special classes (e.g. wxFrame) handle different categories of widgets and
117 still have the possibility to draw something in the client area.
118 It was therefore required to write a special purpose GTK widget, that would
119 represent a client area in the sense of wxWidgets capable to do the jobs
120 2), 3) and 4). I have written this class and it resides in win_gtk.c of
123 All windows must have a widget, with which they interact with other under-
124 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
125 the wxWindow class has a member variable called m_widget which holds a
126 pointer to this widget. When the window class represents a GTK native widget,
127 this is (in most cases) the only GTK widget the class manages. E.g. the
128 wxStaticText class handles only a GtkLabel widget a pointer to which you
129 can find in m_widget (defined in wxWindow)
131 When the class has a client area for drawing into and for containing children
132 it has to handle the client area widget (of the type GtkPizza, defined in
133 win_gtk.c), but there could be any number of widgets, handled by a class
134 The common rule for all windows is only, that the widget that interacts with
135 the rest of GTK must be referenced in m_widget and all other widgets must be
136 children of this widget on the GTK level. The top-most widget, which also
137 represents the client area, must be in the m_wxwindow field and must be of
140 As I said, the window classes that display a GTK native widget only have
141 one widget, so in the case of e.g. the wxButton class m_widget holds a
142 pointer to a GtkButton widget. But windows with client areas (for drawing
143 and children) have a m_widget field that is a pointer to a GtkScrolled-
144 Window and a m_wxwindow field that is pointer to a GtkPizza and this
145 one is (in the GTK sense) a child of the GtkScrolledWindow.
147 If the m_wxwindow field is set, then all input to this widget is inter-
148 cepted and sent to the wxWidgets class. If not, all input to the widget
149 that gets pointed to by m_widget gets intercepted and sent to the class.
153 The design of scrolling in wxWidgets is markedly different from that offered
154 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
155 clicking on a scrollbar belonging to scrolled window will inevitably move
156 the window. In wxWidgets, the scrollbar will only emit an event, send this
157 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
158 which actually moves the window and its subchildren. Note that GtkPizza
159 memorizes how much it has been scrolled but that wxWidgets forgets this
160 so that the two coordinates systems have to be kept in synch. This is done
161 in various places using the pizza->xoffset and pizza->yoffset values.
165 Singularily the most broken code in GTK is the code that is supposed to
166 inform subwindows (child windows) about new positions. Very often, duplicate
167 events are sent without changes in size or position, equally often no
168 events are sent at all (All this is due to a bug in the GtkContainer code
169 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
170 GTK's own system and it simply waits for size events for toplevel windows
171 and then iterates down the respective size events to all window. This has
172 the disadvantage that windows might get size events before the GTK widget
173 actually has the reported size. This doesn't normally pose any problem, but
174 the OpenGL drawing routines rely on correct behaviour. Therefore, I have
175 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
176 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
177 window that is used for OpenGL output really has that size (as reported by
182 If someone at some point of time feels the immense desire to have a look at,
183 change or attempt to optimise the Refresh() logic, this person will need an
184 intimate understanding of what "draw" and "expose" events are and what
185 they are used for, in particular when used in connection with GTK's
186 own windowless widgets. Beware.
190 Cursors, too, have been a constant source of pleasure. The main difficulty
191 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
192 for the parent. To prevent this from doing too much harm, I use idle time
193 to set the cursor over and over again, starting from the toplevel windows
194 and ending with the youngest generation (speaking of parent and child windows).
195 Also don't forget that cursors (like much else) are connected to GdkWindows,
196 not GtkWidgets and that the "window" field of a GtkWidget might very well
197 point to the GdkWindow of the parent widget (-> "window-less widget") and
198 that the two obviously have very different meanings.
202 //-----------------------------------------------------------------------------
204 //-----------------------------------------------------------------------------
206 extern bool g_blockEventsOnDrag
;
207 extern bool g_blockEventsOnScroll
;
208 extern wxCursor g_globalCursor
;
210 static GdkGC
*g_eraseGC
= NULL
;
212 // mouse capture state: the window which has it and if the mouse is currently
214 static wxWindowGTK
*g_captureWindow
= (wxWindowGTK
*) NULL
;
215 static bool g_captureWindowHasMouse
= false;
217 wxWindowGTK
*g_focusWindow
= (wxWindowGTK
*) NULL
;
219 // the last window which had the focus - this is normally never NULL (except
220 // if we never had focus at all) as even when g_focusWindow is NULL it still
221 // keeps its previous value
222 wxWindowGTK
*g_focusWindowLast
= (wxWindowGTK
*) NULL
;
224 // If a window get the focus set but has not been realized
225 // yet, defer setting the focus to idle time.
226 wxWindowGTK
*g_delayedFocus
= (wxWindowGTK
*) NULL
;
228 // hack: we need something to pass to gtk_menu_popup, so we store the time of
229 // the last click here (extern: used from gtk/menu.cpp)
230 guint32 wxGtkTimeLastClick
= 0;
232 extern bool g_mainThreadLocked
;
234 //-----------------------------------------------------------------------------
236 //-----------------------------------------------------------------------------
241 # define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
243 # define DEBUG_MAIN_THREAD
246 #define DEBUG_MAIN_THREAD
249 // the trace mask used for the focus debugging messages
250 #define TRACE_FOCUS _T("focus")
252 //-----------------------------------------------------------------------------
253 // missing gdk functions
254 //-----------------------------------------------------------------------------
257 gdk_window_warp_pointer (GdkWindow
*window
,
261 GdkWindowPrivate
*priv
;
264 window
= GDK_ROOT_PARENT();
266 priv
= (GdkWindowPrivate
*) window
;
268 if (!priv
->destroyed
)
270 XWarpPointer (priv
->xdisplay
,
271 None
, /* not source window -> move from anywhere */
272 priv
->xwindow
, /* dest window */
273 0, 0, 0, 0, /* not source window -> move from anywhere */
278 //-----------------------------------------------------------------------------
280 //-----------------------------------------------------------------------------
282 extern void wxapp_install_idle_handler();
283 extern bool g_isIdle
;
285 //-----------------------------------------------------------------------------
286 // local code (see below)
287 //-----------------------------------------------------------------------------
289 // returns the child of win which currently has focus or NULL if not found
291 // Note: can't be static, needed by textctrl.cpp.
292 wxWindow
*wxFindFocusedChild(wxWindowGTK
*win
)
294 wxWindow
*winFocus
= wxWindowGTK::FindFocus();
296 return (wxWindow
*)NULL
;
298 if ( winFocus
== win
)
299 return (wxWindow
*)win
;
301 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
303 node
= node
->GetNext() )
305 wxWindow
*child
= wxFindFocusedChild(node
->GetData());
310 return (wxWindow
*)NULL
;
313 static void draw_frame( GtkWidget
*widget
, wxWindowGTK
*win
)
315 // wxUniversal widgets draw the borders and scrollbars themselves
316 #ifndef __WXUNIVERSAL__
323 if (win
->m_hasScrolling
)
325 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(widget
);
327 GtkRequisition vscroll_req
;
328 vscroll_req
.width
= 2;
329 vscroll_req
.height
= 2;
330 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
331 (scroll_window
->vscrollbar
, &vscroll_req
);
333 GtkRequisition hscroll_req
;
334 hscroll_req
.width
= 2;
335 hscroll_req
.height
= 2;
336 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
337 (scroll_window
->hscrollbar
, &hscroll_req
);
339 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(widget
) );
341 if (scroll_window
->vscrollbar_visible
)
343 dw
+= vscroll_req
.width
;
344 dw
+= scroll_class
->scrollbar_spacing
;
347 if (scroll_window
->hscrollbar_visible
)
349 dh
+= hscroll_req
.height
;
350 dh
+= scroll_class
->scrollbar_spacing
;
356 if (GTK_WIDGET_NO_WINDOW (widget
))
358 dx
+= widget
->allocation
.x
;
359 dy
+= widget
->allocation
.y
;
362 if (win
->HasFlag(wxRAISED_BORDER
))
364 gtk_draw_shadow( widget
->style
,
369 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
373 if (win
->HasFlag(wxSUNKEN_BORDER
))
375 gtk_draw_shadow( widget
->style
,
380 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
384 if (win
->HasFlag(wxSIMPLE_BORDER
))
387 gc
= gdk_gc_new( widget
->window
);
388 gdk_gc_set_foreground( gc
, &widget
->style
->black
);
389 gdk_draw_rectangle( widget
->window
, gc
, FALSE
,
391 widget
->allocation
.width
-dw
-1, widget
->allocation
.height
-dh
-1 );
395 #endif // __WXUNIVERSAL__
398 //-----------------------------------------------------------------------------
399 // "expose_event" of m_widget
400 //-----------------------------------------------------------------------------
403 static gint
gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxWindowGTK
*win
)
405 if (gdk_event
->count
> 0) return FALSE
;
407 draw_frame( widget
, win
);
413 //-----------------------------------------------------------------------------
414 // "draw" of m_widget
415 //-----------------------------------------------------------------------------
418 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxWindowGTK
*win
)
420 draw_frame( widget
, win
);
424 //-----------------------------------------------------------------------------
425 // "size_request" of m_widget
426 //-----------------------------------------------------------------------------
428 // make it extern because wxStaticText needs to disconnect this one
430 void wxgtk_window_size_request_callback(GtkWidget
*widget
,
431 GtkRequisition
*requisition
,
435 win
->GetSize( &w
, &h
);
441 requisition
->height
= h
;
442 requisition
->width
= w
;
448 void wxgtk_combo_size_request_callback(GtkWidget
*widget
,
449 GtkRequisition
*requisition
,
452 // This callback is actually hooked into the text entry
453 // of the combo box, not the GtkHBox.
456 win
->GetSize( &w
, &h
);
462 GtkCombo
*gcombo
= GTK_COMBO(win
->m_widget
);
464 GtkRequisition entry_req
;
466 entry_req
.height
= 2;
467 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo
->button
) )->size_request
)
468 (gcombo
->button
, &entry_req
);
470 requisition
->width
= w
- entry_req
.width
;
471 requisition
->height
= entry_req
.height
;
475 //-----------------------------------------------------------------------------
476 // "expose_event" of m_wxwindow
477 //-----------------------------------------------------------------------------
480 static int gtk_window_expose_callback( GtkWidget
*widget
,
481 GdkEventExpose
*gdk_event
,
487 wxapp_install_idle_handler();
489 // This gets called immediately after an expose event
490 // under GTK 1.2 so we collect the calls and wait for
491 // the idle handler to pick things up.
493 win
->GetUpdateRegion().Union( gdk_event
->area
.x
,
495 gdk_event
->area
.width
,
496 gdk_event
->area
.height
);
497 win
->m_clearRegion
.Union( gdk_event
->area
.x
,
499 gdk_event
->area
.width
,
500 gdk_event
->area
.height
);
502 // Actual redrawing takes place in idle time.
509 //-----------------------------------------------------------------------------
510 // "event" of m_wxwindow
511 //-----------------------------------------------------------------------------
513 // GTK thinks it is clever and filters out a certain amount of "unneeded"
514 // expose events. We need them, of course, so we override the main event
515 // procedure in GtkWidget by giving our own handler for all system events.
516 // There, we look for expose events ourselves whereas all other events are
521 gint
gtk_window_event_event_callback( GtkWidget
*widget
,
522 GdkEventExpose
*event
,
525 if (event
->type
== GDK_EXPOSE
)
527 gint ret
= gtk_window_expose_callback( widget
, event
, win
);
535 //-----------------------------------------------------------------------------
536 // "draw" of m_wxwindow
537 //-----------------------------------------------------------------------------
539 // This callback is a complete replacement of the gtk_pizza_draw() function,
540 // which is disabled.
543 static void gtk_window_draw_callback( GtkWidget
*widget
,
550 wxapp_install_idle_handler();
552 // if there are any children we must refresh everything
555 if ( !win
->HasFlag(wxFULL_REPAINT_ON_RESIZE
) &&
556 win
->GetChildren().IsEmpty() )
564 wxPrintf( wxT("OnDraw from ") );
565 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
566 wxPrintf( win
->GetClassInfo()->GetClassName() );
567 wxPrintf( wxT(" %d %d %d %d\n"), (int)rect
->x
,
574 #ifndef __WXUNIVERSAL__
575 GtkPizza
*pizza
= GTK_PIZZA (widget
);
577 if (win
->GetThemeEnabled() && win
->GetBackgroundStyle() == wxBG_STYLE_SYSTEM
)
579 wxWindow
*parent
= win
->GetParent();
580 while (parent
&& !parent
->IsTopLevel())
581 parent
= parent
->GetParent();
585 gtk_paint_flat_box (parent
->m_widget
->style
,
596 win
->m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
597 win
->GetUpdateRegion().Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
599 // Update immediately, not in idle time.
602 #ifndef __WXUNIVERSAL__
603 // Redraw child widgets
604 GList
*children
= pizza
->children
;
607 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
608 children
= children
->next
;
610 GdkRectangle child_area
;
611 if (gtk_widget_intersect (child
->widget
, rect
, &child_area
))
613 gtk_widget_draw (child
->widget
, &child_area
/* (GdkRectangle*) NULL*/ );
620 //-----------------------------------------------------------------------------
621 // "key_press_event" from any window
622 //-----------------------------------------------------------------------------
624 // set WXTRACE to this to see the key event codes on the console
625 #define TRACE_KEYS _T("keyevent")
627 // translates an X key symbol to WXK_XXX value
629 // if isChar is true it means that the value returned will be used for EVT_CHAR
630 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
631 // for example, while if it is false it means that the value is going to be
632 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
634 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
640 // Shift, Control and Alt don't generate the CHAR events at all
643 key_code
= isChar
? 0 : WXK_SHIFT
;
647 key_code
= isChar
? 0 : WXK_CONTROL
;
655 key_code
= isChar
? 0 : WXK_ALT
;
658 // neither do the toggle modifies
659 case GDK_Scroll_Lock
:
660 key_code
= isChar
? 0 : WXK_SCROLL
;
664 key_code
= isChar
? 0 : WXK_CAPITAL
;
668 key_code
= isChar
? 0 : WXK_NUMLOCK
;
672 // various other special keys
685 case GDK_ISO_Left_Tab
:
692 key_code
= WXK_RETURN
;
696 key_code
= WXK_CLEAR
;
700 key_code
= WXK_PAUSE
;
704 key_code
= WXK_SELECT
;
708 key_code
= WXK_PRINT
;
712 key_code
= WXK_EXECUTE
;
716 key_code
= WXK_ESCAPE
;
719 // cursor and other extended keyboard keys
721 key_code
= WXK_DELETE
;
737 key_code
= WXK_RIGHT
;
744 case GDK_Prior
: // == GDK_Page_Up
745 key_code
= WXK_PAGEUP
;
748 case GDK_Next
: // == GDK_Page_Down
749 key_code
= WXK_PAGEDOWN
;
761 key_code
= WXK_INSERT
;
776 key_code
= (isChar
? '0' : WXK_NUMPAD0
) + keysym
- GDK_KP_0
;
780 key_code
= isChar
? ' ' : WXK_NUMPAD_SPACE
;
784 key_code
= isChar
? WXK_TAB
: WXK_NUMPAD_TAB
;
788 key_code
= isChar
? WXK_RETURN
: WXK_NUMPAD_ENTER
;
792 key_code
= isChar
? WXK_F1
: WXK_NUMPAD_F1
;
796 key_code
= isChar
? WXK_F2
: WXK_NUMPAD_F2
;
800 key_code
= isChar
? WXK_F3
: WXK_NUMPAD_F3
;
804 key_code
= isChar
? WXK_F4
: WXK_NUMPAD_F4
;
808 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_HOME
;
812 key_code
= isChar
? WXK_LEFT
: WXK_NUMPAD_LEFT
;
816 key_code
= isChar
? WXK_UP
: WXK_NUMPAD_UP
;
820 key_code
= isChar
? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
824 key_code
= isChar
? WXK_DOWN
: WXK_NUMPAD_DOWN
;
827 case GDK_KP_Prior
: // == GDK_KP_Page_Up
828 key_code
= isChar
? WXK_PAGEUP
: WXK_NUMPAD_PAGEUP
;
831 case GDK_KP_Next
: // == GDK_KP_Page_Down
832 key_code
= isChar
? WXK_NEXT
: WXK_NUMPAD_PAGEDOWN
;
836 key_code
= isChar
? WXK_END
: WXK_NUMPAD_END
;
840 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_BEGIN
;
844 key_code
= isChar
? WXK_INSERT
: WXK_NUMPAD_INSERT
;
848 key_code
= isChar
? WXK_DELETE
: WXK_NUMPAD_DELETE
;
852 key_code
= isChar
? '=' : WXK_NUMPAD_EQUAL
;
855 case GDK_KP_Multiply
:
856 key_code
= isChar
? '*' : WXK_NUMPAD_MULTIPLY
;
860 key_code
= isChar
? '+' : WXK_NUMPAD_ADD
;
863 case GDK_KP_Separator
:
864 // FIXME: what is this?
865 key_code
= isChar
? '.' : WXK_NUMPAD_SEPARATOR
;
868 case GDK_KP_Subtract
:
869 key_code
= isChar
? '-' : WXK_NUMPAD_SUBTRACT
;
873 key_code
= isChar
? '.' : WXK_NUMPAD_DECIMAL
;
877 key_code
= isChar
? '/' : WXK_NUMPAD_DIVIDE
;
894 key_code
= WXK_F1
+ keysym
- GDK_F1
;
904 static inline bool wxIsAsciiKeysym(KeySym ks
)
909 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
911 GdkEventKey
*gdk_event
)
915 GdkModifierType state
;
916 if (gdk_event
->window
)
917 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
919 event
.SetTimestamp( gdk_event
->time
);
920 event
.SetId(win
->GetId());
921 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
922 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
923 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
924 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
) != 0;
925 event
.m_scanCode
= gdk_event
->keyval
;
926 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
927 event
.m_rawFlags
= 0;
929 event
.m_uniChar
= gdk_keyval_to_unicode(gdk_event
->keyval
);
931 wxGetMousePosition( &x
, &y
);
932 win
->ScreenToClient( &x
, &y
);
935 event
.SetEventObject( win
);
940 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
942 GdkEventKey
*gdk_event
)
944 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
945 // but only event->keyval which is quite useless to us, so remember
946 // the last character from GDK_KEY_PRESS and reuse it as last resort
948 // NB: should be MT-safe as we're always called from the main thread only
953 } s_lastKeyPress
= { 0, 0 };
955 KeySym keysym
= gdk_event
->keyval
;
957 wxLogTrace(TRACE_KEYS
, _T("Key %s event: keysym = %ld"),
958 event
.GetEventType() == wxEVT_KEY_UP
? _T("release")
962 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
966 // do we have the translation or is it a plain ASCII character?
967 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
969 // we should use keysym if it is ASCII as X does some translations
970 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
971 // which we don't want here (but which we do use for OnChar())
972 if ( !wxIsAsciiKeysym(keysym
) )
974 keysym
= (KeySym
)gdk_event
->string
[0];
977 // we want to always get the same key code when the same key is
978 // pressed regardless of the state of the modifiers, i.e. on a
979 // standard US keyboard pressing '5' or '%' ('5' key with
980 // Shift) should result in the same key code in OnKeyDown():
981 // '5' (although OnChar() will get either '5' or '%').
983 // to do it we first translate keysym to keycode (== scan code)
984 // and then back but always using the lower register
985 Display
*dpy
= (Display
*)wxGetDisplay();
986 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
988 wxLogTrace(TRACE_KEYS
, _T("\t-> keycode %d"), keycode
);
990 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
992 // use the normalized, i.e. lower register, keysym if we've
994 key_code
= keysymNormalized
? keysymNormalized
: keysym
;
996 // as explained above, we want to have lower register key codes
997 // normally but for the letter keys we want to have the upper ones
999 // NB: don't use XConvertCase() here, we want to do it for letters
1001 key_code
= toupper(key_code
);
1003 else // non ASCII key, what to do?
1005 // by default, ignore it
1008 // but if we have cached information from the last KEY_PRESS
1009 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
1012 if ( keysym
== s_lastKeyPress
.keysym
)
1014 key_code
= s_lastKeyPress
.keycode
;
1019 if ( gdk_event
->type
== GDK_KEY_PRESS
)
1021 // remember it to be reused for KEY_UP event later
1022 s_lastKeyPress
.keysym
= keysym
;
1023 s_lastKeyPress
.keycode
= key_code
;
1027 wxLogTrace(TRACE_KEYS
, _T("\t-> wxKeyCode %ld"), key_code
);
1029 // sending unknown key events doesn't really make sense
1033 // now fill all the other fields
1034 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
1036 event
.m_keyCode
= key_code
;
1043 static gint
gtk_window_key_press_callback( GtkWidget
*widget
,
1044 GdkEventKey
*gdk_event
,
1050 wxapp_install_idle_handler();
1054 if (g_blockEventsOnDrag
)
1058 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1060 bool return_after_IM
= false;
1062 if( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) == false )
1064 // Emit KEY_DOWN event
1065 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1069 // Return after IM processing as we cannot do
1070 // anything with it anyhow.
1071 return_after_IM
= true;
1074 // This is for GTK+ 1.2 only. The char event generatation for GTK+ 2.0 is done
1075 // in the "commit" handler.
1077 // 2005.02.02 modified by Hong Jen Yee (hzysoft@sina.com.tw).
1078 // In GTK+ 1.2, strings sent by IMs are also regarded as key_press events whose
1079 // keyCodes cannot be recognized by wxWidgets. These MBCS strings, however, are
1080 // composed of more than one character, which means gdk_event->length will always
1081 // greater than one. When gtk_event->length == 1, this may be an ASCII character
1082 // and can be translated by wx. However, when MBCS characters are sent by IM,
1083 // gdk_event->length will >= 2. So neither should we pass it to accelerator table,
1084 // nor should we pass it to controls. The following explanation was excerpted
1085 // from GDK documentation.
1086 // gint length : the length of string.
1087 // gchar *string : a null-terminated multi-byte string containing the composed
1088 // characters resulting from the key press. When text is being input, in a GtkEntry
1089 // for example, it is these characters which should be added to the input buffer.
1090 // When using Input Methods to support internationalized text input, the composed
1091 // characters appear here after the pre-editing has been completed.
1093 if ( (!ret
) && (gdk_event
->length
> 1) ) // If this event contains a pre-edited string from IM.
1095 // We should translate this key event into wxEVT_CHAR not wxEVT_KEY_DOWN.
1096 #if wxUSE_UNICODE // GTK+ 1.2 is not UTF-8 based.
1097 const wxWCharBuffer string
= wxConvLocal
.cMB2WC( gdk_event
->string
);
1101 const char* string
= gdk_event
->string
;
1104 // Implement OnCharHook by checking ancestor top level windows
1105 wxWindow
*parent
= win
;
1106 while (parent
&& !parent
->IsTopLevel())
1107 parent
= parent
->GetParent();
1109 for( const wxChar
* pstr
= string
; *pstr
; pstr
++ )
1112 event
.m_uniChar
= *pstr
;
1113 // Backward compatible for ISO-8859-1
1114 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1116 event
.m_keyCode
= *pstr
;
1120 event
.SetEventType( wxEVT_CHAR_HOOK
);
1121 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1125 event
.SetEventType(wxEVT_CHAR
);
1126 win
->GetEventHandler()->ProcessEvent( event
);
1132 if (return_after_IM
)
1138 wxWindowGTK
*ancestor
= win
;
1141 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1144 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1145 ret
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1148 if (ancestor
->IsTopLevel())
1150 ancestor
= ancestor
->GetParent();
1153 #endif // wxUSE_ACCEL
1155 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
1156 // will only be sent if it is not in an accelerator table.
1160 KeySym keysym
= gdk_event
->keyval
;
1161 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
1162 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
1165 if ( wxIsAsciiKeysym(keysym
) )
1168 key_code
= (unsigned char)keysym
;
1170 // gdk_event->string is actually deprecated
1171 else if ( gdk_event
->length
== 1 )
1173 key_code
= (unsigned char)gdk_event
->string
[0];
1179 wxLogTrace(TRACE_KEYS
, _T("Char event: %ld"), key_code
);
1181 event
.m_keyCode
= key_code
;
1183 // Implement OnCharHook by checking ancestor top level windows
1184 wxWindow
*parent
= win
;
1185 while (parent
&& !parent
->IsTopLevel())
1186 parent
= parent
->GetParent();
1189 event
.SetEventType( wxEVT_CHAR_HOOK
);
1190 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1195 event
.SetEventType(wxEVT_CHAR
);
1196 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1205 // win is a control: tab can be propagated up
1207 ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
)) &&
1208 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here - the control may
1209 // have this style, yet choose not to process this particular TAB in which
1210 // case TAB must still work as a navigational character
1211 // JS: enabling again to make consistent with other platforms
1212 // (with wxTE_PROCESS_TAB you have to call Navigate to get default
1213 // navigation behaviour)
1215 (! (win
->HasFlag(wxTE_PROCESS_TAB
) && win
->IsKindOf(CLASSINFO(wxTextCtrl
)) )) &&
1217 win
->GetParent() && (win
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1219 wxNavigationKeyEvent new_event
;
1220 new_event
.SetEventObject( win
->GetParent() );
1221 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
1222 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
1223 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
1224 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
1225 new_event
.SetCurrentFocus( win
);
1226 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent( new_event
);
1229 // generate wxID_CANCEL if <esc> has been pressed (typically in dialogs)
1231 (gdk_event
->keyval
== GDK_Escape
) )
1233 // however only do it if we have a Cancel button in the dialog,
1234 // otherwise the user code may get confused by the events from a
1235 // non-existing button and, worse, a wxButton might get button event
1236 // from another button which is not really expected
1237 wxWindow
*winForCancel
= win
,
1239 while ( winForCancel
)
1241 btnCancel
= winForCancel
->FindWindow(wxID_CANCEL
);
1244 // found a cancel button
1248 if ( winForCancel
->IsTopLevel() )
1250 // no need to look further
1254 // maybe our parent has a cancel button?
1255 winForCancel
= winForCancel
->GetParent();
1260 wxCommandEvent
eventClick(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
1261 eventClick
.SetEventObject(btnCancel
);
1262 ret
= btnCancel
->GetEventHandler()->ProcessEvent(eventClick
);
1268 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
1276 //-----------------------------------------------------------------------------
1277 // "key_release_event" from any window
1278 //-----------------------------------------------------------------------------
1281 static gint
gtk_window_key_release_callback( GtkWidget
*widget
,
1282 GdkEventKey
*gdk_event
,
1288 wxapp_install_idle_handler();
1293 if (g_blockEventsOnDrag
)
1296 wxKeyEvent
event( wxEVT_KEY_UP
);
1297 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1299 // unknown key pressed, ignore (the event would be useless anyhow)
1303 if ( !win
->GetEventHandler()->ProcessEvent( event
) )
1306 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_release_event" );
1311 // ============================================================================
1313 // ============================================================================
1315 // ----------------------------------------------------------------------------
1316 // mouse event processing helpers
1317 // ----------------------------------------------------------------------------
1319 // init wxMouseEvent with the info from GdkEventXXX struct
1320 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1321 wxMouseEvent
& event
,
1324 event
.SetTimestamp( gdk_event
->time
);
1325 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1326 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1327 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1328 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1329 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1330 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1331 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1332 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
1334 event
.m_linesPerAction
= 3;
1335 event
.m_wheelDelta
= 120;
1336 if (((GdkEventButton
*)gdk_event
)->button
== 4)
1337 event
.m_wheelRotation
= 120;
1338 else if (((GdkEventButton
*)gdk_event
)->button
== 5)
1339 event
.m_wheelRotation
= -120;
1342 wxPoint pt
= win
->GetClientAreaOrigin();
1343 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1344 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1346 event
.SetEventObject( win
);
1347 event
.SetId( win
->GetId() );
1348 event
.SetTimestamp( gdk_event
->time
);
1351 static void AdjustEventButtonState(wxMouseEvent
& event
)
1353 // GDK reports the old state of the button for a button press event, but
1354 // for compatibility with MSW and common sense we want m_leftDown be true
1355 // for a LEFT_DOWN event, not FALSE, so we will invert
1356 // left/right/middleDown for the corresponding click events
1358 if ((event
.GetEventType() == wxEVT_LEFT_DOWN
) ||
1359 (event
.GetEventType() == wxEVT_LEFT_DCLICK
) ||
1360 (event
.GetEventType() == wxEVT_LEFT_UP
))
1362 event
.m_leftDown
= !event
.m_leftDown
;
1366 if ((event
.GetEventType() == wxEVT_MIDDLE_DOWN
) ||
1367 (event
.GetEventType() == wxEVT_MIDDLE_DCLICK
) ||
1368 (event
.GetEventType() == wxEVT_MIDDLE_UP
))
1370 event
.m_middleDown
= !event
.m_middleDown
;
1374 if ((event
.GetEventType() == wxEVT_RIGHT_DOWN
) ||
1375 (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) ||
1376 (event
.GetEventType() == wxEVT_RIGHT_UP
))
1378 event
.m_rightDown
= !event
.m_rightDown
;
1383 // find the window to send the mouse event too
1385 wxWindowGTK
*FindWindowForMouseEvent(wxWindowGTK
*win
, wxCoord
& x
, wxCoord
& y
)
1390 if (win
->m_wxwindow
)
1392 GtkPizza
*pizza
= GTK_PIZZA(win
->m_wxwindow
);
1393 xx
+= pizza
->xoffset
;
1394 yy
+= pizza
->yoffset
;
1397 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
1400 wxWindowGTK
*child
= node
->GetData();
1402 node
= node
->GetNext();
1403 if (!child
->IsShown())
1406 if (child
->IsTransparentForMouse())
1408 // wxStaticBox is transparent in the box itself
1409 int xx1
= child
->m_x
;
1410 int yy1
= child
->m_y
;
1411 int xx2
= child
->m_x
+ child
->m_width
;
1412 int yy2
= child
->m_y
+ child
->m_height
;
1415 if (((xx
>= xx1
) && (xx
<= xx1
+10) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1417 ((xx
>= xx2
-10) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1419 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy1
+10)) ||
1421 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy2
-1) && (yy
<= yy2
)))
1432 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1433 (child
->m_x
<= xx
) &&
1434 (child
->m_y
<= yy
) &&
1435 (child
->m_x
+child
->m_width
>= xx
) &&
1436 (child
->m_y
+child
->m_height
>= yy
))
1449 //-----------------------------------------------------------------------------
1450 // "button_press_event"
1451 //-----------------------------------------------------------------------------
1454 static gint
gtk_window_button_press_callback( GtkWidget
*widget
,
1455 GdkEventButton
*gdk_event
,
1461 wxapp_install_idle_handler();
1464 wxPrintf( wxT("1) OnButtonPress from ") );
1465 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1466 wxPrintf( win->GetClassInfo()->GetClassName() );
1467 wxPrintf( wxT(".\n") );
1469 if (!win
->m_hasVMT
) return FALSE
;
1470 if (g_blockEventsOnDrag
) return TRUE
;
1471 if (g_blockEventsOnScroll
) return TRUE
;
1473 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1475 if (win
->m_wxwindow
&& (g_focusWindow
!= win
) && win
->AcceptsFocus())
1477 gtk_widget_grab_focus( win
->m_wxwindow
);
1479 wxPrintf( wxT("GrabFocus from ") );
1480 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1481 wxPrintf( win->GetClassInfo()->GetClassName() );
1482 wxPrintf( wxT(".\n") );
1486 // GDK sends surplus button down events
1487 // before a double click event. We
1488 // need to filter these out.
1489 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1491 GdkEvent
*peek_event
= gdk_event_peek();
1494 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1495 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1497 gdk_event_free( peek_event
);
1502 gdk_event_free( peek_event
);
1507 wxEventType event_type
= wxEVT_NULL
;
1509 if (gdk_event
->button
== 1)
1511 // note that GDK generates triple click events which are not supported
1512 // by wxWidgets but still have to be passed to the app as otherwise
1513 // clicks would simply go missing
1514 switch (gdk_event
->type
)
1516 // we shouldn't get triple clicks at all for GTK2 because we
1517 // suppress them artificially using the code above but we still
1518 // should map them to something for GTK1 and not just ignore them
1519 // as this would lose clicks
1520 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1521 case GDK_BUTTON_PRESS
:
1522 event_type
= wxEVT_LEFT_DOWN
;
1525 case GDK_2BUTTON_PRESS
:
1526 event_type
= wxEVT_LEFT_DCLICK
;
1530 // just to silence gcc warnings
1534 else if (gdk_event
->button
== 2)
1536 switch (gdk_event
->type
)
1538 case GDK_3BUTTON_PRESS
:
1539 case GDK_BUTTON_PRESS
:
1540 event_type
= wxEVT_MIDDLE_DOWN
;
1543 case GDK_2BUTTON_PRESS
:
1544 event_type
= wxEVT_MIDDLE_DCLICK
;
1551 else if (gdk_event
->button
== 3)
1553 switch (gdk_event
->type
)
1555 case GDK_3BUTTON_PRESS
:
1556 case GDK_BUTTON_PRESS
:
1557 event_type
= wxEVT_RIGHT_DOWN
;
1560 case GDK_2BUTTON_PRESS
:
1561 event_type
= wxEVT_RIGHT_DCLICK
;
1568 else if (gdk_event
->button
== 4 || gdk_event
->button
== 5)
1570 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1572 event_type
= wxEVT_MOUSEWHEEL
;
1576 if ( event_type
== wxEVT_NULL
)
1578 // unknown mouse button or click type
1582 wxMouseEvent
event( event_type
);
1583 InitMouseEvent( win
, event
, gdk_event
);
1585 AdjustEventButtonState(event
);
1587 // wxListBox actually gets mouse events from the item, so we need to give it
1588 // a chance to correct this
1589 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1591 // find the correct window to send the event to: it may be a different one
1592 // from the one which got it at GTK+ level because some controls don't have
1593 // their own X window and thus cannot get any events.
1594 if ( !g_captureWindow
)
1595 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1597 wxGtkTimeLastClick
= gdk_event
->time
;
1599 if (event_type
== wxEVT_LEFT_DCLICK
)
1601 // GTK 1.2 crashes when intercepting double
1602 // click events from both wxSpinButton and
1604 if (GTK_IS_SPIN_BUTTON(win
->m_widget
))
1606 // Just disable this event for now.
1611 if (win
->GetEventHandler()->ProcessEvent( event
))
1613 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_press_event" );
1617 if (event_type
== wxEVT_RIGHT_DOWN
)
1619 // generate a "context menu" event: this is similar to right mouse
1620 // click under many GUIs except that it is generated differently
1621 // (right up under MSW, ctrl-click under Mac, right down here) and
1623 // (a) it's a command event and so is propagated to the parent
1624 // (b) under some ports it can be generated from kbd too
1625 // (c) it uses screen coords (because of (a))
1626 wxContextMenuEvent
evtCtx(
1629 win
->ClientToScreen(event
.GetPosition()));
1630 evtCtx
.SetEventObject(win
);
1631 return win
->GetEventHandler()->ProcessEvent(evtCtx
);
1638 //-----------------------------------------------------------------------------
1639 // "button_release_event"
1640 //-----------------------------------------------------------------------------
1643 static gint
gtk_window_button_release_callback( GtkWidget
*widget
,
1644 GdkEventButton
*gdk_event
,
1650 wxapp_install_idle_handler();
1652 if (!win
->m_hasVMT
) return FALSE
;
1653 if (g_blockEventsOnDrag
) return FALSE
;
1654 if (g_blockEventsOnScroll
) return FALSE
;
1656 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1658 wxEventType event_type
= wxEVT_NULL
;
1660 switch (gdk_event
->button
)
1663 event_type
= wxEVT_LEFT_UP
;
1667 event_type
= wxEVT_MIDDLE_UP
;
1671 event_type
= wxEVT_RIGHT_UP
;
1675 // unknwon button, don't process
1679 wxMouseEvent
event( event_type
);
1680 InitMouseEvent( win
, event
, gdk_event
);
1682 AdjustEventButtonState(event
);
1684 // same wxListBox hack as above
1685 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1687 if ( !g_captureWindow
)
1688 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1690 if (win
->GetEventHandler()->ProcessEvent( event
))
1692 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_release_event" );
1700 //-----------------------------------------------------------------------------
1701 // "motion_notify_event"
1702 //-----------------------------------------------------------------------------
1705 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
,
1706 GdkEventMotion
*gdk_event
,
1712 wxapp_install_idle_handler();
1714 if (!win
->m_hasVMT
) return FALSE
;
1715 if (g_blockEventsOnDrag
) return FALSE
;
1716 if (g_blockEventsOnScroll
) return FALSE
;
1718 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1720 if (gdk_event
->is_hint
)
1724 GdkModifierType state
;
1725 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1731 printf( "OnMotion from " );
1732 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1733 printf( win->GetClassInfo()->GetClassName() );
1737 wxMouseEvent
event( wxEVT_MOTION
);
1738 InitMouseEvent(win
, event
, gdk_event
);
1740 if ( g_captureWindow
)
1742 // synthetize a mouse enter or leave event if needed
1743 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1744 // This seems to be necessary and actually been added to
1745 // GDK itself in version 2.0.X
1748 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1749 if ( hasMouse
!= g_captureWindowHasMouse
)
1751 // the mouse changed window
1752 g_captureWindowHasMouse
= hasMouse
;
1754 wxMouseEvent
eventM(g_captureWindowHasMouse
? wxEVT_ENTER_WINDOW
1755 : wxEVT_LEAVE_WINDOW
);
1756 InitMouseEvent(win
, eventM
, gdk_event
);
1757 eventM
.SetEventObject(win
);
1758 win
->GetEventHandler()->ProcessEvent(eventM
);
1763 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1766 if (win
->GetEventHandler()->ProcessEvent( event
))
1768 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "motion_notify_event" );
1776 //-----------------------------------------------------------------------------
1778 //-----------------------------------------------------------------------------
1780 // send the wxChildFocusEvent and wxFocusEvent, common code of
1781 // gtk_window_focus_in_callback() and SetFocus()
1782 static bool DoSendFocusEvents(wxWindow
*win
)
1784 // Notify the parent keeping track of focus for the kbd navigation
1785 // purposes that we got it.
1786 wxChildFocusEvent
eventChildFocus(win
);
1787 (void)win
->GetEventHandler()->ProcessEvent(eventChildFocus
);
1789 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, win
->GetId());
1790 eventFocus
.SetEventObject(win
);
1792 return win
->GetEventHandler()->ProcessEvent(eventFocus
);
1796 static gint
gtk_window_focus_in_callback( GtkWidget
*widget
,
1797 GdkEvent
*WXUNUSED(event
),
1803 wxapp_install_idle_handler();
1806 g_focusWindow
= win
;
1808 wxLogTrace(TRACE_FOCUS
,
1809 _T("%s: focus in"), win
->GetName().c_str());
1813 gdk_im_begin(win
->m_ic
, win
->m_wxwindow
->window
);
1817 // caret needs to be informed about focus change
1818 wxCaret
*caret
= win
->GetCaret();
1821 caret
->OnSetFocus();
1823 #endif // wxUSE_CARET
1825 // does the window itself think that it has the focus?
1826 if ( !win
->m_hasFocus
)
1828 // not yet, notify it
1829 win
->m_hasFocus
= true;
1831 if ( DoSendFocusEvents(win
) )
1833 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_in_event" );
1842 //-----------------------------------------------------------------------------
1843 // "focus_out_event"
1844 //-----------------------------------------------------------------------------
1847 static gint
gtk_window_focus_out_callback( GtkWidget
*widget
, GdkEventFocus
*gdk_event
, wxWindowGTK
*win
)
1852 wxapp_install_idle_handler();
1854 wxLogTrace( TRACE_FOCUS
,
1855 _T("%s: focus out"), win
->GetName().c_str() );
1858 wxWindowGTK
*winFocus
= wxFindFocusedChild(win
);
1862 g_focusWindow
= (wxWindowGTK
*)NULL
;
1870 // caret needs to be informed about focus change
1871 wxCaret
*caret
= win
->GetCaret();
1874 caret
->OnKillFocus();
1876 #endif // wxUSE_CARET
1878 // don't send the window a kill focus event if it thinks that it doesn't
1879 // have focus already
1880 if ( win
->m_hasFocus
)
1882 win
->m_hasFocus
= false;
1884 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
1885 event
.SetEventObject( win
);
1887 // even if we did process the event in wx code, still let GTK itself
1888 // process it too as otherwise bad things happen, especially in GTK2
1889 // where the text control simply aborts the program if it doesn't get
1890 // the matching focus out event
1891 (void)win
->GetEventHandler()->ProcessEvent( event
);
1898 //-----------------------------------------------------------------------------
1899 // "enter_notify_event"
1900 //-----------------------------------------------------------------------------
1904 gint
gtk_window_enter_callback( GtkWidget
*widget
,
1905 GdkEventCrossing
*gdk_event
,
1911 wxapp_install_idle_handler();
1913 if (!win
->m_hasVMT
) return FALSE
;
1914 if (g_blockEventsOnDrag
) return FALSE
;
1916 // Event was emitted after a grab
1917 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1919 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1923 GdkModifierType state
= (GdkModifierType
)0;
1925 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1927 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
1928 InitMouseEvent(win
, event
, gdk_event
);
1929 wxPoint pt
= win
->GetClientAreaOrigin();
1930 event
.m_x
= x
+ pt
.x
;
1931 event
.m_y
= y
+ pt
.y
;
1933 if (win
->GetEventHandler()->ProcessEvent( event
))
1935 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "enter_notify_event" );
1943 //-----------------------------------------------------------------------------
1944 // "leave_notify_event"
1945 //-----------------------------------------------------------------------------
1948 static gint
gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindowGTK
*win
)
1953 wxapp_install_idle_handler();
1955 if (!win
->m_hasVMT
) return FALSE
;
1956 if (g_blockEventsOnDrag
) return FALSE
;
1958 // Event was emitted after an ungrab
1959 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1961 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1963 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
1964 event
.SetTimestamp( gdk_event
->time
);
1965 event
.SetEventObject( win
);
1969 GdkModifierType state
= (GdkModifierType
)0;
1971 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1973 event
.m_shiftDown
= (state
& GDK_SHIFT_MASK
) != 0;
1974 event
.m_controlDown
= (state
& GDK_CONTROL_MASK
) != 0;
1975 event
.m_altDown
= (state
& GDK_MOD1_MASK
) != 0;
1976 event
.m_metaDown
= (state
& GDK_MOD2_MASK
) != 0;
1977 event
.m_leftDown
= (state
& GDK_BUTTON1_MASK
) != 0;
1978 event
.m_middleDown
= (state
& GDK_BUTTON2_MASK
) != 0;
1979 event
.m_rightDown
= (state
& GDK_BUTTON3_MASK
) != 0;
1981 wxPoint pt
= win
->GetClientAreaOrigin();
1982 event
.m_x
= x
+ pt
.x
;
1983 event
.m_y
= y
+ pt
.y
;
1985 if (win
->GetEventHandler()->ProcessEvent( event
))
1987 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "leave_notify_event" );
1995 //-----------------------------------------------------------------------------
1996 // "value_changed" from m_vAdjust
1997 //-----------------------------------------------------------------------------
2000 static void gtk_window_vscroll_callback( GtkAdjustment
*adjust
,
2007 wxapp_install_idle_handler();
2009 if (g_blockEventsOnDrag
) return;
2011 if (!win
->m_hasVMT
) return;
2013 float diff
= adjust
->value
- win
->m_oldVerticalPos
;
2014 if (fabs(diff
) < 0.2) return;
2016 win
->m_oldVerticalPos
= adjust
->value
;
2018 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2019 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->vscrollbar
));
2021 int value
= (int)(adjust
->value
+0.5);
2023 wxScrollWinEvent
event( command
, value
, wxVERTICAL
);
2024 event
.SetEventObject( win
);
2025 win
->GetEventHandler()->ProcessEvent( event
);
2029 //-----------------------------------------------------------------------------
2030 // "value_changed" from m_hAdjust
2031 //-----------------------------------------------------------------------------
2034 static void gtk_window_hscroll_callback( GtkAdjustment
*adjust
,
2041 wxapp_install_idle_handler();
2043 if (g_blockEventsOnDrag
) return;
2044 if (!win
->m_hasVMT
) return;
2046 float diff
= adjust
->value
- win
->m_oldHorizontalPos
;
2047 if (fabs(diff
) < 0.2) return;
2049 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2050 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->hscrollbar
));
2052 win
->m_oldHorizontalPos
= adjust
->value
;
2054 int value
= (int)(adjust
->value
+0.5);
2056 wxScrollWinEvent
event( command
, value
, wxHORIZONTAL
);
2057 event
.SetEventObject( win
);
2058 win
->GetEventHandler()->ProcessEvent( event
);
2062 //-----------------------------------------------------------------------------
2063 // "button_press_event" from scrollbar
2064 //-----------------------------------------------------------------------------
2067 static gint
gtk_scrollbar_button_press_callback( GtkRange
*widget
,
2068 GdkEventButton
*gdk_event
,
2074 wxapp_install_idle_handler();
2077 g_blockEventsOnScroll
= true;
2079 // FIXME: there is no 'slider' field in GTK+ 2.0 any more
2080 win
->m_isScrolling
= (gdk_event
->window
== widget
->slider
);
2086 //-----------------------------------------------------------------------------
2087 // "button_release_event" from scrollbar
2088 //-----------------------------------------------------------------------------
2091 static gint
gtk_scrollbar_button_release_callback( GtkRange
*widget
,
2092 GdkEventButton
*WXUNUSED(gdk_event
),
2097 // don't test here as we can release the mouse while being over
2098 // a different window than the slider
2100 // if (gdk_event->window != widget->slider) return FALSE;
2102 g_blockEventsOnScroll
= false;
2104 if (win
->m_isScrolling
)
2106 wxEventType command
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2110 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2111 if (widget
== GTK_RANGE(scrolledWindow
->hscrollbar
))
2113 value
= (int)(win
->m_hAdjust
->value
+0.5);
2116 if (widget
== GTK_RANGE(scrolledWindow
->vscrollbar
))
2118 value
= (int)(win
->m_vAdjust
->value
+0.5);
2122 wxScrollWinEvent
event( command
, value
, dir
);
2123 event
.SetEventObject( win
);
2124 win
->GetEventHandler()->ProcessEvent( event
);
2127 win
->m_isScrolling
= false;
2133 // ----------------------------------------------------------------------------
2134 // this wxWindowBase function is implemented here (in platform-specific file)
2135 // because it is static and so couldn't be made virtual
2136 // ----------------------------------------------------------------------------
2138 wxWindow
*wxWindowBase::DoFindFocus()
2140 // the cast is necessary when we compile in wxUniversal mode
2141 return (wxWindow
*)g_focusWindow
;
2144 //-----------------------------------------------------------------------------
2145 // "realize" from m_widget
2146 //-----------------------------------------------------------------------------
2148 /* We cannot set colours and fonts before the widget has
2149 been realized, so we do this directly after realization. */
2153 gtk_window_realized_callback( GtkWidget
*m_widget
, wxWindow
*win
)
2158 wxapp_install_idle_handler();
2160 wxWindowCreateEvent
event( win
);
2161 event
.SetEventObject( win
);
2162 win
->GetEventHandler()->ProcessEvent( event
);
2168 //-----------------------------------------------------------------------------
2170 //-----------------------------------------------------------------------------
2174 void gtk_window_size_callback( GtkWidget
*WXUNUSED(widget
),
2175 GtkAllocation
*WXUNUSED(alloc
),
2179 wxapp_install_idle_handler();
2181 if (!win
->m_hasScrolling
) return;
2183 int client_width
= 0;
2184 int client_height
= 0;
2185 win
->GetClientSize( &client_width
, &client_height
);
2186 if ((client_width
== win
->m_oldClientWidth
) && (client_height
== win
->m_oldClientHeight
))
2189 win
->m_oldClientWidth
= client_width
;
2190 win
->m_oldClientHeight
= client_height
;
2192 if (!win
->m_nativeSizeEvent
)
2194 wxSizeEvent
event( win
->GetSize(), win
->GetId() );
2195 event
.SetEventObject( win
);
2196 win
->GetEventHandler()->ProcessEvent( event
);
2203 #define WXUNUSED_UNLESS_XIM(param) param
2205 #define WXUNUSED_UNLESS_XIM(param) WXUNUSED(param)
2208 /* Resize XIM window */
2212 void gtk_wxwindow_size_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2213 GtkAllocation
* WXUNUSED_UNLESS_XIM(alloc
),
2214 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2217 wxapp_install_idle_handler();
2223 if (gdk_ic_get_style (win
->m_ic
) & GDK_IM_PREEDIT_POSITION
)
2227 gdk_window_get_size (widget
->window
, &width
, &height
);
2228 win
->m_icattr
->preedit_area
.width
= width
;
2229 win
->m_icattr
->preedit_area
.height
= height
;
2230 gdk_ic_set_attr (win
->m_ic
, win
->m_icattr
, GDK_IC_PREEDIT_AREA
);
2236 //-----------------------------------------------------------------------------
2237 // "realize" from m_wxwindow
2238 //-----------------------------------------------------------------------------
2240 /* Initialize XIM support */
2244 gtk_wxwindow_realized_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2245 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2248 wxapp_install_idle_handler();
2251 if (win
->m_ic
) return FALSE
;
2252 if (!widget
) return FALSE
;
2253 if (!gdk_im_ready()) return FALSE
;
2255 win
->m_icattr
= gdk_ic_attr_new();
2256 if (!win
->m_icattr
) return FALSE
;
2260 GdkColormap
*colormap
;
2261 GdkICAttr
*attr
= win
->m_icattr
;
2262 unsigned attrmask
= GDK_IC_ALL_REQ
;
2264 GdkIMStyle supported_style
= (GdkIMStyle
)
2265 (GDK_IM_PREEDIT_NONE
|
2266 GDK_IM_PREEDIT_NOTHING
|
2267 GDK_IM_PREEDIT_POSITION
|
2268 GDK_IM_STATUS_NONE
|
2269 GDK_IM_STATUS_NOTHING
);
2271 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2272 supported_style
= (GdkIMStyle
)(supported_style
& ~GDK_IM_PREEDIT_POSITION
);
2274 attr
->style
= style
= gdk_im_decide_style (supported_style
);
2275 attr
->client_window
= widget
->window
;
2277 if ((colormap
= gtk_widget_get_colormap (widget
)) !=
2278 gtk_widget_get_default_colormap ())
2280 attrmask
|= GDK_IC_PREEDIT_COLORMAP
;
2281 attr
->preedit_colormap
= colormap
;
2284 attrmask
|= GDK_IC_PREEDIT_FOREGROUND
;
2285 attrmask
|= GDK_IC_PREEDIT_BACKGROUND
;
2286 attr
->preedit_foreground
= widget
->style
->fg
[GTK_STATE_NORMAL
];
2287 attr
->preedit_background
= widget
->style
->base
[GTK_STATE_NORMAL
];
2289 switch (style
& GDK_IM_PREEDIT_MASK
)
2291 case GDK_IM_PREEDIT_POSITION
:
2292 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2294 g_warning ("over-the-spot style requires fontset");
2298 gdk_window_get_size (widget
->window
, &width
, &height
);
2300 attrmask
|= GDK_IC_PREEDIT_POSITION_REQ
;
2301 attr
->spot_location
.x
= 0;
2302 attr
->spot_location
.y
= height
;
2303 attr
->preedit_area
.x
= 0;
2304 attr
->preedit_area
.y
= 0;
2305 attr
->preedit_area
.width
= width
;
2306 attr
->preedit_area
.height
= height
;
2307 attr
->preedit_fontset
= widget
->style
->font
;
2312 win
->m_ic
= gdk_ic_new (attr
, (GdkICAttributesType
)attrmask
);
2314 if (win
->m_ic
== NULL
)
2315 g_warning ("Can't create input context.");
2318 mask
= gdk_window_get_events (widget
->window
);
2319 mask
= (GdkEventMask
)(mask
| gdk_ic_get_events (win
->m_ic
));
2320 gdk_window_set_events (widget
->window
, mask
);
2322 if (GTK_WIDGET_HAS_FOCUS(widget
))
2323 gdk_im_begin (win
->m_ic
, widget
->window
);
2331 //-----------------------------------------------------------------------------
2332 // InsertChild for wxWindowGTK.
2333 //-----------------------------------------------------------------------------
2335 /* Callback for wxWindowGTK. This very strange beast has to be used because
2336 * C++ has no virtual methods in a constructor. We have to emulate a
2337 * virtual function here as wxNotebook requires a different way to insert
2338 * a child in it. I had opted for creating a wxNotebookPage window class
2339 * which would have made this superfluous (such in the MDI window system),
2340 * but no-one was listening to me... */
2342 static void wxInsertChildInWindow( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2344 /* the window might have been scrolled already, do we
2345 have to adapt the position */
2346 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
2347 child
->m_x
+= pizza
->xoffset
;
2348 child
->m_y
+= pizza
->yoffset
;
2350 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
2351 GTK_WIDGET(child
->m_widget
),
2358 //-----------------------------------------------------------------------------
2360 //-----------------------------------------------------------------------------
2362 wxWindow
*wxGetActiveWindow()
2364 return wxWindow::FindFocus();
2368 wxMouseState
wxGetMouseState()
2374 GdkModifierType mask
;
2376 gdk_window_get_pointer(NULL
, &x
, &y
, &mask
);
2380 ms
.SetLeftDown(mask
& GDK_BUTTON1_MASK
);
2381 ms
.SetMiddleDown(mask
& GDK_BUTTON2_MASK
);
2382 ms
.SetRightDown(mask
& GDK_BUTTON3_MASK
);
2384 ms
.SetControlDown(mask
& GDK_CONTROL_MASK
);
2385 ms
.SetShiftDown(mask
& GDK_SHIFT_MASK
);
2386 ms
.SetAltDown(mask
& GDK_MOD1_MASK
);
2387 ms
.SetMetaDown(mask
& GDK_MOD2_MASK
);
2392 //-----------------------------------------------------------------------------
2394 //-----------------------------------------------------------------------------
2396 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2398 #ifdef __WXUNIVERSAL__
2399 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2401 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
2402 #endif // __WXUNIVERSAL__/__WXGTK__
2404 void wxWindowGTK::Init()
2407 m_widget
= (GtkWidget
*) NULL
;
2408 m_wxwindow
= (GtkWidget
*) NULL
;
2409 m_focusWidget
= (GtkWidget
*) NULL
;
2419 m_needParent
= true;
2420 m_isBeingDeleted
= false;
2423 m_nativeSizeEvent
= false;
2425 m_hasScrolling
= false;
2426 m_isScrolling
= false;
2428 m_hAdjust
= (GtkAdjustment
*) NULL
;
2429 m_vAdjust
= (GtkAdjustment
*) NULL
;
2430 m_oldHorizontalPos
=
2431 m_oldVerticalPos
= 0.0;
2433 m_oldClientHeight
= 0;
2437 m_insertCallback
= (wxInsertChildFunction
) NULL
;
2439 m_acceptsFocus
= false;
2442 m_clipPaintRegion
= false;
2444 m_needsStyleChange
= false;
2446 m_cursor
= *wxSTANDARD_CURSOR
;
2449 m_ic
= (GdkIC
*) NULL
;
2450 m_icattr
= (GdkICAttr
*) NULL
;
2454 wxWindowGTK::wxWindowGTK()
2459 wxWindowGTK::wxWindowGTK( wxWindow
*parent
,
2464 const wxString
&name
)
2468 Create( parent
, id
, pos
, size
, style
, name
);
2471 bool wxWindowGTK::Create( wxWindow
*parent
,
2476 const wxString
&name
)
2478 if (!PreCreation( parent
, pos
, size
) ||
2479 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2481 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2485 m_insertCallback
= wxInsertChildInWindow
;
2487 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
2488 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
2490 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2492 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2493 scroll_class
->scrollbar_spacing
= 0;
2495 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2497 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
2498 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
2500 m_wxwindow
= gtk_pizza_new();
2502 #ifndef __WXUNIVERSAL__
2503 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
2505 if (HasFlag(wxRAISED_BORDER
))
2507 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
2509 else if (HasFlag(wxSUNKEN_BORDER
))
2511 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
2513 else if (HasFlag(wxSIMPLE_BORDER
))
2515 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
2519 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
2521 #endif // __WXUNIVERSAL__
2523 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2525 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
2526 m_acceptsFocus
= true;
2528 // I _really_ don't want scrollbars in the beginning
2529 m_vAdjust
->lower
= 0.0;
2530 m_vAdjust
->upper
= 1.0;
2531 m_vAdjust
->value
= 0.0;
2532 m_vAdjust
->step_increment
= 1.0;
2533 m_vAdjust
->page_increment
= 1.0;
2534 m_vAdjust
->page_size
= 5.0;
2535 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
2536 m_hAdjust
->lower
= 0.0;
2537 m_hAdjust
->upper
= 1.0;
2538 m_hAdjust
->value
= 0.0;
2539 m_hAdjust
->step_increment
= 1.0;
2540 m_hAdjust
->page_increment
= 1.0;
2541 m_hAdjust
->page_size
= 5.0;
2542 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
2544 // these handlers block mouse events to any window during scrolling such as
2545 // motion events and prevent GTK and wxWidgets from fighting over where the
2548 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_press_event",
2549 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2551 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_press_event",
2552 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2554 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_release_event",
2555 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2557 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_release_event",
2558 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2560 // these handlers get notified when screen updates are required either when
2561 // scrolling or when the window size (and therefore scrollbar configuration)
2564 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
2565 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
2566 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
2567 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
2569 gtk_widget_show( m_wxwindow
);
2572 m_parent
->DoAddChild( this );
2574 m_focusWidget
= m_wxwindow
;
2581 wxWindowGTK::~wxWindowGTK()
2585 if (g_focusWindow
== this)
2586 g_focusWindow
= NULL
;
2588 if ( g_delayedFocus
== this )
2589 g_delayedFocus
= NULL
;
2591 m_isBeingDeleted
= true;
2594 // destroy children before destroying this window itself
2597 // unhook focus handlers to prevent stray events being
2598 // propagated to this (soon to be) dead object
2599 if (m_focusWidget
!= NULL
)
2601 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2602 (GtkSignalFunc
) gtk_window_focus_in_callback
, (gpointer
) this );
2603 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2604 (GtkSignalFunc
) gtk_window_focus_out_callback
, (gpointer
) this );
2612 gdk_ic_destroy (m_ic
);
2614 gdk_ic_attr_destroy (m_icattr
);
2619 gtk_widget_destroy( m_wxwindow
);
2620 m_wxwindow
= (GtkWidget
*) NULL
;
2625 gtk_widget_destroy( m_widget
);
2626 m_widget
= (GtkWidget
*) NULL
;
2630 bool wxWindowGTK::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2632 wxCHECK_MSG( !m_needParent
|| parent
, false, wxT("Need complete parent.") );
2634 // Use either the given size, or the default if -1 is given.
2635 // See wxWindowBase for these functions.
2636 m_width
= WidthDefault(size
.x
) ;
2637 m_height
= HeightDefault(size
.y
);
2645 void wxWindowGTK::PostCreation()
2647 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2653 // these get reported to wxWidgets -> wxPaintEvent
2655 gtk_pizza_set_external( GTK_PIZZA(m_wxwindow
), TRUE
);
2657 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
2658 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
2660 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
2661 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
2663 if (!HasFlag(wxFULL_REPAINT_ON_RESIZE
))
2665 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "event",
2666 GTK_SIGNAL_FUNC(gtk_window_event_event_callback
), (gpointer
)this );
2670 // these are called when the "sunken" or "raised" borders are drawn
2671 gtk_signal_connect( GTK_OBJECT(m_widget
), "expose_event",
2672 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
2674 gtk_signal_connect( GTK_OBJECT(m_widget
), "draw",
2675 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
2680 if (!GTK_IS_WINDOW(m_widget
))
2682 if (m_focusWidget
== NULL
)
2683 m_focusWidget
= m_widget
;
2685 gtk_signal_connect( GTK_OBJECT(m_focusWidget
), "focus_in_event",
2686 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
2688 gtk_signal_connect_after( GTK_OBJECT(m_focusWidget
), "focus_out_event",
2689 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
2692 // connect to the various key and mouse handlers
2694 GtkWidget
*connect_widget
= GetConnectWidget();
2696 ConnectWidget( connect_widget
);
2698 /* We cannot set colours, fonts and cursors before the widget has
2699 been realized, so we do this directly after realization */
2700 gtk_signal_connect( GTK_OBJECT(connect_widget
), "realize",
2701 GTK_SIGNAL_FUNC(gtk_window_realized_callback
), (gpointer
) this );
2705 // Catch native resize events
2706 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
2707 GTK_SIGNAL_FUNC(gtk_window_size_callback
), (gpointer
)this );
2709 // Initialize XIM support
2710 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "realize",
2711 GTK_SIGNAL_FUNC(gtk_wxwindow_realized_callback
), (gpointer
) this );
2713 // And resize XIM window
2714 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
2715 GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback
), (gpointer
)this );
2718 if (GTK_IS_COMBO(m_widget
))
2720 GtkCombo
*gcombo
= GTK_COMBO(m_widget
);
2722 gtk_signal_connect( GTK_OBJECT(gcombo
->entry
), "size_request",
2723 GTK_SIGNAL_FUNC(wxgtk_combo_size_request_callback
),
2728 // This is needed if we want to add our windows into native
2729 // GTK controls, such as the toolbar. With this callback, the
2730 // toolbar gets to know the correct size (the one set by the
2731 // programmer). Sadly, it misbehaves for wxComboBox.
2732 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_request",
2733 GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback
),
2737 InheritAttributes();
2741 // unless the window was created initially hidden (i.e. Hide() had been
2742 // called before Create()), we should show it at GTK+ level as well
2744 gtk_widget_show( m_widget
);
2747 void wxWindowGTK::ConnectWidget( GtkWidget
*widget
)
2749 gtk_signal_connect( GTK_OBJECT(widget
), "key_press_event",
2750 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
2752 gtk_signal_connect( GTK_OBJECT(widget
), "key_release_event",
2753 GTK_SIGNAL_FUNC(gtk_window_key_release_callback
), (gpointer
)this );
2755 gtk_signal_connect( GTK_OBJECT(widget
), "button_press_event",
2756 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
2758 gtk_signal_connect( GTK_OBJECT(widget
), "button_release_event",
2759 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
2761 gtk_signal_connect( GTK_OBJECT(widget
), "motion_notify_event",
2762 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
2764 gtk_signal_connect( GTK_OBJECT(widget
), "enter_notify_event",
2765 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
2767 gtk_signal_connect( GTK_OBJECT(widget
), "leave_notify_event",
2768 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
2771 bool wxWindowGTK::Destroy()
2773 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2777 return wxWindowBase::Destroy();
2780 void wxWindowGTK::DoMoveWindow(int x
, int y
, int width
, int height
)
2782 gtk_pizza_set_size( GTK_PIZZA(m_parent
->m_wxwindow
), m_widget
, x
, y
, width
, height
);
2785 void wxWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
2787 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2788 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
2791 printf( "DoSetSize: name %s, x,y,w,h: %d,%d,%d,%d \n", GetName().c_str(), x,y,width,height );
2794 if (m_resizing
) return; /* I don't like recursions */
2797 int currentX
, currentY
;
2798 GetPosition(¤tX
, ¤tY
);
2799 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2801 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2803 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2805 if (m_parent
->m_wxwindow
== NULL
) /* i.e. wxNotebook */
2807 /* don't set the size for children of wxNotebook, just take the values. */
2815 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
2816 if ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0)
2818 if (x
!= -1) m_x
= x
+ pizza
->xoffset
;
2819 if (y
!= -1) m_y
= y
+ pizza
->yoffset
;
2823 m_x
= x
+ pizza
->xoffset
;
2824 m_y
= y
+ pizza
->yoffset
;
2827 // calculate the best size if we should auto size the window
2828 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
2829 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
2831 const wxSize sizeBest
= GetBestSize();
2832 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
2834 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
2835 height
= sizeBest
.y
;
2843 int minWidth
= GetMinWidth(),
2844 minHeight
= GetMinHeight(),
2845 maxWidth
= GetMaxWidth(),
2846 maxHeight
= GetMaxHeight();
2848 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
2849 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
2850 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
2851 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
2853 int left_border
= 0;
2854 int right_border
= 0;
2856 int bottom_border
= 0;
2858 /* the default button has a border around it */
2859 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
2867 DoMoveWindow( m_x
-top_border
,
2869 m_width
+left_border
+right_border
,
2870 m_height
+top_border
+bottom_border
);
2875 /* Sometimes the client area changes size without the
2876 whole windows's size changing, but if the whole
2877 windows's size doesn't change, no wxSizeEvent will
2878 normally be sent. Here we add an extra test if
2879 the client test has been changed and this will
2881 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
2885 wxPrintf( "OnSize sent from " );
2886 if (GetClassInfo() && GetClassInfo()->GetClassName())
2887 wxPrintf( GetClassInfo()->GetClassName() );
2888 wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height );
2891 if (!m_nativeSizeEvent
)
2893 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
2894 event
.SetEventObject( this );
2895 GetEventHandler()->ProcessEvent( event
);
2901 void wxWindowGTK::OnInternalIdle()
2903 // Update style if the window was not yet realized
2904 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
2905 if (m_needsStyleChange
)
2907 SetBackgroundStyle(GetBackgroundStyle());
2908 m_needsStyleChange
= false;
2911 // Update invalidated regions.
2914 wxCursor cursor
= m_cursor
;
2915 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
2919 /* I now set the cursor anew in every OnInternalIdle call
2920 as setting the cursor in a parent window also effects the
2921 windows above so that checking for the current cursor is
2926 GdkWindow
*window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
2928 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2930 if (!g_globalCursor
.Ok())
2931 cursor
= *wxSTANDARD_CURSOR
;
2933 window
= m_widget
->window
;
2934 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2935 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2941 GdkWindow
*window
= m_widget
->window
;
2942 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2943 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2948 if (wxUpdateUIEvent::CanUpdate(this))
2949 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2952 void wxWindowGTK::DoGetSize( int *width
, int *height
) const
2954 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2956 if (width
) (*width
) = m_width
;
2957 if (height
) (*height
) = m_height
;
2960 void wxWindowGTK::DoSetClientSize( int width
, int height
)
2962 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2966 SetSize( width
, height
);
2973 #ifndef __WXUNIVERSAL__
2974 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
2976 /* when using GTK 1.2 we set the shadow border size to 2 */
2980 if (HasFlag(wxSIMPLE_BORDER
))
2982 /* when using GTK 1.2 we set the simple border size to 1 */
2986 #endif // __WXUNIVERSAL__
2990 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
2992 GtkRequisition vscroll_req
;
2993 vscroll_req
.width
= 2;
2994 vscroll_req
.height
= 2;
2995 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
2996 (scroll_window
->vscrollbar
, &vscroll_req
);
2998 GtkRequisition hscroll_req
;
2999 hscroll_req
.width
= 2;
3000 hscroll_req
.height
= 2;
3001 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
3002 (scroll_window
->hscrollbar
, &hscroll_req
);
3004 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3006 if (scroll_window
->vscrollbar_visible
)
3008 dw
+= vscroll_req
.width
;
3009 dw
+= scroll_class
->scrollbar_spacing
;
3012 if (scroll_window
->hscrollbar_visible
)
3014 dh
+= hscroll_req
.height
;
3015 dh
+= scroll_class
->scrollbar_spacing
;
3019 SetSize( width
+dw
, height
+dh
);
3023 void wxWindowGTK::DoGetClientSize( int *width
, int *height
) const
3025 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3029 if (width
) (*width
) = m_width
;
3030 if (height
) (*height
) = m_height
;
3037 #ifndef __WXUNIVERSAL__
3038 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
3040 /* when using GTK 1.2 we set the shadow border size to 2 */
3044 if (HasFlag(wxSIMPLE_BORDER
))
3046 /* when using GTK 1.2 we set the simple border size to 1 */
3050 #endif // __WXUNIVERSAL__
3054 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
3056 GtkRequisition vscroll_req
;
3057 vscroll_req
.width
= 2;
3058 vscroll_req
.height
= 2;
3059 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
3060 (scroll_window
->vscrollbar
, &vscroll_req
);
3062 GtkRequisition hscroll_req
;
3063 hscroll_req
.width
= 2;
3064 hscroll_req
.height
= 2;
3065 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
3066 (scroll_window
->hscrollbar
, &hscroll_req
);
3068 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3070 if (scroll_window
->vscrollbar_visible
)
3072 dw
+= vscroll_req
.width
;
3073 dw
+= scroll_class
->scrollbar_spacing
;
3076 if (scroll_window
->hscrollbar_visible
)
3078 dh
+= hscroll_req
.height
;
3079 dh
+= scroll_class
->scrollbar_spacing
;
3083 if (width
) (*width
) = m_width
- dw
;
3084 if (height
) (*height
) = m_height
- dh
;
3088 printf( "GetClientSize, name %s ", GetName().c_str() );
3089 if (width) printf( " width = %d", (*width) );
3090 if (height) printf( " height = %d", (*height) );
3095 void wxWindowGTK::DoGetPosition( int *x
, int *y
) const
3097 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3101 if (m_parent
&& m_parent
->m_wxwindow
)
3103 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
3104 dx
= pizza
->xoffset
;
3105 dy
= pizza
->yoffset
;
3108 if (x
) (*x
) = m_x
- dx
;
3109 if (y
) (*y
) = m_y
- dy
;
3112 void wxWindowGTK::DoClientToScreen( int *x
, int *y
) const
3114 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3116 if (!m_widget
->window
) return;
3118 GdkWindow
*source
= (GdkWindow
*) NULL
;
3120 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3122 source
= m_widget
->window
;
3126 gdk_window_get_origin( source
, &org_x
, &org_y
);
3130 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3132 org_x
+= m_widget
->allocation
.x
;
3133 org_y
+= m_widget
->allocation
.y
;
3141 void wxWindowGTK::DoScreenToClient( int *x
, int *y
) const
3143 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3145 if (!m_widget
->window
) return;
3147 GdkWindow
*source
= (GdkWindow
*) NULL
;
3149 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3151 source
= m_widget
->window
;
3155 gdk_window_get_origin( source
, &org_x
, &org_y
);
3159 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3161 org_x
+= m_widget
->allocation
.x
;
3162 org_y
+= m_widget
->allocation
.y
;
3170 bool wxWindowGTK::Show( bool show
)
3172 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3174 if (!wxWindowBase::Show(show
))
3181 gtk_widget_show( m_widget
);
3183 gtk_widget_hide( m_widget
);
3185 wxShowEvent
eventShow(GetId(), show
);
3186 eventShow
.SetEventObject(this);
3188 GetEventHandler()->ProcessEvent(eventShow
);
3193 static void wxWindowNotifyEnable(wxWindowGTK
* win
, bool enable
)
3195 win
->OnParentEnable(enable
);
3197 // Recurse, so that children have the opportunity to Do The Right Thing
3198 // and reset colours that have been messed up by a parent's (really ancestor's)
3200 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3202 node
= node
->GetNext() )
3204 wxWindow
*child
= node
->GetData();
3205 if (!child
->IsKindOf(CLASSINFO(wxDialog
)) && !child
->IsKindOf(CLASSINFO(wxFrame
)))
3206 wxWindowNotifyEnable(child
, enable
);
3210 bool wxWindowGTK::Enable( bool enable
)
3212 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3214 if (!wxWindowBase::Enable(enable
))
3220 gtk_widget_set_sensitive( m_widget
, enable
);
3222 gtk_widget_set_sensitive( m_wxwindow
, enable
);
3224 wxWindowNotifyEnable(this, enable
);
3229 int wxWindowGTK::GetCharHeight() const
3231 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
3233 wxFont font
= GetFont();
3234 wxCHECK_MSG( font
.Ok(), 12, wxT("invalid font") );
3236 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3238 return gfont
->ascent
+ gfont
->descent
;
3241 int wxWindowGTK::GetCharWidth() const
3243 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
3245 wxFont font
= GetFont();
3246 wxCHECK_MSG( font
.Ok(), 8, wxT("invalid font") );
3248 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3250 return gdk_string_width( gfont
, "g" );
3253 void wxWindowGTK::GetTextExtent( const wxString
& string
,
3257 int *externalLeading
,
3258 const wxFont
*theFont
) const
3260 wxFont fontToUse
= theFont
? *theFont
: GetFont();
3262 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
3271 GdkFont
*font
= fontToUse
.GetInternalFont( 1.0 );
3272 if (x
) (*x
) = gdk_string_width( font
, wxGTK_CONV( string
) );
3273 if (y
) (*y
) = font
->ascent
+ font
->descent
;
3274 if (descent
) (*descent
) = font
->descent
;
3275 if (externalLeading
) (*externalLeading
) = 0; // ??
3278 void wxWindowGTK::SetFocus()
3280 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3283 // don't do anything if we already have focus
3289 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow
))
3291 gtk_widget_grab_focus (m_wxwindow
);
3296 if (GTK_WIDGET_CAN_FOCUS(m_widget
) && !GTK_WIDGET_HAS_FOCUS (m_widget
) )
3299 if (!GTK_WIDGET_REALIZED(m_widget
))
3301 // we can't set the focus to the widget now so we remember that
3302 // it should be focused and will do it later, during the idle
3303 // time, as soon as we can
3304 wxLogTrace(TRACE_FOCUS
,
3305 _T("Delaying setting focus to %s(%s)"),
3306 GetClassInfo()->GetClassName(), GetLabel().c_str());
3308 g_delayedFocus
= this;
3312 wxLogTrace(TRACE_FOCUS
,
3313 _T("Setting focus to %s(%s)"),
3314 GetClassInfo()->GetClassName(), GetLabel().c_str());
3316 gtk_widget_grab_focus (m_widget
);
3320 if (GTK_IS_CONTAINER(m_widget
))
3322 gtk_container_focus( GTK_CONTAINER(m_widget
), GTK_DIR_TAB_FORWARD
);
3326 wxLogTrace(TRACE_FOCUS
,
3327 _T("Can't set focus to %s(%s)"),
3328 GetClassInfo()->GetClassName(), GetLabel().c_str());
3333 bool wxWindowGTK::AcceptsFocus() const
3335 return m_acceptsFocus
&& wxWindowBase::AcceptsFocus();
3338 bool wxWindowGTK::Reparent( wxWindowBase
*newParentBase
)
3340 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3342 wxWindowGTK
*oldParent
= m_parent
,
3343 *newParent
= (wxWindowGTK
*)newParentBase
;
3345 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3347 if ( !wxWindowBase::Reparent(newParent
) )
3350 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3352 /* prevent GTK from deleting the widget arbitrarily */
3353 gtk_widget_ref( m_widget
);
3357 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3360 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3364 /* insert GTK representation */
3365 (*(newParent
->m_insertCallback
))(newParent
, this);
3368 /* reverse: prevent GTK from deleting the widget arbitrarily */
3369 gtk_widget_unref( m_widget
);
3374 void wxWindowGTK::DoAddChild(wxWindowGTK
*child
)
3376 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3378 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3380 wxASSERT_MSG( (m_insertCallback
!= NULL
), wxT("invalid child insertion function") );
3385 /* insert GTK representation */
3386 (*m_insertCallback
)(this, child
);
3389 void wxWindowGTK::Raise()
3391 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3393 if (m_wxwindow
&& m_wxwindow
->window
)
3395 gdk_window_raise( m_wxwindow
->window
);
3397 else if (m_widget
->window
)
3399 gdk_window_raise( m_widget
->window
);
3403 void wxWindowGTK::Lower()
3405 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3407 if (m_wxwindow
&& m_wxwindow
->window
)
3409 gdk_window_lower( m_wxwindow
->window
);
3411 else if (m_widget
->window
)
3413 gdk_window_lower( m_widget
->window
);
3417 bool wxWindowGTK::SetCursor( const wxCursor
&cursor
)
3419 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3421 if (cursor
== m_cursor
)
3425 wxapp_install_idle_handler();
3427 if (cursor
== wxNullCursor
)
3428 return wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
);
3430 return wxWindowBase::SetCursor( cursor
);
3433 void wxWindowGTK::WarpPointer( int x
, int y
)
3435 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3437 // We provide this function ourselves as it is
3438 // missing in GDK (top of this file).
3440 GdkWindow
*window
= (GdkWindow
*) NULL
;
3442 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3444 window
= GetConnectWidget()->window
;
3447 gdk_window_warp_pointer( window
, x
, y
);
3451 void wxWindowGTK::Refresh( bool eraseBackground
, const wxRect
*rect
)
3455 if (!m_widget
->window
)
3459 wxapp_install_idle_handler();
3462 if (m_wxwindow
&& rect
)
3464 myRect
.SetSize(wxSize( m_wxwindow
->allocation
.width
,
3465 m_wxwindow
->allocation
.height
));
3466 if ( myRect
.Intersect(*rect
).IsEmpty() )
3468 // nothing to do, rectangle is empty
3475 // schedule the area for later updating in GtkUpdate()
3476 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
3480 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3484 m_clearRegion
.Clear();
3485 m_clearRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
3493 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3497 GdkRectangle gdk_rect
;
3498 gdk_rect
.x
= rect
->x
;
3499 gdk_rect
.y
= rect
->y
;
3500 gdk_rect
.width
= rect
->width
;
3501 gdk_rect
.height
= rect
->height
;
3502 gtk_widget_draw( m_widget
, &gdk_rect
);
3509 m_updateRegion
.Clear();
3510 m_updateRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
3514 gtk_widget_draw( m_widget
, (GdkRectangle
*) NULL
);
3519 void wxWindowGTK::Update()
3523 // when we call Update() we really want to update the window immediately on
3524 // screen, even if it means flushing the entire queue and hence slowing down
3525 // everything -- but it should still be done, it's just that Update() should
3526 // be called very rarely
3530 void wxWindowGTK::GtkUpdate()
3532 if (!m_updateRegion
.IsEmpty())
3533 GtkSendPaintEvents();
3535 // for consistency with other platforms (and also because it's convenient
3536 // to be able to update an entire TLW by calling Update() only once), we
3537 // should also update all our children here
3538 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3540 node
= node
->GetNext() )
3542 node
->GetData()->GtkUpdate();
3546 void wxWindowGTK::GtkSendPaintEvents()
3550 m_clearRegion
.Clear();
3551 m_updateRegion
.Clear();
3555 // Clip to paint region in wxClientDC
3556 m_clipPaintRegion
= true;
3558 // widget to draw on
3559 GtkPizza
*pizza
= GTK_PIZZA (m_wxwindow
);
3561 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM
))
3563 // find ancestor from which to steal background
3564 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3566 parent
= (wxWindow
*)this;
3568 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
3570 wxRegionIterator
upd( m_updateRegion
);
3574 rect
.x
= upd
.GetX();
3575 rect
.y
= upd
.GetY();
3576 rect
.width
= upd
.GetWidth();
3577 rect
.height
= upd
.GetHeight();
3579 gtk_paint_flat_box( parent
->m_widget
->style
,
3581 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
3594 // if (!m_clearRegion.IsEmpty()) // Always send an erase event under GTK 1.2
3596 wxWindowDC
dc( (wxWindow
*)this );
3597 if (m_clearRegion
.IsEmpty())
3598 dc
.SetClippingRegion( m_updateRegion
);
3600 dc
.SetClippingRegion( m_clearRegion
);
3602 wxEraseEvent
erase_event( GetId(), &dc
);
3603 erase_event
.SetEventObject( this );
3605 if (!GetEventHandler()->ProcessEvent(erase_event
) && GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3609 g_eraseGC
= gdk_gc_new( pizza
->bin_window
);
3610 gdk_gc_set_fill( g_eraseGC
, GDK_SOLID
);
3612 gdk_gc_set_foreground( g_eraseGC
, GetBackgroundColour().GetColor() );
3614 wxRegionIterator
upd( m_clearRegion
);
3617 gdk_draw_rectangle( pizza
->bin_window
, g_eraseGC
, 1,
3618 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
3622 m_clearRegion
.Clear();
3625 wxNcPaintEvent
nc_paint_event( GetId() );
3626 nc_paint_event
.SetEventObject( this );
3627 GetEventHandler()->ProcessEvent( nc_paint_event
);
3629 wxPaintEvent
paint_event( GetId() );
3630 paint_event
.SetEventObject( this );
3631 GetEventHandler()->ProcessEvent( paint_event
);
3633 m_clipPaintRegion
= false;
3635 #if !defined(__WXUNIVERSAL__)
3636 // The following code will result in all window-less widgets
3637 // being redrawn because the wxWidgets class is allowed to
3638 // paint over the window-less widgets.
3640 GList
*children
= pizza
->children
;
3643 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
3644 children
= children
->next
;
3646 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
3647 GTK_WIDGET_DRAWABLE (child
->widget
))
3649 // Get intersection of widget area and update region
3650 wxRegion
region( m_updateRegion
);
3652 GdkEventExpose gdk_event
;
3653 gdk_event
.type
= GDK_EXPOSE
;
3654 gdk_event
.window
= pizza
->bin_window
;
3655 gdk_event
.count
= 0;
3656 gdk_event
.send_event
= TRUE
;
3658 wxRegionIterator
upd( m_updateRegion
);
3662 rect
.x
= upd
.GetX();
3663 rect
.y
= upd
.GetY();
3664 rect
.width
= upd
.GetWidth();
3665 rect
.height
= upd
.GetHeight();
3667 if (gtk_widget_intersect (child
->widget
, &rect
, &gdk_event
.area
))
3669 gtk_widget_event (child
->widget
, (GdkEvent
*) &gdk_event
);
3676 #endif // native GTK 1
3678 m_updateRegion
.Clear();
3681 void wxWindowGTK::ClearBackground()
3683 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3685 if (m_wxwindow
&& m_wxwindow
->window
)
3687 m_clearRegion
.Clear();
3688 wxSize
size( GetClientSize() );
3689 m_clearRegion
.Union( 0,0,size
.x
,size
.y
);
3691 // Better do this in idle?
3697 void wxWindowGTK::DoSetToolTip( wxToolTip
*tip
)
3699 wxWindowBase::DoSetToolTip(tip
);
3702 m_tooltip
->Apply( (wxWindow
*)this );
3705 void wxWindowGTK::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
3707 wxString
tmp( tip
);
3708 gtk_tooltips_set_tip( tips
, GetConnectWidget(), wxGTK_CONV(tmp
), (gchar
*) NULL
);
3710 #endif // wxUSE_TOOLTIPS
3712 bool wxWindowGTK::SetBackgroundColour( const wxColour
&colour
)
3714 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3716 if (!wxWindowBase::SetBackgroundColour(colour
))
3721 // We need the pixel value e.g. for background clearing.
3722 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3725 // apply style change (forceStyle=true so that new style is applied
3726 // even if the bg colour changed from valid to wxNullColour)
3727 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3728 ApplyWidgetStyle(true);
3733 bool wxWindowGTK::SetForegroundColour( const wxColour
&colour
)
3735 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3737 if (!wxWindowBase::SetForegroundColour(colour
))
3744 // We need the pixel value e.g. for background clearing.
3745 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3748 // apply style change (forceStyle=true so that new style is applied
3749 // even if the bg colour changed from valid to wxNullColour):
3750 ApplyWidgetStyle(true);
3755 GtkRcStyle
*wxWindowGTK::CreateWidgetStyle(bool forceStyle
)
3757 // do we need to apply any changes at all?
3760 !m_foregroundColour
.Ok() && !m_backgroundColour
.Ok() )
3765 GtkRcStyle
*style
= gtk_rc_style_new();
3769 wxString xfontname
= m_font
.GetNativeFontInfo()->GetXFontName();
3770 style
->fontset_name
= g_strdup(xfontname
.c_str());
3773 if ( m_foregroundColour
.Ok() )
3775 GdkColor
*fg
= m_foregroundColour
.GetColor();
3777 style
->fg
[GTK_STATE_NORMAL
] = *fg
;
3778 style
->color_flags
[GTK_STATE_NORMAL
] = GTK_RC_FG
;
3780 style
->fg
[GTK_STATE_PRELIGHT
] = *fg
;
3781 style
->color_flags
[GTK_STATE_PRELIGHT
] = GTK_RC_FG
;
3783 style
->fg
[GTK_STATE_ACTIVE
] = *fg
;
3784 style
->color_flags
[GTK_STATE_ACTIVE
] = GTK_RC_FG
;
3787 if ( m_backgroundColour
.Ok() )
3789 GdkColor
*bg
= m_backgroundColour
.GetColor();
3791 style
->bg
[GTK_STATE_NORMAL
] = *bg
;
3792 style
->base
[GTK_STATE_NORMAL
] = *bg
;
3793 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)
3794 (style
->color_flags
[GTK_STATE_NORMAL
] | GTK_RC_BG
| GTK_RC_BASE
);
3796 style
->bg
[GTK_STATE_PRELIGHT
] = *bg
;
3797 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
3798 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)
3799 (style
->color_flags
[GTK_STATE_PRELIGHT
] | GTK_RC_BG
| GTK_RC_BASE
);
3801 style
->bg
[GTK_STATE_ACTIVE
] = *bg
;
3802 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
3803 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)
3804 (style
->color_flags
[GTK_STATE_ACTIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3806 style
->bg
[GTK_STATE_INSENSITIVE
] = *bg
;
3807 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
3808 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)
3809 (style
->color_flags
[GTK_STATE_INSENSITIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3815 void wxWindowGTK::ApplyWidgetStyle(bool forceStyle
)
3817 GtkRcStyle
*style
= CreateWidgetStyle(forceStyle
);
3820 DoApplyWidgetStyle(style
);
3821 gtk_rc_style_unref(style
);
3824 // Style change may affect GTK+'s size calculation:
3825 InvalidateBestSize();
3828 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle
*style
)
3831 gtk_widget_modify_style(m_wxwindow
, style
);
3833 gtk_widget_modify_style(m_widget
, style
);
3836 bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style
)
3838 wxWindowBase::SetBackgroundStyle(style
);
3840 if (style
== wxBG_STYLE_CUSTOM
)
3842 GdkWindow
*window
= (GdkWindow
*) NULL
;
3844 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3846 window
= GetConnectWidget()->window
;
3850 // Make sure GDK/X11 doesn't refresh the window
3852 gdk_window_set_back_pixmap( window
, None
, False
);
3854 Display
* display
= GDK_WINDOW_DISPLAY(window
);
3857 m_needsStyleChange
= false;
3860 // Do in OnIdle, because the window is not yet available
3861 m_needsStyleChange
= true;
3863 // Don't apply widget style, or we get a grey background
3867 // apply style change (forceStyle=true so that new style is applied
3868 // even if the bg colour changed from valid to wxNullColour):
3869 ApplyWidgetStyle(true);
3874 #if wxUSE_DRAG_AND_DROP
3876 void wxWindowGTK::SetDropTarget( wxDropTarget
*dropTarget
)
3878 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3880 GtkWidget
*dnd_widget
= GetConnectWidget();
3882 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
3884 if (m_dropTarget
) delete m_dropTarget
;
3885 m_dropTarget
= dropTarget
;
3887 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
3890 #endif // wxUSE_DRAG_AND_DROP
3892 GtkWidget
* wxWindowGTK::GetConnectWidget()
3894 GtkWidget
*connect_widget
= m_widget
;
3895 if (m_wxwindow
) connect_widget
= m_wxwindow
;
3897 return connect_widget
;
3900 bool wxWindowGTK::IsOwnGtkWindow( GdkWindow
*window
)
3903 return (window
== GTK_PIZZA(m_wxwindow
)->bin_window
);
3905 return (window
== m_widget
->window
);
3908 bool wxWindowGTK::SetFont( const wxFont
&font
)
3910 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3912 if (!wxWindowBase::SetFont(font
))
3915 // apply style change (forceStyle=true so that new style is applied
3916 // even if the font changed from valid to wxNullFont):
3917 ApplyWidgetStyle(true);
3922 void wxWindowGTK::DoCaptureMouse()
3924 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3926 GdkWindow
*window
= (GdkWindow
*) NULL
;
3928 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3930 window
= GetConnectWidget()->window
;
3932 wxCHECK_RET( window
, _T("CaptureMouse() failed") );
3934 const wxCursor
* cursor
= &m_cursor
;
3936 cursor
= wxSTANDARD_CURSOR
;
3938 gdk_pointer_grab( window
, FALSE
,
3940 (GDK_BUTTON_PRESS_MASK
|
3941 GDK_BUTTON_RELEASE_MASK
|
3942 GDK_POINTER_MOTION_HINT_MASK
|
3943 GDK_POINTER_MOTION_MASK
),
3945 cursor
->GetCursor(),
3946 (guint32
)GDK_CURRENT_TIME
);
3947 g_captureWindow
= this;
3948 g_captureWindowHasMouse
= true;
3951 void wxWindowGTK::DoReleaseMouse()
3953 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3955 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
3957 g_captureWindow
= (wxWindowGTK
*) NULL
;
3959 GdkWindow
*window
= (GdkWindow
*) NULL
;
3961 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3963 window
= GetConnectWidget()->window
;
3968 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
3972 wxWindow
*wxWindowBase::GetCapture()
3974 return (wxWindow
*)g_captureWindow
;
3977 bool wxWindowGTK::IsRetained() const
3982 void wxWindowGTK::SetScrollbar( int orient
, int pos
, int thumbVisible
,
3983 int range
, bool refresh
)
3985 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3987 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
3989 m_hasScrolling
= true;
3991 if (orient
== wxHORIZONTAL
)
3993 float fpos
= (float)pos
;
3994 float frange
= (float)range
;
3995 float fthumb
= (float)thumbVisible
;
3996 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
3997 if (fpos
< 0.0) fpos
= 0.0;
3999 if ((fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
4000 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
4002 SetScrollPos( orient
, pos
, refresh
);
4006 m_oldHorizontalPos
= fpos
;
4008 m_hAdjust
->lower
= 0.0;
4009 m_hAdjust
->upper
= frange
;
4010 m_hAdjust
->value
= fpos
;
4011 m_hAdjust
->step_increment
= 1.0;
4012 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4013 m_hAdjust
->page_size
= fthumb
;
4017 float fpos
= (float)pos
;
4018 float frange
= (float)range
;
4019 float fthumb
= (float)thumbVisible
;
4020 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
4021 if (fpos
< 0.0) fpos
= 0.0;
4023 if ((fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
4024 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
4026 SetScrollPos( orient
, pos
, refresh
);
4030 m_oldVerticalPos
= fpos
;
4032 m_vAdjust
->lower
= 0.0;
4033 m_vAdjust
->upper
= frange
;
4034 m_vAdjust
->value
= fpos
;
4035 m_vAdjust
->step_increment
= 1.0;
4036 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4037 m_vAdjust
->page_size
= fthumb
;
4040 if (orient
== wxHORIZONTAL
)
4041 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
4043 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
4046 void wxWindowGTK::GtkUpdateScrollbar(int orient
)
4048 GtkAdjustment
*adj
= orient
== wxHORIZONTAL
? m_hAdjust
: m_vAdjust
;
4049 GtkSignalFunc fn
= orient
== wxHORIZONTAL
4050 ? (GtkSignalFunc
)gtk_window_hscroll_callback
4051 : (GtkSignalFunc
)gtk_window_vscroll_callback
;
4053 gtk_signal_disconnect_by_func(GTK_OBJECT(adj
), fn
, (gpointer
)this);
4054 gtk_signal_emit_by_name(GTK_OBJECT(adj
), "value_changed");
4055 gtk_signal_connect(GTK_OBJECT(adj
), "value_changed", fn
, (gpointer
)this);
4058 void wxWindowGTK::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
4060 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4061 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4063 GtkAdjustment
*adj
= orient
== wxHORIZONTAL
? m_hAdjust
: m_vAdjust
;
4065 float fpos
= (float)pos
;
4066 if (fpos
> adj
->upper
- adj
->page_size
)
4067 fpos
= adj
->upper
- adj
->page_size
;
4070 *(orient
== wxHORIZONTAL
? &m_oldHorizontalPos
: &m_oldVerticalPos
) = fpos
;
4072 if (fabs(fpos
-adj
->value
) < 0.2)
4076 if ( m_wxwindow
->window
)
4081 int wxWindowGTK::GetScrollThumb( int orient
) const
4083 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4085 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4087 if (orient
== wxHORIZONTAL
)
4088 return (int)(m_hAdjust
->page_size
+0.5);
4090 return (int)(m_vAdjust
->page_size
+0.5);
4093 int wxWindowGTK::GetScrollPos( int orient
) const
4095 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4097 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4099 if (orient
== wxHORIZONTAL
)
4100 return (int)(m_hAdjust
->value
+0.5);
4102 return (int)(m_vAdjust
->value
+0.5);
4105 int wxWindowGTK::GetScrollRange( int orient
) const
4107 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4109 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4111 if (orient
== wxHORIZONTAL
)
4112 return (int)(m_hAdjust
->upper
+0.5);
4114 return (int)(m_vAdjust
->upper
+0.5);
4117 void wxWindowGTK::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4119 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4121 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4123 // No scrolling requested.
4124 if ((dx
== 0) && (dy
== 0)) return;
4126 if (!m_updateRegion
.IsEmpty())
4128 m_updateRegion
.Offset( dx
, dy
);
4132 GetClientSize( &cw
, &ch
);
4133 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
4136 if (!m_clearRegion
.IsEmpty())
4138 m_clearRegion
.Offset( dx
, dy
);
4142 GetClientSize( &cw
, &ch
);
4143 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
4146 m_clipPaintRegion
= true;
4148 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow
), -dx
, -dy
);
4150 m_clipPaintRegion
= false;
4153 void wxWindowGTK::SetWindowStyleFlag( long style
)
4155 // Updates the internal variable. NB: Now m_windowStyle bits carry the _new_ style values already
4156 wxWindowBase::SetWindowStyleFlag(style
);
4159 // Find the wxWindow at the current mouse position, also returning the mouse
4161 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4163 pt
= wxGetMousePosition();
4164 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4168 // Get the current mouse position.
4169 wxPoint
wxGetMousePosition()
4171 /* This crashes when used within wxHelpContext,
4172 so we have to use the X-specific implementation below.
4174 GdkModifierType *mask;
4175 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4177 return wxPoint(x, y);
4181 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4183 Display
*display
= windowAtPtr
? GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4184 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4185 Window rootReturn
, childReturn
;
4186 int rootX
, rootY
, winX
, winY
;
4187 unsigned int maskReturn
;
4189 XQueryPointer (display
,
4193 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4194 return wxPoint(rootX
, rootY
);
4198 // Needed for implementing e.g. combobox on wxGTK within a modal dialog.
4199 void wxAddGrab(wxWindow
* window
)
4201 gtk_grab_add( (GtkWidget
*) window
->GetHandle() );
4204 void wxRemoveGrab(wxWindow
* window
)
4206 gtk_grab_remove( (GtkWidget
*) window
->GetHandle() );
4209 // ----------------------------------------------------------------------------
4211 // ----------------------------------------------------------------------------
4213 class wxWinModule
: public wxModule
4220 DECLARE_DYNAMIC_CLASS(wxWinModule
)
4223 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
4225 bool wxWinModule::OnInit()
4227 // g_eraseGC = gdk_gc_new( GDK_ROOT_PARENT() );
4228 // gdk_gc_set_fill( g_eraseGC, GDK_SOLID );
4233 void wxWinModule::OnExit()
4236 gdk_gc_unref( g_eraseGC
);