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/dialog.h"
28 #include "wx/settings.h"
29 #include "wx/msgdlg.h"
30 #include "wx/textctrl.h"
31 #include "wx/combobox.h"
32 #include "wx/layout.h"
33 #include "wx/statusbr.h"
35 #include "wx/module.h"
38 #if wxUSE_DRAG_AND_DROP
43 #include "wx/tooltip.h"
50 #include "wx/fontutil.h"
53 #include "wx/thread.h"
58 #include "wx/gtk1/private.h"
59 #include <gdk/gdkprivate.h>
60 #include <gdk/gdkkeysyms.h>
64 #include <gtk/gtkprivate.h>
66 #include "wx/gtk1/win_gtk.h"
68 //-----------------------------------------------------------------------------
69 // documentation on internals
70 //-----------------------------------------------------------------------------
73 I have been asked several times about writing some documentation about
74 the GTK port of wxWidgets, especially its internal structures. Obviously,
75 you cannot understand wxGTK without knowing a little about the GTK, but
76 some more information about what the wxWindow, which is the base class
77 for all other window classes, does seems required as well.
81 What does wxWindow do? It contains the common interface for the following
82 jobs of its descendants:
84 1) Define the rudimentary behaviour common to all window classes, such as
85 resizing, intercepting user input (so as to make it possible to use these
86 events for special purposes in a derived class), window names etc.
88 2) Provide the possibility to contain and manage children, if the derived
89 class is allowed to contain children, which holds true for those window
90 classes which do not display a native GTK widget. To name them, these
91 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
92 work classes are a special case and are handled a bit differently from
93 the rest. The same holds true for the wxNotebook class.
95 3) Provide the possibility to draw into a client area of a window. This,
96 too, only holds true for classes that do not display a native GTK widget
99 4) Provide the entire mechanism for scrolling widgets. This actual inter-
100 face for this is usually in wxScrolledWindow, but the GTK implementation
103 5) A multitude of helper or extra methods for special purposes, such as
104 Drag'n'Drop, managing validators etc.
106 6) Display a border (sunken, raised, simple or none).
108 Normally one might expect, that one wxWidgets window would always correspond
109 to one GTK widget. Under GTK, there is no such allround widget that has all
110 the functionality. Moreover, the GTK defines a client area as a different
111 widget from the actual widget you are handling. Last but not least some
112 special classes (e.g. wxFrame) handle different categories of widgets and
113 still have the possibility to draw something in the client area.
114 It was therefore required to write a special purpose GTK widget, that would
115 represent a client area in the sense of wxWidgets capable to do the jobs
116 2), 3) and 4). I have written this class and it resides in win_gtk.c of
119 All windows must have a widget, with which they interact with other under-
120 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
121 the wxWindow class has a member variable called m_widget which holds a
122 pointer to this widget. When the window class represents a GTK native widget,
123 this is (in most cases) the only GTK widget the class manages. E.g. the
124 wxStaticText class handles only a GtkLabel widget a pointer to which you
125 can find in m_widget (defined in wxWindow)
127 When the class has a client area for drawing into and for containing children
128 it has to handle the client area widget (of the type GtkPizza, defined in
129 win_gtk.c), but there could be any number of widgets, handled by a class
130 The common rule for all windows is only, that the widget that interacts with
131 the rest of GTK must be referenced in m_widget and all other widgets must be
132 children of this widget on the GTK level. The top-most widget, which also
133 represents the client area, must be in the m_wxwindow field and must be of
136 As I said, the window classes that display a GTK native widget only have
137 one widget, so in the case of e.g. the wxButton class m_widget holds a
138 pointer to a GtkButton widget. But windows with client areas (for drawing
139 and children) have a m_widget field that is a pointer to a GtkScrolled-
140 Window and a m_wxwindow field that is pointer to a GtkPizza and this
141 one is (in the GTK sense) a child of the GtkScrolledWindow.
143 If the m_wxwindow field is set, then all input to this widget is inter-
144 cepted and sent to the wxWidgets class. If not, all input to the widget
145 that gets pointed to by m_widget gets intercepted and sent to the class.
149 The design of scrolling in wxWidgets is markedly different from that offered
150 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
151 clicking on a scrollbar belonging to scrolled window will inevitably move
152 the window. In wxWidgets, the scrollbar will only emit an event, send this
153 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
154 which actually moves the window and its subchildren. Note that GtkPizza
155 memorizes how much it has been scrolled but that wxWidgets forgets this
156 so that the two coordinates systems have to be kept in synch. This is done
157 in various places using the pizza->xoffset and pizza->yoffset values.
161 Singularily the most broken code in GTK is the code that is supposed to
162 inform subwindows (child windows) about new positions. Very often, duplicate
163 events are sent without changes in size or position, equally often no
164 events are sent at all (All this is due to a bug in the GtkContainer code
165 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
166 GTK's own system and it simply waits for size events for toplevel windows
167 and then iterates down the respective size events to all window. This has
168 the disadvantage that windows might get size events before the GTK widget
169 actually has the reported size. This doesn't normally pose any problem, but
170 the OpenGL drawing routines rely on correct behaviour. Therefore, I have
171 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
172 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
173 window that is used for OpenGL output really has that size (as reported by
178 If someone at some point of time feels the immense desire to have a look at,
179 change or attempt to optimise the Refresh() logic, this person will need an
180 intimate understanding of what "draw" and "expose" events are and what
181 they are used for, in particular when used in connection with GTK's
182 own windowless widgets. Beware.
186 Cursors, too, have been a constant source of pleasure. The main difficulty
187 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
188 for the parent. To prevent this from doing too much harm, I use idle time
189 to set the cursor over and over again, starting from the toplevel windows
190 and ending with the youngest generation (speaking of parent and child windows).
191 Also don't forget that cursors (like much else) are connected to GdkWindows,
192 not GtkWidgets and that the "window" field of a GtkWidget might very well
193 point to the GdkWindow of the parent widget (-> "window-less widget") and
194 that the two obviously have very different meanings.
198 //-----------------------------------------------------------------------------
200 //-----------------------------------------------------------------------------
202 extern bool g_blockEventsOnDrag
;
203 extern bool g_blockEventsOnScroll
;
204 extern wxCursor g_globalCursor
;
206 static GdkGC
*g_eraseGC
= NULL
;
208 // mouse capture state: the window which has it and if the mouse is currently
210 static wxWindowGTK
*g_captureWindow
= NULL
;
211 static bool g_captureWindowHasMouse
= false;
213 wxWindowGTK
*g_focusWindow
= NULL
;
215 // the last window which had the focus - this is normally never NULL (except
216 // if we never had focus at all) as even when g_focusWindow is NULL it still
217 // keeps its previous value
218 wxWindowGTK
*g_focusWindowLast
= NULL
;
220 // If a window get the focus set but has not been realized
221 // yet, defer setting the focus to idle time.
222 wxWindowGTK
*g_delayedFocus
= NULL
;
224 // hack: we need something to pass to gtk_menu_popup, so we store the time of
225 // the last click here (extern: used from gtk/menu.cpp)
226 guint32 wxGtkTimeLastClick
= 0;
228 // global variables because GTK+ DnD want to have the
229 // mouse event that caused it
230 GdkEvent
*g_lastMouseEvent
= NULL
;
231 int g_lastButtonNumber
= 0;
233 extern bool g_mainThreadLocked
;
235 //-----------------------------------------------------------------------------
237 //-----------------------------------------------------------------------------
240 # define DEBUG_MAIN_THREAD \
241 wxASSERT_MSG( !g_mainThreadLocked || !wxThread::IsMain(), \
242 "GUI reentrancy detected" );
244 # define DEBUG_MAIN_THREAD
247 // the trace mask used for the focus debugging messages
248 #define TRACE_FOCUS wxT("focus")
250 //-----------------------------------------------------------------------------
251 // missing gdk functions
252 //-----------------------------------------------------------------------------
255 gdk_window_warp_pointer (GdkWindow
*window
,
259 GdkWindowPrivate
*priv
;
262 window
= GDK_ROOT_PARENT();
264 priv
= (GdkWindowPrivate
*) window
;
266 if (!priv
->destroyed
)
268 XWarpPointer (priv
->xdisplay
,
269 None
, /* not source window -> move from anywhere */
270 priv
->xwindow
, /* dest window */
271 0, 0, 0, 0, /* not source window -> move from anywhere */
276 //-----------------------------------------------------------------------------
278 //-----------------------------------------------------------------------------
280 extern void wxapp_install_idle_handler();
281 extern bool g_isIdle
;
283 //-----------------------------------------------------------------------------
284 // local code (see below)
285 //-----------------------------------------------------------------------------
287 // returns the child of win which currently has focus or NULL if not found
289 // Note: can't be static, needed by textctrl.cpp.
290 wxWindow
*wxFindFocusedChild(wxWindowGTK
*win
)
292 wxWindow
*winFocus
= wxWindowGTK::FindFocus();
296 if ( winFocus
== win
)
297 return (wxWindow
*)win
;
299 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
301 node
= node
->GetNext() )
303 wxWindow
*child
= wxFindFocusedChild(node
->GetData());
311 static void draw_frame( GtkWidget
*widget
, wxWindowGTK
*win
)
313 // wxUniversal widgets draw the borders and scrollbars themselves
314 #ifndef __WXUNIVERSAL__
321 if (win
->m_hasScrolling
)
323 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(widget
);
325 GtkRequisition vscroll_req
;
326 vscroll_req
.width
= 2;
327 vscroll_req
.height
= 2;
328 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
329 (scroll_window
->vscrollbar
, &vscroll_req
);
331 GtkRequisition hscroll_req
;
332 hscroll_req
.width
= 2;
333 hscroll_req
.height
= 2;
334 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
335 (scroll_window
->hscrollbar
, &hscroll_req
);
337 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(widget
) );
339 if (scroll_window
->vscrollbar_visible
)
341 dw
+= vscroll_req
.width
;
342 dw
+= scroll_class
->scrollbar_spacing
;
345 if (scroll_window
->hscrollbar_visible
)
347 dh
+= hscroll_req
.height
;
348 dh
+= scroll_class
->scrollbar_spacing
;
354 if (GTK_WIDGET_NO_WINDOW (widget
))
356 dx
+= widget
->allocation
.x
;
357 dy
+= widget
->allocation
.y
;
360 if (win
->HasFlag(wxRAISED_BORDER
))
362 gtk_draw_shadow( widget
->style
,
367 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
371 if (win
->HasFlag(wxSUNKEN_BORDER
) || win
->HasFlag(wxBORDER_THEME
))
373 gtk_draw_shadow( widget
->style
,
378 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
382 if (win
->HasFlag(wxSIMPLE_BORDER
))
385 gc
= gdk_gc_new( widget
->window
);
386 gdk_gc_set_foreground( gc
, &widget
->style
->black
);
387 gdk_draw_rectangle( widget
->window
, gc
, FALSE
,
389 widget
->allocation
.width
-dw
-1, widget
->allocation
.height
-dh
-1 );
393 #endif // __WXUNIVERSAL__
396 //-----------------------------------------------------------------------------
397 // "expose_event" of m_widget
398 //-----------------------------------------------------------------------------
401 static gint
gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxWindowGTK
*win
)
403 if (gdk_event
->count
> 0) return FALSE
;
405 draw_frame( widget
, win
);
411 //-----------------------------------------------------------------------------
412 // "draw" of m_widget
413 //-----------------------------------------------------------------------------
416 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxWindowGTK
*win
)
418 draw_frame( widget
, win
);
422 //-----------------------------------------------------------------------------
423 // "size_request" of m_widget
424 //-----------------------------------------------------------------------------
426 // make it extern because wxStaticText needs to disconnect this one
428 void wxgtk_window_size_request_callback(GtkWidget
*WXUNUSED(widget
),
429 GtkRequisition
*requisition
,
433 win
->GetSize( &w
, &h
);
439 requisition
->height
= h
;
440 requisition
->width
= w
;
446 void wxgtk_combo_size_request_callback(GtkWidget
*WXUNUSED(widget
),
447 GtkRequisition
*requisition
,
450 // This callback is actually hooked into the text entry
451 // of the combo box, not the GtkHBox.
454 win
->GetSize( &w
, &h
);
460 GtkCombo
*gcombo
= GTK_COMBO(win
->m_widget
);
462 GtkRequisition entry_req
;
464 entry_req
.height
= 2;
465 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo
->button
) )->size_request
)
466 (gcombo
->button
, &entry_req
);
468 requisition
->width
= w
- entry_req
.width
;
469 requisition
->height
= entry_req
.height
;
473 //-----------------------------------------------------------------------------
474 // "expose_event" of m_wxwindow
475 //-----------------------------------------------------------------------------
478 static int gtk_window_expose_callback( GtkWidget
*WXUNUSED(widget
),
479 GdkEventExpose
*gdk_event
,
485 wxapp_install_idle_handler();
487 // This gets called immediately after an expose event
488 // under GTK 1.2 so we collect the calls and wait for
489 // the idle handler to pick things up.
491 win
->GetUpdateRegion().Union( gdk_event
->area
.x
,
493 gdk_event
->area
.width
,
494 gdk_event
->area
.height
);
495 win
->m_clearRegion
.Union( gdk_event
->area
.x
,
497 gdk_event
->area
.width
,
498 gdk_event
->area
.height
);
500 // Actual redrawing takes place in idle time.
507 //-----------------------------------------------------------------------------
508 // "event" of m_wxwindow
509 //-----------------------------------------------------------------------------
511 // GTK thinks it is clever and filters out a certain amount of "unneeded"
512 // expose events. We need them, of course, so we override the main event
513 // procedure in GtkWidget by giving our own handler for all system events.
514 // There, we look for expose events ourselves whereas all other events are
519 gint
gtk_window_event_event_callback( GtkWidget
*widget
,
520 GdkEventExpose
*event
,
523 if (event
->type
== GDK_EXPOSE
)
525 gint ret
= gtk_window_expose_callback( widget
, event
, win
);
533 //-----------------------------------------------------------------------------
534 // "draw" of m_wxwindow
535 //-----------------------------------------------------------------------------
537 // This callback is a complete replacement of the gtk_pizza_draw() function,
538 // which is disabled.
541 static void gtk_window_draw_callback( GtkWidget
*widget
,
548 wxapp_install_idle_handler();
550 // if there are any children we must refresh everything
553 if ( !win
->HasFlag(wxFULL_REPAINT_ON_RESIZE
) &&
554 win
->GetChildren().IsEmpty() )
562 wxPrintf( wxT("OnDraw from ") );
563 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
564 wxPrintf( win
->GetClassInfo()->GetClassName() );
565 wxPrintf( wxT(" %d %d %d %d\n"), (int)rect
->x
,
572 #ifndef __WXUNIVERSAL__
573 GtkPizza
*pizza
= GTK_PIZZA (widget
);
575 if (win
->GetThemeEnabled() && win
->GetBackgroundStyle() == wxBG_STYLE_SYSTEM
)
577 wxWindow
*parent
= win
->GetParent();
578 while (parent
&& !parent
->IsTopLevel())
579 parent
= parent
->GetParent();
583 gtk_paint_flat_box (parent
->m_widget
->style
,
594 win
->m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
595 win
->GetUpdateRegion().Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
597 // Update immediately, not in idle time.
600 #ifndef __WXUNIVERSAL__
601 // Redraw child widgets
602 GList
*children
= pizza
->children
;
605 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
606 children
= children
->next
;
608 GdkRectangle child_area
;
609 if (gtk_widget_intersect (child
->widget
, rect
, &child_area
))
611 gtk_widget_draw (child
->widget
, &child_area
/* NULL*/ );
618 //-----------------------------------------------------------------------------
619 // "key_press_event" from any window
620 //-----------------------------------------------------------------------------
622 // set WXTRACE to this to see the key event codes on the console
623 #define TRACE_KEYS wxT("keyevent")
625 // translates an X key symbol to WXK_XXX value
627 // if isChar is true it means that the value returned will be used for EVT_CHAR
628 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
629 // for example, while if it is false it means that the value is going to be
630 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
632 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
638 // Shift, Control and Alt don't generate the CHAR events at all
641 key_code
= isChar
? 0 : WXK_SHIFT
;
645 key_code
= isChar
? 0 : WXK_CONTROL
;
653 key_code
= isChar
? 0 : WXK_ALT
;
656 // neither do the toggle modifies
657 case GDK_Scroll_Lock
:
658 key_code
= isChar
? 0 : WXK_SCROLL
;
662 key_code
= isChar
? 0 : WXK_CAPITAL
;
666 key_code
= isChar
? 0 : WXK_NUMLOCK
;
670 // various other special keys
683 case GDK_ISO_Left_Tab
:
690 key_code
= WXK_RETURN
;
694 key_code
= WXK_CLEAR
;
698 key_code
= WXK_PAUSE
;
702 key_code
= WXK_SELECT
;
706 key_code
= WXK_PRINT
;
710 key_code
= WXK_EXECUTE
;
714 key_code
= WXK_ESCAPE
;
717 // cursor and other extended keyboard keys
719 key_code
= WXK_DELETE
;
735 key_code
= WXK_RIGHT
;
742 case GDK_Prior
: // == GDK_Page_Up
743 key_code
= WXK_PAGEUP
;
746 case GDK_Next
: // == GDK_Page_Down
747 key_code
= WXK_PAGEDOWN
;
759 key_code
= WXK_INSERT
;
774 key_code
= (isChar
? '0' : WXK_NUMPAD0
) + keysym
- GDK_KP_0
;
778 key_code
= isChar
? ' ' : WXK_NUMPAD_SPACE
;
782 key_code
= isChar
? WXK_TAB
: WXK_NUMPAD_TAB
;
786 key_code
= isChar
? WXK_RETURN
: WXK_NUMPAD_ENTER
;
790 key_code
= isChar
? WXK_F1
: WXK_NUMPAD_F1
;
794 key_code
= isChar
? WXK_F2
: WXK_NUMPAD_F2
;
798 key_code
= isChar
? WXK_F3
: WXK_NUMPAD_F3
;
802 key_code
= isChar
? WXK_F4
: WXK_NUMPAD_F4
;
806 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_HOME
;
810 key_code
= isChar
? WXK_LEFT
: WXK_NUMPAD_LEFT
;
814 key_code
= isChar
? WXK_UP
: WXK_NUMPAD_UP
;
818 key_code
= isChar
? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
822 key_code
= isChar
? WXK_DOWN
: WXK_NUMPAD_DOWN
;
825 case GDK_KP_Prior
: // == GDK_KP_Page_Up
826 key_code
= isChar
? WXK_PAGEUP
: WXK_NUMPAD_PAGEUP
;
829 case GDK_KP_Next
: // == GDK_KP_Page_Down
830 key_code
= isChar
? WXK_PAGEDOWN
: WXK_NUMPAD_PAGEDOWN
;
834 key_code
= isChar
? WXK_END
: WXK_NUMPAD_END
;
838 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_BEGIN
;
842 key_code
= isChar
? WXK_INSERT
: WXK_NUMPAD_INSERT
;
846 key_code
= isChar
? WXK_DELETE
: WXK_NUMPAD_DELETE
;
850 key_code
= isChar
? '=' : WXK_NUMPAD_EQUAL
;
853 case GDK_KP_Multiply
:
854 key_code
= isChar
? '*' : WXK_NUMPAD_MULTIPLY
;
858 key_code
= isChar
? '+' : WXK_NUMPAD_ADD
;
861 case GDK_KP_Separator
:
862 // FIXME: what is this?
863 key_code
= isChar
? '.' : WXK_NUMPAD_SEPARATOR
;
866 case GDK_KP_Subtract
:
867 key_code
= isChar
? '-' : WXK_NUMPAD_SUBTRACT
;
871 key_code
= isChar
? '.' : WXK_NUMPAD_DECIMAL
;
875 key_code
= isChar
? '/' : WXK_NUMPAD_DIVIDE
;
892 key_code
= WXK_F1
+ keysym
- GDK_F1
;
902 static inline bool wxIsAsciiKeysym(KeySym ks
)
907 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
909 GdkEventKey
*gdk_event
)
913 GdkModifierType state
;
914 if (gdk_event
->window
)
915 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
917 event
.SetTimestamp( gdk_event
->time
);
918 event
.SetId(win
->GetId());
919 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
920 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
921 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
922 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
) != 0;
923 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
924 event
.m_rawFlags
= 0;
927 // this is not gtk1.x
928 event
.m_uniChar
= gdk_keyval_to_unicode(gdk_event
->keyval
);
931 wxGetMousePosition( &x
, &y
);
932 win
->ScreenToClient( &x
, &y
);
935 event
.SetEventObject( win
);
940 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
942 GdkEventKey
*gdk_event
)
944 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
945 // but only event->keyval which is quite useless to us, so remember
946 // the last character from GDK_KEY_PRESS and reuse it as last resort
948 // NB: should be MT-safe as we're always called from the main thread only
953 } s_lastKeyPress
= { 0, 0 };
955 KeySym keysym
= gdk_event
->keyval
;
957 wxLogTrace(TRACE_KEYS
, wxT("Key %s event: keysym = %ld"),
958 event
.GetEventType() == wxEVT_KEY_UP
? wxT("release")
962 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
966 // do we have the translation or is it a plain ASCII character?
967 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
969 // we should use keysym if it is ASCII as X does some translations
970 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
971 // which we don't want here (but which we do use for OnChar())
972 if ( !wxIsAsciiKeysym(keysym
) )
974 keysym
= (KeySym
)gdk_event
->string
[0];
977 // we want to always get the same key code when the same key is
978 // pressed regardless of the state of the modifiers, i.e. on a
979 // standard US keyboard pressing '5' or '%' ('5' key with
980 // Shift) should result in the same key code in OnKeyDown():
981 // '5' (although OnChar() will get either '5' or '%').
983 // to do it we first translate keysym to keycode (== scan code)
984 // and then back but always using the lower register
985 Display
*dpy
= (Display
*)wxGetDisplay();
986 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
988 wxLogTrace(TRACE_KEYS
, wxT("\t-> keycode %d"), keycode
);
990 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
992 // use the normalized, i.e. lower register, keysym if we've
994 key_code
= keysymNormalized
? keysymNormalized
: keysym
;
996 // as explained above, we want to have lower register key codes
997 // normally but for the letter keys we want to have the upper ones
999 // NB: don't use XConvertCase() here, we want to do it for letters
1001 key_code
= toupper(key_code
);
1003 else // non ASCII key, what to do?
1005 // by default, ignore it
1008 // but if we have cached information from the last KEY_PRESS
1009 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
1012 if ( keysym
== s_lastKeyPress
.keysym
)
1014 key_code
= s_lastKeyPress
.keycode
;
1019 if ( gdk_event
->type
== GDK_KEY_PRESS
)
1021 // remember it to be reused for KEY_UP event later
1022 s_lastKeyPress
.keysym
= keysym
;
1023 s_lastKeyPress
.keycode
= key_code
;
1027 wxLogTrace(TRACE_KEYS
, wxT("\t-> wxKeyCode %ld"), key_code
);
1029 // sending unknown key events doesn't really make sense
1033 // now fill all the other fields
1034 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
1036 event
.m_keyCode
= key_code
;
1043 static gint
gtk_window_key_press_callback( GtkWidget
*widget
,
1044 GdkEventKey
*gdk_event
,
1050 wxapp_install_idle_handler();
1054 if (g_blockEventsOnDrag
)
1058 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1060 bool return_after_IM
= false;
1062 if ( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1064 // Emit KEY_DOWN event
1065 ret
= win
->HandleWindowEvent( event
);
1069 // Return after IM processing as we cannot do
1070 // anything with it anyhow.
1071 return_after_IM
= true;
1074 // This is for GTK+ 1.2 only. The char event generatation for GTK+ 2.0 is done
1075 // in the "commit" handler.
1077 // 2005.02.02 modified by Hong Jen Yee (hzysoft@sina.com.tw).
1078 // In GTK+ 1.2, strings sent by IMs are also regarded as key_press events whose
1079 // keyCodes cannot be recognized by wxWidgets. These MBCS strings, however, are
1080 // composed of more than one character, which means gdk_event->length will always
1081 // greater than one. When gtk_event->length == 1, this may be an ASCII character
1082 // and can be translated by wx. However, when MBCS characters are sent by IM,
1083 // gdk_event->length will >= 2. So neither should we pass it to accelerator table,
1084 // nor should we pass it to controls. The following explanation was excerpted
1085 // from GDK documentation.
1086 // gint length : the length of string.
1087 // gchar *string : a null-terminated multi-byte string containing the composed
1088 // characters resulting from the key press. When text is being input, in a GtkEntry
1089 // for example, it is these characters which should be added to the input buffer.
1090 // When using Input Methods to support internationalized text input, the composed
1091 // characters appear here after the pre-editing has been completed.
1093 if ( (!ret
) && (gdk_event
->length
> 1) ) // If this event contains a pre-edited string from IM.
1095 // We should translate this key event into wxEVT_CHAR not wxEVT_KEY_DOWN.
1096 #if wxUSE_UNICODE // GTK+ 1.2 is not UTF-8 based.
1097 const wxWCharBuffer string
= wxConvLocal
.cMB2WC( gdk_event
->string
);
1101 const char* string
= gdk_event
->string
;
1104 // Implement OnCharHook by checking ancestor top level windows
1105 wxWindow
*parent
= win
;
1106 while (parent
&& !parent
->IsTopLevel())
1107 parent
= parent
->GetParent();
1109 for( const wxChar
* pstr
= string
; *pstr
; pstr
++ )
1112 event
.m_uniChar
= *pstr
;
1113 // Backward compatible for ISO-8859-1
1114 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1116 event
.m_keyCode
= *pstr
;
1120 event
.SetEventType( wxEVT_CHAR_HOOK
);
1121 ret
= parent
->HandleWindowEvent( event
);
1125 event
.SetEventType(wxEVT_CHAR
);
1126 win
->HandleWindowEvent( event
);
1132 if (return_after_IM
)
1138 wxWindowGTK
*ancestor
= win
;
1141 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1144 wxCommandEvent
command_event( wxEVT_MENU
, command
);
1145 ret
= ancestor
->HandleWindowEvent( command_event
);
1148 if (ancestor
->IsTopLevel())
1150 ancestor
= ancestor
->GetParent();
1153 #endif // wxUSE_ACCEL
1155 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
1156 // will only be sent if it is not in an accelerator table.
1160 KeySym keysym
= gdk_event
->keyval
;
1161 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
1162 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
1165 if ( wxIsAsciiKeysym(keysym
) )
1168 key_code
= (unsigned char)keysym
;
1170 // gdk_event->string is actually deprecated
1171 else if ( gdk_event
->length
== 1 )
1173 key_code
= (unsigned char)gdk_event
->string
[0];
1179 wxLogTrace(TRACE_KEYS
, wxT("Char event: %ld"), key_code
);
1181 event
.m_keyCode
= key_code
;
1183 // Implement OnCharHook by checking ancestor top level windows
1184 wxWindow
*parent
= win
;
1185 while (parent
&& !parent
->IsTopLevel())
1186 parent
= parent
->GetParent();
1189 event
.SetEventType( wxEVT_CHAR_HOOK
);
1190 ret
= parent
->HandleWindowEvent( event
);
1195 event
.SetEventType(wxEVT_CHAR
);
1196 ret
= win
->HandleWindowEvent( event
);
1205 // win is a control: tab can be propagated up
1207 ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
)) &&
1208 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here - the control may
1209 // have this style, yet choose not to process this particular TAB in which
1210 // case TAB must still work as a navigational character
1211 // JS: enabling again to make consistent with other platforms
1212 // (with wxTE_PROCESS_TAB you have to call Navigate to get default
1213 // navigation behaviour)
1215 (! (win
->HasFlag(wxTE_PROCESS_TAB
) && win
->IsKindOf(CLASSINFO(wxTextCtrl
)) )) &&
1217 win
->GetParent() && (win
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1219 wxNavigationKeyEvent new_event
;
1220 new_event
.SetEventObject( win
->GetParent() );
1221 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
1222 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
1223 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
1224 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
1225 new_event
.SetCurrentFocus( win
);
1226 ret
= win
->GetParent()->HandleWindowEvent( new_event
);
1229 // generate wxID_CANCEL if <esc> has been pressed (typically in dialogs)
1231 (gdk_event
->keyval
== GDK_Escape
) )
1233 // however only do it if we have a Cancel button in the dialog,
1234 // otherwise the user code may get confused by the events from a
1235 // non-existing button and, worse, a wxButton might get button event
1236 // from another button which is not really expected
1237 wxWindow
*winForCancel
= win
,
1239 while ( winForCancel
)
1241 btnCancel
= winForCancel
->FindWindow(wxID_CANCEL
);
1244 // found a cancel button
1248 if ( winForCancel
->IsTopLevel() )
1250 // no need to look further
1254 // maybe our parent has a cancel button?
1255 winForCancel
= winForCancel
->GetParent();
1260 wxCommandEvent
eventClick(wxEVT_BUTTON
, wxID_CANCEL
);
1261 eventClick
.SetEventObject(btnCancel
);
1262 ret
= btnCancel
->HandleWindowEvent(eventClick
);
1268 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
1276 //-----------------------------------------------------------------------------
1277 // "key_release_event" from any window
1278 //-----------------------------------------------------------------------------
1281 static gint
gtk_window_key_release_callback( GtkWidget
*widget
,
1282 GdkEventKey
*gdk_event
,
1288 wxapp_install_idle_handler();
1293 if (g_blockEventsOnDrag
)
1296 wxKeyEvent
event( wxEVT_KEY_UP
);
1297 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1299 // unknown key pressed, ignore (the event would be useless anyhow)
1303 if ( !win
->HandleWindowEvent( event
) )
1306 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_release_event" );
1311 // ============================================================================
1313 // ============================================================================
1315 // ----------------------------------------------------------------------------
1316 // mouse event processing helpers
1317 // ----------------------------------------------------------------------------
1319 // init wxMouseEvent with the info from GdkEventXXX struct
1320 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1321 wxMouseEvent
& event
,
1324 event
.SetTimestamp( gdk_event
->time
);
1325 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1326 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1327 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1328 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1329 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1330 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1331 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1332 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
1334 event
.m_linesPerAction
= 3;
1335 event
.m_columnsPerAction
= 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
== 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 g_lastButtonNumber
= gdk_event
->button
;
1478 if (win
->m_wxwindow
&& (g_focusWindow
!= win
) && win
->IsFocusable())
1480 gtk_widget_grab_focus( win
->m_wxwindow
);
1482 wxPrintf( wxT("GrabFocus from ") );
1483 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1484 wxPrintf( win->GetClassInfo()->GetClassName() );
1485 wxPrintf( wxT(".\n") );
1489 // GDK sends surplus button down events
1490 // before a double click event. We
1491 // need to filter these out.
1492 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1494 GdkEvent
*peek_event
= gdk_event_peek();
1497 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1498 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1500 gdk_event_free( peek_event
);
1505 gdk_event_free( peek_event
);
1510 wxEventType event_type
= wxEVT_NULL
;
1512 if (gdk_event
->button
== 1)
1514 // note that GDK generates triple click events which are not supported
1515 // by wxWidgets but still have to be passed to the app as otherwise
1516 // clicks would simply go missing
1517 switch (gdk_event
->type
)
1519 // we shouldn't get triple clicks at all for GTK2 because we
1520 // suppress them artificially using the code above but we still
1521 // should map them to something for GTK1 and not just ignore them
1522 // as this would lose clicks
1523 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1524 case GDK_BUTTON_PRESS
:
1525 event_type
= wxEVT_LEFT_DOWN
;
1528 case GDK_2BUTTON_PRESS
:
1529 event_type
= wxEVT_LEFT_DCLICK
;
1533 // just to silence gcc warnings
1537 else if (gdk_event
->button
== 2)
1539 switch (gdk_event
->type
)
1541 case GDK_3BUTTON_PRESS
:
1542 case GDK_BUTTON_PRESS
:
1543 event_type
= wxEVT_MIDDLE_DOWN
;
1546 case GDK_2BUTTON_PRESS
:
1547 event_type
= wxEVT_MIDDLE_DCLICK
;
1554 else if (gdk_event
->button
== 3)
1556 switch (gdk_event
->type
)
1558 case GDK_3BUTTON_PRESS
:
1559 case GDK_BUTTON_PRESS
:
1560 event_type
= wxEVT_RIGHT_DOWN
;
1563 case GDK_2BUTTON_PRESS
:
1564 event_type
= wxEVT_RIGHT_DCLICK
;
1571 else if (gdk_event
->button
== 4 || gdk_event
->button
== 5)
1573 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1575 event_type
= wxEVT_MOUSEWHEEL
;
1579 if ( event_type
== wxEVT_NULL
)
1581 // unknown mouse button or click type
1585 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1587 wxMouseEvent
event( event_type
);
1588 InitMouseEvent( win
, event
, gdk_event
);
1590 AdjustEventButtonState(event
);
1592 // wxListBox actually gets mouse events from the item, so we need to give it
1593 // a chance to correct this
1594 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1596 // find the correct window to send the event to: it may be a different one
1597 // from the one which got it at GTK+ level because some controls don't have
1598 // their own X window and thus cannot get any events.
1599 if ( !g_captureWindow
)
1600 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1602 wxGtkTimeLastClick
= gdk_event
->time
;
1604 if (event_type
== wxEVT_LEFT_DCLICK
)
1606 // GTK 1.2 crashes when intercepting double
1607 // click events from both wxSpinButton and
1609 if (GTK_IS_SPIN_BUTTON(win
->m_widget
))
1611 // Just disable this event for now.
1616 if (win
->HandleWindowEvent( event
))
1618 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_press_event" );
1619 g_lastMouseEvent
= NULL
;
1622 g_lastMouseEvent
= NULL
;
1624 if (event_type
== wxEVT_RIGHT_DOWN
)
1626 // generate a "context menu" event: this is similar to right mouse
1627 // click under many GUIs except that it is generated differently
1628 // (right up under MSW, ctrl-click under Mac, right down here) and
1630 // (a) it's a command event and so is propagated to the parent
1631 // (b) under some ports it can be generated from kbd too
1632 // (c) it uses screen coords (because of (a))
1633 wxContextMenuEvent
evtCtx(
1636 win
->ClientToScreen(event
.GetPosition()));
1637 evtCtx
.SetEventObject(win
);
1638 return win
->HandleWindowEvent(evtCtx
);
1645 //-----------------------------------------------------------------------------
1646 // "button_release_event"
1647 //-----------------------------------------------------------------------------
1650 static gint
gtk_window_button_release_callback( GtkWidget
*widget
,
1651 GdkEventButton
*gdk_event
,
1657 wxapp_install_idle_handler();
1659 if (!win
->m_hasVMT
) return FALSE
;
1660 if (g_blockEventsOnDrag
) return FALSE
;
1661 if (g_blockEventsOnScroll
) return FALSE
;
1663 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1665 g_lastButtonNumber
= 0;
1667 wxEventType event_type
= wxEVT_NULL
;
1669 switch (gdk_event
->button
)
1672 event_type
= wxEVT_LEFT_UP
;
1676 event_type
= wxEVT_MIDDLE_UP
;
1680 event_type
= wxEVT_RIGHT_UP
;
1684 // unknown button, don't process
1688 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1690 wxMouseEvent
event( event_type
);
1691 InitMouseEvent( win
, event
, gdk_event
);
1693 AdjustEventButtonState(event
);
1695 // same wxListBox hack as above
1696 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1698 if ( !g_captureWindow
)
1699 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1701 if (win
->HandleWindowEvent( event
))
1703 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_release_event" );
1711 //-----------------------------------------------------------------------------
1712 // "motion_notify_event"
1713 //-----------------------------------------------------------------------------
1716 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
,
1717 GdkEventMotion
*gdk_event
,
1723 wxapp_install_idle_handler();
1725 if (!win
->m_hasVMT
) return FALSE
;
1726 if (g_blockEventsOnDrag
) return FALSE
;
1727 if (g_blockEventsOnScroll
) return FALSE
;
1729 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1731 if (gdk_event
->is_hint
)
1735 GdkModifierType state
;
1736 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1741 g_lastMouseEvent
= (GdkEvent
*) gdk_event
;
1744 printf( "OnMotion from " );
1745 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1746 printf( win->GetClassInfo()->GetClassName() );
1750 wxMouseEvent
event( wxEVT_MOTION
);
1751 InitMouseEvent(win
, event
, gdk_event
);
1753 if ( g_captureWindow
)
1755 // synthetize a mouse enter or leave event if needed
1756 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1757 // This seems to be necessary and actually been added to
1758 // GDK itself in version 2.0.X
1761 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1762 if ( hasMouse
!= g_captureWindowHasMouse
)
1764 // the mouse changed window
1765 g_captureWindowHasMouse
= hasMouse
;
1767 wxMouseEvent
eventM(g_captureWindowHasMouse
? wxEVT_ENTER_WINDOW
1768 : wxEVT_LEAVE_WINDOW
);
1769 InitMouseEvent(win
, eventM
, gdk_event
);
1770 eventM
.SetEventObject(win
);
1771 win
->HandleWindowEvent(eventM
);
1776 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1779 bool ret
= win
->HandleWindowEvent( event
);
1780 g_lastMouseEvent
= NULL
;
1784 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "motion_notify_event" );
1787 return ret
? TRUE
: FALSE
;
1791 //-----------------------------------------------------------------------------
1793 //-----------------------------------------------------------------------------
1795 // send the wxChildFocusEvent and wxFocusEvent, common code of
1796 // gtk_window_focus_in_callback() and SetFocus()
1797 static bool DoSendFocusEvents(wxWindow
*win
)
1799 // Notify the parent keeping track of focus for the kbd navigation
1800 // purposes that we got it.
1801 wxChildFocusEvent
eventChildFocus(win
);
1802 (void)win
->HandleWindowEvent(eventChildFocus
);
1804 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, win
->GetId());
1805 eventFocus
.SetEventObject(win
);
1807 return win
->HandleWindowEvent(eventFocus
);
1811 static gint
gtk_window_focus_in_callback( GtkWidget
*widget
,
1812 GdkEvent
*WXUNUSED(event
),
1818 wxapp_install_idle_handler();
1821 g_focusWindow
= win
;
1823 wxLogTrace(TRACE_FOCUS
,
1824 wxT("%s: focus in"), win
->GetName().c_str());
1828 gdk_im_begin(win
->m_ic
, win
->m_wxwindow
->window
);
1832 // caret needs to be informed about focus change
1833 wxCaret
*caret
= win
->GetCaret();
1836 caret
->OnSetFocus();
1838 #endif // wxUSE_CARET
1840 // does the window itself think that it has the focus?
1841 if ( !win
->m_hasFocus
)
1843 // not yet, notify it
1844 win
->m_hasFocus
= true;
1846 if ( DoSendFocusEvents(win
) )
1848 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_in_event" );
1857 //-----------------------------------------------------------------------------
1858 // "focus_out_event"
1859 //-----------------------------------------------------------------------------
1862 static gint
gtk_window_focus_out_callback( GtkWidget
*WXUNUSED(widget
),
1863 GdkEventFocus
*WXUNUSED(gdk_event
),
1869 wxapp_install_idle_handler();
1871 wxLogTrace( TRACE_FOCUS
,
1872 wxT("%s: focus out"), win
->GetName().c_str() );
1875 wxWindowGTK
*winFocus
= wxFindFocusedChild(win
);
1879 g_focusWindow
= NULL
;
1887 // caret needs to be informed about focus change
1888 wxCaret
*caret
= win
->GetCaret();
1891 caret
->OnKillFocus();
1893 #endif // wxUSE_CARET
1895 // don't send the window a kill focus event if it thinks that it doesn't
1896 // have focus already
1897 if ( win
->m_hasFocus
)
1899 win
->m_hasFocus
= false;
1901 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
1902 event
.SetEventObject( win
);
1904 // even if we did process the event in wx code, still let GTK itself
1905 // process it too as otherwise bad things happen, especially in GTK2
1906 // where the text control simply aborts the program if it doesn't get
1907 // the matching focus out event
1908 (void)win
->HandleWindowEvent( event
);
1915 //-----------------------------------------------------------------------------
1916 // "enter_notify_event"
1917 //-----------------------------------------------------------------------------
1921 gint
gtk_window_enter_callback( GtkWidget
*widget
,
1922 GdkEventCrossing
*gdk_event
,
1928 wxapp_install_idle_handler();
1930 if (!win
->m_hasVMT
) return FALSE
;
1931 if (g_blockEventsOnDrag
) return FALSE
;
1933 // Event was emitted after a grab
1934 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1936 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1940 GdkModifierType state
= (GdkModifierType
)0;
1942 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1944 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
1945 InitMouseEvent(win
, event
, gdk_event
);
1946 wxPoint pt
= win
->GetClientAreaOrigin();
1947 event
.m_x
= x
+ pt
.x
;
1948 event
.m_y
= y
+ pt
.y
;
1950 if (win
->HandleWindowEvent( event
))
1952 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "enter_notify_event" );
1960 //-----------------------------------------------------------------------------
1961 // "leave_notify_event"
1962 //-----------------------------------------------------------------------------
1965 static gint
gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindowGTK
*win
)
1970 wxapp_install_idle_handler();
1972 if (!win
->m_hasVMT
) return FALSE
;
1973 if (g_blockEventsOnDrag
) return FALSE
;
1975 // Event was emitted after an ungrab
1976 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
1978 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1980 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
1981 event
.SetTimestamp( gdk_event
->time
);
1982 event
.SetEventObject( win
);
1986 GdkModifierType state
= (GdkModifierType
)0;
1988 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
1990 event
.m_shiftDown
= (state
& GDK_SHIFT_MASK
) != 0;
1991 event
.m_controlDown
= (state
& GDK_CONTROL_MASK
) != 0;
1992 event
.m_altDown
= (state
& GDK_MOD1_MASK
) != 0;
1993 event
.m_metaDown
= (state
& GDK_MOD2_MASK
) != 0;
1994 event
.m_leftDown
= (state
& GDK_BUTTON1_MASK
) != 0;
1995 event
.m_middleDown
= (state
& GDK_BUTTON2_MASK
) != 0;
1996 event
.m_rightDown
= (state
& GDK_BUTTON3_MASK
) != 0;
1998 wxPoint pt
= win
->GetClientAreaOrigin();
1999 event
.m_x
= x
+ pt
.x
;
2000 event
.m_y
= y
+ pt
.y
;
2002 if (win
->HandleWindowEvent( event
))
2004 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "leave_notify_event" );
2012 //-----------------------------------------------------------------------------
2013 // "value_changed" from m_vAdjust
2014 //-----------------------------------------------------------------------------
2017 static void gtk_window_vscroll_callback( GtkAdjustment
*adjust
,
2024 wxapp_install_idle_handler();
2026 if (g_blockEventsOnDrag
) return;
2028 if (!win
->m_hasVMT
) return;
2030 float diff
= adjust
->value
- win
->m_oldVerticalPos
;
2031 if (fabs(diff
) < 0.2) return;
2033 win
->m_oldVerticalPos
= adjust
->value
;
2035 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2036 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->vscrollbar
));
2038 int value
= (int)(adjust
->value
+0.5);
2040 wxScrollWinEvent
event( command
, value
, wxVERTICAL
);
2041 event
.SetEventObject( win
);
2042 win
->HandleWindowEvent( event
);
2046 //-----------------------------------------------------------------------------
2047 // "value_changed" from m_hAdjust
2048 //-----------------------------------------------------------------------------
2051 static void gtk_window_hscroll_callback( GtkAdjustment
*adjust
,
2058 wxapp_install_idle_handler();
2060 if (g_blockEventsOnDrag
) return;
2061 if (!win
->m_hasVMT
) return;
2063 float diff
= adjust
->value
- win
->m_oldHorizontalPos
;
2064 if (fabs(diff
) < 0.2) return;
2066 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2067 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->hscrollbar
));
2069 win
->m_oldHorizontalPos
= adjust
->value
;
2071 int value
= (int)(adjust
->value
+0.5);
2073 wxScrollWinEvent
event( command
, value
, wxHORIZONTAL
);
2074 event
.SetEventObject( win
);
2075 win
->HandleWindowEvent( event
);
2079 //-----------------------------------------------------------------------------
2080 // "button_press_event" from scrollbar
2081 //-----------------------------------------------------------------------------
2084 static gint
gtk_scrollbar_button_press_callback( GtkRange
*widget
,
2085 GdkEventButton
*gdk_event
,
2091 wxapp_install_idle_handler();
2094 g_blockEventsOnScroll
= true;
2096 // FIXME: there is no 'slider' field in GTK+ 2.0 any more
2097 win
->m_isScrolling
= (gdk_event
->window
== widget
->slider
);
2103 //-----------------------------------------------------------------------------
2104 // "button_release_event" from scrollbar
2105 //-----------------------------------------------------------------------------
2108 static gint
gtk_scrollbar_button_release_callback( GtkRange
*widget
,
2109 GdkEventButton
*WXUNUSED(gdk_event
),
2114 // don't test here as we can release the mouse while being over
2115 // a different window than the slider
2117 // if (gdk_event->window != widget->slider) return FALSE;
2119 g_blockEventsOnScroll
= false;
2121 if (win
->m_isScrolling
)
2123 wxEventType command
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2127 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2128 if (widget
== GTK_RANGE(scrolledWindow
->hscrollbar
))
2130 value
= (int)(win
->m_hAdjust
->value
+0.5);
2133 if (widget
== GTK_RANGE(scrolledWindow
->vscrollbar
))
2135 value
= (int)(win
->m_vAdjust
->value
+0.5);
2139 wxScrollWinEvent
event( command
, value
, dir
);
2140 event
.SetEventObject( win
);
2141 win
->HandleWindowEvent( event
);
2144 win
->m_isScrolling
= false;
2150 // ----------------------------------------------------------------------------
2151 // this wxWindowBase function is implemented here (in platform-specific file)
2152 // because it is static and so couldn't be made virtual
2153 // ----------------------------------------------------------------------------
2155 wxWindow
*wxWindowBase::DoFindFocus()
2157 // the cast is necessary when we compile in wxUniversal mode
2158 return (wxWindow
*)g_focusWindow
;
2161 //-----------------------------------------------------------------------------
2162 // "realize" from m_widget
2163 //-----------------------------------------------------------------------------
2165 /* We cannot set colours and fonts before the widget has
2166 been realized, so we do this directly after realization. */
2170 gtk_window_realized_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
2175 wxapp_install_idle_handler();
2177 wxWindowCreateEvent
event( win
);
2178 event
.SetEventObject( win
);
2179 win
->HandleWindowEvent( event
);
2185 //-----------------------------------------------------------------------------
2187 //-----------------------------------------------------------------------------
2191 void gtk_window_size_callback( GtkWidget
*WXUNUSED(widget
),
2192 GtkAllocation
*WXUNUSED(alloc
),
2196 wxapp_install_idle_handler();
2198 if (!win
->m_hasScrolling
) return;
2200 int client_width
= 0;
2201 int client_height
= 0;
2202 win
->GetClientSize( &client_width
, &client_height
);
2203 if ((client_width
== win
->m_oldClientWidth
) && (client_height
== win
->m_oldClientHeight
))
2206 win
->m_oldClientWidth
= client_width
;
2207 win
->m_oldClientHeight
= client_height
;
2209 if (!win
->m_nativeSizeEvent
)
2211 wxSizeEvent
event( win
->GetSize(), win
->GetId() );
2212 event
.SetEventObject( win
);
2213 win
->HandleWindowEvent( event
);
2220 #define WXUNUSED_UNLESS_XIM(param) param
2222 #define WXUNUSED_UNLESS_XIM(param) WXUNUSED(param)
2225 /* Resize XIM window */
2229 void gtk_wxwindow_size_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2230 GtkAllocation
* WXUNUSED(alloc
),
2231 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2234 wxapp_install_idle_handler();
2240 if (gdk_ic_get_style (win
->m_ic
) & GDK_IM_PREEDIT_POSITION
)
2244 gdk_window_get_size (widget
->window
, &width
, &height
);
2245 win
->m_icattr
->preedit_area
.width
= width
;
2246 win
->m_icattr
->preedit_area
.height
= height
;
2247 gdk_ic_set_attr (win
->m_ic
, win
->m_icattr
, GDK_IC_PREEDIT_AREA
);
2253 //-----------------------------------------------------------------------------
2254 // "realize" from m_wxwindow
2255 //-----------------------------------------------------------------------------
2257 /* Initialize XIM support */
2261 gtk_wxwindow_realized_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2262 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2265 wxapp_install_idle_handler();
2268 if (win
->m_ic
) return FALSE
;
2269 if (!widget
) return FALSE
;
2270 if (!gdk_im_ready()) return FALSE
;
2272 win
->m_icattr
= gdk_ic_attr_new();
2273 if (!win
->m_icattr
) return FALSE
;
2277 GdkColormap
*colormap
;
2278 GdkICAttr
*attr
= win
->m_icattr
;
2279 unsigned attrmask
= GDK_IC_ALL_REQ
;
2281 GdkIMStyle supported_style
= (GdkIMStyle
)
2282 (GDK_IM_PREEDIT_NONE
|
2283 GDK_IM_PREEDIT_NOTHING
|
2284 GDK_IM_PREEDIT_POSITION
|
2285 GDK_IM_STATUS_NONE
|
2286 GDK_IM_STATUS_NOTHING
);
2288 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2289 supported_style
= (GdkIMStyle
)(supported_style
& ~GDK_IM_PREEDIT_POSITION
);
2291 attr
->style
= style
= gdk_im_decide_style (supported_style
);
2292 attr
->client_window
= widget
->window
;
2294 if ((colormap
= gtk_widget_get_colormap (widget
)) !=
2295 gtk_widget_get_default_colormap ())
2297 attrmask
|= GDK_IC_PREEDIT_COLORMAP
;
2298 attr
->preedit_colormap
= colormap
;
2301 attrmask
|= GDK_IC_PREEDIT_FOREGROUND
;
2302 attrmask
|= GDK_IC_PREEDIT_BACKGROUND
;
2303 attr
->preedit_foreground
= widget
->style
->fg
[GTK_STATE_NORMAL
];
2304 attr
->preedit_background
= widget
->style
->base
[GTK_STATE_NORMAL
];
2306 switch (style
& GDK_IM_PREEDIT_MASK
)
2308 case GDK_IM_PREEDIT_POSITION
:
2309 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2311 g_warning ("over-the-spot style requires fontset");
2315 gdk_window_get_size (widget
->window
, &width
, &height
);
2317 attrmask
|= GDK_IC_PREEDIT_POSITION_REQ
;
2318 attr
->spot_location
.x
= 0;
2319 attr
->spot_location
.y
= height
;
2320 attr
->preedit_area
.x
= 0;
2321 attr
->preedit_area
.y
= 0;
2322 attr
->preedit_area
.width
= width
;
2323 attr
->preedit_area
.height
= height
;
2324 attr
->preedit_fontset
= widget
->style
->font
;
2329 win
->m_ic
= gdk_ic_new (attr
, (GdkICAttributesType
)attrmask
);
2331 if (win
->m_ic
== NULL
)
2332 g_warning ("Can't create input context.");
2335 mask
= gdk_window_get_events (widget
->window
);
2336 mask
= (GdkEventMask
)(mask
| gdk_ic_get_events (win
->m_ic
));
2337 gdk_window_set_events (widget
->window
, mask
);
2339 if (GTK_WIDGET_HAS_FOCUS(widget
))
2340 gdk_im_begin (win
->m_ic
, widget
->window
);
2348 //-----------------------------------------------------------------------------
2349 // InsertChild for wxWindowGTK.
2350 //-----------------------------------------------------------------------------
2352 /* Callback for wxWindowGTK. This very strange beast has to be used because
2353 * C++ has no virtual methods in a constructor. We have to emulate a
2354 * virtual function here as wxNotebook requires a different way to insert
2355 * a child in it. I had opted for creating a wxNotebookPage window class
2356 * which would have made this superfluous (such in the MDI window system),
2357 * but no-one was listening to me... */
2359 static void wxInsertChildInWindow( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2361 /* the window might have been scrolled already, do we
2362 have to adapt the position */
2363 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
2364 child
->m_x
+= pizza
->xoffset
;
2365 child
->m_y
+= pizza
->yoffset
;
2367 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
2368 GTK_WIDGET(child
->m_widget
),
2375 //-----------------------------------------------------------------------------
2377 //-----------------------------------------------------------------------------
2379 wxWindow
*wxGetActiveWindow()
2381 return wxWindow::FindFocus();
2385 wxMouseState
wxGetMouseState()
2391 GdkModifierType mask
;
2393 gdk_window_get_pointer(NULL
, &x
, &y
, &mask
);
2397 ms
.SetLeftDown(mask
& GDK_BUTTON1_MASK
);
2398 ms
.SetMiddleDown(mask
& GDK_BUTTON2_MASK
);
2399 ms
.SetRightDown(mask
& GDK_BUTTON3_MASK
);
2401 ms
.SetControlDown(mask
& GDK_CONTROL_MASK
);
2402 ms
.SetShiftDown(mask
& GDK_SHIFT_MASK
);
2403 ms
.SetAltDown(mask
& GDK_MOD1_MASK
);
2404 ms
.SetMetaDown(mask
& GDK_MOD2_MASK
);
2409 //-----------------------------------------------------------------------------
2411 //-----------------------------------------------------------------------------
2413 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2415 #ifdef __WXUNIVERSAL__
2416 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2417 #endif // __WXUNIVERSAL__
2419 void wxWindowGTK::Init()
2424 m_focusWidget
= NULL
;
2434 m_needParent
= true;
2437 m_nativeSizeEvent
= false;
2439 m_hasScrolling
= false;
2440 m_isScrolling
= false;
2444 m_oldHorizontalPos
=
2445 m_oldVerticalPos
= 0.0;
2447 m_oldClientHeight
= 0;
2451 m_insertCallback
= (wxInsertChildFunction
) NULL
;
2453 m_acceptsFocus
= false;
2456 m_clipPaintRegion
= false;
2458 m_needsStyleChange
= false;
2460 m_cursor
= *wxSTANDARD_CURSOR
;
2468 wxWindowGTK::wxWindowGTK()
2473 wxWindowGTK::wxWindowGTK( wxWindow
*parent
,
2478 const wxString
&name
)
2482 Create( parent
, id
, pos
, size
, style
, name
);
2485 bool wxWindowGTK::Create( wxWindow
*parent
,
2490 const wxString
&name
)
2492 // Get default border
2493 wxBorder border
= GetBorder(style
);
2494 style
&= ~wxBORDER_MASK
;
2497 if (!PreCreation( parent
, pos
, size
) ||
2498 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2500 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2504 m_insertCallback
= wxInsertChildInWindow
;
2506 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
2507 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
2509 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2511 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2512 scroll_class
->scrollbar_spacing
= 0;
2514 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2516 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
2517 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
2519 m_wxwindow
= gtk_pizza_new();
2521 #ifndef __WXUNIVERSAL__
2522 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
2524 if (HasFlag(wxRAISED_BORDER
))
2526 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
2528 else if (HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxBORDER_THEME
))
2530 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
2532 else if (HasFlag(wxSIMPLE_BORDER
))
2534 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
2538 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
2540 #endif // __WXUNIVERSAL__
2542 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2544 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
2545 m_acceptsFocus
= true;
2547 // I _really_ don't want scrollbars in the beginning
2548 m_vAdjust
->lower
= 0.0;
2549 m_vAdjust
->upper
= 1.0;
2550 m_vAdjust
->value
= 0.0;
2551 m_vAdjust
->step_increment
= 1.0;
2552 m_vAdjust
->page_increment
= 1.0;
2553 m_vAdjust
->page_size
= 5.0;
2554 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
2555 m_hAdjust
->lower
= 0.0;
2556 m_hAdjust
->upper
= 1.0;
2557 m_hAdjust
->value
= 0.0;
2558 m_hAdjust
->step_increment
= 1.0;
2559 m_hAdjust
->page_increment
= 1.0;
2560 m_hAdjust
->page_size
= 5.0;
2561 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
2563 // these handlers block mouse events to any window during scrolling such as
2564 // motion events and prevent GTK and wxWidgets from fighting over where the
2567 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_press_event",
2568 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2570 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_press_event",
2571 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2573 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_release_event",
2574 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2576 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_release_event",
2577 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2579 // these handlers get notified when screen updates are required either when
2580 // scrolling or when the window size (and therefore scrollbar configuration)
2583 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
2584 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
2585 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
2586 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
2588 gtk_widget_show( m_wxwindow
);
2591 m_parent
->DoAddChild( this );
2593 m_focusWidget
= m_wxwindow
;
2600 wxWindowGTK::~wxWindowGTK()
2604 if (g_focusWindow
== this)
2605 g_focusWindow
= NULL
;
2607 if ( g_delayedFocus
== this )
2608 g_delayedFocus
= NULL
;
2612 // destroy children before destroying this window itself
2615 // unhook focus handlers to prevent stray events being
2616 // propagated to this (soon to be) dead object
2617 if (m_focusWidget
!= NULL
)
2619 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2620 (GtkSignalFunc
) gtk_window_focus_in_callback
, (gpointer
) this );
2621 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2622 (GtkSignalFunc
) gtk_window_focus_out_callback
, (gpointer
) this );
2630 gdk_ic_destroy (m_ic
);
2632 gdk_ic_attr_destroy (m_icattr
);
2637 gtk_widget_destroy( m_wxwindow
);
2643 gtk_widget_destroy( m_widget
);
2648 bool wxWindowGTK::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2650 wxCHECK_MSG( !m_needParent
|| parent
, false, wxT("Need complete parent.") );
2652 // Use either the given size, or the default if -1 is given.
2653 // See wxWindowBase for these functions.
2654 m_width
= WidthDefault(size
.x
) ;
2655 m_height
= HeightDefault(size
.y
);
2663 void wxWindowGTK::PostCreation()
2665 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2671 // these get reported to wxWidgets -> wxPaintEvent
2673 gtk_pizza_set_external( GTK_PIZZA(m_wxwindow
), TRUE
);
2675 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
2676 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
2678 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
2679 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
2681 if (!HasFlag(wxFULL_REPAINT_ON_RESIZE
))
2683 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "event",
2684 GTK_SIGNAL_FUNC(gtk_window_event_event_callback
), (gpointer
)this );
2688 // these are called when the "sunken" or "raised" borders are drawn
2689 gtk_signal_connect( GTK_OBJECT(m_widget
), "expose_event",
2690 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
2692 gtk_signal_connect( GTK_OBJECT(m_widget
), "draw",
2693 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
2698 if (!GTK_IS_WINDOW(m_widget
))
2700 if (m_focusWidget
== NULL
)
2701 m_focusWidget
= m_widget
;
2703 gtk_signal_connect( GTK_OBJECT(m_focusWidget
), "focus_in_event",
2704 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
2706 gtk_signal_connect_after( GTK_OBJECT(m_focusWidget
), "focus_out_event",
2707 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
2710 // connect to the various key and mouse handlers
2712 GtkWidget
*connect_widget
= GetConnectWidget();
2714 ConnectWidget( connect_widget
);
2716 /* We cannot set colours, fonts and cursors before the widget has
2717 been realized, so we do this directly after realization */
2718 gtk_signal_connect( GTK_OBJECT(connect_widget
), "realize",
2719 GTK_SIGNAL_FUNC(gtk_window_realized_callback
), (gpointer
) this );
2723 // Catch native resize events
2724 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
2725 GTK_SIGNAL_FUNC(gtk_window_size_callback
), (gpointer
)this );
2727 // Initialize XIM support
2728 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "realize",
2729 GTK_SIGNAL_FUNC(gtk_wxwindow_realized_callback
), (gpointer
) this );
2731 // And resize XIM window
2732 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
2733 GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback
), (gpointer
)this );
2736 if (GTK_IS_COMBO(m_widget
))
2738 GtkCombo
*gcombo
= GTK_COMBO(m_widget
);
2740 gtk_signal_connect( GTK_OBJECT(gcombo
->entry
), "size_request",
2741 GTK_SIGNAL_FUNC(wxgtk_combo_size_request_callback
),
2746 // This is needed if we want to add our windows into native
2747 // GTK controls, such as the toolbar. With this callback, the
2748 // toolbar gets to know the correct size (the one set by the
2749 // programmer). Sadly, it misbehaves for wxComboBox.
2750 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_request",
2751 GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback
),
2755 InheritAttributes();
2759 // unless the window was created initially hidden (i.e. Hide() had been
2760 // called before Create()), we should show it at GTK+ level as well
2762 gtk_widget_show( m_widget
);
2765 void wxWindowGTK::ConnectWidget( GtkWidget
*widget
)
2767 gtk_signal_connect( GTK_OBJECT(widget
), "key_press_event",
2768 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
2770 gtk_signal_connect( GTK_OBJECT(widget
), "key_release_event",
2771 GTK_SIGNAL_FUNC(gtk_window_key_release_callback
), (gpointer
)this );
2773 gtk_signal_connect( GTK_OBJECT(widget
), "button_press_event",
2774 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
2776 gtk_signal_connect( GTK_OBJECT(widget
), "button_release_event",
2777 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
2779 gtk_signal_connect( GTK_OBJECT(widget
), "motion_notify_event",
2780 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
2782 gtk_signal_connect( GTK_OBJECT(widget
), "enter_notify_event",
2783 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
2785 gtk_signal_connect( GTK_OBJECT(widget
), "leave_notify_event",
2786 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
2789 bool wxWindowGTK::Destroy()
2791 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2795 return wxWindowBase::Destroy();
2798 void wxWindowGTK::DoMoveWindow(int x
, int y
, int width
, int height
)
2800 gtk_pizza_set_size( GTK_PIZZA(m_parent
->m_wxwindow
), m_widget
, x
, y
, width
, height
);
2803 void wxWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
2805 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2806 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
2809 printf( "DoSetSize: name %s, x,y,w,h: %d,%d,%d,%d \n", GetName().c_str(), x,y,width,height );
2812 if (m_resizing
) return; /* I don't like recursions */
2815 int currentX
, currentY
;
2816 GetPosition(¤tX
, ¤tY
);
2817 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2819 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2821 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2823 if (m_parent
->m_wxwindow
== NULL
) /* i.e. wxNotebook */
2825 /* don't set the size for children of wxNotebook, just take the values. */
2833 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
2834 if ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0)
2836 if (x
!= -1) m_x
= x
+ pizza
->xoffset
;
2837 if (y
!= -1) m_y
= y
+ pizza
->yoffset
;
2841 m_x
= x
+ pizza
->xoffset
;
2842 m_y
= y
+ pizza
->yoffset
;
2845 // calculate the best size if we should auto size the window
2846 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
2847 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
2849 const wxSize sizeBest
= GetBestSize();
2850 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
2852 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
2853 height
= sizeBest
.y
;
2861 int minWidth
= GetMinWidth(),
2862 minHeight
= GetMinHeight(),
2863 maxWidth
= GetMaxWidth(),
2864 maxHeight
= GetMaxHeight();
2866 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
2867 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
2868 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
2869 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
2871 int left_border
= 0;
2872 int right_border
= 0;
2874 int bottom_border
= 0;
2876 /* the default button has a border around it */
2877 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
2885 DoMoveWindow( m_x
-top_border
,
2887 m_width
+left_border
+right_border
,
2888 m_height
+top_border
+bottom_border
);
2893 /* Sometimes the client area changes size without the
2894 whole windows's size changing, but if the whole
2895 windows's size doesn't change, no wxSizeEvent will
2896 normally be sent. Here we add an extra test if
2897 the client test has been changed and this will
2899 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
2903 wxPrintf( "OnSize sent from " );
2904 if (GetClassInfo() && GetClassInfo()->GetClassName())
2905 wxPrintf( GetClassInfo()->GetClassName() );
2906 wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height );
2909 if (!m_nativeSizeEvent
)
2911 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
2912 event
.SetEventObject( this );
2913 HandleWindowEvent( event
);
2919 void wxWindowGTK::OnInternalIdle()
2921 // Update style if the window was not yet realized
2922 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
2923 if (m_needsStyleChange
)
2925 SetBackgroundStyle(GetBackgroundStyle());
2926 m_needsStyleChange
= false;
2929 // Update invalidated regions.
2932 wxCursor cursor
= m_cursor
;
2933 if (g_globalCursor
.IsOk()) cursor
= g_globalCursor
;
2937 /* I now set the cursor anew in every OnInternalIdle call
2938 as setting the cursor in a parent window also effects the
2939 windows above so that checking for the current cursor is
2944 GdkWindow
*window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
2946 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2948 if (!g_globalCursor
.IsOk())
2949 cursor
= *wxSTANDARD_CURSOR
;
2951 window
= m_widget
->window
;
2952 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
2953 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2956 else if ( m_widget
)
2958 GdkWindow
*window
= m_widget
->window
;
2959 if ( window
&& !GTK_WIDGET_NO_WINDOW(m_widget
) )
2960 gdk_window_set_cursor( window
, cursor
.GetCursor() );
2964 wxWindowBase::OnInternalIdle();
2967 void wxWindowGTK::DoGetSize( int *width
, int *height
) const
2969 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2971 if (width
) (*width
) = m_width
;
2972 if (height
) (*height
) = m_height
;
2975 void wxWindowGTK::DoSetClientSize( int width
, int height
)
2977 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
2981 SetSize( width
, height
);
2988 #ifndef __WXUNIVERSAL__
2989 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxBORDER_THEME
))
2991 /* when using GTK 1.2 we set the shadow border size to 2 */
2995 if (HasFlag(wxSIMPLE_BORDER
))
2997 /* when using GTK 1.2 we set the simple border size to 1 */
3001 #endif // __WXUNIVERSAL__
3005 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
3007 GtkRequisition vscroll_req
;
3008 vscroll_req
.width
= 2;
3009 vscroll_req
.height
= 2;
3010 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
3011 (scroll_window
->vscrollbar
, &vscroll_req
);
3013 GtkRequisition hscroll_req
;
3014 hscroll_req
.width
= 2;
3015 hscroll_req
.height
= 2;
3016 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
3017 (scroll_window
->hscrollbar
, &hscroll_req
);
3019 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3021 if (scroll_window
->vscrollbar_visible
)
3023 dw
+= vscroll_req
.width
;
3024 dw
+= scroll_class
->scrollbar_spacing
;
3027 if (scroll_window
->hscrollbar_visible
)
3029 dh
+= hscroll_req
.height
;
3030 dh
+= scroll_class
->scrollbar_spacing
;
3034 SetSize( width
+dw
, height
+dh
);
3038 void wxWindowGTK::DoGetClientSize( int *width
, int *height
) const
3040 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3044 if (width
) (*width
) = m_width
;
3045 if (height
) (*height
) = m_height
;
3052 #ifndef __WXUNIVERSAL__
3053 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxBORDER_THEME
))
3055 /* when using GTK 1.2 we set the shadow border size to 2 */
3059 if (HasFlag(wxSIMPLE_BORDER
))
3061 /* when using GTK 1.2 we set the simple border size to 1 */
3065 #endif // __WXUNIVERSAL__
3069 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
3071 GtkRequisition vscroll_req
;
3072 vscroll_req
.width
= 2;
3073 vscroll_req
.height
= 2;
3074 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
3075 (scroll_window
->vscrollbar
, &vscroll_req
);
3077 GtkRequisition hscroll_req
;
3078 hscroll_req
.width
= 2;
3079 hscroll_req
.height
= 2;
3080 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
3081 (scroll_window
->hscrollbar
, &hscroll_req
);
3083 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3085 if (scroll_window
->vscrollbar_visible
)
3087 dw
+= vscroll_req
.width
;
3088 dw
+= scroll_class
->scrollbar_spacing
;
3091 if (scroll_window
->hscrollbar_visible
)
3093 dh
+= hscroll_req
.height
;
3094 dh
+= scroll_class
->scrollbar_spacing
;
3098 if (width
) (*width
) = m_width
- dw
;
3099 if (height
) (*height
) = m_height
- dh
;
3103 printf( "GetClientSize, name %s ", GetName().c_str() );
3104 if (width) printf( " width = %d", (*width) );
3105 if (height) printf( " height = %d", (*height) );
3110 void wxWindowGTK::DoGetPosition( int *x
, int *y
) const
3112 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3116 if (m_parent
&& m_parent
->m_wxwindow
)
3118 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
3119 dx
= pizza
->xoffset
;
3120 dy
= pizza
->yoffset
;
3123 if (x
) (*x
) = m_x
- dx
;
3124 if (y
) (*y
) = m_y
- dy
;
3127 void wxWindowGTK::DoClientToScreen( int *x
, int *y
) const
3129 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3131 if (!m_widget
->window
) return;
3133 GdkWindow
*source
= NULL
;
3135 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3137 source
= m_widget
->window
;
3141 gdk_window_get_origin( source
, &org_x
, &org_y
);
3145 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3147 org_x
+= m_widget
->allocation
.x
;
3148 org_y
+= m_widget
->allocation
.y
;
3156 void wxWindowGTK::DoScreenToClient( int *x
, int *y
) const
3158 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3160 if (!m_widget
->window
) return;
3162 GdkWindow
*source
= NULL
;
3164 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3166 source
= m_widget
->window
;
3170 gdk_window_get_origin( source
, &org_x
, &org_y
);
3174 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3176 org_x
+= m_widget
->allocation
.x
;
3177 org_y
+= m_widget
->allocation
.y
;
3185 bool wxWindowGTK::Show( bool show
)
3187 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3189 if (!wxWindowBase::Show(show
))
3196 gtk_widget_show( m_widget
);
3198 gtk_widget_hide( m_widget
);
3200 wxShowEvent
eventShow(GetId(), show
);
3201 eventShow
.SetEventObject(this);
3203 HandleWindowEvent(eventShow
);
3208 void wxWindowGTK::DoEnable( bool enable
)
3210 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3212 gtk_widget_set_sensitive( m_widget
, enable
);
3214 gtk_widget_set_sensitive( m_wxwindow
, enable
);
3217 int wxWindowGTK::GetCharHeight() const
3219 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
3221 wxFont font
= GetFont();
3222 wxCHECK_MSG( font
.IsOk(), 12, wxT("invalid font") );
3224 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3226 return gfont
->ascent
+ gfont
->descent
;
3229 int wxWindowGTK::GetCharWidth() const
3231 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
3233 wxFont font
= GetFont();
3234 wxCHECK_MSG( font
.IsOk(), 8, wxT("invalid font") );
3236 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3238 return gdk_string_width( gfont
, "g" );
3241 void wxWindowGTK::DoGetTextExtent(const wxString
& string
,
3245 int *externalLeading
,
3246 const wxFont
*theFont
) const
3248 wxFont fontToUse
= theFont
? *theFont
: GetFont();
3250 wxCHECK_RET( fontToUse
.IsOk(), wxT("invalid font") );
3259 GdkFont
*font
= fontToUse
.GetInternalFont( 1.0 );
3260 if (x
) (*x
) = gdk_string_width( font
, wxGTK_CONV( string
) );
3261 if (y
) (*y
) = font
->ascent
+ font
->descent
;
3262 if (descent
) (*descent
) = font
->descent
;
3263 if (externalLeading
) (*externalLeading
) = 0; // ??
3266 void wxWindowGTK::SetFocus()
3268 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3271 // don't do anything if we already have focus
3277 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow
))
3279 gtk_widget_grab_focus (m_wxwindow
);
3284 if (GTK_WIDGET_CAN_FOCUS(m_widget
) && !GTK_WIDGET_HAS_FOCUS (m_widget
) )
3287 if (!GTK_WIDGET_REALIZED(m_widget
))
3289 // we can't set the focus to the widget now so we remember that
3290 // it should be focused and will do it later, during the idle
3291 // time, as soon as we can
3292 wxLogTrace(TRACE_FOCUS
,
3293 wxT("Delaying setting focus to %s(%s)"),
3294 GetClassInfo()->GetClassName(), GetLabel().c_str());
3296 g_delayedFocus
= this;
3300 wxLogTrace(TRACE_FOCUS
,
3301 wxT("Setting focus to %s(%s)"),
3302 GetClassInfo()->GetClassName(), GetLabel().c_str());
3304 gtk_widget_grab_focus (m_widget
);
3308 if (GTK_IS_CONTAINER(m_widget
))
3310 gtk_container_focus( GTK_CONTAINER(m_widget
), GTK_DIR_TAB_FORWARD
);
3314 wxLogTrace(TRACE_FOCUS
,
3315 wxT("Can't set focus to %s(%s)"),
3316 GetClassInfo()->GetClassName(), GetLabel().c_str());
3321 bool wxWindowGTK::AcceptsFocus() const
3323 return m_acceptsFocus
&& wxWindowBase::AcceptsFocus();
3326 bool wxWindowGTK::Reparent( wxWindowBase
*newParentBase
)
3328 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3330 wxWindowGTK
*oldParent
= m_parent
,
3331 *newParent
= (wxWindowGTK
*)newParentBase
;
3333 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3335 if ( !wxWindowBase::Reparent(newParent
) )
3338 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3340 /* prevent GTK from deleting the widget arbitrarily */
3341 gtk_widget_ref( m_widget
);
3345 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3348 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3352 /* insert GTK representation */
3353 (*(newParent
->m_insertCallback
))(newParent
, this);
3356 /* reverse: prevent GTK from deleting the widget arbitrarily */
3357 gtk_widget_unref( m_widget
);
3362 void wxWindowGTK::DoAddChild(wxWindowGTK
*child
)
3364 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3366 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3368 wxASSERT_MSG( (m_insertCallback
!= NULL
), wxT("invalid child insertion function") );
3373 /* insert GTK representation */
3374 (*m_insertCallback
)(this, child
);
3377 void wxWindowGTK::Raise()
3379 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3381 if (m_wxwindow
&& m_wxwindow
->window
)
3383 gdk_window_raise( m_wxwindow
->window
);
3385 else if (m_widget
->window
)
3387 gdk_window_raise( m_widget
->window
);
3391 void wxWindowGTK::Lower()
3393 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3395 if (m_wxwindow
&& m_wxwindow
->window
)
3397 gdk_window_lower( m_wxwindow
->window
);
3399 else if (m_widget
->window
)
3401 gdk_window_lower( m_widget
->window
);
3405 bool wxWindowGTK::SetCursor( const wxCursor
&cursor
)
3407 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3409 if ( cursor
.IsSameAs(m_cursor
) )
3413 wxapp_install_idle_handler();
3415 return wxWindowBase::SetCursor( cursor
.IsOk() ? cursor
3416 : *wxSTANDARD_CURSOR
);
3419 void wxWindowGTK::WarpPointer( int x
, int y
)
3421 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3423 // We provide this function ourselves as it is
3424 // missing in GDK (top of this file).
3426 GdkWindow
*window
= NULL
;
3428 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3430 window
= GetConnectWidget()->window
;
3433 gdk_window_warp_pointer( window
, x
, y
);
3437 void wxWindowGTK::Refresh( bool eraseBackground
, const wxRect
*rect
)
3441 if (!m_widget
->window
)
3445 wxapp_install_idle_handler();
3448 if (m_wxwindow
&& rect
)
3450 myRect
.SetSize(wxSize( m_wxwindow
->allocation
.width
,
3451 m_wxwindow
->allocation
.height
));
3452 if ( myRect
.Intersect(*rect
).IsEmpty() )
3454 // nothing to do, rectangle is empty
3461 // schedule the area for later updating in GtkUpdate()
3462 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
3466 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3470 m_clearRegion
.Clear();
3471 m_clearRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
3479 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3483 GdkRectangle gdk_rect
;
3484 gdk_rect
.x
= rect
->x
;
3485 gdk_rect
.y
= rect
->y
;
3486 gdk_rect
.width
= rect
->width
;
3487 gdk_rect
.height
= rect
->height
;
3488 gtk_widget_draw( m_widget
, &gdk_rect
);
3495 m_updateRegion
.Clear();
3496 m_updateRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
3500 gtk_widget_draw( m_widget
, NULL
);
3505 void wxWindowGTK::Update()
3509 // when we call Update() we really want to update the window immediately on
3510 // screen, even if it means flushing the entire queue and hence slowing down
3511 // everything -- but it should still be done, it's just that Update() should
3512 // be called very rarely
3516 void wxWindowGTK::GtkUpdate()
3518 if (!m_updateRegion
.IsEmpty())
3519 GtkSendPaintEvents();
3521 // for consistency with other platforms (and also because it's convenient
3522 // to be able to update an entire TLW by calling Update() only once), we
3523 // should also update all our children here
3524 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3526 node
= node
->GetNext() )
3528 node
->GetData()->GtkUpdate();
3532 void wxWindowGTK::GtkSendPaintEvents()
3536 m_clearRegion
.Clear();
3537 m_updateRegion
.Clear();
3541 // Clip to paint region in wxClientDC
3542 m_clipPaintRegion
= true;
3544 // widget to draw on
3545 GtkPizza
*pizza
= GTK_PIZZA (m_wxwindow
);
3547 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM
))
3549 // find ancestor from which to steal background
3550 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
3552 parent
= (wxWindow
*)this;
3554 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
3556 wxRegionIterator
upd( m_updateRegion
);
3560 rect
.x
= upd
.GetX();
3561 rect
.y
= upd
.GetY();
3562 rect
.width
= upd
.GetWidth();
3563 rect
.height
= upd
.GetHeight();
3565 gtk_paint_flat_box( parent
->m_widget
->style
,
3567 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
3578 else // Always send an erase event under GTK 1.2
3580 wxWindowDC
dc( (wxWindow
*)this );
3581 dc
.SetDeviceClippingRegion( m_clearRegion
.IsEmpty() ? m_updateRegion
3584 wxEraseEvent
erase_event( GetId(), &dc
);
3585 erase_event
.SetEventObject( this );
3587 if (!HandleWindowEvent(erase_event
) && GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3591 g_eraseGC
= gdk_gc_new( pizza
->bin_window
);
3592 gdk_gc_set_fill( g_eraseGC
, GDK_SOLID
);
3594 gdk_gc_set_foreground( g_eraseGC
, GetBackgroundColour().GetColor() );
3596 wxRegionIterator
upd( m_clearRegion
);
3599 gdk_draw_rectangle( pizza
->bin_window
, g_eraseGC
, 1,
3600 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
3604 m_clearRegion
.Clear();
3607 wxNcPaintEvent
nc_paint_event( GetId() );
3608 nc_paint_event
.SetEventObject( this );
3609 HandleWindowEvent( nc_paint_event
);
3611 wxPaintEvent
paint_event( GetId() );
3612 paint_event
.SetEventObject( this );
3613 HandleWindowEvent( paint_event
);
3615 m_clipPaintRegion
= false;
3617 #if !defined(__WXUNIVERSAL__)
3618 // The following code will result in all window-less widgets
3619 // being redrawn because the wxWidgets class is allowed to
3620 // paint over the window-less widgets.
3622 GList
*children
= pizza
->children
;
3625 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
3626 children
= children
->next
;
3628 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
3629 GTK_WIDGET_DRAWABLE (child
->widget
))
3631 // Get intersection of widget area and update region
3632 wxRegion
region( m_updateRegion
);
3634 GdkEventExpose gdk_event
;
3635 gdk_event
.type
= GDK_EXPOSE
;
3636 gdk_event
.window
= pizza
->bin_window
;
3637 gdk_event
.count
= 0;
3638 gdk_event
.send_event
= TRUE
;
3640 wxRegionIterator
upd( m_updateRegion
);
3644 rect
.x
= upd
.GetX();
3645 rect
.y
= upd
.GetY();
3646 rect
.width
= upd
.GetWidth();
3647 rect
.height
= upd
.GetHeight();
3649 if (gtk_widget_intersect (child
->widget
, &rect
, &gdk_event
.area
))
3651 gtk_widget_event (child
->widget
, (GdkEvent
*) &gdk_event
);
3658 #endif // native GTK 1
3660 m_updateRegion
.Clear();
3663 void wxWindowGTK::ClearBackground()
3665 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3667 if (m_wxwindow
&& m_wxwindow
->window
)
3669 m_clearRegion
.Clear();
3670 wxSize
size( GetClientSize() );
3671 m_clearRegion
.Union( 0,0,size
.x
,size
.y
);
3673 // Better do this in idle?
3679 void wxWindowGTK::DoSetToolTip( wxToolTip
*tip
)
3681 wxWindowBase::DoSetToolTip(tip
);
3684 m_tooltip
->Apply( (wxWindow
*)this );
3687 void wxWindowGTK::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
3689 wxString
tmp( tip
);
3690 gtk_tooltips_set_tip( tips
, GetConnectWidget(), wxGTK_CONV(tmp
), NULL
);
3692 #endif // wxUSE_TOOLTIPS
3694 bool wxWindowGTK::SetBackgroundColour( const wxColour
&colour
)
3696 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3698 if (!wxWindowBase::SetBackgroundColour(colour
))
3703 // We need the pixel value e.g. for background clearing.
3704 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3707 // apply style change (forceStyle=true so that new style is applied
3708 // even if the bg colour changed from valid to wxNullColour)
3709 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
3710 ApplyWidgetStyle(true);
3715 bool wxWindowGTK::SetForegroundColour( const wxColour
&colour
)
3717 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3719 if (!wxWindowBase::SetForegroundColour(colour
))
3726 // We need the pixel value e.g. for background clearing.
3727 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
3730 // apply style change (forceStyle=true so that new style is applied
3731 // even if the bg colour changed from valid to wxNullColour):
3732 ApplyWidgetStyle(true);
3737 GtkRcStyle
*wxWindowGTK::CreateWidgetStyle(bool forceStyle
)
3739 // do we need to apply any changes at all?
3742 !m_foregroundColour
.IsOk() && !m_backgroundColour
.IsOk() )
3747 GtkRcStyle
*style
= gtk_rc_style_new();
3749 if ( m_font
.IsOk() )
3751 wxString xfontname
= m_font
.GetNativeFontInfo()->GetXFontName();
3752 style
->fontset_name
= g_strdup(xfontname
.c_str());
3755 if ( m_foregroundColour
.IsOk() )
3757 GdkColor
*fg
= m_foregroundColour
.GetColor();
3759 style
->fg
[GTK_STATE_NORMAL
] = *fg
;
3760 style
->color_flags
[GTK_STATE_NORMAL
] = GTK_RC_FG
;
3762 style
->fg
[GTK_STATE_PRELIGHT
] = *fg
;
3763 style
->color_flags
[GTK_STATE_PRELIGHT
] = GTK_RC_FG
;
3765 style
->fg
[GTK_STATE_ACTIVE
] = *fg
;
3766 style
->color_flags
[GTK_STATE_ACTIVE
] = GTK_RC_FG
;
3769 if ( m_backgroundColour
.IsOk() )
3771 GdkColor
*bg
= m_backgroundColour
.GetColor();
3773 style
->bg
[GTK_STATE_NORMAL
] = *bg
;
3774 style
->base
[GTK_STATE_NORMAL
] = *bg
;
3775 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)
3776 (style
->color_flags
[GTK_STATE_NORMAL
] | GTK_RC_BG
| GTK_RC_BASE
);
3778 style
->bg
[GTK_STATE_PRELIGHT
] = *bg
;
3779 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
3780 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)
3781 (style
->color_flags
[GTK_STATE_PRELIGHT
] | GTK_RC_BG
| GTK_RC_BASE
);
3783 style
->bg
[GTK_STATE_ACTIVE
] = *bg
;
3784 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
3785 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)
3786 (style
->color_flags
[GTK_STATE_ACTIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3788 style
->bg
[GTK_STATE_INSENSITIVE
] = *bg
;
3789 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
3790 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)
3791 (style
->color_flags
[GTK_STATE_INSENSITIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
3797 void wxWindowGTK::ApplyWidgetStyle(bool forceStyle
)
3799 GtkRcStyle
*style
= CreateWidgetStyle(forceStyle
);
3802 DoApplyWidgetStyle(style
);
3803 gtk_rc_style_unref(style
);
3806 // Style change may affect GTK+'s size calculation:
3807 InvalidateBestSize();
3810 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle
*style
)
3813 gtk_widget_modify_style(m_wxwindow
, style
);
3815 gtk_widget_modify_style(m_widget
, style
);
3818 bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style
)
3820 wxWindowBase::SetBackgroundStyle(style
);
3822 if (style
== wxBG_STYLE_CUSTOM
)
3824 GdkWindow
*window
= NULL
;
3826 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3828 window
= GetConnectWidget()->window
;
3832 // Make sure GDK/X11 doesn't refresh the window
3834 gdk_window_set_back_pixmap( window
, None
, False
);
3836 Display
* display
= GDK_WINDOW_DISPLAY(window
);
3839 m_needsStyleChange
= false;
3842 // Do in OnIdle, because the window is not yet available
3843 m_needsStyleChange
= true;
3845 // Don't apply widget style, or we get a grey background
3849 // apply style change (forceStyle=true so that new style is applied
3850 // even if the bg colour changed from valid to wxNullColour):
3851 ApplyWidgetStyle(true);
3856 #if wxUSE_DRAG_AND_DROP
3858 void wxWindowGTK::SetDropTarget( wxDropTarget
*dropTarget
)
3860 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3862 GtkWidget
*dnd_widget
= GetConnectWidget();
3864 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
3866 if (m_dropTarget
) delete m_dropTarget
;
3867 m_dropTarget
= dropTarget
;
3869 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
3872 #endif // wxUSE_DRAG_AND_DROP
3874 GtkWidget
* wxWindowGTK::GetConnectWidget()
3876 GtkWidget
*connect_widget
= m_widget
;
3877 if (m_wxwindow
) connect_widget
= m_wxwindow
;
3879 return connect_widget
;
3882 bool wxWindowGTK::IsOwnGtkWindow( GdkWindow
*window
)
3885 return (window
== GTK_PIZZA(m_wxwindow
)->bin_window
);
3887 return (window
== m_widget
->window
);
3890 bool wxWindowGTK::SetFont( const wxFont
&font
)
3892 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
3894 if (!wxWindowBase::SetFont(font
))
3897 // apply style change (forceStyle=true so that new style is applied
3898 // even if the font changed from valid to wxNullFont):
3899 ApplyWidgetStyle(true);
3904 void wxWindowGTK::DoCaptureMouse()
3906 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3908 GdkWindow
*window
= NULL
;
3910 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3912 window
= GetConnectWidget()->window
;
3914 wxCHECK_RET( window
, wxT("CaptureMouse() failed") );
3916 const wxCursor
* cursor
= &m_cursor
;
3917 if (!cursor
->IsOk())
3918 cursor
= wxSTANDARD_CURSOR
;
3920 gdk_pointer_grab( window
, FALSE
,
3922 (GDK_BUTTON_PRESS_MASK
|
3923 GDK_BUTTON_RELEASE_MASK
|
3924 GDK_POINTER_MOTION_HINT_MASK
|
3925 GDK_POINTER_MOTION_MASK
),
3927 cursor
->GetCursor(),
3928 (guint32
)GDK_CURRENT_TIME
);
3929 g_captureWindow
= this;
3930 g_captureWindowHasMouse
= true;
3933 void wxWindowGTK::DoReleaseMouse()
3935 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3937 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
3939 g_captureWindow
= NULL
;
3941 GdkWindow
*window
= NULL
;
3943 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3945 window
= GetConnectWidget()->window
;
3950 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
3954 wxWindow
*wxWindowBase::GetCapture()
3956 return (wxWindow
*)g_captureWindow
;
3959 bool wxWindowGTK::IsRetained() const
3964 void wxWindowGTK::SetScrollbar( int orient
, int pos
, int thumbVisible
,
3965 int range
, bool refresh
)
3967 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3969 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
3971 m_hasScrolling
= true;
3973 if (orient
== wxHORIZONTAL
)
3975 float fpos
= (float)pos
;
3976 float frange
= (float)range
;
3977 float fthumb
= (float)thumbVisible
;
3978 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
3979 if (fpos
< 0.0) fpos
= 0.0;
3981 if ((fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
3982 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
3984 SetScrollPos( orient
, pos
, refresh
);
3988 m_oldHorizontalPos
= fpos
;
3990 m_hAdjust
->lower
= 0.0;
3991 m_hAdjust
->upper
= frange
;
3992 m_hAdjust
->value
= fpos
;
3993 m_hAdjust
->step_increment
= 1.0;
3994 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
3995 m_hAdjust
->page_size
= fthumb
;
3999 float fpos
= (float)pos
;
4000 float frange
= (float)range
;
4001 float fthumb
= (float)thumbVisible
;
4002 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
4003 if (fpos
< 0.0) fpos
= 0.0;
4005 if ((fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
4006 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
4008 SetScrollPos( orient
, pos
, refresh
);
4012 m_oldVerticalPos
= fpos
;
4014 m_vAdjust
->lower
= 0.0;
4015 m_vAdjust
->upper
= frange
;
4016 m_vAdjust
->value
= fpos
;
4017 m_vAdjust
->step_increment
= 1.0;
4018 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4019 m_vAdjust
->page_size
= fthumb
;
4022 if (orient
== wxHORIZONTAL
)
4023 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
4025 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
4028 void wxWindowGTK::GtkUpdateScrollbar(int orient
)
4030 GtkAdjustment
*adj
= orient
== wxHORIZONTAL
? m_hAdjust
: m_vAdjust
;
4031 GtkSignalFunc fn
= orient
== wxHORIZONTAL
4032 ? (GtkSignalFunc
)gtk_window_hscroll_callback
4033 : (GtkSignalFunc
)gtk_window_vscroll_callback
;
4035 gtk_signal_disconnect_by_func(GTK_OBJECT(adj
), fn
, (gpointer
)this);
4036 gtk_signal_emit_by_name(GTK_OBJECT(adj
), "value_changed");
4037 gtk_signal_connect(GTK_OBJECT(adj
), "value_changed", fn
, (gpointer
)this);
4040 void wxWindowGTK::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
4042 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4043 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4045 GtkAdjustment
*adj
= orient
== wxHORIZONTAL
? m_hAdjust
: m_vAdjust
;
4047 float fpos
= (float)pos
;
4048 if (fpos
> adj
->upper
- adj
->page_size
)
4049 fpos
= adj
->upper
- adj
->page_size
;
4052 *(orient
== wxHORIZONTAL
? &m_oldHorizontalPos
: &m_oldVerticalPos
) = fpos
;
4054 if (fabs(fpos
-adj
->value
) < 0.2)
4058 if ( m_wxwindow
->window
)
4063 int wxWindowGTK::GetScrollThumb( int orient
) const
4065 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4067 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4069 if (orient
== wxHORIZONTAL
)
4070 return (int)(m_hAdjust
->page_size
+0.5);
4072 return (int)(m_vAdjust
->page_size
+0.5);
4075 int wxWindowGTK::GetScrollPos( int orient
) const
4077 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4079 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4081 if (orient
== wxHORIZONTAL
)
4082 return (int)(m_hAdjust
->value
+0.5);
4084 return (int)(m_vAdjust
->value
+0.5);
4087 int wxWindowGTK::GetScrollRange( int orient
) const
4089 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4091 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4093 if (orient
== wxHORIZONTAL
)
4094 return (int)(m_hAdjust
->upper
+0.5);
4096 return (int)(m_vAdjust
->upper
+0.5);
4099 void wxWindowGTK::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4101 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4103 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4105 // No scrolling requested.
4106 if ((dx
== 0) && (dy
== 0)) return;
4108 if (!m_updateRegion
.IsEmpty())
4110 m_updateRegion
.Offset( dx
, dy
);
4114 GetClientSize( &cw
, &ch
);
4115 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
4118 if (!m_clearRegion
.IsEmpty())
4120 m_clearRegion
.Offset( dx
, dy
);
4124 GetClientSize( &cw
, &ch
);
4125 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
4128 m_clipPaintRegion
= true;
4130 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow
), -dx
, -dy
);
4132 m_clipPaintRegion
= false;
4135 void wxWindowGTK::SetWindowStyleFlag( long style
)
4137 // Updates the internal variable. NB: Now m_windowStyle bits carry the _new_ style values already
4138 wxWindowBase::SetWindowStyleFlag(style
);
4141 // Find the wxWindow at the current mouse position, also returning the mouse
4143 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4145 pt
= wxGetMousePosition();
4146 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4150 // Get the current mouse position.
4151 wxPoint
wxGetMousePosition()
4153 /* This crashes when used within wxHelpContext,
4154 so we have to use the X-specific implementation below.
4156 GdkModifierType *mask;
4157 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4159 return wxPoint(x, y);
4163 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4165 Display
*display
= windowAtPtr
? GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4166 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4167 Window rootReturn
, childReturn
;
4168 int rootX
, rootY
, winX
, winY
;
4169 unsigned int maskReturn
;
4171 XQueryPointer (display
,
4175 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4176 return wxPoint(rootX
, rootY
);
4180 // Needed for implementing e.g. combobox on wxGTK within a modal dialog.
4181 void wxAddGrab(wxWindow
* window
)
4183 gtk_grab_add( (GtkWidget
*) window
->GetHandle() );
4186 void wxRemoveGrab(wxWindow
* window
)
4188 gtk_grab_remove( (GtkWidget
*) window
->GetHandle() );
4191 // ----------------------------------------------------------------------------
4193 // ----------------------------------------------------------------------------
4195 class wxWinModule
: public wxModule
4202 DECLARE_DYNAMIC_CLASS(wxWinModule
)
4205 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
4207 bool wxWinModule::OnInit()
4209 // g_eraseGC = gdk_gc_new( GDK_ROOT_PARENT() );
4210 // gdk_gc_set_fill( g_eraseGC, GDK_SOLID );
4215 void wxWinModule::OnExit()
4218 gdk_gc_unref( g_eraseGC
);
4221 GdkWindow
* wxWindowGTK::GTKGetDrawingWindow() const
4223 GdkWindow
* window
= NULL
;
4225 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;