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