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"
29 #include "wx/notebook.h"
30 #include "wx/statusbr.h"
32 //#include "wx/treectrl.h"
33 #include "gdk/gdkkeysyms.h"
35 #include "wx/gtk/win_gtk.h"
36 #include "gdk/gdkprivate.h"
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 extern wxList wxPendingDelete
;
43 extern wxList wxTopLevelWindows
;
44 extern bool g_blockEventsOnDrag
;
46 //-----------------------------------------------------------------------------
47 // GTK callbacks for wxWindows event system
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
51 // expose (of m_wxwindow, not of m_widget)
53 void gtk_window_expose_callback( GtkWidget
*WXUNUSED(widget
), GdkEventExpose
*gdk_event
, wxWindow
*win
)
55 if (!win
->HasVMT()) return;
56 if (g_blockEventsOnDrag
) return;
59 if (IS_KIND_OF(win,wxStatusBar))
61 printf( "OnExpose from " );
62 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
63 printf( win->GetClassInfo()->GetClassName() );
66 printf( "x: %d \n", gdk_event->area.x );
67 printf( "y: %d \n", gdk_event->area.y );
68 printf( "w: %d \n", gdk_event->area.width );
69 printf( "h: %d \n", gdk_event->area.height );
73 win
->m_updateRegion
.Union( gdk_event
->area
.x
,
75 gdk_event
->area
.width
,
76 gdk_event
->area
.height
);
78 if (gdk_event
->count
> 0) return;
80 wxPaintEvent
event( win
->GetId() );
81 event
.SetEventObject( win
);
82 win
->ProcessEvent( event
);
84 win
->m_updateRegion
.Clear();
87 //-----------------------------------------------------------------------------
88 // draw (of m_wxwindow, not of m_widget)
90 void gtk_window_draw_callback( GtkWidget
*WXUNUSED(widget
), GdkRectangle
*rect
, wxWindow
*win
)
92 if (!win
->HasVMT()) return;
93 if (g_blockEventsOnDrag
) return;
96 if (IS_KIND_OF(win,wxStatusBar))
98 printf( "OnDraw from " );
99 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
100 printf( win->GetClassInfo()->GetClassName() );
103 printf( "x: %d \n", rect->x );
104 printf( "y: %d \n", rect->y );
105 printf( "w: %d \n", rect->width );
106 printf( "h: %d \n", rect->height );
110 win
->m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
112 wxPaintEvent
event( win
->GetId() );
113 event
.SetEventObject( win
);
114 win
->ProcessEvent( event
);
116 win
->m_updateRegion
.Clear();
119 //-----------------------------------------------------------------------------
121 // I don't any longer intercept GTK's internal resize events, except
122 // for frames and from within MDI and tabbed windows (client area
123 // size determined internally by GTK, not wxWin).
126 void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
128 if (!win->HasVMT()) return;
129 if (g_blockEventsOnDrag) return;
133 if ((win->m_x == alloc->x) &&
134 (win->m_y == alloc->y) &&
135 (win->m_width == alloc->width) &&
136 (win->m_height == alloc->height))
141 printf( "OnResize from " );
142 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
143 printf( win->GetClassInfo()->GetClassName() );
146 printf( " Old: X: %d Y: %d ", win->m_x, win->m_y );
147 printf( " W: %d H: %d ", win->m_width, win->m_height );
150 printf( " New: X: %d Y: %d ", alloc->x, alloc->y );
151 printf( " W: %d H: %d ", alloc->width, alloc->height );
154 wxSizeEvent event( wxSize( alloc->width, alloc->height), win->GetId() );
155 event.SetEventObject( win );
156 win->ProcessEvent( event );
160 //-----------------------------------------------------------------------------
163 gint
gtk_window_key_press_callback( GtkWidget
*WXUNUSED(widget
), GdkEventKey
*gdk_event
, wxWindow
*win
)
165 if (!win
->HasVMT()) return FALSE
;
166 if (g_blockEventsOnDrag
) return FALSE
;
169 printf( "OnKeyPress from " );
170 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
171 printf( win->GetClassInfo()->GetClassName() );
176 switch (gdk_event
->keyval
)
178 case GDK_BackSpace
: key_code
= WXK_BACK
; break;
179 case GDK_Tab
: key_code
= WXK_TAB
; break;
180 case GDK_Linefeed
: key_code
= WXK_RETURN
; break;
181 case GDK_Clear
: key_code
= WXK_CLEAR
; break;
182 case GDK_Return
: key_code
= WXK_RETURN
; break;
183 case GDK_Pause
: key_code
= WXK_PAUSE
; break;
184 case GDK_Scroll_Lock
: key_code
= WXK_SCROLL
; break;
185 case GDK_Escape
: key_code
= WXK_ESCAPE
; break;
186 case GDK_Delete
: key_code
= WXK_DELETE
; break;
187 case GDK_Home
: key_code
= WXK_HOME
; break;
188 case GDK_Left
: key_code
= WXK_LEFT
; break;
189 case GDK_Up
: key_code
= WXK_UP
; break;
190 case GDK_Right
: key_code
= WXK_RIGHT
; break;
191 case GDK_Down
: key_code
= WXK_DOWN
; break;
192 case GDK_Prior
: key_code
= WXK_PRIOR
; break;
193 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
194 case GDK_Next
: key_code
= WXK_NEXT
; break;
195 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
196 case GDK_End
: key_code
= WXK_END
; break;
197 case GDK_Begin
: key_code
= WXK_HOME
; break;
198 case GDK_Select
: key_code
= WXK_SELECT
; break;
199 case GDK_Print
: key_code
= WXK_PRINT
; break;
200 case GDK_Execute
: key_code
= WXK_EXECUTE
; break;
201 case GDK_Insert
: key_code
= WXK_INSERT
; break;
202 case GDK_Num_Lock
: key_code
= WXK_NUMLOCK
; break;
203 case GDK_KP_Tab
: key_code
= WXK_TAB
; break;
204 case GDK_KP_Enter
: key_code
= WXK_RETURN
; break;
205 case GDK_KP_Home
: key_code
= WXK_HOME
; break;
206 case GDK_KP_Left
: key_code
= WXK_LEFT
; break;
207 case GDK_KP_Up
: key_code
= WXK_UP
; break;
208 case GDK_KP_Right
: key_code
= WXK_RIGHT
; break;
209 case GDK_KP_Down
: key_code
= WXK_DOWN
; break;
210 case GDK_KP_Prior
: key_code
= WXK_PRIOR
; break;
211 // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
212 case GDK_KP_Next
: key_code
= WXK_NEXT
; break;
213 // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
214 case GDK_KP_End
: key_code
= WXK_END
; break;
215 case GDK_KP_Begin
: key_code
= WXK_HOME
; break;
216 case GDK_KP_Insert
: key_code
= WXK_INSERT
; break;
217 case GDK_KP_Delete
: key_code
= WXK_DELETE
; break;
218 case GDK_KP_Multiply
: key_code
= WXK_MULTIPLY
; break;
219 case GDK_KP_Add
: key_code
= WXK_ADD
; break;
220 case GDK_KP_Separator
: key_code
= WXK_SEPARATOR
; break;
221 case GDK_KP_Subtract
: key_code
= WXK_SUBTRACT
; break;
222 case GDK_KP_Decimal
: key_code
= WXK_DECIMAL
; break;
223 case GDK_KP_Divide
: key_code
= WXK_DIVIDE
; break;
224 case GDK_KP_0
: key_code
= WXK_NUMPAD0
; break;
225 case GDK_KP_1
: key_code
= WXK_NUMPAD1
; break;
226 case GDK_KP_2
: key_code
= WXK_NUMPAD2
; break;
227 case GDK_KP_3
: key_code
= WXK_NUMPAD3
; break;
228 case GDK_KP_4
: key_code
= WXK_NUMPAD4
; break;
229 case GDK_KP_5
: key_code
= WXK_NUMPAD5
; break;
230 case GDK_KP_6
: key_code
= WXK_NUMPAD6
; break;
231 case GDK_KP_7
: key_code
= WXK_NUMPAD7
; break;
232 case GDK_KP_8
: key_code
= WXK_NUMPAD7
; break;
233 case GDK_KP_9
: key_code
= WXK_NUMPAD9
; break;
234 case GDK_F1
: key_code
= WXK_F1
; break;
235 case GDK_F2
: key_code
= WXK_F2
; break;
236 case GDK_F3
: key_code
= WXK_F3
; break;
237 case GDK_F4
: key_code
= WXK_F4
; break;
238 case GDK_F5
: key_code
= WXK_F5
; break;
239 case GDK_F6
: key_code
= WXK_F6
; break;
240 case GDK_F7
: key_code
= WXK_F7
; break;
241 case GDK_F8
: key_code
= WXK_F8
; break;
242 case GDK_F9
: key_code
= WXK_F9
; break;
243 case GDK_F10
: key_code
= WXK_F10
; break;
244 case GDK_F11
: key_code
= WXK_F11
; break;
245 case GDK_F12
: key_code
= WXK_F12
; break;
248 if ((gdk_event
->keyval
>= 0x20) && (gdk_event
->keyval
<= 0xFF))
249 key_code
= gdk_event
->keyval
;
253 if (!key_code
) return FALSE
;
255 wxKeyEvent
event( wxEVT_CHAR
);
256 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
257 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
258 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
259 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
260 event
.m_keyCode
= key_code
;
263 event
.SetEventObject( win
);
265 bool ret
= win
->ProcessEvent( event
);
267 if (ret) printf( "found.\n") ;
272 //-----------------------------------------------------------------------------
275 gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
277 if (widget
->window
!= gdk_event
->window
) return TRUE
;
278 if (g_blockEventsOnDrag
) return TRUE
;
282 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
) && !GTK_WIDGET_HAS_FOCUS (win
->m_wxwindow
) )
284 gtk_widget_grab_focus (win
->m_wxwindow
);
287 printf( "GrabFocus from " );
288 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
289 printf( win->GetClassInfo()->GetClassName() );
296 if (!win
->HasVMT()) return TRUE
;
299 printf( "OnButtonPress from " );
300 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
301 printf( win->GetClassInfo()->GetClassName() );
305 wxEventType event_type
= wxEVT_LEFT_DOWN
;
307 if (gdk_event
->button
== 1)
309 switch (gdk_event
->type
)
311 case GDK_BUTTON_PRESS
: event_type
= wxEVT_LEFT_DOWN
; break;
312 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_LEFT_DCLICK
; break;
316 else if (gdk_event
->button
== 2)
318 switch (gdk_event
->type
)
320 case GDK_BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DOWN
; break;
321 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DCLICK
; break;
325 else if (gdk_event
->button
== 3)
327 switch (gdk_event
->type
)
329 case GDK_BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DOWN
; break;
330 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DCLICK
; break;
335 wxMouseEvent
event( event_type
);
336 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
337 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
338 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
339 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
340 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
341 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
342 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
344 event
.m_x
= (long)gdk_event
->x
;
345 event
.m_y
= (long)gdk_event
->y
;
346 event
.SetEventObject( win
);
348 win
->ProcessEvent( event
);
353 //-----------------------------------------------------------------------------
356 gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
358 if (widget
->window
!= gdk_event
->window
) return TRUE
;
360 if (g_blockEventsOnDrag
) return TRUE
;
362 if (!win
->HasVMT()) return TRUE
;
365 printf( "OnButtonRelease from " );
366 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
367 printf( win->GetClassInfo()->GetClassName() );
371 wxEventType event_type
= wxEVT_NULL
;
373 switch (gdk_event
->button
)
375 case 1: event_type
= wxEVT_LEFT_UP
; break;
376 case 2: event_type
= wxEVT_MIDDLE_UP
; break;
377 case 3: event_type
= wxEVT_RIGHT_UP
; break;
380 wxMouseEvent
event( event_type
);
381 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
382 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
383 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
384 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
385 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
386 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
387 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
388 event
.m_x
= (long)gdk_event
->x
;
389 event
.m_y
= (long)gdk_event
->y
;
390 event
.SetEventObject( win
);
392 win
->ProcessEvent( event
);
397 //-----------------------------------------------------------------------------
400 gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxWindow
*win
)
402 if (widget
->window
!= gdk_event
->window
) return TRUE
;
404 if (g_blockEventsOnDrag
) return TRUE
;
406 if (!win
->HasVMT()) return TRUE
;
409 printf( "OnMotion from " );
410 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
411 printf( win->GetClassInfo()->GetClassName() );
415 wxMouseEvent
event( wxEVT_MOTION
);
416 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
417 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
418 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
419 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
420 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
421 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
422 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
424 event
.m_x
= (long)gdk_event
->x
;
425 event
.m_y
= (long)gdk_event
->y
;
426 event
.SetEventObject( win
);
428 win
->ProcessEvent( event
);
433 //-----------------------------------------------------------------------------
436 gint
gtk_window_focus_in_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
438 if (g_blockEventsOnDrag
) return TRUE
;
441 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
443 GTK_WIDGET_SET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
445 printf( "SetFocus flag from " );
446 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
447 printf( win->GetClassInfo()->GetClassName() );
453 if (!win
->HasVMT()) return TRUE
;
456 printf( "OnSetFocus from " );
457 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
458 printf( win->GetClassInfo()->GetClassName() );
460 printf( WXSTRINGCAST win->GetLabel() );
464 wxFocusEvent
event( wxEVT_SET_FOCUS
, win
->GetId() );
465 event
.SetEventObject( win
);
466 win
->ProcessEvent( event
);
471 //-----------------------------------------------------------------------------
474 gint
gtk_window_focus_out_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
476 if (g_blockEventsOnDrag
) return TRUE
;
479 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
480 GTK_WIDGET_UNSET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
483 if (!win
->HasVMT()) return TRUE
;
486 printf( "OnKillFocus from " );
487 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
488 printf( win->GetClassInfo()->GetClassName() );
492 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
493 event
.SetEventObject( win
);
494 win
->ProcessEvent( event
);
499 //-----------------------------------------------------------------------------
502 void gtk_window_vscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
504 if (g_blockEventsOnDrag
) return;
507 printf( "OnVScroll from " );
508 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
509 printf( win->GetClassInfo()->GetClassName() );
513 if (!win
->HasVMT()) return;
515 float diff
= win
->m_vAdjust
->value
- win
->m_oldVerticalPos
;
516 if (fabs(diff
) < 0.2) return;
519 int i = (int)(win->m_oldVerticalPos+0.5);
520 printf( "Old value: %d.\n", i );
521 i = (int)(win->m_vAdjust->value+0.5);
522 printf( "Sending new value: %d.\n", i );
525 wxEventType command
= wxEVT_NULL
;
527 float line_step
= win
->m_vAdjust
->step_increment
;
528 float page_step
= win
->m_vAdjust
->page_increment
;
530 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
531 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
532 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
533 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
534 else command
= wxEVT_SCROLL_THUMBTRACK
;
536 int value
= (int)(win
->m_vAdjust
->value
+0.5);
538 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
539 event
.SetEventObject( win
);
540 win
->ProcessEvent( event
);
543 //-----------------------------------------------------------------------------
546 void gtk_window_hscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
548 if (g_blockEventsOnDrag
) return;
551 printf( "OnHScroll from " );
552 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
553 printf( win->GetClassInfo()->GetClassName() );
557 if (!win
->HasVMT()) return;
559 float diff
= win
->m_hAdjust
->value
- win
->m_oldHorizontalPos
;
560 if (fabs(diff
) < 0.2) return;
563 int i = (int)(win->m_oldHorizontalPos+0.5);
564 printf( "Old value: %d.\n", i );
565 i = (int)(win->m_hAdjust->value+0.5);
566 printf( "Sending new value: %d.\n", i );
569 wxEventType command
= wxEVT_NULL
;
571 float line_step
= win
->m_hAdjust
->step_increment
;
572 float page_step
= win
->m_hAdjust
->page_increment
;
574 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
575 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
576 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
577 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
578 else command
= wxEVT_SCROLL_THUMBTRACK
;
580 int value
= (int)(win
->m_hAdjust
->value
+0.5);
582 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
583 event
.SetEventObject( win
);
584 win
->ProcessEvent( event
);
587 //-----------------------------------------------------------------------------
588 // vertical scroll change
590 void gtk_window_vscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
592 if (g_blockEventsOnDrag
) return;
595 printf( "OnVScroll change from " );
596 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
597 printf( win->GetClassInfo()->GetClassName() );
601 if (!win
->HasVMT()) return;
603 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
604 int value
= (int)(win
->m_vAdjust
->value
+0.5);
606 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
607 event
.SetEventObject( win
);
608 win
->ProcessEvent( event
);
611 //-----------------------------------------------------------------------------
612 // horizontal scroll change
614 void gtk_window_hscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
616 if (g_blockEventsOnDrag
) return;
619 printf( "OnHScroll change from " );
620 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
621 printf( win->GetClassInfo()->GetClassName() );
625 if (!win
->HasVMT()) return;
627 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
628 int value
= (int)(win
->m_hAdjust
->value
+0.5);
630 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
631 event
.SetEventObject( win
);
632 win
->ProcessEvent( event
);
635 //-----------------------------------------------------------------------------
638 void gtk_window_drop_callback( GtkWidget
*widget
, GdkEvent
*event
, wxWindow
*win
)
640 if (!win
->HasVMT()) return;
642 if (win
->GetDropTarget())
646 gdk_window_get_pointer( widget
->window
, &x
, &y
, NULL
);
647 win
->GetDropTarget()->Drop( event
, x
, y
);
651 g_free (event->dropdataavailable.data);
652 g_free (event->dropdataavailable.data_type);
656 //-----------------------------------------------------------------------------
659 bool gtk_window_destroy_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
661 printf( "OnDestroy from " );
662 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
663 printf( win
->GetClassInfo()->GetClassName() );
665 printf( "Goodbye.\n" );
666 printf( " Robert Roebling.\n" );
671 //-----------------------------------------------------------------------------
674 bool gtk_window_enter_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
676 if (widget
->window
!= gdk_event
->window
) return TRUE
;
677 if (g_blockEventsOnDrag
) return TRUE
;
678 if (!win
->HasVMT()) return TRUE
;
681 gdk_window_set_cursor( widget
->window
, win
->m_cursor
->GetCursor() );
683 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
684 event
.SetEventObject( win
);
685 return win
->ProcessEvent( event
);
688 //-----------------------------------------------------------------------------
691 bool gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
693 if (widget
->window
!= gdk_event
->window
) return TRUE
;
694 if (!win
->HasVMT()) return TRUE
;
695 if (g_blockEventsOnDrag
) return TRUE
;
698 gdk_window_set_cursor( widget
->window
, wxSTANDARD_CURSOR
->GetCursor() );
700 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
701 event
.SetEventObject( win
);
702 return win
->ProcessEvent( event
);
705 //-----------------------------------------------------------------------------
706 // wxWindow implementation
707 //-----------------------------------------------------------------------------
709 IMPLEMENT_DYNAMIC_CLASS(wxWindow
,wxEvtHandler
)
711 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
712 EVT_SIZE(wxWindow::OnSize
)
713 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
714 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
715 EVT_IDLE(wxWindow::OnIdle
)
723 m_children
.DeleteContents( FALSE
);
729 m_eventHandler
= this;
730 m_windowValidator
= NULL
;
732 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
733 m_font
= *wxSWISS_FONT
;
735 m_windowName
= "noname";
736 m_constraints
= NULL
;
737 m_constraintsInvolvedIn
= NULL
;
738 m_windowSizer
= NULL
;
739 m_sizerParent
= NULL
;
740 m_autoLayout
= FALSE
;
744 m_hasScrolling
= FALSE
;
747 m_oldHorizontalPos
= 0.0;
748 m_oldVerticalPos
= 0.0;
751 m_drawingOffsetX
= 0;
752 m_drawingOffsetY
= 0;
753 m_pDropTarget
= NULL
;
757 wxWindow::wxWindow( wxWindow
*parent
, wxWindowID id
,
758 const wxPoint
&pos
, const wxSize
&size
,
759 long style
, const wxString
&name
)
762 Create( parent
, id
, pos
, size
, style
, name
);
765 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
766 const wxPoint
&pos
, const wxSize
&size
,
767 long style
, const wxString
&name
)
773 PreCreation( parent
, id
, pos
, size
, style
, name
);
775 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
776 m_hasScrolling
= TRUE
;
778 GtkScrolledWindow
*s_window
;
779 s_window
= GTK_SCROLLED_WINDOW(m_widget
);
781 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
782 scroll_class
->scrollbar_spacing
= 0;
784 gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
786 m_oldHorizontalPos
= 0.0;
787 m_oldVerticalPos
= 0.0;
789 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) );
790 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) );
792 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "value_changed",
793 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
794 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "value_changed",
795 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
797 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "changed",
798 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
799 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "changed",
800 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
802 GtkViewport
*viewport
;
803 viewport
= GTK_VIEWPORT(s_window
->viewport
);
805 if (m_windowStyle
& wxRAISED_BORDER
)
807 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
809 else if (m_windowStyle
& wxSUNKEN_BORDER
)
811 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
815 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
818 m_wxwindow
= gtk_myfixed_new();
820 if (m_wxwindow
) GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
822 if (m_windowStyle
& wxTAB_TRAVERSAL
== wxTAB_TRAVERSAL
)
823 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
825 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
827 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
829 // shut the viewport up
830 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
831 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
833 // I _really_ don't want scrollbars in the beginning
834 m_vAdjust
->lower
= 0.0;
835 m_vAdjust
->upper
= 1.0;
836 m_vAdjust
->value
= 0.0;
837 m_vAdjust
->step_increment
= 1.0;
838 m_vAdjust
->page_increment
= 1.0;
839 m_vAdjust
->page_size
= 5.0;
840 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
841 m_hAdjust
->lower
= 0.0;
842 m_hAdjust
->upper
= 1.0;
843 m_hAdjust
->value
= 0.0;
844 m_hAdjust
->step_increment
= 1.0;
845 m_hAdjust
->page_increment
= 1.0;
846 m_hAdjust
->page_size
= 5.0;
847 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
849 gtk_widget_show( m_wxwindow
);
858 wxWindow::~wxWindow(void)
862 if (m_pDropTarget
) delete m_pDropTarget
;
864 if (m_parent
) m_parent
->RemoveChild( this );
865 if (m_widget
) Show( FALSE
);
869 if (m_wxwindow
) gtk_widget_destroy( m_wxwindow
);
871 if (m_widget
) gtk_widget_destroy( m_widget
);
875 DeleteRelatedConstraints();
878 // This removes any dangling pointers to this window
879 // in other windows' constraintsInvolvedIn lists.
880 UnsetConstraints(m_constraints
);
881 delete m_constraints
;
882 m_constraints
= NULL
;
886 delete m_windowSizer
;
887 m_windowSizer
= NULL
;
889 // If this is a child of a sizer, remove self from parent
891 m_sizerParent
->RemoveChild((wxWindow
*)this);
893 // Just in case the window has been Closed, but
894 // we're then deleting immediately: don't leave
895 // dangling pointers.
896 wxPendingDelete
.DeleteObject(this);
898 // Just in case we've loaded a top-level window via
899 // wxWindow::LoadNativeDialog but we weren't a dialog
901 wxTopLevelWindows
.DeleteObject(this);
905 void wxWindow::PreCreation( wxWindow
*parent
, wxWindowID id
,
906 const wxPoint
&pos
, const wxSize
&size
,
907 long style
, const wxString
&name
)
909 if (m_needParent
&& (parent
== NULL
))
910 wxFatalError( _("Need complete parent."), name
);
915 m_children
.DeleteContents( FALSE
);
919 if (m_width
== -1) m_width
= 20;
921 if (m_height
== -1) m_height
= 20;
923 m_eventHandler
= this;
924 m_windowValidator
= NULL
;
927 if (m_cursor
== NULL
)
928 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
929 m_font
= *wxSWISS_FONT
;
930 m_backgroundColour
= wxWHITE
;
931 m_foregroundColour
= wxBLACK
;
932 m_windowStyle
= style
;
934 m_constraints
= NULL
;
935 m_constraintsInvolvedIn
= NULL
;
936 m_windowSizer
= NULL
;
937 m_sizerParent
= NULL
;
938 m_autoLayout
= FALSE
;
939 m_drawingOffsetX
= 0;
940 m_drawingOffsetY
= 0;
941 m_pDropTarget
= NULL
;
945 void wxWindow::PostCreation(void)
947 if (m_parent
) m_parent
->AddChild( this );
949 // GtkStyle *style = m_widget->style;
950 // style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
952 GtkWidget
*connect_widget
= GetConnectWidget();
954 gtk_object_set_data (GTK_OBJECT (connect_widget
), "MyWxWindow", (gpointer
)this );
958 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
959 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
961 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
962 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
966 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
967 GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this );
970 gtk_signal_connect( GTK_OBJECT(connect_widget
), "key_press_event",
971 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
973 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_press_event",
974 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
976 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_release_event",
977 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
979 gtk_signal_connect( GTK_OBJECT(connect_widget
), "motion_notify_event",
980 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
982 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_in_event",
983 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
985 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_out_event",
986 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
988 // Only for cursor handling
990 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter_notify_event",
991 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
993 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave_notify_event",
994 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
998 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "enter_notify_event",
999 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
1001 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "leave_notify_event",
1002 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
1006 // Does destroy ever get called ?
1008 gtk_signal_connect( GTK_OBJECT(m_widget), "destroy_event",
1009 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1013 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "destroy_event",
1014 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1018 if (m_widget
&& m_parent
) gtk_widget_realize( m_widget
);
1019 if (m_wxwindow
) gtk_widget_realize( m_wxwindow
);
1021 SetCursor( wxSTANDARD_CURSOR
);
1026 bool wxWindow::HasVMT(void)
1031 bool wxWindow::Close( bool force
)
1033 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1034 event
.SetEventObject(this);
1035 event
.SetForce(force
);
1037 return GetEventHandler()->ProcessEvent(event
);
1040 bool wxWindow::Destroy(void)
1047 bool wxWindow::DestroyChildren(void)
1052 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
)
1055 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
)
1058 if (GetChildren()->Member(child
)) delete node
;
1065 void wxWindow::PrepareDC( wxDC
&WXUNUSED(dc
) )
1067 // are we to set fonts here ?
1070 void wxWindow::ImplementSetSize(void)
1072 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1075 void wxWindow::ImplementSetPosition(void)
1077 if (IS_KIND_OF(this,wxFrame
) || IS_KIND_OF(this,wxDialog
))
1079 if ((m_x
!= -1) || (m_y
!= -1))
1080 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1086 printf( _("wxWindow::SetSize error.\n") );
1090 if ((m_parent
) && (m_parent
->m_wxwindow
))
1091 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1093 // Don't do anything for children of wxNotebook and wxMDIChildFrame
1096 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1098 if (m_resizing
) return; // I don't like recursions
1106 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1108 if (newX
== -1) newX
= m_x
;
1109 if (newY
== -1) newY
= m_y
;
1110 if (newW
== -1) newW
= m_width
;
1111 if (newH
== -1) newH
= m_height
;
1114 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1116 if (newW
== -1) newW
= 80;
1119 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1121 if (newH
== -1) newH
= 26;
1124 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1128 ImplementSetPosition();
1130 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1138 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1139 event
.SetEventObject( this );
1140 ProcessEvent( event
);
1145 void wxWindow::SetSize( int width
, int height
)
1147 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1150 void wxWindow::Move( int x
, int y
)
1152 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1155 void wxWindow::GetSize( int *width
, int *height
) const
1157 if (width
) (*width
) = m_width
;
1158 if (height
) (*height
) = m_height
;
1161 void wxWindow::SetClientSize( int width
, int height
)
1165 SetSize( width
, height
);
1172 if (!m_hasScrolling
)
1175 do we have sunken dialogs ?
1177 GtkStyleClass *window_class = m_wxwindow->style->klass;
1179 dw += 2 * window_class->xthickness;
1180 dh += 2 * window_class->ythickness;
1185 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1186 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1188 GtkWidget
*viewport
= scroll_window
->viewport
;
1189 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1191 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1192 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1194 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1195 (m_windowStyle
& wxSUNKEN_BORDER
)
1198 dw
+= 2 * viewport_class
->xthickness
;
1199 dh
+= 2 * viewport_class
->ythickness
;
1202 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1204 dw
+= vscrollbar
->allocation
.width
;
1205 dw
+= scroll_class
->scrollbar_spacing
;
1208 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1210 dh
+= hscrollbar
->allocation
.height
;
1211 dw
+= scroll_class
->scrollbar_spacing
;
1215 SetSize( width
+dw
, height
+dh
);
1219 void wxWindow::GetClientSize( int *width
, int *height
) const
1223 if (width
) (*width
) = m_width
;
1224 if (height
) (*height
) = m_height
;
1231 if (!m_hasScrolling
)
1234 do we have sunken dialogs ?
1236 GtkStyleClass *window_class = m_wxwindow->style->klass;
1238 dw += 2 * window_class->xthickness;
1239 dh += 2 * window_class->ythickness;
1244 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1245 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1247 GtkWidget
*viewport
= scroll_window
->viewport
;
1248 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1250 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1251 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1253 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1254 (m_windowStyle
& wxSUNKEN_BORDER
)
1257 dw
+= 2 * viewport_class
->xthickness
;
1258 dh
+= 2 * viewport_class
->ythickness
;
1261 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1263 // dw += vscrollbar->allocation.width;
1264 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1265 dw
+= scroll_class
->scrollbar_spacing
;
1268 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1270 // dh += hscrollbar->allocation.height;
1272 dh
+= scroll_class
->scrollbar_spacing
;
1276 if (width
) (*width
) = m_width
- dw
;
1277 if (height
) (*height
) = m_height
- dh
;
1281 void wxWindow::GetPosition( int *x
, int *y
) const
1287 void wxWindow::ClientToScreen( int *x
, int *y
)
1289 // Does this look simple ?
1291 GdkWindow
*source
= NULL
;
1293 source
= m_wxwindow
->window
;
1295 source
= m_widget
->window
;
1299 gdk_window_get_origin( source
, &org_x
, &org_y
);
1303 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1305 org_x
+= m_widget
->allocation
.x
;
1306 org_y
+= m_widget
->allocation
.y
;
1314 void wxWindow::ScreenToClient( int *x
, int *y
)
1316 GdkWindow
*source
= NULL
;
1318 source
= m_wxwindow
->window
;
1320 source
= m_widget
->window
;
1324 gdk_window_get_origin( source
, &org_x
, &org_y
);
1328 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1330 org_x
+= m_widget
->allocation
.x
;
1331 org_y
+= m_widget
->allocation
.y
;
1339 void wxWindow::Centre( int direction
)
1341 if (IS_KIND_OF(this,wxDialog
) || IS_KIND_OF(this,wxFrame
))
1343 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
1344 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
1345 ImplementSetPosition();
1353 m_parent
->GetSize( &p_w
, &p_h
);
1354 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (p_w
- m_width
) / 2;
1355 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (p_h
- m_height
) / 2;
1356 ImplementSetPosition();
1361 void wxWindow::Fit(void)
1365 wxNode
*node
= GetChildren()->First();
1368 wxWindow
*win
= (wxWindow
*)node
->Data();
1370 win
->GetPosition(&wx
, &wy
);
1371 win
->GetSize(&ww
, &wh
);
1372 if ( wx
+ ww
> maxX
)
1374 if ( wy
+ wh
> maxY
)
1377 node
= node
->Next();
1379 SetClientSize(maxX
+ 5, maxY
+ 10);
1382 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1384 //if (GetAutoLayout()) Layout();
1387 bool wxWindow::Show( bool show
)
1390 gtk_widget_show( m_widget
);
1392 gtk_widget_hide( m_widget
);
1397 void wxWindow::Enable( bool enable
)
1399 m_isEnabled
= enable
;
1400 gtk_widget_set_sensitive( m_widget
, enable
);
1401 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1404 void wxWindow::MakeModal( bool modal
)
1407 // Disable all other windows
1408 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1410 wxNode
*node
= wxTopLevelWindows
.First();
1413 wxWindow
*win
= (wxWindow
*)node
->Data();
1415 win
->Enable(!modal
);
1417 node
= node
->Next();
1422 void wxWindow::SetFocus(void)
1424 GtkWidget
*connect_widget
= GetConnectWidget();
1427 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1429 gtk_widget_grab_focus (connect_widget
);
1434 bool wxWindow::OnClose(void)
1439 void wxWindow::AddChild( wxWindow
*child
)
1441 // Addchild is (often) called before the program
1442 // has left the parents constructor so that no
1443 // virtual tables work yet. The approach below
1444 // practically imitates virtual tables, i.e. it
1445 // implements a different AddChild() behaviour
1446 // for wxFrame, wxDialog, wxWindow and
1447 // wxMDIParentFrame.
1449 // wxFrame and wxDialog as children aren't placed into the parents
1451 if (( IS_KIND_OF(child
,wxFrame
) || IS_KIND_OF(child
,wxDialog
) ) &&
1452 (!IS_KIND_OF(child
,wxMDIChildFrame
)))
1454 m_children
.Append( child
);
1456 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1457 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1462 // In the case of an wxMDIChildFrame descendant, we use the
1463 // client windows's AddChild()
1465 if (IS_KIND_OF(this,wxMDIParentFrame
))
1467 if (IS_KIND_OF(child
,wxMDIChildFrame
))
1469 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1472 client
->AddChild( child
);
1478 // wxNotebook is very special, so it has a private AddChild()
1480 if (IS_KIND_OF(this,wxNotebook
))
1482 wxNotebook
*tab
= (wxNotebook
*)this;
1483 tab
->AddChild( child
);
1487 // wxFrame has a private AddChild
1489 if (IS_KIND_OF(this,wxFrame
) && !IS_KIND_OF(this,wxMDIChildFrame
))
1491 wxFrame
*frame
= (wxFrame
*)this;
1492 frame
->AddChild( child
);
1498 m_children
.Append( child
);
1499 if (m_wxwindow
) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
,
1500 child
->m_x
, child
->m_y
);
1502 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1505 wxList
*wxWindow::GetChildren(void)
1507 return (&m_children
);
1510 void wxWindow::RemoveChild( wxWindow
*child
)
1513 GetChildren()->DeleteObject( child
);
1514 child
->m_parent
= NULL
;
1517 void wxWindow::SetReturnCode( int retCode
)
1519 m_retCode
= retCode
;
1522 int wxWindow::GetReturnCode(void)
1527 wxWindow
*wxWindow::GetParent(void)
1532 void wxWindow::Raise(void)
1534 if (m_widget
) gdk_window_raise( m_widget
->window
);
1537 void wxWindow::Lower(void)
1539 if (m_widget
) gdk_window_lower( m_widget
->window
);
1542 wxEvtHandler
*wxWindow::GetEventHandler(void)
1544 return m_eventHandler
;
1547 void wxWindow::SetEventHandler( wxEvtHandler
*handler
)
1549 m_eventHandler
= handler
;
1552 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
1554 handler
->SetNextHandler(GetEventHandler());
1555 SetEventHandler(handler
);
1558 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
1560 if ( GetEventHandler() )
1562 wxEvtHandler
*handlerA
= GetEventHandler();
1563 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
1564 handlerA
->SetNextHandler(NULL
);
1565 SetEventHandler(handlerB
);
1566 if ( deleteHandler
)
1578 wxValidator
*wxWindow::GetValidator(void)
1580 return m_windowValidator
;
1583 void wxWindow::SetValidator( wxValidator
*validator
)
1585 m_windowValidator
= validator
;
1588 bool wxWindow::IsBeingDeleted(void)
1593 void wxWindow::SetId( wxWindowID id
)
1598 wxWindowID
wxWindow::GetId(void)
1603 void wxWindow::SetCursor( const wxCursor
&cursor
)
1605 wxASSERT(m_cursor
!= NULL
);
1607 if (m_cursor
!= NULL
)
1608 if (*m_cursor
== cursor
)
1610 (*m_cursor
) = cursor
;
1611 if (m_widget
->window
)
1612 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1613 if (m_wxwindow
&& m_wxwindow
->window
)
1614 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1617 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1619 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1622 gdk_window_clear_area( m_wxwindow
->window
,
1634 wxClientDC
dc(this);
1638 dc
.GetInternalDeviceOrigin( &x
, &y
);
1642 GetClientSize( &w
, &h
);
1644 GdkRectangle gdk_rect
;
1648 gdk_rect
.height
= h
;
1649 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1654 GdkRectangle gdk_rect
;
1655 gdk_rect
.x
= rect
->x
;
1656 gdk_rect
.y
= rect
->y
;
1657 gdk_rect
.width
= rect
->width
;
1658 gdk_rect
.height
= rect
->height
;
1661 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1663 gtk_widget_draw( m_widget
, &gdk_rect
);
1667 bool wxWindow::IsExposed( long x
, long y
)
1669 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1672 bool wxWindow::IsExposed( long x
, long y
, long width
, long height
)
1674 return (m_updateRegion
.Contains( x
, y
, width
, height
) != wxOutRegion
);
1677 void wxWindow::Clear(void)
1679 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1682 wxColour
wxWindow::GetBackgroundColour(void) const
1684 return m_backgroundColour
;
1687 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1689 m_backgroundColour
= colour
;
1692 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1693 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1694 gdk_window_clear( m_wxwindow
->window
);
1699 bool wxWindow::Validate(void)
1701 wxNode
*node
= GetChildren()->First();
1704 wxWindow
*child
= (wxWindow
*)node
->Data();
1705 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1707 node
= node
->Next();
1712 bool wxWindow::TransferDataToWindow(void)
1714 wxNode
*node
= GetChildren()->First();
1717 wxWindow
*child
= (wxWindow
*)node
->Data();
1718 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1719 !child
->GetValidator()->TransferToWindow() )
1721 wxMessageBox( _("Application Error"), _("Could not transfer data to window"), wxOK
|wxICON_EXCLAMATION
);
1724 node
= node
->Next();
1729 bool wxWindow::TransferDataFromWindow(void)
1731 wxNode
*node
= GetChildren()->First();
1734 wxWindow
*child
= (wxWindow
*)node
->Data();
1735 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1737 node
= node
->Next();
1742 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1744 TransferDataToWindow();
1747 void wxWindow::InitDialog(void)
1749 wxInitDialogEvent
event(GetId());
1750 event
.SetEventObject( this );
1751 GetEventHandler()->ProcessEvent(event
);
1754 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
1756 menu
->SetInvokingWindow( win
);
1757 wxNode
*node
= menu
->m_items
.First();
1760 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
1761 if (menuitem
->IsSubMenu())
1762 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1763 node
= node
->Next();
1767 bool wxWindow::PopupMenu( wxMenu
*menu
, int WXUNUSED(x
), int WXUNUSED(y
) )
1769 SetInvokingWindow( menu
, this );
1770 gtk_menu_popup( GTK_MENU(menu
->m_menu
), NULL
, NULL
, NULL
, NULL
, 0, 0 );
1774 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1776 GtkWidget
*dnd_widget
= GetConnectWidget();
1780 gtk_signal_disconnect_by_func( GTK_OBJECT(dnd_widget
),
1781 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1783 m_pDropTarget
->UnregisterWidget( dnd_widget
);
1784 delete m_pDropTarget
;
1786 m_pDropTarget
= dropTarget
;
1789 m_pDropTarget
->RegisterWidget( dnd_widget
);
1791 gtk_signal_connect( GTK_OBJECT(dnd_widget
), "drop_data_available_event",
1792 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1796 wxDropTarget
*wxWindow::GetDropTarget() const
1798 return m_pDropTarget
;
1801 GtkWidget
* wxWindow::GetConnectWidget(void)
1803 GtkWidget
*connect_widget
= m_widget
;
1804 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1806 return connect_widget
;
1809 void wxWindow::SetFont( const wxFont
&font
)
1814 copy old style values to new one
1815 set font in new style
1816 -> takes to many resources
1818 GtkStyle *style = gtk_style_new();
1823 wxFont
*wxWindow::GetFont(void)
1828 void wxWindow::SetWindowStyleFlag( long flag
)
1830 m_windowStyle
= flag
;
1833 long wxWindow::GetWindowStyleFlag(void) const
1835 return m_windowStyle
;
1838 void wxWindow::CaptureMouse(void)
1840 GtkWidget
*connect_widget
= GetConnectWidget();
1841 gtk_grab_add( connect_widget
);
1842 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1844 (GDK_BUTTON_PRESS_MASK
|
1845 GDK_BUTTON_RELEASE_MASK
|
1846 GDK_POINTER_MOTION_MASK
),
1847 NULL
, NULL
, GDK_CURRENT_TIME
);
1850 void wxWindow::ReleaseMouse(void)
1852 GtkWidget
*connect_widget
= GetConnectWidget();
1853 gtk_grab_remove( connect_widget
);
1854 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1857 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1861 wxString
wxWindow::GetTitle(void) const
1863 return (wxString
&)m_windowName
;
1866 wxString
wxWindow::GetLabel(void) const
1871 void wxWindow::SetName( const wxString
&name
)
1873 m_windowName
= name
;
1876 wxString
wxWindow::GetName(void) const
1878 return (wxString
&)m_windowName
;
1881 bool wxWindow::IsShown(void) const
1886 bool wxWindow::IsRetained(void)
1891 wxWindow
*wxWindow::FindWindow( long id
)
1893 if (id
== m_windowId
) return this;
1894 wxNode
*node
= m_children
.First();
1897 wxWindow
*child
= (wxWindow
*)node
->Data();
1898 wxWindow
*res
= child
->FindWindow( id
);
1899 if (res
) return res
;
1900 node
= node
->Next();
1905 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1907 if (name
== m_windowName
) return this;
1908 wxNode
*node
= m_children
.First();
1911 wxWindow
*child
= (wxWindow
*)node
->Data();
1912 wxWindow
*res
= child
->FindWindow( name
);
1913 if (res
) return res
;
1914 node
= node
->Next();
1919 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1920 int range
, bool WXUNUSED(refresh
) )
1922 if (!m_wxwindow
) return;
1924 if (orient
== wxHORIZONTAL
)
1926 float fpos
= (float)pos
;
1927 m_oldHorizontalPos
= fpos
;
1928 float frange
= (float)range
;
1929 float fthumb
= (float)thumbVisible
;
1931 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1932 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1933 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1936 m_hAdjust
->lower
= 0.0;
1937 m_hAdjust
->upper
= frange
;
1938 m_hAdjust
->value
= fpos
;
1939 m_hAdjust
->step_increment
= 1.0;
1940 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1941 m_hAdjust
->page_size
= fthumb
;
1945 float fpos
= (float)pos
;
1946 m_oldVerticalPos
= fpos
;
1947 float frange
= (float)range
;
1948 float fthumb
= (float)thumbVisible
;
1950 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1951 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1952 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1955 m_vAdjust
->lower
= 0.0;
1956 m_vAdjust
->upper
= frange
;
1957 m_vAdjust
->value
= fpos
;
1958 m_vAdjust
->step_increment
= 1.0;
1959 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1960 m_vAdjust
->page_size
= fthumb
;
1963 if (m_wxwindow
->window
)
1965 if (orient
== wxHORIZONTAL
)
1968 m_drawingOffsetX = -16000;
1970 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1972 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
1977 m_drawingOffsetY = -16000;
1979 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1981 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
1984 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1988 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
1990 if (!m_wxwindow
) return;
1992 if (orient
== wxHORIZONTAL
)
1994 float fpos
= (float)pos
;
1995 m_oldHorizontalPos
= fpos
;
1997 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
1998 m_hAdjust
->value
= fpos
;
2002 float fpos
= (float)pos
;
2003 m_oldVerticalPos
= fpos
;
2004 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
2005 m_vAdjust
->value
= fpos
;
2008 if (m_wxwindow
->window
)
2010 if (orient
== wxHORIZONTAL
)
2011 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
2013 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
2017 int wxWindow::GetScrollThumb( int orient
) const
2019 if (!m_wxwindow
) return 0;
2021 if (orient
== wxHORIZONTAL
)
2022 return (int)(m_hAdjust
->page_size
+0.5);
2024 return (int)(m_vAdjust
->page_size
+0.5);
2027 int wxWindow::GetScrollPos( int orient
) const
2029 if (!m_wxwindow
) return 0;
2031 if (orient
== wxHORIZONTAL
)
2032 return (int)(m_hAdjust
->value
+0.5);
2034 return (int)(m_vAdjust
->value
+0.5);
2037 int wxWindow::GetScrollRange( int orient
) const
2039 if (!m_wxwindow
) return 0;
2041 if (orient
== wxHORIZONTAL
)
2042 return (int)(m_hAdjust
->upper
+0.5);
2044 return (int)(m_vAdjust
->upper
+0.5);
2047 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
2049 if (!m_wxwindow
) return;
2051 bool refresh
= FALSE
;
2053 if ((m_drawingOffsetX
== 0) && (m_drawingOffsetY
== 0))
2055 m_drawingOffsetX
= -16000;
2056 m_drawingOffsetY
= -16000;
2061 m_drawingOffsetX
+= dx
;
2062 m_drawingOffsetY
+= dy
;
2065 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
2067 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow
), m_drawingOffsetX
, m_drawingOffsetY
);
2069 if (refresh
) Refresh();
2072 The code here is very nifty, but it doesn't work with
2073 overlapping windows...
2077 GetClientSize( &cw, &ch );
2079 int w = cw - abs(dx);
2080 int h = ch - abs(dy);
2081 if ((h < 0) || (w < 0))
2088 if (dx < 0) s_x = -dx;
2089 if (dy < 0) s_y = -dy;
2092 if (dx > 0) d_x = dx;
2093 if (dy > 0) d_y = dy;
2094 gdk_window_copy_area( m_wxwindow->window, m_wxwindow->style->fg_gc[0], d_x, d_y,
2095 m_wxwindow->window, s_x, s_y, w, h );
2098 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
2099 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
2100 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
2101 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
2103 Refresh( TRUE, &rect );
2107 void wxWindow::GetDrawingOffset( long *x
, long *y
)
2109 if (x
) *x
= m_drawingOffsetX
;
2110 if (y
) *y
= m_drawingOffsetY
;
2113 //-------------------------------------------------------------------------------------
2115 //-------------------------------------------------------------------------------------
2117 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
2119 return m_constraints
;
2122 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
2126 UnsetConstraints(m_constraints
);
2127 delete m_constraints
;
2129 m_constraints
= constraints
;
2132 // Make sure other windows know they're part of a 'meaningful relationship'
2133 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
2134 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2135 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
2136 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2137 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
2138 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2139 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
2140 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2141 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
2142 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2143 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
2144 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2145 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
2146 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2147 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
2148 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2154 void wxWindow::SetAutoLayout( bool autoLayout
)
2156 m_autoLayout
= autoLayout
;
2159 bool wxWindow::GetAutoLayout(void) const
2161 return m_autoLayout
;
2164 wxSizer
*wxWindow::GetSizer(void) const
2166 return m_windowSizer
;
2169 void wxWindow::SetSizerParent( wxWindow
*win
)
2171 m_sizerParent
= win
;
2174 wxWindow
*wxWindow::GetSizerParent(void) const
2176 return m_sizerParent
;
2179 // This removes any dangling pointers to this window
2180 // in other windows' constraintsInvolvedIn lists.
2181 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2185 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2186 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2187 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2188 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2189 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2190 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2191 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2192 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2193 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2194 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2195 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2196 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2197 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2198 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2199 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2200 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2204 // Back-pointer to other windows we're involved with, so if we delete
2205 // this window, we must delete any constraints we're involved with.
2206 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2208 if (!m_constraintsInvolvedIn
)
2209 m_constraintsInvolvedIn
= new wxList
;
2210 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2211 m_constraintsInvolvedIn
->Append(otherWin
);
2214 // REMOVE back-pointer to other windows we're involved with.
2215 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2217 if (m_constraintsInvolvedIn
)
2218 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2221 // Reset any constraints that mention this window
2222 void wxWindow::DeleteRelatedConstraints(void)
2224 if (m_constraintsInvolvedIn
)
2226 wxNode
*node
= m_constraintsInvolvedIn
->First();
2229 wxWindow
*win
= (wxWindow
*)node
->Data();
2230 wxNode
*next
= node
->Next();
2231 wxLayoutConstraints
*constr
= win
->GetConstraints();
2233 // Reset any constraints involving this window
2236 constr
->left
.ResetIfWin((wxWindow
*)this);
2237 constr
->top
.ResetIfWin((wxWindow
*)this);
2238 constr
->right
.ResetIfWin((wxWindow
*)this);
2239 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2240 constr
->width
.ResetIfWin((wxWindow
*)this);
2241 constr
->height
.ResetIfWin((wxWindow
*)this);
2242 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2243 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2248 delete m_constraintsInvolvedIn
;
2249 m_constraintsInvolvedIn
= NULL
;
2253 void wxWindow::SetSizer(wxSizer
*sizer
)
2255 m_windowSizer
= sizer
;
2257 sizer
->SetSizerParent((wxWindow
*)this);
2264 bool wxWindow::Layout(void)
2266 if (GetConstraints())
2269 GetClientSize(&w
, &h
);
2270 GetConstraints()->width
.SetValue(w
);
2271 GetConstraints()->height
.SetValue(h
);
2274 // If top level (one sizer), evaluate the sizer's constraints.
2278 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2279 GetSizer()->LayoutPhase1(&noChanges
);
2280 GetSizer()->LayoutPhase2(&noChanges
);
2281 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2286 // Otherwise, evaluate child constraints
2287 ResetConstraints(); // Mark all constraints as unevaluated
2288 DoPhase(1); // Just one phase need if no sizers involved
2290 SetConstraintSizes(); // Recursively set the real window sizes
2296 // Do a phase of evaluating constraints:
2297 // the default behaviour. wxSizers may do a similar
2298 // thing, but also impose their own 'constraints'
2299 // and order the evaluation differently.
2300 bool wxWindow::LayoutPhase1(int *noChanges
)
2302 wxLayoutConstraints
*constr
= GetConstraints();
2305 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2311 bool wxWindow::LayoutPhase2(int *noChanges
)
2321 // Do a phase of evaluating child constraints
2322 bool wxWindow::DoPhase(int phase
)
2324 int noIterations
= 0;
2325 int maxIterations
= 500;
2329 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2333 wxNode
*node
= GetChildren()->First();
2336 wxWindow
*child
= (wxWindow
*)node
->Data();
2337 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2339 wxLayoutConstraints
*constr
= child
->GetConstraints();
2342 if (succeeded
.Member(child
))
2347 int tempNoChanges
= 0;
2348 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2349 noChanges
+= tempNoChanges
;
2352 succeeded
.Append(child
);
2357 node
= node
->Next();
2364 void wxWindow::ResetConstraints(void)
2366 wxLayoutConstraints
*constr
= GetConstraints();
2369 constr
->left
.SetDone(FALSE
);
2370 constr
->top
.SetDone(FALSE
);
2371 constr
->right
.SetDone(FALSE
);
2372 constr
->bottom
.SetDone(FALSE
);
2373 constr
->width
.SetDone(FALSE
);
2374 constr
->height
.SetDone(FALSE
);
2375 constr
->centreX
.SetDone(FALSE
);
2376 constr
->centreY
.SetDone(FALSE
);
2378 wxNode
*node
= GetChildren()->First();
2381 wxWindow
*win
= (wxWindow
*)node
->Data();
2382 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2383 win
->ResetConstraints();
2384 node
= node
->Next();
2388 // Need to distinguish between setting the 'fake' size for
2389 // windows and sizers, and setting the real values.
2390 void wxWindow::SetConstraintSizes(bool recurse
)
2392 wxLayoutConstraints
*constr
= GetConstraints();
2393 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2394 constr
->width
.GetDone() && constr
->height
.GetDone())
2396 int x
= constr
->left
.GetValue();
2397 int y
= constr
->top
.GetValue();
2398 int w
= constr
->width
.GetValue();
2399 int h
= constr
->height
.GetValue();
2401 // If we don't want to resize this window, just move it...
2402 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2403 (constr
->height
.GetRelationship() != wxAsIs
))
2405 // Calls Layout() recursively. AAAGH. How can we stop that.
2406 // Simply take Layout() out of non-top level OnSizes.
2407 SizerSetSize(x
, y
, w
, h
);
2416 char *windowClass
= this->GetClassInfo()->GetClassName();
2419 if (GetName() == "")
2420 winName
= _("unnamed");
2422 winName
= GetName();
2423 wxDebugMsg(_("Constraint(s) not satisfied for window of type %s, name %s:\n"), (const char *)windowClass
, (const char *)winName
);
2424 if (!constr
->left
.GetDone())
2425 wxDebugMsg(_(" unsatisfied 'left' constraint.\n"));
2426 if (!constr
->right
.GetDone())
2427 wxDebugMsg(_(" unsatisfied 'right' constraint.\n"));
2428 if (!constr
->width
.GetDone())
2429 wxDebugMsg(_(" unsatisfied 'width' constraint.\n"));
2430 if (!constr
->height
.GetDone())
2431 wxDebugMsg(_(" unsatisfied 'height' constraint.\n"));
2432 wxDebugMsg(_("Please check constraints: try adding AsIs() constraints.\n"));
2437 wxNode
*node
= GetChildren()->First();
2440 wxWindow
*win
= (wxWindow
*)node
->Data();
2441 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2442 win
->SetConstraintSizes();
2443 node
= node
->Next();
2448 // This assumes that all sizers are 'on' the same
2449 // window, i.e. the parent of this window.
2450 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2452 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2453 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2457 m_sizerParent
->GetPosition(&xp
, &yp
);
2458 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2463 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2467 TransformSizerToActual(&xx
, &yy
);
2468 SetSize(xx
, yy
, w
, h
);
2471 void wxWindow::SizerMove(int x
, int y
)
2475 TransformSizerToActual(&xx
, &yy
);
2479 // Only set the size/position of the constraint (if any)
2480 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2482 wxLayoutConstraints
*constr
= GetConstraints();
2487 constr
->left
.SetValue(x
);
2488 constr
->left
.SetDone(TRUE
);
2492 constr
->top
.SetValue(y
);
2493 constr
->top
.SetDone(TRUE
);
2497 constr
->width
.SetValue(w
);
2498 constr
->width
.SetDone(TRUE
);
2502 constr
->height
.SetValue(h
);
2503 constr
->height
.SetDone(TRUE
);
2508 void wxWindow::MoveConstraint(int x
, int y
)
2510 wxLayoutConstraints
*constr
= GetConstraints();
2515 constr
->left
.SetValue(x
);
2516 constr
->left
.SetDone(TRUE
);
2520 constr
->top
.SetValue(y
);
2521 constr
->top
.SetDone(TRUE
);
2526 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2528 wxLayoutConstraints
*constr
= GetConstraints();
2531 *w
= constr
->width
.GetValue();
2532 *h
= constr
->height
.GetValue();
2538 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2540 wxLayoutConstraints
*constr
= GetConstraints();
2543 *w
= constr
->width
.GetValue();
2544 *h
= constr
->height
.GetValue();
2547 GetClientSize(w
, h
);
2550 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2552 wxLayoutConstraints
*constr
= GetConstraints();
2555 *x
= constr
->left
.GetValue();
2556 *y
= constr
->top
.GetValue();
2562 bool wxWindow::AcceptsFocus() const
2564 return IsEnabled() && IsShown();
2567 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
) )