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