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