1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
17 #include "wx/window.h"
21 #include "wx/layout.h"
23 #include "wx/dialog.h"
24 #include "wx/msgdlg.h"
25 #include "wx/dcclient.h"
28 #include "wx/notebook.h"
29 #include "gdk/gdkkeysyms.h"
31 #include "wx/gtk/win_gtk.h"
32 #include "gdk/gdkprivate.h"
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 extern wxList wxPendingDelete
;
39 extern wxList wxTopLevelWindows
;
40 extern bool g_blockEventsOnDrag
;
42 //-----------------------------------------------------------------------------
43 // GTK callbacks for wxWindows event system
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
47 // expose (of m_wxwindow, not of m_widget)
49 void gtk_window_expose_callback( GtkWidget
*WXUNUSED(widget
), GdkEventExpose
*gdk_event
, wxWindow
*win
)
51 if (!win
->HasVMT()) return;
52 if (g_blockEventsOnDrag
) return;
55 printf( "OnExpose from " );
56 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
57 printf( win->GetClassInfo()->GetClassName() );
60 printf( "x: %d \n", gdk_event->area.x );
61 printf( "y: %d \n", gdk_event->area.y );
62 printf( "w: %d \n", gdk_event->area.width );
63 printf( "h: %d \n", gdk_event->area.height );
66 win
->m_updateRegion
.Union( gdk_event
->area
.x
,
68 gdk_event
->area
.width
,
69 gdk_event
->area
.height
);
71 if (gdk_event
->count
> 0) return;
73 wxPaintEvent
event( win
->GetId() );
74 event
.SetEventObject( win
);
75 win
->ProcessEvent( event
);
77 win
->m_updateRegion
.Clear();
80 //-----------------------------------------------------------------------------
81 // draw (of m_wxwindow, not of m_widget)
83 void gtk_window_draw_callback( GtkWidget
*WXUNUSED(widget
), GdkRectangle
*rect
, wxWindow
*win
)
85 if (!win
->HasVMT()) return;
86 if (g_blockEventsOnDrag
) return;
89 printf( "OnDraw from " );
90 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
91 printf( win->GetClassInfo()->GetClassName() );
94 printf( "x: %d \n", rect->x );
95 printf( "y: %d \n", rect->y );
96 printf( "w: %d \n", rect->width );
97 printf( "h: %d \n", rect->height );
100 win
->m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
102 wxPaintEvent
event( win
->GetId() );
103 event
.SetEventObject( win
);
104 win
->ProcessEvent( event
);
106 win
->m_updateRegion
.Clear();
109 //-----------------------------------------------------------------------------
111 // I don't any longer intercept GTK's internal resize events, except
112 // for frames and from within MDI and tabbed windows (client area
113 // size determined internally by GTK, not wxWin).
116 void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
118 if (!win->HasVMT()) return;
119 if (g_blockEventsOnDrag) return;
123 if ((win->m_x == alloc->x) &&
124 (win->m_y == alloc->y) &&
125 (win->m_width == alloc->width) &&
126 (win->m_height == alloc->height))
131 printf( "OnResize from " );
132 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
133 printf( win->GetClassInfo()->GetClassName() );
136 printf( " Old: X: %d Y: %d ", win->m_x, win->m_y );
137 printf( " W: %d H: %d ", win->m_width, win->m_height );
140 printf( " New: X: %d Y: %d ", alloc->x, alloc->y );
141 printf( " W: %d H: %d ", alloc->width, alloc->height );
144 wxSizeEvent event( wxSize( alloc->width, alloc->height), win->GetId() );
145 event.SetEventObject( win );
146 win->ProcessEvent( event );
150 //-----------------------------------------------------------------------------
153 gint
gtk_window_key_press_callback( GtkWidget
*WXUNUSED(widget
), GdkEventKey
*gdk_event
, wxWindow
*win
)
155 if (!win
->HasVMT()) return FALSE
;
156 if (g_blockEventsOnDrag
) return FALSE
;
159 printf( "OnKeyPress from " );
160 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
161 printf( win->GetClassInfo()->GetClassName() );
166 switch (gdk_event
->keyval
)
168 case GDK_BackSpace
: key_code
= WXK_BACK
; break;
169 case GDK_Tab
: key_code
= WXK_TAB
; break;
170 case GDK_Linefeed
: key_code
= WXK_RETURN
; break;
171 case GDK_Clear
: key_code
= WXK_CLEAR
; break;
172 case GDK_Return
: key_code
= WXK_RETURN
; break;
173 case GDK_Pause
: key_code
= WXK_PAUSE
; break;
174 case GDK_Scroll_Lock
: key_code
= WXK_SCROLL
; break;
175 case GDK_Escape
: key_code
= WXK_ESCAPE
; break;
176 case GDK_Delete
: key_code
= WXK_DELETE
; break;
177 case GDK_Home
: key_code
= WXK_HOME
; break;
178 case GDK_Left
: key_code
= WXK_LEFT
; break;
179 case GDK_Up
: key_code
= WXK_UP
; break;
180 case GDK_Right
: key_code
= WXK_RIGHT
; break;
181 case GDK_Down
: key_code
= WXK_DOWN
; break;
182 case GDK_Prior
: key_code
= WXK_PRIOR
; break;
183 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
184 case GDK_Next
: key_code
= WXK_NEXT
; break;
185 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
186 case GDK_End
: key_code
= WXK_END
; break;
187 case GDK_Begin
: key_code
= WXK_HOME
; break;
188 case GDK_Select
: key_code
= WXK_SELECT
; break;
189 case GDK_Print
: key_code
= WXK_PRINT
; break;
190 case GDK_Execute
: key_code
= WXK_EXECUTE
; break;
191 case GDK_Insert
: key_code
= WXK_INSERT
; break;
192 case GDK_Num_Lock
: key_code
= WXK_NUMLOCK
; break;
193 case GDK_KP_Tab
: key_code
= WXK_TAB
; break;
194 case GDK_KP_Enter
: key_code
= WXK_RETURN
; break;
195 case GDK_KP_Home
: key_code
= WXK_HOME
; break;
196 case GDK_KP_Left
: key_code
= WXK_LEFT
; break;
197 case GDK_KP_Up
: key_code
= WXK_UP
; break;
198 case GDK_KP_Right
: key_code
= WXK_RIGHT
; break;
199 case GDK_KP_Down
: key_code
= WXK_DOWN
; break;
200 case GDK_KP_Prior
: key_code
= WXK_PRIOR
; break;
201 // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
202 case GDK_KP_Next
: key_code
= WXK_NEXT
; break;
203 // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
204 case GDK_KP_End
: key_code
= WXK_END
; break;
205 case GDK_KP_Begin
: key_code
= WXK_HOME
; break;
206 case GDK_KP_Insert
: key_code
= WXK_INSERT
; break;
207 case GDK_KP_Delete
: key_code
= WXK_DELETE
; break;
208 case GDK_KP_Multiply
: key_code
= WXK_MULTIPLY
; break;
209 case GDK_KP_Add
: key_code
= WXK_ADD
; break;
210 case GDK_KP_Separator
: key_code
= WXK_SEPARATOR
; break;
211 case GDK_KP_Subtract
: key_code
= WXK_SUBTRACT
; break;
212 case GDK_KP_Decimal
: key_code
= WXK_DECIMAL
; break;
213 case GDK_KP_Divide
: key_code
= WXK_DIVIDE
; break;
214 case GDK_KP_0
: key_code
= WXK_NUMPAD0
; break;
215 case GDK_KP_1
: key_code
= WXK_NUMPAD1
; break;
216 case GDK_KP_2
: key_code
= WXK_NUMPAD2
; break;
217 case GDK_KP_3
: key_code
= WXK_NUMPAD3
; break;
218 case GDK_KP_4
: key_code
= WXK_NUMPAD4
; break;
219 case GDK_KP_5
: key_code
= WXK_NUMPAD5
; break;
220 case GDK_KP_6
: key_code
= WXK_NUMPAD6
; break;
221 case GDK_KP_7
: key_code
= WXK_NUMPAD7
; break;
222 case GDK_KP_8
: key_code
= WXK_NUMPAD7
; break;
223 case GDK_KP_9
: key_code
= WXK_NUMPAD9
; break;
224 case GDK_F1
: key_code
= WXK_F1
; break;
225 case GDK_F2
: key_code
= WXK_F2
; break;
226 case GDK_F3
: key_code
= WXK_F3
; break;
227 case GDK_F4
: key_code
= WXK_F4
; break;
228 case GDK_F5
: key_code
= WXK_F5
; break;
229 case GDK_F6
: key_code
= WXK_F6
; break;
230 case GDK_F7
: key_code
= WXK_F7
; break;
231 case GDK_F8
: key_code
= WXK_F8
; break;
232 case GDK_F9
: key_code
= WXK_F9
; break;
233 case GDK_F10
: key_code
= WXK_F10
; break;
234 case GDK_F11
: key_code
= WXK_F11
; break;
235 case GDK_F12
: key_code
= WXK_F12
; break;
238 if ((gdk_event
->keyval
>= 0x20) && (gdk_event
->keyval
<= 0xFF))
239 key_code
= gdk_event
->keyval
;
243 if (!key_code
) return FALSE
;
245 wxKeyEvent
event( wxEVT_CHAR
);
246 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
247 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
248 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
249 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
250 event
.m_keyCode
= key_code
;
253 event
.SetEventObject( win
);
254 return win
->ProcessEvent( event
);
257 //-----------------------------------------------------------------------------
260 gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
262 if (widget
->window
!= gdk_event
->window
) return FALSE
;
263 if (g_blockEventsOnDrag
) return FALSE
;
267 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
) && !GTK_WIDGET_HAS_FOCUS (win
->m_wxwindow
) )
269 gtk_widget_grab_focus (win
->m_wxwindow
);
272 printf( "GrabFocus from " );
273 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
274 printf( win->GetClassInfo()->GetClassName() );
281 if (!win
->HasVMT()) return FALSE
;
284 printf( "OnButtonPress from " );
285 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
286 printf( win->GetClassInfo()->GetClassName() );
290 wxEventType event_type
= wxEVT_LEFT_DOWN
;
292 if (gdk_event
->button
== 1)
294 switch (gdk_event
->type
)
296 case GDK_BUTTON_PRESS
: event_type
= wxEVT_LEFT_DOWN
; break;
297 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_LEFT_DCLICK
; break;
301 else if (gdk_event
->button
== 2)
303 switch (gdk_event
->type
)
305 case GDK_BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DOWN
; break;
306 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DCLICK
; break;
310 else if (gdk_event
->button
== 3)
312 switch (gdk_event
->type
)
314 case GDK_BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DOWN
; break;
315 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DCLICK
; break;
320 wxMouseEvent
event( event_type
);
321 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
322 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
323 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
324 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
325 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
326 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
327 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
329 event
.m_x
= (long)gdk_event
->x
;
330 event
.m_y
= (long)gdk_event
->y
;
331 event
.SetEventObject( win
);
333 win
->ProcessEvent( event
);
338 //-----------------------------------------------------------------------------
341 gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
343 if (widget
->window
!= gdk_event
->window
) return TRUE
;
345 if (g_blockEventsOnDrag
) return FALSE
;
347 if (!win
->HasVMT()) return FALSE
;
350 printf( "OnButtonRelease from " );
351 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
352 printf( win->GetClassInfo()->GetClassName() );
356 wxEventType event_type
= wxEVT_NULL
;
358 switch (gdk_event
->button
)
360 case 1: event_type
= wxEVT_LEFT_UP
; break;
361 case 2: event_type
= wxEVT_MIDDLE_UP
; break;
362 case 3: event_type
= wxEVT_RIGHT_UP
; break;
365 wxMouseEvent
event( event_type
);
366 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
367 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
368 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
369 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
370 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
371 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
372 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
373 event
.m_x
= (long)gdk_event
->x
;
374 event
.m_y
= (long)gdk_event
->y
;
375 event
.SetEventObject( win
);
377 return win
->ProcessEvent( event
);
380 //-----------------------------------------------------------------------------
383 gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxWindow
*win
)
385 if (widget
->window
!= gdk_event
->window
) return TRUE
;
387 if (g_blockEventsOnDrag
) return FALSE
;
389 if (!win
->HasVMT()) return FALSE
;
392 printf( "OnMotion from " );
393 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
394 printf( win->GetClassInfo()->GetClassName() );
398 wxMouseEvent
event( wxEVT_MOTION
);
399 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
400 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
401 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
402 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
403 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
404 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
405 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
407 event
.m_x
= (long)gdk_event
->x
;
408 event
.m_y
= (long)gdk_event
->y
;
409 event
.SetEventObject( win
);
411 win
->ProcessEvent( event
);
416 //-----------------------------------------------------------------------------
419 gint
gtk_window_focus_in_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
421 if (g_blockEventsOnDrag
) return FALSE
;
424 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
426 GTK_WIDGET_SET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
428 printf( "SetFocus flag from " );
429 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
430 printf( win->GetClassInfo()->GetClassName() );
436 if (!win
->HasVMT()) return FALSE
;
439 printf( "OnSetFocus from " );
440 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
441 printf( win->GetClassInfo()->GetClassName() );
443 printf( WXSTRINGCAST win->GetLabel() );
447 wxFocusEvent
event( wxEVT_SET_FOCUS
, win
->GetId() );
448 event
.SetEventObject( win
);
449 return win
->ProcessEvent( event
);
452 //-----------------------------------------------------------------------------
455 gint
gtk_window_focus_out_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
457 if (g_blockEventsOnDrag
) return FALSE
;
460 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
461 GTK_WIDGET_UNSET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
464 if (!win
->HasVMT()) return FALSE
;
467 printf( "OnKillFocus from " );
468 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
469 printf( win->GetClassInfo()->GetClassName() );
473 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
474 event
.SetEventObject( win
);
475 return win
->ProcessEvent( event
);
478 //-----------------------------------------------------------------------------
481 void gtk_window_vscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
483 if (g_blockEventsOnDrag
) return;
486 printf( "OnVScroll from " );
487 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
488 printf( win->GetClassInfo()->GetClassName() );
492 if (!win
->HasVMT()) return;
494 float diff
= win
->m_vAdjust
->value
- win
->m_oldVerticalPos
;
495 if (fabs(diff
) < 0.2) return;
498 int i = (int)(win->m_oldVerticalPos+0.5);
499 printf( "Old value: %d.\n", i );
500 i = (int)(win->m_vAdjust->value+0.5);
501 printf( "Sending new value: %d.\n", i );
504 wxEventType command
= wxEVT_NULL
;
506 float line_step
= win
->m_vAdjust
->step_increment
;
507 float page_step
= win
->m_vAdjust
->page_increment
;
509 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
510 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
511 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
512 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
513 else command
= wxEVT_SCROLL_THUMBTRACK
;
515 int value
= (int)(win
->m_vAdjust
->value
+0.5);
517 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
518 event
.SetEventObject( win
);
519 win
->ProcessEvent( event
);
522 //-----------------------------------------------------------------------------
525 void gtk_window_hscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
527 if (g_blockEventsOnDrag
) return;
530 printf( "OnHScroll from " );
531 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
532 printf( win->GetClassInfo()->GetClassName() );
536 if (!win
->HasVMT()) return;
538 float diff
= win
->m_hAdjust
->value
- win
->m_oldHorizontalPos
;
539 if (fabs(diff
) < 0.2) return;
542 int i = (int)(win->m_oldHorizontalPos+0.5);
543 printf( "Old value: %d.\n", i );
544 i = (int)(win->m_hAdjust->value+0.5);
545 printf( "Sending new value: %d.\n", i );
548 wxEventType command
= wxEVT_NULL
;
550 float line_step
= win
->m_hAdjust
->step_increment
;
551 float page_step
= win
->m_hAdjust
->page_increment
;
553 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
554 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
555 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
556 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
557 else command
= wxEVT_SCROLL_THUMBTRACK
;
559 int value
= (int)(win
->m_hAdjust
->value
+0.5);
561 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
562 event
.SetEventObject( win
);
563 win
->ProcessEvent( event
);
566 //-----------------------------------------------------------------------------
567 // vertical scroll change
569 void gtk_window_vscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
571 if (g_blockEventsOnDrag
) return;
574 printf( "OnVScroll change from " );
575 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
576 printf( win->GetClassInfo()->GetClassName() );
580 if (!win
->HasVMT()) return;
582 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
583 int value
= (int)(win
->m_vAdjust
->value
+0.5);
585 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
586 event
.SetEventObject( win
);
587 win
->ProcessEvent( event
);
590 //-----------------------------------------------------------------------------
591 // horizontal scroll change
593 void gtk_window_hscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
595 if (g_blockEventsOnDrag
) return;
598 printf( "OnHScroll change from " );
599 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
600 printf( win->GetClassInfo()->GetClassName() );
604 if (!win
->HasVMT()) return;
606 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
607 int value
= (int)(win
->m_hAdjust
->value
+0.5);
609 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
610 event
.SetEventObject( win
);
611 win
->ProcessEvent( event
);
614 //-----------------------------------------------------------------------------
617 void gtk_window_drop_callback( GtkWidget
*widget
, GdkEvent
*event
, wxWindow
*win
)
619 printf( "OnDrop.\n" );
621 if (win
->GetDropTarget())
625 gdk_window_get_pointer( widget
->window
, &x
, &y
, NULL
);
626 win
->GetDropTarget()->Drop( event
, x
, y
);
630 g_free (event->dropdataavailable.data);
631 g_free (event->dropdataavailable.data_type);
635 //-----------------------------------------------------------------------------
638 bool gtk_window_destroy_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
640 printf( "OnDestroy from " );
641 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
642 printf( win
->GetClassInfo()->GetClassName() );
644 printf( "Goodbye.\n" );
645 printf( " Robert Roebling.\n" );
650 //-----------------------------------------------------------------------------
653 bool gtk_window_enter_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
655 if (widget
->window
!= gdk_event
->window
) return TRUE
;
657 if (g_blockEventsOnDrag
) return FALSE
;
660 gdk_window_set_cursor( widget
->window
, win
->m_cursor
->GetCursor() );
662 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
663 event
.SetEventObject( win
);
664 return win
->ProcessEvent( event
);
667 //-----------------------------------------------------------------------------
670 bool gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
672 if (widget
->window
!= gdk_event
->window
) return TRUE
;
674 if (g_blockEventsOnDrag
) return FALSE
;
677 gdk_window_set_cursor( widget
->window
, wxSTANDARD_CURSOR
->GetCursor() );
679 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
680 event
.SetEventObject( win
);
681 return win
->ProcessEvent( event
);
684 //-----------------------------------------------------------------------------
685 // wxWindow implementation
686 //-----------------------------------------------------------------------------
688 IMPLEMENT_DYNAMIC_CLASS(wxWindow
,wxEvtHandler
)
690 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
691 // EVT_CHAR(wxWindow::OnChar)
692 EVT_SIZE(wxWindow::OnSize
)
693 // EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
694 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
695 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
696 // EVT_IDLE(wxWindow::OnIdle)
704 m_children
.DeleteContents( FALSE
);
710 m_eventHandler
= this;
711 m_windowValidator
= NULL
;
713 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
714 m_font
= *wxSWISS_FONT
;
716 m_windowName
= "noname";
717 m_constraints
= NULL
;
718 m_constraintsInvolvedIn
= NULL
;
719 m_windowSizer
= NULL
;
720 m_sizerParent
= NULL
;
721 m_autoLayout
= FALSE
;
725 m_hasScrolling
= FALSE
;
728 m_oldHorizontalPos
= 0.0;
729 m_oldVerticalPos
= 0.0;
732 m_drawingOffsetX
= 0;
733 m_drawingOffsetY
= 0;
734 m_pDropTarget
= NULL
;
738 wxWindow::wxWindow( wxWindow
*parent
, wxWindowID id
,
739 const wxPoint
&pos
, const wxSize
&size
,
740 long style
, const wxString
&name
)
742 Create( parent
, id
, pos
, size
, style
, name
);
745 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
746 const wxPoint
&pos
, const wxSize
&size
,
747 long style
, const wxString
&name
)
753 PreCreation( parent
, id
, pos
, size
, style
, name
);
755 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
756 m_hasScrolling
= TRUE
;
758 GtkScrolledWindow
*s_window
;
759 s_window
= GTK_SCROLLED_WINDOW(m_widget
);
761 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
762 scroll_class
->scrollbar_spacing
= 0;
764 gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
766 m_oldHorizontalPos
= 0.0;
767 m_oldVerticalPos
= 0.0;
769 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) );
770 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) );
772 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "value_changed",
773 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
774 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "value_changed",
775 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
777 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "changed",
778 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
779 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "changed",
780 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
782 GtkViewport
*viewport
;
783 viewport
= GTK_VIEWPORT(s_window
->viewport
);
785 if (m_windowStyle
& wxRAISED_BORDER
)
787 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
789 else if (m_windowStyle
& wxSUNKEN_BORDER
)
791 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
795 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
798 m_wxwindow
= gtk_myfixed_new();
800 if (m_windowStyle
& wxTAB_TRAVERSAL
== wxTAB_TRAVERSAL
)
801 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
803 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
805 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
807 // shut the viewport up
808 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
809 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
811 // I _really_ don't want scrollbars in the beginning
812 m_vAdjust
->lower
= 0.0;
813 m_vAdjust
->upper
= 1.0;
814 m_vAdjust
->value
= 0.0;
815 m_vAdjust
->step_increment
= 1.0;
816 m_vAdjust
->page_increment
= 1.0;
817 m_vAdjust
->page_size
= 5.0;
818 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
819 m_hAdjust
->lower
= 0.0;
820 m_hAdjust
->upper
= 1.0;
821 m_hAdjust
->value
= 0.0;
822 m_hAdjust
->step_increment
= 1.0;
823 m_hAdjust
->page_increment
= 1.0;
824 m_hAdjust
->page_size
= 5.0;
825 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
827 gtk_widget_show( m_wxwindow
);
836 wxWindow::~wxWindow(void)
840 if (m_pDropTarget
) delete m_pDropTarget
;
842 if (m_parent
) m_parent
->RemoveChild( this );
843 if (m_widget
) Show( FALSE
);
847 if (m_wxwindow
) gtk_widget_destroy( m_wxwindow
);
849 if (m_widget
) gtk_widget_destroy( m_widget
);
853 DeleteRelatedConstraints();
856 // This removes any dangling pointers to this window
857 // in other windows' constraintsInvolvedIn lists.
858 UnsetConstraints(m_constraints
);
859 delete m_constraints
;
860 m_constraints
= NULL
;
864 delete m_windowSizer
;
865 m_windowSizer
= NULL
;
867 // If this is a child of a sizer, remove self from parent
869 m_sizerParent
->RemoveChild((wxWindow
*)this);
871 // Just in case the window has been Closed, but
872 // we're then deleting immediately: don't leave
873 // dangling pointers.
874 wxPendingDelete
.DeleteObject(this);
876 // Just in case we've loaded a top-level window via
877 // wxWindow::LoadNativeDialog but we weren't a dialog
879 wxTopLevelWindows
.DeleteObject(this);
883 void wxWindow::PreCreation( wxWindow
*parent
, wxWindowID id
,
884 const wxPoint
&pos
, const wxSize
&size
,
885 long style
, const wxString
&name
)
887 if (m_needParent
&& (parent
== NULL
))
888 wxFatalError( "Need complete parent.", name
);
893 m_children
.DeleteContents( FALSE
);
897 if (m_width
== -1) m_width
= 20;
899 if (m_height
== -1) m_height
= 20;
901 m_eventHandler
= this;
902 m_windowValidator
= NULL
;
905 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
906 m_font
= *wxSWISS_FONT
;
907 m_backgroundColour
= wxWHITE
;
908 m_foregroundColour
= wxBLACK
;
909 m_windowStyle
= style
;
911 m_constraints
= NULL
;
912 m_constraintsInvolvedIn
= NULL
;
913 m_windowSizer
= NULL
;
914 m_sizerParent
= NULL
;
915 m_autoLayout
= FALSE
;
916 m_drawingOffsetX
= 0;
917 m_drawingOffsetY
= 0;
918 m_pDropTarget
= NULL
;
922 void wxWindow::PostCreation(void)
924 if (m_parent
) m_parent
->AddChild( this );
926 // GtkStyle *style = m_widget->style;
927 // style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
929 GtkWidget
*connect_widget
= m_widget
;
930 if (m_wxwindow
) connect_widget
= m_wxwindow
;
932 gtk_object_set_data (GTK_OBJECT (connect_widget
), "MyWxWindow", (gpointer
)this );
936 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
937 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
939 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
940 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
944 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
945 GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this );
948 gtk_signal_connect( GTK_OBJECT(connect_widget
), "key_press_event",
949 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
951 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_press_event",
952 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
954 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_release_event",
955 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
957 gtk_signal_connect( GTK_OBJECT(connect_widget
), "motion_notify_event",
958 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
960 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_in_event",
961 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
963 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_out_event",
964 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
966 gtk_signal_connect( GTK_OBJECT(connect_widget
), "drop_data_available_event",
967 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
969 // Only for cursor handling
971 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter_notify_event",
972 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
974 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave_notify_event",
975 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
979 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "enter_notify_event",
980 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
982 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "leave_notify_event",
983 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
987 // Does destroy ever get called ?
989 gtk_signal_connect( GTK_OBJECT(m_widget), "destroy_event",
990 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
994 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "destroy_event",
995 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
999 if (m_widget
&& m_parent
) gtk_widget_realize( m_widget
);
1000 if (m_wxwindow
) gtk_widget_realize( m_wxwindow
);
1002 SetCursor( wxSTANDARD_CURSOR
);
1007 bool wxWindow::HasVMT(void)
1012 bool wxWindow::Close( bool force
)
1014 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1015 event
.SetEventObject(this);
1016 event
.SetForce(force
);
1018 return GetEventHandler()->ProcessEvent(event
);
1021 bool wxWindow::Destroy(void)
1028 bool wxWindow::DestroyChildren(void)
1033 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
)
1036 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
)
1039 if (GetChildren()->Member(child
)) delete node
;
1046 void wxWindow::PrepareDC( wxDC
&WXUNUSED(dc
) )
1048 // are we to set fonts here ?
1051 void wxWindow::ImplementSetSize(void)
1053 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1056 void wxWindow::ImplementSetPosition(void)
1060 if (IsKindOf(CLASSINFO(wxFrame
)) ||
1061 IsKindOf(CLASSINFO(wxDialog
)))
1063 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1067 printf( "wxWindow::SetSize error.\n" );
1072 if ((m_parent
) && (m_parent
->m_wxwindow
))
1073 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1075 // Don't do anything for children of wxNotebook and wxMDIChildFrame
1078 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1080 if (m_resizing
) return; // I don't like recursions
1088 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1090 if (newX
== -1) newX
= m_x
;
1091 if (newY
== -1) newY
= m_y
;
1092 if (newW
== -1) newW
= m_width
;
1093 if (newH
== -1) newH
= m_height
;
1096 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1098 if (newW
== -1) newW
= 80;
1101 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1103 if (newH
== -1) newH
= 26;
1106 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1110 ImplementSetPosition();
1112 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1120 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1121 event
.SetEventObject( this );
1122 ProcessEvent( event
);
1127 void wxWindow::SetSize( int width
, int height
)
1129 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1132 void wxWindow::Move( int x
, int y
)
1134 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1137 void wxWindow::GetSize( int *width
, int *height
) const
1139 if (width
) (*width
) = m_width
;
1140 if (height
) (*height
) = m_height
;
1143 void wxWindow::SetClientSize( int width
, int height
)
1147 SetSize( width
, height
);
1154 if (!m_hasScrolling
)
1157 do we have sunken dialogs ?
1159 GtkStyleClass *window_class = m_wxwindow->style->klass;
1161 dw += 2 * window_class->xthickness;
1162 dh += 2 * window_class->ythickness;
1167 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1168 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1170 GtkWidget
*viewport
= scroll_window
->viewport
;
1171 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1173 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1174 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1176 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1177 (m_windowStyle
& wxSUNKEN_BORDER
)
1180 dw
+= 2 * viewport_class
->xthickness
;
1181 dh
+= 2 * viewport_class
->ythickness
;
1184 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1186 dw
+= vscrollbar
->allocation
.width
;
1187 dw
+= scroll_class
->scrollbar_spacing
;
1190 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1192 dh
+= hscrollbar
->allocation
.height
;
1193 dw
+= scroll_class
->scrollbar_spacing
;
1197 SetSize( width
+dw
, height
+dh
);
1201 void wxWindow::GetClientSize( int *width
, int *height
) const
1205 if (width
) (*width
) = m_width
;
1206 if (height
) (*height
) = m_height
;
1213 if (!m_hasScrolling
)
1216 do we have sunken dialogs ?
1218 GtkStyleClass *window_class = m_wxwindow->style->klass;
1220 dw += 2 * window_class->xthickness;
1221 dh += 2 * window_class->ythickness;
1226 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1227 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1229 GtkWidget
*viewport
= scroll_window
->viewport
;
1230 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1232 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1233 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1235 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1236 (m_windowStyle
& wxSUNKEN_BORDER
)
1239 dw
+= 2 * viewport_class
->xthickness
;
1240 dh
+= 2 * viewport_class
->ythickness
;
1243 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1245 // dw += vscrollbar->allocation.width;
1246 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1247 dw
+= scroll_class
->scrollbar_spacing
;
1250 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1252 // dh += hscrollbar->allocation.height;
1254 dh
+= scroll_class
->scrollbar_spacing
;
1258 if (width
) (*width
) = m_width
- dw
;
1259 if (height
) (*height
) = m_height
- dh
;
1263 void wxWindow::GetPosition( int *x
, int *y
) const
1269 void wxWindow::ClientToScreen( int *x
, int *y
)
1271 // Does this look simple ?
1273 GdkWindow
*source
= NULL
;
1275 source
= m_wxwindow
->window
;
1277 source
= m_widget
->window
;
1281 gdk_window_get_origin( source
, &org_x
, &org_y
);
1285 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1287 org_x
+= m_widget
->allocation
.x
;
1288 org_y
+= m_widget
->allocation
.y
;
1296 void wxWindow::ScreenToClient( int *x
, int *y
)
1298 GdkWindow
*source
= NULL
;
1300 source
= m_wxwindow
->window
;
1302 source
= m_widget
->window
;
1306 gdk_window_get_origin( source
, &org_x
, &org_y
);
1310 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1312 org_x
+= m_widget
->allocation
.x
;
1313 org_y
+= m_widget
->allocation
.y
;
1321 void wxWindow::Centre( int direction
)
1325 GetPosition( &x
, &y
);
1326 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1328 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) x
= (gdk_screen_width () - m_width
) / 2;
1329 if (direction
& wxVERTICAL
== wxVERTICAL
) y
= (gdk_screen_height () - m_height
) / 2;
1330 gtk_widget_set_uposition( m_widget
, x
, y
);
1338 m_parent
->GetSize( &p_w
, &p_h
);
1339 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) x
= (p_w
- m_width
) / 2;
1340 if (direction
& wxVERTICAL
== wxVERTICAL
) y
= (p_h
- m_height
) / 2;
1341 gtk_widget_set_uposition( m_widget
, x
, y
);
1346 void wxWindow::Fit(void)
1350 wxNode
*node
= GetChildren()->First();
1353 wxWindow
*win
= (wxWindow
*)node
->Data();
1355 win
->GetPosition(&wx
, &wy
);
1356 win
->GetSize(&ww
, &wh
);
1357 if ( wx
+ ww
> maxX
)
1359 if ( wy
+ wh
> maxY
)
1362 node
= node
->Next();
1364 SetClientSize(maxX
+ 5, maxY
+ 5);
1367 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1369 //if (GetAutoLayout()) Layout();
1372 bool wxWindow::Show( bool show
)
1375 gtk_widget_show( m_widget
);
1377 gtk_widget_hide( m_widget
);
1382 void wxWindow::Enable( bool enable
)
1384 m_isEnabled
= enable
;
1385 gtk_widget_set_sensitive( m_widget
, enable
);
1386 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1389 void wxWindow::MakeModal( bool modal
)
1392 // Disable all other windows
1393 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1395 wxNode
*node
= wxTopLevelWindows
.First();
1398 wxWindow
*win
= (wxWindow
*)node
->Data();
1400 win
->Enable(!modal
);
1402 node
= node
->Next();
1407 void wxWindow::SetFocus(void)
1409 GtkWidget
*connect_widget
= m_widget
;
1410 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1413 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1415 gtk_widget_grab_focus (connect_widget
);
1420 bool wxWindow::OnClose(void)
1422 printf( "OnClose event.\n" );
1426 void wxWindow::AddChild( wxWindow
*child
)
1428 // Addchild is (often) called before the program
1429 // has left the parents constructor so that no
1430 // virtual tables work yet. The approach below
1431 // practically imitates virtual tables, i.e. it
1432 // implements a different AddChild() behaviour
1433 // for wxFrame, wxDialog, wxWindow and
1434 // wxMDIParentFrame.
1436 if (IsKindOf(CLASSINFO(wxMDIParentFrame
)))
1438 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1440 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1443 client
->AddChild( child
);
1449 // wxNotebooks are very special, so they have their own AddChild
1451 if (IsKindOf(CLASSINFO(wxNotebook
)))
1453 wxNotebook
*tab
= (wxNotebook
*)this;
1454 tab
->AddChild( child
);
1458 m_children
.Append( child
);
1459 if (child
->IsKindOf(CLASSINFO(wxFrame
)) || child
->IsKindOf(CLASSINFO(wxDialog
)))
1461 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1462 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1467 gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
, child
->m_x
, child
->m_y
);
1469 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1472 wxList
*wxWindow::GetChildren(void)
1474 return (&m_children
);
1477 void wxWindow::RemoveChild( wxWindow
*child
)
1480 GetChildren()->DeleteObject( child
);
1481 child
->m_parent
= NULL
;
1484 void wxWindow::SetReturnCode( int retCode
)
1486 m_retCode
= retCode
;
1489 int wxWindow::GetReturnCode(void)
1494 wxWindow
*wxWindow::GetParent(void)
1499 wxEvtHandler
*wxWindow::GetEventHandler(void)
1501 return m_eventHandler
;
1504 void wxWindow::SetEventhandler( wxEvtHandler
*handler
)
1506 m_eventHandler
= handler
;
1509 wxValidator
*wxWindow::GetValidator(void)
1511 return m_windowValidator
;
1514 void wxWindow::SetValidator( wxValidator
*validator
)
1516 m_windowValidator
= validator
;
1519 bool wxWindow::IsBeingDeleted(void)
1524 void wxWindow::SetId( wxWindowID id
)
1529 wxWindowID
wxWindow::GetId(void)
1534 void wxWindow::SetCursor( const wxCursor
&cursor
)
1536 if (*m_cursor
== cursor
) return;
1537 (*m_cursor
) = cursor
;
1538 if (m_widget
->window
)
1539 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1540 if (m_wxwindow
&& m_wxwindow
->window
)
1541 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1544 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1546 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1549 gdk_window_clear_area( m_wxwindow
->window
,
1561 wxClientDC
dc(this);
1565 dc
.GetInternalDeviceOrigin( &x
, &y
);
1569 GetClientSize( &w
, &h
);
1571 GdkRectangle gdk_rect
;
1575 gdk_rect
.height
= h
;
1576 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1581 GdkRectangle gdk_rect
;
1582 gdk_rect
.x
= rect
->x
;
1583 gdk_rect
.y
= rect
->y
;
1584 gdk_rect
.width
= rect
->width
;
1585 gdk_rect
.height
= rect
->height
;
1587 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1589 gtk_widget_draw( m_widget
, &gdk_rect
);
1593 bool wxWindow::IsExposed( long x
, long y
)
1595 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1598 bool wxWindow::IsExposed( long x
, long y
, long width
, long height
)
1600 return (m_updateRegion
.Contains( x
, y
, width
, height
) != wxOutRegion
);
1603 void wxWindow::Clear(void)
1605 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1608 wxColour
wxWindow::GetBackgroundColour(void) const
1610 return m_backgroundColour
;
1613 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1615 m_backgroundColour
= colour
;
1618 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1619 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1620 gdk_window_clear( m_wxwindow
->window
);
1625 bool wxWindow::Validate(void)
1627 wxNode
*node
= GetChildren()->First();
1630 wxWindow
*child
= (wxWindow
*)node
->Data();
1631 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1633 node
= node
->Next();
1638 bool wxWindow::TransferDataToWindow(void)
1640 wxNode
*node
= GetChildren()->First();
1643 wxWindow
*child
= (wxWindow
*)node
->Data();
1644 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1645 !child
->GetValidator()->TransferToWindow() )
1647 wxMessageBox( "Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1650 node
= node
->Next();
1655 bool wxWindow::TransferDataFromWindow(void)
1657 wxNode
*node
= GetChildren()->First();
1660 wxWindow
*child
= (wxWindow
*)node
->Data();
1661 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1663 node
= node
->Next();
1668 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1670 TransferDataToWindow();
1673 void wxWindow::InitDialog(void)
1675 wxInitDialogEvent
event(GetId());
1676 event
.SetEventObject( this );
1677 GetEventHandler()->ProcessEvent(event
);
1680 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1682 GtkWidget
*connect_widget
= m_widget
;
1683 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1686 m_pDropTarget
->UnregisterWidget( connect_widget
);
1687 delete m_pDropTarget
;
1689 m_pDropTarget
= dropTarget
;
1692 m_pDropTarget
->RegisterWidget( connect_widget
);
1696 wxDropTarget
*wxWindow::GetDropTarget() const
1698 return m_pDropTarget
;
1701 void wxWindow::SetFont( const wxFont
&font
)
1706 copy old style values to new one
1707 set font in new style
1708 -> takes to many resources
1710 GtkStyle *style = gtk_style_new();
1715 wxFont
*wxWindow::GetFont(void)
1720 void wxWindow::SetWindowStyleFlag( long flag
)
1722 m_windowStyle
= flag
;
1725 long wxWindow::GetWindowStyleFlag(void) const
1727 return m_windowStyle
;
1730 void wxWindow::CaptureMouse(void)
1732 GtkWidget
*connect_widget
= m_widget
;
1733 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1734 gtk_grab_add( connect_widget
);
1735 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1737 (GDK_BUTTON_PRESS_MASK
|
1738 GDK_BUTTON_RELEASE_MASK
|
1739 GDK_POINTER_MOTION_MASK
),
1740 NULL
, NULL
, GDK_CURRENT_TIME
);
1743 void wxWindow::ReleaseMouse(void)
1745 GtkWidget
*connect_widget
= m_widget
;
1746 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1747 gtk_grab_remove( connect_widget
);
1748 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1751 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1755 wxString
wxWindow::GetTitle(void) const
1757 return (wxString
&)m_windowName
;
1760 wxString
wxWindow::GetLabel(void) const
1765 void wxWindow::SetName( const wxString
&name
)
1767 m_windowName
= name
;
1770 wxString
wxWindow::GetName(void) const
1772 return (wxString
&)m_windowName
;
1775 bool wxWindow::IsShown(void) const
1780 bool wxWindow::IsRetained(void)
1785 wxWindow
*wxWindow::FindWindow( long id
)
1787 if (id
== m_windowId
) return this;
1788 wxNode
*node
= m_children
.First();
1791 wxWindow
*child
= (wxWindow
*)node
->Data();
1792 wxWindow
*res
= child
->FindWindow( id
);
1793 if (res
) return res
;
1794 node
= node
->Next();
1799 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1801 if (name
== m_windowName
) return this;
1802 wxNode
*node
= m_children
.First();
1805 wxWindow
*child
= (wxWindow
*)node
->Data();
1806 wxWindow
*res
= child
->FindWindow( name
);
1807 if (res
) return res
;
1808 node
= node
->Next();
1813 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1814 int range
, bool WXUNUSED(refresh
) )
1816 if (!m_wxwindow
) return;
1818 if (orient
== wxHORIZONTAL
)
1820 float fpos
= (float)pos
;
1821 m_oldHorizontalPos
= fpos
;
1822 float frange
= (float)range
;
1823 float fthumb
= (float)thumbVisible
;
1825 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1826 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1827 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1830 m_hAdjust
->lower
= 0.0;
1831 m_hAdjust
->upper
= frange
;
1832 m_hAdjust
->value
= fpos
;
1833 m_hAdjust
->step_increment
= 1.0;
1834 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1835 m_hAdjust
->page_size
= fthumb
;
1839 float fpos
= (float)pos
;
1840 m_oldVerticalPos
= fpos
;
1841 float frange
= (float)range
;
1842 float fthumb
= (float)thumbVisible
;
1844 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1845 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1846 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1849 m_vAdjust
->lower
= 0.0;
1850 m_vAdjust
->upper
= frange
;
1851 m_vAdjust
->value
= fpos
;
1852 m_vAdjust
->step_increment
= 1.0;
1853 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1854 m_vAdjust
->page_size
= fthumb
;
1857 if (m_wxwindow
->window
)
1859 if (orient
== wxHORIZONTAL
)
1860 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
1862 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
1864 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1868 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
1870 if (!m_wxwindow
) return;
1872 if (orient
== wxHORIZONTAL
)
1874 float fpos
= (float)pos
;
1875 m_oldHorizontalPos
= fpos
;
1877 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
1878 m_hAdjust
->value
= fpos
;
1882 float fpos
= (float)pos
;
1883 m_oldVerticalPos
= fpos
;
1884 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
1885 m_vAdjust
->value
= fpos
;
1888 if (m_wxwindow
->window
)
1890 if (orient
== wxHORIZONTAL
)
1891 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
1893 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
1897 int wxWindow::GetScrollThumb( int orient
) const
1899 if (!m_wxwindow
) return 0;
1901 if (orient
== wxHORIZONTAL
)
1902 return (int)(m_hAdjust
->page_size
+0.5);
1904 return (int)(m_vAdjust
->page_size
+0.5);
1907 int wxWindow::GetScrollPos( int orient
) const
1909 if (!m_wxwindow
) return 0;
1911 if (orient
== wxHORIZONTAL
)
1912 return (int)(m_hAdjust
->value
+0.5);
1914 return (int)(m_vAdjust
->value
+0.5);
1917 int wxWindow::GetScrollRange( int orient
) const
1919 if (!m_wxwindow
) return 0;
1921 if (orient
== wxHORIZONTAL
)
1922 return (int)(m_hAdjust
->upper
+0.5);
1924 return (int)(m_vAdjust
->upper
+0.5);
1927 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
1929 if (!m_wxwindow
) return;
1931 m_drawingOffsetX
+= dx
;
1932 m_drawingOffsetY
+= dy
;
1934 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
1936 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow
), m_drawingOffsetX
, m_drawingOffsetY
);
1939 The code here is very nifty, but it doesn't work with
1940 overlapping windows...
1944 GetClientSize( &cw, &ch );
1946 int w = cw - abs(dx);
1947 int h = ch - abs(dy);
1948 if ((h < 0) || (w < 0))
1955 if (dx < 0) s_x = -dx;
1956 if (dy < 0) s_y = -dy;
1959 if (dx > 0) d_x = dx;
1960 if (dy > 0) d_y = dy;
1961 gdk_window_copy_area( m_wxwindow->window, m_wxwindow->style->fg_gc[0], d_x, d_y,
1962 m_wxwindow->window, s_x, s_y, w, h );
1965 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
1966 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
1967 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
1968 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
1970 Refresh( TRUE, &rect );
1974 void wxWindow::GetDrawingOffset( long *x
, long *y
)
1976 if (x
) *x
= m_drawingOffsetX
;
1977 if (y
) *y
= m_drawingOffsetY
;
1980 //-------------------------------------------------------------------------------------
1982 //-------------------------------------------------------------------------------------
1984 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
1986 return m_constraints
;
1989 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
1993 UnsetConstraints(m_constraints
);
1994 delete m_constraints
;
1996 m_constraints
= constraints
;
1999 // Make sure other windows know they're part of a 'meaningful relationship'
2000 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
2001 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2002 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
2003 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2004 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
2005 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2006 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
2007 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2008 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
2009 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2010 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
2011 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2012 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
2013 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2014 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
2015 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2021 void wxWindow::SetAutoLayout( bool autoLayout
)
2023 m_autoLayout
= autoLayout
;
2026 bool wxWindow::GetAutoLayout(void) const
2028 return m_autoLayout
;
2031 wxSizer
*wxWindow::GetSizer(void) const
2033 return m_windowSizer
;
2036 void wxWindow::SetSizerParent( wxWindow
*win
)
2038 m_sizerParent
= win
;
2041 wxWindow
*wxWindow::GetSizerParent(void) const
2043 return m_sizerParent
;
2046 // This removes any dangling pointers to this window
2047 // in other windows' constraintsInvolvedIn lists.
2048 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2052 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2053 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2054 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2055 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2056 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2057 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2058 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2059 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2060 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2061 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2062 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2063 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2064 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2065 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2066 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2067 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2071 // Back-pointer to other windows we're involved with, so if we delete
2072 // this window, we must delete any constraints we're involved with.
2073 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2075 if (!m_constraintsInvolvedIn
)
2076 m_constraintsInvolvedIn
= new wxList
;
2077 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2078 m_constraintsInvolvedIn
->Append(otherWin
);
2081 // REMOVE back-pointer to other windows we're involved with.
2082 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2084 if (m_constraintsInvolvedIn
)
2085 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2088 // Reset any constraints that mention this window
2089 void wxWindow::DeleteRelatedConstraints(void)
2091 if (m_constraintsInvolvedIn
)
2093 wxNode
*node
= m_constraintsInvolvedIn
->First();
2096 wxWindow
*win
= (wxWindow
*)node
->Data();
2097 wxNode
*next
= node
->Next();
2098 wxLayoutConstraints
*constr
= win
->GetConstraints();
2100 // Reset any constraints involving this window
2103 constr
->left
.ResetIfWin((wxWindow
*)this);
2104 constr
->top
.ResetIfWin((wxWindow
*)this);
2105 constr
->right
.ResetIfWin((wxWindow
*)this);
2106 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2107 constr
->width
.ResetIfWin((wxWindow
*)this);
2108 constr
->height
.ResetIfWin((wxWindow
*)this);
2109 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2110 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2115 delete m_constraintsInvolvedIn
;
2116 m_constraintsInvolvedIn
= NULL
;
2120 void wxWindow::SetSizer(wxSizer
*sizer
)
2122 m_windowSizer
= sizer
;
2124 sizer
->SetSizerParent((wxWindow
*)this);
2131 bool wxWindow::Layout(void)
2133 if (GetConstraints())
2136 GetClientSize(&w
, &h
);
2137 GetConstraints()->width
.SetValue(w
);
2138 GetConstraints()->height
.SetValue(h
);
2141 // If top level (one sizer), evaluate the sizer's constraints.
2145 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2146 GetSizer()->LayoutPhase1(&noChanges
);
2147 GetSizer()->LayoutPhase2(&noChanges
);
2148 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2153 // Otherwise, evaluate child constraints
2154 ResetConstraints(); // Mark all constraints as unevaluated
2155 DoPhase(1); // Just one phase need if no sizers involved
2157 SetConstraintSizes(); // Recursively set the real window sizes
2163 // Do a phase of evaluating constraints:
2164 // the default behaviour. wxSizers may do a similar
2165 // thing, but also impose their own 'constraints'
2166 // and order the evaluation differently.
2167 bool wxWindow::LayoutPhase1(int *noChanges
)
2169 wxLayoutConstraints
*constr
= GetConstraints();
2172 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2178 bool wxWindow::LayoutPhase2(int *noChanges
)
2188 // Do a phase of evaluating child constraints
2189 bool wxWindow::DoPhase(int phase
)
2191 int noIterations
= 0;
2192 int maxIterations
= 500;
2196 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2200 wxNode
*node
= GetChildren()->First();
2203 wxWindow
*child
= (wxWindow
*)node
->Data();
2204 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2206 wxLayoutConstraints
*constr
= child
->GetConstraints();
2209 if (succeeded
.Member(child
))
2214 int tempNoChanges
= 0;
2215 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2216 noChanges
+= tempNoChanges
;
2219 succeeded
.Append(child
);
2224 node
= node
->Next();
2231 void wxWindow::ResetConstraints(void)
2233 wxLayoutConstraints
*constr
= GetConstraints();
2236 constr
->left
.SetDone(FALSE
);
2237 constr
->top
.SetDone(FALSE
);
2238 constr
->right
.SetDone(FALSE
);
2239 constr
->bottom
.SetDone(FALSE
);
2240 constr
->width
.SetDone(FALSE
);
2241 constr
->height
.SetDone(FALSE
);
2242 constr
->centreX
.SetDone(FALSE
);
2243 constr
->centreY
.SetDone(FALSE
);
2245 wxNode
*node
= GetChildren()->First();
2248 wxWindow
*win
= (wxWindow
*)node
->Data();
2249 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2250 win
->ResetConstraints();
2251 node
= node
->Next();
2255 // Need to distinguish between setting the 'fake' size for
2256 // windows and sizers, and setting the real values.
2257 void wxWindow::SetConstraintSizes(bool recurse
)
2259 wxLayoutConstraints
*constr
= GetConstraints();
2260 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2261 constr
->width
.GetDone() && constr
->height
.GetDone())
2263 int x
= constr
->left
.GetValue();
2264 int y
= constr
->top
.GetValue();
2265 int w
= constr
->width
.GetValue();
2266 int h
= constr
->height
.GetValue();
2268 // If we don't want to resize this window, just move it...
2269 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2270 (constr
->height
.GetRelationship() != wxAsIs
))
2272 // Calls Layout() recursively. AAAGH. How can we stop that.
2273 // Simply take Layout() out of non-top level OnSizes.
2274 SizerSetSize(x
, y
, w
, h
);
2283 char *windowClass
= this->GetClassInfo()->GetClassName();
2286 if (GetName() == "")
2287 winName
= "unnamed";
2289 winName
= GetName();
2290 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
2291 if (!constr
->left
.GetDone())
2292 wxDebugMsg(" unsatisfied 'left' constraint.\n");
2293 if (!constr
->right
.GetDone())
2294 wxDebugMsg(" unsatisfied 'right' constraint.\n");
2295 if (!constr
->width
.GetDone())
2296 wxDebugMsg(" unsatisfied 'width' constraint.\n");
2297 if (!constr
->height
.GetDone())
2298 wxDebugMsg(" unsatisfied 'height' constraint.\n");
2299 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
2304 wxNode
*node
= GetChildren()->First();
2307 wxWindow
*win
= (wxWindow
*)node
->Data();
2308 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2309 win
->SetConstraintSizes();
2310 node
= node
->Next();
2315 // This assumes that all sizers are 'on' the same
2316 // window, i.e. the parent of this window.
2317 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2319 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2320 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2324 m_sizerParent
->GetPosition(&xp
, &yp
);
2325 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2330 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2334 TransformSizerToActual(&xx
, &yy
);
2335 SetSize(xx
, yy
, w
, h
);
2338 void wxWindow::SizerMove(int x
, int y
)
2342 TransformSizerToActual(&xx
, &yy
);
2346 // Only set the size/position of the constraint (if any)
2347 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2349 wxLayoutConstraints
*constr
= GetConstraints();
2354 constr
->left
.SetValue(x
);
2355 constr
->left
.SetDone(TRUE
);
2359 constr
->top
.SetValue(y
);
2360 constr
->top
.SetDone(TRUE
);
2364 constr
->width
.SetValue(w
);
2365 constr
->width
.SetDone(TRUE
);
2369 constr
->height
.SetValue(h
);
2370 constr
->height
.SetDone(TRUE
);
2375 void wxWindow::MoveConstraint(int x
, int y
)
2377 wxLayoutConstraints
*constr
= GetConstraints();
2382 constr
->left
.SetValue(x
);
2383 constr
->left
.SetDone(TRUE
);
2387 constr
->top
.SetValue(y
);
2388 constr
->top
.SetDone(TRUE
);
2393 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2395 wxLayoutConstraints
*constr
= GetConstraints();
2398 *w
= constr
->width
.GetValue();
2399 *h
= constr
->height
.GetValue();
2405 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2407 wxLayoutConstraints
*constr
= GetConstraints();
2410 *w
= constr
->width
.GetValue();
2411 *h
= constr
->height
.GetValue();
2414 GetClientSize(w
, h
);
2417 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2419 wxLayoutConstraints
*constr
= GetConstraints();
2422 *x
= constr
->left
.GetValue();
2423 *y
= constr
->top
.GetValue();
2429 bool wxWindow::AcceptsFocus() const
2431 return IsEnabled() && IsShown();