]> git.saurik.com Git - wxWidgets.git/blob - src/motif/window.cpp
Added wxHTML build to Makefile for VisualC++
[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 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "window.h"
22 #endif
23
24 #include "wx/setup.h"
25 #include "wx/menu.h"
26 #include "wx/dc.h"
27 #include "wx/dcclient.h"
28 #include "wx/utils.h"
29 #include "wx/app.h"
30 #include "wx/panel.h"
31 #include "wx/layout.h"
32 #include "wx/dialog.h"
33 #include "wx/listbox.h"
34 #include "wx/button.h"
35 #include "wx/settings.h"
36 #include "wx/msgdlg.h"
37 #include "wx/frame.h"
38 #include "wx/scrolwin.h"
39 #include "wx/module.h"
40 #include "wx/menuitem.h"
41 #include "wx/log.h"
42
43 #include "wx/listimpl.cpp"
44
45 #if wxUSE_DRAG_AND_DROP
46 #include "wx/dnd.h"
47 #endif
48
49 #include <Xm/Xm.h>
50
51 #include <Xm/DrawingA.h>
52 #include <Xm/ScrolledW.h>
53 #include <Xm/ScrollBar.h>
54 #include <Xm/Frame.h>
55 #include <Xm/Label.h>
56
57 #include "wx/motif/private.h"
58
59 #include <string.h>
60
61 // ----------------------------------------------------------------------------
62 // constants
63 // ----------------------------------------------------------------------------
64
65 static const int SCROLL_MARGIN = 4;
66
67 // ----------------------------------------------------------------------------
68 // global variables for this module
69 // ----------------------------------------------------------------------------
70
71 extern wxHashTable *wxWidgetHashTable;
72
73 // ----------------------------------------------------------------------------
74 // private functions
75 // ----------------------------------------------------------------------------
76
77 static void wxCanvasRepaintProc(Widget, XtPointer, XmDrawingAreaCallbackStruct * cbs);
78 static void wxCanvasInputEvent(Widget drawingArea, XtPointer data, XmDrawingAreaCallbackStruct * cbs);
79 static void wxCanvasMotionEvent(Widget, XButtonEvent * event);
80 static void wxCanvasEnterLeave(Widget drawingArea, XtPointer clientData, XCrossingEvent * event);
81 static void wxScrollBarCallback(Widget widget, XtPointer clientData,
82 XmScaleCallbackStruct *cbs);
83 static void wxPanelItemEventHandler(Widget wid,
84 XtPointer client_data,
85 XEvent* event,
86 Boolean *continueToDispatch);
87
88 // unused for now
89 #if 0
90
91 // Helper function for 16-bit fonts
92 static int str16len(const char *s)
93 {
94 int count = 0;
95
96 while (s[0] && s[1]) {
97 count++;
98 s += 2;
99 }
100
101 return count;
102 }
103
104 #endif // 0
105
106 // ----------------------------------------------------------------------------
107 // macros
108 // ----------------------------------------------------------------------------
109
110 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
111 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
112 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
113
114 // ----------------------------------------------------------------------------
115 // event tables
116 // ----------------------------------------------------------------------------
117
118 #if !USE_SHARED_LIBRARY
119 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler)
120
121 BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
122 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
123 EVT_IDLE(wxWindow::OnIdle)
124 END_EVENT_TABLE()
125 #endif // USE_SHARED_LIBRARY
126
127 // ============================================================================
128 // implementation
129 // ============================================================================
130
131 // ----------------------------------------------------------------------------
132 // list types
133 // ----------------------------------------------------------------------------
134
135 WX_DEFINE_LIST(wxRectList);
136
137 // ----------------------------------------------------------------------------
138 // helper functions
139 // ----------------------------------------------------------------------------
140
141 void wxWindow::UnmanageAndDestroy(WXWidget widget)
142 {
143 Widget w = (Widget)widget;
144 if ( w )
145 {
146 XtUnmanageChild(w);
147 XtDestroyWidget(w);
148 }
149 }
150
151 bool wxWindow::MapOrUnmap(WXWidget widget, bool map)
152 {
153 Widget w = (Widget)widget;
154 if ( !w )
155 return FALSE;
156
157 if ( map )
158 XtMapWidget(w);
159 else
160 XtUnmapWidget(w);
161
162 return TRUE;
163 }
164
165 // ----------------------------------------------------------------------------
166 // constructors
167 // ----------------------------------------------------------------------------
168
169 void wxWindow::Init()
170 {
171 // generic initializations first
172 InitBase();
173
174 // Motif-specific
175 m_needsRefresh = TRUE;
176 m_mainWidget = (WXWidget) 0;
177
178 m_button1Pressed =
179 m_button2Pressed =
180 m_button3Pressed = FALSE;
181
182 m_winCaptured = FALSE;
183
184 m_isShown = TRUE;
185
186 m_hScrollBar =
187 m_vScrollBar =
188 m_borderWidget =
189 m_scrolledWindow =
190 m_drawingArea = (WXWidget) 0;
191
192 m_hScroll =
193 m_vScroll = FALSE;
194
195 m_scrollPosX =
196 m_scrollPosY = 0;
197
198 m_backingPixmap = (WXPixmap) 0;
199 m_pixmapWidth =
200 m_pixmapHeight = 0;
201
202 m_pixmapOffsetX =
203 m_pixmapOffsetY = 0;
204
205 m_lastTS = 0;
206 m_lastButton = 0;
207 m_canAddEventHandler = FALSE;
208 }
209
210 // real construction (Init() must have been called before!)
211 bool wxWindow::Create(wxWindow *parent, wxWindowID id,
212 const wxPoint& pos,
213 const wxSize& size,
214 long style,
215 const wxString& name)
216 {
217 wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" );
218
219 CreateBase(parent, id, pos, size, style, name);
220
221 parent->AddChild(this);
222
223 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
224 m_foregroundColour = *wxBLACK;
225
226 //// TODO: we should probably optimize by only creating a
227 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
228 //// But for now, let's simplify things by always creating the
229 //// drawing area, since otherwise the translations are different.
230
231 // New translations for getting mouse motion feedback
232 static const String translations =
233 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
234 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
235 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
236 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
237 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
238 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
239 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
240 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
241 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
242 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
243 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
244 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
245 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
246 <Key>: DrawingAreaInput()";
247
248 XtActionsRec actions[1];
249 actions[0].string = "wxCanvasMotionEvent";
250 actions[0].proc = (XtActionProc) wxCanvasMotionEvent;
251 XtAppAddActions ((XtAppContext) wxTheApp->GetAppContext(), actions, 1);
252
253 Widget parentWidget = (Widget) parent->GetClientWidget();
254 if (style & wxBORDER)
255 {
256 m_borderWidget = (WXWidget)XtVaCreateManagedWidget
257 (
258 "canvasBorder",
259 xmFrameWidgetClass, parentWidget,
260 XmNshadowType, XmSHADOW_IN,
261 NULL
262 );
263 }
264
265 m_scrolledWindow = (WXWidget)XtVaCreateManagedWidget
266 (
267 "scrolledWindow",
268 xmScrolledWindowWidgetClass,
269 m_borderWidget ? (Widget) m_borderWidget
270 : parentWidget,
271 XmNresizePolicy, XmRESIZE_NONE,
272 XmNspacing, 0,
273 XmNscrollingPolicy, XmAPPLICATION_DEFINED,
274 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
275 NULL
276 );
277
278 XtTranslations ptr = XtParseTranslationTable(translations);
279 m_drawingArea = (WXWidget)XtVaCreateWidget
280 (
281 name,
282 xmDrawingAreaWidgetClass, (Widget) m_scrolledWindow,
283 XmNunitType, XmPIXELS,
284 // XmNresizePolicy, XmRESIZE_ANY,
285 XmNresizePolicy, XmRESIZE_NONE,
286 XmNmarginHeight, 0,
287 XmNmarginWidth, 0,
288 XmNtranslations, ptr,
289 NULL
290 );
291 XtFree((char *) ptr);
292
293 #if 0
294 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
295 {
296 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
297 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
298 XtFree ((char *) ptr);
299 }
300 #endif // 0
301
302 wxAddWindowToTable((Widget) m_drawingArea, this);
303 wxAddWindowToTable((Widget) m_scrolledWindow, this);
304
305 // This order is very important in Motif 1.2.1
306 XtRealizeWidget ((Widget) m_scrolledWindow);
307 XtRealizeWidget ((Widget) m_drawingArea);
308 XtManageChild ((Widget) m_drawingArea);
309
310 ptr = XtParseTranslationTable("<Configure>: resize()");
311 XtOverrideTranslations((Widget) m_drawingArea, ptr);
312 XtFree ((char *) ptr);
313
314 XtAddCallback ((Widget) m_drawingArea, XmNexposeCallback, (XtCallbackProc) wxCanvasRepaintProc, (XtPointer) this);
315 XtAddCallback ((Widget) m_drawingArea, XmNinputCallback, (XtCallbackProc) wxCanvasInputEvent, (XtPointer) this);
316
317 // TODO?
318 #if 0
319 display = XtDisplay (scrolledWindow);
320 xwindow = XtWindow (drawingArea);
321 #endif // 0
322
323 XtAddEventHandler(
324 (Widget)m_drawingArea,
325 PointerMotionHintMask | EnterWindowMask |
326 LeaveWindowMask | FocusChangeMask,
327 False,
328 (XtEventHandler) wxCanvasEnterLeave,
329 (XtPointer) this
330 );
331
332 // Scrolled widget needs to have its colour changed or we get a little blue
333 // square where the scrollbars abutt
334 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
335 DoChangeBackgroundColour(m_scrolledWindow, backgroundColour, TRUE);
336 DoChangeBackgroundColour(m_drawingArea, backgroundColour, TRUE);
337
338 XmScrolledWindowSetAreas(
339 (Widget)m_scrolledWindow,
340 (Widget) 0, (Widget) 0,
341 (Widget) m_drawingArea);
342
343 #if 0
344 if (m_hScrollBar)
345 XtRealizeWidget ((Widget) m_hScrollBar);
346 if (m_vScrollBar)
347 XtRealizeWidget ((Widget) m_vScrollBar);
348 #endif // 0
349
350 // Without this, the cursor may not be restored properly (e.g. in splitter
351 // sample).
352 SetCursor(*wxSTANDARD_CURSOR);
353 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
354 SetSize(pos.x, pos.y, size.x, size.y);
355
356 return TRUE;
357 }
358
359 // Destructor
360 wxWindow::~wxWindow()
361 {
362 // Motif-specific actions first
363 WXWidget wMain = GetMainWidget();
364 if ( wMain )
365 {
366 // Removes event handlers
367 DetachWidget(wMain);
368 }
369
370 ClearUpdateRects();
371
372 // If m_drawingArea, we're a fully-fledged window with drawing area,
373 // scrollbars etc. (what wxCanvas used to be)
374 if ( m_drawingArea )
375 {
376 // Destroy children before destroying self
377 DestroyChildren();
378
379 if (m_backingPixmap)
380 XFreePixmap (XtDisplay ((Widget) GetMainWidget()), (Pixmap) m_backingPixmap);
381
382 Widget w = (Widget) m_drawingArea;
383 wxDeleteWindowFromTable(w);
384
385 if (w)
386 {
387 XtDestroyWidget(w);
388 }
389
390 m_mainWidget = (WXWidget) 0;
391
392 // Only if we're _really_ a canvas (not a dialog box/panel)
393 if (m_scrolledWindow)
394 {
395 wxDeleteWindowFromTable((Widget) m_scrolledWindow);
396 }
397
398 UnmanageAndDestroy(m_hScrollBar);
399 UnmanageAndDestroy(m_vScrollBar);
400 UnmanageAndDestroy(m_scrolledWindow);
401
402 if (m_borderWidget)
403 {
404 XtDestroyWidget ((Widget) m_borderWidget);
405 m_borderWidget = (WXWidget) 0;
406 }
407 }
408
409 // Destroy the window
410 if (GetMainWidget())
411 {
412 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
413 // Child widgets will get destroyed automatically when a frame
414 // or dialog is destroyed, but before that you may get some memory
415 // leaks and potential layout problems if you delete and then add
416 // child windows.
417 XtDestroyWidget((Widget) GetMainWidget());
418 SetMainWidget((WXWidget) NULL);
419 }
420 }
421
422 // ----------------------------------------------------------------------------
423 // scrollbar management
424 // ----------------------------------------------------------------------------
425
426 // Helper function
427 void wxWindow::CreateScrollbar(wxOrientation orientation)
428 {
429 wxCHECK_RET( m_drawingArea, "this window can't have scrollbars" );
430
431 XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_NONE, NULL);
432
433 // Add scrollbars if required
434 if (orientation == wxHORIZONTAL)
435 {
436 Widget hScrollBar = XtVaCreateManagedWidget ("hsb",
437 xmScrollBarWidgetClass, (Widget) m_scrolledWindow,
438 XmNorientation, XmHORIZONTAL,
439 NULL);
440 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
441 XtAddCallback (hScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
442 XtAddCallback (hScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
443 XtAddCallback (hScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
444 XtAddCallback (hScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
445 XtAddCallback (hScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
446 XtAddCallback (hScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
447 XtAddCallback (hScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
448
449 XtVaSetValues (hScrollBar,
450 XmNincrement, 1,
451 XmNvalue, 0,
452 NULL);
453
454 m_hScrollBar = (WXWidget) hScrollBar;
455
456 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
457 DoChangeBackgroundColour(m_hScrollBar, backgroundColour, TRUE);
458
459 XtRealizeWidget(hScrollBar);
460
461 XtVaSetValues((Widget) m_scrolledWindow,
462 XmNhorizontalScrollBar, (Widget) m_hScrollBar,
463 NULL);
464
465 m_hScroll = TRUE;
466 }
467
468 if (orientation == wxVERTICAL)
469 {
470 Widget vScrollBar = XtVaCreateManagedWidget ("vsb",
471 xmScrollBarWidgetClass, (Widget) m_scrolledWindow,
472 XmNorientation, XmVERTICAL,
473 NULL);
474 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
475 XtAddCallback (vScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
476 XtAddCallback (vScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
477 XtAddCallback (vScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
478 XtAddCallback (vScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
479 XtAddCallback (vScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
480 XtAddCallback (vScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
481 XtAddCallback (vScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
482
483 XtVaSetValues (vScrollBar,
484 XmNincrement, 1,
485 XmNvalue, 0,
486 NULL);
487
488 m_vScrollBar = (WXWidget) vScrollBar;
489 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
490 DoChangeBackgroundColour(m_vScrollBar, backgroundColour, TRUE);
491
492 XtRealizeWidget(vScrollBar);
493
494 XtVaSetValues((Widget) m_scrolledWindow,
495 XmNverticalScrollBar, (Widget) m_vScrollBar,
496 NULL);
497
498 m_vScroll = TRUE;
499 }
500
501 XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL);
502 }
503
504 void wxWindow::DestroyScrollbar(wxOrientation orientation)
505 {
506 wxCHECK_RET( m_drawingArea, "this window can't have scrollbars" );
507
508 XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_NONE, NULL);
509 // Add scrollbars if required
510 if (orientation == wxHORIZONTAL)
511 {
512 if (m_hScrollBar)
513 {
514 XtDestroyWidget((Widget) m_hScrollBar);
515 }
516 m_hScrollBar = (WXWidget) 0;
517 m_hScroll = FALSE;
518
519 XtVaSetValues((Widget) m_scrolledWindow,
520 XmNhorizontalScrollBar, (Widget) 0,
521 NULL);
522
523 }
524
525 if (orientation == wxVERTICAL)
526 {
527 if (m_vScrollBar)
528 {
529 XtDestroyWidget((Widget) m_vScrollBar);
530 }
531 m_vScrollBar = (WXWidget) 0;
532 m_vScroll = TRUE;
533
534 XtVaSetValues((Widget) m_scrolledWindow,
535 XmNverticalScrollBar, (Widget) 0,
536 NULL);
537
538 }
539 XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL);
540 }
541
542 // ---------------------------------------------------------------------------
543 // basic operations
544 // ---------------------------------------------------------------------------
545
546 void wxWindow::SetFocus()
547 {
548 Widget wMain = (Widget) GetMainWidget();
549 XmProcessTraversal(wMain, XmTRAVERSE_CURRENT);
550 XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT);
551 }
552
553 // Get the window with the focus
554 wxWindow *wxWindowBase::FindFocus()
555 {
556 // TODO Problems:
557 // (1) Can there be multiple focussed widgets in an application?
558 // In which case we need to find the top-level window that's
559 // currently active.
560 // (2) The widget with the focus may not be in the widget table
561 // depending on which widgets I put in the table
562 wxWindow *winFocus = (wxWindow *)NULL;
563 for ( wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
564 node;
565 node = node->GetNext() )
566 {
567 wxWindow *win = node->GetData();
568
569 Widget w = XmGetFocusWidget ((Widget) win->GetTopWidget());
570
571 if (w != (Widget) NULL)
572 {
573 winFocus = wxGetWindowFromTable(w);
574 if ( winFocus )
575 break;
576 }
577 }
578
579 return winFocus;
580 }
581
582 bool wxWindow::Enable(bool enable)
583 {
584 if ( !wxWindowBase::Enable(enable) )
585 return FALSE;
586
587 Widget wMain = (Widget)GetMainWidget();
588 if ( wMain )
589 {
590 XtSetSensitive(wMain, enable);
591 XmUpdateDisplay(wMain);
592 }
593
594 return TRUE;
595 }
596
597 bool wxWindow::Show(bool show)
598 {
599 if ( !wxWindowBase::Show(show) )
600 return FALSE;
601
602 if (m_borderWidget || m_scrolledWindow)
603 {
604 MapOrUnmap(m_drawingArea, show);
605 MapOrUnmap(m_borderWidget ? m_borderWidget : m_scrolledWindow, show);
606 }
607 else
608 {
609 if ( !MapOrUnmap(GetTopWidget(), show) )
610 MapOrUnmap(GetMainWidget(), show);
611 }
612
613 #if 0
614 Window xwin = (Window) GetXWindow();
615 Display *xdisp = (Display*) GetXDisplay();
616 if (show)
617 XMapWindow(xdisp, xwin);
618 else
619 XUnmapWindow(xdisp, xwin);
620 #endif
621
622 return TRUE;
623 }
624
625 // Raise the window to the top of the Z order
626 void wxWindow::Raise()
627 {
628 Widget wTop = (Widget) GetTopWidget();
629 Window window = XtWindow(wTop);
630 XRaiseWindow(XtDisplay(wTop), window);
631 }
632
633 // Lower the window to the bottom of the Z order
634 void wxWindow::Lower()
635 {
636 Widget wTop = (Widget) GetTopWidget();
637 Window window = XtWindow(wTop);
638 XLowerWindow(XtDisplay(wTop), window);
639 }
640
641 void wxWindow::SetTitle(const wxString& title)
642 {
643 XtVaSetValues((Widget)GetMainWidget(), XmNtitle, title.c_str(), NULL);
644 }
645
646 wxString wxWindow::GetTitle() const
647 {
648 char *title;
649 XtVaGetValues((Widget)GetMainWidget(), XmNtitle, &title, NULL);
650
651 return wxString(title);
652 }
653
654 void wxWindow::CaptureMouse()
655 {
656 if ( m_winCaptured )
657 return;
658
659 Widget wMain = (Widget)GetMainWidget();
660 if ( wMain )
661 XtAddGrab(wMain, TRUE, FALSE);
662
663 m_winCaptured = TRUE;
664 }
665
666 void wxWindow::ReleaseMouse()
667 {
668 if ( !m_winCaptured )
669 return;
670
671 Widget wMain = (Widget)GetMainWidget();
672 if ( wMain )
673 XtRemoveGrab(wMain);
674
675 m_winCaptured = FALSE;
676 }
677
678 bool wxWindow::SetFont(const wxFont& font)
679 {
680 if ( !wxWindowBase::SetFont(font) )
681 {
682 // nothing to do
683 return FALSE;
684 }
685
686 ChangeFont();
687
688 return TRUE;
689 }
690
691 bool wxWindow::SetCursor(const wxCursor& cursor)
692 {
693 if ( !wxWindowBase::SetCursor(cursor) )
694 {
695 // no change
696 return FALSE;
697 }
698
699 wxASSERT_MSG( m_cursor.Ok(),
700 _T("cursor must be valid after call to the base version"));
701
702 WXDisplay *dpy = GetXDisplay();
703 WXCursor x_cursor = m_cursor.GetXCursor(dpy);
704
705 Widget w = (Widget) GetMainWidget();
706 Window win = XtWindow(w);
707 XDefineCursor((Display*) dpy, win, (Cursor) x_cursor);
708
709 return TRUE;
710 }
711
712 // Coordinates relative to the window
713 void wxWindow::WarpPointer (int x, int y)
714 {
715 Widget wClient = (Widget)GetClientWidget();
716
717 XWarpPointer(XtDisplay(wClient), None, XtWindow(wClient), 0, 0, 0, 0, x, y);
718 }
719
720 // ---------------------------------------------------------------------------
721 // scrolling stuff
722 // ---------------------------------------------------------------------------
723
724 int wxWindow::GetScrollPos(int orient) const
725 {
726 if (orient == wxHORIZONTAL)
727 return m_scrollPosX;
728 else
729 return m_scrollPosY;
730
731 #if 0
732 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
733 if (scrollBar)
734 {
735 int pos;
736 XtVaGetValues(scrollBar, XmNvalue, &pos, NULL);
737 return pos;
738 }
739 else
740 return 0;
741 #endif // 0
742 }
743
744 // This now returns the whole range, not just the number of positions that we
745 // can scroll.
746 int wxWindow::GetScrollRange(int orient) const
747 {
748 Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient);
749 wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
750
751 int range;
752 XtVaGetValues(scrollBar, XmNmaximum, &range, NULL);
753 return range;
754 }
755
756 int wxWindow::GetScrollThumb(int orient) const
757 {
758 Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient);
759 wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
760
761 int thumb;
762 XtVaGetValues(scrollBar, XmNsliderSize, &thumb, NULL);
763 return thumb;
764 }
765
766 void wxWindow::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
767 {
768 Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient);
769
770 if ( scrollBar )
771 {
772 XtVaSetValues (scrollBar, XmNvalue, pos, NULL);
773 }
774
775 SetInternalScrollPos((wxOrientation)orient, pos);
776 }
777
778 // New function that will replace some of the above.
779 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
780 int range, bool WXUNUSED(refresh))
781 {
782 int oldW, oldH;
783 GetSize(& oldW, & oldH);
784
785 if (range == 0)
786 range = 1;
787 if (thumbVisible == 0)
788 thumbVisible = 1;
789
790 if (thumbVisible > range)
791 thumbVisible = range;
792
793 // Save the old state to see if it changed
794 WXWidget oldScrollBar = GetScrollbar((wxOrientation)orient);
795
796 if (orient == wxHORIZONTAL)
797 {
798 if (thumbVisible == range)
799 {
800 if (m_hScrollBar)
801 DestroyScrollbar(wxHORIZONTAL);
802 }
803 else
804 {
805 if (!m_hScrollBar)
806 CreateScrollbar(wxHORIZONTAL);
807 }
808 }
809 if (orient == wxVERTICAL)
810 {
811 if (thumbVisible == range)
812 {
813 if (m_vScrollBar)
814 DestroyScrollbar(wxVERTICAL);
815 }
816 else
817 {
818 if (!m_vScrollBar)
819 CreateScrollbar(wxVERTICAL);
820 }
821 }
822 WXWidget newScrollBar = GetScrollbar((wxOrientation)orient);
823
824 if (oldScrollBar != newScrollBar)
825 {
826 // This is important! Without it, scrollbars misbehave badly.
827 XtUnrealizeWidget((Widget) m_scrolledWindow);
828 XmScrolledWindowSetAreas ((Widget) m_scrolledWindow, (Widget) m_hScrollBar, (Widget) m_vScrollBar, (Widget) m_drawingArea);
829 XtRealizeWidget((Widget) m_scrolledWindow);
830 XtManageChild((Widget) m_scrolledWindow);
831 }
832
833 if (newScrollBar)
834 {
835 XtVaSetValues((Widget) newScrollBar,
836 XmNvalue, pos,
837 XmNminimum, 0,
838 XmNmaximum, range,
839 XmNsliderSize, thumbVisible,
840 NULL);
841 }
842
843 SetInternalScrollPos((wxOrientation)orient, pos);
844
845 int newW, newH;
846 GetSize(& newW, & newH);
847
848 // Adjusting scrollbars can resize the canvas accidentally
849 if (newW != oldW || newH != oldH)
850 SetSize(-1, -1, oldW, oldH);
851 }
852
853 // Does a physical scroll
854 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
855 {
856 int x, y, w, h;
857 if (rect)
858 {
859 // Use specified rectangle
860 x = rect->x; y = rect->y; w = rect->width; h = rect->height;
861 }
862 else
863 {
864 // Use whole client area
865 x = 0; y = 0;
866 GetClientSize(& w, & h);
867 }
868
869 int x1 = (dx >= 0) ? x : x - dx;
870 int y1 = (dy >= 0) ? y : y - dy;
871 int w1 = w - abs(dx);
872 int h1 = h - abs(dy);
873 int x2 = (dx >= 0) ? x + dx : x;
874 int y2 = (dy >= 0) ? y + dy : y;
875
876 wxClientDC dc(this);
877
878 dc.SetLogicalFunction (wxCOPY);
879
880 Widget widget = (Widget) GetMainWidget();
881 Window window = XtWindow(widget);
882 Display* display = XtDisplay(widget);
883
884 XCopyArea(display, window, window, (GC) dc.GetGC(),
885 x1, y1, w1, h1, x2, y2);
886
887 dc.SetAutoSetting(TRUE);
888 wxBrush brush(GetBackgroundColour(), wxSOLID);
889 dc.SetBrush(brush); // FIXME: needed?
890
891 // We'll add rectangles to the list of update rectangles according to which
892 // bits we've exposed.
893 wxList updateRects;
894
895 if (dx > 0)
896 {
897 wxRect *rect = new wxRect;
898 rect->x = x;
899 rect->y = y;
900 rect->width = dx;
901 rect->height = h;
902
903 XFillRectangle(display, window,
904 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
905
906 rect->x = rect->x;
907 rect->y = rect->y;
908 rect->width = rect->width;
909 rect->height = rect->height;
910
911 updateRects.Append((wxObject*) rect);
912 }
913 else if (dx < 0)
914 {
915 wxRect *rect = new wxRect;
916
917 rect->x = x + w + dx;
918 rect->y = y;
919 rect->width = -dx;
920 rect->height = h;
921
922 XFillRectangle(display, window,
923 (GC) dc.GetGC(), rect->x, rect->y, rect->width,
924 rect->height);
925
926 rect->x = rect->x;
927 rect->y = rect->y;
928 rect->width = rect->width;
929 rect->height = rect->height;
930
931 updateRects.Append((wxObject*) rect);
932 }
933 if (dy > 0)
934 {
935 wxRect *rect = new wxRect;
936
937 rect->x = x;
938 rect->y = y;
939 rect->width = w;
940 rect->height = dy;
941
942 XFillRectangle(display, window,
943 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
944
945 rect->x = rect->x;
946 rect->y = rect->y;
947 rect->width = rect->width;
948 rect->height = rect->height;
949
950 updateRects.Append((wxObject*) rect);
951 }
952 else if (dy < 0)
953 {
954 wxRect *rect = new wxRect;
955
956 rect->x = x;
957 rect->y = y + h + dy;
958 rect->width = w;
959 rect->height = -dy;
960
961 XFillRectangle(display, window,
962 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
963
964 rect->x = rect->x;
965 rect->y = rect->y;
966 rect->width = rect->width;
967 rect->height = rect->height;
968
969 updateRects.Append((wxObject*) rect);
970 }
971 dc.SetBrush(wxNullBrush);
972
973 // Now send expose events
974
975 wxNode* node = updateRects.First();
976 while (node)
977 {
978 wxRect* rect = (wxRect*) node->Data();
979 XExposeEvent event;
980
981 event.type = Expose;
982 event.display = display;
983 event.send_event = True;
984 event.window = window;
985
986 event.x = rect->x;
987 event.y = rect->y;
988 event.width = rect->width;
989 event.height = rect->height;
990
991 event.count = 0;
992
993 XSendEvent(display, window, False, ExposureMask, (XEvent *)&event);
994
995 node = node->Next();
996
997 }
998
999 // Delete the update rects
1000 node = updateRects.First();
1001 while (node)
1002 {
1003 wxRect* rect = (wxRect*) node->Data();
1004 delete rect;
1005 node = node->Next();
1006 }
1007
1008 XmUpdateDisplay((Widget) GetMainWidget());
1009 }
1010
1011 // ---------------------------------------------------------------------------
1012 // drag and drop
1013 // ---------------------------------------------------------------------------
1014
1015 #if wxUSE_DRAG_AND_DROP
1016
1017 void wxWindow::SetDropTarget(wxDropTarget * WXUNUSED(pDropTarget))
1018 {
1019 // TODO
1020 }
1021
1022 #endif
1023
1024 // Old style file-manager drag&drop
1025 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept))
1026 {
1027 // TODO
1028 }
1029
1030 // ----------------------------------------------------------------------------
1031 // tooltips
1032 // ----------------------------------------------------------------------------
1033
1034 #if wxUSE_TOOLTIPS
1035
1036 void wxWindow::DoSetToolTip(wxToolTip * WXUNUSED(tooltip))
1037 {
1038 // TODO
1039 }
1040
1041 #endif // wxUSE_TOOLTIPS
1042
1043 // ---------------------------------------------------------------------------
1044 // moving and resizing
1045 // ---------------------------------------------------------------------------
1046
1047 bool wxWindow::PreResize()
1048 {
1049 return TRUE;
1050 }
1051
1052 // Get total size
1053 void wxWindow::DoGetSize(int *x, int *y) const
1054 {
1055 if (m_drawingArea)
1056 {
1057 CanvasGetSize(x, y);
1058 return;
1059 }
1060
1061 Widget widget = (Widget) GetTopWidget();
1062 Dimension xx, yy;
1063 XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
1064 *x = xx; *y = yy;
1065 }
1066
1067 void wxWindow::DoGetPosition(int *x, int *y) const
1068 {
1069 if (m_drawingArea)
1070 {
1071 CanvasGetPosition(x, y);
1072 return;
1073 }
1074 Widget widget = (Widget) GetTopWidget();
1075 Position xx, yy;
1076 XtVaGetValues(widget, XmNx, &xx, XmNy, &yy, NULL);
1077
1078 // We may be faking the client origin. So a window that's really at (0, 30)
1079 // may appear (to wxWin apps) to be at (0, 0).
1080 if (GetParent())
1081 {
1082 wxPoint pt(GetParent()->GetClientAreaOrigin());
1083 xx -= pt.x;
1084 yy -= pt.y;
1085 }
1086
1087 *x = xx; *y = yy;
1088 }
1089
1090 void wxWindow::DoScreenToClient(int *x, int *y) const
1091 {
1092 Widget widget = (Widget) GetClientWidget();
1093 Display *display = XtDisplay((Widget) GetMainWidget());
1094 Window rootWindow = RootWindowOfScreen(XtScreen(widget));
1095 Window thisWindow = XtWindow(widget);
1096
1097 Window childWindow;
1098 int xx = *x;
1099 int yy = *y;
1100 XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow);
1101 }
1102
1103 void wxWindow::DoClientToScreen(int *x, int *y) const
1104 {
1105 Widget widget = (Widget) GetClientWidget();
1106 Display *display = XtDisplay(widget);
1107 Window rootWindow = RootWindowOfScreen(XtScreen(widget));
1108 Window thisWindow = XtWindow(widget);
1109
1110 Window childWindow;
1111 int xx = *x;
1112 int yy = *y;
1113 XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow);
1114 }
1115
1116
1117 // Get size *available for subwindows* i.e. excluding menu bar etc.
1118 void wxWindow::DoGetClientSize(int *x, int *y) const
1119 {
1120 Widget widget = (Widget) GetClientWidget();
1121 Dimension xx, yy;
1122 XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
1123 *x = xx; *y = yy;
1124 }
1125
1126 void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1127 {
1128 // A bit of optimization to help sort out the flickers.
1129 int oldX, oldY, oldW, oldH;
1130 GetSize(& oldW, & oldH);
1131 GetPosition(& oldX, & oldY);
1132
1133 bool useOldPos = FALSE;
1134 bool useOldSize = FALSE;
1135
1136 if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0))
1137 useOldPos = TRUE;
1138 else if (x == oldX && y == oldY)
1139 useOldPos = TRUE;
1140
1141 if ((width == -1) && (height == -1))
1142 useOldSize = TRUE;
1143 else if (width == oldW && height == oldH)
1144 useOldSize = TRUE;
1145
1146 if (!wxNoOptimize::CanOptimize())
1147 {
1148 useOldSize = FALSE; useOldPos = FALSE;
1149 }
1150
1151 if (useOldPos && useOldSize)
1152 return;
1153
1154 if (m_drawingArea)
1155 {
1156 CanvasSetSize(x, y, width, height, sizeFlags);
1157 return;
1158 }
1159 Widget widget = (Widget) GetTopWidget();
1160 if (!widget)
1161 return;
1162
1163 bool managed = XtIsManaged( widget );
1164 if (managed)
1165 XtUnmanageChild(widget);
1166
1167 int xx = x; int yy = y;
1168 AdjustForParentClientOrigin(xx, yy, sizeFlags);
1169
1170 if (!useOldPos)
1171 {
1172 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
1173 XtVaSetValues(widget, XmNx, xx, NULL);
1174 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
1175 XtVaSetValues(widget, XmNy, yy, NULL);
1176 }
1177 if (!useOldSize)
1178 {
1179 if (width > -1)
1180 XtVaSetValues(widget, XmNwidth, width, NULL);
1181 if (height > -1)
1182 XtVaSetValues(widget, XmNheight, height, NULL);
1183 }
1184
1185 if (managed)
1186 XtManageChild(widget);
1187
1188 // How about this bit. Maybe we don't need to generate size events
1189 // all the time -- they'll be generated when the window is sized anyway.
1190 #if 0
1191 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
1192 sizeEvent.SetEventObject(this);
1193
1194 GetEventHandler()->ProcessEvent(sizeEvent);
1195 #endif // 0
1196 }
1197
1198 void wxWindow::DoSetClientSize(int width, int height)
1199 {
1200 if (m_drawingArea)
1201 {
1202 CanvasSetClientSize(width, height);
1203 return;
1204 }
1205
1206 Widget widget = (Widget) GetTopWidget();
1207
1208 if (width > -1)
1209 XtVaSetValues(widget, XmNwidth, width, NULL);
1210 if (height > -1)
1211 XtVaSetValues(widget, XmNheight, height, NULL);
1212
1213 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
1214 sizeEvent.SetEventObject(this);
1215
1216 GetEventHandler()->ProcessEvent(sizeEvent);
1217 }
1218
1219 // For implementation purposes - sometimes decorations make the client area
1220 // smaller
1221 wxPoint wxWindow::GetClientAreaOrigin() const
1222 {
1223 return wxPoint(0, 0);
1224 }
1225
1226 // Makes an adjustment to the window position (for example, a frame that has
1227 // a toolbar that it manages itself).
1228 void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
1229 {
1230 if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
1231 {
1232 wxPoint pt(GetParent()->GetClientAreaOrigin());
1233 x += pt.x; y += pt.y;
1234 }
1235 }
1236
1237 void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH)
1238 {
1239 m_minWidth = minW;
1240 m_minHeight = minH;
1241 m_maxWidth = maxW;
1242 m_maxHeight = maxH;
1243
1244 wxFrame *frame = wxDynamicCast(this, wxFrame);
1245 if ( !frame )
1246 {
1247 // TODO what about dialogs?
1248 return;
1249 }
1250
1251 Widget widget = (Widget) frame->GetShellWidget();
1252
1253 if (minW > -1)
1254 XtVaSetValues(widget, XmNminWidth, minW, NULL);
1255 if (minH > -1)
1256 XtVaSetValues(widget, XmNminHeight, minH, NULL);
1257 if (maxW > -1)
1258 XtVaSetValues(widget, XmNmaxWidth, maxW, NULL);
1259 if (maxH > -1)
1260 XtVaSetValues(widget, XmNmaxHeight, maxH, NULL);
1261 if (incW > -1)
1262 XtVaSetValues(widget, XmNwidthInc, incW, NULL);
1263 if (incH > -1)
1264 XtVaSetValues(widget, XmNheightInc, incH, NULL);
1265 }
1266
1267 // ---------------------------------------------------------------------------
1268 // text metrics
1269 // ---------------------------------------------------------------------------
1270
1271 int wxWindow::GetCharHeight() const
1272 {
1273 wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
1274
1275 WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay());
1276
1277 int direction, ascent, descent;
1278 XCharStruct overall;
1279 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
1280 &descent, &overall);
1281
1282 // return (overall.ascent + overall.descent);
1283 return (ascent + descent);
1284 }
1285
1286 int wxWindow::GetCharWidth() const
1287 {
1288 wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
1289
1290 WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay());
1291
1292 int direction, ascent, descent;
1293 XCharStruct overall;
1294 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
1295 &descent, &overall);
1296
1297 return overall.width;
1298 }
1299
1300 void wxWindow::GetTextExtent(const wxString& string,
1301 int *x, int *y,
1302 int *descent, int *externalLeading,
1303 const wxFont *theFont) const
1304 {
1305 wxFont *fontToUse = (wxFont *)theFont;
1306 if (!fontToUse)
1307 fontToUse = (wxFont *) & m_font;
1308
1309 wxCHECK_RET( fontToUse->Ok(), "valid window font needed" );
1310
1311 WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay());
1312
1313 int direction, ascent, descent2;
1314 XCharStruct overall;
1315 int slen;
1316
1317 #if 0
1318 if (use16)
1319 XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction,
1320 &ascent, &descent2, &overall);
1321 #endif
1322
1323 XTextExtents((XFontStruct*) pFontStruct, string, slen,
1324 &direction, &ascent, &descent2, &overall);
1325
1326 if ( x )
1327 *x = (overall.width);
1328 if ( y )
1329 *y = (ascent + descent2);
1330 if (descent)
1331 *descent = descent2;
1332 if (externalLeading)
1333 *externalLeading = 0;
1334 }
1335
1336 // ----------------------------------------------------------------------------
1337 // painting
1338 // ----------------------------------------------------------------------------
1339
1340 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
1341 {
1342 m_needsRefresh = TRUE;
1343 Display *display = XtDisplay((Widget) GetMainWidget());
1344 Window thisWindow = XtWindow((Widget) GetMainWidget());
1345
1346 XExposeEvent dummyEvent;
1347 int width, height;
1348 GetSize(&width, &height);
1349
1350 dummyEvent.type = Expose;
1351 dummyEvent.display = display;
1352 dummyEvent.send_event = True;
1353 dummyEvent.window = thisWindow;
1354 if (rect)
1355 {
1356 dummyEvent.x = rect->x;
1357 dummyEvent.y = rect->y;
1358 dummyEvent.width = rect->width;
1359 dummyEvent.height = rect->height;
1360 }
1361 else
1362 {
1363 dummyEvent.x = 0;
1364 dummyEvent.y = 0;
1365 dummyEvent.width = width;
1366 dummyEvent.height = height;
1367 }
1368 dummyEvent.count = 0;
1369
1370 if (eraseBack)
1371 {
1372 wxClientDC dc(this);
1373 wxBrush backgroundBrush(GetBackgroundColour(), wxSOLID);
1374 dc.SetBackground(backgroundBrush);
1375 if (rect)
1376 dc.Clear(*rect);
1377 else
1378 dc.Clear();
1379 }
1380
1381 XSendEvent(display, thisWindow, False, ExposureMask, (XEvent *)&dummyEvent);
1382 }
1383
1384 void wxWindow::Clear()
1385 {
1386 wxClientDC dc(this);
1387 wxBrush brush(GetBackgroundColour(), wxSOLID);
1388 dc.SetBackground(brush);
1389 dc.Clear();
1390 }
1391
1392 void wxWindow::ClearUpdateRects()
1393 {
1394 wxRectList::Node* node = m_updateRects.GetFirst();
1395 while (node)
1396 {
1397 wxRect* rect = node->GetData();
1398 delete rect;
1399 node = node->GetNext();
1400 }
1401
1402 m_updateRects.Clear();
1403 }
1404
1405 void wxWindow::DoPaint()
1406 {
1407 //TODO : make a temporary gc so we can do the XCopyArea below
1408 if (m_backingPixmap && !m_needsRefresh)
1409 {
1410 wxPaintDC dc(this);
1411
1412 GC tempGC = (GC) dc.GetBackingGC();
1413
1414 Widget widget = (Widget) GetMainWidget();
1415
1416 int scrollPosX = 0;
1417 int scrollPosY = 0;
1418
1419 // We have to test whether it's a wxScrolledWindow (hack!) because
1420 // otherwise we don't know how many pixels have been scrolled. We might
1421 // solve this in the future by defining virtual wxWindow functions to get
1422 // the scroll position in pixels. Or, each kind of scrolled window has to
1423 // implement backing stores itself, using generic wxWindows code.
1424 wxScrolledWindow* scrolledWindow = wxDynamicCast(this, wxScrolledWindow);
1425 if ( scrolledWindow )
1426 {
1427 int x, y;
1428 scrolledWindow->CalcScrolledPosition(0, 0, &x, &y);
1429
1430 scrollPosX = - x;
1431 scrollPosY = - y;
1432 }
1433
1434 // TODO: This could be optimized further by only copying the areas in the
1435 // current update region.
1436
1437 // Only blit the part visible in the client area. The backing pixmap
1438 // always starts at 0, 0 but we may be looking at only a portion of it.
1439 wxSize clientArea = GetClientSize();
1440 int toBlitX = m_pixmapWidth - scrollPosX;
1441 int toBlitY = m_pixmapHeight - scrollPosY;
1442
1443 // Copy whichever is samller, the amount of pixmap we have to copy,
1444 // or the size of the client area.
1445 toBlitX = wxMin(toBlitX, clientArea.x);
1446 toBlitY = wxMin(toBlitY, clientArea.y);
1447
1448 // Make sure we're not negative
1449 toBlitX = wxMax(0, toBlitX);
1450 toBlitY = wxMax(0, toBlitY);
1451
1452 XCopyArea
1453 (
1454 XtDisplay(widget),
1455 (Pixmap) m_backingPixmap,
1456 XtWindow (widget),
1457 tempGC,
1458 scrollPosX, scrollPosY, // Start at the scroll position
1459 toBlitX, toBlitY, // How much of the pixmap to copy
1460 0, 0 // Destination
1461 );
1462 }
1463 else
1464 {
1465 // Set an erase event first
1466 wxEraseEvent eraseEvent(GetId());
1467 eraseEvent.SetEventObject(this);
1468 GetEventHandler()->ProcessEvent(eraseEvent);
1469
1470 wxPaintEvent event(GetId());
1471 event.SetEventObject(this);
1472 GetEventHandler()->ProcessEvent(event);
1473
1474 m_needsRefresh = FALSE;
1475 }
1476 }
1477
1478 // ----------------------------------------------------------------------------
1479 // event handlers
1480 // ----------------------------------------------------------------------------
1481
1482 // Responds to colour changes: passes event on to children.
1483 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
1484 {
1485 wxWindowList::Node *node = GetChildren().GetFirst();
1486 while ( node )
1487 {
1488 // Only propagate to non-top-level windows
1489 wxWindow *win = node->GetData();
1490 if ( win->GetParent() )
1491 {
1492 wxSysColourChangedEvent event2;
1493 event.m_eventObject = win;
1494 win->GetEventHandler()->ProcessEvent(event2);
1495 }
1496
1497 node = node->GetNext();
1498 }
1499 }
1500
1501 void wxWindow::OnIdle(wxIdleEvent& event)
1502 {
1503 // This calls the UI-update mechanism (querying windows for
1504 // menu/toolbar/control state information)
1505 UpdateWindowUI();
1506 }
1507
1508 // ----------------------------------------------------------------------------
1509 // accelerators
1510 // ----------------------------------------------------------------------------
1511
1512 bool wxWindow::ProcessAccelerator(wxKeyEvent& event)
1513 {
1514 if (!m_acceleratorTable.Ok())
1515 return FALSE;
1516
1517 int count = m_acceleratorTable.GetCount();
1518 wxAcceleratorEntry* entries = m_acceleratorTable.GetEntries();
1519 int i;
1520 for (i = 0; i < count; i++)
1521 {
1522 wxAcceleratorEntry* entry = & (entries[i]);
1523 if (entry->MatchesEvent(event))
1524 {
1525 // Bingo, we have a match. Now find a control that matches the entry
1526 // command id.
1527
1528 // Need to go up to the top of the window hierarchy, since it might
1529 // be e.g. a menu item
1530 wxWindow* parent = this;
1531 while ( parent && !parent->IsTopLevel() )
1532 parent = parent->GetParent();
1533
1534 if (!parent)
1535 return FALSE;
1536
1537 wxFrame* frame = wxDynamicCast(parent, wxFrame);
1538 if ( frame )
1539 {
1540 // Try for a menu command
1541 if (frame->GetMenuBar())
1542 {
1543 wxMenuItem* item = frame->GetMenuBar()->FindItemForId(entry->GetCommand());
1544 if (item)
1545 {
1546 wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, entry->GetCommand());
1547 commandEvent.SetEventObject(frame);
1548
1549 // If ProcessEvent returns TRUE (it was handled), then
1550 // the calling code will skip the event handling.
1551 return frame->GetEventHandler()->ProcessEvent(commandEvent);
1552 }
1553 }
1554 }
1555
1556 // Find a child matching the command id
1557 wxWindow* child = parent->FindWindow(entry->GetCommand());
1558
1559 // No such child
1560 if (!child)
1561 return FALSE;
1562
1563 // Now we process those kinds of windows that we can.
1564 // For now, only buttons.
1565 if ( wxDynamicCast(child, wxButton) )
1566 {
1567 wxCommandEvent commandEvent (wxEVT_COMMAND_BUTTON_CLICKED, child->GetId());
1568 commandEvent.SetEventObject(child);
1569 return child->GetEventHandler()->ProcessEvent(commandEvent);
1570 }
1571
1572 return FALSE;
1573 } // matches event
1574 }// for
1575
1576 // We didn't match the key event against an accelerator.
1577 return FALSE;
1578 }
1579
1580 // ============================================================================
1581 // Motif-specific stuff from here on
1582 // ============================================================================
1583
1584 // ----------------------------------------------------------------------------
1585 // function which maintain the global hash table mapping Widgets to wxWindows
1586 // ----------------------------------------------------------------------------
1587
1588 bool wxAddWindowToTable(Widget w, wxWindow *win)
1589 {
1590 wxWindow *oldItem = NULL;
1591 if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w)))
1592 {
1593 wxLogDebug("Widget table clash: new widget is %ld, %s",
1594 (long)w, win->GetClassInfo()->GetClassName());
1595 return FALSE;
1596 }
1597
1598 wxWidgetHashTable->Put((long) w, win);
1599
1600 return TRUE;
1601 }
1602
1603 wxWindow *wxGetWindowFromTable(Widget w)
1604 {
1605 return (wxWindow *)wxWidgetHashTable->Get((long) w);
1606 }
1607
1608 void wxDeleteWindowFromTable(Widget w)
1609 {
1610 wxWidgetHashTable->Delete((long)w);
1611 }
1612
1613 // ----------------------------------------------------------------------------
1614 // add/remove window from the table
1615 // ----------------------------------------------------------------------------
1616
1617 // Add to hash table, add event handler
1618 bool wxWindow::AttachWidget (wxWindow* parent, WXWidget mainWidget,
1619 WXWidget formWidget, int x, int y, int width, int height)
1620 {
1621 wxAddWindowToTable((Widget) mainWidget, this);
1622 if (CanAddEventHandler())
1623 {
1624 XtAddEventHandler((Widget) mainWidget,
1625 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask,
1626 False,
1627 wxPanelItemEventHandler,
1628 (XtPointer) this);
1629 }
1630
1631 if (!formWidget)
1632 {
1633 XtTranslations ptr;
1634 XtOverrideTranslations ((Widget) mainWidget,
1635 ptr = XtParseTranslationTable ("<Configure>: resize()"));
1636 XtFree ((char *) ptr);
1637 }
1638
1639 // Some widgets have a parent form widget, e.g. wxRadioBox
1640 if (formWidget)
1641 {
1642 if (!wxAddWindowToTable((Widget) formWidget, this))
1643 return FALSE;
1644
1645 XtTranslations ptr;
1646 XtOverrideTranslations ((Widget) formWidget,
1647 ptr = XtParseTranslationTable ("<Configure>: resize()"));
1648 XtFree ((char *) ptr);
1649 }
1650
1651 if (x == -1)
1652 x = 0;
1653 if (y == -1)
1654 y = 0;
1655 SetSize (x, y, width, height);
1656
1657 return TRUE;
1658 }
1659
1660 // Remove event handler, remove from hash table
1661 bool wxWindow::DetachWidget(WXWidget widget)
1662 {
1663 if (CanAddEventHandler())
1664 {
1665 XtRemoveEventHandler((Widget) widget,
1666 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask,
1667 False,
1668 wxPanelItemEventHandler,
1669 (XtPointer)this);
1670 }
1671
1672 wxDeleteWindowFromTable((Widget) widget);
1673 return TRUE;
1674 }
1675
1676 // ----------------------------------------------------------------------------
1677 // Motif-specific accessors
1678 // ----------------------------------------------------------------------------
1679
1680 // Get the underlying X window
1681 WXWindow wxWindow::GetXWindow() const
1682 {
1683 Widget wMain = (Widget)GetMainWidget();
1684 if ( wMain )
1685 return (WXWindow) XtWindow(wMain);
1686 else
1687 return (WXWindow) 0;
1688 }
1689
1690 // Get the underlying X display
1691 WXDisplay *wxWindow::GetXDisplay() const
1692 {
1693 Widget wMain = (Widget)GetMainWidget();
1694 if ( wMain )
1695 return (WXDisplay*) XtDisplay(wMain);
1696 else
1697 return (WXDisplay*) NULL;
1698 }
1699
1700 WXWidget wxWindow::GetMainWidget() const
1701 {
1702 if (m_drawingArea)
1703 return m_drawingArea;
1704 else
1705 return m_mainWidget;
1706 }
1707
1708 WXWidget wxWindow::GetClientWidget() const
1709 {
1710 if (m_drawingArea != (WXWidget) 0)
1711 return m_drawingArea;
1712 else
1713 return GetMainWidget();
1714 }
1715
1716 WXWidget wxWindow::GetTopWidget() const
1717 {
1718 return GetMainWidget();
1719 }
1720
1721 WXWidget wxWindow::GetLabelWidget() const
1722 {
1723 return GetMainWidget();
1724 }
1725
1726 // ----------------------------------------------------------------------------
1727 // Motif callbacks
1728 // ----------------------------------------------------------------------------
1729
1730 // All widgets should have this as their resize proc.
1731 // OnSize sent to wxWindow via client data.
1732 void wxWidgetResizeProc(Widget w, XConfigureEvent *event, String args[], int *num_args)
1733 {
1734 wxWindow *win = wxGetWindowFromTable(w);
1735 if (!win)
1736 return;
1737
1738 if (win->PreResize())
1739 {
1740 int width, height;
1741 win->GetSize(&width, &height);
1742 wxSizeEvent sizeEvent(wxSize(width, height), win->GetId());
1743 sizeEvent.SetEventObject(win);
1744 win->GetEventHandler()->ProcessEvent(sizeEvent);
1745 }
1746 }
1747
1748 static void wxCanvasRepaintProc(Widget drawingArea,
1749 XtPointer clientData,
1750 XmDrawingAreaCallbackStruct * cbs)
1751 {
1752 if (!wxGetWindowFromTable(drawingArea))
1753 return;
1754
1755 XEvent * event = cbs->event;
1756 wxWindow * win = (wxWindow *) clientData;
1757
1758 switch (event->type)
1759 {
1760 case Expose:
1761 {
1762 if (event -> xexpose.count == 0)
1763 {
1764 #if 0
1765 wxPaintEvent event(win->GetId());
1766 event.SetEventObject(win);
1767 win->GetEventHandler()->ProcessEvent(event);
1768 #endif // 0
1769
1770 win->DoPaint();
1771 win->ClearUpdateRects();
1772 }
1773 else
1774 {
1775 win->AddUpdateRect(event->xexpose.x, event->xexpose.y,
1776 event->xexpose.width, event->xexpose.height);
1777 }
1778 break;
1779 }
1780 }
1781 }
1782
1783 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1784 static void wxCanvasEnterLeave(Widget drawingArea,
1785 XtPointer clientData,
1786 XCrossingEvent * event)
1787 {
1788 XmDrawingAreaCallbackStruct cbs;
1789 XEvent ev;
1790
1791 ((XCrossingEvent &) ev) = *event;
1792
1793 cbs.reason = XmCR_INPUT;
1794 cbs.event = &ev;
1795
1796 wxCanvasInputEvent(drawingArea, (XtPointer) NULL, &cbs);
1797 }
1798
1799 // Fix to make it work under Motif 1.0 (!)
1800 static void wxCanvasMotionEvent (Widget drawingArea, XButtonEvent * event)
1801 {
1802 #if XmVersion <= 1000
1803 XmDrawingAreaCallbackStruct cbs;
1804 XEvent ev;
1805
1806 ev = *((XEvent *) event);
1807 cbs.reason = XmCR_INPUT;
1808 cbs.event = &ev;
1809
1810 wxCanvasInputEvent (drawingArea, (XtPointer) NULL, &cbs);
1811 #endif // XmVersion <= 1000
1812 }
1813
1814 static void wxCanvasInputEvent(Widget drawingArea,
1815 XtPointer data,
1816 XmDrawingAreaCallbackStruct * cbs)
1817 {
1818 wxWindow *canvas = wxGetWindowFromTable(drawingArea);
1819 XEvent local_event;
1820
1821 if (canvas==NULL)
1822 return;
1823
1824 if (cbs->reason != XmCR_INPUT)
1825 return;
1826
1827 local_event = *(cbs->event); // We must keep a copy!
1828
1829 switch (local_event.xany.type)
1830 {
1831 case EnterNotify:
1832 case LeaveNotify:
1833 case ButtonPress:
1834 case ButtonRelease:
1835 case MotionNotify:
1836 {
1837 wxEventType eventType = wxEVT_NULL;
1838
1839 if (local_event.xany.type == EnterNotify)
1840 {
1841 //if (local_event.xcrossing.mode!=NotifyNormal)
1842 // return ; // Ignore grab events
1843 eventType = wxEVT_ENTER_WINDOW;
1844 // canvas->GetEventHandler()->OnSetFocus();
1845 }
1846 else if (local_event.xany.type == LeaveNotify)
1847 {
1848 //if (local_event.xcrossing.mode!=NotifyNormal)
1849 // return ; // Ignore grab events
1850 eventType = wxEVT_LEAVE_WINDOW;
1851 // canvas->GetEventHandler()->OnKillFocus();
1852 }
1853 else if (local_event.xany.type == MotionNotify)
1854 {
1855 eventType = wxEVT_MOTION;
1856 if (local_event.xmotion.is_hint == NotifyHint)
1857 {
1858 Window root, child;
1859 Display *dpy = XtDisplay (drawingArea);
1860
1861 XQueryPointer (dpy, XtWindow (drawingArea),
1862 &root, &child,
1863 &local_event.xmotion.x_root,
1864 &local_event.xmotion.y_root,
1865 &local_event.xmotion.x,
1866 &local_event.xmotion.y,
1867 &local_event.xmotion.state);
1868 }
1869 else
1870 {
1871 }
1872 }
1873
1874 else if (local_event.xany.type == ButtonPress)
1875 {
1876 if (local_event.xbutton.button == Button1)
1877 {
1878 eventType = wxEVT_LEFT_DOWN;
1879 canvas->SetButton1(TRUE);
1880 }
1881 else if (local_event.xbutton.button == Button2)
1882 {
1883 eventType = wxEVT_MIDDLE_DOWN;
1884 canvas->SetButton2(TRUE);
1885 }
1886 else if (local_event.xbutton.button == Button3)
1887 {
1888 eventType = wxEVT_RIGHT_DOWN;
1889 canvas->SetButton3(TRUE);
1890 }
1891 }
1892 else if (local_event.xany.type == ButtonRelease)
1893 {
1894 if (local_event.xbutton.button == Button1)
1895 {
1896 eventType = wxEVT_LEFT_UP;
1897 canvas->SetButton1(FALSE);
1898 }
1899 else if (local_event.xbutton.button == Button2)
1900 {
1901 eventType = wxEVT_MIDDLE_UP;
1902 canvas->SetButton2(FALSE);
1903 }
1904 else if (local_event.xbutton.button == Button3)
1905 {
1906 eventType = wxEVT_RIGHT_UP;
1907 canvas->SetButton3(FALSE);
1908 }
1909 }
1910
1911 wxMouseEvent wxevent (eventType);
1912
1913 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
1914 || (event_left_is_down (&local_event)
1915 && (eventType != wxEVT_LEFT_UP)));
1916 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
1917 || (event_middle_is_down (&local_event)
1918 && (eventType != wxEVT_MIDDLE_UP)));
1919 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
1920 || (event_right_is_down (&local_event)
1921 && (eventType != wxEVT_RIGHT_UP)));
1922
1923 wxevent.m_shiftDown = local_event.xbutton.state & ShiftMask;
1924 wxevent.m_controlDown = local_event.xbutton.state & ControlMask;
1925 wxevent.m_altDown = local_event.xbutton.state & Mod3Mask;
1926 wxevent.m_metaDown = local_event.xbutton.state & Mod1Mask;
1927 wxevent.SetTimestamp(local_event.xbutton.time);
1928
1929 // Now check if we need to translate this event into a double click
1930 if (TRUE) // canvas->doubleClickAllowed)
1931 {
1932 if (wxevent.ButtonDown())
1933 {
1934 long dclickTime = XtGetMultiClickTime((Display*) wxGetDisplay());
1935
1936 // get button and time-stamp
1937 int button = 0;
1938 if (wxevent.LeftDown())
1939 button = 1;
1940 else if (wxevent.MiddleDown())
1941 button = 2;
1942 else if (wxevent.RightDown())
1943 button = 3;
1944 long ts = wxevent.GetTimestamp();
1945
1946 // check, if single or double click
1947 int buttonLast = canvas->GetLastClickedButton();
1948 long lastTS = canvas->GetLastClickTime();
1949 if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime )
1950 {
1951 // I have a dclick
1952 canvas->SetLastClick(0, ts);
1953 switch ( eventType )
1954 {
1955 case wxEVT_LEFT_DOWN:
1956 wxevent.SetEventType(wxEVT_LEFT_DCLICK);
1957 break;
1958 case wxEVT_MIDDLE_DOWN:
1959 wxevent.SetEventType(wxEVT_MIDDLE_DCLICK);
1960 break;
1961 case wxEVT_RIGHT_DOWN:
1962 wxevent.SetEventType(wxEVT_RIGHT_DCLICK);
1963 break;
1964
1965 default :
1966 break;
1967 }
1968
1969 }
1970 else
1971 {
1972 // not fast enough or different button
1973 canvas->SetLastClick(button, ts);
1974 }
1975 }
1976 }
1977
1978 wxevent.SetId(canvas->GetId());
1979 wxevent.SetEventObject(canvas);
1980 wxevent.m_x = local_event.xbutton.x;
1981 wxevent.m_y = local_event.xbutton.y;
1982 canvas->GetEventHandler()->ProcessEvent (wxevent);
1983 #if 0
1984 if (eventType == wxEVT_ENTER_WINDOW ||
1985 eventType == wxEVT_LEAVE_WINDOW ||
1986 eventType == wxEVT_MOTION
1987 )
1988 return;
1989 #endif // 0
1990 break;
1991 }
1992 case KeyPress:
1993 {
1994 KeySym keySym;
1995 #if 0
1996 XComposeStatus compose;
1997 (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
1998 #endif // 0
1999
2000 (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL);
2001 int id = wxCharCodeXToWX (keySym);
2002
2003 wxEventType eventType = wxEVT_CHAR;
2004
2005 wxKeyEvent event (eventType);
2006
2007 if (local_event.xkey.state & ShiftMask)
2008 event.m_shiftDown = TRUE;
2009 if (local_event.xkey.state & ControlMask)
2010 event.m_controlDown = TRUE;
2011 if (local_event.xkey.state & Mod3Mask)
2012 event.m_altDown = TRUE;
2013 if (local_event.xkey.state & Mod1Mask)
2014 event.m_metaDown = TRUE;
2015 event.SetEventObject(canvas);
2016 event.m_keyCode = id;
2017 event.SetTimestamp(local_event.xkey.time);
2018
2019 if (id > -1)
2020 {
2021 // Implement wxFrame::OnCharHook by checking ancestor.
2022 wxWindow *parent = canvas->GetParent();
2023 while (parent && !parent->IsKindOf(CLASSINFO(wxFrame)))
2024 parent = parent->GetParent();
2025
2026 if (parent)
2027 {
2028 event.SetEventType(wxEVT_CHAR_HOOK);
2029 if (parent->GetEventHandler()->ProcessEvent(event))
2030 return;
2031 }
2032
2033 // For simplicity, OnKeyDown is the same as OnChar
2034 // TODO: filter modifier key presses from OnChar
2035 event.SetEventType(wxEVT_KEY_DOWN);
2036
2037 // Only process OnChar if OnKeyDown didn't swallow it
2038 if (!canvas->GetEventHandler()->ProcessEvent (event))
2039 {
2040 event.SetEventType(wxEVT_CHAR);
2041 canvas->GetEventHandler()->ProcessEvent (event);
2042 }
2043 }
2044 break;
2045 }
2046 case KeyRelease:
2047 {
2048 KeySym keySym;
2049 (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL);
2050 int id = wxCharCodeXToWX (keySym);
2051
2052 wxKeyEvent event (wxEVT_KEY_UP);
2053
2054 if (local_event.xkey.state & ShiftMask)
2055 event.m_shiftDown = TRUE;
2056 if (local_event.xkey.state & ControlMask)
2057 event.m_controlDown = TRUE;
2058 if (local_event.xkey.state & Mod3Mask)
2059 event.m_altDown = TRUE;
2060 if (local_event.xkey.state & Mod1Mask)
2061 event.m_metaDown = TRUE;
2062 event.SetEventObject(canvas);
2063 event.m_keyCode = id;
2064 event.SetTimestamp(local_event.xkey.time);
2065
2066 if (id > -1)
2067 {
2068 canvas->GetEventHandler()->ProcessEvent (event);
2069 }
2070 break;
2071 }
2072 case FocusIn:
2073 {
2074 if (local_event.xfocus.detail != NotifyPointer)
2075 {
2076 wxFocusEvent event(wxEVT_SET_FOCUS, canvas->GetId());
2077 event.SetEventObject(canvas);
2078 canvas->GetEventHandler()->ProcessEvent(event);
2079 }
2080 break;
2081 }
2082 case FocusOut:
2083 {
2084 if (local_event.xfocus.detail != NotifyPointer)
2085 {
2086 wxFocusEvent event(wxEVT_KILL_FOCUS, canvas->GetId());
2087 event.SetEventObject(canvas);
2088 canvas->GetEventHandler()->ProcessEvent(event);
2089 }
2090 break;
2091 }
2092 default:
2093 break;
2094 }
2095 }
2096
2097 static void wxPanelItemEventHandler(Widget wid,
2098 XtPointer client_data,
2099 XEvent* event,
2100 Boolean *continueToDispatch)
2101 {
2102 // Widget can be a label or the actual widget.
2103
2104 wxWindow *window = wxGetWindowFromTable(wid);
2105 if (window)
2106 {
2107 wxMouseEvent wxevent(0);
2108 if (wxTranslateMouseEvent(wxevent, window, wid, event))
2109 {
2110 window->GetEventHandler()->ProcessEvent(wxevent);
2111 }
2112 }
2113
2114 // TODO: probably the key to allowing default behaviour to happen. Say we
2115 // set a m_doDefault flag to FALSE at the start of this function. Then in
2116 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2117 // TRUE, indicating that default processing can happen. Thus, behaviour can
2118 // appear to be overridden just by adding an event handler and not calling
2119 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2120 // way of handling drawing area events, to simplify things.
2121 *continueToDispatch = True;
2122 }
2123
2124 static void wxScrollBarCallback(Widget scrollbar,
2125 XtPointer clientData,
2126 XmScaleCallbackStruct *cbs)
2127 {
2128 wxWindow *win = wxGetWindowFromTable(scrollbar);
2129 int orientation = (int) clientData;
2130
2131 wxEventType eventType = wxEVT_NULL;
2132 switch (cbs->reason)
2133 {
2134 case XmCR_INCREMENT:
2135 {
2136 eventType = wxEVT_SCROLL_LINEDOWN;
2137 break;
2138 }
2139 case XmCR_DECREMENT:
2140 {
2141 eventType = wxEVT_SCROLL_LINEUP;
2142 break;
2143 }
2144 case XmCR_DRAG:
2145 {
2146 eventType = wxEVT_SCROLL_THUMBTRACK;
2147 break;
2148 }
2149 case XmCR_VALUE_CHANGED:
2150 {
2151 // TODO: Should this be intercepted too, or will it cause
2152 // duplicate events?
2153 eventType = wxEVT_SCROLL_THUMBTRACK;
2154 break;
2155 }
2156 case XmCR_PAGE_INCREMENT:
2157 {
2158 eventType = wxEVT_SCROLL_PAGEDOWN;
2159 break;
2160 }
2161 case XmCR_PAGE_DECREMENT:
2162 {
2163 eventType = wxEVT_SCROLL_PAGEUP;
2164 break;
2165 }
2166 case XmCR_TO_TOP:
2167 {
2168 eventType = wxEVT_SCROLL_TOP;
2169 break;
2170 }
2171 case XmCR_TO_BOTTOM:
2172 {
2173 eventType = wxEVT_SCROLL_BOTTOM;
2174 break;
2175 }
2176 default:
2177 {
2178 // Should never get here
2179 wxFAIL_MSG("Unknown scroll event.");
2180 break;
2181 }
2182 }
2183
2184 wxScrollEvent event(eventType, win->GetId());
2185 event.SetEventObject(win);
2186 event.SetPosition(cbs->value);
2187 event.SetOrientation( (orientation == XmHORIZONTAL) ? wxHORIZONTAL : wxVERTICAL );
2188
2189 win->GetEventHandler()->ProcessEvent(event);
2190 }
2191
2192 // For repainting arbitrary windows
2193 void wxUniversalRepaintProc(Widget w, XtPointer WXUNUSED(c_data), XEvent *event, char *)
2194 {
2195 Window window;
2196 Display *display;
2197
2198 wxWindow* win = wxGetWindowFromTable(w);
2199 if (!win)
2200 return;
2201
2202 switch(event -> type)
2203 {
2204 case Expose:
2205 {
2206 window = (Window) win -> GetXWindow();
2207 display = (Display *) win -> GetXDisplay();
2208
2209 if (event -> xexpose.count == 0)
2210 {
2211 win->DoPaint();
2212
2213 win->ClearUpdateRects();
2214 }
2215 else
2216 {
2217 win->AddUpdateRect(event->xexpose.x, event->xexpose.y,
2218 event->xexpose.width, event->xexpose.height);
2219 }
2220
2221 break;
2222 }
2223 }
2224 }
2225
2226 // ----------------------------------------------------------------------------
2227 // CanvaseXXXSize() functions
2228 // ----------------------------------------------------------------------------
2229
2230 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2231 void wxWindow::CanvasSetSize (int x, int y, int w, int h, int sizeFlags)
2232 {
2233 // A bit of optimization to help sort out the flickers.
2234 int oldX, oldY, oldW, oldH;
2235 GetSize(& oldW, & oldH);
2236 GetPosition(& oldX, & oldY);
2237
2238 bool useOldPos = FALSE;
2239 bool useOldSize = FALSE;
2240
2241 if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0))
2242 useOldPos = TRUE;
2243 else if (x == oldX && y == oldY)
2244 useOldPos = TRUE;
2245
2246 if ((w == -1) && (h == -1))
2247 useOldSize = TRUE;
2248 else if (w == oldW && h == oldH)
2249 useOldSize = TRUE;
2250
2251 if (!wxNoOptimize::CanOptimize())
2252 {
2253 useOldSize = FALSE; useOldPos = FALSE;
2254 }
2255
2256 if (useOldPos && useOldSize)
2257 return;
2258
2259 Widget drawingArea = (Widget) m_drawingArea;
2260 bool managed = XtIsManaged(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
2261
2262 if (managed)
2263 XtUnmanageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
2264 XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
2265
2266 int xx = x; int yy = y;
2267 AdjustForParentClientOrigin(xx, yy, sizeFlags);
2268
2269 if (!useOldPos)
2270 {
2271 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
2272 {
2273 XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow,
2274 XmNx, xx, NULL);
2275 }
2276
2277 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
2278 {
2279 XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow,
2280 XmNy, yy, NULL);
2281 }
2282 }
2283
2284 if (!useOldSize)
2285 {
2286
2287 if (w > -1)
2288 {
2289 if (m_borderWidget)
2290 {
2291 XtVaSetValues ((Widget) m_borderWidget, XmNwidth, w, NULL);
2292 short thick, margin;
2293 XtVaGetValues ((Widget) m_borderWidget,
2294 XmNshadowThickness, &thick,
2295 XmNmarginWidth, &margin,
2296 NULL);
2297 w -= 2 * (thick + margin);
2298 }
2299
2300 XtVaSetValues ((Widget) m_scrolledWindow, XmNwidth, w, NULL);
2301
2302 Dimension spacing;
2303 Widget sbar;
2304 XtVaGetValues ((Widget) m_scrolledWindow,
2305 XmNspacing, &spacing,
2306 XmNverticalScrollBar, &sbar,
2307 NULL);
2308 Dimension wsbar;
2309 if (sbar)
2310 XtVaGetValues (sbar, XmNwidth, &wsbar, NULL);
2311 else
2312 wsbar = 0;
2313
2314 w -= (spacing + wsbar);
2315
2316 #if 0
2317 XtVaSetValues(drawingArea, XmNwidth, w, NULL);
2318 #endif // 0
2319 }
2320 if (h > -1)
2321 {
2322 if (m_borderWidget)
2323 {
2324 XtVaSetValues ((Widget) m_borderWidget, XmNheight, h, NULL);
2325 short thick, margin;
2326 XtVaGetValues ((Widget) m_borderWidget,
2327 XmNshadowThickness, &thick,
2328 XmNmarginHeight, &margin,
2329 NULL);
2330 h -= 2 * (thick + margin);
2331 }
2332
2333 XtVaSetValues ((Widget) m_scrolledWindow, XmNheight, h, NULL);
2334
2335 Dimension spacing;
2336 Widget sbar;
2337 XtVaGetValues ((Widget) m_scrolledWindow,
2338 XmNspacing, &spacing,
2339 XmNhorizontalScrollBar, &sbar,
2340 NULL);
2341 Dimension wsbar;
2342 if (sbar)
2343 XtVaGetValues (sbar, XmNheight, &wsbar, NULL);
2344 else
2345 wsbar = 0;
2346
2347 h -= (spacing + wsbar);
2348
2349 #if 0
2350 XtVaSetValues(drawingArea, XmNheight, h, NULL);
2351 #endif // 0
2352 }
2353 }
2354
2355 if (managed)
2356 XtManageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
2357 XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
2358
2359 #if 0
2360 int ww, hh;
2361 GetClientSize (&ww, &hh);
2362 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2363 sizeEvent.SetEventObject(this);
2364
2365 GetEventHandler()->ProcessEvent(sizeEvent);
2366 #endif // 0
2367 }
2368
2369 void wxWindow::CanvasSetClientSize (int w, int h)
2370 {
2371 Widget drawingArea = (Widget) m_drawingArea;
2372
2373 XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
2374
2375 if (w > -1)
2376 XtVaSetValues(drawingArea, XmNwidth, w, NULL);
2377 if (h > -1)
2378 XtVaSetValues(drawingArea, XmNheight, h, NULL);
2379
2380 #if 0
2381 // TODO: is this necessary?
2382 allowRepainting = FALSE;
2383
2384 XSync (XtDisplay (drawingArea), FALSE);
2385 XEvent event;
2386 while (XtAppPending (wxTheApp->appContext))
2387 {
2388 XFlush (XtDisplay (drawingArea));
2389 XtAppNextEvent (wxTheApp->appContext, &event);
2390 XtDispatchEvent (&event);
2391 }
2392 #endif // 0
2393
2394 XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
2395
2396 #if 0
2397 allowRepainting = TRUE;
2398 DoRefresh ();
2399
2400 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2401 sizeEvent.SetEventObject(this);
2402
2403 GetEventHandler()->ProcessEvent(sizeEvent);
2404 #endif // 0
2405 }
2406
2407 void wxWindow::CanvasGetClientSize (int *w, int *h) const
2408 {
2409 // Must return the same thing that was set via SetClientSize
2410 Dimension xx, yy;
2411 XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL);
2412 *w = xx;
2413 *h = yy;
2414 }
2415
2416 void wxWindow::CanvasGetSize (int *w, int *h) const
2417 {
2418 Dimension xx, yy;
2419 if ((Widget) m_borderWidget)
2420 XtVaGetValues ((Widget) m_borderWidget, XmNwidth, &xx, XmNheight, &yy, NULL);
2421 else if ((Widget) m_scrolledWindow)
2422 XtVaGetValues ((Widget) m_scrolledWindow, XmNwidth, &xx, XmNheight, &yy, NULL);
2423 else
2424 XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL);
2425
2426 *w = xx;
2427 *h = yy;
2428 }
2429
2430 void wxWindow::CanvasGetPosition (int *x, int *y) const
2431 {
2432 Position xx, yy;
2433 XtVaGetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, XmNx, &xx, XmNy, &yy, NULL);
2434
2435 // We may be faking the client origin.
2436 // So a window that's really at (0, 30) may appear
2437 // (to wxWin apps) to be at (0, 0).
2438 if (GetParent())
2439 {
2440 wxPoint pt(GetParent()->GetClientAreaOrigin());
2441 xx -= pt.x;
2442 yy -= pt.y;
2443 }
2444
2445 *x = xx;
2446 *y = yy;
2447 }
2448
2449 // ----------------------------------------------------------------------------
2450 // TranslateXXXEvent() functions
2451 // ----------------------------------------------------------------------------
2452
2453 bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent)
2454 {
2455 switch (xevent->xany.type)
2456 {
2457 case EnterNotify:
2458 case LeaveNotify:
2459 case ButtonPress:
2460 case ButtonRelease:
2461 case MotionNotify:
2462 {
2463 wxEventType eventType = wxEVT_NULL;
2464
2465 if (xevent->xany.type == LeaveNotify)
2466 {
2467 win->SetButton1(FALSE);
2468 win->SetButton2(FALSE);
2469 win->SetButton3(FALSE);
2470 return FALSE;
2471 }
2472 else if (xevent->xany.type == MotionNotify)
2473 {
2474 eventType = wxEVT_MOTION;
2475 }
2476 else if (xevent->xany.type == ButtonPress)
2477 {
2478 if (xevent->xbutton.button == Button1)
2479 {
2480 eventType = wxEVT_LEFT_DOWN;
2481 win->SetButton1(TRUE);
2482 }
2483 else if (xevent->xbutton.button == Button2)
2484 {
2485 eventType = wxEVT_MIDDLE_DOWN;
2486 win->SetButton2(TRUE);
2487 }
2488 else if (xevent->xbutton.button == Button3)
2489 {
2490 eventType = wxEVT_RIGHT_DOWN;
2491 win->SetButton3(TRUE);
2492 }
2493 }
2494 else if (xevent->xany.type == ButtonRelease)
2495 {
2496 if (xevent->xbutton.button == Button1)
2497 {
2498 eventType = wxEVT_LEFT_UP;
2499 win->SetButton1(FALSE);
2500 }
2501 else if (xevent->xbutton.button == Button2)
2502 {
2503 eventType = wxEVT_MIDDLE_UP;
2504 win->SetButton2(FALSE);
2505 }
2506 else if (xevent->xbutton.button == Button3)
2507 {
2508 eventType = wxEVT_RIGHT_UP;
2509 win->SetButton3(FALSE);
2510 }
2511 else return FALSE;
2512 }
2513 else
2514 {
2515 return FALSE;
2516 }
2517
2518 wxevent.SetEventType(eventType);
2519
2520 Position x1, y1;
2521 XtVaGetValues(widget, XmNx, &x1, XmNy, &y1, NULL);
2522
2523 int x2, y2;
2524 win->GetPosition(&x2, &y2);
2525
2526 // The button x/y must be translated to wxWindows
2527 // window space - the widget might be a label or button,
2528 // within a form.
2529 int dx = 0;
2530 int dy = 0;
2531 if (widget != (Widget)win->GetMainWidget())
2532 {
2533 dx = x1;
2534 dy = y1;
2535 }
2536
2537 wxevent.m_x = xevent->xbutton.x + dx;
2538 wxevent.m_y = xevent->xbutton.y + dy;
2539
2540 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
2541 || (event_left_is_down (xevent)
2542 && (eventType != wxEVT_LEFT_UP)));
2543 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
2544 || (event_middle_is_down (xevent)
2545 && (eventType != wxEVT_MIDDLE_UP)));
2546 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
2547 || (event_right_is_down (xevent)
2548 && (eventType != wxEVT_RIGHT_UP)));
2549
2550 wxevent.m_shiftDown = xevent->xbutton.state & ShiftMask;
2551 wxevent.m_controlDown = xevent->xbutton.state & ControlMask;
2552 return TRUE;
2553 }
2554 }
2555 return FALSE;
2556 }
2557
2558 bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent)
2559 {
2560 switch (xevent->xany.type)
2561 {
2562 case KeyPress:
2563 {
2564 char buf[20];
2565
2566 KeySym keySym;
2567 #if 0
2568 XComposeStatus compose;
2569 (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
2570 #endif // 0
2571 (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL);
2572 int id = wxCharCodeXToWX (keySym);
2573
2574 if (xevent->xkey.state & ShiftMask)
2575 wxevent.m_shiftDown = TRUE;
2576 if (xevent->xkey.state & ControlMask)
2577 wxevent.m_controlDown = TRUE;
2578 if (xevent->xkey.state & Mod3Mask)
2579 wxevent.m_altDown = TRUE;
2580 if (xevent->xkey.state & Mod1Mask)
2581 wxevent.m_metaDown = TRUE;
2582 wxevent.SetEventObject(win);
2583 wxevent.m_keyCode = id;
2584 wxevent.SetTimestamp(xevent->xkey.time);
2585
2586 wxevent.m_x = xevent->xbutton.x;
2587 wxevent.m_y = xevent->xbutton.y;
2588
2589 if (id > -1)
2590 return TRUE;
2591 else
2592 return FALSE;
2593 break;
2594 }
2595 default:
2596 break;
2597 }
2598 return FALSE;
2599 }
2600
2601 // ----------------------------------------------------------------------------
2602 // Colour stuff
2603 // ----------------------------------------------------------------------------
2604
2605 #define YAllocColor XAllocColor
2606 XColor g_itemColors[5];
2607 int wxComputeColours (Display *display, wxColour * back, wxColour * fore)
2608 {
2609 int result;
2610 static XmColorProc colorProc;
2611
2612 result = wxNO_COLORS;
2613
2614 if (back)
2615 {
2616 g_itemColors[0].red = (((long) back->Red ()) << 8);
2617 g_itemColors[0].green = (((long) back->Green ()) << 8);
2618 g_itemColors[0].blue = (((long) back->Blue ()) << 8);
2619 g_itemColors[0].flags = DoRed | DoGreen | DoBlue;
2620 if (colorProc == (XmColorProc) NULL)
2621 {
2622 // Get a ptr to the actual function
2623 colorProc = XmSetColorCalculation ((XmColorProc) NULL);
2624 // And set it back to motif.
2625 XmSetColorCalculation (colorProc);
2626 }
2627 (*colorProc) (&g_itemColors[wxBACK_INDEX],
2628 &g_itemColors[wxFORE_INDEX],
2629 &g_itemColors[wxSELE_INDEX],
2630 &g_itemColors[wxTOPS_INDEX],
2631 &g_itemColors[wxBOTS_INDEX]);
2632 result = wxBACK_COLORS;
2633 }
2634 if (fore)
2635 {
2636 g_itemColors[wxFORE_INDEX].red = (((long) fore->Red ()) << 8);
2637 g_itemColors[wxFORE_INDEX].green = (((long) fore->Green ()) << 8);
2638 g_itemColors[wxFORE_INDEX].blue = (((long) fore->Blue ()) << 8);
2639 g_itemColors[wxFORE_INDEX].flags = DoRed | DoGreen | DoBlue;
2640 if (result == wxNO_COLORS)
2641 result = wxFORE_COLORS;
2642 }
2643
2644 Display *dpy = display;
2645 Colormap cmap = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) dpy);
2646
2647 if (back)
2648 {
2649 /* 5 Colours to allocate */
2650 for (int i = 0; i < 5; i++)
2651 if (!YAllocColor (dpy, cmap, &g_itemColors[i]))
2652 result = wxNO_COLORS;
2653 }
2654 else if (fore)
2655 {
2656 /* Only 1 colour to allocate */
2657 if (!YAllocColor (dpy, cmap, &g_itemColors[wxFORE_INDEX]))
2658 result = wxNO_COLORS;
2659 }
2660
2661 return (result);
2662
2663 }
2664
2665 // Changes the foreground and background colours to be derived from the current
2666 // background colour. To change the foreground colour, you must call
2667 // SetForegroundColour explicitly.
2668 void wxWindow::ChangeBackgroundColour()
2669 {
2670 WXWidget mainWidget = GetMainWidget();
2671 if ( mainWidget )
2672 DoChangeBackgroundColour(mainWidget, m_backgroundColour);
2673
2674 // This not necessary
2675 #if 0
2676
2677 if (m_scrolledWindow && (GetMainWidget() != m_scrolledWindow))
2678 {
2679 DoChangeBackgroundColour(m_scrolledWindow, m_backgroundColour);
2680 // Have to set the scrollbar colours back since
2681 // the scrolled window seemed to change them
2682 wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
2683
2684 if (m_hScrollBar)
2685 DoChangeBackgroundColour(m_hScrollBar, backgroundColour);
2686 if (m_vScrollBar)
2687 DoChangeBackgroundColour(m_vScrollBar, backgroundColour);
2688 }
2689 #endif
2690 }
2691
2692 void wxWindow::ChangeForegroundColour()
2693 {
2694 WXWidget mainWidget = GetMainWidget();
2695 if ( mainWidget )
2696 DoChangeForegroundColour(mainWidget, m_foregroundColour);
2697 if ( m_scrolledWindow && mainWidget != m_scrolledWindow )
2698 DoChangeForegroundColour(m_scrolledWindow, m_foregroundColour);
2699 }
2700
2701 // Change a widget's foreground and background colours.
2702 void wxWindow::DoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour)
2703 {
2704 // When should we specify the foreground, if it's calculated
2705 // by wxComputeColours?
2706 // Solution: say we start with the default (computed) foreground colour.
2707 // If we call SetForegroundColour explicitly for a control or window,
2708 // then the foreground is changed.
2709 // Therefore SetBackgroundColour computes the foreground colour, and
2710 // SetForegroundColour changes the foreground colour. The ordering is
2711 // important.
2712
2713 Widget w = (Widget)widget;
2714 XtVaSetValues(
2715 w,
2716 XmNforeground, foregroundColour.AllocColour(XtDisplay(w)),
2717 NULL
2718 );
2719 }
2720
2721 void wxWindow::DoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour)
2722 {
2723 wxComputeColours (XtDisplay((Widget) widget), & backgroundColour,
2724 (wxColour*) NULL);
2725
2726 XtVaSetValues ((Widget) widget,
2727 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
2728 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
2729 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
2730 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
2731 NULL);
2732
2733 if (changeArmColour)
2734 XtVaSetValues ((Widget) widget,
2735 XmNarmColor, g_itemColors[wxSELE_INDEX].pixel,
2736 NULL);
2737 }
2738
2739 bool wxWindow::SetBackgroundColour(const wxColour& col)
2740 {
2741 if ( !wxWindowBase::SetBackgroundColour(col) )
2742 return FALSE;
2743
2744 ChangeBackgroundColour();
2745
2746 return TRUE;
2747 }
2748
2749 bool wxWindow::SetForegroundColour(const wxColour& col)
2750 {
2751 if ( !wxWindowBase::SetForegroundColour(col) )
2752 return FALSE;
2753
2754 ChangeForegroundColour();
2755
2756 return TRUE;
2757 }
2758
2759 void wxWindow::ChangeFont(bool keepOriginalSize)
2760 {
2761 // Note that this causes the widget to be resized back
2762 // to its original size! We therefore have to set the size
2763 // back again. TODO: a better way in Motif?
2764 Widget w = (Widget) GetLabelWidget(); // Usually the main widget
2765 if (w && m_font.Ok())
2766 {
2767 int width, height, width1, height1;
2768 GetSize(& width, & height);
2769
2770 // lesstif 0.87 hangs here
2771 #ifndef LESSTIF_VERSION
2772 XtVaSetValues (w,
2773 XmNfontList, (XmFontList) m_font.GetFontList(1.0, XtDisplay(w)),
2774 NULL);
2775 #endif
2776
2777 GetSize(& width1, & height1);
2778 if (keepOriginalSize && (width != width1 || height != height1))
2779 {
2780 SetSize(-1, -1, width, height);
2781 }
2782 }
2783 }
2784
2785 // ----------------------------------------------------------------------------
2786 // global functions
2787 // ----------------------------------------------------------------------------
2788
2789 wxWindow *wxGetActiveWindow()
2790 {
2791 // TODO
2792 return NULL;
2793 }
2794
2795 // ----------------------------------------------------------------------------
2796 // wxNoOptimize: switch off size optimization
2797 // ----------------------------------------------------------------------------
2798
2799 int wxNoOptimize::ms_count = 0;