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