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