]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
faa94f3e | 2 | // Name: src/gtk/window.cpp |
9a33c3ef | 3 | // Purpose: wxWindowGTK implementation |
c801d85f | 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" |
88a7a4e1 WS |
18 | |
19 | #ifndef WX_PRECOMP | |
e4db172a | 20 | #include "wx/log.h" |
670f9935 | 21 | #include "wx/app.h" |
cca410b3 | 22 | #include "wx/toplevel.h" |
ed4b0fdc | 23 | #include "wx/dcclient.h" |
3b3dc801 | 24 | #include "wx/menu.h" |
9eddec69 | 25 | #include "wx/settings.h" |
246c5004 | 26 | #include "wx/msgdlg.h" |
18680f86 | 27 | #include "wx/math.h" |
88a7a4e1 WS |
28 | #endif |
29 | ||
bfeeb7f3 PC |
30 | #include "wx/dnd.h" |
31 | #include "wx/tooltip.h" | |
32 | #include "wx/caret.h" | |
48d011c8 | 33 | #include "wx/fontutil.h" |
55fb00a7 | 34 | #include "wx/scopeguard.h" |
8ab7b4c5 | 35 | #include "wx/sysopt.h" |
b4071e91 | 36 | |
fab591c5 | 37 | #include <ctype.h> |
c801d85f | 38 | |
9e691f46 | 39 | #include "wx/gtk/private.h" |
bbd92d1d | 40 | #include "wx/gtk/private/win_gtk.h" |
4a99d597 VS |
41 | #include "wx/gtk/private/event.h" |
42 | using namespace wxGTKImpl; | |
14b44999 | 43 | |
3ac8d3bc | 44 | #include <gdk/gdkx.h> |
6bc8a1c8 | 45 | |
14b44999 VS |
46 | #include <gdk/gdkkeysyms.h> |
47 | #if GTK_CHECK_VERSION(3,0,0) | |
48 | #include <gdk/gdkkeysyms-compat.h> | |
49 | #endif | |
50 | ||
868a2826 RR |
51 | //----------------------------------------------------------------------------- |
52 | // documentation on internals | |
53 | //----------------------------------------------------------------------------- | |
54 | ||
55 | /* | |
56 | I have been asked several times about writing some documentation about | |
77ffb593 | 57 | the GTK port of wxWidgets, especially its internal structures. Obviously, |
868a2826 | 58 | you cannot understand wxGTK without knowing a little about the GTK, but |
47d67540 | 59 | some more information about what the wxWindow, which is the base class |
868a2826 | 60 | for all other window classes, does seems required as well. |
47d67540 | 61 | |
30760ce7 RR |
62 | I) |
63 | ||
868a2826 | 64 | What does wxWindow do? It contains the common interface for the following |
e380f72b | 65 | jobs of its descendants: |
47d67540 | 66 | |
868a2826 | 67 | 1) Define the rudimentary behaviour common to all window classes, such as |
e380f72b RR |
68 | resizing, intercepting user input (so as to make it possible to use these |
69 | events for special purposes in a derived class), window names etc. | |
868a2826 RR |
70 | |
71 | 2) Provide the possibility to contain and manage children, if the derived | |
72 | class is allowed to contain children, which holds true for those window | |
e380f72b | 73 | classes which do not display a native GTK widget. To name them, these |
868a2826 | 74 | classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame- |
47d67540 | 75 | work classes are a special case and are handled a bit differently from |
e380f72b | 76 | the rest. The same holds true for the wxNotebook class. |
47d67540 | 77 | |
868a2826 RR |
78 | 3) Provide the possibility to draw into a client area of a window. This, |
79 | too, only holds true for classes that do not display a native GTK widget | |
80 | as above. | |
47d67540 | 81 | |
e380f72b RR |
82 | 4) Provide the entire mechanism for scrolling widgets. This actual inter- |
83 | face for this is usually in wxScrolledWindow, but the GTK implementation | |
868a2826 | 84 | is in this class. |
47d67540 | 85 | |
868a2826 RR |
86 | 5) A multitude of helper or extra methods for special purposes, such as |
87 | Drag'n'Drop, managing validators etc. | |
47d67540 | 88 | |
30760ce7 RR |
89 | 6) Display a border (sunken, raised, simple or none). |
90 | ||
77ffb593 | 91 | Normally one might expect, that one wxWidgets window would always correspond |
6a17b868 | 92 | to one GTK widget. Under GTK, there is no such all-round widget that has all |
868a2826 RR |
93 | the functionality. Moreover, the GTK defines a client area as a different |
94 | widget from the actual widget you are handling. Last but not least some | |
95 | special classes (e.g. wxFrame) handle different categories of widgets and | |
96 | still have the possibility to draw something in the client area. | |
97 | It was therefore required to write a special purpose GTK widget, that would | |
77ffb593 | 98 | represent a client area in the sense of wxWidgets capable to do the jobs |
868a2826 RR |
99 | 2), 3) and 4). I have written this class and it resides in win_gtk.c of |
100 | this directory. | |
47d67540 | 101 | |
868a2826 | 102 | All windows must have a widget, with which they interact with other under- |
e380f72b | 103 | lying GTK widgets. It is this widget, e.g. that has to be resized etc and |
90e572f1 | 104 | the wxWindow class has a member variable called m_widget which holds a |
e380f72b RR |
105 | pointer to this widget. When the window class represents a GTK native widget, |
106 | this is (in most cases) the only GTK widget the class manages. E.g. the | |
f8e045e2 | 107 | wxStaticText class handles only a GtkLabel widget a pointer to which you |
e380f72b | 108 | can find in m_widget (defined in wxWindow) |
8bbe427f | 109 | |
e380f72b | 110 | When the class has a client area for drawing into and for containing children |
08f53168 PC |
111 | it has to handle the client area widget (of the type wxPizza, defined in |
112 | win_gtk.cpp), but there could be any number of widgets, handled by a class. | |
8bbe427f VZ |
113 | The common rule for all windows is only, that the widget that interacts with |
114 | the rest of GTK must be referenced in m_widget and all other widgets must be | |
115 | children of this widget on the GTK level. The top-most widget, which also | |
116 | represents the client area, must be in the m_wxwindow field and must be of | |
08f53168 | 117 | the type wxPizza. |
47d67540 | 118 | |
868a2826 RR |
119 | As I said, the window classes that display a GTK native widget only have |
120 | one widget, so in the case of e.g. the wxButton class m_widget holds a | |
121 | pointer to a GtkButton widget. But windows with client areas (for drawing | |
122 | and children) have a m_widget field that is a pointer to a GtkScrolled- | |
08f53168 | 123 | Window and a m_wxwindow field that is pointer to a wxPizza and this |
868a2826 | 124 | one is (in the GTK sense) a child of the GtkScrolledWindow. |
47d67540 | 125 | |
868a2826 | 126 | If the m_wxwindow field is set, then all input to this widget is inter- |
77ffb593 | 127 | cepted and sent to the wxWidgets class. If not, all input to the widget |
868a2826 | 128 | that gets pointed to by m_widget gets intercepted and sent to the class. |
148cd9b6 | 129 | |
30760ce7 | 130 | II) |
148cd9b6 | 131 | |
77ffb593 | 132 | The design of scrolling in wxWidgets is markedly different from that offered |
30760ce7 RR |
133 | by the GTK itself and therefore we cannot simply take it as it is. In GTK, |
134 | clicking on a scrollbar belonging to scrolled window will inevitably move | |
77ffb593 | 135 | the window. In wxWidgets, the scrollbar will only emit an event, send this |
30760ce7 | 136 | to (normally) a wxScrolledWindow and that class will call ScrollWindow() |
08f53168 | 137 | which actually moves the window and its sub-windows. Note that wxPizza |
77ffb593 | 138 | memorizes how much it has been scrolled but that wxWidgets forgets this |
30760ce7 | 139 | so that the two coordinates systems have to be kept in synch. This is done |
08f53168 | 140 | in various places using the pizza->m_scroll_x and pizza->m_scroll_y values. |
148cd9b6 VZ |
141 | |
142 | III) | |
143 | ||
6a17b868 | 144 | Singularly the most broken code in GTK is the code that is supposed to |
30760ce7 RR |
145 | inform subwindows (child windows) about new positions. Very often, duplicate |
146 | events are sent without changes in size or position, equally often no | |
147 | events are sent at all (All this is due to a bug in the GtkContainer code | |
148 | which got fixed in GTK 1.2.6). For that reason, wxGTK completely ignores | |
149 | GTK's own system and it simply waits for size events for toplevel windows | |
150 | and then iterates down the respective size events to all window. This has | |
90e572f1 | 151 | the disadvantage that windows might get size events before the GTK widget |
30760ce7 | 152 | actually has the reported size. This doesn't normally pose any problem, but |
90e572f1 | 153 | the OpenGL drawing routines rely on correct behaviour. Therefore, I have |
30760ce7 RR |
154 | added the m_nativeSizeEvents flag, which is true only for the OpenGL canvas, |
155 | i.e. the wxGLCanvas will emit a size event, when (and not before) the X11 | |
90e572f1 | 156 | window that is used for OpenGL output really has that size (as reported by |
30760ce7 RR |
157 | GTK). |
158 | ||
159 | IV) | |
148cd9b6 | 160 | |
30760ce7 | 161 | If someone at some point of time feels the immense desire to have a look at, |
90e572f1 MR |
162 | change or attempt to optimise the Refresh() logic, this person will need an |
163 | intimate understanding of what "draw" and "expose" events are and what | |
164 | they are used for, in particular when used in connection with GTK's | |
30760ce7 | 165 | own windowless widgets. Beware. |
148cd9b6 | 166 | |
30760ce7 | 167 | V) |
148cd9b6 | 168 | |
30760ce7 RR |
169 | Cursors, too, have been a constant source of pleasure. The main difficulty |
170 | is that a GdkWindow inherits a cursor if the programmer sets a new cursor | |
c2246a38 RR |
171 | for the parent. To prevent this from doing too much harm, SetCursor calls |
172 | GTKUpdateCursor, which will recursively re-set the cursors of all child windows. | |
30760ce7 RR |
173 | Also don't forget that cursors (like much else) are connected to GdkWindows, |
174 | not GtkWidgets and that the "window" field of a GtkWidget might very well | |
90e572f1 | 175 | point to the GdkWindow of the parent widget (-> "window-less widget") and |
30760ce7 | 176 | that the two obviously have very different meanings. |
868a2826 RR |
177 | */ |
178 | ||
f03fc89f VZ |
179 | //----------------------------------------------------------------------------- |
180 | // data | |
181 | //----------------------------------------------------------------------------- | |
182 | ||
b541538f PC |
183 | // Don't allow event propagation during drag |
184 | bool g_blockEventsOnDrag; | |
185 | // Don't allow mouse event propagation during scroll | |
186 | bool g_blockEventsOnScroll; | |
238d735d | 187 | extern wxCursor g_globalCursor; |
f68586e5 | 188 | |
1e6feb95 VZ |
189 | // mouse capture state: the window which has it and if the mouse is currently |
190 | // inside it | |
d3b9f782 | 191 | static wxWindowGTK *g_captureWindow = NULL; |
0a164d4c | 192 | static bool g_captureWindowHasMouse = false; |
1e6feb95 | 193 | |
22f43cb5 VS |
194 | // The window that currently has focus: |
195 | static wxWindowGTK *gs_currentFocus = NULL; | |
196 | // The window that is scheduled to get focus in the next event loop iteration | |
197 | // or NULL if there's no pending focus change: | |
198 | static wxWindowGTK *gs_pendingFocus = NULL; | |
1e6feb95 | 199 | |
bd2e08d0 VS |
200 | // the window that has deferred focus-out event pending, if any (see |
201 | // GTKAddDeferredFocusOut() for details) | |
202 | static wxWindowGTK *gs_deferredFocusOut = NULL; | |
d7fa7eaa | 203 | |
5e513780 RR |
204 | // global variables because GTK+ DnD want to have the |
205 | // mouse event that caused it | |
d3b9f782 | 206 | GdkEvent *g_lastMouseEvent = NULL; |
5e513780 | 207 | int g_lastButtonNumber = 0; |
8f9850dd | 208 | |
2e563988 RR |
209 | //----------------------------------------------------------------------------- |
210 | // debug | |
211 | //----------------------------------------------------------------------------- | |
212 | ||
6cad4f1b | 213 | // the trace mask used for the focus debugging messages |
9a83f860 | 214 | #define TRACE_FOCUS wxT("focus") |
6cad4f1b | 215 | |
47c93b63 RR |
216 | //----------------------------------------------------------------------------- |
217 | // "size_request" of m_widget | |
218 | //----------------------------------------------------------------------------- | |
219 | ||
865bb325 | 220 | extern "C" { |
9800347d FM |
221 | static void |
222 | wxgtk_window_size_request_callback(GtkWidget * WXUNUSED(widget), | |
223 | GtkRequisition *requisition, | |
224 | wxWindow * win) | |
47c93b63 | 225 | { |
e1f448ee | 226 | int w, h; |
47c93b63 | 227 | win->GetSize( &w, &h ); |
e1f448ee VZ |
228 | if (w < 2) |
229 | w = 2; | |
230 | if (h < 2) | |
231 | h = 2; | |
1e6feb95 | 232 | |
47c93b63 RR |
233 | requisition->height = h; |
234 | requisition->width = w; | |
235 | } | |
865bb325 | 236 | } |
47c93b63 | 237 | |
c801d85f | 238 | //----------------------------------------------------------------------------- |
034be888 | 239 | // "expose_event" of m_wxwindow |
c801d85f KB |
240 | //----------------------------------------------------------------------------- |
241 | ||
865bb325 | 242 | extern "C" { |
7f7beb1d | 243 | static gboolean |
f089940f | 244 | gtk_window_expose_callback( GtkWidget*, |
7f7beb1d MR |
245 | GdkEventExpose *gdk_event, |
246 | wxWindow *win ) | |
47d67540 | 247 | { |
f089940f | 248 | if (gdk_event->window == win->GTKGetDrawingWindow()) |
3d2d8da1 | 249 | { |
8d49fda6 PC |
250 | win->GetUpdateRegion() = wxRegion( gdk_event->region ); |
251 | win->GtkSendPaintEvents(); | |
3d2d8da1 | 252 | } |
90e572f1 | 253 | // Let parent window draw window-less widgets |
2109c024 | 254 | return FALSE; |
b6fa52db | 255 | } |
865bb325 | 256 | } |
b6fa52db | 257 | |
75f661bb | 258 | #ifndef __WXUNIVERSAL__ |
08f53168 | 259 | //----------------------------------------------------------------------------- |
75f661bb | 260 | // "expose_event" from m_wxwindow->parent, for drawing border |
08f53168 PC |
261 | //----------------------------------------------------------------------------- |
262 | ||
08f53168 PC |
263 | extern "C" { |
264 | static gboolean | |
6de67633 | 265 | expose_event_border(GtkWidget* widget, GdkEventExpose* gdk_event, wxWindow* win) |
08f53168 | 266 | { |
f089940f | 267 | if (gdk_event->window != gtk_widget_get_parent_window(win->m_wxwindow)) |
75f661bb PC |
268 | return false; |
269 | ||
6e7cf3bd PC |
270 | if (!win->IsShown()) |
271 | return false; | |
272 | ||
989d151c PC |
273 | GtkAllocation alloc; |
274 | gtk_widget_get_allocation(win->m_wxwindow, &alloc); | |
75f661bb PC |
275 | const int x = alloc.x; |
276 | const int y = alloc.y; | |
277 | const int w = alloc.width; | |
278 | const int h = alloc.height; | |
279 | ||
280 | if (w <= 0 || h <= 0) | |
08f53168 PC |
281 | return false; |
282 | ||
08f53168 PC |
283 | if (win->HasFlag(wxBORDER_SIMPLE)) |
284 | { | |
830910cc | 285 | gdk_draw_rectangle(gdk_event->window, |
08f09504 | 286 | gtk_widget_get_style(widget)->black_gc, false, x, y, w - 1, h - 1); |
08f53168 PC |
287 | } |
288 | else | |
289 | { | |
290 | GtkShadowType shadow = GTK_SHADOW_IN; | |
291 | if (win->HasFlag(wxBORDER_RAISED)) | |
292 | shadow = GTK_SHADOW_OUT; | |
03eaa52a PC |
293 | |
294 | // Style detail to use | |
295 | const char* detail; | |
75f661bb | 296 | if (win->m_widget == win->m_wxwindow) |
03eaa52a PC |
297 | // for non-scrollable wxWindows |
298 | detail = "entry"; | |
299 | else | |
300 | // for scrollable ones | |
301 | detail = "viewport"; | |
302 | ||
4f4f76de PC |
303 | // clip rect is required to avoid painting background |
304 | // over upper left (w,h) of parent window | |
305 | GdkRectangle clipRect = { x, y, w, h }; | |
08f53168 | 306 | gtk_paint_shadow( |
08f09504 | 307 | gtk_widget_get_style(win->m_wxwindow), gdk_event->window, GTK_STATE_NORMAL, |
4f4f76de | 308 | shadow, &clipRect, wxGTKPrivate::GetEntryWidget(), detail, x, y, w, h); |
08f53168 | 309 | } |
75f661bb PC |
310 | return false; |
311 | } | |
312 | } | |
313 | ||
314 | //----------------------------------------------------------------------------- | |
315 | // "parent_set" from m_wxwindow | |
316 | //----------------------------------------------------------------------------- | |
08f53168 | 317 | |
75f661bb PC |
318 | extern "C" { |
319 | static void | |
cb0c51ac | 320 | parent_set(GtkWidget* widget, GtkWidget* old_parent, wxWindow* win) |
75f661bb PC |
321 | { |
322 | if (old_parent) | |
323 | { | |
324 | g_signal_handlers_disconnect_by_func( | |
325 | old_parent, (void*)expose_event_border, win); | |
326 | } | |
08f09504 PC |
327 | GtkWidget* parent = gtk_widget_get_parent(widget); |
328 | if (parent) | |
75f661bb | 329 | { |
08f09504 | 330 | g_signal_connect_after(parent, "expose_event", |
75f661bb PC |
331 | G_CALLBACK(expose_event_border), win); |
332 | } | |
08f53168 PC |
333 | } |
334 | } | |
335 | #endif // !__WXUNIVERSAL__ | |
336 | ||
c801d85f | 337 | //----------------------------------------------------------------------------- |
b292e2f5 | 338 | // "key_press_event" from any window |
c801d85f | 339 | //----------------------------------------------------------------------------- |
c801d85f | 340 | |
7da1b5f9 RD |
341 | // These are used when transforming Ctrl-alpha to ascii values 1-26 |
342 | inline bool wxIsLowerChar(int code) | |
343 | { | |
344 | return (code >= 'a' && code <= 'z' ); | |
345 | } | |
346 | ||
347 | inline bool wxIsUpperChar(int code) | |
348 | { | |
349 | return (code >= 'A' && code <= 'Z' ); | |
350 | } | |
351 | ||
352 | ||
74710601 | 353 | // set WXTRACE to this to see the key event codes on the console |
9a83f860 | 354 | #define TRACE_KEYS wxT("keyevent") |
f17393f1 | 355 | |
1c6896d7 VZ |
356 | // translates an X key symbol to WXK_XXX value |
357 | // | |
358 | // if isChar is true it means that the value returned will be used for EVT_CHAR | |
359 | // event and then we choose the logical WXK_XXX, i.e. '/' for GDK_KP_Divide, | |
360 | // for example, while if it is false it means that the value is going to be | |
361 | // used for KEY_DOWN/UP events and then we translate GDK_KP_Divide to | |
362 | // WXK_NUMPAD_DIVIDE | |
363 | static long wxTranslateKeySymToWXKey(KeySym keysym, bool isChar) | |
364 | { | |
365 | long key_code; | |
366 | ||
367 | switch ( keysym ) | |
368 | { | |
369 | // Shift, Control and Alt don't generate the CHAR events at all | |
370 | case GDK_Shift_L: | |
371 | case GDK_Shift_R: | |
372 | key_code = isChar ? 0 : WXK_SHIFT; | |
373 | break; | |
374 | case GDK_Control_L: | |
375 | case GDK_Control_R: | |
376 | key_code = isChar ? 0 : WXK_CONTROL; | |
377 | break; | |
378 | case GDK_Meta_L: | |
379 | case GDK_Meta_R: | |
380 | case GDK_Alt_L: | |
381 | case GDK_Alt_R: | |
382 | case GDK_Super_L: | |
383 | case GDK_Super_R: | |
384 | key_code = isChar ? 0 : WXK_ALT; | |
385 | break; | |
386 | ||
387 | // neither do the toggle modifies | |
388 | case GDK_Scroll_Lock: | |
389 | key_code = isChar ? 0 : WXK_SCROLL; | |
390 | break; | |
391 | ||
392 | case GDK_Caps_Lock: | |
393 | key_code = isChar ? 0 : WXK_CAPITAL; | |
394 | break; | |
395 | ||
396 | case GDK_Num_Lock: | |
397 | key_code = isChar ? 0 : WXK_NUMLOCK; | |
398 | break; | |
399 | ||
400 | ||
401 | // various other special keys | |
402 | case GDK_Menu: | |
403 | key_code = WXK_MENU; | |
404 | break; | |
405 | ||
406 | case GDK_Help: | |
407 | key_code = WXK_HELP; | |
408 | break; | |
409 | ||
410 | case GDK_BackSpace: | |
411 | key_code = WXK_BACK; | |
412 | break; | |
413 | ||
414 | case GDK_ISO_Left_Tab: | |
415 | case GDK_Tab: | |
416 | key_code = WXK_TAB; | |
417 | break; | |
418 | ||
419 | case GDK_Linefeed: | |
420 | case GDK_Return: | |
421 | key_code = WXK_RETURN; | |
422 | break; | |
423 | ||
424 | case GDK_Clear: | |
425 | key_code = WXK_CLEAR; | |
426 | break; | |
427 | ||
428 | case GDK_Pause: | |
429 | key_code = WXK_PAUSE; | |
430 | break; | |
431 | ||
432 | case GDK_Select: | |
433 | key_code = WXK_SELECT; | |
434 | break; | |
435 | ||
436 | case GDK_Print: | |
437 | key_code = WXK_PRINT; | |
438 | break; | |
439 | ||
440 | case GDK_Execute: | |
441 | key_code = WXK_EXECUTE; | |
442 | break; | |
443 | ||
444 | case GDK_Escape: | |
445 | key_code = WXK_ESCAPE; | |
446 | break; | |
447 | ||
448 | // cursor and other extended keyboard keys | |
449 | case GDK_Delete: | |
450 | key_code = WXK_DELETE; | |
451 | break; | |
452 | ||
453 | case GDK_Home: | |
454 | key_code = WXK_HOME; | |
455 | break; | |
456 | ||
457 | case GDK_Left: | |
458 | key_code = WXK_LEFT; | |
459 | break; | |
460 | ||
461 | case GDK_Up: | |
462 | key_code = WXK_UP; | |
463 | break; | |
464 | ||
465 | case GDK_Right: | |
466 | key_code = WXK_RIGHT; | |
467 | break; | |
468 | ||
469 | case GDK_Down: | |
470 | key_code = WXK_DOWN; | |
471 | break; | |
472 | ||
473 | case GDK_Prior: // == GDK_Page_Up | |
faa94f3e | 474 | key_code = WXK_PAGEUP; |
1c6896d7 VZ |
475 | break; |
476 | ||
477 | case GDK_Next: // == GDK_Page_Down | |
faa94f3e | 478 | key_code = WXK_PAGEDOWN; |
1c6896d7 VZ |
479 | break; |
480 | ||
481 | case GDK_End: | |
482 | key_code = WXK_END; | |
483 | break; | |
484 | ||
485 | case GDK_Begin: | |
486 | key_code = WXK_HOME; | |
487 | break; | |
488 | ||
489 | case GDK_Insert: | |
490 | key_code = WXK_INSERT; | |
491 | break; | |
492 | ||
493 | ||
494 | // numpad keys | |
495 | case GDK_KP_0: | |
496 | case GDK_KP_1: | |
497 | case GDK_KP_2: | |
498 | case GDK_KP_3: | |
499 | case GDK_KP_4: | |
500 | case GDK_KP_5: | |
501 | case GDK_KP_6: | |
502 | case GDK_KP_7: | |
503 | case GDK_KP_8: | |
504 | case GDK_KP_9: | |
2a230426 | 505 | key_code = (isChar ? '0' : int(WXK_NUMPAD0)) + keysym - GDK_KP_0; |
1c6896d7 VZ |
506 | break; |
507 | ||
508 | case GDK_KP_Space: | |
2a230426 | 509 | key_code = isChar ? ' ' : int(WXK_NUMPAD_SPACE); |
1c6896d7 VZ |
510 | break; |
511 | ||
512 | case GDK_KP_Tab: | |
513 | key_code = isChar ? WXK_TAB : WXK_NUMPAD_TAB; | |
514 | break; | |
515 | ||
516 | case GDK_KP_Enter: | |
517 | key_code = isChar ? WXK_RETURN : WXK_NUMPAD_ENTER; | |
518 | break; | |
519 | ||
520 | case GDK_KP_F1: | |
521 | key_code = isChar ? WXK_F1 : WXK_NUMPAD_F1; | |
522 | break; | |
523 | ||
524 | case GDK_KP_F2: | |
525 | key_code = isChar ? WXK_F2 : WXK_NUMPAD_F2; | |
526 | break; | |
527 | ||
528 | case GDK_KP_F3: | |
529 | key_code = isChar ? WXK_F3 : WXK_NUMPAD_F3; | |
530 | break; | |
531 | ||
532 | case GDK_KP_F4: | |
533 | key_code = isChar ? WXK_F4 : WXK_NUMPAD_F4; | |
534 | break; | |
535 | ||
536 | case GDK_KP_Home: | |
537 | key_code = isChar ? WXK_HOME : WXK_NUMPAD_HOME; | |
538 | break; | |
539 | ||
540 | case GDK_KP_Left: | |
541 | key_code = isChar ? WXK_LEFT : WXK_NUMPAD_LEFT; | |
542 | break; | |
543 | ||
544 | case GDK_KP_Up: | |
545 | key_code = isChar ? WXK_UP : WXK_NUMPAD_UP; | |
546 | break; | |
547 | ||
548 | case GDK_KP_Right: | |
549 | key_code = isChar ? WXK_RIGHT : WXK_NUMPAD_RIGHT; | |
550 | break; | |
551 | ||
552 | case GDK_KP_Down: | |
553 | key_code = isChar ? WXK_DOWN : WXK_NUMPAD_DOWN; | |
554 | break; | |
555 | ||
556 | case GDK_KP_Prior: // == GDK_KP_Page_Up | |
faa94f3e | 557 | key_code = isChar ? WXK_PAGEUP : WXK_NUMPAD_PAGEUP; |
1c6896d7 VZ |
558 | break; |
559 | ||
560 | case GDK_KP_Next: // == GDK_KP_Page_Down | |
faa94f3e | 561 | key_code = isChar ? WXK_PAGEDOWN : WXK_NUMPAD_PAGEDOWN; |
1c6896d7 VZ |
562 | break; |
563 | ||
564 | case GDK_KP_End: | |
565 | key_code = isChar ? WXK_END : WXK_NUMPAD_END; | |
566 | break; | |
567 | ||
568 | case GDK_KP_Begin: | |
569 | key_code = isChar ? WXK_HOME : WXK_NUMPAD_BEGIN; | |
570 | break; | |
571 | ||
572 | case GDK_KP_Insert: | |
573 | key_code = isChar ? WXK_INSERT : WXK_NUMPAD_INSERT; | |
574 | break; | |
575 | ||
576 | case GDK_KP_Delete: | |
577 | key_code = isChar ? WXK_DELETE : WXK_NUMPAD_DELETE; | |
578 | break; | |
579 | ||
580 | case GDK_KP_Equal: | |
2a230426 | 581 | key_code = isChar ? '=' : int(WXK_NUMPAD_EQUAL); |
1c6896d7 VZ |
582 | break; |
583 | ||
584 | case GDK_KP_Multiply: | |
2a230426 | 585 | key_code = isChar ? '*' : int(WXK_NUMPAD_MULTIPLY); |
1c6896d7 VZ |
586 | break; |
587 | ||
588 | case GDK_KP_Add: | |
2a230426 | 589 | key_code = isChar ? '+' : int(WXK_NUMPAD_ADD); |
1c6896d7 VZ |
590 | break; |
591 | ||
592 | case GDK_KP_Separator: | |
593 | // FIXME: what is this? | |
2a230426 | 594 | key_code = isChar ? '.' : int(WXK_NUMPAD_SEPARATOR); |
1c6896d7 VZ |
595 | break; |
596 | ||
597 | case GDK_KP_Subtract: | |
2a230426 | 598 | key_code = isChar ? '-' : int(WXK_NUMPAD_SUBTRACT); |
1c6896d7 VZ |
599 | break; |
600 | ||
601 | case GDK_KP_Decimal: | |
2a230426 | 602 | key_code = isChar ? '.' : int(WXK_NUMPAD_DECIMAL); |
1c6896d7 VZ |
603 | break; |
604 | ||
605 | case GDK_KP_Divide: | |
2a230426 | 606 | key_code = isChar ? '/' : int(WXK_NUMPAD_DIVIDE); |
1c6896d7 VZ |
607 | break; |
608 | ||
609 | ||
610 | // function keys | |
611 | case GDK_F1: | |
612 | case GDK_F2: | |
613 | case GDK_F3: | |
614 | case GDK_F4: | |
615 | case GDK_F5: | |
616 | case GDK_F6: | |
617 | case GDK_F7: | |
618 | case GDK_F8: | |
619 | case GDK_F9: | |
620 | case GDK_F10: | |
621 | case GDK_F11: | |
622 | case GDK_F12: | |
623 | key_code = WXK_F1 + keysym - GDK_F1; | |
624 | break; | |
625 | ||
626 | default: | |
627 | key_code = 0; | |
628 | } | |
629 | ||
630 | return key_code; | |
631 | } | |
632 | ||
633 | static inline bool wxIsAsciiKeysym(KeySym ks) | |
634 | { | |
635 | return ks < 256; | |
636 | } | |
637 | ||
a3c15d89 VS |
638 | static void wxFillOtherKeyEventFields(wxKeyEvent& event, |
639 | wxWindowGTK *win, | |
640 | GdkEventKey *gdk_event) | |
641 | { | |
a3c15d89 | 642 | event.SetTimestamp( gdk_event->time ); |
cfa8c7d6 | 643 | event.SetId(win->GetId()); |
d0fb62a6 | 644 | |
a3c15d89 VS |
645 | event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK) != 0; |
646 | event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK) != 0; | |
647 | event.m_altDown = (gdk_event->state & GDK_MOD1_MASK) != 0; | |
87ec008f | 648 | event.m_metaDown = (gdk_event->state & GDK_META_MASK) != 0; |
d0fb62a6 VZ |
649 | |
650 | // Normally we take the state of modifiers directly from the low level GDK | |
651 | // event but unfortunately GDK uses a different convention from MSW for the | |
652 | // key events corresponding to the modifier keys themselves: in it, when | |
653 | // e.g. Shift key is pressed, GDK_SHIFT_MASK is not set while it is set | |
654 | // when Shift is released. Under MSW the situation is exactly reversed and | |
655 | // the modifier corresponding to the key is set when it is pressed and | |
656 | // unset when it is released. To ensure consistent behaviour between | |
657 | // platforms (and because it seems to make slightly more sense, although | |
658 | // arguably both behaviours are reasonable) we follow MSW here. | |
659 | // | |
660 | // Final notice: we set the flags to the desired value instead of just | |
661 | // inverting them because they are not set correctly (i.e. in the same way | |
662 | // as for the real events generated by the user) for wxUIActionSimulator- | |
663 | // produced events and it seems better to keep that class code the same | |
664 | // among all platforms and fix the discrepancy here instead of adding | |
665 | // wxGTK-specific code to wxUIActionSimulator. | |
666 | const bool isPress = gdk_event->type == GDK_KEY_PRESS; | |
667 | switch ( gdk_event->keyval ) | |
668 | { | |
669 | case GDK_Shift_L: | |
670 | case GDK_Shift_R: | |
671 | event.m_shiftDown = isPress; | |
672 | break; | |
673 | ||
674 | case GDK_Control_L: | |
675 | case GDK_Control_R: | |
676 | event.m_controlDown = isPress; | |
677 | break; | |
678 | ||
679 | case GDK_Alt_L: | |
680 | case GDK_Alt_R: | |
681 | event.m_altDown = isPress; | |
682 | break; | |
683 | ||
684 | case GDK_Meta_L: | |
685 | case GDK_Meta_R: | |
686 | case GDK_Super_L: | |
687 | case GDK_Super_R: | |
688 | event.m_metaDown = isPress; | |
689 | break; | |
690 | } | |
691 | ||
a3c15d89 | 692 | event.m_rawCode = (wxUint32) gdk_event->keyval; |
5995a84f | 693 | event.m_rawFlags = gdk_event->hardware_keycode; |
d0fb62a6 | 694 | |
f795e586 PC |
695 | wxGetMousePosition(&event.m_x, &event.m_y); |
696 | win->ScreenToClient(&event.m_x, &event.m_y); | |
a3c15d89 VS |
697 | event.SetEventObject( win ); |
698 | } | |
699 | ||
700 | ||
74710601 VZ |
701 | static bool |
702 | wxTranslateGTKKeyEventToWx(wxKeyEvent& event, | |
703 | wxWindowGTK *win, | |
704 | GdkEventKey *gdk_event) | |
47d67540 | 705 | { |
1c6896d7 VZ |
706 | // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string |
707 | // but only event->keyval which is quite useless to us, so remember | |
708 | // the last character from GDK_KEY_PRESS and reuse it as last resort | |
709 | // | |
710 | // NB: should be MT-safe as we're always called from the main thread only | |
711 | static struct | |
712 | { | |
713 | KeySym keysym; | |
714 | long keycode; | |
715 | } s_lastKeyPress = { 0, 0 }; | |
716 | ||
717 | KeySym keysym = gdk_event->keyval; | |
0a62b197 | 718 | |
9a83f860 VZ |
719 | wxLogTrace(TRACE_KEYS, wxT("Key %s event: keysym = %ld"), |
720 | event.GetEventType() == wxEVT_KEY_UP ? wxT("release") | |
721 | : wxT("press"), | |
0a62b197 VZ |
722 | keysym); |
723 | ||
0a164d4c | 724 | long key_code = wxTranslateKeySymToWXKey(keysym, false /* !isChar */); |
1c6896d7 VZ |
725 | |
726 | if ( !key_code ) | |
727 | { | |
728 | // do we have the translation or is it a plain ASCII character? | |
729 | if ( (gdk_event->length == 1) || wxIsAsciiKeysym(keysym) ) | |
730 | { | |
731 | // we should use keysym if it is ASCII as X does some translations | |
732 | // like "I pressed while Control is down" => "Ctrl-I" == "TAB" | |
733 | // which we don't want here (but which we do use for OnChar()) | |
734 | if ( !wxIsAsciiKeysym(keysym) ) | |
735 | { | |
736 | keysym = (KeySym)gdk_event->string[0]; | |
737 | } | |
a2053b27 | 738 | |
1c6896d7 | 739 | // we want to always get the same key code when the same key is |
90e572f1 | 740 | // pressed regardless of the state of the modifiers, i.e. on a |
1c6896d7 VZ |
741 | // standard US keyboard pressing '5' or '%' ('5' key with |
742 | // Shift) should result in the same key code in OnKeyDown(): | |
743 | // '5' (although OnChar() will get either '5' or '%'). | |
744 | // | |
745 | // to do it we first translate keysym to keycode (== scan code) | |
746 | // and then back but always using the lower register | |
747 | Display *dpy = (Display *)wxGetDisplay(); | |
748 | KeyCode keycode = XKeysymToKeycode(dpy, keysym); | |
0a62b197 | 749 | |
9a83f860 | 750 | wxLogTrace(TRACE_KEYS, wxT("\t-> keycode %d"), keycode); |
0a62b197 | 751 | |
1c6896d7 VZ |
752 | KeySym keysymNormalized = XKeycodeToKeysym(dpy, keycode, 0); |
753 | ||
754 | // use the normalized, i.e. lower register, keysym if we've | |
755 | // got one | |
756 | key_code = keysymNormalized ? keysymNormalized : keysym; | |
757 | ||
758 | // as explained above, we want to have lower register key codes | |
759 | // normally but for the letter keys we want to have the upper ones | |
760 | // | |
761 | // NB: don't use XConvertCase() here, we want to do it for letters | |
762 | // only | |
763 | key_code = toupper(key_code); | |
764 | } | |
765 | else // non ASCII key, what to do? | |
766 | { | |
767 | // by default, ignore it | |
768 | key_code = 0; | |
769 | ||
770 | // but if we have cached information from the last KEY_PRESS | |
771 | if ( gdk_event->type == GDK_KEY_RELEASE ) | |
772 | { | |
773 | // then reuse it | |
774 | if ( keysym == s_lastKeyPress.keysym ) | |
775 | { | |
776 | key_code = s_lastKeyPress.keycode; | |
777 | } | |
778 | } | |
779 | } | |
780 | ||
781 | if ( gdk_event->type == GDK_KEY_PRESS ) | |
782 | { | |
783 | // remember it to be reused for KEY_UP event later | |
784 | s_lastKeyPress.keysym = keysym; | |
785 | s_lastKeyPress.keycode = key_code; | |
786 | } | |
787 | } | |
788 | ||
9a83f860 | 789 | wxLogTrace(TRACE_KEYS, wxT("\t-> wxKeyCode %ld"), key_code); |
c801d85f | 790 | |
74710601 | 791 | // sending unknown key events doesn't really make sense |
1c6896d7 | 792 | if ( !key_code ) |
0a164d4c | 793 | return false; |
3d6f7261 | 794 | |
276f883f VZ |
795 | event.m_keyCode = key_code; |
796 | ||
7333c0ef VZ |
797 | #if wxUSE_UNICODE |
798 | event.m_uniChar = gdk_keyval_to_unicode(key_code ? key_code : keysym); | |
799 | if ( !event.m_uniChar && event.m_keyCode <= WXK_DELETE ) | |
800 | { | |
801 | // Set Unicode key code to the ASCII equivalent for compatibility. E.g. | |
802 | // let RETURN generate the key event with both key and Unicode key | |
803 | // codes of 13. | |
804 | event.m_uniChar = event.m_keyCode; | |
805 | } | |
806 | #endif // wxUSE_UNICODE | |
807 | ||
1c6896d7 | 808 | // now fill all the other fields |
a3c15d89 | 809 | wxFillOtherKeyEventFields(event, win, gdk_event); |
0a164d4c | 810 | |
0a164d4c | 811 | return true; |
74710601 VZ |
812 | } |
813 | ||
7c5e6fc6 | 814 | |
a3c15d89 VS |
815 | struct wxGtkIMData |
816 | { | |
817 | GtkIMContext *context; | |
818 | GdkEventKey *lastKeyEvent; | |
819 | ||
820 | wxGtkIMData() | |
821 | { | |
822 | context = gtk_im_multicontext_new(); | |
823 | lastKeyEvent = NULL; | |
824 | } | |
825 | ~wxGtkIMData() | |
826 | { | |
3fe39b0c | 827 | g_object_unref (context); |
a3c15d89 VS |
828 | } |
829 | }; | |
a3c15d89 | 830 | |
2933f70a VZ |
831 | namespace |
832 | { | |
833 | ||
f47a3591 VZ |
834 | // Send wxEVT_CHAR_HOOK event to the parent of the window and return true only |
835 | // if it was processed (and not skipped). | |
836 | bool SendCharHookEvent(const wxKeyEvent& event, wxWindow *win) | |
2933f70a | 837 | { |
3a95f73c VZ |
838 | // wxEVT_CHAR_HOOK must be sent to allow the parent windows (e.g. a dialog |
839 | // which typically closes when Esc key is pressed in any of its controls) | |
5c16a699 VZ |
840 | // to handle key events in all of its children unless the mouse is captured |
841 | // in which case we consider that the keyboard should be "captured" too. | |
842 | if ( !g_captureWindow ) | |
2933f70a | 843 | { |
3a95f73c VZ |
844 | wxKeyEvent eventCharHook(wxEVT_CHAR_HOOK, event); |
845 | if ( win->HandleWindowEvent(eventCharHook) ) | |
846 | return true; | |
2933f70a VZ |
847 | } |
848 | ||
f47a3591 | 849 | return false; |
2933f70a VZ |
850 | } |
851 | ||
852 | } // anonymous namespace | |
853 | ||
865bb325 | 854 | extern "C" { |
7f7beb1d | 855 | static gboolean |
3591d10f | 856 | gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), |
7f7beb1d MR |
857 | GdkEventKey *gdk_event, |
858 | wxWindow *win ) | |
74710601 | 859 | { |
1c6896d7 VZ |
860 | if (!win->m_hasVMT) |
861 | return FALSE; | |
862 | if (g_blockEventsOnDrag) | |
863 | return FALSE; | |
f1272160 | 864 | |
f1272160 RR |
865 | wxKeyEvent event( wxEVT_KEY_DOWN ); |
866 | bool ret = false; | |
867 | bool return_after_IM = false; | |
868 | ||
84dc821c JS |
869 | if( wxTranslateGTKKeyEventToWx(event, win, gdk_event) ) |
870 | { | |
f47a3591 VZ |
871 | // Send the CHAR_HOOK event first |
872 | if ( SendCharHookEvent(event, win) ) | |
873 | { | |
874 | // Don't do anything at all with this event any more. | |
875 | return TRUE; | |
876 | } | |
877 | ||
84dc821c | 878 | // Emit KEY_DOWN event |
937013e0 | 879 | ret = win->HandleWindowEvent( event ); |
84dc821c JS |
880 | } |
881 | else | |
f1272160 RR |
882 | { |
883 | // Return after IM processing as we cannot do | |
884 | // anything with it anyhow. | |
885 | return_after_IM = true; | |
886 | } | |
887 | ||
9cbe96d0 | 888 | if (!ret && win->m_imData) |
f6fca1f8 | 889 | { |
9cbe96d0 VZ |
890 | win->m_imData->lastKeyEvent = gdk_event; |
891 | ||
f1272160 RR |
892 | // We should let GTK+ IM filter key event first. According to GTK+ 2.0 API |
893 | // docs, if IM filter returns true, no further processing should be done. | |
0a164d4c | 894 | // we should send the key_down event anyway. |
f1272160 | 895 | bool intercepted_by_IM = gtk_im_context_filter_keypress(win->m_imData->context, gdk_event); |
f6fca1f8 | 896 | win->m_imData->lastKeyEvent = NULL; |
f1272160 RR |
897 | if (intercepted_by_IM) |
898 | { | |
9a83f860 | 899 | wxLogTrace(TRACE_KEYS, wxT("Key event intercepted by IM")); |
7f7beb1d | 900 | return TRUE; |
f1272160 | 901 | } |
f6fca1f8 | 902 | } |
68567a96 | 903 | |
f1272160 | 904 | if (return_after_IM) |
7f7beb1d | 905 | return FALSE; |
68567a96 | 906 | |
50b58dec RD |
907 | #if wxUSE_ACCEL |
908 | if (!ret) | |
909 | { | |
910 | wxWindowGTK *ancestor = win; | |
911 | while (ancestor) | |
912 | { | |
913 | int command = ancestor->GetAcceleratorTable()->GetCommand( event ); | |
914 | if (command != -1) | |
915 | { | |
b1bb04c5 VS |
916 | wxCommandEvent menu_event( wxEVT_COMMAND_MENU_SELECTED, command ); |
917 | ret = ancestor->HandleWindowEvent( menu_event ); | |
918 | ||
919 | if ( !ret ) | |
920 | { | |
921 | // if the accelerator wasn't handled as menu event, try | |
922 | // it as button click (for compatibility with other | |
923 | // platforms): | |
924 | wxCommandEvent button_event( wxEVT_COMMAND_BUTTON_CLICKED, command ); | |
925 | ret = ancestor->HandleWindowEvent( button_event ); | |
926 | } | |
927 | ||
50b58dec RD |
928 | break; |
929 | } | |
930 | if (ancestor->IsTopLevel()) | |
931 | break; | |
932 | ancestor = ancestor->GetParent(); | |
933 | } | |
934 | } | |
935 | #endif // wxUSE_ACCEL | |
936 | ||
1ec3a984 RR |
937 | // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x |
938 | // will only be sent if it is not in an accelerator table. | |
2dde25b9 | 939 | if (!ret) |
d728dd40 | 940 | { |
7c5e6fc6 | 941 | long key_code; |
1c6896d7 | 942 | KeySym keysym = gdk_event->keyval; |
36025bcc | 943 | // Find key code for EVT_CHAR and EVT_CHAR_HOOK events |
0a164d4c | 944 | key_code = wxTranslateKeySymToWXKey(keysym, true /* isChar */); |
36025bcc | 945 | if ( !key_code ) |
1c6896d7 | 946 | { |
0b187670 | 947 | if ( wxIsAsciiKeysym(keysym) ) |
1ec3a984 | 948 | { |
36025bcc VS |
949 | // ASCII key |
950 | key_code = (unsigned char)keysym; | |
951 | } | |
0b187670 RR |
952 | // gdk_event->string is actually deprecated |
953 | else if ( gdk_event->length == 1 ) | |
954 | { | |
955 | key_code = (unsigned char)gdk_event->string[0]; | |
956 | } | |
36025bcc | 957 | } |
7c5e6fc6 | 958 | |
36025bcc VS |
959 | if ( key_code ) |
960 | { | |
f47a3591 VZ |
961 | wxKeyEvent eventChar(wxEVT_CHAR, event); |
962 | ||
9a83f860 | 963 | wxLogTrace(TRACE_KEYS, wxT("Char event: %ld"), key_code); |
7c5e6fc6 | 964 | |
f47a3591 | 965 | eventChar.m_keyCode = key_code; |
7c5e6fc6 | 966 | |
1dabdced RD |
967 | // To conform to the docs we need to translate Ctrl-alpha |
968 | // characters to values in the range 1-26. | |
f47a3591 | 969 | if ( eventChar.ControlDown() && |
7da1b5f9 | 970 | ( wxIsLowerChar(key_code) || wxIsUpperChar(key_code) )) |
1dabdced | 971 | { |
7da1b5f9 | 972 | if ( wxIsLowerChar(key_code) ) |
f47a3591 | 973 | eventChar.m_keyCode = key_code - 'a' + 1; |
7da1b5f9 | 974 | if ( wxIsUpperChar(key_code) ) |
f47a3591 | 975 | eventChar.m_keyCode = key_code - 'A' + 1; |
1dabdced | 976 | #if wxUSE_UNICODE |
079b6a77 | 977 | eventChar.m_uniChar = eventChar.m_keyCode; |
1dabdced | 978 | #endif |
7f7beb1d | 979 | } |
1dabdced | 980 | |
f47a3591 | 981 | ret = win->HandleWindowEvent(eventChar); |
f17393f1 | 982 | } |
d728dd40 | 983 | } |
4d3ab2a0 | 984 | |
c7b2e494 | 985 | return ret; |
2b5f62a0 | 986 | } |
865bb325 | 987 | } |
2b5f62a0 | 988 | |
865bb325 | 989 | extern "C" { |
7f7beb1d | 990 | static void |
e4161a2a | 991 | gtk_wxwindow_commit_cb (GtkIMContext * WXUNUSED(context), |
7f7beb1d MR |
992 | const gchar *str, |
993 | wxWindow *window) | |
2b5f62a0 | 994 | { |
f47a3591 | 995 | wxKeyEvent event( wxEVT_CHAR ); |
2b5f62a0 | 996 | |
a3c15d89 VS |
997 | // take modifiers, cursor position, timestamp etc. from the last |
998 | // key_press_event that was fed into Input Method: | |
999 | if (window->m_imData->lastKeyEvent) | |
1000 | { | |
1001 | wxFillOtherKeyEventFields(event, | |
1002 | window, window->m_imData->lastKeyEvent); | |
1003 | } | |
28c513cb RR |
1004 | else |
1005 | { | |
1006 | event.SetEventObject( window ); | |
1007 | } | |
a3c15d89 | 1008 | |
6256849f VS |
1009 | const wxString data(wxGTK_CONV_BACK_SYS(str)); |
1010 | if( data.empty() ) | |
5bfaca1b | 1011 | return; |
7c5e6fc6 | 1012 | |
6256849f | 1013 | for( wxString::const_iterator pstr = data.begin(); pstr != data.end(); ++pstr ) |
7c5e6fc6 | 1014 | { |
5bfaca1b VS |
1015 | #if wxUSE_UNICODE |
1016 | event.m_uniChar = *pstr; | |
f6fca1f8 | 1017 | // Backward compatible for ISO-8859-1 |
5bfaca1b | 1018 | event.m_keyCode = *pstr < 256 ? event.m_uniChar : 0; |
9a83f860 | 1019 | wxLogTrace(TRACE_KEYS, wxT("IM sent character '%c'"), event.m_uniChar); |
5bfaca1b | 1020 | #else |
6256849f | 1021 | event.m_keyCode = (char)*pstr; |
5bfaca1b | 1022 | #endif // wxUSE_UNICODE |
1dabdced RD |
1023 | |
1024 | // To conform to the docs we need to translate Ctrl-alpha | |
1025 | // characters to values in the range 1-26. | |
7da1b5f9 RD |
1026 | if ( event.ControlDown() && |
1027 | ( wxIsLowerChar(*pstr) || wxIsUpperChar(*pstr) )) | |
1dabdced | 1028 | { |
7da1b5f9 RD |
1029 | if ( wxIsLowerChar(*pstr) ) |
1030 | event.m_keyCode = *pstr - 'a' + 1; | |
1031 | if ( wxIsUpperChar(*pstr) ) | |
1032 | event.m_keyCode = *pstr - 'A' + 1; | |
1033 | ||
1dabdced RD |
1034 | event.m_keyCode = *pstr - 'a' + 1; |
1035 | #if wxUSE_UNICODE | |
1036 | event.m_uniChar = event.m_keyCode; | |
7f7beb1d MR |
1037 | #endif |
1038 | } | |
1dabdced | 1039 | |
f47a3591 | 1040 | window->HandleWindowEvent(event); |
2b5f62a0 VZ |
1041 | } |
1042 | } | |
865bb325 | 1043 | } |
2b5f62a0 VZ |
1044 | |
1045 | ||
b666df2c RR |
1046 | //----------------------------------------------------------------------------- |
1047 | // "key_release_event" from any window | |
1048 | //----------------------------------------------------------------------------- | |
1049 | ||
865bb325 | 1050 | extern "C" { |
7f7beb1d | 1051 | static gboolean |
e4161a2a | 1052 | gtk_window_key_release_callback( GtkWidget * WXUNUSED(widget), |
7f7beb1d MR |
1053 | GdkEventKey *gdk_event, |
1054 | wxWindowGTK *win ) | |
b666df2c | 1055 | { |
74710601 VZ |
1056 | if (!win->m_hasVMT) |
1057 | return FALSE; | |
b666df2c | 1058 | |
74710601 VZ |
1059 | if (g_blockEventsOnDrag) |
1060 | return FALSE; | |
b666df2c RR |
1061 | |
1062 | wxKeyEvent event( wxEVT_KEY_UP ); | |
74710601 | 1063 | if ( !wxTranslateGTKKeyEventToWx(event, win, gdk_event) ) |
b666df2c | 1064 | { |
90e572f1 | 1065 | // unknown key pressed, ignore (the event would be useless anyhow) |
74710601 | 1066 | return FALSE; |
b666df2c RR |
1067 | } |
1068 | ||
97687291 | 1069 | return win->GTKProcessEvent(event); |
b666df2c | 1070 | } |
865bb325 | 1071 | } |
b666df2c | 1072 | |
c5f9d156 VS |
1073 | // ============================================================================ |
1074 | // the mouse events | |
1075 | // ============================================================================ | |
1076 | ||
d1f2ac45 VZ |
1077 | // ---------------------------------------------------------------------------- |
1078 | // mouse event processing helpers | |
1079 | // ---------------------------------------------------------------------------- | |
1080 | ||
2daa0ce9 VZ |
1081 | static void AdjustEventButtonState(wxMouseEvent& event) |
1082 | { | |
1083 | // GDK reports the old state of the button for a button press event, but | |
1084 | // for compatibility with MSW and common sense we want m_leftDown be TRUE | |
1085 | // for a LEFT_DOWN event, not FALSE, so we will invert | |
1086 | // left/right/middleDown for the corresponding click events | |
1e6feb95 | 1087 | |
1a8caf94 RR |
1088 | if ((event.GetEventType() == wxEVT_LEFT_DOWN) || |
1089 | (event.GetEventType() == wxEVT_LEFT_DCLICK) || | |
1090 | (event.GetEventType() == wxEVT_LEFT_UP)) | |
1091 | { | |
1092 | event.m_leftDown = !event.m_leftDown; | |
1093 | return; | |
1094 | } | |
1095 | ||
1096 | if ((event.GetEventType() == wxEVT_MIDDLE_DOWN) || | |
1097 | (event.GetEventType() == wxEVT_MIDDLE_DCLICK) || | |
1098 | (event.GetEventType() == wxEVT_MIDDLE_UP)) | |
2daa0ce9 | 1099 | { |
1a8caf94 RR |
1100 | event.m_middleDown = !event.m_middleDown; |
1101 | return; | |
1102 | } | |
1103 | ||
1104 | if ((event.GetEventType() == wxEVT_RIGHT_DOWN) || | |
1105 | (event.GetEventType() == wxEVT_RIGHT_DCLICK) || | |
1106 | (event.GetEventType() == wxEVT_RIGHT_UP)) | |
1107 | { | |
1108 | event.m_rightDown = !event.m_rightDown; | |
1109 | return; | |
2daa0ce9 | 1110 | } |
e7cda1c3 VZ |
1111 | |
1112 | if ((event.GetEventType() == wxEVT_AUX1_DOWN) || | |
1113 | (event.GetEventType() == wxEVT_AUX1_DCLICK)) | |
1114 | { | |
1115 | event.m_aux1Down = true; | |
1116 | return; | |
1117 | } | |
1118 | ||
1119 | if ((event.GetEventType() == wxEVT_AUX2_DOWN) || | |
1120 | (event.GetEventType() == wxEVT_AUX2_DCLICK)) | |
1121 | { | |
1122 | event.m_aux2Down = true; | |
1123 | return; | |
1124 | } | |
2daa0ce9 VZ |
1125 | } |
1126 | ||
d1f2ac45 VZ |
1127 | // find the window to send the mouse event too |
1128 | static | |
1129 | wxWindowGTK *FindWindowForMouseEvent(wxWindowGTK *win, wxCoord& x, wxCoord& y) | |
1130 | { | |
7d4909b2 RR |
1131 | wxCoord xx = x; |
1132 | wxCoord yy = y; | |
1133 | ||
d1f2ac45 VZ |
1134 | if (win->m_wxwindow) |
1135 | { | |
08f53168 PC |
1136 | wxPizza* pizza = WX_PIZZA(win->m_wxwindow); |
1137 | xx += pizza->m_scroll_x; | |
1138 | yy += pizza->m_scroll_y; | |
d1f2ac45 VZ |
1139 | } |
1140 | ||
222ed1d6 | 1141 | wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); |
d1f2ac45 VZ |
1142 | while (node) |
1143 | { | |
b1d4dd7a | 1144 | wxWindowGTK *child = node->GetData(); |
d1f2ac45 | 1145 | |
b1d4dd7a | 1146 | node = node->GetNext(); |
d1f2ac45 VZ |
1147 | if (!child->IsShown()) |
1148 | continue; | |
1149 | ||
71ead4bf | 1150 | if (child->GTKIsTransparentForMouse()) |
d1f2ac45 VZ |
1151 | { |
1152 | // wxStaticBox is transparent in the box itself | |
1153 | int xx1 = child->m_x; | |
1154 | int yy1 = child->m_y; | |
1155 | int xx2 = child->m_x + child->m_width; | |
7408cf7f | 1156 | int yy2 = child->m_y + child->m_height; |
d1f2ac45 VZ |
1157 | |
1158 | // left | |
7d4909b2 | 1159 | if (((xx >= xx1) && (xx <= xx1+10) && (yy >= yy1) && (yy <= yy2)) || |
d1f2ac45 | 1160 | // right |
7d4909b2 | 1161 | ((xx >= xx2-10) && (xx <= xx2) && (yy >= yy1) && (yy <= yy2)) || |
d1f2ac45 | 1162 | // top |
7d4909b2 | 1163 | ((xx >= xx1) && (xx <= xx2) && (yy >= yy1) && (yy <= yy1+10)) || |
d1f2ac45 | 1164 | // bottom |
7d4909b2 | 1165 | ((xx >= xx1) && (xx <= xx2) && (yy >= yy2-1) && (yy <= yy2))) |
d1f2ac45 VZ |
1166 | { |
1167 | win = child; | |
1168 | x -= child->m_x; | |
1169 | y -= child->m_y; | |
1170 | break; | |
1171 | } | |
1172 | ||
1173 | } | |
1174 | else | |
1175 | { | |
d3b9f782 | 1176 | if ((child->m_wxwindow == NULL) && |
7d4909b2 RR |
1177 | (child->m_x <= xx) && |
1178 | (child->m_y <= yy) && | |
af3653dd RR |
1179 | (child->m_x+child->m_width >= xx) && |
1180 | (child->m_y+child->m_height >= yy)) | |
d1f2ac45 VZ |
1181 | { |
1182 | win = child; | |
1183 | x -= child->m_x; | |
1184 | y -= child->m_y; | |
1185 | break; | |
1186 | } | |
1187 | } | |
1188 | } | |
1189 | ||
1190 | return win; | |
1191 | } | |
1192 | ||
ef5c70f9 VZ |
1193 | // ---------------------------------------------------------------------------- |
1194 | // common event handlers helpers | |
1195 | // ---------------------------------------------------------------------------- | |
1196 | ||
97687291 VZ |
1197 | bool wxWindowGTK::GTKProcessEvent(wxEvent& event) const |
1198 | { | |
1199 | // nothing special at this level | |
937013e0 | 1200 | return HandleWindowEvent(event); |
97687291 VZ |
1201 | } |
1202 | ||
02bad830 VZ |
1203 | bool wxWindowGTK::GTKShouldIgnoreEvent() const |
1204 | { | |
1205 | return !m_hasVMT || g_blockEventsOnDrag; | |
1206 | } | |
1207 | ||
5478f221 | 1208 | int wxWindowGTK::GTKCallbackCommonPrologue(GdkEventAny *event) const |
ef5c70f9 | 1209 | { |
ef5c70f9 | 1210 | if (!m_hasVMT) |
5478f221 | 1211 | return FALSE; |
ef5c70f9 | 1212 | if (g_blockEventsOnDrag) |
5478f221 | 1213 | return TRUE; |
ef5c70f9 | 1214 | if (g_blockEventsOnScroll) |
5478f221 | 1215 | return TRUE; |
ef5c70f9 VZ |
1216 | |
1217 | if (!GTKIsOwnWindow(event->window)) | |
5478f221 | 1218 | return FALSE; |
ef5c70f9 | 1219 | |
5478f221 | 1220 | return -1; |
ef5c70f9 VZ |
1221 | } |
1222 | ||
1223 | // overloads for all GDK event types we use here: we need to have this as | |
1224 | // GdkEventXXX can't be implicitly cast to GdkEventAny even if it, in fact, | |
1225 | // derives from it in the sense that the structs have the same layout | |
1226 | #define wxDEFINE_COMMON_PROLOGUE_OVERLOAD(T) \ | |
5478f221 | 1227 | static int wxGtkCallbackCommonPrologue(T *event, wxWindowGTK *win) \ |
ef5c70f9 VZ |
1228 | { \ |
1229 | return win->GTKCallbackCommonPrologue((GdkEventAny *)event); \ | |
1230 | } | |
1231 | ||
1232 | wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventButton) | |
1233 | wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventMotion) | |
1234 | wxDEFINE_COMMON_PROLOGUE_OVERLOAD(GdkEventCrossing) | |
1235 | ||
1236 | #undef wxDEFINE_COMMON_PROLOGUE_OVERLOAD | |
1237 | ||
5478f221 VZ |
1238 | #define wxCOMMON_CALLBACK_PROLOGUE(event, win) \ |
1239 | const int rc = wxGtkCallbackCommonPrologue(event, win); \ | |
1240 | if ( rc != -1 ) \ | |
1241 | return rc | |
1242 | ||
ef5c70f9 VZ |
1243 | // all event handlers must have C linkage as they're called from GTK+ C code |
1244 | extern "C" | |
1245 | { | |
1246 | ||
c801d85f | 1247 | //----------------------------------------------------------------------------- |
2f2aa628 RR |
1248 | // "button_press_event" |
1249 | //----------------------------------------------------------------------------- | |
c801d85f | 1250 | |
7f7beb1d MR |
1251 | static gboolean |
1252 | gtk_window_button_press_callback( GtkWidget *widget, | |
1253 | GdkEventButton *gdk_event, | |
1254 | wxWindowGTK *win ) | |
903f689b | 1255 | { |
5478f221 | 1256 | wxCOMMON_CALLBACK_PROLOGUE(gdk_event, win); |
034be888 | 1257 | |
8f9850dd RR |
1258 | g_lastButtonNumber = gdk_event->button; |
1259 | ||
90e572f1 | 1260 | // GDK sends surplus button down events |
2b5f62a0 VZ |
1261 | // before a double click event. We |
1262 | // need to filter these out. | |
1e89eecd | 1263 | if ((gdk_event->type == GDK_BUTTON_PRESS) && (win->m_wxwindow)) |
2b5f62a0 VZ |
1264 | { |
1265 | GdkEvent *peek_event = gdk_event_peek(); | |
1266 | if (peek_event) | |
1267 | { | |
8b8a8e0e RR |
1268 | if ((peek_event->type == GDK_2BUTTON_PRESS) || |
1269 | (peek_event->type == GDK_3BUTTON_PRESS)) | |
2b5f62a0 VZ |
1270 | { |
1271 | gdk_event_free( peek_event ); | |
1272 | return TRUE; | |
1273 | } | |
1274 | else | |
1275 | { | |
1276 | gdk_event_free( peek_event ); | |
1277 | } | |
1278 | } | |
1279 | } | |
1280 | ||
2daa0ce9 | 1281 | wxEventType event_type = wxEVT_NULL; |
47d67540 | 1282 | |
15475ced VZ |
1283 | if ( gdk_event->type == GDK_2BUTTON_PRESS && |
1284 | gdk_event->button >= 1 && gdk_event->button <= 3 ) | |
1285 | { | |
1286 | // Reset GDK internal timestamp variables in order to disable GDK | |
1287 | // triple click events. GDK will then next time believe no button has | |
1288 | // been clicked just before, and send a normal button click event. | |
1289 | GdkDisplay* display = gtk_widget_get_display (widget); | |
1290 | display->button_click_time[1] = 0; | |
1291 | display->button_click_time[0] = 0; | |
1292 | } | |
15475ced | 1293 | |
f5e27805 | 1294 | if (gdk_event->button == 1) |
c801d85f | 1295 | { |
f3f0d961 | 1296 | // note that GDK generates triple click events which are not supported |
77ffb593 | 1297 | // by wxWidgets but still have to be passed to the app as otherwise |
f3f0d961 | 1298 | // clicks would simply go missing |
f5e27805 RR |
1299 | switch (gdk_event->type) |
1300 | { | |
15475ced VZ |
1301 | // we shouldn't get triple clicks at all for GTK2 because we |
1302 | // suppress them artificially using the code above but we still | |
1303 | // should map them to something for GTK1 and not just ignore them | |
1304 | // as this would lose clicks | |
f3f0d961 VZ |
1305 | case GDK_3BUTTON_PRESS: // we could also map this to DCLICK... |
1306 | case GDK_BUTTON_PRESS: | |
1307 | event_type = wxEVT_LEFT_DOWN; | |
1308 | break; | |
1309 | ||
1310 | case GDK_2BUTTON_PRESS: | |
1311 | event_type = wxEVT_LEFT_DCLICK; | |
1312 | break; | |
b1f50e65 VZ |
1313 | |
1314 | default: | |
1315 | // just to silence gcc warnings | |
1316 | ; | |
f5e27805 | 1317 | } |
362c6693 | 1318 | } |
f5e27805 | 1319 | else if (gdk_event->button == 2) |
c801d85f | 1320 | { |
f5e27805 RR |
1321 | switch (gdk_event->type) |
1322 | { | |
15475ced | 1323 | case GDK_3BUTTON_PRESS: |
f3f0d961 VZ |
1324 | case GDK_BUTTON_PRESS: |
1325 | event_type = wxEVT_MIDDLE_DOWN; | |
1326 | break; | |
1327 | ||
1328 | case GDK_2BUTTON_PRESS: | |
1329 | event_type = wxEVT_MIDDLE_DCLICK; | |
1330 | break; | |
b1f50e65 VZ |
1331 | |
1332 | default: | |
1333 | ; | |
f5e27805 | 1334 | } |
362c6693 | 1335 | } |
f5e27805 | 1336 | else if (gdk_event->button == 3) |
c801d85f | 1337 | { |
f5e27805 RR |
1338 | switch (gdk_event->type) |
1339 | { | |
15475ced | 1340 | case GDK_3BUTTON_PRESS: |
f3f0d961 VZ |
1341 | case GDK_BUTTON_PRESS: |
1342 | event_type = wxEVT_RIGHT_DOWN; | |
1343 | break; | |
1344 | ||
1345 | case GDK_2BUTTON_PRESS: | |
1346 | event_type = wxEVT_RIGHT_DCLICK; | |
1347 | break; | |
b1f50e65 VZ |
1348 | |
1349 | default: | |
1350 | ; | |
2b5f62a0 VZ |
1351 | } |
1352 | } | |
47d67540 | 1353 | |
e7cda1c3 VZ |
1354 | else if (gdk_event->button == 8) |
1355 | { | |
1356 | switch (gdk_event->type) | |
1357 | { | |
1358 | case GDK_3BUTTON_PRESS: | |
1359 | case GDK_BUTTON_PRESS: | |
1360 | event_type = wxEVT_AUX1_DOWN; | |
1361 | break; | |
1362 | ||
1363 | case GDK_2BUTTON_PRESS: | |
1364 | event_type = wxEVT_AUX1_DCLICK; | |
1365 | break; | |
1366 | ||
1367 | default: | |
1368 | ; | |
1369 | } | |
1370 | } | |
1371 | ||
1372 | else if (gdk_event->button == 9) | |
1373 | { | |
1374 | switch (gdk_event->type) | |
1375 | { | |
1376 | case GDK_3BUTTON_PRESS: | |
1377 | case GDK_BUTTON_PRESS: | |
1378 | event_type = wxEVT_AUX2_DOWN; | |
1379 | break; | |
1380 | ||
1381 | case GDK_2BUTTON_PRESS: | |
1382 | event_type = wxEVT_AUX2_DCLICK; | |
1383 | break; | |
1384 | ||
1385 | default: | |
1386 | ; | |
1387 | } | |
1388 | } | |
1389 | ||
2daa0ce9 VZ |
1390 | if ( event_type == wxEVT_NULL ) |
1391 | { | |
1392 | // unknown mouse button or click type | |
1393 | return FALSE; | |
1394 | } | |
1395 | ||
8f9850dd | 1396 | g_lastMouseEvent = (GdkEvent*) gdk_event; |
fcb29b23 | 1397 | |
f5e27805 | 1398 | wxMouseEvent event( event_type ); |
c5f9d156 | 1399 | InitMouseEvent( win, event, gdk_event ); |
47d67540 | 1400 | |
2daa0ce9 | 1401 | AdjustEventButtonState(event); |
94633ad9 | 1402 | |
90e572f1 MR |
1403 | // find the correct window to send the event to: it may be a different one |
1404 | // from the one which got it at GTK+ level because some controls don't have | |
d1f2ac45 VZ |
1405 | // their own X window and thus cannot get any events. |
1406 | if ( !g_captureWindow ) | |
1407 | win = FindWindowForMouseEvent(win, event.m_x, event.m_y); | |
ff8bfdbb | 1408 | |
ccb9fa0d RD |
1409 | // reset the event object and id in case win changed. |
1410 | event.SetEventObject( win ); | |
1411 | event.SetId( win->GetId() ); | |
670f9935 | 1412 | |
fcb29b23 | 1413 | bool ret = win->GTKProcessEvent( event ); |
5e513780 | 1414 | g_lastMouseEvent = NULL; |
fcb29b23 VZ |
1415 | if ( ret ) |
1416 | return TRUE; | |
47d67540 | 1417 | |
78cd9c69 | 1418 | if ((event_type == wxEVT_LEFT_DOWN) && !win->IsOfStandardClass() && |
22f43cb5 | 1419 | (gs_currentFocus != win) /* && win->IsFocusable() */) |
8622e8cd | 1420 | { |
c7bfb76a | 1421 | win->SetFocus(); |
8622e8cd RR |
1422 | } |
1423 | ||
ac103441 RR |
1424 | if (event_type == wxEVT_RIGHT_DOWN) |
1425 | { | |
1426 | // generate a "context menu" event: this is similar to right mouse | |
1427 | // click under many GUIs except that it is generated differently | |
1428 | // (right up under MSW, ctrl-click under Mac, right down here) and | |
1429 | // | |
1430 | // (a) it's a command event and so is propagated to the parent | |
1431 | // (b) under some ports it can be generated from kbd too | |
1432 | // (c) it uses screen coords (because of (a)) | |
1433 | wxContextMenuEvent evtCtx( | |
1434 | wxEVT_CONTEXT_MENU, | |
1435 | win->GetId(), | |
1436 | win->ClientToScreen(event.GetPosition())); | |
1437 | evtCtx.SetEventObject(win); | |
97687291 | 1438 | return win->GTKProcessEvent(evtCtx); |
ac103441 RR |
1439 | } |
1440 | ||
034be888 | 1441 | return FALSE; |
362c6693 | 1442 | } |
c801d85f KB |
1443 | |
1444 | //----------------------------------------------------------------------------- | |
97b3455a | 1445 | // "button_release_event" |
2f2aa628 | 1446 | //----------------------------------------------------------------------------- |
c801d85f | 1447 | |
7f7beb1d | 1448 | static gboolean |
71ead4bf | 1449 | gtk_window_button_release_callback( GtkWidget *WXUNUSED(widget), |
7f7beb1d MR |
1450 | GdkEventButton *gdk_event, |
1451 | wxWindowGTK *win ) | |
47d67540 | 1452 | { |
5478f221 | 1453 | wxCOMMON_CALLBACK_PROLOGUE(gdk_event, win); |
47d67540 | 1454 | |
8f9850dd RR |
1455 | g_lastButtonNumber = 0; |
1456 | ||
f5e27805 | 1457 | wxEventType event_type = wxEVT_NULL; |
47d67540 | 1458 | |
f5e27805 RR |
1459 | switch (gdk_event->button) |
1460 | { | |
2b5f62a0 VZ |
1461 | case 1: |
1462 | event_type = wxEVT_LEFT_UP; | |
1463 | break; | |
1464 | ||
1465 | case 2: | |
1466 | event_type = wxEVT_MIDDLE_UP; | |
1467 | break; | |
1468 | ||
1469 | case 3: | |
1470 | event_type = wxEVT_RIGHT_UP; | |
1471 | break; | |
1472 | ||
e7cda1c3 VZ |
1473 | case 8: |
1474 | event_type = wxEVT_AUX1_UP; | |
1475 | break; | |
1476 | ||
1477 | case 9: | |
1478 | event_type = wxEVT_AUX2_UP; | |
1479 | break; | |
1480 | ||
2b5f62a0 | 1481 | default: |
6a17b868 | 1482 | // unknown button, don't process |
2b5f62a0 | 1483 | return FALSE; |
f5e27805 | 1484 | } |
47d67540 | 1485 | |
8f9850dd | 1486 | g_lastMouseEvent = (GdkEvent*) gdk_event; |
fcb29b23 | 1487 | |
f5e27805 | 1488 | wxMouseEvent event( event_type ); |
c5f9d156 | 1489 | InitMouseEvent( win, event, gdk_event ); |
f5e27805 | 1490 | |
2daa0ce9 VZ |
1491 | AdjustEventButtonState(event); |
1492 | ||
d1f2ac45 VZ |
1493 | if ( !g_captureWindow ) |
1494 | win = FindWindowForMouseEvent(win, event.m_x, event.m_y); | |
47d67540 | 1495 | |
ccb9fa0d RD |
1496 | // reset the event object and id in case win changed. |
1497 | event.SetEventObject( win ); | |
1498 | event.SetId( win->GetId() ); | |
1499 | ||
e6cac2df | 1500 | bool ret = win->GTKProcessEvent(event); |
f4322df6 | 1501 | |
e6cac2df | 1502 | g_lastMouseEvent = NULL; |
f4322df6 | 1503 | |
e6cac2df | 1504 | return ret; |
362c6693 | 1505 | } |
c801d85f KB |
1506 | |
1507 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
1508 | // "motion_notify_event" |
1509 | //----------------------------------------------------------------------------- | |
c801d85f | 1510 | |
7f7beb1d | 1511 | static gboolean |
e4161a2a | 1512 | gtk_window_motion_notify_callback( GtkWidget * WXUNUSED(widget), |
7f7beb1d MR |
1513 | GdkEventMotion *gdk_event, |
1514 | wxWindowGTK *win ) | |
47d67540 | 1515 | { |
5478f221 | 1516 | wxCOMMON_CALLBACK_PROLOGUE(gdk_event, win); |
034be888 | 1517 | |
ff8bfdbb | 1518 | if (gdk_event->is_hint) |
aae24d21 | 1519 | { |
f7a11f8c RR |
1520 | int x = 0; |
1521 | int y = 0; | |
1522 | GdkModifierType state; | |
1523 | gdk_window_get_pointer(gdk_event->window, &x, &y, &state); | |
1524 | gdk_event->x = x; | |
1525 | gdk_event->y = y; | |
aae24d21 | 1526 | } |
ff8bfdbb | 1527 | |
8f9850dd RR |
1528 | g_lastMouseEvent = (GdkEvent*) gdk_event; |
1529 | ||
e380f72b | 1530 | wxMouseEvent event( wxEVT_MOTION ); |
c5f9d156 | 1531 | InitMouseEvent(win, event, gdk_event); |
e380f72b | 1532 | |
50382578 | 1533 | if ( g_captureWindow ) |
2f2aa628 | 1534 | { |
6a17b868 | 1535 | // synthesise a mouse enter or leave event if needed |
1e6feb95 | 1536 | GdkWindow *winUnderMouse = gdk_window_at_pointer(NULL, NULL); |
7c5e6fc6 | 1537 | // This seems to be necessary and actually been added to |
50382578 RR |
1538 | // GDK itself in version 2.0.X |
1539 | gdk_flush(); | |
7c5e6fc6 | 1540 | |
1e6feb95 VZ |
1541 | bool hasMouse = winUnderMouse == gdk_event->window; |
1542 | if ( hasMouse != g_captureWindowHasMouse ) | |
1543 | { | |
1544 | // the mouse changed window | |
1545 | g_captureWindowHasMouse = hasMouse; | |
1546 | ||
17a1ebd1 VZ |
1547 | wxMouseEvent eventM(g_captureWindowHasMouse ? wxEVT_ENTER_WINDOW |
1548 | : wxEVT_LEAVE_WINDOW); | |
1549 | InitMouseEvent(win, eventM, gdk_event); | |
1550 | eventM.SetEventObject(win); | |
97687291 | 1551 | win->GTKProcessEvent(eventM); |
1e6feb95 VZ |
1552 | } |
1553 | } | |
1554 | else // no capture | |
1555 | { | |
d1f2ac45 | 1556 | win = FindWindowForMouseEvent(win, event.m_x, event.m_y); |
ccb9fa0d RD |
1557 | |
1558 | // reset the event object and id in case win changed. | |
1559 | event.SetEventObject( win ); | |
1560 | event.SetId( win->GetId() ); | |
2f2aa628 | 1561 | } |
47d67540 | 1562 | |
38f69be1 RR |
1563 | if ( !g_captureWindow ) |
1564 | { | |
1565 | wxSetCursorEvent cevent( event.m_x, event.m_y ); | |
97687291 | 1566 | if (win->GTKProcessEvent( cevent )) |
38f69be1 | 1567 | { |
ec1e0c66 | 1568 | win->SetCursor( cevent.GetCursor() ); |
38f69be1 RR |
1569 | } |
1570 | } | |
2e1f5012 | 1571 | |
5e513780 | 1572 | bool ret = win->GTKProcessEvent(event); |
fcb29b23 | 1573 | |
5e513780 RR |
1574 | g_lastMouseEvent = NULL; |
1575 | ||
1576 | return ret; | |
362c6693 | 1577 | } |
c801d85f | 1578 | |
557c9f5b | 1579 | //----------------------------------------------------------------------------- |
40e5ebbf | 1580 | // "scroll_event" (mouse wheel event) |
557c9f5b JS |
1581 | //----------------------------------------------------------------------------- |
1582 | ||
7f251559 RR |
1583 | static gboolean |
1584 | window_scroll_event_hscrollbar(GtkWidget*, GdkEventScroll* gdk_event, wxWindow* win) | |
1585 | { | |
1586 | if (gdk_event->direction != GDK_SCROLL_LEFT && | |
1587 | gdk_event->direction != GDK_SCROLL_RIGHT) | |
1588 | { | |
1589 | return false; | |
1590 | } | |
1591 | ||
7f251559 | 1592 | GtkRange *range = win->m_scrollBar[wxWindow::ScrollDir_Horz]; |
7f251559 | 1593 | |
fc9ab22a | 1594 | if (range && gtk_widget_get_visible(GTK_WIDGET(range))) |
7f251559 | 1595 | { |
08f09504 | 1596 | GtkAdjustment* adj = gtk_range_get_adjustment(range); |
989d151c | 1597 | double delta = gtk_adjustment_get_step_increment(adj) * 3; |
7f251559 RR |
1598 | if (gdk_event->direction == GDK_SCROLL_LEFT) |
1599 | delta = -delta; | |
1600 | ||
989d151c | 1601 | gtk_range_set_value(range, gtk_adjustment_get_value(adj) + delta); |
7f251559 RR |
1602 | |
1603 | return TRUE; | |
1604 | } | |
1605 | ||
1606 | return FALSE; | |
1607 | } | |
1608 | ||
7f7beb1d | 1609 | static gboolean |
76e4be8e | 1610 | window_scroll_event(GtkWidget*, GdkEventScroll* gdk_event, wxWindow* win) |
557c9f5b | 1611 | { |
76e4be8e PC |
1612 | if (gdk_event->direction != GDK_SCROLL_UP && |
1613 | gdk_event->direction != GDK_SCROLL_DOWN) | |
1614 | { | |
1615 | return false; | |
1616 | } | |
0a164d4c | 1617 | |
76e4be8e | 1618 | wxMouseEvent event(wxEVT_MOUSEWHEEL); |
b4e43132 | 1619 | InitMouseEvent(win, event, gdk_event); |
c53c7fad RD |
1620 | |
1621 | // FIXME: Get these values from GTK or GDK | |
58d185f7 | 1622 | event.m_linesPerAction = 3; |
60773911 | 1623 | event.m_wheelDelta = 120; |
557c9f5b JS |
1624 | if (gdk_event->direction == GDK_SCROLL_UP) |
1625 | event.m_wheelRotation = 120; | |
1626 | else | |
1627 | event.m_wheelRotation = -120; | |
1628 | ||
7f251559 RR |
1629 | if (win->GTKProcessEvent(event)) |
1630 | return TRUE; | |
35510e48 | 1631 | |
7f251559 | 1632 | GtkRange *range = win->m_scrollBar[wxWindow::ScrollDir_Vert]; |
7f251559 | 1633 | |
fc9ab22a | 1634 | if (range && gtk_widget_get_visible(GTK_WIDGET(range))) |
7f251559 | 1635 | { |
08f09504 | 1636 | GtkAdjustment* adj = gtk_range_get_adjustment(range); |
989d151c | 1637 | double delta = gtk_adjustment_get_step_increment(adj) * 3; |
7f251559 | 1638 | if (gdk_event->direction == GDK_SCROLL_UP) |
08f09504 | 1639 | delta = -delta; |
7f251559 | 1640 | |
989d151c | 1641 | gtk_range_set_value(range, gtk_adjustment_get_value(adj) + delta); |
7f251559 RR |
1642 | |
1643 | return TRUE; | |
1644 | } | |
1645 | ||
1646 | return FALSE; | |
557c9f5b | 1647 | } |
ac103441 RR |
1648 | |
1649 | //----------------------------------------------------------------------------- | |
1650 | // "popup-menu" | |
1651 | //----------------------------------------------------------------------------- | |
ef5c70f9 | 1652 | |
ac103441 RR |
1653 | static gboolean wxgtk_window_popup_menu_callback(GtkWidget*, wxWindowGTK* win) |
1654 | { | |
ac9d38d8 | 1655 | wxContextMenuEvent event(wxEVT_CONTEXT_MENU, win->GetId(), wxPoint(-1, -1)); |
ac103441 | 1656 | event.SetEventObject(win); |
97687291 | 1657 | return win->GTKProcessEvent(event); |
ac103441 | 1658 | } |
557c9f5b | 1659 | |
c801d85f | 1660 | //----------------------------------------------------------------------------- |
2f2aa628 RR |
1661 | // "focus_in_event" |
1662 | //----------------------------------------------------------------------------- | |
c801d85f | 1663 | |
7f7beb1d | 1664 | static gboolean |
e4161a2a | 1665 | gtk_window_focus_in_callback( GtkWidget * WXUNUSED(widget), |
7f7beb1d | 1666 | GdkEventFocus *WXUNUSED(event), |
bd2e08d0 | 1667 | wxWindowGTK *win ) |
c801d85f | 1668 | { |
bd2e08d0 | 1669 | return win->GTKHandleFocusIn(); |
362c6693 | 1670 | } |
c801d85f KB |
1671 | |
1672 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
1673 | // "focus_out_event" |
1674 | //----------------------------------------------------------------------------- | |
c801d85f | 1675 | |
7f7beb1d | 1676 | static gboolean |
e4161a2a VZ |
1677 | gtk_window_focus_out_callback( GtkWidget * WXUNUSED(widget), |
1678 | GdkEventFocus * WXUNUSED(gdk_event), | |
7f7beb1d | 1679 | wxWindowGTK *win ) |
c801d85f | 1680 | { |
bd2e08d0 | 1681 | return win->GTKHandleFocusOut(); |
362c6693 | 1682 | } |
c801d85f | 1683 | |
bd2e08d0 VS |
1684 | //----------------------------------------------------------------------------- |
1685 | // "focus" | |
1686 | //----------------------------------------------------------------------------- | |
1687 | ||
28e88942 VZ |
1688 | static gboolean |
1689 | wx_window_focus_callback(GtkWidget *widget, | |
e4161a2a | 1690 | GtkDirectionType WXUNUSED(direction), |
28e88942 VZ |
1691 | wxWindowGTK *win) |
1692 | { | |
08f53168 | 1693 | // the default handler for focus signal in GtkScrolledWindow sets |
28e88942 VZ |
1694 | // focus to the window itself even if it doesn't accept focus, i.e. has no |
1695 | // GTK_CAN_FOCUS in its style -- work around this by forcibly preventing | |
1696 | // the signal from reaching gtk_scrolled_window_focus() if we don't have | |
1697 | // any children which might accept focus (we know we don't accept the focus | |
1698 | // ourselves as this signal is only connected in this case) | |
1699 | if ( win->GetChildren().empty() ) | |
1700 | g_signal_stop_emission_by_name(widget, "focus"); | |
1701 | ||
1702 | // we didn't change the focus | |
1703 | return FALSE; | |
1704 | } | |
1705 | ||
b4071e91 RR |
1706 | //----------------------------------------------------------------------------- |
1707 | // "enter_notify_event" | |
1708 | //----------------------------------------------------------------------------- | |
1709 | ||
f3a5f83a MR |
1710 | static gboolean |
1711 | gtk_window_enter_callback( GtkWidget *widget, | |
1712 | GdkEventCrossing *gdk_event, | |
1713 | wxWindowGTK *win ) | |
b4071e91 | 1714 | { |
5478f221 | 1715 | wxCOMMON_CALLBACK_PROLOGUE(gdk_event, win); |
47d67540 | 1716 | |
7f5f144a RR |
1717 | // Event was emitted after a grab |
1718 | if (gdk_event->mode != GDK_CROSSING_NORMAL) return FALSE; | |
7c5e6fc6 | 1719 | |
4a33eba6 RR |
1720 | int x = 0; |
1721 | int y = 0; | |
1722 | GdkModifierType state = (GdkModifierType)0; | |
ff8bfdbb | 1723 | |
989d151c | 1724 | gdk_window_get_pointer(gtk_widget_get_window(widget), &x, &y, &state); |
ff8bfdbb | 1725 | |
edc1d330 | 1726 | wxMouseEvent event( wxEVT_ENTER_WINDOW ); |
c5f9d156 VS |
1727 | InitMouseEvent(win, event, gdk_event); |
1728 | wxPoint pt = win->GetClientAreaOrigin(); | |
1729 | event.m_x = x + pt.x; | |
1730 | event.m_y = y + pt.y; | |
ff8bfdbb | 1731 | |
38f69be1 RR |
1732 | if ( !g_captureWindow ) |
1733 | { | |
1734 | wxSetCursorEvent cevent( event.m_x, event.m_y ); | |
97687291 | 1735 | if (win->GTKProcessEvent( cevent )) |
38f69be1 | 1736 | { |
ec1e0c66 | 1737 | win->SetCursor( cevent.GetCursor() ); |
38f69be1 RR |
1738 | } |
1739 | } | |
2e1f5012 | 1740 | |
97687291 | 1741 | return win->GTKProcessEvent(event); |
b4071e91 | 1742 | } |
47d67540 | 1743 | |
b4071e91 RR |
1744 | //----------------------------------------------------------------------------- |
1745 | // "leave_notify_event" | |
1746 | //----------------------------------------------------------------------------- | |
1747 | ||
f3a5f83a MR |
1748 | static gboolean |
1749 | gtk_window_leave_callback( GtkWidget *widget, | |
1750 | GdkEventCrossing *gdk_event, | |
1751 | wxWindowGTK *win ) | |
b4071e91 | 1752 | { |
5478f221 | 1753 | wxCOMMON_CALLBACK_PROLOGUE(gdk_event, win); |
b292e2f5 | 1754 | |
7f5f144a RR |
1755 | // Event was emitted after an ungrab |
1756 | if (gdk_event->mode != GDK_CROSSING_NORMAL) return FALSE; | |
7c5e6fc6 | 1757 | |
e380f72b | 1758 | wxMouseEvent event( wxEVT_LEAVE_WINDOW ); |
47d67540 | 1759 | |
4a33eba6 RR |
1760 | int x = 0; |
1761 | int y = 0; | |
1762 | GdkModifierType state = (GdkModifierType)0; | |
ff8bfdbb | 1763 | |
989d151c | 1764 | gdk_window_get_pointer(gtk_widget_get_window(widget), &x, &y, &state); |
ff8bfdbb | 1765 | |
b4e43132 | 1766 | InitMouseEvent(win, event, gdk_event); |
ff8bfdbb | 1767 | |
97687291 | 1768 | return win->GTKProcessEvent(event); |
b4071e91 | 1769 | } |
47d67540 | 1770 | |
c801d85f | 1771 | //----------------------------------------------------------------------------- |
add7cadd | 1772 | // "value_changed" from scrollbar |
2f2aa628 | 1773 | //----------------------------------------------------------------------------- |
c801d85f | 1774 | |
add7cadd PC |
1775 | static void |
1776 | gtk_scrollbar_value_changed(GtkRange* range, wxWindow* win) | |
47d67540 | 1777 | { |
71ead4bf | 1778 | wxEventType eventType = win->GTKGetScrollEventType(range); |
add7cadd PC |
1779 | if (eventType != wxEVT_NULL) |
1780 | { | |
1781 | // Convert scroll event type to scrollwin event type | |
1782 | eventType += wxEVT_SCROLLWIN_TOP - wxEVT_SCROLL_TOP; | |
22c9b211 VZ |
1783 | |
1784 | // find the scrollbar which generated the event | |
1785 | wxWindowGTK::ScrollDir dir = win->ScrollDirFromRange(range); | |
35510e48 | 1786 | |
22c9b211 | 1787 | // generate the corresponding wx event |
bfeeb7f3 | 1788 | const int orient = wxWindow::OrientFromScrollDir(dir); |
add7cadd PC |
1789 | wxScrollWinEvent event(eventType, win->GetScrollPos(orient), orient); |
1790 | event.SetEventObject(win); | |
22c9b211 | 1791 | |
97687291 | 1792 | win->GTKProcessEvent(event); |
add7cadd | 1793 | } |
362c6693 | 1794 | } |
c801d85f | 1795 | |
cb43b372 RR |
1796 | //----------------------------------------------------------------------------- |
1797 | // "button_press_event" from scrollbar | |
1798 | //----------------------------------------------------------------------------- | |
1799 | ||
7f7beb1d | 1800 | static gboolean |
add7cadd | 1801 | gtk_scrollbar_button_press_event(GtkRange*, GdkEventButton*, wxWindow* win) |
cb43b372 | 1802 | { |
0a164d4c | 1803 | g_blockEventsOnScroll = true; |
add7cadd | 1804 | win->m_mouseButtonDown = true; |
9e691f46 | 1805 | |
add7cadd | 1806 | return false; |
cb43b372 RR |
1807 | } |
1808 | ||
c918b2cd PC |
1809 | //----------------------------------------------------------------------------- |
1810 | // "event_after" from scrollbar | |
1811 | //----------------------------------------------------------------------------- | |
1812 | ||
c918b2cd PC |
1813 | static void |
1814 | gtk_scrollbar_event_after(GtkRange* range, GdkEvent* event, wxWindow* win) | |
1815 | { | |
1816 | if (event->type == GDK_BUTTON_RELEASE) | |
1817 | { | |
1818 | g_signal_handlers_block_by_func(range, (void*)gtk_scrollbar_event_after, win); | |
1819 | ||
bfeeb7f3 | 1820 | const int orient = wxWindow::OrientFromScrollDir( |
22c9b211 | 1821 | win->ScrollDirFromRange(range)); |
74ab5f5b VZ |
1822 | wxScrollWinEvent evt(wxEVT_SCROLLWIN_THUMBRELEASE, |
1823 | win->GetScrollPos(orient), orient); | |
1824 | evt.SetEventObject(win); | |
1825 | win->GTKProcessEvent(evt); | |
c918b2cd PC |
1826 | } |
1827 | } | |
c918b2cd | 1828 | |
cb43b372 RR |
1829 | //----------------------------------------------------------------------------- |
1830 | // "button_release_event" from scrollbar | |
1831 | //----------------------------------------------------------------------------- | |
1832 | ||
7f7beb1d | 1833 | static gboolean |
add7cadd | 1834 | gtk_scrollbar_button_release_event(GtkRange* range, GdkEventButton*, wxWindow* win) |
cb43b372 | 1835 | { |
0a164d4c | 1836 | g_blockEventsOnScroll = false; |
add7cadd PC |
1837 | win->m_mouseButtonDown = false; |
1838 | // If thumb tracking | |
2a23d363 | 1839 | if (win->m_isScrolling) |
88413fec | 1840 | { |
add7cadd | 1841 | win->m_isScrolling = false; |
c918b2cd | 1842 | // Hook up handler to send thumb release event after this emission is finished. |
8ea30e36 PC |
1843 | // To allow setting scroll position from event handler, sending event must |
1844 | // be deferred until after the GtkRange handler for this signal has run | |
c918b2cd | 1845 | g_signal_handlers_unblock_by_func(range, (void*)gtk_scrollbar_event_after, win); |
88413fec RR |
1846 | } |
1847 | ||
add7cadd | 1848 | return false; |
cb43b372 | 1849 | } |
ca298c88 | 1850 | |
a2053b27 RR |
1851 | //----------------------------------------------------------------------------- |
1852 | // "realize" from m_widget | |
1853 | //----------------------------------------------------------------------------- | |
1854 | ||
7f7beb1d | 1855 | static void |
514b0e13 | 1856 | gtk_window_realized_callback(GtkWidget* WXUNUSED(widget), wxWindowGTK* win) |
a2053b27 | 1857 | { |
612515af VZ |
1858 | win->GTKHandleRealized(); |
1859 | } | |
1860 | ||
1a0d3739 PC |
1861 | //----------------------------------------------------------------------------- |
1862 | // "unrealize" from m_wxwindow | |
1863 | //----------------------------------------------------------------------------- | |
1864 | ||
1865 | static void unrealize(GtkWidget*, wxWindowGTK* win) | |
1866 | { | |
1867 | if (win->m_imData) | |
1868 | gtk_im_context_set_client_window(win->m_imData->context, NULL); | |
1869 | } | |
1870 | ||
b79395c5 | 1871 | //----------------------------------------------------------------------------- |
cca410b3 | 1872 | // "size_allocate" from m_wxwindow or m_widget |
b79395c5 RR |
1873 | //----------------------------------------------------------------------------- |
1874 | ||
cca410b3 PC |
1875 | static void |
1876 | size_allocate(GtkWidget*, GtkAllocation* alloc, wxWindow* win) | |
8f75cb6c | 1877 | { |
cca410b3 PC |
1878 | int w = alloc->width; |
1879 | int h = alloc->height; | |
1880 | if (win->m_wxwindow) | |
5b8a521e | 1881 | { |
08f53168 PC |
1882 | int border_x, border_y; |
1883 | WX_PIZZA(win->m_wxwindow)->get_border_widths(border_x, border_y); | |
1884 | w -= 2 * border_x; | |
1885 | h -= 2 * border_y; | |
cca410b3 PC |
1886 | if (w < 0) w = 0; |
1887 | if (h < 0) h = 0; | |
1888 | } | |
1889 | if (win->m_oldClientWidth != w || win->m_oldClientHeight != h) | |
1890 | { | |
1891 | win->m_oldClientWidth = w; | |
1892 | win->m_oldClientHeight = h; | |
1893 | // this callback can be connected to m_wxwindow, | |
1894 | // so always get size from m_widget->allocation | |
989d151c PC |
1895 | GtkAllocation a; |
1896 | gtk_widget_get_allocation(win->m_widget, &a); | |
1897 | win->m_width = a.width; | |
1898 | win->m_height = a.height; | |
cca410b3 PC |
1899 | if (!win->m_nativeSizeEvent) |
1900 | { | |
1901 | wxSizeEvent event(win->GetSize(), win->GetId()); | |
1902 | event.SetEventObject(win); | |
1903 | win->GTKProcessEvent(event); | |
1904 | } | |
5b8a521e | 1905 | } |
8f75cb6c RR |
1906 | } |
1907 | ||
7738af59 | 1908 | //----------------------------------------------------------------------------- |
78cd9c69 | 1909 | // "grab_broken" |
7738af59 VZ |
1910 | //----------------------------------------------------------------------------- |
1911 | ||
db885f2a PC |
1912 | #if GTK_CHECK_VERSION(2, 8, 0) |
1913 | static gboolean | |
1914 | gtk_window_grab_broken( GtkWidget*, | |
7738af59 VZ |
1915 | GdkEventGrabBroken *event, |
1916 | wxWindow *win ) | |
1917 | { | |
1918 | // Mouse capture has been lost involuntarily, notify the application | |
db885f2a | 1919 | if(!event->keyboard && wxWindow::GetCapture() == win) |
7738af59 VZ |
1920 | { |
1921 | wxMouseCaptureLostEvent evt( win->GetId() ); | |
1922 | evt.SetEventObject( win ); | |
937013e0 | 1923 | win->HandleWindowEvent( evt ); |
7738af59 | 1924 | } |
db885f2a | 1925 | return false; |
7738af59 | 1926 | } |
4b859ff4 | 1927 | #endif |
7738af59 | 1928 | |
013151c7 JS |
1929 | //----------------------------------------------------------------------------- |
1930 | // "style_set" | |
1931 | //----------------------------------------------------------------------------- | |
1932 | ||
1933 | static | |
1934 | void gtk_window_style_set_callback( GtkWidget *WXUNUSED(widget), | |
1935 | GtkStyle *previous_style, | |
1936 | wxWindow* win ) | |
1937 | { | |
013151c7 JS |
1938 | if (win && previous_style) |
1939 | { | |
013151c7 JS |
1940 | wxSysColourChangedEvent event; |
1941 | event.SetEventObject(win); | |
1942 | ||
1943 | win->GTKProcessEvent( event ); | |
1944 | } | |
1945 | } | |
1946 | ||
ef5c70f9 VZ |
1947 | } // extern "C" |
1948 | ||
f0b87ef9 PC |
1949 | void wxWindowGTK::GTKHandleRealized() |
1950 | { | |
1951 | if (m_imData) | |
1952 | { | |
1953 | gtk_im_context_set_client_window | |
1954 | ( | |
1955 | m_imData->context, | |
1956 | m_wxwindow ? GTKGetDrawingWindow() | |
1957 | : gtk_widget_get_window(m_widget) | |
1958 | ); | |
1959 | } | |
1960 | ||
1961 | // We cannot set colours and fonts before the widget | |
1962 | // been realized, so we do this directly after realization | |
1963 | // or otherwise in idle time | |
1964 | ||
1965 | if (m_needsStyleChange) | |
1966 | { | |
1967 | SetBackgroundStyle(GetBackgroundStyle()); | |
1968 | m_needsStyleChange = false; | |
1969 | } | |
1970 | ||
514b0e13 | 1971 | wxWindowCreateEvent event(static_cast<wxWindow*>(this)); |
f0b87ef9 PC |
1972 | event.SetEventObject( this ); |
1973 | GTKProcessEvent( event ); | |
1974 | ||
1975 | GTKUpdateCursor(true, false); | |
1976 | } | |
1977 | ||
ef5c70f9 VZ |
1978 | // ---------------------------------------------------------------------------- |
1979 | // this wxWindowBase function is implemented here (in platform-specific file) | |
1980 | // because it is static and so couldn't be made virtual | |
1981 | // ---------------------------------------------------------------------------- | |
1982 | ||
1983 | wxWindow *wxWindowBase::DoFindFocus() | |
1984 | { | |
22f43cb5 | 1985 | wxWindowGTK *focus = gs_pendingFocus ? gs_pendingFocus : gs_currentFocus; |
ef5c70f9 | 1986 | // the cast is necessary when we compile in wxUniversal mode |
5c33522f | 1987 | return static_cast<wxWindow*>(focus); |
865bb325 | 1988 | } |
63081513 | 1989 | |
48200154 | 1990 | void wxWindowGTK::AddChildGTK(wxWindowGTK* child) |
6ca41e57 | 1991 | { |
9a33c3ef | 1992 | wxASSERT_MSG(m_wxwindow, "Cannot add a child to a window without a client area"); |
03647350 | 1993 | |
9a33c3ef FM |
1994 | // the window might have been scrolled already, we |
1995 | // have to adapt the position | |
48200154 | 1996 | wxPizza* pizza = WX_PIZZA(m_wxwindow); |
08f53168 PC |
1997 | child->m_x += pizza->m_scroll_x; |
1998 | child->m_y += pizza->m_scroll_y; | |
148cd9b6 | 1999 | |
08f53168 PC |
2000 | gtk_widget_set_size_request( |
2001 | child->m_widget, child->m_width, child->m_height); | |
f089940f | 2002 | pizza->put(child->m_widget, child->m_x, child->m_y); |
6ca41e57 RR |
2003 | } |
2004 | ||
bbe0af5b RR |
2005 | //----------------------------------------------------------------------------- |
2006 | // global functions | |
2007 | //----------------------------------------------------------------------------- | |
2008 | ||
1e6feb95 | 2009 | wxWindow *wxGetActiveWindow() |
bbe0af5b | 2010 | { |
6cad4f1b | 2011 | return wxWindow::FindFocus(); |
bbe0af5b RR |
2012 | } |
2013 | ||
7dd40b6f RD |
2014 | |
2015 | wxMouseState wxGetMouseState() | |
2016 | { | |
2017 | wxMouseState ms; | |
2018 | ||
2019 | gint x; | |
2020 | gint y; | |
2021 | GdkModifierType mask; | |
2022 | ||
2023 | gdk_window_get_pointer(NULL, &x, &y, &mask); | |
2024 | ||
2025 | ms.SetX(x); | |
2026 | ms.SetY(y); | |
c4021a79 PC |
2027 | ms.SetLeftDown((mask & GDK_BUTTON1_MASK) != 0); |
2028 | ms.SetMiddleDown((mask & GDK_BUTTON2_MASK) != 0); | |
2029 | ms.SetRightDown((mask & GDK_BUTTON3_MASK) != 0); | |
e7cda1c3 | 2030 | // see the comment in InitMouseEvent() |
c4021a79 PC |
2031 | ms.SetAux1Down((mask & GDK_BUTTON4_MASK) != 0); |
2032 | ms.SetAux2Down((mask & GDK_BUTTON5_MASK) != 0); | |
2033 | ||
2034 | ms.SetControlDown((mask & GDK_CONTROL_MASK) != 0); | |
2035 | ms.SetShiftDown((mask & GDK_SHIFT_MASK) != 0); | |
2036 | ms.SetAltDown((mask & GDK_MOD1_MASK) != 0); | |
2037 | ms.SetMetaDown((mask & GDK_META_MASK) != 0); | |
3d257b8d | 2038 | |
7dd40b6f RD |
2039 | return ms; |
2040 | } | |
3d257b8d | 2041 | |
c801d85f | 2042 | //----------------------------------------------------------------------------- |
1e6feb95 | 2043 | // wxWindowGTK |
c801d85f KB |
2044 | //----------------------------------------------------------------------------- |
2045 | ||
6522713c VZ |
2046 | // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu() |
2047 | // method | |
1e6feb95 | 2048 | #ifdef __WXUNIVERSAL__ |
6522713c | 2049 | IMPLEMENT_ABSTRACT_CLASS(wxWindowGTK, wxWindowBase) |
28953245 | 2050 | #endif // __WXUNIVERSAL__ |
c801d85f | 2051 | |
1e6feb95 | 2052 | void wxWindowGTK::Init() |
c801d85f | 2053 | { |
f03fc89f | 2054 | // GTK specific |
d3b9f782 VZ |
2055 | m_widget = NULL; |
2056 | m_wxwindow = NULL; | |
2057 | m_focusWidget = NULL; | |
8bbe427f | 2058 | |
f03fc89f | 2059 | // position/size |
a2053b27 RR |
2060 | m_x = 0; |
2061 | m_y = 0; | |
2062 | m_width = 0; | |
e380f72b | 2063 | m_height = 0; |
8bbe427f | 2064 | |
0a164d4c | 2065 | m_hasVMT = false; |
02761f6c | 2066 | |
c6212a0c | 2067 | m_showOnIdle = false; |
148cd9b6 | 2068 | |
0a164d4c WS |
2069 | m_noExpose = false; |
2070 | m_nativeSizeEvent = false; | |
94633ad9 | 2071 | |
0a164d4c | 2072 | m_isScrolling = false; |
add7cadd | 2073 | m_mouseButtonDown = false; |
add7cadd | 2074 | |
22c9b211 VZ |
2075 | // initialize scrolling stuff |
2076 | for ( int dir = 0; dir < ScrollDir_Max; dir++ ) | |
2077 | { | |
2078 | m_scrollBar[dir] = NULL; | |
2079 | m_scrollPos[dir] = 0; | |
22c9b211 | 2080 | } |
f03fc89f | 2081 | |
815ac4a7 VZ |
2082 | m_oldClientWidth = |
2083 | m_oldClientHeight = 0; | |
8bbe427f | 2084 | |
0a164d4c | 2085 | m_clipPaintRegion = false; |
b6fa52db | 2086 | |
c7382f91 JS |
2087 | m_needsStyleChange = false; |
2088 | ||
5e014a0c | 2089 | m_cursor = *wxSTANDARD_CURSOR; |
2daa0ce9 | 2090 | |
a3c15d89 | 2091 | m_imData = NULL; |
a589495e | 2092 | m_dirtyTabOrder = false; |
362c6693 | 2093 | } |
c801d85f | 2094 | |
1e6feb95 | 2095 | wxWindowGTK::wxWindowGTK() |
68995f26 VZ |
2096 | { |
2097 | Init(); | |
2098 | } | |
2099 | ||
1e6feb95 VZ |
2100 | wxWindowGTK::wxWindowGTK( wxWindow *parent, |
2101 | wxWindowID id, | |
2102 | const wxPoint &pos, | |
2103 | const wxSize &size, | |
2104 | long style, | |
2105 | const wxString &name ) | |
6ca41e57 | 2106 | { |
68995f26 VZ |
2107 | Init(); |
2108 | ||
e380f72b | 2109 | Create( parent, id, pos, size, style, name ); |
6ca41e57 | 2110 | } |
8bbe427f | 2111 | |
1e6feb95 VZ |
2112 | bool wxWindowGTK::Create( wxWindow *parent, |
2113 | wxWindowID id, | |
2114 | const wxPoint &pos, | |
2115 | const wxSize &size, | |
2116 | long style, | |
2117 | const wxString &name ) | |
c801d85f | 2118 | { |
e5048854 JS |
2119 | // Get default border |
2120 | wxBorder border = GetBorder(style); | |
9800347d | 2121 | |
e5048854 JS |
2122 | style &= ~wxBORDER_MASK; |
2123 | style |= border; | |
ac9d38d8 | 2124 | |
4dcaf11a RR |
2125 | if (!PreCreation( parent, pos, size ) || |
2126 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
2127 | { | |
1e6feb95 | 2128 | wxFAIL_MSG( wxT("wxWindowGTK creation failed") ); |
0a164d4c | 2129 | return false; |
4dcaf11a | 2130 | } |
47d67540 | 2131 | |
7da4a9cf RR |
2132 | // We should accept the native look |
2133 | #if 0 | |
2134 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget) ); | |
2135 | scroll_class->scrollbar_spacing = 0; | |
2136 | #endif | |
2137 | ||
e5048854 | 2138 | |
0f52f610 | 2139 | m_wxwindow = wxPizza::New(m_windowStyle); |
75f661bb PC |
2140 | #ifndef __WXUNIVERSAL__ |
2141 | if (HasFlag(wxPizza::BORDER_STYLES)) | |
2142 | { | |
2143 | g_signal_connect(m_wxwindow, "parent_set", | |
2144 | G_CALLBACK(parent_set), this); | |
2145 | } | |
2146 | #endif | |
3e09bcfd | 2147 | if (!HasFlag(wxHSCROLL) && !HasFlag(wxVSCROLL)) |
c9192212 | 2148 | m_widget = m_wxwindow; |
6552c7af RR |
2149 | else |
2150 | { | |
d3b9f782 | 2151 | m_widget = gtk_scrolled_window_new( NULL, NULL ); |
ff8bfdbb | 2152 | |
6552c7af | 2153 | GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); |
47d67540 | 2154 | |
6552c7af RR |
2155 | // There is a conflict with default bindings at GTK+ |
2156 | // level between scrolled windows and notebooks both of which want to use | |
2157 | // Ctrl-PageUp/Down: scrolled windows for scrolling in the horizontal | |
2158 | // direction and notebooks for changing pages -- we decide that if we don't | |
2159 | // have wxHSCROLL style we can safely sacrifice horizontal scrolling if it | |
2160 | // means we can get working keyboard navigation in notebooks | |
2161 | if ( !HasFlag(wxHSCROLL) ) | |
fd4081aa | 2162 | { |
6552c7af RR |
2163 | GtkBindingSet * |
2164 | bindings = gtk_binding_set_by_class(G_OBJECT_GET_CLASS(m_widget)); | |
2165 | if ( bindings ) | |
2166 | { | |
2167 | gtk_binding_entry_remove(bindings, GDK_Page_Up, GDK_CONTROL_MASK); | |
2168 | gtk_binding_entry_remove(bindings, GDK_Page_Down, GDK_CONTROL_MASK); | |
2169 | } | |
fd4081aa | 2170 | } |
fd4081aa | 2171 | |
6552c7af RR |
2172 | if (HasFlag(wxALWAYS_SHOW_SB)) |
2173 | { | |
2174 | gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS ); | |
6552c7af RR |
2175 | } |
2176 | else | |
2177 | { | |
2178 | gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); | |
2179 | } | |
47d67540 | 2180 | |
989d151c PC |
2181 | m_scrollBar[ScrollDir_Horz] = GTK_RANGE(gtk_scrolled_window_get_hscrollbar(scrolledWindow)); |
2182 | m_scrollBar[ScrollDir_Vert] = GTK_RANGE(gtk_scrolled_window_get_vscrollbar(scrolledWindow)); | |
6552c7af RR |
2183 | if (GetLayoutDirection() == wxLayout_RightToLeft) |
2184 | gtk_range_set_inverted( m_scrollBar[ScrollDir_Horz], TRUE ); | |
47d67540 | 2185 | |
6552c7af | 2186 | gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); |
4e5a4c69 | 2187 | |
6552c7af RR |
2188 | // connect various scroll-related events |
2189 | for ( int dir = 0; dir < ScrollDir_Max; dir++ ) | |
2190 | { | |
2191 | // these handlers block mouse events to any window during scrolling | |
2192 | // such as motion events and prevent GTK and wxWidgets from fighting | |
2193 | // over where the slider should be | |
2194 | g_signal_connect(m_scrollBar[dir], "button_press_event", | |
22c9b211 | 2195 | G_CALLBACK(gtk_scrollbar_button_press_event), this); |
6552c7af | 2196 | g_signal_connect(m_scrollBar[dir], "button_release_event", |
22c9b211 VZ |
2197 | G_CALLBACK(gtk_scrollbar_button_release_event), this); |
2198 | ||
6552c7af | 2199 | gulong handler_id = g_signal_connect(m_scrollBar[dir], "event_after", |
22c9b211 | 2200 | G_CALLBACK(gtk_scrollbar_event_after), this); |
6552c7af | 2201 | g_signal_handler_block(m_scrollBar[dir], handler_id); |
22c9b211 | 2202 | |
6552c7af | 2203 | // these handlers get notified when scrollbar slider moves |
40e5ebbf | 2204 | g_signal_connect_after(m_scrollBar[dir], "value_changed", |
22c9b211 | 2205 | G_CALLBACK(gtk_scrollbar_value_changed), this); |
6552c7af | 2206 | } |
76ed8f8d | 2207 | |
6552c7af RR |
2208 | gtk_widget_show( m_wxwindow ); |
2209 | } | |
9ff9d30c | 2210 | g_object_ref(m_widget); |
47d67540 | 2211 | |
f03fc89f VZ |
2212 | if (m_parent) |
2213 | m_parent->DoAddChild( this ); | |
94633ad9 | 2214 | |
76fcf0f2 | 2215 | m_focusWidget = m_wxwindow; |
8bbe427f | 2216 | |
29901843 VS |
2217 | SetCanFocus(AcceptsFocus()); |
2218 | ||
e380f72b | 2219 | PostCreation(); |
8bbe427f | 2220 | |
0a164d4c | 2221 | return true; |
362c6693 | 2222 | } |
c801d85f | 2223 | |
1e6feb95 | 2224 | wxWindowGTK::~wxWindowGTK() |
c801d85f | 2225 | { |
7de59551 RD |
2226 | SendDestroyEvent(); |
2227 | ||
22f43cb5 VS |
2228 | if (gs_currentFocus == this) |
2229 | gs_currentFocus = NULL; | |
2230 | if (gs_pendingFocus == this) | |
2231 | gs_pendingFocus = NULL; | |
44cd54c2 | 2232 | |
bd2e08d0 VS |
2233 | if ( gs_deferredFocusOut == this ) |
2234 | gs_deferredFocusOut = NULL; | |
3e679f01 | 2235 | |
0a164d4c | 2236 | m_hasVMT = false; |
47d67540 | 2237 | |
02c3e53b JS |
2238 | // destroy children before destroying this window itself |
2239 | DestroyChildren(); | |
2240 | ||
2241 | // unhook focus handlers to prevent stray events being | |
2242 | // propagated to this (soon to be) dead object | |
2243 | if (m_focusWidget != NULL) | |
2244 | { | |
9fa72bd2 MR |
2245 | g_signal_handlers_disconnect_by_func (m_focusWidget, |
2246 | (gpointer) gtk_window_focus_in_callback, | |
2247 | this); | |
2248 | g_signal_handlers_disconnect_by_func (m_focusWidget, | |
2249 | (gpointer) gtk_window_focus_out_callback, | |
2250 | this); | |
02c3e53b JS |
2251 | } |
2252 | ||
f03fc89f | 2253 | if (m_widget) |
0a164d4c | 2254 | Show( false ); |
8bbe427f | 2255 | |
f6551618 MW |
2256 | // delete before the widgets to avoid a crash on solaris |
2257 | delete m_imData; | |
1a0d3739 | 2258 | m_imData = NULL; |
f6551618 | 2259 | |
2f55b88c PC |
2260 | // avoid problem with GTK+ 2.18 where a frozen window causes the whole |
2261 | // TLW to be frozen, and if the window is then destroyed, nothing ever | |
2262 | // gets painted again | |
2263 | if (IsFrozen()) | |
2264 | DoThaw(); | |
2265 | ||
f03fc89f | 2266 | if (m_widget) |
a2053b27 | 2267 | { |
9ff9d30c PC |
2268 | // Note that gtk_widget_destroy() does not destroy the widget, it just |
2269 | // emits the "destroy" signal. The widget is not actually destroyed | |
2270 | // until its reference count drops to zero. | |
2271 | gtk_widget_destroy(m_widget); | |
2272 | // Release our reference, should be the last one | |
2273 | g_object_unref(m_widget); | |
2274 | m_widget = NULL; | |
a2053b27 | 2275 | } |
9ff9d30c | 2276 | m_wxwindow = NULL; |
362c6693 | 2277 | } |
c801d85f | 2278 | |
1e6feb95 | 2279 | bool wxWindowGTK::PreCreation( wxWindowGTK *parent, const wxPoint &pos, const wxSize &size ) |
c801d85f | 2280 | { |
e8375af8 VZ |
2281 | if ( GTKNeedsParent() ) |
2282 | { | |
2283 | wxCHECK_MSG( parent, false, wxT("Must have non-NULL parent") ); | |
2284 | } | |
8bbe427f | 2285 | |
a7c26d10 RD |
2286 | // Use either the given size, or the default if -1 is given. |
2287 | // See wxWindowBase for these functions. | |
3013a903 | 2288 | m_width = WidthDefault(size.x) ; |
f03fc89f | 2289 | m_height = HeightDefault(size.y); |
8bbe427f | 2290 | |
43a18898 RR |
2291 | m_x = (int)pos.x; |
2292 | m_y = (int)pos.y; | |
8bbe427f | 2293 | |
0a164d4c | 2294 | return true; |
c801d85f KB |
2295 | } |
2296 | ||
1e6feb95 | 2297 | void wxWindowGTK::PostCreation() |
c801d85f | 2298 | { |
82b978d7 RD |
2299 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") ); |
2300 | ||
43a18898 RR |
2301 | if (m_wxwindow) |
2302 | { | |
147bc491 | 2303 | if (!m_noExpose) |
b02da6b1 | 2304 | { |
77ffb593 | 2305 | // these get reported to wxWidgets -> wxPaintEvent |
1e6feb95 | 2306 | |
9fa72bd2 MR |
2307 | g_signal_connect (m_wxwindow, "expose_event", |
2308 | G_CALLBACK (gtk_window_expose_callback), this); | |
147bc491 | 2309 | |
847dfdb4 | 2310 | if (GetLayoutDirection() == wxLayout_LeftToRight) |
08f53168 | 2311 | gtk_widget_set_redraw_on_allocate(m_wxwindow, HasFlag(wxFULL_REPAINT_ON_RESIZE)); |
93d23d8f | 2312 | } |
2b5f62a0 | 2313 | |
ed56a258 JS |
2314 | // Create input method handler |
2315 | m_imData = new wxGtkIMData; | |
2316 | ||
2b5f62a0 | 2317 | // Cannot handle drawing preedited text yet |
a3c15d89 | 2318 | gtk_im_context_set_use_preedit( m_imData->context, FALSE ); |
2b5f62a0 | 2319 | |
9fa72bd2 | 2320 | g_signal_connect (m_imData->context, "commit", |
da210120 | 2321 | G_CALLBACK (gtk_wxwindow_commit_cb), this); |
1a0d3739 | 2322 | g_signal_connect(m_wxwindow, "unrealize", G_CALLBACK(unrealize), this); |
43a18898 | 2323 | } |
47d67540 | 2324 | |
76fcf0f2 | 2325 | // focus handling |
63081513 | 2326 | |
06fda9e8 RR |
2327 | if (!GTK_IS_WINDOW(m_widget)) |
2328 | { | |
2329 | if (m_focusWidget == NULL) | |
2330 | m_focusWidget = m_widget; | |
0a164d4c | 2331 | |
4c20ee63 RR |
2332 | if (m_wxwindow) |
2333 | { | |
2334 | g_signal_connect (m_focusWidget, "focus_in_event", | |
9fa72bd2 | 2335 | G_CALLBACK (gtk_window_focus_in_callback), this); |
4c20ee63 | 2336 | g_signal_connect (m_focusWidget, "focus_out_event", |
f1e57cb9 | 2337 | G_CALLBACK (gtk_window_focus_out_callback), this); |
4c20ee63 RR |
2338 | } |
2339 | else | |
2340 | { | |
2341 | g_signal_connect_after (m_focusWidget, "focus_in_event", | |
2342 | G_CALLBACK (gtk_window_focus_in_callback), this); | |
2343 | g_signal_connect_after (m_focusWidget, "focus_out_event", | |
2344 | G_CALLBACK (gtk_window_focus_out_callback), this); | |
2345 | } | |
06fda9e8 | 2346 | } |
76fcf0f2 | 2347 | |
28e88942 VZ |
2348 | if ( !AcceptsFocusFromKeyboard() ) |
2349 | { | |
80332672 | 2350 | SetCanFocus(false); |
28e88942 VZ |
2351 | |
2352 | g_signal_connect(m_widget, "focus", | |
2353 | G_CALLBACK(wx_window_focus_callback), this); | |
2354 | } | |
2355 | ||
76fcf0f2 | 2356 | // connect to the various key and mouse handlers |
63081513 | 2357 | |
a2053b27 | 2358 | GtkWidget *connect_widget = GetConnectWidget(); |
f03fc89f | 2359 | |
a2053b27 | 2360 | ConnectWidget( connect_widget ); |
47d67540 | 2361 | |
843101f7 VS |
2362 | // We cannot set colours, fonts and cursors before the widget has been |
2363 | // realized, so we do this directly after realization -- unless the widget | |
2364 | // was in fact realized already. | |
2365 | if ( gtk_widget_get_realized(connect_widget) ) | |
2366 | { | |
2367 | gtk_window_realized_callback(connect_widget, this); | |
2368 | } | |
2369 | else | |
2370 | { | |
2371 | g_signal_connect (connect_widget, "realize", | |
2372 | G_CALLBACK (gtk_window_realized_callback), this); | |
2373 | } | |
2daa0ce9 | 2374 | |
cca410b3 PC |
2375 | if (!IsTopLevel()) |
2376 | { | |
2377 | g_signal_connect(m_wxwindow ? m_wxwindow : m_widget, "size_allocate", | |
2378 | G_CALLBACK(size_allocate), this); | |
2379 | } | |
2380 | ||
db885f2a | 2381 | #if GTK_CHECK_VERSION(2, 8, 0) |
bb8afd65 VZ |
2382 | if ( gtk_check_version(2,8,0) == NULL ) |
2383 | { | |
2384 | // Make sure we can notify the app when mouse capture is lost | |
2385 | if ( m_wxwindow ) | |
4b859ff4 | 2386 | { |
4b859ff4 | 2387 | g_signal_connect (m_wxwindow, "grab_broken_event", |
7738af59 | 2388 | G_CALLBACK (gtk_window_grab_broken), this); |
4b859ff4 | 2389 | } |
7738af59 | 2390 | |
bb8afd65 | 2391 | if ( connect_widget != m_wxwindow ) |
4b859ff4 | 2392 | { |
4b859ff4 | 2393 | g_signal_connect (connect_widget, "grab_broken_event", |
7738af59 | 2394 | G_CALLBACK (gtk_window_grab_broken), this); |
4b859ff4 | 2395 | } |
63081513 | 2396 | } |
bb8afd65 | 2397 | #endif // GTK+ >= 2.8 |
2daa0ce9 | 2398 | |
92153555 | 2399 | if ( GTKShouldConnectSizeRequest() ) |
47c93b63 RR |
2400 | { |
2401 | // This is needed if we want to add our windows into native | |
024e9a4c | 2402 | // GTK controls, such as the toolbar. With this callback, the |
47c93b63 | 2403 | // toolbar gets to know the correct size (the one set by the |
024e9a4c | 2404 | // programmer). Sadly, it misbehaves for wxComboBox. |
9fa72bd2 MR |
2405 | g_signal_connect (m_widget, "size_request", |
2406 | G_CALLBACK (wxgtk_window_size_request_callback), | |
2407 | this); | |
47c93b63 | 2408 | } |
1e6feb95 | 2409 | |
40bab631 VS |
2410 | InheritAttributes(); |
2411 | ||
0a164d4c | 2412 | m_hasVMT = true; |
e892f2fd | 2413 | |
978af864 | 2414 | SetLayoutDirection(wxLayout_Default); |
a433fbd5 VZ |
2415 | |
2416 | // unless the window was created initially hidden (i.e. Hide() had been | |
2417 | // called before Create()), we should show it at GTK+ level as well | |
2418 | if ( IsShown() ) | |
2419 | gtk_widget_show( m_widget ); | |
b4071e91 RR |
2420 | } |
2421 | ||
1da8e6e4 VZ |
2422 | unsigned long |
2423 | wxWindowGTK::GTKConnectWidget(const char *signal, wxGTKCallback callback) | |
a0c8bb73 VZ |
2424 | { |
2425 | return g_signal_connect(m_widget, signal, callback, this); | |
2426 | } | |
2427 | ||
1e6feb95 | 2428 | void wxWindowGTK::ConnectWidget( GtkWidget *widget ) |
b4071e91 | 2429 | { |
9fa72bd2 MR |
2430 | g_signal_connect (widget, "key_press_event", |
2431 | G_CALLBACK (gtk_window_key_press_callback), this); | |
2432 | g_signal_connect (widget, "key_release_event", | |
2433 | G_CALLBACK (gtk_window_key_release_callback), this); | |
2434 | g_signal_connect (widget, "button_press_event", | |
2435 | G_CALLBACK (gtk_window_button_press_callback), this); | |
2436 | g_signal_connect (widget, "button_release_event", | |
2437 | G_CALLBACK (gtk_window_button_release_callback), this); | |
2438 | g_signal_connect (widget, "motion_notify_event", | |
2439 | G_CALLBACK (gtk_window_motion_notify_callback), this); | |
35510e48 | 2440 | |
9fa72bd2 | 2441 | g_signal_connect (widget, "scroll_event", |
76e4be8e | 2442 | G_CALLBACK (window_scroll_event), this); |
7f251559 RR |
2443 | if (m_scrollBar[ScrollDir_Horz]) |
2444 | g_signal_connect (m_scrollBar[ScrollDir_Horz], "scroll_event", | |
2445 | G_CALLBACK (window_scroll_event_hscrollbar), this); | |
2446 | if (m_scrollBar[ScrollDir_Vert]) | |
2447 | g_signal_connect (m_scrollBar[ScrollDir_Vert], "scroll_event", | |
2448 | G_CALLBACK (window_scroll_event), this); | |
35510e48 | 2449 | |
9fa72bd2 MR |
2450 | g_signal_connect (widget, "popup_menu", |
2451 | G_CALLBACK (wxgtk_window_popup_menu_callback), this); | |
2452 | g_signal_connect (widget, "enter_notify_event", | |
2453 | G_CALLBACK (gtk_window_enter_callback), this); | |
2454 | g_signal_connect (widget, "leave_notify_event", | |
2455 | G_CALLBACK (gtk_window_leave_callback), this); | |
013151c7 JS |
2456 | |
2457 | if (IsTopLevel() && m_wxwindow) | |
2458 | g_signal_connect (m_wxwindow, "style_set", | |
2459 | G_CALLBACK (gtk_window_style_set_callback), this); | |
362c6693 | 2460 | } |
c801d85f | 2461 | |
1e6feb95 | 2462 | bool wxWindowGTK::Destroy() |
c801d85f | 2463 | { |
0a164d4c | 2464 | m_hasVMT = false; |
c801d85f | 2465 | |
f03fc89f | 2466 | return wxWindowBase::Destroy(); |
362c6693 | 2467 | } |
c801d85f | 2468 | |
1e6feb95 | 2469 | void wxWindowGTK::DoMoveWindow(int x, int y, int width, int height) |
23efdd02 | 2470 | { |
08f53168 | 2471 | gtk_widget_set_size_request(m_widget, width, height); |
03647350 | 2472 | |
69597639 | 2473 | // inform the parent to perform the move |
03647350 | 2474 | wxASSERT_MSG(m_parent && m_parent->m_wxwindow, |
9a33c3ef | 2475 | "the parent window has no client area?"); |
08f53168 | 2476 | WX_PIZZA(m_parent->m_wxwindow)->move(m_widget, x, y); |
23efdd02 | 2477 | } |
2daa0ce9 | 2478 | |
82008f15 PC |
2479 | void wxWindowGTK::ConstrainSize() |
2480 | { | |
2481 | #ifdef __WXGPE__ | |
2482 | // GPE's window manager doesn't like size hints at all, esp. when the user | |
2483 | // has to use the virtual keyboard, so don't constrain size there | |
2484 | if (!IsTopLevel()) | |
2485 | #endif | |
2486 | { | |
2487 | const wxSize minSize = GetMinSize(); | |
2488 | const wxSize maxSize = GetMaxSize(); | |
2489 | if (minSize.x > 0 && m_width < minSize.x) m_width = minSize.x; | |
2490 | if (minSize.y > 0 && m_height < minSize.y) m_height = minSize.y; | |
2491 | if (maxSize.x > 0 && m_width > maxSize.x) m_width = maxSize.x; | |
2492 | if (maxSize.y > 0 && m_height > maxSize.y) m_height = maxSize.y; | |
2493 | } | |
2494 | } | |
2495 | ||
1e6feb95 | 2496 | void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags ) |
c801d85f | 2497 | { |
82b978d7 | 2498 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") ); |
1e6feb95 | 2499 | wxASSERT_MSG( (m_parent != NULL), wxT("wxWindowGTK::SetSize requires parent.\n") ); |
8bbe427f | 2500 | |
6d50fada PC |
2501 | if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0 && (x == -1 || y == -1)) |
2502 | { | |
2503 | int currentX, currentY; | |
2504 | GetPosition(¤tX, ¤tY); | |
2505 | if (x == -1) | |
2506 | x = currentX; | |
2507 | if (y == -1) | |
2508 | y = currentY; | |
2509 | } | |
a200c35e VS |
2510 | AdjustForParentClientOrigin(x, y, sizeFlags); |
2511 | ||
fe39b16a RR |
2512 | // calculate the best size if we should auto size the window |
2513 | if ( ((sizeFlags & wxSIZE_AUTO_WIDTH) && width == -1) || | |
2514 | ((sizeFlags & wxSIZE_AUTO_HEIGHT) && height == -1) ) | |
2515 | { | |
2516 | const wxSize sizeBest = GetBestSize(); | |
2517 | if ( (sizeFlags & wxSIZE_AUTO_WIDTH) && width == -1 ) | |
2518 | width = sizeBest.x; | |
2519 | if ( (sizeFlags & wxSIZE_AUTO_HEIGHT) && height == -1 ) | |
2520 | height = sizeBest.y; | |
2521 | } | |
2522 | ||
cca410b3 | 2523 | const wxSize oldSize(m_width, m_height); |
fe39b16a RR |
2524 | if (width != -1) |
2525 | m_width = width; | |
2526 | if (height != -1) | |
2527 | m_height = height; | |
2528 | ||
cca410b3 | 2529 | if (m_parent->m_wxwindow) |
fb1585ae | 2530 | { |
08f53168 PC |
2531 | wxPizza* pizza = WX_PIZZA(m_parent->m_wxwindow); |
2532 | m_x = x + pizza->m_scroll_x; | |
2533 | m_y = y + pizza->m_scroll_y; | |
47d67540 | 2534 | |
863e0817 RR |
2535 | int left_border = 0; |
2536 | int right_border = 0; | |
2537 | int top_border = 0; | |
c50f1fb9 | 2538 | int bottom_border = 0; |
f03fc89f | 2539 | |
863e0817 | 2540 | /* the default button has a border around it */ |
fc9ab22a | 2541 | if (gtk_widget_get_can_default(m_widget)) |
c50f1fb9 | 2542 | { |
f893066b RR |
2543 | GtkBorder *default_border = NULL; |
2544 | gtk_widget_style_get( m_widget, "default_border", &default_border, NULL ); | |
2545 | if (default_border) | |
863e0817 | 2546 | { |
f893066b RR |
2547 | left_border += default_border->left; |
2548 | right_border += default_border->right; | |
2549 | top_border += default_border->top; | |
2550 | bottom_border += default_border->bottom; | |
6cfdfed8 | 2551 | gtk_border_free( default_border ); |
863e0817 | 2552 | } |
863e0817 | 2553 | } |
c50f1fb9 | 2554 | |
18ac7bef PC |
2555 | DoMoveWindow( m_x - left_border, |
2556 | m_y - top_border, | |
863e0817 RR |
2557 | m_width+left_border+right_border, |
2558 | m_height+top_border+bottom_border ); | |
54517652 | 2559 | } |
148cd9b6 | 2560 | |
cca410b3 | 2561 | if (m_width != oldSize.x || m_height != oldSize.y) |
5b8a521e | 2562 | { |
cca410b3 PC |
2563 | // update these variables to keep size_allocate handler |
2564 | // from sending another size event for this change | |
5b8a521e | 2565 | GetClientSize( &m_oldClientWidth, &m_oldClientHeight ); |
6d693bb4 | 2566 | |
cca410b3 PC |
2567 | gtk_widget_queue_resize(m_widget); |
2568 | if (!m_nativeSizeEvent) | |
2569 | { | |
2570 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); | |
2571 | event.SetEventObject( this ); | |
937013e0 | 2572 | HandleWindowEvent( event ); |
cca410b3 | 2573 | } |
03647350 | 2574 | } else |
e47e063a RR |
2575 | if (sizeFlags & wxSIZE_FORCE_EVENT) |
2576 | { | |
2577 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); | |
2578 | event.SetEventObject( this ); | |
2579 | HandleWindowEvent( event ); | |
30760ce7 | 2580 | } |
362c6693 | 2581 | } |
c801d85f | 2582 | |
71ead4bf | 2583 | bool wxWindowGTK::GTKShowFromOnIdle() |
9390a202 | 2584 | { |
fc9ab22a | 2585 | if (IsShown() && m_showOnIdle && !gtk_widget_get_visible (m_widget)) |
f46ad98f RR |
2586 | { |
2587 | GtkAllocation alloc; | |
2588 | alloc.x = m_x; | |
2589 | alloc.y = m_y; | |
2590 | alloc.width = m_width; | |
2591 | alloc.height = m_height; | |
2592 | gtk_widget_size_allocate( m_widget, &alloc ); | |
2593 | gtk_widget_show( m_widget ); | |
2594 | wxShowEvent eventShow(GetId(), true); | |
2595 | eventShow.SetEventObject(this); | |
937013e0 | 2596 | HandleWindowEvent(eventShow); |
f46ad98f | 2597 | m_showOnIdle = false; |
7317857d | 2598 | return true; |
f46ad98f | 2599 | } |
02761f6c | 2600 | |
7317857d RR |
2601 | return false; |
2602 | } | |
2603 | ||
2604 | void wxWindowGTK::OnInternalIdle() | |
2605 | { | |
bd2e08d0 VS |
2606 | if ( gs_deferredFocusOut ) |
2607 | GTKHandleDeferredFocusOut(); | |
2608 | ||
7317857d | 2609 | // Check if we have to show window now |
71ead4bf | 2610 | if (GTKShowFromOnIdle()) return; |
7317857d RR |
2611 | |
2612 | if ( m_dirtyTabOrder ) | |
2613 | { | |
2614 | m_dirtyTabOrder = false; | |
2615 | RealizeTabOrder(); | |
2616 | } | |
2617 | ||
9c61c5b0 VZ |
2618 | // Update style if the window was not yet realized when |
2619 | // SetBackgroundStyle() was called | |
7317857d RR |
2620 | if (m_needsStyleChange) |
2621 | { | |
2622 | SetBackgroundStyle(GetBackgroundStyle()); | |
2623 | m_needsStyleChange = false; | |
2624 | } | |
02761f6c | 2625 | |
6a50a2c4 | 2626 | wxWindowBase::OnInternalIdle(); |
9390a202 RR |
2627 | } |
2628 | ||
1e6feb95 | 2629 | void wxWindowGTK::DoGetSize( int *width, int *height ) const |
c801d85f | 2630 | { |
82b978d7 | 2631 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 2632 | |
fb1585ae RR |
2633 | if (width) (*width) = m_width; |
2634 | if (height) (*height) = m_height; | |
362c6693 | 2635 | } |
c801d85f | 2636 | |
1e6feb95 | 2637 | void wxWindowGTK::DoSetClientSize( int width, int height ) |
c801d85f | 2638 | { |
82b978d7 RD |
2639 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
2640 | ||
949ff63e PC |
2641 | const wxSize size = GetSize(); |
2642 | const wxSize clientSize = GetClientSize(); | |
2643 | SetSize(width + (size.x - clientSize.x), height + (size.y - clientSize.y)); | |
362c6693 | 2644 | } |
c801d85f | 2645 | |
1e6feb95 | 2646 | void wxWindowGTK::DoGetClientSize( int *width, int *height ) const |
c801d85f | 2647 | { |
82b978d7 | 2648 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 2649 | |
09bf8378 PC |
2650 | int w = m_width; |
2651 | int h = m_height; | |
2652 | ||
fcdd5335 | 2653 | if ( m_wxwindow ) |
c801d85f | 2654 | { |
8466fc74 | 2655 | // if window is scrollable, account for scrollbars |
fcdd5335 | 2656 | if ( GTK_IS_SCROLLED_WINDOW(m_widget) ) |
8466fc74 | 2657 | { |
fcdd5335 VZ |
2658 | GtkPolicyType policy[ScrollDir_Max]; |
2659 | gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(m_widget), | |
2660 | &policy[ScrollDir_Horz], | |
2661 | &policy[ScrollDir_Vert]); | |
2662 | ||
2663 | for ( int i = 0; i < ScrollDir_Max; i++ ) | |
8466fc74 | 2664 | { |
fcdd5335 VZ |
2665 | // don't account for the scrollbars we don't have |
2666 | GtkRange * const range = m_scrollBar[i]; | |
2667 | if ( !range ) | |
2668 | continue; | |
2669 | ||
2670 | // nor for the ones we have but don't current show | |
2671 | switch ( policy[i] ) | |
2672 | { | |
2673 | case GTK_POLICY_NEVER: | |
2674 | // never shown so doesn't take any place | |
2675 | continue; | |
2676 | ||
2677 | case GTK_POLICY_ALWAYS: | |
2678 | // no checks necessary | |
2679 | break; | |
2680 | ||
2681 | case GTK_POLICY_AUTOMATIC: | |
2682 | // may be shown or not, check | |
2683 | GtkAdjustment *adj = gtk_range_get_adjustment(range); | |
989d151c | 2684 | if (gtk_adjustment_get_upper(adj) <= gtk_adjustment_get_page_size(adj)) |
fcdd5335 VZ |
2685 | continue; |
2686 | } | |
2687 | ||
9800347d | 2688 | GtkScrolledWindowClass *scroll_class = |
7da4a9cf RR |
2689 | GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget) ); |
2690 | ||
fcdd5335 VZ |
2691 | GtkRequisition req; |
2692 | gtk_widget_size_request(GTK_WIDGET(range), &req); | |
8466fc74 | 2693 | if (i == ScrollDir_Horz) |
7da4a9cf | 2694 | h -= req.height + scroll_class->scrollbar_spacing; |
8466fc74 | 2695 | else |
7da4a9cf | 2696 | w -= req.width + scroll_class->scrollbar_spacing; |
8466fc74 PC |
2697 | } |
2698 | } | |
09bf8378 | 2699 | |
b3554952 VZ |
2700 | const wxSize sizeBorders = DoGetBorderSize(); |
2701 | w -= sizeBorders.x; | |
2702 | h -= sizeBorders.y; | |
9000c624 | 2703 | |
69346023 PC |
2704 | if (w < 0) |
2705 | w = 0; | |
2706 | if (h < 0) | |
2707 | h = 0; | |
1ecc4d80 | 2708 | } |
1e6feb95 | 2709 | |
09bf8378 PC |
2710 | if (width) *width = w; |
2711 | if (height) *height = h; | |
362c6693 | 2712 | } |
c801d85f | 2713 | |
b3554952 VZ |
2714 | wxSize wxWindowGTK::DoGetBorderSize() const |
2715 | { | |
2716 | if ( !m_wxwindow ) | |
2717 | return wxWindowBase::DoGetBorderSize(); | |
2718 | ||
2719 | int x, y; | |
2720 | WX_PIZZA(m_wxwindow)->get_border_widths(x, y); | |
2721 | ||
2722 | return 2*wxSize(x, y); | |
2723 | } | |
2724 | ||
1e6feb95 | 2725 | void wxWindowGTK::DoGetPosition( int *x, int *y ) const |
c801d85f | 2726 | { |
82b978d7 | 2727 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 2728 | |
bf0c00c6 RR |
2729 | int dx = 0; |
2730 | int dy = 0; | |
fd8a7b0b | 2731 | if (!IsTopLevel() && m_parent && m_parent->m_wxwindow) |
bf0c00c6 | 2732 | { |
08f53168 PC |
2733 | wxPizza* pizza = WX_PIZZA(m_parent->m_wxwindow); |
2734 | dx = pizza->m_scroll_x; | |
2735 | dy = pizza->m_scroll_y; | |
bf0c00c6 | 2736 | } |
94633ad9 | 2737 | |
96c8547e JS |
2738 | if (m_x == -1 && m_y == -1) |
2739 | { | |
d3b9f782 | 2740 | GdkWindow *source = NULL; |
96c8547e | 2741 | if (m_wxwindow) |
989d151c | 2742 | source = gtk_widget_get_window(m_wxwindow); |
96c8547e | 2743 | else |
989d151c | 2744 | source = gtk_widget_get_window(m_widget); |
96c8547e JS |
2745 | |
2746 | if (source) | |
2747 | { | |
2748 | int org_x = 0; | |
2749 | int org_y = 0; | |
2750 | gdk_window_get_origin( source, &org_x, &org_y ); | |
2751 | ||
bb5521a9 VZ |
2752 | if (m_parent) |
2753 | m_parent->ScreenToClient(&org_x, &org_y); | |
96c8547e | 2754 | |
5c33522f VZ |
2755 | const_cast<wxWindowGTK*>(this)->m_x = org_x; |
2756 | const_cast<wxWindowGTK*>(this)->m_y = org_y; | |
bfeeb7f3 | 2757 | } |
96c8547e JS |
2758 | } |
2759 | ||
496beb3f VS |
2760 | if (x) (*x) = m_x - dx; |
2761 | if (y) (*y) = m_y - dy; | |
362c6693 | 2762 | } |
c801d85f | 2763 | |
1e6feb95 | 2764 | void wxWindowGTK::DoClientToScreen( int *x, int *y ) const |
c801d85f | 2765 | { |
82b978d7 | 2766 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 2767 | |
989d151c | 2768 | if (gtk_widget_get_window(m_widget) == NULL) return; |
a2053b27 | 2769 | |
d3b9f782 | 2770 | GdkWindow *source = NULL; |
43a18898 | 2771 | if (m_wxwindow) |
989d151c | 2772 | source = gtk_widget_get_window(m_wxwindow); |
43a18898 | 2773 | else |
989d151c | 2774 | source = gtk_widget_get_window(m_widget); |
47d67540 | 2775 | |
43a18898 RR |
2776 | int org_x = 0; |
2777 | int org_y = 0; | |
2778 | gdk_window_get_origin( source, &org_x, &org_y ); | |
c801d85f | 2779 | |
43a18898 | 2780 | if (!m_wxwindow) |
c801d85f | 2781 | { |
fc9ab22a | 2782 | if (!gtk_widget_get_has_window(m_widget)) |
43a18898 | 2783 | { |
989d151c PC |
2784 | GtkAllocation a; |
2785 | gtk_widget_get_allocation(m_widget, &a); | |
2786 | org_x += a.x; | |
2787 | org_y += a.y; | |
43a18898 | 2788 | } |
362c6693 | 2789 | } |
47d67540 | 2790 | |
49e74855 RR |
2791 | |
2792 | if (x) | |
2793 | { | |
2794 | if (GetLayoutDirection() == wxLayout_RightToLeft) | |
2795 | *x = (GetClientSize().x - *x) + org_x; | |
fcb29b23 | 2796 | else |
49e74855 RR |
2797 | *x += org_x; |
2798 | } | |
fcb29b23 | 2799 | |
43a18898 | 2800 | if (y) *y += org_y; |
362c6693 | 2801 | } |
c801d85f | 2802 | |
1e6feb95 | 2803 | void wxWindowGTK::DoScreenToClient( int *x, int *y ) const |
c801d85f | 2804 | { |
82b978d7 | 2805 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
47d67540 | 2806 | |
989d151c | 2807 | if (!gtk_widget_get_realized(m_widget)) return; |
a2053b27 | 2808 | |
d3b9f782 | 2809 | GdkWindow *source = NULL; |
1ecc4d80 | 2810 | if (m_wxwindow) |
989d151c | 2811 | source = gtk_widget_get_window(m_wxwindow); |
1ecc4d80 | 2812 | else |
989d151c | 2813 | source = gtk_widget_get_window(m_widget); |
47d67540 | 2814 | |
1ecc4d80 RR |
2815 | int org_x = 0; |
2816 | int org_y = 0; | |
2817 | gdk_window_get_origin( source, &org_x, &org_y ); | |
c801d85f | 2818 | |
1ecc4d80 | 2819 | if (!m_wxwindow) |
c801d85f | 2820 | { |
fc9ab22a | 2821 | if (!gtk_widget_get_has_window(m_widget)) |
1ecc4d80 | 2822 | { |
989d151c PC |
2823 | GtkAllocation a; |
2824 | gtk_widget_get_allocation(m_widget, &a); | |
2825 | org_x += a.x; | |
2826 | org_y += a.y; | |
1ecc4d80 | 2827 | } |
362c6693 | 2828 | } |
47d67540 | 2829 | |
49e74855 RR |
2830 | if (x) |
2831 | { | |
2832 | if (GetLayoutDirection() == wxLayout_RightToLeft) | |
2833 | *x = (GetClientSize().x - *x) - org_x; | |
fcb29b23 | 2834 | else |
49e74855 RR |
2835 | *x -= org_x; |
2836 | } | |
1ecc4d80 | 2837 | if (y) *y -= org_y; |
362c6693 | 2838 | } |
c801d85f | 2839 | |
1e6feb95 | 2840 | bool wxWindowGTK::Show( bool show ) |
c801d85f | 2841 | { |
3cc57044 | 2842 | if ( !wxWindowBase::Show(show) ) |
739730ca RR |
2843 | { |
2844 | // nothing to do | |
0a164d4c | 2845 | return false; |
739730ca | 2846 | } |
8bbe427f | 2847 | |
3cc57044 VZ |
2848 | // notice that we may call Hide() before the window is created and this is |
2849 | // actually useful to create it hidden initially -- but we can't call | |
2850 | // Show() before it is created | |
2851 | if ( !m_widget ) | |
f46ad98f | 2852 | { |
3cc57044 VZ |
2853 | wxASSERT_MSG( !show, "can't show invalid window" ); |
2854 | return true; | |
f46ad98f | 2855 | } |
3cc57044 VZ |
2856 | |
2857 | if ( show ) | |
f46ad98f | 2858 | { |
3cc57044 VZ |
2859 | if ( m_showOnIdle ) |
2860 | { | |
2861 | // defer until later | |
2862 | return true; | |
2863 | } | |
2864 | ||
2865 | gtk_widget_show(m_widget); | |
f46ad98f | 2866 | } |
3cc57044 VZ |
2867 | else // hide |
2868 | { | |
2869 | gtk_widget_hide(m_widget); | |
2870 | } | |
2871 | ||
2872 | wxShowEvent eventShow(GetId(), show); | |
2873 | eventShow.SetEventObject(this); | |
2874 | HandleWindowEvent(eventShow); | |
2b5f62a0 | 2875 | |
0a164d4c | 2876 | return true; |
362c6693 | 2877 | } |
c801d85f | 2878 | |
47a8a4d5 | 2879 | void wxWindowGTK::DoEnable( bool enable ) |
fdca68a6 | 2880 | { |
47a8a4d5 | 2881 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
1ecc4d80 | 2882 | |
f03fc89f | 2883 | gtk_widget_set_sensitive( m_widget, enable ); |
6552c7af | 2884 | if (m_wxwindow && (m_wxwindow != m_widget)) |
f03fc89f | 2885 | gtk_widget_set_sensitive( m_wxwindow, enable ); |
362c6693 | 2886 | } |
c801d85f | 2887 | |
1e6feb95 | 2888 | int wxWindowGTK::GetCharHeight() const |
2f2aa628 | 2889 | { |
82b978d7 | 2890 | wxCHECK_MSG( (m_widget != NULL), 12, wxT("invalid window") ); |
47d67540 | 2891 | |
cc402e64 | 2892 | wxFont font = GetFont(); |
a1b806b9 | 2893 | wxCHECK_MSG( font.IsOk(), 12, wxT("invalid font") ); |
2f2aa628 | 2894 | |
db885f2a | 2895 | PangoContext* context = gtk_widget_get_pango_context(m_widget); |
bbd006c0 RR |
2896 | |
2897 | if (!context) | |
2898 | return 0; | |
2899 | ||
cc402e64 | 2900 | PangoFontDescription *desc = font.GetNativeFontInfo()->description; |
bbd006c0 RR |
2901 | PangoLayout *layout = pango_layout_new(context); |
2902 | pango_layout_set_font_description(layout, desc); | |
2903 | pango_layout_set_text(layout, "H", 1); | |
2904 | PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data; | |
2905 | ||
2906 | PangoRectangle rect; | |
2907 | pango_layout_line_get_extents(line, NULL, &rect); | |
2908 | ||
3fe39b0c | 2909 | g_object_unref (layout); |
7de59551 | 2910 | |
f69e2009 | 2911 | return (int) PANGO_PIXELS(rect.height); |
362c6693 | 2912 | } |
c801d85f | 2913 | |
1e6feb95 | 2914 | int wxWindowGTK::GetCharWidth() const |
c33c4050 | 2915 | { |
82b978d7 | 2916 | wxCHECK_MSG( (m_widget != NULL), 8, wxT("invalid window") ); |
47d67540 | 2917 | |
cc402e64 | 2918 | wxFont font = GetFont(); |
a1b806b9 | 2919 | wxCHECK_MSG( font.IsOk(), 8, wxT("invalid font") ); |
47d67540 | 2920 | |
db885f2a | 2921 | PangoContext* context = gtk_widget_get_pango_context(m_widget); |
bbd006c0 RR |
2922 | |
2923 | if (!context) | |
2924 | return 0; | |
2925 | ||
cc402e64 | 2926 | PangoFontDescription *desc = font.GetNativeFontInfo()->description; |
bbd006c0 RR |
2927 | PangoLayout *layout = pango_layout_new(context); |
2928 | pango_layout_set_font_description(layout, desc); | |
95c430aa | 2929 | pango_layout_set_text(layout, "g", 1); |
bbd006c0 RR |
2930 | PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data; |
2931 | ||
2932 | PangoRectangle rect; | |
2933 | pango_layout_line_get_extents(line, NULL, &rect); | |
2934 | ||
3fe39b0c | 2935 | g_object_unref (layout); |
7de59551 | 2936 | |
f69e2009 | 2937 | return (int) PANGO_PIXELS(rect.width); |
c33c4050 RR |
2938 | } |
2939 | ||
6de70470 VZ |
2940 | void wxWindowGTK::DoGetTextExtent( const wxString& string, |
2941 | int *x, | |
2942 | int *y, | |
2943 | int *descent, | |
2944 | int *externalLeading, | |
2945 | const wxFont *theFont ) const | |
c33c4050 | 2946 | { |
cc402e64 | 2947 | wxFont fontToUse = theFont ? *theFont : GetFont(); |
47d67540 | 2948 | |
a1b806b9 | 2949 | wxCHECK_RET( fontToUse.IsOk(), wxT("invalid font") ); |
2b5f62a0 | 2950 | |
0a164d4c | 2951 | if (string.empty()) |
48d011c8 | 2952 | { |
b15ed747 RR |
2953 | if (x) (*x) = 0; |
2954 | if (y) (*y) = 0; | |
48d011c8 RR |
2955 | return; |
2956 | } | |
47d67540 | 2957 | |
48d011c8 RR |
2958 | PangoContext *context = NULL; |
2959 | if (m_widget) | |
2b5f62a0 VZ |
2960 | context = gtk_widget_get_pango_context( m_widget ); |
2961 | ||
48d011c8 RR |
2962 | if (!context) |
2963 | { | |
b15ed747 RR |
2964 | if (x) (*x) = 0; |
2965 | if (y) (*y) = 0; | |
48d011c8 RR |
2966 | return; |
2967 | } | |
2b5f62a0 | 2968 | |
48d011c8 RR |
2969 | PangoFontDescription *desc = fontToUse.GetNativeFontInfo()->description; |
2970 | PangoLayout *layout = pango_layout_new(context); | |
2971 | pango_layout_set_font_description(layout, desc); | |
2972 | { | |
a3669332 VZ |
2973 | const wxCharBuffer data = wxGTK_CONV( string ); |
2974 | if ( data ) | |
2975 | pango_layout_set_text(layout, data, strlen(data)); | |
48d011c8 | 2976 | } |
2b5f62a0 | 2977 | |
48d011c8 | 2978 | PangoRectangle rect; |
fd43b1b3 | 2979 | pango_layout_get_extents(layout, NULL, &rect); |
2b5f62a0 | 2980 | |
f69e2009 VS |
2981 | if (x) (*x) = (wxCoord) PANGO_PIXELS(rect.width); |
2982 | if (y) (*y) = (wxCoord) PANGO_PIXELS(rect.height); | |
48d011c8 RR |
2983 | if (descent) |
2984 | { | |
f69e2009 VS |
2985 | PangoLayoutIter *iter = pango_layout_get_iter(layout); |
2986 | int baseline = pango_layout_iter_get_baseline(iter); | |
2987 | pango_layout_iter_free(iter); | |
2988 | *descent = *y - PANGO_PIXELS(baseline); | |
48d011c8 RR |
2989 | } |
2990 | if (externalLeading) (*externalLeading) = 0; // ?? | |
2b5f62a0 | 2991 | |
3fe39b0c | 2992 | g_object_unref (layout); |
c33c4050 RR |
2993 | } |
2994 | ||
36a845fe RR |
2995 | void wxWindowGTK::GTKDisableFocusOutEvent() |
2996 | { | |
2997 | g_signal_handlers_block_by_func( m_focusWidget, | |
2998 | (gpointer) gtk_window_focus_out_callback, this); | |
2999 | } | |
3000 | ||
3001 | void wxWindowGTK::GTKEnableFocusOutEvent() | |
3002 | { | |
3003 | g_signal_handlers_unblock_by_func( m_focusWidget, | |
3004 | (gpointer) gtk_window_focus_out_callback, this); | |
3005 | } | |
bd2e08d0 VS |
3006 | |
3007 | bool wxWindowGTK::GTKHandleFocusIn() | |
ef5c70f9 | 3008 | { |
bd2e08d0 VS |
3009 | // Disable default focus handling for custom windows since the default GTK+ |
3010 | // handler issues a repaint | |
3011 | const bool retval = m_wxwindow ? true : false; | |
3012 | ||
3013 | ||
3014 | // NB: if there's still unprocessed deferred focus-out event (see | |
3015 | // GTKHandleFocusOut() for explanation), we need to process it first so | |
3016 | // that the order of focus events -- focus-out first, then focus-in | |
3017 | // elsewhere -- is preserved | |
3018 | if ( gs_deferredFocusOut ) | |
ef5c70f9 | 3019 | { |
bd2e08d0 VS |
3020 | if ( GTKNeedsToFilterSameWindowFocus() && |
3021 | gs_deferredFocusOut == this ) | |
ef5c70f9 | 3022 | { |
bd2e08d0 VS |
3023 | // GTK+ focus changed from this wxWindow back to itself, so don't |
3024 | // emit any events at all | |
3025 | wxLogTrace(TRACE_FOCUS, | |
3026 | "filtered out spurious focus change within %s(%p, %s)", | |
3027 | GetClassInfo()->GetClassName(), this, GetLabel()); | |
3028 | gs_deferredFocusOut = NULL; | |
3029 | return retval; | |
ef5c70f9 | 3030 | } |
bd2e08d0 VS |
3031 | |
3032 | // otherwise we need to send focus-out first | |
3033 | wxASSERT_MSG ( gs_deferredFocusOut != this, | |
3034 | "GTKHandleFocusIn(GTKFocus_Normal) called even though focus changed back to itself - derived class should handle this" ); | |
3035 | GTKHandleDeferredFocusOut(); | |
ef5c70f9 VZ |
3036 | } |
3037 | ||
bd2e08d0 VS |
3038 | |
3039 | wxLogTrace(TRACE_FOCUS, | |
3040 | "handling focus_in event for %s(%p, %s)", | |
3041 | GetClassInfo()->GetClassName(), this, GetLabel()); | |
3042 | ||
3043 | if (m_imData) | |
3044 | gtk_im_context_focus_in(m_imData->context); | |
3045 | ||
22f43cb5 VS |
3046 | gs_currentFocus = this; |
3047 | gs_pendingFocus = NULL; | |
bd2e08d0 VS |
3048 | |
3049 | #if wxUSE_CARET | |
3050 | // caret needs to be informed about focus change | |
3051 | wxCaret *caret = GetCaret(); | |
3052 | if ( caret ) | |
3053 | { | |
3054 | caret->OnSetFocus(); | |
3055 | } | |
3056 | #endif // wxUSE_CARET | |
3057 | ||
3058 | // Notify the parent keeping track of focus for the kbd navigation | |
3059 | // purposes that we got it. | |
b22bb1a0 | 3060 | wxChildFocusEvent eventChildFocus(static_cast<wxWindow*>(this)); |
bd2e08d0 VS |
3061 | GTKProcessEvent(eventChildFocus); |
3062 | ||
3063 | wxFocusEvent eventFocus(wxEVT_SET_FOCUS, GetId()); | |
3064 | eventFocus.SetEventObject(this); | |
3065 | GTKProcessEvent(eventFocus); | |
3066 | ||
3067 | return retval; | |
ef5c70f9 VZ |
3068 | } |
3069 | ||
bd2e08d0 | 3070 | bool wxWindowGTK::GTKHandleFocusOut() |
7cec1c9e | 3071 | { |
bd2e08d0 VS |
3072 | // Disable default focus handling for custom windows since the default GTK+ |
3073 | // handler issues a repaint | |
3074 | const bool retval = m_wxwindow ? true : false; | |
3075 | ||
3076 | ||
3077 | // NB: If a control is composed of several GtkWidgets and when focus | |
3078 | // changes from one of them to another within the same wxWindow, we get | |
3079 | // a focus-out event followed by focus-in for another GtkWidget owned | |
3080 | // by the same wx control. We don't want to generate two spurious | |
3081 | // wxEVT_SET_FOCUS events in this case, so we defer sending wx events | |
3082 | // from GTKHandleFocusOut() until we know for sure it's not coming back | |
3083 | // (i.e. in GTKHandleFocusIn() or at idle time). | |
3084 | if ( GTKNeedsToFilterSameWindowFocus() ) | |
7cec1c9e | 3085 | { |
bd2e08d0 VS |
3086 | wxASSERT_MSG( gs_deferredFocusOut == NULL, |
3087 | "deferred focus out event already pending" ); | |
3088 | wxLogTrace(TRACE_FOCUS, | |
3089 | "deferring focus_out event for %s(%p, %s)", | |
3090 | GetClassInfo()->GetClassName(), this, GetLabel()); | |
3091 | gs_deferredFocusOut = this; | |
3092 | return retval; | |
7cec1c9e RR |
3093 | } |
3094 | ||
bd2e08d0 VS |
3095 | GTKHandleFocusOutNoDeferring(); |
3096 | ||
3097 | return retval; | |
3098 | } | |
3099 | ||
3100 | void wxWindowGTK::GTKHandleFocusOutNoDeferring() | |
3101 | { | |
3102 | wxLogTrace(TRACE_FOCUS, | |
3103 | "handling focus_out event for %s(%p, %s)", | |
3104 | GetClassInfo()->GetClassName(), this, GetLabel()); | |
3105 | ||
3106 | if (m_imData) | |
3107 | gtk_im_context_focus_out(m_imData->context); | |
3108 | ||
22f43cb5 | 3109 | if ( gs_currentFocus != this ) |
7cec1c9e | 3110 | { |
22f43cb5 | 3111 | // Something is terribly wrong, gs_currentFocus is out of sync with the |
bd2e08d0 VS |
3112 | // real focus. We will reset it to NULL anyway, because after this |
3113 | // focus-out event is handled, one of the following with happen: | |
3114 | // | |
3115 | // * either focus will go out of the app altogether, in which case | |
22f43cb5 | 3116 | // gs_currentFocus _should_ be NULL |
bd2e08d0 VS |
3117 | // |
3118 | // * or it goes to another control, in which case focus-in event will | |
22f43cb5 | 3119 | // follow immediately and it will set gs_currentFocus to the right |
bd2e08d0 VS |
3120 | // value |
3121 | wxLogDebug("window %s(%p, %s) lost focus even though it didn't have it", | |
3122 | GetClassInfo()->GetClassName(), this, GetLabel()); | |
3123 | } | |
22f43cb5 | 3124 | gs_currentFocus = NULL; |
db885f2a | 3125 | |
bd2e08d0 VS |
3126 | #if wxUSE_CARET |
3127 | // caret needs to be informed about focus change | |
3128 | wxCaret *caret = GetCaret(); | |
3129 | if ( caret ) | |
3130 | { | |
3131 | caret->OnKillFocus(); | |
354aa1e3 | 3132 | } |
bd2e08d0 VS |
3133 | #endif // wxUSE_CARET |
3134 | ||
3135 | wxFocusEvent event( wxEVT_KILL_FOCUS, GetId() ); | |
3136 | event.SetEventObject( this ); | |
9a237e2f | 3137 | event.SetWindow( FindFocus() ); |
bd2e08d0 VS |
3138 | GTKProcessEvent( event ); |
3139 | } | |
3140 | ||
3141 | /*static*/ | |
3142 | void wxWindowGTK::GTKHandleDeferredFocusOut() | |
3143 | { | |
3144 | // NB: See GTKHandleFocusOut() for explanation. This function is called | |
3145 | // from either GTKHandleFocusIn() or OnInternalIdle() to process | |
3146 | // deferred event. | |
3147 | if ( gs_deferredFocusOut ) | |
c801d85f | 3148 | { |
bd2e08d0 VS |
3149 | wxWindowGTK *win = gs_deferredFocusOut; |
3150 | gs_deferredFocusOut = NULL; | |
db885f2a | 3151 | |
bd2e08d0 VS |
3152 | wxLogTrace(TRACE_FOCUS, |
3153 | "processing deferred focus_out event for %s(%p, %s)", | |
3154 | win->GetClassInfo()->GetClassName(), win, win->GetLabel()); | |
fcb29b23 | 3155 | |
bd2e08d0 VS |
3156 | win->GTKHandleFocusOutNoDeferring(); |
3157 | } | |
3158 | } | |
0a164d4c | 3159 | |
bd2e08d0 VS |
3160 | void wxWindowGTK::SetFocus() |
3161 | { | |
3162 | wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); | |
6aeb6f2a | 3163 | |
bd2e08d0 VS |
3164 | // Setting "physical" focus is not immediate in GTK+ and while |
3165 | // gtk_widget_is_focus ("determines if the widget is the focus widget | |
3166 | // within its toplevel", i.e. returns true for one widget per TLW, not | |
3167 | // globally) returns true immediately after grabbing focus, | |
3168 | // GTK_WIDGET_HAS_FOCUS (which returns true only for the one widget that | |
4c51a665 | 3169 | // has focus at the moment) takes effect only after the window is shown |
bd2e08d0 VS |
3170 | // (if it was hidden at the moment of the call) or at the next event loop |
3171 | // iteration. | |
3172 | // | |
3173 | // Because we want to FindFocus() call immediately following | |
3174 | // foo->SetFocus() to return foo, we have to keep track of "pending" focus | |
3175 | // ourselves. | |
22f43cb5 | 3176 | gs_pendingFocus = this; |
bd2e08d0 VS |
3177 | |
3178 | GtkWidget *widget = m_wxwindow ? m_wxwindow : m_focusWidget; | |
3179 | ||
3180 | if ( GTK_IS_CONTAINER(widget) && | |
fc9ab22a | 3181 | !gtk_widget_get_can_focus(widget) ) |
bd2e08d0 VS |
3182 | { |
3183 | wxLogTrace(TRACE_FOCUS, | |
9a83f860 | 3184 | wxT("Setting focus to a child of %s(%p, %s)"), |
bd2e08d0 VS |
3185 | GetClassInfo()->GetClassName(), this, GetLabel().c_str()); |
3186 | gtk_widget_child_focus(widget, GTK_DIR_TAB_FORWARD); | |
3187 | } | |
3188 | else | |
3189 | { | |
3190 | wxLogTrace(TRACE_FOCUS, | |
9a83f860 | 3191 | wxT("Setting focus to %s(%p, %s)"), |
bd2e08d0 VS |
3192 | GetClassInfo()->GetClassName(), this, GetLabel().c_str()); |
3193 | gtk_widget_grab_focus(widget); | |
362c6693 | 3194 | } |
362c6693 | 3195 | } |
c801d85f | 3196 | |
80332672 VZ |
3197 | void wxWindowGTK::SetCanFocus(bool canFocus) |
3198 | { | |
fc9ab22a | 3199 | gtk_widget_set_can_focus(m_widget, canFocus); |
80332672 VZ |
3200 | |
3201 | if ( m_wxwindow && (m_widget != m_wxwindow) ) | |
3202 | { | |
fc9ab22a | 3203 | gtk_widget_set_can_focus(m_wxwindow, canFocus); |
80332672 VZ |
3204 | } |
3205 | } | |
3206 | ||
1e6feb95 | 3207 | bool wxWindowGTK::Reparent( wxWindowBase *newParentBase ) |
463c1fa1 | 3208 | { |
0a164d4c | 3209 | wxCHECK_MSG( (m_widget != NULL), false, wxT("invalid window") ); |
c50f1fb9 | 3210 | |
0edbdf6a | 3211 | wxWindowGTK * const newParent = (wxWindowGTK *)newParentBase; |
a2053b27 | 3212 | |
5fd11f09 RR |
3213 | wxASSERT( GTK_IS_WIDGET(m_widget) ); |
3214 | ||
f03fc89f | 3215 | if ( !wxWindowBase::Reparent(newParent) ) |
0a164d4c | 3216 | return false; |
8bbe427f | 3217 | |
5fd11f09 RR |
3218 | wxASSERT( GTK_IS_WIDGET(m_widget) ); |
3219 | ||
0edbdf6a VZ |
3220 | // Notice that old m_parent pointer might be non-NULL here but the widget |
3221 | // still not have any parent at GTK level if it's a notebook page that had | |
3222 | // been removed from the notebook so test this at GTK level and not wx one. | |
3223 | if ( GtkWidget *parentGTK = gtk_widget_get_parent(m_widget) ) | |
3224 | gtk_container_remove(GTK_CONTAINER(parentGTK), m_widget); | |
c50f1fb9 | 3225 | |
5fd11f09 RR |
3226 | wxASSERT( GTK_IS_WIDGET(m_widget) ); |
3227 | ||
8ce63e9d RR |
3228 | if (newParent) |
3229 | { | |
fc9ab22a | 3230 | if (gtk_widget_get_visible (newParent->m_widget)) |
f46ad98f RR |
3231 | { |
3232 | m_showOnIdle = true; | |
3233 | gtk_widget_hide( m_widget ); | |
3234 | } | |
8ce63e9d | 3235 | /* insert GTK representation */ |
48200154 | 3236 | newParent->AddChildGTK(this); |
8ce63e9d | 3237 | } |
c50f1fb9 | 3238 | |
978af864 | 3239 | SetLayoutDirection(wxLayout_Default); |
148cd9b6 | 3240 | |
0a164d4c | 3241 | return true; |
362c6693 | 3242 | } |
c801d85f | 3243 | |
1e6feb95 | 3244 | void wxWindowGTK::DoAddChild(wxWindowGTK *child) |
ddb6bc71 | 3245 | { |
223d09f6 | 3246 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid window") ); |
223d09f6 | 3247 | wxASSERT_MSG( (child != NULL), wxT("invalid child window") ); |
ddb6bc71 | 3248 | |
ddb6bc71 RR |
3249 | /* add to list */ |
3250 | AddChild( child ); | |
c50f1fb9 | 3251 | |
ddb6bc71 | 3252 | /* insert GTK representation */ |
48200154 | 3253 | AddChildGTK(child); |
ddb6bc71 RR |
3254 | } |
3255 | ||
a589495e VS |
3256 | void wxWindowGTK::AddChild(wxWindowBase *child) |
3257 | { | |
3258 | wxWindowBase::AddChild(child); | |
3259 | m_dirtyTabOrder = true; | |
a1abca32 | 3260 | wxTheApp->WakeUpIdle(); |
a589495e VS |
3261 | } |
3262 | ||
3263 | void wxWindowGTK::RemoveChild(wxWindowBase *child) | |
3264 | { | |
3265 | wxWindowBase::RemoveChild(child); | |
3266 | m_dirtyTabOrder = true; | |
a1abca32 | 3267 | wxTheApp->WakeUpIdle(); |
a589495e | 3268 | } |
0a164d4c | 3269 | |
978af864 VZ |
3270 | /* static */ |
3271 | wxLayoutDirection wxWindowGTK::GTKGetLayout(GtkWidget *widget) | |
3272 | { | |
10bd1f7d | 3273 | return gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL |
978af864 VZ |
3274 | ? wxLayout_RightToLeft |
3275 | : wxLayout_LeftToRight; | |
3276 | } | |
3277 | ||
3278 | /* static */ | |
3279 | void wxWindowGTK::GTKSetLayout(GtkWidget *widget, wxLayoutDirection dir) | |
3280 | { | |
9a83f860 | 3281 | wxASSERT_MSG( dir != wxLayout_Default, wxT("invalid layout direction") ); |
978af864 | 3282 | |
10bd1f7d | 3283 | gtk_widget_set_direction(widget, |
978af864 VZ |
3284 | dir == wxLayout_RightToLeft ? GTK_TEXT_DIR_RTL |
3285 | : GTK_TEXT_DIR_LTR); | |
3286 | } | |
3287 | ||
3288 | wxLayoutDirection wxWindowGTK::GetLayoutDirection() const | |
3289 | { | |
3290 | return GTKGetLayout(m_widget); | |
3291 | } | |
3292 | ||
3293 | void wxWindowGTK::SetLayoutDirection(wxLayoutDirection dir) | |
3294 | { | |
3295 | if ( dir == wxLayout_Default ) | |
3296 | { | |
3297 | const wxWindow *const parent = GetParent(); | |
3298 | if ( parent ) | |
3299 | { | |
3300 | // inherit layout from parent. | |
3301 | dir = parent->GetLayoutDirection(); | |
3302 | } | |
3303 | else // no parent, use global default layout | |
3304 | { | |
3305 | dir = wxTheApp->GetLayoutDirection(); | |
3306 | } | |
3307 | } | |
3308 | ||
3309 | if ( dir == wxLayout_Default ) | |
3310 | return; | |
3311 | ||
3312 | GTKSetLayout(m_widget, dir); | |
fcb29b23 | 3313 | |
6552c7af | 3314 | if (m_wxwindow && (m_wxwindow != m_widget)) |
69597639 RR |
3315 | GTKSetLayout(m_wxwindow, dir); |
3316 | } | |
3317 | ||
3318 | wxCoord | |
3319 | wxWindowGTK::AdjustForLayoutDirection(wxCoord x, | |
3320 | wxCoord WXUNUSED(width), | |
3321 | wxCoord WXUNUSED(widthTotal)) const | |
3322 | { | |
08f53168 | 3323 | // We now mirror the coordinates of RTL windows in wxPizza |
69597639 | 3324 | return x; |
978af864 VZ |
3325 | } |
3326 | ||
915bd4e4 | 3327 | void wxWindowGTK::DoMoveInTabOrder(wxWindow *win, WindowOrder move) |
a589495e VS |
3328 | { |
3329 | wxWindowBase::DoMoveInTabOrder(win, move); | |
3330 | m_dirtyTabOrder = true; | |
a1abca32 | 3331 | wxTheApp->WakeUpIdle(); |
a589495e VS |
3332 | } |
3333 | ||
5644933f VZ |
3334 | bool wxWindowGTK::DoNavigateIn(int flags) |
3335 | { | |
3336 | if ( flags & wxNavigationKeyEvent::WinChange ) | |
3337 | { | |
9a83f860 | 3338 | wxFAIL_MSG( wxT("not implemented") ); |
5644933f VZ |
3339 | |
3340 | return false; | |
3341 | } | |
3342 | else // navigate inside the container | |
3343 | { | |
7a3ba5af | 3344 | wxWindow *parent = wxGetTopLevelParent((wxWindow *)this); |
9a83f860 | 3345 | wxCHECK_MSG( parent, false, wxT("every window must have a TLW parent") ); |
5644933f VZ |
3346 | |
3347 | GtkDirectionType dir; | |
3348 | dir = flags & wxNavigationKeyEvent::IsForward ? GTK_DIR_TAB_FORWARD | |
3349 | : GTK_DIR_TAB_BACKWARD; | |
3350 | ||
3351 | gboolean rc; | |
3352 | g_signal_emit_by_name(parent->m_widget, "focus", dir, &rc); | |
3353 | ||
3354 | return rc == TRUE; | |
3355 | } | |
3356 | } | |
3357 | ||
2e1f5012 VZ |
3358 | bool wxWindowGTK::GTKWidgetNeedsMnemonic() const |
3359 | { | |
3360 | // none needed by default | |
3361 | return false; | |
3362 | } | |
3363 | ||
3364 | void wxWindowGTK::GTKWidgetDoSetMnemonic(GtkWidget* WXUNUSED(w)) | |
3365 | { | |
3366 | // nothing to do by default since none is needed | |
3367 | } | |
3368 | ||
a589495e VS |
3369 | void wxWindowGTK::RealizeTabOrder() |
3370 | { | |
3371 | if (m_wxwindow) | |
3372 | { | |
12848fda | 3373 | if ( !m_children.empty() ) |
a589495e | 3374 | { |
259858fc | 3375 | // we don't only construct the correct focus chain but also use |
2e1f5012 VZ |
3376 | // this opportunity to update the mnemonic widgets for the widgets |
3377 | // that need them | |
259858fc | 3378 | |
a589495e | 3379 | GList *chain = NULL; |
2e1f5012 | 3380 | wxWindowGTK* mnemonicWindow = NULL; |
0a164d4c | 3381 | |
12848fda VZ |
3382 | for ( wxWindowList::const_iterator i = m_children.begin(); |
3383 | i != m_children.end(); | |
3384 | ++i ) | |
a589495e | 3385 | { |
259858fc | 3386 | wxWindowGTK *win = *i; |
2e1f5012 | 3387 | |
a3edb930 VZ |
3388 | bool focusableFromKeyboard = win->AcceptsFocusFromKeyboard(); |
3389 | ||
2e1f5012 | 3390 | if ( mnemonicWindow ) |
259858fc | 3391 | { |
a3edb930 | 3392 | if ( focusableFromKeyboard ) |
259858fc | 3393 | { |
2e1f5012 VZ |
3394 | // wxComboBox et al. needs to focus on on a different |
3395 | // widget than m_widget, so if the main widget isn't | |
3396 | // focusable try the connect widget | |
3397 | GtkWidget* w = win->m_widget; | |
fc9ab22a | 3398 | if ( !gtk_widget_get_can_focus(w) ) |
2e1f5012 VZ |
3399 | { |
3400 | w = win->GetConnectWidget(); | |
fc9ab22a | 3401 | if ( !gtk_widget_get_can_focus(w) ) |
2e1f5012 VZ |
3402 | w = NULL; |
3403 | } | |
3404 | ||
3405 | if ( w ) | |
3406 | { | |
3407 | mnemonicWindow->GTKWidgetDoSetMnemonic(w); | |
3408 | mnemonicWindow = NULL; | |
3409 | } | |
259858fc VZ |
3410 | } |
3411 | } | |
2e1f5012 | 3412 | else if ( win->GTKWidgetNeedsMnemonic() ) |
259858fc | 3413 | { |
2e1f5012 | 3414 | mnemonicWindow = win; |
259858fc | 3415 | } |
259858fc | 3416 | |
a3edb930 VZ |
3417 | if ( focusableFromKeyboard ) |
3418 | chain = g_list_prepend(chain, win->m_widget); | |
a589495e | 3419 | } |
0a164d4c | 3420 | |
a589495e | 3421 | chain = g_list_reverse(chain); |
0a164d4c | 3422 | |
a589495e VS |
3423 | gtk_container_set_focus_chain(GTK_CONTAINER(m_wxwindow), chain); |
3424 | g_list_free(chain); | |
3425 | } | |
12848fda | 3426 | else // no children |
a589495e VS |
3427 | { |
3428 | gtk_container_unset_focus_chain(GTK_CONTAINER(m_wxwindow)); | |
3429 | } | |
3430 | } | |
a589495e VS |
3431 | } |
3432 | ||
1e6feb95 | 3433 | void wxWindowGTK::Raise() |
362c6693 | 3434 | { |
82b978d7 RD |
3435 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
3436 | ||
989d151c | 3437 | if (m_wxwindow && gtk_widget_get_window(m_wxwindow)) |
fdfb8475 | 3438 | { |
989d151c | 3439 | gdk_window_raise(gtk_widget_get_window(m_wxwindow)); |
fdfb8475 | 3440 | } |
989d151c | 3441 | else if (gtk_widget_get_window(m_widget)) |
fdfb8475 | 3442 | { |
989d151c | 3443 | gdk_window_raise(gtk_widget_get_window(m_widget)); |
fdfb8475 | 3444 | } |
362c6693 RR |
3445 | } |
3446 | ||
1e6feb95 | 3447 | void wxWindowGTK::Lower() |
362c6693 | 3448 | { |
82b978d7 RD |
3449 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
3450 | ||
989d151c | 3451 | if (m_wxwindow && gtk_widget_get_window(m_wxwindow)) |
fdfb8475 | 3452 | { |
989d151c | 3453 | gdk_window_lower(gtk_widget_get_window(m_wxwindow)); |
fdfb8475 | 3454 | } |
989d151c | 3455 | else if (gtk_widget_get_window(m_widget)) |
fdfb8475 | 3456 | { |
989d151c | 3457 | gdk_window_lower(gtk_widget_get_window(m_widget)); |
fdfb8475 | 3458 | } |
362c6693 | 3459 | } |
c801d85f | 3460 | |
1e6feb95 | 3461 | bool wxWindowGTK::SetCursor( const wxCursor &cursor ) |
86b29a61 | 3462 | { |
a1b806b9 | 3463 | if ( !wxWindowBase::SetCursor(cursor.IsOk() ? cursor : *wxSTANDARD_CURSOR) ) |
2f262021 | 3464 | return false; |
f6bcfd97 | 3465 | |
2f262021 | 3466 | GTKUpdateCursor(); |
1e6feb95 | 3467 | |
2f262021 | 3468 | return true; |
ef5c70f9 VZ |
3469 | } |
3470 | ||
c2246a38 | 3471 | void wxWindowGTK::GTKUpdateCursor(bool update_self /*=true*/, bool recurse /*=true*/) |
ef5c70f9 | 3472 | { |
c2246a38 | 3473 | if (update_self) |
ef5c70f9 | 3474 | { |
a1b806b9 DS |
3475 | wxCursor cursor(g_globalCursor.IsOk() ? g_globalCursor : GetCursor()); |
3476 | if ( cursor.IsOk() ) | |
ef5c70f9 | 3477 | { |
9c76b9af RR |
3478 | wxArrayGdkWindows windowsThis; |
3479 | GdkWindow* window = GTKGetWindow(windowsThis); | |
3480 | if (window) | |
3481 | gdk_window_set_cursor( window, cursor.GetCursor() ); | |
3482 | else | |
ef5c70f9 | 3483 | { |
9c76b9af RR |
3484 | const size_t count = windowsThis.size(); |
3485 | for ( size_t n = 0; n < count; n++ ) | |
5dd7eef7 | 3486 | { |
9c76b9af RR |
3487 | GdkWindow *win = windowsThis[n]; |
3488 | // It can be zero if the window has not been realized yet. | |
3489 | if ( win ) | |
c2246a38 | 3490 | { |
c2246a38 RR |
3491 | gdk_window_set_cursor(win, cursor.GetCursor()); |
3492 | } | |
5dd7eef7 | 3493 | } |
c2246a38 RR |
3494 | } |
3495 | } | |
3496 | } | |
3497 | ||
3498 | if (recurse) | |
3499 | { | |
3500 | for (wxWindowList::iterator it = GetChildren().begin(); it != GetChildren().end(); ++it) | |
3501 | { | |
3502 | (*it)->GTKUpdateCursor( true ); | |
ef5c70f9 VZ |
3503 | } |
3504 | } | |
362c6693 | 3505 | } |
c801d85f | 3506 | |
1e6feb95 | 3507 | void wxWindowGTK::WarpPointer( int x, int y ) |
4f22cf8d | 3508 | { |
82b978d7 RD |
3509 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); |
3510 | ||
1ddb3b55 PC |
3511 | ClientToScreen(&x, &y); |
3512 | GdkDisplay* display = gtk_widget_get_display(m_widget); | |
3513 | GdkScreen* screen = gtk_widget_get_screen(m_widget); | |
3514 | #ifdef __WXGTK30__ | |
3515 | GdkDeviceManager* manager = gdk_display_get_device_manager(display); | |
3516 | gdk_device_warp(gdk_device_manager_get_client_pointer(manager), screen, x, y); | |
3517 | #else | |
3518 | XWarpPointer(GDK_DISPLAY_XDISPLAY(display), | |
3519 | None, | |
3520 | GDK_WINDOW_XID(gdk_screen_get_root_window(screen)), | |
3521 | 0, 0, 0, 0, x, y); | |
3522 | #endif | |
4f22cf8d RR |
3523 | } |
3524 | ||
22c9b211 | 3525 | wxWindowGTK::ScrollDir wxWindowGTK::ScrollDirFromRange(GtkRange *range) const |
0c131a5a | 3526 | { |
22c9b211 VZ |
3527 | // find the scrollbar which generated the event |
3528 | for ( int dir = 0; dir < ScrollDir_Max; dir++ ) | |
0c131a5a | 3529 | { |
22c9b211 VZ |
3530 | if ( range == m_scrollBar[dir] ) |
3531 | return (ScrollDir)dir; | |
0c131a5a | 3532 | } |
22c9b211 | 3533 | |
9a83f860 | 3534 | wxFAIL_MSG( wxT("event from unknown scrollbar received") ); |
22c9b211 VZ |
3535 | |
3536 | return ScrollDir_Max; | |
0c131a5a VZ |
3537 | } |
3538 | ||
22c9b211 | 3539 | bool wxWindowGTK::DoScrollByUnits(ScrollDir dir, ScrollUnit unit, int units) |
0c131a5a | 3540 | { |
add7cadd | 3541 | bool changed = false; |
22c9b211 VZ |
3542 | GtkRange* range = m_scrollBar[dir]; |
3543 | if ( range && units ) | |
add7cadd | 3544 | { |
08f09504 | 3545 | GtkAdjustment* adj = gtk_range_get_adjustment(range); |
989d151c PC |
3546 | double inc = unit == ScrollUnit_Line ? gtk_adjustment_get_step_increment(adj) |
3547 | : gtk_adjustment_get_page_increment(adj); | |
22c9b211 | 3548 | |
989d151c | 3549 | const int posOld = wxRound(gtk_adjustment_get_value(adj)); |
22c9b211 VZ |
3550 | gtk_range_set_value(range, posOld + units*inc); |
3551 | ||
989d151c | 3552 | changed = wxRound(gtk_adjustment_get_value(adj)) != posOld; |
add7cadd | 3553 | } |
22c9b211 | 3554 | |
add7cadd | 3555 | return changed; |
0c131a5a | 3556 | } |
3013a903 | 3557 | |
22c9b211 VZ |
3558 | bool wxWindowGTK::ScrollLines(int lines) |
3559 | { | |
3560 | return DoScrollByUnits(ScrollDir_Vert, ScrollUnit_Line, lines); | |
3561 | } | |
3562 | ||
3563 | bool wxWindowGTK::ScrollPages(int pages) | |
3564 | { | |
3565 | return DoScrollByUnits(ScrollDir_Vert, ScrollUnit_Page, pages); | |
3566 | } | |
3567 | ||
e4161a2a VZ |
3568 | void wxWindowGTK::Refresh(bool WXUNUSED(eraseBackground), |
3569 | const wxRect *rect) | |
c801d85f | 3570 | { |
c968ba80 | 3571 | if (m_wxwindow) |
4e5a4c69 | 3572 | { |
ffaaf107 | 3573 | if (gtk_widget_get_mapped(m_wxwindow)) |
d0285203 | 3574 | { |
ffaaf107 PC |
3575 | GdkWindow* window = gtk_widget_get_window(m_wxwindow); |
3576 | if (rect) | |
3577 | { | |
3578 | GdkRectangle r = { rect->x, rect->y, rect->width, rect->height }; | |
3579 | if (GetLayoutDirection() == wxLayout_RightToLeft) | |
3580 | r.x = gdk_window_get_width(window) - r.x - rect->width; | |
3581 | gdk_window_invalidate_rect(window, &r, true); | |
3582 | } | |
3583 | else | |
3584 | gdk_window_invalidate_rect(window, NULL, true); | |
d0285203 | 3585 | } |
4e5a4c69 | 3586 | } |
ffaaf107 | 3587 | else if (m_widget) |
c968ba80 | 3588 | { |
ffaaf107 PC |
3589 | if (gtk_widget_get_mapped(m_widget)) |
3590 | { | |
3591 | if (rect) | |
3592 | gtk_widget_queue_draw_area(m_widget, rect->x, rect->y, rect->width, rect->height); | |
3593 | else | |
3594 | gtk_widget_queue_draw(m_widget); | |
3595 | } | |
c968ba80 | 3596 | } |
362c6693 | 3597 | } |
c801d85f | 3598 | |
beab25bd | 3599 | void wxWindowGTK::Update() |
010afced | 3600 | { |
fc9ab22a | 3601 | if (m_widget && gtk_widget_get_mapped(m_widget)) |
ab0c1a3c PC |
3602 | { |
3603 | GdkDisplay* display = gtk_widget_get_display(m_widget); | |
3604 | // Flush everything out to the server, and wait for it to finish. | |
3605 | // This ensures nothing will overwrite the drawing we are about to do. | |
3606 | gdk_display_sync(display); | |
010afced | 3607 | |
f089940f PC |
3608 | GdkWindow* window = GTKGetDrawingWindow(); |
3609 | if (window == NULL) | |
989d151c | 3610 | window = gtk_widget_get_window(m_widget); |
f089940f | 3611 | gdk_window_process_updates(window, true); |
03647350 | 3612 | |
6cab4fca PC |
3613 | // Flush again, but no need to wait for it to finish |
3614 | gdk_display_flush(display); | |
a67f1484 | 3615 | } |
beab25bd RR |
3616 | } |
3617 | ||
657b4fd4 | 3618 | bool wxWindowGTK::DoIsExposed( int x, int y ) const |
847dfdb4 RR |
3619 | { |
3620 | return m_updateRegion.Contains(x, y) != wxOutRegion; | |
3621 | } | |
3622 | ||
657b4fd4 | 3623 | bool wxWindowGTK::DoIsExposed( int x, int y, int w, int h ) const |
847dfdb4 RR |
3624 | { |
3625 | if (GetLayoutDirection() == wxLayout_RightToLeft) | |
3626 | return m_updateRegion.Contains(x-w, y, w, h) != wxOutRegion; | |
3627 | else | |
3628 | return m_updateRegion.Contains(x, y, w, h) != wxOutRegion; | |
3629 | } | |
3630 | ||
beab25bd RR |
3631 | void wxWindowGTK::GtkSendPaintEvents() |
3632 | { | |
3bcc8d15 RR |
3633 | if (!m_wxwindow) |
3634 | { | |
3bcc8d15 RR |
3635 | m_updateRegion.Clear(); |
3636 | return; | |
3637 | } | |
beab25bd | 3638 | |
f90566f5 | 3639 | // Clip to paint region in wxClientDC |
0a164d4c | 3640 | m_clipPaintRegion = true; |
fab591c5 | 3641 | |
bcb614b3 RR |
3642 | m_nativeUpdateRegion = m_updateRegion; |
3643 | ||
847dfdb4 RR |
3644 | if (GetLayoutDirection() == wxLayout_RightToLeft) |
3645 | { | |
bcb614b3 RR |
3646 | // Transform m_updateRegion under RTL |
3647 | m_updateRegion.Clear(); | |
fcb29b23 | 3648 | |
847dfdb4 | 3649 | gint width; |
989d151c | 3650 | gdk_drawable_get_size(gtk_widget_get_window(m_wxwindow), &width, NULL); |
fcb29b23 | 3651 | |
bcb614b3 | 3652 | wxRegionIterator upd( m_nativeUpdateRegion ); |
847dfdb4 RR |
3653 | while (upd) |
3654 | { | |
3655 | wxRect rect; | |
3656 | rect.x = upd.GetX(); | |
3657 | rect.y = upd.GetY(); | |
3658 | rect.width = upd.GetWidth(); | |
3659 | rect.height = upd.GetHeight(); | |
fcb29b23 | 3660 | |
847dfdb4 | 3661 | rect.x = width - rect.x - rect.width; |
bcb614b3 | 3662 | m_updateRegion.Union( rect ); |
fcb29b23 | 3663 | |
847dfdb4 RR |
3664 | ++upd; |
3665 | } | |
3666 | } | |
fcb29b23 | 3667 | |
9c61c5b0 | 3668 | switch ( GetBackgroundStyle() ) |
f90566f5 | 3669 | { |
9c61c5b0 | 3670 | case wxBG_STYLE_ERASE: |
822cf31c | 3671 | { |
9c61c5b0 VZ |
3672 | wxWindowDC dc( (wxWindow*)this ); |
3673 | dc.SetDeviceClippingRegion( m_updateRegion ); | |
3674 | ||
3675 | // Work around gtk-qt <= 0.60 bug whereby the window colour | |
3676 | // remains grey | |
3677 | if ( UseBgCol() && | |
3678 | wxSystemOptions:: | |
3679 | GetOptionInt("gtk.window.force-background-colour") ) | |
3680 | { | |
3681 | dc.SetBackground(GetBackgroundColour()); | |
3682 | dc.Clear(); | |
3683 | } | |
3684 | ||
3685 | wxEraseEvent erase_event( GetId(), &dc ); | |
3686 | erase_event.SetEventObject( this ); | |
3687 | ||
3688 | if ( HandleWindowEvent(erase_event) ) | |
3689 | { | |
3690 | // background erased, don't do it again | |
3691 | break; | |
3692 | } | |
822cf31c | 3693 | } |
9c61c5b0 | 3694 | // fall through |
b15ed747 | 3695 | |
9c61c5b0 VZ |
3696 | case wxBG_STYLE_SYSTEM: |
3697 | if ( GetThemeEnabled() ) | |
3698 | { | |
3699 | // find ancestor from which to steal background | |
3700 | wxWindow *parent = wxGetTopLevelParent((wxWindow *)this); | |
3701 | if (!parent) | |
3702 | parent = (wxWindow*)this; | |
3703 | ||
fc9ab22a | 3704 | if (gtk_widget_get_mapped(parent->m_widget)) |
9c61c5b0 VZ |
3705 | { |
3706 | wxRegionIterator upd( m_nativeUpdateRegion ); | |
3707 | while (upd) | |
3708 | { | |
3709 | GdkRectangle rect; | |
3710 | rect.x = upd.GetX(); | |
3711 | rect.y = upd.GetY(); | |
3712 | rect.width = upd.GetWidth(); | |
3713 | rect.height = upd.GetHeight(); | |
3714 | ||
08f09504 | 3715 | gtk_paint_flat_box(gtk_widget_get_style(parent->m_widget), |
f089940f | 3716 | GTKGetDrawingWindow(), |
989d151c | 3717 | gtk_widget_get_state(m_wxwindow), |
9c61c5b0 VZ |
3718 | GTK_SHADOW_NONE, |
3719 | &rect, | |
3720 | parent->m_widget, | |
3721 | (char *)"base", | |
3722 | 0, 0, -1, -1 ); | |
3723 | ||
3724 | ++upd; | |
3725 | } | |
3726 | } | |
3727 | } | |
3728 | break; | |
8ab7b4c5 | 3729 | |
9c61c5b0 VZ |
3730 | case wxBG_STYLE_PAINT: |
3731 | // nothing to do: window will be painted over in EVT_PAINT | |
3732 | break; | |
b15ed747 | 3733 | |
9c61c5b0 VZ |
3734 | default: |
3735 | wxFAIL_MSG( "unsupported background style" ); | |
b15ed747 | 3736 | } |
03eaa52a | 3737 | |
beab25bd RR |
3738 | wxNcPaintEvent nc_paint_event( GetId() ); |
3739 | nc_paint_event.SetEventObject( this ); | |
937013e0 | 3740 | HandleWindowEvent( nc_paint_event ); |
03eaa52a | 3741 | |
beab25bd RR |
3742 | wxPaintEvent paint_event( GetId() ); |
3743 | paint_event.SetEventObject( this ); | |
937013e0 | 3744 | HandleWindowEvent( paint_event ); |
beab25bd | 3745 | |
0a164d4c | 3746 | m_clipPaintRegion = false; |
c89f5c02 | 3747 | |
c89f5c02 | 3748 | m_updateRegion.Clear(); |
bcb614b3 | 3749 | m_nativeUpdateRegion.Clear(); |
beab25bd RR |
3750 | } |
3751 | ||
8e1a5bf9 VZ |
3752 | void wxWindowGTK::SetDoubleBuffered( bool on ) |
3753 | { | |
3754 | wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); | |
3755 | ||
3756 | if ( m_wxwindow ) | |
3757 | gtk_widget_set_double_buffered( m_wxwindow, on ); | |
3758 | } | |
3759 | ||
2e992e06 VZ |
3760 | bool wxWindowGTK::IsDoubleBuffered() const |
3761 | { | |
fc9ab22a | 3762 | return gtk_widget_get_double_buffered( m_wxwindow ); |
2e992e06 VZ |
3763 | } |
3764 | ||
596f1d11 | 3765 | void wxWindowGTK::ClearBackground() |
c801d85f | 3766 | { |
82b978d7 | 3767 | wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); |
362c6693 | 3768 | } |
c801d85f | 3769 | |
ff8bfdbb | 3770 | #if wxUSE_TOOLTIPS |
1e6feb95 | 3771 | void wxWindowGTK::DoSetToolTip( wxToolTip *tip ) |
b1170810 | 3772 | { |
558a94bd | 3773 | if (m_tooltip != tip) |
fb4b0165 | 3774 | { |
558a94bd PC |
3775 | wxWindowBase::DoSetToolTip(tip); |
3776 | ||
3777 | if (m_tooltip) | |
3778 | m_tooltip->GTKSetWindow(static_cast<wxWindow*>(this)); | |
3779 | else | |
3780 | GTKApplyToolTip(NULL); | |
fb4b0165 | 3781 | } |
b1170810 RR |
3782 | } |
3783 | ||
558a94bd | 3784 | void wxWindowGTK::GTKApplyToolTip(const char* tip) |
b1170810 | 3785 | { |
558a94bd | 3786 | wxToolTip::GTKApply(GetConnectWidget(), tip); |
301cd871 | 3787 | } |
ff8bfdbb | 3788 | #endif // wxUSE_TOOLTIPS |
b1170810 | 3789 | |
1e6feb95 | 3790 | bool wxWindowGTK::SetBackgroundColour( const wxColour &colour ) |
c801d85f | 3791 | { |
0a164d4c | 3792 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") ); |
8bbe427f | 3793 | |
739730ca | 3794 | if (!wxWindowBase::SetBackgroundColour(colour)) |
44dfb5ce | 3795 | return false; |
c50f1fb9 | 3796 | |
a1b806b9 | 3797 | if (colour.IsOk()) |
994bc575 | 3798 | { |
5edef14e VS |
3799 | // We need the pixel value e.g. for background clearing. |
3800 | m_backgroundColour.CalcPixel(gtk_widget_get_colormap(m_widget)); | |
994bc575 | 3801 | } |
ca298c88 | 3802 | |
5edef14e | 3803 | // apply style change (forceStyle=true so that new style is applied |
c7382f91 | 3804 | // even if the bg colour changed from valid to wxNullColour) |
9c61c5b0 | 3805 | GTKApplyWidgetStyle(true); |
ea323db3 | 3806 | |
5edef14e | 3807 | return true; |
6de97a3b RR |
3808 | } |
3809 | ||
1e6feb95 | 3810 | bool wxWindowGTK::SetForegroundColour( const wxColour &colour ) |
6de97a3b | 3811 | { |
0a164d4c | 3812 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") ); |
8bbe427f | 3813 | |
739730ca RR |
3814 | if (!wxWindowBase::SetForegroundColour(colour)) |
3815 | { | |
5edef14e | 3816 | return false; |
739730ca | 3817 | } |
0a164d4c | 3818 | |
a1b806b9 | 3819 | if (colour.IsOk()) |
ea323db3 | 3820 | { |
5edef14e VS |
3821 | // We need the pixel value e.g. for background clearing. |
3822 | m_foregroundColour.CalcPixel(gtk_widget_get_colormap(m_widget)); | |
ea323db3 | 3823 | } |
f03fc89f | 3824 | |
5edef14e VS |
3825 | // apply style change (forceStyle=true so that new style is applied |
3826 | // even if the bg colour changed from valid to wxNullColour): | |
496e7ec6 | 3827 | GTKApplyWidgetStyle(true); |
5edef14e | 3828 | |
44dfb5ce | 3829 | return true; |
58614078 RR |
3830 | } |
3831 | ||
496e7ec6 | 3832 | PangoContext *wxWindowGTK::GTKGetPangoDefaultContext() |
2b5f62a0 VZ |
3833 | { |
3834 | return gtk_widget_get_pango_context( m_widget ); | |
3835 | } | |
0a164d4c | 3836 | |
496e7ec6 | 3837 | GtkRcStyle *wxWindowGTK::GTKCreateWidgetStyle(bool forceStyle) |
58614078 | 3838 | { |
f40fdaa3 | 3839 | // do we need to apply any changes at all? |
5edef14e | 3840 | if ( !forceStyle && |
a1b806b9 DS |
3841 | !m_font.IsOk() && |
3842 | !m_foregroundColour.IsOk() && !m_backgroundColour.IsOk() ) | |
fb65642c | 3843 | { |
f40fdaa3 | 3844 | return NULL; |
fb65642c RR |
3845 | } |
3846 | ||
f40fdaa3 | 3847 | GtkRcStyle *style = gtk_rc_style_new(); |
1ecc4d80 | 3848 | |
a1b806b9 | 3849 | if ( m_font.IsOk() ) |
db434467 | 3850 | { |
0a164d4c | 3851 | style->font_desc = |
f40fdaa3 | 3852 | pango_font_description_copy( m_font.GetNativeFontInfo()->description ); |
288059b2 | 3853 | } |
1ecc4d80 | 3854 | |
532ae0f6 VZ |
3855 | int flagsNormal = 0, |
3856 | flagsPrelight = 0, | |
3857 | flagsActive = 0, | |
3858 | flagsInsensitive = 0; | |
3859 | ||
a1b806b9 | 3860 | if ( m_foregroundColour.IsOk() ) |
1ecc4d80 | 3861 | { |
c6685317 | 3862 | const GdkColor *fg = m_foregroundColour.GetColor(); |
0a164d4c | 3863 | |
532ae0f6 VZ |
3864 | style->fg[GTK_STATE_NORMAL] = |
3865 | style->text[GTK_STATE_NORMAL] = *fg; | |
3866 | flagsNormal |= GTK_RC_FG | GTK_RC_TEXT; | |
0a164d4c | 3867 | |
532ae0f6 VZ |
3868 | style->fg[GTK_STATE_PRELIGHT] = |
3869 | style->text[GTK_STATE_PRELIGHT] = *fg; | |
3870 | flagsPrelight |= GTK_RC_FG | GTK_RC_TEXT; | |
0a164d4c | 3871 | |
532ae0f6 VZ |
3872 | style->fg[GTK_STATE_ACTIVE] = |
3873 | style->text[GTK_STATE_ACTIVE] = *fg; | |
3874 | flagsActive |= GTK_RC_FG | GTK_RC_TEXT; | |
1ecc4d80 RR |
3875 | } |
3876 | ||
a1b806b9 | 3877 | if ( m_backgroundColour.IsOk() ) |
1ecc4d80 | 3878 | { |
c6685317 | 3879 | const GdkColor *bg = m_backgroundColour.GetColor(); |
5edef14e | 3880 | |
532ae0f6 | 3881 | style->bg[GTK_STATE_NORMAL] = |
5edef14e | 3882 | style->base[GTK_STATE_NORMAL] = *bg; |
532ae0f6 | 3883 | flagsNormal |= GTK_RC_BG | GTK_RC_BASE; |
0a164d4c | 3884 | |
532ae0f6 | 3885 | style->bg[GTK_STATE_PRELIGHT] = |
5edef14e | 3886 | style->base[GTK_STATE_PRELIGHT] = *bg; |
532ae0f6 | 3887 | flagsPrelight |= GTK_RC_BG | GTK_RC_BASE; |
0a164d4c | 3888 | |
532ae0f6 | 3889 | style->bg[GTK_STATE_ACTIVE] = |
5edef14e | 3890 | style->base[GTK_STATE_ACTIVE] = *bg; |
532ae0f6 | 3891 | flagsActive |= GTK_RC_BG | GTK_RC_BASE; |
0a164d4c | 3892 | |
532ae0f6 | 3893 | style->bg[GTK_STATE_INSENSITIVE] = |
5edef14e | 3894 | style->base[GTK_STATE_INSENSITIVE] = *bg; |
532ae0f6 | 3895 | flagsInsensitive |= GTK_RC_BG | GTK_RC_BASE; |
1ecc4d80 | 3896 | } |
0a164d4c | 3897 | |
532ae0f6 VZ |
3898 | style->color_flags[GTK_STATE_NORMAL] = (GtkRcFlags)flagsNormal; |
3899 | style->color_flags[GTK_STATE_PRELIGHT] = (GtkRcFlags)flagsPrelight; | |
3900 | style->color_flags[GTK_STATE_ACTIVE] = (GtkRcFlags)flagsActive; | |
3901 | style->color_flags[GTK_STATE_INSENSITIVE] = (GtkRcFlags)flagsInsensitive; | |
3902 | ||
f40fdaa3 | 3903 | return style; |
a81258be RR |
3904 | } |
3905 | ||
496e7ec6 | 3906 | void wxWindowGTK::GTKApplyWidgetStyle(bool forceStyle) |
a81258be | 3907 | { |
496e7ec6 | 3908 | GtkRcStyle *style = GTKCreateWidgetStyle(forceStyle); |
f8e045e2 RD |
3909 | if ( style ) |
3910 | { | |
7074ce35 | 3911 | DoApplyWidgetStyle(style); |
08f09504 | 3912 | g_object_unref(style); |
f8e045e2 | 3913 | } |
6dd18972 VS |
3914 | |
3915 | // Style change may affect GTK+'s size calculation: | |
3916 | InvalidateBestSize(); | |
6de97a3b RR |
3917 | } |
3918 | ||
7074ce35 VS |
3919 | void wxWindowGTK::DoApplyWidgetStyle(GtkRcStyle *style) |
3920 | { | |
0d013e46 VZ |
3921 | if ( m_wxwindow ) |
3922 | { | |
3923 | // block the signal temporarily to avoid sending | |
3924 | // wxSysColourChangedEvents when we change the colours ourselves | |
3925 | bool unblock = false; | |
3926 | if ( IsTopLevel() ) | |
3927 | { | |
3928 | unblock = true; | |
3929 | g_signal_handlers_block_by_func( | |
3930 | m_wxwindow, (void *)gtk_window_style_set_callback, this); | |
3931 | } | |
013151c7 | 3932 | |
7074ce35 | 3933 | gtk_widget_modify_style(m_wxwindow, style); |
0d013e46 VZ |
3934 | |
3935 | if ( unblock ) | |
3936 | { | |
3937 | g_signal_handlers_unblock_by_func( | |
3938 | m_wxwindow, (void *)gtk_window_style_set_callback, this); | |
3939 | } | |
3940 | } | |
7cb93e45 | 3941 | else |
0d013e46 | 3942 | { |
7cb93e45 | 3943 | gtk_widget_modify_style(m_widget, style); |
0d013e46 | 3944 | } |
7074ce35 VS |
3945 | } |
3946 | ||
c7382f91 JS |
3947 | bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style) |
3948 | { | |
3949 | wxWindowBase::SetBackgroundStyle(style); | |
0a164d4c | 3950 | |
9c61c5b0 | 3951 | if ( style == wxBG_STYLE_PAINT ) |
c7382f91 | 3952 | { |
788f9633 VZ |
3953 | GdkWindow *window; |
3954 | if ( m_wxwindow ) | |
3955 | { | |
f089940f | 3956 | window = GTKGetDrawingWindow(); |
788f9633 | 3957 | } |
c7382f91 | 3958 | else |
788f9633 VZ |
3959 | { |
3960 | GtkWidget * const w = GetConnectWidget(); | |
989d151c | 3961 | window = w ? gtk_widget_get_window(w) : NULL; |
788f9633 | 3962 | } |
c7382f91 JS |
3963 | |
3964 | if (window) | |
3965 | { | |
3966 | // Make sure GDK/X11 doesn't refresh the window | |
3967 | // automatically. | |
3968 | gdk_window_set_back_pixmap( window, None, False ); | |
3969 | #ifdef __X__ | |
3970 | Display* display = GDK_WINDOW_DISPLAY(window); | |
3971 | XFlush(display); | |
3972 | #endif | |
3973 | m_needsStyleChange = false; | |
3974 | } | |
788f9633 VZ |
3975 | else // window not realized yet |
3976 | { | |
c7382f91 JS |
3977 | // Do in OnIdle, because the window is not yet available |
3978 | m_needsStyleChange = true; | |
788f9633 | 3979 | } |
0a164d4c | 3980 | |
c7382f91 JS |
3981 | // Don't apply widget style, or we get a grey background |
3982 | } | |
3983 | else | |
3984 | { | |
3985 | // apply style change (forceStyle=true so that new style is applied | |
3986 | // even if the bg colour changed from valid to wxNullColour): | |
496e7ec6 | 3987 | GTKApplyWidgetStyle(true); |
c7382f91 | 3988 | } |
9c61c5b0 | 3989 | |
c7382f91 JS |
3990 | return true; |
3991 | } | |
7074ce35 | 3992 | |
bcf7614c PC |
3993 | // ---------------------------------------------------------------------------- |
3994 | // Pop-up menu stuff | |
3995 | // ---------------------------------------------------------------------------- | |
3996 | ||
3997 | #if wxUSE_MENUS_NATIVE | |
3998 | ||
edd6813c PC |
3999 | extern "C" { |
4000 | static | |
bcf7614c PC |
4001 | void wxPopupMenuPositionCallback( GtkMenu *menu, |
4002 | gint *x, gint *y, | |
4003 | gboolean * WXUNUSED(whatever), | |
4004 | gpointer user_data ) | |
4005 | { | |
4006 | // ensure that the menu appears entirely on screen | |
4007 | GtkRequisition req; | |
4008 | gtk_widget_get_child_requisition(GTK_WIDGET(menu), &req); | |
4009 | ||
4010 | wxSize sizeScreen = wxGetDisplaySize(); | |
4011 | wxPoint *pos = (wxPoint*)user_data; | |
4012 | ||
4013 | gint xmax = sizeScreen.x - req.width, | |
4014 | ymax = sizeScreen.y - req.height; | |
4015 | ||
4016 | *x = pos->x < xmax ? pos->x : xmax; | |
4017 | *y = pos->y < ymax ? pos->y : ymax; | |
4018 | } | |
edd6813c PC |
4019 | } |
4020 | ||
bcf7614c PC |
4021 | bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y ) |
4022 | { | |
4023 | wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") ); | |
4024 | ||
55fb00a7 VZ |
4025 | // For compatibility with other ports, pretend that the window showing the |
4026 | // menu has focus while the menu is shown. This is needed because the popup | |
4027 | // menu actually steals the focus from the window it's associated it in | |
4028 | // wxGTK unlike, say, wxMSW. | |
4029 | wxWindowGTK* const oldPendingFocus = gs_pendingFocus; | |
4030 | gs_pendingFocus = this; | |
4031 | wxON_BLOCK_EXIT_SET( gs_pendingFocus, oldPendingFocus ); | |
4032 | ||
a1c6f069 | 4033 | menu->UpdateUI(); |
bcf7614c PC |
4034 | |
4035 | wxPoint pos; | |
4036 | gpointer userdata; | |
4037 | GtkMenuPositionFunc posfunc; | |
4038 | if ( x == -1 && y == -1 ) | |
4039 | { | |
4040 | // use GTK's default positioning algorithm | |
4041 | userdata = NULL; | |
4042 | posfunc = NULL; | |
4043 | } | |
4044 | else | |
4045 | { | |
4046 | pos = ClientToScreen(wxPoint(x, y)); | |
4047 | userdata = &pos; | |
4048 | posfunc = wxPopupMenuPositionCallback; | |
4049 | } | |
4050 | ||
4051 | menu->m_popupShown = true; | |
4052 | gtk_menu_popup( | |
4053 | GTK_MENU(menu->m_menu), | |
d3b9f782 VZ |
4054 | NULL, // parent menu shell |
4055 | NULL, // parent menu item | |
bcf7614c PC |
4056 | posfunc, // function to position it |
4057 | userdata, // client data | |
4058 | 0, // button used to activate it | |
4059 | gtk_get_current_event_time() | |
4060 | ); | |
4061 | ||
4062 | while (menu->m_popupShown) | |
4063 | { | |
4064 | gtk_main_iteration(); | |
4065 | } | |
4066 | ||
4067 | return true; | |
4068 | } | |
4069 | ||
4070 | #endif // wxUSE_MENUS_NATIVE | |
4071 | ||
06cfab17 | 4072 | #if wxUSE_DRAG_AND_DROP |
ac57418f | 4073 | |
1e6feb95 | 4074 | void wxWindowGTK::SetDropTarget( wxDropTarget *dropTarget ) |
c801d85f | 4075 | { |
82b978d7 RD |
4076 | wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); |
4077 | ||
1ecc4d80 | 4078 | GtkWidget *dnd_widget = GetConnectWidget(); |
47d67540 | 4079 | |
1fe91d70 | 4080 | if (m_dropTarget) m_dropTarget->GtkUnregisterWidget( dnd_widget ); |
47d67540 | 4081 | |
1ecc4d80 RR |
4082 | if (m_dropTarget) delete m_dropTarget; |
4083 | m_dropTarget = dropTarget; | |
47d67540 | 4084 | |
1fe91d70 | 4085 | if (m_dropTarget) m_dropTarget->GtkRegisterWidget( dnd_widget ); |
362c6693 | 4086 | } |
c801d85f | 4087 | |
f03fc89f | 4088 | #endif // wxUSE_DRAG_AND_DROP |
ac57418f | 4089 | |
1e6feb95 | 4090 | GtkWidget* wxWindowGTK::GetConnectWidget() |
e3e65dac | 4091 | { |
1ecc4d80 RR |
4092 | GtkWidget *connect_widget = m_widget; |
4093 | if (m_wxwindow) connect_widget = m_wxwindow; | |
47d67540 | 4094 | |
1ecc4d80 | 4095 | return connect_widget; |
e3e65dac | 4096 | } |
47d67540 | 4097 | |
ef5c70f9 | 4098 | bool wxWindowGTK::GTKIsOwnWindow(GdkWindow *window) const |
903f689b | 4099 | { |
ef5c70f9 VZ |
4100 | wxArrayGdkWindows windowsThis; |
4101 | GdkWindow * const winThis = GTKGetWindow(windowsThis); | |
148cd9b6 | 4102 | |
ef5c70f9 VZ |
4103 | return winThis ? window == winThis |
4104 | : windowsThis.Index(window) != wxNOT_FOUND; | |
4105 | } | |
4106 | ||
4107 | GdkWindow *wxWindowGTK::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const | |
4108 | { | |
989d151c | 4109 | return m_wxwindow ? GTKGetDrawingWindow() : gtk_widget_get_window(m_widget); |
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): | |
496e7ec6 | 4121 | GTKApplyWidgetStyle(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 | ||
d3b9f782 | 4130 | GdkWindow *window = NULL; |
b231914f | 4131 | if (m_wxwindow) |
f089940f | 4132 | window = GTKGetDrawingWindow(); |
ed673c6a | 4133 | else |
989d151c | 4134 | window = gtk_widget_get_window(GetConnectWidget()); |
148cd9b6 | 4135 | |
9a83f860 | 4136 | wxCHECK_RET( window, wxT("CaptureMouse() failed") ); |
c50f1fb9 | 4137 | |
f516d986 | 4138 | const wxCursor* cursor = &m_cursor; |
a1b806b9 | 4139 | if (!cursor->IsOk()) |
cca602ac JS |
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), |
d3b9f782 | 4148 | 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 | |
d3b9f782 | 4161 | g_captureWindow = NULL; |
c43430bb | 4162 | |
d3b9f782 | 4163 | GdkWindow *window = NULL; |
b231914f | 4164 | if (m_wxwindow) |
f089940f | 4165 | window = GTKGetDrawingWindow(); |
ed673c6a | 4166 | else |
989d151c | 4167 | window = gtk_widget_get_window(GetConnectWidget()); |
148cd9b6 | 4168 | |
b02da6b1 VZ |
4169 | if (!window) |
4170 | return; | |
c50f1fb9 | 4171 | |
b02da6b1 | 4172 | gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME ); |
362c6693 | 4173 | } |
c801d85f | 4174 | |
7738af59 VZ |
4175 | void wxWindowGTK::GTKReleaseMouseAndNotify() |
4176 | { | |
4177 | DoReleaseMouse(); | |
4178 | wxMouseCaptureLostEvent evt(GetId()); | |
4179 | evt.SetEventObject( this ); | |
937013e0 | 4180 | HandleWindowEvent( evt ); |
7738af59 VZ |
4181 | } |
4182 | ||
1e6feb95 VZ |
4183 | /* static */ |
4184 | wxWindow *wxWindowBase::GetCapture() | |
4185 | { | |
4186 | return (wxWindow *)g_captureWindow; | |
4187 | } | |
4188 | ||
4189 | bool wxWindowGTK::IsRetained() const | |
c801d85f | 4190 | { |
0a164d4c | 4191 | return false; |
362c6693 | 4192 | } |
c801d85f | 4193 | |
22c9b211 VZ |
4194 | void wxWindowGTK::SetScrollbar(int orient, |
4195 | int pos, | |
4196 | int thumbVisible, | |
4197 | int range, | |
4198 | bool WXUNUSED(update)) | |
c801d85f | 4199 | { |
63c95f27 PC |
4200 | const int dir = ScrollDirFromOrient(orient); |
4201 | GtkRange* const sb = m_scrollBar[dir]; | |
9a83f860 | 4202 | wxCHECK_RET( sb, wxT("this window is not scrollable") ); |
c801d85f | 4203 | |
8466fc74 | 4204 | if (range <= 0) |
de7bb802 PC |
4205 | { |
4206 | // GtkRange requires upper > lower | |
4207 | range = | |
4208 | thumbVisible = 1; | |
4209 | } | |
47d67540 | 4210 | |
63c95f27 PC |
4211 | g_signal_handlers_block_by_func( |
4212 | sb, (void*)gtk_scrollbar_value_changed, this); | |
4213 | ||
2bca0d20 | 4214 | gtk_range_set_increments(sb, 1, thumbVisible); |
989d151c | 4215 | gtk_adjustment_set_page_size(gtk_range_get_adjustment(sb), thumbVisible); |
63c95f27 | 4216 | gtk_range_set_range(sb, 0, range); |
2bca0d20 PC |
4217 | gtk_range_set_value(sb, pos); |
4218 | m_scrollPos[dir] = gtk_range_get_value(sb); | |
63c95f27 PC |
4219 | |
4220 | g_signal_handlers_unblock_by_func( | |
4221 | sb, (void*)gtk_scrollbar_value_changed, this); | |
87a3ebe9 VZ |
4222 | } |
4223 | ||
22c9b211 | 4224 | void wxWindowGTK::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) |
c801d85f | 4225 | { |
b9e7f011 VZ |
4226 | const int dir = ScrollDirFromOrient(orient); |
4227 | GtkRange * const sb = m_scrollBar[dir]; | |
9a83f860 | 4228 | wxCHECK_RET( sb, wxT("this window is not scrollable") ); |
1ecc4d80 | 4229 | |
add7cadd PC |
4230 | // This check is more than an optimization. Without it, the slider |
4231 | // will not move smoothly while tracking when using wxScrollHelper. | |
4232 | if (GetScrollPos(orient) != pos) | |
47d67540 | 4233 | { |
63c95f27 PC |
4234 | g_signal_handlers_block_by_func( |
4235 | sb, (void*)gtk_scrollbar_value_changed, this); | |
40e5ebbf | 4236 | |
63c95f27 | 4237 | gtk_range_set_value(sb, pos); |
2bca0d20 | 4238 | m_scrollPos[dir] = gtk_range_get_value(sb); |
98264520 | 4239 | |
63c95f27 PC |
4240 | g_signal_handlers_unblock_by_func( |
4241 | sb, (void*)gtk_scrollbar_value_changed, this); | |
cb43b372 | 4242 | } |
362c6693 | 4243 | } |
c801d85f | 4244 | |
22c9b211 | 4245 | int wxWindowGTK::GetScrollThumb(int orient) const |
c801d85f | 4246 | { |
b9e7f011 | 4247 | GtkRange * const sb = m_scrollBar[ScrollDirFromOrient(orient)]; |
9a83f860 | 4248 | wxCHECK_MSG( sb, 0, wxT("this window is not scrollable") ); |
47d67540 | 4249 | |
989d151c | 4250 | return wxRound(gtk_adjustment_get_page_size(gtk_range_get_adjustment(sb))); |
362c6693 | 4251 | } |
c801d85f | 4252 | |
1e6feb95 | 4253 | int wxWindowGTK::GetScrollPos( int orient ) const |
c801d85f | 4254 | { |
b9e7f011 | 4255 | GtkRange * const sb = m_scrollBar[ScrollDirFromOrient(orient)]; |
9a83f860 | 4256 | wxCHECK_MSG( sb, 0, wxT("this window is not scrollable") ); |
c801d85f | 4257 | |
2bca0d20 | 4258 | return wxRound(gtk_range_get_value(sb)); |
362c6693 | 4259 | } |
c801d85f | 4260 | |
1e6feb95 | 4261 | int wxWindowGTK::GetScrollRange( int orient ) const |
c801d85f | 4262 | { |
b9e7f011 | 4263 | GtkRange * const sb = m_scrollBar[ScrollDirFromOrient(orient)]; |
9a83f860 | 4264 | wxCHECK_MSG( sb, 0, wxT("this window is not scrollable") ); |
c801d85f | 4265 | |
989d151c | 4266 | return wxRound(gtk_adjustment_get_upper(gtk_range_get_adjustment(sb))); |
add7cadd PC |
4267 | } |
4268 | ||
4269 | // Determine if increment is the same as +/-x, allowing for some small | |
4270 | // difference due to possible inexactness in floating point arithmetic | |
4271 | static inline bool IsScrollIncrement(double increment, double x) | |
4272 | { | |
4273 | wxASSERT(increment > 0); | |
4274 | const double tolerance = 1.0 / 1024; | |
4275 | return fabs(increment - fabs(x)) < tolerance; | |
4276 | } | |
4277 | ||
71ead4bf | 4278 | wxEventType wxWindowGTK::GTKGetScrollEventType(GtkRange* range) |
add7cadd | 4279 | { |
add7cadd PC |
4280 | wxASSERT(range == m_scrollBar[0] || range == m_scrollBar[1]); |
4281 | ||
4282 | const int barIndex = range == m_scrollBar[1]; | |
fcb29b23 | 4283 | |
2bca0d20 | 4284 | const double value = gtk_range_get_value(range); |
fcb29b23 | 4285 | |
add7cadd PC |
4286 | // save previous position |
4287 | const double oldPos = m_scrollPos[barIndex]; | |
4288 | // update current position | |
2bca0d20 | 4289 | m_scrollPos[barIndex] = value; |
add7cadd | 4290 | // If event should be ignored, or integral position has not changed |
2bca0d20 | 4291 | if (!m_hasVMT || g_blockEventsOnDrag || wxRound(value) == wxRound(oldPos)) |
add7cadd PC |
4292 | { |
4293 | return wxEVT_NULL; | |
4294 | } | |
4295 | ||
4296 | wxEventType eventType = wxEVT_SCROLL_THUMBTRACK; | |
4297 | if (!m_isScrolling) | |
4298 | { | |
4299 | // Difference from last change event | |
2bca0d20 | 4300 | const double diff = value - oldPos; |
add7cadd PC |
4301 | const bool isDown = diff > 0; |
4302 | ||
2bca0d20 | 4303 | GtkAdjustment* adj = gtk_range_get_adjustment(range); |
989d151c | 4304 | if (IsScrollIncrement(gtk_adjustment_get_step_increment(adj), diff)) |
add7cadd PC |
4305 | { |
4306 | eventType = isDown ? wxEVT_SCROLL_LINEDOWN : wxEVT_SCROLL_LINEUP; | |
4307 | } | |
989d151c | 4308 | else if (IsScrollIncrement(gtk_adjustment_get_page_increment(adj), diff)) |
add7cadd PC |
4309 | { |
4310 | eventType = isDown ? wxEVT_SCROLL_PAGEDOWN : wxEVT_SCROLL_PAGEUP; | |
4311 | } | |
4312 | else if (m_mouseButtonDown) | |
4313 | { | |
4314 | // Assume track event | |
4315 | m_isScrolling = true; | |
4316 | } | |
4317 | } | |
4318 | return eventType; | |
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; |
35510e48 | 4329 | |
0a164d4c | 4330 | m_clipPaintRegion = true; |
0fc5dbf5 | 4331 | |
08f53168 | 4332 | WX_PIZZA(m_wxwindow)->scroll(dx, dy); |
0fc5dbf5 | 4333 | |
0a164d4c | 4334 | m_clipPaintRegion = false; |
113faca1 | 4335 | |
231018bd | 4336 | #if wxUSE_CARET |
113faca1 JS |
4337 | bool restoreCaret = (GetCaret() != NULL && GetCaret()->IsVisible()); |
4338 | if (restoreCaret) | |
4339 | { | |
4340 | wxRect caretRect(GetCaret()->GetPosition(), GetCaret()->GetSize()); | |
4341 | if (dx > 0) | |
4342 | caretRect.width += dx; | |
4343 | else | |
fcb29b23 | 4344 | { |
113faca1 | 4345 | caretRect.x += dx; caretRect.width -= dx; |
fcb29b23 | 4346 | } |
113faca1 JS |
4347 | if (dy > 0) |
4348 | caretRect.height += dy; | |
4349 | else | |
fcb29b23 | 4350 | { |
113faca1 | 4351 | caretRect.y += dy; caretRect.height -= dy; |
fcb29b23 VZ |
4352 | } |
4353 | ||
113faca1 JS |
4354 | RefreshRect(caretRect); |
4355 | } | |
fcb29b23 | 4356 | #endif // wxUSE_CARET |
c801d85f | 4357 | } |
3723b7b1 | 4358 | |
496e7ec6 | 4359 | void wxWindowGTK::GTKScrolledWindowSetBorder(GtkWidget* w, int wxstyle) |
6493aaca VZ |
4360 | { |
4361 | //RN: Note that static controls usually have no border on gtk, so maybe | |
88a7a4e1 | 4362 | //it makes sense to treat that as simply no border at the wx level |
6493aaca VZ |
4363 | //as well... |
4364 | if (!(wxstyle & wxNO_BORDER) && !(wxstyle & wxBORDER_STATIC)) | |
4365 | { | |
4366 | GtkShadowType gtkstyle; | |
88a7a4e1 | 4367 | |
6493aaca VZ |
4368 | if(wxstyle & wxBORDER_RAISED) |
4369 | gtkstyle = GTK_SHADOW_OUT; | |
ec2d6790 | 4370 | else if ((wxstyle & wxBORDER_SUNKEN) || (wxstyle & wxBORDER_THEME)) |
6493aaca | 4371 | gtkstyle = GTK_SHADOW_IN; |
78cd9c69 JS |
4372 | #if 0 |
4373 | // Now obsolete | |
6493aaca VZ |
4374 | else if (wxstyle & wxBORDER_DOUBLE) |
4375 | gtkstyle = GTK_SHADOW_ETCHED_IN; | |
78cd9c69 | 4376 | #endif |
6493aaca VZ |
4377 | else //default |
4378 | gtkstyle = GTK_SHADOW_IN; | |
4379 | ||
88a7a4e1 | 4380 | gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(w), |
6493aaca VZ |
4381 | gtkstyle ); |
4382 | } | |
4383 | } | |
4384 | ||
015dca24 MR |
4385 | void wxWindowGTK::SetWindowStyleFlag( long style ) |
4386 | { | |
4387 | // Updates the internal variable. NB: Now m_windowStyle bits carry the _new_ style values already | |
4388 | wxWindowBase::SetWindowStyleFlag(style); | |
4389 | } | |
4e5a4c69 | 4390 | |
3723b7b1 JS |
4391 | // Find the wxWindow at the current mouse position, also returning the mouse |
4392 | // position. | |
4393 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) | |
4394 | { | |
59a12e90 JS |
4395 | pt = wxGetMousePosition(); |
4396 | wxWindow* found = wxFindWindowAtPoint(pt); | |
4397 | return found; | |
3723b7b1 JS |
4398 | } |
4399 | ||
4400 | // Get the current mouse position. | |
4401 | wxPoint wxGetMousePosition() | |
4402 | { | |
59a12e90 JS |
4403 | /* This crashes when used within wxHelpContext, |
4404 | so we have to use the X-specific implementation below. | |
4405 | gint x, y; | |
4406 | GdkModifierType *mask; | |
4407 | (void) gdk_window_get_pointer(NULL, &x, &y, mask); | |
4408 | ||
4409 | return wxPoint(x, y); | |
4410 | */ | |
4411 | ||
3723b7b1 JS |
4412 | int x, y; |
4413 | GdkWindow* windowAtPtr = gdk_window_at_pointer(& x, & y); | |
59a12e90 | 4414 | |
37d81cc2 | 4415 | Display *display = windowAtPtr ? GDK_WINDOW_XDISPLAY(windowAtPtr) : GDK_DISPLAY(); |
59a12e90 JS |
4416 | Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display)); |
4417 | Window rootReturn, childReturn; | |
4418 | int rootX, rootY, winX, winY; | |
4419 | unsigned int maskReturn; | |
4420 | ||
4421 | XQueryPointer (display, | |
5cd09f0b RR |
4422 | rootWindow, |
4423 | &rootReturn, | |
59a12e90 JS |
4424 | &childReturn, |
4425 | &rootX, &rootY, &winX, &winY, &maskReturn); | |
4426 | return wxPoint(rootX, rootY); | |
4427 | ||
3723b7b1 JS |
4428 | } |
4429 | ||
08f53168 PC |
4430 | GdkWindow* wxWindowGTK::GTKGetDrawingWindow() const |
4431 | { | |
4432 | GdkWindow* window = NULL; | |
4433 | if (m_wxwindow) | |
989d151c | 4434 | window = gtk_widget_get_window(m_wxwindow); |
08f53168 PC |
4435 | return window; |
4436 | } | |
5f346ddc VS |
4437 | |
4438 | // ---------------------------------------------------------------------------- | |
4439 | // freeze/thaw | |
4440 | // ---------------------------------------------------------------------------- | |
4441 | ||
89267fe5 VS |
4442 | extern "C" |
4443 | { | |
4444 | ||
4445 | // this is called if we attempted to freeze unrealized widget when it finally | |
4446 | // is realized (and so can be frozen): | |
f089940f | 4447 | static void wx_frozen_widget_realize(GtkWidget* w, wxWindowGTK* win) |
89267fe5 | 4448 | { |
fc9ab22a VS |
4449 | wxASSERT( w && gtk_widget_get_has_window(w) ); |
4450 | wxASSERT( gtk_widget_get_realized(w) ); | |
89267fe5 VS |
4451 | |
4452 | g_signal_handlers_disconnect_by_func | |
4453 | ( | |
4454 | w, | |
4455 | (void*)wx_frozen_widget_realize, | |
f089940f | 4456 | win |
89267fe5 VS |
4457 | ); |
4458 | ||
989d151c | 4459 | GdkWindow* window; |
9914bfbb PC |
4460 | if (w == win->m_wxwindow) |
4461 | window = win->GTKGetDrawingWindow(); | |
989d151c PC |
4462 | else |
4463 | window = gtk_widget_get_window(w); | |
f089940f | 4464 | gdk_window_freeze_updates(window); |
89267fe5 VS |
4465 | } |
4466 | ||
4467 | } // extern "C" | |
4468 | ||
5f346ddc VS |
4469 | void wxWindowGTK::GTKFreezeWidget(GtkWidget *w) |
4470 | { | |
fc9ab22a | 4471 | if ( !w || !gtk_widget_get_has_window(w) ) |
89267fe5 VS |
4472 | return; // window-less widget, cannot be frozen |
4473 | ||
989d151c PC |
4474 | GdkWindow* window = gtk_widget_get_window(w); |
4475 | if (window == NULL) | |
89267fe5 VS |
4476 | { |
4477 | // we can't thaw unrealized widgets because they don't have GdkWindow, | |
4478 | // so set it up to be done immediately after realization: | |
4479 | g_signal_connect_after | |
4480 | ( | |
4481 | w, | |
4482 | "realize", | |
4483 | G_CALLBACK(wx_frozen_widget_realize), | |
f089940f | 4484 | this |
89267fe5 VS |
4485 | ); |
4486 | return; | |
4487 | } | |
4488 | ||
9914bfbb PC |
4489 | if (w == m_wxwindow) |
4490 | window = GTKGetDrawingWindow(); | |
f089940f | 4491 | gdk_window_freeze_updates(window); |
5f346ddc VS |
4492 | } |
4493 | ||
4494 | void wxWindowGTK::GTKThawWidget(GtkWidget *w) | |
4495 | { | |
fc9ab22a | 4496 | if ( !w || !gtk_widget_get_has_window(w) ) |
89267fe5 VS |
4497 | return; // window-less widget, cannot be frozen |
4498 | ||
989d151c PC |
4499 | GdkWindow* window = gtk_widget_get_window(w); |
4500 | if (window == NULL) | |
89267fe5 VS |
4501 | { |
4502 | // the widget wasn't realized yet, no need to thaw | |
4503 | g_signal_handlers_disconnect_by_func | |
4504 | ( | |
4505 | w, | |
4506 | (void*)wx_frozen_widget_realize, | |
f089940f | 4507 | this |
89267fe5 VS |
4508 | ); |
4509 | return; | |
4510 | } | |
4511 | ||
9914bfbb PC |
4512 | if (w == m_wxwindow) |
4513 | window = GTKGetDrawingWindow(); | |
f089940f | 4514 | gdk_window_thaw_updates(window); |
5f346ddc VS |
4515 | } |
4516 | ||
4517 | void wxWindowGTK::DoFreeze() | |
4518 | { | |
4519 | GTKFreezeWidget(m_widget); | |
4520 | if ( m_wxwindow && m_widget != m_wxwindow ) | |
4521 | GTKFreezeWidget(m_wxwindow); | |
4522 | } | |
4523 | ||
4524 | void wxWindowGTK::DoThaw() | |
4525 | { | |
4526 | GTKThawWidget(m_widget); | |
4527 | if ( m_wxwindow && m_widget != m_wxwindow ) | |
4528 | GTKThawWidget(m_wxwindow); | |
4529 | } |