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