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