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 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
758 const wxPoint
&pos
, const wxSize
&size
,
759 long style
, const wxString
&name
)
767 PreCreation( parent
, id
, pos
, size
, style
, name
);
769 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
770 m_hasScrolling
= TRUE
;
772 GtkScrolledWindow
*s_window
;
773 s_window
= GTK_SCROLLED_WINDOW(m_widget
);
775 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
776 scroll_class
->scrollbar_spacing
= 0;
778 gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
780 m_oldHorizontalPos
= 0.0;
781 m_oldVerticalPos
= 0.0;
783 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) );
784 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) );
786 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "value_changed",
787 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
788 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "value_changed",
789 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
791 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "changed",
792 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
793 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "changed",
794 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
796 GtkViewport
*viewport
;
797 viewport
= GTK_VIEWPORT(s_window
->viewport
);
799 if (m_windowStyle
& wxRAISED_BORDER
)
801 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
803 else if (m_windowStyle
& wxSUNKEN_BORDER
)
805 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
809 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
812 m_wxwindow
= gtk_myfixed_new();
814 if (m_wxwindow
) GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
816 if (m_windowStyle
& wxTAB_TRAVERSAL
== wxTAB_TRAVERSAL
)
817 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
819 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
821 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
823 // shut the viewport up
824 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
825 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
827 // I _really_ don't want scrollbars in the beginning
828 m_vAdjust
->lower
= 0.0;
829 m_vAdjust
->upper
= 1.0;
830 m_vAdjust
->value
= 0.0;
831 m_vAdjust
->step_increment
= 1.0;
832 m_vAdjust
->page_increment
= 1.0;
833 m_vAdjust
->page_size
= 5.0;
834 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
835 m_hAdjust
->lower
= 0.0;
836 m_hAdjust
->upper
= 1.0;
837 m_hAdjust
->value
= 0.0;
838 m_hAdjust
->step_increment
= 1.0;
839 m_hAdjust
->page_increment
= 1.0;
840 m_hAdjust
->page_size
= 5.0;
841 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
843 gtk_widget_show( m_wxwindow
);
852 wxWindow::~wxWindow(void)
856 if (m_pDropTarget
) delete m_pDropTarget
;
858 if (m_parent
) m_parent
->RemoveChild( this );
859 if (m_widget
) Show( FALSE
);
863 if (m_wxwindow
) gtk_widget_destroy( m_wxwindow
);
865 if (m_widget
) gtk_widget_destroy( m_widget
);
869 DeleteRelatedConstraints();
872 // This removes any dangling pointers to this window
873 // in other windows' constraintsInvolvedIn lists.
874 UnsetConstraints(m_constraints
);
875 delete m_constraints
;
876 m_constraints
= NULL
;
880 delete m_windowSizer
;
881 m_windowSizer
= NULL
;
883 // If this is a child of a sizer, remove self from parent
884 if (m_sizerParent
) m_sizerParent
->RemoveChild((wxWindow
*)this);
886 // Just in case the window has been Closed, but
887 // we're then deleting immediately: don't leave
888 // dangling pointers.
889 wxPendingDelete
.DeleteObject(this);
891 // Just in case we've loaded a top-level window via
892 // wxWindow::LoadNativeDialog but we weren't a dialog
894 wxTopLevelWindows
.DeleteObject(this);
896 if (m_windowValidator
) delete m_windowValidator
;
899 void wxWindow::PreCreation( wxWindow
*parent
, wxWindowID id
,
900 const wxPoint
&pos
, const wxSize
&size
,
901 long style
, const wxString
&name
)
903 if (m_needParent
&& (parent
== NULL
))
904 wxFatalError( _("Need complete parent."), name
);
909 m_children
.DeleteContents( FALSE
);
913 if (m_width
== -1) m_width
= 20;
915 if (m_height
== -1) m_height
= 20;
917 m_eventHandler
= this;
920 if (m_cursor
== NULL
)
921 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
922 m_font
= *wxSWISS_FONT
;
923 m_backgroundColour
= wxWHITE
;
924 m_foregroundColour
= wxBLACK
;
925 m_windowStyle
= style
;
927 m_constraints
= NULL
;
928 m_constraintsInvolvedIn
= NULL
;
929 m_windowSizer
= NULL
;
930 m_sizerParent
= NULL
;
931 m_autoLayout
= FALSE
;
932 m_drawingOffsetX
= 0;
933 m_drawingOffsetY
= 0;
934 m_pDropTarget
= NULL
;
936 m_windowValidator
= NULL
;
939 void wxWindow::PostCreation(void)
941 if (m_parent
) m_parent
->AddChild( this );
943 // GtkStyle *style = m_widget->style;
944 // style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
946 GtkWidget
*connect_widget
= GetConnectWidget();
948 gtk_object_set_data (GTK_OBJECT (connect_widget
), "MyWxWindow", (gpointer
)this );
952 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
953 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
955 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
956 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
960 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
961 GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this );
964 gtk_signal_connect( GTK_OBJECT(connect_widget
), "key_press_event",
965 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
967 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_press_event",
968 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
970 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_release_event",
971 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
973 gtk_signal_connect( GTK_OBJECT(connect_widget
), "motion_notify_event",
974 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
976 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_in_event",
977 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
979 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_out_event",
980 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
982 // Only for cursor handling
984 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter_notify_event",
985 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
987 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave_notify_event",
988 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
992 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "enter_notify_event",
993 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
995 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "leave_notify_event",
996 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
1000 // Does destroy ever get called ?
1002 gtk_signal_connect( GTK_OBJECT(m_widget), "destroy_event",
1003 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1007 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "destroy_event",
1008 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1012 if (m_widget
&& m_parent
) gtk_widget_realize( m_widget
);
1013 if (m_wxwindow
) gtk_widget_realize( m_wxwindow
);
1015 SetCursor( wxSTANDARD_CURSOR
);
1020 bool wxWindow::HasVMT(void)
1025 bool wxWindow::Close( bool force
)
1027 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1028 event
.SetEventObject(this);
1029 event
.SetForce(force
);
1031 return GetEventHandler()->ProcessEvent(event
);
1034 bool wxWindow::Destroy(void)
1041 bool wxWindow::DestroyChildren(void)
1046 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
)
1049 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
)
1052 if (GetChildren()->Member(child
)) delete node
;
1059 void wxWindow::PrepareDC( wxDC
&WXUNUSED(dc
) )
1061 // are we to set fonts here ?
1064 void wxWindow::ImplementSetSize(void)
1066 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1069 void wxWindow::ImplementSetPosition(void)
1071 if (IS_KIND_OF(this,wxFrame
) || IS_KIND_OF(this,wxDialog
))
1073 if ((m_x
!= -1) || (m_y
!= -1))
1074 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1080 printf( _("wxWindow::SetSize error.\n") );
1084 if ((m_parent
) && (m_parent
->m_wxwindow
))
1085 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1087 // Don't do anything for children of wxNotebook and wxMDIChildFrame
1090 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1092 if (m_resizing
) return; // I don't like recursions
1100 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1102 if (newX
== -1) newX
= m_x
;
1103 if (newY
== -1) newY
= m_y
;
1104 if (newW
== -1) newW
= m_width
;
1105 if (newH
== -1) newH
= m_height
;
1108 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1110 if (newW
== -1) newW
= 80;
1113 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1115 if (newH
== -1) newH
= 26;
1118 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1122 ImplementSetPosition();
1124 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1132 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1133 event
.SetEventObject( this );
1134 ProcessEvent( event
);
1139 void wxWindow::SetSize( int width
, int height
)
1141 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1144 void wxWindow::Move( int x
, int y
)
1146 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1149 void wxWindow::GetSize( int *width
, int *height
) const
1151 if (width
) (*width
) = m_width
;
1152 if (height
) (*height
) = m_height
;
1155 void wxWindow::SetClientSize( int width
, int height
)
1159 SetSize( width
, height
);
1166 if (!m_hasScrolling
)
1169 do we have sunken dialogs ?
1171 GtkStyleClass *window_class = m_wxwindow->style->klass;
1173 dw += 2 * window_class->xthickness;
1174 dh += 2 * window_class->ythickness;
1179 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1180 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1182 GtkWidget
*viewport
= scroll_window
->viewport
;
1183 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1185 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1186 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1188 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1189 (m_windowStyle
& wxSUNKEN_BORDER
)
1192 dw
+= 2 * viewport_class
->xthickness
;
1193 dh
+= 2 * viewport_class
->ythickness
;
1196 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1198 dw
+= vscrollbar
->allocation
.width
;
1199 dw
+= scroll_class
->scrollbar_spacing
;
1202 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1204 dh
+= hscrollbar
->allocation
.height
;
1205 dw
+= scroll_class
->scrollbar_spacing
;
1209 SetSize( width
+dw
, height
+dh
);
1213 void wxWindow::GetClientSize( int *width
, int *height
) const
1217 if (width
) (*width
) = m_width
;
1218 if (height
) (*height
) = m_height
;
1225 if (!m_hasScrolling
)
1228 do we have sunken dialogs ?
1230 GtkStyleClass *window_class = m_wxwindow->style->klass;
1232 dw += 2 * window_class->xthickness;
1233 dh += 2 * window_class->ythickness;
1238 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1239 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1241 GtkWidget
*viewport
= scroll_window
->viewport
;
1242 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1244 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1245 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1247 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1248 (m_windowStyle
& wxSUNKEN_BORDER
)
1251 dw
+= 2 * viewport_class
->xthickness
;
1252 dh
+= 2 * viewport_class
->ythickness
;
1255 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1257 // dw += vscrollbar->allocation.width;
1258 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1259 dw
+= scroll_class
->scrollbar_spacing
;
1262 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1264 // dh += hscrollbar->allocation.height;
1266 dh
+= scroll_class
->scrollbar_spacing
;
1270 if (width
) (*width
) = m_width
- dw
;
1271 if (height
) (*height
) = m_height
- dh
;
1275 void wxWindow::GetPosition( int *x
, int *y
) const
1281 void wxWindow::ClientToScreen( int *x
, int *y
)
1283 // Does this look simple ?
1285 GdkWindow
*source
= NULL
;
1287 source
= m_wxwindow
->window
;
1289 source
= m_widget
->window
;
1293 gdk_window_get_origin( source
, &org_x
, &org_y
);
1297 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1299 org_x
+= m_widget
->allocation
.x
;
1300 org_y
+= m_widget
->allocation
.y
;
1308 void wxWindow::ScreenToClient( int *x
, int *y
)
1310 GdkWindow
*source
= NULL
;
1312 source
= m_wxwindow
->window
;
1314 source
= m_widget
->window
;
1318 gdk_window_get_origin( source
, &org_x
, &org_y
);
1322 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1324 org_x
+= m_widget
->allocation
.x
;
1325 org_y
+= m_widget
->allocation
.y
;
1333 void wxWindow::Centre( int direction
)
1335 if (IS_KIND_OF(this,wxDialog
) || IS_KIND_OF(this,wxFrame
))
1337 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
1338 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
1339 ImplementSetPosition();
1347 m_parent
->GetSize( &p_w
, &p_h
);
1348 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (p_w
- m_width
) / 2;
1349 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (p_h
- m_height
) / 2;
1350 ImplementSetPosition();
1355 void wxWindow::Fit(void)
1359 wxNode
*node
= GetChildren()->First();
1362 wxWindow
*win
= (wxWindow
*)node
->Data();
1364 win
->GetPosition(&wx
, &wy
);
1365 win
->GetSize(&ww
, &wh
);
1366 if ( wx
+ ww
> maxX
)
1368 if ( wy
+ wh
> maxY
)
1371 node
= node
->Next();
1373 SetClientSize(maxX
+ 5, maxY
+ 10);
1376 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1378 //if (GetAutoLayout()) Layout();
1381 bool wxWindow::Show( bool show
)
1384 gtk_widget_show( m_widget
);
1386 gtk_widget_hide( m_widget
);
1391 void wxWindow::Enable( bool enable
)
1393 m_isEnabled
= enable
;
1394 gtk_widget_set_sensitive( m_widget
, enable
);
1395 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1398 void wxWindow::MakeModal( bool modal
)
1401 // Disable all other windows
1402 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1404 wxNode
*node
= wxTopLevelWindows
.First();
1407 wxWindow
*win
= (wxWindow
*)node
->Data();
1409 win
->Enable(!modal
);
1411 node
= node
->Next();
1416 void wxWindow::SetFocus(void)
1418 GtkWidget
*connect_widget
= GetConnectWidget();
1421 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1423 gtk_widget_grab_focus (connect_widget
);
1428 bool wxWindow::OnClose(void)
1433 void wxWindow::AddChild( wxWindow
*child
)
1435 // Addchild is (often) called before the program
1436 // has left the parents constructor so that no
1437 // virtual tables work yet. The approach below
1438 // practically imitates virtual tables, i.e. it
1439 // implements a different AddChild() behaviour
1440 // for wxFrame, wxDialog, wxWindow and
1441 // wxMDIParentFrame.
1443 // wxFrame and wxDialog as children aren't placed into the parents
1445 if (( IS_KIND_OF(child
,wxFrame
) || IS_KIND_OF(child
,wxDialog
) ) &&
1446 (!IS_KIND_OF(child
,wxMDIChildFrame
)))
1448 m_children
.Append( child
);
1450 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1451 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1456 // In the case of an wxMDIChildFrame descendant, we use the
1457 // client windows's AddChild()
1459 if (IS_KIND_OF(this,wxMDIParentFrame
))
1461 if (IS_KIND_OF(child
,wxMDIChildFrame
))
1463 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1466 client
->AddChild( child
);
1472 // wxNotebook is very special, so it has a private AddChild()
1474 if (IS_KIND_OF(this,wxNotebook
))
1476 wxNotebook
*tab
= (wxNotebook
*)this;
1477 tab
->AddChild( child
);
1481 // wxFrame has a private AddChild
1483 if (IS_KIND_OF(this,wxFrame
) && !IS_KIND_OF(this,wxMDIChildFrame
))
1485 wxFrame
*frame
= (wxFrame
*)this;
1486 frame
->AddChild( child
);
1492 m_children
.Append( child
);
1493 if (m_wxwindow
) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
,
1494 child
->m_x
, child
->m_y
);
1496 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1499 wxList
*wxWindow::GetChildren(void)
1501 return (&m_children
);
1504 void wxWindow::RemoveChild( wxWindow
*child
)
1507 GetChildren()->DeleteObject( child
);
1508 child
->m_parent
= NULL
;
1511 void wxWindow::SetReturnCode( int retCode
)
1513 m_retCode
= retCode
;
1516 int wxWindow::GetReturnCode(void)
1521 wxWindow
*wxWindow::GetParent(void)
1526 void wxWindow::Raise(void)
1528 if (m_widget
) gdk_window_raise( m_widget
->window
);
1531 void wxWindow::Lower(void)
1533 if (m_widget
) gdk_window_lower( m_widget
->window
);
1536 wxEvtHandler
*wxWindow::GetEventHandler(void)
1538 return m_eventHandler
;
1541 void wxWindow::SetEventHandler( wxEvtHandler
*handler
)
1543 m_eventHandler
= handler
;
1546 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
1548 handler
->SetNextHandler(GetEventHandler());
1549 SetEventHandler(handler
);
1552 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
1554 if ( GetEventHandler() )
1556 wxEvtHandler
*handlerA
= GetEventHandler();
1557 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
1558 handlerA
->SetNextHandler(NULL
);
1559 SetEventHandler(handlerB
);
1560 if ( deleteHandler
)
1572 wxValidator
*wxWindow::GetValidator(void)
1574 return m_windowValidator
;
1577 void wxWindow::SetValidator( const wxValidator
& validator
)
1579 if (m_windowValidator
) delete m_windowValidator
;
1580 m_windowValidator
= validator
.Clone();
1581 if (m_windowValidator
) m_windowValidator
->SetWindow(this);
1584 bool wxWindow::IsBeingDeleted(void)
1589 void wxWindow::SetId( wxWindowID id
)
1594 wxWindowID
wxWindow::GetId(void)
1599 void wxWindow::SetCursor( const wxCursor
&cursor
)
1601 wxASSERT(m_cursor
!= NULL
);
1603 if (m_cursor
!= NULL
)
1604 if (*m_cursor
== cursor
)
1606 (*m_cursor
) = cursor
;
1607 if (m_widget
->window
)
1608 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1609 if (m_wxwindow
&& m_wxwindow
->window
)
1610 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1613 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1615 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1618 gdk_window_clear_area( m_wxwindow
->window
,
1630 wxClientDC
dc(this);
1634 dc
.GetInternalDeviceOrigin( &x
, &y
);
1638 GetClientSize( &w
, &h
);
1640 GdkRectangle gdk_rect
;
1644 gdk_rect
.height
= h
;
1645 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1650 GdkRectangle gdk_rect
;
1651 gdk_rect
.x
= rect
->x
;
1652 gdk_rect
.y
= rect
->y
;
1653 gdk_rect
.width
= rect
->width
;
1654 gdk_rect
.height
= rect
->height
;
1657 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1659 gtk_widget_draw( m_widget
, &gdk_rect
);
1663 bool wxWindow::IsExposed( long x
, long y
)
1665 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1668 bool wxWindow::IsExposed( long x
, long y
, long width
, long height
)
1670 return (m_updateRegion
.Contains( x
, y
, width
, height
) != wxOutRegion
);
1673 void wxWindow::Clear(void)
1675 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1678 wxColour
wxWindow::GetBackgroundColour(void) const
1680 return m_backgroundColour
;
1683 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1685 m_backgroundColour
= colour
;
1688 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1689 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1690 gdk_window_clear( m_wxwindow
->window
);
1695 wxColour
wxWindow::GetForegroundColour(void) const
1697 return m_foregroundColour
;
1700 void wxWindow::SetForegroundColour( const wxColour
&colour
)
1702 m_foregroundColour
= colour
;
1705 bool wxWindow::Validate(void)
1707 wxNode
*node
= GetChildren()->First();
1710 wxWindow
*child
= (wxWindow
*)node
->Data();
1711 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1713 node
= node
->Next();
1718 bool wxWindow::TransferDataToWindow(void)
1720 wxNode
*node
= GetChildren()->First();
1723 wxWindow
*child
= (wxWindow
*)node
->Data();
1724 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1725 !child
->GetValidator()->TransferToWindow() )
1727 wxMessageBox( _("Application Error"), _("Could not transfer data to window"), wxOK
|wxICON_EXCLAMATION
);
1730 node
= node
->Next();
1735 bool wxWindow::TransferDataFromWindow(void)
1737 wxNode
*node
= GetChildren()->First();
1740 wxWindow
*child
= (wxWindow
*)node
->Data();
1741 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1743 node
= node
->Next();
1748 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1750 TransferDataToWindow();
1753 void wxWindow::InitDialog(void)
1755 wxInitDialogEvent
event(GetId());
1756 event
.SetEventObject( this );
1757 GetEventHandler()->ProcessEvent(event
);
1760 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
1762 menu
->SetInvokingWindow( win
);
1763 wxNode
*node
= menu
->m_items
.First();
1766 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
1767 if (menuitem
->IsSubMenu())
1768 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1769 node
= node
->Next();
1773 bool wxWindow::PopupMenu( wxMenu
*menu
, int WXUNUSED(x
), int WXUNUSED(y
) )
1775 SetInvokingWindow( menu
, this );
1776 gtk_menu_popup( GTK_MENU(menu
->m_menu
), NULL
, NULL
, NULL
, NULL
, 0, 0 );
1780 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1782 GtkWidget
*dnd_widget
= GetConnectWidget();
1786 gtk_signal_disconnect_by_func( GTK_OBJECT(dnd_widget
),
1787 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1789 m_pDropTarget
->UnregisterWidget( dnd_widget
);
1790 delete m_pDropTarget
;
1792 m_pDropTarget
= dropTarget
;
1795 m_pDropTarget
->RegisterWidget( dnd_widget
);
1797 gtk_signal_connect( GTK_OBJECT(dnd_widget
), "drop_data_available_event",
1798 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1802 wxDropTarget
*wxWindow::GetDropTarget() const
1804 return m_pDropTarget
;
1807 GtkWidget
* wxWindow::GetConnectWidget(void)
1809 GtkWidget
*connect_widget
= m_widget
;
1810 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1812 return connect_widget
;
1815 void wxWindow::SetFont( const wxFont
&font
)
1820 copy old style values to new one
1821 set font in new style
1822 -> takes to many resources
1824 GtkStyle *style = gtk_style_new();
1829 wxFont
*wxWindow::GetFont(void)
1834 void wxWindow::SetWindowStyleFlag( long flag
)
1836 m_windowStyle
= flag
;
1839 long wxWindow::GetWindowStyleFlag(void) const
1841 return m_windowStyle
;
1844 void wxWindow::CaptureMouse(void)
1846 GtkWidget
*connect_widget
= GetConnectWidget();
1847 gtk_grab_add( connect_widget
);
1848 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1850 (GDK_BUTTON_PRESS_MASK
|
1851 GDK_BUTTON_RELEASE_MASK
|
1852 GDK_POINTER_MOTION_MASK
),
1853 NULL
, NULL
, GDK_CURRENT_TIME
);
1856 void wxWindow::ReleaseMouse(void)
1858 GtkWidget
*connect_widget
= GetConnectWidget();
1859 gtk_grab_remove( connect_widget
);
1860 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1863 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1867 wxString
wxWindow::GetTitle(void) const
1869 return (wxString
&)m_windowName
;
1872 wxString
wxWindow::GetLabel(void) const
1877 void wxWindow::SetName( const wxString
&name
)
1879 m_windowName
= name
;
1882 wxString
wxWindow::GetName(void) const
1884 return (wxString
&)m_windowName
;
1887 bool wxWindow::IsShown(void) const
1892 bool wxWindow::IsRetained(void)
1897 wxWindow
*wxWindow::FindWindow( long id
)
1899 if (id
== m_windowId
) return this;
1900 wxNode
*node
= m_children
.First();
1903 wxWindow
*child
= (wxWindow
*)node
->Data();
1904 wxWindow
*res
= child
->FindWindow( id
);
1905 if (res
) return res
;
1906 node
= node
->Next();
1911 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1913 if (name
== m_windowName
) return this;
1914 wxNode
*node
= m_children
.First();
1917 wxWindow
*child
= (wxWindow
*)node
->Data();
1918 wxWindow
*res
= child
->FindWindow( name
);
1919 if (res
) return res
;
1920 node
= node
->Next();
1925 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1926 int range
, bool WXUNUSED(refresh
) )
1928 if (!m_wxwindow
) return;
1930 if (orient
== wxHORIZONTAL
)
1932 float fpos
= (float)pos
;
1933 m_oldHorizontalPos
= fpos
;
1934 float frange
= (float)range
;
1935 float fthumb
= (float)thumbVisible
;
1937 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1938 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1939 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1942 m_hAdjust
->lower
= 0.0;
1943 m_hAdjust
->upper
= frange
;
1944 m_hAdjust
->value
= fpos
;
1945 m_hAdjust
->step_increment
= 1.0;
1946 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1947 m_hAdjust
->page_size
= fthumb
;
1951 float fpos
= (float)pos
;
1952 m_oldVerticalPos
= fpos
;
1953 float frange
= (float)range
;
1954 float fthumb
= (float)thumbVisible
;
1956 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1957 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1958 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1961 m_vAdjust
->lower
= 0.0;
1962 m_vAdjust
->upper
= frange
;
1963 m_vAdjust
->value
= fpos
;
1964 m_vAdjust
->step_increment
= 1.0;
1965 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1966 m_vAdjust
->page_size
= fthumb
;
1969 if (m_wxwindow
->window
)
1971 if (orient
== wxHORIZONTAL
)
1974 m_drawingOffsetX = -16000;
1976 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1978 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
1983 m_drawingOffsetY = -16000;
1985 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1987 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
1990 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1994 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
1996 if (!m_wxwindow
) return;
1998 if (orient
== wxHORIZONTAL
)
2000 float fpos
= (float)pos
;
2001 m_oldHorizontalPos
= fpos
;
2003 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
2004 m_hAdjust
->value
= fpos
;
2008 float fpos
= (float)pos
;
2009 m_oldVerticalPos
= fpos
;
2010 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
2011 m_vAdjust
->value
= fpos
;
2014 if (m_wxwindow
->window
)
2016 if (orient
== wxHORIZONTAL
)
2017 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
2019 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
2023 int wxWindow::GetScrollThumb( int orient
) const
2025 if (!m_wxwindow
) return 0;
2027 if (orient
== wxHORIZONTAL
)
2028 return (int)(m_hAdjust
->page_size
+0.5);
2030 return (int)(m_vAdjust
->page_size
+0.5);
2033 int wxWindow::GetScrollPos( int orient
) const
2035 if (!m_wxwindow
) return 0;
2037 if (orient
== wxHORIZONTAL
)
2038 return (int)(m_hAdjust
->value
+0.5);
2040 return (int)(m_vAdjust
->value
+0.5);
2043 int wxWindow::GetScrollRange( int orient
) const
2045 if (!m_wxwindow
) return 0;
2047 if (orient
== wxHORIZONTAL
)
2048 return (int)(m_hAdjust
->upper
+0.5);
2050 return (int)(m_vAdjust
->upper
+0.5);
2053 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
2055 if (!m_wxwindow
) return;
2057 bool refresh
= FALSE
;
2059 if ((m_drawingOffsetX
== 0) && (m_drawingOffsetY
== 0))
2061 m_drawingOffsetX
= -16000;
2062 m_drawingOffsetY
= -16000;
2067 m_drawingOffsetX
+= dx
;
2068 m_drawingOffsetY
+= dy
;
2071 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
2073 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow
), m_drawingOffsetX
, m_drawingOffsetY
);
2075 if (refresh
) Refresh();
2078 The code here is very nifty, but it doesn't work with
2079 overlapping windows...
2083 GetClientSize( &cw, &ch );
2085 int w = cw - abs(dx);
2086 int h = ch - abs(dy);
2087 if ((h < 0) || (w < 0))
2094 if (dx < 0) s_x = -dx;
2095 if (dy < 0) s_y = -dy;
2098 if (dx > 0) d_x = dx;
2099 if (dy > 0) d_y = dy;
2100 gdk_window_copy_area( m_wxwindow->window, m_wxwindow->style->fg_gc[0], d_x, d_y,
2101 m_wxwindow->window, s_x, s_y, w, h );
2104 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
2105 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
2106 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
2107 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
2109 Refresh( TRUE, &rect );
2113 void wxWindow::GetDrawingOffset( long *x
, long *y
)
2115 if (x
) *x
= m_drawingOffsetX
;
2116 if (y
) *y
= m_drawingOffsetY
;
2119 //-------------------------------------------------------------------------------------
2121 //-------------------------------------------------------------------------------------
2123 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
2125 return m_constraints
;
2128 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
2132 UnsetConstraints(m_constraints
);
2133 delete m_constraints
;
2135 m_constraints
= constraints
;
2138 // Make sure other windows know they're part of a 'meaningful relationship'
2139 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
2140 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2141 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
2142 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2143 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
2144 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2145 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
2146 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2147 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
2148 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2149 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
2150 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2151 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
2152 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2153 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
2154 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2160 void wxWindow::SetAutoLayout( bool autoLayout
)
2162 m_autoLayout
= autoLayout
;
2165 bool wxWindow::GetAutoLayout(void) const
2167 return m_autoLayout
;
2170 wxSizer
*wxWindow::GetSizer(void) const
2172 return m_windowSizer
;
2175 void wxWindow::SetSizerParent( wxWindow
*win
)
2177 m_sizerParent
= win
;
2180 wxWindow
*wxWindow::GetSizerParent(void) const
2182 return m_sizerParent
;
2185 // This removes any dangling pointers to this window
2186 // in other windows' constraintsInvolvedIn lists.
2187 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2191 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2192 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2193 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2194 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2195 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2196 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2197 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2198 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2199 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2200 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2201 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2202 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2203 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2204 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2205 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2206 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2210 // Back-pointer to other windows we're involved with, so if we delete
2211 // this window, we must delete any constraints we're involved with.
2212 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2214 if (!m_constraintsInvolvedIn
)
2215 m_constraintsInvolvedIn
= new wxList
;
2216 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2217 m_constraintsInvolvedIn
->Append(otherWin
);
2220 // REMOVE back-pointer to other windows we're involved with.
2221 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2223 if (m_constraintsInvolvedIn
)
2224 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2227 // Reset any constraints that mention this window
2228 void wxWindow::DeleteRelatedConstraints(void)
2230 if (m_constraintsInvolvedIn
)
2232 wxNode
*node
= m_constraintsInvolvedIn
->First();
2235 wxWindow
*win
= (wxWindow
*)node
->Data();
2236 wxNode
*next
= node
->Next();
2237 wxLayoutConstraints
*constr
= win
->GetConstraints();
2239 // Reset any constraints involving this window
2242 constr
->left
.ResetIfWin((wxWindow
*)this);
2243 constr
->top
.ResetIfWin((wxWindow
*)this);
2244 constr
->right
.ResetIfWin((wxWindow
*)this);
2245 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2246 constr
->width
.ResetIfWin((wxWindow
*)this);
2247 constr
->height
.ResetIfWin((wxWindow
*)this);
2248 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2249 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2254 delete m_constraintsInvolvedIn
;
2255 m_constraintsInvolvedIn
= NULL
;
2259 void wxWindow::SetSizer(wxSizer
*sizer
)
2261 m_windowSizer
= sizer
;
2263 sizer
->SetSizerParent((wxWindow
*)this);
2270 bool wxWindow::Layout(void)
2272 if (GetConstraints())
2275 GetClientSize(&w
, &h
);
2276 GetConstraints()->width
.SetValue(w
);
2277 GetConstraints()->height
.SetValue(h
);
2280 // If top level (one sizer), evaluate the sizer's constraints.
2284 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2285 GetSizer()->LayoutPhase1(&noChanges
);
2286 GetSizer()->LayoutPhase2(&noChanges
);
2287 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2292 // Otherwise, evaluate child constraints
2293 ResetConstraints(); // Mark all constraints as unevaluated
2294 DoPhase(1); // Just one phase need if no sizers involved
2296 SetConstraintSizes(); // Recursively set the real window sizes
2302 // Do a phase of evaluating constraints:
2303 // the default behaviour. wxSizers may do a similar
2304 // thing, but also impose their own 'constraints'
2305 // and order the evaluation differently.
2306 bool wxWindow::LayoutPhase1(int *noChanges
)
2308 wxLayoutConstraints
*constr
= GetConstraints();
2311 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2317 bool wxWindow::LayoutPhase2(int *noChanges
)
2327 // Do a phase of evaluating child constraints
2328 bool wxWindow::DoPhase(int phase
)
2330 int noIterations
= 0;
2331 int maxIterations
= 500;
2335 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2339 wxNode
*node
= GetChildren()->First();
2342 wxWindow
*child
= (wxWindow
*)node
->Data();
2343 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2345 wxLayoutConstraints
*constr
= child
->GetConstraints();
2348 if (succeeded
.Member(child
))
2353 int tempNoChanges
= 0;
2354 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2355 noChanges
+= tempNoChanges
;
2358 succeeded
.Append(child
);
2363 node
= node
->Next();
2370 void wxWindow::ResetConstraints(void)
2372 wxLayoutConstraints
*constr
= GetConstraints();
2375 constr
->left
.SetDone(FALSE
);
2376 constr
->top
.SetDone(FALSE
);
2377 constr
->right
.SetDone(FALSE
);
2378 constr
->bottom
.SetDone(FALSE
);
2379 constr
->width
.SetDone(FALSE
);
2380 constr
->height
.SetDone(FALSE
);
2381 constr
->centreX
.SetDone(FALSE
);
2382 constr
->centreY
.SetDone(FALSE
);
2384 wxNode
*node
= GetChildren()->First();
2387 wxWindow
*win
= (wxWindow
*)node
->Data();
2388 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2389 win
->ResetConstraints();
2390 node
= node
->Next();
2394 // Need to distinguish between setting the 'fake' size for
2395 // windows and sizers, and setting the real values.
2396 void wxWindow::SetConstraintSizes(bool recurse
)
2398 wxLayoutConstraints
*constr
= GetConstraints();
2399 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2400 constr
->width
.GetDone() && constr
->height
.GetDone())
2402 int x
= constr
->left
.GetValue();
2403 int y
= constr
->top
.GetValue();
2404 int w
= constr
->width
.GetValue();
2405 int h
= constr
->height
.GetValue();
2407 // If we don't want to resize this window, just move it...
2408 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2409 (constr
->height
.GetRelationship() != wxAsIs
))
2411 // Calls Layout() recursively. AAAGH. How can we stop that.
2412 // Simply take Layout() out of non-top level OnSizes.
2413 SizerSetSize(x
, y
, w
, h
);
2422 char *windowClass
= this->GetClassInfo()->GetClassName();
2425 if (GetName() == "")
2426 winName
= _("unnamed");
2428 winName
= GetName();
2429 wxDebugMsg(_("Constraint(s) not satisfied for window of type %s, name %s:\n"), (const char *)windowClass
, (const char *)winName
);
2430 if (!constr
->left
.GetDone())
2431 wxDebugMsg(_(" unsatisfied 'left' constraint.\n"));
2432 if (!constr
->right
.GetDone())
2433 wxDebugMsg(_(" unsatisfied 'right' constraint.\n"));
2434 if (!constr
->width
.GetDone())
2435 wxDebugMsg(_(" unsatisfied 'width' constraint.\n"));
2436 if (!constr
->height
.GetDone())
2437 wxDebugMsg(_(" unsatisfied 'height' constraint.\n"));
2438 wxDebugMsg(_("Please check constraints: try adding AsIs() constraints.\n"));
2443 wxNode
*node
= GetChildren()->First();
2446 wxWindow
*win
= (wxWindow
*)node
->Data();
2447 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2448 win
->SetConstraintSizes();
2449 node
= node
->Next();
2454 // This assumes that all sizers are 'on' the same
2455 // window, i.e. the parent of this window.
2456 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2458 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2459 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2463 m_sizerParent
->GetPosition(&xp
, &yp
);
2464 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2469 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2473 TransformSizerToActual(&xx
, &yy
);
2474 SetSize(xx
, yy
, w
, h
);
2477 void wxWindow::SizerMove(int x
, int y
)
2481 TransformSizerToActual(&xx
, &yy
);
2485 // Only set the size/position of the constraint (if any)
2486 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2488 wxLayoutConstraints
*constr
= GetConstraints();
2493 constr
->left
.SetValue(x
);
2494 constr
->left
.SetDone(TRUE
);
2498 constr
->top
.SetValue(y
);
2499 constr
->top
.SetDone(TRUE
);
2503 constr
->width
.SetValue(w
);
2504 constr
->width
.SetDone(TRUE
);
2508 constr
->height
.SetValue(h
);
2509 constr
->height
.SetDone(TRUE
);
2514 void wxWindow::MoveConstraint(int x
, int y
)
2516 wxLayoutConstraints
*constr
= GetConstraints();
2521 constr
->left
.SetValue(x
);
2522 constr
->left
.SetDone(TRUE
);
2526 constr
->top
.SetValue(y
);
2527 constr
->top
.SetDone(TRUE
);
2532 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2534 wxLayoutConstraints
*constr
= GetConstraints();
2537 *w
= constr
->width
.GetValue();
2538 *h
= constr
->height
.GetValue();
2544 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2546 wxLayoutConstraints
*constr
= GetConstraints();
2549 *w
= constr
->width
.GetValue();
2550 *h
= constr
->height
.GetValue();
2553 GetClientSize(w
, h
);
2556 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2558 wxLayoutConstraints
*constr
= GetConstraints();
2561 *x
= constr
->left
.GetValue();
2562 *y
= constr
->top
.GetValue();
2568 bool wxWindow::AcceptsFocus() const
2570 return IsEnabled() && IsShown();
2573 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
) )