1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/window.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Julian Smart
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
14 #define XWarpPointer XWARPPOINTER
17 #include "wx/window.h"
18 #include "wx/dcclient.h"
21 #include "wx/layout.h"
23 #include "wx/dialog.h"
24 #include "wx/msgdlg.h"
25 #include "wx/module.h"
26 #include "wx/combobox.h"
28 #if wxUSE_DRAG_AND_DROP
33 #include "wx/tooltip.h"
41 #include "wx/textctrl.h"
45 #include "wx/statusbr.h"
47 #include "wx/settings.h"
49 #include "wx/fontutil.h"
52 #include "wx/thread.h"
58 #include "wx/gtk/private.h"
59 #include <gdk/gdkprivate.h>
60 #include <gdk/gdkkeysyms.h>
64 #include <gtk/gtkprivate.h>
66 #include "wx/gtk/win_gtk.h"
69 #include <pango/pangox.h>
80 extern GtkContainerClass
*pizza_parent_class
;
83 //-----------------------------------------------------------------------------
84 // documentation on internals
85 //-----------------------------------------------------------------------------
88 I have been asked several times about writing some documentation about
89 the GTK port of wxWidgets, especially its internal structures. Obviously,
90 you cannot understand wxGTK without knowing a little about the GTK, but
91 some more information about what the wxWindow, which is the base class
92 for all other window classes, does seems required as well.
96 What does wxWindow do? It contains the common interface for the following
97 jobs of its descendants:
99 1) Define the rudimentary behaviour common to all window classes, such as
100 resizing, intercepting user input (so as to make it possible to use these
101 events for special purposes in a derived class), window names etc.
103 2) Provide the possibility to contain and manage children, if the derived
104 class is allowed to contain children, which holds true for those window
105 classes which do not display a native GTK widget. To name them, these
106 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
107 work classes are a special case and are handled a bit differently from
108 the rest. The same holds true for the wxNotebook class.
110 3) Provide the possibility to draw into a client area of a window. This,
111 too, only holds true for classes that do not display a native GTK widget
114 4) Provide the entire mechanism for scrolling widgets. This actual inter-
115 face for this is usually in wxScrolledWindow, but the GTK implementation
118 5) A multitude of helper or extra methods for special purposes, such as
119 Drag'n'Drop, managing validators etc.
121 6) Display a border (sunken, raised, simple or none).
123 Normally one might expect, that one wxWidgets window would always correspond
124 to one GTK widget. Under GTK, there is no such allround widget that has all
125 the functionality. Moreover, the GTK defines a client area as a different
126 widget from the actual widget you are handling. Last but not least some
127 special classes (e.g. wxFrame) handle different categories of widgets and
128 still have the possibility to draw something in the client area.
129 It was therefore required to write a special purpose GTK widget, that would
130 represent a client area in the sense of wxWidgets capable to do the jobs
131 2), 3) and 4). I have written this class and it resides in win_gtk.c of
134 All windows must have a widget, with which they interact with other under-
135 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
136 thw wxWindow class has a member variable called m_widget which holds a
137 pointer to this widget. When the window class represents a GTK native widget,
138 this is (in most cases) the only GTK widget the class manages. E.g. the
139 wxStaticText class handles only a GtkLabel widget a pointer to which you
140 can find in m_widget (defined in wxWindow)
142 When the class has a client area for drawing into and for containing children
143 it has to handle the client area widget (of the type GtkPizza, defined in
144 win_gtk.c), but there could be any number of widgets, handled by a class
145 The common rule for all windows is only, that the widget that interacts with
146 the rest of GTK must be referenced in m_widget and all other widgets must be
147 children of this widget on the GTK level. The top-most widget, which also
148 represents the client area, must be in the m_wxwindow field and must be of
151 As I said, the window classes that display a GTK native widget only have
152 one widget, so in the case of e.g. the wxButton class m_widget holds a
153 pointer to a GtkButton widget. But windows with client areas (for drawing
154 and children) have a m_widget field that is a pointer to a GtkScrolled-
155 Window and a m_wxwindow field that is pointer to a GtkPizza and this
156 one is (in the GTK sense) a child of the GtkScrolledWindow.
158 If the m_wxwindow field is set, then all input to this widget is inter-
159 cepted and sent to the wxWidgets class. If not, all input to the widget
160 that gets pointed to by m_widget gets intercepted and sent to the class.
164 The design of scrolling in wxWidgets is markedly different from that offered
165 by the GTK itself and therefore we cannot simply take it as it is. In GTK,
166 clicking on a scrollbar belonging to scrolled window will inevitably move
167 the window. In wxWidgets, the scrollbar will only emit an event, send this
168 to (normally) a wxScrolledWindow and that class will call ScrollWindow()
169 which actually moves the window and its subchildren. Note that GtkPizza
170 memorizes how much it has been scrolled but that wxWidgets forgets this
171 so that the two coordinates systems have to be kept in synch. This is done
172 in various places using the pizza->xoffset and pizza->yoffset values.
176 Singularily the most broken code in GTK is the code that is supposes to
177 inform subwindows (child windows) about new positions. Very often, duplicate
178 events are sent without changes in size or position, equally often no
179 events are sent at all (All this is due to a bug in the GtkContainer code
180 which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores
181 GTK's own system and it simply waits for size events for toplevel windows
182 and then iterates down the respective size events to all window. This has
183 the disadvantage, that windows might get size events before the GTK widget
184 actually has the reported size. This doesn't normally pose any problem, but
185 the OpenGl drawing routines rely on correct behaviour. Therefore, I have
186 added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas,
187 i.e. the wxGLCanvas will emit a size event, when (and not before) the X11
188 window that is used for OpenGl output really has that size (as reported by
193 If someone at some point of time feels the immense desire to have a look at,
194 change or attempt to optimse the Refresh() logic, this person will need an
195 intimate understanding of what a "draw" and what an "expose" events are and
196 what there are used for, in particular when used in connection with GTK's
197 own windowless widgets. Beware.
201 Cursors, too, have been a constant source of pleasure. The main difficulty
202 is that a GdkWindow inherits a cursor if the programmer sets a new cursor
203 for the parent. To prevent this from doing too much harm, I use idle time
204 to set the cursor over and over again, starting from the toplevel windows
205 and ending with the youngest generation (speaking of parent and child windows).
206 Also don't forget that cursors (like much else) are connected to GdkWindows,
207 not GtkWidgets and that the "window" field of a GtkWidget might very well
208 point to the GdkWindow of the parent widget (-> "window less widget") and
209 that the two obviously have very different meanings.
213 //-----------------------------------------------------------------------------
215 //-----------------------------------------------------------------------------
217 extern wxList wxPendingDelete
;
218 extern bool g_blockEventsOnDrag
;
219 extern bool g_blockEventsOnScroll
;
220 extern wxCursor g_globalCursor
;
222 static GdkGC
*g_eraseGC
= NULL
;
224 // mouse capture state: the window which has it and if the mouse is currently
226 static wxWindowGTK
*g_captureWindow
= (wxWindowGTK
*) NULL
;
227 static bool g_captureWindowHasMouse
= false;
229 wxWindowGTK
*g_focusWindow
= (wxWindowGTK
*) NULL
;
231 // the last window which had the focus - this is normally never NULL (except
232 // if we never had focus at all) as even when g_focusWindow is NULL it still
233 // keeps its previous value
234 wxWindowGTK
*g_focusWindowLast
= (wxWindowGTK
*) NULL
;
236 // If a window get the focus set but has not been realized
237 // yet, defer setting the focus to idle time.
238 wxWindowGTK
*g_delayedFocus
= (wxWindowGTK
*) NULL
;
240 // hack: we need something to pass to gtk_menu_popup, so we store the time of
241 // the last click here
242 static guint32 gs_timeLastClick
= 0;
244 extern bool g_mainThreadLocked
;
246 //-----------------------------------------------------------------------------
248 //-----------------------------------------------------------------------------
253 # define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance");
255 # define DEBUG_MAIN_THREAD
258 #define DEBUG_MAIN_THREAD
261 // the trace mask used for the focus debugging messages
262 #define TRACE_FOCUS _T("focus")
264 //-----------------------------------------------------------------------------
265 // missing gdk functions
266 //-----------------------------------------------------------------------------
269 gdk_window_warp_pointer (GdkWindow
*window
,
274 GdkWindowPrivate
*priv
;
278 window
= GDK_ROOT_PARENT();
281 if (!GDK_WINDOW_DESTROYED(window
))
283 XWarpPointer (GDK_WINDOW_XDISPLAY(window
),
284 None
, /* not source window -> move from anywhere */
285 GDK_WINDOW_XID(window
), /* dest window */
286 0, 0, 0, 0, /* not source window -> move from anywhere */
290 priv
= (GdkWindowPrivate
*) window
;
292 if (!priv
->destroyed
)
294 XWarpPointer (priv
->xdisplay
,
295 None
, /* not source window -> move from anywhere */
296 priv
->xwindow
, /* dest window */
297 0, 0, 0, 0, /* not source window -> move from anywhere */
303 //-----------------------------------------------------------------------------
305 //-----------------------------------------------------------------------------
307 extern void wxapp_install_idle_handler();
308 extern bool g_isIdle
;
310 //-----------------------------------------------------------------------------
311 // local code (see below)
312 //-----------------------------------------------------------------------------
314 // returns the child of win which currently has focus or NULL if not found
316 // Note: can't be static, needed by textctrl.cpp.
317 wxWindow
*wxFindFocusedChild(wxWindowGTK
*win
)
319 wxWindow
*winFocus
= wxWindowGTK::FindFocus();
321 return (wxWindow
*)NULL
;
323 if ( winFocus
== win
)
324 return (wxWindow
*)win
;
326 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
328 node
= node
->GetNext() )
330 wxWindow
*child
= wxFindFocusedChild(node
->GetData());
335 return (wxWindow
*)NULL
;
338 static void draw_frame( GtkWidget
*widget
, wxWindowGTK
*win
)
340 // wxUniversal widgets draw the borders and scrollbars themselves
341 #ifndef __WXUNIVERSAL__
348 if (win
->m_hasScrolling
)
350 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(widget
);
352 GtkRequisition vscroll_req
;
353 vscroll_req
.width
= 2;
354 vscroll_req
.height
= 2;
355 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
356 (scroll_window
->vscrollbar
, &vscroll_req
);
358 GtkRequisition hscroll_req
;
359 hscroll_req
.width
= 2;
360 hscroll_req
.height
= 2;
361 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
362 (scroll_window
->hscrollbar
, &hscroll_req
);
364 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(widget
) );
366 if (scroll_window
->vscrollbar_visible
)
368 dw
+= vscroll_req
.width
;
369 dw
+= scroll_class
->scrollbar_spacing
;
372 if (scroll_window
->hscrollbar_visible
)
374 dh
+= hscroll_req
.height
;
375 dh
+= scroll_class
->scrollbar_spacing
;
381 if (GTK_WIDGET_NO_WINDOW (widget
))
383 dx
+= widget
->allocation
.x
;
384 dy
+= widget
->allocation
.y
;
387 if (win
->HasFlag(wxRAISED_BORDER
))
389 gtk_draw_shadow( widget
->style
,
394 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
398 if (win
->HasFlag(wxSUNKEN_BORDER
))
400 gtk_draw_shadow( widget
->style
,
405 widget
->allocation
.width
-dw
, widget
->allocation
.height
-dh
);
409 if (win
->HasFlag(wxSIMPLE_BORDER
))
412 gc
= gdk_gc_new( widget
->window
);
413 gdk_gc_set_foreground( gc
, &widget
->style
->black
);
414 gdk_draw_rectangle( widget
->window
, gc
, FALSE
,
416 widget
->allocation
.width
-dw
-1, widget
->allocation
.height
-dh
-1 );
420 #endif // __WXUNIVERSAL__
423 //-----------------------------------------------------------------------------
424 // "expose_event" of m_widget
425 //-----------------------------------------------------------------------------
428 static gint
gtk_window_own_expose_callback( GtkWidget
*widget
, GdkEventExpose
*gdk_event
, wxWindowGTK
*win
)
430 if (gdk_event
->count
> 0) return FALSE
;
432 draw_frame( widget
, win
);
436 (* GTK_WIDGET_CLASS (pizza_parent_class
)->expose_event
) (widget
, gdk_event
);
443 //-----------------------------------------------------------------------------
444 // "draw" of m_widget
445 //-----------------------------------------------------------------------------
450 static void gtk_window_own_draw_callback( GtkWidget
*widget
, GdkRectangle
*WXUNUSED(rect
), wxWindowGTK
*win
)
452 draw_frame( widget
, win
);
458 //-----------------------------------------------------------------------------
459 // "size_request" of m_widget
460 //-----------------------------------------------------------------------------
462 // make it extern because wxStaticText needs to disconnect this one
464 void wxgtk_window_size_request_callback(GtkWidget
*widget
,
465 GtkRequisition
*requisition
,
469 win
->GetSize( &w
, &h
);
475 requisition
->height
= h
;
476 requisition
->width
= w
;
482 void wxgtk_combo_size_request_callback(GtkWidget
*widget
,
483 GtkRequisition
*requisition
,
486 // This callback is actually hooked into the text entry
487 // of the combo box, not the GtkHBox.
490 win
->GetSize( &w
, &h
);
496 GtkCombo
*gcombo
= GTK_COMBO(win
->m_widget
);
498 GtkRequisition entry_req
;
500 entry_req
.height
= 2;
501 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo
->button
) )->size_request
)
502 (gcombo
->button
, &entry_req
);
504 requisition
->width
= w
- entry_req
.width
;
505 requisition
->height
= entry_req
.height
;
509 //-----------------------------------------------------------------------------
510 // "expose_event" of m_wxwindow
511 //-----------------------------------------------------------------------------
514 static int gtk_window_expose_callback( GtkWidget
*widget
,
515 GdkEventExpose
*gdk_event
,
521 wxapp_install_idle_handler();
524 // This callback gets called in drawing-idle time under
525 // GTK 2.0, so we don't need to defer anything to idle
528 GtkPizza
*pizza
= GTK_PIZZA( widget
);
529 if (gdk_event
->window
!= pizza
->bin_window
) return FALSE
;
534 wxPrintf( wxT("OnExpose from ") );
535 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
536 wxPrintf( win
->GetClassInfo()->GetClassName() );
537 wxPrintf( wxT(" %d %d %d %d\n"), (int)gdk_event
->area
.x
,
538 (int)gdk_event
->area
.y
,
539 (int)gdk_event
->area
.width
,
540 (int)gdk_event
->area
.height
);
545 win
->m_wxwindow
->style
,
549 (GdkRectangle
*) NULL
,
551 (char *)"button", // const_cast
556 win
->GetUpdateRegion() = wxRegion( gdk_event
->region
);
558 win
->GtkSendPaintEvents();
561 // Let parent window draw window less widgets
562 (* GTK_WIDGET_CLASS (pizza_parent_class
)->expose_event
) (widget
, gdk_event
);
564 // This gets called immediately after an expose event
565 // under GTK 1.2 so we collect the calls and wait for
566 // the idle handler to pick things up.
568 win
->GetUpdateRegion().Union( gdk_event
->area
.x
,
570 gdk_event
->area
.width
,
571 gdk_event
->area
.height
);
572 win
->m_clearRegion
.Union( gdk_event
->area
.x
,
574 gdk_event
->area
.width
,
575 gdk_event
->area
.height
);
577 // Actual redrawing takes place in idle time.
585 //-----------------------------------------------------------------------------
586 // "event" of m_wxwindow
587 //-----------------------------------------------------------------------------
591 // GTK thinks it is clever and filters out a certain amount of "unneeded"
592 // expose events. We need them, of course, so we override the main event
593 // procedure in GtkWidget by giving our own handler for all system events.
594 // There, we look for expose events ourselves whereas all other events are
599 gint
gtk_window_event_event_callback( GtkWidget
*widget
,
600 GdkEventExpose
*event
,
603 if (event
->type
== GDK_EXPOSE
)
605 gint ret
= gtk_window_expose_callback( widget
, event
, win
);
615 //-----------------------------------------------------------------------------
616 // "draw" of m_wxwindow
617 //-----------------------------------------------------------------------------
621 // This callback is a complete replacement of the gtk_pizza_draw() function,
622 // which is disabled.
625 static void gtk_window_draw_callback( GtkWidget
*widget
,
632 wxapp_install_idle_handler();
634 // if there are any children we must refresh everything
637 if ( !win
->HasFlag(wxFULL_REPAINT_ON_RESIZE
) &&
638 win
->GetChildren().IsEmpty() )
646 wxPrintf( wxT("OnDraw from ") );
647 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
648 wxPrintf( win
->GetClassInfo()->GetClassName() );
649 wxPrintf( wxT(" %d %d %d %d\n"), (int)rect
->x
,
656 #ifndef __WXUNIVERSAL__
657 GtkPizza
*pizza
= GTK_PIZZA (widget
);
659 if (win
->GetThemeEnabled() && win
->GetBackgroundStyle() == wxBG_STYLE_SYSTEM
)
661 wxWindow
*parent
= win
->GetParent();
662 while (parent
&& !parent
->IsTopLevel())
663 parent
= parent
->GetParent();
667 gtk_paint_flat_box (parent
->m_widget
->style
,
678 win
->m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
679 win
->GetUpdateRegion().Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
681 // Update immediately, not in idle time.
684 #ifndef __WXUNIVERSAL__
685 // Redraw child widgets
686 GList
*children
= pizza
->children
;
689 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
690 children
= children
->next
;
692 GdkRectangle child_area
;
693 if (gtk_widget_intersect (child
->widget
, rect
, &child_area
))
695 gtk_widget_draw (child
->widget
, &child_area
/* (GdkRectangle*) NULL*/ );
704 //-----------------------------------------------------------------------------
705 // "key_press_event" from any window
706 //-----------------------------------------------------------------------------
708 // set WXTRACE to this to see the key event codes on the console
709 #define TRACE_KEYS _T("keyevent")
711 // translates an X key symbol to WXK_XXX value
713 // if isChar is true it means that the value returned will be used for EVT_CHAR
714 // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide,
715 // for example, while if it is false it means that the value is going to be
716 // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to
718 static long wxTranslateKeySymToWXKey(KeySym keysym
, bool isChar
)
724 // Shift, Control and Alt don't generate the CHAR events at all
727 key_code
= isChar
? 0 : WXK_SHIFT
;
731 key_code
= isChar
? 0 : WXK_CONTROL
;
739 key_code
= isChar
? 0 : WXK_ALT
;
742 // neither do the toggle modifies
743 case GDK_Scroll_Lock
:
744 key_code
= isChar
? 0 : WXK_SCROLL
;
748 key_code
= isChar
? 0 : WXK_CAPITAL
;
752 key_code
= isChar
? 0 : WXK_NUMLOCK
;
756 // various other special keys
769 case GDK_ISO_Left_Tab
:
776 key_code
= WXK_RETURN
;
780 key_code
= WXK_CLEAR
;
784 key_code
= WXK_PAUSE
;
788 key_code
= WXK_SELECT
;
792 key_code
= WXK_PRINT
;
796 key_code
= WXK_EXECUTE
;
800 key_code
= WXK_ESCAPE
;
803 // cursor and other extended keyboard keys
805 key_code
= WXK_DELETE
;
821 key_code
= WXK_RIGHT
;
828 case GDK_Prior
: // == GDK_Page_Up
829 key_code
= WXK_PRIOR
;
832 case GDK_Next
: // == GDK_Page_Down
845 key_code
= WXK_INSERT
;
860 key_code
= (isChar
? '0' : WXK_NUMPAD0
) + keysym
- GDK_KP_0
;
864 key_code
= isChar
? ' ' : WXK_NUMPAD_SPACE
;
868 key_code
= isChar
? WXK_TAB
: WXK_NUMPAD_TAB
;
872 key_code
= isChar
? WXK_RETURN
: WXK_NUMPAD_ENTER
;
876 key_code
= isChar
? WXK_F1
: WXK_NUMPAD_F1
;
880 key_code
= isChar
? WXK_F2
: WXK_NUMPAD_F2
;
884 key_code
= isChar
? WXK_F3
: WXK_NUMPAD_F3
;
888 key_code
= isChar
? WXK_F4
: WXK_NUMPAD_F4
;
892 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_HOME
;
896 key_code
= isChar
? WXK_LEFT
: WXK_NUMPAD_LEFT
;
900 key_code
= isChar
? WXK_UP
: WXK_NUMPAD_UP
;
904 key_code
= isChar
? WXK_RIGHT
: WXK_NUMPAD_RIGHT
;
908 key_code
= isChar
? WXK_DOWN
: WXK_NUMPAD_DOWN
;
911 case GDK_KP_Prior
: // == GDK_KP_Page_Up
912 key_code
= isChar
? WXK_PRIOR
: WXK_NUMPAD_PRIOR
;
915 case GDK_KP_Next
: // == GDK_KP_Page_Down
916 key_code
= isChar
? WXK_NEXT
: WXK_NUMPAD_NEXT
;
920 key_code
= isChar
? WXK_END
: WXK_NUMPAD_END
;
924 key_code
= isChar
? WXK_HOME
: WXK_NUMPAD_BEGIN
;
928 key_code
= isChar
? WXK_INSERT
: WXK_NUMPAD_INSERT
;
932 key_code
= isChar
? WXK_DELETE
: WXK_NUMPAD_DELETE
;
936 key_code
= isChar
? '=' : WXK_NUMPAD_EQUAL
;
939 case GDK_KP_Multiply
:
940 key_code
= isChar
? '*' : WXK_NUMPAD_MULTIPLY
;
944 key_code
= isChar
? '+' : WXK_NUMPAD_ADD
;
947 case GDK_KP_Separator
:
948 // FIXME: what is this?
949 key_code
= isChar
? '.' : WXK_NUMPAD_SEPARATOR
;
952 case GDK_KP_Subtract
:
953 key_code
= isChar
? '-' : WXK_NUMPAD_SUBTRACT
;
957 key_code
= isChar
? '.' : WXK_NUMPAD_DECIMAL
;
961 key_code
= isChar
? '/' : WXK_NUMPAD_DIVIDE
;
978 key_code
= WXK_F1
+ keysym
- GDK_F1
;
988 static inline bool wxIsAsciiKeysym(KeySym ks
)
993 static void wxFillOtherKeyEventFields(wxKeyEvent
& event
,
995 GdkEventKey
*gdk_event
)
999 GdkModifierType state
;
1000 if (gdk_event
->window
)
1001 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1003 event
.SetTimestamp( gdk_event
->time
);
1004 event
.SetId(win
->GetId());
1005 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
) != 0;
1006 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
) != 0;
1007 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
) != 0;
1008 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
) != 0;
1009 event
.m_scanCode
= gdk_event
->keyval
;
1010 event
.m_rawCode
= (wxUint32
) gdk_event
->keyval
;
1011 event
.m_rawFlags
= 0;
1013 event
.m_uniChar
= gdk_keyval_to_unicode(gdk_event
->keyval
);
1015 wxGetMousePosition( &x
, &y
);
1016 win
->ScreenToClient( &x
, &y
);
1019 event
.SetEventObject( win
);
1024 wxTranslateGTKKeyEventToWx(wxKeyEvent
& event
,
1026 GdkEventKey
*gdk_event
)
1028 // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string
1029 // but only event->keyval which is quite useless to us, so remember
1030 // the last character from GDK_KEY_PRESS and reuse it as last resort
1032 // NB: should be MT-safe as we're always called from the main thread only
1037 } s_lastKeyPress
= { 0, 0 };
1039 KeySym keysym
= gdk_event
->keyval
;
1041 wxLogTrace(TRACE_KEYS
, _T("Key %s event: keysym = %ld"),
1042 event
.GetEventType() == wxEVT_KEY_UP
? _T("release")
1046 long key_code
= wxTranslateKeySymToWXKey(keysym
, false /* !isChar */);
1050 // do we have the translation or is it a plain ASCII character?
1051 if ( (gdk_event
->length
== 1) || wxIsAsciiKeysym(keysym
) )
1053 // we should use keysym if it is ASCII as X does some translations
1054 // like "I pressed while Control is down" => "Ctrl-I" == "TAB"
1055 // which we don't want here (but which we do use for OnChar())
1056 if ( !wxIsAsciiKeysym(keysym
) )
1058 keysym
= (KeySym
)gdk_event
->string
[0];
1061 // we want to always get the same key code when the same key is
1062 // pressed regardless of the state of the modifies, i.e. on a
1063 // standard US keyboard pressing '5' or '%' ('5' key with
1064 // Shift) should result in the same key code in OnKeyDown():
1065 // '5' (although OnChar() will get either '5' or '%').
1067 // to do it we first translate keysym to keycode (== scan code)
1068 // and then back but always using the lower register
1069 Display
*dpy
= (Display
*)wxGetDisplay();
1070 KeyCode keycode
= XKeysymToKeycode(dpy
, keysym
);
1072 wxLogTrace(TRACE_KEYS
, _T("\t-> keycode %d"), keycode
);
1074 KeySym keysymNormalized
= XKeycodeToKeysym(dpy
, keycode
, 0);
1076 // use the normalized, i.e. lower register, keysym if we've
1078 key_code
= keysymNormalized
? keysymNormalized
: keysym
;
1080 // as explained above, we want to have lower register key codes
1081 // normally but for the letter keys we want to have the upper ones
1083 // NB: don't use XConvertCase() here, we want to do it for letters
1085 key_code
= toupper(key_code
);
1087 else // non ASCII key, what to do?
1089 // by default, ignore it
1092 // but if we have cached information from the last KEY_PRESS
1093 if ( gdk_event
->type
== GDK_KEY_RELEASE
)
1096 if ( keysym
== s_lastKeyPress
.keysym
)
1098 key_code
= s_lastKeyPress
.keycode
;
1103 if ( gdk_event
->type
== GDK_KEY_PRESS
)
1105 // remember it to be reused for KEY_UP event later
1106 s_lastKeyPress
.keysym
= keysym
;
1107 s_lastKeyPress
.keycode
= key_code
;
1111 wxLogTrace(TRACE_KEYS
, _T("\t-> wxKeyCode %ld"), key_code
);
1113 // sending unknown key events doesn't really make sense
1117 // now fill all the other fields
1118 wxFillOtherKeyEventFields(event
, win
, gdk_event
);
1120 event
.m_keyCode
= key_code
;
1129 GtkIMContext
*context
;
1130 GdkEventKey
*lastKeyEvent
;
1134 context
= gtk_im_multicontext_new();
1135 lastKeyEvent
= NULL
;
1139 g_object_unref(context
);
1145 static gint
gtk_window_key_press_callback( GtkWidget
*widget
,
1146 GdkEventKey
*gdk_event
,
1152 wxapp_install_idle_handler();
1156 if (g_blockEventsOnDrag
)
1160 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1162 bool return_after_IM
= false;
1164 if( wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1166 // Emit KEY_DOWN event
1167 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1171 // Return after IM processing as we cannot do
1172 // anything with it anyhow.
1173 return_after_IM
= true;
1177 // 2005.01.26 modified by Hong Jen Yee (hzysoft@sina.com.tw):
1178 // When we get a key_press event here, it could be originate
1179 // from the current widget or its child widgets. However, only the widget
1180 // with the INPUT FOCUS can generate the INITIAL key_press event. That is,
1181 // if the CURRENT widget doesn't have the FOCUS at all, this event definitely
1182 // originated from its child widgets and shouldn't be passed to IM context.
1183 // In fact, what a GTK+ IM should do is filtering keyEvents and convert them
1184 // into text input ONLY WHEN THE WIDGET HAS INPUT FOCUS. Besides, when current
1185 // widgets has both IM context and input focus, the event should be filtered
1186 // by gtk_im_context_filter_keypress().
1187 // Then, we should, according to GTK+ 2.0 API doc, return whatever it returns.
1188 if ((!ret
) && (win
->m_imData
!= NULL
) && ( wxWindow::FindFocus() == win
))
1190 // We should let GTK+ IM filter key event first. According to GTK+ 2.0 API
1191 // docs, if IM filter returns true, no further processing should be done.
1192 // we should send the key_down event anyway.
1193 bool intercepted_by_IM
= gtk_im_context_filter_keypress(win
->m_imData
->context
, gdk_event
);
1194 win
->m_imData
->lastKeyEvent
= NULL
;
1195 if (intercepted_by_IM
)
1197 wxLogTrace(TRACE_KEYS
, _T("Key event intercepted by IM"));
1202 if (return_after_IM
)
1206 // This is for GTK+ 1.2 only. The char event generatation for GTK+ 2.0 is done
1207 // in the "commit" handler.
1209 // 2005.02.02 modified by Hong Jen Yee (hzysoft@sina.com.tw).
1210 // In GTK+ 1.2, strings sent by IMs are also regarded as key_press events whose
1211 // keyCodes cannot be recognized by wxWidgets. These MBCS strings, however, are
1212 // composed of more than one character, which means gdk_event->length will always
1213 // greater than one. When gtk_event->length == 1, this may be an ASCII character
1214 // and can be translated by wx. However, when MBCS characters are sent by IM,
1215 // gdk_event->length will >= 2. So neither should we pass it to accelerator table,
1216 // nor should we pass it to controls. The following explanation was excerpted
1217 // from GDK documentation.
1218 // gint length : the length of string.
1219 // gchar *string : a null-terminated multi-byte string containing the composed
1220 // characters resulting from the key press. When text is being input, in a GtkEntry
1221 // for example, it is these characters which should be added to the input buffer.
1222 // When using Input Methods to support internationalized text input, the composed
1223 // characters appear here after the pre-editing has been completed.
1225 if ( (!ret
) && (gdk_event
->length
> 1) ) // If this event contains a pre-edited string from IM.
1227 // We should translate this key event into wxEVT_CHAR not wxEVT_KEY_DOWN.
1228 #if wxUSE_UNICODE // GTK+ 1.2 is not UTF-8 based.
1229 const wxWCharBuffer string
= wxConvLocal
.cMB2WC( gdk_event
->string
);
1233 const char* string
= gdk_event
->string
;
1236 // Implement OnCharHook by checking ancesteror top level windows
1237 wxWindow
*parent
= win
;
1238 while (parent
&& !parent
->IsTopLevel())
1239 parent
= parent
->GetParent();
1241 for( const wxChar
* pstr
= string
; *pstr
; pstr
++ )
1244 event
.m_uniChar
= *pstr
;
1245 // Backward compatible for ISO-8859-1
1246 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1248 event
.m_keyCode
= *pstr
;
1252 event
.SetEventType( wxEVT_CHAR_HOOK
);
1253 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1257 event
.SetEventType(wxEVT_CHAR
);
1258 win
->GetEventHandler()->ProcessEvent( event
);
1264 #endif // #ifndef __WXGTK20__
1269 wxWindowGTK
*ancestor
= win
;
1272 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1275 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1276 ret
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1279 if (ancestor
->IsTopLevel())
1281 ancestor
= ancestor
->GetParent();
1284 #endif // wxUSE_ACCEL
1286 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
1287 // will only be sent if it is not in an accelerator table.
1291 KeySym keysym
= gdk_event
->keyval
;
1292 // Find key code for EVT_CHAR and EVT_CHAR_HOOK events
1293 key_code
= wxTranslateKeySymToWXKey(keysym
, true /* isChar */);
1296 if ( wxIsAsciiKeysym(keysym
) )
1299 key_code
= (unsigned char)keysym
;
1301 // gdk_event->string is actually deprecated
1302 else if ( gdk_event
->length
== 1 )
1304 key_code
= (unsigned char)gdk_event
->string
[0];
1310 wxLogTrace(TRACE_KEYS
, _T("Char event: %ld"), key_code
);
1312 event
.m_keyCode
= key_code
;
1314 // Implement OnCharHook by checking ancesteror top level windows
1315 wxWindow
*parent
= win
;
1316 while (parent
&& !parent
->IsTopLevel())
1317 parent
= parent
->GetParent();
1320 event
.SetEventType( wxEVT_CHAR_HOOK
);
1321 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1326 event
.SetEventType(wxEVT_CHAR
);
1327 ret
= win
->GetEventHandler()->ProcessEvent( event
);
1336 // win is a control: tab can be propagated up
1338 ((gdk_event
->keyval
== GDK_Tab
) || (gdk_event
->keyval
== GDK_ISO_Left_Tab
)) &&
1339 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1340 // have this style, yet choose not to process this particular TAB in which
1341 // case TAB must still work as a navigational character
1342 // JS: enabling again to make consistent with other platforms
1343 // (with wxTE_PROCESS_TAB you have to call Navigate to get default
1344 // navigation behaviour)
1346 (! (win
->HasFlag(wxTE_PROCESS_TAB
) && win
->IsKindOf(CLASSINFO(wxTextCtrl
)) )) &&
1348 win
->GetParent() && (win
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1350 wxNavigationKeyEvent new_event
;
1351 new_event
.SetEventObject( win
->GetParent() );
1352 // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB
1353 new_event
.SetDirection( (gdk_event
->keyval
== GDK_Tab
) );
1354 // CTRL-TAB changes the (parent) window, i.e. switch notebook page
1355 new_event
.SetWindowChange( (gdk_event
->state
& GDK_CONTROL_MASK
) );
1356 new_event
.SetCurrentFocus( win
);
1357 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent( new_event
);
1360 // generate wxID_CANCEL if <esc> has been pressed (typically in dialogs)
1362 (gdk_event
->keyval
== GDK_Escape
) )
1364 // however only do it if we have a Cancel button in the dialog,
1365 // otherwise the user code may get confused by the events from a
1366 // non-existing button and, worse, a wxButton might get button event
1367 // from another button which is not really expected
1368 wxWindow
*winForCancel
= win
,
1370 while ( winForCancel
)
1372 btnCancel
= winForCancel
->FindWindow(wxID_CANCEL
);
1375 // found a cancel button
1379 if ( winForCancel
->IsTopLevel() )
1381 // no need to look further
1385 // maybe our parent has a cancel button?
1386 winForCancel
= winForCancel
->GetParent();
1391 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
1392 event
.SetEventObject(btnCancel
);
1393 ret
= btnCancel
->GetEventHandler()->ProcessEvent(event
);
1399 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
1409 static void gtk_wxwindow_commit_cb (GtkIMContext
*context
,
1413 wxKeyEvent
event( wxEVT_KEY_DOWN
);
1415 // take modifiers, cursor position, timestamp etc. from the last
1416 // key_press_event that was fed into Input Method:
1417 if (window
->m_imData
->lastKeyEvent
)
1419 wxFillOtherKeyEventFields(event
,
1420 window
, window
->m_imData
->lastKeyEvent
);
1424 const wxWCharBuffer data
= wxConvUTF8
.cMB2WC( (char*)str
);
1426 const wxWCharBuffer wdata
= wxConvUTF8
.cMB2WC( (char*)str
);
1427 const wxCharBuffer data
= wxConvLocal
.cWC2MB( wdata
);
1428 #endif // wxUSE_UNICODE
1429 if( !(const wxChar
*)data
)
1434 // Implement OnCharHook by checking ancestor top level windows
1435 wxWindow
*parent
= window
;
1436 while (parent
&& !parent
->IsTopLevel())
1437 parent
= parent
->GetParent();
1439 for( const wxChar
* pstr
= data
; *pstr
; pstr
++ )
1442 event
.m_uniChar
= *pstr
;
1443 // Backward compatible for ISO-8859-1
1444 event
.m_keyCode
= *pstr
< 256 ? event
.m_uniChar
: 0;
1445 wxLogTrace(TRACE_KEYS
, _T("IM sent character '%c'"), event
.m_uniChar
);
1447 event
.m_keyCode
= *pstr
;
1448 #endif // wxUSE_UNICODE
1451 event
.SetEventType( wxEVT_CHAR_HOOK
);
1452 ret
= parent
->GetEventHandler()->ProcessEvent( event
);
1457 event
.SetEventType(wxEVT_CHAR
);
1458 ret
= window
->GetEventHandler()->ProcessEvent( event
);
1466 //-----------------------------------------------------------------------------
1467 // "key_release_event" from any window
1468 //-----------------------------------------------------------------------------
1471 static gint
gtk_window_key_release_callback( GtkWidget
*widget
,
1472 GdkEventKey
*gdk_event
,
1478 wxapp_install_idle_handler();
1483 if (g_blockEventsOnDrag
)
1486 wxKeyEvent
event( wxEVT_KEY_UP
);
1487 if ( !wxTranslateGTKKeyEventToWx(event
, win
, gdk_event
) )
1489 // unknown key pressed, ignore (the event would be useless anyhow
1493 if ( !win
->GetEventHandler()->ProcessEvent( event
) )
1496 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_release_event" );
1501 // ============================================================================
1503 // ============================================================================
1505 // ----------------------------------------------------------------------------
1506 // mouse event processing helpers
1507 // ----------------------------------------------------------------------------
1509 // init wxMouseEvent with the info from GdkEventXXX struct
1510 template<typename T
> void InitMouseEvent(wxWindowGTK
*win
,
1511 wxMouseEvent
& event
,
1514 event
.SetTimestamp( gdk_event
->time
);
1515 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
1516 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
1517 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
1518 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
1519 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
1520 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
1521 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
1522 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
1524 event
.m_linesPerAction
= 3;
1525 event
.m_wheelDelta
= 120;
1526 if (((GdkEventButton
*)gdk_event
)->button
== 4)
1527 event
.m_wheelRotation
= 120;
1528 else if (((GdkEventButton
*)gdk_event
)->button
== 5)
1529 event
.m_wheelRotation
= -120;
1532 wxPoint pt
= win
->GetClientAreaOrigin();
1533 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
1534 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
1536 event
.SetEventObject( win
);
1537 event
.SetId( win
->GetId() );
1538 event
.SetTimestamp( gdk_event
->time
);
1541 static void AdjustEventButtonState(wxMouseEvent
& event
)
1543 // GDK reports the old state of the button for a button press event, but
1544 // for compatibility with MSW and common sense we want m_leftDown be TRUE
1545 // for a LEFT_DOWN event, not FALSE, so we will invert
1546 // left/right/middleDown for the corresponding click events
1548 if ((event
.GetEventType() == wxEVT_LEFT_DOWN
) ||
1549 (event
.GetEventType() == wxEVT_LEFT_DCLICK
) ||
1550 (event
.GetEventType() == wxEVT_LEFT_UP
))
1552 event
.m_leftDown
= !event
.m_leftDown
;
1556 if ((event
.GetEventType() == wxEVT_MIDDLE_DOWN
) ||
1557 (event
.GetEventType() == wxEVT_MIDDLE_DCLICK
) ||
1558 (event
.GetEventType() == wxEVT_MIDDLE_UP
))
1560 event
.m_middleDown
= !event
.m_middleDown
;
1564 if ((event
.GetEventType() == wxEVT_RIGHT_DOWN
) ||
1565 (event
.GetEventType() == wxEVT_RIGHT_DCLICK
) ||
1566 (event
.GetEventType() == wxEVT_RIGHT_UP
))
1568 event
.m_rightDown
= !event
.m_rightDown
;
1573 // find the window to send the mouse event too
1575 wxWindowGTK
*FindWindowForMouseEvent(wxWindowGTK
*win
, wxCoord
& x
, wxCoord
& y
)
1580 if (win
->m_wxwindow
)
1582 GtkPizza
*pizza
= GTK_PIZZA(win
->m_wxwindow
);
1583 xx
+= pizza
->xoffset
;
1584 yy
+= pizza
->yoffset
;
1587 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
1590 wxWindowGTK
*child
= node
->GetData();
1592 node
= node
->GetNext();
1593 if (!child
->IsShown())
1596 if (child
->IsTransparentForMouse())
1598 // wxStaticBox is transparent in the box itself
1599 int xx1
= child
->m_x
;
1600 int yy1
= child
->m_y
;
1601 int xx2
= child
->m_x
+ child
->m_width
;
1602 int yy2
= child
->m_y
+ child
->m_height
;
1605 if (((xx
>= xx1
) && (xx
<= xx1
+10) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1607 ((xx
>= xx2
-10) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy2
)) ||
1609 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy1
) && (yy
<= yy1
+10)) ||
1611 ((xx
>= xx1
) && (xx
<= xx2
) && (yy
>= yy2
-1) && (yy
<= yy2
)))
1622 if ((child
->m_wxwindow
== (GtkWidget
*) NULL
) &&
1623 (child
->m_x
<= xx
) &&
1624 (child
->m_y
<= yy
) &&
1625 (child
->m_x
+child
->m_width
>= xx
) &&
1626 (child
->m_y
+child
->m_height
>= yy
))
1639 //-----------------------------------------------------------------------------
1640 // "button_press_event"
1641 //-----------------------------------------------------------------------------
1644 static gint
gtk_window_button_press_callback( GtkWidget
*widget
,
1645 GdkEventButton
*gdk_event
,
1651 wxapp_install_idle_handler();
1654 wxPrintf( wxT("1) OnButtonPress from ") );
1655 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1656 wxPrintf( win->GetClassInfo()->GetClassName() );
1657 wxPrintf( wxT(".\n") );
1659 if (!win
->m_hasVMT
) return FALSE
;
1660 if (g_blockEventsOnDrag
) return TRUE
;
1661 if (g_blockEventsOnScroll
) return TRUE
;
1663 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1665 if (win
->m_wxwindow
&& (g_focusWindow
!= win
) && win
->AcceptsFocus())
1667 gtk_widget_grab_focus( win
->m_wxwindow
);
1669 wxPrintf( wxT("GrabFocus from ") );
1670 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1671 wxPrintf( win->GetClassInfo()->GetClassName() );
1672 wxPrintf( wxT(".\n") );
1676 // GDK sends surplus button down event
1677 // before a double click event. We
1678 // need to filter these out.
1679 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1681 GdkEvent
*peek_event
= gdk_event_peek();
1684 if ((peek_event
->type
== GDK_2BUTTON_PRESS
) ||
1685 (peek_event
->type
== GDK_3BUTTON_PRESS
))
1687 gdk_event_free( peek_event
);
1692 gdk_event_free( peek_event
);
1697 wxEventType event_type
= wxEVT_NULL
;
1699 // GdkDisplay is a GTK+ 2.2.0 thing
1700 #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2, 2, 0)
1701 if ( gdk_event
->type
== GDK_2BUTTON_PRESS
&&
1702 !gtk_check_version(2,2,0) &&
1703 gdk_event
->button
>= 1 && gdk_event
->button
<= 3 )
1705 // Reset GDK internal timestamp variables in order to disable GDK
1706 // triple click events. GDK will then next time believe no button has
1707 // been clicked just before, and send a normal button click event.
1708 GdkDisplay
* display
= gtk_widget_get_display (widget
);
1709 display
->button_click_time
[1] = 0;
1710 display
->button_click_time
[0] = 0;
1714 if (gdk_event
->button
== 1)
1716 // note that GDK generates triple click events which are not supported
1717 // by wxWidgets but still have to be passed to the app as otherwise
1718 // clicks would simply go missing
1719 switch (gdk_event
->type
)
1721 // we shouldn't get triple clicks at all for GTK2 because we
1722 // suppress them artificially using the code above but we still
1723 // should map them to something for GTK1 and not just ignore them
1724 // as this would lose clicks
1725 case GDK_3BUTTON_PRESS
: // we could also map this to DCLICK...
1726 case GDK_BUTTON_PRESS
:
1727 event_type
= wxEVT_LEFT_DOWN
;
1730 case GDK_2BUTTON_PRESS
:
1731 event_type
= wxEVT_LEFT_DCLICK
;
1735 // just to silence gcc warnings
1739 else if (gdk_event
->button
== 2)
1741 switch (gdk_event
->type
)
1743 case GDK_3BUTTON_PRESS
:
1744 case GDK_BUTTON_PRESS
:
1745 event_type
= wxEVT_MIDDLE_DOWN
;
1748 case GDK_2BUTTON_PRESS
:
1749 event_type
= wxEVT_MIDDLE_DCLICK
;
1756 else if (gdk_event
->button
== 3)
1758 switch (gdk_event
->type
)
1760 case GDK_3BUTTON_PRESS
:
1761 case GDK_BUTTON_PRESS
:
1762 event_type
= wxEVT_RIGHT_DOWN
;
1765 case GDK_2BUTTON_PRESS
:
1766 event_type
= wxEVT_RIGHT_DCLICK
;
1773 else if (gdk_event
->button
== 4 || gdk_event
->button
== 5)
1775 if (gdk_event
->type
== GDK_BUTTON_PRESS
)
1777 event_type
= wxEVT_MOUSEWHEEL
;
1781 if ( event_type
== wxEVT_NULL
)
1783 // unknown mouse button or click type
1787 wxMouseEvent
event( event_type
);
1788 InitMouseEvent( win
, event
, gdk_event
);
1790 AdjustEventButtonState(event
);
1792 // wxListBox actually get mouse events from the item, so we need to give it
1793 // a chance to correct this
1794 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1796 // find the correct window to send the event too: it may be a different one
1797 // from the one which got it at GTK+ level because some control don't have
1798 // their own X window and thus cannot get any events.
1799 if ( !g_captureWindow
)
1800 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1802 gs_timeLastClick
= gdk_event
->time
;
1805 if (event_type
== wxEVT_LEFT_DCLICK
)
1807 // GTK 1.2 crashes when intercepting double
1808 // click events from both wxSpinButton and
1810 if (GTK_IS_SPIN_BUTTON(win
->m_widget
))
1812 // Just disable this event for now.
1818 if (win
->GetEventHandler()->ProcessEvent( event
))
1820 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_press_event" );
1824 if (event_type
== wxEVT_RIGHT_DOWN
)
1826 // generate a "context menu" event: this is similar to right mouse
1827 // click under many GUIs except that it is generated differently
1828 // (right up under MSW, ctrl-click under Mac, right down here) and
1830 // (a) it's a command event and so is propagated to the parent
1831 // (b) under some ports it can be generated from kbd too
1832 // (c) it uses screen coords (because of (a))
1833 wxContextMenuEvent
evtCtx(
1836 win
->ClientToScreen(event
.GetPosition()));
1837 evtCtx
.SetEventObject(win
);
1838 return win
->GetEventHandler()->ProcessEvent(evtCtx
);
1845 //-----------------------------------------------------------------------------
1846 // "button_release_event"
1847 //-----------------------------------------------------------------------------
1850 static gint
gtk_window_button_release_callback( GtkWidget
*widget
,
1851 GdkEventButton
*gdk_event
,
1857 wxapp_install_idle_handler();
1859 if (!win
->m_hasVMT
) return FALSE
;
1860 if (g_blockEventsOnDrag
) return FALSE
;
1861 if (g_blockEventsOnScroll
) return FALSE
;
1863 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1865 wxEventType event_type
= wxEVT_NULL
;
1867 switch (gdk_event
->button
)
1870 event_type
= wxEVT_LEFT_UP
;
1874 event_type
= wxEVT_MIDDLE_UP
;
1878 event_type
= wxEVT_RIGHT_UP
;
1882 // unknwon button, don't process
1886 wxMouseEvent
event( event_type
);
1887 InitMouseEvent( win
, event
, gdk_event
);
1889 AdjustEventButtonState(event
);
1891 // same wxListBox hack as above
1892 win
->FixUpMouseEvent(widget
, event
.m_x
, event
.m_y
);
1894 if ( !g_captureWindow
)
1895 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1897 if (win
->GetEventHandler()->ProcessEvent( event
))
1899 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_release_event" );
1907 //-----------------------------------------------------------------------------
1908 // "motion_notify_event"
1909 //-----------------------------------------------------------------------------
1912 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
,
1913 GdkEventMotion
*gdk_event
,
1919 wxapp_install_idle_handler();
1921 if (!win
->m_hasVMT
) return FALSE
;
1922 if (g_blockEventsOnDrag
) return FALSE
;
1923 if (g_blockEventsOnScroll
) return FALSE
;
1925 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
1927 if (gdk_event
->is_hint
)
1931 GdkModifierType state
;
1932 gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
);
1938 printf( "OnMotion from " );
1939 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1940 printf( win->GetClassInfo()->GetClassName() );
1944 wxMouseEvent
event( wxEVT_MOTION
);
1945 InitMouseEvent(win
, event
, gdk_event
);
1947 if ( g_captureWindow
)
1949 // synthetize a mouse enter or leave event if needed
1950 GdkWindow
*winUnderMouse
= gdk_window_at_pointer(NULL
, NULL
);
1951 // This seems to be necessary and actually been added to
1952 // GDK itself in version 2.0.X
1955 bool hasMouse
= winUnderMouse
== gdk_event
->window
;
1956 if ( hasMouse
!= g_captureWindowHasMouse
)
1958 // the mouse changed window
1959 g_captureWindowHasMouse
= hasMouse
;
1961 wxMouseEvent
event(g_captureWindowHasMouse
? wxEVT_ENTER_WINDOW
1962 : wxEVT_LEAVE_WINDOW
);
1963 InitMouseEvent(win
, event
, gdk_event
);
1964 event
.SetEventObject(win
);
1965 win
->GetEventHandler()->ProcessEvent(event
);
1970 win
= FindWindowForMouseEvent(win
, event
.m_x
, event
.m_y
);
1973 if (win
->GetEventHandler()->ProcessEvent( event
))
1975 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "motion_notify_event" );
1984 //-----------------------------------------------------------------------------
1985 // "mouse_wheel_event"
1986 //-----------------------------------------------------------------------------
1989 static gint
gtk_window_wheel_callback (GtkWidget
* widget
,
1990 GdkEventScroll
* gdk_event
,
1996 wxapp_install_idle_handler();
1998 wxEventType event_type
= wxEVT_NULL
;
1999 if (gdk_event
->direction
== GDK_SCROLL_UP
)
2000 event_type
= wxEVT_MOUSEWHEEL
;
2001 else if (gdk_event
->direction
== GDK_SCROLL_DOWN
)
2002 event_type
= wxEVT_MOUSEWHEEL
;
2006 wxMouseEvent
event( event_type
);
2007 // Can't use InitMouse macro because scroll events don't have button
2008 event
.SetTimestamp( gdk_event
->time
);
2009 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
2010 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
2011 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
2012 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
2013 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
2014 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
2015 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
2016 event
.m_linesPerAction
= 3;
2017 event
.m_wheelDelta
= 120;
2018 if (gdk_event
->direction
== GDK_SCROLL_UP
)
2019 event
.m_wheelRotation
= 120;
2021 event
.m_wheelRotation
= -120;
2023 wxPoint pt
= win
->GetClientAreaOrigin();
2024 event
.m_x
= (wxCoord
)gdk_event
->x
- pt
.x
;
2025 event
.m_y
= (wxCoord
)gdk_event
->y
- pt
.y
;
2027 event
.SetEventObject( win
);
2028 event
.SetId( win
->GetId() );
2029 event
.SetTimestamp( gdk_event
->time
);
2031 if (win
->GetEventHandler()->ProcessEvent( event
))
2033 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "scroll_event" );
2041 //-----------------------------------------------------------------------------
2043 //-----------------------------------------------------------------------------
2045 static gboolean
wxgtk_window_popup_menu_callback(GtkWidget
*, wxWindowGTK
* win
)
2047 wxContextMenuEvent
event(
2051 event
.SetEventObject(win
);
2052 return win
->GetEventHandler()->ProcessEvent(event
);
2055 #endif // __WXGTK20__
2057 //-----------------------------------------------------------------------------
2059 //-----------------------------------------------------------------------------
2061 // send the wxChildFocusEvent and wxFocusEvent, common code of
2062 // gtk_window_focus_in_callback() and SetFocus()
2063 static bool DoSendFocusEvents(wxWindow
*win
)
2065 // Notify the parent keeping track of focus for the kbd navigation
2066 // purposes that we got it.
2067 wxChildFocusEvent
eventChildFocus(win
);
2068 (void)win
->GetEventHandler()->ProcessEvent(eventChildFocus
);
2070 wxFocusEvent
eventFocus(wxEVT_SET_FOCUS
, win
->GetId());
2071 eventFocus
.SetEventObject(win
);
2073 return win
->GetEventHandler()->ProcessEvent(eventFocus
);
2077 static gint
gtk_window_focus_in_callback( GtkWidget
*widget
,
2078 GdkEvent
*WXUNUSED(event
),
2084 wxapp_install_idle_handler();
2088 gtk_im_context_focus_in(win
->m_imData
->context
);
2092 g_focusWindow
= win
;
2094 wxLogTrace(TRACE_FOCUS
,
2095 _T("%s: focus in"), win
->GetName().c_str());
2099 gdk_im_begin(win
->m_ic
, win
->m_wxwindow
->window
);
2103 // caret needs to be informed about focus change
2104 wxCaret
*caret
= win
->GetCaret();
2107 caret
->OnSetFocus();
2109 #endif // wxUSE_CARET
2111 // does the window itself think that it has the focus?
2112 if ( !win
->m_hasFocus
)
2114 // not yet, notify it
2115 win
->m_hasFocus
= true;
2117 if ( DoSendFocusEvents(win
) )
2119 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_in_event" );
2128 //-----------------------------------------------------------------------------
2129 // "focus_out_event"
2130 //-----------------------------------------------------------------------------
2133 static gint
gtk_window_focus_out_callback( GtkWidget
*widget
, GdkEventFocus
*gdk_event
, wxWindowGTK
*win
)
2138 wxapp_install_idle_handler();
2142 gtk_im_context_focus_out(win
->m_imData
->context
);
2145 wxLogTrace( TRACE_FOCUS
,
2146 _T("%s: focus out"), win
->GetName().c_str() );
2149 wxWindowGTK
*winFocus
= wxFindFocusedChild(win
);
2153 g_focusWindow
= (wxWindowGTK
*)NULL
;
2161 // caret needs to be informed about focus change
2162 wxCaret
*caret
= win
->GetCaret();
2165 caret
->OnKillFocus();
2167 #endif // wxUSE_CARET
2169 // don't send the window a kill focus event if it thinks that it doesn't
2170 // have focus already
2171 if ( win
->m_hasFocus
)
2173 win
->m_hasFocus
= false;
2175 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
2176 event
.SetEventObject( win
);
2178 // even if we did process the event in wx code, still let GTK itself
2179 // process it too as otherwise bad things happen, especially in GTK2
2180 // where the text control simply aborts the program if it doesn't get
2181 // the matching focus out event
2182 (void)win
->GetEventHandler()->ProcessEvent( event
);
2189 //-----------------------------------------------------------------------------
2190 // "enter_notify_event"
2191 //-----------------------------------------------------------------------------
2195 gint
gtk_window_enter_callback( GtkWidget
*widget
,
2196 GdkEventCrossing
*gdk_event
,
2202 wxapp_install_idle_handler();
2204 if (!win
->m_hasVMT
) return FALSE
;
2205 if (g_blockEventsOnDrag
) return FALSE
;
2207 // Event was emitted after a grab
2208 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
2210 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
2214 GdkModifierType state
= (GdkModifierType
)0;
2216 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
2218 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
2219 InitMouseEvent(win
, event
, gdk_event
);
2220 wxPoint pt
= win
->GetClientAreaOrigin();
2221 event
.m_x
= x
+ pt
.x
;
2222 event
.m_y
= y
+ pt
.y
;
2224 if (win
->GetEventHandler()->ProcessEvent( event
))
2226 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "enter_notify_event" );
2234 //-----------------------------------------------------------------------------
2235 // "leave_notify_event"
2236 //-----------------------------------------------------------------------------
2239 static gint
gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindowGTK
*win
)
2244 wxapp_install_idle_handler();
2246 if (!win
->m_hasVMT
) return FALSE
;
2247 if (g_blockEventsOnDrag
) return FALSE
;
2249 // Event was emitted after an ungrab
2250 if (gdk_event
->mode
!= GDK_CROSSING_NORMAL
) return FALSE
;
2252 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return FALSE
;
2254 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
2255 event
.SetTimestamp( gdk_event
->time
);
2256 event
.SetEventObject( win
);
2260 GdkModifierType state
= (GdkModifierType
)0;
2262 gdk_window_get_pointer( widget
->window
, &x
, &y
, &state
);
2264 event
.m_shiftDown
= (state
& GDK_SHIFT_MASK
) != 0;
2265 event
.m_controlDown
= (state
& GDK_CONTROL_MASK
) != 0;
2266 event
.m_altDown
= (state
& GDK_MOD1_MASK
) != 0;
2267 event
.m_metaDown
= (state
& GDK_MOD2_MASK
) != 0;
2268 event
.m_leftDown
= (state
& GDK_BUTTON1_MASK
) != 0;
2269 event
.m_middleDown
= (state
& GDK_BUTTON2_MASK
) != 0;
2270 event
.m_rightDown
= (state
& GDK_BUTTON3_MASK
) != 0;
2272 wxPoint pt
= win
->GetClientAreaOrigin();
2273 event
.m_x
= x
+ pt
.x
;
2274 event
.m_y
= y
+ pt
.y
;
2276 if (win
->GetEventHandler()->ProcessEvent( event
))
2278 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "leave_notify_event" );
2286 //-----------------------------------------------------------------------------
2287 // "value_changed" from m_vAdjust
2288 //-----------------------------------------------------------------------------
2291 static void gtk_window_vscroll_callback( GtkAdjustment
*adjust
,
2298 wxapp_install_idle_handler();
2300 if (g_blockEventsOnDrag
) return;
2302 if (!win
->m_hasVMT
) return;
2304 float diff
= adjust
->value
- win
->m_oldVerticalPos
;
2305 if (fabs(diff
) < 0.2) return;
2307 win
->m_oldVerticalPos
= adjust
->value
;
2310 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2312 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->vscrollbar
));
2314 int value
= (int)(adjust
->value
+0.5);
2316 wxScrollWinEvent
event( command
, value
, wxVERTICAL
);
2317 event
.SetEventObject( win
);
2318 win
->GetEventHandler()->ProcessEvent( event
);
2322 //-----------------------------------------------------------------------------
2323 // "value_changed" from m_hAdjust
2324 //-----------------------------------------------------------------------------
2327 static void gtk_window_hscroll_callback( GtkAdjustment
*adjust
,
2334 wxapp_install_idle_handler();
2336 if (g_blockEventsOnDrag
) return;
2337 if (!win
->m_hasVMT
) return;
2339 float diff
= adjust
->value
- win
->m_oldHorizontalPos
;
2340 if (fabs(diff
) < 0.2) return;
2343 GtkScrolledWindow
*sw
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2345 wxEventType command
= GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw
->hscrollbar
));
2347 win
->m_oldHorizontalPos
= adjust
->value
;
2349 int value
= (int)(adjust
->value
+0.5);
2351 wxScrollWinEvent
event( command
, value
, wxHORIZONTAL
);
2352 event
.SetEventObject( win
);
2353 win
->GetEventHandler()->ProcessEvent( event
);
2357 //-----------------------------------------------------------------------------
2358 // "button_press_event" from scrollbar
2359 //-----------------------------------------------------------------------------
2362 static gint
gtk_scrollbar_button_press_callback( GtkRange
*widget
,
2363 GdkEventButton
*gdk_event
,
2369 wxapp_install_idle_handler();
2372 g_blockEventsOnScroll
= true;
2374 // FIXME: there is no 'slider' field in GTK+ 2.0 any more
2376 win
->m_isScrolling
= (gdk_event
->window
== widget
->slider
);
2383 //-----------------------------------------------------------------------------
2384 // "button_release_event" from scrollbar
2385 //-----------------------------------------------------------------------------
2388 static gint
gtk_scrollbar_button_release_callback( GtkRange
*widget
,
2389 GdkEventButton
*WXUNUSED(gdk_event
),
2394 // don't test here as we can release the mouse while being over
2395 // a different window than the slider
2397 // if (gdk_event->window != widget->slider) return FALSE;
2399 g_blockEventsOnScroll
= false;
2401 if (win
->m_isScrolling
)
2403 wxEventType command
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2407 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(win
->m_widget
);
2408 if (widget
== GTK_RANGE(scrolledWindow
->hscrollbar
))
2410 value
= (int)(win
->m_hAdjust
->value
+0.5);
2413 if (widget
== GTK_RANGE(scrolledWindow
->vscrollbar
))
2415 value
= (int)(win
->m_vAdjust
->value
+0.5);
2419 wxScrollWinEvent
event( command
, value
, dir
);
2420 event
.SetEventObject( win
);
2421 win
->GetEventHandler()->ProcessEvent( event
);
2424 win
->m_isScrolling
= false;
2430 // ----------------------------------------------------------------------------
2431 // this wxWindowBase function is implemented here (in platform-specific file)
2432 // because it is static and so couldn't be made virtual
2433 // ----------------------------------------------------------------------------
2435 wxWindow
*wxWindowBase::DoFindFocus()
2437 // the cast is necessary when we compile in wxUniversal mode
2438 return (wxWindow
*)g_focusWindow
;
2441 //-----------------------------------------------------------------------------
2442 // "realize" from m_widget
2443 //-----------------------------------------------------------------------------
2445 /* We cannot set colours and fonts before the widget has
2446 been realized, so we do this directly after realization. */
2450 gtk_window_realized_callback( GtkWidget
*m_widget
, wxWindow
*win
)
2455 wxapp_install_idle_handler();
2460 GtkPizza
*pizza
= GTK_PIZZA( m_widget
);
2461 gtk_im_context_set_client_window( win
->m_imData
->context
,
2462 pizza
->bin_window
);
2466 wxWindowCreateEvent
event( win
);
2467 event
.SetEventObject( win
);
2468 win
->GetEventHandler()->ProcessEvent( event
);
2474 //-----------------------------------------------------------------------------
2476 //-----------------------------------------------------------------------------
2480 void gtk_window_size_callback( GtkWidget
*WXUNUSED(widget
),
2481 GtkAllocation
*WXUNUSED(alloc
),
2485 wxapp_install_idle_handler();
2487 if (!win
->m_hasScrolling
) return;
2489 int client_width
= 0;
2490 int client_height
= 0;
2491 win
->GetClientSize( &client_width
, &client_height
);
2492 if ((client_width
== win
->m_oldClientWidth
) && (client_height
== win
->m_oldClientHeight
))
2495 win
->m_oldClientWidth
= client_width
;
2496 win
->m_oldClientHeight
= client_height
;
2498 if (!win
->m_nativeSizeEvent
)
2500 wxSizeEvent
event( win
->GetSize(), win
->GetId() );
2501 event
.SetEventObject( win
);
2502 win
->GetEventHandler()->ProcessEvent( event
);
2509 #define WXUNUSED_UNLESS_XIM(param) param
2511 #define WXUNUSED_UNLESS_XIM(param) WXUNUSED(param)
2514 /* Resize XIM window */
2518 void gtk_wxwindow_size_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2519 GtkAllocation
* WXUNUSED_UNLESS_XIM(alloc
),
2520 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2523 wxapp_install_idle_handler();
2529 if (gdk_ic_get_style (win
->m_ic
) & GDK_IM_PREEDIT_POSITION
)
2533 gdk_window_get_size (widget
->window
, &width
, &height
);
2534 win
->m_icattr
->preedit_area
.width
= width
;
2535 win
->m_icattr
->preedit_area
.height
= height
;
2536 gdk_ic_set_attr (win
->m_ic
, win
->m_icattr
, GDK_IC_PREEDIT_AREA
);
2542 //-----------------------------------------------------------------------------
2543 // "realize" from m_wxwindow
2544 //-----------------------------------------------------------------------------
2546 /* Initialize XIM support */
2550 gtk_wxwindow_realized_callback( GtkWidget
* WXUNUSED_UNLESS_XIM(widget
),
2551 wxWindowGTK
* WXUNUSED_UNLESS_XIM(win
) )
2554 wxapp_install_idle_handler();
2557 if (win
->m_ic
) return FALSE
;
2558 if (!widget
) return FALSE
;
2559 if (!gdk_im_ready()) return FALSE
;
2561 win
->m_icattr
= gdk_ic_attr_new();
2562 if (!win
->m_icattr
) return FALSE
;
2566 GdkColormap
*colormap
;
2567 GdkICAttr
*attr
= win
->m_icattr
;
2568 unsigned attrmask
= GDK_IC_ALL_REQ
;
2570 GdkIMStyle supported_style
= (GdkIMStyle
)
2571 (GDK_IM_PREEDIT_NONE
|
2572 GDK_IM_PREEDIT_NOTHING
|
2573 GDK_IM_PREEDIT_POSITION
|
2574 GDK_IM_STATUS_NONE
|
2575 GDK_IM_STATUS_NOTHING
);
2577 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2578 supported_style
= (GdkIMStyle
)(supported_style
& ~GDK_IM_PREEDIT_POSITION
);
2580 attr
->style
= style
= gdk_im_decide_style (supported_style
);
2581 attr
->client_window
= widget
->window
;
2583 if ((colormap
= gtk_widget_get_colormap (widget
)) !=
2584 gtk_widget_get_default_colormap ())
2586 attrmask
|= GDK_IC_PREEDIT_COLORMAP
;
2587 attr
->preedit_colormap
= colormap
;
2590 attrmask
|= GDK_IC_PREEDIT_FOREGROUND
;
2591 attrmask
|= GDK_IC_PREEDIT_BACKGROUND
;
2592 attr
->preedit_foreground
= widget
->style
->fg
[GTK_STATE_NORMAL
];
2593 attr
->preedit_background
= widget
->style
->base
[GTK_STATE_NORMAL
];
2595 switch (style
& GDK_IM_PREEDIT_MASK
)
2597 case GDK_IM_PREEDIT_POSITION
:
2598 if (widget
->style
&& widget
->style
->font
->type
!= GDK_FONT_FONTSET
)
2600 g_warning ("over-the-spot style requires fontset");
2604 gdk_window_get_size (widget
->window
, &width
, &height
);
2606 attrmask
|= GDK_IC_PREEDIT_POSITION_REQ
;
2607 attr
->spot_location
.x
= 0;
2608 attr
->spot_location
.y
= height
;
2609 attr
->preedit_area
.x
= 0;
2610 attr
->preedit_area
.y
= 0;
2611 attr
->preedit_area
.width
= width
;
2612 attr
->preedit_area
.height
= height
;
2613 attr
->preedit_fontset
= widget
->style
->font
;
2618 win
->m_ic
= gdk_ic_new (attr
, (GdkICAttributesType
)attrmask
);
2620 if (win
->m_ic
== NULL
)
2621 g_warning ("Can't create input context.");
2624 mask
= gdk_window_get_events (widget
->window
);
2625 mask
= (GdkEventMask
)(mask
| gdk_ic_get_events (win
->m_ic
));
2626 gdk_window_set_events (widget
->window
, mask
);
2628 if (GTK_WIDGET_HAS_FOCUS(widget
))
2629 gdk_im_begin (win
->m_ic
, widget
->window
);
2637 //-----------------------------------------------------------------------------
2638 // InsertChild for wxWindowGTK.
2639 //-----------------------------------------------------------------------------
2641 /* Callback for wxWindowGTK. This very strange beast has to be used because
2642 * C++ has no virtual methods in a constructor. We have to emulate a
2643 * virtual function here as wxNotebook requires a different way to insert
2644 * a child in it. I had opted for creating a wxNotebookPage window class
2645 * which would have made this superfluous (such in the MDI window system),
2646 * but no-one was listening to me... */
2648 static void wxInsertChildInWindow( wxWindowGTK
* parent
, wxWindowGTK
* child
)
2650 /* the window might have been scrolled already, do we
2651 have to adapt the position */
2652 GtkPizza
*pizza
= GTK_PIZZA(parent
->m_wxwindow
);
2653 child
->m_x
+= pizza
->xoffset
;
2654 child
->m_y
+= pizza
->yoffset
;
2656 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
2657 GTK_WIDGET(child
->m_widget
),
2664 //-----------------------------------------------------------------------------
2666 //-----------------------------------------------------------------------------
2668 wxWindow
*wxGetActiveWindow()
2670 return wxWindow::FindFocus();
2673 //-----------------------------------------------------------------------------
2675 //-----------------------------------------------------------------------------
2677 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
2679 #ifdef __WXUNIVERSAL__
2680 IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK
, wxWindowBase
)
2682 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
2683 #endif // __WXUNIVERSAL__/__WXGTK__
2685 void wxWindowGTK::Init()
2688 m_widget
= (GtkWidget
*) NULL
;
2689 m_wxwindow
= (GtkWidget
*) NULL
;
2690 m_focusWidget
= (GtkWidget
*) NULL
;
2700 m_needParent
= true;
2701 m_isBeingDeleted
= false;
2704 m_nativeSizeEvent
= false;
2706 m_hasScrolling
= false;
2707 m_isScrolling
= false;
2709 m_hAdjust
= (GtkAdjustment
*) NULL
;
2710 m_vAdjust
= (GtkAdjustment
*) NULL
;
2711 m_oldHorizontalPos
=
2712 m_oldVerticalPos
= 0.0;
2714 m_oldClientHeight
= 0;
2718 m_insertCallback
= (wxInsertChildFunction
) NULL
;
2720 m_acceptsFocus
= false;
2723 m_clipPaintRegion
= false;
2725 m_needsStyleChange
= false;
2727 m_cursor
= *wxSTANDARD_CURSOR
;
2731 m_x11Context
= NULL
;
2732 m_dirtyTabOrder
= false;
2735 m_ic
= (GdkIC
*) NULL
;
2736 m_icattr
= (GdkICAttr
*) NULL
;
2741 wxWindowGTK::wxWindowGTK()
2746 wxWindowGTK::wxWindowGTK( wxWindow
*parent
,
2751 const wxString
&name
)
2755 Create( parent
, id
, pos
, size
, style
, name
);
2758 bool wxWindowGTK::Create( wxWindow
*parent
,
2763 const wxString
&name
)
2765 if (!PreCreation( parent
, pos
, size
) ||
2766 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
2768 wxFAIL_MSG( wxT("wxWindowGTK creation failed") );
2772 m_insertCallback
= wxInsertChildInWindow
;
2774 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
2775 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
2777 GtkScrolledWindow
*scrolledWindow
= GTK_SCROLLED_WINDOW(m_widget
);
2779 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
2780 scroll_class
->scrollbar_spacing
= 0;
2782 gtk_scrolled_window_set_policy( scrolledWindow
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
2784 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->hscrollbar
) );
2785 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(scrolledWindow
->vscrollbar
) );
2787 m_wxwindow
= gtk_pizza_new();
2789 #ifndef __WXUNIVERSAL__
2790 GtkPizza
*pizza
= GTK_PIZZA(m_wxwindow
);
2792 if (HasFlag(wxRAISED_BORDER
))
2794 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_OUT
);
2796 else if (HasFlag(wxSUNKEN_BORDER
))
2798 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_IN
);
2800 else if (HasFlag(wxSIMPLE_BORDER
))
2802 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_THIN
);
2806 gtk_pizza_set_shadow_type( pizza
, GTK_MYSHADOW_NONE
);
2808 #endif // __WXUNIVERSAL__
2810 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
2812 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
2813 m_acceptsFocus
= true;
2815 // I _really_ don't want scrollbars in the beginning
2816 m_vAdjust
->lower
= 0.0;
2817 m_vAdjust
->upper
= 1.0;
2818 m_vAdjust
->value
= 0.0;
2819 m_vAdjust
->step_increment
= 1.0;
2820 m_vAdjust
->page_increment
= 1.0;
2821 m_vAdjust
->page_size
= 5.0;
2822 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
2823 m_hAdjust
->lower
= 0.0;
2824 m_hAdjust
->upper
= 1.0;
2825 m_hAdjust
->value
= 0.0;
2826 m_hAdjust
->step_increment
= 1.0;
2827 m_hAdjust
->page_increment
= 1.0;
2828 m_hAdjust
->page_size
= 5.0;
2829 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
2831 // these handlers block mouse events to any window during scrolling such as
2832 // motion events and prevent GTK and wxWidgets from fighting over where the
2835 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_press_event",
2836 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2838 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_press_event",
2839 (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this );
2841 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->vscrollbar
), "button_release_event",
2842 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2844 gtk_signal_connect( GTK_OBJECT(scrolledWindow
->hscrollbar
), "button_release_event",
2845 (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this );
2847 // these handlers get notified when screen updates are required either when
2848 // scrolling or when the window size (and therefore scrollbar configuration)
2851 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
2852 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
2853 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
2854 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
2856 gtk_widget_show( m_wxwindow
);
2859 m_parent
->DoAddChild( this );
2861 m_focusWidget
= m_wxwindow
;
2868 wxWindowGTK::~wxWindowGTK()
2872 if (g_focusWindow
== this)
2873 g_focusWindow
= NULL
;
2875 if ( g_delayedFocus
== this )
2876 g_delayedFocus
= NULL
;
2878 m_isBeingDeleted
= true;
2881 // destroy children before destroying this window itself
2884 // unhook focus handlers to prevent stray events being
2885 // propagated to this (soon to be) dead object
2886 if (m_focusWidget
!= NULL
)
2888 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2889 (GtkSignalFunc
) gtk_window_focus_in_callback
, (gpointer
) this );
2890 gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget
),
2891 (GtkSignalFunc
) gtk_window_focus_out_callback
, (gpointer
) this );
2899 gdk_ic_destroy (m_ic
);
2901 gdk_ic_attr_destroy (m_icattr
);
2905 // delete before the widgets to avoid a crash on solaris
2911 gtk_widget_destroy( m_wxwindow
);
2912 m_wxwindow
= (GtkWidget
*) NULL
;
2917 gtk_widget_destroy( m_widget
);
2918 m_widget
= (GtkWidget
*) NULL
;
2922 bool wxWindowGTK::PreCreation( wxWindowGTK
*parent
, const wxPoint
&pos
, const wxSize
&size
)
2924 wxCHECK_MSG( !m_needParent
|| parent
, false, wxT("Need complete parent.") );
2926 // Use either the given size, or the default if -1 is given.
2927 // See wxWindowBase for these functions.
2928 m_width
= WidthDefault(size
.x
) ;
2929 m_height
= HeightDefault(size
.y
);
2937 void wxWindowGTK::PostCreation()
2939 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
2945 // these get reported to wxWidgets -> wxPaintEvent
2947 gtk_pizza_set_external( GTK_PIZZA(m_wxwindow
), TRUE
);
2949 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
2950 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
2953 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
2954 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
2956 if (!HasFlag(wxFULL_REPAINT_ON_RESIZE
))
2958 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "event",
2959 GTK_SIGNAL_FUNC(gtk_window_event_event_callback
), (gpointer
)this );
2962 // gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow), !HasFlag( wxFULL_REPAINT_ON_RESIZE ) );
2967 // Create input method handler
2968 m_imData
= new wxGtkIMData
;
2970 // Cannot handle drawing preedited text yet
2971 gtk_im_context_set_use_preedit( m_imData
->context
, FALSE
);
2973 g_signal_connect (G_OBJECT (m_imData
->context
), "commit",
2974 G_CALLBACK (gtk_wxwindow_commit_cb
), this);
2977 // these are called when the "sunken" or "raised" borders are drawn
2978 gtk_signal_connect( GTK_OBJECT(m_widget
), "expose_event",
2979 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback
), (gpointer
)this );
2982 gtk_signal_connect( GTK_OBJECT(m_widget
), "draw",
2983 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback
), (gpointer
)this );
2989 if (!GTK_IS_WINDOW(m_widget
))
2991 if (m_focusWidget
== NULL
)
2992 m_focusWidget
= m_widget
;
2994 gtk_signal_connect( GTK_OBJECT(m_focusWidget
), "focus_in_event",
2995 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
2997 gtk_signal_connect_after( GTK_OBJECT(m_focusWidget
), "focus_out_event",
2998 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
3001 // connect to the various key and mouse handlers
3003 GtkWidget
*connect_widget
= GetConnectWidget();
3005 ConnectWidget( connect_widget
);
3007 /* We cannot set colours, fonts and cursors before the widget has
3008 been realized, so we do this directly after realization */
3009 gtk_signal_connect( GTK_OBJECT(connect_widget
), "realize",
3010 GTK_SIGNAL_FUNC(gtk_window_realized_callback
), (gpointer
) this );
3014 // Catch native resize events
3015 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
3016 GTK_SIGNAL_FUNC(gtk_window_size_callback
), (gpointer
)this );
3018 // Initialize XIM support
3019 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "realize",
3020 GTK_SIGNAL_FUNC(gtk_wxwindow_realized_callback
), (gpointer
) this );
3022 // And resize XIM window
3023 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "size_allocate",
3024 GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback
), (gpointer
)this );
3027 if (GTK_IS_COMBO(m_widget
))
3029 GtkCombo
*gcombo
= GTK_COMBO(m_widget
);
3031 gtk_signal_connect( GTK_OBJECT(gcombo
->entry
), "size_request",
3032 GTK_SIGNAL_FUNC(wxgtk_combo_size_request_callback
),
3037 // This is needed if we want to add our windows into native
3038 // GTK controls, such as the toolbar. With this callback, the
3039 // toolbar gets to know the correct size (the one set by the
3040 // programmer). Sadly, it misbehaves for wxComboBox.
3041 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_request",
3042 GTK_SIGNAL_FUNC(wxgtk_window_size_request_callback
),
3046 InheritAttributes();
3050 // unless the window was created initially hidden (i.e. Hide() had been
3051 // called before Create()), we should show it at GTK+ level as well
3053 gtk_widget_show( m_widget
);
3056 void wxWindowGTK::ConnectWidget( GtkWidget
*widget
)
3058 gtk_signal_connect( GTK_OBJECT(widget
), "key_press_event",
3059 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
3061 gtk_signal_connect( GTK_OBJECT(widget
), "key_release_event",
3062 GTK_SIGNAL_FUNC(gtk_window_key_release_callback
), (gpointer
)this );
3064 gtk_signal_connect( GTK_OBJECT(widget
), "button_press_event",
3065 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
3067 gtk_signal_connect( GTK_OBJECT(widget
), "button_release_event",
3068 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
3070 gtk_signal_connect( GTK_OBJECT(widget
), "motion_notify_event",
3071 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
3074 gtk_signal_connect( GTK_OBJECT(widget
), "scroll_event",
3075 GTK_SIGNAL_FUNC(gtk_window_wheel_callback
), (gpointer
)this );
3076 g_signal_connect(widget
, "popup_menu",
3077 G_CALLBACK(wxgtk_window_popup_menu_callback
), this);
3080 gtk_signal_connect( GTK_OBJECT(widget
), "enter_notify_event",
3081 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
3083 gtk_signal_connect( GTK_OBJECT(widget
), "leave_notify_event",
3084 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
3087 bool wxWindowGTK::Destroy()
3089 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3093 return wxWindowBase::Destroy();
3096 void wxWindowGTK::DoMoveWindow(int x
, int y
, int width
, int height
)
3098 gtk_pizza_set_size( GTK_PIZZA(m_parent
->m_wxwindow
), m_widget
, x
, y
, width
, height
);
3101 void wxWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
3103 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3104 wxASSERT_MSG( (m_parent
!= NULL
), wxT("wxWindowGTK::SetSize requires parent.\n") );
3107 printf( "DoSetSize: name %s, x,y,w,h: %d,%d,%d,%d \n", GetName().c_str(), x,y,width,height );
3110 if (m_resizing
) return; /* I don't like recursions */
3113 int currentX
, currentY
;
3114 GetPosition(¤tX
, ¤tY
);
3115 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
3117 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
3119 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
3121 if (m_parent
->m_wxwindow
== NULL
) /* i.e. wxNotebook */
3123 /* don't set the size for children of wxNotebook, just take the values. */
3131 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
3132 if ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0)
3134 if (x
!= -1) m_x
= x
+ pizza
->xoffset
;
3135 if (y
!= -1) m_y
= y
+ pizza
->yoffset
;
3139 m_x
= x
+ pizza
->xoffset
;
3140 m_y
= y
+ pizza
->yoffset
;
3143 // calculate the best size if we should auto size the window
3144 if ( ((sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1) ||
3145 ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1) )
3147 const wxSize sizeBest
= GetBestSize();
3148 if ( (sizeFlags
& wxSIZE_AUTO_WIDTH
) && width
== -1 )
3150 if ( (sizeFlags
& wxSIZE_AUTO_HEIGHT
) && height
== -1 )
3151 height
= sizeBest
.y
;
3159 int minWidth
= GetMinWidth(),
3160 minHeight
= GetMinHeight(),
3161 maxWidth
= GetMaxWidth(),
3162 maxHeight
= GetMaxHeight();
3164 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
3165 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
3166 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
3167 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
3169 int left_border
= 0;
3170 int right_border
= 0;
3172 int bottom_border
= 0;
3174 /* the default button has a border around it */
3175 if (GTK_WIDGET_CAN_DEFAULT(m_widget
))
3178 GtkBorder
*default_border
= NULL
;
3179 gtk_widget_style_get( m_widget
, "default_border", &default_border
, NULL
);
3182 left_border
+= default_border
->left
;
3183 right_border
+= default_border
->right
;
3184 top_border
+= default_border
->top
;
3185 bottom_border
+= default_border
->bottom
;
3186 g_free( default_border
);
3196 DoMoveWindow( m_x
-top_border
,
3198 m_width
+left_border
+right_border
,
3199 m_height
+top_border
+bottom_border
);
3204 /* Sometimes the client area changes size without the
3205 whole windows's size changing, but if the whole
3206 windows's size doesn't change, no wxSizeEvent will
3207 normally be sent. Here we add an extra test if
3208 the client test has been changed and this will
3210 GetClientSize( &m_oldClientWidth
, &m_oldClientHeight
);
3214 wxPrintf( "OnSize sent from " );
3215 if (GetClassInfo() && GetClassInfo()->GetClassName())
3216 wxPrintf( GetClassInfo()->GetClassName() );
3217 wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height );
3220 if (!m_nativeSizeEvent
)
3222 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
3223 event
.SetEventObject( this );
3224 GetEventHandler()->ProcessEvent( event
);
3230 void wxWindowGTK::OnInternalIdle()
3233 if ( m_dirtyTabOrder
)
3236 // Update style if the window was not yet realized
3237 // and SetBackgroundStyle(wxBG_STYLE_CUSTOM) was called
3238 if (m_needsStyleChange
)
3240 SetBackgroundStyle(GetBackgroundStyle());
3241 m_needsStyleChange
= false;
3244 // Update invalidated regions.
3247 wxCursor cursor
= m_cursor
;
3248 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
3252 /* I now set the cursor anew in every OnInternalIdle call
3253 as setting the cursor in a parent window also effects the
3254 windows above so that checking for the current cursor is
3259 GdkWindow
*window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3261 gdk_window_set_cursor( window
, cursor
.GetCursor() );
3263 if (!g_globalCursor
.Ok())
3264 cursor
= *wxSTANDARD_CURSOR
;
3266 window
= m_widget
->window
;
3267 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
3268 gdk_window_set_cursor( window
, cursor
.GetCursor() );
3274 GdkWindow
*window
= m_widget
->window
;
3275 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
3276 gdk_window_set_cursor( window
, cursor
.GetCursor() );
3281 if (wxUpdateUIEvent::CanUpdate(this))
3282 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
3285 void wxWindowGTK::DoGetSize( int *width
, int *height
) const
3287 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3289 if (width
) (*width
) = m_width
;
3290 if (height
) (*height
) = m_height
;
3293 void wxWindowGTK::DoSetClientSize( int width
, int height
)
3295 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3299 SetSize( width
, height
);
3306 #ifndef __WXUNIVERSAL__
3307 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
3309 /* when using GTK 1.2 we set the shadow border size to 2 */
3313 if (HasFlag(wxSIMPLE_BORDER
))
3315 /* when using GTK 1.2 we set the simple border size to 1 */
3319 #endif // __WXUNIVERSAL__
3323 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
3325 GtkRequisition vscroll_req
;
3326 vscroll_req
.width
= 2;
3327 vscroll_req
.height
= 2;
3328 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
3329 (scroll_window
->vscrollbar
, &vscroll_req
);
3331 GtkRequisition hscroll_req
;
3332 hscroll_req
.width
= 2;
3333 hscroll_req
.height
= 2;
3334 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
3335 (scroll_window
->hscrollbar
, &hscroll_req
);
3337 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3339 if (scroll_window
->vscrollbar_visible
)
3341 dw
+= vscroll_req
.width
;
3342 dw
+= scroll_class
->scrollbar_spacing
;
3345 if (scroll_window
->hscrollbar_visible
)
3347 dh
+= hscroll_req
.height
;
3348 dh
+= scroll_class
->scrollbar_spacing
;
3352 SetSize( width
+dw
, height
+dh
);
3356 void wxWindowGTK::DoGetClientSize( int *width
, int *height
) const
3358 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3362 if (width
) (*width
) = m_width
;
3363 if (height
) (*height
) = m_height
;
3370 #ifndef __WXUNIVERSAL__
3371 if (HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
))
3373 /* when using GTK 1.2 we set the shadow border size to 2 */
3377 if (HasFlag(wxSIMPLE_BORDER
))
3379 /* when using GTK 1.2 we set the simple border size to 1 */
3383 #endif // __WXUNIVERSAL__
3387 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
3389 GtkRequisition vscroll_req
;
3390 vscroll_req
.width
= 2;
3391 vscroll_req
.height
= 2;
3392 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->vscrollbar
) )->size_request
)
3393 (scroll_window
->vscrollbar
, &vscroll_req
);
3395 GtkRequisition hscroll_req
;
3396 hscroll_req
.width
= 2;
3397 hscroll_req
.height
= 2;
3398 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window
->hscrollbar
) )->size_request
)
3399 (scroll_window
->hscrollbar
, &hscroll_req
);
3401 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget
) );
3403 if (scroll_window
->vscrollbar_visible
)
3405 dw
+= vscroll_req
.width
;
3406 dw
+= scroll_class
->scrollbar_spacing
;
3409 if (scroll_window
->hscrollbar_visible
)
3411 dh
+= hscroll_req
.height
;
3412 dh
+= scroll_class
->scrollbar_spacing
;
3416 if (width
) (*width
) = m_width
- dw
;
3417 if (height
) (*height
) = m_height
- dh
;
3421 printf( "GetClientSize, name %s ", GetName().c_str() );
3422 if (width) printf( " width = %d", (*width) );
3423 if (height) printf( " height = %d", (*height) );
3428 void wxWindowGTK::DoGetPosition( int *x
, int *y
) const
3430 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3434 if (m_parent
&& m_parent
->m_wxwindow
)
3436 GtkPizza
*pizza
= GTK_PIZZA(m_parent
->m_wxwindow
);
3437 dx
= pizza
->xoffset
;
3438 dy
= pizza
->yoffset
;
3441 if (x
) (*x
) = m_x
- dx
;
3442 if (y
) (*y
) = m_y
- dy
;
3445 void wxWindowGTK::DoClientToScreen( int *x
, int *y
) const
3447 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3449 if (!m_widget
->window
) return;
3451 GdkWindow
*source
= (GdkWindow
*) NULL
;
3453 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3455 source
= m_widget
->window
;
3459 gdk_window_get_origin( source
, &org_x
, &org_y
);
3463 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3465 org_x
+= m_widget
->allocation
.x
;
3466 org_y
+= m_widget
->allocation
.y
;
3474 void wxWindowGTK::DoScreenToClient( int *x
, int *y
) const
3476 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3478 if (!m_widget
->window
) return;
3480 GdkWindow
*source
= (GdkWindow
*) NULL
;
3482 source
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3484 source
= m_widget
->window
;
3488 gdk_window_get_origin( source
, &org_x
, &org_y
);
3492 if (GTK_WIDGET_NO_WINDOW (m_widget
))
3494 org_x
+= m_widget
->allocation
.x
;
3495 org_y
+= m_widget
->allocation
.y
;
3503 bool wxWindowGTK::Show( bool show
)
3505 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3507 if (!wxWindowBase::Show(show
))
3514 gtk_widget_show( m_widget
);
3516 gtk_widget_hide( m_widget
);
3518 wxShowEvent
eventShow(GetId(), show
);
3519 eventShow
.SetEventObject(this);
3521 GetEventHandler()->ProcessEvent(eventShow
);
3526 static void wxWindowNotifyEnable(wxWindowGTK
* win
, bool enable
)
3528 win
->OnParentEnable(enable
);
3530 // Recurse, so that children have the opportunity to Do The Right Thing
3531 // and reset colours that have been messed up by a parent's (really ancestor's)
3533 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
3535 node
= node
->GetNext() )
3537 wxWindow
*child
= node
->GetData();
3538 if (!child
->IsKindOf(CLASSINFO(wxDialog
)) && !child
->IsKindOf(CLASSINFO(wxFrame
)))
3539 wxWindowNotifyEnable(child
, enable
);
3543 bool wxWindowGTK::Enable( bool enable
)
3545 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3547 if (!wxWindowBase::Enable(enable
))
3553 gtk_widget_set_sensitive( m_widget
, enable
);
3555 gtk_widget_set_sensitive( m_wxwindow
, enable
);
3557 wxWindowNotifyEnable(this, enable
);
3562 int wxWindowGTK::GetCharHeight() const
3564 wxCHECK_MSG( (m_widget
!= NULL
), 12, wxT("invalid window") );
3566 wxFont font
= GetFont();
3567 wxCHECK_MSG( font
.Ok(), 12, wxT("invalid font") );
3570 PangoContext
*context
= NULL
;
3572 context
= gtk_widget_get_pango_context( m_widget
);
3577 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
3578 PangoLayout
*layout
= pango_layout_new(context
);
3579 pango_layout_set_font_description(layout
, desc
);
3580 pango_layout_set_text(layout
, "H", 1);
3581 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
3583 PangoRectangle rect
;
3584 pango_layout_line_get_extents(line
, NULL
, &rect
);
3586 g_object_unref( G_OBJECT( layout
) );
3588 return (int) PANGO_PIXELS(rect
.height
);
3590 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3592 return gfont
->ascent
+ gfont
->descent
;
3596 int wxWindowGTK::GetCharWidth() const
3598 wxCHECK_MSG( (m_widget
!= NULL
), 8, wxT("invalid window") );
3600 wxFont font
= GetFont();
3601 wxCHECK_MSG( font
.Ok(), 8, wxT("invalid font") );
3604 PangoContext
*context
= NULL
;
3606 context
= gtk_widget_get_pango_context( m_widget
);
3611 PangoFontDescription
*desc
= font
.GetNativeFontInfo()->description
;
3612 PangoLayout
*layout
= pango_layout_new(context
);
3613 pango_layout_set_font_description(layout
, desc
);
3614 pango_layout_set_text(layout
, "g", 1);
3615 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
3617 PangoRectangle rect
;
3618 pango_layout_line_get_extents(line
, NULL
, &rect
);
3620 g_object_unref( G_OBJECT( layout
) );
3622 return (int) PANGO_PIXELS(rect
.width
);
3624 GdkFont
*gfont
= font
.GetInternalFont( 1.0 );
3626 return gdk_string_width( gfont
, "g" );
3630 void wxWindowGTK::GetTextExtent( const wxString
& string
,
3634 int *externalLeading
,
3635 const wxFont
*theFont
) const
3637 wxFont fontToUse
= theFont
? *theFont
: GetFont();
3639 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
3649 PangoContext
*context
= NULL
;
3651 context
= gtk_widget_get_pango_context( m_widget
);
3660 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
3661 PangoLayout
*layout
= pango_layout_new(context
);
3662 pango_layout_set_font_description(layout
, desc
);
3665 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
3666 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
3668 const wxWCharBuffer wdata
= wxConvLocal
.cMB2WC( string
);
3669 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( wdata
);
3670 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
3674 PangoRectangle rect
;
3675 pango_layout_get_extents(layout
, NULL
, &rect
);
3677 if (x
) (*x
) = (wxCoord
) PANGO_PIXELS(rect
.width
);
3678 if (y
) (*y
) = (wxCoord
) PANGO_PIXELS(rect
.height
);
3681 PangoLayoutIter
*iter
= pango_layout_get_iter(layout
);
3682 int baseline
= pango_layout_iter_get_baseline(iter
);
3683 pango_layout_iter_free(iter
);
3684 *descent
= *y
- PANGO_PIXELS(baseline
);
3686 if (externalLeading
) (*externalLeading
) = 0; // ??
3688 g_object_unref( G_OBJECT( layout
) );
3690 GdkFont
*font
= fontToUse
.GetInternalFont( 1.0 );
3691 if (x
) (*x
) = gdk_string_width( font
, wxGTK_CONV( string
) );
3692 if (y
) (*y
) = font
->ascent
+ font
->descent
;
3693 if (descent
) (*descent
) = font
->descent
;
3694 if (externalLeading
) (*externalLeading
) = 0; // ??
3698 void wxWindowGTK::SetFocus()
3700 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
3703 // don't do anything if we already have focus
3709 if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow
))
3711 gtk_widget_grab_focus (m_wxwindow
);
3717 if (GTK_IS_CONTAINER(m_widget
))
3719 gtk_widget_child_focus( m_widget
, GTK_DIR_TAB_FORWARD
);
3723 if (GTK_WIDGET_CAN_FOCUS(m_widget
) && !GTK_WIDGET_HAS_FOCUS (m_widget
) )
3726 if (!GTK_WIDGET_REALIZED(m_widget
))
3728 // we can't set the focus to the widget now so we remember that
3729 // it should be focused and will do it later, during the idle
3730 // time, as soon as we can
3731 wxLogTrace(TRACE_FOCUS
,
3732 _T("Delaying setting focus to %s(%s)"),
3733 GetClassInfo()->GetClassName(), GetLabel().c_str());
3735 g_delayedFocus
= this;
3739 wxLogTrace(TRACE_FOCUS
,
3740 _T("Setting focus to %s(%s)"),
3741 GetClassInfo()->GetClassName(), GetLabel().c_str());
3743 gtk_widget_grab_focus (m_widget
);
3748 if (GTK_IS_CONTAINER(m_widget
))
3750 gtk_container_focus( GTK_CONTAINER(m_widget
), GTK_DIR_TAB_FORWARD
);
3755 wxLogTrace(TRACE_FOCUS
,
3756 _T("Can't set focus to %s(%s)"),
3757 GetClassInfo()->GetClassName(), GetLabel().c_str());
3762 bool wxWindowGTK::AcceptsFocus() const
3764 return m_acceptsFocus
&& wxWindowBase::AcceptsFocus();
3767 bool wxWindowGTK::Reparent( wxWindowBase
*newParentBase
)
3769 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3771 wxWindowGTK
*oldParent
= m_parent
,
3772 *newParent
= (wxWindowGTK
*)newParentBase
;
3774 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3776 if ( !wxWindowBase::Reparent(newParent
) )
3779 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3781 /* prevent GTK from deleting the widget arbitrarily */
3782 gtk_widget_ref( m_widget
);
3786 gtk_container_remove( GTK_CONTAINER(m_widget
->parent
), m_widget
);
3789 wxASSERT( GTK_IS_WIDGET(m_widget
) );
3793 /* insert GTK representation */
3794 (*(newParent
->m_insertCallback
))(newParent
, this);
3797 /* reverse: prevent GTK from deleting the widget arbitrarily */
3798 gtk_widget_unref( m_widget
);
3803 void wxWindowGTK::DoAddChild(wxWindowGTK
*child
)
3805 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid window") );
3807 wxASSERT_MSG( (child
!= NULL
), wxT("invalid child window") );
3809 wxASSERT_MSG( (m_insertCallback
!= NULL
), wxT("invalid child insertion function") );
3814 /* insert GTK representation */
3815 (*m_insertCallback
)(this, child
);
3820 void wxWindowGTK::AddChild(wxWindowBase
*child
)
3822 wxWindowBase::AddChild(child
);
3823 m_dirtyTabOrder
= true;
3825 wxapp_install_idle_handler();
3828 void wxWindowGTK::RemoveChild(wxWindowBase
*child
)
3830 wxWindowBase::RemoveChild(child
);
3831 m_dirtyTabOrder
= true;
3833 wxapp_install_idle_handler();
3836 void wxWindowGTK::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
3838 wxWindowBase::DoMoveInTabOrder(win
, move
);
3839 m_dirtyTabOrder
= true;
3841 wxapp_install_idle_handler();
3844 void wxWindowGTK::RealizeTabOrder()
3848 if (m_children
.size() > 0)
3850 GList
*chain
= NULL
;
3852 for (wxWindowList::const_iterator i
= m_children
.begin();
3853 i
!= m_children
.end(); ++i
)
3855 chain
= g_list_prepend(chain
, (*i
)->m_widget
);
3858 chain
= g_list_reverse(chain
);
3860 gtk_container_set_focus_chain(GTK_CONTAINER(m_wxwindow
), chain
);
3865 gtk_container_unset_focus_chain(GTK_CONTAINER(m_wxwindow
));
3869 m_dirtyTabOrder
= false;
3872 #endif // __WXGTK20__
3874 void wxWindowGTK::Raise()
3876 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3878 if (m_wxwindow
&& m_wxwindow
->window
)
3880 gdk_window_raise( m_wxwindow
->window
);
3882 else if (m_widget
->window
)
3884 gdk_window_raise( m_widget
->window
);
3888 void wxWindowGTK::Lower()
3890 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3892 if (m_wxwindow
&& m_wxwindow
->window
)
3894 gdk_window_lower( m_wxwindow
->window
);
3896 else if (m_widget
->window
)
3898 gdk_window_lower( m_widget
->window
);
3902 bool wxWindowGTK::SetCursor( const wxCursor
&cursor
)
3904 wxCHECK_MSG( (m_widget
!= NULL
), false, wxT("invalid window") );
3906 if (cursor
== m_cursor
)
3910 wxapp_install_idle_handler();
3912 if (cursor
== wxNullCursor
)
3913 return wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
);
3915 return wxWindowBase::SetCursor( cursor
);
3918 void wxWindowGTK::WarpPointer( int x
, int y
)
3920 wxCHECK_RET( (m_widget
!= NULL
), wxT("invalid window") );
3922 // We provide this function ourselves as it is
3923 // missing in GDK (top of this file).
3925 GdkWindow
*window
= (GdkWindow
*) NULL
;
3927 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
3929 window
= GetConnectWidget()->window
;
3932 gdk_window_warp_pointer( window
, x
, y
);
3936 void wxWindowGTK::Refresh( bool eraseBackground
, const wxRect
*rect
)
3940 if (!m_widget
->window
)
3945 wxapp_install_idle_handler();
3948 if (m_wxwindow
&& rect
)
3950 myRect
.SetSize(wxSize( m_wxwindow
->allocation
.width
,
3951 m_wxwindow
->allocation
.height
));
3952 if ( myRect
.Intersect(*rect
).IsEmpty() )
3954 // nothing to do, rectangle is empty
3961 // schedule the area for later updating in GtkUpdate()
3962 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
3966 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3970 m_clearRegion
.Clear();
3971 m_clearRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
3979 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
3983 GdkRectangle gdk_rect
;
3984 gdk_rect
.x
= rect
->x
;
3985 gdk_rect
.y
= rect
->y
;
3986 gdk_rect
.width
= rect
->width
;
3987 gdk_rect
.height
= rect
->height
;
3988 gtk_widget_draw( m_widget
, &gdk_rect
);
3995 m_updateRegion
.Clear();
3996 m_updateRegion
.Union( 0, 0, m_wxwindow
->allocation
.width
, m_wxwindow
->allocation
.height
);
4000 gtk_widget_draw( m_widget
, (GdkRectangle
*) NULL
);
4006 GdkRectangle gdk_rect
,
4010 gdk_rect
.x
= rect
->x
;
4011 gdk_rect
.y
= rect
->y
;
4012 gdk_rect
.width
= rect
->width
;
4013 gdk_rect
.height
= rect
->height
;
4016 else // invalidate everything
4021 gdk_window_invalidate_rect( GTK_PIZZA(m_wxwindow
)->bin_window
, p
, TRUE
);
4026 void wxWindowGTK::Update()
4030 // when we call Update() we really want to update the window immediately on
4031 // screen, even if itmeans flushing the entire queue and hence slowing down
4032 // everything -- but it should still be done, it's just that Update() should
4033 // be called very rarely
4037 void wxWindowGTK::GtkUpdate()
4040 if (m_wxwindow
&& GTK_PIZZA(m_wxwindow
)->bin_window
)
4041 gdk_window_process_updates( GTK_PIZZA(m_wxwindow
)->bin_window
, FALSE
);
4043 if (!m_updateRegion
.IsEmpty())
4044 GtkSendPaintEvents();
4047 // for consistency with other platforms (and also because it's convenient
4048 // to be able to update an entire TLW by calling Update() only once), we
4049 // should also update all our children here
4050 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4052 node
= node
->GetNext() )
4054 node
->GetData()->GtkUpdate();
4058 void wxWindowGTK::GtkSendPaintEvents()
4063 m_clearRegion
.Clear();
4065 m_updateRegion
.Clear();
4069 // Clip to paint region in wxClientDC
4070 m_clipPaintRegion
= true;
4072 // widget to draw on
4073 GtkPizza
*pizza
= GTK_PIZZA (m_wxwindow
);
4075 if (GetThemeEnabled() && (GetBackgroundStyle() == wxBG_STYLE_SYSTEM
))
4077 // find ancestor from which to steal background
4078 wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
4080 parent
= (wxWindow
*)this;
4082 if (GTK_WIDGET_MAPPED(parent
->m_widget
))
4084 wxRegionIterator
upd( m_updateRegion
);
4088 rect
.x
= upd
.GetX();
4089 rect
.y
= upd
.GetY();
4090 rect
.width
= upd
.GetWidth();
4091 rect
.height
= upd
.GetHeight();
4093 gtk_paint_flat_box( parent
->m_widget
->style
,
4095 (GtkStateType
)GTK_WIDGET_STATE(m_wxwindow
),
4110 wxWindowDC
dc( (wxWindow
*)this );
4111 dc
.SetClippingRegion( m_updateRegion
);
4113 wxEraseEvent
erase_event( GetId(), &dc
);
4114 erase_event
.SetEventObject( this );
4116 GetEventHandler()->ProcessEvent(erase_event
);
4119 // if (!m_clearRegion.IsEmpty()) // Always send an erase event under GTK 1.2
4121 wxWindowDC
dc( (wxWindow
*)this );
4122 if (m_clearRegion
.IsEmpty())
4123 dc
.SetClippingRegion( m_updateRegion
);
4125 dc
.SetClippingRegion( m_clearRegion
);
4127 wxEraseEvent
erase_event( GetId(), &dc
);
4128 erase_event
.SetEventObject( this );
4130 if (!GetEventHandler()->ProcessEvent(erase_event
) && GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
4134 g_eraseGC
= gdk_gc_new( pizza
->bin_window
);
4135 gdk_gc_set_fill( g_eraseGC
, GDK_SOLID
);
4137 gdk_gc_set_foreground( g_eraseGC
, GetBackgroundColour().GetColor() );
4139 wxRegionIterator
upd( m_clearRegion
);
4142 gdk_draw_rectangle( pizza
->bin_window
, g_eraseGC
, 1,
4143 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
4147 m_clearRegion
.Clear();
4151 wxNcPaintEvent
nc_paint_event( GetId() );
4152 nc_paint_event
.SetEventObject( this );
4153 GetEventHandler()->ProcessEvent( nc_paint_event
);
4155 wxPaintEvent
paint_event( GetId() );
4156 paint_event
.SetEventObject( this );
4157 GetEventHandler()->ProcessEvent( paint_event
);
4159 m_clipPaintRegion
= false;
4161 #if !defined(__WXUNIVERSAL__) && !defined(__WXGTK20__)
4162 // The following code will result in all window-less widgets
4163 // being redrawn because the wxWidgets class is allowed to
4164 // paint over the window-less widgets.
4166 GList
*children
= pizza
->children
;
4169 GtkPizzaChild
*child
= (GtkPizzaChild
*) children
->data
;
4170 children
= children
->next
;
4172 if (GTK_WIDGET_NO_WINDOW (child
->widget
) &&
4173 GTK_WIDGET_DRAWABLE (child
->widget
))
4175 // Get intersection of widget area and update region
4176 wxRegion
region( m_updateRegion
);
4178 GdkEventExpose gdk_event
;
4179 gdk_event
.type
= GDK_EXPOSE
;
4180 gdk_event
.window
= pizza
->bin_window
;
4181 gdk_event
.count
= 0;
4182 gdk_event
.send_event
= TRUE
;
4184 wxRegionIterator
upd( m_updateRegion
);
4188 rect
.x
= upd
.GetX();
4189 rect
.y
= upd
.GetY();
4190 rect
.width
= upd
.GetWidth();
4191 rect
.height
= upd
.GetHeight();
4193 if (gtk_widget_intersect (child
->widget
, &rect
, &gdk_event
.area
))
4195 gtk_widget_event (child
->widget
, (GdkEvent
*) &gdk_event
);
4202 #endif // native GTK 1
4204 m_updateRegion
.Clear();
4207 void wxWindowGTK::ClearBackground()
4209 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4212 if (m_wxwindow
&& m_wxwindow
->window
)
4214 m_clearRegion
.Clear();
4215 wxSize
size( GetClientSize() );
4216 m_clearRegion
.Union( 0,0,size
.x
,size
.y
);
4218 // Better do this in idle?
4225 void wxWindowGTK::DoSetToolTip( wxToolTip
*tip
)
4227 wxWindowBase::DoSetToolTip(tip
);
4230 m_tooltip
->Apply( (wxWindow
*)this );
4233 void wxWindowGTK::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
4235 wxString
tmp( tip
);
4236 gtk_tooltips_set_tip( tips
, GetConnectWidget(), wxGTK_CONV(tmp
), (gchar
*) NULL
);
4238 #endif // wxUSE_TOOLTIPS
4240 bool wxWindowGTK::SetBackgroundColour( const wxColour
&colour
)
4242 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
4244 if (!wxWindowBase::SetBackgroundColour(colour
))
4249 // We need the pixel value e.g. for background clearing.
4250 m_backgroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
4253 // apply style change (forceStyle=true so that new style is applied
4254 // even if the bg colour changed from valid to wxNullColour)
4255 if (GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
4256 ApplyWidgetStyle(true);
4261 bool wxWindowGTK::SetForegroundColour( const wxColour
&colour
)
4263 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
4265 if (!wxWindowBase::SetForegroundColour(colour
))
4272 // We need the pixel value e.g. for background clearing.
4273 m_foregroundColour
.CalcPixel(gtk_widget_get_colormap(m_widget
));
4276 // apply style change (forceStyle=true so that new style is applied
4277 // even if the bg colour changed from valid to wxNullColour):
4278 ApplyWidgetStyle(true);
4284 PangoContext
*wxWindowGTK::GtkGetPangoDefaultContext()
4286 return gtk_widget_get_pango_context( m_widget
);
4289 // MR: Returns the same as GtkGetPangoDefaultContext until the symbol can be removed in 2.7.x
4290 PangoContext
*wxWindowGTK::GtkGetPangoX11Context()
4292 return gtk_widget_get_pango_context( m_widget
);
4296 GtkRcStyle
*wxWindowGTK::CreateWidgetStyle(bool forceStyle
)
4298 // do we need to apply any changes at all?
4301 !m_foregroundColour
.Ok() && !m_backgroundColour
.Ok() )
4306 GtkRcStyle
*style
= gtk_rc_style_new();
4312 pango_font_description_copy( m_font
.GetNativeFontInfo()->description
);
4314 wxString xfontname
= m_font
.GetNativeFontInfo()->GetXFontName();
4315 style
->fontset_name
= g_strdup(xfontname
.c_str());
4319 if ( m_foregroundColour
.Ok() )
4321 GdkColor
*fg
= m_foregroundColour
.GetColor();
4323 style
->fg
[GTK_STATE_NORMAL
] = *fg
;
4324 style
->color_flags
[GTK_STATE_NORMAL
] = GTK_RC_FG
;
4326 style
->fg
[GTK_STATE_PRELIGHT
] = *fg
;
4327 style
->color_flags
[GTK_STATE_PRELIGHT
] = GTK_RC_FG
;
4329 style
->fg
[GTK_STATE_ACTIVE
] = *fg
;
4330 style
->color_flags
[GTK_STATE_ACTIVE
] = GTK_RC_FG
;
4333 if ( m_backgroundColour
.Ok() )
4335 GdkColor
*bg
= m_backgroundColour
.GetColor();
4337 style
->bg
[GTK_STATE_NORMAL
] = *bg
;
4338 style
->base
[GTK_STATE_NORMAL
] = *bg
;
4339 style
->color_flags
[GTK_STATE_NORMAL
] = (GtkRcFlags
)
4340 (style
->color_flags
[GTK_STATE_NORMAL
] | GTK_RC_BG
| GTK_RC_BASE
);
4342 style
->bg
[GTK_STATE_PRELIGHT
] = *bg
;
4343 style
->base
[GTK_STATE_PRELIGHT
] = *bg
;
4344 style
->color_flags
[GTK_STATE_PRELIGHT
] = (GtkRcFlags
)
4345 (style
->color_flags
[GTK_STATE_PRELIGHT
] | GTK_RC_BG
| GTK_RC_BASE
);
4347 style
->bg
[GTK_STATE_ACTIVE
] = *bg
;
4348 style
->base
[GTK_STATE_ACTIVE
] = *bg
;
4349 style
->color_flags
[GTK_STATE_ACTIVE
] = (GtkRcFlags
)
4350 (style
->color_flags
[GTK_STATE_ACTIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
4352 style
->bg
[GTK_STATE_INSENSITIVE
] = *bg
;
4353 style
->base
[GTK_STATE_INSENSITIVE
] = *bg
;
4354 style
->color_flags
[GTK_STATE_INSENSITIVE
] = (GtkRcFlags
)
4355 (style
->color_flags
[GTK_STATE_INSENSITIVE
] | GTK_RC_BG
| GTK_RC_BASE
);
4361 void wxWindowGTK::ApplyWidgetStyle(bool forceStyle
)
4363 GtkRcStyle
*style
= CreateWidgetStyle(forceStyle
);
4366 DoApplyWidgetStyle(style
);
4367 gtk_rc_style_unref(style
);
4370 // Style change may affect GTK+'s size calculation:
4371 InvalidateBestSize();
4374 void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle
*style
)
4377 gtk_widget_modify_style(m_wxwindow
, style
);
4379 gtk_widget_modify_style(m_widget
, style
);
4382 bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style
)
4384 wxWindowBase::SetBackgroundStyle(style
);
4386 if (style
== wxBG_STYLE_CUSTOM
)
4388 GdkWindow
*window
= (GdkWindow
*) NULL
;
4390 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4392 window
= GetConnectWidget()->window
;
4396 // Make sure GDK/X11 doesn't refresh the window
4398 gdk_window_set_back_pixmap( window
, None
, False
);
4400 Display
* display
= GDK_WINDOW_DISPLAY(window
);
4403 m_needsStyleChange
= false;
4406 // Do in OnIdle, because the window is not yet available
4407 m_needsStyleChange
= true;
4409 // Don't apply widget style, or we get a grey background
4413 // apply style change (forceStyle=true so that new style is applied
4414 // even if the bg colour changed from valid to wxNullColour):
4415 ApplyWidgetStyle(true);
4420 //-----------------------------------------------------------------------------
4421 // Pop-up menu stuff
4422 //-----------------------------------------------------------------------------
4424 #if wxUSE_MENUS_NATIVE
4426 extern "C" WXDLLIMPEXP_CORE
4427 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
4429 *is_waiting
= FALSE
;
4432 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
4434 menu
->SetInvokingWindow( win
);
4436 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
4439 wxMenuItem
*menuitem
= node
->GetData();
4440 if (menuitem
->IsSubMenu())
4442 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
4445 node
= node
->GetNext();
4449 extern "C" WXDLLIMPEXP_CORE
4450 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
4453 gboolean
* WXUNUSED(whatever
),
4455 gpointer user_data
)
4457 // ensure that the menu appears entirely on screen
4459 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
4461 wxSize sizeScreen
= wxGetDisplaySize();
4462 wxPoint
*pos
= (wxPoint
*)user_data
;
4464 gint xmax
= sizeScreen
.x
- req
.width
,
4465 ymax
= sizeScreen
.y
- req
.height
;
4467 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
4468 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
4471 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
4473 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
4475 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
4477 // NOTE: if you change this code, you need to update
4478 // the same code in taskbar.cpp as well. This
4479 // is ugly code duplication, I know,
4481 SetInvokingWindow( menu
, this );
4485 bool is_waiting
= true;
4487 gulong handler
= gtk_signal_connect( GTK_OBJECT(menu
->m_menu
),
4489 GTK_SIGNAL_FUNC(gtk_pop_hide_callback
),
4490 (gpointer
)&is_waiting
);
4494 GtkMenuPositionFunc posfunc
;
4495 if ( x
== -1 && y
== -1 )
4497 // use GTK's default positioning algorithm
4503 pos
= ClientToScreen(wxPoint(x
, y
));
4505 posfunc
= wxPopupMenuPositionCallback
;
4509 GTK_MENU(menu
->m_menu
),
4510 (GtkWidget
*) NULL
, // parent menu shell
4511 (GtkWidget
*) NULL
, // parent menu item
4512 posfunc
, // function to position it
4513 userdata
, // client data
4514 0, // button used to activate it
4516 gtk_get_current_event_time()
4518 gs_timeLastClick
// the time of activation
4524 gtk_main_iteration();
4527 gtk_signal_disconnect(GTK_OBJECT(menu
->m_menu
), handler
);
4532 #endif // wxUSE_MENUS_NATIVE
4534 #if wxUSE_DRAG_AND_DROP
4536 void wxWindowGTK::SetDropTarget( wxDropTarget
*dropTarget
)
4538 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4540 GtkWidget
*dnd_widget
= GetConnectWidget();
4542 if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget
);
4544 if (m_dropTarget
) delete m_dropTarget
;
4545 m_dropTarget
= dropTarget
;
4547 if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget
);
4550 #endif // wxUSE_DRAG_AND_DROP
4552 GtkWidget
* wxWindowGTK::GetConnectWidget()
4554 GtkWidget
*connect_widget
= m_widget
;
4555 if (m_wxwindow
) connect_widget
= m_wxwindow
;
4557 return connect_widget
;
4560 bool wxWindowGTK::IsOwnGtkWindow( GdkWindow
*window
)
4563 return (window
== GTK_PIZZA(m_wxwindow
)->bin_window
);
4565 return (window
== m_widget
->window
);
4568 bool wxWindowGTK::SetFont( const wxFont
&font
)
4570 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
4572 if (!wxWindowBase::SetFont(font
))
4575 // apply style change (forceStyle=true so that new style is applied
4576 // even if the font changed from valid to wxNullFont):
4577 ApplyWidgetStyle(true);
4582 void wxWindowGTK::DoCaptureMouse()
4584 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4586 GdkWindow
*window
= (GdkWindow
*) NULL
;
4588 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4590 window
= GetConnectWidget()->window
;
4592 wxCHECK_RET( window
, _T("CaptureMouse() failed") );
4594 wxCursor
* cursor
= & m_cursor
;
4596 cursor
= wxSTANDARD_CURSOR
;
4598 gdk_pointer_grab( window
, FALSE
,
4600 (GDK_BUTTON_PRESS_MASK
|
4601 GDK_BUTTON_RELEASE_MASK
|
4602 GDK_POINTER_MOTION_HINT_MASK
|
4603 GDK_POINTER_MOTION_MASK
),
4605 cursor
->GetCursor(),
4606 (guint32
)GDK_CURRENT_TIME
);
4607 g_captureWindow
= this;
4608 g_captureWindowHasMouse
= true;
4611 void wxWindowGTK::DoReleaseMouse()
4613 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4615 wxCHECK_RET( g_captureWindow
, wxT("can't release mouse - not captured") );
4617 g_captureWindow
= (wxWindowGTK
*) NULL
;
4619 GdkWindow
*window
= (GdkWindow
*) NULL
;
4621 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
4623 window
= GetConnectWidget()->window
;
4628 gdk_pointer_ungrab ( (guint32
)GDK_CURRENT_TIME
);
4632 wxWindow
*wxWindowBase::GetCapture()
4634 return (wxWindow
*)g_captureWindow
;
4637 bool wxWindowGTK::IsRetained() const
4642 void wxWindowGTK::SetScrollbar( int orient
, int pos
, int thumbVisible
,
4643 int range
, bool refresh
)
4645 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4647 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4649 m_hasScrolling
= true;
4651 if (orient
== wxHORIZONTAL
)
4653 float fpos
= (float)pos
;
4654 float frange
= (float)range
;
4655 float fthumb
= (float)thumbVisible
;
4656 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
4657 if (fpos
< 0.0) fpos
= 0.0;
4659 if ((fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
4660 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
4662 SetScrollPos( orient
, pos
, refresh
);
4666 m_oldHorizontalPos
= fpos
;
4668 m_hAdjust
->lower
= 0.0;
4669 m_hAdjust
->upper
= frange
;
4670 m_hAdjust
->value
= fpos
;
4671 m_hAdjust
->step_increment
= 1.0;
4672 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4673 m_hAdjust
->page_size
= fthumb
;
4677 float fpos
= (float)pos
;
4678 float frange
= (float)range
;
4679 float fthumb
= (float)thumbVisible
;
4680 if (fpos
> frange
-fthumb
) fpos
= frange
-fthumb
;
4681 if (fpos
< 0.0) fpos
= 0.0;
4683 if ((fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
4684 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
4686 SetScrollPos( orient
, pos
, refresh
);
4690 m_oldVerticalPos
= fpos
;
4692 m_vAdjust
->lower
= 0.0;
4693 m_vAdjust
->upper
= frange
;
4694 m_vAdjust
->value
= fpos
;
4695 m_vAdjust
->step_increment
= 1.0;
4696 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
,0));
4697 m_vAdjust
->page_size
= fthumb
;
4700 if (orient
== wxHORIZONTAL
)
4701 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
4703 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
4706 void wxWindowGTK::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
4708 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4710 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4712 if (orient
== wxHORIZONTAL
)
4714 float fpos
= (float)pos
;
4715 if (fpos
> m_hAdjust
->upper
- m_hAdjust
->page_size
) fpos
= m_hAdjust
->upper
- m_hAdjust
->page_size
;
4716 if (fpos
< 0.0) fpos
= 0.0;
4717 m_oldHorizontalPos
= fpos
;
4719 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
4720 m_hAdjust
->value
= fpos
;
4724 float fpos
= (float)pos
;
4725 if (fpos
> m_vAdjust
->upper
- m_vAdjust
->page_size
) fpos
= m_vAdjust
->upper
- m_vAdjust
->page_size
;
4726 if (fpos
< 0.0) fpos
= 0.0;
4727 m_oldVerticalPos
= fpos
;
4729 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
4730 m_vAdjust
->value
= fpos
;
4733 if (m_wxwindow
->window
)
4735 if (orient
== wxHORIZONTAL
)
4737 gtk_signal_disconnect_by_func( GTK_OBJECT(m_hAdjust
),
4738 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
4740 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
4742 gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed",
4743 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
4747 gtk_signal_disconnect_by_func( GTK_OBJECT(m_vAdjust
),
4748 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
4750 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
4752 gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed",
4753 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
4758 int wxWindowGTK::GetScrollThumb( int orient
) const
4760 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4762 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4764 if (orient
== wxHORIZONTAL
)
4765 return (int)(m_hAdjust
->page_size
+0.5);
4767 return (int)(m_vAdjust
->page_size
+0.5);
4770 int wxWindowGTK::GetScrollPos( int orient
) const
4772 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4774 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4776 if (orient
== wxHORIZONTAL
)
4777 return (int)(m_hAdjust
->value
+0.5);
4779 return (int)(m_vAdjust
->value
+0.5);
4782 int wxWindowGTK::GetScrollRange( int orient
) const
4784 wxCHECK_MSG( m_widget
!= NULL
, 0, wxT("invalid window") );
4786 wxCHECK_MSG( m_wxwindow
!= NULL
, 0, wxT("window needs client area for scrolling") );
4788 if (orient
== wxHORIZONTAL
)
4789 return (int)(m_hAdjust
->upper
+0.5);
4791 return (int)(m_vAdjust
->upper
+0.5);
4794 void wxWindowGTK::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
4796 wxCHECK_RET( m_widget
!= NULL
, wxT("invalid window") );
4798 wxCHECK_RET( m_wxwindow
!= NULL
, wxT("window needs client area for scrolling") );
4800 // No scrolling requested.
4801 if ((dx
== 0) && (dy
== 0)) return;
4804 if (!m_updateRegion
.IsEmpty())
4806 m_updateRegion
.Offset( dx
, dy
);
4810 GetClientSize( &cw
, &ch
);
4811 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
4814 if (!m_clearRegion
.IsEmpty())
4816 m_clearRegion
.Offset( dx
, dy
);
4820 GetClientSize( &cw
, &ch
);
4821 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
4825 m_clipPaintRegion
= true;
4827 gtk_pizza_scroll( GTK_PIZZA(m_wxwindow
), -dx
, -dy
);
4829 m_clipPaintRegion
= false;
4833 // Find the wxWindow at the current mouse position, also returning the mouse
4835 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
4837 pt
= wxGetMousePosition();
4838 wxWindow
* found
= wxFindWindowAtPoint(pt
);
4842 // Get the current mouse position.
4843 wxPoint
wxGetMousePosition()
4845 /* This crashes when used within wxHelpContext,
4846 so we have to use the X-specific implementation below.
4848 GdkModifierType *mask;
4849 (void) gdk_window_get_pointer(NULL, &x, &y, mask);
4851 return wxPoint(x, y);
4855 GdkWindow
* windowAtPtr
= gdk_window_at_pointer(& x
, & y
);
4857 Display
*display
= windowAtPtr
? GDK_WINDOW_XDISPLAY(windowAtPtr
) : GDK_DISPLAY();
4858 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
4859 Window rootReturn
, childReturn
;
4860 int rootX
, rootY
, winX
, winY
;
4861 unsigned int maskReturn
;
4863 XQueryPointer (display
,
4867 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
4868 return wxPoint(rootX
, rootY
);
4872 // ----------------------------------------------------------------------------
4874 // ----------------------------------------------------------------------------
4876 class wxWinModule
: public wxModule
4883 DECLARE_DYNAMIC_CLASS(wxWinModule
)
4886 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
4888 bool wxWinModule::OnInit()
4890 // g_eraseGC = gdk_gc_new( GDK_ROOT_PARENT() );
4891 // gdk_gc_set_fill( g_eraseGC, GDK_SOLID );
4896 void wxWinModule::OnExit()
4899 gdk_gc_unref( g_eraseGC
);