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