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