1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling, Julian Smart 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  12 #pragma implementation "window.h" 
  16 #include "wx/window.h" 
  20 #include "wx/layout.h" 
  22 #include "wx/dialog.h" 
  23 #include "wx/msgdlg.h" 
  24 #if wxUSE_DRAG_AND_DROP 
  27 #include "wx/tooltip.h" 
  29 #include "wx/statusbr.h" 
  31 #include "wx/settings.h" 
  38 #include "gdk/gdkprivate.h" 
  39 #include "gdk/gdkkeysyms.h" 
  40 #include "wx/gtk/win_gtk.h" 
  42 //----------------------------------------------------------------------------- 
  43 // documentation on internals 
  44 //----------------------------------------------------------------------------- 
  47    I have been asked several times about writing some documentation about 
  48    the GTK port of wxWindows, especially its internal structures. Obviously, 
  49    you cannot understand wxGTK without knowing a little about the GTK, but 
  50    some more information about what the wxWindow, which is the base class 
  51    for all other window classes, does seems required as well. 
  53    What does wxWindow do? It contains the common interface for the following 
  54    jobs of its descendants: 
  56    1) Define the rudimentary behaviour common to all window classes, such as 
  57    resizing, intercepting user input (so as to make it possible to use these 
  58    events for special purposes in a derived class), window names etc. 
  60    2) Provide the possibility to contain and manage children, if the derived 
  61    class is allowed to contain children, which holds true for those window 
  62    classes which do not display a native GTK widget. To name them, these 
  63    classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame- 
  64    work classes are a special case and are handled a bit differently from 
  65    the rest. The same holds true for the wxNotebook class. 
  67    3) Provide the possibility to draw into a client area of a window. This, 
  68    too, only holds true for classes that do not display a native GTK widget 
  71    4) Provide the entire mechanism for scrolling widgets. This actual inter- 
  72    face for this is usually in wxScrolledWindow, but the GTK implementation 
  75    5) A multitude of helper or extra methods for special purposes, such as 
  76    Drag'n'Drop, managing validators etc. 
  78    Normally one might expect, that one wxWindows window would always correspond 
  79    to one GTK widget. Under GTK, there is no such allround widget that has all 
  80    the functionality. Moreover, the GTK defines a client area as a different 
  81    widget from the actual widget you are handling. Last but not least some 
  82    special classes (e.g. wxFrame) handle different categories of widgets and 
  83    still have the possibility to draw something in the client area. 
  84    It was therefore required to write a special purpose GTK widget, that would 
  85    represent a client area in the sense of wxWindows capable to do the jobs 
  86    2), 3) and 4). I have written this class and it resides in win_gtk.c of 
  89    All windows must have a widget, with which they interact with other under- 
  90    lying GTK widgets. It is this widget, e.g. that has to be resized etc and 
  91    thw wxWindow class has a member variable called m_widget which holds a 
  92    pointer to this widget. When the window class represents a GTK native widget, 
  93    this is (in most cases) the only GTK widget the class manages. E.g. the 
  94    wxStatitText class handles only a GtkLabel widget a pointer to which you 
  95    can find in m_widget (defined in wxWindow) 
  97    When the class has a client area for drawing into and for containing children 
  98    it has to handle the client area widget (of the type GtkMyFixed, defined in 
  99    win_gtk.c), but there could be any number of widgets, handled by a class 
 100    The common rule for all windows is only, that the widget that interacts with 
 101    the rest of GTK must be referenced in m_widget and all other widgets must be 
 102    children of this widget on the GTK level. The top-most widget, which also 
 103    represents the client area, must be in the m_wxwindow field and must be of 
 106    As I said, the window classes that display a GTK native widget only have 
 107    one widget, so in the case of e.g. the wxButton class m_widget holds a 
 108    pointer to a GtkButton widget. But windows with client areas (for drawing 
 109    and children) have a m_widget field that is a pointer to a GtkScrolled- 
 110    Window and a m_wxwindow field that is pointer to a GtkMyFixed and this 
 111    one is (in the GTK sense) a child of the GtkScrolledWindow. 
 113    If the m_wxwindow field is set, then all input to this widget is inter- 
 114    cepted and sent to the wxWindows class. If not, all input to the widget 
 115    that gets pointed to by m_widget gets intercepted and sent to the class. 
 119 //------------------------------------------------------------------------- 
 120 // conditional compilation 
 121 //------------------------------------------------------------------------- 
 123 #if (GTK_MINOR_VERSION == 1) 
 124 #if (GTK_MICRO_VERSION >= 5) 
 125 #define NEW_GTK_SCROLL_CODE 
 129 //----------------------------------------------------------------------------- 
 131 //----------------------------------------------------------------------------- 
 135 static gint 
gtk_debug_focus_in_callback( GtkWidget 
*WXUNUSED(widget
), 
 136                                          GdkEvent 
*WXUNUSED(event
), 
 139     printf( "FOCUS NOW AT: " ); 
 146 void debug_focus_in( GtkWidget
* widget
, const char* name
, const char *window 
) 
 154     char *s 
= new char[tmp
.Length()+1]; 
 156     strcpy( s
, WXSTRINGCAST tmp 
); 
 158     gtk_signal_connect( GTK_OBJECT(widget
), "focus_in_event", 
 159       GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback
), (gpointer
)s 
); 
 164 //----------------------------------------------------------------------------- 
 166 //----------------------------------------------------------------------------- 
 168 extern wxList     wxPendingDelete
; 
 169 extern wxList     wxTopLevelWindows
; 
 170 extern bool       g_blockEventsOnDrag
; 
 171 extern bool       g_blockEventsOnScroll
; 
 172 static bool       g_capturing 
= FALSE
; 
 173 static wxWindow  
*g_focusWindow 
= (wxWindow
*) NULL
; 
 175 // hack: we need something to pass to gtk_menu_popup, so we store the time of 
 176 // the last click here 
 177 static guint32 gs_timeLastClick 
= 0; 
 179 //----------------------------------------------------------------------------- 
 180 // "expose_event" (of m_wxwindow, not of m_widget) 
 181 //----------------------------------------------------------------------------- 
 183 static void gtk_window_expose_callback( GtkWidget 
*WXUNUSED(widget
), GdkEventExpose 
*gdk_event
, wxWindow 
*win 
) 
 185     if (!win
->HasVMT()) return; 
 187     win
->m_updateRegion
.Union( gdk_event
->area
.x
, 
 189                                gdk_event
->area
.width
, 
 190                                gdk_event
->area
.height 
); 
 192     if (gdk_event
->count 
> 0) return; 
 195     printf( "OnExpose from " ); 
 196     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
 197         printf( win->GetClassInfo()->GetClassName() ); 
 201     wxPaintEvent 
event( win
->GetId() ); 
 202     event
.SetEventObject( win 
); 
 203     win
->GetEventHandler()->ProcessEvent( event 
); 
 205     win
->m_updateRegion
.Clear(); 
 208 //----------------------------------------------------------------------------- 
 209 // "draw" (of m_wxwindow, not of m_widget) 
 210 //----------------------------------------------------------------------------- 
 212 static void gtk_window_draw_callback( GtkWidget 
*WXUNUSED(widget
), GdkRectangle 
*rect
, wxWindow 
*win 
) 
 214     if (!win
->HasVMT()) return; 
 216     win
->m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height 
); 
 218     wxPaintEvent 
event( win
->GetId() ); 
 219     event
.SetEventObject( win 
); 
 220     win
->GetEventHandler()->ProcessEvent( event 
); 
 222     win
->m_updateRegion
.Clear(); 
 225 //----------------------------------------------------------------------------- 
 226 // "key_press_event" from any window 
 227 //----------------------------------------------------------------------------- 
 229 static gint 
gtk_window_key_press_callback( GtkWidget 
*widget
, GdkEventKey 
*gdk_event
, wxWindow 
*win 
) 
 231     if (!win
->HasVMT()) return FALSE
; 
 232     if (g_blockEventsOnDrag
) return FALSE
; 
 235     printf( "OnKeyPress from " ); 
 236     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
 237         printf( win->GetClassInfo()->GetClassName() ); 
 242     switch (gdk_event
->keyval
) 
 244         case GDK_BackSpace
:     key_code 
= WXK_BACK
;        break; 
 245         case GDK_Tab
:           key_code 
= WXK_TAB
;         break; 
 246         case GDK_Linefeed
:      key_code 
= WXK_RETURN
;      break; 
 247         case GDK_Clear
:         key_code 
= WXK_CLEAR
;       break; 
 248         case GDK_Return
:        key_code 
= WXK_RETURN
;      break; 
 249         case GDK_Pause
:         key_code 
= WXK_PAUSE
;       break; 
 250         case GDK_Scroll_Lock
:   key_code 
= WXK_SCROLL
;      break; 
 251         case GDK_Escape
:        key_code 
= WXK_ESCAPE
;      break; 
 252         case GDK_Delete
:        key_code 
= WXK_DELETE
;      break; 
 253         case GDK_Home
:          key_code 
= WXK_HOME
;        break; 
 254         case GDK_Left
:          key_code 
= WXK_LEFT
;        break; 
 255         case GDK_Up
:            key_code 
= WXK_UP
;          break; 
 256         case GDK_Right
:         key_code 
= WXK_RIGHT
;       break; 
 257         case GDK_Down
:          key_code 
= WXK_DOWN
;        break; 
 258         case GDK_Prior
:         key_code 
= WXK_PRIOR
;       break; 
 259 //      case GDK_Page_Up:       key_code = WXK_PAGEUP;      break; 
 260         case GDK_Next
:          key_code 
= WXK_NEXT
;        break; 
 261 //      case GDK_Page_Down:     key_code = WXK_PAGEDOWN;    break; 
 262         case GDK_End
:           key_code 
= WXK_END
;         break; 
 263         case GDK_Begin
:         key_code 
= WXK_HOME
;        break; 
 264         case GDK_Select
:        key_code 
= WXK_SELECT
;      break; 
 265         case GDK_Print
:         key_code 
= WXK_PRINT
;       break; 
 266         case GDK_Execute
:       key_code 
= WXK_EXECUTE
;     break; 
 267         case GDK_Insert
:        key_code 
= WXK_INSERT
;      break; 
 268         case GDK_Num_Lock
:      key_code 
= WXK_NUMLOCK
;     break; 
 269         case GDK_KP_Tab
:        key_code 
= WXK_TAB
;         break; 
 270         case GDK_KP_Enter
:      key_code 
= WXK_RETURN
;      break; 
 271         case GDK_KP_Home
:       key_code 
= WXK_HOME
;        break; 
 272         case GDK_KP_Left
:       key_code 
= WXK_LEFT
;        break; 
 273         case GDK_KP_Up
:         key_code 
= WXK_UP
;          break; 
 274         case GDK_KP_Right
:      key_code 
= WXK_RIGHT
;       break; 
 275         case GDK_KP_Down
:       key_code 
= WXK_DOWN
;        break; 
 276         case GDK_KP_Prior
:      key_code 
= WXK_PRIOR
;       break; 
 277 //      case GDK_KP_Page_Up:    key_code = WXK_PAGEUP;      break; 
 278         case GDK_KP_Next
:       key_code 
= WXK_NEXT
;        break; 
 279 //      case GDK_KP_Page_Down:  key_code = WXK_PAGEDOWN;    break; 
 280         case GDK_KP_End
:        key_code 
= WXK_END
;         break; 
 281         case GDK_KP_Begin
:      key_code 
= WXK_HOME
;        break; 
 282         case GDK_KP_Insert
:     key_code 
= WXK_INSERT
;      break; 
 283         case GDK_KP_Delete
:     key_code 
= WXK_DELETE
;      break; 
 284         case GDK_KP_Multiply
:   key_code 
= WXK_MULTIPLY
;    break; 
 285         case GDK_KP_Add
:        key_code 
= WXK_ADD
;         break; 
 286         case GDK_KP_Separator
:  key_code 
= WXK_SEPARATOR
;   break; 
 287         case GDK_KP_Subtract
:   key_code 
= WXK_SUBTRACT
;    break; 
 288         case GDK_KP_Decimal
:    key_code 
= WXK_DECIMAL
;     break; 
 289         case GDK_KP_Divide
:     key_code 
= WXK_DIVIDE
;      break; 
 290         case GDK_KP_0
:          key_code 
= WXK_NUMPAD0
;     break; 
 291         case GDK_KP_1
:          key_code 
= WXK_NUMPAD1
;     break; 
 292         case GDK_KP_2
:          key_code 
= WXK_NUMPAD2
;     break; 
 293         case GDK_KP_3
:          key_code 
= WXK_NUMPAD3
;     break; 
 294         case GDK_KP_4
:          key_code 
= WXK_NUMPAD4
;     break; 
 295         case GDK_KP_5
:          key_code 
= WXK_NUMPAD5
;     break; 
 296         case GDK_KP_6
:          key_code 
= WXK_NUMPAD6
;     break; 
 297         case GDK_KP_7
:          key_code 
= WXK_NUMPAD7
;     break; 
 298         case GDK_KP_8
:          key_code 
= WXK_NUMPAD7
;     break; 
 299         case GDK_KP_9
:          key_code 
= WXK_NUMPAD9
;     break; 
 300         case GDK_F1
:            key_code 
= WXK_F1
;          break; 
 301         case GDK_F2
:            key_code 
= WXK_F2
;          break; 
 302         case GDK_F3
:            key_code 
= WXK_F3
;          break; 
 303         case GDK_F4
:            key_code 
= WXK_F4
;          break; 
 304         case GDK_F5
:            key_code 
= WXK_F5
;          break; 
 305         case GDK_F6
:            key_code 
= WXK_F6
;          break; 
 306         case GDK_F7
:            key_code 
= WXK_F7
;          break; 
 307         case GDK_F8
:            key_code 
= WXK_F8
;          break; 
 308         case GDK_F9
:            key_code 
= WXK_F9
;          break; 
 309         case GDK_F10
:           key_code 
= WXK_F10
;         break; 
 310         case GDK_F11
:           key_code 
= WXK_F11
;         break; 
 311         case GDK_F12
:           key_code 
= WXK_F12
;         break; 
 314             if ((gdk_event
->keyval 
>= 0x20) && (gdk_event
->keyval 
<= 0xFF)) 
 315                 key_code 
= gdk_event
->keyval
; 
 319     if (!key_code
) return FALSE
; 
 321     wxKeyEvent 
event( wxEVT_KEY_DOWN 
); 
 322     event
.m_shiftDown 
= (gdk_event
->state 
& GDK_SHIFT_MASK
); 
 323     event
.m_controlDown 
= (gdk_event
->state 
& GDK_CONTROL_MASK
); 
 324     event
.m_altDown 
= (gdk_event
->state 
& GDK_MOD1_MASK
); 
 325     event
.m_metaDown 
= (gdk_event
->state 
& GDK_MOD2_MASK
); 
 326     event
.m_keyCode 
= key_code
; 
 329     event
