1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/window.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Julian Smart
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
14 #define XWarpPointer XWARPPOINTER
17 #include "wx/window.h"
22 #include "wx/toplevel.h"
23 #include "wx/dcclient.h"
25 #include "wx/settings.h"
26 #include "wx/msgdlg.h"
31 #include "wx/tooltip.h"
33 #include "wx/fontutil.h"
34 #include "wx/sysopt.h"
37 #include "wx/thread.h"
42 #include "wx/gtk/private.h"
43 #include "wx/gtk/win_gtk.h"
44 #include <gdk/gdkkeysyms.h>
47 //-----------------------------------------------------------------------------
48 // documentation on internals
49 //-----------------------------------------------------------------------------
52 I have been asked several times about writing some documentation about
53 the GTK port of wxWidgets, especially its internal structures. Obviously,
54 you cannot understand wxGTK without knowing a little about the GTK, but
55 some more information about what the wxWindow, which is the base class
56 for all other window classes, does seems required as well.
60 What does wxWindow do? It contains the common interface for the following
61 jobs of its descendants:
63 1) Define the rudimentary behaviour common to all window classes, such as
64 resizing, intercepting user input (so as to make it possible to use these
65 events for special purposes in a derived class), window names etc.
67 2) Provide the possibility to contain and manage children, if the derived
68 class is allowed to contain children, which holds true for those window
69 classes which do not display a native GTK widget. To name them, these
70 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
71 work classes are a special case and are handled a bit differently from
72 the rest. The same holds true for the wxNotebook class.
74 3) Provide the possibility to draw into a client area of a window. This,
75 too, only holds true for classes that do not display a native GTK widget
78 4) Provide the entire mechanism for scrolling widgets. This actual inter-
79 face for this is usually in wxScrolledWindow, but the GTK implementation
82 5) A multitude of helper or extra methods for special purposes, such as
83 Drag'n'Drop, managing validators etc.
85 6) Display a border (sunken, raised, simple or none).
87 Normally one might expect, that one wxWidgets window would always correspond
88 to one GTK widget. Under GTK, there is no such all-round widget that has all
89 the functionality. Moreover, the GTK defines a client area as a different
90 widget from the actual widget you are handling. Last but not least some
91 special classes (e.g. wxFrame) handle different categories of widgets and
92 still have the possibility to draw something in the client area.
93 It was therefore required to write a special purpose GTK widget, that would
94 represent a client area in the sense of wxWidgets capable to do the jobs
95 2), 3) and 4). I have written this class and it resides in win_gtk.c of
98 All windows must have a widget, with which they interact with other under-
99 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
100 the wxWindow class has a member variable called m_widget which holds a
101 pointer to this widget. When the window class represents a GTK native widget,
102 this is (in most cases) the only GTK widget the class manages. E.g. the
103 wxStaticText class handles only a GtkLabel widget a pointer to which you
104 can find in m_widget (defined in wxWindow)
106 When the class has a client area for drawing into and for containing children
107 it has to handle the client area widget (of the type wxPizza, defined in
108 win_gtk.cpp), but there could be any number of widgets, handled by a class.
109 The common rule for all windows is only, that the widget that interacts with
110 the rest of GTK must be referenced in m_widget and all other widgets must be
111 children of this widget on the GTK level. The top-most widget, which also
112 represents the client area, must be in the m_wxwindow field and must be of
115 As I said, the window classes that display a GTK native widget only have
116 one widget, so in the case of e.g. the wxButton class m_widget holds a
117 pointer to a GtkButton widget. But windows with client areas (for drawing
118 and children) have a m_widget field that is a pointer to a GtkScrolled-
119 Window and a m_wxwindow field that is pointer to a wxPizza and this
120 one is (in the GTK sense) a child of the GtkScrolledWindow.
122 If the m_wxwindow field is set, then all input to this widget is inter-
123 cepted and sent to the wxWidgets class. If not, all input to the widget
124 that gets pointed to by m_widget gets intercepted and sent to the class.
128 The design of scrolling in wxWidgets is markedly different from that offered
129 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
130 clicking on a scrollbar belonging to scrolled window will inevitably move
131 the window. In wxWidgets, the scrollbar will only emit an event, send this
132 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
133 which actually moves the window and its sub-windows. Note that wxPizza
134 memorizes how much it has been scrolled but that wxWidgets forgets this
135 so that the two coordinates systems have to be kept in synch. This is done
136 in various places using the pizza->m_scroll_x and pizza->m_scroll_y values.
140 Singularly the most broken code in GTK is the code that is supposed to
141 inform subwindows (child windows) about new positions. Very often, duplicate
142 events are sent without changes in size or position, equally often no
143 events are sent at all (All this is due to a bug in the GtkContainer code
144 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
145 GTK's own system and it simply waits for size events for toplevel windows
146 and then iterates down the respective size events to all window. This has
147 the disadvantage that windows might get size events before the GTK widget
148 actually has the reported size. This doesn't normally pose any problem, but
149 the OpenGL drawing routines rely on correct behaviour. Therefore, I have
150 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
151 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
152 window that is used for OpenGL output really has that size (as reported by
157 If someone at some point of time feels the immense desire to have a look at,
158 change or attempt to optimise the Refresh() logic, this person will need an
159 intimate understanding of what "draw" and "expose" events are and what
160 they are used for, in particular when used in connection with GTK's
161 own windowless widgets. Beware.
165 Cursors, too, have been a constant source of pleasure. The main difficulty
166 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
167 for the parent. To prevent this from doing too much harm, I use idle time
168 to set the cursor over and over again, starting from the toplevel windows
169 and ending with the youngest generation (speaking of parent and child windows).
170 Also don't forget that cursors (like much else) are connected to GdkWindows,
171 not GtkWidgets and that the "window" field of a GtkWidget might very well
172 point to the GdkWindow of the parent widget (-> "window-less widget") and
173 that the two obviously have very different meanings.
177 //-----------------------------------------------------------------------------
179 //-----------------------------------------------------------------------------
181 // Don't allow event propagation during drag
182 bool g_blockEventsOnDrag
;
183 // Don't allow mouse event propagation during scroll
184 bool g_blockEventsOnScroll
;
185 extern wxCursor g_globalCursor
;
187 // mouse capture state: the window which has it and if the mouse is currently
189 static wxWindowGTK
*g_captureWindow
= (wxWindowGTK
*) NULL
;
190 static bool g_captureWindowHasMouse
= false;
192 wxWindowGTK
*g_focusWindow
= (wxWindowGTK
*) NULL
;
194 // the last window which had the focus - this is normally never NULL (except
195 // if we never had focus at all) as even when g_focusWindow is NULL it still
196 // keeps its previous value
197 wxWindowGTK
*g_focusWindowLast
= (wxWindowGTK
*) NULL
;
199 // If a window get the focus set but has not been realized
200 // yet, defer setting the focus to idle time.
201 wxWindowGTK
*g_delayedFocus
= (wxWindowGTK
*) NULL
;
203 // global variables because GTK+ DnD want to have the
204 // mouse event that caused it
205 GdkEvent
*g_lastMouseEvent
= (GdkEvent
*) NULL
;
206 int g_lastButtonNumber
= 0;
208 extern bool g_mainThreadLocked
;
210 //-----------------------------------------------------------------------------
212 //-----------------------------------------------------------------------------
217 # define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
219 # define DEBUG_MAIN_THREAD
222 #define DEBUG_MAIN_THREAD
225 // the trace mask used for the focus debugging messages
226 #define TRACE_FOCUS _T("focus")
228 //-----------------------------------------------------------------------------
229 // missing gdk functions
230 //-----------------------------------------------------------------------------
233 gdk_window_warp_pointer (GdkWindow
*window
,
238 window
= gdk_get_default_root_window();
240 if (!GDK_WINDOW_DESTROYED(window
))
242 XWarpPointer (GDK_WINDOW_XDISPLAY(window
),
243 None
, /* not source window -> move from anywhere */
244 GDK_WINDOW_XID(window
), /* dest window */
245 0, 0, 0, 0, /* not source window -> move from anywhere */
250 //-----------------------------------------------------------------------------
251 // local code (see below)
252 //-----------------------------------------------------------------------------
254 // returns the child of win which currently has focus or NULL if not found
256 // Note: can't be static, needed by textctrl.cpp.
257 wxWindow
*wxFindFocusedChild(wxWindowGTK
*win
)
259 wxWindow
*winFocus
= wxWindowGTK::FindFocus();
261 return (wxWindow
*)NULL
;
263 if ( winFocus
== win
)
264 return (wxWindow
*)win
;
266 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
268 node
= node
->GetNext() )
270 wxWindow
*child
= wxFindFocusedChild(node
->GetData());
275 return (wxWindow
*)NULL
;
278 static void GetScrollbarWidth(GtkWidget
* widget
, int& w
, int& h
)
280 GtkScrolledWindow
* scroll_window
= GTK_SCROLLED_WINDOW(widget
);
281 GtkScrolledWindowClass
* scroll_class
= GTK_SCROLLED_WINDOW_CLASS(GTK_OBJECT_GET_CLASS(scroll_window
));
282 GtkRequisition scroll_req
;
285 if (scroll_window
->vscrollbar_visible
)
287 scroll_req
.width
= 2;
288 scroll_req
.height
= 2;
289 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
290 (scroll_window
->vscrollbar
, &scroll_req
);
291 w
= scroll_req
.width
+
292 scroll_class
->scrollbar_spacing
;
296 if (scroll_window
->hscrollbar_visible
)
298 scroll_req
.width
= 2;
299 scroll_req
.height
= 2;
300 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
301 (scroll_window
->hscrollbar
, &scroll_req
);
302 h
= scroll_req
.height
+
303 scroll_class
->scrollbar_spacing
;
307 //-----------------------------------------------------------------------------
308 // "size_request" of m_widget
309 //-----------------------------------------------------------------------------
311 // make it extern because wxStaticText needs to disconnect this one
313 void wxgtk_window_size_request_callback(GtkWidget
* WXUNUSED(widget
),
314 GtkRequisition
*requisition
,
318 win
->GetSize( &w
, &h
);
324 requisition
->height
= h
;
325 requisition
->width
= w
;
329 //-----------------------------------------------------------------------------
330 // "expose_event" of m_wxwindow
331 //-----------------------------------------------------------------------------
335 gtk_window_expose_callback( GtkWidget
*,
336 GdkEventExpose
*gdk_event
,
344 wxPrintf( wxT("OnExpose from ") );
345 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
346 wxPrintf( win
->GetClassInfo()->GetClassName() );
347 wxPrintf( wxT(" %d %d %d %d\n"), (int)gdk_event
->area
.x
,
348 (int)gdk_event
->area
.y
,
349 (int)gdk_event
->area
.width
,
350 (int)gdk_event
->area
.height
);
355 win
->m_wxwindow
->style
,
359 (GdkRectangle
*) NULL
,
361 (char *)"button", // const_cast
366 win
->GetUpdateRegion() = wxRegion( gdk_event
->region
);
368 win
->GtkSendPaintEvents();
370 // Let parent window draw window-less widgets
375 //-----------------------------------------------------------------------------
376 // "expose_event" from m_widget, for drawing border
377 //-----------------------------------------------------------------------------
379 #ifndef __WXUNIVERSAL__
381 GtkWidget
* GetEntryWidget();
385 expose_event_border(GtkWidget
* widget
, GdkEventExpose
* gdk_event
, wxWindow
* win
)
387 // if this event is not for the GdkWindow the border is drawn on
388 if (win
->m_wxwindow
== win
->m_widget
&& gdk_event
->window
== widget
->window
)
393 // GtkScrolledWindow is GTK_NO_WINDOW
394 if (GTK_WIDGET_NO_WINDOW(widget
))
396 x
= widget
->allocation
.x
;
397 y
= widget
->allocation
.y
;
399 int w
= win
->m_wxwindow
->allocation
.width
;
400 int h
= win
->m_wxwindow
->allocation
.height
;
401 if (win
->HasFlag(wxBORDER_SIMPLE
))
403 GdkGC
* gc
= gdk_gc_new(gdk_event
->window
);
404 gdk_gc_set_foreground(gc
, &widget
->style
->black
);
405 gdk_draw_rectangle(gdk_event
->window
, gc
, false, x
, y
, w
- 1, h
- 1);
410 GtkShadowType shadow
= GTK_SHADOW_IN
;
411 if (win
->HasFlag(wxBORDER_RAISED
))
412 shadow
= GTK_SHADOW_OUT
;
414 // Style detail to use
416 if (widget
== win
->m_wxwindow
)
417 // for non-scrollable wxWindows
420 // for scrollable ones
423 GtkWidget
* styleWidget
= GetEntryWidget();
425 styleWidget
->style
, gdk_event
->window
, GTK_STATE_NORMAL
,
426 shadow
, NULL
, styleWidget
, detail
, x
, y
, w
, h
);
429 // no further painting is needed for border-only GdkWindow
430 return win
->m_wxwindow
== win
->m_widget
;
433 #endif // !__WXUNIVERSAL__
435 //-----------------------------------------------------------------------------
436 // "key_press_event" from any window
437 //-----------------------------------------------------------------------------
439 // These are used when transforming Ctrl-alpha to ascii values 1-26
440 inline bool wxIsLowerChar(int code
)
442 return (code
>= 'a' && code
<= 'z' );
445 inline bool wxIsUpperChar(int code
)
447 return (code
>= 'A' && code
<= 'Z' );
451 // set WXTRACE to this to see the key event codes on the console
452 #define TRACE_KEYS _T("keyevent")
454 // translates an X key symbol to WXK_XXX value
456 // if isChar is true it means that the value returned will be used for EVT_CHAR
457 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
458 // for example, while if it is false it means that the value is going to be
459 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
461 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
467 // Shift, Control and Alt don't generate the CHAR events at all
470 key_code
= isChar
? 0 : WXK_SHIFT
;
474 key_code
= isChar
? 0 : WXK_CONTROL
;
482 key_code
= isChar
? 0 : WXK_ALT
;
485 // neither do the toggle modifies
486 case GDK_Scroll_Lock
:
487 key_code
= isChar
? 0 : WXK_SCROLL
;
491 key_code
= isChar
? 0 : WXK_CAPITAL
;
495 key_code
= isChar
? 0 : WXK_NUMLOCK
;
499 // various other special keys
512 case GDK_ISO_Left_Tab
:
519 key_code
= WXK_RETURN
;
523 key_code
= WXK_CLEAR
;
527 key_code
= WXK_PAUSE
;
531 key_code
= WXK_SELECT
;
535 key_code
= WXK_PRINT
;
539 key_code
= WXK_EXECUTE
;
543 key_code
= WXK_ESCAPE
;
546 // cursor and other extended keyboard keys
548 key_code
= WXK_DELETE
;
564 key_code
= WXK_RIGHT
;
571 case GDK_Prior
: // == GDK_Page_Up
572 key_code
= WXK_PAGEUP
;
575 case GDK_Next
: // == GDK_Page_Down
576 key_code
= WXK_PAGEDOWN
;
588 key_code
= WXK_INSERT
;
603 key_code
= (isChar
? '0' : WXK_NUMPAD0
) + keysym
- GDK_KP_0
;
607 key_code
= isChar
? ' ' : WXK_NUMPAD_SPACE
;
611 key_code
= isChar
? WXK_TAB
: WXK_NUMPAD_TAB
;
615 key_code
= isChar
? WXK_RETURN
: WXK_NUMPAD_ENTER
;
619 key_code
= isChar
? WXK_F1
: WXK_NUMPAD_F1
;
623 key_code
= isChar
? WXK_F2
: WXK_NUMPAD_F2
;
627 key_code
= isChar
? WXK_F3
: WXK_NUMPAD_F3
;
631 key_code
= isChar
? WXK_F4
: WXK_NUMPAD_F4
;
635 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_HOME
;
639 key_code
= isChar
? WXK_LEFT
: WXK_NUMPAD_LEFT
;
643 key_code
= isChar
? WXK_UP
: WXK_NUMPAD_UP
;
647 key_code
= isChar
? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
651 key_code
= isChar
? WXK_DOWN
: WXK_NUMPAD_DOWN
;
654 case GDK_KP_Prior
: // == GDK_KP_Page_Up
655 key_code
= isChar
? WXK_PAGEUP
: WXK_NUMPAD_PAGEUP
;
658 case GDK_KP_Next
: // == GDK_KP_Page_Down
659 key_code
= isChar
? WXK_PAGEDOWN
: WXK_NUMPAD_PAGEDOWN
;
663 key_code
= isChar
? WXK_END
: WXK_NUMPAD_END
;
667 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_BEGIN
;
671 key_code
= isChar
? WXK_INSERT
: WXK_NUMPAD_INSERT
;
675 key_code
= isChar
? WXK_DELETE
: WXK_NUMPAD_DELETE
;
679 key_code
= isChar
? '=' : WXK_NUMPAD_EQUAL
;
682 case GDK_KP_Multiply
:
683 key_code
= isChar
? '*' : WXK_NUMPAD_MULTIPLY
;
687 key_code
= isChar
? '+' : WXK_NUMPAD_ADD
;
690 case GDK_KP_Separator
:
691 // FIXME: what is this?
692 key_code
= isChar
? '.' : WXK_NUMPAD_SEPARATOR
;
695 case GDK_KP_Subtract
:
696 key_code
= isChar
? '-' : WXK_NUMPAD_SUBTRACT
;
700 key_code
= isChar
? '.' : WXK_NUMPAD_DECIMAL
;
704 key_code
= isChar
? '/' : WXK_NUMPAD_DIVIDE
;
721 key_code
= WXK_F1
+ keysym
- GDK_F1
;
731 static inline bool wxIsAsciiKeysym(KeySym ks
)
736 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
738 GdkEventKey
*gdk_event
)
742 GdkModifierType state
;
743 if (gdk_event
->window
)
744 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
746 event
.SetTimestamp( gdk_event
->time
);
747 event
.SetId(win
->GetId());
748 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
749 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
750 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
751 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
) != 0;
752 event
.m_scanCode
= gdk_event
->keyval
;
753 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
754 event
.m_rawFlags
= 0;
756 event
.m_uniChar
= gdk_keyval_to_unicode(gdk_event
->keyval
);
758 wxGetMousePosition( &x
, &y
);
759 win
->ScreenToClient( &x
, &y
);
762 event
.SetEventObject( win
);
767 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
769 GdkEventKey
*gdk_event
)
771 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
772 // but only event->keyval which is quite useless to us, so remember
773 // the last character from GDK_KEY_PRESS and reuse it as last resort
775 // NB: should be MT-safe as we're always called from the main thread only
780 } s_lastKeyPress
= { 0, 0 };
782 KeySym keysym
= gdk_event
->keyval
;
784 wxLogTrace(TRACE_KEYS
, _T("Key %s event: keysym = %ld"),
785 event
.GetEventType() == wxEVT_KEY_UP
? _T("release")
789 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
793 // do we have the translation or is it a plain ASCII character?
794 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
796 // we should use keysym if it is ASCII as X does some translations
797 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
798 // which we don't want here (but which we do use for OnChar())
799 if ( !wxIsAsciiKeysym(keysym
) )
801 keysym
= (KeySym
)gdk_event
->string
[0];
804 // we want to always get the same key code when the same key is
805 // pressed regardless of the state of the modifiers, i.e. on a
806 // standard US keyboard pressing '5' or '%' ('5' key with
807 // Shift) should result in the same key code in OnKeyDown():
808 // '5' (although OnChar() will get either '5' or '%').
810 // to do it we first translate keysym to keycode (== scan code)
811 // and then back but always using the lower register
812 Display
*dpy
= (Display
*)wxGetDisplay();
813 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
815 wxLogTrace(TRACE_KEYS
, _T("\t-> keycode %d"), keycode
);
817 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
819 // use the normalized, i.e. lower register, keysym if we've
821 key_code
= keysymNormalized
? keysymNormalized
: keysym
;
823 // as explained above, we want to have lower register key codes
824 // normally but for the letter keys we want to have the upper ones
826 // NB: don't use XConvertCase() here, we want to do it for letters
828 key_code
= toupper(key_code
);
830 else // non ASCII key, what to do?
832 // by default, ignore it
835 // but if we have cached information from the last KEY_PRESS
836 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
839 if ( keysym
== s_lastKeyPress
.keysym
)
841 key_code
= s_lastKeyPress
.keycode
;
846 if ( gdk_event
->type
== GDK_KEY_PRESS
)
848 // remember it to be reused for KEY_UP event later
849 s_lastKeyPress
.keysym
= keysym
;
850 s_lastKeyPress
.keycode
= key_code
;
854 wxLogTrace(TRACE_KEYS
, _T("\t-> wxKeyCode %ld"), key_code
);
856 // sending unknown key events doesn't really make sense
860 // now fill all the other fields
861 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
863 event
.m_keyCode
= key_code
;
865 if ( gdk_event
->type
== GDK_KEY_PRESS
|| gdk_event
->type
== GDK_KEY_RELEASE
)
867 event
.m_uniChar
= key_code
;
877 GtkIMContext
*context
;
878 GdkEventKey
*lastKeyEvent
;
882 context
= gtk_im_multicontext_new();
887 g_object_unref (context
);
893 gtk_window_key_press_callback( GtkWidget
*widget
,
894 GdkEventKey
*gdk_event
,
901 if (g_blockEventsOnDrag
)
904 // GTK+ sends keypress events to the focus widget and then
905 // to all its parent and grandparent widget. We only want
906 // the key events from the focus widget.
907 if (!GTK_WIDGET_HAS_FOCUS(widget
))
910 wxKeyEvent
event( wxEVT_KEY_DOWN
);
912 bool return_after_IM
= false;
914 if( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
916 // Emit KEY_DOWN event
917 ret
= win
->HandleWindowEvent( event
);
921 // Return after IM processing as we cannot do
922 // anything with it anyhow.
923 return_after_IM
= true;
926 if ((!ret
) && (win
->m_imData
!= NULL
))
928 // We should let GTK+ IM filter key event first. According to GTK+ 2.0 API
929 // docs, if IM filter returns true, no further processing should be done.
930 // we should send the key_down event anyway.
931 bool intercepted_by_IM
= gtk_im_context_filter_keypress(win
->m_imData
->context
, gdk_event
);
932 win
->m_imData
->lastKeyEvent
= NULL
;
933 if (intercepted_by_IM
)
935 wxLogTrace(TRACE_KEYS
, _T("Key event intercepted by IM"));
946 wxWindowGTK
*ancestor
= win
;
949 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
952 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
953 ret
= ancestor
->HandleWindowEvent( command_event
);
956 if (ancestor
->IsTopLevel())
958 ancestor
= ancestor
->GetParent();
961 #endif // wxUSE_ACCEL
963 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
964 // will only be sent if it is not in an accelerator table.
968 KeySym keysym
= gdk_event
->keyval
;
969 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
970 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
973 if ( wxIsAsciiKeysym(keysym
) )
976 key_code
= (unsigned char)keysym
;
978 // gdk_event->string is actually deprecated
979 else if ( gdk_event
->length
== 1 )
981 key_code
= (unsigned char)gdk_event
->string
[0];
987 wxLogTrace(TRACE_KEYS
, _T("Char event: %ld"), key_code
);
989 event
.m_keyCode
= key_code
;
991 // To conform to the docs we need to translate Ctrl-alpha
992 // characters to values in the range 1-26.
993 if ( event
.ControlDown() &&
994 ( wxIsLowerChar(key_code
) || wxIsUpperChar(key_code
) ))
996 if ( wxIsLowerChar(key_code
) )
997 event
.m_keyCode
= key_code
- 'a' + 1;
998 if ( wxIsUpperChar(key_code
) )
999 event
.m_keyCode
= key_code
- 'A' + 1;
1001 event
.m_uniChar
= event
.m_keyCode
;
1005 // Implement OnCharHook by checking ancestor top level windows
1006 wxWindow
*parent
= win
;
1007 while (parent
&& !parent
->IsTopLevel())
1008 parent
= parent
->GetParent();
1011 event
.SetEventType( wxEVT_CHAR_HOOK
);
1012 ret
= parent
->HandleWindowEvent( event
);
1017 event
.SetEventType(wxEVT_CHAR
);
1018 ret
= win
->HandleWindowEvent( event
);
1029 gtk_wxwindow_commit_cb (GtkIMContext
* WXUNUSED(context
),
1033 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1035 // take modifiers, cursor position, timestamp etc. from the last
1036 // key_press_event that was fed into Input Method:
1037 if (window
->m_imData
->lastKeyEvent
)
1039 wxFillOtherKeyEventFields(event
,
1040 window
, window
->m_imData
->lastKeyEvent
);
1044 event
.SetEventObject( window
);
1047 const wxString
data(wxGTK_CONV_BACK_SYS(str
));
1053 // Implement OnCharHook by checking ancestor top level windows
1054 wxWindow
*parent
= window
;
1055 while (parent
&& !parent
->IsTopLevel())
1056 parent
= parent
->GetParent();
1058 for( wxString::const_iterator pstr
= data
.begin(); pstr
!= data
.end(); ++pstr
)
1061 event
.m_uniChar
= *pstr
;
1062 // Backward compatible for ISO-8859-1
1063 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1064 wxLogTrace(TRACE_KEYS
, _T("IM sent character '%c'"), event
.m_uniChar
);
1066 event
.m_keyCode
= (char)*pstr
;
1067 #endif // wxUSE_UNICODE
1069 // To conform to the docs we need to translate Ctrl-alpha
1070 // characters to values in the range 1-26.
1071 if ( event
.ControlDown() &&
1072 ( wxIsLowerChar(*pstr
) || wxIsUpperChar(*pstr
) ))
1074 if ( wxIsLowerChar(*pstr
) )
1075 event
.m_keyCode
= *pstr
- 'a' + 1;
1076 if ( wxIsUpperChar(*pstr
) )
1077 event
.m_keyCode
= *pstr
- 'A' + 1;
1079 event
.m_keyCode
= *pstr
- 'a' + 1;
1081 event
.m_uniChar
= event
.m_keyCode
;
1087 event
.SetEventType( wxEVT_CHAR_HOOK
);
1088 ret
= parent
->HandleWindowEvent( event
);
1093 event
.SetEventType(wxEVT_CHAR
);
1094 ret
= window
->HandleWindowEvent( event
);
1101 //-----------------------------------------------------------------------------
1102 // "key_release_event" from any window
1103 //-----------------------------------------------------------------------------
1107 gtk_window_key_release_callback( GtkWidget
* WXUNUSED(widget
),
1108 GdkEventKey
*gdk_event
,
1116 if (g_blockEventsOnDrag
)
1119 wxKeyEvent
event( wxEVT_KEY_UP
);
1120 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1122 // unknown key pressed, ignore (the event would be useless anyhow)
1126 return win
->GTKProcessEvent(event
);
1130 // ============================================================================
1132 // ============================================================================
1134 // ----------------------------------------------------------------------------
1135 // mouse event processing helpers
1136 // ----------------------------------------------------------------------------
1138 // init wxMouseEvent with the info from GdkEventXXX struct
1139 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1140 wxMouseEvent
& event
,
1143 event
.SetTimestamp( gdk_event
->time
);
1144 event
.m_shiftDown
= gdk_event
->state
& GDK_SHIFT_MASK
;
1145 event
.m_controlDown
= gdk_event
->state
& GDK_CONTROL_MASK
;
1146 event
.m_altDown
= gdk_event
->state
& GDK_MOD1_MASK
;
1147 event
.m_metaDown
= gdk_event
->state
& GDK_MOD2_MASK
;
1148 event
.m_leftDown
= gdk_event
->state
& GDK_BUTTON1_MASK
;
1149 event
.m_middleDown
= gdk_event
->state
& GDK_BUTTON2_MASK
;
1150 event
.m_rightDown
= gdk_event
->state
& GDK_BUTTON3_MASK
;
1151 event
.m_aux1Down
= gdk_event
->state
& GDK_BUTTON4_MASK
;
1152 event
.m_aux2Down
= gdk_event
->state
& GDK_BUTTON5_MASK
;
1154 wxPoint pt
= win
->GetClientAreaOrigin();
1155 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1156 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1158 if ((win
->m_wxwindow
) && (win
->GetLayoutDirection() == wxLayout_RightToLeft
))
1160 // origin in the upper right corner
1161 int window_width
= win
->m_wxwindow
->allocation
.width
;
1162 event
.m_x
= window_width
- event
.m_x
;
1165 event
.SetEventObject( win
);
1166 event
.SetId( win
->GetId() );
1167 event
.SetTimestamp( gdk_event
->time
);
1170 static void AdjustEventButtonState(wxMouseEvent
& event
)
1172 // GDK reports the old state of the button for a button press event, but
1173 // for compatibility with MSW and common sense we want m_leftDown be TRUE
1174 // for a LEFT_DOWN event, not FALSE, so we will invert
1175 // left/right/middleDown for the corresponding click events
1177 if ((event
.GetEventType() == wxEVT_LEFT_DOWN
) ||
1178 (event
.GetEventType() == wxEVT_LEFT_DCLICK
) ||
1179 (event
.GetEventType() == wxEVT_LEFT_UP
))
1181 event
.m_leftDown
= !event
.m_leftDown
;
1185 if ((event
.GetEventType() == wxEVT_MIDDLE_DOWN
) ||
1186 (event
.GetEventType() == wxEVT_MIDDLE_DCLICK
) ||
1187 (event
.GetEventType() == wxEVT_MIDDLE_UP
))
1189 event
.m_middleDown
= !event
.m_middleDown
;
1193 if ((event
.GetEventType() == wxEVT_RIGHT_DOWN
) ||
1194 (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) ||
1195 (event
.GetEventType() == wxEVT_RIGHT_UP
))
1197 event
.m_rightDown
= !event
.m_rightDown
;
1202 // find the window to send the mouse event too
1204 wxWindowGTK
*FindWindowForMouseEvent(wxWindowGTK
*win
, wxCoord
& x
, wxCoord
& y
)
1209 if (win
->m_wxwindow
)
1211 wxPizza
* pizza
= WX_PIZZA(win
->m_wxwindow
);
1212 xx
+= pizza
->m_scroll_x
;
1213 yy
+= pizza
->m_scroll_y
;
1216 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
1219 wxWindowGTK
*child
= node
->GetData();
1221 node
= node
->GetNext();
1222 if (!child
->IsShown())
1225 if (child
->IsTransparentForMouse())
1227 // wxStaticBox is transparent in the box itself
1228 int xx1
= child
->m_x
;
1229 int yy1
= child
->m_y
;
1230 int xx2
= child
->m_x
+ child
->m_width
;
1231 int yy2
= child
->m_y
+ child
->m_height
;
1234 if (((xx
>= xx1
) && (xx
<= xx1
+10) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1236 ((xx
>= xx2
-10) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1238 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy1
+10)) ||
1240 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy2
-1) && (yy
<= yy2
)))
1251 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1252 (child
->m_x
<= xx
) &&
1253 (child
->m_y
<= yy
) &&
1254 (child
->m_x
+child
->m_width
>= xx
) &&
1255 (child
->m_y
+child
->m_height
>= yy
))
1268 // ----------------------------------------------------------------------------
1269 // common event handlers helpers
1270 // ----------------------------------------------------------------------------
1272 bool wxWindowGTK::GTKProcessEvent(wxEvent
& event
) const
1274 // nothing special at this level
1275 return HandleWindowEvent(event
);
1278 int wxWindowGTK::GTKCallbackCommonPrologue(GdkEventAny
*event
) const
1284 if (g_blockEventsOnDrag
)
1286 if (g_blockEventsOnScroll
)
1289 if (!GTKIsOwnWindow(event
->window
))
1295 // overloads for all GDK event types we use here: we need to have this as
1296 // GdkEventXXX can't be implicitly cast to GdkEventAny even if it, in fact,
1297 // derives from it in the sense that the structs have the same layout
1298 #define wxDEFINE_COMMON_PROLOGUE_OVERLOAD(T) \
1299 static int wxGtkCallbackCommonPrologue(T *event, wxWindowGTK *win) \
1301 return win->GTKCallbackCommonPrologue((GdkEventAny *)event); \
1304 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventButton
)
1305 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventMotion
)
1306 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventCrossing
)
1308 #undef wxDEFINE_COMMON_PROLOGUE_OVERLOAD
1310 #define wxCOMMON_CALLBACK_PROLOGUE(event, win) \
1311 const int rc = wxGtkCallbackCommonPrologue(event, win); \
1315 // send the wxChildFocusEvent and wxFocusEvent, common code of
1316 // gtk_window_focus_in_callback() and SetFocus()
1317 static bool DoSendFocusEvents(wxWindow
*win
)
1319 // Notify the parent keeping track of focus for the kbd navigation
1320 // purposes that we got it.
1321 wxChildFocusEvent
eventChildFocus(win
);
1322 (void)win
->HandleWindowEvent(eventChildFocus
);
1324 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, win
->GetId());
1325 eventFocus
.SetEventObject(win
);
1327 return win
->HandleWindowEvent(eventFocus
);
1330 // all event handlers must have C linkage as they're called from GTK+ C code
1334 //-----------------------------------------------------------------------------
1335 // "button_press_event"
1336 //-----------------------------------------------------------------------------
1339 gtk_window_button_press_callback( GtkWidget
*widget
,
1340 GdkEventButton
*gdk_event
,
1343 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1345 g_lastButtonNumber
= gdk_event
->button
;
1347 // GDK sends surplus button down events
1348 // before a double click event. We
1349 // need to filter these out.
1350 if ((gdk_event
->type
== GDK_BUTTON_PRESS
) && (win
->m_wxwindow
))
1352 GdkEvent
*peek_event
= gdk_event_peek();
1355 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1356 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1358 gdk_event_free( peek_event
);
1363 gdk_event_free( peek_event
);
1368 wxEventType event_type
= wxEVT_NULL
;
1370 if ( gdk_event
->type
== GDK_2BUTTON_PRESS
&&
1371 gdk_event
->button
>= 1 && gdk_event
->button
<= 3 )
1373 // Reset GDK internal timestamp variables in order to disable GDK
1374 // triple click events. GDK will then next time believe no button has
1375 // been clicked just before, and send a normal button click event.
1376 GdkDisplay
* display
= gtk_widget_get_display (widget
);
1377 display
->button_click_time
[1] = 0;
1378 display
->button_click_time
[0] = 0;
1381 if (gdk_event
->button
== 1)
1383 // note that GDK generates triple click events which are not supported
1384 // by wxWidgets but still have to be passed to the app as otherwise
1385 // clicks would simply go missing
1386 switch (gdk_event
->type
)
1388 // we shouldn't get triple clicks at all for GTK2 because we
1389 // suppress them artificially using the code above but we still
1390 // should map them to something for GTK1 and not just ignore them
1391 // as this would lose clicks
1392 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1393 case GDK_BUTTON_PRESS
:
1394 event_type
= wxEVT_LEFT_DOWN
;
1397 case GDK_2BUTTON_PRESS
:
1398 event_type
= wxEVT_LEFT_DCLICK
;
1402 // just to silence gcc warnings
1406 else if (gdk_event
->button
== 2)
1408 switch (gdk_event
->type
)
1410 case GDK_3BUTTON_PRESS
:
1411 case GDK_BUTTON_PRESS
:
1412 event_type
= wxEVT_MIDDLE_DOWN
;
1415 case GDK_2BUTTON_PRESS
:
1416 event_type
= wxEVT_MIDDLE_DCLICK
;
1423 else if (gdk_event
->button
== 3)
1425 switch (gdk_event
->type
)
1427 case GDK_3BUTTON_PRESS
:
1428 case GDK_BUTTON_PRESS
:
1429 event_type
= wxEVT_RIGHT_DOWN
;
1432 case GDK_2BUTTON_PRESS
:
1433 event_type
= wxEVT_RIGHT_DCLICK
;
1441 if ( event_type
== wxEVT_NULL
)
1443 // unknown mouse button or click type
1447 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1449 wxMouseEvent
event( event_type
);
1450 InitMouseEvent( win
, event
, gdk_event
);
1452 AdjustEventButtonState(event
);
1454 // wxListBox actually gets mouse events from the item, so we need to give it
1455 // a chance to correct this
1456 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1458 // find the correct window to send the event to: it may be a different one
1459 // from the one which got it at GTK+ level because some controls don't have
1460 // their own X window and thus cannot get any events.
1461 if ( !g_captureWindow
)
1462 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1464 // reset the event object and id in case win changed.
1465 event
.SetEventObject( win
);
1466 event
.SetId( win
->GetId() );
1468 bool ret
= win
->GTKProcessEvent( event
);
1469 g_lastMouseEvent
= NULL
;
1473 if ((event_type
== wxEVT_LEFT_DOWN
) && !win
->IsOfStandardClass() &&
1474 (g_focusWindow
!= win
) /* && win->IsFocusable() */)
1479 if (event_type
== wxEVT_RIGHT_DOWN
)
1481 // generate a "context menu" event: this is similar to right mouse
1482 // click under many GUIs except that it is generated differently
1483 // (right up under MSW, ctrl-click under Mac, right down here) and
1485 // (a) it's a command event and so is propagated to the parent
1486 // (b) under some ports it can be generated from kbd too
1487 // (c) it uses screen coords (because of (a))
1488 wxContextMenuEvent
evtCtx(
1491 win
->ClientToScreen(event
.GetPosition()));
1492 evtCtx
.SetEventObject(win
);
1493 return win
->GTKProcessEvent(evtCtx
);
1499 //-----------------------------------------------------------------------------
1500 // "button_release_event"
1501 //-----------------------------------------------------------------------------
1504 gtk_window_button_release_callback( GtkWidget
*widget
,
1505 GdkEventButton
*gdk_event
,
1508 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1510 g_lastButtonNumber
= 0;
1512 wxEventType event_type
= wxEVT_NULL
;
1514 switch (gdk_event
->button
)
1517 event_type
= wxEVT_LEFT_UP
;
1521 event_type
= wxEVT_MIDDLE_UP
;
1525 event_type
= wxEVT_RIGHT_UP
;
1529 // unknown button, don't process
1533 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1535 wxMouseEvent
event( event_type
);
1536 InitMouseEvent( win
, event
, gdk_event
);
1538 AdjustEventButtonState(event
);
1540 // same wxListBox hack as above
1541 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1543 if ( !g_captureWindow
)
1544 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1546 // reset the event object and id in case win changed.
1547 event
.SetEventObject( win
);
1548 event
.SetId( win
->GetId() );
1550 bool ret
= win
->GTKProcessEvent(event
);
1552 g_lastMouseEvent
= NULL
;
1557 //-----------------------------------------------------------------------------
1558 // "motion_notify_event"
1559 //-----------------------------------------------------------------------------
1562 gtk_window_motion_notify_callback( GtkWidget
* WXUNUSED(widget
),
1563 GdkEventMotion
*gdk_event
,
1566 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1568 if (gdk_event
->is_hint
)
1572 GdkModifierType state
;
1573 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1578 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1580 wxMouseEvent
event( wxEVT_MOTION
);
1581 InitMouseEvent(win
, event
, gdk_event
);
1583 if ( g_captureWindow
)
1585 // synthesise a mouse enter or leave event if needed
1586 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1587 // This seems to be necessary and actually been added to
1588 // GDK itself in version 2.0.X
1591 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1592 if ( hasMouse
!= g_captureWindowHasMouse
)
1594 // the mouse changed window
1595 g_captureWindowHasMouse
= hasMouse
;
1597 wxMouseEvent
eventM(g_captureWindowHasMouse
? wxEVT_ENTER_WINDOW
1598 : wxEVT_LEAVE_WINDOW
);
1599 InitMouseEvent(win
, eventM
, gdk_event
);
1600 eventM
.SetEventObject(win
);
1601 win
->GTKProcessEvent(eventM
);
1606 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1608 // reset the event object and id in case win changed.
1609 event
.SetEventObject( win
);
1610 event
.SetId( win
->GetId() );
1613 if ( !g_captureWindow
)
1615 wxSetCursorEvent
cevent( event
.m_x
, event
.m_y
);
1616 if (win
->GTKProcessEvent( cevent
))
1618 win
->SetCursor( cevent
.GetCursor() );
1622 bool ret
= win
->GTKProcessEvent(event
);
1624 g_lastMouseEvent
= NULL
;
1629 //-----------------------------------------------------------------------------
1630 // "scroll_event" (mouse wheel event)
1631 //-----------------------------------------------------------------------------
1634 window_scroll_event(GtkWidget
*, GdkEventScroll
* gdk_event
, wxWindow
* win
)
1638 if (gdk_event
->direction
!= GDK_SCROLL_UP
&&
1639 gdk_event
->direction
!= GDK_SCROLL_DOWN
)
1644 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
1645 InitMouseEvent(win
, event
, gdk_event
);
1646 event
.m_linesPerAction
= 3;
1647 event
.m_wheelDelta
= 120;
1648 if (gdk_event
->direction
== GDK_SCROLL_UP
)
1649 event
.m_wheelRotation
= 120;
1651 event
.m_wheelRotation
= -120;
1653 return win
->GTKProcessEvent(event
);
1656 //-----------------------------------------------------------------------------
1658 //-----------------------------------------------------------------------------
1660 static gboolean
wxgtk_window_popup_menu_callback(GtkWidget
*, wxWindowGTK
* win
)
1662 wxContextMenuEvent
event(wxEVT_CONTEXT_MENU
, win
->GetId(), wxPoint(-1, -1));
1663 event
.SetEventObject(win
);
1664 return win
->GTKProcessEvent(event
);
1667 //-----------------------------------------------------------------------------
1669 //-----------------------------------------------------------------------------
1672 gtk_window_focus_in_callback( GtkWidget
* WXUNUSED(widget
),
1673 GdkEventFocus
*WXUNUSED(event
),
1679 gtk_im_context_focus_in(win
->m_imData
->context
);
1682 g_focusWindow
= win
;
1684 wxLogTrace(TRACE_FOCUS
,
1685 _T("%s: focus in"), win
->GetName().c_str());
1688 // caret needs to be informed about focus change
1689 wxCaret
*caret
= win
->GetCaret();
1692 caret
->OnSetFocus();
1694 #endif // wxUSE_CARET
1696 gboolean ret
= FALSE
;
1698 // does the window itself think that it has the focus?
1699 if ( !win
->m_hasFocus
)
1701 // not yet, notify it
1702 win
->m_hasFocus
= true;
1704 (void)DoSendFocusEvents(win
);
1709 // Disable default focus handling for custom windows
1710 // since the default GTK+ handler issues a repaint
1711 if (win
->m_wxwindow
)
1717 //-----------------------------------------------------------------------------
1718 // "focus_out_event"
1719 //-----------------------------------------------------------------------------
1722 gtk_window_focus_out_callback( GtkWidget
* WXUNUSED(widget
),
1723 GdkEventFocus
* WXUNUSED(gdk_event
),
1729 gtk_im_context_focus_out(win
->m_imData
->context
);
1731 wxLogTrace( TRACE_FOCUS
,
1732 _T("%s: focus out"), win
->GetName().c_str() );
1735 wxWindowGTK
*winFocus
= wxFindFocusedChild(win
);
1739 g_focusWindow
= (wxWindowGTK
*)NULL
;
1742 // caret needs to be informed about focus change
1743 wxCaret
*caret
= win
->GetCaret();
1746 caret
->OnKillFocus();
1748 #endif // wxUSE_CARET
1750 // don't send the window a kill focus event if it thinks that it doesn't
1751 // have focus already
1752 if ( win
->m_hasFocus
)
1754 // the event handler might delete the window when it loses focus, so
1755 // check whether this is a custom window before calling it
1756 const bool has_wxwindow
= win
->m_wxwindow
!= NULL
;
1758 win
->m_hasFocus
= false;
1760 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
1761 event
.SetEventObject( win
);
1763 (void)win
->GTKProcessEvent( event
);
1765 // Disable default focus handling for custom windows
1766 // since the default GTK+ handler issues a repaint
1771 // continue with normal processing
1776 wx_window_focus_callback(GtkWidget
*widget
,
1777 GtkDirectionType
WXUNUSED(direction
),
1780 // the default handler for focus signal in GtkScrolledWindow sets
1781 // focus to the window itself even if it doesn't accept focus, i.e. has no
1782 // GTK_CAN_FOCUS in its style -- work around this by forcibly preventing
1783 // the signal from reaching gtk_scrolled_window_focus() if we don't have
1784 // any children which might accept focus (we know we don't accept the focus
1785 // ourselves as this signal is only connected in this case)
1786 if ( win
->GetChildren().empty() )
1787 g_signal_stop_emission_by_name(widget
, "focus");
1789 // we didn't change the focus
1793 //-----------------------------------------------------------------------------
1794 // "enter_notify_event"
1795 //-----------------------------------------------------------------------------
1798 gtk_window_enter_callback( GtkWidget
*widget
,
1799 GdkEventCrossing
*gdk_event
,
1802 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1804 // Event was emitted after a grab
1805 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1809 GdkModifierType state
= (GdkModifierType
)0;
1811 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1813 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
1814 InitMouseEvent(win
, event
, gdk_event
);
1815 wxPoint pt
= win
->GetClientAreaOrigin();
1816 event
.m_x
= x
+ pt
.x
;
1817 event
.m_y
= y
+ pt
.y
;
1819 if ( !g_captureWindow
)
1821 wxSetCursorEvent
cevent( event
.m_x
, event
.m_y
);
1822 if (win
->GTKProcessEvent( cevent
))
1824 win
->SetCursor( cevent
.GetCursor() );
1828 return win
->GTKProcessEvent(event
);
1831 //-----------------------------------------------------------------------------
1832 // "leave_notify_event"
1833 //-----------------------------------------------------------------------------
1836 gtk_window_leave_callback( GtkWidget
*widget
,
1837 GdkEventCrossing
*gdk_event
,
1840 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1842 // Event was emitted after an ungrab
1843 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1845 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
1849 GdkModifierType state
= (GdkModifierType
)0;
1851 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1853 InitMouseEvent(win
, event
, gdk_event
);
1855 return win
->GTKProcessEvent(event
);
1858 //-----------------------------------------------------------------------------
1859 // "value_changed" from scrollbar
1860 //-----------------------------------------------------------------------------
1863 gtk_scrollbar_value_changed(GtkRange
* range
, wxWindow
* win
)
1865 wxEventType eventType
= win
->GetScrollEventType(range
);
1866 if (eventType
!= wxEVT_NULL
)
1868 // Convert scroll event type to scrollwin event type
1869 eventType
+= wxEVT_SCROLLWIN_TOP
- wxEVT_SCROLL_TOP
;
1871 // find the scrollbar which generated the event
1872 wxWindowGTK::ScrollDir dir
= win
->ScrollDirFromRange(range
);
1874 // generate the corresponding wx event
1875 const int orient
= wxWindow::OrientFromScrollDir(dir
);
1876 wxScrollWinEvent
event(eventType
, win
->GetScrollPos(orient
), orient
);
1877 event
.SetEventObject(win
);
1879 win
->GTKProcessEvent(event
);
1883 //-----------------------------------------------------------------------------
1884 // "button_press_event" from scrollbar
1885 //-----------------------------------------------------------------------------
1888 gtk_scrollbar_button_press_event(GtkRange
*, GdkEventButton
*, wxWindow
* win
)
1892 g_blockEventsOnScroll
= true;
1893 win
->m_mouseButtonDown
= true;
1898 //-----------------------------------------------------------------------------
1899 // "event_after" from scrollbar
1900 //-----------------------------------------------------------------------------
1903 gtk_scrollbar_event_after(GtkRange
* range
, GdkEvent
* event
, wxWindow
* win
)
1905 if (event
->type
== GDK_BUTTON_RELEASE
)
1907 g_signal_handlers_block_by_func(range
, (void*)gtk_scrollbar_event_after
, win
);
1909 const int orient
= wxWindow::OrientFromScrollDir(
1910 win
->ScrollDirFromRange(range
));
1911 wxScrollWinEvent
evt(wxEVT_SCROLLWIN_THUMBRELEASE
,
1912 win
->GetScrollPos(orient
), orient
);
1913 evt
.SetEventObject(win
);
1914 win
->GTKProcessEvent(evt
);
1918 //-----------------------------------------------------------------------------
1919 // "button_release_event" from scrollbar
1920 //-----------------------------------------------------------------------------
1923 gtk_scrollbar_button_release_event(GtkRange
* range
, GdkEventButton
*, wxWindow
* win
)
1927 g_blockEventsOnScroll
= false;
1928 win
->m_mouseButtonDown
= false;
1929 // If thumb tracking
1930 if (win
->m_isScrolling
)
1932 win
->m_isScrolling
= false;
1933 // Hook up handler to send thumb release event after this emission is finished.
1934 // To allow setting scroll position from event handler, sending event must
1935 // be deferred until after the GtkRange handler for this signal has run
1936 g_signal_handlers_unblock_by_func(range
, (void*)gtk_scrollbar_event_after
, win
);
1942 //-----------------------------------------------------------------------------
1943 // "realize" from m_widget
1944 //-----------------------------------------------------------------------------
1947 gtk_window_realized_callback(GtkWidget
* widget
, wxWindow
* win
)
1953 gtk_im_context_set_client_window( win
->m_imData
->context
,
1957 // We cannot set colours and fonts before the widget
1958 // been realized, so we do this directly after realization
1959 // or otherwise in idle time
1961 if (win
->m_needsStyleChange
)
1963 win
->SetBackgroundStyle(win
->GetBackgroundStyle());
1964 win
->m_needsStyleChange
= false;
1967 wxWindowCreateEvent
event( win
);
1968 event
.SetEventObject( win
);
1969 win
->GTKProcessEvent( event
);
1972 //-----------------------------------------------------------------------------
1973 // "size_allocate" from m_wxwindow or m_widget
1974 //-----------------------------------------------------------------------------
1977 size_allocate(GtkWidget
*, GtkAllocation
* alloc
, wxWindow
* win
)
1979 int w
= alloc
->width
;
1980 int h
= alloc
->height
;
1981 if (win
->m_wxwindow
)
1983 int border_x
, border_y
;
1984 WX_PIZZA(win
->m_wxwindow
)->get_border_widths(border_x
, border_y
);
1990 if (win
->m_oldClientWidth
!= w
|| win
->m_oldClientHeight
!= h
)
1992 win
->m_oldClientWidth
= w
;
1993 win
->m_oldClientHeight
= h
;
1994 // this callback can be connected to m_wxwindow,
1995 // so always get size from m_widget->allocation
1996 win
->m_width
= win
->m_widget
->allocation
.width
;
1997 win
->m_height
= win
->m_widget
->allocation
.height
;
1998 if (!win
->m_nativeSizeEvent
)
2000 wxSizeEvent
event(win
->GetSize(), win
->GetId());
2001 event
.SetEventObject(win
);
2002 win
->GTKProcessEvent(event
);
2007 //-----------------------------------------------------------------------------
2009 //-----------------------------------------------------------------------------
2011 #if GTK_CHECK_VERSION(2, 8, 0)
2013 gtk_window_grab_broken( GtkWidget
*,
2014 GdkEventGrabBroken
*event
,
2017 // Mouse capture has been lost involuntarily, notify the application
2018 if(!event
->keyboard
&& wxWindow::GetCapture() == win
)
2020 wxMouseCaptureLostEvent
evt( win
->GetId() );
2021 evt
.SetEventObject( win
);
2022 win
->HandleWindowEvent( evt
);
2028 //-----------------------------------------------------------------------------
2030 //-----------------------------------------------------------------------------
2033 void gtk_window_style_set_callback( GtkWidget
*WXUNUSED(widget
),
2034 GtkStyle
*previous_style
,
2037 if (win
&& previous_style
)
2039 wxSysColourChangedEvent event
;
2040 event
.SetEventObject(win
);
2042 win
->GTKProcessEvent( event
);
2048 // Helper to suspend colour change event event processing while we change a widget's style
2049 class wxSuspendStyleEvents
2052 wxSuspendStyleEvents(wxWindow
* win
)
2055 if (win
->m_wxwindow
&& win
->IsTopLevel())
2058 g_signal_handlers_block_by_func(
2059 m_win
->m_wxwindow
, (void*)gtk_window_style_set_callback
, m_win
);
2062 ~wxSuspendStyleEvents()
2065 g_signal_handlers_unblock_by_func(
2066 m_win
->m_wxwindow
, (void*)gtk_window_style_set_callback
, m_win
);
2072 // ----------------------------------------------------------------------------
2073 // this wxWindowBase function is implemented here (in platform-specific file)
2074 // because it is static and so couldn't be made virtual
2075 // ----------------------------------------------------------------------------
2077 wxWindow
*wxWindowBase::DoFindFocus()
2079 // the cast is necessary when we compile in wxUniversal mode
2080 return (wxWindow
*)g_focusWindow
;
2083 //-----------------------------------------------------------------------------
2084 // InsertChild for wxWindowGTK.
2085 //-----------------------------------------------------------------------------
2087 /* Callback for wxWindowGTK. This very strange beast has to be used because
2088 * C++ has no virtual methods in a constructor. We have to emulate a
2089 * virtual function here as wxNotebook requires a different way to insert
2090 * a child in it. I had opted for creating a wxNotebookPage window class
2091 * which would have made this superfluous (such in the MDI window system),
2092 * but no-one was listening to me... */
2094 static void wxInsertChildInWindow( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2096 /* the window might have been scrolled already, do we
2097 have to adapt the position */
2098 wxPizza
* pizza
= WX_PIZZA(parent
->m_wxwindow
);
2099 child
->m_x
+= pizza
->m_scroll_x
;
2100 child
->m_y
+= pizza
->m_scroll_y
;
2102 gtk_widget_set_size_request(
2103 child
->m_widget
, child
->m_width
, child
->m_height
);
2105 GTK_FIXED(parent
->m_wxwindow
), child
->m_widget
, child
->m_x
, child
->m_y
);
2108 //-----------------------------------------------------------------------------
2110 //-----------------------------------------------------------------------------
2112 wxWindow
*wxGetActiveWindow()
2114 return wxWindow::FindFocus();
2118 wxMouseState
wxGetMouseState()
2124 GdkModifierType mask
;
2126 gdk_window_get_pointer(NULL
, &x
, &y
, &mask
);
2130 ms
.SetLeftDown(mask
& GDK_BUTTON1_MASK
);
2131 ms
.SetMiddleDown(mask
& GDK_BUTTON2_MASK
);
2132 ms
.SetRightDown(mask
& GDK_BUTTON3_MASK
);
2133 ms
.SetAux1Down(mask
& GDK_BUTTON4_MASK
);
2134 ms
.SetAux2Down(mask
& GDK_BUTTON5_MASK
);
2136 ms
.SetControlDown(mask
& GDK_CONTROL_MASK
);
2137 ms
.SetShiftDown(mask
& GDK_SHIFT_MASK
);
2138 ms
.SetAltDown(mask
& GDK_MOD1_MASK
);
2139 ms
.SetMetaDown(mask
& GDK_MOD2_MASK
);
2144 //-----------------------------------------------------------------------------
2146 //-----------------------------------------------------------------------------
2148 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2150 #ifdef __WXUNIVERSAL__
2151 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2153 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
2154 #endif // __WXUNIVERSAL__/__WXGTK__
2156 void wxWindowGTK::Init()
2159 m_widget
= (GtkWidget
*) NULL
;
2160 m_wxwindow
= (GtkWidget
*) NULL
;
2161 m_focusWidget
= (GtkWidget
*) NULL
;
2170 m_isBeingDeleted
= false;
2172 m_showOnIdle
= false;
2175 m_nativeSizeEvent
= false;
2177 m_hasScrolling
= false;
2178 m_isScrolling
= false;
2179 m_mouseButtonDown
= false;
2181 // initialize scrolling stuff
2182 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
2184 m_scrollBar
[dir
] = NULL
;
2185 m_scrollPos
[dir
] = 0;
2189 m_oldClientHeight
= 0;
2191 m_insertCallback
= wxInsertChildInWindow
;
2195 m_clipPaintRegion
= false;
2197 m_needsStyleChange
= false;
2199 m_cursor
= *wxSTANDARD_CURSOR
;
2202 m_dirtyTabOrder
= false;
2205 wxWindowGTK::wxWindowGTK()
2210 wxWindowGTK::wxWindowGTK( wxWindow
*parent
,
2215 const wxString
&name
)
2219 Create( parent
, id
, pos
, size
, style
, name
);
2222 bool wxWindowGTK::Create( wxWindow
*parent
,
2227 const wxString
&name
)
2229 // Get default border
2230 wxBorder border
= GetBorder(style
);
2231 style
&= ~wxBORDER_MASK
;
2234 if (!PreCreation( parent
, pos
, size
) ||
2235 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2237 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2242 m_wxwindow
= wxPizza::New(m_windowStyle
);
2243 if (!HasFlag(wxHSCROLL
) && !HasFlag(wxVSCROLL
))
2244 m_widget
= m_wxwindow
;
2247 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
2249 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2251 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2252 scroll_class
->scrollbar_spacing
= 0;
2254 // There is a conflict with default bindings at GTK+
2255 // level between scrolled windows and notebooks both of which want to use
2256 // Ctrl-PageUp/Down: scrolled windows for scrolling in the horizontal
2257 // direction and notebooks for changing pages -- we decide that if we don't
2258 // have wxHSCROLL style we can safely sacrifice horizontal scrolling if it
2259 // means we can get working keyboard navigation in notebooks
2260 if ( !HasFlag(wxHSCROLL
) )
2263 bindings
= gtk_binding_set_by_class(G_OBJECT_GET_CLASS(m_widget
));
2266 gtk_binding_entry_remove(bindings
, GDK_Page_Up
, GDK_CONTROL_MASK
);
2267 gtk_binding_entry_remove(bindings
, GDK_Page_Down
, GDK_CONTROL_MASK
);
2271 if (HasFlag(wxALWAYS_SHOW_SB
))
2273 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_ALWAYS
, GTK_POLICY_ALWAYS
);
2275 scrolledWindow
->hscrollbar_visible
= TRUE
;
2276 scrolledWindow
->vscrollbar_visible
= TRUE
;
2280 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2283 m_scrollBar
[ScrollDir_Horz
] = GTK_RANGE(scrolledWindow
->hscrollbar
);
2284 m_scrollBar
[ScrollDir_Vert
] = GTK_RANGE(scrolledWindow
->vscrollbar
);
2285 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2286 gtk_range_set_inverted( m_scrollBar
[ScrollDir_Horz
], TRUE
);
2288 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2290 // connect various scroll-related events
2291 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
2293 // these handlers block mouse events to any window during scrolling
2294 // such as motion events and prevent GTK and wxWidgets from fighting
2295 // over where the slider should be
2296 g_signal_connect(m_scrollBar
[dir
], "button_press_event",
2297 G_CALLBACK(gtk_scrollbar_button_press_event
), this);
2298 g_signal_connect(m_scrollBar
[dir
], "button_release_event",
2299 G_CALLBACK(gtk_scrollbar_button_release_event
), this);
2301 gulong handler_id
= g_signal_connect(m_scrollBar
[dir
], "event_after",
2302 G_CALLBACK(gtk_scrollbar_event_after
), this);
2303 g_signal_handler_block(m_scrollBar
[dir
], handler_id
);
2305 // these handlers get notified when scrollbar slider moves
2306 g_signal_connect_after(m_scrollBar
[dir
], "value_changed",
2307 G_CALLBACK(gtk_scrollbar_value_changed
), this);
2310 gtk_widget_show( m_wxwindow
);
2314 m_parent
->DoAddChild( this );
2316 m_focusWidget
= m_wxwindow
;
2323 wxWindowGTK::~wxWindowGTK()
2327 if (g_focusWindow
== this)
2328 g_focusWindow
= NULL
;
2330 if ( g_delayedFocus
== this )
2331 g_delayedFocus
= NULL
;
2333 m_isBeingDeleted
= true;
2336 // destroy children before destroying this window itself
2339 // unhook focus handlers to prevent stray events being
2340 // propagated to this (soon to be) dead object
2341 if (m_focusWidget
!= NULL
)
2343 g_signal_handlers_disconnect_by_func (m_focusWidget
,
2344 (gpointer
) gtk_window_focus_in_callback
,
2346 g_signal_handlers_disconnect_by_func (m_focusWidget
,
2347 (gpointer
) gtk_window_focus_out_callback
,
2354 // delete before the widgets to avoid a crash on solaris
2357 if (m_wxwindow
&& (m_wxwindow
!= m_widget
))
2359 gtk_widget_destroy( m_wxwindow
);
2360 m_wxwindow
= (GtkWidget
*) NULL
;
2365 gtk_widget_destroy( m_widget
);
2366 m_widget
= (GtkWidget
*) NULL
;
2370 bool wxWindowGTK::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2372 if ( GTKNeedsParent() )
2374 wxCHECK_MSG( parent
, false, wxT("Must have non-NULL parent") );
2377 // Use either the given size, or the default if -1 is given.
2378 // See wxWindowBase for these functions.
2379 m_width
= WidthDefault(size
.x
) ;
2380 m_height
= HeightDefault(size
.y
);
2388 void wxWindowGTK::PostCreation()
2390 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2396 // these get reported to wxWidgets -> wxPaintEvent
2398 g_signal_connect (m_wxwindow
, "expose_event",
2399 G_CALLBACK (gtk_window_expose_callback
), this);
2401 if (GetLayoutDirection() == wxLayout_LeftToRight
)
2402 gtk_widget_set_redraw_on_allocate(m_wxwindow
, HasFlag(wxFULL_REPAINT_ON_RESIZE
));
2405 // Create input method handler
2406 m_imData
= new wxGtkIMData
;
2408 // Cannot handle drawing preedited text yet
2409 gtk_im_context_set_use_preedit( m_imData
->context
, FALSE
);
2411 g_signal_connect (m_imData
->context
, "commit",
2412 G_CALLBACK (gtk_wxwindow_commit_cb
), this);
2415 #ifndef __WXUNIVERSAL__
2416 if (HasFlag(wxPizza::BORDER_STYLES
))
2418 g_signal_connect(m_widget
, "expose_event",
2419 G_CALLBACK(expose_event_border
), this);
2426 if (!GTK_IS_WINDOW(m_widget
))
2428 if (m_focusWidget
== NULL
)
2429 m_focusWidget
= m_widget
;
2433 g_signal_connect (m_focusWidget
, "focus_in_event",
2434 G_CALLBACK (gtk_window_focus_in_callback
), this);
2435 g_signal_connect (m_focusWidget
, "focus_out_event",
2436 G_CALLBACK (gtk_window_focus_out_callback
), this);
2440 g_signal_connect_after (m_focusWidget
, "focus_in_event",
2441 G_CALLBACK (gtk_window_focus_in_callback
), this);
2442 g_signal_connect_after (m_focusWidget
, "focus_out_event",
2443 G_CALLBACK (gtk_window_focus_out_callback
), this);
2447 if ( !AcceptsFocusFromKeyboard() )
2451 g_signal_connect(m_widget
, "focus",
2452 G_CALLBACK(wx_window_focus_callback
), this);
2455 // connect to the various key and mouse handlers
2457 GtkWidget
*connect_widget
= GetConnectWidget();
2459 ConnectWidget( connect_widget
);
2461 /* We cannot set colours, fonts and cursors before the widget has
2462 been realized, so we do this directly after realization */
2463 g_signal_connect (connect_widget
, "realize",
2464 G_CALLBACK (gtk_window_realized_callback
), this);
2468 g_signal_connect(m_wxwindow
? m_wxwindow
: m_widget
, "size_allocate",
2469 G_CALLBACK(size_allocate
), this);
2474 #if GTK_CHECK_VERSION(2, 8, 0)
2475 if (!gtk_check_version(2,8,0))
2477 // Make sure we can notify the app when mouse capture is lost
2478 g_signal_connect (m_wxwindow
, "grab_broken_event",
2479 G_CALLBACK (gtk_window_grab_broken
), this);
2484 if ( connect_widget
!= m_wxwindow
)
2486 #if GTK_CHECK_VERSION(2, 8, 0)
2487 if (!gtk_check_version(2,8,0))
2489 // Make sure we can notify app code when mouse capture is lost
2490 g_signal_connect (connect_widget
, "grab_broken_event",
2491 G_CALLBACK (gtk_window_grab_broken
), this);
2496 #ifdef GTK_IS_FILE_CHOOSER_BUTTON
2497 if (!gtk_check_version(2,6,0) && GTK_IS_FILE_CHOOSER_BUTTON(m_widget
))
2499 // If we connect to the "size_request" signal of a GtkFileChooserButton
2500 // then that control won't be sized properly when placed inside sizers
2501 // (this can be tested removing this elseif and running XRC or WIDGETS samples)
2502 // FIXME: what should be done here ?
2505 if ( !IsTopLevel() ) // top level windows use their own callback
2507 // This is needed if we want to add our windows into native
2508 // GTK controls, such as the toolbar. With this callback, the
2509 // toolbar gets to know the correct size (the one set by the
2510 // programmer). Sadly, it misbehaves for wxComboBox.
2511 g_signal_connect (m_widget
, "size_request",
2512 G_CALLBACK (wxgtk_window_size_request_callback
),
2516 InheritAttributes();
2520 SetLayoutDirection(wxLayout_Default
);
2522 // unless the window was created initially hidden (i.e. Hide() had been
2523 // called before Create()), we should show it at GTK+ level as well
2525 gtk_widget_show( m_widget
);
2528 void wxWindowGTK::ConnectWidget( GtkWidget
*widget
)
2530 g_signal_connect (widget
, "key_press_event",
2531 G_CALLBACK (gtk_window_key_press_callback
), this);
2532 g_signal_connect (widget
, "key_release_event",
2533 G_CALLBACK (gtk_window_key_release_callback
), this);
2534 g_signal_connect (widget
, "button_press_event",
2535 G_CALLBACK (gtk_window_button_press_callback
), this);
2536 g_signal_connect (widget
, "button_release_event",
2537 G_CALLBACK (gtk_window_button_release_callback
), this);
2538 g_signal_connect (widget
, "motion_notify_event",
2539 G_CALLBACK (gtk_window_motion_notify_callback
), this);
2540 g_signal_connect (widget
, "scroll_event",
2541 G_CALLBACK (window_scroll_event
), this);
2542 g_signal_connect (widget
, "popup_menu",
2543 G_CALLBACK (wxgtk_window_popup_menu_callback
), this);
2544 g_signal_connect (widget
, "enter_notify_event",
2545 G_CALLBACK (gtk_window_enter_callback
), this);
2546 g_signal_connect (widget
, "leave_notify_event",
2547 G_CALLBACK (gtk_window_leave_callback
), this);
2549 if (IsTopLevel() && m_wxwindow
)
2550 g_signal_connect (m_wxwindow
, "style_set",
2551 G_CALLBACK (gtk_window_style_set_callback
), this);
2554 bool wxWindowGTK::Destroy()
2556 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2560 return wxWindowBase::Destroy();
2563 void wxWindowGTK::DoMoveWindow(int x
, int y
, int width
, int height
)
2565 gtk_widget_set_size_request(m_widget
, width
, height
);
2566 // inform the parent to perform the move
2567 WX_PIZZA(m_parent
->m_wxwindow
)->move(m_widget
, x
, y
);
2570 void wxWindowGTK::ConstrainSize()
2573 // GPE's window manager doesn't like size hints at all, esp. when the user
2574 // has to use the virtual keyboard, so don't constrain size there
2578 const wxSize minSize
= GetMinSize();
2579 const wxSize maxSize
= GetMaxSize();
2580 if (minSize
.x
> 0 && m_width
< minSize
.x
) m_width
= minSize
.x
;
2581 if (minSize
.y
> 0 && m_height
< minSize
.y
) m_height
= minSize
.y
;
2582 if (maxSize
.x
> 0 && m_width
> maxSize
.x
) m_width
= maxSize
.x
;
2583 if (maxSize
.y
> 0 && m_height
> maxSize
.y
) m_height
= maxSize
.y
;
2587 void wxWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
2589 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2590 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
2592 int currentX
, currentY
;
2593 GetPosition(¤tX
, ¤tY
);
2594 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2596 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2598 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2600 // calculate the best size if we should auto size the window
2601 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
2602 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
2604 const wxSize sizeBest
= GetBestSize();
2605 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
2607 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
2608 height
= sizeBest
.y
;
2611 const wxSize
oldSize(m_width
, m_height
);
2619 if (m_parent
->m_wxwindow
)
2621 wxPizza
* pizza
= WX_PIZZA(m_parent
->m_wxwindow
);
2622 m_x
= x
+ pizza
->m_scroll_x
;
2623 m_y
= y
+ pizza
->m_scroll_y
;
2625 int left_border
= 0;
2626 int right_border
= 0;
2628 int bottom_border
= 0;
2630 /* the default button has a border around it */
2631 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
2633 GtkBorder
*default_border
= NULL
;
2634 gtk_widget_style_get( m_widget
, "default_border", &default_border
, NULL
);
2637 left_border
+= default_border
->left
;
2638 right_border
+= default_border
->right
;
2639 top_border
+= default_border
->top
;
2640 bottom_border
+= default_border
->bottom
;
2641 gtk_border_free( default_border
);
2645 DoMoveWindow( m_x
- left_border
,
2647 m_width
+left_border
+right_border
,
2648 m_height
+top_border
+bottom_border
);
2651 if (m_width
!= oldSize
.x
|| m_height
!= oldSize
.y
)
2653 // update these variables to keep size_allocate handler
2654 // from sending another size event for this change
2655 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
2657 gtk_widget_queue_resize(m_widget
);
2658 if (!m_nativeSizeEvent
)
2660 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
2661 event
.SetEventObject( this );
2662 HandleWindowEvent( event
);
2667 bool wxWindowGTK::GtkShowFromOnIdle()
2669 if (IsShown() && m_showOnIdle
&& !GTK_WIDGET_VISIBLE (m_widget
))
2671 GtkAllocation alloc
;
2674 alloc
.width
= m_width
;
2675 alloc
.height
= m_height
;
2676 gtk_widget_size_allocate( m_widget
, &alloc
);
2677 gtk_widget_show( m_widget
);
2678 wxShowEvent
eventShow(GetId(), true);
2679 eventShow
.SetEventObject(this);
2680 HandleWindowEvent(eventShow
);
2681 m_showOnIdle
= false;
2688 void wxWindowGTK::OnInternalIdle()
2690 // Check if we have to show window now
2691 if (GtkShowFromOnIdle()) return;
2693 if ( m_dirtyTabOrder
)
2695 m_dirtyTabOrder
= false;
2699 // Update style if the window was not yet realized
2700 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
2701 if (m_needsStyleChange
)
2703 SetBackgroundStyle(GetBackgroundStyle());
2704 m_needsStyleChange
= false;
2707 wxCursor cursor
= m_cursor
;
2708 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
2712 /* I now set the cursor anew in every OnInternalIdle call
2713 as setting the cursor in a parent window also effects the
2714 windows above so that checking for the current cursor is
2717 if (m_wxwindow
&& (m_wxwindow
!= m_widget
))
2719 GdkWindow
*window
= m_wxwindow
->window
;
2721 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2723 if (!g_globalCursor
.Ok())
2724 cursor
= *wxSTANDARD_CURSOR
;
2726 window
= m_widget
->window
;
2727 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2728 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2731 else if ( m_widget
)
2733 GdkWindow
*window
= m_widget
->window
;
2734 if ( window
&& !GTK_WIDGET_NO_WINDOW(m_widget
) )
2735 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2739 if (wxUpdateUIEvent::CanUpdate(this) && IsShown())
2740 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2743 void wxWindowGTK::DoGetSize( int *width
, int *height
) const
2745 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2747 if (width
) (*width
) = m_width
;
2748 if (height
) (*height
) = m_height
;
2751 void wxWindowGTK::DoSetClientSize( int width
, int height
)
2753 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2755 const wxSize size
= GetSize();
2756 const wxSize clientSize
= GetClientSize();
2757 SetSize(width
+ (size
.x
- clientSize
.x
), height
+ (size
.y
- clientSize
.y
));
2760 void wxWindowGTK::DoGetClientSize( int *width
, int *height
) const
2762 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2773 GetScrollbarWidth(m_widget
, dw
, dh
);
2775 int border_x
, border_y
;
2776 WX_PIZZA(m_wxwindow
)->get_border_widths(border_x
, border_y
);
2788 if (width
) *width
= w
;
2789 if (height
) *height
= h
;
2792 void wxWindowGTK::DoGetPosition( int *x
, int *y
) const
2794 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2798 if (!IsTopLevel() && m_parent
&& m_parent
->m_wxwindow
)
2800 wxPizza
* pizza
= WX_PIZZA(m_parent
->m_wxwindow
);
2801 dx
= pizza
->m_scroll_x
;
2802 dy
= pizza
->m_scroll_y
;
2805 if (m_x
== -1 && m_y
== -1)
2807 GdkWindow
*source
= (GdkWindow
*) NULL
;
2809 source
= m_wxwindow
->window
;
2811 source
= m_widget
->window
;
2817 gdk_window_get_origin( source
, &org_x
, &org_y
);
2820 m_parent
->ScreenToClient(&org_x
, &org_y
);
2822 wx_const_cast(wxWindowGTK
*, this)->m_x
= org_x
;
2823 wx_const_cast(wxWindowGTK
*, this)->m_y
= org_y
;
2827 if (x
) (*x
) = m_x
- dx
;
2828 if (y
) (*y
) = m_y
- dy
;
2831 void wxWindowGTK::DoClientToScreen( int *x
, int *y
) const
2833 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2835 if (!m_widget
->window
) return;
2837 GdkWindow
*source
= (GdkWindow
*) NULL
;
2839 source
= m_wxwindow
->window
;
2841 source
= m_widget
->window
;
2845 gdk_window_get_origin( source
, &org_x
, &org_y
);
2849 if (GTK_WIDGET_NO_WINDOW (m_widget
))
2851 org_x
+= m_widget
->allocation
.x
;
2852 org_y
+= m_widget
->allocation
.y
;
2859 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2860 *x
= (GetClientSize().x
- *x
) + org_x
;
2868 void wxWindowGTK::DoScreenToClient( int *x
, int *y
) const
2870 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2872 if (!m_widget
->window
) return;
2874 GdkWindow
*source
= (GdkWindow
*) NULL
;
2876 source
= m_wxwindow
->window
;
2878 source
= m_widget
->window
;
2882 gdk_window_get_origin( source
, &org_x
, &org_y
);
2886 if (GTK_WIDGET_NO_WINDOW (m_widget
))
2888 org_x
+= m_widget
->allocation
.x
;
2889 org_y
+= m_widget
->allocation
.y
;
2895 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2896 *x
= (GetClientSize().x
- *x
) - org_x
;
2903 bool wxWindowGTK::Show( bool show
)
2905 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
2907 if (!wxWindowBase::Show(show
))
2913 if (show
&& m_showOnIdle
)
2920 gtk_widget_show(m_widget
);
2922 gtk_widget_hide(m_widget
);
2923 wxShowEvent
eventShow(GetId(), show
);
2924 eventShow
.SetEventObject(this);
2925 HandleWindowEvent(eventShow
);
2931 void wxWindowGTK::DoEnable( bool enable
)
2933 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2935 gtk_widget_set_sensitive( m_widget
, enable
);
2936 if (m_wxwindow
&& (m_wxwindow
!= m_widget
))
2937 gtk_widget_set_sensitive( m_wxwindow
, enable
);
2940 int wxWindowGTK::GetCharHeight() const
2942 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
2944 wxFont font
= GetFont();
2945 wxCHECK_MSG( font
.Ok(), 12, wxT("invalid font") );
2947 PangoContext
* context
= gtk_widget_get_pango_context(m_widget
);
2952 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
2953 PangoLayout
*layout
= pango_layout_new(context
);
2954 pango_layout_set_font_description(layout
, desc
);
2955 pango_layout_set_text(layout
, "H", 1);
2956 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
2958 PangoRectangle rect
;
2959 pango_layout_line_get_extents(line
, NULL
, &rect
);
2961 g_object_unref (layout
);
2963 return (int) PANGO_PIXELS(rect
.height
);
2966 int wxWindowGTK::GetCharWidth() const
2968 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
2970 wxFont font
= GetFont();
2971 wxCHECK_MSG( font
.Ok(), 8, wxT("invalid font") );
2973 PangoContext
* context
= gtk_widget_get_pango_context(m_widget
);
2978 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
2979 PangoLayout
*layout
= pango_layout_new(context
);
2980 pango_layout_set_font_description(layout
, desc
);
2981 pango_layout_set_text(layout
, "g", 1);
2982 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
2984 PangoRectangle rect
;
2985 pango_layout_line_get_extents(line
, NULL
, &rect
);
2987 g_object_unref (layout
);
2989 return (int) PANGO_PIXELS(rect
.width
);
2992 void wxWindowGTK::GetTextExtent( const wxString
& string
,
2996 int *externalLeading
,
2997 const wxFont
*theFont
) const
2999 wxFont fontToUse
= theFont
? *theFont
: GetFont();
3001 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
3010 PangoContext
*context
= NULL
;
3012 context
= gtk_widget_get_pango_context( m_widget
);
3021 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
3022 PangoLayout
*layout
= pango_layout_new(context
);
3023 pango_layout_set_font_description(layout
, desc
);
3025 const wxCharBuffer data
= wxGTK_CONV( string
);
3027 pango_layout_set_text(layout
, data
, strlen(data
));
3030 PangoRectangle rect
;
3031 pango_layout_get_extents(layout
, NULL
, &rect
);
3033 if (x
) (*x
) = (wxCoord
) PANGO_PIXELS(rect
.width
);
3034 if (y
) (*y
) = (wxCoord
) PANGO_PIXELS(rect
.height
);
3037 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
3038 int baseline
= pango_layout_iter_get_baseline(iter
);
3039 pango_layout_iter_free(iter
);
3040 *descent
= *y
- PANGO_PIXELS(baseline
);
3042 if (externalLeading
) (*externalLeading
) = 0; // ??
3044 g_object_unref (layout
);
3047 bool wxWindowGTK::GTKSetDelayedFocusIfNeeded()
3049 if ( g_delayedFocus
== this )
3051 if ( GTK_WIDGET_REALIZED(m_widget
) )
3053 gtk_widget_grab_focus(m_widget
);
3054 g_delayedFocus
= NULL
;
3063 void wxWindowGTK::SetFocus()
3065 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3068 // don't do anything if we already have focus
3074 // wxWindow::SetFocus() should really set the focus to
3075 // this control, whatever the flags are
3076 if (!GTK_WIDGET_CAN_FOCUS(m_wxwindow
))
3077 GTK_WIDGET_SET_FLAGS(m_wxwindow
, GTK_CAN_FOCUS
);
3079 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow
))
3081 gtk_widget_grab_focus (m_wxwindow
);
3086 // wxWindow::SetFocus() should really set the focus to
3087 // this control, whatever the flags are
3088 if (!GTK_WIDGET_CAN_FOCUS(m_widget
))
3089 GTK_WIDGET_SET_FLAGS(m_widget
, GTK_CAN_FOCUS
);
3091 if (GTK_IS_CONTAINER(m_widget
))
3093 if (GTK_IS_RADIO_BUTTON(m_widget
))
3095 gtk_widget_grab_focus (m_widget
);
3099 gtk_widget_child_focus( m_widget
, GTK_DIR_TAB_FORWARD
);
3102 if (GTK_WIDGET_CAN_FOCUS(m_widget
) && !GTK_WIDGET_HAS_FOCUS (m_widget
) )
3105 if (!GTK_WIDGET_REALIZED(m_widget
))
3107 // we can't set the focus to the widget now so we remember that
3108 // it should be focused and will do it later, during the idle
3109 // time, as soon as we can
3110 wxLogTrace(TRACE_FOCUS
,
3111 _T("Delaying setting focus to %s(%s)"),
3112 GetClassInfo()->GetClassName(), GetLabel().c_str());
3114 g_delayedFocus
= this;
3118 wxLogTrace(TRACE_FOCUS
,
3119 _T("Setting focus to %s(%s)"),
3120 GetClassInfo()->GetClassName(), GetLabel().c_str());
3122 gtk_widget_grab_focus (m_widget
);
3127 wxLogTrace(TRACE_FOCUS
,
3128 _T("Can't set focus to %s(%s)"),
3129 GetClassInfo()->GetClassName(), GetLabel().c_str());
3134 void wxWindowGTK::SetCanFocus(bool canFocus
)
3137 GTK_WIDGET_SET_FLAGS(m_widget
, GTK_CAN_FOCUS
);
3139 GTK_WIDGET_UNSET_FLAGS(m_widget
, GTK_CAN_FOCUS
);
3141 if ( m_wxwindow
&& (m_widget
!= m_wxwindow
) )
3144 GTK_WIDGET_SET_FLAGS(m_wxwindow
, GTK_CAN_FOCUS
);
3146 GTK_WIDGET_UNSET_FLAGS(m_wxwindow
, GTK_CAN_FOCUS
);
3150 bool wxWindowGTK::Reparent( wxWindowBase
*newParentBase
)
3152 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3154 wxWindowGTK
*oldParent
= m_parent
,
3155 *newParent
= (wxWindowGTK
*)newParentBase
;
3157 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3159 if ( !wxWindowBase::Reparent(newParent
) )
3162 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3164 /* prevent GTK from deleting the widget arbitrarily */
3165 gtk_widget_ref( m_widget
);
3169 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3172 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3176 if (GTK_WIDGET_VISIBLE (newParent
->m_widget
))
3178 m_showOnIdle
= true;
3179 gtk_widget_hide( m_widget
);
3182 /* insert GTK representation */
3183 (*(newParent
->m_insertCallback
))(newParent
, this);
3186 /* reverse: prevent GTK from deleting the widget arbitrarily */
3187 gtk_widget_unref( m_widget
);
3189 SetLayoutDirection(wxLayout_Default
);
3194 void wxWindowGTK::DoAddChild(wxWindowGTK
*child
)
3196 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3197 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3202 /* insert GTK representation */
3203 (*m_insertCallback
)(this, child
);
3206 void wxWindowGTK::AddChild(wxWindowBase
*child
)
3208 wxWindowBase::AddChild(child
);
3209 m_dirtyTabOrder
= true;
3210 wxTheApp
->WakeUpIdle();
3213 void wxWindowGTK::RemoveChild(wxWindowBase
*child
)
3215 wxWindowBase::RemoveChild(child
);
3216 m_dirtyTabOrder
= true;
3217 wxTheApp
->WakeUpIdle();
3221 wxLayoutDirection
wxWindowGTK::GTKGetLayout(GtkWidget
*widget
)
3223 return gtk_widget_get_direction(widget
) == GTK_TEXT_DIR_RTL
3224 ? wxLayout_RightToLeft
3225 : wxLayout_LeftToRight
;
3229 void wxWindowGTK::GTKSetLayout(GtkWidget
*widget
, wxLayoutDirection dir
)
3231 wxASSERT_MSG( dir
!= wxLayout_Default
, _T("invalid layout direction") );
3233 gtk_widget_set_direction(widget
,
3234 dir
== wxLayout_RightToLeft
? GTK_TEXT_DIR_RTL
3235 : GTK_TEXT_DIR_LTR
);
3238 wxLayoutDirection
wxWindowGTK::GetLayoutDirection() const
3240 return GTKGetLayout(m_widget
);
3243 void wxWindowGTK::SetLayoutDirection(wxLayoutDirection dir
)
3245 if ( dir
== wxLayout_Default
)
3247 const wxWindow
*const parent
= GetParent();
3250 // inherit layout from parent.
3251 dir
= parent
->GetLayoutDirection();
3253 else // no parent, use global default layout
3255 dir
= wxTheApp
->GetLayoutDirection();
3259 if ( dir
== wxLayout_Default
)
3262 GTKSetLayout(m_widget
, dir
);
3264 if (m_wxwindow
&& (m_wxwindow
!= m_widget
))
3265 GTKSetLayout(m_wxwindow
, dir
);
3269 wxWindowGTK::AdjustForLayoutDirection(wxCoord x
,
3270 wxCoord
WXUNUSED(width
),
3271 wxCoord
WXUNUSED(widthTotal
)) const
3273 // We now mirror the coordinates of RTL windows in wxPizza
3277 void wxWindowGTK::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
3279 wxWindowBase::DoMoveInTabOrder(win
, move
);
3280 m_dirtyTabOrder
= true;
3281 wxTheApp
->WakeUpIdle();
3284 bool wxWindowGTK::DoNavigateIn(int flags
)
3286 if ( flags
& wxNavigationKeyEvent::WinChange
)
3288 wxFAIL_MSG( _T("not implemented") );
3292 else // navigate inside the container
3294 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3295 wxCHECK_MSG( parent
, false, _T("every window must have a TLW parent") );
3297 GtkDirectionType dir
;
3298 dir
= flags
& wxNavigationKeyEvent::IsForward
? GTK_DIR_TAB_FORWARD
3299 : GTK_DIR_TAB_BACKWARD
;
3302 g_signal_emit_by_name(parent
->m_widget
, "focus", dir
, &rc
);
3308 bool wxWindowGTK::GTKWidgetNeedsMnemonic() const
3310 // none needed by default
3314 void wxWindowGTK::GTKWidgetDoSetMnemonic(GtkWidget
* WXUNUSED(w
))
3316 // nothing to do by default since none is needed
3319 void wxWindowGTK::RealizeTabOrder()
3323 if ( !m_children
.empty() )
3325 // we don't only construct the correct focus chain but also use
3326 // this opportunity to update the mnemonic widgets for the widgets
3329 GList
*chain
= NULL
;
3330 wxWindowGTK
* mnemonicWindow
= NULL
;
3332 for ( wxWindowList::const_iterator i
= m_children
.begin();
3333 i
!= m_children
.end();
3336 wxWindowGTK
*win
= *i
;
3338 if ( mnemonicWindow
)
3340 if ( win
->AcceptsFocusFromKeyboard() )
3342 // wxComboBox et al. needs to focus on on a different
3343 // widget than m_widget, so if the main widget isn't
3344 // focusable try the connect widget
3345 GtkWidget
* w
= win
->m_widget
;
3346 if ( !GTK_WIDGET_CAN_FOCUS(w
) )
3348 w
= win
->GetConnectWidget();
3349 if ( !GTK_WIDGET_CAN_FOCUS(w
) )
3355 mnemonicWindow
->GTKWidgetDoSetMnemonic(w
);
3356 mnemonicWindow
= NULL
;
3360 else if ( win
->GTKWidgetNeedsMnemonic() )
3362 mnemonicWindow
= win
;
3365 chain
= g_list_prepend(chain
, win
->m_widget
);
3368 chain
= g_list_reverse(chain
);
3370 gtk_container_set_focus_chain(GTK_CONTAINER(m_wxwindow
), chain
);
3375 gtk_container_unset_focus_chain(GTK_CONTAINER(m_wxwindow
));
3380 void wxWindowGTK::Raise()
3382 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3384 if (m_wxwindow
&& m_wxwindow
->window
)
3386 gdk_window_raise( m_wxwindow
->window
);
3388 else if (m_widget
->window
)
3390 gdk_window_raise( m_widget
->window
);
3394 void wxWindowGTK::Lower()
3396 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3398 if (m_wxwindow
&& m_wxwindow
->window
)
3400 gdk_window_lower( m_wxwindow
->window
);
3402 else if (m_widget
->window
)
3404 gdk_window_lower( m_widget
->window
);
3408 bool wxWindowGTK::SetCursor( const wxCursor
&cursor
)
3410 if ( !wxWindowBase::SetCursor(cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
) )
3418 void wxWindowGTK::GTKUpdateCursor()
3420 wxCursor
cursor(g_globalCursor
.Ok() ? g_globalCursor
: GetCursor());
3423 wxArrayGdkWindows windowsThis
;
3424 GdkWindow
* const winThis
= GTKGetWindow(windowsThis
);
3427 gdk_window_set_cursor(winThis
, cursor
.GetCursor());
3431 const size_t count
= windowsThis
.size();
3432 for ( size_t n
= 0; n
< count
; n
++ )
3434 GdkWindow
*win
= windowsThis
[n
];
3437 wxFAIL_MSG(_T("NULL window returned by GTKGetWindow()?"));
3441 gdk_window_set_cursor(win
, cursor
.GetCursor());
3447 void wxWindowGTK::WarpPointer( int x
, int y
)
3449 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3451 // We provide this function ourselves as it is
3452 // missing in GDK (top of this file).
3454 GdkWindow
*window
= (GdkWindow
*) NULL
;
3456 window
= m_wxwindow
->window
;
3458 window
= GetConnectWidget()->window
;
3461 gdk_window_warp_pointer( window
, x
, y
);
3464 wxWindowGTK::ScrollDir
wxWindowGTK::ScrollDirFromRange(GtkRange
*range
) const
3466 // find the scrollbar which generated the event
3467 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
3469 if ( range
== m_scrollBar
[dir
] )
3470 return (ScrollDir
)dir
;
3473 wxFAIL_MSG( _T("event from unknown scrollbar received") );
3475 return ScrollDir_Max
;
3478 bool wxWindowGTK::DoScrollByUnits(ScrollDir dir
, ScrollUnit unit
, int units
)
3480 bool changed
= false;
3481 GtkRange
* range
= m_scrollBar
[dir
];
3482 if ( range
&& units
)
3484 GtkAdjustment
* adj
= range
->adjustment
;
3485 gdouble inc
= unit
== ScrollUnit_Line
? adj
->step_increment
3486 : adj
->page_increment
;
3488 const int posOld
= int(adj
->value
+ 0.5);
3489 gtk_range_set_value(range
, posOld
+ units
*inc
);
3491 changed
= int(adj
->value
+ 0.5) != posOld
;
3497 bool wxWindowGTK::ScrollLines(int lines
)
3499 return DoScrollByUnits(ScrollDir_Vert
, ScrollUnit_Line
, lines
);
3502 bool wxWindowGTK::ScrollPages(int pages
)
3504 return DoScrollByUnits(ScrollDir_Vert
, ScrollUnit_Page
, pages
);
3507 void wxWindowGTK::Refresh(bool WXUNUSED(eraseBackground
),
3512 if (!m_widget
->window
)
3517 if (m_wxwindow
->window
== NULL
) return;
3519 GdkRectangle gdk_rect
,
3523 gdk_rect
.x
= rect
->x
;
3524 gdk_rect
.y
= rect
->y
;
3525 gdk_rect
.width
= rect
->width
;
3526 gdk_rect
.height
= rect
->height
;
3527 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3528 gdk_rect
.x
= GetClientSize().x
- gdk_rect
.x
- gdk_rect
.width
;
3532 else // invalidate everything
3537 gdk_window_invalidate_rect(m_wxwindow
->window
, p
, true);
3541 void wxWindowGTK::Update()
3545 // when we call Update() we really want to update the window immediately on
3546 // screen, even if it means flushing the entire queue and hence slowing down
3547 // everything -- but it should still be done, it's just that Update() should
3548 // be called very rarely
3552 void wxWindowGTK::GtkUpdate()
3554 if (m_wxwindow
&& m_wxwindow
->window
)
3555 gdk_window_process_updates(m_wxwindow
->window
, false);
3556 if (m_widget
&& m_widget
->window
&& (m_wxwindow
!= m_widget
))
3557 gdk_window_process_updates( m_widget
->window
, FALSE
);
3559 // for consistency with other platforms (and also because it's convenient
3560 // to be able to update an entire TLW by calling Update() only once), we
3561 // should also update all our children here
3562 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3564 node
= node
->GetNext() )
3566 node
->GetData()->GtkUpdate();
3570 bool wxWindowGTK::DoIsExposed( int x
, int y
) const
3572 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
3576 bool wxWindowGTK::DoIsExposed( int x
, int y
, int w
, int h
) const
3578 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3579 return m_updateRegion
.Contains(x
-w
, y
, w
, h
) != wxOutRegion
;
3581 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
3584 void wxWindowGTK::GtkSendPaintEvents()
3588 m_updateRegion
.Clear();
3592 // Clip to paint region in wxClientDC
3593 m_clipPaintRegion
= true;
3595 m_nativeUpdateRegion
= m_updateRegion
;
3597 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3599 // Transform m_updateRegion under RTL
3600 m_updateRegion
.Clear();
3603 gdk_drawable_get_size(m_wxwindow
->window
, &width
, NULL
);
3605 wxRegionIterator
upd( m_nativeUpdateRegion
);
3609 rect
.x
= upd
.GetX();
3610 rect
.y
= upd
.GetY();
3611 rect
.width
= upd
.GetWidth();
3612 rect
.height
= upd
.GetHeight();
3614 rect
.x
= width
- rect
.x
- rect
.width
;
3615 m_updateRegion
.Union( rect
);
3621 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM
))
3623 // find ancestor from which to steal background
3624 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3626 parent
= (wxWindow
*)this;
3628 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
3630 wxRegionIterator
upd( m_nativeUpdateRegion
);
3634 rect
.x
= upd
.GetX();
3635 rect
.y
= upd
.GetY();
3636 rect
.width
= upd
.GetWidth();
3637 rect
.height
= upd
.GetHeight();
3639 gtk_paint_flat_box( parent
->m_widget
->style
,
3641 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
3654 wxWindowDC
dc( (wxWindow
*)this );
3655 dc
.SetClippingRegion( m_updateRegion
);
3657 // Work around gtk-qt <= 0.60 bug whereby the window colour
3659 if (GetBackgroundStyle() == wxBG_STYLE_COLOUR
&& GetBackgroundColour().Ok() && wxSystemOptions::GetOptionInt(wxT("gtk.window.force-background-colour")) == 1)
3661 dc
.SetBackground(wxBrush(GetBackgroundColour()));
3665 wxEraseEvent
erase_event( GetId(), &dc
);
3666 erase_event
.SetEventObject( this );
3668 HandleWindowEvent(erase_event
);
3671 wxNcPaintEvent
nc_paint_event( GetId() );
3672 nc_paint_event
.SetEventObject( this );
3673 HandleWindowEvent( nc_paint_event
);
3675 wxPaintEvent
paint_event( GetId() );
3676 paint_event
.SetEventObject( this );
3677 HandleWindowEvent( paint_event
);
3679 m_clipPaintRegion
= false;
3681 m_updateRegion
.Clear();
3682 m_nativeUpdateRegion
.Clear();
3685 void wxWindowGTK::SetDoubleBuffered( bool on
)
3687 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3690 gtk_widget_set_double_buffered( m_wxwindow
, on
);
3693 bool wxWindowGTK::IsDoubleBuffered() const
3695 return GTK_WIDGET_DOUBLE_BUFFERED( m_wxwindow
);
3698 void wxWindowGTK::ClearBackground()
3700 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3704 void wxWindowGTK::DoSetToolTip( wxToolTip
*tip
)
3706 wxWindowBase::DoSetToolTip(tip
);
3709 m_tooltip
->Apply( (wxWindow
*)this );
3712 void wxWindowGTK::ApplyToolTip( GtkTooltips
*tips
, const gchar
*tip
)
3714 gtk_tooltips_set_tip(tips
, GetConnectWidget(), tip
, NULL
);
3716 #endif // wxUSE_TOOLTIPS
3718 bool wxWindowGTK::SetBackgroundColour( const wxColour
&colour
)
3720 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3722 if (!wxWindowBase::SetBackgroundColour(colour
))
3727 // We need the pixel value e.g. for background clearing.
3728 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3731 // apply style change (forceStyle=true so that new style is applied
3732 // even if the bg colour changed from valid to wxNullColour)
3733 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3734 ApplyWidgetStyle(true);
3739 bool wxWindowGTK::SetForegroundColour( const wxColour
&colour
)
3741 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3743 if (!wxWindowBase::SetForegroundColour(colour
))
3750 // We need the pixel value e.g. for background clearing.
3751 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3754 // apply style change (forceStyle=true so that new style is applied
3755 // even if the bg colour changed from valid to wxNullColour):
3756 ApplyWidgetStyle(true);
3761 PangoContext
*wxWindowGTK::GtkGetPangoDefaultContext()
3763 return gtk_widget_get_pango_context( m_widget
);
3766 GtkRcStyle
*wxWindowGTK::CreateWidgetStyle(bool forceStyle
)
3768 // do we need to apply any changes at all?
3771 !m_foregroundColour
.Ok() && !m_backgroundColour
.Ok() )
3776 GtkRcStyle
*style
= gtk_rc_style_new();
3781 pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
3784 int flagsNormal
= 0,
3787 flagsInsensitive
= 0;
3789 if ( m_foregroundColour
.Ok() )
3791 const GdkColor
*fg
= m_foregroundColour
.GetColor();
3793 style
->fg
[GTK_STATE_NORMAL
] =
3794 style
->text
[GTK_STATE_NORMAL
] = *fg
;
3795 flagsNormal
|= GTK_RC_FG
| GTK_RC_TEXT
;
3797 style
->fg
[GTK_STATE_PRELIGHT
] =
3798 style
->text
[GTK_STATE_PRELIGHT
] = *fg
;
3799 flagsPrelight
|= GTK_RC_FG
| GTK_RC_TEXT
;
3801 style
->fg
[GTK_STATE_ACTIVE
] =
3802 style
->text
[GTK_STATE_ACTIVE
] = *fg
;
3803 flagsActive
|= GTK_RC_FG
| GTK_RC_TEXT
;
3806 if ( m_backgroundColour
.Ok() )
3808 const GdkColor
*bg
= m_backgroundColour
.GetColor();
3810 style
->bg
[GTK_STATE_NORMAL
] =
3811 style
->base
[GTK_STATE_NORMAL
] = *bg
;
3812 flagsNormal
|= GTK_RC_BG
| GTK_RC_BASE
;
3814 style
->bg
[GTK_STATE_PRELIGHT
] =
3815 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
3816 flagsPrelight
|= GTK_RC_BG
| GTK_RC_BASE
;
3818 style
->bg
[GTK_STATE_ACTIVE
] =
3819 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
3820 flagsActive
|= GTK_RC_BG
| GTK_RC_BASE
;
3822 style
->bg
[GTK_STATE_INSENSITIVE
] =
3823 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
3824 flagsInsensitive
|= GTK_RC_BG
| GTK_RC_BASE
;
3827 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)flagsNormal
;
3828 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)flagsPrelight
;
3829 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)flagsActive
;
3830 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)flagsInsensitive
;
3835 void wxWindowGTK::ApplyWidgetStyle(bool forceStyle
)
3837 GtkRcStyle
*style
= CreateWidgetStyle(forceStyle
);
3840 DoApplyWidgetStyle(style
);
3841 gtk_rc_style_unref(style
);
3844 // Style change may affect GTK+'s size calculation:
3845 InvalidateBestSize();
3848 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle
*style
)
3850 wxSuspendStyleEvents
s(static_cast<wxWindow
*>(this));
3853 gtk_widget_modify_style(m_wxwindow
, style
);
3855 gtk_widget_modify_style(m_widget
, style
);
3858 bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style
)
3860 wxWindowBase::SetBackgroundStyle(style
);
3862 if (style
== wxBG_STYLE_CUSTOM
)
3867 window
= m_wxwindow
->window
;
3871 GtkWidget
* const w
= GetConnectWidget();
3872 window
= w
? w
->window
: NULL
;
3877 // Make sure GDK/X11 doesn't refresh the window
3879 gdk_window_set_back_pixmap( window
, None
, False
);
3881 Display
* display
= GDK_WINDOW_DISPLAY(window
);
3884 m_needsStyleChange
= false;
3886 else // window not realized yet
3888 // Do in OnIdle, because the window is not yet available
3889 m_needsStyleChange
= true;
3892 // Don't apply widget style, or we get a grey background
3896 // apply style change (forceStyle=true so that new style is applied
3897 // even if the bg colour changed from valid to wxNullColour):
3898 ApplyWidgetStyle(true);
3903 #if wxUSE_DRAG_AND_DROP
3905 void wxWindowGTK::SetDropTarget( wxDropTarget
*dropTarget
)
3907 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3909 GtkWidget
*dnd_widget
= GetConnectWidget();
3911 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
3913 if (m_dropTarget
) delete m_dropTarget
;
3914 m_dropTarget
= dropTarget
;
3916 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
3919 #endif // wxUSE_DRAG_AND_DROP
3921 GtkWidget
* wxWindowGTK::GetConnectWidget()
3923 GtkWidget
*connect_widget
= m_widget
;
3924 if (m_wxwindow
) connect_widget
= m_wxwindow
;
3926 return connect_widget
;
3929 bool wxWindowGTK::GTKIsOwnWindow(GdkWindow
*window
) const
3931 wxArrayGdkWindows windowsThis
;
3932 GdkWindow
* const winThis
= GTKGetWindow(windowsThis
);
3934 return winThis
? window
== winThis
3935 : windowsThis
.Index(window
) != wxNOT_FOUND
;
3938 GdkWindow
*wxWindowGTK::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
3940 return m_wxwindow
? m_wxwindow
->window
: m_widget
->window
;
3943 bool wxWindowGTK::SetFont( const wxFont
&font
)
3945 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3947 if (!wxWindowBase::SetFont(font
))
3950 // apply style change (forceStyle=true so that new style is applied
3951 // even if the font changed from valid to wxNullFont):
3952 ApplyWidgetStyle(true);
3957 void wxWindowGTK::DoCaptureMouse()
3959 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3961 GdkWindow
*window
= (GdkWindow
*) NULL
;
3963 window
= m_wxwindow
->window
;
3965 window
= GetConnectWidget()->window
;
3967 wxCHECK_RET( window
, _T("CaptureMouse() failed") );
3969 const wxCursor
* cursor
= &m_cursor
;
3971 cursor
= wxSTANDARD_CURSOR
;
3973 gdk_pointer_grab( window
, FALSE
,
3975 (GDK_BUTTON_PRESS_MASK
|
3976 GDK_BUTTON_RELEASE_MASK
|
3977 GDK_POINTER_MOTION_HINT_MASK
|
3978 GDK_POINTER_MOTION_MASK
),
3980 cursor
->GetCursor(),
3981 (guint32
)GDK_CURRENT_TIME
);
3982 g_captureWindow
= this;
3983 g_captureWindowHasMouse
= true;
3986 void wxWindowGTK::DoReleaseMouse()
3988 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3990 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
3992 g_captureWindow
= (wxWindowGTK
*) NULL
;
3994 GdkWindow
*window
= (GdkWindow
*) NULL
;
3996 window
= m_wxwindow
->window
;
3998 window
= GetConnectWidget()->window
;
4003 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
4006 void wxWindowGTK::GTKReleaseMouseAndNotify()
4009 wxMouseCaptureLostEvent
evt(GetId());
4010 evt
.SetEventObject( this );
4011 HandleWindowEvent( evt
);
4015 wxWindow
*wxWindowBase::GetCapture()
4017 return (wxWindow
*)g_captureWindow
;
4020 bool wxWindowGTK::IsRetained() const
4025 void wxWindowGTK::SetScrollbar(int orient
,
4029 bool WXUNUSED(update
))
4031 const int dir
= ScrollDirFromOrient(orient
);
4032 GtkRange
* const sb
= m_scrollBar
[dir
];
4033 wxCHECK_RET( sb
, _T("this window is not scrollable") );
4037 m_hasScrolling
= true;
4041 // GtkRange requires upper > lower
4046 GtkAdjustment
* const adj
= sb
->adjustment
;
4047 adj
->step_increment
= 1;
4048 adj
->page_increment
=
4049 adj
->page_size
= thumbVisible
;
4052 g_signal_handlers_block_by_func(
4053 sb
, (void*)gtk_scrollbar_value_changed
, this);
4055 gtk_range_set_range(sb
, 0, range
);
4056 m_scrollPos
[dir
] = sb
->adjustment
->value
;
4058 g_signal_handlers_unblock_by_func(
4059 sb
, (void*)gtk_scrollbar_value_changed
, this);
4062 void wxWindowGTK::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
4064 const int dir
= ScrollDirFromOrient(orient
);
4065 GtkRange
* const sb
= m_scrollBar
[dir
];
4066 wxCHECK_RET( sb
, _T("this window is not scrollable") );
4068 // This check is more than an optimization. Without it, the slider
4069 // will not move smoothly while tracking when using wxScrollHelper.
4070 if (GetScrollPos(orient
) != pos
)
4072 g_signal_handlers_block_by_func(
4073 sb
, (void*)gtk_scrollbar_value_changed
, this);
4075 gtk_range_set_value(sb
, pos
);
4076 m_scrollPos
[dir
] = sb
->adjustment
->value
;
4078 g_signal_handlers_unblock_by_func(
4079 sb
, (void*)gtk_scrollbar_value_changed
, this);
4083 int wxWindowGTK::GetScrollThumb(int orient
) const
4085 GtkRange
* const sb
= m_scrollBar
[ScrollDirFromOrient(orient
)];
4086 wxCHECK_MSG( sb
, 0, _T("this window is not scrollable") );
4088 return int(sb
->adjustment
->page_size
);
4091 int wxWindowGTK::GetScrollPos( int orient
) const
4093 GtkRange
* const sb
= m_scrollBar
[ScrollDirFromOrient(orient
)];
4094 wxCHECK_MSG( sb
, 0, _T("this window is not scrollable") );
4096 return int(sb
->adjustment
->value
+ 0.5);
4099 int wxWindowGTK::GetScrollRange( int orient
) const
4101 GtkRange
* const sb
= m_scrollBar
[ScrollDirFromOrient(orient
)];
4102 wxCHECK_MSG( sb
, 0, _T("this window is not scrollable") );
4104 return int(sb
->adjustment
->upper
);
4107 // Determine if increment is the same as +/-x, allowing for some small
4108 // difference due to possible inexactness in floating point arithmetic
4109 static inline bool IsScrollIncrement(double increment
, double x
)
4111 wxASSERT(increment
> 0);
4112 const double tolerance
= 1.0 / 1024;
4113 return fabs(increment
- fabs(x
)) < tolerance
;
4116 wxEventType
wxWindowGTK::GetScrollEventType(GtkRange
* range
)
4120 wxASSERT(range
== m_scrollBar
[0] || range
== m_scrollBar
[1]);
4122 const int barIndex
= range
== m_scrollBar
[1];
4123 GtkAdjustment
* adj
= range
->adjustment
;
4125 const int value
= int(adj
->value
+ 0.5);
4127 // save previous position
4128 const double oldPos
= m_scrollPos
[barIndex
];
4129 // update current position
4130 m_scrollPos
[barIndex
] = adj
->value
;
4131 // If event should be ignored, or integral position has not changed
4132 if (!m_hasVMT
|| g_blockEventsOnDrag
|| value
== int(oldPos
+ 0.5))
4137 wxEventType eventType
= wxEVT_SCROLL_THUMBTRACK
;
4140 // Difference from last change event
4141 const double diff
= adj
->value
- oldPos
;
4142 const bool isDown
= diff
> 0;
4144 if (IsScrollIncrement(adj
->step_increment
, diff
))
4146 eventType
= isDown
? wxEVT_SCROLL_LINEDOWN
: wxEVT_SCROLL_LINEUP
;
4148 else if (IsScrollIncrement(adj
->page_increment
, diff
))
4150 eventType
= isDown
? wxEVT_SCROLL_PAGEDOWN
: wxEVT_SCROLL_PAGEUP
;
4152 else if (m_mouseButtonDown
)
4154 // Assume track event
4155 m_isScrolling
= true;
4161 void wxWindowGTK::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4163 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4165 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4167 // No scrolling requested.
4168 if ((dx
== 0) && (dy
== 0)) return;
4170 m_clipPaintRegion
= true;
4172 WX_PIZZA(m_wxwindow
)->scroll(dx
, dy
);
4174 m_clipPaintRegion
= false;
4177 bool restoreCaret
= (GetCaret() != NULL
&& GetCaret()->IsVisible());
4180 wxRect
caretRect(GetCaret()->GetPosition(), GetCaret()->GetSize());
4182 caretRect
.width
+= dx
;
4185 caretRect
.x
+= dx
; caretRect
.width
-= dx
;
4188 caretRect
.height
+= dy
;
4191 caretRect
.y
+= dy
; caretRect
.height
-= dy
;
4194 RefreshRect(caretRect
);
4196 #endif // wxUSE_CARET
4199 void wxWindowGTK::GtkScrolledWindowSetBorder(GtkWidget
* w
, int wxstyle
)
4201 //RN: Note that static controls usually have no border on gtk, so maybe
4202 //it makes sense to treat that as simply no border at the wx level
4204 if (!(wxstyle
& wxNO_BORDER
) && !(wxstyle
& wxBORDER_STATIC
))
4206 GtkShadowType gtkstyle
;
4208 if(wxstyle
& wxBORDER_RAISED
)
4209 gtkstyle
= GTK_SHADOW_OUT
;
4210 else if (wxstyle
& wxBORDER_SUNKEN
)
4211 gtkstyle
= GTK_SHADOW_IN
;
4214 else if (wxstyle
& wxBORDER_DOUBLE
)
4215 gtkstyle
= GTK_SHADOW_ETCHED_IN
;
4218 gtkstyle
= GTK_SHADOW_IN
;
4220 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(w
),
4225 void wxWindowGTK::SetWindowStyleFlag( long style
)
4227 // Updates the internal variable. NB: Now m_windowStyle bits carry the _new_ style values already
4228 wxWindowBase::SetWindowStyleFlag(style
);
4231 // Find the wxWindow at the current mouse position, also returning the mouse
4233 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4235 pt
= wxGetMousePosition();
4236 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4240 // Get the current mouse position.
4241 wxPoint
wxGetMousePosition()
4243 /* This crashes when used within wxHelpContext,
4244 so we have to use the X-specific implementation below.
4246 GdkModifierType *mask;
4247 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4249 return wxPoint(x, y);
4253 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4255 Display
*display
= windowAtPtr
? GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4256 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4257 Window rootReturn
, childReturn
;
4258 int rootX
, rootY
, winX
, winY
;
4259 unsigned int maskReturn
;
4261 XQueryPointer (display
,
4265 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4266 return wxPoint(rootX
, rootY
);
4270 GdkWindow
* wxWindowGTK::GTKGetDrawingWindow() const
4272 GdkWindow
* window
= NULL
;
4274 window
= m_wxwindow
->window
;