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