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