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