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 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1071 printf( "wxWindow::SetSize error.\n" );
1076 if ((m_parent
) && (m_parent
->m_wxwindow
))
1077 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1079 // Don't do anything for children of wxNotebook and wxMDIChildFrame
1082 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1084 if (m_resizing
) return; // I don't like recursions
1092 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1094 if (newX
== -1) newX
= m_x
;
1095 if (newY
== -1) newY
= m_y
;
1096 if (newW
== -1) newW
= m_width
;
1097 if (newH
== -1) newH
= m_height
;
1100 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1102 if (newW
== -1) newW
= 80;
1105 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1107 if (newH
== -1) newH
= 26;
1110 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1114 ImplementSetPosition();
1116 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1124 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1125 event
.SetEventObject( this );
1126 ProcessEvent( event
);
1131 void wxWindow::SetSize( int width
, int height
)
1133 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1136 void wxWindow::Move( int x
, int y
)
1138 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1141 void wxWindow::GetSize( int *width
, int *height
) const
1143 if (width
) (*width
) = m_width
;
1144 if (height
) (*height
) = m_height
;
1147 void wxWindow::SetClientSize( int width
, int height
)
1151 SetSize( width
, height
);
1158 if (!m_hasScrolling
)
1161 do we have sunken dialogs ?
1163 GtkStyleClass *window_class = m_wxwindow->style->klass;
1165 dw += 2 * window_class->xthickness;
1166 dh += 2 * window_class->ythickness;
1171 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1172 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1174 GtkWidget
*viewport
= scroll_window
->viewport
;
1175 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1177 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1178 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1180 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1181 (m_windowStyle
& wxSUNKEN_BORDER
)
1184 dw
+= 2 * viewport_class
->xthickness
;
1185 dh
+= 2 * viewport_class
->ythickness
;
1188 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1190 dw
+= vscrollbar
->allocation
.width
;
1191 dw
+= scroll_class
->scrollbar_spacing
;
1194 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1196 dh
+= hscrollbar
->allocation
.height
;
1197 dw
+= scroll_class
->scrollbar_spacing
;
1201 SetSize( width
+dw
, height
+dh
);
1205 void wxWindow::GetClientSize( int *width
, int *height
) const
1209 if (width
) (*width
) = m_width
;
1210 if (height
) (*height
) = m_height
;
1217 if (!m_hasScrolling
)
1220 do we have sunken dialogs ?
1222 GtkStyleClass *window_class = m_wxwindow->style->klass;
1224 dw += 2 * window_class->xthickness;
1225 dh += 2 * window_class->ythickness;
1230 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1231 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1233 GtkWidget
*viewport
= scroll_window
->viewport
;
1234 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1236 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1237 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1239 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1240 (m_windowStyle
& wxSUNKEN_BORDER
)
1243 dw
+= 2 * viewport_class
->xthickness
;
1244 dh
+= 2 * viewport_class
->ythickness
;
1247 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1249 // dw += vscrollbar->allocation.width;
1250 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1251 dw
+= scroll_class
->scrollbar_spacing
;
1254 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1256 // dh += hscrollbar->allocation.height;
1258 dh
+= scroll_class
->scrollbar_spacing
;
1262 if (width
) (*width
) = m_width
- dw
;
1263 if (height
) (*height
) = m_height
- dh
;
1267 void wxWindow::GetPosition( int *x
, int *y
) const
1273 void wxWindow::ClientToScreen( int *x
, int *y
)
1275 // Does this look simple ?
1277 GdkWindow
*source
= NULL
;
1279 source
= m_wxwindow
->window
;
1281 source
= m_widget
->window
;
1285 gdk_window_get_origin( source
, &org_x
, &org_y
);
1289 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1291 org_x
+= m_widget
->allocation
.x
;
1292 org_y
+= m_widget
->allocation
.y
;
1300 void wxWindow::ScreenToClient( int *x
, int *y
)
1302 GdkWindow
*source
= NULL
;
1304 source
= m_wxwindow
->window
;
1306 source
= m_widget
->window
;
1310 gdk_window_get_origin( source
, &org_x
, &org_y
);
1314 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1316 org_x
+= m_widget
->allocation
.x
;
1317 org_y
+= m_widget
->allocation
.y
;
1325 void wxWindow::Centre( int direction
)
1327 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1329 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
1330 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
1331 ImplementSetPosition();
1339 m_parent
->GetSize( &p_w
, &p_h
);
1340 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (p_w
- m_width
) / 2;
1341 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (p_h
- m_height
) / 2;
1342 ImplementSetPosition();
1347 void wxWindow::Fit(void)
1351 wxNode
*node
= GetChildren()->First();
1354 wxWindow
*win
= (wxWindow
*)node
->Data();
1356 win
->GetPosition(&wx
, &wy
);
1357 win
->GetSize(&ww
, &wh
);
1358 if ( wx
+ ww
> maxX
)
1360 if ( wy
+ wh
> maxY
)
1363 node
= node
->Next();
1365 SetClientSize(maxX
+ 5, maxY
+ 5);
1368 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1370 //if (GetAutoLayout()) Layout();
1373 bool wxWindow::Show( bool show
)
1376 gtk_widget_show( m_widget
);
1378 gtk_widget_hide( m_widget
);
1383 void wxWindow::Enable( bool enable
)
1385 m_isEnabled
= enable
;
1386 gtk_widget_set_sensitive( m_widget
, enable
);
1387 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1390 void wxWindow::MakeModal( bool modal
)
1393 // Disable all other windows
1394 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1396 wxNode
*node
= wxTopLevelWindows
.First();
1399 wxWindow
*win
= (wxWindow
*)node
->Data();
1401 win
->Enable(!modal
);
1403 node
= node
->Next();
1408 void wxWindow::SetFocus(void)
1410 GtkWidget
*connect_widget
= m_widget
;
1411 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1414 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1416 gtk_widget_grab_focus (connect_widget
);
1421 bool wxWindow::OnClose(void)
1426 void wxWindow::AddChild( wxWindow
*child
)
1428 // Addchild is (often) called before the program
1429 // has left the parents constructor so that no
1430 // virtual tables work yet. The approach below
1431 // practically imitates virtual tables, i.e. it
1432 // implements a different AddChild() behaviour
1433 // for wxFrame, wxDialog, wxWindow and
1434 // wxMDIParentFrame.
1436 // wxFrame and wxDialog as children aren't placed into the parents
1438 if (( IS_KIND_OF(child
,wxFrame
) || IS_KIND_OF(child
,wxDialog
) ) &&
1439 (!IS_KIND_OF(child
,wxMDIChildFrame
)))
1441 m_children
.Append( child
);
1443 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1444 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1449 // In the case of an wxMDIChildFrame descendant, we use the
1450 // client windows's AddChild()
1452 if (IS_KIND_OF(this,wxMDIParentFrame
))
1454 if (IS_KIND_OF(child
,wxMDIChildFrame
))
1456 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1459 client
->AddChild( child
);
1465 // wxNotebook is very special, so it has a private AddChild()
1467 if (IS_KIND_OF(this,wxNotebook
))
1469 wxNotebook
*tab
= (wxNotebook
*)this;
1470 tab
->AddChild( child
);
1474 // wxFrame has a private AddChild
1476 if (IS_KIND_OF(this,wxFrame
))
1478 wxFrame
*frame
= (wxFrame
*)this;
1479 frame
->AddChild( child
);
1485 m_children
.Append( child
);
1486 if (m_wxwindow
) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
,
1487 child
->m_x
, child
->m_y
);
1489 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1492 wxList
*wxWindow::GetChildren(void)
1494 return (&m_children
);
1497 void wxWindow::RemoveChild( wxWindow
*child
)
1500 GetChildren()->DeleteObject( child
);
1501 child
->m_parent
= NULL
;
1504 void wxWindow::SetReturnCode( int retCode
)
1506 m_retCode
= retCode
;
1509 int wxWindow::GetReturnCode(void)
1514 wxWindow
*wxWindow::GetParent(void)
1519 wxEvtHandler
*wxWindow::GetEventHandler(void)
1521 return m_eventHandler
;
1524 void wxWindow::SetEventhandler( wxEvtHandler
*handler
)
1526 m_eventHandler
= handler
;
1529 wxValidator
*wxWindow::GetValidator(void)
1531 return m_windowValidator
;
1534 void wxWindow::SetValidator( wxValidator
*validator
)
1536 m_windowValidator
= validator
;
1539 bool wxWindow::IsBeingDeleted(void)
1544 void wxWindow::SetId( wxWindowID id
)
1549 wxWindowID
wxWindow::GetId(void)
1554 void wxWindow::SetCursor( const wxCursor
&cursor
)
1556 if (*m_cursor
== cursor
) return;
1557 (*m_cursor
) = cursor
;
1558 if (m_widget
->window
)
1559 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1560 if (m_wxwindow
&& m_wxwindow
->window
)
1561 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1564 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1566 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1569 gdk_window_clear_area( m_wxwindow
->window
,
1581 wxClientDC
dc(this);
1585 dc
.GetInternalDeviceOrigin( &x
, &y
);
1589 GetClientSize( &w
, &h
);
1591 GdkRectangle gdk_rect
;
1595 gdk_rect
.height
= h
;
1596 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1601 GdkRectangle gdk_rect
;
1602 gdk_rect
.x
= rect
->x
;
1603 gdk_rect
.y
= rect
->y
;
1604 gdk_rect
.width
= rect
->width
;
1605 gdk_rect
.height
= rect
->height
;
1607 if (IS_KIND_OF(this,wxTreeCtrl
))
1609 printf( "x: %d y: %d w: %d h: %d .\n",
1610 gdk_rect
.x
, gdk_rect
.y
, gdk_rect
.width
, gdk_rect
.height
);
1614 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1616 gtk_widget_draw( m_widget
, &gdk_rect
);
1620 bool wxWindow::IsExposed( long x
, long y
)
1622 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1625 bool wxWindow::IsExposed( long x
, long y
, long width
, long height
)
1627 return (m_updateRegion
.Contains( x
, y
, width
, height
) != wxOutRegion
);
1630 void wxWindow::Clear(void)
1632 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1635 wxColour
wxWindow::GetBackgroundColour(void) const
1637 return m_backgroundColour
;
1640 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1642 m_backgroundColour
= colour
;
1645 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1646 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1647 gdk_window_clear( m_wxwindow
->window
);
1652 bool wxWindow::Validate(void)
1654 wxNode
*node
= GetChildren()->First();
1657 wxWindow
*child
= (wxWindow
*)node
->Data();
1658 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1660 node
= node
->Next();
1665 bool wxWindow::TransferDataToWindow(void)
1667 wxNode
*node
= GetChildren()->First();
1670 wxWindow
*child
= (wxWindow
*)node
->Data();
1671 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1672 !child
->GetValidator()->TransferToWindow() )
1674 wxMessageBox( "Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1677 node
= node
->Next();
1682 bool wxWindow::TransferDataFromWindow(void)
1684 wxNode
*node
= GetChildren()->First();
1687 wxWindow
*child
= (wxWindow
*)node
->Data();
1688 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1690 node
= node
->Next();
1695 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1697 TransferDataToWindow();
1700 void wxWindow::InitDialog(void)
1702 wxInitDialogEvent
event(GetId());
1703 event
.SetEventObject( this );
1704 GetEventHandler()->ProcessEvent(event
);
1707 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1709 GtkWidget
*dnd_widget
= GetDropTargetWidget();
1713 gtk_signal_disconnect_by_func( GTK_OBJECT(dnd_widget
),
1714 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1716 m_pDropTarget
->UnregisterWidget( dnd_widget
);
1717 delete m_pDropTarget
;
1719 m_pDropTarget
= dropTarget
;
1722 m_pDropTarget
->RegisterWidget( dnd_widget
);
1724 gtk_signal_connect( GTK_OBJECT(dnd_widget
), "drop_data_available_event",
1725 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1729 wxDropTarget
*wxWindow::GetDropTarget() const
1731 return m_pDropTarget
;
1734 GtkWidget
* wxWindow::GetDropTargetWidget(void)
1736 GtkWidget
*connect_widget
= m_widget
;
1737 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1739 return connect_widget
;
1742 void wxWindow::SetFont( const wxFont
&font
)
1747 copy old style values to new one
1748 set font in new style
1749 -> takes to many resources
1751 GtkStyle *style = gtk_style_new();
1756 wxFont
*wxWindow::GetFont(void)
1761 void wxWindow::SetWindowStyleFlag( long flag
)
1763 m_windowStyle
= flag
;
1766 long wxWindow::GetWindowStyleFlag(void) const
1768 return m_windowStyle
;
1771 void wxWindow::CaptureMouse(void)
1773 GtkWidget
*connect_widget
= m_widget
;
1774 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1775 gtk_grab_add( connect_widget
);
1776 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1778 (GDK_BUTTON_PRESS_MASK
|
1779 GDK_BUTTON_RELEASE_MASK
|
1780 GDK_POINTER_MOTION_MASK
),
1781 NULL
, NULL
, GDK_CURRENT_TIME
);
1784 void wxWindow::ReleaseMouse(void)
1786 GtkWidget
*connect_widget
= m_widget
;
1787 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1788 gtk_grab_remove( connect_widget
);
1789 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1792 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1796 wxString
wxWindow::GetTitle(void) const
1798 return (wxString
&)m_windowName
;
1801 wxString
wxWindow::GetLabel(void) const
1806 void wxWindow::SetName( const wxString
&name
)
1808 m_windowName
= name
;
1811 wxString
wxWindow::GetName(void) const
1813 return (wxString
&)m_windowName
;
1816 bool wxWindow::IsShown(void) const
1821 bool wxWindow::IsRetained(void)
1826 wxWindow
*wxWindow::FindWindow( long id
)
1828 if (id
== m_windowId
) return this;
1829 wxNode
*node
= m_children
.First();
1832 wxWindow
*child
= (wxWindow
*)node
->Data();
1833 wxWindow
*res
= child
->FindWindow( id
);
1834 if (res
) return res
;
1835 node
= node
->Next();
1840 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1842 if (name
== m_windowName
) return this;
1843 wxNode
*node
= m_children
.First();
1846 wxWindow
*child
= (wxWindow
*)node
->Data();
1847 wxWindow
*res
= child
->FindWindow( name
);
1848 if (res
) return res
;
1849 node
= node
->Next();
1854 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1855 int range
, bool WXUNUSED(refresh
) )
1857 if (!m_wxwindow
) return;
1859 if (orient
== wxHORIZONTAL
)
1861 float fpos
= (float)pos
;
1862 m_oldHorizontalPos
= fpos
;
1863 float frange
= (float)range
;
1864 float fthumb
= (float)thumbVisible
;
1866 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1867 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1868 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1871 m_hAdjust
->lower
= 0.0;
1872 m_hAdjust
->upper
= frange
;
1873 m_hAdjust
->value
= fpos
;
1874 m_hAdjust
->step_increment
= 1.0;
1875 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1876 m_hAdjust
->page_size
= fthumb
;
1880 float fpos
= (float)pos
;
1881 m_oldVerticalPos
= fpos
;
1882 float frange
= (float)range
;
1883 float fthumb
= (float)thumbVisible
;
1885 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1886 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1887 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1890 m_vAdjust
->lower
= 0.0;
1891 m_vAdjust
->upper
= frange
;
1892 m_vAdjust
->value
= fpos
;
1893 m_vAdjust
->step_increment
= 1.0;
1894 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1895 m_vAdjust
->page_size
= fthumb
;
1898 if (m_wxwindow
->window
)
1900 if (orient
== wxHORIZONTAL
)
1903 m_drawingOffsetX = -16000;
1905 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1907 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
1912 m_drawingOffsetY = -16000;
1914 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1916 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
1919 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1923 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
1925 if (!m_wxwindow
) return;
1927 if (orient
== wxHORIZONTAL
)
1929 float fpos
= (float)pos
;
1930 m_oldHorizontalPos
= fpos
;
1932 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
1933 m_hAdjust
->value
= fpos
;
1937 float fpos
= (float)pos
;
1938 m_oldVerticalPos
= fpos
;
1939 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
1940 m_vAdjust
->value
= fpos
;
1943 if (m_wxwindow
->window
)
1945 if (orient
== wxHORIZONTAL
)
1946 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
1948 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
1952 int wxWindow::GetScrollThumb( int orient
) const
1954 if (!m_wxwindow
) return 0;
1956 if (orient
== wxHORIZONTAL
)
1957 return (int)(m_hAdjust
->page_size
+0.5);
1959 return (int)(m_vAdjust
->page_size
+0.5);
1962 int wxWindow::GetScrollPos( int orient
) const
1964 if (!m_wxwindow
) return 0;
1966 if (orient
== wxHORIZONTAL
)
1967 return (int)(m_hAdjust
->value
+0.5);
1969 return (int)(m_vAdjust
->value
+0.5);
1972 int wxWindow::GetScrollRange( int orient
) const
1974 if (!m_wxwindow
) return 0;
1976 if (orient
== wxHORIZONTAL
)
1977 return (int)(m_hAdjust
->upper
+0.5);
1979 return (int)(m_vAdjust
->upper
+0.5);
1982 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
1984 if (!m_wxwindow
) return;
1986 bool refresh
= FALSE
;
1988 if ((m_drawingOffsetX
== 0) && (m_drawingOffsetY
== 0))
1990 m_drawingOffsetX
= -16000;
1991 m_drawingOffsetY
= -16000;
1996 m_drawingOffsetX
+= dx
;
1997 m_drawingOffsetY
+= dy
;
2000 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
2002 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow
), m_drawingOffsetX
, m_drawingOffsetY
);
2004 if (refresh
) Refresh();
2007 The code here is very nifty, but it doesn't work with
2008 overlapping windows...
2012 GetClientSize( &cw, &ch );
2014 int w = cw - abs(dx);
2015 int h = ch - abs(dy);
2016 if ((h < 0) || (w < 0))
2023 if (dx < 0) s_x = -dx;
2024 if (dy < 0) s_y = -dy;
2027 if (dx > 0) d_x = dx;
2028 if (dy > 0) d_y = dy;
2029 gdk_window_copy_area( m_wxwindow->window, m_wxwindow->style->fg_gc[0], d_x, d_y,
2030 m_wxwindow->window, s_x, s_y, w, h );
2033 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
2034 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
2035 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
2036 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
2038 Refresh( TRUE, &rect );
2042 void wxWindow::GetDrawingOffset( long *x
, long *y
)
2044 if (x
) *x
= m_drawingOffsetX
;
2045 if (y
) *y
= m_drawingOffsetY
;
2048 //-------------------------------------------------------------------------------------
2050 //-------------------------------------------------------------------------------------
2052 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
2054 return m_constraints
;
2057 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
2061 UnsetConstraints(m_constraints
);
2062 delete m_constraints
;
2064 m_constraints
= constraints
;
2067 // Make sure other windows know they're part of a 'meaningful relationship'
2068 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
2069 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2070 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
2071 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2072 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
2073 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2074 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
2075 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2076 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
2077 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2078 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
2079 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2080 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
2081 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2082 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
2083 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2089 void wxWindow::SetAutoLayout( bool autoLayout
)
2091 m_autoLayout
= autoLayout
;
2094 bool wxWindow::GetAutoLayout(void) const
2096 return m_autoLayout
;
2099 wxSizer
*wxWindow::GetSizer(void) const
2101 return m_windowSizer
;
2104 void wxWindow::SetSizerParent( wxWindow
*win
)
2106 m_sizerParent
= win
;
2109 wxWindow
*wxWindow::GetSizerParent(void) const
2111 return m_sizerParent
;
2114 // This removes any dangling pointers to this window
2115 // in other windows' constraintsInvolvedIn lists.
2116 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2120 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2121 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2122 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2123 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2124 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2125 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2126 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2127 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2128 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2129 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2130 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2131 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2132 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2133 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2134 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2135 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2139 // Back-pointer to other windows we're involved with, so if we delete
2140 // this window, we must delete any constraints we're involved with.
2141 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2143 if (!m_constraintsInvolvedIn
)
2144 m_constraintsInvolvedIn
= new wxList
;
2145 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2146 m_constraintsInvolvedIn
->Append(otherWin
);
2149 // REMOVE back-pointer to other windows we're involved with.
2150 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2152 if (m_constraintsInvolvedIn
)
2153 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2156 // Reset any constraints that mention this window
2157 void wxWindow::DeleteRelatedConstraints(void)
2159 if (m_constraintsInvolvedIn
)
2161 wxNode
*node
= m_constraintsInvolvedIn
->First();
2164 wxWindow
*win
= (wxWindow
*)node
->Data();
2165 wxNode
*next
= node
->Next();
2166 wxLayoutConstraints
*constr
= win
->GetConstraints();
2168 // Reset any constraints involving this window
2171 constr
->left
.ResetIfWin((wxWindow
*)this);
2172 constr
->top
.ResetIfWin((wxWindow
*)this);
2173 constr
->right
.ResetIfWin((wxWindow
*)this);
2174 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2175 constr
->width
.ResetIfWin((wxWindow
*)this);
2176 constr
->height
.ResetIfWin((wxWindow
*)this);
2177 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2178 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2183 delete m_constraintsInvolvedIn
;
2184 m_constraintsInvolvedIn
= NULL
;
2188 void wxWindow::SetSizer(wxSizer
*sizer
)
2190 m_windowSizer
= sizer
;
2192 sizer
->SetSizerParent((wxWindow
*)this);
2199 bool wxWindow::Layout(void)
2201 if (GetConstraints())
2204 GetClientSize(&w
, &h
);
2205 GetConstraints()->width
.SetValue(w
);
2206 GetConstraints()->height
.SetValue(h
);
2209 // If top level (one sizer), evaluate the sizer's constraints.
2213 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2214 GetSizer()->LayoutPhase1(&noChanges
);
2215 GetSizer()->LayoutPhase2(&noChanges
);
2216 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2221 // Otherwise, evaluate child constraints
2222 ResetConstraints(); // Mark all constraints as unevaluated
2223 DoPhase(1); // Just one phase need if no sizers involved
2225 SetConstraintSizes(); // Recursively set the real window sizes
2231 // Do a phase of evaluating constraints:
2232 // the default behaviour. wxSizers may do a similar
2233 // thing, but also impose their own 'constraints'
2234 // and order the evaluation differently.
2235 bool wxWindow::LayoutPhase1(int *noChanges
)
2237 wxLayoutConstraints
*constr
= GetConstraints();
2240 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2246 bool wxWindow::LayoutPhase2(int *noChanges
)
2256 // Do a phase of evaluating child constraints
2257 bool wxWindow::DoPhase(int phase
)
2259 int noIterations
= 0;
2260 int maxIterations
= 500;
2264 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2268 wxNode
*node
= GetChildren()->First();
2271 wxWindow
*child
= (wxWindow
*)node
->Data();
2272 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2274 wxLayoutConstraints
*constr
= child
->GetConstraints();
2277 if (succeeded
.Member(child
))
2282 int tempNoChanges
= 0;
2283 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2284 noChanges
+= tempNoChanges
;
2287 succeeded
.Append(child
);
2292 node
= node
->Next();
2299 void wxWindow::ResetConstraints(void)
2301 wxLayoutConstraints
*constr
= GetConstraints();
2304 constr
->left
.SetDone(FALSE
);
2305 constr
->top
.SetDone(FALSE
);
2306 constr
->right
.SetDone(FALSE
);
2307 constr
->bottom
.SetDone(FALSE
);
2308 constr
->width
.SetDone(FALSE
);
2309 constr
->height
.SetDone(FALSE
);
2310 constr
->centreX
.SetDone(FALSE
);
2311 constr
->centreY
.SetDone(FALSE
);
2313 wxNode
*node
= GetChildren()->First();
2316 wxWindow
*win
= (wxWindow
*)node
->Data();
2317 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2318 win
->ResetConstraints();
2319 node
= node
->Next();
2323 // Need to distinguish between setting the 'fake' size for
2324 // windows and sizers, and setting the real values.
2325 void wxWindow::SetConstraintSizes(bool recurse
)
2327 wxLayoutConstraints
*constr
= GetConstraints();
2328 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2329 constr
->width
.GetDone() && constr
->height
.GetDone())
2331 int x
= constr
->left
.GetValue();
2332 int y
= constr
->top
.GetValue();
2333 int w
= constr
->width
.GetValue();
2334 int h
= constr
->height
.GetValue();
2336 // If we don't want to resize this window, just move it...
2337 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2338 (constr
->height
.GetRelationship() != wxAsIs
))
2340 // Calls Layout() recursively. AAAGH. How can we stop that.
2341 // Simply take Layout() out of non-top level OnSizes.
2342 SizerSetSize(x
, y
, w
, h
);
2351 char *windowClass
= this->GetClassInfo()->GetClassName();
2354 if (GetName() == "")
2355 winName
= "unnamed";
2357 winName
= GetName();
2358 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
2359 if (!constr
->left
.GetDone())
2360 wxDebugMsg(" unsatisfied 'left' constraint.\n");
2361 if (!constr
->right
.GetDone())
2362 wxDebugMsg(" unsatisfied 'right' constraint.\n");
2363 if (!constr
->width
.GetDone())
2364 wxDebugMsg(" unsatisfied 'width' constraint.\n");
2365 if (!constr
->height
.GetDone())
2366 wxDebugMsg(" unsatisfied 'height' constraint.\n");
2367 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
2372 wxNode
*node
= GetChildren()->First();
2375 wxWindow
*win
= (wxWindow
*)node
->Data();
2376 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2377 win
->SetConstraintSizes();
2378 node
= node
->Next();
2383 // This assumes that all sizers are 'on' the same
2384 // window, i.e. the parent of this window.
2385 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2387 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2388 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2392 m_sizerParent
->GetPosition(&xp
, &yp
);
2393 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2398 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2402 TransformSizerToActual(&xx
, &yy
);
2403 SetSize(xx
, yy
, w
, h
);
2406 void wxWindow::SizerMove(int x
, int y
)
2410 TransformSizerToActual(&xx
, &yy
);
2414 // Only set the size/position of the constraint (if any)
2415 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2417 wxLayoutConstraints
*constr
= GetConstraints();
2422 constr
->left
.SetValue(x
);
2423 constr
->left
.SetDone(TRUE
);
2427 constr
->top
.SetValue(y
);
2428 constr
->top
.SetDone(TRUE
);
2432 constr
->width
.SetValue(w
);
2433 constr
->width
.SetDone(TRUE
);
2437 constr
->height
.SetValue(h
);
2438 constr
->height
.SetDone(TRUE
);
2443 void wxWindow::MoveConstraint(int x
, int y
)
2445 wxLayoutConstraints
*constr
= GetConstraints();
2450 constr
->left
.SetValue(x
);
2451 constr
->left
.SetDone(TRUE
);
2455 constr
->top
.SetValue(y
);
2456 constr
->top
.SetDone(TRUE
);
2461 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2463 wxLayoutConstraints
*constr
= GetConstraints();
2466 *w
= constr
->width
.GetValue();
2467 *h
= constr
->height
.GetValue();
2473 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2475 wxLayoutConstraints
*constr
= GetConstraints();
2478 *w
= constr
->width
.GetValue();
2479 *h
= constr
->height
.GetValue();
2482 GetClientSize(w
, h
);
2485 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2487 wxLayoutConstraints
*constr
= GetConstraints();
2490 *x
= constr
->left
.GetValue();
2491 *y
= constr
->top
.GetValue();
2497 bool wxWindow::AcceptsFocus() const
2499 return IsEnabled() && IsShown();
2502 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
) )