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