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"
23 #include "wx/dcclient.h"
25 #include "wx/settings.h"
26 #include "wx/msgdlg.h"
27 #include "wx/textctrl.h"
28 #include "wx/radiobut.h"
29 #include "wx/toolbar.h"
30 #include "wx/combobox.h"
31 #include "wx/layout.h"
36 #include "wx/tooltip.h"
38 #include "wx/fontutil.h"
41 #include "wx/thread.h"
46 // FIXME: Due to a hack we use GtkCombo in here, which is deprecated since gtk2.3.0
47 #include <gtk/gtkversion.h>
48 #if defined(GTK_DISABLE_DEPRECATED) && GTK_CHECK_VERSION(2,3,0)
49 #undef GTK_DISABLE_DEPRECATED
50 #include <gtk/gtkcombo.h>
51 #define GTK_DISABLE_DEPRECATED
54 #include "wx/gtk/private.h"
55 #include "wx/gtk/win_gtk.h"
56 #include <gdk/gdkkeysyms.h>
59 //-----------------------------------------------------------------------------
60 // documentation on internals
61 //-----------------------------------------------------------------------------
64 I have been asked several times about writing some documentation about
65 the GTK port of wxWidgets, especially its internal structures. Obviously,
66 you cannot understand wxGTK without knowing a little about the GTK, but
67 some more information about what the wxWindow, which is the base class
68 for all other window classes, does seems required as well.
72 What does wxWindow do? It contains the common interface for the following
73 jobs of its descendants:
75 1) Define the rudimentary behaviour common to all window classes, such as
76 resizing, intercepting user input (so as to make it possible to use these
77 events for special purposes in a derived class), window names etc.
79 2) Provide the possibility to contain and manage children, if the derived
80 class is allowed to contain children, which holds true for those window
81 classes which do not display a native GTK widget. To name them, these
82 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
83 work classes are a special case and are handled a bit differently from
84 the rest. The same holds true for the wxNotebook class.
86 3) Provide the possibility to draw into a client area of a window. This,
87 too, only holds true for classes that do not display a native GTK widget
90 4) Provide the entire mechanism for scrolling widgets. This actual inter-
91 face for this is usually in wxScrolledWindow, but the GTK implementation
94 5) A multitude of helper or extra methods for special purposes, such as
95 Drag'n'Drop, managing validators etc.
97 6) Display a border (sunken, raised, simple or none).
99 Normally one might expect, that one wxWidgets window would always correspond
100 to one GTK widget. Under GTK, there is no such all-round widget that has all
101 the functionality. Moreover, the GTK defines a client area as a different
102 widget from the actual widget you are handling. Last but not least some
103 special classes (e.g. wxFrame) handle different categories of widgets and
104 still have the possibility to draw something in the client area.
105 It was therefore required to write a special purpose GTK widget, that would
106 represent a client area in the sense of wxWidgets capable to do the jobs
107 2), 3) and 4). I have written this class and it resides in win_gtk.c of
110 All windows must have a widget, with which they interact with other under-
111 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
112 the wxWindow class has a member variable called m_widget which holds a
113 pointer to this widget. When the window class represents a GTK native widget,
114 this is (in most cases) the only GTK widget the class manages. E.g. the
115 wxStaticText class handles only a GtkLabel widget a pointer to which you
116 can find in m_widget (defined in wxWindow)
118 When the class has a client area for drawing into and for containing children
119 it has to handle the client area widget (of the type GtkPizza, defined in
120 win_gtk.c), but there could be any number of widgets, handled by a class
121 The common rule for all windows is only, that the widget that interacts with
122 the rest of GTK must be referenced in m_widget and all other widgets must be
123 children of this widget on the GTK level. The top-most widget, which also
124 represents the client area, must be in the m_wxwindow field and must be of
127 As I said, the window classes that display a GTK native widget only have
128 one widget, so in the case of e.g. the wxButton class m_widget holds a
129 pointer to a GtkButton widget. But windows with client areas (for drawing
130 and children) have a m_widget field that is a pointer to a GtkScrolled-
131 Window and a m_wxwindow field that is pointer to a GtkPizza and this
132 one is (in the GTK sense) a child of the GtkScrolledWindow.
134 If the m_wxwindow field is set, then all input to this widget is inter-
135 cepted and sent to the wxWidgets class. If not, all input to the widget
136 that gets pointed to by m_widget gets intercepted and sent to the class.
140 The design of scrolling in wxWidgets is markedly different from that offered
141 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
142 clicking on a scrollbar belonging to scrolled window will inevitably move
143 the window. In wxWidgets, the scrollbar will only emit an event, send this
144 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
145 which actually moves the window and its sub-windows. Note that GtkPizza
146 memorizes how much it has been scrolled but that wxWidgets forgets this
147 so that the two coordinates systems have to be kept in synch. This is done
148 in various places using the pizza->xoffset and pizza->yoffset values.
152 Singularly the most broken code in GTK is the code that is supposed to
153 inform subwindows (child windows) about new positions. Very often, duplicate
154 events are sent without changes in size or position, equally often no
155 events are sent at all (All this is due to a bug in the GtkContainer code
156 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
157 GTK's own system and it simply waits for size events for toplevel windows
158 and then iterates down the respective size events to all window. This has
159 the disadvantage that windows might get size events before the GTK widget
160 actually has the reported size. This doesn't normally pose any problem, but
161 the OpenGL drawing routines rely on correct behaviour. Therefore, I have
162 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
163 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
164 window that is used for OpenGL output really has that size (as reported by
169 If someone at some point of time feels the immense desire to have a look at,
170 change or attempt to optimise the Refresh() logic, this person will need an
171 intimate understanding of what "draw" and "expose" events are and what
172 they are used for, in particular when used in connection with GTK's
173 own windowless widgets. Beware.
177 Cursors, too, have been a constant source of pleasure. The main difficulty
178 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
179 for the parent. To prevent this from doing too much harm, I use idle time
180 to set the cursor over and over again, starting from the toplevel windows
181 and ending with the youngest generation (speaking of parent and child windows).
182 Also don't forget that cursors (like much else) are connected to GdkWindows,
183 not GtkWidgets and that the "window" field of a GtkWidget might very well
184 point to the GdkWindow of the parent widget (-> "window-less widget") and
185 that the two obviously have very different meanings.
189 //-----------------------------------------------------------------------------
191 //-----------------------------------------------------------------------------
193 extern bool g_blockEventsOnDrag
;
194 extern bool g_blockEventsOnScroll
;
195 extern wxCursor g_globalCursor
;
197 // mouse capture state: the window which has it and if the mouse is currently
199 static wxWindowGTK
*g_captureWindow
= (wxWindowGTK
*) NULL
;
200 static bool g_captureWindowHasMouse
= false;
202 wxWindowGTK
*g_focusWindow
= (wxWindowGTK
*) NULL
;
204 // the last window which had the focus - this is normally never NULL (except
205 // if we never had focus at all) as even when g_focusWindow is NULL it still
206 // keeps its previous value
207 wxWindowGTK
*g_focusWindowLast
= (wxWindowGTK
*) NULL
;
209 // If a window get the focus set but has not been realized
210 // yet, defer setting the focus to idle time.
211 wxWindowGTK
*g_delayedFocus
= (wxWindowGTK
*) NULL
;
213 // Save the last mouse event for drag start
214 GdkEvent
*g_lastMouseEvent
= (GdkEvent
*) NULL
;
215 int g_lastButtonNumber
= 0;
217 extern bool g_mainThreadLocked
;
219 //-----------------------------------------------------------------------------
221 //-----------------------------------------------------------------------------
226 # define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
228 # define DEBUG_MAIN_THREAD
231 #define DEBUG_MAIN_THREAD
234 // the trace mask used for the focus debugging messages
235 #define TRACE_FOCUS _T("focus")
237 //-----------------------------------------------------------------------------
238 // missing gdk functions
239 //-----------------------------------------------------------------------------
242 gdk_window_warp_pointer (GdkWindow
*window
,
247 window
= gdk_get_default_root_window();
249 if (!GDK_WINDOW_DESTROYED(window
))
251 XWarpPointer (GDK_WINDOW_XDISPLAY(window
),
252 None
, /* not source window -> move from anywhere */
253 GDK_WINDOW_XID(window
), /* dest window */
254 0, 0, 0, 0, /* not source window -> move from anywhere */
259 //-----------------------------------------------------------------------------
260 // local code (see below)
261 //-----------------------------------------------------------------------------
263 // returns the child of win which currently has focus or NULL if not found
265 // Note: can't be static, needed by textctrl.cpp.
266 wxWindow
*wxFindFocusedChild(wxWindowGTK
*win
)
268 wxWindow
*winFocus
= wxWindowGTK
::FindFocus();
270 return (wxWindow
*)NULL
;
272 if ( winFocus
== win
)
273 return (wxWindow
*)win
;
275 for ( wxWindowList
::compatibility_iterator node
= win
->GetChildren().GetFirst();
277 node
= node
->GetNext() )
279 wxWindow
*child
= wxFindFocusedChild(node
->GetData());
284 return (wxWindow
*)NULL
;
287 static void GetScrollbarWidth(GtkWidget
* widget
, int& w
, int& h
)
289 GtkScrolledWindow
* scroll_window
= GTK_SCROLLED_WINDOW(widget
);
290 GtkScrolledWindowClass
* scroll_class
= GTK_SCROLLED_WINDOW_CLASS(GTK_OBJECT_GET_CLASS(scroll_window
));
291 GtkRequisition scroll_req
;
294 if (scroll_window
->vscrollbar_visible
)
296 scroll_req
.width
= 2;
297 scroll_req
.height
= 2;
298 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
299 (scroll_window
->vscrollbar
, &scroll_req
);
300 w
= scroll_req
.width
+
301 scroll_class
->scrollbar_spacing
;
305 if (scroll_window
->hscrollbar_visible
)
307 scroll_req
.width
= 2;
308 scroll_req
.height
= 2;
309 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
310 (scroll_window
->hscrollbar
, &scroll_req
);
311 h
= scroll_req
.height
+
312 scroll_class
->scrollbar_spacing
;
316 static void draw_frame( GtkWidget
*widget
, wxWindowGTK
*win
)
318 // wxUniversal widgets draw the borders and scrollbars themselves
319 #ifndef __WXUNIVERSAL__
325 if (GTK_WIDGET_NO_WINDOW (widget
))
327 dx
+= widget
->allocation
.x
;
328 dy
+= widget
->allocation
.y
;
336 if (win
->m_hasScrolling
)
338 GetScrollbarWidth(widget
, dw
, dh
);
340 if (win
->GetLayoutDirection() == wxLayout_RightToLeft
)
342 // This is actually wrong for old GTK+ version
343 // which do not display the scrollbar on the
349 int w
= widget
->allocation
.width
-dw
;
350 int h
= widget
->allocation
.height
-dh
;
352 if (win
->HasFlag(wxRAISED_BORDER
))
354 gtk_paint_shadow (widget
->style
,
358 NULL
, NULL
, NULL
, // FIXME: No clipping?
363 if (win
->HasFlag(wxSUNKEN_BORDER
))
365 gtk_paint_shadow (widget
->style
,
369 NULL
, NULL
, NULL
, // FIXME: No clipping?
374 if (win
->HasFlag(wxSIMPLE_BORDER
))
377 gc
= gdk_gc_new( widget
->window
);
378 gdk_gc_set_foreground( gc
, &widget
->style
->black
);
379 gdk_draw_rectangle( widget
->window
, gc
, FALSE
, x
, y
, w
-1, h
-1 );
383 #endif // __WXUNIVERSAL__
386 //-----------------------------------------------------------------------------
387 // "expose_event" of m_widget
388 //-----------------------------------------------------------------------------
392 gtk_window_own_expose_callback( GtkWidget
*widget
,
393 GdkEventExpose
*gdk_event
,
396 if (gdk_event
->count
== 0)
397 draw_frame(widget
, win
);
402 //-----------------------------------------------------------------------------
403 // "size_request" of m_widget
404 //-----------------------------------------------------------------------------
406 // make it extern because wxStaticText needs to disconnect this one
408 void wxgtk_window_size_request_callback(GtkWidget
*widget
,
409 GtkRequisition
*requisition
,
413 win
->GetSize( &w
, &h
);
419 requisition
->height
= h
;
420 requisition
->width
= w
;
426 void wxgtk_combo_size_request_callback(GtkWidget
*widget
,
427 GtkRequisition
*requisition
,
430 // This callback is actually hooked into the text entry
431 // of the combo box, not the GtkHBox.
434 win
->GetSize( &w
, &h
);
440 GtkCombo
*gcombo
= GTK_COMBO(win
->m_widget
);
442 GtkRequisition entry_req
;
444 entry_req
.height
= 2;
445 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo
->entry
) )->size_request
)
446 (gcombo
->entry
, &entry_req
);
448 GtkRequisition button_req
;
449 button_req
.width
= 2;
450 button_req
.height
= 2;
451 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo
->button
) )->size_request
)
452 (gcombo
->button
, &button_req
);
454 requisition
->width
= w
- button_req
.width
;
455 requisition
->height
= entry_req
.height
;
459 //-----------------------------------------------------------------------------
460 // "expose_event" of m_wxwindow
461 //-----------------------------------------------------------------------------
465 gtk_window_expose_callback( GtkWidget
*widget
,
466 GdkEventExpose
*gdk_event
,
471 // don't need to install idle handler, its done from "event" signal
473 // This callback gets called in drawing-idle time under
474 // GTK 2.0, so we don't need to defer anything to idle
477 GtkPizza
*pizza
= GTK_PIZZA( widget
);
478 if (gdk_event
->window
!= pizza
->bin_window
)
480 // block expose events on GTK_WIDGET(pizza)->window,
481 // all drawing is done on pizza->bin_window
489 wxPrintf( wxT("OnExpose from ") );
490 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
491 wxPrintf( win
->GetClassInfo()->GetClassName() );
492 wxPrintf( wxT(" %d %d %d %d\n"), (int)gdk_event
->area
.x
,
493 (int)gdk_event
->area
.y
,
494 (int)gdk_event
->area
.width
,
495 (int)gdk_event
->area
.height
);
500 win
->m_wxwindow
->style
,
504 (GdkRectangle
*) NULL
,
506 (char *)"button", // const_cast
511 win
->GetUpdateRegion() = wxRegion( gdk_event
->region
);
513 win
->GtkSendPaintEvents();
515 // Let parent window draw window-less widgets
520 //-----------------------------------------------------------------------------
521 // "key_press_event" from any window
522 //-----------------------------------------------------------------------------
524 // These are used when transforming Ctrl-alpha to ascii values 1-26
525 inline bool wxIsLowerChar(int code
)
527 return (code
>= 'a' && code
<= 'z' );
530 inline bool wxIsUpperChar(int code
)
532 return (code
>= 'A' && code
<= 'Z' );
536 // set WXTRACE to this to see the key event codes on the console
537 #define TRACE_KEYS _T("keyevent")
539 // translates an X key symbol to WXK_XXX value
541 // if isChar is true it means that the value returned will be used for EVT_CHAR
542 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
543 // for example, while if it is false it means that the value is going to be
544 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
546 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
552 // Shift, Control and Alt don't generate the CHAR events at all
555 key_code
= isChar ?
0 : WXK_SHIFT
;
559 key_code
= isChar ?
0 : WXK_CONTROL
;
567 key_code
= isChar ?
0 : WXK_ALT
;
570 // neither do the toggle modifies
571 case GDK_Scroll_Lock
:
572 key_code
= isChar ?
0 : WXK_SCROLL
;
576 key_code
= isChar ?
0 : WXK_CAPITAL
;
580 key_code
= isChar ?
0 : WXK_NUMLOCK
;
584 // various other special keys
597 case GDK_ISO_Left_Tab
:
604 key_code
= WXK_RETURN
;
608 key_code
= WXK_CLEAR
;
612 key_code
= WXK_PAUSE
;
616 key_code
= WXK_SELECT
;
620 key_code
= WXK_PRINT
;
624 key_code
= WXK_EXECUTE
;
628 key_code
= WXK_ESCAPE
;
631 // cursor and other extended keyboard keys
633 key_code
= WXK_DELETE
;
649 key_code
= WXK_RIGHT
;
656 case GDK_Prior
: // == GDK_Page_Up
657 key_code
= WXK_PAGEUP
;
660 case GDK_Next
: // == GDK_Page_Down
661 key_code
= WXK_PAGEDOWN
;
673 key_code
= WXK_INSERT
;
688 key_code
= (isChar ?
'0' : WXK_NUMPAD0
) + keysym
- GDK_KP_0
;
692 key_code
= isChar ?
' ' : WXK_NUMPAD_SPACE
;
696 key_code
= isChar ? WXK_TAB
: WXK_NUMPAD_TAB
;
700 key_code
= isChar ? WXK_RETURN
: WXK_NUMPAD_ENTER
;
704 key_code
= isChar ? WXK_F1
: WXK_NUMPAD_F1
;
708 key_code
= isChar ? WXK_F2
: WXK_NUMPAD_F2
;
712 key_code
= isChar ? WXK_F3
: WXK_NUMPAD_F3
;
716 key_code
= isChar ? WXK_F4
: WXK_NUMPAD_F4
;
720 key_code
= isChar ? WXK_HOME
: WXK_NUMPAD_HOME
;
724 key_code
= isChar ? WXK_LEFT
: WXK_NUMPAD_LEFT
;
728 key_code
= isChar ? WXK_UP
: WXK_NUMPAD_UP
;
732 key_code
= isChar ? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
736 key_code
= isChar ? WXK_DOWN
: WXK_NUMPAD_DOWN
;
739 case GDK_KP_Prior
: // == GDK_KP_Page_Up
740 key_code
= isChar ? WXK_PAGEUP
: WXK_NUMPAD_PAGEUP
;
743 case GDK_KP_Next
: // == GDK_KP_Page_Down
744 key_code
= isChar ? WXK_PAGEDOWN
: WXK_NUMPAD_PAGEDOWN
;
748 key_code
= isChar ? WXK_END
: WXK_NUMPAD_END
;
752 key_code
= isChar ? WXK_HOME
: WXK_NUMPAD_BEGIN
;
756 key_code
= isChar ? WXK_INSERT
: WXK_NUMPAD_INSERT
;
760 key_code
= isChar ? WXK_DELETE
: WXK_NUMPAD_DELETE
;
764 key_code
= isChar ?
'=' : WXK_NUMPAD_EQUAL
;
767 case GDK_KP_Multiply
:
768 key_code
= isChar ?
'*' : WXK_NUMPAD_MULTIPLY
;
772 key_code
= isChar ?
'+' : WXK_NUMPAD_ADD
;
775 case GDK_KP_Separator
:
776 // FIXME: what is this?
777 key_code
= isChar ?
'.' : WXK_NUMPAD_SEPARATOR
;
780 case GDK_KP_Subtract
:
781 key_code
= isChar ?
'-' : WXK_NUMPAD_SUBTRACT
;
785 key_code
= isChar ?
'.' : WXK_NUMPAD_DECIMAL
;
789 key_code
= isChar ?
'/' : WXK_NUMPAD_DIVIDE
;
806 key_code
= WXK_F1
+ keysym
- GDK_F1
;
816 static inline bool wxIsAsciiKeysym(KeySym ks
)
821 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
823 GdkEventKey
*gdk_event
)
827 GdkModifierType state
;
828 if (gdk_event
->window
)
829 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
831 event
.SetTimestamp( gdk_event
->time
);
832 event
.SetId(win
->GetId());
833 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
834 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
835 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
836 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
) != 0;
837 event
.m_scanCode
= gdk_event
->keyval
;
838 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
839 event
.m_rawFlags
= 0;
841 event
.m_uniChar
= gdk_keyval_to_unicode(gdk_event
->keyval
);
843 wxGetMousePosition( &x
, &y
);
844 win
->ScreenToClient( &x
, &y
);
847 event
.SetEventObject( win
);
852 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
854 GdkEventKey
*gdk_event
)
856 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
857 // but only event->keyval which is quite useless to us, so remember
858 // the last character from GDK_KEY_PRESS and reuse it as last resort
860 // NB: should be MT-safe as we're always called from the main thread only
865 } s_lastKeyPress
= { 0, 0 };
867 KeySym keysym
= gdk_event
->keyval
;
869 wxLogTrace(TRACE_KEYS
, _T("Key %s event: keysym = %ld"),
870 event
.GetEventType() == wxEVT_KEY_UP ?
_T("release")
874 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
878 // do we have the translation or is it a plain ASCII character?
879 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
881 // we should use keysym if it is ASCII as X does some translations
882 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
883 // which we don't want here (but which we do use for OnChar())
884 if ( !wxIsAsciiKeysym(keysym
) )
886 keysym
= (KeySym
)gdk_event
->string
[0];
889 // we want to always get the same key code when the same key is
890 // pressed regardless of the state of the modifiers, i.e. on a
891 // standard US keyboard pressing '5' or '%' ('5' key with
892 // Shift) should result in the same key code in OnKeyDown():
893 // '5' (although OnChar() will get either '5' or '%').
895 // to do it we first translate keysym to keycode (== scan code)
896 // and then back but always using the lower register
897 Display
*dpy
= (Display
*)wxGetDisplay();
898 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
900 wxLogTrace(TRACE_KEYS
, _T("\t-> keycode %d"), keycode
);
902 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
904 // use the normalized, i.e. lower register, keysym if we've
906 key_code
= keysymNormalized ? keysymNormalized
: keysym
;
908 // as explained above, we want to have lower register key codes
909 // normally but for the letter keys we want to have the upper ones
911 // NB: don't use XConvertCase() here, we want to do it for letters
913 key_code
= toupper(key_code
);
915 else // non ASCII key, what to do?
917 // by default, ignore it
920 // but if we have cached information from the last KEY_PRESS
921 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
924 if ( keysym
== s_lastKeyPress
.keysym
)
926 key_code
= s_lastKeyPress
.keycode
;
931 if ( gdk_event
->type
== GDK_KEY_PRESS
)
933 // remember it to be reused for KEY_UP event later
934 s_lastKeyPress
.keysym
= keysym
;
935 s_lastKeyPress
.keycode
= key_code
;
939 wxLogTrace(TRACE_KEYS
, _T("\t-> wxKeyCode %ld"), key_code
);
941 // sending unknown key events doesn't really make sense
945 // now fill all the other fields
946 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
948 event
.m_keyCode
= key_code
;
950 if ( gdk_event
->type
== GDK_KEY_PRESS
|| gdk_event
->type
== GDK_KEY_RELEASE
)
952 event
.m_uniChar
= key_code
;
962 GtkIMContext
*context
;
963 GdkEventKey
*lastKeyEvent
;
967 context
= gtk_im_multicontext_new();
972 g_object_unref (context
);
978 gtk_window_key_press_callback( GtkWidget
*widget
,
979 GdkEventKey
*gdk_event
,
984 // don't need to install idle handler, its done from "event" signal
988 if (g_blockEventsOnDrag
)
992 wxKeyEvent
event( wxEVT_KEY_DOWN
);
994 bool return_after_IM
= false;
996 if( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
998 // Emit KEY_DOWN event
999 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1003 // Return after IM processing as we cannot do
1004 // anything with it anyhow.
1005 return_after_IM
= true;
1008 // 2005.01.26 modified by Hong Jen Yee (hzysoft@sina.com.tw):
1009 // When we get a key_press event here, it could be originate
1010 // from the current widget or its child widgets. However, only the widget
1011 // with the INPUT FOCUS can generate the INITIAL key_press event. That is,
1012 // if the CURRENT widget doesn't have the FOCUS at all, this event definitely
1013 // originated from its child widgets and shouldn't be passed to IM context.
1014 // In fact, what a GTK+ IM should do is filtering keyEvents and convert them
1015 // into text input ONLY WHEN THE WIDGET HAS INPUT FOCUS. Besides, when current
1016 // widgets has both IM context and input focus, the event should be filtered
1017 // by gtk_im_context_filter_keypress().
1018 // Then, we should, according to GTK+ 2.0 API doc, return whatever it returns.
1019 if ((!ret
) && (win
->m_imData
!= NULL
) && ( wxWindow
::FindFocus() == win
))
1021 // We should let GTK+ IM filter key event first. According to GTK+ 2.0 API
1022 // docs, if IM filter returns true, no further processing should be done.
1023 // we should send the key_down event anyway.
1024 bool intercepted_by_IM
= gtk_im_context_filter_keypress(win
->m_imData
->context
, gdk_event
);
1025 win
->m_imData
->lastKeyEvent
= NULL
;
1026 if (intercepted_by_IM
)
1028 wxLogTrace(TRACE_KEYS
, _T("Key event intercepted by IM"));
1033 if (return_after_IM
)
1039 wxWindowGTK
*ancestor
= win
;
1042 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1045 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1046 ret
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1049 if (ancestor
->IsTopLevel())
1051 ancestor
= ancestor
->GetParent();
1054 #endif // wxUSE_ACCEL
1056 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
1057 // will only be sent if it is not in an accelerator table.
1061 KeySym keysym
= gdk_event
->keyval
;
1062 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
1063 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
1066 if ( wxIsAsciiKeysym(keysym
) )
1069 key_code
= (unsigned char)keysym
;
1071 // gdk_event->string is actually deprecated
1072 else if ( gdk_event
->length
== 1 )
1074 key_code
= (unsigned char)gdk_event
->string
[0];
1080 wxLogTrace(TRACE_KEYS
, _T("Char event: %ld"), key_code
);
1082 event
.m_keyCode
= key_code
;
1084 // To conform to the docs we need to translate Ctrl-alpha
1085 // characters to values in the range 1-26.
1086 if ( event
.ControlDown() &&
1087 ( wxIsLowerChar(key_code
) || wxIsUpperChar(key_code
) ))
1089 if ( wxIsLowerChar(key_code
) )
1090 event
.m_keyCode
= key_code
- 'a' + 1;
1091 if ( wxIsUpperChar(key_code
) )
1092 event
.m_keyCode
= key_code
- 'A' + 1;
1094 event
.m_uniChar
= event
.m_keyCode
;
1098 // Implement OnCharHook by checking ancestor top level windows
1099 wxWindow
*parent
= win
;
1100 while (parent
&& !parent
->IsTopLevel())
1101 parent
= parent
->GetParent();
1104 event
.SetEventType( wxEVT_CHAR_HOOK
);
1105 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1110 event
.SetEventType(wxEVT_CHAR
);
1111 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1116 // win is a control: tab can be propagated up
1118 ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
)) &&
1119 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here - the control may
1120 // have this style, yet choose not to process this particular TAB in which
1121 // case TAB must still work as a navigational character
1122 // JS: enabling again to make consistent with other platforms
1123 // (with wxTE_PROCESS_TAB you have to call Navigate to get default
1124 // navigation behaviour)
1126 (! (win
->HasFlag(wxTE_PROCESS_TAB
) && win
->IsKindOf(CLASSINFO(wxTextCtrl
)) )) &&
1128 win
->GetParent() && (win
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1130 wxNavigationKeyEvent new_event
;
1131 new_event
.SetEventObject( win
->GetParent() );
1132 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
1133 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
1134 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
1135 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
1136 new_event
.SetCurrentFocus( win
);
1137 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent( new_event
);
1146 gtk_wxwindow_commit_cb (GtkIMContext
*context
,
1150 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1152 // take modifiers, cursor position, timestamp etc. from the last
1153 // key_press_event that was fed into Input Method:
1154 if (window
->m_imData
->lastKeyEvent
)
1156 wxFillOtherKeyEventFields(event
,
1157 window
, window
->m_imData
->lastKeyEvent
);
1160 const wxWxCharBuffer
data(wxGTK_CONV_BACK(str
));
1166 // Implement OnCharHook by checking ancestor top level windows
1167 wxWindow
*parent
= window
;
1168 while (parent
&& !parent
->IsTopLevel())
1169 parent
= parent
->GetParent();
1171 for( const wxChar
* pstr
= data
; *pstr
; pstr
++ )
1174 event
.m_uniChar
= *pstr
;
1175 // Backward compatible for ISO-8859-1
1176 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1177 wxLogTrace(TRACE_KEYS
, _T("IM sent character '%c'"), event
.m_uniChar
);
1179 event
.m_keyCode
= *pstr
;
1180 #endif // wxUSE_UNICODE
1182 // To conform to the docs we need to translate Ctrl-alpha
1183 // characters to values in the range 1-26.
1184 if ( event
.ControlDown() &&
1185 ( wxIsLowerChar(*pstr
) || wxIsUpperChar(*pstr
) ))
1187 if ( wxIsLowerChar(*pstr
) )
1188 event
.m_keyCode
= *pstr
- 'a' + 1;
1189 if ( wxIsUpperChar(*pstr
) )
1190 event
.m_keyCode
= *pstr
- 'A' + 1;
1192 event
.m_keyCode
= *pstr
- 'a' + 1;
1194 event
.m_uniChar
= event
.m_keyCode
;
1200 event
.SetEventType( wxEVT_CHAR_HOOK
);
1201 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1206 event
.SetEventType(wxEVT_CHAR
);
1207 ret
= window
->GetEventHandler()->ProcessEvent( event
);
1214 //-----------------------------------------------------------------------------
1215 // "key_release_event" from any window
1216 //-----------------------------------------------------------------------------
1220 gtk_window_key_release_callback( GtkWidget
*widget
,
1221 GdkEventKey
*gdk_event
,
1226 // don't need to install idle handler, its done from "event" signal
1231 if (g_blockEventsOnDrag
)
1234 wxKeyEvent
event( wxEVT_KEY_UP
);
1235 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1237 // unknown key pressed, ignore (the event would be useless anyhow)
1241 return win
->GTKProcessEvent(event
);
1245 // ============================================================================
1247 // ============================================================================
1249 // ----------------------------------------------------------------------------
1250 // mouse event processing helpers
1251 // ----------------------------------------------------------------------------
1253 // init wxMouseEvent with the info from GdkEventXXX struct
1254 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1255 wxMouseEvent
& event
,
1258 event
.SetTimestamp( gdk_event
->time
);
1259 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1260 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1261 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1262 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1263 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1264 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1265 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1266 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
1268 event
.m_linesPerAction
= 3;
1269 event
.m_wheelDelta
= 120;
1270 if (((GdkEventButton
*)gdk_event
)->button
== 4)
1271 event
.m_wheelRotation
= 120;
1272 else if (((GdkEventButton
*)gdk_event
)->button
== 5)
1273 event
.m_wheelRotation
= -120;
1276 wxPoint pt
= win
->GetClientAreaOrigin();
1277 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1278 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1280 if ((win
->m_wxwindow
) && (win
->GetLayoutDirection() == wxLayout_RightToLeft
))
1282 // origin in the upper right corner
1283 int window_width
= gtk_pizza_get_rtl_offset( GTK_PIZZA(win
->m_wxwindow
) );
1284 event
.m_x
= window_width
- event
.m_x
;
1287 event
.SetEventObject( win
);
1288 event
.SetId( win
->GetId() );
1289 event
.SetTimestamp( gdk_event
->time
);
1292 static void AdjustEventButtonState(wxMouseEvent
& event
)
1294 // GDK reports the old state of the button for a button press event, but
1295 // for compatibility with MSW and common sense we want m_leftDown be TRUE
1296 // for a LEFT_DOWN event, not FALSE, so we will invert
1297 // left/right/middleDown for the corresponding click events
1299 if ((event
.GetEventType() == wxEVT_LEFT_DOWN
) ||
1300 (event
.GetEventType() == wxEVT_LEFT_DCLICK
) ||
1301 (event
.GetEventType() == wxEVT_LEFT_UP
))
1303 event
.m_leftDown
= !event
.m_leftDown
;
1307 if ((event
.GetEventType() == wxEVT_MIDDLE_DOWN
) ||
1308 (event
.GetEventType() == wxEVT_MIDDLE_DCLICK
) ||
1309 (event
.GetEventType() == wxEVT_MIDDLE_UP
))
1311 event
.m_middleDown
= !event
.m_middleDown
;
1315 if ((event
.GetEventType() == wxEVT_RIGHT_DOWN
) ||
1316 (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) ||
1317 (event
.GetEventType() == wxEVT_RIGHT_UP
))
1319 event
.m_rightDown
= !event
.m_rightDown
;
1324 // find the window to send the mouse event too
1326 wxWindowGTK
*FindWindowForMouseEvent(wxWindowGTK
*win
, wxCoord
& x
, wxCoord
& y
)
1331 if (win
->m_wxwindow
)
1333 GtkPizza
*pizza
= GTK_PIZZA(win
->m_wxwindow
);
1334 xx
+= gtk_pizza_get_xoffset( pizza
);
1335 yy
+= gtk_pizza_get_yoffset( pizza
);
1338 wxWindowList
::compatibility_iterator node
= win
->GetChildren().GetFirst();
1341 wxWindowGTK
*child
= node
->GetData();
1343 node
= node
->GetNext();
1344 if (!child
->IsShown())
1347 if (child
->IsTransparentForMouse())
1349 // wxStaticBox is transparent in the box itself
1350 int xx1
= child
->m_x
;
1351 int yy1
= child
->m_y
;
1352 int xx2
= child
->m_x
+ child
->m_width
;
1353 int yy2
= child
->m_y
+ child
->m_height
;
1356 if (((xx
>= xx1
) && (xx
<= xx1
+10) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1358 ((xx
>= xx2
-10) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1360 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy1
+10)) ||
1362 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy2
-1) && (yy
<= yy2
)))
1373 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1374 (child
->m_x
<= xx
) &&
1375 (child
->m_y
<= yy
) &&
1376 (child
->m_x
+child
->m_width
>= xx
) &&
1377 (child
->m_y
+child
->m_height
>= yy
))
1390 // ----------------------------------------------------------------------------
1391 // common event handlers helpers
1392 // ----------------------------------------------------------------------------
1394 bool wxWindowGTK
::GTKProcessEvent(wxEvent
& event
) const
1396 // nothing special at this level
1397 return GetEventHandler()->ProcessEvent(event
);
1400 int wxWindowGTK
::GTKCallbackCommonPrologue(GdkEventAny
*event
) const
1404 // don't need to install idle handler, its done from "event" signal
1408 if (g_blockEventsOnDrag
)
1410 if (g_blockEventsOnScroll
)
1413 if (!GTKIsOwnWindow(event
->window
))
1419 // overloads for all GDK event types we use here: we need to have this as
1420 // GdkEventXXX can't be implicitly cast to GdkEventAny even if it, in fact,
1421 // derives from it in the sense that the structs have the same layout
1422 #define wxDEFINE_COMMON_PROLOGUE_OVERLOAD(T) \
1423 static int wxGtkCallbackCommonPrologue(T *event, wxWindowGTK *win) \
1425 return win->GTKCallbackCommonPrologue((GdkEventAny *)event); \
1428 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventButton
)
1429 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventMotion
)
1430 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventCrossing
)
1432 #undef wxDEFINE_COMMON_PROLOGUE_OVERLOAD
1434 #define wxCOMMON_CALLBACK_PROLOGUE(event, win) \
1435 const int rc = wxGtkCallbackCommonPrologue(event, win); \
1439 // send the wxChildFocusEvent and wxFocusEvent, common code of
1440 // gtk_window_focus_in_callback() and SetFocus()
1441 static bool DoSendFocusEvents(wxWindow
*win
)
1443 // Notify the parent keeping track of focus for the kbd navigation
1444 // purposes that we got it.
1445 wxChildFocusEvent
eventChildFocus(win
);
1446 (void)win
->GetEventHandler()->ProcessEvent(eventChildFocus
);
1448 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, win
->GetId());
1449 eventFocus
.SetEventObject(win
);
1451 return win
->GetEventHandler()->ProcessEvent(eventFocus
);
1454 // all event handlers must have C linkage as they're called from GTK+ C code
1458 //-----------------------------------------------------------------------------
1459 // "button_press_event"
1460 //-----------------------------------------------------------------------------
1463 gtk_window_button_press_callback( GtkWidget
*widget
,
1464 GdkEventButton
*gdk_event
,
1467 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1469 g_lastButtonNumber
= gdk_event
->button
;
1471 if (win
->m_wxwindow
&& (g_focusWindow
!= win
) && win
->AcceptsFocus())
1473 gtk_widget_grab_focus( win
->m_wxwindow
);
1476 // GDK sends surplus button down events
1477 // before a double click event. We
1478 // need to filter these out.
1479 if ((gdk_event
->type
== GDK_BUTTON_PRESS
) && (win
->m_wxwindow
))
1481 GdkEvent
*peek_event
= gdk_event_peek();
1484 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1485 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1487 gdk_event_free( peek_event
);
1492 gdk_event_free( peek_event
);
1497 wxEventType event_type
= wxEVT_NULL
;
1499 // GdkDisplay is a GTK+ 2.2.0 thing
1500 #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2, 2, 0)
1501 if ( gdk_event
->type
== GDK_2BUTTON_PRESS
&&
1502 !gtk_check_version(2,2,0) &&
1503 gdk_event
->button
>= 1 && gdk_event
->button
<= 3 )
1505 // Reset GDK internal timestamp variables in order to disable GDK
1506 // triple click events. GDK will then next time believe no button has
1507 // been clicked just before, and send a normal button click event.
1508 GdkDisplay
* display
= gtk_widget_get_display (widget
);
1509 display
->button_click_time
[1] = 0;
1510 display
->button_click_time
[0] = 0;
1514 if (gdk_event
->button
== 1)
1516 // note that GDK generates triple click events which are not supported
1517 // by wxWidgets but still have to be passed to the app as otherwise
1518 // clicks would simply go missing
1519 switch (gdk_event
->type
)
1521 // we shouldn't get triple clicks at all for GTK2 because we
1522 // suppress them artificially using the code above but we still
1523 // should map them to something for GTK1 and not just ignore them
1524 // as this would lose clicks
1525 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1526 case GDK_BUTTON_PRESS
:
1527 event_type
= wxEVT_LEFT_DOWN
;
1530 case GDK_2BUTTON_PRESS
:
1531 event_type
= wxEVT_LEFT_DCLICK
;
1535 // just to silence gcc warnings
1539 else if (gdk_event
->button
== 2)
1541 switch (gdk_event
->type
)
1543 case GDK_3BUTTON_PRESS
:
1544 case GDK_BUTTON_PRESS
:
1545 event_type
= wxEVT_MIDDLE_DOWN
;
1548 case GDK_2BUTTON_PRESS
:
1549 event_type
= wxEVT_MIDDLE_DCLICK
;
1556 else if (gdk_event
->button
== 3)
1558 switch (gdk_event
->type
)
1560 case GDK_3BUTTON_PRESS
:
1561 case GDK_BUTTON_PRESS
:
1562 event_type
= wxEVT_RIGHT_DOWN
;
1565 case GDK_2BUTTON_PRESS
:
1566 event_type
= wxEVT_RIGHT_DCLICK
;
1573 else if (gdk_event
->button
== 4 || gdk_event
->button
== 5)
1575 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1577 event_type
= wxEVT_MOUSEWHEEL
;
1581 if ( event_type
== wxEVT_NULL
)
1583 // unknown mouse button or click type
1587 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1589 wxMouseEvent
event( event_type
);
1590 InitMouseEvent( win
, event
, gdk_event
);
1592 AdjustEventButtonState(event
);
1594 // wxListBox actually gets mouse events from the item, so we need to give it
1595 // a chance to correct this
1596 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1598 // find the correct window to send the event to: it may be a different one
1599 // from the one which got it at GTK+ level because some controls don't have
1600 // their own X window and thus cannot get any events.
1601 if ( !g_captureWindow
)
1602 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1604 // reset the event object and id in case win changed.
1605 event
.SetEventObject( win
);
1606 event
.SetId( win
->GetId() );
1608 if (win
->GTKProcessEvent( event
))
1613 if (event_type
== wxEVT_RIGHT_DOWN
)
1615 // generate a "context menu" event: this is similar to right mouse
1616 // click under many GUIs except that it is generated differently
1617 // (right up under MSW, ctrl-click under Mac, right down here) and
1619 // (a) it's a command event and so is propagated to the parent
1620 // (b) under some ports it can be generated from kbd too
1621 // (c) it uses screen coords (because of (a))
1622 wxContextMenuEvent
evtCtx(
1625 win
->ClientToScreen(event
.GetPosition()));
1626 evtCtx
.SetEventObject(win
);
1627 return win
->GTKProcessEvent(evtCtx
);
1633 //-----------------------------------------------------------------------------
1634 // "button_release_event"
1635 //-----------------------------------------------------------------------------
1638 gtk_window_button_release_callback( GtkWidget
*widget
,
1639 GdkEventButton
*gdk_event
,
1642 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1644 g_lastButtonNumber
= 0;
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 // unknown button, don't process
1667 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1669 wxMouseEvent
event( event_type
);
1670 InitMouseEvent( win
, event
, gdk_event
);
1672 AdjustEventButtonState(event
);
1674 // same wxListBox hack as above
1675 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1677 if ( !g_captureWindow
)
1678 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1680 // reset the event object and id in case win changed.
1681 event
.SetEventObject( win
);
1682 event
.SetId( win
->GetId() );
1684 return win
->GTKProcessEvent(event
);
1687 //-----------------------------------------------------------------------------
1688 // "motion_notify_event"
1689 //-----------------------------------------------------------------------------
1692 gtk_window_motion_notify_callback( GtkWidget
*widget
,
1693 GdkEventMotion
*gdk_event
,
1696 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1698 if (gdk_event
->is_hint
)
1702 GdkModifierType state
;
1703 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1708 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1710 wxMouseEvent
event( wxEVT_MOTION
);
1711 InitMouseEvent(win
, event
, gdk_event
);
1713 if ( g_captureWindow
)
1715 // synthesise a mouse enter or leave event if needed
1716 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1717 // This seems to be necessary and actually been added to
1718 // GDK itself in version 2.0.X
1721 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1722 if ( hasMouse
!= g_captureWindowHasMouse
)
1724 // the mouse changed window
1725 g_captureWindowHasMouse
= hasMouse
;
1727 wxMouseEvent
eventM(g_captureWindowHasMouse ? wxEVT_ENTER_WINDOW
1728 : wxEVT_LEAVE_WINDOW
);
1729 InitMouseEvent(win
, eventM
, gdk_event
);
1730 eventM
.SetEventObject(win
);
1731 win
->GTKProcessEvent(eventM
);
1736 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1738 // reset the event object and id in case win changed.
1739 event
.SetEventObject( win
);
1740 event
.SetId( win
->GetId() );
1743 if ( !g_captureWindow
)
1745 wxSetCursorEvent
cevent( event
.m_x
, event
.m_y
);
1746 if (win
->GTKProcessEvent( cevent
))
1748 win
->SetCursor( cevent
.GetCursor() );
1752 return win
->GTKProcessEvent(event
);
1755 //-----------------------------------------------------------------------------
1756 // "scroll_event", (mouse wheel event)
1757 //-----------------------------------------------------------------------------
1760 window_scroll_event(GtkWidget
*, GdkEventScroll
* gdk_event
, wxWindow
* win
)
1764 // don't need to install idle handler, its done from "event" signal
1766 if (gdk_event
->direction
!= GDK_SCROLL_UP
&&
1767 gdk_event
->direction
!= GDK_SCROLL_DOWN
)
1772 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
1773 // Can't use InitMouse macro because scroll events don't have button
1774 event
.SetTimestamp( gdk_event
->time
);
1775 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1776 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1777 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1778 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1779 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1780 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1781 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1782 event
.m_linesPerAction
= 3;
1783 event
.m_wheelDelta
= 120;
1784 if (gdk_event
->direction
== GDK_SCROLL_UP
)
1785 event
.m_wheelRotation
= 120;
1787 event
.m_wheelRotation
= -120;
1789 wxPoint pt
= win
->GetClientAreaOrigin();
1790 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1791 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1793 event
.SetEventObject( win
);
1794 event
.SetId( win
->GetId() );
1795 event
.SetTimestamp( gdk_event
->time
);
1797 return win
->GTKProcessEvent(event
);
1800 //-----------------------------------------------------------------------------
1802 //-----------------------------------------------------------------------------
1804 static gboolean
wxgtk_window_popup_menu_callback(GtkWidget
*, wxWindowGTK
* win
)
1806 wxContextMenuEvent
event(wxEVT_CONTEXT_MENU
, win
->GetId(), wxPoint(-1, -1));
1807 event
.SetEventObject(win
);
1808 return win
->GTKProcessEvent(event
);
1811 //-----------------------------------------------------------------------------
1813 //-----------------------------------------------------------------------------
1816 gtk_window_focus_in_callback( GtkWidget
*widget
,
1817 GdkEventFocus
*WXUNUSED(event
),
1822 // don't need to install idle handler, its done from "event" signal
1825 gtk_im_context_focus_in(win
->m_imData
->context
);
1828 g_focusWindow
= win
;
1830 wxLogTrace(TRACE_FOCUS
,
1831 _T("%s: focus in"), win
->GetName().c_str());
1834 // caret needs to be informed about focus change
1835 wxCaret
*caret
= win
->GetCaret();
1838 caret
->OnSetFocus();
1840 #endif // wxUSE_CARET
1842 gboolean ret
= FALSE
;
1844 // does the window itself think that it has the focus?
1845 if ( !win
->m_hasFocus
)
1847 // not yet, notify it
1848 win
->m_hasFocus
= true;
1850 (void)DoSendFocusEvents(win
);
1855 // Disable default focus handling for custom windows
1856 // since the default GTK+ handler issues a repaint
1857 if (win
->m_wxwindow
)
1863 //-----------------------------------------------------------------------------
1864 // "focus_out_event"
1865 //-----------------------------------------------------------------------------
1868 gtk_window_focus_out_callback( GtkWidget
*widget
,
1869 GdkEventFocus
*gdk_event
,
1874 // don't need to install idle handler, its done from "event" signal
1877 gtk_im_context_focus_out(win
->m_imData
->context
);
1879 wxLogTrace( TRACE_FOCUS
,
1880 _T("%s: focus out"), win
->GetName().c_str() );
1883 wxWindowGTK
*winFocus
= wxFindFocusedChild(win
);
1887 g_focusWindow
= (wxWindowGTK
*)NULL
;
1890 // caret needs to be informed about focus change
1891 wxCaret
*caret
= win
->GetCaret();
1894 caret
->OnKillFocus();
1896 #endif // wxUSE_CARET
1898 gboolean ret
= FALSE
;
1900 // don't send the window a kill focus event if it thinks that it doesn't
1901 // have focus already
1902 if ( win
->m_hasFocus
)
1904 win
->m_hasFocus
= false;
1906 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
1907 event
.SetEventObject( win
);
1909 (void)win
->GTKProcessEvent( event
);
1914 // Disable default focus handling for custom windows
1915 // since the default GTK+ handler issues a repaint
1916 if (win
->m_wxwindow
)
1922 //-----------------------------------------------------------------------------
1923 // "enter_notify_event"
1924 //-----------------------------------------------------------------------------
1927 gtk_window_enter_callback( GtkWidget
*widget
,
1928 GdkEventCrossing
*gdk_event
,
1931 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1933 // Event was emitted after a grab
1934 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1938 GdkModifierType state
= (GdkModifierType
)0;
1940 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1942 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
1943 InitMouseEvent(win
, event
, gdk_event
);
1944 wxPoint pt
= win
->GetClientAreaOrigin();
1945 event
.m_x
= x
+ pt
.x
;
1946 event
.m_y
= y
+ pt
.y
;
1948 if ( !g_captureWindow
)
1950 wxSetCursorEvent
cevent( event
.m_x
, event
.m_y
);
1951 if (win
->GTKProcessEvent( cevent
))
1953 win
->SetCursor( cevent
.GetCursor() );
1957 return win
->GTKProcessEvent(event
);
1960 //-----------------------------------------------------------------------------
1961 // "leave_notify_event"
1962 //-----------------------------------------------------------------------------
1965 gtk_window_leave_callback( GtkWidget
*widget
,
1966 GdkEventCrossing
*gdk_event
,
1969 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1971 // Event was emitted after an ungrab
1972 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1974 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
1975 event
.SetTimestamp( gdk_event
->time
);
1976 event
.SetEventObject( win
);
1980 GdkModifierType state
= (GdkModifierType
)0;
1982 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1984 event
.m_shiftDown
= (state
& GDK_SHIFT_MASK
) != 0;
1985 event
.m_controlDown
= (state
& GDK_CONTROL_MASK
) != 0;
1986 event
.m_altDown
= (state
& GDK_MOD1_MASK
) != 0;
1987 event
.m_metaDown
= (state
& GDK_MOD2_MASK
) != 0;
1988 event
.m_leftDown
= (state
& GDK_BUTTON1_MASK
) != 0;
1989 event
.m_middleDown
= (state
& GDK_BUTTON2_MASK
) != 0;
1990 event
.m_rightDown
= (state
& GDK_BUTTON3_MASK
) != 0;
1992 wxPoint pt
= win
->GetClientAreaOrigin();
1993 event
.m_x
= x
+ pt
.x
;
1994 event
.m_y
= y
+ pt
.y
;
1996 return win
->GTKProcessEvent(event
);
1999 //-----------------------------------------------------------------------------
2000 // "value_changed" from scrollbar
2001 //-----------------------------------------------------------------------------
2004 gtk_scrollbar_value_changed(GtkRange
* range
, wxWindow
* win
)
2006 wxEventType eventType
= win
->GetScrollEventType(range
);
2007 if (eventType
!= wxEVT_NULL
)
2009 // Convert scroll event type to scrollwin event type
2010 eventType
+= wxEVT_SCROLLWIN_TOP
- wxEVT_SCROLL_TOP
;
2012 // find the scrollbar which generated the event
2013 wxWindowGTK
::ScrollDir dir
= win
->ScrollDirFromRange(range
);
2015 // generate the corresponding wx event
2016 const int orient
= wxWindow
::OrientFromScrollDir(dir
);
2017 wxScrollWinEvent
event(eventType
, win
->GetScrollPos(orient
), orient
);
2018 event
.SetEventObject(win
);
2020 win
->m_blockValueChanged
[dir
] = true;
2021 win
->GTKProcessEvent(event
);
2022 win
->m_blockValueChanged
[dir
] = false;
2026 //-----------------------------------------------------------------------------
2027 // "button_press_event" from scrollbar
2028 //-----------------------------------------------------------------------------
2031 gtk_scrollbar_button_press_event(GtkRange
*, GdkEventButton
*, wxWindow
* win
)
2035 // don't need to install idle handler, its done from "event" signal
2037 g_blockEventsOnScroll
= true;
2038 win
->m_mouseButtonDown
= true;
2043 //-----------------------------------------------------------------------------
2044 // "event_after" from scrollbar
2045 //-----------------------------------------------------------------------------
2048 gtk_scrollbar_event_after(GtkRange
* range
, GdkEvent
* event
, wxWindow
* win
)
2050 if (event
->type
== GDK_BUTTON_RELEASE
)
2052 g_signal_handlers_block_by_func(range
, (void*)gtk_scrollbar_event_after
, win
);
2054 const int orient
= wxWindow
::OrientFromScrollDir(
2055 win
->ScrollDirFromRange(range
));
2056 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBRELEASE
, win
->GetScrollPos(orient
), orient
);
2057 event
.SetEventObject(win
);
2058 win
->GTKProcessEvent(event
);
2062 //-----------------------------------------------------------------------------
2063 // "button_release_event" from scrollbar
2064 //-----------------------------------------------------------------------------
2067 gtk_scrollbar_button_release_event(GtkRange
* range
, GdkEventButton
*, wxWindow
* win
)
2071 g_blockEventsOnScroll
= false;
2072 win
->m_mouseButtonDown
= false;
2073 // If thumb tracking
2074 if (win
->m_isScrolling
)
2076 win
->m_isScrolling
= false;
2077 // Hook up handler to send thumb release event after this emission is finished.
2078 // To allow setting scroll position from event handler, sending event must
2079 // be deferred until after the GtkRange handler for this signal has run
2080 g_signal_handlers_unblock_by_func(range
, (void*)gtk_scrollbar_event_after
, win
);
2086 //-----------------------------------------------------------------------------
2087 // "realize" from m_widget
2088 //-----------------------------------------------------------------------------
2090 /* We cannot set colours and fonts before the widget has
2091 been realized, so we do this directly after realization. */
2094 gtk_window_realized_callback( GtkWidget
*m_widget
, wxWindow
*win
)
2099 wxapp_install_idle_handler();
2103 GtkPizza
*pizza
= GTK_PIZZA( m_widget
);
2104 gtk_im_context_set_client_window( win
->m_imData
->context
,
2105 pizza
->bin_window
);
2108 wxWindowCreateEvent
event( win
);
2109 event
.SetEventObject( win
);
2110 win
->GTKProcessEvent( event
);
2113 //-----------------------------------------------------------------------------
2115 //-----------------------------------------------------------------------------
2118 void gtk_window_size_callback( GtkWidget
*WXUNUSED(widget
),
2119 GtkAllocation
*alloc
,
2123 wxapp_install_idle_handler();
2125 int client_width
= 0;
2126 int client_height
= 0;
2127 win
->GetClientSize( &client_width
, &client_height
);
2128 if ((client_width
== win
->m_oldClientWidth
) && (client_height
== win
->m_oldClientHeight
))
2132 wxPrintf( wxT("size_allocate ") );
2133 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
2134 wxPrintf( win
->GetClassInfo()->GetClassName() );
2135 wxPrintf( wxT(" %d %d %d %d\n"),
2142 win
->m_oldClientWidth
= client_width
;
2143 win
->m_oldClientHeight
= client_height
;
2145 if (!win
->m_nativeSizeEvent
)
2147 wxSizeEvent
event( win
->GetSize(), win
->GetId() );
2148 event
.SetEventObject( win
);
2149 win
->GTKProcessEvent( event
);
2155 // ----------------------------------------------------------------------------
2156 // this wxWindowBase function is implemented here (in platform-specific file)
2157 // because it is static and so couldn't be made virtual
2158 // ----------------------------------------------------------------------------
2160 wxWindow
*wxWindowBase
::DoFindFocus()
2162 // the cast is necessary when we compile in wxUniversal mode
2163 return (wxWindow
*)g_focusWindow
;
2166 //-----------------------------------------------------------------------------
2167 // InsertChild for wxWindowGTK.
2168 //-----------------------------------------------------------------------------
2170 /* Callback for wxWindowGTK. This very strange beast has to be used because
2171 * C++ has no virtual methods in a constructor. We have to emulate a
2172 * virtual function here as wxNotebook requires a different way to insert
2173 * a child in it. I had opted for creating a wxNotebookPage window class
2174 * which would have made this superfluous (such in the MDI window system),
2175 * but no-one was listening to me... */
2177 static void wxInsertChildInWindow( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2179 /* the window might have been scrolled already, do we
2180 have to adapt the position */
2181 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
2182 child
->m_x
+= gtk_pizza_get_xoffset( pizza
);
2183 child
->m_y
+= gtk_pizza_get_yoffset( pizza
);
2185 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
2186 GTK_WIDGET(child
->m_widget
),
2193 //-----------------------------------------------------------------------------
2195 //-----------------------------------------------------------------------------
2197 wxWindow
*wxGetActiveWindow()
2199 return wxWindow
::FindFocus();
2203 wxMouseState
wxGetMouseState()
2209 GdkModifierType mask
;
2211 gdk_window_get_pointer(NULL
, &x
, &y
, &mask
);
2215 ms
.SetLeftDown(mask
& GDK_BUTTON1_MASK
);
2216 ms
.SetMiddleDown(mask
& GDK_BUTTON2_MASK
);
2217 ms
.SetRightDown(mask
& GDK_BUTTON3_MASK
);
2219 ms
.SetControlDown(mask
& GDK_CONTROL_MASK
);
2220 ms
.SetShiftDown(mask
& GDK_SHIFT_MASK
);
2221 ms
.SetAltDown(mask
& GDK_MOD1_MASK
);
2222 ms
.SetMetaDown(mask
& GDK_MOD2_MASK
);
2227 //-----------------------------------------------------------------------------
2229 //-----------------------------------------------------------------------------
2231 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2233 #ifdef __WXUNIVERSAL__
2234 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2236 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
2237 #endif // __WXUNIVERSAL__/__WXGTK__
2239 void wxWindowGTK
::Init()
2242 m_widget
= (GtkWidget
*) NULL
;
2243 m_wxwindow
= (GtkWidget
*) NULL
;
2244 m_focusWidget
= (GtkWidget
*) NULL
;
2254 m_needParent
= true;
2255 m_isBeingDeleted
= false;
2257 m_showOnIdle
= false;
2260 m_nativeSizeEvent
= false;
2262 m_hasScrolling
= false;
2263 m_isScrolling
= false;
2264 m_mouseButtonDown
= false;
2265 m_blockScrollEvent
= false;
2267 // initialize scrolling stuff
2268 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
2270 m_scrollBar
[dir
] = NULL
;
2271 m_scrollPos
[dir
] = 0;
2272 m_blockValueChanged
[dir
] = false;
2276 m_oldClientHeight
= 0;
2280 m_insertCallback
= (wxInsertChildFunction
) NULL
;
2282 m_acceptsFocus
= false;
2285 m_clipPaintRegion
= false;
2287 m_needsStyleChange
= false;
2289 m_cursor
= *wxSTANDARD_CURSOR
;
2292 m_dirtyTabOrder
= false;
2295 wxWindowGTK
::wxWindowGTK()
2300 wxWindowGTK
::wxWindowGTK( wxWindow
*parent
,
2305 const wxString
&name
)
2309 Create( parent
, id
, pos
, size
, style
, name
);
2312 bool wxWindowGTK
::Create( wxWindow
*parent
,
2317 const wxString
&name
)
2319 if (!PreCreation( parent
, pos
, size
) ||
2320 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2322 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2326 m_insertCallback
= wxInsertChildInWindow
;
2328 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
2329 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
2331 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2333 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2334 scroll_class
->scrollbar_spacing
= 0;
2336 if (HasFlag(wxALWAYS_SHOW_SB
))
2338 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_ALWAYS
, GTK_POLICY_ALWAYS
);
2340 scrolledWindow
->hscrollbar_visible
= TRUE
;
2341 scrolledWindow
->vscrollbar_visible
= TRUE
;
2345 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2348 m_scrollBar
[ScrollDir_Horz
] = GTK_RANGE(scrolledWindow
->hscrollbar
);
2349 m_scrollBar
[ScrollDir_Vert
] = GTK_RANGE(scrolledWindow
->vscrollbar
);
2350 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2351 gtk_range_set_inverted( m_scrollBar
[ScrollDir_Horz
], TRUE
);
2353 m_wxwindow
= gtk_pizza_new();
2355 #ifndef __WXUNIVERSAL__
2356 if (HasFlag(wxSIMPLE_BORDER
))
2357 gtk_container_set_border_width((GtkContainer
*)m_wxwindow
, 1);
2358 else if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
2359 gtk_container_set_border_width((GtkContainer
*)m_wxwindow
, 2);
2360 #endif // __WXUNIVERSAL__
2362 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2364 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
2365 m_acceptsFocus
= true;
2367 // connect various scroll-related events
2368 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
2370 // these handlers block mouse events to any window during scrolling
2371 // such as motion events and prevent GTK and wxWidgets from fighting
2372 // over where the slider should be
2373 g_signal_connect(m_scrollBar
[dir
], "button_press_event",
2374 G_CALLBACK(gtk_scrollbar_button_press_event
), this);
2375 g_signal_connect(m_scrollBar
[dir
], "button_release_event",
2376 G_CALLBACK(gtk_scrollbar_button_release_event
), this);
2378 gulong handler_id
= g_signal_connect(m_scrollBar
[dir
], "event_after",
2379 G_CALLBACK(gtk_scrollbar_event_after
), this);
2380 g_signal_handler_block(m_scrollBar
[dir
], handler_id
);
2382 // these handlers get notified when scrollbar slider moves
2383 g_signal_connect(m_scrollBar
[dir
], "value_changed",
2384 G_CALLBACK(gtk_scrollbar_value_changed
), this);
2387 gtk_widget_show( m_wxwindow
);
2390 m_parent
->DoAddChild( this );
2392 m_focusWidget
= m_wxwindow
;
2399 wxWindowGTK
::~wxWindowGTK()
2403 if (g_focusWindow
== this)
2404 g_focusWindow
= NULL
;
2406 if ( g_delayedFocus
== this )
2407 g_delayedFocus
= NULL
;
2409 m_isBeingDeleted
= true;
2412 // destroy children before destroying this window itself
2415 // unhook focus handlers to prevent stray events being
2416 // propagated to this (soon to be) dead object
2417 if (m_focusWidget
!= NULL
)
2419 g_signal_handlers_disconnect_by_func (m_focusWidget
,
2420 (gpointer
) gtk_window_focus_in_callback
,
2422 g_signal_handlers_disconnect_by_func (m_focusWidget
,
2423 (gpointer
) gtk_window_focus_out_callback
,
2430 // delete before the widgets to avoid a crash on solaris
2435 gtk_widget_destroy( m_wxwindow
);
2436 m_wxwindow
= (GtkWidget
*) NULL
;
2441 gtk_widget_destroy( m_widget
);
2442 m_widget
= (GtkWidget
*) NULL
;
2446 bool wxWindowGTK
::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2448 wxCHECK_MSG( !m_needParent
|| parent
, false, wxT("Need complete parent.") );
2450 // Use either the given size, or the default if -1 is given.
2451 // See wxWindowBase for these functions.
2452 m_width
= WidthDefault(size
.x
) ;
2453 m_height
= HeightDefault(size
.y
);
2461 void wxWindowGTK
::PostCreation()
2463 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2469 // these get reported to wxWidgets -> wxPaintEvent
2471 g_signal_connect (m_wxwindow
, "expose_event",
2472 G_CALLBACK (gtk_window_expose_callback
), this);
2474 if (GetLayoutDirection() == wxLayout_LeftToRight
)
2475 gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow
), HasFlag( wxFULL_REPAINT_ON_RESIZE
) );
2478 // Create input method handler
2479 m_imData
= new wxGtkIMData
;
2481 // Cannot handle drawing preedited text yet
2482 gtk_im_context_set_use_preedit( m_imData
->context
, FALSE
);
2484 g_signal_connect (m_imData
->context
, "commit",
2485 G_CALLBACK (gtk_wxwindow_commit_cb
), this);
2487 // these are called when the "sunken" or "raised" borders are drawn
2488 g_signal_connect (m_widget
, "expose_event",
2489 G_CALLBACK (gtk_window_own_expose_callback
), this);
2494 if (!GTK_IS_WINDOW(m_widget
))
2496 if (m_focusWidget
== NULL
)
2497 m_focusWidget
= m_widget
;
2501 g_signal_connect (m_focusWidget
, "focus_in_event",
2502 G_CALLBACK (gtk_window_focus_in_callback
), this);
2503 g_signal_connect (m_focusWidget
, "focus_out_event",
2504 G_CALLBACK (gtk_window_focus_out_callback
), this);
2508 g_signal_connect_after (m_focusWidget
, "focus_in_event",
2509 G_CALLBACK (gtk_window_focus_in_callback
), this);
2510 g_signal_connect_after (m_focusWidget
, "focus_out_event",
2511 G_CALLBACK (gtk_window_focus_out_callback
), this);
2515 // connect to the various key and mouse handlers
2517 GtkWidget
*connect_widget
= GetConnectWidget();
2519 ConnectWidget( connect_widget
);
2521 /* We cannot set colours, fonts and cursors before the widget has
2522 been realized, so we do this directly after realization */
2523 g_signal_connect (connect_widget
, "realize",
2524 G_CALLBACK (gtk_window_realized_callback
), this);
2528 // Catch native resize events
2529 g_signal_connect (m_wxwindow
, "size_allocate",
2530 G_CALLBACK (gtk_window_size_callback
), this);
2533 if (GTK_IS_COMBO(m_widget
))
2535 GtkCombo
*gcombo
= GTK_COMBO(m_widget
);
2537 g_signal_connect (gcombo
->entry
, "size_request",
2538 G_CALLBACK (wxgtk_combo_size_request_callback
),
2541 #ifdef GTK_IS_FILE_CHOOSER_BUTTON
2542 else if (!gtk_check_version(2,6,0) && GTK_IS_FILE_CHOOSER_BUTTON(m_widget
))
2544 // If we connect to the "size_request" signal of a GtkFileChooserButton
2545 // then that control won't be sized properly when placed inside sizers
2546 // (this can be tested removing this elseif and running XRC or WIDGETS samples)
2547 // FIXME: what should be done here ?
2552 // This is needed if we want to add our windows into native
2553 // GTK controls, such as the toolbar. With this callback, the
2554 // toolbar gets to know the correct size (the one set by the
2555 // programmer). Sadly, it misbehaves for wxComboBox.
2556 g_signal_connect (m_widget
, "size_request",
2557 G_CALLBACK (wxgtk_window_size_request_callback
),
2561 InheritAttributes();
2565 SetLayoutDirection(wxLayout_Default
);
2567 // unless the window was created initially hidden (i.e. Hide() had been
2568 // called before Create()), we should show it at GTK+ level as well
2570 gtk_widget_show( m_widget
);
2573 void wxWindowGTK
::ConnectWidget( GtkWidget
*widget
)
2575 g_signal_connect (widget
, "key_press_event",
2576 G_CALLBACK (gtk_window_key_press_callback
), this);
2577 g_signal_connect (widget
, "key_release_event",
2578 G_CALLBACK (gtk_window_key_release_callback
), this);
2579 g_signal_connect (widget
, "button_press_event",
2580 G_CALLBACK (gtk_window_button_press_callback
), this);
2581 g_signal_connect (widget
, "button_release_event",
2582 G_CALLBACK (gtk_window_button_release_callback
), this);
2583 g_signal_connect (widget
, "motion_notify_event",
2584 G_CALLBACK (gtk_window_motion_notify_callback
), this);
2585 g_signal_connect (widget
, "scroll_event",
2586 G_CALLBACK (window_scroll_event
), this);
2587 g_signal_connect (widget
, "popup_menu",
2588 G_CALLBACK (wxgtk_window_popup_menu_callback
), this);
2589 g_signal_connect (widget
, "enter_notify_event",
2590 G_CALLBACK (gtk_window_enter_callback
), this);
2591 g_signal_connect (widget
, "leave_notify_event",
2592 G_CALLBACK (gtk_window_leave_callback
), this);
2595 bool wxWindowGTK
::Destroy()
2597 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2601 return wxWindowBase
::Destroy();
2604 void wxWindowGTK
::DoMoveWindow(int x
, int y
, int width
, int height
)
2606 // inform the parent to perform the move
2607 gtk_pizza_set_size( GTK_PIZZA(m_parent
->m_wxwindow
), m_widget
, x
, y
, width
, height
);
2611 void wxWindowGTK
::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
2613 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2614 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
2616 if (m_resizing
) return; /* I don't like recursions */
2619 int currentX
, currentY
;
2620 GetPosition(¤tX
, ¤tY
);
2621 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2623 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2625 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2627 // calculate the best size if we should auto size the window
2628 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
2629 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
2631 const wxSize sizeBest
= GetBestSize();
2632 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
2634 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
2635 height
= sizeBest
.y
;
2643 int minWidth
= GetMinWidth(),
2644 minHeight
= GetMinHeight(),
2645 maxWidth
= GetMaxWidth(),
2646 maxHeight
= GetMaxHeight();
2648 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
2649 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
2650 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
2651 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
2653 #if wxUSE_TOOLBAR_NATIVE
2654 if (wxDynamicCast(GetParent(), wxToolBar
))
2656 // don't take the x,y values, they're wrong because toolbar sets them
2657 GtkWidget
*widget
= GTK_WIDGET(m_widget
);
2658 gtk_widget_set_size_request (widget
, m_width
, m_height
);
2662 if (m_parent
->m_wxwindow
== NULL
) // i.e. wxNotebook
2664 // don't set the size for children of wxNotebook, just take the values.
2672 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
2673 if ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0)
2675 if (x
!= -1) m_x
= x
+ gtk_pizza_get_xoffset( pizza
);
2676 if (y
!= -1) m_y
= y
+ gtk_pizza_get_yoffset( pizza
);
2680 m_x
= x
+ gtk_pizza_get_xoffset( pizza
);
2681 m_y
= y
+ gtk_pizza_get_yoffset( pizza
);
2684 int left_border
= 0;
2685 int right_border
= 0;
2687 int bottom_border
= 0;
2689 /* the default button has a border around it */
2690 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
2692 GtkBorder
*default_border
= NULL
;
2693 gtk_widget_style_get( m_widget
, "default_border", &default_border
, NULL
);
2696 left_border
+= default_border
->left
;
2697 right_border
+= default_border
->right
;
2698 top_border
+= default_border
->top
;
2699 bottom_border
+= default_border
->bottom
;
2700 g_free( default_border
);
2704 DoMoveWindow( m_x
-top_border
,
2706 m_width
+left_border
+right_border
,
2707 m_height
+top_border
+bottom_border
);
2712 /* Sometimes the client area changes size without the
2713 whole windows's size changing, but if the whole
2714 windows's size doesn't change, no wxSizeEvent will
2715 normally be sent. Here we add an extra test if
2716 the client test has been changed and this will
2718 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
2722 wxPrintf( "OnSize sent from " );
2723 if (GetClassInfo() && GetClassInfo()->GetClassName())
2724 wxPrintf( GetClassInfo()->GetClassName() );
2725 wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height );
2728 if (!m_nativeSizeEvent
)
2730 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
2731 event
.SetEventObject( this );
2732 GetEventHandler()->ProcessEvent( event
);
2738 bool wxWindowGTK
::GtkShowFromOnIdle()
2740 if (IsShown() && m_showOnIdle
&& !GTK_WIDGET_VISIBLE (m_widget
))
2742 GtkAllocation alloc
;
2745 alloc
.width
= m_width
;
2746 alloc
.height
= m_height
;
2747 gtk_widget_size_allocate( m_widget
, &alloc
);
2748 gtk_widget_show( m_widget
);
2749 wxShowEvent
eventShow(GetId(), true);
2750 eventShow
.SetEventObject(this);
2751 GetEventHandler()->ProcessEvent(eventShow
);
2752 m_showOnIdle
= false;
2759 void wxWindowGTK
::OnInternalIdle()
2761 // Check if we have to show window now
2762 if (GtkShowFromOnIdle()) return;
2764 if ( m_dirtyTabOrder
)
2766 m_dirtyTabOrder
= false;
2770 // Update style if the window was not yet realized
2771 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
2772 if (m_needsStyleChange
)
2774 SetBackgroundStyle(GetBackgroundStyle());
2775 m_needsStyleChange
= false;
2778 wxCursor cursor
= m_cursor
;
2779 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
2783 /* I now set the cursor anew in every OnInternalIdle call
2784 as setting the cursor in a parent window also effects the
2785 windows above so that checking for the current cursor is
2790 GdkWindow
*window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
2792 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2794 if (!g_globalCursor
.Ok())
2795 cursor
= *wxSTANDARD_CURSOR
;
2797 window
= m_widget
->window
;
2798 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2799 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2802 else if ( m_widget
)
2804 GdkWindow
*window
= m_widget
->window
;
2805 if ( window
&& !GTK_WIDGET_NO_WINDOW(m_widget
) )
2806 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2810 if (wxUpdateUIEvent
::CanUpdate(this))
2811 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2814 void wxWindowGTK
::DoGetSize( int *width
, int *height
) const
2816 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2818 if (width
) (*width
) = m_width
;
2819 if (height
) (*height
) = m_height
;
2822 void wxWindowGTK
::DoSetClientSize( int width
, int height
)
2824 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2833 GetScrollbarWidth(m_widget
, dw
, dh
);
2836 const int border
= GTK_CONTAINER(m_wxwindow
)->border_width
;
2844 SetSize(width
, height
);
2847 void wxWindowGTK
::DoGetClientSize( int *width
, int *height
) const
2849 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2860 GetScrollbarWidth(m_widget
, dw
, dh
);
2862 const int border
= GTK_CONTAINER(m_wxwindow
)->border_width
;
2874 if (width
) *width
= w
;
2875 if (height
) *height
= h
;
2878 void wxWindowGTK
::DoGetPosition( int *x
, int *y
) const
2880 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2884 if (m_parent
&& m_parent
->m_wxwindow
)
2886 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
2887 dx
= gtk_pizza_get_xoffset( pizza
);
2888 dy
= gtk_pizza_get_yoffset( pizza
);
2891 if (m_x
== -1 && m_y
== -1)
2893 GdkWindow
*source
= (GdkWindow
*) NULL
;
2895 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
2897 source
= m_widget
->window
;
2903 gdk_window_get_origin( source
, &org_x
, &org_y
);
2906 GetParent()->ScreenToClient(&org_x
, &org_y
);
2908 wx_const_cast(wxWindowGTK
*, this)->m_x
= org_x
;
2909 wx_const_cast(wxWindowGTK
*, this)->m_y
= org_y
;
2913 if (x
) (*x
) = m_x
- dx
;
2914 if (y
) (*y
) = m_y
- dy
;
2917 void wxWindowGTK
::DoClientToScreen( int *x
, int *y
) const
2919 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2921 if (!m_widget
->window
) return;
2923 GdkWindow
*source
= (GdkWindow
*) NULL
;
2925 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
2927 source
= m_widget
->window
;
2931 gdk_window_get_origin( source
, &org_x
, &org_y
);
2935 if (GTK_WIDGET_NO_WINDOW (m_widget
))
2937 org_x
+= m_widget
->allocation
.x
;
2938 org_y
+= m_widget
->allocation
.y
;
2945 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2946 *x
= (GetClientSize().x
- *x
) + org_x
;
2954 void wxWindowGTK
::DoScreenToClient( int *x
, int *y
) const
2956 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2958 if (!m_widget
->window
) return;
2960 GdkWindow
*source
= (GdkWindow
*) NULL
;
2962 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
2964 source
= m_widget
->window
;
2968 gdk_window_get_origin( source
, &org_x
, &org_y
);
2972 if (GTK_WIDGET_NO_WINDOW (m_widget
))
2974 org_x
+= m_widget
->allocation
.x
;
2975 org_y
+= m_widget
->allocation
.y
;
2981 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2982 *x
= (GetClientSize().x
- *x
) - org_x
;
2989 bool wxWindowGTK
::Show( bool show
)
2991 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
2993 if (!wxWindowBase
::Show(show
))
3003 gtk_widget_show( m_widget
);
3004 wxShowEvent
eventShow(GetId(), show
);
3005 eventShow
.SetEventObject(this);
3006 GetEventHandler()->ProcessEvent(eventShow
);
3011 gtk_widget_hide( m_widget
);
3012 wxShowEvent
eventShow(GetId(), show
);
3013 eventShow
.SetEventObject(this);
3014 GetEventHandler()->ProcessEvent(eventShow
);
3020 static void wxWindowNotifyEnable(wxWindowGTK
* win
, bool enable
)
3022 win
->OnParentEnable(enable
);
3024 // Recurse, so that children have the opportunity to Do The Right Thing
3025 // and reset colours that have been messed up by a parent's (really ancestor's)
3027 for ( wxWindowList
::compatibility_iterator node
= win
->GetChildren().GetFirst();
3029 node
= node
->GetNext() )
3031 wxWindow
*child
= node
->GetData();
3032 if (!child
->IsKindOf(CLASSINFO(wxDialog
)) && !child
->IsKindOf(CLASSINFO(wxFrame
)))
3033 wxWindowNotifyEnable(child
, enable
);
3037 bool wxWindowGTK
::Enable( bool enable
)
3039 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3041 if (!wxWindowBase
::Enable(enable
))
3047 gtk_widget_set_sensitive( m_widget
, enable
);
3049 gtk_widget_set_sensitive( m_wxwindow
, enable
);
3051 wxWindowNotifyEnable(this, enable
);
3056 int wxWindowGTK
::GetCharHeight() const
3058 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
3060 wxFont font
= GetFont();
3061 wxCHECK_MSG( font
.Ok(), 12, wxT("invalid font") );
3063 PangoContext
*context
= NULL
;
3065 context
= gtk_widget_get_pango_context( m_widget
);
3070 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
3071 PangoLayout
*layout
= pango_layout_new(context
);
3072 pango_layout_set_font_description(layout
, desc
);
3073 pango_layout_set_text(layout
, "H", 1);
3074 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
3076 PangoRectangle rect
;
3077 pango_layout_line_get_extents(line
, NULL
, &rect
);
3079 g_object_unref (layout
);
3081 return (int) PANGO_PIXELS(rect
.height
);
3084 int wxWindowGTK
::GetCharWidth() const
3086 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
3088 wxFont font
= GetFont();
3089 wxCHECK_MSG( font
.Ok(), 8, wxT("invalid font") );
3091 PangoContext
*context
= NULL
;
3093 context
= gtk_widget_get_pango_context( m_widget
);
3098 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
3099 PangoLayout
*layout
= pango_layout_new(context
);
3100 pango_layout_set_font_description(layout
, desc
);
3101 pango_layout_set_text(layout
, "g", 1);
3102 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
3104 PangoRectangle rect
;
3105 pango_layout_line_get_extents(line
, NULL
, &rect
);
3107 g_object_unref (layout
);
3109 return (int) PANGO_PIXELS(rect
.width
);
3112 void wxWindowGTK
::GetTextExtent( const wxString
& string
,
3116 int *externalLeading
,
3117 const wxFont
*theFont
) const
3119 wxFont fontToUse
= theFont ?
*theFont
: GetFont();
3121 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
3130 PangoContext
*context
= NULL
;
3132 context
= gtk_widget_get_pango_context( m_widget
);
3141 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
3142 PangoLayout
*layout
= pango_layout_new(context
);
3143 pango_layout_set_font_description(layout
, desc
);
3145 const wxCharBuffer data
= wxGTK_CONV( string
);
3147 pango_layout_set_text(layout
, data
, strlen(data
));
3150 PangoRectangle rect
;
3151 pango_layout_get_extents(layout
, NULL
, &rect
);
3153 if (x
) (*x
) = (wxCoord
) PANGO_PIXELS(rect
.width
);
3154 if (y
) (*y
) = (wxCoord
) PANGO_PIXELS(rect
.height
);
3157 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
3158 int baseline
= pango_layout_iter_get_baseline(iter
);
3159 pango_layout_iter_free(iter
);
3160 *descent
= *y
- PANGO_PIXELS(baseline
);
3162 if (externalLeading
) (*externalLeading
) = 0; // ??
3164 g_object_unref (layout
);
3167 bool wxWindowGTK
::GTKSetDelayedFocusIfNeeded()
3169 if ( g_delayedFocus
== this )
3171 if ( GTK_WIDGET_REALIZED(m_widget
) )
3173 gtk_widget_grab_focus(m_widget
);
3174 g_delayedFocus
= NULL
;
3183 void wxWindowGTK
::SetFocus()
3185 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3188 // don't do anything if we already have focus
3194 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow
))
3196 gtk_widget_grab_focus (m_wxwindow
);
3201 if (GTK_IS_CONTAINER(m_widget
))
3203 if (IsKindOf(CLASSINFO(wxRadioButton
)))
3205 gtk_widget_grab_focus (m_widget
);
3209 gtk_widget_child_focus( m_widget
, GTK_DIR_TAB_FORWARD
);
3212 if (GTK_WIDGET_CAN_FOCUS(m_widget
) && !GTK_WIDGET_HAS_FOCUS (m_widget
) )
3215 if (!GTK_WIDGET_REALIZED(m_widget
))
3217 // we can't set the focus to the widget now so we remember that
3218 // it should be focused and will do it later, during the idle
3219 // time, as soon as we can
3220 wxLogTrace(TRACE_FOCUS
,
3221 _T("Delaying setting focus to %s(%s)"),
3222 GetClassInfo()->GetClassName(), GetLabel().c_str());
3224 g_delayedFocus
= this;
3228 wxLogTrace(TRACE_FOCUS
,
3229 _T("Setting focus to %s(%s)"),
3230 GetClassInfo()->GetClassName(), GetLabel().c_str());
3232 gtk_widget_grab_focus (m_widget
);
3237 wxLogTrace(TRACE_FOCUS
,
3238 _T("Can't set focus to %s(%s)"),
3239 GetClassInfo()->GetClassName(), GetLabel().c_str());
3244 bool wxWindowGTK
::AcceptsFocus() const
3246 return m_acceptsFocus
&& wxWindowBase
::AcceptsFocus();
3249 bool wxWindowGTK
::Reparent( wxWindowBase
*newParentBase
)
3251 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3253 wxWindowGTK
*oldParent
= m_parent
,
3254 *newParent
= (wxWindowGTK
*)newParentBase
;
3256 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3258 if ( !wxWindowBase
::Reparent(newParent
) )
3261 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3263 /* prevent GTK from deleting the widget arbitrarily */
3264 gtk_widget_ref( m_widget
);
3268 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3271 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3275 if (GTK_WIDGET_VISIBLE (newParent
->m_widget
))
3277 m_showOnIdle
= true;
3278 gtk_widget_hide( m_widget
);
3281 /* insert GTK representation */
3282 (*(newParent
->m_insertCallback
))(newParent
, this);
3285 /* reverse: prevent GTK from deleting the widget arbitrarily */
3286 gtk_widget_unref( m_widget
);
3288 SetLayoutDirection(wxLayout_Default
);
3293 void wxWindowGTK
::DoAddChild(wxWindowGTK
*child
)
3295 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3297 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3299 wxASSERT_MSG( (m_insertCallback
!= NULL
), wxT("invalid child insertion function") );
3304 /* insert GTK representation */
3305 (*m_insertCallback
)(this, child
);
3308 void wxWindowGTK
::AddChild(wxWindowBase
*child
)
3310 wxWindowBase
::AddChild(child
);
3311 m_dirtyTabOrder
= true;
3313 wxapp_install_idle_handler();
3316 void wxWindowGTK
::RemoveChild(wxWindowBase
*child
)
3318 wxWindowBase
::RemoveChild(child
);
3319 m_dirtyTabOrder
= true;
3321 wxapp_install_idle_handler();
3325 wxLayoutDirection wxWindowGTK
::GTKGetLayout(GtkWidget
*widget
)
3327 return gtk_widget_get_direction(GTK_WIDGET(widget
)) == GTK_TEXT_DIR_RTL
3328 ? wxLayout_RightToLeft
3329 : wxLayout_LeftToRight
;
3333 void wxWindowGTK
::GTKSetLayout(GtkWidget
*widget
, wxLayoutDirection dir
)
3335 wxASSERT_MSG( dir
!= wxLayout_Default
, _T("invalid layout direction") );
3337 gtk_widget_set_direction(GTK_WIDGET(widget
),
3338 dir
== wxLayout_RightToLeft ? GTK_TEXT_DIR_RTL
3339 : GTK_TEXT_DIR_LTR
);
3342 wxLayoutDirection wxWindowGTK
::GetLayoutDirection() const
3344 return GTKGetLayout(m_widget
);
3347 void wxWindowGTK
::SetLayoutDirection(wxLayoutDirection dir
)
3349 if ( dir
== wxLayout_Default
)
3351 const wxWindow
*const parent
= GetParent();
3354 // inherit layout from parent.
3355 dir
= parent
->GetLayoutDirection();
3357 else // no parent, use global default layout
3359 dir
= wxTheApp
->GetLayoutDirection();
3363 if ( dir
== wxLayout_Default
)
3366 GTKSetLayout(m_widget
, dir
);
3369 GTKSetLayout(m_wxwindow
, dir
);
3373 wxWindowGTK
::AdjustForLayoutDirection(wxCoord x
,
3374 wxCoord
WXUNUSED(width
),
3375 wxCoord
WXUNUSED(widthTotal
)) const
3377 // We now mirrors the coordinates of RTL windows in GtkPizza
3381 void wxWindowGTK
::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
3383 wxWindowBase
::DoMoveInTabOrder(win
, move
);
3384 m_dirtyTabOrder
= true;
3386 wxapp_install_idle_handler();
3389 bool wxWindowGTK
::GTKWidgetNeedsMnemonic() const
3391 // none needed by default
3395 void wxWindowGTK
::GTKWidgetDoSetMnemonic(GtkWidget
* WXUNUSED(w
))
3397 // nothing to do by default since none is needed
3400 void wxWindowGTK
::RealizeTabOrder()
3404 if ( !m_children
.empty() )
3406 // we don't only construct the correct focus chain but also use
3407 // this opportunity to update the mnemonic widgets for the widgets
3410 GList
*chain
= NULL
;
3411 wxWindowGTK
* mnemonicWindow
= NULL
;
3413 for ( wxWindowList
::const_iterator i
= m_children
.begin();
3414 i
!= m_children
.end();
3417 wxWindowGTK
*win
= *i
;
3419 if ( mnemonicWindow
)
3421 if ( win
->AcceptsFocusFromKeyboard() )
3423 // wxComboBox et al. needs to focus on on a different
3424 // widget than m_widget, so if the main widget isn't
3425 // focusable try the connect widget
3426 GtkWidget
* w
= win
->m_widget
;
3427 if ( !GTK_WIDGET_CAN_FOCUS(w
) )
3429 w
= win
->GetConnectWidget();
3430 if ( !GTK_WIDGET_CAN_FOCUS(w
) )
3436 mnemonicWindow
->GTKWidgetDoSetMnemonic(w
);
3437 mnemonicWindow
= NULL
;
3441 else if ( win
->GTKWidgetNeedsMnemonic() )
3443 mnemonicWindow
= win
;
3446 chain
= g_list_prepend(chain
, win
->m_widget
);
3449 chain
= g_list_reverse(chain
);
3451 gtk_container_set_focus_chain(GTK_CONTAINER(m_wxwindow
), chain
);
3456 gtk_container_unset_focus_chain(GTK_CONTAINER(m_wxwindow
));
3461 void wxWindowGTK
::Raise()
3463 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3465 if (m_wxwindow
&& m_wxwindow
->window
)
3467 gdk_window_raise( m_wxwindow
->window
);
3469 else if (m_widget
->window
)
3471 gdk_window_raise( m_widget
->window
);
3475 void wxWindowGTK
::Lower()
3477 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3479 if (m_wxwindow
&& m_wxwindow
->window
)
3481 gdk_window_lower( m_wxwindow
->window
);
3483 else if (m_widget
->window
)
3485 gdk_window_lower( m_widget
->window
);
3489 bool wxWindowGTK
::SetCursor( const wxCursor
&cursor
)
3491 if ( !wxWindowBase
::SetCursor(cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
) )
3499 void wxWindowGTK
::GTKUpdateCursor()
3501 wxCursor
cursor(g_globalCursor
.Ok() ? g_globalCursor
: GetCursor());
3504 wxArrayGdkWindows windowsThis
;
3505 GdkWindow
* const winThis
= GTKGetWindow(windowsThis
);
3508 gdk_window_set_cursor(winThis
, cursor
.GetCursor());
3512 const size_t count
= windowsThis
.size();
3513 for ( size_t n
= 0; n
< count
; n
++ )
3515 GdkWindow
*win
= windowsThis
[n
];
3518 wxFAIL_MSG(_T("NULL window returned by GTKGetWindow()?"));
3522 gdk_window_set_cursor(win
, cursor
.GetCursor());
3528 void wxWindowGTK
::WarpPointer( int x
, int y
)
3530 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3532 // We provide this function ourselves as it is
3533 // missing in GDK (top of this file).
3535 GdkWindow
*window
= (GdkWindow
*) NULL
;
3537 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3539 window
= GetConnectWidget()->window
;
3542 gdk_window_warp_pointer( window
, x
, y
);
3545 wxWindowGTK
::ScrollDir wxWindowGTK
::ScrollDirFromRange(GtkRange
*range
) const
3547 // find the scrollbar which generated the event
3548 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
3550 if ( range
== m_scrollBar
[dir
] )
3551 return (ScrollDir
)dir
;
3554 wxFAIL_MSG( _T("event from unknown scrollbar received") );
3556 return ScrollDir_Max
;
3559 bool wxWindowGTK
::DoScrollByUnits(ScrollDir dir
, ScrollUnit unit
, int units
)
3561 bool changed
= false;
3562 GtkRange
* range
= m_scrollBar
[dir
];
3563 if ( range
&& units
)
3565 GtkAdjustment
* adj
= range
->adjustment
;
3566 gdouble inc
= unit
== ScrollUnit_Line ? adj
->step_increment
3567 : adj
->page_increment
;
3569 const int posOld
= int(adj
->value
+ 0.5);
3570 gtk_range_set_value(range
, posOld
+ units
*inc
);
3572 changed
= int(adj
->value
+ 0.5) != posOld
;
3578 bool wxWindowGTK
::ScrollLines(int lines
)
3580 return DoScrollByUnits(ScrollDir_Vert
, ScrollUnit_Line
, lines
);
3583 bool wxWindowGTK
::ScrollPages(int pages
)
3585 return DoScrollByUnits(ScrollDir_Vert
, ScrollUnit_Page
, pages
);
3588 void wxWindowGTK
::Refresh( bool eraseBackground
, const wxRect
*rect
)
3592 if (!m_widget
->window
)
3597 if (!GTK_PIZZA(m_wxwindow
)->bin_window
) return;
3599 GdkRectangle gdk_rect
,
3603 gdk_rect
.x
= rect
->x
;
3604 gdk_rect
.y
= rect
->y
;
3605 gdk_rect
.width
= rect
->width
;
3606 gdk_rect
.height
= rect
->height
;
3607 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3608 gdk_rect
.x
= GetClientSize().x
- gdk_rect
.x
- gdk_rect
.width
;
3612 else // invalidate everything
3617 gdk_window_invalidate_rect( GTK_PIZZA(m_wxwindow
)->bin_window
, p
, TRUE
);
3621 void wxWindowGTK
::Update()
3625 // when we call Update() we really want to update the window immediately on
3626 // screen, even if it means flushing the entire queue and hence slowing down
3627 // everything -- but it should still be done, it's just that Update() should
3628 // be called very rarely
3632 void wxWindowGTK
::GtkUpdate()
3634 if (m_wxwindow
&& GTK_PIZZA(m_wxwindow
)->bin_window
)
3635 gdk_window_process_updates( GTK_PIZZA(m_wxwindow
)->bin_window
, FALSE
);
3636 if (m_widget
&& m_widget
->window
)
3637 gdk_window_process_updates( m_widget
->window
, FALSE
);
3639 // for consistency with other platforms (and also because it's convenient
3640 // to be able to update an entire TLW by calling Update() only once), we
3641 // should also update all our children here
3642 for ( wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
3644 node
= node
->GetNext() )
3646 node
->GetData()->GtkUpdate();
3650 bool wxWindowGTK
::DoIsExposed( int x
, int y
) const
3652 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
3656 bool wxWindowGTK
::DoIsExposed( int x
, int y
, int w
, int h
) const
3658 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3659 return m_updateRegion
.Contains(x
-w
, y
, w
, h
) != wxOutRegion
;
3661 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
3664 void wxWindowGTK
::GtkSendPaintEvents()
3668 m_updateRegion
.Clear();
3672 // Clip to paint region in wxClientDC
3673 m_clipPaintRegion
= true;
3675 m_nativeUpdateRegion
= m_updateRegion
;
3677 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3679 // Transform m_updateRegion under RTL
3680 m_updateRegion
.Clear();
3683 gdk_window_get_geometry( GTK_PIZZA(m_wxwindow
)->bin_window
,
3684 NULL
, NULL
, &width
, NULL
, NULL
);
3686 wxRegionIterator
upd( m_nativeUpdateRegion
);
3690 rect
.x
= upd
.GetX();
3691 rect
.y
= upd
.GetY();
3692 rect
.width
= upd
.GetWidth();
3693 rect
.height
= upd
.GetHeight();
3695 rect
.x
= width
- rect
.x
- rect
.width
;
3696 m_updateRegion
.Union( rect
);
3702 // widget to draw on
3703 GtkPizza
*pizza
= GTK_PIZZA (m_wxwindow
);
3705 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM
))
3707 // find ancestor from which to steal background
3708 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3710 parent
= (wxWindow
*)this;
3712 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
3714 wxRegionIterator
upd( m_nativeUpdateRegion
);
3718 rect
.x
= upd
.GetX();
3719 rect
.y
= upd
.GetY();
3720 rect
.width
= upd
.GetWidth();
3721 rect
.height
= upd
.GetHeight();
3723 gtk_paint_flat_box( parent
->m_widget
->style
,
3725 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
3738 wxWindowDC
dc( (wxWindow
*)this );
3739 dc
.SetClippingRegion( m_updateRegion
);
3741 wxEraseEvent
erase_event( GetId(), &dc
);
3742 erase_event
.SetEventObject( this );
3744 GetEventHandler()->ProcessEvent(erase_event
);
3747 wxNcPaintEvent
nc_paint_event( GetId() );
3748 nc_paint_event
.SetEventObject( this );
3749 GetEventHandler()->ProcessEvent( nc_paint_event
);
3751 wxPaintEvent
paint_event( GetId() );
3752 paint_event
.SetEventObject( this );
3753 GetEventHandler()->ProcessEvent( paint_event
);
3755 m_clipPaintRegion
= false;
3757 m_updateRegion
.Clear();
3758 m_nativeUpdateRegion
.Clear();
3761 void wxWindowGTK
::SetDoubleBuffered( bool on
)
3763 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3766 gtk_widget_set_double_buffered( m_wxwindow
, on
);
3769 bool wxWindowGTK
::IsDoubleBuffered() const
3771 return GTK_WIDGET_DOUBLE_BUFFERED( m_wxwindow
);
3774 void wxWindowGTK
::ClearBackground()
3776 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3780 void wxWindowGTK
::DoSetToolTip( wxToolTip
*tip
)
3782 wxWindowBase
::DoSetToolTip(tip
);
3785 m_tooltip
->Apply( (wxWindow
*)this );
3788 void wxWindowGTK
::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
3792 wxString
tmp( tip
);
3793 gtk_tooltips_set_tip( tips
, GetConnectWidget(), wxGTK_CONV(tmp
), (gchar
*) NULL
);
3797 gtk_tooltips_set_tip( tips
, GetConnectWidget(), NULL
, NULL
);
3800 #endif // wxUSE_TOOLTIPS
3802 bool wxWindowGTK
::SetBackgroundColour( const wxColour
&colour
)
3804 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3806 if (!wxWindowBase
::SetBackgroundColour(colour
))
3811 // We need the pixel value e.g. for background clearing.
3812 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3815 // apply style change (forceStyle=true so that new style is applied
3816 // even if the bg colour changed from valid to wxNullColour)
3817 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3818 ApplyWidgetStyle(true);
3823 bool wxWindowGTK
::SetForegroundColour( const wxColour
&colour
)
3825 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3827 if (!wxWindowBase
::SetForegroundColour(colour
))
3834 // We need the pixel value e.g. for background clearing.
3835 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3838 // apply style change (forceStyle=true so that new style is applied
3839 // even if the bg colour changed from valid to wxNullColour):
3840 ApplyWidgetStyle(true);
3845 PangoContext
*wxWindowGTK
::GtkGetPangoDefaultContext()
3847 return gtk_widget_get_pango_context( m_widget
);
3850 GtkRcStyle
*wxWindowGTK
::CreateWidgetStyle(bool forceStyle
)
3852 // do we need to apply any changes at all?
3855 !m_foregroundColour
.Ok() && !m_backgroundColour
.Ok() )
3860 GtkRcStyle
*style
= gtk_rc_style_new();
3865 pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
3868 if ( m_foregroundColour
.Ok() )
3870 const GdkColor
*fg
= m_foregroundColour
.GetColor();
3872 style
->fg
[GTK_STATE_NORMAL
] = *fg
;
3873 style
->color_flags
[GTK_STATE_NORMAL
] = GTK_RC_FG
;
3875 style
->fg
[GTK_STATE_PRELIGHT
] = *fg
;
3876 style
->color_flags
[GTK_STATE_PRELIGHT
] = GTK_RC_FG
;
3878 style
->fg
[GTK_STATE_ACTIVE
] = *fg
;
3879 style
->color_flags
[GTK_STATE_ACTIVE
] = GTK_RC_FG
;
3882 if ( m_backgroundColour
.Ok() )
3884 const GdkColor
*bg
= m_backgroundColour
.GetColor();
3886 style
->bg
[GTK_STATE_NORMAL
] = *bg
;
3887 style
->base
[GTK_STATE_NORMAL
] = *bg
;
3888 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)
3889 (style
->color_flags
[GTK_STATE_NORMAL
] | GTK_RC_BG
| GTK_RC_BASE
);
3891 style
->bg
[GTK_STATE_PRELIGHT
] = *bg
;
3892 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
3893 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)
3894 (style
->color_flags
[GTK_STATE_PRELIGHT
] | GTK_RC_BG
| GTK_RC_BASE
);
3896 style
->bg
[GTK_STATE_ACTIVE
] = *bg
;
3897 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
3898 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)
3899 (style
->color_flags
[GTK_STATE_ACTIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3901 style
->bg
[GTK_STATE_INSENSITIVE
] = *bg
;
3902 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
3903 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)
3904 (style
->color_flags
[GTK_STATE_INSENSITIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3910 void wxWindowGTK
::ApplyWidgetStyle(bool forceStyle
)
3912 GtkRcStyle
*style
= CreateWidgetStyle(forceStyle
);
3915 DoApplyWidgetStyle(style
);
3916 gtk_rc_style_unref(style
);
3919 // Style change may affect GTK+'s size calculation:
3920 InvalidateBestSize();
3923 void wxWindowGTK
::DoApplyWidgetStyle(GtkRcStyle
*style
)
3926 gtk_widget_modify_style(m_wxwindow
, style
);
3928 gtk_widget_modify_style(m_widget
, style
);
3931 bool wxWindowGTK
::SetBackgroundStyle(wxBackgroundStyle style
)
3933 wxWindowBase
::SetBackgroundStyle(style
);
3935 if (style
== wxBG_STYLE_CUSTOM
)
3937 GdkWindow
*window
= (GdkWindow
*) NULL
;
3939 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3941 window
= GetConnectWidget()->window
;
3945 // Make sure GDK/X11 doesn't refresh the window
3947 gdk_window_set_back_pixmap( window
, None
, False
);
3949 Display
* display
= GDK_WINDOW_DISPLAY(window
);
3952 m_needsStyleChange
= false;
3955 // Do in OnIdle, because the window is not yet available
3956 m_needsStyleChange
= true;
3958 // Don't apply widget style, or we get a grey background
3962 // apply style change (forceStyle=true so that new style is applied
3963 // even if the bg colour changed from valid to wxNullColour):
3964 ApplyWidgetStyle(true);
3969 #if wxUSE_DRAG_AND_DROP
3971 void wxWindowGTK
::SetDropTarget( wxDropTarget
*dropTarget
)
3973 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3975 GtkWidget
*dnd_widget
= GetConnectWidget();
3977 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
3979 if (m_dropTarget
) delete m_dropTarget
;
3980 m_dropTarget
= dropTarget
;
3982 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
3985 #endif // wxUSE_DRAG_AND_DROP
3987 GtkWidget
* wxWindowGTK
::GetConnectWidget()
3989 GtkWidget
*connect_widget
= m_widget
;
3990 if (m_wxwindow
) connect_widget
= m_wxwindow
;
3992 return connect_widget
;
3995 bool wxWindowGTK
::GTKIsOwnWindow(GdkWindow
*window
) const
3997 wxArrayGdkWindows windowsThis
;
3998 GdkWindow
* const winThis
= GTKGetWindow(windowsThis
);
4000 return winThis ? window
== winThis
4001 : windowsThis
.Index(window
) != wxNOT_FOUND
;
4004 GdkWindow
*wxWindowGTK
::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
4006 return m_wxwindow ?
GTK_PIZZA(m_wxwindow
)->bin_window
: m_widget
->window
;
4009 bool wxWindowGTK
::SetFont( const wxFont
&font
)
4011 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
4013 if (!wxWindowBase
::SetFont(font
))
4016 // apply style change (forceStyle=true so that new style is applied
4017 // even if the font changed from valid to wxNullFont):
4018 ApplyWidgetStyle(true);
4023 void wxWindowGTK
::DoCaptureMouse()
4025 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4027 GdkWindow
*window
= (GdkWindow
*) NULL
;
4029 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4031 window
= GetConnectWidget()->window
;
4033 wxCHECK_RET( window
, _T("CaptureMouse() failed") );
4035 const wxCursor
* cursor
= &m_cursor
;
4037 cursor
= wxSTANDARD_CURSOR
;
4039 gdk_pointer_grab( window
, FALSE
,
4041 (GDK_BUTTON_PRESS_MASK
|
4042 GDK_BUTTON_RELEASE_MASK
|
4043 GDK_POINTER_MOTION_HINT_MASK
|
4044 GDK_POINTER_MOTION_MASK
),
4046 cursor
->GetCursor(),
4047 (guint32
)GDK_CURRENT_TIME
);
4048 g_captureWindow
= this;
4049 g_captureWindowHasMouse
= true;
4052 void wxWindowGTK
::DoReleaseMouse()
4054 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4056 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
4058 g_captureWindow
= (wxWindowGTK
*) NULL
;
4060 GdkWindow
*window
= (GdkWindow
*) NULL
;
4062 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4064 window
= GetConnectWidget()->window
;
4069 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
4073 wxWindow
*wxWindowBase
::GetCapture()
4075 return (wxWindow
*)g_captureWindow
;
4078 bool wxWindowGTK
::IsRetained() const
4083 void wxWindowGTK
::BlockScrollEvent()
4085 wxASSERT(!m_blockScrollEvent
);
4086 m_blockScrollEvent
= true;
4089 void wxWindowGTK
::UnblockScrollEvent()
4091 wxASSERT(m_blockScrollEvent
);
4092 m_blockScrollEvent
= false;
4095 void wxWindowGTK
::SetScrollbar(int orient
,
4099 bool WXUNUSED(update
))
4101 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4102 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4106 m_hasScrolling
= true;
4110 // GtkRange requires upper > lower
4115 if (pos
> range
- thumbVisible
)
4116 pos
= range
- thumbVisible
;
4119 GtkAdjustment
* adj
= m_scrollBar
[ScrollDirFromOrient(orient
)]->adjustment
;
4120 adj
->step_increment
= 1;
4121 adj
->page_increment
=
4122 adj
->page_size
= thumbVisible
;
4124 SetScrollPos(orient
, pos
);
4125 gtk_adjustment_changed(adj
);
4128 void wxWindowGTK
::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
4130 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4131 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4133 // This check is more than an optimization. Without it, the slider
4134 // will not move smoothly while tracking when using wxScrollHelper.
4135 if (GetScrollPos(orient
) != pos
)
4137 const int dir
= ScrollDirFromOrient(orient
);
4138 GtkAdjustment
* adj
= m_scrollBar
[dir
]->adjustment
;
4139 const int max
= int(adj
->upper
- adj
->page_size
);
4144 m_scrollPos
[dir
] = adj
->value
= pos
;
4146 // If a "value_changed" signal emission is not already in progress
4147 if (!m_blockValueChanged
[dir
])
4149 gtk_adjustment_value_changed(adj
);
4154 int wxWindowGTK
::GetScrollThumb(int orient
) const
4156 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4157 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4159 return int(m_scrollBar
[ScrollDirFromOrient(orient
)]->adjustment
->page_size
);
4162 int wxWindowGTK
::GetScrollPos( int orient
) const
4164 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4165 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4167 return int(m_scrollBar
[ScrollDirFromOrient(orient
)]->adjustment
->value
+ 0.5);
4170 int wxWindowGTK
::GetScrollRange( int orient
) const
4172 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4173 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4175 return int(m_scrollBar
[ScrollDirFromOrient(orient
)]->adjustment
->upper
);
4178 // Determine if increment is the same as +/-x, allowing for some small
4179 // difference due to possible inexactness in floating point arithmetic
4180 static inline bool IsScrollIncrement(double increment
, double x
)
4182 wxASSERT(increment
> 0);
4183 const double tolerance
= 1.0 / 1024;
4184 return fabs(increment
- fabs(x
)) < tolerance
;
4187 wxEventType wxWindowGTK
::GetScrollEventType(GtkRange
* range
)
4192 wxapp_install_idle_handler();
4194 wxASSERT(range
== m_scrollBar
[0] || range
== m_scrollBar
[1]);
4196 const int barIndex
= range
== m_scrollBar
[1];
4197 GtkAdjustment
* adj
= range
->adjustment
;
4199 const int value
= int(adj
->value
+ 0.5);
4201 // save previous position
4202 const double oldPos
= m_scrollPos
[barIndex
];
4203 // update current position
4204 m_scrollPos
[barIndex
] = adj
->value
;
4205 // If event should be ignored, or integral position has not changed
4206 if (!m_hasVMT
|| g_blockEventsOnDrag
|| value
== int(oldPos
+ 0.5))
4211 wxEventType eventType
= wxEVT_SCROLL_THUMBTRACK
;
4214 // Difference from last change event
4215 const double diff
= adj
->value
- oldPos
;
4216 const bool isDown
= diff
> 0;
4218 if (IsScrollIncrement(adj
->step_increment
, diff
))
4220 eventType
= isDown ? wxEVT_SCROLL_LINEDOWN
: wxEVT_SCROLL_LINEUP
;
4222 else if (IsScrollIncrement(adj
->page_increment
, diff
))
4224 eventType
= isDown ? wxEVT_SCROLL_PAGEDOWN
: wxEVT_SCROLL_PAGEUP
;
4226 else if (m_mouseButtonDown
)
4228 // Assume track event
4229 m_isScrolling
= true;
4235 void wxWindowGTK
::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4237 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4239 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4241 // No scrolling requested.
4242 if ((dx
== 0) && (dy
== 0)) return;
4244 m_clipPaintRegion
= true;
4246 if (GetLayoutDirection() == wxLayout_RightToLeft
)
4247 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow
), dx
, -dy
);
4249 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow
), -dx
, -dy
);
4251 m_clipPaintRegion
= false;
4254 bool restoreCaret
= (GetCaret() != NULL
&& GetCaret()->IsVisible());
4257 wxRect
caretRect(GetCaret()->GetPosition(), GetCaret()->GetSize());
4259 caretRect
.width
+= dx
;
4262 caretRect
.x
+= dx
; caretRect
.width
-= dx
;
4265 caretRect
.height
+= dy
;
4268 caretRect
.y
+= dy
; caretRect
.height
-= dy
;
4271 RefreshRect(caretRect
);
4276 void wxWindowGTK
::GtkScrolledWindowSetBorder(GtkWidget
* w
, int wxstyle
)
4278 //RN: Note that static controls usually have no border on gtk, so maybe
4279 //it makes sense to treat that as simply no border at the wx level
4281 if (!(wxstyle
& wxNO_BORDER
) && !(wxstyle
& wxBORDER_STATIC
))
4283 GtkShadowType gtkstyle
;
4285 if(wxstyle
& wxBORDER_RAISED
)
4286 gtkstyle
= GTK_SHADOW_OUT
;
4287 else if (wxstyle
& wxBORDER_SUNKEN
)
4288 gtkstyle
= GTK_SHADOW_IN
;
4289 else if (wxstyle
& wxBORDER_DOUBLE
)
4290 gtkstyle
= GTK_SHADOW_ETCHED_IN
;
4292 gtkstyle
= GTK_SHADOW_IN
;
4294 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(w
),
4299 void wxWindowGTK
::SetWindowStyleFlag( long style
)
4301 // Updates the internal variable. NB: Now m_windowStyle bits carry the _new_ style values already
4302 wxWindowBase
::SetWindowStyleFlag(style
);
4305 // Find the wxWindow at the current mouse position, also returning the mouse
4307 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4309 pt
= wxGetMousePosition();
4310 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4314 // Get the current mouse position.
4315 wxPoint
wxGetMousePosition()
4317 /* This crashes when used within wxHelpContext,
4318 so we have to use the X-specific implementation below.
4320 GdkModifierType *mask;
4321 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4323 return wxPoint(x, y);
4327 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4329 Display
*display
= windowAtPtr ?
GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4330 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4331 Window rootReturn
, childReturn
;
4332 int rootX
, rootY
, winX
, winY
;
4333 unsigned int maskReturn
;
4335 XQueryPointer (display
,
4339 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4340 return wxPoint(rootX
, rootY
);
4344 // Needed for implementing e.g. combobox on wxGTK within a modal dialog.
4345 void wxAddGrab(wxWindow
* window
)
4347 gtk_grab_add( (GtkWidget
*) window
->GetHandle() );
4350 void wxRemoveGrab(wxWindow
* window
)
4352 gtk_grab_remove( (GtkWidget
*) window
->GetHandle() );