]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/window.cpp
GTK:
[wxWidgets.git] / src / gtk1 / window.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: window.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11
12#ifdef __GNUG__
13#pragma implementation "window.h"
14#endif
15
16#include "wx/defs.h"
17#include "wx/window.h"
18#include "wx/dc.h"
19#include "wx/frame.h"
20#include "wx/app.h"
21#include "wx/layout.h"
22#include "wx/utils.h"
23#include "wx/dialog.h"
24#include "wx/msgdlg.h"
25#include "wx/dcclient.h"
26#include "wx/dnd.h"
27#include "wx/mdi.h"
28#include "gdk/gdkkeysyms.h"
29#include <math.h>
30#include "wx/gtk/win_gtk.h"
31#include "gdk/gdkprivate.h"
32
33//-----------------------------------------------------------------------------
34// data
35//-----------------------------------------------------------------------------
36
37extern wxList wxPendingDelete;
38extern wxList wxTopLevelWindows;
39extern bool g_blockEventsOnDrag;
40
41//-----------------------------------------------------------------------------
42// GTK callbacks for wxWindows event system
43//-----------------------------------------------------------------------------
44
45//-----------------------------------------------------------------------------
46// expose (of m_wxwindow, not of m_widget)
47
48void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxWindow *win )
49{
50 if (!win->HasVMT()) return;
51 if (g_blockEventsOnDrag) return;
52
53/*
54 printf( "OnExpose from " );
55 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
56 printf( win->GetClassInfo()->GetClassName() );
57 printf( ".\n" );
58
59 printf( "x: %d \n", gdk_event->area.x );
60 printf( "y: %d \n", gdk_event->area.y );
61 printf( "w: %d \n", gdk_event->area.width );
62 printf( "h: %d \n", gdk_event->area.height );
63*/
64
65 win->m_updateRegion.Union( gdk_event->area.x,
66 gdk_event->area.y,
67 gdk_event->area.width,
68 gdk_event->area.height );
69
70 if (gdk_event->count > 0) return;
71
72 wxPaintEvent event( win->GetId() );
73 event.SetEventObject( win );
74 win->ProcessEvent( event );
75
76 win->m_updateRegion.Clear();
77};
78
79//-----------------------------------------------------------------------------
80// draw (of m_wxwindow, not of m_widget)
81
82void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxWindow *win )
83{
84 if (!win->HasVMT()) return;
85 if (g_blockEventsOnDrag) return;
86
87/*
88 printf( "OnDraw from " );
89 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
90 printf( win->GetClassInfo()->GetClassName() );
91 printf( ".\n" );
92
93 printf( "x: %d \n", rect->x );
94 printf( "y: %d \n", rect->y );
95 printf( "w: %d \n", rect->width );
96 printf( "h: %d \n", rect->height );
97*/
98
99 win->m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height );
100
101 wxPaintEvent event( win->GetId() );
102 event.SetEventObject( win );
103 win->ProcessEvent( event );
104
105 win->m_updateRegion.Clear();
106};
107
108//-----------------------------------------------------------------------------
109// size
110// I don't any longer intercept GTK's internal resize events (except frames)
111
112/*
113void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
114{
115 if (!win->HasVMT()) return;
116 if (g_blockEventsOnDrag) return;
117
118 return;
119
120 if ((win->m_x == alloc->x) &&
121 (win->m_y == alloc->y) &&
122 (win->m_width == alloc->width) &&
123 (win->m_height == alloc->height))
124 {
125 return;
126 };
127
128 printf( "OnResize from " );
129 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
130 printf( win->GetClassInfo()->GetClassName() );
131 printf( " .\n" );
132
133 printf( " Old: X: %d Y: %d ", win->m_x, win->m_y );
134 printf( " W: %d H: %d ", win->m_width, win->m_height );
135 printf( " .\n" );
136
137 printf( " New: X: %d Y: %d ", alloc->x, alloc->y );
138 printf( " W: %d H: %d ", alloc->width, alloc->height );
139 printf( " .\n" );
140
141 wxSizeEvent event( wxSize( alloc->width, alloc->height), win->GetId() );
142 event.SetEventObject( win );
143 win->ProcessEvent( event );
144};
145*/
146
147//-----------------------------------------------------------------------------
148// key_press
149
150gint gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), GdkEventKey *gdk_event, wxWindow *win )
151{
152 if (!win->HasVMT()) return FALSE;
153 if (g_blockEventsOnDrag) return FALSE;
154
155/*
156 printf( "OnKeyPress from " );
157 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
158 printf( win->GetClassInfo()->GetClassName() );
159 printf( ".\n" );
160*/
161
162 long key_code = 0;
163 switch (gdk_event->keyval)
164 {
165 case GDK_BackSpace: key_code = WXK_BACK; break;
166 case GDK_Tab: key_code = WXK_TAB; break;
167 case GDK_Linefeed: key_code = WXK_RETURN; break;
168 case GDK_Clear: key_code = WXK_CLEAR; break;
169 case GDK_Return: key_code = WXK_RETURN; break;
170 case GDK_Pause: key_code = WXK_PAUSE; break;
171 case GDK_Scroll_Lock: key_code = WXK_SCROLL; break;
172 case GDK_Escape: key_code = WXK_ESCAPE; break;
173 case GDK_Delete: key_code = WXK_DELETE; break;
174 case GDK_Home: key_code = WXK_HOME; break;
175 case GDK_Left: key_code = WXK_LEFT; break;
176 case GDK_Up: key_code = WXK_UP; break;
177 case GDK_Right: key_code = WXK_RIGHT; break;
178 case GDK_Down: key_code = WXK_DOWN; break;
179 case GDK_Prior: key_code = WXK_PRIOR; break;
180// case GDK_Page_Up: key_code = WXK_PAGEUP; break;
181 case GDK_Next: key_code = WXK_NEXT; break;
182// case GDK_Page_Down: key_code = WXK_PAGEDOWN; break;
183 case GDK_End: key_code = WXK_END; break;
184 case GDK_Begin: key_code = WXK_HOME; break;
185 case GDK_Select: key_code = WXK_SELECT; break;
186 case GDK_Print: key_code = WXK_PRINT; break;
187 case GDK_Execute: key_code = WXK_EXECUTE; break;
188 case GDK_Insert: key_code = WXK_INSERT; break;
189 case GDK_Num_Lock: key_code = WXK_NUMLOCK; break;
190 case GDK_KP_Tab: key_code = WXK_TAB; break;
191 case GDK_KP_Enter: key_code = WXK_RETURN; break;
192 case GDK_KP_Home: key_code = WXK_HOME; break;
193 case GDK_KP_Left: key_code = WXK_LEFT; break;
194 case GDK_KP_Up: key_code = WXK_UP; break;
195 case GDK_KP_Right: key_code = WXK_RIGHT; break;
196 case GDK_KP_Down: key_code = WXK_DOWN; break;
197 case GDK_KP_Prior: key_code = WXK_PRIOR; break;
198// case GDK_KP_Page_Up: key_code = WXK_PAGEUP; break;
199 case GDK_KP_Next: key_code = WXK_NEXT; break;
200// case GDK_KP_Page_Down: key_code = WXK_PAGEDOWN; break;
201 case GDK_KP_End: key_code = WXK_END; break;
202 case GDK_KP_Begin: key_code = WXK_HOME; break;
203 case GDK_KP_Insert: key_code = WXK_INSERT; break;
204 case GDK_KP_Delete: key_code = WXK_DELETE; break;
205 case GDK_KP_Multiply: key_code = WXK_MULTIPLY; break;
206 case GDK_KP_Add: key_code = WXK_ADD; break;
207 case GDK_KP_Separator: key_code = WXK_SEPARATOR; break;
208 case GDK_KP_Subtract: key_code = WXK_SUBTRACT; break;
209 case GDK_KP_Decimal: key_code = WXK_DECIMAL; break;
210 case GDK_KP_Divide: key_code = WXK_DIVIDE; break;
211 case GDK_KP_0: key_code = WXK_NUMPAD0; break;
212 case GDK_KP_1: key_code = WXK_NUMPAD1; break;
213 case GDK_KP_2: key_code = WXK_NUMPAD2; break;
214 case GDK_KP_3: key_code = WXK_NUMPAD3; break;
215 case GDK_KP_4: key_code = WXK_NUMPAD4; break;
216 case GDK_KP_5: key_code = WXK_NUMPAD5; break;
217 case GDK_KP_6: key_code = WXK_NUMPAD6; break;
218 case GDK_KP_7: key_code = WXK_NUMPAD7; break;
219 case GDK_KP_8: key_code = WXK_NUMPAD7; break;
220 case GDK_KP_9: key_code = WXK_NUMPAD9; break;
221 case GDK_F1: key_code = WXK_F1; break;
222 case GDK_F2: key_code = WXK_F2; break;
223 case GDK_F3: key_code = WXK_F3; break;
224 case GDK_F4: key_code = WXK_F4; break;
225 case GDK_F5: key_code = WXK_F5; break;
226 case GDK_F6: key_code = WXK_F6; break;
227 case GDK_F7: key_code = WXK_F7; break;
228 case GDK_F8: key_code = WXK_F8; break;
229 case GDK_F9: key_code = WXK_F9; break;
230 case GDK_F10: key_code = WXK_F10; break;
231 case GDK_F11: key_code = WXK_F11; break;
232 case GDK_F12: key_code = WXK_F12; break;
233 default:
234 {
235 if ((gdk_event->keyval >= 0x20) && (gdk_event->keyval <= 0xFF))
236 key_code = gdk_event->keyval;
237 };
238 };
239
240 if (!key_code) return FALSE;
241
242 wxKeyEvent event( wxEVT_CHAR );
243 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
244 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
245 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
246 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
247 event.m_keyCode = key_code;
248 event.m_x = 0;
249 event.m_y = 0;
250 event.SetEventObject( win );
251 return win->ProcessEvent( event );
252};
253
254//-----------------------------------------------------------------------------
255// button_press
256
257gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
258{
259 if (widget->window != gdk_event->window) return FALSE;
260 if (g_blockEventsOnDrag) return FALSE;
261
262 if (win->m_wxwindow)
263 {
264 if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow) && !GTK_WIDGET_HAS_FOCUS (win->m_wxwindow) )
265 {
266 gtk_widget_grab_focus (win->m_wxwindow);
267
268/*
269 printf( "GrabFocus from " );
270 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
271 printf( win->GetClassInfo()->GetClassName() );
272 printf( ".\n" );
273*/
274
275 };
276 };
277
278 if (!win->HasVMT()) return FALSE;
279
280/*
281 printf( "OnButtonPress from " );
282 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
283 printf( win->GetClassInfo()->GetClassName() );
284 printf( ".\n" );
285*/
286
287 WXTYPE event_type = wxEVT_LEFT_DOWN;
288
289 if (gdk_event->button == 1)
290 {
291 switch (gdk_event->type)
292 {
293 case GDK_BUTTON_PRESS: event_type = wxEVT_LEFT_DOWN; break;
294 case GDK_2BUTTON_PRESS: event_type = wxEVT_LEFT_DCLICK; break;
295 default: break;
296 };
297 }
298 else if (gdk_event->button == 2)
299 {
300 switch (gdk_event->type)
301 {
302 case GDK_BUTTON_PRESS: event_type = wxEVT_MIDDLE_DOWN; break;
303 case GDK_2BUTTON_PRESS: event_type = wxEVT_MIDDLE_DCLICK; break;
304 default: break;
305 };
306 }
307 else if (gdk_event->button == 3)
308 {
309 switch (gdk_event->type)
310 {
311 case GDK_BUTTON_PRESS: event_type = wxEVT_RIGHT_DOWN; break;
312 case GDK_2BUTTON_PRESS: event_type = wxEVT_RIGHT_DCLICK; break;
313 default: break;
314 };
315 };
316
317 wxMouseEvent event( event_type );
318 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
319 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
320 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
321 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
322 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
323 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
324 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
325
326 event.m_x = (long)gdk_event->x;
327 event.m_y = (long)gdk_event->y;
328 event.SetEventObject( win );
329
330 win->ProcessEvent( event );
331
332 return TRUE;
333};
334
335//-----------------------------------------------------------------------------
336// button_release
337
338gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
339{
340 if (widget->window != gdk_event->window) return TRUE;
341
342 if (g_blockEventsOnDrag) return FALSE;
343
344 if (!win->HasVMT()) return FALSE;
345
346/*
347 printf( "OnButtonRelease from " );
348 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
349 printf( win->GetClassInfo()->GetClassName() );
350 printf( ".\n" );
351*/
352
353 WXTYPE event_type = 0;
354
355 switch (gdk_event->button)
356 {
357 case 1: event_type = wxEVT_LEFT_UP; break;
358 case 2: event_type = wxEVT_MIDDLE_UP; break;
359 case 3: event_type = wxEVT_RIGHT_UP; break;
360 };
361
362 wxMouseEvent event( event_type );
363 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
364 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
365 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
366 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
367 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
368 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
369 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
370 event.m_x = (long)gdk_event->x;
371 event.m_y = (long)gdk_event->y;
372 event.SetEventObject( win );
373
374 return win->ProcessEvent( event );
375};
376
377//-----------------------------------------------------------------------------
378// motion_notify
379
380gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxWindow *win )
381{
382 if (widget->window != gdk_event->window) return TRUE;
383
384 if (g_blockEventsOnDrag) return FALSE;
385
386 if (!win->HasVMT()) return FALSE;
387
388/*
389 printf( "OnMotion from " );
390 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
391 printf( win->GetClassInfo()->GetClassName() );
392 printf( ".\n" );
393*/
394
395 wxMouseEvent event( wxEVT_MOTION );
396 event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK);
397 event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK);
398 event.m_altDown = (gdk_event->state & GDK_MOD1_MASK);
399 event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK);
400 event.m_leftDown = (gdk_event->state & GDK_BUTTON1_MASK);
401 event.m_middleDown = (gdk_event->state & GDK_BUTTON2_MASK);
402 event.m_rightDown = (gdk_event->state & GDK_BUTTON3_MASK);
403
404 event.m_x = (long)gdk_event->x;
405 event.m_y = (long)gdk_event->y;
406 event.SetEventObject( win );
407
408 win->ProcessEvent( event );
409
410 return FALSE;
411};
412
413//-----------------------------------------------------------------------------
414// focus_in
415
416void gtk_window_focus_in_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxWindow *win )
417{
418 if (g_blockEventsOnDrag) return;
419 if (win->m_wxwindow)
420 {
421 if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow))
422 {
423 GTK_WIDGET_SET_FLAGS (win->m_wxwindow, GTK_HAS_FOCUS);
424/*
425 printf( "SetFocus flag from " );
426 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
427 printf( win->GetClassInfo()->GetClassName() );
428 printf( ".\n" );
429*/
430 };
431 };
432
433 if (!win->HasVMT()) return;
434
435/*
436 printf( "OnSetFocus from " );
437 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
438 printf( win->GetClassInfo()->GetClassName() );
439 printf( " " );
440 printf( WXSTRINGCAST win->GetLabel() );
441 printf( ".\n" );
442*/
443
444 wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() );
445 event.SetEventObject( win );
446 win->ProcessEvent( event );
447};
448
449//-----------------------------------------------------------------------------
450// focus out
451
452void gtk_window_focus_out_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxWindow *win )
453{
454 if (g_blockEventsOnDrag) return;
455 if (win->m_wxwindow)
456 {
457 if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow))
458 GTK_WIDGET_UNSET_FLAGS (win->m_wxwindow, GTK_HAS_FOCUS);
459 };
460
461 if (!win->HasVMT()) return;
462
463/*
464 printf( "OnKillFocus from " );
465 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
466 printf( win->GetClassInfo()->GetClassName() );
467 printf( ".\n" );
468*/
469
470 wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() );
471 event.SetEventObject( win );
472 win->ProcessEvent( event );
473};
474
475//-----------------------------------------------------------------------------
476// vertical scroll
477
478void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
479{
480 if (g_blockEventsOnDrag) return;
481
482/*
483 printf( "OnVScroll from " );
484 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
485 printf( win->GetClassInfo()->GetClassName() );
486 printf( ".\n" );
487*/
488
489 if (!win->HasVMT()) return;
490
491 float diff = win->m_vAdjust->value - win->m_oldVerticalPos;
492 if (fabs(diff) < 0.2) return;
493
494/*
495 int i = (int)(win->m_oldVerticalPos+0.5);
496 printf( "Old value: %d.\n", i );
497 i = (int)(win->m_vAdjust->value+0.5);
498 printf( "Sending new value: %d.\n", i );
499*/
500
501 int command = 0;
502
503 float line_step = win->m_vAdjust->step_increment;
504 float page_step = win->m_vAdjust->page_increment;
505
506 if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
507 else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
508 else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
509 else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
510 else command = wxEVT_SCROLL_THUMBTRACK;
511
512 int value = (int)(win->m_vAdjust->value+0.5);
513
514 wxScrollEvent event( command, win->GetId(), value, wxVERTICAL );
515 event.SetEventObject( win );
516 win->ProcessEvent( event );
517};
518
519//-----------------------------------------------------------------------------
520// horizontal scroll
521
522void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
523{
524 if (g_blockEventsOnDrag) return;
525
526/*
527 printf( "OnHScroll from " );
528 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
529 printf( win->GetClassInfo()->GetClassName() );
530 printf( ".\n" );
531*/
532
533 if (!win->HasVMT()) return;
534
535 float diff = win->m_hAdjust->value - win->m_oldHorizontalPos;
536 if (fabs(diff) < 0.2) return;
537
538/*
539 int i = (int)(win->m_oldHorizontalPos+0.5);
540 printf( "Old value: %d.\n", i );
541 i = (int)(win->m_hAdjust->value+0.5);
542 printf( "Sending new value: %d.\n", i );
543*/
544
545 int command = 0;
546
547 float line_step = win->m_hAdjust->step_increment;
548 float page_step = win->m_hAdjust->page_increment;
549
550 if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
551 else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
552 else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
553 else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
554 else command = wxEVT_SCROLL_THUMBTRACK;
555
556 int value = (int)(win->m_hAdjust->value+0.5);
557
558 wxScrollEvent event( command, win->GetId(), value, wxHORIZONTAL );
559 event.SetEventObject( win );
560 win->ProcessEvent( event );
561};
562
563//-----------------------------------------------------------------------------
564// vertical scroll change
565
566void gtk_window_vscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
567{
568 if (g_blockEventsOnDrag) return;
569
570/*
571 printf( "OnVScroll change from " );
572 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
573 printf( win->GetClassInfo()->GetClassName() );
574 printf( ".\n" );
575*/
576
577 if (!win->HasVMT()) return;
578
579 int command = wxEVT_SCROLL_THUMBTRACK;
580 int value = (int)(win->m_vAdjust->value+0.5);
581
582 wxScrollEvent event( command, win->GetId(), value, wxVERTICAL );
583 event.SetEventObject( win );
584 win->ProcessEvent( event );
585};
586
587//-----------------------------------------------------------------------------
588// horizontal scroll change
589
590void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxWindow *win )
591{
592 if (g_blockEventsOnDrag) return;
593
594/*
595 printf( "OnHScroll change from " );
596 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
597 printf( win->GetClassInfo()->GetClassName() );
598 printf( ".\n" );
599*/
600
601 if (!win->HasVMT()) return;
602
603 int command = wxEVT_SCROLL_THUMBTRACK;
604 int value = (int)(win->m_hAdjust->value+0.5);
605
606 wxScrollEvent event( command, win->GetId(), value, wxHORIZONTAL );
607 event.SetEventObject( win );
608 win->ProcessEvent( event );
609};
610
611//-----------------------------------------------------------------------------
612// drop
613
614void gtk_window_drop_callback( GtkWidget *widget, GdkEvent *event, wxWindow *win )
615{
616 printf( "OnDrop.\n" );
617
618 if (win->GetDropTarget())
619 {
620 int x = 0;
621 int y = 0;
622 gdk_window_get_pointer( widget->window, &x, &y, NULL );
623 win->GetDropTarget()->Drop( event, x, y );
624 };
625
626/*
627 g_free (event->dropdataavailable.data);
628 g_free (event->dropdataavailable.data_type);
629*/
630}
631
632//-----------------------------------------------------------------------------
633// destroy
634
635bool gtk_window_destroy_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxWindow *win )
636{
637 printf( "OnDestroy from " );
638 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
639 printf( win->GetClassInfo()->GetClassName() );
640 printf( ".\n" );
641 printf( "Goodbye.\n" );
642 printf( " Robert Roebling.\n" );
643
644 return FALSE;
645};
646
647//-----------------------------------------------------------------------------
648// enter
649
650bool gtk_window_enter_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win )
651{
652 if (g_blockEventsOnDrag) return FALSE;
653
654 if (widget->window)
655 gdk_window_set_cursor( widget->window, win->m_cursor->GetCursor() );
656
657 return TRUE;
658};
659
660//-----------------------------------------------------------------------------
661// leave
662
663bool gtk_window_leave_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *WXUNUSED(win) )
664{
665 if (g_blockEventsOnDrag) return FALSE;
666
667 if (widget->window)
668 gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() );
669
670 return TRUE;
671};
672
673//-----------------------------------------------------------------------------
674// wxWindow implementation
675//-----------------------------------------------------------------------------
676
677IMPLEMENT_DYNAMIC_CLASS(wxWindow,wxEvtHandler)
678
679BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
680// EVT_CHAR(wxWindow::OnChar)
681 EVT_SIZE(wxWindow::OnSize)
682// EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
683 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
684 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
685// EVT_IDLE(wxWindow::OnIdle)
686END_EVENT_TABLE()
687
688wxWindow::wxWindow()
689{
690 m_widget = NULL;
691 m_wxwindow = NULL;
692 m_parent = NULL;
693 m_children.DeleteContents( FALSE );
694 m_x = 0;
695 m_y = 0;
696 m_width = 0;
697 m_height = 0;
698 m_retCode = 0;
699 m_eventHandler = this;
700 m_windowValidator = NULL;
701 m_windowId = -1;
702 m_cursor = new wxCursor( wxCURSOR_ARROW );
703 m_font = *wxSWISS_FONT;
704 m_windowStyle = 0;
705 m_windowName = "noname";
706 m_constraints = NULL;
707 m_constraintsInvolvedIn = NULL;
708 m_windowSizer = NULL;
709 m_sizerParent = NULL;
710 m_autoLayout = FALSE;
711 m_sizeSet = FALSE;
712 m_hasVMT = FALSE;
713 m_needParent = TRUE;
714 m_hasScrolling = FALSE;
715 m_hAdjust = NULL;
716 m_vAdjust = NULL;
717 m_oldHorizontalPos = 0.0;
718 m_oldVerticalPos = 0.0;
719 m_isShown = FALSE;
720 m_isEnabled = TRUE;
721 m_drawingOffsetX = 0;
722 m_drawingOffsetY = 0;
723 m_pDropTarget = NULL;
724};
725
726wxWindow::wxWindow( wxWindow *parent, const wxWindowID id,
727 const wxPoint &pos, const wxSize &size,
728 const long style, const wxString &name )
729{
730 Create( parent, id, pos, size, style, name );
731};
732
733bool wxWindow::Create( wxWindow *parent, const wxWindowID id,
734 const wxPoint &pos, const wxSize &size,
735 const long style, const wxString &name )
736{
737 m_isShown = FALSE;
738 m_isEnabled = TRUE;
739 m_needParent = TRUE;
740
741 PreCreation( parent, id, pos, size, style, name );
742
743 m_widget = gtk_scrolled_window_new( NULL, NULL );
744 m_hasScrolling = TRUE;
745
746 GtkScrolledWindow *s_window;
747 s_window = GTK_SCROLLED_WINDOW(m_widget);
748
749 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
750 scroll_class->scrollbar_spacing = 0;
751
752 gtk_scrolled_window_set_policy( s_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
753
754 m_oldHorizontalPos = 0.0;
755 m_oldVerticalPos = 0.0;
756
757 m_hAdjust = gtk_range_get_adjustment( GTK_RANGE(s_window->hscrollbar) );
758 m_vAdjust = gtk_range_get_adjustment( GTK_RANGE(s_window->vscrollbar) );
759
760 gtk_signal_connect (GTK_OBJECT (m_hAdjust), "value_changed",
761 (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this );
762 gtk_signal_connect (GTK_OBJECT (m_vAdjust), "value_changed",
763 (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this );
764
765 gtk_signal_connect (GTK_OBJECT (m_hAdjust), "changed",
766 (GtkSignalFunc) gtk_window_hscroll_change_callback, (gpointer) this );
767 gtk_signal_connect (GTK_OBJECT (m_vAdjust), "changed",
768 (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this );
769
770 GtkViewport *viewport;
771 viewport = GTK_VIEWPORT(s_window->viewport);
772
773 if (m_windowStyle & wxRAISED_BORDER)
774 {
775 gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_OUT );
776 }
777 else if (m_windowStyle & wxSUNKEN_BORDER)
778 {
779 gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_IN );
780 }
781 else
782 {
783 gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE );
784 };
785
786 m_wxwindow = gtk_myfixed_new();
787
788 if (m_windowStyle & wxTAB_TRAVERSAL == wxTAB_TRAVERSAL)
789 GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
790 else
791 GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
792
793 gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
794
795 // shut the viewport up
796 gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
797 gtk_viewport_set_vadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
798
799 // I _really_ don't want scrollbars in the beginning
800 m_vAdjust->lower = 0.0;
801 m_vAdjust->upper = 1.0;
802 m_vAdjust->value = 0.0;
803 m_vAdjust->step_increment = 1.0;
804 m_vAdjust->page_increment = 1.0;
805 m_vAdjust->page_size = 5.0;
806 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
807 m_hAdjust->lower = 0.0;
808 m_hAdjust->upper = 1.0;
809 m_hAdjust->value = 0.0;
810 m_hAdjust->step_increment = 1.0;
811 m_hAdjust->page_increment = 1.0;
812 m_hAdjust->page_size = 5.0;
813 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
814
815 gtk_widget_show( m_wxwindow );
816
817 PostCreation();
818
819 Show( TRUE );
820
821 return TRUE;
822};
823
824wxWindow::~wxWindow(void)
825{
826 m_hasVMT = FALSE;
827
828 if (m_pDropTarget) delete m_pDropTarget;
829
830 if (m_parent) m_parent->RemoveChild( this );
831 if (m_widget) Show( FALSE );
832
833 DestroyChildren();
834
835 if (m_wxwindow) gtk_widget_destroy( m_wxwindow );
836
837 if (m_widget) gtk_widget_destroy( m_widget );
838
839// delete m_cursor;
840
841 DeleteRelatedConstraints();
842 if (m_constraints)
843 {
844 // This removes any dangling pointers to this window
845 // in other windows' constraintsInvolvedIn lists.
846 UnsetConstraints(m_constraints);
847 delete m_constraints;
848 m_constraints = NULL;
849 }
850 if (m_windowSizer)
851 {
852 delete m_windowSizer;
853 m_windowSizer = NULL;
854 }
855 // If this is a child of a sizer, remove self from parent
856 if (m_sizerParent)
857 m_sizerParent->RemoveChild((wxWindow *)this);
858
859 // Just in case the window has been Closed, but
860 // we're then deleting immediately: don't leave
861 // dangling pointers.
862 wxPendingDelete.DeleteObject(this);
863
864 // Just in case we've loaded a top-level window via
865 // wxWindow::LoadNativeDialog but we weren't a dialog
866 // class
867 wxTopLevelWindows.DeleteObject(this);
868
869};
870
871void wxWindow::PreCreation( wxWindow *parent, const wxWindowID id,
872 const wxPoint &pos, const wxSize &size,
873 const long style, const wxString &name )
874{
875 if (m_needParent && (parent == NULL))
876 wxFatalError( "Need complete parent.", name );
877
878 m_widget = NULL;
879 m_hasVMT = FALSE;
880 m_parent = parent;
881 m_children.DeleteContents( FALSE );
882 m_x = (int)pos.x;
883 m_y = (int)pos.y;
884 m_width = size.x;
885 if (m_width == -1) m_width = 20;
886 m_height = size.y;
887 if (m_height == -1) m_height = 20;
888 m_retCode = 0;
889 m_eventHandler = this;
890 m_windowValidator = NULL;
891 m_windowId = id;
892 m_sizeSet = FALSE;
893 m_cursor = new wxCursor( wxCURSOR_ARROW );
894 m_font = *wxSWISS_FONT;
895 m_backgroundColour = wxWHITE;
896 m_foregroundColour = wxBLACK;
897 m_windowStyle = style;
898 m_windowName = name;
899 m_constraints = NULL;
900 m_constraintsInvolvedIn = NULL;
901 m_windowSizer = NULL;
902 m_sizerParent = NULL;
903 m_autoLayout = FALSE;
904 m_drawingOffsetX = 0;
905 m_drawingOffsetY = 0;
906 m_pDropTarget = NULL;
907}
908
909void wxWindow::PostCreation(void)
910{
911 if (m_parent) m_parent->AddChild( this );
912
913// GtkStyle *style = m_widget->style;
914// style->font = m_font.GetInternalFont( 1.0 ); // destroy old font ?
915
916 GtkWidget *connect_widget = m_widget;
917 if (m_wxwindow) connect_widget = m_wxwindow;
918
919 gtk_object_set_data (GTK_OBJECT (connect_widget), "MyWxWindow", (gpointer)this );
920
921 if (m_wxwindow)
922 {
923 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event",
924 GTK_SIGNAL_FUNC(gtk_window_expose_callback), (gpointer)this );
925
926 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw",
927 GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this );
928 };
929
930/*
931 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
932 GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this );
933*/
934
935 gtk_signal_connect( GTK_OBJECT(connect_widget), "key_press_event",
936 GTK_SIGNAL_FUNC(gtk_window_key_press_callback), (gpointer)this );
937
938 gtk_signal_connect( GTK_OBJECT(connect_widget), "button_press_event",
939 GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this );
940
941 gtk_signal_connect( GTK_OBJECT(connect_widget), "button_release_event",
942 GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
943
944 gtk_signal_connect( GTK_OBJECT(connect_widget), "motion_notify_event",
945 GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
946
947 gtk_signal_connect( GTK_OBJECT(connect_widget), "focus_in_event",
948 GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
949
950 gtk_signal_connect( GTK_OBJECT(connect_widget), "focus_out_event",
951 GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
952
953 gtk_signal_connect( GTK_OBJECT(connect_widget), "drop_data_available_event",
954 GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this );
955
956 // Only for cursor handling
957
958 gtk_signal_connect( GTK_OBJECT(m_widget), "enter_notify_event",
959 GTK_SIGNAL_FUNC(gtk_window_enter_callback), (gpointer)this );
960
961 gtk_signal_connect( GTK_OBJECT(m_widget), "leave_notify_event",
962 GTK_SIGNAL_FUNC(gtk_window_leave_callback), (gpointer)this );
963
964 if (m_wxwindow)
965 {
966 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "enter_notify_event",
967 GTK_SIGNAL_FUNC(gtk_window_enter_callback), (gpointer)this );
968
969 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "leave_notify_event",
970 GTK_SIGNAL_FUNC(gtk_window_leave_callback), (gpointer)this );
971 };
972
973/*
974 // Does destroy ever get called ?
975
976 gtk_signal_connect( GTK_OBJECT(m_widget), "destroy_event",
977 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
978
979 if (m_wxwindow)
980 {
981 gtk_signal_connect( GTK_OBJECT(m_wxwindow), "destroy_event",
982 GTK_SIGNAL_FUNC(gtk_window_destroy_callback), (gpointer)this );
983 };
984*/
985
986 if (m_widget && m_parent) gtk_widget_realize( m_widget );
987 if (m_wxwindow) gtk_widget_realize( m_wxwindow );
988
989 SetCursor( wxSTANDARD_CURSOR );
990
991 m_hasVMT = TRUE;
992};
993
994bool wxWindow::HasVMT(void)
995{
996 return m_hasVMT;
997};
998
999bool wxWindow::Close( const bool force )
1000{
1001 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
1002 event.SetEventObject(this);
1003 event.SetForce(force);
1004
1005 return GetEventHandler()->ProcessEvent(event);
1006};
1007
1008bool wxWindow::Destroy(void)
1009{
1010 m_hasVMT = FALSE;
1011 delete this;
1012 return TRUE;
1013};
1014
1015bool wxWindow::DestroyChildren(void)
1016{
1017 if (GetChildren())
1018 {
1019 wxNode *node;
1020 while ((node = GetChildren()->First()) != (wxNode *)NULL)
1021 {
1022 wxWindow *child;
1023 if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL)
1024 {
1025 delete child;
1026 if (GetChildren()->Member(child)) delete node;
1027 };
1028 };
1029 };
1030 return TRUE;
1031};
1032
1033void wxWindow::PrepareDC( wxDC &WXUNUSED(dc) )
1034{
1035 // are we to set fonts here ?
1036};
1037
1038void wxWindow::ImplementSetSize(void)
1039{
1040 gtk_widget_set_usize( m_widget, m_width, m_height );
1041};
1042
1043void wxWindow::ImplementSetPosition(void)
1044{
1045 if ((m_parent) && (m_parent->m_wxwindow))
1046 gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x, m_y );
1047 else
1048 gtk_widget_set_uposition( m_widget, m_x, m_y );
1049};
1050
1051void wxWindow::SetSize( const int x, const int y, const int width, const int height, const int sizeFlags )
1052{
1053 int newX = x;
1054 int newY = y;
1055 int newW = width;
1056 int newH = height;
1057
1058 if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING)
1059 {
1060 if (newX == -1) newX = m_x;
1061 if (newY == -1) newY = m_y;
1062 if (newW == -1) newW = m_width;
1063 if (newH == -1) newH = m_height;
1064 };
1065
1066 if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH)
1067 {
1068 if (newW == -1) newW = 80;
1069 };
1070
1071 if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT)
1072 {
1073 if (newH == -1) newH = 26;
1074 };
1075
1076 if ((m_x != newX) || (m_y != newY) || (!m_sizeSet))
1077 {
1078 m_x = newX;
1079 m_y = newY;
1080 ImplementSetPosition();
1081 };
1082 if ((m_width != newW) || (m_height != newH) || (!m_sizeSet))
1083 {
1084 m_width = newW;
1085 m_height = newH;
1086 ImplementSetSize();
1087 };
1088 m_sizeSet = TRUE;
1089
1090 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
1091 event.SetEventObject( this );
1092 ProcessEvent( event );
1093};
1094
1095void wxWindow::SetSize( const int width, const int height )
1096{
1097 SetSize( -1, -1, width, height, wxSIZE_USE_EXISTING );
1098};
1099
1100void wxWindow::Move( const int x, const int y )
1101{
1102 SetSize( x, y, -1, -1, wxSIZE_USE_EXISTING );
1103};
1104
1105void wxWindow::GetSize( int *width, int *height ) const
1106{
1107 (*width) = m_width;
1108 (*height) = m_height;
1109};
1110
1111void wxWindow::SetClientSize( const int width, const int height )
1112{
1113 if (!m_wxwindow)
1114 {
1115 SetSize( width, height );
1116 }
1117 else
1118 {
1119 int dw = 0;
1120 int dh = 0;
1121
1122 if (!m_hasScrolling)
1123 {
1124/*
1125 do we have sunken dialogs ?
1126
1127 GtkStyleClass *window_class = m_wxwindow->style->klass;
1128
1129 dw += 2 * window_class->xthickness;
1130 dh += 2 * window_class->ythickness;
1131*/
1132 }
1133 else
1134 {
1135 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
1136 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
1137
1138 GtkWidget *viewport = scroll_window->viewport;
1139 GtkStyleClass *viewport_class = viewport->style->klass;
1140
1141 GtkWidget *hscrollbar = scroll_window->hscrollbar;
1142 GtkWidget *vscrollbar = scroll_window->vscrollbar;
1143
1144 if ((m_windowStyle & wxRAISED_BORDER) ||
1145 (m_windowStyle & wxSUNKEN_BORDER)
1146 )
1147 {
1148 dw += 2 * viewport_class->xthickness;
1149 dh += 2 * viewport_class->ythickness;
1150 };
1151
1152 if (GTK_WIDGET_VISIBLE(vscrollbar))
1153 {
1154 dw += vscrollbar->allocation.width;
1155 dw += scroll_class->scrollbar_spacing;
1156 };
1157
1158 if (GTK_WIDGET_VISIBLE(hscrollbar))
1159 {
1160 dh += hscrollbar->allocation.height;
1161 dw += scroll_class->scrollbar_spacing;
1162 };
1163 };
1164
1165 SetSize( width+dw, height+dh );
1166 };
1167};
1168
1169void wxWindow::GetClientSize( int *width, int *height ) const
1170{
1171 if (!m_wxwindow)
1172 {
1173 if (width) (*width) = m_width;
1174 if (height) (*height) = m_height;
1175 }
1176 else
1177 {
1178 int dw = 0;
1179 int dh = 0;
1180
1181 if (!m_hasScrolling)
1182 {
1183/*
1184 do we have sunken dialogs ?
1185
1186 GtkStyleClass *window_class = m_wxwindow->style->klass;
1187
1188 dw += 2 * window_class->xthickness;
1189 dh += 2 * window_class->ythickness;
1190*/
1191 }
1192 else
1193 {
1194 GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
1195 GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
1196
1197 GtkWidget *viewport = scroll_window->viewport;
1198 GtkStyleClass *viewport_class = viewport->style->klass;
1199
1200 GtkWidget *hscrollbar = scroll_window->hscrollbar;
1201 GtkWidget *vscrollbar = scroll_window->vscrollbar;
1202
1203 if ((m_windowStyle & wxRAISED_BORDER) ||
1204 (m_windowStyle & wxSUNKEN_BORDER)
1205 )
1206 {
1207 dw += 2 * viewport_class->xthickness;
1208 dh += 2 * viewport_class->ythickness;
1209 };
1210
1211 if (GTK_WIDGET_VISIBLE(vscrollbar))
1212 {
1213// dw += vscrollbar->allocation.width;
1214 dw += 15; // range.slider_width = 11 + 2*2pts edge
1215 dw += scroll_class->scrollbar_spacing;
1216 };
1217
1218 if (GTK_WIDGET_VISIBLE(hscrollbar))
1219 {
1220// dh += hscrollbar->allocation.height;
1221 dh += 15;
1222 dh += scroll_class->scrollbar_spacing;
1223 };
1224 };
1225
1226 if (width) (*width) = m_width - dw;
1227 if (height) (*height) = m_height - dh;
1228 };
1229};
1230
1231void wxWindow::GetPosition( int *x, int *y ) const
1232{
1233 if (x) (*x) = m_x;
1234 if (y) (*y) = m_y;
1235};
1236
1237void wxWindow::ClientToScreen( int *x, int *y )
1238{
1239 // Does this look simple ?
1240
1241 GdkWindow *source = NULL;
1242 if (m_wxwindow)
1243 source = m_wxwindow->window;
1244 else
1245 source = m_widget->window;
1246
1247 int org_x = 0;
1248 int org_y = 0;
1249 gdk_window_get_origin( source, &org_x, &org_y );
1250
1251 if (!m_wxwindow)
1252 {
1253 if (GTK_WIDGET_NO_WINDOW (m_widget))
1254 {
1255 org_x += m_widget->allocation.x;
1256 org_y += m_widget->allocation.y;
1257 };
1258 };
1259
1260 if (x) *x += org_x;
1261 if (y) *y += org_y;
1262};
1263
1264void wxWindow::ScreenToClient( int *x, int *y )
1265{
1266 GdkWindow *source = NULL;
1267 if (m_wxwindow)
1268 source = m_wxwindow->window;
1269 else
1270 source = m_widget->window;
1271
1272 int org_x = 0;
1273 int org_y = 0;
1274 gdk_window_get_origin( source, &org_x, &org_y );
1275
1276 if (!m_wxwindow)
1277 {
1278 if (GTK_WIDGET_NO_WINDOW (m_widget))
1279 {
1280 org_x += m_widget->allocation.x;
1281 org_y += m_widget->allocation.y;
1282 };
1283 };
1284
1285 if (x) *x -= org_x;
1286 if (y) *y -= org_y;
1287};
1288
1289void wxWindow::Centre( const int direction )
1290{
1291 int x = 0;
1292 int y = 0;
1293 GetPosition( &x, &y );
1294 if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame)))
1295 {
1296 if (direction & wxHORIZONTAL == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2;
1297 if (direction & wxVERTICAL == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2;
1298 gtk_widget_set_uposition( m_widget, x, y );
1299 }
1300 else
1301 {
1302 if (m_parent)
1303 {
1304 int p_w = 0;
1305 int p_h = 0;
1306 m_parent->GetSize( &p_w, &p_h );
1307 if (direction & wxHORIZONTAL == wxHORIZONTAL) x = (p_w - m_width) / 2;
1308 if (direction & wxVERTICAL == wxVERTICAL) y = (p_h - m_height) / 2;
1309 gtk_widget_set_uposition( m_widget, x, y );
1310 };
1311 }
1312};
1313
1314void wxWindow::Fit(void)
1315{
1316 int maxX = 0;
1317 int maxY = 0;
1318 wxNode *node = GetChildren()->First();
1319 while ( node )
1320 {
1321 wxWindow *win = (wxWindow *)node->Data();
1322 int wx, wy, ww, wh;
1323 win->GetPosition(&wx, &wy);
1324 win->GetSize(&ww, &wh);
1325 if ( wx + ww > maxX )
1326 maxX = wx + ww;
1327 if ( wy + wh > maxY )
1328 maxY = wy + wh;
1329
1330 node = node->Next();
1331 }
1332 SetClientSize(maxX + 5, maxY + 5);
1333};
1334
1335void wxWindow::OnSize( wxSizeEvent &WXUNUSED(event) )
1336{
1337 if (GetAutoLayout()) Layout();
1338};
1339
1340bool wxWindow::Show( const bool show )
1341{
1342 if (show)
1343 gtk_widget_show( m_widget );
1344 else
1345 gtk_widget_hide( m_widget );
1346 m_isShown = show;
1347 return TRUE;
1348};
1349
1350void wxWindow::Enable( const bool enable )
1351{
1352 m_isEnabled = enable;
1353 gtk_widget_set_sensitive( m_widget, enable );
1354 if (m_wxwindow) gtk_widget_set_sensitive( m_wxwindow, enable );
1355};
1356
1357void wxWindow::MakeModal( const bool modal )
1358{
1359 return;
1360 // Disable all other windows
1361 if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame)))
1362 {
1363 wxNode *node = wxTopLevelWindows.First();
1364 while (node)
1365 {
1366 wxWindow *win = (wxWindow *)node->Data();
1367 if (win != this)
1368 win->Enable(!modal);
1369
1370 node = node->Next();
1371 }
1372 }
1373}
1374
1375void wxWindow::SetFocus(void)
1376{
1377 GtkWidget *connect_widget = m_widget;
1378 if (m_wxwindow) connect_widget = m_wxwindow;
1379 if (connect_widget)
1380 {
1381 if (GTK_WIDGET_CAN_FOCUS(connect_widget) && !GTK_WIDGET_HAS_FOCUS (connect_widget) )
1382 {
1383 gtk_widget_grab_focus (connect_widget);
1384 };
1385 };
1386};
1387
1388bool wxWindow::OnClose(void)
1389{
1390 printf( "OnClose event.\n" );
1391 return TRUE;
1392};
1393
1394void wxWindow::AddChild( wxWindow *child )
1395{
1396 // Addchild is (often) called before the program
1397 // has left the parents constructor so that no
1398 // virtual tables work yet. The approach below
1399 // practically imitates virtual tables, i.e. it
1400 // implements a different AddChild() behaviour
1401 // for wxFrame, wxDialog, wxWindow and
1402 // wxMDIParentFrame.
1403
1404 if (IsKindOf(CLASSINFO(wxMDIParentFrame)))
1405 {
1406 if (child->IsKindOf(CLASSINFO(wxMDIChildFrame)))
1407 {
1408 wxMDIClientWindow *client = ((wxMDIParentFrame*)this)->GetClientWindow();
1409 if (client)
1410 {
1411 client->AddChild( child );
1412 return;
1413 };
1414 };
1415 };
1416 m_children.Append( child );
1417 if (child->IsKindOf(CLASSINFO(wxFrame)) || child->IsKindOf(CLASSINFO(wxDialog)))
1418 {
1419 if ((child->m_x != -1) && (child->m_y != -1))
1420 gtk_widget_set_uposition( child->m_widget, child->m_x, child->m_y );
1421 }
1422 else
1423 {
1424 if (m_wxwindow)
1425 gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), child->m_widget, child->m_x, child->m_y );
1426 };
1427 gtk_widget_set_usize( child->m_widget, child->m_width, child->m_height );
1428};
1429
1430wxList *wxWindow::GetChildren(void)
1431{
1432 return (&m_children);
1433};
1434
1435void wxWindow::RemoveChild( wxWindow *child )
1436{
1437 if (GetChildren())
1438 GetChildren()->DeleteObject( child );
1439 child->m_parent = NULL;
1440};
1441
1442void wxWindow::SetReturnCode( int retCode )
1443{
1444 m_retCode = retCode;
1445};
1446
1447int wxWindow::GetReturnCode(void)
1448{
1449 return m_retCode;
1450};
1451
1452wxWindow *wxWindow::GetParent(void)
1453{
1454 return m_parent;
1455};
1456
1457wxEvtHandler *wxWindow::GetEventHandler(void)
1458{
1459 return m_eventHandler;
1460};
1461
1462void wxWindow::SetEventhandler( wxEvtHandler *handler )
1463{
1464 m_eventHandler = handler;
1465};
1466
1467wxValidator *wxWindow::GetValidator(void)
1468{
1469 return m_windowValidator;
1470};
1471
1472void wxWindow::SetValidator( wxValidator *validator )
1473{
1474 m_windowValidator = validator;
1475};
1476
1477bool wxWindow::IsBeingDeleted(void)
1478{
1479 return FALSE;
1480};
1481
1482void wxWindow::SetId( wxWindowID id )
1483{
1484 m_windowId = id;
1485};
1486
1487wxWindowID wxWindow::GetId(void)
1488{
1489 return m_windowId;
1490};
1491
1492void wxWindow::SetCursor( const wxCursor &cursor )
1493{
1494 if (*m_cursor == cursor) return;
1495 (*m_cursor) = cursor;
1496 if (m_widget->window)
1497 gdk_window_set_cursor( m_widget->window, m_cursor->GetCursor() );
1498 if (m_wxwindow && m_wxwindow->window)
1499 gdk_window_set_cursor( m_wxwindow->window, m_cursor->GetCursor() );
1500};
1501
1502void wxWindow::Refresh( const bool eraseBackground, const wxRect *rect )
1503{
1504 if (eraseBackground && m_wxwindow && m_wxwindow->window)
1505 {
1506 if (rect)
1507 gdk_window_clear_area( m_wxwindow->window,
1508 rect->x,
1509 rect->y,
1510 rect->width,
1511 rect->height );
1512 else
1513 Clear();
1514 };
1515 if (!rect)
1516 {
1517 if (m_wxwindow)
1518 {
1519 wxClientDC dc(this);
1520 PrepareDC(dc);
1521 long x = 0;
1522 long y = 0;
1523 dc.GetInternalDeviceOrigin( &x, &y );
1524
1525 int w = 0;
1526 int h = 0;
1527 GetClientSize( &w, &h );
1528
1529 GdkRectangle gdk_rect;
1530 gdk_rect.x = x;
1531 gdk_rect.y = y;
1532 gdk_rect.width = w;
1533 gdk_rect.height = h;
1534 gtk_widget_draw( m_wxwindow, &gdk_rect );
1535 };
1536 }
1537 else
1538 {
1539 GdkRectangle gdk_rect;
1540 gdk_rect.x = rect->x;
1541 gdk_rect.y = rect->y;
1542 gdk_rect.width = rect->width;
1543 gdk_rect.height = rect->height;
1544 if (m_wxwindow)
1545 gtk_widget_draw( m_wxwindow, &gdk_rect );
1546 else
1547 gtk_widget_draw( m_widget, &gdk_rect );
1548 };
1549};
1550
1551bool wxWindow::IsExposed( const long x, const long y )
1552{
1553 return (m_updateRegion.Contains( x, y ) != wxOutRegion );
1554};
1555
1556bool wxWindow::IsExposed( const long x, const long y, const long width, const long height )
1557{
1558 return (m_updateRegion.Contains( x, y, width, height ) != wxOutRegion );
1559};
1560
1561void wxWindow::Clear(void)
1562{
1563 if (m_wxwindow && m_wxwindow->window) gdk_window_clear( m_wxwindow->window );
1564};
1565
1566wxColour wxWindow::GetBackgroundColour(void) const
1567{
1568 return m_backgroundColour;
1569};
1570
1571void wxWindow::SetBackgroundColour( const wxColour &colour )
1572{
1573 m_backgroundColour = colour;
1574 if (m_wxwindow)
1575 {
1576 m_backgroundColour.CalcPixel( m_wxwindow->style->colormap );
1577 gdk_window_set_background( m_wxwindow->window, m_backgroundColour.GetColor() );
1578 gdk_window_clear( m_wxwindow->window );
1579 };
1580 // do something ?
1581};
1582
1583bool wxWindow::Validate(void)
1584{
1585 wxNode *node = GetChildren()->First();
1586 while (node)
1587 {
1588 wxWindow *child = (wxWindow *)node->Data();
1589 if (child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this))
1590 { return FALSE; }
1591 node = node->Next();
1592 };
1593 return TRUE;
1594};
1595
1596bool wxWindow::TransferDataToWindow(void)
1597{
1598 wxNode *node = GetChildren()->First();
1599 while (node)
1600 {
1601 wxWindow *child = (wxWindow *)node->Data();
1602 if (child->GetValidator() && /* child->GetValidator()->Ok() && */
1603 !child->GetValidator()->TransferToWindow() )
1604 {
1605 wxMessageBox( "Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION );
1606 return FALSE;
1607 };
1608 node = node->Next();
1609 };
1610 return TRUE;
1611};
1612
1613bool wxWindow::TransferDataFromWindow(void)
1614{
1615 wxNode *node = GetChildren()->First();
1616 while (node)
1617 {
1618 wxWindow *child = (wxWindow *)node->Data();
1619 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->TransferFromWindow() )
1620 { return FALSE; }
1621 node = node->Next();
1622 }
1623 return TRUE;
1624};
1625
1626void wxWindow::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
1627{
1628 TransferDataToWindow();
1629};
1630
1631void wxWindow::InitDialog(void)
1632{
1633 wxInitDialogEvent event(GetId());
1634 event.SetEventObject( this );
1635 GetEventHandler()->ProcessEvent(event);
1636};
1637
1638void wxWindow::SetDropTarget( wxDropTarget *dropTarget )
1639{
1640 GtkWidget *connect_widget = m_widget;
1641 if (m_wxwindow) connect_widget = m_wxwindow;
1642 if (m_pDropTarget)
1643 {
1644 m_pDropTarget->UnregisterWidget( connect_widget );
1645 delete m_pDropTarget;
1646 };
1647 m_pDropTarget = dropTarget;
1648 if (m_pDropTarget)
1649 {
1650 m_pDropTarget->RegisterWidget( connect_widget );
1651 };
1652};
1653
1654wxDropTarget *wxWindow::GetDropTarget() const
1655{
1656 return m_pDropTarget;
1657};
1658
1659void wxWindow::SetFont( const wxFont &font )
1660{
1661 m_font = font;
1662/*
1663 create new style
1664 copy old style values to new one
1665 set font in new style
1666 -> takes to many resources
1667
1668 GtkStyle *style = gtk_style_new();
1669 ...
1670*/
1671};
1672
1673wxFont *wxWindow::GetFont(void)
1674{
1675 return &m_font;
1676};
1677
1678void wxWindow::SetWindowStyleFlag( long flag )
1679{
1680 m_windowStyle = flag;
1681};
1682
1683long wxWindow::GetWindowStyleFlag(void) const
1684{
1685 return m_windowStyle;
1686};
1687
1688void wxWindow::CaptureMouse(void)
1689{
1690 GtkWidget *connect_widget = m_widget;
1691 if (m_wxwindow) connect_widget = m_wxwindow;
1692 gtk_grab_add( connect_widget );
1693 gdk_pointer_grab ( connect_widget->window, FALSE,
1694 (GdkEventMask)
1695 (GDK_BUTTON_PRESS_MASK |
1696 GDK_BUTTON_RELEASE_MASK |
1697 GDK_POINTER_MOTION_MASK),
1698 NULL, NULL, GDK_CURRENT_TIME );
1699};
1700
1701void wxWindow::ReleaseMouse(void)
1702{
1703 GtkWidget *connect_widget = m_widget;
1704 if (m_wxwindow) connect_widget = m_wxwindow;
1705 gtk_grab_remove( connect_widget );
1706 gdk_pointer_ungrab ( GDK_CURRENT_TIME );
1707};
1708
1709void wxWindow::SetTitle( const wxString &WXUNUSED(title) )
1710{
1711};
1712
1713wxString wxWindow::GetTitle(void) const
1714{
1715 return (wxString&)m_windowName;
1716};
1717
1718wxString wxWindow::GetLabel(void) const
1719{
1720 return GetTitle();
1721};
1722
1723void wxWindow::SetName( const wxString &name )
1724{
1725 m_windowName = name;
1726};
1727
1728wxString wxWindow::GetName(void) const
1729{
1730 return (wxString&)m_windowName;
1731};
1732
1733bool wxWindow::IsShown(void)
1734{
1735 return m_isShown;
1736};
1737
1738bool wxWindow::IsRetained(void)
1739{
1740 return FALSE;
1741};
1742
1743wxWindow *wxWindow::FindWindow( const long id )
1744{
1745 if (id == m_windowId) return this;
1746 wxNode *node = m_children.First();
1747 while (node)
1748 {
1749 wxWindow *child = (wxWindow*)node->Data();
1750 wxWindow *res = child->FindWindow( id );
1751 if (res) return res;
1752 node = node->Next();
1753 };
1754 return NULL;
1755};
1756
1757wxWindow *wxWindow::FindWindow( const wxString& name )
1758{
1759 if (name == m_windowName) return this;
1760 wxNode *node = m_children.First();
1761 while (node)
1762 {
1763 wxWindow *child = (wxWindow*)node->Data();
1764 wxWindow *res = child->FindWindow( name );
1765 if (res) return res;
1766 node = node->Next();
1767 };
1768 return NULL;
1769};
1770
1771void wxWindow::SetScrollbar( const int orient, const int pos, const int thumbVisible,
1772 const int range, const bool WXUNUSED(refresh) )
1773{
1774 if (!m_wxwindow) return;
1775
1776 if (orient == wxHORIZONTAL)
1777 {
1778 float fpos = (float)pos;
1779 m_oldHorizontalPos = fpos;
1780 float frange = (float)range;
1781 float fthumb = (float)thumbVisible;
1782
1783 if ((fabs(fpos-m_hAdjust->value) < 0.2) &&
1784 (fabs(frange-m_hAdjust->upper) < 0.2) &&
1785 (fabs(fthumb-m_hAdjust->page_size) < 0.2))
1786 return;
1787
1788 m_hAdjust->lower = 0.0;
1789 m_hAdjust->upper = frange;
1790 m_hAdjust->value = fpos;
1791 m_hAdjust->step_increment = 1.0;
1792 m_hAdjust->page_increment = (float)(wxMax(fthumb-2,0));
1793 m_hAdjust->page_size = fthumb;
1794 }
1795 else
1796 {
1797 float fpos = (float)pos;
1798 m_oldVerticalPos = fpos;
1799 float frange = (float)range;
1800 float fthumb = (float)thumbVisible;
1801
1802 if ((fabs(fpos-m_vAdjust->value) < 0.2) &&
1803 (fabs(frange-m_vAdjust->upper) < 0.2) &&
1804 (fabs(fthumb-m_vAdjust->page_size) < 0.2))
1805 return;
1806
1807 m_vAdjust->lower = 0.0;
1808 m_vAdjust->upper = frange;
1809 m_vAdjust->value = fpos;
1810 m_vAdjust->step_increment = 1.0;
1811 m_vAdjust->page_increment = (float)(wxMax(fthumb-2,0));
1812 m_vAdjust->page_size = fthumb;
1813 };
1814
1815 if (m_wxwindow->window)
1816 {
1817 if (orient == wxHORIZONTAL)
1818 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
1819 else
1820 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "changed" );
1821
1822// gtk_widget_set_usize( m_widget, m_width, m_height );
1823 };
1824};
1825
1826void wxWindow::SetScrollPos( const int orient, const int pos, const bool WXUNUSED(refresh) )
1827{
1828 if (!m_wxwindow) return;
1829
1830 if (orient == wxHORIZONTAL)
1831 {
1832 float fpos = (float)pos;
1833 m_oldHorizontalPos = fpos;
1834
1835 if (fabs(fpos-m_hAdjust->value) < 0.2) return;
1836 m_hAdjust->value = fpos;
1837 }
1838 else
1839 {
1840 float fpos = (float)pos;
1841 m_oldVerticalPos = fpos;
1842 if (fabs(fpos-m_vAdjust->value) < 0.2) return;
1843 m_vAdjust->value = fpos;
1844 };
1845
1846 if (m_wxwindow->window)
1847 {
1848 if (orient == wxHORIZONTAL)
1849 gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" );
1850 else
1851 gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" );
1852 };
1853};
1854
1855int wxWindow::GetScrollThumb( const int orient ) const
1856{
1857 if (!m_wxwindow) return 0;
1858
1859 if (orient == wxHORIZONTAL)
1860 return (int)(m_hAdjust->page_size+0.5);
1861 else
1862 return (int)(m_vAdjust->page_size+0.5);
1863};
1864
1865int wxWindow::GetScrollPos( const int orient ) const
1866{
1867 if (!m_wxwindow) return 0;
1868
1869 if (orient == wxHORIZONTAL)
1870 return (int)(m_hAdjust->value+0.5);
1871 else
1872 return (int)(m_vAdjust->value+0.5);
1873};
1874
1875int wxWindow::GetScrollRange( const int orient ) const
1876{
1877 if (!m_wxwindow) return 0;
1878
1879 if (orient == wxHORIZONTAL)
1880 return (int)(m_hAdjust->upper+0.5);
1881 else
1882 return (int)(m_vAdjust->upper+0.5);
1883};
1884
1885void wxWindow::ScrollWindow( const int dx, const int dy, const wxRect* WXUNUSED(rect) )
1886{
1887 if (!m_wxwindow) return;
1888
1889 m_drawingOffsetX += dx;
1890 m_drawingOffsetY += dy;
1891
1892// printf( "X: %d Y: %d \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
1893
1894 gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
1895
1896/*
1897 The code here is very nifty, but it doesn't work with
1898 overlapping windows...
1899
1900 int cw = 0;
1901 int ch = 0;
1902 GetClientSize( &cw, &ch );
1903
1904 int w = cw - abs(dx);
1905 int h = ch - abs(dy);
1906 if ((h < 0) || (w < 0))
1907 {
1908 Refresh();
1909 return;
1910 };
1911 int s_x = 0;
1912 int s_y = 0;
1913 if (dx < 0) s_x = -dx;
1914 if (dy < 0) s_y = -dy;
1915 int d_x = 0;
1916 int d_y = 0;
1917 if (dx > 0) d_x = dx;
1918 if (dy > 0) d_y = dy;
1919 gdk_window_copy_area( m_wxwindow->window, m_wxwindow->style->fg_gc[0], d_x, d_y,
1920 m_wxwindow->window, s_x, s_y, w, h );
1921
1922 wxRect rect;
1923 if (dx < 0) rect.x = cw+dx; else rect.x = 0;
1924 if (dy < 0) rect.y = ch+dy; else rect.y = 0;
1925 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
1926 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
1927
1928 Refresh( TRUE, &rect );
1929*/
1930};
1931
1932void wxWindow::GetDrawingOffset( long *x, long *y )
1933{
1934 if (x) *x = m_drawingOffsetX;
1935 if (y) *y = m_drawingOffsetY;
1936};
1937
1938//-------------------------------------------------------------------------------------
1939// Layout
1940//-------------------------------------------------------------------------------------
1941
1942wxLayoutConstraints *wxWindow::GetConstraints(void) const
1943{
1944 return m_constraints;
1945};
1946
1947void wxWindow::SetConstraints( wxLayoutConstraints *constraints )
1948{
1949 if (m_constraints)
1950 {
1951 UnsetConstraints(m_constraints);
1952 delete m_constraints;
1953 }
1954 m_constraints = constraints;
1955 if (m_constraints)
1956 {
1957 // Make sure other windows know they're part of a 'meaningful relationship'
1958 if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this))
1959 m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1960 if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this))
1961 m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1962 if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this))
1963 m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1964 if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this))
1965 m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1966 if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this))
1967 m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1968 if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this))
1969 m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1970 if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this))
1971 m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1972 if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this))
1973 m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1974 }
1975;
1976}
1977;
1978
1979void wxWindow::SetAutoLayout( const bool autoLayout )
1980{
1981 m_autoLayout = autoLayout;
1982};
1983
1984bool wxWindow::GetAutoLayout(void) const
1985{
1986 return m_autoLayout;
1987};
1988
1989wxSizer *wxWindow::GetSizer(void) const
1990{
1991 return m_windowSizer;
1992};
1993
1994void wxWindow::SetSizerParent( wxWindow *win )
1995{
1996 m_sizerParent = win;
1997};
1998
1999wxWindow *wxWindow::GetSizerParent(void) const
2000{
2001 return m_sizerParent;
2002};
2003
2004// This removes any dangling pointers to this window
2005// in other windows' constraintsInvolvedIn lists.
2006void wxWindow::UnsetConstraints(wxLayoutConstraints *c)
2007{
2008 if (c)
2009 {
2010 if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this))
2011 c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
2012 if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this))
2013 c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
2014 if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this))
2015 c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
2016 if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this))
2017 c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
2018 if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this))
2019 c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
2020 if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this))
2021 c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
2022 if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this))
2023 c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
2024 if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this))
2025 c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
2026 }
2027}
2028
2029// Back-pointer to other windows we're involved with, so if we delete
2030// this window, we must delete any constraints we're involved with.
2031void wxWindow::AddConstraintReference(wxWindow *otherWin)
2032{
2033 if (!m_constraintsInvolvedIn)
2034 m_constraintsInvolvedIn = new wxList;
2035 if (!m_constraintsInvolvedIn->Member(otherWin))
2036 m_constraintsInvolvedIn->Append(otherWin);
2037}
2038
2039// REMOVE back-pointer to other windows we're involved with.
2040void wxWindow::RemoveConstraintReference(wxWindow *otherWin)
2041{
2042 if (m_constraintsInvolvedIn)
2043 m_constraintsInvolvedIn->DeleteObject(otherWin);
2044}
2045
2046// Reset any constraints that mention this window
2047void wxWindow::DeleteRelatedConstraints(void)
2048{
2049 if (m_constraintsInvolvedIn)
2050 {
2051 wxNode *node = m_constraintsInvolvedIn->First();
2052 while (node)
2053 {
2054 wxWindow *win = (wxWindow *)node->Data();
2055 wxNode *next = node->Next();
2056 wxLayoutConstraints *constr = win->GetConstraints();
2057
2058 // Reset any constraints involving this window
2059 if (constr)
2060 {
2061 constr->left.ResetIfWin((wxWindow *)this);
2062 constr->top.ResetIfWin((wxWindow *)this);
2063 constr->right.ResetIfWin((wxWindow *)this);
2064 constr->bottom.ResetIfWin((wxWindow *)this);
2065 constr->width.ResetIfWin((wxWindow *)this);
2066 constr->height.ResetIfWin((wxWindow *)this);
2067 constr->centreX.ResetIfWin((wxWindow *)this);
2068 constr->centreY.ResetIfWin((wxWindow *)this);
2069 }
2070 delete node;
2071 node = next;
2072 }
2073 delete m_constraintsInvolvedIn;
2074 m_constraintsInvolvedIn = NULL;
2075 }
2076}
2077
2078void wxWindow::SetSizer(wxSizer *sizer)
2079{
2080 m_windowSizer = sizer;
2081 if (sizer)
2082 sizer->SetSizerParent((wxWindow *)this);
2083}
2084
2085/*
2086 * New version
2087 */
2088
2089bool wxWindow::Layout(void)
2090{
2091 if (GetConstraints())
2092 {
2093 int w, h;
2094 GetClientSize(&w, &h);
2095 GetConstraints()->width.SetValue(w);
2096 GetConstraints()->height.SetValue(h);
2097 }
2098
2099 // If top level (one sizer), evaluate the sizer's constraints.
2100 if (GetSizer())
2101 {
2102 int noChanges;
2103 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
2104 GetSizer()->LayoutPhase1(&noChanges);
2105 GetSizer()->LayoutPhase2(&noChanges);
2106 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
2107 return TRUE;
2108 }
2109 else
2110 {
2111 // Otherwise, evaluate child constraints
2112 ResetConstraints(); // Mark all constraints as unevaluated
2113 DoPhase(1); // Just one phase need if no sizers involved
2114 DoPhase(2);
2115 SetConstraintSizes(); // Recursively set the real window sizes
2116 }
2117 return TRUE;
2118}
2119
2120
2121// Do a phase of evaluating constraints:
2122// the default behaviour. wxSizers may do a similar
2123// thing, but also impose their own 'constraints'
2124// and order the evaluation differently.
2125bool wxWindow::LayoutPhase1(int *noChanges)
2126{
2127 wxLayoutConstraints *constr = GetConstraints();
2128 if (constr)
2129 {
2130 return constr->SatisfyConstraints((wxWindow *)this, noChanges);
2131 }
2132 else
2133 return TRUE;
2134}
2135
2136bool wxWindow::LayoutPhase2(int *noChanges)
2137{
2138 *noChanges = 0;
2139
2140 // Layout children
2141 DoPhase(1);
2142 DoPhase(2);
2143 return TRUE;
2144}
2145
2146// Do a phase of evaluating child constraints
2147bool wxWindow::DoPhase(const int phase)
2148{
2149 int noIterations = 0;
2150 int maxIterations = 500;
2151 int noChanges = 1;
2152 int noFailures = 0;
2153 wxList succeeded;
2154 while ((noChanges > 0) && (noIterations < maxIterations))
2155 {
2156 noChanges = 0;
2157 noFailures = 0;
2158 wxNode *node = GetChildren()->First();
2159 while (node)
2160 {
2161 wxWindow *child = (wxWindow *)node->Data();
2162 if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog)))
2163 {
2164 wxLayoutConstraints *constr = child->GetConstraints();
2165 if (constr)
2166 {
2167 if (succeeded.Member(child))
2168 {
2169 }
2170 else
2171 {
2172 int tempNoChanges = 0;
2173 bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
2174 noChanges += tempNoChanges;
2175 if (success)
2176 {
2177 succeeded.Append(child);
2178 }
2179 }
2180 }
2181 }
2182 node = node->Next();
2183 }
2184 noIterations ++;
2185 }
2186 return TRUE;
2187}
2188
2189void wxWindow::ResetConstraints(void)
2190{
2191 wxLayoutConstraints *constr = GetConstraints();
2192 if (constr)
2193 {
2194 constr->left.SetDone(FALSE);
2195 constr->top.SetDone(FALSE);
2196 constr->right.SetDone(FALSE);
2197 constr->bottom.SetDone(FALSE);
2198 constr->width.SetDone(FALSE);
2199 constr->height.SetDone(FALSE);
2200 constr->centreX.SetDone(FALSE);
2201 constr->centreY.SetDone(FALSE);
2202 }
2203 wxNode *node = GetChildren()->First();
2204 while (node)
2205 {
2206 wxWindow *win = (wxWindow *)node->Data();
2207 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
2208 win->ResetConstraints();
2209 node = node->Next();
2210 }
2211}
2212
2213// Need to distinguish between setting the 'fake' size for
2214// windows and sizers, and setting the real values.
2215void wxWindow::SetConstraintSizes(const bool recurse)
2216{
2217 wxLayoutConstraints *constr = GetConstraints();
2218 if (constr && constr->left.GetDone() && constr->right.GetDone() &&
2219 constr->width.GetDone() && constr->height.GetDone())
2220 {
2221 int x = constr->left.GetValue();
2222 int y = constr->top.GetValue();
2223 int w = constr->width.GetValue();
2224 int h = constr->height.GetValue();
2225
2226 // If we don't want to resize this window, just move it...
2227 if ((constr->width.GetRelationship() != wxAsIs) ||
2228 (constr->height.GetRelationship() != wxAsIs))
2229 {
2230 // Calls Layout() recursively. AAAGH. How can we stop that.
2231 // Simply take Layout() out of non-top level OnSizes.
2232 SizerSetSize(x, y, w, h);
2233 }
2234 else
2235 {
2236 SizerMove(x, y);
2237 }
2238 }
2239 else if (constr)
2240 {
2241 char *windowClass = this->GetClassInfo()->GetClassName();
2242
2243 wxString winName;
2244 if (GetName() == "")
2245 winName = "unnamed";
2246 else
2247 winName = GetName();
2248 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass, (const char *)winName);
2249 if (!constr->left.GetDone())
2250 wxDebugMsg(" unsatisfied 'left' constraint.\n");
2251 if (!constr->right.GetDone())
2252 wxDebugMsg(" unsatisfied 'right' constraint.\n");
2253 if (!constr->width.GetDone())
2254 wxDebugMsg(" unsatisfied 'width' constraint.\n");
2255 if (!constr->height.GetDone())
2256 wxDebugMsg(" unsatisfied 'height' constraint.\n");
2257 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
2258 }
2259
2260 if (recurse)
2261 {
2262 wxNode *node = GetChildren()->First();
2263 while (node)
2264 {
2265 wxWindow *win = (wxWindow *)node->Data();
2266 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
2267 win->SetConstraintSizes();
2268 node = node->Next();
2269 }
2270 }
2271}
2272
2273// This assumes that all sizers are 'on' the same
2274// window, i.e. the parent of this window.
2275void wxWindow::TransformSizerToActual(int *x, int *y) const
2276{
2277 if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) ||
2278 m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) )
2279 return;
2280
2281 int xp, yp;
2282 m_sizerParent->GetPosition(&xp, &yp);
2283 m_sizerParent->TransformSizerToActual(&xp, &yp);
2284 *x += xp;
2285 *y += yp;
2286}
2287
2288void wxWindow::SizerSetSize(const int x, const int y, const int w, const int h)
2289{
2290 int xx = x;
2291 int yy = y;
2292 TransformSizerToActual(&xx, &yy);
2293 SetSize(xx, yy, w, h);
2294}
2295
2296void wxWindow::SizerMove(const int x, const int y)
2297{
2298 int xx = x;
2299 int yy = y;
2300 TransformSizerToActual(&xx, &yy);
2301 Move(xx, yy);
2302}
2303
2304// Only set the size/position of the constraint (if any)
2305void wxWindow::SetSizeConstraint(const int x, const int y, const int w, const int h)
2306{
2307 wxLayoutConstraints *constr = GetConstraints();
2308 if (constr)
2309 {
2310 if (x != -1)
2311 {
2312 constr->left.SetValue(x);
2313 constr->left.SetDone(TRUE);
2314 }
2315 if (y != -1)
2316 {
2317 constr->top.SetValue(y);
2318 constr->top.SetDone(TRUE);
2319 }
2320 if (w != -1)
2321 {
2322 constr->width.SetValue(w);
2323 constr->width.SetDone(TRUE);
2324 }
2325 if (h != -1)
2326 {
2327 constr->height.SetValue(h);
2328 constr->height.SetDone(TRUE);
2329 }
2330 }
2331}
2332
2333void wxWindow::MoveConstraint(const int x, const int y)
2334{
2335 wxLayoutConstraints *constr = GetConstraints();
2336 if (constr)
2337 {
2338 if (x != -1)
2339 {
2340 constr->left.SetValue(x);
2341 constr->left.SetDone(TRUE);
2342 }
2343 if (y != -1)
2344 {
2345 constr->top.SetValue(y);
2346 constr->top.SetDone(TRUE);
2347 }
2348 }
2349}
2350
2351void wxWindow::GetSizeConstraint(int *w, int *h) const
2352{
2353 wxLayoutConstraints *constr = GetConstraints();
2354 if (constr)
2355 {
2356 *w = constr->width.GetValue();
2357 *h = constr->height.GetValue();
2358 }
2359 else
2360 GetSize(w, h);
2361}
2362
2363void wxWindow::GetClientSizeConstraint(int *w, int *h) const
2364{
2365 wxLayoutConstraints *constr = GetConstraints();
2366 if (constr)
2367 {
2368 *w = constr->width.GetValue();
2369 *h = constr->height.GetValue();
2370 }
2371 else
2372 GetClientSize(w, h);
2373}
2374
2375void wxWindow::GetPositionConstraint(int *x, int *y) const
2376{
2377 wxLayoutConstraints *constr = GetConstraints();
2378 if (constr)
2379 {
2380 *x = constr->left.GetValue();
2381 *y = constr->top.GetValue();
2382 }
2383 else
2384 GetPosition(x, y);
2385}
2386