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"
22 #include "wx/toplevel.h"
23 #include "wx/dcclient.h"
25 #include "wx/settings.h"
26 #include "wx/msgdlg.h"
31 #include "wx/tooltip.h"
33 #include "wx/fontutil.h"
34 #include "wx/sysopt.h"
37 #include "wx/thread.h"
42 #include "wx/gtk/private.h"
43 #include "wx/gtk/win_gtk.h"
44 #include <gdk/gdkkeysyms.h>
47 //-----------------------------------------------------------------------------
48 // documentation on internals
49 //-----------------------------------------------------------------------------
52 I have been asked several times about writing some documentation about
53 the GTK port of wxWidgets, especially its internal structures. Obviously,
54 you cannot understand wxGTK without knowing a little about the GTK, but
55 some more information about what the wxWindow, which is the base class
56 for all other window classes, does seems required as well.
60 What does wxWindow do? It contains the common interface for the following
61 jobs of its descendants:
63 1) Define the rudimentary behaviour common to all window classes, such as
64 resizing, intercepting user input (so as to make it possible to use these
65 events for special purposes in a derived class), window names etc.
67 2) Provide the possibility to contain and manage children, if the derived
68 class is allowed to contain children, which holds true for those window
69 classes which do not display a native GTK widget. To name them, these
70 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
71 work classes are a special case and are handled a bit differently from
72 the rest. The same holds true for the wxNotebook class.
74 3) Provide the possibility to draw into a client area of a window. This,
75 too, only holds true for classes that do not display a native GTK widget
78 4) Provide the entire mechanism for scrolling widgets. This actual inter-
79 face for this is usually in wxScrolledWindow, but the GTK implementation
82 5) A multitude of helper or extra methods for special purposes, such as
83 Drag'n'Drop, managing validators etc.
85 6) Display a border (sunken, raised, simple or none).
87 Normally one might expect, that one wxWidgets window would always correspond
88 to one GTK widget. Under GTK, there is no such all-round widget that has all
89 the functionality. Moreover, the GTK defines a client area as a different
90 widget from the actual widget you are handling. Last but not least some
91 special classes (e.g. wxFrame) handle different categories of widgets and
92 still have the possibility to draw something in the client area.
93 It was therefore required to write a special purpose GTK widget, that would
94 represent a client area in the sense of wxWidgets capable to do the jobs
95 2), 3) and 4). I have written this class and it resides in win_gtk.c of
98 All windows must have a widget, with which they interact with other under-
99 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
100 the wxWindow class has a member variable called m_widget which holds a
101 pointer to this widget. When the window class represents a GTK native widget,
102 this is (in most cases) the only GTK widget the class manages. E.g. the
103 wxStaticText class handles only a GtkLabel widget a pointer to which you
104 can find in m_widget (defined in wxWindow)
106 When the class has a client area for drawing into and for containing children
107 it has to handle the client area widget (of the type wxPizza, defined in
108 win_gtk.cpp), but there could be any number of widgets, handled by a class.
109 The common rule for all windows is only, that the widget that interacts with
110 the rest of GTK must be referenced in m_widget and all other widgets must be
111 children of this widget on the GTK level. The top-most widget, which also
112 represents the client area, must be in the m_wxwindow field and must be of
115 As I said, the window classes that display a GTK native widget only have
116 one widget, so in the case of e.g. the wxButton class m_widget holds a
117 pointer to a GtkButton widget. But windows with client areas (for drawing
118 and children) have a m_widget field that is a pointer to a GtkScrolled-
119 Window and a m_wxwindow field that is pointer to a wxPizza and this
120 one is (in the GTK sense) a child of the GtkScrolledWindow.
122 If the m_wxwindow field is set, then all input to this widget is inter-
123 cepted and sent to the wxWidgets class. If not, all input to the widget
124 that gets pointed to by m_widget gets intercepted and sent to the class.
128 The design of scrolling in wxWidgets is markedly different from that offered
129 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
130 clicking on a scrollbar belonging to scrolled window will inevitably move
131 the window. In wxWidgets, the scrollbar will only emit an event, send this
132 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
133 which actually moves the window and its sub-windows. Note that wxPizza
134 memorizes how much it has been scrolled but that wxWidgets forgets this
135 so that the two coordinates systems have to be kept in synch. This is done
136 in various places using the pizza->m_scroll_x and pizza->m_scroll_y values.
140 Singularly the most broken code in GTK is the code that is supposed to
141 inform subwindows (child windows) about new positions. Very often, duplicate
142 events are sent without changes in size or position, equally often no
143 events are sent at all (All this is due to a bug in the GtkContainer code
144 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
145 GTK's own system and it simply waits for size events for toplevel windows
146 and then iterates down the respective size events to all window. This has
147 the disadvantage that windows might get size events before the GTK widget
148 actually has the reported size. This doesn't normally pose any problem, but
149 the OpenGL drawing routines rely on correct behaviour. Therefore, I have
150 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
151 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
152 window that is used for OpenGL output really has that size (as reported by
157 If someone at some point of time feels the immense desire to have a look at,
158 change or attempt to optimise the Refresh() logic, this person will need an
159 intimate understanding of what "draw" and "expose" events are and what
160 they are used for, in particular when used in connection with GTK's
161 own windowless widgets. Beware.
165 Cursors, too, have been a constant source of pleasure. The main difficulty
166 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
167 for the parent. To prevent this from doing too much harm, I use idle time
168 to set the cursor over and over again, starting from the toplevel windows
169 and ending with the youngest generation (speaking of parent and child windows).
170 Also don't forget that cursors (like much else) are connected to GdkWindows,
171 not GtkWidgets and that the "window" field of a GtkWidget might very well
172 point to the GdkWindow of the parent widget (-> "window-less widget") and
173 that the two obviously have very different meanings.
177 //-----------------------------------------------------------------------------
179 //-----------------------------------------------------------------------------
181 // Don't allow event propagation during drag
182 bool g_blockEventsOnDrag
;
183 // Don't allow mouse event propagation during scroll
184 bool g_blockEventsOnScroll
;
185 extern wxCursor g_globalCursor
;
187 // mouse capture state: the window which has it and if the mouse is currently
189 static wxWindowGTK
*g_captureWindow
= (wxWindowGTK
*) NULL
;
190 static bool g_captureWindowHasMouse
= false;
192 wxWindowGTK
*g_focusWindow
= (wxWindowGTK
*) NULL
;
194 // the last window which had the focus - this is normally never NULL (except
195 // if we never had focus at all) as even when g_focusWindow is NULL it still
196 // keeps its previous value
197 wxWindowGTK
*g_focusWindowLast
= (wxWindowGTK
*) NULL
;
199 // If a window get the focus set but has not been realized
200 // yet, defer setting the focus to idle time.
201 wxWindowGTK
*g_delayedFocus
= (wxWindowGTK
*) NULL
;
203 // global variables because GTK+ DnD want to have the
204 // mouse event that caused it
205 GdkEvent
*g_lastMouseEvent
= (GdkEvent
*) NULL
;
206 int g_lastButtonNumber
= 0;
208 extern bool g_mainThreadLocked
;
210 //-----------------------------------------------------------------------------
212 //-----------------------------------------------------------------------------
217 # define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
219 # define DEBUG_MAIN_THREAD
222 #define DEBUG_MAIN_THREAD
225 // the trace mask used for the focus debugging messages
226 #define TRACE_FOCUS _T("focus")
228 //-----------------------------------------------------------------------------
229 // missing gdk functions
230 //-----------------------------------------------------------------------------
233 gdk_window_warp_pointer (GdkWindow
*window
,
238 window
= gdk_get_default_root_window();
240 if (!GDK_WINDOW_DESTROYED(window
))
242 XWarpPointer (GDK_WINDOW_XDISPLAY(window
),
243 None
, /* not source window -> move from anywhere */
244 GDK_WINDOW_XID(window
), /* dest window */
245 0, 0, 0, 0, /* not source window -> move from anywhere */
250 //-----------------------------------------------------------------------------
251 // local code (see below)
252 //-----------------------------------------------------------------------------
254 // returns the child of win which currently has focus or NULL if not found
256 // Note: can't be static, needed by textctrl.cpp.
257 wxWindow
*wxFindFocusedChild(wxWindowGTK
*win
)
259 wxWindow
*winFocus
= wxWindowGTK::FindFocus();
261 return (wxWindow
*)NULL
;
263 if ( winFocus
== win
)
264 return (wxWindow
*)win
;
266 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
268 node
= node
->GetNext() )
270 wxWindow
*child
= wxFindFocusedChild(node
->GetData());
275 return (wxWindow
*)NULL
;
278 static void GetScrollbarWidth(GtkWidget
* widget
, int& w
, int& h
)
280 GtkScrolledWindow
* scroll_window
= GTK_SCROLLED_WINDOW(widget
);
281 GtkScrolledWindowClass
* scroll_class
= GTK_SCROLLED_WINDOW_CLASS(GTK_OBJECT_GET_CLASS(scroll_window
));
282 GtkRequisition scroll_req
;
285 if (scroll_window
->vscrollbar_visible
)
287 scroll_req
.width
= 2;
288 scroll_req
.height
= 2;
289 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
290 (scroll_window
->vscrollbar
, &scroll_req
);
291 w
= scroll_req
.width
+
292 scroll_class
->scrollbar_spacing
;
296 if (scroll_window
->hscrollbar_visible
)
298 scroll_req
.width
= 2;
299 scroll_req
.height
= 2;
300 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
301 (scroll_window
->hscrollbar
, &scroll_req
);
302 h
= scroll_req
.height
+
303 scroll_class
->scrollbar_spacing
;
307 //-----------------------------------------------------------------------------
308 // "size_request" of m_widget
309 //-----------------------------------------------------------------------------
311 // make it extern because wxStaticText needs to disconnect this one
313 void wxgtk_window_size_request_callback(GtkWidget
* WXUNUSED(widget
),
314 GtkRequisition
*requisition
,
318 win
->GetSize( &w
, &h
);
324 requisition
->height
= h
;
325 requisition
->width
= w
;
329 //-----------------------------------------------------------------------------
330 // "expose_event" of m_wxwindow
331 //-----------------------------------------------------------------------------
334 extern GtkWidget
*GetEntryWidget();
338 gtk_window_expose_callback( GtkWidget
*widget
,
339 GdkEventExpose
*gdk_event
,
344 wxPizza
*pizza
= WX_PIZZA(widget
);
345 GdkWindow
*backing_window
= pizza
->m_backing_window
;
347 int w
= widget
->allocation
.width
;
348 int h
= widget
->allocation
.height
;
350 // if this event is for the border-only GdkWindow
351 if (backing_window
&& gdk_event
->window
== pizza
->m_backing_window
)
353 if (win
->HasFlag(wxBORDER_SIMPLE
))
355 GdkGC
* gc
= gdk_gc_new(gdk_event
->window
);
356 gdk_gc_set_foreground(gc
, &widget
->style
->black
);
357 gdk_draw_rectangle(gdk_event
->window
, gc
, false, 0, 0, w
- 1, h
- 1);
362 GtkShadowType shadow
= GTK_SHADOW_IN
;
363 if (win
->HasFlag(wxBORDER_RAISED
))
364 shadow
= GTK_SHADOW_OUT
;
366 GetEntryWidget()->style
, gdk_event
->window
, GTK_STATE_NORMAL
,
367 shadow
, NULL
, GetEntryWidget(), "entry", 0, 0, w
, h
);
376 wxPrintf( wxT("OnExpose from ") );
377 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
378 wxPrintf( win
->GetClassInfo()->GetClassName() );
379 wxPrintf( wxT(" %d %d %d %d\n"), (int)gdk_event
->area
.x
,
380 (int)gdk_event
->area
.y
,
381 (int)gdk_event
->area
.width
,
382 (int)gdk_event
->area
.height
);
387 win
->m_wxwindow
->style
,
391 (GdkRectangle
*) NULL
,
393 (char *)"button", // const_cast
398 win
->GetUpdateRegion() = wxRegion( gdk_event
->region
);
400 win
->GtkSendPaintEvents();
402 // Let parent window draw window-less widgets
407 //-----------------------------------------------------------------------------
408 // "expose_event" from m_widget, for drawing border
409 //-----------------------------------------------------------------------------
411 #ifndef __WXUNIVERSAL__
414 expose_event_border(GtkWidget
* widget
, GdkEventExpose
* gdk_event
, wxWindow
* win
)
416 // if this event is not for the GdkWindow the border is drawn on
417 if (win
->m_wxwindow
== win
->m_widget
&& gdk_event
->window
== widget
->window
)
422 // GtkScrolledWindow is GTK_NO_WINDOW
423 if (GTK_WIDGET_NO_WINDOW(widget
))
425 x
= widget
->allocation
.x
;
426 y
= widget
->allocation
.y
;
428 int w
= win
->m_wxwindow
->allocation
.width
;
429 int h
= win
->m_wxwindow
->allocation
.height
;
430 if (win
->HasFlag(wxBORDER_SIMPLE
))
433 gc
= gdk_gc_new(gdk_event
->window
);
434 gdk_gc_set_foreground(gc
, &widget
->style
->black
);
435 gdk_draw_rectangle(gdk_event
->window
, gc
, false, x
, y
, w
- 1, h
- 1);
440 GtkShadowType shadow
= GTK_SHADOW_IN
;
441 if (win
->HasFlag(wxBORDER_RAISED
))
442 shadow
= GTK_SHADOW_OUT
;
444 GetEntryWidget()->style
, gdk_event
->window
, GTK_STATE_NORMAL
,
445 shadow
, NULL
, GetEntryWidget(), "viewport", x
, y
, w
, h
);
448 // no further painting is needed for border-only GdkWindow
449 return win
->m_wxwindow
== win
->m_widget
;
452 #endif // !__WXUNIVERSAL__
454 //-----------------------------------------------------------------------------
455 // "key_press_event" from any window
456 //-----------------------------------------------------------------------------
458 // These are used when transforming Ctrl-alpha to ascii values 1-26
459 inline bool wxIsLowerChar(int code
)
461 return (code
>= 'a' && code
<= 'z' );
464 inline bool wxIsUpperChar(int code
)
466 return (code
>= 'A' && code
<= 'Z' );
470 // set WXTRACE to this to see the key event codes on the console
471 #define TRACE_KEYS _T("keyevent")
473 // translates an X key symbol to WXK_XXX value
475 // if isChar is true it means that the value returned will be used for EVT_CHAR
476 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
477 // for example, while if it is false it means that the value is going to be
478 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
480 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
486 // Shift, Control and Alt don't generate the CHAR events at all
489 key_code
= isChar
? 0 : WXK_SHIFT
;
493 key_code
= isChar
? 0 : WXK_CONTROL
;
501 key_code
= isChar
? 0 : WXK_ALT
;
504 // neither do the toggle modifies
505 case GDK_Scroll_Lock
:
506 key_code
= isChar
? 0 : WXK_SCROLL
;
510 key_code
= isChar
? 0 : WXK_CAPITAL
;
514 key_code
= isChar
? 0 : WXK_NUMLOCK
;
518 // various other special keys
531 case GDK_ISO_Left_Tab
:
538 key_code
= WXK_RETURN
;
542 key_code
= WXK_CLEAR
;
546 key_code
= WXK_PAUSE
;
550 key_code
= WXK_SELECT
;
554 key_code
= WXK_PRINT
;
558 key_code
= WXK_EXECUTE
;
562 key_code
= WXK_ESCAPE
;
565 // cursor and other extended keyboard keys
567 key_code
= WXK_DELETE
;
583 key_code
= WXK_RIGHT
;
590 case GDK_Prior
: // == GDK_Page_Up
591 key_code
= WXK_PAGEUP
;
594 case GDK_Next
: // == GDK_Page_Down
595 key_code
= WXK_PAGEDOWN
;
607 key_code
= WXK_INSERT
;
622 key_code
= (isChar
? '0' : WXK_NUMPAD0
) + keysym
- GDK_KP_0
;
626 key_code
= isChar
? ' ' : WXK_NUMPAD_SPACE
;
630 key_code
= isChar
? WXK_TAB
: WXK_NUMPAD_TAB
;
634 key_code
= isChar
? WXK_RETURN
: WXK_NUMPAD_ENTER
;
638 key_code
= isChar
? WXK_F1
: WXK_NUMPAD_F1
;
642 key_code
= isChar
? WXK_F2
: WXK_NUMPAD_F2
;
646 key_code
= isChar
? WXK_F3
: WXK_NUMPAD_F3
;
650 key_code
= isChar
? WXK_F4
: WXK_NUMPAD_F4
;
654 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_HOME
;
658 key_code
= isChar
? WXK_LEFT
: WXK_NUMPAD_LEFT
;
662 key_code
= isChar
? WXK_UP
: WXK_NUMPAD_UP
;
666 key_code
= isChar
? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
670 key_code
= isChar
? WXK_DOWN
: WXK_NUMPAD_DOWN
;
673 case GDK_KP_Prior
: // == GDK_KP_Page_Up
674 key_code
= isChar
? WXK_PAGEUP
: WXK_NUMPAD_PAGEUP
;
677 case GDK_KP_Next
: // == GDK_KP_Page_Down
678 key_code
= isChar
? WXK_PAGEDOWN
: WXK_NUMPAD_PAGEDOWN
;
682 key_code
= isChar
? WXK_END
: WXK_NUMPAD_END
;
686 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_BEGIN
;
690 key_code
= isChar
? WXK_INSERT
: WXK_NUMPAD_INSERT
;
694 key_code
= isChar
? WXK_DELETE
: WXK_NUMPAD_DELETE
;
698 key_code
= isChar
? '=' : WXK_NUMPAD_EQUAL
;
701 case GDK_KP_Multiply
:
702 key_code
= isChar
? '*' : WXK_NUMPAD_MULTIPLY
;
706 key_code
= isChar
? '+' : WXK_NUMPAD_ADD
;
709 case GDK_KP_Separator
:
710 // FIXME: what is this?
711 key_code
= isChar
? '.' : WXK_NUMPAD_SEPARATOR
;
714 case GDK_KP_Subtract
:
715 key_code
= isChar
? '-' : WXK_NUMPAD_SUBTRACT
;
719 key_code
= isChar
? '.' : WXK_NUMPAD_DECIMAL
;
723 key_code
= isChar
? '/' : WXK_NUMPAD_DIVIDE
;
740 key_code
= WXK_F1
+ keysym
- GDK_F1
;
750 static inline bool wxIsAsciiKeysym(KeySym ks
)
755 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
757 GdkEventKey
*gdk_event
)
761 GdkModifierType state
;
762 if (gdk_event
->window
)
763 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
765 event
.SetTimestamp( gdk_event
->time
);
766 event
.SetId(win
->GetId());
767 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
768 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
769 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
770 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
) != 0;
771 event
.m_scanCode
= gdk_event
->keyval
;
772 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
773 event
.m_rawFlags
= 0;
775 event
.m_uniChar
= gdk_keyval_to_unicode(gdk_event
->keyval
);
777 wxGetMousePosition( &x
, &y
);
778 win
->ScreenToClient( &x
, &y
);
781 event
.SetEventObject( win
);
786 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
788 GdkEventKey
*gdk_event
)
790 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
791 // but only event->keyval which is quite useless to us, so remember
792 // the last character from GDK_KEY_PRESS and reuse it as last resort
794 // NB: should be MT-safe as we're always called from the main thread only
799 } s_lastKeyPress
= { 0, 0 };
801 KeySym keysym
= gdk_event
->keyval
;
803 wxLogTrace(TRACE_KEYS
, _T("Key %s event: keysym = %ld"),
804 event
.GetEventType() == wxEVT_KEY_UP
? _T("release")
808 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
812 // do we have the translation or is it a plain ASCII character?
813 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
815 // we should use keysym if it is ASCII as X does some translations
816 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
817 // which we don't want here (but which we do use for OnChar())
818 if ( !wxIsAsciiKeysym(keysym
) )
820 keysym
= (KeySym
)gdk_event
->string
[0];
823 // we want to always get the same key code when the same key is
824 // pressed regardless of the state of the modifiers, i.e. on a
825 // standard US keyboard pressing '5' or '%' ('5' key with
826 // Shift) should result in the same key code in OnKeyDown():
827 // '5' (although OnChar() will get either '5' or '%').
829 // to do it we first translate keysym to keycode (== scan code)
830 // and then back but always using the lower register
831 Display
*dpy
= (Display
*)wxGetDisplay();
832 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
834 wxLogTrace(TRACE_KEYS
, _T("\t-> keycode %d"), keycode
);
836 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
838 // use the normalized, i.e. lower register, keysym if we've
840 key_code
= keysymNormalized
? keysymNormalized
: keysym
;
842 // as explained above, we want to have lower register key codes
843 // normally but for the letter keys we want to have the upper ones
845 // NB: don't use XConvertCase() here, we want to do it for letters
847 key_code
= toupper(key_code
);
849 else // non ASCII key, what to do?
851 // by default, ignore it
854 // but if we have cached information from the last KEY_PRESS
855 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
858 if ( keysym
== s_lastKeyPress
.keysym
)
860 key_code
= s_lastKeyPress
.keycode
;
865 if ( gdk_event
->type
== GDK_KEY_PRESS
)
867 // remember it to be reused for KEY_UP event later
868 s_lastKeyPress
.keysym
= keysym
;
869 s_lastKeyPress
.keycode
= key_code
;
873 wxLogTrace(TRACE_KEYS
, _T("\t-> wxKeyCode %ld"), key_code
);
875 // sending unknown key events doesn't really make sense
879 // now fill all the other fields
880 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
882 event
.m_keyCode
= key_code
;
884 if ( gdk_event
->type
== GDK_KEY_PRESS
|| gdk_event
->type
== GDK_KEY_RELEASE
)
886 event
.m_uniChar
= key_code
;
896 GtkIMContext
*context
;
897 GdkEventKey
*lastKeyEvent
;
901 context
= gtk_im_multicontext_new();
906 g_object_unref (context
);
912 gtk_window_key_press_callback( GtkWidget
*widget
,
913 GdkEventKey
*gdk_event
,
920 if (g_blockEventsOnDrag
)
923 // GTK+ sends keypress events to the focus widget and then
924 // to all its parent and grandparent widget. We only want
925 // the key events from the focus widget.
926 if (!GTK_WIDGET_HAS_FOCUS(widget
))
929 wxKeyEvent
event( wxEVT_KEY_DOWN
);
931 bool return_after_IM
= false;
933 if( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
935 // Emit KEY_DOWN event
936 ret
= win
->GetEventHandler()->ProcessEvent( event
);
940 // Return after IM processing as we cannot do
941 // anything with it anyhow.
942 return_after_IM
= true;
945 if ((!ret
) && (win
->m_imData
!= NULL
))
947 // We should let GTK+ IM filter key event first. According to GTK+ 2.0 API
948 // docs, if IM filter returns true, no further processing should be done.
949 // we should send the key_down event anyway.
950 bool intercepted_by_IM
= gtk_im_context_filter_keypress(win
->m_imData
->context
, gdk_event
);
951 win
->m_imData
->lastKeyEvent
= NULL
;
952 if (intercepted_by_IM
)
954 wxLogTrace(TRACE_KEYS
, _T("Key event intercepted by IM"));
965 wxWindowGTK
*ancestor
= win
;
968 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
971 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
972 ret
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
975 if (ancestor
->IsTopLevel())
977 ancestor
= ancestor
->GetParent();
980 #endif // wxUSE_ACCEL
982 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
983 // will only be sent if it is not in an accelerator table.
987 KeySym keysym
= gdk_event
->keyval
;
988 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
989 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
992 if ( wxIsAsciiKeysym(keysym
) )
995 key_code
= (unsigned char)keysym
;
997 // gdk_event->string is actually deprecated
998 else if ( gdk_event
->length
== 1 )
1000 key_code
= (unsigned char)gdk_event
->string
[0];
1006 wxLogTrace(TRACE_KEYS
, _T("Char event: %ld"), key_code
);
1008 event
.m_keyCode
= key_code
;
1010 // To conform to the docs we need to translate Ctrl-alpha
1011 // characters to values in the range 1-26.
1012 if ( event
.ControlDown() &&
1013 ( wxIsLowerChar(key_code
) || wxIsUpperChar(key_code
) ))
1015 if ( wxIsLowerChar(key_code
) )
1016 event
.m_keyCode
= key_code
- 'a' + 1;
1017 if ( wxIsUpperChar(key_code
) )
1018 event
.m_keyCode
= key_code
- 'A' + 1;
1020 event
.m_uniChar
= event
.m_keyCode
;
1024 // Implement OnCharHook by checking ancestor top level windows
1025 wxWindow
*parent
= win
;
1026 while (parent
&& !parent
->IsTopLevel())
1027 parent
= parent
->GetParent();
1030 event
.SetEventType( wxEVT_CHAR_HOOK
);
1031 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1036 event
.SetEventType(wxEVT_CHAR
);
1037 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1048 gtk_wxwindow_commit_cb (GtkIMContext
* WXUNUSED(context
),
1052 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1054 // take modifiers, cursor position, timestamp etc. from the last
1055 // key_press_event that was fed into Input Method:
1056 if (window
->m_imData
->lastKeyEvent
)
1058 wxFillOtherKeyEventFields(event
,
1059 window
, window
->m_imData
->lastKeyEvent
);
1063 event
.SetEventObject( window
);
1066 const wxString
data(wxGTK_CONV_BACK_SYS(str
));
1072 // Implement OnCharHook by checking ancestor top level windows
1073 wxWindow
*parent
= window
;
1074 while (parent
&& !parent
->IsTopLevel())
1075 parent
= parent
->GetParent();
1077 for( wxString::const_iterator pstr
= data
.begin(); pstr
!= data
.end(); ++pstr
)
1080 event
.m_uniChar
= *pstr
;
1081 // Backward compatible for ISO-8859-1
1082 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1083 wxLogTrace(TRACE_KEYS
, _T("IM sent character '%c'"), event
.m_uniChar
);
1085 event
.m_keyCode
= (char)*pstr
;
1086 #endif // wxUSE_UNICODE
1088 // To conform to the docs we need to translate Ctrl-alpha
1089 // characters to values in the range 1-26.
1090 if ( event
.ControlDown() &&
1091 ( wxIsLowerChar(*pstr
) || wxIsUpperChar(*pstr
) ))
1093 if ( wxIsLowerChar(*pstr
) )
1094 event
.m_keyCode
= *pstr
- 'a' + 1;
1095 if ( wxIsUpperChar(*pstr
) )
1096 event
.m_keyCode
= *pstr
- 'A' + 1;
1098 event
.m_keyCode
= *pstr
- 'a' + 1;
1100 event
.m_uniChar
= event
.m_keyCode
;
1106 event
.SetEventType( wxEVT_CHAR_HOOK
);
1107 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1112 event
.SetEventType(wxEVT_CHAR
);
1113 ret
= window
->GetEventHandler()->ProcessEvent( event
);
1120 //-----------------------------------------------------------------------------
1121 // "key_release_event" from any window
1122 //-----------------------------------------------------------------------------
1126 gtk_window_key_release_callback( GtkWidget
* WXUNUSED(widget
),
1127 GdkEventKey
*gdk_event
,
1135 if (g_blockEventsOnDrag
)
1138 wxKeyEvent
event( wxEVT_KEY_UP
);
1139 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1141 // unknown key pressed, ignore (the event would be useless anyhow)
1145 return win
->GTKProcessEvent(event
);
1149 // ============================================================================
1151 // ============================================================================
1153 // ----------------------------------------------------------------------------
1154 // mouse event processing helpers
1155 // ----------------------------------------------------------------------------
1157 // init wxMouseEvent with the info from GdkEventXXX struct
1158 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1159 wxMouseEvent
& event
,
1162 event
.SetTimestamp( gdk_event
->time
);
1163 event
.m_shiftDown
= gdk_event
->state
& GDK_SHIFT_MASK
;
1164 event
.m_controlDown
= gdk_event
->state
& GDK_CONTROL_MASK
;
1165 event
.m_altDown
= gdk_event
->state
& GDK_MOD1_MASK
;
1166 event
.m_metaDown
= gdk_event
->state
& GDK_MOD2_MASK
;
1167 event
.m_leftDown
= gdk_event
->state
& GDK_BUTTON1_MASK
;
1168 event
.m_middleDown
= gdk_event
->state
& GDK_BUTTON2_MASK
;
1169 event
.m_rightDown
= gdk_event
->state
& GDK_BUTTON3_MASK
;
1170 event
.m_aux1Down
= gdk_event
->state
& GDK_BUTTON4_MASK
;
1171 event
.m_aux2Down
= gdk_event
->state
& GDK_BUTTON5_MASK
;
1173 wxPoint pt
= win
->GetClientAreaOrigin();
1174 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1175 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1177 if ((win
->m_wxwindow
) && (win
->GetLayoutDirection() == wxLayout_RightToLeft
))
1179 // origin in the upper right corner
1180 int window_width
= win
->m_wxwindow
->allocation
.width
;
1181 event
.m_x
= window_width
- event
.m_x
;
1184 event
.SetEventObject( win
);
1185 event
.SetId( win
->GetId() );
1186 event
.SetTimestamp( gdk_event
->time
);
1189 static void AdjustEventButtonState(wxMouseEvent
& event
)
1191 // GDK reports the old state of the button for a button press event, but
1192 // for compatibility with MSW and common sense we want m_leftDown be TRUE
1193 // for a LEFT_DOWN event, not FALSE, so we will invert
1194 // left/right/middleDown for the corresponding click events
1196 if ((event
.GetEventType() == wxEVT_LEFT_DOWN
) ||
1197 (event
.GetEventType() == wxEVT_LEFT_DCLICK
) ||
1198 (event
.GetEventType() == wxEVT_LEFT_UP
))
1200 event
.m_leftDown
= !event
.m_leftDown
;
1204 if ((event
.GetEventType() == wxEVT_MIDDLE_DOWN
) ||
1205 (event
.GetEventType() == wxEVT_MIDDLE_DCLICK
) ||
1206 (event
.GetEventType() == wxEVT_MIDDLE_UP
))
1208 event
.m_middleDown
= !event
.m_middleDown
;
1212 if ((event
.GetEventType() == wxEVT_RIGHT_DOWN
) ||
1213 (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) ||
1214 (event
.GetEventType() == wxEVT_RIGHT_UP
))
1216 event
.m_rightDown
= !event
.m_rightDown
;
1221 // find the window to send the mouse event too
1223 wxWindowGTK
*FindWindowForMouseEvent(wxWindowGTK
*win
, wxCoord
& x
, wxCoord
& y
)
1228 if (win
->m_wxwindow
)
1230 wxPizza
* pizza
= WX_PIZZA(win
->m_wxwindow
);
1231 xx
+= pizza
->m_scroll_x
;
1232 yy
+= pizza
->m_scroll_y
;
1235 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
1238 wxWindowGTK
*child
= node
->GetData();
1240 node
= node
->GetNext();
1241 if (!child
->IsShown())
1244 if (child
->IsTransparentForMouse())
1246 // wxStaticBox is transparent in the box itself
1247 int xx1
= child
->m_x
;
1248 int yy1
= child
->m_y
;
1249 int xx2
= child
->m_x
+ child
->m_width
;
1250 int yy2
= child
->m_y
+ child
->m_height
;
1253 if (((xx
>= xx1
) && (xx
<= xx1
+10) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1255 ((xx
>= xx2
-10) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1257 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy1
+10)) ||
1259 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy2
-1) && (yy
<= yy2
)))
1270 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1271 (child
->m_x
<= xx
) &&
1272 (child
->m_y
<= yy
) &&
1273 (child
->m_x
+child
->m_width
>= xx
) &&
1274 (child
->m_y
+child
->m_height
>= yy
))
1287 // ----------------------------------------------------------------------------
1288 // common event handlers helpers
1289 // ----------------------------------------------------------------------------
1291 bool wxWindowGTK::GTKProcessEvent(wxEvent
& event
) const
1293 // nothing special at this level
1294 return GetEventHandler()->ProcessEvent(event
);
1297 int wxWindowGTK::GTKCallbackCommonPrologue(GdkEventAny
*event
) const
1303 if (g_blockEventsOnDrag
)
1305 if (g_blockEventsOnScroll
)
1308 if (!GTKIsOwnWindow(event
->window
))
1314 // overloads for all GDK event types we use here: we need to have this as
1315 // GdkEventXXX can't be implicitly cast to GdkEventAny even if it, in fact,
1316 // derives from it in the sense that the structs have the same layout
1317 #define wxDEFINE_COMMON_PROLOGUE_OVERLOAD(T) \
1318 static int wxGtkCallbackCommonPrologue(T *event, wxWindowGTK *win) \
1320 return win->GTKCallbackCommonPrologue((GdkEventAny *)event); \
1323 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventButton
)
1324 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventMotion
)
1325 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventCrossing
)
1327 #undef wxDEFINE_COMMON_PROLOGUE_OVERLOAD
1329 #define wxCOMMON_CALLBACK_PROLOGUE(event, win) \
1330 const int rc = wxGtkCallbackCommonPrologue(event, win); \
1334 // send the wxChildFocusEvent and wxFocusEvent, common code of
1335 // gtk_window_focus_in_callback() and SetFocus()
1336 static bool DoSendFocusEvents(wxWindow
*win
)
1338 // Notify the parent keeping track of focus for the kbd navigation
1339 // purposes that we got it.
1340 wxChildFocusEvent
eventChildFocus(win
);
1341 (void)win
->GetEventHandler()->ProcessEvent(eventChildFocus
);
1343 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, win
->GetId());
1344 eventFocus
.SetEventObject(win
);
1346 return win
->GetEventHandler()->ProcessEvent(eventFocus
);
1349 // all event handlers must have C linkage as they're called from GTK+ C code
1353 //-----------------------------------------------------------------------------
1354 // "button_press_event"
1355 //-----------------------------------------------------------------------------
1358 gtk_window_button_press_callback( GtkWidget
*widget
,
1359 GdkEventButton
*gdk_event
,
1362 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1364 g_lastButtonNumber
= gdk_event
->button
;
1366 // GDK sends surplus button down events
1367 // before a double click event. We
1368 // need to filter these out.
1369 if ((gdk_event
->type
== GDK_BUTTON_PRESS
) && (win
->m_wxwindow
))
1371 GdkEvent
*peek_event
= gdk_event_peek();
1374 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1375 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1377 gdk_event_free( peek_event
);
1382 gdk_event_free( peek_event
);
1387 wxEventType event_type
= wxEVT_NULL
;
1389 if ( gdk_event
->type
== GDK_2BUTTON_PRESS
&&
1390 gdk_event
->button
>= 1 && gdk_event
->button
<= 3 )
1392 // Reset GDK internal timestamp variables in order to disable GDK
1393 // triple click events. GDK will then next time believe no button has
1394 // been clicked just before, and send a normal button click event.
1395 GdkDisplay
* display
= gtk_widget_get_display (widget
);
1396 display
->button_click_time
[1] = 0;
1397 display
->button_click_time
[0] = 0;
1400 if (gdk_event
->button
== 1)
1402 // note that GDK generates triple click events which are not supported
1403 // by wxWidgets but still have to be passed to the app as otherwise
1404 // clicks would simply go missing
1405 switch (gdk_event
->type
)
1407 // we shouldn't get triple clicks at all for GTK2 because we
1408 // suppress them artificially using the code above but we still
1409 // should map them to something for GTK1 and not just ignore them
1410 // as this would lose clicks
1411 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1412 case GDK_BUTTON_PRESS
:
1413 event_type
= wxEVT_LEFT_DOWN
;
1416 case GDK_2BUTTON_PRESS
:
1417 event_type
= wxEVT_LEFT_DCLICK
;
1421 // just to silence gcc warnings
1425 else if (gdk_event
->button
== 2)
1427 switch (gdk_event
->type
)
1429 case GDK_3BUTTON_PRESS
:
1430 case GDK_BUTTON_PRESS
:
1431 event_type
= wxEVT_MIDDLE_DOWN
;
1434 case GDK_2BUTTON_PRESS
:
1435 event_type
= wxEVT_MIDDLE_DCLICK
;
1442 else if (gdk_event
->button
== 3)
1444 switch (gdk_event
->type
)
1446 case GDK_3BUTTON_PRESS
:
1447 case GDK_BUTTON_PRESS
:
1448 event_type
= wxEVT_RIGHT_DOWN
;
1451 case GDK_2BUTTON_PRESS
:
1452 event_type
= wxEVT_RIGHT_DCLICK
;
1460 if ( event_type
== wxEVT_NULL
)
1462 // unknown mouse button or click type
1466 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1468 wxMouseEvent
event( event_type
);
1469 InitMouseEvent( win
, event
, gdk_event
);
1471 AdjustEventButtonState(event
);
1473 // wxListBox actually gets mouse events from the item, so we need to give it
1474 // a chance to correct this
1475 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1477 // find the correct window to send the event to: it may be a different one
1478 // from the one which got it at GTK+ level because some controls don't have
1479 // their own X window and thus cannot get any events.
1480 if ( !g_captureWindow
)
1481 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1483 // reset the event object and id in case win changed.
1484 event
.SetEventObject( win
);
1485 event
.SetId( win
->GetId() );
1487 bool ret
= win
->GTKProcessEvent( event
);
1488 g_lastMouseEvent
= NULL
;
1492 if ((event_type
== wxEVT_LEFT_DOWN
) && !win
->IsOfStandardClass() &&
1493 (g_focusWindow
!= win
) /* && win->IsFocusable() */)
1498 if (event_type
== wxEVT_RIGHT_DOWN
)
1500 // generate a "context menu" event: this is similar to right mouse
1501 // click under many GUIs except that it is generated differently
1502 // (right up under MSW, ctrl-click under Mac, right down here) and
1504 // (a) it's a command event and so is propagated to the parent
1505 // (b) under some ports it can be generated from kbd too
1506 // (c) it uses screen coords (because of (a))
1507 wxContextMenuEvent
evtCtx(
1510 win
->ClientToScreen(event
.GetPosition()));
1511 evtCtx
.SetEventObject(win
);
1512 return win
->GTKProcessEvent(evtCtx
);
1518 //-----------------------------------------------------------------------------
1519 // "button_release_event"
1520 //-----------------------------------------------------------------------------
1523 gtk_window_button_release_callback( GtkWidget
*widget
,
1524 GdkEventButton
*gdk_event
,
1527 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1529 g_lastButtonNumber
= 0;
1531 wxEventType event_type
= wxEVT_NULL
;
1533 switch (gdk_event
->button
)
1536 event_type
= wxEVT_LEFT_UP
;
1540 event_type
= wxEVT_MIDDLE_UP
;
1544 event_type
= wxEVT_RIGHT_UP
;
1548 // unknown button, don't process
1552 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1554 wxMouseEvent
event( event_type
);
1555 InitMouseEvent( win
, event
, gdk_event
);
1557 AdjustEventButtonState(event
);
1559 // same wxListBox hack as above
1560 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1562 if ( !g_captureWindow
)
1563 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1565 // reset the event object and id in case win changed.
1566 event
.SetEventObject( win
);
1567 event
.SetId( win
->GetId() );
1569 bool ret
= win
->GTKProcessEvent(event
);
1571 g_lastMouseEvent
= NULL
;
1576 //-----------------------------------------------------------------------------
1577 // "motion_notify_event"
1578 //-----------------------------------------------------------------------------
1581 gtk_window_motion_notify_callback( GtkWidget
* WXUNUSED(widget
),
1582 GdkEventMotion
*gdk_event
,
1585 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1587 if (gdk_event
->is_hint
)
1591 GdkModifierType state
;
1592 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1597 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1599 wxMouseEvent
event( wxEVT_MOTION
);
1600 InitMouseEvent(win
, event
, gdk_event
);
1602 if ( g_captureWindow
)
1604 // synthesise a mouse enter or leave event if needed
1605 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1606 // This seems to be necessary and actually been added to
1607 // GDK itself in version 2.0.X
1610 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1611 if ( hasMouse
!= g_captureWindowHasMouse
)
1613 // the mouse changed window
1614 g_captureWindowHasMouse
= hasMouse
;
1616 wxMouseEvent
eventM(g_captureWindowHasMouse
? wxEVT_ENTER_WINDOW
1617 : wxEVT_LEAVE_WINDOW
);
1618 InitMouseEvent(win
, eventM
, gdk_event
);
1619 eventM
.SetEventObject(win
);
1620 win
->GTKProcessEvent(eventM
);
1625 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1627 // reset the event object and id in case win changed.
1628 event
.SetEventObject( win
);
1629 event
.SetId( win
->GetId() );
1632 if ( !g_captureWindow
)
1634 wxSetCursorEvent
cevent( event
.m_x
, event
.m_y
);
1635 if (win
->GTKProcessEvent( cevent
))
1637 win
->SetCursor( cevent
.GetCursor() );
1641 bool ret
= win
->GTKProcessEvent(event
);
1643 g_lastMouseEvent
= NULL
;
1648 //-----------------------------------------------------------------------------
1649 // "scroll_event" (mouse wheel event)
1650 //-----------------------------------------------------------------------------
1653 window_scroll_event(GtkWidget
*, GdkEventScroll
* gdk_event
, wxWindow
* win
)
1657 if (gdk_event
->direction
!= GDK_SCROLL_UP
&&
1658 gdk_event
->direction
!= GDK_SCROLL_DOWN
)
1663 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
1664 InitMouseEvent(win
, event
, gdk_event
);
1665 event
.m_linesPerAction
= 3;
1666 event
.m_wheelDelta
= 120;
1667 if (gdk_event
->direction
== GDK_SCROLL_UP
)
1668 event
.m_wheelRotation
= 120;
1670 event
.m_wheelRotation
= -120;
1672 return win
->GTKProcessEvent(event
);
1675 //-----------------------------------------------------------------------------
1677 //-----------------------------------------------------------------------------
1679 static gboolean
wxgtk_window_popup_menu_callback(GtkWidget
*, wxWindowGTK
* win
)
1681 wxContextMenuEvent
event(wxEVT_CONTEXT_MENU
, win
->GetId(), wxPoint(-1, -1));
1682 event
.SetEventObject(win
);
1683 return win
->GTKProcessEvent(event
);
1686 //-----------------------------------------------------------------------------
1688 //-----------------------------------------------------------------------------
1691 gtk_window_focus_in_callback( GtkWidget
* WXUNUSED(widget
),
1692 GdkEventFocus
*WXUNUSED(event
),
1698 gtk_im_context_focus_in(win
->m_imData
->context
);
1701 g_focusWindow
= win
;
1703 wxLogTrace(TRACE_FOCUS
,
1704 _T("%s: focus in"), win
->GetName().c_str());
1707 // caret needs to be informed about focus change
1708 wxCaret
*caret
= win
->GetCaret();
1711 caret
->OnSetFocus();
1713 #endif // wxUSE_CARET
1715 gboolean ret
= FALSE
;
1717 // does the window itself think that it has the focus?
1718 if ( !win
->m_hasFocus
)
1720 // not yet, notify it
1721 win
->m_hasFocus
= true;
1723 (void)DoSendFocusEvents(win
);
1728 // Disable default focus handling for custom windows
1729 // since the default GTK+ handler issues a repaint
1730 if (win
->m_wxwindow
)
1736 //-----------------------------------------------------------------------------
1737 // "focus_out_event"
1738 //-----------------------------------------------------------------------------
1741 gtk_window_focus_out_callback( GtkWidget
* WXUNUSED(widget
),
1742 GdkEventFocus
* WXUNUSED(gdk_event
),
1748 gtk_im_context_focus_out(win
->m_imData
->context
);
1750 wxLogTrace( TRACE_FOCUS
,
1751 _T("%s: focus out"), win
->GetName().c_str() );
1754 wxWindowGTK
*winFocus
= wxFindFocusedChild(win
);
1758 g_focusWindow
= (wxWindowGTK
*)NULL
;
1761 // caret needs to be informed about focus change
1762 wxCaret
*caret
= win
->GetCaret();
1765 caret
->OnKillFocus();
1767 #endif // wxUSE_CARET
1769 // don't send the window a kill focus event if it thinks that it doesn't
1770 // have focus already
1771 if ( win
->m_hasFocus
)
1773 // the event handler might delete the window when it loses focus, so
1774 // check whether this is a custom window before calling it
1775 const bool has_wxwindow
= win
->m_wxwindow
!= NULL
;
1777 win
->m_hasFocus
= false;
1779 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
1780 event
.SetEventObject( win
);
1782 (void)win
->GTKProcessEvent( event
);
1784 // Disable default focus handling for custom windows
1785 // since the default GTK+ handler issues a repaint
1790 // continue with normal processing
1795 wx_window_focus_callback(GtkWidget
*widget
,
1796 GtkDirectionType
WXUNUSED(direction
),
1799 // the default handler for focus signal in GtkScrolledWindow sets
1800 // focus to the window itself even if it doesn't accept focus, i.e. has no
1801 // GTK_CAN_FOCUS in its style -- work around this by forcibly preventing
1802 // the signal from reaching gtk_scrolled_window_focus() if we don't have
1803 // any children which might accept focus (we know we don't accept the focus
1804 // ourselves as this signal is only connected in this case)
1805 if ( win
->GetChildren().empty() )
1806 g_signal_stop_emission_by_name(widget
, "focus");
1808 // we didn't change the focus
1812 //-----------------------------------------------------------------------------
1813 // "enter_notify_event"
1814 //-----------------------------------------------------------------------------
1817 gtk_window_enter_callback( GtkWidget
*widget
,
1818 GdkEventCrossing
*gdk_event
,
1821 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1823 // Event was emitted after a grab
1824 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1828 GdkModifierType state
= (GdkModifierType
)0;
1830 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1832 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
1833 InitMouseEvent(win
, event
, gdk_event
);
1834 wxPoint pt
= win
->GetClientAreaOrigin();
1835 event
.m_x
= x
+ pt
.x
;
1836 event
.m_y
= y
+ pt
.y
;
1838 if ( !g_captureWindow
)
1840 wxSetCursorEvent
cevent( event
.m_x
, event
.m_y
);
1841 if (win
->GTKProcessEvent( cevent
))
1843 win
->SetCursor( cevent
.GetCursor() );
1847 return win
->GTKProcessEvent(event
);
1850 //-----------------------------------------------------------------------------
1851 // "leave_notify_event"
1852 //-----------------------------------------------------------------------------
1855 gtk_window_leave_callback( GtkWidget
*widget
,
1856 GdkEventCrossing
*gdk_event
,
1859 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1861 // Event was emitted after an ungrab
1862 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1864 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
1868 GdkModifierType state
= (GdkModifierType
)0;
1870 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1872 InitMouseEvent(win
, event
, gdk_event
);
1874 return win
->GTKProcessEvent(event
);
1877 //-----------------------------------------------------------------------------
1878 // "value_changed" from scrollbar
1879 //-----------------------------------------------------------------------------
1882 gtk_scrollbar_value_changed(GtkRange
* range
, wxWindow
* win
)
1884 wxEventType eventType
= win
->GetScrollEventType(range
);
1885 if (eventType
!= wxEVT_NULL
)
1887 // Convert scroll event type to scrollwin event type
1888 eventType
+= wxEVT_SCROLLWIN_TOP
- wxEVT_SCROLL_TOP
;
1890 // find the scrollbar which generated the event
1891 wxWindowGTK::ScrollDir dir
= win
->ScrollDirFromRange(range
);
1893 // generate the corresponding wx event
1894 const int orient
= wxWindow::OrientFromScrollDir(dir
);
1895 wxScrollWinEvent
event(eventType
, win
->GetScrollPos(orient
), orient
);
1896 event
.SetEventObject(win
);
1898 win
->GTKProcessEvent(event
);
1902 //-----------------------------------------------------------------------------
1903 // "button_press_event" from scrollbar
1904 //-----------------------------------------------------------------------------
1907 gtk_scrollbar_button_press_event(GtkRange
*, GdkEventButton
*, wxWindow
* win
)
1911 g_blockEventsOnScroll
= true;
1912 win
->m_mouseButtonDown
= true;
1917 //-----------------------------------------------------------------------------
1918 // "event_after" from scrollbar
1919 //-----------------------------------------------------------------------------
1922 gtk_scrollbar_event_after(GtkRange
* range
, GdkEvent
* event
, wxWindow
* win
)
1924 if (event
->type
== GDK_BUTTON_RELEASE
)
1926 g_signal_handlers_block_by_func(range
, (void*)gtk_scrollbar_event_after
, win
);
1928 const int orient
= wxWindow::OrientFromScrollDir(
1929 win
->ScrollDirFromRange(range
));
1930 wxScrollWinEvent
evt(wxEVT_SCROLLWIN_THUMBRELEASE
,
1931 win
->GetScrollPos(orient
), orient
);
1932 evt
.SetEventObject(win
);
1933 win
->GTKProcessEvent(evt
);
1937 //-----------------------------------------------------------------------------
1938 // "button_release_event" from scrollbar
1939 //-----------------------------------------------------------------------------
1942 gtk_scrollbar_button_release_event(GtkRange
* range
, GdkEventButton
*, wxWindow
* win
)
1946 g_blockEventsOnScroll
= false;
1947 win
->m_mouseButtonDown
= false;
1948 // If thumb tracking
1949 if (win
->m_isScrolling
)
1951 win
->m_isScrolling
= false;
1952 // Hook up handler to send thumb release event after this emission is finished.
1953 // To allow setting scroll position from event handler, sending event must
1954 // be deferred until after the GtkRange handler for this signal has run
1955 g_signal_handlers_unblock_by_func(range
, (void*)gtk_scrollbar_event_after
, win
);
1961 //-----------------------------------------------------------------------------
1962 // "realize" from m_widget
1963 //-----------------------------------------------------------------------------
1966 gtk_window_realized_callback(GtkWidget
* widget
, wxWindow
* win
)
1972 gtk_im_context_set_client_window( win
->m_imData
->context
,
1976 // We cannot set colours and fonts before the widget
1977 // been realized, so we do this directly after realization
1978 // or otherwise in idle time
1980 if (win
->m_needsStyleChange
)
1982 win
->SetBackgroundStyle(win
->GetBackgroundStyle());
1983 win
->m_needsStyleChange
= false;
1986 wxWindowCreateEvent
event( win
);
1987 event
.SetEventObject( win
);
1988 win
->GTKProcessEvent( event
);
1991 //-----------------------------------------------------------------------------
1992 // "size_allocate" from m_wxwindow or m_widget
1993 //-----------------------------------------------------------------------------
1996 size_allocate(GtkWidget
*, GtkAllocation
* alloc
, wxWindow
* win
)
1998 int w
= alloc
->width
;
1999 int h
= alloc
->height
;
2000 if (win
->m_wxwindow
)
2002 int border_x
, border_y
;
2003 WX_PIZZA(win
->m_wxwindow
)->get_border_widths(border_x
, border_y
);
2009 if (win
->m_oldClientWidth
!= w
|| win
->m_oldClientHeight
!= h
)
2011 win
->m_oldClientWidth
= w
;
2012 win
->m_oldClientHeight
= h
;
2013 // this callback can be connected to m_wxwindow,
2014 // so always get size from m_widget->allocation
2015 win
->m_width
= win
->m_widget
->allocation
.width
;
2016 win
->m_height
= win
->m_widget
->allocation
.height
;
2017 if (!win
->m_nativeSizeEvent
)
2019 wxSizeEvent
event(win
->GetSize(), win
->GetId());
2020 event
.SetEventObject(win
);
2021 win
->GTKProcessEvent(event
);
2026 //-----------------------------------------------------------------------------
2028 //-----------------------------------------------------------------------------
2030 #if GTK_CHECK_VERSION(2, 8, 0)
2032 gtk_window_grab_broken( GtkWidget
*,
2033 GdkEventGrabBroken
*event
,
2036 // Mouse capture has been lost involuntarily, notify the application
2037 if(!event
->keyboard
&& wxWindow::GetCapture() == win
)
2039 wxMouseCaptureLostEvent
evt( win
->GetId() );
2040 evt
.SetEventObject( win
);
2041 win
->GetEventHandler()->ProcessEvent( evt
);
2047 //-----------------------------------------------------------------------------
2049 //-----------------------------------------------------------------------------
2052 void gtk_window_style_set_callback( GtkWidget
*WXUNUSED(widget
),
2053 GtkStyle
*previous_style
,
2056 //wxLogDebug(wxT("gtk_window_style_set_callback"));
2057 if (win
&& previous_style
)
2059 wxString
name(win
->GetName());
2060 //wxLogDebug(wxT("gtk_window_style_set_callback %s"), name.c_str());
2061 wxSysColourChangedEvent event
;
2062 event
.SetEventObject(win
);
2064 win
->GTKProcessEvent( event
);
2070 // Connect/disconnect style-set
2072 void wxConnectStyleSet(wxWindow
* win
)
2074 if (win
->m_wxwindow
)
2075 g_signal_connect (win
->m_wxwindow
, "style_set",
2076 G_CALLBACK (gtk_window_style_set_callback
), win
);
2079 void wxDisconnectStyleSet(wxWindow
* win
)
2081 if (win
->m_wxwindow
)
2082 g_signal_handlers_disconnect_by_func (win
->m_wxwindow
,
2083 (gpointer
) gtk_window_style_set_callback
,
2087 // Helper to suspend colour change event event processing while we change a widget's style
2088 class wxSuspendStyleEvents
2091 wxSuspendStyleEvents(wxWindow
* win
)
2094 if (win
->IsTopLevel())
2095 wxDisconnectStyleSet(win
);
2097 ~wxSuspendStyleEvents()
2099 if (m_win
->IsTopLevel())
2100 wxConnectStyleSet(m_win
);
2106 // ----------------------------------------------------------------------------
2107 // this wxWindowBase function is implemented here (in platform-specific file)
2108 // because it is static and so couldn't be made virtual
2109 // ----------------------------------------------------------------------------
2111 wxWindow
*wxWindowBase::DoFindFocus()
2113 // the cast is necessary when we compile in wxUniversal mode
2114 return (wxWindow
*)g_focusWindow
;
2117 //-----------------------------------------------------------------------------
2118 // InsertChild for wxWindowGTK.
2119 //-----------------------------------------------------------------------------
2121 /* Callback for wxWindowGTK. This very strange beast has to be used because
2122 * C++ has no virtual methods in a constructor. We have to emulate a
2123 * virtual function here as wxNotebook requires a different way to insert
2124 * a child in it. I had opted for creating a wxNotebookPage window class
2125 * which would have made this superfluous (such in the MDI window system),
2126 * but no-one was listening to me... */
2128 static void wxInsertChildInWindow( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2130 /* the window might have been scrolled already, do we
2131 have to adapt the position */
2132 wxPizza
* pizza
= WX_PIZZA(parent
->m_wxwindow
);
2133 child
->m_x
+= pizza
->m_scroll_x
;
2134 child
->m_y
+= pizza
->m_scroll_y
;
2136 gtk_widget_set_size_request(
2137 child
->m_widget
, child
->m_width
, child
->m_height
);
2139 GTK_FIXED(parent
->m_wxwindow
), child
->m_widget
, child
->m_x
, child
->m_y
);
2142 //-----------------------------------------------------------------------------
2144 //-----------------------------------------------------------------------------
2146 wxWindow
*wxGetActiveWindow()
2148 return wxWindow::FindFocus();
2152 wxMouseState
wxGetMouseState()
2158 GdkModifierType mask
;
2160 gdk_window_get_pointer(NULL
, &x
, &y
, &mask
);
2164 ms
.SetLeftDown(mask
& GDK_BUTTON1_MASK
);
2165 ms
.SetMiddleDown(mask
& GDK_BUTTON2_MASK
);
2166 ms
.SetRightDown(mask
& GDK_BUTTON3_MASK
);
2167 ms
.SetAux1Down(mask
& GDK_BUTTON4_MASK
);
2168 ms
.SetAux2Down(mask
& GDK_BUTTON5_MASK
);
2170 ms
.SetControlDown(mask
& GDK_CONTROL_MASK
);
2171 ms
.SetShiftDown(mask
& GDK_SHIFT_MASK
);
2172 ms
.SetAltDown(mask
& GDK_MOD1_MASK
);
2173 ms
.SetMetaDown(mask
& GDK_MOD2_MASK
);
2178 //-----------------------------------------------------------------------------
2180 //-----------------------------------------------------------------------------
2182 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2184 #ifdef __WXUNIVERSAL__
2185 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2187 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
2188 #endif // __WXUNIVERSAL__/__WXGTK__
2190 void wxWindowGTK::Init()
2193 m_widget
= (GtkWidget
*) NULL
;
2194 m_wxwindow
= (GtkWidget
*) NULL
;
2195 m_focusWidget
= (GtkWidget
*) NULL
;
2204 m_isBeingDeleted
= false;
2206 m_showOnIdle
= false;
2209 m_nativeSizeEvent
= false;
2211 m_hasScrolling
= false;
2212 m_isScrolling
= false;
2213 m_mouseButtonDown
= false;
2215 // initialize scrolling stuff
2216 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
2218 m_scrollBar
[dir
] = NULL
;
2219 m_scrollPos
[dir
] = 0;
2223 m_oldClientHeight
= 0;
2225 m_insertCallback
= wxInsertChildInWindow
;
2229 m_clipPaintRegion
= false;
2231 m_needsStyleChange
= false;
2233 m_cursor
= *wxSTANDARD_CURSOR
;
2236 m_dirtyTabOrder
= false;
2239 wxWindowGTK::wxWindowGTK()
2244 wxWindowGTK::wxWindowGTK( wxWindow
*parent
,
2249 const wxString
&name
)
2253 Create( parent
, id
, pos
, size
, style
, name
);
2256 bool wxWindowGTK::Create( wxWindow
*parent
,
2261 const wxString
&name
)
2263 if (!PreCreation( parent
, pos
, size
) ||
2264 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2266 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2270 m_wxwindow
= wxPizza::New(m_windowStyle
);
2271 if (!HasFlag(wxHSCROLL
) && !HasFlag(wxVSCROLL
))
2272 m_widget
= m_wxwindow
;
2275 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
2276 gtk_container_set_resize_mode(GTK_CONTAINER(m_widget
), GTK_RESIZE_QUEUE
);
2278 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2280 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2281 scroll_class
->scrollbar_spacing
= 0;
2283 // There is a conflict with default bindings at GTK+
2284 // level between scrolled windows and notebooks both of which want to use
2285 // Ctrl-PageUp/Down: scrolled windows for scrolling in the horizontal
2286 // direction and notebooks for changing pages -- we decide that if we don't
2287 // have wxHSCROLL style we can safely sacrifice horizontal scrolling if it
2288 // means we can get working keyboard navigation in notebooks
2289 if ( !HasFlag(wxHSCROLL
) )
2292 bindings
= gtk_binding_set_by_class(G_OBJECT_GET_CLASS(m_widget
));
2295 gtk_binding_entry_remove(bindings
, GDK_Page_Up
, GDK_CONTROL_MASK
);
2296 gtk_binding_entry_remove(bindings
, GDK_Page_Down
, GDK_CONTROL_MASK
);
2300 if (HasFlag(wxALWAYS_SHOW_SB
))
2302 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_ALWAYS
, GTK_POLICY_ALWAYS
);
2304 scrolledWindow
->hscrollbar_visible
= TRUE
;
2305 scrolledWindow
->vscrollbar_visible
= TRUE
;
2309 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2312 m_scrollBar
[ScrollDir_Horz
] = GTK_RANGE(scrolledWindow
->hscrollbar
);
2313 m_scrollBar
[ScrollDir_Vert
] = GTK_RANGE(scrolledWindow
->vscrollbar
);
2314 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2315 gtk_range_set_inverted( m_scrollBar
[ScrollDir_Horz
], TRUE
);
2317 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2319 // connect various scroll-related events
2320 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
2322 // these handlers block mouse events to any window during scrolling
2323 // such as motion events and prevent GTK and wxWidgets from fighting
2324 // over where the slider should be
2325 g_signal_connect(m_scrollBar
[dir
], "button_press_event",
2326 G_CALLBACK(gtk_scrollbar_button_press_event
), this);
2327 g_signal_connect(m_scrollBar
[dir
], "button_release_event",
2328 G_CALLBACK(gtk_scrollbar_button_release_event
), this);
2330 gulong handler_id
= g_signal_connect(m_scrollBar
[dir
], "event_after",
2331 G_CALLBACK(gtk_scrollbar_event_after
), this);
2332 g_signal_handler_block(m_scrollBar
[dir
], handler_id
);
2334 // these handlers get notified when scrollbar slider moves
2335 g_signal_connect_after(m_scrollBar
[dir
], "value_changed",
2336 G_CALLBACK(gtk_scrollbar_value_changed
), this);
2339 gtk_widget_show( m_wxwindow
);
2343 m_parent
->DoAddChild( this );
2345 m_focusWidget
= m_wxwindow
;
2352 wxWindowGTK::~wxWindowGTK()
2356 if (g_focusWindow
== this)
2357 g_focusWindow
= NULL
;
2359 if ( g_delayedFocus
== this )
2360 g_delayedFocus
= NULL
;
2362 m_isBeingDeleted
= true;
2365 // destroy children before destroying this window itself
2368 // unhook focus handlers to prevent stray events being
2369 // propagated to this (soon to be) dead object
2370 if (m_focusWidget
!= NULL
)
2372 g_signal_handlers_disconnect_by_func (m_focusWidget
,
2373 (gpointer
) gtk_window_focus_in_callback
,
2375 g_signal_handlers_disconnect_by_func (m_focusWidget
,
2376 (gpointer
) gtk_window_focus_out_callback
,
2383 // delete before the widgets to avoid a crash on solaris
2386 if (m_wxwindow
&& (m_wxwindow
!= m_widget
))
2388 gtk_widget_destroy( m_wxwindow
);
2389 m_wxwindow
= (GtkWidget
*) NULL
;
2394 gtk_widget_destroy( m_widget
);
2395 m_widget
= (GtkWidget
*) NULL
;
2399 bool wxWindowGTK::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2401 if ( GTKNeedsParent() )
2403 wxCHECK_MSG( parent
, false, wxT("Must have non-NULL parent") );
2406 // Use either the given size, or the default if -1 is given.
2407 // See wxWindowBase for these functions.
2408 m_width
= WidthDefault(size
.x
) ;
2409 m_height
= HeightDefault(size
.y
);
2417 void wxWindowGTK::PostCreation()
2419 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2425 // these get reported to wxWidgets -> wxPaintEvent
2427 g_signal_connect (m_wxwindow
, "expose_event",
2428 G_CALLBACK (gtk_window_expose_callback
), this);
2430 if (GetLayoutDirection() == wxLayout_LeftToRight
)
2431 gtk_widget_set_redraw_on_allocate(m_wxwindow
, HasFlag(wxFULL_REPAINT_ON_RESIZE
));
2434 // Create input method handler
2435 m_imData
= new wxGtkIMData
;
2437 // Cannot handle drawing preedited text yet
2438 gtk_im_context_set_use_preedit( m_imData
->context
, FALSE
);
2440 g_signal_connect (m_imData
->context
, "commit",
2441 G_CALLBACK (gtk_wxwindow_commit_cb
), this);
2444 #ifndef __WXUNIVERSAL__
2445 if (HasFlag(wxBORDER_SIMPLE
| wxBORDER_RAISED
| wxBORDER_SUNKEN
))
2447 g_signal_connect(m_widget
, "expose_event",
2448 G_CALLBACK(expose_event_border
), this);
2455 if (!GTK_IS_WINDOW(m_widget
))
2457 if (m_focusWidget
== NULL
)
2458 m_focusWidget
= m_widget
;
2462 g_signal_connect (m_focusWidget
, "focus_in_event",
2463 G_CALLBACK (gtk_window_focus_in_callback
), this);
2464 g_signal_connect (m_focusWidget
, "focus_out_event",
2465 G_CALLBACK (gtk_window_focus_out_callback
), this);
2469 g_signal_connect_after (m_focusWidget
, "focus_in_event",
2470 G_CALLBACK (gtk_window_focus_in_callback
), this);
2471 g_signal_connect_after (m_focusWidget
, "focus_out_event",
2472 G_CALLBACK (gtk_window_focus_out_callback
), this);
2476 if ( !AcceptsFocusFromKeyboard() )
2480 g_signal_connect(m_widget
, "focus",
2481 G_CALLBACK(wx_window_focus_callback
), this);
2484 // connect to the various key and mouse handlers
2486 GtkWidget
*connect_widget
= GetConnectWidget();
2488 ConnectWidget( connect_widget
);
2490 /* We cannot set colours, fonts and cursors before the widget has
2491 been realized, so we do this directly after realization */
2492 g_signal_connect (connect_widget
, "realize",
2493 G_CALLBACK (gtk_window_realized_callback
), this);
2497 g_signal_connect(m_wxwindow
? m_wxwindow
: m_widget
, "size_allocate",
2498 G_CALLBACK(size_allocate
), this);
2503 #if GTK_CHECK_VERSION(2, 8, 0)
2504 if (!gtk_check_version(2,8,0))
2506 // Make sure we can notify the app when mouse capture is lost
2507 g_signal_connect (m_wxwindow
, "grab_broken_event",
2508 G_CALLBACK (gtk_window_grab_broken
), this);
2513 if ( connect_widget
!= m_wxwindow
)
2515 #if GTK_CHECK_VERSION(2, 8, 0)
2516 if (!gtk_check_version(2,8,0))
2518 // Make sure we can notify app code when mouse capture is lost
2519 g_signal_connect (connect_widget
, "grab_broken_event",
2520 G_CALLBACK (gtk_window_grab_broken
), this);
2525 #ifdef GTK_IS_FILE_CHOOSER_BUTTON
2526 if (!gtk_check_version(2,6,0) && GTK_IS_FILE_CHOOSER_BUTTON(m_widget
))
2528 // If we connect to the "size_request" signal of a GtkFileChooserButton
2529 // then that control won't be sized properly when placed inside sizers
2530 // (this can be tested removing this elseif and running XRC or WIDGETS samples)
2531 // FIXME: what should be done here ?
2534 if ( !IsTopLevel() ) // top level windows use their own callback
2536 // This is needed if we want to add our windows into native
2537 // GTK controls, such as the toolbar. With this callback, the
2538 // toolbar gets to know the correct size (the one set by the
2539 // programmer). Sadly, it misbehaves for wxComboBox.
2540 g_signal_connect (m_widget
, "size_request",
2541 G_CALLBACK (wxgtk_window_size_request_callback
),
2545 InheritAttributes();
2549 SetLayoutDirection(wxLayout_Default
);
2551 // unless the window was created initially hidden (i.e. Hide() had been
2552 // called before Create()), we should show it at GTK+ level as well
2554 gtk_widget_show( m_widget
);
2557 void wxWindowGTK::ConnectWidget( GtkWidget
*widget
)
2559 g_signal_connect (widget
, "key_press_event",
2560 G_CALLBACK (gtk_window_key_press_callback
), this);
2561 g_signal_connect (widget
, "key_release_event",
2562 G_CALLBACK (gtk_window_key_release_callback
), this);
2563 g_signal_connect (widget
, "button_press_event",
2564 G_CALLBACK (gtk_window_button_press_callback
), this);
2565 g_signal_connect (widget
, "button_release_event",
2566 G_CALLBACK (gtk_window_button_release_callback
), this);
2567 g_signal_connect (widget
, "motion_notify_event",
2568 G_CALLBACK (gtk_window_motion_notify_callback
), this);
2569 g_signal_connect (widget
, "scroll_event",
2570 G_CALLBACK (window_scroll_event
), this);
2571 g_signal_connect (widget
, "popup_menu",
2572 G_CALLBACK (wxgtk_window_popup_menu_callback
), this);
2573 g_signal_connect (widget
, "enter_notify_event",
2574 G_CALLBACK (gtk_window_enter_callback
), this);
2575 g_signal_connect (widget
, "leave_notify_event",
2576 G_CALLBACK (gtk_window_leave_callback
), this);
2578 if (IsTopLevel() && m_wxwindow
)
2579 g_signal_connect (m_wxwindow
, "style_set",
2580 G_CALLBACK (gtk_window_style_set_callback
), this);
2583 bool wxWindowGTK::Destroy()
2585 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2589 return wxWindowBase::Destroy();
2592 void wxWindowGTK::DoMoveWindow(int x
, int y
, int width
, int height
)
2594 gtk_widget_set_size_request(m_widget
, width
, height
);
2595 // inform the parent to perform the move
2596 WX_PIZZA(m_parent
->m_wxwindow
)->move(m_widget
, x
, y
);
2599 void wxWindowGTK::ConstrainSize()
2602 // GPE's window manager doesn't like size hints at all, esp. when the user
2603 // has to use the virtual keyboard, so don't constrain size there
2607 const wxSize minSize
= GetMinSize();
2608 const wxSize maxSize
= GetMaxSize();
2609 if (minSize
.x
> 0 && m_width
< minSize
.x
) m_width
= minSize
.x
;
2610 if (minSize
.y
> 0 && m_height
< minSize
.y
) m_height
= minSize
.y
;
2611 if (maxSize
.x
> 0 && m_width
> maxSize
.x
) m_width
= maxSize
.x
;
2612 if (maxSize
.y
> 0 && m_height
> maxSize
.y
) m_height
= maxSize
.y
;
2616 void wxWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
2618 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2619 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
2621 int currentX
, currentY
;
2622 GetPosition(¤tX
, ¤tY
);
2623 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2625 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2627 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2629 // calculate the best size if we should auto size the window
2630 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
2631 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
2633 const wxSize sizeBest
= GetBestSize();
2634 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
2636 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
2637 height
= sizeBest
.y
;
2640 const wxSize
oldSize(m_width
, m_height
);
2648 if (m_parent
->m_wxwindow
)
2650 wxPizza
* pizza
= WX_PIZZA(m_parent
->m_wxwindow
);
2651 m_x
= x
+ pizza
->m_scroll_x
;
2652 m_y
= y
+ pizza
->m_scroll_y
;
2654 int left_border
= 0;
2655 int right_border
= 0;
2657 int bottom_border
= 0;
2659 /* the default button has a border around it */
2660 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
2662 GtkBorder
*default_border
= NULL
;
2663 gtk_widget_style_get( m_widget
, "default_border", &default_border
, NULL
);
2666 left_border
+= default_border
->left
;
2667 right_border
+= default_border
->right
;
2668 top_border
+= default_border
->top
;
2669 bottom_border
+= default_border
->bottom
;
2670 gtk_border_free( default_border
);
2674 DoMoveWindow( m_x
- left_border
,
2676 m_width
+left_border
+right_border
,
2677 m_height
+top_border
+bottom_border
);
2680 if (m_width
!= oldSize
.x
|| m_height
!= oldSize
.y
)
2682 // update these variables to keep size_allocate handler
2683 // from sending another size event for this change
2684 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
2686 gtk_widget_queue_resize(m_widget
);
2687 if (!m_nativeSizeEvent
)
2689 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
2690 event
.SetEventObject( this );
2691 GetEventHandler()->ProcessEvent( event
);
2696 bool wxWindowGTK::GtkShowFromOnIdle()
2698 if (IsShown() && m_showOnIdle
&& !GTK_WIDGET_VISIBLE (m_widget
))
2700 GtkAllocation alloc
;
2703 alloc
.width
= m_width
;
2704 alloc
.height
= m_height
;
2705 gtk_widget_size_allocate( m_widget
, &alloc
);
2706 gtk_widget_show( m_widget
);
2707 wxShowEvent
eventShow(GetId(), true);
2708 eventShow
.SetEventObject(this);
2709 GetEventHandler()->ProcessEvent(eventShow
);
2710 m_showOnIdle
= false;
2717 void wxWindowGTK::OnInternalIdle()
2719 // Check if we have to show window now
2720 if (GtkShowFromOnIdle()) return;
2722 if ( m_dirtyTabOrder
)
2724 m_dirtyTabOrder
= false;
2728 // Update style if the window was not yet realized
2729 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
2730 if (m_needsStyleChange
)
2732 SetBackgroundStyle(GetBackgroundStyle());
2733 m_needsStyleChange
= false;
2736 wxCursor cursor
= m_cursor
;
2737 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
2741 /* I now set the cursor anew in every OnInternalIdle call
2742 as setting the cursor in a parent window also effects the
2743 windows above so that checking for the current cursor is
2746 if (m_wxwindow
&& (m_wxwindow
!= m_widget
))
2748 GdkWindow
*window
= m_wxwindow
->window
;
2750 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2752 if (!g_globalCursor
.Ok())
2753 cursor
= *wxSTANDARD_CURSOR
;
2755 window
= m_widget
->window
;
2756 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2757 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2760 else if ( m_widget
)
2762 GdkWindow
*window
= m_widget
->window
;
2763 if ( window
&& !GTK_WIDGET_NO_WINDOW(m_widget
) )
2764 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2768 if (wxUpdateUIEvent::CanUpdate(this) && IsShown())
2769 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2772 void wxWindowGTK::DoGetSize( int *width
, int *height
) const
2774 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2776 if (width
) (*width
) = m_width
;
2777 if (height
) (*height
) = m_height
;
2780 void wxWindowGTK::DoSetClientSize( int width
, int height
)
2782 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2784 const wxSize size
= GetSize();
2785 const wxSize clientSize
= GetClientSize();
2786 SetSize(width
+ (size
.x
- clientSize
.x
), height
+ (size
.y
- clientSize
.y
));
2789 void wxWindowGTK::DoGetClientSize( int *width
, int *height
) const
2791 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2802 GetScrollbarWidth(m_widget
, dw
, dh
);
2804 int border_x
, border_y
;
2805 WX_PIZZA(m_wxwindow
)->get_border_widths(border_x
, border_y
);
2817 if (width
) *width
= w
;
2818 if (height
) *height
= h
;
2821 void wxWindowGTK::DoGetPosition( int *x
, int *y
) const
2823 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2827 if (!IsTopLevel() && m_parent
&& m_parent
->m_wxwindow
)
2829 wxPizza
* pizza
= WX_PIZZA(m_parent
->m_wxwindow
);
2830 dx
= pizza
->m_scroll_x
;
2831 dy
= pizza
->m_scroll_y
;
2834 if (m_x
== -1 && m_y
== -1)
2836 GdkWindow
*source
= (GdkWindow
*) NULL
;
2838 source
= m_wxwindow
->window
;
2840 source
= m_widget
->window
;
2846 gdk_window_get_origin( source
, &org_x
, &org_y
);
2849 m_parent
->ScreenToClient(&org_x
, &org_y
);
2851 wx_const_cast(wxWindowGTK
*, this)->m_x
= org_x
;
2852 wx_const_cast(wxWindowGTK
*, this)->m_y
= org_y
;
2856 if (x
) (*x
) = m_x
- dx
;
2857 if (y
) (*y
) = m_y
- dy
;
2860 void wxWindowGTK::DoClientToScreen( int *x
, int *y
) const
2862 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2864 if (!m_widget
->window
) return;
2866 GdkWindow
*source
= (GdkWindow
*) NULL
;
2868 source
= m_wxwindow
->window
;
2870 source
= m_widget
->window
;
2874 gdk_window_get_origin( source
, &org_x
, &org_y
);
2878 if (GTK_WIDGET_NO_WINDOW (m_widget
))
2880 org_x
+= m_widget
->allocation
.x
;
2881 org_y
+= m_widget
->allocation
.y
;
2888 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2889 *x
= (GetClientSize().x
- *x
) + org_x
;
2897 void wxWindowGTK::DoScreenToClient( int *x
, int *y
) const
2899 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2901 if (!m_widget
->window
) return;
2903 GdkWindow
*source
= (GdkWindow
*) NULL
;
2905 source
= m_wxwindow
->window
;
2907 source
= m_widget
->window
;
2911 gdk_window_get_origin( source
, &org_x
, &org_y
);
2915 if (GTK_WIDGET_NO_WINDOW (m_widget
))
2917 org_x
+= m_widget
->allocation
.x
;
2918 org_y
+= m_widget
->allocation
.y
;
2924 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2925 *x
= (GetClientSize().x
- *x
) - org_x
;
2932 bool wxWindowGTK::Show( bool show
)
2934 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
2936 if (!wxWindowBase::Show(show
))
2946 gtk_widget_show( m_widget
);
2947 wxShowEvent
eventShow(GetId(), show
);
2948 eventShow
.SetEventObject(this);
2949 GetEventHandler()->ProcessEvent(eventShow
);
2954 gtk_widget_hide( m_widget
);
2955 wxShowEvent
eventShow(GetId(), show
);
2956 eventShow
.SetEventObject(this);
2957 GetEventHandler()->ProcessEvent(eventShow
);
2963 void wxWindowGTK::DoEnable( bool enable
)
2965 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2967 gtk_widget_set_sensitive( m_widget
, enable
);
2968 if (m_wxwindow
&& (m_wxwindow
!= m_widget
))
2969 gtk_widget_set_sensitive( m_wxwindow
, enable
);
2972 int wxWindowGTK::GetCharHeight() const
2974 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
2976 wxFont font
= GetFont();
2977 wxCHECK_MSG( font
.Ok(), 12, wxT("invalid font") );
2979 PangoContext
* context
= gtk_widget_get_pango_context(m_widget
);
2984 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
2985 PangoLayout
*layout
= pango_layout_new(context
);
2986 pango_layout_set_font_description(layout
, desc
);
2987 pango_layout_set_text(layout
, "H", 1);
2988 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
2990 PangoRectangle rect
;
2991 pango_layout_line_get_extents(line
, NULL
, &rect
);
2993 g_object_unref (layout
);
2995 return (int) PANGO_PIXELS(rect
.height
);
2998 int wxWindowGTK::GetCharWidth() const
3000 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
3002 wxFont font
= GetFont();
3003 wxCHECK_MSG( font
.Ok(), 8, wxT("invalid font") );
3005 PangoContext
* context
= gtk_widget_get_pango_context(m_widget
);
3010 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
3011 PangoLayout
*layout
= pango_layout_new(context
);
3012 pango_layout_set_font_description(layout
, desc
);
3013 pango_layout_set_text(layout
, "g", 1);
3014 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
3016 PangoRectangle rect
;
3017 pango_layout_line_get_extents(line
, NULL
, &rect
);
3019 g_object_unref (layout
);
3021 return (int) PANGO_PIXELS(rect
.width
);
3024 void wxWindowGTK::GetTextExtent( const wxString
& string
,
3028 int *externalLeading
,
3029 const wxFont
*theFont
) const
3031 wxFont fontToUse
= theFont
? *theFont
: GetFont();
3033 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
3042 PangoContext
*context
= NULL
;
3044 context
= gtk_widget_get_pango_context( m_widget
);
3053 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
3054 PangoLayout
*layout
= pango_layout_new(context
);
3055 pango_layout_set_font_description(layout
, desc
);
3057 const wxCharBuffer data
= wxGTK_CONV( string
);
3059 pango_layout_set_text(layout
, data
, strlen(data
));
3062 PangoRectangle rect
;
3063 pango_layout_get_extents(layout
, NULL
, &rect
);
3065 if (x
) (*x
) = (wxCoord
) PANGO_PIXELS(rect
.width
);
3066 if (y
) (*y
) = (wxCoord
) PANGO_PIXELS(rect
.height
);
3069 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
3070 int baseline
= pango_layout_iter_get_baseline(iter
);
3071 pango_layout_iter_free(iter
);
3072 *descent
= *y
- PANGO_PIXELS(baseline
);
3074 if (externalLeading
) (*externalLeading
) = 0; // ??
3076 g_object_unref (layout
);
3079 bool wxWindowGTK::GTKSetDelayedFocusIfNeeded()
3081 if ( g_delayedFocus
== this )
3083 if ( GTK_WIDGET_REALIZED(m_widget
) )
3085 gtk_widget_grab_focus(m_widget
);
3086 g_delayedFocus
= NULL
;
3095 void wxWindowGTK::SetFocus()
3097 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3100 // don't do anything if we already have focus
3106 // wxWindow::SetFocus() should really set the focus to
3107 // this control, whatever the flags are
3108 if (!GTK_WIDGET_CAN_FOCUS(m_wxwindow
))
3109 GTK_WIDGET_SET_FLAGS(m_wxwindow
, GTK_CAN_FOCUS
);
3111 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow
))
3113 gtk_widget_grab_focus (m_wxwindow
);
3118 // wxWindow::SetFocus() should really set the focus to
3119 // this control, whatever the flags are
3120 if (!GTK_WIDGET_CAN_FOCUS(m_widget
))
3121 GTK_WIDGET_SET_FLAGS(m_widget
, GTK_CAN_FOCUS
);
3123 if (GTK_IS_CONTAINER(m_widget
))
3125 if (GTK_IS_RADIO_BUTTON(m_widget
))
3127 gtk_widget_grab_focus (m_widget
);
3131 gtk_widget_child_focus( m_widget
, GTK_DIR_TAB_FORWARD
);
3134 if (GTK_WIDGET_CAN_FOCUS(m_widget
) && !GTK_WIDGET_HAS_FOCUS (m_widget
) )
3137 if (!GTK_WIDGET_REALIZED(m_widget
))
3139 // we can't set the focus to the widget now so we remember that
3140 // it should be focused and will do it later, during the idle
3141 // time, as soon as we can
3142 wxLogTrace(TRACE_FOCUS
,
3143 _T("Delaying setting focus to %s(%s)"),
3144 GetClassInfo()->GetClassName(), GetLabel().c_str());
3146 g_delayedFocus
= this;
3150 wxLogTrace(TRACE_FOCUS
,
3151 _T("Setting focus to %s(%s)"),
3152 GetClassInfo()->GetClassName(), GetLabel().c_str());
3154 gtk_widget_grab_focus (m_widget
);
3159 wxLogTrace(TRACE_FOCUS
,
3160 _T("Can't set focus to %s(%s)"),
3161 GetClassInfo()->GetClassName(), GetLabel().c_str());
3166 void wxWindowGTK::SetCanFocus(bool canFocus
)
3169 GTK_WIDGET_SET_FLAGS(m_widget
, GTK_CAN_FOCUS
);
3171 GTK_WIDGET_UNSET_FLAGS(m_widget
, GTK_CAN_FOCUS
);
3173 if ( m_wxwindow
&& (m_widget
!= m_wxwindow
) )
3176 GTK_WIDGET_SET_FLAGS(m_wxwindow
, GTK_CAN_FOCUS
);
3178 GTK_WIDGET_UNSET_FLAGS(m_wxwindow
, GTK_CAN_FOCUS
);
3182 bool wxWindowGTK::Reparent( wxWindowBase
*newParentBase
)
3184 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3186 wxWindowGTK
*oldParent
= m_parent
,
3187 *newParent
= (wxWindowGTK
*)newParentBase
;
3189 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3191 if ( !wxWindowBase::Reparent(newParent
) )
3194 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3196 /* prevent GTK from deleting the widget arbitrarily */
3197 gtk_widget_ref( m_widget
);
3201 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3204 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3208 if (GTK_WIDGET_VISIBLE (newParent
->m_widget
))
3210 m_showOnIdle
= true;
3211 gtk_widget_hide( m_widget
);
3214 /* insert GTK representation */
3215 (*(newParent
->m_insertCallback
))(newParent
, this);
3218 /* reverse: prevent GTK from deleting the widget arbitrarily */
3219 gtk_widget_unref( m_widget
);
3221 SetLayoutDirection(wxLayout_Default
);
3226 void wxWindowGTK::DoAddChild(wxWindowGTK
*child
)
3228 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3229 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3234 /* insert GTK representation */
3235 (*m_insertCallback
)(this, child
);
3238 void wxWindowGTK::AddChild(wxWindowBase
*child
)
3240 wxWindowBase::AddChild(child
);
3241 m_dirtyTabOrder
= true;
3242 wxTheApp
->WakeUpIdle();
3245 void wxWindowGTK::RemoveChild(wxWindowBase
*child
)
3247 wxWindowBase::RemoveChild(child
);
3248 m_dirtyTabOrder
= true;
3249 wxTheApp
->WakeUpIdle();
3253 wxLayoutDirection
wxWindowGTK::GTKGetLayout(GtkWidget
*widget
)
3255 return gtk_widget_get_direction(widget
) == GTK_TEXT_DIR_RTL
3256 ? wxLayout_RightToLeft
3257 : wxLayout_LeftToRight
;
3261 void wxWindowGTK::GTKSetLayout(GtkWidget
*widget
, wxLayoutDirection dir
)
3263 wxASSERT_MSG( dir
!= wxLayout_Default
, _T("invalid layout direction") );
3265 gtk_widget_set_direction(widget
,
3266 dir
== wxLayout_RightToLeft
? GTK_TEXT_DIR_RTL
3267 : GTK_TEXT_DIR_LTR
);
3270 wxLayoutDirection
wxWindowGTK::GetLayoutDirection() const
3272 return GTKGetLayout(m_widget
);
3275 void wxWindowGTK::SetLayoutDirection(wxLayoutDirection dir
)
3277 if ( dir
== wxLayout_Default
)
3279 const wxWindow
*const parent
= GetParent();
3282 // inherit layout from parent.
3283 dir
= parent
->GetLayoutDirection();
3285 else // no parent, use global default layout
3287 dir
= wxTheApp
->GetLayoutDirection();
3291 if ( dir
== wxLayout_Default
)
3294 GTKSetLayout(m_widget
, dir
);
3296 if (m_wxwindow
&& (m_wxwindow
!= m_widget
))
3297 GTKSetLayout(m_wxwindow
, dir
);
3301 wxWindowGTK::AdjustForLayoutDirection(wxCoord x
,
3302 wxCoord
WXUNUSED(width
),
3303 wxCoord
WXUNUSED(widthTotal
)) const
3305 // We now mirror the coordinates of RTL windows in wxPizza
3309 void wxWindowGTK::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
3311 wxWindowBase::DoMoveInTabOrder(win
, move
);
3312 m_dirtyTabOrder
= true;
3313 wxTheApp
->WakeUpIdle();
3316 bool wxWindowGTK::DoNavigateIn(int flags
)
3318 if ( flags
& wxNavigationKeyEvent::WinChange
)
3320 wxFAIL_MSG( _T("not implemented") );
3324 else // navigate inside the container
3326 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3327 wxCHECK_MSG( parent
, false, _T("every window must have a TLW parent") );
3329 GtkDirectionType dir
;
3330 dir
= flags
& wxNavigationKeyEvent::IsForward
? GTK_DIR_TAB_FORWARD
3331 : GTK_DIR_TAB_BACKWARD
;
3334 g_signal_emit_by_name(parent
->m_widget
, "focus", dir
, &rc
);
3340 bool wxWindowGTK::GTKWidgetNeedsMnemonic() const
3342 // none needed by default
3346 void wxWindowGTK::GTKWidgetDoSetMnemonic(GtkWidget
* WXUNUSED(w
))
3348 // nothing to do by default since none is needed
3351 void wxWindowGTK::RealizeTabOrder()
3355 if ( !m_children
.empty() )
3357 // we don't only construct the correct focus chain but also use
3358 // this opportunity to update the mnemonic widgets for the widgets
3361 GList
*chain
= NULL
;
3362 wxWindowGTK
* mnemonicWindow
= NULL
;
3364 for ( wxWindowList::const_iterator i
= m_children
.begin();
3365 i
!= m_children
.end();
3368 wxWindowGTK
*win
= *i
;
3370 if ( mnemonicWindow
)
3372 if ( win
->AcceptsFocusFromKeyboard() )
3374 // wxComboBox et al. needs to focus on on a different
3375 // widget than m_widget, so if the main widget isn't
3376 // focusable try the connect widget
3377 GtkWidget
* w
= win
->m_widget
;
3378 if ( !GTK_WIDGET_CAN_FOCUS(w
) )
3380 w
= win
->GetConnectWidget();
3381 if ( !GTK_WIDGET_CAN_FOCUS(w
) )
3387 mnemonicWindow
->GTKWidgetDoSetMnemonic(w
);
3388 mnemonicWindow
= NULL
;
3392 else if ( win
->GTKWidgetNeedsMnemonic() )
3394 mnemonicWindow
= win
;
3397 chain
= g_list_prepend(chain
, win
->m_widget
);
3400 chain
= g_list_reverse(chain
);
3402 gtk_container_set_focus_chain(GTK_CONTAINER(m_wxwindow
), chain
);
3407 gtk_container_unset_focus_chain(GTK_CONTAINER(m_wxwindow
));
3412 void wxWindowGTK::Raise()
3414 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3416 if (m_wxwindow
&& m_wxwindow
->window
)
3418 gdk_window_raise( m_wxwindow
->window
);
3420 else if (m_widget
->window
)
3422 gdk_window_raise( m_widget
->window
);
3426 void wxWindowGTK::Lower()
3428 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3430 if (m_wxwindow
&& m_wxwindow
->window
)
3432 gdk_window_lower( m_wxwindow
->window
);
3434 else if (m_widget
->window
)
3436 gdk_window_lower( m_widget
->window
);
3440 bool wxWindowGTK::SetCursor( const wxCursor
&cursor
)
3442 if ( !wxWindowBase::SetCursor(cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
) )
3450 void wxWindowGTK::GTKUpdateCursor()
3452 wxCursor
cursor(g_globalCursor
.Ok() ? g_globalCursor
: GetCursor());
3455 wxArrayGdkWindows windowsThis
;
3456 GdkWindow
* const winThis
= GTKGetWindow(windowsThis
);
3459 gdk_window_set_cursor(winThis
, cursor
.GetCursor());
3463 const size_t count
= windowsThis
.size();
3464 for ( size_t n
= 0; n
< count
; n
++ )
3466 GdkWindow
*win
= windowsThis
[n
];
3469 wxFAIL_MSG(_T("NULL window returned by GTKGetWindow()?"));
3473 gdk_window_set_cursor(win
, cursor
.GetCursor());
3479 void wxWindowGTK::WarpPointer( int x
, int y
)
3481 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3483 // We provide this function ourselves as it is
3484 // missing in GDK (top of this file).
3486 GdkWindow
*window
= (GdkWindow
*) NULL
;
3488 window
= m_wxwindow
->window
;
3490 window
= GetConnectWidget()->window
;
3493 gdk_window_warp_pointer( window
, x
, y
);
3496 wxWindowGTK::ScrollDir
wxWindowGTK::ScrollDirFromRange(GtkRange
*range
) const
3498 // find the scrollbar which generated the event
3499 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
3501 if ( range
== m_scrollBar
[dir
] )
3502 return (ScrollDir
)dir
;
3505 wxFAIL_MSG( _T("event from unknown scrollbar received") );
3507 return ScrollDir_Max
;
3510 bool wxWindowGTK::DoScrollByUnits(ScrollDir dir
, ScrollUnit unit
, int units
)
3512 bool changed
= false;
3513 GtkRange
* range
= m_scrollBar
[dir
];
3514 if ( range
&& units
)
3516 GtkAdjustment
* adj
= range
->adjustment
;
3517 gdouble inc
= unit
== ScrollUnit_Line
? adj
->step_increment
3518 : adj
->page_increment
;
3520 const int posOld
= int(adj
->value
+ 0.5);
3521 gtk_range_set_value(range
, posOld
+ units
*inc
);
3523 changed
= int(adj
->value
+ 0.5) != posOld
;
3529 bool wxWindowGTK::ScrollLines(int lines
)
3531 return DoScrollByUnits(ScrollDir_Vert
, ScrollUnit_Line
, lines
);
3534 bool wxWindowGTK::ScrollPages(int pages
)
3536 return DoScrollByUnits(ScrollDir_Vert
, ScrollUnit_Page
, pages
);
3539 void wxWindowGTK::Refresh(bool WXUNUSED(eraseBackground
),
3544 if (!m_widget
->window
)
3549 if (m_wxwindow
->window
== NULL
) return;
3551 GdkRectangle gdk_rect
,
3555 gdk_rect
.x
= rect
->x
;
3556 gdk_rect
.y
= rect
->y
;
3557 gdk_rect
.width
= rect
->width
;
3558 gdk_rect
.height
= rect
->height
;
3559 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3560 gdk_rect
.x
= GetClientSize().x
- gdk_rect
.x
- gdk_rect
.width
;
3564 else // invalidate everything
3569 gdk_window_invalidate_rect(m_wxwindow
->window
, p
, true);
3573 void wxWindowGTK::Update()
3577 // when we call Update() we really want to update the window immediately on
3578 // screen, even if it means flushing the entire queue and hence slowing down
3579 // everything -- but it should still be done, it's just that Update() should
3580 // be called very rarely
3584 void wxWindowGTK::GtkUpdate()
3586 if (m_wxwindow
&& m_wxwindow
->window
)
3587 gdk_window_process_updates(m_wxwindow
->window
, false);
3588 if (m_widget
&& m_widget
->window
&& (m_wxwindow
!= m_widget
))
3589 gdk_window_process_updates( m_widget
->window
, FALSE
);
3591 // for consistency with other platforms (and also because it's convenient
3592 // to be able to update an entire TLW by calling Update() only once), we
3593 // should also update all our children here
3594 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3596 node
= node
->GetNext() )
3598 node
->GetData()->GtkUpdate();
3602 bool wxWindowGTK::DoIsExposed( int x
, int y
) const
3604 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
3608 bool wxWindowGTK::DoIsExposed( int x
, int y
, int w
, int h
) const
3610 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3611 return m_updateRegion
.Contains(x
-w
, y
, w
, h
) != wxOutRegion
;
3613 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
3616 void wxWindowGTK::GtkSendPaintEvents()
3620 m_updateRegion
.Clear();
3624 // Clip to paint region in wxClientDC
3625 m_clipPaintRegion
= true;
3627 m_nativeUpdateRegion
= m_updateRegion
;
3629 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3631 // Transform m_updateRegion under RTL
3632 m_updateRegion
.Clear();
3635 gdk_drawable_get_size(m_wxwindow
->window
, &width
, NULL
);
3637 wxRegionIterator
upd( m_nativeUpdateRegion
);
3641 rect
.x
= upd
.GetX();
3642 rect
.y
= upd
.GetY();
3643 rect
.width
= upd
.GetWidth();
3644 rect
.height
= upd
.GetHeight();
3646 rect
.x
= width
- rect
.x
- rect
.width
;
3647 m_updateRegion
.Union( rect
);
3653 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM
))
3655 // find ancestor from which to steal background
3656 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3658 parent
= (wxWindow
*)this;
3660 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
3662 wxRegionIterator
upd( m_nativeUpdateRegion
);
3666 rect
.x
= upd
.GetX();
3667 rect
.y
= upd
.GetY();
3668 rect
.width
= upd
.GetWidth();
3669 rect
.height
= upd
.GetHeight();
3671 gtk_paint_flat_box( parent
->m_widget
->style
,
3673 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
3686 wxWindowDC
dc( (wxWindow
*)this );
3687 dc
.SetClippingRegion( m_updateRegion
);
3689 // Work around gtk-qt <= 0.60 bug whereby the window colour
3691 if (GetBackgroundStyle() == wxBG_STYLE_COLOUR
&& GetBackgroundColour().Ok() && wxSystemOptions::GetOptionInt(wxT("gtk.window.force-background-colour")) == 1)
3693 dc
.SetBackground(wxBrush(GetBackgroundColour()));
3697 wxEraseEvent
erase_event( GetId(), &dc
);
3698 erase_event
.SetEventObject( this );
3700 GetEventHandler()->ProcessEvent(erase_event
);
3703 wxNcPaintEvent
nc_paint_event( GetId() );
3704 nc_paint_event
.SetEventObject( this );
3705 GetEventHandler()->ProcessEvent( nc_paint_event
);
3707 wxPaintEvent
paint_event( GetId() );
3708 paint_event
.SetEventObject( this );
3709 GetEventHandler()->ProcessEvent( paint_event
);
3711 m_clipPaintRegion
= false;
3713 m_updateRegion
.Clear();
3714 m_nativeUpdateRegion
.Clear();
3717 void wxWindowGTK::SetDoubleBuffered( bool on
)
3719 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3722 gtk_widget_set_double_buffered( m_wxwindow
, on
);
3725 bool wxWindowGTK::IsDoubleBuffered() const
3727 return GTK_WIDGET_DOUBLE_BUFFERED( m_wxwindow
);
3730 void wxWindowGTK::ClearBackground()
3732 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3736 void wxWindowGTK::DoSetToolTip( wxToolTip
*tip
)
3738 wxWindowBase::DoSetToolTip(tip
);
3741 m_tooltip
->Apply( (wxWindow
*)this );
3744 void wxWindowGTK::ApplyToolTip( GtkTooltips
*tips
, const gchar
*tip
)
3746 gtk_tooltips_set_tip(tips
, GetConnectWidget(), tip
, NULL
);
3748 #endif // wxUSE_TOOLTIPS
3750 bool wxWindowGTK::SetBackgroundColour( const wxColour
&colour
)
3752 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3754 if (!wxWindowBase::SetBackgroundColour(colour
))
3759 // We need the pixel value e.g. for background clearing.
3760 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3763 // apply style change (forceStyle=true so that new style is applied
3764 // even if the bg colour changed from valid to wxNullColour)
3765 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3766 ApplyWidgetStyle(true);
3771 bool wxWindowGTK::SetForegroundColour( const wxColour
&colour
)
3773 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3775 if (!wxWindowBase::SetForegroundColour(colour
))
3782 // We need the pixel value e.g. for background clearing.
3783 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3786 // apply style change (forceStyle=true so that new style is applied
3787 // even if the bg colour changed from valid to wxNullColour):
3788 ApplyWidgetStyle(true);
3793 PangoContext
*wxWindowGTK::GtkGetPangoDefaultContext()
3795 return gtk_widget_get_pango_context( m_widget
);
3798 GtkRcStyle
*wxWindowGTK::CreateWidgetStyle(bool forceStyle
)
3800 // do we need to apply any changes at all?
3803 !m_foregroundColour
.Ok() && !m_backgroundColour
.Ok() )
3808 GtkRcStyle
*style
= gtk_rc_style_new();
3813 pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
3816 int flagsNormal
= 0,
3819 flagsInsensitive
= 0;
3821 if ( m_foregroundColour
.Ok() )
3823 const GdkColor
*fg
= m_foregroundColour
.GetColor();
3825 style
->fg
[GTK_STATE_NORMAL
] =
3826 style
->text
[GTK_STATE_NORMAL
] = *fg
;
3827 flagsNormal
|= GTK_RC_FG
| GTK_RC_TEXT
;
3829 style
->fg
[GTK_STATE_PRELIGHT
] =
3830 style
->text
[GTK_STATE_PRELIGHT
] = *fg
;
3831 flagsPrelight
|= GTK_RC_FG
| GTK_RC_TEXT
;
3833 style
->fg
[GTK_STATE_ACTIVE
] =
3834 style
->text
[GTK_STATE_ACTIVE
] = *fg
;
3835 flagsActive
|= GTK_RC_FG
| GTK_RC_TEXT
;
3838 if ( m_backgroundColour
.Ok() )
3840 const GdkColor
*bg
= m_backgroundColour
.GetColor();
3842 style
->bg
[GTK_STATE_NORMAL
] =
3843 style
->base
[GTK_STATE_NORMAL
] = *bg
;
3844 flagsNormal
|= GTK_RC_BG
| GTK_RC_BASE
;
3846 style
->bg
[GTK_STATE_PRELIGHT
] =
3847 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
3848 flagsPrelight
|= GTK_RC_BG
| GTK_RC_BASE
;
3850 style
->bg
[GTK_STATE_ACTIVE
] =
3851 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
3852 flagsActive
|= GTK_RC_BG
| GTK_RC_BASE
;
3854 style
->bg
[GTK_STATE_INSENSITIVE
] =
3855 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
3856 flagsInsensitive
|= GTK_RC_BG
| GTK_RC_BASE
;
3859 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)flagsNormal
;
3860 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)flagsPrelight
;
3861 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)flagsActive
;
3862 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)flagsInsensitive
;
3867 void wxWindowGTK::ApplyWidgetStyle(bool forceStyle
)
3869 GtkRcStyle
*style
= CreateWidgetStyle(forceStyle
);
3872 DoApplyWidgetStyle(style
);
3873 gtk_rc_style_unref(style
);
3876 // Style change may affect GTK+'s size calculation:
3877 InvalidateBestSize();
3880 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle
*style
)
3882 wxSuspendStyleEvents
s(static_cast<wxWindow
*>(this));
3885 gtk_widget_modify_style(m_wxwindow
, style
);
3887 gtk_widget_modify_style(m_widget
, style
);
3890 bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style
)
3892 wxWindowBase::SetBackgroundStyle(style
);
3894 if (style
== wxBG_STYLE_CUSTOM
)
3899 window
= m_wxwindow
->window
;
3903 GtkWidget
* const w
= GetConnectWidget();
3904 window
= w
? w
->window
: NULL
;
3909 // Make sure GDK/X11 doesn't refresh the window
3911 gdk_window_set_back_pixmap( window
, None
, False
);
3913 Display
* display
= GDK_WINDOW_DISPLAY(window
);
3916 m_needsStyleChange
= false;
3918 else // window not realized yet
3920 // Do in OnIdle, because the window is not yet available
3921 m_needsStyleChange
= true;
3924 // Don't apply widget style, or we get a grey background
3928 // apply style change (forceStyle=true so that new style is applied
3929 // even if the bg colour changed from valid to wxNullColour):
3930 ApplyWidgetStyle(true);
3935 #if wxUSE_DRAG_AND_DROP
3937 void wxWindowGTK::SetDropTarget( wxDropTarget
*dropTarget
)
3939 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3941 GtkWidget
*dnd_widget
= GetConnectWidget();
3943 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
3945 if (m_dropTarget
) delete m_dropTarget
;
3946 m_dropTarget
= dropTarget
;
3948 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
3951 #endif // wxUSE_DRAG_AND_DROP
3953 GtkWidget
* wxWindowGTK::GetConnectWidget()
3955 GtkWidget
*connect_widget
= m_widget
;
3956 if (m_wxwindow
) connect_widget
= m_wxwindow
;
3958 return connect_widget
;
3961 bool wxWindowGTK::GTKIsOwnWindow(GdkWindow
*window
) const
3963 wxArrayGdkWindows windowsThis
;
3964 GdkWindow
* const winThis
= GTKGetWindow(windowsThis
);
3966 return winThis
? window
== winThis
3967 : windowsThis
.Index(window
) != wxNOT_FOUND
;
3970 GdkWindow
*wxWindowGTK::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
3972 return m_wxwindow
? m_wxwindow
->window
: m_widget
->window
;
3975 bool wxWindowGTK::SetFont( const wxFont
&font
)
3977 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3979 if (!wxWindowBase::SetFont(font
))
3982 // apply style change (forceStyle=true so that new style is applied
3983 // even if the font changed from valid to wxNullFont):
3984 ApplyWidgetStyle(true);
3989 void wxWindowGTK::DoCaptureMouse()
3991 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3993 GdkWindow
*window
= (GdkWindow
*) NULL
;
3995 window
= m_wxwindow
->window
;
3997 window
= GetConnectWidget()->window
;
3999 wxCHECK_RET( window
, _T("CaptureMouse() failed") );
4001 const wxCursor
* cursor
= &m_cursor
;
4003 cursor
= wxSTANDARD_CURSOR
;
4005 gdk_pointer_grab( window
, FALSE
,
4007 (GDK_BUTTON_PRESS_MASK
|
4008 GDK_BUTTON_RELEASE_MASK
|
4009 GDK_POINTER_MOTION_HINT_MASK
|
4010 GDK_POINTER_MOTION_MASK
),
4012 cursor
->GetCursor(),
4013 (guint32
)GDK_CURRENT_TIME
);
4014 g_captureWindow
= this;
4015 g_captureWindowHasMouse
= true;
4018 void wxWindowGTK::DoReleaseMouse()
4020 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4022 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
4024 g_captureWindow
= (wxWindowGTK
*) NULL
;
4026 GdkWindow
*window
= (GdkWindow
*) NULL
;
4028 window
= m_wxwindow
->window
;
4030 window
= GetConnectWidget()->window
;
4035 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
4038 void wxWindowGTK::GTKReleaseMouseAndNotify()
4041 wxMouseCaptureLostEvent
evt(GetId());
4042 evt
.SetEventObject( this );
4043 GetEventHandler()->ProcessEvent( evt
);
4047 wxWindow
*wxWindowBase::GetCapture()
4049 return (wxWindow
*)g_captureWindow
;
4052 bool wxWindowGTK::IsRetained() const
4057 void wxWindowGTK::SetScrollbar(int orient
,
4061 bool WXUNUSED(update
))
4063 const int dir
= ScrollDirFromOrient(orient
);
4064 GtkRange
* const sb
= m_scrollBar
[dir
];
4065 wxCHECK_RET( sb
, _T("this window is not scrollable") );
4069 m_hasScrolling
= true;
4073 // GtkRange requires upper > lower
4078 GtkAdjustment
* const adj
= sb
->adjustment
;
4079 adj
->step_increment
= 1;
4080 adj
->page_increment
=
4081 adj
->page_size
= thumbVisible
;
4084 g_signal_handlers_block_by_func(
4085 sb
, (void*)gtk_scrollbar_value_changed
, this);
4087 gtk_range_set_range(sb
, 0, range
);
4088 m_scrollPos
[dir
] = sb
->adjustment
->value
;
4090 g_signal_handlers_unblock_by_func(
4091 sb
, (void*)gtk_scrollbar_value_changed
, this);
4094 void wxWindowGTK::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
4096 const int dir
= ScrollDirFromOrient(orient
);
4097 GtkRange
* const sb
= m_scrollBar
[dir
];
4098 wxCHECK_RET( sb
, _T("this window is not scrollable") );
4100 // This check is more than an optimization. Without it, the slider
4101 // will not move smoothly while tracking when using wxScrollHelper.
4102 if (GetScrollPos(orient
) != pos
)
4104 g_signal_handlers_block_by_func(
4105 sb
, (void*)gtk_scrollbar_value_changed
, this);
4107 gtk_range_set_value(sb
, pos
);
4108 m_scrollPos
[dir
] = sb
->adjustment
->value
;
4110 g_signal_handlers_unblock_by_func(
4111 sb
, (void*)gtk_scrollbar_value_changed
, this);
4115 int wxWindowGTK::GetScrollThumb(int orient
) const
4117 GtkRange
* const sb
= m_scrollBar
[ScrollDirFromOrient(orient
)];
4118 wxCHECK_MSG( sb
, 0, _T("this window is not scrollable") );
4120 return int(sb
->adjustment
->page_size
);
4123 int wxWindowGTK::GetScrollPos( int orient
) const
4125 GtkRange
* const sb
= m_scrollBar
[ScrollDirFromOrient(orient
)];
4126 wxCHECK_MSG( sb
, 0, _T("this window is not scrollable") );
4128 return int(sb
->adjustment
->value
+ 0.5);
4131 int wxWindowGTK::GetScrollRange( int orient
) const
4133 GtkRange
* const sb
= m_scrollBar
[ScrollDirFromOrient(orient
)];
4134 wxCHECK_MSG( sb
, 0, _T("this window is not scrollable") );
4136 return int(sb
->adjustment
->upper
);
4139 // Determine if increment is the same as +/-x, allowing for some small
4140 // difference due to possible inexactness in floating point arithmetic
4141 static inline bool IsScrollIncrement(double increment
, double x
)
4143 wxASSERT(increment
> 0);
4144 const double tolerance
= 1.0 / 1024;
4145 return fabs(increment
- fabs(x
)) < tolerance
;
4148 wxEventType
wxWindowGTK::GetScrollEventType(GtkRange
* range
)
4152 wxASSERT(range
== m_scrollBar
[0] || range
== m_scrollBar
[1]);
4154 const int barIndex
= range
== m_scrollBar
[1];
4155 GtkAdjustment
* adj
= range
->adjustment
;
4157 const int value
= int(adj
->value
+ 0.5);
4159 // save previous position
4160 const double oldPos
= m_scrollPos
[barIndex
];
4161 // update current position
4162 m_scrollPos
[barIndex
] = adj
->value
;
4163 // If event should be ignored, or integral position has not changed
4164 if (!m_hasVMT
|| g_blockEventsOnDrag
|| value
== int(oldPos
+ 0.5))
4169 wxEventType eventType
= wxEVT_SCROLL_THUMBTRACK
;
4172 // Difference from last change event
4173 const double diff
= adj
->value
- oldPos
;
4174 const bool isDown
= diff
> 0;
4176 if (IsScrollIncrement(adj
->step_increment
, diff
))
4178 eventType
= isDown
? wxEVT_SCROLL_LINEDOWN
: wxEVT_SCROLL_LINEUP
;
4180 else if (IsScrollIncrement(adj
->page_increment
, diff
))
4182 eventType
= isDown
? wxEVT_SCROLL_PAGEDOWN
: wxEVT_SCROLL_PAGEUP
;
4184 else if (m_mouseButtonDown
)
4186 // Assume track event
4187 m_isScrolling
= true;
4193 void wxWindowGTK::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4195 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4197 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4199 // No scrolling requested.
4200 if ((dx
== 0) && (dy
== 0)) return;
4202 m_clipPaintRegion
= true;
4204 WX_PIZZA(m_wxwindow
)->scroll(dx
, dy
);
4206 m_clipPaintRegion
= false;
4209 bool restoreCaret
= (GetCaret() != NULL
&& GetCaret()->IsVisible());
4212 wxRect
caretRect(GetCaret()->GetPosition(), GetCaret()->GetSize());
4214 caretRect
.width
+= dx
;
4217 caretRect
.x
+= dx
; caretRect
.width
-= dx
;
4220 caretRect
.height
+= dy
;
4223 caretRect
.y
+= dy
; caretRect
.height
-= dy
;
4226 RefreshRect(caretRect
);
4228 #endif // wxUSE_CARET
4231 void wxWindowGTK::GtkScrolledWindowSetBorder(GtkWidget
* w
, int wxstyle
)
4233 //RN: Note that static controls usually have no border on gtk, so maybe
4234 //it makes sense to treat that as simply no border at the wx level
4236 if (!(wxstyle
& wxNO_BORDER
) && !(wxstyle
& wxBORDER_STATIC
))
4238 GtkShadowType gtkstyle
;
4240 if(wxstyle
& wxBORDER_RAISED
)
4241 gtkstyle
= GTK_SHADOW_OUT
;
4242 else if (wxstyle
& wxBORDER_SUNKEN
)
4243 gtkstyle
= GTK_SHADOW_IN
;
4246 else if (wxstyle
& wxBORDER_DOUBLE
)
4247 gtkstyle
= GTK_SHADOW_ETCHED_IN
;
4250 gtkstyle
= GTK_SHADOW_IN
;
4252 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(w
),
4257 void wxWindowGTK::SetWindowStyleFlag( long style
)
4259 // Updates the internal variable. NB: Now m_windowStyle bits carry the _new_ style values already
4260 wxWindowBase::SetWindowStyleFlag(style
);
4263 // Find the wxWindow at the current mouse position, also returning the mouse
4265 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4267 pt
= wxGetMousePosition();
4268 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4272 // Get the current mouse position.
4273 wxPoint
wxGetMousePosition()
4275 /* This crashes when used within wxHelpContext,
4276 so we have to use the X-specific implementation below.
4278 GdkModifierType *mask;
4279 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4281 return wxPoint(x, y);
4285 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4287 Display
*display
= windowAtPtr
? GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4288 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4289 Window rootReturn
, childReturn
;
4290 int rootX
, rootY
, winX
, winY
;
4291 unsigned int maskReturn
;
4293 XQueryPointer (display
,
4297 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4298 return wxPoint(rootX
, rootY
);
4302 // Needed for implementing e.g. combobox on wxGTK within a modal dialog.
4303 void wxAddGrab(wxWindow
* window
)
4305 gtk_grab_add( (GtkWidget
*) window
->GetHandle() );
4308 void wxRemoveGrab(wxWindow
* window
)
4310 gtk_grab_remove( (GtkWidget
*) window
->GetHandle() );
4313 GdkWindow
* wxWindowGTK::GTKGetDrawingWindow() const
4315 GdkWindow
* window
= NULL
;
4317 window
= m_wxwindow
->window
;