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 if ((gdk_event
->keyval
>= 0x20) && (gdk_event
->keyval
<= 0xFF))
197 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "key_press_event" );
203 //-----------------------------------------------------------------------------
204 // "button_press_event"
205 //-----------------------------------------------------------------------------
207 static gint
gtk_window_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
209 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return TRUE
;
211 if (g_blockEventsOnDrag
) return TRUE
;
215 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
) && !GTK_WIDGET_HAS_FOCUS (win
->m_wxwindow
) )
217 gtk_widget_grab_focus (win
->m_wxwindow
);
220 printf( "GrabFocus from " );
221 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
222 printf( win->GetClassInfo()->GetClassName() );
229 if (!win
->HasVMT()) return TRUE
;
231 printf( "OnButtonPress from " );
232 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
233 printf( win
->GetClassInfo()->GetClassName() );
236 wxEventType event_type
= wxEVT_LEFT_DOWN
;
238 if (gdk_event
->button
== 1)
240 switch (gdk_event
->type
)
242 case GDK_BUTTON_PRESS
: event_type
= wxEVT_LEFT_DOWN
; break;
243 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_LEFT_DCLICK
; break;
247 else if (gdk_event
->button
== 2)
249 switch (gdk_event
->type
)
251 case GDK_BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DOWN
; break;
252 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DCLICK
; break;
256 else if (gdk_event
->button
== 3)
258 switch (gdk_event
->type
)
260 case GDK_BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DOWN
; break;
261 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DCLICK
; break;
266 wxMouseEvent
event( event_type
);
267 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
268 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
269 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
270 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
271 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
272 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
273 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
275 event
.m_x
= (long)gdk_event
->x
;
276 event
.m_y
= (long)gdk_event
->y
;
278 // Some control don't have their own X window and thus cannot get
281 wxNode
*node
= win
->GetChildren()->First();
284 wxWindow
*child
= (wxWindow
*)node
->Data();
285 if ((child
->m_x
<= event
.m_x
) &&
286 (child
->m_y
<= event
.m_y
) &&
287 (child
->m_x
+child
->m_width
>= event
.m_x
) &&
288 (child
->m_y
+child
->m_height
>= event
.m_y
))
291 event
.m_x
-= child
->m_x
;
292 event
.m_y
-= child
->m_y
;
298 event
.SetEventObject( win
);
300 if (win
->GetEventHandler()->ProcessEvent( event
))
301 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_press_event" );
306 //-----------------------------------------------------------------------------
308 //-----------------------------------------------------------------------------
310 static gint
gtk_window_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxWindow
*win
)
312 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return TRUE
;
313 if (g_blockEventsOnDrag
) return TRUE
;
315 if (!win
->HasVMT()) return TRUE
;
318 printf( "OnButtonRelease from " );
319 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
320 printf( win->GetClassInfo()->GetClassName() );
324 wxEventType event_type
= wxEVT_NULL
;
326 switch (gdk_event
->button
)
328 case 1: event_type
= wxEVT_LEFT_UP
; break;
329 case 2: event_type
= wxEVT_MIDDLE_UP
; break;
330 case 3: event_type
= wxEVT_RIGHT_UP
; break;
333 wxMouseEvent
event( event_type
);
334 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
335 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
336 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
337 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
338 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
339 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
340 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
341 event
.m_x
= (long)gdk_event
->x
;
342 event
.m_y
= (long)gdk_event
->y
;
344 // Some control don't have their own X window and thus cannot get
347 wxNode
*node
= win
->GetChildren()->First();
350 wxWindow
*child
= (wxWindow
*)node
->Data();
351 if ((child
->m_x
<= event
.m_x
) &&
352 (child
->m_y
<= event
.m_y
) &&
353 (child
->m_x
+child
->m_width
>= event
.m_x
) &&
354 (child
->m_y
+child
->m_height
>= event
.m_y
))
357 event
.m_x
-= child
->m_x
;
358 event
.m_y
-= child
->m_y
;
364 event
.SetEventObject( win
);
366 if (win
->GetEventHandler()->ProcessEvent( event
))
367 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "button_release_event" );
372 //-----------------------------------------------------------------------------
373 // "motion_notify_event"
374 //-----------------------------------------------------------------------------
376 static gint
gtk_window_motion_notify_callback( GtkWidget
*widget
, GdkEventMotion
*gdk_event
, wxWindow
*win
)
378 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return TRUE
;
379 if (g_blockEventsOnDrag
) return TRUE
;
381 if (!win
->HasVMT()) return TRUE
;
384 printf( "OnMotion from " );
385 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
386 printf( win->GetClassInfo()->GetClassName() );
390 wxMouseEvent
event( wxEVT_MOTION
);
391 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
392 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
393 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
394 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
395 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
396 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
397 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
399 event
.m_x
= (long)gdk_event
->x
;
400 event
.m_y
= (long)gdk_event
->y
;
402 // Some control don't have their own X window and thus cannot get
405 wxNode
*node
= win
->GetChildren()->First();
408 wxWindow
*child
= (wxWindow
*)node
->Data();
409 if ((child
->m_x
<= event
.m_x
) &&
410 (child
->m_y
<= event
.m_y
) &&
411 (child
->m_x
+child
->m_width
>= event
.m_x
) &&
412 (child
->m_y
+child
->m_height
>= event
.m_y
))
415 event
.m_x
-= child
->m_x
;
416 event
.m_y
-= child
->m_y
;
422 event
.SetEventObject( win
);
424 if (win
->GetEventHandler()->ProcessEvent( event
))
425 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "motion_notify_event" );
430 //-----------------------------------------------------------------------------
432 //-----------------------------------------------------------------------------
434 static gint
gtk_window_focus_in_callback( GtkWidget
*widget
, GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
436 if (g_blockEventsOnDrag
) return TRUE
;
439 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
441 GTK_WIDGET_SET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
443 printf( "SetFocus flag from " );
444 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
445 printf( win->GetClassInfo()->GetClassName() );
451 if (!win
->HasVMT()) return TRUE
;
454 printf( "OnSetFocus from " );
455 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
456 printf( win->GetClassInfo()->GetClassName() );
458 printf( WXSTRINGCAST win->GetLabel() );
462 wxFocusEvent
event( wxEVT_SET_FOCUS
, win
->GetId() );
463 event
.SetEventObject( win
);
465 if (win
->GetEventHandler()->ProcessEvent( event
))
466 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_in_event" );
471 //-----------------------------------------------------------------------------
473 //-----------------------------------------------------------------------------
475 static gint
gtk_window_focus_out_callback( GtkWidget
*widget
, GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
477 if (g_blockEventsOnDrag
) return TRUE
;
480 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
481 GTK_WIDGET_UNSET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
484 if (!win
->HasVMT()) return TRUE
;
487 printf( "OnKillFocus from " );
488 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
489 printf( win->GetClassInfo()->GetClassName() );
493 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
494 event
.SetEventObject( win
);
496 if (win
->GetEventHandler()->ProcessEvent( event
))
497 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget
), "focus_out_event" );
502 //-----------------------------------------------------------------------------
503 // "value_changed" from m_vAdjust
504 //-----------------------------------------------------------------------------
506 static void gtk_window_vscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
508 if (g_blockEventsOnDrag
) return;
511 printf( "OnVScroll from " );
512 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
513 printf( win->GetClassInfo()->GetClassName() );
517 if (!win
->HasVMT()) return;
519 float diff
= win
->m_vAdjust
->value
- win
->m_oldVerticalPos
;
520 if (fabs(diff
) < 0.2) return;
522 wxEventType command
= wxEVT_NULL
;
524 float line_step
= win
->m_vAdjust
->step_increment
;
525 float page_step
= win
->m_vAdjust
->page_increment
;
527 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
528 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
529 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
530 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
531 else command
= wxEVT_SCROLL_THUMBTRACK
;
533 int value
= (int)(win
->m_vAdjust
->value
+0.5);
535 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
536 event
.SetEventObject( win
);
537 win
->GetEventHandler()->ProcessEvent( event
);
540 //-----------------------------------------------------------------------------
541 // "value_changed" from m_hAdjust
542 //-----------------------------------------------------------------------------
544 static void gtk_window_hscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
546 if (g_blockEventsOnDrag
) return;
549 printf( "OnHScroll from " );
550 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
551 printf( win->GetClassInfo()->GetClassName() );
555 if (!win
->HasVMT()) return;
557 float diff
= win
->m_hAdjust
->value
- win
->m_oldHorizontalPos
;
558 if (fabs(diff
) < 0.2) return;
560 wxEventType command
= wxEVT_NULL
;
562 float line_step
= win
->m_hAdjust
->step_increment
;
563 float page_step
= win
->m_hAdjust
->page_increment
;
565 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
566 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
567 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
568 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
569 else command
= wxEVT_SCROLL_THUMBTRACK
;
571 int value
= (int)(win
->m_hAdjust
->value
+0.5);
573 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
574 event
.SetEventObject( win
);
575 win
->GetEventHandler()->ProcessEvent( event
);
578 //-----------------------------------------------------------------------------
579 // "changed" from m_vAdjust
580 //-----------------------------------------------------------------------------
582 static void gtk_window_vscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
584 if (g_blockEventsOnDrag
) return;
587 printf( "OnVScroll change from " );
588 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
589 printf( win->GetClassInfo()->GetClassName() );
593 if (!win
->HasVMT()) return;
595 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
596 int value
= (int)(win
->m_vAdjust
->value
+0.5);
598 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
599 event
.SetEventObject( win
);
600 win
->GetEventHandler()->ProcessEvent( event
);
603 //-----------------------------------------------------------------------------
604 // "changed" from m_hAdjust
605 //-----------------------------------------------------------------------------
607 static void gtk_window_hscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
609 if (g_blockEventsOnDrag
) return;
612 printf( "OnHScroll change from " );
613 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
614 printf( win->GetClassInfo()->GetClassName() );
618 if (!win
->HasVMT()) return;
620 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
621 int value
= (int)(win
->m_hAdjust
->value
+0.5);
623 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
624 event
.SetEventObject( win
);
625 win
->GetEventHandler()->ProcessEvent( event
);
628 //-----------------------------------------------------------------------------
629 // "drop_data_available_event"
630 //-----------------------------------------------------------------------------
632 static void gtk_window_drop_callback( GtkWidget
*widget
, GdkEvent
*event
, wxWindow
*win
)
634 if (!win
->HasVMT()) return;
636 if (win
->GetDropTarget())
640 gdk_window_get_pointer( widget
->window
, &x
, &y
, (GdkModifierType
*) NULL
);
641 win
->GetDropTarget()->Drop( event
, x
, y
);
645 g_free (event->dropdataavailable.data);
646 g_free (event->dropdataavailable.data_type);
650 //-----------------------------------------------------------------------------
651 // "enter_notify_event"
652 //-----------------------------------------------------------------------------
654 static gint
gtk_window_enter_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
656 if (widget
->window
!= gdk_event
->window
) return TRUE
;
657 if (g_blockEventsOnDrag
) return TRUE
;
658 if (!win
->HasVMT()) return TRUE
;
661 gdk_window_set_cursor( widget
->window
, win
->m_cursor
->GetCursor() );
663 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
664 event
.SetEventObject( win
);
665 return win
->GetEventHandler()->ProcessEvent( event
);
668 //-----------------------------------------------------------------------------
669 // "leave_notify_event"
670 //-----------------------------------------------------------------------------
672 static gint
gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
674 if (widget
->window
!= gdk_event
->window
) return TRUE
;
675 if (!win
->HasVMT()) return TRUE
;
676 if (g_blockEventsOnDrag
) return TRUE
;
679 gdk_window_set_cursor( widget
->window
, wxSTANDARD_CURSOR
->GetCursor() );
681 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
682 event
.SetEventObject( win
);
683 return win
->GetEventHandler()->ProcessEvent( event
);
686 //-----------------------------------------------------------------------------
688 //-----------------------------------------------------------------------------
690 IMPLEMENT_DYNAMIC_CLASS(wxWindow
,wxEvtHandler
)
692 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
693 EVT_SIZE(wxWindow::OnSize
)
694 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
695 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
696 EVT_IDLE(wxWindow::OnIdle
)
701 m_widget
= (GtkWidget
*) NULL
;
702 m_wxwindow
= (GtkWidget
*) NULL
;
703 m_parent
= (wxWindow
*) NULL
;
704 m_children
.DeleteContents( FALSE
);
714 m_eventHandler
= this;
715 m_windowValidator
= (wxValidator
*) NULL
;
717 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
718 m_font
= *wxSWISS_FONT
;
720 m_windowName
= "noname";
721 m_constraints
= (wxLayoutConstraints
*) NULL
;
722 m_constraintsInvolvedIn
= (wxList
*) NULL
;
723 m_windowSizer
= (wxSizer
*) NULL
;
724 m_sizerParent
= (wxWindow
*) NULL
;
725 m_autoLayout
= FALSE
;
729 m_hasScrolling
= FALSE
;
730 m_hAdjust
= (GtkAdjustment
*) NULL
;
731 m_vAdjust
= (GtkAdjustment
*) NULL
;
732 m_oldHorizontalPos
= 0.0;
733 m_oldVerticalPos
= 0.0;
736 m_pDropTarget
= (wxDropTarget
*) NULL
;
740 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
741 const wxPoint
&pos
, const wxSize
&size
,
742 long style
, const wxString
&name
)
748 m_cursor
= (wxCursor
*) NULL
;
750 PreCreation( parent
, id
, pos
, size
, style
, name
);
752 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
753 m_hasScrolling
= TRUE
;
755 GtkScrolledWindow
*s_window
;
756 s_window
= GTK_SCROLLED_WINDOW(m_widget
);
758 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
759 scroll_class
->scrollbar_spacing
= 0;
761 gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
763 m_oldHorizontalPos
= 0.0;
764 m_oldVerticalPos
= 0.0;
766 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) );
767 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) );
769 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "value_changed",
770 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
771 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "value_changed",
772 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
774 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "changed",
775 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
776 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "changed",
777 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
779 GtkViewport
*viewport
;
780 viewport
= GTK_VIEWPORT(s_window
->viewport
);
782 if (m_windowStyle
& wxRAISED_BORDER
)
784 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
786 else if (m_windowStyle
& wxSUNKEN_BORDER
)
788 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
792 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
795 m_wxwindow
= gtk_myfixed_new();
797 if (m_wxwindow
) GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
799 if (m_windowStyle
& wxTAB_TRAVERSAL
== wxTAB_TRAVERSAL
)
800 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
802 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
804 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
806 // shut the viewport up
807 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
808 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
810 // I _really_ don't want scrollbars in the beginning
811 m_vAdjust
->lower
= 0.0;
812 m_vAdjust
->upper
= 1.0;
813 m_vAdjust
->value
= 0.0;
814 m_vAdjust
->step_increment
= 1.0;
815 m_vAdjust
->page_increment
= 1.0;
816 m_vAdjust
->page_size
= 5.0;
817 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
818 m_hAdjust
->lower
= 0.0;
819 m_hAdjust
->upper
= 1.0;
820 m_hAdjust
->value
= 0.0;
821 m_hAdjust
->step_increment
= 1.0;
822 m_hAdjust
->page_increment
= 1.0;
823 m_hAdjust
->page_size
= 5.0;
824 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
826 gtk_widget_show( m_wxwindow
);
835 wxWindow::~wxWindow(void)
839 if (m_pDropTarget
) delete m_pDropTarget
;
841 if (m_parent
) m_parent
->RemoveChild( this );
842 if (m_widget
) Show( FALSE
);
846 if (m_wxwindow
) gtk_widget_destroy( m_wxwindow
);
848 if (m_widget
) gtk_widget_destroy( m_widget
);
852 DeleteRelatedConstraints();
855 // This removes any dangling pointers to this window
856 // in other windows' constraintsInvolvedIn lists.
857 UnsetConstraints(m_constraints
);
858 delete m_constraints
;
859 m_constraints
= (wxLayoutConstraints
*) NULL
;
863 delete m_windowSizer
;
864 m_windowSizer
= (wxSizer
*) NULL
;
866 // If this is a child of a sizer, remove self from parent
867 if (m_sizerParent
) m_sizerParent
->RemoveChild((wxWindow
*)this);
869 // Just in case the window has been Closed, but
870 // we're then deleting immediately: don't leave
871 // dangling pointers.
872 wxPendingDelete
.DeleteObject(this);
874 // Just in case we've loaded a top-level window via
875 // wxWindow::LoadNativeDialog but we weren't a dialog
877 wxTopLevelWindows
.DeleteObject(this);
879 if (m_windowValidator
) delete m_windowValidator
;
882 void wxWindow::PreCreation( wxWindow
*parent
, wxWindowID id
,
883 const wxPoint
&pos
, const wxSize
&size
,
884 long style
, const wxString
&name
)
886 if (m_needParent
&& (parent
== NULL
))
887 wxFatalError( "Need complete parent.", name
);
889 m_widget
= (GtkWidget
*) NULL
;
892 m_children
.DeleteContents( FALSE
);
896 if (m_width
== -1) m_width
= 20;
898 if (m_height
== -1) m_height
= 20;
904 m_eventHandler
= this;
907 if (m_cursor
== NULL
)
908 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
909 m_font
= *wxSWISS_FONT
;
910 m_backgroundColour
= wxWHITE
;
911 m_foregroundColour
= wxBLACK
;
912 m_windowStyle
= style
;
914 m_constraints
= (wxLayoutConstraints
*) NULL
;
915 m_constraintsInvolvedIn
= (wxList
*) NULL
;
916 m_windowSizer
= (wxSizer
*) NULL
;
917 m_sizerParent
= (wxWindow
*) NULL
;
918 m_autoLayout
= FALSE
;
919 m_pDropTarget
= (wxDropTarget
*) NULL
;
921 m_windowValidator
= (wxValidator
*) NULL
;
924 void wxWindow::PostCreation(void)
926 if (m_parent
) m_parent
->AddChild( this );
928 // GtkStyle *style = m_widget->style;
929 // style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
931 GtkWidget
*connect_widget
= GetConnectWidget();
935 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
936 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
938 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
939 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
942 gtk_signal_connect( GTK_OBJECT(connect_widget
), "key_press_event",
943 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
945 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_press_event",
946 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
948 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_release_event",
949 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
951 gtk_signal_connect( GTK_OBJECT(connect_widget
), "motion_notify_event",
952 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
954 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_in_event",
955 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
957 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_out_event",
958 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
960 // Only for cursor handling
962 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter_notify_event",
963 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
965 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave_notify_event",
966 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
970 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "enter_notify_event",
971 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
973 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "leave_notify_event",
974 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
977 if (m_widget
&& m_parent
) gtk_widget_realize( m_widget
);
981 gtk_widget_realize( m_wxwindow
);
982 gdk_gc_set_exposures( m_wxwindow
->style
->fg_gc
[0], TRUE
);
985 SetCursor( wxSTANDARD_CURSOR
);
990 bool wxWindow::HasVMT(void)
995 bool wxWindow::Close( bool force
)
997 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
998 event
.SetEventObject(this);
999 event
.SetForce(force
);
1001 return GetEventHandler()->ProcessEvent(event
);
1004 bool wxWindow::Destroy(void)
1011 bool wxWindow::DestroyChildren(void)
1016 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
)
1019 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
)
1022 if (GetChildren()->Member(child
)) delete node
;
1029 void wxWindow::PrepareDC( wxDC
&WXUNUSED(dc
) )
1031 // are we to set fonts here ?
1034 void wxWindow::ImplementSetSize(void)
1036 if ((m_minWidth
!= -1) && (m_width
< m_minWidth
)) m_width
= m_minWidth
;
1037 if ((m_minHeight
!= -1) && (m_height
< m_minHeight
)) m_height
= m_minHeight
;
1038 if ((m_maxWidth
!= -1) && (m_width
> m_maxWidth
)) m_width
= m_minWidth
;
1039 if ((m_maxHeight
!= -1) && (m_height
> m_maxHeight
)) m_height
= m_minHeight
;
1040 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1043 void wxWindow::ImplementSetPosition(void)
1045 if (IS_KIND_OF(this,wxFrame
) || IS_KIND_OF(this,wxDialog
))
1047 if ((m_x
!= -1) || (m_y
!= -1))
1048 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1054 wxFAIL_MSG( "wxWindow::SetSize error.\n" );
1058 if ((m_parent
) && (m_parent
->m_wxwindow
))
1059 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1061 // Don't do anything for children of wxNotebook and wxMDIChildFrame
1064 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1066 if (m_resizing
) return; // I don't like recursions
1074 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1076 if (newX
== -1) newX
= m_x
;
1077 if (newY
== -1) newY
= m_y
;
1078 if (newW
== -1) newW
= m_width
;
1079 if (newH
== -1) newH
= m_height
;
1082 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1084 if (newW
== -1) newW
= 80;
1087 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1089 if (newH
== -1) newH
= 26;
1092 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1096 ImplementSetPosition();
1098 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1106 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1107 event
.SetEventObject( this );
1108 ProcessEvent( event
);
1113 void wxWindow::SetSize( int width
, int height
)
1115 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1118 void wxWindow::Move( int x
, int y
)
1120 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1123 void wxWindow::GetSize( int *width
, int *height
) const
1125 if (width
) (*width
) = m_width
;
1126 if (height
) (*height
) = m_height
;
1129 void wxWindow::SetClientSize( int width
, int height
)
1133 SetSize( width
, height
);
1140 if (!m_hasScrolling
)
1143 do we have sunken dialogs ?
1145 GtkStyleClass *window_class = m_wxwindow->style->klass;
1147 dw += 2 * window_class->xthickness;
1148 dh += 2 * window_class->ythickness;
1153 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1154 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1156 GtkWidget
*viewport
= scroll_window
->viewport
;
1157 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1159 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1160 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1162 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1163 (m_windowStyle
& wxSUNKEN_BORDER
))
1165 dw
+= 2 * viewport_class
->xthickness
;
1166 dh
+= 2 * viewport_class
->ythickness
;
1169 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1171 dw
+= vscrollbar
->allocation
.width
;
1172 dw
+= scroll_class
->scrollbar_spacing
;
1175 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1177 dh
+= hscrollbar
->allocation
.height
;
1178 dw
+= scroll_class
->scrollbar_spacing
;
1182 SetSize( width
+dw
, height
+dh
);
1186 void wxWindow::GetClientSize( int *width
, int *height
) const
1190 if (width
) (*width
) = m_width
;
1191 if (height
) (*height
) = m_height
;
1198 if (!m_hasScrolling
)
1201 do we have sunken dialogs ?
1203 GtkStyleClass *window_class = m_wxwindow->style->klass;
1205 dw += 2 * window_class->xthickness;
1206 dh += 2 * window_class->ythickness;
1211 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1212 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1214 GtkWidget
*viewport
= scroll_window
->viewport
;
1215 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1217 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1218 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1220 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1221 (m_windowStyle
& wxSUNKEN_BORDER
))
1223 dw
+= 2 * viewport_class
->xthickness
;
1224 dh
+= 2 * viewport_class
->ythickness
;
1227 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1229 // dw += vscrollbar->allocation.width;
1230 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1231 dw
+= scroll_class
->scrollbar_spacing
;
1234 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1236 // dh += hscrollbar->allocation.height;
1238 dh
+= scroll_class
->scrollbar_spacing
;
1242 if (width
) (*width
) = m_width
- dw
;
1243 if (height
) (*height
) = m_height
- dh
;
1247 void wxWindow::GetPosition( int *x
, int *y
) const
1253 void wxWindow::ClientToScreen( int *x
, int *y
)
1255 GdkWindow
*source
= (GdkWindow
*) NULL
;
1257 source
= m_wxwindow
->window
;
1259 source
= m_widget
->window
;
1263 gdk_window_get_origin( source
, &org_x
, &org_y
);
1267 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1269 org_x
+= m_widget
->allocation
.x
;
1270 org_y
+= m_widget
->allocation
.y
;
1278 void wxWindow::ScreenToClient( int *x
, int *y
)
1280 GdkWindow
*source
= (GdkWindow
*) NULL
;
1282 source
= m_wxwindow
->window
;
1284 source
= m_widget
->window
;
1288 gdk_window_get_origin( source
, &org_x
, &org_y
);
1292 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1294 org_x
+= m_widget
->allocation
.x
;
1295 org_y
+= m_widget
->allocation
.y
;
1303 void wxWindow::Centre( int direction
)
1305 if (IS_KIND_OF(this,wxDialog
) || IS_KIND_OF(this,wxFrame
))
1307 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
1308 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
1309 ImplementSetPosition();
1317 m_parent
->GetSize( &p_w
, &p_h
);
1318 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (p_w
- m_width
) / 2;
1319 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (p_h
- m_height
) / 2;
1320 ImplementSetPosition();
1325 void wxWindow::Fit(void)
1329 wxNode
*node
= GetChildren()->First();
1332 wxWindow
*win
= (wxWindow
*)node
->Data();
1334 win
->GetPosition(&wx
, &wy
);
1335 win
->GetSize(&ww
, &wh
);
1336 if ( wx
+ ww
> maxX
)
1338 if ( wy
+ wh
> maxY
)
1341 node
= node
->Next();
1343 SetClientSize(maxX
+ 5, maxY
+ 10);
1346 void wxWindow::SetSizeHints( int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
) )
1354 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1356 //if (GetAutoLayout()) Layout();
1359 bool wxWindow::Show( bool show
)
1362 gtk_widget_show( m_widget
);
1364 gtk_widget_hide( m_widget
);
1369 void wxWindow::Enable( bool enable
)
1371 m_isEnabled
= enable
;
1372 gtk_widget_set_sensitive( m_widget
, enable
);
1373 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1376 int wxWindow::GetCharHeight(void) const
1378 GdkFont
*font
= m_font
.GetInternalFont( 1.0 );
1379 return font
->ascent
+ font
->descent
;
1382 int wxWindow::GetCharWidth(void) const
1384 GdkFont
*font
= m_font
.GetInternalFont( 1.0 );
1385 return gdk_string_width( font
, "H" );
1388 void wxWindow::GetTextExtent( const wxString
& string
, int *x
, int *y
,
1389 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool WXUNUSED(use16
) ) const
1391 wxFont fontToUse
= m_font
;
1392 if (theFont
) fontToUse
= *theFont
;
1394 GdkFont
*font
= fontToUse
.GetInternalFont( 1.0 );
1395 if (x
) (*y
) = gdk_string_width( font
, string
);
1396 if (y
) (*y
) = font
->ascent
+ font
->descent
;
1397 if (descent
) (*descent
) = font
->descent
;
1398 if (externalLeading
) (*externalLeading
) = 0; // ??
1401 void wxWindow::MakeModal( bool modal
)
1404 // Disable all other windows
1405 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1407 wxNode
*node
= wxTopLevelWindows
.First();
1410 wxWindow
*win
= (wxWindow
*)node
->Data();
1412 win
->Enable(!modal
);
1414 node
= node
->Next();
1419 void wxWindow::SetFocus(void)
1421 GtkWidget
*connect_widget
= GetConnectWidget();
1424 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1426 gtk_widget_grab_focus (connect_widget
);
1431 bool wxWindow::OnClose(void)
1436 void wxWindow::AddChild( wxWindow
*child
)
1438 // Addchild is (often) called before the program
1439 // has left the parents constructor so that no
1440 // virtual tables work yet. The approach below
1441 // practically imitates virtual tables, i.e. it
1442 // implements a different AddChild() behaviour
1443 // for wxFrame, wxDialog, wxWindow and
1444 // wxMDIParentFrame.
1446 // wxFrame and wxDialog as children aren't placed into the parents
1448 if (( IS_KIND_OF(child
,wxFrame
) || IS_KIND_OF(child
,wxDialog
) ) &&
1449 (!IS_KIND_OF(child
,wxMDIChildFrame
)))
1451 m_children
.Append( child
);
1453 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1454 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1459 // In the case of an wxMDIChildFrame descendant, we use the
1460 // client windows's AddChild()
1462 if (IS_KIND_OF(this,wxMDIParentFrame
))
1464 if (IS_KIND_OF(child
,wxMDIChildFrame
))
1466 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1469 client
->AddChild( child
);
1475 // wxNotebook is very special, so it has a private AddChild()
1477 if (IS_KIND_OF(this,wxNotebook
))
1479 wxNotebook
*tab
= (wxNotebook
*)this;
1480 tab
->AddChild( child
);
1484 // wxFrame has a private AddChild
1486 if (IS_KIND_OF(this,wxFrame
) && !IS_KIND_OF(this,wxMDIChildFrame
))
1488 wxFrame
*frame
= (wxFrame
*)this;
1489 frame
->AddChild( child
);
1495 m_children
.Append( child
);
1496 if (m_wxwindow
) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
,
1497 child
->m_x
, child
->m_y
);
1499 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1502 wxList
*wxWindow::GetChildren(void)
1504 return (&m_children
);
1507 void wxWindow::RemoveChild( wxWindow
*child
)
1510 GetChildren()->DeleteObject( child
);
1511 child
->m_parent
= (wxWindow
*) NULL
;
1514 void wxWindow::SetReturnCode( int retCode
)
1516 m_retCode
= retCode
;
1519 int wxWindow::GetReturnCode(void)
1524 void wxWindow::Raise(void)
1526 if (m_widget
) gdk_window_raise( m_widget
->window
);
1529 void wxWindow::Lower(void)
1531 if (m_widget
) gdk_window_lower( m_widget
->window
);
1534 wxEvtHandler
*wxWindow::GetEventHandler(void)
1536 return m_eventHandler
;
1539 void wxWindow::SetEventHandler( wxEvtHandler
*handler
)
1541 m_eventHandler
= handler
;
1544 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
1546 handler
->SetNextHandler(GetEventHandler());
1547 SetEventHandler(handler
);
1550 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
1552 if ( GetEventHandler() )
1554 wxEvtHandler
*handlerA
= GetEventHandler();
1555 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
1556 handlerA
->SetNextHandler((wxEvtHandler
*) NULL
);
1557 SetEventHandler(handlerB
);
1558 if ( deleteHandler
)
1561 return (wxEvtHandler
*) NULL
;
1567 return (wxEvtHandler
*) NULL
;
1570 wxValidator
*wxWindow::GetValidator(void)
1572 return m_windowValidator
;
1575 void wxWindow::SetValidator( const wxValidator
& validator
)
1577 if (m_windowValidator
) delete m_windowValidator
;
1578 m_windowValidator
= validator
.Clone();
1579 if (m_windowValidator
) m_windowValidator
->SetWindow(this);
1582 bool wxWindow::IsBeingDeleted(void)
1587 void wxWindow::SetId( wxWindowID id
)
1592 wxWindowID
wxWindow::GetId(void)
1597 void wxWindow::SetCursor( const wxCursor
&cursor
)
1599 wxASSERT(m_cursor
!= NULL
);
1601 if (m_cursor
!= NULL
)
1602 if (*m_cursor
== cursor
)
1604 (*m_cursor
) = cursor
;
1605 if (m_widget
->window
)
1606 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1607 if (m_wxwindow
&& m_wxwindow
->window
)
1608 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1611 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1613 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1616 gdk_window_clear_area( m_wxwindow
->window
,
1630 GetClientSize( &w
, &h
);
1632 GdkRectangle gdk_rect
;
1636 gdk_rect
.height
= h
;
1637 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1642 GdkRectangle gdk_rect
;
1643 gdk_rect
.x
= rect
->x
;
1644 gdk_rect
.y
= rect
->y
;
1645 gdk_rect
.width
= rect
->width
;
1646 gdk_rect
.height
= rect
->height
;
1649 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1651 gtk_widget_draw( m_widget
, &gdk_rect
);
1655 bool wxWindow::IsExposed( long x
, long y
)
1657 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1660 bool wxWindow::IsExposed( long x
, long y
, long width
, long height
)
1662 return (m_updateRegion
.Contains( x
, y
, width
, height
) != wxOutRegion
);
1665 void wxWindow::Clear(void)
1667 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1670 wxColour
wxWindow::GetBackgroundColour(void) const
1672 return m_backgroundColour
;
1675 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1677 m_backgroundColour
= colour
;
1680 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1681 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1682 gdk_window_clear( m_wxwindow
->window
);
1687 wxColour
wxWindow::GetForegroundColour(void) const
1689 return m_foregroundColour
;
1692 void wxWindow::SetForegroundColour( const wxColour
&colour
)
1694 m_foregroundColour
= colour
;
1697 bool wxWindow::Validate(void)
1699 wxNode
*node
= GetChildren()->First();
1702 wxWindow
*child
= (wxWindow
*)node
->Data();
1703 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1705 node
= node
->Next();
1710 bool wxWindow::TransferDataToWindow(void)
1712 wxNode
*node
= GetChildren()->First();
1715 wxWindow
*child
= (wxWindow
*)node
->Data();
1716 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1717 !child
->GetValidator()->TransferToWindow() )
1719 wxMessageBox( _("Application Error"), _("Could not transfer data to window"), wxOK
|wxICON_EXCLAMATION
);
1722 node
= node
->Next();
1727 bool wxWindow::TransferDataFromWindow(void)
1729 wxNode
*node
= GetChildren()->First();
1732 wxWindow
*child
= (wxWindow
*)node
->Data();
1733 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1735 node
= node
->Next();
1740 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1742 TransferDataToWindow();
1745 void wxWindow::InitDialog(void)
1747 wxInitDialogEvent
event(GetId());
1748 event
.SetEventObject( this );
1749 GetEventHandler()->ProcessEvent(event
);
1752 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
1754 menu
->SetInvokingWindow( win
);
1755 wxNode
*node
= menu
->m_items
.First();
1758 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
1759 if (menuitem
->IsSubMenu())
1760 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1761 node
= node
->Next();
1765 bool wxWindow::PopupMenu( wxMenu
*menu
, int WXUNUSED(x
), int WXUNUSED(y
) )
1767 SetInvokingWindow( menu
, this );
1768 gtk_menu_popup( GTK_MENU(menu
->m_menu
), (GtkWidget
*) NULL
, (GtkWidget
*) NULL
, (GtkMenuPositionFunc
) NULL
, NULL
, 0, 0 );
1772 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1774 GtkWidget
*dnd_widget
= GetConnectWidget();
1778 gtk_signal_disconnect_by_func( GTK_OBJECT(dnd_widget
),
1779 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1781 m_pDropTarget
->UnregisterWidget( dnd_widget
);
1782 delete m_pDropTarget
;
1784 m_pDropTarget
= dropTarget
;
1787 m_pDropTarget
->RegisterWidget( dnd_widget
);
1789 gtk_signal_connect( GTK_OBJECT(dnd_widget
), "drop_data_available_event",
1790 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1794 wxDropTarget
*wxWindow::GetDropTarget() const
1796 return m_pDropTarget
;
1799 GtkWidget
* wxWindow::GetConnectWidget(void)
1801 GtkWidget
*connect_widget
= m_widget
;
1802 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1804 return connect_widget
;
1807 bool wxWindow::IsOwnGtkWindow( GdkWindow
*window
)
1809 if (m_wxwindow
) return (window
== m_wxwindow
->window
);
1810 return (window
== m_widget
->window
);
1813 void wxWindow::SetFont( const wxFont
&font
)
1818 copy old style values to new one
1819 set font in new style
1820 -> takes to many resources
1822 GtkStyle *style = gtk_style_new();
1827 wxFont
*wxWindow::GetFont(void)
1832 void wxWindow::SetWindowStyleFlag( long flag
)
1834 m_windowStyle
= flag
;
1837 long wxWindow::GetWindowStyleFlag(void) const
1839 return m_windowStyle
;
1842 void wxWindow::CaptureMouse(void)
1844 GtkWidget
*connect_widget
= GetConnectWidget();
1845 gtk_grab_add( connect_widget
);
1846 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1848 (GDK_BUTTON_PRESS_MASK
|
1849 GDK_BUTTON_RELEASE_MASK
|
1850 GDK_POINTER_MOTION_MASK
),
1851 (GdkWindow
*) NULL
, (GdkCursor
*) NULL
, GDK_CURRENT_TIME
);
1854 void wxWindow::ReleaseMouse(void)
1856 GtkWidget
*connect_widget
= GetConnectWidget();
1857 gtk_grab_remove( connect_widget
);
1858 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1861 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1865 wxString
wxWindow::GetTitle(void) const
1867 return (wxString
&)m_windowName
;
1870 wxString
wxWindow::GetLabel(void) const
1875 void wxWindow::SetName( const wxString
&name
)
1877 m_windowName
= name
;
1880 wxString
wxWindow::GetName(void) const
1882 return (wxString
&)m_windowName
;
1885 bool wxWindow::IsShown(void) const
1890 bool wxWindow::IsRetained(void)
1895 wxWindow
*wxWindow::FindWindow( long id
)
1897 if (id
== m_windowId
) return this;
1898 wxNode
*node
= m_children
.First();
1901 wxWindow
*child
= (wxWindow
*)node
->Data();
1902 wxWindow
*res
= child
->FindWindow( id
);
1903 if (res
) return res
;
1904 node
= node
->Next();
1906 return (wxWindow
*) NULL
;
1909 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1911 if (name
== m_windowName
) return this;
1912 wxNode
*node
= m_children
.First();
1915 wxWindow
*child
= (wxWindow
*)node
->Data();
1916 wxWindow
*res
= child
->FindWindow( name
);
1917 if (res
) return res
;
1918 node
= node
->Next();
1920 return (wxWindow
*) NULL
;
1923 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1924 int range
, bool WXUNUSED(refresh
) )
1926 if (!m_wxwindow
) return;
1928 if (orient
== wxHORIZONTAL
)
1930 float fpos
= (float)pos
;
1931 m_oldHorizontalPos
= fpos
;
1932 float frange
= (float)range
;
1933 float fthumb
= (float)thumbVisible
;
1935 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1936 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1937 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1940 m_hAdjust
->lower
= 0.0;
1941 m_hAdjust
->upper
= frange
;
1942 m_hAdjust
->value
= fpos
;
1943 m_hAdjust
->step_increment
= 1.0;
1944 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1945 m_hAdjust
->page_size
= fthumb
;
1949 float fpos
= (float)pos
;
1950 m_oldVerticalPos
= fpos
;
1951 float frange
= (float)range
;
1952 float fthumb
= (float)thumbVisible
;
1954 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1955 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1956 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1959 m_vAdjust
->lower
= 0.0;
1960 m_vAdjust
->upper
= frange
;
1961 m_vAdjust
->value
= fpos
;
1962 m_vAdjust
->step_increment
= 1.0;
1963 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1964 m_vAdjust
->page_size
= fthumb
;
1967 if (m_wxwindow
->window
)
1969 if (orient
== wxHORIZONTAL
)
1970 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
1972 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
1974 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1978 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
1980 if (!m_wxwindow
) return;
1982 if (orient
== wxHORIZONTAL
)
1984 float fpos
= (float)pos
;
1985 m_oldHorizontalPos
= fpos
;
1987 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
1988 m_hAdjust
->value
= fpos
;
1992 float fpos
= (float)pos
;
1993 m_oldVerticalPos
= fpos
;
1994 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
1995 m_vAdjust
->value
= fpos
;
1998 if (m_wxwindow
->window
)
2000 if (orient
== wxHORIZONTAL
)
2001 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
2003 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
2007 int wxWindow::GetScrollThumb( int orient
) const
2009 if (!m_wxwindow
) return 0;
2011 if (orient
== wxHORIZONTAL
)
2012 return (int)(m_hAdjust
->page_size
+0.5);
2014 return (int)(m_vAdjust
->page_size
+0.5);
2017 int wxWindow::GetScrollPos( int orient
) const
2019 if (!m_wxwindow
) return 0;
2021 if (orient
== wxHORIZONTAL
)
2022 return (int)(m_hAdjust
->value
+0.5);
2024 return (int)(m_vAdjust
->value
+0.5);
2027 int wxWindow::GetScrollRange( int orient
) const
2029 if (!m_wxwindow
) return 0;
2031 if (orient
== wxHORIZONTAL
)
2032 return (int)(m_hAdjust
->upper
+0.5);
2034 return (int)(m_vAdjust
->upper
+0.5);
2037 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
2039 if (!m_wxwindow
) return;
2042 bool refresh = FALSE;
2044 if ((m_drawingOffsetX == 0) && (m_drawingOffsetY == 0))
2046 m_drawingOffsetX = -16000;
2047 m_drawingOffsetY = -16000;
2052 m_drawingOffsetX += dx;
2053 m_drawingOffsetY += dy;
2056 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
2058 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
2060 if (refresh) Refresh();
2062 The code here is very nifty, but it doesn't work with
2063 overlapping windows...
2068 GetClientSize( &cw
, &ch
);
2070 int w
= cw
- abs(dx
);
2071 int h
= ch
- abs(dy
);
2072 if ((h
< 0) || (w
< 0))
2079 if (dx
< 0) s_x
= -dx
;
2080 if (dy
< 0) s_y
= -dy
;
2083 if (dx
> 0) d_x
= dx
;
2084 if (dy
> 0) d_y
= dy
;
2085 gdk_window_copy_area( m_wxwindow
->window
, m_wxwindow
->style
->fg_gc
[0], d_x
, d_y
,
2086 m_wxwindow
->window
, s_x
, s_y
, w
, h
);
2089 if (dx
< 0) rect
.x
= cw
+dx
; else rect
.x
= 0;
2090 if (dy
< 0) rect
.y
= ch
+dy
; else rect
.y
= 0;
2091 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
2092 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
2094 Refresh( TRUE
, &rect
);
2097 //-------------------------------------------------------------------------------------
2099 //-------------------------------------------------------------------------------------
2101 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
2103 return m_constraints
;
2106 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
2110 UnsetConstraints(m_constraints
);
2111 delete m_constraints
;
2113 m_constraints
= constraints
;
2116 // Make sure other windows know they're part of a 'meaningful relationship'
2117 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
2118 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2119 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
2120 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2121 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
2122 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2123 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
2124 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2125 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
2126 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2127 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
2128 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2129 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
2130 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2131 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
2132 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2138 void wxWindow::SetAutoLayout( bool autoLayout
)
2140 m_autoLayout
= autoLayout
;
2143 bool wxWindow::GetAutoLayout(void) const
2145 return m_autoLayout
;
2148 wxSizer
*wxWindow::GetSizer(void) const
2150 return m_windowSizer
;
2153 void wxWindow::SetSizerParent( wxWindow
*win
)
2155 m_sizerParent
= win
;
2158 wxWindow
*wxWindow::GetSizerParent(void) const
2160 return m_sizerParent
;
2163 // This removes any dangling pointers to this window
2164 // in other windows' constraintsInvolvedIn lists.
2165 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2169 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2170 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2171 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2172 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2173 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2174 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2175 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2176 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2177 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2178 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2179 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2180 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2181 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2182 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2183 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2184 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2188 // Back-pointer to other windows we're involved with, so if we delete
2189 // this window, we must delete any constraints we're involved with.
2190 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2192 if (!m_constraintsInvolvedIn
)
2193 m_constraintsInvolvedIn
= new wxList
;
2194 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2195 m_constraintsInvolvedIn
->Append(otherWin
);
2198 // REMOVE back-pointer to other windows we're involved with.
2199 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2201 if (m_constraintsInvolvedIn
)
2202 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2205 // Reset any constraints that mention this window
2206 void wxWindow::DeleteRelatedConstraints(void)
2208 if (m_constraintsInvolvedIn
)
2210 wxNode
*node
= m_constraintsInvolvedIn
->First();
2213 wxWindow
*win
= (wxWindow
*)node
->Data();
2214 wxNode
*next
= node
->Next();
2215 wxLayoutConstraints
*constr
= win
->GetConstraints();
2217 // Reset any constraints involving this window
2220 constr
->left
.ResetIfWin((wxWindow
*)this);
2221 constr
->top
.ResetIfWin((wxWindow
*)this);
2222 constr
->right
.ResetIfWin((wxWindow
*)this);
2223 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2224 constr
->width
.ResetIfWin((wxWindow
*)this);
2225 constr
->height
.ResetIfWin((wxWindow
*)this);
2226 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2227 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2232 delete m_constraintsInvolvedIn
;
2233 m_constraintsInvolvedIn
= (wxList
*) NULL
;
2237 void wxWindow::SetSizer(wxSizer
*sizer
)
2239 m_windowSizer
= sizer
;
2241 sizer
->SetSizerParent((wxWindow
*)this);
2248 bool wxWindow::Layout(void)
2250 if (GetConstraints())
2253 GetClientSize(&w
, &h
);
2254 GetConstraints()->width
.SetValue(w
);
2255 GetConstraints()->height
.SetValue(h
);
2258 // If top level (one sizer), evaluate the sizer's constraints.
2262 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2263 GetSizer()->LayoutPhase1(&noChanges
);
2264 GetSizer()->LayoutPhase2(&noChanges
);
2265 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2270 // Otherwise, evaluate child constraints
2271 ResetConstraints(); // Mark all constraints as unevaluated
2272 DoPhase(1); // Just one phase need if no sizers involved
2274 SetConstraintSizes(); // Recursively set the real window sizes
2280 // Do a phase of evaluating constraints:
2281 // the default behaviour. wxSizers may do a similar
2282 // thing, but also impose their own 'constraints'
2283 // and order the evaluation differently.
2284 bool wxWindow::LayoutPhase1(int *noChanges
)
2286 wxLayoutConstraints
*constr
= GetConstraints();
2289 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2295 bool wxWindow::LayoutPhase2(int *noChanges
)
2305 // Do a phase of evaluating child constraints
2306 bool wxWindow::DoPhase(int phase
)
2308 int noIterations
= 0;
2309 int maxIterations
= 500;
2313 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2317 wxNode
*node
= GetChildren()->First();
2320 wxWindow
*child
= (wxWindow
*)node
->Data();
2321 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2323 wxLayoutConstraints
*constr
= child
->GetConstraints();
2326 if (succeeded
.Member(child
))
2331 int tempNoChanges
= 0;
2332 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2333 noChanges
+= tempNoChanges
;
2336 succeeded
.Append(child
);
2341 node
= node
->Next();
2348 void wxWindow::ResetConstraints(void)
2350 wxLayoutConstraints
*constr
= GetConstraints();
2353 constr
->left
.SetDone(FALSE
);
2354 constr
->top
.SetDone(FALSE
);
2355 constr
->right
.SetDone(FALSE
);
2356 constr
->bottom
.SetDone(FALSE
);
2357 constr
->width
.SetDone(FALSE
);
2358 constr
->height
.SetDone(FALSE
);
2359 constr
->centreX
.SetDone(FALSE
);
2360 constr
->centreY
.SetDone(FALSE
);
2362 wxNode
*node
= GetChildren()->First();
2365 wxWindow
*win
= (wxWindow
*)node
->Data();
2366 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2367 win
->ResetConstraints();
2368 node
= node
->Next();
2372 // Need to distinguish between setting the 'fake' size for
2373 // windows and sizers, and setting the real values.
2374 void wxWindow::SetConstraintSizes(bool recurse
)
2376 wxLayoutConstraints
*constr
= GetConstraints();
2377 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2378 constr
->width
.GetDone() && constr
->height
.GetDone())
2380 int x
= constr
->left
.GetValue();
2381 int y
= constr
->top
.GetValue();
2382 int w
= constr
->width
.GetValue();
2383 int h
= constr
->height
.GetValue();
2385 // If we don't want to resize this window, just move it...
2386 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2387 (constr
->height
.GetRelationship() != wxAsIs
))
2389 // Calls Layout() recursively. AAAGH. How can we stop that.
2390 // Simply take Layout() out of non-top level OnSizes.
2391 SizerSetSize(x
, y
, w
, h
);
2400 char *windowClass
= this->GetClassInfo()->GetClassName();
2403 if (GetName() == "")
2404 winName
= _("unnamed");
2406 winName
= GetName();
2407 wxDebugMsg(_("Constraint(s) not satisfied for window of type %s, name %s:\n"), (const char *)windowClass
, (const char *)winName
);
2408 if (!constr
->left
.GetDone())
2409 wxDebugMsg(_(" unsatisfied 'left' constraint.\n"));
2410 if (!constr
->right
.GetDone())
2411 wxDebugMsg(_(" unsatisfied 'right' constraint.\n"));
2412 if (!constr
->width
.GetDone())
2413 wxDebugMsg(_(" unsatisfied 'width' constraint.\n"));
2414 if (!constr
->height
.GetDone())
2415 wxDebugMsg(_(" unsatisfied 'height' constraint.\n"));
2416 wxDebugMsg(_("Please check constraints: try adding AsIs() constraints.\n"));
2421 wxNode
*node
= GetChildren()->First();
2424 wxWindow
*win
= (wxWindow
*)node
->Data();
2425 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2426 win
->SetConstraintSizes();
2427 node
= node
->Next();
2432 // This assumes that all sizers are 'on' the same
2433 // window, i.e. the parent of this window.
2434 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2436 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2437 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2441 m_sizerParent
->GetPosition(&xp
, &yp
);
2442 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2447 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2451 TransformSizerToActual(&xx
, &yy
);
2452 SetSize(xx
, yy
, w
, h
);
2455 void wxWindow::SizerMove(int x
, int y
)
2459 TransformSizerToActual(&xx
, &yy
);
2463 // Only set the size/position of the constraint (if any)
2464 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2466 wxLayoutConstraints
*constr
= GetConstraints();
2471 constr
->left
.SetValue(x
);
2472 constr
->left
.SetDone(TRUE
);
2476 constr
->top
.SetValue(y
);
2477 constr
->top
.SetDone(TRUE
);
2481 constr
->width
.SetValue(w
);
2482 constr
->width
.SetDone(TRUE
);
2486 constr
->height
.SetValue(h
);
2487 constr
->height
.SetDone(TRUE
);
2492 void wxWindow::MoveConstraint(int x
, int y
)
2494 wxLayoutConstraints
*constr
= GetConstraints();
2499 constr
->left
.SetValue(x
);
2500 constr
->left
.SetDone(TRUE
);
2504 constr
->top
.SetValue(y
);
2505 constr
->top
.SetDone(TRUE
);
2510 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2512 wxLayoutConstraints
*constr
= GetConstraints();
2515 *w
= constr
->width
.GetValue();
2516 *h
= constr
->height
.GetValue();
2522 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2524 wxLayoutConstraints
*constr
= GetConstraints();
2527 *w
= constr
->width
.GetValue();
2528 *h
= constr
->height
.GetValue();
2531 GetClientSize(w
, h
);
2534 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2536 wxLayoutConstraints
*constr
= GetConstraints();
2539 *x
= constr
->left
.GetValue();
2540 *y
= constr
->top
.GetValue();
2546 bool wxWindow::AcceptsFocus() const
2548 return IsEnabled() && IsShown();
2551 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
) )