1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/window.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Julian Smart
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
14 #define XWarpPointer XWARPPOINTER
17 #include "wx/window.h"
25 #include "wx/dcclient.h"
27 #include "wx/dialog.h"
28 #include "wx/settings.h"
29 #include "wx/msgdlg.h"
30 #include "wx/textctrl.h"
31 #include "wx/radiobut.h"
32 #include "wx/toolbar.h"
33 #include "wx/combobox.h"
34 #include "wx/layout.h"
35 #include "wx/statusbr.h"
37 #include "wx/module.h"
40 #if wxUSE_DRAG_AND_DROP
45 #include "wx/tooltip.h"
52 #include "wx/fontutil.h"
55 #include "wx/thread.h"
60 // FIXME: Due to a hack we use GtkCombo in here, which is deprecated since gtk2.3.0
61 #include <gtk/gtkversion.h>
62 #if defined(GTK_DISABLE_DEPRECATED) && GTK_CHECK_VERSION(2,3,0)
63 #undef GTK_DISABLE_DEPRECATED
66 #include "wx/gtk/private.h"
67 #include <gdk/gdkprivate.h>
68 #include <gdk/gdkkeysyms.h>
72 #include <gtk/gtkprivate.h>
74 #include "wx/gtk/win_gtk.h"
76 #include <pango/pangox.h>
82 //-----------------------------------------------------------------------------
83 // documentation on internals
84 //-----------------------------------------------------------------------------
87 I have been asked several times about writing some documentation about
88 the GTK port of wxWidgets, especially its internal structures. Obviously,
89 you cannot understand wxGTK without knowing a little about the GTK, but
90 some more information about what the wxWindow, which is the base class
91 for all other window classes, does seems required as well.
95 What does wxWindow do? It contains the common interface for the following
96 jobs of its descendants:
98 1) Define the rudimentary behaviour common to all window classes, such as
99 resizing, intercepting user input (so as to make it possible to use these
100 events for special purposes in a derived class), window names etc.
102 2) Provide the possibility to contain and manage children, if the derived
103 class is allowed to contain children, which holds true for those window
104 classes which do not display a native GTK widget. To name them, these
105 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
106 work classes are a special case and are handled a bit differently from
107 the rest. The same holds true for the wxNotebook class.
109 3) Provide the possibility to draw into a client area of a window. This,
110 too, only holds true for classes that do not display a native GTK widget
113 4) Provide the entire mechanism for scrolling widgets. This actual inter-
114 face for this is usually in wxScrolledWindow, but the GTK implementation
117 5) A multitude of helper or extra methods for special purposes, such as
118 Drag'n'Drop, managing validators etc.
120 6) Display a border (sunken, raised, simple or none).
122 Normally one might expect, that one wxWidgets window would always correspond
123 to one GTK widget. Under GTK, there is no such all-round widget that has all
124 the functionality. Moreover, the GTK defines a client area as a different
125 widget from the actual widget you are handling. Last but not least some
126 special classes (e.g. wxFrame) handle different categories of widgets and
127 still have the possibility to draw something in the client area.
128 It was therefore required to write a special purpose GTK widget, that would
129 represent a client area in the sense of wxWidgets capable to do the jobs
130 2), 3) and 4). I have written this class and it resides in win_gtk.c of
133 All windows must have a widget, with which they interact with other under-
134 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
135 the wxWindow class has a member variable called m_widget which holds a
136 pointer to this widget. When the window class represents a GTK native widget,
137 this is (in most cases) the only GTK widget the class manages. E.g. the
138 wxStaticText class handles only a GtkLabel widget a pointer to which you
139 can find in m_widget (defined in wxWindow)
141 When the class has a client area for drawing into and for containing children
142 it has to handle the client area widget (of the type GtkPizza, defined in
143 win_gtk.c), but there could be any number of widgets, handled by a class
144 The common rule for all windows is only, that the widget that interacts with
145 the rest of GTK must be referenced in m_widget and all other widgets must be
146 children of this widget on the GTK level. The top-most widget, which also
147 represents the client area, must be in the m_wxwindow field and must be of
150 As I said, the window classes that display a GTK native widget only have
151 one widget, so in the case of e.g. the wxButton class m_widget holds a
152 pointer to a GtkButton widget. But windows with client areas (for drawing
153 and children) have a m_widget field that is a pointer to a GtkScrolled-
154 Window and a m_wxwindow field that is pointer to a GtkPizza and this
155 one is (in the GTK sense) a child of the GtkScrolledWindow.
157 If the m_wxwindow field is set, then all input to this widget is inter-
158 cepted and sent to the wxWidgets class. If not, all input to the widget
159 that gets pointed to by m_widget gets intercepted and sent to the class.
163 The design of scrolling in wxWidgets is markedly different from that offered
164 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
165 clicking on a scrollbar belonging to scrolled window will inevitably move
166 the window. In wxWidgets, the scrollbar will only emit an event, send this
167 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
168 which actually moves the window and its sub-windows. Note that GtkPizza
169 memorizes how much it has been scrolled but that wxWidgets forgets this
170 so that the two coordinates systems have to be kept in synch. This is done
171 in various places using the pizza->xoffset and pizza->yoffset values.
175 Singularly the most broken code in GTK is the code that is supposed to
176 inform subwindows (child windows) about new positions. Very often, duplicate
177 events are sent without changes in size or position, equally often no
178 events are sent at all (All this is due to a bug in the GtkContainer code
179 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
180 GTK's own system and it simply waits for size events for toplevel windows
181 and then iterates down the respective size events to all window. This has
182 the disadvantage that windows might get size events before the GTK widget
183 actually has the reported size. This doesn't normally pose any problem, but
184 the OpenGL drawing routines rely on correct behaviour. Therefore, I have
185 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
186 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
187 window that is used for OpenGL output really has that size (as reported by
192 If someone at some point of time feels the immense desire to have a look at,
193 change or attempt to optimise the Refresh() logic, this person will need an
194 intimate understanding of what "draw" and "expose" events are and what
195 they are used for, in particular when used in connection with GTK's
196 own windowless widgets. Beware.
200 Cursors, too, have been a constant source of pleasure. The main difficulty
201 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
202 for the parent. To prevent this from doing too much harm, I use idle time
203 to set the cursor over and over again, starting from the toplevel windows
204 and ending with the youngest generation (speaking of parent and child windows).
205 Also don't forget that cursors (like much else) are connected to GdkWindows,
206 not GtkWidgets and that the "window" field of a GtkWidget might very well
207 point to the GdkWindow of the parent widget (-> "window-less widget") and
208 that the two obviously have very different meanings.
212 //-----------------------------------------------------------------------------
214 //-----------------------------------------------------------------------------
216 extern bool g_blockEventsOnDrag
;
217 extern bool g_blockEventsOnScroll
;
218 extern wxCursor g_globalCursor
;
220 // mouse capture state: the window which has it and if the mouse is currently
222 static wxWindowGTK
*g_captureWindow
= (wxWindowGTK
*) NULL
;
223 static bool g_captureWindowHasMouse
= false;
225 wxWindowGTK
*g_focusWindow
= (wxWindowGTK
*) NULL
;
227 // the last window which had the focus - this is normally never NULL (except
228 // if we never had focus at all) as even when g_focusWindow is NULL it still
229 // keeps its previous value
230 wxWindowGTK
*g_focusWindowLast
= (wxWindowGTK
*) NULL
;
232 // If a window get the focus set but has not been realized
233 // yet, defer setting the focus to idle time.
234 wxWindowGTK
*g_delayedFocus
= (wxWindowGTK
*) NULL
;
236 extern bool g_mainThreadLocked
;
238 //-----------------------------------------------------------------------------
240 //-----------------------------------------------------------------------------
245 # define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
247 # define DEBUG_MAIN_THREAD
250 #define DEBUG_MAIN_THREAD
253 // the trace mask used for the focus debugging messages
254 #define TRACE_FOCUS _T("focus")
256 //-----------------------------------------------------------------------------
257 // missing gdk functions
258 //-----------------------------------------------------------------------------
261 gdk_window_warp_pointer (GdkWindow
*window
,
266 window
= gdk_get_default_root_window();
268 if (!GDK_WINDOW_DESTROYED(window
))
270 XWarpPointer (GDK_WINDOW_XDISPLAY(window
),
271 None
, /* not source window -> move from anywhere */
272 GDK_WINDOW_XID(window
), /* dest window */
273 0, 0, 0, 0, /* not source window -> move from anywhere */
278 //-----------------------------------------------------------------------------
279 // local code (see below)
280 //-----------------------------------------------------------------------------
282 // returns the child of win which currently has focus or NULL if not found
284 // Note: can't be static, needed by textctrl.cpp.
285 wxWindow
*wxFindFocusedChild(wxWindowGTK
*win
)
287 wxWindow
*winFocus
= wxWindowGTK::FindFocus();
289 return (wxWindow
*)NULL
;
291 if ( winFocus
== win
)
292 return (wxWindow
*)win
;
294 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
296 node
= node
->GetNext() )
298 wxWindow
*child
= wxFindFocusedChild(node
->GetData());
303 return (wxWindow
*)NULL
;
306 static void GetScrollbarWidth(GtkWidget
* widget
, int& w
, int& h
)
308 GtkScrolledWindow
* scroll_window
= GTK_SCROLLED_WINDOW(widget
);
309 GtkScrolledWindowClass
* scroll_class
= GTK_SCROLLED_WINDOW_CLASS(GTK_OBJECT_GET_CLASS(scroll_window
));
310 GtkRequisition scroll_req
;
313 if (scroll_window
->vscrollbar_visible
)
315 scroll_req
.width
= 2;
316 scroll_req
.height
= 2;
317 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
318 (scroll_window
->vscrollbar
, &scroll_req
);
319 w
= scroll_req
.width
+
320 scroll_class
->scrollbar_spacing
;
324 if (scroll_window
->hscrollbar_visible
)
326 scroll_req
.width
= 2;
327 scroll_req
.height
= 2;
328 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
329 (scroll_window
->hscrollbar
, &scroll_req
);
330 h
= scroll_req
.height
+
331 scroll_class
->scrollbar_spacing
;
335 static void draw_frame( GtkWidget
*widget
, wxWindowGTK
*win
)
337 // wxUniversal widgets draw the borders and scrollbars themselves
338 #ifndef __WXUNIVERSAL__
344 if (GTK_WIDGET_NO_WINDOW (widget
))
346 dx
+= widget
->allocation
.x
;
347 dy
+= widget
->allocation
.y
;
355 if (win
->m_hasScrolling
)
357 GetScrollbarWidth(widget
, dw
, dh
);
359 if (win
->GetLayoutDirection() == wxLayout_RightToLeft
)
361 // This is actually wrong for old GTK+ version
362 // which do not display the scrollbar on the
368 int w
= widget
->allocation
.width
-dw
;
369 int h
= widget
->allocation
.height
-dh
;
371 if (win
->HasFlag(wxRAISED_BORDER
))
373 gtk_paint_shadow (widget
->style
,
377 NULL
, NULL
, NULL
, // FIXME: No clipping?
382 if (win
->HasFlag(wxSUNKEN_BORDER
))
384 gtk_paint_shadow (widget
->style
,
388 NULL
, NULL
, NULL
, // FIXME: No clipping?
393 if (win
->HasFlag(wxSIMPLE_BORDER
))
396 gc
= gdk_gc_new( widget
->window
);
397 gdk_gc_set_foreground( gc
, &widget
->style
->black
);
398 gdk_draw_rectangle( widget
->window
, gc
, FALSE
, x
, y
, w
-1, h
-1 );
402 #endif // __WXUNIVERSAL__
405 //-----------------------------------------------------------------------------
406 // "expose_event" of m_widget
407 //-----------------------------------------------------------------------------
411 gtk_window_own_expose_callback( GtkWidget
*widget
,
412 GdkEventExpose
*gdk_event
,
415 if (gdk_event
->count
== 0)
416 draw_frame(widget
, win
);
421 //-----------------------------------------------------------------------------
422 // "size_request" of m_widget
423 //-----------------------------------------------------------------------------
425 // make it extern because wxStaticText needs to disconnect this one
427 void wxgtk_window_size_request_callback(GtkWidget
*widget
,
428 GtkRequisition
*requisition
,
432 win
->GetSize( &w
, &h
);
438 requisition
->height
= h
;
439 requisition
->width
= w
;
445 void wxgtk_combo_size_request_callback(GtkWidget
*widget
,
446 GtkRequisition
*requisition
,
449 // This callback is actually hooked into the text entry
450 // of the combo box, not the GtkHBox.
453 win
->GetSize( &w
, &h
);
459 GtkCombo
*gcombo
= GTK_COMBO(win
->m_widget
);
461 GtkRequisition entry_req
;
463 entry_req
.height
= 2;
464 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo
->button
) )->size_request
)
465 (gcombo
->button
, &entry_req
);
467 requisition
->width
= w
- entry_req
.width
;
468 requisition
->height
= entry_req
.height
;
472 //-----------------------------------------------------------------------------
473 // "expose_event" of m_wxwindow
474 //-----------------------------------------------------------------------------
478 gtk_window_expose_callback( GtkWidget
*widget
,
479 GdkEventExpose
*gdk_event
,
484 // don't need to install idle handler, its done from "event" signal
486 // This callback gets called in drawing-idle time under
487 // GTK 2.0, so we don't need to defer anything to idle
490 GtkPizza
*pizza
= GTK_PIZZA( widget
);
491 if (gdk_event
->window
!= pizza
->bin_window
) return FALSE
;
497 wxPrintf( wxT("OnExpose from ") );
498 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
499 wxPrintf( win
->GetClassInfo()->GetClassName() );
500 wxPrintf( wxT(" %d %d %d %d\n"), (int)gdk_event
->area
.x
,
501 (int)gdk_event
->area
.y
,
502 (int)gdk_event
->area
.width
,
503 (int)gdk_event
->area
.height
);
508 win
->m_wxwindow
->style
,
512 (GdkRectangle
*) NULL
,
514 (char *)"button", // const_cast
519 win
->GetUpdateRegion() = wxRegion( gdk_event
->region
);
521 win
->GtkSendPaintEvents();
523 // Let parent window draw window-less widgets
528 //-----------------------------------------------------------------------------
529 // "key_press_event" from any window
530 //-----------------------------------------------------------------------------
532 // These are used when transforming Ctrl-alpha to ascii values 1-26
533 inline bool wxIsLowerChar(int code
)
535 return (code
>= 'a' && code
<= 'z' );
538 inline bool wxIsUpperChar(int code
)
540 return (code
>= 'A' && code
<= 'Z' );
544 // set WXTRACE to this to see the key event codes on the console
545 #define TRACE_KEYS _T("keyevent")
547 // translates an X key symbol to WXK_XXX value
549 // if isChar is true it means that the value returned will be used for EVT_CHAR
550 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
551 // for example, while if it is false it means that the value is going to be
552 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
554 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
560 // Shift, Control and Alt don't generate the CHAR events at all
563 key_code
= isChar
? 0 : WXK_SHIFT
;
567 key_code
= isChar
? 0 : WXK_CONTROL
;
575 key_code
= isChar
? 0 : WXK_ALT
;
578 // neither do the toggle modifies
579 case GDK_Scroll_Lock
:
580 key_code
= isChar
? 0 : WXK_SCROLL
;
584 key_code
= isChar
? 0 : WXK_CAPITAL
;
588 key_code
= isChar
? 0 : WXK_NUMLOCK
;
592 // various other special keys
605 case GDK_ISO_Left_Tab
:
612 key_code
= WXK_RETURN
;
616 key_code
= WXK_CLEAR
;
620 key_code
= WXK_PAUSE
;
624 key_code
= WXK_SELECT
;
628 key_code
= WXK_PRINT
;
632 key_code
= WXK_EXECUTE
;
636 key_code
= WXK_ESCAPE
;
639 // cursor and other extended keyboard keys
641 key_code
= WXK_DELETE
;
657 key_code
= WXK_RIGHT
;
664 case GDK_Prior
: // == GDK_Page_Up
665 key_code
= WXK_PAGEUP
;
668 case GDK_Next
: // == GDK_Page_Down
669 key_code
= WXK_PAGEDOWN
;
681 key_code
= WXK_INSERT
;
696 key_code
= (isChar
? '0' : WXK_NUMPAD0
) + keysym
- GDK_KP_0
;
700 key_code
= isChar
? ' ' : WXK_NUMPAD_SPACE
;
704 key_code
= isChar
? WXK_TAB
: WXK_NUMPAD_TAB
;
708 key_code
= isChar
? WXK_RETURN
: WXK_NUMPAD_ENTER
;
712 key_code
= isChar
? WXK_F1
: WXK_NUMPAD_F1
;
716 key_code
= isChar
? WXK_F2
: WXK_NUMPAD_F2
;
720 key_code
= isChar
? WXK_F3
: WXK_NUMPAD_F3
;
724 key_code
= isChar
? WXK_F4
: WXK_NUMPAD_F4
;
728 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_HOME
;
732 key_code
= isChar
? WXK_LEFT
: WXK_NUMPAD_LEFT
;
736 key_code
= isChar
? WXK_UP
: WXK_NUMPAD_UP
;
740 key_code
= isChar
? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
744 key_code
= isChar
? WXK_DOWN
: WXK_NUMPAD_DOWN
;
747 case GDK_KP_Prior
: // == GDK_KP_Page_Up
748 key_code
= isChar
? WXK_PAGEUP
: WXK_NUMPAD_PAGEUP
;
751 case GDK_KP_Next
: // == GDK_KP_Page_Down
752 key_code
= isChar
? WXK_PAGEDOWN
: WXK_NUMPAD_PAGEDOWN
;
756 key_code
= isChar
? WXK_END
: WXK_NUMPAD_END
;
760 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_BEGIN
;
764 key_code
= isChar
? WXK_INSERT
: WXK_NUMPAD_INSERT
;
768 key_code
= isChar
? WXK_DELETE
: WXK_NUMPAD_DELETE
;
772 key_code
= isChar
? '=' : WXK_NUMPAD_EQUAL
;
775 case GDK_KP_Multiply
:
776 key_code
= isChar
? '*' : WXK_NUMPAD_MULTIPLY
;
780 key_code
= isChar
? '+' : WXK_NUMPAD_ADD
;
783 case GDK_KP_Separator
:
784 // FIXME: what is this?
785 key_code
= isChar
? '.' : WXK_NUMPAD_SEPARATOR
;
788 case GDK_KP_Subtract
:
789 key_code
= isChar
? '-' : WXK_NUMPAD_SUBTRACT
;
793 key_code
= isChar
? '.' : WXK_NUMPAD_DECIMAL
;
797 key_code
= isChar
? '/' : WXK_NUMPAD_DIVIDE
;
814 key_code
= WXK_F1
+ keysym
- GDK_F1
;
824 static inline bool wxIsAsciiKeysym(KeySym ks
)
829 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
831 GdkEventKey
*gdk_event
)
835 GdkModifierType state
;
836 if (gdk_event
->window
)
837 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
839 event
.SetTimestamp( gdk_event
->time
);
840 event
.SetId(win
->GetId());
841 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
842 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
843 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
844 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
) != 0;
845 event
.m_scanCode
= gdk_event
->keyval
;
846 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
847 event
.m_rawFlags
= 0;
849 event
.m_uniChar
= gdk_keyval_to_unicode(gdk_event
->keyval
);
851 wxGetMousePosition( &x
, &y
);
852 win
->ScreenToClient( &x
, &y
);
855 event
.SetEventObject( win
);
860 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
862 GdkEventKey
*gdk_event
)
864 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
865 // but only event->keyval which is quite useless to us, so remember
866 // the last character from GDK_KEY_PRESS and reuse it as last resort
868 // NB: should be MT-safe as we're always called from the main thread only
873 } s_lastKeyPress
= { 0, 0 };
875 KeySym keysym
= gdk_event
->keyval
;
877 wxLogTrace(TRACE_KEYS
, _T("Key %s event: keysym = %ld"),
878 event
.GetEventType() == wxEVT_KEY_UP
? _T("release")
882 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
886 // do we have the translation or is it a plain ASCII character?
887 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
889 // we should use keysym if it is ASCII as X does some translations
890 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
891 // which we don't want here (but which we do use for OnChar())
892 if ( !wxIsAsciiKeysym(keysym
) )
894 keysym
= (KeySym
)gdk_event
->string
[0];
897 // we want to always get the same key code when the same key is
898 // pressed regardless of the state of the modifiers, i.e. on a
899 // standard US keyboard pressing '5' or '%' ('5' key with
900 // Shift) should result in the same key code in OnKeyDown():
901 // '5' (although OnChar() will get either '5' or '%').
903 // to do it we first translate keysym to keycode (== scan code)
904 // and then back but always using the lower register
905 Display
*dpy
= (Display
*)wxGetDisplay();
906 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
908 wxLogTrace(TRACE_KEYS
, _T("\t-> keycode %d"), keycode
);
910 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
912 // use the normalized, i.e. lower register, keysym if we've
914 key_code
= keysymNormalized
? keysymNormalized
: keysym
;
916 // as explained above, we want to have lower register key codes
917 // normally but for the letter keys we want to have the upper ones
919 // NB: don't use XConvertCase() here, we want to do it for letters
921 key_code
= toupper(key_code
);
923 else // non ASCII key, what to do?
925 // by default, ignore it
928 // but if we have cached information from the last KEY_PRESS
929 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
932 if ( keysym
== s_lastKeyPress
.keysym
)
934 key_code
= s_lastKeyPress
.keycode
;
939 if ( gdk_event
->type
== GDK_KEY_PRESS
)
941 // remember it to be reused for KEY_UP event later
942 s_lastKeyPress
.keysym
= keysym
;
943 s_lastKeyPress
.keycode
= key_code
;
947 wxLogTrace(TRACE_KEYS
, _T("\t-> wxKeyCode %ld"), key_code
);
949 // sending unknown key events doesn't really make sense
953 // now fill all the other fields
954 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
956 event
.m_keyCode
= key_code
;
958 if ( gdk_event
->type
== GDK_KEY_PRESS
|| gdk_event
->type
== GDK_KEY_RELEASE
)
960 event
.m_uniChar
= key_code
;
970 GtkIMContext
*context
;
971 GdkEventKey
*lastKeyEvent
;
975 context
= gtk_im_multicontext_new();
980 g_object_unref (context
);
986 gtk_window_key_press_callback( GtkWidget
*widget
,
987 GdkEventKey
*gdk_event
,
992 // don't need to install idle handler, its done from "event" signal
996 if (g_blockEventsOnDrag
)
1000 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1002 bool return_after_IM
= false;
1004 if( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1006 // Emit KEY_DOWN event
1007 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1011 // Return after IM processing as we cannot do
1012 // anything with it anyhow.
1013 return_after_IM
= true;
1016 // 2005.01.26 modified by Hong Jen Yee (hzysoft@sina.com.tw):
1017 // When we get a key_press event here, it could be originate
1018 // from the current widget or its child widgets. However, only the widget
1019 // with the INPUT FOCUS can generate the INITIAL key_press event. That is,
1020 // if the CURRENT widget doesn't have the FOCUS at all, this event definitely
1021 // originated from its child widgets and shouldn't be passed to IM context.
1022 // In fact, what a GTK+ IM should do is filtering keyEvents and convert them
1023 // into text input ONLY WHEN THE WIDGET HAS INPUT FOCUS. Besides, when current
1024 // widgets has both IM context and input focus, the event should be filtered
1025 // by gtk_im_context_filter_keypress().
1026 // Then, we should, according to GTK+ 2.0 API doc, return whatever it returns.
1027 if ((!ret
) && (win
->m_imData
!= NULL
) && ( wxWindow::FindFocus() == win
))
1029 // We should let GTK+ IM filter key event first. According to GTK+ 2.0 API
1030 // docs, if IM filter returns true, no further processing should be done.
1031 // we should send the key_down event anyway.
1032 bool intercepted_by_IM
= gtk_im_context_filter_keypress(win
->m_imData
->context
, gdk_event
);
1033 win
->m_imData
->lastKeyEvent
= NULL
;
1034 if (intercepted_by_IM
)
1036 wxLogTrace(TRACE_KEYS
, _T("Key event intercepted by IM"));
1041 if (return_after_IM
)
1047 wxWindowGTK
*ancestor
= win
;
1050 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1053 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1054 ret
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1057 if (ancestor
->IsTopLevel())
1059 ancestor
= ancestor
->GetParent();
1062 #endif // wxUSE_ACCEL
1064 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
1065 // will only be sent if it is not in an accelerator table.
1069 KeySym keysym
= gdk_event
->keyval
;
1070 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
1071 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
1074 if ( wxIsAsciiKeysym(keysym
) )
1077 key_code
= (unsigned char)keysym
;
1079 // gdk_event->string is actually deprecated
1080 else if ( gdk_event
->length
== 1 )
1082 key_code
= (unsigned char)gdk_event
->string
[0];
1088 wxLogTrace(TRACE_KEYS
, _T("Char event: %ld"), key_code
);
1090 event
.m_keyCode
= key_code
;
1092 // To conform to the docs we need to translate Ctrl-alpha
1093 // characters to values in the range 1-26.
1094 if ( event
.ControlDown() &&
1095 ( wxIsLowerChar(key_code
) || wxIsUpperChar(key_code
) ))
1097 if ( wxIsLowerChar(key_code
) )
1098 event
.m_keyCode
= key_code
- 'a' + 1;
1099 if ( wxIsUpperChar(key_code
) )
1100 event
.m_keyCode
= key_code
- 'A' + 1;
1102 event
.m_uniChar
= event
.m_keyCode
;
1106 // Implement OnCharHook by checking ancestor top level windows
1107 wxWindow
*parent
= win
;
1108 while (parent
&& !parent
->IsTopLevel())
1109 parent
= parent
->GetParent();
1112 event
.SetEventType( wxEVT_CHAR_HOOK
);
1113 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1118 event
.SetEventType(wxEVT_CHAR
);
1119 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1124 // win is a control: tab can be propagated up
1126 ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
)) &&
1127 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here - the control may
1128 // have this style, yet choose not to process this particular TAB in which
1129 // case TAB must still work as a navigational character
1130 // JS: enabling again to make consistent with other platforms
1131 // (with wxTE_PROCESS_TAB you have to call Navigate to get default
1132 // navigation behaviour)
1134 (! (win
->HasFlag(wxTE_PROCESS_TAB
) && win
->IsKindOf(CLASSINFO(wxTextCtrl
)) )) &&
1136 win
->GetParent() && (win
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1138 wxNavigationKeyEvent new_event
;
1139 new_event
.SetEventObject( win
->GetParent() );
1140 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
1141 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
1142 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
1143 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
1144 new_event
.SetCurrentFocus( win
);
1145 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent( new_event
);
1154 gtk_wxwindow_commit_cb (GtkIMContext
*context
,
1158 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1160 // take modifiers, cursor position, timestamp etc. from the last
1161 // key_press_event that was fed into Input Method:
1162 if (window
->m_imData
->lastKeyEvent
)
1164 wxFillOtherKeyEventFields(event
,
1165 window
, window
->m_imData
->lastKeyEvent
);
1168 const wxWxCharBuffer
data(wxGTK_CONV_BACK(str
));
1174 // Implement OnCharHook by checking ancestor top level windows
1175 wxWindow
*parent
= window
;
1176 while (parent
&& !parent
->IsTopLevel())
1177 parent
= parent
->GetParent();
1179 for( const wxChar
* pstr
= data
; *pstr
; pstr
++ )
1182 event
.m_uniChar
= *pstr
;
1183 // Backward compatible for ISO-8859-1
1184 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1185 wxLogTrace(TRACE_KEYS
, _T("IM sent character '%c'"), event
.m_uniChar
);
1187 event
.m_keyCode
= *pstr
;
1188 #endif // wxUSE_UNICODE
1190 // To conform to the docs we need to translate Ctrl-alpha
1191 // characters to values in the range 1-26.
1192 if ( event
.ControlDown() &&
1193 ( wxIsLowerChar(*pstr
) || wxIsUpperChar(*pstr
) ))
1195 if ( wxIsLowerChar(*pstr
) )
1196 event
.m_keyCode
= *pstr
- 'a' + 1;
1197 if ( wxIsUpperChar(*pstr
) )
1198 event
.m_keyCode
= *pstr
- 'A' + 1;
1200 event
.m_keyCode
= *pstr
- 'a' + 1;
1202 event
.m_uniChar
= event
.m_keyCode
;
1208 event
.SetEventType( wxEVT_CHAR_HOOK
);
1209 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1214 event
.SetEventType(wxEVT_CHAR
);
1215 ret
= window
->GetEventHandler()->ProcessEvent( event
);
1222 //-----------------------------------------------------------------------------
1223 // "key_release_event" from any window
1224 //-----------------------------------------------------------------------------
1228 gtk_window_key_release_callback( GtkWidget
*widget
,
1229 GdkEventKey
*gdk_event
,
1234 // don't need to install idle handler, its done from "event" signal
1239 if (g_blockEventsOnDrag
)
1242 wxKeyEvent
event( wxEVT_KEY_UP
);
1243 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1245 // unknown key pressed, ignore (the event would be useless anyhow)
1249 return win
->GTKProcessEvent(event
);
1253 // ============================================================================
1255 // ============================================================================
1257 // ----------------------------------------------------------------------------
1258 // mouse event processing helpers
1259 // ----------------------------------------------------------------------------
1261 // init wxMouseEvent with the info from GdkEventXXX struct
1262 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1263 wxMouseEvent
& event
,
1266 event
.SetTimestamp( gdk_event
->time
);
1267 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1268 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1269 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1270 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1271 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1272 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1273 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1274 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
1276 event
.m_linesPerAction
= 3;
1277 event
.m_wheelDelta
= 120;
1278 if (((GdkEventButton
*)gdk_event
)->button
== 4)
1279 event
.m_wheelRotation
= 120;
1280 else if (((GdkEventButton
*)gdk_event
)->button
== 5)
1281 event
.m_wheelRotation
= -120;
1284 wxPoint pt
= win
->GetClientAreaOrigin();
1285 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1286 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1288 if ((win
->m_wxwindow
) && (win
->GetLayoutDirection() == wxLayout_RightToLeft
))
1290 // origin in the upper right corner
1291 int window_width
= gtk_pizza_get_rtl_offset( GTK_PIZZA(win
->m_wxwindow
) );
1292 event
.m_x
= window_width
- event
.m_x
;
1295 event
.SetEventObject( win
);
1296 event
.SetId( win
->GetId() );
1297 event
.SetTimestamp( gdk_event
->time
);
1300 static void AdjustEventButtonState(wxMouseEvent
& event
)
1302 // GDK reports the old state of the button for a button press event, but
1303 // for compatibility with MSW and common sense we want m_leftDown be TRUE
1304 // for a LEFT_DOWN event, not FALSE, so we will invert
1305 // left/right/middleDown for the corresponding click events
1307 if ((event
.GetEventType() == wxEVT_LEFT_DOWN
) ||
1308 (event
.GetEventType() == wxEVT_LEFT_DCLICK
) ||
1309 (event
.GetEventType() == wxEVT_LEFT_UP
))
1311 event
.m_leftDown
= !event
.m_leftDown
;
1315 if ((event
.GetEventType() == wxEVT_MIDDLE_DOWN
) ||
1316 (event
.GetEventType() == wxEVT_MIDDLE_DCLICK
) ||
1317 (event
.GetEventType() == wxEVT_MIDDLE_UP
))
1319 event
.m_middleDown
= !event
.m_middleDown
;
1323 if ((event
.GetEventType() == wxEVT_RIGHT_DOWN
) ||
1324 (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) ||
1325 (event
.GetEventType() == wxEVT_RIGHT_UP
))
1327 event
.m_rightDown
= !event
.m_rightDown
;
1332 // find the window to send the mouse event too
1334 wxWindowGTK
*FindWindowForMouseEvent(wxWindowGTK
*win
, wxCoord
& x
, wxCoord
& y
)
1339 if (win
->m_wxwindow
)
1341 GtkPizza
*pizza
= GTK_PIZZA(win
->m_wxwindow
);
1342 xx
+= gtk_pizza_get_xoffset( pizza
);
1343 yy
+= gtk_pizza_get_yoffset( pizza
);
1346 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
1349 wxWindowGTK
*child
= node
->GetData();
1351 node
= node
->GetNext();
1352 if (!child
->IsShown())
1355 if (child
->IsTransparentForMouse())
1357 // wxStaticBox is transparent in the box itself
1358 int xx1
= child
->m_x
;
1359 int yy1
= child
->m_y
;
1360 int xx2
= child
->m_x
+ child
->m_width
;
1361 int yy2
= child
->m_y
+ child
->m_height
;
1364 if (((xx
>= xx1
) && (xx
<= xx1
+10) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1366 ((xx
>= xx2
-10) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1368 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy1
+10)) ||
1370 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy2
-1) && (yy
<= yy2
)))
1381 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1382 (child
->m_x
<= xx
) &&
1383 (child
->m_y
<= yy
) &&
1384 (child
->m_x
+child
->m_width
>= xx
) &&
1385 (child
->m_y
+child
->m_height
>= yy
))
1398 // ----------------------------------------------------------------------------
1399 // common event handlers helpers
1400 // ----------------------------------------------------------------------------
1402 bool wxWindowGTK::GTKProcessEvent(wxEvent
& event
) const
1404 // nothing special at this level
1405 return GetEventHandler()->ProcessEvent(event
);
1408 int wxWindowGTK::GTKCallbackCommonPrologue(GdkEventAny
*event
) const
1412 // don't need to install idle handler, its done from "event" signal
1416 if (g_blockEventsOnDrag
)
1418 if (g_blockEventsOnScroll
)
1421 if (!GTKIsOwnWindow(event
->window
))
1427 // overloads for all GDK event types we use here: we need to have this as
1428 // GdkEventXXX can't be implicitly cast to GdkEventAny even if it, in fact,
1429 // derives from it in the sense that the structs have the same layout
1430 #define wxDEFINE_COMMON_PROLOGUE_OVERLOAD(T) \
1431 static int wxGtkCallbackCommonPrologue(T *event, wxWindowGTK *win) \
1433 return win->GTKCallbackCommonPrologue((GdkEventAny *)event); \
1436 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventButton
)
1437 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventMotion
)
1438 wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventCrossing
)
1440 #undef wxDEFINE_COMMON_PROLOGUE_OVERLOAD
1442 #define wxCOMMON_CALLBACK_PROLOGUE(event, win) \
1443 const int rc = wxGtkCallbackCommonPrologue(event, win); \
1447 // send the wxChildFocusEvent and wxFocusEvent, common code of
1448 // gtk_window_focus_in_callback() and SetFocus()
1449 static bool DoSendFocusEvents(wxWindow
*win
)
1451 // Notify the parent keeping track of focus for the kbd navigation
1452 // purposes that we got it.
1453 wxChildFocusEvent
eventChildFocus(win
);
1454 (void)win
->GetEventHandler()->ProcessEvent(eventChildFocus
);
1456 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, win
->GetId());
1457 eventFocus
.SetEventObject(win
);
1459 return win
->GetEventHandler()->ProcessEvent(eventFocus
);
1462 // all event handlers must have C linkage as they're called from GTK+ C code
1466 //-----------------------------------------------------------------------------
1467 // "button_press_event"
1468 //-----------------------------------------------------------------------------
1471 gtk_window_button_press_callback( GtkWidget
*widget
,
1472 GdkEventButton
*gdk_event
,
1475 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1477 if (win
->m_wxwindow
&& (g_focusWindow
!= win
) && win
->AcceptsFocus())
1479 gtk_widget_grab_focus( win
->m_wxwindow
);
1482 // GDK sends surplus button down events
1483 // before a double click event. We
1484 // need to filter these out.
1485 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1487 GdkEvent
*peek_event
= gdk_event_peek();
1490 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1491 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1493 gdk_event_free( peek_event
);
1498 gdk_event_free( peek_event
);
1503 wxEventType event_type
= wxEVT_NULL
;
1505 // GdkDisplay is a GTK+ 2.2.0 thing
1506 #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2, 2, 0)
1507 if ( gdk_event
->type
== GDK_2BUTTON_PRESS
&&
1508 !gtk_check_version(2,2,0) &&
1509 gdk_event
->button
>= 1 && gdk_event
->button
<= 3 )
1511 // Reset GDK internal timestamp variables in order to disable GDK
1512 // triple click events. GDK will then next time believe no button has
1513 // been clicked just before, and send a normal button click event.
1514 GdkDisplay
* display
= gtk_widget_get_display (widget
);
1515 display
->button_click_time
[1] = 0;
1516 display
->button_click_time
[0] = 0;
1520 if (gdk_event
->button
== 1)
1522 // note that GDK generates triple click events which are not supported
1523 // by wxWidgets but still have to be passed to the app as otherwise
1524 // clicks would simply go missing
1525 switch (gdk_event
->type
)
1527 // we shouldn't get triple clicks at all for GTK2 because we
1528 // suppress them artificially using the code above but we still
1529 // should map them to something for GTK1 and not just ignore them
1530 // as this would lose clicks
1531 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1532 case GDK_BUTTON_PRESS
:
1533 event_type
= wxEVT_LEFT_DOWN
;
1536 case GDK_2BUTTON_PRESS
:
1537 event_type
= wxEVT_LEFT_DCLICK
;
1541 // just to silence gcc warnings
1545 else if (gdk_event
->button
== 2)
1547 switch (gdk_event
->type
)
1549 case GDK_3BUTTON_PRESS
:
1550 case GDK_BUTTON_PRESS
:
1551 event_type
= wxEVT_MIDDLE_DOWN
;
1554 case GDK_2BUTTON_PRESS
:
1555 event_type
= wxEVT_MIDDLE_DCLICK
;
1562 else if (gdk_event
->button
== 3)
1564 switch (gdk_event
->type
)
1566 case GDK_3BUTTON_PRESS
:
1567 case GDK_BUTTON_PRESS
:
1568 event_type
= wxEVT_RIGHT_DOWN
;
1571 case GDK_2BUTTON_PRESS
:
1572 event_type
= wxEVT_RIGHT_DCLICK
;
1579 else if (gdk_event
->button
== 4 || gdk_event
->button
== 5)
1581 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1583 event_type
= wxEVT_MOUSEWHEEL
;
1587 if ( event_type
== wxEVT_NULL
)
1589 // unknown mouse button or click type
1593 wxMouseEvent
event( event_type
);
1594 InitMouseEvent( win
, event
, gdk_event
);
1596 AdjustEventButtonState(event
);
1598 // wxListBox actually gets mouse events from the item, so we need to give it
1599 // a chance to correct this
1600 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1602 // find the correct window to send the event to: it may be a different one
1603 // from the one which got it at GTK+ level because some controls don't have
1604 // their own X window and thus cannot get any events.
1605 if ( !g_captureWindow
)
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() );
1612 if (win
->GTKProcessEvent( event
))
1617 if (event_type
== wxEVT_RIGHT_DOWN
)
1619 // generate a "context menu" event: this is similar to right mouse
1620 // click under many GUIs except that it is generated differently
1621 // (right up under MSW, ctrl-click under Mac, right down here) and
1623 // (a) it's a command event and so is propagated to the parent
1624 // (b) under some ports it can be generated from kbd too
1625 // (c) it uses screen coords (because of (a))
1626 wxContextMenuEvent
evtCtx(
1629 win
->ClientToScreen(event
.GetPosition()));
1630 evtCtx
.SetEventObject(win
);
1631 return win
->GTKProcessEvent(evtCtx
);
1637 //-----------------------------------------------------------------------------
1638 // "button_release_event"
1639 //-----------------------------------------------------------------------------
1642 gtk_window_button_release_callback( GtkWidget
*widget
,
1643 GdkEventButton
*gdk_event
,
1646 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1648 wxEventType event_type
= wxEVT_NULL
;
1650 switch (gdk_event
->button
)
1653 event_type
= wxEVT_LEFT_UP
;
1657 event_type
= wxEVT_MIDDLE_UP
;
1661 event_type
= wxEVT_RIGHT_UP
;
1665 // unknown button, don't process
1669 wxMouseEvent
event( event_type
);
1670 InitMouseEvent( win
, event
, gdk_event
);
1672 AdjustEventButtonState(event
);
1674 // same wxListBox hack as above
1675 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1677 if ( !g_captureWindow
)
1678 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1680 // reset the event object and id in case win changed.
1681 event
.SetEventObject( win
);
1682 event
.SetId( win
->GetId() );
1684 return win
->GTKProcessEvent(event
);
1687 //-----------------------------------------------------------------------------
1688 // "motion_notify_event"
1689 //-----------------------------------------------------------------------------
1692 gtk_window_motion_notify_callback( GtkWidget
*widget
,
1693 GdkEventMotion
*gdk_event
,
1696 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1698 if (gdk_event
->is_hint
)
1702 GdkModifierType state
;
1703 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1708 wxMouseEvent
event( wxEVT_MOTION
);
1709 InitMouseEvent(win
, event
, gdk_event
);
1711 if ( g_captureWindow
)
1713 // synthesise a mouse enter or leave event if needed
1714 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1715 // This seems to be necessary and actually been added to
1716 // GDK itself in version 2.0.X
1719 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1720 if ( hasMouse
!= g_captureWindowHasMouse
)
1722 // the mouse changed window
1723 g_captureWindowHasMouse
= hasMouse
;
1725 wxMouseEvent
eventM(g_captureWindowHasMouse
? wxEVT_ENTER_WINDOW
1726 : wxEVT_LEAVE_WINDOW
);
1727 InitMouseEvent(win
, eventM
, gdk_event
);
1728 eventM
.SetEventObject(win
);
1729 win
->GTKProcessEvent(eventM
);
1734 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1736 // reset the event object and id in case win changed.
1737 event
.SetEventObject( win
);
1738 event
.SetId( win
->GetId() );
1741 if ( !g_captureWindow
)
1743 wxSetCursorEvent
cevent( event
.m_x
, event
.m_y
);
1744 if (win
->GTKProcessEvent( cevent
))
1746 win
->SetCursor( cevent
.GetCursor() );
1750 return win
->GTKProcessEvent(event
);
1753 //-----------------------------------------------------------------------------
1754 // "scroll_event", (mouse wheel event)
1755 //-----------------------------------------------------------------------------
1758 window_scroll_event(GtkWidget
*, GdkEventScroll
* gdk_event
, wxWindow
* win
)
1762 // don't need to install idle handler, its done from "event" signal
1764 if (gdk_event
->direction
!= GDK_SCROLL_UP
&&
1765 gdk_event
->direction
!= GDK_SCROLL_DOWN
)
1770 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
1771 // Can't use InitMouse macro because scroll events don't have button
1772 event
.SetTimestamp( gdk_event
->time
);
1773 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1774 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1775 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1776 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1777 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1778 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1779 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1780 event
.m_linesPerAction
= 3;
1781 event
.m_wheelDelta
= 120;
1782 if (gdk_event
->direction
== GDK_SCROLL_UP
)
1783 event
.m_wheelRotation
= 120;
1785 event
.m_wheelRotation
= -120;
1787 wxPoint pt
= win
->GetClientAreaOrigin();
1788 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1789 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1791 event
.SetEventObject( win
);
1792 event
.SetId( win
->GetId() );
1793 event
.SetTimestamp( gdk_event
->time
);
1795 return win
->GTKProcessEvent(event
);
1798 //-----------------------------------------------------------------------------
1800 //-----------------------------------------------------------------------------
1802 static gboolean
wxgtk_window_popup_menu_callback(GtkWidget
*, wxWindowGTK
* win
)
1804 wxContextMenuEvent
event(wxEVT_CONTEXT_MENU
, win
->GetId(), wxPoint(-1, -1));
1805 event
.SetEventObject(win
);
1806 return win
->GTKProcessEvent(event
);
1809 //-----------------------------------------------------------------------------
1811 //-----------------------------------------------------------------------------
1814 gtk_window_focus_in_callback( GtkWidget
*widget
,
1815 GdkEventFocus
*WXUNUSED(event
),
1820 // don't need to install idle handler, its done from "event" signal
1823 gtk_im_context_focus_in(win
->m_imData
->context
);
1826 g_focusWindow
= win
;
1828 wxLogTrace(TRACE_FOCUS
,
1829 _T("%s: focus in"), win
->GetName().c_str());
1833 gdk_im_begin(win
->m_ic
, win
->m_wxwindow
->window
);
1837 // caret needs to be informed about focus change
1838 wxCaret
*caret
= win
->GetCaret();
1841 caret
->OnSetFocus();
1843 #endif // wxUSE_CARET
1845 gboolean ret
= FALSE
;
1847 // does the window itself think that it has the focus?
1848 if ( !win
->m_hasFocus
)
1850 // not yet, notify it
1851 win
->m_hasFocus
= true;
1853 (void)DoSendFocusEvents(win
);
1858 // Disable default focus handling for custom windows
1859 // since the default GTK+ handler issues a repaint
1860 if (win
->m_wxwindow
)
1866 //-----------------------------------------------------------------------------
1867 // "focus_out_event"
1868 //-----------------------------------------------------------------------------
1871 gtk_window_focus_out_callback( GtkWidget
*widget
,
1872 GdkEventFocus
*gdk_event
,
1877 // don't need to install idle handler, its done from "event" signal
1880 gtk_im_context_focus_out(win
->m_imData
->context
);
1882 wxLogTrace( TRACE_FOCUS
,
1883 _T("%s: focus out"), win
->GetName().c_str() );
1886 wxWindowGTK
*winFocus
= wxFindFocusedChild(win
);
1890 g_focusWindow
= (wxWindowGTK
*)NULL
;
1898 // caret needs to be informed about focus change
1899 wxCaret
*caret
= win
->GetCaret();
1902 caret
->OnKillFocus();
1904 #endif // wxUSE_CARET
1906 gboolean ret
= FALSE
;
1908 // don't send the window a kill focus event if it thinks that it doesn't
1909 // have focus already
1910 if ( win
->m_hasFocus
)
1912 win
->m_hasFocus
= false;
1914 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
1915 event
.SetEventObject( win
);
1917 (void)win
->GTKProcessEvent( event
);
1922 // Disable default focus handling for custom windows
1923 // since the default GTK+ handler issues a repaint
1924 if (win
->m_wxwindow
)
1930 //-----------------------------------------------------------------------------
1931 // "enter_notify_event"
1932 //-----------------------------------------------------------------------------
1935 gtk_window_enter_callback( GtkWidget
*widget
,
1936 GdkEventCrossing
*gdk_event
,
1939 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1941 // Event was emitted after a grab
1942 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1946 GdkModifierType state
= (GdkModifierType
)0;
1948 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1950 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
1951 InitMouseEvent(win
, event
, gdk_event
);
1952 wxPoint pt
= win
->GetClientAreaOrigin();
1953 event
.m_x
= x
+ pt
.x
;
1954 event
.m_y
= y
+ pt
.y
;
1956 if ( !g_captureWindow
)
1958 wxSetCursorEvent
cevent( event
.m_x
, event
.m_y
);
1959 if (win
->GTKProcessEvent( cevent
))
1961 win
->SetCursor( cevent
.GetCursor() );
1965 return win
->GTKProcessEvent(event
);
1968 //-----------------------------------------------------------------------------
1969 // "leave_notify_event"
1970 //-----------------------------------------------------------------------------
1973 gtk_window_leave_callback( GtkWidget
*widget
,
1974 GdkEventCrossing
*gdk_event
,
1977 wxCOMMON_CALLBACK_PROLOGUE(gdk_event
, win
);
1979 // Event was emitted after an ungrab
1980 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1982 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
1983 event
.SetTimestamp( gdk_event
->time
);
1984 event
.SetEventObject( win
);
1988 GdkModifierType state
= (GdkModifierType
)0;
1990 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1992 event
.m_shiftDown
= (state
& GDK_SHIFT_MASK
) != 0;
1993 event
.m_controlDown
= (state
& GDK_CONTROL_MASK
) != 0;
1994 event
.m_altDown
= (state
& GDK_MOD1_MASK
) != 0;
1995 event
.m_metaDown
= (state
& GDK_MOD2_MASK
) != 0;
1996 event
.m_leftDown
= (state
& GDK_BUTTON1_MASK
) != 0;
1997 event
.m_middleDown
= (state
& GDK_BUTTON2_MASK
) != 0;
1998 event
.m_rightDown
= (state
& GDK_BUTTON3_MASK
) != 0;
2000 wxPoint pt
= win
->GetClientAreaOrigin();
2001 event
.m_x
= x
+ pt
.x
;
2002 event
.m_y
= y
+ pt
.y
;
2004 return win
->GTKProcessEvent(event
);
2007 //-----------------------------------------------------------------------------
2008 // "value_changed" from scrollbar
2009 //-----------------------------------------------------------------------------
2012 gtk_scrollbar_value_changed(GtkRange
* range
, wxWindow
* win
)
2014 wxEventType eventType
= win
->GetScrollEventType(range
);
2015 if (eventType
!= wxEVT_NULL
)
2017 // Convert scroll event type to scrollwin event type
2018 eventType
+= wxEVT_SCROLLWIN_TOP
- wxEVT_SCROLL_TOP
;
2020 // find the scrollbar which generated the event
2021 wxWindowGTK::ScrollDir dir
= win
->ScrollDirFromRange(range
);
2023 // generate the corresponding wx event
2024 const int orient
= win
->OrientFromScrollDir(dir
);
2025 wxScrollWinEvent
event(eventType
, win
->GetScrollPos(orient
), orient
);
2026 event
.SetEventObject(win
);
2028 win
->m_blockValueChanged
[dir
] = true;
2029 win
->GTKProcessEvent(event
);
2030 win
->m_blockValueChanged
[dir
] = false;
2034 //-----------------------------------------------------------------------------
2035 // "button_press_event" from scrollbar
2036 //-----------------------------------------------------------------------------
2039 gtk_scrollbar_button_press_event(GtkRange
*, GdkEventButton
*, wxWindow
* win
)
2043 // don't need to install idle handler, its done from "event" signal
2045 g_blockEventsOnScroll
= true;
2046 win
->m_mouseButtonDown
= true;
2051 //-----------------------------------------------------------------------------
2052 // "event_after" from scrollbar
2053 //-----------------------------------------------------------------------------
2056 gtk_scrollbar_event_after(GtkRange
* range
, GdkEvent
* event
, wxWindow
* win
)
2058 if (event
->type
== GDK_BUTTON_RELEASE
)
2060 g_signal_handlers_block_by_func(range
, (void*)gtk_scrollbar_event_after
, win
);
2062 const int orient
= win
->OrientFromScrollDir(
2063 win
->ScrollDirFromRange(range
));
2064 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBRELEASE
, win
->GetScrollPos(orient
), orient
);
2065 event
.SetEventObject(win
);
2066 win
->GTKProcessEvent(event
);
2070 //-----------------------------------------------------------------------------
2071 // "button_release_event" from scrollbar
2072 //-----------------------------------------------------------------------------
2075 gtk_scrollbar_button_release_event(GtkRange
* range
, GdkEventButton
*, wxWindow
* win
)
2079 g_blockEventsOnScroll
= false;
2080 win
->m_mouseButtonDown
= false;
2081 // If thumb tracking
2082 if (win
->m_isScrolling
)
2084 win
->m_isScrolling
= false;
2085 // Hook up handler to send thumb release event after this emission is finished.
2086 // To allow setting scroll position from event handler, sending event must
2087 // be deferred until after the GtkRange handler for this signal has run
2088 g_signal_handlers_unblock_by_func(range
, (void*)gtk_scrollbar_event_after
, win
);
2094 //-----------------------------------------------------------------------------
2095 // "realize" from m_widget
2096 //-----------------------------------------------------------------------------
2098 /* We cannot set colours and fonts before the widget has
2099 been realized, so we do this directly after realization. */
2102 gtk_window_realized_callback( GtkWidget
*m_widget
, wxWindow
*win
)
2107 wxapp_install_idle_handler();
2111 GtkPizza
*pizza
= GTK_PIZZA( m_widget
);
2112 gtk_im_context_set_client_window( win
->m_imData
->context
,
2113 pizza
->bin_window
);
2116 wxWindowCreateEvent
event( win
);
2117 event
.SetEventObject( win
);
2118 win
->GTKProcessEvent( event
);
2121 //-----------------------------------------------------------------------------
2123 //-----------------------------------------------------------------------------
2126 void gtk_window_size_callback( GtkWidget
*WXUNUSED(widget
),
2127 GtkAllocation
*alloc
,
2131 wxapp_install_idle_handler();
2133 int client_width
= 0;
2134 int client_height
= 0;
2135 win
->GetClientSize( &client_width
, &client_height
);
2136 if ((client_width
== win
->m_oldClientWidth
) && (client_height
== win
->m_oldClientHeight
))
2140 wxPrintf( wxT("size_allocate ") );
2141 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
2142 wxPrintf( win
->GetClassInfo()->GetClassName() );
2143 wxPrintf( wxT(" %d %d %d %d\n"),
2150 GTK_PIZZA(win
->m_wxwindow
)->m_width
= win
->GetClientSize().x
;
2152 win
->m_oldClientWidth
= client_width
;
2153 win
->m_oldClientHeight
= client_height
;
2155 if (!win
->m_nativeSizeEvent
)
2157 wxSizeEvent
event( win
->GetSize(), win
->GetId() );
2158 event
.SetEventObject( win
);
2159 win
->GTKProcessEvent( event
);
2165 #define WXUNUSED_UNLESS_XIM(param) param
2167 #define WXUNUSED_UNLESS_XIM(param) WXUNUSED(param)
2170 /* Resize XIM window */
2172 void gtk_wxwindow_size_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2173 GtkAllocation
* WXUNUSED_UNLESS_XIM(alloc
),
2174 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2177 wxapp_install_idle_handler();
2183 if (gdk_ic_get_style (win
->m_ic
) & GDK_IM_PREEDIT_POSITION
)
2187 gdk_drawable_get_size (widget
->window
, &width
, &height
);
2188 win
->m_icattr
->preedit_area
.width
= width
;
2189 win
->m_icattr
->preedit_area
.height
= height
;
2190 gdk_ic_set_attr (win
->m_ic
, win
->m_icattr
, GDK_IC_PREEDIT_AREA
);
2195 //-----------------------------------------------------------------------------
2196 // "realize" from m_wxwindow
2197 //-----------------------------------------------------------------------------
2199 /* Initialize XIM support */
2202 gtk_wxwindow_realized_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2203 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2206 wxapp_install_idle_handler();
2209 if (win
->m_ic
) return;
2210 if (!widget
) return;
2211 if (!gdk_im_ready()) return;
2213 win
->m_icattr
= gdk_ic_attr_new();
2214 if (!win
->m_icattr
) return;
2218 GdkColormap
*colormap
;
2219 GdkICAttr
*attr
= win
->m_icattr
;
2220 unsigned attrmask
= GDK_IC_ALL_REQ
;
2222 GdkIMStyle supported_style
= (GdkIMStyle
)
2223 (GDK_IM_PREEDIT_NONE
|
2224 GDK_IM_PREEDIT_NOTHING
|
2225 GDK_IM_PREEDIT_POSITION
|
2226 GDK_IM_STATUS_NONE
|
2227 GDK_IM_STATUS_NOTHING
);
2229 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2230 supported_style
= (GdkIMStyle
)(supported_style
& ~GDK_IM_PREEDIT_POSITION
);
2232 attr
->style
= style
= gdk_im_decide_style (supported_style
);
2233 attr
->client_window
= widget
->window
;
2235 if ((colormap
= gtk_widget_get_colormap (widget
)) !=
2236 gtk_widget_get_default_colormap ())
2238 attrmask
|= GDK_IC_PREEDIT_COLORMAP
;
2239 attr
->preedit_colormap
= colormap
;
2242 attrmask
|= GDK_IC_PREEDIT_FOREGROUND
;
2243 attrmask
|= GDK_IC_PREEDIT_BACKGROUND
;
2244 attr
->preedit_foreground
= widget
->style
->fg
[GTK_STATE_NORMAL
];
2245 attr
->preedit_background
= widget
->style
->base
[GTK_STATE_NORMAL
];
2247 switch (style
& GDK_IM_PREEDIT_MASK
)
2249 case GDK_IM_PREEDIT_POSITION
:
2250 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2252 g_warning ("over-the-spot style requires fontset");
2256 gdk_drawable_get_size (widget
->window
, &width
, &height
);
2258 attrmask
|= GDK_IC_PREEDIT_POSITION_REQ
;
2259 attr
->spot_location
.x
= 0;
2260 attr
->spot_location
.y
= height
;
2261 attr
->preedit_area
.x
= 0;
2262 attr
->preedit_area
.y
= 0;
2263 attr
->preedit_area
.width
= width
;
2264 attr
->preedit_area
.height
= height
;
2265 attr
->preedit_fontset
= widget
->style
->font
;
2270 win
->m_ic
= gdk_ic_new (attr
, (GdkICAttributesType
)attrmask
);
2272 if (win
->m_ic
== NULL
)
2273 g_warning ("Can't create input context.");
2276 mask
= gdk_window_get_events (widget
->window
);
2277 mask
= (GdkEventMask
)(mask
| gdk_ic_get_events (win
->m_ic
));
2278 gdk_window_set_events (widget
->window
, mask
);
2280 if (GTK_WIDGET_HAS_FOCUS(widget
))
2281 gdk_im_begin (win
->m_ic
, widget
->window
);
2288 // ----------------------------------------------------------------------------
2289 // this wxWindowBase function is implemented here (in platform-specific file)
2290 // because it is static and so couldn't be made virtual
2291 // ----------------------------------------------------------------------------
2293 wxWindow
*wxWindowBase::DoFindFocus()
2295 // the cast is necessary when we compile in wxUniversal mode
2296 return (wxWindow
*)g_focusWindow
;
2299 //-----------------------------------------------------------------------------
2300 // InsertChild for wxWindowGTK.
2301 //-----------------------------------------------------------------------------
2303 /* Callback for wxWindowGTK. This very strange beast has to be used because
2304 * C++ has no virtual methods in a constructor. We have to emulate a
2305 * virtual function here as wxNotebook requires a different way to insert
2306 * a child in it. I had opted for creating a wxNotebookPage window class
2307 * which would have made this superfluous (such in the MDI window system),
2308 * but no-one was listening to me... */
2310 static void wxInsertChildInWindow( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2312 /* the window might have been scrolled already, do we
2313 have to adapt the position */
2314 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
2315 child
->m_x
+= gtk_pizza_get_xoffset( pizza
);
2316 child
->m_y
+= gtk_pizza_get_yoffset( pizza
);
2318 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
2319 GTK_WIDGET(child
->m_widget
),
2326 //-----------------------------------------------------------------------------
2328 //-----------------------------------------------------------------------------
2330 wxWindow
*wxGetActiveWindow()
2332 return wxWindow::FindFocus();
2336 wxMouseState
wxGetMouseState()
2342 GdkModifierType mask
;
2344 gdk_window_get_pointer(NULL
, &x
, &y
, &mask
);
2348 ms
.SetLeftDown(mask
& GDK_BUTTON1_MASK
);
2349 ms
.SetMiddleDown(mask
& GDK_BUTTON2_MASK
);
2350 ms
.SetRightDown(mask
& GDK_BUTTON3_MASK
);
2352 ms
.SetControlDown(mask
& GDK_CONTROL_MASK
);
2353 ms
.SetShiftDown(mask
& GDK_SHIFT_MASK
);
2354 ms
.SetAltDown(mask
& GDK_MOD1_MASK
);
2355 ms
.SetMetaDown(mask
& GDK_MOD2_MASK
);
2360 //-----------------------------------------------------------------------------
2362 //-----------------------------------------------------------------------------
2364 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2366 #ifdef __WXUNIVERSAL__
2367 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2369 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
2370 #endif // __WXUNIVERSAL__/__WXGTK__
2372 void wxWindowGTK::Init()
2375 m_widget
= (GtkWidget
*) NULL
;
2376 m_wxwindow
= (GtkWidget
*) NULL
;
2377 m_focusWidget
= (GtkWidget
*) NULL
;
2387 m_needParent
= true;
2388 m_isBeingDeleted
= false;
2390 m_showOnIdle
= false;
2393 m_nativeSizeEvent
= false;
2395 m_hasScrolling
= false;
2396 m_isScrolling
= false;
2397 m_mouseButtonDown
= false;
2398 m_blockScrollEvent
= false;
2400 // initialize scrolling stuff
2401 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
2403 m_scrollBar
[dir
] = NULL
;
2404 m_scrollPos
[dir
] = 0;
2405 m_blockValueChanged
[dir
] = false;
2409 m_oldClientHeight
= 0;
2413 m_insertCallback
= (wxInsertChildFunction
) NULL
;
2415 m_acceptsFocus
= false;
2418 m_clipPaintRegion
= false;
2420 m_needsStyleChange
= false;
2422 m_cursor
= *wxSTANDARD_CURSOR
;
2425 m_dirtyTabOrder
= false;
2428 wxWindowGTK::wxWindowGTK()
2433 wxWindowGTK::wxWindowGTK( wxWindow
*parent
,
2438 const wxString
&name
)
2442 Create( parent
, id
, pos
, size
, style
, name
);
2445 bool wxWindowGTK::Create( wxWindow
*parent
,
2450 const wxString
&name
)
2452 if (!PreCreation( parent
, pos
, size
) ||
2453 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2455 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2459 m_insertCallback
= wxInsertChildInWindow
;
2461 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
2462 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
2464 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2466 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2467 scroll_class
->scrollbar_spacing
= 0;
2469 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2471 m_scrollBar
[ScrollDir_Horz
] = GTK_RANGE(scrolledWindow
->hscrollbar
);
2472 m_scrollBar
[ScrollDir_Vert
] = GTK_RANGE(scrolledWindow
->vscrollbar
);
2473 if (GetLayoutDirection() == wxLayout_RightToLeft
)
2474 gtk_range_set_inverted( m_scrollBar
[ScrollDir_Horz
], TRUE
);
2476 m_wxwindow
= gtk_pizza_new();
2478 #ifndef __WXUNIVERSAL__
2479 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
2481 if (HasFlag(wxRAISED_BORDER
))
2483 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
2485 else if (HasFlag(wxSUNKEN_BORDER
))
2487 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
2489 else if (HasFlag(wxSIMPLE_BORDER
))
2491 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
2495 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
2497 #endif // __WXUNIVERSAL__
2499 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2501 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
2502 m_acceptsFocus
= true;
2504 // connect various scroll-related events
2505 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
2507 // these handlers block mouse events to any window during scrolling
2508 // such as motion events and prevent GTK and wxWidgets from fighting
2509 // over where the slider should be
2510 g_signal_connect(m_scrollBar
[dir
], "button_press_event",
2511 G_CALLBACK(gtk_scrollbar_button_press_event
), this);
2512 g_signal_connect(m_scrollBar
[dir
], "button_release_event",
2513 G_CALLBACK(gtk_scrollbar_button_release_event
), this);
2515 gulong handler_id
= g_signal_connect(m_scrollBar
[dir
], "event_after",
2516 G_CALLBACK(gtk_scrollbar_event_after
), this);
2517 g_signal_handler_block(m_scrollBar
[dir
], handler_id
);
2519 // these handlers get notified when scrollbar slider moves
2520 g_signal_connect(m_scrollBar
[dir
], "value_changed",
2521 G_CALLBACK(gtk_scrollbar_value_changed
), this);
2524 gtk_widget_show( m_wxwindow
);
2527 m_parent
->DoAddChild( this );
2529 m_focusWidget
= m_wxwindow
;
2536 wxWindowGTK::~wxWindowGTK()
2540 if (g_focusWindow
== this)
2541 g_focusWindow
= NULL
;
2543 if ( g_delayedFocus
== this )
2544 g_delayedFocus
= NULL
;
2546 m_isBeingDeleted
= true;
2549 // destroy children before destroying this window itself
2552 // unhook focus handlers to prevent stray events being
2553 // propagated to this (soon to be) dead object
2554 if (m_focusWidget
!= NULL
)
2556 g_signal_handlers_disconnect_by_func (m_focusWidget
,
2557 (gpointer
) gtk_window_focus_in_callback
,
2559 g_signal_handlers_disconnect_by_func (m_focusWidget
,
2560 (gpointer
) gtk_window_focus_out_callback
,
2569 gdk_ic_destroy (m_ic
);
2571 gdk_ic_attr_destroy (m_icattr
);
2574 // delete before the widgets to avoid a crash on solaris
2579 gtk_widget_destroy( m_wxwindow
);
2580 m_wxwindow
= (GtkWidget
*) NULL
;
2585 gtk_widget_destroy( m_widget
);
2586 m_widget
= (GtkWidget
*) NULL
;
2590 bool wxWindowGTK::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2592 wxCHECK_MSG( !m_needParent
|| parent
, false, wxT("Need complete parent.") );
2594 // Use either the given size, or the default if -1 is given.
2595 // See wxWindowBase for these functions.
2596 m_width
= WidthDefault(size
.x
) ;
2597 m_height
= HeightDefault(size
.y
);
2605 void wxWindowGTK::PostCreation()
2607 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2613 // these get reported to wxWidgets -> wxPaintEvent
2615 g_signal_connect (m_wxwindow
, "expose_event",
2616 G_CALLBACK (gtk_window_expose_callback
), this);
2618 if (GetLayoutDirection() == wxLayout_LeftToRight
)
2619 gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow
), HasFlag( wxFULL_REPAINT_ON_RESIZE
) );
2622 // Create input method handler
2623 m_imData
= new wxGtkIMData
;
2625 // Cannot handle drawing preedited text yet
2626 gtk_im_context_set_use_preedit( m_imData
->context
, FALSE
);
2628 g_signal_connect (m_imData
->context
, "commit",
2629 G_CALLBACK (gtk_wxwindow_commit_cb
), this);
2631 // these are called when the "sunken" or "raised" borders are drawn
2632 g_signal_connect (m_widget
, "expose_event",
2633 G_CALLBACK (gtk_window_own_expose_callback
), this);
2638 if (!GTK_IS_WINDOW(m_widget
))
2640 if (m_focusWidget
== NULL
)
2641 m_focusWidget
= m_widget
;
2645 g_signal_connect (m_focusWidget
, "focus_in_event",
2646 G_CALLBACK (gtk_window_focus_in_callback
), this);
2647 g_signal_connect (m_focusWidget
, "focus_out_event",
2648 G_CALLBACK (gtk_window_focus_out_callback
), this);
2652 g_signal_connect_after (m_focusWidget
, "focus_in_event",
2653 G_CALLBACK (gtk_window_focus_in_callback
), this);
2654 g_signal_connect_after (m_focusWidget
, "focus_out_event",
2655 G_CALLBACK (gtk_window_focus_out_callback
), this);
2659 // connect to the various key and mouse handlers
2661 GtkWidget
*connect_widget
= GetConnectWidget();
2663 ConnectWidget( connect_widget
);
2665 /* We cannot set colours, fonts and cursors before the widget has
2666 been realized, so we do this directly after realization */
2667 g_signal_connect (connect_widget
, "realize",
2668 G_CALLBACK (gtk_window_realized_callback
), this);
2672 // Catch native resize events
2673 g_signal_connect (m_wxwindow
, "size_allocate",
2674 G_CALLBACK (gtk_window_size_callback
), this);
2676 // Initialize XIM support
2677 g_signal_connect (m_wxwindow
, "realize",
2678 G_CALLBACK (gtk_wxwindow_realized_callback
), this);
2680 // And resize XIM window
2681 g_signal_connect (m_wxwindow
, "size_allocate",
2682 G_CALLBACK (gtk_wxwindow_size_callback
), this);
2685 if (GTK_IS_COMBO(m_widget
))
2687 GtkCombo
*gcombo
= GTK_COMBO(m_widget
);
2689 g_signal_connect (gcombo
->entry
, "size_request",
2690 G_CALLBACK (wxgtk_combo_size_request_callback
),
2693 #ifdef GTK_IS_FILE_CHOOSER_BUTTON
2694 else if (!gtk_check_version(2,6,0) && GTK_IS_FILE_CHOOSER_BUTTON(m_widget
))
2696 // If we connect to the "size_request" signal of a GtkFileChooserButton
2697 // then that control won't be sized properly when placed inside sizers
2698 // (this can be tested removing this elseif and running XRC or WIDGETS samples)
2699 // FIXME: what should be done here ?
2704 // This is needed if we want to add our windows into native
2705 // GTK controls, such as the toolbar. With this callback, the
2706 // toolbar gets to know the correct size (the one set by the
2707 // programmer). Sadly, it misbehaves for wxComboBox.
2708 g_signal_connect (m_widget
, "size_request",
2709 G_CALLBACK (wxgtk_window_size_request_callback
),
2713 InheritAttributes();
2717 SetLayoutDirection(wxLayout_Default
);
2719 // unless the window was created initially hidden (i.e. Hide() had been
2720 // called before Create()), we should show it at GTK+ level as well
2722 gtk_widget_show( m_widget
);
2725 void wxWindowGTK::ConnectWidget( GtkWidget
*widget
)
2727 g_signal_connect (widget
, "key_press_event",
2728 G_CALLBACK (gtk_window_key_press_callback
), this);
2729 g_signal_connect (widget
, "key_release_event",
2730 G_CALLBACK (gtk_window_key_release_callback
), this);
2731 g_signal_connect (widget
, "button_press_event",
2732 G_CALLBACK (gtk_window_button_press_callback
), this);
2733 g_signal_connect (widget
, "button_release_event",
2734 G_CALLBACK (gtk_window_button_release_callback
), this);
2735 g_signal_connect (widget
, "motion_notify_event",
2736 G_CALLBACK (gtk_window_motion_notify_callback
), this);
2737 g_signal_connect (widget
, "scroll_event",
2738 G_CALLBACK (window_scroll_event
), this);
2739 g_signal_connect (widget
, "popup_menu",
2740 G_CALLBACK (wxgtk_window_popup_menu_callback
), this);
2741 g_signal_connect (widget
, "enter_notify_event",
2742 G_CALLBACK (gtk_window_enter_callback
), this);
2743 g_signal_connect (widget
, "leave_notify_event",
2744 G_CALLBACK (gtk_window_leave_callback
), this);
2747 bool wxWindowGTK::Destroy()
2749 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2753 return wxWindowBase::Destroy();
2756 void wxWindowGTK::DoMoveWindow(int x
, int y
, int width
, int height
)
2758 // inform the parent to perform the move
2759 gtk_pizza_set_size( GTK_PIZZA(m_parent
->m_wxwindow
), m_widget
, x
, y
, width
, height
);
2763 void wxWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
2765 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2766 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
2768 if (m_resizing
) return; /* I don't like recursions */
2771 int currentX
, currentY
;
2772 GetPosition(¤tX
, ¤tY
);
2773 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2775 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2777 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2779 // calculate the best size if we should auto size the window
2780 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
2781 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
2783 const wxSize sizeBest
= GetBestSize();
2784 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
2786 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
2787 height
= sizeBest
.y
;
2795 int minWidth
= GetMinWidth(),
2796 minHeight
= GetMinHeight(),
2797 maxWidth
= GetMaxWidth(),
2798 maxHeight
= GetMaxHeight();
2800 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
2801 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
2802 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
2803 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
2805 #if wxUSE_TOOLBAR_NATIVE
2806 if (wxDynamicCast(GetParent(), wxToolBar
))
2808 // don't take the x,y values, they're wrong because toolbar sets them
2809 GtkWidget
*widget
= GTK_WIDGET(m_widget
);
2810 gtk_widget_set_size_request (widget
, m_width
, m_height
);
2814 if (m_parent
->m_wxwindow
== NULL
) // i.e. wxNotebook
2816 // don't set the size for children of wxNotebook, just take the values.
2824 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
2825 if ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0)
2827 if (x
!= -1) m_x
= x
+ gtk_pizza_get_xoffset( pizza
);
2828 if (y
!= -1) m_y
= y
+ gtk_pizza_get_yoffset( pizza
);
2832 m_x
= x
+ gtk_pizza_get_xoffset( pizza
);
2833 m_y
= y
+ gtk_pizza_get_yoffset( pizza
);
2836 int left_border
= 0;
2837 int right_border
= 0;
2839 int bottom_border
= 0;
2841 /* the default button has a border around it */
2842 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
2844 GtkBorder
*default_border
= NULL
;
2845 gtk_widget_style_get( m_widget
, "default_border", &default_border
, NULL
);
2848 left_border
+= default_border
->left
;
2849 right_border
+= default_border
->right
;
2850 top_border
+= default_border
->top
;
2851 bottom_border
+= default_border
->bottom
;
2852 g_free( default_border
);
2856 DoMoveWindow( m_x
-top_border
,
2858 m_width
+left_border
+right_border
,
2859 m_height
+top_border
+bottom_border
);
2864 /* Sometimes the client area changes size without the
2865 whole windows's size changing, but if the whole
2866 windows's size doesn't change, no wxSizeEvent will
2867 normally be sent. Here we add an extra test if
2868 the client test has been changed and this will
2870 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
2874 wxPrintf( "OnSize sent from " );
2875 if (GetClassInfo() && GetClassInfo()->GetClassName())
2876 wxPrintf( GetClassInfo()->GetClassName() );
2877 wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height );
2880 if (!m_nativeSizeEvent
)
2882 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
2883 event
.SetEventObject( this );
2884 GetEventHandler()->ProcessEvent( event
);
2890 bool wxWindowGTK::GtkShowFromOnIdle()
2892 if (IsShown() && m_showOnIdle
&& !GTK_WIDGET_VISIBLE (m_widget
))
2894 GtkAllocation alloc
;
2897 alloc
.width
= m_width
;
2898 alloc
.height
= m_height
;
2899 gtk_widget_size_allocate( m_widget
, &alloc
);
2900 gtk_widget_show( m_widget
);
2901 wxShowEvent
eventShow(GetId(), true);
2902 eventShow
.SetEventObject(this);
2903 GetEventHandler()->ProcessEvent(eventShow
);
2904 m_showOnIdle
= false;
2911 void wxWindowGTK::OnInternalIdle()
2913 // Check if we have to show window now
2914 if (GtkShowFromOnIdle()) return;
2916 if ( m_dirtyTabOrder
)
2918 m_dirtyTabOrder
= false;
2922 // Update style if the window was not yet realized
2923 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
2924 if (m_needsStyleChange
)
2926 SetBackgroundStyle(GetBackgroundStyle());
2927 m_needsStyleChange
= false;
2930 wxCursor cursor
= m_cursor
;
2931 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
2935 /* I now set the cursor anew in every OnInternalIdle call
2936 as setting the cursor in a parent window also effects the
2937 windows above so that checking for the current cursor is
2942 GdkWindow
*window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
2944 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2946 if (!g_globalCursor
.Ok())
2947 cursor
= *wxSTANDARD_CURSOR
;
2949 window
= m_widget
->window
;
2950 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2951 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2954 else if ( m_widget
)
2956 GdkWindow
*window
= m_widget
->window
;
2957 if ( window
&& !GTK_WIDGET_NO_WINDOW(m_widget
) )
2958 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2962 if (wxUpdateUIEvent::CanUpdate(this))
2963 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2966 void wxWindowGTK::DoGetSize( int *width
, int *height
) const
2968 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2970 if (width
) (*width
) = m_width
;
2971 if (height
) (*height
) = m_height
;
2974 void wxWindowGTK::DoSetClientSize( int width
, int height
)
2976 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2985 GetScrollbarWidth(m_widget
, dw
, dh
);
2988 #ifndef __WXUNIVERSAL__
2989 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
2991 // shadow border size is 2
2995 if (HasFlag(wxSIMPLE_BORDER
))
2997 // simple border size is 1
3001 #endif // __WXUNIVERSAL__
3007 SetSize(width
, height
);
3010 void wxWindowGTK::DoGetClientSize( int *width
, int *height
) const
3012 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3023 GetScrollbarWidth(m_widget
, dw
, dh
);
3025 #ifndef __WXUNIVERSAL__
3026 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
3028 // shadow border size is 2
3032 if (HasFlag(wxSIMPLE_BORDER
))
3034 // simple border size is 1
3038 #endif // __WXUNIVERSAL__
3048 if (width
) *width
= w
;
3049 if (height
) *height
= h
;
3052 void wxWindowGTK::DoGetPosition( int *x
, int *y
) const
3054 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3058 if (m_parent
&& m_parent
->m_wxwindow
)
3060 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
3061 dx
= gtk_pizza_get_xoffset( pizza
);
3062 dy
= gtk_pizza_get_yoffset( pizza
);
3065 if (m_x
== -1 && m_y
== -1)
3067 GdkWindow
*source
= (GdkWindow
*) NULL
;
3069 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3071 source
= m_widget
->window
;
3077 gdk_window_get_origin( source
, &org_x
, &org_y
);
3080 GetParent()->ScreenToClient(&org_x
, &org_y
);
3082 ((wxWindowGTK
*) this)->m_x
= org_x
;
3083 ((wxWindowGTK
*) this)->m_y
= org_y
;
3087 if (x
) (*x
) = m_x
- dx
;
3088 if (y
) (*y
) = m_y
- dy
;
3091 void wxWindowGTK::DoClientToScreen( int *x
, int *y
) const
3093 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3095 if (!m_widget
->window
) return;
3097 GdkWindow
*source
= (GdkWindow
*) NULL
;
3099 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3101 source
= m_widget
->window
;
3105 gdk_window_get_origin( source
, &org_x
, &org_y
);
3109 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3111 org_x
+= m_widget
->allocation
.x
;
3112 org_y
+= m_widget
->allocation
.y
;
3119 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3120 *x
= (GetClientSize().x
- *x
) + org_x
;
3128 void wxWindowGTK::DoScreenToClient( int *x
, int *y
) const
3130 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3132 if (!m_widget
->window
) return;
3134 GdkWindow
*source
= (GdkWindow
*) NULL
;
3136 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3138 source
= m_widget
->window
;
3142 gdk_window_get_origin( source
, &org_x
, &org_y
);
3146 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3148 org_x
+= m_widget
->allocation
.x
;
3149 org_y
+= m_widget
->allocation
.y
;
3155 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3156 *x
= (GetClientSize().x
- *x
) - org_x
;
3163 bool wxWindowGTK::Show( bool show
)
3165 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3167 if (!wxWindowBase::Show(show
))
3177 gtk_widget_show( m_widget
);
3178 wxShowEvent
eventShow(GetId(), show
);
3179 eventShow
.SetEventObject(this);
3180 GetEventHandler()->ProcessEvent(eventShow
);
3185 gtk_widget_hide( m_widget
);
3186 wxShowEvent
eventShow(GetId(), show
);
3187 eventShow
.SetEventObject(this);
3188 GetEventHandler()->ProcessEvent(eventShow
);
3194 static void wxWindowNotifyEnable(wxWindowGTK
* win
, bool enable
)
3196 win
->OnParentEnable(enable
);
3198 // Recurse, so that children have the opportunity to Do The Right Thing
3199 // and reset colours that have been messed up by a parent's (really ancestor's)
3201 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3203 node
= node
->GetNext() )
3205 wxWindow
*child
= node
->GetData();
3206 if (!child
->IsKindOf(CLASSINFO(wxDialog
)) && !child
->IsKindOf(CLASSINFO(wxFrame
)))
3207 wxWindowNotifyEnable(child
, enable
);
3211 bool wxWindowGTK::Enable( bool enable
)
3213 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3215 if (!wxWindowBase::Enable(enable
))
3221 gtk_widget_set_sensitive( m_widget
, enable
);
3223 gtk_widget_set_sensitive( m_wxwindow
, enable
);
3225 wxWindowNotifyEnable(this, enable
);
3230 int wxWindowGTK::GetCharHeight() const
3232 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
3234 wxFont font
= GetFont();
3235 wxCHECK_MSG( font
.Ok(), 12, wxT("invalid font") );
3237 PangoContext
*context
= NULL
;
3239 context
= gtk_widget_get_pango_context( m_widget
);
3244 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
3245 PangoLayout
*layout
= pango_layout_new(context
);
3246 pango_layout_set_font_description(layout
, desc
);
3247 pango_layout_set_text(layout
, "H", 1);
3248 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
3250 PangoRectangle rect
;
3251 pango_layout_line_get_extents(line
, NULL
, &rect
);
3253 g_object_unref (layout
);
3255 return (int) PANGO_PIXELS(rect
.height
);
3258 int wxWindowGTK::GetCharWidth() const
3260 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
3262 wxFont font
= GetFont();
3263 wxCHECK_MSG( font
.Ok(), 8, wxT("invalid font") );
3265 PangoContext
*context
= NULL
;
3267 context
= gtk_widget_get_pango_context( m_widget
);
3272 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
3273 PangoLayout
*layout
= pango_layout_new(context
);
3274 pango_layout_set_font_description(layout
, desc
);
3275 pango_layout_set_text(layout
, "g", 1);
3276 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
3278 PangoRectangle rect
;
3279 pango_layout_line_get_extents(line
, NULL
, &rect
);
3281 g_object_unref (layout
);
3283 return (int) PANGO_PIXELS(rect
.width
);
3286 void wxWindowGTK::GetTextExtent( const wxString
& string
,
3290 int *externalLeading
,
3291 const wxFont
*theFont
) const
3293 wxFont fontToUse
= theFont
? *theFont
: GetFont();
3295 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
3304 PangoContext
*context
= NULL
;
3306 context
= gtk_widget_get_pango_context( m_widget
);
3315 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
3316 PangoLayout
*layout
= pango_layout_new(context
);
3317 pango_layout_set_font_description(layout
, desc
);
3319 const wxCharBuffer data
= wxGTK_CONV( string
);
3321 pango_layout_set_text(layout
, data
, strlen(data
));
3324 PangoRectangle rect
;
3325 pango_layout_get_extents(layout
, NULL
, &rect
);
3327 if (x
) (*x
) = (wxCoord
) PANGO_PIXELS(rect
.width
);
3328 if (y
) (*y
) = (wxCoord
) PANGO_PIXELS(rect
.height
);
3331 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
3332 int baseline
= pango_layout_iter_get_baseline(iter
);
3333 pango_layout_iter_free(iter
);
3334 *descent
= *y
- PANGO_PIXELS(baseline
);
3336 if (externalLeading
) (*externalLeading
) = 0; // ??
3338 g_object_unref (layout
);
3341 bool wxWindowGTK::GTKSetDelayedFocusIfNeeded()
3343 if ( g_delayedFocus
== this )
3345 if ( GTK_WIDGET_REALIZED(m_widget
) )
3347 gtk_widget_grab_focus(m_widget
);
3348 g_delayedFocus
= NULL
;
3357 void wxWindowGTK::SetFocus()
3359 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3362 // don't do anything if we already have focus
3368 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow
))
3370 gtk_widget_grab_focus (m_wxwindow
);
3375 if (GTK_IS_CONTAINER(m_widget
))
3377 if (IsKindOf(CLASSINFO(wxRadioButton
)))
3379 gtk_widget_grab_focus (m_widget
);
3383 gtk_widget_child_focus( m_widget
, GTK_DIR_TAB_FORWARD
);
3386 if (GTK_WIDGET_CAN_FOCUS(m_widget
) && !GTK_WIDGET_HAS_FOCUS (m_widget
) )
3389 if (!GTK_WIDGET_REALIZED(m_widget
))
3391 // we can't set the focus to the widget now so we remember that
3392 // it should be focused and will do it later, during the idle
3393 // time, as soon as we can
3394 wxLogTrace(TRACE_FOCUS
,
3395 _T("Delaying setting focus to %s(%s)"),
3396 GetClassInfo()->GetClassName(), GetLabel().c_str());
3398 g_delayedFocus
= this;
3402 wxLogTrace(TRACE_FOCUS
,
3403 _T("Setting focus to %s(%s)"),
3404 GetClassInfo()->GetClassName(), GetLabel().c_str());
3406 gtk_widget_grab_focus (m_widget
);
3411 wxLogTrace(TRACE_FOCUS
,
3412 _T("Can't set focus to %s(%s)"),
3413 GetClassInfo()->GetClassName(), GetLabel().c_str());
3418 bool wxWindowGTK::AcceptsFocus() const
3420 return m_acceptsFocus
&& wxWindowBase::AcceptsFocus();
3423 bool wxWindowGTK::Reparent( wxWindowBase
*newParentBase
)
3425 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3427 wxWindowGTK
*oldParent
= m_parent
,
3428 *newParent
= (wxWindowGTK
*)newParentBase
;
3430 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3432 if ( !wxWindowBase::Reparent(newParent
) )
3435 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3437 /* prevent GTK from deleting the widget arbitrarily */
3438 gtk_widget_ref( m_widget
);
3442 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3445 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3449 if (GTK_WIDGET_VISIBLE (newParent
->m_widget
))
3451 m_showOnIdle
= true;
3452 gtk_widget_hide( m_widget
);
3455 /* insert GTK representation */
3456 (*(newParent
->m_insertCallback
))(newParent
, this);
3459 /* reverse: prevent GTK from deleting the widget arbitrarily */
3460 gtk_widget_unref( m_widget
);
3462 SetLayoutDirection(wxLayout_Default
);
3467 void wxWindowGTK::DoAddChild(wxWindowGTK
*child
)
3469 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3471 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3473 wxASSERT_MSG( (m_insertCallback
!= NULL
), wxT("invalid child insertion function") );
3478 /* insert GTK representation */
3479 (*m_insertCallback
)(this, child
);
3482 void wxWindowGTK::AddChild(wxWindowBase
*child
)
3484 wxWindowBase::AddChild(child
);
3485 m_dirtyTabOrder
= true;
3487 wxapp_install_idle_handler();
3490 void wxWindowGTK::RemoveChild(wxWindowBase
*child
)
3492 wxWindowBase::RemoveChild(child
);
3493 m_dirtyTabOrder
= true;
3495 wxapp_install_idle_handler();
3499 wxLayoutDirection
wxWindowGTK::GTKGetLayout(GtkWidget
*widget
)
3501 return gtk_widget_get_direction(GTK_WIDGET(widget
)) == GTK_TEXT_DIR_RTL
3502 ? wxLayout_RightToLeft
3503 : wxLayout_LeftToRight
;
3507 void wxWindowGTK::GTKSetLayout(GtkWidget
*widget
, wxLayoutDirection dir
)
3509 wxASSERT_MSG( dir
!= wxLayout_Default
, _T("invalid layout direction") );
3511 gtk_widget_set_direction(GTK_WIDGET(widget
),
3512 dir
== wxLayout_RightToLeft
? GTK_TEXT_DIR_RTL
3513 : GTK_TEXT_DIR_LTR
);
3516 wxLayoutDirection
wxWindowGTK::GetLayoutDirection() const
3518 return GTKGetLayout(m_widget
);
3521 void wxWindowGTK::SetLayoutDirection(wxLayoutDirection dir
)
3523 if ( dir
== wxLayout_Default
)
3525 const wxWindow
*const parent
= GetParent();
3528 // inherit layout from parent.
3529 dir
= parent
->GetLayoutDirection();
3531 else // no parent, use global default layout
3533 dir
= wxTheApp
->GetLayoutDirection();
3537 if ( dir
== wxLayout_Default
)
3540 GTKSetLayout(m_widget
, dir
);
3543 GTKSetLayout(m_wxwindow
, dir
);
3547 wxWindowGTK::AdjustForLayoutDirection(wxCoord x
,
3548 wxCoord
WXUNUSED(width
),
3549 wxCoord
WXUNUSED(widthTotal
)) const
3551 // We now mirrors the coordinates of RTL windows in GtkPizza
3555 void wxWindowGTK::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
3557 wxWindowBase::DoMoveInTabOrder(win
, move
);
3558 m_dirtyTabOrder
= true;
3560 wxapp_install_idle_handler();
3563 bool wxWindowGTK::GTKWidgetNeedsMnemonic() const
3565 // none needed by default
3569 void wxWindowGTK::GTKWidgetDoSetMnemonic(GtkWidget
* WXUNUSED(w
))
3571 // nothing to do by default since none is needed
3574 void wxWindowGTK::RealizeTabOrder()
3578 if ( !m_children
.empty() )
3580 // we don't only construct the correct focus chain but also use
3581 // this opportunity to update the mnemonic widgets for the widgets
3584 GList
*chain
= NULL
;
3585 wxWindowGTK
* mnemonicWindow
= NULL
;
3587 for ( wxWindowList::const_iterator i
= m_children
.begin();
3588 i
!= m_children
.end();
3591 wxWindowGTK
*win
= *i
;
3593 if ( mnemonicWindow
)
3595 if ( win
->AcceptsFocusFromKeyboard() )
3597 // wxComboBox et al. needs to focus on on a different
3598 // widget than m_widget, so if the main widget isn't
3599 // focusable try the connect widget
3600 GtkWidget
* w
= win
->m_widget
;
3601 if ( !GTK_WIDGET_CAN_FOCUS(w
) )
3603 w
= win
->GetConnectWidget();
3604 if ( !GTK_WIDGET_CAN_FOCUS(w
) )
3610 mnemonicWindow
->GTKWidgetDoSetMnemonic(w
);
3611 mnemonicWindow
= NULL
;
3615 else if ( win
->GTKWidgetNeedsMnemonic() )
3617 mnemonicWindow
= win
;
3620 chain
= g_list_prepend(chain
, win
->m_widget
);
3623 chain
= g_list_reverse(chain
);
3625 gtk_container_set_focus_chain(GTK_CONTAINER(m_wxwindow
), chain
);
3630 gtk_container_unset_focus_chain(GTK_CONTAINER(m_wxwindow
));
3635 void wxWindowGTK::Raise()
3637 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3639 if (m_wxwindow
&& m_wxwindow
->window
)
3641 gdk_window_raise( m_wxwindow
->window
);
3643 else if (m_widget
->window
)
3645 gdk_window_raise( m_widget
->window
);
3649 void wxWindowGTK::Lower()
3651 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3653 if (m_wxwindow
&& m_wxwindow
->window
)
3655 gdk_window_lower( m_wxwindow
->window
);
3657 else if (m_widget
->window
)
3659 gdk_window_lower( m_widget
->window
);
3663 bool wxWindowGTK::SetCursor( const wxCursor
&cursor
)
3665 if ( !wxWindowBase::SetCursor(cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
) )
3673 void wxWindowGTK::GTKUpdateCursor()
3675 wxCursor
cursor(g_globalCursor
.Ok() ? g_globalCursor
: GetCursor());
3678 wxArrayGdkWindows windowsThis
;
3679 GdkWindow
* const winThis
= GTKGetWindow(windowsThis
);
3682 gdk_window_set_cursor(winThis
, cursor
.GetCursor());
3686 const size_t count
= windowsThis
.size();
3687 for ( size_t n
= 0; n
< count
; n
++ )
3689 GdkWindow
*win
= windowsThis
[n
];
3692 wxFAIL_MSG(_T("NULL window returned by GTKGetWindow()?"));
3696 gdk_window_set_cursor(win
, cursor
.GetCursor());
3702 void wxWindowGTK::WarpPointer( int x
, int y
)
3704 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3706 // We provide this function ourselves as it is
3707 // missing in GDK (top of this file).
3709 GdkWindow
*window
= (GdkWindow
*) NULL
;
3711 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3713 window
= GetConnectWidget()->window
;
3716 gdk_window_warp_pointer( window
, x
, y
);
3719 wxWindowGTK::ScrollDir
wxWindowGTK::ScrollDirFromRange(GtkRange
*range
) const
3721 // find the scrollbar which generated the event
3722 for ( int dir
= 0; dir
< ScrollDir_Max
; dir
++ )
3724 if ( range
== m_scrollBar
[dir
] )
3725 return (ScrollDir
)dir
;
3728 wxFAIL_MSG( _T("event from unknown scrollbar received") );
3730 return ScrollDir_Max
;
3733 bool wxWindowGTK::DoScrollByUnits(ScrollDir dir
, ScrollUnit unit
, int units
)
3735 bool changed
= false;
3736 GtkRange
* range
= m_scrollBar
[dir
];
3737 if ( range
&& units
)
3739 GtkAdjustment
* adj
= range
->adjustment
;
3740 gdouble inc
= unit
== ScrollUnit_Line
? adj
->step_increment
3741 : adj
->page_increment
;
3743 const int posOld
= int(adj
->value
+ 0.5);
3744 gtk_range_set_value(range
, posOld
+ units
*inc
);
3746 changed
= int(adj
->value
+ 0.5) != posOld
;
3752 bool wxWindowGTK::ScrollLines(int lines
)
3754 return DoScrollByUnits(ScrollDir_Vert
, ScrollUnit_Line
, lines
);
3757 bool wxWindowGTK::ScrollPages(int pages
)
3759 return DoScrollByUnits(ScrollDir_Vert
, ScrollUnit_Page
, pages
);
3762 void wxWindowGTK::Refresh( bool eraseBackground
, const wxRect
*rect
)
3766 if (!m_widget
->window
)
3771 if (!GTK_PIZZA(m_wxwindow
)->bin_window
) return;
3773 GdkRectangle gdk_rect
,
3777 gdk_rect
.x
= rect
->x
;
3778 gdk_rect
.y
= rect
->y
;
3779 gdk_rect
.width
= rect
->width
;
3780 gdk_rect
.height
= rect
->height
;
3781 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3782 gdk_rect
.x
= GetClientSize().x
- gdk_rect
.x
- gdk_rect
.width
;
3786 else // invalidate everything
3791 gdk_window_invalidate_rect( GTK_PIZZA(m_wxwindow
)->bin_window
, p
, TRUE
);
3795 void wxWindowGTK::Update()
3799 // when we call Update() we really want to update the window immediately on
3800 // screen, even if it means flushing the entire queue and hence slowing down
3801 // everything -- but it should still be done, it's just that Update() should
3802 // be called very rarely
3806 void wxWindowGTK::GtkUpdate()
3808 if (m_wxwindow
&& GTK_PIZZA(m_wxwindow
)->bin_window
)
3809 gdk_window_process_updates( GTK_PIZZA(m_wxwindow
)->bin_window
, FALSE
);
3810 if (m_widget
&& m_widget
->window
)
3811 gdk_window_process_updates( m_widget
->window
, FALSE
);
3813 // for consistency with other platforms (and also because it's convenient
3814 // to be able to update an entire TLW by calling Update() only once), we
3815 // should also update all our children here
3816 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3818 node
= node
->GetNext() )
3820 node
->GetData()->GtkUpdate();
3824 bool wxWindowGTK::DoIsExposed( int x
, int y
) const
3826 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
3830 bool wxWindowGTK::DoIsExposed( int x
, int y
, int w
, int h
) const
3832 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3833 return m_updateRegion
.Contains(x
-w
, y
, w
, h
) != wxOutRegion
;
3835 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
3838 void wxWindowGTK::GtkSendPaintEvents()
3842 m_updateRegion
.Clear();
3846 // Clip to paint region in wxClientDC
3847 m_clipPaintRegion
= true;
3849 m_nativeUpdateRegion
= m_updateRegion
;
3851 if (GetLayoutDirection() == wxLayout_RightToLeft
)
3853 // Transform m_updateRegion under RTL
3854 m_updateRegion
.Clear();
3857 gdk_window_get_geometry( GTK_PIZZA(m_wxwindow
)->bin_window
,
3858 NULL
, NULL
, &width
, NULL
, NULL
);
3860 wxRegionIterator
upd( m_nativeUpdateRegion
);
3864 rect
.x
= upd
.GetX();
3865 rect
.y
= upd
.GetY();
3866 rect
.width
= upd
.GetWidth();
3867 rect
.height
= upd
.GetHeight();
3869 rect
.x
= width
- rect
.x
- rect
.width
;
3870 m_updateRegion
.Union( rect
);
3876 // widget to draw on
3877 GtkPizza
*pizza
= GTK_PIZZA (m_wxwindow
);
3879 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM
))
3881 // find ancestor from which to steal background
3882 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3884 parent
= (wxWindow
*)this;
3886 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
3888 wxRegionIterator
upd( m_nativeUpdateRegion
);
3892 rect
.x
= upd
.GetX();
3893 rect
.y
= upd
.GetY();
3894 rect
.width
= upd
.GetWidth();
3895 rect
.height
= upd
.GetHeight();
3897 gtk_paint_flat_box( parent
->m_widget
->style
,
3899 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
3912 wxWindowDC
dc( (wxWindow
*)this );
3913 dc
.SetClippingRegion( m_updateRegion
);
3915 wxEraseEvent
erase_event( GetId(), &dc
);
3916 erase_event
.SetEventObject( this );
3918 GetEventHandler()->ProcessEvent(erase_event
);
3921 wxNcPaintEvent
nc_paint_event( GetId() );
3922 nc_paint_event
.SetEventObject( this );
3923 GetEventHandler()->ProcessEvent( nc_paint_event
);
3925 wxPaintEvent
paint_event( GetId() );
3926 paint_event
.SetEventObject( this );
3927 GetEventHandler()->ProcessEvent( paint_event
);
3929 m_clipPaintRegion
= false;
3931 m_updateRegion
.Clear();
3932 m_nativeUpdateRegion
.Clear();
3935 void wxWindowGTK::SetDoubleBuffered( bool on
)
3937 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3940 gtk_widget_set_double_buffered( m_wxwindow
, on
);
3943 bool wxWindowGTK::IsDoubleBuffered() const
3945 return GTK_WIDGET_DOUBLE_BUFFERED( m_wxwindow
);
3948 void wxWindowGTK::ClearBackground()
3950 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3954 void wxWindowGTK::DoSetToolTip( wxToolTip
*tip
)
3956 wxWindowBase::DoSetToolTip(tip
);
3959 m_tooltip
->Apply( (wxWindow
*)this );
3962 void wxWindowGTK::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
3964 wxString
tmp( tip
);
3965 gtk_tooltips_set_tip( tips
, GetConnectWidget(), wxGTK_CONV(tmp
), (gchar
*) NULL
);
3967 #endif // wxUSE_TOOLTIPS
3969 bool wxWindowGTK::SetBackgroundColour( const wxColour
&colour
)
3971 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3973 if (!wxWindowBase::SetBackgroundColour(colour
))
3978 // We need the pixel value e.g. for background clearing.
3979 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3982 // apply style change (forceStyle=true so that new style is applied
3983 // even if the bg colour changed from valid to wxNullColour)
3984 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3985 ApplyWidgetStyle(true);
3990 bool wxWindowGTK::SetForegroundColour( const wxColour
&colour
)
3992 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3994 if (!wxWindowBase::SetForegroundColour(colour
))
4001 // We need the pixel value e.g. for background clearing.
4002 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
4005 // apply style change (forceStyle=true so that new style is applied
4006 // even if the bg colour changed from valid to wxNullColour):
4007 ApplyWidgetStyle(true);
4012 PangoContext
*wxWindowGTK::GtkGetPangoDefaultContext()
4014 return gtk_widget_get_pango_context( m_widget
);
4017 GtkRcStyle
*wxWindowGTK::CreateWidgetStyle(bool forceStyle
)
4019 // do we need to apply any changes at all?
4022 !m_foregroundColour
.Ok() && !m_backgroundColour
.Ok() )
4027 GtkRcStyle
*style
= gtk_rc_style_new();
4032 pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
4035 if ( m_foregroundColour
.Ok() )
4037 const GdkColor
*fg
= m_foregroundColour
.GetColor();
4039 style
->fg
[GTK_STATE_NORMAL
] = *fg
;
4040 style
->color_flags
[GTK_STATE_NORMAL
] = GTK_RC_FG
;
4042 style
->fg
[GTK_STATE_PRELIGHT
] = *fg
;
4043 style
->color_flags
[GTK_STATE_PRELIGHT
] = GTK_RC_FG
;
4045 style
->fg
[GTK_STATE_ACTIVE
] = *fg
;
4046 style
->color_flags
[GTK_STATE_ACTIVE
] = GTK_RC_FG
;
4049 if ( m_backgroundColour
.Ok() )
4051 const GdkColor
*bg
= m_backgroundColour
.GetColor();
4053 style
->bg
[GTK_STATE_NORMAL
] = *bg
;
4054 style
->base
[GTK_STATE_NORMAL
] = *bg
;
4055 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)
4056 (style
->color_flags
[GTK_STATE_NORMAL
] | GTK_RC_BG
| GTK_RC_BASE
);
4058 style
->bg
[GTK_STATE_PRELIGHT
] = *bg
;
4059 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
4060 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)
4061 (style
->color_flags
[GTK_STATE_PRELIGHT
] | GTK_RC_BG
| GTK_RC_BASE
);
4063 style
->bg
[GTK_STATE_ACTIVE
] = *bg
;
4064 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
4065 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)
4066 (style
->color_flags
[GTK_STATE_ACTIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
4068 style
->bg
[GTK_STATE_INSENSITIVE
] = *bg
;
4069 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
4070 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)
4071 (style
->color_flags
[GTK_STATE_INSENSITIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
4077 void wxWindowGTK::ApplyWidgetStyle(bool forceStyle
)
4079 GtkRcStyle
*style
= CreateWidgetStyle(forceStyle
);
4082 DoApplyWidgetStyle(style
);
4083 gtk_rc_style_unref(style
);
4086 // Style change may affect GTK+'s size calculation:
4087 InvalidateBestSize();
4090 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle
*style
)
4093 gtk_widget_modify_style(m_wxwindow
, style
);
4095 gtk_widget_modify_style(m_widget
, style
);
4098 bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style
)
4100 wxWindowBase::SetBackgroundStyle(style
);
4102 if (style
== wxBG_STYLE_CUSTOM
)
4104 GdkWindow
*window
= (GdkWindow
*) NULL
;
4106 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4108 window
= GetConnectWidget()->window
;
4112 // Make sure GDK/X11 doesn't refresh the window
4114 gdk_window_set_back_pixmap( window
, None
, False
);
4116 Display
* display
= GDK_WINDOW_DISPLAY(window
);
4119 m_needsStyleChange
= false;
4122 // Do in OnIdle, because the window is not yet available
4123 m_needsStyleChange
= true;
4125 // Don't apply widget style, or we get a grey background
4129 // apply style change (forceStyle=true so that new style is applied
4130 // even if the bg colour changed from valid to wxNullColour):
4131 ApplyWidgetStyle(true);
4136 #if wxUSE_DRAG_AND_DROP
4138 void wxWindowGTK::SetDropTarget( wxDropTarget
*dropTarget
)
4140 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4142 GtkWidget
*dnd_widget
= GetConnectWidget();
4144 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
4146 if (m_dropTarget
) delete m_dropTarget
;
4147 m_dropTarget
= dropTarget
;
4149 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
4152 #endif // wxUSE_DRAG_AND_DROP
4154 GtkWidget
* wxWindowGTK::GetConnectWidget()
4156 GtkWidget
*connect_widget
= m_widget
;
4157 if (m_wxwindow
) connect_widget
= m_wxwindow
;
4159 return connect_widget
;
4162 bool wxWindowGTK::GTKIsOwnWindow(GdkWindow
*window
) const
4164 wxArrayGdkWindows windowsThis
;
4165 GdkWindow
* const winThis
= GTKGetWindow(windowsThis
);
4167 return winThis
? window
== winThis
4168 : windowsThis
.Index(window
) != wxNOT_FOUND
;
4171 GdkWindow
*wxWindowGTK::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
4173 return m_wxwindow
? GTK_PIZZA(m_wxwindow
)->bin_window
: m_widget
->window
;
4176 bool wxWindowGTK::SetFont( const wxFont
&font
)
4178 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
4180 if (!wxWindowBase::SetFont(font
))
4183 // apply style change (forceStyle=true so that new style is applied
4184 // even if the font changed from valid to wxNullFont):
4185 ApplyWidgetStyle(true);
4190 void wxWindowGTK::DoCaptureMouse()
4192 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4194 GdkWindow
*window
= (GdkWindow
*) NULL
;
4196 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4198 window
= GetConnectWidget()->window
;
4200 wxCHECK_RET( window
, _T("CaptureMouse() failed") );
4202 const wxCursor
* cursor
= &m_cursor
;
4204 cursor
= wxSTANDARD_CURSOR
;
4206 gdk_pointer_grab( window
, FALSE
,
4208 (GDK_BUTTON_PRESS_MASK
|
4209 GDK_BUTTON_RELEASE_MASK
|
4210 GDK_POINTER_MOTION_HINT_MASK
|
4211 GDK_POINTER_MOTION_MASK
),
4213 cursor
->GetCursor(),
4214 (guint32
)GDK_CURRENT_TIME
);
4215 g_captureWindow
= this;
4216 g_captureWindowHasMouse
= true;
4219 void wxWindowGTK::DoReleaseMouse()
4221 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4223 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
4225 g_captureWindow
= (wxWindowGTK
*) NULL
;
4227 GdkWindow
*window
= (GdkWindow
*) NULL
;
4229 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4231 window
= GetConnectWidget()->window
;
4236 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
4240 wxWindow
*wxWindowBase::GetCapture()
4242 return (wxWindow
*)g_captureWindow
;
4245 bool wxWindowGTK::IsRetained() const
4250 void wxWindowGTK::BlockScrollEvent()
4252 wxASSERT(!m_blockScrollEvent
);
4253 m_blockScrollEvent
= true;
4256 void wxWindowGTK::UnblockScrollEvent()
4258 wxASSERT(m_blockScrollEvent
);
4259 m_blockScrollEvent
= false;
4262 void wxWindowGTK::SetScrollbar(int orient
,
4266 bool WXUNUSED(update
))
4268 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4269 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4273 m_hasScrolling
= true;
4277 // GtkRange requires upper > lower
4282 if (pos
> range
- thumbVisible
)
4283 pos
= range
- thumbVisible
;
4286 GtkAdjustment
* adj
= m_scrollBar
[ScrollDirFromOrient(orient
)]->adjustment
;
4287 adj
->step_increment
= 1;
4288 adj
->page_increment
=
4289 adj
->page_size
= thumbVisible
;
4291 SetScrollPos(orient
, pos
);
4292 gtk_adjustment_changed(adj
);
4295 void wxWindowGTK::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
4297 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4298 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4300 // This check is more than an optimization. Without it, the slider
4301 // will not move smoothly while tracking when using wxScrollHelper.
4302 if (GetScrollPos(orient
) != pos
)
4304 const int dir
= ScrollDirFromOrient(orient
);
4305 GtkAdjustment
* adj
= m_scrollBar
[dir
]->adjustment
;
4306 const int max
= int(adj
->upper
- adj
->page_size
);
4311 m_scrollPos
[dir
] = adj
->value
= pos
;
4313 // If a "value_changed" signal emission is not already in progress
4314 if (!m_blockValueChanged
[dir
])
4316 gtk_adjustment_value_changed(adj
);
4321 int wxWindowGTK::GetScrollThumb(int orient
) const
4323 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4324 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4326 return int(m_scrollBar
[ScrollDirFromOrient(orient
)]->adjustment
->page_size
);
4329 int wxWindowGTK::GetScrollPos( int orient
) const
4331 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4332 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4334 return int(m_scrollBar
[ScrollDirFromOrient(orient
)]->adjustment
->value
+ 0.5);
4337 int wxWindowGTK::GetScrollRange( int orient
) const
4339 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4340 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4342 return int(m_scrollBar
[ScrollDirFromOrient(orient
)]->adjustment
->upper
);
4345 // Determine if increment is the same as +/-x, allowing for some small
4346 // difference due to possible inexactness in floating point arithmetic
4347 static inline bool IsScrollIncrement(double increment
, double x
)
4349 wxASSERT(increment
> 0);
4350 const double tolerance
= 1.0 / 1024;
4351 return fabs(increment
- fabs(x
)) < tolerance
;
4354 wxEventType
wxWindowGTK::GetScrollEventType(GtkRange
* range
)
4359 wxapp_install_idle_handler();
4361 wxASSERT(range
== m_scrollBar
[0] || range
== m_scrollBar
[1]);
4363 const int barIndex
= range
== m_scrollBar
[1];
4364 GtkAdjustment
* adj
= range
->adjustment
;
4366 const int value
= int(adj
->value
+ 0.5);
4368 // save previous position
4369 const double oldPos
= m_scrollPos
[barIndex
];
4370 // update current position
4371 m_scrollPos
[barIndex
] = adj
->value
;
4372 // If event should be ignored, or integral position has not changed
4373 if (!m_hasVMT
|| g_blockEventsOnDrag
|| value
== int(oldPos
+ 0.5))
4378 wxEventType eventType
= wxEVT_SCROLL_THUMBTRACK
;
4381 // Difference from last change event
4382 const double diff
= adj
->value
- oldPos
;
4383 const bool isDown
= diff
> 0;
4385 if (IsScrollIncrement(adj
->step_increment
, diff
))
4387 eventType
= isDown
? wxEVT_SCROLL_LINEDOWN
: wxEVT_SCROLL_LINEUP
;
4389 else if (IsScrollIncrement(adj
->page_increment
, diff
))
4391 eventType
= isDown
? wxEVT_SCROLL_PAGEDOWN
: wxEVT_SCROLL_PAGEUP
;
4393 else if (m_mouseButtonDown
)
4395 // Assume track event
4396 m_isScrolling
= true;
4402 void wxWindowGTK::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4404 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4406 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4408 // No scrolling requested.
4409 if ((dx
== 0) && (dy
== 0)) return;
4411 m_clipPaintRegion
= true;
4413 if (GetLayoutDirection() == wxLayout_RightToLeft
)
4414 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow
), dx
, -dy
);
4416 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow
), -dx
, -dy
);
4418 m_clipPaintRegion
= false;
4421 void wxWindowGTK::GtkScrolledWindowSetBorder(GtkWidget
* w
, int wxstyle
)
4423 //RN: Note that static controls usually have no border on gtk, so maybe
4424 //it makes sense to treat that as simply no border at the wx level
4426 if (!(wxstyle
& wxNO_BORDER
) && !(wxstyle
& wxBORDER_STATIC
))
4428 GtkShadowType gtkstyle
;
4430 if(wxstyle
& wxBORDER_RAISED
)
4431 gtkstyle
= GTK_SHADOW_OUT
;
4432 else if (wxstyle
& wxBORDER_SUNKEN
)
4433 gtkstyle
= GTK_SHADOW_IN
;
4434 else if (wxstyle
& wxBORDER_DOUBLE
)
4435 gtkstyle
= GTK_SHADOW_ETCHED_IN
;
4437 gtkstyle
= GTK_SHADOW_IN
;
4439 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(w
),
4444 void wxWindowGTK::SetWindowStyleFlag( long style
)
4446 // Updates the internal variable. NB: Now m_windowStyle bits carry the _new_ style values already
4447 wxWindowBase::SetWindowStyleFlag(style
);
4450 // Find the wxWindow at the current mouse position, also returning the mouse
4452 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4454 pt
= wxGetMousePosition();
4455 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4459 // Get the current mouse position.
4460 wxPoint
wxGetMousePosition()
4462 /* This crashes when used within wxHelpContext,
4463 so we have to use the X-specific implementation below.
4465 GdkModifierType *mask;
4466 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4468 return wxPoint(x, y);
4472 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4474 Display
*display
= windowAtPtr
? GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4475 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4476 Window rootReturn
, childReturn
;
4477 int rootX
, rootY
, winX
, winY
;
4478 unsigned int maskReturn
;
4480 XQueryPointer (display
,
4484 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4485 return wxPoint(rootX
, rootY
);
4489 // Needed for implementing e.g. combobox on wxGTK within a modal dialog.
4490 void wxAddGrab(wxWindow
* window
)
4492 gtk_grab_add( (GtkWidget
*) window
->GetHandle() );
4495 void wxRemoveGrab(wxWindow
* window
)
4497 gtk_grab_remove( (GtkWidget
*) window
->GetHandle() );