]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/window.cpp
Found a few situations where the most recent
[wxWidgets.git] / src / gtk / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: window.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling, Julian Smart
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation "window.h"
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"
24
25 #if wxUSE_DRAG_AND_DROP
26 #include "wx/dnd.h"
27 #endif
28
29 #if wxUSE_TOOLTIPS
30 #include "wx/tooltip.h"
31 #endif
32
33 #include "wx/menu.h"
34 #include "wx/statusbr.h"
35 #include "wx/intl.h"
36 #include "wx/settings.h"
37 #include "wx/log.h"
38
39 #include <math.h>
40
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
47 //-----------------------------------------------------------------------------
48 // documentation on internals
49 //-----------------------------------------------------------------------------
50
51 /*
52 I have been asked several times about writing some documentation about
53 the GTK port of wxWindows, especially its internal structures. Obviously,
54 you cannot understand wxGTK without knowing a little about the GTK, but
55 some more information about what the wxWindow, which is the base class
56 for all other window classes, does seems required as well.
57
58 What does wxWindow do? It contains the common interface for the following
59 jobs of its descendants:
60
61 1) Define the rudimentary behaviour common to all window classes, such as
62 resizing, intercepting user input (so as to make it possible to use these
63 events for special purposes in a derived class), window names etc.
64
65 2) Provide the possibility to contain and manage children, if the derived
66 class is allowed to contain children, which holds true for those window
67 classes which do not display a native GTK widget. To name them, these
68 classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
69 work classes are a special case and are handled a bit differently from
70 the rest. The same holds true for the wxNotebook class.
71
72 3) Provide the possibility to draw into a client area of a window. This,
73 too, only holds true for classes that do not display a native GTK widget
74 as above.
75
76 4) Provide the entire mechanism for scrolling widgets. This actual inter-
77 face for this is usually in wxScrolledWindow, but the GTK implementation
78 is in this class.
79
80 5) A multitude of helper or extra methods for special purposes, such as
81 Drag'n'Drop, managing validators etc.
82
83 Normally one might expect, that one wxWindows window would always correspond
84 to one GTK widget. Under GTK, there is no such allround widget that has all
85 the functionality. Moreover, the GTK defines a client area as a different
86 widget from the actual widget you are handling. Last but not least some
87 special classes (e.g. wxFrame) handle different categories of widgets and
88 still have the possibility to draw something in the client area.
89 It was therefore required to write a special purpose GTK widget, that would
90 represent a client area in the sense of wxWindows capable to do the jobs
91 2), 3) and 4). I have written this class and it resides in win_gtk.c of
92 this directory.
93
94 All windows must have a widget, with which they interact with other under-
95 lying GTK widgets. It is this widget, e.g. that has to be resized etc and
96 thw wxWindow class has a member variable called m_widget which holds a
97 pointer to this widget. When the window class represents a GTK native widget,
98 this is (in most cases) the only GTK widget the class manages. E.g. the
99 wxStatitText class handles only a GtkLabel widget a pointer to which you
100 can find in m_widget (defined in wxWindow)
101
102 When the class has a client area for drawing into and for containing children
103 it has to handle the client area widget (of the type GtkMyFixed, defined in
104 win_gtk.c), but there could be any number of widgets, handled by a class
105 The common rule for all windows is only, that the widget that interacts with
106 the rest of GTK must be referenced in m_widget and all other widgets must be
107 children of this widget on the GTK level. The top-most widget, which also
108 represents the client area, must be in the m_wxwindow field and must be of
109 the type GtkMyFixed.
110
111 As I said, the window classes that display a GTK native widget only have
112 one widget, so in the case of e.g. the wxButton class m_widget holds a
113 pointer to a GtkButton widget. But windows with client areas (for drawing
114 and children) have a m_widget field that is a pointer to a GtkScrolled-
115 Window and a m_wxwindow field that is pointer to a GtkMyFixed and this
116 one is (in the GTK sense) a child of the GtkScrolledWindow.
117
118 If the m_wxwindow field is set, then all input to this widget is inter-
119 cepted and sent to the wxWindows class. If not, all input to the widget
120 that gets pointed to by m_widget gets intercepted and sent to the class.
121
122 */
123
124 //-----------------------------------------------------------------------------
125 // debug
126 //-----------------------------------------------------------------------------
127
128 #ifdef __WXDEBUG__
129
130 static gint gtk_debug_focus_in_callback( GtkWidget *WXUNUSED(widget),
131 GdkEvent *WXUNUSED(event),
132 const wxChar *name )
133 {
134 wxPrintf( _T("FOCUS NOW AT: ") );
135 wxPrintf( name );
136 wxPrintf( _T("\n") );
137
138 return FALSE;
139 }
140
141 void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window )
142 {
143 wxString tmp = name;
144 tmp += _T(" FROM ");
145 tmp += window;
146
147 wxChar *s = new wxChar[tmp.Length()+1];
148
149 wxStrcpy( s, tmp );
150
151 gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event",
152 GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback), (gpointer)s );
153 }
154
155 #endif
156
157 //-----------------------------------------------------------------------------
158 // data
159 //-----------------------------------------------------------------------------
160
161 extern wxList wxPendingDelete;
162 extern bool g_blockEventsOnDrag;
163 extern bool g_blockEventsOnScroll;
164 extern bool g_isIdle;
165 static bool g_capturing = FALSE;
166 static wxWindow *g_focusWindow = (wxWindow*) NULL;
167
168 /* hack: we need something to pass to gtk_menu_popup, so we store the time of
169 the last click here */
170 static guint32 gs_timeLastClick = 0;
171
172 //-----------------------------------------------------------------------------
173 // idle system
174 //-----------------------------------------------------------------------------
175
176 extern void wxapp_install_idle_handler();
177 extern bool g_isIdle;
178
179 #if (GTK_MINOR_VERSION > 0)
180
181 //-----------------------------------------------------------------------------
182 // local code (see below)
183 //-----------------------------------------------------------------------------
184
185 static void draw_frame( GtkWidget *widget, wxWindow *win )
186 {
187 if (!win->HasVMT()) return;
188
189 int dw = 0;
190 int dh = 0;
191
192 if (win->m_hasScrolling)
193 {
194 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(widget);
195 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(widget)->klass );
196
197 /*
198 GtkWidget *hscrollbar = scroll_window->hscrollbar;
199 GtkWidget *vscrollbar = scroll_window->vscrollbar;
200
201 we use this instead: range.slider_width = 11 + 2*2pts edge
202 */
203
204 if (scroll_window->vscrollbar_visible)
205 {
206 dw += 15; /* dw += vscrollbar->allocation.width; */
207 dw += scroll_class->scrollbar_spacing;
208 }
209
210 if (scroll_window->hscrollbar_visible)
211 {
212 dh += 15; /* dh += hscrollbar->allocation.height; */
213 dw += scroll_class->scrollbar_spacing;
214 }
215 }
216
217 int dx = 0;
218 int dy = 0;
219 if (GTK_WIDGET_NO_WINDOW (widget))
220 {
221 dx += widget->allocation.x;
222 dy += widget->allocation.y;
223 }
224
225 if (win->m_windowStyle & wxRAISED_BORDER)
226 {
227 gtk_draw_shadow( widget->style,
228 widget->window,
229 GTK_STATE_NORMAL,
230 GTK_SHADOW_OUT,
231 dx, dy,
232 win->m_width-dw, win->m_height-dh );
233 return;
234 }
235
236 if (win->m_windowStyle & wxSUNKEN_BORDER)
237 {
238 gtk_draw_shadow( widget->style,
239 widget->window,
240 GTK_STATE_NORMAL,
241 GTK_SHADOW_IN,
242 dx, dy,
243 win->m_width-dw, win->m_height-dh );
244 return;
245 }
246 }
247
248 //-----------------------------------------------------------------------------
249 // "expose_event" of m_widget
250 //-----------------------------------------------------------------------------
251
252 static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxWindow *win )
253 {
254 if (gdk_event->count > 0) return;
255 draw_frame( widget, win );
256 }
257
258 //-----------------------------------------------------------------------------
259 // "draw" of m_wxwindow
260 //-----------------------------------------------------------------------------
261
262 static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxWindow *win )
263 {
264 draw_frame( widget, win );
265 }
266
267 #endif
268
269 //-----------------------------------------------------------------------------
270 // "expose_event" of m_wxwindow
271 //-----------------------------------------------------------------------------
272
273 static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxWindow *win )
274 {
275 if (g_isIdle) wxapp_install_idle_handler();
276
277 if (!win->HasVMT()) return;
278
279 win->m_updateRegion.Union( gdk_event->area.x,
280 gdk_event->area.y,
281 gdk_event->area.width,
282 gdk_event->area.height );
283
284 if (gdk_event->count > 0) return;
285
286 /*
287 printf( "OnExpose from " );
288 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
289 printf( win->GetClassInfo()->GetClassName() );
290 printf( ".\n" );
291 */
292
293 wxPaintEvent event( win->GetId() );
294 event.SetEventObject( win );
295 win->GetEventHandler()->ProcessEvent( event );
296
297 win->m_updateRegion.Clear();
298 }
299
300 //-----------------------------------------------------------------------------
301 // "draw" of m_wxwindow
302 //-----------------------------------------------------------------------------
303
304 static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxWindow *win )
305 {
306 if (g_isIdle) wxapp_install_idle_handler();
307
308 if (!win->HasVMT()) return;
309
310 win->m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height );
311
312 wxPaintEvent event( win->GetId() );
313 event.SetEventObject( win );
314 win->GetEventHandler()->ProcessEvent( event );
315
316 win->m_updateRegion.Clear();
317 }
318
319 //-----------------------------------------------------------------------------
320 // "key_press_event" from any window
321 //-----------------------------------------------------------------------------
322
323 static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win )
324 {
325 if (g_isIdle) wxapp_install_idle_handler();
326
327 if (!win->HasVMT()) return FALSE;
328 if (g_blockEventsOnDrag) return FALSE;
329
330 /*
331 wxPrintf( _T("OnKeyPress from ") );
332 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
333 wxPrintf( win->GetClassInfo()->GetClassName() );
334 wxPrintf( _T(".\n") );
335 */
336
337 long key_code = 0;
338 switch (gdk_event->keyval)
339 {
340 case GDK_BackSpace: key_code = WXK_BACK; break;
341 case GDK_ISO_Left_Tab:
342 case GDK_KP_Tab:
343 case GDK_Tab: key_code = WXK_TAB; break;
344 case GDK_Linefeed: key_code = WXK_RETURN; break;
345 case GDK_Clear: key_code = WXK_CLEAR; break;
346 case GDK_Return: key_code = WXK_RETURN; break;
347 case GDK_Pause: key_code = WXK_PAUSE; break;
348 case GDK_Scroll_Lock: key_code = WXK_SCROLL; break;
349 case GDK_Escape: key_code = WXK_ESCAPE; break;
350 case GDK_Delete: key_code = WXK_DELETE; break;
351 case GDK_Home: key_code = WXK_HOME; break;
352 case GDK_Left: key_code = WXK_LEFT; break;
353 case GDK_Up: key_code = WXK_UP; break;
354 case GDK_Right: key_code = WXK_RIGHT; break;
355 case GDK_Down: key_code = WXK_DOWN; break;
356 case GDK_Prior: key_code = WXK_PRIOR; break;
357 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
358 case GDK_Next: key_code = WXK_NEXT; break;
359 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
360 case GDK_End: key_code = WXK_END; break;
361 case GDK_Begin: key_code = WXK_HOME; break;
362 case GDK_Select: key_code = WXK_SELECT; break;
363 case GDK_Print: key_code = WXK_PRINT; break;
364 case GDK_Execute: key_code = WXK_EXECUTE; break;
365 case GDK_Insert: key_code = WXK_INSERT; break;
366 case GDK_Num_Lock: key_code = WXK_NUMLOCK; break;
367 case GDK_KP_Enter: key_code = WXK_RETURN; break;
368 case GDK_KP_Home: key_code = WXK_HOME; break;
369 case GDK_KP_Left: key_code = WXK_LEFT; break;
370 case GDK_KP_Up: key_code = WXK_UP; break;
371 case GDK_KP_Right: key_code = WXK_RIGHT; break;
372 case GDK_KP_Down: key_code = WXK_DOWN; break;
373 case GDK_KP_Prior: key_code = WXK_PRIOR; break;
374 // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
375 case GDK_KP_Next: key_code = WXK_NEXT; break;
376 // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
377 case GDK_KP_End: key_code = WXK_END; break;
378 case GDK_KP_Begin: key_code = WXK_HOME; break;
379 case GDK_KP_Insert: key_code = WXK_INSERT; break;
380 case GDK_KP_Delete: key_code = WXK_DELETE; break;
381 case GDK_KP_Multiply: key_code = WXK_MULTIPLY; break;
382 case GDK_KP_Add: key_code = WXK_ADD; break;
383 case GDK_KP_Separator: key_code = WXK_SEPARATOR; break;
384 case GDK_KP_Subtract: key_code = WXK_SUBTRACT; break;
385 case GDK_KP_Decimal: key_code = WXK_DECIMAL; break;
386 case GDK_KP_Divide: key_code = WXK_DIVIDE; break;
387 case GDK_KP_0: key_code = WXK_NUMPAD0; break;
388 case GDK_KP_1: key_code = WXK_NUMPAD1; break;
389 case GDK_KP_2: key_code = WXK_NUMPAD2; break;
390 case GDK_KP_3: key_code = WXK_NUMPAD3; break;
391 case GDK_KP_4: key_code = WXK_NUMPAD4; break;
392 case GDK_KP_5: key_code = WXK_NUMPAD5; break;
393 case GDK_KP_6: key_code = WXK_NUMPAD6; break;
394 case GDK_KP_7: key_code = WXK_NUMPAD7; break;
395 case GDK_KP_8: key_code = WXK_NUMPAD7; break;
396 case GDK_KP_9: key_code = WXK_NUMPAD9; break;
397 case GDK_F1: key_code = WXK_F1; break;
398 case GDK_F2: key_code = WXK_F2; break;
399 case GDK_F3: key_code = WXK_F3; break;
400 case GDK_F4: key_code = WXK_F4; break;
401 case GDK_F5: key_code = WXK_F5; break;
402 case GDK_F6: key_code = WXK_F6; break;
403 case GDK_F7: key_code = WXK_F7; break;
404 case GDK_F8: key_code = WXK_F8; break;
405 case GDK_F9: key_code = WXK_F9; break;
406 case GDK_F10: key_code = WXK_F10; break;
407 case GDK_F11: key_code = WXK_F11; break;
408 case GDK_F12: key_code = WXK_F12; break;
409 default:
410 {
411 if ((gdk_event->keyval >= 0x20) && (gdk_event->keyval <= 0xFF))
412 key_code = gdk_event->keyval;
413 }
414 }
415
416 if (!key_code) return FALSE;
417
418 wxKeyEvent event( wxEVT_KEY_DOWN );
419 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
420 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
421 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
422 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
423 event.m_keyCode = key_code;
424 event.m_x = 0;
425 event.m_y = 0;
426 event.SetEventObject( win );
427
428 bool ret = win->GetEventHandler()->ProcessEvent( event );
429
430 if (!ret)
431 {
432 wxWindow *ancestor = win;
433 while (ancestor)
434 {
435 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
436 if (command != -1)
437 {
438 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
439 ret = ancestor->GetEventHandler()->ProcessEvent( command_event );
440 break;
441 }
442 ancestor = ancestor->GetParent();
443 }
444 }
445
446 // win is a control: tab can be propagated up
447 if ( (!ret) &&
448 ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab)) &&
449 ((win->m_windowStyle & wxTE_PROCESS_TAB) == 0))
450 {
451 wxNavigationKeyEvent new_event;
452 /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
453 new_event.SetDirection( (gdk_event->keyval == GDK_Tab) );
454 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
455 new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) );
456 new_event.SetCurrentFocus( win );
457 ret = win->GetEventHandler()->ProcessEvent( new_event );
458 }
459
460 if ( (!ret) &&
461 (gdk_event->keyval == GDK_Escape) )
462 {
463 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
464 new_event.SetEventObject( win );
465 ret = win->GetEventHandler()->ProcessEvent( new_event );
466 }
467
468 /*
469 Damn, I forgot why this didn't work, but it didn't work.
470
471 // win is a panel: up can be propagated to the panel
472 if ((!ret) && (win->m_wxwindow) && (win->m_parent) && (win->m_parent->AcceptsFocus()) &&
473 (gdk_event->keyval == GDK_Up))
474 {
475 win->m_parent->SetFocus();
476 ret = TRUE;
477 }
478
479 // win is a panel: left/right can be propagated to the panel
480 if ((!ret) && (win->m_wxwindow) &&
481 ((gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Left) ||
482 (gdk_event->keyval == GDK_Up) || (gdk_event->keyval == GDK_Down)))
483 {
484 wxNavigationKeyEvent new_event;
485 new_event.SetDirection( (gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Down) );
486 new_event.SetCurrentFocus( win );
487 ret = win->GetEventHandler()->ProcessEvent( new_event );
488 }
489 */
490
491 if (ret)
492 {
493 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
494 return TRUE;
495 }
496
497 return FALSE;
498 }
499
500 //-----------------------------------------------------------------------------
501 // "key_release_event" from any window
502 //-----------------------------------------------------------------------------
503
504 static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win )
505 {
506 if (g_isIdle) wxapp_install_idle_handler();
507
508 if (!win->HasVMT()) return FALSE;
509 if (g_blockEventsOnDrag) return FALSE;
510
511 /*
512 printf( "OnKeyRelease from " );
513 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
514 printf( win->GetClassInfo()->GetClassName() );
515 printf( ".\n" );
516 */
517
518 long key_code = 0;
519 switch (gdk_event->keyval)
520 {
521 case GDK_BackSpace: key_code = WXK_BACK; break;
522 case GDK_ISO_Left_Tab:
523 case GDK_KP_Tab:
524 case GDK_Tab: key_code = WXK_TAB; break;
525 case GDK_Linefeed: key_code = WXK_RETURN; break;
526 case GDK_Clear: key_code = WXK_CLEAR; break;
527 case GDK_Return: key_code = WXK_RETURN; break;
528 case GDK_Pause: key_code = WXK_PAUSE; break;
529 case GDK_Scroll_Lock: key_code = WXK_SCROLL; break;
530 case GDK_Escape: key_code = WXK_ESCAPE; break;
531 case GDK_Delete: key_code = WXK_DELETE; break;
532 case GDK_Home: key_code = WXK_HOME; break;
533 case GDK_Left: key_code = WXK_LEFT; break;
534 case GDK_Up: key_code = WXK_UP; break;
535 case GDK_Right: key_code = WXK_RIGHT; break;
536 case GDK_Down: key_code = WXK_DOWN; break;
537 case GDK_Prior: key_code = WXK_PRIOR; break;
538 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
539 case GDK_Next: key_code = WXK_NEXT; break;
540 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
541 case GDK_End: key_code = WXK_END; break;
542 case GDK_Begin: key_code = WXK_HOME; break;
543 case GDK_Select: key_code = WXK_SELECT; break;
544 case GDK_Print: key_code = WXK_PRINT; break;
545 case GDK_Execute: key_code = WXK_EXECUTE; break;
546 case GDK_Insert: key_code = WXK_INSERT; break;
547 case GDK_Num_Lock: key_code = WXK_NUMLOCK; break;
548 case GDK_KP_Enter: key_code = WXK_RETURN; break;
549 case GDK_KP_Home: key_code = WXK_HOME; break;
550 case GDK_KP_Left: key_code = WXK_LEFT; break;
551 case GDK_KP_Up: key_code = WXK_UP; break;
552 case GDK_KP_Right: key_code = WXK_RIGHT; break;
553 case GDK_KP_Down: key_code = WXK_DOWN; break;
554 case GDK_KP_Prior: key_code = WXK_PRIOR; break;
555 // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
556 case GDK_KP_Next: key_code = WXK_NEXT; break;
557 // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
558 case GDK_KP_End: key_code = WXK_END; break;
559 case GDK_KP_Begin: key_code = WXK_HOME; break;
560 case GDK_KP_Insert: key_code = WXK_INSERT; break;
561 case GDK_KP_Delete: key_code = WXK_DELETE; break;
562 case GDK_KP_Multiply: key_code = WXK_MULTIPLY; break;
563 case GDK_KP_Add: key_code = WXK_ADD; break;
564 case GDK_KP_Separator: key_code = WXK_SEPARATOR; break;
565 case GDK_KP_Subtract: key_code = WXK_SUBTRACT; break;
566 case GDK_KP_Decimal: key_code = WXK_DECIMAL; break;
567 case GDK_KP_Divide: key_code = WXK_DIVIDE; break;
568 case GDK_KP_0: key_code = WXK_NUMPAD0; break;
569 case GDK_KP_1: key_code = WXK_NUMPAD1; break;
570 case GDK_KP_2: key_code = WXK_NUMPAD2; break;
571 case GDK_KP_3: key_code = WXK_NUMPAD3; break;
572 case GDK_KP_4: key_code = WXK_NUMPAD4; break;
573 case GDK_KP_5: key_code = WXK_NUMPAD5; break;
574 case GDK_KP_6: key_code = WXK_NUMPAD6; break;
575 case GDK_KP_7: key_code = WXK_NUMPAD7; break;
576 case GDK_KP_8: key_code = WXK_NUMPAD7; break;
577 case GDK_KP_9: key_code = WXK_NUMPAD9; break;
578 case GDK_F1: key_code = WXK_F1; break;
579 case GDK_F2: key_code = WXK_F2; break;
580 case GDK_F3: key_code = WXK_F3; break;
581 case GDK_F4: key_code = WXK_F4; break;
582 case GDK_F5: key_code = WXK_F5; break;
583 case GDK_F6: key_code = WXK_F6; break;
584 case GDK_F7: key_code = WXK_F7; break;
585 case GDK_F8: key_code = WXK_F8; break;
586 case GDK_F9: key_code = WXK_F9; break;
587 case GDK_F10: key_code = WXK_F10; break;
588 case GDK_F11: key_code = WXK_F11; break;
589 case GDK_F12: key_code = WXK_F12; break;
590 default:
591 {
592 if ((gdk_event->keyval >= 0x20) && (gdk_event->keyval <= 0xFF))
593 key_code = gdk_event->keyval;
594 }
595 }
596
597 if (!key_code) return FALSE;
598
599 wxKeyEvent event( wxEVT_KEY_UP );
600 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
601 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
602 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
603 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
604 event.m_keyCode = key_code;
605 event.m_x = 0;
606 event.m_y = 0;
607 event.SetEventObject( win );
608
609 if (win->GetEventHandler()->ProcessEvent( event ))
610 {
611 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_release_event" );
612 return TRUE;
613 }
614
615 return FALSE;
616 }
617
618 //-----------------------------------------------------------------------------
619 // "button_press_event"
620 //-----------------------------------------------------------------------------
621
622 static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
623 {
624 if (g_isIdle) wxapp_install_idle_handler();
625
626 /*
627 wxPrintf( _T("1) OnButtonPress from ") );
628 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
629 wxPrintf( win->GetClassInfo()->GetClassName() );
630 wxPrintf( _T(".\n") );
631 */
632
633 if (!win->HasVMT()) return FALSE;
634 if (g_blockEventsOnDrag) return TRUE;
635 if (g_blockEventsOnScroll) return TRUE;
636
637 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
638
639 if (win->m_wxwindow)
640 {
641 if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow) && !GTK_WIDGET_HAS_FOCUS (win->m_wxwindow) )
642 {
643 gtk_widget_grab_focus (win->m_wxwindow);
644
645 /*
646 wxPrintf( _T("GrabFocus from ") );
647 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
648 wxPrintf( win->GetClassInfo()->GetClassName() );
649 wxPrintf( _T(".\n") );
650 */
651
652 }
653 /*
654 else
655 {
656 wxPrintf( _T("No GrabFocus from ") );
657 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
658 wxPrintf( win->GetClassInfo()->GetClassName() );
659 if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow))
660 wxPrintf( _T(" because it already has") );
661 wxPrintf( _T(".\n") );
662 }
663 */
664 }
665
666 /*
667 wxPrintf( _T("2) OnButtonPress from ") );
668 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
669 wxPrintf( win->GetClassInfo()->GetClassName() );
670 wxPrintf( _T(".\n") );
671 */
672
673 wxEventType event_type = wxEVT_LEFT_DOWN;
674
675 if (gdk_event->button == 1)
676 {
677 switch (gdk_event->type)
678 {
679 case GDK_BUTTON_PRESS: event_type = wxEVT_LEFT_DOWN; break;
680 case GDK_2BUTTON_PRESS: event_type = wxEVT_LEFT_DCLICK; break;
681 default: break;
682 }
683 }
684 else if (gdk_event->button == 2)
685 {
686 switch (gdk_event->type)
687 {
688 case GDK_BUTTON_PRESS: event_type = wxEVT_MIDDLE_DOWN; break;
689 case GDK_2BUTTON_PRESS: event_type = wxEVT_MIDDLE_DCLICK; break;
690 default: break;
691 }
692 }
693 else if (gdk_event->button == 3)
694 {
695 switch (gdk_event->type)
696 {
697 case GDK_BUTTON_PRESS: event_type = wxEVT_RIGHT_DOWN; break;
698 case GDK_2BUTTON_PRESS: event_type = wxEVT_RIGHT_DCLICK; break;
699 default: break;
700 }
701 }
702
703 wxMouseEvent event( event_type );
704 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
705 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
706 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
707 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
708 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
709 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
710 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
711
712 event.m_x = (long)gdk_event->x;
713 event.m_y = (long)gdk_event->y;
714
715 // Some control don't have their own X window and thus cannot get
716 // any events.
717
718 if (!g_capturing)
719 {
720 wxNode *node = win->GetChildren().First();
721 while (node)
722 {
723 wxWindow *child = (wxWindow*)node->Data();
724
725 if (child->m_isStaticBox)
726 {
727 // wxStaticBox is transparent in the box itself
728 int x = event.m_x;
729 int y = event.m_y;
730 int xx1 = child->m_x;
731 int yy1 = child->m_y;
732 int xx2 = child->m_x + child->m_width;
733 int yy2 = child->m_x + child->m_height;
734
735 // left
736 if (((x >= xx1) && (x <= xx1+10) && (y >= yy1) && (y <= yy2)) ||
737 // right
738 ((x >= xx2-10) && (x <= xx2) && (y >= yy1) && (y <= yy2)) ||
739 // top
740 ((x >= xx1) && (x <= xx2) && (y >= yy1) && (y <= yy1+10)) ||
741 // bottom
742 ((x >= xx1) && (x <= xx2) && (y >= yy2-1) && (y <= yy2)))
743 {
744 win = child;
745 event.m_x -= child->m_x;
746 event.m_y -= child->m_y;
747 break;
748 }
749
750 }
751 else
752 {
753 if ((child->m_wxwindow == (GtkWidget*) NULL) &&
754 (child->m_x <= event.m_x) &&
755 (child->m_y <= event.m_y) &&
756 (child->m_x+child->m_width >= event.m_x) &&
757 (child->m_y+child->m_height >= event.m_y))
758 {
759 win = child;
760 event.m_x -= child->m_x;
761 event.m_y -= child->m_y;
762 break;
763 }
764 }
765 node = node->Next();
766 }
767 }
768
769 event.SetEventObject( win );
770
771 gs_timeLastClick = gdk_event->time;
772
773 if (win->GetEventHandler()->ProcessEvent( event ))
774 {
775 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_press_event" );
776 return TRUE;
777 }
778
779 return FALSE;
780 }
781
782 //-----------------------------------------------------------------------------
783 // "button_release_event"
784 //-----------------------------------------------------------------------------
785
786 static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
787 {
788 if (g_isIdle) wxapp_install_idle_handler();
789
790 if (!win->HasVMT()) return FALSE;
791 if (g_blockEventsOnDrag) return FALSE;
792 if (g_blockEventsOnScroll) return FALSE;
793
794 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
795
796 /*
797 printf( "OnButtonRelease from " );
798 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
799 printf( win->GetClassInfo()->GetClassName() );
800 printf( ".\n" );
801 */
802
803 wxEventType event_type = wxEVT_NULL;
804
805 switch (gdk_event->button)
806 {
807 case 1: event_type = wxEVT_LEFT_UP; break;
808 case 2: event_type = wxEVT_MIDDLE_UP; break;
809 case 3: event_type = wxEVT_RIGHT_UP; break;
810 }
811
812 wxMouseEvent event( event_type );
813 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
814 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
815 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
816 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
817 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
818 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
819 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
820 event.m_x = (long)gdk_event->x;
821 event.m_y = (long)gdk_event->y;
822
823 // Some control don't have their own X window and thus cannot get
824 // any events.
825
826 if (!g_capturing)
827 {
828 wxNode *node = win->GetChildren().First();
829 while (node)
830 {
831 wxWindow *child = (wxWindow*)node->Data();
832
833 if (child->m_isStaticBox)
834 {
835 // wxStaticBox is transparent in the box itself
836 int x = event.m_x;
837 int y = event.m_y;
838 int xx1 = child->m_x;
839 int yy1 = child->m_y;
840 int xx2 = child->m_x + child->m_width;
841 int yy2 = child->m_x + child->m_height;
842
843 // left
844 if (((x >= xx1) && (x <= xx1+10) && (y >= yy1) && (y <= yy2)) ||
845 // right
846 ((x >= xx2-10) && (x <= xx2) && (y >= yy1) && (y <= yy2)) ||
847 // top
848 ((x >= xx1) && (x <= xx2) && (y >= yy1) && (y <= yy1+10)) ||
849 // bottom
850 ((x >= xx1) && (x <= xx2) && (y >= yy2-1) && (y <= yy2)))
851 {
852 win = child;
853 event.m_x -= child->m_x;
854 event.m_y -= child->m_y;
855 break;
856 }
857
858 }
859 else
860 {
861 if ((child->m_wxwindow == (GtkWidget*) NULL) &&
862 (child->m_x <= event.m_x) &&
863 (child->m_y <= event.m_y) &&
864 (child->m_x+child->m_width >= event.m_x) &&
865 (child->m_y+child->m_height >= event.m_y))
866 {
867 win = child;
868 event.m_x -= child->m_x;
869 event.m_y -= child->m_y;
870 break;
871 }
872 }
873 node = node->Next();
874 }
875 }
876
877 event.SetEventObject( win );
878
879 if (win->GetEventHandler()->ProcessEvent( event ))
880 {
881 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_release_event" );
882 return TRUE;
883 }
884
885 return FALSE;
886 }
887
888 //-----------------------------------------------------------------------------
889 // "motion_notify_event"
890 //-----------------------------------------------------------------------------
891
892 static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxWindow *win )
893 {
894 if (g_isIdle) wxapp_install_idle_handler();
895
896 if (!win->HasVMT()) return FALSE;
897 if (g_blockEventsOnDrag) return FALSE;
898 if (g_blockEventsOnScroll) return FALSE;
899
900 if (!win->IsOwnGtkWindow( gdk_event->window )) return FALSE;
901
902 if (gdk_event->is_hint)
903 {
904 int x = 0;
905 int y = 0;
906 GdkModifierType state;
907 gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
908 gdk_event->x = x;
909 gdk_event->y = y;
910 gdk_event->state = state;
911 }
912
913 /*
914 printf( "OnMotion from " );
915 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
916 printf( win->GetClassInfo()->GetClassName() );
917 printf( ".\n" );
918 */
919
920 wxMouseEvent event( wxEVT_MOTION );
921 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
922 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
923 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
924 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
925 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
926 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
927 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
928
929 event.m_x = (long)gdk_event->x;
930 event.m_y = (long)gdk_event->y;
931
932 // Some control don't have their own X window and thus cannot get
933 // any events.
934
935 if (!g_capturing)
936 {
937 wxNode *node = win->GetChildren().First();
938 while (node)
939 {
940 wxWindow *child = (wxWindow*)node->Data();
941
942 if (child->m_isStaticBox)
943 {
944 // wxStaticBox is transparent in the box itself
945 int x = event.m_x;
946 int y = event.m_y;
947 int xx1 = child->m_x;
948 int yy1 = child->m_y;
949 int xx2 = child->m_x + child->m_width;
950 int yy2 = child->m_x + child->m_height;
951
952 // left
953 if (((x >= xx1) && (x <= xx1+10) && (y >= yy1) && (y <= yy2)) ||
954 // right
955 ((x >= xx2-10) && (x <= xx2) && (y >= yy1) && (y <= yy2)) ||
956 // top
957 ((x >= xx1) && (x <= xx2) && (y >= yy1) && (y <= yy1+10)) ||
958 // bottom
959 ((x >= xx1) && (x <= xx2) && (y >= yy2-1) && (y <= yy2)))
960 {
961 win = child;
962 event.m_x -= child->m_x;
963 event.m_y -= child->m_y;
964 break;
965 }
966
967 }
968 else
969 {
970 if ((child->m_wxwindow == (GtkWidget*) NULL) &&
971 (child->m_x <= event.m_x) &&
972 (child->m_y <= event.m_y) &&
973 (child->m_x+child->m_width >= event.m_x) &&
974 (child->m_y+child->m_height >= event.m_y))
975 {
976 win = child;
977 event.m_x -= child->m_x;
978 event.m_y -= child->m_y;
979 break;
980 }
981 }
982 node = node->Next();
983 }
984 }
985
986 event.SetEventObject( win );
987
988 if (win->GetEventHandler()->ProcessEvent( event ))
989 {
990 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "motion_notify_event" );
991 return TRUE;
992 }
993
994 return FALSE;
995 }
996
997 //-----------------------------------------------------------------------------
998 // "focus_in_event"
999 //-----------------------------------------------------------------------------
1000
1001 static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win )
1002 {
1003 if (g_isIdle) wxapp_install_idle_handler();
1004
1005 if (!win->HasVMT()) return FALSE;
1006 if (g_blockEventsOnDrag) return FALSE;
1007
1008 g_focusWindow = win;
1009
1010 if (win->m_wxwindow)
1011 {
1012 if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow))
1013 {
1014 GTK_WIDGET_SET_FLAGS (win->m_wxwindow, GTK_HAS_FOCUS);
1015 /*
1016 printf( "SetFocus flag from " );
1017 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1018 printf( win->GetClassInfo()->GetClassName() );
1019 printf( ".\n" );
1020 */
1021 }
1022 }
1023
1024
1025 /*
1026 wxPrintf( _T("OnSetFocus from ") );
1027 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1028 wxPrintf( win->GetClassInfo()->GetClassName() );
1029 wxPrintf( _T(" ") );
1030 wxPrintf( win->GetLabel() );
1031 wxPrintf( _T(".\n") );
1032 */
1033
1034 wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() );
1035 event.SetEventObject( win );
1036
1037 if (win->GetEventHandler()->ProcessEvent( event ))
1038 {
1039 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_in_event" );
1040 return TRUE;
1041 }
1042
1043 return FALSE;
1044 }
1045
1046 //-----------------------------------------------------------------------------
1047 // "focus_out_event"
1048 //-----------------------------------------------------------------------------
1049
1050 static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win )
1051 {
1052 if (g_isIdle) wxapp_install_idle_handler();
1053
1054 if (!win->HasVMT()) return FALSE;
1055 if (g_blockEventsOnDrag) return FALSE;
1056
1057 if (win->m_wxwindow)
1058 {
1059 if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow))
1060 GTK_WIDGET_UNSET_FLAGS (win->m_wxwindow, GTK_HAS_FOCUS);
1061 }
1062
1063 /*
1064 wxPrintf( _T("OnKillFocus from ") );
1065 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1066 wxPrintf( win->GetClassInfo()->GetClassName() );
1067 wxPrintf( _T(" ") );
1068 wxPrintf( win->GetLabel() );
1069 wxPrintf( _T(".\n") );
1070 */
1071
1072 wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() );
1073 event.SetEventObject( win );
1074
1075 if (win->GetEventHandler()->ProcessEvent( event ))
1076 {
1077 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_out_event" );
1078 return TRUE;
1079 }
1080
1081 return FALSE;
1082 }
1083
1084 //-----------------------------------------------------------------------------
1085 // "enter_notify_event"
1086 //-----------------------------------------------------------------------------
1087
1088 static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win )
1089 {
1090 if (g_isIdle) wxapp_install_idle_handler();
1091
1092 if (!win->HasVMT()) return FALSE;
1093 if (g_blockEventsOnDrag) return FALSE;
1094
1095 if (widget->window != gdk_event->window) return FALSE;
1096
1097 if ((widget->window) && (win->m_cursor.Ok()))
1098 gdk_window_set_cursor( widget->window, win->m_cursor.GetCursor() );
1099
1100 /*
1101 printf( "OnEnter from " );
1102 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1103 printf( win->GetClassInfo()->GetClassName() );
1104 printf( ".\n" );
1105 */
1106
1107 wxMouseEvent event( wxEVT_ENTER_WINDOW );
1108 event.SetEventObject( win );
1109
1110 int x = 0;
1111 int y = 0;
1112 GdkModifierType state = (GdkModifierType)0;
1113
1114 gdk_window_get_pointer( widget->window, &x, &y, &state );
1115
1116 event.m_shiftDown = (state & GDK_SHIFT_MASK);
1117 event.m_controlDown = (state & GDK_CONTROL_MASK);
1118 event.m_altDown = (state & GDK_MOD1_MASK);
1119 event.m_metaDown = (state & GDK_MOD2_MASK);
1120 event.m_leftDown = (state & GDK_BUTTON1_MASK);
1121 event.m_middleDown = (state & GDK_BUTTON2_MASK);
1122 event.m_rightDown = (state & GDK_BUTTON3_MASK);
1123
1124 event.m_x = (long)x;
1125 event.m_y = (long)y;
1126
1127 if (win->GetEventHandler()->ProcessEvent( event ))
1128 {
1129 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "enter_notify_event" );
1130 return TRUE;
1131 }
1132
1133 return FALSE;
1134 }
1135
1136 //-----------------------------------------------------------------------------
1137 // "leave_notify_event"
1138 //-----------------------------------------------------------------------------
1139
1140 static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win )
1141 {
1142 if (g_isIdle) wxapp_install_idle_handler();
1143
1144 if (!win->HasVMT()) return FALSE;
1145 if (g_blockEventsOnDrag) return FALSE;
1146
1147 if (widget->window != gdk_event->window) return FALSE;
1148
1149 if (widget->window)
1150 gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() );
1151
1152 /*
1153 printf( "OnLeave from " );
1154 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1155 printf( win->GetClassInfo()->GetClassName() );
1156 printf( ".\n" );
1157 */
1158
1159 wxMouseEvent event( wxEVT_LEAVE_WINDOW );
1160 event.SetEventObject( win );
1161
1162 int x = 0;
1163 int y = 0;
1164 GdkModifierType state = (GdkModifierType)0;
1165
1166 gdk_window_get_pointer( widget->window, &x, &y, &state );
1167
1168 event.m_shiftDown = (state & GDK_SHIFT_MASK);
1169 event.m_controlDown = (state & GDK_CONTROL_MASK);
1170 event.m_altDown = (state & GDK_MOD1_MASK);
1171 event.m_metaDown = (state & GDK_MOD2_MASK);
1172 event.m_leftDown = (state & GDK_BUTTON1_MASK);
1173 event.m_middleDown = (state & GDK_BUTTON2_MASK);
1174 event.m_rightDown = (state & GDK_BUTTON3_MASK);
1175
1176 event.m_x = (long)x;
1177 event.m_y = (long)y;
1178
1179 if (win->GetEventHandler()->ProcessEvent( event ))
1180 {
1181 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "leave_notify_event" );
1182 return TRUE;
1183 }
1184
1185 return FALSE;
1186 }
1187
1188 //-----------------------------------------------------------------------------
1189 // "value_changed" from m_vAdjust
1190 //-----------------------------------------------------------------------------
1191
1192 static void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
1193 {
1194 if (g_isIdle) wxapp_install_idle_handler();
1195
1196 if (g_blockEventsOnDrag) return;
1197
1198 /*
1199 printf( "OnVScroll from " );
1200 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1201 printf( win->GetClassInfo()->GetClassName() );
1202 printf( ".\n" );
1203 */
1204
1205 if (!win->HasVMT()) return;
1206
1207 float diff = win->m_vAdjust->value - win->m_oldVerticalPos;
1208 if (fabs(diff) < 0.2) return;
1209 win->m_oldVerticalPos = win->m_vAdjust->value;
1210
1211 wxEventType command = wxEVT_NULL;
1212
1213 float line_step = win->m_vAdjust->step_increment;
1214 float page_step = win->m_vAdjust->page_increment;
1215
1216 if (win->m_isScrolling)
1217 {
1218 command = wxEVT_SCROLL_THUMBTRACK;
1219 }
1220 else
1221 {
1222 if (fabs(win->m_vAdjust->value-win->m_vAdjust->lower) < 0.2) command = wxEVT_SCROLL_BOTTOM;
1223 else if (fabs(win->m_vAdjust->value-win->m_vAdjust->upper) < 0.2) command = wxEVT_SCROLL_TOP;
1224 else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
1225 else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
1226 else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
1227 else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
1228 else command = wxEVT_SCROLL_THUMBTRACK;
1229 }
1230
1231 int value = (int)(win->m_vAdjust->value+0.5);
1232
1233 wxScrollEvent event( command, win->GetId(), value, wxVERTICAL );
1234 event.SetEventObject( win );
1235 win->GetEventHandler()->ProcessEvent( event );
1236 }
1237
1238 //-----------------------------------------------------------------------------
1239 // "value_changed" from m_hAdjust
1240 //-----------------------------------------------------------------------------
1241
1242 static void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
1243 {
1244 if (g_isIdle) wxapp_install_idle_handler();
1245
1246 if (g_blockEventsOnDrag) return;
1247
1248 /*
1249 printf( "OnHScroll from " );
1250 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1251 printf( win->GetClassInfo()->GetClassName() );
1252 printf( ".\n" );
1253 */
1254
1255 if (!win->HasVMT()) return;
1256
1257 float diff = win->m_hAdjust->value - win->m_oldHorizontalPos;
1258 if (fabs(diff) < 0.2) return;
1259 win->m_oldHorizontalPos = win->m_hAdjust->value;
1260
1261 wxEventType command = wxEVT_NULL;
1262
1263 float line_step = win->m_hAdjust->step_increment;
1264 float page_step = win->m_hAdjust->page_increment;
1265
1266 if (win->m_isScrolling)
1267 {
1268 command = wxEVT_SCROLL_THUMBTRACK;
1269 }
1270 else
1271 {
1272 if (fabs(win->m_hAdjust->value-win->m_hAdjust->lower) < 0.2) command = wxEVT_SCROLL_BOTTOM;
1273 else if (fabs(win->m_hAdjust->value-win->m_hAdjust->upper) < 0.2) command = wxEVT_SCROLL_TOP;
1274 else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
1275 else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
1276 else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
1277 else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
1278 else command = wxEVT_SCROLL_THUMBTRACK;
1279 }
1280
1281 int value = (int)(win->m_hAdjust->value+0.5);
1282
1283 wxScrollEvent event( command, win->GetId(), value, wxHORIZONTAL );
1284 event.SetEventObject( win );
1285 win->GetEventHandler()->ProcessEvent( event );
1286 }
1287
1288 //-----------------------------------------------------------------------------
1289 // "changed" from m_vAdjust
1290 //-----------------------------------------------------------------------------
1291
1292 static void gtk_window_vscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
1293 {
1294 if (g_isIdle) wxapp_install_idle_handler();
1295
1296 if (g_blockEventsOnDrag) return;
1297
1298 /*
1299 printf( "OnVScroll change from " );
1300 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1301 printf( win->GetClassInfo()->GetClassName() );
1302 printf( ".\n" );
1303 */
1304
1305 if (!win->HasVMT()) return;
1306
1307 wxEventType command = wxEVT_SCROLL_THUMBTRACK;
1308 int value = (int)(win->m_vAdjust->value+0.5);
1309
1310 wxScrollEvent event( command, win->GetId(), value, wxVERTICAL );
1311 event.SetEventObject( win );
1312 win->GetEventHandler()->ProcessEvent( event );
1313 }
1314
1315 //-----------------------------------------------------------------------------
1316 // "changed" from m_hAdjust
1317 //-----------------------------------------------------------------------------
1318
1319 static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
1320 {
1321 if (g_isIdle) wxapp_install_idle_handler();
1322
1323 if (g_blockEventsOnDrag) return;
1324
1325 /*
1326 printf( "OnHScroll change from " );
1327 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
1328 printf( win->GetClassInfo()->GetClassName() );
1329 printf( ".\n" );
1330 */
1331
1332 if (!win->HasVMT()) return;
1333
1334 wxEventType command = wxEVT_SCROLL_THUMBTRACK;
1335 int value = (int)(win->m_hAdjust->value+0.5);
1336
1337 wxScrollEvent event( command, win->GetId(), value, wxHORIZONTAL );
1338 event.SetEventObject( win );
1339 win->GetEventHandler()->ProcessEvent( event );
1340 }
1341
1342 //-----------------------------------------------------------------------------
1343 // "button_press_event" from scrollbar
1344 //-----------------------------------------------------------------------------
1345
1346 static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget),
1347 GdkEventButton *WXUNUSED(gdk_event),
1348 wxWindow *win )
1349 {
1350 if (g_isIdle) wxapp_install_idle_handler();
1351
1352 // don't test here as we can release the mouse while being over
1353 // a different window then the slider
1354 //
1355 // if (gdk_event->window != widget->slider) return FALSE;
1356
1357 win->m_isScrolling = TRUE;
1358 g_blockEventsOnScroll = TRUE;
1359
1360 return FALSE;
1361 }
1362
1363 //-----------------------------------------------------------------------------
1364 // "button_release_event" from scrollbar
1365 //-----------------------------------------------------------------------------
1366
1367 static gint gtk_scrollbar_button_release_callback( GtkRange *widget,
1368 GdkEventButton *WXUNUSED(gdk_event),
1369 wxWindow *win )
1370 {
1371 if (g_isIdle) wxapp_install_idle_handler();
1372
1373 // don't test here as we can release the mouse while being over
1374 // a different window then the slider
1375 //
1376 // if (gdk_event->window != widget->slider) return FALSE;
1377
1378 GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(win->m_widget);
1379
1380 if (widget == GTK_RANGE(s_window->vscrollbar))
1381 gtk_signal_emit_by_name( GTK_OBJECT(win->m_hAdjust), "value_changed" );
1382 else
1383 gtk_signal_emit_by_name( GTK_OBJECT(win->m_vAdjust), "value_changed" );
1384
1385 win->m_isScrolling = FALSE;
1386 g_blockEventsOnScroll = FALSE;
1387
1388 return FALSE;
1389 }
1390
1391 //-----------------------------------------------------------------------------
1392 // "realize" from m_widget
1393 //-----------------------------------------------------------------------------
1394
1395 /* we cannot set colours, fonts and cursors before the widget has
1396 been realized, so we do this directly after realization */
1397
1398 static gint
1399 gtk_window_realized_callback( GtkWidget *widget, wxWindow *win )
1400 {
1401 if (g_isIdle) wxapp_install_idle_handler();
1402
1403 if (win->m_font != *wxSWISS_FONT)
1404 {
1405 wxFont font( win->m_font );
1406 win->m_font = wxNullFont;
1407 win->SetFont( font );
1408 }
1409
1410 if (win->m_backgroundColour != wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ))
1411 {
1412 wxColour bg( win->m_backgroundColour );
1413 win->m_backgroundColour = wxNullColour;
1414 win->SetBackgroundColour( bg );
1415 }
1416
1417 if (win->m_foregroundColour != *wxBLACK)
1418 {
1419 wxColour fg( win->m_foregroundColour );
1420 win->m_foregroundColour = wxNullColour;
1421 win->SetForegroundColour( fg );
1422 }
1423
1424 wxCursor cursor( win->m_cursor );
1425 win->m_cursor = wxNullCursor;
1426 win->SetCursor( cursor );
1427
1428 return FALSE;
1429 }
1430
1431 //-----------------------------------------------------------------------------
1432 // InsertChild for wxWindow.
1433 //-----------------------------------------------------------------------------
1434
1435 /* Callback for wxWindow. This very strange beast has to be used because
1436 * C++ has no virtual methods in a constructor. We have to emulate a
1437 * virtual function here as wxNotebook requires a different way to insert
1438 * a child in it. I had opted for creating a wxNotebookPage window class
1439 * which would have made this superfluous (such in the MDI window system),
1440 * but no-one was listening to me... */
1441
1442 static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child )
1443 {
1444 gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow),
1445 GTK_WIDGET(child->m_widget),
1446 child->m_x,
1447 child->m_y );
1448
1449 gtk_widget_set_usize( child->m_widget,
1450 child->m_width,
1451 child->m_height );
1452
1453 if (parent->m_windowStyle & wxTAB_TRAVERSAL)
1454 {
1455 /* we now allow a window to get the focus as long as it
1456 doesn't have any children. */
1457 GTK_WIDGET_UNSET_FLAGS( parent->m_wxwindow, GTK_CAN_FOCUS );
1458 }
1459 }
1460
1461 //-----------------------------------------------------------------------------
1462 // global functions
1463 //-----------------------------------------------------------------------------
1464
1465 wxWindow* wxGetActiveWindow()
1466 {
1467 return g_focusWindow;
1468 }
1469
1470 //-----------------------------------------------------------------------------
1471 // wxWindow
1472 //-----------------------------------------------------------------------------
1473
1474 IMPLEMENT_DYNAMIC_CLASS(wxWindow,wxEvtHandler)
1475
1476 BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
1477 EVT_SIZE(wxWindow::OnSize)
1478 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
1479 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
1480 EVT_KEY_DOWN(wxWindow::OnKeyDown)
1481 END_EVENT_TABLE()
1482
1483 void wxWindow::Init()
1484 {
1485 m_isWindow = TRUE;
1486
1487 m_widget = (GtkWidget *) NULL;
1488 m_wxwindow = (GtkWidget *) NULL;
1489 m_parent = (wxWindow *) NULL;
1490 m_children.DeleteContents( FALSE );
1491
1492 m_x = 0;
1493 m_y = 0;
1494 m_width = 0;
1495 m_height = 0;
1496 m_minWidth = -1;
1497 m_minHeight = -1;
1498 m_maxWidth = -1;
1499 m_maxHeight = -1;
1500
1501 m_retCode = 0;
1502
1503 m_eventHandler = this;
1504 m_windowValidator = (wxValidator *) NULL;
1505
1506 m_windowId = -1;
1507
1508 m_cursor = *wxSTANDARD_CURSOR;
1509 m_font = *wxSWISS_FONT;
1510 m_windowStyle = 0;
1511 m_windowName = "noname";
1512
1513 m_constraints = (wxLayoutConstraints *) NULL;
1514 m_constraintsInvolvedIn = (wxList *) NULL;
1515 m_windowSizer = (wxSizer *) NULL;
1516 m_sizerParent = (wxWindow *) NULL;
1517 m_autoLayout = FALSE;
1518
1519 m_sizeSet = FALSE;
1520 m_hasVMT = FALSE;
1521 m_needParent = TRUE;
1522
1523 m_hasScrolling = FALSE;
1524 m_isScrolling = FALSE;
1525 m_hAdjust = (GtkAdjustment*) NULL;
1526 m_vAdjust = (GtkAdjustment*) NULL;
1527 m_oldHorizontalPos = 0.0;
1528 m_oldVerticalPos = 0.0;
1529
1530 m_isShown = FALSE;
1531 m_isEnabled = TRUE;
1532
1533 #if wxUSE_DRAG_AND_DROP
1534 m_dropTarget = (wxDropTarget*) NULL;
1535 #endif
1536 m_resizing = FALSE;
1537 m_scrollGC = (GdkGC*) NULL;
1538 m_widgetStyle = (GtkStyle*) NULL;
1539
1540 m_insertCallback = wxInsertChildInWindow;
1541
1542 m_clientObject = (wxClientData*) NULL;
1543 m_clientData = NULL;
1544
1545 m_isStaticBox = FALSE;
1546 m_acceptsFocus = FALSE;
1547
1548 #if wxUSE_TOOLTIPS
1549 m_toolTip = (wxToolTip*) NULL;
1550 #endif // wxUSE_TOOLTIPS
1551 }
1552
1553 wxWindow::wxWindow()
1554 {
1555 Init();
1556 }
1557
1558 wxWindow::wxWindow( wxWindow *parent, wxWindowID id,
1559 const wxPoint &pos, const wxSize &size,
1560 long style, const wxString &name )
1561 {
1562 Init();
1563
1564 Create( parent, id, pos, size, style, name );
1565 }
1566
1567 bool wxWindow::Create( wxWindow *parent, wxWindowID id,
1568 const wxPoint &pos, const wxSize &size,
1569 long style, const wxString &name )
1570 {
1571 wxASSERT_MSG( m_isWindow, _T("Init() must have been called before!") );
1572
1573 PreCreation( parent, id, pos, size, style, name );
1574
1575 m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
1576 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
1577
1578 #ifdef __WXDEBUG__
1579 debug_focus_in( m_widget, _T("wxWindow::m_widget"), name );
1580 #endif
1581
1582 GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget);
1583
1584 #ifdef __WXDEBUG__
1585 debug_focus_in( s_window->hscrollbar, _T("wxWindow::hsrcollbar"), name );
1586 debug_focus_in( s_window->vscrollbar, _T("wxWindow::vsrcollbar"), name );
1587 #endif
1588
1589 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
1590 scroll_class->scrollbar_spacing = 0;
1591
1592 gtk_scrolled_window_set_policy( s_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
1593
1594 m_oldHorizontalPos = 0.0;
1595 m_oldVerticalPos = 0.0;
1596
1597 m_hAdjust = gtk_range_get_adjustment( GTK_RANGE(s_window->hscrollbar) );
1598 m_vAdjust = gtk_range_get_adjustment( GTK_RANGE(s_window->vscrollbar) );
1599
1600 m_wxwindow = gtk_myfixed_new();
1601
1602 #ifdef __WXDEBUG__
1603 debug_focus_in( m_wxwindow, _T("wxWindow::m_wxwindow"), name );
1604 #endif
1605
1606 gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
1607
1608 #if (GTK_MINOR_VERSION > 0)
1609 GtkMyFixed *myfixed = GTK_MYFIXED(m_wxwindow);
1610
1611 if (m_windowStyle & wxRAISED_BORDER)
1612 {
1613 gtk_myfixed_set_shadow_type( myfixed, GTK_SHADOW_OUT );
1614 }
1615 else if (m_windowStyle & wxSUNKEN_BORDER)
1616 {
1617 gtk_myfixed_set_shadow_type( myfixed, GTK_SHADOW_IN );
1618 }
1619 else
1620 {
1621 gtk_myfixed_set_shadow_type( myfixed, GTK_SHADOW_NONE );
1622 }
1623 #else
1624 GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport);
1625
1626 if (m_windowStyle & wxRAISED_BORDER)
1627 {
1628 gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_OUT );
1629 }
1630 else if (m_windowStyle & wxSUNKEN_BORDER)
1631 {
1632 gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_IN );
1633 }
1634 else
1635 {
1636 gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE );
1637 }
1638 #endif
1639
1640 /* we always allow a window to get the focus as long as it
1641 doesn't have any children. */
1642 if (m_windowStyle & wxTAB_TRAVERSAL)
1643 {
1644 GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
1645 m_acceptsFocus = FALSE;
1646 }
1647 else
1648 {
1649 GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
1650 m_acceptsFocus = TRUE;
1651 }
1652
1653 /* grab the actual focus */
1654 // gtk_widget_grab_focus( m_wxwindow );
1655
1656 gtk_widget_show( m_wxwindow );
1657
1658
1659 #if (GTK_MINOR_VERSION == 0)
1660 // shut the viewport up
1661 gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
1662 gtk_viewport_set_vadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
1663 #endif
1664
1665 // I _really_ don't want scrollbars in the beginning
1666 m_vAdjust->lower = 0.0;
1667 m_vAdjust->upper = 1.0;
1668 m_vAdjust->value = 0.0;
1669 m_vAdjust->step_increment = 1.0;
1670 m_vAdjust->page_increment = 1.0;
1671 m_vAdjust->page_size = 5.0;
1672 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
1673 m_hAdjust->lower = 0.0;
1674 m_hAdjust->upper = 1.0;
1675 m_hAdjust->value = 0.0;
1676 m_hAdjust->step_increment = 1.0;
1677 m_hAdjust->page_increment = 1.0;
1678 m_hAdjust->page_size = 5.0;
1679 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
1680
1681 // these handlers block mouse events to any window during scrolling
1682 // such as motion events and prevent GTK and wxWindows from fighting
1683 // over where the slider should be
1684
1685 gtk_signal_connect( GTK_OBJECT(s_window->vscrollbar), "button_press_event",
1686 (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this );
1687
1688 gtk_signal_connect( GTK_OBJECT(s_window->hscrollbar), "button_press_event",
1689 (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this );
1690
1691 gtk_signal_connect( GTK_OBJECT(s_window->vscrollbar), "button_release_event",
1692 (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this );
1693
1694 gtk_signal_connect( GTK_OBJECT(s_window->hscrollbar), "button_release_event",
1695 (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this );
1696
1697 // these handlers get notified when screen updates are required either when
1698 // scrolling or when the window size (and therefore scrollbar configuration)
1699 // has changed
1700
1701 gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed",
1702 (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this );
1703 gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed",
1704 (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this );
1705
1706 gtk_signal_connect( GTK_OBJECT(m_hAdjust), "changed",
1707 (GtkSignalFunc) gtk_window_hscroll_change_callback, (gpointer) this );
1708 gtk_signal_connect(GTK_OBJECT(m_vAdjust), "changed",
1709 (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this );
1710
1711 if (m_parent) m_parent->AddChild( this );
1712
1713 (m_parent->m_insertCallback)( m_parent, this );
1714
1715 PostCreation();
1716
1717 Show( TRUE );
1718
1719 return TRUE;
1720 }
1721
1722 wxWindow::~wxWindow()
1723 {
1724 m_hasVMT = FALSE;
1725
1726 #if wxUSE_DRAG_AND_DROP
1727 if (m_dropTarget)
1728 {
1729 delete m_dropTarget;
1730 m_dropTarget = (wxDropTarget*) NULL;
1731 }
1732 #endif
1733
1734 #if wxUSE_TOOLTIPS
1735 if (m_toolTip)
1736 {
1737 delete m_toolTip;
1738 m_toolTip = (wxToolTip*) NULL;
1739 }
1740 #endif // wxUSE_TOOLTIPS
1741
1742 if (m_widget) Show( FALSE );
1743
1744 DestroyChildren();
1745
1746 if (m_parent) m_parent->RemoveChild( this );
1747
1748 if (m_widgetStyle) gtk_style_unref( m_widgetStyle );
1749
1750 if (m_scrollGC) gdk_gc_unref( m_scrollGC );
1751
1752 if (m_wxwindow) gtk_widget_destroy( m_wxwindow );
1753
1754 if (m_widget) gtk_widget_destroy( m_widget );
1755
1756 DeleteRelatedConstraints();
1757 if (m_constraints)
1758 {
1759 /* This removes any dangling pointers to this window
1760 * in other windows' constraintsInvolvedIn lists. */
1761 UnsetConstraints(m_constraints);
1762 delete m_constraints;
1763 m_constraints = (wxLayoutConstraints *) NULL;
1764 }
1765
1766 if (m_windowSizer)
1767 {
1768 delete m_windowSizer;
1769 m_windowSizer = (wxSizer *) NULL;
1770 }
1771 /* If this is a child of a sizer, remove self from parent */
1772 if (m_sizerParent) m_sizerParent->RemoveChild((wxWindow *)this);
1773
1774 /* Just in case the window has been Closed, but
1775 * we're then deleting immediately: don't leave
1776 * dangling pointers. */
1777 wxPendingDelete.DeleteObject(this);
1778
1779 /* Just in case we've loaded a top-level window via
1780 * wxWindow::LoadNativeDialog but we weren't a dialog
1781 * class */
1782 wxTopLevelWindows.DeleteObject(this);
1783
1784 if (m_windowValidator) delete m_windowValidator;
1785
1786 if (m_clientObject) delete m_clientObject;
1787 }
1788
1789 void wxWindow::PreCreation( wxWindow *parent, wxWindowID id,
1790 const wxPoint &pos, const wxSize &size,
1791 long style, const wxString &name )
1792 {
1793 wxASSERT_MSG( (!m_needParent) || (parent), _T("Need complete parent.") );
1794
1795 m_widget = (GtkWidget*) NULL;
1796 m_wxwindow = (GtkWidget*) NULL;
1797 m_hasVMT = FALSE;
1798 m_parent = parent;
1799 m_children.DeleteContents( FALSE );
1800
1801 m_width = size.x;
1802 if (m_width == -1) m_width = 20;
1803 m_height = size.y;
1804 if (m_height == -1) m_height = 20;
1805
1806 m_x = (int)pos.x;
1807 m_y = (int)pos.y;
1808
1809 if (!m_needParent) /* some reasonable defaults */
1810 {
1811 if (m_x == -1)
1812 {
1813 m_x = (gdk_screen_width () - m_width) / 2;
1814 if (m_x < 10) m_x = 10;
1815 }
1816 if (m_y == -1)
1817 {
1818 m_y = (gdk_screen_height () - m_height) / 2;
1819 if (m_y < 10) m_y = 10;
1820 }
1821 }
1822
1823 m_minWidth = -1;
1824 m_minHeight = -1;
1825 m_maxWidth = -1;
1826 m_maxHeight = -1;
1827
1828 m_retCode = 0;
1829
1830 m_eventHandler = this;
1831
1832 m_windowId = id == -1 ? wxNewId() : id;
1833
1834 m_sizeSet = FALSE;
1835
1836 m_cursor = *wxSTANDARD_CURSOR;
1837 m_font = *wxSWISS_FONT;
1838 m_backgroundColour = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
1839 m_foregroundColour = *wxBLACK;
1840 m_windowStyle = style;
1841 m_windowName = name;
1842
1843 m_constraints = (wxLayoutConstraints *) NULL;
1844 m_constraintsInvolvedIn = (wxList *) NULL;
1845 m_windowSizer = (wxSizer *) NULL;
1846 m_sizerParent = (wxWindow *) NULL;
1847 m_autoLayout = FALSE;
1848
1849 m_hasScrolling = FALSE;
1850 m_isScrolling = FALSE;
1851 m_hAdjust = (GtkAdjustment *) NULL;
1852 m_vAdjust = (GtkAdjustment *) NULL;
1853 m_oldHorizontalPos = 0.0;
1854 m_oldVerticalPos = 0.0;
1855
1856 m_isShown = FALSE;
1857 m_isEnabled = TRUE;
1858
1859 #if wxUSE_DRAG_AND_DROP
1860 m_dropTarget = (wxDropTarget *) NULL;
1861 #endif
1862 m_resizing = FALSE;
1863 m_windowValidator = (wxValidator *) NULL;
1864 m_scrollGC = (GdkGC*) NULL;
1865 m_widgetStyle = (GtkStyle*) NULL;
1866
1867 m_clientObject = (wxClientData*)NULL;
1868 m_clientData = NULL;
1869
1870 m_isStaticBox = FALSE;
1871
1872 #if wxUSE_TOOLTIPS
1873 m_toolTip = (wxToolTip*) NULL;
1874 #endif // wxUSE_TOOLTIPS
1875 }
1876
1877 void wxWindow::PostCreation()
1878 {
1879 wxASSERT_MSG( (m_widget != NULL), _T("invalid window") );
1880
1881 if (m_wxwindow)
1882 {
1883 /* these get reported to wxWindows -> wxPaintEvent */
1884 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event",
1885 GTK_SIGNAL_FUNC(gtk_window_expose_callback), (gpointer)this );
1886
1887 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw",
1888 GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this );
1889
1890 #if (GTK_MINOR_VERSION > 0)
1891 /* these are called when the "sunken" or "raised" borders are drawn */
1892 gtk_signal_connect( GTK_OBJECT(m_widget), "expose_event",
1893 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
1894
1895 gtk_signal_connect( GTK_OBJECT(m_widget), "draw",
1896 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
1897 #endif
1898 }
1899
1900 GtkWidget *connect_widget = GetConnectWidget();
1901
1902 ConnectWidget( connect_widget );
1903
1904 /* we cannot set colours, fonts and cursors before the widget has
1905 been realized, so we do this directly after realization */
1906 gtk_signal_connect( GTK_OBJECT(connect_widget), "realize",
1907 GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this );
1908
1909 m_hasVMT = TRUE;
1910 }
1911
1912 void wxWindow::ConnectWidget( GtkWidget *widget )
1913 {
1914 gtk_signal_connect( GTK_OBJECT(widget), "key_press_event",
1915 GTK_SIGNAL_FUNC(gtk_window_key_press_callback), (gpointer)this );
1916
1917 gtk_signal_connect( GTK_OBJECT(widget), "key_release_event",
1918 GTK_SIGNAL_FUNC(gtk_window_key_release_callback), (gpointer)this );
1919
1920 gtk_signal_connect( GTK_OBJECT(widget), "button_press_event",
1921 GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this );
1922
1923 gtk_signal_connect( GTK_OBJECT(widget), "button_release_event",
1924 GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
1925
1926 gtk_signal_connect( GTK_OBJECT(widget), "motion_notify_event",
1927 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
1928
1929 gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event",
1930 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
1931
1932 gtk_signal_connect( GTK_OBJECT(widget), "focus_out_event",
1933 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
1934
1935 gtk_signal_connect( GTK_OBJECT(widget), "enter_notify_event",
1936 GTK_SIGNAL_FUNC(gtk_window_enter_callback), (gpointer)this );
1937
1938 gtk_signal_connect( GTK_OBJECT(widget), "leave_notify_event",
1939 GTK_SIGNAL_FUNC(gtk_window_leave_callback), (gpointer)this );
1940 }
1941
1942 bool wxWindow::HasVMT()
1943 {
1944 return m_hasVMT;
1945 }
1946
1947 bool wxWindow::Close( bool force )
1948 {
1949 wxASSERT_MSG( (m_widget != NULL), _T("invalid window") );
1950
1951 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
1952 event.SetEventObject(this);
1953 event.SetCanVeto(!force);
1954
1955 /* return FALSE if window wasn't closed because the application vetoed the
1956 * close event */
1957 return GetEventHandler()->ProcessEvent(event) && !event.GetVeto();
1958 }
1959
1960 bool wxWindow::Destroy()
1961 {
1962 wxASSERT_MSG( (m_widget != NULL), _T("invalid window") );
1963
1964 m_hasVMT = FALSE;
1965 delete this;
1966 return TRUE;
1967 }
1968
1969 bool wxWindow::DestroyChildren()
1970 {
1971 wxNode *node;
1972 while ((node = m_children.First()) != (wxNode *)NULL)
1973 {
1974 wxWindow *child;
1975 if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL)
1976 {
1977 delete child;
1978 if (m_children.Member(child)) delete node;
1979 }
1980 }
1981 return TRUE;
1982 }
1983
1984 void wxWindow::PrepareDC( wxDC &WXUNUSED(dc) )
1985 {
1986 // are we to set fonts here ?
1987 }
1988
1989 void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
1990 {
1991 wxASSERT_MSG( (m_widget != NULL), _T("invalid window") );
1992 wxASSERT_MSG( (m_parent != NULL), _T("wxWindow::SetSize requires parent.\n") );
1993
1994 if (m_resizing) return; /* I don't like recursions */
1995 m_resizing = TRUE;
1996
1997 if (m_parent->m_wxwindow == NULL) /* i.e. wxNotebook page */
1998 {
1999 /* don't set the size for children of wxNotebook, just take the values. */
2000 m_x = x;
2001 m_y = y;
2002 m_width = width;
2003 m_height = height;
2004 }
2005 else
2006 {
2007 int old_width = m_width;
2008 int old_height = m_height;
2009
2010 if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING)
2011 {
2012 if (x != -1) m_x = x;
2013 if (y != -1) m_y = y;
2014 if (width != -1) m_width = width;
2015 if (height != -1) m_height = height;
2016 }
2017 else
2018 {
2019 m_x = x;
2020 m_y = y;
2021 m_width = width;
2022 m_height = height;
2023 }
2024
2025 if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH)
2026 {
2027 if (width == -1) m_width = 80;
2028 }
2029
2030 if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT)
2031 {
2032 if (height == -1) m_height = 26;
2033 }
2034
2035 if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
2036 if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
2037 if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth;
2038 if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight;
2039
2040 if (GTK_WIDGET_HAS_DEFAULT(m_widget))
2041 {
2042 /* the default button has a border around it */
2043 int border = 5;
2044
2045 gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x-border, m_y-border );
2046
2047 gtk_widget_set_usize( m_widget, m_width+2*border, m_height+2*border );
2048 }
2049 else
2050 {
2051 gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x, m_y );
2052
2053 if ((old_width != m_width) || (old_height != m_height))
2054 {
2055 gtk_widget_set_usize( m_widget, m_width, m_height );
2056
2057 /* this is the result of hours of debugging: the following code
2058 means that if we have a m_wxwindow and we set the size of
2059 m_widget, m_widget (which is a GtkScrolledWindow) does NOT
2060 automatically propagate its size down to its m_wxwindow,
2061 which is its client area. therefore, we have to tell the
2062 client area directly that it has to resize itself.
2063 this will lead to that m_widget (GtkScrolledWindow) will
2064 calculate how much size it needs for scrollbars etc and
2065 it will then call XXX_size_allocate of its child, which
2066 is m_wxwindow. m_wxwindow in turn will do the same with its
2067 children and so on. problems can arise if this happens
2068 before all the children have been realized as some widgets
2069 stupidy need to be realized during XXX_size_allocate (e.g.
2070 GtkNotebook) and they will segv if called otherwise. this
2071 emergency is tested in gtk_myfixed_size_allocate. Normally
2072 this shouldn't be needed and only gtk_widget_queue_resize()
2073 should be enough to provoke a resize at the next appropriate
2074 moment, but this seems to fail, e.g. when a wxNotebook contains
2075 a wxSplitterWindow: the splitter window's children won't
2076 show up properly resized then. */
2077
2078 if (m_wxwindow)
2079 {
2080 GtkAllocation alloc;
2081 alloc.x = m_x;
2082 alloc.y = m_y;
2083 alloc.width = m_width;
2084 alloc.height = m_height;
2085 gtk_widget_size_allocate( m_widget, &alloc );
2086 }
2087 }
2088 }
2089 }
2090
2091 m_sizeSet = TRUE;
2092
2093 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
2094 event.SetEventObject( this );
2095 GetEventHandler()->ProcessEvent( event );
2096
2097 m_resizing = FALSE;
2098 }
2099
2100 void wxWindow::OnInternalIdle()
2101 {
2102 UpdateWindowUI();
2103 }
2104
2105 void wxWindow::GetSize( int *width, int *height ) const
2106 {
2107 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2108
2109 if (width) (*width) = m_width;
2110 if (height) (*height) = m_height;
2111 }
2112
2113 void wxWindow::DoSetClientSize( int width, int height )
2114 {
2115 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2116
2117 if (!m_wxwindow)
2118 {
2119 SetSize( width, height );
2120 }
2121 else
2122 {
2123 int dw = 0;
2124 int dh = 0;
2125
2126 if (!m_hasScrolling)
2127 {
2128 GtkStyleClass *window_class = m_wxwindow->style->klass;
2129
2130 if ((m_windowStyle & wxRAISED_BORDER) ||
2131 (m_windowStyle & wxSUNKEN_BORDER))
2132 {
2133 dw += 2 * window_class->xthickness;
2134 dh += 2 * window_class->ythickness;
2135 }
2136 }
2137 else
2138 {
2139 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
2140 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
2141
2142 #if (GTK_MINOR_VERSION == 0)
2143 GtkWidget *viewport = scroll_window->viewport;
2144 GtkStyleClass *viewport_class = viewport->style->klass;
2145
2146 if ((m_windowStyle & wxRAISED_BORDER) ||
2147 (m_windowStyle & wxSUNKEN_BORDER))
2148 {
2149 dw += 2 * viewport_class->xthickness;
2150 dh += 2 * viewport_class->ythickness;
2151 }
2152 #endif
2153
2154 /*
2155 GtkWidget *hscrollbar = scroll_window->hscrollbar;
2156 GtkWidget *vscrollbar = scroll_window->vscrollbar;
2157
2158 we use this instead: range.slider_width = 11 + 2*2pts edge
2159 */
2160
2161 if (scroll_window->vscrollbar_visible)
2162 {
2163 dw += 15; /* dw += vscrollbar->allocation.width; */
2164 dw += scroll_class->scrollbar_spacing;
2165 }
2166
2167 if (scroll_window->hscrollbar_visible)
2168 {
2169 dh += 15; /* dh += hscrollbar->allocation.height; */
2170 dw += scroll_class->scrollbar_spacing;
2171 }
2172 }
2173
2174 SetSize( width+dw, height+dh );
2175 }
2176 }
2177
2178 void wxWindow::GetClientSize( int *width, int *height ) const
2179 {
2180 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2181
2182 if (!m_wxwindow)
2183 {
2184 if (width) (*width) = m_width;
2185 if (height) (*height) = m_height;
2186 }
2187 else
2188 {
2189 int dw = 0;
2190 int dh = 0;
2191
2192 if (!m_hasScrolling)
2193 {
2194 GtkStyleClass *window_class = m_wxwindow->style->klass;
2195
2196 if ((m_windowStyle & wxRAISED_BORDER) ||
2197 (m_windowStyle & wxSUNKEN_BORDER))
2198 {
2199 dw += 2 * window_class->xthickness;
2200 dh += 2 * window_class->ythickness;
2201 }
2202 }
2203 else
2204 {
2205 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
2206 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
2207
2208 #if (GTK_MINOR_VERSION == 0)
2209 GtkWidget *viewport = scroll_window->viewport;
2210 GtkStyleClass *viewport_class = viewport->style->klass;
2211
2212 if ((m_windowStyle & wxRAISED_BORDER) ||
2213 (m_windowStyle & wxSUNKEN_BORDER))
2214 {
2215 dw += 2 * viewport_class->xthickness;
2216 dh += 2 * viewport_class->ythickness;
2217 }
2218 #endif
2219 /*
2220 GtkWidget *hscrollbar = scroll_window->hscrollbar;
2221 GtkWidget *vscrollbar = scroll_window->vscrollbar;
2222
2223 we use this instead: range.slider_width = 11 + 2*2pts edge
2224 */
2225
2226 if (scroll_window->vscrollbar_visible)
2227 {
2228 dw += 15; /* dw += vscrollbar->allocation.width; */
2229 dw += scroll_class->scrollbar_spacing;
2230 }
2231
2232 if (scroll_window->hscrollbar_visible)
2233 {
2234 dh += 15; /* dh += hscrollbar->allocation.height; */
2235 dh += scroll_class->scrollbar_spacing;
2236 }
2237 }
2238
2239 if (width) (*width) = m_width - dw;
2240 if (height) (*height) = m_height - dh;
2241 }
2242 }
2243
2244 void wxWindow::GetPosition( int *x, int *y ) const
2245 {
2246 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2247
2248 if (x) (*x) = m_x;
2249 if (y) (*y) = m_y;
2250 }
2251
2252 void wxWindow::ClientToScreen( int *x, int *y )
2253 {
2254 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2255
2256 if (!m_widget->window) return;
2257
2258 GdkWindow *source = (GdkWindow *) NULL;
2259 if (m_wxwindow)
2260 source = m_wxwindow->window;
2261 else
2262 source = m_widget->window;
2263
2264 int org_x = 0;
2265 int org_y = 0;
2266 gdk_window_get_origin( source, &org_x, &org_y );
2267
2268 if (!m_wxwindow)
2269 {
2270 if (GTK_WIDGET_NO_WINDOW (m_widget))
2271 {
2272 org_x += m_widget->allocation.x;
2273 org_y += m_widget->allocation.y;
2274 }
2275 }
2276
2277 if (x) *x += org_x;
2278 if (y) *y += org_y;
2279 }
2280
2281 void wxWindow::ScreenToClient( int *x, int *y )
2282 {
2283 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2284
2285 if (!m_widget->window) return;
2286
2287 GdkWindow *source = (GdkWindow *) NULL;
2288 if (m_wxwindow)
2289 source = m_wxwindow->window;
2290 else
2291 source = m_widget->window;
2292
2293 int org_x = 0;
2294 int org_y = 0;
2295 gdk_window_get_origin( source, &org_x, &org_y );
2296
2297 if (!m_wxwindow)
2298 {
2299 if (GTK_WIDGET_NO_WINDOW (m_widget))
2300 {
2301 org_x += m_widget->allocation.x;
2302 org_y += m_widget->allocation.y;
2303 }
2304 }
2305
2306 if (x) *x -= org_x;
2307 if (y) *y -= org_y;
2308 }
2309
2310 void wxWindow::Centre( int direction )
2311 {
2312 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2313
2314 int x = m_x;
2315 int y = m_y;
2316
2317 if (m_parent)
2318 {
2319 int p_w = 0;
2320 int p_h = 0;
2321 m_parent->GetSize( &p_w, &p_h );
2322 if (direction & wxHORIZONTAL == wxHORIZONTAL) x = (p_w - m_width) / 2;
2323 if (direction & wxVERTICAL == wxVERTICAL) y = (p_h - m_height) / 2;
2324 }
2325 else
2326 {
2327 if (direction & wxHORIZONTAL == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2;
2328 if (direction & wxVERTICAL == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2;
2329 }
2330
2331 Move( x, y );
2332 }
2333
2334 void wxWindow::Fit()
2335 {
2336 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2337
2338 int maxX = 0;
2339 int maxY = 0;
2340 wxNode *node = m_children.First();
2341 while (node)
2342 {
2343 wxWindow *win = (wxWindow *)node->Data();
2344 int wx, wy, ww, wh;
2345 win->GetPosition(&wx, &wy);
2346 win->GetSize(&ww, &wh);
2347 if (wx + ww > maxX) maxX = wx + ww;
2348 if (wy + wh > maxY) maxY = wy + wh;
2349
2350 node = node->Next();
2351 }
2352
2353 SetClientSize(maxX + 7, maxY + 14);
2354 }
2355
2356 void wxWindow::SetSizeHints( int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH) )
2357 {
2358 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2359
2360 m_minWidth = minW;
2361 m_minHeight = minH;
2362 m_maxWidth = maxW;
2363 m_maxHeight = maxH;
2364 }
2365
2366 void wxWindow::OnSize( wxSizeEvent &WXUNUSED(event) )
2367 {
2368 /* this is commented because it also is commented
2369 in wxMSW. before I get even more questions about
2370 this. */
2371 // if (GetAutoLayout()) Layout();
2372 }
2373
2374 bool wxWindow::Show( bool show )
2375 {
2376 wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") );
2377
2378 if (show == m_isShown) return TRUE;
2379
2380 if (show)
2381 gtk_widget_show( m_widget );
2382 else
2383 gtk_widget_hide( m_widget );
2384
2385 m_isShown = show;
2386
2387 return TRUE;
2388 }
2389
2390 void wxWindow::Enable( bool enable )
2391 {
2392 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2393
2394 m_isEnabled = enable;
2395
2396 gtk_widget_set_sensitive( m_widget, enable );
2397 if (m_wxwindow) gtk_widget_set_sensitive( m_wxwindow, enable );
2398 }
2399
2400 int wxWindow::GetCharHeight() const
2401 {
2402 wxCHECK_MSG( (m_widget != NULL), 12, _T("invalid window") );
2403
2404 wxCHECK_MSG( m_font.Ok(), 12, _T("invalid font") );
2405
2406 GdkFont *font = m_font.GetInternalFont( 1.0 );
2407
2408 return font->ascent + font->descent;
2409 }
2410
2411 int wxWindow::GetCharWidth() const
2412 {
2413 wxCHECK_MSG( (m_widget != NULL), 8, _T("invalid window") );
2414
2415 wxCHECK_MSG( m_font.Ok(), 8, _T("invalid font") );
2416
2417 GdkFont *font = m_font.GetInternalFont( 1.0 );
2418
2419 return gdk_string_width( font, "H" );
2420 }
2421
2422 void wxWindow::GetTextExtent( const wxString& string, int *x, int *y,
2423 int *descent, int *externalLeading, const wxFont *theFont, bool WXUNUSED(use16) ) const
2424 {
2425 wxFont fontToUse = m_font;
2426 if (theFont) fontToUse = *theFont;
2427
2428 wxCHECK_RET( fontToUse.Ok(), _T("invalid font") );
2429
2430 GdkFont *font = fontToUse.GetInternalFont( 1.0 );
2431 if (x) (*x) = gdk_string_width( font, string.mbc_str() );
2432 if (y) (*y) = font->ascent + font->descent;
2433 if (descent) (*descent) = font->descent;
2434 if (externalLeading) (*externalLeading) = 0; // ??
2435 }
2436
2437 void wxWindow::MakeModal( bool modal )
2438 {
2439 return;
2440
2441 // Disable all other windows
2442 if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame)))
2443 {
2444 wxNode *node = wxTopLevelWindows.First();
2445 while (node)
2446 {
2447 wxWindow *win = (wxWindow *)node->Data();
2448 if (win != this) win->Enable(!modal);
2449
2450 node = node->Next();
2451 }
2452 }
2453 }
2454
2455 void wxWindow::OnKeyDown( wxKeyEvent &event )
2456 {
2457 event.SetEventType( wxEVT_CHAR );
2458
2459 if (!GetEventHandler()->ProcessEvent( event ))
2460 {
2461 event.Skip();
2462 }
2463 }
2464
2465 void wxWindow::SetFocus()
2466 {
2467 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2468
2469 GtkWidget *connect_widget = GetConnectWidget();
2470 if (connect_widget)
2471 {
2472 if (GTK_WIDGET_CAN_FOCUS(connect_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ )
2473 {
2474 gtk_widget_grab_focus (connect_widget);
2475 }
2476 else if (GTK_IS_CONTAINER(connect_widget))
2477 {
2478 gtk_container_focus( GTK_CONTAINER(connect_widget), GTK_DIR_TAB_FORWARD );
2479 }
2480 else
2481 {
2482 }
2483 }
2484 }
2485
2486 wxWindow *wxWindow::FindFocus()
2487 {
2488 return g_focusWindow;
2489 }
2490
2491 bool wxWindow::AcceptsFocus() const
2492 {
2493 return IsEnabled() && IsShown() && m_acceptsFocus;
2494 }
2495
2496 void wxWindow::AddChild( wxWindow *child )
2497 {
2498 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2499 wxCHECK_RET( (child != NULL), _T("invalid child") );
2500
2501 m_children.Append( child );
2502 }
2503
2504 wxWindow *wxWindow::ReParent( wxWindow *newParent )
2505 {
2506 wxCHECK_MSG( (m_widget != NULL), (wxWindow*) NULL, _T("invalid window") );
2507
2508 wxWindow *oldParent = GetParent();
2509
2510 if (oldParent) oldParent->RemoveChild( this );
2511
2512 gtk_widget_unparent( m_widget );
2513
2514 if (newParent)
2515 {
2516 newParent->AddChild( this );
2517 (newParent->m_insertCallback)( newParent, this );
2518 }
2519
2520 return oldParent;
2521 }
2522
2523 void wxWindow::RemoveChild( wxWindow *child )
2524 {
2525 m_children.DeleteObject( child );
2526 child->m_parent = (wxWindow *) NULL;
2527 }
2528
2529 void wxWindow::SetReturnCode( int retCode )
2530 {
2531 m_retCode = retCode;
2532 }
2533
2534 int wxWindow::GetReturnCode()
2535 {
2536 return m_retCode;
2537 }
2538
2539 void wxWindow::Raise()
2540 {
2541 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2542
2543 if (!m_widget->window) return;
2544
2545 if (m_widget) gdk_window_raise( m_widget->window );
2546 }
2547
2548 void wxWindow::Lower()
2549 {
2550 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2551
2552 if (!m_widget->window) return;
2553
2554 if (m_widget) gdk_window_lower( m_widget->window );
2555 }
2556
2557 wxEvtHandler *wxWindow::GetEventHandler() const
2558 {
2559 return m_eventHandler;
2560 }
2561
2562 void wxWindow::SetEventHandler( wxEvtHandler *handler )
2563 {
2564 m_eventHandler = handler;
2565 }
2566
2567 void wxWindow::PushEventHandler(wxEvtHandler *handler)
2568 {
2569 handler->SetNextHandler(GetEventHandler());
2570 SetEventHandler(handler);
2571 }
2572
2573 wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler)
2574 {
2575 if (GetEventHandler())
2576 {
2577 wxEvtHandler *handlerA = GetEventHandler();
2578 wxEvtHandler *handlerB = handlerA->GetNextHandler();
2579 handlerA->SetNextHandler((wxEvtHandler *) NULL);
2580 SetEventHandler(handlerB);
2581 if (deleteHandler)
2582 {
2583 delete handlerA;
2584 return (wxEvtHandler*) NULL;
2585 }
2586 else
2587 return handlerA;
2588 }
2589 else
2590 return (wxEvtHandler *) NULL;
2591 }
2592
2593 wxValidator *wxWindow::GetValidator()
2594 {
2595 return m_windowValidator;
2596 }
2597
2598 void wxWindow::SetValidator( const wxValidator& validator )
2599 {
2600 if (m_windowValidator) delete m_windowValidator;
2601 m_windowValidator = (wxValidator*)validator.Clone();
2602 if (m_windowValidator) m_windowValidator->SetWindow(this);
2603 }
2604
2605 void wxWindow::SetClientObject( wxClientData *data )
2606 {
2607 if (m_clientObject) delete m_clientObject;
2608 m_clientObject = data;
2609 }
2610
2611 wxClientData *wxWindow::GetClientObject()
2612 {
2613 return m_clientObject;
2614 }
2615
2616 void wxWindow::SetClientData( void *data )
2617 {
2618 m_clientData = data;
2619 }
2620
2621 void *wxWindow::GetClientData()
2622 {
2623 return m_clientData;
2624 }
2625
2626 bool wxWindow::IsBeingDeleted()
2627 {
2628 return FALSE;
2629 }
2630
2631 void wxWindow::SetId( wxWindowID id )
2632 {
2633 m_windowId = id;
2634 }
2635
2636 wxWindowID wxWindow::GetId() const
2637 {
2638 return m_windowId;
2639 }
2640
2641 void wxWindow::SetCursor( const wxCursor &cursor )
2642 {
2643 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2644
2645 if (cursor.Ok())
2646 {
2647 if (cursor == m_cursor) return;
2648 m_cursor = cursor;
2649 }
2650 else
2651 {
2652 m_cursor = *wxSTANDARD_CURSOR;
2653 }
2654
2655 if (!m_widget->window) return;
2656
2657 gdk_window_set_cursor( m_widget->window, m_cursor.GetCursor() );
2658
2659 if ((m_wxwindow) && (m_wxwindow->window))
2660 gdk_window_set_cursor( m_wxwindow->window, m_cursor.GetCursor() );
2661 }
2662
2663 void wxWindow::WarpPointer( int WXUNUSED(x), int WXUNUSED(y) )
2664 {
2665 // TODO
2666 }
2667
2668 void wxWindow::Refresh( bool eraseBackground, const wxRect *rect )
2669 {
2670 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2671
2672 if (!m_widget->window) return;
2673
2674 if (eraseBackground && m_wxwindow && m_wxwindow->window)
2675 {
2676 if (rect)
2677 {
2678 gdk_window_clear_area( m_wxwindow->window,
2679 rect->x, rect->y,
2680 rect->width, rect->height );
2681 }
2682 else
2683 {
2684 gdk_window_clear( m_wxwindow->window );
2685 }
2686 }
2687
2688 if (!rect)
2689 {
2690 if (m_wxwindow)
2691 gtk_widget_draw( m_wxwindow, (GdkRectangle*) NULL );
2692 else
2693 gtk_widget_draw( m_widget, (GdkRectangle*) NULL );
2694 }
2695 else
2696 {
2697 GdkRectangle gdk_rect;
2698 gdk_rect.x = rect->x;
2699 gdk_rect.y = rect->y;
2700 gdk_rect.width = rect->width;
2701 gdk_rect.height = rect->height;
2702
2703 if (m_wxwindow)
2704 gtk_widget_draw( m_wxwindow, &gdk_rect );
2705 else
2706 gtk_widget_draw( m_widget, &gdk_rect );
2707 }
2708 }
2709
2710 wxRegion wxWindow::GetUpdateRegion() const
2711 {
2712 return m_updateRegion;
2713 }
2714
2715 bool wxWindow::IsExposed( int x, int y) const
2716 {
2717 return (m_updateRegion.Contains( x, y ) != wxOutRegion );
2718 }
2719
2720 bool wxWindow::IsExposed( int x, int y, int w, int h ) const
2721 {
2722 return (m_updateRegion.Contains( x, y, w, h ) != wxOutRegion );
2723 }
2724
2725 bool wxWindow::IsExposed( const wxPoint& pt ) const
2726 {
2727 return (m_updateRegion.Contains( pt.x, pt.y ) != wxOutRegion );
2728 }
2729
2730 bool wxWindow::IsExposed( const wxRect& rect ) const
2731 {
2732 return (m_updateRegion.Contains( rect.x, rect.y, rect.width, rect.height ) != wxOutRegion );
2733 }
2734
2735 void wxWindow::Clear()
2736 {
2737 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
2738
2739 if (!m_widget->window) return;
2740
2741 if (m_wxwindow && m_wxwindow->window)
2742 {
2743 gdk_window_clear( m_wxwindow->window );
2744 }
2745 }
2746
2747 #if wxUSE_TOOLTIPS
2748 void wxWindow::SetToolTip( const wxString &tip )
2749 {
2750 if (m_toolTip)
2751 {
2752 m_toolTip->SetTip( tip );
2753 }
2754 else
2755 {
2756 SetToolTip( new wxToolTip( tip ) );
2757 }
2758
2759 // setting empty tooltip text does not remove the tooltip any more for
2760 // wxMSW compatibility - use SetToolTip((wxToolTip *)NULL) for this
2761 }
2762
2763 void wxWindow::SetToolTip( wxToolTip *tip )
2764 {
2765 if (m_toolTip)
2766 {
2767 m_toolTip->SetTip( (char*) NULL );
2768 delete m_toolTip;
2769 }
2770
2771 m_toolTip = tip;
2772
2773 if (m_toolTip)
2774 m_toolTip->Apply( this );
2775 }
2776
2777 void wxWindow::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
2778 {
2779 gtk_tooltips_set_tip( tips, GetConnectWidget(), wxConv_current->cWX2MB(tip), (gchar*) NULL );
2780 }
2781 #endif // wxUSE_TOOLTIPS
2782
2783 wxColour wxWindow::GetBackgroundColour() const
2784 {
2785 return m_backgroundColour;
2786 }
2787
2788 void wxWindow::SetBackgroundColour( const wxColour &colour )
2789 {
2790 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
2791
2792 if (m_backgroundColour == colour) return;
2793
2794 m_backgroundColour = colour;
2795 if (!m_backgroundColour.Ok()) return;
2796
2797 GtkWidget *connect_widget = GetConnectWidget();
2798 if (!connect_widget->window) return;
2799
2800 if (m_wxwindow && m_wxwindow->window)
2801 {
2802 /* wxMSW doesn't clear the window here. I don't do that
2803 either to provide compatibility. call Clear() to do
2804 the job. */
2805
2806 m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_wxwindow->window ) );
2807 gdk_window_set_background( m_wxwindow->window, m_backgroundColour.GetColor() );
2808 }
2809
2810 wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
2811
2812 if (sysbg.Red() == colour.Red() &&
2813 sysbg.Green() == colour.Green() &&
2814 sysbg.Blue() == colour.Blue())
2815 {
2816 m_backgroundColour = wxNullColour;
2817 ApplyWidgetStyle();
2818 m_backgroundColour = sysbg;
2819 }
2820 else
2821 {
2822 ApplyWidgetStyle();
2823 }
2824 }
2825
2826 wxColour wxWindow::GetForegroundColour() const
2827 {
2828 return m_foregroundColour;
2829 }
2830
2831 void wxWindow::SetForegroundColour( const wxColour &colour )
2832 {
2833 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
2834
2835 if (m_foregroundColour == colour) return;
2836
2837 m_foregroundColour = colour;
2838 if (!m_foregroundColour.Ok()) return;
2839
2840 if (!m_widget->window) return;
2841
2842 wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
2843 if (sysbg.Red() == colour.Red() &&
2844 sysbg.Green() == colour.Green() &&
2845 sysbg.Blue() == colour.Blue())
2846 {
2847 m_backgroundColour = wxNullColour;
2848 ApplyWidgetStyle();
2849 m_backgroundColour = sysbg;
2850 }
2851 else
2852 {
2853 ApplyWidgetStyle();
2854 }
2855 }
2856
2857 GtkStyle *wxWindow::GetWidgetStyle()
2858 {
2859 if (m_widgetStyle) gtk_style_unref( m_widgetStyle );
2860
2861 m_widgetStyle =
2862 gtk_style_copy(
2863 gtk_widget_get_style( m_widget ) );
2864
2865 return m_widgetStyle;
2866 }
2867
2868 void wxWindow::SetWidgetStyle()
2869 {
2870 GtkStyle *style = GetWidgetStyle();
2871
2872 gdk_font_unref( style->font );
2873 style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
2874
2875 if (m_foregroundColour.Ok())
2876 {
2877 m_foregroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
2878 style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor();
2879 style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor();
2880 style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor();
2881 }
2882
2883 if (m_backgroundColour.Ok())
2884 {
2885 m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
2886 style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
2887 style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
2888 style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
2889 style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
2890 style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
2891 style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
2892 style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
2893 style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
2894 }
2895 }
2896
2897 void wxWindow::ApplyWidgetStyle()
2898 {
2899 }
2900
2901 bool wxWindow::Validate()
2902 {
2903 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
2904
2905 wxNode *node = m_children.First();
2906 while (node)
2907 {
2908 wxWindow *child = (wxWindow *)node->Data();
2909 if (child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this))
2910 {
2911 return FALSE;
2912 }
2913 node = node->Next();
2914 }
2915 return TRUE;
2916 }
2917
2918 bool wxWindow::TransferDataToWindow()
2919 {
2920 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
2921
2922 wxNode *node = m_children.First();
2923 while (node)
2924 {
2925 wxWindow *child = (wxWindow *)node->Data();
2926 if (child->GetValidator() && /* child->GetValidator()->Ok() && */
2927 !child->GetValidator()->TransferToWindow() )
2928 {
2929 wxMessageBox( _("Application Error"), _("Could not transfer data to window"), wxOK|wxICON_EXCLAMATION );
2930 return FALSE;
2931 }
2932 node = node->Next();
2933 }
2934 return TRUE;
2935 }
2936
2937 bool wxWindow::TransferDataFromWindow()
2938 {
2939 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
2940
2941 wxNode *node = m_children.First();
2942 while (node)
2943 {
2944 wxWindow *child = (wxWindow *)node->Data();
2945 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->TransferFromWindow() )
2946 {
2947 return FALSE;
2948 }
2949 node = node->Next();
2950 }
2951 return TRUE;
2952 }
2953
2954 void wxWindow::SetAcceleratorTable( const wxAcceleratorTable& accel )
2955 {
2956 m_acceleratorTable = accel;
2957 }
2958
2959 void wxWindow::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
2960 {
2961 TransferDataToWindow();
2962 }
2963
2964 void wxWindow::InitDialog()
2965 {
2966 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
2967
2968 wxInitDialogEvent event(GetId());
2969 event.SetEventObject( this );
2970 GetEventHandler()->ProcessEvent(event);
2971 }
2972
2973 static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
2974 {
2975 menu->SetInvokingWindow( win );
2976 wxNode *node = menu->GetItems().First();
2977 while (node)
2978 {
2979 wxMenuItem *menuitem = (wxMenuItem*)node->Data();
2980 if (menuitem->IsSubMenu())
2981 {
2982 SetInvokingWindow( menuitem->GetSubMenu(), win );
2983 }
2984 node = node->Next();
2985 }
2986 }
2987
2988 static gint gs_pop_x = 0;
2989 static gint gs_pop_y = 0;
2990
2991 static void pop_pos_callback( GtkMenu *menu, gint *x, gint *y, wxWindow *win )
2992 {
2993 win->ClientToScreen( &gs_pop_x, &gs_pop_y );
2994 *x = gs_pop_x;
2995 *y = gs_pop_y;
2996 }
2997
2998 bool wxWindow::PopupMenu( wxMenu *menu, int x, int y )
2999 {
3000 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
3001
3002 wxCHECK_MSG( menu != NULL, FALSE, _T("invalid popup-menu") );
3003
3004 SetInvokingWindow( menu, this );
3005
3006 menu->UpdateUI();
3007
3008 gs_pop_x = x;
3009 gs_pop_y = y;
3010
3011 gtk_menu_popup(
3012 GTK_MENU(menu->m_menu),
3013 (GtkWidget *) NULL, // parent menu shell
3014 (GtkWidget *) NULL, // parent menu item
3015 (GtkMenuPositionFunc) pop_pos_callback,
3016 (gpointer) this, // client data
3017 0, // button used to activate it
3018 0 //gs_timeLastClick // the time of activation
3019 );
3020 return TRUE;
3021 }
3022
3023 #if wxUSE_DRAG_AND_DROP
3024
3025 void wxWindow::SetDropTarget( wxDropTarget *dropTarget )
3026 {
3027 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3028
3029 GtkWidget *dnd_widget = GetConnectWidget();
3030
3031 if (m_dropTarget) m_dropTarget->UnregisterWidget( dnd_widget );
3032
3033 if (m_dropTarget) delete m_dropTarget;
3034 m_dropTarget = dropTarget;
3035
3036 if (m_dropTarget) m_dropTarget->RegisterWidget( dnd_widget );
3037 }
3038
3039 wxDropTarget *wxWindow::GetDropTarget() const
3040 {
3041 return m_dropTarget;
3042 }
3043
3044 #endif
3045
3046 GtkWidget* wxWindow::GetConnectWidget()
3047 {
3048 GtkWidget *connect_widget = m_widget;
3049 if (m_wxwindow) connect_widget = m_wxwindow;
3050
3051 return connect_widget;
3052 }
3053
3054 bool wxWindow::IsOwnGtkWindow( GdkWindow *window )
3055 {
3056 if (m_wxwindow) return (window == m_wxwindow->window);
3057 return (window == m_widget->window);
3058 }
3059
3060 void wxWindow::SetFont( const wxFont &font )
3061 {
3062 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3063
3064 if (m_font == font) return;
3065
3066 if (((wxFont*)&font)->Ok())
3067 m_font = font;
3068 else
3069 m_font = *wxSWISS_FONT;
3070
3071 if (!m_widget->window) return;
3072
3073 wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
3074 if (sysbg.Red() == m_backgroundColour.Red() &&
3075 sysbg.Green() == m_backgroundColour.Green() &&
3076 sysbg.Blue() == m_backgroundColour.Blue())
3077 {
3078 m_backgroundColour = wxNullColour;
3079 ApplyWidgetStyle();
3080 m_backgroundColour = sysbg;
3081 }
3082 else
3083 {
3084 ApplyWidgetStyle();
3085 }
3086 }
3087
3088 void wxWindow::SetWindowStyleFlag( long flag )
3089 {
3090 m_windowStyle = flag;
3091 }
3092
3093 long wxWindow::GetWindowStyleFlag() const
3094 {
3095 return m_windowStyle;
3096 }
3097
3098 void wxWindow::CaptureMouse()
3099 {
3100 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3101
3102 wxCHECK_RET( g_capturing == FALSE, _T("CaptureMouse called twice") );
3103
3104 if (!m_widget->window) return;
3105
3106 GtkWidget *connect_widget = GetConnectWidget();
3107 gtk_grab_add( connect_widget );
3108 gdk_pointer_grab( connect_widget->window, FALSE,
3109 (GdkEventMask)
3110 (GDK_BUTTON_PRESS_MASK |
3111 GDK_BUTTON_RELEASE_MASK |
3112 GDK_POINTER_MOTION_MASK),
3113 (GdkWindow *) NULL,
3114 (GdkCursor *) NULL,
3115 GDK_CURRENT_TIME );
3116 g_capturing = TRUE;
3117 }
3118
3119 void wxWindow::ReleaseMouse()
3120 {
3121 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3122
3123 wxCHECK_RET( g_capturing == TRUE, _T("ReleaseMouse called twice") );
3124
3125 if (!m_widget->window) return;
3126
3127 GtkWidget *connect_widget = GetConnectWidget();
3128 gtk_grab_remove( connect_widget );
3129 gdk_pointer_ungrab ( GDK_CURRENT_TIME );
3130 g_capturing = FALSE;
3131 }
3132
3133 void wxWindow::SetTitle( const wxString &WXUNUSED(title) )
3134 {
3135 }
3136
3137 wxString wxWindow::GetTitle() const
3138 {
3139 return (wxString&)m_windowName;
3140 }
3141
3142 wxString wxWindow::GetLabel() const
3143 {
3144 return GetTitle();
3145 }
3146
3147 void wxWindow::SetName( const wxString &name )
3148 {
3149 m_windowName = name;
3150 }
3151
3152 wxString wxWindow::GetName() const
3153 {
3154 return (wxString&)m_windowName;
3155 }
3156
3157 bool wxWindow::IsShown() const
3158 {
3159 return m_isShown;
3160 }
3161
3162 bool wxWindow::IsRetained()
3163 {
3164 return FALSE;
3165 }
3166
3167 wxWindow *wxWindow::FindWindow( long id )
3168 {
3169 if (id == m_windowId) return this;
3170 wxNode *node = m_children.First();
3171 while (node)
3172 {
3173 wxWindow *child = (wxWindow*)node->Data();
3174 wxWindow *res = child->FindWindow( id );
3175 if (res) return res;
3176 node = node->Next();
3177 }
3178 return (wxWindow *) NULL;
3179 }
3180
3181 wxWindow *wxWindow::FindWindow( const wxString& name )
3182 {
3183 if (name == m_windowName) return this;
3184 wxNode *node = m_children.First();
3185 while (node)
3186 {
3187 wxWindow *child = (wxWindow*)node->Data();
3188 wxWindow *res = child->FindWindow( name );
3189 if (res) return res;
3190 node = node->Next();
3191 }
3192 return (wxWindow *) NULL;
3193 }
3194
3195 void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible,
3196 int range, bool refresh )
3197 {
3198 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3199
3200 wxCHECK_RET( m_wxwindow != NULL, _T("window needs client area for scrolling") );
3201
3202 m_hasScrolling = TRUE;
3203
3204 if (orient == wxHORIZONTAL)
3205 {
3206 float fpos = (float)pos;
3207 float frange = (float)range;
3208 float fthumb = (float)thumbVisible;
3209 if (fpos > frange-fthumb) fpos = frange-fthumb;
3210 if (fpos < 0.0) fpos = 0.0;
3211
3212 if ((fabs(frange-m_hAdjust->upper) < 0.2) &&
3213 (fabs(fthumb-m_hAdjust->page_size) < 0.2))
3214 {
3215 SetScrollPos( orient, pos, refresh );
3216 return;
3217 }
3218
3219 m_oldHorizontalPos = fpos;
3220
3221 m_hAdjust->lower = 0.0;
3222 m_hAdjust->upper = frange;
3223 m_hAdjust->value = fpos;
3224 m_hAdjust->step_increment = 1.0;
3225 m_hAdjust->page_increment = (float)(wxMax(fthumb,0));
3226 m_hAdjust->page_size = fthumb;
3227 }
3228 else
3229 {
3230 float fpos = (float)pos;
3231 float frange = (float)range;
3232 float fthumb = (float)thumbVisible;
3233 if (fpos > frange-fthumb) fpos = frange-fthumb;
3234 if (fpos < 0.0) fpos = 0.0;
3235
3236 if ((fabs(frange-m_vAdjust->upper) < 0.2) &&
3237 (fabs(fthumb-m_vAdjust->page_size) < 0.2))
3238 {
3239 SetScrollPos( orient, pos, refresh );
3240 return;
3241 }
3242
3243 m_oldVerticalPos = fpos;
3244
3245 m_vAdjust->lower = 0.0;
3246 m_vAdjust->upper = frange;
3247 m_vAdjust->value = fpos;
3248 m_vAdjust->step_increment = 1.0;
3249 m_vAdjust->page_increment = (float)(wxMax(fthumb,0));
3250 m_vAdjust->page_size = fthumb;
3251 }
3252
3253 if (m_wxwindow)
3254 {
3255 if (orient == wxHORIZONTAL)
3256 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
3257 else
3258 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
3259
3260 gtk_widget_set_usize( m_widget, m_width, m_height );
3261 }
3262 }
3263
3264 void wxWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) )
3265 {
3266 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3267
3268 wxCHECK_RET( m_wxwindow != NULL, _T("window needs client area for scrolling") );
3269
3270 if (orient == wxHORIZONTAL)
3271 {
3272 float fpos = (float)pos;
3273 if (fpos > m_hAdjust->upper - m_hAdjust->page_size) fpos = m_hAdjust->upper - m_hAdjust->page_size;
3274 if (fpos < 0.0) fpos = 0.0;
3275 m_oldHorizontalPos = fpos;
3276
3277 if (fabs(fpos-m_hAdjust->value) < 0.2) return;
3278 m_hAdjust->value = fpos;
3279 }
3280 else
3281 {
3282 float fpos = (float)pos;
3283 if (fpos > m_vAdjust->upper - m_vAdjust->page_size) fpos = m_vAdjust->upper - m_vAdjust->page_size;
3284 if (fpos < 0.0) fpos = 0.0;
3285 m_oldVerticalPos = fpos;
3286
3287 if (fabs(fpos-m_vAdjust->value) < 0.2) return;
3288 m_vAdjust->value = fpos;
3289 }
3290
3291 if (!m_isScrolling)
3292 {
3293 if (m_wxwindow->window)
3294 {
3295 if (orient == wxHORIZONTAL)
3296 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" );
3297 else
3298 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" );
3299 }
3300 }
3301 }
3302
3303 int wxWindow::GetScrollThumb( int orient ) const
3304 {
3305 wxCHECK_MSG( m_widget != NULL, 0, _T("invalid window") );
3306
3307 wxCHECK_MSG( m_wxwindow != NULL, 0, _T("window needs client area for scrolling") );
3308
3309 if (orient == wxHORIZONTAL)
3310 return (int)(m_hAdjust->page_size+0.5);
3311 else
3312 return (int)(m_vAdjust->page_size+0.5);
3313 }
3314
3315 int wxWindow::GetScrollPos( int orient ) const
3316 {
3317 wxCHECK_MSG( m_widget != NULL, 0, _T("invalid window") );
3318
3319 wxCHECK_MSG( m_wxwindow != NULL, 0, _T("window needs client area for scrolling") );
3320
3321 if (orient == wxHORIZONTAL)
3322 return (int)(m_hAdjust->value+0.5);
3323 else
3324 return (int)(m_vAdjust->value+0.5);
3325 }
3326
3327 int wxWindow::GetScrollRange( int orient ) const
3328 {
3329 wxCHECK_MSG( m_widget != NULL, 0, _T("invalid window") );
3330
3331 wxCHECK_MSG( m_wxwindow != NULL, 0, _T("window needs client area for scrolling") );
3332
3333 if (orient == wxHORIZONTAL)
3334 return (int)(m_hAdjust->upper+0.5);
3335 else
3336 return (int)(m_vAdjust->upper+0.5);
3337 }
3338
3339 void wxWindow::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) )
3340 {
3341 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3342
3343 wxCHECK_RET( m_wxwindow != NULL, _T("window needs client area for scrolling") );
3344
3345 wxNode *node = m_children.First();
3346 while (node)
3347 {
3348 wxWindow *child = (wxWindow*) node->Data();
3349 child->Move( child->m_x + dx, child->m_y + dy );
3350 node = node->Next();
3351 }
3352
3353 int cw = 0;
3354 int ch = 0;
3355 GetClientSize( &cw, &ch );
3356
3357 int w = cw - abs(dx);
3358 int h = ch - abs(dy);
3359 if ((h < 0) || (w < 0))
3360 {
3361 Refresh();
3362 return;
3363 }
3364 int s_x = 0;
3365 int s_y = 0;
3366 if (dx < 0) s_x = -dx;
3367 if (dy < 0) s_y = -dy;
3368 int d_x = 0;
3369 int d_y = 0;
3370 if (dx > 0) d_x = dx;
3371 if (dy > 0) d_y = dy;
3372
3373 if (!m_scrollGC)
3374 {
3375 m_scrollGC = gdk_gc_new( m_wxwindow->window );
3376 gdk_gc_set_exposures( m_scrollGC, TRUE );
3377 }
3378
3379 gdk_window_copy_area( m_wxwindow->window, m_scrollGC, d_x, d_y,
3380 m_wxwindow->window, s_x, s_y, w, h );
3381
3382 wxRect rect;
3383 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
3384 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
3385 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
3386 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
3387
3388 Refresh( TRUE, &rect );
3389 }
3390
3391 //-------------------------------------------------------------------------------------
3392 // Layout
3393 //-------------------------------------------------------------------------------------
3394
3395 wxLayoutConstraints *wxWindow::GetConstraints() const
3396 {
3397 return m_constraints;
3398 }
3399
3400 void wxWindow::SetConstraints( wxLayoutConstraints *constraints )
3401 {
3402 if (m_constraints)
3403 {
3404 UnsetConstraints(m_constraints);
3405 delete m_constraints;
3406 }
3407 m_constraints = constraints;
3408 if (m_constraints)
3409 {
3410 // Make sure other windows know they're part of a 'meaningful relationship'
3411 if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this))
3412 m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3413 if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this))
3414 m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3415 if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this))
3416 m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3417 if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this))
3418 m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3419 if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this))
3420 m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3421 if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this))
3422 m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3423 if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this))
3424 m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3425 if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this))
3426 m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3427 }
3428 ;
3429 }
3430 ;
3431
3432 void wxWindow::SetAutoLayout( bool autoLayout )
3433 {
3434 m_autoLayout = autoLayout;
3435 }
3436
3437 bool wxWindow::GetAutoLayout() const
3438 {
3439 return m_autoLayout;
3440 }
3441
3442 wxSizer *wxWindow::GetSizer() const
3443 {
3444 return m_windowSizer;
3445 }
3446
3447 void wxWindow::SetSizerParent( wxWindow *win )
3448 {
3449 m_sizerParent = win;
3450 }
3451
3452 wxWindow *wxWindow::GetSizerParent() const
3453 {
3454 return m_sizerParent;
3455 }
3456
3457 // This removes any dangling pointers to this window
3458 // in other windows' constraintsInvolvedIn lists.
3459 void wxWindow::UnsetConstraints(wxLayoutConstraints *c)
3460 {
3461 if (c)
3462 {
3463 if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this))
3464 c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3465 if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this))
3466 c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3467 if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this))
3468 c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3469 if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this))
3470 c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3471 if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this))
3472 c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3473 if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this))
3474 c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3475 if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this))
3476 c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3477 if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this))
3478 c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3479 }
3480 }
3481
3482 // Back-pointer to other windows we're involved with, so if we delete
3483 // this window, we must delete any constraints we're involved with.
3484 void wxWindow::AddConstraintReference(wxWindow *otherWin)
3485 {
3486 if (!m_constraintsInvolvedIn)
3487 m_constraintsInvolvedIn = new wxList;
3488 if (!m_constraintsInvolvedIn->Member(otherWin))
3489 m_constraintsInvolvedIn->Append(otherWin);
3490 }
3491
3492 // REMOVE back-pointer to other windows we're involved with.
3493 void wxWindow::RemoveConstraintReference(wxWindow *otherWin)
3494 {
3495 if (m_constraintsInvolvedIn)
3496 m_constraintsInvolvedIn->DeleteObject(otherWin);
3497 }
3498
3499 // Reset any constraints that mention this window
3500 void wxWindow::DeleteRelatedConstraints()
3501 {
3502 if (m_constraintsInvolvedIn)
3503 {
3504 wxNode *node = m_constraintsInvolvedIn->First();
3505 while (node)
3506 {
3507 wxWindow *win = (wxWindow *)node->Data();
3508 wxNode *next = node->Next();
3509 wxLayoutConstraints *constr = win->GetConstraints();
3510
3511 // Reset any constraints involving this window
3512 if (constr)
3513 {
3514 constr->left.ResetIfWin((wxWindow *)this);
3515 constr->top.ResetIfWin((wxWindow *)this);
3516 constr->right.ResetIfWin((wxWindow *)this);
3517 constr->bottom.ResetIfWin((wxWindow *)this);
3518 constr->width.ResetIfWin((wxWindow *)this);
3519 constr->height.ResetIfWin((wxWindow *)this);
3520 constr->centreX.ResetIfWin((wxWindow *)this);
3521 constr->centreY.ResetIfWin((wxWindow *)this);
3522 }
3523 delete node;
3524 node = next;
3525 }
3526 delete m_constraintsInvolvedIn;
3527 m_constraintsInvolvedIn = (wxList *) NULL;
3528 }
3529 }
3530
3531 void wxWindow::SetSizer(wxSizer *sizer)
3532 {
3533 m_windowSizer = sizer;
3534 if (sizer)
3535 sizer->SetSizerParent((wxWindow *)this);
3536 }
3537
3538 /*
3539 * New version
3540 */
3541
3542 bool wxWindow::Layout()
3543 {
3544 if (GetConstraints())
3545 {
3546 int w, h;
3547 GetClientSize(&w, &h);
3548 GetConstraints()->width.SetValue(w);
3549 GetConstraints()->height.SetValue(h);
3550 }
3551
3552 // If top level (one sizer), evaluate the sizer's constraints.
3553 if (GetSizer())
3554 {
3555 int noChanges;
3556 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
3557 GetSizer()->LayoutPhase1(&noChanges);
3558 GetSizer()->LayoutPhase2(&noChanges);
3559 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
3560
3561 return TRUE;
3562 }
3563 else
3564 {
3565 // Otherwise, evaluate child constraints
3566 ResetConstraints(); // Mark all constraints as unevaluated
3567 DoPhase(1); // Just one phase need if no sizers involved
3568 DoPhase(2);
3569 SetConstraintSizes(); // Recursively set the real window sizes
3570 }
3571 return TRUE;
3572 }
3573
3574
3575 // Do a phase of evaluating constraints:
3576 // the default behaviour. wxSizers may do a similar
3577 // thing, but also impose their own 'constraints'
3578 // and order the evaluation differently.
3579 bool wxWindow::LayoutPhase1(int *noChanges)
3580 {
3581 wxLayoutConstraints *constr = GetConstraints();
3582 if (constr)
3583 {
3584 return constr->SatisfyConstraints((wxWindow *)this, noChanges);
3585 }
3586 else
3587 return TRUE;
3588 }
3589
3590 bool wxWindow::LayoutPhase2(int *noChanges)
3591 {
3592 *noChanges = 0;
3593
3594 // Layout children
3595 DoPhase(1);
3596 DoPhase(2);
3597 return TRUE;
3598 }
3599
3600 // Do a phase of evaluating child constraints
3601 bool wxWindow::DoPhase(int phase)
3602 {
3603 int noIterations = 0;
3604 int maxIterations = 500;
3605 int noChanges = 1;
3606 int noFailures = 0;
3607 wxList succeeded;
3608 while ((noChanges > 0) && (noIterations < maxIterations))
3609 {
3610 noChanges = 0;
3611 noFailures = 0;
3612 wxNode *node = m_children.First();
3613 while (node)
3614 {
3615 wxWindow *child = (wxWindow *)node->Data();
3616 if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog)))
3617 {
3618 wxLayoutConstraints *constr = child->GetConstraints();
3619 if (constr)
3620 {
3621 if (succeeded.Member(child))
3622 {
3623 }
3624 else
3625 {
3626 int tempNoChanges = 0;
3627 bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
3628 noChanges += tempNoChanges;
3629 if (success)
3630 {
3631 succeeded.Append(child);
3632 }
3633 }
3634 }
3635 }
3636 node = node->Next();
3637 }
3638 noIterations ++;
3639 }
3640 return TRUE;
3641 }
3642
3643 void wxWindow::ResetConstraints()
3644 {
3645 wxLayoutConstraints *constr = GetConstraints();
3646 if (constr)
3647 {
3648 constr->left.SetDone(FALSE);
3649 constr->top.SetDone(FALSE);
3650 constr->right.SetDone(FALSE);
3651 constr->bottom.SetDone(FALSE);
3652 constr->width.SetDone(FALSE);
3653 constr->height.SetDone(FALSE);
3654 constr->centreX.SetDone(FALSE);
3655 constr->centreY.SetDone(FALSE);
3656 }
3657 wxNode *node = m_children.First();
3658 while (node)
3659 {
3660 wxWindow *win = (wxWindow *)node->Data();
3661 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
3662 win->ResetConstraints();
3663 node = node->Next();
3664 }
3665 }
3666
3667 // Need to distinguish between setting the 'fake' size for
3668 // windows and sizers, and setting the real values.
3669 void wxWindow::SetConstraintSizes(bool recurse)
3670 {
3671 wxLayoutConstraints *constr = GetConstraints();
3672 if (constr && constr->left.GetDone() && constr->right.GetDone() &&
3673 constr->width.GetDone() && constr->height.GetDone())
3674 {
3675 int x = constr->left.GetValue();
3676 int y = constr->top.GetValue();
3677 int w = constr->width.GetValue();
3678 int h = constr->height.GetValue();
3679
3680 // If we don't want to resize this window, just move it...
3681 if ((constr->width.GetRelationship() != wxAsIs) ||
3682 (constr->height.GetRelationship() != wxAsIs))
3683 {
3684 // Calls Layout() recursively. AAAGH. How can we stop that.
3685 // Simply take Layout() out of non-top level OnSizes.
3686 SizerSetSize(x, y, w, h);
3687 }
3688 else
3689 {
3690 SizerMove(x, y);
3691 }
3692 }
3693 else if (constr)
3694 {
3695 wxChar *windowClass = this->GetClassInfo()->GetClassName();
3696
3697 wxString winName;
3698 if (GetName() == _T(""))
3699 winName = _T("unnamed");
3700 else
3701 winName = GetName();
3702 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
3703 (const wxChar *)windowClass,
3704 (const wxChar *)winName);
3705 if (!constr->left.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
3706 if (!constr->right.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
3707 if (!constr->width.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
3708 if (!constr->height.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
3709 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
3710 }
3711
3712 if (recurse)
3713 {
3714 wxNode *node = m_children.First();
3715 while (node)
3716 {
3717 wxWindow *win = (wxWindow *)node->Data();
3718 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
3719 win->SetConstraintSizes();
3720 node = node->Next();
3721 }
3722 }
3723 }
3724
3725 // This assumes that all sizers are 'on' the same
3726 // window, i.e. the parent of this window.
3727 void wxWindow::TransformSizerToActual(int *x, int *y) const
3728 {
3729 if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) ||
3730 m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) )
3731 return;
3732
3733 int xp, yp;
3734 m_sizerParent->GetPosition(&xp, &yp);
3735 m_sizerParent->TransformSizerToActual(&xp, &yp);
3736 *x += xp;
3737 *y += yp;
3738 }
3739
3740 void wxWindow::SizerSetSize(int x, int y, int w, int h)
3741 {
3742 int xx = x;
3743 int yy = y;
3744 TransformSizerToActual(&xx, &yy);
3745 SetSize(xx, yy, w, h);
3746 }
3747
3748 void wxWindow::SizerMove(int x, int y)
3749 {
3750 int xx = x;
3751 int yy = y;
3752 TransformSizerToActual(&xx, &yy);
3753 Move(xx, yy);
3754 }
3755
3756 // Only set the size/position of the constraint (if any)
3757 void wxWindow::SetSizeConstraint(int x, int y, int w, int h)
3758 {
3759 wxLayoutConstraints *constr = GetConstraints();
3760 if (constr)
3761 {
3762 if (x != -1)
3763 {
3764 constr->left.SetValue(x);
3765 constr->left.SetDone(TRUE);
3766 }
3767 if (y != -1)
3768 {
3769 constr->top.SetValue(y);
3770 constr->top.SetDone(TRUE);
3771 }
3772 if (w != -1)
3773 {
3774 constr->width.SetValue(w);
3775 constr->width.SetDone(TRUE);
3776 }
3777 if (h != -1)
3778 {
3779 constr->height.SetValue(h);
3780 constr->height.SetDone(TRUE);
3781 }
3782 }
3783 }
3784
3785 void wxWindow::MoveConstraint(int x, int y)
3786 {
3787 wxLayoutConstraints *constr = GetConstraints();
3788 if (constr)
3789 {
3790 if (x != -1)
3791 {
3792 constr->left.SetValue(x);
3793 constr->left.SetDone(TRUE);
3794 }
3795 if (y != -1)
3796 {
3797 constr->top.SetValue(y);
3798 constr->top.SetDone(TRUE);
3799 }
3800 }
3801 }
3802
3803 void wxWindow::GetSizeConstraint(int *w, int *h) const
3804 {
3805 wxLayoutConstraints *constr = GetConstraints();
3806 if (constr)
3807 {
3808 *w = constr->width.GetValue();
3809 *h = constr->height.GetValue();
3810 }
3811 else
3812 GetSize(w, h);
3813 }
3814
3815 void wxWindow::GetClientSizeConstraint(int *w, int *h) const
3816 {
3817 wxLayoutConstraints *constr = GetConstraints();
3818 if (constr)
3819 {
3820 *w = constr->width.GetValue();
3821 *h = constr->height.GetValue();
3822 }
3823 else
3824 GetClientSize(w, h);
3825 }
3826
3827 void wxWindow::GetPositionConstraint(int *x, int *y) const
3828 {
3829 wxLayoutConstraints *constr = GetConstraints();
3830 if (constr)
3831 {
3832 *x = constr->left.GetValue();
3833 *y = constr->top.GetValue();
3834 }
3835 else
3836 GetPosition(x, y);
3837 }
3838