1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/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"
18 #include "wx/dcclient.h"
21 #include "wx/layout.h"
23 #include "wx/dialog.h"
24 #include "wx/msgdlg.h"
25 #include "wx/module.h"
26 #include "wx/combobox.h"
28 #if wxUSE_DRAG_AND_DROP
33 #include "wx/tooltip.h"
41 #include "wx/textctrl.h"
45 #include "wx/statusbr.h"
47 #include "wx/settings.h"
49 #include "wx/fontutil.h"
52 #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 wxList wxPendingDelete
;
203 extern bool g_blockEventsOnDrag
;
204 extern bool g_blockEventsOnScroll
;
205 extern wxCursor g_globalCursor
;
207 static GdkGC
*g_eraseGC
= NULL
;
209 // mouse capture state: the window which has it and if the mouse is currently
211 static wxWindowGTK
*g_captureWindow
= (wxWindowGTK
*) NULL
;
212 static bool g_captureWindowHasMouse
= false;
214 wxWindowGTK
*g_focusWindow
= (wxWindowGTK
*) NULL
;
216 // the last window which had the focus - this is normally never NULL (except
217 // if we never had focus at all) as even when g_focusWindow is NULL it still
218 // keeps its previous value
219 wxWindowGTK
*g_focusWindowLast
= (wxWindowGTK
*) NULL
;
221 // If a window get the focus set but has not been realized
222 // yet, defer setting the focus to idle time.
223 wxWindowGTK
*g_delayedFocus
= (wxWindowGTK
*) NULL
;
225 // hack: we need something to pass to gtk_menu_popup, so we store the time of
226 // the last click here (extern: used from gtk/menu.cpp)
227 guint32 wxGtkTimeLastClick
= 0;
229 extern bool g_mainThreadLocked
;
231 //-----------------------------------------------------------------------------
233 //-----------------------------------------------------------------------------
238 # define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
240 # define DEBUG_MAIN_THREAD
243 #define DEBUG_MAIN_THREAD
246 // the trace mask used for the focus debugging messages
247 #define TRACE_FOCUS _T("focus")
249 //-----------------------------------------------------------------------------
250 // missing gdk functions
251 //-----------------------------------------------------------------------------
254 gdk_window_warp_pointer (GdkWindow
*window
,
258 GdkWindowPrivate
*priv
;
261 window
= GDK_ROOT_PARENT();
263 priv
= (GdkWindowPrivate
*) window
;
265 if (!priv
->destroyed
)
267 XWarpPointer (priv
->xdisplay
,
268 None
, /* not source window -> move from anywhere */
269 priv
->xwindow
, /* dest window */
270 0, 0, 0, 0, /* not source window -> move from anywhere */
275 //-----------------------------------------------------------------------------
277 //-----------------------------------------------------------------------------
279 extern void wxapp_install_idle_handler();
280 extern bool g_isIdle
;
282 //-----------------------------------------------------------------------------
283 // local code (see below)
284 //-----------------------------------------------------------------------------
286 // returns the child of win which currently has focus or NULL if not found
288 // Note: can't be static, needed by textctrl.cpp.
289 wxWindow
*wxFindFocusedChild(wxWindowGTK
*win
)
291 wxWindow
*winFocus
= wxWindowGTK::FindFocus();
293 return (wxWindow
*)NULL
;
295 if ( winFocus
== win
)
296 return (wxWindow
*)win
;
298 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
300 node
= node
->GetNext() )
302 wxWindow
*child
= wxFindFocusedChild(node
->GetData());
307 return (wxWindow
*)NULL
;
310 static void draw_frame( GtkWidget
*widget
, wxWindowGTK
*win
)
312 // wxUniversal widgets draw the borders and scrollbars themselves
313 #ifndef __WXUNIVERSAL__
320 if (win
->m_hasScrolling
)
322 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(widget
);
324 GtkRequisition vscroll_req
;
325 vscroll_req
.width
= 2;
326 vscroll_req
.height
= 2;
327 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
328 (scroll_window
->vscrollbar
, &vscroll_req
);
330 GtkRequisition hscroll_req
;
331 hscroll_req
.width
= 2;
332 hscroll_req
.height
= 2;
333 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
334 (scroll_window
->hscrollbar
, &hscroll_req
);
336 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(widget
) );
338 if (scroll_window
->vscrollbar_visible
)
340 dw
+= vscroll_req
.width
;
341 dw
+= scroll_class
->scrollbar_spacing
;
344 if (scroll_window
->hscrollbar_visible
)
346 dh
+= hscroll_req
.height
;
347 dh
+= scroll_class
->scrollbar_spacing
;
353 if (GTK_WIDGET_NO_WINDOW (widget
))
355 dx
+= widget
->allocation
.x
;
356 dy
+= widget
->allocation
.y
;
359 if (win
->HasFlag(wxRAISED_BORDER
))
361 gtk_draw_shadow( widget
->style
,
366 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
370 if (win
->HasFlag(wxSUNKEN_BORDER
))
372 gtk_draw_shadow( widget
->style
,
377 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
381 if (win
->HasFlag(wxSIMPLE_BORDER
))
384 gc
= gdk_gc_new( widget
->window
);
385 gdk_gc_set_foreground( gc
, &widget
->style
->black
);
386 gdk_draw_rectangle( widget
->window
, gc
, FALSE
,
388 widget
->allocation
.width
-dw
-1, widget
->allocation
.height
-dh
-1 );
392 #endif // __WXUNIVERSAL__
395 //-----------------------------------------------------------------------------
396 // "expose_event" of m_widget
397 //-----------------------------------------------------------------------------
400 static gint
gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxWindowGTK
*win
)
402 if (gdk_event
->count
> 0) return FALSE
;
404 draw_frame( widget
, win
);
410 //-----------------------------------------------------------------------------
411 // "draw" of m_widget
412 //-----------------------------------------------------------------------------
415 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxWindowGTK
*win
)
417 draw_frame( widget
, win
);
421 //-----------------------------------------------------------------------------
422 // "size_request" of m_widget
423 //-----------------------------------------------------------------------------
425 // make it extern because wxStaticText needs to disconnect this one
427 void wxgtk_window_size_request_callback(GtkWidget
*widget
,
428 GtkRequisition
*requisition
,
432 win
->GetSize( &w
, &h
);
438 requisition
->height
= h
;
439 requisition
->width
= w
;
445 void wxgtk_combo_size_request_callback(GtkWidget
*widget
,
446 GtkRequisition
*requisition
,
449 // This callback is actually hooked into the text entry
450 // of the combo box, not the GtkHBox.
453 win
->GetSize( &w
, &h
);
459 GtkCombo
*gcombo
= GTK_COMBO(win
->m_widget
);
461 GtkRequisition entry_req
;
463 entry_req
.height
= 2;
464 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo
->button
) )->size_request
)
465 (gcombo
->button
, &entry_req
);
467 requisition
->width
= w
- entry_req
.width
;
468 requisition
->height
= entry_req
.height
;
472 //-----------------------------------------------------------------------------
473 // "expose_event" of m_wxwindow
474 //-----------------------------------------------------------------------------
477 static int gtk_window_expose_callback( GtkWidget
*widget
,
478 GdkEventExpose
*gdk_event
,
484 wxapp_install_idle_handler();
486 // This gets called immediately after an expose event
487 // under GTK 1.2 so we collect the calls and wait for
488 // the idle handler to pick things up.
490 win
->GetUpdateRegion().Union( gdk_event
->area
.x
,
492 gdk_event
->area
.width
,
493 gdk_event
->area
.height
);
494 win
->m_clearRegion
.Union( gdk_event
->area
.x
,
496 gdk_event
->area
.width
,
497 gdk_event
->area
.height
);
499 // Actual redrawing takes place in idle time.
506 //-----------------------------------------------------------------------------
507 // "event" of m_wxwindow
508 //-----------------------------------------------------------------------------
510 // GTK thinks it is clever and filters out a certain amount of "unneeded"
511 // expose events. We need them, of course, so we override the main event
512 // procedure in GtkWidget by giving our own handler for all system events.
513 // There, we look for expose events ourselves whereas all other events are
518 gint
gtk_window_event_event_callback( GtkWidget
*widget
,
519 GdkEventExpose
*event
,
522 if (event
->type
== GDK_EXPOSE
)
524 gint ret
= gtk_window_expose_callback( widget
, event
, win
);
532 //-----------------------------------------------------------------------------
533 // "draw" of m_wxwindow
534 //-----------------------------------------------------------------------------
536 // This callback is a complete replacement of the gtk_pizza_draw() function,
537 // which is disabled.
540 static void gtk_window_draw_callback( GtkWidget
*widget
,
547 wxapp_install_idle_handler();
549 // if there are any children we must refresh everything
552 if ( !win
->HasFlag(wxFULL_REPAINT_ON_RESIZE
) &&
553 win
->GetChildren().IsEmpty() )
561 wxPrintf( wxT("OnDraw from ") );
562 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
563 wxPrintf( win
->GetClassInfo()->GetClassName() );
564 wxPrintf( wxT(" %d %d %d %d\n"), (int)rect
->x
,
571 #ifndef __WXUNIVERSAL__
572 GtkPizza
*pizza
= GTK_PIZZA (widget
);
574 if (win
->GetThemeEnabled() && win
->GetBackgroundStyle() == wxBG_STYLE_SYSTEM
)
576 wxWindow
*parent
= win
->GetParent();
577 while (parent
&& !parent
->IsTopLevel())
578 parent
= parent
->GetParent();
582 gtk_paint_flat_box (parent
->m_widget
->style
,
593 win
->m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
594 win
->GetUpdateRegion().Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
596 // Update immediately, not in idle time.
599 #ifndef __WXUNIVERSAL__
600 // Redraw child widgets
601 GList
*children
= pizza
->children
;
604 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
605 children
= children
->next
;
607 GdkRectangle child_area
;
608 if (gtk_widget_intersect (child
->widget
, rect
, &child_area
))
610 gtk_widget_draw (child
->widget
, &child_area
/* (GdkRectangle*) NULL*/ );
617 //-----------------------------------------------------------------------------
618 // "key_press_event" from any window
619 //-----------------------------------------------------------------------------
621 // set WXTRACE to this to see the key event codes on the console
622 #define TRACE_KEYS _T("keyevent")
624 // translates an X key symbol to WXK_XXX value
626 // if isChar is true it means that the value returned will be used for EVT_CHAR
627 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
628 // for example, while if it is false it means that the value is going to be
629 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
631 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
637 // Shift, Control and Alt don't generate the CHAR events at all
640 key_code
= isChar
? 0 : WXK_SHIFT
;
644 key_code
= isChar
? 0 : WXK_CONTROL
;
652 key_code
= isChar
? 0 : WXK_ALT
;
655 // neither do the toggle modifies
656 case GDK_Scroll_Lock
:
657 key_code
= isChar
? 0 : WXK_SCROLL
;
661 key_code
= isChar
? 0 : WXK_CAPITAL
;
665 key_code
= isChar
? 0 : WXK_NUMLOCK
;
669 // various other special keys
682 case GDK_ISO_Left_Tab
:
689 key_code
= WXK_RETURN
;
693 key_code
= WXK_CLEAR
;
697 key_code
= WXK_PAUSE
;
701 key_code
= WXK_SELECT
;
705 key_code
= WXK_PRINT
;
709 key_code
= WXK_EXECUTE
;
713 key_code
= WXK_ESCAPE
;
716 // cursor and other extended keyboard keys
718 key_code
= WXK_DELETE
;
734 key_code
= WXK_RIGHT
;
741 case GDK_Prior
: // == GDK_Page_Up
742 key_code
= WXK_PRIOR
;
745 case GDK_Next
: // == GDK_Page_Down
758 key_code
= WXK_INSERT
;
773 key_code
= (isChar
? '0' : WXK_NUMPAD0
) + keysym
- GDK_KP_0
;
777 key_code
= isChar
? ' ' : WXK_NUMPAD_SPACE
;
781 key_code
= isChar
? WXK_TAB
: WXK_NUMPAD_TAB
;
785 key_code
= isChar
? WXK_RETURN
: WXK_NUMPAD_ENTER
;
789 key_code
= isChar
? WXK_F1
: WXK_NUMPAD_F1
;
793 key_code
= isChar
? WXK_F2
: WXK_NUMPAD_F2
;
797 key_code
= isChar
? WXK_F3
: WXK_NUMPAD_F3
;
801 key_code
= isChar
? WXK_F4
: WXK_NUMPAD_F4
;
805 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_HOME
;
809 key_code
= isChar
? WXK_LEFT
: WXK_NUMPAD_LEFT
;
813 key_code
= isChar
? WXK_UP
: WXK_NUMPAD_UP
;
817 key_code
= isChar
? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
821 key_code
= isChar
? WXK_DOWN
: WXK_NUMPAD_DOWN
;
824 case GDK_KP_Prior
: // == GDK_KP_Page_Up
825 key_code
= isChar
? WXK_PRIOR
: WXK_NUMPAD_PRIOR
;
828 case GDK_KP_Next
: // == GDK_KP_Page_Down
829 key_code
= isChar
? WXK_NEXT
: WXK_NUMPAD_NEXT
;
833 key_code
= isChar
? WXK_END
: WXK_NUMPAD_END
;
837 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_BEGIN
;
841 key_code
= isChar
? WXK_INSERT
: WXK_NUMPAD_INSERT
;
845 key_code
= isChar
? WXK_DELETE
: WXK_NUMPAD_DELETE
;
849 key_code
= isChar
? '=' : WXK_NUMPAD_EQUAL
;
852 case GDK_KP_Multiply
:
853 key_code
= isChar
? '*' : WXK_NUMPAD_MULTIPLY
;
857 key_code
= isChar
? '+' : WXK_NUMPAD_ADD
;
860 case GDK_KP_Separator
:
861 // FIXME: what is this?
862 key_code
= isChar
? '.' : WXK_NUMPAD_SEPARATOR
;
865 case GDK_KP_Subtract
:
866 key_code
= isChar
? '-' : WXK_NUMPAD_SUBTRACT
;
870 key_code
= isChar
? '.' : WXK_NUMPAD_DECIMAL
;
874 key_code
= isChar
? '/' : WXK_NUMPAD_DIVIDE
;
891 key_code
= WXK_F1
+ keysym
- GDK_F1
;
901 static inline bool wxIsAsciiKeysym(KeySym ks
)
906 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
908 GdkEventKey
*gdk_event
)
912 GdkModifierType state
;
913 if (gdk_event
->window
)
914 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
916 event
.SetTimestamp( gdk_event
->time
);
917 event
.SetId(win
->GetId());
918 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
919 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
920 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
921 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
) != 0;
922 event
.m_scanCode
= gdk_event
->keyval
;
923 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
924 event
.m_rawFlags
= 0;
926 event
.m_uniChar
= gdk_keyval_to_unicode(gdk_event
->keyval
);
928 wxGetMousePosition( &x
, &y
);
929 win
->ScreenToClient( &x
, &y
);
932 event
.SetEventObject( win
);
937 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
939 GdkEventKey
*gdk_event
)
941 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
942 // but only event->keyval which is quite useless to us, so remember
943 // the last character from GDK_KEY_PRESS and reuse it as last resort
945 // NB: should be MT-safe as we're always called from the main thread only
950 } s_lastKeyPress
= { 0, 0 };
952 KeySym keysym
= gdk_event
->keyval
;
954 wxLogTrace(TRACE_KEYS
, _T("Key %s event: keysym = %ld"),
955 event
.GetEventType() == wxEVT_KEY_UP
? _T("release")
959 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
963 // do we have the translation or is it a plain ASCII character?
964 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
966 // we should use keysym if it is ASCII as X does some translations
967 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
968 // which we don't want here (but which we do use for OnChar())
969 if ( !wxIsAsciiKeysym(keysym
) )
971 keysym
= (KeySym
)gdk_event
->string
[0];
974 // we want to always get the same key code when the same key is
975 // pressed regardless of the state of the modifiers, i.e. on a
976 // standard US keyboard pressing '5' or '%' ('5' key with
977 // Shift) should result in the same key code in OnKeyDown():
978 // '5' (although OnChar() will get either '5' or '%').
980 // to do it we first translate keysym to keycode (== scan code)
981 // and then back but always using the lower register
982 Display
*dpy
= (Display
*)wxGetDisplay();
983 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
985 wxLogTrace(TRACE_KEYS
, _T("\t-> keycode %d"), keycode
);
987 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
989 // use the normalized, i.e. lower register, keysym if we've
991 key_code
= keysymNormalized
? keysymNormalized
: keysym
;
993 // as explained above, we want to have lower register key codes
994 // normally but for the letter keys we want to have the upper ones
996 // NB: don't use XConvertCase() here, we want to do it for letters
998 key_code
= toupper(key_code
);
1000 else // non ASCII key, what to do?
1002 // by default, ignore it
1005 // but if we have cached information from the last KEY_PRESS
1006 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
1009 if ( keysym
== s_lastKeyPress
.keysym
)
1011 key_code
= s_lastKeyPress
.keycode
;
1016 if ( gdk_event
->type
== GDK_KEY_PRESS
)
1018 // remember it to be reused for KEY_UP event later
1019 s_lastKeyPress
.keysym
= keysym
;
1020 s_lastKeyPress
.keycode
= key_code
;
1024 wxLogTrace(TRACE_KEYS
, _T("\t-> wxKeyCode %ld"), key_code
);
1026 // sending unknown key events doesn't really make sense
1030 // now fill all the other fields
1031 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
1033 event
.m_keyCode
= key_code
;
1040 static gint
gtk_window_key_press_callback( GtkWidget
*widget
,
1041 GdkEventKey
*gdk_event
,
1047 wxapp_install_idle_handler();
1051 if (g_blockEventsOnDrag
)
1055 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1057 bool return_after_IM
= false;
1059 if( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) == false )
1061 // Return after IM processing as we cannot do
1062 // anything with it anyhow.
1063 return_after_IM
= true;
1066 if (return_after_IM
)
1069 // Emit KEY_DOWN event
1070 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1072 // This is for GTK+ 1.2 only. The char event generatation for GTK+ 2.0 is done
1073 // in the "commit" handler.
1075 // 2005.02.02 modified by Hong Jen Yee (hzysoft@sina.com.tw).
1076 // In GTK+ 1.2, strings sent by IMs are also regarded as key_press events whose
1077 // keyCodes cannot be recognized by wxWidgets. These MBCS strings, however, are
1078 // composed of more than one character, which means gdk_event->length will always
1079 // greater than one. When gtk_event->length == 1, this may be an ASCII character
1080 // and can be translated by wx. However, when MBCS characters are sent by IM,
1081 // gdk_event->length will >= 2. So neither should we pass it to accelerator table,
1082 // nor should we pass it to controls. The following explanation was excerpted
1083 // from GDK documentation.
1084 // gint length : the length of string.
1085 // gchar *string : a null-terminated multi-byte string containing the composed
1086 // characters resulting from the key press. When text is being input, in a GtkEntry
1087 // for example, it is these characters which should be added to the input buffer.
1088 // When using Input Methods to support internationalized text input, the composed
1089 // characters appear here after the pre-editing has been completed.
1091 if ( (!ret
) && (gdk_event
->length
> 1) ) // If this event contains a pre-edited string from IM.
1093 // We should translate this key event into wxEVT_CHAR not wxEVT_KEY_DOWN.
1094 #if wxUSE_UNICODE // GTK+ 1.2 is not UTF-8 based.
1095 const wxWCharBuffer string
= wxConvLocal
.cMB2WC( gdk_event
->string
);
1099 const char* string
= gdk_event
->string
;
1102 // Implement OnCharHook by checking ancestor top level windows
1103 wxWindow
*parent
= win
;
1104 while (parent
&& !parent
->IsTopLevel())
1105 parent
= parent
->GetParent();
1107 for( const wxChar
* pstr
= string
; *pstr
; pstr
++ )
1110 event
.m_uniChar
= *pstr
;
1111 // Backward compatible for ISO-8859-1
1112 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1114 event
.m_keyCode
= *pstr
;
1118 event
.SetEventType( wxEVT_CHAR_HOOK
);
1119 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1123 event
.SetEventType(wxEVT_CHAR
);
1124 win
->GetEventHandler()->ProcessEvent( event
);
1133 wxWindowGTK
*ancestor
= win
;
1136 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1139 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1140 ret
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1143 if (ancestor
->IsTopLevel())
1145 ancestor
= ancestor
->GetParent();
1148 #endif // wxUSE_ACCEL
1150 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
1151 // will only be sent if it is not in an accelerator table.
1155 KeySym keysym
= gdk_event
->keyval
;
1156 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
1157 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
1160 if ( wxIsAsciiKeysym(keysym
) )
1163 key_code
= (unsigned char)keysym
;
1165 // gdk_event->string is actually deprecated
1166 else if ( gdk_event
->length
== 1 )
1168 key_code
= (unsigned char)gdk_event
->string
[0];
1174 wxLogTrace(TRACE_KEYS
, _T("Char event: %ld"), key_code
);
1176 event
.m_keyCode
= key_code
;
1178 // Implement OnCharHook by checking ancestor top level windows
1179 wxWindow
*parent
= win
;
1180 while (parent
&& !parent
->IsTopLevel())
1181 parent
= parent
->GetParent();
1184 event
.SetEventType( wxEVT_CHAR_HOOK
);
1185 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1190 event
.SetEventType(wxEVT_CHAR
);
1191 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1200 // win is a control: tab can be propagated up
1202 ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
)) &&
1203 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here - the control may
1204 // have this style, yet choose not to process this particular TAB in which
1205 // case TAB must still work as a navigational character
1206 // JS: enabling again to make consistent with other platforms
1207 // (with wxTE_PROCESS_TAB you have to call Navigate to get default
1208 // navigation behaviour)
1210 (! (win
->HasFlag(wxTE_PROCESS_TAB
) && win
->IsKindOf(CLASSINFO(wxTextCtrl
)) )) &&
1212 win
->GetParent() && (win
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1214 wxNavigationKeyEvent new_event
;
1215 new_event
.SetEventObject( win
->GetParent() );
1216 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
1217 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
1218 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
1219 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
1220 new_event
.SetCurrentFocus( win
);
1221 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent( new_event
);
1224 // generate wxID_CANCEL if <esc> has been pressed (typically in dialogs)
1226 (gdk_event
->keyval
== GDK_Escape
) )
1228 // however only do it if we have a Cancel button in the dialog,
1229 // otherwise the user code may get confused by the events from a
1230 // non-existing button and, worse, a wxButton might get button event
1231 // from another button which is not really expected
1232 wxWindow
*winForCancel
= win
,
1234 while ( winForCancel
)
1236 btnCancel
= winForCancel
->FindWindow(wxID_CANCEL
);
1239 // found a cancel button
1243 if ( winForCancel
->IsTopLevel() )
1245 // no need to look further
1249 // maybe our parent has a cancel button?
1250 winForCancel
= winForCancel
->GetParent();
1255 wxCommandEvent
eventClick(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
1256 eventClick
.SetEventObject(btnCancel
);
1257 ret
= btnCancel
->GetEventHandler()->ProcessEvent(eventClick
);
1263 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
1271 //-----------------------------------------------------------------------------
1272 // "key_release_event" from any window
1273 //-----------------------------------------------------------------------------
1276 static gint
gtk_window_key_release_callback( GtkWidget
*widget
,
1277 GdkEventKey
*gdk_event
,
1283 wxapp_install_idle_handler();
1288 if (g_blockEventsOnDrag
)
1291 wxKeyEvent
event( wxEVT_KEY_UP
);
1292 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1294 // unknown key pressed, ignore (the event would be useless anyhow)
1298 if ( !win
->GetEventHandler()->ProcessEvent( event
) )
1301 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_release_event" );
1306 // ============================================================================
1308 // ============================================================================
1310 // ----------------------------------------------------------------------------
1311 // mouse event processing helpers
1312 // ----------------------------------------------------------------------------
1314 // init wxMouseEvent with the info from GdkEventXXX struct
1315 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1316 wxMouseEvent
& event
,
1319 event
.SetTimestamp( gdk_event
->time
);
1320 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1321 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1322 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1323 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1324 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1325 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1326 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1327 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
1329 event
.m_linesPerAction
= 3;
1330 event
.m_wheelDelta
= 120;
1331 if (((GdkEventButton
*)gdk_event
)->button
== 4)
1332 event
.m_wheelRotation
= 120;
1333 else if (((GdkEventButton
*)gdk_event
)->button
== 5)
1334 event
.m_wheelRotation
= -120;
1337 wxPoint pt
= win
->GetClientAreaOrigin();
1338 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1339 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1341 event
.SetEventObject( win
);
1342 event
.SetId( win
->GetId() );
1343 event
.SetTimestamp( gdk_event
->time
);
1346 static void AdjustEventButtonState(wxMouseEvent
& event
)
1348 // GDK reports the old state of the button for a button press event, but
1349 // for compatibility with MSW and common sense we want m_leftDown be TRUE
1350 // for a LEFT_DOWN event, not FALSE, so we will invert
1351 // left/right/middleDown for the corresponding click events
1353 if ((event
.GetEventType() == wxEVT_LEFT_DOWN
) ||
1354 (event
.GetEventType() == wxEVT_LEFT_DCLICK
) ||
1355 (event
.GetEventType() == wxEVT_LEFT_UP
))
1357 event
.m_leftDown
= !event
.m_leftDown
;
1361 if ((event
.GetEventType() == wxEVT_MIDDLE_DOWN
) ||
1362 (event
.GetEventType() == wxEVT_MIDDLE_DCLICK
) ||
1363 (event
.GetEventType() == wxEVT_MIDDLE_UP
))
1365 event
.m_middleDown
= !event
.m_middleDown
;
1369 if ((event
.GetEventType() == wxEVT_RIGHT_DOWN
) ||
1370 (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) ||
1371 (event
.GetEventType() == wxEVT_RIGHT_UP
))
1373 event
.m_rightDown
= !event
.m_rightDown
;
1378 // find the window to send the mouse event too
1380 wxWindowGTK
*FindWindowForMouseEvent(wxWindowGTK
*win
, wxCoord
& x
, wxCoord
& y
)
1385 if (win
->m_wxwindow
)
1387 GtkPizza
*pizza
= GTK_PIZZA(win
->m_wxwindow
);
1388 xx
+= pizza
->xoffset
;
1389 yy
+= pizza
->yoffset
;
1392 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
1395 wxWindowGTK
*child
= node
->GetData();
1397 node
= node
->GetNext();
1398 if (!child
->IsShown())
1401 if (child
->IsTransparentForMouse())
1403 // wxStaticBox is transparent in the box itself
1404 int xx1
= child
->m_x
;
1405 int yy1
= child
->m_y
;
1406 int xx2
= child
->m_x
+ child
->m_width
;
1407 int yy2
= child
->m_y
+ child
->m_height
;
1410 if (((xx
>= xx1
) && (xx
<= xx1
+10) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1412 ((xx
>= xx2
-10) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1414 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy1
+10)) ||
1416 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy2
-1) && (yy
<= yy2
)))
1427 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1428 (child
->m_x
<= xx
) &&
1429 (child
->m_y
<= yy
) &&
1430 (child
->m_x
+child
->m_width
>= xx
) &&
1431 (child
->m_y
+child
->m_height
>= yy
))
1444 //-----------------------------------------------------------------------------
1445 // "button_press_event"
1446 //-----------------------------------------------------------------------------
1449 static gint
gtk_window_button_press_callback( GtkWidget
*widget
,
1450 GdkEventButton
*gdk_event
,
1456 wxapp_install_idle_handler();
1459 wxPrintf( wxT("1) OnButtonPress from ") );
1460 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1461 wxPrintf( win->GetClassInfo()->GetClassName() );
1462 wxPrintf( wxT(".\n") );
1464 if (!win
->m_hasVMT
) return FALSE
;
1465 if (g_blockEventsOnDrag
) return TRUE
;
1466 if (g_blockEventsOnScroll
) return TRUE
;
1468 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1470 if (win
->m_wxwindow
&& (g_focusWindow
!= win
) && win
->AcceptsFocus())
1472 gtk_widget_grab_focus( win
->m_wxwindow
);
1474 wxPrintf( wxT("GrabFocus from ") );
1475 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1476 wxPrintf( win->GetClassInfo()->GetClassName() );
1477 wxPrintf( wxT(".\n") );
1481 // GDK sends surplus button down events
1482 // before a double click event. We
1483 // need to filter these out.
1484 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1486 GdkEvent
*peek_event
= gdk_event_peek();
1489 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1490 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1492 gdk_event_free( peek_event
);
1497 gdk_event_free( peek_event
);
1502 wxEventType event_type
= wxEVT_NULL
;
1504 if (gdk_event
->button
== 1)
1506 // note that GDK generates triple click events which are not supported
1507 // by wxWidgets but still have to be passed to the app as otherwise
1508 // clicks would simply go missing
1509 switch (gdk_event
->type
)
1511 // we shouldn't get triple clicks at all for GTK2 because we
1512 // suppress them artificially using the code above but we still
1513 // should map them to something for GTK1 and not just ignore them
1514 // as this would lose clicks
1515 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1516 case GDK_BUTTON_PRESS
:
1517 event_type
= wxEVT_LEFT_DOWN
;
1520 case GDK_2BUTTON_PRESS
:
1521 event_type
= wxEVT_LEFT_DCLICK
;
1525 // just to silence gcc warnings
1529 else if (gdk_event
->button
== 2)
1531 switch (gdk_event
->type
)
1533 case GDK_3BUTTON_PRESS
:
1534 case GDK_BUTTON_PRESS
:
1535 event_type
= wxEVT_MIDDLE_DOWN
;
1538 case GDK_2BUTTON_PRESS
:
1539 event_type
= wxEVT_MIDDLE_DCLICK
;
1546 else if (gdk_event
->button
== 3)
1548 switch (gdk_event
->type
)
1550 case GDK_3BUTTON_PRESS
:
1551 case GDK_BUTTON_PRESS
:
1552 event_type
= wxEVT_RIGHT_DOWN
;
1555 case GDK_2BUTTON_PRESS
:
1556 event_type
= wxEVT_RIGHT_DCLICK
;
1563 else if (gdk_event
->button
== 4 || gdk_event
->button
== 5)
1565 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1567 event_type
= wxEVT_MOUSEWHEEL
;
1571 if ( event_type
== wxEVT_NULL
)
1573 // unknown mouse button or click type
1577 wxMouseEvent
event( event_type
);
1578 InitMouseEvent( win
, event
, gdk_event
);
1580 AdjustEventButtonState(event
);
1582 // wxListBox actually gets mouse events from the item, so we need to give it
1583 // a chance to correct this
1584 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1586 // find the correct window to send the event to: it may be a different one
1587 // from the one which got it at GTK+ level because some controls don't have
1588 // their own X window and thus cannot get any events.
1589 if ( !g_captureWindow
)
1590 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1592 wxGtkTimeLastClick
= gdk_event
->time
;
1594 if (event_type
== wxEVT_LEFT_DCLICK
)
1596 // GTK 1.2 crashes when intercepting double
1597 // click events from both wxSpinButton and
1599 if (GTK_IS_SPIN_BUTTON(win
->m_widget
))
1601 // Just disable this event for now.
1606 if (win
->GetEventHandler()->ProcessEvent( event
))
1608 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_press_event" );
1612 if (event_type
== wxEVT_RIGHT_DOWN
)
1614 // generate a "context menu" event: this is similar to right mouse
1615 // click under many GUIs except that it is generated differently
1616 // (right up under MSW, ctrl-click under Mac, right down here) and
1618 // (a) it's a command event and so is propagated to the parent
1619 // (b) under some ports it can be generated from kbd too
1620 // (c) it uses screen coords (because of (a))
1621 wxContextMenuEvent
evtCtx(
1624 win
->ClientToScreen(event
.GetPosition()));
1625 evtCtx
.SetEventObject(win
);
1626 return win
->GetEventHandler()->ProcessEvent(evtCtx
);
1633 //-----------------------------------------------------------------------------
1634 // "button_release_event"
1635 //-----------------------------------------------------------------------------
1638 static gint
gtk_window_button_release_callback( GtkWidget
*widget
,
1639 GdkEventButton
*gdk_event
,
1645 wxapp_install_idle_handler();
1647 if (!win
->m_hasVMT
) return FALSE
;
1648 if (g_blockEventsOnDrag
) return FALSE
;
1649 if (g_blockEventsOnScroll
) return FALSE
;
1651 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1653 wxEventType event_type
= wxEVT_NULL
;
1655 switch (gdk_event
->button
)
1658 event_type
= wxEVT_LEFT_UP
;
1662 event_type
= wxEVT_MIDDLE_UP
;
1666 event_type
= wxEVT_RIGHT_UP
;
1670 // unknwon button, don't process
1674 wxMouseEvent
event( event_type
);
1675 InitMouseEvent( win
, event
, gdk_event
);
1677 AdjustEventButtonState(event
);
1679 // same wxListBox hack as above
1680 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1682 if ( !g_captureWindow
)
1683 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1685 if (win
->GetEventHandler()->ProcessEvent( event
))
1687 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_release_event" );
1695 //-----------------------------------------------------------------------------
1696 // "motion_notify_event"
1697 //-----------------------------------------------------------------------------
1700 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
,
1701 GdkEventMotion
*gdk_event
,
1707 wxapp_install_idle_handler();
1709 if (!win
->m_hasVMT
) return FALSE
;
1710 if (g_blockEventsOnDrag
) return FALSE
;
1711 if (g_blockEventsOnScroll
) return FALSE
;
1713 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1715 if (gdk_event
->is_hint
)
1719 GdkModifierType state
;
1720 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1726 printf( "OnMotion from " );
1727 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1728 printf( win->GetClassInfo()->GetClassName() );
1732 wxMouseEvent
event( wxEVT_MOTION
);
1733 InitMouseEvent(win
, event
, gdk_event
);
1735 if ( g_captureWindow
)
1737 // synthetize a mouse enter or leave event if needed
1738 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1739 // This seems to be necessary and actually been added to
1740 // GDK itself in version 2.0.X
1743 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1744 if ( hasMouse
!= g_captureWindowHasMouse
)
1746 // the mouse changed window
1747 g_captureWindowHasMouse
= hasMouse
;
1749 wxMouseEvent
eventM(g_captureWindowHasMouse
? wxEVT_ENTER_WINDOW
1750 : wxEVT_LEAVE_WINDOW
);
1751 InitMouseEvent(win
, eventM
, gdk_event
);
1752 eventM
.SetEventObject(win
);
1753 win
->GetEventHandler()->ProcessEvent(eventM
);
1758 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1761 if (win
->GetEventHandler()->ProcessEvent( event
))
1763 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "motion_notify_event" );
1771 //-----------------------------------------------------------------------------
1773 //-----------------------------------------------------------------------------
1775 // send the wxChildFocusEvent and wxFocusEvent, common code of
1776 // gtk_window_focus_in_callback() and SetFocus()
1777 static bool DoSendFocusEvents(wxWindow
*win
)
1779 // Notify the parent keeping track of focus for the kbd navigation
1780 // purposes that we got it.
1781 wxChildFocusEvent
eventChildFocus(win
);
1782 (void)win
->GetEventHandler()->ProcessEvent(eventChildFocus
);
1784 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, win
->GetId());
1785 eventFocus
.SetEventObject(win
);
1787 return win
->GetEventHandler()->ProcessEvent(eventFocus
);
1791 static gint
gtk_window_focus_in_callback( GtkWidget
*widget
,
1792 GdkEvent
*WXUNUSED(event
),
1798 wxapp_install_idle_handler();
1801 g_focusWindow
= win
;
1803 wxLogTrace(TRACE_FOCUS
,
1804 _T("%s: focus in"), win
->GetName().c_str());
1808 gdk_im_begin(win
->m_ic
, win
->m_wxwindow
->window
);
1812 // caret needs to be informed about focus change
1813 wxCaret
*caret
= win
->GetCaret();
1816 caret
->OnSetFocus();
1818 #endif // wxUSE_CARET
1820 // does the window itself think that it has the focus?
1821 if ( !win
->m_hasFocus
)
1823 // not yet, notify it
1824 win
->m_hasFocus
= true;
1826 if ( DoSendFocusEvents(win
) )
1828 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_in_event" );
1837 //-----------------------------------------------------------------------------
1838 // "focus_out_event"
1839 //-----------------------------------------------------------------------------
1842 static gint
gtk_window_focus_out_callback( GtkWidget
*widget
, GdkEventFocus
*gdk_event
, wxWindowGTK
*win
)
1847 wxapp_install_idle_handler();
1849 wxLogTrace( TRACE_FOCUS
,
1850 _T("%s: focus out"), win
->GetName().c_str() );
1853 wxWindowGTK
*winFocus
= wxFindFocusedChild(win
);
1857 g_focusWindow
= (wxWindowGTK
*)NULL
;
1865 // caret needs to be informed about focus change
1866 wxCaret
*caret
= win
->GetCaret();
1869 caret
->OnKillFocus();
1871 #endif // wxUSE_CARET
1873 // don't send the window a kill focus event if it thinks that it doesn't
1874 // have focus already
1875 if ( win
->m_hasFocus
)
1877 win
->m_hasFocus
= false;
1879 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
1880 event
.SetEventObject( win
);
1882 // even if we did process the event in wx code, still let GTK itself
1883 // process it too as otherwise bad things happen, especially in GTK2
1884 // where the text control simply aborts the program if it doesn't get
1885 // the matching focus out event
1886 (void)win
->GetEventHandler()->ProcessEvent( event
);
1893 //-----------------------------------------------------------------------------
1894 // "enter_notify_event"
1895 //-----------------------------------------------------------------------------
1899 gint
gtk_window_enter_callback( GtkWidget
*widget
,
1900 GdkEventCrossing
*gdk_event
,
1906 wxapp_install_idle_handler();
1908 if (!win
->m_hasVMT
) return FALSE
;
1909 if (g_blockEventsOnDrag
) return FALSE
;
1911 // Event was emitted after a grab
1912 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1914 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1918 GdkModifierType state
= (GdkModifierType
)0;
1920 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1922 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
1923 InitMouseEvent(win
, event
, gdk_event
);
1924 wxPoint pt
= win
->GetClientAreaOrigin();
1925 event
.m_x
= x
+ pt
.x
;
1926 event
.m_y
= y
+ pt
.y
;
1928 if (win
->GetEventHandler()->ProcessEvent( event
))
1930 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "enter_notify_event" );
1938 //-----------------------------------------------------------------------------
1939 // "leave_notify_event"
1940 //-----------------------------------------------------------------------------
1943 static gint
gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindowGTK
*win
)
1948 wxapp_install_idle_handler();
1950 if (!win
->m_hasVMT
) return FALSE
;
1951 if (g_blockEventsOnDrag
) return FALSE
;
1953 // Event was emitted after an ungrab
1954 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1956 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1958 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
1959 event
.SetTimestamp( gdk_event
->time
);
1960 event
.SetEventObject( win
);
1964 GdkModifierType state
= (GdkModifierType
)0;
1966 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1968 event
.m_shiftDown
= (state
& GDK_SHIFT_MASK
) != 0;
1969 event
.m_controlDown
= (state
& GDK_CONTROL_MASK
) != 0;
1970 event
.m_altDown
= (state
& GDK_MOD1_MASK
) != 0;
1971 event
.m_metaDown
= (state
& GDK_MOD2_MASK
) != 0;
1972 event
.m_leftDown
= (state
& GDK_BUTTON1_MASK
) != 0;
1973 event
.m_middleDown
= (state
& GDK_BUTTON2_MASK
) != 0;
1974 event
.m_rightDown
= (state
& GDK_BUTTON3_MASK
) != 0;
1976 wxPoint pt
= win
->GetClientAreaOrigin();
1977 event
.m_x
= x
+ pt
.x
;
1978 event
.m_y
= y
+ pt
.y
;
1980 if (win
->GetEventHandler()->ProcessEvent( event
))
1982 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "leave_notify_event" );
1990 //-----------------------------------------------------------------------------
1991 // "value_changed" from m_vAdjust
1992 //-----------------------------------------------------------------------------
1995 static void gtk_window_vscroll_callback( GtkAdjustment
*adjust
,
2002 wxapp_install_idle_handler();
2004 if (g_blockEventsOnDrag
) return;
2006 if (!win
->m_hasVMT
) return;
2008 float diff
= adjust
->value
- win
->m_oldVerticalPos
;
2009 if (fabs(diff
) < 0.2) return;
2011 win
->m_oldVerticalPos
= adjust
->value
;
2013 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2014 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->vscrollbar
));
2016 int value
= (int)(adjust
->value
+0.5);
2018 wxScrollWinEvent
event( command
, value
, wxVERTICAL
);
2019 event
.SetEventObject( win
);
2020 win
->GetEventHandler()->ProcessEvent( event
);
2024 //-----------------------------------------------------------------------------
2025 // "value_changed" from m_hAdjust
2026 //-----------------------------------------------------------------------------
2029 static void gtk_window_hscroll_callback( GtkAdjustment
*adjust
,
2036 wxapp_install_idle_handler();
2038 if (g_blockEventsOnDrag
) return;
2039 if (!win
->m_hasVMT
) return;
2041 float diff
= adjust
->value
- win
->m_oldHorizontalPos
;
2042 if (fabs(diff
) < 0.2) return;
2044 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2045 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->hscrollbar
));
2047 win
->m_oldHorizontalPos
= adjust
->value
;
2049 int value
= (int)(adjust
->value
+0.5);
2051 wxScrollWinEvent
event( command
, value
, wxHORIZONTAL
);
2052 event
.SetEventObject( win
);
2053 win
->GetEventHandler()->ProcessEvent( event
);
2057 //-----------------------------------------------------------------------------
2058 // "button_press_event" from scrollbar
2059 //-----------------------------------------------------------------------------
2062 static gint
gtk_scrollbar_button_press_callback( GtkRange
*widget
,
2063 GdkEventButton
*gdk_event
,
2069 wxapp_install_idle_handler();
2072 g_blockEventsOnScroll
= true;
2074 // FIXME: there is no 'slider' field in GTK+ 2.0 any more
2075 win
->m_isScrolling
= (gdk_event
->window
== widget
->slider
);
2081 //-----------------------------------------------------------------------------
2082 // "button_release_event" from scrollbar
2083 //-----------------------------------------------------------------------------
2086 static gint
gtk_scrollbar_button_release_callback( GtkRange
*widget
,
2087 GdkEventButton
*WXUNUSED(gdk_event
),
2092 // don't test here as we can release the mouse while being over
2093 // a different window than the slider
2095 // if (gdk_event->window != widget->slider) return FALSE;
2097 g_blockEventsOnScroll
= false;
2099 if (win
->m_isScrolling
)
2101 wxEventType command
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2105 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2106 if (widget
== GTK_RANGE(scrolledWindow
->hscrollbar
))
2108 value
= (int)(win
->m_hAdjust
->value
+0.5);
2111 if (widget
== GTK_RANGE(scrolledWindow
->vscrollbar
))
2113 value
= (int)(win
->m_vAdjust
->value
+0.5);
2117 wxScrollWinEvent
event( command
, value
, dir
);
2118 event
.SetEventObject( win
);
2119 win
->GetEventHandler()->ProcessEvent( event
);
2122 win
->m_isScrolling
= false;
2128 // ----------------------------------------------------------------------------
2129 // this wxWindowBase function is implemented here (in platform-specific file)
2130 // because it is static and so couldn't be made virtual
2131 // ----------------------------------------------------------------------------
2133 wxWindow
*wxWindowBase::DoFindFocus()
2135 // the cast is necessary when we compile in wxUniversal mode
2136 return (wxWindow
*)g_focusWindow
;
2139 //-----------------------------------------------------------------------------
2140 // "realize" from m_widget
2141 //-----------------------------------------------------------------------------
2143 /* We cannot set colours and fonts before the widget has
2144 been realized, so we do this directly after realization. */
2148 gtk_window_realized_callback( GtkWidget
*m_widget
, wxWindow
*win
)
2153 wxapp_install_idle_handler();
2155 wxWindowCreateEvent
event( win
);
2156 event
.SetEventObject( win
);
2157 win
->GetEventHandler()->ProcessEvent( event
);
2163 //-----------------------------------------------------------------------------
2165 //-----------------------------------------------------------------------------
2169 void gtk_window_size_callback( GtkWidget
*WXUNUSED(widget
),
2170 GtkAllocation
*WXUNUSED(alloc
),
2174 wxapp_install_idle_handler();
2176 if (!win
->m_hasScrolling
) return;
2178 int client_width
= 0;
2179 int client_height
= 0;
2180 win
->GetClientSize( &client_width
, &client_height
);
2181 if ((client_width
== win
->m_oldClientWidth
) && (client_height
== win
->m_oldClientHeight
))
2184 win
->m_oldClientWidth
= client_width
;
2185 win
->m_oldClientHeight
= client_height
;
2187 if (!win
->m_nativeSizeEvent
)
2189 wxSizeEvent
event( win
->GetSize(), win
->GetId() );
2190 event
.SetEventObject( win
);
2191 win
->GetEventHandler()->ProcessEvent( event
);
2198 #define WXUNUSED_UNLESS_XIM(param) param
2200 #define WXUNUSED_UNLESS_XIM(param) WXUNUSED(param)
2203 /* Resize XIM window */
2207 void gtk_wxwindow_size_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2208 GtkAllocation
* WXUNUSED_UNLESS_XIM(alloc
),
2209 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2212 wxapp_install_idle_handler();
2218 if (gdk_ic_get_style (win
->m_ic
) & GDK_IM_PREEDIT_POSITION
)
2222 gdk_window_get_size (widget
->window
, &width
, &height
);
2223 win
->m_icattr
->preedit_area
.width
= width
;
2224 win
->m_icattr
->preedit_area
.height
= height
;
2225 gdk_ic_set_attr (win
->m_ic
, win
->m_icattr
, GDK_IC_PREEDIT_AREA
);
2231 //-----------------------------------------------------------------------------
2232 // "realize" from m_wxwindow
2233 //-----------------------------------------------------------------------------
2235 /* Initialize XIM support */
2239 gtk_wxwindow_realized_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2240 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2243 wxapp_install_idle_handler();
2246 if (win
->m_ic
) return FALSE
;
2247 if (!widget
) return FALSE
;
2248 if (!gdk_im_ready()) return FALSE
;
2250 win
->m_icattr
= gdk_ic_attr_new();
2251 if (!win
->m_icattr
) return FALSE
;
2255 GdkColormap
*colormap
;
2256 GdkICAttr
*attr
= win
->m_icattr
;
2257 unsigned attrmask
= GDK_IC_ALL_REQ
;
2259 GdkIMStyle supported_style
= (GdkIMStyle
)
2260 (GDK_IM_PREEDIT_NONE
|
2261 GDK_IM_PREEDIT_NOTHING
|
2262 GDK_IM_PREEDIT_POSITION
|
2263 GDK_IM_STATUS_NONE
|
2264 GDK_IM_STATUS_NOTHING
);
2266 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2267 supported_style
= (GdkIMStyle
)(supported_style
& ~GDK_IM_PREEDIT_POSITION
);
2269 attr
->style
= style
= gdk_im_decide_style (supported_style
);
2270 attr
->client_window
= widget
->window
;
2272 if ((colormap
= gtk_widget_get_colormap (widget
)) !=
2273 gtk_widget_get_default_colormap ())
2275 attrmask
|= GDK_IC_PREEDIT_COLORMAP
;
2276 attr
->preedit_colormap
= colormap
;
2279 attrmask
|= GDK_IC_PREEDIT_FOREGROUND
;
2280 attrmask
|= GDK_IC_PREEDIT_BACKGROUND
;
2281 attr
->preedit_foreground
= widget
->style
->fg
[GTK_STATE_NORMAL
];
2282 attr
->preedit_background
= widget
->style
->base
[GTK_STATE_NORMAL
];
2284 switch (style
& GDK_IM_PREEDIT_MASK
)
2286 case GDK_IM_PREEDIT_POSITION
:
2287 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2289 g_warning ("over-the-spot style requires fontset");
2293 gdk_window_get_size (widget
->window
, &width
, &height
);
2295 attrmask
|= GDK_IC_PREEDIT_POSITION_REQ
;
2296 attr
->spot_location
.x
= 0;
2297 attr
->spot_location
.y
= height
;
2298 attr
->preedit_area
.x
= 0;
2299 attr
->preedit_area
.y
= 0;
2300 attr
->preedit_area
.width
= width
;
2301 attr
->preedit_area
.height
= height
;
2302 attr
->preedit_fontset
= widget
->style
->font
;
2307 win
->m_ic
= gdk_ic_new (attr
, (GdkICAttributesType
)attrmask
);
2309 if (win
->m_ic
== NULL
)
2310 g_warning ("Can't create input context.");
2313 mask
= gdk_window_get_events (widget
->window
);
2314 mask
= (GdkEventMask
)(mask
| gdk_ic_get_events (win
->m_ic
));
2315 gdk_window_set_events (widget
->window
, mask
);
2317 if (GTK_WIDGET_HAS_FOCUS(widget
))
2318 gdk_im_begin (win
->m_ic
, widget
->window
);
2326 //-----------------------------------------------------------------------------
2327 // InsertChild for wxWindowGTK.
2328 //-----------------------------------------------------------------------------
2330 /* Callback for wxWindowGTK. This very strange beast has to be used because
2331 * C++ has no virtual methods in a constructor. We have to emulate a
2332 * virtual function here as wxNotebook requires a different way to insert
2333 * a child in it. I had opted for creating a wxNotebookPage window class
2334 * which would have made this superfluous (such in the MDI window system),
2335 * but no-one was listening to me... */
2337 static void wxInsertChildInWindow( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2339 /* the window might have been scrolled already, do we
2340 have to adapt the position */
2341 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
2342 child
->m_x
+= pizza
->xoffset
;
2343 child
->m_y
+= pizza
->yoffset
;
2345 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
2346 GTK_WIDGET(child
->m_widget
),
2353 //-----------------------------------------------------------------------------
2355 //-----------------------------------------------------------------------------
2357 wxWindow
*wxGetActiveWindow()
2359 return wxWindow::FindFocus();
2363 wxMouseState
wxGetMouseState()
2369 GdkModifierType mask
;
2371 gdk_window_get_pointer(NULL
, &x
, &y
, &mask
);
2375 ms
.SetLeftDown(mask
& GDK_BUTTON1_MASK
);
2376 ms
.SetMiddleDown(mask
& GDK_BUTTON2_MASK
);
2377 ms
.SetRightDown(mask
& GDK_BUTTON3_MASK
);
2379 ms
.SetControlDown(mask
& GDK_CONTROL_MASK
);
2380 ms
.SetShiftDown(mask
& GDK_SHIFT_MASK
);
2381 ms
.SetAltDown(mask
& GDK_MOD1_MASK
);
2382 ms
.SetMetaDown(mask
& GDK_MOD2_MASK
);
2387 //-----------------------------------------------------------------------------
2389 //-----------------------------------------------------------------------------
2391 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2393 #ifdef __WXUNIVERSAL__
2394 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2396 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
2397 #endif // __WXUNIVERSAL__/__WXGTK__
2399 void wxWindowGTK::Init()
2402 m_widget
= (GtkWidget
*) NULL
;
2403 m_wxwindow
= (GtkWidget
*) NULL
;
2404 m_focusWidget
= (GtkWidget
*) NULL
;
2414 m_needParent
= true;
2415 m_isBeingDeleted
= false;
2418 m_nativeSizeEvent
= false;
2420 m_hasScrolling
= false;
2421 m_isScrolling
= false;
2423 m_hAdjust
= (GtkAdjustment
*) NULL
;
2424 m_vAdjust
= (GtkAdjustment
*) NULL
;
2425 m_oldHorizontalPos
=
2426 m_oldVerticalPos
= 0.0;
2428 m_oldClientHeight
= 0;
2432 m_insertCallback
= (wxInsertChildFunction
) NULL
;
2434 m_acceptsFocus
= false;
2437 m_clipPaintRegion
= false;
2439 m_needsStyleChange
= false;
2441 m_cursor
= *wxSTANDARD_CURSOR
;
2444 m_ic
= (GdkIC
*) NULL
;
2445 m_icattr
= (GdkICAttr
*) NULL
;
2449 wxWindowGTK::wxWindowGTK()
2454 wxWindowGTK::wxWindowGTK( wxWindow
*parent
,
2459 const wxString
&name
)
2463 Create( parent
, id
, pos
, size
, style
, name
);
2466 bool wxWindowGTK::Create( wxWindow
*parent
,
2471 const wxString
&name
)
2473 if (!PreCreation( parent
, pos
, size
) ||
2474 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2476 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2480 m_insertCallback
= wxInsertChildInWindow
;
2482 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
2483 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
2485 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2487 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2488 scroll_class
->scrollbar_spacing
= 0;
2490 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2492 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
2493 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
2495 m_wxwindow
= gtk_pizza_new();
2497 #ifndef __WXUNIVERSAL__
2498 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
2500 if (HasFlag(wxRAISED_BORDER
))
2502 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
2504 else if (HasFlag(wxSUNKEN_BORDER
))
2506 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
2508 else if (HasFlag(wxSIMPLE_BORDER
))
2510 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
2514 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
2516 #endif // __WXUNIVERSAL__
2518 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2520 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
2521 m_acceptsFocus
= true;
2523 // I _really_ don't want scrollbars in the beginning
2524 m_vAdjust
->lower
= 0.0;
2525 m_vAdjust
->upper
= 1.0;
2526 m_vAdjust
->value
= 0.0;
2527 m_vAdjust
->step_increment
= 1.0;
2528 m_vAdjust
->page_increment
= 1.0;
2529 m_vAdjust
->page_size
= 5.0;
2530 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
2531 m_hAdjust
->lower
= 0.0;
2532 m_hAdjust
->upper
= 1.0;
2533 m_hAdjust
->value
= 0.0;
2534 m_hAdjust
->step_increment
= 1.0;
2535 m_hAdjust
->page_increment
= 1.0;
2536 m_hAdjust
->page_size
= 5.0;
2537 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
2539 // these handlers block mouse events to any window during scrolling such as
2540 // motion events and prevent GTK and wxWidgets from fighting over where the
2543 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_press_event",
2544 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2546 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_press_event",
2547 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2549 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_release_event",
2550 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2552 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_release_event",
2553 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2555 // these handlers get notified when screen updates are required either when
2556 // scrolling or when the window size (and therefore scrollbar configuration)
2559 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
2560 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
2561 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
2562 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
2564 gtk_widget_show( m_wxwindow
);
2567 m_parent
->DoAddChild( this );
2569 m_focusWidget
= m_wxwindow
;
2576 wxWindowGTK::~wxWindowGTK()
2580 if (g_focusWindow
== this)
2581 g_focusWindow
= NULL
;
2583 if ( g_delayedFocus
== this )
2584 g_delayedFocus
= NULL
;
2586 m_isBeingDeleted
= true;
2589 // destroy children before destroying this window itself
2592 // unhook focus handlers to prevent stray events being
2593 // propagated to this (soon to be) dead object
2594 if (m_focusWidget
!= NULL
)
2596 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2597 (GtkSignalFunc
) gtk_window_focus_in_callback
, (gpointer
) this );
2598 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2599 (GtkSignalFunc
) gtk_window_focus_out_callback
, (gpointer
) this );
2607 gdk_ic_destroy (m_ic
);
2609 gdk_ic_attr_destroy (m_icattr
);
2614 gtk_widget_destroy( m_wxwindow
);
2615 m_wxwindow
= (GtkWidget
*) NULL
;
2620 gtk_widget_destroy( m_widget
);
2621 m_widget
= (GtkWidget
*) NULL
;
2625 bool wxWindowGTK::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2627 wxCHECK_MSG( !m_needParent
|| parent
, false, wxT("Need complete parent.") );
2629 // Use either the given size, or the default if -1 is given.
2630 // See wxWindowBase for these functions.
2631 m_width
= WidthDefault(size
.x
) ;
2632 m_height
= HeightDefault(size
.y
);
2640 void wxWindowGTK::PostCreation()
2642 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2648 // these get reported to wxWidgets -> wxPaintEvent
2650 gtk_pizza_set_external( GTK_PIZZA(m_wxwindow
), TRUE
);
2652 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
2653 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
2655 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
2656 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
2658 if (!HasFlag(wxFULL_REPAINT_ON_RESIZE
))
2660 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "event",
2661 GTK_SIGNAL_FUNC(gtk_window_event_event_callback
), (gpointer
)this );
2665 // these are called when the "sunken" or "raised" borders are drawn
2666 gtk_signal_connect( GTK_OBJECT(m_widget
), "expose_event",
2667 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
2669 gtk_signal_connect( GTK_OBJECT(m_widget
), "draw",
2670 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
2675 if (!GTK_IS_WINDOW(m_widget
))
2677 if (m_focusWidget
== NULL
)
2678 m_focusWidget
= m_widget
;
2680 gtk_signal_connect( GTK_OBJECT(m_focusWidget
), "focus_in_event",
2681 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
2683 gtk_signal_connect_after( GTK_OBJECT(m_focusWidget
), "focus_out_event",
2684 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
2687 // connect to the various key and mouse handlers
2689 GtkWidget
*connect_widget
= GetConnectWidget();
2691 ConnectWidget( connect_widget
);
2693 /* We cannot set colours, fonts and cursors before the widget has
2694 been realized, so we do this directly after realization */
2695 gtk_signal_connect( GTK_OBJECT(connect_widget
), "realize",
2696 GTK_SIGNAL_FUNC(gtk_window_realized_callback
), (gpointer
) this );
2700 // Catch native resize events
2701 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
2702 GTK_SIGNAL_FUNC(gtk_window_size_callback
), (gpointer
)this );
2704 // Initialize XIM support
2705 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "realize",
2706 GTK_SIGNAL_FUNC(gtk_wxwindow_realized_callback
), (gpointer
) this );
2708 // And resize XIM window
2709 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
2710 GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback
), (gpointer
)this );
2713 if (GTK_IS_COMBO(m_widget
))
2715 GtkCombo
*gcombo
= GTK_COMBO(m_widget
);
2717 gtk_signal_connect( GTK_OBJECT(gcombo
->entry
), "size_request",
2718 GTK_SIGNAL_FUNC(wxgtk_combo_size_request_callback
),
2723 // This is needed if we want to add our windows into native
2724 // GTK controls, such as the toolbar. With this callback, the
2725 // toolbar gets to know the correct size (the one set by the
2726 // programmer). Sadly, it misbehaves for wxComboBox.
2727 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_request",
2728 GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback
),
2732 InheritAttributes();
2736 // unless the window was created initially hidden (i.e. Hide() had been
2737 // called before Create()), we should show it at GTK+ level as well
2739 gtk_widget_show( m_widget
);
2742 void wxWindowGTK::ConnectWidget( GtkWidget
*widget
)
2744 gtk_signal_connect( GTK_OBJECT(widget
), "key_press_event",
2745 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
2747 gtk_signal_connect( GTK_OBJECT(widget
), "key_release_event",
2748 GTK_SIGNAL_FUNC(gtk_window_key_release_callback
), (gpointer
)this );
2750 gtk_signal_connect( GTK_OBJECT(widget
), "button_press_event",
2751 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
2753 gtk_signal_connect( GTK_OBJECT(widget
), "button_release_event",
2754 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
2756 gtk_signal_connect( GTK_OBJECT(widget
), "motion_notify_event",
2757 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
2759 gtk_signal_connect( GTK_OBJECT(widget
), "enter_notify_event",
2760 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
2762 gtk_signal_connect( GTK_OBJECT(widget
), "leave_notify_event",
2763 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
2766 bool wxWindowGTK::Destroy()
2768 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2772 return wxWindowBase::Destroy();
2775 void wxWindowGTK::DoMoveWindow(int x
, int y
, int width
, int height
)
2777 gtk_pizza_set_size( GTK_PIZZA(m_parent
->m_wxwindow
), m_widget
, x
, y
, width
, height
);
2780 void wxWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
2782 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2783 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
2786 printf( "DoSetSize: name %s, x,y,w,h: %d,%d,%d,%d \n", GetName().c_str(), x,y,width,height );
2789 if (m_resizing
) return; /* I don't like recursions */
2792 int currentX
, currentY
;
2793 GetPosition(¤tX
, ¤tY
);
2794 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2796 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2798 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2800 if (m_parent
->m_wxwindow
== NULL
) /* i.e. wxNotebook */
2802 /* don't set the size for children of wxNotebook, just take the values. */
2810 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
2811 if ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0)
2813 if (x
!= -1) m_x
= x
+ pizza
->xoffset
;
2814 if (y
!= -1) m_y
= y
+ pizza
->yoffset
;
2818 m_x
= x
+ pizza
->xoffset
;
2819 m_y
= y
+ pizza
->yoffset
;
2822 // calculate the best size if we should auto size the window
2823 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
2824 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
2826 const wxSize sizeBest
= GetBestSize();
2827 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
2829 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
2830 height
= sizeBest
.y
;
2838 int minWidth
= GetMinWidth(),
2839 minHeight
= GetMinHeight(),
2840 maxWidth
= GetMaxWidth(),
2841 maxHeight
= GetMaxHeight();
2843 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
2844 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
2845 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
2846 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
2848 int left_border
= 0;
2849 int right_border
= 0;
2851 int bottom_border
= 0;
2853 /* the default button has a border around it */
2854 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
2862 DoMoveWindow( m_x
-top_border
,
2864 m_width
+left_border
+right_border
,
2865 m_height
+top_border
+bottom_border
);
2870 /* Sometimes the client area changes size without the
2871 whole windows's size changing, but if the whole
2872 windows's size doesn't change, no wxSizeEvent will
2873 normally be sent. Here we add an extra test if
2874 the client test has been changed and this will
2876 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
2880 wxPrintf( "OnSize sent from " );
2881 if (GetClassInfo() && GetClassInfo()->GetClassName())
2882 wxPrintf( GetClassInfo()->GetClassName() );
2883 wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height );
2886 if (!m_nativeSizeEvent
)
2888 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
2889 event
.SetEventObject( this );
2890 GetEventHandler()->ProcessEvent( event
);
2896 void wxWindowGTK::OnInternalIdle()
2898 // Update style if the window was not yet realized
2899 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
2900 if (m_needsStyleChange
)
2902 SetBackgroundStyle(GetBackgroundStyle());
2903 m_needsStyleChange
= false;
2906 // Update invalidated regions.
2909 wxCursor cursor
= m_cursor
;
2910 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
2914 /* I now set the cursor anew in every OnInternalIdle call
2915 as setting the cursor in a parent window also effects the
2916 windows above so that checking for the current cursor is
2921 GdkWindow
*window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
2923 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2925 if (!g_globalCursor
.Ok())
2926 cursor
= *wxSTANDARD_CURSOR
;
2928 window
= m_widget
->window
;
2929 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2930 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2936 GdkWindow
*window
= m_widget
->window
;
2937 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2938 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2943 if (wxUpdateUIEvent::CanUpdate(this))
2944 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2947 void wxWindowGTK::DoGetSize( int *width
, int *height
) const
2949 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2951 if (width
) (*width
) = m_width
;
2952 if (height
) (*height
) = m_height
;
2955 void wxWindowGTK::DoSetClientSize( int width
, int height
)
2957 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2961 SetSize( width
, height
);
2968 #ifndef __WXUNIVERSAL__
2969 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
2971 /* when using GTK 1.2 we set the shadow border size to 2 */
2975 if (HasFlag(wxSIMPLE_BORDER
))
2977 /* when using GTK 1.2 we set the simple border size to 1 */
2981 #endif // __WXUNIVERSAL__
2985 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
2987 GtkRequisition vscroll_req
;
2988 vscroll_req
.width
= 2;
2989 vscroll_req
.height
= 2;
2990 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
2991 (scroll_window
->vscrollbar
, &vscroll_req
);
2993 GtkRequisition hscroll_req
;
2994 hscroll_req
.width
= 2;
2995 hscroll_req
.height
= 2;
2996 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
2997 (scroll_window
->hscrollbar
, &hscroll_req
);
2999 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3001 if (scroll_window
->vscrollbar_visible
)
3003 dw
+= vscroll_req
.width
;
3004 dw
+= scroll_class
->scrollbar_spacing
;
3007 if (scroll_window
->hscrollbar_visible
)
3009 dh
+= hscroll_req
.height
;
3010 dh
+= scroll_class
->scrollbar_spacing
;
3014 SetSize( width
+dw
, height
+dh
);
3018 void wxWindowGTK::DoGetClientSize( int *width
, int *height
) const
3020 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3024 if (width
) (*width
) = m_width
;
3025 if (height
) (*height
) = m_height
;
3032 #ifndef __WXUNIVERSAL__
3033 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
3035 /* when using GTK 1.2 we set the shadow border size to 2 */
3039 if (HasFlag(wxSIMPLE_BORDER
))
3041 /* when using GTK 1.2 we set the simple border size to 1 */
3045 #endif // __WXUNIVERSAL__
3049 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
3051 GtkRequisition vscroll_req
;
3052 vscroll_req
.width
= 2;
3053 vscroll_req
.height
= 2;
3054 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
3055 (scroll_window
->vscrollbar
, &vscroll_req
);
3057 GtkRequisition hscroll_req
;
3058 hscroll_req
.width
= 2;
3059 hscroll_req
.height
= 2;
3060 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
3061 (scroll_window
->hscrollbar
, &hscroll_req
);
3063 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3065 if (scroll_window
->vscrollbar_visible
)
3067 dw
+= vscroll_req
.width
;
3068 dw
+= scroll_class
->scrollbar_spacing
;
3071 if (scroll_window
->hscrollbar_visible
)
3073 dh
+= hscroll_req
.height
;
3074 dh
+= scroll_class
->scrollbar_spacing
;
3078 if (width
) (*width
) = m_width
- dw
;
3079 if (height
) (*height
) = m_height
- dh
;
3083 printf( "GetClientSize, name %s ", GetName().c_str() );
3084 if (width) printf( " width = %d", (*width) );
3085 if (height) printf( " height = %d", (*height) );
3090 void wxWindowGTK::DoGetPosition( int *x
, int *y
) const
3092 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3096 if (m_parent
&& m_parent
->m_wxwindow
)
3098 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
3099 dx
= pizza
->xoffset
;
3100 dy
= pizza
->yoffset
;
3103 if (x
) (*x
) = m_x
- dx
;
3104 if (y
) (*y
) = m_y
- dy
;
3107 void wxWindowGTK::DoClientToScreen( int *x
, int *y
) const
3109 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3111 if (!m_widget
->window
) return;
3113 GdkWindow
*source
= (GdkWindow
*) NULL
;
3115 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3117 source
= m_widget
->window
;
3121 gdk_window_get_origin( source
, &org_x
, &org_y
);
3125 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3127 org_x
+= m_widget
->allocation
.x
;
3128 org_y
+= m_widget
->allocation
.y
;
3136 void wxWindowGTK::DoScreenToClient( int *x
, int *y
) const
3138 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3140 if (!m_widget
->window
) return;
3142 GdkWindow
*source
= (GdkWindow
*) NULL
;
3144 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3146 source
= m_widget
->window
;
3150 gdk_window_get_origin( source
, &org_x
, &org_y
);
3154 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3156 org_x
+= m_widget
->allocation
.x
;
3157 org_y
+= m_widget
->allocation
.y
;
3165 bool wxWindowGTK::Show( bool show
)
3167 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3169 if (!wxWindowBase::Show(show
))
3176 gtk_widget_show( m_widget
);
3178 gtk_widget_hide( m_widget
);
3180 wxShowEvent
eventShow(GetId(), show
);
3181 eventShow
.SetEventObject(this);
3183 GetEventHandler()->ProcessEvent(eventShow
);
3188 static void wxWindowNotifyEnable(wxWindowGTK
* win
, bool enable
)
3190 win
->OnParentEnable(enable
);
3192 // Recurse, so that children have the opportunity to Do The Right Thing
3193 // and reset colours that have been messed up by a parent's (really ancestor's)
3195 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3197 node
= node
->GetNext() )
3199 wxWindow
*child
= node
->GetData();
3200 if (!child
->IsKindOf(CLASSINFO(wxDialog
)) && !child
->IsKindOf(CLASSINFO(wxFrame
)))
3201 wxWindowNotifyEnable(child
, enable
);
3205 bool wxWindowGTK::Enable( bool enable
)
3207 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3209 if (!wxWindowBase::Enable(enable
))
3215 gtk_widget_set_sensitive( m_widget
, enable
);
3217 gtk_widget_set_sensitive( m_wxwindow
, enable
);
3219 wxWindowNotifyEnable(this, enable
);
3224 int wxWindowGTK::GetCharHeight() const
3226 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
3228 wxFont font
= GetFont();
3229 wxCHECK_MSG( font
.Ok(), 12, wxT("invalid font") );
3231 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3233 return gfont
->ascent
+ gfont
->descent
;
3236 int wxWindowGTK::GetCharWidth() const
3238 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
3240 wxFont font
= GetFont();
3241 wxCHECK_MSG( font
.Ok(), 8, wxT("invalid font") );
3243 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3245 return gdk_string_width( gfont
, "g" );
3248 void wxWindowGTK::GetTextExtent( const wxString
& string
,
3252 int *externalLeading
,
3253 const wxFont
*theFont
) const
3255 wxFont fontToUse
= theFont
? *theFont
: GetFont();
3257 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
3266 GdkFont
*font
= fontToUse
.GetInternalFont( 1.0 );
3267 if (x
) (*x
) = gdk_string_width( font
, wxGTK_CONV( string
) );
3268 if (y
) (*y
) = font
->ascent
+ font
->descent
;
3269 if (descent
) (*descent
) = font
->descent
;
3270 if (externalLeading
) (*externalLeading
) = 0; // ??
3273 void wxWindowGTK::SetFocus()
3275 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3278 // don't do anything if we already have focus
3284 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow
))
3286 gtk_widget_grab_focus (m_wxwindow
);
3291 if (GTK_WIDGET_CAN_FOCUS(m_widget
) && !GTK_WIDGET_HAS_FOCUS (m_widget
) )
3294 if (!GTK_WIDGET_REALIZED(m_widget
))
3296 // we can't set the focus to the widget now so we remember that
3297 // it should be focused and will do it later, during the idle
3298 // time, as soon as we can
3299 wxLogTrace(TRACE_FOCUS
,
3300 _T("Delaying setting focus to %s(%s)"),
3301 GetClassInfo()->GetClassName(), GetLabel().c_str());
3303 g_delayedFocus
= this;
3307 wxLogTrace(TRACE_FOCUS
,
3308 _T("Setting focus to %s(%s)"),
3309 GetClassInfo()->GetClassName(), GetLabel().c_str());
3311 gtk_widget_grab_focus (m_widget
);
3315 if (GTK_IS_CONTAINER(m_widget
))
3317 gtk_container_focus( GTK_CONTAINER(m_widget
), GTK_DIR_TAB_FORWARD
);
3321 wxLogTrace(TRACE_FOCUS
,
3322 _T("Can't set focus to %s(%s)"),
3323 GetClassInfo()->GetClassName(), GetLabel().c_str());
3328 bool wxWindowGTK::AcceptsFocus() const
3330 return m_acceptsFocus
&& wxWindowBase::AcceptsFocus();
3333 bool wxWindowGTK::Reparent( wxWindowBase
*newParentBase
)
3335 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3337 wxWindowGTK
*oldParent
= m_parent
,
3338 *newParent
= (wxWindowGTK
*)newParentBase
;
3340 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3342 if ( !wxWindowBase::Reparent(newParent
) )
3345 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3347 /* prevent GTK from deleting the widget arbitrarily */
3348 gtk_widget_ref( m_widget
);
3352 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3355 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3359 /* insert GTK representation */
3360 (*(newParent
->m_insertCallback
))(newParent
, this);
3363 /* reverse: prevent GTK from deleting the widget arbitrarily */
3364 gtk_widget_unref( m_widget
);
3369 void wxWindowGTK::DoAddChild(wxWindowGTK
*child
)
3371 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3373 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3375 wxASSERT_MSG( (m_insertCallback
!= NULL
), wxT("invalid child insertion function") );
3380 /* insert GTK representation */
3381 (*m_insertCallback
)(this, child
);
3384 void wxWindowGTK::Raise()
3386 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3388 if (m_wxwindow
&& m_wxwindow
->window
)
3390 gdk_window_raise( m_wxwindow
->window
);
3392 else if (m_widget
->window
)
3394 gdk_window_raise( m_widget
->window
);
3398 void wxWindowGTK::Lower()
3400 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3402 if (m_wxwindow
&& m_wxwindow
->window
)
3404 gdk_window_lower( m_wxwindow
->window
);
3406 else if (m_widget
->window
)
3408 gdk_window_lower( m_widget
->window
);
3412 bool wxWindowGTK::SetCursor( const wxCursor
&cursor
)
3414 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3416 if (cursor
== m_cursor
)
3420 wxapp_install_idle_handler();
3422 if (cursor
== wxNullCursor
)
3423 return wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
);
3425 return wxWindowBase::SetCursor( cursor
);
3428 void wxWindowGTK::WarpPointer( int x
, int y
)
3430 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3432 // We provide this function ourselves as it is
3433 // missing in GDK (top of this file).
3435 GdkWindow
*window
= (GdkWindow
*) NULL
;
3437 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3439 window
= GetConnectWidget()->window
;
3442 gdk_window_warp_pointer( window
, x
, y
);
3446 void wxWindowGTK::Refresh( bool eraseBackground
, const wxRect
*rect
)
3450 if (!m_widget
->window
)
3454 wxapp_install_idle_handler();
3457 if (m_wxwindow
&& rect
)
3459 myRect
.SetSize(wxSize( m_wxwindow
->allocation
.width
,
3460 m_wxwindow
->allocation
.height
));
3461 if ( myRect
.Intersect(*rect
).IsEmpty() )
3463 // nothing to do, rectangle is empty
3470 // schedule the area for later updating in GtkUpdate()
3471 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
3475 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3479 m_clearRegion
.Clear();
3480 m_clearRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
3488 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3492 GdkRectangle gdk_rect
;
3493 gdk_rect
.x
= rect
->x
;
3494 gdk_rect
.y
= rect
->y
;
3495 gdk_rect
.width
= rect
->width
;
3496 gdk_rect
.height
= rect
->height
;
3497 gtk_widget_draw( m_widget
, &gdk_rect
);
3504 m_updateRegion
.Clear();
3505 m_updateRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
3509 gtk_widget_draw( m_widget
, (GdkRectangle
*) NULL
);
3514 void wxWindowGTK::Update()
3518 // when we call Update() we really want to update the window immediately on
3519 // screen, even if it means flushing the entire queue and hence slowing down
3520 // everything -- but it should still be done, it's just that Update() should
3521 // be called very rarely
3525 void wxWindowGTK::GtkUpdate()
3527 if (!m_updateRegion
.IsEmpty())
3528 GtkSendPaintEvents();
3530 // for consistency with other platforms (and also because it's convenient
3531 // to be able to update an entire TLW by calling Update() only once), we
3532 // should also update all our children here
3533 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3535 node
= node
->GetNext() )
3537 node
->GetData()->GtkUpdate();
3541 void wxWindowGTK::GtkSendPaintEvents()
3545 m_clearRegion
.Clear();
3546 m_updateRegion
.Clear();
3550 // Clip to paint region in wxClientDC
3551 m_clipPaintRegion
= true;
3553 // widget to draw on
3554 GtkPizza
*pizza
= GTK_PIZZA (m_wxwindow
);
3556 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM
))
3558 // find ancestor from which to steal background
3559 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3561 parent
= (wxWindow
*)this;
3563 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
3565 wxRegionIterator
upd( m_updateRegion
);
3569 rect
.x
= upd
.GetX();
3570 rect
.y
= upd
.GetY();
3571 rect
.width
= upd
.GetWidth();
3572 rect
.height
= upd
.GetHeight();
3574 gtk_paint_flat_box( parent
->m_widget
->style
,
3576 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
3589 // if (!m_clearRegion.IsEmpty()) // Always send an erase event under GTK 1.2
3591 wxWindowDC
dc( (wxWindow
*)this );
3592 if (m_clearRegion
.IsEmpty())
3593 dc
.SetClippingRegion( m_updateRegion
);
3595 dc
.SetClippingRegion( m_clearRegion
);
3597 wxEraseEvent
erase_event( GetId(), &dc
);
3598 erase_event
.SetEventObject( this );
3600 if (!GetEventHandler()->ProcessEvent(erase_event
) && GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3604 g_eraseGC
= gdk_gc_new( pizza
->bin_window
);
3605 gdk_gc_set_fill( g_eraseGC
, GDK_SOLID
);
3607 gdk_gc_set_foreground( g_eraseGC
, GetBackgroundColour().GetColor() );
3609 wxRegionIterator
upd( m_clearRegion
);
3612 gdk_draw_rectangle( pizza
->bin_window
, g_eraseGC
, 1,
3613 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
3617 m_clearRegion
.Clear();
3620 wxNcPaintEvent
nc_paint_event( GetId() );
3621 nc_paint_event
.SetEventObject( this );
3622 GetEventHandler()->ProcessEvent( nc_paint_event
);
3624 wxPaintEvent
paint_event( GetId() );
3625 paint_event
.SetEventObject( this );
3626 GetEventHandler()->ProcessEvent( paint_event
);
3628 m_clipPaintRegion
= false;
3630 #if !defined(__WXUNIVERSAL__)
3631 // The following code will result in all window-less widgets
3632 // being redrawn because the wxWidgets class is allowed to
3633 // paint over the window-less widgets.
3635 GList
*children
= pizza
->children
;
3638 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
3639 children
= children
->next
;
3641 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
3642 GTK_WIDGET_DRAWABLE (child
->widget
))
3644 // Get intersection of widget area and update region
3645 wxRegion
region( m_updateRegion
);
3647 GdkEventExpose gdk_event
;
3648 gdk_event
.type
= GDK_EXPOSE
;
3649 gdk_event
.window
= pizza
->bin_window
;
3650 gdk_event
.count
= 0;
3651 gdk_event
.send_event
= TRUE
;
3653 wxRegionIterator
upd( m_updateRegion
);
3657 rect
.x
= upd
.GetX();
3658 rect
.y
= upd
.GetY();
3659 rect
.width
= upd
.GetWidth();
3660 rect
.height
= upd
.GetHeight();
3662 if (gtk_widget_intersect (child
->widget
, &rect
, &gdk_event
.area
))
3664 gtk_widget_event (child
->widget
, (GdkEvent
*) &gdk_event
);
3671 #endif // native GTK 1
3673 m_updateRegion
.Clear();
3676 void wxWindowGTK::ClearBackground()
3678 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3680 if (m_wxwindow
&& m_wxwindow
->window
)
3682 m_clearRegion
.Clear();
3683 wxSize
size( GetClientSize() );
3684 m_clearRegion
.Union( 0,0,size
.x
,size
.y
);
3686 // Better do this in idle?
3692 void wxWindowGTK::DoSetToolTip( wxToolTip
*tip
)
3694 wxWindowBase::DoSetToolTip(tip
);
3697 m_tooltip
->Apply( (wxWindow
*)this );
3700 void wxWindowGTK::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
3702 wxString
tmp( tip
);
3703 gtk_tooltips_set_tip( tips
, GetConnectWidget(), wxGTK_CONV(tmp
), (gchar
*) NULL
);
3705 #endif // wxUSE_TOOLTIPS
3707 bool wxWindowGTK::SetBackgroundColour( const wxColour
&colour
)
3709 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3711 if (!wxWindowBase::SetBackgroundColour(colour
))
3716 // We need the pixel value e.g. for background clearing.
3717 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3720 // apply style change (forceStyle=true so that new style is applied
3721 // even if the bg colour changed from valid to wxNullColour)
3722 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3723 ApplyWidgetStyle(true);
3728 bool wxWindowGTK::SetForegroundColour( const wxColour
&colour
)
3730 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3732 if (!wxWindowBase::SetForegroundColour(colour
))
3739 // We need the pixel value e.g. for background clearing.
3740 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3743 // apply style change (forceStyle=true so that new style is applied
3744 // even if the bg colour changed from valid to wxNullColour):
3745 ApplyWidgetStyle(true);
3750 GtkRcStyle
*wxWindowGTK::CreateWidgetStyle(bool forceStyle
)
3752 // do we need to apply any changes at all?
3755 !m_foregroundColour
.Ok() && !m_backgroundColour
.Ok() )
3760 GtkRcStyle
*style
= gtk_rc_style_new();
3764 wxString xfontname
= m_font
.GetNativeFontInfo()->GetXFontName();
3765 style
->fontset_name
= g_strdup(xfontname
.c_str());
3768 if ( m_foregroundColour
.Ok() )
3770 GdkColor
*fg
= m_foregroundColour
.GetColor();
3772 style
->fg
[GTK_STATE_NORMAL
] = *fg
;
3773 style
->color_flags
[GTK_STATE_NORMAL
] = GTK_RC_FG
;
3775 style
->fg
[GTK_STATE_PRELIGHT
] = *fg
;
3776 style
->color_flags
[GTK_STATE_PRELIGHT
] = GTK_RC_FG
;
3778 style
->fg
[GTK_STATE_ACTIVE
] = *fg
;
3779 style
->color_flags
[GTK_STATE_ACTIVE
] = GTK_RC_FG
;
3782 if ( m_backgroundColour
.Ok() )
3784 GdkColor
*bg
= m_backgroundColour
.GetColor();
3786 style
->bg
[GTK_STATE_NORMAL
] = *bg
;
3787 style
->base
[GTK_STATE_NORMAL
] = *bg
;
3788 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)
3789 (style
->color_flags
[GTK_STATE_NORMAL
] | GTK_RC_BG
| GTK_RC_BASE
);
3791 style
->bg
[GTK_STATE_PRELIGHT
] = *bg
;
3792 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
3793 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)
3794 (style
->color_flags
[GTK_STATE_PRELIGHT
] | GTK_RC_BG
| GTK_RC_BASE
);
3796 style
->bg
[GTK_STATE_ACTIVE
] = *bg
;
3797 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
3798 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)
3799 (style
->color_flags
[GTK_STATE_ACTIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3801 style
->bg
[GTK_STATE_INSENSITIVE
] = *bg
;
3802 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
3803 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)
3804 (style
->color_flags
[GTK_STATE_INSENSITIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3810 void wxWindowGTK::ApplyWidgetStyle(bool forceStyle
)
3812 GtkRcStyle
*style
= CreateWidgetStyle(forceStyle
);
3815 DoApplyWidgetStyle(style
);
3816 gtk_rc_style_unref(style
);
3819 // Style change may affect GTK+'s size calculation:
3820 InvalidateBestSize();
3823 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle
*style
)
3826 gtk_widget_modify_style(m_wxwindow
, style
);
3828 gtk_widget_modify_style(m_widget
, style
);
3831 bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style
)
3833 wxWindowBase::SetBackgroundStyle(style
);
3835 if (style
== wxBG_STYLE_CUSTOM
)
3837 GdkWindow
*window
= (GdkWindow
*) NULL
;
3839 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3841 window
= GetConnectWidget()->window
;
3845 // Make sure GDK/X11 doesn't refresh the window
3847 gdk_window_set_back_pixmap( window
, None
, False
);
3849 Display
* display
= GDK_WINDOW_DISPLAY(window
);
3852 m_needsStyleChange
= false;
3855 // Do in OnIdle, because the window is not yet available
3856 m_needsStyleChange
= true;
3858 // Don't apply widget style, or we get a grey background
3862 // apply style change (forceStyle=true so that new style is applied
3863 // even if the bg colour changed from valid to wxNullColour):
3864 ApplyWidgetStyle(true);
3869 #if wxUSE_DRAG_AND_DROP
3871 void wxWindowGTK::SetDropTarget( wxDropTarget
*dropTarget
)
3873 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3875 GtkWidget
*dnd_widget
= GetConnectWidget();
3877 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
3879 if (m_dropTarget
) delete m_dropTarget
;
3880 m_dropTarget
= dropTarget
;
3882 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
3885 #endif // wxUSE_DRAG_AND_DROP
3887 GtkWidget
* wxWindowGTK::GetConnectWidget()
3889 GtkWidget
*connect_widget
= m_widget
;
3890 if (m_wxwindow
) connect_widget
= m_wxwindow
;
3892 return connect_widget
;
3895 bool wxWindowGTK::IsOwnGtkWindow( GdkWindow
*window
)
3898 return (window
== GTK_PIZZA(m_wxwindow
)->bin_window
);
3900 return (window
== m_widget
->window
);
3903 bool wxWindowGTK::SetFont( const wxFont
&font
)
3905 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3907 if (!wxWindowBase::SetFont(font
))
3910 // apply style change (forceStyle=true so that new style is applied
3911 // even if the font changed from valid to wxNullFont):
3912 ApplyWidgetStyle(true);
3917 void wxWindowGTK::DoCaptureMouse()
3919 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3921 GdkWindow
*window
= (GdkWindow
*) NULL
;
3923 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3925 window
= GetConnectWidget()->window
;
3927 wxCHECK_RET( window
, _T("CaptureMouse() failed") );
3929 wxCursor
* cursor
= & m_cursor
;
3931 cursor
= wxSTANDARD_CURSOR
;
3933 gdk_pointer_grab( window
, FALSE
,
3935 (GDK_BUTTON_PRESS_MASK
|
3936 GDK_BUTTON_RELEASE_MASK
|
3937 GDK_POINTER_MOTION_HINT_MASK
|
3938 GDK_POINTER_MOTION_MASK
),
3940 cursor
->GetCursor(),
3941 (guint32
)GDK_CURRENT_TIME
);
3942 g_captureWindow
= this;
3943 g_captureWindowHasMouse
= true;
3946 void wxWindowGTK::DoReleaseMouse()
3948 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3950 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
3952 g_captureWindow
= (wxWindowGTK
*) NULL
;
3954 GdkWindow
*window
= (GdkWindow
*) NULL
;
3956 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3958 window
= GetConnectWidget()->window
;
3963 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
3967 wxWindow
*wxWindowBase::GetCapture()
3969 return (wxWindow
*)g_captureWindow
;
3972 bool wxWindowGTK::IsRetained() const
3977 void wxWindowGTK::SetScrollbar( int orient
, int pos
, int thumbVisible
,
3978 int range
, bool refresh
)
3980 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3982 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
3984 m_hasScrolling
= true;
3986 if (orient
== wxHORIZONTAL
)
3988 float fpos
= (float)pos
;
3989 float frange
= (float)range
;
3990 float fthumb
= (float)thumbVisible
;
3991 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
3992 if (fpos
< 0.0) fpos
= 0.0;
3994 if ((fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
3995 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
3997 SetScrollPos( orient
, pos
, refresh
);
4001 m_oldHorizontalPos
= fpos
;
4003 m_hAdjust
->lower
= 0.0;
4004 m_hAdjust
->upper
= frange
;
4005 m_hAdjust
->value
= fpos
;
4006 m_hAdjust
->step_increment
= 1.0;
4007 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4008 m_hAdjust
->page_size
= fthumb
;
4012 float fpos
= (float)pos
;
4013 float frange
= (float)range
;
4014 float fthumb
= (float)thumbVisible
;
4015 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
4016 if (fpos
< 0.0) fpos
= 0.0;
4018 if ((fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
4019 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
4021 SetScrollPos( orient
, pos
, refresh
);
4025 m_oldVerticalPos
= fpos
;
4027 m_vAdjust
->lower
= 0.0;
4028 m_vAdjust
->upper
= frange
;
4029 m_vAdjust
->value
= fpos
;
4030 m_vAdjust
->step_increment
= 1.0;
4031 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4032 m_vAdjust
->page_size
= fthumb
;
4035 if (orient
== wxHORIZONTAL
)
4036 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
4038 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
4041 void wxWindowGTK::GtkUpdateScrollbar(int orient
)
4043 GtkAdjustment
*adj
= orient
== wxHORIZONTAL
? m_hAdjust
: m_vAdjust
;
4044 GtkSignalFunc fn
= orient
== wxHORIZONTAL
4045 ? (GtkSignalFunc
)gtk_window_hscroll_callback
4046 : (GtkSignalFunc
)gtk_window_vscroll_callback
;
4048 gtk_signal_disconnect_by_func(GTK_OBJECT(adj
), fn
, (gpointer
)this);
4049 gtk_signal_emit_by_name(GTK_OBJECT(adj
), "value_changed");
4050 gtk_signal_connect(GTK_OBJECT(adj
), "value_changed", fn
, (gpointer
)this);
4053 void wxWindowGTK::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
4055 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4056 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4058 GtkAdjustment
*adj
= orient
== wxHORIZONTAL
? m_hAdjust
: m_vAdjust
;
4060 float fpos
= (float)pos
;
4061 if (fpos
> adj
->upper
- adj
->page_size
)
4062 fpos
= adj
->upper
- adj
->page_size
;
4065 *(orient
== wxHORIZONTAL
? &m_oldHorizontalPos
: &m_oldVerticalPos
) = fpos
;
4067 if (fabs(fpos
-adj
->value
) < 0.2)
4071 if ( m_wxwindow
->window
)
4076 int wxWindowGTK::GetScrollThumb( int orient
) const
4078 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4080 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4082 if (orient
== wxHORIZONTAL
)
4083 return (int)(m_hAdjust
->page_size
+0.5);
4085 return (int)(m_vAdjust
->page_size
+0.5);
4088 int wxWindowGTK::GetScrollPos( int orient
) const
4090 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4092 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4094 if (orient
== wxHORIZONTAL
)
4095 return (int)(m_hAdjust
->value
+0.5);
4097 return (int)(m_vAdjust
->value
+0.5);
4100 int wxWindowGTK::GetScrollRange( int orient
) const
4102 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4104 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4106 if (orient
== wxHORIZONTAL
)
4107 return (int)(m_hAdjust
->upper
+0.5);
4109 return (int)(m_vAdjust
->upper
+0.5);
4112 void wxWindowGTK::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4114 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4116 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4118 // No scrolling requested.
4119 if ((dx
== 0) && (dy
== 0)) return;
4121 if (!m_updateRegion
.IsEmpty())
4123 m_updateRegion
.Offset( dx
, dy
);
4127 GetClientSize( &cw
, &ch
);
4128 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
4131 if (!m_clearRegion
.IsEmpty())
4133 m_clearRegion
.Offset( dx
, dy
);
4137 GetClientSize( &cw
, &ch
);
4138 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
4141 m_clipPaintRegion
= true;
4143 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow
), -dx
, -dy
);
4145 m_clipPaintRegion
= false;
4148 void wxWindowGTK::SetWindowStyleFlag( long style
)
4150 // Updates the internal variable. NB: Now m_windowStyle bits carry the _new_ style values already
4151 wxWindowBase::SetWindowStyleFlag(style
);
4154 // Find the wxWindow at the current mouse position, also returning the mouse
4156 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4158 pt
= wxGetMousePosition();
4159 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4163 // Get the current mouse position.
4164 wxPoint
wxGetMousePosition()
4166 /* This crashes when used within wxHelpContext,
4167 so we have to use the X-specific implementation below.
4169 GdkModifierType *mask;
4170 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4172 return wxPoint(x, y);
4176 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4178 Display
*display
= windowAtPtr
? GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4179 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4180 Window rootReturn
, childReturn
;
4181 int rootX
, rootY
, winX
, winY
;
4182 unsigned int maskReturn
;
4184 XQueryPointer (display
,
4188 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4189 return wxPoint(rootX
, rootY
);
4193 // Needed for implementing e.g. combobox on wxGTK within a modal dialog.
4194 void wxAddGrab(wxWindow
* window
)
4196 gtk_grab_add( (GtkWidget
*) window
->GetHandle() );
4199 void wxRemoveGrab(wxWindow
* window
)
4201 gtk_grab_remove( (GtkWidget
*) window
->GetHandle() );
4204 // ----------------------------------------------------------------------------
4206 // ----------------------------------------------------------------------------
4208 class wxWinModule
: public wxModule
4215 DECLARE_DYNAMIC_CLASS(wxWinModule
)
4218 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
4220 bool wxWinModule::OnInit()
4222 // g_eraseGC = gdk_gc_new( GDK_ROOT_PARENT() );
4223 // gdk_gc_set_fill( g_eraseGC, GDK_SOLID );
4228 void wxWinModule::OnExit()
4231 gdk_gc_unref( g_eraseGC
);