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