]>
Commit | Line | Data |
---|---|---|
83df96d6 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: windows.cpp | |
3 | // Purpose: wxWindow | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "window.h" | |
22 | #endif | |
23 | ||
83df96d6 JS |
24 | #include "wx/setup.h" |
25 | #include "wx/menu.h" | |
26 | #include "wx/dc.h" | |
27 | #include "wx/dcclient.h" | |
28 | #include "wx/utils.h" | |
29 | #include "wx/app.h" | |
30 | #include "wx/panel.h" | |
31 | #include "wx/layout.h" | |
32 | #include "wx/dialog.h" | |
33 | #include "wx/listbox.h" | |
34 | #include "wx/button.h" | |
35 | #include "wx/settings.h" | |
36 | #include "wx/msgdlg.h" | |
37 | #include "wx/frame.h" | |
38 | #include "wx/scrolwin.h" | |
39 | #include "wx/module.h" | |
40 | #include "wx/menuitem.h" | |
41 | #include "wx/log.h" | |
42 | ||
43 | #if wxUSE_DRAG_AND_DROP | |
44 | #include "wx/dnd.h" | |
45 | #endif | |
46 | ||
bc797f4c | 47 | #include "wx/x11/private.h" |
83df96d6 JS |
48 | |
49 | #include <string.h> | |
50 | ||
51 | // ---------------------------------------------------------------------------- | |
52 | // constants | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
55 | static const int SCROLL_MARGIN = 4; | |
56 | ||
57 | // ---------------------------------------------------------------------------- | |
58 | // global variables for this module | |
59 | // ---------------------------------------------------------------------------- | |
60 | ||
61 | extern wxHashTable *wxWidgetHashTable; | |
62 | static wxWindow* g_captureWindow = NULL; | |
63 | ||
83df96d6 JS |
64 | // ---------------------------------------------------------------------------- |
65 | // macros | |
66 | // ---------------------------------------------------------------------------- | |
67 | ||
68 | #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask) | |
69 | #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask) | |
70 | #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask) | |
71 | ||
72 | // ---------------------------------------------------------------------------- | |
73 | // event tables | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
bc797f4c | 76 | IMPLEMENT_DYNAMIC_CLASS(wxWindowX11, wxWindowBase) |
83df96d6 | 77 | |
bc797f4c JS |
78 | BEGIN_EVENT_TABLE(wxWindowX11, wxWindowBase) |
79 | EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged) | |
80 | EVT_IDLE(wxWindowX11::OnIdle) | |
81 | END_EVENT_TABLE() | |
83df96d6 JS |
82 | |
83 | // ============================================================================ | |
84 | // implementation | |
85 | // ============================================================================ | |
86 | ||
87 | // ---------------------------------------------------------------------------- | |
88 | // helper functions | |
89 | // ---------------------------------------------------------------------------- | |
90 | ||
83df96d6 JS |
91 | // ---------------------------------------------------------------------------- |
92 | // constructors | |
93 | // ---------------------------------------------------------------------------- | |
94 | ||
bc797f4c | 95 | void wxWindowX11::Init() |
83df96d6 JS |
96 | { |
97 | // generic initializations first | |
98 | InitBase(); | |
99 | ||
100 | // Motif-specific | |
101 | m_needsRefresh = TRUE; | |
102 | m_mainWidget = (WXWidget) 0; | |
103 | ||
104 | m_button1Pressed = | |
105 | m_button2Pressed = | |
106 | m_button3Pressed = FALSE; | |
107 | ||
108 | m_winCaptured = FALSE; | |
109 | ||
110 | m_isShown = TRUE; | |
111 | m_isBeingDeleted = FALSE; | |
112 | ||
113 | m_hScrollBar = | |
114 | m_vScrollBar = | |
115 | m_borderWidget = | |
116 | m_scrolledWindow = | |
117 | m_drawingArea = (WXWidget) 0; | |
118 | ||
119 | m_hScroll = | |
120 | m_vScroll = FALSE; | |
121 | ||
122 | m_scrollPosX = | |
123 | m_scrollPosY = 0; | |
124 | ||
125 | m_backingPixmap = (WXPixmap) 0; | |
126 | m_pixmapWidth = | |
127 | m_pixmapHeight = 0; | |
128 | ||
129 | m_pixmapOffsetX = | |
130 | m_pixmapOffsetY = 0; | |
131 | ||
132 | m_lastTS = 0; | |
133 | m_lastButton = 0; | |
134 | m_canAddEventHandler = FALSE; | |
135 | } | |
136 | ||
137 | // real construction (Init() must have been called before!) | |
bc797f4c | 138 | bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, |
83df96d6 JS |
139 | const wxPoint& pos, |
140 | const wxSize& size, | |
141 | long style, | |
142 | const wxString& name) | |
143 | { | |
144 | wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" ); | |
145 | ||
146 | CreateBase(parent, id, pos, size, style, wxDefaultValidator, name); | |
147 | ||
148 | parent->AddChild(this); | |
149 | ||
150 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); | |
151 | m_foregroundColour = *wxBLACK; | |
152 | ||
83df96d6 JS |
153 | if (style & wxSIMPLE_BORDER) |
154 | { | |
83df96d6 JS |
155 | } else if (style & wxSUNKEN_BORDER) |
156 | { | |
83df96d6 JS |
157 | } else if (style & wxRAISED_BORDER) |
158 | { | |
83df96d6 JS |
159 | } |
160 | ||
bc797f4c | 161 | // TODO: create XWindow |
83df96d6 JS |
162 | |
163 | #if 0 | |
bc797f4c JS |
164 | wxAddWindowToTable((Window) m_drawingArea, this); |
165 | wxAddWindowToTable((Window) m_scrolledWindow, this); | |
166 | #endif | |
83df96d6 JS |
167 | |
168 | // Without this, the cursor may not be restored properly (e.g. in splitter | |
169 | // sample). | |
170 | SetCursor(*wxSTANDARD_CURSOR); | |
171 | SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
172 | SetSize(pos.x, pos.y, size.x, size.y); | |
173 | ||
174 | return TRUE; | |
175 | } | |
176 | ||
177 | // Destructor | |
bc797f4c | 178 | wxWindowX11::~wxWindow() |
83df96d6 JS |
179 | { |
180 | if (g_captureWindow == this) | |
181 | g_captureWindow = NULL; | |
182 | ||
183 | m_isBeingDeleted = TRUE; | |
184 | ||
185 | // Motif-specific actions first | |
bc797f4c | 186 | WXWindow wMain = GetMainWindow(); |
83df96d6 JS |
187 | if ( wMain ) |
188 | { | |
189 | // Removes event handlers | |
bc797f4c | 190 | //DetachWidget(wMain); |
83df96d6 JS |
191 | } |
192 | ||
193 | ClearUpdateRects(); | |
194 | ||
195 | if ( m_parent ) | |
196 | m_parent->RemoveChild( this ); | |
197 | ||
bc797f4c JS |
198 | // TODO |
199 | ||
200 | #if 0 | |
83df96d6 JS |
201 | // If m_drawingArea, we're a fully-fledged window with drawing area, |
202 | // scrollbars etc. (what wxCanvas used to be) | |
203 | if ( m_drawingArea ) | |
204 | { | |
205 | // Destroy children before destroying self | |
206 | DestroyChildren(); | |
207 | ||
208 | if (m_backingPixmap) | |
209 | XFreePixmap (XtDisplay ((Widget) GetMainWidget()), (Pixmap) m_backingPixmap); | |
210 | ||
211 | Widget w = (Widget) m_drawingArea; | |
212 | wxDeleteWindowFromTable(w); | |
213 | ||
214 | if (w) | |
215 | { | |
216 | XtDestroyWidget(w); | |
217 | m_drawingArea = (WXWidget) 0; | |
218 | } | |
219 | ||
220 | // Only if we're _really_ a canvas (not a dialog box/panel) | |
221 | if (m_scrolledWindow) | |
222 | { | |
223 | wxDeleteWindowFromTable((Widget) m_scrolledWindow); | |
224 | } | |
225 | ||
226 | if (m_hScrollBar) | |
227 | { | |
228 | wxDeleteWindowFromTable((Widget) m_hScrollBar); | |
229 | XtUnmanageChild((Widget) m_hScrollBar); | |
230 | } | |
231 | if (m_vScrollBar) | |
232 | { | |
233 | wxDeleteWindowFromTable((Widget) m_vScrollBar); | |
234 | XtUnmanageChild((Widget) m_vScrollBar); | |
235 | } | |
236 | ||
237 | if (m_hScrollBar) | |
238 | XtDestroyWidget((Widget) m_hScrollBar); | |
239 | if (m_vScrollBar) | |
240 | XtDestroyWidget((Widget) m_vScrollBar); | |
241 | ||
242 | UnmanageAndDestroy(m_scrolledWindow); | |
243 | ||
244 | if (m_borderWidget) | |
245 | { | |
246 | XtDestroyWidget ((Widget) m_borderWidget); | |
247 | m_borderWidget = (WXWidget) 0; | |
248 | } | |
249 | } | |
250 | else // Why wasn't this here before? JACS 8/3/2000 | |
bc797f4c | 251 | #endif |
83df96d6 JS |
252 | DestroyChildren(); |
253 | ||
254 | ||
255 | // Destroy the window | |
bc797f4c JS |
256 | if (GetMainWindow()) |
257 | { | |
258 | // TODO | |
259 | // XtDestroyWidget((Widget) GetMainWidget()); | |
260 | SetMainWindow((WXWindow) NULL); | |
83df96d6 JS |
261 | } |
262 | } | |
263 | ||
264 | // ---------------------------------------------------------------------------- | |
265 | // scrollbar management | |
266 | // ---------------------------------------------------------------------------- | |
267 | ||
268 | // Helper function | |
bc797f4c | 269 | void wxWindowX11::CreateScrollbar(wxOrientation orientation) |
83df96d6 | 270 | { |
bc797f4c JS |
271 | // TODO |
272 | #if 0 | |
83df96d6 JS |
273 | wxCHECK_RET( m_drawingArea, "this window can't have scrollbars" ); |
274 | ||
275 | XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_NONE, NULL); | |
276 | ||
277 | // Add scrollbars if required | |
278 | if (orientation == wxHORIZONTAL) | |
279 | { | |
280 | Widget hScrollBar = XtVaCreateManagedWidget ("hsb", | |
281 | xmScrollBarWidgetClass, (Widget) m_scrolledWindow, | |
282 | XmNorientation, XmHORIZONTAL, | |
283 | NULL); | |
284 | XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
285 | XtAddCallback (hScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
286 | XtAddCallback (hScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
287 | XtAddCallback (hScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
288 | XtAddCallback (hScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
289 | XtAddCallback (hScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
290 | XtAddCallback (hScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
291 | XtAddCallback (hScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL); | |
292 | ||
293 | XtVaSetValues (hScrollBar, | |
294 | XmNincrement, 1, | |
295 | XmNvalue, 0, | |
296 | NULL); | |
297 | ||
298 | m_hScrollBar = (WXWidget) hScrollBar; | |
299 | ||
300 | wxColour backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); | |
301 | DoChangeBackgroundColour(m_hScrollBar, backgroundColour, TRUE); | |
302 | ||
303 | XtRealizeWidget(hScrollBar); | |
304 | ||
305 | XtVaSetValues((Widget) m_scrolledWindow, | |
306 | XmNhorizontalScrollBar, (Widget) m_hScrollBar, | |
307 | NULL); | |
308 | ||
309 | m_hScroll = TRUE; | |
310 | ||
311 | wxAddWindowToTable( hScrollBar, this ); | |
312 | } | |
313 | ||
314 | if (orientation == wxVERTICAL) | |
315 | { | |
316 | Widget vScrollBar = XtVaCreateManagedWidget ("vsb", | |
317 | xmScrollBarWidgetClass, (Widget) m_scrolledWindow, | |
318 | XmNorientation, XmVERTICAL, | |
319 | NULL); | |
320 | XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
321 | XtAddCallback (vScrollBar, XmNdragCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
322 | XtAddCallback (vScrollBar, XmNincrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
323 | XtAddCallback (vScrollBar, XmNdecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
324 | XtAddCallback (vScrollBar, XmNpageIncrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
325 | XtAddCallback (vScrollBar, XmNpageDecrementCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
326 | XtAddCallback (vScrollBar, XmNtoTopCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
327 | XtAddCallback (vScrollBar, XmNtoBottomCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL); | |
328 | ||
329 | XtVaSetValues (vScrollBar, | |
330 | XmNincrement, 1, | |
331 | XmNvalue, 0, | |
332 | NULL); | |
333 | ||
334 | m_vScrollBar = (WXWidget) vScrollBar; | |
335 | wxColour backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); | |
336 | DoChangeBackgroundColour(m_vScrollBar, backgroundColour, TRUE); | |
337 | ||
338 | XtRealizeWidget(vScrollBar); | |
339 | ||
340 | XtVaSetValues((Widget) m_scrolledWindow, | |
341 | XmNverticalScrollBar, (Widget) m_vScrollBar, | |
342 | NULL); | |
343 | ||
344 | m_vScroll = TRUE; | |
345 | ||
346 | wxAddWindowToTable( vScrollBar, this ); | |
347 | } | |
348 | ||
349 | XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL); | |
bc797f4c | 350 | #endif |
83df96d6 JS |
351 | } |
352 | ||
bc797f4c | 353 | void wxWindowX11::DestroyScrollbar(wxOrientation orientation) |
83df96d6 | 354 | { |
bc797f4c JS |
355 | // TODO |
356 | #if 0 | |
83df96d6 JS |
357 | wxCHECK_RET( m_drawingArea, "this window can't have scrollbars" ); |
358 | ||
359 | XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_NONE, NULL); | |
360 | // Add scrollbars if required | |
361 | if (orientation == wxHORIZONTAL) | |
362 | { | |
363 | if (m_hScrollBar) | |
364 | { | |
365 | wxDeleteWindowFromTable((Widget)m_hScrollBar); | |
366 | XtDestroyWidget((Widget) m_hScrollBar); | |
367 | } | |
368 | m_hScrollBar = (WXWidget) 0; | |
369 | m_hScroll = FALSE; | |
370 | ||
371 | XtVaSetValues((Widget) m_scrolledWindow, | |
372 | XmNhorizontalScrollBar, (Widget) 0, | |
373 | NULL); | |
374 | ||
375 | } | |
376 | ||
377 | if (orientation == wxVERTICAL) | |
378 | { | |
379 | if (m_vScrollBar) | |
380 | { | |
381 | wxDeleteWindowFromTable((Widget)m_vScrollBar); | |
382 | XtDestroyWidget((Widget) m_vScrollBar); | |
383 | } | |
384 | m_vScrollBar = (WXWidget) 0; | |
385 | m_vScroll = FALSE; | |
386 | ||
387 | XtVaSetValues((Widget) m_scrolledWindow, | |
388 | XmNverticalScrollBar, (Widget) 0, | |
389 | NULL); | |
390 | ||
391 | } | |
392 | XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL); | |
bc797f4c | 393 | #endif |
83df96d6 JS |
394 | } |
395 | ||
396 | // --------------------------------------------------------------------------- | |
397 | // basic operations | |
398 | // --------------------------------------------------------------------------- | |
399 | ||
bc797f4c | 400 | void wxWindowX11::SetFocus() |
83df96d6 | 401 | { |
bc797f4c JS |
402 | // TODO |
403 | #if 0 | |
83df96d6 JS |
404 | Widget wMain = (Widget) GetMainWidget(); |
405 | XmProcessTraversal(wMain, XmTRAVERSE_CURRENT); | |
406 | XmProcessTraversal((Widget) GetMainWidget(), XmTRAVERSE_CURRENT); | |
bc797f4c | 407 | #endif |
83df96d6 JS |
408 | } |
409 | ||
410 | // Get the window with the focus | |
411 | wxWindow *wxWindowBase::FindFocus() | |
412 | { | |
bc797f4c JS |
413 | // TODO |
414 | return NULL; | |
415 | #if 0 | |
416 | ||
83df96d6 JS |
417 | // TODO Problems: |
418 | // (1) Can there be multiple focussed widgets in an application? | |
419 | // In which case we need to find the top-level window that's | |
420 | // currently active. | |
421 | // (2) The widget with the focus may not be in the widget table | |
422 | // depending on which widgets I put in the table | |
423 | wxWindow *winFocus = (wxWindow *)NULL; | |
424 | for ( wxWindowList::Node *node = wxTopLevelWindows.GetFirst(); | |
425 | node; | |
426 | node = node->GetNext() ) | |
427 | { | |
428 | wxWindow *win = node->GetData(); | |
429 | ||
430 | Widget w = XmGetFocusWidget ((Widget) win->GetTopWidget()); | |
431 | ||
432 | if (w != (Widget) NULL) | |
433 | { | |
434 | winFocus = wxGetWindowFromTable(w); | |
435 | if ( winFocus ) | |
436 | break; | |
437 | } | |
438 | } | |
439 | ||
440 | return winFocus; | |
bc797f4c | 441 | #endif |
83df96d6 JS |
442 | } |
443 | ||
bc797f4c | 444 | bool wxWindowX11::Enable(bool enable) |
83df96d6 JS |
445 | { |
446 | if ( !wxWindowBase::Enable(enable) ) | |
447 | return FALSE; | |
448 | ||
bc797f4c JS |
449 | // TODO |
450 | #if 0 | |
83df96d6 JS |
451 | Widget wMain = (Widget)GetMainWidget(); |
452 | if ( wMain ) | |
453 | { | |
454 | XtSetSensitive(wMain, enable); | |
455 | XmUpdateDisplay(wMain); | |
456 | } | |
bc797f4c | 457 | #endif |
83df96d6 JS |
458 | |
459 | return TRUE; | |
460 | } | |
461 | ||
bc797f4c | 462 | bool wxWindowX11::Show(bool show) |
83df96d6 JS |
463 | { |
464 | if ( !wxWindowBase::Show(show) ) | |
465 | return FALSE; | |
466 | ||
83df96d6 JS |
467 | Window xwin = (Window) GetXWindow(); |
468 | Display *xdisp = (Display*) GetXDisplay(); | |
469 | if (show) | |
470 | XMapWindow(xdisp, xwin); | |
471 | else | |
472 | XUnmapWindow(xdisp, xwin); | |
83df96d6 JS |
473 | |
474 | return TRUE; | |
475 | } | |
476 | ||
477 | // Raise the window to the top of the Z order | |
bc797f4c | 478 | void wxWindowX11::Raise() |
83df96d6 | 479 | { |
bc797f4c JS |
480 | Window window = GetTopWindow(); |
481 | if (window) | |
482 | XRaiseWindow(wxGetDisplay(), window); | |
83df96d6 JS |
483 | } |
484 | ||
485 | // Lower the window to the bottom of the Z order | |
bc797f4c | 486 | void wxWindowX11::Lower() |
83df96d6 | 487 | { |
bc797f4c JS |
488 | Window window = GetTopWindow(); |
489 | if (window) | |
490 | XLowerWindow(wxGetDisplay(), window); | |
83df96d6 JS |
491 | } |
492 | ||
bc797f4c | 493 | void wxWindowX11::SetTitle(const wxString& title) |
83df96d6 | 494 | { |
bc797f4c JS |
495 | // TODO |
496 | // XtVaSetValues((Widget)GetMainWidget(), XmNtitle, title.c_str(), NULL); | |
83df96d6 JS |
497 | } |
498 | ||
bc797f4c | 499 | wxString wxWindowX11::GetTitle() const |
83df96d6 | 500 | { |
bc797f4c JS |
501 | // TODO |
502 | return wxEmptyString; | |
503 | #if 0 | |
83df96d6 JS |
504 | char *title; |
505 | XtVaGetValues((Widget)GetMainWidget(), XmNtitle, &title, NULL); | |
506 | ||
507 | return wxString(title); | |
bc797f4c | 508 | #endif |
83df96d6 JS |
509 | } |
510 | ||
bc797f4c | 511 | void wxWindowX11::DoCaptureMouse() |
83df96d6 JS |
512 | { |
513 | g_captureWindow = this; | |
514 | if ( m_winCaptured ) | |
515 | return; | |
516 | ||
bc797f4c JS |
517 | // TODO |
518 | #if 0 | |
83df96d6 JS |
519 | Widget wMain = (Widget)GetMainWidget(); |
520 | if ( wMain ) | |
521 | XtAddGrab(wMain, TRUE, FALSE); | |
bc797f4c | 522 | #endif |
83df96d6 JS |
523 | |
524 | m_winCaptured = TRUE; | |
525 | } | |
526 | ||
bc797f4c | 527 | void wxWindowX11::DoReleaseMouse() |
83df96d6 JS |
528 | { |
529 | g_captureWindow = NULL; | |
530 | if ( !m_winCaptured ) | |
531 | return; | |
532 | ||
bc797f4c JS |
533 | // TODO |
534 | #if 0 | |
83df96d6 JS |
535 | Widget wMain = (Widget)GetMainWidget(); |
536 | if ( wMain ) | |
537 | XtRemoveGrab(wMain); | |
bc797f4c | 538 | #endif |
83df96d6 JS |
539 | |
540 | m_winCaptured = FALSE; | |
541 | } | |
542 | ||
bc797f4c | 543 | bool wxWindowX11::SetFont(const wxFont& font) |
83df96d6 JS |
544 | { |
545 | if ( !wxWindowBase::SetFont(font) ) | |
546 | { | |
547 | // nothing to do | |
548 | return FALSE; | |
549 | } | |
550 | ||
551 | ChangeFont(); | |
552 | ||
553 | return TRUE; | |
554 | } | |
555 | ||
bc797f4c | 556 | bool wxWindowX11::SetCursor(const wxCursor& cursor) |
83df96d6 JS |
557 | { |
558 | if ( !wxWindowBase::SetCursor(cursor) ) | |
559 | { | |
560 | // no change | |
561 | return FALSE; | |
562 | } | |
563 | ||
83df96d6 JS |
564 | wxCursor* cursor2 = NULL; |
565 | if (m_cursor.Ok()) | |
566 | cursor2 = & m_cursor; | |
567 | else | |
568 | cursor2 = wxSTANDARD_CURSOR; | |
569 | ||
570 | WXDisplay *dpy = GetXDisplay(); | |
571 | WXCursor x_cursor = cursor2->GetXCursor(dpy); | |
572 | ||
bc797f4c | 573 | Window win = (Window) GetMainWindow(); |
83df96d6 JS |
574 | XDefineCursor((Display*) dpy, win, (Cursor) x_cursor); |
575 | ||
576 | return TRUE; | |
577 | } | |
578 | ||
579 | // Coordinates relative to the window | |
bc797f4c | 580 | void wxWindowX11::WarpPointer (int x, int y) |
83df96d6 | 581 | { |
bc797f4c | 582 | Window wClient = (Window) GetClientWindow(); |
83df96d6 | 583 | |
bc797f4c | 584 | XWarpPointer(wxGetDisplay(), None, wClient, 0, 0, 0, 0, x, y); |
83df96d6 JS |
585 | } |
586 | ||
587 | // --------------------------------------------------------------------------- | |
588 | // scrolling stuff | |
589 | // --------------------------------------------------------------------------- | |
590 | ||
bc797f4c | 591 | int wxWindowX11::GetScrollPos(int orient) const |
83df96d6 JS |
592 | { |
593 | if (orient == wxHORIZONTAL) | |
594 | return m_scrollPosX; | |
595 | else | |
596 | return m_scrollPosY; | |
83df96d6 JS |
597 | } |
598 | ||
599 | // This now returns the whole range, not just the number of positions that we | |
600 | // can scroll. | |
bc797f4c | 601 | int wxWindowX11::GetScrollRange(int WXUNUSED(orient)) const |
83df96d6 | 602 | { |
bc797f4c JS |
603 | // TODO |
604 | return 0; | |
605 | #if 0 | |
83df96d6 JS |
606 | Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient); |
607 | wxCHECK_MSG( scrollBar, 0, "no such scrollbar" ); | |
608 | ||
609 | int range; | |
610 | XtVaGetValues(scrollBar, XmNmaximum, &range, NULL); | |
611 | return range; | |
bc797f4c | 612 | #endif |
83df96d6 JS |
613 | } |
614 | ||
bc797f4c | 615 | int wxWindowX11::GetScrollThumb(int orient) const |
83df96d6 | 616 | { |
bc797f4c JS |
617 | // TODO |
618 | return 0; | |
619 | ||
620 | #if 0 | |
83df96d6 JS |
621 | Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient); |
622 | wxCHECK_MSG( scrollBar, 0, "no such scrollbar" ); | |
623 | ||
624 | int thumb; | |
625 | XtVaGetValues(scrollBar, XmNsliderSize, &thumb, NULL); | |
626 | return thumb; | |
bc797f4c | 627 | #endif |
83df96d6 JS |
628 | } |
629 | ||
bc797f4c | 630 | void wxWindowX11::SetScrollPos(int WXUNUSED(orient), int WXUNUSED(pos), bool WXUNUSED(refresh)) |
83df96d6 | 631 | { |
bc797f4c JS |
632 | // TODO |
633 | ||
634 | #if 0 | |
83df96d6 JS |
635 | Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient); |
636 | ||
637 | if ( scrollBar ) | |
638 | { | |
639 | XtVaSetValues (scrollBar, XmNvalue, pos, NULL); | |
640 | } | |
bc797f4c | 641 | #endif |
83df96d6 JS |
642 | SetInternalScrollPos((wxOrientation)orient, pos); |
643 | } | |
644 | ||
645 | // New function that will replace some of the above. | |
bc797f4c JS |
646 | void wxWindowX11::SetScrollbar(int WXUNUSED(orient), int WXUNUSED(pos), int WXUNUSED(thumbVisible), |
647 | int WXUNUSED(range), bool WXUNUSED(refresh)) | |
83df96d6 | 648 | { |
bc797f4c JS |
649 | // TODO |
650 | #if 0 | |
83df96d6 JS |
651 | int oldW, oldH; |
652 | GetSize(& oldW, & oldH); | |
653 | ||
654 | if (range == 0) | |
655 | range = 1; | |
656 | if (thumbVisible == 0) | |
657 | thumbVisible = 1; | |
658 | ||
659 | if (thumbVisible > range) | |
660 | thumbVisible = range; | |
661 | ||
662 | // Save the old state to see if it changed | |
663 | WXWidget oldScrollBar = GetScrollbar((wxOrientation)orient); | |
664 | ||
665 | if (orient == wxHORIZONTAL) | |
666 | { | |
667 | if (thumbVisible == range) | |
668 | { | |
669 | if (m_hScrollBar) | |
670 | DestroyScrollbar(wxHORIZONTAL); | |
671 | } | |
672 | else | |
673 | { | |
674 | if (!m_hScrollBar) | |
675 | CreateScrollbar(wxHORIZONTAL); | |
676 | } | |
677 | } | |
678 | if (orient == wxVERTICAL) | |
679 | { | |
680 | if (thumbVisible == range) | |
681 | { | |
682 | if (m_vScrollBar) | |
683 | DestroyScrollbar(wxVERTICAL); | |
684 | } | |
685 | else | |
686 | { | |
687 | if (!m_vScrollBar) | |
688 | CreateScrollbar(wxVERTICAL); | |
689 | } | |
690 | } | |
691 | WXWidget newScrollBar = GetScrollbar((wxOrientation)orient); | |
692 | ||
693 | if (oldScrollBar != newScrollBar) | |
694 | { | |
695 | // This is important! Without it, scrollbars misbehave badly. | |
696 | XtUnrealizeWidget((Widget) m_scrolledWindow); | |
697 | XmScrolledWindowSetAreas ((Widget) m_scrolledWindow, (Widget) m_hScrollBar, (Widget) m_vScrollBar, (Widget) m_drawingArea); | |
698 | XtRealizeWidget((Widget) m_scrolledWindow); | |
699 | XtManageChild((Widget) m_scrolledWindow); | |
700 | } | |
701 | ||
702 | if (newScrollBar) | |
703 | { | |
704 | XtVaSetValues((Widget) newScrollBar, | |
705 | XmNvalue, pos, | |
706 | XmNminimum, 0, | |
707 | XmNmaximum, range, | |
708 | XmNsliderSize, thumbVisible, | |
709 | NULL); | |
710 | } | |
711 | ||
712 | SetInternalScrollPos((wxOrientation)orient, pos); | |
713 | ||
714 | int newW, newH; | |
715 | GetSize(& newW, & newH); | |
716 | ||
717 | // Adjusting scrollbars can resize the canvas accidentally | |
718 | if (newW != oldW || newH != oldH) | |
719 | SetSize(-1, -1, oldW, oldH); | |
bc797f4c | 720 | #endif |
83df96d6 JS |
721 | } |
722 | ||
723 | // Does a physical scroll | |
bc797f4c | 724 | void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect) |
83df96d6 JS |
725 | { |
726 | int x, y, w, h; | |
727 | if (rect) | |
728 | { | |
729 | // Use specified rectangle | |
730 | x = rect->x; y = rect->y; w = rect->width; h = rect->height; | |
731 | } | |
732 | else | |
733 | { | |
734 | // Use whole client area | |
735 | x = 0; y = 0; | |
736 | GetClientSize(& w, & h); | |
737 | } | |
bc797f4c | 738 | |
83df96d6 JS |
739 | wxNode *cnode = m_children.First(); |
740 | while (cnode) | |
741 | { | |
742 | wxWindow *child = (wxWindow*) cnode->Data(); | |
bc797f4c JS |
743 | int sx = 0; |
744 | int sy = 0; | |
745 | child->GetSize( &sx, &sy ); | |
83df96d6 | 746 | wxPoint pos( child->GetPosition() ); |
bc797f4c JS |
747 | child->SetSize( pos.x + dx, pos.y + dy, sx, sy, wxSIZE_ALLOW_MINUS_ONE ); |
748 | cnode = cnode->Next(); | |
83df96d6 | 749 | } |
bc797f4c | 750 | |
83df96d6 JS |
751 | int x1 = (dx >= 0) ? x : x - dx; |
752 | int y1 = (dy >= 0) ? y : y - dy; | |
753 | int w1 = w - abs(dx); | |
754 | int h1 = h - abs(dy); | |
755 | int x2 = (dx >= 0) ? x + dx : x; | |
756 | int y2 = (dy >= 0) ? y + dy : y; | |
bc797f4c | 757 | |
83df96d6 | 758 | wxClientDC dc(this); |
bc797f4c | 759 | |
83df96d6 | 760 | dc.SetLogicalFunction (wxCOPY); |
bc797f4c JS |
761 | |
762 | Window window = (Window) GetMainWindow(); | |
763 | Display* display = wxGetDisplay(); | |
764 | ||
83df96d6 | 765 | XCopyArea(display, window, window, (GC) dc.GetGC(), |
bc797f4c JS |
766 | x1, y1, w1, h1, x2, y2); |
767 | ||
83df96d6 JS |
768 | dc.SetAutoSetting(TRUE); |
769 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
770 | dc.SetBrush(brush); // FIXME: needed? | |
bc797f4c | 771 | |
83df96d6 JS |
772 | // We'll add rectangles to the list of update rectangles according to which |
773 | // bits we've exposed. | |
774 | wxList updateRects; | |
bc797f4c | 775 | |
83df96d6 JS |
776 | if (dx > 0) |
777 | { | |
778 | wxRect *rect = new wxRect; | |
779 | rect->x = x; | |
780 | rect->y = y; | |
781 | rect->width = dx; | |
782 | rect->height = h; | |
bc797f4c | 783 | |
83df96d6 JS |
784 | XFillRectangle(display, window, |
785 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); | |
bc797f4c | 786 | |
83df96d6 JS |
787 | rect->x = rect->x; |
788 | rect->y = rect->y; | |
789 | rect->width = rect->width; | |
790 | rect->height = rect->height; | |
bc797f4c | 791 | |
83df96d6 JS |
792 | updateRects.Append((wxObject*) rect); |
793 | } | |
794 | else if (dx < 0) | |
795 | { | |
796 | wxRect *rect = new wxRect; | |
bc797f4c | 797 | |
83df96d6 JS |
798 | rect->x = x + w + dx; |
799 | rect->y = y; | |
800 | rect->width = -dx; | |
801 | rect->height = h; | |
bc797f4c | 802 | |
83df96d6 JS |
803 | XFillRectangle(display, window, |
804 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, | |
805 | rect->height); | |
bc797f4c | 806 | |
83df96d6 JS |
807 | rect->x = rect->x; |
808 | rect->y = rect->y; | |
809 | rect->width = rect->width; | |
810 | rect->height = rect->height; | |
bc797f4c | 811 | |
83df96d6 JS |
812 | updateRects.Append((wxObject*) rect); |
813 | } | |
814 | if (dy > 0) | |
815 | { | |
816 | wxRect *rect = new wxRect; | |
bc797f4c | 817 | |
83df96d6 JS |
818 | rect->x = x; |
819 | rect->y = y; | |
820 | rect->width = w; | |
821 | rect->height = dy; | |
bc797f4c | 822 | |
83df96d6 JS |
823 | XFillRectangle(display, window, |
824 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); | |
bc797f4c | 825 | |
83df96d6 JS |
826 | rect->x = rect->x; |
827 | rect->y = rect->y; | |
828 | rect->width = rect->width; | |
829 | rect->height = rect->height; | |
bc797f4c | 830 | |
83df96d6 JS |
831 | updateRects.Append((wxObject*) rect); |
832 | } | |
833 | else if (dy < 0) | |
834 | { | |
835 | wxRect *rect = new wxRect; | |
bc797f4c | 836 | |
83df96d6 JS |
837 | rect->x = x; |
838 | rect->y = y + h + dy; | |
839 | rect->width = w; | |
840 | rect->height = -dy; | |
bc797f4c | 841 | |
83df96d6 JS |
842 | XFillRectangle(display, window, |
843 | (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height); | |
bc797f4c | 844 | |
83df96d6 JS |
845 | rect->x = rect->x; |
846 | rect->y = rect->y; | |
847 | rect->width = rect->width; | |
848 | rect->height = rect->height; | |
bc797f4c | 849 | |
83df96d6 JS |
850 | updateRects.Append((wxObject*) rect); |
851 | } | |
852 | dc.SetBrush(wxNullBrush); | |
bc797f4c | 853 | |
83df96d6 | 854 | // Now send expose events |
bc797f4c | 855 | |
83df96d6 JS |
856 | wxNode* node = updateRects.First(); |
857 | while (node) | |
858 | { | |
859 | wxRect* rect = (wxRect*) node->Data(); | |
860 | XExposeEvent event; | |
bc797f4c | 861 | |
83df96d6 JS |
862 | event.type = Expose; |
863 | event.display = display; | |
864 | event.send_event = True; | |
865 | event.window = window; | |
bc797f4c | 866 | |
83df96d6 JS |
867 | event.x = rect->x; |
868 | event.y = rect->y; | |
869 | event.width = rect->width; | |
870 | event.height = rect->height; | |
bc797f4c | 871 | |
83df96d6 | 872 | event.count = 0; |
bc797f4c | 873 | |
83df96d6 | 874 | XSendEvent(display, window, False, ExposureMask, (XEvent *)&event); |
bc797f4c | 875 | |
83df96d6 | 876 | node = node->Next(); |
bc797f4c | 877 | |
83df96d6 | 878 | } |
bc797f4c | 879 | |
83df96d6 JS |
880 | // Delete the update rects |
881 | node = updateRects.First(); | |
882 | while (node) | |
883 | { | |
884 | wxRect* rect = (wxRect*) node->Data(); | |
885 | delete rect; | |
886 | node = node->Next(); | |
887 | } | |
bc797f4c JS |
888 | |
889 | // TODO | |
83df96d6 | 890 | |
bc797f4c | 891 | // XmUpdateDisplay((Widget) GetMainWidget()); |
83df96d6 JS |
892 | } |
893 | ||
894 | // --------------------------------------------------------------------------- | |
895 | // drag and drop | |
896 | // --------------------------------------------------------------------------- | |
897 | ||
898 | #if wxUSE_DRAG_AND_DROP | |
899 | ||
bc797f4c | 900 | void wxWindowX11::SetDropTarget(wxDropTarget * WXUNUSED(pDropTarget)) |
83df96d6 JS |
901 | { |
902 | // TODO | |
903 | } | |
904 | ||
905 | #endif | |
906 | ||
907 | // Old style file-manager drag&drop | |
bc797f4c | 908 | void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept)) |
83df96d6 JS |
909 | { |
910 | // TODO | |
911 | } | |
912 | ||
913 | // ---------------------------------------------------------------------------- | |
914 | // tooltips | |
915 | // ---------------------------------------------------------------------------- | |
916 | ||
917 | #if wxUSE_TOOLTIPS | |
918 | ||
bc797f4c | 919 | void wxWindowX11::DoSetToolTip(wxToolTip * WXUNUSED(tooltip)) |
83df96d6 JS |
920 | { |
921 | // TODO | |
922 | } | |
923 | ||
924 | #endif // wxUSE_TOOLTIPS | |
925 | ||
83df96d6 JS |
926 | // --------------------------------------------------------------------------- |
927 | // moving and resizing | |
928 | // --------------------------------------------------------------------------- | |
929 | ||
bc797f4c | 930 | bool wxWindowX11::PreResize() |
83df96d6 JS |
931 | { |
932 | return TRUE; | |
933 | } | |
934 | ||
935 | // Get total size | |
bc797f4c | 936 | void wxWindowX11::DoGetSize(int *x, int *y) const |
83df96d6 | 937 | { |
bc797f4c JS |
938 | // TODO |
939 | #if 0 | |
83df96d6 JS |
940 | if (m_drawingArea) |
941 | { | |
942 | CanvasGetSize(x, y); | |
943 | return; | |
944 | } | |
945 | ||
946 | Widget widget = (Widget) GetTopWidget(); | |
947 | Dimension xx, yy; | |
948 | XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL); | |
949 | if(x) *x = xx; if(y) *y = yy; | |
bc797f4c | 950 | #endif |
83df96d6 JS |
951 | } |
952 | ||
bc797f4c | 953 | void wxWindowX11::DoGetPosition(int *x, int *y) const |
83df96d6 | 954 | { |
bc797f4c JS |
955 | // TODO |
956 | #if 0 | |
83df96d6 JS |
957 | if (m_drawingArea) |
958 | { | |
959 | CanvasGetPosition(x, y); | |
960 | return; | |
961 | } | |
962 | Widget widget = (Widget) GetTopWidget(); | |
963 | Position xx, yy; | |
964 | XtVaGetValues(widget, XmNx, &xx, XmNy, &yy, NULL); | |
965 | ||
966 | // We may be faking the client origin. So a window that's really at (0, 30) | |
967 | // may appear (to wxWin apps) to be at (0, 0). | |
968 | if (GetParent()) | |
969 | { | |
970 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
971 | xx -= pt.x; | |
972 | yy -= pt.y; | |
973 | } | |
974 | ||
975 | if(x) *x = xx; if(y) *y = yy; | |
bc797f4c | 976 | #endif |
83df96d6 JS |
977 | } |
978 | ||
bc797f4c | 979 | void wxWindowX11::DoScreenToClient(int *x, int *y) const |
83df96d6 | 980 | { |
bc797f4c JS |
981 | Display *display = wxGetDisplay(); |
982 | Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display)); | |
983 | Window thisWindow = (Window) GetClientWindow(); | |
83df96d6 JS |
984 | |
985 | Window childWindow; | |
986 | int xx = *x; | |
987 | int yy = *y; | |
988 | XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow); | |
989 | } | |
990 | ||
bc797f4c | 991 | void wxWindowX11::DoClientToScreen(int *x, int *y) const |
83df96d6 | 992 | { |
bc797f4c JS |
993 | Display *display = wxGetDisplay(); |
994 | Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display)); | |
995 | Window thisWindow = (Window) GetClientWindow(); | |
83df96d6 JS |
996 | |
997 | Window childWindow; | |
998 | int xx = *x; | |
999 | int yy = *y; | |
1000 | XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow); | |
1001 | } | |
1002 | ||
1003 | ||
1004 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
bc797f4c | 1005 | void wxWindowX11::DoGetClientSize(int *x, int *y) const |
83df96d6 | 1006 | { |
bc797f4c JS |
1007 | // TODO |
1008 | #if 0 | |
83df96d6 JS |
1009 | Widget widget = (Widget) GetClientWidget(); |
1010 | Dimension xx, yy; | |
1011 | XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL); | |
1012 | if(x) *x = xx; if(y) *y = yy; | |
bc797f4c | 1013 | #endif |
83df96d6 JS |
1014 | } |
1015 | ||
bc797f4c | 1016 | void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
83df96d6 | 1017 | { |
bc797f4c JS |
1018 | // TODO |
1019 | #if 0 | |
83df96d6 JS |
1020 | // A bit of optimization to help sort out the flickers. |
1021 | int oldX, oldY, oldW, oldH; | |
1022 | GetSize(& oldW, & oldH); | |
1023 | GetPosition(& oldX, & oldY); | |
1024 | ||
1025 | if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
1026 | { | |
1027 | if ( x == -1 ) | |
1028 | x = oldX; | |
1029 | if ( y == -1 ) | |
1030 | y = oldY; | |
1031 | } | |
1032 | ||
1033 | if ( width == -1 ) | |
1034 | width = oldW; | |
1035 | if ( height == -1 ) | |
1036 | height = oldH; | |
1037 | ||
1038 | bool nothingChanged = (x == oldX) && (y == oldY) && | |
1039 | (width == oldW) && (height == oldH); | |
1040 | ||
1041 | if (!wxNoOptimize::CanOptimize()) | |
1042 | { | |
1043 | nothingChanged = FALSE; | |
1044 | } | |
1045 | ||
1046 | if ( !nothingChanged ) | |
1047 | { | |
1048 | if (m_drawingArea) | |
1049 | { | |
1050 | CanvasSetSize(x, y, width, height, sizeFlags); | |
1051 | return; | |
1052 | } | |
1053 | ||
1054 | Widget widget = (Widget) GetTopWidget(); | |
1055 | if (!widget) | |
1056 | return; | |
1057 | ||
1058 | bool managed = XtIsManaged( widget ); | |
1059 | if (managed) | |
1060 | XtUnmanageChild(widget); | |
1061 | ||
1062 | int xx = x; | |
1063 | int yy = y; | |
1064 | AdjustForParentClientOrigin(xx, yy, sizeFlags); | |
1065 | ||
1066 | DoMoveWindow(xx, yy, width, height); | |
1067 | ||
1068 | if (managed) | |
1069 | XtManageChild(widget); | |
1070 | ||
83df96d6 | 1071 | } |
bc797f4c | 1072 | #endif |
83df96d6 JS |
1073 | } |
1074 | ||
bc797f4c | 1075 | void wxWindowX11::DoSetClientSize(int width, int height) |
83df96d6 | 1076 | { |
bc797f4c JS |
1077 | // TODO |
1078 | #if 0 | |
83df96d6 JS |
1079 | if (m_drawingArea) |
1080 | { | |
1081 | CanvasSetClientSize(width, height); | |
1082 | return; | |
1083 | } | |
1084 | ||
1085 | Widget widget = (Widget) GetTopWidget(); | |
1086 | ||
1087 | if (width > -1) | |
1088 | XtVaSetValues(widget, XmNwidth, width, NULL); | |
1089 | if (height > -1) | |
1090 | XtVaSetValues(widget, XmNheight, height, NULL); | |
1091 | ||
1092 | wxSizeEvent sizeEvent(wxSize(width, height), GetId()); | |
1093 | sizeEvent.SetEventObject(this); | |
1094 | ||
1095 | GetEventHandler()->ProcessEvent(sizeEvent); | |
bc797f4c | 1096 | #endif |
83df96d6 JS |
1097 | } |
1098 | ||
1099 | // For implementation purposes - sometimes decorations make the client area | |
1100 | // smaller | |
bc797f4c | 1101 | wxPoint wxWindowX11::GetClientAreaOrigin() const |
83df96d6 JS |
1102 | { |
1103 | return wxPoint(0, 0); | |
1104 | } | |
1105 | ||
1106 | // Makes an adjustment to the window position (for example, a frame that has | |
1107 | // a toolbar that it manages itself). | |
bc797f4c | 1108 | void wxWindowX11::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) |
83df96d6 JS |
1109 | { |
1110 | if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) | |
1111 | { | |
1112 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
1113 | x += pt.x; y += pt.y; | |
1114 | } | |
1115 | } | |
1116 | ||
bc797f4c | 1117 | void wxWindowX11::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH) |
83df96d6 | 1118 | { |
bc797f4c JS |
1119 | // TODO |
1120 | #if 0 | |
83df96d6 JS |
1121 | m_minWidth = minW; |
1122 | m_minHeight = minH; | |
1123 | m_maxWidth = maxW; | |
1124 | m_maxHeight = maxH; | |
1125 | ||
1126 | wxFrame *frame = wxDynamicCast(this, wxFrame); | |
1127 | if ( !frame ) | |
1128 | { | |
1129 | // TODO what about dialogs? | |
1130 | return; | |
1131 | } | |
1132 | ||
1133 | Widget widget = (Widget) frame->GetShellWidget(); | |
1134 | ||
1135 | if (minW > -1) | |
1136 | XtVaSetValues(widget, XmNminWidth, minW, NULL); | |
1137 | if (minH > -1) | |
1138 | XtVaSetValues(widget, XmNminHeight, minH, NULL); | |
1139 | if (maxW > -1) | |
1140 | XtVaSetValues(widget, XmNmaxWidth, maxW, NULL); | |
1141 | if (maxH > -1) | |
1142 | XtVaSetValues(widget, XmNmaxHeight, maxH, NULL); | |
1143 | if (incW > -1) | |
1144 | XtVaSetValues(widget, XmNwidthInc, incW, NULL); | |
1145 | if (incH > -1) | |
1146 | XtVaSetValues(widget, XmNheightInc, incH, NULL); | |
bc797f4c | 1147 | #endif |
83df96d6 JS |
1148 | } |
1149 | ||
bc797f4c | 1150 | void wxWindowX11::DoMoveWindow(int x, int y, int width, int height) |
83df96d6 | 1151 | { |
bc797f4c JS |
1152 | // TODO |
1153 | #if 0 | |
83df96d6 JS |
1154 | XtVaSetValues((Widget)GetTopWidget(), |
1155 | XmNx, x, | |
1156 | XmNy, y, | |
1157 | XmNwidth, width, | |
1158 | XmNheight, height, | |
1159 | NULL); | |
bc797f4c | 1160 | #endif |
83df96d6 JS |
1161 | } |
1162 | ||
1163 | // --------------------------------------------------------------------------- | |
1164 | // text metrics | |
1165 | // --------------------------------------------------------------------------- | |
1166 | ||
bc797f4c | 1167 | int wxWindowX11::GetCharHeight() const |
83df96d6 JS |
1168 | { |
1169 | wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" ); | |
1170 | ||
1171 | WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay()); | |
1172 | ||
1173 | int direction, ascent, descent; | |
1174 | XCharStruct overall; | |
1175 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
1176 | &descent, &overall); | |
1177 | ||
1178 | // return (overall.ascent + overall.descent); | |
1179 | return (ascent + descent); | |
1180 | } | |
1181 | ||
bc797f4c | 1182 | int wxWindowX11::GetCharWidth() const |
83df96d6 JS |
1183 | { |
1184 | wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" ); | |
1185 | ||
1186 | WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay()); | |
1187 | ||
1188 | int direction, ascent, descent; | |
1189 | XCharStruct overall; | |
1190 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
1191 | &descent, &overall); | |
1192 | ||
1193 | return overall.width; | |
1194 | } | |
1195 | ||
bc797f4c | 1196 | void wxWindowX11::GetTextExtent(const wxString& string, |
83df96d6 JS |
1197 | int *x, int *y, |
1198 | int *descent, int *externalLeading, | |
1199 | const wxFont *theFont) const | |
1200 | { | |
1201 | wxFont *fontToUse = (wxFont *)theFont; | |
1202 | if (!fontToUse) | |
1203 | fontToUse = (wxFont *) & m_font; | |
1204 | ||
1205 | wxCHECK_RET( fontToUse->Ok(), "valid window font needed" ); | |
1206 | ||
1207 | WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay()); | |
1208 | ||
1209 | int direction, ascent, descent2; | |
1210 | XCharStruct overall; | |
1211 | int slen = string.Len(); | |
1212 | ||
1213 | #if 0 | |
1214 | if (use16) | |
1215 | XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction, | |
1216 | &ascent, &descent2, &overall); | |
1217 | #endif | |
1218 | ||
1219 | XTextExtents((XFontStruct*) pFontStruct, string, slen, | |
1220 | &direction, &ascent, &descent2, &overall); | |
1221 | ||
1222 | if ( x ) | |
1223 | *x = (overall.width); | |
1224 | if ( y ) | |
1225 | *y = (ascent + descent2); | |
1226 | if (descent) | |
1227 | *descent = descent2; | |
1228 | if (externalLeading) | |
1229 | *externalLeading = 0; | |
1230 | ||
1231 | } | |
1232 | ||
1233 | // ---------------------------------------------------------------------------- | |
1234 | // painting | |
1235 | // ---------------------------------------------------------------------------- | |
1236 | ||
bc797f4c | 1237 | void wxWindowX11::Refresh(bool eraseBack, const wxRect *rect) |
83df96d6 JS |
1238 | { |
1239 | m_needsRefresh = TRUE; | |
bc797f4c JS |
1240 | Display *display = wxGetDisplay(); |
1241 | Window thisWindow = (Widget) GetMainWindow(); | |
83df96d6 JS |
1242 | |
1243 | XExposeEvent dummyEvent; | |
1244 | int width, height; | |
1245 | GetSize(&width, &height); | |
1246 | ||
1247 | dummyEvent.type = Expose; | |
1248 | dummyEvent.display = display; | |
1249 | dummyEvent.send_event = True; | |
1250 | dummyEvent.window = thisWindow; | |
1251 | if (rect) | |
1252 | { | |
1253 | dummyEvent.x = rect->x; | |
1254 | dummyEvent.y = rect->y; | |
1255 | dummyEvent.width = rect->width; | |
1256 | dummyEvent.height = rect->height; | |
1257 | } | |
1258 | else | |
1259 | { | |
1260 | dummyEvent.x = 0; | |
1261 | dummyEvent.y = 0; | |
1262 | dummyEvent.width = width; | |
1263 | dummyEvent.height = height; | |
1264 | } | |
1265 | dummyEvent.count = 0; | |
1266 | ||
1267 | if (eraseBack) | |
1268 | { | |
1269 | wxClientDC dc(this); | |
1270 | wxBrush backgroundBrush(GetBackgroundColour(), wxSOLID); | |
1271 | dc.SetBackground(backgroundBrush); | |
1272 | if (rect) | |
1273 | dc.Clear(*rect); | |
1274 | else | |
1275 | dc.Clear(); | |
1276 | } | |
1277 | ||
1278 | XSendEvent(display, thisWindow, False, ExposureMask, (XEvent *)&dummyEvent); | |
1279 | } | |
1280 | ||
bc797f4c | 1281 | void wxWindowX11::Clear() |
83df96d6 JS |
1282 | { |
1283 | wxClientDC dc(this); | |
1284 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1285 | dc.SetBackground(brush); | |
1286 | dc.Clear(); | |
1287 | } | |
1288 | ||
bc797f4c | 1289 | void wxWindowX11::ClearUpdateRects() |
83df96d6 JS |
1290 | { |
1291 | wxRectList::Node* node = m_updateRects.GetFirst(); | |
1292 | while (node) | |
1293 | { | |
1294 | wxRect* rect = node->GetData(); | |
1295 | delete rect; | |
1296 | node = node->GetNext(); | |
1297 | } | |
1298 | ||
1299 | m_updateRects.Clear(); | |
1300 | } | |
1301 | ||
bc797f4c | 1302 | void wxWindowX11::DoPaint() |
83df96d6 | 1303 | { |
bc797f4c JS |
1304 | // Set an erase event first |
1305 | wxEraseEvent eraseEvent(GetId()); | |
1306 | eraseEvent.SetEventObject(this); | |
1307 | GetEventHandler()->ProcessEvent(eraseEvent); | |
1308 | ||
1309 | wxPaintEvent event(GetId()); | |
1310 | event.SetEventObject(this); | |
1311 | GetEventHandler()->ProcessEvent(event); | |
1312 | ||
1313 | m_needsRefresh = FALSE; | |
83df96d6 JS |
1314 | } |
1315 | ||
1316 | // ---------------------------------------------------------------------------- | |
1317 | // event handlers | |
1318 | // ---------------------------------------------------------------------------- | |
1319 | ||
1320 | // Responds to colour changes: passes event on to children. | |
bc797f4c | 1321 | void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event) |
83df96d6 JS |
1322 | { |
1323 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1324 | while ( node ) | |
1325 | { | |
1326 | // Only propagate to non-top-level windows | |
1327 | wxWindow *win = node->GetData(); | |
1328 | if ( win->GetParent() ) | |
1329 | { | |
1330 | wxSysColourChangedEvent event2; | |
1331 | event.m_eventObject = win; | |
1332 | win->GetEventHandler()->ProcessEvent(event2); | |
1333 | } | |
1334 | ||
1335 | node = node->GetNext(); | |
1336 | } | |
1337 | } | |
1338 | ||
bc797f4c | 1339 | void wxWindowX11::OnIdle(wxIdleEvent& WXUNUSED(event)) |
83df96d6 JS |
1340 | { |
1341 | // This calls the UI-update mechanism (querying windows for | |
1342 | // menu/toolbar/control state information) | |
1343 | UpdateWindowUI(); | |
1344 | } | |
1345 | ||
1346 | // ---------------------------------------------------------------------------- | |
1347 | // accelerators | |
1348 | // ---------------------------------------------------------------------------- | |
1349 | ||
bc797f4c | 1350 | bool wxWindowX11::ProcessAccelerator(wxKeyEvent& event) |
83df96d6 JS |
1351 | { |
1352 | if (!m_acceleratorTable.Ok()) | |
1353 | return FALSE; | |
1354 | ||
1355 | int count = m_acceleratorTable.GetCount(); | |
1356 | wxAcceleratorEntry* entries = m_acceleratorTable.GetEntries(); | |
1357 | int i; | |
1358 | for (i = 0; i < count; i++) | |
1359 | { | |
1360 | wxAcceleratorEntry* entry = & (entries[i]); | |
1361 | if (entry->MatchesEvent(event)) | |
1362 | { | |
1363 | // Bingo, we have a match. Now find a control that matches the | |
1364 | // entry command id. | |
1365 | ||
1366 | // Need to go up to the top of the window hierarchy, since it might | |
1367 | // be e.g. a menu item | |
1368 | wxWindow* parent = this; | |
1369 | while ( parent && !parent->IsTopLevel() ) | |
1370 | parent = parent->GetParent(); | |
1371 | ||
1372 | if (!parent) | |
1373 | return FALSE; | |
1374 | ||
1375 | wxFrame* frame = wxDynamicCast(parent, wxFrame); | |
1376 | if ( frame ) | |
1377 | { | |
1378 | // Try for a menu command | |
1379 | if (frame->GetMenuBar()) | |
1380 | { | |
1381 | wxMenuItem* item = frame->GetMenuBar()->FindItem(entry->GetCommand()); | |
1382 | if (item) | |
1383 | { | |
1384 | wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, entry->GetCommand()); | |
1385 | commandEvent.SetEventObject(frame); | |
1386 | ||
1387 | // If ProcessEvent returns TRUE (it was handled), then | |
1388 | // the calling code will skip the event handling. | |
1389 | return frame->GetEventHandler()->ProcessEvent(commandEvent); | |
1390 | } | |
1391 | } | |
1392 | } | |
1393 | ||
1394 | // Find a child matching the command id | |
1395 | wxWindow* child = parent->FindWindow(entry->GetCommand()); | |
1396 | ||
1397 | // No such child | |
1398 | if (!child) | |
1399 | return FALSE; | |
1400 | ||
1401 | // Now we process those kinds of windows that we can. | |
1402 | // For now, only buttons. | |
1403 | if ( wxDynamicCast(child, wxButton) ) | |
1404 | { | |
1405 | wxCommandEvent commandEvent (wxEVT_COMMAND_BUTTON_CLICKED, child->GetId()); | |
1406 | commandEvent.SetEventObject(child); | |
1407 | return child->GetEventHandler()->ProcessEvent(commandEvent); | |
1408 | } | |
1409 | ||
1410 | return FALSE; | |
1411 | } // matches event | |
1412 | }// for | |
1413 | ||
1414 | // We didn't match the key event against an accelerator. | |
1415 | return FALSE; | |
1416 | } | |
1417 | ||
1418 | // ============================================================================ | |
bc797f4c | 1419 | // X11-specific stuff from here on |
83df96d6 JS |
1420 | // ============================================================================ |
1421 | ||
1422 | // ---------------------------------------------------------------------------- | |
1423 | // function which maintain the global hash table mapping Widgets to wxWindows | |
1424 | // ---------------------------------------------------------------------------- | |
1425 | ||
bc797f4c | 1426 | bool wxAddWindowToTable(Window w, wxWindow *win) |
83df96d6 JS |
1427 | { |
1428 | wxWindow *oldItem = NULL; | |
1429 | if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w))) | |
1430 | { | |
1431 | wxLogDebug("Widget table clash: new widget is %ld, %s", | |
1432 | (long)w, win->GetClassInfo()->GetClassName()); | |
1433 | return FALSE; | |
1434 | } | |
1435 | ||
1436 | wxWidgetHashTable->Put((long) w, win); | |
1437 | ||
bc797f4c | 1438 | wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)", |
83df96d6 JS |
1439 | w, win, win->GetClassInfo()->GetClassName()); |
1440 | ||
1441 | return TRUE; | |
1442 | } | |
1443 | ||
bc797f4c | 1444 | wxWindow *wxGetWindowFromTable(Window w) |
83df96d6 JS |
1445 | { |
1446 | return (wxWindow *)wxWidgetHashTable->Get((long) w); | |
1447 | } | |
1448 | ||
bc797f4c | 1449 | void wxDeleteWindowFromTable(Window w) |
83df96d6 JS |
1450 | { |
1451 | wxWidgetHashTable->Delete((long)w); | |
1452 | } | |
1453 | ||
1454 | // ---------------------------------------------------------------------------- | |
1455 | // add/remove window from the table | |
1456 | // ---------------------------------------------------------------------------- | |
1457 | ||
1458 | // Add to hash table, add event handler | |
bc797f4c JS |
1459 | bool wxWindowX11::AttachWidget (wxWindow* WXUNUSED(parent), WXWindow mainWidget, |
1460 | int x, int y, int width, int height) | |
83df96d6 | 1461 | { |
bc797f4c JS |
1462 | wxAddWindowToTable((Window ) mainWidget, this); |
1463 | ||
1464 | // TODO | |
1465 | #if 0 | |
83df96d6 JS |
1466 | if (CanAddEventHandler()) |
1467 | { | |
1468 | XtAddEventHandler((Widget) mainWidget, | |
1469 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask, | |
1470 | False, | |
1471 | wxPanelItemEventHandler, | |
1472 | (XtPointer) this); | |
1473 | } | |
1474 | ||
1475 | if (!formWidget) | |
1476 | { | |
1477 | XtTranslations ptr; | |
1478 | XtOverrideTranslations ((Widget) mainWidget, | |
1479 | ptr = XtParseTranslationTable ("<Configure>: resize()")); | |
1480 | XtFree ((char *) ptr); | |
1481 | } | |
1482 | ||
1483 | // Some widgets have a parent form widget, e.g. wxRadioBox | |
1484 | if (formWidget) | |
1485 | { | |
1486 | if (!wxAddWindowToTable((Widget) formWidget, this)) | |
1487 | return FALSE; | |
1488 | ||
1489 | XtTranslations ptr; | |
1490 | XtOverrideTranslations ((Widget) formWidget, | |
1491 | ptr = XtParseTranslationTable ("<Configure>: resize()")); | |
1492 | XtFree ((char *) ptr); | |
1493 | } | |
bc797f4c | 1494 | #endif |
83df96d6 JS |
1495 | if (x == -1) |
1496 | x = 0; | |
1497 | if (y == -1) | |
1498 | y = 0; | |
bc797f4c | 1499 | |
83df96d6 JS |
1500 | SetSize (x, y, width, height); |
1501 | ||
1502 | return TRUE; | |
1503 | } | |
1504 | ||
1505 | // Remove event handler, remove from hash table | |
bc797f4c | 1506 | bool wxWindowX11::DetachWidget(WXWindow widget) |
83df96d6 | 1507 | { |
bc797f4c JS |
1508 | // TODO |
1509 | #if 0 | |
83df96d6 JS |
1510 | if (CanAddEventHandler()) |
1511 | { | |
1512 | XtRemoveEventHandler((Widget) widget, | |
1513 | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, // | KeyPressMask, | |
1514 | False, | |
1515 | wxPanelItemEventHandler, | |
1516 | (XtPointer)this); | |
1517 | } | |
bc797f4c | 1518 | #endif |
83df96d6 | 1519 | |
bc797f4c | 1520 | wxDeleteWindowFromTable((Window) widget); |
83df96d6 JS |
1521 | return TRUE; |
1522 | } | |
1523 | ||
1524 | // ---------------------------------------------------------------------------- | |
bc797f4c | 1525 | // X11-specific accessors |
83df96d6 JS |
1526 | // ---------------------------------------------------------------------------- |
1527 | ||
1528 | // Get the underlying X window | |
bc797f4c | 1529 | WXWindow wxWindowX11::GetXWindow() const |
83df96d6 | 1530 | { |
bc797f4c | 1531 | return GetMainWindow(); |
83df96d6 JS |
1532 | } |
1533 | ||
1534 | // Get the underlying X display | |
bc797f4c | 1535 | WXDisplay *wxWindowX11::GetXDisplay() const |
83df96d6 | 1536 | { |
bc797f4c | 1537 | return wxGetDisplay(); |
83df96d6 JS |
1538 | } |
1539 | ||
bc797f4c | 1540 | WXWindow wxWindowX11::GetMainWindow() const |
83df96d6 JS |
1541 | { |
1542 | if (m_drawingArea) | |
1543 | return m_drawingArea; | |
1544 | else | |
1545 | return m_mainWidget; | |
1546 | } | |
1547 | ||
bc797f4c | 1548 | WXWindow wxWindowX11::GetClientWidget() const |
83df96d6 | 1549 | { |
bc797f4c | 1550 | if (m_drawingArea != (WXWindow) 0) |
83df96d6 JS |
1551 | return m_drawingArea; |
1552 | else | |
bc797f4c | 1553 | return GetMainWindow(); |
83df96d6 JS |
1554 | } |
1555 | ||
bc797f4c | 1556 | WXWindow wxWindowX11::GetTopWindow() const |
83df96d6 | 1557 | { |
bc797f4c | 1558 | return GetMainWindow(); |
83df96d6 JS |
1559 | } |
1560 | ||
bc797f4c | 1561 | WXWindow wxWindowX11::GetLabelWindow() const |
83df96d6 | 1562 | { |
bc797f4c | 1563 | return GetMainWindow(); |
83df96d6 JS |
1564 | } |
1565 | ||
1566 | // ---------------------------------------------------------------------------- | |
bc797f4c | 1567 | // callbacks |
83df96d6 JS |
1568 | // ---------------------------------------------------------------------------- |
1569 | ||
1b0fb34b | 1570 | // TODO: implement wxWindow scrollbar, presumably using wxScrollBar |
83df96d6 | 1571 | #if 0 |
83df96d6 JS |
1572 | static void wxScrollBarCallback(Widget scrollbar, |
1573 | XtPointer clientData, | |
1574 | XmScrollBarCallbackStruct *cbs) | |
1575 | { | |
1576 | wxWindow *win = wxGetWindowFromTable(scrollbar); | |
1577 | int orientation = (int) clientData; | |
1578 | ||
1579 | wxEventType eventType = wxEVT_NULL; | |
1580 | switch (cbs->reason) | |
1581 | { | |
1582 | case XmCR_INCREMENT: | |
1583 | { | |
1584 | eventType = wxEVT_SCROLLWIN_LINEDOWN; | |
1585 | break; | |
1586 | } | |
1587 | case XmCR_DECREMENT: | |
1588 | { | |
1589 | eventType = wxEVT_SCROLLWIN_LINEUP; | |
1590 | break; | |
1591 | } | |
1592 | case XmCR_DRAG: | |
1593 | { | |
1594 | eventType = wxEVT_SCROLLWIN_THUMBTRACK; | |
1595 | break; | |
1596 | } | |
1597 | case XmCR_VALUE_CHANGED: | |
1598 | { | |
1599 | eventType = wxEVT_SCROLLWIN_THUMBRELEASE; | |
1600 | break; | |
1601 | } | |
1602 | case XmCR_PAGE_INCREMENT: | |
1603 | { | |
1604 | eventType = wxEVT_SCROLLWIN_PAGEDOWN; | |
1605 | break; | |
1606 | } | |
1607 | case XmCR_PAGE_DECREMENT: | |
1608 | { | |
1609 | eventType = wxEVT_SCROLLWIN_PAGEUP; | |
1610 | break; | |
1611 | } | |
1612 | case XmCR_TO_TOP: | |
1613 | { | |
1614 | eventType = wxEVT_SCROLLWIN_TOP; | |
1615 | break; | |
1616 | } | |
1617 | case XmCR_TO_BOTTOM: | |
1618 | { | |
1619 | eventType = wxEVT_SCROLLWIN_BOTTOM; | |
1620 | break; | |
1621 | } | |
1622 | default: | |
1623 | { | |
1624 | // Should never get here | |
1625 | wxFAIL_MSG("Unknown scroll event."); | |
1626 | break; | |
1627 | } | |
1628 | } | |
1629 | ||
1630 | wxScrollWinEvent event(eventType, | |
1631 | cbs->value, | |
1632 | ((orientation == XmHORIZONTAL) ? | |
1633 | wxHORIZONTAL : wxVERTICAL)); | |
1634 | event.SetEventObject( win ); | |
1635 | win->GetEventHandler()->ProcessEvent(event); | |
1636 | } | |
bc797f4c | 1637 | #endif |
1b0fb34b | 1638 | |
bc797f4c | 1639 | |
83df96d6 JS |
1640 | // ---------------------------------------------------------------------------- |
1641 | // CanvaseXXXSize() functions | |
1642 | // ---------------------------------------------------------------------------- | |
1643 | ||
1644 | // SetSize, but as per old wxCanvas (with drawing widget etc.) | |
bc797f4c | 1645 | void wxWindowX11::CanvasSetSize (int x, int y, int w, int h, int sizeFlags) |
83df96d6 | 1646 | { |
bc797f4c JS |
1647 | // TODO |
1648 | #if 0 | |
83df96d6 JS |
1649 | // A bit of optimization to help sort out the flickers. |
1650 | int oldX, oldY, oldW, oldH; | |
1651 | GetSize(& oldW, & oldH); | |
1652 | GetPosition(& oldX, & oldY); | |
1653 | ||
1654 | bool useOldPos = FALSE; | |
1655 | bool useOldSize = FALSE; | |
1656 | ||
1657 | if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0)) | |
1658 | useOldPos = TRUE; | |
1659 | else if (x == oldX && y == oldY) | |
1660 | useOldPos = TRUE; | |
1661 | ||
1662 | if ((w == -1) && (h == -1)) | |
1663 | useOldSize = TRUE; | |
1664 | else if (w == oldW && h == oldH) | |
1665 | useOldSize = TRUE; | |
1666 | ||
1667 | if (!wxNoOptimize::CanOptimize()) | |
1668 | { | |
1669 | useOldSize = FALSE; useOldPos = FALSE; | |
1670 | } | |
1671 | ||
1672 | if (useOldPos && useOldSize) | |
1673 | return; | |
1674 | ||
1675 | Widget drawingArea = (Widget) m_drawingArea; | |
1676 | bool managed = XtIsManaged(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); | |
1677 | ||
1678 | if (managed) | |
1679 | XtUnmanageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); | |
1680 | XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL); | |
1681 | ||
1682 | int xx = x; int yy = y; | |
1683 | AdjustForParentClientOrigin(xx, yy, sizeFlags); | |
1684 | ||
1685 | if (!useOldPos) | |
1686 | { | |
1687 | if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
1688 | { | |
1689 | XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, | |
1690 | XmNx, xx, NULL); | |
1691 | } | |
1692 | ||
1693 | if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
1694 | { | |
1695 | XtVaSetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, | |
1696 | XmNy, yy, NULL); | |
1697 | } | |
1698 | } | |
1699 | ||
1700 | if (!useOldSize) | |
1701 | { | |
1702 | ||
1703 | if (w > -1) | |
1704 | { | |
1705 | if (m_borderWidget) | |
1706 | { | |
1707 | XtVaSetValues ((Widget) m_borderWidget, XmNwidth, w, NULL); | |
1708 | short thick, margin; | |
1709 | XtVaGetValues ((Widget) m_borderWidget, | |
1710 | XmNshadowThickness, &thick, | |
1711 | XmNmarginWidth, &margin, | |
1712 | NULL); | |
1713 | w -= 2 * (thick + margin); | |
1714 | } | |
1715 | ||
1716 | XtVaSetValues ((Widget) m_scrolledWindow, XmNwidth, w, NULL); | |
1717 | ||
1718 | Dimension spacing; | |
1719 | Widget sbar; | |
1720 | XtVaGetValues ((Widget) m_scrolledWindow, | |
1721 | XmNspacing, &spacing, | |
1722 | XmNverticalScrollBar, &sbar, | |
1723 | NULL); | |
1724 | Dimension wsbar; | |
1725 | if (sbar) | |
1726 | XtVaGetValues (sbar, XmNwidth, &wsbar, NULL); | |
1727 | else | |
1728 | wsbar = 0; | |
1729 | ||
1730 | w -= (spacing + wsbar); | |
1731 | ||
1732 | #if 0 | |
1733 | XtVaSetValues(drawingArea, XmNwidth, w, NULL); | |
1734 | #endif // 0 | |
1735 | } | |
1736 | if (h > -1) | |
1737 | { | |
1738 | if (m_borderWidget) | |
1739 | { | |
1740 | XtVaSetValues ((Widget) m_borderWidget, XmNheight, h, NULL); | |
1741 | short thick, margin; | |
1742 | XtVaGetValues ((Widget) m_borderWidget, | |
1743 | XmNshadowThickness, &thick, | |
1744 | XmNmarginHeight, &margin, | |
1745 | NULL); | |
1746 | h -= 2 * (thick + margin); | |
1747 | } | |
1748 | ||
1749 | XtVaSetValues ((Widget) m_scrolledWindow, XmNheight, h, NULL); | |
1750 | ||
1751 | Dimension spacing; | |
1752 | Widget sbar; | |
1753 | XtVaGetValues ((Widget) m_scrolledWindow, | |
1754 | XmNspacing, &spacing, | |
1755 | XmNhorizontalScrollBar, &sbar, | |
1756 | NULL); | |
1757 | Dimension wsbar; | |
1758 | if (sbar) | |
1759 | XtVaGetValues (sbar, XmNheight, &wsbar, NULL); | |
1760 | else | |
1761 | wsbar = 0; | |
1762 | ||
1763 | h -= (spacing + wsbar); | |
1764 | ||
1765 | #if 0 | |
1766 | XtVaSetValues(drawingArea, XmNheight, h, NULL); | |
1767 | #endif // 0 | |
1768 | } | |
1769 | } | |
1770 | ||
1771 | if (managed) | |
1772 | XtManageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow); | |
1773 | XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL); | |
bc797f4c JS |
1774 | #endif |
1775 | // 0 | |
83df96d6 JS |
1776 | } |
1777 | ||
bc797f4c | 1778 | void wxWindowX11::CanvasSetClientSize (int w, int h) |
83df96d6 | 1779 | { |
bc797f4c JS |
1780 | // TODO |
1781 | #if 0 | |
83df96d6 JS |
1782 | Widget drawingArea = (Widget) m_drawingArea; |
1783 | ||
1784 | XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL); | |
1785 | ||
1786 | if (w > -1) | |
1787 | XtVaSetValues(drawingArea, XmNwidth, w, NULL); | |
1788 | if (h > -1) | |
1789 | XtVaSetValues(drawingArea, XmNheight, h, NULL); | |
1790 | ||
83df96d6 | 1791 | XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL); |
83df96d6 JS |
1792 | #endif // 0 |
1793 | } | |
1794 | ||
bc797f4c | 1795 | void wxWindowX11::CanvasGetClientSize (int *w, int *h) const |
83df96d6 | 1796 | { |
bc797f4c JS |
1797 | // TODO |
1798 | #if 0 | |
83df96d6 JS |
1799 | // Must return the same thing that was set via SetClientSize |
1800 | Dimension xx, yy; | |
1801 | XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL); | |
1802 | *w = xx; | |
1803 | *h = yy; | |
bc797f4c | 1804 | #endif |
83df96d6 JS |
1805 | } |
1806 | ||
bc797f4c | 1807 | void wxWindowX11::CanvasGetSize (int *w, int *h) const |
83df96d6 | 1808 | { |
bc797f4c JS |
1809 | // TODO |
1810 | #if 0 | |
83df96d6 JS |
1811 | Dimension xx, yy; |
1812 | if ((Widget) m_borderWidget) | |
1813 | XtVaGetValues ((Widget) m_borderWidget, XmNwidth, &xx, XmNheight, &yy, NULL); | |
1814 | else if ((Widget) m_scrolledWindow) | |
1815 | XtVaGetValues ((Widget) m_scrolledWindow, XmNwidth, &xx, XmNheight, &yy, NULL); | |
1816 | else | |
1817 | XtVaGetValues ((Widget) m_drawingArea, XmNwidth, &xx, XmNheight, &yy, NULL); | |
1818 | ||
1819 | *w = xx; | |
1820 | *h = yy; | |
bc797f4c | 1821 | #endif |
83df96d6 JS |
1822 | } |
1823 | ||
bc797f4c | 1824 | void wxWindowX11::CanvasGetPosition (int *x, int *y) const |
83df96d6 | 1825 | { |
bc797f4c JS |
1826 | // TODO |
1827 | #if 0 | |
83df96d6 JS |
1828 | Position xx, yy; |
1829 | XtVaGetValues (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow, XmNx, &xx, XmNy, &yy, NULL); | |
1830 | ||
1831 | // We may be faking the client origin. | |
1832 | // So a window that's really at (0, 30) may appear | |
1833 | // (to wxWin apps) to be at (0, 0). | |
1834 | if (GetParent()) | |
1835 | { | |
1836 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
1837 | xx -= pt.x; | |
1838 | yy -= pt.y; | |
1839 | } | |
1840 | ||
1841 | *x = xx; | |
1842 | *y = yy; | |
bc797f4c | 1843 | #endif |
83df96d6 JS |
1844 | } |
1845 | ||
1846 | // ---------------------------------------------------------------------------- | |
1847 | // TranslateXXXEvent() functions | |
1848 | // ---------------------------------------------------------------------------- | |
1849 | ||
1b0fb34b | 1850 | bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Window window, XEvent *xevent) |
83df96d6 JS |
1851 | { |
1852 | switch (xevent->xany.type) | |
1853 | { | |
1b0fb34b JS |
1854 | case EnterNotify: |
1855 | case LeaveNotify: | |
83df96d6 JS |
1856 | case ButtonPress: |
1857 | case ButtonRelease: | |
1858 | case MotionNotify: | |
1859 | { | |
1860 | wxEventType eventType = wxEVT_NULL; | |
1861 | ||
1b0fb34b | 1862 | if (xevent->xany.type == EnterNotify) |
83df96d6 | 1863 | { |
1b0fb34b JS |
1864 | //if (local_event.xcrossing.mode!=NotifyNormal) |
1865 | // return ; // Ignore grab events | |
1866 | eventType = wxEVT_ENTER_WINDOW; | |
1867 | // canvas->GetEventHandler()->OnSetFocus(); | |
1868 | } | |
1869 | else if (xevent->xany.type == LeaveNotify) | |
1870 | { | |
1871 | //if (local_event.xcrossingr.mode!=NotifyNormal) | |
1872 | // return ; // Ignore grab events | |
1873 | eventType = wxEVT_LEAVE_WINDOW; | |
1874 | // canvas->GetEventHandler()->OnKillFocus(); | |
83df96d6 JS |
1875 | } |
1876 | else if (xevent->xany.type == MotionNotify) | |
1877 | { | |
1878 | eventType = wxEVT_MOTION; | |
1879 | } | |
1880 | else if (xevent->xany.type == ButtonPress) | |
1881 | { | |
1882 | wxevent.SetTimestamp(xevent->xbutton.time); | |
1883 | int button = 0; | |
1884 | if (xevent->xbutton.button == Button1) | |
1885 | { | |
1886 | eventType = wxEVT_LEFT_DOWN; | |
1887 | win->SetButton1(TRUE); | |
1888 | button = 1; | |
1889 | } | |
1890 | else if (xevent->xbutton.button == Button2) | |
1891 | { | |
1892 | eventType = wxEVT_MIDDLE_DOWN; | |
1893 | win->SetButton2(TRUE); | |
1894 | button = 2; | |
1895 | } | |
1896 | else if (xevent->xbutton.button == Button3) | |
1897 | { | |
1898 | eventType = wxEVT_RIGHT_DOWN; | |
1899 | win->SetButton3(TRUE); | |
1900 | button = 3; | |
1901 | } | |
1902 | ||
1903 | // check for a double click | |
1b0fb34b JS |
1904 | // TODO: where can we get this value from? |
1905 | //long dclickTime = XtGetMultiClickTime((Display*) wxGetDisplay()); | |
1906 | long dClickTime = 200; | |
83df96d6 JS |
1907 | long ts = wxevent.GetTimestamp(); |
1908 | ||
1909 | int buttonLast = win->GetLastClickedButton(); | |
1910 | long lastTS = win->GetLastClickTime(); | |
1911 | if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime ) | |
1912 | { | |
1913 | // I have a dclick | |
1914 | win->SetLastClick(0, ts); | |
1915 | if ( eventType == wxEVT_LEFT_DOWN ) | |
1916 | eventType = wxEVT_LEFT_DCLICK; | |
1917 | else if ( eventType == wxEVT_MIDDLE_DOWN ) | |
1918 | eventType = wxEVT_MIDDLE_DCLICK; | |
1919 | else if ( eventType == wxEVT_RIGHT_DOWN ) | |
1920 | eventType = wxEVT_RIGHT_DCLICK; | |
1921 | } | |
1922 | else | |
1923 | { | |
1924 | // not fast enough or different button | |
1925 | win->SetLastClick(button, ts); | |
1926 | } | |
1927 | } | |
1928 | else if (xevent->xany.type == ButtonRelease) | |
1929 | { | |
1930 | if (xevent->xbutton.button == Button1) | |
1931 | { | |
1932 | eventType = wxEVT_LEFT_UP; | |
1933 | win->SetButton1(FALSE); | |
1934 | } | |
1935 | else if (xevent->xbutton.button == Button2) | |
1936 | { | |
1937 | eventType = wxEVT_MIDDLE_UP; | |
1938 | win->SetButton2(FALSE); | |
1939 | } | |
1940 | else if (xevent->xbutton.button == Button3) | |
1941 | { | |
1942 | eventType = wxEVT_RIGHT_UP; | |
1943 | win->SetButton3(FALSE); | |
1944 | } | |
1945 | else return FALSE; | |
1946 | } | |
1947 | else | |
1948 | { | |
1949 | return FALSE; | |
1950 | } | |
1951 | ||
1952 | wxevent.SetEventType(eventType); | |
1953 | ||
1b0fb34b JS |
1954 | wxevent.m_x = xevent->xbutton.x; |
1955 | wxevent.m_y = xevent->xbutton.y; | |
83df96d6 JS |
1956 | |
1957 | wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN) | |
1958 | || (event_left_is_down (xevent) | |
1959 | && (eventType != wxEVT_LEFT_UP))); | |
1960 | wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN) | |
1961 | || (event_middle_is_down (xevent) | |
1962 | && (eventType != wxEVT_MIDDLE_UP))); | |
1963 | wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN) | |
1964 | || (event_right_is_down (xevent) | |
1965 | && (eventType != wxEVT_RIGHT_UP))); | |
1966 | ||
1967 | wxevent.m_shiftDown = xevent->xbutton.state & ShiftMask; | |
1968 | wxevent.m_controlDown = xevent->xbutton.state & ControlMask; | |
1969 | wxevent.m_altDown = xevent->xbutton.state & Mod3Mask; | |
1970 | wxevent.m_metaDown = xevent->xbutton.state & Mod1Mask; | |
1971 | ||
1972 | wxevent.SetId(win->GetId()); | |
1973 | wxevent.SetEventObject(win); | |
1974 | ||
1975 | return TRUE; | |
1976 | } | |
1977 | } | |
1978 | return FALSE; | |
1979 | } | |
1980 | ||
7eaac9f5 | 1981 | bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Window WXUNUSED(win), XEvent *xevent) |
83df96d6 JS |
1982 | { |
1983 | switch (xevent->xany.type) | |
1984 | { | |
1985 | case KeyPress: | |
1986 | case KeyRelease: | |
1987 | { | |
1988 | char buf[20]; | |
1989 | ||
1990 | KeySym keySym; | |
83df96d6 JS |
1991 | (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL); |
1992 | int id = wxCharCodeXToWX (keySym); | |
1993 | ||
1994 | if (xevent->xkey.state & ShiftMask) | |
1995 | wxevent.m_shiftDown = TRUE; | |
1996 | if (xevent->xkey.state & ControlMask) | |
1997 | wxevent.m_controlDown = TRUE; | |
1998 | if (xevent->xkey.state & Mod3Mask) | |
1999 | wxevent.m_altDown = TRUE; | |
2000 | if (xevent->xkey.state & Mod1Mask) | |
2001 | wxevent.m_metaDown = TRUE; | |
2002 | wxevent.SetEventObject(win); | |
2003 | wxevent.m_keyCode = id; | |
2004 | wxevent.SetTimestamp(xevent->xkey.time); | |
2005 | ||
2006 | wxevent.m_x = xevent->xbutton.x; | |
2007 | wxevent.m_y = xevent->xbutton.y; | |
2008 | ||
2009 | if (id > -1) | |
2010 | return TRUE; | |
2011 | else | |
2012 | return FALSE; | |
2013 | break; | |
2014 | } | |
2015 | default: | |
2016 | break; | |
2017 | } | |
2018 | return FALSE; | |
2019 | } | |
2020 | ||
2021 | // ---------------------------------------------------------------------------- | |
2022 | // Colour stuff | |
2023 | // ---------------------------------------------------------------------------- | |
2024 | ||
bc797f4c JS |
2025 | #if 0 |
2026 | ||
83df96d6 JS |
2027 | #define YAllocColor XAllocColor |
2028 | XColor g_itemColors[5]; | |
2029 | int wxComputeColours (Display *display, wxColour * back, wxColour * fore) | |
2030 | { | |
2031 | int result; | |
2032 | static XmColorProc colorProc; | |
2033 | ||
2034 | result = wxNO_COLORS; | |
2035 | ||
2036 | if (back) | |
2037 | { | |
2038 | g_itemColors[0].red = (((long) back->Red ()) << 8); | |
2039 | g_itemColors[0].green = (((long) back->Green ()) << 8); | |
2040 | g_itemColors[0].blue = (((long) back->Blue ()) << 8); | |
2041 | g_itemColors[0].flags = DoRed | DoGreen | DoBlue; | |
2042 | if (colorProc == (XmColorProc) NULL) | |
2043 | { | |
2044 | // Get a ptr to the actual function | |
2045 | colorProc = XmSetColorCalculation ((XmColorProc) NULL); | |
2046 | // And set it back to motif. | |
2047 | XmSetColorCalculation (colorProc); | |
2048 | } | |
2049 | (*colorProc) (&g_itemColors[wxBACK_INDEX], | |
2050 | &g_itemColors[wxFORE_INDEX], | |
2051 | &g_itemColors[wxSELE_INDEX], | |
2052 | &g_itemColors[wxTOPS_INDEX], | |
2053 | &g_itemColors[wxBOTS_INDEX]); | |
2054 | result = wxBACK_COLORS; | |
2055 | } | |
2056 | if (fore) | |
2057 | { | |
2058 | g_itemColors[wxFORE_INDEX].red = (((long) fore->Red ()) << 8); | |
2059 | g_itemColors[wxFORE_INDEX].green = (((long) fore->Green ()) << 8); | |
2060 | g_itemColors[wxFORE_INDEX].blue = (((long) fore->Blue ()) << 8); | |
2061 | g_itemColors[wxFORE_INDEX].flags = DoRed | DoGreen | DoBlue; | |
2062 | if (result == wxNO_COLORS) | |
2063 | result = wxFORE_COLORS; | |
2064 | } | |
2065 | ||
2066 | Display *dpy = display; | |
2067 | Colormap cmap = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) dpy); | |
2068 | ||
2069 | if (back) | |
2070 | { | |
2071 | /* 5 Colours to allocate */ | |
2072 | for (int i = 0; i < 5; i++) | |
2073 | if (!YAllocColor (dpy, cmap, &g_itemColors[i])) | |
2074 | result = wxNO_COLORS; | |
2075 | } | |
2076 | else if (fore) | |
2077 | { | |
2078 | /* Only 1 colour to allocate */ | |
2079 | if (!YAllocColor (dpy, cmap, &g_itemColors[wxFORE_INDEX])) | |
2080 | result = wxNO_COLORS; | |
2081 | } | |
2082 | ||
2083 | return (result); | |
2084 | ||
2085 | } | |
bc797f4c | 2086 | #endif |
83df96d6 JS |
2087 | |
2088 | // Changes the foreground and background colours to be derived from the current | |
2089 | // background colour. To change the foreground colour, you must call | |
2090 | // SetForegroundColour explicitly. | |
bc797f4c | 2091 | void wxWindowX11::ChangeBackgroundColour() |
83df96d6 | 2092 | { |
bc797f4c JS |
2093 | // TODO |
2094 | #if 0 | |
83df96d6 JS |
2095 | WXWidget mainWidget = GetMainWidget(); |
2096 | if ( mainWidget ) | |
2097 | DoChangeBackgroundColour(mainWidget, m_backgroundColour); | |
83df96d6 JS |
2098 | #endif |
2099 | } | |
2100 | ||
bc797f4c | 2101 | void wxWindowX11::ChangeForegroundColour() |
83df96d6 | 2102 | { |
bc797f4c JS |
2103 | // TODO |
2104 | #if 0 | |
83df96d6 JS |
2105 | WXWidget mainWidget = GetMainWidget(); |
2106 | if ( mainWidget ) | |
2107 | DoChangeForegroundColour(mainWidget, m_foregroundColour); | |
2108 | if ( m_scrolledWindow && mainWidget != m_scrolledWindow ) | |
2109 | DoChangeForegroundColour(m_scrolledWindow, m_foregroundColour); | |
bc797f4c | 2110 | #endif |
83df96d6 JS |
2111 | } |
2112 | ||
2113 | // Change a widget's foreground and background colours. | |
bc797f4c | 2114 | void wxWindowX11::DoChangeForegroundColour(WXWindow widget, wxColour& foregroundColour) |
83df96d6 | 2115 | { |
bc797f4c JS |
2116 | // TODO |
2117 | #if 0 | |
83df96d6 JS |
2118 | // When should we specify the foreground, if it's calculated |
2119 | // by wxComputeColours? | |
2120 | // Solution: say we start with the default (computed) foreground colour. | |
2121 | // If we call SetForegroundColour explicitly for a control or window, | |
2122 | // then the foreground is changed. | |
2123 | // Therefore SetBackgroundColour computes the foreground colour, and | |
2124 | // SetForegroundColour changes the foreground colour. The ordering is | |
2125 | // important. | |
2126 | ||
2127 | Widget w = (Widget)widget; | |
2128 | XtVaSetValues( | |
2129 | w, | |
2130 | XmNforeground, foregroundColour.AllocColour(XtDisplay(w)), | |
2131 | NULL | |
2132 | ); | |
bc797f4c | 2133 | #endif |
83df96d6 JS |
2134 | } |
2135 | ||
bc797f4c | 2136 | void wxWindowX11::DoChangeBackgroundColour(WXWindow widget, wxColour& backgroundColour, bool changeArmColour) |
83df96d6 | 2137 | { |
bc797f4c JS |
2138 | // TODO |
2139 | #if 0 | |
83df96d6 JS |
2140 | wxComputeColours (XtDisplay((Widget) widget), & backgroundColour, |
2141 | (wxColour*) NULL); | |
2142 | ||
2143 | XtVaSetValues ((Widget) widget, | |
2144 | XmNbackground, g_itemColors[wxBACK_INDEX].pixel, | |
2145 | XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel, | |
2146 | XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel, | |
2147 | XmNforeground, g_itemColors[wxFORE_INDEX].pixel, | |
2148 | NULL); | |
2149 | ||
2150 | if (changeArmColour) | |
2151 | XtVaSetValues ((Widget) widget, | |
2152 | XmNarmColor, g_itemColors[wxSELE_INDEX].pixel, | |
2153 | NULL); | |
bc797f4c | 2154 | #endif |
83df96d6 JS |
2155 | } |
2156 | ||
bc797f4c | 2157 | bool wxWindowX11::SetBackgroundColour(const wxColour& col) |
83df96d6 JS |
2158 | { |
2159 | if ( !wxWindowBase::SetBackgroundColour(col) ) | |
2160 | return FALSE; | |
2161 | ||
2162 | ChangeBackgroundColour(); | |
2163 | ||
2164 | return TRUE; | |
2165 | } | |
2166 | ||
bc797f4c | 2167 | bool wxWindowX11::SetForegroundColour(const wxColour& col) |
83df96d6 JS |
2168 | { |
2169 | if ( !wxWindowBase::SetForegroundColour(col) ) | |
2170 | return FALSE; | |
2171 | ||
2172 | ChangeForegroundColour(); | |
2173 | ||
2174 | return TRUE; | |
2175 | } | |
2176 | ||
bc797f4c | 2177 | void wxWindowX11::ChangeFont(bool keepOriginalSize) |
83df96d6 | 2178 | { |
bc797f4c JS |
2179 | // TODO |
2180 | #if 0 | |
83df96d6 JS |
2181 | // Note that this causes the widget to be resized back |
2182 | // to its original size! We therefore have to set the size | |
2183 | // back again. TODO: a better way in Motif? | |
2184 | Widget w = (Widget) GetLabelWidget(); // Usually the main widget | |
2185 | if (w && m_font.Ok()) | |
2186 | { | |
2187 | int width, height, width1, height1; | |
2188 | GetSize(& width, & height); | |
2189 | ||
2190 | // lesstif 0.87 hangs here | |
2191 | #ifndef LESSTIF_VERSION | |
2192 | XtVaSetValues (w, | |
2193 | XmNfontList, (XmFontList) m_font.GetFontList(1.0, XtDisplay(w)), | |
2194 | NULL); | |
2195 | #endif | |
2196 | ||
2197 | GetSize(& width1, & height1); | |
2198 | if (keepOriginalSize && (width != width1 || height != height1)) | |
2199 | { | |
2200 | SetSize(-1, -1, width, height); | |
2201 | } | |
2202 | } | |
bc797f4c | 2203 | #endif |
83df96d6 JS |
2204 | } |
2205 | ||
2206 | // ---------------------------------------------------------------------------- | |
2207 | // global functions | |
2208 | // ---------------------------------------------------------------------------- | |
2209 | ||
2210 | wxWindow *wxGetActiveWindow() | |
2211 | { | |
2212 | // TODO | |
2213 | wxFAIL_MSG("Not implemented"); | |
2214 | return NULL; | |
2215 | } | |
2216 | ||
2217 | /* static */ | |
2218 | wxWindow *wxWindowBase::GetCapture() | |
2219 | { | |
2220 | return (wxWindow *)g_captureWindow; | |
2221 | } | |
2222 | ||
2223 | ||
2224 | // Find the wxWindow at the current mouse position, returning the mouse | |
2225 | // position. | |
2226 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) | |
2227 | { | |
2228 | return wxFindWindowAtPoint(wxGetMousePosition()); | |
2229 | } | |
2230 | ||
2231 | // Get the current mouse position. | |
2232 | wxPoint wxGetMousePosition() | |
2233 | { | |
2234 | Display *display = (Display*) wxGetDisplay(); | |
2235 | Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display)); | |
2236 | Window rootReturn, childReturn; | |
2237 | int rootX, rootY, winX, winY; | |
2238 | unsigned int maskReturn; | |
2239 | ||
2240 | XQueryPointer (display, | |
2241 | rootWindow, | |
2242 | &rootReturn, | |
2243 | &childReturn, | |
2244 | &rootX, &rootY, &winX, &winY, &maskReturn); | |
2245 | return wxPoint(rootX, rootY); | |
2246 | } | |
2247 | ||
2248 | ||
2249 | // ---------------------------------------------------------------------------- | |
2250 | // wxNoOptimize: switch off size optimization | |
2251 | // ---------------------------------------------------------------------------- | |
2252 | ||
2253 | int wxNoOptimize::ms_count = 0; | |
2254 |