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