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