]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
f6bcfd97 | 2 | // Name: gtk/window.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
c67d8618 | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling, Julian Smart |
5e0aa05a | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | ||
11 | #ifdef __GNUG__ | |
bfc6fde4 | 12 | #pragma implementation "window.h" |
c801d85f KB |
13 | #endif |
14 | ||
d02af7bb JJ |
15 | #ifdef __VMS |
16 | #define XWarpPointer XWARPPOINTER | |
17 | #endif | |
18 | ||
c801d85f KB |
19 | #include "wx/defs.h" |
20 | #include "wx/window.h" | |
33611ebb | 21 | #include "wx/dcclient.h" |
c801d85f KB |
22 | #include "wx/frame.h" |
23 | #include "wx/app.h" | |
24 | #include "wx/layout.h" | |
25 | #include "wx/utils.h" | |
26 | #include "wx/dialog.h" | |
27 | #include "wx/msgdlg.h" | |
0fc5dbf5 | 28 | #include "wx/module.h" |
bfc6fde4 | 29 | |
06cfab17 | 30 | #if wxUSE_DRAG_AND_DROP |
bfc6fde4 | 31 | #include "wx/dnd.h" |
ac57418f | 32 | #endif |
bfc6fde4 | 33 | |
cad880f5 | 34 | #if wxUSE_TOOLTIPS |
bfc6fde4 | 35 | #include "wx/tooltip.h" |
cad880f5 | 36 | #endif |
bfc6fde4 | 37 | |
f6bcfd97 BP |
38 | #if wxUSE_CARET |
39 | #include "wx/caret.h" | |
40 | #endif // wxUSE_CARET | |
41 | ||
ab93a576 | 42 | #if wxUSE_TEXTCTRL |
0fc5dbf5 | 43 | #include "wx/textctrl.h" |
ab93a576 RD |
44 | #endif |
45 | ||
30dea054 | 46 | #include "wx/menu.h" |
d4c99d6f | 47 | #include "wx/statusbr.h" |
b4071e91 | 48 | #include "wx/intl.h" |
3bc755fc | 49 | #include "wx/settings.h" |
3069ac4e | 50 | #include "wx/log.h" |
48d011c8 | 51 | #include "wx/fontutil.h" |
b4071e91 | 52 | |
3ac8d3bc RR |
53 | #ifdef __WXDEBUG__ |
54 | #include "wx/thread.h" | |
55 | #endif | |
56 | ||
b4071e91 | 57 | #include <math.h> |
fab591c5 | 58 | #include <ctype.h> |
c801d85f | 59 | |
9e691f46 | 60 | #include "wx/gtk/private.h" |
3ac8d3bc RR |
61 | #include <gdk/gdkprivate.h> |
62 | #include <gdk/gdkkeysyms.h> | |
3ac8d3bc | 63 | #include <gdk/gdkx.h> |
6bc8a1c8 | 64 | |
8cb9f0d0 RR |
65 | #include <gtk/gtk.h> |
66 | #include <gtk/gtkprivate.h> | |
67 | ||
68 | #include "wx/gtk/win_gtk.h" | |
69 | ||
2b5f62a0 VZ |
70 | #ifdef __WXGTK20__ |
71 | #include <pango/pangox.h> | |
72 | #endif | |
73 | ||
9e691f46 VZ |
74 | #ifdef __WXGTK20__ |
75 | #define SET_CONTAINER_FOCUS(w, d) gtk_widget_child_focus((w), (d)) | |
76 | #else | |
77 | #define SET_CONTAINER_FOCUS(w, d) gtk_container_focus(GTK_CONTAINER(w), (d)) | |
78 | #endif | |
79 | ||
4e5a4c69 RR |
80 | #ifdef __WXGTK20__ |
81 | #ifdef HAVE_XIM | |
82 | #undef HAVE_XIM | |
83 | #endif | |
84 | #endif | |
85 | ||
af1d24da RR |
86 | #ifdef __WXGTK20__ |
87 | extern GtkContainerClass *pizza_parent_class; | |
88 | #endif | |
89 | ||
868a2826 RR |
90 | //----------------------------------------------------------------------------- |
91 | // documentation on internals | |
92 | //----------------------------------------------------------------------------- | |
93 | ||
94 | /* | |
95 | I have been asked several times about writing some documentation about | |
96 | the GTK port of wxWindows, especially its internal structures. Obviously, | |
97 | you cannot understand wxGTK without knowing a little about the GTK, but | |
47d67540 | 98 | some more information about what the wxWindow, which is the base class |
868a2826 | 99 | for all other window classes, does seems required as well. |
47d67540 | 100 | |
30760ce7 RR |
101 | I) |
102 | ||
868a2826 | 103 | What does wxWindow do? It contains the common interface for the following |
e380f72b | 104 | jobs of its descendants: |
47d67540 | 105 | |
868a2826 | 106 | 1) Define the rudimentary behaviour common to all window classes, such as |
e380f72b RR |
107 | resizing, intercepting user input (so as to make it possible to use these |
108 | events for special purposes in a derived class), window names etc. | |
868a2826 RR |
109 | |
110 | 2) Provide the possibility to contain and manage children, if the derived | |
111 | class is allowed to contain children, which holds true for those window | |
e380f72b | 112 | classes which do not display a native GTK widget. To name them, these |
868a2826 | 113 | classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame- |
47d67540 | 114 | work classes are a special case and are handled a bit differently from |
e380f72b | 115 | the rest. The same holds true for the wxNotebook class. |
47d67540 | 116 | |
868a2826 RR |
117 | 3) Provide the possibility to draw into a client area of a window. This, |
118 | too, only holds true for classes that do not display a native GTK widget | |
119 | as above. | |
47d67540 | 120 | |
e380f72b RR |
121 | 4) Provide the entire mechanism for scrolling widgets. This actual inter- |
122 | face for this is usually in wxScrolledWindow, but the GTK implementation | |
868a2826 | 123 | is in this class. |
47d67540 | 124 | |
868a2826 RR |
125 | 5) A multitude of helper or extra methods for special purposes, such as |
126 | Drag'n'Drop, managing validators etc. | |
47d67540 | 127 | |
30760ce7 RR |
128 | 6) Display a border (sunken, raised, simple or none). |
129 | ||
e380f72b RR |
130 | Normally one might expect, that one wxWindows window would always correspond |
131 | to one GTK widget. Under GTK, there is no such allround widget that has all | |
868a2826 RR |
132 | the functionality. Moreover, the GTK defines a client area as a different |
133 | widget from the actual widget you are handling. Last but not least some | |
134 | special classes (e.g. wxFrame) handle different categories of widgets and | |
135 | still have the possibility to draw something in the client area. | |
136 | It was therefore required to write a special purpose GTK widget, that would | |
137 | represent a client area in the sense of wxWindows capable to do the jobs | |
138 | 2), 3) and 4). I have written this class and it resides in win_gtk.c of | |
139 | this directory. | |
47d67540 | 140 | |
868a2826 | 141 | All windows must have a widget, with which they interact with other under- |
e380f72b | 142 | lying GTK widgets. It is this widget, e.g. that has to be resized etc and |
868a2826 | 143 | thw wxWindow class has a member variable called m_widget which holds a |
e380f72b RR |
144 | pointer to this widget. When the window class represents a GTK native widget, |
145 | this is (in most cases) the only GTK widget the class manages. E.g. the | |
146 | wxStatitText class handles only a GtkLabel widget a pointer to which you | |
147 | can find in m_widget (defined in wxWindow) | |
8bbe427f | 148 | |
e380f72b | 149 | When the class has a client area for drawing into and for containing children |
da048e3d | 150 | it has to handle the client area widget (of the type GtkPizza, defined in |
8bbe427f VZ |
151 | win_gtk.c), but there could be any number of widgets, handled by a class |
152 | The common rule for all windows is only, that the widget that interacts with | |
153 | the rest of GTK must be referenced in m_widget and all other widgets must be | |
154 | children of this widget on the GTK level. The top-most widget, which also | |
155 | represents the client area, must be in the m_wxwindow field and must be of | |
da048e3d | 156 | the type GtkPizza. |
47d67540 | 157 | |
868a2826 RR |
158 | As I said, the window classes that display a GTK native widget only have |
159 | one widget, so in the case of e.g. the wxButton class m_widget holds a | |
160 | pointer to a GtkButton widget. But windows with client areas (for drawing | |
161 | and children) have a m_widget field that is a pointer to a GtkScrolled- | |
da048e3d | 162 | Window and a m_wxwindow field that is pointer to a GtkPizza and this |
868a2826 | 163 | one is (in the GTK sense) a child of the GtkScrolledWindow. |
47d67540 | 164 | |
868a2826 RR |
165 | If the m_wxwindow field is set, then all input to this widget is inter- |
166 | cepted and sent to the wxWindows class. If not, all input to the widget | |
167 | that gets pointed to by m_widget gets intercepted and sent to the class. | |
148cd9b6 | 168 | |
30760ce7 | 169 | II) |
148cd9b6 | 170 | |
30760ce7 RR |
171 | The design of scrolling in wxWindows is markedly different from that offered |
172 | by the GTK itself and therefore we cannot simply take it as it is. In GTK, | |
173 | clicking on a scrollbar belonging to scrolled window will inevitably move | |
174 | the window. In wxWindows, the scrollbar will only emit an event, send this | |
175 | to (normally) a wxScrolledWindow and that class will call ScrollWindow() | |
da048e3d | 176 | which actually moves the window and its subchildren. Note that GtkPizza |
30760ce7 RR |
177 | memorizes how much it has been scrolled but that wxWindows forgets this |
178 | so that the two coordinates systems have to be kept in synch. This is done | |
da048e3d | 179 | in various places using the pizza->xoffset and pizza->yoffset values. |
148cd9b6 VZ |
180 | |
181 | III) | |
182 | ||
30760ce7 RR |
183 | Singularily the most broken code in GTK is the code that is supposes to |
184 | inform subwindows (child windows) about new positions. Very often, duplicate | |
185 | events are sent without changes in size or position, equally often no | |
186 | events are sent at all (All this is due to a bug in the GtkContainer code | |
187 | which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores | |
188 | GTK's own system and it simply waits for size events for toplevel windows | |
189 | and then iterates down the respective size events to all window. This has | |
190 | the disadvantage, that windows might get size events before the GTK widget | |
191 | actually has the reported size. This doesn't normally pose any problem, but | |
3017f78d | 192 | the OpenGl drawing routines rely on correct behaviour. Therefore, I have |
30760ce7 RR |
193 | added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas, |
194 | i.e. the wxGLCanvas will emit a size event, when (and not before) the X11 | |
195 | window that is used for OpenGl output really has that size (as reported by | |
196 | GTK). | |
197 | ||
198 | IV) | |
148cd9b6 | 199 | |
30760ce7 RR |
200 | If someone at some point of time feels the immense desire to have a look at, |
201 | change or attempt to optimse the Refresh() logic, this person will need an | |
202 | intimate understanding of what a "draw" and what an "expose" events are and | |
203 | what there are used for, in particular when used in connection with GTK's | |
204 | own windowless widgets. Beware. | |
148cd9b6 | 205 | |
30760ce7 | 206 | V) |
148cd9b6 | 207 | |
30760ce7 RR |
208 | Cursors, too, have been a constant source of pleasure. The main difficulty |
209 | is that a GdkWindow inherits a cursor if the programmer sets a new cursor | |
210 | for the parent. To prevent this from doing too much harm, I use idle time | |
211 | to set the cursor over and over again, starting from the toplevel windows | |
212 | and ending with the youngest generation (speaking of parent and child windows). | |
213 | Also don't forget that cursors (like much else) are connected to GdkWindows, | |
214 | not GtkWidgets and that the "window" field of a GtkWidget might very well | |
148cd9b6 | 215 | point to the GdkWindow of the parent widget (-> "window less widget") and |
30760ce7 | 216 | that the two obviously have very different meanings. |
868a2826 RR |
217 | |
218 | */ | |
219 | ||
f03fc89f VZ |
220 | //----------------------------------------------------------------------------- |
221 | // data | |
222 | //----------------------------------------------------------------------------- | |
223 | ||
224 | extern wxList wxPendingDelete; | |
225 | extern bool g_blockEventsOnDrag; | |
226 | extern bool g_blockEventsOnScroll; | |
238d735d | 227 | extern wxCursor g_globalCursor; |
f68586e5 | 228 | |
4e5a4c69 RR |
229 | static GdkGC *g_eraseGC = NULL; |
230 | ||
1e6feb95 VZ |
231 | // mouse capture state: the window which has it and if the mouse is currently |
232 | // inside it | |
233 | static wxWindowGTK *g_captureWindow = (wxWindowGTK*) NULL; | |
234 | static bool g_captureWindowHasMouse = FALSE; | |
235 | ||
236 | /* extern */ wxWindowGTK *g_focusWindow = (wxWindowGTK*) NULL; | |
237 | ||
238 | // the last window which had the focus - this is normally never NULL (except | |
239 | // if we never had focus at all) as even when g_focusWindow is NULL it still | |
240 | // keeps its previous value | |
d7fa7eaa | 241 | static wxWindowGTK *g_focusWindowLast = (wxWindowGTK*) NULL; |
148cd9b6 | 242 | |
e8c12a53 VS |
243 | // the frame that is currently active (i.e. its child has focus). It is |
244 | // used to generate wxActivateEvents | |
d7fa7eaa | 245 | static wxWindowGTK *g_activeFrame = (wxWindowGTK*) NULL; |
e8c12a53 VS |
246 | static bool g_activeFrameLostFocus = FALSE; |
247 | ||
d7fa7eaa RR |
248 | // If a window get the focus set but has not been realized |
249 | // yet, defer setting the focus to idle time. | |
250 | wxWindowGTK *g_delayedFocus = (wxWindowGTK*) NULL; | |
251 | ||
148cd9b6 VZ |
252 | // if we detect that the app has got/lost the focus, we set this variable to |
253 | // either TRUE or FALSE and an activate event will be sent during the next | |
254 | // OnIdle() call and it is reset to -1: this value means that we shouldn't | |
255 | // send any activate events at all | |
256 | static int g_sendActivateEvent = -1; | |
f03fc89f VZ |
257 | |
258 | /* hack: we need something to pass to gtk_menu_popup, so we store the time of | |
259 | the last click here */ | |
260 | static guint32 gs_timeLastClick = 0; | |
261 | ||
3ac8d3bc RR |
262 | extern bool g_mainThreadLocked; |
263 | ||
2e563988 RR |
264 | //----------------------------------------------------------------------------- |
265 | // debug | |
266 | //----------------------------------------------------------------------------- | |
267 | ||
d52e91c9 | 268 | #ifndef __WXGTK20__ |
2b5f62a0 | 269 | #define DISABLE_STYLE_IF_BROKEN_THEME 0 |
d52e91c9 | 270 | #endif |
a56fcaaf | 271 | |
2e563988 RR |
272 | #ifdef __WXDEBUG__ |
273 | ||
c6e62f74 KB |
274 | #if wxUSE_THREADS |
275 | # define DEBUG_MAIN_THREAD if (wxThread::IsMain() && g_mainThreadLocked) printf("gui reentrance"); | |
276 | #else | |
277 | # define DEBUG_MAIN_THREAD | |
278 | #endif | |
559d79aa BJ |
279 | #else |
280 | #define DEBUG_MAIN_THREAD | |
f03fc89f | 281 | #endif // Debug |
ff8bfdbb | 282 | |
6cad4f1b VZ |
283 | // the trace mask used for the focus debugging messages |
284 | #define TRACE_FOCUS _T("focus") | |
285 | ||
85eb36c2 RR |
286 | //----------------------------------------------------------------------------- |
287 | // missing gdk functions | |
288 | //----------------------------------------------------------------------------- | |
289 | ||
290 | void | |
291 | gdk_window_warp_pointer (GdkWindow *window, | |
c50f1fb9 VZ |
292 | gint x, |
293 | gint y) | |
85eb36c2 | 294 | { |
dd00f3f6 | 295 | #ifndef __WXGTK20__ |
85eb36c2 | 296 | GdkWindowPrivate *priv; |
dd00f3f6 | 297 | #endif |
c50f1fb9 | 298 | |
85eb36c2 | 299 | if (!window) |
27df579a | 300 | window = GDK_ROOT_PARENT(); |
c50f1fb9 | 301 | |
dd00f3f6 OK |
302 | #ifdef __WXGTK20__ |
303 | if (!GDK_WINDOW_DESTROYED(window)) | |
304 | { | |
305 | XWarpPointer (GDK_WINDOW_XDISPLAY(window), | |
306 | None, /* not source window -> move from anywhere */ | |
307 | GDK_WINDOW_XID(window), /* dest window */ | |
308 | 0, 0, 0, 0, /* not source window -> move from anywhere */ | |
309 | x, y ); | |
310 | } | |
311 | #else | |
85eb36c2 | 312 | priv = (GdkWindowPrivate*) window; |
c50f1fb9 | 313 | |
85eb36c2 RR |
314 | if (!priv->destroyed) |
315 | { | |
c50f1fb9 | 316 | XWarpPointer (priv->xdisplay, |
85eb36c2 | 317 | None, /* not source window -> move from anywhere */ |
c50f1fb9 | 318 | priv->xwindow, /* dest window */ |
85eb36c2 | 319 | 0, 0, 0, 0, /* not source window -> move from anywhere */ |
c50f1fb9 | 320 | x, y ); |
85eb36c2 | 321 | } |
dd00f3f6 | 322 | #endif |
85eb36c2 RR |
323 | } |
324 | ||
acfd422a | 325 | //----------------------------------------------------------------------------- |
a2053b27 | 326 | // idle system |
acfd422a RR |
327 | //----------------------------------------------------------------------------- |
328 | ||
a2053b27 RR |
329 | extern void wxapp_install_idle_handler(); |
330 | extern bool g_isIdle; | |
331 | ||
ed673c6a RR |
332 | //----------------------------------------------------------------------------- |
333 | // local code (see below) | |
334 | //----------------------------------------------------------------------------- | |
335 | ||
f6bcfd97 | 336 | // returns the child of win which currently has focus or NULL if not found |
1e6feb95 | 337 | // |
fc71ef6e | 338 | // Note: can't be static, needed by textctrl.cpp. |
3379ed37 | 339 | wxWindow *wxFindFocusedChild(wxWindowGTK *win) |
f6bcfd97 | 340 | { |
3379ed37 | 341 | wxWindow *winFocus = wxWindowGTK::FindFocus(); |
f6bcfd97 | 342 | if ( !winFocus ) |
3379ed37 | 343 | return (wxWindow *)NULL; |
f6bcfd97 BP |
344 | |
345 | if ( winFocus == win ) | |
3379ed37 | 346 | return (wxWindow *)win; |
f6bcfd97 BP |
347 | |
348 | for ( wxWindowList::Node *node = win->GetChildren().GetFirst(); | |
349 | node; | |
350 | node = node->GetNext() ) | |
351 | { | |
3379ed37 | 352 | wxWindow *child = wxFindFocusedChild(node->GetData()); |
f6bcfd97 BP |
353 | if ( child ) |
354 | return child; | |
355 | } | |
356 | ||
3379ed37 | 357 | return (wxWindow *)NULL; |
f6bcfd97 BP |
358 | } |
359 | ||
1e6feb95 | 360 | static void draw_frame( GtkWidget *widget, wxWindowGTK *win ) |
ed673c6a | 361 | { |
1e6feb95 VZ |
362 | // wxUniversal widgets draw the borders and scrollbars themselves |
363 | #ifndef __WXUNIVERSAL__ | |
ed673c6a RR |
364 | if (!win->m_hasVMT) |
365 | return; | |
366 | ||
367 | int dw = 0; | |
368 | int dh = 0; | |
369 | ||
5b8a521e | 370 | if (win->m_hasScrolling) |
ed673c6a | 371 | { |
beab25bd | 372 | GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(widget); |
2daa0ce9 | 373 | |
beab25bd RR |
374 | GtkRequisition vscroll_req; |
375 | vscroll_req.width = 2; | |
376 | vscroll_req.height = 2; | |
377 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window->vscrollbar) )->size_request ) | |
378 | (scroll_window->vscrollbar, &vscroll_req ); | |
2daa0ce9 | 379 | |
beab25bd RR |
380 | GtkRequisition hscroll_req; |
381 | hscroll_req.width = 2; | |
382 | hscroll_req.height = 2; | |
383 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window->hscrollbar) )->size_request ) | |
384 | (scroll_window->hscrollbar, &hscroll_req ); | |
9000c624 | 385 | |
beab25bd | 386 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(widget) ); |
ed673c6a | 387 | |
beab25bd RR |
388 | if (scroll_window->vscrollbar_visible) |
389 | { | |
390 | dw += vscroll_req.width; | |
391 | dw += scroll_class->scrollbar_spacing; | |
392 | } | |
ed673c6a | 393 | |
beab25bd RR |
394 | if (scroll_window->hscrollbar_visible) |
395 | { | |
396 | dh += hscroll_req.height; | |
397 | dh += scroll_class->scrollbar_spacing; | |
398 | } | |
399 | } | |
ed673c6a RR |
400 | |
401 | int dx = 0; | |
402 | int dy = 0; | |
403 | if (GTK_WIDGET_NO_WINDOW (widget)) | |
404 | { | |
405 | dx += widget->allocation.x; | |
406 | dy += widget->allocation.y; | |
407 | } | |
408 | ||
409 | if (win->HasFlag(wxRAISED_BORDER)) | |
410 | { | |
411 | gtk_draw_shadow( widget->style, | |
412 | widget->window, | |
413 | GTK_STATE_NORMAL, | |
414 | GTK_SHADOW_OUT, | |
415 | dx, dy, | |
07f5b19a | 416 | widget->allocation.width-dw, widget->allocation.height-dh ); |
ed673c6a RR |
417 | return; |
418 | } | |
419 | ||
420 | if (win->HasFlag(wxSUNKEN_BORDER)) | |
421 | { | |
422 | gtk_draw_shadow( widget->style, | |
423 | widget->window, | |
424 | GTK_STATE_NORMAL, | |
425 | GTK_SHADOW_IN, | |
426 | dx, dy, | |
07f5b19a | 427 | widget->allocation.width-dw, widget->allocation.height-dh ); |
ed673c6a RR |
428 | return; |
429 | } | |
148cd9b6 | 430 | |
ed673c6a RR |
431 | if (win->HasFlag(wxSIMPLE_BORDER)) |
432 | { | |
433 | GdkGC *gc; | |
b02da6b1 | 434 | gc = gdk_gc_new( widget->window ); |
ed673c6a | 435 | gdk_gc_set_foreground( gc, &widget->style->black ); |
148cd9b6 | 436 | gdk_draw_rectangle( widget->window, gc, FALSE, |
ed673c6a | 437 | dx, dy, |
07f5b19a | 438 | widget->allocation.width-dw-1, widget->allocation.height-dh-1 ); |
ed673c6a RR |
439 | gdk_gc_unref( gc ); |
440 | return; | |
441 | } | |
1e6feb95 | 442 | #endif // __WXUNIVERSAL__ |
ed673c6a RR |
443 | } |
444 | ||
445 | //----------------------------------------------------------------------------- | |
446 | // "expose_event" of m_widget | |
447 | //----------------------------------------------------------------------------- | |
448 | ||
1e6feb95 | 449 | gint gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxWindowGTK *win ) |
ed673c6a | 450 | { |
b6fa52db | 451 | if (gdk_event->count > 0) return FALSE; |
1e6feb95 | 452 | |
ed673c6a | 453 | draw_frame( widget, win ); |
1e6feb95 | 454 | |
af1d24da RR |
455 | #ifdef __WXGTK20__ |
456 | ||
457 | (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, gdk_event); | |
0fc5dbf5 VZ |
458 | |
459 | #endif | |
b6fa52db | 460 | return TRUE; |
ed673c6a RR |
461 | } |
462 | ||
463 | //----------------------------------------------------------------------------- | |
147bc491 | 464 | // "draw" of m_widget |
ed673c6a RR |
465 | //----------------------------------------------------------------------------- |
466 | ||
67d78217 RR |
467 | #ifndef __WXGTK20__ |
468 | ||
1e6feb95 | 469 | static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxWindowGTK *win ) |
ed673c6a RR |
470 | { |
471 | draw_frame( widget, win ); | |
472 | } | |
473 | ||
1c6896d7 | 474 | #endif // GTK+ < 2.0 |
c5b42c87 | 475 | |
47c93b63 RR |
476 | //----------------------------------------------------------------------------- |
477 | // "size_request" of m_widget | |
478 | //----------------------------------------------------------------------------- | |
479 | ||
480 | static void gtk_window_size_request_callback( GtkWidget *widget, GtkRequisition *requisition, wxWindow *win ) | |
481 | { | |
482 | int w,h; | |
483 | win->GetSize( &w, &h ); | |
484 | if (w < 2) w = 2; | |
485 | if (h < 2) h = 2; | |
1e6feb95 | 486 | |
47c93b63 RR |
487 | requisition->height = h; |
488 | requisition->width = w; | |
489 | } | |
490 | ||
c801d85f | 491 | //----------------------------------------------------------------------------- |
034be888 | 492 | // "expose_event" of m_wxwindow |
c801d85f KB |
493 | //----------------------------------------------------------------------------- |
494 | ||
1e6feb95 VZ |
495 | static int gtk_window_expose_callback( GtkWidget *widget, |
496 | GdkEventExpose *gdk_event, | |
497 | wxWindow *win ) | |
47d67540 | 498 | { |
3ac8d3bc RR |
499 | DEBUG_MAIN_THREAD |
500 | ||
b6fa52db RR |
501 | if (g_isIdle) |
502 | wxapp_install_idle_handler(); | |
1e6feb95 | 503 | |
3fc6e5fa RR |
504 | #ifdef __WXGTK20__ |
505 | // This callback gets called in drawing-idle time under | |
506 | // GTK 2.0, so we don't need to defer anything to idle | |
507 | // time anymore. | |
2b5f62a0 | 508 | |
3fc6e5fa RR |
509 | GtkPizza *pizza = GTK_PIZZA( widget ); |
510 | if (gdk_event->window != pizza->bin_window) return FALSE; | |
2b5f62a0 | 511 | |
d7fa7eaa RR |
512 | #if 0 |
513 | if (win->GetName()) | |
3d2d8da1 RR |
514 | { |
515 | wxPrintf( wxT("OnExpose from ") ); | |
516 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
517 | wxPrintf( win->GetClassInfo()->GetClassName() ); | |
518 | wxPrintf( wxT(" %d %d %d %d\n"), (int)gdk_event->area.x, | |
519 | (int)gdk_event->area.y, | |
520 | (int)gdk_event->area.width, | |
521 | (int)gdk_event->area.height ); | |
522 | } | |
d7fa7eaa | 523 | #endif |
1e6feb95 | 524 | |
b15ed747 RR |
525 | win->GetUpdateRegion() = wxRegion( gdk_event->region ); |
526 | ||
527 | win->GtkSendPaintEvents(); | |
528 | ||
2b5f62a0 | 529 | |
3fc6e5fa | 530 | // Let parent window draw window less widgets |
b15ed747 RR |
531 | (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, gdk_event); |
532 | #else | |
533 | // This gets called immediately after an expose event | |
534 | // under GTK 1.2 so we collect the calls and wait for | |
535 | // the idle handler to pick things up. | |
2b5f62a0 | 536 | |
2bc6945a RR |
537 | win->GetUpdateRegion().Union( gdk_event->area.x, |
538 | gdk_event->area.y, | |
539 | gdk_event->area.width, | |
540 | gdk_event->area.height ); | |
d665f50b JS |
541 | win->m_clearRegion.Union( gdk_event->area.x, |
542 | gdk_event->area.y, | |
543 | gdk_event->area.width, | |
544 | gdk_event->area.height ); | |
0e09f76e | 545 | |
8f3e7ecc | 546 | // Actual redrawing takes place in idle time. |
62cb3cd8 | 547 | // win->GtkUpdate(); |
0fc5dbf5 | 548 | #endif |
f7a11f8c | 549 | |
3fc6e5fa | 550 | return FALSE; |
b6fa52db RR |
551 | } |
552 | ||
553 | //----------------------------------------------------------------------------- | |
554 | // "event" of m_wxwindow | |
555 | //----------------------------------------------------------------------------- | |
556 | ||
beab25bd RR |
557 | // GTK thinks it is clever and filters out a certain amount of "unneeded" |
558 | // expose events. We need them, of course, so we override the main event | |
559 | // procedure in GtkWidget by giving our own handler for all system events. | |
560 | // There, we look for expose events ourselves whereas all other events are | |
561 | // handled normally. | |
b6fa52db | 562 | |
1e6feb95 VZ |
563 | gint gtk_window_event_event_callback( GtkWidget *widget, |
564 | GdkEventExpose *event, | |
565 | wxWindow *win ) | |
b6fa52db RR |
566 | { |
567 | if (event->type == GDK_EXPOSE) | |
568 | { | |
569 | gint ret = gtk_window_expose_callback( widget, event, win ); | |
570 | return ret; | |
571 | } | |
572 | ||
b6fa52db | 573 | return FALSE; |
362c6693 | 574 | } |
c801d85f KB |
575 | |
576 | //----------------------------------------------------------------------------- | |
034be888 | 577 | // "draw" of m_wxwindow |
2f2aa628 | 578 | //----------------------------------------------------------------------------- |
c801d85f | 579 | |
67d78217 RR |
580 | #ifndef __WXGTK20__ |
581 | ||
beab25bd | 582 | // This callback is a complete replacement of the gtk_pizza_draw() function, |
67d78217 | 583 | // which is disabled. |
b6fa52db | 584 | |
1e6feb95 VZ |
585 | static void gtk_window_draw_callback( GtkWidget *widget, |
586 | GdkRectangle *rect, | |
587 | wxWindow *win ) | |
47d67540 | 588 | { |
3ac8d3bc RR |
589 | DEBUG_MAIN_THREAD |
590 | ||
c50f1fb9 | 591 | if (g_isIdle) |
a2053b27 | 592 | wxapp_install_idle_handler(); |
2d19ad25 | 593 | |
beab25bd RR |
594 | // The wxNO_FULL_REPAINT_ON_RESIZE flag only works if |
595 | // there are no child windows. | |
e22454be RR |
596 | if ((win->HasFlag(wxNO_FULL_REPAINT_ON_RESIZE)) && |
597 | (win->GetChildren().GetCount() == 0)) | |
598 | { | |
599 | return; | |
600 | } | |
2d19ad25 | 601 | |
d7fa7eaa RR |
602 | #if 0 |
603 | if (win->GetName()) | |
3d2d8da1 RR |
604 | { |
605 | wxPrintf( wxT("OnDraw from ") ); | |
606 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
607 | wxPrintf( win->GetClassInfo()->GetClassName() ); | |
608 | wxPrintf( wxT(" %d %d %d %d\n"), (int)rect->x, | |
609 | (int)rect->y, | |
610 | (int)rect->width, | |
611 | (int)rect->height ); | |
612 | } | |
d7fa7eaa | 613 | #endif |
1e6feb95 | 614 | |
2e09dc2d | 615 | #ifndef __WXUNIVERSAL__ |
b420fb6a | 616 | GtkPizza *pizza = GTK_PIZZA (widget); |
2bc6945a | 617 | |
9cc7121f | 618 | if (win->GetThemeEnabled()) |
789dbcd4 | 619 | { |
9cc7121f RR |
620 | wxWindow *parent = win->GetParent(); |
621 | while (parent && !parent->IsTopLevel()) | |
789dbcd4 | 622 | parent = parent->GetParent(); |
9cc7121f RR |
623 | if (!parent) |
624 | parent = win; | |
625 | ||
90350682 VZ |
626 | gtk_paint_flat_box (parent->m_widget->style, |
627 | pizza->bin_window, | |
628 | GTK_STATE_NORMAL, | |
629 | GTK_SHADOW_NONE, | |
630 | rect, | |
631 | parent->m_widget, | |
632 | (char *)"base", | |
633 | 0, 0, -1, -1); | |
789dbcd4 | 634 | } |
2e09dc2d | 635 | #endif |
1e6feb95 | 636 | |
62cb3cd8 | 637 | win->m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height ); |
9cc7121f | 638 | win->GetUpdateRegion().Union( rect->x, rect->y, rect->width, rect->height ); |
148cd9b6 | 639 | |
62cb3cd8 | 640 | // Update immediately, not in idle time. |
010afced | 641 | win->GtkUpdate(); |
1e6feb95 | 642 | |
8f3e7ecc | 643 | #ifndef __WXUNIVERSAL__ |
beab25bd | 644 | // Redraw child widgets |
e22454be RR |
645 | GList *children = pizza->children; |
646 | while (children) | |
647 | { | |
beab25bd RR |
648 | GtkPizzaChild *child = (GtkPizzaChild*) children->data; |
649 | children = children->next; | |
b420fb6a | 650 | |
beab25bd RR |
651 | GdkRectangle child_area; |
652 | if (gtk_widget_intersect (child->widget, rect, &child_area)) | |
653 | { | |
654 | gtk_widget_draw (child->widget, &child_area /* (GdkRectangle*) NULL*/ ); | |
655 | } | |
e22454be | 656 | } |
8f3e7ecc | 657 | #endif |
362c6693 | 658 | } |
c801d85f | 659 | |
67d78217 RR |
660 | #endif |
661 | ||
c801d85f | 662 | //----------------------------------------------------------------------------- |
b292e2f5 | 663 | // "key_press_event" from any window |
c801d85f | 664 | //----------------------------------------------------------------------------- |
c801d85f | 665 | |
74710601 VZ |
666 | // set WXTRACE to this to see the key event codes on the console |
667 | #define TRACE_KEYS _T("keyevent") | |
f17393f1 | 668 | |
1c6896d7 VZ |
669 | // translates an X key symbol to WXK_XXX value |
670 | // | |
671 | // if isChar is true it means that the value returned will be used for EVT_CHAR | |
672 | // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide, | |
673 | // for example, while if it is false it means that the value is going to be | |
674 | // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to | |
675 | // WXK_NUMPAD_DIVIDE | |
676 | static long wxTranslateKeySymToWXKey(KeySym keysym, bool isChar) | |
677 | { | |
678 | long key_code; | |
679 | ||
680 | switch ( keysym ) | |
681 | { | |
682 | // Shift, Control and Alt don't generate the CHAR events at all | |
683 | case GDK_Shift_L: | |
684 | case GDK_Shift_R: | |
685 | key_code = isChar ? 0 : WXK_SHIFT; | |
686 | break; | |
687 | case GDK_Control_L: | |
688 | case GDK_Control_R: | |
689 | key_code = isChar ? 0 : WXK_CONTROL; | |
690 | break; | |
691 | case GDK_Meta_L: | |
692 | case GDK_Meta_R: | |
693 | case GDK_Alt_L: | |
694 | case GDK_Alt_R: | |
695 | case GDK_Super_L: | |
696 | case GDK_Super_R: | |
697 | key_code = isChar ? 0 : WXK_ALT; | |
698 | break; | |
699 | ||
700 | // neither do the toggle modifies | |
701 | case GDK_Scroll_Lock: | |
702 | key_code = isChar ? 0 : WXK_SCROLL; | |
703 | break; | |
704 | ||
705 | case GDK_Caps_Lock: | |
706 | key_code = isChar ? 0 : WXK_CAPITAL; | |
707 | break; | |
708 | ||
709 | case GDK_Num_Lock: | |
710 | key_code = isChar ? 0 : WXK_NUMLOCK; | |
711 | break; | |
712 | ||
713 | ||
714 | // various other special keys | |
715 | case GDK_Menu: | |
716 | key_code = WXK_MENU; | |
717 | break; | |
718 | ||
719 | case GDK_Help: | |
720 | key_code = WXK_HELP; | |
721 | break; | |
722 | ||
723 | case GDK_BackSpace: | |
724 | key_code = WXK_BACK; | |
725 | break; | |
726 | ||
727 | case GDK_ISO_Left_Tab: | |
728 | case GDK_Tab: | |
729 | key_code = WXK_TAB; | |
730 | break; | |
731 | ||
732 | case GDK_Linefeed: | |
733 | case GDK_Return: | |
734 | key_code = WXK_RETURN; | |
735 | break; | |
736 | ||
737 | case GDK_Clear: | |
738 | key_code = WXK_CLEAR; | |
739 | break; | |
740 | ||
741 | case GDK_Pause: | |
742 | key_code = WXK_PAUSE; | |
743 | break; | |
744 | ||
745 | case GDK_Select: | |
746 | key_code = WXK_SELECT; | |
747 | break; | |
748 | ||
749 | case GDK_Print: | |
750 | key_code = WXK_PRINT; | |
751 | break; | |
752 | ||
753 | case GDK_Execute: | |
754 | key_code = WXK_EXECUTE; | |
755 | break; | |
756 | ||
757 | case GDK_Escape: | |
758 | key_code = WXK_ESCAPE; | |
759 | break; | |
760 | ||
761 | // cursor and other extended keyboard keys | |
762 | case GDK_Delete: | |
763 | key_code = WXK_DELETE; | |
764 | break; | |
765 | ||
766 | case GDK_Home: | |
767 | key_code = WXK_HOME; | |
768 | break; | |
769 | ||
770 | case GDK_Left: | |
771 | key_code = WXK_LEFT; | |
772 | break; | |
773 | ||
774 | case GDK_Up: | |
775 | key_code = WXK_UP; | |
776 | break; | |
777 | ||
778 | case GDK_Right: | |
779 | key_code = WXK_RIGHT; | |
780 | break; | |
781 | ||
782 | case GDK_Down: | |
783 | key_code = WXK_DOWN; | |
784 | break; | |
785 | ||
786 | case GDK_Prior: // == GDK_Page_Up | |
787 | key_code = WXK_PRIOR; | |
788 | break; | |
789 | ||
790 | case GDK_Next: // == GDK_Page_Down | |
791 | key_code = WXK_NEXT; | |
792 | break; | |
793 | ||
794 | case GDK_End: | |
795 | key_code = WXK_END; | |
796 | break; | |
797 | ||
798 | case GDK_Begin: | |
799 | key_code = WXK_HOME; | |
800 | break; | |
801 | ||
802 | case GDK_Insert: | |
803 | key_code = WXK_INSERT; | |
804 | break; | |
805 | ||
806 | ||
807 | // numpad keys | |
808 | case GDK_KP_0: | |
809 | case GDK_KP_1: | |
810 | case GDK_KP_2: | |
811 | case GDK_KP_3: | |
812 | case GDK_KP_4: | |
813 | case GDK_KP_5: | |
814 | case GDK_KP_6: | |
815 | case GDK_KP_7: | |
816 | case GDK_KP_8: | |
817 | case GDK_KP_9: | |
818 | key_code = (isChar ? '0' : WXK_NUMPAD0) + keysym - GDK_KP_0; | |
819 | break; | |
820 | ||
821 | case GDK_KP_Space: | |
822 | key_code = isChar ? ' ' : WXK_NUMPAD_SPACE; | |
823 | break; | |
824 | ||
825 | case GDK_KP_Tab: | |
826 | key_code = isChar ? WXK_TAB : WXK_NUMPAD_TAB; | |
827 | break; | |
828 | ||
829 | case GDK_KP_Enter: | |
830 | key_code = isChar ? WXK_RETURN : WXK_NUMPAD_ENTER; | |
831 | break; | |
832 | ||
833 | case GDK_KP_F1: | |
834 | key_code = isChar ? WXK_F1 : WXK_NUMPAD_F1; | |
835 | break; | |
836 | ||
837 | case GDK_KP_F2: | |
838 | key_code = isChar ? WXK_F2 : WXK_NUMPAD_F2; | |
839 | break; | |
840 | ||
841 | case GDK_KP_F3: | |
842 | key_code = isChar ? WXK_F3 : WXK_NUMPAD_F3; | |
843 | break; | |
844 | ||
845 | case GDK_KP_F4: | |
846 | key_code = isChar ? WXK_F4 : WXK_NUMPAD_F4; | |
847 | break; | |
848 | ||
849 | case GDK_KP_Home: | |
850 | key_code = isChar ? WXK_HOME : WXK_NUMPAD_HOME; | |
851 | break; | |
852 | ||
853 | case GDK_KP_Left: | |
854 | key_code = isChar ? WXK_LEFT : WXK_NUMPAD_LEFT; | |
855 | break; | |
856 | ||
857 | case GDK_KP_Up: | |
858 | key_code = isChar ? WXK_UP : WXK_NUMPAD_UP; | |
859 | break; | |
860 | ||
861 | case GDK_KP_Right: | |
862 | key_code = isChar ? WXK_RIGHT : WXK_NUMPAD_RIGHT; | |
863 | break; | |
864 | ||
865 | case GDK_KP_Down: | |
866 | key_code = isChar ? WXK_DOWN : WXK_NUMPAD_DOWN; | |
867 | break; | |
868 | ||
869 | case GDK_KP_Prior: // == GDK_KP_Page_Up | |
870 | key_code = isChar ? WXK_PRIOR : WXK_NUMPAD_PRIOR; | |
871 | break; | |
872 | ||
873 | case GDK_KP_Next: // == GDK_KP_Page_Down | |
874 | key_code = isChar ? WXK_NEXT : WXK_NUMPAD_NEXT; | |
875 | break; | |
876 | ||
877 | case GDK_KP_End: | |
878 | key_code = isChar ? WXK_END : WXK_NUMPAD_END; | |
879 | break; | |
880 | ||
881 | case GDK_KP_Begin: | |
882 | key_code = isChar ? WXK_HOME : WXK_NUMPAD_BEGIN; | |
883 | break; | |
884 | ||
885 | case GDK_KP_Insert: | |
886 | key_code = isChar ? WXK_INSERT : WXK_NUMPAD_INSERT; | |
887 | break; | |
888 | ||
889 | case GDK_KP_Delete: | |
890 | key_code = isChar ? WXK_DELETE : WXK_NUMPAD_DELETE; | |
891 | break; | |
892 | ||
893 | case GDK_KP_Equal: | |
894 | key_code = isChar ? '=' : WXK_NUMPAD_EQUAL; | |
895 | break; | |
896 | ||
897 | case GDK_KP_Multiply: | |
898 | key_code = isChar ? '*' : WXK_NUMPAD_MULTIPLY; | |
899 | break; | |
900 | ||
901 | case GDK_KP_Add: | |
902 | key_code = isChar ? '+' : WXK_NUMPAD_ADD; | |
903 | break; | |
904 | ||
905 | case GDK_KP_Separator: | |
906 | // FIXME: what is this? | |
907 | key_code = isChar ? '.' : WXK_NUMPAD_SEPARATOR; | |
908 | break; | |
909 | ||
910 | case GDK_KP_Subtract: | |
911 | key_code = isChar ? '-' : WXK_NUMPAD_SUBTRACT; | |
912 | break; | |
913 | ||
914 | case GDK_KP_Decimal: | |
915 | key_code = isChar ? '.' : WXK_NUMPAD_DECIMAL; | |
916 | break; | |
917 | ||
918 | case GDK_KP_Divide: | |
919 | key_code = isChar ? '/' : WXK_NUMPAD_DIVIDE; | |
920 | break; | |
921 | ||
922 | ||
923 | // function keys | |
924 | case GDK_F1: | |
925 | case GDK_F2: | |
926 | case GDK_F3: | |
927 | case GDK_F4: | |
928 | case GDK_F5: | |
929 | case GDK_F6: | |
930 | case GDK_F7: | |
931 | case GDK_F8: | |
932 | case GDK_F9: | |
933 | case GDK_F10: | |
934 | case GDK_F11: | |
935 | case GDK_F12: | |
936 | key_code = WXK_F1 + keysym - GDK_F1; | |
937 | break; | |
938 | ||
939 | default: | |
940 | key_code = 0; | |
941 | } | |
942 | ||
943 | return key_code; | |
944 | } | |
945 | ||
946 | static inline bool wxIsAsciiKeysym(KeySym ks) | |
947 | { | |
948 | return ks < 256; | |
949 | } | |
950 | ||
74710601 VZ |
951 | static bool |
952 | wxTranslateGTKKeyEventToWx(wxKeyEvent& event, | |
953 | wxWindowGTK *win, | |
954 | GdkEventKey *gdk_event) | |
47d67540 | 955 | { |
1c6896d7 VZ |
956 | // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string |
957 | // but only event->keyval which is quite useless to us, so remember | |
958 | // the last character from GDK_KEY_PRESS and reuse it as last resort | |
959 | // | |
960 | // NB: should be MT-safe as we're always called from the main thread only | |
961 | static struct | |
962 | { | |
963 | KeySym keysym; | |
964 | long keycode; | |
965 | } s_lastKeyPress = { 0, 0 }; | |
966 | ||
967 | KeySym keysym = gdk_event->keyval; | |
0a62b197 | 968 | |
ada7d2c0 | 969 | wxLogTrace(TRACE_KEYS, _T("Key %s event: keysym = %ld"), |
0a62b197 VZ |
970 | event.GetEventType() == wxEVT_KEY_UP ? _T("release") |
971 | : _T("press"), | |
972 | keysym); | |
973 | ||
1c6896d7 VZ |
974 | long key_code = wxTranslateKeySymToWXKey(keysym, FALSE /* !isChar */); |
975 | ||
976 | if ( !key_code ) | |
977 | { | |
978 | // do we have the translation or is it a plain ASCII character? | |
979 | if ( (gdk_event->length == 1) || wxIsAsciiKeysym(keysym) ) | |
980 | { | |
981 | // we should use keysym if it is ASCII as X does some translations | |
982 | // like "I pressed while Control is down" => "Ctrl-I" == "TAB" | |
983 | // which we don't want here (but which we do use for OnChar()) | |
984 | if ( !wxIsAsciiKeysym(keysym) ) | |
985 | { | |
986 | keysym = (KeySym)gdk_event->string[0]; | |
987 | } | |
a2053b27 | 988 | |
1c6896d7 VZ |
989 | // we want to always get the same key code when the same key is |
990 | // pressed regardless of the state of the modifies, i.e. on a | |
991 | // standard US keyboard pressing '5' or '%' ('5' key with | |
992 | // Shift) should result in the same key code in OnKeyDown(): | |
993 | // '5' (although OnChar() will get either '5' or '%'). | |
994 | // | |
995 | // to do it we first translate keysym to keycode (== scan code) | |
996 | // and then back but always using the lower register | |
997 | Display *dpy = (Display *)wxGetDisplay(); | |
998 | KeyCode keycode = XKeysymToKeycode(dpy, keysym); | |
0a62b197 VZ |
999 | |
1000 | wxLogTrace(TRACE_KEYS, _T("\t-> keycode %d"), keycode); | |
1001 | ||
1c6896d7 VZ |
1002 | KeySym keysymNormalized = XKeycodeToKeysym(dpy, keycode, 0); |
1003 | ||
1004 | // use the normalized, i.e. lower register, keysym if we've | |
1005 | // got one | |
1006 | key_code = keysymNormalized ? keysymNormalized : keysym; | |
1007 | ||
1008 | // as explained above, we want to have lower register key codes | |
1009 | // normally but for the letter keys we want to have the upper ones | |
1010 | // | |
1011 | // NB: don't use XConvertCase() here, we want to do it for letters | |
1012 | // only | |
1013 | key_code = toupper(key_code); | |
1014 | } | |
1015 | else // non ASCII key, what to do? | |
1016 | { | |
1017 | // by default, ignore it | |
1018 | key_code = 0; | |
1019 | ||
1020 | // but if we have cached information from the last KEY_PRESS | |
1021 | if ( gdk_event->type == GDK_KEY_RELEASE ) | |
1022 | { | |
1023 | // then reuse it | |
1024 | if ( keysym == s_lastKeyPress.keysym ) | |
1025 | { | |
1026 | key_code = s_lastKeyPress.keycode; | |
1027 | } | |
1028 | } | |
1029 | } | |
1030 | ||
1031 | if ( gdk_event->type == GDK_KEY_PRESS ) | |
1032 | { | |
1033 | // remember it to be reused for KEY_UP event later | |
1034 | s_lastKeyPress.keysym = keysym; | |
1035 | s_lastKeyPress.keycode = key_code; | |
1036 | } | |
1037 | } | |
1038 | ||
ada7d2c0 | 1039 | wxLogTrace(TRACE_KEYS, _T("\t-> wxKeyCode %ld"), key_code); |
c801d85f | 1040 | |
74710601 | 1041 | // sending unknown key events doesn't really make sense |
1c6896d7 | 1042 | if ( !key_code ) |
74710601 | 1043 | return FALSE; |
3d6f7261 | 1044 | |
1c6896d7 | 1045 | // now fill all the other fields |
b0e813a0 RR |
1046 | int x = 0; |
1047 | int y = 0; | |
1048 | GdkModifierType state; | |
f17393f1 VZ |
1049 | if (gdk_event->window) |
1050 | gdk_window_get_pointer(gdk_event->window, &x, &y, &state); | |
47d67540 | 1051 | |
d1367c3d | 1052 | event.SetTimestamp( gdk_event->time ); |
74710601 VZ |
1053 | event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK) != 0; |
1054 | event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK) != 0; | |
1055 | event.m_altDown = (gdk_event->state & GDK_MOD1_MASK) != 0; | |
1056 | event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK) != 0; | |
f5e27805 | 1057 | event.m_keyCode = key_code; |
b0e813a0 | 1058 | event.m_scanCode = gdk_event->keyval; |
9c7df356 VZ |
1059 | event.m_rawCode = (wxUint32) gdk_event->keyval; |
1060 | event.m_rawFlags = 0; | |
b0e813a0 RR |
1061 | event.m_x = x; |
1062 | event.m_y = y; | |
f5e27805 | 1063 | event.SetEventObject( win ); |
74710601 VZ |
1064 | |
1065 | return TRUE; | |
1066 | } | |
1067 | ||
7c5e6fc6 | 1068 | |
74710601 VZ |
1069 | static gint gtk_window_key_press_callback( GtkWidget *widget, |
1070 | GdkEventKey *gdk_event, | |
1071 | wxWindow *win ) | |
1072 | { | |
1073 | DEBUG_MAIN_THREAD | |
1074 | ||
1075 | if (g_isIdle) | |
1076 | wxapp_install_idle_handler(); | |
1077 | ||
1c6896d7 VZ |
1078 | if (!win->m_hasVMT) |
1079 | return FALSE; | |
1080 | if (g_blockEventsOnDrag) | |
1081 | return FALSE; | |
74710601 | 1082 | |
1ec3a984 RR |
1083 | |
1084 | wxKeyEvent event( wxEVT_KEY_DOWN ); | |
74710601 VZ |
1085 | if ( !wxTranslateGTKKeyEventToWx(event, win, gdk_event) ) |
1086 | { | |
1c6896d7 | 1087 | // unknown key pressed, ignore (the event would be useless anyhow) |
74710601 VZ |
1088 | return FALSE; |
1089 | } | |
1090 | ||
1ec3a984 RR |
1091 | // Emit KEY_DOWN event |
1092 | bool ret = win->GetEventHandler()->ProcessEvent( event ); | |
c50f1fb9 | 1093 | |
88ac883a | 1094 | #if wxUSE_ACCEL |
f5e27805 | 1095 | if (!ret) |
47d67540 | 1096 | { |
1e6feb95 | 1097 | wxWindowGTK *ancestor = win; |
f5e27805 RR |
1098 | while (ancestor) |
1099 | { | |
1100 | int command = ancestor->GetAcceleratorTable()->GetCommand( event ); | |
1101 | if (command != -1) | |
1102 | { | |
1103 | wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); | |
1104 | ret = ancestor->GetEventHandler()->ProcessEvent( command_event ); | |
1105 | break; | |
1106 | } | |
f6bcfd97 | 1107 | if (ancestor->IsTopLevel()) |
b02da6b1 | 1108 | break; |
f5e27805 RR |
1109 | ancestor = ancestor->GetParent(); |
1110 | } | |
bcf1fa6b | 1111 | } |
88ac883a | 1112 | #endif // wxUSE_ACCEL |
3017f78d | 1113 | |
1ec3a984 RR |
1114 | // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x |
1115 | // will only be sent if it is not in an accelerator table. | |
2dde25b9 | 1116 | if (!ret) |
d728dd40 | 1117 | { |
7c5e6fc6 | 1118 | long key_code; |
1c6896d7 | 1119 | KeySym keysym = gdk_event->keyval; |
7c5e6fc6 RD |
1120 | #ifdef __WXGTK20__ |
1121 | // In GTK 2.0, we need to hand over the key event to an input method | |
1122 | // and the IM will emit a "commit" event containing the actual utf8 | |
1123 | // character. In that case the EVT_CHAR events will be sent from | |
1124 | // there. But only do it this way for non-KeySym keys. | |
1125 | key_code = wxTranslateKeySymToWXKey(gdk_event->keyval, FALSE /* isChar */); | |
1126 | if ( !key_code && win->m_imContext ) | |
1c6896d7 | 1127 | { |
7c5e6fc6 RD |
1128 | gtk_im_context_filter_keypress ( (GtkIMContext*) win->m_imContext, gdk_event ); |
1129 | ret = TRUE; | |
1c6896d7 | 1130 | } |
7c5e6fc6 RD |
1131 | else |
1132 | #endif | |
f17393f1 | 1133 | { |
7c5e6fc6 RD |
1134 | // Find key code for EVT_CHAR and EVT_CHAR_HOOK events |
1135 | key_code = wxTranslateKeySymToWXKey(keysym, TRUE /* isChar */); | |
1136 | if ( !key_code ) | |
1ec3a984 | 1137 | { |
7c5e6fc6 RD |
1138 | if ( gdk_event->length == 1 ) |
1139 | { | |
1140 | key_code = (unsigned char)gdk_event->string[0]; | |
1141 | } | |
1142 | else if ( wxIsAsciiKeysym(keysym) ) | |
1143 | { | |
1144 | // ASCII key | |
1145 | key_code = (unsigned char)keysym; | |
1146 | } | |
1ec3a984 | 1147 | } |
f17393f1 | 1148 | |
7c5e6fc6 | 1149 | if ( key_code ) |
1ec3a984 | 1150 | { |
7c5e6fc6 RD |
1151 | wxLogTrace(TRACE_KEYS, _T("Char event: %ld"), key_code); |
1152 | ||
1153 | event.m_keyCode = key_code; | |
1154 | ||
1155 | // Implement OnCharHook by checking ancesteror top level windows | |
1156 | wxWindow *parent = win; | |
1157 | while (parent && !parent->IsTopLevel()) | |
1158 | parent = parent->GetParent(); | |
1159 | if (parent) | |
1160 | { | |
1161 | event.SetEventType( wxEVT_CHAR_HOOK ); | |
1162 | ret = parent->GetEventHandler()->ProcessEvent( event ); | |
1163 | } | |
1164 | ||
1165 | if (!ret) | |
1166 | { | |
1167 | event.SetEventType(wxEVT_CHAR); | |
1168 | ret = win->GetEventHandler()->ProcessEvent( event ); | |
1169 | } | |
1ec3a984 | 1170 | } |
f17393f1 | 1171 | } |
d728dd40 KB |
1172 | } |
1173 | ||
1ec3a984 | 1174 | // win is a control: tab can be propagated up |
f17393f1 | 1175 | if ( !ret && |
5664fc32 | 1176 | ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab)) && |
f6bcfd97 BP |
1177 | // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may |
1178 | // have this style, yet choose not to process this particular TAB in which | |
1179 | // case TAB must still work as a navigational character | |
1180 | #if 0 | |
f17393f1 | 1181 | !win->HasFlag(wxTE_PROCESS_TAB) && |
f6bcfd97 | 1182 | #endif // 0 |
f17393f1 | 1183 | win->GetParent() && (win->GetParent()->HasFlag( wxTAB_TRAVERSAL)) ) |
b292e2f5 RR |
1184 | { |
1185 | wxNavigationKeyEvent new_event; | |
8253c7fd | 1186 | new_event.SetEventObject( win->GetParent() ); |
1ec3a984 | 1187 | // GDK reports GDK_ISO_Left_Tab for SHIFT-TAB |
5664fc32 | 1188 | new_event.SetDirection( (gdk_event->keyval == GDK_Tab) ); |
1ec3a984 | 1189 | // CTRL-TAB changes the (parent) window, i.e. switch notebook page |
b98d804b | 1190 | new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) ); |
b292e2f5 | 1191 | new_event.SetCurrentFocus( win ); |
8253c7fd | 1192 | ret = win->GetParent()->GetEventHandler()->ProcessEvent( new_event ); |
b292e2f5 | 1193 | } |
ff8bfdbb | 1194 | |
1ec3a984 | 1195 | // generate wxID_CANCEL if <esc> has been pressed (typically in dialogs) |
f17393f1 | 1196 | if ( !ret && |
b98d804b RR |
1197 | (gdk_event->keyval == GDK_Escape) ) |
1198 | { | |
6ce16bdb VZ |
1199 | // however only do it if we have a Cancel button in the dialog, |
1200 | // otherwise the user code may get confused by the events from a | |
1201 | // non-existing button and, worse, a wxButton might get button event | |
1202 | // from another button which is not really expected | |
1203 | wxWindow *winForCancel = win, | |
1204 | *btnCancel = NULL; | |
1205 | while ( winForCancel ) | |
1206 | { | |
1207 | btnCancel = winForCancel->FindWindow(wxID_CANCEL); | |
1208 | if ( btnCancel ) | |
1209 | { | |
1210 | // found a cancel button | |
1211 | break; | |
1212 | } | |
1213 | ||
1214 | if ( winForCancel->IsTopLevel() ) | |
1215 | { | |
1216 | // no need to look further | |
1217 | break; | |
1218 | } | |
1219 | ||
1220 | // maybe our parent has a cancel button? | |
1221 | winForCancel = winForCancel->GetParent(); | |
1222 | } | |
1223 | ||
1224 | if ( btnCancel ) | |
1225 | { | |
1226 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); | |
1227 | event.SetEventObject(btnCancel); | |
1228 | ret = btnCancel->GetEventHandler()->ProcessEvent(event); | |
1229 | } | |
b98d804b | 1230 | } |
c50f1fb9 | 1231 | |
2b5f62a0 | 1232 | if (ret) |
801aa178 | 1233 | { |
2b5f62a0 VZ |
1234 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); |
1235 | return TRUE; | |
1236 | } | |
1237 | ||
1238 | return FALSE; | |
1239 | } | |
2b5f62a0 VZ |
1240 | |
1241 | #ifdef __WXGTK20__ | |
2b5f62a0 VZ |
1242 | static void gtk_wxwindow_commit_cb (GtkIMContext *context, |
1243 | const gchar *str, | |
1244 | wxWindow *window) | |
1245 | { | |
1246 | bool ret = FALSE; | |
1247 | ||
1248 | wxKeyEvent event( wxEVT_KEY_DOWN ); | |
1249 | ||
1250 | #if wxUSE_UNICODE | |
1251 | event.m_uniChar = g_utf8_get_char( str ); | |
1252 | ||
1253 | // Backward compatible for ISO-8859 | |
1254 | if (event.m_uniChar < 256) | |
1255 | event.m_keyCode = event.m_uniChar; | |
1256 | #else | |
1257 | gunichar uniChar = g_utf8_get_char( str ); | |
1258 | // We cannot handle Unicode in non-Unicode mode | |
1259 | if (uniChar > 255) return; | |
1260 | ||
1261 | event.m_keyCode = uniChar; | |
1262 | #endif | |
1263 | ||
7c5e6fc6 RD |
1264 | |
1265 | // TODO: We still need to set all the extra attributes of the | |
1266 | // event, modifiers and such... | |
1267 | ||
1268 | ||
1269 | // Implement OnCharHook by checking ancestor top level windows | |
1270 | wxWindow *parent = window; | |
1271 | while (parent && !parent->IsTopLevel()) | |
2b5f62a0 | 1272 | parent = parent->GetParent(); |
7c5e6fc6 RD |
1273 | if (parent) |
1274 | { | |
1275 | event.SetEventType( wxEVT_CHAR_HOOK ); | |
1276 | ret = parent->GetEventHandler()->ProcessEvent( event ); | |
1277 | } | |
2b5f62a0 | 1278 | |
7c5e6fc6 RD |
1279 | if (!ret) |
1280 | { | |
1281 | event.SetEventType(wxEVT_CHAR); | |
1282 | ret = window->GetEventHandler()->ProcessEvent( event ); | |
2b5f62a0 VZ |
1283 | } |
1284 | } | |
1285 | #endif | |
1286 | ||
1287 | ||
b666df2c RR |
1288 | //----------------------------------------------------------------------------- |
1289 | // "key_release_event" from any window | |
1290 | //----------------------------------------------------------------------------- | |
1291 | ||
74710601 VZ |
1292 | static gint gtk_window_key_release_callback( GtkWidget *widget, |
1293 | GdkEventKey *gdk_event, | |
1294 | wxWindowGTK *win ) | |
b666df2c | 1295 | { |
3ac8d3bc RR |
1296 | DEBUG_MAIN_THREAD |
1297 | ||
c50f1fb9 | 1298 | if (g_isIdle) |
a2053b27 RR |
1299 | wxapp_install_idle_handler(); |
1300 | ||
74710601 VZ |
1301 | if (!win->m_hasVMT) |
1302 | return FALSE; | |
b666df2c | 1303 | |
74710601 VZ |
1304 | if (g_blockEventsOnDrag) |
1305 | return FALSE; | |
b666df2c RR |
1306 | |
1307 | wxKeyEvent event( wxEVT_KEY_UP ); | |
74710601 | 1308 | if ( !wxTranslateGTKKeyEventToWx(event, win, gdk_event) ) |
b666df2c | 1309 | { |
74710601 VZ |
1310 | // unknown key pressed, ignore (the event would be useless anyhow |
1311 | return FALSE; | |
b666df2c RR |
1312 | } |
1313 | ||
74710601 VZ |
1314 | if ( !win->GetEventHandler()->ProcessEvent( event ) ) |
1315 | return FALSE; | |
1316 | ||
1317 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_release_event" ); | |
1318 | return TRUE; | |
b666df2c RR |
1319 | } |
1320 | ||
c5f9d156 VS |
1321 | // ============================================================================ |
1322 | // the mouse events | |
1323 | // ============================================================================ | |
1324 | ||
d1f2ac45 VZ |
1325 | // ---------------------------------------------------------------------------- |
1326 | // mouse event processing helpers | |
1327 | // ---------------------------------------------------------------------------- | |
1328 | ||
c5f9d156 | 1329 | // init wxMouseEvent with the info from gdk_event |
edc1d330 VZ |
1330 | // |
1331 | // NB: this has to be a macro as gdk_event type is different for different | |
1332 | // events we're used with | |
1333 | #define InitMouseEvent(/* wxWindowGTK * */ win, \ | |
1334 | /* wxMouseEvent& */ event, \ | |
1335 | /* GdkEventXXX * */ gdk_event) \ | |
1336 | { \ | |
1337 | event.SetTimestamp( gdk_event->time ); \ | |
1338 | event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); \ | |
1339 | event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); \ | |
1340 | event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); \ | |
1341 | event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); \ | |
1342 | event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); \ | |
1343 | event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); \ | |
1344 | event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); \ | |
2b5f62a0 VZ |
1345 | if (event.GetEventType()==wxEVT_MOUSEWHEEL) \ |
1346 | { \ | |
1347 | if (((GdkEventButton*)gdk_event)->button == 4) \ | |
1348 | event.m_wheelRotation = 120; \ | |
1349 | else if (((GdkEventButton*)gdk_event)->button == 5) \ | |
1350 | event.m_wheelRotation = -120; \ | |
1351 | } \ | |
edc1d330 VZ |
1352 | \ |
1353 | wxPoint pt = win->GetClientAreaOrigin(); \ | |
1354 | event.m_x = (wxCoord)gdk_event->x - pt.x; \ | |
1355 | event.m_y = (wxCoord)gdk_event->y - pt.y; \ | |
1356 | \ | |
1357 | event.SetEventObject( win ); \ | |
1358 | event.SetId( win->GetId() ); \ | |
1359 | event.SetTimestamp( gdk_event->time ); \ | |
1360 | } \ | |
c5f9d156 | 1361 | |
2daa0ce9 VZ |
1362 | static void AdjustEventButtonState(wxMouseEvent& event) |
1363 | { | |
1364 | // GDK reports the old state of the button for a button press event, but | |
1365 | // for compatibility with MSW and common sense we want m_leftDown be TRUE | |
1366 | // for a LEFT_DOWN event, not FALSE, so we will invert | |
1367 | // left/right/middleDown for the corresponding click events | |
1e6feb95 | 1368 | |
1a8caf94 RR |
1369 | if ((event.GetEventType() == wxEVT_LEFT_DOWN) || |
1370 | (event.GetEventType() == wxEVT_LEFT_DCLICK) || | |
1371 | (event.GetEventType() == wxEVT_LEFT_UP)) | |
1372 | { | |
1373 | event.m_leftDown = !event.m_leftDown; | |
1374 | return; | |
1375 | } | |
1376 | ||
1377 | if ((event.GetEventType() == wxEVT_MIDDLE_DOWN) || | |
1378 | (event.GetEventType() == wxEVT_MIDDLE_DCLICK) || | |
1379 | (event.GetEventType() == wxEVT_MIDDLE_UP)) | |
2daa0ce9 | 1380 | { |
1a8caf94 RR |
1381 | event.m_middleDown = !event.m_middleDown; |
1382 | return; | |
1383 | } | |
1384 | ||
1385 | if ((event.GetEventType() == wxEVT_RIGHT_DOWN) || | |
1386 | (event.GetEventType() == wxEVT_RIGHT_DCLICK) || | |
1387 | (event.GetEventType() == wxEVT_RIGHT_UP)) | |
1388 | { | |
1389 | event.m_rightDown = !event.m_rightDown; | |
1390 | return; | |
2daa0ce9 VZ |
1391 | } |
1392 | } | |
1393 | ||
d1f2ac45 VZ |
1394 | // find the window to send the mouse event too |
1395 | static | |
1396 | wxWindowGTK *FindWindowForMouseEvent(wxWindowGTK *win, wxCoord& x, wxCoord& y) | |
1397 | { | |
7d4909b2 RR |
1398 | wxCoord xx = x; |
1399 | wxCoord yy = y; | |
1400 | ||
d1f2ac45 VZ |
1401 | if (win->m_wxwindow) |
1402 | { | |
1403 | GtkPizza *pizza = GTK_PIZZA(win->m_wxwindow); | |
7d4909b2 RR |
1404 | xx += pizza->xoffset; |
1405 | yy += pizza->yoffset; | |
d1f2ac45 VZ |
1406 | } |
1407 | ||
b1d4dd7a | 1408 | wxWindowList::Node *node = win->GetChildren().GetFirst(); |
d1f2ac45 VZ |
1409 | while (node) |
1410 | { | |
b1d4dd7a | 1411 | wxWindowGTK *child = node->GetData(); |
d1f2ac45 | 1412 | |
b1d4dd7a | 1413 | node = node->GetNext(); |
d1f2ac45 VZ |
1414 | if (!child->IsShown()) |
1415 | continue; | |
1416 | ||
1417 | if (child->IsTransparentForMouse()) | |
1418 | { | |
1419 | // wxStaticBox is transparent in the box itself | |
1420 | int xx1 = child->m_x; | |
1421 | int yy1 = child->m_y; | |
1422 | int xx2 = child->m_x + child->m_width; | |
1423 | int yy2 = child->m_x + child->m_height; | |
1424 | ||
1425 | // left | |
7d4909b2 | 1426 | if (((xx >= xx1) && (xx <= xx1+10) && (yy >= yy1) && (yy <= yy2)) || |
d1f2ac45 | 1427 | // right |
7d4909b2 | 1428 | ((xx >= xx2-10) && (xx <= xx2) && (yy >= yy1) && (yy <= yy2)) || |
d1f2ac45 | 1429 | // top |
7d4909b2 | 1430 | ((xx >= xx1) && (xx <= xx2) && (yy >= yy1) && (yy <= yy1+10)) || |
d1f2ac45 | 1431 | // bottom |
7d4909b2 | 1432 | ((xx >= xx1) && (xx <= xx2) && (yy >= yy2-1) && (yy <= yy2))) |
d1f2ac45 VZ |
1433 | { |
1434 | win = child; | |
1435 | x -= child->m_x; | |
1436 | y -= child->m_y; | |
1437 | break; | |
1438 | } | |
1439 | ||
1440 | } | |
1441 | else | |
1442 | { | |
1443 | if ((child->m_wxwindow == (GtkWidget*) NULL) && | |
7d4909b2 RR |
1444 | (child->m_x <= xx) && |
1445 | (child->m_y <= yy) && | |
af3653dd RR |
1446 | (child->m_x+child->m_width >= xx) && |
1447 | (child->m_y+child->m_height >= yy)) | |
d1f2ac45 VZ |
1448 | { |
1449 | win = child; | |
1450 | x -= child->m_x; | |
1451 | y -= child->m_y; | |
1452 | break; | |
1453 | } | |
1454 | } | |
1455 | } | |
1456 | ||
1457 | return win; | |
1458 | } | |
1459 | ||
c801d85f | 1460 | //----------------------------------------------------------------------------- |
2f2aa628 RR |
1461 | // "button_press_event" |
1462 | //----------------------------------------------------------------------------- | |
c801d85f | 1463 | |
d1f2ac45 VZ |
1464 | static gint gtk_window_button_press_callback( GtkWidget *widget, |
1465 | GdkEventButton *gdk_event, | |
1466 | wxWindowGTK *win ) | |
903f689b | 1467 | { |
3ac8d3bc RR |
1468 | DEBUG_MAIN_THREAD |
1469 | ||
c50f1fb9 | 1470 | if (g_isIdle) |
a2053b27 RR |
1471 | wxapp_install_idle_handler(); |
1472 | ||
1473 | /* | |
223d09f6 | 1474 | wxPrintf( wxT("1) OnButtonPress from ") ); |
a2053b27 RR |
1475 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) |
1476 | wxPrintf( win->GetClassInfo()->GetClassName() ); | |
223d09f6 | 1477 | wxPrintf( wxT(".\n") ); |
a2053b27 | 1478 | */ |
a2053b27 | 1479 | if (!win->m_hasVMT) return FALSE; |
f5e27805 | 1480 | if (g_blockEventsOnDrag) return TRUE; |
76ed8f8d | 1481 | if (g_blockEventsOnScroll) return TRUE; |
c801d85f | 1482 | |
034be888 RR |
1483 | if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; |
1484 | ||
afbe906a | 1485 | if (win->m_wxwindow && (g_focusWindow != win) && win->AcceptsFocus()) |
c801d85f | 1486 | { |
afbe906a | 1487 | gtk_widget_grab_focus( win->m_wxwindow ); |
c801d85f | 1488 | /* |
afbe906a RR |
1489 | wxPrintf( wxT("GrabFocus from ") ); |
1490 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
1491 | wxPrintf( win->GetClassInfo()->GetClassName() ); | |
1492 | wxPrintf( wxT(".\n") ); | |
c801d85f | 1493 | */ |
362c6693 | 1494 | } |
47d67540 | 1495 | |
2b5f62a0 VZ |
1496 | // GDK sends surplus button down event |
1497 | // before a double click event. We | |
1498 | // need to filter these out. | |
1499 | if (gdk_event->type == GDK_BUTTON_PRESS) | |
1500 | { | |
1501 | GdkEvent *peek_event = gdk_event_peek(); | |
1502 | if (peek_event) | |
1503 | { | |
1504 | if (peek_event->type == GDK_2BUTTON_PRESS) | |
1505 | { | |
1506 | gdk_event_free( peek_event ); | |
1507 | return TRUE; | |
1508 | } | |
1509 | else | |
1510 | { | |
1511 | gdk_event_free( peek_event ); | |
1512 | } | |
1513 | } | |
1514 | } | |
1515 | ||
2daa0ce9 | 1516 | wxEventType event_type = wxEVT_NULL; |
47d67540 | 1517 | |
f5e27805 | 1518 | if (gdk_event->button == 1) |
c801d85f | 1519 | { |
f5e27805 RR |
1520 | switch (gdk_event->type) |
1521 | { | |
1522 | case GDK_BUTTON_PRESS: event_type = wxEVT_LEFT_DOWN; break; | |
1523 | case GDK_2BUTTON_PRESS: event_type = wxEVT_LEFT_DCLICK; break; | |
1524 | default: break; | |
1525 | } | |
362c6693 | 1526 | } |
f5e27805 | 1527 | else if (gdk_event->button == 2) |
c801d85f | 1528 | { |
f5e27805 RR |
1529 | switch (gdk_event->type) |
1530 | { | |
1531 | case GDK_BUTTON_PRESS: event_type = wxEVT_MIDDLE_DOWN; break; | |
1532 | case GDK_2BUTTON_PRESS: event_type = wxEVT_MIDDLE_DCLICK; break; | |
1533 | default: break; | |
1534 | } | |
362c6693 | 1535 | } |
f5e27805 | 1536 | else if (gdk_event->button == 3) |
c801d85f | 1537 | { |
f5e27805 RR |
1538 | switch (gdk_event->type) |
1539 | { | |
1540 | case GDK_BUTTON_PRESS: event_type = wxEVT_RIGHT_DOWN; break; | |
1541 | case GDK_2BUTTON_PRESS: event_type = wxEVT_RIGHT_DCLICK; break; | |
1542 | default: break; | |
1543 | } | |
362c6693 | 1544 | } |
2b5f62a0 VZ |
1545 | else if (gdk_event->button == 4) |
1546 | { | |
1547 | switch (gdk_event->type) | |
1548 | { | |
1549 | case GDK_BUTTON_PRESS: event_type = wxEVT_MOUSEWHEEL; break; | |
1550 | default: break; | |
1551 | } | |
1552 | } | |
1553 | else if (gdk_event->button == 5) | |
1554 | { | |
1555 | switch (gdk_event->type) | |
1556 | { | |
1557 | case GDK_BUTTON_PRESS: event_type = wxEVT_MOUSEWHEEL; break; | |
1558 | default: break; | |
1559 | } | |
1560 | } | |
47d67540 | 1561 | |
2daa0ce9 VZ |
1562 | if ( event_type == wxEVT_NULL ) |
1563 | { | |
1564 | // unknown mouse button or click type | |
1565 | return FALSE; | |
1566 | } | |
1567 | ||
f5e27805 | 1568 | wxMouseEvent event( event_type ); |
c5f9d156 | 1569 | InitMouseEvent( win, event, gdk_event ); |
47d67540 | 1570 | |
2daa0ce9 | 1571 | AdjustEventButtonState(event); |
94633ad9 | 1572 | |
3ae4c570 VZ |
1573 | // wxListBox actually get mouse events from the item, so we need to give it |
1574 | // a chance to correct this | |
1575 | win->FixUpMouseEvent(widget, event.m_x, event.m_y); | |
2daa0ce9 | 1576 | |
d1f2ac45 VZ |
1577 | // find the correct window to send the event too: it may be a different one |
1578 | // from the one which got it at GTK+ level because some control don't have | |
1579 | // their own X window and thus cannot get any events. | |
1580 | if ( !g_captureWindow ) | |
1581 | win = FindWindowForMouseEvent(win, event.m_x, event.m_y); | |
ff8bfdbb | 1582 | |
f5e27805 | 1583 | gs_timeLastClick = gdk_event->time; |
47d67540 | 1584 | |
2f073eb2 RR |
1585 | /* |
1586 | wxPrintf( wxT("2) OnButtonPress from ") ); | |
1587 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
1588 | wxPrintf( win->GetClassInfo()->GetClassName() ); | |
1589 | wxPrintf( wxT(".\n") ); | |
1590 | */ | |
1591 | ||
df135f2b RR |
1592 | #ifndef __WXGTK20__ |
1593 | if (event_type == wxEVT_LEFT_DCLICK) | |
1594 | { | |
1595 | // GTK 1.2 crashes when intercepting double | |
1596 | // click events from both wxSpinButton and | |
1597 | // wxSpinCtrl | |
1598 | if (GTK_IS_SPIN_BUTTON(win->m_widget)) | |
1599 | { | |
1600 | // Just disable this event for now. | |
1601 | return FALSE; | |
1602 | } | |
1603 | } | |
1604 | #endif | |
1605 | ||
f5e27805 | 1606 | if (win->GetEventHandler()->ProcessEvent( event )) |
034be888 | 1607 | { |
f5e27805 | 1608 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_press_event" ); |
f03fc89f | 1609 | return TRUE; |
034be888 | 1610 | } |
47d67540 | 1611 | |
034be888 | 1612 | return FALSE; |
362c6693 | 1613 | } |
c801d85f KB |
1614 | |
1615 | //----------------------------------------------------------------------------- | |
97b3455a | 1616 | // "button_release_event" |
2f2aa628 | 1617 | //----------------------------------------------------------------------------- |
c801d85f | 1618 | |
2b5f62a0 VZ |
1619 | static gint gtk_window_button_release_callback( GtkWidget *widget, |
1620 | GdkEventButton *gdk_event, | |
1621 | wxWindowGTK *win ) | |
47d67540 | 1622 | { |
3ac8d3bc RR |
1623 | DEBUG_MAIN_THREAD |
1624 | ||
c50f1fb9 | 1625 | if (g_isIdle) |
a2053b27 RR |
1626 | wxapp_install_idle_handler(); |
1627 | ||
1628 | if (!win->m_hasVMT) return FALSE; | |
034be888 RR |
1629 | if (g_blockEventsOnDrag) return FALSE; |
1630 | if (g_blockEventsOnScroll) return FALSE; | |
c801d85f | 1631 | |
034be888 | 1632 | if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; |
47d67540 | 1633 | |
f5e27805 | 1634 | wxEventType event_type = wxEVT_NULL; |
47d67540 | 1635 | |
f5e27805 RR |
1636 | switch (gdk_event->button) |
1637 | { | |
2b5f62a0 VZ |
1638 | case 1: |
1639 | event_type = wxEVT_LEFT_UP; | |
1640 | break; | |
1641 | ||
1642 | case 2: | |
1643 | event_type = wxEVT_MIDDLE_UP; | |
1644 | break; | |
1645 | ||
1646 | case 3: | |
1647 | event_type = wxEVT_RIGHT_UP; | |
1648 | break; | |
1649 | ||
1650 | default: | |
1651 | // unknwon button, don't process | |
1652 | return FALSE; | |
f5e27805 | 1653 | } |
47d67540 | 1654 | |
f5e27805 | 1655 | wxMouseEvent event( event_type ); |
c5f9d156 | 1656 | InitMouseEvent( win, event, gdk_event ); |
f5e27805 | 1657 | |
2daa0ce9 VZ |
1658 | AdjustEventButtonState(event); |
1659 | ||
3ae4c570 VZ |
1660 | // same wxListBox hack as above |
1661 | win->FixUpMouseEvent(widget, event.m_x, event.m_y); | |
e2762ff0 | 1662 | |
2b5f62a0 VZ |
1663 | if ( event_type == wxEVT_RIGHT_UP ) |
1664 | { | |
1665 | // generate a "context menu" event: this is similar to wxEVT_RIGHT_UP | |
1666 | // except that: | |
1667 | // | |
1668 | // (a) it's a command event and so is propagated to the parent | |
1669 | // (b) under MSW it can be generated from kbd too | |
1670 | // (c) it uses screen coords (because of (a)) | |
1671 | wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, | |
1672 | win->GetId(), | |
1673 | win->ClientToScreen(event.GetPosition())); | |
1674 | (void)win->GetEventHandler()->ProcessEvent(evtCtx); | |
1675 | } | |
1676 | ||
d1f2ac45 VZ |
1677 | if ( !g_captureWindow ) |
1678 | win = FindWindowForMouseEvent(win, event.m_x, event.m_y); | |
47d67540 | 1679 | |
f5e27805 | 1680 | if (win->GetEventHandler()->ProcessEvent( event )) |
034be888 | 1681 | { |
f5e27805 | 1682 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_release_event" ); |
f03fc89f | 1683 | return TRUE; |
034be888 | 1684 | } |
47d67540 | 1685 | |
034be888 | 1686 | return FALSE; |
362c6693 | 1687 | } |
c801d85f KB |
1688 | |
1689 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
1690 | // "motion_notify_event" |
1691 | //----------------------------------------------------------------------------- | |
c801d85f | 1692 | |
1e6feb95 VZ |
1693 | static gint gtk_window_motion_notify_callback( GtkWidget *widget, |
1694 | GdkEventMotion *gdk_event, | |
1695 | wxWindowGTK *win ) | |
47d67540 | 1696 | { |
3ac8d3bc RR |
1697 | DEBUG_MAIN_THREAD |
1698 | ||
c50f1fb9 | 1699 | if (g_isIdle) |
a2053b27 RR |
1700 | wxapp_install_idle_handler(); |
1701 | ||
1702 | if (!win->m_hasVMT) return FALSE; | |
034be888 RR |
1703 | if (g_blockEventsOnDrag) return FALSE; |
1704 | if (g_blockEventsOnScroll) return FALSE; | |
148cd9b6 | 1705 | |
034be888 RR |
1706 | if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; |
1707 | ||
ff8bfdbb | 1708 | if (gdk_event->is_hint) |
aae24d21 | 1709 | { |
f7a11f8c RR |
1710 | int x = 0; |
1711 | int y = 0; | |
1712 | GdkModifierType state; | |
1713 | gdk_window_get_pointer(gdk_event->window, &x, &y, &state); | |
1714 | gdk_event->x = x; | |
1715 | gdk_event->y = y; | |
aae24d21 | 1716 | } |
ff8bfdbb | 1717 | |
c801d85f | 1718 | /* |
e380f72b RR |
1719 | printf( "OnMotion from " ); |
1720 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
1721 | printf( win->GetClassInfo()->GetClassName() ); | |
1722 | printf( ".\n" ); | |
aae24d21 | 1723 | */ |
47d67540 | 1724 | |
e380f72b | 1725 | wxMouseEvent event( wxEVT_MOTION ); |
c5f9d156 | 1726 | InitMouseEvent(win, event, gdk_event); |
e380f72b | 1727 | |
50382578 | 1728 | if ( g_captureWindow ) |
2f2aa628 | 1729 | { |
1e6feb95 VZ |
1730 | // synthetize a mouse enter or leave event if needed |
1731 | GdkWindow *winUnderMouse = gdk_window_at_pointer(NULL, NULL); | |
7c5e6fc6 | 1732 | // This seems to be necessary and actually been added to |
50382578 RR |
1733 | // GDK itself in version 2.0.X |
1734 | gdk_flush(); | |
7c5e6fc6 | 1735 | |
1e6feb95 VZ |
1736 | bool hasMouse = winUnderMouse == gdk_event->window; |
1737 | if ( hasMouse != g_captureWindowHasMouse ) | |
1738 | { | |
1739 | // the mouse changed window | |
1740 | g_captureWindowHasMouse = hasMouse; | |
1741 | ||
1742 | wxMouseEvent event(g_captureWindowHasMouse ? wxEVT_ENTER_WINDOW | |
1743 | : wxEVT_LEAVE_WINDOW); | |
c5f9d156 | 1744 | InitMouseEvent(win, event, gdk_event); |
1e6feb95 VZ |
1745 | event.SetEventObject(win); |
1746 | win->GetEventHandler()->ProcessEvent(event); | |
1747 | } | |
1748 | } | |
1749 | else // no capture | |
1750 | { | |
d1f2ac45 | 1751 | win = FindWindowForMouseEvent(win, event.m_x, event.m_y); |
2f2aa628 | 1752 | } |
47d67540 | 1753 | |
e380f72b | 1754 | if (win->GetEventHandler()->ProcessEvent( event )) |
034be888 | 1755 | { |
e380f72b | 1756 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "motion_notify_event" ); |
f03fc89f | 1757 | return TRUE; |
034be888 | 1758 | } |
47d67540 | 1759 | |
034be888 | 1760 | return FALSE; |
362c6693 | 1761 | } |
c801d85f KB |
1762 | |
1763 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
1764 | // "focus_in_event" |
1765 | //----------------------------------------------------------------------------- | |
c801d85f | 1766 | |
6aeb6f2a VZ |
1767 | // send the wxChildFocusEvent and wxFocusEvent, common code of |
1768 | // gtk_window_focus_in_callback() and SetFocus() | |
1769 | static bool DoSendFocusEvents(wxWindow *win) | |
1770 | { | |
1771 | // Notify the parent keeping track of focus for the kbd navigation | |
1772 | // purposes that we got it. | |
1773 | wxChildFocusEvent eventChildFocus(win); | |
1774 | (void)win->GetEventHandler()->ProcessEvent(eventChildFocus); | |
1775 | ||
1776 | wxFocusEvent eventFocus(wxEVT_SET_FOCUS, win->GetId()); | |
1777 | eventFocus.SetEventObject(win); | |
1778 | ||
1779 | return win->GetEventHandler()->ProcessEvent(eventFocus); | |
1780 | } | |
1781 | ||
1e6feb95 VZ |
1782 | static gint gtk_window_focus_in_callback( GtkWidget *widget, |
1783 | GdkEvent *WXUNUSED(event), | |
1784 | wxWindow *win ) | |
c801d85f | 1785 | { |
3ac8d3bc RR |
1786 | DEBUG_MAIN_THREAD |
1787 | ||
c50f1fb9 | 1788 | if (g_isIdle) |
a2053b27 RR |
1789 | wxapp_install_idle_handler(); |
1790 | ||
1791 | if (!win->m_hasVMT) return FALSE; | |
034be888 | 1792 | if (g_blockEventsOnDrag) return FALSE; |
ff8bfdbb | 1793 | |
148cd9b6 VZ |
1794 | switch ( g_sendActivateEvent ) |
1795 | { | |
1796 | case -1: | |
76fcf0f2 | 1797 | // we've got focus from outside, synthetize wxActivateEvent |
148cd9b6 VZ |
1798 | g_sendActivateEvent = 1; |
1799 | break; | |
1800 | ||
1801 | case 0: | |
1802 | // another our window just lost focus, it was already ours before | |
1803 | // - don't send any wxActivateEvent | |
1804 | g_sendActivateEvent = -1; | |
1805 | break; | |
1806 | } | |
1807 | ||
1e6feb95 | 1808 | g_focusWindowLast = |
b292e2f5 | 1809 | g_focusWindow = win; |
ff8bfdbb | 1810 | |
6cad4f1b VZ |
1811 | wxLogTrace(TRACE_FOCUS, |
1812 | _T("%s: focus in"), win->GetName().c_str()); | |
7de59551 | 1813 | |
b79395c5 RR |
1814 | #ifdef HAVE_XIM |
1815 | if (win->m_ic) | |
1816 | gdk_im_begin(win->m_ic, win->m_wxwindow->window); | |
1817 | #endif | |
1818 | ||
1e6feb95 | 1819 | #if wxUSE_CARET |
f6bcfd97 BP |
1820 | // caret needs to be informed about focus change |
1821 | wxCaret *caret = win->GetCaret(); | |
1822 | if ( caret ) | |
1823 | { | |
1824 | caret->OnSetFocus(); | |
1825 | } | |
1826 | #endif // wxUSE_CARET | |
1827 | ||
d7fa7eaa | 1828 | g_activeFrameLostFocus = FALSE; |
2b5f62a0 | 1829 | |
e8c12a53 VS |
1830 | wxWindowGTK *active = wxGetTopLevelParent(win); |
1831 | if ( active != g_activeFrame ) | |
942bef71 | 1832 | { |
e8c12a53 VS |
1833 | if ( g_activeFrame ) |
1834 | { | |
45eb5249 | 1835 | wxLogTrace(wxT("activate"), wxT("Deactivating frame %p (from focus_in)"), g_activeFrame); |
e8c12a53 VS |
1836 | wxActivateEvent event(wxEVT_ACTIVATE, FALSE, g_activeFrame->GetId()); |
1837 | event.SetEventObject(g_activeFrame); | |
1838 | g_activeFrame->GetEventHandler()->ProcessEvent(event); | |
1839 | } | |
47d67540 | 1840 | |
45eb5249 | 1841 | wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), active); |
e8c12a53 VS |
1842 | g_activeFrame = active; |
1843 | wxActivateEvent event(wxEVT_ACTIVATE, TRUE, g_activeFrame->GetId()); | |
1844 | event.SetEventObject(g_activeFrame); | |
1845 | g_activeFrame->GetEventHandler()->ProcessEvent(event); | |
2b5f62a0 | 1846 | |
d7fa7eaa RR |
1847 | // Don't send focus events in addition to activate |
1848 | // if (win == g_activeFrame) | |
1849 | // return TRUE; | |
942bef71 | 1850 | } |
e8c12a53 | 1851 | |
6cad4f1b VZ |
1852 | // does the window itself think that it has the focus? |
1853 | if ( !win->m_hasFocus ) | |
5cd09f0b | 1854 | { |
6cad4f1b VZ |
1855 | // not yet, notify it |
1856 | win->m_hasFocus = TRUE; | |
1857 | ||
1858 | if ( DoSendFocusEvents(win) ) | |
1859 | { | |
1860 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_in_event" ); | |
1861 | return TRUE; | |
1862 | } | |
034be888 | 1863 | } |
ca298c88 | 1864 | |
034be888 | 1865 | return FALSE; |
362c6693 | 1866 | } |
c801d85f KB |
1867 | |
1868 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
1869 | // "focus_out_event" |
1870 | //----------------------------------------------------------------------------- | |
c801d85f | 1871 | |
afbe906a | 1872 | static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEventFocus *gdk_event, wxWindowGTK *win ) |
c801d85f | 1873 | { |
3ac8d3bc RR |
1874 | DEBUG_MAIN_THREAD |
1875 | ||
c50f1fb9 | 1876 | if (g_isIdle) |
a2053b27 RR |
1877 | wxapp_install_idle_handler(); |
1878 | ||
1879 | if (!win->m_hasVMT) return FALSE; | |
034be888 | 1880 | if (g_blockEventsOnDrag) return FALSE; |
ca298c88 | 1881 | |
6cad4f1b VZ |
1882 | wxLogTrace( TRACE_FOCUS, |
1883 | _T("%s: focus out"), win->GetName().c_str() ); | |
b231914f | 1884 | |
45eb5249 VS |
1885 | if ( !g_activeFrameLostFocus && g_activeFrame ) |
1886 | { | |
c0ad3d42 VZ |
1887 | // VZ: commenting this out because it does happen (although not easy |
1888 | // to reproduce, I only see it when using wxMiniFrame and not | |
1889 | // always) and makes using Mahogany quite annoying | |
1890 | #if 0 | |
1891 | wxASSERT_MSG( wxGetTopLevelParent(win) == g_activeFrame, | |
63fd5f0b | 1892 | wxT("unfocusing window that hasn't gained focus properly") ); |
c0ad3d42 VZ |
1893 | #endif // 0 |
1894 | ||
45eb5249 VS |
1895 | g_activeFrameLostFocus = TRUE; |
1896 | } | |
1897 | ||
148cd9b6 VZ |
1898 | // if the focus goes out of our app alltogether, OnIdle() will send |
1899 | // wxActivateEvent, otherwise gtk_window_focus_in_callback() will reset | |
1900 | // g_sendActivateEvent to -1 | |
1901 | g_sendActivateEvent = 0; | |
1902 | ||
3379ed37 | 1903 | wxWindowGTK *winFocus = wxFindFocusedChild(win); |
f6bcfd97 BP |
1904 | if ( winFocus ) |
1905 | win = winFocus; | |
1906 | ||
1e6feb95 | 1907 | g_focusWindow = (wxWindowGTK *)NULL; |
148cd9b6 | 1908 | |
b79395c5 RR |
1909 | #ifdef HAVE_XIM |
1910 | if (win->m_ic) | |
1911 | gdk_im_end(); | |
1912 | #endif | |
1913 | ||
1e6feb95 | 1914 | #if wxUSE_CARET |
f6bcfd97 BP |
1915 | // caret needs to be informed about focus change |
1916 | wxCaret *caret = win->GetCaret(); | |
1917 | if ( caret ) | |
1918 | { | |
1919 | caret->OnKillFocus(); | |
1920 | } | |
1921 | #endif // wxUSE_CARET | |
1922 | ||
6cad4f1b VZ |
1923 | // don't send the window a kill focus event if it thinks that it doesn't |
1924 | // have focus already | |
1925 | if ( win->m_hasFocus ) | |
5cd09f0b | 1926 | { |
6cad4f1b VZ |
1927 | win->m_hasFocus = FALSE; |
1928 | ||
1929 | wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() ); | |
1930 | event.SetEventObject( win ); | |
1931 | ||
1932 | if (win->GetEventHandler()->ProcessEvent( event )) | |
1933 | { | |
1934 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_out_event" ); | |
1935 | return TRUE; | |
1936 | } | |
034be888 | 1937 | } |
ca298c88 | 1938 | |
034be888 | 1939 | return FALSE; |
362c6693 | 1940 | } |
c801d85f | 1941 | |
b4071e91 RR |
1942 | //----------------------------------------------------------------------------- |
1943 | // "enter_notify_event" | |
1944 | //----------------------------------------------------------------------------- | |
1945 | ||
edc1d330 VZ |
1946 | static |
1947 | gint gtk_window_enter_callback( GtkWidget *widget, | |
1948 | GdkEventCrossing *gdk_event, | |
1949 | wxWindowGTK *win ) | |
b4071e91 | 1950 | { |
3ac8d3bc RR |
1951 | DEBUG_MAIN_THREAD |
1952 | ||
c50f1fb9 | 1953 | if (g_isIdle) |
a2053b27 | 1954 | wxapp_install_idle_handler(); |
ca298c88 | 1955 | |
a2053b27 RR |
1956 | if (!win->m_hasVMT) return FALSE; |
1957 | if (g_blockEventsOnDrag) return FALSE; | |
47d67540 | 1958 | |
7f5f144a RR |
1959 | // Event was emitted after a grab |
1960 | if (gdk_event->mode != GDK_CROSSING_NORMAL) return FALSE; | |
7c5e6fc6 | 1961 | |
a2053b27 | 1962 | if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; |
b292e2f5 | 1963 | |
4a33eba6 RR |
1964 | int x = 0; |
1965 | int y = 0; | |
1966 | GdkModifierType state = (GdkModifierType)0; | |
ff8bfdbb | 1967 | |
a2053b27 | 1968 | gdk_window_get_pointer( widget->window, &x, &y, &state ); |
ff8bfdbb | 1969 | |
edc1d330 | 1970 | wxMouseEvent event( wxEVT_ENTER_WINDOW ); |
c5f9d156 VS |
1971 | InitMouseEvent(win, event, gdk_event); |
1972 | wxPoint pt = win->GetClientAreaOrigin(); | |
1973 | event.m_x = x + pt.x; | |
1974 | event.m_y = y + pt.y; | |
ff8bfdbb | 1975 | |
e380f72b | 1976 | if (win->GetEventHandler()->ProcessEvent( event )) |
034be888 | 1977 | { |
e380f72b | 1978 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "enter_notify_event" ); |
034be888 RR |
1979 | return TRUE; |
1980 | } | |
ca298c88 | 1981 | |
034be888 | 1982 | return FALSE; |
b4071e91 | 1983 | } |
47d67540 | 1984 | |
b4071e91 RR |
1985 | //----------------------------------------------------------------------------- |
1986 | // "leave_notify_event" | |
1987 | //----------------------------------------------------------------------------- | |
1988 | ||
1e6feb95 | 1989 | static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindowGTK *win ) |
b4071e91 | 1990 | { |
3ac8d3bc RR |
1991 | DEBUG_MAIN_THREAD |
1992 | ||
c50f1fb9 | 1993 | if (g_isIdle) |
a2053b27 | 1994 | wxapp_install_idle_handler(); |
acfd422a | 1995 | |
a2053b27 RR |
1996 | if (!win->m_hasVMT) return FALSE; |
1997 | if (g_blockEventsOnDrag) return FALSE; | |
b292e2f5 | 1998 | |
7f5f144a RR |
1999 | // Event was emitted after an ungrab |
2000 | if (gdk_event->mode != GDK_CROSSING_NORMAL) return FALSE; | |
7c5e6fc6 | 2001 | |
a2053b27 | 2002 | if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; |
c50f1fb9 | 2003 | |
e380f72b | 2004 | wxMouseEvent event( wxEVT_LEAVE_WINDOW ); |
d1367c3d | 2005 | event.SetTimestamp( gdk_event->time ); |
e380f72b | 2006 | event.SetEventObject( win ); |
47d67540 | 2007 | |
4a33eba6 RR |
2008 | int x = 0; |
2009 | int y = 0; | |
2010 | GdkModifierType state = (GdkModifierType)0; | |
ff8bfdbb | 2011 | |
4a33eba6 | 2012 | gdk_window_get_pointer( widget->window, &x, &y, &state ); |
ff8bfdbb | 2013 | |
74710601 VZ |
2014 | event.m_shiftDown = (state & GDK_SHIFT_MASK) != 0; |
2015 | event.m_controlDown = (state & GDK_CONTROL_MASK) != 0; | |
2016 | event.m_altDown = (state & GDK_MOD1_MASK) != 0; | |
2017 | event.m_metaDown = (state & GDK_MOD2_MASK) != 0; | |
2018 | event.m_leftDown = (state & GDK_BUTTON1_MASK) != 0; | |
2019 | event.m_middleDown = (state & GDK_BUTTON2_MASK) != 0; | |
2020 | event.m_rightDown = (state & GDK_BUTTON3_MASK) != 0; | |
4a33eba6 | 2021 | |
c5f9d156 VS |
2022 | wxPoint pt = win->GetClientAreaOrigin(); |
2023 | event.m_x = x + pt.x; | |
2024 | event.m_y = y + pt.y; | |
ff8bfdbb | 2025 | |
e380f72b | 2026 | if (win->GetEventHandler()->ProcessEvent( event )) |
034be888 | 2027 | { |
e380f72b | 2028 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "leave_notify_event" ); |
034be888 RR |
2029 | return TRUE; |
2030 | } | |
ca298c88 | 2031 | |
034be888 | 2032 | return FALSE; |
b4071e91 | 2033 | } |
47d67540 | 2034 | |
c801d85f | 2035 | //----------------------------------------------------------------------------- |
2f2aa628 RR |
2036 | // "value_changed" from m_vAdjust |
2037 | //----------------------------------------------------------------------------- | |
c801d85f | 2038 | |
9e691f46 VZ |
2039 | static void gtk_window_vscroll_callback( GtkAdjustment *adjust, |
2040 | SCROLLBAR_CBACK_ARG | |
2041 | wxWindowGTK *win ) | |
c801d85f | 2042 | { |
3ac8d3bc RR |
2043 | DEBUG_MAIN_THREAD |
2044 | ||
c50f1fb9 | 2045 | if (g_isIdle) |
a2053b27 | 2046 | wxapp_install_idle_handler(); |
c801d85f | 2047 | |
a2053b27 | 2048 | if (g_blockEventsOnDrag) return; |
47d67540 | 2049 | |
a2053b27 | 2050 | if (!win->m_hasVMT) return; |
148cd9b6 | 2051 | |
5e014a0c | 2052 | float diff = adjust->value - win->m_oldVerticalPos; |
e380f72b | 2053 | if (fabs(diff) < 0.2) return; |
148cd9b6 | 2054 | |
5e014a0c | 2055 | win->m_oldVerticalPos = adjust->value; |
47d67540 | 2056 | |
a8bf1826 | 2057 | #ifndef __WXGTK20__ |
6728fb61 | 2058 | GtkScrolledWindow *sw = GTK_SCROLLED_WINDOW(win->m_widget); |
a8bf1826 | 2059 | #endif |
6728fb61 | 2060 | wxEventType command = GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw->vscrollbar)); |
148cd9b6 | 2061 | |
5e014a0c | 2062 | int value = (int)(adjust->value+0.5); |
c801d85f | 2063 | |
c5b42c87 | 2064 | wxScrollWinEvent event( command, value, wxVERTICAL ); |
e380f72b RR |
2065 | event.SetEventObject( win ); |
2066 | win->GetEventHandler()->ProcessEvent( event ); | |
362c6693 | 2067 | } |
c801d85f KB |
2068 | |
2069 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
2070 | // "value_changed" from m_hAdjust |
2071 | //----------------------------------------------------------------------------- | |
c801d85f | 2072 | |
9e691f46 VZ |
2073 | static void gtk_window_hscroll_callback( GtkAdjustment *adjust, |
2074 | SCROLLBAR_CBACK_ARG | |
2075 | wxWindowGTK *win ) | |
47d67540 | 2076 | { |
3ac8d3bc RR |
2077 | DEBUG_MAIN_THREAD |
2078 | ||
c50f1fb9 | 2079 | if (g_isIdle) |
a2053b27 | 2080 | wxapp_install_idle_handler(); |
47d67540 | 2081 | |
a2053b27 RR |
2082 | if (g_blockEventsOnDrag) return; |
2083 | if (!win->m_hasVMT) return; | |
47d67540 | 2084 | |
5e014a0c | 2085 | float diff = adjust->value - win->m_oldHorizontalPos; |
e380f72b | 2086 | if (fabs(diff) < 0.2) return; |
148cd9b6 | 2087 | |
a8bf1826 | 2088 | #ifndef __WXGTK20__ |
6728fb61 | 2089 | GtkScrolledWindow *sw = GTK_SCROLLED_WINDOW(win->m_widget); |
a8bf1826 | 2090 | #endif |
6728fb61 | 2091 | wxEventType command = GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw->hscrollbar)); |
148cd9b6 | 2092 | |
9e691f46 | 2093 | win->m_oldHorizontalPos = adjust->value; |
148cd9b6 | 2094 | |
5e014a0c | 2095 | int value = (int)(adjust->value+0.5); |
47d67540 | 2096 | |
c5b42c87 | 2097 | wxScrollWinEvent event( command, value, wxHORIZONTAL ); |
e380f72b RR |
2098 | event.SetEventObject( win ); |
2099 | win->GetEventHandler()->ProcessEvent( event ); | |
362c6693 | 2100 | } |
c801d85f | 2101 | |
cb43b372 RR |
2102 | //----------------------------------------------------------------------------- |
2103 | // "button_press_event" from scrollbar | |
2104 | //----------------------------------------------------------------------------- | |
2105 | ||
2a23d363 RR |
2106 | static gint gtk_scrollbar_button_press_callback( GtkRange *widget, |
2107 | GdkEventButton *gdk_event, | |
1e6feb95 | 2108 | wxWindowGTK *win) |
cb43b372 | 2109 | { |
3ac8d3bc RR |
2110 | DEBUG_MAIN_THREAD |
2111 | ||
c50f1fb9 | 2112 | if (g_isIdle) |
a2053b27 RR |
2113 | wxapp_install_idle_handler(); |
2114 | ||
d6d26e04 | 2115 | |
5b8a521e | 2116 | g_blockEventsOnScroll = TRUE; |
9e691f46 VZ |
2117 | |
2118 | // FIXME: there is no 'slider' field in GTK+ 2.0 any more | |
2119 | #ifndef __WXGTK20__ | |
2a23d363 | 2120 | win->m_isScrolling = (gdk_event->window == widget->slider); |
9e691f46 | 2121 | #endif |
47d67540 | 2122 | |
e380f72b | 2123 | return FALSE; |
cb43b372 RR |
2124 | } |
2125 | ||
2126 | //----------------------------------------------------------------------------- | |
2127 | // "button_release_event" from scrollbar | |
2128 | //----------------------------------------------------------------------------- | |
2129 | ||
88413fec | 2130 | static gint gtk_scrollbar_button_release_callback( GtkRange *widget, |
8bbe427f | 2131 | GdkEventButton *WXUNUSED(gdk_event), |
1e6feb95 | 2132 | wxWindowGTK *win) |
cb43b372 | 2133 | { |
3ac8d3bc RR |
2134 | DEBUG_MAIN_THREAD |
2135 | ||
1ecc4d80 | 2136 | // don't test here as we can release the mouse while being over |
5e014a0c | 2137 | // a different window than the slider |
76ed8f8d RR |
2138 | // |
2139 | // if (gdk_event->window != widget->slider) return FALSE; | |
cb43b372 | 2140 | |
5b8a521e | 2141 | g_blockEventsOnScroll = FALSE; |
47d67540 | 2142 | |
2a23d363 | 2143 | if (win->m_isScrolling) |
88413fec | 2144 | { |
d6d26e04 | 2145 | wxEventType command = wxEVT_SCROLLWIN_THUMBRELEASE; |
2a23d363 RR |
2146 | int value = -1; |
2147 | int dir = -1; | |
2daa0ce9 | 2148 | |
2a23d363 RR |
2149 | GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(win->m_widget); |
2150 | if (widget == GTK_RANGE(scrolledWindow->hscrollbar)) | |
2151 | { | |
2152 | value = (int)(win->m_hAdjust->value+0.5); | |
2153 | dir = wxHORIZONTAL; | |
2154 | } | |
2155 | if (widget == GTK_RANGE(scrolledWindow->vscrollbar)) | |
2156 | { | |
2157 | value = (int)(win->m_vAdjust->value+0.5); | |
2158 | dir = wxVERTICAL; | |
2159 | } | |
2daa0ce9 | 2160 | |
2a23d363 | 2161 | wxScrollWinEvent event( command, value, dir ); |
2a23d363 RR |
2162 | event.SetEventObject( win ); |
2163 | win->GetEventHandler()->ProcessEvent( event ); | |
88413fec RR |
2164 | } |
2165 | ||
2a23d363 | 2166 | win->m_isScrolling = FALSE; |
2daa0ce9 | 2167 | |
e380f72b | 2168 | return FALSE; |
cb43b372 RR |
2169 | } |
2170 | ||
f03fc89f VZ |
2171 | // ---------------------------------------------------------------------------- |
2172 | // this wxWindowBase function is implemented here (in platform-specific file) | |
2173 | // because it is static and so couldn't be made virtual | |
2174 | // ---------------------------------------------------------------------------- | |
2b07d713 | 2175 | |
f03fc89f | 2176 | wxWindow *wxWindowBase::FindFocus() |
2b07d713 | 2177 | { |
1e6feb95 VZ |
2178 | // the cast is necessary when we compile in wxUniversal mode |
2179 | return (wxWindow *)g_focusWindow; | |
2b07d713 | 2180 | } |
ca298c88 | 2181 | |
1a685a59 | 2182 | |
a2053b27 RR |
2183 | //----------------------------------------------------------------------------- |
2184 | // "realize" from m_widget | |
2185 | //----------------------------------------------------------------------------- | |
2186 | ||
b79395c5 RR |
2187 | /* We cannot set colours and fonts before the widget has |
2188 | been realized, so we do this directly after realization. */ | |
a2053b27 RR |
2189 | |
2190 | static gint | |
2b5f62a0 | 2191 | gtk_window_realized_callback( GtkWidget *m_widget, wxWindow *win ) |
a2053b27 | 2192 | { |
3ac8d3bc RR |
2193 | DEBUG_MAIN_THREAD |
2194 | ||
c50f1fb9 | 2195 | if (g_isIdle) |
a2053b27 RR |
2196 | wxapp_install_idle_handler(); |
2197 | ||
739730ca | 2198 | if (win->m_delayedBackgroundColour) |
ea323db3 | 2199 | win->GtkSetBackgroundColour( win->GetBackgroundColour() ); |
a2053b27 | 2200 | |
739730ca | 2201 | if (win->m_delayedForegroundColour) |
ea323db3 | 2202 | win->GtkSetForegroundColour( win->GetForegroundColour() ); |
a2053b27 | 2203 | |
2b5f62a0 VZ |
2204 | #ifdef __WXGTK20__ |
2205 | if (win->m_imContext) | |
2206 | { | |
2207 | GtkPizza *pizza = GTK_PIZZA( m_widget ); | |
2208 | gtk_im_context_set_client_window( (GtkIMContext*) win->m_imContext, pizza->bin_window ); | |
2209 | } | |
2210 | #endif | |
2211 | ||
3c679789 RR |
2212 | wxWindowCreateEvent event( win ); |
2213 | event.SetEventObject( win ); | |
2214 | win->GetEventHandler()->ProcessEvent( event ); | |
1e6feb95 | 2215 | |
a2053b27 RR |
2216 | return FALSE; |
2217 | } | |
2218 | ||
b79395c5 RR |
2219 | //----------------------------------------------------------------------------- |
2220 | // "size_allocate" | |
2221 | //----------------------------------------------------------------------------- | |
2222 | ||
8f75cb6c | 2223 | static |
adc1999b RR |
2224 | void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), |
2225 | GtkAllocation *WXUNUSED(alloc), | |
8f75cb6c RR |
2226 | wxWindow *win ) |
2227 | { | |
2228 | if (g_isIdle) | |
2229 | wxapp_install_idle_handler(); | |
2daa0ce9 | 2230 | |
5b8a521e | 2231 | if (!win->m_hasScrolling) return; |
2daa0ce9 | 2232 | |
5b8a521e RR |
2233 | int client_width = 0; |
2234 | int client_height = 0; | |
2235 | win->GetClientSize( &client_width, &client_height ); | |
2236 | if ((client_width == win->m_oldClientWidth) && (client_height == win->m_oldClientHeight)) | |
2237 | return; | |
2daa0ce9 | 2238 | |
5b8a521e RR |
2239 | win->m_oldClientWidth = client_width; |
2240 | win->m_oldClientHeight = client_height; | |
2daa0ce9 | 2241 | |
5b8a521e RR |
2242 | if (!win->m_nativeSizeEvent) |
2243 | { | |
2244 | wxSizeEvent event( win->GetSize(), win->GetId() ); | |
2245 | event.SetEventObject( win ); | |
2246 | win->GetEventHandler()->ProcessEvent( event ); | |
2247 | } | |
8f75cb6c RR |
2248 | } |
2249 | ||
2250 | ||
3ed2e7ce VZ |
2251 | #ifdef HAVE_XIM |
2252 | #define WXUNUSED_UNLESS_XIM(param) param | |
2253 | #else | |
2254 | #define WXUNUSED_UNLESS_XIM(param) WXUNUSED(param) | |
2255 | #endif | |
2256 | ||
b79395c5 RR |
2257 | /* Resize XIM window */ |
2258 | ||
3ed2e7ce | 2259 | static |
8f75cb6c RR |
2260 | void gtk_wxwindow_size_callback( GtkWidget* WXUNUSED_UNLESS_XIM(widget), |
2261 | GtkAllocation* WXUNUSED_UNLESS_XIM(alloc), | |
1e6feb95 | 2262 | wxWindowGTK* WXUNUSED_UNLESS_XIM(win) ) |
b79395c5 RR |
2263 | { |
2264 | if (g_isIdle) | |
2265 | wxapp_install_idle_handler(); | |
2daa0ce9 | 2266 | |
9a8c7620 | 2267 | #ifdef HAVE_XIM |
b79395c5 RR |
2268 | if (!win->m_ic) |
2269 | return; | |
2270 | ||
b79395c5 RR |
2271 | if (gdk_ic_get_style (win->m_ic) & GDK_IM_PREEDIT_POSITION) |
2272 | { | |
2273 | gint width, height; | |
2274 | ||
3ed2e7ce | 2275 | gdk_window_get_size (widget->window, &width, &height); |
b79395c5 RR |
2276 | win->m_icattr->preedit_area.width = width; |
2277 | win->m_icattr->preedit_area.height = height; | |
2278 | gdk_ic_set_attr (win->m_ic, win->m_icattr, GDK_IC_PREEDIT_AREA); | |
2279 | } | |
9a8c7620 | 2280 | #endif // HAVE_XIM |
b79395c5 RR |
2281 | } |
2282 | ||
63081513 RR |
2283 | //----------------------------------------------------------------------------- |
2284 | // "realize" from m_wxwindow | |
2285 | //----------------------------------------------------------------------------- | |
2286 | ||
2287 | /* Initialize XIM support */ | |
2288 | ||
2289 | static gint | |
3ed2e7ce | 2290 | gtk_wxwindow_realized_callback( GtkWidget * WXUNUSED_UNLESS_XIM(widget), |
1e6feb95 | 2291 | wxWindowGTK * WXUNUSED_UNLESS_XIM(win) ) |
63081513 RR |
2292 | { |
2293 | if (g_isIdle) | |
2294 | wxapp_install_idle_handler(); | |
2295 | ||
d06800f1 | 2296 | #ifdef HAVE_XIM |
63081513 RR |
2297 | if (win->m_ic) return FALSE; |
2298 | if (!widget) return FALSE; | |
2299 | if (!gdk_im_ready()) return FALSE; | |
2300 | ||
2301 | win->m_icattr = gdk_ic_attr_new(); | |
2302 | if (!win->m_icattr) return FALSE; | |
2daa0ce9 | 2303 | |
63081513 RR |
2304 | gint width, height; |
2305 | GdkEventMask mask; | |
2306 | GdkColormap *colormap; | |
2307 | GdkICAttr *attr = win->m_icattr; | |
b58b1dfc | 2308 | unsigned attrmask = GDK_IC_ALL_REQ; |
63081513 | 2309 | GdkIMStyle style; |
b79395c5 RR |
2310 | GdkIMStyle supported_style = (GdkIMStyle) |
2311 | (GDK_IM_PREEDIT_NONE | | |
1e6feb95 VZ |
2312 | GDK_IM_PREEDIT_NOTHING | |
2313 | GDK_IM_PREEDIT_POSITION | | |
2314 | GDK_IM_STATUS_NONE | | |
2315 | GDK_IM_STATUS_NOTHING); | |
63081513 RR |
2316 | |
2317 | if (widget->style && widget->style->font->type != GDK_FONT_FONTSET) | |
1e6feb95 | 2318 | supported_style = (GdkIMStyle)(supported_style & ~GDK_IM_PREEDIT_POSITION); |
63081513 RR |
2319 | |
2320 | attr->style = style = gdk_im_decide_style (supported_style); | |
2321 | attr->client_window = widget->window; | |
2322 | ||
2323 | if ((colormap = gtk_widget_get_colormap (widget)) != | |
1e6feb95 | 2324 | gtk_widget_get_default_colormap ()) |
63081513 | 2325 | { |
5cd09f0b RR |
2326 | attrmask |= GDK_IC_PREEDIT_COLORMAP; |
2327 | attr->preedit_colormap = colormap; | |
63081513 | 2328 | } |
2daa0ce9 | 2329 | |
63081513 RR |
2330 | attrmask |= GDK_IC_PREEDIT_FOREGROUND; |
2331 | attrmask |= GDK_IC_PREEDIT_BACKGROUND; | |
2332 | attr->preedit_foreground = widget->style->fg[GTK_STATE_NORMAL]; | |
2333 | attr->preedit_background = widget->style->base[GTK_STATE_NORMAL]; | |
2334 | ||
2335 | switch (style & GDK_IM_PREEDIT_MASK) | |
2336 | { | |
1e6feb95 VZ |
2337 | case GDK_IM_PREEDIT_POSITION: |
2338 | if (widget->style && widget->style->font->type != GDK_FONT_FONTSET) | |
2339 | { | |
2340 | g_warning ("over-the-spot style requires fontset"); | |
2341 | break; | |
2342 | } | |
63081513 | 2343 | |
1e6feb95 | 2344 | gdk_window_get_size (widget->window, &width, &height); |
63081513 | 2345 | |
1e6feb95 VZ |
2346 | attrmask |= GDK_IC_PREEDIT_POSITION_REQ; |
2347 | attr->spot_location.x = 0; | |
2348 | attr->spot_location.y = height; | |
2349 | attr->preedit_area.x = 0; | |
2350 | attr->preedit_area.y = 0; | |
2351 | attr->preedit_area.width = width; | |
2352 | attr->preedit_area.height = height; | |
2353 | attr->preedit_fontset = widget->style->font; | |
63081513 | 2354 | |
1e6feb95 | 2355 | break; |
b79395c5 | 2356 | } |
2daa0ce9 | 2357 | |
b58b1dfc | 2358 | win->m_ic = gdk_ic_new (attr, (GdkICAttributesType)attrmask); |
2daa0ce9 | 2359 | |
63081513 | 2360 | if (win->m_ic == NULL) |
1e6feb95 | 2361 | g_warning ("Can't create input context."); |
63081513 | 2362 | else |
1e6feb95 VZ |
2363 | { |
2364 | mask = gdk_window_get_events (widget->window); | |
2365 | mask = (GdkEventMask)(mask | gdk_ic_get_events (win->m_ic)); | |
2366 | gdk_window_set_events (widget->window, mask); | |
2367 | ||
2368 | if (GTK_WIDGET_HAS_FOCUS(widget)) | |
2369 | gdk_im_begin (win->m_ic, widget->window); | |
2370 | } | |
2371 | #endif // HAVE_XIM | |
63081513 RR |
2372 | |
2373 | return FALSE; | |
2374 | } | |
2375 | ||
6ca41e57 | 2376 | //----------------------------------------------------------------------------- |
1e6feb95 | 2377 | // InsertChild for wxWindowGTK. |
6ca41e57 RR |
2378 | //----------------------------------------------------------------------------- |
2379 | ||
1e6feb95 | 2380 | /* Callback for wxWindowGTK. This very strange beast has to be used because |
b1170810 RR |
2381 | * C++ has no virtual methods in a constructor. We have to emulate a |
2382 | * virtual function here as wxNotebook requires a different way to insert | |
2383 | * a child in it. I had opted for creating a wxNotebookPage window class | |
2384 | * which would have made this superfluous (such in the MDI window system), | |
2385 | * but no-one was listening to me... */ | |
6ca41e57 | 2386 | |
1e6feb95 | 2387 | static void wxInsertChildInWindow( wxWindowGTK* parent, wxWindowGTK* child ) |
6ca41e57 | 2388 | { |
bf0c00c6 RR |
2389 | /* the window might have been scrolled already, do we |
2390 | have to adapt the position */ | |
da048e3d RR |
2391 | GtkPizza *pizza = GTK_PIZZA(parent->m_wxwindow); |
2392 | child->m_x += pizza->xoffset; | |
2393 | child->m_y += pizza->yoffset; | |
148cd9b6 | 2394 | |
da048e3d | 2395 | gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow), |
a2053b27 RR |
2396 | GTK_WIDGET(child->m_widget), |
2397 | child->m_x, | |
2398 | child->m_y, | |
2399 | child->m_width, | |
2400 | child->m_height ); | |
6ca41e57 RR |
2401 | } |
2402 | ||
bbe0af5b RR |
2403 | //----------------------------------------------------------------------------- |
2404 | // global functions | |
2405 | //----------------------------------------------------------------------------- | |
2406 | ||
1e6feb95 | 2407 | wxWindow *wxGetActiveWindow() |
bbe0af5b | 2408 | { |
6cad4f1b | 2409 | return wxWindow::FindFocus(); |
bbe0af5b RR |
2410 | } |
2411 | ||
c801d85f | 2412 | //----------------------------------------------------------------------------- |
1e6feb95 | 2413 | // wxWindowGTK |
c801d85f KB |
2414 | //----------------------------------------------------------------------------- |
2415 | ||
6522713c VZ |
2416 | // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu() |
2417 | // method | |
1e6feb95 | 2418 | #ifdef __WXUNIVERSAL__ |
6522713c VZ |
2419 | IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK, wxWindowBase) |
2420 | #else // __WXGTK__ | |
1e6feb95 | 2421 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) |
6522713c | 2422 | #endif // __WXUNIVERSAL__/__WXGTK__ |
c801d85f | 2423 | |
1e6feb95 | 2424 | void wxWindowGTK::Init() |
c801d85f | 2425 | { |
f03fc89f VZ |
2426 | // common init |
2427 | InitBase(); | |
68995f26 | 2428 | |
f03fc89f | 2429 | // GTK specific |
a2053b27 | 2430 | m_widget = (GtkWidget *) NULL; |
e380f72b | 2431 | m_wxwindow = (GtkWidget *) NULL; |
76fcf0f2 | 2432 | m_focusWidget = (GtkWidget *) NULL; |
8bbe427f | 2433 | |
f03fc89f | 2434 | // position/size |
a2053b27 RR |
2435 | m_x = 0; |
2436 | m_y = 0; | |
2437 | m_width = 0; | |
e380f72b | 2438 | m_height = 0; |
8bbe427f | 2439 | |
e380f72b RR |
2440 | m_sizeSet = FALSE; |
2441 | m_hasVMT = FALSE; | |
2442 | m_needParent = TRUE; | |
31c6b4fc | 2443 | m_isBeingDeleted = FALSE; |
148cd9b6 | 2444 | |
147bc491 | 2445 | m_noExpose = FALSE; |
30760ce7 | 2446 | m_nativeSizeEvent = FALSE; |
94633ad9 | 2447 | |
a2053b27 | 2448 | m_hasScrolling = FALSE; |
846e1424 | 2449 | m_isScrolling = FALSE; |
f03fc89f | 2450 | |
a2053b27 | 2451 | m_hAdjust = (GtkAdjustment*) NULL; |
e380f72b | 2452 | m_vAdjust = (GtkAdjustment*) NULL; |
a2053b27 | 2453 | m_oldHorizontalPos = 0.0; |
e380f72b | 2454 | m_oldVerticalPos = 0.0; |
8bbe427f | 2455 | |
e380f72b | 2456 | m_resizing = FALSE; |
e380f72b | 2457 | m_widgetStyle = (GtkStyle*) NULL; |
8bbe427f | 2458 | |
ddb6bc71 | 2459 | m_insertCallback = (wxInsertChildFunction) NULL; |
8bbe427f | 2460 | |
b292e2f5 | 2461 | m_acceptsFocus = FALSE; |
6cad4f1b | 2462 | m_hasFocus = FALSE; |
148cd9b6 | 2463 | |
b6fa52db | 2464 | m_clipPaintRegion = FALSE; |
b6fa52db | 2465 | |
5e014a0c | 2466 | m_cursor = *wxSTANDARD_CURSOR; |
2daa0ce9 | 2467 | |
f6bcfd97 BP |
2468 | m_delayedForegroundColour = FALSE; |
2469 | m_delayedBackgroundColour = FALSE; | |
1e6feb95 | 2470 | |
2b5f62a0 VZ |
2471 | #ifdef __WXGTK20__ |
2472 | m_imContext = NULL; | |
2473 | m_x11Context = NULL; | |
2474 | #else | |
63081513 RR |
2475 | #ifdef HAVE_XIM |
2476 | m_ic = (GdkIC*) NULL; | |
2477 | m_icattr = (GdkICAttr*) NULL; | |
2478 | #endif | |
2b5f62a0 | 2479 | #endif |
362c6693 | 2480 | } |
c801d85f | 2481 | |
1e6feb95 | 2482 | wxWindowGTK::wxWindowGTK() |
68995f26 VZ |
2483 | { |
2484 | Init(); | |
2485 | } | |
2486 | ||
1e6feb95 VZ |
2487 | wxWindowGTK::wxWindowGTK( wxWindow *parent, |
2488 | wxWindowID id, | |
2489 | const wxPoint &pos, | |
2490 | const wxSize &size, | |
2491 | long style, | |
2492 | const wxString &name ) | |
6ca41e57 | 2493 | { |
68995f26 VZ |
2494 | Init(); |
2495 | ||
e380f72b | 2496 | Create( parent, id, pos, size, style, name ); |
6ca41e57 | 2497 | } |
8bbe427f | 2498 | |
1e6feb95 VZ |
2499 | bool wxWindowGTK::Create( wxWindow *parent, |
2500 | wxWindowID id, | |
2501 | const wxPoint &pos, | |
2502 | const wxSize &size, | |
2503 | long style, | |
2504 | const wxString &name ) | |
c801d85f | 2505 | { |
4dcaf11a RR |
2506 | if (!PreCreation( parent, pos, size ) || |
2507 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
2508 | { | |
1e6feb95 | 2509 | wxFAIL_MSG( wxT("wxWindowGTK creation failed") ); |
b02da6b1 | 2510 | return FALSE; |
4dcaf11a | 2511 | } |
47d67540 | 2512 | |
ddb6bc71 | 2513 | m_insertCallback = wxInsertChildInWindow; |
2b5f62a0 | 2514 | |
994bc575 | 2515 | // always needed for background clearing |
2b5f62a0 | 2516 | m_delayedBackgroundColour = TRUE; |
1e6feb95 | 2517 | |
e380f72b | 2518 | m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); |
38c7b3d3 | 2519 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); |
ff8bfdbb | 2520 | |
f03fc89f | 2521 | GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); |
47d67540 | 2522 | |
dd00f3f6 | 2523 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget) ); |
e380f72b | 2524 | scroll_class->scrollbar_spacing = 0; |
47d67540 | 2525 | |
f03fc89f | 2526 | gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); |
47d67540 | 2527 | |
f03fc89f VZ |
2528 | m_hAdjust = gtk_range_get_adjustment( GTK_RANGE(scrolledWindow->hscrollbar) ); |
2529 | m_vAdjust = gtk_range_get_adjustment( GTK_RANGE(scrolledWindow->vscrollbar) ); | |
47d67540 | 2530 | |
da048e3d | 2531 | m_wxwindow = gtk_pizza_new(); |
0fc5dbf5 | 2532 | |
1e6feb95 | 2533 | #ifndef __WXUNIVERSAL__ |
da048e3d | 2534 | GtkPizza *pizza = GTK_PIZZA(m_wxwindow); |
b292e2f5 | 2535 | |
f03fc89f | 2536 | if (HasFlag(wxRAISED_BORDER)) |
034be888 | 2537 | { |
da048e3d | 2538 | gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_OUT ); |
034be888 | 2539 | } |
f03fc89f | 2540 | else if (HasFlag(wxSUNKEN_BORDER)) |
034be888 | 2541 | { |
da048e3d | 2542 | gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_IN ); |
5e014a0c RR |
2543 | } |
2544 | else if (HasFlag(wxSIMPLE_BORDER)) | |
2545 | { | |
da048e3d | 2546 | gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_THIN ); |
034be888 RR |
2547 | } |
2548 | else | |
2549 | { | |
da048e3d | 2550 | gtk_pizza_set_shadow_type( pizza, GTK_MYSHADOW_NONE ); |
034be888 | 2551 | } |
1e6feb95 | 2552 | #endif // __WXUNIVERSAL__ |
47d67540 | 2553 | |
4e5a4c69 RR |
2554 | gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); |
2555 | ||
3da17724 RR |
2556 | GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); |
2557 | m_acceptsFocus = TRUE; | |
ca298c88 | 2558 | |
e380f72b | 2559 | // I _really_ don't want scrollbars in the beginning |
a2053b27 RR |
2560 | m_vAdjust->lower = 0.0; |
2561 | m_vAdjust->upper = 1.0; | |
2562 | m_vAdjust->value = 0.0; | |
2563 | m_vAdjust->step_increment = 1.0; | |
2564 | m_vAdjust->page_increment = 1.0; | |
2565 | m_vAdjust->page_size = 5.0; | |
2566 | gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" ); | |
2567 | m_hAdjust->lower = 0.0; | |
2568 | m_hAdjust->upper = 1.0; | |
2569 | m_hAdjust->value = 0.0; | |
2570 | m_hAdjust->step_increment = 1.0; | |
2571 | m_hAdjust->page_increment = 1.0; | |
2572 | m_hAdjust->page_size = 5.0; | |
2573 | gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" ); | |
f03fc89f VZ |
2574 | |
2575 | // these handlers block mouse events to any window during scrolling such as | |
2576 | // motion events and prevent GTK and wxWindows from fighting over where the | |
2577 | // slider should be | |
2578 | ||
2579 | gtk_signal_connect( GTK_OBJECT(scrolledWindow->vscrollbar), "button_press_event", | |
76ed8f8d RR |
2580 | (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this ); |
2581 | ||
f03fc89f | 2582 | gtk_signal_connect( GTK_OBJECT(scrolledWindow->hscrollbar), "button_press_event", |
76ed8f8d RR |
2583 | (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this ); |
2584 | ||
f03fc89f | 2585 | gtk_signal_connect( GTK_OBJECT(scrolledWindow->vscrollbar), "button_release_event", |
76ed8f8d RR |
2586 | (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this ); |
2587 | ||
f03fc89f | 2588 | gtk_signal_connect( GTK_OBJECT(scrolledWindow->hscrollbar), "button_release_event", |
76ed8f8d | 2589 | (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this ); |
8bbe427f | 2590 | |
034be888 | 2591 | // these handlers get notified when screen updates are required either when |
76ed8f8d RR |
2592 | // scrolling or when the window size (and therefore scrollbar configuration) |
2593 | // has changed | |
2594 | ||
2595 | gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed", | |
2596 | (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this ); | |
2597 | gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed", | |
2598 | (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this ); | |
2599 | ||
2b5f62a0 VZ |
2600 | #ifdef __WXGTK20__ |
2601 | // Create input method handler | |
2602 | m_imContext = (GtkIMMulticontext*) gtk_im_multicontext_new (); | |
2603 | ||
2604 | // Cannot handle drawing preedited text yet | |
2605 | gtk_im_context_set_use_preedit( (GtkIMContext*) m_imContext, FALSE ); | |
2606 | ||
2607 | g_signal_connect (G_OBJECT (m_imContext), "commit", | |
2608 | G_CALLBACK (gtk_wxwindow_commit_cb), this); | |
2609 | #endif | |
2610 | ||
f03fc89f | 2611 | gtk_widget_show( m_wxwindow ); |
47d67540 | 2612 | |
f03fc89f VZ |
2613 | if (m_parent) |
2614 | m_parent->DoAddChild( this ); | |
94633ad9 | 2615 | |
76fcf0f2 | 2616 | m_focusWidget = m_wxwindow; |
8bbe427f | 2617 | |
e380f72b | 2618 | PostCreation(); |
8bbe427f | 2619 | |
e380f72b | 2620 | Show( TRUE ); |
c801d85f | 2621 | |
e380f72b | 2622 | return TRUE; |
362c6693 | 2623 | } |
c801d85f | 2624 | |
1e6feb95 | 2625 | wxWindowGTK::~wxWindowGTK() |
c801d85f | 2626 | { |
7de59551 RD |
2627 | SendDestroyEvent(); |
2628 | ||
44cd54c2 JS |
2629 | if (g_focusWindow == this) |
2630 | g_focusWindow = NULL; | |
2631 | ||
e8c12a53 VS |
2632 | if (g_activeFrame == this) |
2633 | g_activeFrame = NULL; | |
2634 | ||
3e679f01 VZ |
2635 | if ( g_delayedFocus == this ) |
2636 | g_delayedFocus = NULL; | |
2637 | ||
31c6b4fc | 2638 | m_isBeingDeleted = TRUE; |
43a18898 | 2639 | m_hasVMT = FALSE; |
47d67540 | 2640 | |
f03fc89f VZ |
2641 | if (m_widget) |
2642 | Show( FALSE ); | |
8bbe427f | 2643 | |
a2053b27 RR |
2644 | DestroyChildren(); |
2645 | ||
f03fc89f VZ |
2646 | if (m_parent) |
2647 | m_parent->RemoveChild( this ); | |
c801d85f | 2648 | |
63081513 RR |
2649 | #ifdef HAVE_XIM |
2650 | if (m_ic) | |
2651 | gdk_ic_destroy (m_ic); | |
2652 | if (m_icattr) | |
2653 | gdk_ic_attr_destroy (m_icattr); | |
2654 | #endif | |
2655 | ||
f03fc89f | 2656 | if (m_widgetStyle) |
a2053b27 | 2657 | { |
a56fcaaf | 2658 | #if DISABLE_STYLE_IF_BROKEN_THEME |
bce1406b RR |
2659 | // don't delete if it's a pixmap theme style |
2660 | if (!m_widgetStyle->engine_data) | |
2661 | gtk_style_unref( m_widgetStyle ); | |
1e6feb95 | 2662 | #endif |
c50f1fb9 | 2663 | m_widgetStyle = (GtkStyle*) NULL; |
a2053b27 | 2664 | } |
c801d85f | 2665 | |
f03fc89f | 2666 | if (m_wxwindow) |
a2053b27 | 2667 | { |
f03fc89f | 2668 | gtk_widget_destroy( m_wxwindow ); |
c50f1fb9 | 2669 | m_wxwindow = (GtkWidget*) NULL; |
a2053b27 | 2670 | } |
8bbe427f | 2671 | |
f03fc89f | 2672 | if (m_widget) |
a2053b27 | 2673 | { |
f03fc89f | 2674 | gtk_widget_destroy( m_widget ); |
c50f1fb9 | 2675 | m_widget = (GtkWidget*) NULL; |
a2053b27 | 2676 | } |
362c6693 | 2677 | } |
c801d85f | 2678 | |
1e6feb95 | 2679 | bool wxWindowGTK::PreCreation( wxWindowGTK *parent, const wxPoint &pos, const wxSize &size ) |
c801d85f | 2680 | { |
223d09f6 | 2681 | wxCHECK_MSG( !m_needParent || parent, FALSE, wxT("Need complete parent.") ); |
8bbe427f | 2682 | |
3013a903 RR |
2683 | // This turns -1 into 30 so that a minimal window is |
2684 | // visible even although -1,-1 has been given as the | |
2685 | // size of the window. the same trick is used in other | |
2686 | // ports and should make debugging easier. | |
2687 | m_width = WidthDefault(size.x) ; | |
f03fc89f | 2688 | m_height = HeightDefault(size.y); |
8bbe427f | 2689 | |
43a18898 RR |
2690 | m_x = (int)pos.x; |
2691 | m_y = (int)pos.y; | |
8bbe427f | 2692 | |
3013a903 | 2693 | // some reasonable defaults |
148cd9b6 | 2694 | if (!parent) |
6ca41e57 | 2695 | { |
43a18898 RR |
2696 | if (m_x == -1) |
2697 | { | |
2698 | m_x = (gdk_screen_width () - m_width) / 2; | |
2699 | if (m_x < 10) m_x = 10; | |
2700 | } | |
2701 | if (m_y == -1) | |
2702 | { | |
2703 | m_y = (gdk_screen_height () - m_height) / 2; | |
2704 | if (m_y < 10) m_y = 10; | |
2705 | } | |
6ca41e57 | 2706 | } |
148cd9b6 | 2707 | |
4dcaf11a | 2708 | return TRUE; |
c801d85f KB |
2709 | } |
2710 | ||
1e6feb95 | 2711 | void wxWindowGTK::PostCreation() |
c801d85f | 2712 | { |
223d09f6 | 2713 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") ); |
94633ad9 | 2714 | |
43a18898 RR |
2715 | if (m_wxwindow) |
2716 | { | |
147bc491 | 2717 | if (!m_noExpose) |
b02da6b1 | 2718 | { |
76fcf0f2 | 2719 | // these get reported to wxWindows -> wxPaintEvent |
1e6feb95 | 2720 | |
b420fb6a RR |
2721 | gtk_pizza_set_external( GTK_PIZZA(m_wxwindow), TRUE ); |
2722 | ||
147bc491 RR |
2723 | gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event", |
2724 | GTK_SIGNAL_FUNC(gtk_window_expose_callback), (gpointer)this ); | |
2725 | ||
4e5a4c69 | 2726 | #ifndef __WXGTK20__ |
147bc491 RR |
2727 | gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw", |
2728 | GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this ); | |
0fc5dbf5 | 2729 | |
e22454be RR |
2730 | if (HasFlag(wxNO_FULL_REPAINT_ON_RESIZE)) |
2731 | { | |
2732 | gtk_signal_connect( GTK_OBJECT(m_wxwindow), "event", | |
2733 | GTK_SIGNAL_FUNC(gtk_window_event_event_callback), (gpointer)this ); | |
2734 | } | |
4e5a4c69 | 2735 | #else |
2b5f62a0 VZ |
2736 | // gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow), HasFlag( wxNO_FULL_REPAINT_ON_RESIZE ) ); |
2737 | #endif | |
2738 | ||
2739 | #ifdef __WXGTK20__ | |
2740 | // Create input method handler | |
2741 | m_imContext = (GtkIMMulticontext*) gtk_im_multicontext_new (); | |
2742 | ||
2743 | // Cannot handle drawing preedited text yet | |
2744 | gtk_im_context_set_use_preedit( (GtkIMContext*) m_imContext, FALSE ); | |
2745 | ||
2746 | g_signal_connect (G_OBJECT (m_imContext), "commit", | |
2747 | G_CALLBACK (gtk_wxwindow_commit_cb), this); | |
4e5a4c69 | 2748 | #endif |
b02da6b1 | 2749 | } |
148cd9b6 | 2750 | |
67d78217 | 2751 | // these are called when the "sunken" or "raised" borders are drawn |
034be888 RR |
2752 | gtk_signal_connect( GTK_OBJECT(m_widget), "expose_event", |
2753 | GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this ); | |
2754 | ||
4e5a4c69 | 2755 | #ifndef __WXGTK20__ |
034be888 RR |
2756 | gtk_signal_connect( GTK_OBJECT(m_widget), "draw", |
2757 | GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this ); | |
4e5a4c69 | 2758 | #endif |
43a18898 | 2759 | } |
47d67540 | 2760 | |
76fcf0f2 | 2761 | // focus handling |
63081513 | 2762 | |
76fcf0f2 RR |
2763 | if (m_focusWidget == NULL) |
2764 | m_focusWidget = m_widget; | |
2daa0ce9 | 2765 | |
76fcf0f2 RR |
2766 | gtk_signal_connect( GTK_OBJECT(m_focusWidget), "focus_in_event", |
2767 | GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this ); | |
2768 | ||
2769 | gtk_signal_connect( GTK_OBJECT(m_focusWidget), "focus_out_event", | |
2770 | GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this ); | |
2771 | ||
2772 | // connect to the various key and mouse handlers | |
63081513 | 2773 | |
a2053b27 | 2774 | GtkWidget *connect_widget = GetConnectWidget(); |
f03fc89f | 2775 | |
a2053b27 | 2776 | ConnectWidget( connect_widget ); |
47d67540 | 2777 | |
63081513 | 2778 | /* We cannot set colours, fonts and cursors before the widget has |
a2053b27 RR |
2779 | been realized, so we do this directly after realization */ |
2780 | gtk_signal_connect( GTK_OBJECT(connect_widget), "realize", | |
c50f1fb9 | 2781 | GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this ); |
2daa0ce9 | 2782 | |
63081513 RR |
2783 | if (m_wxwindow) |
2784 | { | |
47c93b63 | 2785 | // Catch native resize events |
8f75cb6c RR |
2786 | gtk_signal_connect( GTK_OBJECT(m_wxwindow), "size_allocate", |
2787 | GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this ); | |
2daa0ce9 | 2788 | |
47c93b63 | 2789 | // Initialize XIM support |
63081513 RR |
2790 | gtk_signal_connect( GTK_OBJECT(m_wxwindow), "realize", |
2791 | GTK_SIGNAL_FUNC(gtk_wxwindow_realized_callback), (gpointer) this ); | |
8f75cb6c | 2792 | |
47c93b63 | 2793 | // And resize XIM window |
b79395c5 RR |
2794 | gtk_signal_connect( GTK_OBJECT(m_wxwindow), "size_allocate", |
2795 | GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback), (gpointer)this ); | |
63081513 | 2796 | } |
2daa0ce9 | 2797 | |
47c93b63 RR |
2798 | if (!GTK_IS_COMBO(m_widget)) |
2799 | { | |
2800 | // This is needed if we want to add our windows into native | |
2801 | // GTK control, such as the toolbar. With this callback, the | |
2802 | // toolbar gets to know the correct size (the one set by the | |
2803 | // programmer). Sadly, it misbehaves for wxComboBox. FIXME | |
2804 | // when moving to GTK 2.0. | |
2805 | gtk_signal_connect( GTK_OBJECT(m_widget), "size_request", | |
2806 | GTK_SIGNAL_FUNC(gtk_window_size_request_callback), (gpointer) this ); | |
2807 | } | |
1e6feb95 | 2808 | |
43a18898 | 2809 | m_hasVMT = TRUE; |
b4071e91 RR |
2810 | } |
2811 | ||
1e6feb95 | 2812 | void wxWindowGTK::ConnectWidget( GtkWidget *widget ) |
b4071e91 | 2813 | { |
43a18898 RR |
2814 | gtk_signal_connect( GTK_OBJECT(widget), "key_press_event", |
2815 | GTK_SIGNAL_FUNC(gtk_window_key_press_callback), (gpointer)this ); | |
c801d85f | 2816 | |
b666df2c RR |
2817 | gtk_signal_connect( GTK_OBJECT(widget), "key_release_event", |
2818 | GTK_SIGNAL_FUNC(gtk_window_key_release_callback), (gpointer)this ); | |
2819 | ||
43a18898 RR |
2820 | gtk_signal_connect( GTK_OBJECT(widget), "button_press_event", |
2821 | GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this ); | |
47d67540 | 2822 | |
43a18898 RR |
2823 | gtk_signal_connect( GTK_OBJECT(widget), "button_release_event", |
2824 | GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this ); | |
47d67540 | 2825 | |
43a18898 RR |
2826 | gtk_signal_connect( GTK_OBJECT(widget), "motion_notify_event", |
2827 | GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this ); | |
47d67540 | 2828 | |
43a18898 RR |
2829 | gtk_signal_connect( GTK_OBJECT(widget), "enter_notify_event", |
2830 | GTK_SIGNAL_FUNC(gtk_window_enter_callback), (gpointer)this ); | |
47d67540 | 2831 | |
43a18898 RR |
2832 | gtk_signal_connect( GTK_OBJECT(widget), "leave_notify_event", |
2833 | GTK_SIGNAL_FUNC(gtk_window_leave_callback), (gpointer)this ); | |
362c6693 | 2834 | } |
c801d85f | 2835 | |
1e6feb95 | 2836 | bool wxWindowGTK::Destroy() |
c801d85f | 2837 | { |
223d09f6 | 2838 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 2839 | |
43a18898 | 2840 | m_hasVMT = FALSE; |
c801d85f | 2841 | |
f03fc89f | 2842 | return wxWindowBase::Destroy(); |
362c6693 | 2843 | } |
c801d85f | 2844 | |
1e6feb95 | 2845 | void wxWindowGTK::DoMoveWindow(int x, int y, int width, int height) |
23efdd02 RR |
2846 | { |
2847 | gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), m_widget, x, y, width, height ); | |
2848 | } | |
2daa0ce9 | 2849 | |
1e6feb95 | 2850 | void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags ) |
c801d85f | 2851 | { |
223d09f6 | 2852 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") ); |
1e6feb95 | 2853 | wxASSERT_MSG( (m_parent != NULL), wxT("wxWindowGTK::SetSize requires parent.\n") ); |
8bbe427f | 2854 | |
33611ebb | 2855 | /* |
f94fca1b | 2856 | printf( "DoSetSize: name %s, x,y,w,h: %d,%d,%d,%d \n", GetName().c_str(), x,y,width,height ); |
33611ebb RR |
2857 | */ |
2858 | ||
e27ce4e9 | 2859 | if (m_resizing) return; /* I don't like recursions */ |
fb1585ae | 2860 | m_resizing = TRUE; |
1e6feb95 | 2861 | |
b9f29261 VS |
2862 | int currentX, currentY; |
2863 | GetPosition(¤tX, ¤tY); | |
2864 | if (x == -1) | |
2865 | x = currentX; | |
a200c35e | 2866 | if (y == -1) |
b9f29261 | 2867 | y = currentY; |
a200c35e VS |
2868 | AdjustForParentClientOrigin(x, y, sizeFlags); |
2869 | ||
a2053b27 | 2870 | if (m_parent->m_wxwindow == NULL) /* i.e. wxNotebook */ |
fb1585ae | 2871 | { |
e27ce4e9 | 2872 | /* don't set the size for children of wxNotebook, just take the values. */ |
fb1585ae RR |
2873 | m_x = x; |
2874 | m_y = y; | |
2875 | m_width = width; | |
ba4e3652 | 2876 | m_height = height; |
fb1585ae | 2877 | } |
ba4e3652 | 2878 | else |
fb1585ae | 2879 | { |
da048e3d | 2880 | GtkPizza *pizza = GTK_PIZZA(m_parent->m_wxwindow); |
85ad5eb5 | 2881 | if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0) |
ba4e3652 | 2882 | { |
da048e3d RR |
2883 | if (x != -1) m_x = x + pizza->xoffset; |
2884 | if (y != -1) m_y = y + pizza->yoffset; | |
ba4e3652 RR |
2885 | } |
2886 | else | |
2887 | { | |
da048e3d RR |
2888 | m_x = x + pizza->xoffset; |
2889 | m_y = y + pizza->yoffset; | |
ba4e3652 | 2890 | } |
d44c23ce RR |
2891 | if (width != -1) m_width = width; |
2892 | if (height != -1) m_height = height; | |
47d67540 | 2893 | |
ba4e3652 RR |
2894 | if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) |
2895 | { | |
2896 | if (width == -1) m_width = 80; | |
2897 | } | |
2898 | ||
2899 | if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) | |
2900 | { | |
2901 | if (height == -1) m_height = 26; | |
2902 | } | |
8bbe427f | 2903 | |
e7dda1ff VS |
2904 | int minWidth = GetMinWidth(), |
2905 | minHeight = GetMinHeight(), | |
2906 | maxWidth = GetMaxWidth(), | |
2907 | maxHeight = GetMaxHeight(); | |
2908 | ||
2909 | if ((minWidth != -1) && (m_width < minWidth)) m_width = minWidth; | |
2910 | if ((minHeight != -1) && (m_height < minHeight)) m_height = minHeight; | |
2911 | if ((maxWidth != -1) && (m_width > maxWidth)) m_width = maxWidth; | |
2912 | if ((maxHeight != -1) && (m_height > maxHeight)) m_height = maxHeight; | |
47d67540 | 2913 | |
a2053b27 | 2914 | int border = 0; |
c50f1fb9 | 2915 | int bottom_border = 0; |
f03fc89f | 2916 | |
eb9e6a00 | 2917 | #ifndef __WXGTK20__ |
29f538ce | 2918 | if (GTK_WIDGET_CAN_DEFAULT(m_widget)) |
c50f1fb9 VZ |
2919 | { |
2920 | /* the default button has a border around it */ | |
2921 | border = 6; | |
2922 | bottom_border = 5; | |
2923 | } | |
67d78217 | 2924 | #endif |
c50f1fb9 | 2925 | |
23efdd02 RR |
2926 | DoMoveWindow( m_x-border, |
2927 | m_y-border, | |
2928 | m_width+2*border, | |
2929 | m_height+border+bottom_border ); | |
54517652 | 2930 | } |
148cd9b6 | 2931 | |
5b8a521e RR |
2932 | if (m_hasScrolling) |
2933 | { | |
1e6feb95 | 2934 | /* Sometimes the client area changes size without the |
b6fa52db RR |
2935 | whole windows's size changing, but if the whole |
2936 | windows's size doesn't change, no wxSizeEvent will | |
2937 | normally be sent. Here we add an extra test if | |
2938 | the client test has been changed and this will | |
2939 | be used then. */ | |
5b8a521e RR |
2940 | GetClientSize( &m_oldClientWidth, &m_oldClientHeight ); |
2941 | } | |
2942 | ||
54517652 | 2943 | /* |
6d693bb4 RR |
2944 | wxPrintf( "OnSize sent from " ); |
2945 | if (GetClassInfo() && GetClassInfo()->GetClassName()) | |
2946 | wxPrintf( GetClassInfo()->GetClassName() ); | |
2947 | wxPrintf( " %d %d %d %d\n", (int)m_x, (int)m_y, (int)m_width, (int)m_height ); | |
2948 | */ | |
2949 | ||
30760ce7 RR |
2950 | if (!m_nativeSizeEvent) |
2951 | { | |
2952 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); | |
2953 | event.SetEventObject( this ); | |
2954 | GetEventHandler()->ProcessEvent( event ); | |
2955 | } | |
6d693bb4 | 2956 | |
fb1585ae | 2957 | m_resizing = FALSE; |
362c6693 | 2958 | } |
c801d85f | 2959 | |
1e6feb95 | 2960 | void wxWindowGTK::OnInternalIdle() |
9390a202 | 2961 | { |
beab25bd | 2962 | // Update invalidated regions. |
010afced | 2963 | GtkUpdate(); |
0fc5dbf5 | 2964 | |
beab25bd | 2965 | // Synthetize activate events. |
148cd9b6 VZ |
2966 | if ( g_sendActivateEvent != -1 ) |
2967 | { | |
2968 | bool activate = g_sendActivateEvent != 0; | |
2969 | ||
2970 | // do it only once | |
2971 | g_sendActivateEvent = -1; | |
2972 | ||
1e6feb95 | 2973 | wxTheApp->SetActive(activate, (wxWindow *)g_focusWindowLast); |
148cd9b6 VZ |
2974 | } |
2975 | ||
e8c12a53 VS |
2976 | if ( g_activeFrameLostFocus ) |
2977 | { | |
2978 | if ( g_activeFrame ) | |
2979 | { | |
45eb5249 | 2980 | wxLogTrace(wxT("activate"), wxT("Deactivating frame %p (from idle)"), g_activeFrame); |
e8c12a53 VS |
2981 | wxActivateEvent event(wxEVT_ACTIVATE, FALSE, g_activeFrame->GetId()); |
2982 | event.SetEventObject(g_activeFrame); | |
2983 | g_activeFrame->GetEventHandler()->ProcessEvent(event); | |
2984 | g_activeFrame = NULL; | |
2985 | } | |
2986 | g_activeFrameLostFocus = FALSE; | |
2987 | } | |
2b5f62a0 | 2988 | |
9146082c RR |
2989 | wxCursor cursor = m_cursor; |
2990 | if (g_globalCursor.Ok()) cursor = g_globalCursor; | |
c50f1fb9 | 2991 | |
f7a11f8c | 2992 | if (cursor.Ok()) |
9146082c | 2993 | { |
3017f78d | 2994 | /* I now set the cursor anew in every OnInternalIdle call |
b02da6b1 VZ |
2995 | as setting the cursor in a parent window also effects the |
2996 | windows above so that checking for the current cursor is | |
2997 | not possible. */ | |
148cd9b6 | 2998 | |
9146082c | 2999 | if (m_wxwindow) |
6a008b33 | 3000 | { |
da048e3d | 3001 | GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window; |
6a008b33 | 3002 | if (window) |
c50f1fb9 | 3003 | gdk_window_set_cursor( window, cursor.GetCursor() ); |
6a008b33 VZ |
3004 | |
3005 | if (!g_globalCursor.Ok()) | |
3006 | cursor = *wxSTANDARD_CURSOR; | |
3007 | ||
3008 | window = m_widget->window; | |
5e014a0c | 3009 | if ((window) && !(GTK_WIDGET_NO_WINDOW(m_widget))) |
9146082c | 3010 | gdk_window_set_cursor( window, cursor.GetCursor() ); |
5e014a0c | 3011 | |
6a008b33 VZ |
3012 | } |
3013 | else | |
3014 | { | |
5e014a0c | 3015 | |
9146082c | 3016 | GdkWindow *window = m_widget->window; |
5e014a0c | 3017 | if ((window) && !(GTK_WIDGET_NO_WINDOW(m_widget))) |
9146082c | 3018 | gdk_window_set_cursor( window, cursor.GetCursor() ); |
5e014a0c | 3019 | |
6a008b33 | 3020 | } |
9146082c | 3021 | } |
6a008b33 | 3022 | |
9390a202 RR |
3023 | UpdateWindowUI(); |
3024 | } | |
3025 | ||
1e6feb95 | 3026 | void wxWindowGTK::DoGetSize( int *width, int *height ) const |
c801d85f | 3027 | { |
223d09f6 | 3028 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 3029 | |
fb1585ae RR |
3030 | if (width) (*width) = m_width; |
3031 | if (height) (*height) = m_height; | |
362c6693 | 3032 | } |
c801d85f | 3033 | |
1e6feb95 | 3034 | void wxWindowGTK::DoSetClientSize( int width, int height ) |
c801d85f | 3035 | { |
223d09f6 | 3036 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 3037 | |
1ecc4d80 | 3038 | if (!m_wxwindow) |
c801d85f | 3039 | { |
1ecc4d80 | 3040 | SetSize( width, height ); |
c801d85f KB |
3041 | } |
3042 | else | |
3043 | { | |
1ecc4d80 RR |
3044 | int dw = 0; |
3045 | int dh = 0; | |
3046 | ||
1e6feb95 | 3047 | #ifndef __WXUNIVERSAL__ |
98d3fdbe RR |
3048 | if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER)) |
3049 | { | |
5e014a0c | 3050 | /* when using GTK 1.2 we set the shadow border size to 2 */ |
6a008b33 | 3051 | dw += 2 * 2; |
98d3fdbe RR |
3052 | dh += 2 * 2; |
3053 | } | |
5e014a0c RR |
3054 | if (HasFlag(wxSIMPLE_BORDER)) |
3055 | { | |
3056 | /* when using GTK 1.2 we set the simple border size to 1 */ | |
3057 | dw += 1 * 2; | |
3058 | dh += 1 * 2; | |
3059 | } | |
1e6feb95 | 3060 | #endif // __WXUNIVERSAL__ |
034be888 | 3061 | |
5b8a521e | 3062 | if (m_hasScrolling) |
98d3fdbe | 3063 | { |
324dbfec | 3064 | GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget); |
2daa0ce9 | 3065 | |
9000c624 RR |
3066 | GtkRequisition vscroll_req; |
3067 | vscroll_req.width = 2; | |
3068 | vscroll_req.height = 2; | |
dd00f3f6 | 3069 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window->vscrollbar) )->size_request ) |
9000c624 | 3070 | (scroll_window->vscrollbar, &vscroll_req ); |
2daa0ce9 | 3071 | |
9000c624 RR |
3072 | GtkRequisition hscroll_req; |
3073 | hscroll_req.width = 2; | |
3074 | hscroll_req.height = 2; | |
dd00f3f6 | 3075 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window->hscrollbar) )->size_request ) |
9000c624 RR |
3076 | (scroll_window->hscrollbar, &hscroll_req ); |
3077 | ||
dd00f3f6 | 3078 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget) ); |
324dbfec | 3079 | |
1ecc4d80 RR |
3080 | if (scroll_window->vscrollbar_visible) |
3081 | { | |
9000c624 | 3082 | dw += vscroll_req.width; |
1ecc4d80 RR |
3083 | dw += scroll_class->scrollbar_spacing; |
3084 | } | |
3085 | ||
3086 | if (scroll_window->hscrollbar_visible) | |
3087 | { | |
9000c624 | 3088 | dh += hscroll_req.height; |
63cc5d9d | 3089 | dh += scroll_class->scrollbar_spacing; |
1ecc4d80 | 3090 | } |
9000c624 | 3091 | } |
1ecc4d80 | 3092 | |
034be888 | 3093 | SetSize( width+dw, height+dh ); |
1ecc4d80 | 3094 | } |
362c6693 | 3095 | } |
c801d85f | 3096 | |
1e6feb95 | 3097 | void wxWindowGTK::DoGetClientSize( int *width, int *height ) const |
c801d85f | 3098 | { |
223d09f6 | 3099 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 3100 | |
1ecc4d80 RR |
3101 | if (!m_wxwindow) |
3102 | { | |
3103 | if (width) (*width) = m_width; | |
3104 | if (height) (*height) = m_height; | |
c801d85f KB |
3105 | } |
3106 | else | |
3107 | { | |
1ecc4d80 RR |
3108 | int dw = 0; |
3109 | int dh = 0; | |
3110 | ||
1e6feb95 | 3111 | #ifndef __WXUNIVERSAL__ |
98d3fdbe RR |
3112 | if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER)) |
3113 | { | |
5e014a0c | 3114 | /* when using GTK 1.2 we set the shadow border size to 2 */ |
6a008b33 | 3115 | dw += 2 * 2; |
98d3fdbe RR |
3116 | dh += 2 * 2; |
3117 | } | |
5e014a0c RR |
3118 | if (HasFlag(wxSIMPLE_BORDER)) |
3119 | { | |
3120 | /* when using GTK 1.2 we set the simple border size to 1 */ | |
3121 | dw += 1 * 2; | |
3122 | dh += 1 * 2; | |
3123 | } | |
1e6feb95 | 3124 | #endif // __WXUNIVERSAL__ |
9000c624 | 3125 | |
5b8a521e | 3126 | if (m_hasScrolling) |
98d3fdbe | 3127 | { |
6a008b33 | 3128 | GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget); |
2daa0ce9 | 3129 | |
9000c624 RR |
3130 | GtkRequisition vscroll_req; |
3131 | vscroll_req.width = 2; | |
3132 | vscroll_req.height = 2; | |
dd00f3f6 | 3133 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window->vscrollbar) )->size_request ) |
9000c624 | 3134 | (scroll_window->vscrollbar, &vscroll_req ); |
2daa0ce9 | 3135 | |
9000c624 RR |
3136 | GtkRequisition hscroll_req; |
3137 | hscroll_req.width = 2; | |
3138 | hscroll_req.height = 2; | |
dd00f3f6 | 3139 | (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(scroll_window->hscrollbar) )->size_request ) |
9000c624 RR |
3140 | (scroll_window->hscrollbar, &hscroll_req ); |
3141 | ||
dd00f3f6 | 3142 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget) ); |
6a008b33 | 3143 | |
1ecc4d80 RR |
3144 | if (scroll_window->vscrollbar_visible) |
3145 | { | |
9000c624 | 3146 | dw += vscroll_req.width; |
1ecc4d80 RR |
3147 | dw += scroll_class->scrollbar_spacing; |
3148 | } | |
3149 | ||
3150 | if (scroll_window->hscrollbar_visible) | |
3151 | { | |
9000c624 | 3152 | dh += hscroll_req.height; |
1ecc4d80 RR |
3153 | dh += scroll_class->scrollbar_spacing; |
3154 | } | |
6a008b33 | 3155 | } |
47d67540 | 3156 | |
1ecc4d80 RR |
3157 | if (width) (*width) = m_width - dw; |
3158 | if (height) (*height) = m_height - dh; | |
3159 | } | |
1e6feb95 | 3160 | |
f94fca1b RR |
3161 | /* |
3162 | printf( "GetClientSize, name %s ", GetName().c_str() ); | |
3163 | if (width) printf( " width = %d", (*width) ); | |
3164 | if (height) printf( " height = %d", (*height) ); | |
3165 | printf( "\n" ); | |
3166 | */ | |
362c6693 | 3167 | } |
c801d85f | 3168 | |
1e6feb95 | 3169 | void wxWindowGTK::DoGetPosition( int *x, int *y ) const |
c801d85f | 3170 | { |
223d09f6 | 3171 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 3172 | |
bf0c00c6 RR |
3173 | int dx = 0; |
3174 | int dy = 0; | |
3175 | if (m_parent && m_parent->m_wxwindow) | |
3176 | { | |
da048e3d | 3177 | GtkPizza *pizza = GTK_PIZZA(m_parent->m_wxwindow); |
b02da6b1 VZ |
3178 | dx = pizza->xoffset; |
3179 | dy = pizza->yoffset; | |
bf0c00c6 | 3180 | } |
94633ad9 | 3181 | |
496beb3f VS |
3182 | if (x) (*x) = m_x - dx; |
3183 | if (y) (*y) = m_y - dy; | |
362c6693 | 3184 | } |
c801d85f | 3185 | |
1e6feb95 | 3186 | void wxWindowGTK::DoClientToScreen( int *x, int *y ) const |
c801d85f | 3187 | { |
223d09f6 | 3188 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 3189 | |
a2053b27 RR |
3190 | if (!m_widget->window) return; |
3191 | ||
43a18898 RR |
3192 | GdkWindow *source = (GdkWindow *) NULL; |
3193 | if (m_wxwindow) | |
da048e3d | 3194 | source = GTK_PIZZA(m_wxwindow)->bin_window; |
43a18898 RR |
3195 | else |
3196 | source = m_widget->window; | |
47d67540 | 3197 | |
43a18898 RR |
3198 | int org_x = 0; |
3199 | int org_y = 0; | |
3200 | gdk_window_get_origin( source, &org_x, &org_y ); | |
c801d85f | 3201 | |
43a18898 | 3202 | if (!m_wxwindow) |
c801d85f | 3203 | { |
43a18898 RR |
3204 | if (GTK_WIDGET_NO_WINDOW (m_widget)) |
3205 | { | |
3206 | org_x += m_widget->allocation.x; | |
3207 | org_y += m_widget->allocation.y; | |
3208 | } | |
362c6693 | 3209 | } |
47d67540 | 3210 | |
43a18898 RR |
3211 | if (x) *x += org_x; |
3212 | if (y) *y += org_y; | |
362c6693 | 3213 | } |
c801d85f | 3214 | |
1e6feb95 | 3215 | void wxWindowGTK::DoScreenToClient( int *x, int *y ) const |
c801d85f | 3216 | { |
223d09f6 | 3217 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 3218 | |
a2053b27 RR |
3219 | if (!m_widget->window) return; |
3220 | ||
1ecc4d80 RR |
3221 | GdkWindow *source = (GdkWindow *) NULL; |
3222 | if (m_wxwindow) | |
da048e3d | 3223 | source = GTK_PIZZA(m_wxwindow)->bin_window; |
1ecc4d80 RR |
3224 | else |
3225 | source = m_widget->window; | |
47d67540 | 3226 | |
1ecc4d80 RR |
3227 | int org_x = 0; |
3228 | int org_y = 0; | |
3229 | gdk_window_get_origin( source, &org_x, &org_y ); | |
c801d85f | 3230 | |
1ecc4d80 | 3231 | if (!m_wxwindow) |
c801d85f | 3232 | { |
1ecc4d80 RR |
3233 | if (GTK_WIDGET_NO_WINDOW (m_widget)) |
3234 | { | |
3235 | org_x += m_widget->allocation.x; | |
3236 | org_y += m_widget->allocation.y; | |
3237 | } | |
362c6693 | 3238 | } |
47d67540 | 3239 | |
1ecc4d80 RR |
3240 | if (x) *x -= org_x; |
3241 | if (y) *y -= org_y; | |
362c6693 | 3242 | } |
c801d85f | 3243 | |
1e6feb95 | 3244 | bool wxWindowGTK::Show( bool show ) |
c801d85f | 3245 | { |
223d09f6 | 3246 | wxCHECK_MSG( (m_widget != NULL), FALSE, wxT("invalid window") ); |
47d67540 | 3247 | |
739730ca RR |
3248 | if (!wxWindowBase::Show(show)) |
3249 | { | |
3250 | // nothing to do | |
f03fc89f | 3251 | return FALSE; |
739730ca | 3252 | } |
8bbe427f | 3253 | |
f03fc89f VZ |
3254 | if (show) |
3255 | gtk_widget_show( m_widget ); | |
1ecc4d80 | 3256 | else |
f03fc89f | 3257 | gtk_widget_hide( m_widget ); |
8bbe427f | 3258 | |
2b5f62a0 VZ |
3259 | wxShowEvent eventShow(GetId(), show); |
3260 | eventShow.m_eventObject = this; | |
3261 | ||
3262 | GetEventHandler()->ProcessEvent(eventShow); | |
3263 | ||
f03fc89f | 3264 | return TRUE; |
362c6693 | 3265 | } |
c801d85f | 3266 | |
3379ed37 | 3267 | static void wxWindowNotifyEnable(wxWindowGTK* win, bool enable) |
fdca68a6 JS |
3268 | { |
3269 | win->OnParentEnable(enable); | |
3270 | ||
3271 | // Recurse, so that children have the opportunity to Do The Right Thing | |
3272 | // and reset colours that have been messed up by a parent's (really ancestor's) | |
3273 | // Enable call | |
3274 | for ( wxWindowList::Node *node = win->GetChildren().GetFirst(); | |
3275 | node; | |
3276 | node = node->GetNext() ) | |
3277 | { | |
3278 | wxWindow *child = node->GetData(); | |
3279 | if (!child->IsKindOf(CLASSINFO(wxDialog)) && !child->IsKindOf(CLASSINFO(wxFrame))) | |
3280 | wxWindowNotifyEnable(child, enable); | |
3281 | } | |
3282 | } | |
3283 | ||
3379ed37 | 3284 | bool wxWindowGTK::Enable( bool enable ) |
c801d85f | 3285 | { |
223d09f6 | 3286 | wxCHECK_MSG( (m_widget != NULL), FALSE, wxT("invalid window") ); |
5e0aa05a | 3287 | |
739730ca RR |
3288 | if (!wxWindowBase::Enable(enable)) |
3289 | { | |
3290 | // nothing to do | |
f03fc89f | 3291 | return FALSE; |
739730ca | 3292 | } |
1ecc4d80 | 3293 | |
f03fc89f VZ |
3294 | gtk_widget_set_sensitive( m_widget, enable ); |
3295 | if ( m_wxwindow ) | |
3296 | gtk_widget_set_sensitive( m_wxwindow, enable ); | |
ff8bfdbb | 3297 | |
fdca68a6 | 3298 | wxWindowNotifyEnable(this, enable); |
513903c4 | 3299 | |
f03fc89f | 3300 | return TRUE; |
362c6693 | 3301 | } |
c801d85f | 3302 | |
1e6feb95 | 3303 | int wxWindowGTK::GetCharHeight() const |
2f2aa628 | 3304 | { |
223d09f6 | 3305 | wxCHECK_MSG( (m_widget != NULL), 12, wxT("invalid window") ); |
47d67540 | 3306 | |
223d09f6 | 3307 | wxCHECK_MSG( m_font.Ok(), 12, wxT("invalid font") ); |
2f2aa628 | 3308 | |
bbd006c0 RR |
3309 | #ifdef __WXGTK20__ |
3310 | PangoContext *context = NULL; | |
3311 | if (m_widget) | |
3312 | context = gtk_widget_get_pango_context( m_widget ); | |
3313 | ||
3314 | if (!context) | |
3315 | return 0; | |
3316 | ||
3317 | PangoFontDescription *desc = m_font.GetNativeFontInfo()->description; | |
3318 | PangoLayout *layout = pango_layout_new(context); | |
3319 | pango_layout_set_font_description(layout, desc); | |
3320 | pango_layout_set_text(layout, "H", 1); | |
3321 | PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data; | |
3322 | ||
3323 | PangoRectangle rect; | |
3324 | pango_layout_line_get_extents(line, NULL, &rect); | |
3325 | ||
3326 | g_object_unref( G_OBJECT( layout ) ); | |
7de59551 | 3327 | |
bbd006c0 RR |
3328 | return (int) (rect.height / PANGO_SCALE); |
3329 | #else | |
f03fc89f VZ |
3330 | GdkFont *font = m_font.GetInternalFont( 1.0 ); |
3331 | ||
3332 | return font->ascent + font->descent; | |
bbd006c0 | 3333 | #endif |
362c6693 | 3334 | } |
c801d85f | 3335 | |
1e6feb95 | 3336 | int wxWindowGTK::GetCharWidth() const |
c33c4050 | 3337 | { |
223d09f6 | 3338 | wxCHECK_MSG( (m_widget != NULL), 8, wxT("invalid window") ); |
47d67540 | 3339 | |
223d09f6 | 3340 | wxCHECK_MSG( m_font.Ok(), 8, wxT("invalid font") ); |
47d67540 | 3341 | |
bbd006c0 RR |
3342 | #ifdef __WXGTK20__ |
3343 | PangoContext *context = NULL; | |
3344 | if (m_widget) | |
3345 | context = gtk_widget_get_pango_context( m_widget ); | |
3346 | ||
3347 | if (!context) | |
3348 | return 0; | |
3349 | ||
3350 | PangoFontDescription *desc = m_font.GetNativeFontInfo()->description; | |
3351 | PangoLayout *layout = pango_layout_new(context); | |
3352 | pango_layout_set_font_description(layout, desc); | |
3353 | pango_layout_set_text(layout, "H", 1); | |
3354 | PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data; | |
3355 | ||
3356 | PangoRectangle rect; | |
3357 | pango_layout_line_get_extents(line, NULL, &rect); | |
3358 | ||
3359 | g_object_unref( G_OBJECT( layout ) ); | |
7de59551 | 3360 | |
bbd006c0 RR |
3361 | return (int) (rect.width / PANGO_SCALE); |
3362 | #else | |
463c1fa1 | 3363 | GdkFont *font = m_font.GetInternalFont( 1.0 ); |
ff8bfdbb | 3364 | |
463c1fa1 | 3365 | return gdk_string_width( font, "H" ); |
bbd006c0 | 3366 | #endif |
c33c4050 RR |
3367 | } |
3368 | ||
1e6feb95 | 3369 | void wxWindowGTK::GetTextExtent( const wxString& string, |
f03fc89f VZ |
3370 | int *x, |
3371 | int *y, | |
3372 | int *descent, | |
3373 | int *externalLeading, | |
3374 | const wxFont *theFont ) const | |
c33c4050 | 3375 | { |
463c1fa1 RR |
3376 | wxFont fontToUse = m_font; |
3377 | if (theFont) fontToUse = *theFont; | |
47d67540 | 3378 | |
223d09f6 | 3379 | wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") ); |
2b5f62a0 | 3380 | |
48d011c8 RR |
3381 | if (string.IsEmpty()) |
3382 | { | |
b15ed747 RR |
3383 | if (x) (*x) = 0; |
3384 | if (y) (*y) = 0; | |
48d011c8 RR |
3385 | return; |
3386 | } | |
47d67540 | 3387 | |
2b5f62a0 | 3388 | #ifdef __WXGTK20__ |
48d011c8 RR |
3389 | PangoContext *context = NULL; |
3390 | if (m_widget) | |
2b5f62a0 VZ |
3391 | context = gtk_widget_get_pango_context( m_widget ); |
3392 | ||
48d011c8 RR |
3393 | if (!context) |
3394 | { | |
b15ed747 RR |
3395 | if (x) (*x) = 0; |
3396 | if (y) (*y) = 0; | |
48d011c8 RR |
3397 | return; |
3398 | } | |
2b5f62a0 | 3399 | |
48d011c8 RR |
3400 | PangoFontDescription *desc = fontToUse.GetNativeFontInfo()->description; |
3401 | PangoLayout *layout = pango_layout_new(context); | |
3402 | pango_layout_set_font_description(layout, desc); | |
3403 | { | |
fb3ed106 | 3404 | #if wxUSE_UNICODE |
48d011c8 RR |
3405 | const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); |
3406 | pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); | |
fb3ed106 RR |
3407 | #else |
3408 | const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string ); | |
3409 | const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); | |
3410 | pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); | |
3411 | #endif | |
48d011c8 RR |
3412 | } |
3413 | PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data; | |
2b5f62a0 | 3414 | |
48d011c8 RR |
3415 | PangoRectangle rect; |
3416 | pango_layout_line_get_extents(line, NULL, &rect); | |
2b5f62a0 | 3417 | |
b15ed747 RR |
3418 | if (x) (*x) = (wxCoord) (rect.width / PANGO_SCALE); |
3419 | if (y) (*y) = (wxCoord) (rect.height / PANGO_SCALE); | |
48d011c8 RR |
3420 | if (descent) |
3421 | { | |
3422 | // Do something about metrics here | |
3423 | (*descent) = 0; | |
3424 | } | |
3425 | if (externalLeading) (*externalLeading) = 0; // ?? | |
2b5f62a0 | 3426 | |
48d011c8 RR |
3427 | g_object_unref( G_OBJECT( layout ) ); |
3428 | #else | |
463c1fa1 | 3429 | GdkFont *font = fontToUse.GetInternalFont( 1.0 ); |
fab591c5 | 3430 | if (x) (*x) = gdk_string_width( font, wxGTK_CONV( string ) ); |
463c1fa1 RR |
3431 | if (y) (*y) = font->ascent + font->descent; |
3432 | if (descent) (*descent) = font->descent; | |
3433 | if (externalLeading) (*externalLeading) = 0; // ?? | |
48d011c8 | 3434 | #endif |
c33c4050 RR |
3435 | } |
3436 | ||
1e6feb95 | 3437 | void wxWindowGTK::SetFocus() |
c801d85f | 3438 | { |
6cad4f1b VZ |
3439 | wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); |
3440 | ||
3441 | if ( m_hasFocus ) | |
3442 | { | |
3443 | // don't do anything if we already have focus | |
3444 | return; | |
3445 | } | |
2daa0ce9 | 3446 | |
354aa1e3 RR |
3447 | if (m_wxwindow) |
3448 | { | |
173348db | 3449 | if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow)) |
b231914f | 3450 | { |
173348db | 3451 | gtk_widget_grab_focus (m_wxwindow); |
b231914f | 3452 | } |
354aa1e3 | 3453 | } |
b231914f | 3454 | else if (m_widget) |
c801d85f | 3455 | { |
173348db | 3456 | if (GTK_WIDGET_CAN_FOCUS(m_widget) && !GTK_WIDGET_HAS_FOCUS (m_widget) ) |
463c1fa1 | 3457 | { |
d7fa7eaa | 3458 | if (!GTK_WIDGET_REALIZED(m_widget)) |
6aeb6f2a | 3459 | { |
6cad4f1b VZ |
3460 | // we can't set the focus to the widget now so we remember that |
3461 | // it should be focused and will do it later, during the idle | |
3462 | // time, as soon as we can | |
3463 | wxLogTrace(TRACE_FOCUS, | |
3464 | _T("Delaying setting focus to %s(%s)"), | |
6aeb6f2a VZ |
3465 | GetClassInfo()->GetClassName(), GetLabel().c_str()); |
3466 | ||
d7fa7eaa | 3467 | g_delayedFocus = this; |
6aeb6f2a | 3468 | } |
d7fa7eaa | 3469 | else |
6aeb6f2a | 3470 | { |
6cad4f1b VZ |
3471 | wxLogTrace(TRACE_FOCUS, |
3472 | _T("Setting focus to %s(%s)"), | |
6aeb6f2a VZ |
3473 | GetClassInfo()->GetClassName(), GetLabel().c_str()); |
3474 | ||
d7fa7eaa | 3475 | gtk_widget_grab_focus (m_widget); |
6aeb6f2a | 3476 | } |
463c1fa1 | 3477 | } |
354aa1e3 | 3478 | else if (GTK_IS_CONTAINER(m_widget)) |
ff8bfdbb | 3479 | { |
9e691f46 | 3480 | SET_CONTAINER_FOCUS( m_widget, GTK_DIR_TAB_FORWARD ); |
ff8bfdbb VZ |
3481 | } |
3482 | else | |
3483 | { | |
6cad4f1b VZ |
3484 | wxLogTrace(TRACE_FOCUS, |
3485 | _T("Can't set focus to %s(%s)"), | |
3486 | GetClassInfo()->GetClassName(), GetLabel().c_str()); | |
ff8bfdbb | 3487 | } |
362c6693 | 3488 | } |
362c6693 | 3489 | } |
c801d85f | 3490 | |
1e6feb95 | 3491 | bool wxWindowGTK::AcceptsFocus() const |
b292e2f5 | 3492 | { |
f03fc89f | 3493 | return m_acceptsFocus && wxWindowBase::AcceptsFocus(); |
b292e2f5 RR |
3494 | } |
3495 | ||
1e6feb95 | 3496 | bool wxWindowGTK::Reparent( wxWindowBase *newParentBase ) |
463c1fa1 | 3497 | { |
223d09f6 | 3498 | wxCHECK_MSG( (m_widget != NULL), FALSE, wxT("invalid window") ); |
c50f1fb9 | 3499 | |
1e6feb95 VZ |
3500 | wxWindowGTK *oldParent = m_parent, |
3501 | *newParent = (wxWindowGTK *)newParentBase; | |
a2053b27 | 3502 | |
5fd11f09 RR |
3503 | wxASSERT( GTK_IS_WIDGET(m_widget) ); |
3504 | ||
f03fc89f VZ |
3505 | if ( !wxWindowBase::Reparent(newParent) ) |
3506 | return FALSE; | |
8bbe427f | 3507 | |
5fd11f09 RR |
3508 | wxASSERT( GTK_IS_WIDGET(m_widget) ); |
3509 | ||
3510 | /* prevent GTK from deleting the widget arbitrarily */ | |
3511 | gtk_widget_ref( m_widget ); | |
3512 | ||
8ce63e9d RR |
3513 | if (oldParent) |
3514 | { | |
3017f78d | 3515 | gtk_container_remove( GTK_CONTAINER(m_widget->parent), m_widget ); |
8ce63e9d | 3516 | } |
c50f1fb9 | 3517 | |
5fd11f09 RR |
3518 | wxASSERT( GTK_IS_WIDGET(m_widget) ); |
3519 | ||
8ce63e9d RR |
3520 | if (newParent) |
3521 | { | |
3522 | /* insert GTK representation */ | |
3523 | (*(newParent->m_insertCallback))(newParent, this); | |
3524 | } | |
c50f1fb9 | 3525 | |
5fd11f09 RR |
3526 | /* reverse: prevent GTK from deleting the widget arbitrarily */ |
3527 | gtk_widget_unref( m_widget ); | |
148cd9b6 | 3528 | |
f03fc89f | 3529 | return TRUE; |
362c6693 | 3530 | } |
c801d85f | 3531 | |
1e6feb95 | 3532 | void wxWindowGTK::DoAddChild(wxWindowGTK *child) |
ddb6bc71 | 3533 | { |
223d09f6 | 3534 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") ); |
ddb6bc71 | 3535 | |
223d09f6 | 3536 | wxASSERT_MSG( (child != NULL), wxT("invalid child window") ); |
ddb6bc71 | 3537 | |
223d09f6 | 3538 | wxASSERT_MSG( (m_insertCallback != NULL), wxT("invalid child insertion function") ); |
c50f1fb9 | 3539 | |
ddb6bc71 RR |
3540 | /* add to list */ |
3541 | AddChild( child ); | |
c50f1fb9 | 3542 | |
ddb6bc71 RR |
3543 | /* insert GTK representation */ |
3544 | (*m_insertCallback)(this, child); | |
3545 | } | |
3546 | ||
1e6feb95 | 3547 | void wxWindowGTK::Raise() |
362c6693 | 3548 | { |
223d09f6 | 3549 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 3550 | |
a2053b27 RR |
3551 | if (!m_widget->window) return; |
3552 | ||
f03fc89f | 3553 | gdk_window_raise( m_widget->window ); |
362c6693 RR |
3554 | } |
3555 | ||
1e6feb95 | 3556 | void wxWindowGTK::Lower() |
362c6693 | 3557 | { |
223d09f6 | 3558 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 3559 | |
a2053b27 RR |
3560 | if (!m_widget->window) return; |
3561 | ||
f03fc89f | 3562 | gdk_window_lower( m_widget->window ); |
362c6693 | 3563 | } |
c801d85f | 3564 | |
1e6feb95 | 3565 | bool wxWindowGTK::SetCursor( const wxCursor &cursor ) |
86b29a61 | 3566 | { |
223d09f6 | 3567 | wxCHECK_MSG( (m_widget != NULL), FALSE, wxT("invalid window") ); |
86b29a61 | 3568 | |
f6bcfd97 BP |
3569 | if (cursor == m_cursor) |
3570 | return FALSE; | |
3571 | ||
3572 | if (g_isIdle) | |
3573 | wxapp_install_idle_handler(); | |
1e6feb95 | 3574 | |
f6bcfd97 BP |
3575 | if (cursor == wxNullCursor) |
3576 | return wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ); | |
3577 | else | |
3578 | return wxWindowBase::SetCursor( cursor ); | |
362c6693 | 3579 | } |
c801d85f | 3580 | |
1e6feb95 | 3581 | void wxWindowGTK::WarpPointer( int x, int y ) |
4f22cf8d | 3582 | { |
223d09f6 | 3583 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
85eb36c2 | 3584 | |
3bcc8d15 RR |
3585 | // We provide this function ourselves as it is |
3586 | // missing in GDK (top of this file). | |
148cd9b6 | 3587 | |
ed673c6a RR |
3588 | GdkWindow *window = (GdkWindow*) NULL; |
3589 | if (m_wxwindow) | |
da048e3d | 3590 | window = GTK_PIZZA(m_wxwindow)->bin_window; |
ed673c6a RR |
3591 | else |
3592 | window = GetConnectWidget()->window; | |
148cd9b6 | 3593 | |
ed673c6a RR |
3594 | if (window) |
3595 | gdk_window_warp_pointer( window, x, y ); | |
4f22cf8d RR |
3596 | } |
3597 | ||
3013a903 | 3598 | |
1e6feb95 | 3599 | void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect ) |
c801d85f | 3600 | { |
f2593d0d | 3601 | if (!m_widget) return; |
a2053b27 | 3602 | if (!m_widget->window) return; |
2b5f62a0 | 3603 | |
4e5a4c69 | 3604 | #ifndef __WXGTK20__ |
ea323db3 RR |
3605 | if (g_isIdle) |
3606 | wxapp_install_idle_handler(); | |
2b5f62a0 | 3607 | |
139adb6a | 3608 | if (eraseBackground && m_wxwindow && m_wxwindow->window) |
c801d85f | 3609 | { |
139adb6a RR |
3610 | if (rect) |
3611 | { | |
3bcc8d15 RR |
3612 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). |
3613 | m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height ); | |
139adb6a RR |
3614 | } |
3615 | else | |
3616 | { | |
3bcc8d15 RR |
3617 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). |
3618 | m_clearRegion.Clear(); | |
3619 | m_clearRegion.Union( 0, 0, m_wxwindow->allocation.width, m_wxwindow->allocation.height ); | |
139adb6a RR |
3620 | } |
3621 | } | |
ff8bfdbb | 3622 | |
3bcc8d15 | 3623 | if (rect) |
139adb6a RR |
3624 | { |
3625 | if (m_wxwindow) | |
b02da6b1 | 3626 | { |
23716407 | 3627 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). |
3bcc8d15 | 3628 | m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height ); |
b02da6b1 | 3629 | } |
ff8bfdbb | 3630 | else |
b6fa52db | 3631 | { |
3bcc8d15 RR |
3632 | GdkRectangle gdk_rect; |
3633 | gdk_rect.x = rect->x; | |
3634 | gdk_rect.y = rect->y; | |
3635 | gdk_rect.width = rect->width; | |
3636 | gdk_rect.height = rect->height; | |
3637 | gtk_widget_draw( m_widget, &gdk_rect ); | |
b6fa52db | 3638 | } |
362c6693 | 3639 | } |
c801d85f | 3640 | else |
139adb6a | 3641 | { |
139adb6a | 3642 | if (m_wxwindow) |
b02da6b1 | 3643 | { |
23716407 | 3644 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). |
3bcc8d15 RR |
3645 | m_updateRegion.Clear(); |
3646 | m_updateRegion.Union( 0, 0, m_wxwindow->allocation.width, m_wxwindow->allocation.height ); | |
b02da6b1 | 3647 | } |
139adb6a | 3648 | else |
b6fa52db | 3649 | { |
3bcc8d15 | 3650 | gtk_widget_draw( m_widget, (GdkRectangle*) NULL ); |
b6fa52db | 3651 | } |
139adb6a | 3652 | } |
4e5a4c69 RR |
3653 | #else |
3654 | if (m_wxwindow) | |
3655 | { | |
3656 | if (rect) | |
3657 | { | |
3658 | GdkRectangle gdk_rect; | |
3659 | gdk_rect.x = rect->x; | |
3660 | gdk_rect.y = rect->y; | |
3661 | gdk_rect.width = rect->width; | |
3662 | gdk_rect.height = rect->height; | |
3663 | gdk_window_invalidate_rect( GTK_PIZZA(m_wxwindow)->bin_window, &gdk_rect, TRUE ); | |
3664 | } | |
3665 | else | |
3666 | { | |
3667 | gdk_window_invalidate_rect( GTK_PIZZA(m_wxwindow)->bin_window, NULL, TRUE ); | |
3668 | } | |
3669 | } | |
3670 | #endif | |
362c6693 | 3671 | } |
c801d85f | 3672 | |
beab25bd | 3673 | void wxWindowGTK::Update() |
010afced RR |
3674 | { |
3675 | GtkUpdate(); | |
3676 | } | |
3677 | ||
3678 | void wxWindowGTK::GtkUpdate() | |
beab25bd | 3679 | { |
4e5a4c69 RR |
3680 | #ifdef __WXGTK20__ |
3681 | if (m_wxwindow && GTK_PIZZA(m_wxwindow)->bin_window) | |
3682 | gdk_window_process_updates( GTK_PIZZA(m_wxwindow)->bin_window, FALSE ); | |
b15ed747 | 3683 | #else |
beab25bd | 3684 | if (!m_updateRegion.IsEmpty()) |
23716407 | 3685 | GtkSendPaintEvents(); |
b15ed747 | 3686 | #endif |
beab25bd RR |
3687 | } |
3688 | ||
3689 | void wxWindowGTK::GtkSendPaintEvents() | |
3690 | { | |
3bcc8d15 RR |
3691 | if (!m_wxwindow) |
3692 | { | |
2b5f62a0 | 3693 | #ifndef __WXGTK20__ |
3bcc8d15 | 3694 | m_clearRegion.Clear(); |
b15ed747 | 3695 | #endif |
3bcc8d15 RR |
3696 | m_updateRegion.Clear(); |
3697 | return; | |
3698 | } | |
beab25bd | 3699 | |
f90566f5 | 3700 | // Clip to paint region in wxClientDC |
3bcc8d15 | 3701 | m_clipPaintRegion = TRUE; |
fab591c5 | 3702 | |
b15ed747 RR |
3703 | #ifndef __WXGTK20__ |
3704 | // widget to draw on | |
3705 | GtkPizza *pizza = GTK_PIZZA (m_wxwindow); | |
2b5f62a0 | 3706 | |
b15ed747 | 3707 | // later for GTK 2.0, too. |
f90566f5 RR |
3708 | if (GetThemeEnabled()) |
3709 | { | |
3710 | // find ancestor from which to steal background | |
3711 | wxWindow *parent = GetParent(); | |
3712 | while (parent && !parent->IsTopLevel()) | |
3713 | parent = parent->GetParent(); | |
3714 | if (!parent) | |
cc06fe74 | 3715 | parent = (wxWindow*)this; |
2b5f62a0 | 3716 | |
f90566f5 RR |
3717 | wxRegionIterator upd( m_updateRegion ); |
3718 | while (upd) | |
3719 | { | |
3720 | GdkRectangle rect; | |
3721 | rect.x = upd.GetX(); | |
3722 | rect.y = upd.GetY(); | |
3723 | rect.width = upd.GetWidth(); | |
3724 | rect.height = upd.GetHeight(); | |
2b5f62a0 | 3725 | |
f90566f5 RR |
3726 | gtk_paint_flat_box( parent->m_widget->style, |
3727 | pizza->bin_window, | |
3728 | GTK_STATE_NORMAL, | |
3729 | GTK_SHADOW_NONE, | |
3730 | &rect, | |
3731 | parent->m_widget, | |
3732 | (char *)"base", | |
3733 | 0, 0, -1, -1 ); | |
2b5f62a0 | 3734 | |
f90566f5 RR |
3735 | upd ++; |
3736 | } | |
3737 | } | |
3738 | else | |
fab591c5 | 3739 | #endif |
b15ed747 RR |
3740 | |
3741 | #ifdef __WXGTK20__ | |
3742 | { | |
3743 | wxWindowDC dc( (wxWindow*)this ); | |
3744 | dc.SetClippingRegion( m_updateRegion ); | |
3745 | ||
3746 | wxEraseEvent erase_event( GetId(), &dc ); | |
3747 | erase_event.SetEventObject( this ); | |
3748 | ||
3749 | GetEventHandler()->ProcessEvent(erase_event); | |
3750 | } | |
3751 | #else | |
3752 | // if (!m_clearRegion.IsEmpty()) // Always send an erase event under GTK 1.2 | |
beab25bd | 3753 | { |
3bcc8d15 | 3754 | wxWindowDC dc( (wxWindow*)this ); |
62cb3cd8 RR |
3755 | if (m_clearRegion.IsEmpty()) |
3756 | dc.SetClippingRegion( m_updateRegion ); | |
3757 | else | |
3758 | dc.SetClippingRegion( m_clearRegion ); | |
0fc5dbf5 | 3759 | |
3bcc8d15 RR |
3760 | wxEraseEvent erase_event( GetId(), &dc ); |
3761 | erase_event.SetEventObject( this ); | |
0fc5dbf5 | 3762 | |
beab25bd RR |
3763 | if (!GetEventHandler()->ProcessEvent(erase_event)) |
3764 | { | |
994bc575 RR |
3765 | if (!g_eraseGC) |
3766 | { | |
f90566f5 | 3767 | g_eraseGC = gdk_gc_new( pizza->bin_window ); |
994bc575 RR |
3768 | gdk_gc_set_fill( g_eraseGC, GDK_SOLID ); |
3769 | } | |
4e5a4c69 | 3770 | gdk_gc_set_foreground( g_eraseGC, m_backgroundColour.GetColor() ); |
0fc5dbf5 | 3771 | |
3bcc8d15 | 3772 | wxRegionIterator upd( m_clearRegion ); |
beab25bd RR |
3773 | while (upd) |
3774 | { | |
f90566f5 RR |
3775 | gdk_draw_rectangle( pizza->bin_window, g_eraseGC, 1, |
3776 | upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() ); | |
beab25bd RR |
3777 | upd ++; |
3778 | } | |
3779 | } | |
3bcc8d15 | 3780 | m_clearRegion.Clear(); |
beab25bd | 3781 | } |
b15ed747 | 3782 | #endif |
beab25bd RR |
3783 | |
3784 | wxNcPaintEvent nc_paint_event( GetId() ); | |
3785 | nc_paint_event.SetEventObject( this ); | |
3786 | GetEventHandler()->ProcessEvent( nc_paint_event ); | |
3787 | ||
3788 | wxPaintEvent paint_event( GetId() ); | |
3789 | paint_event.SetEventObject( this ); | |
3790 | GetEventHandler()->ProcessEvent( paint_event ); | |
3791 | ||
beab25bd | 3792 | m_clipPaintRegion = FALSE; |
c89f5c02 | 3793 | |
8f3e7ecc | 3794 | #ifndef __WXUNIVERSAL__ |
4e5a4c69 | 3795 | #ifndef __WXGTK20__ |
8f3e7ecc RR |
3796 | // The following code will result in all window-less widgets |
3797 | // being redrawn because the wxWindows class is allowed to | |
3798 | // paint over the window-less widgets. | |
0fc5dbf5 | 3799 | |
8f3e7ecc RR |
3800 | GList *children = pizza->children; |
3801 | while (children) | |
c89f5c02 | 3802 | { |
8f3e7ecc RR |
3803 | GtkPizzaChild *child = (GtkPizzaChild*) children->data; |
3804 | children = children->next; | |
2b5f62a0 | 3805 | |
8f3e7ecc RR |
3806 | if (GTK_WIDGET_NO_WINDOW (child->widget) && |
3807 | GTK_WIDGET_DRAWABLE (child->widget)) | |
3808 | { | |
3809 | // Get intersection of widget area and update region | |
3810 | wxRegion region( m_updateRegion ); | |
0fc5dbf5 | 3811 | |
8f3e7ecc RR |
3812 | GdkEventExpose gdk_event; |
3813 | gdk_event.type = GDK_EXPOSE; | |
3814 | gdk_event.window = pizza->bin_window; | |
3815 | gdk_event.count = 0; | |
0fc5dbf5 | 3816 | |
8f3e7ecc RR |
3817 | wxRegionIterator upd( m_updateRegion ); |
3818 | while (upd) | |
c89f5c02 | 3819 | { |
8f3e7ecc RR |
3820 | GdkRectangle rect; |
3821 | rect.x = upd.GetX(); | |
3822 | rect.y = upd.GetY(); | |
3823 | rect.width = upd.GetWidth(); | |
3824 | rect.height = upd.GetHeight(); | |
0fc5dbf5 | 3825 | |
8f3e7ecc RR |
3826 | if (gtk_widget_intersect (child->widget, &rect, &gdk_event.area)) |
3827 | { | |
3828 | gtk_widget_event (child->widget, (GdkEvent*) &gdk_event); | |
3829 | } | |
0fc5dbf5 | 3830 | |
8f3e7ecc | 3831 | upd ++; |
c89f5c02 RR |
3832 | } |
3833 | } | |
3834 | } | |
4e5a4c69 | 3835 | #endif |
8f3e7ecc | 3836 | #endif |
c89f5c02 RR |
3837 | |
3838 | m_updateRegion.Clear(); | |
beab25bd RR |
3839 | } |
3840 | ||
1e6feb95 | 3841 | void wxWindowGTK::Clear() |
c801d85f | 3842 | { |
223d09f6 | 3843 | wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); |
47d67540 | 3844 | |
b15ed747 | 3845 | #ifndef __WXGTK20__ |
f234c60c RR |
3846 | if (m_wxwindow && m_wxwindow->window) |
3847 | { | |
d7fa7eaa RR |
3848 | m_clearRegion.Clear(); |
3849 | wxSize size( GetClientSize() ); | |
3850 | m_clearRegion.Union( 0,0,size.x,size.y ); | |
2b5f62a0 | 3851 | |
d7fa7eaa | 3852 | // Better do this in idle? |
010afced | 3853 | GtkUpdate(); |
f234c60c | 3854 | } |
b15ed747 | 3855 | #endif |
362c6693 | 3856 | } |
c801d85f | 3857 | |
ff8bfdbb | 3858 | #if wxUSE_TOOLTIPS |
1e6feb95 | 3859 | void wxWindowGTK::DoSetToolTip( wxToolTip *tip ) |
b1170810 | 3860 | { |
f03fc89f | 3861 | wxWindowBase::DoSetToolTip(tip); |
ff8bfdbb | 3862 | |
f03fc89f | 3863 | if (m_tooltip) |
3379ed37 | 3864 | m_tooltip->Apply( (wxWindow *)this ); |
b1170810 RR |
3865 | } |
3866 | ||
1e6feb95 | 3867 | void wxWindowGTK::ApplyToolTip( GtkTooltips *tips, const wxChar *tip ) |
b1170810 | 3868 | { |
dcf924a3 | 3869 | gtk_tooltips_set_tip( tips, GetConnectWidget(), wxConvCurrent->cWX2MB(tip), (gchar*) NULL ); |
301cd871 | 3870 | } |
ff8bfdbb | 3871 | #endif // wxUSE_TOOLTIPS |
b1170810 | 3872 | |
ea323db3 RR |
3873 | void wxWindowGTK::GtkSetBackgroundColour( const wxColour &colour ) |
3874 | { | |
3875 | GdkWindow *window = (GdkWindow*) NULL; | |
3876 | if (m_wxwindow) | |
3877 | window = GTK_PIZZA(m_wxwindow)->bin_window; | |
3878 | else | |
3879 | window = GetConnectWidget()->window; | |
3880 | ||
3881 | wxASSERT( window ); | |
2b5f62a0 | 3882 | |
ea323db3 RR |
3883 | // We need the pixel value e.g. for background clearing. |
3884 | m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) ); | |
2b5f62a0 | 3885 | |
f90566f5 | 3886 | if (m_wxwindow) |
ea323db3 | 3887 | { |
f90566f5 | 3888 | // wxMSW doesn't clear the window here, either. |
ea323db3 RR |
3889 | gdk_window_set_background( window, m_backgroundColour.GetColor() ); |
3890 | } | |
3891 | ||
3892 | ApplyWidgetStyle(); | |
3893 | } | |
3894 | ||
1e6feb95 | 3895 | bool wxWindowGTK::SetBackgroundColour( const wxColour &colour ) |
c801d85f | 3896 | { |
223d09f6 | 3897 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid window") ); |
8bbe427f | 3898 | |
739730ca | 3899 | if (!wxWindowBase::SetBackgroundColour(colour)) |
ea323db3 | 3900 | return FALSE; |
c50f1fb9 | 3901 | |
ed673c6a RR |
3902 | GdkWindow *window = (GdkWindow*) NULL; |
3903 | if (m_wxwindow) | |
da048e3d | 3904 | window = GTK_PIZZA(m_wxwindow)->bin_window; |
ed673c6a RR |
3905 | else |
3906 | window = GetConnectWidget()->window; | |
148cd9b6 | 3907 | |
ed673c6a | 3908 | if (!window) |
739730ca RR |
3909 | { |
3910 | // indicate that a new style has been set | |
c50f1fb9 VZ |
3911 | // but it couldn't get applied as the |
3912 | // widget hasn't been realized yet. | |
3913 | m_delayedBackgroundColour = TRUE; | |
ea323db3 | 3914 | return TRUE; |
739730ca | 3915 | } |
ea323db3 | 3916 | else |
994bc575 | 3917 | { |
ea323db3 | 3918 | GtkSetBackgroundColour( colour ); |
994bc575 | 3919 | } |
ca298c88 | 3920 | |
ea323db3 RR |
3921 | return TRUE; |
3922 | } | |
8bbe427f | 3923 | |
ea323db3 RR |
3924 | void wxWindowGTK::GtkSetForegroundColour( const wxColour &colour ) |
3925 | { | |
3926 | GdkWindow *window = (GdkWindow*) NULL; | |
3927 | if (m_wxwindow) | |
3928 | window = GTK_PIZZA(m_wxwindow)->bin_window; | |
3929 | else | |
3930 | window = GetConnectWidget()->window; | |
c801d85f | 3931 | |
ea323db3 RR |
3932 | wxASSERT( window ); |
3933 | ||
3934 | ApplyWidgetStyle(); | |
6de97a3b RR |
3935 | } |
3936 | ||
1e6feb95 | 3937 | bool wxWindowGTK::SetForegroundColour( const wxColour &colour ) |
6de97a3b | 3938 | { |
223d09f6 | 3939 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid window") ); |
8bbe427f | 3940 | |
739730ca RR |
3941 | if (!wxWindowBase::SetForegroundColour(colour)) |
3942 | { | |
3943 | // don't leave if the GTK widget has just | |
3944 | // been realized | |
3945 | if (!m_delayedForegroundColour) return FALSE; | |
3946 | } | |
c50f1fb9 | 3947 | |
ed673c6a RR |
3948 | GdkWindow *window = (GdkWindow*) NULL; |
3949 | if (m_wxwindow) | |
da048e3d | 3950 | window = GTK_PIZZA(m_wxwindow)->bin_window; |
ed673c6a RR |
3951 | else |
3952 | window = GetConnectWidget()->window; | |
148cd9b6 | 3953 | |
ed673c6a | 3954 | if (!window) |
739730ca RR |
3955 | { |
3956 | // indicate that a new style has been set | |
c50f1fb9 VZ |
3957 | // but it couldn't get applied as the |
3958 | // widget hasn't been realized yet. | |
3959 | m_delayedForegroundColour = TRUE; | |
739730ca | 3960 | } |
ea323db3 RR |
3961 | else |
3962 | { | |
3963 | GtkSetForegroundColour( colour ); | |
3964 | } | |
f03fc89f VZ |
3965 | |
3966 | return TRUE; | |
58614078 RR |
3967 | } |
3968 | ||
2b5f62a0 VZ |
3969 | #ifdef __WXGTK20__ |
3970 | PangoContext *wxWindowGTK::GtkGetPangoDefaultContext() | |
3971 | { | |
3972 | return gtk_widget_get_pango_context( m_widget ); | |
3973 | } | |
3974 | ||
3975 | PangoContext *wxWindowGTK::GtkGetPangoX11Context() | |
3976 | { | |
3977 | if (!m_x11Context) | |
3978 | m_x11Context = pango_x_get_context( gdk_display ); | |
3979 | ||
3980 | return m_x11Context; | |
3981 | } | |
3982 | #endif | |
3983 | ||
1e6feb95 | 3984 | GtkStyle *wxWindowGTK::GetWidgetStyle() |
58614078 | 3985 | { |
103aab26 RR |
3986 | if (m_widgetStyle) |
3987 | { | |
3988 | GtkStyle *remake = gtk_style_copy( m_widgetStyle ); | |
9e691f46 VZ |
3989 | |
3990 | // FIXME: no more klass in 2.0 | |
3991 | #ifndef __WXGTK20__ | |
103aab26 | 3992 | remake->klass = m_widgetStyle->klass; |
dd00f3f6 | 3993 | #endif |
2daa0ce9 | 3994 | |
103aab26 RR |
3995 | gtk_style_unref( m_widgetStyle ); |
3996 | m_widgetStyle = remake; | |
3997 | } | |
3998 | else | |
3999 | { | |
4000 | GtkStyle *def = gtk_rc_get_style( m_widget ); | |
e6527f9d | 4001 | |
103aab26 RR |
4002 | if (!def) |
4003 | def = gtk_widget_get_default_style(); | |
e6527f9d | 4004 | |
103aab26 | 4005 | m_widgetStyle = gtk_style_copy( def ); |
9e691f46 VZ |
4006 | |
4007 | // FIXME: no more klass in 2.0 | |
4008 | #ifndef __WXGTK20__ | |
103aab26 | 4009 | m_widgetStyle->klass = def->klass; |
dd00f3f6 | 4010 | #endif |
103aab26 | 4011 | } |
8bbe427f | 4012 | |
1ecc4d80 | 4013 | return m_widgetStyle; |
58614078 RR |
4014 | } |
4015 | ||
1e6feb95 | 4016 | void wxWindowGTK::SetWidgetStyle() |
58614078 | 4017 | { |
8f3e7ecc | 4018 | #if DISABLE_STYLE_IF_BROKEN_THEME |
fb65642c RR |
4019 | if (m_widget->style->engine_data) |
4020 | { | |
4021 | static bool s_warningPrinted = FALSE; | |
4022 | if (!s_warningPrinted) | |
4023 | { | |
4024 | printf( "wxWindows warning: Widget styles disabled due to buggy GTK theme.\n" ); | |
4025 | s_warningPrinted = TRUE; | |
4026 | } | |
4027 | m_widgetStyle = m_widget->style; | |
4028 | return; | |
4029 | } | |
a56fcaaf | 4030 | #endif |
fb65642c | 4031 | |
1ecc4d80 RR |
4032 | GtkStyle *style = GetWidgetStyle(); |
4033 | ||
a756f210 | 4034 | if (m_font != wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT )) |
db434467 | 4035 | { |
288059b2 RR |
4036 | #ifdef __WXGTK20__ |
4037 | pango_font_description_free( style->font_desc ); | |
4038 | pango_font_description_copy( m_font.GetNativeFontInfo()->description ); | |
4039 | #else | |
4040 | gdk_font_unref( style->font ); | |
f77cf4e6 | 4041 | style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) ); |
cfcc3932 | 4042 | #endif |
288059b2 | 4043 | } |
1ecc4d80 RR |
4044 | |
4045 | if (m_foregroundColour.Ok()) | |
4046 | { | |
454e2a22 | 4047 | m_foregroundColour.CalcPixel( gtk_widget_get_colormap( m_widget ) ); |
a756f210 | 4048 | if (m_foregroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)) |
db434467 RR |
4049 | { |
4050 | style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor(); | |
4051 | style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor(); | |
4052 | style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor(); | |
4053 | } | |
1e6feb95 | 4054 | else |
f6bcfd97 BP |
4055 | { |
4056 | // Try to restore the gtk default style. This is still a little | |
4057 | // oversimplified for what is probably really needed here for controls | |
4058 | // other than buttons, but is better than not being able to (re)set a | |
4059 | // control's foreground colour to *wxBLACK -- RL | |
4060 | GtkStyle *def = gtk_rc_get_style( m_widget ); | |
4061 | ||
4062 | if (!def) | |
4063 | def = gtk_widget_get_default_style(); | |
4064 | ||
4065 | style->fg[GTK_STATE_NORMAL] = def->fg[GTK_STATE_NORMAL]; | |
4066 | style->fg[GTK_STATE_PRELIGHT] = def->fg[GTK_STATE_PRELIGHT]; | |
4067 | style->fg[GTK_STATE_ACTIVE] = def->fg[GTK_STATE_ACTIVE]; | |
4068 | } | |
1ecc4d80 RR |
4069 | } |
4070 | ||
4071 | if (m_backgroundColour.Ok()) | |
4072 | { | |
454e2a22 | 4073 | m_backgroundColour.CalcPixel( gtk_widget_get_colormap( m_widget ) ); |
a756f210 | 4074 | if (m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) |
db434467 RR |
4075 | { |
4076 | style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); | |
4077 | style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); | |
4078 | style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); | |
4079 | style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); | |
4080 | style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); | |
4081 | style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); | |
4082 | style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); | |
4083 | style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); | |
f6bcfd97 BP |
4084 | } |
4085 | else | |
4086 | { | |
4087 | // Try to restore the gtk default style. This is still a little | |
4088 | // oversimplified for what is probably really needed here for controls | |
4089 | // other than buttons, but is better than not being able to (re)set a | |
4090 | // control's background colour to default grey and means resetting a | |
1e6feb95 | 4091 | // button to wxSYS_COLOUR_BTNFACE will restore its usual highlighting |
f6bcfd97 BP |
4092 | // behavior -- RL |
4093 | GtkStyle *def = gtk_rc_get_style( m_widget ); | |
4094 | ||
4095 | if (!def) | |
4096 | def = gtk_widget_get_default_style(); | |
4097 | ||
4098 | style->bg[GTK_STATE_NORMAL] = def->bg[GTK_STATE_NORMAL]; | |
4099 | style->base[GTK_STATE_NORMAL] = def->base[GTK_STATE_NORMAL]; | |
4100 | style->bg[GTK_STATE_PRELIGHT] = def->bg[GTK_STATE_PRELIGHT]; | |
4101 | style->base[GTK_STATE_PRELIGHT] = def->base[GTK_STATE_PRELIGHT]; | |
4102 | style->bg[GTK_STATE_ACTIVE] = def->bg[GTK_STATE_ACTIVE]; | |
4103 | style->base[GTK_STATE_ACTIVE] = def->base[GTK_STATE_ACTIVE]; | |
4104 | style->bg[GTK_STATE_INSENSITIVE] = def->bg[GTK_STATE_INSENSITIVE]; | |
4105 | style->base[GTK_STATE_INSENSITIVE] = def->base[GTK_STATE_INSENSITIVE]; | |
4106 | } | |
1ecc4d80 | 4107 | } |
a81258be RR |
4108 | } |
4109 | ||
1e6feb95 | 4110 | void wxWindowGTK::ApplyWidgetStyle() |
a81258be | 4111 | { |
6de97a3b RR |
4112 | } |
4113 | ||
2259e007 RR |
4114 | //----------------------------------------------------------------------------- |
4115 | // Pop-up menu stuff | |
4116 | //----------------------------------------------------------------------------- | |
4117 | ||
6522713c | 4118 | #if wxUSE_MENUS_NATIVE |
1e6feb95 | 4119 | |
90350682 VZ |
4120 | extern "C" |
4121 | void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting ) | |
2259e007 RR |
4122 | { |
4123 | *is_waiting = FALSE; | |
4124 | } | |
4125 | ||
1e6feb95 | 4126 | static void SetInvokingWindow( wxMenu *menu, wxWindowGTK *win ) |
30dea054 | 4127 | { |
1ecc4d80 | 4128 | menu->SetInvokingWindow( win ); |
1987af7e | 4129 | wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); |
1ecc4d80 RR |
4130 | while (node) |
4131 | { | |
1987af7e | 4132 | wxMenuItem *menuitem = node->GetData(); |
1ecc4d80 RR |
4133 | if (menuitem->IsSubMenu()) |
4134 | { | |
ff8bfdbb VZ |
4135 | SetInvokingWindow( menuitem->GetSubMenu(), win ); |
4136 | } | |
1987af7e VZ |
4137 | |
4138 | node = node->GetNext(); | |
1ecc4d80 | 4139 | } |
362c6693 | 4140 | } |
30dea054 | 4141 | |
e3473203 VZ |
4142 | // used to pass the coordinates from wxWindowGTK::DoPopupMenu() to |
4143 | // wxPopupMenuPositionCallback() | |
4144 | // | |
4145 | // should be safe even in the MT case as the user can hardly popup 2 menus | |
4146 | // simultaneously, can he? | |
0c77152e RR |
4147 | static gint gs_pop_x = 0; |
4148 | static gint gs_pop_y = 0; | |
4149 | ||
295272bd VZ |
4150 | extern "C" void wxPopupMenuPositionCallback( GtkMenu *menu, |
4151 | gint *x, gint *y, | |
9e691f46 VZ |
4152 | #ifdef __WXGTK20__ |
4153 | gboolean * WXUNUSED(whatever), | |
4154 | #endif | |
295272bd | 4155 | gpointer WXUNUSED(user_data) ) |
0c77152e | 4156 | { |
e3473203 VZ |
4157 | // ensure that the menu appears entirely on screen |
4158 | GtkRequisition req; | |
4159 | gtk_widget_get_child_requisition(GTK_WIDGET(menu), &req); | |
4160 | ||
4161 | wxSize sizeScreen = wxGetDisplaySize(); | |
4162 | ||
4163 | gint xmax = sizeScreen.x - req.width, | |
4164 | ymax = sizeScreen.y - req.height; | |
4165 | ||
4166 | *x = gs_pop_x < xmax ? gs_pop_x : xmax; | |
4167 | *y = gs_pop_y < ymax ? gs_pop_y : ymax; | |
0c77152e RR |
4168 | } |
4169 | ||
1e6feb95 | 4170 | bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y ) |
30dea054 | 4171 | { |
223d09f6 | 4172 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid window") ); |
47d67540 | 4173 | |
223d09f6 | 4174 | wxCHECK_MSG( menu != NULL, FALSE, wxT("invalid popup-menu") ); |
8bbe427f | 4175 | |
1ecc4d80 | 4176 | SetInvokingWindow( menu, this ); |
ff8bfdbb | 4177 | |
631f1bfe JS |
4178 | menu->UpdateUI(); |
4179 | ||
0c77152e RR |
4180 | gs_pop_x = x; |
4181 | gs_pop_y = y; | |
e3473203 | 4182 | ClientToScreen( &gs_pop_x, &gs_pop_y ); |
ff8bfdbb | 4183 | |
2259e007 | 4184 | bool is_waiting = TRUE; |
148cd9b6 | 4185 | |
90350682 VZ |
4186 | gtk_signal_connect( GTK_OBJECT(menu->m_menu), |
4187 | "hide", | |
4188 | GTK_SIGNAL_FUNC(gtk_pop_hide_callback), | |
4189 | (gpointer)&is_waiting ); | |
2259e007 | 4190 | |
1ecc4d80 | 4191 | gtk_menu_popup( |
47d67540 | 4192 | GTK_MENU(menu->m_menu), |
e3473203 VZ |
4193 | (GtkWidget *) NULL, // parent menu shell |
4194 | (GtkWidget *) NULL, // parent menu item | |
4195 | wxPopupMenuPositionCallback, // function to position it | |
4196 | NULL, // client data | |
4197 | 0, // button used to activate it | |
4198 | gs_timeLastClick // the time of activation | |
47d67540 | 4199 | ); |
148cd9b6 | 4200 | |
956dbab1 RR |
4201 | while (is_waiting) |
4202 | { | |
4203 | while (gtk_events_pending()) | |
4204 | gtk_main_iteration(); | |
4205 | } | |
2259e007 | 4206 | |
1ecc4d80 | 4207 | return TRUE; |
30dea054 RR |
4208 | } |
4209 | ||
6522713c | 4210 | #endif // wxUSE_MENUS_NATIVE |
1e6feb95 | 4211 | |
06cfab17 | 4212 | #if wxUSE_DRAG_AND_DROP |
ac57418f | 4213 | |
1e6feb95 | 4214 | void wxWindowGTK::SetDropTarget( wxDropTarget *dropTarget ) |
c801d85f | 4215 | { |
223d09f6 | 4216 | wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); |
47d67540 | 4217 | |
1ecc4d80 | 4218 | GtkWidget *dnd_widget = GetConnectWidget(); |
47d67540 | 4219 | |
1ecc4d80 | 4220 | if (m_dropTarget) m_dropTarget->UnregisterWidget( dnd_widget ); |
47d67540 | 4221 | |
1ecc4d80 RR |
4222 | if (m_dropTarget) delete m_dropTarget; |
4223 | m_dropTarget = dropTarget; | |
47d67540 | 4224 | |
1ecc4d80 | 4225 | if (m_dropTarget) m_dropTarget->RegisterWidget( dnd_widget ); |
362c6693 | 4226 | } |
c801d85f | 4227 | |
f03fc89f | 4228 | #endif // wxUSE_DRAG_AND_DROP |
ac57418f | 4229 | |
1e6feb95 | 4230 | GtkWidget* wxWindowGTK::GetConnectWidget() |
e3e65dac | 4231 | { |
1ecc4d80 RR |
4232 | GtkWidget *connect_widget = m_widget; |
4233 | if (m_wxwindow) connect_widget = m_wxwindow; | |
47d67540 | 4234 | |
1ecc4d80 | 4235 | return connect_widget; |
e3e65dac | 4236 | } |
47d67540 | 4237 | |
1e6feb95 | 4238 | bool wxWindowGTK::IsOwnGtkWindow( GdkWindow *window ) |
903f689b | 4239 | { |
148cd9b6 | 4240 | if (m_wxwindow) |
da048e3d | 4241 | return (window == GTK_PIZZA(m_wxwindow)->bin_window); |
148cd9b6 | 4242 | |
1ecc4d80 | 4243 | return (window == m_widget->window); |
903f689b RR |
4244 | } |
4245 | ||
1e6feb95 | 4246 | bool wxWindowGTK::SetFont( const wxFont &font ) |
c801d85f | 4247 | { |
223d09f6 | 4248 | wxCHECK_MSG( m_widget != NULL, FALSE, wxT("invalid window") ); |
c801d85f | 4249 | |
739730ca RR |
4250 | if (!wxWindowBase::SetFont(font)) |
4251 | { | |
454e2a22 | 4252 | return FALSE; |
739730ca | 4253 | } |
9c288e4d | 4254 | |
a756f210 | 4255 | wxColour sysbg = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ); |
f03fc89f | 4256 | if ( sysbg == m_backgroundColour ) |
ae0bdb01 RR |
4257 | { |
4258 | m_backgroundColour = wxNullColour; | |
4259 | ApplyWidgetStyle(); | |
ff8bfdbb VZ |
4260 | m_backgroundColour = sysbg; |
4261 | } | |
ae0bdb01 RR |
4262 | else |
4263 | { | |
4264 | ApplyWidgetStyle(); | |
4265 | } | |
c801d85f | 4266 | |
f03fc89f | 4267 | return TRUE; |
362c6693 | 4268 | } |
c801d85f | 4269 | |
94633ad9 | 4270 | void wxWindowGTK::DoCaptureMouse() |
c801d85f | 4271 | { |
b231914f VZ |
4272 | wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); |
4273 | ||
ed673c6a | 4274 | GdkWindow *window = (GdkWindow*) NULL; |
b231914f VZ |
4275 | if (m_wxwindow) |
4276 | window = GTK_PIZZA(m_wxwindow)->bin_window; | |
ed673c6a | 4277 | else |
b231914f | 4278 | window = GetConnectWidget()->window; |
148cd9b6 | 4279 | |
e4606ed9 | 4280 | wxCHECK_RET( window, _T("CaptureMouse() failed") ); |
c50f1fb9 | 4281 | |
b231914f | 4282 | wxCursor* cursor = & m_cursor; |
cca602ac JS |
4283 | if (!cursor->Ok()) |
4284 | cursor = wxSTANDARD_CURSOR; | |
4285 | ||
ed673c6a | 4286 | gdk_pointer_grab( window, FALSE, |
1ecc4d80 RR |
4287 | (GdkEventMask) |
4288 | (GDK_BUTTON_PRESS_MASK | | |
4289 | GDK_BUTTON_RELEASE_MASK | | |
148cd9b6 | 4290 | GDK_POINTER_MOTION_HINT_MASK | |
1ecc4d80 | 4291 | GDK_POINTER_MOTION_MASK), |
ff8bfdbb | 4292 | (GdkWindow *) NULL, |
cca602ac | 4293 | cursor->GetCursor(), |
b02da6b1 | 4294 | (guint32)GDK_CURRENT_TIME ); |
b231914f | 4295 | g_captureWindow = this; |
1e6feb95 | 4296 | g_captureWindowHasMouse = TRUE; |
362c6693 | 4297 | } |
c801d85f | 4298 | |
94633ad9 | 4299 | void wxWindowGTK::DoReleaseMouse() |
c801d85f | 4300 | { |
b231914f VZ |
4301 | wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); |
4302 | ||
e4606ed9 | 4303 | wxCHECK_RET( g_captureWindow, wxT("can't release mouse - not captured") ); |
47d67540 | 4304 | |
c43430bb VS |
4305 | g_captureWindow = (wxWindowGTK*) NULL; |
4306 | ||
ed673c6a | 4307 | GdkWindow *window = (GdkWindow*) NULL; |
b231914f VZ |
4308 | if (m_wxwindow) |
4309 | window = GTK_PIZZA(m_wxwindow)->bin_window; | |
ed673c6a | 4310 | else |
b231914f | 4311 | window = GetConnectWidget()->window; |
148cd9b6 | 4312 | |
b02da6b1 VZ |
4313 | if (!window) |
4314 | return; | |
c50f1fb9 | 4315 | |
b02da6b1 | 4316 | gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME ); |
362c6693 | 4317 | } |
c801d85f | 4318 | |
1e6feb95 VZ |
4319 | /* static */ |
4320 | wxWindow *wxWindowBase::GetCapture() | |
4321 | { | |
4322 | return (wxWindow *)g_captureWindow; | |
4323 | } | |
4324 | ||
4325 | bool wxWindowGTK::IsRetained() const | |
c801d85f | 4326 | { |
1ecc4d80 | 4327 | return FALSE; |
362c6693 | 4328 | } |
c801d85f | 4329 | |
1e6feb95 | 4330 | void wxWindowGTK::SetScrollbar( int orient, int pos, int thumbVisible, |
cb43b372 | 4331 | int range, bool refresh ) |
c801d85f | 4332 | { |
223d09f6 | 4333 | wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); |
8bbe427f | 4334 | |
223d09f6 | 4335 | wxCHECK_RET( m_wxwindow != NULL, wxT("window needs client area for scrolling") ); |
c801d85f | 4336 | |
1ecc4d80 | 4337 | m_hasScrolling = TRUE; |
47d67540 | 4338 | |
1ecc4d80 | 4339 | if (orient == wxHORIZONTAL) |
cb43b372 | 4340 | { |
1ecc4d80 RR |
4341 | float fpos = (float)pos; |
4342 | float frange = (float)range; | |
4343 | float fthumb = (float)thumbVisible; | |
4344 | if (fpos > frange-fthumb) fpos = frange-fthumb; | |
4345 | if (fpos < 0.0) fpos = 0.0; | |
4346 | ||
4347 | if ((fabs(frange-m_hAdjust->upper) < 0.2) && | |
4348 | (fabs(fthumb-m_hAdjust->page_size) < 0.2)) | |
4349 | { | |
4350 | SetScrollPos( orient, pos, refresh ); | |
4351 | return; | |
4352 | } | |
47d67540 | 4353 | |
1ecc4d80 | 4354 | m_oldHorizontalPos = fpos; |
47d67540 | 4355 | |
1ecc4d80 RR |
4356 | m_hAdjust->lower = 0.0; |
4357 | m_hAdjust->upper = frange; | |
4358 | m_hAdjust->value = fpos; | |
4359 | m_hAdjust->step_increment = 1.0; | |
4360 | m_hAdjust->page_increment = (float)(wxMax(fthumb,0)); | |
4361 | m_hAdjust->page_size = fthumb; | |
cb43b372 | 4362 | } |
1ecc4d80 RR |
4363 | else |
4364 | { | |
4365 | float fpos = (float)pos; | |
4366 | float frange = (float)range; | |
4367 | float fthumb = (float)thumbVisible; | |
4368 | if (fpos > frange-fthumb) fpos = frange-fthumb; | |
4369 | if (fpos < 0.0) fpos = 0.0; | |
4370 | ||
4371 | if ((fabs(frange-m_vAdjust->upper) < 0.2) && | |
4372 | (fabs(fthumb-m_vAdjust->page_size) < 0.2)) | |
4373 | { | |
4374 | SetScrollPos( orient, pos, refresh ); | |
4375 | return; | |
4376 | } | |
47d67540 | 4377 | |
1ecc4d80 | 4378 | m_oldVerticalPos = fpos; |
47d67540 | 4379 | |
1ecc4d80 RR |
4380 | m_vAdjust->lower = 0.0; |
4381 | m_vAdjust->upper = frange; | |
4382 | m_vAdjust->value = fpos; | |
4383 | m_vAdjust->step_increment = 1.0; | |
4384 | m_vAdjust->page_increment = (float)(wxMax(fthumb,0)); | |
4385 | m_vAdjust->page_size = fthumb; | |
4386 | } | |
47d67540 | 4387 | |
eb082a08 RR |
4388 | if (orient == wxHORIZONTAL) |
4389 | gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" ); | |
4390 | else | |
4391 | gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" ); | |
362c6693 | 4392 | } |
c801d85f | 4393 | |
1e6feb95 | 4394 | void wxWindowGTK::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) ) |
c801d85f | 4395 | { |
223d09f6 | 4396 | wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); |
1ecc4d80 | 4397 | |
223d09f6 | 4398 | wxCHECK_RET( m_wxwindow != NULL, wxT("window needs client area for scrolling") ); |
1ecc4d80 RR |
4399 | |
4400 | if (orient == wxHORIZONTAL) | |
4401 | { | |
4402 | float fpos = (float)pos; | |
4403 | if (fpos > m_hAdjust->upper - m_hAdjust->page_size) fpos = m_hAdjust->upper - m_hAdjust->page_size; | |
4404 | if (fpos < 0.0) fpos = 0.0; | |
4405 | m_oldHorizontalPos = fpos; | |
4406 | ||
4407 | if (fabs(fpos-m_hAdjust->value) < 0.2) return; | |
4408 | m_hAdjust->value = fpos; | |
4409 | } | |
4410 | else | |
4411 | { | |
4412 | float fpos = (float)pos; | |
4413 | if (fpos > m_vAdjust->upper - m_vAdjust->page_size) fpos = m_vAdjust->upper - m_vAdjust->page_size; | |
4414 | if (fpos < 0.0) fpos = 0.0; | |
4415 | m_oldVerticalPos = fpos; | |
ff8bfdbb | 4416 | |
1ecc4d80 RR |
4417 | if (fabs(fpos-m_vAdjust->value) < 0.2) return; |
4418 | m_vAdjust->value = fpos; | |
4419 | } | |
47d67540 | 4420 | |
5b8a521e | 4421 | if (m_wxwindow->window) |
47d67540 | 4422 | { |
5b8a521e | 4423 | if (orient == wxHORIZONTAL) |
473d087e RR |
4424 | { |
4425 | gtk_signal_disconnect_by_func( GTK_OBJECT(m_hAdjust), | |
4426 | (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this ); | |
2daa0ce9 | 4427 | |
5b8a521e | 4428 | gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" ); |
2daa0ce9 | 4429 | |
473d087e RR |
4430 | gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed", |
4431 | (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this ); | |
4432 | } | |
5b8a521e | 4433 | else |
473d087e RR |
4434 | { |
4435 | gtk_signal_disconnect_by_func( GTK_OBJECT(m_vAdjust), | |
4436 | (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this ); | |
2daa0ce9 | 4437 | |
5b8a521e | 4438 | gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" ); |
473d087e RR |
4439 | |
4440 | gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed", | |
4441 | (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this ); | |
4442 | } | |
cb43b372 | 4443 | } |
362c6693 | 4444 | } |
c801d85f | 4445 | |
1e6feb95 | 4446 | int wxWindowGTK::GetScrollThumb( int orient ) const |
c801d85f | 4447 | { |
223d09f6 | 4448 | wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid window") ); |
47d67540 | 4449 | |
223d09f6 | 4450 | wxCHECK_MSG( m_wxwindow != NULL, 0, wxT("window needs client area for scrolling") ); |
47d67540 | 4451 | |
1ecc4d80 RR |
4452 | if (orient == wxHORIZONTAL) |
4453 | return (int)(m_hAdjust->page_size+0.5); | |
4454 | else | |
4455 | return (int)(m_vAdjust->page_size+0.5); | |
362c6693 | 4456 | } |
c801d85f | 4457 | |
1e6feb95 | 4458 | int wxWindowGTK::GetScrollPos( int orient ) const |
c801d85f | 4459 | { |
223d09f6 | 4460 | wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid window") ); |
47d67540 | 4461 | |
223d09f6 | 4462 | wxCHECK_MSG( m_wxwindow != NULL, 0, wxT("window needs client area for scrolling") ); |
c801d85f | 4463 | |
1ecc4d80 RR |
4464 | if (orient == wxHORIZONTAL) |
4465 | return (int)(m_hAdjust->value+0.5); | |
4466 | else | |
4467 | return (int)(m_vAdjust->value+0.5); | |
362c6693 | 4468 | } |
c801d85f | 4469 | |
1e6feb95 | 4470 | int wxWindowGTK::GetScrollRange( int orient ) const |
c801d85f | 4471 | { |
223d09f6 | 4472 | wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid window") ); |
47d67540 | 4473 | |
223d09f6 | 4474 | wxCHECK_MSG( m_wxwindow != NULL, 0, wxT("window needs client area for scrolling") ); |
c801d85f | 4475 | |
1ecc4d80 RR |
4476 | if (orient == wxHORIZONTAL) |
4477 | return (int)(m_hAdjust->upper+0.5); | |
4478 | else | |
4479 | return (int)(m_vAdjust->upper+0.5); | |
362c6693 | 4480 | } |
c801d85f | 4481 | |
1e6feb95 | 4482 | void wxWindowGTK::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) ) |
c801d85f | 4483 | { |
223d09f6 | 4484 | wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); |
47d67540 | 4485 | |
223d09f6 | 4486 | wxCHECK_RET( m_wxwindow != NULL, wxT("window needs client area for scrolling") ); |
2b5f62a0 | 4487 | |
f47ae6e7 | 4488 | // No scrolling requested. |
8e217128 | 4489 | if ((dx == 0) && (dy == 0)) return; |
0fc5dbf5 | 4490 | |
4e5a4c69 | 4491 | #ifndef __WXGTK20__ |
35917d22 RR |
4492 | if (!m_updateRegion.IsEmpty()) |
4493 | { | |
4494 | m_updateRegion.Offset( dx, dy ); | |
0fc5dbf5 | 4495 | |
35917d22 RR |
4496 | int cw = 0; |
4497 | int ch = 0; | |
4498 | GetClientSize( &cw, &ch ); | |
4499 | m_updateRegion.Intersect( 0, 0, cw, ch ); | |
4500 | } | |
0fc5dbf5 | 4501 | |
3bcc8d15 RR |
4502 | if (!m_clearRegion.IsEmpty()) |
4503 | { | |
4504 | m_clearRegion.Offset( dx, dy ); | |
0fc5dbf5 | 4505 | |
3bcc8d15 RR |
4506 | int cw = 0; |
4507 | int ch = 0; | |
4508 | GetClientSize( &cw, &ch ); | |
4509 | m_clearRegion.Intersect( 0, 0, cw, ch ); | |
4510 | } | |
3fc6e5fa RR |
4511 | #endif |
4512 | ||
b6fa52db | 4513 | m_clipPaintRegion = TRUE; |
0fc5dbf5 | 4514 | |
da048e3d | 4515 | gtk_pizza_scroll( GTK_PIZZA(m_wxwindow), -dx, -dy ); |
0fc5dbf5 | 4516 | |
b6fa52db | 4517 | m_clipPaintRegion = FALSE; |
c801d85f | 4518 | } |
3723b7b1 | 4519 | |
4e5a4c69 | 4520 | |
3723b7b1 JS |
4521 | // Find the wxWindow at the current mouse position, also returning the mouse |
4522 | // position. | |
4523 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) | |
4524 | { | |
59a12e90 JS |
4525 | pt = wxGetMousePosition(); |
4526 | wxWindow* found = wxFindWindowAtPoint(pt); | |
4527 | return found; | |
3723b7b1 JS |
4528 | } |
4529 | ||
4530 | // Get the current mouse position. | |
4531 | wxPoint wxGetMousePosition() | |
4532 | { | |
59a12e90 JS |
4533 | /* This crashes when used within wxHelpContext, |
4534 | so we have to use the X-specific implementation below. | |
4535 | gint x, y; | |
4536 | GdkModifierType *mask; | |
4537 | (void) gdk_window_get_pointer(NULL, &x, &y, mask); | |
4538 | ||
4539 | return wxPoint(x, y); | |
4540 | */ | |
4541 | ||
3723b7b1 JS |
4542 | int x, y; |
4543 | GdkWindow* windowAtPtr = gdk_window_at_pointer(& x, & y); | |
59a12e90 | 4544 | |
37d81cc2 | 4545 | Display *display = windowAtPtr ? GDK_WINDOW_XDISPLAY(windowAtPtr) : GDK_DISPLAY(); |
59a12e90 JS |
4546 | Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display)); |
4547 | Window rootReturn, childReturn; | |
4548 | int rootX, rootY, winX, winY; | |
4549 | unsigned int maskReturn; | |
4550 | ||
4551 | XQueryPointer (display, | |
5cd09f0b RR |
4552 | rootWindow, |
4553 | &rootReturn, | |
59a12e90 JS |
4554 | &childReturn, |
4555 | &rootX, &rootY, &winX, &winY, &maskReturn); | |
4556 | return wxPoint(rootX, rootY); | |
4557 | ||
3723b7b1 JS |
4558 | } |
4559 | ||
4e5a4c69 RR |
4560 | // ---------------------------------------------------------------------------- |
4561 | // wxDCModule | |
4562 | // ---------------------------------------------------------------------------- | |
4563 | ||
4564 | class wxWinModule : public wxModule | |
4565 | { | |
4566 | public: | |
4567 | bool OnInit(); | |
4568 | void OnExit(); | |
4569 | ||
4570 | private: | |
4571 | DECLARE_DYNAMIC_CLASS(wxWinModule) | |
4572 | }; | |
4573 | ||
4574 | IMPLEMENT_DYNAMIC_CLASS(wxWinModule, wxModule) | |
4575 | ||
4576 | bool wxWinModule::OnInit() | |
4577 | { | |
994bc575 RR |
4578 | // g_eraseGC = gdk_gc_new( GDK_ROOT_PARENT() ); |
4579 | // gdk_gc_set_fill( g_eraseGC, GDK_SOLID ); | |
0fc5dbf5 | 4580 | |
4e5a4c69 RR |
4581 | return TRUE; |
4582 | } | |
4583 | ||
4584 | void wxWinModule::OnExit() | |
4585 | { | |
994bc575 RR |
4586 | if (g_eraseGC) |
4587 | gdk_gc_unref( g_eraseGC ); | |
4e5a4c69 RR |
4588 | } |
4589 | ||
6728fb61 | 4590 | // vi:sts=4:sw=4:et |