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