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
)
757 Create( parent
, id
, pos
, size
, style
, name
);
760 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
761 const wxPoint
&pos
, const wxSize
&size
,
762 long style
, const wxString
&name
)
768 PreCreation( parent
, id
, pos
, size
, style
, name
);
770 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
771 m_hasScrolling
= TRUE
;
773 GtkScrolledWindow
*s_window
;
774 s_window
= GTK_SCROLLED_WINDOW(m_widget
);
776 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
777 scroll_class
->scrollbar_spacing
= 0;
779 gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
781 m_oldHorizontalPos
= 0.0;
782 m_oldVerticalPos
= 0.0;
784 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) );
785 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) );
787 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "value_changed",
788 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
789 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "value_changed",
790 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
792 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "changed",
793 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
794 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "changed",
795 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
797 GtkViewport
*viewport
;
798 viewport
= GTK_VIEWPORT(s_window
->viewport
);
800 if (m_windowStyle
& wxRAISED_BORDER
)
802 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
804 else if (m_windowStyle
& wxSUNKEN_BORDER
)
806 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
810 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
813 m_wxwindow
= gtk_myfixed_new();
815 if (m_wxwindow
) GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
817 if (m_windowStyle
& wxTAB_TRAVERSAL
== wxTAB_TRAVERSAL
)
818 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
820 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
822 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
824 // shut the viewport up
825 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
826 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
828 // I _really_ don't want scrollbars in the beginning
829 m_vAdjust
->lower
= 0.0;
830 m_vAdjust
->upper
= 1.0;
831 m_vAdjust
->value
= 0.0;
832 m_vAdjust
->step_increment
= 1.0;
833 m_vAdjust
->page_increment
= 1.0;
834 m_vAdjust
->page_size
= 5.0;
835 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
836 m_hAdjust
->lower
= 0.0;
837 m_hAdjust
->upper
= 1.0;
838 m_hAdjust
->value
= 0.0;
839 m_hAdjust
->step_increment
= 1.0;
840 m_hAdjust
->page_increment
= 1.0;
841 m_hAdjust
->page_size
= 5.0;
842 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
844 gtk_widget_show( m_wxwindow
);
853 wxWindow::~wxWindow(void)
857 if (m_pDropTarget
) delete m_pDropTarget
;
859 if (m_parent
) m_parent
->RemoveChild( this );
860 if (m_widget
) Show( FALSE
);
864 if (m_wxwindow
) gtk_widget_destroy( m_wxwindow
);
866 if (m_widget
) gtk_widget_destroy( m_widget
);
870 DeleteRelatedConstraints();
873 // This removes any dangling pointers to this window
874 // in other windows' constraintsInvolvedIn lists.
875 UnsetConstraints(m_constraints
);
876 delete m_constraints
;
877 m_constraints
= NULL
;
881 delete m_windowSizer
;
882 m_windowSizer
= NULL
;
884 // If this is a child of a sizer, remove self from parent
886 m_sizerParent
->RemoveChild((wxWindow
*)this);
888 // Just in case the window has been Closed, but
889 // we're then deleting immediately: don't leave
890 // dangling pointers.
891 wxPendingDelete
.DeleteObject(this);
893 // Just in case we've loaded a top-level window via
894 // wxWindow::LoadNativeDialog but we weren't a dialog
896 wxTopLevelWindows
.DeleteObject(this);
900 void wxWindow::PreCreation( wxWindow
*parent
, wxWindowID id
,
901 const wxPoint
&pos
, const wxSize
&size
,
902 long style
, const wxString
&name
)
904 if (m_needParent
&& (parent
== NULL
))
905 wxFatalError( "Need complete parent.", name
);
910 m_children
.DeleteContents( FALSE
);
914 if (m_width
== -1) m_width
= 20;
916 if (m_height
== -1) m_height
= 20;
918 m_eventHandler
= this;
919 m_windowValidator
= NULL
;
922 if (m_cursor
== NULL
)
923 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
924 m_font
= *wxSWISS_FONT
;
925 m_backgroundColour
= wxWHITE
;
926 m_foregroundColour
= wxBLACK
;
927 m_windowStyle
= style
;
929 m_constraints
= NULL
;
930 m_constraintsInvolvedIn
= NULL
;
931 m_windowSizer
= NULL
;
932 m_sizerParent
= NULL
;
933 m_autoLayout
= FALSE
;
934 m_drawingOffsetX
= 0;
935 m_drawingOffsetY
= 0;
936 m_pDropTarget
= NULL
;
940 void wxWindow::PostCreation(void)
942 if (m_parent
) m_parent
->AddChild( this );
944 // GtkStyle *style = m_widget->style;
945 // style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
947 GtkWidget
*connect_widget
= m_widget
;
948 if (m_wxwindow
) connect_widget
= m_wxwindow
;
950 gtk_object_set_data (GTK_OBJECT (connect_widget
), "MyWxWindow", (gpointer
)this );
954 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
955 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
957 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
958 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
962 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
963 GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this );
966 gtk_signal_connect( GTK_OBJECT(connect_widget
), "key_press_event",
967 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
969 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_press_event",
970 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
972 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_release_event",
973 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
975 gtk_signal_connect( GTK_OBJECT(connect_widget
), "motion_notify_event",
976 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
978 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_in_event",
979 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
981 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_out_event",
982 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
984 // Only for cursor handling
986 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter_notify_event",
987 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
989 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave_notify_event",
990 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
994 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "enter_notify_event",
995 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
997 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "leave_notify_event",
998 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
1002 // Does destroy ever get called ?
1004 gtk_signal_connect( GTK_OBJECT(m_widget), "destroy_event",
1005 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1009 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "destroy_event",
1010 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1014 if (m_widget
&& m_parent
) gtk_widget_realize( m_widget
);
1015 if (m_wxwindow
) gtk_widget_realize( m_wxwindow
);
1017 SetCursor( wxSTANDARD_CURSOR
);
1022 bool wxWindow::HasVMT(void)
1027 bool wxWindow::Close( bool force
)
1029 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1030 event
.SetEventObject(this);
1031 event
.SetForce(force
);
1033 return GetEventHandler()->ProcessEvent(event
);
1036 bool wxWindow::Destroy(void)
1043 bool wxWindow::DestroyChildren(void)
1048 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
)
1051 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
)
1054 if (GetChildren()->Member(child
)) delete node
;
1061 void wxWindow::PrepareDC( wxDC
&WXUNUSED(dc
) )
1063 // are we to set fonts here ?
1066 void wxWindow::ImplementSetSize(void)
1068 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1071 void wxWindow::ImplementSetPosition(void)
1073 if (IS_KIND_OF(this,wxFrame
) || IS_KIND_OF(this,wxDialog
))
1075 if ((m_x
!= -1) || (m_y
!= -1))
1076 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1082 printf( "wxWindow::SetSize error.\n" );
1086 if ((m_parent
) && (m_parent
->m_wxwindow
))
1087 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1089 // Don't do anything for children of wxNotebook and wxMDIChildFrame
1092 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1094 if (m_resizing
) return; // I don't like recursions
1102 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1104 if (newX
== -1) newX
= m_x
;
1105 if (newY
== -1) newY
= m_y
;
1106 if (newW
== -1) newW
= m_width
;
1107 if (newH
== -1) newH
= m_height
;
1110 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1112 if (newW
== -1) newW
= 80;
1115 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1117 if (newH
== -1) newH
= 26;
1120 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1124 ImplementSetPosition();
1126 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1134 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1135 event
.SetEventObject( this );
1136 ProcessEvent( event
);
1141 void wxWindow::SetSize( int width
, int height
)
1143 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1146 void wxWindow::Move( int x
, int y
)
1148 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1151 void wxWindow::GetSize( int *width
, int *height
) const
1153 if (width
) (*width
) = m_width
;
1154 if (height
) (*height
) = m_height
;
1157 void wxWindow::SetClientSize( int width
, int height
)
1161 SetSize( width
, height
);
1168 if (!m_hasScrolling
)
1171 do we have sunken dialogs ?
1173 GtkStyleClass *window_class = m_wxwindow->style->klass;
1175 dw += 2 * window_class->xthickness;
1176 dh += 2 * window_class->ythickness;
1181 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1182 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1184 GtkWidget
*viewport
= scroll_window
->viewport
;
1185 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1187 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1188 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1190 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1191 (m_windowStyle
& wxSUNKEN_BORDER
)
1194 dw
+= 2 * viewport_class
->xthickness
;
1195 dh
+= 2 * viewport_class
->ythickness
;
1198 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1200 dw
+= vscrollbar
->allocation
.width
;
1201 dw
+= scroll_class
->scrollbar_spacing
;
1204 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1206 dh
+= hscrollbar
->allocation
.height
;
1207 dw
+= scroll_class
->scrollbar_spacing
;
1211 SetSize( width
+dw
, height
+dh
);
1215 void wxWindow::GetClientSize( int *width
, int *height
) const
1219 if (width
) (*width
) = m_width
;
1220 if (height
) (*height
) = m_height
;
1227 if (!m_hasScrolling
)
1230 do we have sunken dialogs ?
1232 GtkStyleClass *window_class = m_wxwindow->style->klass;
1234 dw += 2 * window_class->xthickness;
1235 dh += 2 * window_class->ythickness;
1240 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1241 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1243 GtkWidget
*viewport
= scroll_window
->viewport
;
1244 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1246 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1247 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1249 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1250 (m_windowStyle
& wxSUNKEN_BORDER
)
1253 dw
+= 2 * viewport_class
->xthickness
;
1254 dh
+= 2 * viewport_class
->ythickness
;
1257 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1259 // dw += vscrollbar->allocation.width;
1260 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1261 dw
+= scroll_class
->scrollbar_spacing
;
1264 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1266 // dh += hscrollbar->allocation.height;
1268 dh
+= scroll_class
->scrollbar_spacing
;
1272 if (width
) (*width
) = m_width
- dw
;
1273 if (height
) (*height
) = m_height
- dh
;
1277 void wxWindow::GetPosition( int *x
, int *y
) const
1283 void wxWindow::ClientToScreen( int *x
, int *y
)
1285 // Does this look simple ?
1287 GdkWindow
*source
= NULL
;
1289 source
= m_wxwindow
->window
;
1291 source
= m_widget
->window
;
1295 gdk_window_get_origin( source
, &org_x
, &org_y
);
1299 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1301 org_x
+= m_widget
->allocation
.x
;
1302 org_y
+= m_widget
->allocation
.y
;
1310 void wxWindow::ScreenToClient( int *x
, int *y
)
1312 GdkWindow
*source
= NULL
;
1314 source
= m_wxwindow
->window
;
1316 source
= m_widget
->window
;
1320 gdk_window_get_origin( source
, &org_x
, &org_y
);
1324 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1326 org_x
+= m_widget
->allocation
.x
;
1327 org_y
+= m_widget
->allocation
.y
;
1335 void wxWindow::Centre( int direction
)
1337 if (IS_KIND_OF(this,wxDialog
) || IS_KIND_OF(this,wxFrame
))
1339 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
1340 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
1341 ImplementSetPosition();
1349 m_parent
->GetSize( &p_w
, &p_h
);
1350 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (p_w
- m_width
) / 2;
1351 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (p_h
- m_height
) / 2;
1352 ImplementSetPosition();
1357 void wxWindow::Fit(void)
1361 wxNode
*node
= GetChildren()->First();
1364 wxWindow
*win
= (wxWindow
*)node
->Data();
1366 win
->GetPosition(&wx
, &wy
);
1367 win
->GetSize(&ww
, &wh
);
1368 if ( wx
+ ww
> maxX
)
1370 if ( wy
+ wh
> maxY
)
1373 node
= node
->Next();
1375 SetClientSize(maxX
+ 5, maxY
+ 10);
1378 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1380 //if (GetAutoLayout()) Layout();
1383 bool wxWindow::Show( bool show
)
1386 gtk_widget_show( m_widget
);
1388 gtk_widget_hide( m_widget
);
1393 void wxWindow::Enable( bool enable
)
1395 m_isEnabled
= enable
;
1396 gtk_widget_set_sensitive( m_widget
, enable
);
1397 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1400 void wxWindow::MakeModal( bool modal
)
1403 // Disable all other windows
1404 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1406 wxNode
*node
= wxTopLevelWindows
.First();
1409 wxWindow
*win
= (wxWindow
*)node
->Data();
1411 win
->Enable(!modal
);
1413 node
= node
->Next();
1418 void wxWindow::SetFocus(void)
1420 GtkWidget
*connect_widget
= m_widget
;
1421 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1424 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1426 gtk_widget_grab_focus (connect_widget
);
1431 bool wxWindow::OnClose(void)
1436 void wxWindow::AddChild( wxWindow
*child
)
1438 // Addchild is (often) called before the program
1439 // has left the parents constructor so that no
1440 // virtual tables work yet. The approach below
1441 // practically imitates virtual tables, i.e. it
1442 // implements a different AddChild() behaviour
1443 // for wxFrame, wxDialog, wxWindow and
1444 // wxMDIParentFrame.
1446 // wxFrame and wxDialog as children aren't placed into the parents
1448 if (( IS_KIND_OF(child
,wxFrame
) || IS_KIND_OF(child
,wxDialog
) ) &&
1449 (!IS_KIND_OF(child
,wxMDIChildFrame
)))
1451 m_children
.Append( child
);
1453 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1454 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1459 // In the case of an wxMDIChildFrame descendant, we use the
1460 // client windows's AddChild()
1462 if (IS_KIND_OF(this,wxMDIParentFrame
))
1464 if (IS_KIND_OF(child
,wxMDIChildFrame
))
1466 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1469 client
->AddChild( child
);
1475 // wxNotebook is very special, so it has a private AddChild()
1477 if (IS_KIND_OF(this,wxNotebook
))
1479 wxNotebook
*tab
= (wxNotebook
*)this;
1480 tab
->AddChild( child
);
1484 // wxFrame has a private AddChild
1486 if (IS_KIND_OF(this,wxFrame
) && !IS_KIND_OF(this,wxMDIChildFrame
))
1488 wxFrame
*frame
= (wxFrame
*)this;
1489 frame
->AddChild( child
);
1495 m_children
.Append( child
);
1496 if (m_wxwindow
) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
,
1497 child
->m_x
, child
->m_y
);
1499 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1502 wxList
*wxWindow::GetChildren(void)
1504 return (&m_children
);
1507 void wxWindow::RemoveChild( wxWindow
*child
)
1510 GetChildren()->DeleteObject( child
);
1511 child
->m_parent
= NULL
;
1514 void wxWindow::SetReturnCode( int retCode
)
1516 m_retCode
= retCode
;
1519 int wxWindow::GetReturnCode(void)
1524 wxWindow
*wxWindow::GetParent(void)
1529 wxEvtHandler
*wxWindow::GetEventHandler(void)
1531 return m_eventHandler
;
1534 void wxWindow::SetEventhandler( wxEvtHandler
*handler
)
1536 m_eventHandler
= handler
;
1539 wxValidator
*wxWindow::GetValidator(void)
1541 return m_windowValidator
;
1544 void wxWindow::SetValidator( wxValidator
*validator
)
1546 m_windowValidator
= validator
;
1549 bool wxWindow::IsBeingDeleted(void)
1554 void wxWindow::SetId( wxWindowID id
)
1559 wxWindowID
wxWindow::GetId(void)
1564 void wxWindow::SetCursor( const wxCursor
&cursor
)
1566 wxASSERT(m_cursor
!= NULL
);
1568 if (m_cursor
!= NULL
)
1569 if (*m_cursor
== cursor
)
1571 (*m_cursor
) = cursor
;
1572 if (m_widget
->window
)
1573 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1574 if (m_wxwindow
&& m_wxwindow
->window
)
1575 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1578 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1580 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1583 gdk_window_clear_area( m_wxwindow
->window
,
1595 wxClientDC
dc(this);
1599 dc
.GetInternalDeviceOrigin( &x
, &y
);
1603 GetClientSize( &w
, &h
);
1605 GdkRectangle gdk_rect
;
1609 gdk_rect
.height
= h
;
1610 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1615 GdkRectangle gdk_rect
;
1616 gdk_rect
.x
= rect
->x
;
1617 gdk_rect
.y
= rect
->y
;
1618 gdk_rect
.width
= rect
->width
;
1619 gdk_rect
.height
= rect
->height
;
1622 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1624 gtk_widget_draw( m_widget
, &gdk_rect
);
1628 bool wxWindow::IsExposed( long x
, long y
)
1630 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1633 bool wxWindow::IsExposed( long x
, long y
, long width
, long height
)
1635 return (m_updateRegion
.Contains( x
, y
, width
, height
) != wxOutRegion
);
1638 void wxWindow::Clear(void)
1640 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1643 wxColour
wxWindow::GetBackgroundColour(void) const
1645 return m_backgroundColour
;
1648 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1650 m_backgroundColour
= colour
;
1653 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1654 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1655 gdk_window_clear( m_wxwindow
->window
);
1660 bool wxWindow::Validate(void)
1662 wxNode
*node
= GetChildren()->First();
1665 wxWindow
*child
= (wxWindow
*)node
->Data();
1666 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1668 node
= node
->Next();
1673 bool wxWindow::TransferDataToWindow(void)
1675 wxNode
*node
= GetChildren()->First();
1678 wxWindow
*child
= (wxWindow
*)node
->Data();
1679 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1680 !child
->GetValidator()->TransferToWindow() )
1682 wxMessageBox( "Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1685 node
= node
->Next();
1690 bool wxWindow::TransferDataFromWindow(void)
1692 wxNode
*node
= GetChildren()->First();
1695 wxWindow
*child
= (wxWindow
*)node
->Data();
1696 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1698 node
= node
->Next();
1703 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1705 TransferDataToWindow();
1708 void wxWindow::InitDialog(void)
1710 wxInitDialogEvent
event(GetId());
1711 event
.SetEventObject( this );
1712 GetEventHandler()->ProcessEvent(event
);
1715 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1717 GtkWidget
*dnd_widget
= GetDropTargetWidget();
1721 gtk_signal_disconnect_by_func( GTK_OBJECT(dnd_widget
),
1722 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1724 m_pDropTarget
->UnregisterWidget( dnd_widget
);
1725 delete m_pDropTarget
;
1727 m_pDropTarget
= dropTarget
;
1730 m_pDropTarget
->RegisterWidget( dnd_widget
);
1732 gtk_signal_connect( GTK_OBJECT(dnd_widget
), "drop_data_available_event",
1733 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1737 wxDropTarget
*wxWindow::GetDropTarget() const
1739 return m_pDropTarget
;
1742 GtkWidget
* wxWindow::GetDropTargetWidget(void)
1744 GtkWidget
*connect_widget
= m_widget
;
1745 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1747 return connect_widget
;
1750 void wxWindow::SetFont( const wxFont
&font
)
1755 copy old style values to new one
1756 set font in new style
1757 -> takes to many resources
1759 GtkStyle *style = gtk_style_new();
1764 wxFont
*wxWindow::GetFont(void)
1769 void wxWindow::SetWindowStyleFlag( long flag
)
1771 m_windowStyle
= flag
;
1774 long wxWindow::GetWindowStyleFlag(void) const
1776 return m_windowStyle
;
1779 void wxWindow::CaptureMouse(void)
1781 GtkWidget
*connect_widget
= m_widget
;
1782 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1783 gtk_grab_add( connect_widget
);
1784 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1786 (GDK_BUTTON_PRESS_MASK
|
1787 GDK_BUTTON_RELEASE_MASK
|
1788 GDK_POINTER_MOTION_MASK
),
1789 NULL
, NULL
, GDK_CURRENT_TIME
);
1792 void wxWindow::ReleaseMouse(void)
1794 GtkWidget
*connect_widget
= m_widget
;
1795 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1796 gtk_grab_remove( connect_widget
);
1797 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1800 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1804 wxString
wxWindow::GetTitle(void) const
1806 return (wxString
&)m_windowName
;
1809 wxString
wxWindow::GetLabel(void) const
1814 void wxWindow::SetName( const wxString
&name
)
1816 m_windowName
= name
;
1819 wxString
wxWindow::GetName(void) const
1821 return (wxString
&)m_windowName
;
1824 bool wxWindow::IsShown(void) const
1829 bool wxWindow::IsRetained(void)
1834 wxWindow
*wxWindow::FindWindow( long id
)
1836 if (id
== m_windowId
) return this;
1837 wxNode
*node
= m_children
.First();
1840 wxWindow
*child
= (wxWindow
*)node
->Data();
1841 wxWindow
*res
= child
->FindWindow( id
);
1842 if (res
) return res
;
1843 node
= node
->Next();
1848 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1850 if (name
== m_windowName
) return this;
1851 wxNode
*node
= m_children
.First();
1854 wxWindow
*child
= (wxWindow
*)node
->Data();
1855 wxWindow
*res
= child
->FindWindow( name
);
1856 if (res
) return res
;
1857 node
= node
->Next();
1862 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1863 int range
, bool WXUNUSED(refresh
) )
1865 if (!m_wxwindow
) return;
1867 if (orient
== wxHORIZONTAL
)
1869 float fpos
= (float)pos
;
1870 m_oldHorizontalPos
= fpos
;
1871 float frange
= (float)range
;
1872 float fthumb
= (float)thumbVisible
;
1874 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1875 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1876 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1879 m_hAdjust
->lower
= 0.0;
1880 m_hAdjust
->upper
= frange
;
1881 m_hAdjust
->value
= fpos
;
1882 m_hAdjust
->step_increment
= 1.0;
1883 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1884 m_hAdjust
->page_size
= fthumb
;
1888 float fpos
= (float)pos
;
1889 m_oldVerticalPos
= fpos
;
1890 float frange
= (float)range
;
1891 float fthumb
= (float)thumbVisible
;
1893 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1894 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1895 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1898 m_vAdjust
->lower
= 0.0;
1899 m_vAdjust
->upper
= frange
;
1900 m_vAdjust
->value
= fpos
;
1901 m_vAdjust
->step_increment
= 1.0;
1902 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1903 m_vAdjust
->page_size
= fthumb
;
1906 if (m_wxwindow
->window
)
1908 if (orient
== wxHORIZONTAL
)
1911 m_drawingOffsetX = -16000;
1913 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1915 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
1920 m_drawingOffsetY = -16000;
1922 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1924 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
1927 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1931 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
1933 if (!m_wxwindow
) return;
1935 if (orient
== wxHORIZONTAL
)
1937 float fpos
= (float)pos
;
1938 m_oldHorizontalPos
= fpos
;
1940 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
1941 m_hAdjust
->value
= fpos
;
1945 float fpos
= (float)pos
;
1946 m_oldVerticalPos
= fpos
;
1947 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
1948 m_vAdjust
->value
= fpos
;
1951 if (m_wxwindow
->window
)
1953 if (orient
== wxHORIZONTAL
)
1954 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
1956 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
1960 int wxWindow::GetScrollThumb( int orient
) const
1962 if (!m_wxwindow
) return 0;
1964 if (orient
== wxHORIZONTAL
)
1965 return (int)(m_hAdjust
->page_size
+0.5);
1967 return (int)(m_vAdjust
->page_size
+0.5);
1970 int wxWindow::GetScrollPos( int orient
) const
1972 if (!m_wxwindow
) return 0;
1974 if (orient
== wxHORIZONTAL
)
1975 return (int)(m_hAdjust
->value
+0.5);
1977 return (int)(m_vAdjust
->value
+0.5);
1980 int wxWindow::GetScrollRange( int orient
) const
1982 if (!m_wxwindow
) return 0;
1984 if (orient
== wxHORIZONTAL
)
1985 return (int)(m_hAdjust
->upper
+0.5);
1987 return (int)(m_vAdjust
->upper
+0.5);
1990 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
1992 if (!m_wxwindow
) return;
1994 bool refresh
= FALSE
;
1996 if ((m_drawingOffsetX
== 0) && (m_drawingOffsetY
== 0))
1998 m_drawingOffsetX
= -16000;
1999 m_drawingOffsetY
= -16000;
2004 m_drawingOffsetX
+= dx
;
2005 m_drawingOffsetY
+= dy
;
2008 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
2010 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow
), m_drawingOffsetX
, m_drawingOffsetY
);
2012 if (refresh
) Refresh();
2015 The code here is very nifty, but it doesn't work with
2016 overlapping windows...
2020 GetClientSize( &cw, &ch );
2022 int w = cw - abs(dx);
2023 int h = ch - abs(dy);
2024 if ((h < 0) || (w < 0))
2031 if (dx < 0) s_x = -dx;
2032 if (dy < 0) s_y = -dy;
2035 if (dx > 0) d_x = dx;
2036 if (dy > 0) d_y = dy;
2037 gdk_window_copy_area( m_wxwindow->window, m_wxwindow->style->fg_gc[0], d_x, d_y,
2038 m_wxwindow->window, s_x, s_y, w, h );
2041 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
2042 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
2043 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
2044 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
2046 Refresh( TRUE, &rect );
2050 void wxWindow::GetDrawingOffset( long *x
, long *y
)
2052 if (x
) *x
= m_drawingOffsetX
;
2053 if (y
) *y
= m_drawingOffsetY
;
2056 //-------------------------------------------------------------------------------------
2058 //-------------------------------------------------------------------------------------
2060 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
2062 return m_constraints
;
2065 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
2069 UnsetConstraints(m_constraints
);
2070 delete m_constraints
;
2072 m_constraints
= constraints
;
2075 // Make sure other windows know they're part of a 'meaningful relationship'
2076 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
2077 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2078 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
2079 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2080 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
2081 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2082 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
2083 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2084 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
2085 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2086 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
2087 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2088 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
2089 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2090 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
2091 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2097 void wxWindow::SetAutoLayout( bool autoLayout
)
2099 m_autoLayout
= autoLayout
;
2102 bool wxWindow::GetAutoLayout(void) const
2104 return m_autoLayout
;
2107 wxSizer
*wxWindow::GetSizer(void) const
2109 return m_windowSizer
;
2112 void wxWindow::SetSizerParent( wxWindow
*win
)
2114 m_sizerParent
= win
;
2117 wxWindow
*wxWindow::GetSizerParent(void) const
2119 return m_sizerParent
;
2122 // This removes any dangling pointers to this window
2123 // in other windows' constraintsInvolvedIn lists.
2124 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2128 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2129 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2130 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2131 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2132 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2133 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2134 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2135 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2136 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2137 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2138 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2139 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2140 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2141 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2142 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2143 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2147 // Back-pointer to other windows we're involved with, so if we delete
2148 // this window, we must delete any constraints we're involved with.
2149 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2151 if (!m_constraintsInvolvedIn
)
2152 m_constraintsInvolvedIn
= new wxList
;
2153 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2154 m_constraintsInvolvedIn
->Append(otherWin
);
2157 // REMOVE back-pointer to other windows we're involved with.
2158 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2160 if (m_constraintsInvolvedIn
)
2161 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2164 // Reset any constraints that mention this window
2165 void wxWindow::DeleteRelatedConstraints(void)
2167 if (m_constraintsInvolvedIn
)
2169 wxNode
*node
= m_constraintsInvolvedIn
->First();
2172 wxWindow
*win
= (wxWindow
*)node
->Data();
2173 wxNode
*next
= node
->Next();
2174 wxLayoutConstraints
*constr
= win
->GetConstraints();
2176 // Reset any constraints involving this window
2179 constr
->left
.ResetIfWin((wxWindow
*)this);
2180 constr
->top
.ResetIfWin((wxWindow
*)this);
2181 constr
->right
.ResetIfWin((wxWindow
*)this);
2182 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2183 constr
->width
.ResetIfWin((wxWindow
*)this);
2184 constr
->height
.ResetIfWin((wxWindow
*)this);
2185 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2186 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2191 delete m_constraintsInvolvedIn
;
2192 m_constraintsInvolvedIn
= NULL
;
2196 void wxWindow::SetSizer(wxSizer
*sizer
)
2198 m_windowSizer
= sizer
;
2200 sizer
->SetSizerParent((wxWindow
*)this);
2207 bool wxWindow::Layout(void)
2209 if (GetConstraints())
2212 GetClientSize(&w
, &h
);
2213 GetConstraints()->width
.SetValue(w
);
2214 GetConstraints()->height
.SetValue(h
);
2217 // If top level (one sizer), evaluate the sizer's constraints.
2221 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2222 GetSizer()->LayoutPhase1(&noChanges
);
2223 GetSizer()->LayoutPhase2(&noChanges
);
2224 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2229 // Otherwise, evaluate child constraints
2230 ResetConstraints(); // Mark all constraints as unevaluated
2231 DoPhase(1); // Just one phase need if no sizers involved
2233 SetConstraintSizes(); // Recursively set the real window sizes
2239 // Do a phase of evaluating constraints:
2240 // the default behaviour. wxSizers may do a similar
2241 // thing, but also impose their own 'constraints'
2242 // and order the evaluation differently.
2243 bool wxWindow::LayoutPhase1(int *noChanges
)
2245 wxLayoutConstraints
*constr
= GetConstraints();
2248 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2254 bool wxWindow::LayoutPhase2(int *noChanges
)
2264 // Do a phase of evaluating child constraints
2265 bool wxWindow::DoPhase(int phase
)
2267 int noIterations
= 0;
2268 int maxIterations
= 500;
2272 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2276 wxNode
*node
= GetChildren()->First();
2279 wxWindow
*child
= (wxWindow
*)node
->Data();
2280 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2282 wxLayoutConstraints
*constr
= child
->GetConstraints();
2285 if (succeeded
.Member(child
))
2290 int tempNoChanges
= 0;
2291 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2292 noChanges
+= tempNoChanges
;
2295 succeeded
.Append(child
);
2300 node
= node
->Next();
2307 void wxWindow::ResetConstraints(void)
2309 wxLayoutConstraints
*constr
= GetConstraints();
2312 constr
->left
.SetDone(FALSE
);
2313 constr
->top
.SetDone(FALSE
);
2314 constr
->right
.SetDone(FALSE
);
2315 constr
->bottom
.SetDone(FALSE
);
2316 constr
->width
.SetDone(FALSE
);
2317 constr
->height
.SetDone(FALSE
);
2318 constr
->centreX
.SetDone(FALSE
);
2319 constr
->centreY
.SetDone(FALSE
);
2321 wxNode
*node
= GetChildren()->First();
2324 wxWindow
*win
= (wxWindow
*)node
->Data();
2325 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2326 win
->ResetConstraints();
2327 node
= node
->Next();
2331 // Need to distinguish between setting the 'fake' size for
2332 // windows and sizers, and setting the real values.
2333 void wxWindow::SetConstraintSizes(bool recurse
)
2335 wxLayoutConstraints
*constr
= GetConstraints();
2336 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2337 constr
->width
.GetDone() && constr
->height
.GetDone())
2339 int x
= constr
->left
.GetValue();
2340 int y
= constr
->top
.GetValue();
2341 int w
= constr
->width
.GetValue();
2342 int h
= constr
->height
.GetValue();
2344 // If we don't want to resize this window, just move it...
2345 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2346 (constr
->height
.GetRelationship() != wxAsIs
))
2348 // Calls Layout() recursively. AAAGH. How can we stop that.
2349 // Simply take Layout() out of non-top level OnSizes.
2350 SizerSetSize(x
, y
, w
, h
);
2359 char *windowClass
= this->GetClassInfo()->GetClassName();
2362 if (GetName() == "")
2363 winName
= "unnamed";
2365 winName
= GetName();
2366 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
2367 if (!constr
->left
.GetDone())
2368 wxDebugMsg(" unsatisfied 'left' constraint.\n");
2369 if (!constr
->right
.GetDone())
2370 wxDebugMsg(" unsatisfied 'right' constraint.\n");
2371 if (!constr
->width
.GetDone())
2372 wxDebugMsg(" unsatisfied 'width' constraint.\n");
2373 if (!constr
->height
.GetDone())
2374 wxDebugMsg(" unsatisfied 'height' constraint.\n");
2375 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
2380 wxNode
*node
= GetChildren()->First();
2383 wxWindow
*win
= (wxWindow
*)node
->Data();
2384 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2385 win
->SetConstraintSizes();
2386 node
= node
->Next();
2391 // This assumes that all sizers are 'on' the same
2392 // window, i.e. the parent of this window.
2393 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2395 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2396 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2400 m_sizerParent
->GetPosition(&xp
, &yp
);
2401 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2406 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2410 TransformSizerToActual(&xx
, &yy
);
2411 SetSize(xx
, yy
, w
, h
);
2414 void wxWindow::SizerMove(int x
, int y
)
2418 TransformSizerToActual(&xx
, &yy
);
2422 // Only set the size/position of the constraint (if any)
2423 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2425 wxLayoutConstraints
*constr
= GetConstraints();
2430 constr
->left
.SetValue(x
);
2431 constr
->left
.SetDone(TRUE
);
2435 constr
->top
.SetValue(y
);
2436 constr
->top
.SetDone(TRUE
);
2440 constr
->width
.SetValue(w
);
2441 constr
->width
.SetDone(TRUE
);
2445 constr
->height
.SetValue(h
);
2446 constr
->height
.SetDone(TRUE
);
2451 void wxWindow::MoveConstraint(int x
, int y
)
2453 wxLayoutConstraints
*constr
= GetConstraints();
2458 constr
->left
.SetValue(x
);
2459 constr
->left
.SetDone(TRUE
);
2463 constr
->top
.SetValue(y
);
2464 constr
->top
.SetDone(TRUE
);
2469 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2471 wxLayoutConstraints
*constr
= GetConstraints();
2474 *w
= constr
->width
.GetValue();
2475 *h
= constr
->height
.GetValue();
2481 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2483 wxLayoutConstraints
*constr
= GetConstraints();
2486 *w
= constr
->width
.GetValue();
2487 *h
= constr
->height
.GetValue();
2490 GetClientSize(w
, h
);
2493 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2495 wxLayoutConstraints
*constr
= GetConstraints();
2498 *x
= constr
->left
.GetValue();
2499 *y
= constr
->top
.GetValue();
2505 bool wxWindow::AcceptsFocus() const
2507 return IsEnabled() && IsShown();
2510 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
) )