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