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