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