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 "wx/statusbr.h"
30 //#include "wx/treectrl.h"
31 #include "gdk/gdkkeysyms.h"
33 #include "wx/gtk/win_gtk.h"
34 #include "gdk/gdkprivate.h"
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 extern wxList wxPendingDelete
;
41 extern wxList wxTopLevelWindows
;
42 extern bool g_blockEventsOnDrag
;
44 //-----------------------------------------------------------------------------
45 // GTK callbacks for wxWindows event system
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
49 // expose (of m_wxwindow, not of m_widget)
51 void gtk_window_expose_callback( GtkWidget
*WXUNUSED(widget
), GdkEventExpose
*gdk_event
, wxWindow
*win
)
53 if (!win
->HasVMT()) return;
54 if (g_blockEventsOnDrag
) return;
57 if (IS_KIND_OF(win,wxTreeCtrl))
59 printf( "OnExpose from " );
60 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
61 printf( win->GetClassInfo()->GetClassName() );
64 printf( "x: %d \n", gdk_event->area.x );
65 printf( "y: %d \n", gdk_event->area.y );
66 printf( "w: %d \n", gdk_event->area.width );
67 printf( "h: %d \n", gdk_event->area.height );
71 win
->m_updateRegion
.Union( gdk_event
->area
.x
,
73 gdk_event
->area
.width
,
74 gdk_event
->area
.height
);
76 if (gdk_event
->count
> 0) return;
78 wxPaintEvent
event( win
->GetId() );
79 event
.SetEventObject( win
);
80 win
->ProcessEvent( event
);
82 win
->m_updateRegion
.Clear();
85 //-----------------------------------------------------------------------------
86 // draw (of m_wxwindow, not of m_widget)
88 void gtk_window_draw_callback( GtkWidget
*WXUNUSED(widget
), GdkRectangle
*rect
, wxWindow
*win
)
90 if (!win
->HasVMT()) return;
91 if (g_blockEventsOnDrag
) return;
94 printf( "OnDraw from " );
95 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
96 printf( win->GetClassInfo()->GetClassName() );
99 printf( "x: %d \n", rect->x );
100 printf( "y: %d \n", rect->y );
101 printf( "w: %d \n", rect->width );
102 printf( "h: %d \n", rect->height );
105 win
->m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
107 wxPaintEvent
event( win
->GetId() );
108 event
.SetEventObject( win
);
109 win
->ProcessEvent( event
);
111 win
->m_updateRegion
.Clear();
114 //-----------------------------------------------------------------------------
116 // I don't any longer intercept GTK's internal resize events, except
117 // for frames and from within MDI and tabbed windows (client area
118 // size determined internally by GTK, not wxWin).
121 void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
123 if (!win->HasVMT()) return;
124 if (g_blockEventsOnDrag) return;
128 if ((win->m_x == alloc->x) &&
129 (win->m_y == alloc->y) &&
130 (win->m_width == alloc->width) &&
131 (win->m_height == alloc->height))
136 printf( "OnResize from " );
137 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
138 printf( win->GetClassInfo()->GetClassName() );
141 printf( " Old: X: %d Y: %d ", win->m_x, win->m_y );
142 printf( " W: %d H: %d ", win->m_width, win->m_height );
145 printf( " New: X: %d Y: %d ", alloc->x, alloc->y );
146 printf( " W: %d H: %d ", alloc->width, alloc->height );
149 wxSizeEvent event( wxSize( alloc->width, alloc->height), win->GetId() );
150 event.SetEventObject( win );
151 win->ProcessEvent( event );
155 //-----------------------------------------------------------------------------
158 gint
gtk_window_key_press_callback( GtkWidget
*WXUNUSED(widget
), GdkEventKey
*gdk_event
, wxWindow
*win
)
160 if (!win
->HasVMT()) return FALSE
;
161 if (g_blockEventsOnDrag
) return FALSE
;
164 printf( "OnKeyPress from " );
165 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
166 printf( win->GetClassInfo()->GetClassName() );
171 switch (gdk_event
->keyval
)
173 case GDK_BackSpace
: key_code
= WXK_BACK
; break;
174 case GDK_Tab
: key_code
= WXK_TAB
; break;
175 case GDK_Linefeed
: key_code
= WXK_RETURN
; break;
176 case GDK_Clear
: key_code
= WXK_CLEAR
; break;
177 case GDK_Return
: key_code
= WXK_RETURN
; break;
178 case GDK_Pause
: key_code
= WXK_PAUSE
; break;
179 case GDK_Scroll_Lock
: key_code
= WXK_SCROLL
; break;
180 case GDK_Escape
: key_code
= WXK_ESCAPE
; break;
181 case GDK_Delete
: key_code
= WXK_DELETE
; break;
182 case GDK_Home
: key_code
= WXK_HOME
; break;
183 case GDK_Left
: key_code
= WXK_LEFT
; break;
184 case GDK_Up
: key_code
= WXK_UP
; break;
185 case GDK_Right
: key_code
= WXK_RIGHT
; break;
186 case GDK_Down
: key_code
= WXK_DOWN
; break;
187 case GDK_Prior
: key_code
= WXK_PRIOR
; break;
188 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
189 case GDK_Next
: key_code
= WXK_NEXT
; break;
190 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
191 case GDK_End
: key_code
= WXK_END
; break;
192 case GDK_Begin
: key_code
= WXK_HOME
; break;
193 case GDK_Select
: key_code
= WXK_SELECT
; break;
194 case GDK_Print
: key_code
= WXK_PRINT
; break;
195 case GDK_Execute
: key_code
= WXK_EXECUTE
; break;
196 case GDK_Insert
: key_code
= WXK_INSERT
; break;
197 case GDK_Num_Lock
: key_code
= WXK_NUMLOCK
; break;
198 case GDK_KP_Tab
: key_code
= WXK_TAB
; break;
199 case GDK_KP_Enter
: key_code
= WXK_RETURN
; break;
200 case GDK_KP_Home
: key_code
= WXK_HOME
; break;
201 case GDK_KP_Left
: key_code
= WXK_LEFT
; break;
202 case GDK_KP_Up
: key_code
= WXK_UP
; break;
203 case GDK_KP_Right
: key_code
= WXK_RIGHT
; break;
204 case GDK_KP_Down
: key_code
= WXK_DOWN
; break;
205 case GDK_KP_Prior
: key_code
= WXK_PRIOR
; break;
206 // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
207 case GDK_KP_Next
: key_code
= WXK_NEXT
; break;
208 // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
209 case GDK_KP_End
: key_code
= WXK_END
; break;
210 case GDK_KP_Begin
: key_code
= WXK_HOME
; break;
211 case GDK_KP_Insert
: key_code
= WXK_INSERT
; break;
212 case GDK_KP_Delete
: key_code
= WXK_DELETE
; break;
213 case GDK_KP_Multiply
: key_code
= WXK_MULTIPLY
; break;
214 case GDK_KP_Add
: key_code
= WXK_ADD
; break;
215 case GDK_KP_Separator
: key_code
= WXK_SEPARATOR
; break;
216 case GDK_KP_Subtract
: key_code
= WXK_SUBTRACT
; break;
217 case GDK_KP_Decimal
: key_code
= WXK_DECIMAL
; break;
218 case GDK_KP_Divide
: key_code
= WXK_DIVIDE
; break;
219 case GDK_KP_0
: key_code
= WXK_NUMPAD0
; break;
220 case GDK_KP_1
: key_code
= WXK_NUMPAD1
; break;
221 case GDK_KP_2
: key_code
= WXK_NUMPAD2
; break;
222 case GDK_KP_3
: key_code
= WXK_NUMPAD3
; break;
223 case GDK_KP_4
: key_code
= WXK_NUMPAD4
; break;
224 case GDK_KP_5
: key_code
= WXK_NUMPAD5
; break;
225 case GDK_KP_6
: key_code
= WXK_NUMPAD6
; break;
226 case GDK_KP_7
: key_code
= WXK_NUMPAD7
; break;
227 case GDK_KP_8
: key_code
= WXK_NUMPAD7
; break;
228 case GDK_KP_9
: key_code
= WXK_NUMPAD9
; break;
229 case GDK_F1
: key_code
= WXK_F1
; break;
230 case GDK_F2
: key_code
= WXK_F2
; break;
231 case GDK_F3
: key_code
= WXK_F3
; break;
232 case GDK_F4
: key_code
= WXK_F4
; break;
233 case GDK_F5
: key_code
= WXK_F5
; break;
234 case GDK_F6
: key_code
= WXK_F6
; break;
235 case GDK_F7
: key_code
= WXK_F7
; break;
236 case GDK_F8
: key_code
= WXK_F8
; break;
237 case GDK_F9
: key_code
= WXK_F9
; break;
238 case GDK_F10
: key_code
= WXK_F10
; break;
239 case GDK_F11
: key_code
= WXK_F11
; break;
240 case GDK_F12
: key_code
= WXK_F12
; break;
243 if ((gdk_event
->keyval
>= 0x20) && (gdk_event
->keyval
<= 0xFF))
244 key_code
= gdk_event
->keyval
;
248 if (!key_code
) return FALSE
;
250 wxKeyEvent
event( wxEVT_CHAR
);
251 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
252 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
253 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
254 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
255 event
.m_keyCode
= key_code
;
258 event
.SetEventObject( win
);
259 return win
->ProcessEvent( event
);
262 //-----------------------------------------------------------------------------
265 gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
267 if (widget
->window
!= gdk_event
->window
) return TRUE
;
268 if (g_blockEventsOnDrag
) return TRUE
;
272 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
) && !GTK_WIDGET_HAS_FOCUS (win
->m_wxwindow
) )
274 gtk_widget_grab_focus (win
->m_wxwindow
);
277 printf( "GrabFocus from " );
278 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
279 printf( win->GetClassInfo()->GetClassName() );
286 if (!win
->HasVMT()) return TRUE
;
289 printf( "OnButtonPress from " );
290 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
291 printf( win->GetClassInfo()->GetClassName() );
295 wxEventType event_type
= wxEVT_LEFT_DOWN
;
297 if (gdk_event
->button
== 1)
299 switch (gdk_event
->type
)
301 case GDK_BUTTON_PRESS
: event_type
= wxEVT_LEFT_DOWN
; break;
302 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_LEFT_DCLICK
; break;
306 else if (gdk_event
->button
== 2)
308 switch (gdk_event
->type
)
310 case GDK_BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DOWN
; break;
311 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DCLICK
; break;
315 else if (gdk_event
->button
== 3)
317 switch (gdk_event
->type
)
319 case GDK_BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DOWN
; break;
320 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DCLICK
; break;
325 wxMouseEvent
event( event_type
);
326 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
327 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
328 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
329 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
330 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
331 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
332 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
334 event
.m_x
= (long)gdk_event
->x
;
335 event
.m_y
= (long)gdk_event
->y
;
336 event
.SetEventObject( win
);
338 win
->ProcessEvent( event
);
343 //-----------------------------------------------------------------------------
346 gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
348 if (widget
->window
!= gdk_event
->window
) return TRUE
;
350 if (g_blockEventsOnDrag
) return TRUE
;
352 if (!win
->HasVMT()) return TRUE
;
355 printf( "OnButtonRelease from " );
356 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
357 printf( win->GetClassInfo()->GetClassName() );
361 wxEventType event_type
= wxEVT_NULL
;
363 switch (gdk_event
->button
)
365 case 1: event_type
= wxEVT_LEFT_UP
; break;
366 case 2: event_type
= wxEVT_MIDDLE_UP
; break;
367 case 3: event_type
= wxEVT_RIGHT_UP
; break;
370 wxMouseEvent
event( event_type
);
371 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
372 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
373 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
374 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
375 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
376 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
377 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
378 event
.m_x
= (long)gdk_event
->x
;
379 event
.m_y
= (long)gdk_event
->y
;
380 event
.SetEventObject( win
);
382 win
->ProcessEvent( event
);
387 //-----------------------------------------------------------------------------
390 gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxWindow
*win
)
392 if (widget
->window
!= gdk_event
->window
) return TRUE
;
394 if (g_blockEventsOnDrag
) return TRUE
;
396 if (!win
->HasVMT()) return TRUE
;
399 printf( "OnMotion from " );
400 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
401 printf( win->GetClassInfo()->GetClassName() );
405 wxMouseEvent
event( wxEVT_MOTION
);
406 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
407 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
408 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
409 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
410 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
411 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
412 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
414 event
.m_x
= (long)gdk_event
->x
;
415 event
.m_y
= (long)gdk_event
->y
;
416 event
.SetEventObject( win
);
418 win
->ProcessEvent( event
);
423 //-----------------------------------------------------------------------------
426 gint
gtk_window_focus_in_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
428 if (g_blockEventsOnDrag
) return TRUE
;
431 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
433 GTK_WIDGET_SET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
435 printf( "SetFocus flag from " );
436 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
437 printf( win->GetClassInfo()->GetClassName() );
443 if (!win
->HasVMT()) return TRUE
;
446 printf( "OnSetFocus from " );
447 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
448 printf( win->GetClassInfo()->GetClassName() );
450 printf( WXSTRINGCAST win->GetLabel() );
454 wxFocusEvent
event( wxEVT_SET_FOCUS
, win
->GetId() );
455 event
.SetEventObject( win
);
456 win
->ProcessEvent( event
);
461 //-----------------------------------------------------------------------------
464 gint
gtk_window_focus_out_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
466 if (g_blockEventsOnDrag
) return TRUE
;
469 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
470 GTK_WIDGET_UNSET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
473 if (!win
->HasVMT()) return TRUE
;
476 printf( "OnKillFocus from " );
477 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
478 printf( win->GetClassInfo()->GetClassName() );
482 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
483 event
.SetEventObject( win
);
484 win
->ProcessEvent( event
);
489 //-----------------------------------------------------------------------------
492 void gtk_window_vscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
494 if (g_blockEventsOnDrag
) return;
497 printf( "OnVScroll from " );
498 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
499 printf( win->GetClassInfo()->GetClassName() );
503 if (!win
->HasVMT()) return;
505 float diff
= win
->m_vAdjust
->value
- win
->m_oldVerticalPos
;
506 if (fabs(diff
) < 0.2) return;
509 int i = (int)(win->m_oldVerticalPos+0.5);
510 printf( "Old value: %d.\n", i );
511 i = (int)(win->m_vAdjust->value+0.5);
512 printf( "Sending new value: %d.\n", i );
515 wxEventType command
= wxEVT_NULL
;
517 float line_step
= win
->m_vAdjust
->step_increment
;
518 float page_step
= win
->m_vAdjust
->page_increment
;
520 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
521 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
522 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
523 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
524 else command
= wxEVT_SCROLL_THUMBTRACK
;
526 int value
= (int)(win
->m_vAdjust
->value
+0.5);
528 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
529 event
.SetEventObject( win
);
530 win
->ProcessEvent( event
);
533 //-----------------------------------------------------------------------------
536 void gtk_window_hscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
538 if (g_blockEventsOnDrag
) return;
541 printf( "OnHScroll from " );
542 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
543 printf( win->GetClassInfo()->GetClassName() );
547 if (!win
->HasVMT()) return;
549 float diff
= win
->m_hAdjust
->value
- win
->m_oldHorizontalPos
;
550 if (fabs(diff
) < 0.2) return;
553 int i = (int)(win->m_oldHorizontalPos+0.5);
554 printf( "Old value: %d.\n", i );
555 i = (int)(win->m_hAdjust->value+0.5);
556 printf( "Sending new value: %d.\n", i );
559 wxEventType command
= wxEVT_NULL
;
561 float line_step
= win
->m_hAdjust
->step_increment
;
562 float page_step
= win
->m_hAdjust
->page_increment
;
564 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
565 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
566 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
567 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
568 else command
= wxEVT_SCROLL_THUMBTRACK
;
570 int value
= (int)(win
->m_hAdjust
->value
+0.5);
572 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
573 event
.SetEventObject( win
);
574 win
->ProcessEvent( event
);
577 //-----------------------------------------------------------------------------
578 // vertical scroll change
580 void gtk_window_vscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
582 if (g_blockEventsOnDrag
) return;
585 printf( "OnVScroll change from " );
586 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
587 printf( win->GetClassInfo()->GetClassName() );
591 if (!win
->HasVMT()) return;
593 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
594 int value
= (int)(win
->m_vAdjust
->value
+0.5);
596 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
597 event
.SetEventObject( win
);
598 win
->ProcessEvent( event
);
601 //-----------------------------------------------------------------------------
602 // horizontal scroll change
604 void gtk_window_hscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
606 if (g_blockEventsOnDrag
) return;
609 printf( "OnHScroll change from " );
610 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
611 printf( win->GetClassInfo()->GetClassName() );
615 if (!win
->HasVMT()) return;
617 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
618 int value
= (int)(win
->m_hAdjust
->value
+0.5);
620 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
621 event
.SetEventObject( win
);
622 win
->ProcessEvent( event
);
625 //-----------------------------------------------------------------------------
628 void gtk_window_drop_callback( GtkWidget
*widget
, GdkEvent
*event
, wxWindow
*win
)
630 if (win
->GetDropTarget())
634 gdk_window_get_pointer( widget
->window
, &x
, &y
, NULL
);
635 win
->GetDropTarget()->Drop( event
, x
, y
);
639 g_free (event->dropdataavailable.data);
640 g_free (event->dropdataavailable.data_type);
644 //-----------------------------------------------------------------------------
647 bool gtk_window_destroy_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
649 printf( "OnDestroy from " );
650 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
651 printf( win
->GetClassInfo()->GetClassName() );
653 printf( "Goodbye.\n" );
654 printf( " Robert Roebling.\n" );
659 //-----------------------------------------------------------------------------
662 bool gtk_window_enter_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
664 if (widget
->window
!= gdk_event
->window
) return TRUE
;
666 if (g_blockEventsOnDrag
) return FALSE
;
669 gdk_window_set_cursor( widget
->window
, win
->m_cursor
->GetCursor() );
671 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
672 event
.SetEventObject( win
);
673 return win
->ProcessEvent( event
);
676 //-----------------------------------------------------------------------------
679 bool gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
681 if (widget
->window
!= gdk_event
->window
) return TRUE
;
683 if (g_blockEventsOnDrag
) return FALSE
;
686 gdk_window_set_cursor( widget
->window
, wxSTANDARD_CURSOR
->GetCursor() );
688 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
689 event
.SetEventObject( win
);
690 return win
->ProcessEvent( event
);
693 //-----------------------------------------------------------------------------
694 // wxWindow implementation
695 //-----------------------------------------------------------------------------
697 IMPLEMENT_DYNAMIC_CLASS(wxWindow
,wxEvtHandler
)
699 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
700 EVT_SIZE(wxWindow::OnSize
)
701 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
702 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
703 EVT_IDLE(wxWindow::OnIdle
)
711 m_children
.DeleteContents( FALSE
);
717 m_eventHandler
= this;
718 m_windowValidator
= NULL
;
720 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
721 m_font
= *wxSWISS_FONT
;
723 m_windowName
= "noname";
724 m_constraints
= NULL
;
725 m_constraintsInvolvedIn
= NULL
;
726 m_windowSizer
= NULL
;
727 m_sizerParent
= NULL
;
728 m_autoLayout
= FALSE
;
732 m_hasScrolling
= FALSE
;
735 m_oldHorizontalPos
= 0.0;
736 m_oldVerticalPos
= 0.0;
739 m_drawingOffsetX
= 0;
740 m_drawingOffsetY
= 0;
741 m_pDropTarget
= NULL
;
745 wxWindow::wxWindow( wxWindow
*parent
, wxWindowID id
,
746 const wxPoint
&pos
, const wxSize
&size
,
747 long style
, const wxString
&name
)
749 Create( parent
, id
, pos
, size
, style
, name
);
752 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
753 const wxPoint
&pos
, const wxSize
&size
,
754 long style
, const wxString
&name
)
760 PreCreation( parent
, id
, pos
, size
, style
, name
);
762 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
763 m_hasScrolling
= TRUE
;
765 GtkScrolledWindow
*s_window
;
766 s_window
= GTK_SCROLLED_WINDOW(m_widget
);
768 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
769 scroll_class
->scrollbar_spacing
= 0;
771 gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
773 m_oldHorizontalPos
= 0.0;
774 m_oldVerticalPos
= 0.0;
776 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) );
777 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) );
779 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "value_changed",
780 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
781 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "value_changed",
782 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
784 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "changed",
785 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
786 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "changed",
787 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
789 GtkViewport
*viewport
;
790 viewport
= GTK_VIEWPORT(s_window
->viewport
);
792 if (m_windowStyle
& wxRAISED_BORDER
)
794 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
796 else if (m_windowStyle
& wxSUNKEN_BORDER
)
798 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
802 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
805 m_wxwindow
= gtk_myfixed_new();
807 if (m_windowStyle
& wxTAB_TRAVERSAL
== wxTAB_TRAVERSAL
)
808 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
810 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
812 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
814 // shut the viewport up
815 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
816 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
818 // I _really_ don't want scrollbars in the beginning
819 m_vAdjust
->lower
= 0.0;
820 m_vAdjust
->upper
= 1.0;
821 m_vAdjust
->value
= 0.0;
822 m_vAdjust
->step_increment
= 1.0;
823 m_vAdjust
->page_increment
= 1.0;
824 m_vAdjust
->page_size
= 5.0;
825 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
826 m_hAdjust
->lower
= 0.0;
827 m_hAdjust
->upper
= 1.0;
828 m_hAdjust
->value
= 0.0;
829 m_hAdjust
->step_increment
= 1.0;
830 m_hAdjust
->page_increment
= 1.0;
831 m_hAdjust
->page_size
= 5.0;
832 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
834 gtk_widget_show( m_wxwindow
);
843 wxWindow::~wxWindow(void)
847 if (m_pDropTarget
) delete m_pDropTarget
;
849 if (m_parent
) m_parent
->RemoveChild( this );
850 if (m_widget
) Show( FALSE
);
854 if (m_wxwindow
) gtk_widget_destroy( m_wxwindow
);
856 if (m_widget
) gtk_widget_destroy( m_widget
);
860 DeleteRelatedConstraints();
863 // This removes any dangling pointers to this window
864 // in other windows' constraintsInvolvedIn lists.
865 UnsetConstraints(m_constraints
);
866 delete m_constraints
;
867 m_constraints
= NULL
;
871 delete m_windowSizer
;
872 m_windowSizer
= NULL
;
874 // If this is a child of a sizer, remove self from parent
876 m_sizerParent
->RemoveChild((wxWindow
*)this);
878 // Just in case the window has been Closed, but
879 // we're then deleting immediately: don't leave
880 // dangling pointers.
881 wxPendingDelete
.DeleteObject(this);
883 // Just in case we've loaded a top-level window via
884 // wxWindow::LoadNativeDialog but we weren't a dialog
886 wxTopLevelWindows
.DeleteObject(this);
890 void wxWindow::PreCreation( wxWindow
*parent
, wxWindowID id
,
891 const wxPoint
&pos
, const wxSize
&size
,
892 long style
, const wxString
&name
)
894 if (m_needParent
&& (parent
== NULL
))
895 wxFatalError( "Need complete parent.", name
);
900 m_children
.DeleteContents( FALSE
);
904 if (m_width
== -1) m_width
= 20;
906 if (m_height
== -1) m_height
= 20;
908 m_eventHandler
= this;
909 m_windowValidator
= NULL
;
912 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
913 m_font
= *wxSWISS_FONT
;
914 m_backgroundColour
= wxWHITE
;
915 m_foregroundColour
= wxBLACK
;
916 m_windowStyle
= style
;
918 m_constraints
= NULL
;
919 m_constraintsInvolvedIn
= NULL
;
920 m_windowSizer
= NULL
;
921 m_sizerParent
= NULL
;
922 m_autoLayout
= FALSE
;
923 m_drawingOffsetX
= 0;
924 m_drawingOffsetY
= 0;
925 m_pDropTarget
= NULL
;
929 void wxWindow::PostCreation(void)
931 if (m_parent
) m_parent
->AddChild( this );
933 // GtkStyle *style = m_widget->style;
934 // style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
936 GtkWidget
*connect_widget
= m_widget
;
937 if (m_wxwindow
) connect_widget
= m_wxwindow
;
939 gtk_object_set_data (GTK_OBJECT (connect_widget
), "MyWxWindow", (gpointer
)this );
943 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
944 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
946 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
947 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
951 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
952 GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this );
955 gtk_signal_connect( GTK_OBJECT(connect_widget
), "key_press_event",
956 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
958 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_press_event",
959 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
961 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_release_event",
962 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
964 gtk_signal_connect( GTK_OBJECT(connect_widget
), "motion_notify_event",
965 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
967 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_in_event",
968 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
970 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_out_event",
971 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
973 // Only for cursor handling
975 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter_notify_event",
976 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
978 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave_notify_event",
979 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
983 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "enter_notify_event",
984 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
986 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "leave_notify_event",
987 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
991 // Does destroy ever get called ?
993 gtk_signal_connect( GTK_OBJECT(m_widget), "destroy_event",
994 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
998 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "destroy_event",
999 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1003 if (m_widget
&& m_parent
) gtk_widget_realize( m_widget
);
1004 if (m_wxwindow
) gtk_widget_realize( m_wxwindow
);
1006 SetCursor( wxSTANDARD_CURSOR
);
1011 bool wxWindow::HasVMT(void)
1016 bool wxWindow::Close( bool force
)
1018 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1019 event
.SetEventObject(this);
1020 event
.SetForce(force
);
1022 return GetEventHandler()->ProcessEvent(event
);
1025 bool wxWindow::Destroy(void)
1032 bool wxWindow::DestroyChildren(void)
1037 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
)
1040 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
)
1043 if (GetChildren()->Member(child
)) delete node
;
1050 void wxWindow::PrepareDC( wxDC
&WXUNUSED(dc
) )
1052 // are we to set fonts here ?
1055 void wxWindow::ImplementSetSize(void)
1057 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1060 void wxWindow::ImplementSetPosition(void)
1064 if (IsKindOf(CLASSINFO(wxFrame
)) ||
1065 IsKindOf(CLASSINFO(wxDialog
)))
1067 if ((m_x
!= -1) || (m_y
!= -1))
1068 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1072 printf( "wxWindow::SetSize error.\n" );
1077 if ((m_parent
) && (m_parent
->m_wxwindow
))
1078 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1080 // Don't do anything for children of wxNotebook and wxMDIChildFrame
1083 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1085 if (m_resizing
) return; // I don't like recursions
1093 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1095 if (newX
== -1) newX
= m_x
;
1096 if (newY
== -1) newY
= m_y
;
1097 if (newW
== -1) newW
= m_width
;
1098 if (newH
== -1) newH
= m_height
;
1101 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1103 if (newW
== -1) newW
= 80;
1106 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1108 if (newH
== -1) newH
= 26;
1111 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1115 ImplementSetPosition();
1117 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1125 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1126 event
.SetEventObject( this );
1127 ProcessEvent( event
);
1132 void wxWindow::SetSize( int width
, int height
)
1134 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1137 void wxWindow::Move( int x
, int y
)
1139 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1142 void wxWindow::GetSize( int *width
, int *height
) const
1144 if (width
) (*width
) = m_width
;
1145 if (height
) (*height
) = m_height
;
1148 void wxWindow::SetClientSize( int width
, int height
)
1152 SetSize( width
, height
);
1159 if (!m_hasScrolling
)
1162 do we have sunken dialogs ?
1164 GtkStyleClass *window_class = m_wxwindow->style->klass;
1166 dw += 2 * window_class->xthickness;
1167 dh += 2 * window_class->ythickness;
1172 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1173 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1175 GtkWidget
*viewport
= scroll_window
->viewport
;
1176 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1178 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1179 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1181 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1182 (m_windowStyle
& wxSUNKEN_BORDER
)
1185 dw
+= 2 * viewport_class
->xthickness
;
1186 dh
+= 2 * viewport_class
->ythickness
;
1189 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1191 dw
+= vscrollbar
->allocation
.width
;
1192 dw
+= scroll_class
->scrollbar_spacing
;
1195 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1197 dh
+= hscrollbar
->allocation
.height
;
1198 dw
+= scroll_class
->scrollbar_spacing
;
1202 SetSize( width
+dw
, height
+dh
);
1206 void wxWindow::GetClientSize( int *width
, int *height
) const
1210 if (width
) (*width
) = m_width
;
1211 if (height
) (*height
) = m_height
;
1218 if (!m_hasScrolling
)
1221 do we have sunken dialogs ?
1223 GtkStyleClass *window_class = m_wxwindow->style->klass;
1225 dw += 2 * window_class->xthickness;
1226 dh += 2 * window_class->ythickness;
1231 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1232 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1234 GtkWidget
*viewport
= scroll_window
->viewport
;
1235 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1237 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1238 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1240 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1241 (m_windowStyle
& wxSUNKEN_BORDER
)
1244 dw
+= 2 * viewport_class
->xthickness
;
1245 dh
+= 2 * viewport_class
->ythickness
;
1248 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1250 // dw += vscrollbar->allocation.width;
1251 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1252 dw
+= scroll_class
->scrollbar_spacing
;
1255 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1257 // dh += hscrollbar->allocation.height;
1259 dh
+= scroll_class
->scrollbar_spacing
;
1263 if (width
) (*width
) = m_width
- dw
;
1264 if (height
) (*height
) = m_height
- dh
;
1268 void wxWindow::GetPosition( int *x
, int *y
) const
1274 void wxWindow::ClientToScreen( int *x
, int *y
)
1276 // Does this look simple ?
1278 GdkWindow
*source
= NULL
;
1280 source
= m_wxwindow
->window
;
1282 source
= m_widget
->window
;
1286 gdk_window_get_origin( source
, &org_x
, &org_y
);
1290 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1292 org_x
+= m_widget
->allocation
.x
;
1293 org_y
+= m_widget
->allocation
.y
;
1301 void wxWindow::ScreenToClient( int *x
, int *y
)
1303 GdkWindow
*source
= NULL
;
1305 source
= m_wxwindow
->window
;
1307 source
= m_widget
->window
;
1311 gdk_window_get_origin( source
, &org_x
, &org_y
);
1315 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1317 org_x
+= m_widget
->allocation
.x
;
1318 org_y
+= m_widget
->allocation
.y
;
1326 void wxWindow::Centre( int direction
)
1328 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1330 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
1331 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
1332 ImplementSetPosition();
1340 m_parent
->GetSize( &p_w
, &p_h
);
1341 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (p_w
- m_width
) / 2;
1342 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (p_h
- m_height
) / 2;
1343 ImplementSetPosition();
1348 void wxWindow::Fit(void)
1352 wxNode
*node
= GetChildren()->First();
1355 wxWindow
*win
= (wxWindow
*)node
->Data();
1357 win
->GetPosition(&wx
, &wy
);
1358 win
->GetSize(&ww
, &wh
);
1359 if ( wx
+ ww
> maxX
)
1361 if ( wy
+ wh
> maxY
)
1364 node
= node
->Next();
1366 SetClientSize(maxX
+ 5, maxY
+ 10);
1369 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1371 //if (GetAutoLayout()) Layout();
1374 bool wxWindow::Show( bool show
)
1377 gtk_widget_show( m_widget
);
1379 gtk_widget_hide( m_widget
);
1384 void wxWindow::Enable( bool enable
)
1386 m_isEnabled
= enable
;
1387 gtk_widget_set_sensitive( m_widget
, enable
);
1388 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1391 void wxWindow::MakeModal( bool modal
)
1394 // Disable all other windows
1395 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1397 wxNode
*node
= wxTopLevelWindows
.First();
1400 wxWindow
*win
= (wxWindow
*)node
->Data();
1402 win
->Enable(!modal
);
1404 node
= node
->Next();
1409 void wxWindow::SetFocus(void)
1411 GtkWidget
*connect_widget
= m_widget
;
1412 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1415 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1417 gtk_widget_grab_focus (connect_widget
);
1422 bool wxWindow::OnClose(void)
1427 void wxWindow::AddChild( wxWindow
*child
)
1429 // Addchild is (often) called before the program
1430 // has left the parents constructor so that no
1431 // virtual tables work yet. The approach below
1432 // practically imitates virtual tables, i.e. it
1433 // implements a different AddChild() behaviour
1434 // for wxFrame, wxDialog, wxWindow and
1435 // wxMDIParentFrame.
1437 // wxFrame and wxDialog as children aren't placed into the parents
1439 if (( IS_KIND_OF(child
,wxFrame
) || IS_KIND_OF(child
,wxDialog
) ) &&
1440 (!IS_KIND_OF(child
,wxMDIChildFrame
)))
1442 m_children
.Append( child
);
1444 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1445 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1450 // In the case of an wxMDIChildFrame descendant, we use the
1451 // client windows's AddChild()
1453 if (IS_KIND_OF(this,wxMDIParentFrame
))
1455 if (IS_KIND_OF(child
,wxMDIChildFrame
))
1457 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1460 client
->AddChild( child
);
1466 // wxNotebook is very special, so it has a private AddChild()
1468 if (IS_KIND_OF(this,wxNotebook
))
1470 wxNotebook
*tab
= (wxNotebook
*)this;
1471 tab
->AddChild( child
);
1475 // wxFrame has a private AddChild
1477 if (IS_KIND_OF(this,wxFrame
) && !IS_KIND_OF(this,wxMDIChildFrame
))
1479 wxFrame
*frame
= (wxFrame
*)this;
1480 frame
->AddChild( child
);
1486 m_children
.Append( child
);
1487 if (m_wxwindow
) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
,
1488 child
->m_x
, child
->m_y
);
1490 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1493 wxList
*wxWindow::GetChildren(void)
1495 return (&m_children
);
1498 void wxWindow::RemoveChild( wxWindow
*child
)
1501 GetChildren()->DeleteObject( child
);
1502 child
->m_parent
= NULL
;
1505 void wxWindow::SetReturnCode( int retCode
)
1507 m_retCode
= retCode
;
1510 int wxWindow::GetReturnCode(void)
1515 wxWindow
*wxWindow::GetParent(void)
1520 wxEvtHandler
*wxWindow::GetEventHandler(void)
1522 return m_eventHandler
;
1525 void wxWindow::SetEventhandler( wxEvtHandler
*handler
)
1527 m_eventHandler
= handler
;
1530 wxValidator
*wxWindow::GetValidator(void)
1532 return m_windowValidator
;
1535 void wxWindow::SetValidator( wxValidator
*validator
)
1537 m_windowValidator
= validator
;
1540 bool wxWindow::IsBeingDeleted(void)
1545 void wxWindow::SetId( wxWindowID id
)
1550 wxWindowID
wxWindow::GetId(void)
1555 void wxWindow::SetCursor( const wxCursor
&cursor
)
1557 if (*m_cursor
== cursor
) return;
1558 (*m_cursor
) = cursor
;
1559 if (m_widget
->window
)
1560 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1561 if (m_wxwindow
&& m_wxwindow
->window
)
1562 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1565 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1567 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1570 gdk_window_clear_area( m_wxwindow
->window
,
1582 wxClientDC
dc(this);
1586 dc
.GetInternalDeviceOrigin( &x
, &y
);
1590 GetClientSize( &w
, &h
);
1592 GdkRectangle gdk_rect
;
1596 gdk_rect
.height
= h
;
1597 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1602 GdkRectangle gdk_rect
;
1603 gdk_rect
.x
= rect
->x
;
1604 gdk_rect
.y
= rect
->y
;
1605 gdk_rect
.width
= rect
->width
;
1606 gdk_rect
.height
= rect
->height
;
1609 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1611 gtk_widget_draw( m_widget
, &gdk_rect
);
1615 bool wxWindow::IsExposed( long x
, long y
)
1617 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1620 bool wxWindow::IsExposed( long x
, long y
, long width
, long height
)
1622 return (m_updateRegion
.Contains( x
, y
, width
, height
) != wxOutRegion
);
1625 void wxWindow::Clear(void)
1627 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1630 wxColour
wxWindow::GetBackgroundColour(void) const
1632 return m_backgroundColour
;
1635 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1637 m_backgroundColour
= colour
;
1640 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1641 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1642 gdk_window_clear( m_wxwindow
->window
);
1647 bool wxWindow::Validate(void)
1649 wxNode
*node
= GetChildren()->First();
1652 wxWindow
*child
= (wxWindow
*)node
->Data();
1653 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1655 node
= node
->Next();
1660 bool wxWindow::TransferDataToWindow(void)
1662 wxNode
*node
= GetChildren()->First();
1665 wxWindow
*child
= (wxWindow
*)node
->Data();
1666 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1667 !child
->GetValidator()->TransferToWindow() )
1669 wxMessageBox( "Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1672 node
= node
->Next();
1677 bool wxWindow::TransferDataFromWindow(void)
1679 wxNode
*node
= GetChildren()->First();
1682 wxWindow
*child
= (wxWindow
*)node
->Data();
1683 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1685 node
= node
->Next();
1690 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1692 TransferDataToWindow();
1695 void wxWindow::InitDialog(void)
1697 wxInitDialogEvent
event(GetId());
1698 event
.SetEventObject( this );
1699 GetEventHandler()->ProcessEvent(event
);
1702 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1704 GtkWidget
*dnd_widget
= GetDropTargetWidget();
1708 gtk_signal_disconnect_by_func( GTK_OBJECT(dnd_widget
),
1709 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1711 m_pDropTarget
->UnregisterWidget( dnd_widget
);
1712 delete m_pDropTarget
;
1714 m_pDropTarget
= dropTarget
;
1717 m_pDropTarget
->RegisterWidget( dnd_widget
);
1719 gtk_signal_connect( GTK_OBJECT(dnd_widget
), "drop_data_available_event",
1720 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1724 wxDropTarget
*wxWindow::GetDropTarget() const
1726 return m_pDropTarget
;
1729 GtkWidget
* wxWindow::GetDropTargetWidget(void)
1731 GtkWidget
*connect_widget
= m_widget
;
1732 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1734 return connect_widget
;
1737 void wxWindow::SetFont( const wxFont
&font
)
1742 copy old style values to new one
1743 set font in new style
1744 -> takes to many resources
1746 GtkStyle *style = gtk_style_new();
1751 wxFont
*wxWindow::GetFont(void)
1756 void wxWindow::SetWindowStyleFlag( long flag
)
1758 m_windowStyle
= flag
;
1761 long wxWindow::GetWindowStyleFlag(void) const
1763 return m_windowStyle
;
1766 void wxWindow::CaptureMouse(void)
1768 GtkWidget
*connect_widget
= m_widget
;
1769 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1770 gtk_grab_add( connect_widget
);
1771 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1773 (GDK_BUTTON_PRESS_MASK
|
1774 GDK_BUTTON_RELEASE_MASK
|
1775 GDK_POINTER_MOTION_MASK
),
1776 NULL
, NULL
, GDK_CURRENT_TIME
);
1779 void wxWindow::ReleaseMouse(void)
1781 GtkWidget
*connect_widget
= m_widget
;
1782 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1783 gtk_grab_remove( connect_widget
);
1784 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1787 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1791 wxString
wxWindow::GetTitle(void) const
1793 return (wxString
&)m_windowName
;
1796 wxString
wxWindow::GetLabel(void) const
1801 void wxWindow::SetName( const wxString
&name
)
1803 m_windowName
= name
;
1806 wxString
wxWindow::GetName(void) const
1808 return (wxString
&)m_windowName
;
1811 bool wxWindow::IsShown(void) const
1816 bool wxWindow::IsRetained(void)
1821 wxWindow
*wxWindow::FindWindow( long id
)
1823 if (id
== m_windowId
) return this;
1824 wxNode
*node
= m_children
.First();
1827 wxWindow
*child
= (wxWindow
*)node
->Data();
1828 wxWindow
*res
= child
->FindWindow( id
);
1829 if (res
) return res
;
1830 node
= node
->Next();
1835 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1837 if (name
== m_windowName
) return this;
1838 wxNode
*node
= m_children
.First();
1841 wxWindow
*child
= (wxWindow
*)node
->Data();
1842 wxWindow
*res
= child
->FindWindow( name
);
1843 if (res
) return res
;
1844 node
= node
->Next();
1849 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1850 int range
, bool WXUNUSED(refresh
) )
1852 if (!m_wxwindow
) return;
1854 if (orient
== wxHORIZONTAL
)
1856 float fpos
= (float)pos
;
1857 m_oldHorizontalPos
= fpos
;
1858 float frange
= (float)range
;
1859 float fthumb
= (float)thumbVisible
;
1861 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1862 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1863 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1866 m_hAdjust
->lower
= 0.0;
1867 m_hAdjust
->upper
= frange
;
1868 m_hAdjust
->value
= fpos
;
1869 m_hAdjust
->step_increment
= 1.0;
1870 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1871 m_hAdjust
->page_size
= fthumb
;
1875 float fpos
= (float)pos
;
1876 m_oldVerticalPos
= fpos
;
1877 float frange
= (float)range
;
1878 float fthumb
= (float)thumbVisible
;
1880 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1881 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1882 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1885 m_vAdjust
->lower
= 0.0;
1886 m_vAdjust
->upper
= frange
;
1887 m_vAdjust
->value
= fpos
;
1888 m_vAdjust
->step_increment
= 1.0;
1889 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1890 m_vAdjust
->page_size
= fthumb
;
1893 if (m_wxwindow
->window
)
1895 if (orient
== wxHORIZONTAL
)
1898 m_drawingOffsetX = -16000;
1900 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1902 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
1907 m_drawingOffsetY = -16000;
1909 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1911 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
1914 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1918 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
1920 if (!m_wxwindow
) return;
1922 if (orient
== wxHORIZONTAL
)
1924 float fpos
= (float)pos
;
1925 m_oldHorizontalPos
= fpos
;
1927 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
1928 m_hAdjust
->value
= fpos
;
1932 float fpos
= (float)pos
;
1933 m_oldVerticalPos
= fpos
;
1934 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
1935 m_vAdjust
->value
= fpos
;
1938 if (m_wxwindow
->window
)
1940 if (orient
== wxHORIZONTAL
)
1941 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
1943 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
1947 int wxWindow::GetScrollThumb( int orient
) const
1949 if (!m_wxwindow
) return 0;
1951 if (orient
== wxHORIZONTAL
)
1952 return (int)(m_hAdjust
->page_size
+0.5);
1954 return (int)(m_vAdjust
->page_size
+0.5);
1957 int wxWindow::GetScrollPos( int orient
) const
1959 if (!m_wxwindow
) return 0;
1961 if (orient
== wxHORIZONTAL
)
1962 return (int)(m_hAdjust
->value
+0.5);
1964 return (int)(m_vAdjust
->value
+0.5);
1967 int wxWindow::GetScrollRange( int orient
) const
1969 if (!m_wxwindow
) return 0;
1971 if (orient
== wxHORIZONTAL
)
1972 return (int)(m_hAdjust
->upper
+0.5);
1974 return (int)(m_vAdjust
->upper
+0.5);
1977 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
1979 if (!m_wxwindow
) return;
1981 bool refresh
= FALSE
;
1983 if ((m_drawingOffsetX
== 0) && (m_drawingOffsetY
== 0))
1985 m_drawingOffsetX
= -16000;
1986 m_drawingOffsetY
= -16000;
1991 m_drawingOffsetX
+= dx
;
1992 m_drawingOffsetY
+= dy
;
1995 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
1997 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow
), m_drawingOffsetX
, m_drawingOffsetY
);
1999 if (refresh
) Refresh();
2002 The code here is very nifty, but it doesn't work with
2003 overlapping windows...
2007 GetClientSize( &cw, &ch );
2009 int w = cw - abs(dx);
2010 int h = ch - abs(dy);
2011 if ((h < 0) || (w < 0))
2018 if (dx < 0) s_x = -dx;
2019 if (dy < 0) s_y = -dy;
2022 if (dx > 0) d_x = dx;
2023 if (dy > 0) d_y = dy;
2024 gdk_window_copy_area( m_wxwindow->window, m_wxwindow->style->fg_gc[0], d_x, d_y,
2025 m_wxwindow->window, s_x, s_y, w, h );
2028 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
2029 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
2030 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
2031 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
2033 Refresh( TRUE, &rect );
2037 void wxWindow::GetDrawingOffset( long *x
, long *y
)
2039 if (x
) *x
= m_drawingOffsetX
;
2040 if (y
) *y
= m_drawingOffsetY
;
2043 //-------------------------------------------------------------------------------------
2045 //-------------------------------------------------------------------------------------
2047 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
2049 return m_constraints
;
2052 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
2056 UnsetConstraints(m_constraints
);
2057 delete m_constraints
;
2059 m_constraints
= constraints
;
2062 // Make sure other windows know they're part of a 'meaningful relationship'
2063 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
2064 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2065 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
2066 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2067 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
2068 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2069 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
2070 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2071 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
2072 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2073 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
2074 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2075 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
2076 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2077 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
2078 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2084 void wxWindow::SetAutoLayout( bool autoLayout
)
2086 m_autoLayout
= autoLayout
;
2089 bool wxWindow::GetAutoLayout(void) const
2091 return m_autoLayout
;
2094 wxSizer
*wxWindow::GetSizer(void) const
2096 return m_windowSizer
;
2099 void wxWindow::SetSizerParent( wxWindow
*win
)
2101 m_sizerParent
= win
;
2104 wxWindow
*wxWindow::GetSizerParent(void) const
2106 return m_sizerParent
;
2109 // This removes any dangling pointers to this window
2110 // in other windows' constraintsInvolvedIn lists.
2111 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2115 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2116 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2117 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2118 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2119 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2120 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2121 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2122 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2123 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2124 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2125 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2126 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2127 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2128 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2129 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2130 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2134 // Back-pointer to other windows we're involved with, so if we delete
2135 // this window, we must delete any constraints we're involved with.
2136 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2138 if (!m_constraintsInvolvedIn
)
2139 m_constraintsInvolvedIn
= new wxList
;
2140 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2141 m_constraintsInvolvedIn
->Append(otherWin
);
2144 // REMOVE back-pointer to other windows we're involved with.
2145 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2147 if (m_constraintsInvolvedIn
)
2148 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2151 // Reset any constraints that mention this window
2152 void wxWindow::DeleteRelatedConstraints(void)
2154 if (m_constraintsInvolvedIn
)
2156 wxNode
*node
= m_constraintsInvolvedIn
->First();
2159 wxWindow
*win
= (wxWindow
*)node
->Data();
2160 wxNode
*next
= node
->Next();
2161 wxLayoutConstraints
*constr
= win
->GetConstraints();
2163 // Reset any constraints involving this window
2166 constr
->left
.ResetIfWin((wxWindow
*)this);
2167 constr
->top
.ResetIfWin((wxWindow
*)this);
2168 constr
->right
.ResetIfWin((wxWindow
*)this);
2169 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2170 constr
->width
.ResetIfWin((wxWindow
*)this);
2171 constr
->height
.ResetIfWin((wxWindow
*)this);
2172 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2173 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2178 delete m_constraintsInvolvedIn
;
2179 m_constraintsInvolvedIn
= NULL
;
2183 void wxWindow::SetSizer(wxSizer
*sizer
)
2185 m_windowSizer
= sizer
;
2187 sizer
->SetSizerParent((wxWindow
*)this);
2194 bool wxWindow::Layout(void)
2196 if (GetConstraints())
2199 GetClientSize(&w
, &h
);
2200 GetConstraints()->width
.SetValue(w
);
2201 GetConstraints()->height
.SetValue(h
);
2204 // If top level (one sizer), evaluate the sizer's constraints.
2208 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2209 GetSizer()->LayoutPhase1(&noChanges
);
2210 GetSizer()->LayoutPhase2(&noChanges
);
2211 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2216 // Otherwise, evaluate child constraints
2217 ResetConstraints(); // Mark all constraints as unevaluated
2218 DoPhase(1); // Just one phase need if no sizers involved
2220 SetConstraintSizes(); // Recursively set the real window sizes
2226 // Do a phase of evaluating constraints:
2227 // the default behaviour. wxSizers may do a similar
2228 // thing, but also impose their own 'constraints'
2229 // and order the evaluation differently.
2230 bool wxWindow::LayoutPhase1(int *noChanges
)
2232 wxLayoutConstraints
*constr
= GetConstraints();
2235 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2241 bool wxWindow::LayoutPhase2(int *noChanges
)
2251 // Do a phase of evaluating child constraints
2252 bool wxWindow::DoPhase(int phase
)
2254 int noIterations
= 0;
2255 int maxIterations
= 500;
2259 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2263 wxNode
*node
= GetChildren()->First();
2266 wxWindow
*child
= (wxWindow
*)node
->Data();
2267 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2269 wxLayoutConstraints
*constr
= child
->GetConstraints();
2272 if (succeeded
.Member(child
))
2277 int tempNoChanges
= 0;
2278 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2279 noChanges
+= tempNoChanges
;
2282 succeeded
.Append(child
);
2287 node
= node
->Next();
2294 void wxWindow::ResetConstraints(void)
2296 wxLayoutConstraints
*constr
= GetConstraints();
2299 constr
->left
.SetDone(FALSE
);
2300 constr
->top
.SetDone(FALSE
);
2301 constr
->right
.SetDone(FALSE
);
2302 constr
->bottom
.SetDone(FALSE
);
2303 constr
->width
.SetDone(FALSE
);
2304 constr
->height
.SetDone(FALSE
);
2305 constr
->centreX
.SetDone(FALSE
);
2306 constr
->centreY
.SetDone(FALSE
);
2308 wxNode
*node
= GetChildren()->First();
2311 wxWindow
*win
= (wxWindow
*)node
->Data();
2312 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2313 win
->ResetConstraints();
2314 node
= node
->Next();
2318 // Need to distinguish between setting the 'fake' size for
2319 // windows and sizers, and setting the real values.
2320 void wxWindow::SetConstraintSizes(bool recurse
)
2322 wxLayoutConstraints
*constr
= GetConstraints();
2323 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2324 constr
->width
.GetDone() && constr
->height
.GetDone())
2326 int x
= constr
->left
.GetValue();
2327 int y
= constr
->top
.GetValue();
2328 int w
= constr
->width
.GetValue();
2329 int h
= constr
->height
.GetValue();
2331 // If we don't want to resize this window, just move it...
2332 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2333 (constr
->height
.GetRelationship() != wxAsIs
))
2335 // Calls Layout() recursively. AAAGH. How can we stop that.
2336 // Simply take Layout() out of non-top level OnSizes.
2337 SizerSetSize(x
, y
, w
, h
);
2346 char *windowClass
= this->GetClassInfo()->GetClassName();
2349 if (GetName() == "")
2350 winName
= "unnamed";
2352 winName
= GetName();
2353 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
2354 if (!constr
->left
.GetDone())
2355 wxDebugMsg(" unsatisfied 'left' constraint.\n");
2356 if (!constr
->right
.GetDone())
2357 wxDebugMsg(" unsatisfied 'right' constraint.\n");
2358 if (!constr
->width
.GetDone())
2359 wxDebugMsg(" unsatisfied 'width' constraint.\n");
2360 if (!constr
->height
.GetDone())
2361 wxDebugMsg(" unsatisfied 'height' constraint.\n");
2362 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
2367 wxNode
*node
= GetChildren()->First();
2370 wxWindow
*win
= (wxWindow
*)node
->Data();
2371 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2372 win
->SetConstraintSizes();
2373 node
= node
->Next();
2378 // This assumes that all sizers are 'on' the same
2379 // window, i.e. the parent of this window.
2380 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2382 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2383 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2387 m_sizerParent
->GetPosition(&xp
, &yp
);
2388 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2393 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2397 TransformSizerToActual(&xx
, &yy
);
2398 SetSize(xx
, yy
, w
, h
);
2401 void wxWindow::SizerMove(int x
, int y
)
2405 TransformSizerToActual(&xx
, &yy
);
2409 // Only set the size/position of the constraint (if any)
2410 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2412 wxLayoutConstraints
*constr
= GetConstraints();
2417 constr
->left
.SetValue(x
);
2418 constr
->left
.SetDone(TRUE
);
2422 constr
->top
.SetValue(y
);
2423 constr
->top
.SetDone(TRUE
);
2427 constr
->width
.SetValue(w
);
2428 constr
->width
.SetDone(TRUE
);
2432 constr
->height
.SetValue(h
);
2433 constr
->height
.SetDone(TRUE
);
2438 void wxWindow::MoveConstraint(int x
, int y
)
2440 wxLayoutConstraints
*constr
= GetConstraints();
2445 constr
->left
.SetValue(x
);
2446 constr
->left
.SetDone(TRUE
);
2450 constr
->top
.SetValue(y
);
2451 constr
->top
.SetDone(TRUE
);
2456 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2458 wxLayoutConstraints
*constr
= GetConstraints();
2461 *w
= constr
->width
.GetValue();
2462 *h
= constr
->height
.GetValue();
2468 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2470 wxLayoutConstraints
*constr
= GetConstraints();
2473 *w
= constr
->width
.GetValue();
2474 *h
= constr
->height
.GetValue();
2477 GetClientSize(w
, h
);
2480 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2482 wxLayoutConstraints
*constr
= GetConstraints();
2485 *x
= constr
->left
.GetValue();
2486 *y
= constr
->top
.GetValue();
2492 bool wxWindow::AcceptsFocus() const
2494 return IsEnabled() && IsShown();
2497 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
) )