]> git.saurik.com Git - wxWidgets.git/blob - src/motif/window.cpp
Added more makefiles; fixed some samples for Cygwin
[wxWidgets.git] / src / motif / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.cpp
3 // Purpose: wxWindow
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "window.h"
14 #endif
15
16 #include "wx/setup.h"
17 #include "wx/menu.h"
18 #include "wx/dc.h"
19 #include "wx/dcclient.h"
20 #include "wx/utils.h"
21 #include "wx/app.h"
22 #include "wx/panel.h"
23 #include "wx/layout.h"
24 #include "wx/dialog.h"
25 #include "wx/listbox.h"
26 #include "wx/button.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/frame.h"
30
31 #include "wx/menuitem.h"
32 #include "wx/log.h"
33
34 #if wxUSE_DRAG_AND_DROP
35 #include "wx/dnd.h"
36 #endif
37
38 #include <Xm/Xm.h>
39
40 #include <Xm/DrawingA.h>
41 #include <Xm/ScrolledW.h>
42 #include <Xm/ScrollBar.h>
43 #include <Xm/Frame.h>
44 #include <Xm/Label.h>
45
46 #include "wx/motif/private.h"
47
48 #include <string.h>
49
50 #define SCROLL_MARGIN 4
51 void wxCanvasRepaintProc (Widget, XtPointer, XmDrawingAreaCallbackStruct * cbs);
52 void wxCanvasInputEvent (Widget drawingArea, XtPointer data, XmDrawingAreaCallbackStruct * cbs);
53 void wxCanvasMotionEvent (Widget, XButtonEvent * event);
54 void wxCanvasEnterLeave (Widget drawingArea, XtPointer clientData, XCrossingEvent * event);
55 static void wxScrollBarCallback(Widget widget, XtPointer clientData,
56 XmScaleCallbackStruct *cbs);
57 void wxPanelItemEventHandler (Widget wid,
58 XtPointer client_data,
59 XEvent* event,
60 Boolean *continueToDispatch);
61
62 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
63 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
64 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
65
66 extern wxList wxPendingDelete;
67
68 #if !USE_SHARED_LIBRARY
69 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler)
70
71 BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
72 EVT_CHAR(wxWindow::OnChar)
73 EVT_KEY_DOWN(wxWindow::OnKeyDown)
74 EVT_KEY_UP(wxWindow::OnKeyUp)
75 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
76 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
77 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
78 EVT_IDLE(wxWindow::OnIdle)
79 END_EVENT_TABLE()
80
81 #endif
82
83
84 // Constructor
85 wxWindow::wxWindow()
86 {
87 // Generic
88 m_windowId = 0;
89 m_windowStyle = 0;
90 m_windowParent = NULL;
91 m_windowEventHandler = this;
92 m_windowName = "";
93 m_windowCursor = *wxSTANDARD_CURSOR;
94 m_children = new wxList;
95 m_constraints = NULL;
96 m_constraintsInvolvedIn = NULL;
97 m_windowSizer = NULL;
98 m_sizerParent = NULL;
99 m_autoLayout = FALSE;
100 m_windowValidator = NULL;
101 m_defaultItem = NULL;
102 m_returnCode = 0;
103 m_caretWidth = 0; m_caretHeight = 0;
104 m_caretEnabled = FALSE;
105 m_caretShown = FALSE;
106 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
107 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ;
108 m_foregroundColour = *wxBLACK;
109
110 #if wxUSE_DRAG_AND_DROP
111 m_pDropTarget = NULL;
112 #endif
113 m_clientObject = (wxClientData*) NULL;
114 m_clientData = NULL;
115
116 /// Motif-specific
117 m_mainWidget = (WXWidget) 0;
118 m_button1Pressed = FALSE;
119 m_button2Pressed = FALSE;
120 m_button3Pressed = FALSE;
121 m_winCaptured = FALSE;
122 m_isShown = TRUE;
123 m_hScrollBar = (WXWidget) 0;
124 m_vScrollBar = (WXWidget) 0;
125 m_borderWidget = (WXWidget) 0;
126 m_scrolledWindow = (WXWidget) 0;
127 m_drawingArea = (WXWidget) 0;
128 m_hScroll = FALSE;
129 m_vScroll = FALSE;
130 m_backingPixmap = (WXPixmap) 0;
131 m_pixmapWidth = 0;
132 m_pixmapHeight = 0;
133 m_pixmapOffsetX = 0;
134 m_pixmapOffsetY = 0;
135 m_lastTS = 0;
136 m_lastButton = 0;
137 m_canAddEventHandler = FALSE;
138 m_scrollPosX = 0;
139 m_scrollPosY = 0;
140 }
141
142 // Destructor
143 wxWindow::~wxWindow()
144 {
145 // Remove potential dangling pointer
146 if (GetParent() && GetParent()->IsKindOf(CLASSINFO(wxPanel)))
147 {
148 wxPanel* panel = (wxPanel*) GetParent();
149 if (panel->GetLastFocus() == this)
150 panel->SetLastFocus((wxWindow*) NULL);
151 }
152
153 //// Motif-specific
154
155 if (GetMainWidget())
156 DetachWidget(GetMainWidget()); // Removes event handlers
157
158 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
159 if (m_drawingArea)
160 {
161 // Destroy children before destroying self
162 DestroyChildren();
163
164 if (m_backingPixmap)
165 XFreePixmap (XtDisplay ((Widget) GetMainWidget()), (Pixmap) m_backingPixmap);
166
167 Widget w = (Widget) m_drawingArea;
168 wxDeleteWindowFromTable(w);
169
170 if (w)
171 XtDestroyWidget(w);
172 m_mainWidget = (WXWidget) 0;
173
174 // Only if we're _really_ a canvas (not a dialog box/panel)
175 if (m_scrolledWindow)
176 {
177 wxDeleteWindowFromTable((Widget) m_scrolledWindow);
178 }
179
180 if (m_hScrollBar)
181 {
182 XtUnmanageChild ((Widget) m_hScrollBar);
183 XtDestroyWidget ((Widget) m_hScrollBar);
184 }
185 if (m_vScrollBar)
186 {
187 XtUnmanageChild ((Widget) m_vScrollBar);
188 XtDestroyWidget ((Widget) m_vScrollBar);
189 }
190 if (m_scrolledWindow)
191 {
192 XtUnmanageChild ((Widget) m_scrolledWindow);
193 XtDestroyWidget ((Widget) m_scrolledWindow);
194 }
195
196 if (m_borderWidget)
197 {
198 XtDestroyWidget ((Widget) m_borderWidget);
199 m_borderWidget = (WXWidget) 0;
200 }
201 }
202
203 //// Generic stuff
204
205 // Have to delete constraints/sizer FIRST otherwise
206 // sizers may try to look at deleted windows as they
207 // delete themselves.
208 #if wxUSE_CONSTRAINTS
209 DeleteRelatedConstraints();
210 if (m_constraints)
211 {
212 // This removes any dangling pointers to this window
213 // in other windows' constraintsInvolvedIn lists.
214 UnsetConstraints(m_constraints);
215 delete m_constraints;
216 m_constraints = NULL;
217 }
218 if (m_windowSizer)
219 {
220 delete m_windowSizer;
221 m_windowSizer = NULL;
222 }
223 // If this is a child of a sizer, remove self from parent
224 if (m_sizerParent)
225 m_sizerParent->RemoveChild((wxWindow *)this);
226 #endif
227
228 if (m_windowParent)
229 m_windowParent->RemoveChild(this);
230
231 DestroyChildren();
232
233 // Destroy the window
234 if (GetMainWidget())
235 {
236 wxDeleteWindowFromTable((Widget) GetMainWidget());
237 XtDestroyWidget((Widget) GetMainWidget());
238 SetMainWidget((WXWidget) NULL);
239 }
240
241 delete m_children;
242 m_children = NULL;
243
244 // Just in case the window has been Closed, but
245 // we're then deleting immediately: don't leave
246 // dangling pointers.
247 wxPendingDelete.DeleteObject(this);
248
249 if ( m_windowValidator ) delete m_windowValidator;
250 if (m_clientObject) delete m_clientObject;
251
252 ClearUpdateRects();
253 }
254
255 // Destroy the window (delayed, if a managed window)
256 bool wxWindow::Destroy()
257 {
258 delete this;
259 return TRUE;
260 }
261
262 // Constructor
263 bool wxWindow::Create(wxWindow *parent, wxWindowID id,
264 const wxPoint& pos,
265 const wxSize& size,
266 long style,
267 const wxString& name)
268 {
269 // Generic
270 m_windowId = 0;
271 m_windowStyle = 0;
272 m_windowParent = NULL;
273 m_windowEventHandler = this;
274 m_windowName = "";
275 m_windowCursor = *wxSTANDARD_CURSOR;
276 m_constraints = NULL;
277 m_constraintsInvolvedIn = NULL;
278 m_windowSizer = NULL;
279 m_sizerParent = NULL;
280 m_autoLayout = FALSE;
281 m_windowValidator = NULL;
282 #if wxUSE_DRAG_AND_DROP
283 m_pDropTarget = NULL;
284 #endif
285 m_caretWidth = 0; m_caretHeight = 0;
286 m_caretEnabled = FALSE;
287 m_caretShown = FALSE;
288 m_minSizeX = -1;
289 m_minSizeY = -1;
290 m_maxSizeX = -1;
291 m_maxSizeY = -1;
292 m_defaultItem = NULL;
293 m_windowParent = NULL;
294 m_clientObject = (wxClientData*) NULL;
295 m_clientData = NULL;
296
297 // Motif-specific
298 m_canAddEventHandler = FALSE;
299 m_mainWidget = (WXWidget) 0;
300 m_button1Pressed = FALSE;
301 m_button2Pressed = FALSE;
302 m_button3Pressed = FALSE;
303 m_winCaptured = FALSE;
304 m_isShown = TRUE;
305 m_hScrollBar = (WXWidget) 0;
306 m_vScrollBar = (WXWidget) 0;
307 m_borderWidget = (WXWidget) 0;
308 m_scrolledWindow = (WXWidget) 0;
309 m_drawingArea = (WXWidget) 0;
310 m_hScroll = FALSE;
311 m_vScroll = FALSE;
312 m_backingPixmap = (WXPixmap) 0;
313 m_pixmapWidth = 0;
314 m_pixmapHeight = 0;
315 m_pixmapOffsetX = 0;
316 m_pixmapOffsetY = 0;
317 m_scrollPosX = 0;
318 m_scrollPosY = 0;
319
320 if (!parent)
321 return FALSE;
322
323 if (parent) parent->AddChild(this);
324
325 m_returnCode = 0;
326
327 SetName(name);
328
329 if ( id == -1 )
330 m_windowId = (int)NewControlId();
331 else
332 m_windowId = id;
333
334 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
335 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ;
336 m_foregroundColour = *wxBLACK;
337
338 m_windowStyle = style;
339
340 if ( id == -1 )
341 m_windowId = (int)NewControlId();
342 else
343 m_windowId = id;
344
345 //// TODO: we should probably optimize by only creating a
346 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
347 //// But for now, let's simplify things by always creating the
348 //// drawing area, since otherwise the translations are different.
349
350 // New translations for getting mouse motion feedback
351 String translations =
352 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
353 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
354 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
355 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
356 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
357 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
358 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
359 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
360 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
361 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
362 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
363 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
364 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
365 <Key>: DrawingAreaInput()";
366
367 XtActionsRec actions[1];
368 actions[0].string = "wxCanvasMotionEvent";
369 actions[0].proc = (XtActionProc) wxCanvasMotionEvent;
370 XtAppAddActions ((XtAppContext) wxTheApp->GetAppContext(), actions, 1);
371
372 Widget parentWidget = (Widget) parent->GetClientWidget();
373 if (style & wxBORDER)
374 m_borderWidget = (WXWidget) XtVaCreateManagedWidget ("canvasBorder",
375 xmFrameWidgetClass, parentWidget,
376 XmNshadowType, XmSHADOW_IN,
377 NULL);
378
379 m_scrolledWindow = (WXWidget) XtVaCreateManagedWidget ("scrolledWindow",
380 xmScrolledWindowWidgetClass, m_borderWidget ? (Widget) m_borderWidget : parentWidget,
381 XmNresizePolicy, XmRESIZE_NONE,
382 XmNspacing, 0,
383 XmNscrollingPolicy, XmAPPLICATION_DEFINED,
384 // XmNscrollBarDisplayPolicy, XmAS_NEEDED,
385 NULL);
386
387 XtTranslations ptr;
388 m_drawingArea = (WXWidget) XtVaCreateWidget ((char*) (const char*) name,
389 xmDrawingAreaWidgetClass, (Widget) m_scrolledWindow,
390 XmNunitType, XmPIXELS,
391 // XmNresizePolicy, XmRESIZE_ANY,
392 XmNresizePolicy, XmRESIZE_NONE,
393 XmNmarginHeight, 0,
394 XmNmarginWidth, 0,
395 XmNtranslations, ptr = XtParseTranslationTable (translations),
396 NULL);
397 /*
398 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
399 {
400 XtFree ((char *) ptr);
401 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
402 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
403 XtFree ((char *) ptr);
404 }
405 */
406
407 wxAddWindowToTable((Widget) m_drawingArea, this);
408 wxAddWindowToTable((Widget) m_scrolledWindow, this);
409
410 /*
411 * This order is very important in Motif 1.2.1
412 *
413 */
414
415 XtRealizeWidget ((Widget) m_scrolledWindow);
416 XtRealizeWidget ((Widget) m_drawingArea);
417 XtManageChild ((Widget) m_drawingArea);
418
419 XtOverrideTranslations ((Widget) m_drawingArea,
420 ptr = XtParseTranslationTable ("<Configure>: resize()"));
421 XtFree ((char *) ptr);
422
423 XtAddCallback ((Widget) m_drawingArea, XmNexposeCallback, (XtCallbackProc) wxCanvasRepaintProc, (XtPointer) this);
424 XtAddCallback ((Widget) m_drawingArea, XmNinputCallback, (XtCallbackProc) wxCanvasInputEvent, (XtPointer) this);
425
426 /* TODO?
427 display = XtDisplay (scrolledWindow);
428 xwindow = XtWindow (drawingArea);
429 */
430
431 XtAddEventHandler ((Widget) m_drawingArea, PointerMotionHintMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask,
432 False, (XtEventHandler) wxCanvasEnterLeave, (XtPointer) this);
433
434 // Scrolled widget needs to have its colour changed or we get
435 // a little blue square where the scrollbars abutt
436 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
437 DoChangeBackgroundColour(m_scrolledWindow, backgroundColour, TRUE);
438 DoChangeBackgroundColour(m_drawingArea, backgroundColour, TRUE);
439
440 XmScrolledWindowSetAreas ((Widget) m_scrolledWindow, (Widget) 0, (Widget) 0, (Widget) m_drawingArea);
441
442 /*
443 if (m_hScrollBar)
444 XtRealizeWidget ((Widget) m_hScrollBar);
445 if (m_vScrollBar)
446 XtRealizeWidget ((Widget) m_vScrollBar);
447 */
448
449 // Without this, the cursor may not be restored properly
450 // (e.g. in splitter sample).
451 SetCursor(*wxSTANDARD_CURSOR);
452 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
453 SetSize(pos.x, pos.y, size.x, size.y);
454
455 return TRUE;
456 }
457
458 // Helper function
459 void wxWindow::CreateScrollbar(int orientation)
460 {
461 if (!m_drawingArea)
462 return;
463
464 XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_NONE, NULL);
465
466 // Add scrollbars if required
467 if (orientation == wxHORIZONTAL)
468 {
469 Widget hScrollBar = XtVaCreateManagedWidget ("hsb",
470 xmScrollBarWidgetClass, (Widget) m_scrolledWindow,
471 XmNorientation, XmHORIZONTAL,
472 NULL);
473 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
474 XtAddCallback (hScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
475 XtAddCallback (hScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
476 XtAddCallback (hScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
477 XtAddCallback (hScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
478 XtAddCallback (hScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
479 XtAddCallback (hScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
480 XtAddCallback (hScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
481
482 XtVaSetValues (hScrollBar,
483 XmNincrement, 1,
484 XmNvalue, 0,
485 NULL);
486
487 m_hScrollBar = (WXWidget) hScrollBar;
488
489 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
490 DoChangeBackgroundColour(m_hScrollBar, backgroundColour, TRUE);
491
492 XtRealizeWidget(hScrollBar);
493
494 XtVaSetValues((Widget) m_scrolledWindow,
495 XmNhorizontalScrollBar, (Widget) m_hScrollBar,
496 NULL);
497
498 m_hScroll = TRUE;
499 }
500
501 if (orientation == wxVERTICAL)
502 {
503 Widget vScrollBar = XtVaCreateManagedWidget ("vsb",
504 xmScrollBarWidgetClass, (Widget) m_scrolledWindow,
505 XmNorientation, XmVERTICAL,
506 NULL);
507 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
508 XtAddCallback (vScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
509 XtAddCallback (vScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
510 XtAddCallback (vScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
511 XtAddCallback (vScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
512 XtAddCallback (vScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
513 XtAddCallback (vScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
514 XtAddCallback (vScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
515
516 XtVaSetValues (vScrollBar,
517 XmNincrement, 1,
518 XmNvalue, 0,
519 NULL);
520
521 m_vScrollBar = (WXWidget) vScrollBar;
522 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
523 DoChangeBackgroundColour(m_vScrollBar, backgroundColour, TRUE);
524
525 XtRealizeWidget(vScrollBar);
526
527 XtVaSetValues((Widget) m_scrolledWindow,
528 XmNverticalScrollBar, (Widget) m_vScrollBar,
529 NULL);
530
531 m_vScroll = TRUE;
532 }
533
534 XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL);
535 }
536 void wxWindow::DestroyScrollbar(int orientation)
537 {
538 if (!m_drawingArea)
539 return;
540
541 XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_NONE, NULL);
542 // Add scrollbars if required
543 if (orientation == wxHORIZONTAL)
544 {
545 if (m_hScrollBar)
546 {
547 XtDestroyWidget((Widget) m_hScrollBar);
548 }
549 m_hScrollBar = (WXWidget) 0;
550 m_hScroll = FALSE;
551
552 XtVaSetValues((Widget) m_scrolledWindow,
553 XmNhorizontalScrollBar, (Widget) 0,
554 NULL);
555
556 }
557
558 if (orientation == wxVERTICAL)
559 {
560 if (m_vScrollBar)
561 {
562 XtDestroyWidget((Widget) m_vScrollBar);
563 }
564 m_vScrollBar = (WXWidget) 0;
565 m_vScroll = TRUE;
566
567 XtVaSetValues((Widget) m_scrolledWindow,
568 XmNverticalScrollBar, (Widget) 0,
569 NULL);
570
571 }
572 XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL);
573 }
574
575 void wxWindow::SetFocus()
576 {
577 XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT);
578 XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT);
579 }
580
581 void wxWindow::Enable(bool enable)
582 {
583 if (GetMainWidget())
584 {
585 XtSetSensitive((Widget) GetMainWidget(), enable);
586 XmUpdateDisplay((Widget) GetMainWidget());
587 }
588 }
589
590 void wxWindow::CaptureMouse()
591 {
592 if (m_winCaptured)
593 return;
594
595 if (GetMainWidget())
596 XtAddGrab((Widget) GetMainWidget(), TRUE, FALSE);
597
598 m_winCaptured = TRUE;
599 }
600
601 void wxWindow::ReleaseMouse()
602 {
603 if (!m_winCaptured)
604 return;
605
606 if (GetMainWidget())
607 XtRemoveGrab((Widget) GetMainWidget());
608 m_winCaptured = FALSE;
609 }
610
611 // Push/pop event handler (i.e. allow a chain of event handlers
612 // be searched)
613 void wxWindow::PushEventHandler(wxEvtHandler *handler)
614 {
615 handler->SetNextHandler(GetEventHandler());
616 SetEventHandler(handler);
617 }
618
619 wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler)
620 {
621 if ( GetEventHandler() )
622 {
623 wxEvtHandler *handlerA = GetEventHandler();
624 wxEvtHandler *handlerB = handlerA->GetNextHandler();
625 handlerA->SetNextHandler(NULL);
626 SetEventHandler(handlerB);
627 if ( deleteHandler )
628 {
629 delete handlerA;
630 return NULL;
631 }
632 else
633 return handlerA;
634 }
635 else
636 return NULL;
637 }
638
639 #if wxUSE_DRAG_AND_DROP
640
641 void wxWindow::SetDropTarget(wxDropTarget *pDropTarget)
642 {
643 if ( m_pDropTarget != 0 ) {
644 delete m_pDropTarget;
645 }
646
647 m_pDropTarget = pDropTarget;
648 if ( m_pDropTarget != 0 )
649 {
650 // TODO
651 }
652 }
653
654 #endif
655
656 // Old style file-manager drag&drop
657 void wxWindow::DragAcceptFiles(bool accept)
658 {
659 // TODO
660 }
661
662 // Get total size
663 void wxWindow::GetSize(int *x, int *y) const
664 {
665 if (m_drawingArea)
666 {
667 CanvasGetSize(x, y);
668 return;
669 }
670
671 Widget widget = (Widget) GetTopWidget();
672 Dimension xx, yy;
673 XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
674 *x = xx; *y = yy;
675 }
676
677 void wxWindow::GetPosition(int *x, int *y) const
678 {
679 if (m_drawingArea)
680 {
681 CanvasGetPosition(x, y);
682 return;
683 }
684 Widget widget = (Widget) GetTopWidget();
685 Position xx, yy;
686 XtVaGetValues(widget, XmNx, &xx, XmNy, &yy, NULL);
687
688 // We may be faking the client origin.
689 // So a window that's really at (0, 30) may appear
690 // (to wxWin apps) to be at (0, 0).
691 if (GetParent())
692 {
693 wxPoint pt(GetParent()->GetClientAreaOrigin());
694 xx -= pt.x;
695 yy -= pt.y;
696 }
697
698 *x = xx; *y = yy;
699 }
700
701 void wxWindow::ScreenToClient(int *x, int *y) const
702 {
703 Widget widget = (Widget) GetClientWidget();
704 Display *display = XtDisplay((Widget) GetMainWidget());
705 Window rootWindow = RootWindowOfScreen(XtScreen(widget));
706 Window thisWindow = XtWindow(widget);
707
708 Window childWindow;
709 int xx = *x;
710 int yy = *y;
711 XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow);
712 }
713
714 void wxWindow::ClientToScreen(int *x, int *y) const
715 {
716 Widget widget = (Widget) GetClientWidget();
717 Display *display = XtDisplay(widget);
718 Window rootWindow = RootWindowOfScreen(XtScreen(widget));
719 Window thisWindow = XtWindow(widget);
720
721 Window childWindow;
722 int xx = *x;
723 int yy = *y;
724 XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow);
725 }
726
727 void wxWindow::SetCursor(const wxCursor& cursor)
728 {
729 m_windowCursor = cursor;
730 if (m_windowCursor.Ok())
731 {
732 WXDisplay *dpy = GetXDisplay();
733 WXCursor x_cursor = ((wxCursor&)cursor).GetXCursor(dpy);
734
735 Widget w = (Widget) GetMainWidget();
736 Window win = XtWindow(w);
737 XDefineCursor((Display*) dpy, win, (Cursor) x_cursor);
738 }
739 }
740
741
742 // Get size *available for subwindows* i.e. excluding menu bar etc.
743 void wxWindow::GetClientSize(int *x, int *y) const
744 {
745 Widget widget = (Widget) GetClientWidget();
746 Dimension xx, yy;
747 XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
748 *x = xx; *y = yy;
749 }
750
751 void wxWindow::SetSize(int x, int y, int width, int height, int sizeFlags)
752 {
753 // A bit of optimization to help sort out the flickers.
754 int oldX, oldY, oldW, oldH;
755 GetSize(& oldW, & oldH);
756 GetPosition(& oldX, & oldY);
757
758 bool useOldPos = FALSE;
759 bool useOldSize = FALSE;
760
761 if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0))
762 useOldPos = TRUE;
763 else if (x == oldX && y == oldY)
764 useOldPos = TRUE;
765
766 if ((width == -1) && (height == -1))
767 useOldSize = TRUE;
768 else if (width == oldW && height == oldH)
769 useOldSize = TRUE;
770
771 if (!wxNoOptimize::CanOptimize())
772 {
773 useOldSize = FALSE; useOldPos = FALSE;
774 }
775
776 if (useOldPos && useOldSize)
777 return;
778
779 if (m_drawingArea)
780 {
781 CanvasSetSize(x, y, width, height, sizeFlags);
782 return;
783 }
784 Widget widget = (Widget) GetTopWidget();
785 if (!widget)
786 return;
787
788 bool managed = XtIsManaged( widget );
789 if (managed)
790 XtUnmanageChild(widget);
791
792 int xx = x; int yy = y;
793 AdjustForParentClientOrigin(xx, yy, sizeFlags);
794
795 if (!useOldPos)
796 {
797 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
798 XtVaSetValues(widget, XmNx, xx, NULL);
799 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
800 XtVaSetValues(widget, XmNy, yy, NULL);
801 }
802 if (!useOldSize)
803 {
804 if (width > -1)
805 XtVaSetValues(widget, XmNwidth, width, NULL);
806 if (height > -1)
807 XtVaSetValues(widget, XmNheight, height, NULL);
808 }
809
810 if (managed)
811 XtManageChild(widget);
812
813 // How about this bit. Maybe we don't need to generate size events
814 // all the time -- they'll be generated when the window is sized anyway.
815 /*
816 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
817 sizeEvent.SetEventObject(this);
818
819 GetEventHandler()->ProcessEvent(sizeEvent);
820 */
821 }
822
823 void wxWindow::SetClientSize(int width, int height)
824 {
825 if (m_drawingArea)
826 {
827 CanvasSetClientSize(width, height);
828 return;
829 }
830
831 Widget widget = (Widget) GetTopWidget();
832
833 if (width > -1)
834 XtVaSetValues(widget, XmNwidth, width, NULL);
835 if (height > -1)
836 XtVaSetValues(widget, XmNheight, height, NULL);
837
838 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
839 sizeEvent.SetEventObject(this);
840
841 GetEventHandler()->ProcessEvent(sizeEvent);
842 }
843
844 // For implementation purposes - sometimes decorations make the client area
845 // smaller
846 wxPoint wxWindow::GetClientAreaOrigin() const
847 {
848 return wxPoint(0, 0);
849 }
850
851 // Makes an adjustment to the window position (for example, a frame that has
852 // a toolbar that it manages itself).
853 void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
854 {
855 if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
856 {
857 wxPoint pt(GetParent()->GetClientAreaOrigin());
858 x += pt.x; y += pt.y;
859 }
860 }
861
862 bool wxWindow::Show(bool show)
863 {
864 if (show)
865 {
866 if (m_borderWidget || m_scrolledWindow)
867 {
868 if (m_drawingArea)
869 XtMapWidget((Widget) m_drawingArea);
870 XtMapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
871 }
872 else
873 {
874 WXWidget topWidget = GetTopWidget();
875 if (GetTopWidget())
876 XtMapWidget((Widget) GetTopWidget());
877 else if (GetMainWidget())
878 XtMapWidget((Widget) GetMainWidget());
879 }
880 }
881 else
882 {
883 if (m_borderWidget || m_scrolledWindow)
884 {
885 if (m_drawingArea)
886 XtUnmapWidget((Widget) m_drawingArea);
887 XtUnmapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
888 }
889 else
890 {
891 if (GetTopWidget())
892 XtUnmapWidget((Widget) GetTopWidget());
893 else if (GetMainWidget())
894 XtUnmapWidget((Widget) GetMainWidget());
895 }
896 }
897
898 /*
899 Window xwin = (Window) GetXWindow();
900 Display *xdisp = (Display*) GetXDisplay();
901 if (show)
902 XMapWindow(xdisp, xwin);
903 else
904 XUnmapWindow(xdisp, xwin);
905 */
906
907 m_isShown = show;
908
909 return TRUE;
910 }
911
912 bool wxWindow::IsShown() const
913 {
914 return m_isShown;
915 }
916
917 int wxWindow::GetCharHeight() const
918 {
919 if (!m_windowFont.Ok())
920 return 0;
921
922 WXFontStructPtr pFontStruct = m_windowFont.GetFontStruct(1.0, GetXDisplay());
923
924 int direction, ascent, descent;
925 XCharStruct overall;
926 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
927 &descent, &overall);
928 // return (overall.ascent + overall.descent);
929 return (ascent + descent);
930 }
931
932 int wxWindow::GetCharWidth() const
933 {
934 if (!m_windowFont.Ok())
935 return 0;
936
937 WXFontStructPtr pFontStruct = m_windowFont.GetFontStruct(1.0, GetXDisplay());
938
939 int direction, ascent, descent;
940 XCharStruct overall;
941 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
942 &descent, &overall);
943 return overall.width;
944 }
945
946 /* Helper function for 16-bit fonts */
947 static int str16len(const char *s)
948 {
949 int count = 0;
950
951 while (s[0] && s[1]) {
952 count++;
953 s += 2;
954 }
955
956 return count;
957 }
958
959 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
960 int *descent, int *externalLeading, const wxFont *theFont, bool use16) const
961 {
962 wxFont *fontToUse = (wxFont *)theFont;
963 if (!fontToUse)
964 fontToUse = (wxFont *) & m_windowFont;
965
966 if (!fontToUse->Ok())
967 return;
968
969 WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay());
970
971 int direction, ascent, descent2;
972 XCharStruct overall;
973 int slen;
974
975 if (use16) slen = str16len(string); else slen = strlen(string);
976
977 if (use16)
978 XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction,
979 &ascent, &descent2, &overall);
980 else
981 XTextExtents((XFontStruct*) pFontStruct, (char*) (const char*) string, slen, &direction,
982 &ascent, &descent2, &overall);
983
984 *x = (overall.width);
985 *y = (ascent + descent2);
986 if (descent)
987 *descent = descent2;
988 if (externalLeading)
989 *externalLeading = 0;
990 }
991
992 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
993 {
994 Display *display = XtDisplay((Widget) GetMainWidget());
995 Window thisWindow = XtWindow((Widget) GetMainWidget());
996
997 XExposeEvent dummyEvent;
998 int width, height;
999 GetSize(&width, &height);
1000
1001 dummyEvent.type = Expose;
1002 dummyEvent.display = display;
1003 dummyEvent.send_event = True;
1004 dummyEvent.window = thisWindow;
1005 if (rect)
1006 {
1007 dummyEvent.x = rect->x;
1008 dummyEvent.y = rect->y;
1009 dummyEvent.width = rect->width;
1010 dummyEvent.height = rect->height;
1011 }
1012 else
1013 {
1014 dummyEvent.x = 0;
1015 dummyEvent.y = 0;
1016 dummyEvent.width = width;
1017 dummyEvent.height = height;
1018 }
1019 dummyEvent.count = 0;
1020
1021 if (eraseBack)
1022 {
1023 wxClientDC dc(this);
1024 wxBrush backgroundBrush(GetBackgroundColour(), wxSOLID);
1025 dc.SetBackground(backgroundBrush);
1026 if (rect)
1027 dc.Clear(*rect);
1028 else
1029 dc.Clear();
1030 }
1031
1032 XSendEvent(display, thisWindow, False, ExposureMask, (XEvent *)&dummyEvent);
1033 }
1034
1035 // Responds to colour changes: passes event on to children.
1036 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
1037 {
1038 wxNode *node = GetChildren().First();
1039 while ( node )
1040 {
1041 // Only propagate to non-top-level windows
1042 wxWindow *win = (wxWindow *)node->Data();
1043 if ( win->GetParent() )
1044 {
1045 wxSysColourChangedEvent event2;
1046 event.m_eventObject = win;
1047 win->GetEventHandler()->ProcessEvent(event2);
1048 }
1049
1050 node = node->Next();
1051 }
1052 }
1053
1054 // This can be called by the app (or wxWindows) to do default processing for the current
1055 // event. Save message/event info in wxWindow so they can be used in this function.
1056 long wxWindow::Default()
1057 {
1058 // TODO
1059 return 0;
1060 }
1061
1062 void wxWindow::InitDialog()
1063 {
1064 wxInitDialogEvent event(GetId());
1065 event.SetEventObject( this );
1066 GetEventHandler()->ProcessEvent(event);
1067 }
1068
1069 // Default init dialog behaviour is to transfer data to window
1070 void wxWindow::OnInitDialog(wxInitDialogEvent& event)
1071 {
1072 TransferDataToWindow();
1073 }
1074
1075 // Caret manipulation
1076 void wxWindow::CreateCaret(int w, int h)
1077 {
1078 m_caretWidth = w;
1079 m_caretHeight = h;
1080 m_caretEnabled = TRUE;
1081 }
1082
1083 void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
1084 {
1085 // TODO
1086 }
1087
1088 void wxWindow::ShowCaret(bool show)
1089 {
1090 // TODO
1091 }
1092
1093 void wxWindow::DestroyCaret()
1094 {
1095 // TODO
1096 m_caretEnabled = FALSE;
1097 }
1098
1099 void wxWindow::SetCaretPos(int x, int y)
1100 {
1101 // TODO
1102 }
1103
1104 void wxWindow::GetCaretPos(int *x, int *y) const
1105 {
1106 // TODO
1107 }
1108
1109 wxWindow *wxGetActiveWindow()
1110 {
1111 // TODO
1112 return NULL;
1113 }
1114
1115 void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH)
1116 {
1117 m_minSizeX = minW;
1118 m_minSizeY = minH;
1119 m_maxSizeX = maxW;
1120 m_maxSizeY = maxH;
1121
1122 if (!this->IsKindOf(CLASSINFO(wxFrame)))
1123 return;
1124
1125 wxFrame *frame = (wxFrame *)this;
1126 Widget widget = (Widget) frame->GetShellWidget();
1127
1128 if (minW > -1)
1129 XtVaSetValues(widget, XmNminWidth, minW, NULL);
1130 if (minH > -1)
1131 XtVaSetValues(widget, XmNminHeight, minH, NULL);
1132 if (maxW > -1)
1133 XtVaSetValues(widget, XmNmaxWidth, maxW, NULL);
1134 if (maxH > -1)
1135 XtVaSetValues(widget, XmNmaxHeight, maxH, NULL);
1136 if (incW > -1)
1137 XtVaSetValues(widget, XmNwidthInc, incW, NULL);
1138 if (incH > -1)
1139 XtVaSetValues(widget, XmNheightInc, incH, NULL);
1140 }
1141
1142 void wxWindow::Centre(int direction)
1143 {
1144 int x, y, width, height, panel_width, panel_height, new_x, new_y;
1145
1146 wxWindow *father = (wxWindow *)GetParent();
1147 if (!father)
1148 return;
1149
1150 father->GetClientSize(&panel_width, &panel_height);
1151 GetSize(&width, &height);
1152 GetPosition(&x, &y);
1153
1154 new_x = -1;
1155 new_y = -1;
1156
1157 if (direction & wxHORIZONTAL)
1158 new_x = (int)((panel_width - width)/2);
1159
1160 if (direction & wxVERTICAL)
1161 new_y = (int)((panel_height - height)/2);
1162
1163 SetSize(new_x, new_y, -1, -1);
1164
1165 }
1166
1167 // Coordinates relative to the window
1168 void wxWindow::WarpPointer (int x, int y)
1169 {
1170 XWarpPointer (XtDisplay((Widget) GetClientWidget()), None, XtWindow((Widget) GetClientWidget()), 0, 0, 0, 0, x, y);
1171 }
1172
1173 void wxWindow::OnEraseBackground(wxEraseEvent& event)
1174 {
1175 // TODO
1176 Default();
1177 }
1178
1179 int wxWindow::GetScrollPos(int orient) const
1180 {
1181 if (orient == wxHORIZONTAL)
1182 return m_scrollPosX;
1183 else
1184 return m_scrollPosY;
1185 /*
1186 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1187 if (scrollBar)
1188 {
1189 int pos;
1190 XtVaGetValues(scrollBar,
1191 XmNvalue, &pos, NULL);
1192 return pos;
1193 }
1194 else
1195 return 0;
1196 */
1197 }
1198
1199 // This now returns the whole range, not just the number
1200 // of positions that we can scroll.
1201 int wxWindow::GetScrollRange(int orient) const
1202 {
1203 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1204 if (scrollBar)
1205 {
1206 int range;
1207 XtVaGetValues(scrollBar,
1208 XmNmaximum, &range, NULL);
1209 return range;
1210 }
1211 else
1212 return 0;
1213 }
1214
1215 int wxWindow::GetScrollThumb(int orient) const
1216 {
1217 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1218 if (scrollBar)
1219 {
1220 int thumb;
1221 XtVaGetValues(scrollBar,
1222 XmNsliderSize, &thumb, NULL);
1223 return thumb;
1224 }
1225 else
1226 return 0;
1227 }
1228
1229 void wxWindow::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
1230 {
1231 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1232 if (scrollBar)
1233 {
1234 XtVaSetValues (scrollBar,
1235 XmNvalue, pos,
1236 NULL);
1237 }
1238 if (orient == wxHORIZONTAL)
1239 m_scrollPosX = pos;
1240 else
1241 m_scrollPosY = pos;
1242
1243 }
1244
1245 // New function that will replace some of the above.
1246 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
1247 int range, bool WXUNUSED(refresh))
1248 {
1249 int oldW, oldH;
1250 GetSize(& oldW, & oldH);
1251
1252 if (range == 0)
1253 range = 1;
1254 if (thumbVisible == 0)
1255 thumbVisible = 1;
1256
1257 if (thumbVisible > range)
1258 thumbVisible = range;
1259
1260 // Save the old state to see if it changed
1261 WXWidget oldScrollBar = ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar );
1262
1263 if (orient == wxHORIZONTAL)
1264 {
1265 if (thumbVisible == range)
1266 {
1267 if (m_hScrollBar)
1268 DestroyScrollbar(wxHORIZONTAL);
1269 }
1270 else
1271 {
1272 if (!m_hScrollBar)
1273 CreateScrollbar(wxHORIZONTAL);
1274 }
1275 }
1276 if (orient == wxVERTICAL)
1277 {
1278 if (thumbVisible == range)
1279 {
1280 if (m_vScrollBar)
1281 DestroyScrollbar(wxVERTICAL);
1282 }
1283 else
1284 {
1285 if (!m_vScrollBar)
1286 CreateScrollbar(wxVERTICAL);
1287 }
1288 }
1289 WXWidget newScrollBar = ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar );
1290
1291 if (oldScrollBar != newScrollBar)
1292 {
1293 // This is important! Without it, scrollbars misbehave
1294 // badly.
1295 XtUnrealizeWidget((Widget) m_scrolledWindow);
1296 XmScrolledWindowSetAreas ((Widget) m_scrolledWindow, (Widget) m_hScrollBar, (Widget) m_vScrollBar, (Widget) m_drawingArea);
1297 XtRealizeWidget((Widget) m_scrolledWindow);
1298 XtManageChild((Widget) m_scrolledWindow);
1299 }
1300
1301 if (newScrollBar)
1302 XtVaSetValues((Widget) newScrollBar,
1303 XmNvalue, pos,
1304 XmNminimum, 0,
1305 XmNmaximum, range,
1306 XmNsliderSize, thumbVisible,
1307 NULL);
1308
1309 if (orient == wxHORIZONTAL)
1310 m_scrollPosX = pos;
1311 else
1312 m_scrollPosY = pos;
1313
1314 int newW, newH;
1315 GetSize(& newW, & newH);
1316
1317 // Adjusting scrollbars can resize the canvas accidentally
1318 if (newW != oldW || newH != oldH)
1319 SetSize(-1, -1, oldW, oldH);
1320 }
1321
1322 // Does a physical scroll
1323 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
1324 {
1325 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1326 int x, y, w, h;
1327 if (rect)
1328 {
1329 // Use specified rectangle
1330 x = rect->x; y = rect->y; w = rect->width; h = rect->height;
1331 }
1332 else
1333 {
1334 // Use whole client area
1335 x = 0; y = 0;
1336 GetClientSize(& w, & h);
1337 }
1338
1339 int x1 = (dx >= 0) ? x : x - dx ;
1340 int y1 = (dy >= 0) ? y : y - dy;
1341 int w1 = w - abs(dx);
1342 int h1 = h - abs(dy);
1343 int x2 = (dx >= 0) ? x + dx : x;
1344 int y2 = (dy >= 0) ? y + dy : y;
1345
1346 wxClientDC dc(this);
1347
1348 dc.SetLogicalFunction (wxCOPY);
1349
1350 Widget widget = (Widget) GetMainWidget();
1351 Window window = XtWindow(widget);
1352 Display* display = XtDisplay(widget);
1353
1354 XCopyArea(display, window,
1355 window, (GC) dc.GetGC(),
1356 x1, y1,
1357 w1, h1,
1358 x2, y2);
1359
1360 dc.SetAutoSetting(TRUE);
1361 wxBrush brush(GetBackgroundColour(), wxSOLID);
1362 dc.SetBrush(brush); // ??
1363
1364 // We'll add rectangles to the list of update rectangles
1365 // according to which bits we've exposed.
1366 wxList updateRects;
1367
1368 if (dx > 0)
1369 {
1370 wxRect *rect = new wxRect;
1371 rect->x = x;
1372 rect->y = y;
1373 rect->width = dx;
1374 rect->height = h;
1375
1376 XFillRectangle(display, window,
1377 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
1378
1379 rect->x = rect->x;
1380 rect->y = rect->y;
1381 rect->width = rect->width;
1382 rect->height = rect->height;
1383
1384 updateRects.Append((wxObject*) rect);
1385 }
1386 else if (dx < 0)
1387 {
1388 wxRect *rect = new wxRect;
1389
1390 rect->x = x + w + dx;
1391 rect->y = y;
1392 rect->width = -dx;
1393 rect->height = h;
1394
1395 XFillRectangle(display, window,
1396 (GC) dc.GetGC(), rect->x, rect->y, rect->width,
1397 rect->height);
1398
1399 rect->x = rect->x;
1400 rect->y = rect->y;
1401 rect->width = rect->width;
1402 rect->height = rect->height;
1403
1404 updateRects.Append((wxObject*) rect);
1405 }
1406 if (dy > 0)
1407 {
1408 wxRect *rect = new wxRect;
1409
1410 rect->x = x;
1411 rect->y = y;
1412 rect->width = w;
1413 rect->height = dy;
1414
1415 XFillRectangle(display, window,
1416 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
1417
1418 rect->x = rect->x;
1419 rect->y = rect->y;
1420 rect->width = rect->width;
1421 rect->height = rect->height;
1422
1423 updateRects.Append((wxObject*) rect);
1424 }
1425 else if (dy < 0)
1426 {
1427 wxRect *rect = new wxRect;
1428
1429 rect->x = x;
1430 rect->y = y + h + dy;
1431 rect->width = w;
1432 rect->height = -dy;
1433
1434 XFillRectangle(display, window,
1435 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
1436
1437 rect->x = rect->x;
1438 rect->y = rect->y;
1439 rect->width = rect->width;
1440 rect->height = rect->height;
1441
1442 updateRects.Append((wxObject*) rect);
1443 }
1444 dc.SetBrush(wxNullBrush);
1445
1446 // Now send expose events
1447
1448 wxNode* node = updateRects.First();
1449 while (node)
1450 {
1451 wxRect* rect = (wxRect*) node->Data();
1452 XExposeEvent event;
1453
1454 event.type = Expose;
1455 event.display = display;
1456 event.send_event = True;
1457 event.window = window;
1458
1459 event.x = rect->x;
1460 event.y = rect->y;
1461 event.width = rect->width;
1462 event.height = rect->height;
1463
1464 event.count = 0;
1465
1466 XSendEvent(display, window, False, ExposureMask, (XEvent *)&event);
1467
1468 node = node->Next();
1469
1470 }
1471
1472 // Delete the update rects
1473 node = updateRects.First();
1474 while (node)
1475 {
1476 wxRect* rect = (wxRect*) node->Data();
1477 delete rect;
1478 node = node->Next();
1479 }
1480
1481 }
1482
1483 void wxWindow::OnChar(wxKeyEvent& event)
1484 {
1485 /* ??
1486 if ( event.KeyCode() == WXK_TAB ) {
1487 // propagate the TABs to the parent - it's up to it to decide what
1488 // to do with it
1489 if ( GetParent() ) {
1490 if ( GetParent()->ProcessEvent(event) )
1491 return;
1492 }
1493 }
1494 */
1495 }
1496
1497 void wxWindow::OnKeyDown(wxKeyEvent& event)
1498 {
1499 Default();
1500 }
1501
1502 void wxWindow::OnKeyUp(wxKeyEvent& event)
1503 {
1504 Default();
1505 }
1506
1507 void wxWindow::OnPaint(wxPaintEvent& event)
1508 {
1509 Default();
1510 }
1511
1512 bool wxWindow::IsEnabled() const
1513 {
1514 // TODO. Is this right?
1515 // return XtGetSensitive((Widget) GetMainWidget());
1516 return FALSE;
1517 }
1518
1519 // Dialog support: override these and call
1520 // base class members to add functionality
1521 // that can't be done using validators.
1522 // NOTE: these functions assume that controls
1523 // are direct children of this window, not grandchildren
1524 // or other levels of descendant.
1525
1526 // Transfer values to controls. If returns FALSE,
1527 // it's an application error (pops up a dialog)
1528 bool wxWindow::TransferDataToWindow()
1529 {
1530 wxNode *node = GetChildren().First();
1531 while ( node )
1532 {
1533 wxWindow *child = (wxWindow *)node->Data();
1534 if ( child->GetValidator() &&
1535 !child->GetValidator()->TransferToWindow() )
1536 {
1537 wxLogError("Could not transfer data to window.");
1538 return FALSE;
1539 }
1540
1541 node = node->Next();
1542 }
1543 return TRUE;
1544 }
1545
1546 // Transfer values from controls. If returns FALSE,
1547 // validation failed: don't quit
1548 bool wxWindow::TransferDataFromWindow()
1549 {
1550 wxNode *node = GetChildren().First();
1551 while ( node )
1552 {
1553 wxWindow *child = (wxWindow *)node->Data();
1554 if ( child->GetValidator() && !child->GetValidator()->TransferFromWindow() )
1555 {
1556 return FALSE;
1557 }
1558
1559 node = node->Next();
1560 }
1561 return TRUE;
1562 }
1563
1564 bool wxWindow::Validate()
1565 {
1566 wxNode *node = GetChildren().First();
1567 while ( node )
1568 {
1569 wxWindow *child = (wxWindow *)node->Data();
1570 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) )
1571 {
1572 return FALSE;
1573 }
1574
1575 node = node->Next();
1576 }
1577 return TRUE;
1578 }
1579
1580 // Get the window with the focus
1581 wxWindow *wxWindow::FindFocus()
1582 {
1583 // TODO
1584 return NULL;
1585 }
1586
1587 void wxWindow::AddChild(wxWindow *child)
1588 {
1589 GetChildren().Append(child);
1590 child->m_windowParent = this;
1591 }
1592
1593 void wxWindow::RemoveChild(wxWindow *child)
1594 {
1595 GetChildren().DeleteObject(child);
1596 child->m_windowParent = NULL;
1597 }
1598
1599 // Reparents this window to have the new parent.
1600 bool wxWindow::Reparent(wxWindow* WXUNUSED(parent))
1601 {
1602 // For now, we indicate that this isn't implemented.
1603 return FALSE;
1604 }
1605
1606 void wxWindow::DestroyChildren()
1607 {
1608 wxNode *node = GetChildren().First();
1609 while (node)
1610 {
1611 wxNode* next = node->Next();
1612 wxWindow* child = (wxWindow*) node->Data();
1613 delete child;
1614 node = next;
1615 }
1616 GetChildren().Clear();
1617 #if 0
1618 wxNode *node;
1619 while ((node = GetChildren().First()) != (wxNode *)NULL) {
1620 wxWindow *child;
1621 if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) {
1622 delete child;
1623 if ( GetChildren().Member(child) )
1624 delete node;
1625 }
1626 } /* while */
1627 #endif
1628 }
1629
1630 void wxWindow::MakeModal(bool modal)
1631 {
1632 // Disable all other windows
1633 if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame)))
1634 {
1635 wxNode *node = wxTopLevelWindows.First();
1636 while (node)
1637 {
1638 wxWindow *win = (wxWindow *)node->Data();
1639 if (win != this)
1640 win->Enable(!modal);
1641
1642 node = node->Next();
1643 }
1644 }
1645 }
1646
1647 // If nothing defined for this, try the parent.
1648 // E.g. we may be a button loaded from a resource, with no callback function
1649 // defined.
1650 void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
1651 {
1652 if (GetEventHandler()->ProcessEvent(event) )
1653 return;
1654 if (m_windowParent)
1655 m_windowParent->GetEventHandler()->OnCommand(win, event);
1656 }
1657
1658 void wxWindow::SetConstraints(wxLayoutConstraints *c)
1659 {
1660 if (m_constraints)
1661 {
1662 UnsetConstraints(m_constraints);
1663 delete m_constraints;
1664 }
1665 m_constraints = c;
1666 if (m_constraints)
1667 {
1668 // Make sure other windows know they're part of a 'meaningful relationship'
1669 if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this))
1670 m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1671 if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this))
1672 m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1673 if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this))
1674 m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1675 if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this))
1676 m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1677 if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this))
1678 m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1679 if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this))
1680 m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1681 if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this))
1682 m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1683 if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this))
1684 m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
1685 }
1686 }
1687
1688 // This removes any dangling pointers to this window
1689 // in other windows' constraintsInvolvedIn lists.
1690 void wxWindow::UnsetConstraints(wxLayoutConstraints *c)
1691 {
1692 if (c)
1693 {
1694 if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this))
1695 c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1696 if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this))
1697 c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1698 if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this))
1699 c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1700 if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this))
1701 c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1702 if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this))
1703 c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1704 if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this))
1705 c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1706 if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this))
1707 c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1708 if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this))
1709 c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
1710 }
1711 }
1712
1713 // Back-pointer to other windows we're involved with, so if we delete
1714 // this window, we must delete any constraints we're involved with.
1715 void wxWindow::AddConstraintReference(wxWindow *otherWin)
1716 {
1717 if (!m_constraintsInvolvedIn)
1718 m_constraintsInvolvedIn = new wxList;
1719 if (!m_constraintsInvolvedIn->Member(otherWin))
1720 m_constraintsInvolvedIn->Append(otherWin);
1721 }
1722
1723 // REMOVE back-pointer to other windows we're involved with.
1724 void wxWindow::RemoveConstraintReference(wxWindow *otherWin)
1725 {
1726 if (m_constraintsInvolvedIn)
1727 m_constraintsInvolvedIn->DeleteObject(otherWin);
1728 }
1729
1730 // Reset any constraints that mention this window
1731 void wxWindow::DeleteRelatedConstraints()
1732 {
1733 if (m_constraintsInvolvedIn)
1734 {
1735 wxNode *node = m_constraintsInvolvedIn->First();
1736 while (node)
1737 {
1738 wxWindow *win = (wxWindow *)node->Data();
1739 wxNode *next = node->Next();
1740 wxLayoutConstraints *constr = win->GetConstraints();
1741
1742 // Reset any constraints involving this window
1743 if (constr)
1744 {
1745 constr->left.ResetIfWin((wxWindow *)this);
1746 constr->top.ResetIfWin((wxWindow *)this);
1747 constr->right.ResetIfWin((wxWindow *)this);
1748 constr->bottom.ResetIfWin((wxWindow *)this);
1749 constr->width.ResetIfWin((wxWindow *)this);
1750 constr->height.ResetIfWin((wxWindow *)this);
1751 constr->centreX.ResetIfWin((wxWindow *)this);
1752 constr->centreY.ResetIfWin((wxWindow *)this);
1753 }
1754 delete node;
1755 node = next;
1756 }
1757 delete m_constraintsInvolvedIn;
1758 m_constraintsInvolvedIn = NULL;
1759 }
1760 }
1761
1762 void wxWindow::SetSizer(wxSizer *sizer)
1763 {
1764 m_windowSizer = sizer;
1765 if (sizer)
1766 sizer->SetSizerParent((wxWindow *)this);
1767 }
1768
1769 /*
1770 * New version
1771 */
1772
1773 bool wxWindow::Layout()
1774 {
1775 if (GetConstraints())
1776 {
1777 int w, h;
1778 GetClientSize(&w, &h);
1779 GetConstraints()->width.SetValue(w);
1780 GetConstraints()->height.SetValue(h);
1781 }
1782
1783 // If top level (one sizer), evaluate the sizer's constraints.
1784 if (GetSizer())
1785 {
1786 int noChanges;
1787 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1788 GetSizer()->LayoutPhase1(&noChanges);
1789 GetSizer()->LayoutPhase2(&noChanges);
1790 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1791 return TRUE;
1792 }
1793 else
1794 {
1795 // Otherwise, evaluate child constraints
1796 ResetConstraints(); // Mark all constraints as unevaluated
1797 DoPhase(1); // Just one phase need if no sizers involved
1798 DoPhase(2);
1799 SetConstraintSizes(); // Recursively set the real window sizes
1800 }
1801 return TRUE;
1802 }
1803
1804
1805 // Do a phase of evaluating constraints:
1806 // the default behaviour. wxSizers may do a similar
1807 // thing, but also impose their own 'constraints'
1808 // and order the evaluation differently.
1809 bool wxWindow::LayoutPhase1(int *noChanges)
1810 {
1811 wxLayoutConstraints *constr = GetConstraints();
1812 if (constr)
1813 {
1814 return constr->SatisfyConstraints((wxWindow *)this, noChanges);
1815 }
1816 else
1817 return TRUE;
1818 }
1819
1820 bool wxWindow::LayoutPhase2(int *noChanges)
1821 {
1822 *noChanges = 0;
1823
1824 // Layout children
1825 DoPhase(1);
1826 DoPhase(2);
1827 return TRUE;
1828 }
1829
1830 // Do a phase of evaluating child constraints
1831 bool wxWindow::DoPhase(int phase)
1832 {
1833 int noIterations = 0;
1834 int maxIterations = 500;
1835 int noChanges = 1;
1836 int noFailures = 0;
1837 wxList succeeded;
1838 while ((noChanges > 0) && (noIterations < maxIterations))
1839 {
1840 noChanges = 0;
1841 noFailures = 0;
1842 wxNode *node = GetChildren().First();
1843 while (node)
1844 {
1845 wxWindow *child = (wxWindow *)node->Data();
1846 if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog)))
1847 {
1848 wxLayoutConstraints *constr = child->GetConstraints();
1849 if (constr)
1850 {
1851 if (succeeded.Member(child))
1852 {
1853 }
1854 else
1855 {
1856 int tempNoChanges = 0;
1857 bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
1858 noChanges += tempNoChanges;
1859 if (success)
1860 {
1861 succeeded.Append(child);
1862 }
1863 }
1864 }
1865 }
1866 node = node->Next();
1867 }
1868 noIterations ++;
1869 }
1870 return TRUE;
1871 }
1872
1873 void wxWindow::ResetConstraints()
1874 {
1875 wxLayoutConstraints *constr = GetConstraints();
1876 if (constr)
1877 {
1878 constr->left.SetDone(FALSE);
1879 constr->top.SetDone(FALSE);
1880 constr->right.SetDone(FALSE);
1881 constr->bottom.SetDone(FALSE);
1882 constr->width.SetDone(FALSE);
1883 constr->height.SetDone(FALSE);
1884 constr->centreX.SetDone(FALSE);
1885 constr->centreY.SetDone(FALSE);
1886 }
1887 wxNode *node = GetChildren().First();
1888 while (node)
1889 {
1890 wxWindow *win = (wxWindow *)node->Data();
1891 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
1892 win->ResetConstraints();
1893 node = node->Next();
1894 }
1895 }
1896
1897 // Need to distinguish between setting the 'fake' size for
1898 // windows and sizers, and setting the real values.
1899 void wxWindow::SetConstraintSizes(bool recurse)
1900 {
1901 wxLayoutConstraints *constr = GetConstraints();
1902 if (constr && constr->left.GetDone() && constr->right.GetDone() &&
1903 constr->width.GetDone() && constr->height.GetDone())
1904 {
1905 int x = constr->left.GetValue();
1906 int y = constr->top.GetValue();
1907 int w = constr->width.GetValue();
1908 int h = constr->height.GetValue();
1909
1910 // If we don't want to resize this window, just move it...
1911 if ((constr->width.GetRelationship() != wxAsIs) ||
1912 (constr->height.GetRelationship() != wxAsIs))
1913 {
1914 // Calls Layout() recursively. AAAGH. How can we stop that.
1915 // Simply take Layout() out of non-top level OnSizes.
1916 SizerSetSize(x, y, w, h);
1917 }
1918 else
1919 {
1920 SizerMove(x, y);
1921 }
1922 }
1923 else if (constr)
1924 {
1925 char *windowClass = this->GetClassInfo()->GetClassName();
1926
1927 wxString winName;
1928 if (GetName() == "")
1929 winName = "unnamed";
1930 else
1931 winName = GetName();
1932 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass, (const char *)winName);
1933 if (!constr->left.GetDone())
1934 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1935 if (!constr->right.GetDone())
1936 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1937 if (!constr->width.GetDone())
1938 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1939 if (!constr->height.GetDone())
1940 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1941 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1942 }
1943
1944 if (recurse)
1945 {
1946 wxNode *node = GetChildren().First();
1947 while (node)
1948 {
1949 wxWindow *win = (wxWindow *)node->Data();
1950 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
1951 win->SetConstraintSizes();
1952 node = node->Next();
1953 }
1954 }
1955 }
1956
1957 // This assumes that all sizers are 'on' the same
1958 // window, i.e. the parent of this window.
1959 void wxWindow::TransformSizerToActual(int *x, int *y) const
1960 {
1961 if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) ||
1962 m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) )
1963 return;
1964
1965 int xp, yp;
1966 m_sizerParent->GetPosition(&xp, &yp);
1967 m_sizerParent->TransformSizerToActual(&xp, &yp);
1968 *x += xp;
1969 *y += yp;
1970 }
1971
1972 void wxWindow::SizerSetSize(int x, int y, int w, int h)
1973 {
1974 int xx = x;
1975 int yy = y;
1976 TransformSizerToActual(&xx, &yy);
1977 SetSize(xx, yy, w, h);
1978 }
1979
1980 void wxWindow::SizerMove(int x, int y)
1981 {
1982 int xx = x;
1983 int yy = y;
1984 TransformSizerToActual(&xx, &yy);
1985 Move(xx, yy);
1986 }
1987
1988 // Only set the size/position of the constraint (if any)
1989 void wxWindow::SetSizeConstraint(int x, int y, int w, int h)
1990 {
1991 wxLayoutConstraints *constr = GetConstraints();
1992 if (constr)
1993 {
1994 if (x != -1)
1995 {
1996 constr->left.SetValue(x);
1997 constr->left.SetDone(TRUE);
1998 }
1999 if (y != -1)
2000 {
2001 constr->top.SetValue(y);
2002 constr->top.SetDone(TRUE);
2003 }
2004 if (w != -1)
2005 {
2006 constr->width.SetValue(w);
2007 constr->width.SetDone(TRUE);
2008 }
2009 if (h != -1)
2010 {
2011 constr->height.SetValue(h);
2012 constr->height.SetDone(TRUE);
2013 }
2014 }
2015 }
2016
2017 void wxWindow::MoveConstraint(int x, int y)
2018 {
2019 wxLayoutConstraints *constr = GetConstraints();
2020 if (constr)
2021 {
2022 if (x != -1)
2023 {
2024 constr->left.SetValue(x);
2025 constr->left.SetDone(TRUE);
2026 }
2027 if (y != -1)
2028 {
2029 constr->top.SetValue(y);
2030 constr->top.SetDone(TRUE);
2031 }
2032 }
2033 }
2034
2035 void wxWindow::GetSizeConstraint(int *w, int *h) const
2036 {
2037 wxLayoutConstraints *constr = GetConstraints();
2038 if (constr)
2039 {
2040 *w = constr->width.GetValue();
2041 *h = constr->height.GetValue();
2042 }
2043 else
2044 GetSize(w, h);
2045 }
2046
2047 void wxWindow::GetClientSizeConstraint(int *w, int *h) const
2048 {
2049 wxLayoutConstraints *constr = GetConstraints();
2050 if (constr)
2051 {
2052 *w = constr->width.GetValue();
2053 *h = constr->height.GetValue();
2054 }
2055 else
2056 GetClientSize(w, h);
2057 }
2058
2059 void wxWindow::GetPositionConstraint(int *x, int *y) const
2060 {
2061 wxLayoutConstraints *constr = GetConstraints();
2062 if (constr)
2063 {
2064 *x = constr->left.GetValue();
2065 *y = constr->top.GetValue();
2066 }
2067 else
2068 GetPosition(x, y);
2069 }
2070
2071 bool wxWindow::Close(bool force)
2072 {
2073 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
2074 event.SetEventObject(this);
2075 #if WXWIN_COMPATIBILITY
2076 event.SetForce(force);
2077 #endif
2078 event.SetCanVeto(!force);
2079
2080 return GetEventHandler()->ProcessEvent(event);
2081 }
2082
2083 wxObject* wxWindow::GetChild(int number) const
2084 {
2085 // Return a pointer to the Nth object in the window
2086 wxNode *node = GetChildren().First();
2087 int n = number;
2088 while (node && n--)
2089 node = node->Next() ;
2090 if (node)
2091 {
2092 wxObject *obj = (wxObject *)node->Data();
2093 return(obj) ;
2094 }
2095 else
2096 return NULL ;
2097 }
2098
2099 void wxWindow::OnDefaultAction(wxControl *initiatingItem)
2100 {
2101 // Obsolete function
2102 }
2103
2104 void wxWindow::Clear()
2105 {
2106 wxClientDC dc(this);
2107 wxBrush brush(GetBackgroundColour(), wxSOLID);
2108 dc.SetBackground(brush);
2109 dc.Clear();
2110 }
2111
2112 // Fits the panel around the items
2113 void wxWindow::Fit()
2114 {
2115 int maxX = 0;
2116 int maxY = 0;
2117 wxNode *node = GetChildren().First();
2118 while ( node )
2119 {
2120 wxWindow *win = (wxWindow *)node->Data();
2121 int wx, wy, ww, wh;
2122 win->GetPosition(&wx, &wy);
2123 win->GetSize(&ww, &wh);
2124 if ( wx + ww > maxX )
2125 maxX = wx + ww;
2126 if ( wy + wh > maxY )
2127 maxY = wy + wh;
2128
2129 node = node->Next();
2130 }
2131 SetClientSize(maxX + 5, maxY + 5);
2132 }
2133
2134 void wxWindow::SetValidator(const wxValidator& validator)
2135 {
2136 if ( m_windowValidator )
2137 delete m_windowValidator;
2138 m_windowValidator = validator.Clone();
2139
2140 if ( m_windowValidator )
2141 m_windowValidator->SetWindow(this) ;
2142 }
2143
2144 void wxWindow::SetClientObject( wxClientData *data )
2145 {
2146 if (m_clientObject) delete m_clientObject;
2147 m_clientObject = data;
2148 }
2149
2150 wxClientData *wxWindow::GetClientObject()
2151 {
2152 return m_clientObject;
2153 }
2154
2155 void wxWindow::SetClientData( void *data )
2156 {
2157 m_clientData = data;
2158 }
2159
2160 void *wxWindow::GetClientData()
2161 {
2162 return m_clientData;
2163 }
2164
2165 // Find a window by id or name
2166 wxWindow *wxWindow::FindWindow(long id)
2167 {
2168 if ( GetId() == id)
2169 return this;
2170
2171 wxNode *node = GetChildren().First();
2172 while ( node )
2173 {
2174 wxWindow *child = (wxWindow *)node->Data();
2175 wxWindow *found = child->FindWindow(id);
2176 if ( found )
2177 return found;
2178 node = node->Next();
2179 }
2180 return NULL;
2181 }
2182
2183 wxWindow *wxWindow::FindWindow(const wxString& name)
2184 {
2185 if ( GetName() == name)
2186 return this;
2187
2188 wxNode *node = GetChildren().First();
2189 while ( node )
2190 {
2191 wxWindow *child = (wxWindow *)node->Data();
2192 wxWindow *found = child->FindWindow(name);
2193 if ( found )
2194 return found;
2195 node = node->Next();
2196 }
2197 return NULL;
2198 }
2199
2200 void wxWindow::OnIdle(wxIdleEvent& event)
2201 {
2202 // This calls the UI-update mechanism (querying windows for
2203 // menu/toolbar/control state information)
2204 UpdateWindowUI();
2205 }
2206
2207 // Raise the window to the top of the Z order
2208 void wxWindow::Raise()
2209 {
2210 Window window = XtWindow((Widget) GetTopWidget());
2211 XRaiseWindow(XtDisplay((Widget) GetTopWidget()), window);
2212 }
2213
2214 // Lower the window to the bottom of the Z order
2215 void wxWindow::Lower()
2216 {
2217 Window window = XtWindow((Widget) GetTopWidget());
2218 XLowerWindow(XtDisplay((Widget) GetTopWidget()), window);
2219 }
2220
2221 bool wxWindow::AcceptsFocus() const
2222 {
2223 return IsShown() && IsEnabled();
2224 }
2225
2226 // Update region access
2227 wxRegion& wxWindow::GetUpdateRegion() const
2228 {
2229 return (wxRegion&) m_updateRegion;
2230 }
2231
2232 bool wxWindow::IsExposed(int x, int y, int w, int h) const
2233 {
2234 return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion);
2235 }
2236
2237 bool wxWindow::IsExposed(const wxPoint& pt) const
2238 {
2239 return (m_updateRegion.Contains(pt) != wxOutRegion);
2240 }
2241
2242 bool wxWindow::IsExposed(const wxRect& rect) const
2243 {
2244 return (m_updateRegion.Contains(rect) != wxOutRegion);
2245 }
2246
2247 /*
2248 * Allocates control IDs
2249 */
2250
2251 int wxWindow::NewControlId()
2252 {
2253 static int s_controlId = 0;
2254 s_controlId ++;
2255 return s_controlId;
2256 }
2257
2258 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable& accel)
2259 {
2260 m_acceleratorTable = accel;
2261 }
2262
2263 // All widgets should have this as their resize proc.
2264 // OnSize sent to wxWindow via client data.
2265 void wxWidgetResizeProc(Widget w, XConfigureEvent *event, String args[], int *num_args)
2266 {
2267 wxWindow *win = (wxWindow *)wxWidgetHashTable->Get((long)w);
2268 if (!win)
2269 return;
2270
2271 if (win->PreResize())
2272 {
2273 int width, height;
2274 win->GetSize(&width, &height);
2275 wxSizeEvent sizeEvent(wxSize(width, height), win->GetId());
2276 sizeEvent.SetEventObject(win);
2277 win->GetEventHandler()->ProcessEvent(sizeEvent);
2278 }
2279 }
2280
2281 bool wxAddWindowToTable(Widget w, wxWindow *win)
2282 {
2283 wxWindow *oldItem = NULL;
2284 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2285 if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w)))
2286 {
2287 wxLogError("Widget table clash: new widget is %ld, %s", (long)w, win->GetClassInfo()->GetClassName());
2288 return FALSE;
2289 }
2290
2291 wxWidgetHashTable->Put ((long) w, win);
2292 return TRUE;
2293 }
2294
2295 wxWindow *wxGetWindowFromTable(Widget w)
2296 {
2297 return (wxWindow *)wxWidgetHashTable->Get ((long) w);
2298 }
2299
2300 void wxDeleteWindowFromTable(Widget w)
2301 {
2302 wxWidgetHashTable->Delete((long)w);
2303 }
2304
2305 // Get the underlying X window and display
2306 WXWindow wxWindow::GetXWindow() const
2307 {
2308 return (WXWindow) XtWindow((Widget) GetMainWidget());
2309 }
2310
2311 WXDisplay *wxWindow::GetXDisplay() const
2312 {
2313 return (WXDisplay*) XtDisplay((Widget) GetMainWidget());
2314 }
2315
2316 WXWidget wxWindow::GetMainWidget() const
2317 {
2318 if (m_drawingArea)
2319 return m_drawingArea;
2320 else
2321 return m_mainWidget;
2322 }
2323
2324 WXWidget wxWindow::GetClientWidget() const
2325 {
2326 if (m_drawingArea != (WXWidget) 0)
2327 return m_drawingArea;
2328 else
2329 return GetMainWidget();
2330 }
2331
2332 WXWidget wxWindow::GetTopWidget() const
2333 {
2334 return GetMainWidget();
2335 }
2336
2337 void wxCanvasRepaintProc (Widget drawingArea, XtPointer clientData,
2338 XmDrawingAreaCallbackStruct * cbs)
2339 {
2340 if (!wxWidgetHashTable->Get ((long) (Widget) drawingArea))
2341 return;
2342
2343 XEvent * event = cbs->event;
2344 wxWindow * win = (wxWindow *) clientData;
2345 Display * display = (Display *) win->GetXDisplay();
2346
2347 switch (event->type)
2348 {
2349 case Expose:
2350 {
2351 wxRect* rect = new wxRect(event->xexpose.x, event->xexpose.y,
2352 event->xexpose.width, event->xexpose.height);
2353 /*
2354 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2355 cout << rect->width << ", " << rect->height << "\n\n";
2356 */
2357
2358 win->m_updateRects.Append((wxObject*) rect);
2359
2360 if (event -> xexpose.count == 0)
2361 {
2362 wxPaintEvent event(win->GetId());
2363 event.SetEventObject(win);
2364 win->GetEventHandler()->ProcessEvent(event);
2365
2366 win->ClearUpdateRects();
2367 }
2368 break;
2369 }
2370 default:
2371 {
2372 cout << "\n\nNew Event ! is = " << event -> type << "\n";
2373 break;
2374 }
2375 }
2376 }
2377
2378 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2379 void
2380 wxCanvasEnterLeave (Widget drawingArea, XtPointer clientData, XCrossingEvent * event)
2381 {
2382 XmDrawingAreaCallbackStruct cbs;
2383 XEvent ev;
2384
2385 //if (event->mode!=NotifyNormal)
2386 // return ;
2387
2388 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2389 ((XCrossingEvent &) ev) = *event;
2390
2391 cbs.reason = XmCR_INPUT;
2392 cbs.event = &ev;
2393
2394 wxCanvasInputEvent (drawingArea, (XtPointer) NULL, &cbs);
2395 }
2396
2397 // Fix to make it work under Motif 1.0 (!)
2398 void wxCanvasMotionEvent (Widget drawingArea, XButtonEvent * event)
2399 {
2400 #if XmVersion<=1000
2401
2402 XmDrawingAreaCallbackStruct cbs;
2403 XEvent ev;
2404
2405 //ev.xbutton = *event;
2406 ev = *((XEvent *) event);
2407 cbs.reason = XmCR_INPUT;
2408 cbs.event = &ev;
2409
2410 wxCanvasInputEvent (drawingArea, (XtPointer) NULL, &cbs);
2411 #endif
2412 }
2413
2414 void wxCanvasInputEvent (Widget drawingArea, XtPointer data, XmDrawingAreaCallbackStruct * cbs)
2415 {
2416 wxWindow *canvas = (wxWindow *) wxWidgetHashTable->Get ((long) (Widget) drawingArea);
2417 XEvent local_event;
2418
2419 if (canvas==NULL)
2420 return ;
2421
2422 if (cbs->reason != XmCR_INPUT)
2423 return;
2424
2425 local_event = *(cbs->event); // We must keep a copy!
2426
2427 /*
2428 switch (local_event.xany.type)
2429 {
2430 case EnterNotify:
2431 cout << "EnterNotify\n";
2432 break;
2433 case LeaveNotify:
2434 cout << "LeaveNotify\n";
2435 break;
2436 case ButtonPress:
2437 cout << "ButtonPress\n";
2438 break;
2439 case ButtonRelease:
2440 cout << "ButtonRelease\n";
2441 break;
2442 case MotionNotify:
2443 cout << "MotionNotify\n";
2444 break;
2445 default:
2446 cout << "Something else\n";
2447 break;
2448 }
2449 */
2450
2451 switch (local_event.xany.type)
2452 {
2453 case EnterNotify:
2454 case LeaveNotify:
2455 case ButtonPress:
2456 case ButtonRelease:
2457 case MotionNotify:
2458 {
2459 wxEventType eventType = wxEVT_NULL;
2460
2461 if (local_event.xany.type == EnterNotify)
2462 {
2463 //if (local_event.xcrossing.mode!=NotifyNormal)
2464 // return ; // Ignore grab events
2465 eventType = wxEVT_ENTER_WINDOW;
2466 // canvas->GetEventHandler()->OnSetFocus();
2467 }
2468 else if (local_event.xany.type == LeaveNotify)
2469 {
2470 //if (local_event.xcrossing.mode!=NotifyNormal)
2471 // return ; // Ignore grab events
2472 eventType = wxEVT_LEAVE_WINDOW;
2473 // canvas->GetEventHandler()->OnKillFocus();
2474 }
2475 else if (local_event.xany.type == MotionNotify)
2476 {
2477 eventType = wxEVT_MOTION;
2478 if (local_event.xmotion.is_hint == NotifyHint)
2479 {
2480 Window root, child;
2481 Display *dpy = XtDisplay (drawingArea);
2482
2483 XQueryPointer (dpy, XtWindow (drawingArea),
2484 &root, &child,
2485 &local_event.xmotion.x_root,
2486 &local_event.xmotion.y_root,
2487 &local_event.xmotion.x,
2488 &local_event.xmotion.y,
2489 &local_event.xmotion.state);
2490 }
2491 else
2492 {
2493 }
2494 }
2495
2496 else if (local_event.xany.type == ButtonPress)
2497 {
2498 if (local_event.xbutton.button == Button1)
2499 {
2500 eventType = wxEVT_LEFT_DOWN;
2501 canvas->m_button1Pressed = TRUE;
2502 }
2503 else if (local_event.xbutton.button == Button2)
2504 {
2505 eventType = wxEVT_MIDDLE_DOWN;
2506 canvas->m_button2Pressed = TRUE;
2507 }
2508 else if (local_event.xbutton.button == Button3)
2509 {
2510 eventType = wxEVT_RIGHT_DOWN;
2511 canvas->m_button3Pressed = TRUE;
2512 }
2513 }
2514 else if (local_event.xany.type == ButtonRelease)
2515 {
2516 if (local_event.xbutton.button == Button1)
2517 {
2518 eventType = wxEVT_LEFT_UP;
2519 canvas->m_button1Pressed = FALSE;
2520 }
2521 else if (local_event.xbutton.button == Button2)
2522 {
2523 eventType = wxEVT_MIDDLE_UP;
2524 canvas->m_button2Pressed = FALSE;
2525 }
2526 else if (local_event.xbutton.button == Button3)
2527 {
2528 eventType = wxEVT_RIGHT_UP;
2529 canvas->m_button3Pressed = FALSE;
2530 }
2531 }
2532
2533 wxMouseEvent wxevent (eventType);
2534 wxevent.m_eventHandle = (char *) &local_event;
2535
2536 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
2537 || (event_left_is_down (&local_event)
2538 && (eventType != wxEVT_LEFT_UP)));
2539 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
2540 || (event_middle_is_down (&local_event)
2541 && (eventType != wxEVT_MIDDLE_UP)));
2542 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
2543 || (event_right_is_down (&local_event)
2544 && (eventType != wxEVT_RIGHT_UP)));
2545
2546 wxevent.m_shiftDown = local_event.xbutton.state & ShiftMask;
2547 wxevent.m_controlDown = local_event.xbutton.state & ControlMask;
2548 wxevent.m_altDown = local_event.xbutton.state & Mod3Mask;
2549 wxevent.m_metaDown = local_event.xbutton.state & Mod1Mask;
2550 wxevent.SetTimestamp(local_event.xbutton.time);
2551
2552 // Now check if we need to translate this event into a double click
2553 if (TRUE) // canvas->doubleClickAllowed)
2554 {
2555 if (wxevent.ButtonDown())
2556 {
2557 long dclickTime = XtGetMultiClickTime((Display*) wxGetDisplay()) ;
2558
2559 // get button and time-stamp
2560 int button = 0;
2561 if (wxevent.LeftDown()) button = 1;
2562 else if (wxevent.MiddleDown()) button = 2;
2563 else if (wxevent.RightDown()) button = 3;
2564 long ts = wxevent.GetTimestamp();
2565 // check, if single or double click
2566 if (canvas->m_lastButton && canvas->m_lastButton==button && (ts - canvas->m_lastTS) < dclickTime)
2567 {
2568 // I have a dclick
2569 canvas->m_lastButton = 0;
2570 switch ( eventType )
2571 {
2572 case wxEVT_LEFT_DOWN:
2573 wxevent.SetEventType(wxEVT_LEFT_DCLICK);
2574 break;
2575 case wxEVT_MIDDLE_DOWN:
2576 wxevent.SetEventType(wxEVT_MIDDLE_DCLICK);
2577 break;
2578 case wxEVT_RIGHT_DOWN:
2579 wxevent.SetEventType(wxEVT_RIGHT_DCLICK);
2580 break;
2581
2582 default :
2583 break;
2584 }
2585
2586 }
2587 else
2588 {
2589 // not fast enough or different button
2590 canvas->m_lastTS = ts;
2591 canvas->m_lastButton = button;
2592 }
2593 }
2594 }
2595
2596 wxevent.SetId(canvas->GetId());
2597 wxevent.SetEventObject(canvas);
2598 wxevent.m_x = local_event.xbutton.x;
2599 wxevent.m_y = local_event.xbutton.y;
2600 canvas->GetEventHandler()->ProcessEvent (wxevent);
2601 /*
2602 if (eventType == wxEVT_ENTER_WINDOW ||
2603 eventType == wxEVT_LEAVE_WINDOW ||
2604 eventType == wxEVT_MOTION
2605 )
2606 return;
2607 */
2608 break;
2609 }
2610 case KeyPress:
2611 {
2612 KeySym keySym;
2613 // XComposeStatus compose;
2614 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2615 (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL);
2616 int id = wxCharCodeXToWX (keySym);
2617
2618 wxEventType eventType = wxEVT_CHAR;
2619
2620 // TODO: Is this the correct criterion for wxEVT_KEY_DOWN down versus wxEVT_CHAR?
2621 if (id > WXK_START) // Non-ASCII values
2622 eventType = wxEVT_KEY_DOWN;
2623
2624 wxKeyEvent event (eventType);
2625
2626 if (local_event.xkey.state & ShiftMask)
2627 event.m_shiftDown = TRUE;
2628 if (local_event.xkey.state & ControlMask)
2629 event.m_controlDown = TRUE;
2630 if (local_event.xkey.state & Mod3Mask)
2631 event.m_altDown = TRUE;
2632 if (local_event.xkey.state & Mod1Mask)
2633 event.m_metaDown = TRUE;
2634 event.SetEventObject(canvas);
2635 event.m_keyCode = id;
2636 event.SetTimestamp(local_event.xkey.time);
2637
2638 if (id > -1)
2639 {
2640 // Implement wxFrame::OnCharHook by checking ancestor.
2641 wxWindow *parent = canvas->GetParent();
2642 while (parent && !parent->IsKindOf(CLASSINFO(wxFrame)))
2643 parent = parent->GetParent();
2644
2645 if (parent)
2646 {
2647 event.SetEventType(wxEVT_CHAR_HOOK);
2648 if (parent->GetEventHandler()->ProcessEvent(event))
2649 return;
2650 event.SetEventType(wxEVT_CHAR);
2651 }
2652
2653 canvas->GetEventHandler()->ProcessEvent (event);
2654 }
2655 break;
2656 }
2657 case KeyRelease:
2658 {
2659 KeySym keySym;
2660 (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL);
2661 int id = wxCharCodeXToWX (keySym);
2662
2663 wxKeyEvent event (wxEVT_KEY_UP);
2664
2665 if (local_event.xkey.state & ShiftMask)
2666 event.m_shiftDown = TRUE;
2667 if (local_event.xkey.state & ControlMask)
2668 event.m_controlDown = TRUE;
2669 if (local_event.xkey.state & Mod3Mask)
2670 event.m_altDown = TRUE;
2671 if (local_event.xkey.state & Mod1Mask)
2672 event.m_metaDown = TRUE;
2673 event.SetEventObject(canvas);
2674 event.m_keyCode = id;
2675 event.SetTimestamp(local_event.xkey.time);
2676
2677 if (id > -1)
2678 {
2679 canvas->GetEventHandler()->ProcessEvent (event);
2680 }
2681 break;
2682 }
2683 case FocusIn:
2684 {
2685 if (local_event.xfocus.detail != NotifyPointer)
2686 {
2687 wxFocusEvent event(wxEVT_SET_FOCUS, canvas->GetId());
2688 event.SetEventObject(canvas);
2689 canvas->GetEventHandler()->ProcessEvent(event);
2690 }
2691 break;
2692 }
2693 case FocusOut:
2694 {
2695 if (local_event.xfocus.detail != NotifyPointer)
2696 {
2697 wxFocusEvent event(wxEVT_KILL_FOCUS, canvas->GetId());
2698 event.SetEventObject(canvas);
2699 canvas->GetEventHandler()->ProcessEvent(event);
2700 }
2701 break;
2702 }
2703 default:
2704 break;
2705 }
2706 }
2707
2708 void wxWindow::DoPaint()
2709 {
2710 //TODO : make a temporary gc so we can do the XCopyArea below
2711 if (0) // m_backingPixmap)
2712 {
2713 /*
2714 Widget drawingArea = (Widget) m_drawingArea;
2715 // int orig = GetDC()->GetLogicalFunction();
2716 // GetDC()->SetLogicalFunction (wxCOPY);
2717
2718 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2719 // should be able to calculate them.
2720 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2721 m_pixmapOffsetX, m_pixmapOffsetY,
2722 m_pixmapWidth, m_pixmapHeight,
2723 0, 0);
2724
2725 // GetDC()->SetLogicalFunction (orig);
2726 */
2727 }
2728 else
2729 {
2730 wxPaintEvent event(GetId());
2731 event.SetEventObject(this);
2732 GetEventHandler()->ProcessEvent(event);
2733 }
2734 }
2735
2736 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2737 void wxWindow::CanvasSetSize (int x, int y, int w, int h, int sizeFlags)
2738 {
2739 // A bit of optimization to help sort out the flickers.
2740 int oldX, oldY, oldW, oldH;
2741 GetSize(& oldW, & oldH);
2742 GetPosition(& oldX, & oldY);
2743
2744 bool useOldPos = FALSE;
2745 bool useOldSize = FALSE;
2746
2747 if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0))
2748 useOldPos = TRUE;
2749 else if (x == oldX && y == oldY)
2750 useOldPos = TRUE;
2751
2752 if ((w == -1) && (h == -1))
2753 useOldSize = TRUE;
2754 else if (w == oldW && h == oldH)
2755 useOldSize = TRUE;
2756
2757 if (!wxNoOptimize::CanOptimize())
2758 {
2759 useOldSize = FALSE; useOldPos = FALSE;
2760 }
2761
2762 if (useOldPos && useOldSize)
2763 return;
2764
2765 Widget drawingArea = (Widget) m_drawingArea;
2766 bool managed = XtIsManaged(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
2767
2768 if (managed)
2769 XtUnmanageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
2770 XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
2771
2772 int xx = x; int yy = y;
2773 AdjustForParentClientOrigin(xx, yy, sizeFlags);
2774
2775 if (!useOldPos)
2776 {
2777 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
2778 {
2779 XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow,
2780 XmNx, xx, NULL);
2781 }
2782
2783 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
2784 {
2785 XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow,
2786 XmNy, yy, NULL);
2787 }
2788 }
2789
2790 if (!useOldSize)
2791 {
2792
2793 if (w > -1)
2794 {
2795 if (m_borderWidget)
2796 {
2797 XtVaSetValues ((Widget) m_borderWidget, XmNwidth, w, NULL);
2798 short thick, margin;
2799 XtVaGetValues ((Widget) m_borderWidget,
2800 XmNshadowThickness, &thick,
2801 XmNmarginWidth, &margin,
2802 NULL);
2803 w -= 2 * (thick + margin);
2804 }
2805
2806 XtVaSetValues ((Widget) m_scrolledWindow, XmNwidth, w, NULL);
2807
2808 Dimension spacing;
2809 Widget sbar;
2810 XtVaGetValues ((Widget) m_scrolledWindow,
2811 XmNspacing, &spacing,
2812 XmNverticalScrollBar, &sbar,
2813 NULL);
2814 Dimension wsbar;
2815 if (sbar)
2816 XtVaGetValues (sbar, XmNwidth, &wsbar, NULL);
2817 else
2818 wsbar = 0;
2819
2820 w -= (spacing + wsbar);
2821
2822 // XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2823 }
2824 if (h > -1)
2825 {
2826 if (m_borderWidget)
2827 {
2828 XtVaSetValues ((Widget) m_borderWidget, XmNheight, h, NULL);
2829 short thick, margin;
2830 XtVaGetValues ((Widget) m_borderWidget,
2831 XmNshadowThickness, &thick,
2832 XmNmarginHeight, &margin,
2833 NULL);
2834 h -= 2 * (thick + margin);
2835 }
2836
2837 XtVaSetValues ((Widget) m_scrolledWindow, XmNheight, h, NULL);
2838
2839 Dimension spacing;
2840 Widget sbar;
2841 XtVaGetValues ((Widget) m_scrolledWindow,
2842 XmNspacing, &spacing,
2843 XmNhorizontalScrollBar, &sbar,
2844 NULL);
2845 Dimension wsbar;
2846 if (sbar)
2847 XtVaGetValues (sbar, XmNheight, &wsbar, NULL);
2848 else
2849 wsbar = 0;
2850
2851 h -= (spacing + wsbar);
2852
2853 // XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2854
2855 }
2856 }
2857
2858 if (managed)
2859 XtManageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
2860 XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
2861
2862 /*
2863 int ww, hh;
2864 GetClientSize (&ww, &hh);
2865 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2866 sizeEvent.SetEventObject(this);
2867
2868 GetEventHandler()->ProcessEvent(sizeEvent);
2869 */
2870
2871 }
2872
2873 void wxWindow::CanvasSetClientSize (int w, int h)
2874 {
2875 Widget drawingArea = (Widget) m_drawingArea;
2876
2877 XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
2878
2879 if (w > -1)
2880 XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2881 if (h > -1)
2882 XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2883 /* TODO: is this necessary?
2884 allowRepainting = FALSE;
2885
2886 XSync (XtDisplay (drawingArea), FALSE);
2887 XEvent event;
2888 while (XtAppPending (wxTheApp->appContext))
2889 {
2890 XFlush (XtDisplay (drawingArea));
2891 XtAppNextEvent (wxTheApp->appContext, &event);
2892 XtDispatchEvent (&event);
2893 }
2894 */
2895
2896 XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
2897
2898 /* TODO
2899 allowRepainting = TRUE;
2900 DoRefresh ();
2901 */
2902
2903 /*
2904 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2905 sizeEvent.SetEventObject(this);
2906
2907 GetEventHandler()->ProcessEvent(sizeEvent);
2908 */
2909 }
2910
2911 void wxWindow::CanvasGetClientSize (int *w, int *h) const
2912 {
2913 // Must return the same thing that was set via SetClientSize
2914 Dimension xx, yy;
2915 XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL);
2916 *w = xx;
2917 *h = yy;
2918 }
2919
2920 void wxWindow::CanvasGetSize (int *w, int *h) const
2921 {
2922 Dimension xx, yy;
2923 if ((Widget) m_borderWidget)
2924 XtVaGetValues ((Widget) m_borderWidget, XmNwidth, &xx, XmNheight, &yy, NULL);
2925 else if ((Widget) m_scrolledWindow)
2926 XtVaGetValues ((Widget) m_scrolledWindow, XmNwidth, &xx, XmNheight, &yy, NULL);
2927 else
2928 XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL);
2929
2930 *w = xx;
2931 *h = yy;
2932 }
2933
2934 void wxWindow::CanvasGetPosition (int *x, int *y) const
2935 {
2936 Position xx, yy;
2937 XtVaGetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, XmNx, &xx, XmNy, &yy, NULL);
2938
2939 // We may be faking the client origin.
2940 // So a window that's really at (0, 30) may appear
2941 // (to wxWin apps) to be at (0, 0).
2942 if (GetParent())
2943 {
2944 wxPoint pt(GetParent()->GetClientAreaOrigin());
2945 xx -= pt.x;
2946 yy -= pt.y;
2947 }
2948
2949 *x = xx;
2950 *y = yy;
2951 }
2952
2953 // Add to hash table, add event handler
2954 bool wxWindow::AttachWidget (wxWindow* parent, WXWidget mainWidget,
2955 WXWidget formWidget, int x, int y, int width, int height)
2956 {
2957 wxAddWindowToTable((Widget) mainWidget, this);
2958 if (CanAddEventHandler())
2959 {
2960 XtAddEventHandler((Widget) mainWidget,
2961 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask,
2962 False,
2963 wxPanelItemEventHandler,
2964 (XtPointer) this);
2965 }
2966
2967 if (!formWidget)
2968 {
2969 XtTranslations ptr;
2970 XtOverrideTranslations ((Widget) mainWidget,
2971 ptr = XtParseTranslationTable ("<Configure>: resize()"));
2972 XtFree ((char *) ptr);
2973 }
2974
2975 // Some widgets have a parent form widget, e.g. wxRadioBox
2976 if (formWidget)
2977 {
2978 if (!wxAddWindowToTable((Widget) formWidget, this))
2979 return FALSE;
2980
2981 XtTranslations ptr;
2982 XtOverrideTranslations ((Widget) formWidget,
2983 ptr = XtParseTranslationTable ("<Configure>: resize()"));
2984 XtFree ((char *) ptr);
2985 }
2986
2987 if (x == -1)
2988 x = 0;
2989 if (y == -1)
2990 y = 0;
2991 SetSize (x, y, width, height);
2992
2993 return TRUE;
2994 }
2995
2996 // Remove event handler, remove from hash table
2997 bool wxWindow::DetachWidget(WXWidget widget)
2998 {
2999 if (CanAddEventHandler())
3000 {
3001 XtRemoveEventHandler((Widget) widget,
3002 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask,
3003 False,
3004 wxPanelItemEventHandler,
3005 (XtPointer)this);
3006 }
3007
3008 wxDeleteWindowFromTable((Widget) widget);
3009 return TRUE;
3010 }
3011
3012 void wxPanelItemEventHandler (Widget wid,
3013 XtPointer client_data,
3014 XEvent* event,
3015 Boolean *continueToDispatch)
3016 {
3017 // Widget can be a label or the actual widget.
3018
3019 wxWindow *window = (wxWindow *)wxWidgetHashTable->Get((long)wid);
3020 if (window)
3021 {
3022 wxMouseEvent wxevent(0);
3023 if (wxTranslateMouseEvent(wxevent, window, wid, event))
3024 {
3025 window->GetEventHandler()->ProcessEvent(wxevent);
3026 }
3027 }
3028 // TODO: probably the key to allowing default behaviour
3029 // to happen.
3030 // Say we set a m_doDefault flag to FALSE at the start of this
3031 // function. Then in e.g. wxWindow::OnMouseEvent we can
3032 // call Default() which sets this flag to TRUE, indicating
3033 // that default processing can happen. Thus, behaviour can appear
3034 // to be overridden just by adding an event handler and not calling
3035 // wxWindow::OnWhatever.
3036 // ALSO, maybe we can use this instead of the current way of handling
3037 // drawing area events, to simplify things.
3038 *continueToDispatch = True;
3039 }
3040
3041 static void wxScrollBarCallback(Widget scrollbar, XtPointer clientData,
3042 XmScaleCallbackStruct *cbs)
3043 {
3044 Widget scrolledWindow = XtParent (scrollbar);
3045 wxWindow *win = (wxWindow *) wxWidgetHashTable->Get ((long) scrolledWindow);
3046 int orientation = (int) clientData;
3047
3048 wxEventType eventType = wxEVT_NULL;
3049 switch (cbs->reason)
3050 {
3051 case XmCR_INCREMENT:
3052 {
3053 eventType = wxEVT_SCROLL_LINEDOWN;
3054 break;
3055 }
3056 case XmCR_DECREMENT:
3057 {
3058 eventType = wxEVT_SCROLL_LINEUP;
3059 break;
3060 }
3061 case XmCR_DRAG:
3062 {
3063 eventType = wxEVT_SCROLL_THUMBTRACK;
3064 break;
3065 }
3066 case XmCR_VALUE_CHANGED:
3067 {
3068 // TODO: Should this be intercepted too, or will it cause
3069 // duplicate events?
3070 eventType = wxEVT_SCROLL_THUMBTRACK;
3071 break;
3072 }
3073 case XmCR_PAGE_INCREMENT:
3074 {
3075 eventType = wxEVT_SCROLL_PAGEDOWN;
3076 break;
3077 }
3078 case XmCR_PAGE_DECREMENT:
3079 {
3080 eventType = wxEVT_SCROLL_PAGEUP;
3081 break;
3082 }
3083 case XmCR_TO_TOP:
3084 {
3085 eventType = wxEVT_SCROLL_TOP;
3086 break;
3087 }
3088 case XmCR_TO_BOTTOM:
3089 {
3090 eventType = wxEVT_SCROLL_BOTTOM;
3091 break;
3092 }
3093 default:
3094 {
3095 // Should never get here
3096 wxFAIL_MSG("Unknown scroll event.");
3097 break;
3098 }
3099 }
3100
3101 wxScrollEvent event(eventType, win->GetId());
3102 event.SetEventObject(win);
3103 event.SetPosition(cbs->value);
3104 event.SetOrientation( (orientation == XmHORIZONTAL) ? wxHORIZONTAL : wxVERTICAL );
3105
3106 win->GetEventHandler()->ProcessEvent(event);
3107 }
3108
3109 bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent)
3110 {
3111 switch (xevent->xany.type)
3112 {
3113 case EnterNotify:
3114 case LeaveNotify:
3115 case ButtonPress:
3116 case ButtonRelease:
3117 case MotionNotify:
3118 {
3119 wxEventType eventType = wxEVT_NULL;
3120
3121 if (xevent->xany.type == LeaveNotify)
3122 {
3123 win->m_button1Pressed = FALSE;
3124 win->m_button2Pressed = FALSE;
3125 win->m_button3Pressed = FALSE;
3126 return FALSE;
3127 }
3128 else if (xevent->xany.type == MotionNotify)
3129 {
3130 eventType = wxEVT_MOTION;
3131 }
3132 else if (xevent->xany.type == ButtonPress)
3133 {
3134 if (xevent->xbutton.button == Button1)
3135 {
3136 eventType = wxEVT_LEFT_DOWN;
3137 win->m_button1Pressed = TRUE;
3138 }
3139 else if (xevent->xbutton.button == Button2)
3140 {
3141 eventType = wxEVT_MIDDLE_DOWN;
3142 win->m_button2Pressed = TRUE;
3143 }
3144 else if (xevent->xbutton.button == Button3)
3145 {
3146 eventType = wxEVT_RIGHT_DOWN;
3147 win->m_button3Pressed = TRUE;
3148 }
3149 }
3150 else if (xevent->xany.type == ButtonRelease)
3151 {
3152 if (xevent->xbutton.button == Button1)
3153 {
3154 eventType = wxEVT_LEFT_UP;
3155 win->m_button1Pressed = FALSE;
3156 }
3157 else if (xevent->xbutton.button == Button2)
3158 {
3159 eventType = wxEVT_MIDDLE_UP;
3160 win->m_button2Pressed = FALSE;
3161 }
3162 else if (xevent->xbutton.button == Button3)
3163 {
3164 eventType = wxEVT_RIGHT_UP;
3165 win->m_button3Pressed = FALSE;
3166 }
3167 else return FALSE;
3168 }
3169 else return FALSE;
3170
3171 wxevent.m_eventHandle = (char *)xevent;
3172 wxevent.SetEventType(eventType);
3173
3174 Position x1, y1;
3175 XtVaGetValues(widget, XmNx, &x1, XmNy, &y1, NULL);
3176
3177 int x2, y2;
3178 win->GetPosition(&x2, &y2);
3179
3180 // The button x/y must be translated to wxWindows
3181 // window space - the widget might be a label or button,
3182 // within a form.
3183 int dx = 0;
3184 int dy = 0;
3185 if (widget != (Widget)win->GetMainWidget())
3186 {
3187 dx = x1;
3188 dy = y1;
3189 }
3190
3191 wxevent.m_x = xevent->xbutton.x + dx;
3192 wxevent.m_y = xevent->xbutton.y + dy;
3193
3194 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
3195 || (event_left_is_down (xevent)
3196 && (eventType != wxEVT_LEFT_UP)));
3197 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
3198 || (event_middle_is_down (xevent)
3199 && (eventType != wxEVT_MIDDLE_UP)));
3200 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
3201 || (event_right_is_down (xevent)
3202 && (eventType != wxEVT_RIGHT_UP)));
3203
3204 wxevent.m_shiftDown = xevent->xbutton.state & ShiftMask;
3205 wxevent.m_controlDown = xevent->xbutton.state & ControlMask;
3206 return TRUE;
3207 }
3208 }
3209 return FALSE;
3210 }
3211
3212 bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent)
3213 {
3214 switch (xevent->xany.type)
3215 {
3216 case KeyPress:
3217 {
3218 char buf[20];
3219
3220 KeySym keySym;
3221 // XComposeStatus compose;
3222 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
3223 (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL);
3224 int id = wxCharCodeXToWX (keySym);
3225
3226 if (xevent->xkey.state & ShiftMask)
3227 wxevent.m_shiftDown = TRUE;
3228 if (xevent->xkey.state & ControlMask)
3229 wxevent.m_controlDown = TRUE;
3230 if (xevent->xkey.state & Mod3Mask)
3231 wxevent.m_altDown = TRUE;
3232 if (xevent->xkey.state & Mod1Mask)
3233 wxevent.m_metaDown = TRUE;
3234 wxevent.SetEventObject(win);
3235 wxevent.m_keyCode = id;
3236 wxevent.SetTimestamp(xevent->xkey.time);
3237
3238 wxevent.m_x = xevent->xbutton.x;
3239 wxevent.m_y = xevent->xbutton.y;
3240
3241 if (id > -1)
3242 return TRUE;
3243 else
3244 return FALSE;
3245 break;
3246 }
3247 default:
3248 break;
3249 }
3250 return FALSE;
3251 }
3252
3253 #define YAllocColor XAllocColor
3254 XColor g_itemColors[5];
3255 int wxComputeColours (Display *display, wxColour * back, wxColour * fore)
3256 {
3257 int result;
3258 static XmColorProc colorProc;
3259
3260 result = wxNO_COLORS;
3261
3262 if (back)
3263 {
3264 g_itemColors[0].red = (((long) back->Red ()) << 8);
3265 g_itemColors[0].green = (((long) back->Green ()) << 8);
3266 g_itemColors[0].blue = (((long) back->Blue ()) << 8);
3267 g_itemColors[0].flags = DoRed | DoGreen | DoBlue;
3268 if (colorProc == (XmColorProc) NULL)
3269 {
3270 // Get a ptr to the actual function
3271 colorProc = XmSetColorCalculation ((XmColorProc) NULL);
3272 // And set it back to motif.
3273 XmSetColorCalculation (colorProc);
3274 }
3275 (*colorProc) (&g_itemColors[wxBACK_INDEX],
3276 &g_itemColors[wxFORE_INDEX],
3277 &g_itemColors[wxSELE_INDEX],
3278 &g_itemColors[wxTOPS_INDEX],
3279 &g_itemColors[wxBOTS_INDEX]);
3280 result = wxBACK_COLORS;
3281 }
3282 if (fore)
3283 {
3284 g_itemColors[wxFORE_INDEX].red = (((long) fore->Red ()) << 8);
3285 g_itemColors[wxFORE_INDEX].green = (((long) fore->Green ()) << 8);
3286 g_itemColors[wxFORE_INDEX].blue = (((long) fore->Blue ()) << 8);
3287 g_itemColors[wxFORE_INDEX].flags = DoRed | DoGreen | DoBlue;
3288 if (result == wxNO_COLORS)
3289 result = wxFORE_COLORS;
3290 }
3291
3292 Display *dpy = display;
3293 Colormap cmap = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) dpy);
3294
3295 if (back)
3296 {
3297 /* 5 Colours to allocate */
3298 for (int i = 0; i < 5; i++)
3299 if (!YAllocColor (dpy, cmap, &g_itemColors[i]))
3300 result = wxNO_COLORS;
3301 }
3302 else if (fore)
3303 {
3304 /* Only 1 colour to allocate */
3305 if (!YAllocColor (dpy, cmap, &g_itemColors[wxFORE_INDEX]))
3306 result = wxNO_COLORS;
3307 }
3308
3309 return (result);
3310
3311 }
3312
3313 // Changes the foreground and background colours to be derived
3314 // from the current background colour.
3315 // To change the foreground colour, you must call SetForegroundColour
3316 // explicitly.
3317 void wxWindow::ChangeBackgroundColour()
3318 {
3319 if (GetMainWidget())
3320 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour);
3321
3322 // This not necessary
3323 #if 0
3324
3325 if (m_scrolledWindow && (GetMainWidget() != m_scrolledWindow))
3326 {
3327 DoChangeBackgroundColour(m_scrolledWindow, m_backgroundColour);
3328 // Have to set the scrollbar colours back since
3329 // the scrolled window seemed to change them
3330 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ;
3331
3332 if (m_hScrollBar)
3333 DoChangeBackgroundColour(m_hScrollBar, backgroundColour);
3334 if (m_vScrollBar)
3335 DoChangeBackgroundColour(m_vScrollBar, backgroundColour);
3336 }
3337 #endif
3338 }
3339
3340 void wxWindow::ChangeForegroundColour()
3341 {
3342 if (GetMainWidget())
3343 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour);
3344 if (m_scrolledWindow && (GetMainWidget() != m_scrolledWindow))
3345 DoChangeForegroundColour(m_scrolledWindow, m_foregroundColour);
3346 }
3347
3348 // Change a widget's foreground and background colours.
3349
3350 void wxWindow::DoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour)
3351 {
3352 // When should we specify the foreground, if it's calculated
3353 // by wxComputeColours?
3354 // Solution: say we start with the default (computed) foreground colour.
3355 // If we call SetForegroundColour explicitly for a control or window,
3356 // then the foreground is changed.
3357 // Therefore SetBackgroundColour computes the foreground colour, and
3358 // SetForegroundColour changes the foreground colour. The ordering is
3359 // important.
3360
3361 XtVaSetValues ((Widget) widget,
3362 XmNforeground, foregroundColour.AllocColour(XtDisplay((Widget) widget)),
3363 NULL);
3364 }
3365
3366 void wxWindow::DoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour)
3367 {
3368 wxComputeColours (XtDisplay((Widget) widget), & backgroundColour,
3369 (wxColour*) NULL);
3370
3371 XtVaSetValues ((Widget) widget,
3372 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
3373 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
3374 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
3375 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
3376 NULL);
3377
3378 if (changeArmColour)
3379 XtVaSetValues ((Widget) widget,
3380 XmNarmColor, g_itemColors[wxSELE_INDEX].pixel,
3381 NULL);
3382 }
3383
3384 void wxWindow::SetBackgroundColour(const wxColour& col)
3385 {
3386 m_backgroundColour = col;
3387 ChangeBackgroundColour();
3388 }
3389
3390 void wxWindow::SetForegroundColour(const wxColour& col)
3391 {
3392 m_foregroundColour = col;
3393 ChangeForegroundColour();
3394 }
3395
3396 void wxWindow::ChangeFont(bool keepOriginalSize)
3397 {
3398 // Note that this causes the widget to be resized back
3399 // to its original size! We therefore have to set the size
3400 // back again. TODO: a better way in Motif?
3401 Widget w = (Widget) GetLabelWidget(); // Usually the main widget
3402 if (w && m_windowFont.Ok())
3403 {
3404 int width, height, width1, height1;
3405 GetSize(& width, & height);
3406
3407 // lesstif 0.87 hangs here
3408 #ifndef LESSTIF_VERSION
3409 XtVaSetValues (w,
3410 XmNfontList, (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(w)),
3411 NULL);
3412 #endif
3413
3414 GetSize(& width1, & height1);
3415 if (keepOriginalSize && (width != width1 || height != height1))
3416 {
3417 SetSize(-1, -1, width, height);
3418 }
3419 }
3420 }
3421
3422 void wxWindow::SetFont(const wxFont& font)
3423 {
3424 m_windowFont = font;
3425 ChangeFont();
3426 }
3427
3428 void wxWindow::SetToolTip(const wxString& tooltip)
3429 {
3430 // TODO
3431 }
3432
3433 void wxWindow::ClearUpdateRects()
3434 {
3435 wxNode* node = m_updateRects.First();
3436 while (node)
3437 {
3438 wxRect* rect = (wxRect*) node->Data();
3439 delete rect;
3440 node = node->Next();
3441 }
3442 m_updateRects.Clear();
3443 }
3444
3445 bool wxWindow::ProcessAccelerator(wxKeyEvent& event)
3446 {
3447 if (!m_acceleratorTable.Ok())
3448 return FALSE;
3449
3450 int count = m_acceleratorTable.GetCount();
3451 wxAcceleratorEntry* entries = m_acceleratorTable.GetEntries();
3452 int i;
3453 for (i = 0; i < count; i++)
3454 {
3455 wxAcceleratorEntry* entry = & (entries[i]);
3456 if (entry->MatchesEvent(event))
3457 {
3458 // Bingo, we have a match. Now find a control
3459 // that matches the entry command id.
3460
3461 // Need to go up to the top of the window hierarchy,
3462 // since it might be e.g. a menu item
3463 wxWindow* parent = this;
3464 while (parent && !parent->IsKindOf(CLASSINFO(wxFrame)) && !parent->IsKindOf(CLASSINFO(wxDialog)))
3465 parent = parent->GetParent();
3466
3467 if (!parent)
3468 return FALSE;
3469
3470 if (parent->IsKindOf(CLASSINFO(wxFrame)))
3471 {
3472 // Try for a menu command
3473 wxFrame* frame = (wxFrame*) parent;
3474 if (frame->GetMenuBar())
3475 {
3476 wxMenuItem* item = frame->GetMenuBar()->FindItemForId(entry->GetCommand());
3477 if (item)
3478 {
3479 wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, entry->GetCommand());
3480 commandEvent.SetEventObject(frame);
3481
3482 // If ProcessEvent returns TRUE (it was handled), then
3483 // the calling code will skip the event handling.
3484 return frame->GetEventHandler()->ProcessEvent(commandEvent);
3485 }
3486 }
3487 }
3488
3489 // Find a child matching the command id
3490 wxWindow* child = parent->FindWindow(entry->GetCommand());
3491
3492 // No such child
3493 if (!child)
3494 return FALSE;
3495
3496 // Now we process those kinds of windows that we can.
3497 // For now, only buttons.
3498 if (child->IsKindOf(CLASSINFO(wxButton)))
3499 {
3500 wxCommandEvent commandEvent (wxEVT_COMMAND_BUTTON_CLICKED, child->GetId());
3501 commandEvent.SetEventObject(child);
3502 return child->GetEventHandler()->ProcessEvent(commandEvent);
3503 }
3504
3505 return FALSE;
3506 } // matches event
3507 }// for
3508
3509 // We didn't match the key event against an accelerator.
3510 return FALSE;
3511 }
3512
3513 /*
3514 * wxNoOptimize: switch off size optimization
3515 */
3516
3517 int wxNoOptimize::m_count = 0;
3518
3519 wxNoOptimize::wxNoOptimize()
3520 {
3521 m_count ++;
3522 }
3523
3524 wxNoOptimize::~wxNoOptimize()
3525 {
3526 m_count --;
3527 }
3528
3529 bool wxNoOptimize::CanOptimize()
3530 {
3531 return (m_count == 0);
3532 }
3533