.SetEventObject( win 
); 
 331     bool ret 
= win
->GetEventHandler()->ProcessEvent( event 
); 
 335         wxWindow 
*ancestor 
= win
; 
 338             int command 
= ancestor
->GetAcceleratorTable()->GetCommand( event 
); 
 341                 wxCommandEvent 
command_event( wxEVT_COMMAND_MENU_SELECTED
, command 
); 
 342                 ret 
= ancestor
->GetEventHandler()->ProcessEvent( command_event 
); 
 345             ancestor 
= ancestor
->GetParent(); 
 349     // win is a control: tab can be propagated up 
 350     if ((!ret
) && (gdk_event
->keyval 
== GDK_Tab
) && ((win
->m_windowStyle 
& wxTE_PROCESS_TAB
) == 0)) 
 352         wxNavigationKeyEvent new_event
; 
 353         new_event
.SetDirection( !(gdk_event
->state 
& GDK_SHIFT_MASK
) ); 
 354         new_event
.SetWindowChange( FALSE 
); 
 355         new_event
.SetCurrentFocus( win 
); 
 356         ret 
= win
->GetEventHandler()->ProcessEvent( new_event 
); 
 360     // win is a panel: up can be propagated to the panel 
 361     if ((!ret) && (win->m_wxwindow) && (win->m_parent) && (win->m_parent->AcceptsFocus()) && 
 362         (gdk_event->keyval == GDK_Up)) 
 364         win->m_parent->SetFocus(); 
 368     // win is a panel: left/right can be propagated to the panel 
 369     if ((!ret) && (win->m_wxwindow) && 
 370         ((gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Left) || 
 371          (gdk_event->keyval == GDK_Up) || (gdk_event->keyval == GDK_Down))) 
 373         wxNavigationKeyEvent new_event; 
 374         new_event.SetDirection( (gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Down) ); 
 375         new_event.SetCurrentFocus( win ); 
 376         ret = win->GetEventHandler()->ProcessEvent( new_event ); 
 382         gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" ); 
 388 //----------------------------------------------------------------------------- 
 389 // "key_release_event" from any window 
 390 //----------------------------------------------------------------------------- 
 392 static gint 
gtk_window_key_release_callback( GtkWidget 
*widget
, GdkEventKey 
*gdk_event
, wxWindow 
*win 
) 
 394     if (!win
->HasVMT()) return FALSE
; 
 395     if (g_blockEventsOnDrag
) return FALSE
; 
 398     printf( "OnKeyRelease from " ); 
 399     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
 400         printf( win->GetClassInfo()->GetClassName() ); 
 405     switch (gdk_event
->keyval
) 
 407         case GDK_BackSpace
:     key_code 
= WXK_BACK
;        break; 
 408         case GDK_Tab
:           key_code 
= WXK_TAB
;         break; 
 409         case GDK_Linefeed
:      key_code 
= WXK_RETURN
;      break; 
 410         case GDK_Clear
:         key_code 
= WXK_CLEAR
;       break; 
 411         case GDK_Return
:        key_code 
= WXK_RETURN
;      break; 
 412         case GDK_Pause
:         key_code 
= WXK_PAUSE
;       break; 
 413         case GDK_Scroll_Lock
:   key_code 
= WXK_SCROLL
;      break; 
 414         case GDK_Escape
:        key_code 
= WXK_ESCAPE
;      break; 
 415         case GDK_Delete
:        key_code 
= WXK_DELETE
;      break; 
 416         case GDK_Home
:          key_code 
= WXK_HOME
;        break; 
 417         case GDK_Left
:          key_code 
= WXK_LEFT
;        break; 
 418         case GDK_Up
:            key_code 
= WXK_UP
;          break; 
 419         case GDK_Right
:         key_code 
= WXK_RIGHT
;       break; 
 420         case GDK_Down
:          key_code 
= WXK_DOWN
;        break; 
 421         case GDK_Prior
:         key_code 
= WXK_PRIOR
;       break; 
 422 //      case GDK_Page_Up:       key_code = WXK_PAGEUP;      break; 
 423         case GDK_Next
:          key_code 
= WXK_NEXT
;        break; 
 424 //      case GDK_Page_Down:     key_code = WXK_PAGEDOWN;    break; 
 425         case GDK_End
:           key_code 
= WXK_END
;         break; 
 426         case GDK_Begin
:         key_code 
= WXK_HOME
;        break; 
 427         case GDK_Select
:        key_code 
= WXK_SELECT
;      break; 
 428         case GDK_Print
:         key_code 
= WXK_PRINT
;       break; 
 429         case GDK_Execute
:       key_code 
= WXK_EXECUTE
;     break; 
 430         case GDK_Insert
:        key_code 
= WXK_INSERT
;      break; 
 431         case GDK_Num_Lock
:      key_code 
= WXK_NUMLOCK
;     break; 
 432         case GDK_KP_Tab
:        key_code 
= WXK_TAB
;         break; 
 433         case GDK_KP_Enter
:      key_code 
= WXK_RETURN
;      break; 
 434         case GDK_KP_Home
:       key_code 
= WXK_HOME
;        break; 
 435         case GDK_KP_Left
:       key_code 
= WXK_LEFT
;        break; 
 436         case GDK_KP_Up
:         key_code 
= WXK_UP
;          break; 
 437         case GDK_KP_Right
:      key_code 
= WXK_RIGHT
;       break; 
 438         case GDK_KP_Down
:       key_code 
= WXK_DOWN
;        break; 
 439         case GDK_KP_Prior
:      key_code 
= WXK_PRIOR
;       break; 
 440 //      case GDK_KP_Page_Up:    key_code = WXK_PAGEUP;      break; 
 441         case GDK_KP_Next
:       key_code 
= WXK_NEXT
;        break; 
 442 //      case GDK_KP_Page_Down:  key_code = WXK_PAGEDOWN;    break; 
 443         case GDK_KP_End
:        key_code 
= WXK_END
;         break; 
 444         case GDK_KP_Begin
:      key_code 
= WXK_HOME
;        break; 
 445         case GDK_KP_Insert
:     key_code 
= WXK_INSERT
;      break; 
 446         case GDK_KP_Delete
:     key_code 
= WXK_DELETE
;      break; 
 447         case GDK_KP_Multiply
:   key_code 
= WXK_MULTIPLY
;    break; 
 448         case GDK_KP_Add
:        key_code 
= WXK_ADD
;         break; 
 449         case GDK_KP_Separator
:  key_code 
= WXK_SEPARATOR
;   break; 
 450         case GDK_KP_Subtract
:   key_code 
= WXK_SUBTRACT
;    break; 
 451         case GDK_KP_Decimal
:    key_code 
= WXK_DECIMAL
;     break; 
 452         case GDK_KP_Divide
:     key_code 
= WXK_DIVIDE
;      break; 
 453         case GDK_KP_0
:          key_code 
= WXK_NUMPAD0
;     break; 
 454         case GDK_KP_1
:          key_code 
= WXK_NUMPAD1
;     break; 
 455         case GDK_KP_2
:          key_code 
= WXK_NUMPAD2
;     break; 
 456         case GDK_KP_3
:          key_code 
= WXK_NUMPAD3
;     break; 
 457         case GDK_KP_4
:          key_code 
= WXK_NUMPAD4
;     break; 
 458         case GDK_KP_5
:          key_code 
= WXK_NUMPAD5
;     break; 
 459         case GDK_KP_6
:          key_code 
= WXK_NUMPAD6
;     break; 
 460         case GDK_KP_7
:          key_code 
= WXK_NUMPAD7
;     break; 
 461         case GDK_KP_8
:          key_code 
= WXK_NUMPAD7
;     break; 
 462         case GDK_KP_9
:          key_code 
= WXK_NUMPAD9
;     break; 
 463         case GDK_F1
:            key_code 
= WXK_F1
;          break; 
 464         case GDK_F2
:            key_code 
= WXK_F2
;          break; 
 465         case GDK_F3
:            key_code 
= WXK_F3
;          break; 
 466         case GDK_F4
:            key_code 
= WXK_F4
;          break; 
 467         case GDK_F5
:            key_code 
= WXK_F5
;          break; 
 468         case GDK_F6
:            key_code 
= WXK_F6
;          break; 
 469         case GDK_F7
:            key_code 
= WXK_F7
;          break; 
 470         case GDK_F8
:            key_code 
= WXK_F8
;          break; 
 471         case GDK_F9
:            key_code 
= WXK_F9
;          break; 
 472         case GDK_F10
:           key_code 
= WXK_F10
;         break; 
 473         case GDK_F11
:           key_code 
= WXK_F11
;         break; 
 474         case GDK_F12
:           key_code 
= WXK_F12
;         break; 
 477             if ((gdk_event
->keyval 
>= 0x20) && (gdk_event
->keyval 
<= 0xFF)) 
 478                 key_code 
= gdk_event
->keyval
; 
 482     if (!key_code
) return FALSE
; 
 484     wxKeyEvent 
event( wxEVT_KEY_UP 
); 
 485     event
.m_shiftDown 
= (gdk_event
->state 
& GDK_SHIFT_MASK
); 
 486     event
.m_controlDown 
= (gdk_event
->state 
& GDK_CONTROL_MASK
); 
 487     event
.m_altDown 
= (gdk_event
->state 
& GDK_MOD1_MASK
); 
 488     event
.m_metaDown 
= (gdk_event
->state 
& GDK_MOD2_MASK
); 
 489     event
.m_keyCode 
= key_code
; 
 492     event
.SetEventObject( win 
); 
 494     bool ret 
= win
->GetEventHandler()->ProcessEvent( event 
); 
 498         gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" ); 
 504 //----------------------------------------------------------------------------- 
 505 // "button_press_event" 
 506 //----------------------------------------------------------------------------- 
 508 static gint 
gtk_window_button_press_callback( GtkWidget 
*widget
, GdkEventButton 
*gdk_event
, wxWindow 
*win 
) 
 510     if (!win
->IsOwnGtkWindow( gdk_event
->window 
)) return TRUE
; 
 512     if (g_blockEventsOnDrag
) return TRUE
; 
 513     if (g_blockEventsOnScroll
) return TRUE
; 
 517         if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
) && !GTK_WIDGET_HAS_FOCUS (win
->m_wxwindow
) ) 
 519             gtk_widget_grab_focus (win
->m_wxwindow
); 
 522             printf( "GrabFocus from " ); 
 523             if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
 524                 printf( win->GetClassInfo()->GetClassName() ); 
 531     if (!win
->HasVMT()) return TRUE
; 
 534     printf( "OnButtonPress from " ); 
 535     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
 536         printf( win->GetClassInfo()->GetClassName() ); 
 540     wxEventType event_type 
= wxEVT_LEFT_DOWN
; 
 542     if (gdk_event
->button 
== 1) 
 544         switch (gdk_event
->type
) 
 546             case GDK_BUTTON_PRESS
: event_type 
= wxEVT_LEFT_DOWN
; break; 
 547             case GDK_2BUTTON_PRESS
: event_type 
= wxEVT_LEFT_DCLICK
; break; 
 551     else if (gdk_event
->button 
== 2) 
 553         switch (gdk_event
->type
) 
 555             case GDK_BUTTON_PRESS
: event_type 
= wxEVT_MIDDLE_DOWN
; break; 
 556             case GDK_2BUTTON_PRESS
: event_type 
= wxEVT_MIDDLE_DCLICK
; break; 
 560     else if (gdk_event
->button 
== 3) 
 562         switch (gdk_event
->type
) 
 564             case GDK_BUTTON_PRESS
: event_type 
= wxEVT_RIGHT_DOWN
; break; 
 565             case GDK_2BUTTON_PRESS
: event_type 
= wxEVT_RIGHT_DCLICK
; break; 
 570     wxMouseEvent 
event( event_type 
); 
 571     event
.m_shiftDown 
= (gdk_event
->state 
& GDK_SHIFT_MASK
); 
 572     event
.m_controlDown 
= (gdk_event
->state 
& GDK_CONTROL_MASK
); 
 573     event
.m_altDown 
= (gdk_event
->state 
& GDK_MOD1_MASK
); 
 574     event
.m_metaDown 
= (gdk_event
->state 
& GDK_MOD2_MASK
); 
 575     event
.m_leftDown 
= (gdk_event
->state 
& GDK_BUTTON1_MASK
); 
 576     event
.m_middleDown 
= (gdk_event
->state 
& GDK_BUTTON2_MASK
); 
 577     event
.m_rightDown 
= (gdk_event
->state 
& GDK_BUTTON3_MASK
); 
 579     event
.m_x 
= (long)gdk_event
->x
; 
 580     event
.m_y 
= (long)gdk_event
->y
; 
 582     // Some control don't have their own X window and thus cannot get 
 587         wxNode 
*node 
= win
->GetChildren().First(); 
 590             wxWindow 
*child 
= (wxWindow
*)node
->Data(); 
 592             if (child
->m_isStaticBox
) 
 594                 // wxStaticBox is transparent in the box itself 
 597                 int xx1 
= child
->m_x
; 
 598                 int yy1 
= child
->m_y
; 
 599                 int xx2 
= child
->m_x 
+ child
->m_width
; 
 600                 int yy2 
= child
->m_x 
+ child
->m_height
; 
 603                 if (((x 
>= xx1
) && (x 
<= xx1
+10) && (y 
>= yy1
) && (y 
<= yy2
)) || 
 605                     ((x 
>= xx2
-10) && (x 
<= xx2
) && (y 
>= yy1
) && (y 
<= yy2
)) || 
 607                     ((x 
>= xx1
) && (x 
<= xx2
) && (y 
>= yy1
) && (y 
<= yy1
+10)) || 
 609                     ((x 
>= xx1
) && (x 
<= xx2
) && (y 
>= yy2
-1) && (y 
<= yy2
))) 
 612                     event
.m_x 
-= child
->m_x
; 
 613                     event
.m_y 
-= child
->m_y
; 
 620                 if ((child
->m_wxwindow 
== (GtkWidget
*) NULL
) && 
 621                     (child
->m_x 
<= event
.m_x
) && 
 622                     (child
->m_y 
<= event
.m_y
) && 
 623                     (child
->m_x
+child
->m_width  
>= event
.m_x
) && 
 624                     (child
->m_y
+child
->m_height 
>= event
.m_y
)) 
 627                     event
.m_x 
-= child
->m_x
; 
 628                     event
.m_y 
-= child
->m_y
; 
 636     wxPoint 
pt(win
->GetClientAreaOrigin()); 
 640     event
.SetEventObject( win 
); 
 642     gs_timeLastClick 
= gdk_event
->time
; 
 644     if (win
->GetEventHandler()->ProcessEvent( event 
)) 
 645         gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_press_event" ); 
 650 //----------------------------------------------------------------------------- 
 651 // "button_release_event" 
 652 //----------------------------------------------------------------------------- 
 654 static gint 
