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