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 // GTK callbacks for wxWindows event system
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
50 // expose (of m_wxwindow, not of m_widget)
52 void gtk_window_expose_callback( GtkWidget
*WXUNUSED(widget
), GdkEventExpose
*gdk_event
, wxWindow
*win
)
54 if (!win
->HasVMT()) return;
55 if (g_blockEventsOnDrag
) return;
58 if (IS_KIND_OF(win,wxStatusBar))
60 printf( "OnExpose from " );
61 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
62 printf( win->GetClassInfo()->GetClassName() );
65 printf( "x: %d \n", gdk_event->area.x );
66 printf( "y: %d \n", gdk_event->area.y );
67 printf( "w: %d \n", gdk_event->area.width );
68 printf( "h: %d \n", gdk_event->area.height );
72 win
->m_updateRegion
.Union( gdk_event
->area
.x
,
74 gdk_event
->area
.width
,
75 gdk_event
->area
.height
);
77 if (gdk_event
->count
> 0) return;
79 wxPaintEvent
event( win
->GetId() );
80 event
.SetEventObject( win
);
81 win
->ProcessEvent( event
);
83 win
->m_updateRegion
.Clear();
86 //-----------------------------------------------------------------------------
87 // draw (of m_wxwindow, not of m_widget)
89 void gtk_window_draw_callback( GtkWidget
*WXUNUSED(widget
), GdkRectangle
*rect
, wxWindow
*win
)
91 if (!win
->HasVMT()) return;
92 if (g_blockEventsOnDrag
) return;
95 if (IS_KIND_OF(win,wxStatusBar))
97 printf( "OnDraw from " );
98 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
99 printf( win->GetClassInfo()->GetClassName() );
102 printf( "x: %d \n", rect->x );
103 printf( "y: %d \n", rect->y );
104 printf( "w: %d \n", rect->width );
105 printf( "h: %d \n", rect->height );
109 win
->m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
111 wxPaintEvent
event( win
->GetId() );
112 event
.SetEventObject( win
);
113 win
->ProcessEvent( event
);
115 win
->m_updateRegion
.Clear();
118 //-----------------------------------------------------------------------------
120 // I don't any longer intercept GTK's internal resize events, except
121 // for frames and from within MDI and tabbed windows (client area
122 // size determined internally by GTK, not wxWin).
125 void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
127 if (!win->HasVMT()) return;
128 if (g_blockEventsOnDrag) return;
132 if ((win->m_x == alloc->x) &&
133 (win->m_y == alloc->y) &&
134 (win->m_width == alloc->width) &&
135 (win->m_height == alloc->height))
140 printf( "OnResize from " );
141 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
142 printf( win->GetClassInfo()->GetClassName() );
145 printf( " Old: X: %d Y: %d ", win->m_x, win->m_y );
146 printf( " W: %d H: %d ", win->m_width, win->m_height );
149 printf( " New: X: %d Y: %d ", alloc->x, alloc->y );
150 printf( " W: %d H: %d ", alloc->width, alloc->height );
153 wxSizeEvent event( wxSize( alloc->width, alloc->height), win->GetId() );
154 event.SetEventObject( win );
155 win->ProcessEvent( event );
159 //-----------------------------------------------------------------------------
162 gint
gtk_window_key_press_callback( GtkWidget
*WXUNUSED(widget
), GdkEventKey
*gdk_event
, wxWindow
*win
)
164 if (!win
->HasVMT()) return FALSE
;
165 if (g_blockEventsOnDrag
) return FALSE
;
168 printf( "OnKeyPress from " );
169 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
170 printf( win->GetClassInfo()->GetClassName() );
175 switch (gdk_event
->keyval
)
177 case GDK_BackSpace
: key_code
= WXK_BACK
; break;
178 case GDK_Tab
: key_code
= WXK_TAB
; break;
179 case GDK_Linefeed
: key_code
= WXK_RETURN
; break;
180 case GDK_Clear
: key_code
= WXK_CLEAR
; break;
181 case GDK_Return
: key_code
= WXK_RETURN
; break;
182 case GDK_Pause
: key_code
= WXK_PAUSE
; break;
183 case GDK_Scroll_Lock
: key_code
= WXK_SCROLL
; break;
184 case GDK_Escape
: key_code
= WXK_ESCAPE
; break;
185 case GDK_Delete
: key_code
= WXK_DELETE
; break;
186 case GDK_Home
: key_code
= WXK_HOME
; break;
187 case GDK_Left
: key_code
= WXK_LEFT
; break;
188 case GDK_Up
: key_code
= WXK_UP
; break;
189 case GDK_Right
: key_code
= WXK_RIGHT
; break;
190 case GDK_Down
: key_code
= WXK_DOWN
; break;
191 case GDK_Prior
: key_code
= WXK_PRIOR
; break;
192 // case GDK_Page_Up: key_code = WXK_PAGEUP; break;
193 case GDK_Next
: key_code
= WXK_NEXT
; break;
194 // case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
195 case GDK_End
: key_code
= WXK_END
; break;
196 case GDK_Begin
: key_code
= WXK_HOME
; break;
197 case GDK_Select
: key_code
= WXK_SELECT
; break;
198 case GDK_Print
: key_code
= WXK_PRINT
; break;
199 case GDK_Execute
: key_code
= WXK_EXECUTE
; break;
200 case GDK_Insert
: key_code
= WXK_INSERT
; break;
201 case GDK_Num_Lock
: key_code
= WXK_NUMLOCK
; break;
202 case GDK_KP_Tab
: key_code
= WXK_TAB
; break;
203 case GDK_KP_Enter
: key_code
= WXK_RETURN
; break;
204 case GDK_KP_Home
: key_code
= WXK_HOME
; break;
205 case GDK_KP_Left
: key_code
= WXK_LEFT
; break;
206 case GDK_KP_Up
: key_code
= WXK_UP
; break;
207 case GDK_KP_Right
: key_code
= WXK_RIGHT
; break;
208 case GDK_KP_Down
: key_code
= WXK_DOWN
; break;
209 case GDK_KP_Prior
: key_code
= WXK_PRIOR
; break;
210 // case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
211 case GDK_KP_Next
: key_code
= WXK_NEXT
; break;
212 // case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
213 case GDK_KP_End
: key_code
= WXK_END
; break;
214 case GDK_KP_Begin
: key_code
= WXK_HOME
; break;
215 case GDK_KP_Insert
: key_code
= WXK_INSERT
; break;
216 case GDK_KP_Delete
: key_code
= WXK_DELETE
; break;
217 case GDK_KP_Multiply
: key_code
= WXK_MULTIPLY
; break;
218 case GDK_KP_Add
: key_code
= WXK_ADD
; break;
219 case GDK_KP_Separator
: key_code
= WXK_SEPARATOR
; break;
220 case GDK_KP_Subtract
: key_code
= WXK_SUBTRACT
; break;
221 case GDK_KP_Decimal
: key_code
= WXK_DECIMAL
; break;
222 case GDK_KP_Divide
: key_code
= WXK_DIVIDE
; break;
223 case GDK_KP_0
: key_code
= WXK_NUMPAD0
; break;
224 case GDK_KP_1
: key_code
= WXK_NUMPAD1
; break;
225 case GDK_KP_2
: key_code
= WXK_NUMPAD2
; break;
226 case GDK_KP_3
: key_code
= WXK_NUMPAD3
; break;
227 case GDK_KP_4
: key_code
= WXK_NUMPAD4
; break;
228 case GDK_KP_5
: key_code
= WXK_NUMPAD5
; break;
229 case GDK_KP_6
: key_code
= WXK_NUMPAD6
; break;
230 case GDK_KP_7
: key_code
= WXK_NUMPAD7
; break;
231 case GDK_KP_8
: key_code
= WXK_NUMPAD7
; break;
232 case GDK_KP_9
: key_code
= WXK_NUMPAD9
; break;
233 case GDK_F1
: key_code
= WXK_F1
; break;
234 case GDK_F2
: key_code
= WXK_F2
; break;
235 case GDK_F3
: key_code
= WXK_F3
; break;
236 case GDK_F4
: key_code
= WXK_F4
; break;
237 case GDK_F5
: key_code
= WXK_F5
; break;
238 case GDK_F6
: key_code
= WXK_F6
; break;
239 case GDK_F7
: key_code
= WXK_F7
; break;
240 case GDK_F8
: key_code
= WXK_F8
; break;
241 case GDK_F9
: key_code
= WXK_F9
; break;
242 case GDK_F10
: key_code
= WXK_F10
; break;
243 case GDK_F11
: key_code
= WXK_F11
; break;
244 case GDK_F12
: key_code
= WXK_F12
; break;
247 if ((gdk_event
->keyval
>= 0x20) && (gdk_event
->keyval
<= 0xFF))
248 key_code
= gdk_event
->keyval
;
252 if (!key_code
) return FALSE
;
254 wxKeyEvent
event( wxEVT_CHAR
);
255 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
256 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
257 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
258 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
259 event
.m_keyCode
= key_code
;
262 event
.SetEventObject( win
);
264 bool ret
= win
->ProcessEvent( event
);
266 if (ret) printf( "found.\n") ;
271 //-----------------------------------------------------------------------------
274 gint
gtk_window_button_press_callback( GtkWidget
*WXUNUSED(widget
), GdkEventButton
*gdk_event
, wxWindow
*win
)
276 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return TRUE
;
278 if (g_blockEventsOnDrag
) return TRUE
;
282 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
) && !GTK_WIDGET_HAS_FOCUS (win
->m_wxwindow
) )
284 gtk_widget_grab_focus (win
->m_wxwindow
);
287 printf( "GrabFocus from " );
288 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
289 printf( win->GetClassInfo()->GetClassName() );
296 if (!win
->HasVMT()) return TRUE
;
299 printf( "OnButtonPress from " );
300 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
301 printf( win->GetClassInfo()->GetClassName() );
305 wxEventType event_type
= wxEVT_LEFT_DOWN
;
307 if (gdk_event
->button
== 1)
309 switch (gdk_event
->type
)
311 case GDK_BUTTON_PRESS
: event_type
= wxEVT_LEFT_DOWN
; break;
312 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_LEFT_DCLICK
; break;
316 else if (gdk_event
->button
== 2)
318 switch (gdk_event
->type
)
320 case GDK_BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DOWN
; break;
321 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_MIDDLE_DCLICK
; break;
325 else if (gdk_event
->button
== 3)
327 switch (gdk_event
->type
)
329 case GDK_BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DOWN
; break;
330 case GDK_2BUTTON_PRESS
: event_type
= wxEVT_RIGHT_DCLICK
; break;
335 wxMouseEvent
event( event_type
);
336 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
337 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
338 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
339 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
340 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
341 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
342 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
344 event
.m_x
= (long)gdk_event
->x
;
345 event
.m_y
= (long)gdk_event
->y
;
346 event
.SetEventObject( win
);
348 win
->ProcessEvent( event
);
353 //-----------------------------------------------------------------------------
356 gint
gtk_window_button_release_callback( GtkWidget
*WXUNUSED(widget
), GdkEventButton
*gdk_event
, wxWindow
*win
)
358 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return TRUE
;
359 if (g_blockEventsOnDrag
) return TRUE
;
361 if (!win
->HasVMT()) return TRUE
;
364 printf( "OnButtonRelease from " );
365 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
366 printf( win->GetClassInfo()->GetClassName() );
370 wxEventType event_type
= wxEVT_NULL
;
372 switch (gdk_event
->button
)
374 case 1: event_type
= wxEVT_LEFT_UP
; break;
375 case 2: event_type
= wxEVT_MIDDLE_UP
; break;
376 case 3: event_type
= wxEVT_RIGHT_UP
; break;
379 wxMouseEvent
event( event_type
);
380 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
381 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
382 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
383 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
384 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
385 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
386 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
387 event
.m_x
= (long)gdk_event
->x
;
388 event
.m_y
= (long)gdk_event
->y
;
389 event
.SetEventObject( win
);
391 win
->ProcessEvent( event
);
396 //-----------------------------------------------------------------------------
399 gint
gtk_window_motion_notify_callback( GtkWidget
*WXUNUSED(widget
), GdkEventMotion
*gdk_event
, wxWindow
*win
)
401 if (!win
->IsOwnGtkWindow( gdk_event
->window
)) return TRUE
;
402 if (g_blockEventsOnDrag
) return TRUE
;
404 if (!win
->HasVMT()) return TRUE
;
407 printf( "OnMotion from " );
408 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
409 printf( win->GetClassInfo()->GetClassName() );
413 wxMouseEvent
event( wxEVT_MOTION
);
414 event
.m_shiftDown
= (gdk_event
->state
& GDK_SHIFT_MASK
);
415 event
.m_controlDown
= (gdk_event
->state
& GDK_CONTROL_MASK
);
416 event
.m_altDown
= (gdk_event
->state
& GDK_MOD1_MASK
);
417 event
.m_metaDown
= (gdk_event
->state
& GDK_MOD2_MASK
);
418 event
.m_leftDown
= (gdk_event
->state
& GDK_BUTTON1_MASK
);
419 event
.m_middleDown
= (gdk_event
->state
& GDK_BUTTON2_MASK
);
420 event
.m_rightDown
= (gdk_event
->state
& GDK_BUTTON3_MASK
);
422 event
.m_x
= (long)gdk_event
->x
;
423 event
.m_y
= (long)gdk_event
->y
;
424 event
.SetEventObject( win
);
426 win
->ProcessEvent( event
);
431 //-----------------------------------------------------------------------------
434 gint
gtk_window_focus_in_callback( GtkWidget
*WXUNUSED(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
);
464 win
->ProcessEvent( event
);
469 //-----------------------------------------------------------------------------
472 gint
gtk_window_focus_out_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
474 if (g_blockEventsOnDrag
) return TRUE
;
477 if (GTK_WIDGET_CAN_FOCUS(win
->m_wxwindow
))
478 GTK_WIDGET_UNSET_FLAGS (win
->m_wxwindow
, GTK_HAS_FOCUS
);
481 if (!win
->HasVMT()) return TRUE
;
484 printf( "OnKillFocus from " );
485 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
486 printf( win->GetClassInfo()->GetClassName() );
490 wxFocusEvent
event( wxEVT_KILL_FOCUS
, win
->GetId() );
491 event
.SetEventObject( win
);
492 win
->ProcessEvent( event
);
497 //-----------------------------------------------------------------------------
500 void gtk_window_vscroll_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
502 if (g_blockEventsOnDrag
) return;
505 printf( "OnVScroll from " );
506 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
507 printf( win->GetClassInfo()->GetClassName() );
511 if (!win
->HasVMT()) return;
513 float diff
= win
->m_vAdjust
->value
- win
->m_oldVerticalPos
;
514 if (fabs(diff
) < 0.2) return;
517 int i = (int)(win->m_oldVerticalPos+0.5);
518 printf( "Old value: %d.\n", i );
519 i = (int)(win->m_vAdjust->value+0.5);
520 printf( "Sending new value: %d.\n", i );
523 wxEventType command
= wxEVT_NULL
;
525 float line_step
= win
->m_vAdjust
->step_increment
;
526 float page_step
= win
->m_vAdjust
->page_increment
;
528 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
529 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
530 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
531 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
532 else command
= wxEVT_SCROLL_THUMBTRACK
;
534 int value
= (int)(win
->m_vAdjust
->value
+0.5);
536 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
537 event
.SetEventObject( win
);
538 win
->ProcessEvent( event
);
541 //-----------------------------------------------------------------------------
544 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;
561 int i = (int)(win->m_oldHorizontalPos+0.5);
562 printf( "Old value: %d.\n", i );
563 i = (int)(win->m_hAdjust->value+0.5);
564 printf( "Sending new value: %d.\n", i );
567 wxEventType command
= wxEVT_NULL
;
569 float line_step
= win
->m_hAdjust
->step_increment
;
570 float page_step
= win
->m_hAdjust
->page_increment
;
572 if (fabs(diff
-line_step
) < 0.2) command
= wxEVT_SCROLL_LINEDOWN
;
573 else if (fabs(diff
+line_step
) < 0.2) command
= wxEVT_SCROLL_LINEUP
;
574 else if (fabs(diff
-page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEDOWN
;
575 else if (fabs(diff
+page_step
) < 0.2) command
= wxEVT_SCROLL_PAGEUP
;
576 else command
= wxEVT_SCROLL_THUMBTRACK
;
578 int value
= (int)(win
->m_hAdjust
->value
+0.5);
580 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
581 event
.SetEventObject( win
);
582 win
->ProcessEvent( event
);
585 //-----------------------------------------------------------------------------
586 // vertical scroll change
588 void gtk_window_vscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
590 if (g_blockEventsOnDrag
) return;
593 printf( "OnVScroll change from " );
594 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
595 printf( win->GetClassInfo()->GetClassName() );
599 if (!win
->HasVMT()) return;
601 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
602 int value
= (int)(win
->m_vAdjust
->value
+0.5);
604 wxScrollEvent
event( command
, win
->GetId(), value
, wxVERTICAL
);
605 event
.SetEventObject( win
);
606 win
->ProcessEvent( event
);
609 //-----------------------------------------------------------------------------
610 // horizontal scroll change
612 void gtk_window_hscroll_change_callback( GtkWidget
*WXUNUSED(widget
), wxWindow
*win
)
614 if (g_blockEventsOnDrag
) return;
617 printf( "OnHScroll change from " );
618 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
619 printf( win->GetClassInfo()->GetClassName() );
623 if (!win
->HasVMT()) return;
625 wxEventType command
= wxEVT_SCROLL_THUMBTRACK
;
626 int value
= (int)(win
->m_hAdjust
->value
+0.5);
628 wxScrollEvent
event( command
, win
->GetId(), value
, wxHORIZONTAL
);
629 event
.SetEventObject( win
);
630 win
->ProcessEvent( event
);
633 //-----------------------------------------------------------------------------
636 void gtk_window_drop_callback( GtkWidget
*widget
, GdkEvent
*event
, wxWindow
*win
)
638 if (!win
->HasVMT()) return;
640 if (win
->GetDropTarget())
644 gdk_window_get_pointer( widget
->window
, &x
, &y
, NULL
);
645 win
->GetDropTarget()->Drop( event
, x
, y
);
649 g_free (event->dropdataavailable.data);
650 g_free (event->dropdataavailable.data_type);
654 //-----------------------------------------------------------------------------
657 bool gtk_window_destroy_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxWindow
*win
)
659 printf( "OnDestroy from " );
660 if (win
->GetClassInfo() && win
->GetClassInfo()->GetClassName())
661 printf( win
->GetClassInfo()->GetClassName() );
663 printf( "Goodbye.\n" );
664 printf( " Robert Roebling.\n" );
669 //-----------------------------------------------------------------------------
672 bool gtk_window_enter_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
674 if (widget
->window
!= gdk_event
->window
) return TRUE
;
675 if (g_blockEventsOnDrag
) return TRUE
;
676 if (!win
->HasVMT()) return TRUE
;
679 gdk_window_set_cursor( widget
->window
, win
->m_cursor
->GetCursor() );
681 wxMouseEvent
event( wxEVT_ENTER_WINDOW
);
682 event
.SetEventObject( win
);
683 return win
->ProcessEvent( event
);
686 //-----------------------------------------------------------------------------
689 bool gtk_window_leave_callback( GtkWidget
*widget
, GdkEventCrossing
*gdk_event
, wxWindow
*win
)
691 if (widget
->window
!= gdk_event
->window
) return TRUE
;
692 if (!win
->HasVMT()) return TRUE
;
693 if (g_blockEventsOnDrag
) return TRUE
;
696 gdk_window_set_cursor( widget
->window
, wxSTANDARD_CURSOR
->GetCursor() );
698 wxMouseEvent
event( wxEVT_LEAVE_WINDOW
);
699 event
.SetEventObject( win
);
700 return win
->ProcessEvent( event
);
703 //-----------------------------------------------------------------------------
704 // wxWindow implementation
705 //-----------------------------------------------------------------------------
707 IMPLEMENT_DYNAMIC_CLASS(wxWindow
,wxEvtHandler
)
709 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
710 EVT_SIZE(wxWindow::OnSize
)
711 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
712 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
713 EVT_IDLE(wxWindow::OnIdle
)
721 m_children
.DeleteContents( FALSE
);
727 m_eventHandler
= this;
728 m_windowValidator
= NULL
;
730 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
731 m_font
= *wxSWISS_FONT
;
733 m_windowName
= "noname";
734 m_constraints
= NULL
;
735 m_constraintsInvolvedIn
= NULL
;
736 m_windowSizer
= NULL
;
737 m_sizerParent
= NULL
;
738 m_autoLayout
= FALSE
;
742 m_hasScrolling
= FALSE
;
745 m_oldHorizontalPos
= 0.0;
746 m_oldVerticalPos
= 0.0;
749 m_drawingOffsetX
= 0;
750 m_drawingOffsetY
= 0;
751 m_pDropTarget
= NULL
;
755 bool wxWindow::Create( wxWindow
*parent
, wxWindowID id
,
756 const wxPoint
&pos
, const wxSize
&size
,
757 long style
, const wxString
&name
)
765 PreCreation( parent
, id
, pos
, size
, style
, name
);
767 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
768 m_hasScrolling
= TRUE
;
770 GtkScrolledWindow
*s_window
;
771 s_window
= GTK_SCROLLED_WINDOW(m_widget
);
773 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
774 scroll_class
->scrollbar_spacing
= 0;
776 gtk_scrolled_window_set_policy( s_window
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
778 m_oldHorizontalPos
= 0.0;
779 m_oldVerticalPos
= 0.0;
781 m_hAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->hscrollbar
) );
782 m_vAdjust
= gtk_range_get_adjustment( GTK_RANGE(s_window
->vscrollbar
) );
784 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "value_changed",
785 (GtkSignalFunc
) gtk_window_hscroll_callback
, (gpointer
) this );
786 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "value_changed",
787 (GtkSignalFunc
) gtk_window_vscroll_callback
, (gpointer
) this );
789 gtk_signal_connect (GTK_OBJECT (m_hAdjust
), "changed",
790 (GtkSignalFunc
) gtk_window_hscroll_change_callback
, (gpointer
) this );
791 gtk_signal_connect (GTK_OBJECT (m_vAdjust
), "changed",
792 (GtkSignalFunc
) gtk_window_vscroll_change_callback
, (gpointer
) this );
794 GtkViewport
*viewport
;
795 viewport
= GTK_VIEWPORT(s_window
->viewport
);
797 if (m_windowStyle
& wxRAISED_BORDER
)
799 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_OUT
);
801 else if (m_windowStyle
& wxSUNKEN_BORDER
)
803 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_IN
);
807 gtk_viewport_set_shadow_type( viewport
, GTK_SHADOW_NONE
);
810 m_wxwindow
= gtk_myfixed_new();
812 if (m_wxwindow
) GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
814 if (m_windowStyle
& wxTAB_TRAVERSAL
== wxTAB_TRAVERSAL
)
815 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
817 GTK_WIDGET_SET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
819 gtk_container_add( GTK_CONTAINER(m_widget
), m_wxwindow
);
821 // shut the viewport up
822 gtk_viewport_set_hadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
823 gtk_viewport_set_vadjustment( viewport
, (GtkAdjustment
*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
825 // I _really_ don't want scrollbars in the beginning
826 m_vAdjust
->lower
= 0.0;
827 m_vAdjust
->upper
= 1.0;
828 m_vAdjust
->value
= 0.0;
829 m_vAdjust
->step_increment
= 1.0;
830 m_vAdjust
->page_increment
= 1.0;
831 m_vAdjust
->page_size
= 5.0;
832 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
833 m_hAdjust
->lower
= 0.0;
834 m_hAdjust
->upper
= 1.0;
835 m_hAdjust
->value
= 0.0;
836 m_hAdjust
->step_increment
= 1.0;
837 m_hAdjust
->page_increment
= 1.0;
838 m_hAdjust
->page_size
= 5.0;
839 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
841 gtk_widget_show( m_wxwindow
);
850 wxWindow::~wxWindow(void)
854 if (m_pDropTarget
) delete m_pDropTarget
;
856 if (m_parent
) m_parent
->RemoveChild( this );
857 if (m_widget
) Show( FALSE
);
861 if (m_wxwindow
) gtk_widget_destroy( m_wxwindow
);
863 if (m_widget
) gtk_widget_destroy( m_widget
);
867 DeleteRelatedConstraints();
870 // This removes any dangling pointers to this window
871 // in other windows' constraintsInvolvedIn lists.
872 UnsetConstraints(m_constraints
);
873 delete m_constraints
;
874 m_constraints
= NULL
;
878 delete m_windowSizer
;
879 m_windowSizer
= NULL
;
881 // If this is a child of a sizer, remove self from parent
882 if (m_sizerParent
) m_sizerParent
->RemoveChild((wxWindow
*)this);
884 // Just in case the window has been Closed, but
885 // we're then deleting immediately: don't leave
886 // dangling pointers.
887 wxPendingDelete
.DeleteObject(this);
889 // Just in case we've loaded a top-level window via
890 // wxWindow::LoadNativeDialog but we weren't a dialog
892 wxTopLevelWindows
.DeleteObject(this);
894 if (m_windowValidator
) delete m_windowValidator
;
897 void wxWindow::PreCreation( wxWindow
*parent
, wxWindowID id
,
898 const wxPoint
&pos
, const wxSize
&size
,
899 long style
, const wxString
&name
)
901 if (m_needParent
&& (parent
== NULL
))
902 wxFatalError( _("Need complete parent."), name
);
907 m_children
.DeleteContents( FALSE
);
911 if (m_width
== -1) m_width
= 20;
913 if (m_height
== -1) m_height
= 20;
915 m_eventHandler
= this;
918 if (m_cursor
== NULL
)
919 m_cursor
= new wxCursor( wxCURSOR_ARROW
);
920 m_font
= *wxSWISS_FONT
;
921 m_backgroundColour
= wxWHITE
;
922 m_foregroundColour
= wxBLACK
;
923 m_windowStyle
= style
;
925 m_constraints
= NULL
;
926 m_constraintsInvolvedIn
= NULL
;
927 m_windowSizer
= NULL
;
928 m_sizerParent
= NULL
;
929 m_autoLayout
= FALSE
;
930 m_drawingOffsetX
= 0;
931 m_drawingOffsetY
= 0;
932 m_pDropTarget
= NULL
;
934 m_windowValidator
= NULL
;
937 void wxWindow::PostCreation(void)
939 if (m_parent
) m_parent
->AddChild( this );
941 // GtkStyle *style = m_widget->style;
942 // style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
944 GtkWidget
*connect_widget
= GetConnectWidget();
946 gtk_object_set_data (GTK_OBJECT (connect_widget
), "MyWxWindow", (gpointer
)this );
950 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "expose_event",
951 GTK_SIGNAL_FUNC(gtk_window_expose_callback
), (gpointer
)this );
953 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "draw",
954 GTK_SIGNAL_FUNC(gtk_window_draw_callback
), (gpointer
)this );
958 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
959 GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this );
962 gtk_signal_connect( GTK_OBJECT(connect_widget
), "key_press_event",
963 GTK_SIGNAL_FUNC(gtk_window_key_press_callback
), (gpointer
)this );
965 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_press_event",
966 GTK_SIGNAL_FUNC(gtk_window_button_press_callback
), (gpointer
)this );
968 gtk_signal_connect( GTK_OBJECT(connect_widget
), "button_release_event",
969 GTK_SIGNAL_FUNC(gtk_window_button_release_callback
), (gpointer
)this );
971 gtk_signal_connect( GTK_OBJECT(connect_widget
), "motion_notify_event",
972 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback
), (gpointer
)this );
974 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_in_event",
975 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback
), (gpointer
)this );
977 gtk_signal_connect( GTK_OBJECT(connect_widget
), "focus_out_event",
978 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback
), (gpointer
)this );
980 // Only for cursor handling
982 gtk_signal_connect( GTK_OBJECT(m_widget
), "enter_notify_event",
983 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
985 gtk_signal_connect( GTK_OBJECT(m_widget
), "leave_notify_event",
986 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
990 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "enter_notify_event",
991 GTK_SIGNAL_FUNC(gtk_window_enter_callback
), (gpointer
)this );
993 gtk_signal_connect( GTK_OBJECT(m_wxwindow
), "leave_notify_event",
994 GTK_SIGNAL_FUNC(gtk_window_leave_callback
), (gpointer
)this );
998 // Does destroy ever get called ?
1000 gtk_signal_connect( GTK_OBJECT(m_widget), "destroy_event",
1001 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1005 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "destroy_event",
1006 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
1010 if (m_widget
&& m_parent
) gtk_widget_realize( m_widget
);
1011 if (m_wxwindow
) gtk_widget_realize( m_wxwindow
);
1013 SetCursor( wxSTANDARD_CURSOR
);
1018 bool wxWindow::HasVMT(void)
1023 bool wxWindow::Close( bool force
)
1025 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1026 event
.SetEventObject(this);
1027 event
.SetForce(force
);
1029 return GetEventHandler()->ProcessEvent(event
);
1032 bool wxWindow::Destroy(void)
1039 bool wxWindow::DestroyChildren(void)
1044 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
)
1047 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
)
1050 if (GetChildren()->Member(child
)) delete node
;
1057 void wxWindow::PrepareDC( wxDC
&WXUNUSED(dc
) )
1059 // are we to set fonts here ?
1062 void wxWindow::ImplementSetSize(void)
1064 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
1067 void wxWindow::ImplementSetPosition(void)
1069 if (IS_KIND_OF(this,wxFrame
) || IS_KIND_OF(this,wxDialog
))
1071 if ((m_x
!= -1) || (m_y
!= -1))
1072 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
1078 wxFAIL_MSG( _("wxWindow::SetSize error.\n") );
1082 if ((m_parent
) && (m_parent
->m_wxwindow
))
1083 gtk_myfixed_move( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);
1085 // Don't do anything for children of wxNotebook and wxMDIChildFrame
1088 void wxWindow::SetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
1090 if (m_resizing
) return; // I don't like recursions
1098 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
1100 if (newX
== -1) newX
= m_x
;
1101 if (newY
== -1) newY
= m_y
;
1102 if (newW
== -1) newW
= m_width
;
1103 if (newH
== -1) newH
= m_height
;
1106 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
1108 if (newW
== -1) newW
= 80;
1111 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
1113 if (newH
== -1) newH
= 26;
1116 if ((m_x
!= newX
) || (m_y
!= newY
) || (!m_sizeSet
))
1120 ImplementSetPosition();
1122 if ((m_width
!= newW
) || (m_height
!= newH
) || (!m_sizeSet
))
1130 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1131 event
.SetEventObject( this );
1132 ProcessEvent( event
);
1137 void wxWindow::SetSize( int width
, int height
)
1139 SetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
);
1142 void wxWindow::Move( int x
, int y
)
1144 SetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
);
1147 void wxWindow::GetSize( int *width
, int *height
) const
1149 if (width
) (*width
) = m_width
;
1150 if (height
) (*height
) = m_height
;
1153 void wxWindow::SetClientSize( int width
, int height
)
1157 SetSize( width
, height
);
1164 if (!m_hasScrolling
)
1167 do we have sunken dialogs ?
1169 GtkStyleClass *window_class = m_wxwindow->style->klass;
1171 dw += 2 * window_class->xthickness;
1172 dh += 2 * window_class->ythickness;
1177 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1178 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1180 GtkWidget
*viewport
= scroll_window
->viewport
;
1181 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1183 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1184 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1186 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1187 (m_windowStyle
& wxSUNKEN_BORDER
)
1190 dw
+= 2 * viewport_class
->xthickness
;
1191 dh
+= 2 * viewport_class
->ythickness
;
1194 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1196 dw
+= vscrollbar
->allocation
.width
;
1197 dw
+= scroll_class
->scrollbar_spacing
;
1200 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1202 dh
+= hscrollbar
->allocation
.height
;
1203 dw
+= scroll_class
->scrollbar_spacing
;
1207 SetSize( width
+dw
, height
+dh
);
1211 void wxWindow::GetClientSize( int *width
, int *height
) const
1215 if (width
) (*width
) = m_width
;
1216 if (height
) (*height
) = m_height
;
1223 if (!m_hasScrolling
)
1226 do we have sunken dialogs ?
1228 GtkStyleClass *window_class = m_wxwindow->style->klass;
1230 dw += 2 * window_class->xthickness;
1231 dh += 2 * window_class->ythickness;
1236 GtkScrolledWindow
*scroll_window
= GTK_SCROLLED_WINDOW(m_widget
);
1237 GtkScrolledWindowClass
*scroll_class
= GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget
)->klass
);
1239 GtkWidget
*viewport
= scroll_window
->viewport
;
1240 GtkStyleClass
*viewport_class
= viewport
->style
->klass
;
1242 GtkWidget
*hscrollbar
= scroll_window
->hscrollbar
;
1243 GtkWidget
*vscrollbar
= scroll_window
->vscrollbar
;
1245 if ((m_windowStyle
& wxRAISED_BORDER
) ||
1246 (m_windowStyle
& wxSUNKEN_BORDER
)
1249 dw
+= 2 * viewport_class
->xthickness
;
1250 dh
+= 2 * viewport_class
->ythickness
;
1253 if (GTK_WIDGET_VISIBLE(vscrollbar
))
1255 // dw += vscrollbar->allocation.width;
1256 dw
+= 15; // range.slider_width = 11 + 2*2pts edge
1257 dw
+= scroll_class
->scrollbar_spacing
;
1260 if (GTK_WIDGET_VISIBLE(hscrollbar
))
1262 // dh += hscrollbar->allocation.height;
1264 dh
+= scroll_class
->scrollbar_spacing
;
1268 if (width
) (*width
) = m_width
- dw
;
1269 if (height
) (*height
) = m_height
- dh
;
1273 void wxWindow::GetPosition( int *x
, int *y
) const
1279 void wxWindow::ClientToScreen( int *x
, int *y
)
1281 // Does this look simple ?
1283 GdkWindow
*source
= NULL
;
1285 source
= m_wxwindow
->window
;
1287 source
= m_widget
->window
;
1291 gdk_window_get_origin( source
, &org_x
, &org_y
);
1295 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1297 org_x
+= m_widget
->allocation
.x
;
1298 org_y
+= m_widget
->allocation
.y
;
1306 void wxWindow::ScreenToClient( int *x
, int *y
)
1308 GdkWindow
*source
= NULL
;
1310 source
= m_wxwindow
->window
;
1312 source
= m_widget
->window
;
1316 gdk_window_get_origin( source
, &org_x
, &org_y
);
1320 if (GTK_WIDGET_NO_WINDOW (m_widget
))
1322 org_x
+= m_widget
->allocation
.x
;
1323 org_y
+= m_widget
->allocation
.y
;
1331 void wxWindow::Centre( int direction
)
1333 if (IS_KIND_OF(this,wxDialog
) || IS_KIND_OF(this,wxFrame
))
1335 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (gdk_screen_width () - m_width
) / 2;
1336 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (gdk_screen_height () - m_height
) / 2;
1337 ImplementSetPosition();
1345 m_parent
->GetSize( &p_w
, &p_h
);
1346 if (direction
& wxHORIZONTAL
== wxHORIZONTAL
) m_x
= (p_w
- m_width
) / 2;
1347 if (direction
& wxVERTICAL
== wxVERTICAL
) m_y
= (p_h
- m_height
) / 2;
1348 ImplementSetPosition();
1353 void wxWindow::Fit(void)
1357 wxNode
*node
= GetChildren()->First();
1360 wxWindow
*win
= (wxWindow
*)node
->Data();
1362 win
->GetPosition(&wx
, &wy
);
1363 win
->GetSize(&ww
, &wh
);
1364 if ( wx
+ ww
> maxX
)
1366 if ( wy
+ wh
> maxY
)
1369 node
= node
->Next();
1371 SetClientSize(maxX
+ 5, maxY
+ 10);
1374 void wxWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1376 //if (GetAutoLayout()) Layout();
1379 bool wxWindow::Show( bool show
)
1382 gtk_widget_show( m_widget
);
1384 gtk_widget_hide( m_widget
);
1389 void wxWindow::Enable( bool enable
)
1391 m_isEnabled
= enable
;
1392 gtk_widget_set_sensitive( m_widget
, enable
);
1393 if (m_wxwindow
) gtk_widget_set_sensitive( m_wxwindow
, enable
);
1396 int wxWindow::GetCharHeight(void) const
1398 GdkFont
*font
= m_font
.GetInternalFont( 1.0 );
1399 return font
->ascent
+ font
->descent
;
1402 int wxWindow::GetCharWidth(void) const
1404 GdkFont
*font
= m_font
.GetInternalFont( 1.0 );
1405 return gdk_string_width( font
, "H" );
1408 void wxWindow::GetTextExtent( const wxString
& string
, int *x
, int *y
,
1409 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool WXUNUSED(use16
) ) const
1411 wxFont fontToUse
= m_font
;
1412 if (theFont
) fontToUse
= *theFont
;
1414 GdkFont
*font
= fontToUse
.GetInternalFont( 1.0 );
1415 if (x
) (*y
) = gdk_string_width( font
, string
);
1416 if (y
) (*y
) = font
->ascent
+ font
->descent
;
1417 if (descent
) (*descent
) = font
->descent
;
1418 if (externalLeading
) (*externalLeading
) = 0; // ??
1421 void wxWindow::MakeModal( bool modal
)
1424 // Disable all other windows
1425 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1427 wxNode
*node
= wxTopLevelWindows
.First();
1430 wxWindow
*win
= (wxWindow
*)node
->Data();
1432 win
->Enable(!modal
);
1434 node
= node
->Next();
1439 void wxWindow::SetFocus(void)
1441 GtkWidget
*connect_widget
= GetConnectWidget();
1444 if (GTK_WIDGET_CAN_FOCUS(connect_widget
) && !GTK_WIDGET_HAS_FOCUS (connect_widget
) )
1446 gtk_widget_grab_focus (connect_widget
);
1451 bool wxWindow::OnClose(void)
1456 void wxWindow::AddChild( wxWindow
*child
)
1458 // Addchild is (often) called before the program
1459 // has left the parents constructor so that no
1460 // virtual tables work yet. The approach below
1461 // practically imitates virtual tables, i.e. it
1462 // implements a different AddChild() behaviour
1463 // for wxFrame, wxDialog, wxWindow and
1464 // wxMDIParentFrame.
1466 // wxFrame and wxDialog as children aren't placed into the parents
1468 if (( IS_KIND_OF(child
,wxFrame
) || IS_KIND_OF(child
,wxDialog
) ) &&
1469 (!IS_KIND_OF(child
,wxMDIChildFrame
)))
1471 m_children
.Append( child
);
1473 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
1474 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
1479 // In the case of an wxMDIChildFrame descendant, we use the
1480 // client windows's AddChild()
1482 if (IS_KIND_OF(this,wxMDIParentFrame
))
1484 if (IS_KIND_OF(child
,wxMDIChildFrame
))
1486 wxMDIClientWindow
*client
= ((wxMDIParentFrame
*)this)->GetClientWindow();
1489 client
->AddChild( child
);
1495 // wxNotebook is very special, so it has a private AddChild()
1497 if (IS_KIND_OF(this,wxNotebook
))
1499 wxNotebook
*tab
= (wxNotebook
*)this;
1500 tab
->AddChild( child
);
1504 // wxFrame has a private AddChild
1506 if (IS_KIND_OF(this,wxFrame
) && !IS_KIND_OF(this,wxMDIChildFrame
))
1508 wxFrame
*frame
= (wxFrame
*)this;
1509 frame
->AddChild( child
);
1515 m_children
.Append( child
);
1516 if (m_wxwindow
) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
,
1517 child
->m_x
, child
->m_y
);
1519 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
1522 wxList
*wxWindow::GetChildren(void)
1524 return (&m_children
);
1527 void wxWindow::RemoveChild( wxWindow
*child
)
1530 GetChildren()->DeleteObject( child
);
1531 child
->m_parent
= NULL
;
1534 void wxWindow::SetReturnCode( int retCode
)
1536 m_retCode
= retCode
;
1539 int wxWindow::GetReturnCode(void)
1544 void wxWindow::Raise(void)
1546 if (m_widget
) gdk_window_raise( m_widget
->window
);
1549 void wxWindow::Lower(void)
1551 if (m_widget
) gdk_window_lower( m_widget
->window
);
1554 wxEvtHandler
*wxWindow::GetEventHandler(void)
1556 return m_eventHandler
;
1559 void wxWindow::SetEventHandler( wxEvtHandler
*handler
)
1561 m_eventHandler
= handler
;
1564 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
1566 handler
->SetNextHandler(GetEventHandler());
1567 SetEventHandler(handler
);
1570 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
1572 if ( GetEventHandler() )
1574 wxEvtHandler
*handlerA
= GetEventHandler();
1575 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
1576 handlerA
->SetNextHandler(NULL
);
1577 SetEventHandler(handlerB
);
1578 if ( deleteHandler
)
1590 wxValidator
*wxWindow::GetValidator(void)
1592 return m_windowValidator
;
1595 void wxWindow::SetValidator( const wxValidator
& validator
)
1597 if (m_windowValidator
) delete m_windowValidator
;
1598 m_windowValidator
= validator
.Clone();
1599 if (m_windowValidator
) m_windowValidator
->SetWindow(this);
1602 bool wxWindow::IsBeingDeleted(void)
1607 void wxWindow::SetId( wxWindowID id
)
1612 wxWindowID
wxWindow::GetId(void)
1617 void wxWindow::SetCursor( const wxCursor
&cursor
)
1619 wxASSERT(m_cursor
!= NULL
);
1621 if (m_cursor
!= NULL
)
1622 if (*m_cursor
== cursor
)
1624 (*m_cursor
) = cursor
;
1625 if (m_widget
->window
)
1626 gdk_window_set_cursor( m_widget
->window
, m_cursor
->GetCursor() );
1627 if (m_wxwindow
&& m_wxwindow
->window
)
1628 gdk_window_set_cursor( m_wxwindow
->window
, m_cursor
->GetCursor() );
1631 void wxWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
1633 if (eraseBackground
&& m_wxwindow
&& m_wxwindow
->window
)
1636 gdk_window_clear_area( m_wxwindow
->window
,
1648 wxClientDC
dc(this);
1652 dc
.GetInternalDeviceOrigin( &x
, &y
);
1656 GetClientSize( &w
, &h
);
1658 GdkRectangle gdk_rect
;
1662 gdk_rect
.height
= h
;
1663 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1668 GdkRectangle gdk_rect
;
1669 gdk_rect
.x
= rect
->x
;
1670 gdk_rect
.y
= rect
->y
;
1671 gdk_rect
.width
= rect
->width
;
1672 gdk_rect
.height
= rect
->height
;
1675 gtk_widget_draw( m_wxwindow
, &gdk_rect
);
1677 gtk_widget_draw( m_widget
, &gdk_rect
);
1681 bool wxWindow::IsExposed( long x
, long y
)
1683 return (m_updateRegion
.Contains( x
, y
) != wxOutRegion
);
1686 bool wxWindow::IsExposed( long x
, long y
, long width
, long height
)
1688 return (m_updateRegion
.Contains( x
, y
, width
, height
) != wxOutRegion
);
1691 void wxWindow::Clear(void)
1693 if (m_wxwindow
&& m_wxwindow
->window
) gdk_window_clear( m_wxwindow
->window
);
1696 wxColour
wxWindow::GetBackgroundColour(void) const
1698 return m_backgroundColour
;
1701 void wxWindow::SetBackgroundColour( const wxColour
&colour
)
1703 m_backgroundColour
= colour
;
1706 m_backgroundColour
.CalcPixel( m_wxwindow
->style
->colormap
);
1707 gdk_window_set_background( m_wxwindow
->window
, m_backgroundColour
.GetColor() );
1708 gdk_window_clear( m_wxwindow
->window
);
1713 wxColour
wxWindow::GetForegroundColour(void) const
1715 return m_foregroundColour
;
1718 void wxWindow::SetForegroundColour( const wxColour
&colour
)
1720 m_foregroundColour
= colour
;
1723 bool wxWindow::Validate(void)
1725 wxNode
*node
= GetChildren()->First();
1728 wxWindow
*child
= (wxWindow
*)node
->Data();
1729 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this))
1731 node
= node
->Next();
1736 bool wxWindow::TransferDataToWindow(void)
1738 wxNode
*node
= GetChildren()->First();
1741 wxWindow
*child
= (wxWindow
*)node
->Data();
1742 if (child
->GetValidator() && /* child->GetValidator()->Ok() && */
1743 !child
->GetValidator()->TransferToWindow() )
1745 wxMessageBox( _("Application Error"), _("Could not transfer data to window"), wxOK
|wxICON_EXCLAMATION
);
1748 node
= node
->Next();
1753 bool wxWindow::TransferDataFromWindow(void)
1755 wxNode
*node
= GetChildren()->First();
1758 wxWindow
*child
= (wxWindow
*)node
->Data();
1759 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->TransferFromWindow() )
1761 node
= node
->Next();
1766 void wxWindow::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1768 TransferDataToWindow();
1771 void wxWindow::InitDialog(void)
1773 wxInitDialogEvent
event(GetId());
1774 event
.SetEventObject( this );
1775 GetEventHandler()->ProcessEvent(event
);
1778 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
1780 menu
->SetInvokingWindow( win
);
1781 wxNode
*node
= menu
->m_items
.First();
1784 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
1785 if (menuitem
->IsSubMenu())
1786 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1787 node
= node
->Next();
1791 bool wxWindow::PopupMenu( wxMenu
*menu
, int WXUNUSED(x
), int WXUNUSED(y
) )
1793 SetInvokingWindow( menu
, this );
1794 gtk_menu_popup( GTK_MENU(menu
->m_menu
), NULL
, NULL
, NULL
, NULL
, 0, 0 );
1798 void wxWindow::SetDropTarget( wxDropTarget
*dropTarget
)
1800 GtkWidget
*dnd_widget
= GetConnectWidget();
1804 gtk_signal_disconnect_by_func( GTK_OBJECT(dnd_widget
),
1805 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1807 m_pDropTarget
->UnregisterWidget( dnd_widget
);
1808 delete m_pDropTarget
;
1810 m_pDropTarget
= dropTarget
;
1813 m_pDropTarget
->RegisterWidget( dnd_widget
);
1815 gtk_signal_connect( GTK_OBJECT(dnd_widget
), "drop_data_available_event",
1816 GTK_SIGNAL_FUNC(gtk_window_drop_callback
), (gpointer
)this );
1820 wxDropTarget
*wxWindow::GetDropTarget() const
1822 return m_pDropTarget
;
1825 GtkWidget
* wxWindow::GetConnectWidget(void)
1827 GtkWidget
*connect_widget
= m_widget
;
1828 if (m_wxwindow
) connect_widget
= m_wxwindow
;
1830 return connect_widget
;
1833 bool wxWindow::IsOwnGtkWindow( GdkWindow
*window
)
1835 if (m_wxwindow
) return (window
== m_wxwindow
->window
);
1836 return (window
== m_widget
->window
);
1839 void wxWindow::SetFont( const wxFont
&font
)
1844 copy old style values to new one
1845 set font in new style
1846 -> takes to many resources
1848 GtkStyle *style = gtk_style_new();
1853 wxFont
*wxWindow::GetFont(void)
1858 void wxWindow::SetWindowStyleFlag( long flag
)
1860 m_windowStyle
= flag
;
1863 long wxWindow::GetWindowStyleFlag(void) const
1865 return m_windowStyle
;
1868 void wxWindow::CaptureMouse(void)
1870 GtkWidget
*connect_widget
= GetConnectWidget();
1871 gtk_grab_add( connect_widget
);
1872 gdk_pointer_grab ( connect_widget
->window
, FALSE
,
1874 (GDK_BUTTON_PRESS_MASK
|
1875 GDK_BUTTON_RELEASE_MASK
|
1876 GDK_POINTER_MOTION_MASK
),
1877 NULL
, NULL
, GDK_CURRENT_TIME
);
1880 void wxWindow::ReleaseMouse(void)
1882 GtkWidget
*connect_widget
= GetConnectWidget();
1883 gtk_grab_remove( connect_widget
);
1884 gdk_pointer_ungrab ( GDK_CURRENT_TIME
);
1887 void wxWindow::SetTitle( const wxString
&WXUNUSED(title
) )
1891 wxString
wxWindow::GetTitle(void) const
1893 return (wxString
&)m_windowName
;
1896 wxString
wxWindow::GetLabel(void) const
1901 void wxWindow::SetName( const wxString
&name
)
1903 m_windowName
= name
;
1906 wxString
wxWindow::GetName(void) const
1908 return (wxString
&)m_windowName
;
1911 bool wxWindow::IsShown(void) const
1916 bool wxWindow::IsRetained(void)
1921 wxWindow
*wxWindow::FindWindow( long id
)
1923 if (id
== m_windowId
) return this;
1924 wxNode
*node
= m_children
.First();
1927 wxWindow
*child
= (wxWindow
*)node
->Data();
1928 wxWindow
*res
= child
->FindWindow( id
);
1929 if (res
) return res
;
1930 node
= node
->Next();
1935 wxWindow
*wxWindow::FindWindow( const wxString
& name
)
1937 if (name
== m_windowName
) return this;
1938 wxNode
*node
= m_children
.First();
1941 wxWindow
*child
= (wxWindow
*)node
->Data();
1942 wxWindow
*res
= child
->FindWindow( name
);
1943 if (res
) return res
;
1944 node
= node
->Next();
1949 void wxWindow::SetScrollbar( int orient
, int pos
, int thumbVisible
,
1950 int range
, bool WXUNUSED(refresh
) )
1952 if (!m_wxwindow
) return;
1954 if (orient
== wxHORIZONTAL
)
1956 float fpos
= (float)pos
;
1957 m_oldHorizontalPos
= fpos
;
1958 float frange
= (float)range
;
1959 float fthumb
= (float)thumbVisible
;
1961 if ((fabs(fpos
-m_hAdjust
->value
) < 0.2) &&
1962 (fabs(frange
-m_hAdjust
->upper
) < 0.2) &&
1963 (fabs(fthumb
-m_hAdjust
->page_size
) < 0.2))
1966 m_hAdjust
->lower
= 0.0;
1967 m_hAdjust
->upper
= frange
;
1968 m_hAdjust
->value
= fpos
;
1969 m_hAdjust
->step_increment
= 1.0;
1970 m_hAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1971 m_hAdjust
->page_size
= fthumb
;
1975 float fpos
= (float)pos
;
1976 m_oldVerticalPos
= fpos
;
1977 float frange
= (float)range
;
1978 float fthumb
= (float)thumbVisible
;
1980 if ((fabs(fpos
-m_vAdjust
->value
) < 0.2) &&
1981 (fabs(frange
-m_vAdjust
->upper
) < 0.2) &&
1982 (fabs(fthumb
-m_vAdjust
->page_size
) < 0.2))
1985 m_vAdjust
->lower
= 0.0;
1986 m_vAdjust
->upper
= frange
;
1987 m_vAdjust
->value
= fpos
;
1988 m_vAdjust
->step_increment
= 1.0;
1989 m_vAdjust
->page_increment
= (float)(wxMax(fthumb
-2,0));
1990 m_vAdjust
->page_size
= fthumb
;
1993 if (m_wxwindow
->window
)
1995 if (orient
== wxHORIZONTAL
)
1998 m_drawingOffsetX = -16000;
2000 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
2002 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "changed" );
2007 m_drawingOffsetY = -16000;
2009 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
2011 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "changed" );
2014 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
2018 void wxWindow::SetScrollPos( int orient
, int pos
, bool WXUNUSED(refresh
) )
2020 if (!m_wxwindow
) return;
2022 if (orient
== wxHORIZONTAL
)
2024 float fpos
= (float)pos
;
2025 m_oldHorizontalPos
= fpos
;
2027 if (fabs(fpos
-m_hAdjust
->value
) < 0.2) return;
2028 m_hAdjust
->value
= fpos
;
2032 float fpos
= (float)pos
;
2033 m_oldVerticalPos
= fpos
;
2034 if (fabs(fpos
-m_vAdjust
->value
) < 0.2) return;
2035 m_vAdjust
->value
= fpos
;
2038 if (m_wxwindow
->window
)
2040 if (orient
== wxHORIZONTAL
)
2041 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust
), "value_changed" );
2043 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust
), "value_changed" );
2047 int wxWindow::GetScrollThumb( int orient
) const
2049 if (!m_wxwindow
) return 0;
2051 if (orient
== wxHORIZONTAL
)
2052 return (int)(m_hAdjust
->page_size
+0.5);
2054 return (int)(m_vAdjust
->page_size
+0.5);
2057 int wxWindow::GetScrollPos( int orient
) const
2059 if (!m_wxwindow
) return 0;
2061 if (orient
== wxHORIZONTAL
)
2062 return (int)(m_hAdjust
->value
+0.5);
2064 return (int)(m_vAdjust
->value
+0.5);
2067 int wxWindow::GetScrollRange( int orient
) const
2069 if (!m_wxwindow
) return 0;
2071 if (orient
== wxHORIZONTAL
)
2072 return (int)(m_hAdjust
->upper
+0.5);
2074 return (int)(m_vAdjust
->upper
+0.5);
2077 void wxWindow::ScrollWindow( int dx
, int dy
, const wxRect
* WXUNUSED(rect
) )
2079 if (!m_wxwindow
) return;
2081 bool refresh
= FALSE
;
2083 if ((m_drawingOffsetX
== 0) && (m_drawingOffsetY
== 0))
2085 m_drawingOffsetX
= -16000;
2086 m_drawingOffsetY
= -16000;
2091 m_drawingOffsetX
+= dx
;
2092 m_drawingOffsetY
+= dy
;
2095 // printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
2097 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow
), m_drawingOffsetX
, m_drawingOffsetY
);
2099 if (refresh
) Refresh();
2102 The code here is very nifty, but it doesn't work with
2103 overlapping windows...
2107 GetClientSize( &cw, &ch );
2109 int w = cw - abs(dx);
2110 int h = ch - abs(dy);
2111 if ((h < 0) || (w < 0))
2118 if (dx < 0) s_x = -dx;
2119 if (dy < 0) s_y = -dy;
2122 if (dx > 0) d_x = dx;
2123 if (dy > 0) d_y = dy;
2124 gdk_window_copy_area( m_wxwindow->window, m_wxwindow->style->fg_gc[0], d_x, d_y,
2125 m_wxwindow->window, s_x, s_y, w, h );
2128 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
2129 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
2130 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
2131 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
2133 Refresh( TRUE, &rect );
2137 void wxWindow::GetDrawingOffset( long *x
, long *y
)
2139 if (x
) *x
= m_drawingOffsetX
;
2140 if (y
) *y
= m_drawingOffsetY
;
2143 //-------------------------------------------------------------------------------------
2145 //-------------------------------------------------------------------------------------
2147 wxLayoutConstraints
*wxWindow::GetConstraints(void) const
2149 return m_constraints
;
2152 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
2156 UnsetConstraints(m_constraints
);
2157 delete m_constraints
;
2159 m_constraints
= constraints
;
2162 // Make sure other windows know they're part of a 'meaningful relationship'
2163 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
2164 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2165 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
2166 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2167 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
2168 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2169 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
2170 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2171 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
2172 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2173 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
2174 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2175 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
2176 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2177 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
2178 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
2184 void wxWindow::SetAutoLayout( bool autoLayout
)
2186 m_autoLayout
= autoLayout
;
2189 bool wxWindow::GetAutoLayout(void) const
2191 return m_autoLayout
;
2194 wxSizer
*wxWindow::GetSizer(void) const
2196 return m_windowSizer
;
2199 void wxWindow::SetSizerParent( wxWindow
*win
)
2201 m_sizerParent
= win
;
2204 wxWindow
*wxWindow::GetSizerParent(void) const
2206 return m_sizerParent
;
2209 // This removes any dangling pointers to this window
2210 // in other windows' constraintsInvolvedIn lists.
2211 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
2215 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2216 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2217 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
2218 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2219 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
2220 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2221 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
2222 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2223 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
2224 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2225 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
2226 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2227 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
2228 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2229 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
2230 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
2234 // Back-pointer to other windows we're involved with, so if we delete
2235 // this window, we must delete any constraints we're involved with.
2236 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
2238 if (!m_constraintsInvolvedIn
)
2239 m_constraintsInvolvedIn
= new wxList
;
2240 if (!m_constraintsInvolvedIn
->Member(otherWin
))
2241 m_constraintsInvolvedIn
->Append(otherWin
);
2244 // REMOVE back-pointer to other windows we're involved with.
2245 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
2247 if (m_constraintsInvolvedIn
)
2248 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
2251 // Reset any constraints that mention this window
2252 void wxWindow::DeleteRelatedConstraints(void)
2254 if (m_constraintsInvolvedIn
)
2256 wxNode
*node
= m_constraintsInvolvedIn
->First();
2259 wxWindow
*win
= (wxWindow
*)node
->Data();
2260 wxNode
*next
= node
->Next();
2261 wxLayoutConstraints
*constr
= win
->GetConstraints();
2263 // Reset any constraints involving this window
2266 constr
->left
.ResetIfWin((wxWindow
*)this);
2267 constr
->top
.ResetIfWin((wxWindow
*)this);
2268 constr
->right
.ResetIfWin((wxWindow
*)this);
2269 constr
->bottom
.ResetIfWin((wxWindow
*)this);
2270 constr
->width
.ResetIfWin((wxWindow
*)this);
2271 constr
->height
.ResetIfWin((wxWindow
*)this);
2272 constr
->centreX
.ResetIfWin((wxWindow
*)this);
2273 constr
->centreY
.ResetIfWin((wxWindow
*)this);
2278 delete m_constraintsInvolvedIn
;
2279 m_constraintsInvolvedIn
= NULL
;
2283 void wxWindow::SetSizer(wxSizer
*sizer
)
2285 m_windowSizer
= sizer
;
2287 sizer
->SetSizerParent((wxWindow
*)this);
2294 bool wxWindow::Layout(void)
2296 if (GetConstraints())
2299 GetClientSize(&w
, &h
);
2300 GetConstraints()->width
.SetValue(w
);
2301 GetConstraints()->height
.SetValue(h
);
2304 // If top level (one sizer), evaluate the sizer's constraints.
2308 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2309 GetSizer()->LayoutPhase1(&noChanges
);
2310 GetSizer()->LayoutPhase2(&noChanges
);
2311 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2316 // Otherwise, evaluate child constraints
2317 ResetConstraints(); // Mark all constraints as unevaluated
2318 DoPhase(1); // Just one phase need if no sizers involved
2320 SetConstraintSizes(); // Recursively set the real window sizes
2326 // Do a phase of evaluating constraints:
2327 // the default behaviour. wxSizers may do a similar
2328 // thing, but also impose their own 'constraints'
2329 // and order the evaluation differently.
2330 bool wxWindow::LayoutPhase1(int *noChanges
)
2332 wxLayoutConstraints
*constr
= GetConstraints();
2335 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
2341 bool wxWindow::LayoutPhase2(int *noChanges
)
2351 // Do a phase of evaluating child constraints
2352 bool wxWindow::DoPhase(int phase
)
2354 int noIterations
= 0;
2355 int maxIterations
= 500;
2359 while ((noChanges
> 0) && (noIterations
< maxIterations
))
2363 wxNode
*node
= GetChildren()->First();
2366 wxWindow
*child
= (wxWindow
*)node
->Data();
2367 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
2369 wxLayoutConstraints
*constr
= child
->GetConstraints();
2372 if (succeeded
.Member(child
))
2377 int tempNoChanges
= 0;
2378 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
2379 noChanges
+= tempNoChanges
;
2382 succeeded
.Append(child
);
2387 node
= node
->Next();
2394 void wxWindow::ResetConstraints(void)
2396 wxLayoutConstraints
*constr
= GetConstraints();
2399 constr
->left
.SetDone(FALSE
);
2400 constr
->top
.SetDone(FALSE
);
2401 constr
->right
.SetDone(FALSE
);
2402 constr
->bottom
.SetDone(FALSE
);
2403 constr
->width
.SetDone(FALSE
);
2404 constr
->height
.SetDone(FALSE
);
2405 constr
->centreX
.SetDone(FALSE
);
2406 constr
->centreY
.SetDone(FALSE
);
2408 wxNode
*node
= GetChildren()->First();
2411 wxWindow
*win
= (wxWindow
*)node
->Data();
2412 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2413 win
->ResetConstraints();
2414 node
= node
->Next();
2418 // Need to distinguish between setting the 'fake' size for
2419 // windows and sizers, and setting the real values.
2420 void wxWindow::SetConstraintSizes(bool recurse
)
2422 wxLayoutConstraints
*constr
= GetConstraints();
2423 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
2424 constr
->width
.GetDone() && constr
->height
.GetDone())
2426 int x
= constr
->left
.GetValue();
2427 int y
= constr
->top
.GetValue();
2428 int w
= constr
->width
.GetValue();
2429 int h
= constr
->height
.GetValue();
2431 // If we don't want to resize this window, just move it...
2432 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
2433 (constr
->height
.GetRelationship() != wxAsIs
))
2435 // Calls Layout() recursively. AAAGH. How can we stop that.
2436 // Simply take Layout() out of non-top level OnSizes.
2437 SizerSetSize(x
, y
, w
, h
);
2446 char *windowClass
= this->GetClassInfo()->GetClassName();
2449 if (GetName() == "")
2450 winName
= _("unnamed");
2452 winName
= GetName();
2453 wxDebugMsg(_("Constraint(s) not satisfied for window of type %s, name %s:\n"), (const char *)windowClass
, (const char *)winName
);
2454 if (!constr
->left
.GetDone())
2455 wxDebugMsg(_(" unsatisfied 'left' constraint.\n"));
2456 if (!constr
->right
.GetDone())
2457 wxDebugMsg(_(" unsatisfied 'right' constraint.\n"));
2458 if (!constr
->width
.GetDone())
2459 wxDebugMsg(_(" unsatisfied 'width' constraint.\n"));
2460 if (!constr
->height
.GetDone())
2461 wxDebugMsg(_(" unsatisfied 'height' constraint.\n"));
2462 wxDebugMsg(_("Please check constraints: try adding AsIs() constraints.\n"));
2467 wxNode
*node
= GetChildren()->First();
2470 wxWindow
*win
= (wxWindow
*)node
->Data();
2471 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
2472 win
->SetConstraintSizes();
2473 node
= node
->Next();
2478 // This assumes that all sizers are 'on' the same
2479 // window, i.e. the parent of this window.
2480 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
2482 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
2483 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
2487 m_sizerParent
->GetPosition(&xp
, &yp
);
2488 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
2493 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2497 TransformSizerToActual(&xx
, &yy
);
2498 SetSize(xx
, yy
, w
, h
);
2501 void wxWindow::SizerMove(int x
, int y
)
2505 TransformSizerToActual(&xx
, &yy
);
2509 // Only set the size/position of the constraint (if any)
2510 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2512 wxLayoutConstraints
*constr
= GetConstraints();
2517 constr
->left
.SetValue(x
);
2518 constr
->left
.SetDone(TRUE
);
2522 constr
->top
.SetValue(y
);
2523 constr
->top
.SetDone(TRUE
);
2527 constr
->width
.SetValue(w
);
2528 constr
->width
.SetDone(TRUE
);
2532 constr
->height
.SetValue(h
);
2533 constr
->height
.SetDone(TRUE
);
2538 void wxWindow::MoveConstraint(int x
, int y
)
2540 wxLayoutConstraints
*constr
= GetConstraints();
2545 constr
->left
.SetValue(x
);
2546 constr
->left
.SetDone(TRUE
);
2550 constr
->top
.SetValue(y
);
2551 constr
->top
.SetDone(TRUE
);
2556 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2558 wxLayoutConstraints
*constr
= GetConstraints();
2561 *w
= constr
->width
.GetValue();
2562 *h
= constr
->height
.GetValue();
2568 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2570 wxLayoutConstraints
*constr
= GetConstraints();
2573 *w
= constr
->width
.GetValue();
2574 *h
= constr
->height
.GetValue();
2577 GetClientSize(w
, h
);
2580 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2582 wxLayoutConstraints
*constr
= GetConstraints();
2585 *x
= constr
->left
.GetValue();
2586 *y
= constr
->top
.GetValue();
2592 bool wxWindow::AcceptsFocus() const
2594 return IsEnabled() && IsShown();
2597 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
) )