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
);
260 bool ret
= win
->ProcessEvent( event
);
262 if (ret) printf( "found.\n") ;
267 //-----------------------------------------------------------------------------
270 gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
272 if (widget
->window
!= gdk_event
->window
) return TRUE
;
273 if (g_blockEventsOnDrag
) return TRUE
;
277 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
) && !GTK_WIDGET_HAS_FOCUS (win
->m_wxwindow
) )
279 gtk_widget_grab_focus (win
->m_wxwindow
);
282 printf( "GrabFocus from " );
283 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
284 printf( win->GetClassInfo()->GetClassName() );
291 if (!win
->HasVMT()) return TRUE
;
294 printf( "OnButtonPress from " );
295 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
296 printf( win->GetClassInfo()->GetClassName() );
300 wxEventType event_type
= wxEVT_LEFT_DOWN
;
302 if (gdk_event
->button
== 1)
304 switch (gdk_event
->type
)
306 case GDK_BUTTON_PRESS
: event_type
= wxEVT_LEFT_DOWN
; break;
307 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_LEFT_DCLICK
; break;
311 else if (gdk_event
->button
== 2)
313 switch (gdk_event
->type
)
315 case GDK_BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DOWN
; break;
316 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DCLICK
; break;
320 else if (gdk_event
->button
== 3)
322 switch (gdk_event
->type
)
324 case GDK_BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DOWN
; break;
325 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DCLICK
; break;
330 wxMouseEvent
event( event_type
);
331 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
332 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
333 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
334 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
335 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
336 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
337 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
339 event
.m_x
= (long)gdk_event
->x
;
340 event
.m_y
= (long)gdk_event
->y
;
341 event
.SetEventObject( win
);
343 win
->ProcessEvent( event
);
348 //-----------------------------------------------------------------------------
351 gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
353 if (widget
->window
!= gdk_event
->window
) return TRUE
;
355 if (g_blockEventsOnDrag
) return TRUE
;
357 if (!win
->HasVMT()) return TRUE
;
360 printf( "OnButtonRelease from " );
361 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
362 printf( win->GetClassInfo()->GetClassName() );
366 wxEventType event_type
= wxEVT_NULL
;
368 switch (gdk_event
->button
)
370 case 1: event_type
= wxEVT_LEFT_UP
; break;
371 case 2: event_type
= wxEVT_MIDDLE_UP
; break;
372 case 3: event_type
= wxEVT_RIGHT_UP
; break;
375 wxMouseEvent
event( event_type
);
376 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
377 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
378 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
379 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
380 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
381 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
382 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
383 event
.m_x
= (long)gdk_event
->x
;
384 event
.m_y
= (long)gdk_event
->y
;
385 event
.SetEventObject( win
);
387 win
->ProcessEvent( event
);
392 //-----------------------------------------------------------------------------
395 gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxWindow
*win
)
397 if (widget
->window
!= gdk_event
->window
) return TRUE
;
399 if (g_blockEventsOnDrag
) return TRUE
;
401 if (!win
->HasVMT()) return TRUE
;
404 printf( "OnMotion from " );
405 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
406 printf( win->GetClassInfo()->GetClassName() );
410 wxMouseEvent
event( wxEVT_MOTION
);
411 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
412 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
413 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
414 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
415 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
416 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
417 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
419 event
.m_x
= (long)gdk_event
->x
;
420 event
.m_y
= (long)gdk_event
->y
;
421 event
.SetEventObject( win
);
423 win
->ProcessEvent( event
);
428 //-----------------------------------------------------------------------------
431 gint
gtk_window_focus_in_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
433 if (g_blockEventsOnDrag
) return TRUE
;
436 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
438 GTK_WIDGET_SET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
440 printf( "SetFocus flag from " );
441 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
442 printf( win->GetClassInfo()->GetClassName() );
448 if (!win
->HasVMT()) return TRUE
;
451 printf( "OnSetFocus from " );
452 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
453 printf( win->GetClassInfo()->GetClassName() );
455 printf( WXSTRINGCAST win->GetLabel() );
459 wxFocusEvent
event( wxEVT_SET_FOCUS
, win
->GetId() );
460 event
.SetEventObject( win
);
461 win
->ProcessEvent( event
);
466 //-----------------------------------------------------------------------------
469 gint
gtk_window_focus_out_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
471 if (g_blockEventsOnDrag
) return TRUE
;
474 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
475 GTK_WIDGET_UNSET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
478 if (!win
->HasVMT()) return TRUE
;
481 printf( "OnKillFocus from " );
482 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
483 printf( win->GetClassInfo()->GetClassName() );
487 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
488 event
.SetEventObject( win
);
489 win
->ProcessEvent( event
);
494 //-----------------------------------------------------------------------------
497 void gtk_window_vscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
499 if (g_blockEventsOnDrag
) return;
502 printf( "OnVScroll from " );
503 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
504 printf( win->GetClassInfo()->GetClassName() );
508 if (!win
->HasVMT()) return;
510 float diff
= win
->m_vAdjust
->value
- win
->m_oldVerticalPos
;
511 if (fabs(diff
) < 0.2) return;
514 int i = (int)(win->m_oldVerticalPos+0.5);
515 printf( "Old value: %d.\n", i );
516 i = (int)(win->m_vAdjust->value+0.5);
517 printf( "Sending new value: %d.\n", i );
520 wxEventType command
= wxEVT_NULL
;
522 float line_step
= win
->m_vAdjust
->step_increment
;
523 float page_step
= win
->m_vAdjust
->page_increment
;
525 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
526 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
527 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
528 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
529 else command
= wxEVT_SCROLL_THUMBTRACK
;
531 int value
= (int)(win
->m_vAdjust
->value
+0.5);
533 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
534 event
.SetEventObject( win
);
535 win
->ProcessEvent( event
);
538 //-----------------------------------------------------------------------------
541 void gtk_window_hscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
543 if (g_blockEventsOnDrag
) return;
546 printf( "OnHScroll from " );
547 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
548 printf( win->GetClassInfo()->GetClassName() );
552 if (!win
->HasVMT()) return;
554 float diff
= win
->m_hAdjust
->value
- win
->m_oldHorizontalPos
;
555 if (fabs(diff
) < 0.2) return;
558 int i = (int)(win->m_oldHorizontalPos+0.5);
559 printf( "Old value: %d.\n", i );
560 i = (int)(win->m_hAdjust->value+0.5);
561 printf( "Sending new value: %d.\n", i );
564 wxEventType command
= wxEVT_NULL
;
566 float line_step
= win
->m_hAdjust
->step_increment
;
567 float page_step
= win
->m_hAdjust
->page_increment
;
569 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
570 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
571 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
572 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
573 else command
= wxEVT_SCROLL_THUMBTRACK
;
575 int value
= (int)(win
->m_hAdjust
->value
+0.5);
577 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
578 event
.SetEventObject( win
);
579 win
->ProcessEvent( event
);
582 //-----------------------------------------------------------------------------
583 // vertical scroll change
585 void gtk_window_vscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
587 if (g_blockEventsOnDrag
) return;
590 printf( "OnVScroll change from " );
591 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
592 printf( win->GetClassInfo()->GetClassName() );
596 if (!win
->HasVMT()) return;
598 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
599 int value
= (int)(win
->m_vAdjust
->value
+0.5);
601 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
602 event
.SetEventObject( win
);
603 win
->ProcessEvent( event
);
606 //-----------------------------------------------------------------------------
607 // horizontal scroll change
609 void gtk_window_hscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
611 if (g_blockEventsOnDrag
) return;
614 printf( "OnHScroll change from " );
615 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
616 printf( win->GetClassInfo()->GetClassName() );
620 if (!win
->HasVMT()) return;
622 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
623 int value
= (int)(win
->m_hAdjust
->value
+0.5);
625 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
626 event
.SetEventObject( win
);
627 win
->ProcessEvent( event
);
630 //-----------------------------------------------------------------------------
633 void gtk_window_drop_callback( GtkWidget
*widget
, GdkEvent
*event
, wxWindow
*win
)
635 if (!win
->HasVMT()) return;
637 if (win
->GetDropTarget())
641 gdk_window_get_pointer( widget
->window
, &x
, &y
, NULL
);
642 win
->GetDropTarget()->Drop( event
, x
, y
);
646 g_free (event->dropdataavailable.data);
647 g_free (event->dropdataavailable.data_type);
651 //-----------------------------------------------------------------------------
654 bool gtk_window_destroy_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
656 printf( "OnDestroy from " );
657 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
658 printf( win
->GetClassInfo()->GetClassName() );
660 printf( "Goodbye.\n" );
661 printf( " Robert Roebling.\n" );
666 //-----------------------------------------------------------------------------
669 bool gtk_window_enter_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
671 if (widget
->window
!= gdk_event
->window
) return TRUE
;
672 if (g_blockEventsOnDrag
) return TRUE
;
673 if (!win
->HasVMT()) return TRUE
;
676 gdk_window_set_cursor( widget
->window
, win
->m_cursor
->GetCursor() );
678 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
679 event
.SetEventObject( win
);
680 return win
->ProcessEvent( event
);
683 //-----------------------------------------------------------------------------
686 bool gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
688 if (widget
->window
!= gdk_event
->window
) return TRUE
;
689 if (!win
->HasVMT()) return TRUE
;
690 if (g_blockEventsOnDrag
) return TRUE
;
693 gdk_window_set_cursor( widget
->window
, wxSTANDARD_CURSOR
->GetCursor() );
695 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
696 event
.SetEventObject( win
);
697 return win
->ProcessEvent( event
);
700 //-----------------------------------------------------------------------------
701 // wxWindow implementation
702 //-----------------------------------------------------------------------------
704 IMPLEMENT_DYNAMIC_CLASS(wxWindow
,wxEvtHandler
)
706 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
707 EVT_SIZE(wxWindow::OnSize
)
708 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
709 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
710 EVT_IDLE(wxWindow::OnIdle
)
718 m_children
.DeleteContents( FALSE
);
724 m_eventHandler
= this;
725 m_windowValidator
= NULL
;
727 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
728 m_font
= *wxSWISS_FONT
;
730 m_windowName
= "noname";
731 m_constraints
= NULL
;
732 m_constraintsInvolvedIn
= NULL
;
733 m_windowSizer
= NULL
;
734 m_sizerParent
= NULL
;
735 m_autoLayout
= FALSE
;
739 m_hasScrolling
= FALSE
;
742 m_oldHorizontalPos
= 0.0;
743 m_oldVerticalPos
= 0.0;
746 m_drawingOffsetX
= 0;
747 m_drawingOffsetY
= 0;
748 m_pDropTarget
= NULL
;
752 wxWindow::wxWindow( wxWindow
*parent
, wxWindowID id
,
753 const wxPoint
&pos
, const wxSize
&size
,
754 long style
, const wxString
&name
)
756 Create( parent
, id
, pos
, size
, style
, name
);
759 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
760 const wxPoint
&pos
, const wxSize
&size
,
761 long style
, const wxString
&name
)
767 PreCreation( parent
, id
, pos
, size
, style
, name
);
769 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
770 m_hasScrolling
= TRUE
;
772 GtkScrolledWindow
*s_window
;
773 s_window
= GTK_SCROLLED_WINDOW(m_widget
);
775 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
776 scroll_class
->scrollbar_spacing
= 0;
778 gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
780 m_oldHorizontalPos
= 0.0;
781 m_oldVerticalPos
= 0.0;
783 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) );
784 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) );
786 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "value_changed",
787 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
788 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "value_changed",
789 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
791 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "changed",
792 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
793 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "changed",
794 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
796 GtkViewport
*viewport
;
797 viewport
= GTK_VIEWPORT(s_window
->viewport
);
799 if (m_windowStyle
& wxRAISED_BORDER
)
801 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
803 else if (m_windowStyle
& wxSUNKEN_BORDER
)
805 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
809 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
812 m_wxwindow
= gtk_myfixed_new();
814 if (m_wxwindow
) GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
816 if (m_windowStyle
& wxTAB_TRAVERSAL
== wxTAB_TRAVERSAL
)
817 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
819 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
821 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
823 // shut the viewport up
824 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
825 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
827 // I _really_ don't want scrollbars in the beginning
828 m_vAdjust
->lower
= 0.0;
829 m_vAdjust
->upper
= 1.0;
830 m_vAdjust
->value
= 0.0;
831 m_vAdjust
->step_increment
= 1.0;
832 m_vAdjust
->page_increment
= 1.0;
833 m_vAdjust
->page_size
= 5.0;
834 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
835 m_hAdjust
->lower
= 0.0;
836 m_hAdjust
->upper
= 1.0;
837 m_hAdjust
->value
= 0.0;
838 m_hAdjust
->step_increment
= 1.0;
839 m_hAdjust
->page_increment
= 1.0;
840 m_hAdjust
->page_size
= 5.0;
841 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
843 gtk_widget_show( m_wxwindow
);
852 wxWindow::~wxWindow(void)
856 if (m_pDropTarget
) delete m_pDropTarget
;
858 if (m_parent
) m_parent
->RemoveChild( this );
859 if (m_widget
) Show( FALSE
);
863 if (m_wxwindow
) gtk_widget_destroy( m_wxwindow
);
865 if (m_widget
) gtk_widget_destroy( m_widget
);
869 DeleteRelatedConstraints();
872 // This removes any dangling pointers to this window
873 // in other windows' constraintsInvolvedIn lists.
874 UnsetConstraints(m_constraints
);
875 delete m_constraints
;
876 m_constraints
= NULL
;
880 delete m_windowSizer
;
881 m_windowSizer
= NULL
;
883 // If this is a child of a sizer, remove self from parent
885 m_sizerParent
->RemoveChild((wxWindow
*)this);
887 // Just in case the window has been Closed, but
888 // we're then deleting immediately: don't leave
889 // dangling pointers.
890 wxPendingDelete
.DeleteObject(this);
892 // Just in case we've loaded a top-level window via
893 // wxWindow::LoadNativeDialog but we weren't a dialog
895 wxTopLevelWindows
.DeleteObject(this);
899 void wxWindow::PreCreation( wxWindow
*parent
, wxWindowID id
,
900 const wxPoint
&pos
, const wxSize
&size
,
901 long style
, const wxString
&name
)
903 if (m_needParent
&& (parent
== NULL
))
904 wxFatalError( "Need complete parent.", name
);
909 m_children
.DeleteContents( FALSE
);
913 if (m_width
== -1) m_width
= 20;
915 if (m_height
== -1) m_height
= 20;
917 m_eventHandler
= this;
918 m_windowValidator
= NULL
;
921 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
922 m_font
= *wxSWISS_FONT
;
923 m_backgroundColour
= wxWHITE
;
924 m_foregroundColour
= wxBLACK
;
925 m_windowStyle
= style
;
927 m_constraints
= NULL
;
928 m_constraintsInvolvedIn
= NULL
;
929 m_windowSizer
= NULL
;
930 m_sizerParent
= NULL
;
931 m_autoLayout
= FALSE
;
932 m_drawingOffsetX
= 0;
933 m_drawingOffsetY
= 0;
934 m_pDropTarget
= NULL
;
938 void wxWindow::PostCreation(void)
940 if (m_parent
) m_parent
->AddChild( this );
942 // GtkStyle *style = m_widget->style;
943 // style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
945 GtkWidget
*connect_widget
= m_widget
;
946 if (m_wxwindow
) connect_widget
= m_wxwindow
;
948 gtk_object_set_data (GTK_OBJECT (connect_widget
), "MyWxWindow", (gpointer
)this );
952 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
953 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
955 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
956 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
960 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
961 GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this );
964 gtk_signal_connect( GTK_OBJECT(connect_widget
), "key_press_event",
965 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
967 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_press_event",
968 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
970 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_release_event",
971 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
973 gtk_signal_connect( GTK_OBJECT(connect_widget
), "motion_notify_event",
974 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
976 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_in_event",
977 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
979 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_out_event",
980 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
982 // Only for cursor handling
984 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter_notify_event",
985 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
987 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave_notify_event",
988 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
992 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "enter_notify_event",
993 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
995 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "leave_notify_event",
996 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
1000 // Does destroy ever get called ?
1002 gtk_signal_connect( GTK_OBJECT(m_widget), "destroy_event",
1003 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1007 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "destroy_event",
1008 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1012 if (m_widget
&& m_parent
) gtk_widget_realize( m_widget
);
1013 if (m_wxwindow
) gtk_widget_realize( m_wxwindow
);
1015 SetCursor( wxSTANDARD_CURSOR
);
1020 bool wxWindow::HasVMT(void)
1025 bool wxWindow::Close( bool force
)
1027 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1028 event
.SetEventObject(this);
1029 event
.SetForce(force
);
1031 return GetEventHandler()->ProcessEvent(event
);
1034 bool wxWindow::Destroy(void)
1041 bool wxWindow::DestroyChildren(void)
1046 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
)
1049 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
)
1052 if (GetChildren()->Member(child
)) delete node
;
1059 void wxWindow::PrepareDC( wxDC
&WXUNUSED(dc
) )
1061 // are we to set fonts here ?
1064 void wxWindow::ImplementSetSize(void)
1066 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1069 void wxWindow::ImplementSetPosition(void)
1071 if (IS_KIND_OF(this,wxFrame
) || IS_KIND_OF(this,wxDialog
))
1073 if ((m_x
!= -1) || (m_y
!= -1))
1074 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1080 printf( "wxWindow::SetSize error.\n" );
1084 if ((m_parent
) && (m_parent
->m_wxwindow
))
1085 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1087 // Don't do anything for children of wxNotebook and wxMDIChildFrame
1090 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1092 if (m_resizing
) return; // I don't like recursions
1100 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1102 if (newX
== -1) newX
= m_x
;
1103 if (newY
== -1) newY
= m_y
;
1104 if (newW
== -1) newW
= m_width
;
1105 if (newH
== -1) newH
= m_height
;
1108 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1110 if (newW
== -1) newW
= 80;
1113 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1115 if (newH
== -1) newH
= 26;
1118 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1122 ImplementSetPosition();
1124 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1132 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1133 event
.SetEventObject( this );
1134 ProcessEvent( event
);
1139 void wxWindow::SetSize( int width
, int height
)
1141 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1144 void wxWindow::Move( int x
, int y
)
1146 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1149 void wxWindow::GetSize( int *width
, int *height
) const
1151 if (width
) (*width
) = m_width
;
1152 if (height
) (*height
) = m_height
;
1155 void wxWindow::SetClientSize( int width
, int height
)
1159 SetSize( width
, height
);
1166 if (!m_hasScrolling
)
1169 do we have sunken dialogs ?
1171 GtkStyleClass *window_class = m_wxwindow->style->klass;
1173 dw += 2 * window_class->xthickness;
1174 dh += 2 * window_class->ythickness;
1179 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1180 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1182 GtkWidget
*viewport
= scroll_window
->viewport
;
1183 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1185 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1186 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1188 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1189 (m_windowStyle
& wxSUNKEN_BORDER
)
1192 dw
+= 2 * viewport_class
->xthickness
;
1193 dh
+= 2 * viewport_class
->ythickness
;
1196 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1198 dw
+= vscrollbar
->allocation
.width
;
1199 dw
+= scroll_class
->scrollbar_spacing
;
1202 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1204 dh
+= hscrollbar
->allocation
.height
;
1205 dw
+= scroll_class
->scrollbar_spacing
;
1209 SetSize( width
+dw
, height
+dh
);
1213 void wxWindow::GetClientSize( int *width
, int *height
) const
1217 if (width
) (*width
) = m_width
;
1218 if (height
) (*height
) = m_height
;
1225 if (!m_hasScrolling
)
1228 do we have sunken dialogs ?
1230 GtkStyleClass *window_class = m_wxwindow->style->klass;
1232 dw += 2 * window_class->xthickness;
1233 dh += 2 * window_class->ythickness;
1238 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1239 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1241 GtkWidget
*viewport
= scroll_window
->viewport
;
1242 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1244 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1245 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1247 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1248 (m_windowStyle
& wxSUNKEN_BORDER
)
1251 dw
+= 2 * viewport_class
->xthickness
;
1252 dh
+= 2 * viewport_class
->ythickness
;
1255 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1257 // dw += vscrollbar->allocation.width;
1258 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1259 dw
+= scroll_class
->scrollbar_spacing
;
1262 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1264 // dh += hscrollbar->allocation.height;
1266 dh
+= scroll_class
->scrollbar_spacing
;
1270 if (width
) (*width
) = m_width
- dw
;
1271 if (height
) (*height
) = m_height
- dh
;
1275 void wxWindow::GetPosition( int *x
, int *y
) const
1281 void wxWindow::ClientToScreen( int *x
, int *y
)
1283 // Does this look simple ?
1285 GdkWindow
*source
= NULL
;
1287 source
= m_wxwindow
->window
;
1289 source
= m_widget
->window
;
1293 gdk_window_get_origin( source
, &org_x
, &org_y
);
1297 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1299 org_x
+= m_widget
->allocation
.x
;
1300 org_y
+= m_widget
->allocation
.y
;
1308 void wxWindow::ScreenToClient( int *x
, int *y
)
1310 GdkWindow
*source
= NULL
;
1312 source
= m_wxwindow
->window
;
1314 source
= m_widget
->window
;
1318 gdk_window_get_origin( source
, &org_x
, &org_y
);
1322 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1324 org_x
+= m_widget
->allocation
.x
;
1325 org_y
+= m_widget
->allocation
.y
;
1333 void wxWindow::Centre( int direction
)
1335 if (IS_KIND_OF(this,wxDialog
) || IS_KIND_OF(this,wxFrame
))
1337 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
1338 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
1339 ImplementSetPosition();
1347 m_parent
->GetSize( &p_w
, &p_h
);
1348 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (p_w
- m_width
) / 2;
1349 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (p_h
- m_height
) / 2;
1350 ImplementSetPosition();
1355 void wxWindow::Fit(void)
1359 wxNode
*node
= GetChildren()->First();
1362 wxWindow
*win
= (wxWindow
*)node
->Data();
1364 win
->GetPosition(&wx
, &wy
);
1365 win
->GetSize(&ww
, &wh
);
1366 if ( wx
+ ww
> maxX
)
1368 if ( wy
+ wh
> maxY
)
1371 node
= node
->Next();
1373 SetClientSize(maxX
+ 5, maxY
+ 10);
1376 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1378 //if (GetAutoLayout()) Layout();
1381 bool wxWindow::Show( bool show
)
1384 gtk_widget_show( m_widget
);
1386 gtk_widget_hide( m_widget
);
1391 void wxWindow::Enable( bool enable
)
1393 m_isEnabled
= enable
;
1394 gtk_widget_set_sensitive( m_widget
, enable
);
1395 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1398 void wxWindow::MakeModal( bool modal
)
1401 // Disable all other windows
1402 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1404 wxNode
*node
= wxTopLevelWindows
.First();
1407 wxWindow
*win
= (wxWindow
*)node
->Data();
1409 win
->Enable(!modal
);
1411 node
= node
->Next();
1416 void wxWindow::SetFocus(void)
1418 GtkWidget
*connect_widget
= m_widget
;
1419 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1422 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1424 gtk_widget_grab_focus (connect_widget
);
1429 bool wxWindow::OnClose(void)
1434 void wxWindow::AddChild( wxWindow
*child
)
1436 // Addchild is (often) called before the program
1437 // has left the parents constructor so that no
1438 // virtual tables work yet. The approach below
1439 // practically imitates virtual tables, i.e. it
1440 // implements a different AddChild() behaviour
1441 // for wxFrame, wxDialog, wxWindow and
1442 // wxMDIParentFrame.
1444 // wxFrame and wxDialog as children aren't placed into the parents
1446 if (( IS_KIND_OF(child
,wxFrame
) || IS_KIND_OF(child
,wxDialog
) ) &&
1447 (!IS_KIND_OF(child
,wxMDIChildFrame
)))
1449 m_children
.Append( child
);
1451 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1452 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1457 // In the case of an wxMDIChildFrame descendant, we use the
1458 // client windows's AddChild()
1460 if (IS_KIND_OF(this,wxMDIParentFrame
))
1462 if (IS_KIND_OF(child
,wxMDIChildFrame
))
1464 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1467 client
->AddChild( child
);
1473 // wxNotebook is very special, so it has a private AddChild()
1475 if (IS_KIND_OF(this,wxNotebook
))
1477 wxNotebook
*tab
= (wxNotebook
*)this;
1478 tab
->AddChild( child
);
1482 // wxFrame has a private AddChild
1484 if (IS_KIND_OF(this,wxFrame
) && !IS_KIND_OF(this,wxMDIChildFrame
))
1486 wxFrame
*frame
= (wxFrame
*)this;
1487 frame
->AddChild( child
);
1493 m_children
.Append( child
);
1494 if (m_wxwindow
) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
,
1495 child
->m_x
, child
->m_y
);
1497 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1500 wxList
*wxWindow::GetChildren(void)
1502 return (&m_children
);
1505 void wxWindow::RemoveChild( wxWindow
*child
)
1508 GetChildren()->DeleteObject( child
);
1509 child
->m_parent
= NULL
;
1512 void wxWindow::SetReturnCode( int retCode
)
1514 m_retCode
= retCode
;
1517 int wxWindow::GetReturnCode(void)
1522 wxWindow
*wxWindow::GetParent(void)
1527 wxEvtHandler
*wxWindow::GetEventHandler(void)
1529 return m_eventHandler
;
1532 void wxWindow::SetEventhandler( wxEvtHandler
*handler
)
1534 m_eventHandler
= handler
;
1537 wxValidator
*wxWindow::GetValidator(void)
1539 return m_windowValidator
;
1542 void wxWindow::SetValidator( wxValidator
*validator
)
1544 m_windowValidator
= validator
;
1547 bool wxWindow::IsBeingDeleted(void)
1552 void wxWindow::SetId( wxWindowID id
)
1557 wxWindowID
wxWindow::GetId(void)
1562 void wxWindow::SetCursor( const wxCursor
&cursor
)
1564 if (*m_cursor
== cursor
) return;
1565 (*m_cursor
) = cursor
;
1566 if (m_widget
->window
)
1567 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1568 if (m_wxwindow
&& m_wxwindow
->window
)
1569 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1572 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1574 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1577 gdk_window_clear_area( m_wxwindow
->window
,
1589 wxClientDC
dc(this);
1593 dc
.GetInternalDeviceOrigin( &x
, &y
);
1597 GetClientSize( &w
, &h
);
1599 GdkRectangle gdk_rect
;
1603 gdk_rect
.height
= h
;
1604 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1609 GdkRectangle gdk_rect
;
1610 gdk_rect
.x
= rect
->x
;
1611 gdk_rect
.y
= rect
->y
;
1612 gdk_rect
.width
= rect
->width
;
1613 gdk_rect
.height
= rect
->height
;
1616 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1618 gtk_widget_draw( m_widget
, &gdk_rect
);
1622 bool wxWindow::IsExposed( long x
, long y
)
1624 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1627 bool wxWindow::IsExposed( long x
, long y
, long width
, long height
)
1629 return (m_updateRegion
.Contains( x
, y
, width
, height
) != wxOutRegion
);
1632 void wxWindow::Clear(void)
1634 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1637 wxColour
wxWindow::GetBackgroundColour(void) const
1639 return m_backgroundColour
;
1642 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1644 m_backgroundColour
= colour
;
1647 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1648 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1649 gdk_window_clear( m_wxwindow
->window
);
1654 bool wxWindow::Validate(void)
1656 wxNode
*node
= GetChildren()->First();
1659 wxWindow
*child
= (wxWindow
*)node
->Data();
1660 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1662 node
= node
->Next();
1667 bool wxWindow::TransferDataToWindow(void)
1669 wxNode
*node
= GetChildren()->First();
1672 wxWindow
*child
= (wxWindow
*)node
->Data();
1673 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1674 !child
->GetValidator()->TransferToWindow() )
1676 wxMessageBox( "Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1679 node
= node
->Next();
1684 bool wxWindow::TransferDataFromWindow(void)
1686 wxNode
*node
= GetChildren()->First();
1689 wxWindow
*child
= (wxWindow
*)node
->Data();
1690 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1692 node
= node
->Next();
1697 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1699 TransferDataToWindow();
1702 void wxWindow::InitDialog(void)
1704 wxInitDialogEvent
event(GetId());
1705 event
.SetEventObject( this );
1706 GetEventHandler()->ProcessEvent(event
);
1709 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1711 GtkWidget
*dnd_widget
= GetDropTargetWidget();
1715 gtk_signal_disconnect_by_func( GTK_OBJECT(dnd_widget
),
1716 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1718 m_pDropTarget
->UnregisterWidget( dnd_widget
);
1719 delete m_pDropTarget
;
1721 m_pDropTarget
= dropTarget
;
1724 m_pDropTarget
->RegisterWidget( dnd_widget
);
1726 gtk_signal_connect( GTK_OBJECT(dnd_widget
), "drop_data_available_event",
1727 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1731 wxDropTarget
*wxWindow::GetDropTarget() const
1733 return m_pDropTarget
;
1736 GtkWidget
* wxWindow::GetDropTargetWidget(void)
1738 GtkWidget
*connect_widget
= m_widget
;
1739 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1741 return connect_widget
;
1744 void wxWindow::SetFont( const wxFont
&font
)
1749 copy old style values to new one
1750 set font in new style
1751 -> takes to many resources
1753 GtkStyle *style = gtk_style_new();
1758 wxFont
*wxWindow::GetFont(void)
1763 void wxWindow::SetWindowStyleFlag( long flag
)
1765 m_windowStyle
= flag
;
1768 long wxWindow::GetWindowStyleFlag(void) const
1770 return m_windowStyle
;
1773 void wxWindow::CaptureMouse(void)
1775 GtkWidget
*connect_widget
= m_widget
;
1776 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1777 gtk_grab_add( connect_widget
);
1778 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1780 (GDK_BUTTON_PRESS_MASK
|
1781 GDK_BUTTON_RELEASE_MASK
|
1782 GDK_POINTER_MOTION_MASK
),
1783 NULL
, NULL
, GDK_CURRENT_TIME
);
1786 void wxWindow::ReleaseMouse(void)
1788 GtkWidget
*connect_widget
= m_widget
;
1789 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1790 gtk_grab_remove( connect_widget
);
1791 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1794 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1798 wxString
wxWindow::GetTitle(void) const
1800 return (wxString
&)m_windowName
;
1803 wxString
wxWindow::GetLabel(void) const
1808 void wxWindow::SetName( const wxString
&name
)
1810 m_windowName
= name
;
1813 wxString
wxWindow::GetName(void) const
1815 return (wxString
&)m_windowName
;
1818 bool wxWindow::IsShown(void) const
1823 bool wxWindow::IsRetained(void)
1828 wxWindow
*wxWindow::FindWindow( long id
)
1830 if (id
== m_windowId
) return this;
1831 wxNode
*node
= m_children
.First();
1834 wxWindow
*child
= (wxWindow
*)node
->Data();
1835 wxWindow
*res
= child
->FindWindow( id
);
1836 if (res
) return res
;
1837 node
= node
->Next();
1842 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1844 if (name
== m_windowName
) return this;
1845 wxNode
*node
= m_children
.First();
1848 wxWindow
*child
= (wxWindow
*)node
->Data();
1849 wxWindow
*res
= child
->FindWindow( name
);
1850 if (res
) return res
;
1851 node
= node
->Next();
1856 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1857 int range
, bool WXUNUSED(refresh
) )
1859 if (!m_wxwindow
) return;
1861 if (orient
== wxHORIZONTAL
)
1863 float fpos
= (float)pos
;
1864 m_oldHorizontalPos
= fpos
;
1865 float frange
= (float)range
;
1866 float fthumb
= (float)thumbVisible
;
1868 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1869 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1870 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1873 m_hAdjust
->lower
= 0.0;
1874 m_hAdjust
->upper
= frange
;
1875 m_hAdjust
->value
= fpos
;
1876 m_hAdjust
->step_increment
= 1.0;
1877 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1878 m_hAdjust
->page_size
= fthumb
;
1882 float fpos
= (float)pos
;
1883 m_oldVerticalPos
= fpos
;
1884 float frange
= (float)range
;
1885 float fthumb
= (float)thumbVisible
;
1887 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1888 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1889 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1892 m_vAdjust
->lower
= 0.0;
1893 m_vAdjust
->upper
= frange
;
1894 m_vAdjust
->value
= fpos
;
1895 m_vAdjust
->step_increment
= 1.0;
1896 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1897 m_vAdjust
->page_size
= fthumb
;
1900 if (m_wxwindow
->window
)
1902 if (orient
== wxHORIZONTAL
)
1905 m_drawingOffsetX = -16000;
1907 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1909 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
1914 m_drawingOffsetY = -16000;
1916 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1918 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
1921 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1925 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
1927 if (!m_wxwindow
) return;
1929 if (orient
== wxHORIZONTAL
)
1931 float fpos
= (float)pos
;
1932 m_oldHorizontalPos
= fpos
;
1934 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
1935 m_hAdjust
->value
= fpos
;
1939 float fpos
= (float)pos
;
1940 m_oldVerticalPos
= fpos
;
1941 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
1942 m_vAdjust
->value
= fpos
;
1945 if (m_wxwindow
->window
)
1947 if (orient
== wxHORIZONTAL
)
1948 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
1950 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
1954 int wxWindow::GetScrollThumb( int orient
) const
1956 if (!m_wxwindow
) return 0;
1958 if (orient
== wxHORIZONTAL
)
1959 return (int)(m_hAdjust
->page_size
+0.5);
1961 return (int)(m_vAdjust
->page_size
+0.5);
1964 int wxWindow::GetScrollPos( int orient
) const
1966 if (!m_wxwindow
) return 0;
1968 if (orient
== wxHORIZONTAL
)
1969 return (int)(m_hAdjust
->value
+0.5);
1971 return (int)(m_vAdjust
->value
+0.5);
1974 int wxWindow::GetScrollRange( int orient
) const
1976 if (!m_wxwindow
) return 0;
1978 if (orient
== wxHORIZONTAL
)
1979 return (int)(m_hAdjust
->upper
+0.5);
1981 return (int)(m_vAdjust
->upper
+0.5);
1984 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
1986 if (!m_wxwindow
) return;
1988 bool refresh
= FALSE
;
1990 if ((m_drawingOffsetX
== 0) && (m_drawingOffsetY
== 0))
1992 m_drawingOffsetX
= -16000;
1993 m_drawingOffsetY
= -16000;
1998 m_drawingOffsetX
+= dx
;
1999 m_drawingOffsetY
+= dy
;
2002 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
2004 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow
), m_drawingOffsetX
, m_drawingOffsetY
);
2006 if (refresh
) Refresh();
2009 The code here is very nifty, but it doesn't work with
2010 overlapping windows...
2014 GetClientSize( &cw, &ch );
2016 int w = cw - abs(dx);
2017 int h = ch - abs(dy);
2018 if ((h < 0) || (w < 0))
2025 if (dx < 0) s_x = -dx;
2026 if (dy < 0) s_y = -dy;
2029 if (dx > 0) d_x = dx;
2030 if (dy > 0) d_y = dy;
2031 gdk_window_copy_area( m_wxwindow->window, m_wxwindow->style->fg_gc[0], d_x, d_y,
2032 m_wxwindow->window, s_x, s_y, w, h );
2035 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
2036 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
2037 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
2038 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
2040 Refresh( TRUE, &rect );
2044 void wxWindow::GetDrawingOffset( long *x
, long *y
)
2046 if (x
) *x
= m_drawingOffsetX
;
2047 if (y
) *y
= m_drawingOffsetY
;
2050 //-------------------------------------------------------------------------------------
2052 //-------------------------------------------------------------------------------------
2054 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
2056 return m_constraints
;
2059 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
2063 UnsetConstraints(m_constraints
);
2064 delete m_constraints
;
2066 m_constraints
= constraints
;
2069 // Make sure other windows know they're part of a 'meaningful relationship'
2070 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
2071 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2072 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
2073 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2074 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
2075 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2076 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
2077 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2078 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
2079 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2080 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
2081 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2082 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
2083 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2084 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
2085 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2091 void wxWindow::SetAutoLayout( bool autoLayout
)
2093 m_autoLayout
= autoLayout
;
2096 bool wxWindow::GetAutoLayout(void) const
2098 return m_autoLayout
;
2101 wxSizer
*wxWindow::GetSizer(void) const
2103 return m_windowSizer
;
2106 void wxWindow::SetSizerParent( wxWindow
*win
)
2108 m_sizerParent
= win
;
2111 wxWindow
*wxWindow::GetSizerParent(void) const
2113 return m_sizerParent
;
2116 // This removes any dangling pointers to this window
2117 // in other windows' constraintsInvolvedIn lists.
2118 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2122 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2123 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2124 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2125 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2126 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2127 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2128 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2129 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2130 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2131 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2132 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2133 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2134 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2135 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2136 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2137 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2141 // Back-pointer to other windows we're involved with, so if we delete
2142 // this window, we must delete any constraints we're involved with.
2143 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2145 if (!m_constraintsInvolvedIn
)
2146 m_constraintsInvolvedIn
= new wxList
;
2147 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2148 m_constraintsInvolvedIn
->Append(otherWin
);
2151 // REMOVE back-pointer to other windows we're involved with.
2152 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2154 if (m_constraintsInvolvedIn
)
2155 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2158 // Reset any constraints that mention this window
2159 void wxWindow::DeleteRelatedConstraints(void)
2161 if (m_constraintsInvolvedIn
)
2163 wxNode
*node
= m_constraintsInvolvedIn
->First();
2166 wxWindow
*win
= (wxWindow
*)node
->Data();
2167 wxNode
*next
= node
->Next();
2168 wxLayoutConstraints
*constr
= win
->GetConstraints();
2170 // Reset any constraints involving this window
2173 constr
->left
.ResetIfWin((wxWindow
*)this);
2174 constr
->top
.ResetIfWin((wxWindow
*)this);
2175 constr
->right
.ResetIfWin((wxWindow
*)this);
2176 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2177 constr
->width
.ResetIfWin((wxWindow
*)this);
2178 constr
->height
.ResetIfWin((wxWindow
*)this);
2179 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2180 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2185 delete m_constraintsInvolvedIn
;
2186 m_constraintsInvolvedIn
= NULL
;
2190 void wxWindow::SetSizer(wxSizer
*sizer
)
2192 m_windowSizer
= sizer
;
2194 sizer
->SetSizerParent((wxWindow
*)this);
2201 bool wxWindow::Layout(void)
2203 if (GetConstraints())
2206 GetClientSize(&w
, &h
);
2207 GetConstraints()->width
.SetValue(w
);
2208 GetConstraints()->height
.SetValue(h
);
2211 // If top level (one sizer), evaluate the sizer's constraints.
2215 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2216 GetSizer()->LayoutPhase1(&noChanges
);
2217 GetSizer()->LayoutPhase2(&noChanges
);
2218 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2223 // Otherwise, evaluate child constraints
2224 ResetConstraints(); // Mark all constraints as unevaluated
2225 DoPhase(1); // Just one phase need if no sizers involved
2227 SetConstraintSizes(); // Recursively set the real window sizes
2233 // Do a phase of evaluating constraints:
2234 // the default behaviour. wxSizers may do a similar
2235 // thing, but also impose their own 'constraints'
2236 // and order the evaluation differently.
2237 bool wxWindow::LayoutPhase1(int *noChanges
)
2239 wxLayoutConstraints
*constr
= GetConstraints();
2242 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2248 bool wxWindow::LayoutPhase2(int *noChanges
)
2258 // Do a phase of evaluating child constraints
2259 bool wxWindow::DoPhase(int phase
)
2261 int noIterations
= 0;
2262 int maxIterations
= 500;
2266 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2270 wxNode
*node
= GetChildren()->First();
2273 wxWindow
*child
= (wxWindow
*)node
->Data();
2274 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2276 wxLayoutConstraints
*constr
= child
->GetConstraints();
2279 if (succeeded
.Member(child
))
2284 int tempNoChanges
= 0;
2285 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2286 noChanges
+= tempNoChanges
;
2289 succeeded
.Append(child
);
2294 node
= node
->Next();
2301 void wxWindow::ResetConstraints(void)
2303 wxLayoutConstraints
*constr
= GetConstraints();
2306 constr
->left
.SetDone(FALSE
);
2307 constr
->top
.SetDone(FALSE
);
2308 constr
->right
.SetDone(FALSE
);
2309 constr
->bottom
.SetDone(FALSE
);
2310 constr
->width
.SetDone(FALSE
);
2311 constr
->height
.SetDone(FALSE
);
2312 constr
->centreX
.SetDone(FALSE
);
2313 constr
->centreY
.SetDone(FALSE
);
2315 wxNode
*node
= GetChildren()->First();
2318 wxWindow
*win
= (wxWindow
*)node
->Data();
2319 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2320 win
->ResetConstraints();
2321 node
= node
->Next();
2325 // Need to distinguish between setting the 'fake' size for
2326 // windows and sizers, and setting the real values.
2327 void wxWindow::SetConstraintSizes(bool recurse
)
2329 wxLayoutConstraints
*constr
= GetConstraints();
2330 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2331 constr
->width
.GetDone() && constr
->height
.GetDone())
2333 int x
= constr
->left
.GetValue();
2334 int y
= constr
->top
.GetValue();
2335 int w
= constr
->width
.GetValue();
2336 int h
= constr
->height
.GetValue();
2338 // If we don't want to resize this window, just move it...
2339 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2340 (constr
->height
.GetRelationship() != wxAsIs
))
2342 // Calls Layout() recursively. AAAGH. How can we stop that.
2343 // Simply take Layout() out of non-top level OnSizes.
2344 SizerSetSize(x
, y
, w
, h
);
2353 char *windowClass
= this->GetClassInfo()->GetClassName();
2356 if (GetName() == "")
2357 winName
= "unnamed";
2359 winName
= GetName();
2360 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
2361 if (!constr
->left
.GetDone())
2362 wxDebugMsg(" unsatisfied 'left' constraint.\n");
2363 if (!constr
->right
.GetDone())
2364 wxDebugMsg(" unsatisfied 'right' constraint.\n");
2365 if (!constr
->width
.GetDone())
2366 wxDebugMsg(" unsatisfied 'width' constraint.\n");
2367 if (!constr
->height
.GetDone())
2368 wxDebugMsg(" unsatisfied 'height' constraint.\n");
2369 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
2374 wxNode
*node
= GetChildren()->First();
2377 wxWindow
*win
= (wxWindow
*)node
->Data();
2378 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2379 win
->SetConstraintSizes();
2380 node
= node
->Next();
2385 // This assumes that all sizers are 'on' the same
2386 // window, i.e. the parent of this window.
2387 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2389 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2390 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2394 m_sizerParent
->GetPosition(&xp
, &yp
);
2395 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2400 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2404 TransformSizerToActual(&xx
, &yy
);
2405 SetSize(xx
, yy
, w
, h
);
2408 void wxWindow::SizerMove(int x
, int y
)
2412 TransformSizerToActual(&xx
, &yy
);
2416 // Only set the size/position of the constraint (if any)
2417 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2419 wxLayoutConstraints
*constr
= GetConstraints();
2424 constr
->left
.SetValue(x
);
2425 constr
->left
.SetDone(TRUE
);
2429 constr
->top
.SetValue(y
);
2430 constr
->top
.SetDone(TRUE
);
2434 constr
->width
.SetValue(w
);
2435 constr
->width
.SetDone(TRUE
);
2439 constr
->height
.SetValue(h
);
2440 constr
->height
.SetDone(TRUE
);
2445 void wxWindow::MoveConstraint(int x
, int y
)
2447 wxLayoutConstraints
*constr
= GetConstraints();
2452 constr
->left
.SetValue(x
);
2453 constr
->left
.SetDone(TRUE
);
2457 constr
->top
.SetValue(y
);
2458 constr
->top
.SetDone(TRUE
);
2463 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2465 wxLayoutConstraints
*constr
= GetConstraints();
2468 *w
= constr
->width
.GetValue();
2469 *h
= constr
->height
.GetValue();
2475 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2477 wxLayoutConstraints
*constr
= GetConstraints();
2480 *w
= constr
->width
.GetValue();
2481 *h
= constr
->height
.GetValue();
2484 GetClientSize(w
, h
);
2487 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2489 wxLayoutConstraints
*constr
= GetConstraints();
2492 *x
= constr
->left
.GetValue();
2493 *y
= constr
->top
.GetValue();
2499 bool wxWindow::AcceptsFocus() const
2501 return IsEnabled() && IsShown();
2504 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
) )