gtk_window_button_release_callback( GtkWidget 
*widget
, GdkEventButton 
*gdk_event
, wxWindow 
*win 
) 
 656     if (!win
->IsOwnGtkWindow( gdk_event
->window 
)) return TRUE
; 
 658     if (g_blockEventsOnDrag
) return TRUE
; 
 659     if (g_blockEventsOnScroll
) return TRUE
; 
 661     if (!win
->HasVMT()) return TRUE
; 
 664     printf( "OnButtonRelease from " ); 
 665     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
 666         printf( win->GetClassInfo()->GetClassName() ); 
 670     wxEventType event_type 
= wxEVT_NULL
; 
 672     switch (gdk_event
->button
) 
 674         case 1: event_type 
= wxEVT_LEFT_UP
; break; 
 675         case 2: event_type 
= wxEVT_MIDDLE_UP
; break; 
 676         case 3: event_type 
= wxEVT_RIGHT_UP
; break; 
 679     wxMouseEvent 
event( event_type 
); 
 680     event
.m_shiftDown 
= (gdk_event
->state 
& GDK_SHIFT_MASK
); 
 681     event
.m_controlDown 
= (gdk_event
->state 
& GDK_CONTROL_MASK
); 
 682     event
.m_altDown 
= (gdk_event
->state 
& GDK_MOD1_MASK
); 
 683     event
.m_metaDown 
= (gdk_event
->state 
& GDK_MOD2_MASK
); 
 684     event
.m_leftDown 
= (gdk_event
->state 
& GDK_BUTTON1_MASK
); 
 685     event
.m_middleDown 
= (gdk_event
->state 
& GDK_BUTTON2_MASK
); 
 686     event
.m_rightDown 
= (gdk_event
->state 
& GDK_BUTTON3_MASK
); 
 687     event
.m_x 
= (long)gdk_event
->x
; 
 688     event
.m_y 
= (long)gdk_event
->y
; 
 690     // Some control don't have their own X window and thus cannot get 
 695         wxNode 
*node 
= win
->GetChildren().First(); 
 698             wxWindow 
*child 
= (wxWindow
*)node
->Data(); 
 700             if (child
->m_isStaticBox
) 
 702                 // wxStaticBox is transparent in the box itself 
 705                 int xx1 
= child
->m_x
; 
 706                 int yy1 
= child
->m_y
; 
 707                 int xx2 
= child
->m_x 
+ child
->m_width
; 
 708                 int yy2 
= child
->m_x 
+ child
->m_height
; 
 711                 if (((x 
>= xx1
) && (x 
<= xx1
+10) && (y 
>= yy1
) && (y 
<= yy2
)) || 
 713                     ((x 
>= xx2
-10) && (x 
<= xx2
) && (y 
>= yy1
) && (y 
<= yy2
)) || 
 715                     ((x 
>= xx1
) && (x 
<= xx2
) && (y 
>= yy1
) && (y 
<= yy1
+10)) || 
 717                     ((x 
>= xx1
) && (x 
<= xx2
) && (y 
>= yy2
-1) && (y 
<= yy2
))) 
 720                     event
.m_x 
-= child
->m_x
; 
 721                     event
.m_y 
-= child
->m_y
; 
 728                 if ((child
->m_wxwindow 
== (GtkWidget
*) NULL
) && 
 729                     (child
->m_x 
<= event
.m_x
) && 
 730                     (child
->m_y 
<= event
.m_y
) && 
 731                     (child
->m_x
+child
->m_width  
>= event
.m_x
) && 
 732                     (child
->m_y
+child
->m_height 
>= event
.m_y
)) 
 735                     event
.m_x 
-= child
->m_x
; 
 736                     event
.m_y 
-= child
->m_y
; 
 744     wxPoint 
pt(win
->GetClientAreaOrigin()); 
 748     event
.SetEventObject( win 
); 
 750     if (win
->GetEventHandler()->ProcessEvent( event 
)) 
 751         gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_release_event" ); 
 756 //----------------------------------------------------------------------------- 
 757 // "motion_notify_event" 
 758 //----------------------------------------------------------------------------- 
 760 static gint 
gtk_window_motion_notify_callback( GtkWidget 
*widget
, GdkEventMotion 
*gdk_event
, wxWindow 
*win 
) 
 762     if (gdk_event
->is_hint
) 
 766        GdkModifierType state
; 
 767        gdk_window_get_pointer(gdk_event
->window
, &x
, &y
, &state
); 
 770        gdk_event
->state 
= state
; 
 773     if (!win
->IsOwnGtkWindow( gdk_event
->window 
)) return TRUE
; 
 775     if (g_blockEventsOnDrag
) return TRUE
; 
 776     if (g_blockEventsOnScroll
) return TRUE
; 
 778     if (!win
->HasVMT()) return TRUE
; 
 781     printf( "OnMotion from " ); 
 782     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
 783       printf( win->GetClassInfo()->GetClassName() ); 
 787     wxMouseEvent 
event( wxEVT_MOTION 
); 
 788     event
.m_shiftDown 
= (gdk_event
->state 
& GDK_SHIFT_MASK
); 
 789     event
.m_controlDown 
= (gdk_event
->state 
& GDK_CONTROL_MASK
); 
 790     event
.m_altDown 
= (gdk_event
->state 
& GDK_MOD1_MASK
); 
 791     event
.m_metaDown 
= (gdk_event
->state 
& GDK_MOD2_MASK
); 
 792     event
.m_leftDown 
= (gdk_event
->state 
& GDK_BUTTON1_MASK
); 
 793     event
.m_middleDown 
= (gdk_event
->state 
& GDK_BUTTON2_MASK
); 
 794     event
.m_rightDown 
= (gdk_event
->state 
& GDK_BUTTON3_MASK
); 
 796     event
.m_x 
= (long)gdk_event
->x
; 
 797     event
.m_y 
= (long)gdk_event
->y
; 
 799     // Some control don't have their own X window and thus cannot get 
 804         wxNode 
*node 
= win
->GetChildren().First(); 
 807             wxWindow 
*child 
= (wxWindow
*)node
->Data(); 
 809             if (child
->m_isStaticBox
) 
 811                 // wxStaticBox is transparent in the box itself 
 814                 int xx1 
= child
->m_x
; 
 815                 int yy1 
= child
->m_y
; 
 816                 int xx2 
= child
->m_x 
+ child
->m_width
; 
 817                 int yy2 
= child
->m_x 
+ child
->m_height
; 
 820                 if (((x 
>= xx1
) && (x 
<= xx1
+10) && (y 
>= yy1
) && (y 
<= yy2
)) || 
 822                     ((x 
>= xx2
-10) && (x 
<= xx2
) && (y 
>= yy1
) && (y 
<= yy2
)) || 
 824                     ((x 
>= xx1
) && (x 
<= xx2
) && (y 
>= yy1
) && (y 
<= yy1
+10)) || 
 826                     ((x 
>= xx1
) && (x 
<= xx2
) && (y 
>= yy2
-1) && (y 
<= yy2
))) 
 829                     event
.m_x 
-= child
->m_x
; 
 830                     event
.m_y 
-= child
->m_y
; 
 837                 if ((child
->m_wxwindow 
== (GtkWidget
*) NULL
) && 
 838                     (child
->m_x 
<= event
.m_x
) && 
 839                     (child
->m_y 
<= event
.m_y
) && 
 840                     (child
->m_x
+child
->m_width  
>= event
.m_x
) && 
 841                     (child
->m_y
+child
->m_height 
>= event
.m_y
)) 
 844                     event
.m_x 
-= child
->m_x
; 
 845                     event
.m_y 
-= child
->m_y
; 
 853     wxPoint 
pt(win
->GetClientAreaOrigin()); 
 857     event
.SetEventObject( win 
); 
 859     if (win
->GetEventHandler()->ProcessEvent( event 
)) 
 860         gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "motion_notify_event" ); 
 865 //----------------------------------------------------------------------------- 
 867 //----------------------------------------------------------------------------- 
 869 static gint 
gtk_window_focus_in_callback( GtkWidget 
*widget
, GdkEvent 
*WXUNUSED(event
), wxWindow 
*win 
) 
 871     if (g_blockEventsOnDrag
) return TRUE
; 
 877         if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
)) 
 879             GTK_WIDGET_SET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
); 
 881             printf( "SetFocus flag from " ); 
 882             if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
 883                 printf( win->GetClassInfo()->GetClassName() ); 
 889     if (!win
->HasVMT()) return TRUE
; 
 892     printf( "OnSetFocus from " ); 
 893     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
 894         printf( win->GetClassInfo()->GetClassName() ); 
 896     printf( WXSTRINGCAST win->GetLabel() ); 
 900     wxFocusEvent 
event( wxEVT_SET_FOCUS
, win
->GetId() ); 
 901     event
.SetEventObject( win 
); 
 903     if (win
->GetEventHandler()->ProcessEvent( event 
)) 
 904         gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_in_event" ); 
 909 //----------------------------------------------------------------------------- 
 911 //----------------------------------------------------------------------------- 
 913 static gint 
gtk_window_focus_out_callback( GtkWidget 
*widget
, GdkEvent 
*WXUNUSED(event
), wxWindow 
*win 
) 
 915     if (g_blockEventsOnDrag
) return TRUE
; 
 918       if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
)) 
 919           GTK_WIDGET_UNSET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
); 
 922     if (!win
->HasVMT()) return TRUE
; 
 925     printf( "OnKillFocus from " ); 
 926     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
 927         printf( win->GetClassInfo()->GetClassName() ); 
 931     wxFocusEvent 
event( wxEVT_KILL_FOCUS
, win
->GetId() ); 
 932     event
.SetEventObject( win 
); 
 934     if (win
->GetEventHandler()->ProcessEvent( event 
)) 
 935         gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_out_event" ); 
 940 //----------------------------------------------------------------------------- 
 941 // "enter_notify_event" 
 942 //----------------------------------------------------------------------------- 
 944 static gint 
gtk_window_enter_callback( GtkWidget 
*widget
, GdkEventCrossing 
*gdk_event
, wxWindow 
*win 
) 
 946     if (g_blockEventsOnDrag
) return TRUE
; 
 948     if ((widget
->window
) && (win
->m_cursor
)) 
 949         gdk_window_set_cursor( widget
->window
, win
->m_cursor
->GetCursor() ); 
 951     if (widget
->window 
!= gdk_event
->window
) return TRUE
; 
 953     if (!win
->HasVMT()) return TRUE
; 
 956     printf( "OnEnter from " ); 
 957     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
 958         printf( win->GetClassInfo()->GetClassName() ); 
 962     wxMouseEvent 
event( wxEVT_ENTER_WINDOW 
); 
 963     event
.SetEventObject( win 
); 
 967     GdkModifierType state 
= (GdkModifierType
)0; 
 969     gdk_window_get_pointer( widget
->window
, &x
, &y
, &state 
); 
 971     event
.m_shiftDown 
= (state 
& GDK_SHIFT_MASK
); 
 972     event
.m_controlDown 
= (state 
& GDK_CONTROL_MASK
); 
 973     event
.m_altDown 
= (state 
& GDK_MOD1_MASK
); 
 974     event
.m_metaDown 
= (state 
& GDK_MOD2_MASK
); 
 975     event
.m_leftDown 
= (state 
& GDK_BUTTON1_MASK
); 
 976     event
.m_middleDown 
= (state 
& GDK_BUTTON2_MASK
); 
 977     event
.m_rightDown 
= (state 
& GDK_BUTTON3_MASK
); 
 982     wxPoint 
pt(win
->GetClientAreaOrigin()); 
 986     if (win
->GetEventHandler()->ProcessEvent( event 
)) 
 987        gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "enter_notify_event" ); 
 992 //----------------------------------------------------------------------------- 
 993 // "leave_notify_event" 
 994 //----------------------------------------------------------------------------- 
 996 static gint 
