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"
31 //#include "wx/treectrl.h"
32 #include "gdk/gdkkeysyms.h"
34 #include "wx/gtk/win_gtk.h"
35 #include "gdk/gdkprivate.h"
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 extern wxList wxPendingDelete
;
42 extern wxList wxTopLevelWindows
;
43 extern bool g_blockEventsOnDrag
;
45 //-----------------------------------------------------------------------------
46 // GTK callbacks for wxWindows event system
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
50 // expose (of m_wxwindow, not of m_widget)
52 void gtk_window_expose_callback( GtkWidget
*WXUNUSED(widget
), GdkEventExpose
*gdk_event
, wxWindow
*win
)
54 if (!win
->HasVMT()) return;
55 if (g_blockEventsOnDrag
) return;
58 if (IS_KIND_OF(win,wxTreeCtrl))
60 printf( "OnExpose from " );
61 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
62 printf( win->GetClassInfo()->GetClassName() );
65 printf( "x: %d \n", gdk_event->area.x );
66 printf( "y: %d \n", gdk_event->area.y );
67 printf( "w: %d \n", gdk_event->area.width );
68 printf( "h: %d \n", gdk_event->area.height );
72 win
->m_updateRegion
.Union( gdk_event
->area
.x
,
74 gdk_event
->area
.width
,
75 gdk_event
->area
.height
);
77 if (gdk_event
->count
> 0) return;
79 wxPaintEvent
event( win
->GetId() );
80 event
.SetEventObject( win
);
81 win
->ProcessEvent( event
);
83 win
->m_updateRegion
.Clear();
86 //-----------------------------------------------------------------------------
87 // draw (of m_wxwindow, not of m_widget)
89 void gtk_window_draw_callback( GtkWidget
*WXUNUSED(widget
), GdkRectangle
*rect
, wxWindow
*win
)
91 if (!win
->HasVMT()) return;
92 if (g_blockEventsOnDrag
) return;
95 printf( "OnDraw from " );
96 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
97 printf( win->GetClassInfo()->GetClassName() );
100 printf( "x: %d \n", rect->x );
101 printf( "y: %d \n", rect->y );
102 printf( "w: %d \n", rect->width );
103 printf( "h: %d \n", rect->height );
106 win
->m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
108 wxPaintEvent
event( win
->GetId() );
109 event
.SetEventObject( win
);
110 win
->ProcessEvent( event
);
112 win
->m_updateRegion
.Clear();
115 //-----------------------------------------------------------------------------
117 // I don't any longer intercept GTK's internal resize events, except
118 // for frames and from within MDI and tabbed windows (client area
119 // size determined internally by GTK, not wxWin).
122 void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
124 if (!win->HasVMT()) return;
125 if (g_blockEventsOnDrag) return;
129 if ((win->m_x == alloc->x) &&
130 (win->m_y == alloc->y) &&
131 (win->m_width == alloc->width) &&
132 (win->m_height == alloc->height))
137 printf( "OnResize from " );
138 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
139 printf( win->GetClassInfo()->GetClassName() );
142 printf( " Old: X: %d Y: %d ", win->m_x, win->m_y );
143 printf( " W: %d H: %d ", win->m_width, win->m_height );
146 printf( " New: X: %d Y: %d ", alloc->x, alloc->y );
147 printf( " W: %d H: %d ", alloc->width, alloc->height );
150 wxSizeEvent event( wxSize( alloc->width, alloc->height), win->GetId() );
151 event.SetEventObject( win );
152 win->ProcessEvent( event );
156 //-----------------------------------------------------------------------------
159 gint
gtk_window_key_press_callback( GtkWidget
*WXUNUSED(widget
), GdkEventKey
*gdk_event
, wxWindow
*win
)
161 if (!win
->HasVMT()) return FALSE
;
162 if (g_blockEventsOnDrag
) return FALSE
;
165 printf( "OnKeyPress from " );
166 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
167 printf( win->GetClassInfo()->GetClassName() );
172 switch (gdk_event
->keyval
)
174 case GDK_BackSpace
: key_code
= WXK_BACK
; break;
175 case GDK_Tab
: key_code
= WXK_TAB
; break;
176 case GDK_Linefeed
: key_code
= WXK_RETURN
; break;
177 case GDK_Clear
: key_code
= WXK_CLEAR
; break;
178 case GDK_Return
: key_code
= WXK_RETURN
; break;
179 case GDK_Pause
: key_code
= WXK_PAUSE
; break;
180 case GDK_Scroll_Lock
: key_code
= WXK_SCROLL
; break;
181 case GDK_Escape
: key_code
= WXK_ESCAPE
; break;
182 case GDK_Delete
: key_code
= WXK_DELETE
; break;
183 case GDK_Home
: key_code
= WXK_HOME
; break;
184 case GDK_Left
: key_code
= WXK_LEFT
; break;
185 case GDK_Up
: key_code
= WXK_UP
; break;
186 case GDK_Right
: key_code
= WXK_RIGHT
; break;
187 case GDK_Down
: key_code
= WXK_DOWN
; break;
188 case GDK_Prior
: key_code
= WXK_PRIOR
; break;
189 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
190 case GDK_Next
: key_code
= WXK_NEXT
; break;
191 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
192 case GDK_End
: key_code
= WXK_END
; break;
193 case GDK_Begin
: key_code
= WXK_HOME
; break;
194 case GDK_Select
: key_code
= WXK_SELECT
; break;
195 case GDK_Print
: key_code
= WXK_PRINT
; break;
196 case GDK_Execute
: key_code
= WXK_EXECUTE
; break;
197 case GDK_Insert
: key_code
= WXK_INSERT
; break;
198 case GDK_Num_Lock
: key_code
= WXK_NUMLOCK
; break;
199 case GDK_KP_Tab
: key_code
= WXK_TAB
; break;
200 case GDK_KP_Enter
: key_code
= WXK_RETURN
; break;
201 case GDK_KP_Home
: key_code
= WXK_HOME
; break;
202 case GDK_KP_Left
: key_code
= WXK_LEFT
; break;
203 case GDK_KP_Up
: key_code
= WXK_UP
; break;
204 case GDK_KP_Right
: key_code
= WXK_RIGHT
; break;
205 case GDK_KP_Down
: key_code
= WXK_DOWN
; break;
206 case GDK_KP_Prior
: key_code
= WXK_PRIOR
; break;
207 // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
208 case GDK_KP_Next
: key_code
= WXK_NEXT
; break;
209 // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
210 case GDK_KP_End
: key_code
= WXK_END
; break;
211 case GDK_KP_Begin
: key_code
= WXK_HOME
; break;
212 case GDK_KP_Insert
: key_code
= WXK_INSERT
; break;
213 case GDK_KP_Delete
: key_code
= WXK_DELETE
; break;
214 case GDK_KP_Multiply
: key_code
= WXK_MULTIPLY
; break;
215 case GDK_KP_Add
: key_code
= WXK_ADD
; break;
216 case GDK_KP_Separator
: key_code
= WXK_SEPARATOR
; break;
217 case GDK_KP_Subtract
: key_code
= WXK_SUBTRACT
; break;
218 case GDK_KP_Decimal
: key_code
= WXK_DECIMAL
; break;
219 case GDK_KP_Divide
: key_code
= WXK_DIVIDE
; break;
220 case GDK_KP_0
: key_code
= WXK_NUMPAD0
; break;
221 case GDK_KP_1
: key_code
= WXK_NUMPAD1
; break;
222 case GDK_KP_2
: key_code
= WXK_NUMPAD2
; break;
223 case GDK_KP_3
: key_code
= WXK_NUMPAD3
; break;
224 case GDK_KP_4
: key_code
= WXK_NUMPAD4
; break;
225 case GDK_KP_5
: key_code
= WXK_NUMPAD5
; break;
226 case GDK_KP_6
: key_code
= WXK_NUMPAD6
; break;
227 case GDK_KP_7
: key_code
= WXK_NUMPAD7
; break;
228 case GDK_KP_8
: key_code
= WXK_NUMPAD7
; break;
229 case GDK_KP_9
: key_code
= WXK_NUMPAD9
; break;
230 case GDK_F1
: key_code
= WXK_F1
; break;
231 case GDK_F2
: key_code
= WXK_F2
; break;
232 case GDK_F3
: key_code
= WXK_F3
; break;
233 case GDK_F4
: key_code
= WXK_F4
; break;
234 case GDK_F5
: key_code
= WXK_F5
; break;
235 case GDK_F6
: key_code
= WXK_F6
; break;
236 case GDK_F7
: key_code
= WXK_F7
; break;
237 case GDK_F8
: key_code
= WXK_F8
; break;
238 case GDK_F9
: key_code
= WXK_F9
; break;
239 case GDK_F10
: key_code
= WXK_F10
; break;
240 case GDK_F11
: key_code
= WXK_F11
; break;
241 case GDK_F12
: key_code
= WXK_F12
; break;
244 if ((gdk_event
->keyval
>= 0x20) && (gdk_event
->keyval
<= 0xFF))
245 key_code
= gdk_event
->keyval
;
249 if (!key_code
) return FALSE
;
251 wxKeyEvent
event( wxEVT_CHAR
);
252 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
253 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
254 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
255 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
256 event
.m_keyCode
= key_code
;
259 event
.SetEventObject( win
);
261 bool ret
= win
->ProcessEvent( event
);
263 if (ret) printf( "found.\n") ;
268 //-----------------------------------------------------------------------------
271 gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
273 if (widget
->window
!= gdk_event
->window
) return TRUE
;
274 if (g_blockEventsOnDrag
) return TRUE
;
278 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
) && !GTK_WIDGET_HAS_FOCUS (win
->m_wxwindow
) )
280 gtk_widget_grab_focus (win
->m_wxwindow
);
283 printf( "GrabFocus from " );
284 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
285 printf( win->GetClassInfo()->GetClassName() );
292 if (!win
->HasVMT()) return TRUE
;
295 printf( "OnButtonPress from " );
296 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
297 printf( win->GetClassInfo()->GetClassName() );
301 wxEventType event_type
= wxEVT_LEFT_DOWN
;
303 if (gdk_event
->button
== 1)
305 switch (gdk_event
->type
)
307 case GDK_BUTTON_PRESS
: event_type
= wxEVT_LEFT_DOWN
; break;
308 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_LEFT_DCLICK
; break;
312 else if (gdk_event
->button
== 2)
314 switch (gdk_event
->type
)
316 case GDK_BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DOWN
; break;
317 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DCLICK
; break;
321 else if (gdk_event
->button
== 3)
323 switch (gdk_event
->type
)
325 case GDK_BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DOWN
; break;
326 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DCLICK
; break;
331 wxMouseEvent
event( event_type
);
332 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
333 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
334 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
335 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
336 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
337 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
338 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
340 event
.m_x
= (long)gdk_event
->x
;
341 event
.m_y
= (long)gdk_event
->y
;
342 event
.SetEventObject( win
);
344 win
->ProcessEvent( event
);
349 //-----------------------------------------------------------------------------
352 gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
354 if (widget
->window
!= gdk_event
->window
) return TRUE
;
356 if (g_blockEventsOnDrag
) return TRUE
;
358 if (!win
->HasVMT()) return TRUE
;
361 printf( "OnButtonRelease from " );
362 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
363 printf( win->GetClassInfo()->GetClassName() );
367 wxEventType event_type
= wxEVT_NULL
;
369 switch (gdk_event
->button
)
371 case 1: event_type
= wxEVT_LEFT_UP
; break;
372 case 2: event_type
= wxEVT_MIDDLE_UP
; break;
373 case 3: event_type
= wxEVT_RIGHT_UP
; break;
376 wxMouseEvent
event( event_type
);
377 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
378 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
379 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
380 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
381 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
382 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
383 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
384 event
.m_x
= (long)gdk_event
->x
;
385 event
.m_y
= (long)gdk_event
->y
;
386 event
.SetEventObject( win
);
388 win
->ProcessEvent( event
);
393 //-----------------------------------------------------------------------------
396 gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxWindow
*win
)
398 if (widget
->window
!= gdk_event
->window
) return TRUE
;
400 if (g_blockEventsOnDrag
) return TRUE
;
402 if (!win
->HasVMT()) return TRUE
;
405 printf( "OnMotion from " );
406 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
407 printf( win->GetClassInfo()->GetClassName() );
411 wxMouseEvent
event( wxEVT_MOTION
);
412 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
413 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
414 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
415 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
416 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
417 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
418 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
420 event
.m_x
= (long)gdk_event
->x
;
421 event
.m_y
= (long)gdk_event
->y
;
422 event
.SetEventObject( win
);
424 win
->ProcessEvent( event
);
429 //-----------------------------------------------------------------------------
432 gint
gtk_window_focus_in_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
434 if (g_blockEventsOnDrag
) return TRUE
;
437 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
439 GTK_WIDGET_SET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
441 printf( "SetFocus flag from " );
442 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
443 printf( win->GetClassInfo()->GetClassName() );
449 if (!win
->HasVMT()) return TRUE
;
452 printf( "OnSetFocus from " );
453 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
454 printf( win->GetClassInfo()->GetClassName() );
456 printf( WXSTRINGCAST win->GetLabel() );
460 wxFocusEvent
event( wxEVT_SET_FOCUS
, win
->GetId() );
461 event
.SetEventObject( win
);
462 win
->ProcessEvent( event
);
467 //-----------------------------------------------------------------------------
470 gint
gtk_window_focus_out_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
472 if (g_blockEventsOnDrag
) return TRUE
;
475 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
476 GTK_WIDGET_UNSET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
479 if (!win
->HasVMT()) return TRUE
;
482 printf( "OnKillFocus from " );
483 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
484 printf( win->GetClassInfo()->GetClassName() );
488 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
489 event
.SetEventObject( win
);
490 win
->ProcessEvent( event
);
495 //-----------------------------------------------------------------------------
498 void gtk_window_vscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
500 if (g_blockEventsOnDrag
) return;
503 printf( "OnVScroll from " );
504 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
505 printf( win->GetClassInfo()->GetClassName() );
509 if (!win
->HasVMT()) return;
511 float diff
= win
->m_vAdjust
->value
- win
->m_oldVerticalPos
;
512 if (fabs(diff
) < 0.2) return;
515 int i = (int)(win->m_oldVerticalPos+0.5);
516 printf( "Old value: %d.\n", i );
517 i = (int)(win->m_vAdjust->value+0.5);
518 printf( "Sending new value: %d.\n", i );
521 wxEventType command
= wxEVT_NULL
;
523 float line_step
= win
->m_vAdjust
->step_increment
;
524 float page_step
= win
->m_vAdjust
->page_increment
;
526 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
527 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
528 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
529 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
530 else command
= wxEVT_SCROLL_THUMBTRACK
;
532 int value
= (int)(win
->m_vAdjust
->value
+0.5);
534 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
535 event
.SetEventObject( win
);
536 win
->ProcessEvent( event
);
539 //-----------------------------------------------------------------------------
542 void gtk_window_hscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
544 if (g_blockEventsOnDrag
) return;
547 printf( "OnHScroll from " );
548 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
549 printf( win->GetClassInfo()->GetClassName() );
553 if (!win
->HasVMT()) return;
555 float diff
= win
->m_hAdjust
->value
- win
->m_oldHorizontalPos
;
556 if (fabs(diff
) < 0.2) return;
559 int i = (int)(win->m_oldHorizontalPos+0.5);
560 printf( "Old value: %d.\n", i );
561 i = (int)(win->m_hAdjust->value+0.5);
562 printf( "Sending new value: %d.\n", i );
565 wxEventType command
= wxEVT_NULL
;
567 float line_step
= win
->m_hAdjust
->step_increment
;
568 float page_step
= win
->m_hAdjust
->page_increment
;
570 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
571 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
572 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
573 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
574 else command
= wxEVT_SCROLL_THUMBTRACK
;
576 int value
= (int)(win
->m_hAdjust
->value
+0.5);
578 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
579 event
.SetEventObject( win
);
580 win
->ProcessEvent( event
);
583 //-----------------------------------------------------------------------------
584 // vertical scroll change
586 void gtk_window_vscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
588 if (g_blockEventsOnDrag
) return;
591 printf( "OnVScroll change from " );
592 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
593 printf( win->GetClassInfo()->GetClassName() );
597 if (!win
->HasVMT()) return;
599 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
600 int value
= (int)(win
->m_vAdjust
->value
+0.5);
602 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
603 event
.SetEventObject( win
);
604 win
->ProcessEvent( event
);
607 //-----------------------------------------------------------------------------
608 // horizontal scroll change
610 void gtk_window_hscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
612 if (g_blockEventsOnDrag
) return;
615 printf( "OnHScroll change from " );
616 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
617 printf( win->GetClassInfo()->GetClassName() );
621 if (!win
->HasVMT()) return;
623 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
624 int value
= (int)(win
->m_hAdjust
->value
+0.5);
626 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
627 event
.SetEventObject( win
);
628 win
->ProcessEvent( event
);
631 //-----------------------------------------------------------------------------
634 void gtk_window_drop_callback( GtkWidget
*widget
, GdkEvent
*event
, wxWindow
*win
)
636 if (!win
->HasVMT()) return;
638 if (win
->GetDropTarget())
642 gdk_window_get_pointer( widget
->window
, &x
, &y
, NULL
);
643 win
->GetDropTarget()->Drop( event
, x
, y
);
647 g_free (event->dropdataavailable.data);
648 g_free (event->dropdataavailable.data_type);
652 //-----------------------------------------------------------------------------
655 bool gtk_window_destroy_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
657 printf( "OnDestroy from " );
658 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
659 printf( win
->GetClassInfo()->GetClassName() );
661 printf( "Goodbye.\n" );
662 printf( " Robert Roebling.\n" );
667 //-----------------------------------------------------------------------------
670 bool gtk_window_enter_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
672 if (widget
->window
!= gdk_event
->window
) return TRUE
;
673 if (g_blockEventsOnDrag
) return TRUE
;
674 if (!win
->HasVMT()) return TRUE
;
677 gdk_window_set_cursor( widget
->window
, win
->m_cursor
->GetCursor() );
679 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
680 event
.SetEventObject( win
);
681 return win
->ProcessEvent( event
);
684 //-----------------------------------------------------------------------------
687 bool gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
689 if (widget
->window
!= gdk_event
->window
) return TRUE
;
690 if (!win
->HasVMT()) return TRUE
;
691 if (g_blockEventsOnDrag
) return TRUE
;
694 gdk_window_set_cursor( widget
->window
, wxSTANDARD_CURSOR
->GetCursor() );
696 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
697 event
.SetEventObject( win
);
698 return win
->ProcessEvent( event
);
701 //-----------------------------------------------------------------------------
702 // wxWindow implementation
703 //-----------------------------------------------------------------------------
705 IMPLEMENT_DYNAMIC_CLASS(wxWindow
,wxEvtHandler
)
707 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
708 EVT_SIZE(wxWindow::OnSize
)
709 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
710 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
711 EVT_IDLE(wxWindow::OnIdle
)
719 m_children
.DeleteContents( FALSE
);
725 m_eventHandler
= this;
726 m_windowValidator
= NULL
;
728 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
729 m_font
= *wxSWISS_FONT
;
731 m_windowName
= "noname";
732 m_constraints
= NULL
;
733 m_constraintsInvolvedIn
= NULL
;
734 m_windowSizer
= NULL
;
735 m_sizerParent
= NULL
;
736 m_autoLayout
= FALSE
;
740 m_hasScrolling
= FALSE
;
743 m_oldHorizontalPos
= 0.0;
744 m_oldVerticalPos
= 0.0;
747 m_drawingOffsetX
= 0;
748 m_drawingOffsetY
= 0;
749 m_pDropTarget
= NULL
;
753 wxWindow::wxWindow( wxWindow
*parent
, wxWindowID id
,
754 const wxPoint
&pos
, const wxSize
&size
,
755 long style
, const wxString
&name
)
758 Create( parent
, id
, pos
, size
, style
, name
);
761 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
762 const wxPoint
&pos
, const wxSize
&size
,
763 long style
, const wxString
&name
)
769 PreCreation( parent
, id
, pos
, size
, style
, name
);
771 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
772 m_hasScrolling
= TRUE
;
774 GtkScrolledWindow
*s_window
;
775 s_window
= GTK_SCROLLED_WINDOW(m_widget
);
777 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
778 scroll_class
->scrollbar_spacing
= 0;
780 gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
782 m_oldHorizontalPos
= 0.0;
783 m_oldVerticalPos
= 0.0;
785 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) );
786 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) );
788 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "value_changed",
789 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
790 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "value_changed",
791 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
793 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "changed",
794 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
795 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "changed",
796 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
798 GtkViewport
*viewport
;
799 viewport
= GTK_VIEWPORT(s_window
->viewport
);
801 if (m_windowStyle
& wxRAISED_BORDER
)
803 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
805 else if (m_windowStyle
& wxSUNKEN_BORDER
)
807 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
811 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
814 m_wxwindow
= gtk_myfixed_new();
816 if (m_wxwindow
) GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
818 if (m_windowStyle
& wxTAB_TRAVERSAL
== wxTAB_TRAVERSAL
)
819 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
821 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
823 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
825 // shut the viewport up
826 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
827 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
829 // I _really_ don't want scrollbars in the beginning
830 m_vAdjust
->lower
= 0.0;
831 m_vAdjust
->upper
= 1.0;
832 m_vAdjust
->value
= 0.0;
833 m_vAdjust
->step_increment
= 1.0;
834 m_vAdjust
->page_increment
= 1.0;
835 m_vAdjust
->page_size
= 5.0;
836 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
837 m_hAdjust
->lower
= 0.0;
838 m_hAdjust
->upper
= 1.0;
839 m_hAdjust
->value
= 0.0;
840 m_hAdjust
->step_increment
= 1.0;
841 m_hAdjust
->page_increment
= 1.0;
842 m_hAdjust
->page_size
= 5.0;
843 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
845 gtk_widget_show( m_wxwindow
);
854 wxWindow::~wxWindow(void)
858 if (m_pDropTarget
) delete m_pDropTarget
;
860 if (m_parent
) m_parent
->RemoveChild( this );
861 if (m_widget
) Show( FALSE
);
865 if (m_wxwindow
) gtk_widget_destroy( m_wxwindow
);
867 if (m_widget
) gtk_widget_destroy( m_widget
);
871 DeleteRelatedConstraints();
874 // This removes any dangling pointers to this window
875 // in other windows' constraintsInvolvedIn lists.
876 UnsetConstraints(m_constraints
);
877 delete m_constraints
;
878 m_constraints
= NULL
;
882 delete m_windowSizer
;
883 m_windowSizer
= NULL
;
885 // If this is a child of a sizer, remove self from parent
887 m_sizerParent
->RemoveChild((wxWindow
*)this);
889 // Just in case the window has been Closed, but
890 // we're then deleting immediately: don't leave
891 // dangling pointers.
892 wxPendingDelete
.DeleteObject(this);
894 // Just in case we've loaded a top-level window via
895 // wxWindow::LoadNativeDialog but we weren't a dialog
897 wxTopLevelWindows
.DeleteObject(this);
901 void wxWindow::PreCreation( wxWindow
*parent
, wxWindowID id
,
902 const wxPoint
&pos
, const wxSize
&size
,
903 long style
, const wxString
&name
)
905 if (m_needParent
&& (parent
== NULL
))
906 wxFatalError( _("Need complete parent."), name
);
911 m_children
.DeleteContents( FALSE
);
915 if (m_width
== -1) m_width
= 20;
917 if (m_height
== -1) m_height
= 20;
919 m_eventHandler
= this;
920 m_windowValidator
= NULL
;
923 if (m_cursor
== NULL
)
924 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
925 m_font
= *wxSWISS_FONT
;
926 m_backgroundColour
= wxWHITE
;
927 m_foregroundColour
= wxBLACK
;
928 m_windowStyle
= style
;
930 m_constraints
= NULL
;
931 m_constraintsInvolvedIn
= NULL
;
932 m_windowSizer
= NULL
;
933 m_sizerParent
= NULL
;
934 m_autoLayout
= FALSE
;
935 m_drawingOffsetX
= 0;
936 m_drawingOffsetY
= 0;
937 m_pDropTarget
= NULL
;
941 void wxWindow::PostCreation(void)
943 if (m_parent
) m_parent
->AddChild( this );
945 // GtkStyle *style = m_widget->style;
946 // style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
948 GtkWidget
*connect_widget
= m_widget
;
949 if (m_wxwindow
) connect_widget
= m_wxwindow
;
951 gtk_object_set_data (GTK_OBJECT (connect_widget
), "MyWxWindow", (gpointer
)this );
955 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
956 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
958 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
959 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
963 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
964 GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this );
967 gtk_signal_connect( GTK_OBJECT(connect_widget
), "key_press_event",
968 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
970 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_press_event",
971 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
973 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_release_event",
974 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
976 gtk_signal_connect( GTK_OBJECT(connect_widget
), "motion_notify_event",
977 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
979 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_in_event",
980 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
982 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_out_event",
983 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
985 // Only for cursor handling
987 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter_notify_event",
988 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
990 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave_notify_event",
991 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
995 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "enter_notify_event",
996 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
998 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "leave_notify_event",
999 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
1003 // Does destroy ever get called ?
1005 gtk_signal_connect( GTK_OBJECT(m_widget), "destroy_event",
1006 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1010 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "destroy_event",
1011 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1015 if (m_widget
&& m_parent
) gtk_widget_realize( m_widget
);
1016 if (m_wxwindow
) gtk_widget_realize( m_wxwindow
);
1018 SetCursor( wxSTANDARD_CURSOR
);
1023 bool wxWindow::HasVMT(void)
1028 bool wxWindow::Close( bool force
)
1030 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1031 event
.SetEventObject(this);
1032 event
.SetForce(force
);
1034 return GetEventHandler()->ProcessEvent(event
);
1037 bool wxWindow::Destroy(void)
1044 bool wxWindow::DestroyChildren(void)
1049 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
)
1052 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
)
1055 if (GetChildren()->Member(child
)) delete node
;
1062 void wxWindow::PrepareDC( wxDC
&WXUNUSED(dc
) )
1064 // are we to set fonts here ?
1067 void wxWindow::ImplementSetSize(void)
1069 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1072 void wxWindow::ImplementSetPosition(void)
1074 if (IS_KIND_OF(this,wxFrame
) || IS_KIND_OF(this,wxDialog
))
1076 if ((m_x
!= -1) || (m_y
!= -1))
1077 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1083 printf( _("wxWindow::SetSize error.\n") );
1087 if ((m_parent
) && (m_parent
->m_wxwindow
))
1088 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1090 // Don't do anything for children of wxNotebook and wxMDIChildFrame
1093 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1095 if (m_resizing
) return; // I don't like recursions
1103 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1105 if (newX
== -1) newX
= m_x
;
1106 if (newY
== -1) newY
= m_y
;
1107 if (newW
== -1) newW
= m_width
;
1108 if (newH
== -1) newH
= m_height
;
1111 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1113 if (newW
== -1) newW
= 80;
1116 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1118 if (newH
== -1) newH
= 26;
1121 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1125 ImplementSetPosition();
1127 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1135 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1136 event
.SetEventObject( this );
1137 ProcessEvent( event
);
1142 void wxWindow::SetSize( int width
, int height
)
1144 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1147 void wxWindow::Move( int x
, int y
)
1149 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1152 void wxWindow::GetSize( int *width
, int *height
) const
1154 if (width
) (*width
) = m_width
;
1155 if (height
) (*height
) = m_height
;
1158 void wxWindow::SetClientSize( int width
, int height
)
1162 SetSize( width
, height
);
1169 if (!m_hasScrolling
)
1172 do we have sunken dialogs ?
1174 GtkStyleClass *window_class = m_wxwindow->style->klass;
1176 dw += 2 * window_class->xthickness;
1177 dh += 2 * window_class->ythickness;
1182 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1183 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1185 GtkWidget
*viewport
= scroll_window
->viewport
;
1186 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1188 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1189 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1191 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1192 (m_windowStyle
& wxSUNKEN_BORDER
)
1195 dw
+= 2 * viewport_class
->xthickness
;
1196 dh
+= 2 * viewport_class
->ythickness
;
1199 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1201 dw
+= vscrollbar
->allocation
.width
;
1202 dw
+= scroll_class
->scrollbar_spacing
;
1205 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1207 dh
+= hscrollbar
->allocation
.height
;
1208 dw
+= scroll_class
->scrollbar_spacing
;
1212 SetSize( width
+dw
, height
+dh
);
1216 void wxWindow::GetClientSize( int *width
, int *height
) const
1220 if (width
) (*width
) = m_width
;
1221 if (height
) (*height
) = m_height
;
1228 if (!m_hasScrolling
)
1231 do we have sunken dialogs ?
1233 GtkStyleClass *window_class = m_wxwindow->style->klass;
1235 dw += 2 * window_class->xthickness;
1236 dh += 2 * window_class->ythickness;
1241 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1242 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1244 GtkWidget
*viewport
= scroll_window
->viewport
;
1245 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1247 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1248 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1250 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1251 (m_windowStyle
& wxSUNKEN_BORDER
)
1254 dw
+= 2 * viewport_class
->xthickness
;
1255 dh
+= 2 * viewport_class
->ythickness
;
1258 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1260 // dw += vscrollbar->allocation.width;
1261 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1262 dw
+= scroll_class
->scrollbar_spacing
;
1265 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1267 // dh += hscrollbar->allocation.height;
1269 dh
+= scroll_class
->scrollbar_spacing
;
1273 if (width
) (*width
) = m_width
- dw
;
1274 if (height
) (*height
) = m_height
- dh
;
1278 void wxWindow::GetPosition( int *x
, int *y
) const
1284 void wxWindow::ClientToScreen( int *x
, int *y
)
1286 // Does this look simple ?
1288 GdkWindow
*source
= NULL
;
1290 source
= m_wxwindow
->window
;
1292 source
= m_widget
->window
;
1296 gdk_window_get_origin( source
, &org_x
, &org_y
);
1300 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1302 org_x
+= m_widget
->allocation
.x
;
1303 org_y
+= m_widget
->allocation
.y
;
1311 void wxWindow::ScreenToClient( int *x
, int *y
)
1313 GdkWindow
*source
= NULL
;
1315 source
= m_wxwindow
->window
;
1317 source
= m_widget
->window
;
1321 gdk_window_get_origin( source
, &org_x
, &org_y
);
1325 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1327 org_x
+= m_widget
->allocation
.x
;
1328 org_y
+= m_widget
->allocation
.y
;
1336 void wxWindow::Centre( int direction
)
1338 if (IS_KIND_OF(this,wxDialog
) || IS_KIND_OF(this,wxFrame
))
1340 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
1341 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
1342 ImplementSetPosition();
1350 m_parent
->GetSize( &p_w
, &p_h
);
1351 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (p_w
- m_width
) / 2;
1352 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (p_h
- m_height
) / 2;
1353 ImplementSetPosition();
1358 void wxWindow::Fit(void)
1362 wxNode
*node
= GetChildren()->First();
1365 wxWindow
*win
= (wxWindow
*)node
->Data();
1367 win
->GetPosition(&wx
, &wy
);
1368 win
->GetSize(&ww
, &wh
);
1369 if ( wx
+ ww
> maxX
)
1371 if ( wy
+ wh
> maxY
)
1374 node
= node
->Next();
1376 SetClientSize(maxX
+ 5, maxY
+ 10);
1379 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1381 //if (GetAutoLayout()) Layout();
1384 bool wxWindow::Show( bool show
)
1387 gtk_widget_show( m_widget
);
1389 gtk_widget_hide( m_widget
);
1394 void wxWindow::Enable( bool enable
)
1396 m_isEnabled
= enable
;
1397 gtk_widget_set_sensitive( m_widget
, enable
);
1398 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1401 void wxWindow::MakeModal( bool modal
)
1404 // Disable all other windows
1405 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1407 wxNode
*node
= wxTopLevelWindows
.First();
1410 wxWindow
*win
= (wxWindow
*)node
->Data();
1412 win
->Enable(!modal
);
1414 node
= node
->Next();
1419 void wxWindow::SetFocus(void)
1421 GtkWidget
*connect_widget
= m_widget
;
1422 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1425 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1427 gtk_widget_grab_focus (connect_widget
);
1432 bool wxWindow::OnClose(void)
1437 void wxWindow::AddChild( wxWindow
*child
)
1439 // Addchild is (often) called before the program
1440 // has left the parents constructor so that no
1441 // virtual tables work yet. The approach below
1442 // practically imitates virtual tables, i.e. it
1443 // implements a different AddChild() behaviour
1444 // for wxFrame, wxDialog, wxWindow and
1445 // wxMDIParentFrame.
1447 // wxFrame and wxDialog as children aren't placed into the parents
1449 if (( IS_KIND_OF(child
,wxFrame
) || IS_KIND_OF(child
,wxDialog
) ) &&
1450 (!IS_KIND_OF(child
,wxMDIChildFrame
)))
1452 m_children
.Append( child
);
1454 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1455 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1460 // In the case of an wxMDIChildFrame descendant, we use the
1461 // client windows's AddChild()
1463 if (IS_KIND_OF(this,wxMDIParentFrame
))
1465 if (IS_KIND_OF(child
,wxMDIChildFrame
))
1467 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1470 client
->AddChild( child
);
1476 // wxNotebook is very special, so it has a private AddChild()
1478 if (IS_KIND_OF(this,wxNotebook
))
1480 wxNotebook
*tab
= (wxNotebook
*)this;
1481 tab
->AddChild( child
);
1485 // wxFrame has a private AddChild
1487 if (IS_KIND_OF(this,wxFrame
) && !IS_KIND_OF(this,wxMDIChildFrame
))
1489 wxFrame
*frame
= (wxFrame
*)this;
1490 frame
->AddChild( child
);
1496 m_children
.Append( child
);
1497 if (m_wxwindow
) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
,
1498 child
->m_x
, child
->m_y
);
1500 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1503 wxList
*wxWindow::GetChildren(void)
1505 return (&m_children
);
1508 void wxWindow::RemoveChild( wxWindow
*child
)
1511 GetChildren()->DeleteObject( child
);
1512 child
->m_parent
= NULL
;
1515 void wxWindow::SetReturnCode( int retCode
)
1517 m_retCode
= retCode
;
1520 int wxWindow::GetReturnCode(void)
1525 wxWindow
*wxWindow::GetParent(void)
1530 wxEvtHandler
*wxWindow::GetEventHandler(void)
1532 return m_eventHandler
;
1535 void wxWindow::SetEventhandler( wxEvtHandler
*handler
)
1537 m_eventHandler
= handler
;
1540 wxValidator
*wxWindow::GetValidator(void)
1542 return m_windowValidator
;
1545 void wxWindow::SetValidator( wxValidator
*validator
)
1547 m_windowValidator
= validator
;
1550 bool wxWindow::IsBeingDeleted(void)
1555 void wxWindow::SetId( wxWindowID id
)
1560 wxWindowID
wxWindow::GetId(void)
1565 void wxWindow::SetCursor( const wxCursor
&cursor
)
1567 wxASSERT(m_cursor
!= NULL
);
1569 if (m_cursor
!= NULL
)
1570 if (*m_cursor
== cursor
)
1572 (*m_cursor
) = cursor
;
1573 if (m_widget
->window
)
1574 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1575 if (m_wxwindow
&& m_wxwindow
->window
)
1576 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1579 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1581 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1584 gdk_window_clear_area( m_wxwindow
->window
,
1596 wxClientDC
dc(this);
1600 dc
.GetInternalDeviceOrigin( &x
, &y
);
1604 GetClientSize( &w
, &h
);
1606 GdkRectangle gdk_rect
;
1610 gdk_rect
.height
= h
;
1611 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1616 GdkRectangle gdk_rect
;
1617 gdk_rect
.x
= rect
->x
;
1618 gdk_rect
.y
= rect
->y
;
1619 gdk_rect
.width
= rect
->width
;
1620 gdk_rect
.height
= rect
->height
;
1623 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1625 gtk_widget_draw( m_widget
, &gdk_rect
);
1629 bool wxWindow::IsExposed( long x
, long y
)
1631 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1634 bool wxWindow::IsExposed( long x
, long y
, long width
, long height
)
1636 return (m_updateRegion
.Contains( x
, y
, width
, height
) != wxOutRegion
);
1639 void wxWindow::Clear(void)
1641 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1644 wxColour
wxWindow::GetBackgroundColour(void) const
1646 return m_backgroundColour
;
1649 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1651 m_backgroundColour
= colour
;
1654 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1655 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1656 gdk_window_clear( m_wxwindow
->window
);
1661 bool wxWindow::Validate(void)
1663 wxNode
*node
= GetChildren()->First();
1666 wxWindow
*child
= (wxWindow
*)node
->Data();
1667 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1669 node
= node
->Next();
1674 bool wxWindow::TransferDataToWindow(void)
1676 wxNode
*node
= GetChildren()->First();
1679 wxWindow
*child
= (wxWindow
*)node
->Data();
1680 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1681 !child
->GetValidator()->TransferToWindow() )
1683 wxMessageBox( _("Application Error"), _("Could not transfer data to window"), wxOK
|wxICON_EXCLAMATION
);
1686 node
= node
->Next();
1691 bool wxWindow::TransferDataFromWindow(void)
1693 wxNode
*node
= GetChildren()->First();
1696 wxWindow
*child
= (wxWindow
*)node
->Data();
1697 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1699 node
= node
->Next();
1704 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1706 TransferDataToWindow();
1709 void wxWindow::InitDialog(void)
1711 wxInitDialogEvent
event(GetId());
1712 event
.SetEventObject( this );
1713 GetEventHandler()->ProcessEvent(event
);
1716 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1718 GtkWidget
*dnd_widget
= GetDropTargetWidget();
1722 gtk_signal_disconnect_by_func( GTK_OBJECT(dnd_widget
),
1723 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1725 m_pDropTarget
->UnregisterWidget( dnd_widget
);
1726 delete m_pDropTarget
;
1728 m_pDropTarget
= dropTarget
;
1731 m_pDropTarget
->RegisterWidget( dnd_widget
);
1733 gtk_signal_connect( GTK_OBJECT(dnd_widget
), "drop_data_available_event",
1734 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1738 wxDropTarget
*wxWindow::GetDropTarget() const
1740 return m_pDropTarget
;
1743 GtkWidget
* wxWindow::GetDropTargetWidget(void)
1745 GtkWidget
*connect_widget
= m_widget
;
1746 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1748 return connect_widget
;
1751 void wxWindow::SetFont( const wxFont
&font
)
1756 copy old style values to new one
1757 set font in new style
1758 -> takes to many resources
1760 GtkStyle *style = gtk_style_new();
1765 wxFont
*wxWindow::GetFont(void)
1770 void wxWindow::SetWindowStyleFlag( long flag
)
1772 m_windowStyle
= flag
;
1775 long wxWindow::GetWindowStyleFlag(void) const
1777 return m_windowStyle
;
1780 void wxWindow::CaptureMouse(void)
1782 GtkWidget
*connect_widget
= m_widget
;
1783 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1784 gtk_grab_add( connect_widget
);
1785 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1787 (GDK_BUTTON_PRESS_MASK
|
1788 GDK_BUTTON_RELEASE_MASK
|
1789 GDK_POINTER_MOTION_MASK
),
1790 NULL
, NULL
, GDK_CURRENT_TIME
);
1793 void wxWindow::ReleaseMouse(void)
1795 GtkWidget
*connect_widget
= m_widget
;
1796 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1797 gtk_grab_remove( connect_widget
);
1798 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1801 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1805 wxString
wxWindow::GetTitle(void) const
1807 return (wxString
&)m_windowName
;
1810 wxString
wxWindow::GetLabel(void) const
1815 void wxWindow::SetName( const wxString
&name
)
1817 m_windowName
= name
;
1820 wxString
wxWindow::GetName(void) const
1822 return (wxString
&)m_windowName
;
1825 bool wxWindow::IsShown(void) const
1830 bool wxWindow::IsRetained(void)
1835 wxWindow
*wxWindow::FindWindow( long id
)
1837 if (id
== m_windowId
) return this;
1838 wxNode
*node
= m_children
.First();
1841 wxWindow
*child
= (wxWindow
*)node
->Data();
1842 wxWindow
*res
= child
->FindWindow( id
);
1843 if (res
) return res
;
1844 node
= node
->Next();
1849 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1851 if (name
== m_windowName
) return this;
1852 wxNode
*node
= m_children
.First();
1855 wxWindow
*child
= (wxWindow
*)node
->Data();
1856 wxWindow
*res
= child
->FindWindow( name
);
1857 if (res
) return res
;
1858 node
= node
->Next();
1863 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1864 int range
, bool WXUNUSED(refresh
) )
1866 if (!m_wxwindow
) return;
1868 if (orient
== wxHORIZONTAL
)
1870 float fpos
= (float)pos
;
1871 m_oldHorizontalPos
= fpos
;
1872 float frange
= (float)range
;
1873 float fthumb
= (float)thumbVisible
;
1875 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1876 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1877 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1880 m_hAdjust
->lower
= 0.0;
1881 m_hAdjust
->upper
= frange
;
1882 m_hAdjust
->value
= fpos
;
1883 m_hAdjust
->step_increment
= 1.0;
1884 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1885 m_hAdjust
->page_size
= fthumb
;
1889 float fpos
= (float)pos
;
1890 m_oldVerticalPos
= fpos
;
1891 float frange
= (float)range
;
1892 float fthumb
= (float)thumbVisible
;
1894 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1895 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1896 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1899 m_vAdjust
->lower
= 0.0;
1900 m_vAdjust
->upper
= frange
;
1901 m_vAdjust
->value
= fpos
;
1902 m_vAdjust
->step_increment
= 1.0;
1903 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1904 m_vAdjust
->page_size
= fthumb
;
1907 if (m_wxwindow
->window
)
1909 if (orient
== wxHORIZONTAL
)
1912 m_drawingOffsetX = -16000;
1914 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1916 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
1921 m_drawingOffsetY = -16000;
1923 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1925 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
1928 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1932 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
1934 if (!m_wxwindow
) return;
1936 if (orient
== wxHORIZONTAL
)
1938 float fpos
= (float)pos
;
1939 m_oldHorizontalPos
= fpos
;
1941 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
1942 m_hAdjust
->value
= fpos
;
1946 float fpos
= (float)pos
;
1947 m_oldVerticalPos
= fpos
;
1948 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
1949 m_vAdjust
->value
= fpos
;
1952 if (m_wxwindow
->window
)
1954 if (orient
== wxHORIZONTAL
)
1955 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
1957 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
1961 int wxWindow::GetScrollThumb( int orient
) const
1963 if (!m_wxwindow
) return 0;
1965 if (orient
== wxHORIZONTAL
)
1966 return (int)(m_hAdjust
->page_size
+0.5);
1968 return (int)(m_vAdjust
->page_size
+0.5);
1971 int wxWindow::GetScrollPos( int orient
) const
1973 if (!m_wxwindow
) return 0;
1975 if (orient
== wxHORIZONTAL
)
1976 return (int)(m_hAdjust
->value
+0.5);
1978 return (int)(m_vAdjust
->value
+0.5);
1981 int wxWindow::GetScrollRange( int orient
) const
1983 if (!m_wxwindow
) return 0;
1985 if (orient
== wxHORIZONTAL
)
1986 return (int)(m_hAdjust
->upper
+0.5);
1988 return (int)(m_vAdjust
->upper
+0.5);
1991 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
1993 if (!m_wxwindow
) return;
1995 bool refresh
= FALSE
;
1997 if ((m_drawingOffsetX
== 0) && (m_drawingOffsetY
== 0))
1999 m_drawingOffsetX
= -16000;
2000 m_drawingOffsetY
= -16000;
2005 m_drawingOffsetX
+= dx
;
2006 m_drawingOffsetY
+= dy
;
2009 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
2011 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow
), m_drawingOffsetX
, m_drawingOffsetY
);
2013 if (refresh
) Refresh();
2016 The code here is very nifty, but it doesn't work with
2017 overlapping windows...
2021 GetClientSize( &cw, &ch );
2023 int w = cw - abs(dx);
2024 int h = ch - abs(dy);
2025 if ((h < 0) || (w < 0))
2032 if (dx < 0) s_x = -dx;
2033 if (dy < 0) s_y = -dy;
2036 if (dx > 0) d_x = dx;
2037 if (dy > 0) d_y = dy;
2038 gdk_window_copy_area( m_wxwindow->window, m_wxwindow->style->fg_gc[0], d_x, d_y,
2039 m_wxwindow->window, s_x, s_y, w, h );
2042 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
2043 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
2044 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
2045 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
2047 Refresh( TRUE, &rect );
2051 void wxWindow::GetDrawingOffset( long *x
, long *y
)
2053 if (x
) *x
= m_drawingOffsetX
;
2054 if (y
) *y
= m_drawingOffsetY
;
2057 //-------------------------------------------------------------------------------------
2059 //-------------------------------------------------------------------------------------
2061 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
2063 return m_constraints
;
2066 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
2070 UnsetConstraints(m_constraints
);
2071 delete m_constraints
;
2073 m_constraints
= constraints
;
2076 // Make sure other windows know they're part of a 'meaningful relationship'
2077 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
2078 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2079 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
2080 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2081 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
2082 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2083 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
2084 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2085 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
2086 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2087 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
2088 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2089 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
2090 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2091 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
2092 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2098 void wxWindow::SetAutoLayout( bool autoLayout
)
2100 m_autoLayout
= autoLayout
;
2103 bool wxWindow::GetAutoLayout(void) const
2105 return m_autoLayout
;
2108 wxSizer
*wxWindow::GetSizer(void) const
2110 return m_windowSizer
;
2113 void wxWindow::SetSizerParent( wxWindow
*win
)
2115 m_sizerParent
= win
;
2118 wxWindow
*wxWindow::GetSizerParent(void) const
2120 return m_sizerParent
;
2123 // This removes any dangling pointers to this window
2124 // in other windows' constraintsInvolvedIn lists.
2125 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2129 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2130 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2131 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2132 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2133 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2134 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2135 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2136 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2137 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2138 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2139 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2140 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2141 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2142 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2143 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2144 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2148 // Back-pointer to other windows we're involved with, so if we delete
2149 // this window, we must delete any constraints we're involved with.
2150 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2152 if (!m_constraintsInvolvedIn
)
2153 m_constraintsInvolvedIn
= new wxList
;
2154 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2155 m_constraintsInvolvedIn
->Append(otherWin
);
2158 // REMOVE back-pointer to other windows we're involved with.
2159 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2161 if (m_constraintsInvolvedIn
)
2162 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2165 // Reset any constraints that mention this window
2166 void wxWindow::DeleteRelatedConstraints(void)
2168 if (m_constraintsInvolvedIn
)
2170 wxNode
*node
= m_constraintsInvolvedIn
->First();
2173 wxWindow
*win
= (wxWindow
*)node
->Data();
2174 wxNode
*next
= node
->Next();
2175 wxLayoutConstraints
*constr
= win
->GetConstraints();
2177 // Reset any constraints involving this window
2180 constr
->left
.ResetIfWin((wxWindow
*)this);
2181 constr
->top
.ResetIfWin((wxWindow
*)this);
2182 constr
->right
.ResetIfWin((wxWindow
*)this);
2183 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2184 constr
->width
.ResetIfWin((wxWindow
*)this);
2185 constr
->height
.ResetIfWin((wxWindow
*)this);
2186 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2187 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2192 delete m_constraintsInvolvedIn
;
2193 m_constraintsInvolvedIn
= NULL
;
2197 void wxWindow::SetSizer(wxSizer
*sizer
)
2199 m_windowSizer
= sizer
;
2201 sizer
->SetSizerParent((wxWindow
*)this);
2208 bool wxWindow::Layout(void)
2210 if (GetConstraints())
2213 GetClientSize(&w
, &h
);
2214 GetConstraints()->width
.SetValue(w
);
2215 GetConstraints()->height
.SetValue(h
);
2218 // If top level (one sizer), evaluate the sizer's constraints.
2222 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2223 GetSizer()->LayoutPhase1(&noChanges
);
2224 GetSizer()->LayoutPhase2(&noChanges
);
2225 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2230 // Otherwise, evaluate child constraints
2231 ResetConstraints(); // Mark all constraints as unevaluated
2232 DoPhase(1); // Just one phase need if no sizers involved
2234 SetConstraintSizes(); // Recursively set the real window sizes
2240 // Do a phase of evaluating constraints:
2241 // the default behaviour. wxSizers may do a similar
2242 // thing, but also impose their own 'constraints'
2243 // and order the evaluation differently.
2244 bool wxWindow::LayoutPhase1(int *noChanges
)
2246 wxLayoutConstraints
*constr
= GetConstraints();
2249 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2255 bool wxWindow::LayoutPhase2(int *noChanges
)
2265 // Do a phase of evaluating child constraints
2266 bool wxWindow::DoPhase(int phase
)
2268 int noIterations
= 0;
2269 int maxIterations
= 500;
2273 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2277 wxNode
*node
= GetChildren()->First();
2280 wxWindow
*child
= (wxWindow
*)node
->Data();
2281 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2283 wxLayoutConstraints
*constr
= child
->GetConstraints();
2286 if (succeeded
.Member(child
))
2291 int tempNoChanges
= 0;
2292 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2293 noChanges
+= tempNoChanges
;
2296 succeeded
.Append(child
);
2301 node
= node
->Next();
2308 void wxWindow::ResetConstraints(void)
2310 wxLayoutConstraints
*constr
= GetConstraints();
2313 constr
->left
.SetDone(FALSE
);
2314 constr
->top
.SetDone(FALSE
);
2315 constr
->right
.SetDone(FALSE
);
2316 constr
->bottom
.SetDone(FALSE
);
2317 constr
->width
.SetDone(FALSE
);
2318 constr
->height
.SetDone(FALSE
);
2319 constr
->centreX
.SetDone(FALSE
);
2320 constr
->centreY
.SetDone(FALSE
);
2322 wxNode
*node
= GetChildren()->First();
2325 wxWindow
*win
= (wxWindow
*)node
->Data();
2326 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2327 win
->ResetConstraints();
2328 node
= node
->Next();
2332 // Need to distinguish between setting the 'fake' size for
2333 // windows and sizers, and setting the real values.
2334 void wxWindow::SetConstraintSizes(bool recurse
)
2336 wxLayoutConstraints
*constr
= GetConstraints();
2337 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2338 constr
->width
.GetDone() && constr
->height
.GetDone())
2340 int x
= constr
->left
.GetValue();
2341 int y
= constr
->top
.GetValue();
2342 int w
= constr
->width
.GetValue();
2343 int h
= constr
->height
.GetValue();
2345 // If we don't want to resize this window, just move it...
2346 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2347 (constr
->height
.GetRelationship() != wxAsIs
))
2349 // Calls Layout() recursively. AAAGH. How can we stop that.
2350 // Simply take Layout() out of non-top level OnSizes.
2351 SizerSetSize(x
, y
, w
, h
);
2360 char *windowClass
= this->GetClassInfo()->GetClassName();
2363 if (GetName() == "")
2364 winName
= _("unnamed");
2366 winName
= GetName();
2367 wxDebugMsg(_("Constraint(s) not satisfied for window of type %s, name %s:\n"), (const char *)windowClass
, (const char *)winName
);
2368 if (!constr
->left
.GetDone())
2369 wxDebugMsg(_(" unsatisfied 'left' constraint.\n"));
2370 if (!constr
->right
.GetDone())
2371 wxDebugMsg(_(" unsatisfied 'right' constraint.\n"));
2372 if (!constr
->width
.GetDone())
2373 wxDebugMsg(_(" unsatisfied 'width' constraint.\n"));
2374 if (!constr
->height
.GetDone())
2375 wxDebugMsg(_(" unsatisfied 'height' constraint.\n"));
2376 wxDebugMsg(_("Please check constraints: try adding AsIs() constraints.\n"));
2381 wxNode
*node
= GetChildren()->First();
2384 wxWindow
*win
= (wxWindow
*)node
->Data();
2385 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2386 win
->SetConstraintSizes();
2387 node
= node
->Next();
2392 // This assumes that all sizers are 'on' the same
2393 // window, i.e. the parent of this window.
2394 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2396 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2397 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2401 m_sizerParent
->GetPosition(&xp
, &yp
);
2402 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2407 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2411 TransformSizerToActual(&xx
, &yy
);
2412 SetSize(xx
, yy
, w
, h
);
2415 void wxWindow::SizerMove(int x
, int y
)
2419 TransformSizerToActual(&xx
, &yy
);
2423 // Only set the size/position of the constraint (if any)
2424 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2426 wxLayoutConstraints
*constr
= GetConstraints();
2431 constr
->left
.SetValue(x
);
2432 constr
->left
.SetDone(TRUE
);
2436 constr
->top
.SetValue(y
);
2437 constr
->top
.SetDone(TRUE
);
2441 constr
->width
.SetValue(w
);
2442 constr
->width
.SetDone(TRUE
);
2446 constr
->height
.SetValue(h
);
2447 constr
->height
.SetDone(TRUE
);
2452 void wxWindow::MoveConstraint(int x
, int y
)
2454 wxLayoutConstraints
*constr
= GetConstraints();
2459 constr
->left
.SetValue(x
);
2460 constr
->left
.SetDone(TRUE
);
2464 constr
->top
.SetValue(y
);
2465 constr
->top
.SetDone(TRUE
);
2470 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2472 wxLayoutConstraints
*constr
= GetConstraints();
2475 *w
= constr
->width
.GetValue();
2476 *h
= constr
->height
.GetValue();
2482 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2484 wxLayoutConstraints
*constr
= GetConstraints();
2487 *w
= constr
->width
.GetValue();
2488 *h
= constr
->height
.GetValue();
2491 GetClientSize(w
, h
);
2494 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2496 wxLayoutConstraints
*constr
= GetConstraints();
2499 *x
= constr
->left
.GetValue();
2500 *y
= constr
->top
.GetValue();
2506 bool wxWindow::AcceptsFocus() const
2508 return IsEnabled() && IsShown();
2511 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
) )