]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: window.cpp | |
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 | ||
15 | #include "wx/defs.h" | |
16 | #include "wx/window.h" | |
17 | #include "wx/dc.h" | |
18 | #include "wx/frame.h" | |
19 | #include "wx/app.h" | |
20 | #include "wx/layout.h" | |
21 | #include "wx/utils.h" | |
22 | #include "wx/dialog.h" | |
23 | #include "wx/msgdlg.h" | |
bfc6fde4 | 24 | |
06cfab17 | 25 | #if wxUSE_DRAG_AND_DROP |
bfc6fde4 | 26 | #include "wx/dnd.h" |
ac57418f | 27 | #endif |
bfc6fde4 | 28 | |
cad880f5 | 29 | #if wxUSE_TOOLTIPS |
bfc6fde4 | 30 | #include "wx/tooltip.h" |
cad880f5 | 31 | #endif |
bfc6fde4 | 32 | |
30dea054 | 33 | #include "wx/menu.h" |
d4c99d6f | 34 | #include "wx/statusbr.h" |
b4071e91 | 35 | #include "wx/intl.h" |
3bc755fc | 36 | #include "wx/settings.h" |
3069ac4e | 37 | #include "wx/log.h" |
b4071e91 RR |
38 | |
39 | #include <math.h> | |
c801d85f | 40 | |
83624f79 RR |
41 | #include "gdk/gdk.h" |
42 | #include "gtk/gtk.h" | |
43 | #include "gdk/gdkprivate.h" | |
44 | #include "gdk/gdkkeysyms.h" | |
45 | #include "wx/gtk/win_gtk.h" | |
46 | ||
6bc8a1c8 | 47 | #include "gdk/gdkx.h" |
6bc8a1c8 | 48 | |
868a2826 RR |
49 | //----------------------------------------------------------------------------- |
50 | // documentation on internals | |
51 | //----------------------------------------------------------------------------- | |
52 | ||
53 | /* | |
54 | I have been asked several times about writing some documentation about | |
55 | the GTK port of wxWindows, especially its internal structures. Obviously, | |
56 | you cannot understand wxGTK without knowing a little about the GTK, but | |
47d67540 | 57 | some more information about what the wxWindow, which is the base class |
868a2826 | 58 | for all other window classes, does seems required as well. |
47d67540 | 59 | |
868a2826 | 60 | What does wxWindow do? It contains the common interface for the following |
e380f72b | 61 | jobs of its descendants: |
47d67540 | 62 | |
868a2826 | 63 | 1) Define the rudimentary behaviour common to all window classes, such as |
e380f72b RR |
64 | resizing, intercepting user input (so as to make it possible to use these |
65 | events for special purposes in a derived class), window names etc. | |
868a2826 RR |
66 | |
67 | 2) Provide the possibility to contain and manage children, if the derived | |
68 | class is allowed to contain children, which holds true for those window | |
e380f72b | 69 | classes which do not display a native GTK widget. To name them, these |
868a2826 | 70 | classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame- |
47d67540 | 71 | work classes are a special case and are handled a bit differently from |
e380f72b | 72 | the rest. The same holds true for the wxNotebook class. |
47d67540 | 73 | |
868a2826 RR |
74 | 3) Provide the possibility to draw into a client area of a window. This, |
75 | too, only holds true for classes that do not display a native GTK widget | |
76 | as above. | |
47d67540 | 77 | |
e380f72b RR |
78 | 4) Provide the entire mechanism for scrolling widgets. This actual inter- |
79 | face for this is usually in wxScrolledWindow, but the GTK implementation | |
868a2826 | 80 | is in this class. |
47d67540 | 81 | |
868a2826 RR |
82 | 5) A multitude of helper or extra methods for special purposes, such as |
83 | Drag'n'Drop, managing validators etc. | |
47d67540 | 84 | |
e380f72b RR |
85 | Normally one might expect, that one wxWindows window would always correspond |
86 | to one GTK widget. Under GTK, there is no such allround widget that has all | |
868a2826 RR |
87 | the functionality. Moreover, the GTK defines a client area as a different |
88 | widget from the actual widget you are handling. Last but not least some | |
89 | special classes (e.g. wxFrame) handle different categories of widgets and | |
90 | still have the possibility to draw something in the client area. | |
91 | It was therefore required to write a special purpose GTK widget, that would | |
92 | represent a client area in the sense of wxWindows capable to do the jobs | |
93 | 2), 3) and 4). I have written this class and it resides in win_gtk.c of | |
94 | this directory. | |
47d67540 | 95 | |
868a2826 | 96 | All windows must have a widget, with which they interact with other under- |
e380f72b | 97 | lying GTK widgets. It is this widget, e.g. that has to be resized etc and |
868a2826 | 98 | thw wxWindow class has a member variable called m_widget which holds a |
e380f72b RR |
99 | pointer to this widget. When the window class represents a GTK native widget, |
100 | this is (in most cases) the only GTK widget the class manages. E.g. the | |
101 | wxStatitText class handles only a GtkLabel widget a pointer to which you | |
102 | can find in m_widget (defined in wxWindow) | |
8bbe427f | 103 | |
e380f72b | 104 | When the class has a client area for drawing into and for containing children |
8bbe427f VZ |
105 | it has to handle the client area widget (of the type GtkMyFixed, defined in |
106 | win_gtk.c), but there could be any number of widgets, handled by a class | |
107 | The common rule for all windows is only, that the widget that interacts with | |
108 | the rest of GTK must be referenced in m_widget and all other widgets must be | |
109 | children of this widget on the GTK level. The top-most widget, which also | |
110 | represents the client area, must be in the m_wxwindow field and must be of | |
e380f72b | 111 | the type GtkMyFixed. |
47d67540 | 112 | |
868a2826 RR |
113 | As I said, the window classes that display a GTK native widget only have |
114 | one widget, so in the case of e.g. the wxButton class m_widget holds a | |
115 | pointer to a GtkButton widget. But windows with client areas (for drawing | |
116 | and children) have a m_widget field that is a pointer to a GtkScrolled- | |
117 | Window and a m_wxwindow field that is pointer to a GtkMyFixed and this | |
118 | one is (in the GTK sense) a child of the GtkScrolledWindow. | |
47d67540 | 119 | |
868a2826 RR |
120 | If the m_wxwindow field is set, then all input to this widget is inter- |
121 | cepted and sent to the wxWindows class. If not, all input to the widget | |
122 | that gets pointed to by m_widget gets intercepted and sent to the class. | |
123 | ||
124 | */ | |
125 | ||
f03fc89f VZ |
126 | //----------------------------------------------------------------------------- |
127 | // data | |
128 | //----------------------------------------------------------------------------- | |
129 | ||
130 | extern wxList wxPendingDelete; | |
131 | extern bool g_blockEventsOnDrag; | |
132 | extern bool g_blockEventsOnScroll; | |
238d735d | 133 | extern wxCursor g_globalCursor; |
72195a0f | 134 | static wxWindow *g_captureWindow = (wxWindow*) NULL; |
f03fc89f VZ |
135 | static wxWindow *g_focusWindow = (wxWindow*) NULL; |
136 | ||
137 | /* hack: we need something to pass to gtk_menu_popup, so we store the time of | |
138 | the last click here */ | |
139 | static guint32 gs_timeLastClick = 0; | |
140 | ||
2e563988 RR |
141 | //----------------------------------------------------------------------------- |
142 | // debug | |
143 | //----------------------------------------------------------------------------- | |
144 | ||
145 | #ifdef __WXDEBUG__ | |
146 | ||
147 | static gint gtk_debug_focus_in_callback( GtkWidget *WXUNUSED(widget), | |
148 | GdkEvent *WXUNUSED(event), | |
149 | const wxChar *name ) | |
150 | { | |
053dcf1a | 151 | /* |
167e3718 VZ |
152 | static bool s_done = FALSE; |
153 | if ( !s_done ) | |
154 | { | |
155 | wxLog::AddTraceMask("focus"); | |
156 | s_done = TRUE; | |
157 | } | |
167e3718 | 158 | wxLogTrace(_T("FOCUS NOW AT: %s"), name); |
053dcf1a | 159 | */ |
2e563988 RR |
160 | |
161 | return FALSE; | |
162 | } | |
163 | ||
164 | void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window ) | |
165 | { | |
166 | wxString tmp = name; | |
167 | tmp += _T(" FROM "); | |
168 | tmp += window; | |
169 | ||
170 | wxChar *s = new wxChar[tmp.Length()+1]; | |
171 | ||
172 | wxStrcpy( s, tmp ); | |
173 | ||
174 | gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event", | |
175 | GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback), (gpointer)s ); | |
176 | } | |
177 | ||
f03fc89f | 178 | #endif // Debug |
ff8bfdbb | 179 | |
85eb36c2 RR |
180 | //----------------------------------------------------------------------------- |
181 | // missing gdk functions | |
182 | //----------------------------------------------------------------------------- | |
183 | ||
184 | void | |
185 | gdk_window_warp_pointer (GdkWindow *window, | |
c50f1fb9 VZ |
186 | gint x, |
187 | gint y) | |
85eb36c2 RR |
188 | { |
189 | GdkWindowPrivate *priv; | |
c50f1fb9 | 190 | |
85eb36c2 RR |
191 | if (!window) |
192 | window = (GdkWindow*) &gdk_root_parent; | |
c50f1fb9 | 193 | |
85eb36c2 | 194 | priv = (GdkWindowPrivate*) window; |
c50f1fb9 | 195 | |
85eb36c2 RR |
196 | if (!priv->destroyed) |
197 | { | |
c50f1fb9 | 198 | XWarpPointer (priv->xdisplay, |
85eb36c2 | 199 | None, /* not source window -> move from anywhere */ |
c50f1fb9 | 200 | priv->xwindow, /* dest window */ |
85eb36c2 | 201 | 0, 0, 0, 0, /* not source window -> move from anywhere */ |
c50f1fb9 | 202 | x, y ); |
85eb36c2 RR |
203 | } |
204 | } | |
205 | ||
acfd422a | 206 | //----------------------------------------------------------------------------- |
a2053b27 | 207 | // idle system |
acfd422a RR |
208 | //----------------------------------------------------------------------------- |
209 | ||
a2053b27 RR |
210 | extern void wxapp_install_idle_handler(); |
211 | extern bool g_isIdle; | |
212 | ||
c5b42c87 RR |
213 | //----------------------------------------------------------------------------- |
214 | // key event conversion routines | |
215 | //----------------------------------------------------------------------------- | |
216 | ||
6bc8a1c8 | 217 | #if (GTK_MINOR_VERSION == 0) |
c693edf3 RR |
218 | /* these functions are copied verbatim from GTK 1.2 */ |
219 | static void | |
220 | gdkx_XConvertCase (KeySym symbol, | |
c50f1fb9 VZ |
221 | KeySym *lower, |
222 | KeySym *upper) | |
c693edf3 RR |
223 | { |
224 | register KeySym sym = symbol; | |
c50f1fb9 | 225 | |
c693edf3 RR |
226 | g_return_if_fail (lower != NULL); |
227 | g_return_if_fail (upper != NULL); | |
c50f1fb9 | 228 | |
c693edf3 RR |
229 | *lower = sym; |
230 | *upper = sym; | |
c50f1fb9 | 231 | |
c693edf3 RR |
232 | switch (sym >> 8) |
233 | { | |
c50f1fb9 | 234 | #if defined (GDK_A) && defined (GDK_Ooblique) |
c693edf3 RR |
235 | case 0: /* Latin 1 */ |
236 | if ((sym >= GDK_A) && (sym <= GDK_Z)) | |
c50f1fb9 | 237 | *lower += (GDK_a - GDK_A); |
c693edf3 | 238 | else if ((sym >= GDK_a) && (sym <= GDK_z)) |
c50f1fb9 | 239 | *upper -= (GDK_a - GDK_A); |
c693edf3 | 240 | else if ((sym >= GDK_Agrave) && (sym <= GDK_Odiaeresis)) |
c50f1fb9 | 241 | *lower += (GDK_agrave - GDK_Agrave); |
c693edf3 | 242 | else if ((sym >= GDK_agrave) && (sym <= GDK_odiaeresis)) |
c50f1fb9 | 243 | *upper -= (GDK_agrave - GDK_Agrave); |
c693edf3 | 244 | else if ((sym >= GDK_Ooblique) && (sym <= GDK_Thorn)) |
c50f1fb9 | 245 | *lower += (GDK_oslash - GDK_Ooblique); |
c693edf3 | 246 | else if ((sym >= GDK_oslash) && (sym <= GDK_thorn)) |
c50f1fb9 | 247 | *upper -= (GDK_oslash - GDK_Ooblique); |
c693edf3 | 248 | break; |
c50f1fb9 VZ |
249 | #endif /* LATIN1 */ |
250 | ||
251 | #if defined (GDK_Aogonek) && defined (GDK_tcedilla) | |
c693edf3 RR |
252 | case 1: /* Latin 2 */ |
253 | /* Assume the KeySym is a legal value (ignore discontinuities) */ | |
254 | if (sym == GDK_Aogonek) | |
c50f1fb9 | 255 | *lower = GDK_aogonek; |
c693edf3 | 256 | else if (sym >= GDK_Lstroke && sym <= GDK_Sacute) |
c50f1fb9 | 257 | *lower += (GDK_lstroke - GDK_Lstroke); |
c693edf3 | 258 | else if (sym >= GDK_Scaron && sym <= GDK_Zacute) |
c50f1fb9 | 259 | *lower += (GDK_scaron - GDK_Scaron); |
c693edf3 | 260 | else if (sym >= GDK_Zcaron && sym <= GDK_Zabovedot) |
c50f1fb9 | 261 | *lower += (GDK_zcaron - GDK_Zcaron); |
c693edf3 | 262 | else if (sym == GDK_aogonek) |
c50f1fb9 | 263 | *upper = GDK_Aogonek; |
c693edf3 | 264 | else if (sym >= GDK_lstroke && sym <= GDK_sacute) |
c50f1fb9 | 265 | *upper -= (GDK_lstroke - GDK_Lstroke); |
c693edf3 | 266 | else if (sym >= GDK_scaron && sym <= GDK_zacute) |
c50f1fb9 | 267 | *upper -= (GDK_scaron - GDK_Scaron); |
c693edf3 | 268 | else if (sym >= GDK_zcaron && sym <= GDK_zabovedot) |
c50f1fb9 | 269 | *upper -= (GDK_zcaron - GDK_Zcaron); |
c693edf3 | 270 | else if (sym >= GDK_Racute && sym <= GDK_Tcedilla) |
c50f1fb9 | 271 | *lower += (GDK_racute - GDK_Racute); |
c693edf3 | 272 | else if (sym >= GDK_racute && sym <= GDK_tcedilla) |
c50f1fb9 | 273 | *upper -= (GDK_racute - GDK_Racute); |
c693edf3 | 274 | break; |
c50f1fb9 VZ |
275 | #endif /* LATIN2 */ |
276 | ||
277 | #if defined (GDK_Hstroke) && defined (GDK_Cabovedot) | |
c693edf3 RR |
278 | case 2: /* Latin 3 */ |
279 | /* Assume the KeySym is a legal value (ignore discontinuities) */ | |
280 | if (sym >= GDK_Hstroke && sym <= GDK_Hcircumflex) | |
c50f1fb9 | 281 | *lower += (GDK_hstroke - GDK_Hstroke); |
c693edf3 | 282 | else if (sym >= GDK_Gbreve && sym <= GDK_Jcircumflex) |
c50f1fb9 | 283 | *lower += (GDK_gbreve - GDK_Gbreve); |
c693edf3 | 284 | else if (sym >= GDK_hstroke && sym <= GDK_hcircumflex) |
c50f1fb9 | 285 | *upper -= (GDK_hstroke - GDK_Hstroke); |
c693edf3 | 286 | else if (sym >= GDK_gbreve && sym <= GDK_jcircumflex) |
c50f1fb9 | 287 | *upper -= (GDK_gbreve - GDK_Gbreve); |
c693edf3 | 288 | else if (sym >= GDK_Cabovedot && sym <= GDK_Scircumflex) |
c50f1fb9 | 289 | *lower += (GDK_cabovedot - GDK_Cabovedot); |
c693edf3 | 290 | else if (sym >= GDK_cabovedot && sym <= GDK_scircumflex) |
c50f1fb9 | 291 | *upper -= (GDK_cabovedot - GDK_Cabovedot); |
c693edf3 | 292 | break; |
c50f1fb9 VZ |
293 | #endif /* LATIN3 */ |
294 | ||
295 | #if defined (GDK_Rcedilla) && defined (GDK_Amacron) | |
c693edf3 RR |
296 | case 3: /* Latin 4 */ |
297 | /* Assume the KeySym is a legal value (ignore discontinuities) */ | |
298 | if (sym >= GDK_Rcedilla && sym <= GDK_Tslash) | |
c50f1fb9 | 299 | *lower += (GDK_rcedilla - GDK_Rcedilla); |
c693edf3 | 300 | else if (sym >= GDK_rcedilla && sym <= GDK_tslash) |
c50f1fb9 | 301 | *upper -= (GDK_rcedilla - GDK_Rcedilla); |
c693edf3 | 302 | else if (sym == GDK_ENG) |
c50f1fb9 | 303 | *lower = GDK_eng; |
c693edf3 | 304 | else if (sym == GDK_eng) |
c50f1fb9 | 305 | *upper = GDK_ENG; |
c693edf3 | 306 | else if (sym >= GDK_Amacron && sym <= GDK_Umacron) |
c50f1fb9 | 307 | *lower += (GDK_amacron - GDK_Amacron); |
c693edf3 | 308 | else if (sym >= GDK_amacron && sym <= GDK_umacron) |
c50f1fb9 | 309 | *upper -= (GDK_amacron - GDK_Amacron); |
c693edf3 | 310 | break; |
c50f1fb9 VZ |
311 | #endif /* LATIN4 */ |
312 | ||
313 | #if defined (GDK_Serbian_DJE) && defined (GDK_Cyrillic_yu) | |
c693edf3 RR |
314 | case 6: /* Cyrillic */ |
315 | /* Assume the KeySym is a legal value (ignore discontinuities) */ | |
316 | if (sym >= GDK_Serbian_DJE && sym <= GDK_Serbian_DZE) | |
c50f1fb9 | 317 | *lower -= (GDK_Serbian_DJE - GDK_Serbian_dje); |
c693edf3 | 318 | else if (sym >= GDK_Serbian_dje && sym <= GDK_Serbian_dze) |
c50f1fb9 | 319 | *upper += (GDK_Serbian_DJE - GDK_Serbian_dje); |
c693edf3 | 320 | else if (sym >= GDK_Cyrillic_YU && sym <= GDK_Cyrillic_HARDSIGN) |
c50f1fb9 | 321 | *lower -= (GDK_Cyrillic_YU - GDK_Cyrillic_yu); |
c693edf3 | 322 | else if (sym >= GDK_Cyrillic_yu && sym <= GDK_Cyrillic_hardsign) |
c50f1fb9 | 323 | *upper += (GDK_Cyrillic_YU - GDK_Cyrillic_yu); |
c693edf3 | 324 | break; |
c50f1fb9 VZ |
325 | #endif /* CYRILLIC */ |
326 | ||
327 | #if defined (GDK_Greek_ALPHAaccent) && defined (GDK_Greek_finalsmallsigma) | |
c693edf3 RR |
328 | case 7: /* Greek */ |
329 | /* Assume the KeySym is a legal value (ignore discontinuities) */ | |
330 | if (sym >= GDK_Greek_ALPHAaccent && sym <= GDK_Greek_OMEGAaccent) | |
c50f1fb9 | 331 | *lower += (GDK_Greek_alphaaccent - GDK_Greek_ALPHAaccent); |
c693edf3 | 332 | else if (sym >= GDK_Greek_alphaaccent && sym <= GDK_Greek_omegaaccent && |
c50f1fb9 VZ |
333 | sym != GDK_Greek_iotaaccentdieresis && |
334 | sym != GDK_Greek_upsilonaccentdieresis) | |
335 | *upper -= (GDK_Greek_alphaaccent - GDK_Greek_ALPHAaccent); | |
c693edf3 | 336 | else if (sym >= GDK_Greek_ALPHA && sym <= GDK_Greek_OMEGA) |
c50f1fb9 | 337 | *lower += (GDK_Greek_alpha - GDK_Greek_ALPHA); |
c693edf3 | 338 | else if (sym >= GDK_Greek_alpha && sym <= GDK_Greek_omega && |
c50f1fb9 VZ |
339 | sym != GDK_Greek_finalsmallsigma) |
340 | *upper -= (GDK_Greek_alpha - GDK_Greek_ALPHA); | |
c693edf3 | 341 | break; |
c50f1fb9 | 342 | #endif /* GREEK */ |
c693edf3 RR |
343 | } |
344 | } | |
345 | ||
6bc8a1c8 | 346 | static guint |
c50f1fb9 | 347 | gdk_keyval_to_upper (guint keyval) |
6bc8a1c8 RR |
348 | { |
349 | if (keyval) | |
350 | { | |
351 | KeySym lower_val = 0; | |
352 | KeySym upper_val = 0; | |
c50f1fb9 | 353 | |
c693edf3 | 354 | gdkx_XConvertCase (keyval, &lower_val, &upper_val); |
6bc8a1c8 RR |
355 | return upper_val; |
356 | } | |
357 | return 0; | |
358 | } | |
359 | #endif | |
360 | ||
c5b42c87 RR |
361 | static long map_to_unmodified_wx_keysym( KeySym keysym ) |
362 | { | |
363 | guint key_code = 0; | |
364 | ||
365 | switch (keysym) | |
366 | { | |
367 | case GDK_Shift_L: | |
368 | case GDK_Shift_R: key_code = WXK_SHIFT; break; | |
369 | case GDK_Control_L: | |
370 | case GDK_Control_R: key_code = WXK_CONTROL; break; | |
c50f1fb9 VZ |
371 | case GDK_Meta_L: |
372 | case GDK_Meta_R: | |
373 | case GDK_Alt_L: | |
374 | case GDK_Alt_R: | |
375 | case GDK_Super_L: | |
376 | case GDK_Super_R: key_code = WXK_ALT; break; | |
c5b42c87 RR |
377 | case GDK_Menu: key_code = WXK_MENU; break; |
378 | case GDK_Help: key_code = WXK_HELP; break; | |
379 | case GDK_BackSpace: key_code = WXK_BACK; break; | |
380 | case GDK_ISO_Left_Tab: | |
381 | case GDK_Tab: key_code = WXK_TAB; break; | |
382 | case GDK_Linefeed: key_code = WXK_RETURN; break; | |
383 | case GDK_Clear: key_code = WXK_CLEAR; break; | |
384 | case GDK_Return: key_code = WXK_RETURN; break; | |
385 | case GDK_Pause: key_code = WXK_PAUSE; break; | |
386 | case GDK_Scroll_Lock: key_code = WXK_SCROLL; break; | |
387 | case GDK_Escape: key_code = WXK_ESCAPE; break; | |
388 | case GDK_Delete: key_code = WXK_DELETE; break; | |
389 | case GDK_Home: key_code = WXK_HOME; break; | |
390 | case GDK_Left: key_code = WXK_LEFT; break; | |
391 | case GDK_Up: key_code = WXK_UP; break; | |
392 | case GDK_Right: key_code = WXK_RIGHT; break; | |
393 | case GDK_Down: key_code = WXK_DOWN; break; | |
394 | case GDK_Prior: key_code = WXK_PRIOR; break; | |
395 | // case GDK_Page_Up: key_code = WXK_PAGEUP; break; | |
396 | case GDK_Next: key_code = WXK_NEXT; break; | |
397 | // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break; | |
398 | case GDK_End: key_code = WXK_END; break; | |
399 | case GDK_Begin: key_code = WXK_HOME; break; | |
400 | case GDK_Select: key_code = WXK_SELECT; break; | |
401 | case GDK_Print: key_code = WXK_PRINT; break; | |
402 | case GDK_Execute: key_code = WXK_EXECUTE; break; | |
403 | case GDK_Insert: key_code = WXK_INSERT; break; | |
404 | case GDK_Num_Lock: key_code = WXK_NUMLOCK; break; | |
405 | ||
406 | case GDK_KP_0: key_code = WXK_NUMPAD0; break; | |
407 | case GDK_KP_1: key_code = WXK_NUMPAD1; break; | |
408 | case GDK_KP_2: key_code = WXK_NUMPAD2; break; | |
409 | case GDK_KP_3: key_code = WXK_NUMPAD3; break; | |
410 | case GDK_KP_4: key_code = WXK_NUMPAD4; break; | |
411 | case GDK_KP_5: key_code = WXK_NUMPAD5; break; | |
412 | case GDK_KP_6: key_code = WXK_NUMPAD6; break; | |
413 | case GDK_KP_7: key_code = WXK_NUMPAD7; break; | |
414 | case GDK_KP_8: key_code = WXK_NUMPAD8; break; | |
415 | case GDK_KP_9: key_code = WXK_NUMPAD9; break; | |
416 | case GDK_KP_Space: key_code = WXK_NUMPAD_SPACE; break; | |
417 | case GDK_KP_Tab: key_code = WXK_NUMPAD_TAB; break; | |
418 | case GDK_KP_Enter: key_code = WXK_NUMPAD_ENTER; break; | |
419 | case GDK_KP_F1: key_code = WXK_NUMPAD_F1; break; | |
420 | case GDK_KP_F2: key_code = WXK_NUMPAD_F2; break; | |
421 | case GDK_KP_F3: key_code = WXK_NUMPAD_F3; break; | |
422 | case GDK_KP_F4: key_code = WXK_NUMPAD_F4; break; | |
423 | case GDK_KP_Home: key_code = WXK_NUMPAD_HOME; break; | |
424 | case GDK_KP_Left: key_code = WXK_NUMPAD_LEFT; break; | |
425 | case GDK_KP_Up: key_code = WXK_NUMPAD_UP; break; | |
426 | case GDK_KP_Right: key_code = WXK_NUMPAD_RIGHT; break; | |
427 | case GDK_KP_Down: key_code = WXK_NUMPAD_DOWN; break; | |
428 | case GDK_KP_Prior: key_code = WXK_NUMPAD_PRIOR; break; | |
429 | // case GDK_KP_Page_Up: key_code = WXK_NUMPAD_PAGEUP; break; | |
21884766 | 430 | case GDK_KP_Next: key_code = WXK_NUMPAD_NEXT; break; |
c5b42c87 RR |
431 | // case GDK_KP_Page_Down: key_code = WXK_NUMPAD_PAGEDOWN; break; |
432 | case GDK_KP_End: key_code = WXK_NUMPAD_END; break; | |
433 | case GDK_KP_Begin: key_code = WXK_NUMPAD_BEGIN; break; | |
434 | case GDK_KP_Insert: key_code = WXK_NUMPAD_INSERT; break; | |
435 | case GDK_KP_Delete: key_code = WXK_NUMPAD_DELETE; break; | |
436 | case GDK_KP_Equal: key_code = WXK_NUMPAD_EQUAL; break; | |
437 | case GDK_KP_Multiply: key_code = WXK_NUMPAD_MULTIPLY; break; | |
438 | case GDK_KP_Add: key_code = WXK_NUMPAD_ADD; break; | |
439 | case GDK_KP_Separator: key_code = WXK_NUMPAD_SEPARATOR; break; | |
440 | case GDK_KP_Subtract: key_code = WXK_NUMPAD_SUBTRACT; break; | |
441 | case GDK_KP_Decimal: key_code = WXK_NUMPAD_DECIMAL; break; | |
442 | case GDK_KP_Divide: key_code = WXK_NUMPAD_DIVIDE; break; | |
c50f1fb9 | 443 | |
c5b42c87 RR |
444 | case GDK_F1: key_code = WXK_F1; break; |
445 | case GDK_F2: key_code = WXK_F2; break; | |
446 | case GDK_F3: key_code = WXK_F3; break; | |
447 | case GDK_F4: key_code = WXK_F4; break; | |
448 | case GDK_F5: key_code = WXK_F5; break; | |
449 | case GDK_F6: key_code = WXK_F6; break; | |
450 | case GDK_F7: key_code = WXK_F7; break; | |
451 | case GDK_F8: key_code = WXK_F8; break; | |
452 | case GDK_F9: key_code = WXK_F9; break; | |
453 | case GDK_F10: key_code = WXK_F10; break; | |
454 | case GDK_F11: key_code = WXK_F11; break; | |
455 | case GDK_F12: key_code = WXK_F12; break; | |
456 | default: | |
457 | { | |
458 | if (keysym <= 0xFF) | |
459 | { | |
460 | guint upper = gdk_keyval_to_upper( keysym ); | |
461 | keysym = (upper != 0 ? upper : keysym ); /* to be MSW compatible */ | |
462 | key_code = keysym; | |
463 | } | |
464 | } | |
465 | } | |
466 | ||
467 | return (key_code); | |
468 | } | |
469 | ||
470 | static long map_to_wx_keysym( KeySym keysym ) | |
471 | { | |
472 | guint key_code = 0; | |
473 | ||
474 | switch (keysym) | |
475 | { | |
c5b42c87 RR |
476 | case GDK_Menu: key_code = WXK_MENU; break; |
477 | case GDK_Help: key_code = WXK_HELP; break; | |
478 | case GDK_BackSpace: key_code = WXK_BACK; break; | |
479 | case GDK_ISO_Left_Tab: | |
480 | case GDK_Tab: key_code = WXK_TAB; break; | |
481 | case GDK_Linefeed: key_code = WXK_RETURN; break; | |
482 | case GDK_Clear: key_code = WXK_CLEAR; break; | |
483 | case GDK_Return: key_code = WXK_RETURN; break; | |
484 | case GDK_Pause: key_code = WXK_PAUSE; break; | |
485 | case GDK_Scroll_Lock: key_code = WXK_SCROLL; break; | |
486 | case GDK_Escape: key_code = WXK_ESCAPE; break; | |
487 | case GDK_Delete: key_code = WXK_DELETE; break; | |
488 | case GDK_Home: key_code = WXK_HOME; break; | |
489 | case GDK_Left: key_code = WXK_LEFT; break; | |
490 | case GDK_Up: key_code = WXK_UP; break; | |
491 | case GDK_Right: key_code = WXK_RIGHT; break; | |
492 | case GDK_Down: key_code = WXK_DOWN; break; | |
493 | case GDK_Prior: key_code = WXK_PRIOR; break; | |
494 | // case GDK_Page_Up: key_code = WXK_PAGEUP; break; | |
495 | case GDK_Next: key_code = WXK_NEXT; break; | |
496 | // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break; | |
497 | case GDK_End: key_code = WXK_END; break; | |
498 | case GDK_Begin: key_code = WXK_HOME; break; | |
499 | case GDK_Select: key_code = WXK_SELECT; break; | |
500 | case GDK_Print: key_code = WXK_PRINT; break; | |
501 | case GDK_Execute: key_code = WXK_EXECUTE; break; | |
502 | case GDK_Insert: key_code = WXK_INSERT; break; | |
503 | case GDK_Num_Lock: key_code = WXK_NUMLOCK; break; | |
504 | ||
505 | case GDK_KP_0: key_code = '0'; break; | |
506 | case GDK_KP_1: key_code = '1'; break; | |
507 | case GDK_KP_2: key_code = '2'; break; | |
508 | case GDK_KP_3: key_code = '3'; break; | |
509 | case GDK_KP_4: key_code = '4'; break; | |
510 | case GDK_KP_5: key_code = '5'; break; | |
511 | case GDK_KP_6: key_code = '6'; break; | |
512 | case GDK_KP_7: key_code = '7'; break; | |
513 | case GDK_KP_8: key_code = '8'; break; | |
514 | case GDK_KP_9: key_code = '9'; break; | |
515 | case GDK_KP_Space: key_code = ' '; break; | |
516 | case GDK_KP_Tab: key_code = WXK_TAB; break; /* or '\t' ??? */ | |
517 | case GDK_KP_Enter: key_code = WXK_RETURN; break; /* or '\r' ??? */ | |
518 | case GDK_KP_F1: key_code = WXK_NUMPAD_F1; break; | |
519 | case GDK_KP_F2: key_code = WXK_NUMPAD_F2; break; | |
520 | case GDK_KP_F3: key_code = WXK_NUMPAD_F3; break; | |
521 | case GDK_KP_F4: key_code = WXK_NUMPAD_F4; break; | |
522 | case GDK_KP_Home: key_code = WXK_HOME; break; | |
523 | case GDK_KP_Left: key_code = WXK_LEFT; break; | |
524 | case GDK_KP_Up: key_code = WXK_UP; break; | |
525 | case GDK_KP_Right: key_code = WXK_RIGHT; break; | |
526 | case GDK_KP_Down: key_code = WXK_DOWN; break; | |
527 | case GDK_KP_Prior: key_code = WXK_PRIOR; break; | |
528 | // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break; | |
21884766 | 529 | case GDK_KP_Next: key_code = WXK_NEXT; break; |
c5b42c87 RR |
530 | // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break; |
531 | case GDK_KP_End: key_code = WXK_END; break; | |
532 | case GDK_KP_Begin: key_code = WXK_HOME; break; | |
533 | case GDK_KP_Insert: key_code = WXK_INSERT; break; | |
534 | case GDK_KP_Delete: key_code = WXK_DELETE; break; | |
535 | case GDK_KP_Equal: key_code = '='; break; | |
536 | case GDK_KP_Multiply: key_code = '*'; break; | |
537 | case GDK_KP_Add: key_code = '+'; break; | |
538 | case GDK_KP_Separator: key_code = ','; break; | |
539 | case GDK_KP_Subtract: key_code = '-'; break; | |
540 | case GDK_KP_Decimal: key_code = '.'; break; | |
541 | case GDK_KP_Divide: key_code = '/'; break; | |
c50f1fb9 | 542 | |
c5b42c87 RR |
543 | case GDK_F1: key_code = WXK_F1; break; |
544 | case GDK_F2: key_code = WXK_F2; break; | |
545 | case GDK_F3: key_code = WXK_F3; break; | |
546 | case GDK_F4: key_code = WXK_F4; break; | |
547 | case GDK_F5: key_code = WXK_F5; break; | |
548 | case GDK_F6: key_code = WXK_F6; break; | |
549 | case GDK_F7: key_code = WXK_F7; break; | |
550 | case GDK_F8: key_code = WXK_F8; break; | |
551 | case GDK_F9: key_code = WXK_F9; break; | |
552 | case GDK_F10: key_code = WXK_F10; break; | |
553 | case GDK_F11: key_code = WXK_F11; break; | |
554 | case GDK_F12: key_code = WXK_F12; break; | |
555 | default: | |
556 | { | |
557 | if (keysym <= 0xFF) | |
558 | { | |
559 | key_code = keysym; | |
560 | } | |
561 | } | |
562 | } | |
563 | ||
564 | return (key_code); | |
565 | } | |
566 | ||
a2053b27 RR |
567 | //----------------------------------------------------------------------------- |
568 | // local code (see below) | |
569 | //----------------------------------------------------------------------------- | |
acfd422a | 570 | |
ef47f9b3 RR |
571 | #if (GTK_MINOR_VERSION > 0) |
572 | ||
034be888 | 573 | static void draw_frame( GtkWidget *widget, wxWindow *win ) |
b292e2f5 | 574 | { |
a2053b27 | 575 | if (!win->m_hasVMT) |
f03fc89f | 576 | return; |
b292e2f5 | 577 | |
034be888 RR |
578 | int dw = 0; |
579 | int dh = 0; | |
ca298c88 | 580 | |
f03fc89f | 581 | if (win->HasScrolling()) |
034be888 RR |
582 | { |
583 | GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(widget); | |
584 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(widget)->klass ); | |
ff8bfdbb | 585 | |
034be888 RR |
586 | /* |
587 | GtkWidget *hscrollbar = scroll_window->hscrollbar; | |
588 | GtkWidget *vscrollbar = scroll_window->vscrollbar; | |
ca298c88 | 589 | |
f03fc89f | 590 | we use this instead: range.slider_width = 11 + 2*2pts edge |
034be888 | 591 | */ |
ff8bfdbb | 592 | |
034be888 RR |
593 | if (scroll_window->vscrollbar_visible) |
594 | { | |
595 | dw += 15; /* dw += vscrollbar->allocation.width; */ | |
596 | dw += scroll_class->scrollbar_spacing; | |
597 | } | |
b292e2f5 | 598 | |
034be888 RR |
599 | if (scroll_window->hscrollbar_visible) |
600 | { | |
601 | dh += 15; /* dh += hscrollbar->allocation.height; */ | |
63cc5d9d | 602 | dh += scroll_class->scrollbar_spacing; |
034be888 RR |
603 | } |
604 | } | |
ca298c88 | 605 | |
034be888 RR |
606 | int dx = 0; |
607 | int dy = 0; | |
608 | if (GTK_WIDGET_NO_WINDOW (widget)) | |
609 | { | |
610 | dx += widget->allocation.x; | |
611 | dy += widget->allocation.y; | |
612 | } | |
ca298c88 | 613 | |
f03fc89f | 614 | if (win->HasFlag(wxRAISED_BORDER)) |
034be888 | 615 | { |
ca298c88 | 616 | gtk_draw_shadow( widget->style, |
034be888 | 617 | widget->window, |
f03fc89f VZ |
618 | GTK_STATE_NORMAL, |
619 | GTK_SHADOW_OUT, | |
620 | dx, dy, | |
a2053b27 | 621 | win->m_width-dw, win->m_height-dh ); |
f03fc89f | 622 | return; |
ca298c88 RD |
623 | } |
624 | ||
f03fc89f | 625 | if (win->HasFlag(wxSUNKEN_BORDER)) |
034be888 | 626 | { |
ca298c88 | 627 | gtk_draw_shadow( widget->style, |
034be888 | 628 | widget->window, |
f03fc89f VZ |
629 | GTK_STATE_NORMAL, |
630 | GTK_SHADOW_IN, | |
631 | dx, dy, | |
a2053b27 | 632 | win->m_width-dw, win->m_height-dh ); |
f03fc89f | 633 | return; |
034be888 | 634 | } |
b292e2f5 RR |
635 | } |
636 | ||
c801d85f | 637 | //----------------------------------------------------------------------------- |
034be888 | 638 | // "expose_event" of m_widget |
c801d85f KB |
639 | //----------------------------------------------------------------------------- |
640 | ||
034be888 RR |
641 | static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxWindow *win ) |
642 | { | |
643 | if (gdk_event->count > 0) return; | |
644 | draw_frame( widget, win ); | |
645 | } | |
47d67540 | 646 | |
034be888 RR |
647 | //----------------------------------------------------------------------------- |
648 | // "draw" of m_wxwindow | |
649 | //----------------------------------------------------------------------------- | |
650 | ||
651 | static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxWindow *win ) | |
652 | { | |
653 | draw_frame( widget, win ); | |
654 | } | |
c801d85f | 655 | |
f03fc89f | 656 | #endif // GTK_MINOR_VERSION > 0 |
ef47f9b3 | 657 | |
c801d85f | 658 | //----------------------------------------------------------------------------- |
034be888 | 659 | // "expose_event" of m_wxwindow |
c801d85f KB |
660 | //----------------------------------------------------------------------------- |
661 | ||
2f2aa628 | 662 | static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxWindow *win ) |
47d67540 | 663 | { |
98d3fdbe RR |
664 | if (!win->m_hasVMT) |
665 | return; | |
666 | ||
6a008b33 | 667 | if (gdk_event->window != win->m_wxwindow->window) |
f03fc89f | 668 | return; |
47d67540 | 669 | |
f03fc89f VZ |
670 | win->GetUpdateRegion().Union( gdk_event->area.x, |
671 | gdk_event->area.y, | |
672 | gdk_event->area.width, | |
673 | gdk_event->area.height ); | |
47d67540 | 674 | |
98d3fdbe | 675 | if (gdk_event->count > 0) |
f03fc89f | 676 | return; |
c801d85f | 677 | |
f5e27805 RR |
678 | wxPaintEvent event( win->GetId() ); |
679 | event.SetEventObject( win ); | |
680 | win->GetEventHandler()->ProcessEvent( event ); | |
47d67540 | 681 | |
98d3fdbe RR |
682 | /* |
683 | wxPrintf( "OnExpose from " ); | |
684 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
685 | wxPrintf( win->GetClassInfo()->GetClassName() ); | |
686 | wxPrintf( " %d %d %d %d\n", (int)gdk_event->area.x, | |
687 | (int)gdk_event->area.y, | |
688 | (int)gdk_event->area.width, | |
689 | (int)gdk_event->area.height ); | |
690 | */ | |
6a008b33 | 691 | |
f03fc89f | 692 | win->GetUpdateRegion().Clear(); |
362c6693 | 693 | } |
c801d85f KB |
694 | |
695 | //----------------------------------------------------------------------------- | |
034be888 | 696 | // "draw" of m_wxwindow |
2f2aa628 | 697 | //----------------------------------------------------------------------------- |
c801d85f | 698 | |
2f2aa628 | 699 | static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxWindow *win ) |
47d67540 | 700 | { |
c50f1fb9 | 701 | if (g_isIdle) |
a2053b27 RR |
702 | wxapp_install_idle_handler(); |
703 | ||
704 | if (!win->m_hasVMT) | |
f03fc89f | 705 | return; |
47d67540 | 706 | |
f03fc89f VZ |
707 | win->GetUpdateRegion().Union( rect->x, rect->y, |
708 | rect->width, rect->height ); | |
47d67540 | 709 | |
f5e27805 RR |
710 | wxPaintEvent event( win->GetId() ); |
711 | event.SetEventObject( win ); | |
6a008b33 | 712 | |
98d3fdbe RR |
713 | /* |
714 | wxPrintf( "OnDraw from " ); | |
715 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
716 | printf( win->GetClassInfo()->GetClassName() ); | |
717 | wxPrintf( " %d %d %d %d\n", (int)rect->x, | |
718 | (int)rect->y, | |
719 | (int)rect->width, | |
720 | (int)rect->height ); | |
721 | */ | |
722 | ||
f5e27805 | 723 | win->GetEventHandler()->ProcessEvent( event ); |
47d67540 | 724 | |
f03fc89f | 725 | win->GetUpdateRegion().Clear(); |
362c6693 | 726 | } |
c801d85f KB |
727 | |
728 | //----------------------------------------------------------------------------- | |
b292e2f5 | 729 | // "key_press_event" from any window |
c801d85f | 730 | //----------------------------------------------------------------------------- |
c801d85f | 731 | |
2f2aa628 | 732 | static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win ) |
47d67540 | 733 | { |
c50f1fb9 | 734 | if (g_isIdle) |
a2053b27 RR |
735 | wxapp_install_idle_handler(); |
736 | ||
737 | if (!win->m_hasVMT) return FALSE; | |
f5e27805 | 738 | if (g_blockEventsOnDrag) return FALSE; |
c801d85f | 739 | |
7be4c594 | 740 | /* |
d1367c3d RR |
741 | printf( "KeyDown-ScanCode is: %d.\n", gdk_event->keyval ); |
742 | if (gdk_event->state & GDK_SHIFT_MASK) | |
743 | printf( "ShiftDown.\n" ); | |
744 | else | |
745 | printf( "ShiftUp.\n" ); | |
746 | if (gdk_event->state & GDK_CONTROL_MASK) | |
747 | printf( "ControlDown.\n" ); | |
748 | else | |
749 | printf( "ControlUp.\n" ); | |
750 | printf( "\n" ); | |
7be4c594 | 751 | */ |
b0e813a0 RR |
752 | int x = 0; |
753 | int y = 0; | |
754 | GdkModifierType state; | |
755 | if (gdk_event->window) gdk_window_get_pointer(gdk_event->window, &x, &y, &state); | |
47d67540 | 756 | |
74505862 | 757 | long key_code = map_to_unmodified_wx_keysym( gdk_event->keyval ); |
c50f1fb9 | 758 | |
f0492f7d RR |
759 | /* sending unknown key events doesn't really make sense */ |
760 | if (key_code == 0) return FALSE; | |
761 | ||
762 | bool ret = FALSE; | |
c50f1fb9 VZ |
763 | |
764 | wxKeyEvent event( wxEVT_KEY_DOWN ); | |
d1367c3d | 765 | event.SetTimestamp( gdk_event->time ); |
f5e27805 RR |
766 | event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); |
767 | event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); | |
768 | event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); | |
769 | event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); | |
770 | event.m_keyCode = key_code; | |
b0e813a0 RR |
771 | event.m_scanCode = gdk_event->keyval; |
772 | event.m_x = x; | |
773 | event.m_y = y; | |
f5e27805 | 774 | event.SetEventObject( win ); |
c5b42c87 | 775 | ret = win->GetEventHandler()->ProcessEvent( event ); |
c50f1fb9 | 776 | |
c5b42c87 | 777 | key_code = map_to_wx_keysym( gdk_event->keyval ); |
47d67540 | 778 | |
88ac883a | 779 | #if wxUSE_ACCEL |
f5e27805 | 780 | if (!ret) |
47d67540 | 781 | { |
f5e27805 RR |
782 | wxWindow *ancestor = win; |
783 | while (ancestor) | |
784 | { | |
785 | int command = ancestor->GetAcceleratorTable()->GetCommand( event ); | |
786 | if (command != -1) | |
787 | { | |
788 | wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); | |
789 | ret = ancestor->GetEventHandler()->ProcessEvent( command_event ); | |
790 | break; | |
791 | } | |
792 | ancestor = ancestor->GetParent(); | |
793 | } | |
bcf1fa6b | 794 | } |
88ac883a | 795 | #endif // wxUSE_ACCEL |
d728dd40 KB |
796 | /* wxMSW doesn't send char events with Alt pressed */ |
797 | /* Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x | |
798 | will only be sent if it is not a menu accelerator. */ | |
799 | if ((key_code != 0) && ! ret ) | |
800 | { | |
c50f1fb9 | 801 | wxKeyEvent event2( wxEVT_CHAR ); |
d728dd40 KB |
802 | event2.SetTimestamp( gdk_event->time ); |
803 | event2.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); | |
804 | event2.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); | |
805 | event2.m_altDown = (gdk_event->state & GDK_MOD1_MASK); | |
806 | event2.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); | |
807 | event2.m_keyCode = key_code; | |
808 | event2.m_scanCode = gdk_event->keyval; | |
809 | event2.m_x = x; | |
810 | event2.m_y = y; | |
811 | event2.SetEventObject( win ); | |
812 | ret = (ret || win->GetEventHandler()->ProcessEvent( event2 )); | |
813 | } | |
814 | ||
ff8bfdbb | 815 | |
053f9cc1 | 816 | /* win is a control: tab can be propagated up */ |
ca298c88 | 817 | if ( (!ret) && |
5664fc32 | 818 | ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab)) && |
f03fc89f | 819 | (win->HasFlag(wxTE_PROCESS_TAB) == 0)) |
b292e2f5 RR |
820 | { |
821 | wxNavigationKeyEvent new_event; | |
f03fc89f | 822 | /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */ |
5664fc32 | 823 | new_event.SetDirection( (gdk_event->keyval == GDK_Tab) ); |
f03fc89f | 824 | /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ |
b98d804b | 825 | new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) ); |
b292e2f5 | 826 | new_event.SetCurrentFocus( win ); |
ff8bfdbb | 827 | ret = win->GetEventHandler()->ProcessEvent( new_event ); |
b292e2f5 | 828 | } |
ff8bfdbb | 829 | |
801aa178 | 830 | /* generate wxID_CANCEL if <esc> has been pressed (typically in dialogs) */ |
ca298c88 | 831 | if ( (!ret) && |
b98d804b RR |
832 | (gdk_event->keyval == GDK_Escape) ) |
833 | { | |
834 | wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); | |
835 | new_event.SetEventObject( win ); | |
836 | ret = win->GetEventHandler()->ProcessEvent( new_event ); | |
837 | } | |
c50f1fb9 | 838 | |
6bc8a1c8 | 839 | #if (GTK_MINOR_VERSION > 0) |
801aa178 RR |
840 | /* pressing F10 will activate the menu bar of the top frame */ |
841 | if ( (!ret) && | |
842 | (gdk_event->keyval == GDK_F10) ) | |
843 | { | |
844 | wxWindow *ancestor = win; | |
845 | while (ancestor) | |
846 | { | |
847 | if (wxIsKindOf(ancestor,wxFrame)) | |
c50f1fb9 VZ |
848 | { |
849 | wxFrame *frame = (wxFrame*) ancestor; | |
801aa178 | 850 | wxMenuBar *menubar = frame->GetMenuBar(); |
c50f1fb9 VZ |
851 | if (menubar) |
852 | { | |
801aa178 | 853 | wxNode *node = menubar->GetMenus().First(); |
c50f1fb9 VZ |
854 | if (node) |
855 | { | |
856 | // doesn't work correctly | |
88ac883a | 857 | // wxMenu *firstMenu = (wxMenu*) node->Data(); |
c50f1fb9 VZ |
858 | // gtk_menu_item_select( GTK_MENU_ITEM(firstMenu->m_owner) ); |
859 | // ret = TRUE; | |
860 | break; | |
861 | } | |
862 | } | |
863 | } | |
801aa178 RR |
864 | ancestor = ancestor->GetParent(); |
865 | } | |
866 | } | |
6bc8a1c8 | 867 | #endif |
ca298c88 | 868 | |
b292e2f5 | 869 | /* |
b98d804b RR |
870 | Damn, I forgot why this didn't work, but it didn't work. |
871 | ||
b292e2f5 | 872 | // win is a panel: up can be propagated to the panel |
a2053b27 | 873 | if ((!ret) && (win->m_wxwindow) && (win->m_parent) && (win->m_parent->AcceptsFocus()) && |
b292e2f5 RR |
874 | (gdk_event->keyval == GDK_Up)) |
875 | { | |
876 | win->m_parent->SetFocus(); | |
ff8bfdbb | 877 | ret = TRUE; |
b292e2f5 | 878 | } |
ff8bfdbb | 879 | |
b292e2f5 | 880 | // win is a panel: left/right can be propagated to the panel |
a2053b27 | 881 | if ((!ret) && (win->m_wxwindow) && |
ff8bfdbb | 882 | ((gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Left) || |
b292e2f5 RR |
883 | (gdk_event->keyval == GDK_Up) || (gdk_event->keyval == GDK_Down))) |
884 | { | |
885 | wxNavigationKeyEvent new_event; | |
886 | new_event.SetDirection( (gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Down) ); | |
887 | new_event.SetCurrentFocus( win ); | |
ff8bfdbb | 888 | ret = win->GetEventHandler()->ProcessEvent( new_event ); |
b292e2f5 RR |
889 | } |
890 | */ | |
ff8bfdbb | 891 | |
f5e27805 RR |
892 | if (ret) |
893 | { | |
b292e2f5 | 894 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" ); |
f03fc89f | 895 | return TRUE; |
f5e27805 | 896 | } |
47d67540 | 897 | |
034be888 | 898 | return FALSE; |
362c6693 | 899 | } |
c801d85f | 900 | |
b666df2c RR |
901 | //----------------------------------------------------------------------------- |
902 | // "key_release_event" from any window | |
903 | //----------------------------------------------------------------------------- | |
904 | ||
905 | static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win ) | |
906 | { | |
c50f1fb9 | 907 | if (g_isIdle) |
a2053b27 RR |
908 | wxapp_install_idle_handler(); |
909 | ||
910 | if (!win->m_hasVMT) return FALSE; | |
b666df2c RR |
911 | if (g_blockEventsOnDrag) return FALSE; |
912 | ||
913 | /* | |
d1367c3d RR |
914 | printf( "KeyUp-ScanCode is: %d.\n", gdk_event->keyval ); |
915 | if (gdk_event->state & GDK_SHIFT_MASK) | |
916 | printf( "ShiftDown.\n" ); | |
917 | else | |
918 | printf( "ShiftUp.\n" ); | |
919 | if (gdk_event->state & GDK_CONTROL_MASK) | |
920 | printf( "ControlDown.\n" ); | |
921 | else | |
922 | printf( "ControlUp.\n" ); | |
923 | printf( "\n" ); | |
b666df2c RR |
924 | */ |
925 | ||
74505862 | 926 | long key_code = map_to_unmodified_wx_keysym( gdk_event->keyval ); |
c50f1fb9 | 927 | |
f0492f7d RR |
928 | /* sending unknown key events doesn't really make sense */ |
929 | if (key_code == 0) return FALSE; | |
b666df2c | 930 | |
b0e813a0 RR |
931 | int x = 0; |
932 | int y = 0; | |
933 | GdkModifierType state; | |
934 | if (gdk_event->window) gdk_window_get_pointer(gdk_event->window, &x, &y, &state); | |
b666df2c RR |
935 | |
936 | wxKeyEvent event( wxEVT_KEY_UP ); | |
d1367c3d | 937 | event.SetTimestamp( gdk_event->time ); |
b666df2c RR |
938 | event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); |
939 | event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); | |
940 | event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); | |
941 | event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); | |
942 | event.m_keyCode = key_code; | |
b0e813a0 RR |
943 | event.m_scanCode = gdk_event->keyval; |
944 | event.m_x = x; | |
945 | event.m_y = y; | |
b666df2c RR |
946 | event.SetEventObject( win ); |
947 | ||
034be888 | 948 | if (win->GetEventHandler()->ProcessEvent( event )) |
b666df2c | 949 | { |
b98d804b | 950 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_release_event" ); |
f03fc89f | 951 | return TRUE; |
b666df2c RR |
952 | } |
953 | ||
034be888 | 954 | return FALSE; |
b666df2c RR |
955 | } |
956 | ||
c801d85f | 957 | //----------------------------------------------------------------------------- |
2f2aa628 RR |
958 | // "button_press_event" |
959 | //----------------------------------------------------------------------------- | |
c801d85f | 960 | |
2f2aa628 | 961 | static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) |
903f689b | 962 | { |
c50f1fb9 | 963 | if (g_isIdle) |
a2053b27 RR |
964 | wxapp_install_idle_handler(); |
965 | ||
966 | /* | |
967 | wxPrintf( _T("1) OnButtonPress from ") ); | |
968 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
969 | wxPrintf( win->GetClassInfo()->GetClassName() ); | |
970 | wxPrintf( _T(".\n") ); | |
971 | */ | |
a2053b27 | 972 | if (!win->m_hasVMT) return FALSE; |
f5e27805 | 973 | if (g_blockEventsOnDrag) return TRUE; |
76ed8f8d | 974 | if (g_blockEventsOnScroll) return TRUE; |
c801d85f | 975 | |
034be888 RR |
976 | if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; |
977 | ||
a2053b27 | 978 | if (win->m_wxwindow) |
c801d85f | 979 | { |
a2053b27 | 980 | if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow) && !GTK_WIDGET_HAS_FOCUS (win->m_wxwindow) ) |
f5e27805 | 981 | { |
a2053b27 | 982 | gtk_widget_grab_focus (win->m_wxwindow); |
47d67540 | 983 | |
c801d85f | 984 | /* |
a2053b27 | 985 | wxPrintf( _T("GrabFocus from ") ); |
f5e27805 | 986 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) |
a2053b27 RR |
987 | wxPrintf( win->GetClassInfo()->GetClassName() ); |
988 | wxPrintf( _T(".\n") ); | |
c801d85f | 989 | */ |
47d67540 | 990 | |
f5e27805 | 991 | } |
362c6693 | 992 | } |
47d67540 | 993 | |
8429bec1 | 994 | /* |
a2053b27 | 995 | wxPrintf( _T("2) OnButtonPress from ") ); |
f5e27805 | 996 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) |
a2053b27 RR |
997 | wxPrintf( win->GetClassInfo()->GetClassName() ); |
998 | wxPrintf( _T(".\n") ); | |
8429bec1 | 999 | */ |
30dea054 | 1000 | |
f5e27805 | 1001 | wxEventType event_type = wxEVT_LEFT_DOWN; |
47d67540 | 1002 | |
f5e27805 | 1003 | if (gdk_event->button == 1) |
c801d85f | 1004 | { |
f5e27805 RR |
1005 | switch (gdk_event->type) |
1006 | { | |
1007 | case GDK_BUTTON_PRESS: event_type = wxEVT_LEFT_DOWN; break; | |
1008 | case GDK_2BUTTON_PRESS: event_type = wxEVT_LEFT_DCLICK; break; | |
1009 | default: break; | |
1010 | } | |
362c6693 | 1011 | } |
f5e27805 | 1012 | else if (gdk_event->button == 2) |
c801d85f | 1013 | { |
f5e27805 RR |
1014 | switch (gdk_event->type) |
1015 | { | |
1016 | case GDK_BUTTON_PRESS: event_type = wxEVT_MIDDLE_DOWN; break; | |
1017 | case GDK_2BUTTON_PRESS: event_type = wxEVT_MIDDLE_DCLICK; break; | |
1018 | default: break; | |
1019 | } | |
362c6693 | 1020 | } |
f5e27805 | 1021 | else if (gdk_event->button == 3) |
c801d85f | 1022 | { |
f5e27805 RR |
1023 | switch (gdk_event->type) |
1024 | { | |
1025 | case GDK_BUTTON_PRESS: event_type = wxEVT_RIGHT_DOWN; break; | |
1026 | case GDK_2BUTTON_PRESS: event_type = wxEVT_RIGHT_DCLICK; break; | |
1027 | default: break; | |
1028 | } | |
362c6693 | 1029 | } |
47d67540 | 1030 | |
f5e27805 | 1031 | wxMouseEvent event( event_type ); |
d1367c3d | 1032 | event.SetTimestamp( gdk_event->time ); |
f5e27805 RR |
1033 | event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); |
1034 | event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); | |
1035 | event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); | |
1036 | event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); | |
1037 | event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); | |
1038 | event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); | |
1039 | event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); | |
47d67540 | 1040 | |
f5e27805 RR |
1041 | event.m_x = (long)gdk_event->x; |
1042 | event.m_y = (long)gdk_event->y; | |
47d67540 | 1043 | |
f5e27805 RR |
1044 | // Some control don't have their own X window and thus cannot get |
1045 | // any events. | |
47d67540 | 1046 | |
72195a0f | 1047 | if (!g_captureWindow) |
2f2aa628 | 1048 | { |
db1b4961 | 1049 | wxNode *node = win->GetChildren().First(); |
f5e27805 RR |
1050 | while (node) |
1051 | { | |
1052 | wxWindow *child = (wxWindow*)node->Data(); | |
ff8bfdbb | 1053 | |
a2053b27 | 1054 | if (child->m_isStaticBox) |
ff8bfdbb VZ |
1055 | { |
1056 | // wxStaticBox is transparent in the box itself | |
a2053b27 RR |
1057 | int x = event.m_x; |
1058 | int y = event.m_y; | |
1059 | int xx1 = child->m_x; | |
1060 | int yy1 = child->m_y; | |
1061 | int xx2 = child->m_x + child->m_width; | |
1062 | int yy2 = child->m_x + child->m_height; | |
ff8bfdbb VZ |
1063 | |
1064 | // left | |
1065 | if (((x >= xx1) && (x <= xx1+10) && (y >= yy1) && (y <= yy2)) || | |
1066 | // right | |
1067 | ((x >= xx2-10) && (x <= xx2) && (y >= yy1) && (y <= yy2)) || | |
1068 | // top | |
1069 | ((x >= xx1) && (x <= xx2) && (y >= yy1) && (y <= yy1+10)) || | |
1070 | // bottom | |
1071 | ((x >= xx1) && (x <= xx2) && (y >= yy2-1) && (y <= yy2))) | |
1072 | { | |
1ecc4d80 | 1073 | win = child; |
a2053b27 RR |
1074 | event.m_x -= child->m_x; |
1075 | event.m_y -= child->m_y; | |
1ecc4d80 | 1076 | break; |
ff8bfdbb VZ |
1077 | } |
1078 | ||
1079 | } | |
1080 | else | |
1081 | { | |
a2053b27 RR |
1082 | if ((child->m_wxwindow == (GtkWidget*) NULL) && |
1083 | (child->m_x <= event.m_x) && | |
1084 | (child->m_y <= event.m_y) && | |
1085 | (child->m_x+child->m_width >= event.m_x) && | |
1086 | (child->m_y+child->m_height >= event.m_y)) | |
1ecc4d80 RR |
1087 | { |
1088 | win = child; | |
a2053b27 RR |
1089 | event.m_x -= child->m_x; |
1090 | event.m_y -= child->m_y; | |
1ecc4d80 | 1091 | break; |
ff8bfdbb | 1092 | } |
f5e27805 RR |
1093 | } |
1094 | node = node->Next(); | |
1095 | } | |
2f2aa628 | 1096 | } |
ff8bfdbb | 1097 | |
f5e27805 | 1098 | event.SetEventObject( win ); |
47d67540 | 1099 | |
f5e27805 | 1100 | gs_timeLastClick = gdk_event->time; |
47d67540 | 1101 | |
f5e27805 | 1102 | if (win->GetEventHandler()->ProcessEvent( event )) |
034be888 | 1103 | { |
f5e27805 | 1104 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_press_event" ); |
f03fc89f | 1105 | return TRUE; |
034be888 | 1106 | } |
47d67540 | 1107 | |
034be888 | 1108 | return FALSE; |
362c6693 | 1109 | } |
c801d85f KB |
1110 | |
1111 | //----------------------------------------------------------------------------- | |
97b3455a | 1112 | // "button_release_event" |
2f2aa628 | 1113 | //----------------------------------------------------------------------------- |
c801d85f | 1114 | |
2f2aa628 | 1115 | static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) |
47d67540 | 1116 | { |
c50f1fb9 | 1117 | if (g_isIdle) |
a2053b27 RR |
1118 | wxapp_install_idle_handler(); |
1119 | ||
1120 | if (!win->m_hasVMT) return FALSE; | |
034be888 RR |
1121 | if (g_blockEventsOnDrag) return FALSE; |
1122 | if (g_blockEventsOnScroll) return FALSE; | |
c801d85f | 1123 | |
034be888 | 1124 | if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; |
47d67540 | 1125 | |
c801d85f | 1126 | /* |
f5e27805 RR |
1127 | printf( "OnButtonRelease from " ); |
1128 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
1129 | printf( win->GetClassInfo()->GetClassName() ); | |
1130 | printf( ".\n" ); | |
c801d85f | 1131 | */ |
47d67540 | 1132 | |
f5e27805 | 1133 | wxEventType event_type = wxEVT_NULL; |
47d67540 | 1134 | |
f5e27805 RR |
1135 | switch (gdk_event->button) |
1136 | { | |
1137 | case 1: event_type = wxEVT_LEFT_UP; break; | |
1138 | case 2: event_type = wxEVT_MIDDLE_UP; break; | |
1139 | case 3: event_type = wxEVT_RIGHT_UP; break; | |
1140 | } | |
47d67540 | 1141 | |
f5e27805 | 1142 | wxMouseEvent event( event_type ); |
d1367c3d | 1143 | event.SetTimestamp( gdk_event->time ); |
f5e27805 RR |
1144 | event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); |
1145 | event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); | |
1146 | event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); | |
1147 | event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); | |
1148 | event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); | |
1149 | event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); | |
1150 | event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); | |
1151 | event.m_x = (long)gdk_event->x; | |
1152 | event.m_y = (long)gdk_event->y; | |
1153 | ||
1154 | // Some control don't have their own X window and thus cannot get | |
1155 | // any events. | |
1156 | ||
72195a0f | 1157 | if (!g_captureWindow) |
2f2aa628 | 1158 | { |
db1b4961 | 1159 | wxNode *node = win->GetChildren().First(); |
f5e27805 RR |
1160 | while (node) |
1161 | { | |
1162 | wxWindow *child = (wxWindow*)node->Data(); | |
ff8bfdbb | 1163 | |
a2053b27 | 1164 | if (child->m_isStaticBox) |
ff8bfdbb VZ |
1165 | { |
1166 | // wxStaticBox is transparent in the box itself | |
1167 | int x = event.m_x; | |
1168 | int y = event.m_y; | |
a2053b27 RR |
1169 | int xx1 = child->m_x; |
1170 | int yy1 = child->m_y; | |
1171 | int xx2 = child->m_x + child->m_width; | |
1172 | int yy2 = child->m_x + child->m_height; | |
ff8bfdbb VZ |
1173 | |
1174 | // left | |
1175 | if (((x >= xx1) && (x <= xx1+10) && (y >= yy1) && (y <= yy2)) || | |
1176 | // right | |
1177 | ((x >= xx2-10) && (x <= xx2) && (y >= yy1) && (y <= yy2)) || | |
1178 | // top | |
1179 | ((x >= xx1) && (x <= xx2) && (y >= yy1) && (y <= yy1+10)) || | |
1180 | // bottom | |
1181 | ((x >= xx1) && (x <= xx2) && (y >= yy2-1) && (y <= yy2))) | |
1182 | { | |
1ecc4d80 | 1183 | win = child; |
a2053b27 RR |
1184 | event.m_x -= child->m_x; |
1185 | event.m_y -= child->m_y; | |
1ecc4d80 | 1186 | break; |
ff8bfdbb VZ |
1187 | } |
1188 | ||
1189 | } | |
1190 | else | |
1191 | { | |
a2053b27 RR |
1192 | if ((child->m_wxwindow == (GtkWidget*) NULL) && |
1193 | (child->m_x <= event.m_x) && | |
1194 | (child->m_y <= event.m_y) && | |
1195 | (child->m_x+child->m_width >= event.m_x) && | |
1196 | (child->m_y+child->m_height >= event.m_y)) | |
1ecc4d80 RR |
1197 | { |
1198 | win = child; | |
a2053b27 RR |
1199 | event.m_x -= child->m_x; |
1200 | event.m_y -= child->m_y; | |
1ecc4d80 | 1201 | break; |
ff8bfdbb | 1202 | } |
f5e27805 RR |
1203 | } |
1204 | node = node->Next(); | |
1205 | } | |
2f2aa628 | 1206 | } |
47d67540 | 1207 | |
f5e27805 | 1208 | event.SetEventObject( win ); |
47d67540 | 1209 | |
f5e27805 | 1210 | if (win->GetEventHandler()->ProcessEvent( event )) |
034be888 | 1211 | { |
f5e27805 | 1212 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_release_event" ); |
f03fc89f | 1213 | return TRUE; |
034be888 | 1214 | } |
47d67540 | 1215 | |
034be888 | 1216 | return FALSE; |
362c6693 | 1217 | } |
c801d85f KB |
1218 | |
1219 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
1220 | // "motion_notify_event" |
1221 | //----------------------------------------------------------------------------- | |
c801d85f | 1222 | |
2f2aa628 | 1223 | static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxWindow *win ) |
47d67540 | 1224 | { |
c50f1fb9 | 1225 | if (g_isIdle) |
a2053b27 RR |
1226 | wxapp_install_idle_handler(); |
1227 | ||
1228 | if (!win->m_hasVMT) return FALSE; | |
034be888 RR |
1229 | if (g_blockEventsOnDrag) return FALSE; |
1230 | if (g_blockEventsOnScroll) return FALSE; | |
1231 | ||
1232 | if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; | |
1233 | ||
ff8bfdbb | 1234 | if (gdk_event->is_hint) |
aae24d21 RR |
1235 | { |
1236 | int x = 0; | |
1237 | int y = 0; | |
1238 | GdkModifierType state; | |
1239 | gdk_window_get_pointer(gdk_event->window, &x, &y, &state); | |
1240 | gdk_event->x = x; | |
1241 | gdk_event->y = y; | |
1242 | gdk_event->state = state; | |
1243 | } | |
ff8bfdbb | 1244 | |
c801d85f | 1245 | /* |
e380f72b RR |
1246 | printf( "OnMotion from " ); |
1247 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
1248 | printf( win->GetClassInfo()->GetClassName() ); | |
1249 | printf( ".\n" ); | |
aae24d21 | 1250 | */ |
47d67540 | 1251 | |
e380f72b | 1252 | wxMouseEvent event( wxEVT_MOTION ); |
d1367c3d | 1253 | event.SetTimestamp( gdk_event->time ); |
e380f72b RR |
1254 | event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK); |
1255 | event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK); | |
1256 | event.m_altDown = (gdk_event->state & GDK_MOD1_MASK); | |
1257 | event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK); | |
1258 | event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK); | |
1259 | event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK); | |
1260 | event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK); | |
1261 | ||
1262 | event.m_x = (long)gdk_event->x; | |
1263 | event.m_y = (long)gdk_event->y; | |
1264 | ||
1265 | // Some control don't have their own X window and thus cannot get | |
1266 | // any events. | |
1267 | ||
72195a0f | 1268 | if (!g_captureWindow) |
2f2aa628 | 1269 | { |
db1b4961 | 1270 | wxNode *node = win->GetChildren().First(); |
e380f72b RR |
1271 | while (node) |
1272 | { | |
1273 | wxWindow *child = (wxWindow*)node->Data(); | |
ff8bfdbb | 1274 | |
a2053b27 | 1275 | if (child->m_isStaticBox) |
ff8bfdbb VZ |
1276 | { |
1277 | // wxStaticBox is transparent in the box itself | |
1278 | int x = event.m_x; | |
1279 | int y = event.m_y; | |
a2053b27 RR |
1280 | int xx1 = child->m_x; |
1281 | int yy1 = child->m_y; | |
1282 | int xx2 = child->m_x + child->m_width; | |
1283 | int yy2 = child->m_x + child->m_height; | |
ff8bfdbb VZ |
1284 | |
1285 | // left | |
1286 | if (((x >= xx1) && (x <= xx1+10) && (y >= yy1) && (y <= yy2)) || | |
1287 | // right | |
1288 | ((x >= xx2-10) && (x <= xx2) && (y >= yy1) && (y <= yy2)) || | |
1289 | // top | |
1290 | ((x >= xx1) && (x <= xx2) && (y >= yy1) && (y <= yy1+10)) || | |
1291 | // bottom | |
1292 | ((x >= xx1) && (x <= xx2) && (y >= yy2-1) && (y <= yy2))) | |
1293 | { | |
1ecc4d80 | 1294 | win = child; |
a2053b27 RR |
1295 | event.m_x -= child->m_x; |
1296 | event.m_y -= child->m_y; | |
1ecc4d80 | 1297 | break; |
ff8bfdbb VZ |
1298 | } |
1299 | ||
1300 | } | |
1301 | else | |
1302 | { | |
a2053b27 RR |
1303 | if ((child->m_wxwindow == (GtkWidget*) NULL) && |
1304 | (child->m_x <= event.m_x) && | |
1305 | (child->m_y <= event.m_y) && | |
1306 | (child->m_x+child->m_width >= event.m_x) && | |
1307 | (child->m_y+child->m_height >= event.m_y)) | |
1ecc4d80 RR |
1308 | { |
1309 | win = child; | |
a2053b27 RR |
1310 | event.m_x -= child->m_x; |
1311 | event.m_y -= child->m_y; | |
1ecc4d80 | 1312 | break; |
ff8bfdbb | 1313 | } |
e380f72b RR |
1314 | } |
1315 | node = node->Next(); | |
1316 | } | |
2f2aa628 | 1317 | } |
47d67540 | 1318 | |
e380f72b | 1319 | event.SetEventObject( win ); |
47d67540 | 1320 | |
e380f72b | 1321 | if (win->GetEventHandler()->ProcessEvent( event )) |
034be888 | 1322 | { |
e380f72b | 1323 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "motion_notify_event" ); |
f03fc89f | 1324 | return TRUE; |
034be888 | 1325 | } |
47d67540 | 1326 | |
034be888 | 1327 | return FALSE; |
362c6693 | 1328 | } |
c801d85f KB |
1329 | |
1330 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
1331 | // "focus_in_event" |
1332 | //----------------------------------------------------------------------------- | |
c801d85f | 1333 | |
2f2aa628 | 1334 | static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win ) |
c801d85f | 1335 | { |
c50f1fb9 | 1336 | if (g_isIdle) |
a2053b27 RR |
1337 | wxapp_install_idle_handler(); |
1338 | ||
1339 | if (!win->m_hasVMT) return FALSE; | |
034be888 | 1340 | if (g_blockEventsOnDrag) return FALSE; |
ff8bfdbb | 1341 | |
b292e2f5 | 1342 | g_focusWindow = win; |
ff8bfdbb | 1343 | |
a2053b27 | 1344 | if (win->m_wxwindow) |
c801d85f | 1345 | { |
a2053b27 | 1346 | if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow)) |
e380f72b | 1347 | { |
a2053b27 | 1348 | GTK_WIDGET_SET_FLAGS (win->m_wxwindow, GTK_HAS_FOCUS); |
47d67540 | 1349 | /* |
e380f72b RR |
1350 | printf( "SetFocus flag from " ); |
1351 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
1352 | printf( win->GetClassInfo()->GetClassName() ); | |
1353 | printf( ".\n" ); | |
c801d85f | 1354 | */ |
e380f72b | 1355 | } |
362c6693 | 1356 | } |
47d67540 | 1357 | |
47d67540 | 1358 | |
c801d85f | 1359 | /* |
f03fc89f | 1360 | printf( "OnSetFocus from " ); |
e380f72b | 1361 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) |
f03fc89f VZ |
1362 | printf( win->GetClassInfo()->GetClassName() ); |
1363 | printf( " " ); | |
1364 | printf( WXSTRINGCAST win->GetLabel() ); | |
1365 | printf( ".\n" ); | |
c801d85f | 1366 | */ |
47d67540 | 1367 | |
e380f72b RR |
1368 | wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() ); |
1369 | event.SetEventObject( win ); | |
47d67540 | 1370 | |
e380f72b | 1371 | if (win->GetEventHandler()->ProcessEvent( event )) |
034be888 | 1372 | { |
e380f72b | 1373 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_in_event" ); |
034be888 RR |
1374 | return TRUE; |
1375 | } | |
ca298c88 | 1376 | |
034be888 | 1377 | return FALSE; |
362c6693 | 1378 | } |
c801d85f KB |
1379 | |
1380 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
1381 | // "focus_out_event" |
1382 | //----------------------------------------------------------------------------- | |
c801d85f | 1383 | |
2f2aa628 | 1384 | static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win ) |
c801d85f | 1385 | { |
c50f1fb9 | 1386 | if (g_isIdle) |
a2053b27 RR |
1387 | wxapp_install_idle_handler(); |
1388 | ||
1389 | if (!win->m_hasVMT) return FALSE; | |
034be888 | 1390 | if (g_blockEventsOnDrag) return FALSE; |
ca298c88 | 1391 | |
a2053b27 | 1392 | if (win->m_wxwindow) |
e380f72b | 1393 | { |
a2053b27 RR |
1394 | if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow)) |
1395 | GTK_WIDGET_UNSET_FLAGS (win->m_wxwindow, GTK_HAS_FOCUS); | |
e380f72b | 1396 | } |
47d67540 | 1397 | |
c801d85f | 1398 | /* |
f03fc89f | 1399 | printf( "OnKillFocus from " ); |
e380f72b | 1400 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) |
f03fc89f VZ |
1401 | printf( win->GetClassInfo()->GetClassName() ); |
1402 | printf( ".\n" ); | |
c801d85f | 1403 | */ |
47d67540 | 1404 | |
e380f72b RR |
1405 | wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() ); |
1406 | event.SetEventObject( win ); | |
47d67540 | 1407 | |
e380f72b | 1408 | if (win->GetEventHandler()->ProcessEvent( event )) |
034be888 | 1409 | { |
e380f72b | 1410 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_out_event" ); |
034be888 RR |
1411 | return TRUE; |
1412 | } | |
ca298c88 | 1413 | |
034be888 | 1414 | return FALSE; |
362c6693 | 1415 | } |
c801d85f | 1416 | |
b4071e91 RR |
1417 | //----------------------------------------------------------------------------- |
1418 | // "enter_notify_event" | |
1419 | //----------------------------------------------------------------------------- | |
1420 | ||
1421 | static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) | |
1422 | { | |
c50f1fb9 | 1423 | if (g_isIdle) |
a2053b27 | 1424 | wxapp_install_idle_handler(); |
ca298c88 | 1425 | |
a2053b27 RR |
1426 | if (!win->m_hasVMT) return FALSE; |
1427 | if (g_blockEventsOnDrag) return FALSE; | |
47d67540 | 1428 | |
a2053b27 | 1429 | if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; |
b292e2f5 | 1430 | |
e380f72b | 1431 | wxMouseEvent event( wxEVT_ENTER_WINDOW ); |
6bc8a1c8 | 1432 | #if (GTK_MINOR_VERSION > 0) |
d1367c3d | 1433 | event.SetTimestamp( gdk_event->time ); |
6bc8a1c8 | 1434 | #endif |
e380f72b | 1435 | event.SetEventObject( win ); |
ff8bfdbb | 1436 | |
4a33eba6 RR |
1437 | int x = 0; |
1438 | int y = 0; | |
1439 | GdkModifierType state = (GdkModifierType)0; | |
ff8bfdbb | 1440 | |
a2053b27 | 1441 | gdk_window_get_pointer( widget->window, &x, &y, &state ); |
ff8bfdbb | 1442 | |
4a33eba6 RR |
1443 | event.m_shiftDown = (state & GDK_SHIFT_MASK); |
1444 | event.m_controlDown = (state & GDK_CONTROL_MASK); | |
1445 | event.m_altDown = (state & GDK_MOD1_MASK); | |
1446 | event.m_metaDown = (state & GDK_MOD2_MASK); | |
1447 | event.m_leftDown = (state & GDK_BUTTON1_MASK); | |
1448 | event.m_middleDown = (state & GDK_BUTTON2_MASK); | |
1449 | event.m_rightDown = (state & GDK_BUTTON3_MASK); | |
1450 | ||
1451 | event.m_x = (long)x; | |
1452 | event.m_y = (long)y; | |
ff8bfdbb | 1453 | |
e380f72b | 1454 | if (win->GetEventHandler()->ProcessEvent( event )) |
034be888 | 1455 | { |
e380f72b | 1456 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "enter_notify_event" ); |
034be888 RR |
1457 | return TRUE; |
1458 | } | |
ca298c88 | 1459 | |
034be888 | 1460 | return FALSE; |
b4071e91 | 1461 | } |
47d67540 | 1462 | |
b4071e91 RR |
1463 | //----------------------------------------------------------------------------- |
1464 | // "leave_notify_event" | |
1465 | //----------------------------------------------------------------------------- | |
1466 | ||
1467 | static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) | |
1468 | { | |
c50f1fb9 | 1469 | if (g_isIdle) |
a2053b27 | 1470 | wxapp_install_idle_handler(); |
acfd422a | 1471 | |
a2053b27 RR |
1472 | if (!win->m_hasVMT) return FALSE; |
1473 | if (g_blockEventsOnDrag) return FALSE; | |
b292e2f5 | 1474 | |
a2053b27 | 1475 | if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE; |
c50f1fb9 | 1476 | |
e380f72b | 1477 | wxMouseEvent event( wxEVT_LEAVE_WINDOW ); |
6bc8a1c8 | 1478 | #if (GTK_MINOR_VERSION > 0) |
d1367c3d | 1479 | event.SetTimestamp( gdk_event->time ); |
6bc8a1c8 | 1480 | #endif |
e380f72b | 1481 | event.SetEventObject( win ); |
47d67540 | 1482 | |
4a33eba6 RR |
1483 | int x = 0; |
1484 | int y = 0; | |
1485 | GdkModifierType state = (GdkModifierType)0; | |
ff8bfdbb | 1486 | |
4a33eba6 | 1487 | gdk_window_get_pointer( widget->window, &x, &y, &state ); |
ff8bfdbb | 1488 | |
4a33eba6 RR |
1489 | event.m_shiftDown = (state & GDK_SHIFT_MASK); |
1490 | event.m_controlDown = (state & GDK_CONTROL_MASK); | |
1491 | event.m_altDown = (state & GDK_MOD1_MASK); | |
1492 | event.m_metaDown = (state & GDK_MOD2_MASK); | |
1493 | event.m_leftDown = (state & GDK_BUTTON1_MASK); | |
1494 | event.m_middleDown = (state & GDK_BUTTON2_MASK); | |
1495 | event.m_rightDown = (state & GDK_BUTTON3_MASK); | |
1496 | ||
1497 | event.m_x = (long)x; | |
1498 | event.m_y = (long)y; | |
ff8bfdbb | 1499 | |
e380f72b | 1500 | if (win->GetEventHandler()->ProcessEvent( event )) |
034be888 | 1501 | { |
e380f72b | 1502 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "leave_notify_event" ); |
034be888 RR |
1503 | return TRUE; |
1504 | } | |
ca298c88 | 1505 | |
034be888 | 1506 | return FALSE; |
b4071e91 | 1507 | } |
47d67540 | 1508 | |
c801d85f | 1509 | //----------------------------------------------------------------------------- |
2f2aa628 RR |
1510 | // "value_changed" from m_vAdjust |
1511 | //----------------------------------------------------------------------------- | |
c801d85f | 1512 | |
2f2aa628 | 1513 | static void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) |
c801d85f | 1514 | { |
c50f1fb9 | 1515 | if (g_isIdle) |
a2053b27 | 1516 | wxapp_install_idle_handler(); |
c801d85f | 1517 | |
a2053b27 | 1518 | if (g_blockEventsOnDrag) return; |
47d67540 | 1519 | |
a2053b27 | 1520 | if (!win->m_hasVMT) return; |
47d67540 | 1521 | |
a2053b27 | 1522 | float diff = win->m_vAdjust->value - win->m_oldVerticalPos; |
e380f72b | 1523 | if (fabs(diff) < 0.2) return; |
a2053b27 | 1524 | win->m_oldVerticalPos = win->m_vAdjust->value; |
47d67540 | 1525 | |
e380f72b | 1526 | wxEventType command = wxEVT_NULL; |
47d67540 | 1527 | |
a2053b27 RR |
1528 | float line_step = win->m_vAdjust->step_increment; |
1529 | float page_step = win->m_vAdjust->page_increment; | |
47d67540 | 1530 | |
f03fc89f | 1531 | if (win->IsScrolling()) |
76ed8f8d | 1532 | { |
c5b42c87 | 1533 | command = wxEVT_SCROLLWIN_THUMBTRACK; |
76ed8f8d RR |
1534 | } |
1535 | else | |
1536 | { | |
c5b42c87 RR |
1537 | if (fabs(win->m_vAdjust->value-win->m_vAdjust->lower) < 0.2) command = wxEVT_SCROLLWIN_BOTTOM; |
1538 | else if (fabs(win->m_vAdjust->value-win->m_vAdjust->upper) < 0.2) command = wxEVT_SCROLLWIN_TOP; | |
1539 | else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLLWIN_LINEDOWN; | |
1540 | else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLLWIN_LINEUP; | |
1541 | else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLLWIN_PAGEDOWN; | |
1542 | else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLLWIN_PAGEUP; | |
1543 | else command = wxEVT_SCROLLWIN_THUMBTRACK; | |
76ed8f8d | 1544 | } |
47d67540 | 1545 | |
a2053b27 | 1546 | int value = (int)(win->m_vAdjust->value+0.5); |
c801d85f | 1547 | |
c5b42c87 | 1548 | wxScrollWinEvent event( command, value, wxVERTICAL ); |
e380f72b RR |
1549 | event.SetEventObject( win ); |
1550 | win->GetEventHandler()->ProcessEvent( event ); | |
362c6693 | 1551 | } |
c801d85f KB |
1552 | |
1553 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
1554 | // "value_changed" from m_hAdjust |
1555 | //----------------------------------------------------------------------------- | |
c801d85f | 1556 | |
2f2aa628 | 1557 | static void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) |
47d67540 | 1558 | { |
c50f1fb9 | 1559 | if (g_isIdle) |
a2053b27 | 1560 | wxapp_install_idle_handler(); |
47d67540 | 1561 | |
a2053b27 RR |
1562 | if (g_blockEventsOnDrag) return; |
1563 | if (!win->m_hasVMT) return; | |
47d67540 | 1564 | |
a2053b27 | 1565 | float diff = win->m_hAdjust->value - win->m_oldHorizontalPos; |
e380f72b | 1566 | if (fabs(diff) < 0.2) return; |
a2053b27 | 1567 | win->m_oldHorizontalPos = win->m_hAdjust->value; |
47d67540 | 1568 | |
e380f72b | 1569 | wxEventType command = wxEVT_NULL; |
47d67540 | 1570 | |
a2053b27 RR |
1571 | float line_step = win->m_hAdjust->step_increment; |
1572 | float page_step = win->m_hAdjust->page_increment; | |
8bbe427f | 1573 | |
f03fc89f | 1574 | if (win->IsScrolling()) |
76ed8f8d | 1575 | { |
c5b42c87 | 1576 | command = wxEVT_SCROLLWIN_THUMBTRACK; |
76ed8f8d RR |
1577 | } |
1578 | else | |
1579 | { | |
c5b42c87 RR |
1580 | if (fabs(win->m_hAdjust->value-win->m_hAdjust->lower) < 0.2) command = wxEVT_SCROLLWIN_BOTTOM; |
1581 | else if (fabs(win->m_hAdjust->value-win->m_hAdjust->upper) < 0.2) command = wxEVT_SCROLLWIN_TOP; | |
1582 | else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLLWIN_LINEDOWN; | |
1583 | else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLLWIN_LINEUP; | |
1584 | else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLLWIN_PAGEDOWN; | |
1585 | else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLLWIN_PAGEUP; | |
1586 | else command = wxEVT_SCROLLWIN_THUMBTRACK; | |
76ed8f8d | 1587 | } |
c801d85f | 1588 | |
a2053b27 | 1589 | int value = (int)(win->m_hAdjust->value+0.5); |
47d67540 | 1590 | |
c5b42c87 | 1591 | wxScrollWinEvent event( command, value, wxHORIZONTAL ); |
e380f72b RR |
1592 | event.SetEventObject( win ); |
1593 | win->GetEventHandler()->ProcessEvent( event ); | |
362c6693 | 1594 | } |
c801d85f KB |
1595 | |
1596 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
1597 | // "changed" from m_vAdjust |
1598 | //----------------------------------------------------------------------------- | |
c801d85f | 1599 | |
2f2aa628 | 1600 | static void gtk_window_vscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) |
c801d85f | 1601 | { |
c50f1fb9 | 1602 | if (g_isIdle) |
a2053b27 | 1603 | wxapp_install_idle_handler(); |
c801d85f | 1604 | |
a2053b27 RR |
1605 | if (g_blockEventsOnDrag) return; |
1606 | if (!win->m_hasVMT) return; | |
47d67540 | 1607 | |
c5b42c87 | 1608 | wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK; |
a2053b27 | 1609 | int value = (int)(win->m_vAdjust->value+0.5); |
c801d85f | 1610 | |
c5b42c87 | 1611 | wxScrollWinEvent event( command, value, wxVERTICAL ); |
e380f72b RR |
1612 | event.SetEventObject( win ); |
1613 | win->GetEventHandler()->ProcessEvent( event ); | |
362c6693 | 1614 | } |
c801d85f KB |
1615 | |
1616 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
1617 | // "changed" from m_hAdjust |
1618 | //----------------------------------------------------------------------------- | |
c801d85f | 1619 | |
2f2aa628 | 1620 | static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win ) |
47d67540 | 1621 | { |
c50f1fb9 | 1622 | if (g_isIdle) |
a2053b27 | 1623 | wxapp_install_idle_handler(); |
47d67540 | 1624 | |
a2053b27 RR |
1625 | if (g_blockEventsOnDrag) return; |
1626 | if (!win->m_hasVMT) return; | |
47d67540 | 1627 | |
c5b42c87 | 1628 | wxEventType command = wxEVT_SCROLLWIN_THUMBTRACK; |
a2053b27 | 1629 | int value = (int)(win->m_hAdjust->value+0.5); |
47d67540 | 1630 | |
c5b42c87 | 1631 | wxScrollWinEvent event( command, value, wxHORIZONTAL ); |
e380f72b RR |
1632 | event.SetEventObject( win ); |
1633 | win->GetEventHandler()->ProcessEvent( event ); | |
362c6693 | 1634 | } |
c801d85f | 1635 | |
cb43b372 RR |
1636 | //----------------------------------------------------------------------------- |
1637 | // "button_press_event" from scrollbar | |
1638 | //----------------------------------------------------------------------------- | |
1639 | ||
8bbe427f VZ |
1640 | static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), |
1641 | GdkEventButton *WXUNUSED(gdk_event), | |
ff8bfdbb | 1642 | wxWindow *win ) |
cb43b372 | 1643 | { |
c50f1fb9 | 1644 | if (g_isIdle) |
a2053b27 RR |
1645 | wxapp_install_idle_handler(); |
1646 | ||
1ecc4d80 RR |
1647 | // don't test here as we can release the mouse while being over |
1648 | // a different window then the slider | |
1649 | // | |
76ed8f8d | 1650 | // if (gdk_event->window != widget->slider) return FALSE; |
8bbe427f | 1651 | |
f03fc89f | 1652 | win->SetScrolling( TRUE ); |
47d67540 | 1653 | |
e380f72b | 1654 | return FALSE; |
cb43b372 RR |
1655 | } |
1656 | ||
1657 | //----------------------------------------------------------------------------- | |
1658 | // "button_release_event" from scrollbar | |
1659 | //----------------------------------------------------------------------------- | |
1660 | ||
8bbe427f VZ |
1661 | static gint gtk_scrollbar_button_release_callback( GtkRange *widget, |
1662 | GdkEventButton *WXUNUSED(gdk_event), | |
ff8bfdbb | 1663 | wxWindow *win ) |
cb43b372 | 1664 | { |
76ed8f8d | 1665 | |
1ecc4d80 | 1666 | // don't test here as we can release the mouse while being over |
76ed8f8d RR |
1667 | // a different window then the slider |
1668 | // | |
1669 | // if (gdk_event->window != widget->slider) return FALSE; | |
cb43b372 | 1670 | |
a2053b27 | 1671 | GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(win->m_widget); |
47d67540 | 1672 | |
f03fc89f | 1673 | if (widget == GTK_RANGE(scrolledWindow->vscrollbar)) |
a2053b27 | 1674 | gtk_signal_emit_by_name( GTK_OBJECT(win->m_hAdjust), "value_changed" ); |
e380f72b | 1675 | else |
a2053b27 | 1676 | gtk_signal_emit_by_name( GTK_OBJECT(win->m_vAdjust), "value_changed" ); |
47d67540 | 1677 | |
f03fc89f | 1678 | win->SetScrolling( FALSE ); |
47d67540 | 1679 | |
e380f72b | 1680 | return FALSE; |
cb43b372 RR |
1681 | } |
1682 | ||
f03fc89f VZ |
1683 | // ---------------------------------------------------------------------------- |
1684 | // this wxWindowBase function is implemented here (in platform-specific file) | |
1685 | // because it is static and so couldn't be made virtual | |
1686 | // ---------------------------------------------------------------------------- | |
2b07d713 | 1687 | |
f03fc89f | 1688 | wxWindow *wxWindowBase::FindFocus() |
2b07d713 | 1689 | { |
f03fc89f | 1690 | return g_focusWindow; |
2b07d713 | 1691 | } |
ca298c88 | 1692 | |
a2053b27 RR |
1693 | //----------------------------------------------------------------------------- |
1694 | // "realize" from m_widget | |
1695 | //----------------------------------------------------------------------------- | |
1696 | ||
1697 | /* we cannot set colours, fonts and cursors before the widget has | |
1698 | been realized, so we do this directly after realization */ | |
1699 | ||
1700 | static gint | |
a234a61a | 1701 | gtk_window_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win ) |
a2053b27 | 1702 | { |
c50f1fb9 | 1703 | if (g_isIdle) |
a2053b27 RR |
1704 | wxapp_install_idle_handler(); |
1705 | ||
739730ca RR |
1706 | if (win->m_delayedFont) |
1707 | win->SetFont( win->GetFont() ); | |
a2053b27 | 1708 | |
739730ca RR |
1709 | if (win->m_delayedBackgroundColour) |
1710 | win->SetBackgroundColour( win->GetBackgroundColour() ); | |
a2053b27 | 1711 | |
739730ca RR |
1712 | if (win->m_delayedForegroundColour) |
1713 | win->SetForegroundColour( win->GetForegroundColour() ); | |
a2053b27 | 1714 | |
739730ca | 1715 | win->SetCursor( win->GetCursor() ); |
c50f1fb9 | 1716 | |
3c679789 RR |
1717 | wxWindowCreateEvent event( win ); |
1718 | event.SetEventObject( win ); | |
1719 | win->GetEventHandler()->ProcessEvent( event ); | |
a2053b27 RR |
1720 | |
1721 | return FALSE; | |
1722 | } | |
1723 | ||
6ca41e57 RR |
1724 | //----------------------------------------------------------------------------- |
1725 | // InsertChild for wxWindow. | |
1726 | //----------------------------------------------------------------------------- | |
1727 | ||
b1170810 RR |
1728 | /* Callback for wxWindow. This very strange beast has to be used because |
1729 | * C++ has no virtual methods in a constructor. We have to emulate a | |
1730 | * virtual function here as wxNotebook requires a different way to insert | |
1731 | * a child in it. I had opted for creating a wxNotebookPage window class | |
1732 | * which would have made this superfluous (such in the MDI window system), | |
1733 | * but no-one was listening to me... */ | |
6ca41e57 RR |
1734 | |
1735 | static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child ) | |
1736 | { | |
a2053b27 RR |
1737 | gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow), |
1738 | GTK_WIDGET(child->m_widget), | |
1739 | child->m_x, | |
1740 | child->m_y, | |
1741 | child->m_width, | |
1742 | child->m_height ); | |
f03fc89f VZ |
1743 | |
1744 | if (parent->HasFlag(wxTAB_TRAVERSAL)) | |
3e61c765 RR |
1745 | { |
1746 | /* we now allow a window to get the focus as long as it | |
ff8bfdbb | 1747 | doesn't have any children. */ |
a2053b27 | 1748 | GTK_WIDGET_UNSET_FLAGS( parent->m_wxwindow, GTK_CAN_FOCUS ); |
3e61c765 | 1749 | } |
6ca41e57 RR |
1750 | } |
1751 | ||
bbe0af5b RR |
1752 | //----------------------------------------------------------------------------- |
1753 | // global functions | |
1754 | //----------------------------------------------------------------------------- | |
1755 | ||
1756 | wxWindow* wxGetActiveWindow() | |
1757 | { | |
f03fc89f | 1758 | return g_focusWindow; |
bbe0af5b RR |
1759 | } |
1760 | ||
c801d85f | 1761 | //----------------------------------------------------------------------------- |
2f2aa628 | 1762 | // wxWindow |
c801d85f KB |
1763 | //----------------------------------------------------------------------------- |
1764 | ||
f03fc89f | 1765 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) |
c801d85f | 1766 | |
68995f26 | 1767 | void wxWindow::Init() |
c801d85f | 1768 | { |
f03fc89f VZ |
1769 | // common init |
1770 | InitBase(); | |
68995f26 | 1771 | |
f03fc89f | 1772 | // GTK specific |
a2053b27 | 1773 | m_widget = (GtkWidget *) NULL; |
e380f72b | 1774 | m_wxwindow = (GtkWidget *) NULL; |
8bbe427f | 1775 | |
f03fc89f | 1776 | // position/size |
a2053b27 RR |
1777 | m_x = 0; |
1778 | m_y = 0; | |
1779 | m_width = 0; | |
e380f72b | 1780 | m_height = 0; |
8bbe427f | 1781 | |
e380f72b RR |
1782 | m_sizeSet = FALSE; |
1783 | m_hasVMT = FALSE; | |
1784 | m_needParent = TRUE; | |
31c6b4fc | 1785 | m_isBeingDeleted = FALSE; |
8bbe427f | 1786 | |
a2053b27 | 1787 | m_hasScrolling = FALSE; |
e380f72b | 1788 | m_isScrolling = FALSE; |
f03fc89f | 1789 | |
a2053b27 | 1790 | m_hAdjust = (GtkAdjustment*) NULL; |
e380f72b | 1791 | m_vAdjust = (GtkAdjustment*) NULL; |
a2053b27 | 1792 | m_oldHorizontalPos = 0.0; |
e380f72b | 1793 | m_oldVerticalPos = 0.0; |
8bbe427f | 1794 | |
e380f72b RR |
1795 | m_resizing = FALSE; |
1796 | m_scrollGC = (GdkGC*) NULL; | |
1797 | m_widgetStyle = (GtkStyle*) NULL; | |
8bbe427f | 1798 | |
ddb6bc71 | 1799 | m_insertCallback = (wxInsertChildFunction) NULL; |
8bbe427f | 1800 | |
1ecc4d80 | 1801 | m_isStaticBox = FALSE; |
b292e2f5 | 1802 | m_acceptsFocus = FALSE; |
362c6693 | 1803 | } |
c801d85f | 1804 | |
68995f26 VZ |
1805 | wxWindow::wxWindow() |
1806 | { | |
1807 | Init(); | |
1808 | } | |
1809 | ||
6ca41e57 | 1810 | wxWindow::wxWindow( wxWindow *parent, wxWindowID id, |
e380f72b RR |
1811 | const wxPoint &pos, const wxSize &size, |
1812 | long style, const wxString &name ) | |
6ca41e57 | 1813 | { |
68995f26 VZ |
1814 | Init(); |
1815 | ||
e380f72b | 1816 | Create( parent, id, pos, size, style, name ); |
6ca41e57 | 1817 | } |
8bbe427f | 1818 | |
debe6624 | 1819 | bool wxWindow::Create( wxWindow *parent, wxWindowID id, |
e380f72b RR |
1820 | const wxPoint &pos, const wxSize &size, |
1821 | long style, const wxString &name ) | |
c801d85f | 1822 | { |
e380f72b | 1823 | PreCreation( parent, id, pos, size, style, name ); |
47d67540 | 1824 | |
ddb6bc71 RR |
1825 | m_insertCallback = wxInsertChildInWindow; |
1826 | ||
e380f72b | 1827 | m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); |
38c7b3d3 | 1828 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); |
ff8bfdbb | 1829 | |
2e563988 RR |
1830 | #ifdef __WXDEBUG__ |
1831 | debug_focus_in( m_widget, _T("wxWindow::m_widget"), name ); | |
1832 | #endif | |
1833 | ||
f03fc89f | 1834 | GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(m_widget); |
47d67540 | 1835 | |
2e563988 | 1836 | #ifdef __WXDEBUG__ |
f03fc89f VZ |
1837 | debug_focus_in( scrolledWindow->hscrollbar, _T("wxWindow::hsrcollbar"), name ); |
1838 | debug_focus_in( scrolledWindow->vscrollbar, _T("wxWindow::vsrcollbar"), name ); | |
2e563988 RR |
1839 | #endif |
1840 | ||
e380f72b RR |
1841 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); |
1842 | scroll_class->scrollbar_spacing = 0; | |
47d67540 | 1843 | |
f03fc89f | 1844 | gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); |
47d67540 | 1845 | |
f03fc89f VZ |
1846 | m_hAdjust = gtk_range_get_adjustment( GTK_RANGE(scrolledWindow->hscrollbar) ); |
1847 | m_vAdjust = gtk_range_get_adjustment( GTK_RANGE(scrolledWindow->vscrollbar) ); | |
47d67540 | 1848 | |
38c7b3d3 RR |
1849 | m_wxwindow = gtk_myfixed_new(); |
1850 | ||
2e563988 RR |
1851 | #ifdef __WXDEBUG__ |
1852 | debug_focus_in( m_wxwindow, _T("wxWindow::m_wxwindow"), name ); | |
1853 | #endif | |
1854 | ||
034be888 | 1855 | gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); |
58dea4b0 | 1856 | |
034be888 RR |
1857 | #if (GTK_MINOR_VERSION > 0) |
1858 | GtkMyFixed *myfixed = GTK_MYFIXED(m_wxwindow); | |
b292e2f5 | 1859 | |
f03fc89f | 1860 | if (HasFlag(wxRAISED_BORDER)) |
034be888 RR |
1861 | { |
1862 | gtk_myfixed_set_shadow_type( myfixed, GTK_SHADOW_OUT ); | |
1863 | } | |
f03fc89f | 1864 | else if (HasFlag(wxSUNKEN_BORDER)) |
034be888 RR |
1865 | { |
1866 | gtk_myfixed_set_shadow_type( myfixed, GTK_SHADOW_IN ); | |
1867 | } | |
1868 | else | |
1869 | { | |
1870 | gtk_myfixed_set_shadow_type( myfixed, GTK_SHADOW_NONE ); | |
1871 | } | |
f03fc89f VZ |
1872 | #else // GTK_MINOR_VERSION == 0 |
1873 | GtkViewport *viewport = GTK_VIEWPORT(scrolledWindow->viewport); | |
b292e2f5 | 1874 | |
f03fc89f | 1875 | if (HasFlag(wxRAISED_BORDER)) |
e380f72b RR |
1876 | { |
1877 | gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_OUT ); | |
1878 | } | |
f03fc89f | 1879 | else if (HasFlag(wxSUNKEN_BORDER)) |
e380f72b RR |
1880 | { |
1881 | gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_IN ); | |
1882 | } | |
1883 | else | |
1884 | { | |
1885 | gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE ); | |
1886 | } | |
f03fc89f | 1887 | #endif // GTK_MINOR_VERSION |
47d67540 | 1888 | |
f03fc89f | 1889 | if (HasFlag(wxTAB_TRAVERSAL)) |
b292e2f5 | 1890 | { |
f03fc89f VZ |
1891 | /* we now allow a window to get the focus as long as it |
1892 | doesn't have any children. */ | |
ff8bfdbb | 1893 | GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); |
b292e2f5 RR |
1894 | m_acceptsFocus = FALSE; |
1895 | } | |
e380f72b | 1896 | else |
b292e2f5 | 1897 | { |
e380f72b | 1898 | GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); |
b292e2f5 RR |
1899 | m_acceptsFocus = TRUE; |
1900 | } | |
ca298c88 | 1901 | |
034be888 | 1902 | #if (GTK_MINOR_VERSION == 0) |
e380f72b RR |
1903 | // shut the viewport up |
1904 | gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ); | |
1905 | gtk_viewport_set_vadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ); | |
f03fc89f | 1906 | #endif // GTK_MINOR_VERSION == 0 |
e380f72b RR |
1907 | |
1908 | // I _really_ don't want scrollbars in the beginning | |
a2053b27 RR |
1909 | m_vAdjust->lower = 0.0; |
1910 | m_vAdjust->upper = 1.0; | |
1911 | m_vAdjust->value = 0.0; | |
1912 | m_vAdjust->step_increment = 1.0; | |
1913 | m_vAdjust->page_increment = 1.0; | |
1914 | m_vAdjust->page_size = 5.0; | |
1915 | gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" ); | |
1916 | m_hAdjust->lower = 0.0; | |
1917 | m_hAdjust->upper = 1.0; | |
1918 | m_hAdjust->value = 0.0; | |
1919 | m_hAdjust->step_increment = 1.0; | |
1920 | m_hAdjust->page_increment = 1.0; | |
1921 | m_hAdjust->page_size = 5.0; | |
1922 | gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" ); | |
f03fc89f VZ |
1923 | |
1924 | // these handlers block mouse events to any window during scrolling such as | |
1925 | // motion events and prevent GTK and wxWindows from fighting over where the | |
1926 | // slider should be | |
1927 | ||
1928 | gtk_signal_connect( GTK_OBJECT(scrolledWindow->vscrollbar), "button_press_event", | |
76ed8f8d RR |
1929 | (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this ); |
1930 | ||
f03fc89f | 1931 | gtk_signal_connect( GTK_OBJECT(scrolledWindow->hscrollbar), "button_press_event", |
76ed8f8d RR |
1932 | (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this ); |
1933 | ||
f03fc89f | 1934 | gtk_signal_connect( GTK_OBJECT(scrolledWindow->vscrollbar), "button_release_event", |
76ed8f8d RR |
1935 | (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this ); |
1936 | ||
f03fc89f | 1937 | gtk_signal_connect( GTK_OBJECT(scrolledWindow->hscrollbar), "button_release_event", |
76ed8f8d | 1938 | (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this ); |
8bbe427f | 1939 | |
034be888 | 1940 | // these handlers get notified when screen updates are required either when |
76ed8f8d RR |
1941 | // scrolling or when the window size (and therefore scrollbar configuration) |
1942 | // has changed | |
1943 | ||
1944 | gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed", | |
1945 | (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this ); | |
1946 | gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed", | |
1947 | (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this ); | |
1948 | ||
1949 | gtk_signal_connect( GTK_OBJECT(m_hAdjust), "changed", | |
1950 | (GtkSignalFunc) gtk_window_hscroll_change_callback, (gpointer) this ); | |
1951 | gtk_signal_connect(GTK_OBJECT(m_vAdjust), "changed", | |
1952 | (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this ); | |
1953 | ||
f03fc89f | 1954 | gtk_widget_show( m_wxwindow ); |
47d67540 | 1955 | |
f03fc89f VZ |
1956 | if (m_parent) |
1957 | m_parent->DoAddChild( this ); | |
8bbe427f | 1958 | |
e380f72b | 1959 | PostCreation(); |
8bbe427f | 1960 | |
e380f72b | 1961 | Show( TRUE ); |
c801d85f | 1962 | |
e380f72b | 1963 | return TRUE; |
362c6693 | 1964 | } |
c801d85f | 1965 | |
68dda785 | 1966 | wxWindow::~wxWindow() |
c801d85f | 1967 | { |
31c6b4fc | 1968 | m_isBeingDeleted = TRUE; |
43a18898 | 1969 | m_hasVMT = FALSE; |
47d67540 | 1970 | |
f03fc89f VZ |
1971 | if (m_widget) |
1972 | Show( FALSE ); | |
8bbe427f | 1973 | |
a2053b27 RR |
1974 | DestroyChildren(); |
1975 | ||
f03fc89f VZ |
1976 | if (m_parent) |
1977 | m_parent->RemoveChild( this ); | |
c801d85f | 1978 | |
f03fc89f | 1979 | if (m_widgetStyle) |
a2053b27 | 1980 | { |
f03fc89f | 1981 | gtk_style_unref( m_widgetStyle ); |
c50f1fb9 | 1982 | m_widgetStyle = (GtkStyle*) NULL; |
a2053b27 | 1983 | } |
c801d85f | 1984 | |
f03fc89f | 1985 | if (m_scrollGC) |
a2053b27 | 1986 | { |
f03fc89f | 1987 | gdk_gc_unref( m_scrollGC ); |
c50f1fb9 | 1988 | m_scrollGC = (GdkGC*) NULL; |
a2053b27 | 1989 | } |
47d67540 | 1990 | |
f03fc89f | 1991 | if (m_wxwindow) |
a2053b27 | 1992 | { |
f03fc89f | 1993 | gtk_widget_destroy( m_wxwindow ); |
c50f1fb9 | 1994 | m_wxwindow = (GtkWidget*) NULL; |
a2053b27 | 1995 | } |
8bbe427f | 1996 | |
f03fc89f | 1997 | if (m_widget) |
a2053b27 | 1998 | { |
f03fc89f | 1999 | gtk_widget_destroy( m_widget ); |
c50f1fb9 | 2000 | m_widget = (GtkWidget*) NULL; |
a2053b27 | 2001 | } |
362c6693 | 2002 | } |
c801d85f | 2003 | |
f03fc89f VZ |
2004 | void wxWindow::PreCreation( wxWindow *parent, |
2005 | wxWindowID id, | |
2006 | const wxPoint &pos, | |
2007 | const wxSize &size, | |
2008 | long style, | |
2009 | const wxString &name ) | |
c801d85f | 2010 | { |
f03fc89f | 2011 | wxASSERT_MSG( !m_needParent || parent, _T("Need complete parent.") ); |
8bbe427f | 2012 | |
f03fc89f VZ |
2013 | if ( !CreateBase(parent, id, pos, size, style, name) ) |
2014 | { | |
2015 | wxFAIL_MSG(_T("window creation failed")); | |
2016 | } | |
8bbe427f | 2017 | |
f03fc89f VZ |
2018 | m_width = WidthDefault(size.x); |
2019 | m_height = HeightDefault(size.y); | |
8bbe427f | 2020 | |
43a18898 RR |
2021 | m_x = (int)pos.x; |
2022 | m_y = (int)pos.y; | |
8bbe427f | 2023 | |
f03fc89f | 2024 | if (!parent) /* some reasonable defaults */ |
6ca41e57 | 2025 | { |
43a18898 RR |
2026 | if (m_x == -1) |
2027 | { | |
2028 | m_x = (gdk_screen_width () - m_width) / 2; | |
2029 | if (m_x < 10) m_x = 10; | |
2030 | } | |
2031 | if (m_y == -1) | |
2032 | { | |
2033 | m_y = (gdk_screen_height () - m_height) / 2; | |
2034 | if (m_y < 10) m_y = 10; | |
2035 | } | |
6ca41e57 | 2036 | } |
c801d85f KB |
2037 | } |
2038 | ||
68dda785 | 2039 | void wxWindow::PostCreation() |
c801d85f | 2040 | { |
05939a81 | 2041 | wxASSERT_MSG( (m_widget != NULL), _T("invalid window") ); |
ca298c88 | 2042 | |
43a18898 RR |
2043 | if (m_wxwindow) |
2044 | { | |
034be888 | 2045 | /* these get reported to wxWindows -> wxPaintEvent */ |
20239453 RR |
2046 | gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event", |
2047 | GTK_SIGNAL_FUNC(gtk_window_expose_callback), (gpointer)this ); | |
47d67540 | 2048 | |
20239453 RR |
2049 | gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw", |
2050 | GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this ); | |
ca298c88 | 2051 | |
ef47f9b3 | 2052 | #if (GTK_MINOR_VERSION > 0) |
f03fc89f | 2053 | /* these are called when the "sunken" or "raised" borders are drawn */ |
034be888 RR |
2054 | gtk_signal_connect( GTK_OBJECT(m_widget), "expose_event", |
2055 | GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this ); | |
2056 | ||
2057 | gtk_signal_connect( GTK_OBJECT(m_widget), "draw", | |
2058 | GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this ); | |
ef47f9b3 | 2059 | #endif |
43a18898 | 2060 | } |
47d67540 | 2061 | |
a2053b27 | 2062 | GtkWidget *connect_widget = GetConnectWidget(); |
f03fc89f | 2063 | |
a2053b27 | 2064 | ConnectWidget( connect_widget ); |
47d67540 | 2065 | |
a2053b27 RR |
2066 | /* we cannot set colours, fonts and cursors before the widget has |
2067 | been realized, so we do this directly after realization */ | |
2068 | gtk_signal_connect( GTK_OBJECT(connect_widget), "realize", | |
c50f1fb9 | 2069 | GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this ); |
ca298c88 | 2070 | |
43a18898 | 2071 | m_hasVMT = TRUE; |
b4071e91 RR |
2072 | } |
2073 | ||
2074 | void wxWindow::ConnectWidget( GtkWidget *widget ) | |
2075 | { | |
43a18898 RR |
2076 | gtk_signal_connect( GTK_OBJECT(widget), "key_press_event", |
2077 | GTK_SIGNAL_FUNC(gtk_window_key_press_callback), (gpointer)this ); | |
c801d85f | 2078 | |
b666df2c RR |
2079 | gtk_signal_connect( GTK_OBJECT(widget), "key_release_event", |
2080 | GTK_SIGNAL_FUNC(gtk_window_key_release_callback), (gpointer)this ); | |
2081 | ||
43a18898 RR |
2082 | gtk_signal_connect( GTK_OBJECT(widget), "button_press_event", |
2083 | GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this ); | |
47d67540 | 2084 | |
43a18898 RR |
2085 | gtk_signal_connect( GTK_OBJECT(widget), "button_release_event", |
2086 | GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this ); | |
47d67540 | 2087 | |
43a18898 RR |
2088 | gtk_signal_connect( GTK_OBJECT(widget), "motion_notify_event", |
2089 | GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this ); | |
47d67540 | 2090 | |
43a18898 RR |
2091 | gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event", |
2092 | GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this ); | |
c801d85f | 2093 | |
43a18898 RR |
2094 | gtk_signal_connect( GTK_OBJECT(widget), "focus_out_event", |
2095 | GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this ); | |
c801d85f | 2096 | |
43a18898 RR |
2097 | gtk_signal_connect( GTK_OBJECT(widget), "enter_notify_event", |
2098 | GTK_SIGNAL_FUNC(gtk_window_enter_callback), (gpointer)this ); | |
47d67540 | 2099 | |
43a18898 RR |
2100 | gtk_signal_connect( GTK_OBJECT(widget), "leave_notify_event", |
2101 | GTK_SIGNAL_FUNC(gtk_window_leave_callback), (gpointer)this ); | |
362c6693 | 2102 | } |
c801d85f | 2103 | |
68dda785 | 2104 | bool wxWindow::Destroy() |
c801d85f | 2105 | { |
05939a81 | 2106 | wxASSERT_MSG( (m_widget != NULL), _T("invalid window") ); |
47d67540 | 2107 | |
43a18898 | 2108 | m_hasVMT = FALSE; |
c801d85f | 2109 | |
f03fc89f | 2110 | return wxWindowBase::Destroy(); |
362c6693 | 2111 | } |
c801d85f | 2112 | |
bfc6fde4 | 2113 | void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags ) |
c801d85f | 2114 | { |
05939a81 OK |
2115 | wxASSERT_MSG( (m_widget != NULL), _T("invalid window") ); |
2116 | wxASSERT_MSG( (m_parent != NULL), _T("wxWindow::SetSize requires parent.\n") ); | |
8bbe427f | 2117 | |
e27ce4e9 | 2118 | if (m_resizing) return; /* I don't like recursions */ |
fb1585ae | 2119 | m_resizing = TRUE; |
47d67540 | 2120 | |
a2053b27 | 2121 | if (m_parent->m_wxwindow == NULL) /* i.e. wxNotebook */ |
fb1585ae | 2122 | { |
e27ce4e9 | 2123 | /* don't set the size for children of wxNotebook, just take the values. */ |
fb1585ae RR |
2124 | m_x = x; |
2125 | m_y = y; | |
2126 | m_width = width; | |
ba4e3652 | 2127 | m_height = height; |
fb1585ae | 2128 | } |
ba4e3652 | 2129 | else |
fb1585ae | 2130 | { |
85ad5eb5 | 2131 | if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0) |
ba4e3652 RR |
2132 | { |
2133 | if (x != -1) m_x = x; | |
2134 | if (y != -1) m_y = y; | |
2135 | if (width != -1) m_width = width; | |
2136 | if (height != -1) m_height = height; | |
2137 | } | |
2138 | else | |
2139 | { | |
2140 | m_x = x; | |
2141 | m_y = y; | |
2142 | m_width = width; | |
2143 | m_height = height; | |
2144 | } | |
47d67540 | 2145 | |
ba4e3652 RR |
2146 | if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) |
2147 | { | |
2148 | if (width == -1) m_width = 80; | |
2149 | } | |
2150 | ||
2151 | if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) | |
2152 | { | |
2153 | if (height == -1) m_height = 26; | |
2154 | } | |
8bbe427f | 2155 | |
ba4e3652 RR |
2156 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; |
2157 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
d3b4d113 RR |
2158 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; |
2159 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
47d67540 | 2160 | |
a2053b27 | 2161 | int border = 0; |
c50f1fb9 | 2162 | int bottom_border = 0; |
f03fc89f | 2163 | |
29f538ce | 2164 | if (GTK_WIDGET_CAN_DEFAULT(m_widget)) |
c50f1fb9 VZ |
2165 | { |
2166 | /* the default button has a border around it */ | |
2167 | border = 6; | |
2168 | bottom_border = 5; | |
2169 | } | |
2170 | ||
2171 | /* this is the result of hours of debugging: the following code | |
2172 | means that if we have a m_wxwindow and we set the size of | |
2173 | m_widget, m_widget (which is a GtkScrolledWindow) does NOT | |
2174 | automatically propagate its size down to its m_wxwindow, | |
2175 | which is its client area. therefore, we have to tell the | |
2176 | client area directly that it has to resize itself. | |
2177 | this will lead to that m_widget (GtkScrolledWindow) will | |
2178 | calculate how much size it needs for scrollbars etc and | |
2179 | it will then call XXX_size_allocate of its child, which | |
2180 | is m_wxwindow. m_wxwindow in turn will do the same with its | |
2181 | children and so on. problems can arise if this happens | |
2182 | before all the children have been realized as some widgets | |
2183 | stupidy need to be realized during XXX_size_allocate (e.g. | |
2184 | GtkNotebook) and they will segv if called otherwise. this | |
2185 | emergency is tested in gtk_myfixed_size_allocate. Normally | |
2186 | this shouldn't be needed and only gtk_widget_queue_resize() | |
2187 | should be enough to provoke a resize at the next appropriate | |
2188 | moment, but this seems to fail, e.g. when a wxNotebook contains | |
2189 | a wxSplitterWindow: the splitter window's children won't | |
2190 | show up properly resized then. */ | |
2191 | ||
2192 | gtk_myfixed_set_size( GTK_MYFIXED(m_parent->m_wxwindow), | |
2193 | m_widget, | |
2194 | m_x-border, | |
2195 | m_y-border, | |
2196 | m_width+2*border, | |
2197 | m_height+border+bottom_border ); | |
ba4e3652 | 2198 | } |
8bbe427f | 2199 | |
fb1585ae | 2200 | m_sizeSet = TRUE; |
47d67540 | 2201 | |
fb1585ae RR |
2202 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); |
2203 | event.SetEventObject( this ); | |
ba4e3652 | 2204 | GetEventHandler()->ProcessEvent( event ); |
47d67540 | 2205 | |
fb1585ae | 2206 | m_resizing = FALSE; |
362c6693 | 2207 | } |
c801d85f | 2208 | |
9390a202 RR |
2209 | void wxWindow::OnInternalIdle() |
2210 | { | |
9146082c RR |
2211 | wxCursor cursor = m_cursor; |
2212 | if (g_globalCursor.Ok()) cursor = g_globalCursor; | |
c50f1fb9 | 2213 | |
9146082c RR |
2214 | if (cursor.Ok() && m_currentGdkCursor != cursor) |
2215 | { | |
d30e0edd RR |
2216 | m_currentGdkCursor = cursor; |
2217 | ||
9146082c | 2218 | if (m_wxwindow) |
6a008b33 | 2219 | { |
9146082c | 2220 | GdkWindow *window = m_wxwindow->window; |
6a008b33 | 2221 | if (window) |
c50f1fb9 | 2222 | gdk_window_set_cursor( window, cursor.GetCursor() ); |
6a008b33 VZ |
2223 | |
2224 | if (!g_globalCursor.Ok()) | |
2225 | cursor = *wxSTANDARD_CURSOR; | |
2226 | ||
2227 | window = m_widget->window; | |
2228 | if (window) | |
9146082c | 2229 | gdk_window_set_cursor( window, cursor.GetCursor() ); |
6a008b33 VZ |
2230 | } |
2231 | else | |
2232 | { | |
9146082c | 2233 | GdkWindow *window = m_widget->window; |
6a008b33 | 2234 | if (window) |
9146082c | 2235 | gdk_window_set_cursor( window, cursor.GetCursor() ); |
6a008b33 | 2236 | } |
9146082c | 2237 | } |
6a008b33 | 2238 | |
9390a202 RR |
2239 | UpdateWindowUI(); |
2240 | } | |
2241 | ||
f03fc89f | 2242 | void wxWindow::DoGetSize( int *width, int *height ) const |
c801d85f | 2243 | { |
05939a81 | 2244 | wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); |
47d67540 | 2245 | |
fb1585ae RR |
2246 | if (width) (*width) = m_width; |
2247 | if (height) (*height) = m_height; | |
362c6693 | 2248 | } |
c801d85f | 2249 | |
bfc6fde4 | 2250 | void wxWindow::DoSetClientSize( int width, int height ) |
c801d85f | 2251 | { |
05939a81 | 2252 | wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); |
47d67540 | 2253 | |
1ecc4d80 | 2254 | if (!m_wxwindow) |
c801d85f | 2255 | { |
1ecc4d80 | 2256 | SetSize( width, height ); |
c801d85f KB |
2257 | } |
2258 | else | |
2259 | { | |
1ecc4d80 RR |
2260 | int dw = 0; |
2261 | int dh = 0; | |
2262 | ||
034be888 | 2263 | #if (GTK_MINOR_VERSION == 0) |
98d3fdbe RR |
2264 | if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER)) |
2265 | { | |
324dbfec RR |
2266 | if (HasScrolling()) |
2267 | { | |
2268 | GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget); | |
2269 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); | |
2270 | ||
2271 | GtkWidget *viewport = scroll_window->viewport; | |
2272 | GtkStyleClass *viewport_class = viewport->style->klass; | |
2273 | ||
2274 | dw += 2 * viewport_class->xthickness; | |
2275 | dh += 2 * viewport_class->ythickness; | |
2276 | } | |
98d3fdbe RR |
2277 | } |
2278 | #else | |
2279 | if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER)) | |
2280 | { | |
6a008b33 VZ |
2281 | /* when using GTK 1.2 we set the border size to 2 */ |
2282 | dw += 2 * 2; | |
98d3fdbe RR |
2283 | dh += 2 * 2; |
2284 | } | |
034be888 RR |
2285 | #endif |
2286 | ||
98d3fdbe RR |
2287 | if (HasScrolling()) |
2288 | { | |
034be888 RR |
2289 | /* |
2290 | GtkWidget *hscrollbar = scroll_window->hscrollbar; | |
2291 | GtkWidget *vscrollbar = scroll_window->vscrollbar; | |
ca298c88 | 2292 | |
f03fc89f | 2293 | we use this instead: range.slider_width = 11 + 2*2pts edge |
034be888 | 2294 | */ |
47d67540 | 2295 | |
324dbfec RR |
2296 | GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget); |
2297 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); | |
2298 | ||
1ecc4d80 RR |
2299 | if (scroll_window->vscrollbar_visible) |
2300 | { | |
034be888 | 2301 | dw += 15; /* dw += vscrollbar->allocation.width; */ |
1ecc4d80 RR |
2302 | dw += scroll_class->scrollbar_spacing; |
2303 | } | |
2304 | ||
2305 | if (scroll_window->hscrollbar_visible) | |
2306 | { | |
034be888 | 2307 | dh += 15; /* dh += hscrollbar->allocation.height; */ |
63cc5d9d | 2308 | dh += scroll_class->scrollbar_spacing; |
1ecc4d80 RR |
2309 | } |
2310 | } | |
2311 | ||
034be888 | 2312 | SetSize( width+dw, height+dh ); |
1ecc4d80 | 2313 | } |
362c6693 | 2314 | } |
c801d85f | 2315 | |
f03fc89f | 2316 | void wxWindow::DoGetClientSize( int *width, int *height ) const |
c801d85f | 2317 | { |
05939a81 | 2318 | wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); |
47d67540 | 2319 | |
1ecc4d80 RR |
2320 | if (!m_wxwindow) |
2321 | { | |
2322 | if (width) (*width) = m_width; | |
2323 | if (height) (*height) = m_height; | |
c801d85f KB |
2324 | } |
2325 | else | |
2326 | { | |
1ecc4d80 RR |
2327 | int dw = 0; |
2328 | int dh = 0; | |
2329 | ||
034be888 | 2330 | #if (GTK_MINOR_VERSION == 0) |
98d3fdbe RR |
2331 | if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER)) |
2332 | { | |
6a008b33 VZ |
2333 | if (HasScrolling()) |
2334 | { | |
2335 | GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget); | |
2336 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); | |
2337 | ||
2338 | GtkWidget *viewport = scroll_window->viewport; | |
2339 | GtkStyleClass *viewport_class = viewport->style->klass; | |
2340 | ||
2341 | dw += 2 * viewport_class->xthickness; | |
2342 | dh += 2 * viewport_class->ythickness; | |
2343 | } | |
98d3fdbe RR |
2344 | } |
2345 | #else | |
2346 | if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER)) | |
2347 | { | |
6a008b33 VZ |
2348 | /* when using GTK 1.2 we set the border size to 2 */ |
2349 | dw += 2 * 2; | |
98d3fdbe RR |
2350 | dh += 2 * 2; |
2351 | } | |
034be888 | 2352 | #endif |
98d3fdbe RR |
2353 | if (HasScrolling()) |
2354 | { | |
034be888 RR |
2355 | /* |
2356 | GtkWidget *hscrollbar = scroll_window->hscrollbar; | |
2357 | GtkWidget *vscrollbar = scroll_window->vscrollbar; | |
ca298c88 | 2358 | |
f03fc89f | 2359 | we use this instead: range.slider_width = 11 + 2*2pts edge |
034be888 | 2360 | */ |
1ecc4d80 | 2361 | |
6a008b33 VZ |
2362 | GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget); |
2363 | GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); | |
2364 | ||
1ecc4d80 RR |
2365 | if (scroll_window->vscrollbar_visible) |
2366 | { | |
034be888 | 2367 | dw += 15; /* dw += vscrollbar->allocation.width; */ |
1ecc4d80 RR |
2368 | dw += scroll_class->scrollbar_spacing; |
2369 | } | |
2370 | ||
2371 | if (scroll_window->hscrollbar_visible) | |
2372 | { | |
034be888 | 2373 | dh += 15; /* dh += hscrollbar->allocation.height; */ |
1ecc4d80 RR |
2374 | dh += scroll_class->scrollbar_spacing; |
2375 | } | |
6a008b33 | 2376 | } |
47d67540 | 2377 | |
1ecc4d80 RR |
2378 | if (width) (*width) = m_width - dw; |
2379 | if (height) (*height) = m_height - dh; | |
2380 | } | |
362c6693 | 2381 | } |
c801d85f | 2382 | |
f03fc89f | 2383 | void wxWindow::DoGetPosition( int *x, int *y ) const |
c801d85f | 2384 | { |
05939a81 | 2385 | wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); |
47d67540 | 2386 | |
43a18898 RR |
2387 | if (x) (*x) = m_x; |
2388 | if (y) (*y) = m_y; | |
362c6693 | 2389 | } |
c801d85f | 2390 | |
dabc0cd5 | 2391 | void wxWindow::DoClientToScreen( int *x, int *y ) const |
c801d85f | 2392 | { |
05939a81 | 2393 | wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); |
47d67540 | 2394 | |
a2053b27 RR |
2395 | if (!m_widget->window) return; |
2396 | ||
43a18898 RR |
2397 | GdkWindow *source = (GdkWindow *) NULL; |
2398 | if (m_wxwindow) | |
2399 | source = m_wxwindow->window; | |
2400 | else | |
2401 | source = m_widget->window; | |
47d67540 | 2402 | |
43a18898 RR |
2403 | int org_x = 0; |
2404 | int org_y = 0; | |
2405 | gdk_window_get_origin( source, &org_x, &org_y ); | |
c801d85f | 2406 | |
43a18898 | 2407 | if (!m_wxwindow) |
c801d85f | 2408 | { |
43a18898 RR |
2409 | if (GTK_WIDGET_NO_WINDOW (m_widget)) |
2410 | { | |
2411 | org_x += m_widget->allocation.x; | |
2412 | org_y += m_widget->allocation.y; | |
2413 | } | |
362c6693 | 2414 | } |
47d67540 | 2415 | |
43a18898 RR |
2416 | if (x) *x += org_x; |
2417 | if (y) *y += org_y; | |
362c6693 | 2418 | } |
c801d85f | 2419 | |
dabc0cd5 | 2420 | void wxWindow::DoScreenToClient( int *x, int *y ) const |
c801d85f | 2421 | { |
05939a81 | 2422 | wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); |
47d67540 | 2423 | |
a2053b27 RR |
2424 | if (!m_widget->window) return; |
2425 | ||
1ecc4d80 RR |
2426 | GdkWindow *source = (GdkWindow *) NULL; |
2427 | if (m_wxwindow) | |
2428 | source = m_wxwindow->window; | |
2429 | else | |
2430 | source = m_widget->window; | |
47d67540 | 2431 | |
1ecc4d80 RR |
2432 | int org_x = 0; |
2433 | int org_y = 0; | |
2434 | gdk_window_get_origin( source, &org_x, &org_y ); | |
c801d85f | 2435 | |
1ecc4d80 | 2436 | if (!m_wxwindow) |
c801d85f | 2437 | { |
1ecc4d80 RR |
2438 | if (GTK_WIDGET_NO_WINDOW (m_widget)) |
2439 | { | |
2440 | org_x += m_widget->allocation.x; | |
2441 | org_y += m_widget->allocation.y; | |
2442 | } | |
362c6693 | 2443 | } |
47d67540 | 2444 | |
1ecc4d80 RR |
2445 | if (x) *x -= org_x; |
2446 | if (y) *y -= org_y; | |
362c6693 | 2447 | } |
c801d85f | 2448 | |
f03fc89f | 2449 | bool wxWindow::Show( bool show ) |
c801d85f | 2450 | { |
f03fc89f | 2451 | wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") ); |
47d67540 | 2452 | |
739730ca RR |
2453 | if (!wxWindowBase::Show(show)) |
2454 | { | |
2455 | // nothing to do | |
f03fc89f | 2456 | return FALSE; |
739730ca | 2457 | } |
8bbe427f | 2458 | |
f03fc89f VZ |
2459 | if (show) |
2460 | gtk_widget_show( m_widget ); | |
1ecc4d80 | 2461 | else |
f03fc89f | 2462 | gtk_widget_hide( m_widget ); |
8bbe427f | 2463 | |
f03fc89f | 2464 | return TRUE; |
362c6693 | 2465 | } |
c801d85f | 2466 | |
f03fc89f | 2467 | bool wxWindow::Enable( bool enable ) |
c801d85f | 2468 | { |
f03fc89f | 2469 | wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") ); |
5e0aa05a | 2470 | |
739730ca RR |
2471 | if (!wxWindowBase::Enable(enable)) |
2472 | { | |
2473 | // nothing to do | |
f03fc89f | 2474 | return FALSE; |
739730ca | 2475 | } |
1ecc4d80 | 2476 | |
f03fc89f VZ |
2477 | gtk_widget_set_sensitive( m_widget, enable ); |
2478 | if ( m_wxwindow ) | |
2479 | gtk_widget_set_sensitive( m_wxwindow, enable ); | |
ff8bfdbb | 2480 | |
f03fc89f | 2481 | return TRUE; |
362c6693 | 2482 | } |
c801d85f | 2483 | |
f03fc89f | 2484 | int wxWindow::GetCharHeight() const |
2f2aa628 | 2485 | { |
f03fc89f | 2486 | wxCHECK_MSG( (m_widget != NULL), 12, _T("invalid window") ); |
47d67540 | 2487 | |
f03fc89f | 2488 | wxCHECK_MSG( m_font.Ok(), 12, _T("invalid font") ); |
2f2aa628 | 2489 | |
f03fc89f VZ |
2490 | GdkFont *font = m_font.GetInternalFont( 1.0 ); |
2491 | ||
2492 | return font->ascent + font->descent; | |
362c6693 | 2493 | } |
c801d85f | 2494 | |
f03fc89f | 2495 | int wxWindow::GetCharWidth() const |
c33c4050 | 2496 | { |
05939a81 | 2497 | wxCHECK_MSG( (m_widget != NULL), 8, _T("invalid window") ); |
47d67540 | 2498 | |
05939a81 | 2499 | wxCHECK_MSG( m_font.Ok(), 8, _T("invalid font") ); |
47d67540 | 2500 | |
463c1fa1 | 2501 | GdkFont *font = m_font.GetInternalFont( 1.0 ); |
ff8bfdbb | 2502 | |
463c1fa1 | 2503 | return gdk_string_width( font, "H" ); |
c33c4050 RR |
2504 | } |
2505 | ||
f03fc89f VZ |
2506 | void wxWindow::GetTextExtent( const wxString& string, |
2507 | int *x, | |
2508 | int *y, | |
2509 | int *descent, | |
2510 | int *externalLeading, | |
2511 | const wxFont *theFont ) const | |
c33c4050 | 2512 | { |
463c1fa1 RR |
2513 | wxFont fontToUse = m_font; |
2514 | if (theFont) fontToUse = *theFont; | |
47d67540 | 2515 | |
05939a81 | 2516 | wxCHECK_RET( fontToUse.Ok(), _T("invalid font") ); |
47d67540 | 2517 | |
463c1fa1 | 2518 | GdkFont *font = fontToUse.GetInternalFont( 1.0 ); |
05939a81 | 2519 | if (x) (*x) = gdk_string_width( font, string.mbc_str() ); |
463c1fa1 RR |
2520 | if (y) (*y) = font->ascent + font->descent; |
2521 | if (descent) (*descent) = font->descent; | |
2522 | if (externalLeading) (*externalLeading) = 0; // ?? | |
c33c4050 RR |
2523 | } |
2524 | ||
68dda785 | 2525 | void wxWindow::SetFocus() |
c801d85f | 2526 | { |
05939a81 | 2527 | wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); |
ff8bfdbb | 2528 | |
463c1fa1 RR |
2529 | GtkWidget *connect_widget = GetConnectWidget(); |
2530 | if (connect_widget) | |
c801d85f | 2531 | { |
b292e2f5 | 2532 | if (GTK_WIDGET_CAN_FOCUS(connect_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ ) |
463c1fa1 RR |
2533 | { |
2534 | gtk_widget_grab_focus (connect_widget); | |
2535 | } | |
ff8bfdbb VZ |
2536 | else if (GTK_IS_CONTAINER(connect_widget)) |
2537 | { | |
2538 | gtk_container_focus( GTK_CONTAINER(connect_widget), GTK_DIR_TAB_FORWARD ); | |
2539 | } | |
2540 | else | |
2541 | { | |
2542 | } | |
362c6693 | 2543 | } |
362c6693 | 2544 | } |
c801d85f | 2545 | |
b292e2f5 RR |
2546 | bool wxWindow::AcceptsFocus() const |
2547 | { | |
f03fc89f | 2548 | return m_acceptsFocus && wxWindowBase::AcceptsFocus(); |
b292e2f5 RR |
2549 | } |
2550 | ||
f03fc89f | 2551 | bool wxWindow::Reparent( wxWindow *newParent ) |
463c1fa1 | 2552 | { |
c693edf3 | 2553 | wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") ); |
c50f1fb9 | 2554 | |
8ce63e9d | 2555 | wxWindow *oldParent = m_parent; |
a2053b27 | 2556 | |
f03fc89f VZ |
2557 | if ( !wxWindowBase::Reparent(newParent) ) |
2558 | return FALSE; | |
8bbe427f | 2559 | |
8ce63e9d RR |
2560 | if (oldParent) |
2561 | { | |
2562 | gtk_container_remove( GTK_CONTAINER(oldParent->m_wxwindow), m_widget ); | |
2563 | } | |
c50f1fb9 | 2564 | |
8ce63e9d RR |
2565 | if (newParent) |
2566 | { | |
2567 | /* insert GTK representation */ | |
2568 | (*(newParent->m_insertCallback))(newParent, this); | |
2569 | } | |
c50f1fb9 | 2570 | |
f03fc89f | 2571 | return TRUE; |
362c6693 | 2572 | } |
c801d85f | 2573 | |
c50f1fb9 | 2574 | void wxWindow::DoAddChild(wxWindow *child) |
ddb6bc71 RR |
2575 | { |
2576 | wxASSERT_MSG( (m_widget != NULL), _T("invalid window") ); | |
2577 | ||
2578 | wxASSERT_MSG( (child != NULL), _T("invalid child window") ); | |
2579 | ||
2580 | wxASSERT_MSG( (m_insertCallback != NULL), _T("invalid child insertion function") ); | |
c50f1fb9 | 2581 | |
ddb6bc71 RR |
2582 | /* add to list */ |
2583 | AddChild( child ); | |
c50f1fb9 | 2584 | |
ddb6bc71 RR |
2585 | /* insert GTK representation */ |
2586 | (*m_insertCallback)(this, child); | |
2587 | } | |
2588 | ||
68dda785 | 2589 | void wxWindow::Raise() |
362c6693 | 2590 | { |
05939a81 | 2591 | wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); |
47d67540 | 2592 | |
a2053b27 RR |
2593 | if (!m_widget->window) return; |
2594 | ||
f03fc89f | 2595 | gdk_window_raise( m_widget->window ); |
362c6693 RR |
2596 | } |
2597 | ||
68dda785 | 2598 | void wxWindow::Lower() |
362c6693 | 2599 | { |
05939a81 | 2600 | wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); |
47d67540 | 2601 | |
a2053b27 RR |
2602 | if (!m_widget->window) return; |
2603 | ||
f03fc89f | 2604 | gdk_window_lower( m_widget->window ); |
362c6693 | 2605 | } |
c801d85f | 2606 | |
f03fc89f | 2607 | bool wxWindow::SetCursor( const wxCursor &cursor ) |
86b29a61 | 2608 | { |
f03fc89f | 2609 | wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") ); |
86b29a61 | 2610 | |
739730ca | 2611 | if (!wxWindowBase::SetCursor(cursor)) |
e55ad60e | 2612 | { |
739730ca RR |
2613 | // don't leave if the GTK widget has just |
2614 | // been realized | |
2615 | if (!m_delayedCursor) return FALSE; | |
2616 | } | |
c50f1fb9 | 2617 | |
739730ca RR |
2618 | GtkWidget *connect_widget = GetConnectWidget(); |
2619 | if (!connect_widget->window) | |
2620 | { | |
2621 | // indicate that a new style has been set | |
c50f1fb9 VZ |
2622 | // but it couldn't get applied as the |
2623 | // widget hasn't been realized yet. | |
2624 | m_delayedCursor = TRUE; | |
2625 | ||
2626 | // pretend we have done something | |
739730ca RR |
2627 | return TRUE; |
2628 | } | |
a2053b27 | 2629 | |
238d735d | 2630 | // gdk_window_set_cursor( connect_widget->window, GetCursor().GetCursor() ); |
fd0eed64 | 2631 | |
739730ca RR |
2632 | // cursor was set |
2633 | return TRUE; | |
362c6693 | 2634 | } |
c801d85f | 2635 | |
85eb36c2 | 2636 | void wxWindow::WarpPointer( int x, int y ) |
4f22cf8d | 2637 | { |
85eb36c2 RR |
2638 | wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); |
2639 | ||
2640 | GtkWidget *connect_widget = GetConnectWidget(); | |
2641 | if (connect_widget->window) | |
2642 | { | |
2643 | /* we provide this function ourselves as it is | |
c50f1fb9 | 2644 | missing in GDK */ |
85eb36c2 RR |
2645 | gdk_window_warp_pointer( connect_widget->window, x, y ); |
2646 | } | |
4f22cf8d RR |
2647 | } |
2648 | ||
debe6624 | 2649 | void wxWindow::Refresh( bool eraseBackground, const wxRect *rect ) |
c801d85f | 2650 | { |
05939a81 | 2651 | wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); |
47d67540 | 2652 | |
a2053b27 RR |
2653 | if (!m_widget->window) return; |
2654 | ||
139adb6a | 2655 | if (eraseBackground && m_wxwindow && m_wxwindow->window) |
c801d85f | 2656 | { |
139adb6a RR |
2657 | if (rect) |
2658 | { | |
2659 | gdk_window_clear_area( m_wxwindow->window, | |
2660 | rect->x, rect->y, | |
f234c60c | 2661 | rect->width, rect->height ); |
139adb6a RR |
2662 | } |
2663 | else | |
2664 | { | |
f234c60c | 2665 | gdk_window_clear( m_wxwindow->window ); |
139adb6a RR |
2666 | } |
2667 | } | |
ff8bfdbb | 2668 | |
139adb6a RR |
2669 | if (!rect) |
2670 | { | |
2671 | if (m_wxwindow) | |
2672 | gtk_widget_draw( m_wxwindow, (GdkRectangle*) NULL ); | |
ff8bfdbb | 2673 | else |
139adb6a | 2674 | gtk_widget_draw( m_widget, (GdkRectangle*) NULL ); |
362c6693 | 2675 | } |
c801d85f | 2676 | else |
139adb6a RR |
2677 | { |
2678 | GdkRectangle gdk_rect; | |
2679 | gdk_rect.x = rect->x; | |
2680 | gdk_rect.y = rect->y; | |
2681 | gdk_rect.width = rect->width; | |
2682 | gdk_rect.height = rect->height; | |
2683 | ||
2684 | if (m_wxwindow) | |
2685 | gtk_widget_draw( m_wxwindow, &gdk_rect ); | |
2686 | else | |
2687 | gtk_widget_draw( m_widget, &gdk_rect ); | |
2688 | } | |
362c6693 | 2689 | } |
c801d85f | 2690 | |
68dda785 | 2691 | void wxWindow::Clear() |
c801d85f | 2692 | { |
05939a81 | 2693 | wxCHECK_RET( m_widget != NULL, _T("invalid window") ); |
47d67540 | 2694 | |
a2053b27 RR |
2695 | if (!m_widget->window) return; |
2696 | ||
f234c60c RR |
2697 | if (m_wxwindow && m_wxwindow->window) |
2698 | { | |
2699 | gdk_window_clear( m_wxwindow->window ); | |
2700 | } | |
362c6693 | 2701 | } |
c801d85f | 2702 | |
ff8bfdbb | 2703 | #if wxUSE_TOOLTIPS |
f03fc89f | 2704 | void wxWindow::DoSetToolTip( wxToolTip *tip ) |
b1170810 | 2705 | { |
f03fc89f | 2706 | wxWindowBase::DoSetToolTip(tip); |
ff8bfdbb | 2707 | |
f03fc89f VZ |
2708 | if (m_tooltip) |
2709 | m_tooltip->Apply( this ); | |
b1170810 RR |
2710 | } |
2711 | ||
05939a81 | 2712 | void wxWindow::ApplyToolTip( GtkTooltips *tips, const wxChar *tip ) |
b1170810 | 2713 | { |
dcf924a3 | 2714 | gtk_tooltips_set_tip( tips, GetConnectWidget(), wxConvCurrent->cWX2MB(tip), (gchar*) NULL ); |
301cd871 | 2715 | } |
ff8bfdbb | 2716 | #endif // wxUSE_TOOLTIPS |
b1170810 | 2717 | |
f03fc89f | 2718 | bool wxWindow::SetBackgroundColour( const wxColour &colour ) |
c801d85f | 2719 | { |
f03fc89f | 2720 | wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") ); |
8bbe427f | 2721 | |
739730ca RR |
2722 | if (!wxWindowBase::SetBackgroundColour(colour)) |
2723 | { | |
2724 | // don't leave if the GTK widget has just | |
2725 | // been realized | |
2726 | if (!m_delayedBackgroundColour) return FALSE; | |
2727 | } | |
c50f1fb9 | 2728 | |
a2053b27 | 2729 | GtkWidget *connect_widget = GetConnectWidget(); |
739730ca RR |
2730 | if (!connect_widget->window) |
2731 | { | |
2732 | // indicate that a new style has been set | |
c50f1fb9 VZ |
2733 | // but it couldn't get applied as the |
2734 | // widget hasn't been realized yet. | |
2735 | m_delayedBackgroundColour = TRUE; | |
2736 | ||
2737 | // pretend we have done something | |
739730ca RR |
2738 | return TRUE; |
2739 | } | |
ca298c88 | 2740 | |
f234c60c | 2741 | if (m_wxwindow && m_wxwindow->window) |
3bc755fc | 2742 | { |
a2053b27 RR |
2743 | /* wxMSW doesn't clear the window here. I don't do that either to |
2744 | provide compatibility. call Clear() to do the job. */ | |
ca298c88 | 2745 | |
f234c60c RR |
2746 | m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_wxwindow->window ) ); |
2747 | gdk_window_set_background( m_wxwindow->window, m_backgroundColour.GetColor() ); | |
3bc755fc | 2748 | } |
8bbe427f | 2749 | |
ae0bdb01 | 2750 | wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ); |
121a3581 | 2751 | if (sysbg == m_backgroundColour) |
ae0bdb01 RR |
2752 | { |
2753 | m_backgroundColour = wxNullColour; | |
2754 | ApplyWidgetStyle(); | |
ff8bfdbb VZ |
2755 | m_backgroundColour = sysbg; |
2756 | } | |
ae0bdb01 RR |
2757 | else |
2758 | { | |
2759 | ApplyWidgetStyle(); | |
2760 | } | |
c801d85f | 2761 | |
f03fc89f | 2762 | return TRUE; |
6de97a3b RR |
2763 | } |
2764 | ||
f03fc89f | 2765 | bool wxWindow::SetForegroundColour( const wxColour &colour ) |
6de97a3b | 2766 | { |
f03fc89f | 2767 | wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") ); |
8bbe427f | 2768 | |
739730ca RR |
2769 | if (!wxWindowBase::SetForegroundColour(colour)) |
2770 | { | |
2771 | // don't leave if the GTK widget has just | |
2772 | // been realized | |
2773 | if (!m_delayedForegroundColour) return FALSE; | |
2774 | } | |
c50f1fb9 | 2775 | |
a2053b27 | 2776 | GtkWidget *connect_widget = GetConnectWidget(); |
739730ca RR |
2777 | if (!connect_widget->window) |
2778 | { | |
2779 | // indicate that a new style has been set | |
c50f1fb9 VZ |
2780 | // but it couldn't get applied as the |
2781 | // widget hasn't been realized yet. | |
2782 | m_delayedForegroundColour = TRUE; | |
2783 | ||
2784 | // pretend we have done something | |
739730ca RR |
2785 | return TRUE; |
2786 | } | |
2b07d713 | 2787 | |
ae0bdb01 | 2788 | wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ); |
2b62ab35 | 2789 | if ( sysbg == m_backgroundColour ) |
ae0bdb01 RR |
2790 | { |
2791 | m_backgroundColour = wxNullColour; | |
2792 | ApplyWidgetStyle(); | |
ff8bfdbb VZ |
2793 | m_backgroundColour = sysbg; |
2794 | } | |
ae0bdb01 RR |
2795 | else |
2796 | { | |
2797 | ApplyWidgetStyle(); | |
2798 | } | |
f03fc89f VZ |
2799 | |
2800 | return TRUE; | |
58614078 RR |
2801 | } |
2802 | ||
2803 | GtkStyle *wxWindow::GetWidgetStyle() | |
2804 | { | |
1ecc4d80 | 2805 | if (m_widgetStyle) gtk_style_unref( m_widgetStyle ); |
8bbe427f | 2806 | |
f03fc89f | 2807 | m_widgetStyle = gtk_style_copy( gtk_widget_get_style( m_widget ) ); |
8bbe427f | 2808 | |
1ecc4d80 | 2809 | return m_widgetStyle; |
58614078 RR |
2810 | } |
2811 | ||
2812 | void wxWindow::SetWidgetStyle() | |
2813 | { | |
1ecc4d80 RR |
2814 | GtkStyle *style = GetWidgetStyle(); |
2815 | ||
2816 | gdk_font_unref( style->font ); | |
2817 | style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) ); | |
2818 | ||
2819 | if (m_foregroundColour.Ok()) | |
2820 | { | |
2821 | m_foregroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) ); | |
2822 | style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor(); | |
2823 | style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor(); | |
2824 | style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor(); | |
2825 | } | |
2826 | ||
2827 | if (m_backgroundColour.Ok()) | |
2828 | { | |
2829 | m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) ); | |
2830 | style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); | |
2831 | style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); | |
2832 | style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); | |
2833 | style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); | |
2834 | style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); | |
2835 | style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); | |
2836 | style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); | |
2837 | style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); | |
2838 | } | |
a81258be RR |
2839 | } |
2840 | ||
58614078 | 2841 | void wxWindow::ApplyWidgetStyle() |
a81258be | 2842 | { |
6de97a3b RR |
2843 | } |
2844 | ||
30dea054 RR |
2845 | static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) |
2846 | { | |
1ecc4d80 | 2847 | menu->SetInvokingWindow( win ); |
c626a8b7 | 2848 | wxNode *node = menu->GetItems().First(); |
1ecc4d80 RR |
2849 | while (node) |
2850 | { | |
2851 | wxMenuItem *menuitem = (wxMenuItem*)node->Data(); | |
2852 | if (menuitem->IsSubMenu()) | |
2853 | { | |
ff8bfdbb VZ |
2854 | SetInvokingWindow( menuitem->GetSubMenu(), win ); |
2855 | } | |
1ecc4d80 RR |
2856 | node = node->Next(); |
2857 | } | |
362c6693 | 2858 | } |
30dea054 | 2859 | |
0c77152e RR |
2860 | static gint gs_pop_x = 0; |
2861 | static gint gs_pop_y = 0; | |
2862 | ||
a234a61a VZ |
2863 | static void pop_pos_callback( GtkMenu * WXUNUSED(menu), |
2864 | gint *x, gint *y, | |
2865 | wxWindow *win ) | |
0c77152e RR |
2866 | { |
2867 | win->ClientToScreen( &gs_pop_x, &gs_pop_y ); | |
2868 | *x = gs_pop_x; | |
2869 | *y = gs_pop_y; | |
2870 | } | |
2871 | ||
2872 | bool wxWindow::PopupMenu( wxMenu *menu, int x, int y ) | |
30dea054 | 2873 | { |
05939a81 | 2874 | wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") ); |
47d67540 | 2875 | |
05939a81 | 2876 | wxCHECK_MSG( menu != NULL, FALSE, _T("invalid popup-menu") ); |
8bbe427f | 2877 | |
1ecc4d80 | 2878 | SetInvokingWindow( menu, this ); |
ff8bfdbb | 2879 | |
631f1bfe JS |
2880 | menu->UpdateUI(); |
2881 | ||
0c77152e RR |
2882 | gs_pop_x = x; |
2883 | gs_pop_y = y; | |
ff8bfdbb | 2884 | |
1ecc4d80 | 2885 | gtk_menu_popup( |
47d67540 | 2886 | GTK_MENU(menu->m_menu), |
0c77152e RR |
2887 | (GtkWidget *) NULL, // parent menu shell |
2888 | (GtkWidget *) NULL, // parent menu item | |
2889 | (GtkMenuPositionFunc) pop_pos_callback, | |
2890 | (gpointer) this, // client data | |
2891 | 0, // button used to activate it | |
2892 | 0 //gs_timeLastClick // the time of activation | |
47d67540 | 2893 | ); |
1ecc4d80 | 2894 | return TRUE; |
30dea054 RR |
2895 | } |
2896 | ||
06cfab17 | 2897 | #if wxUSE_DRAG_AND_DROP |
ac57418f | 2898 | |
c801d85f KB |
2899 | void wxWindow::SetDropTarget( wxDropTarget *dropTarget ) |
2900 | { | |
05939a81 | 2901 | wxCHECK_RET( m_widget != NULL, _T("invalid window") ); |
47d67540 | 2902 | |
1ecc4d80 | 2903 | GtkWidget *dnd_widget = GetConnectWidget(); |
47d67540 | 2904 | |
1ecc4d80 | 2905 | if (m_dropTarget) m_dropTarget->UnregisterWidget( dnd_widget ); |
47d67540 | 2906 | |
1ecc4d80 RR |
2907 | if (m_dropTarget) delete m_dropTarget; |
2908 | m_dropTarget = dropTarget; | |
47d67540 | 2909 | |
1ecc4d80 | 2910 | if (m_dropTarget) m_dropTarget->RegisterWidget( dnd_widget ); |
362c6693 | 2911 | } |
c801d85f | 2912 | |
f03fc89f | 2913 | #endif // wxUSE_DRAG_AND_DROP |
ac57418f | 2914 | |
68dda785 | 2915 | GtkWidget* wxWindow::GetConnectWidget() |
e3e65dac | 2916 | { |
1ecc4d80 RR |
2917 | GtkWidget *connect_widget = m_widget; |
2918 | if (m_wxwindow) connect_widget = m_wxwindow; | |
47d67540 | 2919 | |
1ecc4d80 | 2920 | return connect_widget; |
e3e65dac | 2921 | } |
47d67540 | 2922 | |
903f689b RR |
2923 | bool wxWindow::IsOwnGtkWindow( GdkWindow *window ) |
2924 | { | |
1ecc4d80 RR |
2925 | if (m_wxwindow) return (window == m_wxwindow->window); |
2926 | return (window == m_widget->window); | |
903f689b RR |
2927 | } |
2928 | ||
f03fc89f | 2929 | bool wxWindow::SetFont( const wxFont &font ) |
c801d85f | 2930 | { |
c50f1fb9 | 2931 | wxCHECK_MSG( m_widget != NULL, FALSE, _T( "invalid window") ); |
c801d85f | 2932 | |
739730ca RR |
2933 | if (!wxWindowBase::SetFont(font)) |
2934 | { | |
2935 | // don't leave if the GTK widget has just | |
2936 | // been realized | |
2937 | if (!m_delayedFont) return FALSE; | |
2938 | } | |
c50f1fb9 | 2939 | |
a2053b27 | 2940 | GtkWidget *connect_widget = GetConnectWidget(); |
739730ca RR |
2941 | if (!connect_widget->window) |
2942 | { | |
2943 | // indicate that a new style has been set | |
c50f1fb9 VZ |
2944 | // but it couldn't get applied as the |
2945 | // widget hasn't been realized yet. | |
2946 | m_delayedFont = TRUE; | |
2947 | ||
2948 | // pretend we have done something | |
739730ca RR |
2949 | return TRUE; |
2950 | } | |
9c288e4d | 2951 | |
ae0bdb01 | 2952 | wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ); |
f03fc89f | 2953 | if ( sysbg == m_backgroundColour ) |
ae0bdb01 RR |
2954 | { |
2955 | m_backgroundColour = wxNullColour; | |
2956 | ApplyWidgetStyle(); | |
ff8bfdbb VZ |
2957 | m_backgroundColour = sysbg; |
2958 | } | |
ae0bdb01 RR |
2959 | else |
2960 | { | |
2961 | ApplyWidgetStyle(); | |
2962 | } | |
c801d85f | 2963 | |
f03fc89f | 2964 | return TRUE; |
362c6693 | 2965 | } |
c801d85f | 2966 | |
68dda785 | 2967 | void wxWindow::CaptureMouse() |
c801d85f | 2968 | { |
05939a81 | 2969 | wxCHECK_RET( m_widget != NULL, _T("invalid window") ); |
47d67540 | 2970 | |
72195a0f | 2971 | wxCHECK_RET( g_captureWindow == NULL, _T("CaptureMouse called twice") ); |
47d67540 | 2972 | |
1ecc4d80 | 2973 | GtkWidget *connect_widget = GetConnectWidget(); |
a2053b27 | 2974 | if (!connect_widget->window) return; |
c50f1fb9 | 2975 | |
1ecc4d80 RR |
2976 | gdk_pointer_grab( connect_widget->window, FALSE, |
2977 | (GdkEventMask) | |
2978 | (GDK_BUTTON_PRESS_MASK | | |
2979 | GDK_BUTTON_RELEASE_MASK | | |
2980 | GDK_POINTER_MOTION_MASK), | |
ff8bfdbb | 2981 | (GdkWindow *) NULL, |
72195a0f | 2982 | m_cursor.GetCursor(), |
ff8bfdbb | 2983 | GDK_CURRENT_TIME ); |
72195a0f | 2984 | g_captureWindow = this; |
362c6693 | 2985 | } |
c801d85f | 2986 | |
68dda785 | 2987 | void wxWindow::ReleaseMouse() |
c801d85f | 2988 | { |
05939a81 | 2989 | wxCHECK_RET( m_widget != NULL, _T("invalid window") ); |
47d67540 | 2990 | |
72195a0f | 2991 | wxCHECK_RET( g_captureWindow, _T("ReleaseMouse called twice") ); |
47d67540 | 2992 | |
1ecc4d80 | 2993 | GtkWidget *connect_widget = GetConnectWidget(); |
a2053b27 | 2994 | if (!connect_widget->window) return; |
c50f1fb9 | 2995 | |
1ecc4d80 | 2996 | gdk_pointer_ungrab ( GDK_CURRENT_TIME ); |
72195a0f | 2997 | g_captureWindow = (wxWindow*) NULL; |
362c6693 | 2998 | } |
c801d85f | 2999 | |
f03fc89f | 3000 | bool wxWindow::IsRetained() const |
c801d85f | 3001 | { |
1ecc4d80 | 3002 | return FALSE; |
362c6693 | 3003 | } |
c801d85f | 3004 | |
debe6624 | 3005 | void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible, |
cb43b372 | 3006 | int range, bool refresh ) |
c801d85f | 3007 | { |
05939a81 | 3008 | wxCHECK_RET( m_widget != NULL, _T("invalid window") ); |
8bbe427f | 3009 | |
05939a81 | 3010 | wxCHECK_RET( m_wxwindow != NULL, _T("window needs client area for scrolling") ); |
c801d85f | 3011 | |
1ecc4d80 | 3012 | m_hasScrolling = TRUE; |
47d67540 | 3013 | |
1ecc4d80 | 3014 | if (orient == wxHORIZONTAL) |
cb43b372 | 3015 | { |
1ecc4d80 RR |
3016 | float fpos = (float)pos; |
3017 | float frange = (float)range; | |
3018 | float fthumb = (float)thumbVisible; | |
3019 | if (fpos > frange-fthumb) fpos = frange-fthumb; | |
3020 | if (fpos < 0.0) fpos = 0.0; | |
3021 | ||
3022 | if ((fabs(frange-m_hAdjust->upper) < 0.2) && | |
3023 | (fabs(fthumb-m_hAdjust->page_size) < 0.2)) | |
3024 | { | |
3025 | SetScrollPos( orient, pos, refresh ); | |
3026 | return; | |
3027 | } | |
47d67540 | 3028 | |
1ecc4d80 | 3029 | m_oldHorizontalPos = fpos; |
47d67540 | 3030 | |
1ecc4d80 RR |
3031 | m_hAdjust->lower = 0.0; |
3032 | m_hAdjust->upper = frange; | |
3033 | m_hAdjust->value = fpos; | |
3034 | m_hAdjust->step_increment = 1.0; | |
3035 | m_hAdjust->page_increment = (float)(wxMax(fthumb,0)); | |
3036 | m_hAdjust->page_size = fthumb; | |
cb43b372 | 3037 | } |
1ecc4d80 RR |
3038 | else |
3039 | { | |
3040 | float fpos = (float)pos; | |
3041 | float frange = (float)range; | |
3042 | float fthumb = (float)thumbVisible; | |
3043 | if (fpos > frange-fthumb) fpos = frange-fthumb; | |
3044 | if (fpos < 0.0) fpos = 0.0; | |
3045 | ||
3046 | if ((fabs(frange-m_vAdjust->upper) < 0.2) && | |
3047 | (fabs(fthumb-m_vAdjust->page_size) < 0.2)) | |
3048 | { | |
3049 | SetScrollPos( orient, pos, refresh ); | |
3050 | return; | |
3051 | } | |
47d67540 | 3052 | |
1ecc4d80 | 3053 | m_oldVerticalPos = fpos; |
47d67540 | 3054 | |
1ecc4d80 RR |
3055 | m_vAdjust->lower = 0.0; |
3056 | m_vAdjust->upper = frange; | |
3057 | m_vAdjust->value = fpos; | |
3058 | m_vAdjust->step_increment = 1.0; | |
3059 | m_vAdjust->page_increment = (float)(wxMax(fthumb,0)); | |
3060 | m_vAdjust->page_size = fthumb; | |
3061 | } | |
47d67540 | 3062 | |
eb082a08 RR |
3063 | if (orient == wxHORIZONTAL) |
3064 | gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" ); | |
3065 | else | |
3066 | gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" ); | |
362c6693 | 3067 | } |
c801d85f | 3068 | |
debe6624 | 3069 | void wxWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) ) |
c801d85f | 3070 | { |
05939a81 | 3071 | wxCHECK_RET( m_widget != NULL, _T("invalid window") ); |
1ecc4d80 | 3072 | |
05939a81 | 3073 | wxCHECK_RET( m_wxwindow != NULL, _T("window needs client area for scrolling") ); |
1ecc4d80 RR |
3074 | |
3075 | if (orient == wxHORIZONTAL) | |
3076 | { | |
3077 | float fpos = (float)pos; | |
3078 | if (fpos > m_hAdjust->upper - m_hAdjust->page_size) fpos = m_hAdjust->upper - m_hAdjust->page_size; | |
3079 | if (fpos < 0.0) fpos = 0.0; | |
3080 | m_oldHorizontalPos = fpos; | |
3081 | ||
3082 | if (fabs(fpos-m_hAdjust->value) < 0.2) return; | |
3083 | m_hAdjust->value = fpos; | |
3084 | } | |
3085 | else | |
3086 | { | |
3087 | float fpos = (float)pos; | |
3088 | if (fpos > m_vAdjust->upper - m_vAdjust->page_size) fpos = m_vAdjust->upper - m_vAdjust->page_size; | |
3089 | if (fpos < 0.0) fpos = 0.0; | |
3090 | m_oldVerticalPos = fpos; | |
ff8bfdbb | 3091 | |
1ecc4d80 RR |
3092 | if (fabs(fpos-m_vAdjust->value) < 0.2) return; |
3093 | m_vAdjust->value = fpos; | |
3094 | } | |
47d67540 | 3095 | |
eb082a08 | 3096 | if (!m_isScrolling) /* prevent recursion */ |
47d67540 | 3097 | { |
1ecc4d80 RR |
3098 | if (m_wxwindow->window) |
3099 | { | |
3100 | if (orient == wxHORIZONTAL) | |
3101 | gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" ); | |
3102 | else | |
3103 | gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" ); | |
3104 | } | |
cb43b372 | 3105 | } |
362c6693 | 3106 | } |
c801d85f | 3107 | |
debe6624 | 3108 | int wxWindow::GetScrollThumb( int orient ) const |
c801d85f | 3109 | { |
05939a81 | 3110 | wxCHECK_MSG( m_widget != NULL, 0, _T("invalid window") ); |
47d67540 | 3111 | |
05939a81 | 3112 | wxCHECK_MSG( m_wxwindow != NULL, 0, _T("window needs client area for scrolling") ); |
47d67540 | 3113 | |
1ecc4d80 RR |
3114 | if (orient == wxHORIZONTAL) |
3115 | return (int)(m_hAdjust->page_size+0.5); | |
3116 | else | |
3117 | return (int)(m_vAdjust->page_size+0.5); | |
362c6693 | 3118 | } |
c801d85f | 3119 | |
debe6624 | 3120 | int wxWindow::GetScrollPos( int orient ) const |
c801d85f | 3121 | { |
05939a81 | 3122 | wxCHECK_MSG( m_widget != NULL, 0, _T("invalid window") ); |
47d67540 | 3123 | |
05939a81 | 3124 | wxCHECK_MSG( m_wxwindow != NULL, 0, _T("window needs client area for scrolling") ); |
c801d85f | 3125 | |
1ecc4d80 RR |
3126 | if (orient == wxHORIZONTAL) |
3127 | return (int)(m_hAdjust->value+0.5); | |
3128 | else | |
3129 | return (int)(m_vAdjust->value+0.5); | |
362c6693 | 3130 | } |
c801d85f | 3131 | |
debe6624 | 3132 | int wxWindow::GetScrollRange( int orient ) const |
c801d85f | 3133 | { |
05939a81 | 3134 | wxCHECK_MSG( m_widget != NULL, 0, _T("invalid window") ); |
47d67540 | 3135 | |
05939a81 | 3136 | wxCHECK_MSG( m_wxwindow != NULL, 0, _T("window needs client area for scrolling") ); |
c801d85f | 3137 | |
1ecc4d80 RR |
3138 | if (orient == wxHORIZONTAL) |
3139 | return (int)(m_hAdjust->upper+0.5); | |
3140 | else | |
3141 | return (int)(m_vAdjust->upper+0.5); | |
362c6693 | 3142 | } |
c801d85f | 3143 | |
debe6624 | 3144 | void wxWindow::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) ) |
c801d85f | 3145 | { |
05939a81 | 3146 | wxCHECK_RET( m_widget != NULL, _T("invalid window") ); |
47d67540 | 3147 | |
05939a81 | 3148 | wxCHECK_RET( m_wxwindow != NULL, _T("window needs client area for scrolling") ); |
c801d85f | 3149 | |
a2053b27 | 3150 | if (!m_scrollGC) |
96d5ab4d | 3151 | { |
a2053b27 RR |
3152 | m_scrollGC = gdk_gc_new( m_wxwindow->window ); |
3153 | gdk_gc_set_exposures( m_scrollGC, TRUE ); | |
96d5ab4d | 3154 | } |
c50f1fb9 | 3155 | |
ea5c6ca7 RR |
3156 | wxNode *node = m_children.First(); |
3157 | while (node) | |
3158 | { | |
3159 | wxWindow *child = (wxWindow*) node->Data(); | |
c50f1fb9 VZ |
3160 | int sx = 0; |
3161 | int sy = 0; | |
3162 | child->GetSize( &sx, &sy ); | |
3163 | child->SetSize( child->m_x + dx, child->m_y + dy, sx, sy, wxSIZE_ALLOW_MINUS_ONE ); | |
3164 | node = node->Next(); | |
ea5c6ca7 | 3165 | } |
96d5ab4d | 3166 | |
c801d85f KB |
3167 | int cw = 0; |
3168 | int ch = 0; | |
3169 | GetClientSize( &cw, &ch ); | |
c801d85f KB |
3170 | int w = cw - abs(dx); |
3171 | int h = ch - abs(dy); | |
c50f1fb9 | 3172 | |
c801d85f KB |
3173 | if ((h < 0) || (w < 0)) |
3174 | { | |
1ecc4d80 | 3175 | Refresh(); |
362c6693 | 3176 | } |
a2053b27 | 3177 | else |
c801d85f | 3178 | { |
a2053b27 RR |
3179 | int s_x = 0; |
3180 | int s_y = 0; | |
3181 | if (dx < 0) s_x = -dx; | |
3182 | if (dy < 0) s_y = -dy; | |
3183 | int d_x = 0; | |
3184 | int d_y = 0; | |
3185 | if (dx > 0) d_x = dx; | |
3186 | if (dy > 0) d_y = dy; | |
c801d85f | 3187 | |
a2053b27 RR |
3188 | gdk_window_copy_area( m_wxwindow->window, m_scrollGC, d_x, d_y, |
3189 | m_wxwindow->window, s_x, s_y, w, h ); | |
c801d85f | 3190 | |
a2053b27 RR |
3191 | wxRect rect; |
3192 | if (dx < 0) rect.x = cw+dx; else rect.x = 0; | |
3193 | if (dy < 0) rect.y = ch+dy; else rect.y = 0; | |
3194 | if (dy != 0) rect.width = cw; else rect.width = abs(dx); | |
3195 | if (dx != 0) rect.height = ch; else rect.height = abs(dy); | |
c801d85f | 3196 | |
a2053b27 RR |
3197 | Refresh( TRUE, &rect ); |
3198 | } | |
c801d85f KB |
3199 | } |
3200 | ||
f03fc89f | 3201 | void wxWindow::SetScrolling(bool scroll) |
c801d85f | 3202 | { |
f03fc89f | 3203 | m_isScrolling = g_blockEventsOnScroll = scroll; |
c801d85f | 3204 | } |