1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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"
25 #include "wx/dcclient.h"
28 #include "wx/layout.h"
29 #include "wx/dialog.h"
30 #include "wx/msgdlg.h"
31 #include "wx/module.h"
32 #include "wx/combobox.h"
33 #if wxUSE_TOOLBAR_NATIVE
34 #include "wx/toolbar.h"
37 #if wxUSE_DRAG_AND_DROP
42 #include "wx/tooltip.h"
50 #include "wx/textctrl.h"
54 #include "wx/statusbr.h"
55 #include "wx/settings.h"
56 #include "wx/fontutil.h"
59 #include "wx/thread.h"
65 // FIXME: Due to a hack we use GtkCombo in here, which is deprecated since gtk2.3.0
66 #include <gtk/gtkversion.h>
67 #if defined(GTK_DISABLE_DEPRECATED) && GTK_CHECK_VERSION(2,3,0)
68 #undef GTK_DISABLE_DEPRECATED
71 #include "wx/gtk/private.h"
72 #include <gdk/gdkprivate.h>
73 #include <gdk/gdkkeysyms.h>
77 #include <gtk/gtkprivate.h>
79 #include "wx/gtk/win_gtk.h"
81 #include <pango/pangox.h>
87 extern GtkContainerClass
*pizza_parent_class
;
89 //-----------------------------------------------------------------------------
90 // documentation on internals
91 //-----------------------------------------------------------------------------
94 I have been asked several times about writing some documentation about
95 the GTK port of wxWidgets, especially its internal structures. Obviously,
96 you cannot understand wxGTK without knowing a little about the GTK, but
97 some more information about what the wxWindow, which is the base class
98 for all other window classes, does seems required as well.
102 What does wxWindow do? It contains the common interface for the following
103 jobs of its descendants:
105 1) Define the rudimentary behaviour common to all window classes, such as
106 resizing, intercepting user input (so as to make it possible to use these
107 events for special purposes in a derived class), window names etc.
109 2) Provide the possibility to contain and manage children, if the derived
110 class is allowed to contain children, which holds true for those window
111 classes which do not display a native GTK widget. To name them, these
112 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
113 work classes are a special case and are handled a bit differently from
114 the rest. The same holds true for the wxNotebook class.
116 3) Provide the possibility to draw into a client area of a window. This,
117 too, only holds true for classes that do not display a native GTK widget
120 4) Provide the entire mechanism for scrolling widgets. This actual inter-
121 face for this is usually in wxScrolledWindow, but the GTK implementation
124 5) A multitude of helper or extra methods for special purposes, such as
125 Drag'n'Drop, managing validators etc.
127 6) Display a border (sunken, raised, simple or none).
129 Normally one might expect, that one wxWidgets window would always correspond
130 to one GTK widget. Under GTK, there is no such allround widget that has all
131 the functionality. Moreover, the GTK defines a client area as a different
132 widget from the actual widget you are handling. Last but not least some
133 special classes (e.g. wxFrame) handle different categories of widgets and
134 still have the possibility to draw something in the client area.
135 It was therefore required to write a special purpose GTK widget, that would
136 represent a client area in the sense of wxWidgets capable to do the jobs
137 2), 3) and 4). I have written this class and it resides in win_gtk.c of
140 All windows must have a widget, with which they interact with other under-
141 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
142 the wxWindow class has a member variable called m_widget which holds a
143 pointer to this widget. When the window class represents a GTK native widget,
144 this is (in most cases) the only GTK widget the class manages. E.g. the
145 wxStaticText class handles only a GtkLabel widget a pointer to which you
146 can find in m_widget (defined in wxWindow)
148 When the class has a client area for drawing into and for containing children
149 it has to handle the client area widget (of the type GtkPizza, defined in
150 win_gtk.c), but there could be any number of widgets, handled by a class
151 The common rule for all windows is only, that the widget that interacts with
152 the rest of GTK must be referenced in m_widget and all other widgets must be
153 children of this widget on the GTK level. The top-most widget, which also
154 represents the client area, must be in the m_wxwindow field and must be of
157 As I said, the window classes that display a GTK native widget only have
158 one widget, so in the case of e.g. the wxButton class m_widget holds a
159 pointer to a GtkButton widget. But windows with client areas (for drawing
160 and children) have a m_widget field that is a pointer to a GtkScrolled-
161 Window and a m_wxwindow field that is pointer to a GtkPizza and this
162 one is (in the GTK sense) a child of the GtkScrolledWindow.
164 If the m_wxwindow field is set, then all input to this widget is inter-
165 cepted and sent to the wxWidgets class. If not, all input to the widget
166 that gets pointed to by m_widget gets intercepted and sent to the class.
170 The design of scrolling in wxWidgets is markedly different from that offered
171 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
172 clicking on a scrollbar belonging to scrolled window will inevitably move
173 the window. In wxWidgets, the scrollbar will only emit an event, send this
174 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
175 which actually moves the window and its subchildren. Note that GtkPizza
176 memorizes how much it has been scrolled but that wxWidgets forgets this
177 so that the two coordinates systems have to be kept in synch. This is done
178 in various places using the pizza->xoffset and pizza->yoffset values.
182 Singularily the most broken code in GTK is the code that is supposed to
183 inform subwindows (child windows) about new positions. Very often, duplicate
184 events are sent without changes in size or position, equally often no
185 events are sent at all (All this is due to a bug in the GtkContainer code
186 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
187 GTK's own system and it simply waits for size events for toplevel windows
188 and then iterates down the respective size events to all window. This has
189 the disadvantage that windows might get size events before the GTK widget
190 actually has the reported size. This doesn't normally pose any problem, but
191 the OpenGL drawing routines rely on correct behaviour. Therefore, I have
192 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
193 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
194 window that is used for OpenGL output really has that size (as reported by
199 If someone at some point of time feels the immense desire to have a look at,
200 change or attempt to optimise the Refresh() logic, this person will need an
201 intimate understanding of what "draw" and "expose" events are and what
202 they are used for, in particular when used in connection with GTK's
203 own windowless widgets. Beware.
207 Cursors, too, have been a constant source of pleasure. The main difficulty
208 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
209 for the parent. To prevent this from doing too much harm, I use idle time
210 to set the cursor over and over again, starting from the toplevel windows
211 and ending with the youngest generation (speaking of parent and child windows).
212 Also don't forget that cursors (like much else) are connected to GdkWindows,
213 not GtkWidgets and that the "window" field of a GtkWidget might very well
214 point to the GdkWindow of the parent widget (-> "window-less widget") and
215 that the two obviously have very different meanings.
219 //-----------------------------------------------------------------------------
221 //-----------------------------------------------------------------------------
223 extern wxList wxPendingDelete
;
224 extern bool g_blockEventsOnDrag
;
225 extern bool g_blockEventsOnScroll
;
226 extern wxCursor g_globalCursor
;
228 static GdkGC
*g_eraseGC
= NULL
;
230 // mouse capture state: the window which has it and if the mouse is currently
232 static wxWindowGTK
*g_captureWindow
= (wxWindowGTK
*) NULL
;
233 static bool g_captureWindowHasMouse
= false;
235 wxWindowGTK
*g_focusWindow
= (wxWindowGTK
*) NULL
;
237 // the last window which had the focus - this is normally never NULL (except
238 // if we never had focus at all) as even when g_focusWindow is NULL it still
239 // keeps its previous value
240 wxWindowGTK
*g_focusWindowLast
= (wxWindowGTK
*) NULL
;
242 // If a window get the focus set but has not been realized
243 // yet, defer setting the focus to idle time.
244 wxWindowGTK
*g_delayedFocus
= (wxWindowGTK
*) NULL
;
246 extern bool g_mainThreadLocked
;
248 //-----------------------------------------------------------------------------
250 //-----------------------------------------------------------------------------
255 # define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
257 # define DEBUG_MAIN_THREAD
260 #define DEBUG_MAIN_THREAD
263 // the trace mask used for the focus debugging messages
264 #define TRACE_FOCUS _T("focus")
266 //-----------------------------------------------------------------------------
267 // missing gdk functions
268 //-----------------------------------------------------------------------------
271 gdk_window_warp_pointer (GdkWindow
*window
,
276 window
= gdk_get_default_root_window();
278 if (!GDK_WINDOW_DESTROYED(window
))
280 XWarpPointer (GDK_WINDOW_XDISPLAY(window
),
281 None
, /* not source window -> move from anywhere */
282 GDK_WINDOW_XID(window
), /* dest window */
283 0, 0, 0, 0, /* not source window -> move from anywhere */
288 //-----------------------------------------------------------------------------
289 // local code (see below)
290 //-----------------------------------------------------------------------------
292 // returns the child of win which currently has focus or NULL if not found
294 // Note: can't be static, needed by textctrl.cpp.
295 wxWindow
*wxFindFocusedChild(wxWindowGTK
*win
)
297 wxWindow
*winFocus
= wxWindowGTK::FindFocus();
299 return (wxWindow
*)NULL
;
301 if ( winFocus
== win
)
302 return (wxWindow
*)win
;
304 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
306 node
= node
->GetNext() )
308 wxWindow
*child
= wxFindFocusedChild(node
->GetData());
313 return (wxWindow
*)NULL
;
316 static void GetScrollbarWidth(GtkWidget
* widget
, int& w
, int& h
)
318 GtkScrolledWindow
* scroll_window
= GTK_SCROLLED_WINDOW(widget
);
319 GtkScrolledWindowClass
* scroll_class
= GTK_SCROLLED_WINDOW_CLASS(GTK_OBJECT_GET_CLASS(scroll_window
));
320 GtkRequisition scroll_req
;
323 if (scroll_window
->vscrollbar_visible
)
325 scroll_req
.width
= 2;
326 scroll_req
.height
= 2;
327 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
328 (scroll_window
->vscrollbar
, &scroll_req
);
329 w
= scroll_req
.width
+
330 scroll_class
->scrollbar_spacing
;
334 if (scroll_window
->hscrollbar_visible
)
336 scroll_req
.width
= 2;
337 scroll_req
.height
= 2;
338 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
339 (scroll_window
->hscrollbar
, &scroll_req
);
340 h
= scroll_req
.height
+
341 scroll_class
->scrollbar_spacing
;
345 static void draw_frame( GtkWidget
*widget
, wxWindowGTK
*win
)
347 // wxUniversal widgets draw the borders and scrollbars themselves
348 #ifndef __WXUNIVERSAL__
355 if (win
->m_hasScrolling
)
357 GetScrollbarWidth(widget
, dw
, dh
);
362 if (GTK_WIDGET_NO_WINDOW (widget
))
364 dx
+= widget
->allocation
.x
;
365 dy
+= widget
->allocation
.y
;
368 if (win
->HasFlag(wxRAISED_BORDER
))
370 gtk_paint_shadow (widget
->style
,
374 NULL
, NULL
, NULL
, // FIXME: No clipping?
376 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
380 if (win
->HasFlag(wxSUNKEN_BORDER
))
382 gtk_paint_shadow (widget
->style
,
386 NULL
, NULL
, NULL
, // FIXME: No clipping?
388 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
392 if (win
->HasFlag(wxSIMPLE_BORDER
))
395 gc
= gdk_gc_new( widget
->window
);
396 gdk_gc_set_foreground( gc
, &widget
->style
->black
);
397 gdk_draw_rectangle( widget
->window
, gc
, FALSE
,
399 widget
->allocation
.width
-dw
-1, widget
->allocation
.height
-dh
-1 );
400 g_object_unref (G_OBJECT (gc
));
403 #endif // __WXUNIVERSAL__
406 //-----------------------------------------------------------------------------
407 // "expose_event" of m_widget
408 //-----------------------------------------------------------------------------
412 gtk_window_own_expose_callback( GtkWidget
*widget
,
413 GdkEventExpose
*gdk_event
,
416 if (gdk_event
->count
> 0) return FALSE
;
418 draw_frame( widget
, win
);
420 (* GTK_WIDGET_CLASS (pizza_parent_class
)->expose_event
) (widget
, gdk_event
);
426 //-----------------------------------------------------------------------------
427 // "size_request" of m_widget
428 //-----------------------------------------------------------------------------
430 // make it extern because wxStaticText needs to disconnect this one
432 void wxgtk_window_size_request_callback(GtkWidget
*widget
,
433 GtkRequisition
*requisition
,
437 win
->GetSize( &w
, &h
);
443 requisition
->height
= h
;
444 requisition
->width
= w
;
450 void wxgtk_combo_size_request_callback(GtkWidget
*widget
,
451 GtkRequisition
*requisition
,
454 // This callback is actually hooked into the text entry
455 // of the combo box, not the GtkHBox.
458 win
->GetSize( &w
, &h
);
464 GtkCombo
*gcombo
= GTK_COMBO(win
->m_widget
);
466 GtkRequisition entry_req
;
468 entry_req
.height
= 2;
469 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo
->button
) )->size_request
)
470 (gcombo
->button
, &entry_req
);
472 requisition
->width
= w
- entry_req
.width
;
473 requisition
->height
= entry_req
.height
;
477 //-----------------------------------------------------------------------------
478 // "expose_event" of m_wxwindow
479 //-----------------------------------------------------------------------------
483 gtk_window_expose_callback( GtkWidget
*widget
,
484 GdkEventExpose
*gdk_event
,
490 wxapp_install_idle_handler();
492 // This callback gets called in drawing-idle time under
493 // GTK 2.0, so we don't need to defer anything to idle
496 GtkPizza
*pizza
= GTK_PIZZA( widget
);
497 if (gdk_event
->window
!= pizza
->bin_window
) return FALSE
;
502 wxPrintf( wxT("OnExpose from ") );
503 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
504 wxPrintf( win
->GetClassInfo()->GetClassName() );
505 wxPrintf( wxT(" %d %d %d %d\n"), (int)gdk_event
->area
.x
,
506 (int)gdk_event
->area
.y
,
507 (int)gdk_event
->area
.width
,
508 (int)gdk_event
->area
.height
);
513 win
->m_wxwindow
->style
,
517 (GdkRectangle
*) NULL
,
519 (char *)"button", // const_cast
524 win
->GetUpdateRegion() = wxRegion( gdk_event
->region
);
526 win
->GtkSendPaintEvents();
529 // Let parent window draw window-less widgets
530 (* GTK_WIDGET_CLASS (pizza_parent_class
)->expose_event
) (widget
, gdk_event
);
536 //-----------------------------------------------------------------------------
537 // "key_press_event" from any window
538 //-----------------------------------------------------------------------------
540 // set WXTRACE to this to see the key event codes on the console
541 #define TRACE_KEYS _T("keyevent")
543 // translates an X key symbol to WXK_XXX value
545 // if isChar is true it means that the value returned will be used for EVT_CHAR
546 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
547 // for example, while if it is false it means that the value is going to be
548 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
550 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
556 // Shift, Control and Alt don't generate the CHAR events at all
559 key_code
= isChar
? 0 : WXK_SHIFT
;
563 key_code
= isChar
? 0 : WXK_CONTROL
;
571 key_code
= isChar
? 0 : WXK_ALT
;
574 // neither do the toggle modifies
575 case GDK_Scroll_Lock
:
576 key_code
= isChar
? 0 : WXK_SCROLL
;
580 key_code
= isChar
? 0 : WXK_CAPITAL
;
584 key_code
= isChar
? 0 : WXK_NUMLOCK
;
588 // various other special keys
601 case GDK_ISO_Left_Tab
:
608 key_code
= WXK_RETURN
;
612 key_code
= WXK_CLEAR
;
616 key_code
= WXK_PAUSE
;
620 key_code
= WXK_SELECT
;
624 key_code
= WXK_PRINT
;
628 key_code
= WXK_EXECUTE
;
632 key_code
= WXK_ESCAPE
;
635 // cursor and other extended keyboard keys
637 key_code
= WXK_DELETE
;
653 key_code
= WXK_RIGHT
;
660 case GDK_Prior
: // == GDK_Page_Up
661 key_code
= WXK_PAGEUP
;
664 case GDK_Next
: // == GDK_Page_Down
665 key_code
= WXK_PAGEDOWN
;
677 key_code
= WXK_INSERT
;
692 key_code
= (isChar
? '0' : WXK_NUMPAD0
) + keysym
- GDK_KP_0
;
696 key_code
= isChar
? ' ' : WXK_NUMPAD_SPACE
;
700 key_code
= isChar
? WXK_TAB
: WXK_NUMPAD_TAB
;
704 key_code
= isChar
? WXK_RETURN
: WXK_NUMPAD_ENTER
;
708 key_code
= isChar
? WXK_F1
: WXK_NUMPAD_F1
;
712 key_code
= isChar
? WXK_F2
: WXK_NUMPAD_F2
;
716 key_code
= isChar
? WXK_F3
: WXK_NUMPAD_F3
;
720 key_code
= isChar
? WXK_F4
: WXK_NUMPAD_F4
;
724 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_HOME
;
728 key_code
= isChar
? WXK_LEFT
: WXK_NUMPAD_LEFT
;
732 key_code
= isChar
? WXK_UP
: WXK_NUMPAD_UP
;
736 key_code
= isChar
? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
740 key_code
= isChar
? WXK_DOWN
: WXK_NUMPAD_DOWN
;
743 case GDK_KP_Prior
: // == GDK_KP_Page_Up
744 key_code
= isChar
? WXK_PAGEUP
: WXK_NUMPAD_PAGEUP
;
747 case GDK_KP_Next
: // == GDK_KP_Page_Down
748 key_code
= isChar
? WXK_PAGEDOWN
: WXK_NUMPAD_PAGEDOWN
;
752 key_code
= isChar
? WXK_END
: WXK_NUMPAD_END
;
756 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_BEGIN
;
760 key_code
= isChar
? WXK_INSERT
: WXK_NUMPAD_INSERT
;
764 key_code
= isChar
? WXK_DELETE
: WXK_NUMPAD_DELETE
;
768 key_code
= isChar
? '=' : WXK_NUMPAD_EQUAL
;
771 case GDK_KP_Multiply
:
772 key_code
= isChar
? '*' : WXK_NUMPAD_MULTIPLY
;
776 key_code
= isChar
? '+' : WXK_NUMPAD_ADD
;
779 case GDK_KP_Separator
:
780 // FIXME: what is this?
781 key_code
= isChar
? '.' : WXK_NUMPAD_SEPARATOR
;
784 case GDK_KP_Subtract
:
785 key_code
= isChar
? '-' : WXK_NUMPAD_SUBTRACT
;
789 key_code
= isChar
? '.' : WXK_NUMPAD_DECIMAL
;
793 key_code
= isChar
? '/' : WXK_NUMPAD_DIVIDE
;
810 key_code
= WXK_F1
+ keysym
- GDK_F1
;
820 static inline bool wxIsAsciiKeysym(KeySym ks
)
825 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
827 GdkEventKey
*gdk_event
)
831 GdkModifierType state
;
832 if (gdk_event
->window
)
833 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
835 event
.SetTimestamp( gdk_event
->time
);
836 event
.SetId(win
->GetId());
837 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
838 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
839 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
840 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
) != 0;
841 event
.m_scanCode
= gdk_event
->keyval
;
842 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
843 event
.m_rawFlags
= 0;
845 event
.m_uniChar
= gdk_keyval_to_unicode(gdk_event
->keyval
);
847 wxGetMousePosition( &x
, &y
);
848 win
->ScreenToClient( &x
, &y
);
851 event
.SetEventObject( win
);
856 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
858 GdkEventKey
*gdk_event
)
860 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
861 // but only event->keyval which is quite useless to us, so remember
862 // the last character from GDK_KEY_PRESS and reuse it as last resort
864 // NB: should be MT-safe as we're always called from the main thread only
869 } s_lastKeyPress
= { 0, 0 };
871 KeySym keysym
= gdk_event
->keyval
;
873 wxLogTrace(TRACE_KEYS
, _T("Key %s event: keysym = %ld"),
874 event
.GetEventType() == wxEVT_KEY_UP
? _T("release")
878 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
882 // do we have the translation or is it a plain ASCII character?
883 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
885 // we should use keysym if it is ASCII as X does some translations
886 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
887 // which we don't want here (but which we do use for OnChar())
888 if ( !wxIsAsciiKeysym(keysym
) )
890 keysym
= (KeySym
)gdk_event
->string
[0];
893 // we want to always get the same key code when the same key is
894 // pressed regardless of the state of the modifiers, i.e. on a
895 // standard US keyboard pressing '5' or '%' ('5' key with
896 // Shift) should result in the same key code in OnKeyDown():
897 // '5' (although OnChar() will get either '5' or '%').
899 // to do it we first translate keysym to keycode (== scan code)
900 // and then back but always using the lower register
901 Display
*dpy
= (Display
*)wxGetDisplay();
902 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
904 wxLogTrace(TRACE_KEYS
, _T("\t-> keycode %d"), keycode
);
906 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
908 // use the normalized, i.e. lower register, keysym if we've
910 key_code
= keysymNormalized
? keysymNormalized
: keysym
;
912 // as explained above, we want to have lower register key codes
913 // normally but for the letter keys we want to have the upper ones
915 // NB: don't use XConvertCase() here, we want to do it for letters
917 key_code
= toupper(key_code
);
919 else // non ASCII key, what to do?
921 // by default, ignore it
924 // but if we have cached information from the last KEY_PRESS
925 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
928 if ( keysym
== s_lastKeyPress
.keysym
)
930 key_code
= s_lastKeyPress
.keycode
;
935 if ( gdk_event
->type
== GDK_KEY_PRESS
)
937 // remember it to be reused for KEY_UP event later
938 s_lastKeyPress
.keysym
= keysym
;
939 s_lastKeyPress
.keycode
= key_code
;
943 wxLogTrace(TRACE_KEYS
, _T("\t-> wxKeyCode %ld"), key_code
);
945 // sending unknown key events doesn't really make sense
949 // now fill all the other fields
950 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
952 event
.m_keyCode
= key_code
;
954 if ( gdk_event
->type
== GDK_KEY_PRESS
|| gdk_event
->type
== GDK_KEY_RELEASE
)
956 event
.m_uniChar
= key_code
;
966 GtkIMContext
*context
;
967 GdkEventKey
*lastKeyEvent
;
971 context
= gtk_im_multicontext_new();
976 g_object_unref(context
);
982 gtk_window_key_press_callback( GtkWidget
*widget
,
983 GdkEventKey
*gdk_event
,
989 wxapp_install_idle_handler();
993 if (g_blockEventsOnDrag
)
997 wxKeyEvent
event( wxEVT_KEY_DOWN
);
999 bool return_after_IM
= false;
1001 if( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1003 // Emit KEY_DOWN event
1004 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1008 // Return after IM processing as we cannot do
1009 // anything with it anyhow.
1010 return_after_IM
= true;
1013 // 2005.01.26 modified by Hong Jen Yee (hzysoft@sina.com.tw):
1014 // When we get a key_press event here, it could be originate
1015 // from the current widget or its child widgets. However, only the widget
1016 // with the INPUT FOCUS can generate the INITIAL key_press event. That is,
1017 // if the CURRENT widget doesn't have the FOCUS at all, this event definitely
1018 // originated from its child widgets and shouldn't be passed to IM context.
1019 // In fact, what a GTK+ IM should do is filtering keyEvents and convert them
1020 // into text input ONLY WHEN THE WIDGET HAS INPUT FOCUS. Besides, when current
1021 // widgets has both IM context and input focus, the event should be filtered
1022 // by gtk_im_context_filter_keypress().
1023 // Then, we should, according to GTK+ 2.0 API doc, return whatever it returns.
1024 if ((!ret
) && (win
->m_imData
!= NULL
) && ( wxWindow::FindFocus() == win
))
1026 // We should let GTK+ IM filter key event first. According to GTK+ 2.0 API
1027 // docs, if IM filter returns true, no further processing should be done.
1028 // we should send the key_down event anyway.
1029 bool intercepted_by_IM
= gtk_im_context_filter_keypress(win
->m_imData
->context
, gdk_event
);
1030 win
->m_imData
->lastKeyEvent
= NULL
;
1031 if (intercepted_by_IM
)
1033 wxLogTrace(TRACE_KEYS
, _T("Key event intercepted by IM"));
1038 if (return_after_IM
)
1044 wxWindowGTK
*ancestor
= win
;
1047 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1050 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1051 ret
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1054 if (ancestor
->IsTopLevel())
1056 ancestor
= ancestor
->GetParent();
1059 #endif // wxUSE_ACCEL
1061 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
1062 // will only be sent if it is not in an accelerator table.
1066 KeySym keysym
= gdk_event
->keyval
;
1067 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
1068 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
1071 if ( wxIsAsciiKeysym(keysym
) )
1074 key_code
= (unsigned char)keysym
;
1076 // gdk_event->string is actually deprecated
1077 else if ( gdk_event
->length
== 1 )
1079 key_code
= (unsigned char)gdk_event
->string
[0];
1085 wxLogTrace(TRACE_KEYS
, _T("Char event: %ld"), key_code
);
1087 event
.m_keyCode
= key_code
;
1089 // To conform to the docs we need to translate Ctrl-alpha
1090 // characters to values in the range 1-26.
1091 if (event
.ControlDown() && key_code
>= 'a' && key_code
<= 'z' )
1093 event
.m_keyCode
= key_code
- 'a' + 1;
1095 event
.m_uniChar
= event
.m_keyCode
;
1099 // Implement OnCharHook by checking ancestor top level windows
1100 wxWindow
*parent
= win
;
1101 while (parent
&& !parent
->IsTopLevel())
1102 parent
= parent
->GetParent();
1105 event
.SetEventType( wxEVT_CHAR_HOOK
);
1106 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1111 event
.SetEventType(wxEVT_CHAR
);
1112 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1121 // win is a control: tab can be propagated up
1123 ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
)) &&
1124 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here - the control may
1125 // have this style, yet choose not to process this particular TAB in which
1126 // case TAB must still work as a navigational character
1127 // JS: enabling again to make consistent with other platforms
1128 // (with wxTE_PROCESS_TAB you have to call Navigate to get default
1129 // navigation behaviour)
1131 (! (win
->HasFlag(wxTE_PROCESS_TAB
) && win
->IsKindOf(CLASSINFO(wxTextCtrl
)) )) &&
1133 win
->GetParent() && (win
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1135 wxNavigationKeyEvent new_event
;
1136 new_event
.SetEventObject( win
->GetParent() );
1137 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
1138 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
1139 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
1140 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
1141 new_event
.SetCurrentFocus( win
);
1142 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent( new_event
);
1145 // generate wxID_CANCEL if <esc> has been pressed (typically in dialogs)
1147 (gdk_event
->keyval
== GDK_Escape
) )
1149 // however only do it if we have a Cancel button in the dialog,
1150 // otherwise the user code may get confused by the events from a
1151 // non-existing button and, worse, a wxButton might get button event
1152 // from another button which is not really expected
1153 wxWindow
*winForCancel
= win
,
1155 while ( winForCancel
)
1157 btnCancel
= winForCancel
->FindWindow(wxID_CANCEL
);
1160 // found a cancel button
1164 if ( winForCancel
->IsTopLevel() )
1166 // no need to look further
1170 // maybe our parent has a cancel button?
1171 winForCancel
= winForCancel
->GetParent();
1176 wxCommandEvent
eventClick(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
1177 eventClick
.SetEventObject(btnCancel
);
1178 ret
= btnCancel
->GetEventHandler()->ProcessEvent(eventClick
);
1184 g_signal_stop_emission_by_name (widget
, "key_press_event");
1194 gtk_wxwindow_commit_cb (GtkIMContext
*context
,
1198 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1200 // take modifiers, cursor position, timestamp etc. from the last
1201 // key_press_event that was fed into Input Method:
1202 if (window
->m_imData
->lastKeyEvent
)
1204 wxFillOtherKeyEventFields(event
,
1205 window
, window
->m_imData
->lastKeyEvent
);
1208 const wxWxCharBuffer
data(wxGTK_CONV_BACK(str
));
1214 // Implement OnCharHook by checking ancestor top level windows
1215 wxWindow
*parent
= window
;
1216 while (parent
&& !parent
->IsTopLevel())
1217 parent
= parent
->GetParent();
1219 for( const wxChar
* pstr
= data
; *pstr
; pstr
++ )
1222 event
.m_uniChar
= *pstr
;
1223 // Backward compatible for ISO-8859-1
1224 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1225 wxLogTrace(TRACE_KEYS
, _T("IM sent character '%c'"), event
.m_uniChar
);
1227 event
.m_keyCode
= *pstr
;
1228 #endif // wxUSE_UNICODE
1230 // To conform to the docs we need to translate Ctrl-alpha
1231 // characters to values in the range 1-26.
1232 if (event
.ControlDown() && *pstr
>= 'a' && *pstr
<= 'z' )
1234 event
.m_keyCode
= *pstr
- 'a' + 1;
1236 event
.m_uniChar
= event
.m_keyCode
;
1242 event
.SetEventType( wxEVT_CHAR_HOOK
);
1243 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1248 event
.SetEventType(wxEVT_CHAR
);
1249 ret
= window
->GetEventHandler()->ProcessEvent( event
);
1256 //-----------------------------------------------------------------------------
1257 // "key_release_event" from any window
1258 //-----------------------------------------------------------------------------
1262 gtk_window_key_release_callback( GtkWidget
*widget
,
1263 GdkEventKey
*gdk_event
,
1269 wxapp_install_idle_handler();
1274 if (g_blockEventsOnDrag
)
1277 wxKeyEvent
event( wxEVT_KEY_UP
);
1278 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1280 // unknown key pressed, ignore (the event would be useless anyhow)
1284 if ( !win
->GetEventHandler()->ProcessEvent( event
) )
1287 g_signal_stop_emission_by_name (widget
, "key_release_event");
1292 // ============================================================================
1294 // ============================================================================
1296 // ----------------------------------------------------------------------------
1297 // mouse event processing helpers
1298 // ----------------------------------------------------------------------------
1300 // init wxMouseEvent with the info from GdkEventXXX struct
1301 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1302 wxMouseEvent
& event
,
1305 event
.SetTimestamp( gdk_event
->time
);
1306 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1307 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1308 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1309 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1310 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1311 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1312 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1313 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
1315 event
.m_linesPerAction
= 3;
1316 event
.m_wheelDelta
= 120;
1317 if (((GdkEventButton
*)gdk_event
)->button
== 4)
1318 event
.m_wheelRotation
= 120;
1319 else if (((GdkEventButton
*)gdk_event
)->button
== 5)
1320 event
.m_wheelRotation
= -120;
1323 wxPoint pt
= win
->GetClientAreaOrigin();
1324 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1325 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1327 event
.SetEventObject( win
);
1328 event
.SetId( win
->GetId() );
1329 event
.SetTimestamp( gdk_event
->time
);
1332 static void AdjustEventButtonState(wxMouseEvent
& event
)
1334 // GDK reports the old state of the button for a button press event, but
1335 // for compatibility with MSW and common sense we want m_leftDown be TRUE
1336 // for a LEFT_DOWN event, not FALSE, so we will invert
1337 // left/right/middleDown for the corresponding click events
1339 if ((event
.GetEventType() == wxEVT_LEFT_DOWN
) ||
1340 (event
.GetEventType() == wxEVT_LEFT_DCLICK
) ||
1341 (event
.GetEventType() == wxEVT_LEFT_UP
))
1343 event
.m_leftDown
= !event
.m_leftDown
;
1347 if ((event
.GetEventType() == wxEVT_MIDDLE_DOWN
) ||
1348 (event
.GetEventType() == wxEVT_MIDDLE_DCLICK
) ||
1349 (event
.GetEventType() == wxEVT_MIDDLE_UP
))
1351 event
.m_middleDown
= !event
.m_middleDown
;
1355 if ((event
.GetEventType() == wxEVT_RIGHT_DOWN
) ||
1356 (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) ||
1357 (event
.GetEventType() == wxEVT_RIGHT_UP
))
1359 event
.m_rightDown
= !event
.m_rightDown
;
1364 // find the window to send the mouse event too
1366 wxWindowGTK
*FindWindowForMouseEvent(wxWindowGTK
*win
, wxCoord
& x
, wxCoord
& y
)
1371 if (win
->m_wxwindow
)
1373 GtkPizza
*pizza
= GTK_PIZZA(win
->m_wxwindow
);
1374 xx
+= pizza
->xoffset
;
1375 yy
+= pizza
->yoffset
;
1378 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
1381 wxWindowGTK
*child
= node
->GetData();
1383 node
= node
->GetNext();
1384 if (!child
->IsShown())
1387 if (child
->IsTransparentForMouse())
1389 // wxStaticBox is transparent in the box itself
1390 int xx1
= child
->m_x
;
1391 int yy1
= child
->m_y
;
1392 int xx2
= child
->m_x
+ child
->m_width
;
1393 int yy2
= child
->m_y
+ child
->m_height
;
1396 if (((xx
>= xx1
) && (xx
<= xx1
+10) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1398 ((xx
>= xx2
-10) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1400 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy1
+10)) ||
1402 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy2
-1) && (yy
<= yy2
)))
1413 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1414 (child
->m_x
<= xx
) &&
1415 (child
->m_y
<= yy
) &&
1416 (child
->m_x
+child
->m_width
>= xx
) &&
1417 (child
->m_y
+child
->m_height
>= yy
))
1430 //-----------------------------------------------------------------------------
1431 // "button_press_event"
1432 //-----------------------------------------------------------------------------
1436 gtk_window_button_press_callback( GtkWidget
*widget
,
1437 GdkEventButton
*gdk_event
,
1443 wxapp_install_idle_handler();
1446 wxPrintf( wxT("1) OnButtonPress from ") );
1447 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1448 wxPrintf( win->GetClassInfo()->GetClassName() );
1449 wxPrintf( wxT(".\n") );
1451 if (!win
->m_hasVMT
) return FALSE
;
1452 if (g_blockEventsOnDrag
) return TRUE
;
1453 if (g_blockEventsOnScroll
) return TRUE
;
1455 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1457 if (win
->m_wxwindow
&& (g_focusWindow
!= win
) && win
->AcceptsFocus())
1459 gtk_widget_grab_focus( win
->m_wxwindow
);
1461 wxPrintf( wxT("GrabFocus from ") );
1462 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1463 wxPrintf( win->GetClassInfo()->GetClassName() );
1464 wxPrintf( wxT(".\n") );
1468 // GDK sends surplus button down events
1469 // before a double click event. We
1470 // need to filter these out.
1471 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1473 GdkEvent
*peek_event
= gdk_event_peek();
1476 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1477 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1479 gdk_event_free( peek_event
);
1484 gdk_event_free( peek_event
);
1489 wxEventType event_type
= wxEVT_NULL
;
1491 // GdkDisplay is a GTK+ 2.2.0 thing
1492 #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2, 2, 0)
1493 if ( gdk_event
->type
== GDK_2BUTTON_PRESS
&&
1494 !gtk_check_version(2,2,0) &&
1495 gdk_event
->button
>= 1 && gdk_event
->button
<= 3 )
1497 // Reset GDK internal timestamp variables in order to disable GDK
1498 // triple click events. GDK will then next time believe no button has
1499 // been clicked just before, and send a normal button click event.
1500 GdkDisplay
* display
= gtk_widget_get_display (widget
);
1501 display
->button_click_time
[1] = 0;
1502 display
->button_click_time
[0] = 0;
1506 if (gdk_event
->button
== 1)
1508 // note that GDK generates triple click events which are not supported
1509 // by wxWidgets but still have to be passed to the app as otherwise
1510 // clicks would simply go missing
1511 switch (gdk_event
->type
)
1513 // we shouldn't get triple clicks at all for GTK2 because we
1514 // suppress them artificially using the code above but we still
1515 // should map them to something for GTK1 and not just ignore them
1516 // as this would lose clicks
1517 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1518 case GDK_BUTTON_PRESS
:
1519 event_type
= wxEVT_LEFT_DOWN
;
1522 case GDK_2BUTTON_PRESS
:
1523 event_type
= wxEVT_LEFT_DCLICK
;
1527 // just to silence gcc warnings
1531 else if (gdk_event
->button
== 2)
1533 switch (gdk_event
->type
)
1535 case GDK_3BUTTON_PRESS
:
1536 case GDK_BUTTON_PRESS
:
1537 event_type
= wxEVT_MIDDLE_DOWN
;
1540 case GDK_2BUTTON_PRESS
:
1541 event_type
= wxEVT_MIDDLE_DCLICK
;
1548 else if (gdk_event
->button
== 3)
1550 switch (gdk_event
->type
)
1552 case GDK_3BUTTON_PRESS
:
1553 case GDK_BUTTON_PRESS
:
1554 event_type
= wxEVT_RIGHT_DOWN
;
1557 case GDK_2BUTTON_PRESS
:
1558 event_type
= wxEVT_RIGHT_DCLICK
;
1565 else if (gdk_event
->button
== 4 || gdk_event
->button
== 5)
1567 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1569 event_type
= wxEVT_MOUSEWHEEL
;
1573 if ( event_type
== wxEVT_NULL
)
1575 // unknown mouse button or click type
1579 wxMouseEvent
event( event_type
);
1580 InitMouseEvent( win
, event
, gdk_event
);
1582 AdjustEventButtonState(event
);
1584 // wxListBox actually gets mouse events from the item, so we need to give it
1585 // a chance to correct this
1586 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1588 // find the correct window to send the event to: it may be a different one
1589 // from the one which got it at GTK+ level because some controls don't have
1590 // their own X window and thus cannot get any events.
1591 if ( !g_captureWindow
)
1592 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1594 // reset the event object and id in case win changed.
1595 event
.SetEventObject( win
);
1596 event
.SetId( win
->GetId() );
1598 if (win
->GetEventHandler()->ProcessEvent( event
))
1600 g_signal_stop_emission_by_name (widget
, "button_press_event");
1604 if (event_type
== wxEVT_RIGHT_DOWN
)
1606 // generate a "context menu" event: this is similar to right mouse
1607 // click under many GUIs except that it is generated differently
1608 // (right up under MSW, ctrl-click under Mac, right down here) and
1610 // (a) it's a command event and so is propagated to the parent
1611 // (b) under some ports it can be generated from kbd too
1612 // (c) it uses screen coords (because of (a))
1613 wxContextMenuEvent
evtCtx(
1616 win
->ClientToScreen(event
.GetPosition()));
1617 evtCtx
.SetEventObject(win
);
1618 return win
->GetEventHandler()->ProcessEvent(evtCtx
);
1625 //-----------------------------------------------------------------------------
1626 // "button_release_event"
1627 //-----------------------------------------------------------------------------
1631 gtk_window_button_release_callback( GtkWidget
*widget
,
1632 GdkEventButton
*gdk_event
,
1638 wxapp_install_idle_handler();
1640 if (!win
->m_hasVMT
) return FALSE
;
1641 if (g_blockEventsOnDrag
) return FALSE
;
1642 if (g_blockEventsOnScroll
) return FALSE
;
1644 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1646 wxEventType event_type
= wxEVT_NULL
;
1648 switch (gdk_event
->button
)
1651 event_type
= wxEVT_LEFT_UP
;
1655 event_type
= wxEVT_MIDDLE_UP
;
1659 event_type
= wxEVT_RIGHT_UP
;
1663 // unknwon button, don't process
1667 wxMouseEvent
event( event_type
);
1668 InitMouseEvent( win
, event
, gdk_event
);
1670 AdjustEventButtonState(event
);
1672 // same wxListBox hack as above
1673 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1675 if ( !g_captureWindow
)
1676 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1678 // reset the event object and id in case win changed.
1679 event
.SetEventObject( win
);
1680 event
.SetId( win
->GetId() );
1682 if (win
->GetEventHandler()->ProcessEvent( event
))
1684 g_signal_stop_emission_by_name (widget
, "button_release_event");
1692 //-----------------------------------------------------------------------------
1693 // "motion_notify_event"
1694 //-----------------------------------------------------------------------------
1698 gtk_window_motion_notify_callback( GtkWidget
*widget
,
1699 GdkEventMotion
*gdk_event
,
1705 wxapp_install_idle_handler();
1707 if (!win
->m_hasVMT
) return FALSE
;
1708 if (g_blockEventsOnDrag
) return FALSE
;
1709 if (g_blockEventsOnScroll
) return FALSE
;
1711 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1713 if (gdk_event
->is_hint
)
1717 GdkModifierType state
;
1718 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1724 printf( "OnMotion from " );
1725 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1726 printf( win->GetClassInfo()->GetClassName() );
1730 wxMouseEvent
event( wxEVT_MOTION
);
1731 InitMouseEvent(win
, event
, gdk_event
);
1733 if ( g_captureWindow
)
1735 // synthetize a mouse enter or leave event if needed
1736 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1737 // This seems to be necessary and actually been added to
1738 // GDK itself in version 2.0.X
1741 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1742 if ( hasMouse
!= g_captureWindowHasMouse
)
1744 // the mouse changed window
1745 g_captureWindowHasMouse
= hasMouse
;
1747 wxMouseEvent
eventM(g_captureWindowHasMouse
? wxEVT_ENTER_WINDOW
1748 : wxEVT_LEAVE_WINDOW
);
1749 InitMouseEvent(win
, eventM
, gdk_event
);
1750 eventM
.SetEventObject(win
);
1751 win
->GetEventHandler()->ProcessEvent(eventM
);
1756 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1758 // reset the event object and id in case win changed.
1759 event
.SetEventObject( win
);
1760 event
.SetId( win
->GetId() );
1763 if ( !g_captureWindow
)
1765 wxSetCursorEvent
cevent( event
.m_x
, event
.m_y
);
1766 if (win
->GetEventHandler()->ProcessEvent( cevent
))
1768 // Rewrite cursor handling here (away from idle).
1772 if (win
->GetEventHandler()->ProcessEvent( event
))
1774 g_signal_stop_emission_by_name (widget
, "motion_notify_event");
1782 //-----------------------------------------------------------------------------
1783 // "scroll_event", (mouse wheel event)
1784 //-----------------------------------------------------------------------------
1788 window_scroll_event(GtkWidget
*, GdkEventScroll
* gdk_event
, wxWindow
* win
)
1793 wxapp_install_idle_handler();
1795 if (gdk_event
->direction
!= GDK_SCROLL_UP
&&
1796 gdk_event
->direction
!= GDK_SCROLL_DOWN
)
1801 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
1802 // Can't use InitMouse macro because scroll events don't have button
1803 event
.SetTimestamp( gdk_event
->time
);
1804 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1805 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1806 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1807 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1808 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1809 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1810 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1811 event
.m_linesPerAction
= 3;
1812 event
.m_wheelDelta
= 120;
1813 if (gdk_event
->direction
== GDK_SCROLL_UP
)
1814 event
.m_wheelRotation
= 120;
1816 event
.m_wheelRotation
= -120;
1818 wxPoint pt
= win
->GetClientAreaOrigin();
1819 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1820 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1822 event
.SetEventObject( win
);
1823 event
.SetId( win
->GetId() );
1824 event
.SetTimestamp( gdk_event
->time
);
1826 return win
->GetEventHandler()->ProcessEvent(event
);
1830 //-----------------------------------------------------------------------------
1832 //-----------------------------------------------------------------------------
1834 static gboolean
wxgtk_window_popup_menu_callback(GtkWidget
*, wxWindowGTK
* win
)
1836 wxContextMenuEvent
event(
1840 event
.SetEventObject(win
);
1841 return win
->GetEventHandler()->ProcessEvent(event
);
1845 //-----------------------------------------------------------------------------
1847 //-----------------------------------------------------------------------------
1849 // send the wxChildFocusEvent and wxFocusEvent, common code of
1850 // gtk_window_focus_in_callback() and SetFocus()
1851 static bool DoSendFocusEvents(wxWindow
*win
)
1853 // Notify the parent keeping track of focus for the kbd navigation
1854 // purposes that we got it.
1855 wxChildFocusEvent
eventChildFocus(win
);
1856 (void)win
->GetEventHandler()->ProcessEvent(eventChildFocus
);
1858 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, win
->GetId());
1859 eventFocus
.SetEventObject(win
);
1861 return win
->GetEventHandler()->ProcessEvent(eventFocus
);
1866 gtk_window_focus_in_callback( GtkWidget
*widget
,
1867 GdkEventFocus
*WXUNUSED(event
),
1873 wxapp_install_idle_handler();
1876 gtk_im_context_focus_in(win
->m_imData
->context
);
1879 g_focusWindow
= win
;
1881 wxLogTrace(TRACE_FOCUS
,
1882 _T("%s: focus in"), win
->GetName().c_str());
1886 gdk_im_begin(win
->m_ic
, win
->m_wxwindow
->window
);
1890 // caret needs to be informed about focus change
1891 wxCaret
*caret
= win
->GetCaret();
1894 caret
->OnSetFocus();
1896 #endif // wxUSE_CARET
1898 gboolean ret
= FALSE
;
1900 // does the window itself think that it has the focus?
1901 if ( !win
->m_hasFocus
)
1903 // not yet, notify it
1904 win
->m_hasFocus
= true;
1906 (void)DoSendFocusEvents(win
);
1911 // Disable default focus handling for custom windows
1912 // since the default GTK+ handler issues a repaint
1913 if (win
->m_wxwindow
)
1920 //-----------------------------------------------------------------------------
1921 // "focus_out_event"
1922 //-----------------------------------------------------------------------------
1926 gtk_window_focus_out_callback( GtkWidget
*widget
,
1927 GdkEventFocus
*gdk_event
,
1933 wxapp_install_idle_handler();
1936 gtk_im_context_focus_out(win
->m_imData
->context
);
1938 wxLogTrace( TRACE_FOCUS
,
1939 _T("%s: focus out"), win
->GetName().c_str() );
1942 wxWindowGTK
*winFocus
= wxFindFocusedChild(win
);
1946 g_focusWindow
= (wxWindowGTK
*)NULL
;
1954 // caret needs to be informed about focus change
1955 wxCaret
*caret
= win
->GetCaret();
1958 caret
->OnKillFocus();
1960 #endif // wxUSE_CARET
1962 gboolean ret
= FALSE
;
1964 // don't send the window a kill focus event if it thinks that it doesn't
1965 // have focus already
1966 if ( win
->m_hasFocus
)
1968 win
->m_hasFocus
= false;
1970 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
1971 event
.SetEventObject( win
);
1973 (void)win
->GetEventHandler()->ProcessEvent( event
);
1978 // Disable default focus handling for custom windows
1979 // since the default GTK+ handler issues a repaint
1980 if (win
->m_wxwindow
)
1987 //-----------------------------------------------------------------------------
1988 // "enter_notify_event"
1989 //-----------------------------------------------------------------------------
1993 gtk_window_enter_callback( GtkWidget
*widget
,
1994 GdkEventCrossing
*gdk_event
,
2000 wxapp_install_idle_handler();
2002 if (!win
->m_hasVMT
) return FALSE
;
2003 if (g_blockEventsOnDrag
) return FALSE
;
2005 // Event was emitted after a grab
2006 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
2008 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
2012 GdkModifierType state
= (GdkModifierType
)0;
2014 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
2016 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
2017 InitMouseEvent(win
, event
, gdk_event
);
2018 wxPoint pt
= win
->GetClientAreaOrigin();
2019 event
.m_x
= x
+ pt
.x
;
2020 event
.m_y
= y
+ pt
.y
;
2022 if ( !g_captureWindow
)
2024 wxSetCursorEvent
cevent( event
.m_x
, event
.m_y
);
2025 if (win
->GetEventHandler()->ProcessEvent( cevent
))
2027 // Rewrite cursor handling here (away from idle).
2031 if (win
->GetEventHandler()->ProcessEvent( event
))
2033 g_signal_stop_emission_by_name (widget
, "enter_notify_event");
2041 //-----------------------------------------------------------------------------
2042 // "leave_notify_event"
2043 //-----------------------------------------------------------------------------
2047 gtk_window_leave_callback( GtkWidget
*widget
,
2048 GdkEventCrossing
*gdk_event
,
2054 wxapp_install_idle_handler();
2056 if (!win
->m_hasVMT
) return FALSE
;
2057 if (g_blockEventsOnDrag
) return FALSE
;
2059 // Event was emitted after an ungrab
2060 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
2062 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
2064 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
2065 event
.SetTimestamp( gdk_event
->time
);
2066 event
.SetEventObject( win
);
2070 GdkModifierType state
= (GdkModifierType
)0;
2072 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
2074 event
.m_shiftDown
= (state
& GDK_SHIFT_MASK
) != 0;
2075 event
.m_controlDown
= (state
& GDK_CONTROL_MASK
) != 0;
2076 event
.m_altDown
= (state
& GDK_MOD1_MASK
) != 0;
2077 event
.m_metaDown
= (state
& GDK_MOD2_MASK
) != 0;
2078 event
.m_leftDown
= (state
& GDK_BUTTON1_MASK
) != 0;
2079 event
.m_middleDown
= (state
& GDK_BUTTON2_MASK
) != 0;
2080 event
.m_rightDown
= (state
& GDK_BUTTON3_MASK
) != 0;
2082 wxPoint pt
= win
->GetClientAreaOrigin();
2083 event
.m_x
= x
+ pt
.x
;
2084 event
.m_y
= y
+ pt
.y
;
2086 if (win
->GetEventHandler()->ProcessEvent( event
))
2088 g_signal_stop_emission_by_name (widget
, "leave_notify_event");
2096 //-----------------------------------------------------------------------------
2097 // "value_changed" from m_vAdjust
2098 //-----------------------------------------------------------------------------
2101 static void gtk_window_vscroll_callback( GtkAdjustment
*adjust
,
2107 wxapp_install_idle_handler();
2109 if (g_blockEventsOnDrag
) return;
2111 if (!win
->m_hasVMT
) return;
2113 float diff
= adjust
->value
- win
->m_oldVerticalPos
;
2114 if (fabs(diff
) < 0.2) return;
2116 win
->m_oldVerticalPos
= adjust
->value
;
2118 wxEventType command
= GtkScrollWinTypeToWx(GTK_SCROLL_JUMP
);
2120 int value
= (int)(adjust
->value
+0.5);
2122 wxScrollWinEvent
event( command
, value
, wxVERTICAL
);
2123 event
.SetEventObject( win
);
2124 win
->GetEventHandler()->ProcessEvent( event
);
2128 //-----------------------------------------------------------------------------
2129 // "value_changed" from m_hAdjust
2130 //-----------------------------------------------------------------------------
2133 static void gtk_window_hscroll_callback( GtkAdjustment
*adjust
,
2139 wxapp_install_idle_handler();
2141 if (g_blockEventsOnDrag
) return;
2142 if (!win
->m_hasVMT
) return;
2144 float diff
= adjust
->value
- win
->m_oldHorizontalPos
;
2145 if (fabs(diff
) < 0.2) return;
2147 wxEventType command
= GtkScrollWinTypeToWx(GTK_SCROLL_JUMP
);
2149 win
->m_oldHorizontalPos
= adjust
->value
;
2151 int value
= (int)(adjust
->value
+0.5);
2153 wxScrollWinEvent
event( command
, value
, wxHORIZONTAL
);
2154 event
.SetEventObject( win
);
2155 win
->GetEventHandler()->ProcessEvent( event
);
2159 //-----------------------------------------------------------------------------
2160 // "button_press_event" from scrollbar
2161 //-----------------------------------------------------------------------------
2165 gtk_scrollbar_button_press_callback( GtkWidget
*widget
,
2166 GdkEventButton
*gdk_event
,
2172 wxapp_install_idle_handler();
2175 g_blockEventsOnScroll
= true;
2177 // FIXME: there is no 'slider' field in GTK+ 2.0 any more
2179 win
->m_isScrolling
= (gdk_event
->window
== widget
->slider
);
2186 //-----------------------------------------------------------------------------
2187 // "button_release_event" from scrollbar
2188 //-----------------------------------------------------------------------------
2192 gtk_scrollbar_button_release_callback( GtkRange
*widget
,
2193 GdkEventButton
*WXUNUSED(gdk_event
),
2198 // don't test here as we can release the mouse while being over
2199 // a different window than the slider
2201 // if (gdk_event->window != widget->slider) return FALSE;
2203 g_blockEventsOnScroll
= false;
2205 if (win
->m_isScrolling
)
2207 wxEventType command
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2211 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2212 if (widget
== GTK_RANGE(scrolledWindow
->hscrollbar
))
2214 value
= (int)(win
->m_hAdjust
->value
+0.5);
2217 if (widget
== GTK_RANGE(scrolledWindow
->vscrollbar
))
2219 value
= (int)(win
->m_vAdjust
->value
+0.5);
2223 wxScrollWinEvent
event( command
, value
, dir
);
2224 event
.SetEventObject( win
);
2225 win
->GetEventHandler()->ProcessEvent( event
);
2228 win
->m_isScrolling
= false;
2234 // ----------------------------------------------------------------------------
2235 // this wxWindowBase function is implemented here (in platform-specific file)
2236 // because it is static and so couldn't be made virtual
2237 // ----------------------------------------------------------------------------
2239 wxWindow
*wxWindowBase::DoFindFocus()
2241 // the cast is necessary when we compile in wxUniversal mode
2242 return (wxWindow
*)g_focusWindow
;
2245 //-----------------------------------------------------------------------------
2246 // "realize" from m_widget
2247 //-----------------------------------------------------------------------------
2249 /* We cannot set colours and fonts before the widget has
2250 been realized, so we do this directly after realization. */
2254 gtk_window_realized_callback( GtkWidget
*m_widget
, wxWindow
*win
)
2259 wxapp_install_idle_handler();
2263 GtkPizza
*pizza
= GTK_PIZZA( m_widget
);
2264 gtk_im_context_set_client_window( win
->m_imData
->context
,
2265 pizza
->bin_window
);
2268 wxWindowCreateEvent
event( win
);
2269 event
.SetEventObject( win
);
2270 win
->GetEventHandler()->ProcessEvent( event
);
2274 //-----------------------------------------------------------------------------
2276 //-----------------------------------------------------------------------------
2280 void gtk_window_size_callback( GtkWidget
*WXUNUSED(widget
),
2281 GtkAllocation
*WXUNUSED(alloc
),
2285 wxapp_install_idle_handler();
2287 if (!win
->m_hasScrolling
) return;
2289 int client_width
= 0;
2290 int client_height
= 0;
2291 win
->GetClientSize( &client_width
, &client_height
);
2292 if ((client_width
== win
->m_oldClientWidth
) && (client_height
== win
->m_oldClientHeight
))
2295 win
->m_oldClientWidth
= client_width
;
2296 win
->m_oldClientHeight
= client_height
;
2298 if (!win
->m_nativeSizeEvent
)
2300 wxSizeEvent
event( win
->GetSize(), win
->GetId() );
2301 event
.SetEventObject( win
);
2302 win
->GetEventHandler()->ProcessEvent( event
);
2309 #define WXUNUSED_UNLESS_XIM(param) param
2311 #define WXUNUSED_UNLESS_XIM(param) WXUNUSED(param)
2314 /* Resize XIM window */
2318 void gtk_wxwindow_size_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2319 GtkAllocation
* WXUNUSED_UNLESS_XIM(alloc
),
2320 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2323 wxapp_install_idle_handler();
2329 if (gdk_ic_get_style (win
->m_ic
) & GDK_IM_PREEDIT_POSITION
)
2333 gdk_drawable_get_size (widget
->window
, &width
, &height
);
2334 win
->m_icattr
->preedit_area
.width
= width
;
2335 win
->m_icattr
->preedit_area
.height
= height
;
2336 gdk_ic_set_attr (win
->m_ic
, win
->m_icattr
, GDK_IC_PREEDIT_AREA
);
2342 //-----------------------------------------------------------------------------
2343 // "realize" from m_wxwindow
2344 //-----------------------------------------------------------------------------
2346 /* Initialize XIM support */
2350 gtk_wxwindow_realized_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2351 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2354 wxapp_install_idle_handler();
2357 if (win
->m_ic
) return;
2358 if (!widget
) return;
2359 if (!gdk_im_ready()) return;
2361 win
->m_icattr
= gdk_ic_attr_new();
2362 if (!win
->m_icattr
) return;
2366 GdkColormap
*colormap
;
2367 GdkICAttr
*attr
= win
->m_icattr
;
2368 unsigned attrmask
= GDK_IC_ALL_REQ
;
2370 GdkIMStyle supported_style
= (GdkIMStyle
)
2371 (GDK_IM_PREEDIT_NONE
|
2372 GDK_IM_PREEDIT_NOTHING
|
2373 GDK_IM_PREEDIT_POSITION
|
2374 GDK_IM_STATUS_NONE
|
2375 GDK_IM_STATUS_NOTHING
);
2377 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2378 supported_style
= (GdkIMStyle
)(supported_style
& ~GDK_IM_PREEDIT_POSITION
);
2380 attr
->style
= style
= gdk_im_decide_style (supported_style
);
2381 attr
->client_window
= widget
->window
;
2383 if ((colormap
= gtk_widget_get_colormap (widget
)) !=
2384 gtk_widget_get_default_colormap ())
2386 attrmask
|= GDK_IC_PREEDIT_COLORMAP
;
2387 attr
->preedit_colormap
= colormap
;
2390 attrmask
|= GDK_IC_PREEDIT_FOREGROUND
;
2391 attrmask
|= GDK_IC_PREEDIT_BACKGROUND
;
2392 attr
->preedit_foreground
= widget
->style
->fg
[GTK_STATE_NORMAL
];
2393 attr
->preedit_background
= widget
->style
->base
[GTK_STATE_NORMAL
];
2395 switch (style
& GDK_IM_PREEDIT_MASK
)
2397 case GDK_IM_PREEDIT_POSITION
:
2398 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2400 g_warning ("over-the-spot style requires fontset");
2404 gdk_drawable_get_size (widget
->window
, &width
, &height
);
2406 attrmask
|= GDK_IC_PREEDIT_POSITION_REQ
;
2407 attr
->spot_location
.x
= 0;
2408 attr
->spot_location
.y
= height
;
2409 attr
->preedit_area
.x
= 0;
2410 attr
->preedit_area
.y
= 0;
2411 attr
->preedit_area
.width
= width
;
2412 attr
->preedit_area
.height
= height
;
2413 attr
->preedit_fontset
= widget
->style
->font
;
2418 win
->m_ic
= gdk_ic_new (attr
, (GdkICAttributesType
)attrmask
);
2420 if (win
->m_ic
== NULL
)
2421 g_warning ("Can't create input context.");
2424 mask
= gdk_window_get_events (widget
->window
);
2425 mask
= (GdkEventMask
)(mask
| gdk_ic_get_events (win
->m_ic
));
2426 gdk_window_set_events (widget
->window
, mask
);
2428 if (GTK_WIDGET_HAS_FOCUS(widget
))
2429 gdk_im_begin (win
->m_ic
, widget
->window
);
2435 //-----------------------------------------------------------------------------
2436 // InsertChild for wxWindowGTK.
2437 //-----------------------------------------------------------------------------
2439 /* Callback for wxWindowGTK. This very strange beast has to be used because
2440 * C++ has no virtual methods in a constructor. We have to emulate a
2441 * virtual function here as wxNotebook requires a different way to insert
2442 * a child in it. I had opted for creating a wxNotebookPage window class
2443 * which would have made this superfluous (such in the MDI window system),
2444 * but no-one was listening to me... */
2446 static void wxInsertChildInWindow( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2448 /* the window might have been scrolled already, do we
2449 have to adapt the position */
2450 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
2451 child
->m_x
+= pizza
->xoffset
;
2452 child
->m_y
+= pizza
->yoffset
;
2454 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
2455 GTK_WIDGET(child
->m_widget
),
2462 //-----------------------------------------------------------------------------
2464 //-----------------------------------------------------------------------------
2466 wxWindow
*wxGetActiveWindow()
2468 return wxWindow::FindFocus();
2472 wxMouseState
wxGetMouseState()
2478 GdkModifierType mask
;
2480 gdk_window_get_pointer(NULL
, &x
, &y
, &mask
);
2484 ms
.SetLeftDown(mask
& GDK_BUTTON1_MASK
);
2485 ms
.SetMiddleDown(mask
& GDK_BUTTON2_MASK
);
2486 ms
.SetRightDown(mask
& GDK_BUTTON3_MASK
);
2488 ms
.SetControlDown(mask
& GDK_CONTROL_MASK
);
2489 ms
.SetShiftDown(mask
& GDK_SHIFT_MASK
);
2490 ms
.SetAltDown(mask
& GDK_MOD1_MASK
);
2491 ms
.SetMetaDown(mask
& GDK_MOD2_MASK
);
2496 //-----------------------------------------------------------------------------
2498 //-----------------------------------------------------------------------------
2500 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2502 #ifdef __WXUNIVERSAL__
2503 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2505 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
2506 #endif // __WXUNIVERSAL__/__WXGTK__
2508 void wxWindowGTK::Init()
2511 m_widget
= (GtkWidget
*) NULL
;
2512 m_wxwindow
= (GtkWidget
*) NULL
;
2513 m_focusWidget
= (GtkWidget
*) NULL
;
2523 m_needParent
= true;
2524 m_isBeingDeleted
= false;
2527 m_nativeSizeEvent
= false;
2529 m_hasScrolling
= false;
2530 m_isScrolling
= false;
2532 m_hAdjust
= (GtkAdjustment
*) NULL
;
2533 m_vAdjust
= (GtkAdjustment
*) NULL
;
2534 m_oldHorizontalPos
=
2535 m_oldVerticalPos
= 0.0;
2537 m_oldClientHeight
= 0;
2541 m_insertCallback
= (wxInsertChildFunction
) NULL
;
2543 m_acceptsFocus
= false;
2546 m_clipPaintRegion
= false;
2548 m_needsStyleChange
= false;
2550 m_cursor
= *wxSTANDARD_CURSOR
;
2553 m_dirtyTabOrder
= false;
2556 wxWindowGTK::wxWindowGTK()
2561 wxWindowGTK::wxWindowGTK( wxWindow
*parent
,
2566 const wxString
&name
)
2570 Create( parent
, id
, pos
, size
, style
, name
);
2573 bool wxWindowGTK::Create( wxWindow
*parent
,
2578 const wxString
&name
)
2580 if (!PreCreation( parent
, pos
, size
) ||
2581 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2583 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2587 m_insertCallback
= wxInsertChildInWindow
;
2589 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
2590 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
2592 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2594 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2595 scroll_class
->scrollbar_spacing
= 0;
2597 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2599 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
2600 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
2602 m_wxwindow
= gtk_pizza_new();
2604 #ifndef __WXUNIVERSAL__
2605 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
2607 if (HasFlag(wxRAISED_BORDER
))
2609 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
2611 else if (HasFlag(wxSUNKEN_BORDER
))
2613 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
2615 else if (HasFlag(wxSIMPLE_BORDER
))
2617 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
2621 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
2623 #endif // __WXUNIVERSAL__
2625 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2627 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
2628 m_acceptsFocus
= true;
2630 // I _really_ don't want scrollbars in the beginning
2631 m_vAdjust
->lower
= 0.0;
2632 m_vAdjust
->upper
= 1.0;
2633 m_vAdjust
->value
= 0.0;
2634 m_vAdjust
->step_increment
= 1.0;
2635 m_vAdjust
->page_increment
= 1.0;
2636 m_vAdjust
->page_size
= 5.0;
2637 g_signal_emit_by_name (m_vAdjust
, "changed");
2638 m_hAdjust
->lower
= 0.0;
2639 m_hAdjust
->upper
= 1.0;
2640 m_hAdjust
->value
= 0.0;
2641 m_hAdjust
->step_increment
= 1.0;
2642 m_hAdjust
->page_increment
= 1.0;
2643 m_hAdjust
->page_size
= 5.0;
2644 g_signal_emit_by_name (m_hAdjust
, "changed");
2646 // these handlers block mouse events to any window during scrolling such as
2647 // motion events and prevent GTK and wxWidgets from fighting over where the
2649 g_signal_connect (scrolledWindow
->vscrollbar
, "button_press_event",
2650 G_CALLBACK (gtk_scrollbar_button_press_callback
), this);
2651 g_signal_connect (scrolledWindow
->hscrollbar
, "button_press_event",
2652 G_CALLBACK (gtk_scrollbar_button_press_callback
), this);
2653 g_signal_connect (scrolledWindow
->vscrollbar
, "button_release_event",
2654 G_CALLBACK (gtk_scrollbar_button_release_callback
), this);
2655 g_signal_connect (scrolledWindow
->hscrollbar
, "button_release_event",
2656 G_CALLBACK (gtk_scrollbar_button_release_callback
), this);
2658 // these handlers get notified when screen updates are required either when
2659 // scrolling or when the window size (and therefore scrollbar configuration)
2662 g_signal_connect (m_hAdjust
, "value_changed",
2663 G_CALLBACK (gtk_window_hscroll_callback
), this);
2664 g_signal_connect (m_vAdjust
, "value_changed",
2665 G_CALLBACK (gtk_window_vscroll_callback
), this);
2667 gtk_widget_show( m_wxwindow
);
2670 m_parent
->DoAddChild( this );
2672 m_focusWidget
= m_wxwindow
;
2679 wxWindowGTK::~wxWindowGTK()
2683 if (g_focusWindow
== this)
2684 g_focusWindow
= NULL
;
2686 if ( g_delayedFocus
== this )
2687 g_delayedFocus
= NULL
;
2689 m_isBeingDeleted
= true;
2692 // destroy children before destroying this window itself
2695 // unhook focus handlers to prevent stray events being
2696 // propagated to this (soon to be) dead object
2697 if (m_focusWidget
!= NULL
)
2699 g_signal_handlers_disconnect_by_func (m_focusWidget
,
2700 (gpointer
) gtk_window_focus_in_callback
,
2702 g_signal_handlers_disconnect_by_func (m_focusWidget
,
2703 (gpointer
) gtk_window_focus_out_callback
,
2712 gdk_ic_destroy (m_ic
);
2714 gdk_ic_attr_destroy (m_icattr
);
2717 // delete before the widgets to avoid a crash on solaris
2722 gtk_widget_destroy( m_wxwindow
);
2723 m_wxwindow
= (GtkWidget
*) NULL
;
2728 gtk_widget_destroy( m_widget
);
2729 m_widget
= (GtkWidget
*) NULL
;
2733 bool wxWindowGTK::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2735 wxCHECK_MSG( !m_needParent
|| parent
, false, wxT("Need complete parent.") );
2737 // Use either the given size, or the default if -1 is given.
2738 // See wxWindowBase for these functions.
2739 m_width
= WidthDefault(size
.x
) ;
2740 m_height
= HeightDefault(size
.y
);
2748 void wxWindowGTK::PostCreation()
2750 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2756 // these get reported to wxWidgets -> wxPaintEvent
2758 gtk_pizza_set_external( GTK_PIZZA(m_wxwindow
), TRUE
);
2760 g_signal_connect (m_wxwindow
, "expose_event",
2761 G_CALLBACK (gtk_window_expose_callback
), this);
2763 gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow
), HasFlag( wxFULL_REPAINT_ON_RESIZE
) );
2766 // Create input method handler
2767 m_imData
= new wxGtkIMData
;
2769 // Cannot handle drawing preedited text yet
2770 gtk_im_context_set_use_preedit( m_imData
->context
, FALSE
);
2772 g_signal_connect (m_imData
->context
, "commit",
2773 G_CALLBACK (gtk_wxwindow_commit_cb
), this);
2775 // these are called when the "sunken" or "raised" borders are drawn
2776 g_signal_connect (m_widget
, "expose_event",
2777 G_CALLBACK (gtk_window_own_expose_callback
), this);
2782 if (!GTK_IS_WINDOW(m_widget
))
2784 if (m_focusWidget
== NULL
)
2785 m_focusWidget
= m_widget
;
2789 g_signal_connect (m_focusWidget
, "focus_in_event",
2790 G_CALLBACK (gtk_window_focus_in_callback
), this);
2791 g_signal_connect (m_focusWidget
, "focus_out_event",
2792 G_CALLBACK (gtk_window_focus_out_callback
), this);
2796 g_signal_connect_after (m_focusWidget
, "focus_in_event",
2797 G_CALLBACK (gtk_window_focus_in_callback
), this);
2798 g_signal_connect_after (m_focusWidget
, "focus_out_event",
2799 G_CALLBACK (gtk_window_focus_out_callback
), this);
2803 // connect to the various key and mouse handlers
2805 GtkWidget
*connect_widget
= GetConnectWidget();
2807 ConnectWidget( connect_widget
);
2809 /* We cannot set colours, fonts and cursors before the widget has
2810 been realized, so we do this directly after realization */
2811 g_signal_connect (connect_widget
, "realize",
2812 G_CALLBACK (gtk_window_realized_callback
), this);
2816 // Catch native resize events
2817 g_signal_connect (m_wxwindow
, "size_allocate",
2818 G_CALLBACK (gtk_window_size_callback
), this);
2820 // Initialize XIM support
2821 g_signal_connect (m_wxwindow
, "realize",
2822 G_CALLBACK (gtk_wxwindow_realized_callback
), this);
2824 // And resize XIM window
2825 g_signal_connect (m_wxwindow
, "size_allocate",
2826 G_CALLBACK (gtk_wxwindow_size_callback
), this);
2829 if (GTK_IS_COMBO(m_widget
))
2831 GtkCombo
*gcombo
= GTK_COMBO(m_widget
);
2833 g_signal_connect (gcombo
->entry
, "size_request",
2834 G_CALLBACK (wxgtk_combo_size_request_callback
),
2839 // This is needed if we want to add our windows into native
2840 // GTK controls, such as the toolbar. With this callback, the
2841 // toolbar gets to know the correct size (the one set by the
2842 // programmer). Sadly, it misbehaves for wxComboBox.
2843 g_signal_connect (m_widget
, "size_request",
2844 G_CALLBACK (wxgtk_window_size_request_callback
),
2848 InheritAttributes();
2852 // unless the window was created initially hidden (i.e. Hide() had been
2853 // called before Create()), we should show it at GTK+ level as well
2855 gtk_widget_show( m_widget
);
2858 void wxWindowGTK::ConnectWidget( GtkWidget
*widget
)
2860 g_signal_connect (widget
, "key_press_event",
2861 G_CALLBACK (gtk_window_key_press_callback
), this);
2862 g_signal_connect (widget
, "key_release_event",
2863 G_CALLBACK (gtk_window_key_release_callback
), this);
2864 g_signal_connect (widget
, "button_press_event",
2865 G_CALLBACK (gtk_window_button_press_callback
), this);
2866 g_signal_connect (widget
, "button_release_event",
2867 G_CALLBACK (gtk_window_button_release_callback
), this);
2868 g_signal_connect (widget
, "motion_notify_event",
2869 G_CALLBACK (gtk_window_motion_notify_callback
), this);
2870 g_signal_connect (widget
, "scroll_event",
2871 G_CALLBACK (window_scroll_event
), this);
2872 g_signal_connect (widget
, "popup_menu",
2873 G_CALLBACK (wxgtk_window_popup_menu_callback
), this);
2874 g_signal_connect (widget
, "enter_notify_event",
2875 G_CALLBACK (gtk_window_enter_callback
), this);
2876 g_signal_connect (widget
, "leave_notify_event",
2877 G_CALLBACK (gtk_window_leave_callback
), this);
2880 bool wxWindowGTK::Destroy()
2882 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2886 return wxWindowBase::Destroy();
2889 void wxWindowGTK::DoMoveWindow(int x
, int y
, int width
, int height
)
2891 gtk_pizza_set_size( GTK_PIZZA(m_parent
->m_wxwindow
), m_widget
, x
, y
, width
, height
);
2894 void wxWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
2896 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2897 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
2900 printf( "DoSetSize: name %s, x,y,w,h: %d,%d,%d,%d \n", GetName().c_str(), x,y,width,height );
2903 if (m_resizing
) return; /* I don't like recursions */
2906 int currentX
, currentY
;
2907 GetPosition(¤tX
, ¤tY
);
2908 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2910 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2912 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2914 // calculate the best size if we should auto size the window
2915 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
2916 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
2918 const wxSize sizeBest
= GetBestSize();
2919 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
2921 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
2922 height
= sizeBest
.y
;
2930 int minWidth
= GetMinWidth(),
2931 minHeight
= GetMinHeight(),
2932 maxWidth
= GetMaxWidth(),
2933 maxHeight
= GetMaxHeight();
2935 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
2936 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
2937 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
2938 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
2940 #if wxUSE_TOOLBAR_NATIVE
2941 if (wxDynamicCast(GetParent(), wxToolBar
))
2943 // don't take the x,y values, they're wrong because toolbar sets them
2944 GtkWidget
*widget
= GTK_WIDGET(m_widget
);
2945 gtk_widget_set_size_request (widget
, m_width
, m_height
);
2946 if (GTK_WIDGET_VISIBLE (widget
))
2947 gtk_widget_queue_resize (widget
);
2951 if (m_parent
->m_wxwindow
== NULL
) // i.e. wxNotebook
2953 // don't set the size for children of wxNotebook, just take the values.
2961 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
2962 if ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0)
2964 if (x
!= -1) m_x
= x
+ pizza
->xoffset
;
2965 if (y
!= -1) m_y
= y
+ pizza
->yoffset
;
2969 m_x
= x
+ pizza
->xoffset
;
2970 m_y
= y
+ pizza
->yoffset
;
2973 int left_border
= 0;
2974 int right_border
= 0;
2976 int bottom_border
= 0;
2978 /* the default button has a border around it */
2979 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
2981 GtkBorder
*default_border
= NULL
;
2982 gtk_widget_style_get( m_widget
, "default_border", &default_border
, NULL
);
2985 left_border
+= default_border
->left
;
2986 right_border
+= default_border
->right
;
2987 top_border
+= default_border
->top
;
2988 bottom_border
+= default_border
->bottom
;
2989 g_free( default_border
);
2993 DoMoveWindow( m_x
-top_border
,
2995 m_width
+left_border
+right_border
,
2996 m_height
+top_border
+bottom_border
);
3001 /* Sometimes the client area changes size without the
3002 whole windows's size changing, but if the whole
3003 windows's size doesn't change, no wxSizeEvent will
3004 normally be sent. Here we add an extra test if
3005 the client test has been changed and this will
3007 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
3011 wxPrintf( "OnSize sent from " );
3012 if (GetClassInfo() && GetClassInfo()->GetClassName())
3013 wxPrintf( GetClassInfo()->GetClassName() );
3014 wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height );
3017 if (!m_nativeSizeEvent
)
3019 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
3020 event
.SetEventObject( this );
3021 GetEventHandler()->ProcessEvent( event
);
3027 void wxWindowGTK::OnInternalIdle()
3029 if ( m_dirtyTabOrder
)
3031 m_dirtyTabOrder
= false;
3035 // Update style if the window was not yet realized
3036 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
3037 if (m_needsStyleChange
)
3039 SetBackgroundStyle(GetBackgroundStyle());
3040 m_needsStyleChange
= false;
3043 // Update invalidated regions.
3046 wxCursor cursor
= m_cursor
;
3047 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
3051 /* I now set the cursor anew in every OnInternalIdle call
3052 as setting the cursor in a parent window also effects the
3053 windows above so that checking for the current cursor is
3058 GdkWindow
*window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3060 gdk_window_set_cursor( window
, cursor
.GetCursor() );
3062 if (!g_globalCursor
.Ok())
3063 cursor
= *wxSTANDARD_CURSOR
;
3065 window
= m_widget
->window
;
3066 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
3067 gdk_window_set_cursor( window
, cursor
.GetCursor() );
3073 GdkWindow
*window
= m_widget
->window
;
3074 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
3075 gdk_window_set_cursor( window
, cursor
.GetCursor() );
3080 if (wxUpdateUIEvent::CanUpdate(this))
3081 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
3084 void wxWindowGTK::DoGetSize( int *width
, int *height
) const
3086 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3088 if (width
) (*width
) = m_width
;
3089 if (height
) (*height
) = m_height
;
3092 void wxWindowGTK::DoSetClientSize( int width
, int height
)
3094 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3103 GetScrollbarWidth(m_widget
, dw
, dh
);
3106 #ifndef __WXUNIVERSAL__
3107 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
3109 // shadow border size is 2
3113 if (HasFlag(wxSIMPLE_BORDER
))
3115 // simple border size is 1
3119 #endif // __WXUNIVERSAL__
3125 SetSize(width
, height
);
3128 void wxWindowGTK::DoGetClientSize( int *width
, int *height
) const
3130 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3142 GetScrollbarWidth(m_widget
, dw
, dh
);
3145 #ifndef __WXUNIVERSAL__
3146 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
3148 // shadow border size is 2
3152 if (HasFlag(wxSIMPLE_BORDER
))
3154 // simple border size is 1
3158 #endif // __WXUNIVERSAL__
3164 if (width
) *width
= w
;
3165 if (height
) *height
= h
;
3168 void wxWindowGTK::DoGetPosition( int *x
, int *y
) const
3170 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3174 if (m_parent
&& m_parent
->m_wxwindow
)
3176 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
3177 dx
= pizza
->xoffset
;
3178 dy
= pizza
->yoffset
;
3181 if (x
) (*x
) = m_x
- dx
;
3182 if (y
) (*y
) = m_y
- dy
;
3185 void wxWindowGTK::DoClientToScreen( int *x
, int *y
) const
3187 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3189 if (!m_widget
->window
) return;
3191 GdkWindow
*source
= (GdkWindow
*) NULL
;
3193 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3195 source
= m_widget
->window
;
3199 gdk_window_get_origin( source
, &org_x
, &org_y
);
3203 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3205 org_x
+= m_widget
->allocation
.x
;
3206 org_y
+= m_widget
->allocation
.y
;
3214 void wxWindowGTK::DoScreenToClient( int *x
, int *y
) const
3216 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3218 if (!m_widget
->window
) return;
3220 GdkWindow
*source
= (GdkWindow
*) NULL
;
3222 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3224 source
= m_widget
->window
;
3228 gdk_window_get_origin( source
, &org_x
, &org_y
);
3232 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3234 org_x
+= m_widget
->allocation
.x
;
3235 org_y
+= m_widget
->allocation
.y
;
3243 bool wxWindowGTK::Show( bool show
)
3245 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3247 if (!wxWindowBase::Show(show
))
3254 gtk_widget_show( m_widget
);
3256 gtk_widget_hide( m_widget
);
3258 wxShowEvent
eventShow(GetId(), show
);
3259 eventShow
.SetEventObject(this);
3261 GetEventHandler()->ProcessEvent(eventShow
);
3266 static void wxWindowNotifyEnable(wxWindowGTK
* win
, bool enable
)
3268 win
->OnParentEnable(enable
);
3270 // Recurse, so that children have the opportunity to Do The Right Thing
3271 // and reset colours that have been messed up by a parent's (really ancestor's)
3273 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3275 node
= node
->GetNext() )
3277 wxWindow
*child
= node
->GetData();
3278 if (!child
->IsKindOf(CLASSINFO(wxDialog
)) && !child
->IsKindOf(CLASSINFO(wxFrame
)))
3279 wxWindowNotifyEnable(child
, enable
);
3283 bool wxWindowGTK::Enable( bool enable
)
3285 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3287 if (!wxWindowBase::Enable(enable
))
3293 gtk_widget_set_sensitive( m_widget
, enable
);
3295 gtk_widget_set_sensitive( m_wxwindow
, enable
);
3297 wxWindowNotifyEnable(this, enable
);
3302 int wxWindowGTK::GetCharHeight() const
3304 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
3306 wxFont font
= GetFont();
3307 wxCHECK_MSG( font
.Ok(), 12, wxT("invalid font") );
3309 PangoContext
*context
= NULL
;
3311 context
= gtk_widget_get_pango_context( m_widget
);
3316 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
3317 PangoLayout
*layout
= pango_layout_new(context
);
3318 pango_layout_set_font_description(layout
, desc
);
3319 pango_layout_set_text(layout
, "H", 1);
3320 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
3322 PangoRectangle rect
;
3323 pango_layout_line_get_extents(line
, NULL
, &rect
);
3325 g_object_unref( G_OBJECT( layout
) );
3327 return (int) PANGO_PIXELS(rect
.height
);
3330 int wxWindowGTK::GetCharWidth() const
3332 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
3334 wxFont font
= GetFont();
3335 wxCHECK_MSG( font
.Ok(), 8, wxT("invalid font") );
3337 PangoContext
*context
= NULL
;
3339 context
= gtk_widget_get_pango_context( m_widget
);
3344 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
3345 PangoLayout
*layout
= pango_layout_new(context
);
3346 pango_layout_set_font_description(layout
, desc
);
3347 pango_layout_set_text(layout
, "g", 1);
3348 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
3350 PangoRectangle rect
;
3351 pango_layout_line_get_extents(line
, NULL
, &rect
);
3353 g_object_unref( G_OBJECT( layout
) );
3355 return (int) PANGO_PIXELS(rect
.width
);
3358 void wxWindowGTK::GetTextExtent( const wxString
& string
,
3362 int *externalLeading
,
3363 const wxFont
*theFont
) const
3365 wxFont fontToUse
= theFont
? *theFont
: GetFont();
3367 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
3376 PangoContext
*context
= NULL
;
3378 context
= gtk_widget_get_pango_context( m_widget
);
3387 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
3388 PangoLayout
*layout
= pango_layout_new(context
);
3389 pango_layout_set_font_description(layout
, desc
);
3391 const wxCharBuffer data
= wxGTK_CONV( string
);
3393 pango_layout_set_text(layout
, data
, strlen(data
));
3396 PangoRectangle rect
;
3397 pango_layout_get_extents(layout
, NULL
, &rect
);
3399 if (x
) (*x
) = (wxCoord
) PANGO_PIXELS(rect
.width
);
3400 if (y
) (*y
) = (wxCoord
) PANGO_PIXELS(rect
.height
);
3403 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
3404 int baseline
= pango_layout_iter_get_baseline(iter
);
3405 pango_layout_iter_free(iter
);
3406 *descent
= *y
- PANGO_PIXELS(baseline
);
3408 if (externalLeading
) (*externalLeading
) = 0; // ??
3410 g_object_unref( G_OBJECT( layout
) );
3413 void wxWindowGTK::SetFocus()
3415 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3418 // don't do anything if we already have focus
3424 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow
))
3426 gtk_widget_grab_focus (m_wxwindow
);
3431 if (GTK_IS_CONTAINER(m_widget
))
3433 gtk_widget_child_focus( m_widget
, GTK_DIR_TAB_FORWARD
);
3436 if (GTK_WIDGET_CAN_FOCUS(m_widget
) && !GTK_WIDGET_HAS_FOCUS (m_widget
) )
3439 if (!GTK_WIDGET_REALIZED(m_widget
))
3441 // we can't set the focus to the widget now so we remember that
3442 // it should be focused and will do it later, during the idle
3443 // time, as soon as we can
3444 wxLogTrace(TRACE_FOCUS
,
3445 _T("Delaying setting focus to %s(%s)"),
3446 GetClassInfo()->GetClassName(), GetLabel().c_str());
3448 g_delayedFocus
= this;
3452 wxLogTrace(TRACE_FOCUS
,
3453 _T("Setting focus to %s(%s)"),
3454 GetClassInfo()->GetClassName(), GetLabel().c_str());
3456 gtk_widget_grab_focus (m_widget
);
3461 wxLogTrace(TRACE_FOCUS
,
3462 _T("Can't set focus to %s(%s)"),
3463 GetClassInfo()->GetClassName(), GetLabel().c_str());
3468 bool wxWindowGTK::AcceptsFocus() const
3470 return m_acceptsFocus
&& wxWindowBase::AcceptsFocus();
3473 bool wxWindowGTK::Reparent( wxWindowBase
*newParentBase
)
3475 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3477 wxWindowGTK
*oldParent
= m_parent
,
3478 *newParent
= (wxWindowGTK
*)newParentBase
;
3480 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3482 if ( !wxWindowBase::Reparent(newParent
) )
3485 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3487 /* prevent GTK from deleting the widget arbitrarily */
3488 gtk_widget_ref( m_widget
);
3492 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3495 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3499 /* insert GTK representation */
3500 (*(newParent
->m_insertCallback
))(newParent
, this);
3503 /* reverse: prevent GTK from deleting the widget arbitrarily */
3504 gtk_widget_unref( m_widget
);
3509 void wxWindowGTK::DoAddChild(wxWindowGTK
*child
)
3511 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3513 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3515 wxASSERT_MSG( (m_insertCallback
!= NULL
), wxT("invalid child insertion function") );
3520 /* insert GTK representation */
3521 (*m_insertCallback
)(this, child
);
3524 void wxWindowGTK::AddChild(wxWindowBase
*child
)
3526 wxWindowBase::AddChild(child
);
3527 m_dirtyTabOrder
= true;
3529 wxapp_install_idle_handler();
3532 void wxWindowGTK::RemoveChild(wxWindowBase
*child
)
3534 wxWindowBase::RemoveChild(child
);
3535 m_dirtyTabOrder
= true;
3537 wxapp_install_idle_handler();
3540 void wxWindowGTK::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
3542 wxWindowBase::DoMoveInTabOrder(win
, move
);
3543 m_dirtyTabOrder
= true;
3545 wxapp_install_idle_handler();
3548 bool wxWindowGTK::GTKWidgetNeedsMnemonic() const
3550 // none needed by default
3554 void wxWindowGTK::GTKWidgetDoSetMnemonic(GtkWidget
* WXUNUSED(w
))
3556 // nothing to do by default since none is needed
3559 void wxWindowGTK::RealizeTabOrder()
3563 if ( !m_children
.empty() )
3565 // we don't only construct the correct focus chain but also use
3566 // this opportunity to update the mnemonic widgets for the widgets
3569 GList
*chain
= NULL
;
3570 wxWindowGTK
* mnemonicWindow
= NULL
;
3572 for ( wxWindowList::const_iterator i
= m_children
.begin();
3573 i
!= m_children
.end();
3576 wxWindowGTK
*win
= *i
;
3578 if ( mnemonicWindow
)
3580 if ( win
->AcceptsFocusFromKeyboard() )
3582 // wxComboBox et al. needs to focus on on a different
3583 // widget than m_widget, so if the main widget isn't
3584 // focusable try the connect widget
3585 GtkWidget
* w
= win
->m_widget
;
3586 if ( !GTK_WIDGET_CAN_FOCUS(w
) )
3588 w
= win
->GetConnectWidget();
3589 if ( !GTK_WIDGET_CAN_FOCUS(w
) )
3595 mnemonicWindow
->GTKWidgetDoSetMnemonic(w
);
3596 mnemonicWindow
= NULL
;
3600 else if ( win
->GTKWidgetNeedsMnemonic() )
3602 mnemonicWindow
= win
;
3605 chain
= g_list_prepend(chain
, win
->m_widget
);
3608 chain
= g_list_reverse(chain
);
3610 gtk_container_set_focus_chain(GTK_CONTAINER(m_wxwindow
), chain
);
3615 gtk_container_unset_focus_chain(GTK_CONTAINER(m_wxwindow
));
3620 void wxWindowGTK::Raise()
3622 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3624 if (m_wxwindow
&& m_wxwindow
->window
)
3626 gdk_window_raise( m_wxwindow
->window
);
3628 else if (m_widget
->window
)
3630 gdk_window_raise( m_widget
->window
);
3634 void wxWindowGTK::Lower()
3636 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3638 if (m_wxwindow
&& m_wxwindow
->window
)
3640 gdk_window_lower( m_wxwindow
->window
);
3642 else if (m_widget
->window
)
3644 gdk_window_lower( m_widget
->window
);
3648 bool wxWindowGTK::SetCursor( const wxCursor
&cursor
)
3650 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3652 if (cursor
== m_cursor
)
3656 wxapp_install_idle_handler();
3658 if (cursor
== wxNullCursor
)
3659 return wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
);
3661 return wxWindowBase::SetCursor( cursor
);
3664 void wxWindowGTK::WarpPointer( int x
, int y
)
3666 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3668 // We provide this function ourselves as it is
3669 // missing in GDK (top of this file).
3671 GdkWindow
*window
= (GdkWindow
*) NULL
;
3673 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3675 window
= GetConnectWidget()->window
;
3678 gdk_window_warp_pointer( window
, x
, y
);
3681 static bool wxScrollAdjust(GtkAdjustment
* adj
, double change
)
3683 double value_start
= adj
->value
;
3684 double value
= value_start
+ change
;
3685 double upper
= adj
->upper
- adj
->page_size
;
3690 // Lower bound will be checked by gtk_adjustment_set_value
3691 gtk_adjustment_set_value(adj
, value
);
3692 return adj
->value
!= value_start
;
3695 bool wxWindowGTK::ScrollLines(int lines
)
3698 m_vAdjust
!= NULL
&&
3699 wxScrollAdjust(m_vAdjust
, lines
* m_vAdjust
->step_increment
);
3702 bool wxWindowGTK::ScrollPages(int pages
)
3705 m_vAdjust
!= NULL
&&
3706 wxScrollAdjust(m_vAdjust
, pages
* m_vAdjust
->page_increment
);
3709 void wxWindowGTK::SetVScrollAdjustment(GtkAdjustment
* adj
)
3711 wxASSERT(m_vAdjust
== NULL
);
3715 void wxWindowGTK::Refresh( bool eraseBackground
, const wxRect
*rect
)
3719 if (!m_widget
->window
)
3724 GdkRectangle gdk_rect
,
3728 gdk_rect
.x
= rect
->x
;
3729 gdk_rect
.y
= rect
->y
;
3730 gdk_rect
.width
= rect
->width
;
3731 gdk_rect
.height
= rect
->height
;
3734 else // invalidate everything
3739 gdk_window_invalidate_rect( GTK_PIZZA(m_wxwindow
)->bin_window
, p
, TRUE
);
3743 void wxWindowGTK::Update()
3747 // when we call Update() we really want to update the window immediately on
3748 // screen, even if it means flushing the entire queue and hence slowing down
3749 // everything -- but it should still be done, it's just that Update() should
3750 // be called very rarely
3754 void wxWindowGTK::GtkUpdate()
3756 if (m_wxwindow
&& GTK_PIZZA(m_wxwindow
)->bin_window
)
3757 gdk_window_process_updates( GTK_PIZZA(m_wxwindow
)->bin_window
, FALSE
);
3759 // for consistency with other platforms (and also because it's convenient
3760 // to be able to update an entire TLW by calling Update() only once), we
3761 // should also update all our children here
3762 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3764 node
= node
->GetNext() )
3766 node
->GetData()->GtkUpdate();
3770 void wxWindowGTK::GtkSendPaintEvents()
3774 m_updateRegion
.Clear();
3778 // Clip to paint region in wxClientDC
3779 m_clipPaintRegion
= true;
3781 // widget to draw on
3782 GtkPizza
*pizza
= GTK_PIZZA (m_wxwindow
);
3784 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM
))
3786 // find ancestor from which to steal background
3787 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3789 parent
= (wxWindow
*)this;
3791 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
3793 wxRegionIterator
upd( m_updateRegion
);
3797 rect
.x
= upd
.GetX();
3798 rect
.y
= upd
.GetY();
3799 rect
.width
= upd
.GetWidth();
3800 rect
.height
= upd
.GetHeight();
3802 gtk_paint_flat_box( parent
->m_widget
->style
,
3804 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
3818 wxWindowDC
dc( (wxWindow
*)this );
3819 dc
.SetClippingRegion( m_updateRegion
);
3821 wxEraseEvent
erase_event( GetId(), &dc
);
3822 erase_event
.SetEventObject( this );
3824 GetEventHandler()->ProcessEvent(erase_event
);
3827 wxNcPaintEvent
nc_paint_event( GetId() );
3828 nc_paint_event
.SetEventObject( this );
3829 GetEventHandler()->ProcessEvent( nc_paint_event
);
3831 wxPaintEvent
paint_event( GetId() );
3832 paint_event
.SetEventObject( this );
3833 GetEventHandler()->ProcessEvent( paint_event
);
3835 m_clipPaintRegion
= false;
3837 m_updateRegion
.Clear();
3840 void wxWindowGTK::ClearBackground()
3842 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3846 void wxWindowGTK::DoSetToolTip( wxToolTip
*tip
)
3848 wxWindowBase::DoSetToolTip(tip
);
3851 m_tooltip
->Apply( (wxWindow
*)this );
3854 void wxWindowGTK::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
3856 wxString
tmp( tip
);
3857 gtk_tooltips_set_tip( tips
, GetConnectWidget(), wxGTK_CONV(tmp
), (gchar
*) NULL
);
3859 #endif // wxUSE_TOOLTIPS
3861 bool wxWindowGTK::SetBackgroundColour( const wxColour
&colour
)
3863 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3865 if (!wxWindowBase::SetBackgroundColour(colour
))
3870 // We need the pixel value e.g. for background clearing.
3871 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3874 // apply style change (forceStyle=true so that new style is applied
3875 // even if the bg colour changed from valid to wxNullColour)
3876 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3877 ApplyWidgetStyle(true);
3882 bool wxWindowGTK::SetForegroundColour( const wxColour
&colour
)
3884 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3886 if (!wxWindowBase::SetForegroundColour(colour
))
3893 // We need the pixel value e.g. for background clearing.
3894 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3897 // apply style change (forceStyle=true so that new style is applied
3898 // even if the bg colour changed from valid to wxNullColour):
3899 ApplyWidgetStyle(true);
3904 PangoContext
*wxWindowGTK::GtkGetPangoDefaultContext()
3906 return gtk_widget_get_pango_context( m_widget
);
3909 GtkRcStyle
*wxWindowGTK::CreateWidgetStyle(bool forceStyle
)
3911 // do we need to apply any changes at all?
3914 !m_foregroundColour
.Ok() && !m_backgroundColour
.Ok() )
3919 GtkRcStyle
*style
= gtk_rc_style_new();
3924 pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
3927 if ( m_foregroundColour
.Ok() )
3929 GdkColor
*fg
= m_foregroundColour
.GetColor();
3931 style
->fg
[GTK_STATE_NORMAL
] = *fg
;
3932 style
->color_flags
[GTK_STATE_NORMAL
] = GTK_RC_FG
;
3934 style
->fg
[GTK_STATE_PRELIGHT
] = *fg
;
3935 style
->color_flags
[GTK_STATE_PRELIGHT
] = GTK_RC_FG
;
3937 style
->fg
[GTK_STATE_ACTIVE
] = *fg
;
3938 style
->color_flags
[GTK_STATE_ACTIVE
] = GTK_RC_FG
;
3941 if ( m_backgroundColour
.Ok() )
3943 GdkColor
*bg
= m_backgroundColour
.GetColor();
3945 style
->bg
[GTK_STATE_NORMAL
] = *bg
;
3946 style
->base
[GTK_STATE_NORMAL
] = *bg
;
3947 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)
3948 (style
->color_flags
[GTK_STATE_NORMAL
] | GTK_RC_BG
| GTK_RC_BASE
);
3950 style
->bg
[GTK_STATE_PRELIGHT
] = *bg
;
3951 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
3952 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)
3953 (style
->color_flags
[GTK_STATE_PRELIGHT
] | GTK_RC_BG
| GTK_RC_BASE
);
3955 style
->bg
[GTK_STATE_ACTIVE
] = *bg
;
3956 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
3957 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)
3958 (style
->color_flags
[GTK_STATE_ACTIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3960 style
->bg
[GTK_STATE_INSENSITIVE
] = *bg
;
3961 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
3962 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)
3963 (style
->color_flags
[GTK_STATE_INSENSITIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3969 void wxWindowGTK::ApplyWidgetStyle(bool forceStyle
)
3971 GtkRcStyle
*style
= CreateWidgetStyle(forceStyle
);
3974 DoApplyWidgetStyle(style
);
3975 gtk_rc_style_unref(style
);
3978 // Style change may affect GTK+'s size calculation:
3979 InvalidateBestSize();
3982 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle
*style
)
3985 gtk_widget_modify_style(m_wxwindow
, style
);
3987 gtk_widget_modify_style(m_widget
, style
);
3990 bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style
)
3992 wxWindowBase::SetBackgroundStyle(style
);
3994 if (style
== wxBG_STYLE_CUSTOM
)
3996 GdkWindow
*window
= (GdkWindow
*) NULL
;
3998 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4000 window
= GetConnectWidget()->window
;
4004 // Make sure GDK/X11 doesn't refresh the window
4006 gdk_window_set_back_pixmap( window
, None
, False
);
4008 Display
* display
= GDK_WINDOW_DISPLAY(window
);
4011 m_needsStyleChange
= false;
4014 // Do in OnIdle, because the window is not yet available
4015 m_needsStyleChange
= true;
4017 // Don't apply widget style, or we get a grey background
4021 // apply style change (forceStyle=true so that new style is applied
4022 // even if the bg colour changed from valid to wxNullColour):
4023 ApplyWidgetStyle(true);
4028 #if wxUSE_DRAG_AND_DROP
4030 void wxWindowGTK::SetDropTarget( wxDropTarget
*dropTarget
)
4032 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4034 GtkWidget
*dnd_widget
= GetConnectWidget();
4036 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
4038 if (m_dropTarget
) delete m_dropTarget
;
4039 m_dropTarget
= dropTarget
;
4041 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
4044 #endif // wxUSE_DRAG_AND_DROP
4046 GtkWidget
* wxWindowGTK::GetConnectWidget()
4048 GtkWidget
*connect_widget
= m_widget
;
4049 if (m_wxwindow
) connect_widget
= m_wxwindow
;
4051 return connect_widget
;
4054 bool wxWindowGTK::IsOwnGtkWindow( GdkWindow
*window
)
4057 return (window
== GTK_PIZZA(m_wxwindow
)->bin_window
);
4059 return (window
== m_widget
->window
);
4062 bool wxWindowGTK::SetFont( const wxFont
&font
)
4064 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
4066 if (!wxWindowBase::SetFont(font
))
4069 // apply style change (forceStyle=true so that new style is applied
4070 // even if the font changed from valid to wxNullFont):
4071 ApplyWidgetStyle(true);
4076 void wxWindowGTK::DoCaptureMouse()
4078 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4080 GdkWindow
*window
= (GdkWindow
*) NULL
;
4082 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4084 window
= GetConnectWidget()->window
;
4086 wxCHECK_RET( window
, _T("CaptureMouse() failed") );
4088 const wxCursor
* cursor
= &m_cursor
;
4090 cursor
= wxSTANDARD_CURSOR
;
4092 gdk_pointer_grab( window
, FALSE
,
4094 (GDK_BUTTON_PRESS_MASK
|
4095 GDK_BUTTON_RELEASE_MASK
|
4096 GDK_POINTER_MOTION_HINT_MASK
|
4097 GDK_POINTER_MOTION_MASK
),
4099 cursor
->GetCursor(),
4100 (guint32
)GDK_CURRENT_TIME
);
4101 g_captureWindow
= this;
4102 g_captureWindowHasMouse
= true;
4105 void wxWindowGTK::DoReleaseMouse()
4107 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4109 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
4111 g_captureWindow
= (wxWindowGTK
*) NULL
;
4113 GdkWindow
*window
= (GdkWindow
*) NULL
;
4115 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4117 window
= GetConnectWidget()->window
;
4122 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
4126 wxWindow
*wxWindowBase::GetCapture()
4128 return (wxWindow
*)g_captureWindow
;
4131 bool wxWindowGTK::IsRetained() const
4136 void wxWindowGTK::SetScrollbar( int orient
, int pos
, int thumbVisible
,
4137 int range
, bool refresh
)
4139 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4141 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4143 m_hasScrolling
= true;
4145 if (orient
== wxHORIZONTAL
)
4147 float fpos
= (float)pos
;
4148 float frange
= (float)range
;
4149 float fthumb
= (float)thumbVisible
;
4150 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
4151 if (fpos
< 0.0) fpos
= 0.0;
4153 if ((fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
4154 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
4156 SetScrollPos( orient
, pos
, refresh
);
4160 m_oldHorizontalPos
= fpos
;
4162 m_hAdjust
->lower
= 0.0;
4163 m_hAdjust
->upper
= frange
;
4164 m_hAdjust
->value
= fpos
;
4165 m_hAdjust
->step_increment
= 1.0;
4166 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4167 m_hAdjust
->page_size
= fthumb
;
4171 float fpos
= (float)pos
;
4172 float frange
= (float)range
;
4173 float fthumb
= (float)thumbVisible
;
4174 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
4175 if (fpos
< 0.0) fpos
= 0.0;
4177 if ((fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
4178 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
4180 SetScrollPos( orient
, pos
, refresh
);
4184 m_oldVerticalPos
= fpos
;
4186 m_vAdjust
->lower
= 0.0;
4187 m_vAdjust
->upper
= frange
;
4188 m_vAdjust
->value
= fpos
;
4189 m_vAdjust
->step_increment
= 1.0;
4190 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4191 m_vAdjust
->page_size
= fthumb
;
4194 if (orient
== wxHORIZONTAL
)
4195 g_signal_emit_by_name (m_hAdjust
, "changed");
4197 g_signal_emit_by_name (m_vAdjust
, "changed");
4200 void wxWindowGTK::GtkUpdateScrollbar(int orient
)
4202 GtkAdjustment
*adj
= orient
== wxHORIZONTAL
? m_hAdjust
: m_vAdjust
;
4203 gpointer fn
= orient
== wxHORIZONTAL
4204 ? (gpointer
) gtk_window_hscroll_callback
4205 : (gpointer
) gtk_window_vscroll_callback
;
4207 g_signal_handlers_disconnect_by_func (adj
, fn
, this);
4208 g_signal_emit_by_name (adj
, "value_changed");
4209 g_signal_connect (adj
, "value_changed", G_CALLBACK (fn
), this);
4212 void wxWindowGTK::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
4214 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4215 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4217 GtkAdjustment
*adj
= orient
== wxHORIZONTAL
? m_hAdjust
: m_vAdjust
;
4219 float fpos
= (float)pos
;
4220 if (fpos
> adj
->upper
- adj
->page_size
)
4221 fpos
= adj
->upper
- adj
->page_size
;
4224 *(orient
== wxHORIZONTAL
? &m_oldHorizontalPos
: &m_oldVerticalPos
) = fpos
;
4226 if (fabs(fpos
-adj
->value
) < 0.2)
4230 if ( m_wxwindow
->window
)
4235 int wxWindowGTK::GetScrollThumb( int orient
) const
4237 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4239 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4241 if (orient
== wxHORIZONTAL
)
4242 return (int)(m_hAdjust
->page_size
+0.5);
4244 return (int)(m_vAdjust
->page_size
+0.5);
4247 int wxWindowGTK::GetScrollPos( int orient
) const
4249 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4251 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4253 if (orient
== wxHORIZONTAL
)
4254 return (int)(m_hAdjust
->value
+0.5);
4256 return (int)(m_vAdjust
->value
+0.5);
4259 int wxWindowGTK::GetScrollRange( int orient
) const
4261 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4263 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4265 if (orient
== wxHORIZONTAL
)
4266 return (int)(m_hAdjust
->upper
+0.5);
4268 return (int)(m_vAdjust
->upper
+0.5);
4271 void wxWindowGTK::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4273 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4275 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4277 // No scrolling requested.
4278 if ((dx
== 0) && (dy
== 0)) return;
4280 m_clipPaintRegion
= true;
4282 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow
), -dx
, -dy
);
4284 m_clipPaintRegion
= false;
4287 void wxWindowGTK::GtkScrolledWindowSetBorder(GtkWidget
* w
, int wxstyle
)
4289 //RN: Note that static controls usually have no border on gtk, so maybe
4290 //it makes sense to treat that as simply no border at the wx level
4292 if (!(wxstyle
& wxNO_BORDER
) && !(wxstyle
& wxBORDER_STATIC
))
4294 GtkShadowType gtkstyle
;
4296 if(wxstyle
& wxBORDER_RAISED
)
4297 gtkstyle
= GTK_SHADOW_OUT
;
4298 else if (wxstyle
& wxBORDER_SUNKEN
)
4299 gtkstyle
= GTK_SHADOW_IN
;
4300 else if (wxstyle
& wxBORDER_DOUBLE
)
4301 gtkstyle
= GTK_SHADOW_ETCHED_IN
;
4303 gtkstyle
= GTK_SHADOW_IN
;
4305 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(w
),
4310 void wxWindowGTK::SetWindowStyleFlag( long style
)
4312 // Updates the internal variable. NB: Now m_windowStyle bits carry the _new_ style values already
4313 wxWindowBase::SetWindowStyleFlag(style
);
4316 // Find the wxWindow at the current mouse position, also returning the mouse
4318 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4320 pt
= wxGetMousePosition();
4321 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4325 // Get the current mouse position.
4326 wxPoint
wxGetMousePosition()
4328 /* This crashes when used within wxHelpContext,
4329 so we have to use the X-specific implementation below.
4331 GdkModifierType *mask;
4332 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4334 return wxPoint(x, y);
4338 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4340 Display
*display
= windowAtPtr
? GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4341 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4342 Window rootReturn
, childReturn
;
4343 int rootX
, rootY
, winX
, winY
;
4344 unsigned int maskReturn
;
4346 XQueryPointer (display
,
4350 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4351 return wxPoint(rootX
, rootY
);
4355 // Needed for implementing e.g. combobox on wxGTK within a modal dialog.
4356 void wxAddGrab(wxWindow
* window
)
4358 gtk_grab_add( (GtkWidget
*) window
->GetHandle() );
4361 void wxRemoveGrab(wxWindow
* window
)
4363 gtk_grab_remove( (GtkWidget
*) window
->GetHandle() );
4366 // ----------------------------------------------------------------------------
4368 // ----------------------------------------------------------------------------
4370 class wxWinModule
: public wxModule
4377 DECLARE_DYNAMIC_CLASS(wxWinModule
)
4380 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
4382 bool wxWinModule::OnInit()
4384 // g_eraseGC = gdk_gc_new( gdk_get_default_root_window() );
4385 // gdk_gc_set_fill( g_eraseGC, GDK_SOLID );
4390 void wxWinModule::OnExit()
4393 g_object_unref (G_OBJECT (g_eraseGC
));