1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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/layout.h"
29 #include "wx/dialog.h"
30 #include "wx/msgdlg.h"
31 #include "wx/module.h"
32 #include "wx/combobox.h"
34 #if wxUSE_DRAG_AND_DROP
39 #include "wx/tooltip.h"
47 #include "wx/textctrl.h"
51 #include "wx/statusbr.h"
52 #include "wx/settings.h"
53 #include "wx/fontutil.h"
56 #include "wx/thread.h"
62 #include "wx/gtk1/private.h"
63 #include <gdk/gdkprivate.h>
64 #include <gdk/gdkkeysyms.h>
68 #include <gtk/gtkprivate.h>
70 #include "wx/gtk1/win_gtk.h"
72 //-----------------------------------------------------------------------------
73 // documentation on internals
74 //-----------------------------------------------------------------------------
77 I have been asked several times about writing some documentation about
78 the GTK port of wxWidgets, especially its internal structures. Obviously,
79 you cannot understand wxGTK without knowing a little about the GTK, but
80 some more information about what the wxWindow, which is the base class
81 for all other window classes, does seems required as well.
85 What does wxWindow do? It contains the common interface for the following
86 jobs of its descendants:
88 1) Define the rudimentary behaviour common to all window classes, such as
89 resizing, intercepting user input (so as to make it possible to use these
90 events for special purposes in a derived class), window names etc.
92 2) Provide the possibility to contain and manage children, if the derived
93 class is allowed to contain children, which holds true for those window
94 classes which do not display a native GTK widget. To name them, these
95 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
96 work classes are a special case and are handled a bit differently from
97 the rest. The same holds true for the wxNotebook class.
99 3) Provide the possibility to draw into a client area of a window. This,
100 too, only holds true for classes that do not display a native GTK widget
103 4) Provide the entire mechanism for scrolling widgets. This actual inter-
104 face for this is usually in wxScrolledWindow, but the GTK implementation
107 5) A multitude of helper or extra methods for special purposes, such as
108 Drag'n'Drop, managing validators etc.
110 6) Display a border (sunken, raised, simple or none).
112 Normally one might expect, that one wxWidgets window would always correspond
113 to one GTK widget. Under GTK, there is no such allround widget that has all
114 the functionality. Moreover, the GTK defines a client area as a different
115 widget from the actual widget you are handling. Last but not least some
116 special classes (e.g. wxFrame) handle different categories of widgets and
117 still have the possibility to draw something in the client area.
118 It was therefore required to write a special purpose GTK widget, that would
119 represent a client area in the sense of wxWidgets capable to do the jobs
120 2), 3) and 4). I have written this class and it resides in win_gtk.c of
123 All windows must have a widget, with which they interact with other under-
124 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
125 the wxWindow class has a member variable called m_widget which holds a
126 pointer to this widget. When the window class represents a GTK native widget,
127 this is (in most cases) the only GTK widget the class manages. E.g. the
128 wxStaticText class handles only a GtkLabel widget a pointer to which you
129 can find in m_widget (defined in wxWindow)
131 When the class has a client area for drawing into and for containing children
132 it has to handle the client area widget (of the type GtkPizza, defined in
133 win_gtk.c), but there could be any number of widgets, handled by a class
134 The common rule for all windows is only, that the widget that interacts with
135 the rest of GTK must be referenced in m_widget and all other widgets must be
136 children of this widget on the GTK level. The top-most widget, which also
137 represents the client area, must be in the m_wxwindow field and must be of
140 As I said, the window classes that display a GTK native widget only have
141 one widget, so in the case of e.g. the wxButton class m_widget holds a
142 pointer to a GtkButton widget. But windows with client areas (for drawing
143 and children) have a m_widget field that is a pointer to a GtkScrolled-
144 Window and a m_wxwindow field that is pointer to a GtkPizza and this
145 one is (in the GTK sense) a child of the GtkScrolledWindow.
147 If the m_wxwindow field is set, then all input to this widget is inter-
148 cepted and sent to the wxWidgets class. If not, all input to the widget
149 that gets pointed to by m_widget gets intercepted and sent to the class.
153 The design of scrolling in wxWidgets is markedly different from that offered
154 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
155 clicking on a scrollbar belonging to scrolled window will inevitably move
156 the window. In wxWidgets, the scrollbar will only emit an event, send this
157 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
158 which actually moves the window and its subchildren. Note that GtkPizza
159 memorizes how much it has been scrolled but that wxWidgets forgets this
160 so that the two coordinates systems have to be kept in synch. This is done
161 in various places using the pizza->xoffset and pizza->yoffset values.
165 Singularily the most broken code in GTK is the code that is supposed to
166 inform subwindows (child windows) about new positions. Very often, duplicate
167 events are sent without changes in size or position, equally often no
168 events are sent at all (All this is due to a bug in the GtkContainer code
169 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
170 GTK's own system and it simply waits for size events for toplevel windows
171 and then iterates down the respective size events to all window. This has
172 the disadvantage that windows might get size events before the GTK widget
173 actually has the reported size. This doesn't normally pose any problem, but
174 the OpenGL drawing routines rely on correct behaviour. Therefore, I have
175 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
176 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
177 window that is used for OpenGL output really has that size (as reported by
182 If someone at some point of time feels the immense desire to have a look at,
183 change or attempt to optimise the Refresh() logic, this person will need an
184 intimate understanding of what "draw" and "expose" events are and what
185 they are used for, in particular when used in connection with GTK's
186 own windowless widgets. Beware.
190 Cursors, too, have been a constant source of pleasure. The main difficulty
191 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
192 for the parent. To prevent this from doing too much harm, I use idle time
193 to set the cursor over and over again, starting from the toplevel windows
194 and ending with the youngest generation (speaking of parent and child windows).
195 Also don't forget that cursors (like much else) are connected to GdkWindows,
196 not GtkWidgets and that the "window" field of a GtkWidget might very well
197 point to the GdkWindow of the parent widget (-> "window-less widget") and
198 that the two obviously have very different meanings.
202 //-----------------------------------------------------------------------------
204 //-----------------------------------------------------------------------------
206 extern wxList wxPendingDelete
;
207 extern bool g_blockEventsOnDrag
;
208 extern bool g_blockEventsOnScroll
;
209 extern wxCursor g_globalCursor
;
211 static GdkGC
*g_eraseGC
= NULL
;
213 // mouse capture state: the window which has it and if the mouse is currently
215 static wxWindowGTK
*g_captureWindow
= (wxWindowGTK
*) NULL
;
216 static bool g_captureWindowHasMouse
= false;
218 wxWindowGTK
*g_focusWindow
= (wxWindowGTK
*) NULL
;
220 // the last window which had the focus - this is normally never NULL (except
221 // if we never had focus at all) as even when g_focusWindow is NULL it still
222 // keeps its previous value
223 wxWindowGTK
*g_focusWindowLast
= (wxWindowGTK
*) NULL
;
225 // If a window get the focus set but has not been realized
226 // yet, defer setting the focus to idle time.
227 wxWindowGTK
*g_delayedFocus
= (wxWindowGTK
*) NULL
;
229 // hack: we need something to pass to gtk_menu_popup, so we store the time of
230 // the last click here (extern: used from gtk/menu.cpp)
231 guint32 wxGtkTimeLastClick
= 0;
233 extern bool g_mainThreadLocked
;
235 //-----------------------------------------------------------------------------
237 //-----------------------------------------------------------------------------
242 # define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
244 # define DEBUG_MAIN_THREAD
247 #define DEBUG_MAIN_THREAD
250 // the trace mask used for the focus debugging messages
251 #define TRACE_FOCUS _T("focus")
253 //-----------------------------------------------------------------------------
254 // missing gdk functions
255 //-----------------------------------------------------------------------------
258 gdk_window_warp_pointer (GdkWindow
*window
,
262 GdkWindowPrivate
*priv
;
265 window
= GDK_ROOT_PARENT();
267 priv
= (GdkWindowPrivate
*) window
;
269 if (!priv
->destroyed
)
271 XWarpPointer (priv
->xdisplay
,
272 None
, /* not source window -> move from anywhere */
273 priv
->xwindow
, /* dest window */
274 0, 0, 0, 0, /* not source window -> move from anywhere */
279 //-----------------------------------------------------------------------------
281 //-----------------------------------------------------------------------------
283 extern void wxapp_install_idle_handler();
284 extern bool g_isIdle
;
286 //-----------------------------------------------------------------------------
287 // local code (see below)
288 //-----------------------------------------------------------------------------
290 // returns the child of win which currently has focus or NULL if not found
292 // Note: can't be static, needed by textctrl.cpp.
293 wxWindow
*wxFindFocusedChild(wxWindowGTK
*win
)
295 wxWindow
*winFocus
= wxWindowGTK::FindFocus();
297 return (wxWindow
*)NULL
;
299 if ( winFocus
== win
)
300 return (wxWindow
*)win
;
302 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
304 node
= node
->GetNext() )
306 wxWindow
*child
= wxFindFocusedChild(node
->GetData());
311 return (wxWindow
*)NULL
;
314 static void draw_frame( GtkWidget
*widget
, wxWindowGTK
*win
)
316 // wxUniversal widgets draw the borders and scrollbars themselves
317 #ifndef __WXUNIVERSAL__
324 if (win
->m_hasScrolling
)
326 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(widget
);
328 GtkRequisition vscroll_req
;
329 vscroll_req
.width
= 2;
330 vscroll_req
.height
= 2;
331 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
332 (scroll_window
->vscrollbar
, &vscroll_req
);
334 GtkRequisition hscroll_req
;
335 hscroll_req
.width
= 2;
336 hscroll_req
.height
= 2;
337 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
338 (scroll_window
->hscrollbar
, &hscroll_req
);
340 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(widget
) );
342 if (scroll_window
->vscrollbar_visible
)
344 dw
+= vscroll_req
.width
;
345 dw
+= scroll_class
->scrollbar_spacing
;
348 if (scroll_window
->hscrollbar_visible
)
350 dh
+= hscroll_req
.height
;
351 dh
+= scroll_class
->scrollbar_spacing
;
357 if (GTK_WIDGET_NO_WINDOW (widget
))
359 dx
+= widget
->allocation
.x
;
360 dy
+= widget
->allocation
.y
;
363 if (win
->HasFlag(wxRAISED_BORDER
))
365 gtk_draw_shadow( widget
->style
,
370 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
374 if (win
->HasFlag(wxSUNKEN_BORDER
))
376 gtk_draw_shadow( widget
->style
,
381 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
385 if (win
->HasFlag(wxSIMPLE_BORDER
))
388 gc
= gdk_gc_new( widget
->window
);
389 gdk_gc_set_foreground( gc
, &widget
->style
->black
);
390 gdk_draw_rectangle( widget
->window
, gc
, FALSE
,
392 widget
->allocation
.width
-dw
-1, widget
->allocation
.height
-dh
-1 );
396 #endif // __WXUNIVERSAL__
399 //-----------------------------------------------------------------------------
400 // "expose_event" of m_widget
401 //-----------------------------------------------------------------------------
404 static gint
gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxWindowGTK
*win
)
406 if (gdk_event
->count
> 0) return FALSE
;
408 draw_frame( widget
, win
);
414 //-----------------------------------------------------------------------------
415 // "draw" of m_widget
416 //-----------------------------------------------------------------------------
419 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxWindowGTK
*win
)
421 draw_frame( widget
, win
);
425 //-----------------------------------------------------------------------------
426 // "size_request" of m_widget
427 //-----------------------------------------------------------------------------
429 // make it extern because wxStaticText needs to disconnect this one
431 void wxgtk_window_size_request_callback(GtkWidget
*widget
,
432 GtkRequisition
*requisition
,
436 win
->GetSize( &w
, &h
);
442 requisition
->height
= h
;
443 requisition
->width
= w
;
449 void wxgtk_combo_size_request_callback(GtkWidget
*widget
,
450 GtkRequisition
*requisition
,
453 // This callback is actually hooked into the text entry
454 // of the combo box, not the GtkHBox.
457 win
->GetSize( &w
, &h
);
463 GtkCombo
*gcombo
= GTK_COMBO(win
->m_widget
);
465 GtkRequisition entry_req
;
467 entry_req
.height
= 2;
468 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo
->button
) )->size_request
)
469 (gcombo
->button
, &entry_req
);
471 requisition
->width
= w
- entry_req
.width
;
472 requisition
->height
= entry_req
.height
;
476 //-----------------------------------------------------------------------------
477 // "expose_event" of m_wxwindow
478 //-----------------------------------------------------------------------------
481 static int gtk_window_expose_callback( GtkWidget
*widget
,
482 GdkEventExpose
*gdk_event
,
488 wxapp_install_idle_handler();
490 // This gets called immediately after an expose event
491 // under GTK 1.2 so we collect the calls and wait for
492 // the idle handler to pick things up.
494 win
->GetUpdateRegion().Union( gdk_event
->area
.x
,
496 gdk_event
->area
.width
,
497 gdk_event
->area
.height
);
498 win
->m_clearRegion
.Union( gdk_event
->area
.x
,
500 gdk_event
->area
.width
,
501 gdk_event
->area
.height
);
503 // Actual redrawing takes place in idle time.
510 //-----------------------------------------------------------------------------
511 // "event" of m_wxwindow
512 //-----------------------------------------------------------------------------
514 // GTK thinks it is clever and filters out a certain amount of "unneeded"
515 // expose events. We need them, of course, so we override the main event
516 // procedure in GtkWidget by giving our own handler for all system events.
517 // There, we look for expose events ourselves whereas all other events are
522 gint
gtk_window_event_event_callback( GtkWidget
*widget
,
523 GdkEventExpose
*event
,
526 if (event
->type
== GDK_EXPOSE
)
528 gint ret
= gtk_window_expose_callback( widget
, event
, win
);
536 //-----------------------------------------------------------------------------
537 // "draw" of m_wxwindow
538 //-----------------------------------------------------------------------------
540 // This callback is a complete replacement of the gtk_pizza_draw() function,
541 // which is disabled.
544 static void gtk_window_draw_callback( GtkWidget
*widget
,
551 wxapp_install_idle_handler();
553 // if there are any children we must refresh everything
556 if ( !win
->HasFlag(wxFULL_REPAINT_ON_RESIZE
) &&
557 win
->GetChildren().IsEmpty() )
565 wxPrintf( wxT("OnDraw from ") );
566 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
567 wxPrintf( win
->GetClassInfo()->GetClassName() );
568 wxPrintf( wxT(" %d %d %d %d\n"), (int)rect
->x
,
575 #ifndef __WXUNIVERSAL__
576 GtkPizza
*pizza
= GTK_PIZZA (widget
);
578 if (win
->GetThemeEnabled() && win
->GetBackgroundStyle() == wxBG_STYLE_SYSTEM
)
580 wxWindow
*parent
= win
->GetParent();
581 while (parent
&& !parent
->IsTopLevel())
582 parent
= parent
->GetParent();
586 gtk_paint_flat_box (parent
->m_widget
->style
,
597 win
->m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
598 win
->GetUpdateRegion().Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
600 // Update immediately, not in idle time.
603 #ifndef __WXUNIVERSAL__
604 // Redraw child widgets
605 GList
*children
= pizza
->children
;
608 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
609 children
= children
->next
;
611 GdkRectangle child_area
;
612 if (gtk_widget_intersect (child
->widget
, rect
, &child_area
))
614 gtk_widget_draw (child
->widget
, &child_area
/* (GdkRectangle*) NULL*/ );
621 //-----------------------------------------------------------------------------
622 // "key_press_event" from any window
623 //-----------------------------------------------------------------------------
625 // set WXTRACE to this to see the key event codes on the console
626 #define TRACE_KEYS _T("keyevent")
628 // translates an X key symbol to WXK_XXX value
630 // if isChar is true it means that the value returned will be used for EVT_CHAR
631 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
632 // for example, while if it is false it means that the value is going to be
633 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
635 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
641 // Shift, Control and Alt don't generate the CHAR events at all
644 key_code
= isChar
? 0 : WXK_SHIFT
;
648 key_code
= isChar
? 0 : WXK_CONTROL
;
656 key_code
= isChar
? 0 : WXK_ALT
;
659 // neither do the toggle modifies
660 case GDK_Scroll_Lock
:
661 key_code
= isChar
? 0 : WXK_SCROLL
;
665 key_code
= isChar
? 0 : WXK_CAPITAL
;
669 key_code
= isChar
? 0 : WXK_NUMLOCK
;
673 // various other special keys
686 case GDK_ISO_Left_Tab
:
693 key_code
= WXK_RETURN
;
697 key_code
= WXK_CLEAR
;
701 key_code
= WXK_PAUSE
;
705 key_code
= WXK_SELECT
;
709 key_code
= WXK_PRINT
;
713 key_code
= WXK_EXECUTE
;
717 key_code
= WXK_ESCAPE
;
720 // cursor and other extended keyboard keys
722 key_code
= WXK_DELETE
;
738 key_code
= WXK_RIGHT
;
745 case GDK_Prior
: // == GDK_Page_Up
746 key_code
= WXK_PAGEUP
;
749 case GDK_Next
: // == GDK_Page_Down
750 key_code
= WXK_PAGEDOWN
;
762 key_code
= WXK_INSERT
;
777 key_code
= (isChar
? '0' : WXK_NUMPAD0
) + keysym
- GDK_KP_0
;
781 key_code
= isChar
? ' ' : WXK_NUMPAD_SPACE
;
785 key_code
= isChar
? WXK_TAB
: WXK_NUMPAD_TAB
;
789 key_code
= isChar
? WXK_RETURN
: WXK_NUMPAD_ENTER
;
793 key_code
= isChar
? WXK_F1
: WXK_NUMPAD_F1
;
797 key_code
= isChar
? WXK_F2
: WXK_NUMPAD_F2
;
801 key_code
= isChar
? WXK_F3
: WXK_NUMPAD_F3
;
805 key_code
= isChar
? WXK_F4
: WXK_NUMPAD_F4
;
809 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_HOME
;
813 key_code
= isChar
? WXK_LEFT
: WXK_NUMPAD_LEFT
;
817 key_code
= isChar
? WXK_UP
: WXK_NUMPAD_UP
;
821 key_code
= isChar
? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
825 key_code
= isChar
? WXK_DOWN
: WXK_NUMPAD_DOWN
;
828 case GDK_KP_Prior
: // == GDK_KP_Page_Up
829 key_code
= isChar
? WXK_PAGEUP
: WXK_NUMPAD_PAGEUP
;
832 case GDK_KP_Next
: // == GDK_KP_Page_Down
833 key_code
= isChar
? WXK_NEXT
: WXK_NUMPAD_PAGEDOWN
;
837 key_code
= isChar
? WXK_END
: WXK_NUMPAD_END
;
841 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_BEGIN
;
845 key_code
= isChar
? WXK_INSERT
: WXK_NUMPAD_INSERT
;
849 key_code
= isChar
? WXK_DELETE
: WXK_NUMPAD_DELETE
;
853 key_code
= isChar
? '=' : WXK_NUMPAD_EQUAL
;
856 case GDK_KP_Multiply
:
857 key_code
= isChar
? '*' : WXK_NUMPAD_MULTIPLY
;
861 key_code
= isChar
? '+' : WXK_NUMPAD_ADD
;
864 case GDK_KP_Separator
:
865 // FIXME: what is this?
866 key_code
= isChar
? '.' : WXK_NUMPAD_SEPARATOR
;
869 case GDK_KP_Subtract
:
870 key_code
= isChar
? '-' : WXK_NUMPAD_SUBTRACT
;
874 key_code
= isChar
? '.' : WXK_NUMPAD_DECIMAL
;
878 key_code
= isChar
? '/' : WXK_NUMPAD_DIVIDE
;
895 key_code
= WXK_F1
+ keysym
- GDK_F1
;
905 static inline bool wxIsAsciiKeysym(KeySym ks
)
910 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
912 GdkEventKey
*gdk_event
)
916 GdkModifierType state
;
917 if (gdk_event
->window
)
918 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
920 event
.SetTimestamp( gdk_event
->time
);
921 event
.SetId(win
->GetId());
922 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
923 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
924 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
925 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
) != 0;
926 event
.m_scanCode
= gdk_event
->keyval
;
927 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
928 event
.m_rawFlags
= 0;
930 event
.m_uniChar
= gdk_keyval_to_unicode(gdk_event
->keyval
);
932 wxGetMousePosition( &x
, &y
);
933 win
->ScreenToClient( &x
, &y
);
936 event
.SetEventObject( win
);
941 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
943 GdkEventKey
*gdk_event
)
945 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
946 // but only event->keyval which is quite useless to us, so remember
947 // the last character from GDK_KEY_PRESS and reuse it as last resort
949 // NB: should be MT-safe as we're always called from the main thread only
954 } s_lastKeyPress
= { 0, 0 };
956 KeySym keysym
= gdk_event
->keyval
;
958 wxLogTrace(TRACE_KEYS
, _T("Key %s event: keysym = %ld"),
959 event
.GetEventType() == wxEVT_KEY_UP
? _T("release")
963 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
967 // do we have the translation or is it a plain ASCII character?
968 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
970 // we should use keysym if it is ASCII as X does some translations
971 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
972 // which we don't want here (but which we do use for OnChar())
973 if ( !wxIsAsciiKeysym(keysym
) )
975 keysym
= (KeySym
)gdk_event
->string
[0];
978 // we want to always get the same key code when the same key is
979 // pressed regardless of the state of the modifiers, i.e. on a
980 // standard US keyboard pressing '5' or '%' ('5' key with
981 // Shift) should result in the same key code in OnKeyDown():
982 // '5' (although OnChar() will get either '5' or '%').
984 // to do it we first translate keysym to keycode (== scan code)
985 // and then back but always using the lower register
986 Display
*dpy
= (Display
*)wxGetDisplay();
987 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
989 wxLogTrace(TRACE_KEYS
, _T("\t-> keycode %d"), keycode
);
991 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
993 // use the normalized, i.e. lower register, keysym if we've
995 key_code
= keysymNormalized
? keysymNormalized
: keysym
;
997 // as explained above, we want to have lower register key codes
998 // normally but for the letter keys we want to have the upper ones
1000 // NB: don't use XConvertCase() here, we want to do it for letters
1002 key_code
= toupper(key_code
);
1004 else // non ASCII key, what to do?
1006 // by default, ignore it
1009 // but if we have cached information from the last KEY_PRESS
1010 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
1013 if ( keysym
== s_lastKeyPress
.keysym
)
1015 key_code
= s_lastKeyPress
.keycode
;
1020 if ( gdk_event
->type
== GDK_KEY_PRESS
)
1022 // remember it to be reused for KEY_UP event later
1023 s_lastKeyPress
.keysym
= keysym
;
1024 s_lastKeyPress
.keycode
= key_code
;
1028 wxLogTrace(TRACE_KEYS
, _T("\t-> wxKeyCode %ld"), key_code
);
1030 // sending unknown key events doesn't really make sense
1034 // now fill all the other fields
1035 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
1037 event
.m_keyCode
= key_code
;
1044 static gint
gtk_window_key_press_callback( GtkWidget
*widget
,
1045 GdkEventKey
*gdk_event
,
1051 wxapp_install_idle_handler();
1055 if (g_blockEventsOnDrag
)
1059 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1061 bool return_after_IM
= false;
1063 if( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) == false )
1065 // Emit KEY_DOWN event
1066 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1070 // Return after IM processing as we cannot do
1071 // anything with it anyhow.
1072 return_after_IM
= true;
1075 // This is for GTK+ 1.2 only. The char event generatation for GTK+ 2.0 is done
1076 // in the "commit" handler.
1078 // 2005.02.02 modified by Hong Jen Yee (hzysoft@sina.com.tw).
1079 // In GTK+ 1.2, strings sent by IMs are also regarded as key_press events whose
1080 // keyCodes cannot be recognized by wxWidgets. These MBCS strings, however, are
1081 // composed of more than one character, which means gdk_event->length will always
1082 // greater than one. When gtk_event->length == 1, this may be an ASCII character
1083 // and can be translated by wx. However, when MBCS characters are sent by IM,
1084 // gdk_event->length will >= 2. So neither should we pass it to accelerator table,
1085 // nor should we pass it to controls. The following explanation was excerpted
1086 // from GDK documentation.
1087 // gint length : the length of string.
1088 // gchar *string : a null-terminated multi-byte string containing the composed
1089 // characters resulting from the key press. When text is being input, in a GtkEntry
1090 // for example, it is these characters which should be added to the input buffer.
1091 // When using Input Methods to support internationalized text input, the composed
1092 // characters appear here after the pre-editing has been completed.
1094 if ( (!ret
) && (gdk_event
->length
> 1) ) // If this event contains a pre-edited string from IM.
1096 // We should translate this key event into wxEVT_CHAR not wxEVT_KEY_DOWN.
1097 #if wxUSE_UNICODE // GTK+ 1.2 is not UTF-8 based.
1098 const wxWCharBuffer string
= wxConvLocal
.cMB2WC( gdk_event
->string
);
1102 const char* string
= gdk_event
->string
;
1105 // Implement OnCharHook by checking ancestor top level windows
1106 wxWindow
*parent
= win
;
1107 while (parent
&& !parent
->IsTopLevel())
1108 parent
= parent
->GetParent();
1110 for( const wxChar
* pstr
= string
; *pstr
; pstr
++ )
1113 event
.m_uniChar
= *pstr
;
1114 // Backward compatible for ISO-8859-1
1115 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1117 event
.m_keyCode
= *pstr
;
1121 event
.SetEventType( wxEVT_CHAR_HOOK
);
1122 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1126 event
.SetEventType(wxEVT_CHAR
);
1127 win
->GetEventHandler()->ProcessEvent( event
);
1133 if (return_after_IM
)
1139 wxWindowGTK
*ancestor
= win
;
1142 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1145 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1146 ret
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1149 if (ancestor
->IsTopLevel())
1151 ancestor
= ancestor
->GetParent();
1154 #endif // wxUSE_ACCEL
1156 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
1157 // will only be sent if it is not in an accelerator table.
1161 KeySym keysym
= gdk_event
->keyval
;
1162 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
1163 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
1166 if ( wxIsAsciiKeysym(keysym
) )
1169 key_code
= (unsigned char)keysym
;
1171 // gdk_event->string is actually deprecated
1172 else if ( gdk_event
->length
== 1 )
1174 key_code
= (unsigned char)gdk_event
->string
[0];
1180 wxLogTrace(TRACE_KEYS
, _T("Char event: %ld"), key_code
);
1182 event
.m_keyCode
= key_code
;
1184 // Implement OnCharHook by checking ancestor top level windows
1185 wxWindow
*parent
= win
;
1186 while (parent
&& !parent
->IsTopLevel())
1187 parent
= parent
->GetParent();
1190 event
.SetEventType( wxEVT_CHAR_HOOK
);
1191 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1196 event
.SetEventType(wxEVT_CHAR
);
1197 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1206 // win is a control: tab can be propagated up
1208 ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
)) &&
1209 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here - the control may
1210 // have this style, yet choose not to process this particular TAB in which
1211 // case TAB must still work as a navigational character
1212 // JS: enabling again to make consistent with other platforms
1213 // (with wxTE_PROCESS_TAB you have to call Navigate to get default
1214 // navigation behaviour)
1216 (! (win
->HasFlag(wxTE_PROCESS_TAB
) && win
->IsKindOf(CLASSINFO(wxTextCtrl
)) )) &&
1218 win
->GetParent() && (win
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1220 wxNavigationKeyEvent new_event
;
1221 new_event
.SetEventObject( win
->GetParent() );
1222 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
1223 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
1224 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
1225 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
1226 new_event
.SetCurrentFocus( win
);
1227 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent( new_event
);
1230 // generate wxID_CANCEL if <esc> has been pressed (typically in dialogs)
1232 (gdk_event
->keyval
== GDK_Escape
) )
1234 // however only do it if we have a Cancel button in the dialog,
1235 // otherwise the user code may get confused by the events from a
1236 // non-existing button and, worse, a wxButton might get button event
1237 // from another button which is not really expected
1238 wxWindow
*winForCancel
= win
,
1240 while ( winForCancel
)
1242 btnCancel
= winForCancel
->FindWindow(wxID_CANCEL
);
1245 // found a cancel button
1249 if ( winForCancel
->IsTopLevel() )
1251 // no need to look further
1255 // maybe our parent has a cancel button?
1256 winForCancel
= winForCancel
->GetParent();
1261 wxCommandEvent
eventClick(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
1262 eventClick
.SetEventObject(btnCancel
);
1263 ret
= btnCancel
->GetEventHandler()->ProcessEvent(eventClick
);
1269 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
1277 //-----------------------------------------------------------------------------
1278 // "key_release_event" from any window
1279 //-----------------------------------------------------------------------------
1282 static gint
gtk_window_key_release_callback( GtkWidget
*widget
,
1283 GdkEventKey
*gdk_event
,
1289 wxapp_install_idle_handler();
1294 if (g_blockEventsOnDrag
)
1297 wxKeyEvent
event( wxEVT_KEY_UP
);
1298 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1300 // unknown key pressed, ignore (the event would be useless anyhow)
1304 if ( !win
->GetEventHandler()->ProcessEvent( event
) )
1307 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_release_event" );
1312 // ============================================================================
1314 // ============================================================================
1316 // ----------------------------------------------------------------------------
1317 // mouse event processing helpers
1318 // ----------------------------------------------------------------------------
1320 // init wxMouseEvent with the info from GdkEventXXX struct
1321 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1322 wxMouseEvent
& event
,
1325 event
.SetTimestamp( gdk_event
->time
);
1326 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1327 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1328 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1329 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1330 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1331 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1332 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1333 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
1335 event
.m_linesPerAction
= 3;
1336 event
.m_wheelDelta
= 120;
1337 if (((GdkEventButton
*)gdk_event
)->button
== 4)
1338 event
.m_wheelRotation
= 120;
1339 else if (((GdkEventButton
*)gdk_event
)->button
== 5)
1340 event
.m_wheelRotation
= -120;
1343 wxPoint pt
= win
->GetClientAreaOrigin();
1344 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1345 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1347 event
.SetEventObject( win
);
1348 event
.SetId( win
->GetId() );
1349 event
.SetTimestamp( gdk_event
->time
);
1352 static void AdjustEventButtonState(wxMouseEvent
& event
)
1354 // GDK reports the old state of the button for a button press event, but
1355 // for compatibility with MSW and common sense we want m_leftDown be TRUE
1356 // for a LEFT_DOWN event, not FALSE, so we will invert
1357 // left/right/middleDown for the corresponding click events
1359 if ((event
.GetEventType() == wxEVT_LEFT_DOWN
) ||
1360 (event
.GetEventType() == wxEVT_LEFT_DCLICK
) ||
1361 (event
.GetEventType() == wxEVT_LEFT_UP
))
1363 event
.m_leftDown
= !event
.m_leftDown
;
1367 if ((event
.GetEventType() == wxEVT_MIDDLE_DOWN
) ||
1368 (event
.GetEventType() == wxEVT_MIDDLE_DCLICK
) ||
1369 (event
.GetEventType() == wxEVT_MIDDLE_UP
))
1371 event
.m_middleDown
= !event
.m_middleDown
;
1375 if ((event
.GetEventType() == wxEVT_RIGHT_DOWN
) ||
1376 (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) ||
1377 (event
.GetEventType() == wxEVT_RIGHT_UP
))
1379 event
.m_rightDown
= !event
.m_rightDown
;
1384 // find the window to send the mouse event too
1386 wxWindowGTK
*FindWindowForMouseEvent(wxWindowGTK
*win
, wxCoord
& x
, wxCoord
& y
)
1391 if (win
->m_wxwindow
)
1393 GtkPizza
*pizza
= GTK_PIZZA(win
->m_wxwindow
);
1394 xx
+= pizza
->xoffset
;
1395 yy
+= pizza
->yoffset
;
1398 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
1401 wxWindowGTK
*child
= node
->GetData();
1403 node
= node
->GetNext();
1404 if (!child
->IsShown())
1407 if (child
->IsTransparentForMouse())
1409 // wxStaticBox is transparent in the box itself
1410 int xx1
= child
->m_x
;
1411 int yy1
= child
->m_y
;
1412 int xx2
= child
->m_x
+ child
->m_width
;
1413 int yy2
= child
->m_y
+ child
->m_height
;
1416 if (((xx
>= xx1
) && (xx
<= xx1
+10) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1418 ((xx
>= xx2
-10) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1420 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy1
+10)) ||
1422 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy2
-1) && (yy
<= yy2
)))
1433 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1434 (child
->m_x
<= xx
) &&
1435 (child
->m_y
<= yy
) &&
1436 (child
->m_x
+child
->m_width
>= xx
) &&
1437 (child
->m_y
+child
->m_height
>= yy
))
1450 //-----------------------------------------------------------------------------
1451 // "button_press_event"
1452 //-----------------------------------------------------------------------------
1455 static gint
gtk_window_button_press_callback( GtkWidget
*widget
,
1456 GdkEventButton
*gdk_event
,
1462 wxapp_install_idle_handler();
1465 wxPrintf( wxT("1) OnButtonPress from ") );
1466 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1467 wxPrintf( win->GetClassInfo()->GetClassName() );
1468 wxPrintf( wxT(".\n") );
1470 if (!win
->m_hasVMT
) return FALSE
;
1471 if (g_blockEventsOnDrag
) return TRUE
;
1472 if (g_blockEventsOnScroll
) return TRUE
;
1474 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1476 if (win
->m_wxwindow
&& (g_focusWindow
!= win
) && win
->AcceptsFocus())
1478 gtk_widget_grab_focus( win
->m_wxwindow
);
1480 wxPrintf( wxT("GrabFocus from ") );
1481 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1482 wxPrintf( win->GetClassInfo()->GetClassName() );
1483 wxPrintf( wxT(".\n") );
1487 // GDK sends surplus button down events
1488 // before a double click event. We
1489 // need to filter these out.
1490 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1492 GdkEvent
*peek_event
= gdk_event_peek();
1495 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1496 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1498 gdk_event_free( peek_event
);
1503 gdk_event_free( peek_event
);
1508 wxEventType event_type
= wxEVT_NULL
;
1510 if (gdk_event
->button
== 1)
1512 // note that GDK generates triple click events which are not supported
1513 // by wxWidgets but still have to be passed to the app as otherwise
1514 // clicks would simply go missing
1515 switch (gdk_event
->type
)
1517 // we shouldn't get triple clicks at all for GTK2 because we
1518 // suppress them artificially using the code above but we still
1519 // should map them to something for GTK1 and not just ignore them
1520 // as this would lose clicks
1521 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1522 case GDK_BUTTON_PRESS
:
1523 event_type
= wxEVT_LEFT_DOWN
;
1526 case GDK_2BUTTON_PRESS
:
1527 event_type
= wxEVT_LEFT_DCLICK
;
1531 // just to silence gcc warnings
1535 else if (gdk_event
->button
== 2)
1537 switch (gdk_event
->type
)
1539 case GDK_3BUTTON_PRESS
:
1540 case GDK_BUTTON_PRESS
:
1541 event_type
= wxEVT_MIDDLE_DOWN
;
1544 case GDK_2BUTTON_PRESS
:
1545 event_type
= wxEVT_MIDDLE_DCLICK
;
1552 else if (gdk_event
->button
== 3)
1554 switch (gdk_event
->type
)
1556 case GDK_3BUTTON_PRESS
:
1557 case GDK_BUTTON_PRESS
:
1558 event_type
= wxEVT_RIGHT_DOWN
;
1561 case GDK_2BUTTON_PRESS
:
1562 event_type
= wxEVT_RIGHT_DCLICK
;
1569 else if (gdk_event
->button
== 4 || gdk_event
->button
== 5)
1571 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1573 event_type
= wxEVT_MOUSEWHEEL
;
1577 if ( event_type
== wxEVT_NULL
)
1579 // unknown mouse button or click type
1583 wxMouseEvent
event( event_type
);
1584 InitMouseEvent( win
, event
, gdk_event
);
1586 AdjustEventButtonState(event
);
1588 // wxListBox actually gets mouse events from the item, so we need to give it
1589 // a chance to correct this
1590 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1592 // find the correct window to send the event to: it may be a different one
1593 // from the one which got it at GTK+ level because some controls don't have
1594 // their own X window and thus cannot get any events.
1595 if ( !g_captureWindow
)
1596 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1598 wxGtkTimeLastClick
= gdk_event
->time
;
1600 if (event_type
== wxEVT_LEFT_DCLICK
)
1602 // GTK 1.2 crashes when intercepting double
1603 // click events from both wxSpinButton and
1605 if (GTK_IS_SPIN_BUTTON(win
->m_widget
))
1607 // Just disable this event for now.
1612 if (win
->GetEventHandler()->ProcessEvent( event
))
1614 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_press_event" );
1618 if (event_type
== wxEVT_RIGHT_DOWN
)
1620 // generate a "context menu" event: this is similar to right mouse
1621 // click under many GUIs except that it is generated differently
1622 // (right up under MSW, ctrl-click under Mac, right down here) and
1624 // (a) it's a command event and so is propagated to the parent
1625 // (b) under some ports it can be generated from kbd too
1626 // (c) it uses screen coords (because of (a))
1627 wxContextMenuEvent
evtCtx(
1630 win
->ClientToScreen(event
.GetPosition()));
1631 evtCtx
.SetEventObject(win
);
1632 return win
->GetEventHandler()->ProcessEvent(evtCtx
);
1639 //-----------------------------------------------------------------------------
1640 // "button_release_event"
1641 //-----------------------------------------------------------------------------
1644 static gint
gtk_window_button_release_callback( GtkWidget
*widget
,
1645 GdkEventButton
*gdk_event
,
1651 wxapp_install_idle_handler();
1653 if (!win
->m_hasVMT
) return FALSE
;
1654 if (g_blockEventsOnDrag
) return FALSE
;
1655 if (g_blockEventsOnScroll
) return FALSE
;
1657 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1659 wxEventType event_type
= wxEVT_NULL
;
1661 switch (gdk_event
->button
)
1664 event_type
= wxEVT_LEFT_UP
;
1668 event_type
= wxEVT_MIDDLE_UP
;
1672 event_type
= wxEVT_RIGHT_UP
;
1676 // unknwon button, don't process
1680 wxMouseEvent
event( event_type
);
1681 InitMouseEvent( win
, event
, gdk_event
);
1683 AdjustEventButtonState(event
);
1685 // same wxListBox hack as above
1686 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1688 if ( !g_captureWindow
)
1689 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1691 if (win
->GetEventHandler()->ProcessEvent( event
))
1693 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_release_event" );
1701 //-----------------------------------------------------------------------------
1702 // "motion_notify_event"
1703 //-----------------------------------------------------------------------------
1706 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
,
1707 GdkEventMotion
*gdk_event
,
1713 wxapp_install_idle_handler();
1715 if (!win
->m_hasVMT
) return FALSE
;
1716 if (g_blockEventsOnDrag
) return FALSE
;
1717 if (g_blockEventsOnScroll
) return FALSE
;
1719 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1721 if (gdk_event
->is_hint
)
1725 GdkModifierType state
;
1726 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1732 printf( "OnMotion from " );
1733 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1734 printf( win->GetClassInfo()->GetClassName() );
1738 wxMouseEvent
event( wxEVT_MOTION
);
1739 InitMouseEvent(win
, event
, gdk_event
);
1741 if ( g_captureWindow
)
1743 // synthetize a mouse enter or leave event if needed
1744 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1745 // This seems to be necessary and actually been added to
1746 // GDK itself in version 2.0.X
1749 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1750 if ( hasMouse
!= g_captureWindowHasMouse
)
1752 // the mouse changed window
1753 g_captureWindowHasMouse
= hasMouse
;
1755 wxMouseEvent
eventM(g_captureWindowHasMouse
? wxEVT_ENTER_WINDOW
1756 : wxEVT_LEAVE_WINDOW
);
1757 InitMouseEvent(win
, eventM
, gdk_event
);
1758 eventM
.SetEventObject(win
);
1759 win
->GetEventHandler()->ProcessEvent(eventM
);
1764 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1767 if (win
->GetEventHandler()->ProcessEvent( event
))
1769 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "motion_notify_event" );
1777 //-----------------------------------------------------------------------------
1779 //-----------------------------------------------------------------------------
1781 // send the wxChildFocusEvent and wxFocusEvent, common code of
1782 // gtk_window_focus_in_callback() and SetFocus()
1783 static bool DoSendFocusEvents(wxWindow
*win
)
1785 // Notify the parent keeping track of focus for the kbd navigation
1786 // purposes that we got it.
1787 wxChildFocusEvent
eventChildFocus(win
);
1788 (void)win
->GetEventHandler()->ProcessEvent(eventChildFocus
);
1790 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, win
->GetId());
1791 eventFocus
.SetEventObject(win
);
1793 return win
->GetEventHandler()->ProcessEvent(eventFocus
);
1797 static gint
gtk_window_focus_in_callback( GtkWidget
*widget
,
1798 GdkEvent
*WXUNUSED(event
),
1804 wxapp_install_idle_handler();
1807 g_focusWindow
= win
;
1809 wxLogTrace(TRACE_FOCUS
,
1810 _T("%s: focus in"), win
->GetName().c_str());
1814 gdk_im_begin(win
->m_ic
, win
->m_wxwindow
->window
);
1818 // caret needs to be informed about focus change
1819 wxCaret
*caret
= win
->GetCaret();
1822 caret
->OnSetFocus();
1824 #endif // wxUSE_CARET
1826 // does the window itself think that it has the focus?
1827 if ( !win
->m_hasFocus
)
1829 // not yet, notify it
1830 win
->m_hasFocus
= true;
1832 if ( DoSendFocusEvents(win
) )
1834 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_in_event" );
1843 //-----------------------------------------------------------------------------
1844 // "focus_out_event"
1845 //-----------------------------------------------------------------------------
1848 static gint
gtk_window_focus_out_callback( GtkWidget
*widget
, GdkEventFocus
*gdk_event
, wxWindowGTK
*win
)
1853 wxapp_install_idle_handler();
1855 wxLogTrace( TRACE_FOCUS
,
1856 _T("%s: focus out"), win
->GetName().c_str() );
1859 wxWindowGTK
*winFocus
= wxFindFocusedChild(win
);
1863 g_focusWindow
= (wxWindowGTK
*)NULL
;
1871 // caret needs to be informed about focus change
1872 wxCaret
*caret
= win
->GetCaret();
1875 caret
->OnKillFocus();
1877 #endif // wxUSE_CARET
1879 // don't send the window a kill focus event if it thinks that it doesn't
1880 // have focus already
1881 if ( win
->m_hasFocus
)
1883 win
->m_hasFocus
= false;
1885 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
1886 event
.SetEventObject( win
);
1888 // even if we did process the event in wx code, still let GTK itself
1889 // process it too as otherwise bad things happen, especially in GTK2
1890 // where the text control simply aborts the program if it doesn't get
1891 // the matching focus out event
1892 (void)win
->GetEventHandler()->ProcessEvent( event
);
1899 //-----------------------------------------------------------------------------
1900 // "enter_notify_event"
1901 //-----------------------------------------------------------------------------
1905 gint
gtk_window_enter_callback( GtkWidget
*widget
,
1906 GdkEventCrossing
*gdk_event
,
1912 wxapp_install_idle_handler();
1914 if (!win
->m_hasVMT
) return FALSE
;
1915 if (g_blockEventsOnDrag
) return FALSE
;
1917 // Event was emitted after a grab
1918 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1920 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1924 GdkModifierType state
= (GdkModifierType
)0;
1926 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1928 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
1929 InitMouseEvent(win
, event
, gdk_event
);
1930 wxPoint pt
= win
->GetClientAreaOrigin();
1931 event
.m_x
= x
+ pt
.x
;
1932 event
.m_y
= y
+ pt
.y
;
1934 if (win
->GetEventHandler()->ProcessEvent( event
))
1936 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "enter_notify_event" );
1944 //-----------------------------------------------------------------------------
1945 // "leave_notify_event"
1946 //-----------------------------------------------------------------------------
1949 static gint
gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindowGTK
*win
)
1954 wxapp_install_idle_handler();
1956 if (!win
->m_hasVMT
) return FALSE
;
1957 if (g_blockEventsOnDrag
) return FALSE
;
1959 // Event was emitted after an ungrab
1960 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1962 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1964 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
1965 event
.SetTimestamp( gdk_event
->time
);
1966 event
.SetEventObject( win
);
1970 GdkModifierType state
= (GdkModifierType
)0;
1972 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1974 event
.m_shiftDown
= (state
& GDK_SHIFT_MASK
) != 0;
1975 event
.m_controlDown
= (state
& GDK_CONTROL_MASK
) != 0;
1976 event
.m_altDown
= (state
& GDK_MOD1_MASK
) != 0;
1977 event
.m_metaDown
= (state
& GDK_MOD2_MASK
) != 0;
1978 event
.m_leftDown
= (state
& GDK_BUTTON1_MASK
) != 0;
1979 event
.m_middleDown
= (state
& GDK_BUTTON2_MASK
) != 0;
1980 event
.m_rightDown
= (state
& GDK_BUTTON3_MASK
) != 0;
1982 wxPoint pt
= win
->GetClientAreaOrigin();
1983 event
.m_x
= x
+ pt
.x
;
1984 event
.m_y
= y
+ pt
.y
;
1986 if (win
->GetEventHandler()->ProcessEvent( event
))
1988 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "leave_notify_event" );
1996 //-----------------------------------------------------------------------------
1997 // "value_changed" from m_vAdjust
1998 //-----------------------------------------------------------------------------
2001 static void gtk_window_vscroll_callback( GtkAdjustment
*adjust
,
2008 wxapp_install_idle_handler();
2010 if (g_blockEventsOnDrag
) return;
2012 if (!win
->m_hasVMT
) return;
2014 float diff
= adjust
->value
- win
->m_oldVerticalPos
;
2015 if (fabs(diff
) < 0.2) return;
2017 win
->m_oldVerticalPos
= adjust
->value
;
2019 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2020 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->vscrollbar
));
2022 int value
= (int)(adjust
->value
+0.5);
2024 wxScrollWinEvent
event( command
, value
, wxVERTICAL
);
2025 event
.SetEventObject( win
);
2026 win
->GetEventHandler()->ProcessEvent( event
);
2030 //-----------------------------------------------------------------------------
2031 // "value_changed" from m_hAdjust
2032 //-----------------------------------------------------------------------------
2035 static void gtk_window_hscroll_callback( GtkAdjustment
*adjust
,
2042 wxapp_install_idle_handler();
2044 if (g_blockEventsOnDrag
) return;
2045 if (!win
->m_hasVMT
) return;
2047 float diff
= adjust
->value
- win
->m_oldHorizontalPos
;
2048 if (fabs(diff
) < 0.2) return;
2050 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2051 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->hscrollbar
));
2053 win
->m_oldHorizontalPos
= adjust
->value
;
2055 int value
= (int)(adjust
->value
+0.5);
2057 wxScrollWinEvent
event( command
, value
, wxHORIZONTAL
);
2058 event
.SetEventObject( win
);
2059 win
->GetEventHandler()->ProcessEvent( event
);
2063 //-----------------------------------------------------------------------------
2064 // "button_press_event" from scrollbar
2065 //-----------------------------------------------------------------------------
2068 static gint
gtk_scrollbar_button_press_callback( GtkRange
*widget
,
2069 GdkEventButton
*gdk_event
,
2075 wxapp_install_idle_handler();
2078 g_blockEventsOnScroll
= true;
2080 // FIXME: there is no 'slider' field in GTK+ 2.0 any more
2081 win
->m_isScrolling
= (gdk_event
->window
== widget
->slider
);
2087 //-----------------------------------------------------------------------------
2088 // "button_release_event" from scrollbar
2089 //-----------------------------------------------------------------------------
2092 static gint
gtk_scrollbar_button_release_callback( GtkRange
*widget
,
2093 GdkEventButton
*WXUNUSED(gdk_event
),
2098 // don't test here as we can release the mouse while being over
2099 // a different window than the slider
2101 // if (gdk_event->window != widget->slider) return FALSE;
2103 g_blockEventsOnScroll
= false;
2105 if (win
->m_isScrolling
)
2107 wxEventType command
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2111 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2112 if (widget
== GTK_RANGE(scrolledWindow
->hscrollbar
))
2114 value
= (int)(win
->m_hAdjust
->value
+0.5);
2117 if (widget
== GTK_RANGE(scrolledWindow
->vscrollbar
))
2119 value
= (int)(win
->m_vAdjust
->value
+0.5);
2123 wxScrollWinEvent
event( command
, value
, dir
);
2124 event
.SetEventObject( win
);
2125 win
->GetEventHandler()->ProcessEvent( event
);
2128 win
->m_isScrolling
= false;
2134 // ----------------------------------------------------------------------------
2135 // this wxWindowBase function is implemented here (in platform-specific file)
2136 // because it is static and so couldn't be made virtual
2137 // ----------------------------------------------------------------------------
2139 wxWindow
*wxWindowBase::DoFindFocus()
2141 // the cast is necessary when we compile in wxUniversal mode
2142 return (wxWindow
*)g_focusWindow
;
2145 //-----------------------------------------------------------------------------
2146 // "realize" from m_widget
2147 //-----------------------------------------------------------------------------
2149 /* We cannot set colours and fonts before the widget has
2150 been realized, so we do this directly after realization. */
2154 gtk_window_realized_callback( GtkWidget
*m_widget
, wxWindow
*win
)
2159 wxapp_install_idle_handler();
2161 wxWindowCreateEvent
event( win
);
2162 event
.SetEventObject( win
);
2163 win
->GetEventHandler()->ProcessEvent( event
);
2169 //-----------------------------------------------------------------------------
2171 //-----------------------------------------------------------------------------
2175 void gtk_window_size_callback( GtkWidget
*WXUNUSED(widget
),
2176 GtkAllocation
*WXUNUSED(alloc
),
2180 wxapp_install_idle_handler();
2182 if (!win
->m_hasScrolling
) return;
2184 int client_width
= 0;
2185 int client_height
= 0;
2186 win
->GetClientSize( &client_width
, &client_height
);
2187 if ((client_width
== win
->m_oldClientWidth
) && (client_height
== win
->m_oldClientHeight
))
2190 win
->m_oldClientWidth
= client_width
;
2191 win
->m_oldClientHeight
= client_height
;
2193 if (!win
->m_nativeSizeEvent
)
2195 wxSizeEvent
event( win
->GetSize(), win
->GetId() );
2196 event
.SetEventObject( win
);
2197 win
->GetEventHandler()->ProcessEvent( event
);
2204 #define WXUNUSED_UNLESS_XIM(param) param
2206 #define WXUNUSED_UNLESS_XIM(param) WXUNUSED(param)
2209 /* Resize XIM window */
2213 void gtk_wxwindow_size_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2214 GtkAllocation
* WXUNUSED_UNLESS_XIM(alloc
),
2215 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2218 wxapp_install_idle_handler();
2224 if (gdk_ic_get_style (win
->m_ic
) & GDK_IM_PREEDIT_POSITION
)
2228 gdk_window_get_size (widget
->window
, &width
, &height
);
2229 win
->m_icattr
->preedit_area
.width
= width
;
2230 win
->m_icattr
->preedit_area
.height
= height
;
2231 gdk_ic_set_attr (win
->m_ic
, win
->m_icattr
, GDK_IC_PREEDIT_AREA
);
2237 //-----------------------------------------------------------------------------
2238 // "realize" from m_wxwindow
2239 //-----------------------------------------------------------------------------
2241 /* Initialize XIM support */
2245 gtk_wxwindow_realized_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2246 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2249 wxapp_install_idle_handler();
2252 if (win
->m_ic
) return FALSE
;
2253 if (!widget
) return FALSE
;
2254 if (!gdk_im_ready()) return FALSE
;
2256 win
->m_icattr
= gdk_ic_attr_new();
2257 if (!win
->m_icattr
) return FALSE
;
2261 GdkColormap
*colormap
;
2262 GdkICAttr
*attr
= win
->m_icattr
;
2263 unsigned attrmask
= GDK_IC_ALL_REQ
;
2265 GdkIMStyle supported_style
= (GdkIMStyle
)
2266 (GDK_IM_PREEDIT_NONE
|
2267 GDK_IM_PREEDIT_NOTHING
|
2268 GDK_IM_PREEDIT_POSITION
|
2269 GDK_IM_STATUS_NONE
|
2270 GDK_IM_STATUS_NOTHING
);
2272 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2273 supported_style
= (GdkIMStyle
)(supported_style
& ~GDK_IM_PREEDIT_POSITION
);
2275 attr
->style
= style
= gdk_im_decide_style (supported_style
);
2276 attr
->client_window
= widget
->window
;
2278 if ((colormap
= gtk_widget_get_colormap (widget
)) !=
2279 gtk_widget_get_default_colormap ())
2281 attrmask
|= GDK_IC_PREEDIT_COLORMAP
;
2282 attr
->preedit_colormap
= colormap
;
2285 attrmask
|= GDK_IC_PREEDIT_FOREGROUND
;
2286 attrmask
|= GDK_IC_PREEDIT_BACKGROUND
;
2287 attr
->preedit_foreground
= widget
->style
->fg
[GTK_STATE_NORMAL
];
2288 attr
->preedit_background
= widget
->style
->base
[GTK_STATE_NORMAL
];
2290 switch (style
& GDK_IM_PREEDIT_MASK
)
2292 case GDK_IM_PREEDIT_POSITION
:
2293 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2295 g_warning ("over-the-spot style requires fontset");
2299 gdk_window_get_size (widget
->window
, &width
, &height
);
2301 attrmask
|= GDK_IC_PREEDIT_POSITION_REQ
;
2302 attr
->spot_location
.x
= 0;
2303 attr
->spot_location
.y
= height
;
2304 attr
->preedit_area
.x
= 0;
2305 attr
->preedit_area
.y
= 0;
2306 attr
->preedit_area
.width
= width
;
2307 attr
->preedit_area
.height
= height
;
2308 attr
->preedit_fontset
= widget
->style
->font
;
2313 win
->m_ic
= gdk_ic_new (attr
, (GdkICAttributesType
)attrmask
);
2315 if (win
->m_ic
== NULL
)
2316 g_warning ("Can't create input context.");
2319 mask
= gdk_window_get_events (widget
->window
);
2320 mask
= (GdkEventMask
)(mask
| gdk_ic_get_events (win
->m_ic
));
2321 gdk_window_set_events (widget
->window
, mask
);
2323 if (GTK_WIDGET_HAS_FOCUS(widget
))
2324 gdk_im_begin (win
->m_ic
, widget
->window
);
2332 //-----------------------------------------------------------------------------
2333 // InsertChild for wxWindowGTK.
2334 //-----------------------------------------------------------------------------
2336 /* Callback for wxWindowGTK. This very strange beast has to be used because
2337 * C++ has no virtual methods in a constructor. We have to emulate a
2338 * virtual function here as wxNotebook requires a different way to insert
2339 * a child in it. I had opted for creating a wxNotebookPage window class
2340 * which would have made this superfluous (such in the MDI window system),
2341 * but no-one was listening to me... */
2343 static void wxInsertChildInWindow( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2345 /* the window might have been scrolled already, do we
2346 have to adapt the position */
2347 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
2348 child
->m_x
+= pizza
->xoffset
;
2349 child
->m_y
+= pizza
->yoffset
;
2351 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
2352 GTK_WIDGET(child
->m_widget
),
2359 //-----------------------------------------------------------------------------
2361 //-----------------------------------------------------------------------------
2363 wxWindow
*wxGetActiveWindow()
2365 return wxWindow::FindFocus();
2369 wxMouseState
wxGetMouseState()
2375 GdkModifierType mask
;
2377 gdk_window_get_pointer(NULL
, &x
, &y
, &mask
);
2381 ms
.SetLeftDown(mask
& GDK_BUTTON1_MASK
);
2382 ms
.SetMiddleDown(mask
& GDK_BUTTON2_MASK
);
2383 ms
.SetRightDown(mask
& GDK_BUTTON3_MASK
);
2385 ms
.SetControlDown(mask
& GDK_CONTROL_MASK
);
2386 ms
.SetShiftDown(mask
& GDK_SHIFT_MASK
);
2387 ms
.SetAltDown(mask
& GDK_MOD1_MASK
);
2388 ms
.SetMetaDown(mask
& GDK_MOD2_MASK
);
2393 //-----------------------------------------------------------------------------
2395 //-----------------------------------------------------------------------------
2397 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2399 #ifdef __WXUNIVERSAL__
2400 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2402 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
2403 #endif // __WXUNIVERSAL__/__WXGTK__
2405 void wxWindowGTK::Init()
2408 m_widget
= (GtkWidget
*) NULL
;
2409 m_wxwindow
= (GtkWidget
*) NULL
;
2410 m_focusWidget
= (GtkWidget
*) NULL
;
2420 m_needParent
= true;
2421 m_isBeingDeleted
= false;
2424 m_nativeSizeEvent
= false;
2426 m_hasScrolling
= false;
2427 m_isScrolling
= false;
2429 m_hAdjust
= (GtkAdjustment
*) NULL
;
2430 m_vAdjust
= (GtkAdjustment
*) NULL
;
2431 m_oldHorizontalPos
=
2432 m_oldVerticalPos
= 0.0;
2434 m_oldClientHeight
= 0;
2438 m_insertCallback
= (wxInsertChildFunction
) NULL
;
2440 m_acceptsFocus
= false;
2443 m_clipPaintRegion
= false;
2445 m_needsStyleChange
= false;
2447 m_cursor
= *wxSTANDARD_CURSOR
;
2450 m_ic
= (GdkIC
*) NULL
;
2451 m_icattr
= (GdkICAttr
*) NULL
;
2455 wxWindowGTK::wxWindowGTK()
2460 wxWindowGTK::wxWindowGTK( wxWindow
*parent
,
2465 const wxString
&name
)
2469 Create( parent
, id
, pos
, size
, style
, name
);
2472 bool wxWindowGTK::Create( wxWindow
*parent
,
2477 const wxString
&name
)
2479 if (!PreCreation( parent
, pos
, size
) ||
2480 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2482 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2486 m_insertCallback
= wxInsertChildInWindow
;
2488 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
2489 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
2491 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2493 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2494 scroll_class
->scrollbar_spacing
= 0;
2496 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2498 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
2499 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
2501 m_wxwindow
= gtk_pizza_new();
2503 #ifndef __WXUNIVERSAL__
2504 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
2506 if (HasFlag(wxRAISED_BORDER
))
2508 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
2510 else if (HasFlag(wxSUNKEN_BORDER
))
2512 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
2514 else if (HasFlag(wxSIMPLE_BORDER
))
2516 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
2520 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
2522 #endif // __WXUNIVERSAL__
2524 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2526 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
2527 m_acceptsFocus
= true;
2529 // I _really_ don't want scrollbars in the beginning
2530 m_vAdjust
->lower
= 0.0;
2531 m_vAdjust
->upper
= 1.0;
2532 m_vAdjust
->value
= 0.0;
2533 m_vAdjust
->step_increment
= 1.0;
2534 m_vAdjust
->page_increment
= 1.0;
2535 m_vAdjust
->page_size
= 5.0;
2536 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
2537 m_hAdjust
->lower
= 0.0;
2538 m_hAdjust
->upper
= 1.0;
2539 m_hAdjust
->value
= 0.0;
2540 m_hAdjust
->step_increment
= 1.0;
2541 m_hAdjust
->page_increment
= 1.0;
2542 m_hAdjust
->page_size
= 5.0;
2543 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
2545 // these handlers block mouse events to any window during scrolling such as
2546 // motion events and prevent GTK and wxWidgets from fighting over where the
2549 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_press_event",
2550 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2552 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_press_event",
2553 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2555 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_release_event",
2556 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2558 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_release_event",
2559 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2561 // these handlers get notified when screen updates are required either when
2562 // scrolling or when the window size (and therefore scrollbar configuration)
2565 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
2566 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
2567 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
2568 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
2570 gtk_widget_show( m_wxwindow
);
2573 m_parent
->DoAddChild( this );
2575 m_focusWidget
= m_wxwindow
;
2582 wxWindowGTK::~wxWindowGTK()
2586 if (g_focusWindow
== this)
2587 g_focusWindow
= NULL
;
2589 if ( g_delayedFocus
== this )
2590 g_delayedFocus
= NULL
;
2592 m_isBeingDeleted
= true;
2595 // destroy children before destroying this window itself
2598 // unhook focus handlers to prevent stray events being
2599 // propagated to this (soon to be) dead object
2600 if (m_focusWidget
!= NULL
)
2602 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2603 (GtkSignalFunc
) gtk_window_focus_in_callback
, (gpointer
) this );
2604 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2605 (GtkSignalFunc
) gtk_window_focus_out_callback
, (gpointer
) this );
2613 gdk_ic_destroy (m_ic
);
2615 gdk_ic_attr_destroy (m_icattr
);
2620 gtk_widget_destroy( m_wxwindow
);
2621 m_wxwindow
= (GtkWidget
*) NULL
;
2626 gtk_widget_destroy( m_widget
);
2627 m_widget
= (GtkWidget
*) NULL
;
2631 bool wxWindowGTK::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2633 wxCHECK_MSG( !m_needParent
|| parent
, false, wxT("Need complete parent.") );
2635 // Use either the given size, or the default if -1 is given.
2636 // See wxWindowBase for these functions.
2637 m_width
= WidthDefault(size
.x
) ;
2638 m_height
= HeightDefault(size
.y
);
2646 void wxWindowGTK::PostCreation()
2648 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2654 // these get reported to wxWidgets -> wxPaintEvent
2656 gtk_pizza_set_external( GTK_PIZZA(m_wxwindow
), TRUE
);
2658 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
2659 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
2661 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
2662 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
2664 if (!HasFlag(wxFULL_REPAINT_ON_RESIZE
))
2666 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "event",
2667 GTK_SIGNAL_FUNC(gtk_window_event_event_callback
), (gpointer
)this );
2671 // these are called when the "sunken" or "raised" borders are drawn
2672 gtk_signal_connect( GTK_OBJECT(m_widget
), "expose_event",
2673 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
2675 gtk_signal_connect( GTK_OBJECT(m_widget
), "draw",
2676 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
2681 if (!GTK_IS_WINDOW(m_widget
))
2683 if (m_focusWidget
== NULL
)
2684 m_focusWidget
= m_widget
;
2686 gtk_signal_connect( GTK_OBJECT(m_focusWidget
), "focus_in_event",
2687 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
2689 gtk_signal_connect_after( GTK_OBJECT(m_focusWidget
), "focus_out_event",
2690 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
2693 // connect to the various key and mouse handlers
2695 GtkWidget
*connect_widget
= GetConnectWidget();
2697 ConnectWidget( connect_widget
);
2699 /* We cannot set colours, fonts and cursors before the widget has
2700 been realized, so we do this directly after realization */
2701 gtk_signal_connect( GTK_OBJECT(connect_widget
), "realize",
2702 GTK_SIGNAL_FUNC(gtk_window_realized_callback
), (gpointer
) this );
2706 // Catch native resize events
2707 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
2708 GTK_SIGNAL_FUNC(gtk_window_size_callback
), (gpointer
)this );
2710 // Initialize XIM support
2711 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "realize",
2712 GTK_SIGNAL_FUNC(gtk_wxwindow_realized_callback
), (gpointer
) this );
2714 // And resize XIM window
2715 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
2716 GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback
), (gpointer
)this );
2719 if (GTK_IS_COMBO(m_widget
))
2721 GtkCombo
*gcombo
= GTK_COMBO(m_widget
);
2723 gtk_signal_connect( GTK_OBJECT(gcombo
->entry
), "size_request",
2724 GTK_SIGNAL_FUNC(wxgtk_combo_size_request_callback
),
2729 // This is needed if we want to add our windows into native
2730 // GTK controls, such as the toolbar. With this callback, the
2731 // toolbar gets to know the correct size (the one set by the
2732 // programmer). Sadly, it misbehaves for wxComboBox.
2733 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_request",
2734 GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback
),
2738 InheritAttributes();
2742 // unless the window was created initially hidden (i.e. Hide() had been
2743 // called before Create()), we should show it at GTK+ level as well
2745 gtk_widget_show( m_widget
);
2748 void wxWindowGTK::ConnectWidget( GtkWidget
*widget
)
2750 gtk_signal_connect( GTK_OBJECT(widget
), "key_press_event",
2751 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
2753 gtk_signal_connect( GTK_OBJECT(widget
), "key_release_event",
2754 GTK_SIGNAL_FUNC(gtk_window_key_release_callback
), (gpointer
)this );
2756 gtk_signal_connect( GTK_OBJECT(widget
), "button_press_event",
2757 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
2759 gtk_signal_connect( GTK_OBJECT(widget
), "button_release_event",
2760 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
2762 gtk_signal_connect( GTK_OBJECT(widget
), "motion_notify_event",
2763 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
2765 gtk_signal_connect( GTK_OBJECT(widget
), "enter_notify_event",
2766 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
2768 gtk_signal_connect( GTK_OBJECT(widget
), "leave_notify_event",
2769 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
2772 bool wxWindowGTK::Destroy()
2774 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2778 return wxWindowBase::Destroy();
2781 void wxWindowGTK::DoMoveWindow(int x
, int y
, int width
, int height
)
2783 gtk_pizza_set_size( GTK_PIZZA(m_parent
->m_wxwindow
), m_widget
, x
, y
, width
, height
);
2786 void wxWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
2788 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2789 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
2792 printf( "DoSetSize: name %s, x,y,w,h: %d,%d,%d,%d \n", GetName().c_str(), x,y,width,height );
2795 if (m_resizing
) return; /* I don't like recursions */
2798 int currentX
, currentY
;
2799 GetPosition(¤tX
, ¤tY
);
2800 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2802 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2804 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2806 if (m_parent
->m_wxwindow
== NULL
) /* i.e. wxNotebook */
2808 /* don't set the size for children of wxNotebook, just take the values. */
2816 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
2817 if ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0)
2819 if (x
!= -1) m_x
= x
+ pizza
->xoffset
;
2820 if (y
!= -1) m_y
= y
+ pizza
->yoffset
;
2824 m_x
= x
+ pizza
->xoffset
;
2825 m_y
= y
+ pizza
->yoffset
;
2828 // calculate the best size if we should auto size the window
2829 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
2830 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
2832 const wxSize sizeBest
= GetBestSize();
2833 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
2835 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
2836 height
= sizeBest
.y
;
2844 int minWidth
= GetMinWidth(),
2845 minHeight
= GetMinHeight(),
2846 maxWidth
= GetMaxWidth(),
2847 maxHeight
= GetMaxHeight();
2849 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
2850 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
2851 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
2852 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
2854 int left_border
= 0;
2855 int right_border
= 0;
2857 int bottom_border
= 0;
2859 /* the default button has a border around it */
2860 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
2868 DoMoveWindow( m_x
-top_border
,
2870 m_width
+left_border
+right_border
,
2871 m_height
+top_border
+bottom_border
);
2876 /* Sometimes the client area changes size without the
2877 whole windows's size changing, but if the whole
2878 windows's size doesn't change, no wxSizeEvent will
2879 normally be sent. Here we add an extra test if
2880 the client test has been changed and this will
2882 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
2886 wxPrintf( "OnSize sent from " );
2887 if (GetClassInfo() && GetClassInfo()->GetClassName())
2888 wxPrintf( GetClassInfo()->GetClassName() );
2889 wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height );
2892 if (!m_nativeSizeEvent
)
2894 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
2895 event
.SetEventObject( this );
2896 GetEventHandler()->ProcessEvent( event
);
2902 void wxWindowGTK::OnInternalIdle()
2904 // Update style if the window was not yet realized
2905 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
2906 if (m_needsStyleChange
)
2908 SetBackgroundStyle(GetBackgroundStyle());
2909 m_needsStyleChange
= false;
2912 // Update invalidated regions.
2915 wxCursor cursor
= m_cursor
;
2916 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
2920 /* I now set the cursor anew in every OnInternalIdle call
2921 as setting the cursor in a parent window also effects the
2922 windows above so that checking for the current cursor is
2927 GdkWindow
*window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
2929 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2931 if (!g_globalCursor
.Ok())
2932 cursor
= *wxSTANDARD_CURSOR
;
2934 window
= m_widget
->window
;
2935 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2936 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2942 GdkWindow
*window
= m_widget
->window
;
2943 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2944 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2949 if (wxUpdateUIEvent::CanUpdate(this))
2950 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2953 void wxWindowGTK::DoGetSize( int *width
, int *height
) const
2955 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2957 if (width
) (*width
) = m_width
;
2958 if (height
) (*height
) = m_height
;
2961 void wxWindowGTK::DoSetClientSize( int width
, int height
)
2963 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2967 SetSize( width
, height
);
2974 #ifndef __WXUNIVERSAL__
2975 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
2977 /* when using GTK 1.2 we set the shadow border size to 2 */
2981 if (HasFlag(wxSIMPLE_BORDER
))
2983 /* when using GTK 1.2 we set the simple border size to 1 */
2987 #endif // __WXUNIVERSAL__
2991 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
2993 GtkRequisition vscroll_req
;
2994 vscroll_req
.width
= 2;
2995 vscroll_req
.height
= 2;
2996 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
2997 (scroll_window
->vscrollbar
, &vscroll_req
);
2999 GtkRequisition hscroll_req
;
3000 hscroll_req
.width
= 2;
3001 hscroll_req
.height
= 2;
3002 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
3003 (scroll_window
->hscrollbar
, &hscroll_req
);
3005 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3007 if (scroll_window
->vscrollbar_visible
)
3009 dw
+= vscroll_req
.width
;
3010 dw
+= scroll_class
->scrollbar_spacing
;
3013 if (scroll_window
->hscrollbar_visible
)
3015 dh
+= hscroll_req
.height
;
3016 dh
+= scroll_class
->scrollbar_spacing
;
3020 SetSize( width
+dw
, height
+dh
);
3024 void wxWindowGTK::DoGetClientSize( int *width
, int *height
) const
3026 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3030 if (width
) (*width
) = m_width
;
3031 if (height
) (*height
) = m_height
;
3038 #ifndef __WXUNIVERSAL__
3039 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
3041 /* when using GTK 1.2 we set the shadow border size to 2 */
3045 if (HasFlag(wxSIMPLE_BORDER
))
3047 /* when using GTK 1.2 we set the simple border size to 1 */
3051 #endif // __WXUNIVERSAL__
3055 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
3057 GtkRequisition vscroll_req
;
3058 vscroll_req
.width
= 2;
3059 vscroll_req
.height
= 2;
3060 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
3061 (scroll_window
->vscrollbar
, &vscroll_req
);
3063 GtkRequisition hscroll_req
;
3064 hscroll_req
.width
= 2;
3065 hscroll_req
.height
= 2;
3066 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
3067 (scroll_window
->hscrollbar
, &hscroll_req
);
3069 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3071 if (scroll_window
->vscrollbar_visible
)
3073 dw
+= vscroll_req
.width
;
3074 dw
+= scroll_class
->scrollbar_spacing
;
3077 if (scroll_window
->hscrollbar_visible
)
3079 dh
+= hscroll_req
.height
;
3080 dh
+= scroll_class
->scrollbar_spacing
;
3084 if (width
) (*width
) = m_width
- dw
;
3085 if (height
) (*height
) = m_height
- dh
;
3089 printf( "GetClientSize, name %s ", GetName().c_str() );
3090 if (width) printf( " width = %d", (*width) );
3091 if (height) printf( " height = %d", (*height) );
3096 void wxWindowGTK::DoGetPosition( int *x
, int *y
) const
3098 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3102 if (m_parent
&& m_parent
->m_wxwindow
)
3104 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
3105 dx
= pizza
->xoffset
;
3106 dy
= pizza
->yoffset
;
3109 if (x
) (*x
) = m_x
- dx
;
3110 if (y
) (*y
) = m_y
- dy
;
3113 void wxWindowGTK::DoClientToScreen( int *x
, int *y
) const
3115 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3117 if (!m_widget
->window
) return;
3119 GdkWindow
*source
= (GdkWindow
*) NULL
;
3121 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3123 source
= m_widget
->window
;
3127 gdk_window_get_origin( source
, &org_x
, &org_y
);
3131 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3133 org_x
+= m_widget
->allocation
.x
;
3134 org_y
+= m_widget
->allocation
.y
;
3142 void wxWindowGTK::DoScreenToClient( int *x
, int *y
) const
3144 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3146 if (!m_widget
->window
) return;
3148 GdkWindow
*source
= (GdkWindow
*) NULL
;
3150 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3152 source
= m_widget
->window
;
3156 gdk_window_get_origin( source
, &org_x
, &org_y
);
3160 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3162 org_x
+= m_widget
->allocation
.x
;
3163 org_y
+= m_widget
->allocation
.y
;
3171 bool wxWindowGTK::Show( bool show
)
3173 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3175 if (!wxWindowBase::Show(show
))
3182 gtk_widget_show( m_widget
);
3184 gtk_widget_hide( m_widget
);
3186 wxShowEvent
eventShow(GetId(), show
);
3187 eventShow
.SetEventObject(this);
3189 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 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3239 return gfont
->ascent
+ gfont
->descent
;
3242 int wxWindowGTK::GetCharWidth() const
3244 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
3246 wxFont font
= GetFont();
3247 wxCHECK_MSG( font
.Ok(), 8, wxT("invalid font") );
3249 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3251 return gdk_string_width( gfont
, "g" );
3254 void wxWindowGTK::GetTextExtent( const wxString
& string
,
3258 int *externalLeading
,
3259 const wxFont
*theFont
) const
3261 wxFont fontToUse
= theFont
? *theFont
: GetFont();
3263 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
3272 GdkFont
*font
= fontToUse
.GetInternalFont( 1.0 );
3273 if (x
) (*x
) = gdk_string_width( font
, wxGTK_CONV( string
) );
3274 if (y
) (*y
) = font
->ascent
+ font
->descent
;
3275 if (descent
) (*descent
) = font
->descent
;
3276 if (externalLeading
) (*externalLeading
) = 0; // ??
3279 void wxWindowGTK::SetFocus()
3281 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3284 // don't do anything if we already have focus
3290 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow
))
3292 gtk_widget_grab_focus (m_wxwindow
);
3297 if (GTK_WIDGET_CAN_FOCUS(m_widget
) && !GTK_WIDGET_HAS_FOCUS (m_widget
) )
3300 if (!GTK_WIDGET_REALIZED(m_widget
))
3302 // we can't set the focus to the widget now so we remember that
3303 // it should be focused and will do it later, during the idle
3304 // time, as soon as we can
3305 wxLogTrace(TRACE_FOCUS
,
3306 _T("Delaying setting focus to %s(%s)"),
3307 GetClassInfo()->GetClassName(), GetLabel().c_str());
3309 g_delayedFocus
= this;
3313 wxLogTrace(TRACE_FOCUS
,
3314 _T("Setting focus to %s(%s)"),
3315 GetClassInfo()->GetClassName(), GetLabel().c_str());
3317 gtk_widget_grab_focus (m_widget
);
3321 if (GTK_IS_CONTAINER(m_widget
))
3323 gtk_container_focus( GTK_CONTAINER(m_widget
), GTK_DIR_TAB_FORWARD
);
3327 wxLogTrace(TRACE_FOCUS
,
3328 _T("Can't set focus to %s(%s)"),
3329 GetClassInfo()->GetClassName(), GetLabel().c_str());
3334 bool wxWindowGTK::AcceptsFocus() const
3336 return m_acceptsFocus
&& wxWindowBase::AcceptsFocus();
3339 bool wxWindowGTK::Reparent( wxWindowBase
*newParentBase
)
3341 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3343 wxWindowGTK
*oldParent
= m_parent
,
3344 *newParent
= (wxWindowGTK
*)newParentBase
;
3346 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3348 if ( !wxWindowBase::Reparent(newParent
) )
3351 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3353 /* prevent GTK from deleting the widget arbitrarily */
3354 gtk_widget_ref( m_widget
);
3358 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3361 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3365 /* insert GTK representation */
3366 (*(newParent
->m_insertCallback
))(newParent
, this);
3369 /* reverse: prevent GTK from deleting the widget arbitrarily */
3370 gtk_widget_unref( m_widget
);
3375 void wxWindowGTK::DoAddChild(wxWindowGTK
*child
)
3377 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3379 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3381 wxASSERT_MSG( (m_insertCallback
!= NULL
), wxT("invalid child insertion function") );
3386 /* insert GTK representation */
3387 (*m_insertCallback
)(this, child
);
3390 void wxWindowGTK::Raise()
3392 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3394 if (m_wxwindow
&& m_wxwindow
->window
)
3396 gdk_window_raise( m_wxwindow
->window
);
3398 else if (m_widget
->window
)
3400 gdk_window_raise( m_widget
->window
);
3404 void wxWindowGTK::Lower()
3406 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3408 if (m_wxwindow
&& m_wxwindow
->window
)
3410 gdk_window_lower( m_wxwindow
->window
);
3412 else if (m_widget
->window
)
3414 gdk_window_lower( m_widget
->window
);
3418 bool wxWindowGTK::SetCursor( const wxCursor
&cursor
)
3420 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3422 if (cursor
== m_cursor
)
3426 wxapp_install_idle_handler();
3428 if (cursor
== wxNullCursor
)
3429 return wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
);
3431 return wxWindowBase::SetCursor( cursor
);
3434 void wxWindowGTK::WarpPointer( int x
, int y
)
3436 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3438 // We provide this function ourselves as it is
3439 // missing in GDK (top of this file).
3441 GdkWindow
*window
= (GdkWindow
*) NULL
;
3443 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3445 window
= GetConnectWidget()->window
;
3448 gdk_window_warp_pointer( window
, x
, y
);
3452 void wxWindowGTK::Refresh( bool eraseBackground
, const wxRect
*rect
)
3456 if (!m_widget
->window
)
3460 wxapp_install_idle_handler();
3463 if (m_wxwindow
&& rect
)
3465 myRect
.SetSize(wxSize( m_wxwindow
->allocation
.width
,
3466 m_wxwindow
->allocation
.height
));
3467 if ( myRect
.Intersect(*rect
).IsEmpty() )
3469 // nothing to do, rectangle is empty
3476 // schedule the area for later updating in GtkUpdate()
3477 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
3481 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3485 m_clearRegion
.Clear();
3486 m_clearRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
3494 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3498 GdkRectangle gdk_rect
;
3499 gdk_rect
.x
= rect
->x
;
3500 gdk_rect
.y
= rect
->y
;
3501 gdk_rect
.width
= rect
->width
;
3502 gdk_rect
.height
= rect
->height
;
3503 gtk_widget_draw( m_widget
, &gdk_rect
);
3510 m_updateRegion
.Clear();
3511 m_updateRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
3515 gtk_widget_draw( m_widget
, (GdkRectangle
*) NULL
);
3520 void wxWindowGTK::Update()
3524 // when we call Update() we really want to update the window immediately on
3525 // screen, even if it means flushing the entire queue and hence slowing down
3526 // everything -- but it should still be done, it's just that Update() should
3527 // be called very rarely
3531 void wxWindowGTK::GtkUpdate()
3533 if (!m_updateRegion
.IsEmpty())
3534 GtkSendPaintEvents();
3536 // for consistency with other platforms (and also because it's convenient
3537 // to be able to update an entire TLW by calling Update() only once), we
3538 // should also update all our children here
3539 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3541 node
= node
->GetNext() )
3543 node
->GetData()->GtkUpdate();
3547 void wxWindowGTK::GtkSendPaintEvents()
3551 m_clearRegion
.Clear();
3552 m_updateRegion
.Clear();
3556 // Clip to paint region in wxClientDC
3557 m_clipPaintRegion
= true;
3559 // widget to draw on
3560 GtkPizza
*pizza
= GTK_PIZZA (m_wxwindow
);
3562 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM
))
3564 // find ancestor from which to steal background
3565 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3567 parent
= (wxWindow
*)this;
3569 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
3571 wxRegionIterator
upd( m_updateRegion
);
3575 rect
.x
= upd
.GetX();
3576 rect
.y
= upd
.GetY();
3577 rect
.width
= upd
.GetWidth();
3578 rect
.height
= upd
.GetHeight();
3580 gtk_paint_flat_box( parent
->m_widget
->style
,
3582 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
3595 // if (!m_clearRegion.IsEmpty()) // Always send an erase event under GTK 1.2
3597 wxWindowDC
dc( (wxWindow
*)this );
3598 if (m_clearRegion
.IsEmpty())
3599 dc
.SetClippingRegion( m_updateRegion
);
3601 dc
.SetClippingRegion( m_clearRegion
);
3603 wxEraseEvent
erase_event( GetId(), &dc
);
3604 erase_event
.SetEventObject( this );
3606 if (!GetEventHandler()->ProcessEvent(erase_event
) && GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3610 g_eraseGC
= gdk_gc_new( pizza
->bin_window
);
3611 gdk_gc_set_fill( g_eraseGC
, GDK_SOLID
);
3613 gdk_gc_set_foreground( g_eraseGC
, GetBackgroundColour().GetColor() );
3615 wxRegionIterator
upd( m_clearRegion
);
3618 gdk_draw_rectangle( pizza
->bin_window
, g_eraseGC
, 1,
3619 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
3623 m_clearRegion
.Clear();
3626 wxNcPaintEvent
nc_paint_event( GetId() );
3627 nc_paint_event
.SetEventObject( this );
3628 GetEventHandler()->ProcessEvent( nc_paint_event
);
3630 wxPaintEvent
paint_event( GetId() );
3631 paint_event
.SetEventObject( this );
3632 GetEventHandler()->ProcessEvent( paint_event
);
3634 m_clipPaintRegion
= false;
3636 #if !defined(__WXUNIVERSAL__)
3637 // The following code will result in all window-less widgets
3638 // being redrawn because the wxWidgets class is allowed to
3639 // paint over the window-less widgets.
3641 GList
*children
= pizza
->children
;
3644 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
3645 children
= children
->next
;
3647 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
3648 GTK_WIDGET_DRAWABLE (child
->widget
))
3650 // Get intersection of widget area and update region
3651 wxRegion
region( m_updateRegion
);
3653 GdkEventExpose gdk_event
;
3654 gdk_event
.type
= GDK_EXPOSE
;
3655 gdk_event
.window
= pizza
->bin_window
;
3656 gdk_event
.count
= 0;
3657 gdk_event
.send_event
= TRUE
;
3659 wxRegionIterator
upd( m_updateRegion
);
3663 rect
.x
= upd
.GetX();
3664 rect
.y
= upd
.GetY();
3665 rect
.width
= upd
.GetWidth();
3666 rect
.height
= upd
.GetHeight();
3668 if (gtk_widget_intersect (child
->widget
, &rect
, &gdk_event
.area
))
3670 gtk_widget_event (child
->widget
, (GdkEvent
*) &gdk_event
);
3677 #endif // native GTK 1
3679 m_updateRegion
.Clear();
3682 void wxWindowGTK::ClearBackground()
3684 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3686 if (m_wxwindow
&& m_wxwindow
->window
)
3688 m_clearRegion
.Clear();
3689 wxSize
size( GetClientSize() );
3690 m_clearRegion
.Union( 0,0,size
.x
,size
.y
);
3692 // Better do this in idle?
3698 void wxWindowGTK::DoSetToolTip( wxToolTip
*tip
)
3700 wxWindowBase::DoSetToolTip(tip
);
3703 m_tooltip
->Apply( (wxWindow
*)this );
3706 void wxWindowGTK::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
3708 wxString
tmp( tip
);
3709 gtk_tooltips_set_tip( tips
, GetConnectWidget(), wxGTK_CONV(tmp
), (gchar
*) NULL
);
3711 #endif // wxUSE_TOOLTIPS
3713 bool wxWindowGTK::SetBackgroundColour( const wxColour
&colour
)
3715 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3717 if (!wxWindowBase::SetBackgroundColour(colour
))
3722 // We need the pixel value e.g. for background clearing.
3723 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3726 // apply style change (forceStyle=true so that new style is applied
3727 // even if the bg colour changed from valid to wxNullColour)
3728 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3729 ApplyWidgetStyle(true);
3734 bool wxWindowGTK::SetForegroundColour( const wxColour
&colour
)
3736 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3738 if (!wxWindowBase::SetForegroundColour(colour
))
3745 // We need the pixel value e.g. for background clearing.
3746 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3749 // apply style change (forceStyle=true so that new style is applied
3750 // even if the bg colour changed from valid to wxNullColour):
3751 ApplyWidgetStyle(true);
3756 GtkRcStyle
*wxWindowGTK::CreateWidgetStyle(bool forceStyle
)
3758 // do we need to apply any changes at all?
3761 !m_foregroundColour
.Ok() && !m_backgroundColour
.Ok() )
3766 GtkRcStyle
*style
= gtk_rc_style_new();
3770 wxString xfontname
= m_font
.GetNativeFontInfo()->GetXFontName();
3771 style
->fontset_name
= g_strdup(xfontname
.c_str());
3774 if ( m_foregroundColour
.Ok() )
3776 GdkColor
*fg
= m_foregroundColour
.GetColor();
3778 style
->fg
[GTK_STATE_NORMAL
] = *fg
;
3779 style
->color_flags
[GTK_STATE_NORMAL
] = GTK_RC_FG
;
3781 style
->fg
[GTK_STATE_PRELIGHT
] = *fg
;
3782 style
->color_flags
[GTK_STATE_PRELIGHT
] = GTK_RC_FG
;
3784 style
->fg
[GTK_STATE_ACTIVE
] = *fg
;
3785 style
->color_flags
[GTK_STATE_ACTIVE
] = GTK_RC_FG
;
3788 if ( m_backgroundColour
.Ok() )
3790 GdkColor
*bg
= m_backgroundColour
.GetColor();
3792 style
->bg
[GTK_STATE_NORMAL
] = *bg
;
3793 style
->base
[GTK_STATE_NORMAL
] = *bg
;
3794 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)
3795 (style
->color_flags
[GTK_STATE_NORMAL
] | GTK_RC_BG
| GTK_RC_BASE
);
3797 style
->bg
[GTK_STATE_PRELIGHT
] = *bg
;
3798 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
3799 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)
3800 (style
->color_flags
[GTK_STATE_PRELIGHT
] | GTK_RC_BG
| GTK_RC_BASE
);
3802 style
->bg
[GTK_STATE_ACTIVE
] = *bg
;
3803 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
3804 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)
3805 (style
->color_flags
[GTK_STATE_ACTIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3807 style
->bg
[GTK_STATE_INSENSITIVE
] = *bg
;
3808 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
3809 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)
3810 (style
->color_flags
[GTK_STATE_INSENSITIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3816 void wxWindowGTK::ApplyWidgetStyle(bool forceStyle
)
3818 GtkRcStyle
*style
= CreateWidgetStyle(forceStyle
);
3821 DoApplyWidgetStyle(style
);
3822 gtk_rc_style_unref(style
);
3825 // Style change may affect GTK+'s size calculation:
3826 InvalidateBestSize();
3829 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle
*style
)
3832 gtk_widget_modify_style(m_wxwindow
, style
);
3834 gtk_widget_modify_style(m_widget
, style
);
3837 bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style
)
3839 wxWindowBase::SetBackgroundStyle(style
);
3841 if (style
== wxBG_STYLE_CUSTOM
)
3843 GdkWindow
*window
= (GdkWindow
*) NULL
;
3845 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3847 window
= GetConnectWidget()->window
;
3851 // Make sure GDK/X11 doesn't refresh the window
3853 gdk_window_set_back_pixmap( window
, None
, False
);
3855 Display
* display
= GDK_WINDOW_DISPLAY(window
);
3858 m_needsStyleChange
= false;
3861 // Do in OnIdle, because the window is not yet available
3862 m_needsStyleChange
= true;
3864 // Don't apply widget style, or we get a grey background
3868 // apply style change (forceStyle=true so that new style is applied
3869 // even if the bg colour changed from valid to wxNullColour):
3870 ApplyWidgetStyle(true);
3875 #if wxUSE_DRAG_AND_DROP
3877 void wxWindowGTK::SetDropTarget( wxDropTarget
*dropTarget
)
3879 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3881 GtkWidget
*dnd_widget
= GetConnectWidget();
3883 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
3885 if (m_dropTarget
) delete m_dropTarget
;
3886 m_dropTarget
= dropTarget
;
3888 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
3891 #endif // wxUSE_DRAG_AND_DROP
3893 GtkWidget
* wxWindowGTK::GetConnectWidget()
3895 GtkWidget
*connect_widget
= m_widget
;
3896 if (m_wxwindow
) connect_widget
= m_wxwindow
;
3898 return connect_widget
;
3901 bool wxWindowGTK::IsOwnGtkWindow( GdkWindow
*window
)
3904 return (window
== GTK_PIZZA(m_wxwindow
)->bin_window
);
3906 return (window
== m_widget
->window
);
3909 bool wxWindowGTK::SetFont( const wxFont
&font
)
3911 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3913 if (!wxWindowBase::SetFont(font
))
3916 // apply style change (forceStyle=true so that new style is applied
3917 // even if the font changed from valid to wxNullFont):
3918 ApplyWidgetStyle(true);
3923 void wxWindowGTK::DoCaptureMouse()
3925 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3927 GdkWindow
*window
= (GdkWindow
*) NULL
;
3929 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3931 window
= GetConnectWidget()->window
;
3933 wxCHECK_RET( window
, _T("CaptureMouse() failed") );
3935 const wxCursor
* cursor
= &m_cursor
;
3937 cursor
= wxSTANDARD_CURSOR
;
3939 gdk_pointer_grab( window
, FALSE
,
3941 (GDK_BUTTON_PRESS_MASK
|
3942 GDK_BUTTON_RELEASE_MASK
|
3943 GDK_POINTER_MOTION_HINT_MASK
|
3944 GDK_POINTER_MOTION_MASK
),
3946 cursor
->GetCursor(),
3947 (guint32
)GDK_CURRENT_TIME
);
3948 g_captureWindow
= this;
3949 g_captureWindowHasMouse
= true;
3952 void wxWindowGTK::DoReleaseMouse()
3954 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3956 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
3958 g_captureWindow
= (wxWindowGTK
*) NULL
;
3960 GdkWindow
*window
= (GdkWindow
*) NULL
;
3962 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3964 window
= GetConnectWidget()->window
;
3969 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
3973 wxWindow
*wxWindowBase::GetCapture()
3975 return (wxWindow
*)g_captureWindow
;
3978 bool wxWindowGTK::IsRetained() const
3983 void wxWindowGTK::SetScrollbar( int orient
, int pos
, int thumbVisible
,
3984 int range
, bool refresh
)
3986 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3988 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
3990 m_hasScrolling
= true;
3992 if (orient
== wxHORIZONTAL
)
3994 float fpos
= (float)pos
;
3995 float frange
= (float)range
;
3996 float fthumb
= (float)thumbVisible
;
3997 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
3998 if (fpos
< 0.0) fpos
= 0.0;
4000 if ((fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
4001 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
4003 SetScrollPos( orient
, pos
, refresh
);
4007 m_oldHorizontalPos
= fpos
;
4009 m_hAdjust
->lower
= 0.0;
4010 m_hAdjust
->upper
= frange
;
4011 m_hAdjust
->value
= fpos
;
4012 m_hAdjust
->step_increment
= 1.0;
4013 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4014 m_hAdjust
->page_size
= fthumb
;
4018 float fpos
= (float)pos
;
4019 float frange
= (float)range
;
4020 float fthumb
= (float)thumbVisible
;
4021 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
4022 if (fpos
< 0.0) fpos
= 0.0;
4024 if ((fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
4025 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
4027 SetScrollPos( orient
, pos
, refresh
);
4031 m_oldVerticalPos
= fpos
;
4033 m_vAdjust
->lower
= 0.0;
4034 m_vAdjust
->upper
= frange
;
4035 m_vAdjust
->value
= fpos
;
4036 m_vAdjust
->step_increment
= 1.0;
4037 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4038 m_vAdjust
->page_size
= fthumb
;
4041 if (orient
== wxHORIZONTAL
)
4042 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
4044 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
4047 void wxWindowGTK::GtkUpdateScrollbar(int orient
)
4049 GtkAdjustment
*adj
= orient
== wxHORIZONTAL
? m_hAdjust
: m_vAdjust
;
4050 GtkSignalFunc fn
= orient
== wxHORIZONTAL
4051 ? (GtkSignalFunc
)gtk_window_hscroll_callback
4052 : (GtkSignalFunc
)gtk_window_vscroll_callback
;
4054 gtk_signal_disconnect_by_func(GTK_OBJECT(adj
), fn
, (gpointer
)this);
4055 gtk_signal_emit_by_name(GTK_OBJECT(adj
), "value_changed");
4056 gtk_signal_connect(GTK_OBJECT(adj
), "value_changed", fn
, (gpointer
)this);
4059 void wxWindowGTK::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
4061 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4062 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4064 GtkAdjustment
*adj
= orient
== wxHORIZONTAL
? m_hAdjust
: m_vAdjust
;
4066 float fpos
= (float)pos
;
4067 if (fpos
> adj
->upper
- adj
->page_size
)
4068 fpos
= adj
->upper
- adj
->page_size
;
4071 *(orient
== wxHORIZONTAL
? &m_oldHorizontalPos
: &m_oldVerticalPos
) = fpos
;
4073 if (fabs(fpos
-adj
->value
) < 0.2)
4077 if ( m_wxwindow
->window
)
4082 int wxWindowGTK::GetScrollThumb( int orient
) const
4084 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4086 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4088 if (orient
== wxHORIZONTAL
)
4089 return (int)(m_hAdjust
->page_size
+0.5);
4091 return (int)(m_vAdjust
->page_size
+0.5);
4094 int wxWindowGTK::GetScrollPos( int orient
) const
4096 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4098 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4100 if (orient
== wxHORIZONTAL
)
4101 return (int)(m_hAdjust
->value
+0.5);
4103 return (int)(m_vAdjust
->value
+0.5);
4106 int wxWindowGTK::GetScrollRange( int orient
) const
4108 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4110 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4112 if (orient
== wxHORIZONTAL
)
4113 return (int)(m_hAdjust
->upper
+0.5);
4115 return (int)(m_vAdjust
->upper
+0.5);
4118 void wxWindowGTK::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4120 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4122 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4124 // No scrolling requested.
4125 if ((dx
== 0) && (dy
== 0)) return;
4127 if (!m_updateRegion
.IsEmpty())
4129 m_updateRegion
.Offset( dx
, dy
);
4133 GetClientSize( &cw
, &ch
);
4134 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
4137 if (!m_clearRegion
.IsEmpty())
4139 m_clearRegion
.Offset( dx
, dy
);
4143 GetClientSize( &cw
, &ch
);
4144 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
4147 m_clipPaintRegion
= true;
4149 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow
), -dx
, -dy
);
4151 m_clipPaintRegion
= false;
4154 void wxWindowGTK::SetWindowStyleFlag( long style
)
4156 // Updates the internal variable. NB: Now m_windowStyle bits carry the _new_ style values already
4157 wxWindowBase::SetWindowStyleFlag(style
);
4160 // Find the wxWindow at the current mouse position, also returning the mouse
4162 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4164 pt
= wxGetMousePosition();
4165 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4169 // Get the current mouse position.
4170 wxPoint
wxGetMousePosition()
4172 /* This crashes when used within wxHelpContext,
4173 so we have to use the X-specific implementation below.
4175 GdkModifierType *mask;
4176 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4178 return wxPoint(x, y);
4182 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4184 Display
*display
= windowAtPtr
? GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4185 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4186 Window rootReturn
, childReturn
;
4187 int rootX
, rootY
, winX
, winY
;
4188 unsigned int maskReturn
;
4190 XQueryPointer (display
,
4194 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4195 return wxPoint(rootX
, rootY
);
4199 // Needed for implementing e.g. combobox on wxGTK within a modal dialog.
4200 void wxAddGrab(wxWindow
* window
)
4202 gtk_grab_add( (GtkWidget
*) window
->GetHandle() );
4205 void wxRemoveGrab(wxWindow
* window
)
4207 gtk_grab_remove( (GtkWidget
*) window
->GetHandle() );
4210 // ----------------------------------------------------------------------------
4212 // ----------------------------------------------------------------------------
4214 class wxWinModule
: public wxModule
4221 DECLARE_DYNAMIC_CLASS(wxWinModule
)
4224 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
4226 bool wxWinModule::OnInit()
4228 // g_eraseGC = gdk_gc_new( GDK_ROOT_PARENT() );
4229 // gdk_gc_set_fill( g_eraseGC, GDK_SOLID );
4234 void wxWinModule::OnExit()
4237 gdk_gc_unref( g_eraseGC
);