]>
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" | |
ab6b6b15 | 39 | #include "wx/scrolbar.h" |
83df96d6 JS |
40 | #include "wx/module.h" |
41 | #include "wx/menuitem.h" | |
42 | #include "wx/log.h" | |
a17a79ba | 43 | #include "wx/univ/renderer.h" |
83df96d6 JS |
44 | |
45 | #if wxUSE_DRAG_AND_DROP | |
46 | #include "wx/dnd.h" | |
47 | #endif | |
48 | ||
bc797f4c | 49 | #include "wx/x11/private.h" |
7266b672 | 50 | #include "X11/Xutil.h" |
83df96d6 | 51 | |
461e93f9 JS |
52 | #if wxUSE_NANOX |
53 | // For wxGetLocalTime, used by XButtonEventGetTime | |
54 | #include "wx/timer.h" | |
55 | #endif | |
56 | ||
83df96d6 JS |
57 | #include <string.h> |
58 | ||
83df96d6 JS |
59 | // ---------------------------------------------------------------------------- |
60 | // global variables for this module | |
61 | // ---------------------------------------------------------------------------- | |
62 | ||
63 | extern wxHashTable *wxWidgetHashTable; | |
ab6b6b15 | 64 | extern wxHashTable *wxClientWidgetHashTable; |
83df96d6 | 65 | static wxWindow* g_captureWindow = NULL; |
c2c0dabf | 66 | static GC g_eraseGC; |
83df96d6 | 67 | |
83df96d6 JS |
68 | // ---------------------------------------------------------------------------- |
69 | // macros | |
70 | // ---------------------------------------------------------------------------- | |
71 | ||
72 | #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask) | |
73 | #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask) | |
74 | #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask) | |
75 | ||
76 | // ---------------------------------------------------------------------------- | |
77 | // event tables | |
78 | // ---------------------------------------------------------------------------- | |
79 | ||
8354aa92 | 80 | IMPLEMENT_ABSTRACT_CLASS(wxWindowX11, wxWindowBase) |
83df96d6 | 81 | |
bc797f4c JS |
82 | BEGIN_EVENT_TABLE(wxWindowX11, wxWindowBase) |
83 | EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged) | |
bc797f4c | 84 | END_EVENT_TABLE() |
83df96d6 JS |
85 | |
86 | // ============================================================================ | |
87 | // implementation | |
88 | // ============================================================================ | |
89 | ||
90 | // ---------------------------------------------------------------------------- | |
91 | // helper functions | |
92 | // ---------------------------------------------------------------------------- | |
93 | ||
83df96d6 JS |
94 | // ---------------------------------------------------------------------------- |
95 | // constructors | |
96 | // ---------------------------------------------------------------------------- | |
97 | ||
bc797f4c | 98 | void wxWindowX11::Init() |
83df96d6 JS |
99 | { |
100 | // generic initializations first | |
101 | InitBase(); | |
102 | ||
7266b672 | 103 | // X11-specific |
ab6b6b15 RR |
104 | m_mainWindow = (WXWindow) 0; |
105 | m_clientWindow = (WXWindow) 0; | |
106 | m_insertIntoMain = FALSE; | |
065722d7 | 107 | m_updateNcArea = FALSE; |
ab6b6b15 | 108 | |
83df96d6 | 109 | m_winCaptured = FALSE; |
3a0b23eb | 110 | m_needsInputFocus = FALSE; |
83df96d6 JS |
111 | m_isShown = TRUE; |
112 | m_isBeingDeleted = FALSE; | |
83df96d6 JS |
113 | m_lastTS = 0; |
114 | m_lastButton = 0; | |
83df96d6 JS |
115 | } |
116 | ||
117 | // real construction (Init() must have been called before!) | |
bc797f4c | 118 | bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, |
83df96d6 JS |
119 | const wxPoint& pos, |
120 | const wxSize& size, | |
121 | long style, | |
122 | const wxString& name) | |
123 | { | |
124 | wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" ); | |
125 | ||
126 | CreateBase(parent, id, pos, size, style, wxDefaultValidator, name); | |
127 | ||
3cd0b8c5 | 128 | parent->AddChild(this); |
83df96d6 | 129 | |
b513212d JS |
130 | int w = size.GetWidth(); |
131 | int h = size.GetHeight(); | |
132 | int x = size.GetX(); | |
133 | int y = size.GetY(); | |
178572bb RR |
134 | if (w == -1) w = 20; |
135 | if (h == -1) h = 20; | |
b513212d JS |
136 | if (x == -1) x = 0; |
137 | if (y == -1) y = 0; | |
83df96d6 | 138 | |
3cd0b8c5 RR |
139 | Display *xdisplay = (Display*) wxGlobalDisplay(); |
140 | int xscreen = DefaultScreen( xdisplay ); | |
7e4501ee | 141 | Visual *xvisual = DefaultVisual( xdisplay, xscreen ); |
3cd0b8c5 | 142 | Colormap cm = DefaultColormap( xdisplay, xscreen ); |
b513212d | 143 | |
3cd0b8c5 RR |
144 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); |
145 | m_backgroundColour.CalcPixel( (WXColormap) cm ); | |
146 | ||
147 | m_foregroundColour = *wxBLACK; | |
148 | m_foregroundColour.CalcPixel( (WXColormap) cm ); | |
3cd0b8c5 | 149 | |
ab6b6b15 RR |
150 | Window xparent = (Window) parent->GetClientWindow(); |
151 | ||
152 | // Add window's own scrollbars to main window, not to client window | |
153 | if (parent->GetInsertIntoMain()) | |
154 | { | |
155 | // wxLogDebug( "Inserted into main: %s", GetName().c_str() ); | |
156 | xparent = (Window) parent->GetMainWindow(); | |
157 | } | |
2f12683e RR |
158 | |
159 | wxSize size2(size); | |
160 | if (size2.x == -1) | |
161 | size2.x = 20; | |
162 | if (size2.y == -1) | |
163 | size2.y = 20; | |
b513212d | 164 | |
2f12683e RR |
165 | wxPoint pos2(pos); |
166 | if (pos2.x == -1) | |
167 | pos2.x = 0; | |
168 | if (pos2.y == -1) | |
169 | pos2.y = 0; | |
170 | ||
ab6b6b15 RR |
171 | #if wxUSE_TWO_WINDOWS |
172 | bool need_two_windows = | |
173 | ((( wxSUNKEN_BORDER | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0); | |
174 | #else | |
175 | bool need_two_windows = FALSE; | |
176 | #endif | |
177 | ||
8601b2e1 JS |
178 | #if wxUSE_NANOX |
179 | long xattributes = 0; | |
180 | #else | |
7e4501ee | 181 | XSetWindowAttributes xattributes; |
ab6b6b15 | 182 | long xattributes_mask = 0; |
7e4501ee | 183 | |
ab6b6b15 | 184 | xattributes_mask |= CWBackPixel; |
7e4501ee | 185 | xattributes.background_pixel = m_backgroundColour.GetPixel(); |
ab6b6b15 RR |
186 | |
187 | xattributes_mask |= CWBorderPixel; | |
7e4501ee RR |
188 | xattributes.border_pixel = BlackPixel( xdisplay, xscreen ); |
189 | ||
2f12683e | 190 | xattributes_mask |= CWEventMask; |
8601b2e1 | 191 | #endif |
ab6b6b15 RR |
192 | |
193 | if (need_two_windows) | |
2f12683e | 194 | { |
8601b2e1 JS |
195 | #if wxUSE_NANOX |
196 | long backColor, foreColor; | |
197 | backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()); | |
198 | foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue()); | |
199 | ||
200 | Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, | |
201 | 0, 0, InputOutput, xvisual, backColor, foreColor); | |
202 | XSelectInput( xdisplay, xwindow, | |
203 | GR_EVENT_MASK_CLOSE_REQ | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
204 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
205 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
206 | PropertyChangeMask ); | |
207 | ||
208 | #else | |
209 | // Normal X11 | |
ab6b6b15 RR |
210 | xattributes.event_mask = |
211 | ExposureMask | StructureNotifyMask | ColormapChangeMask; | |
212 | ||
213 | Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, | |
214 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); | |
8601b2e1 JS |
215 | |
216 | #endif | |
217 | ||
ab6b6b15 RR |
218 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); |
219 | ||
220 | m_mainWindow = (WXWindow) xwindow; | |
221 | wxAddWindowToTable( xwindow, (wxWindow*) this ); | |
222 | ||
223 | XMapWindow( xdisplay, xwindow ); | |
8601b2e1 JS |
224 | |
225 | #if !wxUSE_NANOX | |
ab6b6b15 RR |
226 | xattributes.event_mask = |
227 | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
228 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
229 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
230 | PropertyChangeMask | VisibilityChangeMask ; | |
231 | ||
232 | if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE )) | |
233 | { | |
234 | xattributes_mask |= CWBitGravity; | |
235 | xattributes.bit_gravity = StaticGravity; | |
236 | } | |
8601b2e1 JS |
237 | #endif |
238 | ||
065722d7 RR |
239 | if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER)) |
240 | { | |
241 | pos2.x = 2; | |
242 | pos2.y = 2; | |
243 | size2.x -= 4; | |
244 | size2.y -= 4; | |
245 | } else | |
246 | if (HasFlag( wxSIMPLE_BORDER )) | |
247 | { | |
248 | pos2.x = 1; | |
249 | pos2.y = 1; | |
250 | size2.x -= 2; | |
251 | size2.y -= 2; | |
252 | } else | |
253 | { | |
254 | pos2.x = 0; | |
255 | pos2.y = 0; | |
256 | } | |
8601b2e1 JS |
257 | #if wxUSE_NANOX |
258 | backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()); | |
259 | foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue()); | |
260 | ||
261 | xwindow = XCreateWindowWithColor( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y, | |
262 | 0, 0, InputOutput, xvisual, backColor, foreColor); | |
263 | XSelectInput( xdisplay, xwindow, | |
264 | GR_EVENT_MASK_CLOSE_REQ | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
265 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
266 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
267 | PropertyChangeMask ); | |
065722d7 | 268 | |
8601b2e1 | 269 | #else |
065722d7 | 270 | xwindow = XCreateWindow( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y, |
ab6b6b15 | 271 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); |
8601b2e1 JS |
272 | #endif |
273 | ||
ab6b6b15 RR |
274 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); |
275 | ||
276 | m_clientWindow = (WXWindow) xwindow; | |
277 | wxAddClientWindowToTable( xwindow, (wxWindow*) this ); | |
278 | ||
279 | XMapWindow( xdisplay, xwindow ); | |
2f12683e | 280 | } |
ab6b6b15 RR |
281 | else |
282 | { | |
283 | // wxLogDebug( "No two windows needed %s", GetName().c_str() ); | |
8601b2e1 JS |
284 | #if wxUSE_NANOX |
285 | long backColor, foreColor; | |
286 | backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()); | |
287 | foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue()); | |
ab6b6b15 | 288 | |
8601b2e1 JS |
289 | Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, |
290 | 0, 0, InputOutput, xvisual, backColor, foreColor); | |
291 | XSelectInput( xdisplay, xwindow, | |
292 | GR_EVENT_MASK_CLOSE_REQ | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
293 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
294 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
295 | PropertyChangeMask ); | |
296 | ||
297 | #else | |
ab6b6b15 RR |
298 | xattributes.event_mask = |
299 | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
300 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
301 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
302 | PropertyChangeMask | VisibilityChangeMask ; | |
2f12683e | 303 | |
ab6b6b15 RR |
304 | if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE )) |
305 | { | |
306 | xattributes_mask |= CWBitGravity; | |
065722d7 | 307 | xattributes.bit_gravity = NorthWestGravity; |
ab6b6b15 RR |
308 | } |
309 | ||
310 | Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, | |
311 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); | |
8601b2e1 JS |
312 | #endif |
313 | ||
ab6b6b15 RR |
314 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); |
315 | ||
316 | m_mainWindow = (WXWindow) xwindow; | |
317 | m_clientWindow = m_mainWindow; | |
318 | wxAddWindowToTable( xwindow, (wxWindow*) this ); | |
319 | ||
320 | XMapWindow( xdisplay, xwindow ); | |
321 | } | |
b513212d | 322 | |
b28d3abf JS |
323 | // Is a subwindow, so map immediately |
324 | m_isShown = TRUE; | |
83df96d6 JS |
325 | |
326 | // Without this, the cursor may not be restored properly (e.g. in splitter | |
327 | // sample). | |
328 | SetCursor(*wxSTANDARD_CURSOR); | |
329 | SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
15c69343 JS |
330 | |
331 | // Don't call this, it can have nasty repercussions for composite controls, | |
332 | // for example | |
333 | // SetSize(pos.x, pos.y, size.x, size.y); | |
83df96d6 JS |
334 | |
335 | return TRUE; | |
336 | } | |
337 | ||
338 | // Destructor | |
7266b672 | 339 | wxWindowX11::~wxWindowX11() |
83df96d6 JS |
340 | { |
341 | if (g_captureWindow == this) | |
342 | g_captureWindow = NULL; | |
343 | ||
344 | m_isBeingDeleted = TRUE; | |
345 | ||
d02cb44e | 346 | if (m_parent) |
83df96d6 JS |
347 | m_parent->RemoveChild( this ); |
348 | ||
d02cb44e | 349 | DestroyChildren(); |
83df96d6 | 350 | |
ab6b6b15 | 351 | if (m_clientWindow != m_mainWindow) |
83df96d6 | 352 | { |
ab6b6b15 RR |
353 | // Destroy the cleint window |
354 | Window xwindow = (Window) m_clientWindow; | |
355 | wxDeleteClientWindowFromTable( xwindow ); | |
7e4501ee | 356 | XDestroyWindow( wxGlobalDisplay(), xwindow ); |
ab6b6b15 | 357 | m_clientWindow = NULL; |
83df96d6 | 358 | } |
ab6b6b15 RR |
359 | |
360 | // Destroy the window | |
361 | Window xwindow = (Window) m_mainWindow; | |
362 | wxDeleteWindowFromTable( xwindow ); | |
363 | XDestroyWindow( wxGlobalDisplay(), xwindow ); | |
364 | m_mainWindow = NULL; | |
83df96d6 JS |
365 | } |
366 | ||
367 | // --------------------------------------------------------------------------- | |
368 | // basic operations | |
369 | // --------------------------------------------------------------------------- | |
370 | ||
bc797f4c | 371 | void wxWindowX11::SetFocus() |
83df96d6 | 372 | { |
ab6b6b15 | 373 | Window xwindow = (Window) m_clientWindow; |
86fd8bda RR |
374 | |
375 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
9b8270da RR |
376 | |
377 | wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") ); | |
378 | ||
379 | #if 0 | |
380 | if (GetName() == "scrollBar") | |
381 | { | |
382 | char *crash = NULL; | |
383 | *crash = 0; | |
384 | } | |
385 | #endif | |
386 | ||
3a0b23eb JS |
387 | if (wxWindowIsVisible(xwindow)) |
388 | { | |
79ad56d0 | 389 | XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime ); |
ba696cfa | 390 | m_needsInputFocus = FALSE; |
3a0b23eb JS |
391 | } |
392 | else | |
393 | { | |
ba696cfa | 394 | m_needsInputFocus = TRUE; |
3a0b23eb | 395 | } |
83df96d6 JS |
396 | } |
397 | ||
398 | // Get the window with the focus | |
399 | wxWindow *wxWindowBase::FindFocus() | |
400 | { | |
86fd8bda | 401 | Window xfocus = (Window) 0; |
b513212d | 402 | int revert = 0; |
bc797f4c | 403 | |
86fd8bda RR |
404 | XGetInputFocus( wxGlobalDisplay(), &xfocus, &revert); |
405 | if (xfocus) | |
83df96d6 | 406 | { |
86fd8bda | 407 | wxWindow *win = wxGetWindowFromTable( xfocus ); |
288efe84 JS |
408 | if (!win) |
409 | { | |
410 | win = wxGetClientWindowFromTable( xfocus ); | |
411 | } | |
b513212d JS |
412 | |
413 | return win; | |
83df96d6 JS |
414 | } |
415 | ||
b513212d | 416 | return NULL; |
83df96d6 JS |
417 | } |
418 | ||
b513212d JS |
419 | // Enabling/disabling handled by event loop, and not sending events |
420 | // if disabled. | |
bc797f4c | 421 | bool wxWindowX11::Enable(bool enable) |
83df96d6 JS |
422 | { |
423 | if ( !wxWindowBase::Enable(enable) ) | |
424 | return FALSE; | |
b513212d | 425 | |
83df96d6 JS |
426 | return TRUE; |
427 | } | |
428 | ||
bc797f4c | 429 | bool wxWindowX11::Show(bool show) |
83df96d6 | 430 | { |
7edcafa4 | 431 | wxWindowBase::Show(show); |
83df96d6 | 432 | |
ab6b6b15 RR |
433 | Window xwindow = (Window) m_mainWindow; |
434 | Display *xdisp = wxGlobalDisplay(); | |
83df96d6 | 435 | if (show) |
b513212d | 436 | { |
7e4501ee | 437 | // wxLogDebug( "Mapping window of type %s", GetName().c_str() ); |
ab6b6b15 | 438 | XMapWindow(xdisp, xwindow); |
b513212d | 439 | } |
83df96d6 | 440 | else |
b513212d | 441 | { |
7e4501ee | 442 | // wxLogDebug( "Unmapping window of type %s", GetName().c_str() ); |
ab6b6b15 | 443 | XUnmapWindow(xdisp, xwindow); |
b513212d | 444 | } |
83df96d6 JS |
445 | |
446 | return TRUE; | |
447 | } | |
448 | ||
449 | // Raise the window to the top of the Z order | |
bc797f4c | 450 | void wxWindowX11::Raise() |
83df96d6 | 451 | { |
ab6b6b15 RR |
452 | if (m_mainWindow) |
453 | XRaiseWindow( wxGlobalDisplay(), (Window) m_mainWindow ); | |
83df96d6 JS |
454 | } |
455 | ||
456 | // Lower the window to the bottom of the Z order | |
bc797f4c | 457 | void wxWindowX11::Lower() |
83df96d6 | 458 | { |
ab6b6b15 RR |
459 | if (m_mainWindow) |
460 | XLowerWindow( wxGlobalDisplay(), (Window) m_mainWindow ); | |
83df96d6 JS |
461 | } |
462 | ||
bc797f4c | 463 | void wxWindowX11::DoCaptureMouse() |
83df96d6 | 464 | { |
7edcafa4 JS |
465 | if ((g_captureWindow != NULL) && (g_captureWindow != this)) |
466 | { | |
346d4fcd | 467 | wxASSERT_MSG(FALSE, "Trying to capture before mouse released."); |
7edcafa4 | 468 | |
346d4fcd RR |
469 | // Core dump now |
470 | int *tmp = NULL; | |
471 | (*tmp) = 1; | |
472 | return; | |
7edcafa4 JS |
473 | } |
474 | ||
346d4fcd | 475 | if (m_winCaptured) |
83df96d6 JS |
476 | return; |
477 | ||
ab6b6b15 | 478 | Window xwindow = (Window) m_clientWindow; |
346d4fcd | 479 | |
86fd8bda RR |
480 | wxCHECK_RET( xwindow, wxT("invalid window") ); |
481 | ||
7edcafa4 JS |
482 | g_captureWindow = (wxWindow*) this; |
483 | ||
346d4fcd | 484 | if (xwindow) |
b513212d | 485 | { |
346d4fcd | 486 | int res = XGrabPointer(wxGlobalDisplay(), xwindow, |
b513212d JS |
487 | FALSE, |
488 | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, | |
489 | GrabModeAsync, | |
490 | GrabModeAsync, | |
491 | None, | |
492 | None, /* cursor */ // TODO: This may need to be set to the cursor of this window | |
346d4fcd | 493 | CurrentTime ); |
b513212d | 494 | |
b28d3abf | 495 | if (res != GrabSuccess) |
b513212d | 496 | { |
346d4fcd RR |
497 | wxString msg; |
498 | msg.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName()); | |
499 | wxLogDebug(msg); | |
500 | if (res == GrabNotViewable) | |
501 | { | |
502 | wxLogDebug("This is not a viewable window - perhaps not shown yet?"); | |
503 | } | |
504 | g_captureWindow = NULL; | |
b28d3abf | 505 | return; |
b513212d | 506 | } |
346d4fcd | 507 | |
b28d3abf | 508 | m_winCaptured = TRUE; |
b513212d | 509 | } |
83df96d6 JS |
510 | } |
511 | ||
bc797f4c | 512 | void wxWindowX11::DoReleaseMouse() |
83df96d6 JS |
513 | { |
514 | g_captureWindow = NULL; | |
346d4fcd | 515 | |
83df96d6 JS |
516 | if ( !m_winCaptured ) |
517 | return; | |
518 | ||
ab6b6b15 | 519 | Window xwindow = (Window) m_clientWindow; |
b513212d | 520 | |
346d4fcd | 521 | if (xwindow) |
b28d3abf | 522 | { |
346d4fcd | 523 | XUngrabPointer( wxGlobalDisplay(), CurrentTime ); |
b28d3abf | 524 | } |
887dd52f | 525 | |
9691c806 | 526 | // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() ); |
83df96d6 JS |
527 | |
528 | m_winCaptured = FALSE; | |
529 | } | |
530 | ||
bc797f4c | 531 | bool wxWindowX11::SetFont(const wxFont& font) |
83df96d6 JS |
532 | { |
533 | if ( !wxWindowBase::SetFont(font) ) | |
534 | { | |
535 | // nothing to do | |
536 | return FALSE; | |
537 | } | |
538 | ||
83df96d6 JS |
539 | return TRUE; |
540 | } | |
541 | ||
bc797f4c | 542 | bool wxWindowX11::SetCursor(const wxCursor& cursor) |
83df96d6 JS |
543 | { |
544 | if ( !wxWindowBase::SetCursor(cursor) ) | |
545 | { | |
546 | // no change | |
547 | return FALSE; | |
548 | } | |
549 | ||
ab6b6b15 | 550 | Window xwindow = (Window) m_clientWindow; |
86fd8bda RR |
551 | |
552 | wxCHECK_MSG( xwindow, FALSE, wxT("invalid window") ); | |
553 | ||
554 | wxCursor cursorToUse; | |
83df96d6 | 555 | if (m_cursor.Ok()) |
86fd8bda | 556 | cursorToUse = m_cursor; |
83df96d6 | 557 | else |
86fd8bda | 558 | cursorToUse = *wxSTANDARD_CURSOR; |
83df96d6 | 559 | |
86fd8bda | 560 | Cursor xcursor = (Cursor) cursorToUse.GetCursor(); |
83df96d6 | 561 | |
e88be8c9 | 562 | XDefineCursor( wxGlobalDisplay(), xwindow, xcursor ); |
83df96d6 JS |
563 | |
564 | return TRUE; | |
565 | } | |
566 | ||
567 | // Coordinates relative to the window | |
bc797f4c | 568 | void wxWindowX11::WarpPointer (int x, int y) |
83df96d6 | 569 | { |
ab6b6b15 | 570 | Window xwindow = (Window) m_clientWindow; |
86fd8bda RR |
571 | |
572 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
573 | ||
574 | XWarpPointer( wxGlobalDisplay(), None, xwindow, 0, 0, 0, 0, x, y); | |
83df96d6 JS |
575 | } |
576 | ||
83df96d6 | 577 | // Does a physical scroll |
bc797f4c | 578 | void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect) |
83df96d6 | 579 | { |
fc9be1cf RR |
580 | // No scrolling requested. |
581 | if ((dx == 0) && (dy == 0)) return; | |
582 | ||
583 | if (!m_updateRegion.IsEmpty()) | |
584 | { | |
585 | m_updateRegion.Offset( dx, dy ); | |
586 | ||
587 | int cw = 0; | |
588 | int ch = 0; | |
589 | GetSize( &cw, &ch ); // GetClientSize() ?? | |
590 | m_updateRegion.Intersect( 0, 0, cw, ch ); | |
591 | } | |
592 | ||
593 | if (!m_clearRegion.IsEmpty()) | |
594 | { | |
595 | m_clearRegion.Offset( dx, dy ); | |
596 | ||
597 | int cw = 0; | |
598 | int ch = 0; | |
599 | GetSize( &cw, &ch ); // GetClientSize() ?? | |
600 | m_clearRegion.Intersect( 0, 0, cw, ch ); | |
601 | } | |
602 | ||
ab6b6b15 | 603 | Window xwindow = (Window) GetClientWindow(); |
7e085304 RR |
604 | |
605 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
606 | ||
607 | Display *xdisplay = wxGlobalDisplay(); | |
608 | ||
609 | GC xgc = XCreateGC( xdisplay, xwindow, 0, NULL ); | |
610 | XSetGraphicsExposures( xdisplay, xgc, True ); | |
611 | ||
e88be8c9 RR |
612 | int s_x = 0; |
613 | int s_y = 0; | |
4125131b RR |
614 | int cw; |
615 | int ch; | |
616 | if (rect) | |
617 | { | |
618 | s_x = rect->x; | |
619 | s_y = rect->y; | |
e88be8c9 | 620 | |
4125131b RR |
621 | cw = rect->width; |
622 | ch = rect->height; | |
623 | } | |
624 | else | |
625 | { | |
626 | s_x = 0; | |
627 | s_y = 0; | |
628 | GetClientSize( &cw, &ch ); | |
629 | } | |
630 | ||
ab6b6b15 RR |
631 | #if wxUSE_TWO_WINDOWS |
632 | wxPoint offset( 0,0 ); | |
633 | #else | |
4125131b RR |
634 | wxPoint offset = GetClientAreaOrigin(); |
635 | s_x += offset.x; | |
636 | s_y += offset.y; | |
ab6b6b15 | 637 | #endif |
e88be8c9 | 638 | |
7e085304 RR |
639 | int w = cw - abs(dx); |
640 | int h = ch - abs(dy); | |
4125131b | 641 | |
7e085304 | 642 | if ((h < 0) || (w < 0)) |
83df96d6 | 643 | { |
7e085304 | 644 | Refresh(); |
83df96d6 JS |
645 | } |
646 | else | |
647 | { | |
4125131b | 648 | wxRect rect; |
f809133f RR |
649 | if (dx < 0) rect.x = cw+dx + offset.x; else rect.x = s_x; |
650 | if (dy < 0) rect.y = ch+dy + offset.y; else rect.y = s_y; | |
4125131b RR |
651 | if (dy != 0) rect.width = cw; else rect.width = abs(dx); |
652 | if (dx != 0) rect.height = ch; else rect.height = abs(dy); | |
653 | ||
654 | int d_x = s_x; | |
655 | int d_y = s_y; | |
e88be8c9 | 656 | |
4125131b RR |
657 | if (dx < 0) s_x += -dx; |
658 | if (dy < 0) s_y += -dy; | |
e88be8c9 RR |
659 | if (dx > 0) d_x = dx + offset.x; |
660 | if (dy > 0) d_y = dy + offset.y; | |
7e085304 RR |
661 | |
662 | XCopyArea( xdisplay, xwindow, xwindow, xgc, s_x, s_y, w, h, d_x, d_y ); | |
4125131b | 663 | |
e88be8c9 | 664 | // wxLogDebug( "Copy: s_x %d s_y %d w %d h %d d_x %d d_y %d", s_x, s_y, w, h, d_x, d_y ); |
7e085304 | 665 | |
e88be8c9 | 666 | // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height ); |
7e085304 RR |
667 | |
668 | m_updateRegion.Union( rect ); | |
669 | m_clearRegion.Union( rect ); | |
83df96d6 | 670 | } |
bc797f4c | 671 | |
7e085304 | 672 | XFreeGC( xdisplay, xgc ); |
83df96d6 JS |
673 | } |
674 | ||
675 | // --------------------------------------------------------------------------- | |
676 | // drag and drop | |
677 | // --------------------------------------------------------------------------- | |
678 | ||
679 | #if wxUSE_DRAG_AND_DROP | |
680 | ||
bc797f4c | 681 | void wxWindowX11::SetDropTarget(wxDropTarget * WXUNUSED(pDropTarget)) |
83df96d6 JS |
682 | { |
683 | // TODO | |
684 | } | |
685 | ||
686 | #endif | |
687 | ||
688 | // Old style file-manager drag&drop | |
bc797f4c | 689 | void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept)) |
83df96d6 JS |
690 | { |
691 | // TODO | |
692 | } | |
693 | ||
694 | // ---------------------------------------------------------------------------- | |
695 | // tooltips | |
696 | // ---------------------------------------------------------------------------- | |
697 | ||
698 | #if wxUSE_TOOLTIPS | |
699 | ||
bc797f4c | 700 | void wxWindowX11::DoSetToolTip(wxToolTip * WXUNUSED(tooltip)) |
83df96d6 JS |
701 | { |
702 | // TODO | |
703 | } | |
704 | ||
705 | #endif // wxUSE_TOOLTIPS | |
706 | ||
83df96d6 JS |
707 | // --------------------------------------------------------------------------- |
708 | // moving and resizing | |
709 | // --------------------------------------------------------------------------- | |
710 | ||
bc797f4c | 711 | bool wxWindowX11::PreResize() |
83df96d6 JS |
712 | { |
713 | return TRUE; | |
714 | } | |
715 | ||
716 | // Get total size | |
bc797f4c | 717 | void wxWindowX11::DoGetSize(int *x, int *y) const |
83df96d6 | 718 | { |
ab6b6b15 | 719 | Window xwindow = (Window) m_mainWindow; |
86fd8bda RR |
720 | |
721 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
722 | ||
59db9cfa | 723 | //XSync(wxGlobalDisplay(), False); |
e941874b | 724 | |
86fd8bda RR |
725 | XWindowAttributes attr; |
726 | Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); | |
727 | wxASSERT(status); | |
b513212d | 728 | |
86fd8bda RR |
729 | if (status) |
730 | { | |
731 | *x = attr.width /* + 2*m_borderSize */ ; | |
732 | *y = attr.height /* + 2*m_borderSize */ ; | |
83df96d6 | 733 | } |
83df96d6 JS |
734 | } |
735 | ||
bc797f4c | 736 | void wxWindowX11::DoGetPosition(int *x, int *y) const |
83df96d6 | 737 | { |
ab6b6b15 | 738 | Window window = (Window) m_mainWindow; |
b513212d | 739 | if (window) |
83df96d6 | 740 | { |
59db9cfa | 741 | //XSync(wxGlobalDisplay(), False); |
b513212d JS |
742 | XWindowAttributes attr; |
743 | Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); | |
744 | wxASSERT(status); | |
745 | ||
746 | if (status) | |
747 | { | |
748 | *x = attr.x; | |
749 | *y = attr.y; | |
750 | ||
751 | // We may be faking the client origin. So a window that's really at (0, 30) | |
752 | // may appear (to wxWin apps) to be at (0, 0). | |
753 | if (GetParent()) | |
754 | { | |
755 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
756 | *x -= pt.x; | |
757 | *y -= pt.y; | |
758 | } | |
759 | } | |
83df96d6 | 760 | } |
83df96d6 JS |
761 | } |
762 | ||
bc797f4c | 763 | void wxWindowX11::DoScreenToClient(int *x, int *y) const |
83df96d6 | 764 | { |
b513212d | 765 | Display *display = wxGlobalDisplay(); |
bc797f4c | 766 | Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display)); |
ab6b6b15 | 767 | Window thisWindow = (Window) m_clientWindow; |
83df96d6 JS |
768 | |
769 | Window childWindow; | |
770 | int xx = *x; | |
771 | int yy = *y; | |
772 | XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow); | |
773 | } | |
774 | ||
bc797f4c | 775 | void wxWindowX11::DoClientToScreen(int *x, int *y) const |
83df96d6 | 776 | { |
b513212d | 777 | Display *display = wxGlobalDisplay(); |
bc797f4c | 778 | Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display)); |
ab6b6b15 | 779 | Window thisWindow = (Window) m_clientWindow; |
83df96d6 JS |
780 | |
781 | Window childWindow; | |
782 | int xx = *x; | |
783 | int yy = *y; | |
784 | XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow); | |
785 | } | |
786 | ||
787 | ||
788 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
bc797f4c | 789 | void wxWindowX11::DoGetClientSize(int *x, int *y) const |
83df96d6 | 790 | { |
ab6b6b15 | 791 | Window window = (Window) m_mainWindow; |
b513212d JS |
792 | |
793 | if (window) | |
794 | { | |
795 | XWindowAttributes attr; | |
3cd0b8c5 | 796 | Status status = XGetWindowAttributes( wxGlobalDisplay(), window, &attr ); |
b513212d JS |
797 | wxASSERT(status); |
798 | ||
799 | if (status) | |
800 | { | |
801 | *x = attr.width ; | |
802 | *y = attr.height ; | |
803 | } | |
804 | } | |
83df96d6 JS |
805 | } |
806 | ||
bc797f4c | 807 | void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
83df96d6 | 808 | { |
df0e1b64 | 809 | // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height); |
ab6b6b15 RR |
810 | |
811 | Window xwindow = (Window) m_mainWindow; | |
83df96d6 | 812 | |
27398643 RR |
813 | wxCHECK_RET( xwindow, wxT("invalid window") ); |
814 | ||
815 | XWindowAttributes attr; | |
816 | Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); | |
817 | wxCHECK_RET( status, wxT("invalid window attributes") ); | |
818 | ||
819 | int new_x = attr.x; | |
820 | int new_y = attr.y; | |
821 | int new_w = attr.width; | |
822 | int new_h = attr.height; | |
ab6b6b15 | 823 | |
b513212d | 824 | if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
83df96d6 | 825 | { |
27398643 | 826 | int yy = 0; |
e5053ade | 827 | AdjustForParentClientOrigin( x, yy, sizeFlags); |
27398643 | 828 | new_x = x; |
83df96d6 | 829 | } |
b513212d | 830 | if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
83df96d6 | 831 | { |
27398643 | 832 | int xx = 0; |
e5053ade | 833 | AdjustForParentClientOrigin( xx, y, sizeFlags); |
27398643 | 834 | new_y = y; |
83df96d6 | 835 | } |
27398643 | 836 | if (width != -1) |
83df96d6 | 837 | { |
27398643 RR |
838 | new_w = width; |
839 | if (new_w <= 0) | |
840 | new_w = 20; | |
83df96d6 | 841 | } |
27398643 | 842 | if (height != -1) |
b513212d | 843 | { |
27398643 RR |
844 | new_h = height; |
845 | if (new_h <= 0) | |
846 | new_h = 20; | |
b513212d | 847 | } |
27398643 RR |
848 | |
849 | DoMoveWindow( new_x, new_y, new_w, new_h ); | |
83df96d6 JS |
850 | } |
851 | ||
bc797f4c | 852 | void wxWindowX11::DoSetClientSize(int width, int height) |
83df96d6 | 853 | { |
df0e1b64 | 854 | // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height); |
ab6b6b15 RR |
855 | |
856 | Window xwindow = (Window) m_mainWindow; | |
83df96d6 | 857 | |
27398643 | 858 | wxCHECK_RET( xwindow, wxT("invalid window") ); |
83df96d6 | 859 | |
2f12683e | 860 | XResizeWindow( wxGlobalDisplay(), xwindow, width, height ); |
df0e1b64 | 861 | |
ab6b6b15 RR |
862 | if (m_mainWindow != m_clientWindow) |
863 | { | |
864 | xwindow = (Window) m_clientWindow; | |
27398643 | 865 | |
a17a79ba RR |
866 | wxWindow *window = (wxWindow*) this; |
867 | wxRenderer *renderer = window->GetRenderer(); | |
868 | if (renderer) | |
ab6b6b15 | 869 | { |
a17a79ba RR |
870 | wxRect border = renderer->GetBorderDimensions( (wxBorder)(m_windowStyle & wxBORDER_MASK) ); |
871 | width -= border.x + border.width; | |
872 | height -= border.y + border.height; | |
ab6b6b15 | 873 | } |
27398643 | 874 | |
ab6b6b15 RR |
875 | XResizeWindow( wxGlobalDisplay(), xwindow, width, height ); |
876 | } | |
83df96d6 JS |
877 | } |
878 | ||
879 | // For implementation purposes - sometimes decorations make the client area | |
880 | // smaller | |
bc797f4c | 881 | wxPoint wxWindowX11::GetClientAreaOrigin() const |
83df96d6 JS |
882 | { |
883 | return wxPoint(0, 0); | |
884 | } | |
885 | ||
ab6b6b15 RR |
886 | void wxWindowX11::DoMoveWindow(int x, int y, int width, int height) |
887 | { | |
888 | Window xwindow = (Window) m_mainWindow; | |
889 | ||
890 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
891 | ||
892 | #if !wxUSE_NANOX | |
893 | ||
894 | XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, width, height ); | |
895 | if (m_mainWindow != m_clientWindow) | |
896 | { | |
897 | xwindow = (Window) m_clientWindow; | |
898 | ||
a17a79ba RR |
899 | wxWindow *window = (wxWindow*) this; |
900 | wxRenderer *renderer = window->GetRenderer(); | |
901 | if (renderer) | |
ab6b6b15 | 902 | { |
a17a79ba RR |
903 | wxRect border = renderer->GetBorderDimensions( (wxBorder)(m_windowStyle & wxBORDER_MASK) ); |
904 | x = border.x; | |
905 | y = border.y; | |
906 | width -= border.x + border.width; | |
907 | height -= border.y + border.height; | |
908 | } | |
909 | else | |
ab6b6b15 RR |
910 | { |
911 | x = 0; | |
912 | y = 0; | |
913 | } | |
914 | ||
ab6b6b15 RR |
915 | wxScrollBar *sb = window->GetScrollbar( wxHORIZONTAL ); |
916 | if (sb && sb->IsShown()) | |
917 | { | |
918 | wxSize size = sb->GetSize(); | |
919 | height -= size.y; | |
920 | } | |
921 | sb = window->GetScrollbar( wxVERTICAL ); | |
922 | if (sb && sb->IsShown()) | |
923 | { | |
924 | wxSize size = sb->GetSize(); | |
925 | width -= size.x; | |
926 | } | |
927 | ||
288efe84 | 928 | XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, wxMax(1, width), wxMax(1, height) ); |
ab6b6b15 RR |
929 | } |
930 | ||
931 | #else | |
932 | ||
933 | XWindowChanges windowChanges; | |
934 | windowChanges.x = x; | |
935 | windowChanges.y = y; | |
936 | windowChanges.width = width; | |
937 | windowChanges.height = height; | |
938 | windowChanges.stack_mode = 0; | |
939 | int valueMask = CWX | CWY | CWWidth | CWHeight; | |
940 | ||
941 | XConfigureWindow( wxGlobalDisplay(), xwindow, valueMask, &windowChanges ); | |
942 | ||
943 | #endif | |
944 | } | |
945 | ||
bc797f4c | 946 | void wxWindowX11::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH) |
83df96d6 JS |
947 | { |
948 | m_minWidth = minW; | |
949 | m_minHeight = minH; | |
950 | m_maxWidth = maxW; | |
951 | m_maxHeight = maxH; | |
952 | ||
461e93f9 | 953 | #if !wxUSE_NANOX |
b513212d JS |
954 | XSizeHints sizeHints; |
955 | sizeHints.flags = 0; | |
956 | ||
957 | if (minW > -1 && minH > -1) | |
83df96d6 | 958 | { |
b513212d JS |
959 | sizeHints.flags |= PMinSize; |
960 | sizeHints.min_width = minW; | |
961 | sizeHints.min_height = minH; | |
962 | } | |
963 | if (maxW > -1 && maxH > -1) | |
964 | { | |
965 | sizeHints.flags |= PMaxSize; | |
966 | sizeHints.max_width = maxW; | |
967 | sizeHints.max_height = maxH; | |
968 | } | |
969 | if (incW > -1 && incH > -1) | |
970 | { | |
971 | sizeHints.flags |= PResizeInc; | |
972 | sizeHints.width_inc = incW; | |
973 | sizeHints.height_inc = incH; | |
83df96d6 JS |
974 | } |
975 | ||
ab6b6b15 | 976 | XSetWMNormalHints(wxGlobalDisplay(), (Window) m_mainWindow, &sizeHints ); |
2f12683e | 977 | #endif |
83df96d6 JS |
978 | } |
979 | ||
980 | // --------------------------------------------------------------------------- | |
981 | // text metrics | |
982 | // --------------------------------------------------------------------------- | |
983 | ||
bc797f4c | 984 | int wxWindowX11::GetCharHeight() const |
83df96d6 JS |
985 | { |
986 | wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" ); | |
987 | ||
ab6b6b15 | 988 | WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, wxGlobalDisplay()); |
83df96d6 JS |
989 | |
990 | int direction, ascent, descent; | |
991 | XCharStruct overall; | |
992 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
993 | &descent, &overall); | |
994 | ||
995 | // return (overall.ascent + overall.descent); | |
996 | return (ascent + descent); | |
997 | } | |
998 | ||
bc797f4c | 999 | int wxWindowX11::GetCharWidth() const |
83df96d6 JS |
1000 | { |
1001 | wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" ); | |
1002 | ||
ab6b6b15 | 1003 | WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, wxGlobalDisplay()); |
83df96d6 JS |
1004 | |
1005 | int direction, ascent, descent; | |
1006 | XCharStruct overall; | |
1007 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
1008 | &descent, &overall); | |
1009 | ||
1010 | return overall.width; | |
1011 | } | |
1012 | ||
bc797f4c | 1013 | void wxWindowX11::GetTextExtent(const wxString& string, |
83df96d6 JS |
1014 | int *x, int *y, |
1015 | int *descent, int *externalLeading, | |
1016 | const wxFont *theFont) const | |
1017 | { | |
0d1dff01 RR |
1018 | wxFont fontToUse = m_font; |
1019 | if (theFont) fontToUse = *theFont; | |
83df96d6 | 1020 | |
0d1dff01 RR |
1021 | wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") ); |
1022 | ||
ab6b6b15 | 1023 | WXFontStructPtr pFontStruct = fontToUse.GetFontStruct(1.0, wxGlobalDisplay()); |
83df96d6 JS |
1024 | |
1025 | int direction, ascent, descent2; | |
1026 | XCharStruct overall; | |
1027 | int slen = string.Len(); | |
1028 | ||
1029 | #if 0 | |
1030 | if (use16) | |
1031 | XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction, | |
1032 | &ascent, &descent2, &overall); | |
1033 | #endif | |
1034 | ||
461e93f9 | 1035 | XTextExtents((XFontStruct*) pFontStruct, (char*) string.c_str(), slen, |
83df96d6 JS |
1036 | &direction, &ascent, &descent2, &overall); |
1037 | ||
1038 | if ( x ) | |
1039 | *x = (overall.width); | |
1040 | if ( y ) | |
1041 | *y = (ascent + descent2); | |
1042 | if (descent) | |
1043 | *descent = descent2; | |
1044 | if (externalLeading) | |
1045 | *externalLeading = 0; | |
1046 | ||
1047 | } | |
1048 | ||
1049 | // ---------------------------------------------------------------------------- | |
1050 | // painting | |
1051 | // ---------------------------------------------------------------------------- | |
1052 | ||
bc797f4c | 1053 | void wxWindowX11::Refresh(bool eraseBack, const wxRect *rect) |
83df96d6 | 1054 | { |
d02cb44e RR |
1055 | if (eraseBack) |
1056 | { | |
1057 | if (rect) | |
1058 | { | |
1059 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). | |
1060 | m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height ); | |
1061 | } | |
1062 | else | |
1063 | { | |
1064 | int height,width; | |
1065 | GetSize( &width, &height ); | |
1066 | ||
1067 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). | |
1068 | m_clearRegion.Clear(); | |
1069 | m_clearRegion.Union( 0, 0, width, height ); | |
1070 | } | |
1071 | } | |
83df96d6 | 1072 | |
83df96d6 JS |
1073 | if (rect) |
1074 | { | |
d02cb44e RR |
1075 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). |
1076 | m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height ); | |
83df96d6 JS |
1077 | } |
1078 | else | |
1079 | { | |
0d1dff01 RR |
1080 | int height,width; |
1081 | GetSize( &width, &height ); | |
d02cb44e RR |
1082 | |
1083 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). | |
1084 | m_updateRegion.Clear(); | |
1085 | m_updateRegion.Union( 0, 0, width, height ); | |
83df96d6 | 1086 | } |
d02cb44e | 1087 | } |
83df96d6 | 1088 | |
d02cb44e RR |
1089 | void wxWindowX11::Update() |
1090 | { | |
ab6b6b15 RR |
1091 | if (m_updateNcArea) |
1092 | { | |
065722d7 | 1093 | // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName()); |
ab6b6b15 RR |
1094 | // Send nc paint events. |
1095 | SendNcPaintEvents(); | |
1096 | } | |
1097 | ||
d02cb44e | 1098 | if (!m_updateRegion.IsEmpty()) |
83df96d6 | 1099 | { |
ab6b6b15 | 1100 | // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName()); |
887dd52f RR |
1101 | // Actually send erase events. |
1102 | SendEraseEvents(); | |
1103 | ||
1104 | // Actually send paint events. | |
1105 | SendPaintEvents(); | |
83df96d6 | 1106 | } |
83df96d6 JS |
1107 | } |
1108 | ||
bc797f4c | 1109 | void wxWindowX11::Clear() |
83df96d6 | 1110 | { |
ab6b6b15 RR |
1111 | // wxClientDC dc((wxWindow*) this); |
1112 | // wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1113 | // dc.SetBackground(brush); | |
1114 | // dc.Clear(); | |
83df96d6 JS |
1115 | } |
1116 | ||
887dd52f | 1117 | void wxWindowX11::SendEraseEvents() |
83df96d6 | 1118 | { |
2f12683e RR |
1119 | if (m_clearRegion.IsEmpty()) return; |
1120 | ||
ab6b6b15 | 1121 | wxClientDC dc( (wxWindow*)this ); |
2f12683e RR |
1122 | dc.SetClippingRegion( m_clearRegion ); |
1123 | ||
1124 | wxEraseEvent erase_event( GetId(), &dc ); | |
1125 | erase_event.SetEventObject( this ); | |
0b5c0e1a | 1126 | |
c2c0dabf | 1127 | if (!GetEventHandler()->ProcessEvent(erase_event) ) |
2f12683e | 1128 | { |
2f12683e | 1129 | Display *xdisplay = wxGlobalDisplay(); |
c2c0dabf RR |
1130 | Window xwindow = (Window) GetClientWindow(); |
1131 | XSetForeground( xdisplay, g_eraseGC, m_backgroundColour.GetPixel() ); | |
1132 | ||
2f12683e RR |
1133 | wxRegionIterator upd( m_clearRegion ); |
1134 | while (upd) | |
1934d291 | 1135 | { |
c2c0dabf | 1136 | XFillRectangle( xdisplay, xwindow, g_eraseGC, |
2f12683e RR |
1137 | upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() ); |
1138 | upd ++; | |
1934d291 | 1139 | } |
83df96d6 | 1140 | } |
2f12683e RR |
1141 | |
1142 | m_clearRegion.Clear(); | |
887dd52f RR |
1143 | } |
1144 | ||
887dd52f RR |
1145 | void wxWindowX11::SendPaintEvents() |
1146 | { | |
df0e1b64 JS |
1147 | // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId()); |
1148 | ||
887dd52f | 1149 | m_clipPaintRegion = TRUE; |
aae73669 | 1150 | |
1934d291 RR |
1151 | wxPaintEvent paint_event( GetId() ); |
1152 | paint_event.SetEventObject( this ); | |
1153 | GetEventHandler()->ProcessEvent( paint_event ); | |
0d1dff01 | 1154 | |
0b5c0e1a | 1155 | m_updateRegion.Clear(); |
2f12683e | 1156 | |
1934d291 | 1157 | m_clipPaintRegion = FALSE; |
83df96d6 JS |
1158 | } |
1159 | ||
ab6b6b15 RR |
1160 | void wxWindowX11::SendNcPaintEvents() |
1161 | { | |
a17a79ba RR |
1162 | wxWindow *window = (wxWindow*) this; |
1163 | ||
1164 | // All this for drawing the small square between the scrollbars. | |
1165 | int width = 0; | |
1166 | int height = 0; | |
1167 | int x = 0; | |
1168 | int y = 0; | |
1169 | wxScrollBar *sb = window->GetScrollbar( wxHORIZONTAL ); | |
1170 | if (sb && sb->IsShown()) | |
1171 | { | |
1172 | height = sb->GetSize().y; | |
1173 | y = sb->GetPosition().y; | |
1174 | ||
1175 | sb = window->GetScrollbar( wxVERTICAL ); | |
1176 | if (sb && sb->IsShown()) | |
1177 | { | |
1178 | width = sb->GetSize().x; | |
1179 | x = sb->GetPosition().x; | |
1180 | ||
1181 | Display *xdisplay = wxGlobalDisplay(); | |
1182 | Window xwindow = (Window) GetMainWindow(); | |
1183 | Colormap cm = (Colormap) wxTheApp->GetMainColormap( wxGetDisplay() ); | |
1184 | wxColour colour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE); | |
1185 | colour.CalcPixel( (WXColormap) cm ); | |
1186 | ||
1187 | XSetForeground( xdisplay, g_eraseGC, colour.GetPixel() ); | |
1188 | ||
1189 | XFillRectangle( xdisplay, xwindow, g_eraseGC, x, y, width, height ); | |
1190 | } | |
1191 | } | |
1192 | ||
ab6b6b15 RR |
1193 | wxNcPaintEvent nc_paint_event( GetId() ); |
1194 | nc_paint_event.SetEventObject( this ); | |
1195 | GetEventHandler()->ProcessEvent( nc_paint_event ); | |
065722d7 RR |
1196 | |
1197 | m_updateNcArea = FALSE; | |
ab6b6b15 RR |
1198 | } |
1199 | ||
83df96d6 JS |
1200 | // ---------------------------------------------------------------------------- |
1201 | // event handlers | |
1202 | // ---------------------------------------------------------------------------- | |
1203 | ||
1204 | // Responds to colour changes: passes event on to children. | |
bc797f4c | 1205 | void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event) |
83df96d6 JS |
1206 | { |
1207 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1208 | while ( node ) | |
1209 | { | |
1210 | // Only propagate to non-top-level windows | |
1211 | wxWindow *win = node->GetData(); | |
1212 | if ( win->GetParent() ) | |
1213 | { | |
1214 | wxSysColourChangedEvent event2; | |
1215 | event.m_eventObject = win; | |
1216 | win->GetEventHandler()->ProcessEvent(event2); | |
1217 | } | |
1218 | ||
1219 | node = node->GetNext(); | |
1220 | } | |
1221 | } | |
1222 | ||
0d1dff01 | 1223 | void wxWindowX11::OnInternalIdle() |
83df96d6 | 1224 | { |
0d1dff01 RR |
1225 | // Update invalidated regions. |
1226 | Update(); | |
1227 | ||
83df96d6 JS |
1228 | // This calls the UI-update mechanism (querying windows for |
1229 | // menu/toolbar/control state information) | |
1230 | UpdateWindowUI(); | |
3a0b23eb JS |
1231 | |
1232 | // Set the input focus if couldn't do it before | |
1233 | if (m_needsInputFocus) | |
ff6b424a | 1234 | { |
3a0b23eb | 1235 | SetFocus(); |
ff6b424a | 1236 | } |
83df96d6 JS |
1237 | } |
1238 | ||
83df96d6 JS |
1239 | // ---------------------------------------------------------------------------- |
1240 | // function which maintain the global hash table mapping Widgets to wxWindows | |
1241 | // ---------------------------------------------------------------------------- | |
1242 | ||
bc797f4c | 1243 | bool wxAddWindowToTable(Window w, wxWindow *win) |
83df96d6 JS |
1244 | { |
1245 | wxWindow *oldItem = NULL; | |
1246 | if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w))) | |
1247 | { | |
1248 | wxLogDebug("Widget table clash: new widget is %ld, %s", | |
1249 | (long)w, win->GetClassInfo()->GetClassName()); | |
1250 | return FALSE; | |
1251 | } | |
1252 | ||
1253 | wxWidgetHashTable->Put((long) w, win); | |
1254 | ||
bc797f4c | 1255 | wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)", |
83df96d6 JS |
1256 | w, win, win->GetClassInfo()->GetClassName()); |
1257 | ||
1258 | return TRUE; | |
1259 | } | |
1260 | ||
bc797f4c | 1261 | wxWindow *wxGetWindowFromTable(Window w) |
83df96d6 JS |
1262 | { |
1263 | return (wxWindow *)wxWidgetHashTable->Get((long) w); | |
1264 | } | |
1265 | ||
bc797f4c | 1266 | void wxDeleteWindowFromTable(Window w) |
83df96d6 JS |
1267 | { |
1268 | wxWidgetHashTable->Delete((long)w); | |
1269 | } | |
1270 | ||
1271 | // ---------------------------------------------------------------------------- | |
ab6b6b15 | 1272 | // function which maintain the global hash table mapping client widgets |
83df96d6 JS |
1273 | // ---------------------------------------------------------------------------- |
1274 | ||
ab6b6b15 RR |
1275 | bool wxAddClientWindowToTable(Window w, wxWindow *win) |
1276 | { | |
1277 | wxWindow *oldItem = NULL; | |
1278 | if ((oldItem = (wxWindow *)wxClientWidgetHashTable->Get ((long) w))) | |
1279 | { | |
1280 | wxLogDebug("Client window table clash: new window is %ld, %s", | |
1281 | (long)w, win->GetClassInfo()->GetClassName()); | |
1282 | return FALSE; | |
1283 | } | |
1284 | ||
1285 | wxClientWidgetHashTable->Put((long) w, win); | |
1286 | ||
1287 | wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)", | |
1288 | w, win, win->GetClassInfo()->GetClassName()); | |
83df96d6 | 1289 | |
ab6b6b15 RR |
1290 | return TRUE; |
1291 | } | |
1292 | ||
1293 | wxWindow *wxGetClientWindowFromTable(Window w) | |
83df96d6 | 1294 | { |
ab6b6b15 | 1295 | return (wxWindow *)wxClientWidgetHashTable->Get((long) w); |
83df96d6 JS |
1296 | } |
1297 | ||
ab6b6b15 | 1298 | void wxDeleteClientWindowFromTable(Window w) |
83df96d6 | 1299 | { |
ab6b6b15 | 1300 | wxClientWidgetHashTable->Delete((long)w); |
83df96d6 JS |
1301 | } |
1302 | ||
ab6b6b15 RR |
1303 | // ---------------------------------------------------------------------------- |
1304 | // add/remove window from the table | |
1305 | // ---------------------------------------------------------------------------- | |
1306 | ||
1307 | // ---------------------------------------------------------------------------- | |
1308 | // X11-specific accessors | |
1309 | // ---------------------------------------------------------------------------- | |
1310 | ||
bc797f4c | 1311 | WXWindow wxWindowX11::GetMainWindow() const |
83df96d6 | 1312 | { |
ab6b6b15 RR |
1313 | return m_mainWindow; |
1314 | } | |
1315 | ||
1316 | WXWindow wxWindowX11::GetClientWindow() const | |
1317 | { | |
1318 | return m_clientWindow; | |
83df96d6 JS |
1319 | } |
1320 | ||
83df96d6 JS |
1321 | // ---------------------------------------------------------------------------- |
1322 | // TranslateXXXEvent() functions | |
1323 | // ---------------------------------------------------------------------------- | |
1324 | ||
1b0fb34b | 1325 | bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Window window, XEvent *xevent) |
83df96d6 | 1326 | { |
461e93f9 | 1327 | switch (XEventGetType(xevent)) |
83df96d6 | 1328 | { |
1b0fb34b JS |
1329 | case EnterNotify: |
1330 | case LeaveNotify: | |
83df96d6 JS |
1331 | case ButtonPress: |
1332 | case ButtonRelease: | |
1333 | case MotionNotify: | |
1334 | { | |
1335 | wxEventType eventType = wxEVT_NULL; | |
1336 | ||
461e93f9 | 1337 | if (XEventGetType(xevent) == EnterNotify) |
83df96d6 | 1338 | { |
1b0fb34b JS |
1339 | //if (local_event.xcrossing.mode!=NotifyNormal) |
1340 | // return ; // Ignore grab events | |
1341 | eventType = wxEVT_ENTER_WINDOW; | |
1342 | // canvas->GetEventHandler()->OnSetFocus(); | |
1343 | } | |
461e93f9 | 1344 | else if (XEventGetType(xevent) == LeaveNotify) |
1b0fb34b JS |
1345 | { |
1346 | //if (local_event.xcrossingr.mode!=NotifyNormal) | |
1347 | // return ; // Ignore grab events | |
1348 | eventType = wxEVT_LEAVE_WINDOW; | |
1349 | // canvas->GetEventHandler()->OnKillFocus(); | |
83df96d6 | 1350 | } |
461e93f9 | 1351 | else if (XEventGetType(xevent) == MotionNotify) |
83df96d6 JS |
1352 | { |
1353 | eventType = wxEVT_MOTION; | |
1354 | } | |
461e93f9 | 1355 | else if (XEventGetType(xevent) == ButtonPress) |
83df96d6 | 1356 | { |
461e93f9 | 1357 | wxevent.SetTimestamp(XButtonEventGetTime(xevent)); |
83df96d6 | 1358 | int button = 0; |
461e93f9 | 1359 | if (XButtonEventLChanged(xevent)) |
83df96d6 JS |
1360 | { |
1361 | eventType = wxEVT_LEFT_DOWN; | |
83df96d6 JS |
1362 | button = 1; |
1363 | } | |
461e93f9 | 1364 | else if (XButtonEventMChanged(xevent)) |
83df96d6 JS |
1365 | { |
1366 | eventType = wxEVT_MIDDLE_DOWN; | |
83df96d6 JS |
1367 | button = 2; |
1368 | } | |
461e93f9 | 1369 | else if (XButtonEventRChanged(xevent)) |
83df96d6 JS |
1370 | { |
1371 | eventType = wxEVT_RIGHT_DOWN; | |
83df96d6 JS |
1372 | button = 3; |
1373 | } | |
1374 | ||
1375 | // check for a double click | |
1b0fb34b | 1376 | // TODO: where can we get this value from? |
b513212d | 1377 | //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay()); |
7266b672 | 1378 | long dclickTime = 200; |
83df96d6 JS |
1379 | long ts = wxevent.GetTimestamp(); |
1380 | ||
1381 | int buttonLast = win->GetLastClickedButton(); | |
1382 | long lastTS = win->GetLastClickTime(); | |
1383 | if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime ) | |
1384 | { | |
1385 | // I have a dclick | |
1386 | win->SetLastClick(0, ts); | |
1387 | if ( eventType == wxEVT_LEFT_DOWN ) | |
1388 | eventType = wxEVT_LEFT_DCLICK; | |
1389 | else if ( eventType == wxEVT_MIDDLE_DOWN ) | |
1390 | eventType = wxEVT_MIDDLE_DCLICK; | |
1391 | else if ( eventType == wxEVT_RIGHT_DOWN ) | |
1392 | eventType = wxEVT_RIGHT_DCLICK; | |
1393 | } | |
1394 | else | |
1395 | { | |
1396 | // not fast enough or different button | |
1397 | win->SetLastClick(button, ts); | |
1398 | } | |
1399 | } | |
461e93f9 | 1400 | else if (XEventGetType(xevent) == ButtonRelease) |
83df96d6 | 1401 | { |
461e93f9 | 1402 | if (XButtonEventLChanged(xevent)) |
83df96d6 JS |
1403 | { |
1404 | eventType = wxEVT_LEFT_UP; | |
83df96d6 | 1405 | } |
461e93f9 | 1406 | else if (XButtonEventMChanged(xevent)) |
83df96d6 JS |
1407 | { |
1408 | eventType = wxEVT_MIDDLE_UP; | |
83df96d6 | 1409 | } |
461e93f9 | 1410 | else if (XButtonEventRChanged(xevent)) |
83df96d6 JS |
1411 | { |
1412 | eventType = wxEVT_RIGHT_UP; | |
83df96d6 JS |
1413 | } |
1414 | else return FALSE; | |
1415 | } | |
1416 | else | |
1417 | { | |
1418 | return FALSE; | |
1419 | } | |
1420 | ||
1421 | wxevent.SetEventType(eventType); | |
1422 | ||
461e93f9 JS |
1423 | wxevent.m_x = XButtonEventGetX(xevent); |
1424 | wxevent.m_y = XButtonEventGetY(xevent); | |
83df96d6 JS |
1425 | |
1426 | wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN) | |
461e93f9 | 1427 | || (XButtonEventLIsDown(xevent) |
83df96d6 JS |
1428 | && (eventType != wxEVT_LEFT_UP))); |
1429 | wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN) | |
461e93f9 | 1430 | || (XButtonEventMIsDown(xevent) |
83df96d6 JS |
1431 | && (eventType != wxEVT_MIDDLE_UP))); |
1432 | wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN) | |
461e93f9 | 1433 | || (XButtonEventRIsDown (xevent) |
83df96d6 JS |
1434 | && (eventType != wxEVT_RIGHT_UP))); |
1435 | ||
461e93f9 JS |
1436 | wxevent.m_shiftDown = XButtonEventShiftIsDown(xevent); |
1437 | wxevent.m_controlDown = XButtonEventCtrlIsDown(xevent); | |
1438 | wxevent.m_altDown = XButtonEventAltIsDown(xevent); | |
1439 | wxevent.m_metaDown = XButtonEventMetaIsDown(xevent); | |
83df96d6 JS |
1440 | |
1441 | wxevent.SetId(win->GetId()); | |
1442 | wxevent.SetEventObject(win); | |
1443 | ||
1444 | return TRUE; | |
1445 | } | |
1446 | } | |
1447 | return FALSE; | |
1448 | } | |
1449 | ||
7eaac9f5 | 1450 | bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Window WXUNUSED(win), XEvent *xevent) |
83df96d6 | 1451 | { |
461e93f9 | 1452 | switch (XEventGetType(xevent)) |
83df96d6 JS |
1453 | { |
1454 | case KeyPress: | |
1455 | case KeyRelease: | |
1456 | { | |
1457 | char buf[20]; | |
1458 | ||
1459 | KeySym keySym; | |
83df96d6 JS |
1460 | (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL); |
1461 | int id = wxCharCodeXToWX (keySym); | |
1462 | ||
461e93f9 JS |
1463 | wxevent.m_shiftDown = XKeyEventShiftIsDown(xevent); |
1464 | wxevent.m_controlDown = XKeyEventCtrlIsDown(xevent); | |
1465 | wxevent.m_altDown = XKeyEventAltIsDown(xevent); | |
1466 | wxevent.m_metaDown = XKeyEventMetaIsDown(xevent); | |
83df96d6 JS |
1467 | wxevent.SetEventObject(win); |
1468 | wxevent.m_keyCode = id; | |
461e93f9 | 1469 | wxevent.SetTimestamp(XKeyEventGetTime(xevent)); |
83df96d6 | 1470 | |
461e93f9 JS |
1471 | wxevent.m_x = XKeyEventGetX(xevent); |
1472 | wxevent.m_y = XKeyEventGetY(xevent); | |
83df96d6 JS |
1473 | |
1474 | if (id > -1) | |
1475 | return TRUE; | |
1476 | else | |
1477 | return FALSE; | |
1478 | break; | |
1479 | } | |
1480 | default: | |
1481 | break; | |
1482 | } | |
1483 | return FALSE; | |
1484 | } | |
1485 | ||
1486 | // ---------------------------------------------------------------------------- | |
1487 | // Colour stuff | |
1488 | // ---------------------------------------------------------------------------- | |
1489 | ||
bc797f4c | 1490 | bool wxWindowX11::SetBackgroundColour(const wxColour& col) |
83df96d6 | 1491 | { |
56cb684a | 1492 | wxWindowBase::SetBackgroundColour(col); |
83df96d6 | 1493 | |
3cd0b8c5 RR |
1494 | Display *xdisplay = (Display*) wxGlobalDisplay(); |
1495 | int xscreen = DefaultScreen( xdisplay ); | |
1496 | Colormap cm = DefaultColormap( xdisplay, xscreen ); | |
1497 | ||
ba696cfa | 1498 | m_backgroundColour.CalcPixel( (WXColormap) cm ); |
3cd0b8c5 | 1499 | |
c2c0dabf RR |
1500 | // We don't set the background colour as we paint |
1501 | // the background ourselves. | |
1502 | // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() ); | |
1503 | ||
83df96d6 JS |
1504 | return TRUE; |
1505 | } | |
1506 | ||
bc797f4c | 1507 | bool wxWindowX11::SetForegroundColour(const wxColour& col) |
83df96d6 JS |
1508 | { |
1509 | if ( !wxWindowBase::SetForegroundColour(col) ) | |
1510 | return FALSE; | |
1511 | ||
83df96d6 JS |
1512 | return TRUE; |
1513 | } | |
1514 | ||
83df96d6 JS |
1515 | // ---------------------------------------------------------------------------- |
1516 | // global functions | |
1517 | // ---------------------------------------------------------------------------- | |
1518 | ||
1519 | wxWindow *wxGetActiveWindow() | |
1520 | { | |
1521 | // TODO | |
1522 | wxFAIL_MSG("Not implemented"); | |
1523 | return NULL; | |
1524 | } | |
1525 | ||
1526 | /* static */ | |
1527 | wxWindow *wxWindowBase::GetCapture() | |
1528 | { | |
1529 | return (wxWindow *)g_captureWindow; | |
1530 | } | |
1531 | ||
1532 | ||
1533 | // Find the wxWindow at the current mouse position, returning the mouse | |
1534 | // position. | |
1535 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) | |
1536 | { | |
1537 | return wxFindWindowAtPoint(wxGetMousePosition()); | |
1538 | } | |
1539 | ||
1540 | // Get the current mouse position. | |
1541 | wxPoint wxGetMousePosition() | |
1542 | { | |
461e93f9 JS |
1543 | #if wxUSE_NANOX |
1544 | /* TODO */ | |
1545 | return wxPoint(0, 0); | |
1546 | #else | |
b513212d | 1547 | Display *display = wxGlobalDisplay(); |
83df96d6 JS |
1548 | Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display)); |
1549 | Window rootReturn, childReturn; | |
1550 | int rootX, rootY, winX, winY; | |
1551 | unsigned int maskReturn; | |
1552 | ||
1553 | XQueryPointer (display, | |
1554 | rootWindow, | |
1555 | &rootReturn, | |
1556 | &childReturn, | |
1557 | &rootX, &rootY, &winX, &winY, &maskReturn); | |
1558 | return wxPoint(rootX, rootY); | |
461e93f9 | 1559 | #endif |
83df96d6 JS |
1560 | } |
1561 | ||
1562 | ||
1563 | // ---------------------------------------------------------------------------- | |
1564 | // wxNoOptimize: switch off size optimization | |
1565 | // ---------------------------------------------------------------------------- | |
1566 | ||
1567 | int wxNoOptimize::ms_count = 0; | |
1568 | ||
c2c0dabf RR |
1569 | |
1570 | // ---------------------------------------------------------------------------- | |
1571 | // wxDCModule | |
1572 | // ---------------------------------------------------------------------------- | |
1573 | ||
1574 | class wxWinModule : public wxModule | |
1575 | { | |
1576 | public: | |
1577 | bool OnInit(); | |
1578 | void OnExit(); | |
1579 | ||
1580 | private: | |
1581 | DECLARE_DYNAMIC_CLASS(wxWinModule) | |
1582 | }; | |
1583 | ||
1584 | IMPLEMENT_DYNAMIC_CLASS(wxWinModule, wxModule) | |
1585 | ||
1586 | bool wxWinModule::OnInit() | |
1587 | { | |
1588 | Display *xdisplay = wxGlobalDisplay(); | |
1589 | int xscreen = DefaultScreen( xdisplay ); | |
1590 | Window xroot = RootWindow( xdisplay, xscreen ); | |
1591 | g_eraseGC = XCreateGC( xdisplay, xroot, 0, NULL ); | |
1592 | XSetFillStyle( xdisplay, g_eraseGC, FillSolid ); | |
1593 | ||
1594 | return TRUE; | |
1595 | } | |
1596 | ||
1597 | void wxWinModule::OnExit() | |
1598 | { | |
1599 | Display *xdisplay = wxGlobalDisplay(); | |
1600 | XFreeGC( xdisplay, g_eraseGC ); | |
1601 | } | |
1602 | ||
1603 |