]> git.saurik.com Git - wxWidgets.git/blame - src/x11/window.cpp
A bit of scrolling works under GTK 2.0
[wxWidgets.git] / src / x11 / window.cpp
CommitLineData
83df96d6
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: windows.cpp
3// Purpose: wxWindow
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "window.h"
22#endif
23
83df96d6
JS
24#include "wx/setup.h"
25#include "wx/menu.h"
26#include "wx/dc.h"
27#include "wx/dcclient.h"
28#include "wx/utils.h"
29#include "wx/app.h"
30#include "wx/panel.h"
31#include "wx/layout.h"
32#include "wx/dialog.h"
33#include "wx/listbox.h"
34#include "wx/button.h"
35#include "wx/settings.h"
36#include "wx/msgdlg.h"
37#include "wx/frame.h"
38#include "wx/scrolwin.h"
ab6b6b15 39#include "wx/scrolbar.h"
83df96d6
JS
40#include "wx/module.h"
41#include "wx/menuitem.h"
42#include "wx/log.h"
43
44#if wxUSE_DRAG_AND_DROP
45 #include "wx/dnd.h"
46#endif
47
bc797f4c 48#include "wx/x11/private.h"
7266b672 49#include "X11/Xutil.h"
83df96d6 50
461e93f9
JS
51#if wxUSE_NANOX
52// For wxGetLocalTime, used by XButtonEventGetTime
53#include "wx/timer.h"
54#endif
55
83df96d6
JS
56#include <string.h>
57
83df96d6
JS
58// ----------------------------------------------------------------------------
59// global variables for this module
60// ----------------------------------------------------------------------------
61
62extern wxHashTable *wxWidgetHashTable;
ab6b6b15 63extern wxHashTable *wxClientWidgetHashTable;
83df96d6 64static wxWindow* g_captureWindow = NULL;
c2c0dabf 65static GC g_eraseGC;
83df96d6 66
83df96d6
JS
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
8354aa92 79IMPLEMENT_ABSTRACT_CLASS(wxWindowX11, wxWindowBase)
83df96d6 80
bc797f4c
JS
81BEGIN_EVENT_TABLE(wxWindowX11, wxWindowBase)
82 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged)
bc797f4c 83END_EVENT_TABLE()
83df96d6
JS
84
85// ============================================================================
86// implementation
87// ============================================================================
88
89// ----------------------------------------------------------------------------
90// helper functions
91// ----------------------------------------------------------------------------
92
83df96d6
JS
93// ----------------------------------------------------------------------------
94// constructors
95// ----------------------------------------------------------------------------
96
bc797f4c 97void wxWindowX11::Init()
83df96d6
JS
98{
99 // generic initializations first
100 InitBase();
101
7266b672 102 // X11-specific
ab6b6b15
RR
103 m_mainWindow = (WXWindow) 0;
104 m_clientWindow = (WXWindow) 0;
105 m_insertIntoMain = FALSE;
065722d7 106 m_updateNcArea = FALSE;
ab6b6b15 107
83df96d6 108 m_winCaptured = FALSE;
3a0b23eb 109 m_needsInputFocus = FALSE;
83df96d6
JS
110 m_isShown = TRUE;
111 m_isBeingDeleted = FALSE;
83df96d6
JS
112 m_lastTS = 0;
113 m_lastButton = 0;
83df96d6
JS
114}
115
116// real construction (Init() must have been called before!)
bc797f4c 117bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
83df96d6
JS
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
3cd0b8c5 127 parent->AddChild(this);
83df96d6 128
b513212d
JS
129 int w = size.GetWidth();
130 int h = size.GetHeight();
131 int x = size.GetX();
132 int y = size.GetY();
178572bb
RR
133 if (w == -1) w = 20;
134 if (h == -1) h = 20;
b513212d
JS
135 if (x == -1) x = 0;
136 if (y == -1) y = 0;
83df96d6 137
3cd0b8c5
RR
138 Display *xdisplay = (Display*) wxGlobalDisplay();
139 int xscreen = DefaultScreen( xdisplay );
7e4501ee 140 Visual *xvisual = DefaultVisual( xdisplay, xscreen );
3cd0b8c5 141 Colormap cm = DefaultColormap( xdisplay, xscreen );
b513212d 142
3cd0b8c5
RR
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 );
3cd0b8c5 148
ab6b6b15
RR
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 }
2f12683e
RR
157
158 wxSize size2(size);
159 if (size2.x == -1)
160 size2.x = 20;
161 if (size2.y == -1)
162 size2.y = 20;
b513212d 163
2f12683e
RR
164 wxPoint pos2(pos);
165 if (pos2.x == -1)
166 pos2.x = 0;
167 if (pos2.y == -1)
168 pos2.y = 0;
169
461e93f9 170#if !wxUSE_NANOX
ab6b6b15
RR
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
7e4501ee 179 XSetWindowAttributes xattributes;
ab6b6b15 180 long xattributes_mask = 0;
7e4501ee 181
ab6b6b15 182 xattributes_mask |= CWBackPixel;
7e4501ee 183 xattributes.background_pixel = m_backgroundColour.GetPixel();
ab6b6b15
RR
184
185 xattributes_mask |= CWBorderPixel;
7e4501ee
RR
186 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
187
2f12683e 188 xattributes_mask |= CWEventMask;
ab6b6b15
RR
189
190 if (need_two_windows)
2f12683e 191 {
ab6b6b15
RR
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
065722d7
RR
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,
ab6b6b15
RR
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 );
2f12683e 245 }
ab6b6b15
RR
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 ;
2f12683e 255
ab6b6b15
RR
256 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE ))
257 {
258 xattributes_mask |= CWBitGravity;
065722d7 259 xattributes.bit_gravity = NorthWestGravity;
ab6b6b15
RR
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 }
2f12683e 273#else
15c69343 274
461e93f9
JS
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 );
461e93f9 288
ab6b6b15
RR
289 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
290
291 m_mainWindow = (WXWindow) xwindow;
ba696cfa 292 wxAddWindowToTable( xwindow, (wxWindow*) this );
ab6b6b15
RR
293
294 XMapWindow( xdisplay, xwindow );
295#endif
b513212d 296
b28d3abf
JS
297 // Is a subwindow, so map immediately
298 m_isShown = TRUE;
83df96d6
JS
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));
15c69343
JS
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);
83df96d6
JS
308
309 return TRUE;
310}
311
312// Destructor
7266b672 313wxWindowX11::~wxWindowX11()
83df96d6
JS
314{
315 if (g_captureWindow == this)
316 g_captureWindow = NULL;
317
318 m_isBeingDeleted = TRUE;
319
d02cb44e 320 if (m_parent)
83df96d6
JS
321 m_parent->RemoveChild( this );
322
d02cb44e 323 DestroyChildren();
83df96d6 324
ab6b6b15 325 if (m_clientWindow != m_mainWindow)
83df96d6 326 {
ab6b6b15
RR
327 // Destroy the cleint window
328 Window xwindow = (Window) m_clientWindow;
329 wxDeleteClientWindowFromTable( xwindow );
7e4501ee 330 XDestroyWindow( wxGlobalDisplay(), xwindow );
ab6b6b15 331 m_clientWindow = NULL;
83df96d6 332 }
ab6b6b15
RR
333
334 // Destroy the window
335 Window xwindow = (Window) m_mainWindow;
336 wxDeleteWindowFromTable( xwindow );
337 XDestroyWindow( wxGlobalDisplay(), xwindow );
338 m_mainWindow = NULL;
83df96d6
JS
339}
340
341// ---------------------------------------------------------------------------
342// basic operations
343// ---------------------------------------------------------------------------
344
bc797f4c 345void wxWindowX11::SetFocus()
83df96d6 346{
ab6b6b15 347 Window xwindow = (Window) m_clientWindow;
86fd8bda
RR
348
349 wxCHECK_RET( xwindow, wxT("invalid window") );
9b8270da
RR
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
3a0b23eb
JS
361 if (wxWindowIsVisible(xwindow))
362 {
79ad56d0 363 XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
ba696cfa 364 m_needsInputFocus = FALSE;
3a0b23eb
JS
365 }
366 else
367 {
ba696cfa 368 m_needsInputFocus = TRUE;
3a0b23eb 369 }
83df96d6
JS
370}
371
372// Get the window with the focus
373wxWindow *wxWindowBase::FindFocus()
374{
86fd8bda 375 Window xfocus = (Window) 0;
b513212d 376 int revert = 0;
bc797f4c 377
86fd8bda
RR
378 XGetInputFocus( wxGlobalDisplay(), &xfocus, &revert);
379 if (xfocus)
83df96d6 380 {
86fd8bda 381 wxWindow *win = wxGetWindowFromTable( xfocus );
288efe84
JS
382 if (!win)
383 {
384 win = wxGetClientWindowFromTable( xfocus );
385 }
b513212d
JS
386
387 return win;
83df96d6
JS
388 }
389
b513212d 390 return NULL;
83df96d6
JS
391}
392
b513212d
JS
393// Enabling/disabling handled by event loop, and not sending events
394// if disabled.
bc797f4c 395bool wxWindowX11::Enable(bool enable)
83df96d6
JS
396{
397 if ( !wxWindowBase::Enable(enable) )
398 return FALSE;
b513212d 399
83df96d6
JS
400 return TRUE;
401}
402
bc797f4c 403bool wxWindowX11::Show(bool show)
83df96d6 404{
7edcafa4 405 wxWindowBase::Show(show);
83df96d6 406
ab6b6b15
RR
407 Window xwindow = (Window) m_mainWindow;
408 Display *xdisp = wxGlobalDisplay();
83df96d6 409 if (show)
b513212d 410 {
7e4501ee 411 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
ab6b6b15 412 XMapWindow(xdisp, xwindow);
b513212d 413 }
83df96d6 414 else
b513212d 415 {
7e4501ee 416 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
ab6b6b15 417 XUnmapWindow(xdisp, xwindow);
b513212d 418 }
83df96d6
JS
419
420 return TRUE;
421}
422
423// Raise the window to the top of the Z order
bc797f4c 424void wxWindowX11::Raise()
83df96d6 425{
ab6b6b15
RR
426 if (m_mainWindow)
427 XRaiseWindow( wxGlobalDisplay(), (Window) m_mainWindow );
83df96d6
JS
428}
429
430// Lower the window to the bottom of the Z order
bc797f4c 431void wxWindowX11::Lower()
83df96d6 432{
ab6b6b15
RR
433 if (m_mainWindow)
434 XLowerWindow( wxGlobalDisplay(), (Window) m_mainWindow );
83df96d6
JS
435}
436
bc797f4c 437void wxWindowX11::DoCaptureMouse()
83df96d6 438{
7edcafa4
JS
439 if ((g_captureWindow != NULL) && (g_captureWindow != this))
440 {
346d4fcd 441 wxASSERT_MSG(FALSE, "Trying to capture before mouse released.");
7edcafa4 442
346d4fcd
RR
443 // Core dump now
444 int *tmp = NULL;
445 (*tmp) = 1;
446 return;
7edcafa4
JS
447 }
448
346d4fcd 449 if (m_winCaptured)
83df96d6
JS
450 return;
451
ab6b6b15 452 Window xwindow = (Window) m_clientWindow;
346d4fcd 453
86fd8bda
RR
454 wxCHECK_RET( xwindow, wxT("invalid window") );
455
7edcafa4
JS
456 g_captureWindow = (wxWindow*) this;
457
346d4fcd 458 if (xwindow)
b513212d 459 {
346d4fcd 460 int res = XGrabPointer(wxGlobalDisplay(), xwindow,
b513212d
JS
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
346d4fcd 467 CurrentTime );
b513212d 468
b28d3abf 469 if (res != GrabSuccess)
b513212d 470 {
346d4fcd
RR
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;
b28d3abf 479 return;
b513212d 480 }
346d4fcd 481
b28d3abf 482 m_winCaptured = TRUE;
b513212d 483 }
83df96d6
JS
484}
485
bc797f4c 486void wxWindowX11::DoReleaseMouse()
83df96d6
JS
487{
488 g_captureWindow = NULL;
346d4fcd 489
83df96d6
JS
490 if ( !m_winCaptured )
491 return;
492
ab6b6b15 493 Window xwindow = (Window) m_clientWindow;
b513212d 494
346d4fcd 495 if (xwindow)
b28d3abf 496 {
346d4fcd 497 XUngrabPointer( wxGlobalDisplay(), CurrentTime );
b28d3abf 498 }
887dd52f 499
9691c806 500 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
83df96d6
JS
501
502 m_winCaptured = FALSE;
503}
504
bc797f4c 505bool wxWindowX11::SetFont(const wxFont& font)
83df96d6
JS
506{
507 if ( !wxWindowBase::SetFont(font) )
508 {
509 // nothing to do
510 return FALSE;
511 }
512
83df96d6
JS
513 return TRUE;
514}
515
bc797f4c 516bool wxWindowX11::SetCursor(const wxCursor& cursor)
83df96d6
JS
517{
518 if ( !wxWindowBase::SetCursor(cursor) )
519 {
520 // no change
521 return FALSE;
522 }
523
ab6b6b15 524 Window xwindow = (Window) m_clientWindow;
86fd8bda
RR
525
526 wxCHECK_MSG( xwindow, FALSE, wxT("invalid window") );
527
528 wxCursor cursorToUse;
83df96d6 529 if (m_cursor.Ok())
86fd8bda 530 cursorToUse = m_cursor;
83df96d6 531 else
86fd8bda 532 cursorToUse = *wxSTANDARD_CURSOR;
83df96d6 533
86fd8bda 534 Cursor xcursor = (Cursor) cursorToUse.GetCursor();
83df96d6 535
e88be8c9 536 XDefineCursor( wxGlobalDisplay(), xwindow, xcursor );
83df96d6
JS
537
538 return TRUE;
539}
540
541// Coordinates relative to the window
bc797f4c 542void wxWindowX11::WarpPointer (int x, int y)
83df96d6 543{
ab6b6b15 544 Window xwindow = (Window) m_clientWindow;
86fd8bda
RR
545
546 wxCHECK_RET( xwindow, wxT("invalid window") );
547
548 XWarpPointer( wxGlobalDisplay(), None, xwindow, 0, 0, 0, 0, x, y);
83df96d6
JS
549}
550
83df96d6 551// Does a physical scroll
bc797f4c 552void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect)
83df96d6 553{
fc9be1cf
RR
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
ab6b6b15 577 Window xwindow = (Window) GetClientWindow();
7e085304
RR
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
e88be8c9
RR
586 int s_x = 0;
587 int s_y = 0;
4125131b
RR
588 int cw;
589 int ch;
590 if (rect)
591 {
592 s_x = rect->x;
593 s_y = rect->y;
e88be8c9 594
4125131b
RR
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
ab6b6b15
RR
605#if wxUSE_TWO_WINDOWS
606 wxPoint offset( 0,0 );
607#else
4125131b
RR
608 wxPoint offset = GetClientAreaOrigin();
609 s_x += offset.x;
610 s_y += offset.y;
ab6b6b15 611#endif
e88be8c9 612
7e085304
RR
613 int w = cw - abs(dx);
614 int h = ch - abs(dy);
4125131b 615
7e085304 616 if ((h < 0) || (w < 0))
83df96d6 617 {
7e085304 618 Refresh();
83df96d6
JS
619 }
620 else
621 {
4125131b 622 wxRect rect;
f809133f
RR
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;
4125131b
RR
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;
e88be8c9 630
4125131b
RR
631 if (dx < 0) s_x += -dx;
632 if (dy < 0) s_y += -dy;
e88be8c9
RR
633 if (dx > 0) d_x = dx + offset.x;
634 if (dy > 0) d_y = dy + offset.y;
7e085304
RR
635
636 XCopyArea( xdisplay, xwindow, xwindow, xgc, s_x, s_y, w, h, d_x, d_y );
4125131b 637
e88be8c9 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 );
7e085304 639
e88be8c9 640 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
7e085304
RR
641
642 m_updateRegion.Union( rect );
643 m_clearRegion.Union( rect );
83df96d6 644 }
bc797f4c 645
7e085304 646 XFreeGC( xdisplay, xgc );
83df96d6
JS
647}
648
649// ---------------------------------------------------------------------------
650// drag and drop
651// ---------------------------------------------------------------------------
652
653#if wxUSE_DRAG_AND_DROP
654
bc797f4c 655void wxWindowX11::SetDropTarget(wxDropTarget * WXUNUSED(pDropTarget))
83df96d6
JS
656{
657 // TODO
658}
659
660#endif
661
662// Old style file-manager drag&drop
bc797f4c 663void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept))
83df96d6
JS
664{
665 // TODO
666}
667
668// ----------------------------------------------------------------------------
669// tooltips
670// ----------------------------------------------------------------------------
671
672#if wxUSE_TOOLTIPS
673
bc797f4c 674void wxWindowX11::DoSetToolTip(wxToolTip * WXUNUSED(tooltip))
83df96d6
JS
675{
676 // TODO
677}
678
679#endif // wxUSE_TOOLTIPS
680
83df96d6
JS
681// ---------------------------------------------------------------------------
682// moving and resizing
683// ---------------------------------------------------------------------------
684
bc797f4c 685bool wxWindowX11::PreResize()
83df96d6
JS
686{
687 return TRUE;
688}
689
690// Get total size
bc797f4c 691void wxWindowX11::DoGetSize(int *x, int *y) const
83df96d6 692{
ab6b6b15 693 Window xwindow = (Window) m_mainWindow;
86fd8bda
RR
694
695 wxCHECK_RET( xwindow, wxT("invalid window") );
696
59db9cfa 697 //XSync(wxGlobalDisplay(), False);
e941874b 698
86fd8bda
RR
699 XWindowAttributes attr;
700 Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr );
701 wxASSERT(status);
b513212d 702
86fd8bda
RR
703 if (status)
704 {
705 *x = attr.width /* + 2*m_borderSize */ ;
706 *y = attr.height /* + 2*m_borderSize */ ;
83df96d6 707 }
83df96d6
JS
708}
709
bc797f4c 710void wxWindowX11::DoGetPosition(int *x, int *y) const
83df96d6 711{
ab6b6b15 712 Window window = (Window) m_mainWindow;
b513212d 713 if (window)
83df96d6 714 {
59db9cfa 715 //XSync(wxGlobalDisplay(), False);
b513212d
JS
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 }
83df96d6 734 }
83df96d6
JS
735}
736
bc797f4c 737void wxWindowX11::DoScreenToClient(int *x, int *y) const
83df96d6 738{
b513212d 739 Display *display = wxGlobalDisplay();
bc797f4c 740 Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display));
ab6b6b15 741 Window thisWindow = (Window) m_clientWindow;
83df96d6
JS
742
743 Window childWindow;
744 int xx = *x;
745 int yy = *y;
746 XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow);
747}
748
bc797f4c 749void wxWindowX11::DoClientToScreen(int *x, int *y) const
83df96d6 750{
b513212d 751 Display *display = wxGlobalDisplay();
bc797f4c 752 Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display));
ab6b6b15 753 Window thisWindow = (Window) m_clientWindow;
83df96d6
JS
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.
bc797f4c 763void wxWindowX11::DoGetClientSize(int *x, int *y) const
83df96d6 764{
ab6b6b15 765 Window window = (Window) m_mainWindow;
b513212d
JS
766
767 if (window)
768 {
769 XWindowAttributes attr;
3cd0b8c5 770 Status status = XGetWindowAttributes( wxGlobalDisplay(), window, &attr );
b513212d
JS
771 wxASSERT(status);
772
773 if (status)
774 {
775 *x = attr.width ;
776 *y = attr.height ;
777 }
778 }
83df96d6
JS
779}
780
bc797f4c 781void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags)
83df96d6 782{
df0e1b64 783 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
ab6b6b15
RR
784
785 Window xwindow = (Window) m_mainWindow;
83df96d6 786
27398643
RR
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;
ab6b6b15 797
b513212d 798 if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
83df96d6 799 {
27398643 800 int yy = 0;
e5053ade 801 AdjustForParentClientOrigin( x, yy, sizeFlags);
27398643 802 new_x = x;
83df96d6 803 }
b513212d 804 if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
83df96d6 805 {
27398643 806 int xx = 0;
e5053ade 807 AdjustForParentClientOrigin( xx, y, sizeFlags);
27398643 808 new_y = y;
83df96d6 809 }
27398643 810 if (width != -1)
83df96d6 811 {
27398643
RR
812 new_w = width;
813 if (new_w <= 0)
814 new_w = 20;
83df96d6 815 }
27398643 816 if (height != -1)
b513212d 817 {
27398643
RR
818 new_h = height;
819 if (new_h <= 0)
820 new_h = 20;
b513212d 821 }
27398643
RR
822
823 DoMoveWindow( new_x, new_y, new_w, new_h );
83df96d6
JS
824}
825
bc797f4c 826void wxWindowX11::DoSetClientSize(int width, int height)
83df96d6 827{
df0e1b64 828 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
ab6b6b15
RR
829
830 Window xwindow = (Window) m_mainWindow;
83df96d6 831
27398643 832 wxCHECK_RET( xwindow, wxT("invalid window") );
83df96d6 833
2f12683e 834 XResizeWindow( wxGlobalDisplay(), xwindow, width, height );
df0e1b64 835
ab6b6b15
RR
836 if (m_mainWindow != m_clientWindow)
837 {
838 xwindow = (Window) m_clientWindow;
27398643 839
ab6b6b15
RR
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 }
27398643 850
ab6b6b15
RR
851 XResizeWindow( wxGlobalDisplay(), xwindow, width, height );
852 }
83df96d6
JS
853}
854
855// For implementation purposes - sometimes decorations make the client area
856// smaller
bc797f4c 857wxPoint wxWindowX11::GetClientAreaOrigin() const
83df96d6
JS
858{
859 return wxPoint(0, 0);
860}
861
ab6b6b15
RR
862void 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
288efe84 908 XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, wxMax(1, width), wxMax(1, height) );
ab6b6b15
RR
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
bc797f4c 926void wxWindowX11::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH)
83df96d6
JS
927{
928 m_minWidth = minW;
929 m_minHeight = minH;
930 m_maxWidth = maxW;
931 m_maxHeight = maxH;
932
461e93f9 933#if !wxUSE_NANOX
b513212d
JS
934 XSizeHints sizeHints;
935 sizeHints.flags = 0;
936
937 if (minW > -1 && minH > -1)
83df96d6 938 {
b513212d
JS
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;
83df96d6
JS
954 }
955
ab6b6b15 956 XSetWMNormalHints(wxGlobalDisplay(), (Window) m_mainWindow, &sizeHints );
2f12683e 957#endif
83df96d6
JS
958}
959
960// ---------------------------------------------------------------------------
961// text metrics
962// ---------------------------------------------------------------------------
963
bc797f4c 964int wxWindowX11::GetCharHeight() const
83df96d6
JS
965{
966 wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
967
ab6b6b15 968 WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, wxGlobalDisplay());
83df96d6
JS
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
bc797f4c 979int wxWindowX11::GetCharWidth() const
83df96d6
JS
980{
981 wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
982
ab6b6b15 983 WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, wxGlobalDisplay());
83df96d6
JS
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
bc797f4c 993void wxWindowX11::GetTextExtent(const wxString& string,
83df96d6
JS
994 int *x, int *y,
995 int *descent, int *externalLeading,
996 const wxFont *theFont) const
997{
0d1dff01
RR
998 wxFont fontToUse = m_font;
999 if (theFont) fontToUse = *theFont;
83df96d6 1000
0d1dff01
RR
1001 wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") );
1002
ab6b6b15 1003 WXFontStructPtr pFontStruct = fontToUse.GetFontStruct(1.0, wxGlobalDisplay());
83df96d6
JS
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
461e93f9 1015 XTextExtents((XFontStruct*) pFontStruct, (char*) string.c_str(), slen,
83df96d6
JS
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
bc797f4c 1033void wxWindowX11::Refresh(bool eraseBack, const wxRect *rect)
83df96d6 1034{
d02cb44e
RR
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 }
83df96d6 1052
83df96d6
JS
1053 if (rect)
1054 {
d02cb44e
RR
1055 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1056 m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height );
83df96d6
JS
1057 }
1058 else
1059 {
0d1dff01
RR
1060 int height,width;
1061 GetSize( &width, &height );
d02cb44e
RR
1062
1063 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1064 m_updateRegion.Clear();
1065 m_updateRegion.Union( 0, 0, width, height );
83df96d6 1066 }
d02cb44e 1067}
83df96d6 1068
d02cb44e
RR
1069void wxWindowX11::Update()
1070{
ab6b6b15
RR
1071 if (m_updateNcArea)
1072 {
065722d7 1073 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
ab6b6b15
RR
1074 // Send nc paint events.
1075 SendNcPaintEvents();
1076 }
1077
d02cb44e 1078 if (!m_updateRegion.IsEmpty())
83df96d6 1079 {
ab6b6b15 1080 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
887dd52f
RR
1081 // Actually send erase events.
1082 SendEraseEvents();
1083
1084 // Actually send paint events.
1085 SendPaintEvents();
83df96d6 1086 }
83df96d6
JS
1087}
1088
bc797f4c 1089void wxWindowX11::Clear()
83df96d6 1090{
ab6b6b15
RR
1091// wxClientDC dc((wxWindow*) this);
1092// wxBrush brush(GetBackgroundColour(), wxSOLID);
1093// dc.SetBackground(brush);
1094// dc.Clear();
83df96d6
JS
1095}
1096
887dd52f 1097void wxWindowX11::SendEraseEvents()
83df96d6 1098{
2f12683e
RR
1099 if (m_clearRegion.IsEmpty()) return;
1100
ab6b6b15 1101 wxClientDC dc( (wxWindow*)this );
2f12683e
RR
1102 dc.SetClippingRegion( m_clearRegion );
1103
1104 wxEraseEvent erase_event( GetId(), &dc );
1105 erase_event.SetEventObject( this );
0b5c0e1a 1106
c2c0dabf 1107 if (!GetEventHandler()->ProcessEvent(erase_event) )
2f12683e 1108 {
2f12683e 1109 Display *xdisplay = wxGlobalDisplay();
c2c0dabf
RR
1110 Window xwindow = (Window) GetClientWindow();
1111 XSetForeground( xdisplay, g_eraseGC, m_backgroundColour.GetPixel() );
1112
2f12683e
RR
1113 wxRegionIterator upd( m_clearRegion );
1114 while (upd)
1934d291 1115 {
c2c0dabf 1116 XFillRectangle( xdisplay, xwindow, g_eraseGC,
2f12683e
RR
1117 upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() );
1118 upd ++;
1934d291 1119 }
83df96d6 1120 }
2f12683e
RR
1121
1122 m_clearRegion.Clear();
887dd52f
RR
1123}
1124
887dd52f
RR
1125void wxWindowX11::SendPaintEvents()
1126{
df0e1b64
JS
1127 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1128
887dd52f 1129 m_clipPaintRegion = TRUE;
aae73669 1130
1934d291
RR
1131 wxPaintEvent paint_event( GetId() );
1132 paint_event.SetEventObject( this );
1133 GetEventHandler()->ProcessEvent( paint_event );
0d1dff01 1134
0b5c0e1a 1135 m_updateRegion.Clear();
2f12683e 1136
1934d291 1137 m_clipPaintRegion = FALSE;
83df96d6
JS
1138}
1139
ab6b6b15
RR
1140void wxWindowX11::SendNcPaintEvents()
1141{
1142 wxNcPaintEvent nc_paint_event( GetId() );
1143 nc_paint_event.SetEventObject( this );
1144 GetEventHandler()->ProcessEvent( nc_paint_event );
065722d7
RR
1145
1146 m_updateNcArea = FALSE;
ab6b6b15
RR
1147}
1148
83df96d6
JS
1149// ----------------------------------------------------------------------------
1150// event handlers
1151// ----------------------------------------------------------------------------
1152
1153// Responds to colour changes: passes event on to children.
bc797f4c 1154void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event)
83df96d6
JS
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
0d1dff01 1172void wxWindowX11::OnInternalIdle()
83df96d6 1173{
0d1dff01
RR
1174 // Update invalidated regions.
1175 Update();
1176
83df96d6
JS
1177 // This calls the UI-update mechanism (querying windows for
1178 // menu/toolbar/control state information)
1179 UpdateWindowUI();
3a0b23eb
JS
1180
1181 // Set the input focus if couldn't do it before
1182 if (m_needsInputFocus)
ff6b424a 1183 {
3a0b23eb 1184 SetFocus();
ff6b424a 1185 }
83df96d6
JS
1186}
1187
83df96d6
JS
1188// ----------------------------------------------------------------------------
1189// function which maintain the global hash table mapping Widgets to wxWindows
1190// ----------------------------------------------------------------------------
1191
bc797f4c 1192bool wxAddWindowToTable(Window w, wxWindow *win)
83df96d6
JS
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
bc797f4c 1204 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
83df96d6
JS
1205 w, win, win->GetClassInfo()->GetClassName());
1206
1207 return TRUE;
1208}
1209
bc797f4c 1210wxWindow *wxGetWindowFromTable(Window w)
83df96d6
JS
1211{
1212 return (wxWindow *)wxWidgetHashTable->Get((long) w);
1213}
1214
bc797f4c 1215void wxDeleteWindowFromTable(Window w)
83df96d6
JS
1216{
1217 wxWidgetHashTable->Delete((long)w);
1218}
1219
1220// ----------------------------------------------------------------------------
ab6b6b15 1221// function which maintain the global hash table mapping client widgets
83df96d6
JS
1222// ----------------------------------------------------------------------------
1223
ab6b6b15
RR
1224bool 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());
83df96d6 1238
ab6b6b15
RR
1239 return TRUE;
1240}
1241
1242wxWindow *wxGetClientWindowFromTable(Window w)
83df96d6 1243{
ab6b6b15 1244 return (wxWindow *)wxClientWidgetHashTable->Get((long) w);
83df96d6
JS
1245}
1246
ab6b6b15 1247void wxDeleteClientWindowFromTable(Window w)
83df96d6 1248{
ab6b6b15 1249 wxClientWidgetHashTable->Delete((long)w);
83df96d6
JS
1250}
1251
ab6b6b15
RR
1252// ----------------------------------------------------------------------------
1253// add/remove window from the table
1254// ----------------------------------------------------------------------------
1255
1256// ----------------------------------------------------------------------------
1257// X11-specific accessors
1258// ----------------------------------------------------------------------------
1259
bc797f4c 1260WXWindow wxWindowX11::GetMainWindow() const
83df96d6 1261{
ab6b6b15
RR
1262 return m_mainWindow;
1263}
1264
1265WXWindow wxWindowX11::GetClientWindow() const
1266{
1267 return m_clientWindow;
83df96d6
JS
1268}
1269
83df96d6
JS
1270// ----------------------------------------------------------------------------
1271// TranslateXXXEvent() functions
1272// ----------------------------------------------------------------------------
1273
1b0fb34b 1274bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Window window, XEvent *xevent)
83df96d6 1275{
461e93f9 1276 switch (XEventGetType(xevent))
83df96d6 1277 {
1b0fb34b
JS
1278 case EnterNotify:
1279 case LeaveNotify:
83df96d6
JS
1280 case ButtonPress:
1281 case ButtonRelease:
1282 case MotionNotify:
1283 {
1284 wxEventType eventType = wxEVT_NULL;
1285
461e93f9 1286 if (XEventGetType(xevent) == EnterNotify)
83df96d6 1287 {
1b0fb34b
JS
1288 //if (local_event.xcrossing.mode!=NotifyNormal)
1289 // return ; // Ignore grab events
1290 eventType = wxEVT_ENTER_WINDOW;
1291 // canvas->GetEventHandler()->OnSetFocus();
1292 }
461e93f9 1293 else if (XEventGetType(xevent) == LeaveNotify)
1b0fb34b
JS
1294 {
1295 //if (local_event.xcrossingr.mode!=NotifyNormal)
1296 // return ; // Ignore grab events
1297 eventType = wxEVT_LEAVE_WINDOW;
1298 // canvas->GetEventHandler()->OnKillFocus();
83df96d6 1299 }
461e93f9 1300 else if (XEventGetType(xevent) == MotionNotify)
83df96d6
JS
1301 {
1302 eventType = wxEVT_MOTION;
1303 }
461e93f9 1304 else if (XEventGetType(xevent) == ButtonPress)
83df96d6 1305 {
461e93f9 1306 wxevent.SetTimestamp(XButtonEventGetTime(xevent));
83df96d6 1307 int button = 0;
461e93f9 1308 if (XButtonEventLChanged(xevent))
83df96d6
JS
1309 {
1310 eventType = wxEVT_LEFT_DOWN;
83df96d6
JS
1311 button = 1;
1312 }
461e93f9 1313 else if (XButtonEventMChanged(xevent))
83df96d6
JS
1314 {
1315 eventType = wxEVT_MIDDLE_DOWN;
83df96d6
JS
1316 button = 2;
1317 }
461e93f9 1318 else if (XButtonEventRChanged(xevent))
83df96d6
JS
1319 {
1320 eventType = wxEVT_RIGHT_DOWN;
83df96d6
JS
1321 button = 3;
1322 }
1323
1324 // check for a double click
1b0fb34b 1325 // TODO: where can we get this value from?
b513212d 1326 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
7266b672 1327 long dclickTime = 200;
83df96d6
JS
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 }
461e93f9 1349 else if (XEventGetType(xevent) == ButtonRelease)
83df96d6 1350 {
461e93f9 1351 if (XButtonEventLChanged(xevent))
83df96d6
JS
1352 {
1353 eventType = wxEVT_LEFT_UP;
83df96d6 1354 }
461e93f9 1355 else if (XButtonEventMChanged(xevent))
83df96d6
JS
1356 {
1357 eventType = wxEVT_MIDDLE_UP;
83df96d6 1358 }
461e93f9 1359 else if (XButtonEventRChanged(xevent))
83df96d6
JS
1360 {
1361 eventType = wxEVT_RIGHT_UP;
83df96d6
JS
1362 }
1363 else return FALSE;
1364 }
1365 else
1366 {
1367 return FALSE;
1368 }
1369
1370 wxevent.SetEventType(eventType);
1371
461e93f9
JS
1372 wxevent.m_x = XButtonEventGetX(xevent);
1373 wxevent.m_y = XButtonEventGetY(xevent);
83df96d6
JS
1374
1375 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
461e93f9 1376 || (XButtonEventLIsDown(xevent)
83df96d6
JS
1377 && (eventType != wxEVT_LEFT_UP)));
1378 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
461e93f9 1379 || (XButtonEventMIsDown(xevent)
83df96d6
JS
1380 && (eventType != wxEVT_MIDDLE_UP)));
1381 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
461e93f9 1382 || (XButtonEventRIsDown (xevent)
83df96d6
JS
1383 && (eventType != wxEVT_RIGHT_UP)));
1384
461e93f9
JS
1385 wxevent.m_shiftDown = XButtonEventShiftIsDown(xevent);
1386 wxevent.m_controlDown = XButtonEventCtrlIsDown(xevent);
1387 wxevent.m_altDown = XButtonEventAltIsDown(xevent);
1388 wxevent.m_metaDown = XButtonEventMetaIsDown(xevent);
83df96d6
JS
1389
1390 wxevent.SetId(win->GetId());
1391 wxevent.SetEventObject(win);
1392
1393 return TRUE;
1394 }
1395 }
1396 return FALSE;
1397}
1398
7eaac9f5 1399bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Window WXUNUSED(win), XEvent *xevent)
83df96d6 1400{
461e93f9 1401 switch (XEventGetType(xevent))
83df96d6
JS
1402 {
1403 case KeyPress:
1404 case KeyRelease:
1405 {
1406 char buf[20];
1407
1408 KeySym keySym;
83df96d6
JS
1409 (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL);
1410 int id = wxCharCodeXToWX (keySym);
1411
461e93f9
JS
1412 wxevent.m_shiftDown = XKeyEventShiftIsDown(xevent);
1413 wxevent.m_controlDown = XKeyEventCtrlIsDown(xevent);
1414 wxevent.m_altDown = XKeyEventAltIsDown(xevent);
1415 wxevent.m_metaDown = XKeyEventMetaIsDown(xevent);
83df96d6
JS
1416 wxevent.SetEventObject(win);
1417 wxevent.m_keyCode = id;
461e93f9 1418 wxevent.SetTimestamp(XKeyEventGetTime(xevent));
83df96d6 1419
461e93f9
JS
1420 wxevent.m_x = XKeyEventGetX(xevent);
1421 wxevent.m_y = XKeyEventGetY(xevent);
83df96d6
JS
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
bc797f4c 1439bool wxWindowX11::SetBackgroundColour(const wxColour& col)
83df96d6 1440{
56cb684a 1441 wxWindowBase::SetBackgroundColour(col);
83df96d6 1442
3cd0b8c5
RR
1443 Display *xdisplay = (Display*) wxGlobalDisplay();
1444 int xscreen = DefaultScreen( xdisplay );
1445 Colormap cm = DefaultColormap( xdisplay, xscreen );
1446
ba696cfa 1447 m_backgroundColour.CalcPixel( (WXColormap) cm );
3cd0b8c5 1448
c2c0dabf
RR
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
83df96d6
JS
1453 return TRUE;
1454}
1455
bc797f4c 1456bool wxWindowX11::SetForegroundColour(const wxColour& col)
83df96d6
JS
1457{
1458 if ( !wxWindowBase::SetForegroundColour(col) )
1459 return FALSE;
1460
83df96d6
JS
1461 return TRUE;
1462}
1463
83df96d6
JS
1464// ----------------------------------------------------------------------------
1465// global functions
1466// ----------------------------------------------------------------------------
1467
1468wxWindow *wxGetActiveWindow()
1469{
1470 // TODO
1471 wxFAIL_MSG("Not implemented");
1472 return NULL;
1473}
1474
1475/* static */
1476wxWindow *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.
1484wxWindow* wxFindWindowAtPointer(wxPoint& pt)
1485{
1486 return wxFindWindowAtPoint(wxGetMousePosition());
1487}
1488
1489// Get the current mouse position.
1490wxPoint wxGetMousePosition()
1491{
461e93f9
JS
1492#if wxUSE_NANOX
1493 /* TODO */
1494 return wxPoint(0, 0);
1495#else
b513212d 1496 Display *display = wxGlobalDisplay();
83df96d6
JS
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);
461e93f9 1508#endif
83df96d6
JS
1509}
1510
1511
1512// ----------------------------------------------------------------------------
1513// wxNoOptimize: switch off size optimization
1514// ----------------------------------------------------------------------------
1515
1516int wxNoOptimize::ms_count = 0;
1517
c2c0dabf
RR
1518
1519// ----------------------------------------------------------------------------
1520// wxDCModule
1521// ----------------------------------------------------------------------------
1522
1523class wxWinModule : public wxModule
1524{
1525public:
1526 bool OnInit();
1527 void OnExit();
1528
1529private:
1530 DECLARE_DYNAMIC_CLASS(wxWinModule)
1531};
1532
1533IMPLEMENT_DYNAMIC_CLASS(wxWinModule, wxModule)
1534
1535bool 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
1546void wxWinModule::OnExit()
1547{
1548 Display *xdisplay = wxGlobalDisplay();
1549 XFreeGC( xdisplay, g_eraseGC );
1550}
1551
1552