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