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