]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/window.cpp
added asserts to check correct order of wxHtmlDCRenderer methods calls
[wxWidgets.git] / src / mgl / window.cpp
CommitLineData
32b8ec41 1/////////////////////////////////////////////////////////////////////////////
a4bbc9f7
VS
2// Name: src/mgl/window.cpp
3// Purpose: wxWindow
4// Author: Vaclav Slavik
5// (based on GTK & MSW implementations)
6// RCS-ID: $Id$
eea93267 7// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
65571936 8// Licence: wxWindows licence
32b8ec41
VZ
9/////////////////////////////////////////////////////////////////////////////
10
a4bbc9f7
VS
11// ===========================================================================
12// declarations
13// ===========================================================================
14
15// ---------------------------------------------------------------------------
16// headers
17// ---------------------------------------------------------------------------
32b8ec41 18
a4bbc9f7
VS
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
88a7a4e1
WS
26#include "wx/window.h"
27
a4bbc9f7 28#ifndef WX_PRECOMP
d53fc7c9 29 #include "wx/msgdlg.h"
a4bbc9f7 30 #include "wx/accel.h"
a4bbc9f7
VS
31 #include "wx/dc.h"
32 #include "wx/dcclient.h"
33 #include "wx/utils.h"
34 #include "wx/app.h"
35 #include "wx/panel.h"
88a7a4e1 36 #include "wx/intl.h"
e4db172a 37 #include "wx/log.h"
11dbb4bf 38 #include "wx/dcscreen.h"
3b3dc801 39 #include "wx/menu.h"
a4bbc9f7
VS
40#endif
41
42#if wxUSE_DRAG_AND_DROP
43 #include "wx/dnd.h"
44#endif
45
a4bbc9f7
VS
46#include "wx/sysopt.h"
47#include "wx/mgl/private.h"
90eb13e6 48#include "wx/caret.h"
a4bbc9f7
VS
49
50#include <mgraph.hpp>
51
52#if wxUSE_TOOLTIPS
53 #include "wx/tooltip.h"
54#endif
55
56// ---------------------------------------------------------------------------
57// global variables
58// ---------------------------------------------------------------------------
59
60// MGL window manager and associated DC.
61winmng_t *g_winMng = NULL;
62MGLDevCtx *g_displayDC = NULL;
63
7de59551 64// the window that has keyboard focus:
7cdbf02c 65static wxWindowMGL *gs_focusedWindow = NULL;
7de59551 66// the window that is about to be focused after currently focused
eea93267
VS
67// one looses focus:
68static wxWindow *gs_toBeFocusedWindow = NULL;
7bdc1879 69// the window that is currently under mouse cursor:
7cdbf02c
VS
70static wxWindowMGL *gs_windowUnderMouse = NULL;
71// the window that has mouse capture
72static wxWindowMGL *gs_mouseCapture = NULL;
73// the frame that is currently active (i.e. its child has focus). It is
74// used to generate wxActivateEvents
75static wxWindowMGL *gs_activeFrame = NULL;
06414d99
MW
76// track the mouse button state for wxGetMouseState()
77unsigned long g_buttonState = 0;
a4bbc9f7
VS
78
79// ---------------------------------------------------------------------------
80// constants
81// ---------------------------------------------------------------------------
82
7de59551 83// Custom identifiers used to distinguish between various event handlers
a4bbc9f7
VS
84// and capture handlers passed to MGL_wm
85enum
86{
87 wxMGL_CAPTURE_MOUSE = 1,
88 wxMGL_CAPTURE_KEYB = 2
89};
90
91
92// ---------------------------------------------------------------------------
93// private functions
94// ---------------------------------------------------------------------------
95
7cdbf02c
VS
96// Returns toplevel grandparent of given window:
97static wxWindowMGL* wxGetTopLevelParent(wxWindowMGL *win)
98{
99 wxWindowMGL *p = win;
100 while (p && !p->IsTopLevel())
101 p = p->GetParent();
102 return p;
103}
104
d53fc7c9 105// An easy way to capture screenshots:
2d1efe3f 106static void wxCaptureScreenshot(bool activeWindowOnly)
e6daf008 107{
d53fc7c9
VS
108#ifdef __DOS__
109 #define SCREENSHOT_FILENAME _T("sshot%03i.png")
110#else
111 #define SCREENSHOT_FILENAME _T("screenshot-%03i.png")
112#endif
e6daf008 113 static int screenshot_num = 0;
d53fc7c9 114 wxString screenshot;
7de59551
RD
115
116 do
d53fc7c9
VS
117 {
118 screenshot.Printf(SCREENSHOT_FILENAME, screenshot_num++);
119 } while ( wxFileExists(screenshot) && screenshot_num < 1000 );
7de59551 120
2d1efe3f
VS
121 wxRect r(0, 0, g_displayDC->sizex(), g_displayDC->sizey());
122
123 if ( activeWindowOnly && gs_activeFrame )
124 {
125 r.Intersect(gs_activeFrame->GetRect());
126 }
7de59551
RD
127
128 g_displayDC->savePNGFromDC(screenshot.mb_str(),
06534aa1 129 r.x, r. y, r.x+r.width, r.y+r.height);
7de59551 130
2b5f62a0
VZ
131 wxMessageBox(wxString::Format(_T("Screenshot captured: %s"),
132 screenshot.c_str()));
e6daf008 133}
e6daf008 134
7bdc1879
VS
135// ---------------------------------------------------------------------------
136// MGL_WM hooks:
137// ---------------------------------------------------------------------------
138
b43a9886 139static void MGLAPI wxWindowPainter(window_t *wnd, MGLDC *dc)
7bdc1879
VS
140{
141 wxWindowMGL *w = (wxWindow*) wnd->userData;
7de59551 142
544c782d 143 if ( w && !(w->GetWindowStyle() & wxTRANSPARENT_WINDOW) )
7bdc1879
VS
144 {
145 MGLDevCtx ctx(dc);
146 w->HandlePaint(&ctx);
147 }
ef344ff8
VS
148}
149
b43a9886 150static ibool MGLAPI wxWindowMouseHandler(window_t *wnd, event_t *e)
ef344ff8
VS
151{
152 wxWindowMGL *win = (wxWindowMGL*)MGL_wmGetWindowUserData(wnd);
d76048f5 153 wxPoint orig(win->GetClientAreaOrigin());
985520bc 154 wxPoint where;
7de59551 155
06414d99
MW
156 g_buttonState = e->modifiers;
157
7de59551 158 MGL_wmCoordGlobalToLocal(win->GetHandle(),
985520bc
VS
159 e->where_x, e->where_y, &where.x, &where.y);
160
0a89ac9c
VS
161 for (wxWindowMGL *w = win; w; w = w->GetParent())
162 {
7de59551 163 if ( !w->IsEnabled() )
0a89ac9c
VS
164 return FALSE;
165 if ( w->IsTopLevel() )
166 break;
167 }
7de59551 168
ef344ff8
VS
169 wxEventType type = wxEVT_NULL;
170 wxMouseEvent event;
171 event.SetEventObject(win);
172 event.SetTimestamp(e->when);
d76048f5
VS
173 event.m_x = where.x - orig.x;
174 event.m_y = where.y - orig.y;
318ac890
MW
175 event.m_shiftDown = ( e->modifiers & EVT_SHIFTKEY ) != 0;
176 event.m_controlDown = ( e->modifiers & EVT_CTRLSTATE ) != 0;
177 event.m_altDown = ( e->modifiers & EVT_LEFTALT ) != 0;
178 event.m_metaDown = ( e->modifiers & EVT_RIGHTALT ) != 0;
179 event.m_leftDown = ( e->modifiers & EVT_LEFTBUT ) != 0;
180 event.m_middleDown = ( e->modifiers & EVT_MIDDLEBUT ) != 0;
181 event.m_rightDown = ( e->modifiers & EVT_RIGHTBUT ) != 0;
7de59551 182
ef344ff8
VS
183 switch (e->what)
184 {
185 case EVT_MOUSEDOWN:
8f5e92db 186 // Change focus if the user clicks outside focused window:
ad02525d 187 if ( win->CanAcceptFocus() && wxWindow::FindFocus() != win )
8f5e92db
VS
188 win->SetFocus();
189
8f5e92db
VS
190 if ( e->message & EVT_DBLCLICK )
191 {
8f5e92db
VS
192 if ( e->message & EVT_LEFTBMASK )
193 type = wxEVT_LEFT_DCLICK;
194 else if ( e->message & EVT_MIDDLEBMASK )
195 type = wxEVT_MIDDLE_DCLICK;
196 else if ( e->message & EVT_RIGHTBMASK )
197 type = wxEVT_RIGHT_DCLICK;
198 }
ea98f686
VS
199 else
200 {
201 if ( e->message & EVT_LEFTBMASK )
202 type = wxEVT_LEFT_DOWN;
203 else if ( e->message & EVT_MIDDLEBMASK )
204 type = wxEVT_MIDDLE_DOWN;
205 else if ( e->message & EVT_RIGHTBMASK )
206 type = wxEVT_RIGHT_DOWN;
207 }
a679e129 208
ef344ff8
VS
209 break;
210
211 case EVT_MOUSEUP:
212 if ( e->message & EVT_LEFTBMASK )
213 type = wxEVT_LEFT_UP;
214 else if ( e->message & EVT_MIDDLEBMASK )
215 type = wxEVT_MIDDLE_UP;
216 else if ( e->message & EVT_RIGHTBMASK )
217 type = wxEVT_RIGHT_UP;
218 break;
219
220 case EVT_MOUSEMOVE:
7cdbf02c
VS
221 if ( !gs_mouseCapture )
222 {
223 if ( win != gs_windowUnderMouse )
224 {
225 if ( gs_windowUnderMouse )
226 {
227 wxMouseEvent event2(event);
7de59551
RD
228 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse->GetHandle(),
229 e->where_x, e->where_y,
7cdbf02c
VS
230 &event2.m_x, &event2.m_y);
231
d76048f5
VS
232 wxPoint orig(gs_windowUnderMouse->GetClientAreaOrigin());
233 event2.m_x -= orig.x;
234 event2.m_y -= orig.y;
235
7cdbf02c
VS
236 event2.SetEventObject(gs_windowUnderMouse);
237 event2.SetEventType(wxEVT_LEAVE_WINDOW);
937013e0 238 gs_windowUnderMouse->HandleWindowEvent(event2);
7cdbf02c
VS
239 }
240
241 wxMouseEvent event3(event);
242 event3.SetEventType(wxEVT_ENTER_WINDOW);
937013e0 243 win->HandleWindowEvent(event3);
7cdbf02c
VS
244
245 gs_windowUnderMouse = win;
246 }
247 }
248 else // gs_mouseCapture
ef344ff8 249 {
7de59551 250 bool inside = (where.x >= 0 &&
7cdbf02c
VS
251 where.y >= 0 &&
252 where.x < win->GetSize().x &&
253 where.y < win->GetSize().y);
254 if ( (inside && gs_windowUnderMouse != win) ||
255 (!inside && gs_windowUnderMouse == win) )
ef344ff8 256 {
7de59551 257 wxMouseEvent evt(inside ?
7cdbf02c
VS
258 wxEVT_ENTER_WINDOW : wxEVT_LEAVE_WINDOW);
259 evt.SetEventObject(win);
937013e0 260 win->HandleWindowEvent(evt);
7cdbf02c 261 gs_windowUnderMouse = inside ? win : NULL;
ef344ff8 262 }
ef344ff8 263 }
7de59551 264
ef344ff8
VS
265 type = wxEVT_MOTION;
266 break;
267
268 default:
269 break;
270 }
7de59551 271
ef344ff8
VS
272 if ( type == wxEVT_NULL )
273 {
274 return FALSE;
275 }
276 else
277 {
278 event.SetEventType(type);
937013e0 279 return win->HandleWindowEvent(event);
ef344ff8
VS
280 }
281}
282
a679e129 283static long wxScanToKeyCode(event_t *event, bool translate)
ef344ff8 284{
84c88a17
VS
285 // VS: make it __WXDEBUG__-only, since we have lots of wxLogTrace calls
286 // here and the arguments would be stored in non-debug executable even
287 // though wxLogTrace would be no-op...
288 #ifdef __WXDEBUG__
289 #define KEY(mgl_key,wx_key) \
290 case mgl_key: \
291 wxLogTrace(_T("keyevents"), \
292 _T("key " #mgl_key ", mapped to " #wx_key)); \
293 key = wx_key; \
294 break;
295 #else
296 #define KEY(mgl_key,wx_key) \
7de59551 297 case mgl_key: key = wx_key; break;
84c88a17 298 #endif
2b260bc3
VS
299
300 long key = 0;
7de59551 301
a679e129 302 if ( translate )
2b260bc3 303 {
3fa2676f
MW
304 bool numlock = (event->modifiers & EVT_NUMLOCK) != 0;
305
a679e129
VS
306 switch ( EVT_scanCode(event->message) )
307 {
308 KEY (KB_padMinus, WXK_NUMPAD_SUBTRACT)
309 KEY (KB_padPlus, WXK_NUMPAD_ADD)
310 KEY (KB_padTimes, WXK_NUMPAD_MULTIPLY)
311 KEY (KB_padDivide, WXK_NUMPAD_DIVIDE)
3fa2676f
MW
312 KEY (KB_padCenter, numlock ? WXK_NUMPAD5 : WXK_NUMPAD_SEPARATOR) // ?
313 KEY (KB_padLeft, numlock ? WXK_NUMPAD4 : WXK_NUMPAD_LEFT)
314 KEY (KB_padRight, numlock ? WXK_NUMPAD6 : WXK_NUMPAD_RIGHT)
315 KEY (KB_padUp, numlock ? WXK_NUMPAD8 : WXK_NUMPAD_UP)
316 KEY (KB_padDown, numlock ? WXK_NUMPAD2 : WXK_NUMPAD_DOWN)
317 KEY (KB_padInsert, numlock ? WXK_NUMPAD0 : WXK_NUMPAD_INSERT)
318 KEY (KB_padDelete, numlock ? WXK_DECIMAL : WXK_NUMPAD_DELETE)
319 KEY (KB_padHome, numlock ? WXK_NUMPAD7 : WXK_NUMPAD_HOME)
320 KEY (KB_padEnd, numlock ? WXK_NUMPAD1 : WXK_NUMPAD_END)
321 KEY (KB_padPageUp, numlock ? WXK_NUMPAD9 : WXK_NUMPAD_PAGEUP)
322 KEY (KB_padPageDown, numlock ? WXK_NUMPAD3 : WXK_NUMPAD_PAGEDOWN)
a679e129
VS
323 KEY (KB_1, '1')
324 KEY (KB_2, '2')
325 KEY (KB_3, '3')
326 KEY (KB_4, '4')
327 KEY (KB_5, '5')
328 KEY (KB_6, '6')
329 KEY (KB_7, '7')
330 KEY (KB_8, '8')
331 KEY (KB_9, '9')
332 KEY (KB_0, '0')
333 KEY (KB_minus, WXK_SUBTRACT)
334 KEY (KB_equals, WXK_ADD)
335 KEY (KB_backSlash, '\\')
336 KEY (KB_Q, 'Q')
337 KEY (KB_W, 'W')
338 KEY (KB_E, 'E')
339 KEY (KB_R, 'R')
340 KEY (KB_T, 'T')
341 KEY (KB_Y, 'Y')
342 KEY (KB_U, 'U')
343 KEY (KB_I, 'I')
344 KEY (KB_O, 'O')
345 KEY (KB_P, 'P')
346 KEY (KB_leftSquareBrace,'[')
347 KEY (KB_rightSquareBrace,']')
348 KEY (KB_A, 'A')
349 KEY (KB_S, 'S')
350 KEY (KB_D, 'D')
351 KEY (KB_F, 'F')
352 KEY (KB_G, 'G')
353 KEY (KB_H, 'H')
354 KEY (KB_J, 'J')
355 KEY (KB_K, 'K')
356 KEY (KB_L, 'L')
357 KEY (KB_semicolon, ';')
358 KEY (KB_apostrophe, '\'')
359 KEY (KB_Z, 'Z')
360 KEY (KB_X, 'X')
361 KEY (KB_C, 'C')
362 KEY (KB_V, 'V')
363 KEY (KB_B, 'B')
364 KEY (KB_N, 'N')
365 KEY (KB_M, 'M')
366 KEY (KB_comma, ',')
367 KEY (KB_period, '.')
368 KEY (KB_divide, WXK_DIVIDE)
369 KEY (KB_space, WXK_SPACE)
370 KEY (KB_tilde, '~')
371
372 default: break;
373 }
374 }
7de59551 375
a679e129
VS
376 if ( key == 0 )
377 {
378 switch ( EVT_scanCode(event->message) )
379 {
380 KEY (KB_padEnter, WXK_NUMPAD_ENTER)
381 KEY (KB_F1, WXK_F1)
382 KEY (KB_F2, WXK_F2)
383 KEY (KB_F3, WXK_F3)
384 KEY (KB_F4, WXK_F4)
385 KEY (KB_F5, WXK_F5)
386 KEY (KB_F6, WXK_F6)
387 KEY (KB_F7, WXK_F7)
388 KEY (KB_F8, WXK_F8)
389 KEY (KB_F9, WXK_F9)
390 KEY (KB_F10, WXK_F10)
391 KEY (KB_F11, WXK_F11)
392 KEY (KB_F12, WXK_F12)
393 KEY (KB_left, WXK_LEFT)
394 KEY (KB_right, WXK_RIGHT)
395 KEY (KB_up, WXK_UP)
396 KEY (KB_down, WXK_DOWN)
397 KEY (KB_insert, WXK_INSERT)
398 KEY (KB_delete, WXK_DELETE)
399 KEY (KB_home, WXK_HOME)
400 KEY (KB_end, WXK_END)
401 KEY (KB_pageUp, WXK_PAGEUP)
402 KEY (KB_pageDown, WXK_PAGEDOWN)
403 KEY (KB_capsLock, WXK_CAPITAL)
404 KEY (KB_numLock, WXK_NUMLOCK)
405 KEY (KB_scrollLock, WXK_SCROLL)
406 KEY (KB_leftShift, WXK_SHIFT)
407 KEY (KB_rightShift, WXK_SHIFT)
408 KEY (KB_leftCtrl, WXK_CONTROL)
409 KEY (KB_rightCtrl, WXK_CONTROL)
410 KEY (KB_leftAlt, WXK_ALT)
411 KEY (KB_rightAlt, WXK_ALT)
412 KEY (KB_leftWindows, WXK_START)
413 KEY (KB_rightWindows, WXK_START)
414 KEY (KB_menu, WXK_MENU)
415 KEY (KB_sysReq, WXK_SNAPSHOT)
416 KEY (KB_esc, WXK_ESCAPE)
417 KEY (KB_backspace, WXK_BACK)
418 KEY (KB_tab, WXK_TAB)
7de59551 419 KEY (KB_enter, WXK_RETURN)
a679e129 420
7de59551
RD
421 default:
422 key = EVT_asciiCode(event->message);
a679e129
VS
423 break;
424 }
2b260bc3
VS
425 }
426
544c782d
VS
427 #undef KEY
428
2b260bc3 429 return key;
ef344ff8
VS
430}
431
d53fc7c9
VS
432static bool wxHandleSpecialKeys(wxKeyEvent& event)
433{
434 // Add an easy way to capture screenshots:
435 if ( event.m_keyCode == WXK_SNAPSHOT
436 #ifdef __WXDEBUG__ // FIXME_MGL - remove when KB_sysReq works in MGL!
7de59551
RD
437 || (event.m_keyCode == WXK_F1 &&
438 event.m_shiftDown && event.m_controlDown)
d53fc7c9 439 #endif
197b1626 440 )
d53fc7c9 441 {
2d1efe3f 442 wxCaptureScreenshot(event.m_altDown/*only active wnd?*/);
127eab18 443 return true;
d53fc7c9 444 }
7de59551 445
127eab18 446 return false;
d53fc7c9
VS
447}
448
b43a9886 449static ibool MGLAPI wxWindowKeybHandler(window_t *wnd, event_t *e)
2b260bc3 450{
2b260bc3 451 wxWindowMGL *win = (wxWindowMGL*)MGL_wmGetWindowUserData(wnd);
a200c35e
VS
452
453 if ( !win->IsEnabled() ) return FALSE;
454
985520bc 455 wxPoint where;
7de59551 456 MGL_wmCoordGlobalToLocal(win->GetHandle(),
985520bc 457 e->where_x, e->where_y, &where.x, &where.y);
7de59551 458
2b260bc3
VS
459 wxKeyEvent event;
460 event.SetEventObject(win);
461 event.SetTimestamp(e->when);
127eab18 462 event.m_keyCode = wxScanToKeyCode(e, true);
2b260bc3
VS
463 event.m_x = where.x;
464 event.m_y = where.y;
318ac890
MW
465 event.m_shiftDown = ( e->modifiers & EVT_SHIFTKEY ) != 0;
466 event.m_controlDown = ( e->modifiers & EVT_CTRLSTATE ) != 0;
467 event.m_altDown = ( e->modifiers & EVT_LEFTALT ) != 0;
468 event.m_metaDown = ( e->modifiers & EVT_RIGHTALT ) != 0;
2b260bc3
VS
469
470 if ( e->what == EVT_KEYUP )
471 {
472 event.SetEventType(wxEVT_KEY_UP);
937013e0 473 return win->HandleWindowEvent(event);
2b260bc3
VS
474 }
475 else
476 {
477 bool ret;
478 wxKeyEvent event2;
479
480 event.SetEventType(wxEVT_KEY_DOWN);
481 event2 = event;
7de59551 482
937013e0 483 ret = win->HandleWindowEvent(event);
2b260bc3 484
84c88a17
VS
485 // wxMSW doesn't send char events with Alt pressed
486 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
d53fc7c9 487 // will only be sent if it is not in an accelerator table:
127eab18 488 event2.m_keyCode = wxScanToKeyCode(e, false);
2b260bc3
VS
489 if ( !ret && event2.m_keyCode != 0 )
490 {
491 event2.SetEventType(wxEVT_CHAR);
937013e0 492 ret = win->HandleWindowEvent(event2);
2b260bc3 493 }
7de59551 494
84c88a17 495 // Synthetize navigation key event, but do it only if the TAB key
d53fc7c9 496 // wasn't handled yet:
84c88a17
VS
497 if ( !ret && event.m_keyCode == WXK_TAB &&
498 win->GetParent() && win->GetParent()->HasFlag(wxTAB_TRAVERSAL) )
499 {
500 wxNavigationKeyEvent navEvent;
501 navEvent.SetEventObject(win->GetParent());
502 // Shift-TAB goes in reverse direction:
503 navEvent.SetDirection(!event.m_shiftDown);
504 // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
505 navEvent.SetWindowChange(event.m_controlDown);
506 navEvent.SetCurrentFocus(wxStaticCast(win, wxWindow));
937013e0 507 ret = win->HandleWindowEvent(navEvent);
84c88a17 508 }
7de59551
RD
509
510 // Finally, process special meaning keys that are usually
d53fc7c9
VS
511 // a responsibility of OS or window manager:
512 if ( !ret )
513 ret = wxHandleSpecialKeys(event);
7de59551 514
2b260bc3
VS
515 return ret;
516 }
7bdc1879 517}
a4bbc9f7
VS
518
519// ---------------------------------------------------------------------------
520// event tables
521// ---------------------------------------------------------------------------
522
ef344ff8 523// in wxUniv this class is abstract because it doesn't have DoPopupMenu()
a4bbc9f7
VS
524IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL, wxWindowBase)
525
526BEGIN_EVENT_TABLE(wxWindowMGL, wxWindowBase)
a4bbc9f7
VS
527END_EVENT_TABLE()
528
529// ===========================================================================
530// implementation
531// ===========================================================================
532
533// ----------------------------------------------------------------------------
534// constructors and such
535// ----------------------------------------------------------------------------
536
1c53456f 537extern wxVideoMode wxGetDefaultDisplayMode();
a3e76614 538
a4bbc9f7
VS
539void wxWindowMGL::Init()
540{
1f43b5c9
VS
541 // First of all, make sure window manager is up and running. If it is
542 // not the case, initialize it in default display mode
543 if ( !g_winMng )
7b9f73d2
VS
544 {
545 if ( !wxTheApp->SetDisplayMode(wxGetDefaultDisplayMode()) )
a1f7eb20 546 wxLogFatalError(_("Cannot initialize display."));
7b9f73d2 547 }
1f43b5c9 548
a4bbc9f7 549 // mgl specific:
a4bbc9f7 550 m_wnd = NULL;
127eab18 551 m_isShown = true;
a4bbc9f7 552 m_paintMGLDC = NULL;
2b260bc3 553 m_eraseBackground = -1;
a4bbc9f7
VS
554}
555
556// Destructor
557wxWindowMGL::~wxWindowMGL()
558{
7de59551
RD
559 SendDestroyEvent();
560
7cdbf02c
VS
561 if ( gs_mouseCapture == this )
562 ReleaseMouse();
d46330c5 563
7cdbf02c 564 if (gs_activeFrame == this)
d46330c5 565 {
66858adf
VS
566 gs_activeFrame = NULL;
567 // activate next frame in Z-order:
568 if ( m_wnd->prev )
569 {
570 wxWindowMGL *win = (wxWindowMGL*)m_wnd->prev->userData;
571 win->SetFocus();
572 }
573 else if ( m_wnd->next )
574 {
575 wxWindowMGL *win = (wxWindowMGL*)m_wnd->next->userData;
576 win->SetFocus();
d46330c5 577 }
d46330c5 578 }
7de59551 579
7cdbf02c 580 if ( gs_focusedWindow == this )
7bdc1879 581 KillFocus();
d46330c5 582
7cdbf02c
VS
583 if ( gs_windowUnderMouse == this )
584 gs_windowUnderMouse = NULL;
a4bbc9f7 585
a4bbc9f7
VS
586 DestroyChildren();
587
a4bbc9f7
VS
588 if ( m_wnd )
589 MGL_wmDestroyWindow(m_wnd);
590}
591
592// real construction (Init() must have been called before!)
593bool wxWindowMGL::Create(wxWindow *parent,
594 wxWindowID id,
595 const wxPoint& pos,
596 const wxSize& size,
597 long style,
598 const wxString& name)
599{
a4bbc9f7 600 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
127eab18 601 return false;
a4bbc9f7 602
544c782d 603 if ( parent )
7bdc1879 604 parent->AddChild(this);
a4bbc9f7 605
ef344ff8
VS
606 int x, y, w, h;
607 x = pos.x, y = pos.y;
608 if ( x == -1 )
609 x = 0; // FIXME_MGL, something better, see GTK+
610 if ( y == -1 )
611 y = 0; // FIXME_MGL, something better, see GTK+
82186005 612 AdjustForParentClientOrigin(x, y, 0);
ef344ff8
VS
613 w = WidthDefault(size.x);
614 h = HeightDefault(size.y);
7de59551 615
72fa862b 616 long mgl_style = 0;
7cdbf02c 617 window_t *wnd_parent = parent ? parent->GetHandle() : NULL;
544c782d 618
e441e1f4 619 if ( style & wxFULL_REPAINT_ON_RESIZE )
544c782d 620 {
72fa862b 621 mgl_style |= MGL_WM_FULL_REPAINT_ON_RESIZE;
544c782d 622 }
72fa862b 623 if ( style & wxSTAY_ON_TOP )
544c782d 624 {
72fa862b 625 mgl_style |= MGL_WM_ALWAYS_ON_TOP;
544c782d
VS
626 }
627 if ( style & wxPOPUP_WINDOW )
628 {
7cdbf02c 629 mgl_style |= MGL_WM_ALWAYS_ON_TOP;
544c782d 630 // it is created hidden as other top level windows
127eab18 631 m_isShown = false;
7cdbf02c 632 wnd_parent = NULL;
544c782d 633 }
ef344ff8 634
58061670
VS
635 window_t *wnd = MGL_wmCreateWindow(g_winMng, wnd_parent, x, y, w, h);
636
637 MGL_wmSetWindowFlags(wnd, mgl_style);
638 MGL_wmShowWindow(wnd, m_isShown);
7de59551 639
58061670
VS
640 SetMGLwindow_t(wnd);
641
127eab18 642 return true;
58061670
VS
643}
644
645void wxWindowMGL::SetMGLwindow_t(struct window_t *wnd)
646{
647 if ( m_wnd )
648 MGL_wmDestroyWindow(m_wnd);
649
650 m_wnd = wnd;
651 if ( !m_wnd ) return;
7de59551 652
127eab18 653 m_isShown = (bool)m_wnd->visible;
ef344ff8 654
a4bbc9f7
VS
655 MGL_wmSetWindowUserData(m_wnd, (void*) this);
656 MGL_wmSetWindowPainter(m_wnd, wxWindowPainter);
ef344ff8
VS
657 MGL_wmPushWindowEventHandler(m_wnd, wxWindowMouseHandler, EVT_MOUSEEVT, 0);
658 MGL_wmPushWindowEventHandler(m_wnd, wxWindowKeybHandler, EVT_KEYEVT, 0);
58061670
VS
659
660 if ( m_cursor.Ok() )
661 MGL_wmSetWindowCursor(m_wnd, *m_cursor.GetMGLCursor());
662 else
663 MGL_wmSetWindowCursor(m_wnd, *wxSTANDARD_CURSOR->GetMGLCursor());
a4bbc9f7
VS
664}
665
666// ---------------------------------------------------------------------------
667// basic operations
668// ---------------------------------------------------------------------------
669
670void wxWindowMGL::SetFocus()
671{
a46935cb
VS
672 if ( gs_focusedWindow == this ) return;
673
eea93267
VS
674 wxWindowMGL *oldFocusedWindow = gs_focusedWindow;
675
7cdbf02c 676 if ( gs_focusedWindow )
eea93267
VS
677 {
678 gs_toBeFocusedWindow = (wxWindow*)this;
7cdbf02c 679 gs_focusedWindow->KillFocus();
eea93267
VS
680 gs_toBeFocusedWindow = NULL;
681 }
7de59551 682
7cdbf02c 683 gs_focusedWindow = this;
7de59551 684
2b260bc3 685 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT, wxMGL_CAPTURE_KEYB);
a4bbc9f7 686
7cdbf02c 687 wxWindowMGL *active = wxGetTopLevelParent(this);
61bd618f 688 if ( !(m_windowStyle & wxPOPUP_WINDOW) && active != gs_activeFrame )
a4bbc9f7 689 {
7cdbf02c
VS
690 if ( gs_activeFrame )
691 {
127eab18 692 wxActivateEvent event(wxEVT_ACTIVATE, false, gs_activeFrame->GetId());
7cdbf02c 693 event.SetEventObject(gs_activeFrame);
937013e0 694 gs_activeFrame->HandleWindowEvent(event);
7cdbf02c
VS
695 }
696
697 gs_activeFrame = active;
127eab18 698 wxActivateEvent event(wxEVT_ACTIVATE, true, gs_activeFrame->GetId());
7cdbf02c 699 event.SetEventObject(gs_activeFrame);
937013e0 700 gs_activeFrame->HandleWindowEvent(event);
a4bbc9f7 701 }
7de59551 702
4d163bf8
VS
703 // notify the parent keeping track of focus for the kbd navigation
704 // purposes that we got it
705 wxChildFocusEvent eventFocus((wxWindow*)this);
937013e0 706 HandleWindowEvent(eventFocus);
4d163bf8 707
a4bbc9f7
VS
708 wxFocusEvent event(wxEVT_SET_FOCUS, GetId());
709 event.SetEventObject(this);
eea93267 710 event.SetWindow((wxWindow*)oldFocusedWindow);
937013e0 711 HandleWindowEvent(event);
869dabf8
VS
712
713#if wxUSE_CARET
714 // caret needs to be informed about focus change
715 wxCaret *caret = GetCaret();
716 if ( caret )
717 caret->OnSetFocus();
718#endif // wxUSE_CARET
a4bbc9f7 719}
32b8ec41 720
a4bbc9f7 721void wxWindowMGL::KillFocus()
32b8ec41 722{
7cdbf02c
VS
723 if ( gs_focusedWindow != this ) return;
724 gs_focusedWindow = NULL;
a4bbc9f7 725
7bdc1879 726 if ( m_isBeingDeleted ) return;
7de59551 727
a4bbc9f7
VS
728 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB);
729
730#if wxUSE_CARET
731 // caret needs to be informed about focus change
732 wxCaret *caret = GetCaret();
7bdc1879 733 if ( caret )
a4bbc9f7
VS
734 caret->OnKillFocus();
735#endif // wxUSE_CARET
736
a4bbc9f7
VS
737 wxFocusEvent event(wxEVT_KILL_FOCUS, GetId());
738 event.SetEventObject(this);
eea93267 739 event.SetWindow(gs_toBeFocusedWindow);
937013e0 740 HandleWindowEvent(event);
32b8ec41
VZ
741}
742
a4bbc9f7
VS
743// ----------------------------------------------------------------------------
744// this wxWindowBase function is implemented here (in platform-specific file)
745// because it is static and so couldn't be made virtual
746// ----------------------------------------------------------------------------
0fe02759 747wxWindow *wxWindowBase::DoFindFocus()
32b8ec41 748{
7cdbf02c 749 return (wxWindow*)gs_focusedWindow;
a4bbc9f7
VS
750}
751
752bool wxWindowMGL::Show(bool show)
753{
754 if ( !wxWindowBase::Show(show) )
127eab18 755 return false;
a4bbc9f7
VS
756
757 MGL_wmShowWindow(m_wnd, show);
7de59551 758
ead60ec5
VS
759 if (!show && gs_activeFrame == this)
760 {
66858adf
VS
761 // activate next frame in Z-order:
762 if ( m_wnd->prev )
763 {
764 wxWindowMGL *win = (wxWindowMGL*)m_wnd->prev->userData;
765 win->SetFocus();
766 }
767 else if ( m_wnd->next )
768 {
769 wxWindowMGL *win = (wxWindowMGL*)m_wnd->next->userData;
770 win->SetFocus();
771 }
772 else
773 {
774 gs_activeFrame = NULL;
ead60ec5
VS
775 }
776 }
777
127eab18 778 return true;
a4bbc9f7
VS
779}
780
781// Raise the window to the top of the Z order
782void wxWindowMGL::Raise()
783{
784 MGL_wmRaiseWindow(m_wnd);
785}
786
787// Lower the window to the bottom of the Z order
788void wxWindowMGL::Lower()
789{
790 MGL_wmLowerWindow(m_wnd);
791}
792
4116c221 793void wxWindowMGL::DoCaptureMouse()
a4bbc9f7 794{
7cdbf02c
VS
795 if ( gs_mouseCapture )
796 MGL_wmUncaptureEvents(gs_mouseCapture->m_wnd, wxMGL_CAPTURE_MOUSE);
797
798 gs_mouseCapture = this;
a4bbc9f7
VS
799 MGL_wmCaptureEvents(m_wnd, EVT_MOUSEEVT, wxMGL_CAPTURE_MOUSE);
800}
801
4116c221 802void wxWindowMGL::DoReleaseMouse()
a4bbc9f7 803{
63fd5f0b 804 wxASSERT_MSG( gs_mouseCapture == this, wxT("attempt to release mouse, but this window hasn't captured it") );
7de59551 805
a4bbc9f7 806 MGL_wmUncaptureEvents(m_wnd, wxMGL_CAPTURE_MOUSE);
7cdbf02c 807 gs_mouseCapture = NULL;
a4bbc9f7
VS
808}
809
810/* static */ wxWindow *wxWindowBase::GetCapture()
811{
7cdbf02c 812 return (wxWindow*)gs_mouseCapture;
a4bbc9f7
VS
813}
814
815bool wxWindowMGL::SetCursor(const wxCursor& cursor)
816{
817 if ( !wxWindowBase::SetCursor(cursor) )
818 {
819 // no change
127eab18 820 return false;
a4bbc9f7
VS
821 }
822
823 if ( m_cursor.Ok() )
824 MGL_wmSetWindowCursor(m_wnd, *m_cursor.GetMGLCursor());
ef344ff8
VS
825 else
826 MGL_wmSetWindowCursor(m_wnd, *wxSTANDARD_CURSOR->GetMGLCursor());
a4bbc9f7 827
127eab18 828 return true;
a4bbc9f7
VS
829}
830
831void wxWindowMGL::WarpPointer(int x, int y)
832{
8014db41
VS
833 int w, h;
834 wxDisplaySize(&w, &h);
835
a4bbc9f7 836 ClientToScreen(&x, &y);
8014db41
VS
837 if ( x < 0 )
838 x = 0;
839 if ( y < 0 )
840 y = 0;
841 if ( x >= w )
842 x = w-1;
843 if ( y >= h )
844 y = h-1;
7de59551 845
a4bbc9f7
VS
846 EVT_setMousePos(x, y);
847}
848
a4bbc9f7
VS
849// Set this window to be the child of 'parent'.
850bool wxWindowMGL::Reparent(wxWindowBase *parent)
851{
852 if ( !wxWindowBase::Reparent(parent) )
127eab18 853 return false;
a4bbc9f7
VS
854
855 MGL_wmReparentWindow(m_wnd, parent->GetHandle());
856
127eab18 857 return true;
a4bbc9f7
VS
858}
859
860
861// ---------------------------------------------------------------------------
862// drag and drop
863// ---------------------------------------------------------------------------
864
865#if wxUSE_DRAG_AND_DROP
866
867void wxWindowMGL::SetDropTarget(wxDropTarget *pDropTarget)
868{
869 if ( m_dropTarget != 0 ) {
870 m_dropTarget->Revoke(m_hWnd);
871 delete m_dropTarget;
872 }
873
874 m_dropTarget = pDropTarget;
875 if ( m_dropTarget != 0 )
876 m_dropTarget->Register(m_hWnd);
877}
878// FIXME_MGL
879#endif // wxUSE_DRAG_AND_DROP
880
881// old style file-manager drag&drop support: we retain the old-style
882// DragAcceptFiles in parallel with SetDropTarget.
127eab18 883void wxWindowMGL::DragAcceptFiles(bool WXUNUSED(accept))
a4bbc9f7
VS
884{
885#if 0 // FIXME_MGL
886 HWND hWnd = GetHwnd();
887 if ( hWnd )
888 ::DragAcceptFiles(hWnd, (BOOL)accept);
889#endif
890}
891
892// ---------------------------------------------------------------------------
893// moving and resizing
894// ---------------------------------------------------------------------------
895
896// Get total size
897void wxWindowMGL::DoGetSize(int *x, int *y) const
898{
ea98f686 899 wxASSERT_MSG( m_wnd, wxT("invalid window") );
7de59551 900
a4bbc9f7
VS
901 if (x) *x = m_wnd->width;
902 if (y) *y = m_wnd->height;
903}
904
905void wxWindowMGL::DoGetPosition(int *x, int *y) const
906{
ea98f686
VS
907 wxASSERT_MSG( m_wnd, wxT("invalid window") );
908
909 int pX = 0, pY = 0;
7de59551 910 AdjustForParentClientOrigin(pX, pY, 0);
e41dcea5 911
ea98f686
VS
912 if (x) *x = m_wnd->x - pX;
913 if (y) *y = m_wnd->y - pY;
a4bbc9f7
VS
914}
915
916void wxWindowMGL::DoScreenToClient(int *x, int *y) const
917{
918 int ax, ay;
985520bc 919 MGL_wmCoordGlobalToLocal(m_wnd, 0, 0, &ax, &ay);
a4bbc9f7 920 if (x)
985520bc 921 (*x) += ax;
a4bbc9f7 922 if (y)
985520bc 923 (*y) += ay;
a4bbc9f7
VS
924}
925
926void wxWindowMGL::DoClientToScreen(int *x, int *y) const
927{
928 int ax, ay;
985520bc 929 MGL_wmCoordLocalToGlobal(m_wnd, 0, 0, &ax, &ay);
a4bbc9f7 930 if (x)
985520bc 931 (*x) += ax;
a4bbc9f7 932 if (y)
985520bc 933 (*y) += ay;
a4bbc9f7
VS
934}
935
936// Get size *available for subwindows* i.e. excluding menu bar etc.
937void wxWindowMGL::DoGetClientSize(int *x, int *y) const
938{
939 DoGetSize(x, y);
940}
941
942void wxWindowMGL::DoMoveWindow(int x, int y, int width, int height)
943{
1cdab5d1
MW
944 wxRect rcClient(GetClientRect());
945
946 MGL_wmSetWindowPosition(m_wnd, x, y, width, height);
947
948 // When the origin or a window stays fixed but the height or width
949 // changes, invalidate the old and new non-client areas
950 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) &&
951 m_wnd->x == x && m_wnd->y == y &&
952 rcClient.Intersect(GetClientRect()) != wxRect(0, 0, width, height) )
953 {
954 wxRegion rgn(0, 0, width, height);
955 rgn.Subtract(rcClient);
956
957 // This should work I think, but doesn't seem to:
958 //MGL_wmInvalidateWindowRegion(m_wnd, rgn.GetMGLRegion().rgnPointer());
959
960 // Use MGL_wmInvalidateWindowRect instead:
961 for (wxRegionIterator it(rgn); it; it++)
962 {
963 rect_t rc;
964 rc.left = it.GetX();
965 rc.top = it.GetY();
966 rc.right = rc.left + it.GetW();
967 rc.bottom = rc.top + it.GetH();
968 MGL_wmInvalidateWindowRect(m_wnd, &rc);
969 }
970 }
a4bbc9f7
VS
971}
972
973// set the size of the window: if the dimensions are positive, just use them,
974// but if any of them is equal to -1, it means that we must find the value for
975// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
976// which case -1 is a valid value for x and y)
977//
978// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
979// the width/height to best suit our contents, otherwise we reuse the current
980// width/height
981void wxWindowMGL::DoSetSize(int x, int y, int width, int height, int sizeFlags)
982{
983 // get the current size and position...
984 int currentX, currentY;
985 GetPosition(&currentX, &currentY);
986 int currentW,currentH;
987 GetSize(&currentW, &currentH);
988
989 // ... and don't do anything (avoiding flicker) if it's already ok
990 if ( x == currentX && y == currentY &&
991 width == currentW && height == currentH )
992 {
993 return;
994 }
995
996 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
997 x = currentX;
998 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
999 y = currentY;
1000
a4bbc9f7 1001 AdjustForParentClientOrigin(x, y, sizeFlags);
a4bbc9f7
VS
1002
1003 wxSize size(-1, -1);
1004 if ( width == -1 )
1005 {
1006 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1007 {
1008 size = DoGetBestSize();
1009 width = size.x;
1010 }
1011 else
1012 {
1013 // just take the current one
1014 width = currentW;
1015 }
1016 }
7de59551 1017
a4bbc9f7
VS
1018 if ( height == -1 )
1019 {
1020 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1021 {
1022 if ( size.x == -1 )
1023 {
1024 size = DoGetBestSize();
1025 }
1026 //else: already called DoGetBestSize() above
1027
1028 height = size.y;
1029 }
1030 else
1031 {
1032 // just take the current one
1033 height = currentH;
1034 }
1035 }
7de59551 1036
6feddea3 1037 int maxWidth = GetMaxWidth(),
7de59551 1038 minWidth = GetMinWidth(),
6feddea3
VS
1039 maxHeight = GetMaxHeight(),
1040 minHeight = GetMinHeight();
7de59551 1041
6feddea3
VS
1042 if ( minWidth != -1 && width < minWidth ) width = minWidth;
1043 if ( maxWidth != -1 && width > maxWidth ) width = maxWidth;
1044 if ( minHeight != -1 && height < minHeight ) height = minHeight;
1045 if ( maxHeight != -1 && height > maxHeight ) height = maxHeight;
a4bbc9f7 1046
7de59551 1047 if ( m_wnd->x != x || m_wnd->y != y ||
88f2a771
VS
1048 (int)m_wnd->width != width || (int)m_wnd->height != height )
1049 {
1050 DoMoveWindow(x, y, width, height);
a4bbc9f7 1051
127eab18
WS
1052 wxSize newSize(width, height);
1053 wxSizeEvent event(newSize, GetId());
88f2a771 1054 event.SetEventObject(this);
937013e0 1055 HandleWindowEvent(event);
88f2a771 1056 }
a4bbc9f7
VS
1057}
1058
1059void wxWindowMGL::DoSetClientSize(int width, int height)
1060{
1061 SetSize(width, height);
1062}
1063
1064// ---------------------------------------------------------------------------
1065// text metrics
1066// ---------------------------------------------------------------------------
1067
1068int wxWindowMGL::GetCharHeight() const
1069{
1070 wxScreenDC dc;
1071 dc.SetFont(m_font);
1072 return dc.GetCharHeight();
1073}
1074
1075int wxWindowMGL::GetCharWidth() const
1076{
1077 wxScreenDC dc;
1078 dc.SetFont(m_font);
1079 return dc.GetCharWidth();
1080}
1081
1082void wxWindowMGL::GetTextExtent(const wxString& string,
1083 int *x, int *y,
1084 int *descent, int *externalLeading,
1085 const wxFont *theFont) const
1086{
1087 wxScreenDC dc;
1088 if (!theFont)
1089 theFont = &m_font;
1090 dc.GetTextExtent(string, x, y, descent, externalLeading, (wxFont*)theFont);
1091}
1092
a4bbc9f7 1093
a4bbc9f7
VS
1094// ---------------------------------------------------------------------------
1095// painting
1096// ---------------------------------------------------------------------------
1097
2b260bc3 1098void wxWindowMGL::Refresh(bool eraseBack, const wxRect *rect)
a4bbc9f7 1099{
2b260bc3
VS
1100 if ( m_eraseBackground == -1 )
1101 m_eraseBackground = eraseBack;
1102 else
1103 m_eraseBackground |= eraseBack;
7de59551 1104
a4bbc9f7
VS
1105 if ( rect )
1106 {
1107 rect_t r;
1108 r.left = rect->GetLeft(), r.right = rect->GetRight();
1109 r.top = rect->GetTop(), r.bottom = rect->GetBottom();
1110 MGL_wmInvalidateWindowRect(GetHandle(), &r);
1111 }
1112 else
1113 MGL_wmInvalidateWindow(GetHandle());
1114}
1115
1116void wxWindowMGL::Update()
1117{
17808a75 1118 if ( !IsFrozen() )
a4bbc9f7
VS
1119 MGL_wmUpdateDC(g_winMng);
1120}
1121
17808a75 1122void wxWindowMGL::DoFreeze()
a4bbc9f7 1123{
127eab18 1124 m_refreshAfterThaw = false;
a4bbc9f7
VS
1125}
1126
17808a75 1127void wxWindowMGL::DoThaw()
a4bbc9f7 1128{
a4bbc9f7
VS
1129 if ( m_refreshAfterThaw )
1130 Refresh();
1131}
1132
a4bbc9f7
VS
1133void wxWindowMGL::HandlePaint(MGLDevCtx *dc)
1134{
17808a75 1135 if ( IsFrozen() )
a4bbc9f7 1136 {
7de59551 1137 // Don't paint anything if the window is frozen.
127eab18 1138 m_refreshAfterThaw = true;
a4bbc9f7
VS
1139 return;
1140 }
7de59551
RD
1141
1142#ifdef __WXDEBUG__
82186005
VS
1143 // FIXME_MGL -- debugging stuff, to be removed!
1144 static int debugPaintEvents = -1;
1145 if ( debugPaintEvents == -1 )
1146 debugPaintEvents = wxGetEnv(wxT("WXMGL_DEBUG_PAINT_EVENTS"), NULL);
1147 if ( debugPaintEvents )
1148 {
1149 dc->setColorRGB(255,0,255);
1150 dc->fillRect(-1000,-1000,2000,2000);
06414d99 1151 wxMilliSleep(50);
82186005 1152 }
b8c0528d
VS
1153#endif
1154
fd495ab3
VS
1155 MGLRegion clip;
1156 dc->getClipRegion(clip);
1157 m_updateRegion = wxRegion(clip);
a4bbc9f7
VS
1158 m_paintMGLDC = dc;
1159
a679e129
VS
1160#if wxUSE_CARET
1161 // must hide caret temporarily, otherwise we'd get rendering artifacts
1162 wxCaret *caret = GetCaret();
1163 if ( caret )
1164 caret->Hide();
1165#endif // wxUSE_CARET
1166
2b260bc3 1167 if ( m_eraseBackground != 0 )
7bdc1879 1168 {
2b260bc3
VS
1169 wxWindowDC dc((wxWindow*)this);
1170 wxEraseEvent eventEr(m_windowId, &dc);
1171 eventEr.SetEventObject(this);
937013e0 1172 HandleWindowEvent(eventEr);
7bdc1879 1173 }
2b260bc3 1174 m_eraseBackground = -1;
a4bbc9f7
VS
1175
1176 wxNcPaintEvent eventNc(GetId());
1177 eventNc.SetEventObject(this);
937013e0 1178 HandleWindowEvent(eventNc);
7de59551 1179
a4bbc9f7
VS
1180 wxPaintEvent eventPt(GetId());
1181 eventPt.SetEventObject(this);
937013e0 1182 HandleWindowEvent(eventPt);
a4bbc9f7 1183
a679e129
VS
1184#if wxUSE_CARET
1185 if ( caret )
1186 caret->Show();
1187#endif // wxUSE_CARET
1188
7bdc1879 1189 m_paintMGLDC = NULL;
fd495ab3 1190 m_updateRegion.Clear();
a4bbc9f7
VS
1191}
1192
1193
1194// Find the wxWindow at the current mouse position, returning the mouse
1195// position.
1196wxWindow* wxFindWindowAtPointer(wxPoint& pt)
1197{
1198 return wxFindWindowAtPoint(pt = wxGetMousePosition());
1199}
1200
1201wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
1202{
1203 window_t *wnd = MGL_wmGetWindowAtPosition(g_winMng, pt.x, pt.y);
1204 return (wxWindow*)wnd->userData;
32b8ec41 1205}
d53fc7c9
VS
1206
1207
1208// ---------------------------------------------------------------------------
1209// idle events processing
1210// ---------------------------------------------------------------------------
1211
e39af974 1212void wxWindowMGL::OnInternalIdle()
d53fc7c9 1213{
24bd6cb9 1214 if (wxUpdateUIEvent::CanUpdate(this) && IsShown())
e39af974 1215 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
d53fc7c9 1216}