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 "gdk/gdkkeysyms.h"
34 #include "wx/gtk/win_gtk.h"
35 #include "gdk/gdkprivate.h"
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 extern wxList wxPendingDelete
;
42 extern wxList wxTopLevelWindows
;
43 extern bool g_blockEventsOnDrag
;
45 //-----------------------------------------------------------------------------
46 // "expose_event" (of m_wxwindow, not of m_widget)
47 //-----------------------------------------------------------------------------
49 static void gtk_window_expose_callback( GtkWidget
*WXUNUSED(widget
), GdkEventExpose
*gdk_event
, wxWindow
*win
)
51 if (!win
->HasVMT()) return;
52 if (g_blockEventsOnDrag
) return;
54 win
->m_updateRegion
.Union( gdk_event
->area
.x
,
56 gdk_event
->area
.width
,
57 gdk_event
->area
.height
);
59 if (gdk_event
->count
> 0) return;
61 wxPaintEvent
event( win
->GetId() );
62 event
.SetEventObject( win
);
63 win
->GetEventHandler()->ProcessEvent( event
);
65 win
->m_updateRegion
.Clear();
68 //-----------------------------------------------------------------------------
69 // "draw" (of m_wxwindow, not of m_widget)
70 //-----------------------------------------------------------------------------
72 static void gtk_window_draw_callback( GtkWidget
*WXUNUSED(widget
), GdkRectangle
*rect
, wxWindow
*win
)
74 if (!win
->HasVMT()) return;
75 if (g_blockEventsOnDrag
) return;
77 win
->m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
79 wxPaintEvent
event( win
->GetId() );
80 event
.SetEventObject( win
);
81 win
->GetEventHandler()->ProcessEvent( event
);
83 win
->m_updateRegion
.Clear();
86 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
90 static gint
gtk_window_key_press_callback( GtkWidget
*widget
, GdkEventKey
*gdk_event
, wxWindow
*win
)
92 if (!win
->HasVMT()) return FALSE
;
93 if (g_blockEventsOnDrag
) return FALSE
;
96 printf( "OnKeyPress from " );
97 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
98 printf( win->GetClassInfo()->GetClassName() );
103 switch (gdk_event
->keyval
)
105 case GDK_BackSpace
: key_code
= WXK_BACK
; break;
106 case GDK_Tab
: key_code
= WXK_TAB
; break;
107 case GDK_Linefeed
: key_code
= WXK_RETURN
; break;
108 case GDK_Clear
: key_code
= WXK_CLEAR
; break;
109 case GDK_Return
: key_code
= WXK_RETURN
; break;
110 case GDK_Pause
: key_code
= WXK_PAUSE
; break;
111 case GDK_Scroll_Lock
: key_code
= WXK_SCROLL
; break;
112 case GDK_Escape
: key_code
= WXK_ESCAPE
; break;
113 case GDK_Delete
: key_code
= WXK_DELETE
; break;
114 case GDK_Home
: key_code
= WXK_HOME
; break;
115 case GDK_Left
: key_code
= WXK_LEFT
; break;
116 case GDK_Up
: key_code
= WXK_UP
; break;
117 case GDK_Right
: key_code
= WXK_RIGHT
; break;
118 case GDK_Down
: key_code
= WXK_DOWN
; break;
119 case GDK_Prior
: key_code
= WXK_PRIOR
; break;
120 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
121 case GDK_Next
: key_code
= WXK_NEXT
; break;
122 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
123 case GDK_End
: key_code
= WXK_END
; break;
124 case GDK_Begin
: key_code
= WXK_HOME
; break;
125 case GDK_Select
: key_code
= WXK_SELECT
; break;
126 case GDK_Print
: key_code
= WXK_PRINT
; break;
127 case GDK_Execute
: key_code
= WXK_EXECUTE
; break;
128 case GDK_Insert
: key_code
= WXK_INSERT
; break;
129 case GDK_Num_Lock
: key_code
= WXK_NUMLOCK
; break;
130 case GDK_KP_Tab
: key_code
= WXK_TAB
; break;
131 case GDK_KP_Enter
: key_code
= WXK_RETURN
; break;
132 case GDK_KP_Home
: key_code
= WXK_HOME
; break;
133 case GDK_KP_Left
: key_code
= WXK_LEFT
; break;
134 case GDK_KP_Up
: key_code
= WXK_UP
; break;
135 case GDK_KP_Right
: key_code
= WXK_RIGHT
; break;
136 case GDK_KP_Down
: key_code
= WXK_DOWN
; break;
137 case GDK_KP_Prior
: key_code
= WXK_PRIOR
; break;
138 // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
139 case GDK_KP_Next
: key_code
= WXK_NEXT
; break;
140 // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
141 case GDK_KP_End
: key_code
= WXK_END
; break;
142 case GDK_KP_Begin
: key_code
= WXK_HOME
; break;
143 case GDK_KP_Insert
: key_code
= WXK_INSERT
; break;
144 case GDK_KP_Delete
: key_code
= WXK_DELETE
; break;
145 case GDK_KP_Multiply
: key_code
= WXK_MULTIPLY
; break;
146 case GDK_KP_Add
: key_code
= WXK_ADD
; break;
147 case GDK_KP_Separator
: key_code
= WXK_SEPARATOR
; break;
148 case GDK_KP_Subtract
: key_code
= WXK_SUBTRACT
; break;
149 case GDK_KP_Decimal
: key_code
= WXK_DECIMAL
; break;
150 case GDK_KP_Divide
: key_code
= WXK_DIVIDE
; break;
151 case GDK_KP_0
: key_code
= WXK_NUMPAD0
; break;
152 case GDK_KP_1
: key_code
= WXK_NUMPAD1
; break;
153 case GDK_KP_2
: key_code
= WXK_NUMPAD2
; break;
154 case GDK_KP_3
: key_code
= WXK_NUMPAD3
; break;
155 case GDK_KP_4
: key_code
= WXK_NUMPAD4
; break;
156 case GDK_KP_5
: key_code
= WXK_NUMPAD5
; break;
157 case GDK_KP_6
: key_code
= WXK_NUMPAD6
; break;
158 case GDK_KP_7
: key_code
= WXK_NUMPAD7
; break;
159 case GDK_KP_8
: key_code
= WXK_NUMPAD7
; break;
160 case GDK_KP_9
: key_code
= WXK_NUMPAD9
; break;
161 case GDK_F1
: key_code
= WXK_F1
; break;
162 case GDK_F2
: key_code
= WXK_F2
; break;
163 case GDK_F3
: key_code
= WXK_F3
; break;
164 case GDK_F4
: key_code
= WXK_F4
; break;
165 case GDK_F5
: key_code
= WXK_F5
; break;
166 case GDK_F6
: key_code
= WXK_F6
; break;
167 case GDK_F7
: key_code
= WXK_F7
; break;
168 case GDK_F8
: key_code
= WXK_F8
; break;
169 case GDK_F9
: key_code
= WXK_F9
; break;
170 case GDK_F10
: key_code
= WXK_F10
; break;
171 case GDK_F11
: key_code
= WXK_F11
; break;
172 case GDK_F12
: key_code
= WXK_F12
; break;
175 if ((gdk_event
->keyval
>= 0x20) && (gdk_event
->keyval
<= 0xFF))
176 key_code
= gdk_event
->keyval
;
180 if (!key_code
) return FALSE
;
182 wxKeyEvent
event( wxEVT_CHAR
);
183 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
184 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
185 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
186 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
187 event
.m_keyCode
= key_code
;
190 event
.SetEventObject( win
);
192 bool ret
= win
->GetEventHandler()->ProcessEvent( event
);
196 int command
= win
->GetAcceleratorTable()->GetCommand( event
);
199 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
200 ret
= win
->GetEventHandler()->ProcessEvent( command_event
);
206 if ((gdk_event
->keyval
>= 0x20) && (gdk_event
->keyval
<= 0xFF))
207 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
213 //-----------------------------------------------------------------------------
214 // "button_press_event"
215 //-----------------------------------------------------------------------------
217 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
219 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return TRUE
;
221 if (g_blockEventsOnDrag
) return TRUE
;
225 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
) && !GTK_WIDGET_HAS_FOCUS (win
->m_wxwindow
) )
227 gtk_widget_grab_focus (win
->m_wxwindow
);
230 printf( "GrabFocus from " );
231 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
232 printf( win->GetClassInfo()->GetClassName() );
239 if (!win
->HasVMT()) return TRUE
;
242 printf( "OnButtonPress from " );
243 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
244 printf( win->GetClassInfo()->GetClassName() );
248 wxEventType event_type
= wxEVT_LEFT_DOWN
;
250 if (gdk_event
->button
== 1)
252 switch (gdk_event
->type
)
254 case GDK_BUTTON_PRESS
: event_type
= wxEVT_LEFT_DOWN
; break;
255 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_LEFT_DCLICK
; break;
259 else if (gdk_event
->button
== 2)
261 switch (gdk_event
->type
)
263 case GDK_BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DOWN
; break;
264 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DCLICK
; break;
268 else if (gdk_event
->button
== 3)
270 switch (gdk_event
->type
)
272 case GDK_BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DOWN
; break;
273 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DCLICK
; break;
278 wxMouseEvent
event( event_type
);
279 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
280 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
281 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
282 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
283 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
284 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
285 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
287 event
.m_x
= (long)gdk_event
->x
;
288 event
.m_y
= (long)gdk_event
->y
;
290 // Some control don't have their own X window and thus cannot get
293 wxNode
*node
= win
->GetChildren()->First();
296 wxWindow
*child
= (wxWindow
*)node
->Data();
297 if ((child
->m_x
<= event
.m_x
) &&
298 (child
->m_y
<= event
.m_y
) &&
299 (child
->m_x
+child
->m_width
>= event
.m_x
) &&
300 (child
->m_y
+child
->m_height
>= event
.m_y
))
303 event
.m_x
-= child
->m_x
;
304 event
.m_y
-= child
->m_y
;
310 event
.SetEventObject( win
);
312 if (win
->GetEventHandler()->ProcessEvent( event
))
313 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_press_event" );
318 //-----------------------------------------------------------------------------
320 //-----------------------------------------------------------------------------
322 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
324 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return TRUE
;
325 if (g_blockEventsOnDrag
) return TRUE
;
327 if (!win
->HasVMT()) return TRUE
;
330 printf( "OnButtonRelease from " );
331 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
332 printf( win->GetClassInfo()->GetClassName() );
336 wxEventType event_type
= wxEVT_NULL
;
338 switch (gdk_event
->button
)
340 case 1: event_type
= wxEVT_LEFT_UP
; break;
341 case 2: event_type
= wxEVT_MIDDLE_UP
; break;
342 case 3: event_type
= wxEVT_RIGHT_UP
; break;
345 wxMouseEvent
event( event_type
);
346 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
347 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
348 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
349 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
350 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
351 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
352 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
353 event
.m_x
= (long)gdk_event
->x
;
354 event
.m_y
= (long)gdk_event
->y
;
356 // Some control don't have their own X window and thus cannot get
359 wxNode
*node
= win
->GetChildren()->First();
362 wxWindow
*child
= (wxWindow
*)node
->Data();
363 if ((child
->m_x
<= event
.m_x
) &&
364 (child
->m_y
<= event
.m_y
) &&
365 (child
->m_x
+child
->m_width
>= event
.m_x
) &&
366 (child
->m_y
+child
->m_height
>= event
.m_y
))
369 event
.m_x
-= child
->m_x
;
370 event
.m_y
-= child
->m_y
;
376 event
.SetEventObject( win
);
378 if (win
->GetEventHandler()->ProcessEvent( event
))
379 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_release_event" );
384 //-----------------------------------------------------------------------------
385 // "motion_notify_event"
386 //-----------------------------------------------------------------------------
388 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxWindow
*win
)
390 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return TRUE
;
391 if (g_blockEventsOnDrag
) return TRUE
;
393 if (!win
->HasVMT()) return TRUE
;
396 printf( "OnMotion from " );
397 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
398 printf( win->GetClassInfo()->GetClassName() );
402 wxMouseEvent
event( wxEVT_MOTION
);
403 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
404 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
405 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
406 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
407 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
408 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
409 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
411 event
.m_x
= (long)gdk_event
->x
;
412 event
.m_y
= (long)gdk_event
->y
;
414 // Some control don't have their own X window and thus cannot get
417 wxNode
*node
= win
->GetChildren()->First();
420 wxWindow
*child
= (wxWindow
*)node
->Data();
421 if ((child
->m_x
<= event
.m_x
) &&
422 (child
->m_y
<= event
.m_y
) &&
423 (child
->m_x
+child
->m_width
>= event
.m_x
) &&
424 (child
->m_y
+child
->m_height
>= event
.m_y
))
427 event
.m_x
-= child
->m_x
;
428 event
.m_y
-= child
->m_y
;
434 event
.SetEventObject( win
);
436 if (win
->GetEventHandler()->ProcessEvent( event
))
437 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "motion_notify_event" );
442 //-----------------------------------------------------------------------------
444 //-----------------------------------------------------------------------------
446 static gint
gtk_window_focus_in_callback( GtkWidget
*widget
, GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
448 if (g_blockEventsOnDrag
) return TRUE
;
451 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
453 GTK_WIDGET_SET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
455 printf( "SetFocus flag from " );
456 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
457 printf( win->GetClassInfo()->GetClassName() );
463 if (!win
->HasVMT()) return TRUE
;
466 printf( "OnSetFocus from " );
467 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
468 printf( win->GetClassInfo()->GetClassName() );
470 printf( WXSTRINGCAST win->GetLabel() );
474 wxFocusEvent
event( wxEVT_SET_FOCUS
, win
->GetId() );
475 event
.SetEventObject( win
);
477 if (win
->GetEventHandler()->ProcessEvent( event
))
478 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_in_event" );
483 //-----------------------------------------------------------------------------
485 //-----------------------------------------------------------------------------
487 static gint
gtk_window_focus_out_callback( GtkWidget
*widget
, GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
489 if (g_blockEventsOnDrag
) return TRUE
;
492 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
493 GTK_WIDGET_UNSET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
496 if (!win
->HasVMT()) return TRUE
;
499 printf( "OnKillFocus from " );
500 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
501 printf( win->GetClassInfo()->GetClassName() );
505 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
506 event
.SetEventObject( win
);
508 if (win
->GetEventHandler()->ProcessEvent( event
))
509 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_out_event" );
514 //-----------------------------------------------------------------------------
515 // "value_changed" from m_vAdjust
516 //-----------------------------------------------------------------------------
518 static void gtk_window_vscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
520 if (g_blockEventsOnDrag
) return;
523 printf( "OnVScroll from " );
524 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
525 printf( win->GetClassInfo()->GetClassName() );
529 if (!win
->HasVMT()) return;
531 float diff
= win
->m_vAdjust
->value
- win
->m_oldVerticalPos
;
532 if (fabs(diff
) < 0.2) return;
534 wxEventType command
= wxEVT_NULL
;
536 float line_step
= win
->m_vAdjust
->step_increment
;
537 float page_step
= win
->m_vAdjust
->page_increment
;
539 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
540 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
541 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
542 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
543 else command
= wxEVT_SCROLL_THUMBTRACK
;
545 int value
= (int)(win
->m_vAdjust
->value
+0.5);
547 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
548 event
.SetEventObject( win
);
549 win
->GetEventHandler()->ProcessEvent( event
);
552 //-----------------------------------------------------------------------------
553 // "value_changed" from m_hAdjust
554 //-----------------------------------------------------------------------------
556 static void gtk_window_hscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
558 if (g_blockEventsOnDrag
) return;
561 printf( "OnHScroll from " );
562 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
563 printf( win->GetClassInfo()->GetClassName() );
567 if (!win
->HasVMT()) return;
569 float diff
= win
->m_hAdjust
->value
- win
->m_oldHorizontalPos
;
570 if (fabs(diff
) < 0.2) return;
572 wxEventType command
= wxEVT_NULL
;
574 float line_step
= win
->m_hAdjust
->step_increment
;
575 float page_step
= win
->m_hAdjust
->page_increment
;
577 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
578 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
579 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
580 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
581 else command
= wxEVT_SCROLL_THUMBTRACK
;
583 int value
= (int)(win
->m_hAdjust
->value
+0.5);
585 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
586 event
.SetEventObject( win
);
587 win
->GetEventHandler()->ProcessEvent( event
);
590 //-----------------------------------------------------------------------------
591 // "changed" from m_vAdjust
592 //-----------------------------------------------------------------------------
594 static void gtk_window_vscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
596 if (g_blockEventsOnDrag
) return;
599 printf( "OnVScroll change from " );
600 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
601 printf( win->GetClassInfo()->GetClassName() );
605 if (!win
->HasVMT()) return;
607 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
608 int value
= (int)(win
->m_vAdjust
->value
+0.5);
610 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
611 event
.SetEventObject( win
);
612 win
->GetEventHandler()->ProcessEvent( event
);
615 //-----------------------------------------------------------------------------
616 // "changed" from m_hAdjust
617 //-----------------------------------------------------------------------------
619 static void gtk_window_hscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
621 if (g_blockEventsOnDrag
) return;
624 printf( "OnHScroll change from " );
625 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
626 printf( win->GetClassInfo()->GetClassName() );
630 if (!win
->HasVMT()) return;
632 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
633 int value
= (int)(win
->m_hAdjust
->value
+0.5);
635 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
636 event
.SetEventObject( win
);
637 win
->GetEventHandler()->ProcessEvent( event
);
640 //-----------------------------------------------------------------------------
641 // "drop_data_available_event"
642 //-----------------------------------------------------------------------------
644 static void gtk_window_drop_callback( GtkWidget
*widget
, GdkEvent
*event
, wxWindow
*win
)
646 if (!win
->HasVMT()) return;
648 if (win
->GetDropTarget())
652 gdk_window_get_pointer( widget
->window
, &x
, &y
, (GdkModifierType
*) NULL
);
653 win
->GetDropTarget()->Drop( event
, x
, y
);
657 g_free (event->dropdataavailable.data);
658 g_free (event->dropdataavailable.data_type);
662 //-----------------------------------------------------------------------------
663 // "enter_notify_event"
664 //-----------------------------------------------------------------------------
666 static gint
gtk_window_enter_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
668 if (widget
->window
!= gdk_event
->window
) return TRUE
;
669 if (g_blockEventsOnDrag
) return TRUE
;
670 if (!win
->HasVMT()) return TRUE
;
673 gdk_window_set_cursor( widget
->window
, win
->m_cursor
->GetCursor() );
675 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
676 event
.SetEventObject( win
);
677 return win
->GetEventHandler()->ProcessEvent( event
);
680 //-----------------------------------------------------------------------------
681 // "leave_notify_event"
682 //-----------------------------------------------------------------------------
684 static gint
gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
686 if (widget
->window
!= gdk_event
->window
) return TRUE
;
687 if (!win
->HasVMT()) return TRUE
;
688 if (g_blockEventsOnDrag
) return TRUE
;
691 gdk_window_set_cursor( widget
->window
, wxSTANDARD_CURSOR
->GetCursor() );
693 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
694 event
.SetEventObject( win
);
695 return win
->GetEventHandler()->ProcessEvent( event
);
698 //-----------------------------------------------------------------------------
700 //-----------------------------------------------------------------------------
702 IMPLEMENT_DYNAMIC_CLASS(wxWindow
,wxEvtHandler
)
704 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
705 EVT_SIZE(wxWindow::OnSize
)
706 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
707 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
708 EVT_IDLE(wxWindow::OnIdle
)
713 m_widget
= (GtkWidget
*) NULL
;
714 m_wxwindow
= (GtkWidget
*) NULL
;
715 m_parent
= (wxWindow
*) NULL
;
716 m_children
.DeleteContents( FALSE
);
726 m_eventHandler
= this;
727 m_windowValidator
= (wxValidator
*) NULL
;
729 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
730 m_font
= *wxSWISS_FONT
;
732 m_windowName
= "noname";
733 m_constraints
= (wxLayoutConstraints
*) NULL
;
734 m_constraintsInvolvedIn
= (wxList
*) NULL
;
735 m_windowSizer
= (wxSizer
*) NULL
;
736 m_sizerParent
= (wxWindow
*) NULL
;
737 m_autoLayout
= FALSE
;
741 m_hasScrolling
= FALSE
;
742 m_hAdjust
= (GtkAdjustment
*) NULL
;
743 m_vAdjust
= (GtkAdjustment
*) NULL
;
744 m_oldHorizontalPos
= 0.0;
745 m_oldVerticalPos
= 0.0;
748 m_pDropTarget
= (wxDropTarget
*) NULL
;
752 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
753 const wxPoint
&pos
, const wxSize
&size
,
754 long style
, const wxString
&name
)
760 m_cursor
= (wxCursor
*) NULL
;
762 PreCreation( parent
, id
, pos
, size
, style
, name
);
764 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
765 m_hasScrolling
= TRUE
;
767 GtkScrolledWindow
*s_window
;
768 s_window
= GTK_SCROLLED_WINDOW(m_widget
);
770 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
771 scroll_class
->scrollbar_spacing
= 0;
773 gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
775 m_oldHorizontalPos
= 0.0;
776 m_oldVerticalPos
= 0.0;
778 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) );
779 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) );
781 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "value_changed",
782 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
783 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "value_changed",
784 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
786 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "changed",
787 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
788 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "changed",
789 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
791 GtkViewport
*viewport
;
792 viewport
= GTK_VIEWPORT(s_window
->viewport
);
794 if (m_windowStyle
& wxRAISED_BORDER
)
796 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
798 else if (m_windowStyle
& wxSUNKEN_BORDER
)
800 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
804 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
807 m_wxwindow
= gtk_myfixed_new();
809 if (m_wxwindow
) GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
811 if (m_windowStyle
& wxTAB_TRAVERSAL
== wxTAB_TRAVERSAL
)
812 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
814 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
816 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
818 // shut the viewport up
819 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
820 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
822 // I _really_ don't want scrollbars in the beginning
823 m_vAdjust
->lower
= 0.0;
824 m_vAdjust
->upper
= 1.0;
825 m_vAdjust
->value
= 0.0;
826 m_vAdjust
->step_increment
= 1.0;
827 m_vAdjust
->page_increment
= 1.0;
828 m_vAdjust
->page_size
= 5.0;
829 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
830 m_hAdjust
->lower
= 0.0;
831 m_hAdjust
->upper
= 1.0;
832 m_hAdjust
->value
= 0.0;
833 m_hAdjust
->step_increment
= 1.0;
834 m_hAdjust
->page_increment
= 1.0;
835 m_hAdjust
->page_size
= 5.0;
836 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
838 gtk_widget_show( m_wxwindow
);
847 wxWindow::~wxWindow(void)
851 if (m_pDropTarget
) delete m_pDropTarget
;
853 if (m_parent
) m_parent
->RemoveChild( this );
854 if (m_widget
) Show( FALSE
);
858 if (m_wxwindow
) gtk_widget_destroy( m_wxwindow
);
860 if (m_widget
) gtk_widget_destroy( m_widget
);
864 DeleteRelatedConstraints();
867 // This removes any dangling pointers to this window
868 // in other windows' constraintsInvolvedIn lists.
869 UnsetConstraints(m_constraints
);
870 delete m_constraints
;
871 m_constraints
= (wxLayoutConstraints
*) NULL
;
875 delete m_windowSizer
;
876 m_windowSizer
= (wxSizer
*) NULL
;
878 // If this is a child of a sizer, remove self from parent
879 if (m_sizerParent
) m_sizerParent
->RemoveChild((wxWindow
*)this);
881 // Just in case the window has been Closed, but
882 // we're then deleting immediately: don't leave
883 // dangling pointers.
884 wxPendingDelete
.DeleteObject(this);
886 // Just in case we've loaded a top-level window via
887 // wxWindow::LoadNativeDialog but we weren't a dialog
889 wxTopLevelWindows
.DeleteObject(this);
891 if (m_windowValidator
) delete m_windowValidator
;
894 void wxWindow::PreCreation( wxWindow
*parent
, wxWindowID id
,
895 const wxPoint
&pos
, const wxSize
&size
,
896 long style
, const wxString
&name
)
898 if (m_needParent
&& (parent
== NULL
))
899 wxFatalError( "Need complete parent.", name
);
901 m_widget
= (GtkWidget
*) NULL
;
904 m_children
.DeleteContents( FALSE
);
908 if (m_width
== -1) m_width
= 20;
910 if (m_height
== -1) m_height
= 20;
916 m_eventHandler
= this;
919 if (m_cursor
== NULL
)
920 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
921 m_font
= *wxSWISS_FONT
;
922 m_backgroundColour
= wxWHITE
;
923 m_foregroundColour
= wxBLACK
;
924 m_windowStyle
= style
;
926 m_constraints
= (wxLayoutConstraints
*) NULL
;
927 m_constraintsInvolvedIn
= (wxList
*) NULL
;
928 m_windowSizer
= (wxSizer
*) NULL
;
929 m_sizerParent
= (wxWindow
*) NULL
;
930 m_autoLayout
= FALSE
;
931 m_pDropTarget
= (wxDropTarget
*) NULL
;
933 m_windowValidator
= (wxValidator
*) NULL
;
936 void wxWindow::PostCreation(void)
938 if (m_parent
) m_parent
->AddChild( this );
940 // GtkStyle *style = m_widget->style;
941 // style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
943 GtkWidget
*connect_widget
= GetConnectWidget();
947 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
948 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
950 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
951 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
954 gtk_signal_connect( GTK_OBJECT(connect_widget
), "key_press_event",
955 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
957 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_press_event",
958 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
960 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_release_event",
961 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
963 gtk_signal_connect( GTK_OBJECT(connect_widget
), "motion_notify_event",
964 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
966 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_in_event",
967 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
969 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_out_event",
970 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
972 // Only for cursor handling
974 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter_notify_event",
975 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
977 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave_notify_event",
978 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
982 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "enter_notify_event",
983 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
985 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "leave_notify_event",
986 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
989 if (m_widget
&& m_parent
) gtk_widget_realize( m_widget
);
993 gtk_widget_realize( m_wxwindow
);
994 gdk_gc_set_exposures( m_wxwindow
->style
->fg_gc
[0], TRUE
);
997 SetCursor( wxSTANDARD_CURSOR
);
1002 bool wxWindow::HasVMT(void)
1007 bool wxWindow::Close( bool force
)
1009 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1010 event
.SetEventObject(this);
1011 event
.SetForce(force
);
1013 return GetEventHandler()->ProcessEvent(event
);
1016 bool wxWindow::Destroy(void)
1023 bool wxWindow::DestroyChildren(void)
1028 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
)
1031 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
)
1034 if (GetChildren()->Member(child
)) delete node
;
1041 void wxWindow::PrepareDC( wxDC
&WXUNUSED(dc
) )
1043 // are we to set fonts here ?
1046 void wxWindow::ImplementSetSize(void)
1048 if ((m_minWidth
!= -1) && (m_width
< m_minWidth
)) m_width
= m_minWidth
;
1049 if ((m_minHeight
!= -1) && (m_height
< m_minHeight
)) m_height
= m_minHeight
;
1050 if ((m_maxWidth
!= -1) && (m_width
> m_maxWidth
)) m_width
= m_minWidth
;
1051 if ((m_maxHeight
!= -1) && (m_height
> m_maxHeight
)) m_height
= m_minHeight
;
1052 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1055 void wxWindow::ImplementSetPosition(void)
1057 if (IS_KIND_OF(this,wxFrame
) || IS_KIND_OF(this,wxDialog
))
1059 if ((m_x
!= -1) || (m_y
!= -1))
1060 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1066 wxFAIL_MSG( "wxWindow::SetSize error.\n" );
1070 if ((m_parent
) && (m_parent
->m_wxwindow
))
1071 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1073 // Don't do anything for children of wxNotebook and wxMDIChildFrame
1076 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1078 if (m_resizing
) return; // I don't like recursions
1086 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1088 if (newX
== -1) newX
= m_x
;
1089 if (newY
== -1) newY
= m_y
;
1090 if (newW
== -1) newW
= m_width
;
1091 if (newH
== -1) newH
= m_height
;
1094 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1096 if (newW
== -1) newW
= 80;
1099 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1101 if (newH
== -1) newH
= 26;
1104 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1108 ImplementSetPosition();
1110 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1118 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1119 event
.SetEventObject( this );
1120 ProcessEvent( event
);
1125 void wxWindow::SetSize( int width
, int height
)
1127 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1130 void wxWindow::Move( int x
, int y
)
1132 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1135 void wxWindow::GetSize( int *width
, int *height
) const
1137 if (width
) (*width
) = m_width
;
1138 if (height
) (*height
) = m_height
;
1141 void wxWindow::SetClientSize( int width
, int height
)
1145 SetSize( width
, height
);
1152 if (!m_hasScrolling
)
1155 do we have sunken dialogs ?
1157 GtkStyleClass *window_class = m_wxwindow->style->klass;
1159 dw += 2 * window_class->xthickness;
1160 dh += 2 * window_class->ythickness;
1165 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1166 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1168 GtkWidget
*viewport
= scroll_window
->viewport
;
1169 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1171 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1172 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1174 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1175 (m_windowStyle
& wxSUNKEN_BORDER
))
1177 dw
+= 2 * viewport_class
->xthickness
;
1178 dh
+= 2 * viewport_class
->ythickness
;
1181 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1183 dw
+= vscrollbar
->allocation
.width
;
1184 dw
+= scroll_class
->scrollbar_spacing
;
1187 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1189 dh
+= hscrollbar
->allocation
.height
;
1190 dw
+= scroll_class
->scrollbar_spacing
;
1194 SetSize( width
+dw
, height
+dh
);
1198 void wxWindow::GetClientSize( int *width
, int *height
) const
1202 if (width
) (*width
) = m_width
;
1203 if (height
) (*height
) = m_height
;
1210 if (!m_hasScrolling
)
1213 do we have sunken dialogs ?
1215 GtkStyleClass *window_class = m_wxwindow->style->klass;
1217 dw += 2 * window_class->xthickness;
1218 dh += 2 * window_class->ythickness;
1223 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1224 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1226 GtkWidget
*viewport
= scroll_window
->viewport
;
1227 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1229 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1230 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1232 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1233 (m_windowStyle
& wxSUNKEN_BORDER
))
1235 dw
+= 2 * viewport_class
->xthickness
;
1236 dh
+= 2 * viewport_class
->ythickness
;
1239 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1241 // dw += vscrollbar->allocation.width;
1242 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1243 dw
+= scroll_class
->scrollbar_spacing
;
1246 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1248 // dh += hscrollbar->allocation.height;
1250 dh
+= scroll_class
->scrollbar_spacing
;
1254 if (width
) (*width
) = m_width
- dw
;
1255 if (height
) (*height
) = m_height
- dh
;
1259 void wxWindow::GetPosition( int *x
, int *y
) const
1265 void wxWindow::ClientToScreen( int *x
, int *y
)
1267 GdkWindow
*source
= (GdkWindow
*) NULL
;
1269 source
= m_wxwindow
->window
;
1271 source
= m_widget
->window
;
1275 gdk_window_get_origin( source
, &org_x
, &org_y
);
1279 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1281 org_x
+= m_widget
->allocation
.x
;
1282 org_y
+= m_widget
->allocation
.y
;
1290 void wxWindow::ScreenToClient( int *x
, int *y
)
1292 GdkWindow
*source
= (GdkWindow
*) NULL
;
1294 source
= m_wxwindow
->window
;
1296 source
= m_widget
->window
;
1300 gdk_window_get_origin( source
, &org_x
, &org_y
);
1304 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1306 org_x
+= m_widget
->allocation
.x
;
1307 org_y
+= m_widget
->allocation
.y
;
1315 void wxWindow::Centre( int direction
)
1317 if (IS_KIND_OF(this,wxDialog
) || IS_KIND_OF(this,wxFrame
))
1319 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
1320 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
1321 ImplementSetPosition();
1329 m_parent
->GetSize( &p_w
, &p_h
);
1330 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (p_w
- m_width
) / 2;
1331 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (p_h
- m_height
) / 2;
1332 ImplementSetPosition();
1337 void wxWindow::Fit(void)
1341 wxNode
*node
= GetChildren()->First();
1344 wxWindow
*win
= (wxWindow
*)node
->Data();
1346 win
->GetPosition(&wx
, &wy
);
1347 win
->GetSize(&ww
, &wh
);
1348 if ( wx
+ ww
> maxX
)
1350 if ( wy
+ wh
> maxY
)
1353 node
= node
->Next();
1355 SetClientSize(maxX
+ 5, maxY
+ 10);
1358 void wxWindow::SetSizeHints( int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
) )
1366 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1368 //if (GetAutoLayout()) Layout();
1371 bool wxWindow::Show( bool show
)
1374 gtk_widget_show( m_widget
);
1376 gtk_widget_hide( m_widget
);
1381 void wxWindow::Enable( bool enable
)
1383 m_isEnabled
= enable
;
1384 gtk_widget_set_sensitive( m_widget
, enable
);
1385 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1388 int wxWindow::GetCharHeight(void) const
1390 GdkFont
*font
= m_font
.GetInternalFont( 1.0 );
1391 return font
->ascent
+ font
->descent
;
1394 int wxWindow::GetCharWidth(void) const
1396 GdkFont
*font
= m_font
.GetInternalFont( 1.0 );
1397 return gdk_string_width( font
, "H" );
1400 void wxWindow::GetTextExtent( const wxString
& string
, int *x
, int *y
,
1401 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool WXUNUSED(use16
) ) const
1403 wxFont fontToUse
= m_font
;
1404 if (theFont
) fontToUse
= *theFont
;
1406 GdkFont
*font
= fontToUse
.GetInternalFont( 1.0 );
1407 if (x
) (*y
) = gdk_string_width( font
, string
);
1408 if (y
) (*y
) = font
->ascent
+ font
->descent
;
1409 if (descent
) (*descent
) = font
->descent
;
1410 if (externalLeading
) (*externalLeading
) = 0; // ??
1413 void wxWindow::MakeModal( bool modal
)
1416 // Disable all other windows
1417 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1419 wxNode
*node
= wxTopLevelWindows
.First();
1422 wxWindow
*win
= (wxWindow
*)node
->Data();
1424 win
->Enable(!modal
);
1426 node
= node
->Next();
1431 void wxWindow::SetFocus(void)
1433 GtkWidget
*connect_widget
= GetConnectWidget();
1436 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1438 gtk_widget_grab_focus (connect_widget
);
1443 bool wxWindow::OnClose(void)
1448 void wxWindow::AddChild( wxWindow
*child
)
1450 // Addchild is (often) called before the program
1451 // has left the parents constructor so that no
1452 // virtual tables work yet. The approach below
1453 // practically imitates virtual tables, i.e. it
1454 // implements a different AddChild() behaviour
1455 // for wxFrame, wxDialog, wxWindow and
1456 // wxMDIParentFrame.
1458 // wxFrame and wxDialog as children aren't placed into the parents
1460 if (( IS_KIND_OF(child
,wxFrame
) || IS_KIND_OF(child
,wxDialog
) ) &&
1461 (!IS_KIND_OF(child
,wxMDIChildFrame
)))
1463 m_children
.Append( child
);
1465 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1466 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1471 // In the case of an wxMDIChildFrame descendant, we use the
1472 // client windows's AddChild()
1474 if (IS_KIND_OF(this,wxMDIParentFrame
))
1476 if (IS_KIND_OF(child
,wxMDIChildFrame
))
1478 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1481 client
->AddChild( child
);
1487 // wxNotebook is very special, so it has a private AddChild()
1489 if (IS_KIND_OF(this,wxNotebook
))
1491 wxNotebook
*tab
= (wxNotebook
*)this;
1492 tab
->AddChild( child
);
1496 // wxFrame has a private AddChild
1498 if (IS_KIND_OF(this,wxFrame
) && !IS_KIND_OF(this,wxMDIChildFrame
))
1500 wxFrame
*frame
= (wxFrame
*)this;
1501 frame
->AddChild( child
);
1507 m_children
.Append( child
);
1508 if (m_wxwindow
) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
,
1509 child
->m_x
, child
->m_y
);
1511 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1514 wxList
*wxWindow::GetChildren(void)
1516 return (&m_children
);
1519 void wxWindow::RemoveChild( wxWindow
*child
)
1522 GetChildren()->DeleteObject( child
);
1523 child
->m_parent
= (wxWindow
*) NULL
;
1526 void wxWindow::SetReturnCode( int retCode
)
1528 m_retCode
= retCode
;
1531 int wxWindow::GetReturnCode(void)
1536 void wxWindow::Raise(void)
1538 if (m_widget
) gdk_window_raise( m_widget
->window
);
1541 void wxWindow::Lower(void)
1543 if (m_widget
) gdk_window_lower( m_widget
->window
);
1546 wxEvtHandler
*wxWindow::GetEventHandler(void)
1548 return m_eventHandler
;
1551 void wxWindow::SetEventHandler( wxEvtHandler
*handler
)
1553 m_eventHandler
= handler
;
1556 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
1558 handler
->SetNextHandler(GetEventHandler());
1559 SetEventHandler(handler
);
1562 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
1564 if ( GetEventHandler() )
1566 wxEvtHandler
*handlerA
= GetEventHandler();
1567 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
1568 handlerA
->SetNextHandler((wxEvtHandler
*) NULL
);
1569 SetEventHandler(handlerB
);
1570 if ( deleteHandler
)
1573 return (wxEvtHandler
*) NULL
;
1579 return (wxEvtHandler
*) NULL
;
1582 wxValidator
*wxWindow::GetValidator(void)
1584 return m_windowValidator
;
1587 void wxWindow::SetValidator( const wxValidator
& validator
)
1589 if (m_windowValidator
) delete m_windowValidator
;
1590 m_windowValidator
= validator
.Clone();
1591 if (m_windowValidator
) m_windowValidator
->SetWindow(this);
1594 bool wxWindow::IsBeingDeleted(void)
1599 void wxWindow::SetId( wxWindowID id
)
1604 wxWindowID
wxWindow::GetId(void)
1609 void wxWindow::SetCursor( const wxCursor
&cursor
)
1611 wxASSERT(m_cursor
!= NULL
);
1613 if (m_cursor
!= NULL
)
1614 if (*m_cursor
== cursor
)
1616 (*m_cursor
) = cursor
;
1617 if (m_widget
->window
)
1618 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1619 if (m_wxwindow
&& m_wxwindow
->window
)
1620 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1623 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1625 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1628 gdk_window_clear_area( m_wxwindow
->window
,
1642 GetClientSize( &w
, &h
);
1644 GdkRectangle gdk_rect
;
1648 gdk_rect
.height
= h
;
1649 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1654 GdkRectangle gdk_rect
;
1655 gdk_rect
.x
= rect
->x
;
1656 gdk_rect
.y
= rect
->y
;
1657 gdk_rect
.width
= rect
->width
;
1658 gdk_rect
.height
= rect
->height
;
1661 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1663 gtk_widget_draw( m_widget
, &gdk_rect
);
1667 wxRegion
wxWindow::GetUpdateRegion() const
1669 return m_updateRegion
;
1672 bool wxWindow::IsExposed( int x
, int y
) const
1674 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1677 bool wxWindow::IsExposed( int x
, int y
, int w
, int h
) const
1679 return (m_updateRegion
.Contains( x
, y
, w
, h
) != wxOutRegion
);
1682 bool wxWindow::IsExposed( const wxPoint
& pt
) const
1684 return (m_updateRegion
.Contains( pt
.x
, pt
.y
) != wxOutRegion
);
1687 bool wxWindow::IsExposed( const wxRect
& rect
) const
1689 return (m_updateRegion
.Contains( rect
.x
, rect
.y
, rect
.width
, rect
.height
) != wxOutRegion
);
1692 void wxWindow::Clear(void)
1694 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1697 wxColour
wxWindow::GetBackgroundColour(void) const
1699 return m_backgroundColour
;
1702 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1704 m_backgroundColour
= colour
;
1707 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1708 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1709 gdk_window_clear( m_wxwindow
->window
);
1714 wxColour
wxWindow::GetForegroundColour(void) const
1716 return m_foregroundColour
;
1719 void wxWindow::SetForegroundColour( const wxColour
&colour
)
1721 m_foregroundColour
= colour
;
1724 bool wxWindow::Validate(void)
1726 wxNode
*node
= GetChildren()->First();
1729 wxWindow
*child
= (wxWindow
*)node
->Data();
1730 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1732 node
= node
->Next();
1737 bool wxWindow::TransferDataToWindow(void)
1739 wxNode
*node
= GetChildren()->First();
1742 wxWindow
*child
= (wxWindow
*)node
->Data();
1743 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1744 !child
->GetValidator()->TransferToWindow() )
1746 wxMessageBox( _("Application Error"), _("Could not transfer data to window"), wxOK
|wxICON_EXCLAMATION
);
1749 node
= node
->Next();
1754 bool wxWindow::TransferDataFromWindow(void)
1756 wxNode
*node
= GetChildren()->First();
1759 wxWindow
*child
= (wxWindow
*)node
->Data();
1760 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1762 node
= node
->Next();
1767 void wxWindow::SetAcceleratorTable( const wxAcceleratorTable
& accel
)
1769 m_acceleratorTable
= accel
;
1772 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1774 TransferDataToWindow();
1777 void wxWindow::InitDialog(void)
1779 wxInitDialogEvent
event(GetId());
1780 event
.SetEventObject( this );
1781 GetEventHandler()->ProcessEvent(event
);
1784 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
1786 menu
->SetInvokingWindow( win
);
1787 wxNode
*node
= menu
->m_items
.First();
1790 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
1791 if (menuitem
->IsSubMenu())
1792 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1793 node
= node
->Next();
1797 bool wxWindow::PopupMenu( wxMenu
*menu
, int WXUNUSED(x
), int WXUNUSED(y
) )
1799 SetInvokingWindow( menu
, this );
1800 gtk_menu_popup( GTK_MENU(menu
->m_menu
), (GtkWidget
*) NULL
, (GtkWidget
*) NULL
, (GtkMenuPositionFunc
) NULL
, NULL
, 0, 0 );
1804 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1806 GtkWidget
*dnd_widget
= GetConnectWidget();
1810 gtk_signal_disconnect_by_func( GTK_OBJECT(dnd_widget
),
1811 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1813 m_pDropTarget
->UnregisterWidget( dnd_widget
);
1814 delete m_pDropTarget
;
1816 m_pDropTarget
= dropTarget
;
1819 m_pDropTarget
->RegisterWidget( dnd_widget
);
1821 gtk_signal_connect( GTK_OBJECT(dnd_widget
), "drop_data_available_event",
1822 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1826 wxDropTarget
*wxWindow::GetDropTarget() const
1828 return m_pDropTarget
;
1831 GtkWidget
* wxWindow::GetConnectWidget(void)
1833 GtkWidget
*connect_widget
= m_widget
;
1834 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1836 return connect_widget
;
1839 bool wxWindow::IsOwnGtkWindow( GdkWindow
*window
)
1841 if (m_wxwindow
) return (window
== m_wxwindow
->window
);
1842 return (window
== m_widget
->window
);
1845 void wxWindow::SetFont( const wxFont
&font
)
1850 copy old style values to new one
1851 set font in new style
1852 -> takes to many resources
1854 GtkStyle *style = gtk_style_new();
1859 wxFont
*wxWindow::GetFont(void)
1864 void wxWindow::SetWindowStyleFlag( long flag
)
1866 m_windowStyle
= flag
;
1869 long wxWindow::GetWindowStyleFlag(void) const
1871 return m_windowStyle
;
1874 void wxWindow::CaptureMouse(void)
1876 GtkWidget
*connect_widget
= GetConnectWidget();
1877 gtk_grab_add( connect_widget
);
1878 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1880 (GDK_BUTTON_PRESS_MASK
|
1881 GDK_BUTTON_RELEASE_MASK
|
1882 GDK_POINTER_MOTION_MASK
),
1883 (GdkWindow
*) NULL
, (GdkCursor
*) NULL
, GDK_CURRENT_TIME
);
1886 void wxWindow::ReleaseMouse(void)
1888 GtkWidget
*connect_widget
= GetConnectWidget();
1889 gtk_grab_remove( connect_widget
);
1890 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1893 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1897 wxString
wxWindow::GetTitle(void) const
1899 return (wxString
&)m_windowName
;
1902 wxString
wxWindow::GetLabel(void) const
1907 void wxWindow::SetName( const wxString
&name
)
1909 m_windowName
= name
;
1912 wxString
wxWindow::GetName(void) const
1914 return (wxString
&)m_windowName
;
1917 bool wxWindow::IsShown(void) const
1922 bool wxWindow::IsRetained(void)
1927 wxWindow
*wxWindow::FindWindow( long id
)
1929 if (id
== m_windowId
) return this;
1930 wxNode
*node
= m_children
.First();
1933 wxWindow
*child
= (wxWindow
*)node
->Data();
1934 wxWindow
*res
= child
->FindWindow( id
);
1935 if (res
) return res
;
1936 node
= node
->Next();
1938 return (wxWindow
*) NULL
;
1941 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1943 if (name
== m_windowName
) return this;
1944 wxNode
*node
= m_children
.First();
1947 wxWindow
*child
= (wxWindow
*)node
->Data();
1948 wxWindow
*res
= child
->FindWindow( name
);
1949 if (res
) return res
;
1950 node
= node
->Next();
1952 return (wxWindow
*) NULL
;
1955 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1956 int range
, bool WXUNUSED(refresh
) )
1958 if (!m_wxwindow
) return;
1960 if (orient
== wxHORIZONTAL
)
1962 float fpos
= (float)pos
;
1963 m_oldHorizontalPos
= fpos
;
1964 float frange
= (float)range
;
1965 float fthumb
= (float)thumbVisible
;
1967 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1968 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1969 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1972 m_hAdjust
->lower
= 0.0;
1973 m_hAdjust
->upper
= frange
;
1974 m_hAdjust
->value
= fpos
;
1975 m_hAdjust
->step_increment
= 1.0;
1976 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1977 m_hAdjust
->page_size
= fthumb
;
1981 float fpos
= (float)pos
;
1982 m_oldVerticalPos
= fpos
;
1983 float frange
= (float)range
;
1984 float fthumb
= (float)thumbVisible
;
1986 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1987 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1988 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1991 m_vAdjust
->lower
= 0.0;
1992 m_vAdjust
->upper
= frange
;
1993 m_vAdjust
->value
= fpos
;
1994 m_vAdjust
->step_increment
= 1.0;
1995 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1996 m_vAdjust
->page_size
= fthumb
;
1999 if (m_wxwindow
->window
)
2001 if (orient
== wxHORIZONTAL
)
2002 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
2004 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
2006 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
2010 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
2012 if (!m_wxwindow
) return;
2014 if (orient
== wxHORIZONTAL
)
2016 float fpos
= (float)pos
;
2017 m_oldHorizontalPos
= fpos
;
2019 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
2020 m_hAdjust
->value
= fpos
;
2024 float fpos
= (float)pos
;
2025 m_oldVerticalPos
= fpos
;
2026 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
2027 m_vAdjust
->value
= fpos
;
2030 if (m_wxwindow
->window
)
2032 if (orient
== wxHORIZONTAL
)
2033 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
2035 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
2039 int wxWindow::GetScrollThumb( int orient
) const
2041 if (!m_wxwindow
) return 0;
2043 if (orient
== wxHORIZONTAL
)
2044 return (int)(m_hAdjust
->page_size
+0.5);
2046 return (int)(m_vAdjust
->page_size
+0.5);
2049 int wxWindow::GetScrollPos( int orient
) const
2051 if (!m_wxwindow
) return 0;
2053 if (orient
== wxHORIZONTAL
)
2054 return (int)(m_hAdjust
->value
+0.5);
2056 return (int)(m_vAdjust
->value
+0.5);
2059 int wxWindow::GetScrollRange( int orient
) const
2061 if (!m_wxwindow
) return 0;
2063 if (orient
== wxHORIZONTAL
)
2064 return (int)(m_hAdjust
->upper
+0.5);
2066 return (int)(m_vAdjust
->upper
+0.5);
2069 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
2071 if (!m_wxwindow
) return;
2074 bool refresh = FALSE;
2076 if ((m_drawingOffsetX == 0) && (m_drawingOffsetY == 0))
2078 m_drawingOffsetX = -16000;
2079 m_drawingOffsetY = -16000;
2084 m_drawingOffsetX += dx;
2085 m_drawingOffsetY += dy;
2088 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
2090 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
2092 if (refresh) Refresh();
2094 The code here is very nifty, but it doesn't work with
2095 overlapping windows...
2100 GetClientSize( &cw
, &ch
);
2102 int w
= cw
- abs(dx
);
2103 int h
= ch
- abs(dy
);
2104 if ((h
< 0) || (w
< 0))
2111 if (dx
< 0) s_x
= -dx
;
2112 if (dy
< 0) s_y
= -dy
;
2115 if (dx
> 0) d_x
= dx
;
2116 if (dy
> 0) d_y
= dy
;
2117 gdk_window_copy_area( m_wxwindow
->window
, m_wxwindow
->style
->fg_gc
[0], d_x
, d_y
,
2118 m_wxwindow
->window
, s_x
, s_y
, w
, h
);
2121 if (dx
< 0) rect
.x
= cw
+dx
; else rect
.x
= 0;
2122 if (dy
< 0) rect
.y
= ch
+dy
; else rect
.y
= 0;
2123 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
2124 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
2126 Refresh( TRUE
, &rect
);
2129 //-------------------------------------------------------------------------------------
2131 //-------------------------------------------------------------------------------------
2133 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
2135 return m_constraints
;
2138 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
2142 UnsetConstraints(m_constraints
);
2143 delete m_constraints
;
2145 m_constraints
= constraints
;
2148 // Make sure other windows know they're part of a 'meaningful relationship'
2149 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
2150 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2151 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
2152 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2153 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
2154 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2155 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
2156 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2157 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
2158 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2159 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
2160 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2161 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
2162 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2163 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
2164 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2170 void wxWindow::SetAutoLayout( bool autoLayout
)
2172 m_autoLayout
= autoLayout
;
2175 bool wxWindow::GetAutoLayout(void) const
2177 return m_autoLayout
;
2180 wxSizer
*wxWindow::GetSizer(void) const
2182 return m_windowSizer
;
2185 void wxWindow::SetSizerParent( wxWindow
*win
)
2187 m_sizerParent
= win
;
2190 wxWindow
*wxWindow::GetSizerParent(void) const
2192 return m_sizerParent
;
2195 // This removes any dangling pointers to this window
2196 // in other windows' constraintsInvolvedIn lists.
2197 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2201 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2202 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2203 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2204 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2205 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2206 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2207 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2208 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2209 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2210 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2211 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2212 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2213 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2214 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2215 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2216 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2220 // Back-pointer to other windows we're involved with, so if we delete
2221 // this window, we must delete any constraints we're involved with.
2222 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2224 if (!m_constraintsInvolvedIn
)
2225 m_constraintsInvolvedIn
= new wxList
;
2226 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2227 m_constraintsInvolvedIn
->Append(otherWin
);
2230 // REMOVE back-pointer to other windows we're involved with.
2231 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2233 if (m_constraintsInvolvedIn
)
2234 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2237 // Reset any constraints that mention this window
2238 void wxWindow::DeleteRelatedConstraints(void)
2240 if (m_constraintsInvolvedIn
)
2242 wxNode
*node
= m_constraintsInvolvedIn
->First();
2245 wxWindow
*win
= (wxWindow
*)node
->Data();
2246 wxNode
*next
= node
->Next();
2247 wxLayoutConstraints
*constr
= win
->GetConstraints();
2249 // Reset any constraints involving this window
2252 constr
->left
.ResetIfWin((wxWindow
*)this);
2253 constr
->top
.ResetIfWin((wxWindow
*)this);
2254 constr
->right
.ResetIfWin((wxWindow
*)this);
2255 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2256 constr
->width
.ResetIfWin((wxWindow
*)this);
2257 constr
->height
.ResetIfWin((wxWindow
*)this);
2258 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2259 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2264 delete m_constraintsInvolvedIn
;
2265 m_constraintsInvolvedIn
= (wxList
*) NULL
;
2269 void wxWindow::SetSizer(wxSizer
*sizer
)
2271 m_windowSizer
= sizer
;
2273 sizer
->SetSizerParent((wxWindow
*)this);
2280 bool wxWindow::Layout(void)
2282 if (GetConstraints())
2285 GetClientSize(&w
, &h
);
2286 GetConstraints()->width
.SetValue(w
);
2287 GetConstraints()->height
.SetValue(h
);
2290 // If top level (one sizer), evaluate the sizer's constraints.
2294 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2295 GetSizer()->LayoutPhase1(&noChanges
);
2296 GetSizer()->LayoutPhase2(&noChanges
);
2297 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2302 // Otherwise, evaluate child constraints
2303 ResetConstraints(); // Mark all constraints as unevaluated
2304 DoPhase(1); // Just one phase need if no sizers involved
2306 SetConstraintSizes(); // Recursively set the real window sizes
2312 // Do a phase of evaluating constraints:
2313 // the default behaviour. wxSizers may do a similar
2314 // thing, but also impose their own 'constraints'
2315 // and order the evaluation differently.
2316 bool wxWindow::LayoutPhase1(int *noChanges
)
2318 wxLayoutConstraints
*constr
= GetConstraints();
2321 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2327 bool wxWindow::LayoutPhase2(int *noChanges
)
2337 // Do a phase of evaluating child constraints
2338 bool wxWindow::DoPhase(int phase
)
2340 int noIterations
= 0;
2341 int maxIterations
= 500;
2345 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2349 wxNode
*node
= GetChildren()->First();
2352 wxWindow
*child
= (wxWindow
*)node
->Data();
2353 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2355 wxLayoutConstraints
*constr
= child
->GetConstraints();
2358 if (succeeded
.Member(child
))
2363 int tempNoChanges
= 0;
2364 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2365 noChanges
+= tempNoChanges
;
2368 succeeded
.Append(child
);
2373 node
= node
->Next();
2380 void wxWindow::ResetConstraints(void)
2382 wxLayoutConstraints
*constr
= GetConstraints();
2385 constr
->left
.SetDone(FALSE
);
2386 constr
->top
.SetDone(FALSE
);
2387 constr
->right
.SetDone(FALSE
);
2388 constr
->bottom
.SetDone(FALSE
);
2389 constr
->width
.SetDone(FALSE
);
2390 constr
->height
.SetDone(FALSE
);
2391 constr
->centreX
.SetDone(FALSE
);
2392 constr
->centreY
.SetDone(FALSE
);
2394 wxNode
*node
= GetChildren()->First();
2397 wxWindow
*win
= (wxWindow
*)node
->Data();
2398 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2399 win
->ResetConstraints();
2400 node
= node
->Next();
2404 // Need to distinguish between setting the 'fake' size for
2405 // windows and sizers, and setting the real values.
2406 void wxWindow::SetConstraintSizes(bool recurse
)
2408 wxLayoutConstraints
*constr
= GetConstraints();
2409 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2410 constr
->width
.GetDone() && constr
->height
.GetDone())
2412 int x
= constr
->left
.GetValue();
2413 int y
= constr
->top
.GetValue();
2414 int w
= constr
->width
.GetValue();
2415 int h
= constr
->height
.GetValue();
2417 // If we don't want to resize this window, just move it...
2418 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2419 (constr
->height
.GetRelationship() != wxAsIs
))
2421 // Calls Layout() recursively. AAAGH. How can we stop that.
2422 // Simply take Layout() out of non-top level OnSizes.
2423 SizerSetSize(x
, y
, w
, h
);
2432 char *windowClass
= this->GetClassInfo()->GetClassName();
2435 if (GetName() == "")
2436 winName
= _("unnamed");
2438 winName
= GetName();
2439 wxDebugMsg(_("Constraint(s) not satisfied for window of type %s, name %s:\n"), (const char *)windowClass
, (const char *)winName
);
2440 if (!constr
->left
.GetDone())
2441 wxDebugMsg(_(" unsatisfied 'left' constraint.\n"));
2442 if (!constr
->right
.GetDone())
2443 wxDebugMsg(_(" unsatisfied 'right' constraint.\n"));
2444 if (!constr
->width
.GetDone())
2445 wxDebugMsg(_(" unsatisfied 'width' constraint.\n"));
2446 if (!constr
->height
.GetDone())
2447 wxDebugMsg(_(" unsatisfied 'height' constraint.\n"));
2448 wxDebugMsg(_("Please check constraints: try adding AsIs() constraints.\n"));
2453 wxNode
*node
= GetChildren()->First();
2456 wxWindow
*win
= (wxWindow
*)node
->Data();
2457 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2458 win
->SetConstraintSizes();
2459 node
= node
->Next();
2464 // This assumes that all sizers are 'on' the same
2465 // window, i.e. the parent of this window.
2466 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2468 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2469 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2473 m_sizerParent
->GetPosition(&xp
, &yp
);
2474 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2479 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2483 TransformSizerToActual(&xx
, &yy
);
2484 SetSize(xx
, yy
, w
, h
);
2487 void wxWindow::SizerMove(int x
, int y
)
2491 TransformSizerToActual(&xx
, &yy
);
2495 // Only set the size/position of the constraint (if any)
2496 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2498 wxLayoutConstraints
*constr
= GetConstraints();
2503 constr
->left
.SetValue(x
);
2504 constr
->left
.SetDone(TRUE
);
2508 constr
->top
.SetValue(y
);
2509 constr
->top
.SetDone(TRUE
);
2513 constr
->width
.SetValue(w
);
2514 constr
->width
.SetDone(TRUE
);
2518 constr
->height
.SetValue(h
);
2519 constr
->height
.SetDone(TRUE
);
2524 void wxWindow::MoveConstraint(int x
, int y
)
2526 wxLayoutConstraints
*constr
= GetConstraints();
2531 constr
->left
.SetValue(x
);
2532 constr
->left
.SetDone(TRUE
);
2536 constr
->top
.SetValue(y
);
2537 constr
->top
.SetDone(TRUE
);
2542 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2544 wxLayoutConstraints
*constr
= GetConstraints();
2547 *w
= constr
->width
.GetValue();
2548 *h
= constr
->height
.GetValue();
2554 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2556 wxLayoutConstraints
*constr
= GetConstraints();
2559 *w
= constr
->width
.GetValue();
2560 *h
= constr
->height
.GetValue();
2563 GetClientSize(w
, h
);
2566 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2568 wxLayoutConstraints
*constr
= GetConstraints();
2571 *x
= constr
->left
.GetValue();
2572 *y
= constr
->top
.GetValue();
2578 bool wxWindow::AcceptsFocus() const
2580 return IsEnabled() && IsShown();
2583 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
) )