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