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