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