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