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