]>
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "window.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/setup.h" | |
17 | #include "wx/menu.h" | |
18 | #include "wx/dc.h" | |
19 | #include "wx/dcclient.h" | |
20 | #include "wx/utils.h" | |
21 | #include "wx/app.h" | |
22 | #include "wx/panel.h" | |
23 | #include "wx/layout.h" | |
24 | #include "wx/dialog.h" | |
25 | #include "wx/listbox.h" | |
26 | #include "wx/button.h" | |
27 | #include "wx/settings.h" | |
28 | #include "wx/msgdlg.h" | |
29 | #include "wx/frame.h" | |
30 | ||
31 | #include "wx/menuitem.h" | |
32 | #include "wx/log.h" | |
33 | ||
47d67540 | 34 | #if wxUSE_DRAG_AND_DROP |
4bb6408c JS |
35 | #include "wx/dnd.h" |
36 | #endif | |
37 | ||
38 | #include <Xm/Xm.h> | |
50414e24 JS |
39 | |
40 | #include <Xm/DrawingA.h> | |
41 | #include <Xm/ScrolledW.h> | |
42 | #include <Xm/ScrollBar.h> | |
43 | #include <Xm/Frame.h> | |
44 | #include <Xm/Label.h> | |
45 | ||
4bb6408c JS |
46 | #include "wx/motif/private.h" |
47 | ||
48 | #include <string.h> | |
49 | ||
50414e24 JS |
50 | #define SCROLL_MARGIN 4 |
51 | void wxCanvasRepaintProc (Widget, XtPointer, XmDrawingAreaCallbackStruct * cbs); | |
52 | void wxCanvasInputEvent (Widget drawingArea, XtPointer data, XmDrawingAreaCallbackStruct * cbs); | |
53 | void wxCanvasMotionEvent (Widget, XButtonEvent * event); | |
54 | void wxCanvasEnterLeave (Widget drawingArea, XtPointer clientData, XCrossingEvent * event); | |
8aa04e8b | 55 | static void wxScrollBarCallback(Widget widget, XtPointer clientData, |
47bc1060 | 56 | XmScaleCallbackStruct *cbs); |
02e8b2f9 JS |
57 | void wxPanelItemEventHandler (Widget wid, |
58 | XtPointer client_data, | |
59 | XEvent* event, | |
60 | Boolean *continueToDispatch); | |
50414e24 JS |
61 | |
62 | #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask) | |
63 | #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask) | |
64 | #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask) | |
65 | ||
4bb6408c JS |
66 | extern wxList wxPendingDelete; |
67 | ||
68 | #if !USE_SHARED_LIBRARY | |
69 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) | |
70 | ||
71 | BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) | |
72 | EVT_CHAR(wxWindow::OnChar) | |
73 | EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) | |
74 | EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) | |
75 | EVT_INIT_DIALOG(wxWindow::OnInitDialog) | |
76 | EVT_IDLE(wxWindow::OnIdle) | |
77 | END_EVENT_TABLE() | |
78 | ||
79 | #endif | |
80 | ||
81 | ||
82 | // Constructor | |
83 | wxWindow::wxWindow() | |
84 | { | |
85 | // Generic | |
86 | m_windowId = 0; | |
87 | m_windowStyle = 0; | |
88 | m_windowParent = NULL; | |
89 | m_windowEventHandler = this; | |
90 | m_windowName = ""; | |
91 | m_windowCursor = *wxSTANDARD_CURSOR; | |
92 | m_children = new wxList; | |
93 | m_constraints = NULL; | |
94 | m_constraintsInvolvedIn = NULL; | |
95 | m_windowSizer = NULL; | |
96 | m_sizerParent = NULL; | |
97 | m_autoLayout = FALSE; | |
98 | m_windowValidator = NULL; | |
99 | m_defaultItem = NULL; | |
100 | m_returnCode = 0; | |
101 | m_caretWidth = 0; m_caretHeight = 0; | |
102 | m_caretEnabled = FALSE; | |
103 | m_caretShown = FALSE; | |
fd71308f JS |
104 | // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; |
105 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; | |
4bb6408c | 106 | m_foregroundColour = *wxBLACK; |
4bb6408c | 107 | |
47d67540 | 108 | #if wxUSE_DRAG_AND_DROP |
4bb6408c JS |
109 | m_pDropTarget = NULL; |
110 | #endif | |
3dd4e4e0 JS |
111 | m_clientObject = (wxClientData*) NULL; |
112 | m_clientData = NULL; | |
4bb6408c | 113 | |
50414e24 | 114 | /// Motif-specific |
4bb6408c JS |
115 | m_mainWidget = (WXWidget) 0; |
116 | m_button1Pressed = FALSE; | |
117 | m_button2Pressed = FALSE; | |
118 | m_button3Pressed = FALSE; | |
119 | m_winCaptured = FALSE; | |
120 | m_isShown = TRUE; | |
50414e24 JS |
121 | m_hScrollBar = (WXWidget) 0; |
122 | m_vScrollBar = (WXWidget) 0; | |
123 | m_borderWidget = (WXWidget) 0; | |
124 | m_scrolledWindow = (WXWidget) 0; | |
125 | m_drawingArea = (WXWidget) 0; | |
126 | m_hScroll = FALSE; | |
127 | m_vScroll = FALSE; | |
50414e24 JS |
128 | m_backingPixmap = (WXPixmap) 0; |
129 | m_pixmapWidth = 0; | |
130 | m_pixmapHeight = 0; | |
131 | m_pixmapOffsetX = 0; | |
132 | m_pixmapOffsetY = 0; | |
133 | m_lastTS = 0; | |
134 | m_lastButton = 0; | |
02e8b2f9 | 135 | m_canAddEventHandler = FALSE; |
47bc1060 JS |
136 | m_scrollPosX = 0; |
137 | m_scrollPosY = 0; | |
4bb6408c JS |
138 | } |
139 | ||
140 | // Destructor | |
141 | wxWindow::~wxWindow() | |
142 | { | |
f97c9854 | 143 | //// Motif-specific |
50414e24 | 144 | |
f97c9854 JS |
145 | if (GetMainWidget()) |
146 | DetachWidget(GetMainWidget()); // Removes event handlers | |
02e8b2f9 | 147 | |
f97c9854 JS |
148 | // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be) |
149 | if (m_drawingArea) | |
150 | { | |
151 | // Destroy children before destroying self | |
152 | DestroyChildren(); | |
50414e24 | 153 | |
f97c9854 JS |
154 | if (m_backingPixmap) |
155 | XFreePixmap (XtDisplay ((Widget) GetMainWidget()), (Pixmap) m_backingPixmap); | |
50414e24 | 156 | |
f97c9854 JS |
157 | Widget w = (Widget) m_drawingArea; |
158 | wxDeleteWindowFromTable(w); | |
50414e24 | 159 | |
f97c9854 JS |
160 | if (w) |
161 | XtDestroyWidget(w); | |
162 | m_mainWidget = (WXWidget) 0; | |
50414e24 | 163 | |
f97c9854 JS |
164 | // Only if we're _really_ a canvas (not a dialog box/panel) |
165 | if (m_scrolledWindow) | |
166 | { | |
167 | wxDeleteWindowFromTable((Widget) m_scrolledWindow); | |
168 | } | |
50414e24 | 169 | |
f97c9854 JS |
170 | if (m_hScrollBar) |
171 | { | |
172 | XtUnmanageChild ((Widget) m_hScrollBar); | |
173 | XtDestroyWidget ((Widget) m_hScrollBar); | |
174 | } | |
175 | if (m_vScrollBar) | |
176 | { | |
177 | XtUnmanageChild ((Widget) m_vScrollBar); | |
178 | XtDestroyWidget ((Widget) m_vScrollBar); | |
179 | } | |
180 | if (m_scrolledWindow) | |
181 | { | |
182 | XtUnmanageChild ((Widget) m_scrolledWindow); | |
183 | XtDestroyWidget ((Widget) m_scrolledWindow); | |
184 | } | |
50414e24 | 185 | |
f97c9854 JS |
186 | if (m_borderWidget) |
187 | { | |
188 | XtDestroyWidget ((Widget) m_borderWidget); | |
189 | m_borderWidget = (WXWidget) 0; | |
190 | } | |
50414e24 | 191 | } |
50414e24 | 192 | |
f97c9854 | 193 | //// Generic stuff |
50414e24 | 194 | |
4bb6408c JS |
195 | // Have to delete constraints/sizer FIRST otherwise |
196 | // sizers may try to look at deleted windows as they | |
197 | // delete themselves. | |
47d67540 | 198 | #if wxUSE_CONSTRAINTS |
4bb6408c JS |
199 | DeleteRelatedConstraints(); |
200 | if (m_constraints) | |
201 | { | |
202 | // This removes any dangling pointers to this window | |
203 | // in other windows' constraintsInvolvedIn lists. | |
204 | UnsetConstraints(m_constraints); | |
205 | delete m_constraints; | |
206 | m_constraints = NULL; | |
207 | } | |
208 | if (m_windowSizer) | |
209 | { | |
210 | delete m_windowSizer; | |
211 | m_windowSizer = NULL; | |
212 | } | |
213 | // If this is a child of a sizer, remove self from parent | |
214 | if (m_sizerParent) | |
215 | m_sizerParent->RemoveChild((wxWindow *)this); | |
216 | #endif | |
217 | ||
218 | if (m_windowParent) | |
219 | m_windowParent->RemoveChild(this); | |
220 | ||
221 | DestroyChildren(); | |
222 | ||
223 | // Destroy the window | |
224 | if (GetMainWidget()) | |
225 | { | |
226 | wxDeleteWindowFromTable((Widget) GetMainWidget()); | |
227 | XtDestroyWidget((Widget) GetMainWidget()); | |
228 | SetMainWidget((WXWidget) NULL); | |
229 | } | |
230 | ||
231 | delete m_children; | |
232 | m_children = NULL; | |
233 | ||
234 | // Just in case the window has been Closed, but | |
235 | // we're then deleting immediately: don't leave | |
236 | // dangling pointers. | |
237 | wxPendingDelete.DeleteObject(this); | |
238 | ||
3dd4e4e0 JS |
239 | if ( m_windowValidator ) delete m_windowValidator; |
240 | if (m_clientObject) delete m_clientObject; | |
55acd85e JS |
241 | |
242 | ClearUpdateRects(); | |
4bb6408c JS |
243 | } |
244 | ||
245 | // Destroy the window (delayed, if a managed window) | |
246 | bool wxWindow::Destroy() | |
247 | { | |
248 | delete this; | |
249 | return TRUE; | |
250 | } | |
251 | ||
252 | // Constructor | |
253 | bool wxWindow::Create(wxWindow *parent, wxWindowID id, | |
254 | const wxPoint& pos, | |
255 | const wxSize& size, | |
256 | long style, | |
257 | const wxString& name) | |
258 | { | |
259 | // Generic | |
260 | m_windowId = 0; | |
261 | m_windowStyle = 0; | |
262 | m_windowParent = NULL; | |
263 | m_windowEventHandler = this; | |
264 | m_windowName = ""; | |
265 | m_windowCursor = *wxSTANDARD_CURSOR; | |
266 | m_constraints = NULL; | |
267 | m_constraintsInvolvedIn = NULL; | |
268 | m_windowSizer = NULL; | |
269 | m_sizerParent = NULL; | |
270 | m_autoLayout = FALSE; | |
271 | m_windowValidator = NULL; | |
47d67540 | 272 | #if wxUSE_DRAG_AND_DROP |
4bb6408c JS |
273 | m_pDropTarget = NULL; |
274 | #endif | |
4bb6408c JS |
275 | m_caretWidth = 0; m_caretHeight = 0; |
276 | m_caretEnabled = FALSE; | |
277 | m_caretShown = FALSE; | |
278 | m_minSizeX = -1; | |
279 | m_minSizeY = -1; | |
280 | m_maxSizeX = -1; | |
281 | m_maxSizeY = -1; | |
282 | m_defaultItem = NULL; | |
283 | m_windowParent = NULL; | |
3dd4e4e0 JS |
284 | m_clientObject = (wxClientData*) NULL; |
285 | m_clientData = NULL; | |
50414e24 JS |
286 | |
287 | // Motif-specific | |
02e8b2f9 | 288 | m_canAddEventHandler = FALSE; |
50414e24 JS |
289 | m_mainWidget = (WXWidget) 0; |
290 | m_button1Pressed = FALSE; | |
291 | m_button2Pressed = FALSE; | |
292 | m_button3Pressed = FALSE; | |
293 | m_winCaptured = FALSE; | |
294 | m_isShown = TRUE; | |
295 | m_hScrollBar = (WXWidget) 0; | |
296 | m_vScrollBar = (WXWidget) 0; | |
297 | m_borderWidget = (WXWidget) 0; | |
298 | m_scrolledWindow = (WXWidget) 0; | |
299 | m_drawingArea = (WXWidget) 0; | |
300 | m_hScroll = FALSE; | |
301 | m_vScroll = FALSE; | |
50414e24 JS |
302 | m_backingPixmap = (WXPixmap) 0; |
303 | m_pixmapWidth = 0; | |
304 | m_pixmapHeight = 0; | |
305 | m_pixmapOffsetX = 0; | |
306 | m_pixmapOffsetY = 0; | |
47bc1060 JS |
307 | m_scrollPosX = 0; |
308 | m_scrollPosY = 0; | |
50414e24 | 309 | |
4bb6408c JS |
310 | if (!parent) |
311 | return FALSE; | |
312 | ||
313 | if (parent) parent->AddChild(this); | |
314 | ||
315 | m_returnCode = 0; | |
316 | ||
317 | SetName(name); | |
318 | ||
319 | if ( id == -1 ) | |
320 | m_windowId = (int)NewControlId(); | |
321 | else | |
322 | m_windowId = id; | |
323 | ||
fd71308f JS |
324 | // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; |
325 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; | |
4bb6408c | 326 | m_foregroundColour = *wxBLACK; |
4bb6408c JS |
327 | |
328 | m_windowStyle = style; | |
329 | ||
330 | if ( id == -1 ) | |
331 | m_windowId = (int)NewControlId(); | |
332 | else | |
333 | m_windowId = id; | |
334 | ||
50414e24 JS |
335 | //// TODO: we should probably optimize by only creating a |
336 | //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL). | |
337 | //// But for now, let's simplify things by always creating the | |
338 | //// drawing area, since otherwise the translations are different. | |
339 | ||
340 | // New translations for getting mouse motion feedback | |
341 | String translations = | |
342 | "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\ | |
343 | <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\ | |
344 | <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\ | |
345 | <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\ | |
346 | <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\ | |
347 | <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\ | |
348 | <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\ | |
349 | <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\ | |
350 | <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\ | |
351 | <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\ | |
352 | <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\ | |
353 | <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\ | |
354 | <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\ | |
355 | <Key>: DrawingAreaInput()"; | |
356 | ||
357 | XtActionsRec actions[1]; | |
358 | actions[0].string = "wxCanvasMotionEvent"; | |
359 | actions[0].proc = (XtActionProc) wxCanvasMotionEvent; | |
360 | XtAppAddActions ((XtAppContext) wxTheApp->GetAppContext(), actions, 1); | |
361 | ||
362 | Widget parentWidget = (Widget) parent->GetClientWidget(); | |
363 | if (style & wxBORDER) | |
364 | m_borderWidget = (WXWidget) XtVaCreateManagedWidget ("canvasBorder", | |
365 | xmFrameWidgetClass, parentWidget, | |
366 | XmNshadowType, XmSHADOW_IN, | |
367 | NULL); | |
368 | ||
369 | m_scrolledWindow = (WXWidget) XtVaCreateManagedWidget ("scrolledWindow", | |
370 | xmScrolledWindowWidgetClass, m_borderWidget ? (Widget) m_borderWidget : parentWidget, | |
371 | XmNspacing, 0, | |
372 | XmNscrollingPolicy, XmAPPLICATION_DEFINED, | |
373 | NULL); | |
374 | ||
375 | XtTranslations ptr; | |
376 | m_drawingArea = (WXWidget) XtVaCreateWidget ((char*) (const char*) name, | |
377 | xmDrawingAreaWidgetClass, (Widget) m_scrolledWindow, | |
378 | XmNunitType, XmPIXELS, | |
379 | // XmNresizePolicy, XmRESIZE_ANY, | |
380 | XmNresizePolicy, XmRESIZE_NONE, | |
381 | XmNmarginHeight, 0, | |
382 | XmNmarginWidth, 0, | |
383 | XmNtranslations, ptr = XtParseTranslationTable (translations), | |
384 | NULL); | |
385 | /* | |
386 | if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS) | |
387 | { | |
388 | XtFree ((char *) ptr); | |
389 | ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()"); | |
390 | XtOverrideTranslations ((Widget) m_drawingArea, ptr); | |
391 | XtFree ((char *) ptr); | |
392 | } | |
393 | */ | |
394 | ||
395 | wxAddWindowToTable((Widget) m_drawingArea, this); | |
396 | wxAddWindowToTable((Widget) m_scrolledWindow, this); | |
397 | ||
398 | /* | |
399 | * This order is very important in Motif 1.2.1 | |
400 | * | |
401 | */ | |
402 | ||
403 | XtRealizeWidget ((Widget) m_scrolledWindow); | |
404 | XtRealizeWidget ((Widget) m_drawingArea); | |
405 | XtManageChild ((Widget) m_drawingArea); | |
406 | ||
407 | XtOverrideTranslations ((Widget) m_drawingArea, | |
408 | ptr = XtParseTranslationTable ("<Configure>: resize()")); | |
409 | XtFree ((char *) ptr); | |
410 | ||
411 | XtAddCallback ((Widget) m_drawingArea, XmNexposeCallback, (XtCallbackProc) wxCanvasRepaintProc, (XtPointer) this); | |
412 | XtAddCallback ((Widget) m_drawingArea, XmNinputCallback, (XtCallbackProc) wxCanvasInputEvent, (XtPointer) this); | |
413 | ||
414 | /* TODO? | |
415 | display = XtDisplay (scrolledWindow); | |
416 | xwindow = XtWindow (drawingArea); | |
417 | */ | |
418 | ||
419 | XtAddEventHandler ((Widget) m_drawingArea, PointerMotionHintMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask, | |
420 | False, (XtEventHandler) wxCanvasEnterLeave, (XtPointer) this); | |
4bb6408c | 421 | |
47bc1060 JS |
422 | // Add scrollbars if required |
423 | if (m_windowStyle & wxHSCROLL) | |
424 | { | |
425 | Widget hScrollBar = XtVaCreateManagedWidget ("hsb", | |
426 | xmScrollBarWidgetClass, (Widget) m_scrolledWindow, | |
427 | XmNorientation, XmHORIZONTAL, | |
428 | NULL); | |
429 | // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
430 | XtAddCallback (hScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
431 | XtAddCallback (hScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
432 | XtAddCallback (hScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
433 | XtAddCallback (hScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
434 | XtAddCallback (hScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
435 | XtAddCallback (hScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
436 | XtAddCallback (hScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
437 | ||
438 | XtVaSetValues (hScrollBar, | |
439 | XmNincrement, 1, | |
440 | XmNvalue, 0, | |
441 | NULL); | |
442 | ||
443 | m_hScrollBar = (WXWidget) hScrollBar; | |
444 | m_hScroll = TRUE; | |
445 | } | |
446 | if (m_windowStyle & wxVSCROLL) | |
447 | { | |
448 | Widget vScrollBar = XtVaCreateManagedWidget ("vsb", | |
449 | xmScrollBarWidgetClass, (Widget) m_scrolledWindow, | |
450 | XmNorientation, XmVERTICAL, | |
451 | NULL); | |
452 | // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
453 | XtAddCallback (vScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
454 | XtAddCallback (vScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
455 | XtAddCallback (vScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
456 | XtAddCallback (vScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
457 | XtAddCallback (vScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
458 | XtAddCallback (vScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
459 | XtAddCallback (vScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
460 | ||
461 | XtVaSetValues (vScrollBar, | |
462 | XmNincrement, 1, | |
463 | XmNvalue, 0, | |
464 | NULL); | |
465 | ||
466 | m_vScrollBar = (WXWidget) vScrollBar; | |
467 | m_vScroll = TRUE; | |
468 | } | |
469 | ||
470 | if (m_hScrollBar || m_vScrollBar) | |
471 | XmScrolledWindowSetAreas ((Widget) m_scrolledWindow, (Widget) m_hScrollBar, (Widget) m_vScrollBar, (Widget) m_drawingArea); | |
472 | ||
473 | if (m_hScrollBar) | |
474 | XtRealizeWidget ((Widget) m_hScrollBar); | |
475 | if (m_vScrollBar) | |
476 | XtRealizeWidget ((Widget) m_vScrollBar); | |
477 | ||
a4294b78 JS |
478 | // Without this, the cursor may not be restored properly |
479 | // (e.g. in splitter sample). | |
480 | SetCursor(*wxSTANDARD_CURSOR); | |
e97f20a0 JS |
481 | SetSize(pos.x, pos.y, size.x, size.y); |
482 | ||
483 | return TRUE; | |
4bb6408c JS |
484 | } |
485 | ||
486 | void wxWindow::SetFocus() | |
487 | { | |
488 | XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT); | |
489 | XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT); | |
490 | } | |
491 | ||
492 | void wxWindow::Enable(bool enable) | |
493 | { | |
494 | if (GetMainWidget()) | |
495 | { | |
496 | XtSetSensitive((Widget) GetMainWidget(), enable); | |
497 | XmUpdateDisplay((Widget) GetMainWidget()); | |
498 | } | |
499 | } | |
500 | ||
501 | void wxWindow::CaptureMouse() | |
502 | { | |
503 | if (m_winCaptured) | |
504 | return; | |
505 | ||
506 | if (GetMainWidget()) | |
507 | XtAddGrab((Widget) GetMainWidget(), TRUE, FALSE); | |
508 | ||
509 | m_winCaptured = TRUE; | |
510 | } | |
511 | ||
512 | void wxWindow::ReleaseMouse() | |
513 | { | |
514 | if (!m_winCaptured) | |
515 | return; | |
516 | ||
517 | if (GetMainWidget()) | |
518 | XtRemoveGrab((Widget) GetMainWidget()); | |
519 | m_winCaptured = FALSE; | |
520 | } | |
521 | ||
522 | // Push/pop event handler (i.e. allow a chain of event handlers | |
523 | // be searched) | |
524 | void wxWindow::PushEventHandler(wxEvtHandler *handler) | |
525 | { | |
526 | handler->SetNextHandler(GetEventHandler()); | |
527 | SetEventHandler(handler); | |
528 | } | |
529 | ||
530 | wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler) | |
531 | { | |
532 | if ( GetEventHandler() ) | |
533 | { | |
534 | wxEvtHandler *handlerA = GetEventHandler(); | |
535 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
536 | handlerA->SetNextHandler(NULL); | |
537 | SetEventHandler(handlerB); | |
538 | if ( deleteHandler ) | |
539 | { | |
540 | delete handlerA; | |
541 | return NULL; | |
542 | } | |
543 | else | |
544 | return handlerA; | |
545 | } | |
546 | else | |
547 | return NULL; | |
548 | } | |
549 | ||
47d67540 | 550 | #if wxUSE_DRAG_AND_DROP |
4bb6408c JS |
551 | |
552 | void wxWindow::SetDropTarget(wxDropTarget *pDropTarget) | |
553 | { | |
554 | if ( m_pDropTarget != 0 ) { | |
555 | delete m_pDropTarget; | |
556 | } | |
557 | ||
558 | m_pDropTarget = pDropTarget; | |
559 | if ( m_pDropTarget != 0 ) | |
560 | { | |
561 | // TODO | |
562 | } | |
563 | } | |
564 | ||
565 | #endif | |
566 | ||
567 | // Old style file-manager drag&drop | |
568 | void wxWindow::DragAcceptFiles(bool accept) | |
569 | { | |
570 | // TODO | |
571 | } | |
572 | ||
573 | // Get total size | |
574 | void wxWindow::GetSize(int *x, int *y) const | |
575 | { | |
50414e24 JS |
576 | if (m_drawingArea) |
577 | { | |
578 | CanvasGetSize(x, y); | |
579 | return; | |
580 | } | |
581 | ||
02e8b2f9 | 582 | Widget widget = (Widget) GetTopWidget(); |
4bb6408c JS |
583 | Dimension xx, yy; |
584 | XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL); | |
585 | *x = xx; *y = yy; | |
586 | } | |
587 | ||
588 | void wxWindow::GetPosition(int *x, int *y) const | |
589 | { | |
a4294b78 JS |
590 | if (m_drawingArea) |
591 | { | |
592 | CanvasGetPosition(x, y); | |
593 | return; | |
594 | } | |
595 | Widget widget = (Widget) GetTopWidget(); | |
596 | Position xx, yy; | |
597 | XtVaGetValues(widget, XmNx, &xx, XmNy, &yy, NULL); | |
598 | ||
599 | // We may be faking the client origin. | |
600 | // So a window that's really at (0, 30) may appear | |
601 | // (to wxWin apps) to be at (0, 0). | |
602 | if (GetParent()) | |
603 | { | |
604 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
605 | xx -= pt.x; | |
606 | yy -= pt.y; | |
607 | } | |
608 | ||
609 | *x = xx; *y = yy; | |
4bb6408c JS |
610 | } |
611 | ||
612 | void wxWindow::ScreenToClient(int *x, int *y) const | |
613 | { | |
47bc1060 JS |
614 | Widget widget = (Widget) GetClientWidget(); |
615 | Display *display = XtDisplay((Widget) GetMainWidget()); | |
616 | Window rootWindow = RootWindowOfScreen(XtScreen(widget)); | |
617 | Window thisWindow = XtWindow(widget); | |
618 | ||
619 | Window childWindow; | |
620 | int xx = *x; | |
621 | int yy = *y; | |
622 | XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow); | |
4bb6408c JS |
623 | } |
624 | ||
625 | void wxWindow::ClientToScreen(int *x, int *y) const | |
626 | { | |
02e8b2f9 | 627 | Widget widget = (Widget) GetClientWidget(); |
4bb6408c JS |
628 | Display *display = XtDisplay(widget); |
629 | Window rootWindow = RootWindowOfScreen(XtScreen(widget)); | |
47bc1060 | 630 | Window thisWindow = XtWindow(widget); |
4bb6408c JS |
631 | |
632 | Window childWindow; | |
633 | int xx = *x; | |
634 | int yy = *y; | |
635 | XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow); | |
636 | } | |
637 | ||
638 | void wxWindow::SetCursor(const wxCursor& cursor) | |
639 | { | |
640 | m_windowCursor = cursor; | |
641 | if (m_windowCursor.Ok()) | |
642 | { | |
4bb6408c | 643 | WXDisplay *dpy = GetXDisplay(); |
47bc1060 | 644 | WXCursor x_cursor = ((wxCursor&)cursor).GetXCursor(dpy); |
4bb6408c JS |
645 | |
646 | Widget w = (Widget) GetMainWidget(); | |
647 | Window win = XtWindow(w); | |
47bc1060 | 648 | XDefineCursor((Display*) dpy, win, (Cursor) x_cursor); |
4bb6408c JS |
649 | } |
650 | } | |
651 | ||
652 | ||
653 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
654 | void wxWindow::GetClientSize(int *x, int *y) const | |
655 | { | |
47bc1060 | 656 | Widget widget = (Widget) GetClientWidget(); |
4bb6408c JS |
657 | Dimension xx, yy; |
658 | XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL); | |
659 | *x = xx; *y = yy; | |
660 | } | |
661 | ||
662 | void wxWindow::SetSize(int x, int y, int width, int height, int sizeFlags) | |
663 | { | |
7fe7d506 JS |
664 | // A bit of optimization to help sort out the flickers. |
665 | int oldX, oldY, oldW, oldH; | |
666 | GetSize(& oldW, & oldH); | |
667 | GetPosition(& oldX, & oldY); | |
668 | ||
669 | bool useOldPos = FALSE; | |
670 | bool useOldSize = FALSE; | |
671 | ||
672 | if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0)) | |
673 | useOldPos = TRUE; | |
674 | else if (x == oldX && y == oldY) | |
675 | useOldPos = TRUE; | |
676 | ||
677 | if ((width == -1) && (height == -1)) | |
678 | useOldSize = TRUE; | |
679 | else if (width == oldW && height == oldH) | |
680 | useOldSize = TRUE; | |
681 | ||
682 | if (useOldPos && useOldSize) | |
683 | return; | |
684 | ||
50414e24 JS |
685 | if (m_drawingArea) |
686 | { | |
687 | CanvasSetSize(x, y, width, height, sizeFlags); | |
688 | return; | |
689 | } | |
02e8b2f9 JS |
690 | Widget widget = (Widget) GetTopWidget(); |
691 | if (!widget) | |
692 | return; | |
693 | ||
694 | bool managed = XtIsManaged( widget ); | |
695 | if (managed) | |
696 | XtUnmanageChild(widget); | |
4bb6408c | 697 | |
a4294b78 JS |
698 | int xx = x; int yy = y; |
699 | AdjustForParentClientOrigin(xx, yy, sizeFlags); | |
700 | ||
7fe7d506 JS |
701 | if (!useOldPos) |
702 | { | |
703 | if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
704 | XtVaSetValues(widget, XmNx, xx, NULL); | |
705 | if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
706 | XtVaSetValues(widget, XmNy, yy, NULL); | |
707 | } | |
708 | if (!useOldSize) | |
709 | { | |
710 | if (width > -1) | |
711 | XtVaSetValues(widget, XmNwidth, width, NULL); | |
712 | if (height > -1) | |
713 | XtVaSetValues(widget, XmNheight, height, NULL); | |
714 | } | |
4bb6408c | 715 | |
02e8b2f9 JS |
716 | if (managed) |
717 | XtManageChild(widget); | |
718 | ||
7fe7d506 JS |
719 | // How about this bit. Maybe we don't need to generate size events |
720 | // all the time -- they'll be generated when the window is sized anyway. | |
721 | /* | |
4bb6408c JS |
722 | wxSizeEvent sizeEvent(wxSize(width, height), GetId()); |
723 | sizeEvent.SetEventObject(this); | |
724 | ||
725 | GetEventHandler()->ProcessEvent(sizeEvent); | |
7fe7d506 | 726 | */ |
4bb6408c JS |
727 | } |
728 | ||
729 | void wxWindow::SetClientSize(int width, int height) | |
730 | { | |
50414e24 JS |
731 | if (m_drawingArea) |
732 | { | |
733 | CanvasSetClientSize(width, height); | |
734 | return; | |
735 | } | |
736 | ||
02e8b2f9 | 737 | Widget widget = (Widget) GetTopWidget(); |
4bb6408c JS |
738 | |
739 | if (width > -1) | |
740 | XtVaSetValues(widget, XmNwidth, width, NULL); | |
741 | if (height > -1) | |
742 | XtVaSetValues(widget, XmNheight, height, NULL); | |
743 | ||
744 | wxSizeEvent sizeEvent(wxSize(width, height), GetId()); | |
745 | sizeEvent.SetEventObject(this); | |
746 | ||
747 | GetEventHandler()->ProcessEvent(sizeEvent); | |
748 | } | |
749 | ||
750 | // For implementation purposes - sometimes decorations make the client area | |
751 | // smaller | |
752 | wxPoint wxWindow::GetClientAreaOrigin() const | |
753 | { | |
754 | return wxPoint(0, 0); | |
755 | } | |
756 | ||
757 | // Makes an adjustment to the window position (for example, a frame that has | |
758 | // a toolbar that it manages itself). | |
759 | void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) | |
760 | { | |
761 | if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) | |
762 | { | |
763 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
764 | x += pt.x; y += pt.y; | |
765 | } | |
766 | } | |
767 | ||
768 | bool wxWindow::Show(bool show) | |
769 | { | |
50414e24 JS |
770 | if (show) |
771 | { | |
772 | if (m_borderWidget || m_scrolledWindow) | |
773 | { | |
02800301 JS |
774 | if (m_drawingArea) |
775 | XtMapWidget((Widget) m_drawingArea); | |
50414e24 JS |
776 | XtMapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); |
777 | } | |
778 | else | |
779 | { | |
621793f4 JS |
780 | WXWidget topWidget = GetTopWidget(); |
781 | if (GetTopWidget()) | |
782 | XtMapWidget((Widget) GetTopWidget()); | |
783 | else if (GetMainWidget()) | |
784 | XtMapWidget((Widget) GetMainWidget()); | |
50414e24 JS |
785 | } |
786 | } | |
787 | else | |
788 | { | |
789 | if (m_borderWidget || m_scrolledWindow) | |
790 | { | |
02800301 JS |
791 | if (m_drawingArea) |
792 | XtUnmapWidget((Widget) m_drawingArea); | |
50414e24 JS |
793 | XtUnmapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); |
794 | } | |
795 | else | |
796 | { | |
621793f4 JS |
797 | if (GetTopWidget()) |
798 | XtUnmapWidget((Widget) GetTopWidget()); | |
799 | else if (GetMainWidget()) | |
800 | XtUnmapWidget((Widget) GetMainWidget()); | |
50414e24 JS |
801 | } |
802 | } | |
803 | ||
804 | /* | |
4bb6408c JS |
805 | Window xwin = (Window) GetXWindow(); |
806 | Display *xdisp = (Display*) GetXDisplay(); | |
807 | if (show) | |
808 | XMapWindow(xdisp, xwin); | |
809 | else | |
810 | XUnmapWindow(xdisp, xwin); | |
50414e24 | 811 | */ |
4bb6408c JS |
812 | |
813 | m_isShown = show; | |
814 | ||
815 | return TRUE; | |
816 | } | |
817 | ||
818 | bool wxWindow::IsShown() const | |
819 | { | |
820 | return m_isShown; | |
821 | } | |
822 | ||
823 | int wxWindow::GetCharHeight() const | |
824 | { | |
47bc1060 | 825 | if (!m_windowFont.Ok()) |
4bb6408c | 826 | return 0; |
47bc1060 JS |
827 | |
828 | WXFontStructPtr pFontStruct = m_windowFont.GetFontStruct(1.0, GetXDisplay()); | |
829 | ||
830 | int direction, ascent, descent; | |
831 | XCharStruct overall; | |
832 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
833 | &descent, &overall); | |
834 | // return (overall.ascent + overall.descent); | |
835 | return (ascent + descent); | |
4bb6408c JS |
836 | } |
837 | ||
838 | int wxWindow::GetCharWidth() const | |
839 | { | |
47bc1060 | 840 | if (!m_windowFont.Ok()) |
4bb6408c | 841 | return 0; |
47bc1060 JS |
842 | |
843 | WXFontStructPtr pFontStruct = m_windowFont.GetFontStruct(1.0, GetXDisplay()); | |
844 | ||
845 | int direction, ascent, descent; | |
846 | XCharStruct overall; | |
847 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
848 | &descent, &overall); | |
849 | return overall.width; | |
850 | } | |
851 | ||
852 | /* Helper function for 16-bit fonts */ | |
853 | static int str16len(const char *s) | |
854 | { | |
855 | int count = 0; | |
856 | ||
857 | while (s[0] && s[1]) { | |
858 | count++; | |
859 | s += 2; | |
860 | } | |
861 | ||
862 | return count; | |
4bb6408c JS |
863 | } |
864 | ||
865 | void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, | |
47bc1060 | 866 | int *descent, int *externalLeading, const wxFont *theFont, bool use16) const |
4bb6408c JS |
867 | { |
868 | wxFont *fontToUse = (wxFont *)theFont; | |
869 | if (!fontToUse) | |
870 | fontToUse = (wxFont *) & m_windowFont; | |
871 | ||
47bc1060 JS |
872 | if (!fontToUse->Ok()) |
873 | return; | |
874 | ||
875 | WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay()); | |
876 | ||
877 | int direction, ascent, descent2; | |
878 | XCharStruct overall; | |
879 | int slen; | |
880 | ||
881 | if (use16) slen = str16len(string); else slen = strlen(string); | |
882 | ||
883 | if (use16) | |
884 | XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction, | |
885 | &ascent, &descent2, &overall); | |
886 | else | |
887 | XTextExtents((XFontStruct*) pFontStruct, (char*) (const char*) string, slen, &direction, | |
888 | &ascent, &descent2, &overall); | |
889 | ||
890 | *x = (overall.width); | |
891 | *y = (ascent + descent2); | |
892 | if (descent) | |
893 | *descent = descent2; | |
894 | if (externalLeading) | |
895 | *externalLeading = 0; | |
4bb6408c JS |
896 | } |
897 | ||
16e93305 | 898 | void wxWindow::Refresh(bool eraseBack, const wxRect *rect) |
4bb6408c JS |
899 | { |
900 | Display *display = XtDisplay((Widget) GetMainWidget()); | |
901 | Window thisWindow = XtWindow((Widget) GetMainWidget()); | |
902 | ||
903 | XExposeEvent dummyEvent; | |
904 | int width, height; | |
905 | GetSize(&width, &height); | |
906 | ||
907 | dummyEvent.type = Expose; | |
908 | dummyEvent.display = display; | |
909 | dummyEvent.send_event = True; | |
910 | dummyEvent.window = thisWindow; | |
911 | if (rect) | |
912 | { | |
913 | dummyEvent.x = rect->x; | |
914 | dummyEvent.y = rect->y; | |
915 | dummyEvent.width = rect->width; | |
916 | dummyEvent.height = rect->height; | |
917 | } | |
918 | else | |
919 | { | |
920 | dummyEvent.x = 0; | |
921 | dummyEvent.y = 0; | |
922 | dummyEvent.width = width; | |
923 | dummyEvent.height = height; | |
924 | } | |
925 | dummyEvent.count = 0; | |
926 | ||
927 | if (eraseBack) | |
928 | { | |
929 | wxClientDC dc(this); | |
e97f20a0 JS |
930 | wxBrush backgroundBrush(GetBackgroundColour(), wxSOLID); |
931 | dc.SetBackground(backgroundBrush); | |
4bb6408c JS |
932 | dc.Clear(); |
933 | } | |
934 | ||
935 | XSendEvent(display, thisWindow, False, ExposureMask, (XEvent *)&dummyEvent); | |
936 | } | |
937 | ||
938 | // Responds to colour changes: passes event on to children. | |
939 | void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event) | |
940 | { | |
941 | wxNode *node = GetChildren()->First(); | |
942 | while ( node ) | |
943 | { | |
944 | // Only propagate to non-top-level windows | |
945 | wxWindow *win = (wxWindow *)node->Data(); | |
946 | if ( win->GetParent() ) | |
947 | { | |
948 | wxSysColourChangedEvent event2; | |
949 | event.m_eventObject = win; | |
950 | win->GetEventHandler()->ProcessEvent(event2); | |
951 | } | |
952 | ||
953 | node = node->Next(); | |
954 | } | |
955 | } | |
956 | ||
957 | // This can be called by the app (or wxWindows) to do default processing for the current | |
958 | // event. Save message/event info in wxWindow so they can be used in this function. | |
959 | long wxWindow::Default() | |
960 | { | |
961 | // TODO | |
962 | return 0; | |
963 | } | |
964 | ||
965 | void wxWindow::InitDialog() | |
966 | { | |
967 | wxInitDialogEvent event(GetId()); | |
968 | event.SetEventObject( this ); | |
969 | GetEventHandler()->ProcessEvent(event); | |
970 | } | |
971 | ||
972 | // Default init dialog behaviour is to transfer data to window | |
973 | void wxWindow::OnInitDialog(wxInitDialogEvent& event) | |
974 | { | |
975 | TransferDataToWindow(); | |
976 | } | |
977 | ||
978 | // Caret manipulation | |
979 | void wxWindow::CreateCaret(int w, int h) | |
980 | { | |
981 | m_caretWidth = w; | |
982 | m_caretHeight = h; | |
983 | m_caretEnabled = TRUE; | |
984 | } | |
985 | ||
986 | void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) | |
987 | { | |
988 | // TODO | |
989 | } | |
990 | ||
991 | void wxWindow::ShowCaret(bool show) | |
992 | { | |
993 | // TODO | |
994 | } | |
995 | ||
996 | void wxWindow::DestroyCaret() | |
997 | { | |
998 | // TODO | |
999 | m_caretEnabled = FALSE; | |
1000 | } | |
1001 | ||
1002 | void wxWindow::SetCaretPos(int x, int y) | |
1003 | { | |
1004 | // TODO | |
1005 | } | |
1006 | ||
1007 | void wxWindow::GetCaretPos(int *x, int *y) const | |
1008 | { | |
1009 | // TODO | |
1010 | } | |
1011 | ||
1012 | wxWindow *wxGetActiveWindow() | |
1013 | { | |
1014 | // TODO | |
1015 | return NULL; | |
1016 | } | |
1017 | ||
1018 | void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH) | |
1019 | { | |
1020 | m_minSizeX = minW; | |
1021 | m_minSizeY = minH; | |
1022 | m_maxSizeX = maxW; | |
1023 | m_maxSizeY = maxH; | |
1024 | ||
1025 | if (!this->IsKindOf(CLASSINFO(wxFrame))) | |
1026 | return; | |
1027 | ||
1028 | wxFrame *frame = (wxFrame *)this; | |
47bc1060 | 1029 | Widget widget = (Widget) frame->GetShellWidget(); |
4bb6408c | 1030 | |
4bb6408c | 1031 | if (minW > -1) |
47bc1060 | 1032 | XtVaSetValues(widget, XmNminWidth, minW, NULL); |
4bb6408c | 1033 | if (minH > -1) |
47bc1060 | 1034 | XtVaSetValues(widget, XmNminHeight, minH, NULL); |
4bb6408c | 1035 | if (maxW > -1) |
47bc1060 | 1036 | XtVaSetValues(widget, XmNmaxWidth, maxW, NULL); |
4bb6408c | 1037 | if (maxH > -1) |
47bc1060 | 1038 | XtVaSetValues(widget, XmNmaxHeight, maxH, NULL); |
4bb6408c | 1039 | if (incW > -1) |
47bc1060 | 1040 | XtVaSetValues(widget, XmNwidthInc, incW, NULL); |
4bb6408c | 1041 | if (incH > -1) |
47bc1060 | 1042 | XtVaSetValues(widget, XmNheightInc, incH, NULL); |
4bb6408c JS |
1043 | } |
1044 | ||
1045 | void wxWindow::Centre(int direction) | |
1046 | { | |
1047 | int x, y, width, height, panel_width, panel_height, new_x, new_y; | |
1048 | ||
1049 | wxWindow *father = (wxWindow *)GetParent(); | |
1050 | if (!father) | |
1051 | return; | |
1052 | ||
1053 | father->GetClientSize(&panel_width, &panel_height); | |
1054 | GetSize(&width, &height); | |
1055 | GetPosition(&x, &y); | |
1056 | ||
1057 | new_x = -1; | |
1058 | new_y = -1; | |
1059 | ||
1060 | if (direction & wxHORIZONTAL) | |
1061 | new_x = (int)((panel_width - width)/2); | |
1062 | ||
1063 | if (direction & wxVERTICAL) | |
1064 | new_y = (int)((panel_height - height)/2); | |
1065 | ||
1066 | SetSize(new_x, new_y, -1, -1); | |
1067 | ||
1068 | } | |
1069 | ||
1070 | // Coordinates relative to the window | |
50414e24 | 1071 | void wxWindow::WarpPointer (int x, int y) |
4bb6408c | 1072 | { |
50414e24 | 1073 | XWarpPointer (XtDisplay((Widget) GetClientWidget()), None, XtWindow((Widget) GetClientWidget()), 0, 0, 0, 0, x, y); |
4bb6408c JS |
1074 | } |
1075 | ||
1076 | void wxWindow::OnEraseBackground(wxEraseEvent& event) | |
1077 | { | |
1078 | // TODO | |
1079 | Default(); | |
1080 | } | |
1081 | ||
1082 | int wxWindow::GetScrollPos(int orient) const | |
1083 | { | |
47bc1060 JS |
1084 | if (orient == wxHORIZONTAL) |
1085 | return m_scrollPosX; | |
1086 | else | |
1087 | return m_scrollPosY; | |
1088 | /* | |
1089 | Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar); | |
1090 | if (scrollBar) | |
1091 | { | |
1092 | int pos; | |
1093 | XtVaGetValues(scrollBar, | |
1094 | XmNvalue, &pos, NULL); | |
1095 | return pos; | |
1096 | } | |
1097 | else | |
1098 | return 0; | |
1099 | */ | |
4bb6408c JS |
1100 | } |
1101 | ||
1102 | // This now returns the whole range, not just the number | |
1103 | // of positions that we can scroll. | |
1104 | int wxWindow::GetScrollRange(int orient) const | |
1105 | { | |
47bc1060 JS |
1106 | Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar); |
1107 | if (scrollBar) | |
1108 | { | |
1109 | int range; | |
1110 | XtVaGetValues(scrollBar, | |
1111 | XmNmaximum, &range, NULL); | |
1112 | return range; | |
1113 | } | |
1114 | else | |
1115 | return 0; | |
4bb6408c JS |
1116 | } |
1117 | ||
1118 | int wxWindow::GetScrollThumb(int orient) const | |
1119 | { | |
47bc1060 JS |
1120 | Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar); |
1121 | if (scrollBar) | |
1122 | { | |
1123 | int thumb; | |
1124 | XtVaGetValues(scrollBar, | |
1125 | XmNsliderSize, &thumb, NULL); | |
1126 | return thumb; | |
1127 | } | |
1128 | else | |
1129 | return 0; | |
4bb6408c JS |
1130 | } |
1131 | ||
47bc1060 | 1132 | void wxWindow::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) |
4bb6408c | 1133 | { |
47bc1060 JS |
1134 | Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar); |
1135 | if (scrollBar) | |
1136 | { | |
1137 | XtVaSetValues (scrollBar, | |
1138 | XmNvalue, pos, | |
1139 | NULL); | |
1140 | } | |
1141 | if (orient == wxHORIZONTAL) | |
1142 | m_scrollPosX = pos; | |
1143 | else | |
1144 | m_scrollPosY = pos; | |
1145 | ||
4bb6408c JS |
1146 | } |
1147 | ||
1148 | // New function that will replace some of the above. | |
1149 | void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible, | |
47bc1060 | 1150 | int range, bool WXUNUSED(refresh)) |
4bb6408c | 1151 | { |
47bc1060 JS |
1152 | Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar ); |
1153 | if (!scrollBar) | |
1154 | return; | |
1155 | ||
1156 | if (range == 0) | |
1157 | range = 1; | |
1158 | if (thumbVisible == 0) | |
1159 | thumbVisible = 1; | |
1160 | ||
1161 | XtVaSetValues(scrollBar, | |
1162 | XmNvalue, pos, | |
1163 | XmNminimum, 0, | |
1164 | XmNmaximum, range, | |
1165 | XmNsliderSize, thumbVisible, | |
1166 | NULL); | |
1167 | ||
1168 | if (orient == wxHORIZONTAL) | |
1169 | m_scrollPosX = pos; | |
1170 | else | |
1171 | m_scrollPosY = pos; | |
4bb6408c JS |
1172 | } |
1173 | ||
1174 | // Does a physical scroll | |
16e93305 | 1175 | void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) |
4bb6408c | 1176 | { |
47bc1060 JS |
1177 | // cerr << "Scrolling. delta = " << dx << ", " << dy << endl; |
1178 | int x, y, w, h; | |
1179 | if (rect) | |
1180 | { | |
1181 | // Use specified rectangle | |
1182 | x = rect->x; y = rect->y; w = rect->width; h = rect->height; | |
1183 | } | |
1184 | else | |
1185 | { | |
1186 | // Use whole client area | |
1187 | x = 0; y = 0; | |
1188 | GetClientSize(& w, & h); | |
1189 | } | |
1190 | ||
1191 | int x1 = (dx >= 0) ? x : x - dx ; | |
1192 | int y1 = (dy >= 0) ? y : y - dy; | |
1193 | int w1 = w - abs(dx); | |
1194 | int h1 = h - abs(dy); | |
1195 | int x2 = (dx >= 0) ? x + dx : x; | |
1196 | int y2 = (dy >= 0) ? y + dy : y; | |
1197 | ||
1198 | wxClientDC dc(this); | |
1199 | ||
1200 | dc.SetLogicalFunction (wxCOPY); | |
1201 | ||
1202 | Widget widget = (Widget) GetMainWidget(); | |
1203 | Window window = XtWindow(widget); | |
1204 | Display* display = XtDisplay(widget); | |
1205 | ||
1206 | XCopyArea(display, window, | |
1207 | window, (GC) dc.GetGC(), | |
1208 | x1, y1, | |
1209 | w1, h1, | |
1210 | x2, y2); | |
1211 | ||
1212 | dc.SetAutoSetting(TRUE); | |
1213 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1214 | dc.SetBrush(brush); // ?? | |
1215 | ||
1216 | // We'll add rectangles to the list of update rectangles | |
1217 | // according to which bits we've exposed. | |
1218 | wxList updateRects; | |
1219 | ||
1220 | if (dx > 0) | |
1221 | { | |
1222 | wxRect *rect = new wxRect; | |
1223 | rect->x = x; | |
1224 | rect->y = y; | |
1225 | rect->width = dx; | |
1226 | rect->height = h; | |
1227 | ||
1228 | XFillRectangle(display, window, | |
1229 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); | |
1230 | ||
1231 | rect->x = rect->x; | |
1232 | rect->y = rect->y; | |
1233 | rect->width = rect->width; | |
1234 | rect->height = rect->height; | |
1235 | ||
1236 | updateRects.Append((wxObject*) rect); | |
1237 | } | |
1238 | else if (dx < 0) | |
1239 | { | |
1240 | wxRect *rect = new wxRect; | |
1241 | ||
1242 | rect->x = x + w + dx; | |
1243 | rect->y = y; | |
1244 | rect->width = -dx; | |
1245 | rect->height = h; | |
1246 | ||
1247 | XFillRectangle(display, window, | |
1248 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, | |
1249 | rect->height); | |
1250 | ||
1251 | rect->x = rect->x; | |
1252 | rect->y = rect->y; | |
1253 | rect->width = rect->width; | |
1254 | rect->height = rect->height; | |
1255 | ||
1256 | updateRects.Append((wxObject*) rect); | |
1257 | } | |
1258 | if (dy > 0) | |
1259 | { | |
1260 | wxRect *rect = new wxRect; | |
1261 | ||
1262 | rect->x = x; | |
1263 | rect->y = y; | |
1264 | rect->width = w; | |
1265 | rect->height = dy; | |
1266 | ||
1267 | XFillRectangle(display, window, | |
1268 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); | |
1269 | ||
1270 | rect->x = rect->x; | |
1271 | rect->y = rect->y; | |
1272 | rect->width = rect->width; | |
1273 | rect->height = rect->height; | |
1274 | ||
1275 | updateRects.Append((wxObject*) rect); | |
1276 | } | |
1277 | else if (dy < 0) | |
1278 | { | |
1279 | wxRect *rect = new wxRect; | |
1280 | ||
1281 | rect->x = x; | |
1282 | rect->y = y + h + dy; | |
1283 | rect->width = w; | |
1284 | rect->height = -dy; | |
1285 | ||
1286 | XFillRectangle(display, window, | |
1287 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); | |
1288 | ||
1289 | rect->x = rect->x; | |
1290 | rect->y = rect->y; | |
1291 | rect->width = rect->width; | |
1292 | rect->height = rect->height; | |
1293 | ||
1294 | updateRects.Append((wxObject*) rect); | |
1295 | } | |
1296 | dc.SetBrush(wxNullBrush); | |
1297 | ||
1298 | // Now send expose events | |
1299 | ||
1300 | wxNode* node = updateRects.First(); | |
1301 | while (node) | |
1302 | { | |
1303 | wxRect* rect = (wxRect*) node->Data(); | |
1304 | XExposeEvent event; | |
1305 | ||
1306 | event.type = Expose; | |
1307 | event.display = display; | |
1308 | event.send_event = True; | |
1309 | event.window = window; | |
1310 | ||
1311 | event.x = rect->x; | |
1312 | event.y = rect->y; | |
1313 | event.width = rect->width; | |
1314 | event.height = rect->height; | |
1315 | ||
1316 | event.count = 0; | |
1317 | ||
1318 | XSendEvent(display, window, False, ExposureMask, (XEvent *)&event); | |
1319 | ||
1320 | node = node->Next(); | |
1321 | ||
1322 | } | |
4fabb575 JS |
1323 | |
1324 | // Delete the update rects | |
1325 | node = updateRects.First(); | |
1326 | while (node) | |
1327 | { | |
1328 | wxRect* rect = (wxRect*) node->Data(); | |
1329 | delete rect; | |
1330 | node = node->Next(); | |
1331 | } | |
1332 | ||
4bb6408c JS |
1333 | } |
1334 | ||
4bb6408c JS |
1335 | void wxWindow::OnChar(wxKeyEvent& event) |
1336 | { | |
1337 | if ( event.KeyCode() == WXK_TAB ) { | |
1338 | // propagate the TABs to the parent - it's up to it to decide what | |
1339 | // to do with it | |
1340 | if ( GetParent() ) { | |
1341 | if ( GetParent()->ProcessEvent(event) ) | |
1342 | return; | |
1343 | } | |
1344 | } | |
1345 | } | |
1346 | ||
1347 | void wxWindow::OnPaint(wxPaintEvent& event) | |
1348 | { | |
1349 | Default(); | |
1350 | } | |
1351 | ||
1352 | bool wxWindow::IsEnabled() const | |
1353 | { | |
47bc1060 JS |
1354 | // TODO. Is this right? |
1355 | // return XtGetSensitive((Widget) GetMainWidget()); | |
4bb6408c JS |
1356 | return FALSE; |
1357 | } | |
1358 | ||
1359 | // Dialog support: override these and call | |
1360 | // base class members to add functionality | |
1361 | // that can't be done using validators. | |
1362 | // NOTE: these functions assume that controls | |
1363 | // are direct children of this window, not grandchildren | |
1364 | // or other levels of descendant. | |
1365 | ||
1366 | // Transfer values to controls. If returns FALSE, | |
1367 | // it's an application error (pops up a dialog) | |
1368 | bool wxWindow::TransferDataToWindow() | |
1369 | { | |
1370 | wxNode *node = GetChildren()->First(); | |
1371 | while ( node ) | |
1372 | { | |
1373 | wxWindow *child = (wxWindow *)node->Data(); | |
1374 | if ( child->GetValidator() && | |
1375 | !child->GetValidator()->TransferToWindow() ) | |
1376 | { | |
1377 | wxMessageBox("Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION); | |
1378 | return FALSE; | |
1379 | } | |
1380 | ||
1381 | node = node->Next(); | |
1382 | } | |
1383 | return TRUE; | |
1384 | } | |
1385 | ||
1386 | // Transfer values from controls. If returns FALSE, | |
1387 | // validation failed: don't quit | |
1388 | bool wxWindow::TransferDataFromWindow() | |
1389 | { | |
1390 | wxNode *node = GetChildren()->First(); | |
1391 | while ( node ) | |
1392 | { | |
1393 | wxWindow *child = (wxWindow *)node->Data(); | |
1394 | if ( child->GetValidator() && !child->GetValidator()->TransferFromWindow() ) | |
1395 | { | |
1396 | return FALSE; | |
1397 | } | |
1398 | ||
1399 | node = node->Next(); | |
1400 | } | |
1401 | return TRUE; | |
1402 | } | |
1403 | ||
1404 | bool wxWindow::Validate() | |
1405 | { | |
1406 | wxNode *node = GetChildren()->First(); | |
1407 | while ( node ) | |
1408 | { | |
1409 | wxWindow *child = (wxWindow *)node->Data(); | |
1410 | if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) ) | |
1411 | { | |
1412 | return FALSE; | |
1413 | } | |
1414 | ||
1415 | node = node->Next(); | |
1416 | } | |
1417 | return TRUE; | |
1418 | } | |
1419 | ||
1420 | // Get the window with the focus | |
1421 | wxWindow *wxWindow::FindFocus() | |
1422 | { | |
1423 | // TODO | |
1424 | return NULL; | |
1425 | } | |
1426 | ||
1427 | void wxWindow::AddChild(wxWindow *child) | |
1428 | { | |
1429 | GetChildren()->Append(child); | |
1430 | child->m_windowParent = this; | |
1431 | } | |
1432 | ||
1433 | void wxWindow::RemoveChild(wxWindow *child) | |
1434 | { | |
1435 | if (GetChildren()) | |
1436 | GetChildren()->DeleteObject(child); | |
1437 | child->m_windowParent = NULL; | |
1438 | } | |
1439 | ||
4fabb575 JS |
1440 | // Reparents this window to have the new parent. |
1441 | bool wxWindow::Reparent(wxWindow* WXUNUSED(parent)) | |
1442 | { | |
1443 | // For now, we indicate that this isn't implemented. | |
1444 | return FALSE; | |
1445 | } | |
1446 | ||
4bb6408c JS |
1447 | void wxWindow::DestroyChildren() |
1448 | { | |
02800301 JS |
1449 | if (GetChildren()) |
1450 | { | |
1451 | wxNode *node = GetChildren()->First(); | |
1452 | while (node) | |
1453 | { | |
1454 | wxNode* next = node->Next(); | |
1455 | wxWindow* child = (wxWindow*) node->Data(); | |
1456 | delete child; | |
1457 | node = next; | |
1458 | } | |
1459 | GetChildren()->Clear(); | |
1460 | #if 0 | |
4bb6408c JS |
1461 | wxNode *node; |
1462 | while ((node = GetChildren()->First()) != (wxNode *)NULL) { | |
1463 | wxWindow *child; | |
1464 | if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) { | |
1465 | delete child; | |
1466 | if ( GetChildren()->Member(child) ) | |
1467 | delete node; | |
1468 | } | |
1469 | } /* while */ | |
02800301 | 1470 | #endif |
4bb6408c JS |
1471 | } |
1472 | } | |
1473 | ||
1474 | void wxWindow::MakeModal(bool modal) | |
1475 | { | |
1476 | // Disable all other windows | |
1477 | if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame))) | |
1478 | { | |
1479 | wxNode *node = wxTopLevelWindows.First(); | |
1480 | while (node) | |
1481 | { | |
1482 | wxWindow *win = (wxWindow *)node->Data(); | |
1483 | if (win != this) | |
1484 | win->Enable(!modal); | |
1485 | ||
1486 | node = node->Next(); | |
1487 | } | |
1488 | } | |
1489 | } | |
1490 | ||
02e8b2f9 JS |
1491 | // If nothing defined for this, try the parent. |
1492 | // E.g. we may be a button loaded from a resource, with no callback function | |
1493 | // defined. | |
1494 | void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event) | |
1495 | { | |
1496 | if (GetEventHandler()->ProcessEvent(event) ) | |
1497 | return; | |
1498 | if (m_windowParent) | |
1499 | m_windowParent->GetEventHandler()->OnCommand(win, event); | |
1500 | } | |
1501 | ||
4bb6408c JS |
1502 | void wxWindow::SetConstraints(wxLayoutConstraints *c) |
1503 | { | |
1504 | if (m_constraints) | |
1505 | { | |
1506 | UnsetConstraints(m_constraints); | |
1507 | delete m_constraints; | |
1508 | } | |
1509 | m_constraints = c; | |
1510 | if (m_constraints) | |
1511 | { | |
1512 | // Make sure other windows know they're part of a 'meaningful relationship' | |
1513 | if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this)) | |
1514 | m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1515 | if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this)) | |
1516 | m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1517 | if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this)) | |
1518 | m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1519 | if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this)) | |
1520 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1521 | if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this)) | |
1522 | m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1523 | if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this)) | |
1524 | m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1525 | if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this)) | |
1526 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1527 | if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this)) | |
1528 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1529 | } | |
1530 | } | |
1531 | ||
1532 | // This removes any dangling pointers to this window | |
1533 | // in other windows' constraintsInvolvedIn lists. | |
1534 | void wxWindow::UnsetConstraints(wxLayoutConstraints *c) | |
1535 | { | |
1536 | if (c) | |
1537 | { | |
1538 | if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this)) | |
1539 | c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1540 | if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this)) | |
1541 | c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1542 | if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this)) | |
1543 | c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1544 | if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this)) | |
1545 | c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1546 | if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this)) | |
1547 | c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1548 | if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this)) | |
1549 | c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1550 | if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this)) | |
1551 | c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1552 | if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this)) | |
1553 | c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1554 | } | |
1555 | } | |
1556 | ||
1557 | // Back-pointer to other windows we're involved with, so if we delete | |
1558 | // this window, we must delete any constraints we're involved with. | |
1559 | void wxWindow::AddConstraintReference(wxWindow *otherWin) | |
1560 | { | |
1561 | if (!m_constraintsInvolvedIn) | |
1562 | m_constraintsInvolvedIn = new wxList; | |
1563 | if (!m_constraintsInvolvedIn->Member(otherWin)) | |
1564 | m_constraintsInvolvedIn->Append(otherWin); | |
1565 | } | |
1566 | ||
1567 | // REMOVE back-pointer to other windows we're involved with. | |
1568 | void wxWindow::RemoveConstraintReference(wxWindow *otherWin) | |
1569 | { | |
1570 | if (m_constraintsInvolvedIn) | |
1571 | m_constraintsInvolvedIn->DeleteObject(otherWin); | |
1572 | } | |
1573 | ||
1574 | // Reset any constraints that mention this window | |
1575 | void wxWindow::DeleteRelatedConstraints() | |
1576 | { | |
1577 | if (m_constraintsInvolvedIn) | |
1578 | { | |
1579 | wxNode *node = m_constraintsInvolvedIn->First(); | |
1580 | while (node) | |
1581 | { | |
1582 | wxWindow *win = (wxWindow *)node->Data(); | |
1583 | wxNode *next = node->Next(); | |
1584 | wxLayoutConstraints *constr = win->GetConstraints(); | |
1585 | ||
1586 | // Reset any constraints involving this window | |
1587 | if (constr) | |
1588 | { | |
1589 | constr->left.ResetIfWin((wxWindow *)this); | |
1590 | constr->top.ResetIfWin((wxWindow *)this); | |
1591 | constr->right.ResetIfWin((wxWindow *)this); | |
1592 | constr->bottom.ResetIfWin((wxWindow *)this); | |
1593 | constr->width.ResetIfWin((wxWindow *)this); | |
1594 | constr->height.ResetIfWin((wxWindow *)this); | |
1595 | constr->centreX.ResetIfWin((wxWindow *)this); | |
1596 | constr->centreY.ResetIfWin((wxWindow *)this); | |
1597 | } | |
1598 | delete node; | |
1599 | node = next; | |
1600 | } | |
1601 | delete m_constraintsInvolvedIn; | |
1602 | m_constraintsInvolvedIn = NULL; | |
1603 | } | |
1604 | } | |
1605 | ||
1606 | void wxWindow::SetSizer(wxSizer *sizer) | |
1607 | { | |
1608 | m_windowSizer = sizer; | |
1609 | if (sizer) | |
1610 | sizer->SetSizerParent((wxWindow *)this); | |
1611 | } | |
1612 | ||
1613 | /* | |
1614 | * New version | |
1615 | */ | |
1616 | ||
1617 | bool wxWindow::Layout() | |
1618 | { | |
1619 | if (GetConstraints()) | |
1620 | { | |
1621 | int w, h; | |
1622 | GetClientSize(&w, &h); | |
1623 | GetConstraints()->width.SetValue(w); | |
1624 | GetConstraints()->height.SetValue(h); | |
1625 | } | |
1626 | ||
1627 | // If top level (one sizer), evaluate the sizer's constraints. | |
1628 | if (GetSizer()) | |
1629 | { | |
1630 | int noChanges; | |
1631 | GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated | |
1632 | GetSizer()->LayoutPhase1(&noChanges); | |
1633 | GetSizer()->LayoutPhase2(&noChanges); | |
1634 | GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes | |
1635 | return TRUE; | |
1636 | } | |
1637 | else | |
1638 | { | |
1639 | // Otherwise, evaluate child constraints | |
1640 | ResetConstraints(); // Mark all constraints as unevaluated | |
1641 | DoPhase(1); // Just one phase need if no sizers involved | |
1642 | DoPhase(2); | |
1643 | SetConstraintSizes(); // Recursively set the real window sizes | |
1644 | } | |
1645 | return TRUE; | |
1646 | } | |
1647 | ||
1648 | ||
1649 | // Do a phase of evaluating constraints: | |
1650 | // the default behaviour. wxSizers may do a similar | |
1651 | // thing, but also impose their own 'constraints' | |
1652 | // and order the evaluation differently. | |
1653 | bool wxWindow::LayoutPhase1(int *noChanges) | |
1654 | { | |
1655 | wxLayoutConstraints *constr = GetConstraints(); | |
1656 | if (constr) | |
1657 | { | |
1658 | return constr->SatisfyConstraints((wxWindow *)this, noChanges); | |
1659 | } | |
1660 | else | |
1661 | return TRUE; | |
1662 | } | |
1663 | ||
1664 | bool wxWindow::LayoutPhase2(int *noChanges) | |
1665 | { | |
1666 | *noChanges = 0; | |
1667 | ||
1668 | // Layout children | |
1669 | DoPhase(1); | |
1670 | DoPhase(2); | |
1671 | return TRUE; | |
1672 | } | |
1673 | ||
1674 | // Do a phase of evaluating child constraints | |
1675 | bool wxWindow::DoPhase(int phase) | |
1676 | { | |
1677 | int noIterations = 0; | |
1678 | int maxIterations = 500; | |
1679 | int noChanges = 1; | |
1680 | int noFailures = 0; | |
1681 | wxList succeeded; | |
1682 | while ((noChanges > 0) && (noIterations < maxIterations)) | |
1683 | { | |
1684 | noChanges = 0; | |
1685 | noFailures = 0; | |
1686 | wxNode *node = GetChildren()->First(); | |
1687 | while (node) | |
1688 | { | |
1689 | wxWindow *child = (wxWindow *)node->Data(); | |
1690 | if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog))) | |
1691 | { | |
1692 | wxLayoutConstraints *constr = child->GetConstraints(); | |
1693 | if (constr) | |
1694 | { | |
1695 | if (succeeded.Member(child)) | |
1696 | { | |
1697 | } | |
1698 | else | |
1699 | { | |
1700 | int tempNoChanges = 0; | |
1701 | bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ; | |
1702 | noChanges += tempNoChanges; | |
1703 | if (success) | |
1704 | { | |
1705 | succeeded.Append(child); | |
1706 | } | |
1707 | } | |
1708 | } | |
1709 | } | |
1710 | node = node->Next(); | |
1711 | } | |
1712 | noIterations ++; | |
1713 | } | |
1714 | return TRUE; | |
1715 | } | |
1716 | ||
1717 | void wxWindow::ResetConstraints() | |
1718 | { | |
1719 | wxLayoutConstraints *constr = GetConstraints(); | |
1720 | if (constr) | |
1721 | { | |
1722 | constr->left.SetDone(FALSE); | |
1723 | constr->top.SetDone(FALSE); | |
1724 | constr->right.SetDone(FALSE); | |
1725 | constr->bottom.SetDone(FALSE); | |
1726 | constr->width.SetDone(FALSE); | |
1727 | constr->height.SetDone(FALSE); | |
1728 | constr->centreX.SetDone(FALSE); | |
1729 | constr->centreY.SetDone(FALSE); | |
1730 | } | |
1731 | wxNode *node = GetChildren()->First(); | |
1732 | while (node) | |
1733 | { | |
1734 | wxWindow *win = (wxWindow *)node->Data(); | |
1735 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))) | |
1736 | win->ResetConstraints(); | |
1737 | node = node->Next(); | |
1738 | } | |
1739 | } | |
1740 | ||
1741 | // Need to distinguish between setting the 'fake' size for | |
1742 | // windows and sizers, and setting the real values. | |
1743 | void wxWindow::SetConstraintSizes(bool recurse) | |
1744 | { | |
1745 | wxLayoutConstraints *constr = GetConstraints(); | |
1746 | if (constr && constr->left.GetDone() && constr->right.GetDone() && | |
1747 | constr->width.GetDone() && constr->height.GetDone()) | |
1748 | { | |
1749 | int x = constr->left.GetValue(); | |
1750 | int y = constr->top.GetValue(); | |
1751 | int w = constr->width.GetValue(); | |
1752 | int h = constr->height.GetValue(); | |
1753 | ||
1754 | // If we don't want to resize this window, just move it... | |
1755 | if ((constr->width.GetRelationship() != wxAsIs) || | |
1756 | (constr->height.GetRelationship() != wxAsIs)) | |
1757 | { | |
1758 | // Calls Layout() recursively. AAAGH. How can we stop that. | |
1759 | // Simply take Layout() out of non-top level OnSizes. | |
1760 | SizerSetSize(x, y, w, h); | |
1761 | } | |
1762 | else | |
1763 | { | |
1764 | SizerMove(x, y); | |
1765 | } | |
1766 | } | |
1767 | else if (constr) | |
1768 | { | |
1769 | char *windowClass = this->GetClassInfo()->GetClassName(); | |
1770 | ||
1771 | wxString winName; | |
1772 | if (GetName() == "") | |
1773 | winName = "unnamed"; | |
1774 | else | |
1775 | winName = GetName(); | |
1776 | wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass, (const char *)winName); | |
1777 | if (!constr->left.GetDone()) | |
1778 | wxDebugMsg(" unsatisfied 'left' constraint.\n"); | |
1779 | if (!constr->right.GetDone()) | |
1780 | wxDebugMsg(" unsatisfied 'right' constraint.\n"); | |
1781 | if (!constr->width.GetDone()) | |
1782 | wxDebugMsg(" unsatisfied 'width' constraint.\n"); | |
1783 | if (!constr->height.GetDone()) | |
1784 | wxDebugMsg(" unsatisfied 'height' constraint.\n"); | |
1785 | wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n"); | |
1786 | } | |
1787 | ||
1788 | if (recurse) | |
1789 | { | |
1790 | wxNode *node = GetChildren()->First(); | |
1791 | while (node) | |
1792 | { | |
1793 | wxWindow *win = (wxWindow *)node->Data(); | |
1794 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))) | |
1795 | win->SetConstraintSizes(); | |
1796 | node = node->Next(); | |
1797 | } | |
1798 | } | |
1799 | } | |
1800 | ||
1801 | // This assumes that all sizers are 'on' the same | |
1802 | // window, i.e. the parent of this window. | |
1803 | void wxWindow::TransformSizerToActual(int *x, int *y) const | |
1804 | { | |
1805 | if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) || | |
1806 | m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) ) | |
1807 | return; | |
1808 | ||
1809 | int xp, yp; | |
1810 | m_sizerParent->GetPosition(&xp, &yp); | |
1811 | m_sizerParent->TransformSizerToActual(&xp, &yp); | |
1812 | *x += xp; | |
1813 | *y += yp; | |
1814 | } | |
1815 | ||
1816 | void wxWindow::SizerSetSize(int x, int y, int w, int h) | |
1817 | { | |
1818 | int xx = x; | |
1819 | int yy = y; | |
1820 | TransformSizerToActual(&xx, &yy); | |
1821 | SetSize(xx, yy, w, h); | |
1822 | } | |
1823 | ||
1824 | void wxWindow::SizerMove(int x, int y) | |
1825 | { | |
1826 | int xx = x; | |
1827 | int yy = y; | |
1828 | TransformSizerToActual(&xx, &yy); | |
1829 | Move(xx, yy); | |
1830 | } | |
1831 | ||
1832 | // Only set the size/position of the constraint (if any) | |
1833 | void wxWindow::SetSizeConstraint(int x, int y, int w, int h) | |
1834 | { | |
1835 | wxLayoutConstraints *constr = GetConstraints(); | |
1836 | if (constr) | |
1837 | { | |
1838 | if (x != -1) | |
1839 | { | |
1840 | constr->left.SetValue(x); | |
1841 | constr->left.SetDone(TRUE); | |
1842 | } | |
1843 | if (y != -1) | |
1844 | { | |
1845 | constr->top.SetValue(y); | |
1846 | constr->top.SetDone(TRUE); | |
1847 | } | |
1848 | if (w != -1) | |
1849 | { | |
1850 | constr->width.SetValue(w); | |
1851 | constr->width.SetDone(TRUE); | |
1852 | } | |
1853 | if (h != -1) | |
1854 | { | |
1855 | constr->height.SetValue(h); | |
1856 | constr->height.SetDone(TRUE); | |
1857 | } | |
1858 | } | |
1859 | } | |
1860 | ||
1861 | void wxWindow::MoveConstraint(int x, int y) | |
1862 | { | |
1863 | wxLayoutConstraints *constr = GetConstraints(); | |
1864 | if (constr) | |
1865 | { | |
1866 | if (x != -1) | |
1867 | { | |
1868 | constr->left.SetValue(x); | |
1869 | constr->left.SetDone(TRUE); | |
1870 | } | |
1871 | if (y != -1) | |
1872 | { | |
1873 | constr->top.SetValue(y); | |
1874 | constr->top.SetDone(TRUE); | |
1875 | } | |
1876 | } | |
1877 | } | |
1878 | ||
1879 | void wxWindow::GetSizeConstraint(int *w, int *h) const | |
1880 | { | |
1881 | wxLayoutConstraints *constr = GetConstraints(); | |
1882 | if (constr) | |
1883 | { | |
1884 | *w = constr->width.GetValue(); | |
1885 | *h = constr->height.GetValue(); | |
1886 | } | |
1887 | else | |
1888 | GetSize(w, h); | |
1889 | } | |
1890 | ||
1891 | void wxWindow::GetClientSizeConstraint(int *w, int *h) const | |
1892 | { | |
1893 | wxLayoutConstraints *constr = GetConstraints(); | |
1894 | if (constr) | |
1895 | { | |
1896 | *w = constr->width.GetValue(); | |
1897 | *h = constr->height.GetValue(); | |
1898 | } | |
1899 | else | |
1900 | GetClientSize(w, h); | |
1901 | } | |
1902 | ||
1903 | void wxWindow::GetPositionConstraint(int *x, int *y) const | |
1904 | { | |
1905 | wxLayoutConstraints *constr = GetConstraints(); | |
1906 | if (constr) | |
1907 | { | |
1908 | *x = constr->left.GetValue(); | |
1909 | *y = constr->top.GetValue(); | |
1910 | } | |
1911 | else | |
1912 | GetPosition(x, y); | |
1913 | } | |
1914 | ||
1915 | bool wxWindow::Close(bool force) | |
1916 | { | |
1917 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); | |
1918 | event.SetEventObject(this); | |
1919 | event.SetForce(force); | |
1920 | ||
1921 | return GetEventHandler()->ProcessEvent(event); | |
1922 | } | |
1923 | ||
1924 | wxObject* wxWindow::GetChild(int number) const | |
1925 | { | |
1926 | // Return a pointer to the Nth object in the window | |
1927 | if (!GetChildren()) | |
1928 | return(NULL) ; | |
1929 | wxNode *node = GetChildren()->First(); | |
1930 | int n = number; | |
1931 | while (node && n--) | |
1932 | node = node->Next() ; | |
1933 | if (node) | |
1934 | { | |
1935 | wxObject *obj = (wxObject *)node->Data(); | |
1936 | return(obj) ; | |
1937 | } | |
1938 | else | |
1939 | return NULL ; | |
1940 | } | |
1941 | ||
1942 | void wxWindow::OnDefaultAction(wxControl *initiatingItem) | |
1943 | { | |
1944 | // Obsolete function | |
1945 | } | |
1946 | ||
1947 | void wxWindow::Clear() | |
1948 | { | |
e97f20a0 | 1949 | wxClientDC dc(this); |
4bb6408c JS |
1950 | wxBrush brush(GetBackgroundColour(), wxSOLID); |
1951 | dc.SetBackground(brush); | |
1952 | dc.Clear(); | |
1953 | } | |
1954 | ||
1955 | // Fits the panel around the items | |
1956 | void wxWindow::Fit() | |
1957 | { | |
1958 | int maxX = 0; | |
1959 | int maxY = 0; | |
1960 | wxNode *node = GetChildren()->First(); | |
1961 | while ( node ) | |
1962 | { | |
1963 | wxWindow *win = (wxWindow *)node->Data(); | |
1964 | int wx, wy, ww, wh; | |
1965 | win->GetPosition(&wx, &wy); | |
1966 | win->GetSize(&ww, &wh); | |
1967 | if ( wx + ww > maxX ) | |
1968 | maxX = wx + ww; | |
1969 | if ( wy + wh > maxY ) | |
1970 | maxY = wy + wh; | |
1971 | ||
1972 | node = node->Next(); | |
1973 | } | |
1974 | SetClientSize(maxX + 5, maxY + 5); | |
1975 | } | |
1976 | ||
1977 | void wxWindow::SetValidator(const wxValidator& validator) | |
1978 | { | |
1979 | if ( m_windowValidator ) | |
1980 | delete m_windowValidator; | |
1981 | m_windowValidator = validator.Clone(); | |
1982 | ||
1983 | if ( m_windowValidator ) | |
1984 | m_windowValidator->SetWindow(this) ; | |
3dd4e4e0 JS |
1985 | } |
1986 | ||
1987 | void wxWindow::SetClientObject( wxClientData *data ) | |
1988 | { | |
1989 | if (m_clientObject) delete m_clientObject; | |
1990 | m_clientObject = data; | |
1991 | } | |
1992 | ||
1993 | wxClientData *wxWindow::GetClientObject() | |
1994 | { | |
1995 | return m_clientObject; | |
1996 | } | |
1997 | ||
1998 | void wxWindow::SetClientData( void *data ) | |
1999 | { | |
2000 | m_clientData = data; | |
2001 | } | |
2002 | ||
2003 | void *wxWindow::GetClientData() | |
2004 | { | |
2005 | return m_clientData; | |
4bb6408c JS |
2006 | } |
2007 | ||
2008 | // Find a window by id or name | |
2009 | wxWindow *wxWindow::FindWindow(long id) | |
2010 | { | |
2011 | if ( GetId() == id) | |
2012 | return this; | |
2013 | ||
2014 | wxNode *node = GetChildren()->First(); | |
2015 | while ( node ) | |
2016 | { | |
2017 | wxWindow *child = (wxWindow *)node->Data(); | |
2018 | wxWindow *found = child->FindWindow(id); | |
2019 | if ( found ) | |
2020 | return found; | |
2021 | node = node->Next(); | |
2022 | } | |
2023 | return NULL; | |
2024 | } | |
2025 | ||
2026 | wxWindow *wxWindow::FindWindow(const wxString& name) | |
2027 | { | |
2028 | if ( GetName() == name) | |
2029 | return this; | |
2030 | ||
2031 | wxNode *node = GetChildren()->First(); | |
2032 | while ( node ) | |
2033 | { | |
2034 | wxWindow *child = (wxWindow *)node->Data(); | |
2035 | wxWindow *found = child->FindWindow(name); | |
2036 | if ( found ) | |
2037 | return found; | |
2038 | node = node->Next(); | |
2039 | } | |
2040 | return NULL; | |
2041 | } | |
2042 | ||
2043 | void wxWindow::OnIdle(wxIdleEvent& event) | |
2044 | { | |
4bb6408c JS |
2045 | // This calls the UI-update mechanism (querying windows for |
2046 | // menu/toolbar/control state information) | |
0d57be45 | 2047 | UpdateWindowUI(); |
4bb6408c JS |
2048 | } |
2049 | ||
2050 | // Raise the window to the top of the Z order | |
2051 | void wxWindow::Raise() | |
2052 | { | |
02e8b2f9 JS |
2053 | Window window = XtWindow((Widget) GetTopWidget()); |
2054 | XRaiseWindow(XtDisplay((Widget) GetTopWidget()), window); | |
4bb6408c JS |
2055 | } |
2056 | ||
2057 | // Lower the window to the bottom of the Z order | |
2058 | void wxWindow::Lower() | |
2059 | { | |
02e8b2f9 JS |
2060 | Window window = XtWindow((Widget) GetTopWidget()); |
2061 | XLowerWindow(XtDisplay((Widget) GetTopWidget()), window); | |
4bb6408c JS |
2062 | } |
2063 | ||
2064 | bool wxWindow::AcceptsFocus() const | |
2065 | { | |
2066 | return IsShown() && IsEnabled(); | |
2067 | } | |
2068 | ||
2069 | // Update region access | |
55acd85e | 2070 | wxRegion& wxWindow::GetUpdateRegion() const |
4bb6408c | 2071 | { |
55acd85e | 2072 | return (wxRegion&) m_updateRegion; |
4bb6408c JS |
2073 | } |
2074 | ||
2075 | bool wxWindow::IsExposed(int x, int y, int w, int h) const | |
2076 | { | |
2077 | return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion); | |
2078 | } | |
2079 | ||
2080 | bool wxWindow::IsExposed(const wxPoint& pt) const | |
2081 | { | |
2082 | return (m_updateRegion.Contains(pt) != wxOutRegion); | |
2083 | } | |
2084 | ||
2085 | bool wxWindow::IsExposed(const wxRect& rect) const | |
2086 | { | |
2087 | return (m_updateRegion.Contains(rect) != wxOutRegion); | |
2088 | } | |
2089 | ||
2090 | /* | |
2091 | * Allocates control IDs | |
2092 | */ | |
2093 | ||
2094 | int wxWindow::NewControlId() | |
2095 | { | |
2096 | static int s_controlId = 0; | |
2097 | s_controlId ++; | |
2098 | return s_controlId; | |
2099 | } | |
2100 | ||
2101 | void wxWindow::SetAcceleratorTable(const wxAcceleratorTable& accel) | |
2102 | { | |
2103 | m_acceleratorTable = accel; | |
2104 | } | |
2105 | ||
2106 | // All widgets should have this as their resize proc. | |
2107 | // OnSize sent to wxWindow via client data. | |
2108 | void wxWidgetResizeProc(Widget w, XConfigureEvent *event, String args[], int *num_args) | |
2109 | { | |
2110 | wxWindow *win = (wxWindow *)wxWidgetHashTable->Get((long)w); | |
2111 | if (!win) | |
2112 | return; | |
2113 | ||
2114 | if (win->PreResize()) | |
2115 | { | |
2116 | int width, height; | |
2117 | win->GetSize(&width, &height); | |
2118 | wxSizeEvent sizeEvent(wxSize(width, height), win->GetId()); | |
2119 | sizeEvent.SetEventObject(win); | |
2120 | win->GetEventHandler()->ProcessEvent(sizeEvent); | |
2121 | } | |
2122 | } | |
2123 | ||
2124 | bool wxAddWindowToTable(Widget w, wxWindow *win) | |
2125 | { | |
2126 | wxWindow *oldItem = NULL; | |
4bb6408c | 2127 | // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName()); |
4bb6408c JS |
2128 | if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w))) |
2129 | { | |
2130 | char buf[300]; | |
2131 | sprintf(buf, "Widget table clash: new widget is %ld, %s", (long)w, win->GetClassInfo()->GetClassName()); | |
2132 | wxError (buf); | |
2133 | fflush(stderr); | |
2134 | sprintf(buf, "Old widget was %s", oldItem->GetClassInfo()->GetClassName()); | |
2135 | wxError (buf); | |
2136 | return FALSE; | |
2137 | } | |
2138 | ||
2139 | wxWidgetHashTable->Put ((long) w, win); | |
2140 | return TRUE; | |
2141 | } | |
2142 | ||
2143 | wxWindow *wxGetWindowFromTable(Widget w) | |
2144 | { | |
2145 | return (wxWindow *)wxWidgetHashTable->Get ((long) w); | |
2146 | } | |
2147 | ||
2148 | void wxDeleteWindowFromTable(Widget w) | |
2149 | { | |
4bb6408c JS |
2150 | wxWidgetHashTable->Delete((long)w); |
2151 | } | |
2152 | ||
2153 | // Get the underlying X window and display | |
2154 | WXWindow wxWindow::GetXWindow() const | |
2155 | { | |
50414e24 | 2156 | return (WXWindow) XtWindow((Widget) GetMainWidget()); |
4bb6408c JS |
2157 | } |
2158 | ||
2159 | WXDisplay *wxWindow::GetXDisplay() const | |
2160 | { | |
50414e24 | 2161 | return (WXDisplay*) XtDisplay((Widget) GetMainWidget()); |
4bb6408c JS |
2162 | } |
2163 | ||
2164 | WXWidget wxWindow::GetMainWidget() const | |
2165 | { | |
50414e24 JS |
2166 | if (m_drawingArea) |
2167 | return m_drawingArea; | |
2168 | else | |
2169 | return m_mainWidget; | |
2170 | } | |
2171 | ||
2172 | WXWidget wxWindow::GetClientWidget() const | |
2173 | { | |
2174 | if (m_drawingArea != (WXWidget) 0) | |
2175 | return m_drawingArea; | |
2176 | else | |
02e8b2f9 JS |
2177 | return GetMainWidget(); |
2178 | } | |
2179 | ||
2180 | WXWidget wxWindow::GetTopWidget() const | |
2181 | { | |
2182 | return GetMainWidget(); | |
4bb6408c JS |
2183 | } |
2184 | ||
50414e24 JS |
2185 | void wxCanvasRepaintProc (Widget drawingArea, XtPointer clientData, |
2186 | XmDrawingAreaCallbackStruct * cbs) | |
2187 | { | |
2188 | if (!wxWidgetHashTable->Get ((long) (Widget) drawingArea)) | |
55acd85e | 2189 | return; |
50414e24 JS |
2190 | |
2191 | XEvent * event = cbs->event; | |
55acd85e JS |
2192 | wxWindow * win = (wxWindow *) clientData; |
2193 | Display * display = (Display *) win->GetXDisplay(); | |
50414e24 JS |
2194 | |
2195 | switch (event->type) | |
2196 | { | |
55acd85e JS |
2197 | case Expose: |
2198 | { | |
2199 | wxRect* rect = new wxRect(event->xexpose.x, event->xexpose.y, | |
2200 | event->xexpose.width, event->xexpose.height); | |
2201 | /* | |
2202 | cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", "; | |
2203 | cout << rect->width << ", " << rect->height << "\n\n"; | |
2204 | */ | |
50414e24 | 2205 | |
55acd85e | 2206 | win->m_updateRects.Append((wxObject*) rect); |
50414e24 | 2207 | |
55acd85e JS |
2208 | if (event -> xexpose.count == 0) |
2209 | { | |
2210 | wxPaintEvent event(win->GetId()); | |
2211 | event.SetEventObject(win); | |
2212 | win->GetEventHandler()->ProcessEvent(event); | |
50414e24 | 2213 | |
55acd85e JS |
2214 | win->ClearUpdateRects(); |
2215 | } | |
2216 | break; | |
2217 | } | |
2218 | default: | |
2219 | { | |
2220 | cout << "\n\nNew Event ! is = " << event -> type << "\n"; | |
2221 | break; | |
2222 | } | |
50414e24 | 2223 | } |
50414e24 JS |
2224 | } |
2225 | ||
2226 | // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4) | |
2227 | void | |
2228 | wxCanvasEnterLeave (Widget drawingArea, XtPointer clientData, XCrossingEvent * event) | |
2229 | { | |
2230 | XmDrawingAreaCallbackStruct cbs; | |
2231 | XEvent ev; | |
2232 | ||
2233 | //if (event->mode!=NotifyNormal) | |
2234 | // return ; | |
2235 | ||
2236 | // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes) | |
2237 | ((XCrossingEvent &) ev) = *event; | |
2238 | ||
2239 | cbs.reason = XmCR_INPUT; | |
2240 | cbs.event = &ev; | |
2241 | ||
2242 | wxCanvasInputEvent (drawingArea, (XtPointer) NULL, &cbs); | |
2243 | } | |
2244 | ||
2245 | // Fix to make it work under Motif 1.0 (!) | |
2246 | void wxCanvasMotionEvent (Widget drawingArea, XButtonEvent * event) | |
2247 | { | |
2248 | #if XmVersion<=1000 | |
4bb6408c | 2249 | |
50414e24 JS |
2250 | XmDrawingAreaCallbackStruct cbs; |
2251 | XEvent ev; | |
2252 | ||
2253 | //ev.xbutton = *event; | |
2254 | ev = *((XEvent *) event); | |
2255 | cbs.reason = XmCR_INPUT; | |
2256 | cbs.event = &ev; | |
2257 | ||
2258 | wxCanvasInputEvent (drawingArea, (XtPointer) NULL, &cbs); | |
2259 | #endif | |
2260 | } | |
2261 | ||
2262 | void wxCanvasInputEvent (Widget drawingArea, XtPointer data, XmDrawingAreaCallbackStruct * cbs) | |
2263 | { | |
2264 | wxWindow *canvas = (wxWindow *) wxWidgetHashTable->Get ((long) (Widget) drawingArea); | |
2265 | XEvent local_event; | |
2266 | ||
2267 | if (canvas==NULL) | |
2268 | return ; | |
2269 | ||
2270 | if (cbs->reason != XmCR_INPUT) | |
2271 | return; | |
2272 | ||
2273 | local_event = *(cbs->event); // We must keep a copy! | |
2274 | ||
f57fe24c JS |
2275 | /* |
2276 | switch (local_event.xany.type) | |
2277 | { | |
2278 | case EnterNotify: | |
2279 | cout << "EnterNotify\n"; | |
2280 | break; | |
2281 | case LeaveNotify: | |
2282 | cout << "LeaveNotify\n"; | |
2283 | break; | |
2284 | case ButtonPress: | |
2285 | cout << "ButtonPress\n"; | |
2286 | break; | |
2287 | case ButtonRelease: | |
2288 | cout << "ButtonRelease\n"; | |
2289 | break; | |
2290 | case MotionNotify: | |
2291 | cout << "MotionNotify\n"; | |
2292 | break; | |
2293 | default: | |
2294 | cout << "Something else\n"; | |
2295 | break; | |
2296 | } | |
2297 | */ | |
2298 | ||
50414e24 JS |
2299 | switch (local_event.xany.type) |
2300 | { | |
2301 | case EnterNotify: | |
2302 | case LeaveNotify: | |
2303 | case ButtonPress: | |
2304 | case ButtonRelease: | |
2305 | case MotionNotify: | |
2306 | { | |
2307 | wxEventType eventType = wxEVT_NULL; | |
2308 | ||
2309 | if (local_event.xany.type == EnterNotify) | |
2310 | { | |
2311 | //if (local_event.xcrossing.mode!=NotifyNormal) | |
2312 | // return ; // Ignore grab events | |
2313 | eventType = wxEVT_ENTER_WINDOW; | |
2314 | // canvas->GetEventHandler()->OnSetFocus(); | |
2315 | } | |
2316 | else if (local_event.xany.type == LeaveNotify) | |
2317 | { | |
2318 | //if (local_event.xcrossing.mode!=NotifyNormal) | |
2319 | // return ; // Ignore grab events | |
2320 | eventType = wxEVT_LEAVE_WINDOW; | |
2321 | // canvas->GetEventHandler()->OnKillFocus(); | |
2322 | } | |
2323 | else if (local_event.xany.type == MotionNotify) | |
2324 | { | |
2325 | eventType = wxEVT_MOTION; | |
2326 | if (local_event.xmotion.is_hint == NotifyHint) | |
2327 | { | |
2328 | Window root, child; | |
2329 | Display *dpy = XtDisplay (drawingArea); | |
2330 | ||
2331 | XQueryPointer (dpy, XtWindow (drawingArea), | |
2332 | &root, &child, | |
2333 | &local_event.xmotion.x_root, | |
2334 | &local_event.xmotion.y_root, | |
2335 | &local_event.xmotion.x, | |
2336 | &local_event.xmotion.y, | |
2337 | &local_event.xmotion.state); | |
2338 | } | |
2339 | else | |
2340 | { | |
2341 | } | |
2342 | } | |
2343 | ||
2344 | else if (local_event.xany.type == ButtonPress) | |
2345 | { | |
2346 | if (local_event.xbutton.button == Button1) | |
2347 | { | |
2348 | eventType = wxEVT_LEFT_DOWN; | |
2349 | canvas->m_button1Pressed = TRUE; | |
2350 | } | |
2351 | else if (local_event.xbutton.button == Button2) | |
2352 | { | |
2353 | eventType = wxEVT_MIDDLE_DOWN; | |
2354 | canvas->m_button2Pressed = TRUE; | |
2355 | } | |
2356 | else if (local_event.xbutton.button == Button3) | |
2357 | { | |
2358 | eventType = wxEVT_RIGHT_DOWN; | |
2359 | canvas->m_button3Pressed = TRUE; | |
2360 | } | |
2361 | } | |
2362 | else if (local_event.xany.type == ButtonRelease) | |
2363 | { | |
2364 | if (local_event.xbutton.button == Button1) | |
2365 | { | |
2366 | eventType = wxEVT_LEFT_UP; | |
2367 | canvas->m_button1Pressed = FALSE; | |
2368 | } | |
2369 | else if (local_event.xbutton.button == Button2) | |
2370 | { | |
2371 | eventType = wxEVT_MIDDLE_UP; | |
2372 | canvas->m_button2Pressed = FALSE; | |
2373 | } | |
2374 | else if (local_event.xbutton.button == Button3) | |
2375 | { | |
2376 | eventType = wxEVT_RIGHT_UP; | |
2377 | canvas->m_button3Pressed = FALSE; | |
2378 | } | |
2379 | } | |
2380 | ||
2381 | wxMouseEvent wxevent (eventType); | |
2382 | wxevent.m_eventHandle = (char *) &local_event; | |
2383 | ||
2384 | wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN) | |
2385 | || (event_left_is_down (&local_event) | |
2386 | && (eventType != wxEVT_LEFT_UP))); | |
2387 | wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN) | |
2388 | || (event_middle_is_down (&local_event) | |
2389 | && (eventType != wxEVT_MIDDLE_UP))); | |
2390 | wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN) | |
2391 | || (event_right_is_down (&local_event) | |
2392 | && (eventType != wxEVT_RIGHT_UP))); | |
2393 | ||
2394 | wxevent.m_shiftDown = local_event.xbutton.state & ShiftMask; | |
2395 | wxevent.m_controlDown = local_event.xbutton.state & ControlMask; | |
2396 | wxevent.m_altDown = local_event.xbutton.state & Mod3Mask; | |
2397 | wxevent.m_metaDown = local_event.xbutton.state & Mod1Mask; | |
2398 | wxevent.SetTimestamp(local_event.xbutton.time); | |
2399 | ||
2400 | // Now check if we need to translate this event into a double click | |
2401 | if (TRUE) // canvas->doubleClickAllowed) | |
2402 | { | |
2403 | if (wxevent.ButtonDown()) | |
2404 | { | |
2405 | long dclickTime = XtGetMultiClickTime((Display*) wxGetDisplay()) ; | |
2406 | ||
2407 | // get button and time-stamp | |
2408 | int button = 0; | |
2409 | if (wxevent.LeftDown()) button = 1; | |
2410 | else if (wxevent.MiddleDown()) button = 2; | |
2411 | else if (wxevent.RightDown()) button = 3; | |
2412 | long ts = wxevent.GetTimestamp(); | |
2413 | // check, if single or double click | |
2414 | if (canvas->m_lastButton && canvas->m_lastButton==button && (ts - canvas->m_lastTS) < dclickTime) | |
2415 | { | |
2416 | // I have a dclick | |
2417 | canvas->m_lastButton = 0; | |
2418 | switch ( eventType ) | |
2419 | { | |
2420 | case wxEVT_LEFT_DOWN: | |
2421 | wxevent.SetEventType(wxEVT_LEFT_DCLICK); | |
2422 | break; | |
2423 | case wxEVT_MIDDLE_DOWN: | |
2424 | wxevent.SetEventType(wxEVT_MIDDLE_DCLICK); | |
2425 | break; | |
2426 | case wxEVT_RIGHT_DOWN: | |
2427 | wxevent.SetEventType(wxEVT_RIGHT_DCLICK); | |
2428 | break; | |
2429 | ||
2430 | default : | |
2431 | break; | |
2432 | } | |
2433 | ||
2434 | } | |
2435 | else | |
2436 | { | |
2437 | // not fast enough or different button | |
2438 | canvas->m_lastTS = ts; | |
2439 | canvas->m_lastButton = button; | |
2440 | } | |
2441 | } | |
2442 | } | |
2443 | ||
2444 | wxevent.SetId(canvas->GetId()); | |
2445 | wxevent.SetEventObject(canvas); | |
a4294b78 JS |
2446 | wxevent.m_x = local_event.xbutton.x; |
2447 | wxevent.m_y = local_event.xbutton.y; | |
50414e24 JS |
2448 | canvas->GetEventHandler()->ProcessEvent (wxevent); |
2449 | /* | |
2450 | if (eventType == wxEVT_ENTER_WINDOW || | |
2451 | eventType == wxEVT_LEAVE_WINDOW || | |
2452 | eventType == wxEVT_MOTION | |
2453 | ) | |
2454 | return; | |
2455 | */ | |
2456 | break; | |
2457 | } | |
2458 | case KeyPress: | |
2459 | { | |
2460 | KeySym keySym; | |
2461 | // XComposeStatus compose; | |
2462 | // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose); | |
2463 | (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL); | |
2464 | int id = wxCharCodeXToWX (keySym); | |
2465 | ||
2466 | wxKeyEvent event (wxEVT_CHAR); | |
2467 | ||
2468 | if (local_event.xkey.state & ShiftMask) | |
2469 | event.m_shiftDown = TRUE; | |
2470 | if (local_event.xkey.state & ControlMask) | |
2471 | event.m_controlDown = TRUE; | |
2472 | if (local_event.xkey.state & Mod3Mask) | |
2473 | event.m_altDown = TRUE; | |
2474 | if (local_event.xkey.state & Mod1Mask) | |
2475 | event.m_metaDown = TRUE; | |
2476 | event.SetEventObject(canvas); | |
2477 | event.m_keyCode = id; | |
2478 | event.SetTimestamp(local_event.xkey.time); | |
2479 | ||
2480 | if (id > -1) | |
2481 | { | |
2482 | // Implement wxFrame::OnCharHook by checking ancestor. | |
2483 | wxWindow *parent = canvas->GetParent(); | |
2484 | while (parent && !parent->IsKindOf(CLASSINFO(wxFrame))) | |
2485 | parent = parent->GetParent(); | |
2486 | ||
2487 | if (parent) | |
2488 | { | |
2489 | event.SetEventType(wxEVT_CHAR_HOOK); | |
2490 | if (parent->GetEventHandler()->ProcessEvent(event)) | |
2491 | return; | |
2492 | event.SetEventType(wxEVT_CHAR); | |
2493 | } | |
2494 | ||
2495 | canvas->GetEventHandler()->ProcessEvent (event); | |
2496 | } | |
2497 | break; | |
2498 | } | |
2499 | case FocusIn: | |
2500 | { | |
2501 | if (local_event.xfocus.detail != NotifyPointer) | |
2502 | { | |
2503 | wxFocusEvent event(wxEVT_SET_FOCUS, canvas->GetId()); | |
2504 | event.SetEventObject(canvas); | |
2505 | canvas->GetEventHandler()->ProcessEvent(event); | |
2506 | } | |
2507 | break; | |
2508 | } | |
2509 | case FocusOut: | |
2510 | { | |
2511 | if (local_event.xfocus.detail != NotifyPointer) | |
2512 | { | |
2513 | wxFocusEvent event(wxEVT_KILL_FOCUS, canvas->GetId()); | |
2514 | event.SetEventObject(canvas); | |
2515 | canvas->GetEventHandler()->ProcessEvent(event); | |
2516 | } | |
2517 | break; | |
2518 | } | |
2519 | default: | |
2520 | break; | |
2521 | } | |
2522 | } | |
2523 | ||
2524 | void wxWindow::DoPaint() | |
2525 | { | |
2526 | //TODO : make a temporary gc so we can do the XCopyArea below | |
2527 | if (0) // m_backingPixmap) | |
2528 | { | |
2529 | /* | |
2530 | Widget drawingArea = (Widget) m_drawingArea; | |
2531 | // int orig = GetDC()->GetLogicalFunction(); | |
2532 | // GetDC()->SetLogicalFunction (wxCOPY); | |
2533 | ||
2534 | // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we | |
2535 | // should be able to calculate them. | |
2536 | XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc, | |
2537 | m_pixmapOffsetX, m_pixmapOffsetY, | |
2538 | m_pixmapWidth, m_pixmapHeight, | |
2539 | 0, 0); | |
2540 | ||
2541 | // GetDC()->SetLogicalFunction (orig); | |
2542 | */ | |
2543 | } | |
2544 | else | |
2545 | { | |
2546 | wxPaintEvent event(GetId()); | |
2547 | event.SetEventObject(this); | |
2548 | GetEventHandler()->ProcessEvent(event); | |
2549 | } | |
2550 | } | |
2551 | ||
2552 | // SetSize, but as per old wxCanvas (with drawing widget etc.) | |
2553 | void wxWindow::CanvasSetSize (int x, int y, int w, int h, int sizeFlags) | |
2554 | { | |
7fe7d506 JS |
2555 | // A bit of optimization to help sort out the flickers. |
2556 | int oldX, oldY, oldW, oldH; | |
2557 | GetSize(& oldW, & oldH); | |
2558 | GetPosition(& oldX, & oldY); | |
2559 | ||
2560 | bool useOldPos = FALSE; | |
2561 | bool useOldSize = FALSE; | |
2562 | ||
2563 | if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0)) | |
2564 | useOldPos = TRUE; | |
2565 | else if (x == oldX && y == oldY) | |
2566 | useOldPos = TRUE; | |
2567 | ||
2568 | if ((w == -1) && (h == -1)) | |
2569 | useOldSize = TRUE; | |
2570 | else if (w == oldW && h == oldH) | |
2571 | useOldSize = TRUE; | |
2572 | ||
2573 | if (useOldPos && useOldSize) | |
2574 | return; | |
2575 | ||
50414e24 JS |
2576 | Widget drawingArea = (Widget) m_drawingArea; |
2577 | bool managed = XtIsManaged(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); | |
2578 | ||
2579 | if (managed) | |
2580 | XtUnmanageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); | |
2581 | XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL); | |
2582 | ||
a4294b78 JS |
2583 | int xx = x; int yy = y; |
2584 | AdjustForParentClientOrigin(xx, yy, sizeFlags); | |
2585 | ||
7fe7d506 JS |
2586 | if (!useOldPos) |
2587 | { | |
2588 | if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
50414e24 JS |
2589 | { |
2590 | XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, | |
a4294b78 | 2591 | XmNx, xx, NULL); |
50414e24 JS |
2592 | } |
2593 | ||
7fe7d506 | 2594 | if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
50414e24 JS |
2595 | { |
2596 | XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, | |
a4294b78 | 2597 | XmNy, yy, NULL); |
50414e24 | 2598 | } |
7fe7d506 | 2599 | } |
50414e24 | 2600 | |
7fe7d506 JS |
2601 | if (!useOldSize) |
2602 | { | |
2603 | ||
2604 | if (w > -1) | |
50414e24 JS |
2605 | { |
2606 | if (m_borderWidget) | |
2607 | { | |
2608 | XtVaSetValues ((Widget) m_borderWidget, XmNwidth, w, NULL); | |
2609 | short thick, margin; | |
2610 | XtVaGetValues ((Widget) m_borderWidget, | |
2611 | XmNshadowThickness, &thick, | |
2612 | XmNmarginWidth, &margin, | |
2613 | NULL); | |
2614 | w -= 2 * (thick + margin); | |
2615 | } | |
2616 | ||
2617 | XtVaSetValues ((Widget) m_scrolledWindow, XmNwidth, w, NULL); | |
2618 | ||
2619 | Dimension spacing; | |
2620 | Widget sbar; | |
2621 | XtVaGetValues ((Widget) m_scrolledWindow, | |
2622 | XmNspacing, &spacing, | |
2623 | XmNverticalScrollBar, &sbar, | |
2624 | NULL); | |
2625 | Dimension wsbar; | |
2626 | if (sbar) | |
2627 | XtVaGetValues (sbar, XmNwidth, &wsbar, NULL); | |
2628 | else | |
2629 | wsbar = 0; | |
2630 | ||
2631 | w -= (spacing + wsbar); | |
2632 | ||
2633 | XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL); | |
2634 | } | |
2635 | if (h > -1) | |
2636 | { | |
2637 | if (m_borderWidget) | |
2638 | { | |
2639 | XtVaSetValues ((Widget) m_borderWidget, XmNheight, h, NULL); | |
2640 | short thick, margin; | |
2641 | XtVaGetValues ((Widget) m_borderWidget, | |
2642 | XmNshadowThickness, &thick, | |
2643 | XmNmarginHeight, &margin, | |
2644 | NULL); | |
2645 | h -= 2 * (thick + margin); | |
2646 | } | |
2647 | ||
2648 | XtVaSetValues ((Widget) m_scrolledWindow, XmNheight, h, NULL); | |
2649 | ||
2650 | Dimension spacing; | |
2651 | Widget sbar; | |
2652 | XtVaGetValues ((Widget) m_scrolledWindow, | |
2653 | XmNspacing, &spacing, | |
2654 | XmNhorizontalScrollBar, &sbar, | |
2655 | NULL); | |
2656 | Dimension wsbar; | |
2657 | if (sbar) | |
2658 | XtVaGetValues (sbar, XmNheight, &wsbar, NULL); | |
2659 | else | |
2660 | wsbar = 0; | |
2661 | ||
2662 | h -= (spacing + wsbar); | |
2663 | ||
2664 | XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL); | |
2665 | } | |
7fe7d506 JS |
2666 | } |
2667 | ||
50414e24 JS |
2668 | if (managed) |
2669 | XtManageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); | |
2670 | XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL); | |
2671 | ||
7fe7d506 | 2672 | /* |
50414e24 JS |
2673 | int ww, hh; |
2674 | GetClientSize (&ww, &hh); | |
2675 | wxSizeEvent sizeEvent(wxSize(ww, hh), GetId()); | |
2676 | sizeEvent.SetEventObject(this); | |
2677 | ||
2678 | GetEventHandler()->ProcessEvent(sizeEvent); | |
7fe7d506 JS |
2679 | */ |
2680 | ||
50414e24 JS |
2681 | } |
2682 | ||
2683 | void wxWindow::CanvasSetClientSize (int w, int h) | |
2684 | { | |
2685 | Widget drawingArea = (Widget) m_drawingArea; | |
2686 | ||
2687 | XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL); | |
2688 | ||
2689 | if (w > -1) | |
2690 | XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL); | |
2691 | if (h > -1) | |
2692 | XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL); | |
2693 | /* TODO: is this necessary? | |
2694 | allowRepainting = FALSE; | |
2695 | ||
2696 | XSync (XtDisplay (drawingArea), FALSE); | |
2697 | XEvent event; | |
2698 | while (XtAppPending (wxTheApp->appContext)) | |
2699 | { | |
2700 | XFlush (XtDisplay (drawingArea)); | |
2701 | XtAppNextEvent (wxTheApp->appContext, &event); | |
2702 | XtDispatchEvent (&event); | |
2703 | } | |
2704 | */ | |
2705 | ||
2706 | XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL); | |
2707 | ||
2708 | /* TODO | |
2709 | allowRepainting = TRUE; | |
2710 | DoRefresh (); | |
2711 | */ | |
2712 | ||
7fe7d506 | 2713 | /* |
50414e24 JS |
2714 | wxSizeEvent sizeEvent(wxSize(w, h), GetId()); |
2715 | sizeEvent.SetEventObject(this); | |
2716 | ||
2717 | GetEventHandler()->ProcessEvent(sizeEvent); | |
7fe7d506 | 2718 | */ |
50414e24 JS |
2719 | } |
2720 | ||
2721 | void wxWindow::CanvasGetClientSize (int *w, int *h) const | |
2722 | { | |
2723 | // Must return the same thing that was set via SetClientSize | |
2724 | Dimension xx, yy; | |
2725 | XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL); | |
2726 | *w = xx; | |
2727 | *h = yy; | |
2728 | } | |
2729 | ||
2730 | void wxWindow::CanvasGetSize (int *w, int *h) const | |
2731 | { | |
2732 | Dimension xx, yy; | |
2733 | if ((Widget) m_borderWidget) | |
2734 | XtVaGetValues ((Widget) m_borderWidget, XmNwidth, &xx, XmNheight, &yy, NULL); | |
2735 | else if ((Widget) m_scrolledWindow) | |
2736 | XtVaGetValues ((Widget) m_scrolledWindow, XmNwidth, &xx, XmNheight, &yy, NULL); | |
2737 | else | |
2738 | XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL); | |
2739 | ||
2740 | *w = xx; | |
2741 | *h = yy; | |
2742 | } | |
2743 | ||
2744 | void wxWindow::CanvasGetPosition (int *x, int *y) const | |
2745 | { | |
a4294b78 JS |
2746 | Position xx, yy; |
2747 | XtVaGetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, XmNx, &xx, XmNy, &yy, NULL); | |
2748 | ||
2749 | // We may be faking the client origin. | |
2750 | // So a window that's really at (0, 30) may appear | |
2751 | // (to wxWin apps) to be at (0, 0). | |
2752 | if (GetParent()) | |
2753 | { | |
2754 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
2755 | xx -= pt.x; | |
2756 | yy -= pt.y; | |
2757 | } | |
2758 | ||
2759 | *x = xx; | |
2760 | *y = yy; | |
50414e24 | 2761 | } |
02e8b2f9 JS |
2762 | |
2763 | // Add to hash table, add event handler | |
2764 | bool wxWindow::AttachWidget (wxWindow* parent, WXWidget mainWidget, | |
2765 | WXWidget formWidget, int x, int y, int width, int height) | |
2766 | { | |
2767 | wxAddWindowToTable((Widget) mainWidget, this); | |
2768 | if (CanAddEventHandler()) | |
2769 | { | |
2770 | XtAddEventHandler((Widget) mainWidget, | |
2771 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask, | |
2772 | False, | |
2773 | wxPanelItemEventHandler, | |
2774 | (XtPointer) this); | |
2775 | } | |
2776 | ||
2777 | if (!formWidget) | |
2778 | { | |
2779 | XtTranslations ptr; | |
2780 | XtOverrideTranslations ((Widget) mainWidget, | |
2781 | ptr = XtParseTranslationTable ("<Configure>: resize()")); | |
2782 | XtFree ((char *) ptr); | |
2783 | } | |
2784 | ||
2785 | // Some widgets have a parent form widget, e.g. wxRadioBox | |
2786 | if (formWidget) | |
2787 | { | |
2788 | if (!wxAddWindowToTable((Widget) formWidget, this)) | |
2789 | return FALSE; | |
2790 | ||
2791 | XtTranslations ptr; | |
2792 | XtOverrideTranslations ((Widget) formWidget, | |
2793 | ptr = XtParseTranslationTable ("<Configure>: resize()")); | |
2794 | XtFree ((char *) ptr); | |
2795 | } | |
2796 | ||
2797 | if (x == -1) | |
2798 | x = 0; | |
2799 | if (y == -1) | |
2800 | y = 0; | |
2801 | SetSize (x, y, width, height); | |
2802 | ||
2803 | return TRUE; | |
2804 | } | |
2805 | ||
2806 | // Remove event handler, remove from hash table | |
2807 | bool wxWindow::DetachWidget(WXWidget widget) | |
2808 | { | |
2809 | if (CanAddEventHandler()) | |
2810 | { | |
2811 | XtRemoveEventHandler((Widget) widget, | |
2812 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask, | |
2813 | False, | |
2814 | wxPanelItemEventHandler, | |
2815 | (XtPointer)this); | |
2816 | } | |
2817 | ||
2818 | wxDeleteWindowFromTable((Widget) widget); | |
2819 | return TRUE; | |
2820 | } | |
2821 | ||
2822 | void wxPanelItemEventHandler (Widget wid, | |
2823 | XtPointer client_data, | |
2824 | XEvent* event, | |
2825 | Boolean *continueToDispatch) | |
2826 | { | |
2827 | // Widget can be a label or the actual widget. | |
2828 | ||
2829 | wxWindow *window = (wxWindow *)wxWidgetHashTable->Get((long)wid); | |
2830 | if (window) | |
2831 | { | |
2832 | wxMouseEvent wxevent(0); | |
2833 | if (wxTranslateMouseEvent(wxevent, window, wid, event)) | |
2834 | { | |
2835 | window->GetEventHandler()->ProcessEvent(wxevent); | |
2836 | } | |
2837 | } | |
2838 | // TODO: probably the key to allowing default behaviour | |
2839 | // to happen. | |
2840 | // Say we set a m_doDefault flag to FALSE at the start of this | |
2841 | // function. Then in e.g. wxWindow::OnMouseEvent we can | |
2842 | // call Default() which sets this flag to TRUE, indicating | |
2843 | // that default processing can happen. Thus, behaviour can appear | |
2844 | // to be overridden just by adding an event handler and not calling | |
2845 | // wxWindow::OnWhatever. | |
2846 | // ALSO, maybe we can use this instead of the current way of handling | |
2847 | // drawing area events, to simplify things. | |
2848 | *continueToDispatch = True; | |
2849 | } | |
2850 | ||
8aa04e8b | 2851 | static void wxScrollBarCallback(Widget scrollbar, XtPointer clientData, |
47bc1060 JS |
2852 | XmScaleCallbackStruct *cbs) |
2853 | { | |
2854 | Widget scrolledWindow = XtParent (scrollbar); | |
2855 | wxWindow *win = (wxWindow *) wxWidgetHashTable->Get ((long) scrolledWindow); | |
2856 | int orientation = (int) clientData; | |
2857 | ||
2858 | wxEventType eventType = wxEVT_NULL; | |
2859 | switch (cbs->reason) | |
2860 | { | |
2861 | case XmCR_INCREMENT: | |
2862 | { | |
2863 | eventType = wxEVT_SCROLL_LINEDOWN; | |
2864 | break; | |
2865 | } | |
2866 | case XmCR_DECREMENT: | |
2867 | { | |
2868 | eventType = wxEVT_SCROLL_LINEUP; | |
2869 | break; | |
2870 | } | |
2871 | case XmCR_DRAG: | |
2872 | { | |
2873 | eventType = wxEVT_SCROLL_THUMBTRACK; | |
2874 | break; | |
2875 | } | |
2876 | case XmCR_VALUE_CHANGED: | |
2877 | { | |
2878 | // TODO: Should this be intercepted too, or will it cause | |
2879 | // duplicate events? | |
2880 | eventType = wxEVT_SCROLL_THUMBTRACK; | |
2881 | break; | |
2882 | } | |
2883 | case XmCR_PAGE_INCREMENT: | |
2884 | { | |
2885 | eventType = wxEVT_SCROLL_PAGEDOWN; | |
2886 | break; | |
2887 | } | |
2888 | case XmCR_PAGE_DECREMENT: | |
2889 | { | |
2890 | eventType = wxEVT_SCROLL_PAGEUP; | |
2891 | break; | |
2892 | } | |
2893 | case XmCR_TO_TOP: | |
2894 | { | |
2895 | eventType = wxEVT_SCROLL_TOP; | |
2896 | break; | |
2897 | } | |
2898 | case XmCR_TO_BOTTOM: | |
2899 | { | |
2900 | eventType = wxEVT_SCROLL_BOTTOM; | |
2901 | break; | |
2902 | } | |
2903 | default: | |
2904 | { | |
2905 | // Should never get here | |
2906 | wxFAIL_MSG("Unknown scroll event."); | |
2907 | break; | |
2908 | } | |
2909 | } | |
2910 | ||
2911 | wxScrollEvent event(eventType, win->GetId()); | |
2912 | event.SetEventObject(win); | |
2913 | event.SetPosition(cbs->value); | |
2914 | event.SetOrientation( (orientation == XmHORIZONTAL) ? wxHORIZONTAL : wxVERTICAL ); | |
2915 | ||
2916 | win->GetEventHandler()->ProcessEvent(event); | |
2917 | } | |
2918 | ||
02e8b2f9 JS |
2919 | bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent) |
2920 | { | |
2921 | switch (xevent->xany.type) | |
2922 | { | |
2923 | case EnterNotify: | |
2924 | case LeaveNotify: | |
2925 | case ButtonPress: | |
2926 | case ButtonRelease: | |
2927 | case MotionNotify: | |
2928 | { | |
2929 | wxEventType eventType = wxEVT_NULL; | |
2930 | ||
2931 | if (xevent->xany.type == LeaveNotify) | |
2932 | { | |
2933 | win->m_button1Pressed = FALSE; | |
2934 | win->m_button2Pressed = FALSE; | |
2935 | win->m_button3Pressed = FALSE; | |
2936 | return FALSE; | |
2937 | } | |
2938 | else if (xevent->xany.type == MotionNotify) | |
2939 | { | |
2940 | eventType = wxEVT_MOTION; | |
2941 | } | |
2942 | else if (xevent->xany.type == ButtonPress) | |
2943 | { | |
2944 | if (xevent->xbutton.button == Button1) | |
2945 | { | |
2946 | eventType = wxEVT_LEFT_DOWN; | |
2947 | win->m_button1Pressed = TRUE; | |
2948 | } | |
2949 | else if (xevent->xbutton.button == Button2) | |
2950 | { | |
2951 | eventType = wxEVT_MIDDLE_DOWN; | |
2952 | win->m_button2Pressed = TRUE; | |
2953 | } | |
2954 | else if (xevent->xbutton.button == Button3) | |
2955 | { | |
2956 | eventType = wxEVT_RIGHT_DOWN; | |
2957 | win->m_button3Pressed = TRUE; | |
2958 | } | |
2959 | } | |
2960 | else if (xevent->xany.type == ButtonRelease) | |
2961 | { | |
2962 | if (xevent->xbutton.button == Button1) | |
2963 | { | |
2964 | eventType = wxEVT_LEFT_UP; | |
2965 | win->m_button1Pressed = FALSE; | |
2966 | } | |
2967 | else if (xevent->xbutton.button == Button2) | |
2968 | { | |
2969 | eventType = wxEVT_MIDDLE_UP; | |
2970 | win->m_button2Pressed = FALSE; | |
2971 | } | |
2972 | else if (xevent->xbutton.button == Button3) | |
2973 | { | |
2974 | eventType = wxEVT_RIGHT_UP; | |
2975 | win->m_button3Pressed = FALSE; | |
2976 | } | |
2977 | else return FALSE; | |
2978 | } | |
2979 | else return FALSE; | |
2980 | ||
2981 | wxevent.m_eventHandle = (char *)xevent; | |
2982 | wxevent.SetEventType(eventType); | |
2983 | ||
2984 | Position x1, y1; | |
2985 | XtVaGetValues(widget, XmNx, &x1, XmNy, &y1, NULL); | |
2986 | ||
2987 | int x2, y2; | |
2988 | win->GetPosition(&x2, &y2); | |
2989 | ||
2990 | // The button x/y must be translated to wxWindows | |
2991 | // window space - the widget might be a label or button, | |
2992 | // within a form. | |
2993 | int dx = 0; | |
2994 | int dy = 0; | |
2995 | if (widget != (Widget)win->GetMainWidget()) | |
2996 | { | |
2997 | dx = x1; | |
2998 | dy = y1; | |
2999 | } | |
3000 | ||
3001 | wxevent.m_x = xevent->xbutton.x + dx; | |
3002 | wxevent.m_y = xevent->xbutton.y + dy; | |
3003 | ||
3004 | wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN) | |
3005 | || (event_left_is_down (xevent) | |
3006 | && (eventType != wxEVT_LEFT_UP))); | |
3007 | wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN) | |
3008 | || (event_middle_is_down (xevent) | |
3009 | && (eventType != wxEVT_MIDDLE_UP))); | |
3010 | wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN) | |
3011 | || (event_right_is_down (xevent) | |
3012 | && (eventType != wxEVT_RIGHT_UP))); | |
3013 | ||
3014 | wxevent.m_shiftDown = xevent->xbutton.state & ShiftMask; | |
3015 | wxevent.m_controlDown = xevent->xbutton.state & ControlMask; | |
3016 | return TRUE; | |
3017 | } | |
3018 | } | |
3019 | return FALSE; | |
3020 | } | |
3021 | ||
3022 | bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent) | |
3023 | { | |
3024 | switch (xevent->xany.type) | |
3025 | { | |
3026 | case KeyPress: | |
3027 | { | |
3028 | char buf[20]; | |
3029 | ||
3030 | KeySym keySym; | |
3031 | // XComposeStatus compose; | |
3032 | // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose); | |
3033 | (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL); | |
3034 | int id = wxCharCodeXToWX (keySym); | |
3035 | ||
3036 | if (xevent->xkey.state & ShiftMask) | |
3037 | wxevent.m_shiftDown = TRUE; | |
3038 | if (xevent->xkey.state & ControlMask) | |
3039 | wxevent.m_controlDown = TRUE; | |
3040 | if (xevent->xkey.state & Mod3Mask) | |
3041 | wxevent.m_altDown = TRUE; | |
3042 | if (xevent->xkey.state & Mod1Mask) | |
3043 | wxevent.m_metaDown = TRUE; | |
3044 | wxevent.SetEventObject(win); | |
3045 | wxevent.m_keyCode = id; | |
3046 | wxevent.SetTimestamp(xevent->xkey.time); | |
3047 | ||
3048 | wxevent.m_x = xevent->xbutton.x; | |
3049 | wxevent.m_y = xevent->xbutton.y; | |
3050 | ||
3051 | if (id > -1) | |
3052 | return TRUE; | |
3053 | else | |
3054 | return FALSE; | |
3055 | break; | |
3056 | } | |
3057 | default: | |
3058 | break; | |
3059 | } | |
3060 | return FALSE; | |
3061 | } | |
3062 | ||
02e8b2f9 | 3063 | #define YAllocColor XAllocColor |
0d57be45 JS |
3064 | XColor g_itemColors[5]; |
3065 | int wxComputeColours (Display *display, wxColour * back, wxColour * fore) | |
02e8b2f9 JS |
3066 | { |
3067 | int result; | |
3068 | static XmColorProc colorProc; | |
3069 | ||
3070 | result = wxNO_COLORS; | |
3071 | ||
3072 | if (back) | |
3073 | { | |
0d57be45 JS |
3074 | g_itemColors[0].red = (((long) back->Red ()) << 8); |
3075 | g_itemColors[0].green = (((long) back->Green ()) << 8); | |
3076 | g_itemColors[0].blue = (((long) back->Blue ()) << 8); | |
3077 | g_itemColors[0].flags = DoRed | DoGreen | DoBlue; | |
02e8b2f9 JS |
3078 | if (colorProc == (XmColorProc) NULL) |
3079 | { | |
3080 | // Get a ptr to the actual function | |
3081 | colorProc = XmSetColorCalculation ((XmColorProc) NULL); | |
3082 | // And set it back to motif. | |
3083 | XmSetColorCalculation (colorProc); | |
3084 | } | |
0d57be45 JS |
3085 | (*colorProc) (&g_itemColors[wxBACK_INDEX], |
3086 | &g_itemColors[wxFORE_INDEX], | |
3087 | &g_itemColors[wxSELE_INDEX], | |
3088 | &g_itemColors[wxTOPS_INDEX], | |
3089 | &g_itemColors[wxBOTS_INDEX]); | |
02e8b2f9 JS |
3090 | result = wxBACK_COLORS; |
3091 | } | |
3092 | if (fore) | |
3093 | { | |
0d57be45 JS |
3094 | g_itemColors[wxFORE_INDEX].red = (((long) fore->Red ()) << 8); |
3095 | g_itemColors[wxFORE_INDEX].green = (((long) fore->Green ()) << 8); | |
3096 | g_itemColors[wxFORE_INDEX].blue = (((long) fore->Blue ()) << 8); | |
3097 | g_itemColors[wxFORE_INDEX].flags = DoRed | DoGreen | DoBlue; | |
02e8b2f9 JS |
3098 | if (result == wxNO_COLORS) |
3099 | result = wxFORE_COLORS; | |
3100 | } | |
3101 | ||
3102 | Display *dpy = display; | |
3103 | Colormap cmap = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) dpy); | |
3104 | ||
3105 | if (back) | |
3106 | { | |
3107 | /* 5 Colours to allocate */ | |
3108 | for (int i = 0; i < 5; i++) | |
0d57be45 | 3109 | if (!YAllocColor (dpy, cmap, &g_itemColors[i])) |
02e8b2f9 JS |
3110 | result = wxNO_COLORS; |
3111 | } | |
3112 | else if (fore) | |
3113 | { | |
3114 | /* Only 1 colour to allocate */ | |
0d57be45 | 3115 | if (!YAllocColor (dpy, cmap, &g_itemColors[wxFORE_INDEX])) |
02e8b2f9 JS |
3116 | result = wxNO_COLORS; |
3117 | } | |
3118 | ||
3119 | return (result); | |
3120 | ||
3121 | } | |
3122 | ||
0d57be45 JS |
3123 | // Changes the foreground and background colours to be derived |
3124 | // from the current background colour. | |
3125 | // To change the foreground colour, you must call SetForegroundColour | |
3126 | // explicitly. | |
3127 | void wxWindow::ChangeBackgroundColour() | |
02e8b2f9 | 3128 | { |
0d57be45 JS |
3129 | if (GetMainWidget()) |
3130 | DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour); | |
3131 | } | |
02e8b2f9 | 3132 | |
0d57be45 JS |
3133 | void wxWindow::ChangeForegroundColour() |
3134 | { | |
3135 | if (GetMainWidget()) | |
3136 | DoChangeForegroundColour(GetMainWidget(), m_foregroundColour); | |
3137 | } | |
02e8b2f9 | 3138 | |
0d57be45 JS |
3139 | // Change a widget's foreground and background colours. |
3140 | ||
0d57be45 JS |
3141 | void wxWindow::DoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour) |
3142 | { | |
3143 | // When should we specify the foreground, if it's calculated | |
3144 | // by wxComputeColours? | |
3145 | // Solution: say we start with the default (computed) foreground colour. | |
3146 | // If we call SetForegroundColour explicitly for a control or window, | |
3147 | // then the foreground is changed. | |
3148 | // Therefore SetBackgroundColour computes the foreground colour, and | |
3149 | // SetForegroundColour changes the foreground colour. The ordering is | |
3150 | // important. | |
02e8b2f9 | 3151 | |
0d57be45 JS |
3152 | XtVaSetValues ((Widget) widget, |
3153 | XmNforeground, foregroundColour.AllocColour(XtDisplay((Widget) widget)), | |
02e8b2f9 | 3154 | NULL); |
0d57be45 JS |
3155 | } |
3156 | ||
3157 | void wxWindow::DoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour) | |
3158 | { | |
3159 | wxComputeColours (XtDisplay((Widget) widget), & backgroundColour, | |
3160 | (wxColour*) NULL); | |
3161 | ||
3162 | XtVaSetValues ((Widget) widget, | |
3163 | XmNbackground, g_itemColors[wxBACK_INDEX].pixel, | |
3164 | XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel, | |
3165 | XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel, | |
3166 | XmNforeground, g_itemColors[wxFORE_INDEX].pixel, | |
02e8b2f9 | 3167 | NULL); |
0d57be45 JS |
3168 | |
3169 | if (changeArmColour) | |
3170 | XtVaSetValues ((Widget) widget, | |
3171 | XmNarmColor, g_itemColors[wxSELE_INDEX].pixel, | |
3172 | NULL); | |
02e8b2f9 JS |
3173 | } |
3174 | ||
0d57be45 | 3175 | void wxWindow::SetBackgroundColour(const wxColour& col) |
02e8b2f9 | 3176 | { |
0d57be45 JS |
3177 | m_backgroundColour = col; |
3178 | ChangeBackgroundColour(); | |
3179 | } | |
3180 | ||
3181 | void wxWindow::SetForegroundColour(const wxColour& col) | |
3182 | { | |
3183 | m_foregroundColour = col; | |
3184 | ChangeForegroundColour(); | |
3185 | } | |
3186 | ||
4b5f3fe6 | 3187 | void wxWindow::ChangeFont(bool keepOriginalSize) |
0d57be45 JS |
3188 | { |
3189 | // Note that this causes the widget to be resized back | |
3190 | // to its original size! We therefore have to set the size | |
3191 | // back again. TODO: a better way in Motif? | |
0d57be45 JS |
3192 | Widget w = (Widget) GetLabelWidget(); // Usually the main widget |
3193 | if (w && m_windowFont.Ok()) | |
3194 | { | |
3195 | int width, height, width1, height1; | |
3196 | GetSize(& width, & height); | |
3197 | ||
3198 | XtVaSetValues (w, | |
3199 | XmNfontList, (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(w)), | |
02e8b2f9 | 3200 | NULL); |
0d57be45 JS |
3201 | |
3202 | GetSize(& width1, & height1); | |
4b5f3fe6 | 3203 | if (keepOriginalSize && (width != width1 || height != height1)) |
0d57be45 JS |
3204 | { |
3205 | SetSize(-1, -1, width, height); | |
3206 | } | |
3207 | } | |
02e8b2f9 | 3208 | } |
0d57be45 JS |
3209 | |
3210 | void wxWindow::SetFont(const wxFont& font) | |
3211 | { | |
3212 | m_windowFont = font; | |
3213 | ChangeFont(); | |
3214 | } | |
3215 | ||
55acd85e JS |
3216 | void wxWindow::ClearUpdateRects() |
3217 | { | |
3218 | wxNode* node = m_updateRects.First(); | |
3219 | while (node) | |
3220 | { | |
3221 | wxRect* rect = (wxRect*) node->Data(); | |
3222 | delete rect; | |
3223 | node = node->Next(); | |
3224 | } | |
3225 | m_updateRects.Clear(); | |
3226 | } | |
8aa04e8b JS |
3227 | |
3228 | bool wxWindow::ProcessAccelerator(wxKeyEvent& event) | |
3229 | { | |
3230 | if (!m_acceleratorTable.Ok()) | |
3231 | return FALSE; | |
3232 | ||
3233 | int count = m_acceleratorTable.GetCount(); | |
3234 | wxAcceleratorEntry* entries = m_acceleratorTable.GetEntries(); | |
3235 | int i; | |
3236 | for (i = 0; i < count; i++) | |
3237 | { | |
3238 | wxAcceleratorEntry* entry = & (entries[i]); | |
3239 | if (entry->MatchesEvent(event)) | |
3240 | { | |
3241 | // Bingo, we have a match. Now find a control | |
3242 | // that matches the entry command id. | |
3243 | ||
3244 | // Need to go up to the top of the window hierarchy, | |
3245 | // since it might be e.g. a menu item | |
3246 | wxWindow* parent = this; | |
3247 | while (parent && !parent->IsKindOf(CLASSINFO(wxFrame)) && !parent->IsKindOf(CLASSINFO(wxDialog))) | |
3248 | parent = parent->GetParent(); | |
3249 | ||
3250 | if (!parent) | |
3251 | return FALSE; | |
3252 | ||
3253 | if (parent->IsKindOf(CLASSINFO(wxFrame))) | |
3254 | { | |
3255 | // Try for a menu command | |
3256 | wxFrame* frame = (wxFrame*) parent; | |
3257 | if (frame->GetMenuBar()) | |
3258 | { | |
3259 | wxMenuItem* item = frame->GetMenuBar()->FindItemForId(entry->GetCommand()); | |
3260 | if (item) | |
3261 | { | |
3262 | wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, entry->GetCommand()); | |
3263 | commandEvent.SetEventObject(frame); | |
3264 | ||
3265 | // If ProcessEvent returns TRUE (it was handled), then | |
3266 | // the calling code will skip the event handling. | |
3267 | return frame->GetEventHandler()->ProcessEvent(commandEvent); | |
3268 | } | |
3269 | } | |
3270 | } | |
3271 | ||
3272 | // Find a child matching the command id | |
3273 | wxWindow* child = parent->FindWindow(entry->GetCommand()); | |
3274 | ||
3275 | // No such child | |
3276 | if (!child) | |
3277 | return FALSE; | |
3278 | ||
3279 | // Now we process those kinds of windows that we can. | |
3280 | // For now, only buttons. | |
3281 | if (child->IsKindOf(CLASSINFO(wxButton))) | |
3282 | { | |
3283 | wxCommandEvent commandEvent (wxEVT_COMMAND_BUTTON_CLICKED, child->GetId()); | |
3284 | commandEvent.SetEventObject(child); | |
3285 | return child->GetEventHandler()->ProcessEvent(commandEvent); | |
3286 | } | |
3287 | ||
3288 | return FALSE; | |
3289 | } // matches event | |
3290 | }// for | |
3291 | ||
3292 | // We didn't match the key event against an accelerator. | |
3293 | return FALSE; | |
3294 | } | |
3295 |