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