]>
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 | |
89 | m_windowId = 0; | |
90 | m_windowStyle = 0; | |
91 | m_windowParent = NULL; | |
92 | m_windowEventHandler = this; | |
93 | m_windowName = ""; | |
94 | m_windowCursor = *wxSTANDARD_CURSOR; | |
95 | m_children = new wxList; | |
96 | m_constraints = NULL; | |
97 | m_constraintsInvolvedIn = NULL; | |
98 | m_windowSizer = NULL; | |
99 | m_sizerParent = NULL; | |
100 | m_autoLayout = FALSE; | |
101 | m_windowValidator = NULL; | |
102 | m_defaultItem = NULL; | |
103 | m_returnCode = 0; | |
104 | m_caretWidth = 0; m_caretHeight = 0; | |
105 | m_caretEnabled = FALSE; | |
106 | m_caretShown = FALSE; | |
fd71308f JS |
107 | // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; |
108 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; | |
4bb6408c | 109 | m_foregroundColour = *wxBLACK; |
2d120f83 | 110 | |
47d67540 | 111 | #if wxUSE_DRAG_AND_DROP |
4bb6408c JS |
112 | m_pDropTarget = NULL; |
113 | #endif | |
3dd4e4e0 JS |
114 | m_clientObject = (wxClientData*) NULL; |
115 | m_clientData = NULL; | |
2d120f83 | 116 | |
50414e24 | 117 | /// Motif-specific |
a91b47e8 | 118 | m_needsRefresh = TRUE; |
4bb6408c JS |
119 | m_mainWidget = (WXWidget) 0; |
120 | m_button1Pressed = FALSE; | |
121 | m_button2Pressed = FALSE; | |
122 | m_button3Pressed = FALSE; | |
123 | m_winCaptured = FALSE; | |
124 | m_isShown = TRUE; | |
50414e24 JS |
125 | m_hScrollBar = (WXWidget) 0; |
126 | m_vScrollBar = (WXWidget) 0; | |
127 | m_borderWidget = (WXWidget) 0; | |
128 | m_scrolledWindow = (WXWidget) 0; | |
129 | m_drawingArea = (WXWidget) 0; | |
130 | m_hScroll = FALSE; | |
131 | m_vScroll = FALSE; | |
50414e24 JS |
132 | m_backingPixmap = (WXPixmap) 0; |
133 | m_pixmapWidth = 0; | |
134 | m_pixmapHeight = 0; | |
135 | m_pixmapOffsetX = 0; | |
136 | m_pixmapOffsetY = 0; | |
137 | m_lastTS = 0; | |
138 | m_lastButton = 0; | |
02e8b2f9 | 139 | m_canAddEventHandler = FALSE; |
47bc1060 JS |
140 | m_scrollPosX = 0; |
141 | m_scrollPosY = 0; | |
4bb6408c JS |
142 | } |
143 | ||
144 | // Destructor | |
145 | wxWindow::~wxWindow() | |
146 | { | |
1f916a19 JS |
147 | // Remove potential dangling pointer |
148 | if (GetParent() && GetParent()->IsKindOf(CLASSINFO(wxPanel))) | |
149 | { | |
150 | wxPanel* panel = (wxPanel*) GetParent(); | |
151 | if (panel->GetLastFocus() == this) | |
152 | panel->SetLastFocus((wxWindow*) NULL); | |
153 | } | |
154 | ||
f97c9854 | 155 | //// Motif-specific |
2d120f83 | 156 | |
f97c9854 JS |
157 | if (GetMainWidget()) |
158 | DetachWidget(GetMainWidget()); // Removes event handlers | |
2d120f83 | 159 | |
f97c9854 JS |
160 | // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be) |
161 | if (m_drawingArea) | |
162 | { | |
163 | // Destroy children before destroying self | |
164 | DestroyChildren(); | |
2d120f83 | 165 | |
f97c9854 | 166 | if (m_backingPixmap) |
2d120f83 JS |
167 | XFreePixmap (XtDisplay ((Widget) GetMainWidget()), (Pixmap) m_backingPixmap); |
168 | ||
f97c9854 JS |
169 | Widget w = (Widget) m_drawingArea; |
170 | wxDeleteWindowFromTable(w); | |
2d120f83 | 171 | |
f97c9854 JS |
172 | if (w) |
173 | XtDestroyWidget(w); | |
174 | m_mainWidget = (WXWidget) 0; | |
2d120f83 | 175 | |
f97c9854 JS |
176 | // Only if we're _really_ a canvas (not a dialog box/panel) |
177 | if (m_scrolledWindow) | |
178 | { | |
179 | wxDeleteWindowFromTable((Widget) m_scrolledWindow); | |
180 | } | |
2d120f83 | 181 | |
f97c9854 JS |
182 | if (m_hScrollBar) |
183 | { | |
184 | XtUnmanageChild ((Widget) m_hScrollBar); | |
185 | XtDestroyWidget ((Widget) m_hScrollBar); | |
186 | } | |
187 | if (m_vScrollBar) | |
188 | { | |
189 | XtUnmanageChild ((Widget) m_vScrollBar); | |
190 | XtDestroyWidget ((Widget) m_vScrollBar); | |
191 | } | |
192 | if (m_scrolledWindow) | |
193 | { | |
194 | XtUnmanageChild ((Widget) m_scrolledWindow); | |
195 | XtDestroyWidget ((Widget) m_scrolledWindow); | |
196 | } | |
2d120f83 | 197 | |
f97c9854 JS |
198 | if (m_borderWidget) |
199 | { | |
200 | XtDestroyWidget ((Widget) m_borderWidget); | |
201 | m_borderWidget = (WXWidget) 0; | |
202 | } | |
50414e24 | 203 | } |
2d120f83 | 204 | |
f97c9854 | 205 | //// Generic stuff |
2d120f83 JS |
206 | |
207 | // Have to delete constraints/sizer FIRST otherwise | |
208 | // sizers may try to look at deleted windows as they | |
209 | // delete themselves. | |
47d67540 | 210 | #if wxUSE_CONSTRAINTS |
4bb6408c JS |
211 | DeleteRelatedConstraints(); |
212 | if (m_constraints) | |
213 | { | |
214 | // This removes any dangling pointers to this window | |
215 | // in other windows' constraintsInvolvedIn lists. | |
216 | UnsetConstraints(m_constraints); | |
217 | delete m_constraints; | |
218 | m_constraints = NULL; | |
219 | } | |
220 | if (m_windowSizer) | |
221 | { | |
222 | delete m_windowSizer; | |
223 | m_windowSizer = NULL; | |
224 | } | |
225 | // If this is a child of a sizer, remove self from parent | |
226 | if (m_sizerParent) | |
227 | m_sizerParent->RemoveChild((wxWindow *)this); | |
228 | #endif | |
2d120f83 | 229 | |
4bb6408c JS |
230 | if (m_windowParent) |
231 | m_windowParent->RemoveChild(this); | |
2d120f83 | 232 | |
4bb6408c | 233 | DestroyChildren(); |
2d120f83 | 234 | |
4bb6408c JS |
235 | // Destroy the window |
236 | if (GetMainWidget()) | |
237 | { | |
cba2db0c JS |
238 | // If this line (XtDestroyWidget) causes a crash, you may comment it out. |
239 | // Child widgets will get destroyed automatically when a frame | |
240 | // or dialog is destroyed, but before that you may get some memory | |
241 | // leaks and potential layout problems if you delete and then add | |
242 | // child windows. | |
2d120f83 JS |
243 | XtDestroyWidget((Widget) GetMainWidget()); |
244 | SetMainWidget((WXWidget) NULL); | |
4bb6408c | 245 | } |
2d120f83 | 246 | |
4bb6408c JS |
247 | delete m_children; |
248 | m_children = NULL; | |
2d120f83 | 249 | |
4bb6408c JS |
250 | // Just in case the window has been Closed, but |
251 | // we're then deleting immediately: don't leave | |
252 | // dangling pointers. | |
253 | wxPendingDelete.DeleteObject(this); | |
2d120f83 | 254 | |
3dd4e4e0 JS |
255 | if ( m_windowValidator ) delete m_windowValidator; |
256 | if (m_clientObject) delete m_clientObject; | |
2d120f83 | 257 | |
55acd85e | 258 | ClearUpdateRects(); |
4bb6408c JS |
259 | } |
260 | ||
261 | // Destroy the window (delayed, if a managed window) | |
262 | bool wxWindow::Destroy() | |
263 | { | |
264 | delete this; | |
265 | return TRUE; | |
266 | } | |
267 | ||
268 | // Constructor | |
269 | bool wxWindow::Create(wxWindow *parent, wxWindowID id, | |
2d120f83 JS |
270 | const wxPoint& pos, |
271 | const wxSize& size, | |
272 | long style, | |
273 | const wxString& name) | |
4bb6408c JS |
274 | { |
275 | // Generic | |
276 | m_windowId = 0; | |
277 | m_windowStyle = 0; | |
278 | m_windowParent = NULL; | |
279 | m_windowEventHandler = this; | |
280 | m_windowName = ""; | |
281 | m_windowCursor = *wxSTANDARD_CURSOR; | |
282 | m_constraints = NULL; | |
283 | m_constraintsInvolvedIn = NULL; | |
284 | m_windowSizer = NULL; | |
285 | m_sizerParent = NULL; | |
286 | m_autoLayout = FALSE; | |
287 | m_windowValidator = NULL; | |
47d67540 | 288 | #if wxUSE_DRAG_AND_DROP |
4bb6408c JS |
289 | m_pDropTarget = NULL; |
290 | #endif | |
4bb6408c JS |
291 | m_caretWidth = 0; m_caretHeight = 0; |
292 | m_caretEnabled = FALSE; | |
293 | m_caretShown = FALSE; | |
294 | m_minSizeX = -1; | |
295 | m_minSizeY = -1; | |
296 | m_maxSizeX = -1; | |
297 | m_maxSizeY = -1; | |
298 | m_defaultItem = NULL; | |
299 | m_windowParent = NULL; | |
3dd4e4e0 JS |
300 | m_clientObject = (wxClientData*) NULL; |
301 | m_clientData = NULL; | |
2d120f83 | 302 | |
50414e24 | 303 | // Motif-specific |
a91b47e8 | 304 | m_needsRefresh = TRUE; |
02e8b2f9 | 305 | m_canAddEventHandler = FALSE; |
50414e24 JS |
306 | m_mainWidget = (WXWidget) 0; |
307 | m_button1Pressed = FALSE; | |
308 | m_button2Pressed = FALSE; | |
309 | m_button3Pressed = FALSE; | |
310 | m_winCaptured = FALSE; | |
311 | m_isShown = TRUE; | |
312 | m_hScrollBar = (WXWidget) 0; | |
313 | m_vScrollBar = (WXWidget) 0; | |
314 | m_borderWidget = (WXWidget) 0; | |
315 | m_scrolledWindow = (WXWidget) 0; | |
316 | m_drawingArea = (WXWidget) 0; | |
317 | m_hScroll = FALSE; | |
318 | m_vScroll = FALSE; | |
50414e24 JS |
319 | m_backingPixmap = (WXPixmap) 0; |
320 | m_pixmapWidth = 0; | |
321 | m_pixmapHeight = 0; | |
322 | m_pixmapOffsetX = 0; | |
323 | m_pixmapOffsetY = 0; | |
47bc1060 JS |
324 | m_scrollPosX = 0; |
325 | m_scrollPosY = 0; | |
2d120f83 | 326 | |
4bb6408c JS |
327 | if (!parent) |
328 | return FALSE; | |
2d120f83 | 329 | |
4bb6408c | 330 | if (parent) parent->AddChild(this); |
2d120f83 | 331 | |
4bb6408c | 332 | m_returnCode = 0; |
2d120f83 | 333 | |
4bb6408c | 334 | SetName(name); |
2d120f83 | 335 | |
4bb6408c | 336 | if ( id == -1 ) |
2d120f83 | 337 | m_windowId = (int)NewControlId(); |
4bb6408c | 338 | else |
2d120f83 JS |
339 | m_windowId = id; |
340 | ||
fd71308f JS |
341 | // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; |
342 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; | |
4bb6408c | 343 | m_foregroundColour = *wxBLACK; |
2d120f83 | 344 | |
4bb6408c | 345 | m_windowStyle = style; |
2d120f83 | 346 | |
4bb6408c | 347 | if ( id == -1 ) |
2d120f83 | 348 | m_windowId = (int)NewControlId(); |
4bb6408c | 349 | else |
2d120f83 JS |
350 | m_windowId = id; |
351 | ||
50414e24 JS |
352 | //// TODO: we should probably optimize by only creating a |
353 | //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL). | |
354 | //// But for now, let's simplify things by always creating the | |
355 | //// drawing area, since otherwise the translations are different. | |
2d120f83 JS |
356 | |
357 | // New translations for getting mouse motion feedback | |
358 | String translations = | |
359 | "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\ | |
360 | <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\ | |
361 | <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\ | |
362 | <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\ | |
363 | <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\ | |
364 | <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\ | |
365 | <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\ | |
366 | <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\ | |
367 | <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\ | |
368 | <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\ | |
369 | <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\ | |
370 | <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\ | |
371 | <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\ | |
372 | <Key>: DrawingAreaInput()"; | |
373 | ||
374 | XtActionsRec actions[1]; | |
375 | actions[0].string = "wxCanvasMotionEvent"; | |
376 | actions[0].proc = (XtActionProc) wxCanvasMotionEvent; | |
377 | XtAppAddActions ((XtAppContext) wxTheApp->GetAppContext(), actions, 1); | |
378 | ||
379 | Widget parentWidget = (Widget) parent->GetClientWidget(); | |
380 | if (style & wxBORDER) | |
381 | m_borderWidget = (WXWidget) XtVaCreateManagedWidget ("canvasBorder", | |
382 | xmFrameWidgetClass, parentWidget, | |
383 | XmNshadowType, XmSHADOW_IN, | |
384 | NULL); | |
385 | ||
386 | m_scrolledWindow = (WXWidget) XtVaCreateManagedWidget ("scrolledWindow", | |
387 | xmScrolledWindowWidgetClass, m_borderWidget ? (Widget) m_borderWidget : parentWidget, | |
388 | XmNresizePolicy, XmRESIZE_NONE, | |
389 | XmNspacing, 0, | |
390 | XmNscrollingPolicy, XmAPPLICATION_DEFINED, | |
391 | // XmNscrollBarDisplayPolicy, XmAS_NEEDED, | |
392 | NULL); | |
393 | ||
394 | XtTranslations ptr; | |
395 | m_drawingArea = (WXWidget) XtVaCreateWidget ((char*) (const char*) name, | |
396 | xmDrawingAreaWidgetClass, (Widget) m_scrolledWindow, | |
397 | XmNunitType, XmPIXELS, | |
398 | // XmNresizePolicy, XmRESIZE_ANY, | |
399 | XmNresizePolicy, XmRESIZE_NONE, | |
400 | XmNmarginHeight, 0, | |
401 | XmNmarginWidth, 0, | |
402 | XmNtranslations, ptr = XtParseTranslationTable (translations), | |
403 | NULL); | |
404 | /* | |
405 | if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS) | |
406 | { | |
407 | XtFree ((char *) ptr); | |
408 | ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()"); | |
409 | XtOverrideTranslations ((Widget) m_drawingArea, ptr); | |
410 | XtFree ((char *) ptr); | |
411 | } | |
412 | */ | |
413 | ||
414 | wxAddWindowToTable((Widget) m_drawingArea, this); | |
415 | wxAddWindowToTable((Widget) m_scrolledWindow, this); | |
416 | ||
417 | /* | |
418 | * This order is very important in Motif 1.2.1 | |
419 | * | |
420 | */ | |
421 | ||
422 | XtRealizeWidget ((Widget) m_scrolledWindow); | |
423 | XtRealizeWidget ((Widget) m_drawingArea); | |
424 | XtManageChild ((Widget) m_drawingArea); | |
425 | ||
426 | XtOverrideTranslations ((Widget) m_drawingArea, | |
427 | ptr = XtParseTranslationTable ("<Configure>: resize()")); | |
50414e24 | 428 | XtFree ((char *) ptr); |
2d120f83 JS |
429 | |
430 | XtAddCallback ((Widget) m_drawingArea, XmNexposeCallback, (XtCallbackProc) wxCanvasRepaintProc, (XtPointer) this); | |
431 | XtAddCallback ((Widget) m_drawingArea, XmNinputCallback, (XtCallbackProc) wxCanvasInputEvent, (XtPointer) this); | |
432 | ||
433 | /* TODO? | |
434 | display = XtDisplay (scrolledWindow); | |
435 | xwindow = XtWindow (drawingArea); | |
436 | */ | |
437 | ||
438 | XtAddEventHandler ((Widget) m_drawingArea, PointerMotionHintMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask, | |
439 | False, (XtEventHandler) wxCanvasEnterLeave, (XtPointer) this); | |
440 | ||
441 | // Scrolled widget needs to have its colour changed or we get | |
442 | // a little blue square where the scrollbars abutt | |
443 | wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); | |
444 | DoChangeBackgroundColour(m_scrolledWindow, backgroundColour, TRUE); | |
445 | DoChangeBackgroundColour(m_drawingArea, backgroundColour, TRUE); | |
446 | ||
447 | XmScrolledWindowSetAreas ((Widget) m_scrolledWindow, (Widget) 0, (Widget) 0, (Widget) m_drawingArea); | |
448 | ||
449 | /* | |
450 | if (m_hScrollBar) | |
451 | XtRealizeWidget ((Widget) m_hScrollBar); | |
452 | if (m_vScrollBar) | |
453 | XtRealizeWidget ((Widget) m_vScrollBar); | |
454 | */ | |
455 | ||
456 | // Without this, the cursor may not be restored properly | |
457 | // (e.g. in splitter sample). | |
458 | SetCursor(*wxSTANDARD_CURSOR); | |
459 | SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); | |
460 | SetSize(pos.x, pos.y, size.x, size.y); | |
461 | ||
462 | return TRUE; | |
88150e60 JS |
463 | } |
464 | ||
465 | // Helper function | |
466 | void wxWindow::CreateScrollbar(int orientation) | |
467 | { | |
2d120f83 JS |
468 | if (!m_drawingArea) |
469 | return; | |
470 | ||
471 | XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_NONE, NULL); | |
472 | ||
473 | // Add scrollbars if required | |
474 | if (orientation == wxHORIZONTAL) | |
475 | { | |
476 | Widget hScrollBar = XtVaCreateManagedWidget ("hsb", | |
477 | xmScrollBarWidgetClass, (Widget) m_scrolledWindow, | |
478 | XmNorientation, XmHORIZONTAL, | |
479 | NULL); | |
480 | // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
481 | XtAddCallback (hScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
482 | XtAddCallback (hScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
483 | XtAddCallback (hScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
484 | XtAddCallback (hScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
485 | XtAddCallback (hScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
486 | XtAddCallback (hScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
487 | XtAddCallback (hScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
488 | ||
489 | XtVaSetValues (hScrollBar, | |
490 | XmNincrement, 1, | |
491 | XmNvalue, 0, | |
492 | NULL); | |
493 | ||
494 | m_hScrollBar = (WXWidget) hScrollBar; | |
495 | ||
496 | wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); | |
497 | DoChangeBackgroundColour(m_hScrollBar, backgroundColour, TRUE); | |
498 | ||
499 | XtRealizeWidget(hScrollBar); | |
500 | ||
501 | XtVaSetValues((Widget) m_scrolledWindow, | |
502 | XmNhorizontalScrollBar, (Widget) m_hScrollBar, | |
503 | NULL); | |
504 | ||
505 | m_hScroll = TRUE; | |
506 | } | |
507 | ||
508 | if (orientation == wxVERTICAL) | |
509 | { | |
510 | Widget vScrollBar = XtVaCreateManagedWidget ("vsb", | |
511 | xmScrollBarWidgetClass, (Widget) m_scrolledWindow, | |
512 | XmNorientation, XmVERTICAL, | |
513 | NULL); | |
514 | // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
515 | XtAddCallback (vScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
516 | XtAddCallback (vScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
517 | XtAddCallback (vScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
518 | XtAddCallback (vScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
519 | XtAddCallback (vScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
520 | XtAddCallback (vScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
521 | XtAddCallback (vScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
522 | ||
523 | XtVaSetValues (vScrollBar, | |
524 | XmNincrement, 1, | |
525 | XmNvalue, 0, | |
526 | NULL); | |
527 | ||
528 | m_vScrollBar = (WXWidget) vScrollBar; | |
529 | wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); | |
530 | DoChangeBackgroundColour(m_vScrollBar, backgroundColour, TRUE); | |
531 | ||
532 | XtRealizeWidget(vScrollBar); | |
533 | ||
534 | XtVaSetValues((Widget) m_scrolledWindow, | |
535 | XmNverticalScrollBar, (Widget) m_vScrollBar, | |
536 | NULL); | |
537 | ||
538 | m_vScroll = TRUE; | |
539 | } | |
540 | ||
541 | XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL); | |
88150e60 JS |
542 | } |
543 | void wxWindow::DestroyScrollbar(int orientation) | |
544 | { | |
2d120f83 JS |
545 | if (!m_drawingArea) |
546 | return; | |
547 | ||
548 | XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_NONE, NULL); | |
549 | // Add scrollbars if required | |
550 | if (orientation == wxHORIZONTAL) | |
551 | { | |
552 | if (m_hScrollBar) | |
553 | { | |
554 | XtDestroyWidget((Widget) m_hScrollBar); | |
555 | } | |
556 | m_hScrollBar = (WXWidget) 0; | |
557 | m_hScroll = FALSE; | |
558 | ||
559 | XtVaSetValues((Widget) m_scrolledWindow, | |
560 | XmNhorizontalScrollBar, (Widget) 0, | |
561 | NULL); | |
562 | ||
563 | } | |
564 | ||
565 | if (orientation == wxVERTICAL) | |
566 | { | |
567 | if (m_vScrollBar) | |
568 | { | |
569 | XtDestroyWidget((Widget) m_vScrollBar); | |
570 | } | |
571 | m_vScrollBar = (WXWidget) 0; | |
572 | m_vScroll = TRUE; | |
573 | ||
574 | XtVaSetValues((Widget) m_scrolledWindow, | |
575 | XmNverticalScrollBar, (Widget) 0, | |
576 | NULL); | |
577 | ||
578 | } | |
579 | XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL); | |
4bb6408c JS |
580 | } |
581 | ||
582 | void wxWindow::SetFocus() | |
583 | { | |
2d120f83 JS |
584 | XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT); |
585 | XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT); | |
4bb6408c JS |
586 | } |
587 | ||
588 | void wxWindow::Enable(bool enable) | |
589 | { | |
2d120f83 JS |
590 | if (GetMainWidget()) |
591 | { | |
592 | XtSetSensitive((Widget) GetMainWidget(), enable); | |
593 | XmUpdateDisplay((Widget) GetMainWidget()); | |
594 | } | |
4bb6408c JS |
595 | } |
596 | ||
597 | void wxWindow::CaptureMouse() | |
598 | { | |
2d120f83 JS |
599 | if (m_winCaptured) |
600 | return; | |
4bb6408c | 601 | |
2d120f83 JS |
602 | if (GetMainWidget()) |
603 | XtAddGrab((Widget) GetMainWidget(), TRUE, FALSE); | |
604 | ||
605 | m_winCaptured = TRUE; | |
4bb6408c JS |
606 | } |
607 | ||
608 | void wxWindow::ReleaseMouse() | |
609 | { | |
2d120f83 JS |
610 | if (!m_winCaptured) |
611 | return; | |
4bb6408c | 612 | |
2d120f83 JS |
613 | if (GetMainWidget()) |
614 | XtRemoveGrab((Widget) GetMainWidget()); | |
615 | m_winCaptured = FALSE; | |
4bb6408c JS |
616 | } |
617 | ||
618 | // Push/pop event handler (i.e. allow a chain of event handlers | |
619 | // be searched) | |
620 | void wxWindow::PushEventHandler(wxEvtHandler *handler) | |
621 | { | |
2d120f83 JS |
622 | handler->SetNextHandler(GetEventHandler()); |
623 | SetEventHandler(handler); | |
4bb6408c JS |
624 | } |
625 | ||
626 | wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler) | |
627 | { | |
2d120f83 JS |
628 | if ( GetEventHandler() ) |
629 | { | |
630 | wxEvtHandler *handlerA = GetEventHandler(); | |
631 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
632 | handlerA->SetNextHandler(NULL); | |
633 | SetEventHandler(handlerB); | |
634 | if ( deleteHandler ) | |
635 | { | |
636 | delete handlerA; | |
637 | return NULL; | |
638 | } | |
639 | else | |
640 | return handlerA; | |
641 | } | |
642 | else | |
643 | return NULL; | |
4bb6408c JS |
644 | } |
645 | ||
47d67540 | 646 | #if wxUSE_DRAG_AND_DROP |
4bb6408c JS |
647 | |
648 | void wxWindow::SetDropTarget(wxDropTarget *pDropTarget) | |
649 | { | |
2d120f83 JS |
650 | if ( m_pDropTarget != 0 ) { |
651 | delete m_pDropTarget; | |
652 | } | |
653 | ||
654 | m_pDropTarget = pDropTarget; | |
655 | if ( m_pDropTarget != 0 ) | |
656 | { | |
657 | // TODO | |
658 | } | |
4bb6408c JS |
659 | } |
660 | ||
661 | #endif | |
662 | ||
663 | // Old style file-manager drag&drop | |
664 | void wxWindow::DragAcceptFiles(bool accept) | |
665 | { | |
666 | // TODO | |
667 | } | |
668 | ||
669 | // Get total size | |
670 | void wxWindow::GetSize(int *x, int *y) const | |
671 | { | |
2d120f83 JS |
672 | if (m_drawingArea) |
673 | { | |
674 | CanvasGetSize(x, y); | |
675 | return; | |
676 | } | |
677 | ||
678 | Widget widget = (Widget) GetTopWidget(); | |
679 | Dimension xx, yy; | |
680 | XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL); | |
681 | *x = xx; *y = yy; | |
4bb6408c JS |
682 | } |
683 | ||
684 | void wxWindow::GetPosition(int *x, int *y) const | |
685 | { | |
a4294b78 JS |
686 | if (m_drawingArea) |
687 | { | |
688 | CanvasGetPosition(x, y); | |
689 | return; | |
690 | } | |
691 | Widget widget = (Widget) GetTopWidget(); | |
692 | Position xx, yy; | |
693 | XtVaGetValues(widget, XmNx, &xx, XmNy, &yy, NULL); | |
2d120f83 | 694 | |
a4294b78 JS |
695 | // We may be faking the client origin. |
696 | // So a window that's really at (0, 30) may appear | |
697 | // (to wxWin apps) to be at (0, 0). | |
698 | if (GetParent()) | |
699 | { | |
700 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
701 | xx -= pt.x; | |
702 | yy -= pt.y; | |
703 | } | |
2d120f83 | 704 | |
a4294b78 | 705 | *x = xx; *y = yy; |
4bb6408c JS |
706 | } |
707 | ||
708 | void wxWindow::ScreenToClient(int *x, int *y) const | |
709 | { | |
2d120f83 JS |
710 | Widget widget = (Widget) GetClientWidget(); |
711 | Display *display = XtDisplay((Widget) GetMainWidget()); | |
712 | Window rootWindow = RootWindowOfScreen(XtScreen(widget)); | |
713 | Window thisWindow = XtWindow(widget); | |
714 | ||
715 | Window childWindow; | |
716 | int xx = *x; | |
717 | int yy = *y; | |
718 | XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow); | |
4bb6408c JS |
719 | } |
720 | ||
721 | void wxWindow::ClientToScreen(int *x, int *y) const | |
722 | { | |
2d120f83 JS |
723 | Widget widget = (Widget) GetClientWidget(); |
724 | Display *display = XtDisplay(widget); | |
725 | Window rootWindow = RootWindowOfScreen(XtScreen(widget)); | |
726 | Window thisWindow = XtWindow(widget); | |
727 | ||
728 | Window childWindow; | |
729 | int xx = *x; | |
730 | int yy = *y; | |
731 | XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow); | |
4bb6408c JS |
732 | } |
733 | ||
734 | void wxWindow::SetCursor(const wxCursor& cursor) | |
735 | { | |
2d120f83 JS |
736 | m_windowCursor = cursor; |
737 | if (m_windowCursor.Ok()) | |
738 | { | |
739 | WXDisplay *dpy = GetXDisplay(); | |
740 | WXCursor x_cursor = ((wxCursor&)cursor).GetXCursor(dpy); | |
741 | ||
742 | Widget w = (Widget) GetMainWidget(); | |
743 | Window win = XtWindow(w); | |
744 | XDefineCursor((Display*) dpy, win, (Cursor) x_cursor); | |
745 | } | |
4bb6408c JS |
746 | } |
747 | ||
748 | ||
749 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
750 | void wxWindow::GetClientSize(int *x, int *y) const | |
751 | { | |
2d120f83 JS |
752 | Widget widget = (Widget) GetClientWidget(); |
753 | Dimension xx, yy; | |
754 | XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL); | |
755 | *x = xx; *y = yy; | |
4bb6408c JS |
756 | } |
757 | ||
758 | void wxWindow::SetSize(int x, int y, int width, int height, int sizeFlags) | |
759 | { | |
2d120f83 JS |
760 | // A bit of optimization to help sort out the flickers. |
761 | int oldX, oldY, oldW, oldH; | |
762 | GetSize(& oldW, & oldH); | |
763 | GetPosition(& oldX, & oldY); | |
764 | ||
765 | bool useOldPos = FALSE; | |
766 | bool useOldSize = FALSE; | |
767 | ||
768 | if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0)) | |
769 | useOldPos = TRUE; | |
770 | else if (x == oldX && y == oldY) | |
771 | useOldPos = TRUE; | |
772 | ||
773 | if ((width == -1) && (height == -1)) | |
774 | useOldSize = TRUE; | |
775 | else if (width == oldW && height == oldH) | |
776 | useOldSize = TRUE; | |
777 | ||
778 | if (!wxNoOptimize::CanOptimize()) | |
779 | { | |
780 | useOldSize = FALSE; useOldPos = FALSE; | |
781 | } | |
782 | ||
783 | if (useOldPos && useOldSize) | |
784 | return; | |
785 | ||
786 | if (m_drawingArea) | |
787 | { | |
788 | CanvasSetSize(x, y, width, height, sizeFlags); | |
789 | return; | |
790 | } | |
791 | Widget widget = (Widget) GetTopWidget(); | |
792 | if (!widget) | |
793 | return; | |
794 | ||
795 | bool managed = XtIsManaged( widget ); | |
796 | if (managed) | |
797 | XtUnmanageChild(widget); | |
798 | ||
799 | int xx = x; int yy = y; | |
800 | AdjustForParentClientOrigin(xx, yy, sizeFlags); | |
801 | ||
802 | if (!useOldPos) | |
803 | { | |
804 | if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
805 | XtVaSetValues(widget, XmNx, xx, NULL); | |
806 | if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
807 | XtVaSetValues(widget, XmNy, yy, NULL); | |
808 | } | |
809 | if (!useOldSize) | |
810 | { | |
811 | if (width > -1) | |
812 | XtVaSetValues(widget, XmNwidth, width, NULL); | |
813 | if (height > -1) | |
814 | XtVaSetValues(widget, XmNheight, height, NULL); | |
815 | } | |
816 | ||
817 | if (managed) | |
818 | XtManageChild(widget); | |
819 | ||
820 | // How about this bit. Maybe we don't need to generate size events | |
821 | // all the time -- they'll be generated when the window is sized anyway. | |
822 | /* | |
823 | wxSizeEvent sizeEvent(wxSize(width, height), GetId()); | |
824 | sizeEvent.SetEventObject(this); | |
825 | ||
826 | GetEventHandler()->ProcessEvent(sizeEvent); | |
827 | */ | |
828 | } | |
7fe7d506 | 829 | |
2d120f83 JS |
830 | void wxWindow::SetClientSize(int width, int height) |
831 | { | |
832 | if (m_drawingArea) | |
833 | { | |
834 | CanvasSetClientSize(width, height); | |
835 | return; | |
836 | } | |
837 | ||
838 | Widget widget = (Widget) GetTopWidget(); | |
839 | ||
840 | if (width > -1) | |
841 | XtVaSetValues(widget, XmNwidth, width, NULL); | |
842 | if (height > -1) | |
843 | XtVaSetValues(widget, XmNheight, height, NULL); | |
844 | ||
845 | wxSizeEvent sizeEvent(wxSize(width, height), GetId()); | |
846 | sizeEvent.SetEventObject(this); | |
847 | ||
848 | GetEventHandler()->ProcessEvent(sizeEvent); | |
849 | } | |
4bb6408c JS |
850 | |
851 | // For implementation purposes - sometimes decorations make the client area | |
852 | // smaller | |
853 | wxPoint wxWindow::GetClientAreaOrigin() const | |
854 | { | |
855 | return wxPoint(0, 0); | |
856 | } | |
857 | ||
858 | // Makes an adjustment to the window position (for example, a frame that has | |
859 | // a toolbar that it manages itself). | |
860 | void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) | |
861 | { | |
862 | if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) | |
863 | { | |
864 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
865 | x += pt.x; y += pt.y; | |
866 | } | |
867 | } | |
868 | ||
869 | bool wxWindow::Show(bool show) | |
870 | { | |
50414e24 JS |
871 | if (show) |
872 | { | |
2d120f83 JS |
873 | if (m_borderWidget || m_scrolledWindow) |
874 | { | |
875 | if (m_drawingArea) | |
876 | XtMapWidget((Widget) m_drawingArea); | |
877 | XtMapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); | |
878 | } | |
879 | else | |
880 | { | |
881 | WXWidget topWidget = GetTopWidget(); | |
882 | if (GetTopWidget()) | |
883 | XtMapWidget((Widget) GetTopWidget()); | |
884 | else if (GetMainWidget()) | |
885 | XtMapWidget((Widget) GetMainWidget()); | |
886 | } | |
50414e24 JS |
887 | } |
888 | else | |
889 | { | |
2d120f83 JS |
890 | if (m_borderWidget || m_scrolledWindow) |
891 | { | |
892 | if (m_drawingArea) | |
893 | XtUnmapWidget((Widget) m_drawingArea); | |
894 | XtUnmapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); | |
895 | } | |
896 | else | |
897 | { | |
898 | if (GetTopWidget()) | |
899 | XtUnmapWidget((Widget) GetTopWidget()); | |
900 | else if (GetMainWidget()) | |
901 | XtUnmapWidget((Widget) GetMainWidget()); | |
902 | } | |
50414e24 | 903 | } |
2d120f83 JS |
904 | |
905 | /* | |
4bb6408c JS |
906 | Window xwin = (Window) GetXWindow(); |
907 | Display *xdisp = (Display*) GetXDisplay(); | |
908 | if (show) | |
2d120f83 | 909 | XMapWindow(xdisp, xwin); |
4bb6408c | 910 | else |
2d120f83 JS |
911 | XUnmapWindow(xdisp, xwin); |
912 | */ | |
913 | ||
4bb6408c | 914 | m_isShown = show; |
2d120f83 | 915 | |
4bb6408c JS |
916 | return TRUE; |
917 | } | |
918 | ||
919 | bool wxWindow::IsShown() const | |
920 | { | |
921 | return m_isShown; | |
922 | } | |
923 | ||
924 | int wxWindow::GetCharHeight() const | |
925 | { | |
2d120f83 JS |
926 | if (!m_windowFont.Ok()) |
927 | return 0; | |
928 | ||
929 | WXFontStructPtr pFontStruct = m_windowFont.GetFontStruct(1.0, GetXDisplay()); | |
930 | ||
931 | int direction, ascent, descent; | |
932 | XCharStruct overall; | |
933 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
47bc1060 | 934 | &descent, &overall); |
2d120f83 JS |
935 | // return (overall.ascent + overall.descent); |
936 | return (ascent + descent); | |
4bb6408c JS |
937 | } |
938 | ||
939 | int wxWindow::GetCharWidth() const | |
940 | { | |
2d120f83 JS |
941 | if (!m_windowFont.Ok()) |
942 | return 0; | |
943 | ||
944 | WXFontStructPtr pFontStruct = m_windowFont.GetFontStruct(1.0, GetXDisplay()); | |
945 | ||
946 | int direction, ascent, descent; | |
947 | XCharStruct overall; | |
948 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
47bc1060 | 949 | &descent, &overall); |
2d120f83 | 950 | return overall.width; |
47bc1060 JS |
951 | } |
952 | ||
953 | /* Helper function for 16-bit fonts */ | |
954 | static int str16len(const char *s) | |
955 | { | |
2d120f83 JS |
956 | int count = 0; |
957 | ||
958 | while (s[0] && s[1]) { | |
959 | count++; | |
960 | s += 2; | |
961 | } | |
962 | ||
963 | return count; | |
4bb6408c JS |
964 | } |
965 | ||
966 | void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, | |
2d120f83 | 967 | int *descent, int *externalLeading, const wxFont *theFont, bool use16) const |
4bb6408c | 968 | { |
2d120f83 JS |
969 | wxFont *fontToUse = (wxFont *)theFont; |
970 | if (!fontToUse) | |
971 | fontToUse = (wxFont *) & m_windowFont; | |
972 | ||
973 | if (!fontToUse->Ok()) | |
974 | return; | |
975 | ||
976 | WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay()); | |
977 | ||
978 | int direction, ascent, descent2; | |
979 | XCharStruct overall; | |
980 | int slen; | |
981 | ||
982 | if (use16) slen = str16len(string); else slen = strlen(string); | |
983 | ||
984 | if (use16) | |
985 | XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction, | |
986 | &ascent, &descent2, &overall); | |
987 | else | |
988 | XTextExtents((XFontStruct*) pFontStruct, (char*) (const char*) string, slen, &direction, | |
989 | &ascent, &descent2, &overall); | |
990 | ||
991 | *x = (overall.width); | |
992 | *y = (ascent + descent2); | |
993 | if (descent) | |
994 | *descent = descent2; | |
995 | if (externalLeading) | |
996 | *externalLeading = 0; | |
4bb6408c JS |
997 | } |
998 | ||
16e93305 | 999 | void wxWindow::Refresh(bool eraseBack, const wxRect *rect) |
4bb6408c | 1000 | { |
a91b47e8 | 1001 | m_needsRefresh = TRUE; |
4bb6408c JS |
1002 | Display *display = XtDisplay((Widget) GetMainWidget()); |
1003 | Window thisWindow = XtWindow((Widget) GetMainWidget()); | |
2d120f83 | 1004 | |
4bb6408c JS |
1005 | XExposeEvent dummyEvent; |
1006 | int width, height; | |
1007 | GetSize(&width, &height); | |
2d120f83 | 1008 | |
4bb6408c JS |
1009 | dummyEvent.type = Expose; |
1010 | dummyEvent.display = display; | |
1011 | dummyEvent.send_event = True; | |
1012 | dummyEvent.window = thisWindow; | |
1013 | if (rect) | |
1014 | { | |
2d120f83 JS |
1015 | dummyEvent.x = rect->x; |
1016 | dummyEvent.y = rect->y; | |
1017 | dummyEvent.width = rect->width; | |
1018 | dummyEvent.height = rect->height; | |
4bb6408c JS |
1019 | } |
1020 | else | |
1021 | { | |
2d120f83 JS |
1022 | dummyEvent.x = 0; |
1023 | dummyEvent.y = 0; | |
1024 | dummyEvent.width = width; | |
1025 | dummyEvent.height = height; | |
4bb6408c JS |
1026 | } |
1027 | dummyEvent.count = 0; | |
2d120f83 | 1028 | |
4bb6408c JS |
1029 | if (eraseBack) |
1030 | { | |
1031 | wxClientDC dc(this); | |
e97f20a0 JS |
1032 | wxBrush backgroundBrush(GetBackgroundColour(), wxSOLID); |
1033 | dc.SetBackground(backgroundBrush); | |
a367b9b3 | 1034 | if (rect) |
2d120f83 | 1035 | dc.Clear(*rect); |
a367b9b3 | 1036 | else |
2d120f83 | 1037 | dc.Clear(); |
4bb6408c | 1038 | } |
2d120f83 | 1039 | |
4bb6408c JS |
1040 | XSendEvent(display, thisWindow, False, ExposureMask, (XEvent *)&dummyEvent); |
1041 | } | |
1042 | ||
1043 | // Responds to colour changes: passes event on to children. | |
1044 | void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event) | |
1045 | { | |
c0ed460c | 1046 | wxNode *node = GetChildren().First(); |
4bb6408c JS |
1047 | while ( node ) |
1048 | { | |
1049 | // Only propagate to non-top-level windows | |
1050 | wxWindow *win = (wxWindow *)node->Data(); | |
1051 | if ( win->GetParent() ) | |
1052 | { | |
1053 | wxSysColourChangedEvent event2; | |
1054 | event.m_eventObject = win; | |
1055 | win->GetEventHandler()->ProcessEvent(event2); | |
1056 | } | |
2d120f83 | 1057 | |
4bb6408c JS |
1058 | node = node->Next(); |
1059 | } | |
1060 | } | |
1061 | ||
1062 | // This can be called by the app (or wxWindows) to do default processing for the current | |
1063 | // event. Save message/event info in wxWindow so they can be used in this function. | |
1064 | long wxWindow::Default() | |
1065 | { | |
1066 | // TODO | |
1067 | return 0; | |
1068 | } | |
1069 | ||
1070 | void wxWindow::InitDialog() | |
1071 | { | |
2d120f83 JS |
1072 | wxInitDialogEvent event(GetId()); |
1073 | event.SetEventObject( this ); | |
1074 | GetEventHandler()->ProcessEvent(event); | |
4bb6408c JS |
1075 | } |
1076 | ||
1077 | // Default init dialog behaviour is to transfer data to window | |
1078 | void wxWindow::OnInitDialog(wxInitDialogEvent& event) | |
1079 | { | |
2d120f83 | 1080 | TransferDataToWindow(); |
4bb6408c JS |
1081 | } |
1082 | ||
1083 | // Caret manipulation | |
1084 | void wxWindow::CreateCaret(int w, int h) | |
1085 | { | |
2d120f83 JS |
1086 | m_caretWidth = w; |
1087 | m_caretHeight = h; | |
1088 | m_caretEnabled = TRUE; | |
4bb6408c JS |
1089 | } |
1090 | ||
1091 | void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) | |
1092 | { | |
1093 | // TODO | |
1094 | } | |
1095 | ||
1096 | void wxWindow::ShowCaret(bool show) | |
1097 | { | |
1098 | // TODO | |
1099 | } | |
1100 | ||
1101 | void wxWindow::DestroyCaret() | |
1102 | { | |
1103 | // TODO | |
1104 | m_caretEnabled = FALSE; | |
1105 | } | |
1106 | ||
1107 | void wxWindow::SetCaretPos(int x, int y) | |
1108 | { | |
1109 | // TODO | |
1110 | } | |
1111 | ||
1112 | void wxWindow::GetCaretPos(int *x, int *y) const | |
1113 | { | |
1114 | // TODO | |
1115 | } | |
1116 | ||
1117 | wxWindow *wxGetActiveWindow() | |
1118 | { | |
1119 | // TODO | |
1120 | return NULL; | |
1121 | } | |
1122 | ||
1123 | void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH) | |
1124 | { | |
1125 | m_minSizeX = minW; | |
1126 | m_minSizeY = minH; | |
1127 | m_maxSizeX = maxW; | |
1128 | m_maxSizeY = maxH; | |
2d120f83 | 1129 | |
4bb6408c | 1130 | if (!this->IsKindOf(CLASSINFO(wxFrame))) |
2d120f83 JS |
1131 | return; |
1132 | ||
4bb6408c | 1133 | wxFrame *frame = (wxFrame *)this; |
47bc1060 | 1134 | Widget widget = (Widget) frame->GetShellWidget(); |
2d120f83 | 1135 | |
4bb6408c | 1136 | if (minW > -1) |
2d120f83 | 1137 | XtVaSetValues(widget, XmNminWidth, minW, NULL); |
4bb6408c | 1138 | if (minH > -1) |
2d120f83 | 1139 | XtVaSetValues(widget, XmNminHeight, minH, NULL); |
4bb6408c | 1140 | if (maxW > -1) |
2d120f83 | 1141 | XtVaSetValues(widget, XmNmaxWidth, maxW, NULL); |
4bb6408c | 1142 | if (maxH > -1) |
2d120f83 | 1143 | XtVaSetValues(widget, XmNmaxHeight, maxH, NULL); |
4bb6408c | 1144 | if (incW > -1) |
2d120f83 | 1145 | XtVaSetValues(widget, XmNwidthInc, incW, NULL); |
4bb6408c | 1146 | if (incH > -1) |
2d120f83 | 1147 | XtVaSetValues(widget, XmNheightInc, incH, NULL); |
4bb6408c JS |
1148 | } |
1149 | ||
1150 | void wxWindow::Centre(int direction) | |
1151 | { | |
2d120f83 JS |
1152 | int x, y, width, height, panel_width, panel_height, new_x, new_y; |
1153 | ||
1154 | wxWindow *father = (wxWindow *)GetParent(); | |
1155 | if (!father) | |
1156 | return; | |
1157 | ||
1158 | father->GetClientSize(&panel_width, &panel_height); | |
1159 | GetSize(&width, &height); | |
1160 | GetPosition(&x, &y); | |
1161 | ||
1162 | new_x = -1; | |
1163 | new_y = -1; | |
1164 | ||
1165 | if (direction & wxHORIZONTAL) | |
1166 | new_x = (int)((panel_width - width)/2); | |
1167 | ||
1168 | if (direction & wxVERTICAL) | |
1169 | new_y = (int)((panel_height - height)/2); | |
1170 | ||
1171 | SetSize(new_x, new_y, -1, -1); | |
1172 | ||
4bb6408c JS |
1173 | } |
1174 | ||
1175 | // Coordinates relative to the window | |
50414e24 | 1176 | void wxWindow::WarpPointer (int x, int y) |
4bb6408c | 1177 | { |
2d120f83 | 1178 | XWarpPointer (XtDisplay((Widget) GetClientWidget()), None, XtWindow((Widget) GetClientWidget()), 0, 0, 0, 0, x, y); |
4bb6408c JS |
1179 | } |
1180 | ||
1181 | void wxWindow::OnEraseBackground(wxEraseEvent& event) | |
1182 | { | |
1183 | // TODO | |
1184 | Default(); | |
1185 | } | |
1186 | ||
1187 | int wxWindow::GetScrollPos(int orient) const | |
1188 | { | |
47bc1060 JS |
1189 | if (orient == wxHORIZONTAL) |
1190 | return m_scrollPosX; | |
1191 | else | |
1192 | return m_scrollPosY; | |
2d120f83 JS |
1193 | /* |
1194 | Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar); | |
1195 | if (scrollBar) | |
1196 | { | |
47bc1060 JS |
1197 | int pos; |
1198 | XtVaGetValues(scrollBar, | |
2d120f83 | 1199 | XmNvalue, &pos, NULL); |
47bc1060 | 1200 | return pos; |
2d120f83 JS |
1201 | } |
1202 | else | |
47bc1060 | 1203 | return 0; |
2d120f83 | 1204 | */ |
4bb6408c JS |
1205 | } |
1206 | ||
1207 | // This now returns the whole range, not just the number | |
1208 | // of positions that we can scroll. | |
1209 | int wxWindow::GetScrollRange(int orient) const | |
1210 | { | |
2d120f83 JS |
1211 | Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar); |
1212 | if (scrollBar) | |
1213 | { | |
47bc1060 JS |
1214 | int range; |
1215 | XtVaGetValues(scrollBar, | |
1216 | XmNmaximum, &range, NULL); | |
1217 | return range; | |
1218 | } | |
1219 | else | |
1220 | return 0; | |
4bb6408c JS |
1221 | } |
1222 | ||
1223 | int wxWindow::GetScrollThumb(int orient) const | |
1224 | { | |
2d120f83 JS |
1225 | Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar); |
1226 | if (scrollBar) | |
1227 | { | |
47bc1060 JS |
1228 | int thumb; |
1229 | XtVaGetValues(scrollBar, | |
1230 | XmNsliderSize, &thumb, NULL); | |
1231 | return thumb; | |
1232 | } | |
1233 | else | |
1234 | return 0; | |
4bb6408c JS |
1235 | } |
1236 | ||
47bc1060 | 1237 | void wxWindow::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) |
4bb6408c | 1238 | { |
2d120f83 JS |
1239 | Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar); |
1240 | if (scrollBar) | |
1241 | { | |
1242 | XtVaSetValues (scrollBar, | |
1243 | XmNvalue, pos, | |
1244 | NULL); | |
1245 | } | |
1246 | if (orient == wxHORIZONTAL) | |
1247 | m_scrollPosX = pos; | |
1248 | else | |
1249 | m_scrollPosY = pos; | |
1250 | ||
4bb6408c JS |
1251 | } |
1252 | ||
1253 | // New function that will replace some of the above. | |
1254 | void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible, | |
2d120f83 | 1255 | int range, bool WXUNUSED(refresh)) |
4bb6408c | 1256 | { |
88150e60 JS |
1257 | int oldW, oldH; |
1258 | GetSize(& oldW, & oldH); | |
2d120f83 | 1259 | |
47bc1060 | 1260 | if (range == 0) |
2d120f83 | 1261 | range = 1; |
47bc1060 | 1262 | if (thumbVisible == 0) |
2d120f83 JS |
1263 | thumbVisible = 1; |
1264 | ||
28ab302b | 1265 | if (thumbVisible > range) |
2d120f83 JS |
1266 | thumbVisible = range; |
1267 | ||
88150e60 JS |
1268 | // Save the old state to see if it changed |
1269 | WXWidget oldScrollBar = ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar ); | |
2d120f83 | 1270 | |
47bc1060 | 1271 | if (orient == wxHORIZONTAL) |
28ab302b | 1272 | { |
88150e60 JS |
1273 | if (thumbVisible == range) |
1274 | { | |
1275 | if (m_hScrollBar) | |
2d120f83 JS |
1276 | DestroyScrollbar(wxHORIZONTAL); |
1277 | } | |
28ab302b | 1278 | else |
88150e60 JS |
1279 | { |
1280 | if (!m_hScrollBar) | |
2d120f83 | 1281 | CreateScrollbar(wxHORIZONTAL); |
88150e60 | 1282 | } |
28ab302b | 1283 | } |
88150e60 | 1284 | if (orient == wxVERTICAL) |
28ab302b | 1285 | { |
88150e60 JS |
1286 | if (thumbVisible == range) |
1287 | { | |
1288 | if (m_vScrollBar) | |
2d120f83 JS |
1289 | DestroyScrollbar(wxVERTICAL); |
1290 | } | |
28ab302b | 1291 | else |
88150e60 JS |
1292 | { |
1293 | if (!m_vScrollBar) | |
2d120f83 | 1294 | CreateScrollbar(wxVERTICAL); |
88150e60 | 1295 | } |
28ab302b | 1296 | } |
88150e60 | 1297 | WXWidget newScrollBar = ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar ); |
2d120f83 | 1298 | |
88150e60 | 1299 | if (oldScrollBar != newScrollBar) |
28ab302b | 1300 | { |
2d120f83 JS |
1301 | // This is important! Without it, scrollbars misbehave |
1302 | // badly. | |
1303 | XtUnrealizeWidget((Widget) m_scrolledWindow); | |
1304 | XmScrolledWindowSetAreas ((Widget) m_scrolledWindow, (Widget) m_hScrollBar, (Widget) m_vScrollBar, (Widget) m_drawingArea); | |
1305 | XtRealizeWidget((Widget) m_scrolledWindow); | |
1306 | XtManageChild((Widget) m_scrolledWindow); | |
28ab302b | 1307 | } |
2d120f83 | 1308 | |
88150e60 | 1309 | if (newScrollBar) |
2d120f83 JS |
1310 | XtVaSetValues((Widget) newScrollBar, |
1311 | XmNvalue, pos, | |
1312 | XmNminimum, 0, | |
1313 | XmNmaximum, range, | |
1314 | XmNsliderSize, thumbVisible, | |
1315 | NULL); | |
1316 | ||
88150e60 JS |
1317 | if (orient == wxHORIZONTAL) |
1318 | m_scrollPosX = pos; | |
28ab302b | 1319 | else |
88150e60 | 1320 | m_scrollPosY = pos; |
2d120f83 | 1321 | |
88150e60 JS |
1322 | int newW, newH; |
1323 | GetSize(& newW, & newH); | |
2d120f83 | 1324 | |
88150e60 JS |
1325 | // Adjusting scrollbars can resize the canvas accidentally |
1326 | if (newW != oldW || newH != oldH) | |
1327 | SetSize(-1, -1, oldW, oldH); | |
4bb6408c JS |
1328 | } |
1329 | ||
1330 | // Does a physical scroll | |
16e93305 | 1331 | void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) |
4bb6408c | 1332 | { |
2d120f83 JS |
1333 | // cerr << "Scrolling. delta = " << dx << ", " << dy << endl; |
1334 | int x, y, w, h; | |
1335 | if (rect) | |
1336 | { | |
1337 | // Use specified rectangle | |
1338 | x = rect->x; y = rect->y; w = rect->width; h = rect->height; | |
1339 | } | |
1340 | else | |
1341 | { | |
1342 | // Use whole client area | |
1343 | x = 0; y = 0; | |
1344 | GetClientSize(& w, & h); | |
1345 | } | |
1346 | ||
1347 | int x1 = (dx >= 0) ? x : x - dx ; | |
1348 | int y1 = (dy >= 0) ? y : y - dy; | |
1349 | int w1 = w - abs(dx); | |
1350 | int h1 = h - abs(dy); | |
1351 | int x2 = (dx >= 0) ? x + dx : x; | |
1352 | int y2 = (dy >= 0) ? y + dy : y; | |
1353 | ||
1354 | wxClientDC dc(this); | |
1355 | ||
1356 | dc.SetLogicalFunction (wxCOPY); | |
1357 | ||
1358 | Widget widget = (Widget) GetMainWidget(); | |
1359 | Window window = XtWindow(widget); | |
1360 | Display* display = XtDisplay(widget); | |
1361 | ||
1362 | XCopyArea(display, window, | |
1363 | window, (GC) dc.GetGC(), | |
1364 | x1, y1, | |
1365 | w1, h1, | |
1366 | x2, y2); | |
1367 | ||
1368 | dc.SetAutoSetting(TRUE); | |
1369 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1370 | dc.SetBrush(brush); // ?? | |
1371 | ||
1372 | // We'll add rectangles to the list of update rectangles | |
1373 | // according to which bits we've exposed. | |
1374 | wxList updateRects; | |
1375 | ||
1376 | if (dx > 0) | |
1377 | { | |
1378 | wxRect *rect = new wxRect; | |
1379 | rect->x = x; | |
1380 | rect->y = y; | |
1381 | rect->width = dx; | |
1382 | rect->height = h; | |
1383 | ||
1384 | XFillRectangle(display, window, | |
1385 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); | |
1386 | ||
1387 | rect->x = rect->x; | |
1388 | rect->y = rect->y; | |
1389 | rect->width = rect->width; | |
1390 | rect->height = rect->height; | |
1391 | ||
1392 | updateRects.Append((wxObject*) rect); | |
1393 | } | |
1394 | else if (dx < 0) | |
1395 | { | |
1396 | wxRect *rect = new wxRect; | |
1397 | ||
1398 | rect->x = x + w + dx; | |
1399 | rect->y = y; | |
1400 | rect->width = -dx; | |
1401 | rect->height = h; | |
1402 | ||
1403 | XFillRectangle(display, window, | |
1404 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, | |
1405 | rect->height); | |
1406 | ||
1407 | rect->x = rect->x; | |
1408 | rect->y = rect->y; | |
1409 | rect->width = rect->width; | |
1410 | rect->height = rect->height; | |
1411 | ||
1412 | updateRects.Append((wxObject*) rect); | |
1413 | } | |
1414 | if (dy > 0) | |
1415 | { | |
1416 | wxRect *rect = new wxRect; | |
1417 | ||
1418 | rect->x = x; | |
1419 | rect->y = y; | |
1420 | rect->width = w; | |
1421 | rect->height = dy; | |
1422 | ||
1423 | XFillRectangle(display, window, | |
1424 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); | |
1425 | ||
1426 | rect->x = rect->x; | |
1427 | rect->y = rect->y; | |
1428 | rect->width = rect->width; | |
1429 | rect->height = rect->height; | |
1430 | ||
1431 | updateRects.Append((wxObject*) rect); | |
1432 | } | |
1433 | else if (dy < 0) | |
1434 | { | |
1435 | wxRect *rect = new wxRect; | |
1436 | ||
1437 | rect->x = x; | |
1438 | rect->y = y + h + dy; | |
1439 | rect->width = w; | |
1440 | rect->height = -dy; | |
1441 | ||
1442 | XFillRectangle(display, window, | |
1443 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); | |
1444 | ||
1445 | rect->x = rect->x; | |
1446 | rect->y = rect->y; | |
1447 | rect->width = rect->width; | |
1448 | rect->height = rect->height; | |
1449 | ||
1450 | updateRects.Append((wxObject*) rect); | |
1451 | } | |
1452 | dc.SetBrush(wxNullBrush); | |
1453 | ||
1454 | // Now send expose events | |
1455 | ||
1456 | wxNode* node = updateRects.First(); | |
1457 | while (node) | |
1458 | { | |
1459 | wxRect* rect = (wxRect*) node->Data(); | |
1460 | XExposeEvent event; | |
1461 | ||
1462 | event.type = Expose; | |
1463 | event.display = display; | |
1464 | event.send_event = True; | |
1465 | event.window = window; | |
1466 | ||
1467 | event.x = rect->x; | |
1468 | event.y = rect->y; | |
1469 | event.width = rect->width; | |
1470 | event.height = rect->height; | |
1471 | ||
1472 | event.count = 0; | |
1473 | ||
1474 | XSendEvent(display, window, False, ExposureMask, (XEvent *)&event); | |
1475 | ||
1476 | node = node->Next(); | |
1477 | ||
1478 | } | |
1479 | ||
1480 | // Delete the update rects | |
1481 | node = updateRects.First(); | |
1482 | while (node) | |
1483 | { | |
1484 | wxRect* rect = (wxRect*) node->Data(); | |
1485 | delete rect; | |
1486 | node = node->Next(); | |
1487 | } | |
a91b47e8 JS |
1488 | |
1489 | XmUpdateDisplay((Widget) GetMainWidget()); | |
4bb6408c JS |
1490 | } |
1491 | ||
4bb6408c JS |
1492 | void wxWindow::OnChar(wxKeyEvent& event) |
1493 | { | |
a91b47e8 | 1494 | event.Skip(); |
4ce81a75 | 1495 | /* ?? |
2d120f83 JS |
1496 | if ( event.KeyCode() == WXK_TAB ) { |
1497 | // propagate the TABs to the parent - it's up to it to decide what | |
1498 | // to do with it | |
1499 | if ( GetParent() ) { | |
1500 | if ( GetParent()->ProcessEvent(event) ) | |
1501 | return; | |
1502 | } | |
1503 | } | |
1504 | */ | |
4ce81a75 JS |
1505 | } |
1506 | ||
1507 | void wxWindow::OnKeyDown(wxKeyEvent& event) | |
1508 | { | |
a91b47e8 | 1509 | event.Skip(); |
4ce81a75 JS |
1510 | } |
1511 | ||
1512 | void wxWindow::OnKeyUp(wxKeyEvent& event) | |
1513 | { | |
a91b47e8 | 1514 | event.Skip(); |
4bb6408c JS |
1515 | } |
1516 | ||
1517 | void wxWindow::OnPaint(wxPaintEvent& event) | |
1518 | { | |
2d120f83 | 1519 | Default(); |
4bb6408c JS |
1520 | } |
1521 | ||
1522 | bool wxWindow::IsEnabled() const | |
1523 | { | |
47bc1060 JS |
1524 | // TODO. Is this right? |
1525 | // return XtGetSensitive((Widget) GetMainWidget()); | |
4bb6408c JS |
1526 | return FALSE; |
1527 | } | |
1528 | ||
1529 | // Dialog support: override these and call | |
1530 | // base class members to add functionality | |
1531 | // that can't be done using validators. | |
1532 | // NOTE: these functions assume that controls | |
1533 | // are direct children of this window, not grandchildren | |
1534 | // or other levels of descendant. | |
1535 | ||
1536 | // Transfer values to controls. If returns FALSE, | |
1537 | // it's an application error (pops up a dialog) | |
1538 | bool wxWindow::TransferDataToWindow() | |
1539 | { | |
2d120f83 JS |
1540 | wxNode *node = GetChildren().First(); |
1541 | while ( node ) | |
1542 | { | |
1543 | wxWindow *child = (wxWindow *)node->Data(); | |
1544 | if ( child->GetValidator() && | |
1545 | !child->GetValidator()->TransferToWindow() ) | |
1546 | { | |
1547 | wxLogError("Could not transfer data to window."); | |
1548 | return FALSE; | |
1549 | } | |
1550 | ||
1551 | node = node->Next(); | |
1552 | } | |
1553 | return TRUE; | |
4bb6408c JS |
1554 | } |
1555 | ||
1556 | // Transfer values from controls. If returns FALSE, | |
1557 | // validation failed: don't quit | |
1558 | bool wxWindow::TransferDataFromWindow() | |
1559 | { | |
2d120f83 JS |
1560 | wxNode *node = GetChildren().First(); |
1561 | while ( node ) | |
1562 | { | |
1563 | wxWindow *child = (wxWindow *)node->Data(); | |
1564 | if ( child->GetValidator() && !child->GetValidator()->TransferFromWindow() ) | |
1565 | { | |
1566 | return FALSE; | |
1567 | } | |
1568 | ||
1569 | node = node->Next(); | |
1570 | } | |
1571 | return TRUE; | |
4bb6408c JS |
1572 | } |
1573 | ||
1574 | bool wxWindow::Validate() | |
1575 | { | |
2d120f83 JS |
1576 | wxNode *node = GetChildren().First(); |
1577 | while ( node ) | |
1578 | { | |
1579 | wxWindow *child = (wxWindow *)node->Data(); | |
1580 | if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) ) | |
1581 | { | |
1582 | return FALSE; | |
1583 | } | |
1584 | ||
1585 | node = node->Next(); | |
1586 | } | |
1587 | return TRUE; | |
4bb6408c JS |
1588 | } |
1589 | ||
1590 | // Get the window with the focus | |
1591 | wxWindow *wxWindow::FindFocus() | |
1592 | { | |
1593 | // TODO | |
1594 | return NULL; | |
1595 | } | |
1596 | ||
1597 | void wxWindow::AddChild(wxWindow *child) | |
1598 | { | |
c0ed460c | 1599 | GetChildren().Append(child); |
4bb6408c JS |
1600 | child->m_windowParent = this; |
1601 | } | |
1602 | ||
1603 | void wxWindow::RemoveChild(wxWindow *child) | |
1604 | { | |
c0ed460c | 1605 | GetChildren().DeleteObject(child); |
4bb6408c JS |
1606 | child->m_windowParent = NULL; |
1607 | } | |
1608 | ||
4fabb575 JS |
1609 | // Reparents this window to have the new parent. |
1610 | bool wxWindow::Reparent(wxWindow* WXUNUSED(parent)) | |
1611 | { | |
1612 | // For now, we indicate that this isn't implemented. | |
1613 | return FALSE; | |
1614 | } | |
1615 | ||
4bb6408c JS |
1616 | void wxWindow::DestroyChildren() |
1617 | { | |
c0ed460c | 1618 | wxNode *node = GetChildren().First(); |
02800301 JS |
1619 | while (node) |
1620 | { | |
2d120f83 JS |
1621 | wxNode* next = node->Next(); |
1622 | wxWindow* child = (wxWindow*) node->Data(); | |
1623 | delete child; | |
1624 | node = next; | |
02800301 | 1625 | } |
c0ed460c | 1626 | GetChildren().Clear(); |
02800301 | 1627 | #if 0 |
4bb6408c | 1628 | wxNode *node; |
c0ed460c | 1629 | while ((node = GetChildren().First()) != (wxNode *)NULL) { |
2d120f83 JS |
1630 | wxWindow *child; |
1631 | if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) { | |
1632 | delete child; | |
1633 | if ( GetChildren().Member(child) ) | |
1634 | delete node; | |
1635 | } | |
4bb6408c | 1636 | } /* while */ |
02800301 | 1637 | #endif |
4bb6408c JS |
1638 | } |
1639 | ||
1640 | void wxWindow::MakeModal(bool modal) | |
1641 | { | |
2d120f83 JS |
1642 | // Disable all other windows |
1643 | if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame))) | |
4bb6408c | 1644 | { |
2d120f83 JS |
1645 | wxNode *node = wxTopLevelWindows.First(); |
1646 | while (node) | |
1647 | { | |
1648 | wxWindow *win = (wxWindow *)node->Data(); | |
1649 | if (win != this) | |
1650 | win->Enable(!modal); | |
1651 | ||
1652 | node = node->Next(); | |
1653 | } | |
4bb6408c | 1654 | } |
4bb6408c JS |
1655 | } |
1656 | ||
02e8b2f9 JS |
1657 | // If nothing defined for this, try the parent. |
1658 | // E.g. we may be a button loaded from a resource, with no callback function | |
1659 | // defined. | |
1660 | void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event) | |
1661 | { | |
2d120f83 JS |
1662 | if (GetEventHandler()->ProcessEvent(event) ) |
1663 | return; | |
1664 | if (m_windowParent) | |
1665 | m_windowParent->GetEventHandler()->OnCommand(win, event); | |
02e8b2f9 JS |
1666 | } |
1667 | ||
4bb6408c JS |
1668 | void wxWindow::SetConstraints(wxLayoutConstraints *c) |
1669 | { | |
2d120f83 JS |
1670 | if (m_constraints) |
1671 | { | |
1672 | UnsetConstraints(m_constraints); | |
1673 | delete m_constraints; | |
1674 | } | |
1675 | m_constraints = c; | |
1676 | if (m_constraints) | |
1677 | { | |
1678 | // Make sure other windows know they're part of a 'meaningful relationship' | |
1679 | if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this)) | |
1680 | m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1681 | if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this)) | |
1682 | m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1683 | if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this)) | |
1684 | m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1685 | if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this)) | |
1686 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1687 | if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this)) | |
1688 | m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1689 | if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this)) | |
1690 | m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1691 | if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this)) | |
1692 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1693 | if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this)) | |
1694 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
1695 | } | |
4bb6408c JS |
1696 | } |
1697 | ||
1698 | // This removes any dangling pointers to this window | |
1699 | // in other windows' constraintsInvolvedIn lists. | |
1700 | void wxWindow::UnsetConstraints(wxLayoutConstraints *c) | |
1701 | { | |
2d120f83 JS |
1702 | if (c) |
1703 | { | |
1704 | if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this)) | |
1705 | c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1706 | if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this)) | |
1707 | c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1708 | if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this)) | |
1709 | c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1710 | if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this)) | |
1711 | c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1712 | if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this)) | |
1713 | c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1714 | if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this)) | |
1715 | c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1716 | if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this)) | |
1717 | c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1718 | if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this)) | |
1719 | c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
1720 | } | |
4bb6408c JS |
1721 | } |
1722 | ||
1723 | // Back-pointer to other windows we're involved with, so if we delete | |
1724 | // this window, we must delete any constraints we're involved with. | |
1725 | void wxWindow::AddConstraintReference(wxWindow *otherWin) | |
1726 | { | |
2d120f83 JS |
1727 | if (!m_constraintsInvolvedIn) |
1728 | m_constraintsInvolvedIn = new wxList; | |
1729 | if (!m_constraintsInvolvedIn->Member(otherWin)) | |
1730 | m_constraintsInvolvedIn->Append(otherWin); | |
4bb6408c JS |
1731 | } |
1732 | ||
1733 | // REMOVE back-pointer to other windows we're involved with. | |
1734 | void wxWindow::RemoveConstraintReference(wxWindow *otherWin) | |
1735 | { | |
2d120f83 JS |
1736 | if (m_constraintsInvolvedIn) |
1737 | m_constraintsInvolvedIn->DeleteObject(otherWin); | |
4bb6408c JS |
1738 | } |
1739 | ||
1740 | // Reset any constraints that mention this window | |
1741 | void wxWindow::DeleteRelatedConstraints() | |
1742 | { | |
2d120f83 | 1743 | if (m_constraintsInvolvedIn) |
4bb6408c | 1744 | { |
2d120f83 JS |
1745 | wxNode *node = m_constraintsInvolvedIn->First(); |
1746 | while (node) | |
1747 | { | |
1748 | wxWindow *win = (wxWindow *)node->Data(); | |
1749 | wxNode *next = node->Next(); | |
1750 | wxLayoutConstraints *constr = win->GetConstraints(); | |
1751 | ||
1752 | // Reset any constraints involving this window | |
1753 | if (constr) | |
1754 | { | |
1755 | constr->left.ResetIfWin((wxWindow *)this); | |
1756 | constr->top.ResetIfWin((wxWindow *)this); | |
1757 | constr->right.ResetIfWin((wxWindow *)this); | |
1758 | constr->bottom.ResetIfWin((wxWindow *)this); | |
1759 | constr->width.ResetIfWin((wxWindow *)this); | |
1760 | constr->height.ResetIfWin((wxWindow *)this); | |
1761 | constr->centreX.ResetIfWin((wxWindow *)this); | |
1762 | constr->centreY.ResetIfWin((wxWindow *)this); | |
1763 | } | |
1764 | delete node; | |
1765 | node = next; | |
1766 | } | |
1767 | delete m_constraintsInvolvedIn; | |
1768 | m_constraintsInvolvedIn = NULL; | |
4bb6408c | 1769 | } |
4bb6408c JS |
1770 | } |
1771 | ||
1772 | void wxWindow::SetSizer(wxSizer *sizer) | |
1773 | { | |
2d120f83 JS |
1774 | m_windowSizer = sizer; |
1775 | if (sizer) | |
1776 | sizer->SetSizerParent((wxWindow *)this); | |
4bb6408c JS |
1777 | } |
1778 | ||
1779 | /* | |
2d120f83 JS |
1780 | * New version |
1781 | */ | |
4bb6408c JS |
1782 | |
1783 | bool wxWindow::Layout() | |
1784 | { | |
2d120f83 JS |
1785 | if (GetConstraints()) |
1786 | { | |
1787 | int w, h; | |
1788 | GetClientSize(&w, &h); | |
1789 | GetConstraints()->width.SetValue(w); | |
1790 | GetConstraints()->height.SetValue(h); | |
1791 | } | |
1792 | ||
1793 | // If top level (one sizer), evaluate the sizer's constraints. | |
1794 | if (GetSizer()) | |
1795 | { | |
1796 | int noChanges; | |
1797 | GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated | |
1798 | GetSizer()->LayoutPhase1(&noChanges); | |
1799 | GetSizer()->LayoutPhase2(&noChanges); | |
1800 | GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes | |
1801 | return TRUE; | |
1802 | } | |
1803 | else | |
1804 | { | |
1805 | // Otherwise, evaluate child constraints | |
1806 | ResetConstraints(); // Mark all constraints as unevaluated | |
1807 | DoPhase(1); // Just one phase need if no sizers involved | |
1808 | DoPhase(2); | |
1809 | SetConstraintSizes(); // Recursively set the real window sizes | |
1810 | } | |
1811 | return TRUE; | |
4bb6408c JS |
1812 | } |
1813 | ||
1814 | ||
1815 | // Do a phase of evaluating constraints: | |
1816 | // the default behaviour. wxSizers may do a similar | |
1817 | // thing, but also impose their own 'constraints' | |
1818 | // and order the evaluation differently. | |
1819 | bool wxWindow::LayoutPhase1(int *noChanges) | |
1820 | { | |
2d120f83 JS |
1821 | wxLayoutConstraints *constr = GetConstraints(); |
1822 | if (constr) | |
1823 | { | |
1824 | return constr->SatisfyConstraints((wxWindow *)this, noChanges); | |
1825 | } | |
1826 | else | |
1827 | return TRUE; | |
4bb6408c JS |
1828 | } |
1829 | ||
1830 | bool wxWindow::LayoutPhase2(int *noChanges) | |
1831 | { | |
2d120f83 JS |
1832 | *noChanges = 0; |
1833 | ||
1834 | // Layout children | |
1835 | DoPhase(1); | |
1836 | DoPhase(2); | |
1837 | return TRUE; | |
4bb6408c JS |
1838 | } |
1839 | ||
1840 | // Do a phase of evaluating child constraints | |
1841 | bool wxWindow::DoPhase(int phase) | |
1842 | { | |
2d120f83 JS |
1843 | int noIterations = 0; |
1844 | int maxIterations = 500; | |
1845 | int noChanges = 1; | |
1846 | int noFailures = 0; | |
1847 | wxList succeeded; | |
1848 | while ((noChanges > 0) && (noIterations < maxIterations)) | |
4bb6408c | 1849 | { |
2d120f83 JS |
1850 | noChanges = 0; |
1851 | noFailures = 0; | |
1852 | wxNode *node = GetChildren().First(); | |
1853 | while (node) | |
4bb6408c | 1854 | { |
2d120f83 JS |
1855 | wxWindow *child = (wxWindow *)node->Data(); |
1856 | if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog))) | |
4bb6408c | 1857 | { |
2d120f83 JS |
1858 | wxLayoutConstraints *constr = child->GetConstraints(); |
1859 | if (constr) | |
1860 | { | |
1861 | if (succeeded.Member(child)) | |
1862 | { | |
1863 | } | |
1864 | else | |
1865 | { | |
1866 | int tempNoChanges = 0; | |
1867 | bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ; | |
1868 | noChanges += tempNoChanges; | |
1869 | if (success) | |
1870 | { | |
1871 | succeeded.Append(child); | |
1872 | } | |
1873 | } | |
1874 | } | |
4bb6408c | 1875 | } |
2d120f83 | 1876 | node = node->Next(); |
4bb6408c | 1877 | } |
2d120f83 | 1878 | noIterations ++; |
4bb6408c | 1879 | } |
2d120f83 | 1880 | return TRUE; |
4bb6408c JS |
1881 | } |
1882 | ||
1883 | void wxWindow::ResetConstraints() | |
1884 | { | |
2d120f83 JS |
1885 | wxLayoutConstraints *constr = GetConstraints(); |
1886 | if (constr) | |
1887 | { | |
1888 | constr->left.SetDone(FALSE); | |
1889 | constr->top.SetDone(FALSE); | |
1890 | constr->right.SetDone(FALSE); | |
1891 | constr->bottom.SetDone(FALSE); | |
1892 | constr->width.SetDone(FALSE); | |
1893 | constr->height.SetDone(FALSE); | |
1894 | constr->centreX.SetDone(FALSE); | |
1895 | constr->centreY.SetDone(FALSE); | |
1896 | } | |
1897 | wxNode *node = GetChildren().First(); | |
1898 | while (node) | |
1899 | { | |
1900 | wxWindow *win = (wxWindow *)node->Data(); | |
1901 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))) | |
1902 | win->ResetConstraints(); | |
1903 | node = node->Next(); | |
1904 | } | |
4bb6408c JS |
1905 | } |
1906 | ||
1907 | // Need to distinguish between setting the 'fake' size for | |
1908 | // windows and sizers, and setting the real values. | |
1909 | void wxWindow::SetConstraintSizes(bool recurse) | |
1910 | { | |
2d120f83 JS |
1911 | wxLayoutConstraints *constr = GetConstraints(); |
1912 | if (constr && constr->left.GetDone() && constr->right.GetDone() && | |
1913 | constr->width.GetDone() && constr->height.GetDone()) | |
4bb6408c | 1914 | { |
2d120f83 JS |
1915 | int x = constr->left.GetValue(); |
1916 | int y = constr->top.GetValue(); | |
1917 | int w = constr->width.GetValue(); | |
1918 | int h = constr->height.GetValue(); | |
1919 | ||
1920 | // If we don't want to resize this window, just move it... | |
1921 | if ((constr->width.GetRelationship() != wxAsIs) || | |
1922 | (constr->height.GetRelationship() != wxAsIs)) | |
1923 | { | |
1924 | // Calls Layout() recursively. AAAGH. How can we stop that. | |
1925 | // Simply take Layout() out of non-top level OnSizes. | |
1926 | SizerSetSize(x, y, w, h); | |
1927 | } | |
1928 | else | |
1929 | { | |
1930 | SizerMove(x, y); | |
1931 | } | |
4bb6408c | 1932 | } |
2d120f83 | 1933 | else if (constr) |
4bb6408c | 1934 | { |
2d120f83 JS |
1935 | char *windowClass = this->GetClassInfo()->GetClassName(); |
1936 | ||
1937 | wxString winName; | |
1938 | if (GetName() == "") | |
1939 | winName = "unnamed"; | |
1940 | else | |
1941 | winName = GetName(); | |
1942 | wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass, (const char *)winName); | |
1943 | if (!constr->left.GetDone()) | |
1944 | wxDebugMsg(" unsatisfied 'left' constraint.\n"); | |
1945 | if (!constr->right.GetDone()) | |
1946 | wxDebugMsg(" unsatisfied 'right' constraint.\n"); | |
1947 | if (!constr->width.GetDone()) | |
1948 | wxDebugMsg(" unsatisfied 'width' constraint.\n"); | |
1949 | if (!constr->height.GetDone()) | |
1950 | wxDebugMsg(" unsatisfied 'height' constraint.\n"); | |
1951 | wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n"); | |
4bb6408c | 1952 | } |
2d120f83 JS |
1953 | |
1954 | if (recurse) | |
4bb6408c | 1955 | { |
2d120f83 JS |
1956 | wxNode *node = GetChildren().First(); |
1957 | while (node) | |
1958 | { | |
1959 | wxWindow *win = (wxWindow *)node->Data(); | |
1960 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))) | |
1961 | win->SetConstraintSizes(); | |
1962 | node = node->Next(); | |
1963 | } | |
4bb6408c | 1964 | } |
4bb6408c JS |
1965 | } |
1966 | ||
1967 | // This assumes that all sizers are 'on' the same | |
1968 | // window, i.e. the parent of this window. | |
1969 | void wxWindow::TransformSizerToActual(int *x, int *y) const | |
1970 | { | |
2d120f83 JS |
1971 | if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) || |
1972 | m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) ) | |
1973 | return; | |
4bb6408c | 1974 | |
2d120f83 JS |
1975 | int xp, yp; |
1976 | m_sizerParent->GetPosition(&xp, &yp); | |
1977 | m_sizerParent->TransformSizerToActual(&xp, &yp); | |
1978 | *x += xp; | |
1979 | *y += yp; | |
4bb6408c JS |
1980 | } |
1981 | ||
1982 | void wxWindow::SizerSetSize(int x, int y, int w, int h) | |
1983 | { | |
2d120f83 JS |
1984 | int xx = x; |
1985 | int yy = y; | |
1986 | TransformSizerToActual(&xx, &yy); | |
1987 | SetSize(xx, yy, w, h); | |
4bb6408c JS |
1988 | } |
1989 | ||
1990 | void wxWindow::SizerMove(int x, int y) | |
1991 | { | |
2d120f83 JS |
1992 | int xx = x; |
1993 | int yy = y; | |
1994 | TransformSizerToActual(&xx, &yy); | |
1995 | Move(xx, yy); | |
4bb6408c JS |
1996 | } |
1997 | ||
1998 | // Only set the size/position of the constraint (if any) | |
1999 | void wxWindow::SetSizeConstraint(int x, int y, int w, int h) | |
2000 | { | |
2d120f83 JS |
2001 | wxLayoutConstraints *constr = GetConstraints(); |
2002 | if (constr) | |
4bb6408c | 2003 | { |
2d120f83 JS |
2004 | if (x != -1) |
2005 | { | |
2006 | constr->left.SetValue(x); | |
2007 | constr->left.SetDone(TRUE); | |
2008 | } | |
2009 | if (y != -1) | |
2010 | { | |
2011 | constr->top.SetValue(y); | |
2012 | constr->top.SetDone(TRUE); | |
2013 | } | |
2014 | if (w != -1) | |
2015 | { | |
2016 | constr->width.SetValue(w); | |
2017 | constr->width.SetDone(TRUE); | |
2018 | } | |
2019 | if (h != -1) | |
2020 | { | |
2021 | constr->height.SetValue(h); | |
2022 | constr->height.SetDone(TRUE); | |
2023 | } | |
4bb6408c | 2024 | } |
4bb6408c JS |
2025 | } |
2026 | ||
2027 | void wxWindow::MoveConstraint(int x, int y) | |
2028 | { | |
2d120f83 JS |
2029 | wxLayoutConstraints *constr = GetConstraints(); |
2030 | if (constr) | |
4bb6408c | 2031 | { |
2d120f83 JS |
2032 | if (x != -1) |
2033 | { | |
2034 | constr->left.SetValue(x); | |
2035 | constr->left.SetDone(TRUE); | |
2036 | } | |
2037 | if (y != -1) | |
2038 | { | |
2039 | constr->top.SetValue(y); | |
2040 | constr->top.SetDone(TRUE); | |
2041 | } | |
4bb6408c | 2042 | } |
4bb6408c JS |
2043 | } |
2044 | ||
2045 | void wxWindow::GetSizeConstraint(int *w, int *h) const | |
2046 | { | |
2d120f83 JS |
2047 | wxLayoutConstraints *constr = GetConstraints(); |
2048 | if (constr) | |
2049 | { | |
2050 | *w = constr->width.GetValue(); | |
2051 | *h = constr->height.GetValue(); | |
2052 | } | |
2053 | else | |
2054 | GetSize(w, h); | |
4bb6408c JS |
2055 | } |
2056 | ||
2057 | void wxWindow::GetClientSizeConstraint(int *w, int *h) const | |
2058 | { | |
2d120f83 JS |
2059 | wxLayoutConstraints *constr = GetConstraints(); |
2060 | if (constr) | |
2061 | { | |
2062 | *w = constr->width.GetValue(); | |
2063 | *h = constr->height.GetValue(); | |
2064 | } | |
2065 | else | |
2066 | GetClientSize(w, h); | |
4bb6408c JS |
2067 | } |
2068 | ||
2069 | void wxWindow::GetPositionConstraint(int *x, int *y) const | |
2070 | { | |
2d120f83 JS |
2071 | wxLayoutConstraints *constr = GetConstraints(); |
2072 | if (constr) | |
2073 | { | |
2074 | *x = constr->left.GetValue(); | |
2075 | *y = constr->top.GetValue(); | |
2076 | } | |
2077 | else | |
2078 | GetPosition(x, y); | |
4bb6408c JS |
2079 | } |
2080 | ||
2081 | bool wxWindow::Close(bool force) | |
2082 | { | |
2d120f83 JS |
2083 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); |
2084 | event.SetEventObject(this); | |
e3065973 | 2085 | #if WXWIN_COMPATIBILITY |
2d120f83 | 2086 | event.SetForce(force); |
e3065973 JS |
2087 | #endif |
2088 | event.SetCanVeto(!force); | |
2d120f83 JS |
2089 | |
2090 | return GetEventHandler()->ProcessEvent(event); | |
4bb6408c JS |
2091 | } |
2092 | ||
2093 | wxObject* wxWindow::GetChild(int number) const | |
2094 | { | |
2d120f83 JS |
2095 | // Return a pointer to the Nth object in the window |
2096 | wxNode *node = GetChildren().First(); | |
2097 | int n = number; | |
2098 | while (node && n--) | |
2099 | node = node->Next() ; | |
2100 | if (node) | |
2101 | { | |
2102 | wxObject *obj = (wxObject *)node->Data(); | |
2103 | return(obj) ; | |
2104 | } | |
2105 | else | |
2106 | return NULL ; | |
4bb6408c JS |
2107 | } |
2108 | ||
2109 | void wxWindow::OnDefaultAction(wxControl *initiatingItem) | |
2110 | { | |
2111 | // Obsolete function | |
2112 | } | |
2113 | ||
2114 | void wxWindow::Clear() | |
2115 | { | |
e97f20a0 | 2116 | wxClientDC dc(this); |
4bb6408c JS |
2117 | wxBrush brush(GetBackgroundColour(), wxSOLID); |
2118 | dc.SetBackground(brush); | |
2119 | dc.Clear(); | |
2120 | } | |
2121 | ||
2122 | // Fits the panel around the items | |
2123 | void wxWindow::Fit() | |
2124 | { | |
2d120f83 JS |
2125 | int maxX = 0; |
2126 | int maxY = 0; | |
2127 | wxNode *node = GetChildren().First(); | |
2128 | while ( node ) | |
2129 | { | |
2130 | wxWindow *win = (wxWindow *)node->Data(); | |
2131 | int wx, wy, ww, wh; | |
2132 | win->GetPosition(&wx, &wy); | |
2133 | win->GetSize(&ww, &wh); | |
2134 | if ( wx + ww > maxX ) | |
2135 | maxX = wx + ww; | |
2136 | if ( wy + wh > maxY ) | |
2137 | maxY = wy + wh; | |
2138 | ||
2139 | node = node->Next(); | |
2140 | } | |
2141 | SetClientSize(maxX + 5, maxY + 5); | |
4bb6408c JS |
2142 | } |
2143 | ||
2144 | void wxWindow::SetValidator(const wxValidator& validator) | |
2145 | { | |
2d120f83 JS |
2146 | if ( m_windowValidator ) |
2147 | delete m_windowValidator; | |
2148 | m_windowValidator = validator.Clone(); | |
2149 | ||
2150 | if ( m_windowValidator ) | |
2151 | m_windowValidator->SetWindow(this) ; | |
3dd4e4e0 JS |
2152 | } |
2153 | ||
2154 | void wxWindow::SetClientObject( wxClientData *data ) | |
2155 | { | |
2d120f83 JS |
2156 | if (m_clientObject) delete m_clientObject; |
2157 | m_clientObject = data; | |
3dd4e4e0 JS |
2158 | } |
2159 | ||
2160 | wxClientData *wxWindow::GetClientObject() | |
2161 | { | |
2d120f83 | 2162 | return m_clientObject; |
3dd4e4e0 JS |
2163 | } |
2164 | ||
2165 | void wxWindow::SetClientData( void *data ) | |
2166 | { | |
2d120f83 | 2167 | m_clientData = data; |
3dd4e4e0 JS |
2168 | } |
2169 | ||
2170 | void *wxWindow::GetClientData() | |
2171 | { | |
2d120f83 | 2172 | return m_clientData; |
4bb6408c JS |
2173 | } |
2174 | ||
2175 | // Find a window by id or name | |
2176 | wxWindow *wxWindow::FindWindow(long id) | |
2177 | { | |
2d120f83 JS |
2178 | if ( GetId() == id) |
2179 | return this; | |
2180 | ||
2181 | wxNode *node = GetChildren().First(); | |
2182 | while ( node ) | |
2183 | { | |
2184 | wxWindow *child = (wxWindow *)node->Data(); | |
2185 | wxWindow *found = child->FindWindow(id); | |
2186 | if ( found ) | |
2187 | return found; | |
2188 | node = node->Next(); | |
2189 | } | |
2190 | return NULL; | |
4bb6408c JS |
2191 | } |
2192 | ||
2193 | wxWindow *wxWindow::FindWindow(const wxString& name) | |
2194 | { | |
2d120f83 JS |
2195 | if ( GetName() == name) |
2196 | return this; | |
2197 | ||
2198 | wxNode *node = GetChildren().First(); | |
2199 | while ( node ) | |
2200 | { | |
2201 | wxWindow *child = (wxWindow *)node->Data(); | |
2202 | wxWindow *found = child->FindWindow(name); | |
2203 | if ( found ) | |
2204 | return found; | |
2205 | node = node->Next(); | |
2206 | } | |
2207 | return NULL; | |
4bb6408c JS |
2208 | } |
2209 | ||
2210 | void wxWindow::OnIdle(wxIdleEvent& event) | |
2211 | { | |
4bb6408c JS |
2212 | // This calls the UI-update mechanism (querying windows for |
2213 | // menu/toolbar/control state information) | |
0d57be45 | 2214 | UpdateWindowUI(); |
4bb6408c JS |
2215 | } |
2216 | ||
2217 | // Raise the window to the top of the Z order | |
2218 | void wxWindow::Raise() | |
2219 | { | |
02e8b2f9 JS |
2220 | Window window = XtWindow((Widget) GetTopWidget()); |
2221 | XRaiseWindow(XtDisplay((Widget) GetTopWidget()), window); | |
4bb6408c JS |
2222 | } |
2223 | ||
2224 | // Lower the window to the bottom of the Z order | |
2225 | void wxWindow::Lower() | |
2226 | { | |
02e8b2f9 JS |
2227 | Window window = XtWindow((Widget) GetTopWidget()); |
2228 | XLowerWindow(XtDisplay((Widget) GetTopWidget()), window); | |
4bb6408c JS |
2229 | } |
2230 | ||
2231 | bool wxWindow::AcceptsFocus() const | |
2232 | { | |
2d120f83 | 2233 | return IsShown() && IsEnabled(); |
4bb6408c JS |
2234 | } |
2235 | ||
2236 | // Update region access | |
55acd85e | 2237 | wxRegion& wxWindow::GetUpdateRegion() const |
4bb6408c | 2238 | { |
55acd85e | 2239 | return (wxRegion&) m_updateRegion; |
4bb6408c JS |
2240 | } |
2241 | ||
2242 | bool wxWindow::IsExposed(int x, int y, int w, int h) const | |
2243 | { | |
2244 | return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion); | |
2245 | } | |
2246 | ||
2247 | bool wxWindow::IsExposed(const wxPoint& pt) const | |
2248 | { | |
2249 | return (m_updateRegion.Contains(pt) != wxOutRegion); | |
2250 | } | |
2251 | ||
2252 | bool wxWindow::IsExposed(const wxRect& rect) const | |
2253 | { | |
2254 | return (m_updateRegion.Contains(rect) != wxOutRegion); | |
2255 | } | |
2256 | ||
2257 | /* | |
2d120f83 JS |
2258 | * Allocates control IDs |
2259 | */ | |
4bb6408c JS |
2260 | |
2261 | int wxWindow::NewControlId() | |
2262 | { | |
2263 | static int s_controlId = 0; | |
2264 | s_controlId ++; | |
2265 | return s_controlId; | |
2266 | } | |
2267 | ||
2268 | void wxWindow::SetAcceleratorTable(const wxAcceleratorTable& accel) | |
2269 | { | |
2270 | m_acceleratorTable = accel; | |
2271 | } | |
2272 | ||
2273 | // All widgets should have this as their resize proc. | |
2274 | // OnSize sent to wxWindow via client data. | |
2275 | void wxWidgetResizeProc(Widget w, XConfigureEvent *event, String args[], int *num_args) | |
2276 | { | |
2277 | wxWindow *win = (wxWindow *)wxWidgetHashTable->Get((long)w); | |
2278 | if (!win) | |
2279 | return; | |
2d120f83 | 2280 | |
4bb6408c JS |
2281 | if (win->PreResize()) |
2282 | { | |
2283 | int width, height; | |
2284 | win->GetSize(&width, &height); | |
2285 | wxSizeEvent sizeEvent(wxSize(width, height), win->GetId()); | |
2286 | sizeEvent.SetEventObject(win); | |
2287 | win->GetEventHandler()->ProcessEvent(sizeEvent); | |
2288 | } | |
2289 | } | |
2290 | ||
2291 | bool wxAddWindowToTable(Widget w, wxWindow *win) | |
2292 | { | |
2d120f83 JS |
2293 | wxWindow *oldItem = NULL; |
2294 | // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName()); | |
2295 | if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w))) | |
2296 | { | |
2297 | wxLogError("Widget table clash: new widget is %ld, %s", (long)w, win->GetClassInfo()->GetClassName()); | |
2298 | return FALSE; | |
2299 | } | |
2300 | ||
2301 | wxWidgetHashTable->Put ((long) w, win); | |
2302 | return TRUE; | |
4bb6408c JS |
2303 | } |
2304 | ||
2305 | wxWindow *wxGetWindowFromTable(Widget w) | |
2306 | { | |
2d120f83 | 2307 | return (wxWindow *)wxWidgetHashTable->Get ((long) w); |
4bb6408c JS |
2308 | } |
2309 | ||
2310 | void wxDeleteWindowFromTable(Widget w) | |
2311 | { | |
2d120f83 | 2312 | wxWidgetHashTable->Delete((long)w); |
4bb6408c | 2313 | } |
2d120f83 | 2314 | |
4bb6408c JS |
2315 | // Get the underlying X window and display |
2316 | WXWindow wxWindow::GetXWindow() const | |
2317 | { | |
50414e24 | 2318 | return (WXWindow) XtWindow((Widget) GetMainWidget()); |
4bb6408c JS |
2319 | } |
2320 | ||
2321 | WXDisplay *wxWindow::GetXDisplay() const | |
2322 | { | |
50414e24 | 2323 | return (WXDisplay*) XtDisplay((Widget) GetMainWidget()); |
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 |