1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
17 #include "wx/window.h"
21 #include "wx/layout.h"
23 #include "wx/dialog.h"
24 #include "wx/msgdlg.h"
25 #include "wx/dcclient.h"
28 #include "wx/notebook.h"
29 #include "gdk/gdkkeysyms.h"
31 #include "wx/gtk/win_gtk.h"
32 #include "gdk/gdkprivate.h"
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 extern wxList wxPendingDelete
;
39 extern wxList wxTopLevelWindows
;
40 extern bool g_blockEventsOnDrag
;
42 //-----------------------------------------------------------------------------
43 // GTK callbacks for wxWindows event system
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
47 // expose (of m_wxwindow, not of m_widget)
49 void gtk_window_expose_callback( GtkWidget
*WXUNUSED(widget
), GdkEventExpose
*gdk_event
, wxWindow
*win
)
51 if (!win
->HasVMT()) return;
52 if (g_blockEventsOnDrag
) return;
55 printf( "OnExpose from " );
56 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
57 printf( win->GetClassInfo()->GetClassName() );
60 printf( "x: %d \n", gdk_event->area.x );
61 printf( "y: %d \n", gdk_event->area.y );
62 printf( "w: %d \n", gdk_event->area.width );
63 printf( "h: %d \n", gdk_event->area.height );
66 win
->m_updateRegion
.Union( gdk_event
->area
.x
,
68 gdk_event
->area
.width
,
69 gdk_event
->area
.height
);
71 if (gdk_event
->count
> 0) return;
73 wxPaintEvent
event( win
->GetId() );
74 event
.SetEventObject( win
);
75 win
->ProcessEvent( event
);
77 win
->m_updateRegion
.Clear();
80 //-----------------------------------------------------------------------------
81 // draw (of m_wxwindow, not of m_widget)
83 void gtk_window_draw_callback( GtkWidget
*WXUNUSED(widget
), GdkRectangle
*rect
, wxWindow
*win
)
85 if (!win
->HasVMT()) return;
86 if (g_blockEventsOnDrag
) return;
89 printf( "OnDraw from " );
90 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
91 printf( win->GetClassInfo()->GetClassName() );
94 printf( "x: %d \n", rect->x );
95 printf( "y: %d \n", rect->y );
96 printf( "w: %d \n", rect->width );
97 printf( "h: %d \n", rect->height );
100 win
->m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
102 wxPaintEvent
event( win
->GetId() );
103 event
.SetEventObject( win
);
104 win
->ProcessEvent( event
);
106 win
->m_updateRegion
.Clear();
109 //-----------------------------------------------------------------------------
111 // I don't any longer intercept GTK's internal resize events (except frames)
114 void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
116 if (!win->HasVMT()) return;
117 if (g_blockEventsOnDrag) return;
121 if ((win->m_x == alloc->x) &&
122 (win->m_y == alloc->y) &&
123 (win->m_width == alloc->width) &&
124 (win->m_height == alloc->height))
129 printf( "OnResize from " );
130 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
131 printf( win->GetClassInfo()->GetClassName() );
134 printf( " Old: X: %d Y: %d ", win->m_x, win->m_y );
135 printf( " W: %d H: %d ", win->m_width, win->m_height );
138 printf( " New: X: %d Y: %d ", alloc->x, alloc->y );
139 printf( " W: %d H: %d ", alloc->width, alloc->height );
142 wxSizeEvent event( wxSize( alloc->width, alloc->height), win->GetId() );
143 event.SetEventObject( win );
144 win->ProcessEvent( event );
148 //-----------------------------------------------------------------------------
151 gint
gtk_window_key_press_callback( GtkWidget
*WXUNUSED(widget
), GdkEventKey
*gdk_event
, wxWindow
*win
)
153 if (!win
->HasVMT()) return FALSE
;
154 if (g_blockEventsOnDrag
) return FALSE
;
157 printf( "OnKeyPress from " );
158 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
159 printf( win->GetClassInfo()->GetClassName() );
164 switch (gdk_event
->keyval
)
166 case GDK_BackSpace
: key_code
= WXK_BACK
; break;
167 case GDK_Tab
: key_code
= WXK_TAB
; break;
168 case GDK_Linefeed
: key_code
= WXK_RETURN
; break;
169 case GDK_Clear
: key_code
= WXK_CLEAR
; break;
170 case GDK_Return
: key_code
= WXK_RETURN
; break;
171 case GDK_Pause
: key_code
= WXK_PAUSE
; break;
172 case GDK_Scroll_Lock
: key_code
= WXK_SCROLL
; break;
173 case GDK_Escape
: key_code
= WXK_ESCAPE
; break;
174 case GDK_Delete
: key_code
= WXK_DELETE
; break;
175 case GDK_Home
: key_code
= WXK_HOME
; break;
176 case GDK_Left
: key_code
= WXK_LEFT
; break;
177 case GDK_Up
: key_code
= WXK_UP
; break;
178 case GDK_Right
: key_code
= WXK_RIGHT
; break;
179 case GDK_Down
: key_code
= WXK_DOWN
; break;
180 case GDK_Prior
: key_code
= WXK_PRIOR
; break;
181 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
182 case GDK_Next
: key_code
= WXK_NEXT
; break;
183 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
184 case GDK_End
: key_code
= WXK_END
; break;
185 case GDK_Begin
: key_code
= WXK_HOME
; break;
186 case GDK_Select
: key_code
= WXK_SELECT
; break;
187 case GDK_Print
: key_code
= WXK_PRINT
; break;
188 case GDK_Execute
: key_code
= WXK_EXECUTE
; break;
189 case GDK_Insert
: key_code
= WXK_INSERT
; break;
190 case GDK_Num_Lock
: key_code
= WXK_NUMLOCK
; break;
191 case GDK_KP_Tab
: key_code
= WXK_TAB
; break;
192 case GDK_KP_Enter
: key_code
= WXK_RETURN
; break;
193 case GDK_KP_Home
: key_code
= WXK_HOME
; break;
194 case GDK_KP_Left
: key_code
= WXK_LEFT
; break;
195 case GDK_KP_Up
: key_code
= WXK_UP
; break;
196 case GDK_KP_Right
: key_code
= WXK_RIGHT
; break;
197 case GDK_KP_Down
: key_code
= WXK_DOWN
; break;
198 case GDK_KP_Prior
: key_code
= WXK_PRIOR
; break;
199 // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
200 case GDK_KP_Next
: key_code
= WXK_NEXT
; break;
201 // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
202 case GDK_KP_End
: key_code
= WXK_END
; break;
203 case GDK_KP_Begin
: key_code
= WXK_HOME
; break;
204 case GDK_KP_Insert
: key_code
= WXK_INSERT
; break;
205 case GDK_KP_Delete
: key_code
= WXK_DELETE
; break;
206 case GDK_KP_Multiply
: key_code
= WXK_MULTIPLY
; break;
207 case GDK_KP_Add
: key_code
= WXK_ADD
; break;
208 case GDK_KP_Separator
: key_code
= WXK_SEPARATOR
; break;
209 case GDK_KP_Subtract
: key_code
= WXK_SUBTRACT
; break;
210 case GDK_KP_Decimal
: key_code
= WXK_DECIMAL
; break;
211 case GDK_KP_Divide
: key_code
= WXK_DIVIDE
; break;
212 case GDK_KP_0
: key_code
= WXK_NUMPAD0
; break;
213 case GDK_KP_1
: key_code
= WXK_NUMPAD1
; break;
214 case GDK_KP_2
: key_code
= WXK_NUMPAD2
; break;
215 case GDK_KP_3
: key_code
= WXK_NUMPAD3
; break;
216 case GDK_KP_4
: key_code
= WXK_NUMPAD4
; break;
217 case GDK_KP_5
: key_code
= WXK_NUMPAD5
; break;
218 case GDK_KP_6
: key_code
= WXK_NUMPAD6
; break;
219 case GDK_KP_7
: key_code
= WXK_NUMPAD7
; break;
220 case GDK_KP_8
: key_code
= WXK_NUMPAD7
; break;
221 case GDK_KP_9
: key_code
= WXK_NUMPAD9
; break;
222 case GDK_F1
: key_code
= WXK_F1
; break;
223 case GDK_F2
: key_code
= WXK_F2
; break;
224 case GDK_F3
: key_code
= WXK_F3
; break;
225 case GDK_F4
: key_code
= WXK_F4
; break;
226 case GDK_F5
: key_code
= WXK_F5
; break;
227 case GDK_F6
: key_code
= WXK_F6
; break;
228 case GDK_F7
: key_code
= WXK_F7
; break;
229 case GDK_F8
: key_code
= WXK_F8
; break;
230 case GDK_F9
: key_code
= WXK_F9
; break;
231 case GDK_F10
: key_code
= WXK_F10
; break;
232 case GDK_F11
: key_code
= WXK_F11
; break;
233 case GDK_F12
: key_code
= WXK_F12
; break;
236 if ((gdk_event
->keyval
>= 0x20) && (gdk_event
->keyval
<= 0xFF))
237 key_code
= gdk_event
->keyval
;
241 if (!key_code
) return FALSE
;
243 wxKeyEvent
event( wxEVT_CHAR
);
244 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
245 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
246 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
247 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
248 event
.m_keyCode
= key_code
;
251 event
.SetEventObject( win
);
252 return win
->ProcessEvent( event
);
255 //-----------------------------------------------------------------------------
258 gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
260 if (widget
->window
!= gdk_event
->window
) return FALSE
;
261 if (g_blockEventsOnDrag
) return FALSE
;
265 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
) && !GTK_WIDGET_HAS_FOCUS (win
->m_wxwindow
) )
267 gtk_widget_grab_focus (win
->m_wxwindow
);
270 printf( "GrabFocus from " );
271 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
272 printf( win->GetClassInfo()->GetClassName() );
279 if (!win
->HasVMT()) return FALSE
;
282 printf( "OnButtonPress from " );
283 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
284 printf( win->GetClassInfo()->GetClassName() );
288 wxEventType event_type
= wxEVT_LEFT_DOWN
;
290 if (gdk_event
->button
== 1)
292 switch (gdk_event
->type
)
294 case GDK_BUTTON_PRESS
: event_type
= wxEVT_LEFT_DOWN
; break;
295 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_LEFT_DCLICK
; break;
299 else if (gdk_event
->button
== 2)
301 switch (gdk_event
->type
)
303 case GDK_BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DOWN
; break;
304 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DCLICK
; break;
308 else if (gdk_event
->button
== 3)
310 switch (gdk_event
->type
)
312 case GDK_BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DOWN
; break;
313 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DCLICK
; break;
318 wxMouseEvent
event( event_type
);
319 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
320 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
321 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
322 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
323 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
324 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
325 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
327 event
.m_x
= (long)gdk_event
->x
;
328 event
.m_y
= (long)gdk_event
->y
;
329 event
.SetEventObject( win
);
331 win
->ProcessEvent( event
);
336 //-----------------------------------------------------------------------------
339 gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
341 if (widget
->window
!= gdk_event
->window
) return TRUE
;
343 if (g_blockEventsOnDrag
) return FALSE
;
345 if (!win
->HasVMT()) return FALSE
;
348 printf( "OnButtonRelease from " );
349 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
350 printf( win->GetClassInfo()->GetClassName() );
354 wxEventType event_type
= wxEVT_NULL
;
356 switch (gdk_event
->button
)
358 case 1: event_type
= wxEVT_LEFT_UP
; break;
359 case 2: event_type
= wxEVT_MIDDLE_UP
; break;
360 case 3: event_type
= wxEVT_RIGHT_UP
; break;
363 wxMouseEvent
event( event_type
);
364 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
365 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
366 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
367 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
368 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
369 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
370 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
371 event
.m_x
= (long)gdk_event
->x
;
372 event
.m_y
= (long)gdk_event
->y
;
373 event
.SetEventObject( win
);
375 return win
->ProcessEvent( event
);
378 //-----------------------------------------------------------------------------
381 gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxWindow
*win
)
383 if (widget
->window
!= gdk_event
->window
) return TRUE
;
385 if (g_blockEventsOnDrag
) return FALSE
;
387 if (!win
->HasVMT()) return FALSE
;
390 printf( "OnMotion from " );
391 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
392 printf( win->GetClassInfo()->GetClassName() );
396 wxMouseEvent
event( wxEVT_MOTION
);
397 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
398 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
399 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
400 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
401 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
402 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
403 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
405 event
.m_x
= (long)gdk_event
->x
;
406 event
.m_y
= (long)gdk_event
->y
;
407 event
.SetEventObject( win
);
409 win
->ProcessEvent( event
);
414 //-----------------------------------------------------------------------------
417 gint
gtk_window_focus_in_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
419 if (g_blockEventsOnDrag
) return FALSE
;
422 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
424 GTK_WIDGET_SET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
426 printf( "SetFocus flag from " );
427 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
428 printf( win->GetClassInfo()->GetClassName() );
434 if (!win
->HasVMT()) return FALSE
;
437 printf( "OnSetFocus from " );
438 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
439 printf( win->GetClassInfo()->GetClassName() );
441 printf( WXSTRINGCAST win->GetLabel() );
445 wxFocusEvent
event( wxEVT_SET_FOCUS
, win
->GetId() );
446 event
.SetEventObject( win
);
447 return win
->ProcessEvent( event
);
450 //-----------------------------------------------------------------------------
453 gint
gtk_window_focus_out_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
455 if (g_blockEventsOnDrag
) return FALSE
;
458 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
459 GTK_WIDGET_UNSET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
462 if (!win
->HasVMT()) return FALSE
;
465 printf( "OnKillFocus from " );
466 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
467 printf( win->GetClassInfo()->GetClassName() );
471 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
472 event
.SetEventObject( win
);
473 return win
->ProcessEvent( event
);
476 //-----------------------------------------------------------------------------
479 void gtk_window_vscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
481 if (g_blockEventsOnDrag
) return;
484 printf( "OnVScroll from " );
485 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
486 printf( win->GetClassInfo()->GetClassName() );
490 if (!win
->HasVMT()) return;
492 float diff
= win
->m_vAdjust
->value
- win
->m_oldVerticalPos
;
493 if (fabs(diff
) < 0.2) return;
496 int i = (int)(win->m_oldVerticalPos+0.5);
497 printf( "Old value: %d.\n", i );
498 i = (int)(win->m_vAdjust->value+0.5);
499 printf( "Sending new value: %d.\n", i );
502 wxEventType command
= wxEVT_NULL
;
504 float line_step
= win
->m_vAdjust
->step_increment
;
505 float page_step
= win
->m_vAdjust
->page_increment
;
507 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
508 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
509 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
510 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
511 else command
= wxEVT_SCROLL_THUMBTRACK
;
513 int value
= (int)(win
->m_vAdjust
->value
+0.5);
515 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
516 event
.SetEventObject( win
);
517 win
->ProcessEvent( event
);
520 //-----------------------------------------------------------------------------
523 void gtk_window_hscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
525 if (g_blockEventsOnDrag
) return;
528 printf( "OnHScroll from " );
529 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
530 printf( win->GetClassInfo()->GetClassName() );
534 if (!win
->HasVMT()) return;
536 float diff
= win
->m_hAdjust
->value
- win
->m_oldHorizontalPos
;
537 if (fabs(diff
) < 0.2) return;
540 int i = (int)(win->m_oldHorizontalPos+0.5);
541 printf( "Old value: %d.\n", i );
542 i = (int)(win->m_hAdjust->value+0.5);
543 printf( "Sending new value: %d.\n", i );
546 wxEventType command
= wxEVT_NULL
;
548 float line_step
= win
->m_hAdjust
->step_increment
;
549 float page_step
= win
->m_hAdjust
->page_increment
;
551 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
552 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
553 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
554 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
555 else command
= wxEVT_SCROLL_THUMBTRACK
;
557 int value
= (int)(win
->m_hAdjust
->value
+0.5);
559 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
560 event
.SetEventObject( win
);
561 win
->ProcessEvent( event
);
564 //-----------------------------------------------------------------------------
565 // vertical scroll change
567 void gtk_window_vscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
569 if (g_blockEventsOnDrag
) return;
572 printf( "OnVScroll change from " );
573 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
574 printf( win->GetClassInfo()->GetClassName() );
578 if (!win
->HasVMT()) return;
580 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
581 int value
= (int)(win
->m_vAdjust
->value
+0.5);
583 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
584 event
.SetEventObject( win
);
585 win
->ProcessEvent( event
);
588 //-----------------------------------------------------------------------------
589 // horizontal scroll change
591 void gtk_window_hscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
593 if (g_blockEventsOnDrag
) return;
596 printf( "OnHScroll change from " );
597 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
598 printf( win->GetClassInfo()->GetClassName() );
602 if (!win
->HasVMT()) return;
604 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
605 int value
= (int)(win
->m_hAdjust
->value
+0.5);
607 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
608 event
.SetEventObject( win
);
609 win
->ProcessEvent( event
);
612 //-----------------------------------------------------------------------------
615 void gtk_window_drop_callback( GtkWidget
*widget
, GdkEvent
*event
, wxWindow
*win
)
617 printf( "OnDrop.\n" );
619 if (win
->GetDropTarget())
623 gdk_window_get_pointer( widget
->window
, &x
, &y
, NULL
);
624 win
->GetDropTarget()->Drop( event
, x
, y
);
628 g_free (event->dropdataavailable.data);
629 g_free (event->dropdataavailable.data_type);
633 //-----------------------------------------------------------------------------
636 bool gtk_window_destroy_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
638 printf( "OnDestroy from " );
639 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
640 printf( win
->GetClassInfo()->GetClassName() );
642 printf( "Goodbye.\n" );
643 printf( " Robert Roebling.\n" );
648 //-----------------------------------------------------------------------------
651 bool gtk_window_enter_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
653 if (widget
->window
!= gdk_event
->window
) return TRUE
;
655 if (g_blockEventsOnDrag
) return FALSE
;
658 gdk_window_set_cursor( widget
->window
, win
->m_cursor
->GetCursor() );
660 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
661 event
.SetEventObject( win
);
662 return win
->ProcessEvent( event
);
665 //-----------------------------------------------------------------------------
668 bool gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
670 if (widget
->window
!= gdk_event
->window
) return TRUE
;
672 if (g_blockEventsOnDrag
) return FALSE
;
675 gdk_window_set_cursor( widget
->window
, wxSTANDARD_CURSOR
->GetCursor() );
677 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
678 event
.SetEventObject( win
);
679 return win
->ProcessEvent( event
);
682 //-----------------------------------------------------------------------------
683 // wxWindow implementation
684 //-----------------------------------------------------------------------------
686 IMPLEMENT_DYNAMIC_CLASS(wxWindow
,wxEvtHandler
)
688 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
689 // EVT_CHAR(wxWindow::OnChar)
690 EVT_SIZE(wxWindow::OnSize
)
691 // EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
692 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
693 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
694 // EVT_IDLE(wxWindow::OnIdle)
702 m_children
.DeleteContents( FALSE
);
708 m_eventHandler
= this;
709 m_windowValidator
= NULL
;
711 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
712 m_font
= *wxSWISS_FONT
;
714 m_windowName
= "noname";
715 m_constraints
= NULL
;
716 m_constraintsInvolvedIn
= NULL
;
717 m_windowSizer
= NULL
;
718 m_sizerParent
= NULL
;
719 m_autoLayout
= FALSE
;
723 m_hasScrolling
= FALSE
;
726 m_oldHorizontalPos
= 0.0;
727 m_oldVerticalPos
= 0.0;
730 m_drawingOffsetX
= 0;
731 m_drawingOffsetY
= 0;
732 m_pDropTarget
= NULL
;
735 wxWindow::wxWindow( wxWindow
*parent
, wxWindowID id
,
736 const wxPoint
&pos
, const wxSize
&size
,
737 long style
, const wxString
&name
)
739 Create( parent
, id
, pos
, size
, style
, name
);
742 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
743 const wxPoint
&pos
, const wxSize
&size
,
744 long style
, const wxString
&name
)
750 PreCreation( parent
, id
, pos
, size
, style
, name
);
752 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
753 m_hasScrolling
= TRUE
;
755 GtkScrolledWindow
*s_window
;
756 s_window
= GTK_SCROLLED_WINDOW(m_widget
);
758 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
759 scroll_class
->scrollbar_spacing
= 0;
761 gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
763 m_oldHorizontalPos
= 0.0;
764 m_oldVerticalPos
= 0.0;
766 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) );
767 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) );
769 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "value_changed",
770 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
771 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "value_changed",
772 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
774 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "changed",
775 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
776 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "changed",
777 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
779 GtkViewport
*viewport
;
780 viewport
= GTK_VIEWPORT(s_window
->viewport
);
782 if (m_windowStyle
& wxRAISED_BORDER
)
784 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
786 else if (m_windowStyle
& wxSUNKEN_BORDER
)
788 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
792 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
795 m_wxwindow
= gtk_myfixed_new();
797 if (m_windowStyle
& wxTAB_TRAVERSAL
== wxTAB_TRAVERSAL
)
798 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
800 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
802 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
804 // shut the viewport up
805 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
806 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
808 // I _really_ don't want scrollbars in the beginning
809 m_vAdjust
->lower
= 0.0;
810 m_vAdjust
->upper
= 1.0;
811 m_vAdjust
->value
= 0.0;
812 m_vAdjust
->step_increment
= 1.0;
813 m_vAdjust
->page_increment
= 1.0;
814 m_vAdjust
->page_size
= 5.0;
815 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
816 m_hAdjust
->lower
= 0.0;
817 m_hAdjust
->upper
= 1.0;
818 m_hAdjust
->value
= 0.0;
819 m_hAdjust
->step_increment
= 1.0;
820 m_hAdjust
->page_increment
= 1.0;
821 m_hAdjust
->page_size
= 5.0;
822 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
824 gtk_widget_show( m_wxwindow
);
833 wxWindow::~wxWindow(void)
837 if (m_pDropTarget
) delete m_pDropTarget
;
839 if (m_parent
) m_parent
->RemoveChild( this );
840 if (m_widget
) Show( FALSE
);
844 if (m_wxwindow
) gtk_widget_destroy( m_wxwindow
);
846 if (m_widget
) gtk_widget_destroy( m_widget
);
850 DeleteRelatedConstraints();
853 // This removes any dangling pointers to this window
854 // in other windows' constraintsInvolvedIn lists.
855 UnsetConstraints(m_constraints
);
856 delete m_constraints
;
857 m_constraints
= NULL
;
861 delete m_windowSizer
;
862 m_windowSizer
= NULL
;
864 // If this is a child of a sizer, remove self from parent
866 m_sizerParent
->RemoveChild((wxWindow
*)this);
868 // Just in case the window has been Closed, but
869 // we're then deleting immediately: don't leave
870 // dangling pointers.
871 wxPendingDelete
.DeleteObject(this);
873 // Just in case we've loaded a top-level window via
874 // wxWindow::LoadNativeDialog but we weren't a dialog
876 wxTopLevelWindows
.DeleteObject(this);
880 void wxWindow::PreCreation( wxWindow
*parent
, wxWindowID id
,
881 const wxPoint
&pos
, const wxSize
&size
,
882 long style
, const wxString
&name
)
884 if (m_needParent
&& (parent
== NULL
))
885 wxFatalError( "Need complete parent.", name
);
890 m_children
.DeleteContents( FALSE
);
894 if (m_width
== -1) m_width
= 20;
896 if (m_height
== -1) m_height
= 20;
898 m_eventHandler
= this;
899 m_windowValidator
= NULL
;
902 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
903 m_font
= *wxSWISS_FONT
;
904 m_backgroundColour
= wxWHITE
;
905 m_foregroundColour
= wxBLACK
;
906 m_windowStyle
= style
;
908 m_constraints
= NULL
;
909 m_constraintsInvolvedIn
= NULL
;
910 m_windowSizer
= NULL
;
911 m_sizerParent
= NULL
;
912 m_autoLayout
= FALSE
;
913 m_drawingOffsetX
= 0;
914 m_drawingOffsetY
= 0;
915 m_pDropTarget
= NULL
;
918 void wxWindow::PostCreation(void)
920 if (m_parent
) m_parent
->AddChild( this );
922 // GtkStyle *style = m_widget->style;
923 // style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
925 GtkWidget
*connect_widget
= m_widget
;
926 if (m_wxwindow
) connect_widget
= m_wxwindow
;
928 gtk_object_set_data (GTK_OBJECT (connect_widget
), "MyWxWindow", (gpointer
)this );
932 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
933 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
935 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
936 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
940 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
941 GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this );
944 gtk_signal_connect( GTK_OBJECT(connect_widget
), "key_press_event",
945 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
947 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_press_event",
948 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
950 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_release_event",
951 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
953 gtk_signal_connect( GTK_OBJECT(connect_widget
), "motion_notify_event",
954 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
956 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_in_event",
957 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
959 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_out_event",
960 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
962 gtk_signal_connect( GTK_OBJECT(connect_widget
), "drop_data_available_event",
963 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
965 // Only for cursor handling
967 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter_notify_event",
968 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
970 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave_notify_event",
971 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
975 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "enter_notify_event",
976 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
978 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "leave_notify_event",
979 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
983 // Does destroy ever get called ?
985 gtk_signal_connect( GTK_OBJECT(m_widget), "destroy_event",
986 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
990 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "destroy_event",
991 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
995 if (m_widget
&& m_parent
) gtk_widget_realize( m_widget
);
996 if (m_wxwindow
) gtk_widget_realize( m_wxwindow
);
998 SetCursor( wxSTANDARD_CURSOR
);
1003 bool wxWindow::HasVMT(void)
1008 bool wxWindow::Close( bool force
)
1010 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1011 event
.SetEventObject(this);
1012 event
.SetForce(force
);
1014 return GetEventHandler()->ProcessEvent(event
);
1017 bool wxWindow::Destroy(void)
1024 bool wxWindow::DestroyChildren(void)
1029 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
)
1032 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
)
1035 if (GetChildren()->Member(child
)) delete node
;
1042 void wxWindow::PrepareDC( wxDC
&WXUNUSED(dc
) )
1044 // are we to set fonts here ?
1047 void wxWindow::ImplementSetSize(void)
1049 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1052 void wxWindow::ImplementSetPosition(void)
1054 if ((m_parent
) && (m_parent
->m_wxwindow
))
1055 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1057 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1060 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1067 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1069 if (newX
== -1) newX
= m_x
;
1070 if (newY
== -1) newY
= m_y
;
1071 if (newW
== -1) newW
= m_width
;
1072 if (newH
== -1) newH
= m_height
;
1075 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1077 if (newW
== -1) newW
= 80;
1080 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1082 if (newH
== -1) newH
= 26;
1085 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1089 ImplementSetPosition();
1091 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1099 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1100 event
.SetEventObject( this );
1101 ProcessEvent( event
);
1104 void wxWindow::SetSize( int width
, int height
)
1106 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1109 void wxWindow::Move( int x
, int y
)
1111 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1114 void wxWindow::GetSize( int *width
, int *height
) const
1117 (*height
) = m_height
;
1120 void wxWindow::SetClientSize( int width
, int height
)
1124 SetSize( width
, height
);
1131 if (!m_hasScrolling
)
1134 do we have sunken dialogs ?
1136 GtkStyleClass *window_class = m_wxwindow->style->klass;
1138 dw += 2 * window_class->xthickness;
1139 dh += 2 * window_class->ythickness;
1144 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1145 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1147 GtkWidget
*viewport
= scroll_window
->viewport
;
1148 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1150 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1151 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1153 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1154 (m_windowStyle
& wxSUNKEN_BORDER
)
1157 dw
+= 2 * viewport_class
->xthickness
;
1158 dh
+= 2 * viewport_class
->ythickness
;
1161 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1163 dw
+= vscrollbar
->allocation
.width
;
1164 dw
+= scroll_class
->scrollbar_spacing
;
1167 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1169 dh
+= hscrollbar
->allocation
.height
;
1170 dw
+= scroll_class
->scrollbar_spacing
;
1174 SetSize( width
+dw
, height
+dh
);
1178 void wxWindow::GetClientSize( int *width
, int *height
) const
1182 if (width
) (*width
) = m_width
;
1183 if (height
) (*height
) = m_height
;
1190 if (!m_hasScrolling
)
1193 do we have sunken dialogs ?
1195 GtkStyleClass *window_class = m_wxwindow->style->klass;
1197 dw += 2 * window_class->xthickness;
1198 dh += 2 * window_class->ythickness;
1203 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1204 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1206 GtkWidget
*viewport
= scroll_window
->viewport
;
1207 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1209 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1210 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1212 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1213 (m_windowStyle
& wxSUNKEN_BORDER
)
1216 dw
+= 2 * viewport_class
->xthickness
;
1217 dh
+= 2 * viewport_class
->ythickness
;
1220 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1222 // dw += vscrollbar->allocation.width;
1223 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1224 dw
+= scroll_class
->scrollbar_spacing
;
1227 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1229 // dh += hscrollbar->allocation.height;
1231 dh
+= scroll_class
->scrollbar_spacing
;
1235 if (width
) (*width
) = m_width
- dw
;
1236 if (height
) (*height
) = m_height
- dh
;
1240 void wxWindow::GetPosition( int *x
, int *y
) const
1246 void wxWindow::ClientToScreen( int *x
, int *y
)
1248 // Does this look simple ?
1250 GdkWindow
*source
= NULL
;
1252 source
= m_wxwindow
->window
;
1254 source
= m_widget
->window
;
1258 gdk_window_get_origin( source
, &org_x
, &org_y
);
1262 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1264 org_x
+= m_widget
->allocation
.x
;
1265 org_y
+= m_widget
->allocation
.y
;
1273 void wxWindow::ScreenToClient( int *x
, int *y
)
1275 GdkWindow
*source
= NULL
;
1277 source
= m_wxwindow
->window
;
1279 source
= m_widget
->window
;
1283 gdk_window_get_origin( source
, &org_x
, &org_y
);
1287 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1289 org_x
+= m_widget
->allocation
.x
;
1290 org_y
+= m_widget
->allocation
.y
;
1298 void wxWindow::Centre( int direction
)
1302 GetPosition( &x
, &y
);
1303 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1305 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) x
= (gdk_screen_width () - m_width
) / 2;
1306 if (direction
& wxVERTICAL
== wxVERTICAL
) y
= (gdk_screen_height () - m_height
) / 2;
1307 gtk_widget_set_uposition( m_widget
, x
, y
);
1315 m_parent
->GetSize( &p_w
, &p_h
);
1316 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) x
= (p_w
- m_width
) / 2;
1317 if (direction
& wxVERTICAL
== wxVERTICAL
) y
= (p_h
- m_height
) / 2;
1318 gtk_widget_set_uposition( m_widget
, x
, y
);
1323 void wxWindow::Fit(void)
1327 wxNode
*node
= GetChildren()->First();
1330 wxWindow
*win
= (wxWindow
*)node
->Data();
1332 win
->GetPosition(&wx
, &wy
);
1333 win
->GetSize(&ww
, &wh
);
1334 if ( wx
+ ww
> maxX
)
1336 if ( wy
+ wh
> maxY
)
1339 node
= node
->Next();
1341 SetClientSize(maxX
+ 5, maxY
+ 5);
1344 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1346 //if (GetAutoLayout()) Layout();
1349 bool wxWindow::Show( bool show
)
1352 gtk_widget_show( m_widget
);
1354 gtk_widget_hide( m_widget
);
1359 void wxWindow::Enable( bool enable
)
1361 m_isEnabled
= enable
;
1362 gtk_widget_set_sensitive( m_widget
, enable
);
1363 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1366 void wxWindow::MakeModal( bool modal
)
1369 // Disable all other windows
1370 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1372 wxNode
*node
= wxTopLevelWindows
.First();
1375 wxWindow
*win
= (wxWindow
*)node
->Data();
1377 win
->Enable(!modal
);
1379 node
= node
->Next();
1384 void wxWindow::SetFocus(void)
1386 GtkWidget
*connect_widget
= m_widget
;
1387 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1390 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1392 gtk_widget_grab_focus (connect_widget
);
1397 bool wxWindow::OnClose(void)
1399 printf( "OnClose event.\n" );
1403 void wxWindow::AddChild( wxWindow
*child
)
1405 // Addchild is (often) called before the program
1406 // has left the parents constructor so that no
1407 // virtual tables work yet. The approach below
1408 // practically imitates virtual tables, i.e. it
1409 // implements a different AddChild() behaviour
1410 // for wxFrame, wxDialog, wxWindow and
1411 // wxMDIParentFrame.
1413 if (IsKindOf(CLASSINFO(wxMDIParentFrame
)))
1415 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1417 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1420 client
->AddChild( child
);
1426 if (IsKindOf(CLASSINFO(wxNotebook
)))
1428 wxNotebook
*tab
= (wxNotebook
*)this;
1429 tab
->AddChild( child
);
1433 m_children
.Append( child
);
1434 if (child
->IsKindOf(CLASSINFO(wxFrame
)) || child
->IsKindOf(CLASSINFO(wxDialog
)))
1436 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1437 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1442 gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
, child
->m_x
, child
->m_y
);
1444 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1447 wxList
*wxWindow::GetChildren(void)
1449 return (&m_children
);
1452 void wxWindow::RemoveChild( wxWindow
*child
)
1455 GetChildren()->DeleteObject( child
);
1456 child
->m_parent
= NULL
;
1459 void wxWindow::SetReturnCode( int retCode
)
1461 m_retCode
= retCode
;
1464 int wxWindow::GetReturnCode(void)
1469 wxWindow
*wxWindow::GetParent(void)
1474 wxEvtHandler
*wxWindow::GetEventHandler(void)
1476 return m_eventHandler
;
1479 void wxWindow::SetEventhandler( wxEvtHandler
*handler
)
1481 m_eventHandler
= handler
;
1484 wxValidator
*wxWindow::GetValidator(void)
1486 return m_windowValidator
;
1489 void wxWindow::SetValidator( wxValidator
*validator
)
1491 m_windowValidator
= validator
;
1494 bool wxWindow::IsBeingDeleted(void)
1499 void wxWindow::SetId( wxWindowID id
)
1504 wxWindowID
wxWindow::GetId(void)
1509 void wxWindow::SetCursor( const wxCursor
&cursor
)
1511 if (*m_cursor
== cursor
) return;
1512 (*m_cursor
) = cursor
;
1513 if (m_widget
->window
)
1514 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1515 if (m_wxwindow
&& m_wxwindow
->window
)
1516 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1519 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1521 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1524 gdk_window_clear_area( m_wxwindow
->window
,
1536 wxClientDC
dc(this);
1540 dc
.GetInternalDeviceOrigin( &x
, &y
);
1544 GetClientSize( &w
, &h
);
1546 GdkRectangle gdk_rect
;
1550 gdk_rect
.height
= h
;
1551 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1556 GdkRectangle gdk_rect
;
1557 gdk_rect
.x
= rect
->x
;
1558 gdk_rect
.y
= rect
->y
;
1559 gdk_rect
.width
= rect
->width
;
1560 gdk_rect
.height
= rect
->height
;
1562 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1564 gtk_widget_draw( m_widget
, &gdk_rect
);
1568 bool wxWindow::IsExposed( long x
, long y
)
1570 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1573 bool wxWindow::IsExposed( long x
, long y
, long width
, long height
)
1575 return (m_updateRegion
.Contains( x
, y
, width
, height
) != wxOutRegion
);
1578 void wxWindow::Clear(void)
1580 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1583 wxColour
wxWindow::GetBackgroundColour(void) const
1585 return m_backgroundColour
;
1588 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1590 m_backgroundColour
= colour
;
1593 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1594 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1595 gdk_window_clear( m_wxwindow
->window
);
1600 bool wxWindow::Validate(void)
1602 wxNode
*node
= GetChildren()->First();
1605 wxWindow
*child
= (wxWindow
*)node
->Data();
1606 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1608 node
= node
->Next();
1613 bool wxWindow::TransferDataToWindow(void)
1615 wxNode
*node
= GetChildren()->First();
1618 wxWindow
*child
= (wxWindow
*)node
->Data();
1619 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1620 !child
->GetValidator()->TransferToWindow() )
1622 wxMessageBox( "Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1625 node
= node
->Next();
1630 bool wxWindow::TransferDataFromWindow(void)
1632 wxNode
*node
= GetChildren()->First();
1635 wxWindow
*child
= (wxWindow
*)node
->Data();
1636 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1638 node
= node
->Next();
1643 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1645 TransferDataToWindow();
1648 void wxWindow::InitDialog(void)
1650 wxInitDialogEvent
event(GetId());
1651 event
.SetEventObject( this );
1652 GetEventHandler()->ProcessEvent(event
);
1655 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1657 GtkWidget
*connect_widget
= m_widget
;
1658 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1661 m_pDropTarget
->UnregisterWidget( connect_widget
);
1662 delete m_pDropTarget
;
1664 m_pDropTarget
= dropTarget
;
1667 m_pDropTarget
->RegisterWidget( connect_widget
);
1671 wxDropTarget
*wxWindow::GetDropTarget() const
1673 return m_pDropTarget
;
1676 void wxWindow::SetFont( const wxFont
&font
)
1681 copy old style values to new one
1682 set font in new style
1683 -> takes to many resources
1685 GtkStyle *style = gtk_style_new();
1690 wxFont
*wxWindow::GetFont(void)
1695 void wxWindow::SetWindowStyleFlag( long flag
)
1697 m_windowStyle
= flag
;
1700 long wxWindow::GetWindowStyleFlag(void) const
1702 return m_windowStyle
;
1705 void wxWindow::CaptureMouse(void)
1707 GtkWidget
*connect_widget
= m_widget
;
1708 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1709 gtk_grab_add( connect_widget
);
1710 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1712 (GDK_BUTTON_PRESS_MASK
|
1713 GDK_BUTTON_RELEASE_MASK
|
1714 GDK_POINTER_MOTION_MASK
),
1715 NULL
, NULL
, GDK_CURRENT_TIME
);
1718 void wxWindow::ReleaseMouse(void)
1720 GtkWidget
*connect_widget
= m_widget
;
1721 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1722 gtk_grab_remove( connect_widget
);
1723 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1726 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1730 wxString
wxWindow::GetTitle(void) const
1732 return (wxString
&)m_windowName
;
1735 wxString
wxWindow::GetLabel(void) const
1740 void wxWindow::SetName( const wxString
&name
)
1742 m_windowName
= name
;
1745 wxString
wxWindow::GetName(void) const
1747 return (wxString
&)m_windowName
;
1750 bool wxWindow::IsShown(void) const
1755 bool wxWindow::IsRetained(void)
1760 wxWindow
*wxWindow::FindWindow( long id
)
1762 if (id
== m_windowId
) return this;
1763 wxNode
*node
= m_children
.First();
1766 wxWindow
*child
= (wxWindow
*)node
->Data();
1767 wxWindow
*res
= child
->FindWindow( id
);
1768 if (res
) return res
;
1769 node
= node
->Next();
1774 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1776 if (name
== m_windowName
) return this;
1777 wxNode
*node
= m_children
.First();
1780 wxWindow
*child
= (wxWindow
*)node
->Data();
1781 wxWindow
*res
= child
->FindWindow( name
);
1782 if (res
) return res
;
1783 node
= node
->Next();
1788 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1789 int range
, bool WXUNUSED(refresh
) )
1791 if (!m_wxwindow
) return;
1793 if (orient
== wxHORIZONTAL
)
1795 float fpos
= (float)pos
;
1796 m_oldHorizontalPos
= fpos
;
1797 float frange
= (float)range
;
1798 float fthumb
= (float)thumbVisible
;
1800 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1801 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1802 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1805 m_hAdjust
->lower
= 0.0;
1806 m_hAdjust
->upper
= frange
;
1807 m_hAdjust
->value
= fpos
;
1808 m_hAdjust
->step_increment
= 1.0;
1809 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1810 m_hAdjust
->page_size
= fthumb
;
1814 float fpos
= (float)pos
;
1815 m_oldVerticalPos
= fpos
;
1816 float frange
= (float)range
;
1817 float fthumb
= (float)thumbVisible
;
1819 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1820 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1821 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1824 m_vAdjust
->lower
= 0.0;
1825 m_vAdjust
->upper
= frange
;
1826 m_vAdjust
->value
= fpos
;
1827 m_vAdjust
->step_increment
= 1.0;
1828 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1829 m_vAdjust
->page_size
= fthumb
;
1832 if (m_wxwindow
->window
)
1834 if (orient
== wxHORIZONTAL
)
1835 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
1837 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
1839 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1843 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
1845 if (!m_wxwindow
) return;
1847 if (orient
== wxHORIZONTAL
)
1849 float fpos
= (float)pos
;
1850 m_oldHorizontalPos
= fpos
;
1852 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
1853 m_hAdjust
->value
= fpos
;
1857 float fpos
= (float)pos
;
1858 m_oldVerticalPos
= fpos
;
1859 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
1860 m_vAdjust
->value
= fpos
;
1863 if (m_wxwindow
->window
)
1865 if (orient
== wxHORIZONTAL
)
1866 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
1868 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
1872 int wxWindow::GetScrollThumb( int orient
) const
1874 if (!m_wxwindow
) return 0;
1876 if (orient
== wxHORIZONTAL
)
1877 return (int)(m_hAdjust
->page_size
+0.5);
1879 return (int)(m_vAdjust
->page_size
+0.5);
1882 int wxWindow::GetScrollPos( int orient
) const
1884 if (!m_wxwindow
) return 0;
1886 if (orient
== wxHORIZONTAL
)
1887 return (int)(m_hAdjust
->value
+0.5);
1889 return (int)(m_vAdjust
->value
+0.5);
1892 int wxWindow::GetScrollRange( int orient
) const
1894 if (!m_wxwindow
) return 0;
1896 if (orient
== wxHORIZONTAL
)
1897 return (int)(m_hAdjust
->upper
+0.5);
1899 return (int)(m_vAdjust
->upper
+0.5);
1902 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
1904 if (!m_wxwindow
) return;
1906 m_drawingOffsetX
+= dx
;
1907 m_drawingOffsetY
+= dy
;
1909 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
1911 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow
), m_drawingOffsetX
, m_drawingOffsetY
);
1914 The code here is very nifty, but it doesn't work with
1915 overlapping windows...
1919 GetClientSize( &cw, &ch );
1921 int w = cw - abs(dx);
1922 int h = ch - abs(dy);
1923 if ((h < 0) || (w < 0))
1930 if (dx < 0) s_x = -dx;
1931 if (dy < 0) s_y = -dy;
1934 if (dx > 0) d_x = dx;
1935 if (dy > 0) d_y = dy;
1936 gdk_window_copy_area( m_wxwindow->window, m_wxwindow->style->fg_gc[0], d_x, d_y,
1937 m_wxwindow->window, s_x, s_y, w, h );
1940 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
1941 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
1942 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
1943 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
1945 Refresh( TRUE, &rect );
1949 void wxWindow::GetDrawingOffset( long *x
, long *y
)
1951 if (x
) *x
= m_drawingOffsetX
;
1952 if (y
) *y
= m_drawingOffsetY
;
1955 //-------------------------------------------------------------------------------------
1957 //-------------------------------------------------------------------------------------
1959 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
1961 return m_constraints
;
1964 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
1968 UnsetConstraints(m_constraints
);
1969 delete m_constraints
;
1971 m_constraints
= constraints
;
1974 // Make sure other windows know they're part of a 'meaningful relationship'
1975 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1976 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1977 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1978 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1979 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1980 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1981 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1982 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1983 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1984 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1985 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1986 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1987 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1988 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1989 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1990 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1996 void wxWindow::SetAutoLayout( bool autoLayout
)
1998 m_autoLayout
= autoLayout
;
2001 bool wxWindow::GetAutoLayout(void) const
2003 return m_autoLayout
;
2006 wxSizer
*wxWindow::GetSizer(void) const
2008 return m_windowSizer
;
2011 void wxWindow::SetSizerParent( wxWindow
*win
)
2013 m_sizerParent
= win
;
2016 wxWindow
*wxWindow::GetSizerParent(void) const
2018 return m_sizerParent
;
2021 // This removes any dangling pointers to this window
2022 // in other windows' constraintsInvolvedIn lists.
2023 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2027 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2028 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2029 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2030 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2031 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2032 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2033 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2034 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2035 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2036 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2037 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2038 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2039 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2040 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2041 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2042 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2046 // Back-pointer to other windows we're involved with, so if we delete
2047 // this window, we must delete any constraints we're involved with.
2048 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2050 if (!m_constraintsInvolvedIn
)
2051 m_constraintsInvolvedIn
= new wxList
;
2052 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2053 m_constraintsInvolvedIn
->Append(otherWin
);
2056 // REMOVE back-pointer to other windows we're involved with.
2057 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2059 if (m_constraintsInvolvedIn
)
2060 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2063 // Reset any constraints that mention this window
2064 void wxWindow::DeleteRelatedConstraints(void)
2066 if (m_constraintsInvolvedIn
)
2068 wxNode
*node
= m_constraintsInvolvedIn
->First();
2071 wxWindow
*win
= (wxWindow
*)node
->Data();
2072 wxNode
*next
= node
->Next();
2073 wxLayoutConstraints
*constr
= win
->GetConstraints();
2075 // Reset any constraints involving this window
2078 constr
->left
.ResetIfWin((wxWindow
*)this);
2079 constr
->top
.ResetIfWin((wxWindow
*)this);
2080 constr
->right
.ResetIfWin((wxWindow
*)this);
2081 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2082 constr
->width
.ResetIfWin((wxWindow
*)this);
2083 constr
->height
.ResetIfWin((wxWindow
*)this);
2084 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2085 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2090 delete m_constraintsInvolvedIn
;
2091 m_constraintsInvolvedIn
= NULL
;
2095 void wxWindow::SetSizer(wxSizer
*sizer
)
2097 m_windowSizer
= sizer
;
2099 sizer
->SetSizerParent((wxWindow
*)this);
2106 bool wxWindow::Layout(void)
2108 if (GetConstraints())
2111 GetClientSize(&w
, &h
);
2112 GetConstraints()->width
.SetValue(w
);
2113 GetConstraints()->height
.SetValue(h
);
2116 // If top level (one sizer), evaluate the sizer's constraints.
2120 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2121 GetSizer()->LayoutPhase1(&noChanges
);
2122 GetSizer()->LayoutPhase2(&noChanges
);
2123 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2128 // Otherwise, evaluate child constraints
2129 ResetConstraints(); // Mark all constraints as unevaluated
2130 DoPhase(1); // Just one phase need if no sizers involved
2132 SetConstraintSizes(); // Recursively set the real window sizes
2138 // Do a phase of evaluating constraints:
2139 // the default behaviour. wxSizers may do a similar
2140 // thing, but also impose their own 'constraints'
2141 // and order the evaluation differently.
2142 bool wxWindow::LayoutPhase1(int *noChanges
)
2144 wxLayoutConstraints
*constr
= GetConstraints();
2147 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2153 bool wxWindow::LayoutPhase2(int *noChanges
)
2163 // Do a phase of evaluating child constraints
2164 bool wxWindow::DoPhase(int phase
)
2166 int noIterations
= 0;
2167 int maxIterations
= 500;
2171 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2175 wxNode
*node
= GetChildren()->First();
2178 wxWindow
*child
= (wxWindow
*)node
->Data();
2179 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2181 wxLayoutConstraints
*constr
= child
->GetConstraints();
2184 if (succeeded
.Member(child
))
2189 int tempNoChanges
= 0;
2190 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2191 noChanges
+= tempNoChanges
;
2194 succeeded
.Append(child
);
2199 node
= node
->Next();
2206 void wxWindow::ResetConstraints(void)
2208 wxLayoutConstraints
*constr
= GetConstraints();
2211 constr
->left
.SetDone(FALSE
);
2212 constr
->top
.SetDone(FALSE
);
2213 constr
->right
.SetDone(FALSE
);
2214 constr
->bottom
.SetDone(FALSE
);
2215 constr
->width
.SetDone(FALSE
);
2216 constr
->height
.SetDone(FALSE
);
2217 constr
->centreX
.SetDone(FALSE
);
2218 constr
->centreY
.SetDone(FALSE
);
2220 wxNode
*node
= GetChildren()->First();
2223 wxWindow
*win
= (wxWindow
*)node
->Data();
2224 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2225 win
->ResetConstraints();
2226 node
= node
->Next();
2230 // Need to distinguish between setting the 'fake' size for
2231 // windows and sizers, and setting the real values.
2232 void wxWindow::SetConstraintSizes(bool recurse
)
2234 wxLayoutConstraints
*constr
= GetConstraints();
2235 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2236 constr
->width
.GetDone() && constr
->height
.GetDone())
2238 int x
= constr
->left
.GetValue();
2239 int y
= constr
->top
.GetValue();
2240 int w
= constr
->width
.GetValue();
2241 int h
= constr
->height
.GetValue();
2243 // If we don't want to resize this window, just move it...
2244 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2245 (constr
->height
.GetRelationship() != wxAsIs
))
2247 // Calls Layout() recursively. AAAGH. How can we stop that.
2248 // Simply take Layout() out of non-top level OnSizes.
2249 SizerSetSize(x
, y
, w
, h
);
2258 char *windowClass
= this->GetClassInfo()->GetClassName();
2261 if (GetName() == "")
2262 winName
= "unnamed";
2264 winName
= GetName();
2265 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
2266 if (!constr
->left
.GetDone())
2267 wxDebugMsg(" unsatisfied 'left' constraint.\n");
2268 if (!constr
->right
.GetDone())
2269 wxDebugMsg(" unsatisfied 'right' constraint.\n");
2270 if (!constr
->width
.GetDone())
2271 wxDebugMsg(" unsatisfied 'width' constraint.\n");
2272 if (!constr
->height
.GetDone())
2273 wxDebugMsg(" unsatisfied 'height' constraint.\n");
2274 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
2279 wxNode
*node
= GetChildren()->First();
2282 wxWindow
*win
= (wxWindow
*)node
->Data();
2283 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2284 win
->SetConstraintSizes();
2285 node
= node
->Next();
2290 // This assumes that all sizers are 'on' the same
2291 // window, i.e. the parent of this window.
2292 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2294 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2295 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2299 m_sizerParent
->GetPosition(&xp
, &yp
);
2300 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2305 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2309 TransformSizerToActual(&xx
, &yy
);
2310 SetSize(xx
, yy
, w
, h
);
2313 void wxWindow::SizerMove(int x
, int y
)
2317 TransformSizerToActual(&xx
, &yy
);
2321 // Only set the size/position of the constraint (if any)
2322 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2324 wxLayoutConstraints
*constr
= GetConstraints();
2329 constr
->left
.SetValue(x
);
2330 constr
->left
.SetDone(TRUE
);
2334 constr
->top
.SetValue(y
);
2335 constr
->top
.SetDone(TRUE
);
2339 constr
->width
.SetValue(w
);
2340 constr
->width
.SetDone(TRUE
);
2344 constr
->height
.SetValue(h
);
2345 constr
->height
.SetDone(TRUE
);
2350 void wxWindow::MoveConstraint(int x
, int y
)
2352 wxLayoutConstraints
*constr
= GetConstraints();
2357 constr
->left
.SetValue(x
);
2358 constr
->left
.SetDone(TRUE
);
2362 constr
->top
.SetValue(y
);
2363 constr
->top
.SetDone(TRUE
);
2368 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2370 wxLayoutConstraints
*constr
= GetConstraints();
2373 *w
= constr
->width
.GetValue();
2374 *h
= constr
->height
.GetValue();
2380 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2382 wxLayoutConstraints
*constr
= GetConstraints();
2385 *w
= constr
->width
.GetValue();
2386 *h
= constr
->height
.GetValue();
2389 GetClientSize(w
, h
);
2392 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2394 wxLayoutConstraints
*constr
= GetConstraints();
2397 *x
= constr
->left
.GetValue();
2398 *y
= constr
->top
.GetValue();
2404 bool wxWindow::AcceptsFocus() const
2406 return IsEnabled() && IsShown();