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