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"
30 #include "wx/textctrl.h"
31 #include "wx/combobox.h"
32 #include "wx/layout.h"
33 #include "wx/statusbr.h"
35 #include "wx/module.h"
38 #if wxUSE_DRAG_AND_DROP
43 #include "wx/tooltip.h"
50 #include "wx/fontutil.h"
53 #include "wx/thread.h"
58 #include "wx/gtk1/private.h"
59 #include <gdk/gdkprivate.h>
60 #include <gdk/gdkkeysyms.h>
64 #include <gtk/gtkprivate.h>
66 #include "wx/gtk1/win_gtk.h"
68 //-----------------------------------------------------------------------------
69 // documentation on internals
70 //-----------------------------------------------------------------------------
73 I have been asked several times about writing some documentation about
74 the GTK port of wxWidgets, especially its internal structures. Obviously,
75 you cannot understand wxGTK without knowing a little about the GTK, but
76 some more information about what the wxWindow, which is the base class
77 for all other window classes, does seems required as well.
81 What does wxWindow do? It contains the common interface for the following
82 jobs of its descendants:
84 1) Define the rudimentary behaviour common to all window classes, such as
85 resizing, intercepting user input (so as to make it possible to use these
86 events for special purposes in a derived class), window names etc.
88 2) Provide the possibility to contain and manage children, if the derived
89 class is allowed to contain children, which holds true for those window
90 classes which do not display a native GTK widget. To name them, these
91 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
92 work classes are a special case and are handled a bit differently from
93 the rest. The same holds true for the wxNotebook class.
95 3) Provide the possibility to draw into a client area of a window. This,
96 too, only holds true for classes that do not display a native GTK widget
99 4) Provide the entire mechanism for scrolling widgets. This actual inter-
100 face for this is usually in wxScrolledWindow, but the GTK implementation
103 5) A multitude of helper or extra methods for special purposes, such as
104 Drag'n'Drop, managing validators etc.
106 6) Display a border (sunken, raised, simple or none).
108 Normally one might expect, that one wxWidgets window would always correspond
109 to one GTK widget. Under GTK, there is no such allround widget that has all
110 the functionality. Moreover, the GTK defines a client area as a different
111 widget from the actual widget you are handling. Last but not least some
112 special classes (e.g. wxFrame) handle different categories of widgets and
113 still have the possibility to draw something in the client area.
114 It was therefore required to write a special purpose GTK widget, that would
115 represent a client area in the sense of wxWidgets capable to do the jobs
116 2), 3) and 4). I have written this class and it resides in win_gtk.c of
119 All windows must have a widget, with which they interact with other under-
120 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
121 the wxWindow class has a member variable called m_widget which holds a
122 pointer to this widget. When the window class represents a GTK native widget,
123 this is (in most cases) the only GTK widget the class manages. E.g. the
124 wxStaticText class handles only a GtkLabel widget a pointer to which you
125 can find in m_widget (defined in wxWindow)
127 When the class has a client area for drawing into and for containing children
128 it has to handle the client area widget (of the type GtkPizza, defined in
129 win_gtk.c), but there could be any number of widgets, handled by a class
130 The common rule for all windows is only, that the widget that interacts with
131 the rest of GTK must be referenced in m_widget and all other widgets must be
132 children of this widget on the GTK level. The top-most widget, which also
133 represents the client area, must be in the m_wxwindow field and must be of
136 As I said, the window classes that display a GTK native widget only have
137 one widget, so in the case of e.g. the wxButton class m_widget holds a
138 pointer to a GtkButton widget. But windows with client areas (for drawing
139 and children) have a m_widget field that is a pointer to a GtkScrolled-
140 Window and a m_wxwindow field that is pointer to a GtkPizza and this
141 one is (in the GTK sense) a child of the GtkScrolledWindow.
143 If the m_wxwindow field is set, then all input to this widget is inter-
144 cepted and sent to the wxWidgets class. If not, all input to the widget
145 that gets pointed to by m_widget gets intercepted and sent to the class.
149 The design of scrolling in wxWidgets is markedly different from that offered
150 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
151 clicking on a scrollbar belonging to scrolled window will inevitably move
152 the window. In wxWidgets, the scrollbar will only emit an event, send this
153 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
154 which actually moves the window and its subchildren. Note that GtkPizza
155 memorizes how much it has been scrolled but that wxWidgets forgets this
156 so that the two coordinates systems have to be kept in synch. This is done
157 in various places using the pizza->xoffset and pizza->yoffset values.
161 Singularily the most broken code in GTK is the code that is supposed to
162 inform subwindows (child windows) about new positions. Very often, duplicate
163 events are sent without changes in size or position, equally often no
164 events are sent at all (All this is due to a bug in the GtkContainer code
165 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
166 GTK's own system and it simply waits for size events for toplevel windows
167 and then iterates down the respective size events to all window. This has
168 the disadvantage that windows might get size events before the GTK widget
169 actually has the reported size. This doesn't normally pose any problem, but
170 the OpenGL drawing routines rely on correct behaviour. Therefore, I have
171 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
172 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
173 window that is used for OpenGL output really has that size (as reported by
178 If someone at some point of time feels the immense desire to have a look at,
179 change or attempt to optimise the Refresh() logic, this person will need an
180 intimate understanding of what "draw" and "expose" events are and what
181 they are used for, in particular when used in connection with GTK's
182 own windowless widgets. Beware.
186 Cursors, too, have been a constant source of pleasure. The main difficulty
187 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
188 for the parent. To prevent this from doing too much harm, I use idle time
189 to set the cursor over and over again, starting from the toplevel windows
190 and ending with the youngest generation (speaking of parent and child windows).
191 Also don't forget that cursors (like much else) are connected to GdkWindows,
192 not GtkWidgets and that the "window" field of a GtkWidget might very well
193 point to the GdkWindow of the parent widget (-> "window-less widget") and
194 that the two obviously have very different meanings.
198 //-----------------------------------------------------------------------------
200 //-----------------------------------------------------------------------------
202 extern bool g_blockEventsOnDrag
;
203 extern bool g_blockEventsOnScroll
;
204 extern wxCursor g_globalCursor
;
206 static GdkGC
*g_eraseGC
= NULL
;
208 // mouse capture state: the window which has it and if the mouse is currently
210 static wxWindowGTK
*g_captureWindow
= (wxWindowGTK
*) NULL
;
211 static bool g_captureWindowHasMouse
= false;
213 wxWindowGTK
*g_focusWindow
= (wxWindowGTK
*) NULL
;
215 // the last window which had the focus - this is normally never NULL (except
216 // if we never had focus at all) as even when g_focusWindow is NULL it still
217 // keeps its previous value
218 wxWindowGTK
*g_focusWindowLast
= (wxWindowGTK
*) NULL
;
220 // If a window get the focus set but has not been realized
221 // yet, defer setting the focus to idle time.
222 wxWindowGTK
*g_delayedFocus
= (wxWindowGTK
*) NULL
;
224 // hack: we need something to pass to gtk_menu_popup, so we store the time of
225 // the last click here (extern: used from gtk/menu.cpp)
226 guint32 wxGtkTimeLastClick
= 0;
228 extern bool g_mainThreadLocked
;
230 //-----------------------------------------------------------------------------
232 //-----------------------------------------------------------------------------
237 # define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
239 # define DEBUG_MAIN_THREAD
242 #define DEBUG_MAIN_THREAD
245 // the trace mask used for the focus debugging messages
246 #define TRACE_FOCUS _T("focus")
248 //-----------------------------------------------------------------------------
249 // missing gdk functions
250 //-----------------------------------------------------------------------------
253 gdk_window_warp_pointer (GdkWindow
*window
,
257 GdkWindowPrivate
*priv
;
260 window
= GDK_ROOT_PARENT();
262 priv
= (GdkWindowPrivate
*) window
;
264 if (!priv
->destroyed
)
266 XWarpPointer (priv
->xdisplay
,
267 None
, /* not source window -> move from anywhere */
268 priv
->xwindow
, /* dest window */
269 0, 0, 0, 0, /* not source window -> move from anywhere */
274 //-----------------------------------------------------------------------------
276 //-----------------------------------------------------------------------------
278 extern void wxapp_install_idle_handler();
279 extern bool g_isIdle
;
281 //-----------------------------------------------------------------------------
282 // local code (see below)
283 //-----------------------------------------------------------------------------
285 // returns the child of win which currently has focus or NULL if not found
287 // Note: can't be static, needed by textctrl.cpp.
288 wxWindow
*wxFindFocusedChild(wxWindowGTK
*win
)
290 wxWindow
*winFocus
= wxWindowGTK::FindFocus();
292 return (wxWindow
*)NULL
;
294 if ( winFocus
== win
)
295 return (wxWindow
*)win
;
297 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
299 node
= node
->GetNext() )
301 wxWindow
*child
= wxFindFocusedChild(node
->GetData());
306 return (wxWindow
*)NULL
;
309 static void draw_frame( GtkWidget
*widget
, wxWindowGTK
*win
)
311 // wxUniversal widgets draw the borders and scrollbars themselves
312 #ifndef __WXUNIVERSAL__
319 if (win
->m_hasScrolling
)
321 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(widget
);
323 GtkRequisition vscroll_req
;
324 vscroll_req
.width
= 2;
325 vscroll_req
.height
= 2;
326 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
327 (scroll_window
->vscrollbar
, &vscroll_req
);
329 GtkRequisition hscroll_req
;
330 hscroll_req
.width
= 2;
331 hscroll_req
.height
= 2;
332 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
333 (scroll_window
->hscrollbar
, &hscroll_req
);
335 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(widget
) );
337 if (scroll_window
->vscrollbar_visible
)
339 dw
+= vscroll_req
.width
;
340 dw
+= scroll_class
->scrollbar_spacing
;
343 if (scroll_window
->hscrollbar_visible
)
345 dh
+= hscroll_req
.height
;
346 dh
+= scroll_class
->scrollbar_spacing
;
352 if (GTK_WIDGET_NO_WINDOW (widget
))
354 dx
+= widget
->allocation
.x
;
355 dy
+= widget
->allocation
.y
;
358 if (win
->HasFlag(wxRAISED_BORDER
))
360 gtk_draw_shadow( widget
->style
,
365 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
369 if (win
->HasFlag(wxSUNKEN_BORDER
))
371 gtk_draw_shadow( widget
->style
,
376 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
380 if (win
->HasFlag(wxSIMPLE_BORDER
))
383 gc
= gdk_gc_new( widget
->window
);
384 gdk_gc_set_foreground( gc
, &widget
->style
->black
);
385 gdk_draw_rectangle( widget
->window
, gc
, FALSE
,
387 widget
->allocation
.width
-dw
-1, widget
->allocation
.height
-dh
-1 );
391 #endif // __WXUNIVERSAL__
394 //-----------------------------------------------------------------------------
395 // "expose_event" of m_widget
396 //-----------------------------------------------------------------------------
399 static gint
gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxWindowGTK
*win
)
401 if (gdk_event
->count
> 0) return FALSE
;
403 draw_frame( widget
, win
);
409 //-----------------------------------------------------------------------------
410 // "draw" of m_widget
411 //-----------------------------------------------------------------------------
414 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxWindowGTK
*win
)
416 draw_frame( widget
, win
);
420 //-----------------------------------------------------------------------------
421 // "size_request" of m_widget
422 //-----------------------------------------------------------------------------
424 // make it extern because wxStaticText needs to disconnect this one
426 void wxgtk_window_size_request_callback(GtkWidget
*widget
,
427 GtkRequisition
*requisition
,
431 win
->GetSize( &w
, &h
);
437 requisition
->height
= h
;
438 requisition
->width
= w
;
444 void wxgtk_combo_size_request_callback(GtkWidget
*widget
,
445 GtkRequisition
*requisition
,
448 // This callback is actually hooked into the text entry
449 // of the combo box, not the GtkHBox.
452 win
->GetSize( &w
, &h
);
458 GtkCombo
*gcombo
= GTK_COMBO(win
->m_widget
);
460 GtkRequisition entry_req
;
462 entry_req
.height
= 2;
463 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo
->button
) )->size_request
)
464 (gcombo
->button
, &entry_req
);
466 requisition
->width
= w
- entry_req
.width
;
467 requisition
->height
= entry_req
.height
;
471 //-----------------------------------------------------------------------------
472 // "expose_event" of m_wxwindow
473 //-----------------------------------------------------------------------------
476 static int gtk_window_expose_callback( GtkWidget
*widget
,
477 GdkEventExpose
*gdk_event
,
483 wxapp_install_idle_handler();
485 // This gets called immediately after an expose event
486 // under GTK 1.2 so we collect the calls and wait for
487 // the idle handler to pick things up.
489 win
->GetUpdateRegion().Union( gdk_event
->area
.x
,
491 gdk_event
->area
.width
,
492 gdk_event
->area
.height
);
493 win
->m_clearRegion
.Union( gdk_event
->area
.x
,
495 gdk_event
->area
.width
,
496 gdk_event
->area
.height
);
498 // Actual redrawing takes place in idle time.
505 //-----------------------------------------------------------------------------
506 // "event" of m_wxwindow
507 //-----------------------------------------------------------------------------
509 // GTK thinks it is clever and filters out a certain amount of "unneeded"
510 // expose events. We need them, of course, so we override the main event
511 // procedure in GtkWidget by giving our own handler for all system events.
512 // There, we look for expose events ourselves whereas all other events are
517 gint
gtk_window_event_event_callback( GtkWidget
*widget
,
518 GdkEventExpose
*event
,
521 if (event
->type
== GDK_EXPOSE
)
523 gint ret
= gtk_window_expose_callback( widget
, event
, win
);
531 //-----------------------------------------------------------------------------
532 // "draw" of m_wxwindow
533 //-----------------------------------------------------------------------------
535 // This callback is a complete replacement of the gtk_pizza_draw() function,
536 // which is disabled.
539 static void gtk_window_draw_callback( GtkWidget
*widget
,
546 wxapp_install_idle_handler();
548 // if there are any children we must refresh everything
551 if ( !win
->HasFlag(wxFULL_REPAINT_ON_RESIZE
) &&
552 win
->GetChildren().IsEmpty() )
560 wxPrintf( wxT("OnDraw from ") );
561 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
562 wxPrintf( win
->GetClassInfo()->GetClassName() );
563 wxPrintf( wxT(" %d %d %d %d\n"), (int)rect
->x
,
570 #ifndef __WXUNIVERSAL__
571 GtkPizza
*pizza
= GTK_PIZZA (widget
);
573 if (win
->GetThemeEnabled() && win
->GetBackgroundStyle() == wxBG_STYLE_SYSTEM
)
575 wxWindow
*parent
= win
->GetParent();
576 while (parent
&& !parent
->IsTopLevel())
577 parent
= parent
->GetParent();
581 gtk_paint_flat_box (parent
->m_widget
->style
,
592 win
->m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
593 win
->GetUpdateRegion().Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
595 // Update immediately, not in idle time.
598 #ifndef __WXUNIVERSAL__
599 // Redraw child widgets
600 GList
*children
= pizza
->children
;
603 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
604 children
= children
->next
;
606 GdkRectangle child_area
;
607 if (gtk_widget_intersect (child
->widget
, rect
, &child_area
))
609 gtk_widget_draw (child
->widget
, &child_area
/* (GdkRectangle*) NULL*/ );
616 //-----------------------------------------------------------------------------
617 // "key_press_event" from any window
618 //-----------------------------------------------------------------------------
620 // set WXTRACE to this to see the key event codes on the console
621 #define TRACE_KEYS _T("keyevent")
623 // translates an X key symbol to WXK_XXX value
625 // if isChar is true it means that the value returned will be used for EVT_CHAR
626 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
627 // for example, while if it is false it means that the value is going to be
628 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
630 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
636 // Shift, Control and Alt don't generate the CHAR events at all
639 key_code
= isChar
? 0 : WXK_SHIFT
;
643 key_code
= isChar
? 0 : WXK_CONTROL
;
651 key_code
= isChar
? 0 : WXK_ALT
;
654 // neither do the toggle modifies
655 case GDK_Scroll_Lock
:
656 key_code
= isChar
? 0 : WXK_SCROLL
;
660 key_code
= isChar
? 0 : WXK_CAPITAL
;
664 key_code
= isChar
? 0 : WXK_NUMLOCK
;
668 // various other special keys
681 case GDK_ISO_Left_Tab
:
688 key_code
= WXK_RETURN
;
692 key_code
= WXK_CLEAR
;
696 key_code
= WXK_PAUSE
;
700 key_code
= WXK_SELECT
;
704 key_code
= WXK_PRINT
;
708 key_code
= WXK_EXECUTE
;
712 key_code
= WXK_ESCAPE
;
715 // cursor and other extended keyboard keys
717 key_code
= WXK_DELETE
;
733 key_code
= WXK_RIGHT
;
740 case GDK_Prior
: // == GDK_Page_Up
741 key_code
= WXK_PAGEUP
;
744 case GDK_Next
: // == GDK_Page_Down
745 key_code
= WXK_PAGEDOWN
;
757 key_code
= WXK_INSERT
;
772 key_code
= (isChar
? '0' : WXK_NUMPAD0
) + keysym
- GDK_KP_0
;
776 key_code
= isChar
? ' ' : WXK_NUMPAD_SPACE
;
780 key_code
= isChar
? WXK_TAB
: WXK_NUMPAD_TAB
;
784 key_code
= isChar
? WXK_RETURN
: WXK_NUMPAD_ENTER
;
788 key_code
= isChar
? WXK_F1
: WXK_NUMPAD_F1
;
792 key_code
= isChar
? WXK_F2
: WXK_NUMPAD_F2
;
796 key_code
= isChar
? WXK_F3
: WXK_NUMPAD_F3
;
800 key_code
= isChar
? WXK_F4
: WXK_NUMPAD_F4
;
804 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_HOME
;
808 key_code
= isChar
? WXK_LEFT
: WXK_NUMPAD_LEFT
;
812 key_code
= isChar
? WXK_UP
: WXK_NUMPAD_UP
;
816 key_code
= isChar
? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
820 key_code
= isChar
? WXK_DOWN
: WXK_NUMPAD_DOWN
;
823 case GDK_KP_Prior
: // == GDK_KP_Page_Up
824 key_code
= isChar
? WXK_PAGEUP
: WXK_NUMPAD_PAGEUP
;
827 case GDK_KP_Next
: // == GDK_KP_Page_Down
828 key_code
= isChar
? WXK_PAGEDOWN
: WXK_NUMPAD_PAGEDOWN
;
832 key_code
= isChar
? WXK_END
: WXK_NUMPAD_END
;
836 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_BEGIN
;
840 key_code
= isChar
? WXK_INSERT
: WXK_NUMPAD_INSERT
;
844 key_code
= isChar
? WXK_DELETE
: WXK_NUMPAD_DELETE
;
848 key_code
= isChar
? '=' : WXK_NUMPAD_EQUAL
;
851 case GDK_KP_Multiply
:
852 key_code
= isChar
? '*' : WXK_NUMPAD_MULTIPLY
;
856 key_code
= isChar
? '+' : WXK_NUMPAD_ADD
;
859 case GDK_KP_Separator
:
860 // FIXME: what is this?
861 key_code
= isChar
? '.' : WXK_NUMPAD_SEPARATOR
;
864 case GDK_KP_Subtract
:
865 key_code
= isChar
? '-' : WXK_NUMPAD_SUBTRACT
;
869 key_code
= isChar
? '.' : WXK_NUMPAD_DECIMAL
;
873 key_code
= isChar
? '/' : WXK_NUMPAD_DIVIDE
;
890 key_code
= WXK_F1
+ keysym
- GDK_F1
;
900 static inline bool wxIsAsciiKeysym(KeySym ks
)
905 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
907 GdkEventKey
*gdk_event
)
911 GdkModifierType state
;
912 if (gdk_event
->window
)
913 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
915 event
.SetTimestamp( gdk_event
->time
);
916 event
.SetId(win
->GetId());
917 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
918 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
919 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
920 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
) != 0;
921 event
.m_scanCode
= gdk_event
->keyval
;
922 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
923 event
.m_rawFlags
= 0;
925 event
.m_uniChar
= gdk_keyval_to_unicode(gdk_event
->keyval
);
927 wxGetMousePosition( &x
, &y
);
928 win
->ScreenToClient( &x
, &y
);
931 event
.SetEventObject( win
);
936 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
938 GdkEventKey
*gdk_event
)
940 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
941 // but only event->keyval which is quite useless to us, so remember
942 // the last character from GDK_KEY_PRESS and reuse it as last resort
944 // NB: should be MT-safe as we're always called from the main thread only
949 } s_lastKeyPress
= { 0, 0 };
951 KeySym keysym
= gdk_event
->keyval
;
953 wxLogTrace(TRACE_KEYS
, _T("Key %s event: keysym = %ld"),
954 event
.GetEventType() == wxEVT_KEY_UP
? _T("release")
958 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
962 // do we have the translation or is it a plain ASCII character?
963 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
965 // we should use keysym if it is ASCII as X does some translations
966 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
967 // which we don't want here (but which we do use for OnChar())
968 if ( !wxIsAsciiKeysym(keysym
) )
970 keysym
= (KeySym
)gdk_event
->string
[0];
973 // we want to always get the same key code when the same key is
974 // pressed regardless of the state of the modifiers, i.e. on a
975 // standard US keyboard pressing '5' or '%' ('5' key with
976 // Shift) should result in the same key code in OnKeyDown():
977 // '5' (although OnChar() will get either '5' or '%').
979 // to do it we first translate keysym to keycode (== scan code)
980 // and then back but always using the lower register
981 Display
*dpy
= (Display
*)wxGetDisplay();
982 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
984 wxLogTrace(TRACE_KEYS
, _T("\t-> keycode %d"), keycode
);
986 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
988 // use the normalized, i.e. lower register, keysym if we've
990 key_code
= keysymNormalized
? keysymNormalized
: keysym
;
992 // as explained above, we want to have lower register key codes
993 // normally but for the letter keys we want to have the upper ones
995 // NB: don't use XConvertCase() here, we want to do it for letters
997 key_code
= toupper(key_code
);
999 else // non ASCII key, what to do?
1001 // by default, ignore it
1004 // but if we have cached information from the last KEY_PRESS
1005 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
1008 if ( keysym
== s_lastKeyPress
.keysym
)
1010 key_code
= s_lastKeyPress
.keycode
;
1015 if ( gdk_event
->type
== GDK_KEY_PRESS
)
1017 // remember it to be reused for KEY_UP event later
1018 s_lastKeyPress
.keysym
= keysym
;
1019 s_lastKeyPress
.keycode
= key_code
;
1023 wxLogTrace(TRACE_KEYS
, _T("\t-> wxKeyCode %ld"), key_code
);
1025 // sending unknown key events doesn't really make sense
1029 // now fill all the other fields
1030 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
1032 event
.m_keyCode
= key_code
;
1039 static gint
gtk_window_key_press_callback( GtkWidget
*widget
,
1040 GdkEventKey
*gdk_event
,
1046 wxapp_install_idle_handler();
1050 if (g_blockEventsOnDrag
)
1054 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1056 bool return_after_IM
= false;
1058 if( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) == false )
1060 // Emit KEY_DOWN event
1061 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1065 // Return after IM processing as we cannot do
1066 // anything with it anyhow.
1067 return_after_IM
= true;
1070 // This is for GTK+ 1.2 only. The char event generatation for GTK+ 2.0 is done
1071 // in the "commit" handler.
1073 // 2005.02.02 modified by Hong Jen Yee (hzysoft@sina.com.tw).
1074 // In GTK+ 1.2, strings sent by IMs are also regarded as key_press events whose
1075 // keyCodes cannot be recognized by wxWidgets. These MBCS strings, however, are
1076 // composed of more than one character, which means gdk_event->length will always
1077 // greater than one. When gtk_event->length == 1, this may be an ASCII character
1078 // and can be translated by wx. However, when MBCS characters are sent by IM,
1079 // gdk_event->length will >= 2. So neither should we pass it to accelerator table,
1080 // nor should we pass it to controls. The following explanation was excerpted
1081 // from GDK documentation.
1082 // gint length : the length of string.
1083 // gchar *string : a null-terminated multi-byte string containing the composed
1084 // characters resulting from the key press. When text is being input, in a GtkEntry
1085 // for example, it is these characters which should be added to the input buffer.
1086 // When using Input Methods to support internationalized text input, the composed
1087 // characters appear here after the pre-editing has been completed.
1089 if ( (!ret
) && (gdk_event
->length
> 1) ) // If this event contains a pre-edited string from IM.
1091 // We should translate this key event into wxEVT_CHAR not wxEVT_KEY_DOWN.
1092 #if wxUSE_UNICODE // GTK+ 1.2 is not UTF-8 based.
1093 const wxWCharBuffer string
= wxConvLocal
.cMB2WC( gdk_event
->string
);
1097 const char* string
= gdk_event
->string
;
1100 // Implement OnCharHook by checking ancestor top level windows
1101 wxWindow
*parent
= win
;
1102 while (parent
&& !parent
->IsTopLevel())
1103 parent
= parent
->GetParent();
1105 for( const wxChar
* pstr
= string
; *pstr
; pstr
++ )
1108 event
.m_uniChar
= *pstr
;
1109 // Backward compatible for ISO-8859-1
1110 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1112 event
.m_keyCode
= *pstr
;
1116 event
.SetEventType( wxEVT_CHAR_HOOK
);
1117 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1121 event
.SetEventType(wxEVT_CHAR
);
1122 win
->GetEventHandler()->ProcessEvent( event
);
1128 if (return_after_IM
)
1134 wxWindowGTK
*ancestor
= win
;
1137 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1140 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1141 ret
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1144 if (ancestor
->IsTopLevel())
1146 ancestor
= ancestor
->GetParent();
1149 #endif // wxUSE_ACCEL
1151 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
1152 // will only be sent if it is not in an accelerator table.
1156 KeySym keysym
= gdk_event
->keyval
;
1157 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
1158 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
1161 if ( wxIsAsciiKeysym(keysym
) )
1164 key_code
= (unsigned char)keysym
;
1166 // gdk_event->string is actually deprecated
1167 else if ( gdk_event
->length
== 1 )
1169 key_code
= (unsigned char)gdk_event
->string
[0];
1175 wxLogTrace(TRACE_KEYS
, _T("Char event: %ld"), key_code
);
1177 event
.m_keyCode
= key_code
;
1179 // Implement OnCharHook by checking ancestor top level windows
1180 wxWindow
*parent
= win
;
1181 while (parent
&& !parent
->IsTopLevel())
1182 parent
= parent
->GetParent();
1185 event
.SetEventType( wxEVT_CHAR_HOOK
);
1186 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1191 event
.SetEventType(wxEVT_CHAR
);
1192 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1201 // win is a control: tab can be propagated up
1203 ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
)) &&
1204 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here - the control may
1205 // have this style, yet choose not to process this particular TAB in which
1206 // case TAB must still work as a navigational character
1207 // JS: enabling again to make consistent with other platforms
1208 // (with wxTE_PROCESS_TAB you have to call Navigate to get default
1209 // navigation behaviour)
1211 (! (win
->HasFlag(wxTE_PROCESS_TAB
) && win
->IsKindOf(CLASSINFO(wxTextCtrl
)) )) &&
1213 win
->GetParent() && (win
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1215 wxNavigationKeyEvent new_event
;
1216 new_event
.SetEventObject( win
->GetParent() );
1217 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
1218 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
1219 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
1220 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
1221 new_event
.SetCurrentFocus( win
);
1222 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent( new_event
);
1225 // generate wxID_CANCEL if <esc> has been pressed (typically in dialogs)
1227 (gdk_event
->keyval
== GDK_Escape
) )
1229 // however only do it if we have a Cancel button in the dialog,
1230 // otherwise the user code may get confused by the events from a
1231 // non-existing button and, worse, a wxButton might get button event
1232 // from another button which is not really expected
1233 wxWindow
*winForCancel
= win
,
1235 while ( winForCancel
)
1237 btnCancel
= winForCancel
->FindWindow(wxID_CANCEL
);
1240 // found a cancel button
1244 if ( winForCancel
->IsTopLevel() )
1246 // no need to look further
1250 // maybe our parent has a cancel button?
1251 winForCancel
= winForCancel
->GetParent();
1256 wxCommandEvent
eventClick(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
1257 eventClick
.SetEventObject(btnCancel
);
1258 ret
= btnCancel
->GetEventHandler()->ProcessEvent(eventClick
);
1264 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
1272 //-----------------------------------------------------------------------------
1273 // "key_release_event" from any window
1274 //-----------------------------------------------------------------------------
1277 static gint
gtk_window_key_release_callback( GtkWidget
*widget
,
1278 GdkEventKey
*gdk_event
,
1284 wxapp_install_idle_handler();
1289 if (g_blockEventsOnDrag
)
1292 wxKeyEvent
event( wxEVT_KEY_UP
);
1293 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1295 // unknown key pressed, ignore (the event would be useless anyhow)
1299 if ( !win
->GetEventHandler()->ProcessEvent( event
) )
1302 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_release_event" );
1307 // ============================================================================
1309 // ============================================================================
1311 // ----------------------------------------------------------------------------
1312 // mouse event processing helpers
1313 // ----------------------------------------------------------------------------
1315 // init wxMouseEvent with the info from GdkEventXXX struct
1316 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1317 wxMouseEvent
& event
,
1320 event
.SetTimestamp( gdk_event
->time
);
1321 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1322 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1323 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1324 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1325 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1326 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1327 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1328 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
1330 event
.m_linesPerAction
= 3;
1331 event
.m_wheelDelta
= 120;
1332 if (((GdkEventButton
*)gdk_event
)->button
== 4)
1333 event
.m_wheelRotation
= 120;
1334 else if (((GdkEventButton
*)gdk_event
)->button
== 5)
1335 event
.m_wheelRotation
= -120;
1338 wxPoint pt
= win
->GetClientAreaOrigin();
1339 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1340 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1342 event
.SetEventObject( win
);
1343 event
.SetId( win
->GetId() );
1344 event
.SetTimestamp( gdk_event
->time
);
1347 static void AdjustEventButtonState(wxMouseEvent
& event
)
1349 // GDK reports the old state of the button for a button press event, but
1350 // for compatibility with MSW and common sense we want m_leftDown be true
1351 // for a LEFT_DOWN event, not FALSE, so we will invert
1352 // left/right/middleDown for the corresponding click events
1354 if ((event
.GetEventType() == wxEVT_LEFT_DOWN
) ||
1355 (event
.GetEventType() == wxEVT_LEFT_DCLICK
) ||
1356 (event
.GetEventType() == wxEVT_LEFT_UP
))
1358 event
.m_leftDown
= !event
.m_leftDown
;
1362 if ((event
.GetEventType() == wxEVT_MIDDLE_DOWN
) ||
1363 (event
.GetEventType() == wxEVT_MIDDLE_DCLICK
) ||
1364 (event
.GetEventType() == wxEVT_MIDDLE_UP
))
1366 event
.m_middleDown
= !event
.m_middleDown
;
1370 if ((event
.GetEventType() == wxEVT_RIGHT_DOWN
) ||
1371 (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) ||
1372 (event
.GetEventType() == wxEVT_RIGHT_UP
))
1374 event
.m_rightDown
= !event
.m_rightDown
;
1379 // find the window to send the mouse event too
1381 wxWindowGTK
*FindWindowForMouseEvent(wxWindowGTK
*win
, wxCoord
& x
, wxCoord
& y
)
1386 if (win
->m_wxwindow
)
1388 GtkPizza
*pizza
= GTK_PIZZA(win
->m_wxwindow
);
1389 xx
+= pizza
->xoffset
;
1390 yy
+= pizza
->yoffset
;
1393 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
1396 wxWindowGTK
*child
= node
->GetData();
1398 node
= node
->GetNext();
1399 if (!child
->IsShown())
1402 if (child
->IsTransparentForMouse())
1404 // wxStaticBox is transparent in the box itself
1405 int xx1
= child
->m_x
;
1406 int yy1
= child
->m_y
;
1407 int xx2
= child
->m_x
+ child
->m_width
;
1408 int yy2
= child
->m_y
+ child
->m_height
;
1411 if (((xx
>= xx1
) && (xx
<= xx1
+10) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1413 ((xx
>= xx2
-10) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1415 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy1
+10)) ||
1417 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy2
-1) && (yy
<= yy2
)))
1428 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1429 (child
->m_x
<= xx
) &&
1430 (child
->m_y
<= yy
) &&
1431 (child
->m_x
+child
->m_width
>= xx
) &&
1432 (child
->m_y
+child
->m_height
>= yy
))
1445 //-----------------------------------------------------------------------------
1446 // "button_press_event"
1447 //-----------------------------------------------------------------------------
1450 static gint
gtk_window_button_press_callback( GtkWidget
*widget
,
1451 GdkEventButton
*gdk_event
,
1457 wxapp_install_idle_handler();
1460 wxPrintf( wxT("1) OnButtonPress from ") );
1461 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1462 wxPrintf( win->GetClassInfo()->GetClassName() );
1463 wxPrintf( wxT(".\n") );
1465 if (!win
->m_hasVMT
) return FALSE
;
1466 if (g_blockEventsOnDrag
) return TRUE
;
1467 if (g_blockEventsOnScroll
) return TRUE
;
1469 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1471 if (win
->m_wxwindow
&& (g_focusWindow
!= win
) && win
->AcceptsFocus())
1473 gtk_widget_grab_focus( win
->m_wxwindow
);
1475 wxPrintf( wxT("GrabFocus from ") );
1476 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1477 wxPrintf( win->GetClassInfo()->GetClassName() );
1478 wxPrintf( wxT(".\n") );
1482 // GDK sends surplus button down events
1483 // before a double click event. We
1484 // need to filter these out.
1485 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1487 GdkEvent
*peek_event
= gdk_event_peek();
1490 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1491 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1493 gdk_event_free( peek_event
);
1498 gdk_event_free( peek_event
);
1503 wxEventType event_type
= wxEVT_NULL
;
1505 if (gdk_event
->button
== 1)
1507 // note that GDK generates triple click events which are not supported
1508 // by wxWidgets but still have to be passed to the app as otherwise
1509 // clicks would simply go missing
1510 switch (gdk_event
->type
)
1512 // we shouldn't get triple clicks at all for GTK2 because we
1513 // suppress them artificially using the code above but we still
1514 // should map them to something for GTK1 and not just ignore them
1515 // as this would lose clicks
1516 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1517 case GDK_BUTTON_PRESS
:
1518 event_type
= wxEVT_LEFT_DOWN
;
1521 case GDK_2BUTTON_PRESS
:
1522 event_type
= wxEVT_LEFT_DCLICK
;
1526 // just to silence gcc warnings
1530 else if (gdk_event
->button
== 2)
1532 switch (gdk_event
->type
)
1534 case GDK_3BUTTON_PRESS
:
1535 case GDK_BUTTON_PRESS
:
1536 event_type
= wxEVT_MIDDLE_DOWN
;
1539 case GDK_2BUTTON_PRESS
:
1540 event_type
= wxEVT_MIDDLE_DCLICK
;
1547 else if (gdk_event
->button
== 3)
1549 switch (gdk_event
->type
)
1551 case GDK_3BUTTON_PRESS
:
1552 case GDK_BUTTON_PRESS
:
1553 event_type
= wxEVT_RIGHT_DOWN
;
1556 case GDK_2BUTTON_PRESS
:
1557 event_type
= wxEVT_RIGHT_DCLICK
;
1564 else if (gdk_event
->button
== 4 || gdk_event
->button
== 5)
1566 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1568 event_type
= wxEVT_MOUSEWHEEL
;
1572 if ( event_type
== wxEVT_NULL
)
1574 // unknown mouse button or click type
1578 wxMouseEvent
event( event_type
);
1579 InitMouseEvent( win
, event
, gdk_event
);
1581 AdjustEventButtonState(event
);
1583 // wxListBox actually gets mouse events from the item, so we need to give it
1584 // a chance to correct this
1585 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1587 // find the correct window to send the event to: it may be a different one
1588 // from the one which got it at GTK+ level because some controls don't have
1589 // their own X window and thus cannot get any events.
1590 if ( !g_captureWindow
)
1591 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1593 wxGtkTimeLastClick
= gdk_event
->time
;
1595 if (event_type
== wxEVT_LEFT_DCLICK
)
1597 // GTK 1.2 crashes when intercepting double
1598 // click events from both wxSpinButton and
1600 if (GTK_IS_SPIN_BUTTON(win
->m_widget
))
1602 // Just disable this event for now.
1607 if (win
->GetEventHandler()->ProcessEvent( event
))
1609 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_press_event" );
1613 if (event_type
== wxEVT_RIGHT_DOWN
)
1615 // generate a "context menu" event: this is similar to right mouse
1616 // click under many GUIs except that it is generated differently
1617 // (right up under MSW, ctrl-click under Mac, right down here) and
1619 // (a) it's a command event and so is propagated to the parent
1620 // (b) under some ports it can be generated from kbd too
1621 // (c) it uses screen coords (because of (a))
1622 wxContextMenuEvent
evtCtx(
1625 win
->ClientToScreen(event
.GetPosition()));
1626 evtCtx
.SetEventObject(win
);
1627 return win
->GetEventHandler()->ProcessEvent(evtCtx
);
1634 //-----------------------------------------------------------------------------
1635 // "button_release_event"
1636 //-----------------------------------------------------------------------------
1639 static gint
gtk_window_button_release_callback( GtkWidget
*widget
,
1640 GdkEventButton
*gdk_event
,
1646 wxapp_install_idle_handler();
1648 if (!win
->m_hasVMT
) return FALSE
;
1649 if (g_blockEventsOnDrag
) return FALSE
;
1650 if (g_blockEventsOnScroll
) return FALSE
;
1652 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1654 wxEventType event_type
= wxEVT_NULL
;
1656 switch (gdk_event
->button
)
1659 event_type
= wxEVT_LEFT_UP
;
1663 event_type
= wxEVT_MIDDLE_UP
;
1667 event_type
= wxEVT_RIGHT_UP
;
1671 // unknwon button, don't process
1675 wxMouseEvent
event( event_type
);
1676 InitMouseEvent( win
, event
, gdk_event
);
1678 AdjustEventButtonState(event
);
1680 // same wxListBox hack as above
1681 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1683 if ( !g_captureWindow
)
1684 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1686 if (win
->GetEventHandler()->ProcessEvent( event
))
1688 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_release_event" );
1696 //-----------------------------------------------------------------------------
1697 // "motion_notify_event"
1698 //-----------------------------------------------------------------------------
1701 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
,
1702 GdkEventMotion
*gdk_event
,
1708 wxapp_install_idle_handler();
1710 if (!win
->m_hasVMT
) return FALSE
;
1711 if (g_blockEventsOnDrag
) return FALSE
;
1712 if (g_blockEventsOnScroll
) return FALSE
;
1714 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1716 if (gdk_event
->is_hint
)
1720 GdkModifierType state
;
1721 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1727 printf( "OnMotion from " );
1728 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1729 printf( win->GetClassInfo()->GetClassName() );
1733 wxMouseEvent
event( wxEVT_MOTION
);
1734 InitMouseEvent(win
, event
, gdk_event
);
1736 if ( g_captureWindow
)
1738 // synthetize a mouse enter or leave event if needed
1739 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1740 // This seems to be necessary and actually been added to
1741 // GDK itself in version 2.0.X
1744 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1745 if ( hasMouse
!= g_captureWindowHasMouse
)
1747 // the mouse changed window
1748 g_captureWindowHasMouse
= hasMouse
;
1750 wxMouseEvent
eventM(g_captureWindowHasMouse
? wxEVT_ENTER_WINDOW
1751 : wxEVT_LEAVE_WINDOW
);
1752 InitMouseEvent(win
, eventM
, gdk_event
);
1753 eventM
.SetEventObject(win
);
1754 win
->GetEventHandler()->ProcessEvent(eventM
);
1759 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1762 if (win
->GetEventHandler()->ProcessEvent( event
))
1764 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "motion_notify_event" );
1772 //-----------------------------------------------------------------------------
1774 //-----------------------------------------------------------------------------
1776 // send the wxChildFocusEvent and wxFocusEvent, common code of
1777 // gtk_window_focus_in_callback() and SetFocus()
1778 static bool DoSendFocusEvents(wxWindow
*win
)
1780 // Notify the parent keeping track of focus for the kbd navigation
1781 // purposes that we got it.
1782 wxChildFocusEvent
eventChildFocus(win
);
1783 (void)win
->GetEventHandler()->ProcessEvent(eventChildFocus
);
1785 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, win
->GetId());
1786 eventFocus
.SetEventObject(win
);
1788 return win
->GetEventHandler()->ProcessEvent(eventFocus
);
1792 static gint
gtk_window_focus_in_callback( GtkWidget
*widget
,
1793 GdkEvent
*WXUNUSED(event
),
1799 wxapp_install_idle_handler();
1802 g_focusWindow
= win
;
1804 wxLogTrace(TRACE_FOCUS
,
1805 _T("%s: focus in"), win
->GetName().c_str());
1809 gdk_im_begin(win
->m_ic
, win
->m_wxwindow
->window
);
1813 // caret needs to be informed about focus change
1814 wxCaret
*caret
= win
->GetCaret();
1817 caret
->OnSetFocus();
1819 #endif // wxUSE_CARET
1821 // does the window itself think that it has the focus?
1822 if ( !win
->m_hasFocus
)
1824 // not yet, notify it
1825 win
->m_hasFocus
= true;
1827 if ( DoSendFocusEvents(win
) )
1829 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_in_event" );
1838 //-----------------------------------------------------------------------------
1839 // "focus_out_event"
1840 //-----------------------------------------------------------------------------
1843 static gint
gtk_window_focus_out_callback( GtkWidget
*widget
, GdkEventFocus
*gdk_event
, wxWindowGTK
*win
)
1848 wxapp_install_idle_handler();
1850 wxLogTrace( TRACE_FOCUS
,
1851 _T("%s: focus out"), win
->GetName().c_str() );
1854 wxWindowGTK
*winFocus
= wxFindFocusedChild(win
);
1858 g_focusWindow
= (wxWindowGTK
*)NULL
;
1866 // caret needs to be informed about focus change
1867 wxCaret
*caret
= win
->GetCaret();
1870 caret
->OnKillFocus();
1872 #endif // wxUSE_CARET
1874 // don't send the window a kill focus event if it thinks that it doesn't
1875 // have focus already
1876 if ( win
->m_hasFocus
)
1878 win
->m_hasFocus
= false;
1880 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
1881 event
.SetEventObject( win
);
1883 // even if we did process the event in wx code, still let GTK itself
1884 // process it too as otherwise bad things happen, especially in GTK2
1885 // where the text control simply aborts the program if it doesn't get
1886 // the matching focus out event
1887 (void)win
->GetEventHandler()->ProcessEvent( event
);
1894 //-----------------------------------------------------------------------------
1895 // "enter_notify_event"
1896 //-----------------------------------------------------------------------------
1900 gint
gtk_window_enter_callback( GtkWidget
*widget
,
1901 GdkEventCrossing
*gdk_event
,
1907 wxapp_install_idle_handler();
1909 if (!win
->m_hasVMT
) return FALSE
;
1910 if (g_blockEventsOnDrag
) return FALSE
;
1912 // Event was emitted after a grab
1913 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1915 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1919 GdkModifierType state
= (GdkModifierType
)0;
1921 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1923 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
1924 InitMouseEvent(win
, event
, gdk_event
);
1925 wxPoint pt
= win
->GetClientAreaOrigin();
1926 event
.m_x
= x
+ pt
.x
;
1927 event
.m_y
= y
+ pt
.y
;
1929 if (win
->GetEventHandler()->ProcessEvent( event
))
1931 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "enter_notify_event" );
1939 //-----------------------------------------------------------------------------
1940 // "leave_notify_event"
1941 //-----------------------------------------------------------------------------
1944 static gint
gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindowGTK
*win
)
1949 wxapp_install_idle_handler();
1951 if (!win
->m_hasVMT
) return FALSE
;
1952 if (g_blockEventsOnDrag
) return FALSE
;
1954 // Event was emitted after an ungrab
1955 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1957 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1959 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
1960 event
.SetTimestamp( gdk_event
->time
);
1961 event
.SetEventObject( win
);
1965 GdkModifierType state
= (GdkModifierType
)0;
1967 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1969 event
.m_shiftDown
= (state
& GDK_SHIFT_MASK
) != 0;
1970 event
.m_controlDown
= (state
& GDK_CONTROL_MASK
) != 0;
1971 event
.m_altDown
= (state
& GDK_MOD1_MASK
) != 0;
1972 event
.m_metaDown
= (state
& GDK_MOD2_MASK
) != 0;
1973 event
.m_leftDown
= (state
& GDK_BUTTON1_MASK
) != 0;
1974 event
.m_middleDown
= (state
& GDK_BUTTON2_MASK
) != 0;
1975 event
.m_rightDown
= (state
& GDK_BUTTON3_MASK
) != 0;
1977 wxPoint pt
= win
->GetClientAreaOrigin();
1978 event
.m_x
= x
+ pt
.x
;
1979 event
.m_y
= y
+ pt
.y
;
1981 if (win
->GetEventHandler()->ProcessEvent( event
))
1983 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "leave_notify_event" );
1991 //-----------------------------------------------------------------------------
1992 // "value_changed" from m_vAdjust
1993 //-----------------------------------------------------------------------------
1996 static void gtk_window_vscroll_callback( GtkAdjustment
*adjust
,
2003 wxapp_install_idle_handler();
2005 if (g_blockEventsOnDrag
) return;
2007 if (!win
->m_hasVMT
) return;
2009 float diff
= adjust
->value
- win
->m_oldVerticalPos
;
2010 if (fabs(diff
) < 0.2) return;
2012 win
->m_oldVerticalPos
= adjust
->value
;
2014 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2015 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->vscrollbar
));
2017 int value
= (int)(adjust
->value
+0.5);
2019 wxScrollWinEvent
event( command
, value
, wxVERTICAL
);
2020 event
.SetEventObject( win
);
2021 win
->GetEventHandler()->ProcessEvent( event
);
2025 //-----------------------------------------------------------------------------
2026 // "value_changed" from m_hAdjust
2027 //-----------------------------------------------------------------------------
2030 static void gtk_window_hscroll_callback( GtkAdjustment
*adjust
,
2037 wxapp_install_idle_handler();
2039 if (g_blockEventsOnDrag
) return;
2040 if (!win
->m_hasVMT
) return;
2042 float diff
= adjust
->value
- win
->m_oldHorizontalPos
;
2043 if (fabs(diff
) < 0.2) return;
2045 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2046 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->hscrollbar
));
2048 win
->m_oldHorizontalPos
= adjust
->value
;
2050 int value
= (int)(adjust
->value
+0.5);
2052 wxScrollWinEvent
event( command
, value
, wxHORIZONTAL
);
2053 event
.SetEventObject( win
);
2054 win
->GetEventHandler()->ProcessEvent( event
);
2058 //-----------------------------------------------------------------------------
2059 // "button_press_event" from scrollbar
2060 //-----------------------------------------------------------------------------
2063 static gint
gtk_scrollbar_button_press_callback( GtkRange
*widget
,
2064 GdkEventButton
*gdk_event
,
2070 wxapp_install_idle_handler();
2073 g_blockEventsOnScroll
= true;
2075 // FIXME: there is no 'slider' field in GTK+ 2.0 any more
2076 win
->m_isScrolling
= (gdk_event
->window
== widget
->slider
);
2082 //-----------------------------------------------------------------------------
2083 // "button_release_event" from scrollbar
2084 //-----------------------------------------------------------------------------
2087 static gint
gtk_scrollbar_button_release_callback( GtkRange
*widget
,
2088 GdkEventButton
*WXUNUSED(gdk_event
),
2093 // don't test here as we can release the mouse while being over
2094 // a different window than the slider
2096 // if (gdk_event->window != widget->slider) return FALSE;
2098 g_blockEventsOnScroll
= false;
2100 if (win
->m_isScrolling
)
2102 wxEventType command
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2106 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2107 if (widget
== GTK_RANGE(scrolledWindow
->hscrollbar
))
2109 value
= (int)(win
->m_hAdjust
->value
+0.5);
2112 if (widget
== GTK_RANGE(scrolledWindow
->vscrollbar
))
2114 value
= (int)(win
->m_vAdjust
->value
+0.5);
2118 wxScrollWinEvent
event( command
, value
, dir
);
2119 event
.SetEventObject( win
);
2120 win
->GetEventHandler()->ProcessEvent( event
);
2123 win
->m_isScrolling
= false;
2129 // ----------------------------------------------------------------------------
2130 // this wxWindowBase function is implemented here (in platform-specific file)
2131 // because it is static and so couldn't be made virtual
2132 // ----------------------------------------------------------------------------
2134 wxWindow
*wxWindowBase::DoFindFocus()
2136 // the cast is necessary when we compile in wxUniversal mode
2137 return (wxWindow
*)g_focusWindow
;
2140 //-----------------------------------------------------------------------------
2141 // "realize" from m_widget
2142 //-----------------------------------------------------------------------------
2144 /* We cannot set colours and fonts before the widget has
2145 been realized, so we do this directly after realization. */
2149 gtk_window_realized_callback( GtkWidget
*m_widget
, wxWindow
*win
)
2154 wxapp_install_idle_handler();
2156 wxWindowCreateEvent
event( win
);
2157 event
.SetEventObject( win
);
2158 win
->GetEventHandler()->ProcessEvent( event
);
2164 //-----------------------------------------------------------------------------
2166 //-----------------------------------------------------------------------------
2170 void gtk_window_size_callback( GtkWidget
*WXUNUSED(widget
),
2171 GtkAllocation
*WXUNUSED(alloc
),
2175 wxapp_install_idle_handler();
2177 if (!win
->m_hasScrolling
) return;
2179 int client_width
= 0;
2180 int client_height
= 0;
2181 win
->GetClientSize( &client_width
, &client_height
);
2182 if ((client_width
== win
->m_oldClientWidth
) && (client_height
== win
->m_oldClientHeight
))
2185 win
->m_oldClientWidth
= client_width
;
2186 win
->m_oldClientHeight
= client_height
;
2188 if (!win
->m_nativeSizeEvent
)
2190 wxSizeEvent
event( win
->GetSize(), win
->GetId() );
2191 event
.SetEventObject( win
);
2192 win
->GetEventHandler()->ProcessEvent( event
);
2199 #define WXUNUSED_UNLESS_XIM(param) param
2201 #define WXUNUSED_UNLESS_XIM(param) WXUNUSED(param)
2204 /* Resize XIM window */
2208 void gtk_wxwindow_size_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2209 GtkAllocation
* WXUNUSED_UNLESS_XIM(alloc
),
2210 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2213 wxapp_install_idle_handler();
2219 if (gdk_ic_get_style (win
->m_ic
) & GDK_IM_PREEDIT_POSITION
)
2223 gdk_window_get_size (widget
->window
, &width
, &height
);
2224 win
->m_icattr
->preedit_area
.width
= width
;
2225 win
->m_icattr
->preedit_area
.height
= height
;
2226 gdk_ic_set_attr (win
->m_ic
, win
->m_icattr
, GDK_IC_PREEDIT_AREA
);
2232 //-----------------------------------------------------------------------------
2233 // "realize" from m_wxwindow
2234 //-----------------------------------------------------------------------------
2236 /* Initialize XIM support */
2240 gtk_wxwindow_realized_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2241 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2244 wxapp_install_idle_handler();
2247 if (win
->m_ic
) return FALSE
;
2248 if (!widget
) return FALSE
;
2249 if (!gdk_im_ready()) return FALSE
;
2251 win
->m_icattr
= gdk_ic_attr_new();
2252 if (!win
->m_icattr
) return FALSE
;
2256 GdkColormap
*colormap
;
2257 GdkICAttr
*attr
= win
->m_icattr
;
2258 unsigned attrmask
= GDK_IC_ALL_REQ
;
2260 GdkIMStyle supported_style
= (GdkIMStyle
)
2261 (GDK_IM_PREEDIT_NONE
|
2262 GDK_IM_PREEDIT_NOTHING
|
2263 GDK_IM_PREEDIT_POSITION
|
2264 GDK_IM_STATUS_NONE
|
2265 GDK_IM_STATUS_NOTHING
);
2267 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2268 supported_style
= (GdkIMStyle
)(supported_style
& ~GDK_IM_PREEDIT_POSITION
);
2270 attr
->style
= style
= gdk_im_decide_style (supported_style
);
2271 attr
->client_window
= widget
->window
;
2273 if ((colormap
= gtk_widget_get_colormap (widget
)) !=
2274 gtk_widget_get_default_colormap ())
2276 attrmask
|= GDK_IC_PREEDIT_COLORMAP
;
2277 attr
->preedit_colormap
= colormap
;
2280 attrmask
|= GDK_IC_PREEDIT_FOREGROUND
;
2281 attrmask
|= GDK_IC_PREEDIT_BACKGROUND
;
2282 attr
->preedit_foreground
= widget
->style
->fg
[GTK_STATE_NORMAL
];
2283 attr
->preedit_background
= widget
->style
->base
[GTK_STATE_NORMAL
];
2285 switch (style
& GDK_IM_PREEDIT_MASK
)
2287 case GDK_IM_PREEDIT_POSITION
:
2288 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2290 g_warning ("over-the-spot style requires fontset");
2294 gdk_window_get_size (widget
->window
, &width
, &height
);
2296 attrmask
|= GDK_IC_PREEDIT_POSITION_REQ
;
2297 attr
->spot_location
.x
= 0;
2298 attr
->spot_location
.y
= height
;
2299 attr
->preedit_area
.x
= 0;
2300 attr
->preedit_area
.y
= 0;
2301 attr
->preedit_area
.width
= width
;
2302 attr
->preedit_area
.height
= height
;
2303 attr
->preedit_fontset
= widget
->style
->font
;
2308 win
->m_ic
= gdk_ic_new (attr
, (GdkICAttributesType
)attrmask
);
2310 if (win
->m_ic
== NULL
)
2311 g_warning ("Can't create input context.");
2314 mask
= gdk_window_get_events (widget
->window
);
2315 mask
= (GdkEventMask
)(mask
| gdk_ic_get_events (win
->m_ic
));
2316 gdk_window_set_events (widget
->window
, mask
);
2318 if (GTK_WIDGET_HAS_FOCUS(widget
))
2319 gdk_im_begin (win
->m_ic
, widget
->window
);
2327 //-----------------------------------------------------------------------------
2328 // InsertChild for wxWindowGTK.
2329 //-----------------------------------------------------------------------------
2331 /* Callback for wxWindowGTK. This very strange beast has to be used because
2332 * C++ has no virtual methods in a constructor. We have to emulate a
2333 * virtual function here as wxNotebook requires a different way to insert
2334 * a child in it. I had opted for creating a wxNotebookPage window class
2335 * which would have made this superfluous (such in the MDI window system),
2336 * but no-one was listening to me... */
2338 static void wxInsertChildInWindow( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2340 /* the window might have been scrolled already, do we
2341 have to adapt the position */
2342 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
2343 child
->m_x
+= pizza
->xoffset
;
2344 child
->m_y
+= pizza
->yoffset
;
2346 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
2347 GTK_WIDGET(child
->m_widget
),
2354 //-----------------------------------------------------------------------------
2356 //-----------------------------------------------------------------------------
2358 wxWindow
*wxGetActiveWindow()
2360 return wxWindow::FindFocus();
2364 wxMouseState
wxGetMouseState()
2370 GdkModifierType mask
;
2372 gdk_window_get_pointer(NULL
, &x
, &y
, &mask
);
2376 ms
.SetLeftDown(mask
& GDK_BUTTON1_MASK
);
2377 ms
.SetMiddleDown(mask
& GDK_BUTTON2_MASK
);
2378 ms
.SetRightDown(mask
& GDK_BUTTON3_MASK
);
2380 ms
.SetControlDown(mask
& GDK_CONTROL_MASK
);
2381 ms
.SetShiftDown(mask
& GDK_SHIFT_MASK
);
2382 ms
.SetAltDown(mask
& GDK_MOD1_MASK
);
2383 ms
.SetMetaDown(mask
& GDK_MOD2_MASK
);
2388 //-----------------------------------------------------------------------------
2390 //-----------------------------------------------------------------------------
2392 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2394 #ifdef __WXUNIVERSAL__
2395 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2397 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
2398 #endif // __WXUNIVERSAL__/__WXGTK__
2400 void wxWindowGTK::Init()
2403 m_widget
= (GtkWidget
*) NULL
;
2404 m_wxwindow
= (GtkWidget
*) NULL
;
2405 m_focusWidget
= (GtkWidget
*) NULL
;
2415 m_needParent
= true;
2416 m_isBeingDeleted
= false;
2419 m_nativeSizeEvent
= false;
2421 m_hasScrolling
= false;
2422 m_isScrolling
= false;
2424 m_hAdjust
= (GtkAdjustment
*) NULL
;
2425 m_vAdjust
= (GtkAdjustment
*) NULL
;
2426 m_oldHorizontalPos
=
2427 m_oldVerticalPos
= 0.0;
2429 m_oldClientHeight
= 0;
2433 m_insertCallback
= (wxInsertChildFunction
) NULL
;
2435 m_acceptsFocus
= false;
2438 m_clipPaintRegion
= false;
2440 m_needsStyleChange
= false;
2442 m_cursor
= *wxSTANDARD_CURSOR
;
2445 m_ic
= (GdkIC
*) NULL
;
2446 m_icattr
= (GdkICAttr
*) NULL
;
2450 wxWindowGTK::wxWindowGTK()
2455 wxWindowGTK::wxWindowGTK( wxWindow
*parent
,
2460 const wxString
&name
)
2464 Create( parent
, id
, pos
, size
, style
, name
);
2467 bool wxWindowGTK::Create( wxWindow
*parent
,
2472 const wxString
&name
)
2474 if (!PreCreation( parent
, pos
, size
) ||
2475 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2477 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2481 m_insertCallback
= wxInsertChildInWindow
;
2483 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
2484 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
2486 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2488 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2489 scroll_class
->scrollbar_spacing
= 0;
2491 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2493 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
2494 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
2496 m_wxwindow
= gtk_pizza_new();
2498 #ifndef __WXUNIVERSAL__
2499 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
2501 if (HasFlag(wxRAISED_BORDER
))
2503 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
2505 else if (HasFlag(wxSUNKEN_BORDER
))
2507 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
2509 else if (HasFlag(wxSIMPLE_BORDER
))
2511 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
2515 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
2517 #endif // __WXUNIVERSAL__
2519 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2521 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
2522 m_acceptsFocus
= true;
2524 // I _really_ don't want scrollbars in the beginning
2525 m_vAdjust
->lower
= 0.0;
2526 m_vAdjust
->upper
= 1.0;
2527 m_vAdjust
->value
= 0.0;
2528 m_vAdjust
->step_increment
= 1.0;
2529 m_vAdjust
->page_increment
= 1.0;
2530 m_vAdjust
->page_size
= 5.0;
2531 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
2532 m_hAdjust
->lower
= 0.0;
2533 m_hAdjust
->upper
= 1.0;
2534 m_hAdjust
->value
= 0.0;
2535 m_hAdjust
->step_increment
= 1.0;
2536 m_hAdjust
->page_increment
= 1.0;
2537 m_hAdjust
->page_size
= 5.0;
2538 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
2540 // these handlers block mouse events to any window during scrolling such as
2541 // motion events and prevent GTK and wxWidgets from fighting over where the
2544 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_press_event",
2545 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2547 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_press_event",
2548 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2550 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_release_event",
2551 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2553 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_release_event",
2554 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2556 // these handlers get notified when screen updates are required either when
2557 // scrolling or when the window size (and therefore scrollbar configuration)
2560 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
2561 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
2562 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
2563 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
2565 gtk_widget_show( m_wxwindow
);
2568 m_parent
->DoAddChild( this );
2570 m_focusWidget
= m_wxwindow
;
2577 wxWindowGTK::~wxWindowGTK()
2581 if (g_focusWindow
== this)
2582 g_focusWindow
= NULL
;
2584 if ( g_delayedFocus
== this )
2585 g_delayedFocus
= NULL
;
2587 m_isBeingDeleted
= true;
2590 // destroy children before destroying this window itself
2593 // unhook focus handlers to prevent stray events being
2594 // propagated to this (soon to be) dead object
2595 if (m_focusWidget
!= NULL
)
2597 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2598 (GtkSignalFunc
) gtk_window_focus_in_callback
, (gpointer
) this );
2599 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2600 (GtkSignalFunc
) gtk_window_focus_out_callback
, (gpointer
) this );
2608 gdk_ic_destroy (m_ic
);
2610 gdk_ic_attr_destroy (m_icattr
);
2615 gtk_widget_destroy( m_wxwindow
);
2616 m_wxwindow
= (GtkWidget
*) NULL
;
2621 gtk_widget_destroy( m_widget
);
2622 m_widget
= (GtkWidget
*) NULL
;
2626 bool wxWindowGTK::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2628 wxCHECK_MSG( !m_needParent
|| parent
, false, wxT("Need complete parent.") );
2630 // Use either the given size, or the default if -1 is given.
2631 // See wxWindowBase for these functions.
2632 m_width
= WidthDefault(size
.x
) ;
2633 m_height
= HeightDefault(size
.y
);
2641 void wxWindowGTK::PostCreation()
2643 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2649 // these get reported to wxWidgets -> wxPaintEvent
2651 gtk_pizza_set_external( GTK_PIZZA(m_wxwindow
), TRUE
);
2653 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
2654 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
2656 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
2657 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
2659 if (!HasFlag(wxFULL_REPAINT_ON_RESIZE
))
2661 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "event",
2662 GTK_SIGNAL_FUNC(gtk_window_event_event_callback
), (gpointer
)this );
2666 // these are called when the "sunken" or "raised" borders are drawn
2667 gtk_signal_connect( GTK_OBJECT(m_widget
), "expose_event",
2668 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
2670 gtk_signal_connect( GTK_OBJECT(m_widget
), "draw",
2671 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
2676 if (!GTK_IS_WINDOW(m_widget
))
2678 if (m_focusWidget
== NULL
)
2679 m_focusWidget
= m_widget
;
2681 gtk_signal_connect( GTK_OBJECT(m_focusWidget
), "focus_in_event",
2682 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
2684 gtk_signal_connect_after( GTK_OBJECT(m_focusWidget
), "focus_out_event",
2685 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
2688 // connect to the various key and mouse handlers
2690 GtkWidget
*connect_widget
= GetConnectWidget();
2692 ConnectWidget( connect_widget
);
2694 /* We cannot set colours, fonts and cursors before the widget has
2695 been realized, so we do this directly after realization */
2696 gtk_signal_connect( GTK_OBJECT(connect_widget
), "realize",
2697 GTK_SIGNAL_FUNC(gtk_window_realized_callback
), (gpointer
) this );
2701 // Catch native resize events
2702 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
2703 GTK_SIGNAL_FUNC(gtk_window_size_callback
), (gpointer
)this );
2705 // Initialize XIM support
2706 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "realize",
2707 GTK_SIGNAL_FUNC(gtk_wxwindow_realized_callback
), (gpointer
) this );
2709 // And resize XIM window
2710 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
2711 GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback
), (gpointer
)this );
2714 if (GTK_IS_COMBO(m_widget
))
2716 GtkCombo
*gcombo
= GTK_COMBO(m_widget
);
2718 gtk_signal_connect( GTK_OBJECT(gcombo
->entry
), "size_request",
2719 GTK_SIGNAL_FUNC(wxgtk_combo_size_request_callback
),
2724 // This is needed if we want to add our windows into native
2725 // GTK controls, such as the toolbar. With this callback, the
2726 // toolbar gets to know the correct size (the one set by the
2727 // programmer). Sadly, it misbehaves for wxComboBox.
2728 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_request",
2729 GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback
),
2733 InheritAttributes();
2737 // unless the window was created initially hidden (i.e. Hide() had been
2738 // called before Create()), we should show it at GTK+ level as well
2740 gtk_widget_show( m_widget
);
2743 void wxWindowGTK::ConnectWidget( GtkWidget
*widget
)
2745 gtk_signal_connect( GTK_OBJECT(widget
), "key_press_event",
2746 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
2748 gtk_signal_connect( GTK_OBJECT(widget
), "key_release_event",
2749 GTK_SIGNAL_FUNC(gtk_window_key_release_callback
), (gpointer
)this );
2751 gtk_signal_connect( GTK_OBJECT(widget
), "button_press_event",
2752 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
2754 gtk_signal_connect( GTK_OBJECT(widget
), "button_release_event",
2755 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
2757 gtk_signal_connect( GTK_OBJECT(widget
), "motion_notify_event",
2758 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
2760 gtk_signal_connect( GTK_OBJECT(widget
), "enter_notify_event",
2761 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
2763 gtk_signal_connect( GTK_OBJECT(widget
), "leave_notify_event",
2764 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
2767 bool wxWindowGTK::Destroy()
2769 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2773 return wxWindowBase::Destroy();
2776 void wxWindowGTK::DoMoveWindow(int x
, int y
, int width
, int height
)
2778 gtk_pizza_set_size( GTK_PIZZA(m_parent
->m_wxwindow
), m_widget
, x
, y
, width
, height
);
2781 void wxWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
2783 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2784 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
2787 printf( "DoSetSize: name %s, x,y,w,h: %d,%d,%d,%d \n", GetName().c_str(), x,y,width,height );
2790 if (m_resizing
) return; /* I don't like recursions */
2793 int currentX
, currentY
;
2794 GetPosition(¤tX
, ¤tY
);
2795 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2797 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2799 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2801 if (m_parent
->m_wxwindow
== NULL
) /* i.e. wxNotebook */
2803 /* don't set the size for children of wxNotebook, just take the values. */
2811 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
2812 if ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0)
2814 if (x
!= -1) m_x
= x
+ pizza
->xoffset
;
2815 if (y
!= -1) m_y
= y
+ pizza
->yoffset
;
2819 m_x
= x
+ pizza
->xoffset
;
2820 m_y
= y
+ pizza
->yoffset
;
2823 // calculate the best size if we should auto size the window
2824 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
2825 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
2827 const wxSize sizeBest
= GetBestSize();
2828 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
2830 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
2831 height
= sizeBest
.y
;
2839 int minWidth
= GetMinWidth(),
2840 minHeight
= GetMinHeight(),
2841 maxWidth
= GetMaxWidth(),
2842 maxHeight
= GetMaxHeight();
2844 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
2845 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
2846 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
2847 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
2849 int left_border
= 0;
2850 int right_border
= 0;
2852 int bottom_border
= 0;
2854 /* the default button has a border around it */
2855 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
2863 DoMoveWindow( m_x
-top_border
,
2865 m_width
+left_border
+right_border
,
2866 m_height
+top_border
+bottom_border
);
2871 /* Sometimes the client area changes size without the
2872 whole windows's size changing, but if the whole
2873 windows's size doesn't change, no wxSizeEvent will
2874 normally be sent. Here we add an extra test if
2875 the client test has been changed and this will
2877 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
2881 wxPrintf( "OnSize sent from " );
2882 if (GetClassInfo() && GetClassInfo()->GetClassName())
2883 wxPrintf( GetClassInfo()->GetClassName() );
2884 wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height );
2887 if (!m_nativeSizeEvent
)
2889 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
2890 event
.SetEventObject( this );
2891 GetEventHandler()->ProcessEvent( event
);
2897 void wxWindowGTK::OnInternalIdle()
2899 // Update style if the window was not yet realized
2900 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
2901 if (m_needsStyleChange
)
2903 SetBackgroundStyle(GetBackgroundStyle());
2904 m_needsStyleChange
= false;
2907 // Update invalidated regions.
2910 wxCursor cursor
= m_cursor
;
2911 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
2915 /* I now set the cursor anew in every OnInternalIdle call
2916 as setting the cursor in a parent window also effects the
2917 windows above so that checking for the current cursor is
2922 GdkWindow
*window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
2924 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2926 if (!g_globalCursor
.Ok())
2927 cursor
= *wxSTANDARD_CURSOR
;
2929 window
= m_widget
->window
;
2930 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2931 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2934 else if ( m_widget
)
2936 GdkWindow
*window
= m_widget
->window
;
2937 if ( window
&& !GTK_WIDGET_NO_WINDOW(m_widget
) )
2938 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2942 if (wxUpdateUIEvent::CanUpdate(this))
2943 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2946 void wxWindowGTK::DoGetSize( int *width
, int *height
) const
2948 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2950 if (width
) (*width
) = m_width
;
2951 if (height
) (*height
) = m_height
;
2954 void wxWindowGTK::DoSetClientSize( int width
, int height
)
2956 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2960 SetSize( width
, height
);
2967 #ifndef __WXUNIVERSAL__
2968 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
2970 /* when using GTK 1.2 we set the shadow border size to 2 */
2974 if (HasFlag(wxSIMPLE_BORDER
))
2976 /* when using GTK 1.2 we set the simple border size to 1 */
2980 #endif // __WXUNIVERSAL__
2984 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
2986 GtkRequisition vscroll_req
;
2987 vscroll_req
.width
= 2;
2988 vscroll_req
.height
= 2;
2989 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
2990 (scroll_window
->vscrollbar
, &vscroll_req
);
2992 GtkRequisition hscroll_req
;
2993 hscroll_req
.width
= 2;
2994 hscroll_req
.height
= 2;
2995 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
2996 (scroll_window
->hscrollbar
, &hscroll_req
);
2998 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3000 if (scroll_window
->vscrollbar_visible
)
3002 dw
+= vscroll_req
.width
;
3003 dw
+= scroll_class
->scrollbar_spacing
;
3006 if (scroll_window
->hscrollbar_visible
)
3008 dh
+= hscroll_req
.height
;
3009 dh
+= scroll_class
->scrollbar_spacing
;
3013 SetSize( width
+dw
, height
+dh
);
3017 void wxWindowGTK::DoGetClientSize( int *width
, int *height
) const
3019 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3023 if (width
) (*width
) = m_width
;
3024 if (height
) (*height
) = m_height
;
3031 #ifndef __WXUNIVERSAL__
3032 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
3034 /* when using GTK 1.2 we set the shadow border size to 2 */
3038 if (HasFlag(wxSIMPLE_BORDER
))
3040 /* when using GTK 1.2 we set the simple border size to 1 */
3044 #endif // __WXUNIVERSAL__
3048 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
3050 GtkRequisition vscroll_req
;
3051 vscroll_req
.width
= 2;
3052 vscroll_req
.height
= 2;
3053 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
3054 (scroll_window
->vscrollbar
, &vscroll_req
);
3056 GtkRequisition hscroll_req
;
3057 hscroll_req
.width
= 2;
3058 hscroll_req
.height
= 2;
3059 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
3060 (scroll_window
->hscrollbar
, &hscroll_req
);
3062 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3064 if (scroll_window
->vscrollbar_visible
)
3066 dw
+= vscroll_req
.width
;
3067 dw
+= scroll_class
->scrollbar_spacing
;
3070 if (scroll_window
->hscrollbar_visible
)
3072 dh
+= hscroll_req
.height
;
3073 dh
+= scroll_class
->scrollbar_spacing
;
3077 if (width
) (*width
) = m_width
- dw
;
3078 if (height
) (*height
) = m_height
- dh
;
3082 printf( "GetClientSize, name %s ", GetName().c_str() );
3083 if (width) printf( " width = %d", (*width) );
3084 if (height) printf( " height = %d", (*height) );
3089 void wxWindowGTK::DoGetPosition( int *x
, int *y
) const
3091 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3095 if (m_parent
&& m_parent
->m_wxwindow
)
3097 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
3098 dx
= pizza
->xoffset
;
3099 dy
= pizza
->yoffset
;
3102 if (x
) (*x
) = m_x
- dx
;
3103 if (y
) (*y
) = m_y
- dy
;
3106 void wxWindowGTK::DoClientToScreen( int *x
, int *y
) const
3108 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3110 if (!m_widget
->window
) return;
3112 GdkWindow
*source
= (GdkWindow
*) NULL
;
3114 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3116 source
= m_widget
->window
;
3120 gdk_window_get_origin( source
, &org_x
, &org_y
);
3124 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3126 org_x
+= m_widget
->allocation
.x
;
3127 org_y
+= m_widget
->allocation
.y
;
3135 void wxWindowGTK::DoScreenToClient( int *x
, int *y
) const
3137 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3139 if (!m_widget
->window
) return;
3141 GdkWindow
*source
= (GdkWindow
*) NULL
;
3143 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3145 source
= m_widget
->window
;
3149 gdk_window_get_origin( source
, &org_x
, &org_y
);
3153 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3155 org_x
+= m_widget
->allocation
.x
;
3156 org_y
+= m_widget
->allocation
.y
;
3164 bool wxWindowGTK::Show( bool show
)
3166 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3168 if (!wxWindowBase::Show(show
))
3175 gtk_widget_show( m_widget
);
3177 gtk_widget_hide( m_widget
);
3179 wxShowEvent
eventShow(GetId(), show
);
3180 eventShow
.SetEventObject(this);
3182 GetEventHandler()->ProcessEvent(eventShow
);
3187 static void wxWindowNotifyEnable(wxWindowGTK
* win
, bool enable
)
3189 win
->OnParentEnable(enable
);
3191 // Recurse, so that children have the opportunity to Do The Right Thing
3192 // and reset colours that have been messed up by a parent's (really ancestor's)
3194 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3196 node
= node
->GetNext() )
3198 wxWindow
*child
= node
->GetData();
3199 if (!child
->IsKindOf(CLASSINFO(wxDialog
)) && !child
->IsKindOf(CLASSINFO(wxFrame
)))
3200 wxWindowNotifyEnable(child
, enable
);
3204 bool wxWindowGTK::Enable( bool enable
)
3206 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3208 if (!wxWindowBase::Enable(enable
))
3214 gtk_widget_set_sensitive( m_widget
, enable
);
3216 gtk_widget_set_sensitive( m_wxwindow
, enable
);
3218 wxWindowNotifyEnable(this, enable
);
3223 int wxWindowGTK::GetCharHeight() const
3225 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
3227 wxFont font
= GetFont();
3228 wxCHECK_MSG( font
.Ok(), 12, wxT("invalid font") );
3230 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3232 return gfont
->ascent
+ gfont
->descent
;
3235 int wxWindowGTK::GetCharWidth() const
3237 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
3239 wxFont font
= GetFont();
3240 wxCHECK_MSG( font
.Ok(), 8, wxT("invalid font") );
3242 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3244 return gdk_string_width( gfont
, "g" );
3247 void wxWindowGTK::GetTextExtent( const wxString
& string
,
3251 int *externalLeading
,
3252 const wxFont
*theFont
) const
3254 wxFont fontToUse
= theFont
? *theFont
: GetFont();
3256 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
3265 GdkFont
*font
= fontToUse
.GetInternalFont( 1.0 );
3266 if (x
) (*x
) = gdk_string_width( font
, wxGTK_CONV( string
) );
3267 if (y
) (*y
) = font
->ascent
+ font
->descent
;
3268 if (descent
) (*descent
) = font
->descent
;
3269 if (externalLeading
) (*externalLeading
) = 0; // ??
3272 void wxWindowGTK::SetFocus()
3274 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3277 // don't do anything if we already have focus
3283 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow
))
3285 gtk_widget_grab_focus (m_wxwindow
);
3290 if (GTK_WIDGET_CAN_FOCUS(m_widget
) && !GTK_WIDGET_HAS_FOCUS (m_widget
) )
3293 if (!GTK_WIDGET_REALIZED(m_widget
))
3295 // we can't set the focus to the widget now so we remember that
3296 // it should be focused and will do it later, during the idle
3297 // time, as soon as we can
3298 wxLogTrace(TRACE_FOCUS
,
3299 _T("Delaying setting focus to %s(%s)"),
3300 GetClassInfo()->GetClassName(), GetLabel().c_str());
3302 g_delayedFocus
= this;
3306 wxLogTrace(TRACE_FOCUS
,
3307 _T("Setting focus to %s(%s)"),
3308 GetClassInfo()->GetClassName(), GetLabel().c_str());
3310 gtk_widget_grab_focus (m_widget
);
3314 if (GTK_IS_CONTAINER(m_widget
))
3316 gtk_container_focus( GTK_CONTAINER(m_widget
), GTK_DIR_TAB_FORWARD
);
3320 wxLogTrace(TRACE_FOCUS
,
3321 _T("Can't set focus to %s(%s)"),
3322 GetClassInfo()->GetClassName(), GetLabel().c_str());
3327 bool wxWindowGTK::AcceptsFocus() const
3329 return m_acceptsFocus
&& wxWindowBase::AcceptsFocus();
3332 bool wxWindowGTK::Reparent( wxWindowBase
*newParentBase
)
3334 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3336 wxWindowGTK
*oldParent
= m_parent
,
3337 *newParent
= (wxWindowGTK
*)newParentBase
;
3339 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3341 if ( !wxWindowBase::Reparent(newParent
) )
3344 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3346 /* prevent GTK from deleting the widget arbitrarily */
3347 gtk_widget_ref( m_widget
);
3351 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3354 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3358 /* insert GTK representation */
3359 (*(newParent
->m_insertCallback
))(newParent
, this);
3362 /* reverse: prevent GTK from deleting the widget arbitrarily */
3363 gtk_widget_unref( m_widget
);
3368 void wxWindowGTK::DoAddChild(wxWindowGTK
*child
)
3370 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3372 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3374 wxASSERT_MSG( (m_insertCallback
!= NULL
), wxT("invalid child insertion function") );
3379 /* insert GTK representation */
3380 (*m_insertCallback
)(this, child
);
3383 void wxWindowGTK::Raise()
3385 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3387 if (m_wxwindow
&& m_wxwindow
->window
)
3389 gdk_window_raise( m_wxwindow
->window
);
3391 else if (m_widget
->window
)
3393 gdk_window_raise( m_widget
->window
);
3397 void wxWindowGTK::Lower()
3399 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3401 if (m_wxwindow
&& m_wxwindow
->window
)
3403 gdk_window_lower( m_wxwindow
->window
);
3405 else if (m_widget
->window
)
3407 gdk_window_lower( m_widget
->window
);
3411 bool wxWindowGTK::SetCursor( const wxCursor
&cursor
)
3413 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3415 if (cursor
== m_cursor
)
3419 wxapp_install_idle_handler();
3421 if (cursor
== wxNullCursor
)
3422 return wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
);
3424 return wxWindowBase::SetCursor( cursor
);
3427 void wxWindowGTK::WarpPointer( int x
, int y
)
3429 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3431 // We provide this function ourselves as it is
3432 // missing in GDK (top of this file).
3434 GdkWindow
*window
= (GdkWindow
*) NULL
;
3436 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3438 window
= GetConnectWidget()->window
;
3441 gdk_window_warp_pointer( window
, x
, y
);
3445 void wxWindowGTK::Refresh( bool eraseBackground
, const wxRect
*rect
)
3449 if (!m_widget
->window
)
3453 wxapp_install_idle_handler();
3456 if (m_wxwindow
&& rect
)
3458 myRect
.SetSize(wxSize( m_wxwindow
->allocation
.width
,
3459 m_wxwindow
->allocation
.height
));
3460 if ( myRect
.Intersect(*rect
).IsEmpty() )
3462 // nothing to do, rectangle is empty
3469 // schedule the area for later updating in GtkUpdate()
3470 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
3474 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3478 m_clearRegion
.Clear();
3479 m_clearRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
3487 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3491 GdkRectangle gdk_rect
;
3492 gdk_rect
.x
= rect
->x
;
3493 gdk_rect
.y
= rect
->y
;
3494 gdk_rect
.width
= rect
->width
;
3495 gdk_rect
.height
= rect
->height
;
3496 gtk_widget_draw( m_widget
, &gdk_rect
);
3503 m_updateRegion
.Clear();
3504 m_updateRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
3508 gtk_widget_draw( m_widget
, (GdkRectangle
*) NULL
);
3513 void wxWindowGTK::Update()
3517 // when we call Update() we really want to update the window immediately on
3518 // screen, even if it means flushing the entire queue and hence slowing down
3519 // everything -- but it should still be done, it's just that Update() should
3520 // be called very rarely
3524 void wxWindowGTK::GtkUpdate()
3526 if (!m_updateRegion
.IsEmpty())
3527 GtkSendPaintEvents();
3529 // for consistency with other platforms (and also because it's convenient
3530 // to be able to update an entire TLW by calling Update() only once), we
3531 // should also update all our children here
3532 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3534 node
= node
->GetNext() )
3536 node
->GetData()->GtkUpdate();
3540 void wxWindowGTK::GtkSendPaintEvents()
3544 m_clearRegion
.Clear();
3545 m_updateRegion
.Clear();
3549 // Clip to paint region in wxClientDC
3550 m_clipPaintRegion
= true;
3552 // widget to draw on
3553 GtkPizza
*pizza
= GTK_PIZZA (m_wxwindow
);
3555 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM
))
3557 // find ancestor from which to steal background
3558 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3560 parent
= (wxWindow
*)this;
3562 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
3564 wxRegionIterator
upd( m_updateRegion
);
3568 rect
.x
= upd
.GetX();
3569 rect
.y
= upd
.GetY();
3570 rect
.width
= upd
.GetWidth();
3571 rect
.height
= upd
.GetHeight();
3573 gtk_paint_flat_box( parent
->m_widget
->style
,
3575 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
3588 // if (!m_clearRegion.IsEmpty()) // Always send an erase event under GTK 1.2
3590 wxWindowDC
dc( (wxWindow
*)this );
3591 if (m_clearRegion
.IsEmpty())
3592 dc
.SetClippingRegion( m_updateRegion
);
3594 dc
.SetClippingRegion( m_clearRegion
);
3596 wxEraseEvent
erase_event( GetId(), &dc
);
3597 erase_event
.SetEventObject( this );
3599 if (!GetEventHandler()->ProcessEvent(erase_event
) && GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3603 g_eraseGC
= gdk_gc_new( pizza
->bin_window
);
3604 gdk_gc_set_fill( g_eraseGC
, GDK_SOLID
);
3606 gdk_gc_set_foreground( g_eraseGC
, GetBackgroundColour().GetColor() );
3608 wxRegionIterator
upd( m_clearRegion
);
3611 gdk_draw_rectangle( pizza
->bin_window
, g_eraseGC
, 1,
3612 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
3616 m_clearRegion
.Clear();
3619 wxNcPaintEvent
nc_paint_event( GetId() );
3620 nc_paint_event
.SetEventObject( this );
3621 GetEventHandler()->ProcessEvent( nc_paint_event
);
3623 wxPaintEvent
paint_event( GetId() );
3624 paint_event
.SetEventObject( this );
3625 GetEventHandler()->ProcessEvent( paint_event
);
3627 m_clipPaintRegion
= false;
3629 #if !defined(__WXUNIVERSAL__)
3630 // The following code will result in all window-less widgets
3631 // being redrawn because the wxWidgets class is allowed to
3632 // paint over the window-less widgets.
3634 GList
*children
= pizza
->children
;
3637 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
3638 children
= children
->next
;
3640 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
3641 GTK_WIDGET_DRAWABLE (child
->widget
))
3643 // Get intersection of widget area and update region
3644 wxRegion
region( m_updateRegion
);
3646 GdkEventExpose gdk_event
;
3647 gdk_event
.type
= GDK_EXPOSE
;
3648 gdk_event
.window
= pizza
->bin_window
;
3649 gdk_event
.count
= 0;
3650 gdk_event
.send_event
= TRUE
;
3652 wxRegionIterator
upd( m_updateRegion
);
3656 rect
.x
= upd
.GetX();
3657 rect
.y
= upd
.GetY();
3658 rect
.width
= upd
.GetWidth();
3659 rect
.height
= upd
.GetHeight();
3661 if (gtk_widget_intersect (child
->widget
, &rect
, &gdk_event
.area
))
3663 gtk_widget_event (child
->widget
, (GdkEvent
*) &gdk_event
);
3670 #endif // native GTK 1
3672 m_updateRegion
.Clear();
3675 void wxWindowGTK::ClearBackground()
3677 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3679 if (m_wxwindow
&& m_wxwindow
->window
)
3681 m_clearRegion
.Clear();
3682 wxSize
size( GetClientSize() );
3683 m_clearRegion
.Union( 0,0,size
.x
,size
.y
);
3685 // Better do this in idle?
3691 void wxWindowGTK::DoSetToolTip( wxToolTip
*tip
)
3693 wxWindowBase::DoSetToolTip(tip
);
3696 m_tooltip
->Apply( (wxWindow
*)this );
3699 void wxWindowGTK::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
3701 wxString
tmp( tip
);
3702 gtk_tooltips_set_tip( tips
, GetConnectWidget(), wxGTK_CONV(tmp
), (gchar
*) NULL
);
3704 #endif // wxUSE_TOOLTIPS
3706 bool wxWindowGTK::SetBackgroundColour( const wxColour
&colour
)
3708 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3710 if (!wxWindowBase::SetBackgroundColour(colour
))
3715 // We need the pixel value e.g. for background clearing.
3716 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3719 // apply style change (forceStyle=true so that new style is applied
3720 // even if the bg colour changed from valid to wxNullColour)
3721 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3722 ApplyWidgetStyle(true);
3727 bool wxWindowGTK::SetForegroundColour( const wxColour
&colour
)
3729 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3731 if (!wxWindowBase::SetForegroundColour(colour
))
3738 // We need the pixel value e.g. for background clearing.
3739 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3742 // apply style change (forceStyle=true so that new style is applied
3743 // even if the bg colour changed from valid to wxNullColour):
3744 ApplyWidgetStyle(true);
3749 GtkRcStyle
*wxWindowGTK::CreateWidgetStyle(bool forceStyle
)
3751 // do we need to apply any changes at all?
3754 !m_foregroundColour
.Ok() && !m_backgroundColour
.Ok() )
3759 GtkRcStyle
*style
= gtk_rc_style_new();
3763 wxString xfontname
= m_font
.GetNativeFontInfo()->GetXFontName();
3764 style
->fontset_name
= g_strdup(xfontname
.c_str());
3767 if ( m_foregroundColour
.Ok() )
3769 GdkColor
*fg
= m_foregroundColour
.GetColor();
3771 style
->fg
[GTK_STATE_NORMAL
] = *fg
;
3772 style
->color_flags
[GTK_STATE_NORMAL
] = GTK_RC_FG
;
3774 style
->fg
[GTK_STATE_PRELIGHT
] = *fg
;
3775 style
->color_flags
[GTK_STATE_PRELIGHT
] = GTK_RC_FG
;
3777 style
->fg
[GTK_STATE_ACTIVE
] = *fg
;
3778 style
->color_flags
[GTK_STATE_ACTIVE
] = GTK_RC_FG
;
3781 if ( m_backgroundColour
.Ok() )
3783 GdkColor
*bg
= m_backgroundColour
.GetColor();
3785 style
->bg
[GTK_STATE_NORMAL
] = *bg
;
3786 style
->base
[GTK_STATE_NORMAL
] = *bg
;
3787 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)
3788 (style
->color_flags
[GTK_STATE_NORMAL
] | GTK_RC_BG
| GTK_RC_BASE
);
3790 style
->bg
[GTK_STATE_PRELIGHT
] = *bg
;
3791 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
3792 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)
3793 (style
->color_flags
[GTK_STATE_PRELIGHT
] | GTK_RC_BG
| GTK_RC_BASE
);
3795 style
->bg
[GTK_STATE_ACTIVE
] = *bg
;
3796 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
3797 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)
3798 (style
->color_flags
[GTK_STATE_ACTIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3800 style
->bg
[GTK_STATE_INSENSITIVE
] = *bg
;
3801 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
3802 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)
3803 (style
->color_flags
[GTK_STATE_INSENSITIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3809 void wxWindowGTK::ApplyWidgetStyle(bool forceStyle
)
3811 GtkRcStyle
*style
= CreateWidgetStyle(forceStyle
);
3814 DoApplyWidgetStyle(style
);
3815 gtk_rc_style_unref(style
);
3818 // Style change may affect GTK+'s size calculation:
3819 InvalidateBestSize();
3822 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle
*style
)
3825 gtk_widget_modify_style(m_wxwindow
, style
);
3827 gtk_widget_modify_style(m_widget
, style
);
3830 bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style
)
3832 wxWindowBase::SetBackgroundStyle(style
);
3834 if (style
== wxBG_STYLE_CUSTOM
)
3836 GdkWindow
*window
= (GdkWindow
*) NULL
;
3838 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3840 window
= GetConnectWidget()->window
;
3844 // Make sure GDK/X11 doesn't refresh the window
3846 gdk_window_set_back_pixmap( window
, None
, False
);
3848 Display
* display
= GDK_WINDOW_DISPLAY(window
);
3851 m_needsStyleChange
= false;
3854 // Do in OnIdle, because the window is not yet available
3855 m_needsStyleChange
= true;
3857 // Don't apply widget style, or we get a grey background
3861 // apply style change (forceStyle=true so that new style is applied
3862 // even if the bg colour changed from valid to wxNullColour):
3863 ApplyWidgetStyle(true);
3868 #if wxUSE_DRAG_AND_DROP
3870 void wxWindowGTK::SetDropTarget( wxDropTarget
*dropTarget
)
3872 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3874 GtkWidget
*dnd_widget
= GetConnectWidget();
3876 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
3878 if (m_dropTarget
) delete m_dropTarget
;
3879 m_dropTarget
= dropTarget
;
3881 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
3884 #endif // wxUSE_DRAG_AND_DROP
3886 GtkWidget
* wxWindowGTK::GetConnectWidget()
3888 GtkWidget
*connect_widget
= m_widget
;
3889 if (m_wxwindow
) connect_widget
= m_wxwindow
;
3891 return connect_widget
;
3894 bool wxWindowGTK::IsOwnGtkWindow( GdkWindow
*window
)
3897 return (window
== GTK_PIZZA(m_wxwindow
)->bin_window
);
3899 return (window
== m_widget
->window
);
3902 bool wxWindowGTK::SetFont( const wxFont
&font
)
3904 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3906 if (!wxWindowBase::SetFont(font
))
3909 // apply style change (forceStyle=true so that new style is applied
3910 // even if the font changed from valid to wxNullFont):
3911 ApplyWidgetStyle(true);
3916 void wxWindowGTK::DoCaptureMouse()
3918 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3920 GdkWindow
*window
= (GdkWindow
*) NULL
;
3922 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3924 window
= GetConnectWidget()->window
;
3926 wxCHECK_RET( window
, _T("CaptureMouse() failed") );
3928 const wxCursor
* cursor
= &m_cursor
;
3930 cursor
= wxSTANDARD_CURSOR
;
3932 gdk_pointer_grab( window
, FALSE
,
3934 (GDK_BUTTON_PRESS_MASK
|
3935 GDK_BUTTON_RELEASE_MASK
|
3936 GDK_POINTER_MOTION_HINT_MASK
|
3937 GDK_POINTER_MOTION_MASK
),
3939 cursor
->GetCursor(),
3940 (guint32
)GDK_CURRENT_TIME
);
3941 g_captureWindow
= this;
3942 g_captureWindowHasMouse
= true;
3945 void wxWindowGTK::DoReleaseMouse()
3947 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3949 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
3951 g_captureWindow
= (wxWindowGTK
*) NULL
;
3953 GdkWindow
*window
= (GdkWindow
*) NULL
;
3955 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3957 window
= GetConnectWidget()->window
;
3962 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
3966 wxWindow
*wxWindowBase::GetCapture()
3968 return (wxWindow
*)g_captureWindow
;
3971 bool wxWindowGTK::IsRetained() const
3976 void wxWindowGTK::SetScrollbar( int orient
, int pos
, int thumbVisible
,
3977 int range
, bool refresh
)
3979 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3981 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
3983 m_hasScrolling
= true;
3985 if (orient
== wxHORIZONTAL
)
3987 float fpos
= (float)pos
;
3988 float frange
= (float)range
;
3989 float fthumb
= (float)thumbVisible
;
3990 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
3991 if (fpos
< 0.0) fpos
= 0.0;
3993 if ((fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
3994 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
3996 SetScrollPos( orient
, pos
, refresh
);
4000 m_oldHorizontalPos
= fpos
;
4002 m_hAdjust
->lower
= 0.0;
4003 m_hAdjust
->upper
= frange
;
4004 m_hAdjust
->value
= fpos
;
4005 m_hAdjust
->step_increment
= 1.0;
4006 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4007 m_hAdjust
->page_size
= fthumb
;
4011 float fpos
= (float)pos
;
4012 float frange
= (float)range
;
4013 float fthumb
= (float)thumbVisible
;
4014 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
4015 if (fpos
< 0.0) fpos
= 0.0;
4017 if ((fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
4018 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
4020 SetScrollPos( orient
, pos
, refresh
);
4024 m_oldVerticalPos
= fpos
;
4026 m_vAdjust
->lower
= 0.0;
4027 m_vAdjust
->upper
= frange
;
4028 m_vAdjust
->value
= fpos
;
4029 m_vAdjust
->step_increment
= 1.0;
4030 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4031 m_vAdjust
->page_size
= fthumb
;
4034 if (orient
== wxHORIZONTAL
)
4035 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
4037 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
4040 void wxWindowGTK::GtkUpdateScrollbar(int orient
)
4042 GtkAdjustment
*adj
= orient
== wxHORIZONTAL
? m_hAdjust
: m_vAdjust
;
4043 GtkSignalFunc fn
= orient
== wxHORIZONTAL
4044 ? (GtkSignalFunc
)gtk_window_hscroll_callback
4045 : (GtkSignalFunc
)gtk_window_vscroll_callback
;
4047 gtk_signal_disconnect_by_func(GTK_OBJECT(adj
), fn
, (gpointer
)this);
4048 gtk_signal_emit_by_name(GTK_OBJECT(adj
), "value_changed");
4049 gtk_signal_connect(GTK_OBJECT(adj
), "value_changed", fn
, (gpointer
)this);
4052 void wxWindowGTK::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
4054 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4055 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4057 GtkAdjustment
*adj
= orient
== wxHORIZONTAL
? m_hAdjust
: m_vAdjust
;
4059 float fpos
= (float)pos
;
4060 if (fpos
> adj
->upper
- adj
->page_size
)
4061 fpos
= adj
->upper
- adj
->page_size
;
4064 *(orient
== wxHORIZONTAL
? &m_oldHorizontalPos
: &m_oldVerticalPos
) = fpos
;
4066 if (fabs(fpos
-adj
->value
) < 0.2)
4070 if ( m_wxwindow
->window
)
4075 int wxWindowGTK::GetScrollThumb( int orient
) const
4077 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4079 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4081 if (orient
== wxHORIZONTAL
)
4082 return (int)(m_hAdjust
->page_size
+0.5);
4084 return (int)(m_vAdjust
->page_size
+0.5);
4087 int wxWindowGTK::GetScrollPos( int orient
) const
4089 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4091 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4093 if (orient
== wxHORIZONTAL
)
4094 return (int)(m_hAdjust
->value
+0.5);
4096 return (int)(m_vAdjust
->value
+0.5);
4099 int wxWindowGTK::GetScrollRange( int orient
) const
4101 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4103 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4105 if (orient
== wxHORIZONTAL
)
4106 return (int)(m_hAdjust
->upper
+0.5);
4108 return (int)(m_vAdjust
->upper
+0.5);
4111 void wxWindowGTK::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4113 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4115 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4117 // No scrolling requested.
4118 if ((dx
== 0) && (dy
== 0)) return;
4120 if (!m_updateRegion
.IsEmpty())
4122 m_updateRegion
.Offset( dx
, dy
);
4126 GetClientSize( &cw
, &ch
);
4127 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
4130 if (!m_clearRegion
.IsEmpty())
4132 m_clearRegion
.Offset( dx
, dy
);
4136 GetClientSize( &cw
, &ch
);
4137 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
4140 m_clipPaintRegion
= true;
4142 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow
), -dx
, -dy
);
4144 m_clipPaintRegion
= false;
4147 void wxWindowGTK::SetWindowStyleFlag( long style
)
4149 // Updates the internal variable. NB: Now m_windowStyle bits carry the _new_ style values already
4150 wxWindowBase::SetWindowStyleFlag(style
);
4153 // Find the wxWindow at the current mouse position, also returning the mouse
4155 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4157 pt
= wxGetMousePosition();
4158 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4162 // Get the current mouse position.
4163 wxPoint
wxGetMousePosition()
4165 /* This crashes when used within wxHelpContext,
4166 so we have to use the X-specific implementation below.
4168 GdkModifierType *mask;
4169 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4171 return wxPoint(x, y);
4175 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4177 Display
*display
= windowAtPtr
? GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4178 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4179 Window rootReturn
, childReturn
;
4180 int rootX
, rootY
, winX
, winY
;
4181 unsigned int maskReturn
;
4183 XQueryPointer (display
,
4187 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4188 return wxPoint(rootX
, rootY
);
4192 // Needed for implementing e.g. combobox on wxGTK within a modal dialog.
4193 void wxAddGrab(wxWindow
* window
)
4195 gtk_grab_add( (GtkWidget
*) window
->GetHandle() );
4198 void wxRemoveGrab(wxWindow
* window
)
4200 gtk_grab_remove( (GtkWidget
*) window
->GetHandle() );
4203 // ----------------------------------------------------------------------------
4205 // ----------------------------------------------------------------------------
4207 class wxWinModule
: public wxModule
4214 DECLARE_DYNAMIC_CLASS(wxWinModule
)
4217 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
4219 bool wxWinModule::OnInit()
4221 // g_eraseGC = gdk_gc_new( GDK_ROOT_PARENT() );
4222 // gdk_gc_set_fill( g_eraseGC, GDK_SOLID );
4227 void wxWinModule::OnExit()
4230 gdk_gc_unref( g_eraseGC
);