1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/window.cpp
3 // Purpose: wxWindowGTK implementation
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"
38 #include "wx/gtk/private.h"
39 #include "wx/gtk/private/win_gtk.h"
40 #include <gdk/gdkkeysyms.h>
43 #if !GTK_CHECK_VERSION(2,10,0)
44 // GTK+ can reliably detect Meta key state only since 2.10 when
45 // GDK_META_MASK was introduced -- there wasn't any way to detect it
46 // in older versions. wxGTK used GDK_MOD2_MASK for this purpose, but
47 // GDK_MOD2_MASK is documented as:
49 // the fifth modifier key (it depends on the modifier mapping of the X
50 // server which key is interpreted as this modifier)
52 // In other words, it isn't guaranteed to map to Meta. This is a real
53 // problem: it is common to map NumLock to it (in fact, it's an exception
54 // if the X server _doesn't_ use it for NumLock). So the old code caused
55 // wxKeyEvent::MetaDown() to always return true as long as NumLock was on
56 // on many systems, which broke all applications using
57 // wxKeyEvent::GetModifiers() to check modifiers state (see e.g. here:
58 // http://tinyurl.com/56lsk2).
60 // Because of this, it's better to not detect Meta key state at all than
61 // to detect it incorrectly. Hence the following #define, which causes
62 // m_metaDown to be always set to false.
63 #define GDK_META_MASK 0
66 //-----------------------------------------------------------------------------
67 // documentation on internals
68 //-----------------------------------------------------------------------------
71 I have been asked several times about writing some documentation about
72 the GTK port of wxWidgets, especially its internal structures. Obviously,
73 you cannot understand wxGTK without knowing a little about the GTK, but
74 some more information about what the wxWindow, which is the base class
75 for all other window classes, does seems required as well.
79 What does wxWindow do? It contains the common interface for the following
80 jobs of its descendants:
82 1) Define the rudimentary behaviour common to all window classes, such as
83 resizing, intercepting user input (so as to make it possible to use these
84 events for special purposes in a derived class), window names etc.
86 2) Provide the possibility to contain and manage children, if the derived
87 class is allowed to contain children, which holds true for those window
88 classes which do not display a native GTK widget. To name them, these
89 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
90 work classes are a special case and are handled a bit differently from
91 the rest. The same holds true for the wxNotebook class.
93 3) Provide the possibility to draw into a client area of a window. This,
94 too, only holds true for classes that do not display a native GTK widget
97 4) Provide the entire mechanism for scrolling widgets. This actual inter-
98 face for this is usually in wxScrolledWindow, but the GTK implementation
101 5) A multitude of helper or extra methods for special purposes, such as
102 Drag'n'Drop, managing validators etc.
104 6) Display a border (sunken, raised, simple or none).
106 Normally one might expect, that one wxWidgets window would always correspond
107 to one GTK widget. Under GTK, there is no such all-round widget that has all
108 the functionality. Moreover, the GTK defines a client area as a different
109 widget from the actual widget you are handling. Last but not least some
110 special classes (e.g. wxFrame) handle different categories of widgets and
111 still have the possibility to draw something in the client area.
112 It was therefore required to write a special purpose GTK widget, that would
113 represent a client area in the sense of wxWidgets capable to do the jobs
114 2), 3) and 4). I have written this class and it resides in win_gtk.c of
117 All windows must have a widget, with which they interact with other under-
118 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
119 the wxWindow class has a member variable called m_widget which holds a
120 pointer to this widget. When the window class represents a GTK native widget,
121 this is (in most cases) the only GTK widget the class manages. E.g. the
122 wxStaticText class handles only a GtkLabel widget a pointer to which you
123 can find in m_widget (defined in wxWindow)
125 When the class has a client area for drawing into and for containing children
126 it has to handle the client area widget (of the type wxPizza, defined in
127 win_gtk.cpp), but there could be any number of widgets, handled by a class.
128 The common rule for all windows is only, that the widget that interacts with
129 the rest of GTK must be referenced in m_widget and all other widgets must be
130 children of this widget on the GTK level. The top-most widget, which also
131 represents the client area, must be in the m_wxwindow field and must be of
134 As I said, the window classes that display a GTK native widget only have
135 one widget, so in the case of e.g. the wxButton class m_widget holds a
136 pointer to a GtkButton widget. But windows with client areas (for drawing
137 and children) have a m_widget field that is a pointer to a GtkScrolled-
138 Window and a m_wxwindow field that is pointer to a wxPizza and this
139 one is (in the GTK sense) a child of the GtkScrolledWindow.
141 If the m_wxwindow field is set, then all input to this widget is inter-
142 cepted and sent to the wxWidgets class. If not, all input to the widget
143 that gets pointed to by m_widget gets intercepted and sent to the class.
147 The design of scrolling in wxWidgets is markedly different from that offered
148 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
149 clicking on a scrollbar belonging to scrolled window will inevitably move
150 the window. In wxWidgets, the scrollbar will only emit an event, send this
151 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
152 which actually moves the window and its sub-windows. Note that wxPizza
153 memorizes how much it has been scrolled but that wxWidgets forgets this
154 so that the two coordinates systems have to be kept in synch. This is done
155 in various places using the pizza->m_scroll_x and pizza->m_scroll_y values.
159 Singularly the most broken code in GTK is the code that is supposed to
160 inform subwindows (child windows) about new positions. Very often, duplicate
161 events are sent without changes in size or position, equally often no
162 events are sent at all (All this is due to a bug in the GtkContainer code
163 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
164 GTK's own system and it simply waits for size events for toplevel windows
165 and then iterates down the respective size events to all window. This has
166 the disadvantage that windows might get size events before the GTK widget
167 actually has the reported size. This doesn't normally pose any problem, but
168 the OpenGL drawing routines rely on correct behaviour. Therefore, I have
169 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
170 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
171 window that is used for OpenGL output really has that size (as reported by
176 If someone at some point of time feels the immense desire to have a look at,
177 change or attempt to optimise the Refresh() logic, this person will need an
178 intimate understanding of what "draw" and "expose" events are and what
179 they are used for, in particular when used in connection with GTK's
180 own windowless widgets. Beware.
184 Cursors, too, have been a constant source of pleasure. The main difficulty
185 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
186 for the parent. To prevent this from doing too much harm, SetCursor calls
187 GTKUpdateCursor, which will recursively re-set the cursors of all child windows.
188 Also don't forget that cursors (like much else) are connected to GdkWindows,
189 not GtkWidgets and that the "window" field of a GtkWidget might very well
190 point to the GdkWindow of the parent widget (-> "window-less widget") and
191 that the two obviously have very different meanings.
194 //-----------------------------------------------------------------------------
196 //-----------------------------------------------------------------------------
198 // Don't allow event propagation during drag
199 bool g_blockEventsOnDrag
;
200 // Don't allow mouse event propagation during scroll
201 bool g_blockEventsOnScroll
;
202 extern wxCursor g_globalCursor
;
204 // mouse capture state: the window which has it and if the mouse is currently
206 static wxWindowGTK
*g_captureWindow
= NULL
;
207 static bool g_captureWindowHasMouse
= false;
209 // The window that currently has focus:
210 static wxWindowGTK
*gs_currentFocus
= NULL
;
211 // The window that is scheduled to get focus in the next event loop iteration
212 // or NULL if there's no pending focus change:
213 static wxWindowGTK
*gs_pendingFocus
= NULL
;
215 // the window that has deferred focus-out event pending, if any (see
216 // GTKAddDeferredFocusOut() for details)
217 static wxWindowGTK
*gs_deferredFocusOut
= NULL
;
219 // global variables because GTK+ DnD want to have the
220 // mouse event that caused it
221 GdkEvent
*g_lastMouseEvent
= NULL
;
222 int g_lastButtonNumber
= 0;
224 //-----------------------------------------------------------------------------
226 //-----------------------------------------------------------------------------
228 // the trace mask used for the focus debugging messages
229 #define TRACE_FOCUS wxT("focus")
231 //-----------------------------------------------------------------------------
232 // missing gdk functions
233 //-----------------------------------------------------------------------------
236 gdk_window_warp_pointer (GdkWindow
*window
,
241 window
= gdk_get_default_root_window();
243 if (!GDK_WINDOW_DESTROYED(window
))
245 XWarpPointer (GDK_WINDOW_XDISPLAY(window
),
246 None
, /* not source window -> move from anywhere */
247 GDK_WINDOW_XID(window
), /* dest window */
248 0, 0, 0, 0, /* not source window -> move from anywhere */
254 //-----------------------------------------------------------------------------
255 // "size_request" of m_widget
256 //-----------------------------------------------------------------------------
260 wxgtk_window_size_request_callback(GtkWidget
* WXUNUSED(widget
),
261 GtkRequisition
*requisition
,
265 win
->GetSize( &w
, &h
);
271 requisition
->height
= h
;
272 requisition
->width
= w
;
276 //-----------------------------------------------------------------------------
277 // "expose_event" of m_wxwindow
278 //-----------------------------------------------------------------------------
282 gtk_window_expose_callback( GtkWidget
*,
283 GdkEventExpose
*gdk_event
,
286 if (gdk_event
->window
== win
->GTKGetDrawingWindow())
288 win
->GetUpdateRegion() = wxRegion( gdk_event
->region
);
289 win
->GtkSendPaintEvents();
291 // Let parent window draw window-less widgets
296 #ifndef __WXUNIVERSAL__
297 //-----------------------------------------------------------------------------
298 // "expose_event" from m_wxwindow->parent, for drawing border
299 //-----------------------------------------------------------------------------
303 expose_event_border(GtkWidget
* widget
, GdkEventExpose
* gdk_event
, wxWindow
* win
)
305 if (gdk_event
->window
!= gtk_widget_get_parent_window(win
->m_wxwindow
))
311 const GtkAllocation
& alloc
= win
->m_wxwindow
->allocation
;
312 const int x
= alloc
.x
;
313 const int y
= alloc
.y
;
314 const int w
= alloc
.width
;
315 const int h
= alloc
.height
;
317 if (w
<= 0 || h
<= 0)
320 if (win
->HasFlag(wxBORDER_SIMPLE
))
322 gdk_draw_rectangle(gdk_event
->window
,
323 widget
->style
->black_gc
, false, x
, y
, w
- 1, h
- 1);
327 GtkShadowType shadow
= GTK_SHADOW_IN
;
328 if (win
->HasFlag(wxBORDER_RAISED
))
329 shadow
= GTK_SHADOW_OUT
;
331 // Style detail to use
333 if (win
->m_widget
== win
->m_wxwindow
)
334 // for non-scrollable wxWindows
337 // for scrollable ones
341 win
->m_wxwindow
->style
, gdk_event
->window
, GTK_STATE_NORMAL
,
342 shadow
, NULL
, wxGTKPrivate::GetEntryWidget(), detail
, x
, y
, w
, h
);
348 //-----------------------------------------------------------------------------
349 // "parent_set" from m_wxwindow
350 //-----------------------------------------------------------------------------
354 parent_set(GtkWidget
* widget
, GtkObject
* old_parent
, wxWindow
* win
)
358 g_signal_handlers_disconnect_by_func(
359 old_parent
, (void*)expose_event_border
, win
);
363 g_signal_connect_after(widget
->parent
, "expose_event",
364 G_CALLBACK(expose_event_border
), win
);
368 #endif // !__WXUNIVERSAL__
370 //-----------------------------------------------------------------------------
371 // "key_press_event" from any window
372 //-----------------------------------------------------------------------------
374 // These are used when transforming Ctrl-alpha to ascii values 1-26
375 inline bool wxIsLowerChar(int code
)
377 return (code
>= 'a' && code
<= 'z' );
380 inline bool wxIsUpperChar(int code
)
382 return (code
>= 'A' && code
<= 'Z' );
386 // set WXTRACE to this to see the key event codes on the console
387 #define TRACE_KEYS wxT("keyevent")
389 // translates an X key symbol to WXK_XXX value
391 // if isChar is true it means that the value returned will be used for EVT_CHAR
392 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
393 // for example, while if it is false it means that the value is going to be
394 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
396 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
402 // Shift, Control and Alt don't generate the CHAR events at all
405 key_code
= isChar
? 0 : WXK_SHIFT
;
409 key_code
= isChar
? 0 : WXK_CONTROL
;
417 key_code
= isChar
? 0 : WXK_ALT
;
420 // neither do the toggle modifies
421 case GDK_Scroll_Lock
:
422 key_code
= isChar
? 0 : WXK_SCROLL
;
426 key_code
= isChar
? 0 : WXK_CAPITAL
;
430 key_code
= isChar
? 0 : WXK_NUMLOCK
;
434 // various other special keys
447 case GDK_ISO_Left_Tab
:
454 key_code
= WXK_RETURN
;
458 key_code
= WXK_CLEAR
;
462 key_code
= WXK_PAUSE
;
466 key_code
= WXK_SELECT
;
470 key_code
= WXK_PRINT
;
474 key_code
= WXK_EXECUTE
;
478 key_code
= WXK_ESCAPE
;
481 // cursor and other extended keyboard keys
483 key_code
= WXK_DELETE
;
499 key_code
= WXK_RIGHT
;
506 case GDK_Prior
: // == GDK_Page_Up
507 key_code
= WXK_PAGEUP
;
510 case GDK_Next
: // == GDK_Page_Down
511 key_code
= WXK_PAGEDOWN
;
523 key_code
= WXK_INSERT
;
538 key_code
= (isChar
? '0' : int(WXK_NUMPAD0
)) + keysym
- GDK_KP_0
;
542 key_code
= isChar
? ' ' : int(WXK_NUMPAD_SPACE
);
546 key_code
= isChar
? WXK_TAB
: WXK_NUMPAD_TAB
;
550 key_code
= isChar
? WXK_RETURN
: WXK_NUMPAD_ENTER
;
554 key_code
= isChar
? WXK_F1
: WXK_NUMPAD_F1
;
558 key_code
= isChar
? WXK_F2
: WXK_NUMPAD_F2
;
562 key_code
= isChar
? WXK_F3
: WXK_NUMPAD_F3
;
566 key_code
= isChar
? WXK_F4
: WXK_NUMPAD_F4
;
570 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_HOME
;
574 key_code
= isChar
? WXK_LEFT
: WXK_NUMPAD_LEFT
;
578 key_code
= isChar
? WXK_UP
: WXK_NUMPAD_UP
;
582 key_code
= isChar
? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
586 key_code
= isChar
? WXK_DOWN
: WXK_NUMPAD_DOWN
;
589 case GDK_KP_Prior
: // == GDK_KP_Page_Up
590 key_code
= isChar
? WXK_PAGEUP
: WXK_NUMPAD_PAGEUP
;
593 case GDK_KP_Next
: // == GDK_KP_Page_Down
594 key_code
= isChar
? WXK_PAGEDOWN
: WXK_NUMPAD_PAGEDOWN
;
598 key_code
= isChar
? WXK_END
: WXK_NUMPAD_END
;
602 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_BEGIN
;
606 key_code
= isChar
? WXK_INSERT
: WXK_NUMPAD_INSERT
;
610 key_code
= isChar
? WXK_DELETE
: WXK_NUMPAD_DELETE
;
614 key_code
= isChar
? '=' : int(WXK_NUMPAD_EQUAL
);
617 case GDK_KP_Multiply
:
618 key_code
= isChar
? '*' : int(WXK_NUMPAD_MULTIPLY
);
622 key_code
= isChar
? '+' : int(WXK_NUMPAD_ADD
);
625 case GDK_KP_Separator
:
626 // FIXME: what is this?
627 key_code
= isChar
? '.' : int(WXK_NUMPAD_SEPARATOR
);
630 case GDK_KP_Subtract
:
631 key_code
= isChar
? '-' : int(WXK_NUMPAD_SUBTRACT
);
635 key_code
= isChar
? '.' : int(WXK_NUMPAD_DECIMAL
);
639 key_code
= isChar
? '/' : int(WXK_NUMPAD_DIVIDE
);
656 key_code
= WXK_F1
+ keysym
- GDK_F1
;
666 static inline bool wxIsAsciiKeysym(KeySym ks
)
671 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
673 GdkEventKey
*gdk_event
)
677 GdkModifierType state
;
678 if (gdk_event
->window
)
679 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
681 event
.SetTimestamp( gdk_event
->time
);
682 event
.SetId(win
->GetId());
683 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
684 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
685 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
686 event
.m_metaDown
= (gdk_event
->state
& GDK_META_MASK
) != 0;
687 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
688 event
.m_rawFlags
= 0;
689 wxGetMousePosition( &x
, &y
);
690 win
->ScreenToClient( &x
, &y
);
693 event
.SetEventObject( win
);
698 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
700 GdkEventKey
*gdk_event
)
702 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
703 // but only event->keyval which is quite useless to us, so remember
704 // the last character from GDK_KEY_PRESS and reuse it as last resort
706 // NB: should be MT-safe as we're always called from the main thread only
711 } s_lastKeyPress
= { 0, 0 };
713 KeySym keysym
= gdk_event
->keyval
;
715 wxLogTrace(TRACE_KEYS
, wxT("Key %s event: keysym = %ld"),
716 event
.GetEventType() == wxEVT_KEY_UP
? wxT("release")
720 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
724 // do we have the translation or is it a plain ASCII character?
725 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
727 // we should use keysym if it is ASCII as X does some translations
728 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
729 // which we don't want here (but which we do use for OnChar())
730 if ( !wxIsAsciiKeysym(keysym
) )
732 keysym
= (KeySym
)gdk_event
->string
[0];
735 // we want to always get the same key code when the same key is
736 // pressed regardless of the state of the modifiers, i.e. on a
737 // standard US keyboard pressing '5' or '%' ('5' key with
738 // Shift) should result in the same key code in OnKeyDown():
739 // '5' (although OnChar() will get either '5' or '%').
741 // to do it we first translate keysym to keycode (== scan code)
742 // and then back but always using the lower register
743 Display
*dpy
= (Display
*)wxGetDisplay();
744 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
746 wxLogTrace(TRACE_KEYS
, wxT("\t-> keycode %d"), keycode
);
748 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
750 // use the normalized, i.e. lower register, keysym if we've
752 key_code
= keysymNormalized
? keysymNormalized
: keysym
;
754 // as explained above, we want to have lower register key codes
755 // normally but for the letter keys we want to have the upper ones
757 // NB: don't use XConvertCase() here, we want to do it for letters
759 key_code
= toupper(key_code
);
761 else // non ASCII key, what to do?
763 // by default, ignore it
766 // but if we have cached information from the last KEY_PRESS
767 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
770 if ( keysym
== s_lastKeyPress
.keysym
)
772 key_code
= s_lastKeyPress
.keycode
;
777 if ( gdk_event
->type
== GDK_KEY_PRESS
)
779 // remember it to be reused for KEY_UP event later
780 s_lastKeyPress
.keysym
= keysym
;
781 s_lastKeyPress
.keycode
= key_code
;
785 wxLogTrace(TRACE_KEYS
, wxT("\t-> wxKeyCode %ld"), key_code
);
787 // sending unknown key events doesn't really make sense
791 event
.m_keyCode
= key_code
;
794 event
.m_uniChar
= gdk_keyval_to_unicode(key_code
? key_code
: keysym
);
795 if ( !event
.m_uniChar
&& event
.m_keyCode
<= WXK_DELETE
)
797 // Set Unicode key code to the ASCII equivalent for compatibility. E.g.
798 // let RETURN generate the key event with both key and Unicode key
800 event
.m_uniChar
= event
.m_keyCode
;
802 #endif // wxUSE_UNICODE
804 // now fill all the other fields
805 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
813 GtkIMContext
*context
;
814 GdkEventKey
*lastKeyEvent
;
818 context
= gtk_im_multicontext_new();
823 g_object_unref (context
);
830 // Send wxEVT_CHAR_HOOK event to the parent of the window and if it wasn't
831 // processed, send wxEVT_CHAR to the window itself. Return true if either of
834 SendCharHookAndCharEvents(const wxKeyEvent
& event
, wxWindow
*win
)
836 // wxEVT_CHAR_HOOK must be sent to the top level parent window to allow it
837 // to handle key events in all of its children.
838 wxWindow
* const parent
= wxGetTopLevelParent(win
);
841 // We need to make a copy of the event object because it is
842 // modified while it's handled, notably its WasProcessed() flag
843 // is set after it had been processed once.
844 wxKeyEvent
eventCharHook(event
);
845 eventCharHook
.SetEventType(wxEVT_CHAR_HOOK
);
846 if ( parent
->HandleWindowEvent(eventCharHook
) )
850 // As above, make a copy of the event first.
851 wxKeyEvent
eventChar(event
);
852 eventChar
.SetEventType(wxEVT_CHAR
);
853 return win
->HandleWindowEvent(eventChar
);
856 } // anonymous namespace
860 gtk_window_key_press_callback( GtkWidget
*WXUNUSED(widget
),
861 GdkEventKey
*gdk_event
,
866 if (g_blockEventsOnDrag
)
869 wxKeyEvent
event( wxEVT_KEY_DOWN
);
871 bool return_after_IM
= false;
873 if( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
875 // Emit KEY_DOWN event
876 ret
= win
->HandleWindowEvent( event
);
880 // Return after IM processing as we cannot do
881 // anything with it anyhow.
882 return_after_IM
= true;
885 if (!ret
&& win
->m_imData
)
887 win
->m_imData
->lastKeyEvent
= gdk_event
;
889 // We should let GTK+ IM filter key event first. According to GTK+ 2.0 API
890 // docs, if IM filter returns true, no further processing should be done.
891 // we should send the key_down event anyway.
892 bool intercepted_by_IM
= gtk_im_context_filter_keypress(win
->m_imData
->context
, gdk_event
);
893 win
->m_imData
->lastKeyEvent
= NULL
;
894 if (intercepted_by_IM
)
896 wxLogTrace(TRACE_KEYS
, wxT("Key event intercepted by IM"));
907 wxWindowGTK
*ancestor
= win
;
910 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
913 wxCommandEvent
menu_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
914 ret
= ancestor
->HandleWindowEvent( menu_event
);
918 // if the accelerator wasn't handled as menu event, try
919 // it as button click (for compatibility with other
921 wxCommandEvent
button_event( wxEVT_COMMAND_BUTTON_CLICKED
, command
);
922 ret
= ancestor
->HandleWindowEvent( button_event
);
927 if (ancestor
->IsTopLevel())
929 ancestor
= ancestor
->GetParent();
932 #endif // wxUSE_ACCEL
934 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
935 // will only be sent if it is not in an accelerator table.
939 KeySym keysym
= gdk_event
->keyval
;
940 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
941 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
944 if ( wxIsAsciiKeysym(keysym
) )
947 key_code
= (unsigned char)keysym
;
949 // gdk_event->string is actually deprecated
950 else if ( gdk_event
->length
== 1 )
952 key_code
= (unsigned char)gdk_event
->string
[0];
958 wxLogTrace(TRACE_KEYS
, wxT("Char event: %ld"), key_code
);
960 event
.m_keyCode
= key_code
;
962 // To conform to the docs we need to translate Ctrl-alpha
963 // characters to values in the range 1-26.
964 if ( event
.ControlDown() &&
965 ( wxIsLowerChar(key_code
) || wxIsUpperChar(key_code
) ))
967 if ( wxIsLowerChar(key_code
) )
968 event
.m_keyCode
= key_code
- 'a' + 1;
969 if ( wxIsUpperChar(key_code
) )
970 event
.m_keyCode
= key_code
- 'A' + 1;
972 event
.m_uniChar
= event
.m_keyCode
;
976 ret
= SendCharHookAndCharEvents(event
, win
);
986 gtk_wxwindow_commit_cb (GtkIMContext
* WXUNUSED(context
),
990 wxKeyEvent
event( wxEVT_KEY_DOWN
);
992 // take modifiers, cursor position, timestamp etc. from the last
993 // key_press_event that was fed into Input Method:
994 if (window
->m_imData
->lastKeyEvent
)
996 wxFillOtherKeyEventFields(event
,
997 window
, window
->m_imData
->lastKeyEvent
);
1001 event
.SetEventObject( window
);
1004 const wxString
data(wxGTK_CONV_BACK_SYS(str
));
1008 for( wxString::const_iterator pstr
= data
.begin(); pstr
!= data
.end(); ++pstr
)
1011 event
.m_uniChar
= *pstr
;
1012 // Backward compatible for ISO-8859-1
1013 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1014 wxLogTrace(TRACE_KEYS
, wxT("IM sent character '%c'"), event
.m_uniChar
);
1016 event
.m_keyCode
= (char)*pstr
;
1017 #endif // wxUSE_UNICODE
1019 // To conform to the docs we need to translate Ctrl-alpha
1020 // characters to values in the range 1-26.
1021 if ( event
.ControlDown() &&
1022 ( wxIsLowerChar(*pstr
) || wxIsUpperChar(*pstr
) ))
1024 if ( wxIsLowerChar(*pstr
) )
1025 event
.m_keyCode
= *pstr
- 'a' + 1;
1026 if ( wxIsUpperChar(*pstr
) )
1027 event
.m_keyCode
= *pstr
- 'A' + 1;
1029 event
.m_keyCode
= *pstr
- 'a' + 1;
1031 event
.m_uniChar
= event
.m_keyCode
;
1035 SendCharHookAndCharEvents(event
, window
);
1041 //-----------------------------------------------------------------------------
1042 // "key_release_event" from any window
1043 //-----------------------------------------------------------------------------
1047 gtk_window_key_release_callback( GtkWidget
* WXUNUSED(widget
),
1048 GdkEventKey
*gdk_event
,
1054 if (g_blockEventsOnDrag
)
1057 wxKeyEvent
event( wxEVT_KEY_UP
);
1058 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1060 // unknown key pressed, ignore (the event would be useless anyhow)
1064 return win
->GTKProcessEvent(event
);
1068 // ============================================================================
1070 // ============================================================================
1072 // ----------------------------------------------------------------------------
1073 // mouse event processing helpers
1074 // ----------------------------------------------------------------------------
1076 // init wxMouseEvent with the info from GdkEventXXX struct
1077 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1078 wxMouseEvent
& event
,
1081 event
.SetTimestamp( gdk_event
->time
);
1082 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
1083 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
1084 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
1085 event
.m_metaDown
= (gdk_event
->state
& GDK_META_MASK
) != 0;
1086 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
) != 0;
1087 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
) != 0;
1088 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
) != 0;
1089 event
.m_aux1Down
= (gdk_event
->state
& GDK_BUTTON4_MASK
) != 0;
1090 event
.m_aux2Down
= (gdk_event
->state
& GDK_BUTTON5_MASK
) != 0;
1092 wxPoint pt
= win
->GetClientAreaOrigin();
1093 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1094 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1096 if ((win
->m_wxwindow
) && (win
->GetLayoutDirection() == wxLayout_RightToLeft
))
1098 // origin in the upper right corner
1099 int window_width
= win
->m_wxwindow
->allocation
.width
;
1100 event
.m_x
= window_width
- event
.m_x
;
1103 event
.SetEventObject( win
);
1104 event
.SetId( win
->GetId() );
1105 event
.SetTimestamp( gdk_event
->time
);
1108 static void AdjustEventButtonState(wxMouseEvent
& event
)
1110 // GDK reports the old state of the button for a button press event, but
1111 // for compatibility with MSW and common sense we want m_leftDown be TRUE
1112 // for a LEFT_DOWN event, not FALSE, so we will invert
1113 // left/right/middleDown for the corresponding click events
1115 if ((event
.GetEventType() == wxEVT_LEFT_DOWN
) ||
1116 (event
.GetEventType() == wxEVT_LEFT_DCLICK
) ||
1117 (event
.GetEventType() == wxEVT_LEFT_UP
))
1119 event
.m_leftDown
= !event
.m_leftDown
;
1123 if ((event
.GetEventType() == wxEVT_MIDDLE_DOWN
) ||
1124 (event
.GetEventType() == wxEVT_MIDDLE_DCLICK
) ||
1125 (event
.GetEventType() == wxEVT_MIDDLE_UP
))
1127 event
.m_middleDown
= !event
.m_middleDown
;
1131 if ((event
.GetEventType() == wxEVT_RIGHT_DOWN
) ||
1132 (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) ||
1133 (event
.GetEventType() == wxEVT_RIGHT_UP
))
1135 event
.m_rightDown
= !event
.m_rightDown
;
1140 // find the window to send the mouse event too
1142 wxWindowGTK
*FindWindowForMouseEvent(wxWindowGTK
*win
, wxCoord
& x
, wxCoord
& y
)
1147 if (win
->m_wxwindow
)
1149 wxPizza
* pizza
= WX_PIZZA(win
->m_wxwindow
);
1150 xx
+= pizza
->m_scroll_x
;
1151 yy
+= pizza
->m_scroll_y
;
1154 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
1157 wxWindowGTK
*child
= node
->GetData();
1159 node
= node
->GetNext();
1160 if (!child
->IsShown())
1163 if (child
->GTKIsTransparentForMouse())
1165 // wxStaticBox is transparent in the box itself
1166 int xx1
= child
->m_x
;
1167 int yy1
= child
->m_y
;
1168 int xx2
= child
->m_x
+ child
->m_width
;
1169 int yy2
= child
->m_y
+ child
->m_height
;
1172 if (((xx
>= xx1
) && (xx
<= xx1
+10) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1174 ((xx
>= xx2
-10) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1176 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy1
+10)) ||
1178 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy2
-1) && (yy
<= yy2
)))
1189 if ((child
->m_wxwindow
== NULL
) &&
1190 (child
->m_x
<= xx
) &&
1191 (child
->m_y
<= yy
) &&
1192 (child
->m_x
+child
->m_width
>= xx
) &&
1193 (child
->m_y
+child
->m_height
>= yy
))
1206 // ----------------------------------------------------------------------------
1207 // common event handlers helpers
1208 // ----------------------------------------------------------------------------
1210 bool wxWindowGTK::GTKProcessEvent(wxEvent
& event
) const
1212 // nothing special at this level
1213 return HandleWindowEvent(event
);
1216 bool wxWindowGTK::GTKShouldIgnoreEvent() const
1218 return !m_hasVMT
|| g_blockEventsOnDrag
;
1221 int wxWindowGTK::GTKCallbackCommonPrologue(GdkEventAny
*event
) const
1225 if (g_blockEventsOnDrag
)
1227 if (g_blockEventsOnScroll
)
1230 if (!GTKIsOwnWindow(event
->window
))
1236 // overloads for all GDK event types we use here: we need to have this as
1237 // GdkEventXXX can't be implicitly cast to GdkEventAny even if it, in fact,
1238 // derives from it in the sense that the structs have the same layout
1239 #define wxDEFINE_COMMON_PROLOGUE_OVERLOAD(T) \
1240 static int wxGtkCallbackCommonPrologue(T *event, wxWindowGTK *win) \
1242 return win->GTKCallbackCommonPrologue((GdkEventAny *)event); \
1245 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventButton
)
1246 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventMotion
)
1247 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventCrossing
)
1249 #undef wxDEFINE_COMMON_PROLOGUE_OVERLOAD
1251 #define wxCOMMON_CALLBACK_PROLOGUE(event, win) \
1252 const int rc = wxGtkCallbackCommonPrologue(event, win); \
1256 // all event handlers must have C linkage as they're called from GTK+ C code
1260 //-----------------------------------------------------------------------------
1261 // "button_press_event"
1262 //-----------------------------------------------------------------------------
1265 gtk_window_button_press_callback( GtkWidget
*widget
,
1266 GdkEventButton
*gdk_event
,
1269 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1271 g_lastButtonNumber
= gdk_event
->button
;
1273 // GDK sends surplus button down events
1274 // before a double click event. We
1275 // need to filter these out.
1276 if ((gdk_event
->type
== GDK_BUTTON_PRESS
) && (win
->m_wxwindow
))
1278 GdkEvent
*peek_event
= gdk_event_peek();
1281 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1282 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1284 gdk_event_free( peek_event
);
1289 gdk_event_free( peek_event
);
1294 wxEventType event_type
= wxEVT_NULL
;
1296 if ( gdk_event
->type
== GDK_2BUTTON_PRESS
&&
1297 gdk_event
->button
>= 1 && gdk_event
->button
<= 3 )
1299 // Reset GDK internal timestamp variables in order to disable GDK
1300 // triple click events. GDK will then next time believe no button has
1301 // been clicked just before, and send a normal button click event.
1302 GdkDisplay
* display
= gtk_widget_get_display (widget
);
1303 display
->button_click_time
[1] = 0;
1304 display
->button_click_time
[0] = 0;
1307 if (gdk_event
->button
== 1)
1309 // note that GDK generates triple click events which are not supported
1310 // by wxWidgets but still have to be passed to the app as otherwise
1311 // clicks would simply go missing
1312 switch (gdk_event
->type
)
1314 // we shouldn't get triple clicks at all for GTK2 because we
1315 // suppress them artificially using the code above but we still
1316 // should map them to something for GTK1 and not just ignore them
1317 // as this would lose clicks
1318 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1319 case GDK_BUTTON_PRESS
:
1320 event_type
= wxEVT_LEFT_DOWN
;
1323 case GDK_2BUTTON_PRESS
:
1324 event_type
= wxEVT_LEFT_DCLICK
;
1328 // just to silence gcc warnings
1332 else if (gdk_event
->button
== 2)
1334 switch (gdk_event
->type
)
1336 case GDK_3BUTTON_PRESS
:
1337 case GDK_BUTTON_PRESS
:
1338 event_type
= wxEVT_MIDDLE_DOWN
;
1341 case GDK_2BUTTON_PRESS
:
1342 event_type
= wxEVT_MIDDLE_DCLICK
;
1349 else if (gdk_event
->button
== 3)
1351 switch (gdk_event
->type
)
1353 case GDK_3BUTTON_PRESS
:
1354 case GDK_BUTTON_PRESS
:
1355 event_type
= wxEVT_RIGHT_DOWN
;
1358 case GDK_2BUTTON_PRESS
:
1359 event_type
= wxEVT_RIGHT_DCLICK
;
1367 if ( event_type
== wxEVT_NULL
)
1369 // unknown mouse button or click type
1373 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1375 wxMouseEvent
event( event_type
);
1376 InitMouseEvent( win
, event
, gdk_event
);
1378 AdjustEventButtonState(event
);
1380 // find the correct window to send the event to: it may be a different one
1381 // from the one which got it at GTK+ level because some controls don't have
1382 // their own X window and thus cannot get any events.
1383 if ( !g_captureWindow
)
1384 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1386 // reset the event object and id in case win changed.
1387 event
.SetEventObject( win
);
1388 event
.SetId( win
->GetId() );
1390 bool ret
= win
->GTKProcessEvent( event
);
1391 g_lastMouseEvent
= NULL
;
1395 if ((event_type
== wxEVT_LEFT_DOWN
) && !win
->IsOfStandardClass() &&
1396 (gs_currentFocus
!= win
) /* && win->IsFocusable() */)
1401 if (event_type
== wxEVT_RIGHT_DOWN
)
1403 // generate a "context menu" event: this is similar to right mouse
1404 // click under many GUIs except that it is generated differently
1405 // (right up under MSW, ctrl-click under Mac, right down here) and
1407 // (a) it's a command event and so is propagated to the parent
1408 // (b) under some ports it can be generated from kbd too
1409 // (c) it uses screen coords (because of (a))
1410 wxContextMenuEvent
evtCtx(
1413 win
->ClientToScreen(event
.GetPosition()));
1414 evtCtx
.SetEventObject(win
);
1415 return win
->GTKProcessEvent(evtCtx
);
1421 //-----------------------------------------------------------------------------
1422 // "button_release_event"
1423 //-----------------------------------------------------------------------------
1426 gtk_window_button_release_callback( GtkWidget
*WXUNUSED(widget
),
1427 GdkEventButton
*gdk_event
,
1430 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1432 g_lastButtonNumber
= 0;
1434 wxEventType event_type
= wxEVT_NULL
;
1436 switch (gdk_event
->button
)
1439 event_type
= wxEVT_LEFT_UP
;
1443 event_type
= wxEVT_MIDDLE_UP
;
1447 event_type
= wxEVT_RIGHT_UP
;
1451 // unknown button, don't process
1455 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1457 wxMouseEvent
event( event_type
);
1458 InitMouseEvent( win
, event
, gdk_event
);
1460 AdjustEventButtonState(event
);
1462 if ( !g_captureWindow
)
1463 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1465 // reset the event object and id in case win changed.
1466 event
.SetEventObject( win
);
1467 event
.SetId( win
->GetId() );
1469 bool ret
= win
->GTKProcessEvent(event
);
1471 g_lastMouseEvent
= NULL
;
1476 //-----------------------------------------------------------------------------
1477 // "motion_notify_event"
1478 //-----------------------------------------------------------------------------
1481 gtk_window_motion_notify_callback( GtkWidget
* WXUNUSED(widget
),
1482 GdkEventMotion
*gdk_event
,
1485 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1487 if (gdk_event
->is_hint
)
1491 GdkModifierType state
;
1492 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1497 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1499 wxMouseEvent
event( wxEVT_MOTION
);
1500 InitMouseEvent(win
, event
, gdk_event
);
1502 if ( g_captureWindow
)
1504 // synthesise a mouse enter or leave event if needed
1505 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1506 // This seems to be necessary and actually been added to
1507 // GDK itself in version 2.0.X
1510 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1511 if ( hasMouse
!= g_captureWindowHasMouse
)
1513 // the mouse changed window
1514 g_captureWindowHasMouse
= hasMouse
;
1516 wxMouseEvent
eventM(g_captureWindowHasMouse
? wxEVT_ENTER_WINDOW
1517 : wxEVT_LEAVE_WINDOW
);
1518 InitMouseEvent(win
, eventM
, gdk_event
);
1519 eventM
.SetEventObject(win
);
1520 win
->GTKProcessEvent(eventM
);
1525 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1527 // reset the event object and id in case win changed.
1528 event
.SetEventObject( win
);
1529 event
.SetId( win
->GetId() );
1532 if ( !g_captureWindow
)
1534 wxSetCursorEvent
cevent( event
.m_x
, event
.m_y
);
1535 if (win
->GTKProcessEvent( cevent
))
1537 win
->SetCursor( cevent
.GetCursor() );
1541 bool ret
= win
->GTKProcessEvent(event
);
1543 g_lastMouseEvent
= NULL
;
1548 //-----------------------------------------------------------------------------
1549 // "scroll_event" (mouse wheel event)
1550 //-----------------------------------------------------------------------------
1553 window_scroll_event_hscrollbar(GtkWidget
*, GdkEventScroll
* gdk_event
, wxWindow
* win
)
1555 if (gdk_event
->direction
!= GDK_SCROLL_LEFT
&&
1556 gdk_event
->direction
!= GDK_SCROLL_RIGHT
)
1561 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
1562 InitMouseEvent(win
, event
, gdk_event
);
1564 GtkRange
*range
= win
->m_scrollBar
[wxWindow::ScrollDir_Horz
];
1565 if (!range
) return FALSE
;
1567 if (range
&& GTK_WIDGET_VISIBLE (range
))
1569 GtkAdjustment
*adj
= range
->adjustment
;
1570 gdouble delta
= adj
->step_increment
* 3;
1571 if (gdk_event
->direction
== GDK_SCROLL_LEFT
)
1574 gdouble new_value
= CLAMP (adj
->value
+ delta
, adj
->lower
, adj
->upper
- adj
->page_size
);
1576 gtk_adjustment_set_value (adj
, new_value
);
1585 window_scroll_event(GtkWidget
*, GdkEventScroll
* gdk_event
, wxWindow
* win
)
1587 if (gdk_event
->direction
!= GDK_SCROLL_UP
&&
1588 gdk_event
->direction
!= GDK_SCROLL_DOWN
)
1593 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
1594 InitMouseEvent(win
, event
, gdk_event
);
1596 // FIXME: Get these values from GTK or GDK
1597 event
.m_linesPerAction
= 3;
1598 event
.m_wheelDelta
= 120;
1599 if (gdk_event
->direction
== GDK_SCROLL_UP
)
1600 event
.m_wheelRotation
= 120;
1602 event
.m_wheelRotation
= -120;
1604 if (win
->GTKProcessEvent(event
))
1607 GtkRange
*range
= win
->m_scrollBar
[wxWindow::ScrollDir_Vert
];
1608 if (!range
) return FALSE
;
1610 if (range
&& GTK_WIDGET_VISIBLE (range
))
1612 GtkAdjustment
*adj
= range
->adjustment
;
1613 gdouble delta
= adj
->step_increment
* 3;
1614 if (gdk_event
->direction
== GDK_SCROLL_UP
)
1617 gdouble new_value
= CLAMP (adj
->value
+ delta
, adj
->lower
, adj
->upper
- adj
->page_size
);
1619 gtk_adjustment_set_value (adj
, new_value
);
1627 //-----------------------------------------------------------------------------
1629 //-----------------------------------------------------------------------------
1631 static gboolean
wxgtk_window_popup_menu_callback(GtkWidget
*, wxWindowGTK
* win
)
1633 wxContextMenuEvent
event(wxEVT_CONTEXT_MENU
, win
->GetId(), wxPoint(-1, -1));
1634 event
.SetEventObject(win
);
1635 return win
->GTKProcessEvent(event
);
1638 //-----------------------------------------------------------------------------
1640 //-----------------------------------------------------------------------------
1643 gtk_window_focus_in_callback( GtkWidget
* WXUNUSED(widget
),
1644 GdkEventFocus
*WXUNUSED(event
),
1647 return win
->GTKHandleFocusIn();
1650 //-----------------------------------------------------------------------------
1651 // "focus_out_event"
1652 //-----------------------------------------------------------------------------
1655 gtk_window_focus_out_callback( GtkWidget
* WXUNUSED(widget
),
1656 GdkEventFocus
* WXUNUSED(gdk_event
),
1659 return win
->GTKHandleFocusOut();
1662 //-----------------------------------------------------------------------------
1664 //-----------------------------------------------------------------------------
1667 wx_window_focus_callback(GtkWidget
*widget
,
1668 GtkDirectionType
WXUNUSED(direction
),
1671 // the default handler for focus signal in GtkScrolledWindow sets
1672 // focus to the window itself even if it doesn't accept focus, i.e. has no
1673 // GTK_CAN_FOCUS in its style -- work around this by forcibly preventing
1674 // the signal from reaching gtk_scrolled_window_focus() if we don't have
1675 // any children which might accept focus (we know we don't accept the focus
1676 // ourselves as this signal is only connected in this case)
1677 if ( win
->GetChildren().empty() )
1678 g_signal_stop_emission_by_name(widget
, "focus");
1680 // we didn't change the focus
1684 //-----------------------------------------------------------------------------
1685 // "enter_notify_event"
1686 //-----------------------------------------------------------------------------
1689 gtk_window_enter_callback( GtkWidget
*widget
,
1690 GdkEventCrossing
*gdk_event
,
1693 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1695 // Event was emitted after a grab
1696 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1700 GdkModifierType state
= (GdkModifierType
)0;
1702 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1704 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
1705 InitMouseEvent(win
, event
, gdk_event
);
1706 wxPoint pt
= win
->GetClientAreaOrigin();
1707 event
.m_x
= x
+ pt
.x
;
1708 event
.m_y
= y
+ pt
.y
;
1710 if ( !g_captureWindow
)
1712 wxSetCursorEvent
cevent( event
.m_x
, event
.m_y
);
1713 if (win
->GTKProcessEvent( cevent
))
1715 win
->SetCursor( cevent
.GetCursor() );
1719 return win
->GTKProcessEvent(event
);
1722 //-----------------------------------------------------------------------------
1723 // "leave_notify_event"
1724 //-----------------------------------------------------------------------------
1727 gtk_window_leave_callback( GtkWidget
*widget
,
1728 GdkEventCrossing
*gdk_event
,
1731 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1733 // Event was emitted after an ungrab
1734 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1736 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
1740 GdkModifierType state
= (GdkModifierType
)0;
1742 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1744 InitMouseEvent(win
, event
, gdk_event
);
1746 return win
->GTKProcessEvent(event
);
1749 //-----------------------------------------------------------------------------
1750 // "value_changed" from scrollbar
1751 //-----------------------------------------------------------------------------
1754 gtk_scrollbar_value_changed(GtkRange
* range
, wxWindow
* win
)
1756 wxEventType eventType
= win
->GTKGetScrollEventType(range
);
1757 if (eventType
!= wxEVT_NULL
)
1759 // Convert scroll event type to scrollwin event type
1760 eventType
+= wxEVT_SCROLLWIN_TOP
- wxEVT_SCROLL_TOP
;
1762 // find the scrollbar which generated the event
1763 wxWindowGTK::ScrollDir dir
= win
->ScrollDirFromRange(range
);
1765 // generate the corresponding wx event
1766 const int orient
= wxWindow::OrientFromScrollDir(dir
);
1767 wxScrollWinEvent
event(eventType
, win
->GetScrollPos(orient
), orient
);
1768 event
.SetEventObject(win
);
1770 win
->GTKProcessEvent(event
);
1774 //-----------------------------------------------------------------------------
1775 // "button_press_event" from scrollbar
1776 //-----------------------------------------------------------------------------
1779 gtk_scrollbar_button_press_event(GtkRange
*, GdkEventButton
*, wxWindow
* win
)
1781 g_blockEventsOnScroll
= true;
1782 win
->m_mouseButtonDown
= true;
1787 //-----------------------------------------------------------------------------
1788 // "event_after" from scrollbar
1789 //-----------------------------------------------------------------------------
1792 gtk_scrollbar_event_after(GtkRange
* range
, GdkEvent
* event
, wxWindow
* win
)
1794 if (event
->type
== GDK_BUTTON_RELEASE
)
1796 g_signal_handlers_block_by_func(range
, (void*)gtk_scrollbar_event_after
, win
);
1798 const int orient
= wxWindow::OrientFromScrollDir(
1799 win
->ScrollDirFromRange(range
));
1800 wxScrollWinEvent
evt(wxEVT_SCROLLWIN_THUMBRELEASE
,
1801 win
->GetScrollPos(orient
), orient
);
1802 evt
.SetEventObject(win
);
1803 win
->GTKProcessEvent(evt
);
1807 //-----------------------------------------------------------------------------
1808 // "button_release_event" from scrollbar
1809 //-----------------------------------------------------------------------------
1812 gtk_scrollbar_button_release_event(GtkRange
* range
, GdkEventButton
*, wxWindow
* win
)
1814 g_blockEventsOnScroll
= false;
1815 win
->m_mouseButtonDown
= false;
1816 // If thumb tracking
1817 if (win
->m_isScrolling
)
1819 win
->m_isScrolling
= false;
1820 // Hook up handler to send thumb release event after this emission is finished.
1821 // To allow setting scroll position from event handler, sending event must
1822 // be deferred until after the GtkRange handler for this signal has run
1823 g_signal_handlers_unblock_by_func(range
, (void*)gtk_scrollbar_event_after
, win
);
1829 //-----------------------------------------------------------------------------
1830 // "realize" from m_widget
1831 //-----------------------------------------------------------------------------
1834 gtk_window_realized_callback(GtkWidget
* widget
, wxWindow
* win
)
1838 gtk_im_context_set_client_window( win
->m_imData
->context
,
1839 win
->m_wxwindow
? win
->GTKGetDrawingWindow() : widget
->window
);
1842 // We cannot set colours and fonts before the widget
1843 // been realized, so we do this directly after realization
1844 // or otherwise in idle time
1846 if (win
->m_needsStyleChange
)
1848 win
->SetBackgroundStyle(win
->GetBackgroundStyle());
1849 win
->m_needsStyleChange
= false;
1852 wxWindowCreateEvent
event( win
);
1853 event
.SetEventObject( win
);
1854 win
->GTKProcessEvent( event
);
1856 win
->GTKUpdateCursor(true, false);
1859 //-----------------------------------------------------------------------------
1860 // "size_allocate" from m_wxwindow or m_widget
1861 //-----------------------------------------------------------------------------
1864 size_allocate(GtkWidget
*, GtkAllocation
* alloc
, wxWindow
* win
)
1866 int w
= alloc
->width
;
1867 int h
= alloc
->height
;
1868 if (win
->m_wxwindow
)
1870 int border_x
, border_y
;
1871 WX_PIZZA(win
->m_wxwindow
)->get_border_widths(border_x
, border_y
);
1877 if (win
->m_oldClientWidth
!= w
|| win
->m_oldClientHeight
!= h
)
1879 win
->m_oldClientWidth
= w
;
1880 win
->m_oldClientHeight
= h
;
1881 // this callback can be connected to m_wxwindow,
1882 // so always get size from m_widget->allocation
1883 win
->m_width
= win
->m_widget
->allocation
.width
;
1884 win
->m_height
= win
->m_widget
->allocation
.height
;
1885 if (!win
->m_nativeSizeEvent
)
1887 wxSizeEvent
event(win
->GetSize(), win
->GetId());
1888 event
.SetEventObject(win
);
1889 win
->GTKProcessEvent(event
);
1894 //-----------------------------------------------------------------------------
1896 //-----------------------------------------------------------------------------
1898 #if GTK_CHECK_VERSION(2, 8, 0)
1900 gtk_window_grab_broken( GtkWidget
*,
1901 GdkEventGrabBroken
*event
,
1904 // Mouse capture has been lost involuntarily, notify the application
1905 if(!event
->keyboard
&& wxWindow::GetCapture() == win
)
1907 wxMouseCaptureLostEvent
evt( win
->GetId() );
1908 evt
.SetEventObject( win
);
1909 win
->HandleWindowEvent( evt
);
1915 //-----------------------------------------------------------------------------
1917 //-----------------------------------------------------------------------------
1920 void gtk_window_style_set_callback( GtkWidget
*WXUNUSED(widget
),
1921 GtkStyle
*previous_style
,
1924 if (win
&& previous_style
)
1926 wxSysColourChangedEvent event
;
1927 event
.SetEventObject(win
);
1929 win
->GTKProcessEvent( event
);
1935 // ----------------------------------------------------------------------------
1936 // this wxWindowBase function is implemented here (in platform-specific file)
1937 // because it is static and so couldn't be made virtual
1938 // ----------------------------------------------------------------------------
1940 wxWindow
*wxWindowBase::DoFindFocus()
1942 wxWindowGTK
*focus
= gs_pendingFocus
? gs_pendingFocus
: gs_currentFocus
;
1943 // the cast is necessary when we compile in wxUniversal mode
1944 return static_cast<wxWindow
*>(focus
);
1947 void wxWindowGTK::AddChildGTK(wxWindowGTK
* child
)
1949 wxASSERT_MSG(m_wxwindow
, "Cannot add a child to a window without a client area");
1951 // the window might have been scrolled already, we
1952 // have to adapt the position
1953 wxPizza
* pizza
= WX_PIZZA(m_wxwindow
);
1954 child
->m_x
+= pizza
->m_scroll_x
;
1955 child
->m_y
+= pizza
->m_scroll_y
;
1957 gtk_widget_set_size_request(
1958 child
->m_widget
, child
->m_width
, child
->m_height
);
1959 pizza
->put(child
->m_widget
, child
->m_x
, child
->m_y
);
1962 //-----------------------------------------------------------------------------
1964 //-----------------------------------------------------------------------------
1966 wxWindow
*wxGetActiveWindow()
1968 return wxWindow::FindFocus();
1972 wxMouseState
wxGetMouseState()
1978 GdkModifierType mask
;
1980 gdk_window_get_pointer(NULL
, &x
, &y
, &mask
);
1984 ms
.SetLeftDown((mask
& GDK_BUTTON1_MASK
) != 0);
1985 ms
.SetMiddleDown((mask
& GDK_BUTTON2_MASK
) != 0);
1986 ms
.SetRightDown((mask
& GDK_BUTTON3_MASK
) != 0);
1987 ms
.SetAux1Down((mask
& GDK_BUTTON4_MASK
) != 0);
1988 ms
.SetAux2Down((mask
& GDK_BUTTON5_MASK
) != 0);
1990 ms
.SetControlDown((mask
& GDK_CONTROL_MASK
) != 0);
1991 ms
.SetShiftDown((mask
& GDK_SHIFT_MASK
) != 0);
1992 ms
.SetAltDown((mask
& GDK_MOD1_MASK
) != 0);
1993 ms
.SetMetaDown((mask
& GDK_META_MASK
) != 0);
1998 //-----------------------------------------------------------------------------
2000 //-----------------------------------------------------------------------------
2002 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2004 #ifdef __WXUNIVERSAL__
2005 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2007 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
2008 #endif // __WXUNIVERSAL__/__WXGTK__
2010 void wxWindowGTK::Init()
2015 m_focusWidget
= NULL
;
2025 m_showOnIdle
= false;
2028 m_nativeSizeEvent
= false;
2030 m_isScrolling
= false;
2031 m_mouseButtonDown
= false;
2033 // initialize scrolling stuff
2034 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
2036 m_scrollBar
[dir
] = NULL
;
2037 m_scrollPos
[dir
] = 0;
2041 m_oldClientHeight
= 0;
2043 m_clipPaintRegion
= false;
2045 m_needsStyleChange
= false;
2047 m_cursor
= *wxSTANDARD_CURSOR
;
2050 m_dirtyTabOrder
= false;
2053 wxWindowGTK::wxWindowGTK()
2058 wxWindowGTK::wxWindowGTK( wxWindow
*parent
,
2063 const wxString
&name
)
2067 Create( parent
, id
, pos
, size
, style
, name
);
2070 bool wxWindowGTK::Create( wxWindow
*parent
,
2075 const wxString
&name
)
2077 // Get default border
2078 wxBorder border
= GetBorder(style
);
2080 style
&= ~wxBORDER_MASK
;
2083 if (!PreCreation( parent
, pos
, size
) ||
2084 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2086 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2090 // We should accept the native look
2092 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2093 scroll_class
->scrollbar_spacing
= 0;
2097 m_wxwindow
= wxPizza::New(m_windowStyle
);
2098 #ifndef __WXUNIVERSAL__
2099 if (HasFlag(wxPizza::BORDER_STYLES
))
2101 g_signal_connect(m_wxwindow
, "parent_set",
2102 G_CALLBACK(parent_set
), this);
2105 if (!HasFlag(wxHSCROLL
) && !HasFlag(wxVSCROLL
))
2106 m_widget
= m_wxwindow
;
2109 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
2111 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2113 // There is a conflict with default bindings at GTK+
2114 // level between scrolled windows and notebooks both of which want to use
2115 // Ctrl-PageUp/Down: scrolled windows for scrolling in the horizontal
2116 // direction and notebooks for changing pages -- we decide that if we don't
2117 // have wxHSCROLL style we can safely sacrifice horizontal scrolling if it
2118 // means we can get working keyboard navigation in notebooks
2119 if ( !HasFlag(wxHSCROLL
) )
2122 bindings
= gtk_binding_set_by_class(G_OBJECT_GET_CLASS(m_widget
));
2125 gtk_binding_entry_remove(bindings
, GDK_Page_Up
, GDK_CONTROL_MASK
);
2126 gtk_binding_entry_remove(bindings
, GDK_Page_Down
, GDK_CONTROL_MASK
);
2130 if (HasFlag(wxALWAYS_SHOW_SB
))
2132 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_ALWAYS
, GTK_POLICY_ALWAYS
);
2134 scrolledWindow
->hscrollbar_visible
= TRUE
;
2135 scrolledWindow
->vscrollbar_visible
= TRUE
;
2139 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2142 m_scrollBar
[ScrollDir_Horz
] = GTK_RANGE(scrolledWindow
->hscrollbar
);
2143 m_scrollBar
[ScrollDir_Vert
] = GTK_RANGE(scrolledWindow
->vscrollbar
);
2144 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2145 gtk_range_set_inverted( m_scrollBar
[ScrollDir_Horz
], TRUE
);
2147 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2149 // connect various scroll-related events
2150 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
2152 // these handlers block mouse events to any window during scrolling
2153 // such as motion events and prevent GTK and wxWidgets from fighting
2154 // over where the slider should be
2155 g_signal_connect(m_scrollBar
[dir
], "button_press_event",
2156 G_CALLBACK(gtk_scrollbar_button_press_event
), this);
2157 g_signal_connect(m_scrollBar
[dir
], "button_release_event",
2158 G_CALLBACK(gtk_scrollbar_button_release_event
), this);
2160 gulong handler_id
= g_signal_connect(m_scrollBar
[dir
], "event_after",
2161 G_CALLBACK(gtk_scrollbar_event_after
), this);
2162 g_signal_handler_block(m_scrollBar
[dir
], handler_id
);
2164 // these handlers get notified when scrollbar slider moves
2165 g_signal_connect_after(m_scrollBar
[dir
], "value_changed",
2166 G_CALLBACK(gtk_scrollbar_value_changed
), this);
2169 gtk_widget_show( m_wxwindow
);
2171 g_object_ref(m_widget
);
2174 m_parent
->DoAddChild( this );
2176 m_focusWidget
= m_wxwindow
;
2178 SetCanFocus(AcceptsFocus());
2185 wxWindowGTK::~wxWindowGTK()
2189 if (gs_currentFocus
== this)
2190 gs_currentFocus
= NULL
;
2191 if (gs_pendingFocus
== this)
2192 gs_pendingFocus
= NULL
;
2194 if ( gs_deferredFocusOut
== this )
2195 gs_deferredFocusOut
= NULL
;
2199 // destroy children before destroying this window itself
2202 // unhook focus handlers to prevent stray events being
2203 // propagated to this (soon to be) dead object
2204 if (m_focusWidget
!= NULL
)
2206 g_signal_handlers_disconnect_by_func (m_focusWidget
,
2207 (gpointer
) gtk_window_focus_in_callback
,
2209 g_signal_handlers_disconnect_by_func (m_focusWidget
,
2210 (gpointer
) gtk_window_focus_out_callback
,
2217 // delete before the widgets to avoid a crash on solaris
2220 // avoid problem with GTK+ 2.18 where a frozen window causes the whole
2221 // TLW to be frozen, and if the window is then destroyed, nothing ever
2222 // gets painted again
2228 // Note that gtk_widget_destroy() does not destroy the widget, it just
2229 // emits the "destroy" signal. The widget is not actually destroyed
2230 // until its reference count drops to zero.
2231 gtk_widget_destroy(m_widget
);
2232 // Release our reference, should be the last one
2233 g_object_unref(m_widget
);
2239 bool wxWindowGTK::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2241 if ( GTKNeedsParent() )
2243 wxCHECK_MSG( parent
, false, wxT("Must have non-NULL parent") );
2246 // Use either the given size, or the default if -1 is given.
2247 // See wxWindowBase for these functions.
2248 m_width
= WidthDefault(size
.x
) ;
2249 m_height
= HeightDefault(size
.y
);
2257 void wxWindowGTK::PostCreation()
2259 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2265 // these get reported to wxWidgets -> wxPaintEvent
2267 g_signal_connect (m_wxwindow
, "expose_event",
2268 G_CALLBACK (gtk_window_expose_callback
), this);
2270 if (GetLayoutDirection() == wxLayout_LeftToRight
)
2271 gtk_widget_set_redraw_on_allocate(m_wxwindow
, HasFlag(wxFULL_REPAINT_ON_RESIZE
));
2274 // Create input method handler
2275 m_imData
= new wxGtkIMData
;
2277 // Cannot handle drawing preedited text yet
2278 gtk_im_context_set_use_preedit( m_imData
->context
, FALSE
);
2280 g_signal_connect (m_imData
->context
, "commit",
2281 G_CALLBACK (gtk_wxwindow_commit_cb
), this);
2286 if (!GTK_IS_WINDOW(m_widget
))
2288 if (m_focusWidget
== NULL
)
2289 m_focusWidget
= m_widget
;
2293 g_signal_connect (m_focusWidget
, "focus_in_event",
2294 G_CALLBACK (gtk_window_focus_in_callback
), this);
2295 g_signal_connect (m_focusWidget
, "focus_out_event",
2296 G_CALLBACK (gtk_window_focus_out_callback
), this);
2300 g_signal_connect_after (m_focusWidget
, "focus_in_event",
2301 G_CALLBACK (gtk_window_focus_in_callback
), this);
2302 g_signal_connect_after (m_focusWidget
, "focus_out_event",
2303 G_CALLBACK (gtk_window_focus_out_callback
), this);
2307 if ( !AcceptsFocusFromKeyboard() )
2311 g_signal_connect(m_widget
, "focus",
2312 G_CALLBACK(wx_window_focus_callback
), this);
2315 // connect to the various key and mouse handlers
2317 GtkWidget
*connect_widget
= GetConnectWidget();
2319 ConnectWidget( connect_widget
);
2321 /* We cannot set colours, fonts and cursors before the widget has
2322 been realized, so we do this directly after realization */
2323 g_signal_connect (connect_widget
, "realize",
2324 G_CALLBACK (gtk_window_realized_callback
), this);
2328 g_signal_connect(m_wxwindow
? m_wxwindow
: m_widget
, "size_allocate",
2329 G_CALLBACK(size_allocate
), this);
2332 #if GTK_CHECK_VERSION(2, 8, 0)
2333 if ( gtk_check_version(2,8,0) == NULL
)
2335 // Make sure we can notify the app when mouse capture is lost
2338 g_signal_connect (m_wxwindow
, "grab_broken_event",
2339 G_CALLBACK (gtk_window_grab_broken
), this);
2342 if ( connect_widget
!= m_wxwindow
)
2344 g_signal_connect (connect_widget
, "grab_broken_event",
2345 G_CALLBACK (gtk_window_grab_broken
), this);
2348 #endif // GTK+ >= 2.8
2350 if ( GTKShouldConnectSizeRequest() )
2352 // This is needed if we want to add our windows into native
2353 // GTK controls, such as the toolbar. With this callback, the
2354 // toolbar gets to know the correct size (the one set by the
2355 // programmer). Sadly, it misbehaves for wxComboBox.
2356 g_signal_connect (m_widget
, "size_request",
2357 G_CALLBACK (wxgtk_window_size_request_callback
),
2361 InheritAttributes();
2365 SetLayoutDirection(wxLayout_Default
);
2367 // unless the window was created initially hidden (i.e. Hide() had been
2368 // called before Create()), we should show it at GTK+ level as well
2370 gtk_widget_show( m_widget
);
2373 gulong
wxWindowGTK::GTKConnectWidget(const char *signal
, void (*callback
)())
2375 return g_signal_connect(m_widget
, signal
, callback
, this);
2378 void wxWindowGTK::ConnectWidget( GtkWidget
*widget
)
2380 g_signal_connect (widget
, "key_press_event",
2381 G_CALLBACK (gtk_window_key_press_callback
), this);
2382 g_signal_connect (widget
, "key_release_event",
2383 G_CALLBACK (gtk_window_key_release_callback
), this);
2384 g_signal_connect (widget
, "button_press_event",
2385 G_CALLBACK (gtk_window_button_press_callback
), this);
2386 g_signal_connect (widget
, "button_release_event",
2387 G_CALLBACK (gtk_window_button_release_callback
), this);
2388 g_signal_connect (widget
, "motion_notify_event",
2389 G_CALLBACK (gtk_window_motion_notify_callback
), this);
2391 g_signal_connect (widget
, "scroll_event",
2392 G_CALLBACK (window_scroll_event
), this);
2393 if (m_scrollBar
[ScrollDir_Horz
])
2394 g_signal_connect (m_scrollBar
[ScrollDir_Horz
], "scroll_event",
2395 G_CALLBACK (window_scroll_event_hscrollbar
), this);
2396 if (m_scrollBar
[ScrollDir_Vert
])
2397 g_signal_connect (m_scrollBar
[ScrollDir_Vert
], "scroll_event",
2398 G_CALLBACK (window_scroll_event
), this);
2400 g_signal_connect (widget
, "popup_menu",
2401 G_CALLBACK (wxgtk_window_popup_menu_callback
), this);
2402 g_signal_connect (widget
, "enter_notify_event",
2403 G_CALLBACK (gtk_window_enter_callback
), this);
2404 g_signal_connect (widget
, "leave_notify_event",
2405 G_CALLBACK (gtk_window_leave_callback
), this);
2407 if (IsTopLevel() && m_wxwindow
)
2408 g_signal_connect (m_wxwindow
, "style_set",
2409 G_CALLBACK (gtk_window_style_set_callback
), this);
2412 bool wxWindowGTK::Destroy()
2414 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2418 return wxWindowBase::Destroy();
2421 void wxWindowGTK::DoMoveWindow(int x
, int y
, int width
, int height
)
2423 gtk_widget_set_size_request(m_widget
, width
, height
);
2425 // inform the parent to perform the move
2426 wxASSERT_MSG(m_parent
&& m_parent
->m_wxwindow
,
2427 "the parent window has no client area?");
2428 WX_PIZZA(m_parent
->m_wxwindow
)->move(m_widget
, x
, y
);
2431 void wxWindowGTK::ConstrainSize()
2434 // GPE's window manager doesn't like size hints at all, esp. when the user
2435 // has to use the virtual keyboard, so don't constrain size there
2439 const wxSize minSize
= GetMinSize();
2440 const wxSize maxSize
= GetMaxSize();
2441 if (minSize
.x
> 0 && m_width
< minSize
.x
) m_width
= minSize
.x
;
2442 if (minSize
.y
> 0 && m_height
< minSize
.y
) m_height
= minSize
.y
;
2443 if (maxSize
.x
> 0 && m_width
> maxSize
.x
) m_width
= maxSize
.x
;
2444 if (maxSize
.y
> 0 && m_height
> maxSize
.y
) m_height
= maxSize
.y
;
2448 void wxWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
2450 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2451 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
2453 int currentX
, currentY
;
2454 GetPosition(¤tX
, ¤tY
);
2455 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2457 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2459 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2461 // calculate the best size if we should auto size the window
2462 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
2463 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
2465 const wxSize sizeBest
= GetBestSize();
2466 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
2468 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
2469 height
= sizeBest
.y
;
2472 const wxSize
oldSize(m_width
, m_height
);
2478 if (m_parent
->m_wxwindow
)
2480 wxPizza
* pizza
= WX_PIZZA(m_parent
->m_wxwindow
);
2481 m_x
= x
+ pizza
->m_scroll_x
;
2482 m_y
= y
+ pizza
->m_scroll_y
;
2484 int left_border
= 0;
2485 int right_border
= 0;
2487 int bottom_border
= 0;
2489 /* the default button has a border around it */
2490 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
2492 GtkBorder
*default_border
= NULL
;
2493 gtk_widget_style_get( m_widget
, "default_border", &default_border
, NULL
);
2496 left_border
+= default_border
->left
;
2497 right_border
+= default_border
->right
;
2498 top_border
+= default_border
->top
;
2499 bottom_border
+= default_border
->bottom
;
2500 gtk_border_free( default_border
);
2504 DoMoveWindow( m_x
- left_border
,
2506 m_width
+left_border
+right_border
,
2507 m_height
+top_border
+bottom_border
);
2510 if (m_width
!= oldSize
.x
|| m_height
!= oldSize
.y
)
2512 // update these variables to keep size_allocate handler
2513 // from sending another size event for this change
2514 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
2516 gtk_widget_queue_resize(m_widget
);
2517 if (!m_nativeSizeEvent
)
2519 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
2520 event
.SetEventObject( this );
2521 HandleWindowEvent( event
);
2524 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
2526 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
2527 event
.SetEventObject( this );
2528 HandleWindowEvent( event
);
2532 bool wxWindowGTK::GTKShowFromOnIdle()
2534 if (IsShown() && m_showOnIdle
&& !GTK_WIDGET_VISIBLE (m_widget
))
2536 GtkAllocation alloc
;
2539 alloc
.width
= m_width
;
2540 alloc
.height
= m_height
;
2541 gtk_widget_size_allocate( m_widget
, &alloc
);
2542 gtk_widget_show( m_widget
);
2543 wxShowEvent
eventShow(GetId(), true);
2544 eventShow
.SetEventObject(this);
2545 HandleWindowEvent(eventShow
);
2546 m_showOnIdle
= false;
2553 void wxWindowGTK::OnInternalIdle()
2555 if ( gs_deferredFocusOut
)
2556 GTKHandleDeferredFocusOut();
2558 // Check if we have to show window now
2559 if (GTKShowFromOnIdle()) return;
2561 if ( m_dirtyTabOrder
)
2563 m_dirtyTabOrder
= false;
2567 // Update style if the window was not yet realized when
2568 // SetBackgroundStyle() was called
2569 if (m_needsStyleChange
)
2571 SetBackgroundStyle(GetBackgroundStyle());
2572 m_needsStyleChange
= false;
2575 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
2576 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2579 void wxWindowGTK::DoGetSize( int *width
, int *height
) const
2581 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2583 if (width
) (*width
) = m_width
;
2584 if (height
) (*height
) = m_height
;
2587 void wxWindowGTK::DoSetClientSize( int width
, int height
)
2589 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2591 const wxSize size
= GetSize();
2592 const wxSize clientSize
= GetClientSize();
2593 SetSize(width
+ (size
.x
- clientSize
.x
), height
+ (size
.y
- clientSize
.y
));
2596 void wxWindowGTK::DoGetClientSize( int *width
, int *height
) const
2598 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2605 // if window is scrollable, account for scrollbars
2606 if ( GTK_IS_SCROLLED_WINDOW(m_widget
) )
2608 GtkPolicyType policy
[ScrollDir_Max
];
2609 gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(m_widget
),
2610 &policy
[ScrollDir_Horz
],
2611 &policy
[ScrollDir_Vert
]);
2613 for ( int i
= 0; i
< ScrollDir_Max
; i
++ )
2615 // don't account for the scrollbars we don't have
2616 GtkRange
* const range
= m_scrollBar
[i
];
2620 // nor for the ones we have but don't current show
2621 switch ( policy
[i
] )
2623 case GTK_POLICY_NEVER
:
2624 // never shown so doesn't take any place
2627 case GTK_POLICY_ALWAYS
:
2628 // no checks necessary
2631 case GTK_POLICY_AUTOMATIC
:
2632 // may be shown or not, check
2633 GtkAdjustment
*adj
= gtk_range_get_adjustment(range
);
2634 if ( adj
->upper
<= adj
->page_size
)
2638 GtkScrolledWindowClass
*scroll_class
=
2639 GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2642 gtk_widget_size_request(GTK_WIDGET(range
), &req
);
2643 if (i
== ScrollDir_Horz
)
2644 h
-= req
.height
+ scroll_class
->scrollbar_spacing
;
2646 w
-= req
.width
+ scroll_class
->scrollbar_spacing
;
2650 const wxSize sizeBorders
= DoGetBorderSize();
2660 if (width
) *width
= w
;
2661 if (height
) *height
= h
;
2664 wxSize
wxWindowGTK::DoGetBorderSize() const
2667 return wxWindowBase::DoGetBorderSize();
2670 WX_PIZZA(m_wxwindow
)->get_border_widths(x
, y
);
2672 return 2*wxSize(x
, y
);
2675 void wxWindowGTK::DoGetPosition( int *x
, int *y
) const
2677 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2681 if (!IsTopLevel() && m_parent
&& m_parent
->m_wxwindow
)
2683 wxPizza
* pizza
= WX_PIZZA(m_parent
->m_wxwindow
);
2684 dx
= pizza
->m_scroll_x
;
2685 dy
= pizza
->m_scroll_y
;
2688 if (m_x
== -1 && m_y
== -1)
2690 GdkWindow
*source
= NULL
;
2692 source
= m_wxwindow
->window
;
2694 source
= m_widget
->window
;
2700 gdk_window_get_origin( source
, &org_x
, &org_y
);
2703 m_parent
->ScreenToClient(&org_x
, &org_y
);
2705 const_cast<wxWindowGTK
*>(this)->m_x
= org_x
;
2706 const_cast<wxWindowGTK
*>(this)->m_y
= org_y
;
2710 if (x
) (*x
) = m_x
- dx
;
2711 if (y
) (*y
) = m_y
- dy
;
2714 void wxWindowGTK::DoClientToScreen( int *x
, int *y
) const
2716 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2718 if (!m_widget
->window
) return;
2720 GdkWindow
*source
= NULL
;
2722 source
= m_wxwindow
->window
;
2724 source
= m_widget
->window
;
2728 gdk_window_get_origin( source
, &org_x
, &org_y
);
2732 if (GTK_WIDGET_NO_WINDOW (m_widget
))
2734 org_x
+= m_widget
->allocation
.x
;
2735 org_y
+= m_widget
->allocation
.y
;
2742 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2743 *x
= (GetClientSize().x
- *x
) + org_x
;
2751 void wxWindowGTK::DoScreenToClient( int *x
, int *y
) const
2753 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2755 if (!m_widget
->window
) return;
2757 GdkWindow
*source
= NULL
;
2759 source
= m_wxwindow
->window
;
2761 source
= m_widget
->window
;
2765 gdk_window_get_origin( source
, &org_x
, &org_y
);
2769 if (GTK_WIDGET_NO_WINDOW (m_widget
))
2771 org_x
+= m_widget
->allocation
.x
;
2772 org_y
+= m_widget
->allocation
.y
;
2778 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2779 *x
= (GetClientSize().x
- *x
) - org_x
;
2786 bool wxWindowGTK::Show( bool show
)
2788 if ( !wxWindowBase::Show(show
) )
2794 // notice that we may call Hide() before the window is created and this is
2795 // actually useful to create it hidden initially -- but we can't call
2796 // Show() before it is created
2799 wxASSERT_MSG( !show
, "can't show invalid window" );
2807 // defer until later
2811 gtk_widget_show(m_widget
);
2815 gtk_widget_hide(m_widget
);
2818 wxShowEvent
eventShow(GetId(), show
);
2819 eventShow
.SetEventObject(this);
2820 HandleWindowEvent(eventShow
);
2825 void wxWindowGTK::DoEnable( bool enable
)
2827 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2829 gtk_widget_set_sensitive( m_widget
, enable
);
2830 if (m_wxwindow
&& (m_wxwindow
!= m_widget
))
2831 gtk_widget_set_sensitive( m_wxwindow
, enable
);
2834 int wxWindowGTK::GetCharHeight() const
2836 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
2838 wxFont font
= GetFont();
2839 wxCHECK_MSG( font
.Ok(), 12, wxT("invalid font") );
2841 PangoContext
* context
= gtk_widget_get_pango_context(m_widget
);
2846 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
2847 PangoLayout
*layout
= pango_layout_new(context
);
2848 pango_layout_set_font_description(layout
, desc
);
2849 pango_layout_set_text(layout
, "H", 1);
2850 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
2852 PangoRectangle rect
;
2853 pango_layout_line_get_extents(line
, NULL
, &rect
);
2855 g_object_unref (layout
);
2857 return (int) PANGO_PIXELS(rect
.height
);
2860 int wxWindowGTK::GetCharWidth() const
2862 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
2864 wxFont font
= GetFont();
2865 wxCHECK_MSG( font
.Ok(), 8, wxT("invalid font") );
2867 PangoContext
* context
= gtk_widget_get_pango_context(m_widget
);
2872 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
2873 PangoLayout
*layout
= pango_layout_new(context
);
2874 pango_layout_set_font_description(layout
, desc
);
2875 pango_layout_set_text(layout
, "g", 1);
2876 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
2878 PangoRectangle rect
;
2879 pango_layout_line_get_extents(line
, NULL
, &rect
);
2881 g_object_unref (layout
);
2883 return (int) PANGO_PIXELS(rect
.width
);
2886 void wxWindowGTK::DoGetTextExtent( const wxString
& string
,
2890 int *externalLeading
,
2891 const wxFont
*theFont
) const
2893 wxFont fontToUse
= theFont
? *theFont
: GetFont();
2895 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
2904 PangoContext
*context
= NULL
;
2906 context
= gtk_widget_get_pango_context( m_widget
);
2915 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
2916 PangoLayout
*layout
= pango_layout_new(context
);
2917 pango_layout_set_font_description(layout
, desc
);
2919 const wxCharBuffer data
= wxGTK_CONV( string
);
2921 pango_layout_set_text(layout
, data
, strlen(data
));
2924 PangoRectangle rect
;
2925 pango_layout_get_extents(layout
, NULL
, &rect
);
2927 if (x
) (*x
) = (wxCoord
) PANGO_PIXELS(rect
.width
);
2928 if (y
) (*y
) = (wxCoord
) PANGO_PIXELS(rect
.height
);
2931 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
2932 int baseline
= pango_layout_iter_get_baseline(iter
);
2933 pango_layout_iter_free(iter
);
2934 *descent
= *y
- PANGO_PIXELS(baseline
);
2936 if (externalLeading
) (*externalLeading
) = 0; // ??
2938 g_object_unref (layout
);
2941 void wxWindowGTK::GTKDisableFocusOutEvent()
2943 g_signal_handlers_block_by_func( m_focusWidget
,
2944 (gpointer
) gtk_window_focus_out_callback
, this);
2947 void wxWindowGTK::GTKEnableFocusOutEvent()
2949 g_signal_handlers_unblock_by_func( m_focusWidget
,
2950 (gpointer
) gtk_window_focus_out_callback
, this);
2953 bool wxWindowGTK::GTKHandleFocusIn()
2955 // Disable default focus handling for custom windows since the default GTK+
2956 // handler issues a repaint
2957 const bool retval
= m_wxwindow
? true : false;
2960 // NB: if there's still unprocessed deferred focus-out event (see
2961 // GTKHandleFocusOut() for explanation), we need to process it first so
2962 // that the order of focus events -- focus-out first, then focus-in
2963 // elsewhere -- is preserved
2964 if ( gs_deferredFocusOut
)
2966 if ( GTKNeedsToFilterSameWindowFocus() &&
2967 gs_deferredFocusOut
== this )
2969 // GTK+ focus changed from this wxWindow back to itself, so don't
2970 // emit any events at all
2971 wxLogTrace(TRACE_FOCUS
,
2972 "filtered out spurious focus change within %s(%p, %s)",
2973 GetClassInfo()->GetClassName(), this, GetLabel());
2974 gs_deferredFocusOut
= NULL
;
2978 // otherwise we need to send focus-out first
2979 wxASSERT_MSG ( gs_deferredFocusOut
!= this,
2980 "GTKHandleFocusIn(GTKFocus_Normal) called even though focus changed back to itself - derived class should handle this" );
2981 GTKHandleDeferredFocusOut();
2985 wxLogTrace(TRACE_FOCUS
,
2986 "handling focus_in event for %s(%p, %s)",
2987 GetClassInfo()->GetClassName(), this, GetLabel());
2990 gtk_im_context_focus_in(m_imData
->context
);
2992 gs_currentFocus
= this;
2993 gs_pendingFocus
= NULL
;
2996 // caret needs to be informed about focus change
2997 wxCaret
*caret
= GetCaret();
3000 caret
->OnSetFocus();
3002 #endif // wxUSE_CARET
3004 // Notify the parent keeping track of focus for the kbd navigation
3005 // purposes that we got it.
3006 wxChildFocusEvent
eventChildFocus(static_cast<wxWindow
*>(this));
3007 GTKProcessEvent(eventChildFocus
);
3009 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, GetId());
3010 eventFocus
.SetEventObject(this);
3011 GTKProcessEvent(eventFocus
);
3016 bool wxWindowGTK::GTKHandleFocusOut()
3018 // Disable default focus handling for custom windows since the default GTK+
3019 // handler issues a repaint
3020 const bool retval
= m_wxwindow
? true : false;
3023 // NB: If a control is composed of several GtkWidgets and when focus
3024 // changes from one of them to another within the same wxWindow, we get
3025 // a focus-out event followed by focus-in for another GtkWidget owned
3026 // by the same wx control. We don't want to generate two spurious
3027 // wxEVT_SET_FOCUS events in this case, so we defer sending wx events
3028 // from GTKHandleFocusOut() until we know for sure it's not coming back
3029 // (i.e. in GTKHandleFocusIn() or at idle time).
3030 if ( GTKNeedsToFilterSameWindowFocus() )
3032 wxASSERT_MSG( gs_deferredFocusOut
== NULL
,
3033 "deferred focus out event already pending" );
3034 wxLogTrace(TRACE_FOCUS
,
3035 "deferring focus_out event for %s(%p, %s)",
3036 GetClassInfo()->GetClassName(), this, GetLabel());
3037 gs_deferredFocusOut
= this;
3041 GTKHandleFocusOutNoDeferring();
3046 void wxWindowGTK::GTKHandleFocusOutNoDeferring()
3048 wxLogTrace(TRACE_FOCUS
,
3049 "handling focus_out event for %s(%p, %s)",
3050 GetClassInfo()->GetClassName(), this, GetLabel());
3053 gtk_im_context_focus_out(m_imData
->context
);
3055 if ( gs_currentFocus
!= this )
3057 // Something is terribly wrong, gs_currentFocus is out of sync with the
3058 // real focus. We will reset it to NULL anyway, because after this
3059 // focus-out event is handled, one of the following with happen:
3061 // * either focus will go out of the app altogether, in which case
3062 // gs_currentFocus _should_ be NULL
3064 // * or it goes to another control, in which case focus-in event will
3065 // follow immediately and it will set gs_currentFocus to the right
3067 wxLogDebug("window %s(%p, %s) lost focus even though it didn't have it",
3068 GetClassInfo()->GetClassName(), this, GetLabel());
3070 gs_currentFocus
= NULL
;
3073 // caret needs to be informed about focus change
3074 wxCaret
*caret
= GetCaret();
3077 caret
->OnKillFocus();
3079 #endif // wxUSE_CARET
3081 wxFocusEvent
event( wxEVT_KILL_FOCUS
, GetId() );
3082 event
.SetEventObject( this );
3083 GTKProcessEvent( event
);
3087 void wxWindowGTK::GTKHandleDeferredFocusOut()
3089 // NB: See GTKHandleFocusOut() for explanation. This function is called
3090 // from either GTKHandleFocusIn() or OnInternalIdle() to process
3092 if ( gs_deferredFocusOut
)
3094 wxWindowGTK
*win
= gs_deferredFocusOut
;
3095 gs_deferredFocusOut
= NULL
;
3097 wxLogTrace(TRACE_FOCUS
,
3098 "processing deferred focus_out event for %s(%p, %s)",
3099 win
->GetClassInfo()->GetClassName(), win
, win
->GetLabel());
3101 win
->GTKHandleFocusOutNoDeferring();
3105 void wxWindowGTK::SetFocus()
3107 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3109 // Setting "physical" focus is not immediate in GTK+ and while
3110 // gtk_widget_is_focus ("determines if the widget is the focus widget
3111 // within its toplevel", i.e. returns true for one widget per TLW, not
3112 // globally) returns true immediately after grabbing focus,
3113 // GTK_WIDGET_HAS_FOCUS (which returns true only for the one widget that
3114 // has focus at the moment) takes affect only after the window is shown
3115 // (if it was hidden at the moment of the call) or at the next event loop
3118 // Because we want to FindFocus() call immediately following
3119 // foo->SetFocus() to return foo, we have to keep track of "pending" focus
3121 gs_pendingFocus
= this;
3123 GtkWidget
*widget
= m_wxwindow
? m_wxwindow
: m_focusWidget
;
3125 if ( GTK_IS_CONTAINER(widget
) &&
3126 !GTK_WIDGET_CAN_FOCUS(widget
) )
3128 wxLogTrace(TRACE_FOCUS
,
3129 wxT("Setting focus to a child of %s(%p, %s)"),
3130 GetClassInfo()->GetClassName(), this, GetLabel().c_str());
3131 gtk_widget_child_focus(widget
, GTK_DIR_TAB_FORWARD
);
3135 wxLogTrace(TRACE_FOCUS
,
3136 wxT("Setting focus to %s(%p, %s)"),
3137 GetClassInfo()->GetClassName(), this, GetLabel().c_str());
3138 gtk_widget_grab_focus(widget
);
3142 void wxWindowGTK::SetCanFocus(bool canFocus
)
3145 GTK_WIDGET_SET_FLAGS(m_widget
, GTK_CAN_FOCUS
);
3147 GTK_WIDGET_UNSET_FLAGS(m_widget
, GTK_CAN_FOCUS
);
3149 if ( m_wxwindow
&& (m_widget
!= m_wxwindow
) )
3152 GTK_WIDGET_SET_FLAGS(m_wxwindow
, GTK_CAN_FOCUS
);
3154 GTK_WIDGET_UNSET_FLAGS(m_wxwindow
, GTK_CAN_FOCUS
);
3158 bool wxWindowGTK::Reparent( wxWindowBase
*newParentBase
)
3160 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3162 wxWindowGTK
*oldParent
= m_parent
,
3163 *newParent
= (wxWindowGTK
*)newParentBase
;
3165 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3167 if ( !wxWindowBase::Reparent(newParent
) )
3170 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3173 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3175 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3179 if (GTK_WIDGET_VISIBLE (newParent
->m_widget
))
3181 m_showOnIdle
= true;
3182 gtk_widget_hide( m_widget
);
3184 /* insert GTK representation */
3185 newParent
->AddChildGTK(this);
3188 SetLayoutDirection(wxLayout_Default
);
3193 void wxWindowGTK::DoAddChild(wxWindowGTK
*child
)
3195 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3196 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3201 /* insert GTK representation */
3205 void wxWindowGTK::AddChild(wxWindowBase
*child
)
3207 wxWindowBase::AddChild(child
);
3208 m_dirtyTabOrder
= true;
3209 wxTheApp
->WakeUpIdle();
3212 void wxWindowGTK::RemoveChild(wxWindowBase
*child
)
3214 wxWindowBase::RemoveChild(child
);
3215 m_dirtyTabOrder
= true;
3216 wxTheApp
->WakeUpIdle();
3220 wxLayoutDirection
wxWindowGTK::GTKGetLayout(GtkWidget
*widget
)
3222 return gtk_widget_get_direction(widget
) == GTK_TEXT_DIR_RTL
3223 ? wxLayout_RightToLeft
3224 : wxLayout_LeftToRight
;
3228 void wxWindowGTK::GTKSetLayout(GtkWidget
*widget
, wxLayoutDirection dir
)
3230 wxASSERT_MSG( dir
!= wxLayout_Default
, wxT("invalid layout direction") );
3232 gtk_widget_set_direction(widget
,
3233 dir
== wxLayout_RightToLeft
? GTK_TEXT_DIR_RTL
3234 : GTK_TEXT_DIR_LTR
);
3237 wxLayoutDirection
wxWindowGTK::GetLayoutDirection() const
3239 return GTKGetLayout(m_widget
);
3242 void wxWindowGTK::SetLayoutDirection(wxLayoutDirection dir
)
3244 if ( dir
== wxLayout_Default
)
3246 const wxWindow
*const parent
= GetParent();
3249 // inherit layout from parent.
3250 dir
= parent
->GetLayoutDirection();
3252 else // no parent, use global default layout
3254 dir
= wxTheApp
->GetLayoutDirection();
3258 if ( dir
== wxLayout_Default
)
3261 GTKSetLayout(m_widget
, dir
);
3263 if (m_wxwindow
&& (m_wxwindow
!= m_widget
))
3264 GTKSetLayout(m_wxwindow
, dir
);
3268 wxWindowGTK::AdjustForLayoutDirection(wxCoord x
,
3269 wxCoord
WXUNUSED(width
),
3270 wxCoord
WXUNUSED(widthTotal
)) const
3272 // We now mirror the coordinates of RTL windows in wxPizza
3276 void wxWindowGTK::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
3278 wxWindowBase::DoMoveInTabOrder(win
, move
);
3279 m_dirtyTabOrder
= true;
3280 wxTheApp
->WakeUpIdle();
3283 bool wxWindowGTK::DoNavigateIn(int flags
)
3285 if ( flags
& wxNavigationKeyEvent::WinChange
)
3287 wxFAIL_MSG( wxT("not implemented") );
3291 else // navigate inside the container
3293 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3294 wxCHECK_MSG( parent
, false, wxT("every window must have a TLW parent") );
3296 GtkDirectionType dir
;
3297 dir
= flags
& wxNavigationKeyEvent::IsForward
? GTK_DIR_TAB_FORWARD
3298 : GTK_DIR_TAB_BACKWARD
;
3301 g_signal_emit_by_name(parent
->m_widget
, "focus", dir
, &rc
);
3307 bool wxWindowGTK::GTKWidgetNeedsMnemonic() const
3309 // none needed by default
3313 void wxWindowGTK::GTKWidgetDoSetMnemonic(GtkWidget
* WXUNUSED(w
))
3315 // nothing to do by default since none is needed
3318 void wxWindowGTK::RealizeTabOrder()
3322 if ( !m_children
.empty() )
3324 // we don't only construct the correct focus chain but also use
3325 // this opportunity to update the mnemonic widgets for the widgets
3328 GList
*chain
= NULL
;
3329 wxWindowGTK
* mnemonicWindow
= NULL
;
3331 for ( wxWindowList::const_iterator i
= m_children
.begin();
3332 i
!= m_children
.end();
3335 wxWindowGTK
*win
= *i
;
3337 if ( mnemonicWindow
)
3339 if ( win
->AcceptsFocusFromKeyboard() )
3341 // wxComboBox et al. needs to focus on on a different
3342 // widget than m_widget, so if the main widget isn't
3343 // focusable try the connect widget
3344 GtkWidget
* w
= win
->m_widget
;
3345 if ( !GTK_WIDGET_CAN_FOCUS(w
) )
3347 w
= win
->GetConnectWidget();
3348 if ( !GTK_WIDGET_CAN_FOCUS(w
) )
3354 mnemonicWindow
->GTKWidgetDoSetMnemonic(w
);
3355 mnemonicWindow
= NULL
;
3359 else if ( win
->GTKWidgetNeedsMnemonic() )
3361 mnemonicWindow
= win
;
3364 chain
= g_list_prepend(chain
, win
->m_widget
);
3367 chain
= g_list_reverse(chain
);
3369 gtk_container_set_focus_chain(GTK_CONTAINER(m_wxwindow
), chain
);
3374 gtk_container_unset_focus_chain(GTK_CONTAINER(m_wxwindow
));
3379 void wxWindowGTK::Raise()
3381 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3383 if (m_wxwindow
&& m_wxwindow
->window
)
3385 gdk_window_raise( m_wxwindow
->window
);
3387 else if (m_widget
->window
)
3389 gdk_window_raise( m_widget
->window
);
3393 void wxWindowGTK::Lower()
3395 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3397 if (m_wxwindow
&& m_wxwindow
->window
)
3399 gdk_window_lower( m_wxwindow
->window
);
3401 else if (m_widget
->window
)
3403 gdk_window_lower( m_widget
->window
);
3407 bool wxWindowGTK::SetCursor( const wxCursor
&cursor
)
3409 if ( !wxWindowBase::SetCursor(cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
) )
3417 void wxWindowGTK::GTKUpdateCursor(bool update_self
/*=true*/, bool recurse
/*=true*/)
3421 wxCursor
cursor(g_globalCursor
.Ok() ? g_globalCursor
: GetCursor());
3424 wxArrayGdkWindows windowsThis
;
3425 GdkWindow
* window
= GTKGetWindow(windowsThis
);
3427 gdk_window_set_cursor( window
, cursor
.GetCursor() );
3430 const size_t count
= windowsThis
.size();
3431 for ( size_t n
= 0; n
< count
; n
++ )
3433 GdkWindow
*win
= windowsThis
[n
];
3434 // It can be zero if the window has not been realized yet.
3437 gdk_window_set_cursor(win
, cursor
.GetCursor());
3446 for (wxWindowList::iterator it
= GetChildren().begin(); it
!= GetChildren().end(); ++it
)
3448 (*it
)->GTKUpdateCursor( true );
3453 void wxWindowGTK::WarpPointer( int x
, int y
)
3455 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3457 // We provide this function ourselves as it is
3458 // missing in GDK (top of this file).
3460 GdkWindow
*window
= NULL
;
3462 window
= m_wxwindow
->window
;
3464 window
= GetConnectWidget()->window
;
3467 gdk_window_warp_pointer( window
, x
, y
);
3470 wxWindowGTK::ScrollDir
wxWindowGTK::ScrollDirFromRange(GtkRange
*range
) const
3472 // find the scrollbar which generated the event
3473 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
3475 if ( range
== m_scrollBar
[dir
] )
3476 return (ScrollDir
)dir
;
3479 wxFAIL_MSG( wxT("event from unknown scrollbar received") );
3481 return ScrollDir_Max
;
3484 bool wxWindowGTK::DoScrollByUnits(ScrollDir dir
, ScrollUnit unit
, int units
)
3486 bool changed
= false;
3487 GtkRange
* range
= m_scrollBar
[dir
];
3488 if ( range
&& units
)
3490 GtkAdjustment
* adj
= range
->adjustment
;
3491 gdouble inc
= unit
== ScrollUnit_Line
? adj
->step_increment
3492 : adj
->page_increment
;
3494 const int posOld
= int(adj
->value
+ 0.5);
3495 gtk_range_set_value(range
, posOld
+ units
*inc
);
3497 changed
= int(adj
->value
+ 0.5) != posOld
;
3503 bool wxWindowGTK::ScrollLines(int lines
)
3505 return DoScrollByUnits(ScrollDir_Vert
, ScrollUnit_Line
, lines
);
3508 bool wxWindowGTK::ScrollPages(int pages
)
3510 return DoScrollByUnits(ScrollDir_Vert
, ScrollUnit_Page
, pages
);
3513 void wxWindowGTK::Refresh(bool WXUNUSED(eraseBackground
),
3518 // it is valid to call Refresh() for a window which hasn't been created
3519 // yet, it simply doesn't do anything in this case
3526 gtk_widget_queue_draw_area( m_widget
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3528 gtk_widget_queue_draw( m_widget
);
3532 // Just return if the widget or one of its ancestors isn't mapped
3534 for (w
= m_wxwindow
; w
!= NULL
; w
= w
->parent
)
3535 if (!GTK_WIDGET_MAPPED (w
))
3538 GdkWindow
* window
= GTKGetDrawingWindow();
3542 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3543 x
= GetClientSize().x
- x
- rect
->width
;
3547 r
.width
= rect
->width
;
3548 r
.height
= rect
->height
;
3549 gdk_window_invalidate_rect(window
, &r
, true);
3552 gdk_window_invalidate_rect(window
, NULL
, true);
3556 void wxWindowGTK::Update()
3558 if (m_widget
&& GTK_WIDGET_MAPPED(m_widget
))
3560 GdkDisplay
* display
= gtk_widget_get_display(m_widget
);
3561 // Flush everything out to the server, and wait for it to finish.
3562 // This ensures nothing will overwrite the drawing we are about to do.
3563 gdk_display_sync(display
);
3565 GdkWindow
* window
= GTKGetDrawingWindow();
3567 window
= m_widget
->window
;
3568 gdk_window_process_updates(window
, true);
3570 // Flush again, but no need to wait for it to finish
3571 gdk_display_flush(display
);
3575 bool wxWindowGTK::DoIsExposed( int x
, int y
) const
3577 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
3580 bool wxWindowGTK::DoIsExposed( int x
, int y
, int w
, int h
) const
3582 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3583 return m_updateRegion
.Contains(x
-w
, y
, w
, h
) != wxOutRegion
;
3585 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
3588 void wxWindowGTK::GtkSendPaintEvents()
3592 m_updateRegion
.Clear();
3596 // Clip to paint region in wxClientDC
3597 m_clipPaintRegion
= true;
3599 m_nativeUpdateRegion
= m_updateRegion
;
3601 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3603 // Transform m_updateRegion under RTL
3604 m_updateRegion
.Clear();
3607 gdk_drawable_get_size(m_wxwindow
->window
, &width
, NULL
);
3609 wxRegionIterator
upd( m_nativeUpdateRegion
);
3613 rect
.x
= upd
.GetX();
3614 rect
.y
= upd
.GetY();
3615 rect
.width
= upd
.GetWidth();
3616 rect
.height
= upd
.GetHeight();
3618 rect
.x
= width
- rect
.x
- rect
.width
;
3619 m_updateRegion
.Union( rect
);
3625 switch ( GetBackgroundStyle() )
3627 case wxBG_STYLE_ERASE
:
3629 wxWindowDC
dc( (wxWindow
*)this );
3630 dc
.SetDeviceClippingRegion( m_updateRegion
);
3632 // Work around gtk-qt <= 0.60 bug whereby the window colour
3636 GetOptionInt("gtk.window.force-background-colour") )
3638 dc
.SetBackground(GetBackgroundColour());
3642 wxEraseEvent
erase_event( GetId(), &dc
);
3643 erase_event
.SetEventObject( this );
3645 if ( HandleWindowEvent(erase_event
) )
3647 // background erased, don't do it again
3653 case wxBG_STYLE_SYSTEM
:
3654 if ( GetThemeEnabled() )
3656 // find ancestor from which to steal background
3657 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3659 parent
= (wxWindow
*)this;
3661 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
3663 wxRegionIterator
upd( m_nativeUpdateRegion
);
3667 rect
.x
= upd
.GetX();
3668 rect
.y
= upd
.GetY();
3669 rect
.width
= upd
.GetWidth();
3670 rect
.height
= upd
.GetHeight();
3672 gtk_paint_flat_box( parent
->m_widget
->style
,
3673 GTKGetDrawingWindow(),
3674 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
3687 case wxBG_STYLE_PAINT
:
3688 // nothing to do: window will be painted over in EVT_PAINT
3692 wxFAIL_MSG( "unsupported background style" );
3695 wxNcPaintEvent
nc_paint_event( GetId() );
3696 nc_paint_event
.SetEventObject( this );
3697 HandleWindowEvent( nc_paint_event
);
3699 wxPaintEvent
paint_event( GetId() );
3700 paint_event
.SetEventObject( this );
3701 HandleWindowEvent( paint_event
);
3703 m_clipPaintRegion
= false;
3705 m_updateRegion
.Clear();
3706 m_nativeUpdateRegion
.Clear();
3709 void wxWindowGTK::SetDoubleBuffered( bool on
)
3711 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3714 gtk_widget_set_double_buffered( m_wxwindow
, on
);
3717 bool wxWindowGTK::IsDoubleBuffered() const
3719 return GTK_WIDGET_DOUBLE_BUFFERED( m_wxwindow
);
3722 void wxWindowGTK::ClearBackground()
3724 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3728 void wxWindowGTK::DoSetToolTip( wxToolTip
*tip
)
3730 wxWindowBase::DoSetToolTip(tip
);
3734 m_tooltip
->GTKApply( (wxWindow
*)this );
3738 GtkWidget
*w
= GetConnectWidget();
3739 wxToolTip::GTKApply(w
, NULL
);
3740 #if GTK_CHECK_VERSION(2, 12, 0)
3741 // Just applying NULL doesn't work on 2.12.0, so also use
3742 // gtk_widget_set_has_tooltip. It is part of the new GtkTooltip API
3743 // but seems also to work with the old GtkTooltips.
3744 if (gtk_check_version(2, 12, 0) == NULL
)
3745 gtk_widget_set_has_tooltip(w
, FALSE
);
3750 void wxWindowGTK::GTKApplyToolTip( GtkTooltips
*tips
, const gchar
*tip
)
3752 gtk_tooltips_set_tip(tips
, GetConnectWidget(), tip
, NULL
);
3754 #endif // wxUSE_TOOLTIPS
3756 bool wxWindowGTK::SetBackgroundColour( const wxColour
&colour
)
3758 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3760 if (!wxWindowBase::SetBackgroundColour(colour
))
3765 // We need the pixel value e.g. for background clearing.
3766 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3769 // apply style change (forceStyle=true so that new style is applied
3770 // even if the bg colour changed from valid to wxNullColour)
3771 GTKApplyWidgetStyle(true);
3776 bool wxWindowGTK::SetForegroundColour( const wxColour
&colour
)
3778 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3780 if (!wxWindowBase::SetForegroundColour(colour
))
3787 // We need the pixel value e.g. for background clearing.
3788 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3791 // apply style change (forceStyle=true so that new style is applied
3792 // even if the bg colour changed from valid to wxNullColour):
3793 GTKApplyWidgetStyle(true);
3798 PangoContext
*wxWindowGTK::GTKGetPangoDefaultContext()
3800 return gtk_widget_get_pango_context( m_widget
);
3803 GtkRcStyle
*wxWindowGTK::GTKCreateWidgetStyle(bool forceStyle
)
3805 // do we need to apply any changes at all?
3808 !m_foregroundColour
.Ok() && !m_backgroundColour
.Ok() )
3813 GtkRcStyle
*style
= gtk_rc_style_new();
3818 pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
3821 int flagsNormal
= 0,
3824 flagsInsensitive
= 0;
3826 if ( m_foregroundColour
.Ok() )
3828 const GdkColor
*fg
= m_foregroundColour
.GetColor();
3830 style
->fg
[GTK_STATE_NORMAL
] =
3831 style
->text
[GTK_STATE_NORMAL
] = *fg
;
3832 flagsNormal
|= GTK_RC_FG
| GTK_RC_TEXT
;
3834 style
->fg
[GTK_STATE_PRELIGHT
] =
3835 style
->text
[GTK_STATE_PRELIGHT
] = *fg
;
3836 flagsPrelight
|= GTK_RC_FG
| GTK_RC_TEXT
;
3838 style
->fg
[GTK_STATE_ACTIVE
] =
3839 style
->text
[GTK_STATE_ACTIVE
] = *fg
;
3840 flagsActive
|= GTK_RC_FG
| GTK_RC_TEXT
;
3843 if ( m_backgroundColour
.Ok() )
3845 const GdkColor
*bg
= m_backgroundColour
.GetColor();
3847 style
->bg
[GTK_STATE_NORMAL
] =
3848 style
->base
[GTK_STATE_NORMAL
] = *bg
;
3849 flagsNormal
|= GTK_RC_BG
| GTK_RC_BASE
;
3851 style
->bg
[GTK_STATE_PRELIGHT
] =
3852 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
3853 flagsPrelight
|= GTK_RC_BG
| GTK_RC_BASE
;
3855 style
->bg
[GTK_STATE_ACTIVE
] =
3856 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
3857 flagsActive
|= GTK_RC_BG
| GTK_RC_BASE
;
3859 style
->bg
[GTK_STATE_INSENSITIVE
] =
3860 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
3861 flagsInsensitive
|= GTK_RC_BG
| GTK_RC_BASE
;
3864 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)flagsNormal
;
3865 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)flagsPrelight
;
3866 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)flagsActive
;
3867 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)flagsInsensitive
;
3872 void wxWindowGTK::GTKApplyWidgetStyle(bool forceStyle
)
3874 GtkRcStyle
*style
= GTKCreateWidgetStyle(forceStyle
);
3877 DoApplyWidgetStyle(style
);
3878 gtk_rc_style_unref(style
);
3881 // Style change may affect GTK+'s size calculation:
3882 InvalidateBestSize();
3885 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle
*style
)
3889 // block the signal temporarily to avoid sending
3890 // wxSysColourChangedEvents when we change the colours ourselves
3891 bool unblock
= false;
3895 g_signal_handlers_block_by_func(
3896 m_wxwindow
, (void *)gtk_window_style_set_callback
, this);
3899 gtk_widget_modify_style(m_wxwindow
, style
);
3903 g_signal_handlers_unblock_by_func(
3904 m_wxwindow
, (void *)gtk_window_style_set_callback
, this);
3909 gtk_widget_modify_style(m_widget
, style
);
3913 bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style
)
3915 wxWindowBase::SetBackgroundStyle(style
);
3917 if ( style
== wxBG_STYLE_PAINT
)
3922 window
= GTKGetDrawingWindow();
3926 GtkWidget
* const w
= GetConnectWidget();
3927 window
= w
? w
->window
: NULL
;
3932 // Make sure GDK/X11 doesn't refresh the window
3934 gdk_window_set_back_pixmap( window
, None
, False
);
3936 Display
* display
= GDK_WINDOW_DISPLAY(window
);
3939 m_needsStyleChange
= false;
3941 else // window not realized yet
3943 // Do in OnIdle, because the window is not yet available
3944 m_needsStyleChange
= true;
3947 // Don't apply widget style, or we get a grey background
3951 // apply style change (forceStyle=true so that new style is applied
3952 // even if the bg colour changed from valid to wxNullColour):
3953 GTKApplyWidgetStyle(true);
3959 // ----------------------------------------------------------------------------
3960 // Pop-up menu stuff
3961 // ----------------------------------------------------------------------------
3963 #if wxUSE_MENUS_NATIVE
3967 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
3969 gboolean
* WXUNUSED(whatever
),
3970 gpointer user_data
)
3972 // ensure that the menu appears entirely on screen
3974 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
3976 wxSize sizeScreen
= wxGetDisplaySize();
3977 wxPoint
*pos
= (wxPoint
*)user_data
;
3979 gint xmax
= sizeScreen
.x
- req
.width
,
3980 ymax
= sizeScreen
.y
- req
.height
;
3982 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
3983 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
3987 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3989 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3995 GtkMenuPositionFunc posfunc
;
3996 if ( x
== -1 && y
== -1 )
3998 // use GTK's default positioning algorithm
4004 pos
= ClientToScreen(wxPoint(x
, y
));
4006 posfunc
= wxPopupMenuPositionCallback
;
4009 menu
->m_popupShown
= true;
4011 GTK_MENU(menu
->m_menu
),
4012 NULL
, // parent menu shell
4013 NULL
, // parent menu item
4014 posfunc
, // function to position it
4015 userdata
, // client data
4016 0, // button used to activate it
4017 gtk_get_current_event_time()
4020 while (menu
->m_popupShown
)
4022 gtk_main_iteration();
4028 #endif // wxUSE_MENUS_NATIVE
4030 #if wxUSE_DRAG_AND_DROP
4032 void wxWindowGTK::SetDropTarget( wxDropTarget
*dropTarget
)
4034 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4036 GtkWidget
*dnd_widget
= GetConnectWidget();
4038 if (m_dropTarget
) m_dropTarget
->GtkUnregisterWidget( dnd_widget
);
4040 if (m_dropTarget
) delete m_dropTarget
;
4041 m_dropTarget
= dropTarget
;
4043 if (m_dropTarget
) m_dropTarget
->GtkRegisterWidget( dnd_widget
);
4046 #endif // wxUSE_DRAG_AND_DROP
4048 GtkWidget
* wxWindowGTK::GetConnectWidget()
4050 GtkWidget
*connect_widget
= m_widget
;
4051 if (m_wxwindow
) connect_widget
= m_wxwindow
;
4053 return connect_widget
;
4056 bool wxWindowGTK::GTKIsOwnWindow(GdkWindow
*window
) const
4058 wxArrayGdkWindows windowsThis
;
4059 GdkWindow
* const winThis
= GTKGetWindow(windowsThis
);
4061 return winThis
? window
== winThis
4062 : windowsThis
.Index(window
) != wxNOT_FOUND
;
4065 GdkWindow
*wxWindowGTK::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
4067 return m_wxwindow
? GTKGetDrawingWindow() : m_widget
->window
;
4070 bool wxWindowGTK::SetFont( const wxFont
&font
)
4072 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
4074 if (!wxWindowBase::SetFont(font
))
4077 // apply style change (forceStyle=true so that new style is applied
4078 // even if the font changed from valid to wxNullFont):
4079 GTKApplyWidgetStyle(true);
4084 void wxWindowGTK::DoCaptureMouse()
4086 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4088 GdkWindow
*window
= NULL
;
4090 window
= GTKGetDrawingWindow();
4092 window
= GetConnectWidget()->window
;
4094 wxCHECK_RET( window
, wxT("CaptureMouse() failed") );
4096 const wxCursor
* cursor
= &m_cursor
;
4098 cursor
= wxSTANDARD_CURSOR
;
4100 gdk_pointer_grab( window
, FALSE
,
4102 (GDK_BUTTON_PRESS_MASK
|
4103 GDK_BUTTON_RELEASE_MASK
|
4104 GDK_POINTER_MOTION_HINT_MASK
|
4105 GDK_POINTER_MOTION_MASK
),
4107 cursor
->GetCursor(),
4108 (guint32
)GDK_CURRENT_TIME
);
4109 g_captureWindow
= this;
4110 g_captureWindowHasMouse
= true;
4113 void wxWindowGTK::DoReleaseMouse()
4115 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4117 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
4119 g_captureWindow
= NULL
;
4121 GdkWindow
*window
= NULL
;
4123 window
= GTKGetDrawingWindow();
4125 window
= GetConnectWidget()->window
;
4130 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
4133 void wxWindowGTK::GTKReleaseMouseAndNotify()
4136 wxMouseCaptureLostEvent
evt(GetId());
4137 evt
.SetEventObject( this );
4138 HandleWindowEvent( evt
);
4142 wxWindow
*wxWindowBase::GetCapture()
4144 return (wxWindow
*)g_captureWindow
;
4147 bool wxWindowGTK::IsRetained() const
4152 void wxWindowGTK::SetScrollbar(int orient
,
4156 bool WXUNUSED(update
))
4158 const int dir
= ScrollDirFromOrient(orient
);
4159 GtkRange
* const sb
= m_scrollBar
[dir
];
4160 wxCHECK_RET( sb
, wxT("this window is not scrollable") );
4164 // GtkRange requires upper > lower
4169 GtkAdjustment
* const adj
= sb
->adjustment
;
4170 adj
->step_increment
= 1;
4171 adj
->page_increment
=
4172 adj
->page_size
= thumbVisible
;
4175 g_signal_handlers_block_by_func(
4176 sb
, (void*)gtk_scrollbar_value_changed
, this);
4178 gtk_range_set_range(sb
, 0, range
);
4179 m_scrollPos
[dir
] = sb
->adjustment
->value
;
4181 g_signal_handlers_unblock_by_func(
4182 sb
, (void*)gtk_scrollbar_value_changed
, this);
4185 void wxWindowGTK::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
4187 const int dir
= ScrollDirFromOrient(orient
);
4188 GtkRange
* const sb
= m_scrollBar
[dir
];
4189 wxCHECK_RET( sb
, wxT("this window is not scrollable") );
4191 // This check is more than an optimization. Without it, the slider
4192 // will not move smoothly while tracking when using wxScrollHelper.
4193 if (GetScrollPos(orient
) != pos
)
4195 g_signal_handlers_block_by_func(
4196 sb
, (void*)gtk_scrollbar_value_changed
, this);
4198 gtk_range_set_value(sb
, pos
);
4199 m_scrollPos
[dir
] = sb
->adjustment
->value
;
4201 g_signal_handlers_unblock_by_func(
4202 sb
, (void*)gtk_scrollbar_value_changed
, this);
4206 int wxWindowGTK::GetScrollThumb(int orient
) const
4208 GtkRange
* const sb
= m_scrollBar
[ScrollDirFromOrient(orient
)];
4209 wxCHECK_MSG( sb
, 0, wxT("this window is not scrollable") );
4211 return wxRound(sb
->adjustment
->page_size
);
4214 int wxWindowGTK::GetScrollPos( int orient
) const
4216 GtkRange
* const sb
= m_scrollBar
[ScrollDirFromOrient(orient
)];
4217 wxCHECK_MSG( sb
, 0, wxT("this window is not scrollable") );
4219 return wxRound(sb
->adjustment
->value
);
4222 int wxWindowGTK::GetScrollRange( int orient
) const
4224 GtkRange
* const sb
= m_scrollBar
[ScrollDirFromOrient(orient
)];
4225 wxCHECK_MSG( sb
, 0, wxT("this window is not scrollable") );
4227 return wxRound(sb
->adjustment
->upper
);
4230 // Determine if increment is the same as +/-x, allowing for some small
4231 // difference due to possible inexactness in floating point arithmetic
4232 static inline bool IsScrollIncrement(double increment
, double x
)
4234 wxASSERT(increment
> 0);
4235 const double tolerance
= 1.0 / 1024;
4236 return fabs(increment
- fabs(x
)) < tolerance
;
4239 wxEventType
wxWindowGTK::GTKGetScrollEventType(GtkRange
* range
)
4241 wxASSERT(range
== m_scrollBar
[0] || range
== m_scrollBar
[1]);
4243 const int barIndex
= range
== m_scrollBar
[1];
4244 GtkAdjustment
* adj
= range
->adjustment
;
4246 const int value
= wxRound(adj
->value
);
4248 // save previous position
4249 const double oldPos
= m_scrollPos
[barIndex
];
4250 // update current position
4251 m_scrollPos
[barIndex
] = adj
->value
;
4252 // If event should be ignored, or integral position has not changed
4253 if (!m_hasVMT
|| g_blockEventsOnDrag
|| value
== wxRound(oldPos
))
4258 wxEventType eventType
= wxEVT_SCROLL_THUMBTRACK
;
4261 // Difference from last change event
4262 const double diff
= adj
->value
- oldPos
;
4263 const bool isDown
= diff
> 0;
4265 if (IsScrollIncrement(adj
->step_increment
, diff
))
4267 eventType
= isDown
? wxEVT_SCROLL_LINEDOWN
: wxEVT_SCROLL_LINEUP
;
4269 else if (IsScrollIncrement(adj
->page_increment
, diff
))
4271 eventType
= isDown
? wxEVT_SCROLL_PAGEDOWN
: wxEVT_SCROLL_PAGEUP
;
4273 else if (m_mouseButtonDown
)
4275 // Assume track event
4276 m_isScrolling
= true;
4282 void wxWindowGTK::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4284 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4286 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4288 // No scrolling requested.
4289 if ((dx
== 0) && (dy
== 0)) return;
4291 m_clipPaintRegion
= true;
4293 WX_PIZZA(m_wxwindow
)->scroll(dx
, dy
);
4295 m_clipPaintRegion
= false;
4298 bool restoreCaret
= (GetCaret() != NULL
&& GetCaret()->IsVisible());
4301 wxRect
caretRect(GetCaret()->GetPosition(), GetCaret()->GetSize());
4303 caretRect
.width
+= dx
;
4306 caretRect
.x
+= dx
; caretRect
.width
-= dx
;
4309 caretRect
.height
+= dy
;
4312 caretRect
.y
+= dy
; caretRect
.height
-= dy
;
4315 RefreshRect(caretRect
);
4317 #endif // wxUSE_CARET
4320 void wxWindowGTK::GTKScrolledWindowSetBorder(GtkWidget
* w
, int wxstyle
)
4322 //RN: Note that static controls usually have no border on gtk, so maybe
4323 //it makes sense to treat that as simply no border at the wx level
4325 if (!(wxstyle
& wxNO_BORDER
) && !(wxstyle
& wxBORDER_STATIC
))
4327 GtkShadowType gtkstyle
;
4329 if(wxstyle
& wxBORDER_RAISED
)
4330 gtkstyle
= GTK_SHADOW_OUT
;
4331 else if ((wxstyle
& wxBORDER_SUNKEN
) || (wxstyle
& wxBORDER_THEME
))
4332 gtkstyle
= GTK_SHADOW_IN
;
4335 else if (wxstyle
& wxBORDER_DOUBLE
)
4336 gtkstyle
= GTK_SHADOW_ETCHED_IN
;
4339 gtkstyle
= GTK_SHADOW_IN
;
4341 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(w
),
4346 void wxWindowGTK::SetWindowStyleFlag( long style
)
4348 // Updates the internal variable. NB: Now m_windowStyle bits carry the _new_ style values already
4349 wxWindowBase::SetWindowStyleFlag(style
);
4352 // Find the wxWindow at the current mouse position, also returning the mouse
4354 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4356 pt
= wxGetMousePosition();
4357 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4361 // Get the current mouse position.
4362 wxPoint
wxGetMousePosition()
4364 /* This crashes when used within wxHelpContext,
4365 so we have to use the X-specific implementation below.
4367 GdkModifierType *mask;
4368 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4370 return wxPoint(x, y);
4374 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4376 Display
*display
= windowAtPtr
? GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4377 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4378 Window rootReturn
, childReturn
;
4379 int rootX
, rootY
, winX
, winY
;
4380 unsigned int maskReturn
;
4382 XQueryPointer (display
,
4386 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4387 return wxPoint(rootX
, rootY
);
4391 GdkWindow
* wxWindowGTK::GTKGetDrawingWindow() const
4393 GdkWindow
* window
= NULL
;
4395 window
= m_wxwindow
->window
;
4399 // ----------------------------------------------------------------------------
4401 // ----------------------------------------------------------------------------
4406 // this is called if we attempted to freeze unrealized widget when it finally
4407 // is realized (and so can be frozen):
4408 static void wx_frozen_widget_realize(GtkWidget
* w
, wxWindowGTK
* win
)
4410 wxASSERT( w
&& !GTK_WIDGET_NO_WINDOW(w
) );
4411 wxASSERT( GTK_WIDGET_REALIZED(w
) );
4413 g_signal_handlers_disconnect_by_func
4416 (void*)wx_frozen_widget_realize
,
4420 GdkWindow
* window
= w
->window
;
4421 if (w
== win
->m_wxwindow
)
4422 window
= win
->GTKGetDrawingWindow();
4423 gdk_window_freeze_updates(window
);
4428 void wxWindowGTK::GTKFreezeWidget(GtkWidget
*w
)
4430 if ( !w
|| GTK_WIDGET_NO_WINDOW(w
) )
4431 return; // window-less widget, cannot be frozen
4433 if ( !GTK_WIDGET_REALIZED(w
) )
4435 // we can't thaw unrealized widgets because they don't have GdkWindow,
4436 // so set it up to be done immediately after realization:
4437 g_signal_connect_after
4441 G_CALLBACK(wx_frozen_widget_realize
),
4447 GdkWindow
* window
= w
->window
;
4448 if (w
== m_wxwindow
)
4449 window
= GTKGetDrawingWindow();
4450 gdk_window_freeze_updates(window
);
4453 void wxWindowGTK::GTKThawWidget(GtkWidget
*w
)
4455 if ( !w
|| GTK_WIDGET_NO_WINDOW(w
) )
4456 return; // window-less widget, cannot be frozen
4458 if ( !GTK_WIDGET_REALIZED(w
) )
4460 // the widget wasn't realized yet, no need to thaw
4461 g_signal_handlers_disconnect_by_func
4464 (void*)wx_frozen_widget_realize
,
4470 GdkWindow
* window
= w
->window
;
4471 if (w
== m_wxwindow
)
4472 window
= GTKGetDrawingWindow();
4473 gdk_window_thaw_updates(window
);
4476 void wxWindowGTK::DoFreeze()
4478 GTKFreezeWidget(m_widget
);
4479 if ( m_wxwindow
&& m_widget
!= m_wxwindow
)
4480 GTKFreezeWidget(m_wxwindow
);
4483 void wxWindowGTK::DoThaw()
4485 GTKThawWidget(m_widget
);
4486 if ( m_wxwindow
&& m_widget
!= m_wxwindow
)
4487 GTKThawWidget(m_wxwindow
);