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