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