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