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