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