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