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
112 // for frames and from within MDI and tabbed windows (client area
113 // size determined internally by GTK, not wxWin).
116 void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
118 if (!win->HasVMT()) return;
119 if (g_blockEventsOnDrag) return;
123 if ((win->m_x == alloc->x) &&
124 (win->m_y == alloc->y) &&
125 (win->m_width == alloc->width) &&
126 (win->m_height == alloc->height))
131 printf( "OnResize from " );
132 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
133 printf( win->GetClassInfo()->GetClassName() );
136 printf( " Old: X: %d Y: %d ", win->m_x, win->m_y );
137 printf( " W: %d H: %d ", win->m_width, win->m_height );
140 printf( " New: X: %d Y: %d ", alloc->x, alloc->y );
141 printf( " W: %d H: %d ", alloc->width, alloc->height );
144 wxSizeEvent event( wxSize( alloc->width, alloc->height), win->GetId() );
145 event.SetEventObject( win );
146 win->ProcessEvent( event );
150 //-----------------------------------------------------------------------------
153 gint
gtk_window_key_press_callback( GtkWidget
*WXUNUSED(widget
), GdkEventKey
*gdk_event
, wxWindow
*win
)
155 if (!win
->HasVMT()) return FALSE
;
156 if (g_blockEventsOnDrag
) return FALSE
;
159 printf( "OnKeyPress from " );
160 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
161 printf( win->GetClassInfo()->GetClassName() );
166 switch (gdk_event
->keyval
)
168 case GDK_BackSpace
: key_code
= WXK_BACK
; break;
169 case GDK_Tab
: key_code
= WXK_TAB
; break;
170 case GDK_Linefeed
: key_code
= WXK_RETURN
; break;
171 case GDK_Clear
: key_code
= WXK_CLEAR
; break;
172 case GDK_Return
: key_code
= WXK_RETURN
; break;
173 case GDK_Pause
: key_code
= WXK_PAUSE
; break;
174 case GDK_Scroll_Lock
: key_code
= WXK_SCROLL
; break;
175 case GDK_Escape
: key_code
= WXK_ESCAPE
; break;
176 case GDK_Delete
: key_code
= WXK_DELETE
; break;
177 case GDK_Home
: key_code
= WXK_HOME
; break;
178 case GDK_Left
: key_code
= WXK_LEFT
; break;
179 case GDK_Up
: key_code
= WXK_UP
; break;
180 case GDK_Right
: key_code
= WXK_RIGHT
; break;
181 case GDK_Down
: key_code
= WXK_DOWN
; break;
182 case GDK_Prior
: key_code
= WXK_PRIOR
; break;
183 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
184 case GDK_Next
: key_code
= WXK_NEXT
; break;
185 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
186 case GDK_End
: key_code
= WXK_END
; break;
187 case GDK_Begin
: key_code
= WXK_HOME
; break;
188 case GDK_Select
: key_code
= WXK_SELECT
; break;
189 case GDK_Print
: key_code
= WXK_PRINT
; break;
190 case GDK_Execute
: key_code
= WXK_EXECUTE
; break;
191 case GDK_Insert
: key_code
= WXK_INSERT
; break;
192 case GDK_Num_Lock
: key_code
= WXK_NUMLOCK
; break;
193 case GDK_KP_Tab
: key_code
= WXK_TAB
; break;
194 case GDK_KP_Enter
: key_code
= WXK_RETURN
; break;
195 case GDK_KP_Home
: key_code
= WXK_HOME
; break;
196 case GDK_KP_Left
: key_code
= WXK_LEFT
; break;
197 case GDK_KP_Up
: key_code
= WXK_UP
; break;
198 case GDK_KP_Right
: key_code
= WXK_RIGHT
; break;
199 case GDK_KP_Down
: key_code
= WXK_DOWN
; break;
200 case GDK_KP_Prior
: key_code
= WXK_PRIOR
; break;
201 // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
202 case GDK_KP_Next
: key_code
= WXK_NEXT
; break;
203 // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
204 case GDK_KP_End
: key_code
= WXK_END
; break;
205 case GDK_KP_Begin
: key_code
= WXK_HOME
; break;
206 case GDK_KP_Insert
: key_code
= WXK_INSERT
; break;
207 case GDK_KP_Delete
: key_code
= WXK_DELETE
; break;
208 case GDK_KP_Multiply
: key_code
= WXK_MULTIPLY
; break;
209 case GDK_KP_Add
: key_code
= WXK_ADD
; break;
210 case GDK_KP_Separator
: key_code
= WXK_SEPARATOR
; break;
211 case GDK_KP_Subtract
: key_code
= WXK_SUBTRACT
; break;
212 case GDK_KP_Decimal
: key_code
= WXK_DECIMAL
; break;
213 case GDK_KP_Divide
: key_code
= WXK_DIVIDE
; break;
214 case GDK_KP_0
: key_code
= WXK_NUMPAD0
; break;
215 case GDK_KP_1
: key_code
= WXK_NUMPAD1
; break;
216 case GDK_KP_2
: key_code
= WXK_NUMPAD2
; break;
217 case GDK_KP_3
: key_code
= WXK_NUMPAD3
; break;
218 case GDK_KP_4
: key_code
= WXK_NUMPAD4
; break;
219 case GDK_KP_5
: key_code
= WXK_NUMPAD5
; break;
220 case GDK_KP_6
: key_code
= WXK_NUMPAD6
; break;
221 case GDK_KP_7
: key_code
= WXK_NUMPAD7
; break;
222 case GDK_KP_8
: key_code
= WXK_NUMPAD7
; break;
223 case GDK_KP_9
: key_code
= WXK_NUMPAD9
; break;
224 case GDK_F1
: key_code
= WXK_F1
; break;
225 case GDK_F2
: key_code
= WXK_F2
; break;
226 case GDK_F3
: key_code
= WXK_F3
; break;
227 case GDK_F4
: key_code
= WXK_F4
; break;
228 case GDK_F5
: key_code
= WXK_F5
; break;
229 case GDK_F6
: key_code
= WXK_F6
; break;
230 case GDK_F7
: key_code
= WXK_F7
; break;
231 case GDK_F8
: key_code
= WXK_F8
; break;
232 case GDK_F9
: key_code
= WXK_F9
; break;
233 case GDK_F10
: key_code
= WXK_F10
; break;
234 case GDK_F11
: key_code
= WXK_F11
; break;
235 case GDK_F12
: key_code
= WXK_F12
; break;
238 if ((gdk_event
->keyval
>= 0x20) && (gdk_event
->keyval
<= 0xFF))
239 key_code
= gdk_event
->keyval
;
243 if (!key_code
) return FALSE
;
245 wxKeyEvent
event( wxEVT_CHAR
);
246 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
247 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
248 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
249 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
250 event
.m_keyCode
= key_code
;
253 event
.SetEventObject( win
);
254 return win
->ProcessEvent( event
);
257 //-----------------------------------------------------------------------------
260 gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
262 if (widget
->window
!= gdk_event
->window
) return FALSE
;
263 if (g_blockEventsOnDrag
) return FALSE
;
267 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
) && !GTK_WIDGET_HAS_FOCUS (win
->m_wxwindow
) )
269 gtk_widget_grab_focus (win
->m_wxwindow
);
272 printf( "GrabFocus from " );
273 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
274 printf( win->GetClassInfo()->GetClassName() );
281 if (!win
->HasVMT()) return FALSE
;
284 printf( "OnButtonPress from " );
285 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
286 printf( win->GetClassInfo()->GetClassName() );
290 wxEventType event_type
= wxEVT_LEFT_DOWN
;
292 if (gdk_event
->button
== 1)
294 switch (gdk_event
->type
)
296 case GDK_BUTTON_PRESS
: event_type
= wxEVT_LEFT_DOWN
; break;
297 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_LEFT_DCLICK
; break;
301 else if (gdk_event
->button
== 2)
303 switch (gdk_event
->type
)
305 case GDK_BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DOWN
; break;
306 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DCLICK
; break;
310 else if (gdk_event
->button
== 3)
312 switch (gdk_event
->type
)
314 case GDK_BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DOWN
; break;
315 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DCLICK
; break;
320 wxMouseEvent
event( event_type
);
321 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
322 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
323 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
324 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
325 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
326 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
327 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
329 event
.m_x
= (long)gdk_event
->x
;
330 event
.m_y
= (long)gdk_event
->y
;
331 event
.SetEventObject( win
);
333 win
->ProcessEvent( event
);
338 //-----------------------------------------------------------------------------
341 gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
343 if (widget
->window
!= gdk_event
->window
) return TRUE
;
345 if (g_blockEventsOnDrag
) return FALSE
;
347 if (!win
->HasVMT()) return FALSE
;
350 printf( "OnButtonRelease from " );
351 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
352 printf( win->GetClassInfo()->GetClassName() );
356 wxEventType event_type
= wxEVT_NULL
;
358 switch (gdk_event
->button
)
360 case 1: event_type
= wxEVT_LEFT_UP
; break;
361 case 2: event_type
= wxEVT_MIDDLE_UP
; break;
362 case 3: event_type
= wxEVT_RIGHT_UP
; break;
365 wxMouseEvent
event( event_type
);
366 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
367 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
368 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
369 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
370 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
371 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
372 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
373 event
.m_x
= (long)gdk_event
->x
;
374 event
.m_y
= (long)gdk_event
->y
;
375 event
.SetEventObject( win
);
377 return win
->ProcessEvent( event
);
380 //-----------------------------------------------------------------------------
383 gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxWindow
*win
)
385 if (widget
->window
!= gdk_event
->window
) return TRUE
;
387 if (g_blockEventsOnDrag
) return FALSE
;
389 if (!win
->HasVMT()) return FALSE
;
392 printf( "OnMotion from " );
393 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
394 printf( win->GetClassInfo()->GetClassName() );
398 wxMouseEvent
event( wxEVT_MOTION
);
399 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
400 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
401 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
402 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
403 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
404 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
405 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
407 event
.m_x
= (long)gdk_event
->x
;
408 event
.m_y
= (long)gdk_event
->y
;
409 event
.SetEventObject( win
);
411 win
->ProcessEvent( event
);
416 //-----------------------------------------------------------------------------
419 gint
gtk_window_focus_in_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
421 if (g_blockEventsOnDrag
) return FALSE
;
424 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
426 GTK_WIDGET_SET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
428 printf( "SetFocus flag from " );
429 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
430 printf( win->GetClassInfo()->GetClassName() );
436 if (!win
->HasVMT()) return FALSE
;
439 printf( "OnSetFocus from " );
440 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
441 printf( win->GetClassInfo()->GetClassName() );
443 printf( WXSTRINGCAST win->GetLabel() );
447 wxFocusEvent
event( wxEVT_SET_FOCUS
, win
->GetId() );
448 event
.SetEventObject( win
);
449 return win
->ProcessEvent( event
);
452 //-----------------------------------------------------------------------------
455 gint
gtk_window_focus_out_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
457 if (g_blockEventsOnDrag
) return FALSE
;
460 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
461 GTK_WIDGET_UNSET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
464 if (!win
->HasVMT()) return FALSE
;
467 printf( "OnKillFocus from " );
468 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
469 printf( win->GetClassInfo()->GetClassName() );
473 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
474 event
.SetEventObject( win
);
475 return win
->ProcessEvent( event
);
478 //-----------------------------------------------------------------------------
481 void gtk_window_vscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
483 if (g_blockEventsOnDrag
) return;
486 printf( "OnVScroll from " );
487 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
488 printf( win->GetClassInfo()->GetClassName() );
492 if (!win
->HasVMT()) return;
494 float diff
= win
->m_vAdjust
->value
- win
->m_oldVerticalPos
;
495 if (fabs(diff
) < 0.2) return;
498 int i = (int)(win->m_oldVerticalPos+0.5);
499 printf( "Old value: %d.\n", i );
500 i = (int)(win->m_vAdjust->value+0.5);
501 printf( "Sending new value: %d.\n", i );
504 wxEventType command
= wxEVT_NULL
;
506 float line_step
= win
->m_vAdjust
->step_increment
;
507 float page_step
= win
->m_vAdjust
->page_increment
;
509 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
510 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
511 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
512 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
513 else command
= wxEVT_SCROLL_THUMBTRACK
;
515 int value
= (int)(win
->m_vAdjust
->value
+0.5);
517 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
518 event
.SetEventObject( win
);
519 win
->ProcessEvent( event
);
522 //-----------------------------------------------------------------------------
525 void gtk_window_hscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
527 if (g_blockEventsOnDrag
) return;
530 printf( "OnHScroll from " );
531 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
532 printf( win->GetClassInfo()->GetClassName() );
536 if (!win
->HasVMT()) return;
538 float diff
= win
->m_hAdjust
->value
- win
->m_oldHorizontalPos
;
539 if (fabs(diff
) < 0.2) return;
542 int i = (int)(win->m_oldHorizontalPos+0.5);
543 printf( "Old value: %d.\n", i );
544 i = (int)(win->m_hAdjust->value+0.5);
545 printf( "Sending new value: %d.\n", i );
548 wxEventType command
= wxEVT_NULL
;
550 float line_step
= win
->m_hAdjust
->step_increment
;
551 float page_step
= win
->m_hAdjust
->page_increment
;
553 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
554 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
555 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
556 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
557 else command
= wxEVT_SCROLL_THUMBTRACK
;
559 int value
= (int)(win
->m_hAdjust
->value
+0.5);
561 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
562 event
.SetEventObject( win
);
563 win
->ProcessEvent( event
);
566 //-----------------------------------------------------------------------------
567 // vertical scroll change
569 void gtk_window_vscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
571 if (g_blockEventsOnDrag
) return;
574 printf( "OnVScroll change from " );
575 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
576 printf( win->GetClassInfo()->GetClassName() );
580 if (!win
->HasVMT()) return;
582 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
583 int value
= (int)(win
->m_vAdjust
->value
+0.5);
585 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
586 event
.SetEventObject( win
);
587 win
->ProcessEvent( event
);
590 //-----------------------------------------------------------------------------
591 // horizontal scroll change
593 void gtk_window_hscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
595 if (g_blockEventsOnDrag
) return;
598 printf( "OnHScroll change from " );
599 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
600 printf( win->GetClassInfo()->GetClassName() );
604 if (!win
->HasVMT()) return;
606 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
607 int value
= (int)(win
->m_hAdjust
->value
+0.5);
609 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
610 event
.SetEventObject( win
);
611 win
->ProcessEvent( event
);
614 //-----------------------------------------------------------------------------
617 void gtk_window_drop_callback( GtkWidget
*widget
, GdkEvent
*event
, wxWindow
*win
)
619 printf( "OnDrop.\n" );
621 if (win
->GetDropTarget())
625 gdk_window_get_pointer( widget
->window
, &x
, &y
, NULL
);
626 win
->GetDropTarget()->Drop( event
, x
, y
);
630 g_free (event->dropdataavailable.data);
631 g_free (event->dropdataavailable.data_type);
635 //-----------------------------------------------------------------------------
638 bool gtk_window_destroy_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
640 printf( "OnDestroy from " );
641 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
642 printf( win
->GetClassInfo()->GetClassName() );
644 printf( "Goodbye.\n" );
645 printf( " Robert Roebling.\n" );
650 //-----------------------------------------------------------------------------
653 bool gtk_window_enter_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
655 if (widget
->window
!= gdk_event
->window
) return TRUE
;
657 if (g_blockEventsOnDrag
) return FALSE
;
660 gdk_window_set_cursor( widget
->window
, win
->m_cursor
->GetCursor() );
662 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
663 event
.SetEventObject( win
);
664 return win
->ProcessEvent( event
);
667 //-----------------------------------------------------------------------------
670 bool gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
672 if (widget
->window
!= gdk_event
->window
) return TRUE
;
674 if (g_blockEventsOnDrag
) return FALSE
;
677 gdk_window_set_cursor( widget
->window
, wxSTANDARD_CURSOR
->GetCursor() );
679 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
680 event
.SetEventObject( win
);
681 return win
->ProcessEvent( event
);
684 //-----------------------------------------------------------------------------
685 // wxWindow implementation
686 //-----------------------------------------------------------------------------
688 IMPLEMENT_DYNAMIC_CLASS(wxWindow
,wxEvtHandler
)
690 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
691 // EVT_CHAR(wxWindow::OnChar)
692 EVT_SIZE(wxWindow::OnSize
)
693 // EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
694 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
695 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
696 // EVT_IDLE(wxWindow::OnIdle)
704 m_children
.DeleteContents( FALSE
);
710 m_eventHandler
= this;
711 m_windowValidator
= NULL
;
713 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
714 m_font
= *wxSWISS_FONT
;
716 m_windowName
= "noname";
717 m_constraints
= NULL
;
718 m_constraintsInvolvedIn
= NULL
;
719 m_windowSizer
= NULL
;
720 m_sizerParent
= NULL
;
721 m_autoLayout
= FALSE
;
725 m_hasScrolling
= FALSE
;
728 m_oldHorizontalPos
= 0.0;
729 m_oldVerticalPos
= 0.0;
732 m_drawingOffsetX
= 0;
733 m_drawingOffsetY
= 0;
734 m_pDropTarget
= NULL
;
738 wxWindow::wxWindow( wxWindow
*parent
, wxWindowID id
,
739 const wxPoint
&pos
, const wxSize
&size
,
740 long style
, const wxString
&name
)
742 Create( parent
, id
, pos
, size
, style
, name
);
745 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
746 const wxPoint
&pos
, const wxSize
&size
,
747 long style
, const wxString
&name
)
753 PreCreation( parent
, id
, pos
, size
, style
, name
);
755 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
756 m_hasScrolling
= TRUE
;
758 GtkScrolledWindow
*s_window
;
759 s_window
= GTK_SCROLLED_WINDOW(m_widget
);
761 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
762 scroll_class
->scrollbar_spacing
= 0;
764 gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
766 m_oldHorizontalPos
= 0.0;
767 m_oldVerticalPos
= 0.0;
769 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) );
770 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) );
772 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "value_changed",
773 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
774 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "value_changed",
775 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
777 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "changed",
778 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
779 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "changed",
780 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
782 GtkViewport
*viewport
;
783 viewport
= GTK_VIEWPORT(s_window
->viewport
);
785 if (m_windowStyle
& wxRAISED_BORDER
)
787 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
789 else if (m_windowStyle
& wxSUNKEN_BORDER
)
791 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
795 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
798 m_wxwindow
= gtk_myfixed_new();
800 if (m_windowStyle
& wxTAB_TRAVERSAL
== wxTAB_TRAVERSAL
)
801 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
803 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
805 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
807 // shut the viewport up
808 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
809 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
811 // I _really_ don't want scrollbars in the beginning
812 m_vAdjust
->lower
= 0.0;
813 m_vAdjust
->upper
= 1.0;
814 m_vAdjust
->value
= 0.0;
815 m_vAdjust
->step_increment
= 1.0;
816 m_vAdjust
->page_increment
= 1.0;
817 m_vAdjust
->page_size
= 5.0;
818 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
819 m_hAdjust
->lower
= 0.0;
820 m_hAdjust
->upper
= 1.0;
821 m_hAdjust
->value
= 0.0;
822 m_hAdjust
->step_increment
= 1.0;
823 m_hAdjust
->page_increment
= 1.0;
824 m_hAdjust
->page_size
= 5.0;
825 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
827 gtk_widget_show( m_wxwindow
);
836 wxWindow::~wxWindow(void)
840 if (m_pDropTarget
) delete m_pDropTarget
;
842 if (m_parent
) m_parent
->RemoveChild( this );
843 if (m_widget
) Show( FALSE
);
847 if (m_wxwindow
) gtk_widget_destroy( m_wxwindow
);
849 if (m_widget
) gtk_widget_destroy( m_widget
);
853 DeleteRelatedConstraints();
856 // This removes any dangling pointers to this window
857 // in other windows' constraintsInvolvedIn lists.
858 UnsetConstraints(m_constraints
);
859 delete m_constraints
;
860 m_constraints
= NULL
;
864 delete m_windowSizer
;
865 m_windowSizer
= NULL
;
867 // If this is a child of a sizer, remove self from parent
869 m_sizerParent
->RemoveChild((wxWindow
*)this);
871 // Just in case the window has been Closed, but
872 // we're then deleting immediately: don't leave
873 // dangling pointers.
874 wxPendingDelete
.DeleteObject(this);
876 // Just in case we've loaded a top-level window via
877 // wxWindow::LoadNativeDialog but we weren't a dialog
879 wxTopLevelWindows
.DeleteObject(this);
883 void wxWindow::PreCreation( wxWindow
*parent
, wxWindowID id
,
884 const wxPoint
&pos
, const wxSize
&size
,
885 long style
, const wxString
&name
)
887 if (m_needParent
&& (parent
== NULL
))
888 wxFatalError( "Need complete parent.", name
);
893 m_children
.DeleteContents( FALSE
);
897 if (m_width
== -1) m_width
= 20;
899 if (m_height
== -1) m_height
= 20;
901 m_eventHandler
= this;
902 m_windowValidator
= NULL
;
905 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
906 m_font
= *wxSWISS_FONT
;
907 m_backgroundColour
= wxWHITE
;
908 m_foregroundColour
= wxBLACK
;
909 m_windowStyle
= style
;
911 m_constraints
= NULL
;
912 m_constraintsInvolvedIn
= NULL
;
913 m_windowSizer
= NULL
;
914 m_sizerParent
= NULL
;
915 m_autoLayout
= FALSE
;
916 m_drawingOffsetX
= 0;
917 m_drawingOffsetY
= 0;
918 m_pDropTarget
= NULL
;
922 void wxWindow::PostCreation(void)
924 if (m_parent
) m_parent
->AddChild( this );
926 // GtkStyle *style = m_widget->style;
927 // style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
929 GtkWidget
*connect_widget
= m_widget
;
930 if (m_wxwindow
) connect_widget
= m_wxwindow
;
932 gtk_object_set_data (GTK_OBJECT (connect_widget
), "MyWxWindow", (gpointer
)this );
936 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
937 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
939 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
940 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
944 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
945 GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this );
948 gtk_signal_connect( GTK_OBJECT(connect_widget
), "key_press_event",
949 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
951 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_press_event",
952 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
954 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_release_event",
955 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
957 gtk_signal_connect( GTK_OBJECT(connect_widget
), "motion_notify_event",
958 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
960 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_in_event",
961 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
963 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_out_event",
964 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
966 gtk_signal_connect( GTK_OBJECT(connect_widget
), "drop_data_available_event",
967 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
969 // Only for cursor handling
971 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter_notify_event",
972 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
974 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave_notify_event",
975 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
979 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "enter_notify_event",
980 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
982 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "leave_notify_event",
983 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
987 // Does destroy ever get called ?
989 gtk_signal_connect( GTK_OBJECT(m_widget), "destroy_event",
990 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
994 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "destroy_event",
995 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
999 if (m_widget
&& m_parent
) gtk_widget_realize( m_widget
);
1000 if (m_wxwindow
) gtk_widget_realize( m_wxwindow
);
1002 SetCursor( wxSTANDARD_CURSOR
);
1007 bool wxWindow::HasVMT(void)
1012 bool wxWindow::Close( bool force
)
1014 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1015 event
.SetEventObject(this);
1016 event
.SetForce(force
);
1018 return GetEventHandler()->ProcessEvent(event
);
1021 bool wxWindow::Destroy(void)
1028 bool wxWindow::DestroyChildren(void)
1033 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
)
1036 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
)
1039 if (GetChildren()->Member(child
)) delete node
;
1046 void wxWindow::PrepareDC( wxDC
&WXUNUSED(dc
) )
1048 // are we to set fonts here ?
1051 void wxWindow::ImplementSetSize(void)
1053 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1056 void wxWindow::ImplementSetPosition(void)
1058 if ((m_parent
) && (m_parent
->m_wxwindow
))
1059 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1061 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1064 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1066 if (m_resizing
) return; // I don't like recursions
1074 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1076 if (newX
== -1) newX
= m_x
;
1077 if (newY
== -1) newY
= m_y
;
1078 if (newW
== -1) newW
= m_width
;
1079 if (newH
== -1) newH
= m_height
;
1082 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1084 if (newW
== -1) newW
= 80;
1087 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1089 if (newH
== -1) newH
= 26;
1092 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1096 ImplementSetPosition();
1098 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1106 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1107 event
.SetEventObject( this );
1108 ProcessEvent( event
);
1113 void wxWindow::SetSize( int width
, int height
)
1115 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1118 void wxWindow::Move( int x
, int y
)
1120 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1123 void wxWindow::GetSize( int *width
, int *height
) const
1125 if (width
) (*width
) = m_width
;
1126 if (height
) (*height
) = m_height
;
1129 void wxWindow::SetClientSize( int width
, int height
)
1133 SetSize( width
, height
);
1140 if (!m_hasScrolling
)
1143 do we have sunken dialogs ?
1145 GtkStyleClass *window_class = m_wxwindow->style->klass;
1147 dw += 2 * window_class->xthickness;
1148 dh += 2 * window_class->ythickness;
1153 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1154 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1156 GtkWidget
*viewport
= scroll_window
->viewport
;
1157 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1159 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1160 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1162 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1163 (m_windowStyle
& wxSUNKEN_BORDER
)
1166 dw
+= 2 * viewport_class
->xthickness
;
1167 dh
+= 2 * viewport_class
->ythickness
;
1170 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1172 dw
+= vscrollbar
->allocation
.width
;
1173 dw
+= scroll_class
->scrollbar_spacing
;
1176 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1178 dh
+= hscrollbar
->allocation
.height
;
1179 dw
+= scroll_class
->scrollbar_spacing
;
1183 SetSize( width
+dw
, height
+dh
);
1187 void wxWindow::GetClientSize( int *width
, int *height
) const
1191 if (width
) (*width
) = m_width
;
1192 if (height
) (*height
) = m_height
;
1199 if (!m_hasScrolling
)
1202 do we have sunken dialogs ?
1204 GtkStyleClass *window_class = m_wxwindow->style->klass;
1206 dw += 2 * window_class->xthickness;
1207 dh += 2 * window_class->ythickness;
1212 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1213 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1215 GtkWidget
*viewport
= scroll_window
->viewport
;
1216 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1218 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1219 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1221 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1222 (m_windowStyle
& wxSUNKEN_BORDER
)
1225 dw
+= 2 * viewport_class
->xthickness
;
1226 dh
+= 2 * viewport_class
->ythickness
;
1229 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1231 // dw += vscrollbar->allocation.width;
1232 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1233 dw
+= scroll_class
->scrollbar_spacing
;
1236 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1238 // dh += hscrollbar->allocation.height;
1240 dh
+= scroll_class
->scrollbar_spacing
;
1244 if (width
) (*width
) = m_width
- dw
;
1245 if (height
) (*height
) = m_height
- dh
;
1249 void wxWindow::GetPosition( int *x
, int *y
) const
1255 void wxWindow::ClientToScreen( int *x
, int *y
)
1257 // Does this look simple ?
1259 GdkWindow
*source
= NULL
;
1261 source
= m_wxwindow
->window
;
1263 source
= m_widget
->window
;
1267 gdk_window_get_origin( source
, &org_x
, &org_y
);
1271 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1273 org_x
+= m_widget
->allocation
.x
;
1274 org_y
+= m_widget
->allocation
.y
;
1282 void wxWindow::ScreenToClient( int *x
, int *y
)
1284 GdkWindow
*source
= NULL
;
1286 source
= m_wxwindow
->window
;
1288 source
= m_widget
->window
;
1292 gdk_window_get_origin( source
, &org_x
, &org_y
);
1296 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1298 org_x
+= m_widget
->allocation
.x
;
1299 org_y
+= m_widget
->allocation
.y
;
1307 void wxWindow::Centre( int direction
)
1311 GetPosition( &x
, &y
);
1312 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1314 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) x
= (gdk_screen_width () - m_width
) / 2;
1315 if (direction
& wxVERTICAL
== wxVERTICAL
) y
= (gdk_screen_height () - m_height
) / 2;
1316 gtk_widget_set_uposition( m_widget
, x
, y
);
1324 m_parent
->GetSize( &p_w
, &p_h
);
1325 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) x
= (p_w
- m_width
) / 2;
1326 if (direction
& wxVERTICAL
== wxVERTICAL
) y
= (p_h
- m_height
) / 2;
1327 gtk_widget_set_uposition( m_widget
, x
, y
);
1332 void wxWindow::Fit(void)
1336 wxNode
*node
= GetChildren()->First();
1339 wxWindow
*win
= (wxWindow
*)node
->Data();
1341 win
->GetPosition(&wx
, &wy
);
1342 win
->GetSize(&ww
, &wh
);
1343 if ( wx
+ ww
> maxX
)
1345 if ( wy
+ wh
> maxY
)
1348 node
= node
->Next();
1350 SetClientSize(maxX
+ 5, maxY
+ 5);
1353 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1355 //if (GetAutoLayout()) Layout();
1358 bool wxWindow::Show( bool show
)
1361 gtk_widget_show( m_widget
);
1363 gtk_widget_hide( m_widget
);
1368 void wxWindow::Enable( bool enable
)
1370 m_isEnabled
= enable
;
1371 gtk_widget_set_sensitive( m_widget
, enable
);
1372 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1375 void wxWindow::MakeModal( bool modal
)
1378 // Disable all other windows
1379 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1381 wxNode
*node
= wxTopLevelWindows
.First();
1384 wxWindow
*win
= (wxWindow
*)node
->Data();
1386 win
->Enable(!modal
);
1388 node
= node
->Next();
1393 void wxWindow::SetFocus(void)
1395 GtkWidget
*connect_widget
= m_widget
;
1396 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1399 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1401 gtk_widget_grab_focus (connect_widget
);
1406 bool wxWindow::OnClose(void)
1408 printf( "OnClose event.\n" );
1412 void wxWindow::AddChild( wxWindow
*child
)
1414 // Addchild is (often) called before the program
1415 // has left the parents constructor so that no
1416 // virtual tables work yet. The approach below
1417 // practically imitates virtual tables, i.e. it
1418 // implements a different AddChild() behaviour
1419 // for wxFrame, wxDialog, wxWindow and
1420 // wxMDIParentFrame.
1422 if (IsKindOf(CLASSINFO(wxMDIParentFrame
)))
1424 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1426 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1429 client
->AddChild( child
);
1435 // wxNotebooks are very special, so they have their own AddChild
1437 if (IsKindOf(CLASSINFO(wxNotebook
)))
1439 wxNotebook
*tab
= (wxNotebook
*)this;
1440 tab
->AddChild( child
);
1444 m_children
.Append( child
);
1445 if (child
->IsKindOf(CLASSINFO(wxFrame
)) || child
->IsKindOf(CLASSINFO(wxDialog
)))
1447 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1448 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1453 gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
, child
->m_x
, child
->m_y
);
1455 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1458 wxList
*wxWindow::GetChildren(void)
1460 return (&m_children
);
1463 void wxWindow::RemoveChild( wxWindow
*child
)
1466 GetChildren()->DeleteObject( child
);
1467 child
->m_parent
= NULL
;
1470 void wxWindow::SetReturnCode( int retCode
)
1472 m_retCode
= retCode
;
1475 int wxWindow::GetReturnCode(void)
1480 wxWindow
*wxWindow::GetParent(void)
1485 wxEvtHandler
*wxWindow::GetEventHandler(void)
1487 return m_eventHandler
;
1490 void wxWindow::SetEventhandler( wxEvtHandler
*handler
)
1492 m_eventHandler
= handler
;
1495 wxValidator
*wxWindow::GetValidator(void)
1497 return m_windowValidator
;
1500 void wxWindow::SetValidator( wxValidator
*validator
)
1502 m_windowValidator
= validator
;
1505 bool wxWindow::IsBeingDeleted(void)
1510 void wxWindow::SetId( wxWindowID id
)
1515 wxWindowID
wxWindow::GetId(void)
1520 void wxWindow::SetCursor( const wxCursor
&cursor
)
1522 if (*m_cursor
== cursor
) return;
1523 (*m_cursor
) = cursor
;
1524 if (m_widget
->window
)
1525 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1526 if (m_wxwindow
&& m_wxwindow
->window
)
1527 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1530 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1532 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1535 gdk_window_clear_area( m_wxwindow
->window
,
1547 wxClientDC
dc(this);
1551 dc
.GetInternalDeviceOrigin( &x
, &y
);
1555 GetClientSize( &w
, &h
);
1557 GdkRectangle gdk_rect
;
1561 gdk_rect
.height
= h
;
1562 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1567 GdkRectangle gdk_rect
;
1568 gdk_rect
.x
= rect
->x
;
1569 gdk_rect
.y
= rect
->y
;
1570 gdk_rect
.width
= rect
->width
;
1571 gdk_rect
.height
= rect
->height
;
1573 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1575 gtk_widget_draw( m_widget
, &gdk_rect
);
1579 bool wxWindow::IsExposed( long x
, long y
)
1581 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1584 bool wxWindow::IsExposed( long x
, long y
, long width
, long height
)
1586 return (m_updateRegion
.Contains( x
, y
, width
, height
) != wxOutRegion
);
1589 void wxWindow::Clear(void)
1591 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1594 wxColour
wxWindow::GetBackgroundColour(void) const
1596 return m_backgroundColour
;
1599 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1601 m_backgroundColour
= colour
;
1604 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1605 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1606 gdk_window_clear( m_wxwindow
->window
);
1611 bool wxWindow::Validate(void)
1613 wxNode
*node
= GetChildren()->First();
1616 wxWindow
*child
= (wxWindow
*)node
->Data();
1617 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1619 node
= node
->Next();
1624 bool wxWindow::TransferDataToWindow(void)
1626 wxNode
*node
= GetChildren()->First();
1629 wxWindow
*child
= (wxWindow
*)node
->Data();
1630 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1631 !child
->GetValidator()->TransferToWindow() )
1633 wxMessageBox( "Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1636 node
= node
->Next();
1641 bool wxWindow::TransferDataFromWindow(void)
1643 wxNode
*node
= GetChildren()->First();
1646 wxWindow
*child
= (wxWindow
*)node
->Data();
1647 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1649 node
= node
->Next();
1654 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1656 TransferDataToWindow();
1659 void wxWindow::InitDialog(void)
1661 wxInitDialogEvent
event(GetId());
1662 event
.SetEventObject( this );
1663 GetEventHandler()->ProcessEvent(event
);
1666 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1668 GtkWidget
*connect_widget
= m_widget
;
1669 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1672 m_pDropTarget
->UnregisterWidget( connect_widget
);
1673 delete m_pDropTarget
;
1675 m_pDropTarget
= dropTarget
;
1678 m_pDropTarget
->RegisterWidget( connect_widget
);
1682 wxDropTarget
*wxWindow::GetDropTarget() const
1684 return m_pDropTarget
;
1687 void wxWindow::SetFont( const wxFont
&font
)
1692 copy old style values to new one
1693 set font in new style
1694 -> takes to many resources
1696 GtkStyle *style = gtk_style_new();
1701 wxFont
*wxWindow::GetFont(void)
1706 void wxWindow::SetWindowStyleFlag( long flag
)
1708 m_windowStyle
= flag
;
1711 long wxWindow::GetWindowStyleFlag(void) const
1713 return m_windowStyle
;
1716 void wxWindow::CaptureMouse(void)
1718 GtkWidget
*connect_widget
= m_widget
;
1719 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1720 gtk_grab_add( connect_widget
);
1721 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1723 (GDK_BUTTON_PRESS_MASK
|
1724 GDK_BUTTON_RELEASE_MASK
|
1725 GDK_POINTER_MOTION_MASK
),
1726 NULL
, NULL
, GDK_CURRENT_TIME
);
1729 void wxWindow::ReleaseMouse(void)
1731 GtkWidget
*connect_widget
= m_widget
;
1732 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1733 gtk_grab_remove( connect_widget
);
1734 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1737 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1741 wxString
wxWindow::GetTitle(void) const
1743 return (wxString
&)m_windowName
;
1746 wxString
wxWindow::GetLabel(void) const
1751 void wxWindow::SetName( const wxString
&name
)
1753 m_windowName
= name
;
1756 wxString
wxWindow::GetName(void) const
1758 return (wxString
&)m_windowName
;
1761 bool wxWindow::IsShown(void) const
1766 bool wxWindow::IsRetained(void)
1771 wxWindow
*wxWindow::FindWindow( long id
)
1773 if (id
== m_windowId
) return this;
1774 wxNode
*node
= m_children
.First();
1777 wxWindow
*child
= (wxWindow
*)node
->Data();
1778 wxWindow
*res
= child
->FindWindow( id
);
1779 if (res
) return res
;
1780 node
= node
->Next();
1785 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1787 if (name
== m_windowName
) return this;
1788 wxNode
*node
= m_children
.First();
1791 wxWindow
*child
= (wxWindow
*)node
->Data();
1792 wxWindow
*res
= child
->FindWindow( name
);
1793 if (res
) return res
;
1794 node
= node
->Next();
1799 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1800 int range
, bool WXUNUSED(refresh
) )
1802 if (!m_wxwindow
) return;
1804 if (orient
== wxHORIZONTAL
)
1806 float fpos
= (float)pos
;
1807 m_oldHorizontalPos
= fpos
;
1808 float frange
= (float)range
;
1809 float fthumb
= (float)thumbVisible
;
1811 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1812 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1813 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1816 m_hAdjust
->lower
= 0.0;
1817 m_hAdjust
->upper
= frange
;
1818 m_hAdjust
->value
= fpos
;
1819 m_hAdjust
->step_increment
= 1.0;
1820 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1821 m_hAdjust
->page_size
= fthumb
;
1825 float fpos
= (float)pos
;
1826 m_oldVerticalPos
= fpos
;
1827 float frange
= (float)range
;
1828 float fthumb
= (float)thumbVisible
;
1830 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1831 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1832 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1835 m_vAdjust
->lower
= 0.0;
1836 m_vAdjust
->upper
= frange
;
1837 m_vAdjust
->value
= fpos
;
1838 m_vAdjust
->step_increment
= 1.0;
1839 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1840 m_vAdjust
->page_size
= fthumb
;
1843 if (m_wxwindow
->window
)
1845 if (orient
== wxHORIZONTAL
)
1846 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
1848 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
1850 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1854 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
1856 if (!m_wxwindow
) return;
1858 if (orient
== wxHORIZONTAL
)
1860 float fpos
= (float)pos
;
1861 m_oldHorizontalPos
= fpos
;
1863 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
1864 m_hAdjust
->value
= fpos
;
1868 float fpos
= (float)pos
;
1869 m_oldVerticalPos
= fpos
;
1870 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
1871 m_vAdjust
->value
= fpos
;
1874 if (m_wxwindow
->window
)
1876 if (orient
== wxHORIZONTAL
)
1877 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
1879 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
1883 int wxWindow::GetScrollThumb( int orient
) const
1885 if (!m_wxwindow
) return 0;
1887 if (orient
== wxHORIZONTAL
)
1888 return (int)(m_hAdjust
->page_size
+0.5);
1890 return (int)(m_vAdjust
->page_size
+0.5);
1893 int wxWindow::GetScrollPos( int orient
) const
1895 if (!m_wxwindow
) return 0;
1897 if (orient
== wxHORIZONTAL
)
1898 return (int)(m_hAdjust
->value
+0.5);
1900 return (int)(m_vAdjust
->value
+0.5);
1903 int wxWindow::GetScrollRange( int orient
) const
1905 if (!m_wxwindow
) return 0;
1907 if (orient
== wxHORIZONTAL
)
1908 return (int)(m_hAdjust
->upper
+0.5);
1910 return (int)(m_vAdjust
->upper
+0.5);
1913 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
1915 if (!m_wxwindow
) return;
1917 m_drawingOffsetX
+= dx
;
1918 m_drawingOffsetY
+= dy
;
1920 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
1922 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow
), m_drawingOffsetX
, m_drawingOffsetY
);
1925 The code here is very nifty, but it doesn't work with
1926 overlapping windows...
1930 GetClientSize( &cw, &ch );
1932 int w = cw - abs(dx);
1933 int h = ch - abs(dy);
1934 if ((h < 0) || (w < 0))
1941 if (dx < 0) s_x = -dx;
1942 if (dy < 0) s_y = -dy;
1945 if (dx > 0) d_x = dx;
1946 if (dy > 0) d_y = dy;
1947 gdk_window_copy_area( m_wxwindow->window, m_wxwindow->style->fg_gc[0], d_x, d_y,
1948 m_wxwindow->window, s_x, s_y, w, h );
1951 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
1952 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
1953 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
1954 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
1956 Refresh( TRUE, &rect );
1960 void wxWindow::GetDrawingOffset( long *x
, long *y
)
1962 if (x
) *x
= m_drawingOffsetX
;
1963 if (y
) *y
= m_drawingOffsetY
;
1966 //-------------------------------------------------------------------------------------
1968 //-------------------------------------------------------------------------------------
1970 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
1972 return m_constraints
;
1975 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
1979 UnsetConstraints(m_constraints
);
1980 delete m_constraints
;
1982 m_constraints
= constraints
;
1985 // Make sure other windows know they're part of a 'meaningful relationship'
1986 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1987 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1988 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1989 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1990 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1991 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1992 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1993 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1994 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1995 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1996 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1997 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1998 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1999 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2000 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
2001 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2007 void wxWindow::SetAutoLayout( bool autoLayout
)
2009 m_autoLayout
= autoLayout
;
2012 bool wxWindow::GetAutoLayout(void) const
2014 return m_autoLayout
;
2017 wxSizer
*wxWindow::GetSizer(void) const
2019 return m_windowSizer
;
2022 void wxWindow::SetSizerParent( wxWindow
*win
)
2024 m_sizerParent
= win
;
2027 wxWindow
*wxWindow::GetSizerParent(void) const
2029 return m_sizerParent
;
2032 // This removes any dangling pointers to this window
2033 // in other windows' constraintsInvolvedIn lists.
2034 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2038 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2039 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2040 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2041 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2042 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2043 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2044 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2045 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2046 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2047 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2048 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2049 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2050 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2051 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2052 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2053 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2057 // Back-pointer to other windows we're involved with, so if we delete
2058 // this window, we must delete any constraints we're involved with.
2059 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2061 if (!m_constraintsInvolvedIn
)
2062 m_constraintsInvolvedIn
= new wxList
;
2063 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2064 m_constraintsInvolvedIn
->Append(otherWin
);
2067 // REMOVE back-pointer to other windows we're involved with.
2068 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2070 if (m_constraintsInvolvedIn
)
2071 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2074 // Reset any constraints that mention this window
2075 void wxWindow::DeleteRelatedConstraints(void)
2077 if (m_constraintsInvolvedIn
)
2079 wxNode
*node
= m_constraintsInvolvedIn
->First();
2082 wxWindow
*win
= (wxWindow
*)node
->Data();
2083 wxNode
*next
= node
->Next();
2084 wxLayoutConstraints
*constr
= win
->GetConstraints();
2086 // Reset any constraints involving this window
2089 constr
->left
.ResetIfWin((wxWindow
*)this);
2090 constr
->top
.ResetIfWin((wxWindow
*)this);
2091 constr
->right
.ResetIfWin((wxWindow
*)this);
2092 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2093 constr
->width
.ResetIfWin((wxWindow
*)this);
2094 constr
->height
.ResetIfWin((wxWindow
*)this);
2095 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2096 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2101 delete m_constraintsInvolvedIn
;
2102 m_constraintsInvolvedIn
= NULL
;
2106 void wxWindow::SetSizer(wxSizer
*sizer
)
2108 m_windowSizer
= sizer
;
2110 sizer
->SetSizerParent((wxWindow
*)this);
2117 bool wxWindow::Layout(void)
2119 if (GetConstraints())
2122 GetClientSize(&w
, &h
);
2123 GetConstraints()->width
.SetValue(w
);
2124 GetConstraints()->height
.SetValue(h
);
2127 // If top level (one sizer), evaluate the sizer's constraints.
2131 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2132 GetSizer()->LayoutPhase1(&noChanges
);
2133 GetSizer()->LayoutPhase2(&noChanges
);
2134 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2139 // Otherwise, evaluate child constraints
2140 ResetConstraints(); // Mark all constraints as unevaluated
2141 DoPhase(1); // Just one phase need if no sizers involved
2143 SetConstraintSizes(); // Recursively set the real window sizes
2149 // Do a phase of evaluating constraints:
2150 // the default behaviour. wxSizers may do a similar
2151 // thing, but also impose their own 'constraints'
2152 // and order the evaluation differently.
2153 bool wxWindow::LayoutPhase1(int *noChanges
)
2155 wxLayoutConstraints
*constr
= GetConstraints();
2158 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2164 bool wxWindow::LayoutPhase2(int *noChanges
)
2174 // Do a phase of evaluating child constraints
2175 bool wxWindow::DoPhase(int phase
)
2177 int noIterations
= 0;
2178 int maxIterations
= 500;
2182 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2186 wxNode
*node
= GetChildren()->First();
2189 wxWindow
*child
= (wxWindow
*)node
->Data();
2190 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2192 wxLayoutConstraints
*constr
= child
->GetConstraints();
2195 if (succeeded
.Member(child
))
2200 int tempNoChanges
= 0;
2201 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2202 noChanges
+= tempNoChanges
;
2205 succeeded
.Append(child
);
2210 node
= node
->Next();
2217 void wxWindow::ResetConstraints(void)
2219 wxLayoutConstraints
*constr
= GetConstraints();
2222 constr
->left
.SetDone(FALSE
);
2223 constr
->top
.SetDone(FALSE
);
2224 constr
->right
.SetDone(FALSE
);
2225 constr
->bottom
.SetDone(FALSE
);
2226 constr
->width
.SetDone(FALSE
);
2227 constr
->height
.SetDone(FALSE
);
2228 constr
->centreX
.SetDone(FALSE
);
2229 constr
->centreY
.SetDone(FALSE
);
2231 wxNode
*node
= GetChildren()->First();
2234 wxWindow
*win
= (wxWindow
*)node
->Data();
2235 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2236 win
->ResetConstraints();
2237 node
= node
->Next();
2241 // Need to distinguish between setting the 'fake' size for
2242 // windows and sizers, and setting the real values.
2243 void wxWindow::SetConstraintSizes(bool recurse
)
2245 wxLayoutConstraints
*constr
= GetConstraints();
2246 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2247 constr
->width
.GetDone() && constr
->height
.GetDone())
2249 int x
= constr
->left
.GetValue();
2250 int y
= constr
->top
.GetValue();
2251 int w
= constr
->width
.GetValue();
2252 int h
= constr
->height
.GetValue();
2254 // If we don't want to resize this window, just move it...
2255 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2256 (constr
->height
.GetRelationship() != wxAsIs
))
2258 // Calls Layout() recursively. AAAGH. How can we stop that.
2259 // Simply take Layout() out of non-top level OnSizes.
2260 SizerSetSize(x
, y
, w
, h
);
2269 char *windowClass
= this->GetClassInfo()->GetClassName();
2272 if (GetName() == "")
2273 winName
= "unnamed";
2275 winName
= GetName();
2276 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
2277 if (!constr
->left
.GetDone())
2278 wxDebugMsg(" unsatisfied 'left' constraint.\n");
2279 if (!constr
->right
.GetDone())
2280 wxDebugMsg(" unsatisfied 'right' constraint.\n");
2281 if (!constr
->width
.GetDone())
2282 wxDebugMsg(" unsatisfied 'width' constraint.\n");
2283 if (!constr
->height
.GetDone())
2284 wxDebugMsg(" unsatisfied 'height' constraint.\n");
2285 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
2290 wxNode
*node
= GetChildren()->First();
2293 wxWindow
*win
= (wxWindow
*)node
->Data();
2294 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2295 win
->SetConstraintSizes();
2296 node
= node
->Next();
2301 // This assumes that all sizers are 'on' the same
2302 // window, i.e. the parent of this window.
2303 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2305 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2306 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2310 m_sizerParent
->GetPosition(&xp
, &yp
);
2311 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2316 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2320 TransformSizerToActual(&xx
, &yy
);
2321 SetSize(xx
, yy
, w
, h
);
2324 void wxWindow::SizerMove(int x
, int y
)
2328 TransformSizerToActual(&xx
, &yy
);
2332 // Only set the size/position of the constraint (if any)
2333 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2335 wxLayoutConstraints
*constr
= GetConstraints();
2340 constr
->left
.SetValue(x
);
2341 constr
->left
.SetDone(TRUE
);
2345 constr
->top
.SetValue(y
);
2346 constr
->top
.SetDone(TRUE
);
2350 constr
->width
.SetValue(w
);
2351 constr
->width
.SetDone(TRUE
);
2355 constr
->height
.SetValue(h
);
2356 constr
->height
.SetDone(TRUE
);
2361 void wxWindow::MoveConstraint(int x
, int y
)
2363 wxLayoutConstraints
*constr
= GetConstraints();
2368 constr
->left
.SetValue(x
);
2369 constr
->left
.SetDone(TRUE
);
2373 constr
->top
.SetValue(y
);
2374 constr
->top
.SetDone(TRUE
);
2379 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2381 wxLayoutConstraints
*constr
= GetConstraints();
2384 *w
= constr
->width
.GetValue();
2385 *h
= constr
->height
.GetValue();
2391 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2393 wxLayoutConstraints
*constr
= GetConstraints();
2396 *w
= constr
->width
.GetValue();
2397 *h
= constr
->height
.GetValue();
2400 GetClientSize(w
, h
);
2403 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2405 wxLayoutConstraints
*constr
= GetConstraints();
2408 *x
= constr
->left
.GetValue();
2409 *y
= constr
->top
.GetValue();
2415 bool wxWindow::AcceptsFocus() const
2417 return IsEnabled() && IsShown();