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