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