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