]>
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 | ||
383 | return win; | |
384 | } | |
385 | ||
386 | return NULL; | |
387 | } | |
388 | ||
389 | // Enabling/disabling handled by event loop, and not sending events | |
390 | // if disabled. | |
391 | bool wxWindowX11::Enable(bool enable) | |
392 | { | |
393 | if ( !wxWindowBase::Enable(enable) ) | |
394 | return FALSE; | |
395 | ||
396 | return TRUE; | |
397 | } | |
398 | ||
399 | bool wxWindowX11::Show(bool show) | |
400 | { | |
401 | wxWindowBase::Show(show); | |
402 | ||
403 | Window xwindow = (Window) m_mainWindow; | |
404 | Display *xdisp = wxGlobalDisplay(); | |
405 | if (show) | |
406 | { | |
407 | // wxLogDebug( "Mapping window of type %s", GetName().c_str() ); | |
408 | XMapWindow(xdisp, xwindow); | |
409 | } | |
410 | else | |
411 | { | |
412 | // wxLogDebug( "Unmapping window of type %s", GetName().c_str() ); | |
413 | XUnmapWindow(xdisp, xwindow); | |
414 | } | |
415 | ||
416 | return TRUE; | |
417 | } | |
418 | ||
419 | // Raise the window to the top of the Z order | |
420 | void wxWindowX11::Raise() | |
421 | { | |
422 | if (m_mainWindow) | |
423 | XRaiseWindow( wxGlobalDisplay(), (Window) m_mainWindow ); | |
424 | } | |
425 | ||
426 | // Lower the window to the bottom of the Z order | |
427 | void wxWindowX11::Lower() | |
428 | { | |
429 | if (m_mainWindow) | |
430 | XLowerWindow( wxGlobalDisplay(), (Window) m_mainWindow ); | |
431 | } | |
432 | ||
433 | void wxWindowX11::DoCaptureMouse() | |
434 | { | |
435 | if ((g_captureWindow != NULL) && (g_captureWindow != this)) | |
436 | { | |
437 | wxASSERT_MSG(FALSE, "Trying to capture before mouse released."); | |
438 | ||
439 | // Core dump now | |
440 | int *tmp = NULL; | |
441 | (*tmp) = 1; | |
442 | return; | |
443 | } | |
444 | ||
445 | if (m_winCaptured) | |
446 | return; | |
447 | ||
448 | Window xwindow = (Window) m_clientWindow; | |
449 | ||
450 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
451 | ||
452 | g_captureWindow = (wxWindow*) this; | |
453 | ||
454 | if (xwindow) | |
455 | { | |
456 | int res = XGrabPointer(wxGlobalDisplay(), xwindow, | |
457 | FALSE, | |
458 | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, | |
459 | GrabModeAsync, | |
460 | GrabModeAsync, | |
461 | None, | |
462 | None, /* cursor */ // TODO: This may need to be set to the cursor of this window | |
463 | CurrentTime ); | |
464 | ||
465 | if (res != GrabSuccess) | |
466 | { | |
467 | wxString msg; | |
468 | msg.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName()); | |
469 | wxLogDebug(msg); | |
470 | if (res == GrabNotViewable) | |
471 | { | |
472 | wxLogDebug("This is not a viewable window - perhaps not shown yet?"); | |
473 | } | |
474 | g_captureWindow = NULL; | |
475 | return; | |
476 | } | |
477 | ||
478 | m_winCaptured = TRUE; | |
479 | } | |
480 | } | |
481 | ||
482 | void wxWindowX11::DoReleaseMouse() | |
483 | { | |
484 | g_captureWindow = NULL; | |
485 | ||
486 | if ( !m_winCaptured ) | |
487 | return; | |
488 | ||
489 | Window xwindow = (Window) m_clientWindow; | |
490 | ||
491 | if (xwindow) | |
492 | { | |
493 | XUngrabPointer( wxGlobalDisplay(), CurrentTime ); | |
494 | } | |
495 | ||
496 | // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() ); | |
497 | ||
498 | m_winCaptured = FALSE; | |
499 | } | |
500 | ||
501 | bool wxWindowX11::SetFont(const wxFont& font) | |
502 | { | |
503 | if ( !wxWindowBase::SetFont(font) ) | |
504 | { | |
505 | // nothing to do | |
506 | return FALSE; | |
507 | } | |
508 | ||
509 | return TRUE; | |
510 | } | |
511 | ||
512 | bool wxWindowX11::SetCursor(const wxCursor& cursor) | |
513 | { | |
514 | if ( !wxWindowBase::SetCursor(cursor) ) | |
515 | { | |
516 | // no change | |
517 | return FALSE; | |
518 | } | |
519 | ||
520 | Window xwindow = (Window) m_clientWindow; | |
521 | ||
522 | wxCHECK_MSG( xwindow, FALSE, wxT("invalid window") ); | |
523 | ||
524 | wxCursor cursorToUse; | |
525 | if (m_cursor.Ok()) | |
526 | cursorToUse = m_cursor; | |
527 | else | |
528 | cursorToUse = *wxSTANDARD_CURSOR; | |
529 | ||
530 | Cursor xcursor = (Cursor) cursorToUse.GetCursor(); | |
531 | ||
532 | XDefineCursor( wxGlobalDisplay(), xwindow, xcursor ); | |
533 | ||
534 | return TRUE; | |
535 | } | |
536 | ||
537 | // Coordinates relative to the window | |
538 | void wxWindowX11::WarpPointer (int x, int y) | |
539 | { | |
540 | Window xwindow = (Window) m_clientWindow; | |
541 | ||
542 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
543 | ||
544 | XWarpPointer( wxGlobalDisplay(), None, xwindow, 0, 0, 0, 0, x, y); | |
545 | } | |
546 | ||
547 | // Does a physical scroll | |
548 | void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect) | |
549 | { | |
550 | // No scrolling requested. | |
551 | if ((dx == 0) && (dy == 0)) return; | |
552 | ||
553 | if (!m_updateRegion.IsEmpty()) | |
554 | { | |
555 | m_updateRegion.Offset( dx, dy ); | |
556 | ||
557 | int cw = 0; | |
558 | int ch = 0; | |
559 | GetSize( &cw, &ch ); // GetClientSize() ?? | |
560 | m_updateRegion.Intersect( 0, 0, cw, ch ); | |
561 | } | |
562 | ||
563 | if (!m_clearRegion.IsEmpty()) | |
564 | { | |
565 | m_clearRegion.Offset( dx, dy ); | |
566 | ||
567 | int cw = 0; | |
568 | int ch = 0; | |
569 | GetSize( &cw, &ch ); // GetClientSize() ?? | |
570 | m_clearRegion.Intersect( 0, 0, cw, ch ); | |
571 | } | |
572 | ||
573 | Window xwindow = (Window) GetClientWindow(); | |
574 | ||
575 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
576 | ||
577 | Display *xdisplay = wxGlobalDisplay(); | |
578 | ||
579 | GC xgc = XCreateGC( xdisplay, xwindow, 0, NULL ); | |
580 | XSetGraphicsExposures( xdisplay, xgc, True ); | |
581 | ||
582 | int s_x = 0; | |
583 | int s_y = 0; | |
584 | int cw; | |
585 | int ch; | |
586 | if (rect) | |
587 | { | |
588 | s_x = rect->x; | |
589 | s_y = rect->y; | |
590 | ||
591 | cw = rect->width; | |
592 | ch = rect->height; | |
593 | } | |
594 | else | |
595 | { | |
596 | s_x = 0; | |
597 | s_y = 0; | |
598 | GetClientSize( &cw, &ch ); | |
599 | } | |
600 | ||
601 | #if wxUSE_TWO_WINDOWS | |
602 | wxPoint offset( 0,0 ); | |
603 | #else | |
604 | wxPoint offset = GetClientAreaOrigin(); | |
605 | s_x += offset.x; | |
606 | s_y += offset.y; | |
607 | #endif | |
608 | ||
609 | int w = cw - abs(dx); | |
610 | int h = ch - abs(dy); | |
611 | ||
612 | if ((h < 0) || (w < 0)) | |
613 | { | |
614 | Refresh(); | |
615 | } | |
616 | else | |
617 | { | |
618 | wxRect rect; | |
619 | if (dx < 0) rect.x = cw+dx + offset.x; else rect.x = s_x; | |
620 | if (dy < 0) rect.y = ch+dy + offset.y; else rect.y = s_y; | |
621 | if (dy != 0) rect.width = cw; else rect.width = abs(dx); | |
622 | if (dx != 0) rect.height = ch; else rect.height = abs(dy); | |
623 | ||
624 | int d_x = s_x; | |
625 | int d_y = s_y; | |
626 | ||
627 | if (dx < 0) s_x += -dx; | |
628 | if (dy < 0) s_y += -dy; | |
629 | if (dx > 0) d_x = dx + offset.x; | |
630 | if (dy > 0) d_y = dy + offset.y; | |
631 | ||
632 | XCopyArea( xdisplay, xwindow, xwindow, xgc, s_x, s_y, w, h, d_x, d_y ); | |
633 | ||
634 | // 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 ); | |
635 | ||
636 | // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height ); | |
637 | ||
638 | m_updateRegion.Union( rect ); | |
639 | m_clearRegion.Union( rect ); | |
640 | } | |
641 | ||
642 | XFreeGC( xdisplay, xgc ); | |
643 | } | |
644 | ||
645 | // --------------------------------------------------------------------------- | |
646 | // drag and drop | |
647 | // --------------------------------------------------------------------------- | |
648 | ||
649 | #if wxUSE_DRAG_AND_DROP | |
650 | ||
651 | void wxWindowX11::SetDropTarget(wxDropTarget * WXUNUSED(pDropTarget)) | |
652 | { | |
653 | // TODO | |
654 | } | |
655 | ||
656 | #endif | |
657 | ||
658 | // Old style file-manager drag&drop | |
659 | void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept)) | |
660 | { | |
661 | // TODO | |
662 | } | |
663 | ||
664 | // ---------------------------------------------------------------------------- | |
665 | // tooltips | |
666 | // ---------------------------------------------------------------------------- | |
667 | ||
668 | #if wxUSE_TOOLTIPS | |
669 | ||
670 | void wxWindowX11::DoSetToolTip(wxToolTip * WXUNUSED(tooltip)) | |
671 | { | |
672 | // TODO | |
673 | } | |
674 | ||
675 | #endif // wxUSE_TOOLTIPS | |
676 | ||
677 | // --------------------------------------------------------------------------- | |
678 | // moving and resizing | |
679 | // --------------------------------------------------------------------------- | |
680 | ||
681 | bool wxWindowX11::PreResize() | |
682 | { | |
683 | return TRUE; | |
684 | } | |
685 | ||
686 | // Get total size | |
687 | void wxWindowX11::DoGetSize(int *x, int *y) const | |
688 | { | |
689 | Window xwindow = (Window) m_mainWindow; | |
690 | ||
691 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
692 | ||
693 | //XSync(wxGlobalDisplay(), False); | |
694 | ||
695 | XWindowAttributes attr; | |
696 | Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); | |
697 | wxASSERT(status); | |
698 | ||
699 | if (status) | |
700 | { | |
701 | *x = attr.width /* + 2*m_borderSize */ ; | |
702 | *y = attr.height /* + 2*m_borderSize */ ; | |
703 | } | |
704 | } | |
705 | ||
706 | void wxWindowX11::DoGetPosition(int *x, int *y) const | |
707 | { | |
708 | Window window = (Window) m_mainWindow; | |
709 | if (window) | |
710 | { | |
711 | //XSync(wxGlobalDisplay(), False); | |
712 | XWindowAttributes attr; | |
713 | Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); | |
714 | wxASSERT(status); | |
715 | ||
716 | if (status) | |
717 | { | |
718 | *x = attr.x; | |
719 | *y = attr.y; | |
720 | ||
721 | // We may be faking the client origin. So a window that's really at (0, 30) | |
722 | // may appear (to wxWin apps) to be at (0, 0). | |
723 | if (GetParent()) | |
724 | { | |
725 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
726 | *x -= pt.x; | |
727 | *y -= pt.y; | |
728 | } | |
729 | } | |
730 | } | |
731 | } | |
732 | ||
733 | void wxWindowX11::DoScreenToClient(int *x, int *y) const | |
734 | { | |
735 | Display *display = wxGlobalDisplay(); | |
736 | Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display)); | |
737 | Window thisWindow = (Window) m_clientWindow; | |
738 | ||
739 | Window childWindow; | |
740 | int xx = *x; | |
741 | int yy = *y; | |
742 | XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow); | |
743 | } | |
744 | ||
745 | void wxWindowX11::DoClientToScreen(int *x, int *y) const | |
746 | { | |
747 | Display *display = wxGlobalDisplay(); | |
748 | Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display)); | |
749 | Window thisWindow = (Window) m_clientWindow; | |
750 | ||
751 | Window childWindow; | |
752 | int xx = *x; | |
753 | int yy = *y; | |
754 | XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow); | |
755 | } | |
756 | ||
757 | ||
758 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
759 | void wxWindowX11::DoGetClientSize(int *x, int *y) const | |
760 | { | |
761 | Window window = (Window) m_mainWindow; | |
762 | ||
763 | if (window) | |
764 | { | |
765 | XWindowAttributes attr; | |
766 | Status status = XGetWindowAttributes( wxGlobalDisplay(), window, &attr ); | |
767 | wxASSERT(status); | |
768 | ||
769 | if (status) | |
770 | { | |
771 | *x = attr.width ; | |
772 | *y = attr.height ; | |
773 | } | |
774 | } | |
775 | } | |
776 | ||
777 | void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
778 | { | |
779 | // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height); | |
780 | ||
781 | Window xwindow = (Window) m_mainWindow; | |
782 | ||
783 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
784 | ||
785 | XWindowAttributes attr; | |
786 | Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); | |
787 | wxCHECK_RET( status, wxT("invalid window attributes") ); | |
788 | ||
789 | int new_x = attr.x; | |
790 | int new_y = attr.y; | |
791 | int new_w = attr.width; | |
792 | int new_h = attr.height; | |
793 | ||
794 | if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
795 | { | |
796 | int yy = 0; | |
797 | AdjustForParentClientOrigin( x, yy, sizeFlags); | |
798 | new_x = x; | |
799 | } | |
800 | if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
801 | { | |
802 | int xx = 0; | |
803 | AdjustForParentClientOrigin( xx, y, sizeFlags); | |
804 | new_y = y; | |
805 | } | |
806 | if (width != -1) | |
807 | { | |
808 | new_w = width; | |
809 | if (new_w <= 0) | |
810 | new_w = 20; | |
811 | } | |
812 | if (height != -1) | |
813 | { | |
814 | new_h = height; | |
815 | if (new_h <= 0) | |
816 | new_h = 20; | |
817 | } | |
818 | ||
819 | DoMoveWindow( new_x, new_y, new_w, new_h ); | |
820 | } | |
821 | ||
822 | void wxWindowX11::DoSetClientSize(int width, int height) | |
823 | { | |
824 | // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height); | |
825 | ||
826 | Window xwindow = (Window) m_mainWindow; | |
827 | ||
828 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
829 | ||
830 | XResizeWindow( wxGlobalDisplay(), xwindow, width, height ); | |
831 | ||
832 | if (m_mainWindow != m_clientWindow) | |
833 | { | |
834 | xwindow = (Window) m_clientWindow; | |
835 | ||
836 | if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER)) | |
837 | { | |
838 | width -= 4; | |
839 | height -= 4; | |
840 | } else | |
841 | if (HasFlag( wxSIMPLE_BORDER )) | |
842 | { | |
843 | width -= 2; | |
844 | height -= 2; | |
845 | } | |
846 | ||
847 | XResizeWindow( wxGlobalDisplay(), xwindow, width, height ); | |
848 | } | |
849 | } | |
850 | ||
851 | // For implementation purposes - sometimes decorations make the client area | |
852 | // smaller | |
853 | wxPoint wxWindowX11::GetClientAreaOrigin() const | |
854 | { | |
855 | return wxPoint(0, 0); | |
856 | } | |
857 | ||
858 | void wxWindowX11::DoMoveWindow(int x, int y, int width, int height) | |
859 | { | |
860 | Window xwindow = (Window) m_mainWindow; | |
861 | ||
862 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
863 | ||
864 | #if !wxUSE_NANOX | |
865 | ||
866 | XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, width, height ); | |
867 | if (m_mainWindow != m_clientWindow) | |
868 | { | |
869 | xwindow = (Window) m_clientWindow; | |
870 | ||
871 | if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER)) | |
872 | { | |
873 | x = 2; | |
874 | y = 2; | |
875 | width -= 4; | |
876 | height -= 4; | |
877 | } else | |
878 | if (HasFlag( wxSIMPLE_BORDER )) | |
879 | { | |
880 | x = 1; | |
881 | y = 1; | |
882 | width -= 2; | |
883 | height -= 2; | |
884 | } else | |
885 | { | |
886 | x = 0; | |
887 | y = 0; | |
888 | } | |
889 | ||
890 | wxWindow *window = (wxWindow*) this; | |
891 | wxScrollBar *sb = window->GetScrollbar( wxHORIZONTAL ); | |
892 | if (sb && sb->IsShown()) | |
893 | { | |
894 | wxSize size = sb->GetSize(); | |
895 | height -= size.y; | |
896 | } | |
897 | sb = window->GetScrollbar( wxVERTICAL ); | |
898 | if (sb && sb->IsShown()) | |
899 | { | |
900 | wxSize size = sb->GetSize(); | |
901 | width -= size.x; | |
902 | } | |
903 | ||
904 | XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, width, height ); | |
905 | } | |
906 | ||
907 | #else | |
908 | ||
909 | XWindowChanges windowChanges; | |
910 | windowChanges.x = x; | |
911 | windowChanges.y = y; | |
912 | windowChanges.width = width; | |
913 | windowChanges.height = height; | |
914 | windowChanges.stack_mode = 0; | |
915 | int valueMask = CWX | CWY | CWWidth | CWHeight; | |
916 | ||
917 | XConfigureWindow( wxGlobalDisplay(), xwindow, valueMask, &windowChanges ); | |
918 | ||
919 | #endif | |
920 | } | |
921 | ||
922 | void wxWindowX11::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH) | |
923 | { | |
924 | m_minWidth = minW; | |
925 | m_minHeight = minH; | |
926 | m_maxWidth = maxW; | |
927 | m_maxHeight = maxH; | |
928 | ||
929 | #if !wxUSE_NANOX | |
930 | XSizeHints sizeHints; | |
931 | sizeHints.flags = 0; | |
932 | ||
933 | if (minW > -1 && minH > -1) | |
934 | { | |
935 | sizeHints.flags |= PMinSize; | |
936 | sizeHints.min_width = minW; | |
937 | sizeHints.min_height = minH; | |
938 | } | |
939 | if (maxW > -1 && maxH > -1) | |
940 | { | |
941 | sizeHints.flags |= PMaxSize; | |
942 | sizeHints.max_width = maxW; | |
943 | sizeHints.max_height = maxH; | |
944 | } | |
945 | if (incW > -1 && incH > -1) | |
946 | { | |
947 | sizeHints.flags |= PResizeInc; | |
948 | sizeHints.width_inc = incW; | |
949 | sizeHints.height_inc = incH; | |
950 | } | |
951 | ||
952 | XSetWMNormalHints(wxGlobalDisplay(), (Window) m_mainWindow, &sizeHints ); | |
953 | #endif | |
954 | } | |
955 | ||
956 | // --------------------------------------------------------------------------- | |
957 | // text metrics | |
958 | // --------------------------------------------------------------------------- | |
959 | ||
960 | int wxWindowX11::GetCharHeight() const | |
961 | { | |
962 | wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" ); | |
963 | ||
964 | WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, wxGlobalDisplay()); | |
965 | ||
966 | int direction, ascent, descent; | |
967 | XCharStruct overall; | |
968 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
969 | &descent, &overall); | |
970 | ||
971 | // return (overall.ascent + overall.descent); | |
972 | return (ascent + descent); | |
973 | } | |
974 | ||
975 | int wxWindowX11::GetCharWidth() const | |
976 | { | |
977 | wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" ); | |
978 | ||
979 | WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, wxGlobalDisplay()); | |
980 | ||
981 | int direction, ascent, descent; | |
982 | XCharStruct overall; | |
983 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
984 | &descent, &overall); | |
985 | ||
986 | return overall.width; | |
987 | } | |
988 | ||
989 | void wxWindowX11::GetTextExtent(const wxString& string, | |
990 | int *x, int *y, | |
991 | int *descent, int *externalLeading, | |
992 | const wxFont *theFont) const | |
993 | { | |
994 | wxFont fontToUse = m_font; | |
995 | if (theFont) fontToUse = *theFont; | |
996 | ||
997 | wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") ); | |
998 | ||
999 | WXFontStructPtr pFontStruct = fontToUse.GetFontStruct(1.0, wxGlobalDisplay()); | |
1000 | ||
1001 | int direction, ascent, descent2; | |
1002 | XCharStruct overall; | |
1003 | int slen = string.Len(); | |
1004 | ||
1005 | #if 0 | |
1006 | if (use16) | |
1007 | XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction, | |
1008 | &ascent, &descent2, &overall); | |
1009 | #endif | |
1010 | ||
1011 | XTextExtents((XFontStruct*) pFontStruct, (char*) string.c_str(), slen, | |
1012 | &direction, &ascent, &descent2, &overall); | |
1013 | ||
1014 | if ( x ) | |
1015 | *x = (overall.width); | |
1016 | if ( y ) | |
1017 | *y = (ascent + descent2); | |
1018 | if (descent) | |
1019 | *descent = descent2; | |
1020 | if (externalLeading) | |
1021 | *externalLeading = 0; | |
1022 | ||
1023 | } | |
1024 | ||
1025 | // ---------------------------------------------------------------------------- | |
1026 | // painting | |
1027 | // ---------------------------------------------------------------------------- | |
1028 | ||
1029 | void wxWindowX11::Refresh(bool eraseBack, const wxRect *rect) | |
1030 | { | |
1031 | if (eraseBack) | |
1032 | { | |
1033 | if (rect) | |
1034 | { | |
1035 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). | |
1036 | m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height ); | |
1037 | } | |
1038 | else | |
1039 | { | |
1040 | int height,width; | |
1041 | GetSize( &width, &height ); | |
1042 | ||
1043 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). | |
1044 | m_clearRegion.Clear(); | |
1045 | m_clearRegion.Union( 0, 0, width, height ); | |
1046 | } | |
1047 | } | |
1048 | ||
1049 | if (rect) | |
1050 | { | |
1051 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). | |
1052 | m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height ); | |
1053 | } | |
1054 | else | |
1055 | { | |
1056 | int height,width; | |
1057 | GetSize( &width, &height ); | |
1058 | ||
1059 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). | |
1060 | m_updateRegion.Clear(); | |
1061 | m_updateRegion.Union( 0, 0, width, height ); | |
1062 | } | |
1063 | } | |
1064 | ||
1065 | void wxWindowX11::Update() | |
1066 | { | |
1067 | if (m_updateNcArea) | |
1068 | { | |
1069 | // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName()); | |
1070 | // Send nc paint events. | |
1071 | SendNcPaintEvents(); | |
1072 | } | |
1073 | ||
1074 | if (!m_updateRegion.IsEmpty()) | |
1075 | { | |
1076 | // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName()); | |
1077 | // Actually send erase events. | |
1078 | SendEraseEvents(); | |
1079 | ||
1080 | // Actually send paint events. | |
1081 | SendPaintEvents(); | |
1082 | } | |
1083 | } | |
1084 | ||
1085 | void wxWindowX11::Clear() | |
1086 | { | |
1087 | // wxClientDC dc((wxWindow*) this); | |
1088 | // wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1089 | // dc.SetBackground(brush); | |
1090 | // dc.Clear(); | |
1091 | } | |
1092 | ||
1093 | void wxWindowX11::SendEraseEvents() | |
1094 | { | |
1095 | if (m_clearRegion.IsEmpty()) return; | |
1096 | ||
1097 | wxClientDC dc( (wxWindow*)this ); | |
1098 | dc.SetClippingRegion( m_clearRegion ); | |
1099 | ||
1100 | wxEraseEvent erase_event( GetId(), &dc ); | |
1101 | erase_event.SetEventObject( this ); | |
1102 | ||
1103 | if (!GetEventHandler()->ProcessEvent(erase_event) ) | |
1104 | { | |
1105 | Display *xdisplay = wxGlobalDisplay(); | |
1106 | Window xwindow = (Window) GetClientWindow(); | |
1107 | XSetForeground( xdisplay, g_eraseGC, m_backgroundColour.GetPixel() ); | |
1108 | ||
1109 | wxRegionIterator upd( m_clearRegion ); | |
1110 | while (upd) | |
1111 | { | |
1112 | XFillRectangle( xdisplay, xwindow, g_eraseGC, | |
1113 | upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() ); | |
1114 | upd ++; | |
1115 | } | |
1116 | } | |
1117 | ||
1118 | m_clearRegion.Clear(); | |
1119 | } | |
1120 | ||
1121 | void wxWindowX11::SendPaintEvents() | |
1122 | { | |
1123 | // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId()); | |
1124 | ||
1125 | m_clipPaintRegion = TRUE; | |
1126 | ||
1127 | wxPaintEvent paint_event( GetId() ); | |
1128 | paint_event.SetEventObject( this ); | |
1129 | GetEventHandler()->ProcessEvent( paint_event ); | |
1130 | ||
1131 | m_updateRegion.Clear(); | |
1132 | ||
1133 | m_clipPaintRegion = FALSE; | |
1134 | } | |
1135 | ||
1136 | void wxWindowX11::SendNcPaintEvents() | |
1137 | { | |
1138 | wxNcPaintEvent nc_paint_event( GetId() ); | |
1139 | nc_paint_event.SetEventObject( this ); | |
1140 | GetEventHandler()->ProcessEvent( nc_paint_event ); | |
1141 | ||
1142 | m_updateNcArea = FALSE; | |
1143 | } | |
1144 | ||
1145 | // ---------------------------------------------------------------------------- | |
1146 | // event handlers | |
1147 | // ---------------------------------------------------------------------------- | |
1148 | ||
1149 | // Responds to colour changes: passes event on to children. | |
1150 | void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event) | |
1151 | { | |
1152 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1153 | while ( node ) | |
1154 | { | |
1155 | // Only propagate to non-top-level windows | |
1156 | wxWindow *win = node->GetData(); | |
1157 | if ( win->GetParent() ) | |
1158 | { | |
1159 | wxSysColourChangedEvent event2; | |
1160 | event.m_eventObject = win; | |
1161 | win->GetEventHandler()->ProcessEvent(event2); | |
1162 | } | |
1163 | ||
1164 | node = node->GetNext(); | |
1165 | } | |
1166 | } | |
1167 | ||
1168 | void wxWindowX11::OnInternalIdle() | |
1169 | { | |
1170 | // Update invalidated regions. | |
1171 | Update(); | |
1172 | ||
1173 | // This calls the UI-update mechanism (querying windows for | |
1174 | // menu/toolbar/control state information) | |
1175 | UpdateWindowUI(); | |
1176 | ||
1177 | // Set the input focus if couldn't do it before | |
1178 | if (m_needsInputFocus) | |
1179 | { | |
1180 | SetFocus(); | |
1181 | } | |
1182 | } | |
1183 | ||
1184 | // ---------------------------------------------------------------------------- | |
1185 | // function which maintain the global hash table mapping Widgets to wxWindows | |
1186 | // ---------------------------------------------------------------------------- | |
1187 | ||
1188 | bool wxAddWindowToTable(Window w, wxWindow *win) | |
1189 | { | |
1190 | wxWindow *oldItem = NULL; | |
1191 | if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w))) | |
1192 | { | |
1193 | wxLogDebug("Widget table clash: new widget is %ld, %s", | |
1194 | (long)w, win->GetClassInfo()->GetClassName()); | |
1195 | return FALSE; | |
1196 | } | |
1197 | ||
1198 | wxWidgetHashTable->Put((long) w, win); | |
1199 | ||
1200 | wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)", | |
1201 | w, win, win->GetClassInfo()->GetClassName()); | |
1202 | ||
1203 | return TRUE; | |
1204 | } | |
1205 | ||
1206 | wxWindow *wxGetWindowFromTable(Window w) | |
1207 | { | |
1208 | return (wxWindow *)wxWidgetHashTable->Get((long) w); | |
1209 | } | |
1210 | ||
1211 | void wxDeleteWindowFromTable(Window w) | |
1212 | { | |
1213 | wxWidgetHashTable->Delete((long)w); | |
1214 | } | |
1215 | ||
1216 | // ---------------------------------------------------------------------------- | |
1217 | // function which maintain the global hash table mapping client widgets | |
1218 | // ---------------------------------------------------------------------------- | |
1219 | ||
1220 | bool wxAddClientWindowToTable(Window w, wxWindow *win) | |
1221 | { | |
1222 | wxWindow *oldItem = NULL; | |
1223 | if ((oldItem = (wxWindow *)wxClientWidgetHashTable->Get ((long) w))) | |
1224 | { | |
1225 | wxLogDebug("Client window table clash: new window is %ld, %s", | |
1226 | (long)w, win->GetClassInfo()->GetClassName()); | |
1227 | return FALSE; | |
1228 | } | |
1229 | ||
1230 | wxClientWidgetHashTable->Put((long) w, win); | |
1231 | ||
1232 | wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)", | |
1233 | w, win, win->GetClassInfo()->GetClassName()); | |
1234 | ||
1235 | return TRUE; | |
1236 | } | |
1237 | ||
1238 | wxWindow *wxGetClientWindowFromTable(Window w) | |
1239 | { | |
1240 | return (wxWindow *)wxClientWidgetHashTable->Get((long) w); | |
1241 | } | |
1242 | ||
1243 | void wxDeleteClientWindowFromTable(Window w) | |
1244 | { | |
1245 | wxClientWidgetHashTable->Delete((long)w); | |
1246 | } | |
1247 | ||
1248 | // ---------------------------------------------------------------------------- | |
1249 | // add/remove window from the table | |
1250 | // ---------------------------------------------------------------------------- | |
1251 | ||
1252 | // ---------------------------------------------------------------------------- | |
1253 | // X11-specific accessors | |
1254 | // ---------------------------------------------------------------------------- | |
1255 | ||
1256 | WXWindow wxWindowX11::GetMainWindow() const | |
1257 | { | |
1258 | return m_mainWindow; | |
1259 | } | |
1260 | ||
1261 | WXWindow wxWindowX11::GetClientWindow() const | |
1262 | { | |
1263 | return m_clientWindow; | |
1264 | } | |
1265 | ||
1266 | // ---------------------------------------------------------------------------- | |
1267 | // TranslateXXXEvent() functions | |
1268 | // ---------------------------------------------------------------------------- | |
1269 | ||
1270 | bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Window window, XEvent *xevent) | |
1271 | { | |
1272 | switch (XEventGetType(xevent)) | |
1273 | { | |
1274 | case EnterNotify: | |
1275 | case LeaveNotify: | |
1276 | case ButtonPress: | |
1277 | case ButtonRelease: | |
1278 | case MotionNotify: | |
1279 | { | |
1280 | wxEventType eventType = wxEVT_NULL; | |
1281 | ||
1282 | if (XEventGetType(xevent) == EnterNotify) | |
1283 | { | |
1284 | //if (local_event.xcrossing.mode!=NotifyNormal) | |
1285 | // return ; // Ignore grab events | |
1286 | eventType = wxEVT_ENTER_WINDOW; | |
1287 | // canvas->GetEventHandler()->OnSetFocus(); | |
1288 | } | |
1289 | else if (XEventGetType(xevent) == LeaveNotify) | |
1290 | { | |
1291 | //if (local_event.xcrossingr.mode!=NotifyNormal) | |
1292 | // return ; // Ignore grab events | |
1293 | eventType = wxEVT_LEAVE_WINDOW; | |
1294 | // canvas->GetEventHandler()->OnKillFocus(); | |
1295 | } | |
1296 | else if (XEventGetType(xevent) == MotionNotify) | |
1297 | { | |
1298 | eventType = wxEVT_MOTION; | |
1299 | } | |
1300 | else if (XEventGetType(xevent) == ButtonPress) | |
1301 | { | |
1302 | wxevent.SetTimestamp(XButtonEventGetTime(xevent)); | |
1303 | int button = 0; | |
1304 | if (XButtonEventLChanged(xevent)) | |
1305 | { | |
1306 | eventType = wxEVT_LEFT_DOWN; | |
1307 | button = 1; | |
1308 | } | |
1309 | else if (XButtonEventMChanged(xevent)) | |
1310 | { | |
1311 | eventType = wxEVT_MIDDLE_DOWN; | |
1312 | button = 2; | |
1313 | } | |
1314 | else if (XButtonEventRChanged(xevent)) | |
1315 | { | |
1316 | eventType = wxEVT_RIGHT_DOWN; | |
1317 | button = 3; | |
1318 | } | |
1319 | ||
1320 | // check for a double click | |
1321 | // TODO: where can we get this value from? | |
1322 | //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay()); | |
1323 | long dclickTime = 200; | |
1324 | long ts = wxevent.GetTimestamp(); | |
1325 | ||
1326 | int buttonLast = win->GetLastClickedButton(); | |
1327 | long lastTS = win->GetLastClickTime(); | |
1328 | if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime ) | |
1329 | { | |
1330 | // I have a dclick | |
1331 | win->SetLastClick(0, ts); | |
1332 | if ( eventType == wxEVT_LEFT_DOWN ) | |
1333 | eventType = wxEVT_LEFT_DCLICK; | |
1334 | else if ( eventType == wxEVT_MIDDLE_DOWN ) | |
1335 | eventType = wxEVT_MIDDLE_DCLICK; | |
1336 | else if ( eventType == wxEVT_RIGHT_DOWN ) | |
1337 | eventType = wxEVT_RIGHT_DCLICK; | |
1338 | } | |
1339 | else | |
1340 | { | |
1341 | // not fast enough or different button | |
1342 | win->SetLastClick(button, ts); | |
1343 | } | |
1344 | } | |
1345 | else if (XEventGetType(xevent) == ButtonRelease) | |
1346 | { | |
1347 | if (XButtonEventLChanged(xevent)) | |
1348 | { | |
1349 | eventType = wxEVT_LEFT_UP; | |
1350 | } | |
1351 | else if (XButtonEventMChanged(xevent)) | |
1352 | { | |
1353 | eventType = wxEVT_MIDDLE_UP; | |
1354 | } | |
1355 | else if (XButtonEventRChanged(xevent)) | |
1356 | { | |
1357 | eventType = wxEVT_RIGHT_UP; | |
1358 | } | |
1359 | else return FALSE; | |
1360 | } | |
1361 | else | |
1362 | { | |
1363 | return FALSE; | |
1364 | } | |
1365 | ||
1366 | wxevent.SetEventType(eventType); | |
1367 | ||
1368 | wxevent.m_x = XButtonEventGetX(xevent); | |
1369 | wxevent.m_y = XButtonEventGetY(xevent); | |
1370 | ||
1371 | wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN) | |
1372 | || (XButtonEventLIsDown(xevent) | |
1373 | && (eventType != wxEVT_LEFT_UP))); | |
1374 | wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN) | |
1375 | || (XButtonEventMIsDown(xevent) | |
1376 | && (eventType != wxEVT_MIDDLE_UP))); | |
1377 | wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN) | |
1378 | || (XButtonEventRIsDown (xevent) | |
1379 | && (eventType != wxEVT_RIGHT_UP))); | |
1380 | ||
1381 | wxevent.m_shiftDown = XButtonEventShiftIsDown(xevent); | |
1382 | wxevent.m_controlDown = XButtonEventCtrlIsDown(xevent); | |
1383 | wxevent.m_altDown = XButtonEventAltIsDown(xevent); | |
1384 | wxevent.m_metaDown = XButtonEventMetaIsDown(xevent); | |
1385 | ||
1386 | wxevent.SetId(win->GetId()); | |
1387 | wxevent.SetEventObject(win); | |
1388 | ||
1389 | return TRUE; | |
1390 | } | |
1391 | } | |
1392 | return FALSE; | |
1393 | } | |
1394 | ||
1395 | bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Window WXUNUSED(win), XEvent *xevent) | |
1396 | { | |
1397 | switch (XEventGetType(xevent)) | |
1398 | { | |
1399 | case KeyPress: | |
1400 | case KeyRelease: | |
1401 | { | |
1402 | char buf[20]; | |
1403 | ||
1404 | KeySym keySym; | |
1405 | (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL); | |
1406 | int id = wxCharCodeXToWX (keySym); | |
1407 | ||
1408 | wxevent.m_shiftDown = XKeyEventShiftIsDown(xevent); | |
1409 | wxevent.m_controlDown = XKeyEventCtrlIsDown(xevent); | |
1410 | wxevent.m_altDown = XKeyEventAltIsDown(xevent); | |
1411 | wxevent.m_metaDown = XKeyEventMetaIsDown(xevent); | |
1412 | wxevent.SetEventObject(win); | |
1413 | wxevent.m_keyCode = id; | |
1414 | wxevent.SetTimestamp(XKeyEventGetTime(xevent)); | |
1415 | ||
1416 | wxevent.m_x = XKeyEventGetX(xevent); | |
1417 | wxevent.m_y = XKeyEventGetY(xevent); | |
1418 | ||
1419 | if (id > -1) | |
1420 | return TRUE; | |
1421 | else | |
1422 | return FALSE; | |
1423 | break; | |
1424 | } | |
1425 | default: | |
1426 | break; | |
1427 | } | |
1428 | return FALSE; | |
1429 | } | |
1430 | ||
1431 | // ---------------------------------------------------------------------------- | |
1432 | // Colour stuff | |
1433 | // ---------------------------------------------------------------------------- | |
1434 | ||
1435 | bool wxWindowX11::SetBackgroundColour(const wxColour& col) | |
1436 | { | |
1437 | wxWindowBase::SetBackgroundColour(col); | |
1438 | ||
1439 | Display *xdisplay = (Display*) wxGlobalDisplay(); | |
1440 | int xscreen = DefaultScreen( xdisplay ); | |
1441 | Colormap cm = DefaultColormap( xdisplay, xscreen ); | |
1442 | ||
1443 | m_backgroundColour.CalcPixel( (WXColormap) cm ); | |
1444 | ||
1445 | // We don't set the background colour as we paint | |
1446 | // the background ourselves. | |
1447 | // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() ); | |
1448 | ||
1449 | return TRUE; | |
1450 | } | |
1451 | ||
1452 | bool wxWindowX11::SetForegroundColour(const wxColour& col) | |
1453 | { | |
1454 | if ( !wxWindowBase::SetForegroundColour(col) ) | |
1455 | return FALSE; | |
1456 | ||
1457 | return TRUE; | |
1458 | } | |
1459 | ||
1460 | // ---------------------------------------------------------------------------- | |
1461 | // global functions | |
1462 | // ---------------------------------------------------------------------------- | |
1463 | ||
1464 | wxWindow *wxGetActiveWindow() | |
1465 | { | |
1466 | // TODO | |
1467 | wxFAIL_MSG("Not implemented"); | |
1468 | return NULL; | |
1469 | } | |
1470 | ||
1471 | /* static */ | |
1472 | wxWindow *wxWindowBase::GetCapture() | |
1473 | { | |
1474 | return (wxWindow *)g_captureWindow; | |
1475 | } | |
1476 | ||
1477 | ||
1478 | // Find the wxWindow at the current mouse position, returning the mouse | |
1479 | // position. | |
1480 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) | |
1481 | { | |
1482 | return wxFindWindowAtPoint(wxGetMousePosition()); | |
1483 | } | |
1484 | ||
1485 | // Get the current mouse position. | |
1486 | wxPoint wxGetMousePosition() | |
1487 | { | |
1488 | #if wxUSE_NANOX | |
1489 | /* TODO */ | |
1490 | return wxPoint(0, 0); | |
1491 | #else | |
1492 | Display *display = wxGlobalDisplay(); | |
1493 | Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display)); | |
1494 | Window rootReturn, childReturn; | |
1495 | int rootX, rootY, winX, winY; | |
1496 | unsigned int maskReturn; | |
1497 | ||
1498 | XQueryPointer (display, | |
1499 | rootWindow, | |
1500 | &rootReturn, | |
1501 | &childReturn, | |
1502 | &rootX, &rootY, &winX, &winY, &maskReturn); | |
1503 | return wxPoint(rootX, rootY); | |
1504 | #endif | |
1505 | } | |
1506 | ||
1507 | ||
1508 | // ---------------------------------------------------------------------------- | |
1509 | // wxNoOptimize: switch off size optimization | |
1510 | // ---------------------------------------------------------------------------- | |
1511 | ||
1512 | int wxNoOptimize::ms_count = 0; | |
1513 | ||
1514 | ||
1515 | // ---------------------------------------------------------------------------- | |
1516 | // wxDCModule | |
1517 | // ---------------------------------------------------------------------------- | |
1518 | ||
1519 | class wxWinModule : public wxModule | |
1520 | { | |
1521 | public: | |
1522 | bool OnInit(); | |
1523 | void OnExit(); | |
1524 | ||
1525 | private: | |
1526 | DECLARE_DYNAMIC_CLASS(wxWinModule) | |
1527 | }; | |
1528 | ||
1529 | IMPLEMENT_DYNAMIC_CLASS(wxWinModule, wxModule) | |
1530 | ||
1531 | bool wxWinModule::OnInit() | |
1532 | { | |
1533 | Display *xdisplay = wxGlobalDisplay(); | |
1534 | int xscreen = DefaultScreen( xdisplay ); | |
1535 | Window xroot = RootWindow( xdisplay, xscreen ); | |
1536 | g_eraseGC = XCreateGC( xdisplay, xroot, 0, NULL ); | |
1537 | XSetFillStyle( xdisplay, g_eraseGC, FillSolid ); | |
1538 | ||
1539 | return TRUE; | |
1540 | } | |
1541 | ||
1542 | void wxWinModule::OnExit() | |
1543 | { | |
1544 | Display *xdisplay = wxGlobalDisplay(); | |
1545 | XFreeGC( xdisplay, g_eraseGC ); | |
1546 | } | |
1547 | ||
1548 |