gtk_window_leave_callback( GtkWidget 
*widget
, GdkEventCrossing 
*gdk_event
, wxWindow 
*win 
) 
 998     if (g_blockEventsOnDrag
) return TRUE
; 
1000     if ((widget
->window
) && (win
->m_cursor
)) 
1001         gdk_window_set_cursor( widget
->window
, wxSTANDARD_CURSOR
->GetCursor() ); 
1003     if (widget
->window 
!= gdk_event
->window
) return TRUE
; 
1005     if (!win
->HasVMT()) return TRUE
; 
1008     printf( "OnLeave from " ); 
1009     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
1010         printf( win->GetClassInfo()->GetClassName() ); 
1014     wxMouseEvent 
event( wxEVT_LEAVE_WINDOW 
); 
1015     event
.SetEventObject( win 
); 
1019     GdkModifierType state 
= (GdkModifierType
)0; 
1021     gdk_window_get_pointer( widget
->window
, &x
, &y
, &state 
); 
1023     event
.m_shiftDown 
= (state 
& GDK_SHIFT_MASK
); 
1024     event
.m_controlDown 
= (state 
& GDK_CONTROL_MASK
); 
1025     event
.m_altDown 
= (state 
& GDK_MOD1_MASK
); 
1026     event
.m_metaDown 
= (state 
& GDK_MOD2_MASK
); 
1027     event
.m_leftDown 
= (state 
& GDK_BUTTON1_MASK
); 
1028     event
.m_middleDown 
= (state 
& GDK_BUTTON2_MASK
); 
1029     event
.m_rightDown 
= (state 
& GDK_BUTTON3_MASK
); 
1031     event
.m_x 
= (long)x
; 
1032     event
.m_y 
= (long)y
; 
1034     wxPoint 
pt(win
->GetClientAreaOrigin()); 
1038     if (win
->GetEventHandler()->ProcessEvent( event 
)) 
1039         gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "leave_notify_event" ); 
1044 //----------------------------------------------------------------------------- 
1045 // "value_changed" from m_vAdjust 
1046 //----------------------------------------------------------------------------- 
1048 static void gtk_window_vscroll_callback( GtkWidget 
*WXUNUSED(widget
), wxWindow 
*win 
) 
1050     if (g_blockEventsOnDrag
) return; 
1053     printf( "OnVScroll from " ); 
1054     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
1055         printf( win->GetClassInfo()->GetClassName() ); 
1059     if (!win
->HasVMT()) return; 
1061     float diff 
= win
->m_vAdjust
->value 
- win
->m_oldVerticalPos
; 
1062     if (fabs(diff
) < 0.2) return; 
1064     wxEventType command 
= wxEVT_NULL
; 
1066     float line_step 
= win
->m_vAdjust
->step_increment
; 
1067     float page_step 
= win
->m_vAdjust
->page_increment
; 
1069     if (win
->m_isScrolling
) 
1071         command 
= wxEVT_SCROLL_THUMBTRACK
; 
1075         if (fabs(win
->m_vAdjust
->value
-win
->m_vAdjust
->lower
) < 0.2) command 
= wxEVT_SCROLL_BOTTOM
; 
1076         else if (fabs(win
->m_vAdjust
->value
-win
->m_vAdjust
->upper
) < 0.2) command 
= wxEVT_SCROLL_TOP
; 
1077         else if (fabs(diff
-line_step
) < 0.2) command 
= wxEVT_SCROLL_LINEDOWN
; 
1078         else if (fabs(diff
+line_step
) < 0.2) command 
= wxEVT_SCROLL_LINEUP
; 
1079         else if (fabs(diff
-page_step
) < 0.2) command 
= wxEVT_SCROLL_PAGEDOWN
; 
1080         else if (fabs(diff
+page_step
) < 0.2) command 
= wxEVT_SCROLL_PAGEUP
; 
1081         else command 
= wxEVT_SCROLL_THUMBTRACK
; 
1084     int value 
= (int)(win
->m_vAdjust
->value
+0.5); 
1086     wxScrollEvent 
event( command
, win
->GetId(), value
, wxVERTICAL 
); 
1087     event
.SetEventObject( win 
); 
1088     win
->GetEventHandler()->ProcessEvent( event 
); 
1091 //----------------------------------------------------------------------------- 
1092 // "value_changed" from m_hAdjust 
1093 //----------------------------------------------------------------------------- 
1095 static void gtk_window_hscroll_callback( GtkWidget 
*WXUNUSED(widget
), wxWindow 
*win 
) 
1097     if (g_blockEventsOnDrag
) return; 
1100     printf( "OnHScroll from " ); 
1101     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
1102         printf( win->GetClassInfo()->GetClassName() ); 
1106     if (!win
->HasVMT()) return; 
1108     float diff 
= win
->m_hAdjust
->value 
- win
->m_oldHorizontalPos
; 
1109     if (fabs(diff
) < 0.2) return; 
1111     wxEventType command 
= wxEVT_NULL
; 
1113     float line_step 
= win
->m_hAdjust
->step_increment
; 
1114     float page_step 
= win
->m_hAdjust
->page_increment
; 
1116     if (win
->m_isScrolling
) 
1118         command 
= wxEVT_SCROLL_THUMBTRACK
; 
1122         if (fabs(win
->m_hAdjust
->value
-win
->m_hAdjust
->lower
) < 0.2) command 
= wxEVT_SCROLL_BOTTOM
; 
1123         else if (fabs(win
->m_hAdjust
->value
-win
->m_hAdjust
->upper
) < 0.2) command 
= wxEVT_SCROLL_TOP
; 
1124         else if (fabs(diff
-line_step
) < 0.2) command 
= wxEVT_SCROLL_LINEDOWN
; 
1125         else if (fabs(diff
+line_step
) < 0.2) command 
= wxEVT_SCROLL_LINEUP
; 
1126         else if (fabs(diff
-page_step
) < 0.2) command 
= wxEVT_SCROLL_PAGEDOWN
; 
1127         else if (fabs(diff
+page_step
) < 0.2) command 
= wxEVT_SCROLL_PAGEUP
; 
1128         else command 
= wxEVT_SCROLL_THUMBTRACK
; 
1131     int value 
= (int)(win
->m_hAdjust
->value
+0.5); 
1133     wxScrollEvent 
event( command
, win
->GetId(), value
, wxHORIZONTAL 
); 
1134     event
.SetEventObject( win 
); 
1135     win
->GetEventHandler()->ProcessEvent( event 
); 
1138 //----------------------------------------------------------------------------- 
1139 // "changed" from m_vAdjust 
1140 //----------------------------------------------------------------------------- 
1142 static void gtk_window_vscroll_change_callback( GtkWidget 
*WXUNUSED(widget
), wxWindow 
*win 
) 
1144     if (g_blockEventsOnDrag
) return; 
1147     printf( "OnVScroll change from " ); 
1148     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
1149         printf( win->GetClassInfo()->GetClassName() ); 
1153     if (!win
->HasVMT()) return; 
1155     wxEventType command 
= wxEVT_SCROLL_THUMBTRACK
; 
1156     int value 
= (int)(win
->m_vAdjust
->value
+0.5); 
1158     wxScrollEvent 
event( command
, win
->GetId(), value
, wxVERTICAL 
); 
1159     event
.SetEventObject( win 
); 
1160     win
->GetEventHandler()->ProcessEvent( event 
); 
1163 //----------------------------------------------------------------------------- 
1164 // "changed" from m_hAdjust 
1165 //----------------------------------------------------------------------------- 
1167 static void gtk_window_hscroll_change_callback( GtkWidget 
*WXUNUSED(widget
), wxWindow 
*win 
) 
1169     if (g_blockEventsOnDrag
) return; 
1172     printf( "OnHScroll change from " ); 
1173     if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) 
1174         printf( win->GetClassInfo()->GetClassName() ); 
1178     if (!win
->HasVMT()) return; 
1180     wxEventType command 
= wxEVT_SCROLL_THUMBTRACK
; 
1181     int value 
= (int)(win
->m_hAdjust
->value
+0.5); 
1183     wxScrollEvent 
event( command
, win
->GetId(), value
, wxHORIZONTAL 
); 
1184     event
.SetEventObject( win 
); 
1185     win
->GetEventHandler()->ProcessEvent( event 
); 
1188 //----------------------------------------------------------------------------- 
1189 // "button_press_event" from scrollbar 
1190 //----------------------------------------------------------------------------- 
1192 static gint 
gtk_scrollbar_button_press_callback( GtkRange 
*WXUNUSED(widget
), 
1193                                                  GdkEventButton 
*WXUNUSED(gdk_event
), 
1196 //  don't test here as we can release the mouse while being over 
1197 //  a different window then the slider 
1199 //    if (gdk_event->window != widget->slider) return FALSE; 
1201     win
->m_isScrolling 
= TRUE
; 
1202     g_blockEventsOnScroll 
= TRUE
; 
1207 //----------------------------------------------------------------------------- 
1208 // "button_release_event" from scrollbar 
1209 //----------------------------------------------------------------------------- 
1211 static gint 
gtk_scrollbar_button_release_callback( GtkRange 
*widget
, 
1212                                                    GdkEventButton 
*WXUNUSED(gdk_event
), 
1216 //  don't test here as we can release the mouse while being over 
1217 //  a different window then the slider 
1219 //    if (gdk_event->window != widget->slider) return FALSE; 
1221     GtkScrolledWindow 
*s_window 
= GTK_SCROLLED_WINDOW(win
->m_widget
); 
1223     if (widget 
== GTK_RANGE(s_window
->vscrollbar
)) 
1224         gtk_signal_emit_by_name( GTK_OBJECT(win
->m_hAdjust
), "value_changed" ); 
1226         gtk_signal_emit_by_name( GTK_OBJECT(win
->m_vAdjust
), "value_changed" ); 
1228     win
->m_isScrolling 
= FALSE
; 
1229     g_blockEventsOnScroll 
= FALSE
; 
1234 //----------------------------------------------------------------------------- 
1235 // InsertChild for wxWindow. 
1236 //----------------------------------------------------------------------------- 
1238 /* Callback for wxWindow. This very strange beast has to be used because 
1239  * C++ has no virtual methods in a constructor. We have to emulate a 
1240  * virtual function here as wxNotebook requires a different way to insert 
1241  * a child in it. I had opted for creating a wxNotebookPage window class 
1242  * which would have made this superfluous (such in the MDI window system), 
1243  * but no-one was listening to me... */ 
1245 static void wxInsertChildInWindow( wxWindow
* parent
, wxWindow
* child 
) 
1247     gtk_myfixed_put( GTK_MYFIXED(parent
->m_wxwindow
), 
1248                      GTK_WIDGET(child
->m_widget
), 
1252     gtk_widget_set_usize( GTK_WIDGET(child
->m_widget
), 
1256     if (wxIS_KIND_OF(parent
,wxFrame
)) 
1258         parent
->m_sizeSet 
= FALSE
; 
1261     if (parent
->m_windowStyle 
& wxTAB_TRAVERSAL
) 
1263         /* we now allow a window to get the focus as long as it 
1264            doesn't have any children. */ 
1265         GTK_WIDGET_UNSET_FLAGS( parent
->m_wxwindow
, GTK_CAN_FOCUS 
); 
1269 //----------------------------------------------------------------------------- 
1271 //----------------------------------------------------------------------------- 
1273 wxWindow
* wxGetActiveWindow() 
1275   return g_focusWindow
; 
1278 //----------------------------------------------------------------------------- 
1280 //----------------------------------------------------------------------------- 
1282 IMPLEMENT_DYNAMIC_CLASS(wxWindow
,wxEvtHandler
) 
1284 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
) 
1285     EVT_SIZE(wxWindow::OnSize
) 
1286     EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
) 
1287     EVT_INIT_DIALOG(wxWindow::OnInitDialog
) 
1288     EVT_KEY_DOWN(wxWindow::OnKeyDown
) 
1291 wxWindow::wxWindow() 
1293     m_widget 
= (GtkWidget 
*) NULL
; 
1294     m_wxwindow 
= (GtkWidget 
*) NULL
; 
1295     m_parent 
= (wxWindow 
*) NULL
; 
1296     m_children
.DeleteContents( FALSE 
); 
1309     m_eventHandler 
= this; 
1310     m_windowValidator 
= (wxValidator 
*) NULL
; 
1314     m_cursor 
= (wxCursor 
*) NULL
; 
1315     m_font 
= *wxSWISS_FONT
; 
1317     m_windowName 
= "noname"; 
1319     m_constraints 
= (wxLayoutConstraints 
*) NULL
; 
1320     m_constraintsInvolvedIn 
= (wxList 
*) NULL
; 
1321     m_windowSizer 
= (wxSizer 
*) NULL
; 
1322     m_sizerParent 
= (wxWindow 
*) NULL
; 
1323     m_autoLayout 
= FALSE
; 
1327     m_needParent 
= TRUE
; 
1329     m_hasScrolling 
= FALSE
; 
1330     m_isScrolling 
= FALSE
; 
1331     m_hAdjust 
= (GtkAdjustment
*) NULL
; 
1332     m_vAdjust 
= (GtkAdjustment
*) NULL
; 
1333     m_oldHorizontalPos 
= 0.0; 
1334     m_oldVerticalPos 
= 0.0; 
1339 #if wxUSE_DRAG_AND_DROP 
1340     m_dropTarget 
= (wxDropTarget
*) NULL
; 
1343     m_scrollGC 
= (GdkGC
*) NULL
; 
1344     m_widgetStyle 
= (GtkStyle
*) NULL
; 
1346     m_insertCallback 
= wxInsertChildInWindow
; 
1348     m_clientObject 
= (wxClientData
*) NULL
; 
1349     m_clientData 
= NULL
; 
1351     m_isStaticBox 
= FALSE
; 
1352     m_acceptsFocus 
= FALSE
; 
1355     m_toolTip 
= (wxToolTip
*) NULL
; 
1356 #endif // wxUSE_TOOLTIPS 
1359 wxWindow::wxWindow( wxWindow 
*parent
, wxWindowID id
, 
1360                     const wxPoint 
&pos
, const wxSize 
&size
, 
1361                     long style
, const wxString 
&name  
) 
1363     m_insertCallback 
= wxInsertChildInWindow
; 
1364     Create( parent
, id
, pos
, size
, style
, name 
); 
1367 bool wxWindow::Create( wxWindow 
*parent
, wxWindowID id
, 
1368                        const wxPoint 
&pos
, const wxSize 
&size
, 
1369                        long style
, const wxString 
&name  
) 
1373     m_needParent 
= TRUE
; 
1375     PreCreation( parent
, id
, pos
, size
, style
, name 
); 
1377     m_widget 
= gtk_scrolled_window_new( (GtkAdjustment 
*) NULL
, (GtkAdjustment 
*) NULL 
); 
1378     GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS 
); 
1381     debug_focus_in( m_widget
, "wxWindow::m_widget", name 
); 
1384     GtkScrolledWindow 
*s_window 
= GTK_SCROLLED_WINDOW(m_widget
); 
1387     debug_focus_in( s_window
->hscrollbar
, "wxWindow::hsrcollbar", name 
); 
1388     debug_focus_in( s_window
->vscrollbar
, "wxWindow::vsrcollbar", name 
); 
1391     GtkScrolledWindowClass 
*scroll_class 
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass 
); 
1392     scroll_class
->scrollbar_spacing 
= 0; 
1394     gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC 
); 
1396     m_oldHorizontalPos 
= 0.0; 
1397     m_oldVerticalPos 
= 0.0; 
1399     m_hAdjust 
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) ); 
1400     m_vAdjust 
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) ); 
1402     m_wxwindow 
= gtk_myfixed_new(); 
1405     debug_focus_in( m_wxwindow
, "wxWindow::m_wxwindow", name 
); 
1408 #ifdef NEW_GTK_SCROLL_CODE 
1409     gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget
), m_wxwindow 
); 
1410     GtkViewport 
*viewport 
= GTK_VIEWPORT(s_window
->child
); 
1412     gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow 
); 
1413     GtkViewport 
*viewport 
= GTK_VIEWPORT(s_window
->viewport
); 
1417     debug_focus_in( GTK_WIDGET(viewport
), "wxWindow::viewport", name 
); 
1420     if (m_windowStyle 
& wxRAISED_BORDER
) 
1422         gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT 
); 
1424     else if (m_windowStyle 
& wxSUNKEN_BORDER
) 
1426         gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN 
); 
1430         gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE 
); 
1433     if (m_windowStyle 
& wxTAB_TRAVERSAL
) 
1435         /* we now allow a window to get the focus as long as it 
1436            doesn't have any children. */ 
1437         GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS 
); 
1438         m_acceptsFocus 
= FALSE
; 
1442         GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS 
); 
1443         m_acceptsFocus 
= TRUE
; 
1446     // shut the viewport up 
1447     gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ); 
1448     gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ); 
1450     // I _really_ don't want scrollbars in the beginning 
1451     m_vAdjust
->lower 
= 0.0; 
1452     m_vAdjust
->upper 
= 1.0; 
1453     m_vAdjust
->value 
= 0.0; 
1454     m_vAdjust
->step_increment 
= 1.0; 
1455     m_vAdjust
->page_increment 
= 1.0; 
1456     m_vAdjust
->page_size 
= 5.0; 
1457     gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" ); 
1458     m_hAdjust
->lower 
= 0.0; 
1459     m_hAdjust
->upper 
= 1.0; 
1460     m_hAdjust
->value 
= 0.0; 
1461     m_hAdjust
->step_increment 
= 1.0; 
1462     m_hAdjust
->page_increment 
= 1.0; 
1463     m_hAdjust
->page_size 
= 5.0; 
1464     gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" ); 
1466     // these handlers block mouse events to any window during scrolling 
1467     // such as motion events and prevent GTK and wxWindows from fighting 
1468     // over where the slider should be 
1470     gtk_signal_connect( GTK_OBJECT(s_window
->vscrollbar
), "button_press_event", 
1471           (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this ); 
1473     gtk_signal_connect( GTK_OBJECT(s_window
->hscrollbar
), "button_press_event", 
1474           (GtkSignalFunc
)gtk_scrollbar_button_press_callback
, (gpointer
) this ); 
1476     gtk_signal_connect( GTK_OBJECT(s_window
->vscrollbar
), "button_release_event", 
1477           (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this ); 
1479     gtk_signal_connect( GTK_OBJECT(s_window
->hscrollbar
), "button_release_event", 
1480           (GtkSignalFunc
)gtk_scrollbar_button_release_callback
, (gpointer
) this ); 
1482     // these handers het notified when screen updates are required either when 
1483     // scrolling or when the window size (and therefore scrollbar configuration) 
1486     gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "value_changed", 
1487           (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this ); 
1488     gtk_signal_connect( GTK_OBJECT(m_vAdjust
), "value_changed", 
1489           (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this ); 
1491     gtk_signal_connect( GTK_OBJECT(m_hAdjust
), "changed", 
1492           (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this ); 
1493     gtk_signal_connect(GTK_OBJECT(m_vAdjust
), "changed", 
1494           (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this ); 
1496     gtk_widget_show( m_wxwindow 
); 
1498     if (m_parent
) m_parent
->AddChild( this ); 
1500     (m_parent
->m_insertCallback
)( m_parent
, this ); 
1509 wxWindow::~wxWindow() 
1513 #if wxUSE_DRAG_AND_DROP 
1514     wxDELETE(m_dropTarget
); 
1518     wxDELETE(m_toolTip
); 
1519 #endif // wxUSE_TOOLTIPS 
1521     if (m_parent
) m_parent
->RemoveChild( this ); 
1522     if (m_widget
) Show( FALSE 
); 
1526     if (m_widgetStyle
) gtk_style_unref( m_widgetStyle 
); 
1528     if (m_scrollGC
) gdk_gc_unref( m_scrollGC 
); 
1530     if (m_wxwindow
) gtk_widget_destroy( m_wxwindow 
); 
1532     if (m_widget
) gtk_widget_destroy( m_widget 
); 
1534     if (m_cursor
) delete m_cursor
; 
1536     DeleteRelatedConstraints(); 
1539         // This removes any dangling pointers to this window 
1540         // in other windows' constraintsInvolvedIn lists. 
1541         UnsetConstraints(m_constraints
); 
1542         delete m_constraints
; 
1543         m_constraints 
= (wxLayoutConstraints 
*) NULL
; 
1547         delete m_windowSizer
; 
1548         m_windowSizer 
= (wxSizer 
*) NULL
; 
1550     // If this is a child of a sizer, remove self from parent 
1551     if (m_sizerParent
) m_sizerParent
->RemoveChild((wxWindow 
*)this); 
1553     // Just in case the window has been Closed, but 
1554     // we're then deleting immediately: don't leave 
1555     // dangling pointers. 
1556     wxPendingDelete
.DeleteObject(this); 
1558     // Just in case we've loaded a top-level window via 
1559     // wxWindow::LoadNativeDialog but we weren't a dialog 
1561     wxTopLevelWindows
.DeleteObject(this); 
1563     if (m_windowValidator
) delete m_windowValidator
; 
1565     if (m_clientObject
) delete m_clientObject
; 
1568 void wxWindow::PreCreation( wxWindow 
*parent
, wxWindowID id
, 
1569       const wxPoint 
&pos
, const wxSize 
&size
, 
1570       long style
, const wxString 
&name 
) 
1572     wxASSERT_MSG( (!m_needParent
) || (parent
), "Need complete parent." ); 
1574     m_widget 
= (GtkWidget
*) NULL
; 
1575     m_wxwindow 
= (GtkWidget
*) NULL
; 
1578     m_children
.DeleteContents( FALSE 
); 
1581     if (m_width 
== -1) m_width 
= 20; 
1583     if (m_height 
== -1) m_height 
= 20; 
1588     if (!m_needParent
)  // some reasonable defaults 
1592             m_x 
= (gdk_screen_width () - m_width
) / 2; 
1593             if (m_x 
< 10) m_x 
= 10; 
1597             m_y 
= (gdk_screen_height () - m_height
) / 2; 
1598             if (m_y 
< 10) m_y 
= 10; 
1609     m_eventHandler 
= this; 
1611     m_windowId 
= id 
== -1 ? wxNewId() : id
; 
1615     m_cursor 
= new wxCursor( wxCURSOR_ARROW 
); 
1616     m_font 
= *wxSWISS_FONT
; 
1617     m_backgroundColour 
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE 
); 
1618     m_foregroundColour 
= *wxBLACK
; 
1619     m_windowStyle 
= style
; 
1620     m_windowName 
= name
; 
1622     m_constraints 
= (wxLayoutConstraints 
*) NULL
; 
1623     m_constraintsInvolvedIn 
= (wxList 
*) NULL
; 
1624     m_windowSizer 
= (wxSizer 
*) NULL
; 
1625     m_sizerParent 
= (wxWindow 
*) NULL
; 
1626     m_autoLayout 
= FALSE
; 
1628     m_hasScrolling 
= FALSE
; 
1629     m_isScrolling 
= FALSE
; 
1630     m_hAdjust 
= (GtkAdjustment 
*) NULL
; 
1631     m_vAdjust 
= (GtkAdjustment 
*) NULL
; 
1632     m_oldHorizontalPos 
= 0.0; 
1633     m_oldVerticalPos 
= 0.0; 
1638 #if wxUSE_DRAG_AND_DROP 
1639     m_dropTarget 
= (wxDropTarget 
*) NULL
; 
1642     m_windowValidator 
= (wxValidator 
*) NULL
; 
1643     m_scrollGC 
= (GdkGC
*) NULL
; 
1644     m_widgetStyle 
= (GtkStyle
*) NULL
; 
1646     m_clientObject 
= (wxClientData
*)NULL
; 
1647     m_clientData 
= NULL
; 
1649     m_isStaticBox 
= FALSE
; 
1652     m_toolTip 
= (wxToolTip
*) NULL
; 
1653 #endif // wxUSE_TOOLTIPS 
1656 void wxWindow::PostCreation() 
1660       gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event", 
1661         GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this ); 
1663       gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw", 
1664         GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this ); 
1667     ConnectWidget( GetConnectWidget() ); 
1669     if (m_widget 
&& m_parent
) gtk_widget_realize( m_widget 
); 
1671     if (m_wxwindow
) gtk_widget_realize( m_wxwindow 
); 
1673     SetCursor( *wxSTANDARD_CURSOR 
); 
1678 void wxWindow::ConnectWidget( GtkWidget 
*widget 
) 
1680     gtk_signal_connect( GTK_OBJECT(widget
), "key_press_event", 
1681       GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this ); 
1683     gtk_signal_connect( GTK_OBJECT(widget
), "key_release_event", 
1684       GTK_SIGNAL_FUNC(gtk_window_key_release_callback
), (gpointer
)this ); 
1686     gtk_signal_connect( GTK_OBJECT(widget
), "button_press_event", 
1687       GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this ); 
1689     gtk_signal_connect( GTK_OBJECT(widget
), "button_release_event", 
1690       GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this ); 
1692     gtk_signal_connect( GTK_OBJECT(widget
), "motion_notify_event", 
1693       GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this ); 
1695     gtk_signal_connect( GTK_OBJECT(widget
), "focus_in_event", 
1696       GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this ); 
1698     gtk_signal_connect( GTK_OBJECT(widget
), "focus_out_event", 
1699       GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this ); 
1701     gtk_signal_connect( GTK_OBJECT(widget
), "enter_notify_event", 
1702       GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this ); 
1704     gtk_signal_connect( GTK_OBJECT(widget
), "leave_notify_event", 
1705       GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this ); 
1708 bool wxWindow::HasVMT() 
1713 bool wxWindow::Close( bool force 
) 
1715     wxASSERT_MSG( (m_widget 
!= NULL
), "invalid window" ); 
1717     wxCloseEvent 
event(wxEVT_CLOSE_WINDOW
, m_windowId
); 
1718     event
.SetEventObject(this); 
1719     event
.SetCanVeto(!force
); 
1721     (void)GetEventHandler()->ProcessEvent(event
); 
1723     // when we're forced to close we do it anyhow, otherwise only if the 
1724     // application didn't forbid it (if the event wasn't processed, GetVeto() 
1725     // will return FALSE too) 
1726     if ( force 
|| !event
.GetVeto() ) 
1730 bool wxWindow::Destroy() 
1732     wxASSERT_MSG( (m_widget 
!= NULL
), "invalid window" ); 
1739 bool wxWindow::DestroyChildren() 
1742     while ((node 
= m_children
.First()) != (wxNode 
*)NULL
) 
1745         if ((child 
= (wxWindow 
*)node
->Data()) != (wxWindow 
*)NULL
) 
1748             if (m_children
.Member(child
)) delete node
; 
1754 void wxWindow::PrepareDC( wxDC 
&WXUNUSED(dc
) ) 
1756     // are we to set fonts here ? 
1759 wxPoint 
wxWindow::GetClientAreaOrigin() const 
1761     return wxPoint(0,0); 
1764 void wxWindow::AdjustForParentClientOrigin( int& x
, int& y
, int sizeFlags 
) 
1766     if (((sizeFlags 
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent()) 
1768         wxPoint 
pt(GetParent()->GetClientAreaOrigin()); 
1774 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags 
) 
1776     wxASSERT_MSG( (m_widget 
!= NULL
), "invalid window" ); 
1777     wxASSERT_MSG( (m_parent 
!= NULL
), "wxWindow::SetSize requires parent.\n" ); 
1779     if (m_resizing
) return; // I don't like recursions 
1782     if (m_parent
->m_wxwindow 
== NULL
) // i.e. wxNotebook 
1784         // don't set the size for children of wxNotebook, just take the values. 
1792         int old_width 
= m_width
; 
1793         int old_height 
= m_height
; 
1795         if ((sizeFlags 
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
) 
1797             if (x 
!= -1) m_x 
= x
; 
1798             if (y 
!= -1) m_y 
= y
; 
1799             if (width 
!= -1) m_width 
= width
; 
1800             if (height 
!= -1) m_height 
= height
; 
1810         if ((sizeFlags 
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
) 
1812              if (width 
== -1) m_width 
= 80; 
1815         if ((sizeFlags 
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
) 
1817              if (height 
== -1) m_height 
= 26; 
1820         if ((m_minWidth 
!= -1) && (m_width 
< m_minWidth
)) m_width 
= m_minWidth
; 
1821         if ((m_minHeight 
!= -1) && (m_height 
< m_minHeight
)) m_height 
= m_minHeight
; 
1822         if ((m_maxWidth 
!= -1) && (m_width 
> m_maxWidth
)) m_width 
= m_maxWidth
; 
1823         if ((m_maxHeight 
!= -1) && (m_height 
> m_maxHeight
)) m_height 
= m_maxHeight
; 
1825         wxPoint 
pt( m_parent
->GetClientAreaOrigin() ); 
1826         gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
+pt
.x
, m_y
+pt
.y 
); 
1828         if ((old_width 
!= m_width
) || (old_height 
!= m_height
)) 
1829              gtk_widget_set_usize( m_widget
, m_width
, m_height 
); 
1834     wxSizeEvent 
event( wxSize(m_width
,m_height
), GetId() ); 
1835     event
.SetEventObject( this ); 
1836     GetEventHandler()->ProcessEvent( event 
); 
1841 void wxWindow::OnInternalIdle() 
1846 void wxWindow::SetSize( int width
, int height 
) 
1848     SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING 
); 
1851 void wxWindow::Move( int x
, int y 
) 
1853     SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING 
); 
1856 void wxWindow::GetSize( int *width
, int *height 
) const 
1858     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
1860     if (width
) (*width
) = m_width
; 
1861     if (height
) (*height
) = m_height
; 
1864 void wxWindow::SetClientSize( int width
, int height 
) 
1866     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
1870         SetSize( width
, height 
); 
1877         if (!m_hasScrolling
) 
1879             GtkStyleClass 
*window_class 
= m_wxwindow
->style
->klass
; 
1881             if ((m_windowStyle 
& wxRAISED_BORDER
) || 
1882                 (m_windowStyle 
& wxSUNKEN_BORDER
)) 
1884                 dw 
+= 2 * window_class
->xthickness
; 
1885                 dh 
+= 2 * window_class
->ythickness
; 
1890             GtkScrolledWindow 
*scroll_window 
= GTK_SCROLLED_WINDOW(m_widget
); 
1891             GtkScrolledWindowClass 
*scroll_class 
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass 
); 
1893 #ifdef NEW_GTK_SCROLL_CODE 
1894             GtkWidget 
*viewport 
= scroll_window
->child
; 
1896             GtkWidget 
*viewport 
= scroll_window
->viewport
; 
1899             GtkStyleClass 
*viewport_class 
= viewport
->style
->klass
; 
1901             GtkWidget 
*hscrollbar 
= scroll_window
->hscrollbar
; 
1902             GtkWidget 
*vscrollbar 
= scroll_window
->vscrollbar
; 
1904             if ((m_windowStyle 
& wxRAISED_BORDER
) || 
1905                 (m_windowStyle 
& wxSUNKEN_BORDER
)) 
1907                 dw 
+= 2 * viewport_class
->xthickness
; 
1908                 dh 
+= 2 * viewport_class
->ythickness
; 
1911             if (scroll_window
->vscrollbar_visible
) 
1913                 dw 
+= vscrollbar
->allocation
.width
; 
1914                 dw 
+= scroll_class
->scrollbar_spacing
; 
1917             if (scroll_window
->hscrollbar_visible
) 
1919                 dh 
+= hscrollbar
->allocation
.height
; 
1920                 dw 
+= scroll_class
->scrollbar_spacing
; 
1924       SetSize( width
+dw
, height
+dh 
); 
1928 void wxWindow::GetClientSize( int *width
, int *height 
) const 
1930     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
1934         if (width
) (*width
) = m_width
; 
1935         if (height
) (*height
) = m_height
; 
1942         if (!m_hasScrolling
) 
1944             GtkStyleClass 
*window_class 
= m_wxwindow
->style
->klass
; 
1946             if ((m_windowStyle 
& wxRAISED_BORDER
) || 
1947                 (m_windowStyle 
& wxSUNKEN_BORDER
)) 
1949                 dw 
+= 2 * window_class
->xthickness
; 
1950                 dh 
+= 2 * window_class
->ythickness
; 
1955             GtkScrolledWindow 
*scroll_window 
= GTK_SCROLLED_WINDOW(m_widget
); 
1956             GtkScrolledWindowClass 
*scroll_class 
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass 
); 
1958 #ifdef NEW_GTK_SCROLL_CODE 
1959             GtkWidget 
*viewport 
= scroll_window
->child
; 
1961             GtkWidget 
*viewport 
= scroll_window
->viewport
; 
1964             GtkStyleClass 
*viewport_class 
= viewport
->style
->klass
; 
1966             if ((m_windowStyle 
& wxRAISED_BORDER
) || 
1967                 (m_windowStyle 
& wxSUNKEN_BORDER
)) 
1969                 dw 
+= 2 * viewport_class
->xthickness
; 
1970                 dh 
+= 2 * viewport_class
->ythickness
; 
1973             if (scroll_window
->vscrollbar_visible
) 
1975 //              dw += vscrollbar->allocation.width; 
1976                 dw 
+= 15;                               // range.slider_width = 11 + 2*2pts edge 
1977                 dw 
+= scroll_class
->scrollbar_spacing
; 
1980             if (scroll_window
->hscrollbar_visible
) 
1982 //              dh += hscrollbar->allocation.height; 
1984                 dh 
+= scroll_class
->scrollbar_spacing
; 
1988         if (width
) (*width
) = m_width 
- dw
; 
1989         if (height
) (*height
) = m_height 
- dh
; 
1993 void wxWindow::GetPosition( int *x
, int *y 
) const 
1995     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2001 void wxWindow::ClientToScreen( int *x
, int *y 
) 
2003     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2005     GdkWindow 
*source 
= (GdkWindow 
*) NULL
; 
2007         source 
= m_wxwindow
->window
; 
2009         source 
= m_widget
->window
; 
2013     gdk_window_get_origin( source
, &org_x
, &org_y 
); 
2017         if (GTK_WIDGET_NO_WINDOW (m_widget
)) 
2019             org_x 
+= m_widget
->allocation
.x
; 
2020             org_y 
+= m_widget
->allocation
.y
; 
2024     wxPoint 
pt(GetClientAreaOrigin()); 
2032 void wxWindow::ScreenToClient( int *x
, int *y 
) 
2034     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2036     GdkWindow 
*source 
= (GdkWindow 
*) NULL
; 
2038         source 
= m_wxwindow
->window
; 
2040         source 
= m_widget
->window
; 
2044     gdk_window_get_origin( source
, &org_x
, &org_y 
); 
2048         if (GTK_WIDGET_NO_WINDOW (m_widget
)) 
2050             org_x 
+= m_widget
->allocation
.x
; 
2051             org_y 
+= m_widget
->allocation
.y
; 
2055     wxPoint 
pt(GetClientAreaOrigin()); 
2063 void wxWindow::Centre( int direction 
) 
2065     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2074         m_parent
->GetSize( &p_w
, &p_h 
); 
2075         if (direction 
& wxHORIZONTAL 
== wxHORIZONTAL
) x 
= (p_w 
- m_width
) / 2; 
2076         if (direction 
& wxVERTICAL 
== wxVERTICAL
) y 
= (p_h 
- m_height
) / 2; 
2080         if (direction 
& wxHORIZONTAL 
== wxHORIZONTAL
) x 
= (gdk_screen_width () - m_width
) / 2; 
2081         if (direction 
& wxVERTICAL 
== wxVERTICAL
) y 
= (gdk_screen_height () - m_height
) / 2; 
2087 void wxWindow::Fit() 
2089     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2093     wxNode 
*node 
= m_children
.First(); 
2096         wxWindow 
*win 
= (wxWindow 
*)node
->Data(); 
2098         win
->GetPosition(&wx
, &wy
); 
2099         win
->GetSize(&ww
, &wh
); 
2100         if (wx 
+ ww 
> maxX
) maxX 
= wx 
+ ww
; 
2101         if (wy 
+ wh 
> maxY
) maxY 
= wy 
+ wh
; 
2103         node 
= node
->Next(); 
2106     SetClientSize(maxX 
+ 7, maxY 
+ 14); 
2109 void wxWindow::SetSizeHints( int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
) ) 
2111     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2119 void wxWindow::OnSize( wxSizeEvent 
&WXUNUSED(event
) ) 
2121 //  if (GetAutoLayout()) Layout(); 
2124 bool wxWindow::Show( bool show 
) 
2126     wxCHECK_MSG( (m_widget 
!= NULL
), FALSE
, "invalid window" ); 
2129         gtk_widget_show( m_widget 
); 
2131         gtk_widget_hide( m_widget 
); 
2138 void wxWindow::Enable( bool enable 
) 
2140     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2142     m_isEnabled 
= enable
; 
2144     gtk_widget_set_sensitive( m_widget
, enable 
); 
2145     if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable 
); 
2148 int wxWindow::GetCharHeight() const 
2150     wxCHECK_MSG( (m_widget 
!= NULL
), 12, "invalid window" ); 
2152     wxCHECK_MSG( m_font
.Ok(), 12, "invalid font" ); 
2154     GdkFont 
*font 
= m_font
.GetInternalFont( 1.0 ); 
2156     return font
->ascent 
+ font
->descent
; 
2159 int wxWindow::GetCharWidth() const 
2161     wxCHECK_MSG( (m_widget 
!= NULL
), 8, "invalid window" ); 
2163     wxCHECK_MSG( m_font
.Ok(), 8, "invalid font" ); 
2165     GdkFont 
*font 
= m_font
.GetInternalFont( 1.0 ); 
2167     return gdk_string_width( font
, "H" ); 
2170 void wxWindow::GetTextExtent( const wxString
& string
, int *x
, int *y
, 
2171   int *descent
, int *externalLeading
, const wxFont 
*theFont
, bool WXUNUSED(use16
) ) const 
2173     wxFont fontToUse 
= m_font
; 
2174     if (theFont
) fontToUse 
= *theFont
; 
2176     wxCHECK_RET( fontToUse
.Ok(), "invalid font" ); 
2178     GdkFont 
*font 
= fontToUse
.GetInternalFont( 1.0 ); 
2179     if (x
) (*x
) = gdk_string_width( font
, string 
); 
2180     if (y
) (*y
) = font
->ascent 
+ font
->descent
; 
2181     if (descent
) (*descent
) = font
->descent
; 
2182     if (externalLeading
) (*externalLeading
) = 0;  // ?? 
2185 void wxWindow::MakeModal( bool modal 
) 
2189     // Disable all other windows 
2190     if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
))) 
2192         wxNode 
*node 
= wxTopLevelWindows
.First(); 
2195             wxWindow 
*win 
= (wxWindow 
*)node
->Data(); 
2196             if (win 
!= this) win
->Enable(!modal
); 
2198             node 
= node
->Next(); 
2203 void wxWindow::OnKeyDown( wxKeyEvent 
&event 
) 
2205     event
.SetEventType( wxEVT_CHAR 
); 
2207     if (!GetEventHandler()->ProcessEvent( event 
)) 
2213 void wxWindow::SetFocus() 
2215     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2217     GtkWidget 
*connect_widget 
= GetConnectWidget(); 
2220         if (GTK_WIDGET_CAN_FOCUS(connect_widget
) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ ) 
2222             gtk_widget_grab_focus (connect_widget
); 
2224         else if (GTK_IS_CONTAINER(connect_widget
)) 
2226             gtk_container_focus( GTK_CONTAINER(connect_widget
), GTK_DIR_TAB_FORWARD 
); 
2234 wxWindow 
*wxWindow::FindFocus() 
2236     return g_focusWindow
; 
2239 bool wxWindow::AcceptsFocus() const 
2241     return IsEnabled() && IsShown() && m_acceptsFocus
; 
2244 void wxWindow::AddChild( wxWindow 
*child 
) 
2246     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2247     wxCHECK_RET( (child 
!= NULL
), "invalid child" ); 
2249     m_children
.Append( child 
); 
2252 wxWindow 
*wxWindow::ReParent( wxWindow 
*newParent 
) 
2254     wxCHECK_MSG( (m_widget 
!= NULL
), (wxWindow
*) NULL
, "invalid window" ); 
2256     wxWindow 
*oldParent 
= GetParent(); 
2258     if (oldParent
) oldParent
->RemoveChild( this ); 
2260     gtk_widget_unparent( m_widget 
); 
2264         newParent
->AddChild( this ); 
2265         (newParent
->m_insertCallback
)( newParent
, this ); 
2271 void wxWindow::RemoveChild( wxWindow 
*child 
) 
2273     m_children
.DeleteObject( child 
); 
2274     child
->m_parent 
= (wxWindow 
*) NULL
; 
2277 void wxWindow::SetReturnCode( int retCode 
) 
2279     m_retCode 
= retCode
; 
2282 int wxWindow::GetReturnCode() 
2287 void wxWindow::Raise() 
2289     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2291     if (m_widget
) gdk_window_raise( m_widget
->window 
); 
2294 void wxWindow::Lower() 
2296     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2298     if (m_widget
) gdk_window_lower( m_widget
->window 
); 
2301 wxEvtHandler 
*wxWindow::GetEventHandler() const 
2303     return m_eventHandler
; 
2306 void wxWindow::SetEventHandler( wxEvtHandler 
*handler 
) 
2308     m_eventHandler 
= handler
; 
2311 void wxWindow::PushEventHandler(wxEvtHandler 
*handler
) 
2313     handler
->SetNextHandler(GetEventHandler()); 
2314     SetEventHandler(handler
); 
2317 wxEvtHandler 
*wxWindow::PopEventHandler(bool deleteHandler
) 
2319     if (GetEventHandler()) 
2321         wxEvtHandler 
*handlerA 
= GetEventHandler(); 
2322         wxEvtHandler 
*handlerB 
= handlerA
->GetNextHandler(); 
2323         handlerA
->SetNextHandler((wxEvtHandler 
*) NULL
); 
2324         SetEventHandler(handlerB
); 
2328             return (wxEvtHandler
*) NULL
; 
2334         return (wxEvtHandler 
*) NULL
; 
2337 wxValidator 
*wxWindow::GetValidator() 
2339     return m_windowValidator
; 
2342 void wxWindow::SetValidator( const wxValidator
& validator 
) 
2344     if (m_windowValidator
) delete m_windowValidator
; 
2345     m_windowValidator 
= validator
.Clone(); 
2346     if (m_windowValidator
) m_windowValidator
->SetWindow(this); 
2349 void wxWindow::SetClientObject( wxClientData 
*data 
) 
2351     if (m_clientObject
) delete m_clientObject
; 
2352     m_clientObject 
= data
; 
2355 wxClientData 
*wxWindow::GetClientObject() 
2357     return m_clientObject
; 
2360 void wxWindow::SetClientData( void *data 
) 
2362     m_clientData 
= data
; 
2365 void *wxWindow::GetClientData() 
2367     return m_clientData
; 
2370 bool wxWindow::IsBeingDeleted() 
2375 void wxWindow::SetId( wxWindowID id 
) 
2380 wxWindowID 
wxWindow::GetId() const 
2385 void wxWindow::SetCursor( const wxCursor 
&cursor 
) 
2387     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2391         if (cursor 
== *m_cursor
) return; 
2396         *m_cursor 
= *wxSTANDARD_CURSOR
; 
2399     if ((m_widget
) && (m_widget
->window
)) 
2400          gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() ); 
2402     if ((m_wxwindow
) && (m_wxwindow
->window
)) 
2403          gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() ); 
2406 void wxWindow::WarpPointer( int WXUNUSED(x
), int WXUNUSED(y
) ) 
2411 void wxWindow::Refresh( bool eraseBackground
, const wxRect 
*rect 
) 
2413     wxCHECK_RET( (m_widget 
!= NULL
), "invalid window" ); 
2415     if (eraseBackground 
&& m_wxwindow 
&& m_wxwindow
->window
) 
2419             gdk_window_clear_area( m_wxwindow
->window
, 
2433             gtk_widget_draw( m_wxwindow
, (GdkRectangle
*) NULL 
); 
2435             gtk_widget_draw( m_widget
, (GdkRectangle
*) NULL 
); 
2439         GdkRectangle gdk_rect
; 
2440         gdk_rect
.x 
= rect
->x
; 
2441         gdk_rect
.y 
= rect
->y
; 
2442         gdk_rect
.width 
= rect
->width
; 
2443         gdk_rect
.height 
= rect
->height
; 
2446             gtk_widget_draw( m_wxwindow
, &gdk_rect 
); 
2448             gtk_widget_draw( m_widget
, &gdk_rect 
); 
2452 wxRegion 
wxWindow::GetUpdateRegion() const 
2454   return m_updateRegion
; 
2457 bool wxWindow::IsExposed( int x
, int y
) const 
2459     return (m_updateRegion
.Contains( x
, y 
) != wxOutRegion 
); 
2462 bool wxWindow::IsExposed( int x
, int y
, int w
, int h 
) const 
2464     return (m_updateRegion
.Contains( x
, y
, w
, h 
) != wxOutRegion 
); 
2467 bool wxWindow::IsExposed( const wxPoint
& pt 
) const 
2469     return (m_updateRegion
.Contains( pt
.x
, pt
.y 
) != wxOutRegion 
); 
2472 bool wxWindow::IsExposed( const wxRect
& rect 
) const 
2474     return (m_updateRegion
.Contains( rect
.x
, rect
.y
, rect
.width
, rect
.height 
) != wxOutRegion 
); 
2477 void wxWindow::Clear() 
2479     wxCHECK_RET( m_widget 
!= NULL
, "invalid window" ); 
2481     if (m_wxwindow 
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window 
); 
2485 void wxWindow::SetToolTip( const wxString 
&tip 
) 
2489         m_toolTip
->SetTip( tip 
); 
2493         SetToolTip( new wxToolTip( tip 
) ); 
2496     // setting empty tooltip text does not remove the tooltip any more for 
2497     // wxMSW compatibility - use SetToolTip((wxToolTip *)NULL) for this 
2500 void wxWindow::SetToolTip( wxToolTip 
*tip 
) 
2504         m_toolTip
->SetTip( (char*) NULL 
); 
2511         m_toolTip
->Apply( this ); 
2514 void wxWindow::ApplyToolTip( GtkTooltips 
*tips
, const char *tip 
) 
2516     gtk_tooltips_set_tip( tips
, GetConnectWidget(), tip
, (gchar
*) NULL 
); 
2518 #endif // wxUSE_TOOLTIPS 
2520 wxColour 
wxWindow::GetBackgroundColour() const 
2522     return m_backgroundColour
; 
2525 void wxWindow::SetBackgroundColour( const wxColour 
&colour 
) 
2527     wxCHECK_RET( m_widget 
!= NULL
, "invalid window" ); 
2529     if (m_backgroundColour 
== colour
) return; 
2531     m_backgroundColour 
= colour
; 
2532     if (!m_backgroundColour
.Ok()) return; 
2536         GdkWindow 
*window 
= m_wxwindow
->window
; 
2537         m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window 
) ); 
2538         gdk_window_set_background( window
, m_backgroundColour
.GetColor() ); 
2539         gdk_window_clear( window 
); 
2542     wxColour sysbg 
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE 
); 
2543     if (sysbg
.Red() == colour
.Red() && 
2544         sysbg
.Green() == colour
.Green() && 
2545         sysbg
.Blue() == colour
.Blue()) 
2547         m_backgroundColour 
= wxNullColour
; 
2549         m_backgroundColour 
= sysbg
; 
2557 wxColour 
wxWindow::GetForegroundColour() const 
2559     return m_foregroundColour
; 
2562 void wxWindow::SetForegroundColour( const wxColour 
&colour 
) 
2564     wxCHECK_RET( m_widget 
!= NULL
, "invalid window" ); 
2566     if (m_foregroundColour 
== colour
) return; 
2568     m_foregroundColour 
= colour
; 
2569     if (!m_foregroundColour
.Ok()) return; 
2571     wxColour sysbg 
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE 
); 
2572     if (sysbg
.Red() == colour
.Red() && 
2573         sysbg
.Green() == colour
.Green() && 
2574         sysbg
.Blue() == colour
.Blue()) 
2576         m_backgroundColour 
= wxNullColour
; 
2578         m_backgroundColour 
= sysbg
; 
2586 GtkStyle 
*wxWindow::GetWidgetStyle() 
2588     if (m_widgetStyle
) gtk_style_unref( m_widgetStyle 
); 
2592         gtk_widget_get_style( m_widget 
) ); 
2594     return m_widgetStyle
; 
2597 void wxWindow::SetWidgetStyle() 
2599     GtkStyle 
*style 
= GetWidgetStyle(); 
2601     gdk_font_unref( style
->font 
); 
2602     style
->font 
= gdk_font_ref( m_font
.GetInternalFont( 1.0 ) ); 
2604     if (m_foregroundColour
.Ok()) 
2606         m_foregroundColour
.CalcPixel( gdk_window_get_colormap( m_widget
->window 
) ); 
2607         style
->fg
[GTK_STATE_NORMAL
] = *m_foregroundColour
.GetColor(); 
2608         style
->fg
[GTK_STATE_PRELIGHT
] = *m_foregroundColour
.GetColor(); 
2609         style
->fg
[GTK_STATE_ACTIVE
] = *m_foregroundColour
.GetColor(); 
2612     if (m_backgroundColour
.Ok()) 
2614         m_backgroundColour
.CalcPixel( gdk_window_get_colormap( m_widget
->window 
) ); 
2615         style
->bg
[GTK_STATE_NORMAL
] = *m_backgroundColour
.GetColor(); 
2616         style
->base
[GTK_STATE_NORMAL
] = *m_backgroundColour
.GetColor(); 
2617         style
->bg
[GTK_STATE_PRELIGHT
] = *m_backgroundColour
.GetColor(); 
2618         style
->base
[GTK_STATE_PRELIGHT
] = *m_backgroundColour
.GetColor(); 
2619         style
->bg
[GTK_STATE_ACTIVE
] = *m_backgroundColour
.GetColor(); 
2620         style
->base
[GTK_STATE_ACTIVE
] = *m_backgroundColour
.GetColor(); 
2621         style
->bg
[GTK_STATE_INSENSITIVE
] = *m_backgroundColour
.GetColor(); 
2622         style
->base
[GTK_STATE_INSENSITIVE
] = *m_backgroundColour
.GetColor(); 
2626 void wxWindow::ApplyWidgetStyle() 
2630 bool wxWindow::Validate() 
2632     wxCHECK_MSG( m_widget 
!= NULL
, FALSE
, "invalid window" ); 
2634     wxNode 
*node 
= m_children
.First(); 
2637         wxWindow 
*child 
= (wxWindow 
*)node
->Data(); 
2638         if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this)) 
2642         node 
= node
->Next(); 
2647 bool wxWindow::TransferDataToWindow() 
2649     wxCHECK_MSG( m_widget 
!= NULL
, FALSE
, "invalid window" ); 
2651     wxNode 
*node 
= m_children
.First(); 
2654         wxWindow 
*child 
= (wxWindow 
*)node
->Data(); 
2655         if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ 
2656             !child
->GetValidator()->TransferToWindow() ) 
2658             wxMessageBox( _("Application Error"), _("Could not transfer data to window"), wxOK
|wxICON_EXCLAMATION 
); 
2661         node 
= node
->Next(); 
2666 bool wxWindow::TransferDataFromWindow() 
2668     wxCHECK_MSG( m_widget 
!= NULL
, FALSE
, "invalid window" ); 
2670     wxNode 
*node 
= m_children
.First(); 
2673         wxWindow 
*child 
= (wxWindow 
*)node
->Data(); 
2674         if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() ) 
2678         node 
= node
->Next(); 
2683 void wxWindow::SetAcceleratorTable( const wxAcceleratorTable
& accel 
) 
2685     m_acceleratorTable 
= accel
; 
2688 void wxWindow::OnInitDialog( wxInitDialogEvent 
&WXUNUSED(event
) ) 
2690     TransferDataToWindow(); 
2693 void wxWindow::InitDialog() 
2695     wxCHECK_RET( m_widget 
!= NULL
, "invalid window" ); 
2697     wxInitDialogEvent 
event(GetId()); 
2698     event
.SetEventObject( this ); 
2699     GetEventHandler()->ProcessEvent(event
); 
2702 static void SetInvokingWindow( wxMenu 
*menu
, wxWindow 
*win 
) 
2704     menu
->SetInvokingWindow( win 
); 
2705     wxNode 
*node 
= menu
->m_items
.First(); 
2708         wxMenuItem 
*menuitem 
= (wxMenuItem
*)node
->Data(); 
2709         if (menuitem
->IsSubMenu()) 
2711             SetInvokingWindow( menuitem
->GetSubMenu(), win 
); 
2713         node 
= node
->Next(); 
2717 static gint gs_pop_x 
= 0; 
2718 static gint gs_pop_y 
= 0; 
2720 static void pop_pos_callback( GtkMenu 
*menu
, gint 
*x
, gint 
*y
, wxWindow 
*win 
) 
2722     win
->ClientToScreen( &gs_pop_x
, &gs_pop_y 
); 
2727 bool wxWindow::PopupMenu( wxMenu 
*menu
, int x
, int y 
) 
2729     wxCHECK_MSG( m_widget 
!= NULL
, FALSE
, "invalid window" ); 
2731     wxCHECK_MSG( menu 
!= NULL
, FALSE
, "invalid popup-menu" ); 
2733     SetInvokingWindow( menu
, this ); 
2739                   GTK_MENU(menu
->m_menu
), 
2740                   (GtkWidget 
*) NULL
,          // parent menu shell 
2741                   (GtkWidget 
*) NULL
,          // parent menu item 
2742                   (GtkMenuPositionFunc
) pop_pos_callback
, 
2743                   (gpointer
) this,             // client data 
2744                   0,                           // button used to activate it 
2745                   0 //gs_timeLastClick         // the time of activation 
2750 #if wxUSE_DRAG_AND_DROP 
2752 void wxWindow::SetDropTarget( wxDropTarget 
*dropTarget 
) 
2754     wxCHECK_RET( m_widget 
!= NULL
, "invalid window" ); 
2756     GtkWidget 
*dnd_widget 
= GetConnectWidget(); 
2758     if (m_dropTarget
) m_dropTarget
->UnregisterWidget( dnd_widget 
); 
2760     if (m_dropTarget
) delete m_dropTarget
; 
2761     m_dropTarget 
= dropTarget
; 
2763     if (m_dropTarget
) m_dropTarget
->RegisterWidget( dnd_widget 
); 
2766 wxDropTarget 
*wxWindow::GetDropTarget() const 
2768     return m_dropTarget
; 
2773 GtkWidget
* wxWindow::GetConnectWidget() 
2775     GtkWidget 
*connect_widget 
= m_widget
; 
2776     if (m_wxwindow
) connect_widget 
= m_wxwindow
; 
2778     return connect_widget
; 
2781 bool wxWindow::IsOwnGtkWindow( GdkWindow 
*window 
) 
2783     if (m_wxwindow
) return (window 
== m_wxwindow
->window
); 
2784     return (window 
== m_widget
->window
); 
2787 void wxWindow::SetFont( const wxFont 
&font 
) 
2789     wxCHECK_RET( m_widget 
!= NULL
, "invalid window" ); 
2791     if (((wxFont
*)&font
)->Ok()) 
2794         m_font 
= *wxSWISS_FONT
; 
2796     wxColour sysbg 
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE 
); 
2797     if (sysbg
.Red() == m_backgroundColour
.Red() && 
2798         sysbg
.Green() == m_backgroundColour
.Green() && 
2799         sysbg
.Blue() == m_backgroundColour
.Blue()) 
2801         m_backgroundColour 
= wxNullColour
; 
2803         m_backgroundColour 
= sysbg
; 
2811 void wxWindow::SetWindowStyleFlag( long flag 
) 
2813     m_windowStyle 
= flag
; 
2816 long wxWindow::GetWindowStyleFlag() const 
2818     return m_windowStyle
; 
2821 void wxWindow::CaptureMouse() 
2823     wxCHECK_RET( m_widget 
!= NULL
, "invalid window" ); 
2825     wxCHECK_RET( g_capturing 
== FALSE
, "CaptureMouse called twice" ); 
2827     GtkWidget 
*connect_widget 
= GetConnectWidget(); 
2828     gtk_grab_add( connect_widget 
); 
2829     gdk_pointer_grab( connect_widget
->window
, FALSE
, 
2831                          (GDK_BUTTON_PRESS_MASK 
| 
2832                           GDK_BUTTON_RELEASE_MASK 
| 
2833                           GDK_POINTER_MOTION_MASK
), 
2840 void wxWindow::ReleaseMouse() 
2842     wxCHECK_RET( m_widget 
!= NULL
, "invalid window" ); 
2844     wxCHECK_RET( g_capturing 
== TRUE
, "ReleaseMouse called twice" ); 
2846     GtkWidget 
*connect_widget 
= GetConnectWidget(); 
2847     gtk_grab_remove( connect_widget 
); 
2848     gdk_pointer_ungrab ( GDK_CURRENT_TIME 
); 
2849     g_capturing 
= FALSE
; 
2852 void wxWindow::SetTitle( const wxString 
&WXUNUSED(title
) ) 
2856 wxString 
wxWindow::GetTitle() const 
2858     return (wxString
&)m_windowName
; 
2861 wxString 
wxWindow::GetLabel() const 
2866 void wxWindow::SetName( const wxString 
&name 
) 
2868     m_windowName 
= name
; 
2871 wxString 
wxWindow::GetName() const 
2873     return (wxString
&)m_windowName
; 
2876 bool wxWindow::IsShown() const 
2881 bool wxWindow::IsRetained() 
2886 wxWindow 
*wxWindow::FindWindow( long id 
) 
2888     if (id 
== m_windowId
) return this; 
2889     wxNode 
*node 
= m_children
.First(); 
2892         wxWindow 
*child 
= (wxWindow
*)node
->Data(); 
2893         wxWindow 
*res 
= child
->FindWindow( id 
); 
2894         if (res
) return res
; 
2895         node 
= node
->Next(); 
2897     return (wxWindow 
*) NULL
; 
2900 wxWindow 
*wxWindow::FindWindow( const wxString
& name 
) 
2902     if (name 
== m_windowName
) return this; 
2903     wxNode 
*node 
= m_children
.First(); 
2906         wxWindow 
*child 
= (wxWindow
*)node
->Data(); 
2907         wxWindow 
*res 
= child
->FindWindow( name 
); 
2908         if (res
) return res
; 
2909         node 
= node
->Next(); 
2911     return (wxWindow 
*) NULL
; 
2914 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
, 
2915       int range
, bool refresh 
) 
2917     wxCHECK_RET( m_widget 
!= NULL
, "invalid window" ); 
2919     wxCHECK_RET( m_wxwindow 
!= NULL
, "window needs client area for scrolling" ); 
2921     m_hasScrolling 
= TRUE
; 
2923     if (orient 
== wxHORIZONTAL
) 
2925         float fpos 
= (float)pos
; 
2926         float frange 
= (float)range
; 
2927         float fthumb 
= (float)thumbVisible
; 
2928         if (fpos 
> frange
-fthumb
) fpos 
= frange
-fthumb
; 
2929         if (fpos 
< 0.0) fpos 
= 0.0; 
2931         if ((fabs(frange
-m_hAdjust
->upper
) < 0.2) && 
2932             (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2)) 
2934             SetScrollPos( orient
, pos
, refresh 
); 
2938         m_oldHorizontalPos 
= fpos
; 
2940         m_hAdjust
->lower 
= 0.0; 
2941         m_hAdjust
->upper 
= frange
; 
2942         m_hAdjust
->value 
= fpos
; 
2943         m_hAdjust
->step_increment 
= 1.0; 
2944         m_hAdjust
->page_increment 
= (float)(wxMax(fthumb
,0)); 
2945         m_hAdjust
->page_size 
= fthumb
; 
2949         float fpos 
= (float)pos
; 
2950         float frange 
= (float)range
; 
2951         float fthumb 
= (float)thumbVisible
; 
2952         if (fpos 
> frange
-fthumb
) fpos 
= frange
-fthumb
; 
2953         if (fpos 
< 0.0) fpos 
= 0.0; 
2955         if ((fabs(frange
-m_vAdjust
->upper
) < 0.2) && 
2956             (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2)) 
2958             SetScrollPos( orient
, pos
, refresh 
); 
2962         m_oldVerticalPos 
= fpos
; 
2964         m_vAdjust
->lower 
= 0.0; 
2965         m_vAdjust
->upper 
= frange
; 
2966         m_vAdjust
->value 
= fpos
; 
2967         m_vAdjust
->step_increment 
= 1.0; 
2968         m_vAdjust
->page_increment 
= (float)(wxMax(fthumb
,0)); 
2969         m_vAdjust
->page_size 
= fthumb
; 
2972     if (m_wxwindow
->window
) 
2974         if (orient 
== wxHORIZONTAL
) 
2975             gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" ); 
2977             gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" ); 
2979         gtk_widget_set_usize( m_widget
, m_width
, m_height 
); 
2983 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) ) 
2985     wxCHECK_RET( m_widget 
!= NULL
, "invalid window" ); 
2987     wxCHECK_RET( m_wxwindow 
!= NULL
, "window needs client area for scrolling" ); 
2989     if (orient 
== wxHORIZONTAL
) 
2991         float fpos 
= (float)pos
; 
2992         if (fpos 
> m_hAdjust
->upper 
- m_hAdjust
->page_size
) fpos 
= m_hAdjust
->upper 
- m_hAdjust
->page_size
; 
2993         if (fpos 
< 0.0) fpos 
= 0.0; 
2994         m_oldHorizontalPos 
= fpos
; 
2996         if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return; 
2997         m_hAdjust
->value 
= fpos
; 
3001         float fpos 
= (float)pos
; 
3002         if (fpos 
> m_vAdjust
->upper 
- m_vAdjust
->page_size
) fpos 
= m_vAdjust
->upper 
- m_vAdjust
->page_size
; 
3003         if (fpos 
< 0.0) fpos 
= 0.0; 
3004         m_oldVerticalPos 
= fpos
; 
3006         if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return; 
3007         m_vAdjust
->value 
= fpos
; 
3012         if (m_wxwindow
->window
) 
3014             if (orient 
== wxHORIZONTAL
) 
3015                 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" ); 
3017                 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" ); 
3022 int wxWindow::GetScrollThumb( int orient 
) const 
3024     wxCHECK_MSG( m_widget 
!= NULL
, 0, "invalid window" ); 
3026     wxCHECK_MSG( m_wxwindow 
!= NULL
, 0, "window needs client area for scrolling" ); 
3028     if (orient 
== wxHORIZONTAL
) 
3029         return (int)(m_hAdjust
->page_size
+0.5); 
3031         return (int)(m_vAdjust
->page_size
+0.5); 
3034 int wxWindow::GetScrollPos( int orient 
) const 
3036     wxCHECK_MSG( m_widget 
!= NULL
, 0, "invalid window" ); 
3038     wxCHECK_MSG( m_wxwindow 
!= NULL
, 0, "window needs client area for scrolling" ); 
3040     if (orient 
== wxHORIZONTAL
) 
3041         return (int)(m_hAdjust
->value
+0.5); 
3043         return (int)(m_vAdjust
->value
+0.5); 
3046 int wxWindow::GetScrollRange( int orient 
) const 
3048     wxCHECK_MSG( m_widget 
!= NULL
, 0, "invalid window" ); 
3050     wxCHECK_MSG( m_wxwindow 
!= NULL
, 0, "window needs client area for scrolling" ); 
3052     if (orient 
== wxHORIZONTAL
) 
3053         return (int)(m_hAdjust
->upper
+0.5); 
3055         return (int)(m_vAdjust
->upper
+0.5); 
3058 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) ) 
3060     wxCHECK_RET( m_widget 
!= NULL
, "invalid window" ); 
3062     wxCHECK_RET( m_wxwindow 
!= NULL
, "window needs client area for scrolling" ); 
3066     GetClientSize( &cw
, &ch 
); 
3068     int w 
= cw 
- abs(dx
); 
3069     int h 
= ch 
- abs(dy
); 
3070     if ((h 
< 0) || (w 
< 0)) 
3077     if (dx 
< 0) s_x 
= -dx
; 
3078     if (dy 
< 0) s_y 
= -dy
; 
3081     if (dx 
> 0) d_x 
= dx
; 
3082     if (dy 
> 0) d_y 
= dy
; 
3086         m_scrollGC 
= gdk_gc_new( m_wxwindow
->window 
); 
3087         gdk_gc_set_exposures( m_scrollGC
, TRUE 
); 
3090     gdk_window_copy_area( m_wxwindow
->window
, m_scrollGC
, d_x
, d_y
, 
3091         m_wxwindow
->window
, s_x
, s_y
, w
, h 
); 
3094     if (dx 
< 0) rect
.x 
= cw
+dx
; else rect
.x 
= 0; 
3095     if (dy 
< 0) rect
.y 
= ch
+dy
; else rect
.y 
= 0; 
3096     if (dy 
!= 0) rect
.width 
= cw
; else rect
.width 
= abs(dx
); 
3097     if (dx 
!= 0) rect
.height 
= ch
; else rect
.height 
= abs(dy
); 
3099     Refresh( TRUE
, &rect 
); 
3102 //------------------------------------------------------------------------------------- 
3104 //------------------------------------------------------------------------------------- 
3106 wxLayoutConstraints 
*wxWindow::GetConstraints() const 
3108   return m_constraints
; 
3111 void wxWindow::SetConstraints( wxLayoutConstraints 
*constraints 
) 
3115     UnsetConstraints(m_constraints
); 
3116     delete m_constraints
; 
3118   m_constraints 
= constraints
; 
3121     // Make sure other windows know they're part of a 'meaningful relationship' 
3122     if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this)) 
3123       m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
3124     if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this)) 
3125       m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
3126     if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this)) 
3127       m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
3128     if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this)) 
3129       m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
3130     if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this)) 
3131       m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
3132     if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this)) 
3133       m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
3134     if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this)) 
3135       m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
3136     if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this)) 
3137       m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow 
*)this); 
3143 void wxWindow::SetAutoLayout( bool autoLayout 
) 
3145   m_autoLayout 
= autoLayout
; 
3148 bool wxWindow::GetAutoLayout() const 
3150   return m_autoLayout
; 
3153 wxSizer 
*wxWindow::GetSizer() const 
3155   return m_windowSizer
; 
3158 void wxWindow::SetSizerParent( wxWindow 
*win 
) 
3160   m_sizerParent 
= win
; 
3163 wxWindow 
*wxWindow::GetSizerParent() const 
3165   return m_sizerParent
; 
3168 // This removes any dangling pointers to this window 
3169 // in other windows' constraintsInvolvedIn lists. 
3170 void wxWindow::UnsetConstraints(wxLayoutConstraints 
*c
) 
3174     if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this)) 
3175       c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
3176     if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this)) 
3177       c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
3178     if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this)) 
3179       c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
3180     if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this)) 
3181       c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
3182     if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this)) 
3183       c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
3184     if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this)) 
3185       c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
3186     if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this)) 
3187       c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
3188     if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this)) 
3189       c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow 
*)this); 
3193 // Back-pointer to other windows we're involved with, so if we delete 
3194 // this window, we must delete any constraints we're involved with. 
3195 void wxWindow::AddConstraintReference(wxWindow 
*otherWin
) 
3197   if (!m_constraintsInvolvedIn
) 
3198     m_constraintsInvolvedIn 
= new wxList
; 
3199   if (!m_constraintsInvolvedIn
->Member(otherWin
)) 
3200     m_constraintsInvolvedIn
->Append(otherWin
); 
3203 // REMOVE back-pointer to other windows we're involved with. 
3204 void wxWindow::RemoveConstraintReference(wxWindow 
*otherWin
) 
3206   if (m_constraintsInvolvedIn
) 
3207     m_constraintsInvolvedIn
->DeleteObject(otherWin
); 
3210 // Reset any constraints that mention this window 
3211 void wxWindow::DeleteRelatedConstraints() 
3213   if (m_constraintsInvolvedIn
) 
3215     wxNode 
*node 
= m_constraintsInvolvedIn
->First(); 
3218       wxWindow 
*win 
= (wxWindow 
*)node
->Data(); 
3219       wxNode 
*next 
= node
->Next(); 
3220       wxLayoutConstraints 
*constr 
= win
->GetConstraints(); 
3222       // Reset any constraints involving this window 
3225         constr
->left
.ResetIfWin((wxWindow 
*)this); 
3226         constr
->top
.ResetIfWin((wxWindow 
*)this); 
3227         constr
->right
.ResetIfWin((wxWindow 
*)this); 
3228         constr
->bottom
.ResetIfWin((wxWindow 
*)this); 
3229         constr
->width
.ResetIfWin((wxWindow 
*)this); 
3230         constr
->height
.ResetIfWin((wxWindow 
*)this); 
3231         constr
->centreX
.ResetIfWin((wxWindow 
*)this); 
3232         constr
->centreY
.ResetIfWin((wxWindow 
*)this); 
3237     delete m_constraintsInvolvedIn
; 
3238     m_constraintsInvolvedIn 
= (wxList 
*) NULL
; 
3242 void wxWindow::SetSizer(wxSizer 
*sizer
) 
3244   m_windowSizer 
= sizer
; 
3246     sizer
->SetSizerParent((wxWindow 
*)this); 
3253 bool wxWindow::Layout() 
3255   if (GetConstraints()) 
3258     GetClientSize(&w
, &h
); 
3259     GetConstraints()->width
.SetValue(w
); 
3260     GetConstraints()->height
.SetValue(h
); 
3263   // If top level (one sizer), evaluate the sizer's constraints. 
3267     GetSizer()->ResetConstraints();   // Mark all constraints as unevaluated 
3268     GetSizer()->LayoutPhase1(&noChanges
); 
3269     GetSizer()->LayoutPhase2(&noChanges
); 
3270     GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes 
3275     // Otherwise, evaluate child constraints 
3276     ResetConstraints();   // Mark all constraints as unevaluated 
3277     DoPhase(1);           // Just one phase need if no sizers involved 
3279     SetConstraintSizes(); // Recursively set the real window sizes 
3285 // Do a phase of evaluating constraints: 
3286 // the default behaviour. wxSizers may do a similar 
3287 // thing, but also impose their own 'constraints' 
3288 // and order the evaluation differently. 
3289 bool wxWindow::LayoutPhase1(int *noChanges
) 
3291   wxLayoutConstraints 
*constr 
= GetConstraints(); 
3294     return constr
->SatisfyConstraints((wxWindow 
*)this, noChanges
); 
3300 bool wxWindow::LayoutPhase2(int *noChanges
) 
3310 // Do a phase of evaluating child constraints 
3311 bool wxWindow::DoPhase(int phase
) 
3313   int noIterations 
= 0; 
3314   int maxIterations 
= 500; 
3318   while ((noChanges 
> 0) && (noIterations 
< maxIterations
)) 
3322     wxNode 
*node 
= m_children
.First(); 
3325       wxWindow 
*child 
= (wxWindow 
*)node
->Data(); 
3326       if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
))) 
3328         wxLayoutConstraints 
*constr 
= child
->GetConstraints(); 
3331           if (succeeded
.Member(child
)) 
3336             int tempNoChanges 
= 0; 
3337             bool success 
= ( (phase 
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ; 
3338             noChanges 
+= tempNoChanges
; 
3341               succeeded
.Append(child
); 
3346       node 
= node
->Next(); 
3353 void wxWindow::ResetConstraints() 
3355   wxLayoutConstraints 
*constr 
= GetConstraints(); 
3358     constr
->left
.SetDone(FALSE
); 
3359     constr
->top
.SetDone(FALSE
); 
3360     constr
->right
.SetDone(FALSE
); 
3361     constr
->bottom
.SetDone(FALSE
); 
3362     constr
->width
.SetDone(FALSE
); 
3363     constr
->height
.SetDone(FALSE
); 
3364     constr
->centreX
.SetDone(FALSE
); 
3365     constr
->centreY
.SetDone(FALSE
); 
3367   wxNode 
*node 
= m_children
.First(); 
3370     wxWindow 
*win 
= (wxWindow 
*)node
->Data(); 
3371     if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
))) 
3372       win
->ResetConstraints(); 
3373     node 
= node
->Next(); 
3377 // Need to distinguish between setting the 'fake' size for 
3378 // windows and sizers, and setting the real values. 
3379 void wxWindow::SetConstraintSizes(bool recurse
) 
3381   wxLayoutConstraints 
*constr 
= GetConstraints(); 
3382   if (constr 
&& constr
->left
.GetDone() && constr
->right
.GetDone() && 
3383                 constr
->width
.GetDone() && constr
->height
.GetDone()) 
3385     int x 
= constr
->left
.GetValue(); 
3386     int y 
= constr
->top
.GetValue(); 
3387     int w 
= constr
->width
.GetValue(); 
3388     int h 
= constr
->height
.GetValue(); 
3390     // If we don't want to resize this window, just move it... 
3391     if ((constr
->width
.GetRelationship() != wxAsIs
) || 
3392         (constr
->height
.GetRelationship() != wxAsIs
)) 
3394       // Calls Layout() recursively. AAAGH. How can we stop that. 
3395       // Simply take Layout() out of non-top level OnSizes. 
3396       SizerSetSize(x
, y
, w
, h
); 
3405     char *windowClass 
= this->GetClassInfo()->GetClassName(); 
3408   if (GetName() == "") 
3409     winName 
= "unnamed"; 
3411     winName 
= GetName(); 
3412     wxLogDebug( "Constraint(s) not satisfied for window of type %s, name %s:\n", 
3413                 (const char *)windowClass
, 
3414                 (const char *)winName
); 
3415     if (!constr
->left
.GetDone()) wxLogDebug( "  unsatisfied 'left' constraint.\n" ); 
3416     if (!constr
->right
.GetDone()) wxLogDebug( "  unsatisfied 'right' constraint.\n" ); 
3417     if (!constr
->width
.GetDone()) wxLogDebug( "  unsatisfied 'width' constraint.\n" ); 
3418     if (!constr
->height
.GetDone())  wxLogDebug( "  unsatisfied 'height' constraint.\n" ); 
3419     wxLogDebug( "Please check constraints: try adding AsIs() constraints.\n" ); 
3424     wxNode 
*node 
= m_children
.First(); 
3427       wxWindow 
*win 
= (wxWindow 
*)node
->Data(); 
3428       if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
))) 
3429         win
->SetConstraintSizes(); 
3430       node 
= node
->Next(); 
3435 // This assumes that all sizers are 'on' the same 
3436 // window, i.e. the parent of this window. 
3437 void wxWindow::TransformSizerToActual(int *x
, int *y
) const 
3439   if (!m_sizerParent 
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) || 
3440          m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) ) 
3444   m_sizerParent
->GetPosition(&xp
, &yp
); 
3445   m_sizerParent
->TransformSizerToActual(&xp
, &yp
); 
3450 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
) 
3454   TransformSizerToActual(&xx
, &yy
); 
3455   SetSize(xx
, yy
, w
, h
); 
3458 void wxWindow::SizerMove(int x
, int y
) 
3462   TransformSizerToActual(&xx
, &yy
); 
3466 // Only set the size/position of the constraint (if any) 
3467 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
) 
3469   wxLayoutConstraints 
*constr 
= GetConstraints(); 
3474       constr
->left
.SetValue(x
); 
3475       constr
->left
.SetDone(TRUE
); 
3479       constr
->top
.SetValue(y
); 
3480       constr
->top
.SetDone(TRUE
); 
3484       constr
->width
.SetValue(w
); 
3485       constr
->width
.SetDone(TRUE
); 
3489       constr
->height
.SetValue(h
); 
3490       constr
->height
.SetDone(TRUE
); 
3495 void wxWindow::MoveConstraint(int x
, int y
) 
3497   wxLayoutConstraints 
*constr 
= GetConstraints(); 
3502       constr
->left
.SetValue(x
); 
3503       constr
->left
.SetDone(TRUE
); 
3507       constr
->top
.SetValue(y
); 
3508       constr
->top
.SetDone(TRUE
); 
3513 void wxWindow::GetSizeConstraint(int *w
, int *h
) const 
3515   wxLayoutConstraints 
*constr 
= GetConstraints(); 
3518     *w 
= constr
->width
.GetValue(); 
3519     *h 
= constr
->height
.GetValue(); 
3525 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const 
3527   wxLayoutConstraints 
*constr 
= GetConstraints(); 
3530     *w 
= constr
->width
.GetValue(); 
3531     *h 
= constr
->height
.GetValue(); 
3534     GetClientSize(w
, h
); 
3537 void wxWindow::GetPositionConstraint(int *x
, int *y
) const 
3539  wxLayoutConstraints 
*constr 
= GetConstraints(); 
3542     *x 
= constr
->left
.GetValue(); 
3543     *y 
= constr
->top
.GetValue();