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