]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/window.cpp
Chnages to focus code with debug code
[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( GTK_WIDGET(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 gtk_widget_show( m_wxwindow );
1602
1603 #ifdef __WXDEBUG__
1604 debug_focus_in( m_wxwindow, _T("wxWindow::m_wxwindow"), name );
1605 #endif
1606
1607 gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
1608
1609 #if (GTK_MINOR_VERSION > 0)
1610 GtkMyFixed *myfixed = GTK_MYFIXED(m_wxwindow);
1611
1612 if (m_windowStyle & wxRAISED_BORDER)
1613 {
1614 gtk_myfixed_set_shadow_type( myfixed, GTK_SHADOW_OUT );
1615 }
1616 else if (m_windowStyle & wxSUNKEN_BORDER)
1617 {
1618 gtk_myfixed_set_shadow_type( myfixed, GTK_SHADOW_IN );
1619 }
1620 else
1621 {
1622 gtk_myfixed_set_shadow_type( myfixed, GTK_SHADOW_NONE );
1623 }
1624 #else
1625 GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport);
1626
1627 if (m_windowStyle & wxRAISED_BORDER)
1628 {
1629 gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_OUT );
1630 }
1631 else if (m_windowStyle & wxSUNKEN_BORDER)
1632 {
1633 gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_IN );
1634 }
1635 else
1636 {
1637 gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE );
1638 }
1639 #endif
1640
1641 /* we always allow a window to get the focus as long as it
1642 doesn't have any children. */
1643 if (m_windowStyle & wxTAB_TRAVERSAL)
1644 {
1645 GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
1646 m_acceptsFocus = FALSE;
1647 }
1648 else
1649 {
1650 GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
1651 m_acceptsFocus = TRUE;
1652 }
1653
1654 /* grab the actual focus */
1655 // gtk_widget_grab_focus( m_wxwindow );
1656
1657 #if (GTK_MINOR_VERSION == 0)
1658 // shut the viewport up
1659 gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
1660 gtk_viewport_set_vadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
1661 #endif
1662
1663 // I _really_ don't want scrollbars in the beginning
1664 m_vAdjust->lower = 0.0;
1665 m_vAdjust->upper = 1.0;
1666 m_vAdjust->value = 0.0;
1667 m_vAdjust->step_increment = 1.0;
1668 m_vAdjust->page_increment = 1.0;
1669 m_vAdjust->page_size = 5.0;
1670 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
1671 m_hAdjust->lower = 0.0;
1672 m_hAdjust->upper = 1.0;
1673 m_hAdjust->value = 0.0;
1674 m_hAdjust->step_increment = 1.0;
1675 m_hAdjust->page_increment = 1.0;
1676 m_hAdjust->page_size = 5.0;
1677 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
1678
1679 // these handlers block mouse events to any window during scrolling
1680 // such as motion events and prevent GTK and wxWindows from fighting
1681 // over where the slider should be
1682
1683 gtk_signal_connect( GTK_OBJECT(s_window->vscrollbar), "button_press_event",
1684 (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this );
1685
1686 gtk_signal_connect( GTK_OBJECT(s_window->hscrollbar), "button_press_event",
1687 (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this );
1688
1689 gtk_signal_connect( GTK_OBJECT(s_window->vscrollbar), "button_release_event",
1690 (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this );
1691
1692 gtk_signal_connect( GTK_OBJECT(s_window->hscrollbar), "button_release_event",
1693 (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this );
1694
1695 // these handlers get notified when screen updates are required either when
1696 // scrolling or when the window size (and therefore scrollbar configuration)
1697 // has changed
1698
1699 gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed",
1700 (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this );
1701 gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed",
1702 (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this );
1703
1704 gtk_signal_connect( GTK_OBJECT(m_hAdjust), "changed",
1705 (GtkSignalFunc) gtk_window_hscroll_change_callback, (gpointer) this );
1706 gtk_signal_connect(GTK_OBJECT(m_vAdjust), "changed",
1707 (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this );
1708
1709 if (m_parent) m_parent->AddChild( this );
1710
1711 (m_parent->m_insertCallback)( m_parent, this );
1712
1713 PostCreation();
1714
1715 Show( TRUE );
1716
1717 return TRUE;
1718 }
1719
1720 wxWindow::~wxWindow()
1721 {
1722 m_hasVMT = FALSE;
1723
1724 #if wxUSE_DRAG_AND_DROP
1725 if (m_dropTarget)
1726 {
1727 delete m_dropTarget;
1728 m_dropTarget = (wxDropTarget*) NULL;
1729 }
1730 #endif
1731
1732 #if wxUSE_TOOLTIPS
1733 if (m_toolTip)
1734 {
1735 delete m_toolTip;
1736 m_toolTip = (wxToolTip*) NULL;
1737 }
1738 #endif // wxUSE_TOOLTIPS
1739
1740 if (m_widget) Show( FALSE );
1741
1742 DestroyChildren();
1743
1744 if (m_parent) m_parent->RemoveChild( this );
1745
1746 if (m_widgetStyle) gtk_style_unref( m_widgetStyle );
1747
1748 if (m_scrollGC) gdk_gc_unref( m_scrollGC );
1749
1750 if (m_wxwindow) gtk_widget_destroy( m_wxwindow );
1751
1752 if (m_widget) gtk_widget_destroy( m_widget );
1753
1754 DeleteRelatedConstraints();
1755 if (m_constraints)
1756 {
1757 /* This removes any dangling pointers to this window
1758 * in other windows' constraintsInvolvedIn lists. */
1759 UnsetConstraints(m_constraints);
1760 delete m_constraints;
1761 m_constraints = (wxLayoutConstraints *) NULL;
1762 }
1763
1764 if (m_windowSizer)
1765 {
1766 delete m_windowSizer;
1767 m_windowSizer = (wxSizer *) NULL;
1768 }
1769 /* If this is a child of a sizer, remove self from parent */
1770 if (m_sizerParent) m_sizerParent->RemoveChild((wxWindow *)this);
1771
1772 /* Just in case the window has been Closed, but
1773 * we're then deleting immediately: don't leave
1774 * dangling pointers. */
1775 wxPendingDelete.DeleteObject(this);
1776
1777 /* Just in case we've loaded a top-level window via
1778 * wxWindow::LoadNativeDialog but we weren't a dialog
1779 * class */
1780 wxTopLevelWindows.DeleteObject(this);
1781
1782 if (m_windowValidator) delete m_windowValidator;
1783
1784 if (m_clientObject) delete m_clientObject;
1785 }
1786
1787 void wxWindow::PreCreation( wxWindow *parent, wxWindowID id,
1788 const wxPoint &pos, const wxSize &size,
1789 long style, const wxString &name )
1790 {
1791 wxASSERT_MSG( (!m_needParent) || (parent), _T("Need complete parent.") );
1792
1793 m_widget = (GtkWidget*) NULL;
1794 m_wxwindow = (GtkWidget*) NULL;
1795 m_hasVMT = FALSE;
1796 m_parent = parent;
1797 m_children.DeleteContents( FALSE );
1798
1799 m_width = size.x;
1800 if (m_width == -1) m_width = 20;
1801 m_height = size.y;
1802 if (m_height == -1) m_height = 20;
1803
1804 m_x = (int)pos.x;
1805 m_y = (int)pos.y;
1806
1807 if (!m_needParent) /* some reasonable defaults */
1808 {
1809 if (m_x == -1)
1810 {
1811 m_x = (gdk_screen_width () - m_width) / 2;
1812 if (m_x < 10) m_x = 10;
1813 }
1814 if (m_y == -1)
1815 {
1816 m_y = (gdk_screen_height () - m_height) / 2;
1817 if (m_y < 10) m_y = 10;
1818 }
1819 }
1820
1821 m_minWidth = -1;
1822 m_minHeight = -1;
1823 m_maxWidth = -1;
1824 m_maxHeight = -1;
1825
1826 m_retCode = 0;
1827
1828 m_eventHandler = this;
1829
1830 m_windowId = id == -1 ? wxNewId() : id;
1831
1832 m_sizeSet = FALSE;
1833
1834 m_cursor = *wxSTANDARD_CURSOR;
1835 m_font = *wxSWISS_FONT;
1836 m_backgroundColour = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
1837 m_foregroundColour = *wxBLACK;
1838 m_windowStyle = style;
1839 m_windowName = name;
1840
1841 m_constraints = (wxLayoutConstraints *) NULL;
1842 m_constraintsInvolvedIn = (wxList *) NULL;
1843 m_windowSizer = (wxSizer *) NULL;
1844 m_sizerParent = (wxWindow *) NULL;
1845 m_autoLayout = FALSE;
1846
1847 m_hasScrolling = FALSE;
1848 m_isScrolling = FALSE;
1849 m_hAdjust = (GtkAdjustment *) NULL;
1850 m_vAdjust = (GtkAdjustment *) NULL;
1851 m_oldHorizontalPos = 0.0;
1852 m_oldVerticalPos = 0.0;
1853
1854 m_isShown = FALSE;
1855 m_isEnabled = TRUE;
1856
1857 #if wxUSE_DRAG_AND_DROP
1858 m_dropTarget = (wxDropTarget *) NULL;
1859 #endif
1860 m_resizing = FALSE;
1861 m_windowValidator = (wxValidator *) NULL;
1862 m_scrollGC = (GdkGC*) NULL;
1863 m_widgetStyle = (GtkStyle*) NULL;
1864
1865 m_clientObject = (wxClientData*)NULL;
1866 m_clientData = NULL;
1867
1868 m_isStaticBox = FALSE;
1869
1870 #if wxUSE_TOOLTIPS
1871 m_toolTip = (wxToolTip*) NULL;
1872 #endif // wxUSE_TOOLTIPS
1873 }
1874
1875 void wxWindow::PostCreation()
1876 {
1877 wxASSERT_MSG( (m_widget != NULL), _T("invalid window") );
1878
1879 if (m_wxwindow)
1880 {
1881 /* these get reported to wxWindows -> wxPaintEvent */
1882 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event",
1883 GTK_SIGNAL_FUNC(gtk_window_expose_callback), (gpointer)this );
1884
1885 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw",
1886 GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this );
1887
1888 #if (GTK_MINOR_VERSION > 0)
1889 /* these are called when the "sunken" or "raised" borders are drawn */
1890 gtk_signal_connect( GTK_OBJECT(m_widget), "expose_event",
1891 GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
1892
1893 gtk_signal_connect( GTK_OBJECT(m_widget), "draw",
1894 GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
1895 #endif
1896 }
1897
1898 GtkWidget *connect_widget = GetConnectWidget();
1899
1900 ConnectWidget( connect_widget );
1901
1902 /* we cannot set colours, fonts and cursors before the widget has
1903 been realized, so we do this directly after realization */
1904 gtk_signal_connect( GTK_OBJECT(connect_widget), "realize",
1905 GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this );
1906
1907 m_hasVMT = TRUE;
1908 }
1909
1910 void wxWindow::ConnectWidget( GtkWidget *widget )
1911 {
1912 gtk_signal_connect( GTK_OBJECT(widget), "key_press_event",
1913 GTK_SIGNAL_FUNC(gtk_window_key_press_callback), (gpointer)this );
1914
1915 gtk_signal_connect( GTK_OBJECT(widget), "key_release_event",
1916 GTK_SIGNAL_FUNC(gtk_window_key_release_callback), (gpointer)this );
1917
1918 gtk_signal_connect( GTK_OBJECT(widget), "button_press_event",
1919 GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this );
1920
1921 gtk_signal_connect( GTK_OBJECT(widget), "button_release_event",
1922 GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
1923
1924 gtk_signal_connect( GTK_OBJECT(widget), "motion_notify_event",
1925 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
1926
1927 gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event",
1928 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
1929
1930 gtk_signal_connect( GTK_OBJECT(widget), "focus_out_event",
1931 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
1932
1933 gtk_signal_connect( GTK_OBJECT(widget), "enter_notify_event",
1934 GTK_SIGNAL_FUNC(gtk_window_enter_callback), (gpointer)this );
1935
1936 gtk_signal_connect( GTK_OBJECT(widget), "leave_notify_event",
1937 GTK_SIGNAL_FUNC(gtk_window_leave_callback), (gpointer)this );
1938 }
1939
1940 bool wxWindow::HasVMT()
1941 {
1942 return m_hasVMT;
1943 }
1944
1945 bool wxWindow::Close( bool force )
1946 {
1947 wxASSERT_MSG( (m_widget != NULL), _T("invalid window") );
1948
1949 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
1950 event.SetEventObject(this);
1951 event.SetCanVeto(!force);
1952
1953 /* return FALSE if window wasn't closed because the application vetoed the
1954 * close event */
1955 return GetEventHandler()->ProcessEvent(event) && !event.GetVeto();
1956 }
1957
1958 bool wxWindow::Destroy()
1959 {
1960 wxASSERT_MSG( (m_widget != NULL), _T("invalid window") );
1961
1962 m_hasVMT = FALSE;
1963 delete this;
1964 return TRUE;
1965 }
1966
1967 bool wxWindow::DestroyChildren()
1968 {
1969 wxNode *node;
1970 while ((node = m_children.First()) != (wxNode *)NULL)
1971 {
1972 wxWindow *child;
1973 if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL)
1974 {
1975 delete child;
1976 if (m_children.Member(child)) delete node;
1977 }
1978 }
1979 return TRUE;
1980 }
1981
1982 void wxWindow::PrepareDC( wxDC &WXUNUSED(dc) )
1983 {
1984 // are we to set fonts here ?
1985 }
1986
1987 void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
1988 {
1989 wxASSERT_MSG( (m_widget != NULL), _T("invalid window") );
1990 wxASSERT_MSG( (m_parent != NULL), _T("wxWindow::SetSize requires parent.\n") );
1991
1992 if (m_resizing) return; /* I don't like recursions */
1993 m_resizing = TRUE;
1994
1995 if (m_parent->m_wxwindow == NULL) /* i.e. wxNotebook */
1996 {
1997 /* don't set the size for children of wxNotebook, just take the values. */
1998 m_x = x;
1999 m_y = y;
2000 m_width = width;
2001 m_height = height;
2002 }
2003 else
2004 {
2005 int old_width = m_width;
2006 int old_height = m_height;
2007
2008 if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING)
2009 {
2010 if (x != -1) m_x = x;
2011 if (y != -1) m_y = y;
2012 if (width != -1) m_width = width;
2013 if (height != -1) m_height = height;
2014 }
2015 else
2016 {
2017 m_x = x;
2018 m_y = y;
2019 m_width = width;
2020 m_height = height;
2021 }
2022
2023 if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH)
2024 {
2025 if (width == -1) m_width = 80;
2026 }
2027
2028 if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT)
2029 {
2030 if (height == -1) m_height = 26;
2031 }
2032
2033 if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
2034 if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
2035 if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth;
2036 if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight;
2037
2038 if (GTK_WIDGET_HAS_DEFAULT(m_widget))
2039 {
2040 /* the default button has a border around it */
2041 int border = 5;
2042
2043 gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x-border, m_y-border );
2044
2045 gtk_widget_set_usize( m_widget, m_width+2*border, m_height+2*border );
2046 }
2047 else
2048 {
2049 gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x, m_y );
2050
2051 if ((old_width != m_width) || (old_height != m_height))
2052 gtk_widget_set_usize( m_widget, m_width, m_height );
2053 }
2054 }
2055
2056 m_sizeSet = TRUE;
2057
2058 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
2059 event.SetEventObject( this );
2060 GetEventHandler()->ProcessEvent( event );
2061
2062 m_resizing = FALSE;
2063 }
2064
2065 void wxWindow::OnInternalIdle()
2066 {
2067 UpdateWindowUI();
2068 }
2069
2070 void wxWindow::GetSize( int *width, int *height ) const
2071 {
2072 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2073
2074 if (width) (*width) = m_width;
2075 if (height) (*height) = m_height;
2076 }
2077
2078 void wxWindow::DoSetClientSize( int width, int height )
2079 {
2080 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2081
2082 if (!m_wxwindow)
2083 {
2084 SetSize( width, height );
2085 }
2086 else
2087 {
2088 int dw = 0;
2089 int dh = 0;
2090
2091 if (!m_hasScrolling)
2092 {
2093 GtkStyleClass *window_class = m_wxwindow->style->klass;
2094
2095 if ((m_windowStyle & wxRAISED_BORDER) ||
2096 (m_windowStyle & wxSUNKEN_BORDER))
2097 {
2098 dw += 2 * window_class->xthickness;
2099 dh += 2 * window_class->ythickness;
2100 }
2101 }
2102 else
2103 {
2104 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
2105 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
2106
2107 #if (GTK_MINOR_VERSION == 0)
2108 GtkWidget *viewport = scroll_window->viewport;
2109 GtkStyleClass *viewport_class = viewport->style->klass;
2110
2111 if ((m_windowStyle & wxRAISED_BORDER) ||
2112 (m_windowStyle & wxSUNKEN_BORDER))
2113 {
2114 dw += 2 * viewport_class->xthickness;
2115 dh += 2 * viewport_class->ythickness;
2116 }
2117 #endif
2118
2119 /*
2120 GtkWidget *hscrollbar = scroll_window->hscrollbar;
2121 GtkWidget *vscrollbar = scroll_window->vscrollbar;
2122
2123 we use this instead: range.slider_width = 11 + 2*2pts edge
2124 */
2125
2126 if (scroll_window->vscrollbar_visible)
2127 {
2128 dw += 15; /* dw += vscrollbar->allocation.width; */
2129 dw += scroll_class->scrollbar_spacing;
2130 }
2131
2132 if (scroll_window->hscrollbar_visible)
2133 {
2134 dh += 15; /* dh += hscrollbar->allocation.height; */
2135 dw += scroll_class->scrollbar_spacing;
2136 }
2137 }
2138
2139 SetSize( width+dw, height+dh );
2140 }
2141 }
2142
2143 void wxWindow::GetClientSize( int *width, int *height ) const
2144 {
2145 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2146
2147 if (!m_wxwindow)
2148 {
2149 if (width) (*width) = m_width;
2150 if (height) (*height) = m_height;
2151 }
2152 else
2153 {
2154 int dw = 0;
2155 int dh = 0;
2156
2157 if (!m_hasScrolling)
2158 {
2159 GtkStyleClass *window_class = m_wxwindow->style->klass;
2160
2161 if ((m_windowStyle & wxRAISED_BORDER) ||
2162 (m_windowStyle & wxSUNKEN_BORDER))
2163 {
2164 dw += 2 * window_class->xthickness;
2165 dh += 2 * window_class->ythickness;
2166 }
2167 }
2168 else
2169 {
2170 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
2171 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
2172
2173 #if (GTK_MINOR_VERSION == 0)
2174 GtkWidget *viewport = scroll_window->viewport;
2175 GtkStyleClass *viewport_class = viewport->style->klass;
2176
2177 if ((m_windowStyle & wxRAISED_BORDER) ||
2178 (m_windowStyle & wxSUNKEN_BORDER))
2179 {
2180 dw += 2 * viewport_class->xthickness;
2181 dh += 2 * viewport_class->ythickness;
2182 }
2183 #endif
2184 /*
2185 GtkWidget *hscrollbar = scroll_window->hscrollbar;
2186 GtkWidget *vscrollbar = scroll_window->vscrollbar;
2187
2188 we use this instead: range.slider_width = 11 + 2*2pts edge
2189 */
2190
2191 if (scroll_window->vscrollbar_visible)
2192 {
2193 dw += 15; /* dw += vscrollbar->allocation.width; */
2194 dw += scroll_class->scrollbar_spacing;
2195 }
2196
2197 if (scroll_window->hscrollbar_visible)
2198 {
2199 dh += 15; /* dh += hscrollbar->allocation.height; */
2200 dh += scroll_class->scrollbar_spacing;
2201 }
2202 }
2203
2204 if (width) (*width) = m_width - dw;
2205 if (height) (*height) = m_height - dh;
2206 }
2207 }
2208
2209 void wxWindow::GetPosition( int *x, int *y ) const
2210 {
2211 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2212
2213 if (x) (*x) = m_x;
2214 if (y) (*y) = m_y;
2215 }
2216
2217 void wxWindow::ClientToScreen( int *x, int *y )
2218 {
2219 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2220
2221 if (!m_widget->window) return;
2222
2223 GdkWindow *source = (GdkWindow *) NULL;
2224 if (m_wxwindow)
2225 source = m_wxwindow->window;
2226 else
2227 source = m_widget->window;
2228
2229 int org_x = 0;
2230 int org_y = 0;
2231 gdk_window_get_origin( source, &org_x, &org_y );
2232
2233 if (!m_wxwindow)
2234 {
2235 if (GTK_WIDGET_NO_WINDOW (m_widget))
2236 {
2237 org_x += m_widget->allocation.x;
2238 org_y += m_widget->allocation.y;
2239 }
2240 }
2241
2242 if (x) *x += org_x;
2243 if (y) *y += org_y;
2244 }
2245
2246 void wxWindow::ScreenToClient( int *x, int *y )
2247 {
2248 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2249
2250 if (!m_widget->window) return;
2251
2252 GdkWindow *source = (GdkWindow *) NULL;
2253 if (m_wxwindow)
2254 source = m_wxwindow->window;
2255 else
2256 source = m_widget->window;
2257
2258 int org_x = 0;
2259 int org_y = 0;
2260 gdk_window_get_origin( source, &org_x, &org_y );
2261
2262 if (!m_wxwindow)
2263 {
2264 if (GTK_WIDGET_NO_WINDOW (m_widget))
2265 {
2266 org_x += m_widget->allocation.x;
2267 org_y += m_widget->allocation.y;
2268 }
2269 }
2270
2271 if (x) *x -= org_x;
2272 if (y) *y -= org_y;
2273 }
2274
2275 void wxWindow::Centre( int direction )
2276 {
2277 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2278
2279 int x = m_x;
2280 int y = m_y;
2281
2282 if (m_parent)
2283 {
2284 int p_w = 0;
2285 int p_h = 0;
2286 m_parent->GetSize( &p_w, &p_h );
2287 if (direction & wxHORIZONTAL == wxHORIZONTAL) x = (p_w - m_width) / 2;
2288 if (direction & wxVERTICAL == wxVERTICAL) y = (p_h - m_height) / 2;
2289 }
2290 else
2291 {
2292 if (direction & wxHORIZONTAL == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2;
2293 if (direction & wxVERTICAL == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2;
2294 }
2295
2296 Move( x, y );
2297 }
2298
2299 void wxWindow::Fit()
2300 {
2301 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2302
2303 int maxX = 0;
2304 int maxY = 0;
2305 wxNode *node = m_children.First();
2306 while (node)
2307 {
2308 wxWindow *win = (wxWindow *)node->Data();
2309 int wx, wy, ww, wh;
2310 win->GetPosition(&wx, &wy);
2311 win->GetSize(&ww, &wh);
2312 if (wx + ww > maxX) maxX = wx + ww;
2313 if (wy + wh > maxY) maxY = wy + wh;
2314
2315 node = node->Next();
2316 }
2317
2318 SetClientSize(maxX + 7, maxY + 14);
2319 }
2320
2321 void wxWindow::SetSizeHints( int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH) )
2322 {
2323 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2324
2325 m_minWidth = minW;
2326 m_minHeight = minH;
2327 m_maxWidth = maxW;
2328 m_maxHeight = maxH;
2329 }
2330
2331 void wxWindow::OnSize( wxSizeEvent &WXUNUSED(event) )
2332 {
2333 /* this is commented because it also is commented
2334 in wxMSW. before I get even more questions about
2335 this. */
2336 // if (GetAutoLayout()) Layout();
2337 }
2338
2339 bool wxWindow::Show( bool show )
2340 {
2341 wxCHECK_MSG( (m_widget != NULL), FALSE, _T("invalid window") );
2342
2343 if (show == m_isShown) return TRUE;
2344
2345 if (show)
2346 gtk_widget_show( m_widget );
2347 else
2348 gtk_widget_hide( m_widget );
2349
2350 m_isShown = show;
2351
2352 return TRUE;
2353 }
2354
2355 void wxWindow::Enable( bool enable )
2356 {
2357 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2358
2359 m_isEnabled = enable;
2360
2361 gtk_widget_set_sensitive( m_widget, enable );
2362 if (m_wxwindow) gtk_widget_set_sensitive( m_wxwindow, enable );
2363 }
2364
2365 int wxWindow::GetCharHeight() const
2366 {
2367 wxCHECK_MSG( (m_widget != NULL), 12, _T("invalid window") );
2368
2369 wxCHECK_MSG( m_font.Ok(), 12, _T("invalid font") );
2370
2371 GdkFont *font = m_font.GetInternalFont( 1.0 );
2372
2373 return font->ascent + font->descent;
2374 }
2375
2376 int wxWindow::GetCharWidth() const
2377 {
2378 wxCHECK_MSG( (m_widget != NULL), 8, _T("invalid window") );
2379
2380 wxCHECK_MSG( m_font.Ok(), 8, _T("invalid font") );
2381
2382 GdkFont *font = m_font.GetInternalFont( 1.0 );
2383
2384 return gdk_string_width( font, "H" );
2385 }
2386
2387 void wxWindow::GetTextExtent( const wxString& string, int *x, int *y,
2388 int *descent, int *externalLeading, const wxFont *theFont, bool WXUNUSED(use16) ) const
2389 {
2390 wxFont fontToUse = m_font;
2391 if (theFont) fontToUse = *theFont;
2392
2393 wxCHECK_RET( fontToUse.Ok(), _T("invalid font") );
2394
2395 GdkFont *font = fontToUse.GetInternalFont( 1.0 );
2396 if (x) (*x) = gdk_string_width( font, string.mbc_str() );
2397 if (y) (*y) = font->ascent + font->descent;
2398 if (descent) (*descent) = font->descent;
2399 if (externalLeading) (*externalLeading) = 0; // ??
2400 }
2401
2402 void wxWindow::MakeModal( bool modal )
2403 {
2404 return;
2405
2406 // Disable all other windows
2407 if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame)))
2408 {
2409 wxNode *node = wxTopLevelWindows.First();
2410 while (node)
2411 {
2412 wxWindow *win = (wxWindow *)node->Data();
2413 if (win != this) win->Enable(!modal);
2414
2415 node = node->Next();
2416 }
2417 }
2418 }
2419
2420 void wxWindow::OnKeyDown( wxKeyEvent &event )
2421 {
2422 event.SetEventType( wxEVT_CHAR );
2423
2424 if (!GetEventHandler()->ProcessEvent( event ))
2425 {
2426 event.Skip();
2427 }
2428 }
2429
2430 void wxWindow::SetFocus()
2431 {
2432 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2433
2434 GtkWidget *connect_widget = GetConnectWidget();
2435 if (connect_widget)
2436 {
2437 if (GTK_WIDGET_CAN_FOCUS(connect_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ )
2438 {
2439 gtk_widget_grab_focus (connect_widget);
2440 }
2441 else if (GTK_IS_CONTAINER(connect_widget))
2442 {
2443 gtk_container_focus( GTK_CONTAINER(connect_widget), GTK_DIR_TAB_FORWARD );
2444 }
2445 else
2446 {
2447 }
2448 }
2449 }
2450
2451 wxWindow *wxWindow::FindFocus()
2452 {
2453 return g_focusWindow;
2454 }
2455
2456 bool wxWindow::AcceptsFocus() const
2457 {
2458 return IsEnabled() && IsShown() && m_acceptsFocus;
2459 }
2460
2461 void wxWindow::AddChild( wxWindow *child )
2462 {
2463 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2464 wxCHECK_RET( (child != NULL), _T("invalid child") );
2465
2466 m_children.Append( child );
2467 }
2468
2469 wxWindow *wxWindow::ReParent( wxWindow *newParent )
2470 {
2471 wxCHECK_MSG( (m_widget != NULL), (wxWindow*) NULL, _T("invalid window") );
2472
2473 wxWindow *oldParent = GetParent();
2474
2475 if (oldParent) oldParent->RemoveChild( this );
2476
2477 gtk_widget_unparent( m_widget );
2478
2479 if (newParent)
2480 {
2481 newParent->AddChild( this );
2482 (newParent->m_insertCallback)( newParent, this );
2483 }
2484
2485 return oldParent;
2486 }
2487
2488 void wxWindow::RemoveChild( wxWindow *child )
2489 {
2490 m_children.DeleteObject( child );
2491 child->m_parent = (wxWindow *) NULL;
2492 }
2493
2494 void wxWindow::SetReturnCode( int retCode )
2495 {
2496 m_retCode = retCode;
2497 }
2498
2499 int wxWindow::GetReturnCode()
2500 {
2501 return m_retCode;
2502 }
2503
2504 void wxWindow::Raise()
2505 {
2506 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2507
2508 if (!m_widget->window) return;
2509
2510 if (m_widget) gdk_window_raise( m_widget->window );
2511 }
2512
2513 void wxWindow::Lower()
2514 {
2515 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2516
2517 if (!m_widget->window) return;
2518
2519 if (m_widget) gdk_window_lower( m_widget->window );
2520 }
2521
2522 wxEvtHandler *wxWindow::GetEventHandler() const
2523 {
2524 return m_eventHandler;
2525 }
2526
2527 void wxWindow::SetEventHandler( wxEvtHandler *handler )
2528 {
2529 m_eventHandler = handler;
2530 }
2531
2532 void wxWindow::PushEventHandler(wxEvtHandler *handler)
2533 {
2534 handler->SetNextHandler(GetEventHandler());
2535 SetEventHandler(handler);
2536 }
2537
2538 wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler)
2539 {
2540 if (GetEventHandler())
2541 {
2542 wxEvtHandler *handlerA = GetEventHandler();
2543 wxEvtHandler *handlerB = handlerA->GetNextHandler();
2544 handlerA->SetNextHandler((wxEvtHandler *) NULL);
2545 SetEventHandler(handlerB);
2546 if (deleteHandler)
2547 {
2548 delete handlerA;
2549 return (wxEvtHandler*) NULL;
2550 }
2551 else
2552 return handlerA;
2553 }
2554 else
2555 return (wxEvtHandler *) NULL;
2556 }
2557
2558 wxValidator *wxWindow::GetValidator()
2559 {
2560 return m_windowValidator;
2561 }
2562
2563 void wxWindow::SetValidator( const wxValidator& validator )
2564 {
2565 if (m_windowValidator) delete m_windowValidator;
2566 m_windowValidator = validator.Clone();
2567 if (m_windowValidator) m_windowValidator->SetWindow(this);
2568 }
2569
2570 void wxWindow::SetClientObject( wxClientData *data )
2571 {
2572 if (m_clientObject) delete m_clientObject;
2573 m_clientObject = data;
2574 }
2575
2576 wxClientData *wxWindow::GetClientObject()
2577 {
2578 return m_clientObject;
2579 }
2580
2581 void wxWindow::SetClientData( void *data )
2582 {
2583 m_clientData = data;
2584 }
2585
2586 void *wxWindow::GetClientData()
2587 {
2588 return m_clientData;
2589 }
2590
2591 bool wxWindow::IsBeingDeleted()
2592 {
2593 return FALSE;
2594 }
2595
2596 void wxWindow::SetId( wxWindowID id )
2597 {
2598 m_windowId = id;
2599 }
2600
2601 wxWindowID wxWindow::GetId() const
2602 {
2603 return m_windowId;
2604 }
2605
2606 void wxWindow::SetCursor( const wxCursor &cursor )
2607 {
2608 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2609
2610 if (cursor.Ok())
2611 {
2612 if (cursor == m_cursor) return;
2613 m_cursor = cursor;
2614 }
2615 else
2616 {
2617 m_cursor = *wxSTANDARD_CURSOR;
2618 }
2619
2620 if (!m_widget->window) return;
2621
2622 gdk_window_set_cursor( m_widget->window, m_cursor.GetCursor() );
2623
2624 if ((m_wxwindow) && (m_wxwindow->window))
2625 gdk_window_set_cursor( m_wxwindow->window, m_cursor.GetCursor() );
2626 }
2627
2628 void wxWindow::WarpPointer( int WXUNUSED(x), int WXUNUSED(y) )
2629 {
2630 // TODO
2631 }
2632
2633 void wxWindow::Refresh( bool eraseBackground, const wxRect *rect )
2634 {
2635 wxCHECK_RET( (m_widget != NULL), _T("invalid window") );
2636
2637 if (!m_widget->window) return;
2638
2639 if (eraseBackground && m_wxwindow && m_wxwindow->window)
2640 {
2641 if (rect)
2642 {
2643 gdk_window_clear_area( m_wxwindow->window,
2644 rect->x, rect->y,
2645 rect->width, rect->height );
2646 }
2647 else
2648 {
2649 gdk_window_clear( m_wxwindow->window );
2650 }
2651 }
2652
2653 if (!rect)
2654 {
2655 if (m_wxwindow)
2656 gtk_widget_draw( m_wxwindow, (GdkRectangle*) NULL );
2657 else
2658 gtk_widget_draw( m_widget, (GdkRectangle*) NULL );
2659 }
2660 else
2661 {
2662 GdkRectangle gdk_rect;
2663 gdk_rect.x = rect->x;
2664 gdk_rect.y = rect->y;
2665 gdk_rect.width = rect->width;
2666 gdk_rect.height = rect->height;
2667
2668 if (m_wxwindow)
2669 gtk_widget_draw( m_wxwindow, &gdk_rect );
2670 else
2671 gtk_widget_draw( m_widget, &gdk_rect );
2672 }
2673 }
2674
2675 wxRegion wxWindow::GetUpdateRegion() const
2676 {
2677 return m_updateRegion;
2678 }
2679
2680 bool wxWindow::IsExposed( int x, int y) const
2681 {
2682 return (m_updateRegion.Contains( x, y ) != wxOutRegion );
2683 }
2684
2685 bool wxWindow::IsExposed( int x, int y, int w, int h ) const
2686 {
2687 return (m_updateRegion.Contains( x, y, w, h ) != wxOutRegion );
2688 }
2689
2690 bool wxWindow::IsExposed( const wxPoint& pt ) const
2691 {
2692 return (m_updateRegion.Contains( pt.x, pt.y ) != wxOutRegion );
2693 }
2694
2695 bool wxWindow::IsExposed( const wxRect& rect ) const
2696 {
2697 return (m_updateRegion.Contains( rect.x, rect.y, rect.width, rect.height ) != wxOutRegion );
2698 }
2699
2700 void wxWindow::Clear()
2701 {
2702 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
2703
2704 if (!m_widget->window) return;
2705
2706 if (m_wxwindow && m_wxwindow->window)
2707 {
2708 gdk_window_clear( m_wxwindow->window );
2709 }
2710 }
2711
2712 #if wxUSE_TOOLTIPS
2713 void wxWindow::SetToolTip( const wxString &tip )
2714 {
2715 if (m_toolTip)
2716 {
2717 m_toolTip->SetTip( tip );
2718 }
2719 else
2720 {
2721 SetToolTip( new wxToolTip( tip ) );
2722 }
2723
2724 // setting empty tooltip text does not remove the tooltip any more for
2725 // wxMSW compatibility - use SetToolTip((wxToolTip *)NULL) for this
2726 }
2727
2728 void wxWindow::SetToolTip( wxToolTip *tip )
2729 {
2730 if (m_toolTip)
2731 {
2732 m_toolTip->SetTip( (char*) NULL );
2733 delete m_toolTip;
2734 }
2735
2736 m_toolTip = tip;
2737
2738 if (m_toolTip)
2739 m_toolTip->Apply( this );
2740 }
2741
2742 void wxWindow::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
2743 {
2744 gtk_tooltips_set_tip( tips, GetConnectWidget(), wxConv_current->cWX2MB(tip), (gchar*) NULL );
2745 }
2746 #endif // wxUSE_TOOLTIPS
2747
2748 wxColour wxWindow::GetBackgroundColour() const
2749 {
2750 return m_backgroundColour;
2751 }
2752
2753 void wxWindow::SetBackgroundColour( const wxColour &colour )
2754 {
2755 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
2756
2757 if (m_backgroundColour == colour) return;
2758
2759 m_backgroundColour = colour;
2760 if (!m_backgroundColour.Ok()) return;
2761
2762 GtkWidget *connect_widget = GetConnectWidget();
2763 if (!connect_widget->window) return;
2764
2765 if (m_wxwindow && m_wxwindow->window)
2766 {
2767 /* wxMSW doesn't clear the window here. I don't do that
2768 either to provide compatibility. call Clear() to do
2769 the job. */
2770
2771 m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_wxwindow->window ) );
2772 gdk_window_set_background( m_wxwindow->window, m_backgroundColour.GetColor() );
2773 }
2774
2775 wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
2776
2777 if (sysbg.Red() == colour.Red() &&
2778 sysbg.Green() == colour.Green() &&
2779 sysbg.Blue() == colour.Blue())
2780 {
2781 m_backgroundColour = wxNullColour;
2782 ApplyWidgetStyle();
2783 m_backgroundColour = sysbg;
2784 }
2785 else
2786 {
2787 ApplyWidgetStyle();
2788 }
2789 }
2790
2791 wxColour wxWindow::GetForegroundColour() const
2792 {
2793 return m_foregroundColour;
2794 }
2795
2796 void wxWindow::SetForegroundColour( const wxColour &colour )
2797 {
2798 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
2799
2800 if (m_foregroundColour == colour) return;
2801
2802 m_foregroundColour = colour;
2803 if (!m_foregroundColour.Ok()) return;
2804
2805 if (!m_widget->window) return;
2806
2807 wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
2808 if (sysbg.Red() == colour.Red() &&
2809 sysbg.Green() == colour.Green() &&
2810 sysbg.Blue() == colour.Blue())
2811 {
2812 m_backgroundColour = wxNullColour;
2813 ApplyWidgetStyle();
2814 m_backgroundColour = sysbg;
2815 }
2816 else
2817 {
2818 ApplyWidgetStyle();
2819 }
2820 }
2821
2822 GtkStyle *wxWindow::GetWidgetStyle()
2823 {
2824 if (m_widgetStyle) gtk_style_unref( m_widgetStyle );
2825
2826 m_widgetStyle =
2827 gtk_style_copy(
2828 gtk_widget_get_style( m_widget ) );
2829
2830 return m_widgetStyle;
2831 }
2832
2833 void wxWindow::SetWidgetStyle()
2834 {
2835 GtkStyle *style = GetWidgetStyle();
2836
2837 gdk_font_unref( style->font );
2838 style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
2839
2840 if (m_foregroundColour.Ok())
2841 {
2842 m_foregroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
2843 style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor();
2844 style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor();
2845 style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor();
2846 }
2847
2848 if (m_backgroundColour.Ok())
2849 {
2850 m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
2851 style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
2852 style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
2853 style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
2854 style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
2855 style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
2856 style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
2857 style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
2858 style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
2859 }
2860 }
2861
2862 void wxWindow::ApplyWidgetStyle()
2863 {
2864 }
2865
2866 bool wxWindow::Validate()
2867 {
2868 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
2869
2870 wxNode *node = m_children.First();
2871 while (node)
2872 {
2873 wxWindow *child = (wxWindow *)node->Data();
2874 if (child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this))
2875 {
2876 return FALSE;
2877 }
2878 node = node->Next();
2879 }
2880 return TRUE;
2881 }
2882
2883 bool wxWindow::TransferDataToWindow()
2884 {
2885 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
2886
2887 wxNode *node = m_children.First();
2888 while (node)
2889 {
2890 wxWindow *child = (wxWindow *)node->Data();
2891 if (child->GetValidator() && /* child->GetValidator()->Ok() && */
2892 !child->GetValidator()->TransferToWindow() )
2893 {
2894 wxMessageBox( _("Application Error"), _("Could not transfer data to window"), wxOK|wxICON_EXCLAMATION );
2895 return FALSE;
2896 }
2897 node = node->Next();
2898 }
2899 return TRUE;
2900 }
2901
2902 bool wxWindow::TransferDataFromWindow()
2903 {
2904 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
2905
2906 wxNode *node = m_children.First();
2907 while (node)
2908 {
2909 wxWindow *child = (wxWindow *)node->Data();
2910 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->TransferFromWindow() )
2911 {
2912 return FALSE;
2913 }
2914 node = node->Next();
2915 }
2916 return TRUE;
2917 }
2918
2919 void wxWindow::SetAcceleratorTable( const wxAcceleratorTable& accel )
2920 {
2921 m_acceleratorTable = accel;
2922 }
2923
2924 void wxWindow::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
2925 {
2926 TransferDataToWindow();
2927 }
2928
2929 void wxWindow::InitDialog()
2930 {
2931 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
2932
2933 wxInitDialogEvent event(GetId());
2934 event.SetEventObject( this );
2935 GetEventHandler()->ProcessEvent(event);
2936 }
2937
2938 static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
2939 {
2940 menu->SetInvokingWindow( win );
2941 wxNode *node = menu->GetItems().First();
2942 while (node)
2943 {
2944 wxMenuItem *menuitem = (wxMenuItem*)node->Data();
2945 if (menuitem->IsSubMenu())
2946 {
2947 SetInvokingWindow( menuitem->GetSubMenu(), win );
2948 }
2949 node = node->Next();
2950 }
2951 }
2952
2953 static gint gs_pop_x = 0;
2954 static gint gs_pop_y = 0;
2955
2956 static void pop_pos_callback( GtkMenu *menu, gint *x, gint *y, wxWindow *win )
2957 {
2958 win->ClientToScreen( &gs_pop_x, &gs_pop_y );
2959 *x = gs_pop_x;
2960 *y = gs_pop_y;
2961 }
2962
2963 bool wxWindow::PopupMenu( wxMenu *menu, int x, int y )
2964 {
2965 wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
2966
2967 wxCHECK_MSG( menu != NULL, FALSE, _T("invalid popup-menu") );
2968
2969 SetInvokingWindow( menu, this );
2970
2971 menu->UpdateUI();
2972
2973 gs_pop_x = x;
2974 gs_pop_y = y;
2975
2976 gtk_menu_popup(
2977 GTK_MENU(menu->m_menu),
2978 (GtkWidget *) NULL, // parent menu shell
2979 (GtkWidget *) NULL, // parent menu item
2980 (GtkMenuPositionFunc) pop_pos_callback,
2981 (gpointer) this, // client data
2982 0, // button used to activate it
2983 0 //gs_timeLastClick // the time of activation
2984 );
2985 return TRUE;
2986 }
2987
2988 #if wxUSE_DRAG_AND_DROP
2989
2990 void wxWindow::SetDropTarget( wxDropTarget *dropTarget )
2991 {
2992 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
2993
2994 GtkWidget *dnd_widget = GetConnectWidget();
2995
2996 if (m_dropTarget) m_dropTarget->UnregisterWidget( dnd_widget );
2997
2998 if (m_dropTarget) delete m_dropTarget;
2999 m_dropTarget = dropTarget;
3000
3001 if (m_dropTarget) m_dropTarget->RegisterWidget( dnd_widget );
3002 }
3003
3004 wxDropTarget *wxWindow::GetDropTarget() const
3005 {
3006 return m_dropTarget;
3007 }
3008
3009 #endif
3010
3011 GtkWidget* wxWindow::GetConnectWidget()
3012 {
3013 GtkWidget *connect_widget = m_widget;
3014 if (m_wxwindow) connect_widget = m_wxwindow;
3015
3016 return connect_widget;
3017 }
3018
3019 bool wxWindow::IsOwnGtkWindow( GdkWindow *window )
3020 {
3021 if (m_wxwindow) return (window == m_wxwindow->window);
3022 return (window == m_widget->window);
3023 }
3024
3025 void wxWindow::SetFont( const wxFont &font )
3026 {
3027 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3028
3029 if (m_font == font) return;
3030
3031 if (((wxFont*)&font)->Ok())
3032 m_font = font;
3033 else
3034 m_font = *wxSWISS_FONT;
3035
3036 wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
3037 if (sysbg.Red() == m_backgroundColour.Red() &&
3038 sysbg.Green() == m_backgroundColour.Green() &&
3039 sysbg.Blue() == m_backgroundColour.Blue())
3040 {
3041 m_backgroundColour = wxNullColour;
3042 ApplyWidgetStyle();
3043 m_backgroundColour = sysbg;
3044 }
3045 else
3046 {
3047 ApplyWidgetStyle();
3048 }
3049 }
3050
3051 void wxWindow::SetWindowStyleFlag( long flag )
3052 {
3053 m_windowStyle = flag;
3054 }
3055
3056 long wxWindow::GetWindowStyleFlag() const
3057 {
3058 return m_windowStyle;
3059 }
3060
3061 void wxWindow::CaptureMouse()
3062 {
3063 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3064
3065 wxCHECK_RET( g_capturing == FALSE, _T("CaptureMouse called twice") );
3066
3067 if (!m_widget->window) return;
3068
3069 GtkWidget *connect_widget = GetConnectWidget();
3070 gtk_grab_add( connect_widget );
3071 gdk_pointer_grab( connect_widget->window, FALSE,
3072 (GdkEventMask)
3073 (GDK_BUTTON_PRESS_MASK |
3074 GDK_BUTTON_RELEASE_MASK |
3075 GDK_POINTER_MOTION_MASK),
3076 (GdkWindow *) NULL,
3077 (GdkCursor *) NULL,
3078 GDK_CURRENT_TIME );
3079 g_capturing = TRUE;
3080 }
3081
3082 void wxWindow::ReleaseMouse()
3083 {
3084 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3085
3086 wxCHECK_RET( g_capturing == TRUE, _T("ReleaseMouse called twice") );
3087
3088 if (!m_widget->window) return;
3089
3090 GtkWidget *connect_widget = GetConnectWidget();
3091 gtk_grab_remove( connect_widget );
3092 gdk_pointer_ungrab ( GDK_CURRENT_TIME );
3093 g_capturing = FALSE;
3094 }
3095
3096 void wxWindow::SetTitle( const wxString &WXUNUSED(title) )
3097 {
3098 }
3099
3100 wxString wxWindow::GetTitle() const
3101 {
3102 return (wxString&)m_windowName;
3103 }
3104
3105 wxString wxWindow::GetLabel() const
3106 {
3107 return GetTitle();
3108 }
3109
3110 void wxWindow::SetName( const wxString &name )
3111 {
3112 m_windowName = name;
3113 }
3114
3115 wxString wxWindow::GetName() const
3116 {
3117 return (wxString&)m_windowName;
3118 }
3119
3120 bool wxWindow::IsShown() const
3121 {
3122 return m_isShown;
3123 }
3124
3125 bool wxWindow::IsRetained()
3126 {
3127 return FALSE;
3128 }
3129
3130 wxWindow *wxWindow::FindWindow( long id )
3131 {
3132 if (id == m_windowId) return this;
3133 wxNode *node = m_children.First();
3134 while (node)
3135 {
3136 wxWindow *child = (wxWindow*)node->Data();
3137 wxWindow *res = child->FindWindow( id );
3138 if (res) return res;
3139 node = node->Next();
3140 }
3141 return (wxWindow *) NULL;
3142 }
3143
3144 wxWindow *wxWindow::FindWindow( const wxString& name )
3145 {
3146 if (name == m_windowName) return this;
3147 wxNode *node = m_children.First();
3148 while (node)
3149 {
3150 wxWindow *child = (wxWindow*)node->Data();
3151 wxWindow *res = child->FindWindow( name );
3152 if (res) return res;
3153 node = node->Next();
3154 }
3155 return (wxWindow *) NULL;
3156 }
3157
3158 void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible,
3159 int range, bool refresh )
3160 {
3161 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3162
3163 wxCHECK_RET( m_wxwindow != NULL, _T("window needs client area for scrolling") );
3164
3165 m_hasScrolling = TRUE;
3166
3167 if (orient == wxHORIZONTAL)
3168 {
3169 float fpos = (float)pos;
3170 float frange = (float)range;
3171 float fthumb = (float)thumbVisible;
3172 if (fpos > frange-fthumb) fpos = frange-fthumb;
3173 if (fpos < 0.0) fpos = 0.0;
3174
3175 if ((fabs(frange-m_hAdjust->upper) < 0.2) &&
3176 (fabs(fthumb-m_hAdjust->page_size) < 0.2))
3177 {
3178 SetScrollPos( orient, pos, refresh );
3179 return;
3180 }
3181
3182 m_oldHorizontalPos = fpos;
3183
3184 m_hAdjust->lower = 0.0;
3185 m_hAdjust->upper = frange;
3186 m_hAdjust->value = fpos;
3187 m_hAdjust->step_increment = 1.0;
3188 m_hAdjust->page_increment = (float)(wxMax(fthumb,0));
3189 m_hAdjust->page_size = fthumb;
3190 }
3191 else
3192 {
3193 float fpos = (float)pos;
3194 float frange = (float)range;
3195 float fthumb = (float)thumbVisible;
3196 if (fpos > frange-fthumb) fpos = frange-fthumb;
3197 if (fpos < 0.0) fpos = 0.0;
3198
3199 if ((fabs(frange-m_vAdjust->upper) < 0.2) &&
3200 (fabs(fthumb-m_vAdjust->page_size) < 0.2))
3201 {
3202 SetScrollPos( orient, pos, refresh );
3203 return;
3204 }
3205
3206 m_oldVerticalPos = fpos;
3207
3208 m_vAdjust->lower = 0.0;
3209 m_vAdjust->upper = frange;
3210 m_vAdjust->value = fpos;
3211 m_vAdjust->step_increment = 1.0;
3212 m_vAdjust->page_increment = (float)(wxMax(fthumb,0));
3213 m_vAdjust->page_size = fthumb;
3214 }
3215
3216 if (m_wxwindow)
3217 {
3218 if (orient == wxHORIZONTAL)
3219 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
3220 else
3221 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
3222
3223 gtk_widget_set_usize( m_widget, m_width, m_height );
3224 }
3225 }
3226
3227 void wxWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) )
3228 {
3229 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3230
3231 wxCHECK_RET( m_wxwindow != NULL, _T("window needs client area for scrolling") );
3232
3233 if (orient == wxHORIZONTAL)
3234 {
3235 float fpos = (float)pos;
3236 if (fpos > m_hAdjust->upper - m_hAdjust->page_size) fpos = m_hAdjust->upper - m_hAdjust->page_size;
3237 if (fpos < 0.0) fpos = 0.0;
3238 m_oldHorizontalPos = fpos;
3239
3240 if (fabs(fpos-m_hAdjust->value) < 0.2) return;
3241 m_hAdjust->value = fpos;
3242 }
3243 else
3244 {
3245 float fpos = (float)pos;
3246 if (fpos > m_vAdjust->upper - m_vAdjust->page_size) fpos = m_vAdjust->upper - m_vAdjust->page_size;
3247 if (fpos < 0.0) fpos = 0.0;
3248 m_oldVerticalPos = fpos;
3249
3250 if (fabs(fpos-m_vAdjust->value) < 0.2) return;
3251 m_vAdjust->value = fpos;
3252 }
3253
3254 if (!m_isScrolling)
3255 {
3256 if (m_wxwindow->window)
3257 {
3258 if (orient == wxHORIZONTAL)
3259 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" );
3260 else
3261 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" );
3262 }
3263 }
3264 }
3265
3266 int wxWindow::GetScrollThumb( int orient ) const
3267 {
3268 wxCHECK_MSG( m_widget != NULL, 0, _T("invalid window") );
3269
3270 wxCHECK_MSG( m_wxwindow != NULL, 0, _T("window needs client area for scrolling") );
3271
3272 if (orient == wxHORIZONTAL)
3273 return (int)(m_hAdjust->page_size+0.5);
3274 else
3275 return (int)(m_vAdjust->page_size+0.5);
3276 }
3277
3278 int wxWindow::GetScrollPos( int orient ) const
3279 {
3280 wxCHECK_MSG( m_widget != NULL, 0, _T("invalid window") );
3281
3282 wxCHECK_MSG( m_wxwindow != NULL, 0, _T("window needs client area for scrolling") );
3283
3284 if (orient == wxHORIZONTAL)
3285 return (int)(m_hAdjust->value+0.5);
3286 else
3287 return (int)(m_vAdjust->value+0.5);
3288 }
3289
3290 int wxWindow::GetScrollRange( int orient ) const
3291 {
3292 wxCHECK_MSG( m_widget != NULL, 0, _T("invalid window") );
3293
3294 wxCHECK_MSG( m_wxwindow != NULL, 0, _T("window needs client area for scrolling") );
3295
3296 if (orient == wxHORIZONTAL)
3297 return (int)(m_hAdjust->upper+0.5);
3298 else
3299 return (int)(m_vAdjust->upper+0.5);
3300 }
3301
3302 void wxWindow::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) )
3303 {
3304 wxCHECK_RET( m_widget != NULL, _T("invalid window") );
3305
3306 wxCHECK_RET( m_wxwindow != NULL, _T("window needs client area for scrolling") );
3307
3308 wxNode *node = m_children.First();
3309 while (node)
3310 {
3311 wxWindow *child = (wxWindow*) node->Data();
3312 child->Move( child->m_x + dx, child->m_y + dy );
3313 node = node->Next();
3314 }
3315
3316 int cw = 0;
3317 int ch = 0;
3318 GetClientSize( &cw, &ch );
3319
3320 int w = cw - abs(dx);
3321 int h = ch - abs(dy);
3322 if ((h < 0) || (w < 0))
3323 {
3324 Refresh();
3325 return;
3326 }
3327 int s_x = 0;
3328 int s_y = 0;
3329 if (dx < 0) s_x = -dx;
3330 if (dy < 0) s_y = -dy;
3331 int d_x = 0;
3332 int d_y = 0;
3333 if (dx > 0) d_x = dx;
3334 if (dy > 0) d_y = dy;
3335
3336 if (!m_scrollGC)
3337 {
3338 m_scrollGC = gdk_gc_new( m_wxwindow->window );
3339 gdk_gc_set_exposures( m_scrollGC, TRUE );
3340 }
3341
3342 gdk_window_copy_area( m_wxwindow->window, m_scrollGC, d_x, d_y,
3343 m_wxwindow->window, s_x, s_y, w, h );
3344
3345 wxRect rect;
3346 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
3347 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
3348 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
3349 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
3350
3351 Refresh( TRUE, &rect );
3352 }
3353
3354 //-------------------------------------------------------------------------------------
3355 // Layout
3356 //-------------------------------------------------------------------------------------
3357
3358 wxLayoutConstraints *wxWindow::GetConstraints() const
3359 {
3360 return m_constraints;
3361 }
3362
3363 void wxWindow::SetConstraints( wxLayoutConstraints *constraints )
3364 {
3365 if (m_constraints)
3366 {
3367 UnsetConstraints(m_constraints);
3368 delete m_constraints;
3369 }
3370 m_constraints = constraints;
3371 if (m_constraints)
3372 {
3373 // Make sure other windows know they're part of a 'meaningful relationship'
3374 if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this))
3375 m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3376 if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this))
3377 m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3378 if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this))
3379 m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3380 if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this))
3381 m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3382 if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this))
3383 m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3384 if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this))
3385 m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3386 if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this))
3387 m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3388 if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this))
3389 m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3390 }
3391 ;
3392 }
3393 ;
3394
3395 void wxWindow::SetAutoLayout( bool autoLayout )
3396 {
3397 m_autoLayout = autoLayout;
3398 }
3399
3400 bool wxWindow::GetAutoLayout() const
3401 {
3402 return m_autoLayout;
3403 }
3404
3405 wxSizer *wxWindow::GetSizer() const
3406 {
3407 return m_windowSizer;
3408 }
3409
3410 void wxWindow::SetSizerParent( wxWindow *win )
3411 {
3412 m_sizerParent = win;
3413 }
3414
3415 wxWindow *wxWindow::GetSizerParent() const
3416 {
3417 return m_sizerParent;
3418 }
3419
3420 // This removes any dangling pointers to this window
3421 // in other windows' constraintsInvolvedIn lists.
3422 void wxWindow::UnsetConstraints(wxLayoutConstraints *c)
3423 {
3424 if (c)
3425 {
3426 if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this))
3427 c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3428 if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this))
3429 c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3430 if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this))
3431 c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3432 if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this))
3433 c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3434 if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this))
3435 c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3436 if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this))
3437 c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3438 if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this))
3439 c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3440 if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this))
3441 c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3442 }
3443 }
3444
3445 // Back-pointer to other windows we're involved with, so if we delete
3446 // this window, we must delete any constraints we're involved with.
3447 void wxWindow::AddConstraintReference(wxWindow *otherWin)
3448 {
3449 if (!m_constraintsInvolvedIn)
3450 m_constraintsInvolvedIn = new wxList;
3451 if (!m_constraintsInvolvedIn->Member(otherWin))
3452 m_constraintsInvolvedIn->Append(otherWin);
3453 }
3454
3455 // REMOVE back-pointer to other windows we're involved with.
3456 void wxWindow::RemoveConstraintReference(wxWindow *otherWin)
3457 {
3458 if (m_constraintsInvolvedIn)
3459 m_constraintsInvolvedIn->DeleteObject(otherWin);
3460 }
3461
3462 // Reset any constraints that mention this window
3463 void wxWindow::DeleteRelatedConstraints()
3464 {
3465 if (m_constraintsInvolvedIn)
3466 {
3467 wxNode *node = m_constraintsInvolvedIn->First();
3468 while (node)
3469 {
3470 wxWindow *win = (wxWindow *)node->Data();
3471 wxNode *next = node->Next();
3472 wxLayoutConstraints *constr = win->GetConstraints();
3473
3474 // Reset any constraints involving this window
3475 if (constr)
3476 {
3477 constr->left.ResetIfWin((wxWindow *)this);
3478 constr->top.ResetIfWin((wxWindow *)this);
3479 constr->right.ResetIfWin((wxWindow *)this);
3480 constr->bottom.ResetIfWin((wxWindow *)this);
3481 constr->width.ResetIfWin((wxWindow *)this);
3482 constr->height.ResetIfWin((wxWindow *)this);
3483 constr->centreX.ResetIfWin((wxWindow *)this);
3484 constr->centreY.ResetIfWin((wxWindow *)this);
3485 }
3486 delete node;
3487 node = next;
3488 }
3489 delete m_constraintsInvolvedIn;
3490 m_constraintsInvolvedIn = (wxList *) NULL;
3491 }
3492 }
3493
3494 void wxWindow::SetSizer(wxSizer *sizer)
3495 {
3496 m_windowSizer = sizer;
3497 if (sizer)
3498 sizer->SetSizerParent((wxWindow *)this);
3499 }
3500
3501 /*
3502 * New version
3503 */
3504
3505 bool wxWindow::Layout()
3506 {
3507 if (GetConstraints())
3508 {
3509 int w, h;
3510 GetClientSize(&w, &h);
3511 GetConstraints()->width.SetValue(w);
3512 GetConstraints()->height.SetValue(h);
3513 }
3514
3515 // If top level (one sizer), evaluate the sizer's constraints.
3516 if (GetSizer())
3517 {
3518 int noChanges;
3519 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
3520 GetSizer()->LayoutPhase1(&noChanges);
3521 GetSizer()->LayoutPhase2(&noChanges);
3522 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
3523 return TRUE;
3524 }
3525 else
3526 {
3527 // Otherwise, evaluate child constraints
3528 ResetConstraints(); // Mark all constraints as unevaluated
3529 DoPhase(1); // Just one phase need if no sizers involved
3530 DoPhase(2);
3531 SetConstraintSizes(); // Recursively set the real window sizes
3532 }
3533 return TRUE;
3534 }
3535
3536
3537 // Do a phase of evaluating constraints:
3538 // the default behaviour. wxSizers may do a similar
3539 // thing, but also impose their own 'constraints'
3540 // and order the evaluation differently.
3541 bool wxWindow::LayoutPhase1(int *noChanges)
3542 {
3543 wxLayoutConstraints *constr = GetConstraints();
3544 if (constr)
3545 {
3546 return constr->SatisfyConstraints((wxWindow *)this, noChanges);
3547 }
3548 else
3549 return TRUE;
3550 }
3551
3552 bool wxWindow::LayoutPhase2(int *noChanges)
3553 {
3554 *noChanges = 0;
3555
3556 // Layout children
3557 DoPhase(1);
3558 DoPhase(2);
3559 return TRUE;
3560 }
3561
3562 // Do a phase of evaluating child constraints
3563 bool wxWindow::DoPhase(int phase)
3564 {
3565 int noIterations = 0;
3566 int maxIterations = 500;
3567 int noChanges = 1;
3568 int noFailures = 0;
3569 wxList succeeded;
3570 while ((noChanges > 0) && (noIterations < maxIterations))
3571 {
3572 noChanges = 0;
3573 noFailures = 0;
3574 wxNode *node = m_children.First();
3575 while (node)
3576 {
3577 wxWindow *child = (wxWindow *)node->Data();
3578 if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog)))
3579 {
3580 wxLayoutConstraints *constr = child->GetConstraints();
3581 if (constr)
3582 {
3583 if (succeeded.Member(child))
3584 {
3585 }
3586 else
3587 {
3588 int tempNoChanges = 0;
3589 bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
3590 noChanges += tempNoChanges;
3591 if (success)
3592 {
3593 succeeded.Append(child);
3594 }
3595 }
3596 }
3597 }
3598 node = node->Next();
3599 }
3600 noIterations ++;
3601 }
3602 return TRUE;
3603 }
3604
3605 void wxWindow::ResetConstraints()
3606 {
3607 wxLayoutConstraints *constr = GetConstraints();
3608 if (constr)
3609 {
3610 constr->left.SetDone(FALSE);
3611 constr->top.SetDone(FALSE);
3612 constr->right.SetDone(FALSE);
3613 constr->bottom.SetDone(FALSE);
3614 constr->width.SetDone(FALSE);
3615 constr->height.SetDone(FALSE);
3616 constr->centreX.SetDone(FALSE);
3617 constr->centreY.SetDone(FALSE);
3618 }
3619 wxNode *node = m_children.First();
3620 while (node)
3621 {
3622 wxWindow *win = (wxWindow *)node->Data();
3623 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
3624 win->ResetConstraints();
3625 node = node->Next();
3626 }
3627 }
3628
3629 // Need to distinguish between setting the 'fake' size for
3630 // windows and sizers, and setting the real values.
3631 void wxWindow::SetConstraintSizes(bool recurse)
3632 {
3633 wxLayoutConstraints *constr = GetConstraints();
3634 if (constr && constr->left.GetDone() && constr->right.GetDone() &&
3635 constr->width.GetDone() && constr->height.GetDone())
3636 {
3637 int x = constr->left.GetValue();
3638 int y = constr->top.GetValue();
3639 int w = constr->width.GetValue();
3640 int h = constr->height.GetValue();
3641
3642 // If we don't want to resize this window, just move it...
3643 if ((constr->width.GetRelationship() != wxAsIs) ||
3644 (constr->height.GetRelationship() != wxAsIs))
3645 {
3646 // Calls Layout() recursively. AAAGH. How can we stop that.
3647 // Simply take Layout() out of non-top level OnSizes.
3648 SizerSetSize(x, y, w, h);
3649 }
3650 else
3651 {
3652 SizerMove(x, y);
3653 }
3654 }
3655 else if (constr)
3656 {
3657 wxChar *windowClass = this->GetClassInfo()->GetClassName();
3658
3659 wxString winName;
3660 if (GetName() == _T(""))
3661 winName = _T("unnamed");
3662 else
3663 winName = GetName();
3664 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
3665 (const wxChar *)windowClass,
3666 (const wxChar *)winName);
3667 if (!constr->left.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
3668 if (!constr->right.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
3669 if (!constr->width.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
3670 if (!constr->height.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
3671 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
3672 }
3673
3674 if (recurse)
3675 {
3676 wxNode *node = m_children.First();
3677 while (node)
3678 {
3679 wxWindow *win = (wxWindow *)node->Data();
3680 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
3681 win->SetConstraintSizes();
3682 node = node->Next();
3683 }
3684 }
3685 }
3686
3687 // This assumes that all sizers are 'on' the same
3688 // window, i.e. the parent of this window.
3689 void wxWindow::TransformSizerToActual(int *x, int *y) const
3690 {
3691 if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) ||
3692 m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) )
3693 return;
3694
3695 int xp, yp;
3696 m_sizerParent->GetPosition(&xp, &yp);
3697 m_sizerParent->TransformSizerToActual(&xp, &yp);
3698 *x += xp;
3699 *y += yp;
3700 }
3701
3702 void wxWindow::SizerSetSize(int x, int y, int w, int h)
3703 {
3704 int xx = x;
3705 int yy = y;
3706 TransformSizerToActual(&xx, &yy);
3707 SetSize(xx, yy, w, h);
3708 }
3709
3710 void wxWindow::SizerMove(int x, int y)
3711 {
3712 int xx = x;
3713 int yy = y;
3714 TransformSizerToActual(&xx, &yy);
3715 Move(xx, yy);
3716 }
3717
3718 // Only set the size/position of the constraint (if any)
3719 void wxWindow::SetSizeConstraint(int x, int y, int w, int h)
3720 {
3721 wxLayoutConstraints *constr = GetConstraints();
3722 if (constr)
3723 {
3724 if (x != -1)
3725 {
3726 constr->left.SetValue(x);
3727 constr->left.SetDone(TRUE);
3728 }
3729 if (y != -1)
3730 {
3731 constr->top.SetValue(y);
3732 constr->top.SetDone(TRUE);
3733 }
3734 if (w != -1)
3735 {
3736 constr->width.SetValue(w);
3737 constr->width.SetDone(TRUE);
3738 }
3739 if (h != -1)
3740 {
3741 constr->height.SetValue(h);
3742 constr->height.SetDone(TRUE);
3743 }
3744 }
3745 }
3746
3747 void wxWindow::MoveConstraint(int x, int y)
3748 {
3749 wxLayoutConstraints *constr = GetConstraints();
3750 if (constr)
3751 {
3752 if (x != -1)
3753 {
3754 constr->left.SetValue(x);
3755 constr->left.SetDone(TRUE);
3756 }
3757 if (y != -1)
3758 {
3759 constr->top.SetValue(y);
3760 constr->top.SetDone(TRUE);
3761 }
3762 }
3763 }
3764
3765 void wxWindow::GetSizeConstraint(int *w, int *h) const
3766 {
3767 wxLayoutConstraints *constr = GetConstraints();
3768 if (constr)
3769 {
3770 *w = constr->width.GetValue();
3771 *h = constr->height.GetValue();
3772 }
3773 else
3774 GetSize(w, h);
3775 }
3776
3777 void wxWindow::GetClientSizeConstraint(int *w, int *h) const
3778 {
3779 wxLayoutConstraints *constr = GetConstraints();
3780 if (constr)
3781 {
3782 *w = constr->width.GetValue();
3783 *h = constr->height.GetValue();
3784 }
3785 else
3786 GetClientSize(w, h);
3787 }
3788
3789 void wxWindow::GetPositionConstraint(int *x, int *y) const
3790 {
3791 wxLayoutConstraints *constr = GetConstraints();
3792 if (constr)
3793 {
3794 *x = constr->left.GetValue();
3795 *y = constr->top.GetValue();
3796 }
3797 else
3798 GetPosition(x, y);
3799 }
3800