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