1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/window.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Julian Smart
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
12 #pragma implementation "window.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
19 #define XWarpPointer XWARPPOINTER
22 #include "wx/window.h"
23 #include "wx/dcclient.h"
26 #include "wx/layout.h"
28 #include "wx/dialog.h"
29 #include "wx/msgdlg.h"
30 #include "wx/module.h"
31 #include "wx/combobox.h"
33 #if wxUSE_DRAG_AND_DROP
38 #include "wx/tooltip.h"
46 #include "wx/textctrl.h"
50 #include "wx/statusbr.h"
52 #include "wx/settings.h"
54 #include "wx/fontutil.h"
57 #include "wx/thread.h"
63 #include "wx/gtk/private.h"
64 #include <gdk/gdkprivate.h>
65 #include <gdk/gdkkeysyms.h>
69 #include <gtk/gtkprivate.h>
71 #include "wx/gtk/win_gtk.h"
74 #include <pango/pangox.h>
85 extern GtkContainerClass
*pizza_parent_class
;
88 //-----------------------------------------------------------------------------
89 // documentation on internals
90 //-----------------------------------------------------------------------------
93 I have been asked several times about writing some documentation about
94 the GTK port of wxWidgets, especially its internal structures. Obviously,
95 you cannot understand wxGTK without knowing a little about the GTK, but
96 some more information about what the wxWindow, which is the base class
97 for all other window classes, does seems required as well.
101 What does wxWindow do? It contains the common interface for the following
102 jobs of its descendants:
104 1) Define the rudimentary behaviour common to all window classes, such as
105 resizing, intercepting user input (so as to make it possible to use these
106 events for special purposes in a derived class), window names etc.
108 2) Provide the possibility to contain and manage children, if the derived
109 class is allowed to contain children, which holds true for those window
110 classes which do not display a native GTK widget. To name them, these
111 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
112 work classes are a special case and are handled a bit differently from
113 the rest. The same holds true for the wxNotebook class.
115 3) Provide the possibility to draw into a client area of a window. This,
116 too, only holds true for classes that do not display a native GTK widget
119 4) Provide the entire mechanism for scrolling widgets. This actual inter-
120 face for this is usually in wxScrolledWindow, but the GTK implementation
123 5) A multitude of helper or extra methods for special purposes, such as
124 Drag'n'Drop, managing validators etc.
126 6) Display a border (sunken, raised, simple or none).
128 Normally one might expect, that one wxWidgets window would always correspond
129 to one GTK widget. Under GTK, there is no such allround widget that has all
130 the functionality. Moreover, the GTK defines a client area as a different
131 widget from the actual widget you are handling. Last but not least some
132 special classes (e.g. wxFrame) handle different categories of widgets and
133 still have the possibility to draw something in the client area.
134 It was therefore required to write a special purpose GTK widget, that would
135 represent a client area in the sense of wxWidgets capable to do the jobs
136 2), 3) and 4). I have written this class and it resides in win_gtk.c of
139 All windows must have a widget, with which they interact with other under-
140 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
141 thw wxWindow class has a member variable called m_widget which holds a
142 pointer to this widget. When the window class represents a GTK native widget,
143 this is (in most cases) the only GTK widget the class manages. E.g. the
144 wxStaticText class handles only a GtkLabel widget a pointer to which you
145 can find in m_widget (defined in wxWindow)
147 When the class has a client area for drawing into and for containing children
148 it has to handle the client area widget (of the type GtkPizza, defined in
149 win_gtk.c), but there could be any number of widgets, handled by a class
150 The common rule for all windows is only, that the widget that interacts with
151 the rest of GTK must be referenced in m_widget and all other widgets must be
152 children of this widget on the GTK level. The top-most widget, which also
153 represents the client area, must be in the m_wxwindow field and must be of
156 As I said, the window classes that display a GTK native widget only have
157 one widget, so in the case of e.g. the wxButton class m_widget holds a
158 pointer to a GtkButton widget. But windows with client areas (for drawing
159 and children) have a m_widget field that is a pointer to a GtkScrolled-
160 Window and a m_wxwindow field that is pointer to a GtkPizza and this
161 one is (in the GTK sense) a child of the GtkScrolledWindow.
163 If the m_wxwindow field is set, then all input to this widget is inter-
164 cepted and sent to the wxWidgets class. If not, all input to the widget
165 that gets pointed to by m_widget gets intercepted and sent to the class.
169 The design of scrolling in wxWidgets is markedly different from that offered
170 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
171 clicking on a scrollbar belonging to scrolled window will inevitably move
172 the window. In wxWidgets, the scrollbar will only emit an event, send this
173 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
174 which actually moves the window and its subchildren. Note that GtkPizza
175 memorizes how much it has been scrolled but that wxWidgets forgets this
176 so that the two coordinates systems have to be kept in synch. This is done
177 in various places using the pizza->xoffset and pizza->yoffset values.
181 Singularily the most broken code in GTK is the code that is supposes to
182 inform subwindows (child windows) about new positions. Very often, duplicate
183 events are sent without changes in size or position, equally often no
184 events are sent at all (All this is due to a bug in the GtkContainer code
185 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
186 GTK's own system and it simply waits for size events for toplevel windows
187 and then iterates down the respective size events to all window. This has
188 the disadvantage, that windows might get size events before the GTK widget
189 actually has the reported size. This doesn't normally pose any problem, but
190 the OpenGl drawing routines rely on correct behaviour. Therefore, I have
191 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
192 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
193 window that is used for OpenGl output really has that size (as reported by
198 If someone at some point of time feels the immense desire to have a look at,
199 change or attempt to optimse the Refresh() logic, this person will need an
200 intimate understanding of what a "draw" and what an "expose" events are and
201 what there are used for, in particular when used in connection with GTK's
202 own windowless widgets. Beware.
206 Cursors, too, have been a constant source of pleasure. The main difficulty
207 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
208 for the parent. To prevent this from doing too much harm, I use idle time
209 to set the cursor over and over again, starting from the toplevel windows
210 and ending with the youngest generation (speaking of parent and child windows).
211 Also don't forget that cursors (like much else) are connected to GdkWindows,
212 not GtkWidgets and that the "window" field of a GtkWidget might very well
213 point to the GdkWindow of the parent widget (-> "window less widget") and
214 that the two obviously have very different meanings.
218 //-----------------------------------------------------------------------------
220 //-----------------------------------------------------------------------------
222 extern wxList wxPendingDelete
;
223 extern bool g_blockEventsOnDrag
;
224 extern bool g_blockEventsOnScroll
;
225 extern wxCursor g_globalCursor
;
227 static GdkGC
*g_eraseGC
= NULL
;
229 // mouse capture state: the window which has it and if the mouse is currently
231 static wxWindowGTK
*g_captureWindow
= (wxWindowGTK
*) NULL
;
232 static bool g_captureWindowHasMouse
= false;
234 wxWindowGTK
*g_focusWindow
= (wxWindowGTK
*) NULL
;
236 // the last window which had the focus - this is normally never NULL (except
237 // if we never had focus at all) as even when g_focusWindow is NULL it still
238 // keeps its previous value
239 wxWindowGTK
*g_focusWindowLast
= (wxWindowGTK
*) NULL
;
241 // If a window get the focus set but has not been realized
242 // yet, defer setting the focus to idle time.
243 wxWindowGTK
*g_delayedFocus
= (wxWindowGTK
*) NULL
;
245 // hack: we need something to pass to gtk_menu_popup, so we store the time of
246 // the last click here
247 static guint32 gs_timeLastClick
= 0;
249 extern bool g_mainThreadLocked
;
251 //-----------------------------------------------------------------------------
253 //-----------------------------------------------------------------------------
258 # define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
260 # define DEBUG_MAIN_THREAD
263 #define DEBUG_MAIN_THREAD
266 // the trace mask used for the focus debugging messages
267 #define TRACE_FOCUS _T("focus")
269 //-----------------------------------------------------------------------------
270 // missing gdk functions
271 //-----------------------------------------------------------------------------
274 gdk_window_warp_pointer (GdkWindow
*window
,
279 GdkWindowPrivate
*priv
;
283 window
= GDK_ROOT_PARENT();
286 if (!GDK_WINDOW_DESTROYED(window
))
288 XWarpPointer (GDK_WINDOW_XDISPLAY(window
),
289 None
, /* not source window -> move from anywhere */
290 GDK_WINDOW_XID(window
), /* dest window */
291 0, 0, 0, 0, /* not source window -> move from anywhere */
295 priv
= (GdkWindowPrivate
*) window
;
297 if (!priv
->destroyed
)
299 XWarpPointer (priv
->xdisplay
,
300 None
, /* not source window -> move from anywhere */
301 priv
->xwindow
, /* dest window */
302 0, 0, 0, 0, /* not source window -> move from anywhere */
308 //-----------------------------------------------------------------------------
310 //-----------------------------------------------------------------------------
312 extern void wxapp_install_idle_handler();
313 extern bool g_isIdle
;
315 //-----------------------------------------------------------------------------
316 // local code (see below)
317 //-----------------------------------------------------------------------------
319 // returns the child of win which currently has focus or NULL if not found
321 // Note: can't be static, needed by textctrl.cpp.
322 wxWindow
*wxFindFocusedChild(wxWindowGTK
*win
)
324 wxWindow
*winFocus
= wxWindowGTK::FindFocus();
326 return (wxWindow
*)NULL
;
328 if ( winFocus
== win
)
329 return (wxWindow
*)win
;
331 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
333 node
= node
->GetNext() )
335 wxWindow
*child
= wxFindFocusedChild(node
->GetData());
340 return (wxWindow
*)NULL
;
343 static void draw_frame( GtkWidget
*widget
, wxWindowGTK
*win
)
345 // wxUniversal widgets draw the borders and scrollbars themselves
346 #ifndef __WXUNIVERSAL__
353 if (win
->m_hasScrolling
)
355 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(widget
);
357 GtkRequisition vscroll_req
;
358 vscroll_req
.width
= 2;
359 vscroll_req
.height
= 2;
360 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
361 (scroll_window
->vscrollbar
, &vscroll_req
);
363 GtkRequisition hscroll_req
;
364 hscroll_req
.width
= 2;
365 hscroll_req
.height
= 2;
366 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
367 (scroll_window
->hscrollbar
, &hscroll_req
);
369 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(widget
) );
371 if (scroll_window
->vscrollbar_visible
)
373 dw
+= vscroll_req
.width
;
374 dw
+= scroll_class
->scrollbar_spacing
;
377 if (scroll_window
->hscrollbar_visible
)
379 dh
+= hscroll_req
.height
;
380 dh
+= scroll_class
->scrollbar_spacing
;
386 if (GTK_WIDGET_NO_WINDOW (widget
))
388 dx
+= widget
->allocation
.x
;
389 dy
+= widget
->allocation
.y
;
392 if (win
->HasFlag(wxRAISED_BORDER
))
394 gtk_draw_shadow( widget
->style
,
399 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
403 if (win
->HasFlag(wxSUNKEN_BORDER
))
405 gtk_draw_shadow( widget
->style
,
410 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
414 if (win
->HasFlag(wxSIMPLE_BORDER
))
417 gc
= gdk_gc_new( widget
->window
);
418 gdk_gc_set_foreground( gc
, &widget
->style
->black
);
419 gdk_draw_rectangle( widget
->window
, gc
, FALSE
,
421 widget
->allocation
.width
-dw
-1, widget
->allocation
.height
-dh
-1 );
425 #endif // __WXUNIVERSAL__
428 //-----------------------------------------------------------------------------
429 // "expose_event" of m_widget
430 //-----------------------------------------------------------------------------
433 static gint
gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxWindowGTK
*win
)
435 if (gdk_event
->count
> 0) return FALSE
;
437 draw_frame( widget
, win
);
441 (* GTK_WIDGET_CLASS (pizza_parent_class
)->expose_event
) (widget
, gdk_event
);
448 //-----------------------------------------------------------------------------
449 // "draw" of m_widget
450 //-----------------------------------------------------------------------------
455 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxWindowGTK
*win
)
457 draw_frame( widget
, win
);
463 //-----------------------------------------------------------------------------
464 // "size_request" of m_widget
465 //-----------------------------------------------------------------------------
467 // make it extern because wxStaticText needs to disconnect this one
469 void wxgtk_window_size_request_callback(GtkWidget
*widget
,
470 GtkRequisition
*requisition
,
474 win
->GetSize( &w
, &h
);
480 requisition
->height
= h
;
481 requisition
->width
= w
;
487 void wxgtk_combo_size_request_callback(GtkWidget
*widget
,
488 GtkRequisition
*requisition
,
491 // This callback is actually hooked into the text entry
492 // of the combo box, not the GtkHBox.
495 win
->GetSize( &w
, &h
);
501 GtkCombo
*gcombo
= GTK_COMBO(win
->m_widget
);
503 GtkRequisition entry_req
;
505 entry_req
.height
= 2;
506 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo
->button
) )->size_request
)
507 (gcombo
->button
, &entry_req
);
509 requisition
->width
= w
- entry_req
.width
;
510 requisition
->height
= entry_req
.height
;
514 //-----------------------------------------------------------------------------
515 // "expose_event" of m_wxwindow
516 //-----------------------------------------------------------------------------
519 static int gtk_window_expose_callback( GtkWidget
*widget
,
520 GdkEventExpose
*gdk_event
,
526 wxapp_install_idle_handler();
529 // This callback gets called in drawing-idle time under
530 // GTK 2.0, so we don't need to defer anything to idle
533 GtkPizza
*pizza
= GTK_PIZZA( widget
);
534 if (gdk_event
->window
!= pizza
->bin_window
) return FALSE
;
539 wxPrintf( wxT("OnExpose from ") );
540 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
541 wxPrintf( win
->GetClassInfo()->GetClassName() );
542 wxPrintf( wxT(" %d %d %d %d\n"), (int)gdk_event
->area
.x
,
543 (int)gdk_event
->area
.y
,
544 (int)gdk_event
->area
.width
,
545 (int)gdk_event
->area
.height
);
550 win
->m_wxwindow
->style
,
554 (GdkRectangle
*) NULL
,
556 (char *)"button", // const_cast
561 win
->GetUpdateRegion() = wxRegion( gdk_event
->region
);
563 win
->GtkSendPaintEvents();
566 // Let parent window draw window less widgets
567 (* GTK_WIDGET_CLASS (pizza_parent_class
)->expose_event
) (widget
, gdk_event
);
569 // This gets called immediately after an expose event
570 // under GTK 1.2 so we collect the calls and wait for
571 // the idle handler to pick things up.
573 win
->GetUpdateRegion().Union( gdk_event
->area
.x
,
575 gdk_event
->area
.width
,
576 gdk_event
->area
.height
);
577 win
->m_clearRegion
.Union( gdk_event
->area
.x
,
579 gdk_event
->area
.width
,
580 gdk_event
->area
.height
);
582 // Actual redrawing takes place in idle time.
590 //-----------------------------------------------------------------------------
591 // "event" of m_wxwindow
592 //-----------------------------------------------------------------------------
596 // GTK thinks it is clever and filters out a certain amount of "unneeded"
597 // expose events. We need them, of course, so we override the main event
598 // procedure in GtkWidget by giving our own handler for all system events.
599 // There, we look for expose events ourselves whereas all other events are
604 gint
gtk_window_event_event_callback( GtkWidget
*widget
,
605 GdkEventExpose
*event
,
608 if (event
->type
== GDK_EXPOSE
)
610 gint ret
= gtk_window_expose_callback( widget
, event
, win
);
620 //-----------------------------------------------------------------------------
621 // "draw" of m_wxwindow
622 //-----------------------------------------------------------------------------
626 // This callback is a complete replacement of the gtk_pizza_draw() function,
627 // which is disabled.
630 static void gtk_window_draw_callback( GtkWidget
*widget
,
637 wxapp_install_idle_handler();
639 // if there are any children we must refresh everything
642 if ( !win
->HasFlag(wxFULL_REPAINT_ON_RESIZE
) &&
643 win
->GetChildren().IsEmpty() )
651 wxPrintf( wxT("OnDraw from ") );
652 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
653 wxPrintf( win
->GetClassInfo()->GetClassName() );
654 wxPrintf( wxT(" %d %d %d %d\n"), (int)rect
->x
,
661 #ifndef __WXUNIVERSAL__
662 GtkPizza
*pizza
= GTK_PIZZA (widget
);
664 if (win
->GetThemeEnabled() && win
->GetBackgroundStyle() == wxBG_STYLE_SYSTEM
)
666 wxWindow
*parent
= win
->GetParent();
667 while (parent
&& !parent
->IsTopLevel())
668 parent
= parent
->GetParent();
672 gtk_paint_flat_box (parent
->m_widget
->style
,
683 win
->m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
684 win
->GetUpdateRegion().Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
686 // Update immediately, not in idle time.
689 #ifndef __WXUNIVERSAL__
690 // Redraw child widgets
691 GList
*children
= pizza
->children
;
694 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
695 children
= children
->next
;
697 GdkRectangle child_area
;
698 if (gtk_widget_intersect (child
->widget
, rect
, &child_area
))
700 gtk_widget_draw (child
->widget
, &child_area
/* (GdkRectangle*) NULL*/ );
709 //-----------------------------------------------------------------------------
710 // "key_press_event" from any window
711 //-----------------------------------------------------------------------------
713 // set WXTRACE to this to see the key event codes on the console
714 #define TRACE_KEYS _T("keyevent")
716 // translates an X key symbol to WXK_XXX value
718 // if isChar is true it means that the value returned will be used for EVT_CHAR
719 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
720 // for example, while if it is false it means that the value is going to be
721 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
723 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
729 // Shift, Control and Alt don't generate the CHAR events at all
732 key_code
= isChar
? 0 : WXK_SHIFT
;
736 key_code
= isChar
? 0 : WXK_CONTROL
;
744 key_code
= isChar
? 0 : WXK_ALT
;
747 // neither do the toggle modifies
748 case GDK_Scroll_Lock
:
749 key_code
= isChar
? 0 : WXK_SCROLL
;
753 key_code
= isChar
? 0 : WXK_CAPITAL
;
757 key_code
= isChar
? 0 : WXK_NUMLOCK
;
761 // various other special keys
774 case GDK_ISO_Left_Tab
:
781 key_code
= WXK_RETURN
;
785 key_code
= WXK_CLEAR
;
789 key_code
= WXK_PAUSE
;
793 key_code
= WXK_SELECT
;
797 key_code
= WXK_PRINT
;
801 key_code
= WXK_EXECUTE
;
805 key_code
= WXK_ESCAPE
;
808 // cursor and other extended keyboard keys
810 key_code
= WXK_DELETE
;
826 key_code
= WXK_RIGHT
;
833 case GDK_Prior
: // == GDK_Page_Up
834 key_code
= WXK_PRIOR
;
837 case GDK_Next
: // == GDK_Page_Down
850 key_code
= WXK_INSERT
;
865 key_code
= (isChar
? '0' : WXK_NUMPAD0
) + keysym
- GDK_KP_0
;
869 key_code
= isChar
? ' ' : WXK_NUMPAD_SPACE
;
873 key_code
= isChar
? WXK_TAB
: WXK_NUMPAD_TAB
;
877 key_code
= isChar
? WXK_RETURN
: WXK_NUMPAD_ENTER
;
881 key_code
= isChar
? WXK_F1
: WXK_NUMPAD_F1
;
885 key_code
= isChar
? WXK_F2
: WXK_NUMPAD_F2
;
889 key_code
= isChar
? WXK_F3
: WXK_NUMPAD_F3
;
893 key_code
= isChar
? WXK_F4
: WXK_NUMPAD_F4
;
897 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_HOME
;
901 key_code
= isChar
? WXK_LEFT
: WXK_NUMPAD_LEFT
;
905 key_code
= isChar
? WXK_UP
: WXK_NUMPAD_UP
;
909 key_code
= isChar
? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
913 key_code
= isChar
? WXK_DOWN
: WXK_NUMPAD_DOWN
;
916 case GDK_KP_Prior
: // == GDK_KP_Page_Up
917 key_code
= isChar
? WXK_PRIOR
: WXK_NUMPAD_PRIOR
;
920 case GDK_KP_Next
: // == GDK_KP_Page_Down
921 key_code
= isChar
? WXK_NEXT
: WXK_NUMPAD_NEXT
;
925 key_code
= isChar
? WXK_END
: WXK_NUMPAD_END
;
929 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_BEGIN
;
933 key_code
= isChar
? WXK_INSERT
: WXK_NUMPAD_INSERT
;
937 key_code
= isChar
? WXK_DELETE
: WXK_NUMPAD_DELETE
;
941 key_code
= isChar
? '=' : WXK_NUMPAD_EQUAL
;
944 case GDK_KP_Multiply
:
945 key_code
= isChar
? '*' : WXK_NUMPAD_MULTIPLY
;
949 key_code
= isChar
? '+' : WXK_NUMPAD_ADD
;
952 case GDK_KP_Separator
:
953 // FIXME: what is this?
954 key_code
= isChar
? '.' : WXK_NUMPAD_SEPARATOR
;
957 case GDK_KP_Subtract
:
958 key_code
= isChar
? '-' : WXK_NUMPAD_SUBTRACT
;
962 key_code
= isChar
? '.' : WXK_NUMPAD_DECIMAL
;
966 key_code
= isChar
? '/' : WXK_NUMPAD_DIVIDE
;
983 key_code
= WXK_F1
+ keysym
- GDK_F1
;
993 static inline bool wxIsAsciiKeysym(KeySym ks
)
998 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
1000 GdkEventKey
*gdk_event
)
1004 GdkModifierType state
;
1005 if (gdk_event
->window
)
1006 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1008 event
.SetTimestamp( gdk_event
->time
);
1009 event
.SetId(win
->GetId());
1010 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
1011 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
1012 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
1013 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
) != 0;
1014 event
.m_scanCode
= gdk_event
->keyval
;
1015 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
1016 event
.m_rawFlags
= 0;
1018 event
.m_uniChar
= gdk_keyval_to_unicode(gdk_event
->keyval
);
1020 wxGetMousePosition( &x
, &y
);
1021 win
->ScreenToClient( &x
, &y
);
1024 event
.SetEventObject( win
);
1029 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
1031 GdkEventKey
*gdk_event
)
1033 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
1034 // but only event->keyval which is quite useless to us, so remember
1035 // the last character from GDK_KEY_PRESS and reuse it as last resort
1037 // NB: should be MT-safe as we're always called from the main thread only
1042 } s_lastKeyPress
= { 0, 0 };
1044 KeySym keysym
= gdk_event
->keyval
;
1046 wxLogTrace(TRACE_KEYS
, _T("Key %s event: keysym = %ld"),
1047 event
.GetEventType() == wxEVT_KEY_UP
? _T("release")
1051 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
1055 // do we have the translation or is it a plain ASCII character?
1056 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
1058 // we should use keysym if it is ASCII as X does some translations
1059 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
1060 // which we don't want here (but which we do use for OnChar())
1061 if ( !wxIsAsciiKeysym(keysym
) )
1063 keysym
= (KeySym
)gdk_event
->string
[0];
1066 // we want to always get the same key code when the same key is
1067 // pressed regardless of the state of the modifies, i.e. on a
1068 // standard US keyboard pressing '5' or '%' ('5' key with
1069 // Shift) should result in the same key code in OnKeyDown():
1070 // '5' (although OnChar() will get either '5' or '%').
1072 // to do it we first translate keysym to keycode (== scan code)
1073 // and then back but always using the lower register
1074 Display
*dpy
= (Display
*)wxGetDisplay();
1075 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
1077 wxLogTrace(TRACE_KEYS
, _T("\t-> keycode %d"), keycode
);
1079 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
1081 // use the normalized, i.e. lower register, keysym if we've
1083 key_code
= keysymNormalized
? keysymNormalized
: keysym
;
1085 // as explained above, we want to have lower register key codes
1086 // normally but for the letter keys we want to have the upper ones
1088 // NB: don't use XConvertCase() here, we want to do it for letters
1090 key_code
= toupper(key_code
);
1092 else // non ASCII key, what to do?
1094 // by default, ignore it
1097 // but if we have cached information from the last KEY_PRESS
1098 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
1101 if ( keysym
== s_lastKeyPress
.keysym
)
1103 key_code
= s_lastKeyPress
.keycode
;
1108 if ( gdk_event
->type
== GDK_KEY_PRESS
)
1110 // remember it to be reused for KEY_UP event later
1111 s_lastKeyPress
.keysym
= keysym
;
1112 s_lastKeyPress
.keycode
= key_code
;
1116 wxLogTrace(TRACE_KEYS
, _T("\t-> wxKeyCode %ld"), key_code
);
1118 // sending unknown key events doesn't really make sense
1122 // now fill all the other fields
1123 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
1125 event
.m_keyCode
= key_code
;
1134 GtkIMContext
*context
;
1135 GdkEventKey
*lastKeyEvent
;
1139 context
= gtk_im_multicontext_new();
1140 lastKeyEvent
= NULL
;
1144 g_object_unref(context
);
1150 static gint
gtk_window_key_press_callback( GtkWidget
*widget
,
1151 GdkEventKey
*gdk_event
,
1157 wxapp_install_idle_handler();
1161 if (g_blockEventsOnDrag
)
1165 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1167 bool return_after_IM
= false;
1169 if( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1171 // Emit KEY_DOWN event
1172 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1176 // Return after IM processing as we cannot do
1177 // anything with it anyhow.
1178 return_after_IM
= true;
1182 // 2005.01.26 modified by Hong Jen Yee (hzysoft@sina.com.tw):
1183 // When we get a key_press event here, it could be originate
1184 // from the current widget or its child widgets. However, only the widget
1185 // with the INPUT FOCUS can generate the INITIAL key_press event. That is,
1186 // if the CURRENT widget doesn't have the FOCUS at all, this event definitely
1187 // originated from its child widgets and shouldn't be passed to IM context.
1188 // In fact, what a GTK+ IM should do is filtering keyEvents and convert them
1189 // into text input ONLY WHEN THE WIDGET HAS INPUT FOCUS. Besides, when current
1190 // widgets has both IM context and input focus, the event should be filtered
1191 // by gtk_im_context_filter_keypress().
1192 // Then, we should, according to GTK+ 2.0 API doc, return whatever it returns.
1193 if ((!ret
) && (win
->m_imData
!= NULL
) && ( wxWindow::FindFocus() == win
))
1195 // We should let GTK+ IM filter key event first. According to GTK+ 2.0 API
1196 // docs, if IM filter returns true, no further processing should be done.
1197 // we should send the key_down event anyway.
1198 bool intercepted_by_IM
= gtk_im_context_filter_keypress(win
->m_imData
->context
, gdk_event
);
1199 win
->m_imData
->lastKeyEvent
= NULL
;
1200 if (intercepted_by_IM
)
1202 wxLogTrace(TRACE_KEYS
, _T("Key event intercepted by IM"));
1207 if (return_after_IM
)
1211 // This is for GTK+ 1.2 only. The char event generatation for GTK+ 2.0 is done
1212 // in the "commit" handler.
1214 // 2005.02.02 modified by Hong Jen Yee (hzysoft@sina.com.tw).
1215 // In GTK+ 1.2, strings sent by IMs are also regarded as key_press events whose
1216 // keyCodes cannot be recognized by wxWidgets. These MBCS strings, however, are
1217 // composed of more than one character, which means gdk_event->length will always
1218 // greater than one. When gtk_event->length == 1, this may be an ASCII character
1219 // and can be translated by wx. However, when MBCS characters are sent by IM,
1220 // gdk_event->length will >= 2. So neither should we pass it to accelerator table,
1221 // nor should we pass it to controls. The following explanation was excerpted
1222 // from GDK documentation.
1223 // gint length : the length of string.
1224 // gchar *string : a null-terminated multi-byte string containing the composed
1225 // characters resulting from the key press. When text is being input, in a GtkEntry
1226 // for example, it is these characters which should be added to the input buffer.
1227 // When using Input Methods to support internationalized text input, the composed
1228 // characters appear here after the pre-editing has been completed.
1230 if ( (!ret
) && (gdk_event
->length
> 1) ) // If this event contains a pre-edited string from IM.
1232 // We should translate this key event into wxEVT_CHAR not wxEVT_KEY_DOWN.
1233 #if wxUSE_UNICODE // GTK+ 1.2 is not UTF-8 based.
1234 const wxWCharBuffer string
= wxConvLocal
.cMB2WC( gdk_event
->string
);
1238 const char* string
= gdk_event
->string
;
1241 // Implement OnCharHook by checking ancesteror top level windows
1242 wxWindow
*parent
= win
;
1243 while (parent
&& !parent
->IsTopLevel())
1244 parent
= parent
->GetParent();
1246 for( const wxChar
* pstr
= string
; *pstr
; pstr
++ )
1249 event
.m_uniChar
= *pstr
;
1250 // Backward compatible for ISO-8859-1
1251 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1253 event
.m_keyCode
= *pstr
;
1257 event
.SetEventType( wxEVT_CHAR_HOOK
);
1258 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1262 event
.SetEventType(wxEVT_CHAR
);
1263 win
->GetEventHandler()->ProcessEvent( event
);
1269 #endif // #ifndef __WXGTK20__
1274 wxWindowGTK
*ancestor
= win
;
1277 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1280 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1281 ret
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1284 if (ancestor
->IsTopLevel())
1286 ancestor
= ancestor
->GetParent();
1289 #endif // wxUSE_ACCEL
1291 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
1292 // will only be sent if it is not in an accelerator table.
1296 KeySym keysym
= gdk_event
->keyval
;
1297 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
1298 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
1301 if ( wxIsAsciiKeysym(keysym
) )
1304 key_code
= (unsigned char)keysym
;
1306 // gdk_event->string is actually deprecated
1307 else if ( gdk_event
->length
== 1 )
1309 key_code
= (unsigned char)gdk_event
->string
[0];
1315 wxLogTrace(TRACE_KEYS
, _T("Char event: %ld"), key_code
);
1317 event
.m_keyCode
= key_code
;
1319 // Implement OnCharHook by checking ancesteror top level windows
1320 wxWindow
*parent
= win
;
1321 while (parent
&& !parent
->IsTopLevel())
1322 parent
= parent
->GetParent();
1325 event
.SetEventType( wxEVT_CHAR_HOOK
);
1326 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1331 event
.SetEventType(wxEVT_CHAR
);
1332 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1341 // win is a control: tab can be propagated up
1343 ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
)) &&
1344 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1345 // have this style, yet choose not to process this particular TAB in which
1346 // case TAB must still work as a navigational character
1347 // JS: enabling again to make consistent with other platforms
1348 // (with wxTE_PROCESS_TAB you have to call Navigate to get default
1349 // navigation behaviour)
1351 (! (win
->HasFlag(wxTE_PROCESS_TAB
) && win
->IsKindOf(CLASSINFO(wxTextCtrl
)) )) &&
1353 win
->GetParent() && (win
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1355 wxNavigationKeyEvent new_event
;
1356 new_event
.SetEventObject( win
->GetParent() );
1357 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
1358 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
1359 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
1360 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
1361 new_event
.SetCurrentFocus( win
);
1362 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent( new_event
);
1365 // generate wxID_CANCEL if <esc> has been pressed (typically in dialogs)
1367 (gdk_event
->keyval
== GDK_Escape
) )
1369 // however only do it if we have a Cancel button in the dialog,
1370 // otherwise the user code may get confused by the events from a
1371 // non-existing button and, worse, a wxButton might get button event
1372 // from another button which is not really expected
1373 wxWindow
*winForCancel
= win
,
1375 while ( winForCancel
)
1377 btnCancel
= winForCancel
->FindWindow(wxID_CANCEL
);
1380 // found a cancel button
1384 if ( winForCancel
->IsTopLevel() )
1386 // no need to look further
1390 // maybe our parent has a cancel button?
1391 winForCancel
= winForCancel
->GetParent();
1396 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
1397 event
.SetEventObject(btnCancel
);
1398 ret
= btnCancel
->GetEventHandler()->ProcessEvent(event
);
1404 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
1414 static void gtk_wxwindow_commit_cb (GtkIMContext
*context
,
1418 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1420 // take modifiers, cursor position, timestamp etc. from the last
1421 // key_press_event that was fed into Input Method:
1422 if (window
->m_imData
->lastKeyEvent
)
1424 wxFillOtherKeyEventFields(event
,
1425 window
, window
->m_imData
->lastKeyEvent
);
1429 const wxWCharBuffer data
= wxConvUTF8
.cMB2WC( (char*)str
);
1431 const wxWCharBuffer wdata
= wxConvUTF8
.cMB2WC( (char*)str
);
1432 const wxCharBuffer data
= wxConvLocal
.cWC2MB( wdata
);
1433 #endif // wxUSE_UNICODE
1434 if( !(const wxChar
*)data
)
1439 // Implement OnCharHook by checking ancestor top level windows
1440 wxWindow
*parent
= window
;
1441 while (parent
&& !parent
->IsTopLevel())
1442 parent
= parent
->GetParent();
1444 for( const wxChar
* pstr
= data
; *pstr
; pstr
++ )
1447 event
.m_uniChar
= *pstr
;
1448 // Backward compatible for ISO-8859-1
1449 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1450 wxLogTrace(TRACE_KEYS
, _T("IM sent character '%c'"), event
.m_uniChar
);
1452 event
.m_keyCode
= *pstr
;
1453 #endif // wxUSE_UNICODE
1456 event
.SetEventType( wxEVT_CHAR_HOOK
);
1457 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1462 event
.SetEventType(wxEVT_CHAR
);
1463 ret
= window
->GetEventHandler()->ProcessEvent( event
);
1471 //-----------------------------------------------------------------------------
1472 // "key_release_event" from any window
1473 //-----------------------------------------------------------------------------
1476 static gint
gtk_window_key_release_callback( GtkWidget
*widget
,
1477 GdkEventKey
*gdk_event
,
1483 wxapp_install_idle_handler();
1488 if (g_blockEventsOnDrag
)
1491 wxKeyEvent
event( wxEVT_KEY_UP
);
1492 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1494 // unknown key pressed, ignore (the event would be useless anyhow
1498 if ( !win
->GetEventHandler()->ProcessEvent( event
) )
1501 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_release_event" );
1506 // ============================================================================
1508 // ============================================================================
1510 // ----------------------------------------------------------------------------
1511 // mouse event processing helpers
1512 // ----------------------------------------------------------------------------
1514 // init wxMouseEvent with the info from GdkEventXXX struct
1515 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1516 wxMouseEvent
& event
,
1519 event
.SetTimestamp( gdk_event
->time
);
1520 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1521 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1522 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1523 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1524 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1525 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1526 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1527 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
1529 event
.m_linesPerAction
= 3;
1530 event
.m_wheelDelta
= 120;
1531 if (((GdkEventButton
*)gdk_event
)->button
== 4)
1532 event
.m_wheelRotation
= 120;
1533 else if (((GdkEventButton
*)gdk_event
)->button
== 5)
1534 event
.m_wheelRotation
= -120;
1537 wxPoint pt
= win
->GetClientAreaOrigin();
1538 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1539 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1541 event
.SetEventObject( win
);
1542 event
.SetId( win
->GetId() );
1543 event
.SetTimestamp( gdk_event
->time
);
1546 static void AdjustEventButtonState(wxMouseEvent
& event
)
1548 // GDK reports the old state of the button for a button press event, but
1549 // for compatibility with MSW and common sense we want m_leftDown be TRUE
1550 // for a LEFT_DOWN event, not FALSE, so we will invert
1551 // left/right/middleDown for the corresponding click events
1553 if ((event
.GetEventType() == wxEVT_LEFT_DOWN
) ||
1554 (event
.GetEventType() == wxEVT_LEFT_DCLICK
) ||
1555 (event
.GetEventType() == wxEVT_LEFT_UP
))
1557 event
.m_leftDown
= !event
.m_leftDown
;
1561 if ((event
.GetEventType() == wxEVT_MIDDLE_DOWN
) ||
1562 (event
.GetEventType() == wxEVT_MIDDLE_DCLICK
) ||
1563 (event
.GetEventType() == wxEVT_MIDDLE_UP
))
1565 event
.m_middleDown
= !event
.m_middleDown
;
1569 if ((event
.GetEventType() == wxEVT_RIGHT_DOWN
) ||
1570 (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) ||
1571 (event
.GetEventType() == wxEVT_RIGHT_UP
))
1573 event
.m_rightDown
= !event
.m_rightDown
;
1578 // find the window to send the mouse event too
1580 wxWindowGTK
*FindWindowForMouseEvent(wxWindowGTK
*win
, wxCoord
& x
, wxCoord
& y
)
1585 if (win
->m_wxwindow
)
1587 GtkPizza
*pizza
= GTK_PIZZA(win
->m_wxwindow
);
1588 xx
+= pizza
->xoffset
;
1589 yy
+= pizza
->yoffset
;
1592 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
1595 wxWindowGTK
*child
= node
->GetData();
1597 node
= node
->GetNext();
1598 if (!child
->IsShown())
1601 if (child
->IsTransparentForMouse())
1603 // wxStaticBox is transparent in the box itself
1604 int xx1
= child
->m_x
;
1605 int yy1
= child
->m_y
;
1606 int xx2
= child
->m_x
+ child
->m_width
;
1607 int yy2
= child
->m_y
+ child
->m_height
;
1610 if (((xx
>= xx1
) && (xx
<= xx1
+10) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1612 ((xx
>= xx2
-10) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1614 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy1
+10)) ||
1616 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy2
-1) && (yy
<= yy2
)))
1627 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1628 (child
->m_x
<= xx
) &&
1629 (child
->m_y
<= yy
) &&
1630 (child
->m_x
+child
->m_width
>= xx
) &&
1631 (child
->m_y
+child
->m_height
>= yy
))
1644 //-----------------------------------------------------------------------------
1645 // "button_press_event"
1646 //-----------------------------------------------------------------------------
1649 static gint
gtk_window_button_press_callback( GtkWidget
*widget
,
1650 GdkEventButton
*gdk_event
,
1656 wxapp_install_idle_handler();
1659 wxPrintf( wxT("1) OnButtonPress from ") );
1660 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1661 wxPrintf( win->GetClassInfo()->GetClassName() );
1662 wxPrintf( wxT(".\n") );
1664 if (!win
->m_hasVMT
) return FALSE
;
1665 if (g_blockEventsOnDrag
) return TRUE
;
1666 if (g_blockEventsOnScroll
) return TRUE
;
1668 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1670 if (win
->m_wxwindow
&& (g_focusWindow
!= win
) && win
->AcceptsFocus())
1672 gtk_widget_grab_focus( win
->m_wxwindow
);
1674 wxPrintf( wxT("GrabFocus from ") );
1675 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1676 wxPrintf( win->GetClassInfo()->GetClassName() );
1677 wxPrintf( wxT(".\n") );
1681 // GDK sends surplus button down event
1682 // before a double click event. We
1683 // need to filter these out.
1684 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1686 GdkEvent
*peek_event
= gdk_event_peek();
1689 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1690 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1692 gdk_event_free( peek_event
);
1697 gdk_event_free( peek_event
);
1702 wxEventType event_type
= wxEVT_NULL
;
1704 // GdkDisplay is a GTK+ 2.2.0 thing
1705 #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2, 2, 0)
1706 if ( gdk_event
->type
== GDK_2BUTTON_PRESS
&&
1707 !gtk_check_version(2,2,0) &&
1708 gdk_event
->button
>= 1 && gdk_event
->button
<= 3 )
1710 // Reset GDK internal timestamp variables in order to disable GDK
1711 // triple click events. GDK will then next time believe no button has
1712 // been clicked just before, and send a normal button click event.
1713 GdkDisplay
* display
= gtk_widget_get_display (widget
);
1714 display
->button_click_time
[1] = 0;
1715 display
->button_click_time
[0] = 0;
1719 if (gdk_event
->button
== 1)
1721 // note that GDK generates triple click events which are not supported
1722 // by wxWidgets but still have to be passed to the app as otherwise
1723 // clicks would simply go missing
1724 switch (gdk_event
->type
)
1726 // we shouldn't get triple clicks at all for GTK2 because we
1727 // suppress them artificially using the code above but we still
1728 // should map them to something for GTK1 and not just ignore them
1729 // as this would lose clicks
1730 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1731 case GDK_BUTTON_PRESS
:
1732 event_type
= wxEVT_LEFT_DOWN
;
1735 case GDK_2BUTTON_PRESS
:
1736 event_type
= wxEVT_LEFT_DCLICK
;
1740 // just to silence gcc warnings
1744 else if (gdk_event
->button
== 2)
1746 switch (gdk_event
->type
)
1748 case GDK_3BUTTON_PRESS
:
1749 case GDK_BUTTON_PRESS
:
1750 event_type
= wxEVT_MIDDLE_DOWN
;
1753 case GDK_2BUTTON_PRESS
:
1754 event_type
= wxEVT_MIDDLE_DCLICK
;
1761 else if (gdk_event
->button
== 3)
1763 switch (gdk_event
->type
)
1765 case GDK_3BUTTON_PRESS
:
1766 case GDK_BUTTON_PRESS
:
1767 event_type
= wxEVT_RIGHT_DOWN
;
1770 case GDK_2BUTTON_PRESS
:
1771 event_type
= wxEVT_RIGHT_DCLICK
;
1778 else if (gdk_event
->button
== 4 || gdk_event
->button
== 5)
1780 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1782 event_type
= wxEVT_MOUSEWHEEL
;
1786 if ( event_type
== wxEVT_NULL
)
1788 // unknown mouse button or click type
1792 wxMouseEvent
event( event_type
);
1793 InitMouseEvent( win
, event
, gdk_event
);
1795 AdjustEventButtonState(event
);
1797 // wxListBox actually get mouse events from the item, so we need to give it
1798 // a chance to correct this
1799 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1801 // find the correct window to send the event too: it may be a different one
1802 // from the one which got it at GTK+ level because some control don't have
1803 // their own X window and thus cannot get any events.
1804 if ( !g_captureWindow
)
1805 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1807 gs_timeLastClick
= gdk_event
->time
;
1810 if (event_type
== wxEVT_LEFT_DCLICK
)
1812 // GTK 1.2 crashes when intercepting double
1813 // click events from both wxSpinButton and
1815 if (GTK_IS_SPIN_BUTTON(win
->m_widget
))
1817 // Just disable this event for now.
1823 if (win
->GetEventHandler()->ProcessEvent( event
))
1825 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_press_event" );
1829 if (event_type
== wxEVT_RIGHT_DOWN
)
1831 // generate a "context menu" event: this is similar to right mouse
1832 // click under many GUIs except that it is generated differently
1833 // (right up under MSW, ctrl-click under Mac, right down here) and
1835 // (a) it's a command event and so is propagated to the parent
1836 // (b) under some ports it can be generated from kbd too
1837 // (c) it uses screen coords (because of (a))
1838 wxContextMenuEvent
evtCtx(
1841 win
->ClientToScreen(event
.GetPosition()));
1842 evtCtx
.SetEventObject(win
);
1843 return win
->GetEventHandler()->ProcessEvent(evtCtx
);
1850 //-----------------------------------------------------------------------------
1851 // "button_release_event"
1852 //-----------------------------------------------------------------------------
1855 static gint
gtk_window_button_release_callback( GtkWidget
*widget
,
1856 GdkEventButton
*gdk_event
,
1862 wxapp_install_idle_handler();
1864 if (!win
->m_hasVMT
) return FALSE
;
1865 if (g_blockEventsOnDrag
) return FALSE
;
1866 if (g_blockEventsOnScroll
) return FALSE
;
1868 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1870 wxEventType event_type
= wxEVT_NULL
;
1872 switch (gdk_event
->button
)
1875 event_type
= wxEVT_LEFT_UP
;
1879 event_type
= wxEVT_MIDDLE_UP
;
1883 event_type
= wxEVT_RIGHT_UP
;
1887 // unknwon button, don't process
1891 wxMouseEvent
event( event_type
);
1892 InitMouseEvent( win
, event
, gdk_event
);
1894 AdjustEventButtonState(event
);
1896 // same wxListBox hack as above
1897 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1899 if ( !g_captureWindow
)
1900 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1902 if (win
->GetEventHandler()->ProcessEvent( event
))
1904 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_release_event" );
1912 //-----------------------------------------------------------------------------
1913 // "motion_notify_event"
1914 //-----------------------------------------------------------------------------
1917 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
,
1918 GdkEventMotion
*gdk_event
,
1924 wxapp_install_idle_handler();
1926 if (!win
->m_hasVMT
) return FALSE
;
1927 if (g_blockEventsOnDrag
) return FALSE
;
1928 if (g_blockEventsOnScroll
) return FALSE
;
1930 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1932 if (gdk_event
->is_hint
)
1936 GdkModifierType state
;
1937 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1943 printf( "OnMotion from " );
1944 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1945 printf( win->GetClassInfo()->GetClassName() );
1949 wxMouseEvent
event( wxEVT_MOTION
);
1950 InitMouseEvent(win
, event
, gdk_event
);
1952 if ( g_captureWindow
)
1954 // synthetize a mouse enter or leave event if needed
1955 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1956 // This seems to be necessary and actually been added to
1957 // GDK itself in version 2.0.X
1960 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1961 if ( hasMouse
!= g_captureWindowHasMouse
)
1963 // the mouse changed window
1964 g_captureWindowHasMouse
= hasMouse
;
1966 wxMouseEvent
event(g_captureWindowHasMouse
? wxEVT_ENTER_WINDOW
1967 : wxEVT_LEAVE_WINDOW
);
1968 InitMouseEvent(win
, event
, gdk_event
);
1969 event
.SetEventObject(win
);
1970 win
->GetEventHandler()->ProcessEvent(event
);
1975 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1978 if (win
->GetEventHandler()->ProcessEvent( event
))
1980 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "motion_notify_event" );
1989 //-----------------------------------------------------------------------------
1990 // "mouse_wheel_event"
1991 //-----------------------------------------------------------------------------
1994 static gint
gtk_window_wheel_callback (GtkWidget
* widget
,
1995 GdkEventScroll
* gdk_event
,
2001 wxapp_install_idle_handler();
2003 wxEventType event_type
= wxEVT_NULL
;
2004 if (gdk_event
->direction
== GDK_SCROLL_UP
)
2005 event_type
= wxEVT_MOUSEWHEEL
;
2006 else if (gdk_event
->direction
== GDK_SCROLL_DOWN
)
2007 event_type
= wxEVT_MOUSEWHEEL
;
2011 wxMouseEvent
event( event_type
);
2012 // Can't use InitMouse macro because scroll events don't have button
2013 event
.SetTimestamp( gdk_event
->time
);
2014 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
2015 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
2016 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
2017 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
2018 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
2019 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
2020 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
2021 event
.m_linesPerAction
= 3;
2022 event
.m_wheelDelta
= 120;
2023 if (gdk_event
->direction
== GDK_SCROLL_UP
)
2024 event
.m_wheelRotation
= 120;
2026 event
.m_wheelRotation
= -120;
2028 wxPoint pt
= win
->GetClientAreaOrigin();
2029 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
2030 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
2032 event
.SetEventObject( win
);
2033 event
.SetId( win
->GetId() );
2034 event
.SetTimestamp( gdk_event
->time
);
2036 if (win
->GetEventHandler()->ProcessEvent( event
))
2038 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "scroll_event" );
2046 //-----------------------------------------------------------------------------
2048 //-----------------------------------------------------------------------------
2050 static gboolean
wxgtk_window_popup_menu_callback(GtkWidget
*, wxWindowGTK
* win
)
2052 wxContextMenuEvent
event(
2056 event
.SetEventObject(win
);
2057 return win
->GetEventHandler()->ProcessEvent(event
);
2060 #endif // __WXGTK20__
2062 //-----------------------------------------------------------------------------
2064 //-----------------------------------------------------------------------------
2066 // send the wxChildFocusEvent and wxFocusEvent, common code of
2067 // gtk_window_focus_in_callback() and SetFocus()
2068 static bool DoSendFocusEvents(wxWindow
*win
)
2070 // Notify the parent keeping track of focus for the kbd navigation
2071 // purposes that we got it.
2072 wxChildFocusEvent
eventChildFocus(win
);
2073 (void)win
->GetEventHandler()->ProcessEvent(eventChildFocus
);
2075 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, win
->GetId());
2076 eventFocus
.SetEventObject(win
);
2078 return win
->GetEventHandler()->ProcessEvent(eventFocus
);
2082 static gint
gtk_window_focus_in_callback( GtkWidget
*widget
,
2083 GdkEvent
*WXUNUSED(event
),
2089 wxapp_install_idle_handler();
2093 gtk_im_context_focus_in(win
->m_imData
->context
);
2097 g_focusWindow
= win
;
2099 wxLogTrace(TRACE_FOCUS
,
2100 _T("%s: focus in"), win
->GetName().c_str());
2104 gdk_im_begin(win
->m_ic
, win
->m_wxwindow
->window
);
2108 // caret needs to be informed about focus change
2109 wxCaret
*caret
= win
->GetCaret();
2112 caret
->OnSetFocus();
2114 #endif // wxUSE_CARET
2116 // does the window itself think that it has the focus?
2117 if ( !win
->m_hasFocus
)
2119 // not yet, notify it
2120 win
->m_hasFocus
= true;
2122 if ( DoSendFocusEvents(win
) )
2124 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_in_event" );
2133 //-----------------------------------------------------------------------------
2134 // "focus_out_event"
2135 //-----------------------------------------------------------------------------
2138 static gint
gtk_window_focus_out_callback( GtkWidget
*widget
, GdkEventFocus
*gdk_event
, wxWindowGTK
*win
)
2143 wxapp_install_idle_handler();
2147 gtk_im_context_focus_out(win
->m_imData
->context
);
2150 wxLogTrace( TRACE_FOCUS
,
2151 _T("%s: focus out"), win
->GetName().c_str() );
2154 wxWindowGTK
*winFocus
= wxFindFocusedChild(win
);
2158 g_focusWindow
= (wxWindowGTK
*)NULL
;
2166 // caret needs to be informed about focus change
2167 wxCaret
*caret
= win
->GetCaret();
2170 caret
->OnKillFocus();
2172 #endif // wxUSE_CARET
2174 // don't send the window a kill focus event if it thinks that it doesn't
2175 // have focus already
2176 if ( win
->m_hasFocus
)
2178 win
->m_hasFocus
= false;
2180 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
2181 event
.SetEventObject( win
);
2183 // even if we did process the event in wx code, still let GTK itself
2184 // process it too as otherwise bad things happen, especially in GTK2
2185 // where the text control simply aborts the program if it doesn't get
2186 // the matching focus out event
2187 (void)win
->GetEventHandler()->ProcessEvent( event
);
2194 //-----------------------------------------------------------------------------
2195 // "enter_notify_event"
2196 //-----------------------------------------------------------------------------
2200 gint
gtk_window_enter_callback( GtkWidget
*widget
,
2201 GdkEventCrossing
*gdk_event
,
2207 wxapp_install_idle_handler();
2209 if (!win
->m_hasVMT
) return FALSE
;
2210 if (g_blockEventsOnDrag
) return FALSE
;
2212 // Event was emitted after a grab
2213 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
2215 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
2219 GdkModifierType state
= (GdkModifierType
)0;
2221 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
2223 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
2224 InitMouseEvent(win
, event
, gdk_event
);
2225 wxPoint pt
= win
->GetClientAreaOrigin();
2226 event
.m_x
= x
+ pt
.x
;
2227 event
.m_y
= y
+ pt
.y
;
2229 if (win
->GetEventHandler()->ProcessEvent( event
))
2231 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "enter_notify_event" );
2239 //-----------------------------------------------------------------------------
2240 // "leave_notify_event"
2241 //-----------------------------------------------------------------------------
2244 static gint
gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindowGTK
*win
)
2249 wxapp_install_idle_handler();
2251 if (!win
->m_hasVMT
) return FALSE
;
2252 if (g_blockEventsOnDrag
) return FALSE
;
2254 // Event was emitted after an ungrab
2255 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
2257 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
2259 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
2260 event
.SetTimestamp( gdk_event
->time
);
2261 event
.SetEventObject( win
);
2265 GdkModifierType state
= (GdkModifierType
)0;
2267 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
2269 event
.m_shiftDown
= (state
& GDK_SHIFT_MASK
) != 0;
2270 event
.m_controlDown
= (state
& GDK_CONTROL_MASK
) != 0;
2271 event
.m_altDown
= (state
& GDK_MOD1_MASK
) != 0;
2272 event
.m_metaDown
= (state
& GDK_MOD2_MASK
) != 0;
2273 event
.m_leftDown
= (state
& GDK_BUTTON1_MASK
) != 0;
2274 event
.m_middleDown
= (state
& GDK_BUTTON2_MASK
) != 0;
2275 event
.m_rightDown
= (state
& GDK_BUTTON3_MASK
) != 0;
2277 wxPoint pt
= win
->GetClientAreaOrigin();
2278 event
.m_x
= x
+ pt
.x
;
2279 event
.m_y
= y
+ pt
.y
;
2281 if (win
->GetEventHandler()->ProcessEvent( event
))
2283 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "leave_notify_event" );
2291 //-----------------------------------------------------------------------------
2292 // "value_changed" from m_vAdjust
2293 //-----------------------------------------------------------------------------
2296 static void gtk_window_vscroll_callback( GtkAdjustment
*adjust
,
2303 wxapp_install_idle_handler();
2305 if (g_blockEventsOnDrag
) return;
2307 if (!win
->m_hasVMT
) return;
2309 float diff
= adjust
->value
- win
->m_oldVerticalPos
;
2310 if (fabs(diff
) < 0.2) return;
2312 win
->m_oldVerticalPos
= adjust
->value
;
2315 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2317 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->vscrollbar
));
2319 int value
= (int)(adjust
->value
+0.5);
2321 wxScrollWinEvent
event( command
, value
, wxVERTICAL
);
2322 event
.SetEventObject( win
);
2323 win
->GetEventHandler()->ProcessEvent( event
);
2327 //-----------------------------------------------------------------------------
2328 // "value_changed" from m_hAdjust
2329 //-----------------------------------------------------------------------------
2332 static void gtk_window_hscroll_callback( GtkAdjustment
*adjust
,
2339 wxapp_install_idle_handler();
2341 if (g_blockEventsOnDrag
) return;
2342 if (!win
->m_hasVMT
) return;
2344 float diff
= adjust
->value
- win
->m_oldHorizontalPos
;
2345 if (fabs(diff
) < 0.2) return;
2348 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2350 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->hscrollbar
));
2352 win
->m_oldHorizontalPos
= adjust
->value
;
2354 int value
= (int)(adjust
->value
+0.5);
2356 wxScrollWinEvent
event( command
, value
, wxHORIZONTAL
);
2357 event
.SetEventObject( win
);
2358 win
->GetEventHandler()->ProcessEvent( event
);
2362 //-----------------------------------------------------------------------------
2363 // "button_press_event" from scrollbar
2364 //-----------------------------------------------------------------------------
2367 static gint
gtk_scrollbar_button_press_callback( GtkRange
*widget
,
2368 GdkEventButton
*gdk_event
,
2374 wxapp_install_idle_handler();
2377 g_blockEventsOnScroll
= true;
2379 // FIXME: there is no 'slider' field in GTK+ 2.0 any more
2381 win
->m_isScrolling
= (gdk_event
->window
== widget
->slider
);
2388 //-----------------------------------------------------------------------------
2389 // "button_release_event" from scrollbar
2390 //-----------------------------------------------------------------------------
2393 static gint
gtk_scrollbar_button_release_callback( GtkRange
*widget
,
2394 GdkEventButton
*WXUNUSED(gdk_event
),
2399 // don't test here as we can release the mouse while being over
2400 // a different window than the slider
2402 // if (gdk_event->window != widget->slider) return FALSE;
2404 g_blockEventsOnScroll
= false;
2406 if (win
->m_isScrolling
)
2408 wxEventType command
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2412 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2413 if (widget
== GTK_RANGE(scrolledWindow
->hscrollbar
))
2415 value
= (int)(win
->m_hAdjust
->value
+0.5);
2418 if (widget
== GTK_RANGE(scrolledWindow
->vscrollbar
))
2420 value
= (int)(win
->m_vAdjust
->value
+0.5);
2424 wxScrollWinEvent
event( command
, value
, dir
);
2425 event
.SetEventObject( win
);
2426 win
->GetEventHandler()->ProcessEvent( event
);
2429 win
->m_isScrolling
= false;
2435 // ----------------------------------------------------------------------------
2436 // this wxWindowBase function is implemented here (in platform-specific file)
2437 // because it is static and so couldn't be made virtual
2438 // ----------------------------------------------------------------------------
2440 wxWindow
*wxWindowBase::DoFindFocus()
2442 // the cast is necessary when we compile in wxUniversal mode
2443 return (wxWindow
*)g_focusWindow
;
2446 //-----------------------------------------------------------------------------
2447 // "realize" from m_widget
2448 //-----------------------------------------------------------------------------
2450 /* We cannot set colours and fonts before the widget has
2451 been realized, so we do this directly after realization. */
2455 gtk_window_realized_callback( GtkWidget
*m_widget
, wxWindow
*win
)
2460 wxapp_install_idle_handler();
2465 GtkPizza
*pizza
= GTK_PIZZA( m_widget
);
2466 gtk_im_context_set_client_window( win
->m_imData
->context
,
2467 pizza
->bin_window
);
2471 wxWindowCreateEvent
event( win
);
2472 event
.SetEventObject( win
);
2473 win
->GetEventHandler()->ProcessEvent( event
);
2479 //-----------------------------------------------------------------------------
2481 //-----------------------------------------------------------------------------
2485 void gtk_window_size_callback( GtkWidget
*WXUNUSED(widget
),
2486 GtkAllocation
*WXUNUSED(alloc
),
2490 wxapp_install_idle_handler();
2492 if (!win
->m_hasScrolling
) return;
2494 int client_width
= 0;
2495 int client_height
= 0;
2496 win
->GetClientSize( &client_width
, &client_height
);
2497 if ((client_width
== win
->m_oldClientWidth
) && (client_height
== win
->m_oldClientHeight
))
2500 win
->m_oldClientWidth
= client_width
;
2501 win
->m_oldClientHeight
= client_height
;
2503 if (!win
->m_nativeSizeEvent
)
2505 wxSizeEvent
event( win
->GetSize(), win
->GetId() );
2506 event
.SetEventObject( win
);
2507 win
->GetEventHandler()->ProcessEvent( event
);
2514 #define WXUNUSED_UNLESS_XIM(param) param
2516 #define WXUNUSED_UNLESS_XIM(param) WXUNUSED(param)
2519 /* Resize XIM window */
2523 void gtk_wxwindow_size_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2524 GtkAllocation
* WXUNUSED_UNLESS_XIM(alloc
),
2525 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2528 wxapp_install_idle_handler();
2534 if (gdk_ic_get_style (win
->m_ic
) & GDK_IM_PREEDIT_POSITION
)
2538 gdk_window_get_size (widget
->window
, &width
, &height
);
2539 win
->m_icattr
->preedit_area
.width
= width
;
2540 win
->m_icattr
->preedit_area
.height
= height
;
2541 gdk_ic_set_attr (win
->m_ic
, win
->m_icattr
, GDK_IC_PREEDIT_AREA
);
2547 //-----------------------------------------------------------------------------
2548 // "realize" from m_wxwindow
2549 //-----------------------------------------------------------------------------
2551 /* Initialize XIM support */
2555 gtk_wxwindow_realized_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2556 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2559 wxapp_install_idle_handler();
2562 if (win
->m_ic
) return FALSE
;
2563 if (!widget
) return FALSE
;
2564 if (!gdk_im_ready()) return FALSE
;
2566 win
->m_icattr
= gdk_ic_attr_new();
2567 if (!win
->m_icattr
) return FALSE
;
2571 GdkColormap
*colormap
;
2572 GdkICAttr
*attr
= win
->m_icattr
;
2573 unsigned attrmask
= GDK_IC_ALL_REQ
;
2575 GdkIMStyle supported_style
= (GdkIMStyle
)
2576 (GDK_IM_PREEDIT_NONE
|
2577 GDK_IM_PREEDIT_NOTHING
|
2578 GDK_IM_PREEDIT_POSITION
|
2579 GDK_IM_STATUS_NONE
|
2580 GDK_IM_STATUS_NOTHING
);
2582 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2583 supported_style
= (GdkIMStyle
)(supported_style
& ~GDK_IM_PREEDIT_POSITION
);
2585 attr
->style
= style
= gdk_im_decide_style (supported_style
);
2586 attr
->client_window
= widget
->window
;
2588 if ((colormap
= gtk_widget_get_colormap (widget
)) !=
2589 gtk_widget_get_default_colormap ())
2591 attrmask
|= GDK_IC_PREEDIT_COLORMAP
;
2592 attr
->preedit_colormap
= colormap
;
2595 attrmask
|= GDK_IC_PREEDIT_FOREGROUND
;
2596 attrmask
|= GDK_IC_PREEDIT_BACKGROUND
;
2597 attr
->preedit_foreground
= widget
->style
->fg
[GTK_STATE_NORMAL
];
2598 attr
->preedit_background
= widget
->style
->base
[GTK_STATE_NORMAL
];
2600 switch (style
& GDK_IM_PREEDIT_MASK
)
2602 case GDK_IM_PREEDIT_POSITION
:
2603 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2605 g_warning ("over-the-spot style requires fontset");
2609 gdk_window_get_size (widget
->window
, &width
, &height
);
2611 attrmask
|= GDK_IC_PREEDIT_POSITION_REQ
;
2612 attr
->spot_location
.x
= 0;
2613 attr
->spot_location
.y
= height
;
2614 attr
->preedit_area
.x
= 0;
2615 attr
->preedit_area
.y
= 0;
2616 attr
->preedit_area
.width
= width
;
2617 attr
->preedit_area
.height
= height
;
2618 attr
->preedit_fontset
= widget
->style
->font
;
2623 win
->m_ic
= gdk_ic_new (attr
, (GdkICAttributesType
)attrmask
);
2625 if (win
->m_ic
== NULL
)
2626 g_warning ("Can't create input context.");
2629 mask
= gdk_window_get_events (widget
->window
);
2630 mask
= (GdkEventMask
)(mask
| gdk_ic_get_events (win
->m_ic
));
2631 gdk_window_set_events (widget
->window
, mask
);
2633 if (GTK_WIDGET_HAS_FOCUS(widget
))
2634 gdk_im_begin (win
->m_ic
, widget
->window
);
2642 //-----------------------------------------------------------------------------
2643 // InsertChild for wxWindowGTK.
2644 //-----------------------------------------------------------------------------
2646 /* Callback for wxWindowGTK. This very strange beast has to be used because
2647 * C++ has no virtual methods in a constructor. We have to emulate a
2648 * virtual function here as wxNotebook requires a different way to insert
2649 * a child in it. I had opted for creating a wxNotebookPage window class
2650 * which would have made this superfluous (such in the MDI window system),
2651 * but no-one was listening to me... */
2653 static void wxInsertChildInWindow( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2655 /* the window might have been scrolled already, do we
2656 have to adapt the position */
2657 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
2658 child
->m_x
+= pizza
->xoffset
;
2659 child
->m_y
+= pizza
->yoffset
;
2661 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
2662 GTK_WIDGET(child
->m_widget
),
2669 //-----------------------------------------------------------------------------
2671 //-----------------------------------------------------------------------------
2673 wxWindow
*wxGetActiveWindow()
2675 return wxWindow::FindFocus();
2678 //-----------------------------------------------------------------------------
2680 //-----------------------------------------------------------------------------
2682 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2684 #ifdef __WXUNIVERSAL__
2685 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2687 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
2688 #endif // __WXUNIVERSAL__/__WXGTK__
2690 void wxWindowGTK::Init()
2693 m_widget
= (GtkWidget
*) NULL
;
2694 m_wxwindow
= (GtkWidget
*) NULL
;
2695 m_focusWidget
= (GtkWidget
*) NULL
;
2705 m_needParent
= true;
2706 m_isBeingDeleted
= false;
2709 m_nativeSizeEvent
= false;
2711 m_hasScrolling
= false;
2712 m_isScrolling
= false;
2714 m_hAdjust
= (GtkAdjustment
*) NULL
;
2715 m_vAdjust
= (GtkAdjustment
*) NULL
;
2716 m_oldHorizontalPos
=
2717 m_oldVerticalPos
= 0.0;
2719 m_oldClientHeight
= 0;
2723 m_insertCallback
= (wxInsertChildFunction
) NULL
;
2725 m_acceptsFocus
= false;
2728 m_clipPaintRegion
= false;
2730 m_needsStyleChange
= false;
2732 m_cursor
= *wxSTANDARD_CURSOR
;
2736 m_x11Context
= NULL
;
2737 m_dirtyTabOrder
= false;
2740 m_ic
= (GdkIC
*) NULL
;
2741 m_icattr
= (GdkICAttr
*) NULL
;
2746 wxWindowGTK::wxWindowGTK()
2751 wxWindowGTK::wxWindowGTK( wxWindow
*parent
,
2756 const wxString
&name
)
2760 Create( parent
, id
, pos
, size
, style
, name
);
2763 bool wxWindowGTK::Create( wxWindow
*parent
,
2768 const wxString
&name
)
2770 if (!PreCreation( parent
, pos
, size
) ||
2771 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2773 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2777 m_insertCallback
= wxInsertChildInWindow
;
2779 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
2780 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
2782 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2784 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2785 scroll_class
->scrollbar_spacing
= 0;
2787 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2789 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
2790 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
2792 m_wxwindow
= gtk_pizza_new();
2794 #ifndef __WXUNIVERSAL__
2795 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
2797 if (HasFlag(wxRAISED_BORDER
))
2799 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
2801 else if (HasFlag(wxSUNKEN_BORDER
))
2803 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
2805 else if (HasFlag(wxSIMPLE_BORDER
))
2807 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
2811 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
2813 #endif // __WXUNIVERSAL__
2815 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2817 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
2818 m_acceptsFocus
= true;
2820 // I _really_ don't want scrollbars in the beginning
2821 m_vAdjust
->lower
= 0.0;
2822 m_vAdjust
->upper
= 1.0;
2823 m_vAdjust
->value
= 0.0;
2824 m_vAdjust
->step_increment
= 1.0;
2825 m_vAdjust
->page_increment
= 1.0;
2826 m_vAdjust
->page_size
= 5.0;
2827 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
2828 m_hAdjust
->lower
= 0.0;
2829 m_hAdjust
->upper
= 1.0;
2830 m_hAdjust
->value
= 0.0;
2831 m_hAdjust
->step_increment
= 1.0;
2832 m_hAdjust
->page_increment
= 1.0;
2833 m_hAdjust
->page_size
= 5.0;
2834 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
2836 // these handlers block mouse events to any window during scrolling such as
2837 // motion events and prevent GTK and wxWidgets from fighting over where the
2840 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_press_event",
2841 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2843 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_press_event",
2844 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2846 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_release_event",
2847 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2849 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_release_event",
2850 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2852 // these handlers get notified when screen updates are required either when
2853 // scrolling or when the window size (and therefore scrollbar configuration)
2856 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
2857 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
2858 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
2859 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
2861 gtk_widget_show( m_wxwindow
);
2864 m_parent
->DoAddChild( this );
2866 m_focusWidget
= m_wxwindow
;
2873 wxWindowGTK::~wxWindowGTK()
2877 if (g_focusWindow
== this)
2878 g_focusWindow
= NULL
;
2880 if ( g_delayedFocus
== this )
2881 g_delayedFocus
= NULL
;
2883 m_isBeingDeleted
= true;
2886 // destroy children before destroying this window itself
2889 // unhook focus handlers to prevent stray events being
2890 // propagated to this (soon to be) dead object
2891 if (m_focusWidget
!= NULL
)
2893 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2894 (GtkSignalFunc
) gtk_window_focus_in_callback
, (gpointer
) this );
2895 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2896 (GtkSignalFunc
) gtk_window_focus_out_callback
, (gpointer
) this );
2904 gdk_ic_destroy (m_ic
);
2906 gdk_ic_attr_destroy (m_icattr
);
2911 gtk_widget_destroy( m_wxwindow
);
2912 m_wxwindow
= (GtkWidget
*) NULL
;
2917 gtk_widget_destroy( m_widget
);
2918 m_widget
= (GtkWidget
*) NULL
;
2926 bool wxWindowGTK::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2928 wxCHECK_MSG( !m_needParent
|| parent
, false, wxT("Need complete parent.") );
2930 // Use either the given size, or the default if -1 is given.
2931 // See wxWindowBase for these functions.
2932 m_width
= WidthDefault(size
.x
) ;
2933 m_height
= HeightDefault(size
.y
);
2941 void wxWindowGTK::PostCreation()
2943 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2949 // these get reported to wxWidgets -> wxPaintEvent
2951 gtk_pizza_set_external( GTK_PIZZA(m_wxwindow
), TRUE
);
2953 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
2954 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
2957 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
2958 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
2960 if (!HasFlag(wxFULL_REPAINT_ON_RESIZE
))
2962 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "event",
2963 GTK_SIGNAL_FUNC(gtk_window_event_event_callback
), (gpointer
)this );
2966 // gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow), !HasFlag( wxFULL_REPAINT_ON_RESIZE ) );
2971 // Create input method handler
2972 m_imData
= new wxGtkIMData
;
2974 // Cannot handle drawing preedited text yet
2975 gtk_im_context_set_use_preedit( m_imData
->context
, FALSE
);
2977 g_signal_connect (G_OBJECT (m_imData
->context
), "commit",
2978 G_CALLBACK (gtk_wxwindow_commit_cb
), this);
2981 // these are called when the "sunken" or "raised" borders are drawn
2982 gtk_signal_connect( GTK_OBJECT(m_widget
), "expose_event",
2983 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
2986 gtk_signal_connect( GTK_OBJECT(m_widget
), "draw",
2987 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
2993 if (!GTK_IS_WINDOW(m_widget
))
2995 if (m_focusWidget
== NULL
)
2996 m_focusWidget
= m_widget
;
2998 gtk_signal_connect( GTK_OBJECT(m_focusWidget
), "focus_in_event",
2999 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
3001 gtk_signal_connect_after( GTK_OBJECT(m_focusWidget
), "focus_out_event",
3002 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
3005 // connect to the various key and mouse handlers
3007 GtkWidget
*connect_widget
= GetConnectWidget();
3009 ConnectWidget( connect_widget
);
3011 /* We cannot set colours, fonts and cursors before the widget has
3012 been realized, so we do this directly after realization */
3013 gtk_signal_connect( GTK_OBJECT(connect_widget
), "realize",
3014 GTK_SIGNAL_FUNC(gtk_window_realized_callback
), (gpointer
) this );
3018 // Catch native resize events
3019 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
3020 GTK_SIGNAL_FUNC(gtk_window_size_callback
), (gpointer
)this );
3022 // Initialize XIM support
3023 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "realize",
3024 GTK_SIGNAL_FUNC(gtk_wxwindow_realized_callback
), (gpointer
) this );
3026 // And resize XIM window
3027 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
3028 GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback
), (gpointer
)this );
3031 if (GTK_IS_COMBO(m_widget
))
3033 GtkCombo
*gcombo
= GTK_COMBO(m_widget
);
3035 gtk_signal_connect( GTK_OBJECT(gcombo
->entry
), "size_request",
3036 GTK_SIGNAL_FUNC(wxgtk_combo_size_request_callback
),
3041 // This is needed if we want to add our windows into native
3042 // GTK controls, such as the toolbar. With this callback, the
3043 // toolbar gets to know the correct size (the one set by the
3044 // programmer). Sadly, it misbehaves for wxComboBox.
3045 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_request",
3046 GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback
),
3050 InheritAttributes();
3054 // unless the window was created initially hidden (i.e. Hide() had been
3055 // called before Create()), we should show it at GTK+ level as well
3057 gtk_widget_show( m_widget
);
3060 void wxWindowGTK::ConnectWidget( GtkWidget
*widget
)
3062 gtk_signal_connect( GTK_OBJECT(widget
), "key_press_event",
3063 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
3065 gtk_signal_connect( GTK_OBJECT(widget
), "key_release_event",
3066 GTK_SIGNAL_FUNC(gtk_window_key_release_callback
), (gpointer
)this );
3068 gtk_signal_connect( GTK_OBJECT(widget
), "button_press_event",
3069 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
3071 gtk_signal_connect( GTK_OBJECT(widget
), "button_release_event",
3072 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
3074 gtk_signal_connect( GTK_OBJECT(widget
), "motion_notify_event",
3075 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
3078 gtk_signal_connect( GTK_OBJECT(widget
), "scroll_event",
3079 GTK_SIGNAL_FUNC(gtk_window_wheel_callback
), (gpointer
)this );
3080 g_signal_connect(widget
, "popup_menu",
3081 G_CALLBACK(wxgtk_window_popup_menu_callback
), this);
3084 gtk_signal_connect( GTK_OBJECT(widget
), "enter_notify_event",
3085 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
3087 gtk_signal_connect( GTK_OBJECT(widget
), "leave_notify_event",
3088 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
3091 bool wxWindowGTK::Destroy()
3093 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3097 return wxWindowBase::Destroy();
3100 void wxWindowGTK::DoMoveWindow(int x
, int y
, int width
, int height
)
3102 gtk_pizza_set_size( GTK_PIZZA(m_parent
->m_wxwindow
), m_widget
, x
, y
, width
, height
);
3105 void wxWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
3107 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3108 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
3111 printf( "DoSetSize: name %s, x,y,w,h: %d,%d,%d,%d \n", GetName().c_str(), x,y,width,height );
3114 if (m_resizing
) return; /* I don't like recursions */
3117 int currentX
, currentY
;
3118 GetPosition(¤tX
, ¤tY
);
3119 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
3121 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
3123 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
3125 if (m_parent
->m_wxwindow
== NULL
) /* i.e. wxNotebook */
3127 /* don't set the size for children of wxNotebook, just take the values. */
3135 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
3136 if ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0)
3138 if (x
!= -1) m_x
= x
+ pizza
->xoffset
;
3139 if (y
!= -1) m_y
= y
+ pizza
->yoffset
;
3143 m_x
= x
+ pizza
->xoffset
;
3144 m_y
= y
+ pizza
->yoffset
;
3147 // calculate the best size if we should auto size the window
3148 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
3149 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
3151 const wxSize sizeBest
= GetBestSize();
3152 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
3154 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
3155 height
= sizeBest
.y
;
3163 int minWidth
= GetMinWidth(),
3164 minHeight
= GetMinHeight(),
3165 maxWidth
= GetMaxWidth(),
3166 maxHeight
= GetMaxHeight();
3168 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
3169 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
3170 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
3171 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
3173 int left_border
= 0;
3174 int right_border
= 0;
3176 int bottom_border
= 0;
3178 /* the default button has a border around it */
3179 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
3182 GtkBorder
*default_border
= NULL
;
3183 gtk_widget_style_get( m_widget
, "default_border", &default_border
, NULL
);
3186 left_border
+= default_border
->left
;
3187 right_border
+= default_border
->right
;
3188 top_border
+= default_border
->top
;
3189 bottom_border
+= default_border
->bottom
;
3190 g_free( default_border
);
3200 DoMoveWindow( m_x
-top_border
,
3202 m_width
+left_border
+right_border
,
3203 m_height
+top_border
+bottom_border
);
3208 /* Sometimes the client area changes size without the
3209 whole windows's size changing, but if the whole
3210 windows's size doesn't change, no wxSizeEvent will
3211 normally be sent. Here we add an extra test if
3212 the client test has been changed and this will
3214 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
3218 wxPrintf( "OnSize sent from " );
3219 if (GetClassInfo() && GetClassInfo()->GetClassName())
3220 wxPrintf( GetClassInfo()->GetClassName() );
3221 wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height );
3224 if (!m_nativeSizeEvent
)
3226 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
3227 event
.SetEventObject( this );
3228 GetEventHandler()->ProcessEvent( event
);
3234 void wxWindowGTK::OnInternalIdle()
3237 if ( m_dirtyTabOrder
)
3240 // Update style if the window was not yet realized
3241 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
3242 if (m_needsStyleChange
)
3244 SetBackgroundStyle(GetBackgroundStyle());
3245 m_needsStyleChange
= false;
3248 // Update invalidated regions.
3251 wxCursor cursor
= m_cursor
;
3252 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
3256 /* I now set the cursor anew in every OnInternalIdle call
3257 as setting the cursor in a parent window also effects the
3258 windows above so that checking for the current cursor is
3263 GdkWindow
*window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3265 gdk_window_set_cursor( window
, cursor
.GetCursor() );
3267 if (!g_globalCursor
.Ok())
3268 cursor
= *wxSTANDARD_CURSOR
;
3270 window
= m_widget
->window
;
3271 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
3272 gdk_window_set_cursor( window
, cursor
.GetCursor() );
3278 GdkWindow
*window
= m_widget
->window
;
3279 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
3280 gdk_window_set_cursor( window
, cursor
.GetCursor() );
3285 if (wxUpdateUIEvent::CanUpdate(this))
3286 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
3289 void wxWindowGTK::DoGetSize( int *width
, int *height
) const
3291 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3293 if (width
) (*width
) = m_width
;
3294 if (height
) (*height
) = m_height
;
3297 void wxWindowGTK::DoSetClientSize( int width
, int height
)
3299 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3303 SetSize( width
, height
);
3310 #ifndef __WXUNIVERSAL__
3311 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
3313 /* when using GTK 1.2 we set the shadow border size to 2 */
3317 if (HasFlag(wxSIMPLE_BORDER
))
3319 /* when using GTK 1.2 we set the simple border size to 1 */
3323 #endif // __WXUNIVERSAL__
3327 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
3329 GtkRequisition vscroll_req
;
3330 vscroll_req
.width
= 2;
3331 vscroll_req
.height
= 2;
3332 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
3333 (scroll_window
->vscrollbar
, &vscroll_req
);
3335 GtkRequisition hscroll_req
;
3336 hscroll_req
.width
= 2;
3337 hscroll_req
.height
= 2;
3338 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
3339 (scroll_window
->hscrollbar
, &hscroll_req
);
3341 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3343 if (scroll_window
->vscrollbar_visible
)
3345 dw
+= vscroll_req
.width
;
3346 dw
+= scroll_class
->scrollbar_spacing
;
3349 if (scroll_window
->hscrollbar_visible
)
3351 dh
+= hscroll_req
.height
;
3352 dh
+= scroll_class
->scrollbar_spacing
;
3356 SetSize( width
+dw
, height
+dh
);
3360 void wxWindowGTK::DoGetClientSize( int *width
, int *height
) const
3362 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3366 if (width
) (*width
) = m_width
;
3367 if (height
) (*height
) = m_height
;
3374 #ifndef __WXUNIVERSAL__
3375 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
3377 /* when using GTK 1.2 we set the shadow border size to 2 */
3381 if (HasFlag(wxSIMPLE_BORDER
))
3383 /* when using GTK 1.2 we set the simple border size to 1 */
3387 #endif // __WXUNIVERSAL__
3391 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
3393 GtkRequisition vscroll_req
;
3394 vscroll_req
.width
= 2;
3395 vscroll_req
.height
= 2;
3396 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
3397 (scroll_window
->vscrollbar
, &vscroll_req
);
3399 GtkRequisition hscroll_req
;
3400 hscroll_req
.width
= 2;
3401 hscroll_req
.height
= 2;
3402 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
3403 (scroll_window
->hscrollbar
, &hscroll_req
);
3405 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3407 if (scroll_window
->vscrollbar_visible
)
3409 dw
+= vscroll_req
.width
;
3410 dw
+= scroll_class
->scrollbar_spacing
;
3413 if (scroll_window
->hscrollbar_visible
)
3415 dh
+= hscroll_req
.height
;
3416 dh
+= scroll_class
->scrollbar_spacing
;
3420 if (width
) (*width
) = m_width
- dw
;
3421 if (height
) (*height
) = m_height
- dh
;
3425 printf( "GetClientSize, name %s ", GetName().c_str() );
3426 if (width) printf( " width = %d", (*width) );
3427 if (height) printf( " height = %d", (*height) );
3432 void wxWindowGTK::DoGetPosition( int *x
, int *y
) const
3434 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3438 if (m_parent
&& m_parent
->m_wxwindow
)
3440 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
3441 dx
= pizza
->xoffset
;
3442 dy
= pizza
->yoffset
;
3445 if (x
) (*x
) = m_x
- dx
;
3446 if (y
) (*y
) = m_y
- dy
;
3449 void wxWindowGTK::DoClientToScreen( int *x
, int *y
) const
3451 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3453 if (!m_widget
->window
) return;
3455 GdkWindow
*source
= (GdkWindow
*) NULL
;
3457 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3459 source
= m_widget
->window
;
3463 gdk_window_get_origin( source
, &org_x
, &org_y
);
3467 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3469 org_x
+= m_widget
->allocation
.x
;
3470 org_y
+= m_widget
->allocation
.y
;
3478 void wxWindowGTK::DoScreenToClient( int *x
, int *y
) const
3480 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3482 if (!m_widget
->window
) return;
3484 GdkWindow
*source
= (GdkWindow
*) NULL
;
3486 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3488 source
= m_widget
->window
;
3492 gdk_window_get_origin( source
, &org_x
, &org_y
);
3496 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3498 org_x
+= m_widget
->allocation
.x
;
3499 org_y
+= m_widget
->allocation
.y
;
3507 bool wxWindowGTK::Show( bool show
)
3509 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3511 if (!wxWindowBase::Show(show
))
3518 gtk_widget_show( m_widget
);
3520 gtk_widget_hide( m_widget
);
3522 wxShowEvent
eventShow(GetId(), show
);
3523 eventShow
.SetEventObject(this);
3525 GetEventHandler()->ProcessEvent(eventShow
);
3530 static void wxWindowNotifyEnable(wxWindowGTK
* win
, bool enable
)
3532 win
->OnParentEnable(enable
);
3534 // Recurse, so that children have the opportunity to Do The Right Thing
3535 // and reset colours that have been messed up by a parent's (really ancestor's)
3537 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3539 node
= node
->GetNext() )
3541 wxWindow
*child
= node
->GetData();
3542 if (!child
->IsKindOf(CLASSINFO(wxDialog
)) && !child
->IsKindOf(CLASSINFO(wxFrame
)))
3543 wxWindowNotifyEnable(child
, enable
);
3547 bool wxWindowGTK::Enable( bool enable
)
3549 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3551 if (!wxWindowBase::Enable(enable
))
3557 gtk_widget_set_sensitive( m_widget
, enable
);
3559 gtk_widget_set_sensitive( m_wxwindow
, enable
);
3561 wxWindowNotifyEnable(this, enable
);
3566 int wxWindowGTK::GetCharHeight() const
3568 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
3570 wxFont font
= GetFont();
3571 wxCHECK_MSG( font
.Ok(), 12, wxT("invalid font") );
3574 PangoContext
*context
= NULL
;
3576 context
= gtk_widget_get_pango_context( m_widget
);
3581 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
3582 PangoLayout
*layout
= pango_layout_new(context
);
3583 pango_layout_set_font_description(layout
, desc
);
3584 pango_layout_set_text(layout
, "H", 1);
3585 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
3587 PangoRectangle rect
;
3588 pango_layout_line_get_extents(line
, NULL
, &rect
);
3590 g_object_unref( G_OBJECT( layout
) );
3592 return (int) PANGO_PIXELS(rect
.height
);
3594 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3596 return gfont
->ascent
+ gfont
->descent
;
3600 int wxWindowGTK::GetCharWidth() const
3602 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
3604 wxFont font
= GetFont();
3605 wxCHECK_MSG( font
.Ok(), 8, wxT("invalid font") );
3608 PangoContext
*context
= NULL
;
3610 context
= gtk_widget_get_pango_context( m_widget
);
3615 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
3616 PangoLayout
*layout
= pango_layout_new(context
);
3617 pango_layout_set_font_description(layout
, desc
);
3618 pango_layout_set_text(layout
, "g", 1);
3619 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
3621 PangoRectangle rect
;
3622 pango_layout_line_get_extents(line
, NULL
, &rect
);
3624 g_object_unref( G_OBJECT( layout
) );
3626 return (int) PANGO_PIXELS(rect
.width
);
3628 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3630 return gdk_string_width( gfont
, "g" );
3634 void wxWindowGTK::GetTextExtent( const wxString
& string
,
3638 int *externalLeading
,
3639 const wxFont
*theFont
) const
3641 wxFont fontToUse
= theFont
? *theFont
: GetFont();
3643 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
3653 PangoContext
*context
= NULL
;
3655 context
= gtk_widget_get_pango_context( m_widget
);
3664 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
3665 PangoLayout
*layout
= pango_layout_new(context
);
3666 pango_layout_set_font_description(layout
, desc
);
3669 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
3670 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
3672 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
3673 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
3674 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
3678 PangoRectangle rect
;
3679 pango_layout_get_extents(layout
, NULL
, &rect
);
3681 if (x
) (*x
) = (wxCoord
) PANGO_PIXELS(rect
.width
);
3682 if (y
) (*y
) = (wxCoord
) PANGO_PIXELS(rect
.height
);
3685 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
3686 int baseline
= pango_layout_iter_get_baseline(iter
);
3687 pango_layout_iter_free(iter
);
3688 *descent
= *y
- PANGO_PIXELS(baseline
);
3690 if (externalLeading
) (*externalLeading
) = 0; // ??
3692 g_object_unref( G_OBJECT( layout
) );
3694 GdkFont
*font
= fontToUse
.GetInternalFont( 1.0 );
3695 if (x
) (*x
) = gdk_string_width( font
, wxGTK_CONV( string
) );
3696 if (y
) (*y
) = font
->ascent
+ font
->descent
;
3697 if (descent
) (*descent
) = font
->descent
;
3698 if (externalLeading
) (*externalLeading
) = 0; // ??
3702 void wxWindowGTK::SetFocus()
3704 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3707 // don't do anything if we already have focus
3713 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow
))
3715 gtk_widget_grab_focus (m_wxwindow
);
3721 if (GTK_IS_CONTAINER(m_widget
))
3723 gtk_widget_child_focus( m_widget
, GTK_DIR_TAB_FORWARD
);
3727 if (GTK_WIDGET_CAN_FOCUS(m_widget
) && !GTK_WIDGET_HAS_FOCUS (m_widget
) )
3730 if (!GTK_WIDGET_REALIZED(m_widget
))
3732 // we can't set the focus to the widget now so we remember that
3733 // it should be focused and will do it later, during the idle
3734 // time, as soon as we can
3735 wxLogTrace(TRACE_FOCUS
,
3736 _T("Delaying setting focus to %s(%s)"),
3737 GetClassInfo()->GetClassName(), GetLabel().c_str());
3739 g_delayedFocus
= this;
3743 wxLogTrace(TRACE_FOCUS
,
3744 _T("Setting focus to %s(%s)"),
3745 GetClassInfo()->GetClassName(), GetLabel().c_str());
3747 gtk_widget_grab_focus (m_widget
);
3752 if (GTK_IS_CONTAINER(m_widget
))
3754 gtk_container_focus( GTK_CONTAINER(m_widget
), GTK_DIR_TAB_FORWARD
);
3759 wxLogTrace(TRACE_FOCUS
,
3760 _T("Can't set focus to %s(%s)"),
3761 GetClassInfo()->GetClassName(), GetLabel().c_str());
3766 bool wxWindowGTK::AcceptsFocus() const
3768 return m_acceptsFocus
&& wxWindowBase::AcceptsFocus();
3771 bool wxWindowGTK::Reparent( wxWindowBase
*newParentBase
)
3773 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3775 wxWindowGTK
*oldParent
= m_parent
,
3776 *newParent
= (wxWindowGTK
*)newParentBase
;
3778 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3780 if ( !wxWindowBase::Reparent(newParent
) )
3783 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3785 /* prevent GTK from deleting the widget arbitrarily */
3786 gtk_widget_ref( m_widget
);
3790 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3793 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3797 /* insert GTK representation */
3798 (*(newParent
->m_insertCallback
))(newParent
, this);
3801 /* reverse: prevent GTK from deleting the widget arbitrarily */
3802 gtk_widget_unref( m_widget
);
3807 void wxWindowGTK::DoAddChild(wxWindowGTK
*child
)
3809 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3811 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3813 wxASSERT_MSG( (m_insertCallback
!= NULL
), wxT("invalid child insertion function") );
3818 /* insert GTK representation */
3819 (*m_insertCallback
)(this, child
);
3824 void wxWindowGTK::AddChild(wxWindowBase
*child
)
3826 wxWindowBase::AddChild(child
);
3827 m_dirtyTabOrder
= true;
3829 wxapp_install_idle_handler();
3832 void wxWindowGTK::RemoveChild(wxWindowBase
*child
)
3834 wxWindowBase::RemoveChild(child
);
3835 m_dirtyTabOrder
= true;
3837 wxapp_install_idle_handler();
3840 void wxWindowGTK::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
3842 wxWindowBase::DoMoveInTabOrder(win
, move
);
3843 m_dirtyTabOrder
= true;
3845 wxapp_install_idle_handler();
3848 void wxWindowGTK::RealizeTabOrder()
3852 if (m_children
.size() > 0)
3854 GList
*chain
= NULL
;
3856 for (wxWindowList::const_iterator i
= m_children
.begin();
3857 i
!= m_children
.end(); ++i
)
3859 chain
= g_list_prepend(chain
, (*i
)->m_widget
);
3862 chain
= g_list_reverse(chain
);
3864 gtk_container_set_focus_chain(GTK_CONTAINER(m_wxwindow
), chain
);
3869 gtk_container_unset_focus_chain(GTK_CONTAINER(m_wxwindow
));
3873 m_dirtyTabOrder
= false;
3876 #endif // __WXGTK20__
3878 void wxWindowGTK::Raise()
3880 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3882 if (m_wxwindow
&& m_wxwindow
->window
)
3884 gdk_window_raise( m_wxwindow
->window
);
3886 else if (m_widget
->window
)
3888 gdk_window_raise( m_widget
->window
);
3892 void wxWindowGTK::Lower()
3894 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3896 if (m_wxwindow
&& m_wxwindow
->window
)
3898 gdk_window_lower( m_wxwindow
->window
);
3900 else if (m_widget
->window
)
3902 gdk_window_lower( m_widget
->window
);
3906 bool wxWindowGTK::SetCursor( const wxCursor
&cursor
)
3908 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3910 if (cursor
== m_cursor
)
3914 wxapp_install_idle_handler();
3916 if (cursor
== wxNullCursor
)
3917 return wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
);
3919 return wxWindowBase::SetCursor( cursor
);
3922 void wxWindowGTK::WarpPointer( int x
, int y
)
3924 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3926 // We provide this function ourselves as it is
3927 // missing in GDK (top of this file).
3929 GdkWindow
*window
= (GdkWindow
*) NULL
;
3931 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3933 window
= GetConnectWidget()->window
;
3936 gdk_window_warp_pointer( window
, x
, y
);
3940 void wxWindowGTK::Refresh( bool eraseBackground
, const wxRect
*rect
)
3944 if (!m_widget
->window
)
3949 wxapp_install_idle_handler();
3952 if (m_wxwindow
&& rect
)
3954 myRect
.SetSize(wxSize( m_wxwindow
->allocation
.width
,
3955 m_wxwindow
->allocation
.height
));
3956 if ( myRect
.Intersect(*rect
).IsEmpty() )
3958 // nothing to do, rectangle is empty
3965 // schedule the area for later updating in GtkUpdate()
3966 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
3970 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3974 m_clearRegion
.Clear();
3975 m_clearRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
3983 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3987 GdkRectangle gdk_rect
;
3988 gdk_rect
.x
= rect
->x
;
3989 gdk_rect
.y
= rect
->y
;
3990 gdk_rect
.width
= rect
->width
;
3991 gdk_rect
.height
= rect
->height
;
3992 gtk_widget_draw( m_widget
, &gdk_rect
);
3999 m_updateRegion
.Clear();
4000 m_updateRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
4004 gtk_widget_draw( m_widget
, (GdkRectangle
*) NULL
);
4010 GdkRectangle gdk_rect
,
4014 gdk_rect
.x
= rect
->x
;
4015 gdk_rect
.y
= rect
->y
;
4016 gdk_rect
.width
= rect
->width
;
4017 gdk_rect
.height
= rect
->height
;
4020 else // invalidate everything
4025 gdk_window_invalidate_rect( GTK_PIZZA(m_wxwindow
)->bin_window
, p
, TRUE
);
4030 void wxWindowGTK::Update()
4034 // when we call Update() we really want to update the window immediately on
4035 // screen, even if itmeans flushing the entire queue and hence slowing down
4036 // everything -- but it should still be done, it's just that Update() should
4037 // be called very rarely
4041 void wxWindowGTK::GtkUpdate()
4044 if (m_wxwindow
&& GTK_PIZZA(m_wxwindow
)->bin_window
)
4045 gdk_window_process_updates( GTK_PIZZA(m_wxwindow
)->bin_window
, FALSE
);
4047 if (!m_updateRegion
.IsEmpty())
4048 GtkSendPaintEvents();
4051 // for consistency with other platforms (and also because it's convenient
4052 // to be able to update an entire TLW by calling Update() only once), we
4053 // should also update all our children here
4054 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4056 node
= node
->GetNext() )
4058 node
->GetData()->GtkUpdate();
4062 void wxWindowGTK::GtkSendPaintEvents()
4067 m_clearRegion
.Clear();
4069 m_updateRegion
.Clear();
4073 // Clip to paint region in wxClientDC
4074 m_clipPaintRegion
= true;
4076 // widget to draw on
4077 GtkPizza
*pizza
= GTK_PIZZA (m_wxwindow
);
4079 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM
))
4081 // find ancestor from which to steal background
4082 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
4084 parent
= (wxWindow
*)this;
4086 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
4088 wxRegionIterator
upd( m_updateRegion
);
4092 rect
.x
= upd
.GetX();
4093 rect
.y
= upd
.GetY();
4094 rect
.width
= upd
.GetWidth();
4095 rect
.height
= upd
.GetHeight();
4097 gtk_paint_flat_box( parent
->m_widget
->style
,
4099 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
4114 wxWindowDC
dc( (wxWindow
*)this );
4115 dc
.SetClippingRegion( m_updateRegion
);
4117 wxEraseEvent
erase_event( GetId(), &dc
);
4118 erase_event
.SetEventObject( this );
4120 GetEventHandler()->ProcessEvent(erase_event
);
4123 // if (!m_clearRegion.IsEmpty()) // Always send an erase event under GTK 1.2
4125 wxWindowDC
dc( (wxWindow
*)this );
4126 if (m_clearRegion
.IsEmpty())
4127 dc
.SetClippingRegion( m_updateRegion
);
4129 dc
.SetClippingRegion( m_clearRegion
);
4131 wxEraseEvent
erase_event( GetId(), &dc
);
4132 erase_event
.SetEventObject( this );
4134 if (!GetEventHandler()->ProcessEvent(erase_event
) && GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
4138 g_eraseGC
= gdk_gc_new( pizza
->bin_window
);
4139 gdk_gc_set_fill( g_eraseGC
, GDK_SOLID
);
4141 gdk_gc_set_foreground( g_eraseGC
, GetBackgroundColour().GetColor() );
4143 wxRegionIterator
upd( m_clearRegion
);
4146 gdk_draw_rectangle( pizza
->bin_window
, g_eraseGC
, 1,
4147 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
4151 m_clearRegion
.Clear();
4155 wxNcPaintEvent
nc_paint_event( GetId() );
4156 nc_paint_event
.SetEventObject( this );
4157 GetEventHandler()->ProcessEvent( nc_paint_event
);
4159 wxPaintEvent
paint_event( GetId() );
4160 paint_event
.SetEventObject( this );
4161 GetEventHandler()->ProcessEvent( paint_event
);
4163 m_clipPaintRegion
= false;
4165 #if !defined(__WXUNIVERSAL__) && !defined(__WXGTK20__)
4166 // The following code will result in all window-less widgets
4167 // being redrawn because the wxWidgets class is allowed to
4168 // paint over the window-less widgets.
4170 GList
*children
= pizza
->children
;
4173 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
4174 children
= children
->next
;
4176 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
4177 GTK_WIDGET_DRAWABLE (child
->widget
))
4179 // Get intersection of widget area and update region
4180 wxRegion
region( m_updateRegion
);
4182 GdkEventExpose gdk_event
;
4183 gdk_event
.type
= GDK_EXPOSE
;
4184 gdk_event
.window
= pizza
->bin_window
;
4185 gdk_event
.count
= 0;
4186 gdk_event
.send_event
= TRUE
;
4188 wxRegionIterator
upd( m_updateRegion
);
4192 rect
.x
= upd
.GetX();
4193 rect
.y
= upd
.GetY();
4194 rect
.width
= upd
.GetWidth();
4195 rect
.height
= upd
.GetHeight();
4197 if (gtk_widget_intersect (child
->widget
, &rect
, &gdk_event
.area
))
4199 gtk_widget_event (child
->widget
, (GdkEvent
*) &gdk_event
);
4206 #endif // native GTK 1
4208 m_updateRegion
.Clear();
4211 void wxWindowGTK::ClearBackground()
4213 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4216 if (m_wxwindow
&& m_wxwindow
->window
)
4218 m_clearRegion
.Clear();
4219 wxSize
size( GetClientSize() );
4220 m_clearRegion
.Union( 0,0,size
.x
,size
.y
);
4222 // Better do this in idle?
4229 void wxWindowGTK::DoSetToolTip( wxToolTip
*tip
)
4231 wxWindowBase::DoSetToolTip(tip
);
4234 m_tooltip
->Apply( (wxWindow
*)this );
4237 void wxWindowGTK::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
4239 wxString
tmp( tip
);
4240 gtk_tooltips_set_tip( tips
, GetConnectWidget(), wxGTK_CONV(tmp
), (gchar
*) NULL
);
4242 #endif // wxUSE_TOOLTIPS
4244 bool wxWindowGTK::SetBackgroundColour( const wxColour
&colour
)
4246 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
4248 if (!wxWindowBase::SetBackgroundColour(colour
))
4253 // We need the pixel value e.g. for background clearing.
4254 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
4257 // apply style change (forceStyle=true so that new style is applied
4258 // even if the bg colour changed from valid to wxNullColour)
4259 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
4260 ApplyWidgetStyle(true);
4265 bool wxWindowGTK::SetForegroundColour( const wxColour
&colour
)
4267 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
4269 if (!wxWindowBase::SetForegroundColour(colour
))
4276 // We need the pixel value e.g. for background clearing.
4277 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
4280 // apply style change (forceStyle=true so that new style is applied
4281 // even if the bg colour changed from valid to wxNullColour):
4282 ApplyWidgetStyle(true);
4288 PangoContext
*wxWindowGTK::GtkGetPangoDefaultContext()
4290 return gtk_widget_get_pango_context( m_widget
);
4293 // MR: Returns the same as GtkGetPangoDefaultContext until the symbol can be removed in 2.7.x
4294 PangoContext
*wxWindowGTK::GtkGetPangoX11Context()
4296 return gtk_widget_get_pango_context( m_widget
);
4300 GtkRcStyle
*wxWindowGTK::CreateWidgetStyle(bool forceStyle
)
4302 // do we need to apply any changes at all?
4305 !m_foregroundColour
.Ok() && !m_backgroundColour
.Ok() )
4310 GtkRcStyle
*style
= gtk_rc_style_new();
4316 pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
4318 wxString xfontname
= m_font
.GetNativeFontInfo()->GetXFontName();
4319 style
->fontset_name
= g_strdup(xfontname
.c_str());
4323 if ( m_foregroundColour
.Ok() )
4325 GdkColor
*fg
= m_foregroundColour
.GetColor();
4327 style
->fg
[GTK_STATE_NORMAL
] = *fg
;
4328 style
->color_flags
[GTK_STATE_NORMAL
] = GTK_RC_FG
;
4330 style
->fg
[GTK_STATE_PRELIGHT
] = *fg
;
4331 style
->color_flags
[GTK_STATE_PRELIGHT
] = GTK_RC_FG
;
4333 style
->fg
[GTK_STATE_ACTIVE
] = *fg
;
4334 style
->color_flags
[GTK_STATE_ACTIVE
] = GTK_RC_FG
;
4337 if ( m_backgroundColour
.Ok() )
4339 GdkColor
*bg
= m_backgroundColour
.GetColor();
4341 style
->bg
[GTK_STATE_NORMAL
] = *bg
;
4342 style
->base
[GTK_STATE_NORMAL
] = *bg
;
4343 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)
4344 (style
->color_flags
[GTK_STATE_NORMAL
] | GTK_RC_BG
| GTK_RC_BASE
);
4346 style
->bg
[GTK_STATE_PRELIGHT
] = *bg
;
4347 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
4348 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)
4349 (style
->color_flags
[GTK_STATE_PRELIGHT
] | GTK_RC_BG
| GTK_RC_BASE
);
4351 style
->bg
[GTK_STATE_ACTIVE
] = *bg
;
4352 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
4353 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)
4354 (style
->color_flags
[GTK_STATE_ACTIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
4356 style
->bg
[GTK_STATE_INSENSITIVE
] = *bg
;
4357 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
4358 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)
4359 (style
->color_flags
[GTK_STATE_INSENSITIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
4365 void wxWindowGTK::ApplyWidgetStyle(bool forceStyle
)
4367 GtkRcStyle
*style
= CreateWidgetStyle(forceStyle
);
4370 DoApplyWidgetStyle(style
);
4371 gtk_rc_style_unref(style
);
4374 // Style change may affect GTK+'s size calculation:
4375 InvalidateBestSize();
4378 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle
*style
)
4381 gtk_widget_modify_style(m_wxwindow
, style
);
4383 gtk_widget_modify_style(m_widget
, style
);
4386 bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style
)
4388 wxWindowBase::SetBackgroundStyle(style
);
4390 if (style
== wxBG_STYLE_CUSTOM
)
4392 GdkWindow
*window
= (GdkWindow
*) NULL
;
4394 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4396 window
= GetConnectWidget()->window
;
4400 // Make sure GDK/X11 doesn't refresh the window
4402 gdk_window_set_back_pixmap( window
, None
, False
);
4404 Display
* display
= GDK_WINDOW_DISPLAY(window
);
4407 m_needsStyleChange
= false;
4410 // Do in OnIdle, because the window is not yet available
4411 m_needsStyleChange
= true;
4413 // Don't apply widget style, or we get a grey background
4417 // apply style change (forceStyle=true so that new style is applied
4418 // even if the bg colour changed from valid to wxNullColour):
4419 ApplyWidgetStyle(true);
4424 //-----------------------------------------------------------------------------
4425 // Pop-up menu stuff
4426 //-----------------------------------------------------------------------------
4428 #if wxUSE_MENUS_NATIVE
4430 extern "C" WXDLLIMPEXP_CORE
4431 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
4433 *is_waiting
= FALSE
;
4436 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
4438 menu
->SetInvokingWindow( win
);
4440 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
4443 wxMenuItem
*menuitem
= node
->GetData();
4444 if (menuitem
->IsSubMenu())
4446 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
4449 node
= node
->GetNext();
4453 extern "C" WXDLLIMPEXP_CORE
4454 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
4457 gboolean
* WXUNUSED(whatever
),
4459 gpointer user_data
)
4461 // ensure that the menu appears entirely on screen
4463 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
4465 wxSize sizeScreen
= wxGetDisplaySize();
4466 wxPoint
*pos
= (wxPoint
*)user_data
;
4468 gint xmax
= sizeScreen
.x
- req
.width
,
4469 ymax
= sizeScreen
.y
- req
.height
;
4471 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
4472 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
4475 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
4477 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
4479 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
4481 // NOTE: if you change this code, you need to update
4482 // the same code in taskbar.cpp as well. This
4483 // is ugly code duplication, I know,
4485 SetInvokingWindow( menu
, this );
4489 bool is_waiting
= true;
4491 gulong handler
= gtk_signal_connect( GTK_OBJECT(menu
->m_menu
),
4493 GTK_SIGNAL_FUNC(gtk_pop_hide_callback
),
4494 (gpointer
)&is_waiting
);
4498 GtkMenuPositionFunc posfunc
;
4499 if ( x
== -1 && y
== -1 )
4501 // use GTK's default positioning algorithm
4507 pos
= ClientToScreen(wxPoint(x
, y
));
4509 posfunc
= wxPopupMenuPositionCallback
;
4513 GTK_MENU(menu
->m_menu
),
4514 (GtkWidget
*) NULL
, // parent menu shell
4515 (GtkWidget
*) NULL
, // parent menu item
4516 posfunc
, // function to position it
4517 userdata
, // client data
4518 0, // button used to activate it
4520 gtk_get_current_event_time()
4522 gs_timeLastClick
// the time of activation
4528 gtk_main_iteration();
4531 gtk_signal_disconnect(GTK_OBJECT(menu
->m_menu
), handler
);
4536 #endif // wxUSE_MENUS_NATIVE
4538 #if wxUSE_DRAG_AND_DROP
4540 void wxWindowGTK::SetDropTarget( wxDropTarget
*dropTarget
)
4542 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4544 GtkWidget
*dnd_widget
= GetConnectWidget();
4546 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
4548 if (m_dropTarget
) delete m_dropTarget
;
4549 m_dropTarget
= dropTarget
;
4551 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
4554 #endif // wxUSE_DRAG_AND_DROP
4556 GtkWidget
* wxWindowGTK::GetConnectWidget()
4558 GtkWidget
*connect_widget
= m_widget
;
4559 if (m_wxwindow
) connect_widget
= m_wxwindow
;
4561 return connect_widget
;
4564 bool wxWindowGTK::IsOwnGtkWindow( GdkWindow
*window
)
4567 return (window
== GTK_PIZZA(m_wxwindow
)->bin_window
);
4569 return (window
== m_widget
->window
);
4572 bool wxWindowGTK::SetFont( const wxFont
&font
)
4574 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
4576 if (!wxWindowBase::SetFont(font
))
4579 // apply style change (forceStyle=true so that new style is applied
4580 // even if the font changed from valid to wxNullFont):
4581 ApplyWidgetStyle(true);
4586 void wxWindowGTK::DoCaptureMouse()
4588 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4590 GdkWindow
*window
= (GdkWindow
*) NULL
;
4592 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4594 window
= GetConnectWidget()->window
;
4596 wxCHECK_RET( window
, _T("CaptureMouse() failed") );
4598 wxCursor
* cursor
= & m_cursor
;
4600 cursor
= wxSTANDARD_CURSOR
;
4602 gdk_pointer_grab( window
, FALSE
,
4604 (GDK_BUTTON_PRESS_MASK
|
4605 GDK_BUTTON_RELEASE_MASK
|
4606 GDK_POINTER_MOTION_HINT_MASK
|
4607 GDK_POINTER_MOTION_MASK
),
4609 cursor
->GetCursor(),
4610 (guint32
)GDK_CURRENT_TIME
);
4611 g_captureWindow
= this;
4612 g_captureWindowHasMouse
= true;
4615 void wxWindowGTK::DoReleaseMouse()
4617 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4619 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
4621 g_captureWindow
= (wxWindowGTK
*) NULL
;
4623 GdkWindow
*window
= (GdkWindow
*) NULL
;
4625 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4627 window
= GetConnectWidget()->window
;
4632 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
4636 wxWindow
*wxWindowBase::GetCapture()
4638 return (wxWindow
*)g_captureWindow
;
4641 bool wxWindowGTK::IsRetained() const
4646 void wxWindowGTK::SetScrollbar( int orient
, int pos
, int thumbVisible
,
4647 int range
, bool refresh
)
4649 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4651 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4653 m_hasScrolling
= true;
4655 if (orient
== wxHORIZONTAL
)
4657 float fpos
= (float)pos
;
4658 float frange
= (float)range
;
4659 float fthumb
= (float)thumbVisible
;
4660 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
4661 if (fpos
< 0.0) fpos
= 0.0;
4663 if ((fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
4664 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
4666 SetScrollPos( orient
, pos
, refresh
);
4670 m_oldHorizontalPos
= fpos
;
4672 m_hAdjust
->lower
= 0.0;
4673 m_hAdjust
->upper
= frange
;
4674 m_hAdjust
->value
= fpos
;
4675 m_hAdjust
->step_increment
= 1.0;
4676 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4677 m_hAdjust
->page_size
= fthumb
;
4681 float fpos
= (float)pos
;
4682 float frange
= (float)range
;
4683 float fthumb
= (float)thumbVisible
;
4684 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
4685 if (fpos
< 0.0) fpos
= 0.0;
4687 if ((fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
4688 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
4690 SetScrollPos( orient
, pos
, refresh
);
4694 m_oldVerticalPos
= fpos
;
4696 m_vAdjust
->lower
= 0.0;
4697 m_vAdjust
->upper
= frange
;
4698 m_vAdjust
->value
= fpos
;
4699 m_vAdjust
->step_increment
= 1.0;
4700 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4701 m_vAdjust
->page_size
= fthumb
;
4704 if (orient
== wxHORIZONTAL
)
4705 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
4707 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
4710 void wxWindowGTK::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
4712 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4714 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4716 if (orient
== wxHORIZONTAL
)
4718 float fpos
= (float)pos
;
4719 if (fpos
> m_hAdjust
->upper
- m_hAdjust
->page_size
) fpos
= m_hAdjust
->upper
- m_hAdjust
->page_size
;
4720 if (fpos
< 0.0) fpos
= 0.0;
4721 m_oldHorizontalPos
= fpos
;
4723 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
4724 m_hAdjust
->value
= fpos
;
4728 float fpos
= (float)pos
;
4729 if (fpos
> m_vAdjust
->upper
- m_vAdjust
->page_size
) fpos
= m_vAdjust
->upper
- m_vAdjust
->page_size
;
4730 if (fpos
< 0.0) fpos
= 0.0;
4731 m_oldVerticalPos
= fpos
;
4733 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
4734 m_vAdjust
->value
= fpos
;
4737 if (m_wxwindow
->window
)
4739 if (orient
== wxHORIZONTAL
)
4741 gtk_signal_disconnect_by_func( GTK_OBJECT(m_hAdjust
),
4742 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
4744 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
4746 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
4747 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
4751 gtk_signal_disconnect_by_func( GTK_OBJECT(m_vAdjust
),
4752 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
4754 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
4756 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
4757 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
4762 int wxWindowGTK::GetScrollThumb( int orient
) const
4764 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4766 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4768 if (orient
== wxHORIZONTAL
)
4769 return (int)(m_hAdjust
->page_size
+0.5);
4771 return (int)(m_vAdjust
->page_size
+0.5);
4774 int wxWindowGTK::GetScrollPos( int orient
) const
4776 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4778 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4780 if (orient
== wxHORIZONTAL
)
4781 return (int)(m_hAdjust
->value
+0.5);
4783 return (int)(m_vAdjust
->value
+0.5);
4786 int wxWindowGTK::GetScrollRange( int orient
) const
4788 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4790 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4792 if (orient
== wxHORIZONTAL
)
4793 return (int)(m_hAdjust
->upper
+0.5);
4795 return (int)(m_vAdjust
->upper
+0.5);
4798 void wxWindowGTK::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4800 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4802 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4804 // No scrolling requested.
4805 if ((dx
== 0) && (dy
== 0)) return;
4808 if (!m_updateRegion
.IsEmpty())
4810 m_updateRegion
.Offset( dx
, dy
);
4814 GetClientSize( &cw
, &ch
);
4815 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
4818 if (!m_clearRegion
.IsEmpty())
4820 m_clearRegion
.Offset( dx
, dy
);
4824 GetClientSize( &cw
, &ch
);
4825 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
4829 m_clipPaintRegion
= true;
4831 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow
), -dx
, -dy
);
4833 m_clipPaintRegion
= false;
4837 // Find the wxWindow at the current mouse position, also returning the mouse
4839 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4841 pt
= wxGetMousePosition();
4842 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4846 // Get the current mouse position.
4847 wxPoint
wxGetMousePosition()
4849 /* This crashes when used within wxHelpContext,
4850 so we have to use the X-specific implementation below.
4852 GdkModifierType *mask;
4853 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4855 return wxPoint(x, y);
4859 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4861 Display
*display
= windowAtPtr
? GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4862 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4863 Window rootReturn
, childReturn
;
4864 int rootX
, rootY
, winX
, winY
;
4865 unsigned int maskReturn
;
4867 XQueryPointer (display
,
4871 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4872 return wxPoint(rootX
, rootY
);
4876 // ----------------------------------------------------------------------------
4878 // ----------------------------------------------------------------------------
4880 class wxWinModule
: public wxModule
4887 DECLARE_DYNAMIC_CLASS(wxWinModule
)
4890 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
4892 bool wxWinModule::OnInit()
4894 // g_eraseGC = gdk_gc_new( GDK_ROOT_PARENT() );
4895 // gdk_gc_set_fill( g_eraseGC, GDK_SOLID );
4900 void wxWinModule::OnExit()
4903 gdk_gc_unref( g_eraseGC
);