]> git.saurik.com Git - wxWidgets.git/blame - src/motif/window.cpp
added wxControlWithItems constructor/destructor (for Darwin)
[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
820 int range;
821 XtVaGetValues(scrollBar, XmNmaximum, &range, NULL);
822 return range;
2d120f83 823}
4bb6408c 824
34636400 825int wxWindow::GetScrollThumb(int orient) const
4bb6408c 826{
af0bb3b1 827 Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient);
34636400
VZ
828 wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
829
830 int thumb;
831 XtVaGetValues(scrollBar, XmNsliderSize, &thumb, NULL);
832 return thumb;
4bb6408c
JS
833}
834
34636400 835void wxWindow::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
4bb6408c 836{
af0bb3b1 837 Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient);
34636400
VZ
838
839 if ( scrollBar )
4bb6408c 840 {
34636400 841 XtVaSetValues (scrollBar, XmNvalue, pos, NULL);
4bb6408c 842 }
34636400 843
af0bb3b1 844 SetInternalScrollPos((wxOrientation)orient, pos);
4bb6408c
JS
845}
846
34636400
VZ
847// New function that will replace some of the above.
848void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
849 int range, bool WXUNUSED(refresh))
4bb6408c 850{
34636400
VZ
851 int oldW, oldH;
852 GetSize(& oldW, & oldH);
853
854 if (range == 0)
855 range = 1;
856 if (thumbVisible == 0)
857 thumbVisible = 1;
858
859 if (thumbVisible > range)
860 thumbVisible = range;
861
862 // Save the old state to see if it changed
af0bb3b1 863 WXWidget oldScrollBar = GetScrollbar((wxOrientation)orient);
34636400
VZ
864
865 if (orient == wxHORIZONTAL)
50414e24 866 {
34636400 867 if (thumbVisible == range)
2d120f83 868 {
34636400
VZ
869 if (m_hScrollBar)
870 DestroyScrollbar(wxHORIZONTAL);
2d120f83
JS
871 }
872 else
873 {
34636400
VZ
874 if (!m_hScrollBar)
875 CreateScrollbar(wxHORIZONTAL);
2d120f83 876 }
50414e24 877 }
34636400 878 if (orient == wxVERTICAL)
50414e24 879 {
34636400 880 if (thumbVisible == range)
2d120f83 881 {
34636400
VZ
882 if (m_vScrollBar)
883 DestroyScrollbar(wxVERTICAL);
2d120f83
JS
884 }
885 else
886 {
34636400
VZ
887 if (!m_vScrollBar)
888 CreateScrollbar(wxVERTICAL);
2d120f83 889 }
50414e24 890 }
af0bb3b1 891 WXWidget newScrollBar = GetScrollbar((wxOrientation)orient);
4bb6408c 892
88150e60 893 if (oldScrollBar != newScrollBar)
28ab302b 894 {
34636400 895 // This is important! Without it, scrollbars misbehave badly.
2d120f83
JS
896 XtUnrealizeWidget((Widget) m_scrolledWindow);
897 XmScrolledWindowSetAreas ((Widget) m_scrolledWindow, (Widget) m_hScrollBar, (Widget) m_vScrollBar, (Widget) m_drawingArea);
898 XtRealizeWidget((Widget) m_scrolledWindow);
899 XtManageChild((Widget) m_scrolledWindow);
28ab302b 900 }
34636400 901
88150e60 902 if (newScrollBar)
34636400 903 {
2d120f83
JS
904 XtVaSetValues((Widget) newScrollBar,
905 XmNvalue, pos,
906 XmNminimum, 0,
907 XmNmaximum, range,
908 XmNsliderSize, thumbVisible,
909 NULL);
34636400
VZ
910 }
911
af0bb3b1 912 SetInternalScrollPos((wxOrientation)orient, pos);
34636400 913
88150e60
JS
914 int newW, newH;
915 GetSize(& newW, & newH);
34636400 916
88150e60
JS
917 // Adjusting scrollbars can resize the canvas accidentally
918 if (newW != oldW || newH != oldH)
919 SetSize(-1, -1, oldW, oldH);
4bb6408c
JS
920}
921
922// Does a physical scroll
16e93305 923void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
4bb6408c 924{
2d120f83
JS
925 int x, y, w, h;
926 if (rect)
927 {
928 // Use specified rectangle
929 x = rect->x; y = rect->y; w = rect->width; h = rect->height;
930 }
931 else
932 {
933 // Use whole client area
934 x = 0; y = 0;
935 GetClientSize(& w, & h);
936 }
34636400 937
76db86e7
RR
938 wxNode *cnode = m_children.First();
939 while (cnode)
940 {
941 wxWindow *child = (wxWindow*) cnode->Data();
942 int sx = 0;
943 int sy = 0;
944 child->GetSize( &sx, &sy );
945 wxPoint pos( child->GetPosition() );
946 child->SetSize( pos.x + dx, pos.y + dy, sx, sy, wxSIZE_ALLOW_MINUS_ONE );
947 cnode = cnode->Next();
948 }
949
34636400 950 int x1 = (dx >= 0) ? x : x - dx;
2d120f83
JS
951 int y1 = (dy >= 0) ? y : y - dy;
952 int w1 = w - abs(dx);
953 int h1 = h - abs(dy);
954 int x2 = (dx >= 0) ? x + dx : x;
955 int y2 = (dy >= 0) ? y + dy : y;
34636400 956
2d120f83 957 wxClientDC dc(this);
34636400 958
2d120f83 959 dc.SetLogicalFunction (wxCOPY);
34636400 960
2d120f83
JS
961 Widget widget = (Widget) GetMainWidget();
962 Window window = XtWindow(widget);
963 Display* display = XtDisplay(widget);
34636400
VZ
964
965 XCopyArea(display, window, window, (GC) dc.GetGC(),
966 x1, y1, w1, h1, x2, y2);
967
2d120f83
JS
968 dc.SetAutoSetting(TRUE);
969 wxBrush brush(GetBackgroundColour(), wxSOLID);
34636400
VZ
970 dc.SetBrush(brush); // FIXME: needed?
971
972 // We'll add rectangles to the list of update rectangles according to which
973 // bits we've exposed.
2d120f83 974 wxList updateRects;
34636400 975
2d120f83
JS
976 if (dx > 0)
977 {
978 wxRect *rect = new wxRect;
979 rect->x = x;
980 rect->y = y;
981 rect->width = dx;
982 rect->height = h;
34636400 983
2d120f83
JS
984 XFillRectangle(display, window,
985 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
34636400 986
2d120f83
JS
987 rect->x = rect->x;
988 rect->y = rect->y;
989 rect->width = rect->width;
990 rect->height = rect->height;
34636400 991
2d120f83
JS
992 updateRects.Append((wxObject*) rect);
993 }
994 else if (dx < 0)
995 {
996 wxRect *rect = new wxRect;
34636400 997
2d120f83
JS
998 rect->x = x + w + dx;
999 rect->y = y;
1000 rect->width = -dx;
1001 rect->height = h;
34636400 1002
2d120f83
JS
1003 XFillRectangle(display, window,
1004 (GC) dc.GetGC(), rect->x, rect->y, rect->width,
1005 rect->height);
34636400 1006
2d120f83
JS
1007 rect->x = rect->x;
1008 rect->y = rect->y;
1009 rect->width = rect->width;
1010 rect->height = rect->height;
34636400 1011
2d120f83
JS
1012 updateRects.Append((wxObject*) rect);
1013 }
1014 if (dy > 0)
1015 {
1016 wxRect *rect = new wxRect;
34636400 1017
2d120f83
JS
1018 rect->x = x;
1019 rect->y = y;
1020 rect->width = w;
1021 rect->height = dy;
34636400 1022
2d120f83
JS
1023 XFillRectangle(display, window,
1024 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
34636400 1025
2d120f83
JS
1026 rect->x = rect->x;
1027 rect->y = rect->y;
1028 rect->width = rect->width;
1029 rect->height = rect->height;
34636400 1030
2d120f83
JS
1031 updateRects.Append((wxObject*) rect);
1032 }
1033 else if (dy < 0)
1034 {
1035 wxRect *rect = new wxRect;
34636400 1036
2d120f83
JS
1037 rect->x = x;
1038 rect->y = y + h + dy;
1039 rect->width = w;
1040 rect->height = -dy;
34636400 1041
2d120f83
JS
1042 XFillRectangle(display, window,
1043 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
34636400 1044
2d120f83
JS
1045 rect->x = rect->x;
1046 rect->y = rect->y;
1047 rect->width = rect->width;
1048 rect->height = rect->height;
34636400 1049
2d120f83
JS
1050 updateRects.Append((wxObject*) rect);
1051 }
1052 dc.SetBrush(wxNullBrush);
34636400 1053
2d120f83 1054 // Now send expose events
34636400 1055
2d120f83
JS
1056 wxNode* node = updateRects.First();
1057 while (node)
1058 {
1059 wxRect* rect = (wxRect*) node->Data();
1060 XExposeEvent event;
34636400 1061
2d120f83
JS
1062 event.type = Expose;
1063 event.display = display;
1064 event.send_event = True;
1065 event.window = window;
34636400 1066
2d120f83
JS
1067 event.x = rect->x;
1068 event.y = rect->y;
1069 event.width = rect->width;
1070 event.height = rect->height;
34636400 1071
2d120f83 1072 event.count = 0;
34636400 1073
2d120f83 1074 XSendEvent(display, window, False, ExposureMask, (XEvent *)&event);
34636400 1075
2d120f83 1076 node = node->Next();
34636400 1077
2d120f83 1078 }
34636400 1079
2d120f83
JS
1080 // Delete the update rects
1081 node = updateRects.First();
1082 while (node)
1083 {
1084 wxRect* rect = (wxRect*) node->Data();
1085 delete rect;
1086 node = node->Next();
1087 }
a91b47e8
JS
1088
1089 XmUpdateDisplay((Widget) GetMainWidget());
4bb6408c
JS
1090}
1091
34636400
VZ
1092// ---------------------------------------------------------------------------
1093// drag and drop
1094// ---------------------------------------------------------------------------
4ce81a75 1095
34636400 1096#if wxUSE_DRAG_AND_DROP
4ce81a75 1097
34636400 1098void wxWindow::SetDropTarget(wxDropTarget * WXUNUSED(pDropTarget))
4ce81a75 1099{
34636400 1100 // TODO
4bb6408c
JS
1101}
1102
34636400
VZ
1103#endif
1104
1105// Old style file-manager drag&drop
1106void wxWindow::DragAcceptFiles(bool WXUNUSED(accept))
4bb6408c 1107{
34636400 1108 // TODO
4bb6408c
JS
1109}
1110
34636400
VZ
1111// ----------------------------------------------------------------------------
1112// tooltips
1113// ----------------------------------------------------------------------------
1114
1115#if wxUSE_TOOLTIPS
1116
1117void wxWindow::DoSetToolTip(wxToolTip * WXUNUSED(tooltip))
4bb6408c 1118{
34636400 1119 // TODO
4bb6408c
JS
1120}
1121
34636400
VZ
1122#endif // wxUSE_TOOLTIPS
1123
ee31c392
VZ
1124// ----------------------------------------------------------------------------
1125// popup menus
1126// ----------------------------------------------------------------------------
1127
1128bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
1129{
1130 Widget widget = (Widget) GetMainWidget();
1131
1132 /* The menuId field seems to be usused, so we'll use it to
1133 indicate whether a menu is popped up or not:
1134 0: Not currently created as a popup
1135 -1: Created as a popup, but not active
1136 1: Active popup.
1137 */
1138
1139 if (menu->GetParent() && (menu->GetId() != -1))
1140 return FALSE;
1141
1142 if (menu->GetMainWidget()) {
1143 menu->DestroyMenu(TRUE);
1144 }
1145
1146 menu->SetId(1); /* Mark as popped-up */
1147 menu->CreateMenu(NULL, widget, menu);
1148 menu->SetInvokingWindow(this);
1149
1150 menu->UpdateUI();
1151
1152 // menu->SetParent(parent);
1153 // parent->children->Append(menu); // Store menu for later deletion
1154
1155 Widget menuWidget = (Widget) menu->GetMainWidget();
1156
1157 int rootX = 0;
1158 int rootY = 0;
1159
1160 int deviceX = x;
1161 int deviceY = y;
1162 /*
1163 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1164 {
1165 wxCanvas *canvas = (wxCanvas *) this;
1166 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1167 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1168 }
1169 */
1170
1171 Display *display = XtDisplay (widget);
1172 Window rootWindow = RootWindowOfScreen (XtScreen((Widget)widget));
1173 Window thisWindow = XtWindow (widget);
1174 Window childWindow;
1175 XTranslateCoordinates (display, thisWindow, rootWindow, (int) deviceX, (int) deviceY,
1176 &rootX, &rootY, &childWindow);
1177
1178 XButtonPressedEvent event;
1179 event.type = ButtonPress;
1180 event.button = 1;
1181
1182 event.x = deviceX;
1183 event.y = deviceY;
1184
1185 event.x_root = rootX;
1186 event.y_root = rootY;
1187
1188 XmMenuPosition (menuWidget, &event);
1189 XtManageChild (menuWidget);
1190
1191 return TRUE;
1192}
1193
34636400
VZ
1194// ---------------------------------------------------------------------------
1195// moving and resizing
1196// ---------------------------------------------------------------------------
4bb6408c 1197
34636400 1198bool wxWindow::PreResize()
4bb6408c 1199{
2d120f83 1200 return TRUE;
4bb6408c
JS
1201}
1202
34636400 1203// Get total size
af0bb3b1 1204void wxWindow::DoGetSize(int *x, int *y) const
4bb6408c 1205{
34636400 1206 if (m_drawingArea)
2d120f83 1207 {
34636400
VZ
1208 CanvasGetSize(x, y);
1209 return;
2d120f83 1210 }
34636400
VZ
1211
1212 Widget widget = (Widget) GetTopWidget();
1213 Dimension xx, yy;
1214 XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
f6fb552e 1215 if(x) *x = xx; if(y) *y = yy;
4bb6408c
JS
1216}
1217
af0bb3b1 1218void wxWindow::DoGetPosition(int *x, int *y) const
4bb6408c 1219{
34636400 1220 if (m_drawingArea)
2d120f83 1221 {
34636400
VZ
1222 CanvasGetPosition(x, y);
1223 return;
2d120f83 1224 }
34636400
VZ
1225 Widget widget = (Widget) GetTopWidget();
1226 Position xx, yy;
1227 XtVaGetValues(widget, XmNx, &xx, XmNy, &yy, NULL);
b59bf2db 1228
34636400
VZ
1229 // We may be faking the client origin. So a window that's really at (0, 30)
1230 // may appear (to wxWin apps) to be at (0, 0).
1231 if (GetParent())
b59bf2db 1232 {
34636400
VZ
1233 wxPoint pt(GetParent()->GetClientAreaOrigin());
1234 xx -= pt.x;
1235 yy -= pt.y;
b59bf2db 1236 }
34636400 1237
f6fb552e 1238 if(x) *x = xx; if(y) *y = yy;
4bb6408c
JS
1239}
1240
af0bb3b1 1241void wxWindow::DoScreenToClient(int *x, int *y) const
4bb6408c 1242{
34636400
VZ
1243 Widget widget = (Widget) GetClientWidget();
1244 Display *display = XtDisplay((Widget) GetMainWidget());
1245 Window rootWindow = RootWindowOfScreen(XtScreen(widget));
1246 Window thisWindow = XtWindow(widget);
1247
1248 Window childWindow;
1249 int xx = *x;
1250 int yy = *y;
1251 XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow);
4bb6408c
JS
1252}
1253
af0bb3b1 1254void wxWindow::DoClientToScreen(int *x, int *y) const
4bb6408c 1255{
34636400
VZ
1256 Widget widget = (Widget) GetClientWidget();
1257 Display *display = XtDisplay(widget);
1258 Window rootWindow = RootWindowOfScreen(XtScreen(widget));
1259 Window thisWindow = XtWindow(widget);
1260
1261 Window childWindow;
1262 int xx = *x;
1263 int yy = *y;
1264 XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow);
4bb6408c
JS
1265}
1266
34636400
VZ
1267
1268// Get size *available for subwindows* i.e. excluding menu bar etc.
af0bb3b1 1269void wxWindow::DoGetClientSize(int *x, int *y) const
4fabb575 1270{
34636400
VZ
1271 Widget widget = (Widget) GetClientWidget();
1272 Dimension xx, yy;
1273 XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
f6fb552e 1274 if(x) *x = xx; if(y) *y = yy;
4fabb575
JS
1275}
1276
34636400 1277void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
4bb6408c 1278{
34636400
VZ
1279 // A bit of optimization to help sort out the flickers.
1280 int oldX, oldY, oldW, oldH;
1281 GetSize(& oldW, & oldH);
1282 GetPosition(& oldX, & oldY);
1283
9d9b7755
VZ
1284 if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1285 {
1286 if ( x == -1 )
1287 x = oldX;
1288 if ( y == -1 )
1289 y = oldY;
1290 }
34636400 1291
9d9b7755
VZ
1292 if ( width == -1 )
1293 width = oldW;
1294 if ( height == -1 )
1295 height = oldH;
34636400 1296
9d9b7755
VZ
1297 bool nothingChanged = (x == oldX) && (y == oldY) &&
1298 (width == oldW) && (height == oldH);
34636400
VZ
1299
1300 if (!wxNoOptimize::CanOptimize())
02800301 1301 {
9d9b7755 1302 nothingChanged = FALSE;
34636400
VZ
1303 }
1304
9d9b7755 1305 if ( !nothingChanged )
34636400 1306 {
9d9b7755
VZ
1307 if (m_drawingArea)
1308 {
1309 CanvasSetSize(x, y, width, height, sizeFlags);
1310 return;
1311 }
34636400 1312
9d9b7755
VZ
1313 Widget widget = (Widget) GetTopWidget();
1314 if (!widget)
1315 return;
34636400 1316
9d9b7755
VZ
1317 bool managed = XtIsManaged( widget );
1318 if (managed)
1319 XtUnmanageChild(widget);
34636400 1320
9d9b7755
VZ
1321 int xx = x;
1322 int yy = y;
1323 AdjustForParentClientOrigin(xx, yy, sizeFlags);
1324
1325 DoMoveWindow(xx, yy, width, height);
34636400 1326
9d9b7755
VZ
1327 if (managed)
1328 XtManageChild(widget);
34636400 1329
9d9b7755
VZ
1330 // How about this bit. Maybe we don't need to generate size events
1331 // all the time -- they'll be generated when the window is sized anyway.
02800301 1332#if 0
9d9b7755
VZ
1333 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
1334 sizeEvent.SetEventObject(this);
34636400 1335
9d9b7755 1336 GetEventHandler()->ProcessEvent(sizeEvent);
34636400 1337#endif // 0
9d9b7755 1338 }
4bb6408c
JS
1339}
1340
34636400 1341void wxWindow::DoSetClientSize(int width, int height)
4bb6408c 1342{
34636400 1343 if (m_drawingArea)
4bb6408c 1344 {
34636400
VZ
1345 CanvasSetClientSize(width, height);
1346 return;
4bb6408c 1347 }
34636400
VZ
1348
1349 Widget widget = (Widget) GetTopWidget();
1350
1351 if (width > -1)
1352 XtVaSetValues(widget, XmNwidth, width, NULL);
1353 if (height > -1)
1354 XtVaSetValues(widget, XmNheight, height, NULL);
1355
1356 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
1357 sizeEvent.SetEventObject(this);
1358
1359 GetEventHandler()->ProcessEvent(sizeEvent);
4bb6408c
JS
1360}
1361
34636400
VZ
1362// For implementation purposes - sometimes decorations make the client area
1363// smaller
1364wxPoint wxWindow::GetClientAreaOrigin() const
02e8b2f9 1365{
34636400 1366 return wxPoint(0, 0);
02e8b2f9
JS
1367}
1368
34636400 1369void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH)
4bb6408c 1370{
34636400
VZ
1371 m_minWidth = minW;
1372 m_minHeight = minH;
1373 m_maxWidth = maxW;
1374 m_maxHeight = maxH;
1375
1376 wxFrame *frame = wxDynamicCast(this, wxFrame);
1377 if ( !frame )
2d120f83 1378 {
34636400
VZ
1379 // TODO what about dialogs?
1380 return;
2d120f83 1381 }
4bb6408c 1382
34636400
VZ
1383 Widget widget = (Widget) frame->GetShellWidget();
1384
1385 if (minW > -1)
1386 XtVaSetValues(widget, XmNminWidth, minW, NULL);
1387 if (minH > -1)
1388 XtVaSetValues(widget, XmNminHeight, minH, NULL);
1389 if (maxW > -1)
1390 XtVaSetValues(widget, XmNmaxWidth, maxW, NULL);
1391 if (maxH > -1)
1392 XtVaSetValues(widget, XmNmaxHeight, maxH, NULL);
1393 if (incW > -1)
1394 XtVaSetValues(widget, XmNwidthInc, incW, NULL);
1395 if (incH > -1)
1396 XtVaSetValues(widget, XmNheightInc, incH, NULL);
4bb6408c
JS
1397}
1398
9d9b7755
VZ
1399void wxWindow::DoMoveWindow(int x, int y, int width, int height)
1400{
0148fe1e
VZ
1401 XtVaSetValues((Widget)GetTopWidget(),
1402 XmNx, x,
1403 XmNy, y,
9d9b7755
VZ
1404 XmNwidth, width,
1405 XmNheight, height,
1406 NULL);
1407}
1408
34636400
VZ
1409// ---------------------------------------------------------------------------
1410// text metrics
1411// ---------------------------------------------------------------------------
1412
1413int wxWindow::GetCharHeight() const
4bb6408c 1414{
af0bb3b1 1415 wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
34636400 1416
af0bb3b1 1417 WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay());
34636400
VZ
1418
1419 int direction, ascent, descent;
1420 XCharStruct overall;
1421 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
1422 &descent, &overall);
1423
1424 // return (overall.ascent + overall.descent);
1425 return (ascent + descent);
4bb6408c
JS
1426}
1427
34636400 1428int wxWindow::GetCharWidth() const
4bb6408c 1429{
af0bb3b1 1430 wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
34636400 1431
af0bb3b1 1432 WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay());
34636400
VZ
1433
1434 int direction, ascent, descent;
1435 XCharStruct overall;
1436 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
1437 &descent, &overall);
1438
1439 return overall.width;
4bb6408c
JS
1440}
1441
34636400
VZ
1442void wxWindow::GetTextExtent(const wxString& string,
1443 int *x, int *y,
1444 int *descent, int *externalLeading,
1445 const wxFont *theFont) const
4bb6408c 1446{
34636400
VZ
1447 wxFont *fontToUse = (wxFont *)theFont;
1448 if (!fontToUse)
af0bb3b1 1449 fontToUse = (wxFont *) & m_font;
34636400 1450
af0bb3b1 1451 wxCHECK_RET( fontToUse->Ok(), "valid window font needed" );
8e877c19 1452
34636400
VZ
1453 WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay());
1454
1455 int direction, ascent, descent2;
1456 XCharStruct overall;
8e877c19 1457 int slen = string.Len();
34636400
VZ
1458
1459#if 0
1460 if (use16)
1461 XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction,
1462 &ascent, &descent2, &overall);
1463#endif
1464
1465 XTextExtents((XFontStruct*) pFontStruct, string, slen,
1466 &direction, &ascent, &descent2, &overall);
1467
1468 if ( x )
1469 *x = (overall.width);
1470 if ( y )
1471 *y = (ascent + descent2);
1472 if (descent)
1473 *descent = descent2;
1474 if (externalLeading)
1475 *externalLeading = 0;
8e877c19 1476
4bb6408c
JS
1477}
1478
34636400
VZ
1479// ----------------------------------------------------------------------------
1480// painting
1481// ----------------------------------------------------------------------------
4bb6408c 1482
34636400 1483void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
4bb6408c 1484{
34636400
VZ
1485 m_needsRefresh = TRUE;
1486 Display *display = XtDisplay((Widget) GetMainWidget());
1487 Window thisWindow = XtWindow((Widget) GetMainWidget());
1488
1489 XExposeEvent dummyEvent;
1490 int width, height;
1491 GetSize(&width, &height);
1492
1493 dummyEvent.type = Expose;
1494 dummyEvent.display = display;
1495 dummyEvent.send_event = True;
1496 dummyEvent.window = thisWindow;
1497 if (rect)
2d120f83 1498 {
34636400
VZ
1499 dummyEvent.x = rect->x;
1500 dummyEvent.y = rect->y;
1501 dummyEvent.width = rect->width;
1502 dummyEvent.height = rect->height;
2d120f83
JS
1503 }
1504 else
1505 {
34636400
VZ
1506 dummyEvent.x = 0;
1507 dummyEvent.y = 0;
1508 dummyEvent.width = width;
1509 dummyEvent.height = height;
2d120f83 1510 }
34636400 1511 dummyEvent.count = 0;
4bb6408c 1512
34636400 1513 if (eraseBack)
2d120f83 1514 {
34636400
VZ
1515 wxClientDC dc(this);
1516 wxBrush backgroundBrush(GetBackgroundColour(), wxSOLID);
1517 dc.SetBackground(backgroundBrush);
1518 if (rect)
1519 dc.Clear(*rect);
1520 else
1521 dc.Clear();
2d120f83 1522 }
4bb6408c 1523
34636400 1524 XSendEvent(display, thisWindow, False, ExposureMask, (XEvent *)&dummyEvent);
4bb6408c
JS
1525}
1526
34636400 1527void wxWindow::Clear()
4bb6408c 1528{
34636400
VZ
1529 wxClientDC dc(this);
1530 wxBrush brush(GetBackgroundColour(), wxSOLID);
1531 dc.SetBackground(brush);
1532 dc.Clear();
4bb6408c
JS
1533}
1534
34636400 1535void wxWindow::ClearUpdateRects()
4bb6408c 1536{
af0bb3b1 1537 wxRectList::Node* node = m_updateRects.GetFirst();
2d120f83
JS
1538 while (node)
1539 {
af0bb3b1 1540 wxRect* rect = node->GetData();
34636400 1541 delete rect;
af0bb3b1 1542 node = node->GetNext();
2d120f83 1543 }
af0bb3b1 1544
34636400 1545 m_updateRects.Clear();
4bb6408c
JS
1546}
1547
34636400 1548void wxWindow::DoPaint()
4bb6408c 1549{
34636400
VZ
1550 //TODO : make a temporary gc so we can do the XCopyArea below
1551 if (m_backingPixmap && !m_needsRefresh)
4bb6408c 1552 {
34636400 1553 wxPaintDC dc(this);
4bb6408c 1554
34636400 1555 GC tempGC = (GC) dc.GetBackingGC();
4bb6408c 1556
34636400 1557 Widget widget = (Widget) GetMainWidget();
4bb6408c 1558
34636400
VZ
1559 int scrollPosX = 0;
1560 int scrollPosY = 0;
4bb6408c 1561
34636400
VZ
1562 // We have to test whether it's a wxScrolledWindow (hack!) because
1563 // otherwise we don't know how many pixels have been scrolled. We might
1564 // solve this in the future by defining virtual wxWindow functions to get
1565 // the scroll position in pixels. Or, each kind of scrolled window has to
1566 // implement backing stores itself, using generic wxWindows code.
1567 wxScrolledWindow* scrolledWindow = wxDynamicCast(this, wxScrolledWindow);
1568 if ( scrolledWindow )
1569 {
1570 int x, y;
1571 scrolledWindow->CalcScrolledPosition(0, 0, &x, &y);
1572
1573 scrollPosX = - x;
1574 scrollPosY = - y;
1575 }
1576
1577 // TODO: This could be optimized further by only copying the areas in the
1578 // current update region.
1579
1580 // Only blit the part visible in the client area. The backing pixmap
1581 // always starts at 0, 0 but we may be looking at only a portion of it.
1582 wxSize clientArea = GetClientSize();
1583 int toBlitX = m_pixmapWidth - scrollPosX;
1584 int toBlitY = m_pixmapHeight - scrollPosY;
1585
1586 // Copy whichever is samller, the amount of pixmap we have to copy,
1587 // or the size of the client area.
1588 toBlitX = wxMin(toBlitX, clientArea.x);
1589 toBlitY = wxMin(toBlitY, clientArea.y);
1590
1591 // Make sure we're not negative
1592 toBlitX = wxMax(0, toBlitX);
1593 toBlitY = wxMax(0, toBlitY);
1594
1595 XCopyArea
1596 (
1597 XtDisplay(widget),
1598 (Pixmap) m_backingPixmap,
1599 XtWindow (widget),
1600 tempGC,
1601 scrollPosX, scrollPosY, // Start at the scroll position
1602 toBlitX, toBlitY, // How much of the pixmap to copy
1603 0, 0 // Destination
1604 );
1605 }
1606 else
4bb6408c 1607 {
34636400
VZ
1608 // Set an erase event first
1609 wxEraseEvent eraseEvent(GetId());
1610 eraseEvent.SetEventObject(this);
1611 GetEventHandler()->ProcessEvent(eraseEvent);
1612
1613 wxPaintEvent event(GetId());
1614 event.SetEventObject(this);
1615 GetEventHandler()->ProcessEvent(event);
1616
1617 m_needsRefresh = FALSE;
4bb6408c 1618 }
4bb6408c
JS
1619}
1620
34636400
VZ
1621// ----------------------------------------------------------------------------
1622// event handlers
1623// ----------------------------------------------------------------------------
1624
1625// Responds to colour changes: passes event on to children.
1626void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
4bb6408c 1627{
34636400
VZ
1628 wxWindowList::Node *node = GetChildren().GetFirst();
1629 while ( node )
4bb6408c 1630 {
34636400
VZ
1631 // Only propagate to non-top-level windows
1632 wxWindow *win = node->GetData();
1633 if ( win->GetParent() )
2d120f83 1634 {
34636400
VZ
1635 wxSysColourChangedEvent event2;
1636 event.m_eventObject = win;
1637 win->GetEventHandler()->ProcessEvent(event2);
2d120f83 1638 }
4bb6408c 1639
34636400 1640 node = node->GetNext();
2d120f83 1641 }
4bb6408c
JS
1642}
1643
af111fc3 1644void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
4bb6408c 1645{
34636400
VZ
1646 // This calls the UI-update mechanism (querying windows for
1647 // menu/toolbar/control state information)
1648 UpdateWindowUI();
4bb6408c
JS
1649}
1650
34636400
VZ
1651// ----------------------------------------------------------------------------
1652// accelerators
1653// ----------------------------------------------------------------------------
4bb6408c 1654
34636400 1655bool wxWindow::ProcessAccelerator(wxKeyEvent& event)
4bb6408c 1656{
34636400
VZ
1657 if (!m_acceleratorTable.Ok())
1658 return FALSE;
4bb6408c 1659
34636400
VZ
1660 int count = m_acceleratorTable.GetCount();
1661 wxAcceleratorEntry* entries = m_acceleratorTable.GetEntries();
1662 int i;
1663 for (i = 0; i < count; i++)
2d120f83 1664 {
34636400
VZ
1665 wxAcceleratorEntry* entry = & (entries[i]);
1666 if (entry->MatchesEvent(event))
1667 {
f6045f99
GD
1668 // Bingo, we have a match. Now find a control that matches the
1669 // entry command id.
4bb6408c 1670
34636400
VZ
1671 // Need to go up to the top of the window hierarchy, since it might
1672 // be e.g. a menu item
1673 wxWindow* parent = this;
1674 while ( parent && !parent->IsTopLevel() )
1675 parent = parent->GetParent();
4bb6408c 1676
34636400
VZ
1677 if (!parent)
1678 return FALSE;
4bb6408c 1679
34636400
VZ
1680 wxFrame* frame = wxDynamicCast(parent, wxFrame);
1681 if ( frame )
1682 {
1683 // Try for a menu command
1684 if (frame->GetMenuBar())
1685 {
c71830c3 1686 wxMenuItem* item = frame->GetMenuBar()->FindItem(entry->GetCommand());
34636400
VZ
1687 if (item)
1688 {
1689 wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, entry->GetCommand());
1690 commandEvent.SetEventObject(frame);
4bb6408c 1691
34636400
VZ
1692 // If ProcessEvent returns TRUE (it was handled), then
1693 // the calling code will skip the event handling.
1694 return frame->GetEventHandler()->ProcessEvent(commandEvent);
1695 }
1696 }
1697 }
3dd4e4e0 1698
34636400
VZ
1699 // Find a child matching the command id
1700 wxWindow* child = parent->FindWindow(entry->GetCommand());
3dd4e4e0 1701
34636400
VZ
1702 // No such child
1703 if (!child)
1704 return FALSE;
3dd4e4e0 1705
34636400
VZ
1706 // Now we process those kinds of windows that we can.
1707 // For now, only buttons.
1708 if ( wxDynamicCast(child, wxButton) )
1709 {
1710 wxCommandEvent commandEvent (wxEVT_COMMAND_BUTTON_CLICKED, child->GetId());
1711 commandEvent.SetEventObject(child);
1712 return child->GetEventHandler()->ProcessEvent(commandEvent);
1713 }
3dd4e4e0 1714
34636400
VZ
1715 return FALSE;
1716 } // matches event
1717 }// for
4bb6408c 1718
34636400
VZ
1719 // We didn't match the key event against an accelerator.
1720 return FALSE;
4bb6408c
JS
1721}
1722
34636400
VZ
1723// ============================================================================
1724// Motif-specific stuff from here on
1725// ============================================================================
1726
1727// ----------------------------------------------------------------------------
1728// function which maintain the global hash table mapping Widgets to wxWindows
1729// ----------------------------------------------------------------------------
1730
1731bool wxAddWindowToTable(Widget w, wxWindow *win)
4bb6408c 1732{
34636400 1733 wxWindow *oldItem = NULL;
33caefb3 1734 if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w)))
2d120f83 1735 {
34636400
VZ
1736 wxLogDebug("Widget table clash: new widget is %ld, %s",
1737 (long)w, win->GetClassInfo()->GetClassName());
1738 return FALSE;
2d120f83 1739 }
4bb6408c 1740
33caefb3 1741 wxWidgetHashTable->Put((long) w, win);
4bb6408c 1742
e838cc14 1743 wxLogTrace("widget", "Widget 0x%08x <-> window %p (%s)",
31528cd3
VZ
1744 w, win, win->GetClassInfo()->GetClassName());
1745
34636400 1746 return TRUE;
4bb6408c
JS
1747}
1748
34636400 1749wxWindow *wxGetWindowFromTable(Widget w)
4bb6408c 1750{
33caefb3 1751 return (wxWindow *)wxWidgetHashTable->Get((long) w);
4bb6408c
JS
1752}
1753
34636400 1754void wxDeleteWindowFromTable(Widget w)
4bb6408c 1755{
33caefb3 1756 wxWidgetHashTable->Delete((long)w);
4bb6408c
JS
1757}
1758
34636400
VZ
1759// ----------------------------------------------------------------------------
1760// add/remove window from the table
1761// ----------------------------------------------------------------------------
4bb6408c 1762
34636400 1763// Add to hash table, add event handler
af111fc3 1764bool wxWindow::AttachWidget (wxWindow* WXUNUSED(parent), WXWidget mainWidget,
34636400 1765 WXWidget formWidget, int x, int y, int width, int height)
4bb6408c 1766{
34636400
VZ
1767 wxAddWindowToTable((Widget) mainWidget, this);
1768 if (CanAddEventHandler())
1769 {
1770 XtAddEventHandler((Widget) mainWidget,
1771 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask,
1772 False,
1773 wxPanelItemEventHandler,
1774 (XtPointer) this);
1775 }
4bb6408c 1776
34636400
VZ
1777 if (!formWidget)
1778 {
1779 XtTranslations ptr;
1780 XtOverrideTranslations ((Widget) mainWidget,
1781 ptr = XtParseTranslationTable ("<Configure>: resize()"));
1782 XtFree ((char *) ptr);
1783 }
4bb6408c 1784
34636400
VZ
1785 // Some widgets have a parent form widget, e.g. wxRadioBox
1786 if (formWidget)
1787 {
1788 if (!wxAddWindowToTable((Widget) formWidget, this))
1789 return FALSE;
4bb6408c 1790
34636400
VZ
1791 XtTranslations ptr;
1792 XtOverrideTranslations ((Widget) formWidget,
1793 ptr = XtParseTranslationTable ("<Configure>: resize()"));
1794 XtFree ((char *) ptr);
1795 }
4bb6408c 1796
34636400
VZ
1797 if (x == -1)
1798 x = 0;
1799 if (y == -1)
1800 y = 0;
1801 SetSize (x, y, width, height);
4bb6408c 1802
34636400 1803 return TRUE;
4bb6408c
JS
1804}
1805
34636400
VZ
1806// Remove event handler, remove from hash table
1807bool wxWindow::DetachWidget(WXWidget widget)
4bb6408c 1808{
34636400 1809 if (CanAddEventHandler())
4bb6408c 1810 {
34636400
VZ
1811 XtRemoveEventHandler((Widget) widget,
1812 ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask,
1813 False,
1814 wxPanelItemEventHandler,
1815 (XtPointer)this);
4bb6408c 1816 }
4bb6408c 1817
34636400 1818 wxDeleteWindowFromTable((Widget) widget);
2d120f83 1819 return TRUE;
4bb6408c
JS
1820}
1821
34636400
VZ
1822// ----------------------------------------------------------------------------
1823// Motif-specific accessors
1824// ----------------------------------------------------------------------------
2d120f83 1825
34636400 1826// Get the underlying X window
4bb6408c
JS
1827WXWindow wxWindow::GetXWindow() const
1828{
af0bb3b1 1829 Widget wMain = (Widget)GetMainWidget();
34636400
VZ
1830 if ( wMain )
1831 return (WXWindow) XtWindow(wMain);
ad813b00
JS
1832 else
1833 return (WXWindow) 0;
4bb6408c
JS
1834}
1835
34636400 1836// Get the underlying X display
4bb6408c
JS
1837WXDisplay *wxWindow::GetXDisplay() const
1838{
af0bb3b1 1839 Widget wMain = (Widget)GetMainWidget();
34636400
VZ
1840 if ( wMain )
1841 return (WXDisplay*) XtDisplay(wMain);
ad813b00
JS
1842 else
1843 return (WXDisplay*) NULL;
4bb6408c
JS
1844}
1845
1846WXWidget wxWindow::GetMainWidget() const
1847{
50414e24 1848 if (m_drawingArea)
2d120f83 1849 return m_drawingArea;
50414e24 1850 else
2d120f83 1851 return m_mainWidget;
50414e24
JS
1852}
1853
1854WXWidget wxWindow::GetClientWidget() const
1855{
1856 if (m_drawingArea != (WXWidget) 0)
1857 return m_drawingArea;
1858 else
02e8b2f9
JS
1859 return GetMainWidget();
1860}
1861
1862WXWidget wxWindow::GetTopWidget() const
1863{
1864 return GetMainWidget();
4bb6408c
JS
1865}
1866
34636400
VZ
1867WXWidget wxWindow::GetLabelWidget() const
1868{
1869 return GetMainWidget();
1870}
1871
1872// ----------------------------------------------------------------------------
1873// Motif callbacks
1874// ----------------------------------------------------------------------------
1875
1876// All widgets should have this as their resize proc.
1877// OnSize sent to wxWindow via client data.
af111fc3 1878void wxWidgetResizeProc(Widget w, XConfigureEvent *WXUNUSED(event), String WXUNUSED(args)[], int *WXUNUSED(num_args))
34636400
VZ
1879{
1880 wxWindow *win = wxGetWindowFromTable(w);
1881 if (!win)
1882 return;
1883
1884 if (win->PreResize())
1885 {
1886 int width, height;
1887 win->GetSize(&width, &height);
1888 wxSizeEvent sizeEvent(wxSize(width, height), win->GetId());
1889 sizeEvent.SetEventObject(win);
1890 win->GetEventHandler()->ProcessEvent(sizeEvent);
1891 }
1892}
1893
1894static void wxCanvasRepaintProc(Widget drawingArea,
1895 XtPointer clientData,
1896 XmDrawingAreaCallbackStruct * cbs)
50414e24 1897{
34636400 1898 if (!wxGetWindowFromTable(drawingArea))
2d120f83 1899 return;
34636400 1900
50414e24 1901 XEvent * event = cbs->event;
55acd85e 1902 wxWindow * win = (wxWindow *) clientData;
34636400 1903
50414e24
JS
1904 switch (event->type)
1905 {
2d120f83 1906 case Expose:
55acd85e 1907 {
6970c7b9
MB
1908 win->AddUpdateRect(event->xexpose.x, event->xexpose.y,
1909 event->xexpose.width, event->xexpose.height);
1910
55acd85e
JS
1911 if (event -> xexpose.count == 0)
1912 {
a91b47e8 1913 win->DoPaint();
55acd85e
JS
1914 win->ClearUpdateRects();
1915 }
1916 break;
1917 }
50414e24 1918 }
50414e24
JS
1919}
1920
1921// Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
34636400 1922static void wxCanvasEnterLeave(Widget drawingArea,
af111fc3 1923 XtPointer WXUNUSED(clientData),
34636400 1924 XCrossingEvent * event)
50414e24 1925{
2d120f83
JS
1926 XmDrawingAreaCallbackStruct cbs;
1927 XEvent ev;
34636400 1928
2d120f83 1929 ((XCrossingEvent &) ev) = *event;
34636400 1930
2d120f83
JS
1931 cbs.reason = XmCR_INPUT;
1932 cbs.event = &ev;
34636400
VZ
1933
1934 wxCanvasInputEvent(drawingArea, (XtPointer) NULL, &cbs);
50414e24
JS
1935}
1936
1937// Fix to make it work under Motif 1.0 (!)
af111fc3 1938static void wxCanvasMotionEvent (Widget WXUNUSED(drawingArea), XButtonEvent * WXUNUSED(event))
50414e24 1939{
34636400 1940#if XmVersion <= 1000
2d120f83
JS
1941 XmDrawingAreaCallbackStruct cbs;
1942 XEvent ev;
34636400 1943
2d120f83
JS
1944 ev = *((XEvent *) event);
1945 cbs.reason = XmCR_INPUT;
1946 cbs.event = &ev;
34636400 1947
2d120f83 1948 wxCanvasInputEvent (drawingArea, (XtPointer) NULL, &cbs);
34636400 1949#endif // XmVersion <= 1000
50414e24
JS
1950}
1951
34636400 1952static void wxCanvasInputEvent(Widget drawingArea,
af111fc3 1953 XtPointer WXUNUSED(data),
34636400 1954 XmDrawingAreaCallbackStruct * cbs)
50414e24 1955{
34636400 1956 wxWindow *canvas = wxGetWindowFromTable(drawingArea);
2d120f83 1957 XEvent local_event;
34636400 1958
2d120f83 1959 if (canvas==NULL)
34636400
VZ
1960 return;
1961
2d120f83
JS
1962 if (cbs->reason != XmCR_INPUT)
1963 return;
34636400
VZ
1964
1965 local_event = *(cbs->event); // We must keep a copy!
1966
2d120f83 1967 switch (local_event.xany.type)
50414e24
JS
1968 {
1969 case EnterNotify:
1970 case LeaveNotify:
1971 case ButtonPress:
1972 case ButtonRelease:
1973 case MotionNotify:
2d120f83 1974 {
1e8abce5
MB
1975 // FIXME: most of this mouse event code is more or less
1976 // duplicated in wxTranslateMouseEvent
1977 //
2d120f83 1978 wxEventType eventType = wxEVT_NULL;
34636400 1979
2d120f83
JS
1980 if (local_event.xany.type == EnterNotify)
1981 {
1982 //if (local_event.xcrossing.mode!=NotifyNormal)
1983 // return ; // Ignore grab events
1984 eventType = wxEVT_ENTER_WINDOW;
1985 // canvas->GetEventHandler()->OnSetFocus();
1986 }
1987 else if (local_event.xany.type == LeaveNotify)
1988 {
1e8abce5 1989 //if (local_event.xcrossingr.mode!=NotifyNormal)
2d120f83
JS
1990 // return ; // Ignore grab events
1991 eventType = wxEVT_LEAVE_WINDOW;
1992 // canvas->GetEventHandler()->OnKillFocus();
1993 }
1994 else if (local_event.xany.type == MotionNotify)
1995 {
1996 eventType = wxEVT_MOTION;
2d120f83 1997 }
34636400 1998
2d120f83
JS
1999 else if (local_event.xany.type == ButtonPress)
2000 {
2001 if (local_event.xbutton.button == Button1)
2002 {
2003 eventType = wxEVT_LEFT_DOWN;
af0bb3b1 2004 canvas->SetButton1(TRUE);
2d120f83
JS
2005 }
2006 else if (local_event.xbutton.button == Button2)
2007 {
2008 eventType = wxEVT_MIDDLE_DOWN;
af0bb3b1 2009 canvas->SetButton2(TRUE);
2d120f83
JS
2010 }
2011 else if (local_event.xbutton.button == Button3)
2012 {
2013 eventType = wxEVT_RIGHT_DOWN;
af0bb3b1 2014 canvas->SetButton3(TRUE);
2d120f83
JS
2015 }
2016 }
2017 else if (local_event.xany.type == ButtonRelease)
2018 {
2019 if (local_event.xbutton.button == Button1)
2020 {
2021 eventType = wxEVT_LEFT_UP;
af0bb3b1 2022 canvas->SetButton1(FALSE);
2d120f83
JS
2023 }
2024 else if (local_event.xbutton.button == Button2)
2025 {
2026 eventType = wxEVT_MIDDLE_UP;
af0bb3b1 2027 canvas->SetButton2(FALSE);
2d120f83
JS
2028 }
2029 else if (local_event.xbutton.button == Button3)
2030 {
2031 eventType = wxEVT_RIGHT_UP;
af0bb3b1 2032 canvas->SetButton3(FALSE);
2d120f83
JS
2033 }
2034 }
34636400 2035
2d120f83 2036 wxMouseEvent wxevent (eventType);
34636400 2037
2d120f83 2038 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
34636400 2039 || (event_left_is_down (&local_event)
2d120f83
JS
2040 && (eventType != wxEVT_LEFT_UP)));
2041 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
34636400 2042 || (event_middle_is_down (&local_event)
2d120f83
JS
2043 && (eventType != wxEVT_MIDDLE_UP)));
2044 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
34636400 2045 || (event_right_is_down (&local_event)
2d120f83 2046 && (eventType != wxEVT_RIGHT_UP)));
34636400 2047
2d120f83
JS
2048 wxevent.m_shiftDown = local_event.xbutton.state & ShiftMask;
2049 wxevent.m_controlDown = local_event.xbutton.state & ControlMask;
2050 wxevent.m_altDown = local_event.xbutton.state & Mod3Mask;
2051 wxevent.m_metaDown = local_event.xbutton.state & Mod1Mask;
2052 wxevent.SetTimestamp(local_event.xbutton.time);
34636400 2053
a16a9bf3 2054 if ( eventType == wxEVT_MOTION )
1afe597e
VZ
2055 {
2056 if (local_event.xmotion.is_hint == NotifyHint)
2057 {
2058 Window root, child;
2059 Display *dpy = XtDisplay (drawingArea);
2060
2061 XQueryPointer (dpy, XtWindow (drawingArea),
2062 &root, &child,
2063 &local_event.xmotion.x_root,
2064 &local_event.xmotion.y_root,
2065 &local_event.xmotion.x,
2066 &local_event.xmotion.y,
2067 &local_event.xmotion.state);
2068 }
2069 else
2070 {
2071 }
2072 }
2073
2d120f83
JS
2074 // Now check if we need to translate this event into a double click
2075 if (TRUE) // canvas->doubleClickAllowed)
2076 {
2077 if (wxevent.ButtonDown())
2078 {
34636400
VZ
2079 long dclickTime = XtGetMultiClickTime((Display*) wxGetDisplay());
2080
2d120f83
JS
2081 // get button and time-stamp
2082 int button = 0;
af0bb3b1
VZ
2083 if (wxevent.LeftDown())
2084 button = 1;
2085 else if (wxevent.MiddleDown())
2086 button = 2;
2087 else if (wxevent.RightDown())
2088 button = 3;
2d120f83 2089 long ts = wxevent.GetTimestamp();
af0bb3b1 2090
2d120f83 2091 // check, if single or double click
af0bb3b1
VZ
2092 int buttonLast = canvas->GetLastClickedButton();
2093 long lastTS = canvas->GetLastClickTime();
2094 if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime )
2d120f83
JS
2095 {
2096 // I have a dclick
af0bb3b1 2097 canvas->SetLastClick(0, ts);
cce442ba
VZ
2098
2099 wxEventType typeDouble;
2100 if ( eventType == wxEVT_LEFT_DOWN )
2101 typeDouble = wxEVT_LEFT_DCLICK;
2102 else if ( eventType == wxEVT_MIDDLE_DOWN )
2103 typeDouble = wxEVT_MIDDLE_DCLICK;
2104 else if ( eventType == wxEVT_RIGHT_DOWN )
2105 typeDouble = wxEVT_RIGHT_DCLICK;
2106 else
2107 typeDouble = wxEVT_NULL;
2108
2109 if ( typeDouble != wxEVT_NULL )
2d120f83 2110 {
cce442ba 2111 wxevent.SetEventType(typeDouble);
2d120f83 2112 }
2d120f83
JS
2113 }
2114 else
2115 {
2116 // not fast enough or different button
af0bb3b1 2117 canvas->SetLastClick(button, ts);
2d120f83
JS
2118 }
2119 }
2120 }
34636400 2121
2d120f83
JS
2122 wxevent.SetId(canvas->GetId());
2123 wxevent.SetEventObject(canvas);
2124 wxevent.m_x = local_event.xbutton.x;
2125 wxevent.m_y = local_event.xbutton.y;
2126 canvas->GetEventHandler()->ProcessEvent (wxevent);
34636400 2127#if 0
2d120f83 2128 if (eventType == wxEVT_ENTER_WINDOW ||
34636400
VZ
2129 eventType == wxEVT_LEAVE_WINDOW ||
2130 eventType == wxEVT_MOTION
2131 )
2132 return;
2133#endif // 0
2d120f83 2134 break;
50414e24
JS
2135 }
2136 case KeyPress:
50414e24 2137 {
2d120f83 2138 KeySym keySym;
45ff6421 2139 static char buf[100];
34636400
VZ
2140#if 0
2141 XComposeStatus compose;
45ff6421 2142 (void) XLookupString ((XKeyEvent *) & local_event, buf, 20, &keySym, &compose);
34636400
VZ
2143#endif // 0
2144
45ff6421 2145 (void) XLookupString ((XKeyEvent *) & local_event, buf, 20, &keySym, NULL);
2d120f83
JS
2146 int id = wxCharCodeXToWX (keySym);
2147
2148 wxEventType eventType = wxEVT_CHAR;
50414e24 2149
2d120f83 2150 wxKeyEvent event (eventType);
34636400 2151
2d120f83
JS
2152 if (local_event.xkey.state & ShiftMask)
2153 event.m_shiftDown = TRUE;
2154 if (local_event.xkey.state & ControlMask)
2155 event.m_controlDown = TRUE;
2156 if (local_event.xkey.state & Mod3Mask)
2157 event.m_altDown = TRUE;
2158 if (local_event.xkey.state & Mod1Mask)
2159 event.m_metaDown = TRUE;
2160 event.SetEventObject(canvas);
2161 event.m_keyCode = id;
2162 event.SetTimestamp(local_event.xkey.time);
34636400 2163
2d120f83
JS
2164 if (id > -1)
2165 {
2166 // Implement wxFrame::OnCharHook by checking ancestor.
2167 wxWindow *parent = canvas->GetParent();
2168 while (parent && !parent->IsKindOf(CLASSINFO(wxFrame)))
2169 parent = parent->GetParent();
34636400 2170
2d120f83
JS
2171 if (parent)
2172 {
2173 event.SetEventType(wxEVT_CHAR_HOOK);
2174 if (parent->GetEventHandler()->ProcessEvent(event))
2175 return;
2d120f83 2176 }
a91b47e8
JS
2177
2178 // For simplicity, OnKeyDown is the same as OnChar
2179 // TODO: filter modifier key presses from OnChar
2180 event.SetEventType(wxEVT_KEY_DOWN);
2181
2182 // Only process OnChar if OnKeyDown didn't swallow it
2183 if (!canvas->GetEventHandler()->ProcessEvent (event))
2184 {
2185 event.SetEventType(wxEVT_CHAR);
2186 canvas->GetEventHandler()->ProcessEvent (event);
34636400 2187 }
2d120f83
JS
2188 }
2189 break;
2190 }
2191 case KeyRelease:
2192 {
45ff6421 2193 static char buf[100];
2d120f83 2194 KeySym keySym;
45ff6421 2195 (void) XLookupString ((XKeyEvent *) & local_event, buf, 20, &keySym, NULL);
2d120f83 2196 int id = wxCharCodeXToWX (keySym);
34636400 2197
2d120f83 2198 wxKeyEvent event (wxEVT_KEY_UP);
34636400 2199
2d120f83
JS
2200 if (local_event.xkey.state & ShiftMask)
2201 event.m_shiftDown = TRUE;
2202 if (local_event.xkey.state & ControlMask)
2203 event.m_controlDown = TRUE;
2204 if (local_event.xkey.state & Mod3Mask)
2205 event.m_altDown = TRUE;
2206 if (local_event.xkey.state & Mod1Mask)
2207 event.m_metaDown = TRUE;
2208 event.SetEventObject(canvas);
2209 event.m_keyCode = id;
2210 event.SetTimestamp(local_event.xkey.time);
34636400 2211
2d120f83
JS
2212 if (id > -1)
2213 {
2214 canvas->GetEventHandler()->ProcessEvent (event);
2215 }
2216 break;
50414e24 2217 }
50414e24 2218 case FocusIn:
2d120f83
JS
2219 {
2220 if (local_event.xfocus.detail != NotifyPointer)
2221 {
2222 wxFocusEvent event(wxEVT_SET_FOCUS, canvas->GetId());
2223 event.SetEventObject(canvas);
2224 canvas->GetEventHandler()->ProcessEvent(event);
2225 }
2226 break;
50414e24 2227 }
50414e24 2228 case FocusOut:
2d120f83
JS
2229 {
2230 if (local_event.xfocus.detail != NotifyPointer)
2231 {
2232 wxFocusEvent event(wxEVT_KILL_FOCUS, canvas->GetId());
2233 event.SetEventObject(canvas);
2234 canvas->GetEventHandler()->ProcessEvent(event);
2235 }
2236 break;
2237 }
50414e24 2238 default:
2d120f83 2239 break;
50414e24
JS
2240 }
2241}
2242
34636400 2243static void wxPanelItemEventHandler(Widget wid,
af111fc3 2244 XtPointer WXUNUSED(client_data),
34636400
VZ
2245 XEvent* event,
2246 Boolean *continueToDispatch)
50414e24 2247{
34636400 2248 // Widget can be a label or the actual widget.
a91b47e8 2249
af0bb3b1 2250 wxWindow *window = wxGetWindowFromTable(wid);
34636400
VZ
2251 if (window)
2252 {
2253 wxMouseEvent wxevent(0);
2254 if (wxTranslateMouseEvent(wxevent, window, wid, event))
2255 {
2256 window->GetEventHandler()->ProcessEvent(wxevent);
2257 }
2258 }
a91b47e8 2259
34636400
VZ
2260 // TODO: probably the key to allowing default behaviour to happen. Say we
2261 // set a m_doDefault flag to FALSE at the start of this function. Then in
2262 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2263 // TRUE, indicating that default processing can happen. Thus, behaviour can
2264 // appear to be overridden just by adding an event handler and not calling
2265 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2266 // way of handling drawing area events, to simplify things.
2267 *continueToDispatch = True;
2268}
a91b47e8 2269
34636400
VZ
2270static void wxScrollBarCallback(Widget scrollbar,
2271 XtPointer clientData,
311227c3 2272 XmScrollBarCallbackStruct *cbs)
34636400 2273{
34636400
VZ
2274 wxWindow *win = wxGetWindowFromTable(scrollbar);
2275 int orientation = (int) clientData;
a91b47e8 2276
34636400
VZ
2277 wxEventType eventType = wxEVT_NULL;
2278 switch (cbs->reason)
2279 {
2280 case XmCR_INCREMENT:
2281 {
311227c3 2282 eventType = wxEVT_SCROLLWIN_LINEDOWN;
34636400
VZ
2283 break;
2284 }
2285 case XmCR_DECREMENT:
2286 {
311227c3 2287 eventType = wxEVT_SCROLLWIN_LINEUP;
34636400
VZ
2288 break;
2289 }
2290 case XmCR_DRAG:
2291 {
311227c3 2292 eventType = wxEVT_SCROLLWIN_THUMBTRACK;
34636400
VZ
2293 break;
2294 }
2295 case XmCR_VALUE_CHANGED:
2296 {
bdeca1d1 2297 eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
34636400
VZ
2298 break;
2299 }
2300 case XmCR_PAGE_INCREMENT:
2301 {
311227c3 2302 eventType = wxEVT_SCROLLWIN_PAGEDOWN;
34636400
VZ
2303 break;
2304 }
2305 case XmCR_PAGE_DECREMENT:
2306 {
311227c3 2307 eventType = wxEVT_SCROLLWIN_PAGEUP;
34636400
VZ
2308 break;
2309 }
2310 case XmCR_TO_TOP:
2311 {
311227c3 2312 eventType = wxEVT_SCROLLWIN_TOP;
34636400
VZ
2313 break;
2314 }
2315 case XmCR_TO_BOTTOM:
2316 {
311227c3 2317 eventType = wxEVT_SCROLLWIN_BOTTOM;
34636400
VZ
2318 break;
2319 }
2320 default:
2321 {
2322 // Should never get here
2323 wxFAIL_MSG("Unknown scroll event.");
2324 break;
2325 }
2326 }
a91b47e8 2327
311227c3
MB
2328 wxScrollWinEvent event(eventType,
2329 cbs->value,
2330 ((orientation == XmHORIZONTAL) ?
2331 wxHORIZONTAL : wxVERTICAL));
2332 event.SetEventObject( win );
34636400
VZ
2333 win->GetEventHandler()->ProcessEvent(event);
2334}
a91b47e8 2335
34636400
VZ
2336// For repainting arbitrary windows
2337void wxUniversalRepaintProc(Widget w, XtPointer WXUNUSED(c_data), XEvent *event, char *)
2338{
2339 Window window;
2340 Display *display;
a91b47e8 2341
34636400
VZ
2342 wxWindow* win = wxGetWindowFromTable(w);
2343 if (!win)
2344 return;
a91b47e8 2345
34636400 2346 switch(event -> type)
50414e24 2347 {
af0bb3b1 2348 case Expose:
34636400
VZ
2349 {
2350 window = (Window) win -> GetXWindow();
2351 display = (Display *) win -> GetXDisplay();
a91b47e8 2352
34636400
VZ
2353 if (event -> xexpose.count == 0)
2354 {
2355 win->DoPaint();
2356
2357 win->ClearUpdateRects();
2358 }
af0bb3b1
VZ
2359 else
2360 {
2361 win->AddUpdateRect(event->xexpose.x, event->xexpose.y,
2362 event->xexpose.width, event->xexpose.height);
2363 }
2364
34636400
VZ
2365 break;
2366 }
50414e24
JS
2367 }
2368}
2369
34636400
VZ
2370// ----------------------------------------------------------------------------
2371// CanvaseXXXSize() functions
2372// ----------------------------------------------------------------------------
2373
50414e24
JS
2374// SetSize, but as per old wxCanvas (with drawing widget etc.)
2375void wxWindow::CanvasSetSize (int x, int y, int w, int h, int sizeFlags)
2376{
2d120f83
JS
2377 // A bit of optimization to help sort out the flickers.
2378 int oldX, oldY, oldW, oldH;
2379 GetSize(& oldW, & oldH);
2380 GetPosition(& oldX, & oldY);
34636400 2381
2d120f83
JS
2382 bool useOldPos = FALSE;
2383 bool useOldSize = FALSE;
34636400 2384
2d120f83
JS
2385 if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0))
2386 useOldPos = TRUE;
2387 else if (x == oldX && y == oldY)
2388 useOldPos = TRUE;
34636400 2389
2d120f83
JS
2390 if ((w == -1) && (h == -1))
2391 useOldSize = TRUE;
2392 else if (w == oldW && h == oldH)
2393 useOldSize = TRUE;
34636400 2394
2d120f83 2395 if (!wxNoOptimize::CanOptimize())
50414e24 2396 {
2d120f83 2397 useOldSize = FALSE; useOldPos = FALSE;
50414e24 2398 }
34636400 2399
2d120f83
JS
2400 if (useOldPos && useOldSize)
2401 return;
34636400 2402
2d120f83
JS
2403 Widget drawingArea = (Widget) m_drawingArea;
2404 bool managed = XtIsManaged(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
34636400 2405
2d120f83
JS
2406 if (managed)
2407 XtUnmanageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
af0bb3b1 2408 XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
34636400 2409
2d120f83
JS
2410 int xx = x; int yy = y;
2411 AdjustForParentClientOrigin(xx, yy, sizeFlags);
34636400 2412
2d120f83 2413 if (!useOldPos)
50414e24 2414 {
2d120f83
JS
2415 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
2416 {
2417 XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow,
2418 XmNx, xx, NULL);
2419 }
34636400 2420
2d120f83
JS
2421 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
2422 {
2423 XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow,
2424 XmNy, yy, NULL);
2425 }
50414e24 2426 }
34636400 2427
2d120f83 2428 if (!useOldSize)
50414e24 2429 {
34636400 2430
2d120f83
JS
2431 if (w > -1)
2432 {
2433 if (m_borderWidget)
2434 {
2435 XtVaSetValues ((Widget) m_borderWidget, XmNwidth, w, NULL);
2436 short thick, margin;
2437 XtVaGetValues ((Widget) m_borderWidget,
2438 XmNshadowThickness, &thick,
2439 XmNmarginWidth, &margin,
2440 NULL);
2441 w -= 2 * (thick + margin);
2442 }
34636400 2443
2d120f83 2444 XtVaSetValues ((Widget) m_scrolledWindow, XmNwidth, w, NULL);
34636400 2445
2d120f83
JS
2446 Dimension spacing;
2447 Widget sbar;
2448 XtVaGetValues ((Widget) m_scrolledWindow,
2449 XmNspacing, &spacing,
2450 XmNverticalScrollBar, &sbar,
2451 NULL);
2452 Dimension wsbar;
2453 if (sbar)
2454 XtVaGetValues (sbar, XmNwidth, &wsbar, NULL);
2455 else
2456 wsbar = 0;
34636400 2457
2d120f83 2458 w -= (spacing + wsbar);
34636400 2459
af0bb3b1
VZ
2460#if 0
2461 XtVaSetValues(drawingArea, XmNwidth, w, NULL);
2462#endif // 0
2d120f83
JS
2463 }
2464 if (h > -1)
2465 {
2466 if (m_borderWidget)
2467 {
2468 XtVaSetValues ((Widget) m_borderWidget, XmNheight, h, NULL);
2469 short thick, margin;
2470 XtVaGetValues ((Widget) m_borderWidget,
2471 XmNshadowThickness, &thick,
2472 XmNmarginHeight, &margin,
2473 NULL);
2474 h -= 2 * (thick + margin);
2475 }
34636400 2476
2d120f83 2477 XtVaSetValues ((Widget) m_scrolledWindow, XmNheight, h, NULL);
34636400 2478
2d120f83
JS
2479 Dimension spacing;
2480 Widget sbar;
2481 XtVaGetValues ((Widget) m_scrolledWindow,
2482 XmNspacing, &spacing,
2483 XmNhorizontalScrollBar, &sbar,
2484 NULL);
2485 Dimension wsbar;
2486 if (sbar)
2487 XtVaGetValues (sbar, XmNheight, &wsbar, NULL);
2488 else
2489 wsbar = 0;
34636400 2490
2d120f83 2491 h -= (spacing + wsbar);
34636400 2492
af0bb3b1
VZ
2493#if 0
2494 XtVaSetValues(drawingArea, XmNheight, h, NULL);
2495#endif // 0
2d120f83 2496 }
50414e24 2497 }
34636400 2498
2d120f83
JS
2499 if (managed)
2500 XtManageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
af0bb3b1 2501 XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
34636400
VZ
2502
2503#if 0
2d120f83
JS
2504 int ww, hh;
2505 GetClientSize (&ww, &hh);
2506 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2507 sizeEvent.SetEventObject(this);
34636400 2508
af0bb3b1 2509 GetEventHandler()->ProcessEvent(sizeEvent);
34636400 2510#endif // 0
50414e24
JS
2511}
2512
2513void wxWindow::CanvasSetClientSize (int w, int h)
2514{
2d120f83 2515 Widget drawingArea = (Widget) m_drawingArea;
34636400 2516
af0bb3b1 2517 XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
34636400 2518
2d120f83 2519 if (w > -1)
af0bb3b1 2520 XtVaSetValues(drawingArea, XmNwidth, w, NULL);
2d120f83 2521 if (h > -1)
af0bb3b1 2522 XtVaSetValues(drawingArea, XmNheight, h, NULL);
50414e24 2523
34636400
VZ
2524#if 0
2525 // TODO: is this necessary?
2526 allowRepainting = FALSE;
02e8b2f9 2527
34636400
VZ
2528 XSync (XtDisplay (drawingArea), FALSE);
2529 XEvent event;
2530 while (XtAppPending (wxTheApp->appContext))
2531 {
2532 XFlush (XtDisplay (drawingArea));
2533 XtAppNextEvent (wxTheApp->appContext, &event);
2534 XtDispatchEvent (&event);
02e8b2f9 2535 }
34636400
VZ
2536#endif // 0
2537
af0bb3b1 2538 XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
34636400
VZ
2539
2540#if 0
af0bb3b1
VZ
2541 allowRepainting = TRUE;
2542 DoRefresh ();
34636400 2543
af0bb3b1
VZ
2544 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2545 sizeEvent.SetEventObject(this);
34636400 2546
af0bb3b1 2547 GetEventHandler()->ProcessEvent(sizeEvent);
34636400 2548#endif // 0
02e8b2f9
JS
2549}
2550
34636400 2551void wxWindow::CanvasGetClientSize (int *w, int *h) const
02e8b2f9 2552{
34636400
VZ
2553 // Must return the same thing that was set via SetClientSize
2554 Dimension xx, yy;
2555 XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL);
2556 *w = xx;
2557 *h = yy;
02e8b2f9
JS
2558}
2559
34636400 2560void wxWindow::CanvasGetSize (int *w, int *h) const
02e8b2f9 2561{
34636400
VZ
2562 Dimension xx, yy;
2563 if ((Widget) m_borderWidget)
2564 XtVaGetValues ((Widget) m_borderWidget, XmNwidth, &xx, XmNheight, &yy, NULL);
2565 else if ((Widget) m_scrolledWindow)
2566 XtVaGetValues ((Widget) m_scrolledWindow, XmNwidth, &xx, XmNheight, &yy, NULL);
2567 else
2568 XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL);
2569
2570 *w = xx;
2571 *h = yy;
02e8b2f9
JS
2572}
2573
34636400 2574void wxWindow::CanvasGetPosition (int *x, int *y) const
47bc1060 2575{
34636400
VZ
2576 Position xx, yy;
2577 XtVaGetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, XmNx, &xx, XmNy, &yy, NULL);
2578
2579 // We may be faking the client origin.
2580 // So a window that's really at (0, 30) may appear
2581 // (to wxWin apps) to be at (0, 0).
2582 if (GetParent())
47bc1060 2583 {
34636400
VZ
2584 wxPoint pt(GetParent()->GetClientAreaOrigin());
2585 xx -= pt.x;
2586 yy -= pt.y;
47bc1060 2587 }
34636400
VZ
2588
2589 *x = xx;
2590 *y = yy;
47bc1060
JS
2591}
2592
34636400
VZ
2593// ----------------------------------------------------------------------------
2594// TranslateXXXEvent() functions
2595// ----------------------------------------------------------------------------
2596
02e8b2f9
JS
2597bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent)
2598{
2d120f83
JS
2599 switch (xevent->xany.type)
2600 {
1e8abce5
MB
2601 case EnterNotify: // never received here - yes ? MB
2602 case LeaveNotify: // never received here - yes ? MB
2603 case ButtonPress:
2604 case ButtonRelease:
2605 case MotionNotify:
02e8b2f9 2606 {
2d120f83 2607 wxEventType eventType = wxEVT_NULL;
34636400 2608
1e8abce5
MB
2609 // FIXME: this is never true I think - MB
2610 //
2d120f83
JS
2611 if (xevent->xany.type == LeaveNotify)
2612 {
af0bb3b1
VZ
2613 win->SetButton1(FALSE);
2614 win->SetButton2(FALSE);
2615 win->SetButton3(FALSE);
2d120f83
JS
2616 return FALSE;
2617 }
2618 else if (xevent->xany.type == MotionNotify)
2619 {
2620 eventType = wxEVT_MOTION;
2621 }
2622 else if (xevent->xany.type == ButtonPress)
2623 {
1e8abce5
MB
2624 wxevent.SetTimestamp(xevent->xbutton.time);
2625 int button = 0;
2d120f83
JS
2626 if (xevent->xbutton.button == Button1)
2627 {
2628 eventType = wxEVT_LEFT_DOWN;
af0bb3b1 2629 win->SetButton1(TRUE);
1e8abce5 2630 button = 1;
2d120f83
JS
2631 }
2632 else if (xevent->xbutton.button == Button2)
2633 {
2634 eventType = wxEVT_MIDDLE_DOWN;
af0bb3b1 2635 win->SetButton2(TRUE);
1e8abce5 2636 button = 2;
2d120f83
JS
2637 }
2638 else if (xevent->xbutton.button == Button3)
2639 {
2640 eventType = wxEVT_RIGHT_DOWN;
af0bb3b1 2641 win->SetButton3(TRUE);
1e8abce5
MB
2642 button = 3;
2643 }
2644
2645 // check for a double click
2646 //
2647 long dclickTime = XtGetMultiClickTime((Display*) wxGetDisplay());
2648 long ts = wxevent.GetTimestamp();
2649
2650 int buttonLast = win->GetLastClickedButton();
2651 long lastTS = win->GetLastClickTime();
2652 if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime )
2653 {
2654 // I have a dclick
2655 win->SetLastClick(0, ts);
205c0389
VZ
2656 if ( eventType == wxEVT_LEFT_DOWN )
2657 eventType = wxEVT_LEFT_DCLICK;
2658 else if ( eventType == wxEVT_MIDDLE_DOWN )
2659 eventType = wxEVT_MIDDLE_DCLICK;
2660 else if ( eventType == wxEVT_RIGHT_DOWN )
2661 eventType = wxEVT_RIGHT_DCLICK;
1e8abce5
MB
2662 }
2663 else
2664 {
2665 // not fast enough or different button
2666 win->SetLastClick(button, ts);
2d120f83
JS
2667 }
2668 }
2669 else if (xevent->xany.type == ButtonRelease)
2670 {
2671 if (xevent->xbutton.button == Button1)
2672 {
2673 eventType = wxEVT_LEFT_UP;
af0bb3b1 2674 win->SetButton1(FALSE);
2d120f83
JS
2675 }
2676 else if (xevent->xbutton.button == Button2)
2677 {
2678 eventType = wxEVT_MIDDLE_UP;
af0bb3b1 2679 win->SetButton2(FALSE);
2d120f83
JS
2680 }
2681 else if (xevent->xbutton.button == Button3)
2682 {
2683 eventType = wxEVT_RIGHT_UP;
af0bb3b1 2684 win->SetButton3(FALSE);
2d120f83
JS
2685 }
2686 else return FALSE;
2687 }
af0bb3b1
VZ
2688 else
2689 {
2690 return FALSE;
2691 }
34636400 2692
2d120f83 2693 wxevent.SetEventType(eventType);
34636400 2694
2d120f83
JS
2695 Position x1, y1;
2696 XtVaGetValues(widget, XmNx, &x1, XmNy, &y1, NULL);
34636400 2697
2d120f83
JS
2698 int x2, y2;
2699 win->GetPosition(&x2, &y2);
34636400 2700
2d120f83
JS
2701 // The button x/y must be translated to wxWindows
2702 // window space - the widget might be a label or button,
2703 // within a form.
2704 int dx = 0;
2705 int dy = 0;
2706 if (widget != (Widget)win->GetMainWidget())
2707 {
2708 dx = x1;
2709 dy = y1;
2710 }
34636400 2711
2d120f83
JS
2712 wxevent.m_x = xevent->xbutton.x + dx;
2713 wxevent.m_y = xevent->xbutton.y + dy;
34636400 2714
2d120f83 2715 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
34636400 2716 || (event_left_is_down (xevent)
2d120f83
JS
2717 && (eventType != wxEVT_LEFT_UP)));
2718 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
34636400 2719 || (event_middle_is_down (xevent)
2d120f83
JS
2720 && (eventType != wxEVT_MIDDLE_UP)));
2721 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
34636400 2722 || (event_right_is_down (xevent)
2d120f83 2723 && (eventType != wxEVT_RIGHT_UP)));
34636400 2724
2d120f83
JS
2725 wxevent.m_shiftDown = xevent->xbutton.state & ShiftMask;
2726 wxevent.m_controlDown = xevent->xbutton.state & ControlMask;
1e8abce5
MB
2727 wxevent.m_altDown = xevent->xbutton.state & Mod3Mask;
2728 wxevent.m_metaDown = xevent->xbutton.state & Mod1Mask;
2729
2730 wxevent.SetId(win->GetId());
2731 wxevent.SetEventObject(win);
2732
2d120f83
JS
2733 return TRUE;
2734 }
02e8b2f9 2735 }
2d120f83 2736 return FALSE;
02e8b2f9
JS
2737}
2738
af111fc3 2739bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget WXUNUSED(widget), XEvent *xevent)
02e8b2f9 2740{
2d120f83
JS
2741 switch (xevent->xany.type)
2742 {
02e8b2f9 2743 case KeyPress:
4a041f2f 2744 case KeyRelease:
2d120f83
JS
2745 {
2746 char buf[20];
34636400 2747
2d120f83 2748 KeySym keySym;
34636400
VZ
2749#if 0
2750 XComposeStatus compose;
2751 (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
2752#endif // 0
2d120f83
JS
2753 (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL);
2754 int id = wxCharCodeXToWX (keySym);
34636400 2755
2d120f83
JS
2756 if (xevent->xkey.state & ShiftMask)
2757 wxevent.m_shiftDown = TRUE;
2758 if (xevent->xkey.state & ControlMask)
2759 wxevent.m_controlDown = TRUE;
2760 if (xevent->xkey.state & Mod3Mask)
2761 wxevent.m_altDown = TRUE;
2762 if (xevent->xkey.state & Mod1Mask)
2763 wxevent.m_metaDown = TRUE;
2764 wxevent.SetEventObject(win);
2765 wxevent.m_keyCode = id;
2766 wxevent.SetTimestamp(xevent->xkey.time);
34636400 2767
2d120f83
JS
2768 wxevent.m_x = xevent->xbutton.x;
2769 wxevent.m_y = xevent->xbutton.y;
34636400 2770
2d120f83
JS
2771 if (id > -1)
2772 return TRUE;
2773 else
2774 return FALSE;
2775 break;
2776 }
02e8b2f9 2777 default:
2d120f83
JS
2778 break;
2779 }
2780 return FALSE;
02e8b2f9
JS
2781}
2782
34636400
VZ
2783// ----------------------------------------------------------------------------
2784// Colour stuff
2785// ----------------------------------------------------------------------------
2786
02e8b2f9 2787#define YAllocColor XAllocColor
0d57be45
JS
2788XColor g_itemColors[5];
2789int wxComputeColours (Display *display, wxColour * back, wxColour * fore)
02e8b2f9 2790{
2d120f83
JS
2791 int result;
2792 static XmColorProc colorProc;
34636400 2793
2d120f83 2794 result = wxNO_COLORS;
34636400 2795
2d120f83 2796 if (back)
02e8b2f9 2797 {
2d120f83
JS
2798 g_itemColors[0].red = (((long) back->Red ()) << 8);
2799 g_itemColors[0].green = (((long) back->Green ()) << 8);
2800 g_itemColors[0].blue = (((long) back->Blue ()) << 8);
2801 g_itemColors[0].flags = DoRed | DoGreen | DoBlue;
2802 if (colorProc == (XmColorProc) NULL)
2803 {
2804 // Get a ptr to the actual function
2805 colorProc = XmSetColorCalculation ((XmColorProc) NULL);
2806 // And set it back to motif.
2807 XmSetColorCalculation (colorProc);
2808 }
2809 (*colorProc) (&g_itemColors[wxBACK_INDEX],
2810 &g_itemColors[wxFORE_INDEX],
2811 &g_itemColors[wxSELE_INDEX],
2812 &g_itemColors[wxTOPS_INDEX],
2813 &g_itemColors[wxBOTS_INDEX]);
2814 result = wxBACK_COLORS;
02e8b2f9 2815 }
2d120f83 2816 if (fore)
02e8b2f9 2817 {
2d120f83
JS
2818 g_itemColors[wxFORE_INDEX].red = (((long) fore->Red ()) << 8);
2819 g_itemColors[wxFORE_INDEX].green = (((long) fore->Green ()) << 8);
2820 g_itemColors[wxFORE_INDEX].blue = (((long) fore->Blue ()) << 8);
2821 g_itemColors[wxFORE_INDEX].flags = DoRed | DoGreen | DoBlue;
2822 if (result == wxNO_COLORS)
2823 result = wxFORE_COLORS;
02e8b2f9 2824 }
34636400 2825
2d120f83
JS
2826 Display *dpy = display;
2827 Colormap cmap = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) dpy);
34636400 2828
2d120f83 2829 if (back)
02e8b2f9 2830 {
2d120f83
JS
2831 /* 5 Colours to allocate */
2832 for (int i = 0; i < 5; i++)
2833 if (!YAllocColor (dpy, cmap, &g_itemColors[i]))
2834 result = wxNO_COLORS;
02e8b2f9 2835 }
2d120f83 2836 else if (fore)
02e8b2f9 2837 {
2d120f83
JS
2838 /* Only 1 colour to allocate */
2839 if (!YAllocColor (dpy, cmap, &g_itemColors[wxFORE_INDEX]))
2840 result = wxNO_COLORS;
02e8b2f9 2841 }
34636400 2842
2d120f83 2843 return (result);
34636400 2844
02e8b2f9
JS
2845}
2846
34636400
VZ
2847// Changes the foreground and background colours to be derived from the current
2848// background colour. To change the foreground colour, you must call
2849// SetForegroundColour explicitly.
0d57be45 2850void wxWindow::ChangeBackgroundColour()
02e8b2f9 2851{
34636400
VZ
2852 WXWidget mainWidget = GetMainWidget();
2853 if ( mainWidget )
2854 DoChangeBackgroundColour(mainWidget, m_backgroundColour);
2855
b412f9be
JS
2856 // This not necessary
2857#if 0
34636400 2858
88150e60 2859 if (m_scrolledWindow && (GetMainWidget() != m_scrolledWindow))
b412f9be 2860 {
88150e60 2861 DoChangeBackgroundColour(m_scrolledWindow, m_backgroundColour);
b412f9be
JS
2862 // Have to set the scrollbar colours back since
2863 // the scrolled window seemed to change them
a756f210 2864 wxColour backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
34636400 2865
b412f9be 2866 if (m_hScrollBar)
2d120f83 2867 DoChangeBackgroundColour(m_hScrollBar, backgroundColour);
b412f9be 2868 if (m_vScrollBar)
2d120f83 2869 DoChangeBackgroundColour(m_vScrollBar, backgroundColour);
b412f9be
JS
2870 }
2871#endif
0d57be45 2872}
02e8b2f9 2873
0d57be45
JS
2874void wxWindow::ChangeForegroundColour()
2875{
34636400
VZ
2876 WXWidget mainWidget = GetMainWidget();
2877 if ( mainWidget )
2878 DoChangeForegroundColour(mainWidget, m_foregroundColour);
2879 if ( m_scrolledWindow && mainWidget != m_scrolledWindow )
88150e60 2880 DoChangeForegroundColour(m_scrolledWindow, m_foregroundColour);
0d57be45 2881}
02e8b2f9 2882
0d57be45 2883// Change a widget's foreground and background colours.
0d57be45
JS
2884void wxWindow::DoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour)
2885{
2d120f83
JS
2886 // When should we specify the foreground, if it's calculated
2887 // by wxComputeColours?
2888 // Solution: say we start with the default (computed) foreground colour.
2889 // If we call SetForegroundColour explicitly for a control or window,
2890 // then the foreground is changed.
2891 // Therefore SetBackgroundColour computes the foreground colour, and
2892 // SetForegroundColour changes the foreground colour. The ordering is
2893 // important.
34636400
VZ
2894
2895 Widget w = (Widget)widget;
2896 XtVaSetValues(
2897 w,
2898 XmNforeground, foregroundColour.AllocColour(XtDisplay(w)),
2899 NULL
2900 );
0d57be45
JS
2901}
2902
2903void wxWindow::DoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour)
2904{
2d120f83
JS
2905 wxComputeColours (XtDisplay((Widget) widget), & backgroundColour,
2906 (wxColour*) NULL);
34636400 2907
0d57be45 2908 XtVaSetValues ((Widget) widget,
2d120f83
JS
2909 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
2910 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
2911 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
2912 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
2913 NULL);
34636400 2914
2d120f83
JS
2915 if (changeArmColour)
2916 XtVaSetValues ((Widget) widget,
2917 XmNarmColor, g_itemColors[wxSELE_INDEX].pixel,
2918 NULL);
02e8b2f9
JS
2919}
2920
af0bb3b1 2921bool wxWindow::SetBackgroundColour(const wxColour& col)
02e8b2f9 2922{
af0bb3b1
VZ
2923 if ( !wxWindowBase::SetBackgroundColour(col) )
2924 return FALSE;
2925
0d57be45 2926 ChangeBackgroundColour();
af0bb3b1
VZ
2927
2928 return TRUE;
0d57be45
JS
2929}
2930
af0bb3b1 2931bool wxWindow::SetForegroundColour(const wxColour& col)
0d57be45 2932{
af0bb3b1
VZ
2933 if ( !wxWindowBase::SetForegroundColour(col) )
2934 return FALSE;
2935
0d57be45 2936 ChangeForegroundColour();
af0bb3b1
VZ
2937
2938 return TRUE;
0d57be45
JS
2939}
2940
4b5f3fe6 2941void wxWindow::ChangeFont(bool keepOriginalSize)
0d57be45
JS
2942{
2943 // Note that this causes the widget to be resized back
2944 // to its original size! We therefore have to set the size
2945 // back again. TODO: a better way in Motif?
0d57be45 2946 Widget w = (Widget) GetLabelWidget(); // Usually the main widget
af0bb3b1 2947 if (w && m_font.Ok())
0d57be45
JS
2948 {
2949 int width, height, width1, height1;
2950 GetSize(& width, & height);
34636400 2951
2d120f83 2952 // lesstif 0.87 hangs here
34636400 2953#ifndef LESSTIF_VERSION
0d57be45 2954 XtVaSetValues (w,
af0bb3b1 2955 XmNfontList, (XmFontList) m_font.GetFontList(1.0, XtDisplay(w)),
2d120f83 2956 NULL);
32c69f2c 2957#endif
34636400 2958
0d57be45 2959 GetSize(& width1, & height1);
4b5f3fe6 2960 if (keepOriginalSize && (width != width1 || height != height1))
0d57be45
JS
2961 {
2962 SetSize(-1, -1, width, height);
2963 }
2964 }
02e8b2f9 2965}
0d57be45 2966
34636400
VZ
2967// ----------------------------------------------------------------------------
2968// global functions
2969// ----------------------------------------------------------------------------
0d57be45 2970
34636400 2971wxWindow *wxGetActiveWindow()
1f112209
JS
2972{
2973 // TODO
9b8f6fa2 2974 wxFAIL_MSG("Not implemented");
34636400 2975 return NULL;
1f112209
JS
2976}
2977
9806a47c
JS
2978/* static */
2979wxWindow *wxWindowBase::GetCapture()
2980{
2981 return (wxWindow *)g_captureWindow;
2982}
2983
2984
3723b7b1
JS
2985// Find the wxWindow at the current mouse position, returning the mouse
2986// position.
2987wxWindow* wxFindWindowAtPointer(wxPoint& pt)
2988{
57591e0e 2989 return wxFindWindowAtPoint(wxGetMousePosition());
3723b7b1
JS
2990}
2991
2992// Get the current mouse position.
2993wxPoint wxGetMousePosition()
2994{
59a12e90
JS
2995 Display *display = (Display*) wxGetDisplay();
2996 Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display));
2997 Window rootReturn, childReturn;
2998 int rootX, rootY, winX, winY;
2999 unsigned int maskReturn;
3000
3001 XQueryPointer (display,
3002 rootWindow,
3003 &rootReturn,
3004 &childReturn,
3005 &rootX, &rootY, &winX, &winY, &maskReturn);
3006 return wxPoint(rootX, rootY);
3723b7b1
JS
3007}
3008
9806a47c 3009
34636400
VZ
3010// ----------------------------------------------------------------------------
3011// wxNoOptimize: switch off size optimization
3012// ----------------------------------------------------------------------------
88150e60 3013
af0bb3b1 3014int wxNoOptimize::ms_count = 0;
311227c3 3015