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