]>
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$ | |
eea93267 | 7 | // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) |
65571936 | 8 | // Licence: wxWindows licence |
32b8ec41 VZ |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
a4bbc9f7 VS |
11 | // =========================================================================== |
12 | // declarations | |
13 | // =========================================================================== | |
14 | ||
15 | // --------------------------------------------------------------------------- | |
16 | // headers | |
17 | // --------------------------------------------------------------------------- | |
32b8ec41 | 18 | |
a4bbc9f7 VS |
19 | // For compilers that support precompilation, includes "wx.h". |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
26 | #ifndef WX_PRECOMP | |
27 | #include "wx/window.h" | |
d53fc7c9 | 28 | #include "wx/msgdlg.h" |
a4bbc9f7 VS |
29 | #include "wx/accel.h" |
30 | #include "wx/setup.h" | |
31 | #include "wx/dc.h" | |
32 | #include "wx/dcclient.h" | |
33 | #include "wx/utils.h" | |
34 | #include "wx/app.h" | |
35 | #include "wx/panel.h" | |
a4bbc9f7 VS |
36 | #endif |
37 | ||
38 | #if wxUSE_DRAG_AND_DROP | |
39 | #include "wx/dnd.h" | |
40 | #endif | |
41 | ||
42 | #include "wx/log.h" | |
43 | #include "wx/sysopt.h" | |
44 | #include "wx/mgl/private.h" | |
45 | #include "wx/intl.h" | |
46 | #include "wx/dcscreen.h" | |
90eb13e6 | 47 | #include "wx/caret.h" |
a4bbc9f7 VS |
48 | |
49 | #include <mgraph.hpp> | |
50 | ||
51 | #if wxUSE_TOOLTIPS | |
52 | #include "wx/tooltip.h" | |
53 | #endif | |
54 | ||
55 | // --------------------------------------------------------------------------- | |
56 | // global variables | |
57 | // --------------------------------------------------------------------------- | |
58 | ||
59 | // MGL window manager and associated DC. | |
60 | winmng_t *g_winMng = NULL; | |
61 | MGLDevCtx *g_displayDC = NULL; | |
62 | ||
7de59551 | 63 | // the window that has keyboard focus: |
7cdbf02c | 64 | static wxWindowMGL *gs_focusedWindow = NULL; |
7de59551 | 65 | // the window that is about to be focused after currently focused |
eea93267 VS |
66 | // one looses focus: |
67 | static wxWindow *gs_toBeFocusedWindow = 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 | ||
7de59551 | 80 | // Custom identifiers used to distinguish between various event handlers |
a4bbc9f7 VS |
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 | ||
7cdbf02c VS |
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 | ||
d53fc7c9 | 102 | // An easy way to capture screenshots: |
2d1efe3f | 103 | static void wxCaptureScreenshot(bool activeWindowOnly) |
e6daf008 | 104 | { |
d53fc7c9 VS |
105 | #ifdef __DOS__ |
106 | #define SCREENSHOT_FILENAME _T("sshot%03i.png") | |
107 | #else | |
108 | #define SCREENSHOT_FILENAME _T("screenshot-%03i.png") | |
109 | #endif | |
e6daf008 | 110 | static int screenshot_num = 0; |
d53fc7c9 | 111 | wxString screenshot; |
7de59551 RD |
112 | |
113 | do | |
d53fc7c9 VS |
114 | { |
115 | screenshot.Printf(SCREENSHOT_FILENAME, screenshot_num++); | |
116 | } while ( wxFileExists(screenshot) && screenshot_num < 1000 ); | |
7de59551 | 117 | |
2d1efe3f VS |
118 | wxRect r(0, 0, g_displayDC->sizex(), g_displayDC->sizey()); |
119 | ||
120 | if ( activeWindowOnly && gs_activeFrame ) | |
121 | { | |
122 | r.Intersect(gs_activeFrame->GetRect()); | |
123 | } | |
7de59551 RD |
124 | |
125 | g_displayDC->savePNGFromDC(screenshot.mb_str(), | |
06534aa1 | 126 | r.x, r. y, r.x+r.width, r.y+r.height); |
7de59551 | 127 | |
2b5f62a0 VZ |
128 | wxMessageBox(wxString::Format(_T("Screenshot captured: %s"), |
129 | screenshot.c_str())); | |
e6daf008 | 130 | } |
e6daf008 | 131 | |
7bdc1879 VS |
132 | // --------------------------------------------------------------------------- |
133 | // MGL_WM hooks: | |
134 | // --------------------------------------------------------------------------- | |
135 | ||
b43a9886 | 136 | static void MGLAPI wxWindowPainter(window_t *wnd, MGLDC *dc) |
7bdc1879 VS |
137 | { |
138 | wxWindowMGL *w = (wxWindow*) wnd->userData; | |
7de59551 | 139 | |
544c782d | 140 | if ( w && !(w->GetWindowStyle() & wxTRANSPARENT_WINDOW) ) |
7bdc1879 VS |
141 | { |
142 | MGLDevCtx ctx(dc); | |
143 | w->HandlePaint(&ctx); | |
144 | } | |
ef344ff8 VS |
145 | } |
146 | ||
b43a9886 | 147 | static ibool MGLAPI wxWindowMouseHandler(window_t *wnd, event_t *e) |
ef344ff8 VS |
148 | { |
149 | wxWindowMGL *win = (wxWindowMGL*)MGL_wmGetWindowUserData(wnd); | |
d76048f5 | 150 | wxPoint orig(win->GetClientAreaOrigin()); |
985520bc | 151 | wxPoint where; |
7de59551 RD |
152 | |
153 | MGL_wmCoordGlobalToLocal(win->GetHandle(), | |
985520bc VS |
154 | e->where_x, e->where_y, &where.x, &where.y); |
155 | ||
0a89ac9c VS |
156 | for (wxWindowMGL *w = win; w; w = w->GetParent()) |
157 | { | |
7de59551 | 158 | if ( !w->IsEnabled() ) |
0a89ac9c VS |
159 | return FALSE; |
160 | if ( w->IsTopLevel() ) | |
161 | break; | |
162 | } | |
7de59551 | 163 | |
ef344ff8 VS |
164 | wxEventType type = wxEVT_NULL; |
165 | wxMouseEvent event; | |
166 | event.SetEventObject(win); | |
167 | event.SetTimestamp(e->when); | |
d76048f5 VS |
168 | event.m_x = where.x - orig.x; |
169 | event.m_y = where.y - orig.y; | |
127eab18 WS |
170 | event.m_shiftDown = ( e->modifiers & EVT_SHIFTKEY ) == EVT_SHIFTKEY; |
171 | event.m_controlDown = ( e->modifiers & EVT_CTRLSTATE ) == EVT_CTRLSTATE; | |
172 | event.m_altDown = ( e->modifiers & EVT_LEFTALT ) == EVT_LEFTALT; | |
173 | event.m_metaDown = ( e->modifiers & EVT_RIGHTALT ) == EVT_RIGHTALT; | |
174 | event.m_leftDown = ( e->modifiers & EVT_LEFTBUT ) == EVT_LEFTBUT; | |
175 | event.m_middleDown = ( e->modifiers & EVT_MIDDLEBUT ) == EVT_MIDDLEBUT; | |
176 | event.m_rightDown = ( e->modifiers & EVT_RIGHTBUT ) == EVT_RIGHTBUT; | |
7de59551 | 177 | |
ef344ff8 VS |
178 | switch (e->what) |
179 | { | |
180 | case EVT_MOUSEDOWN: | |
8f5e92db VS |
181 | // Change focus if the user clicks outside focused window: |
182 | if ( win->AcceptsFocus() && wxWindow::FindFocus() != win ) | |
183 | win->SetFocus(); | |
184 | ||
8f5e92db VS |
185 | if ( e->message & EVT_DBLCLICK ) |
186 | { | |
8f5e92db VS |
187 | if ( e->message & EVT_LEFTBMASK ) |
188 | type = wxEVT_LEFT_DCLICK; | |
189 | else if ( e->message & EVT_MIDDLEBMASK ) | |
190 | type = wxEVT_MIDDLE_DCLICK; | |
191 | else if ( e->message & EVT_RIGHTBMASK ) | |
192 | type = wxEVT_RIGHT_DCLICK; | |
193 | } | |
ea98f686 VS |
194 | else |
195 | { | |
196 | if ( e->message & EVT_LEFTBMASK ) | |
197 | type = wxEVT_LEFT_DOWN; | |
198 | else if ( e->message & EVT_MIDDLEBMASK ) | |
199 | type = wxEVT_MIDDLE_DOWN; | |
200 | else if ( e->message & EVT_RIGHTBMASK ) | |
201 | type = wxEVT_RIGHT_DOWN; | |
202 | } | |
a679e129 | 203 | |
ef344ff8 VS |
204 | break; |
205 | ||
206 | case EVT_MOUSEUP: | |
207 | if ( e->message & EVT_LEFTBMASK ) | |
208 | type = wxEVT_LEFT_UP; | |
209 | else if ( e->message & EVT_MIDDLEBMASK ) | |
210 | type = wxEVT_MIDDLE_UP; | |
211 | else if ( e->message & EVT_RIGHTBMASK ) | |
212 | type = wxEVT_RIGHT_UP; | |
213 | break; | |
214 | ||
215 | case EVT_MOUSEMOVE: | |
7cdbf02c VS |
216 | if ( !gs_mouseCapture ) |
217 | { | |
218 | if ( win != gs_windowUnderMouse ) | |
219 | { | |
220 | if ( gs_windowUnderMouse ) | |
221 | { | |
222 | wxMouseEvent event2(event); | |
7de59551 RD |
223 | MGL_wmCoordGlobalToLocal(gs_windowUnderMouse->GetHandle(), |
224 | e->where_x, e->where_y, | |
7cdbf02c VS |
225 | &event2.m_x, &event2.m_y); |
226 | ||
d76048f5 VS |
227 | wxPoint orig(gs_windowUnderMouse->GetClientAreaOrigin()); |
228 | event2.m_x -= orig.x; | |
229 | event2.m_y -= orig.y; | |
230 | ||
7cdbf02c VS |
231 | event2.SetEventObject(gs_windowUnderMouse); |
232 | event2.SetEventType(wxEVT_LEAVE_WINDOW); | |
233 | gs_windowUnderMouse->GetEventHandler()->ProcessEvent(event2); | |
234 | } | |
235 | ||
236 | wxMouseEvent event3(event); | |
237 | event3.SetEventType(wxEVT_ENTER_WINDOW); | |
238 | win->GetEventHandler()->ProcessEvent(event3); | |
239 | ||
240 | gs_windowUnderMouse = win; | |
241 | } | |
242 | } | |
243 | else // gs_mouseCapture | |
ef344ff8 | 244 | { |
7de59551 | 245 | bool inside = (where.x >= 0 && |
7cdbf02c VS |
246 | where.y >= 0 && |
247 | where.x < win->GetSize().x && | |
248 | where.y < win->GetSize().y); | |
249 | if ( (inside && gs_windowUnderMouse != win) || | |
250 | (!inside && gs_windowUnderMouse == win) ) | |
ef344ff8 | 251 | { |
7de59551 | 252 | wxMouseEvent evt(inside ? |
7cdbf02c VS |
253 | wxEVT_ENTER_WINDOW : wxEVT_LEAVE_WINDOW); |
254 | evt.SetEventObject(win); | |
255 | win->GetEventHandler()->ProcessEvent(evt); | |
256 | gs_windowUnderMouse = inside ? win : NULL; | |
ef344ff8 | 257 | } |
ef344ff8 | 258 | } |
7de59551 | 259 | |
ef344ff8 VS |
260 | type = wxEVT_MOTION; |
261 | break; | |
262 | ||
263 | default: | |
264 | break; | |
265 | } | |
7de59551 | 266 | |
ef344ff8 VS |
267 | if ( type == wxEVT_NULL ) |
268 | { | |
269 | return FALSE; | |
270 | } | |
271 | else | |
272 | { | |
273 | event.SetEventType(type); | |
274 | return win->GetEventHandler()->ProcessEvent(event); | |
275 | } | |
276 | } | |
277 | ||
a679e129 | 278 | static long wxScanToKeyCode(event_t *event, bool translate) |
ef344ff8 | 279 | { |
84c88a17 VS |
280 | // VS: make it __WXDEBUG__-only, since we have lots of wxLogTrace calls |
281 | // here and the arguments would be stored in non-debug executable even | |
282 | // though wxLogTrace would be no-op... | |
283 | #ifdef __WXDEBUG__ | |
284 | #define KEY(mgl_key,wx_key) \ | |
285 | case mgl_key: \ | |
286 | wxLogTrace(_T("keyevents"), \ | |
287 | _T("key " #mgl_key ", mapped to " #wx_key)); \ | |
288 | key = wx_key; \ | |
289 | break; | |
290 | #else | |
291 | #define KEY(mgl_key,wx_key) \ | |
7de59551 | 292 | case mgl_key: key = wx_key; break; |
84c88a17 | 293 | #endif |
2b260bc3 VS |
294 | |
295 | long key = 0; | |
7de59551 | 296 | |
a679e129 | 297 | if ( translate ) |
2b260bc3 | 298 | { |
a679e129 VS |
299 | switch ( EVT_scanCode(event->message) ) |
300 | { | |
301 | KEY (KB_padMinus, WXK_NUMPAD_SUBTRACT) | |
302 | KEY (KB_padPlus, WXK_NUMPAD_ADD) | |
303 | KEY (KB_padTimes, WXK_NUMPAD_MULTIPLY) | |
304 | KEY (KB_padDivide, WXK_NUMPAD_DIVIDE) | |
305 | KEY (KB_padCenter, WXK_NUMPAD_SEPARATOR) // ? | |
306 | KEY (KB_padLeft, WXK_NUMPAD_LEFT) | |
307 | KEY (KB_padRight, WXK_NUMPAD_RIGHT) | |
308 | KEY (KB_padUp, WXK_NUMPAD_UP) | |
309 | KEY (KB_padDown, WXK_NUMPAD_DOWN) | |
310 | KEY (KB_padInsert, WXK_NUMPAD_INSERT) | |
311 | KEY (KB_padDelete, WXK_NUMPAD_DELETE) | |
312 | KEY (KB_padHome, WXK_NUMPAD_HOME) | |
313 | KEY (KB_padEnd, WXK_NUMPAD_END) | |
314 | KEY (KB_padPageUp, WXK_NUMPAD_PAGEUP) | |
315 | //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR) | |
316 | KEY (KB_padPageDown, WXK_NUMPAD_PAGEDOWN) | |
317 | //KEY (KB_padPageDown, WXK_NUMPAD_NEXT) | |
318 | KEY (KB_1, '1') | |
319 | KEY (KB_2, '2') | |
320 | KEY (KB_3, '3') | |
321 | KEY (KB_4, '4') | |
322 | KEY (KB_5, '5') | |
323 | KEY (KB_6, '6') | |
324 | KEY (KB_7, '7') | |
325 | KEY (KB_8, '8') | |
326 | KEY (KB_9, '9') | |
327 | KEY (KB_0, '0') | |
328 | KEY (KB_minus, WXK_SUBTRACT) | |
329 | KEY (KB_equals, WXK_ADD) | |
330 | KEY (KB_backSlash, '\\') | |
331 | KEY (KB_Q, 'Q') | |
332 | KEY (KB_W, 'W') | |
333 | KEY (KB_E, 'E') | |
334 | KEY (KB_R, 'R') | |
335 | KEY (KB_T, 'T') | |
336 | KEY (KB_Y, 'Y') | |
337 | KEY (KB_U, 'U') | |
338 | KEY (KB_I, 'I') | |
339 | KEY (KB_O, 'O') | |
340 | KEY (KB_P, 'P') | |
341 | KEY (KB_leftSquareBrace,'[') | |
342 | KEY (KB_rightSquareBrace,']') | |
343 | KEY (KB_A, 'A') | |
344 | KEY (KB_S, 'S') | |
345 | KEY (KB_D, 'D') | |
346 | KEY (KB_F, 'F') | |
347 | KEY (KB_G, 'G') | |
348 | KEY (KB_H, 'H') | |
349 | KEY (KB_J, 'J') | |
350 | KEY (KB_K, 'K') | |
351 | KEY (KB_L, 'L') | |
352 | KEY (KB_semicolon, ';') | |
353 | KEY (KB_apostrophe, '\'') | |
354 | KEY (KB_Z, 'Z') | |
355 | KEY (KB_X, 'X') | |
356 | KEY (KB_C, 'C') | |
357 | KEY (KB_V, 'V') | |
358 | KEY (KB_B, 'B') | |
359 | KEY (KB_N, 'N') | |
360 | KEY (KB_M, 'M') | |
361 | KEY (KB_comma, ',') | |
362 | KEY (KB_period, '.') | |
363 | KEY (KB_divide, WXK_DIVIDE) | |
364 | KEY (KB_space, WXK_SPACE) | |
365 | KEY (KB_tilde, '~') | |
366 | ||
367 | default: break; | |
368 | } | |
369 | } | |
7de59551 | 370 | |
a679e129 VS |
371 | if ( key == 0 ) |
372 | { | |
373 | switch ( EVT_scanCode(event->message) ) | |
374 | { | |
375 | KEY (KB_padEnter, WXK_NUMPAD_ENTER) | |
376 | KEY (KB_F1, WXK_F1) | |
377 | KEY (KB_F2, WXK_F2) | |
378 | KEY (KB_F3, WXK_F3) | |
379 | KEY (KB_F4, WXK_F4) | |
380 | KEY (KB_F5, WXK_F5) | |
381 | KEY (KB_F6, WXK_F6) | |
382 | KEY (KB_F7, WXK_F7) | |
383 | KEY (KB_F8, WXK_F8) | |
384 | KEY (KB_F9, WXK_F9) | |
385 | KEY (KB_F10, WXK_F10) | |
386 | KEY (KB_F11, WXK_F11) | |
387 | KEY (KB_F12, WXK_F12) | |
388 | KEY (KB_left, WXK_LEFT) | |
389 | KEY (KB_right, WXK_RIGHT) | |
390 | KEY (KB_up, WXK_UP) | |
391 | KEY (KB_down, WXK_DOWN) | |
392 | KEY (KB_insert, WXK_INSERT) | |
393 | KEY (KB_delete, WXK_DELETE) | |
394 | KEY (KB_home, WXK_HOME) | |
395 | KEY (KB_end, WXK_END) | |
396 | KEY (KB_pageUp, WXK_PAGEUP) | |
397 | KEY (KB_pageDown, WXK_PAGEDOWN) | |
398 | KEY (KB_capsLock, WXK_CAPITAL) | |
399 | KEY (KB_numLock, WXK_NUMLOCK) | |
400 | KEY (KB_scrollLock, WXK_SCROLL) | |
401 | KEY (KB_leftShift, WXK_SHIFT) | |
402 | KEY (KB_rightShift, WXK_SHIFT) | |
403 | KEY (KB_leftCtrl, WXK_CONTROL) | |
404 | KEY (KB_rightCtrl, WXK_CONTROL) | |
405 | KEY (KB_leftAlt, WXK_ALT) | |
406 | KEY (KB_rightAlt, WXK_ALT) | |
407 | KEY (KB_leftWindows, WXK_START) | |
408 | KEY (KB_rightWindows, WXK_START) | |
409 | KEY (KB_menu, WXK_MENU) | |
410 | KEY (KB_sysReq, WXK_SNAPSHOT) | |
411 | KEY (KB_esc, WXK_ESCAPE) | |
412 | KEY (KB_backspace, WXK_BACK) | |
413 | KEY (KB_tab, WXK_TAB) | |
7de59551 | 414 | KEY (KB_enter, WXK_RETURN) |
a679e129 | 415 | |
7de59551 RD |
416 | default: |
417 | key = EVT_asciiCode(event->message); | |
a679e129 VS |
418 | break; |
419 | } | |
2b260bc3 VS |
420 | } |
421 | ||
544c782d VS |
422 | #undef KEY |
423 | ||
2b260bc3 | 424 | return key; |
ef344ff8 VS |
425 | } |
426 | ||
d53fc7c9 VS |
427 | static bool wxHandleSpecialKeys(wxKeyEvent& event) |
428 | { | |
429 | // Add an easy way to capture screenshots: | |
430 | if ( event.m_keyCode == WXK_SNAPSHOT | |
431 | #ifdef __WXDEBUG__ // FIXME_MGL - remove when KB_sysReq works in MGL! | |
7de59551 RD |
432 | || (event.m_keyCode == WXK_F1 && |
433 | event.m_shiftDown && event.m_controlDown) | |
d53fc7c9 | 434 | #endif |
197b1626 | 435 | ) |
d53fc7c9 | 436 | { |
2d1efe3f | 437 | wxCaptureScreenshot(event.m_altDown/*only active wnd?*/); |
127eab18 | 438 | return true; |
d53fc7c9 | 439 | } |
7de59551 | 440 | |
127eab18 | 441 | return false; |
d53fc7c9 VS |
442 | } |
443 | ||
b43a9886 | 444 | static ibool MGLAPI wxWindowKeybHandler(window_t *wnd, event_t *e) |
2b260bc3 | 445 | { |
2b260bc3 | 446 | wxWindowMGL *win = (wxWindowMGL*)MGL_wmGetWindowUserData(wnd); |
a200c35e VS |
447 | |
448 | if ( !win->IsEnabled() ) return FALSE; | |
449 | ||
985520bc | 450 | wxPoint where; |
7de59551 | 451 | MGL_wmCoordGlobalToLocal(win->GetHandle(), |
985520bc | 452 | e->where_x, e->where_y, &where.x, &where.y); |
7de59551 | 453 | |
2b260bc3 VS |
454 | wxKeyEvent event; |
455 | event.SetEventObject(win); | |
456 | event.SetTimestamp(e->when); | |
127eab18 | 457 | event.m_keyCode = wxScanToKeyCode(e, true); |
2b260bc3 VS |
458 | event.m_scanCode = 0; // not used by wx at all |
459 | event.m_x = where.x; | |
460 | event.m_y = where.y; | |
127eab18 WS |
461 | event.m_shiftDown = ( e->modifiers & EVT_SHIFTKEY ) == EVT_SHIFTKEY; |
462 | event.m_controlDown = ( e->modifiers & EVT_CTRLSTATE ) == EVT_CTRLSTATE; | |
463 | event.m_altDown = ( e->modifiers & EVT_LEFTALT ) == EVT_LEFTALT; | |
464 | event.m_metaDown = ( e->modifiers & EVT_RIGHTALT ) == EVT_RIGHTALT; | |
2b260bc3 VS |
465 | |
466 | if ( e->what == EVT_KEYUP ) | |
467 | { | |
468 | event.SetEventType(wxEVT_KEY_UP); | |
469 | return win->GetEventHandler()->ProcessEvent(event); | |
470 | } | |
471 | else | |
472 | { | |
473 | bool ret; | |
474 | wxKeyEvent event2; | |
475 | ||
476 | event.SetEventType(wxEVT_KEY_DOWN); | |
477 | event2 = event; | |
7de59551 | 478 | |
2b260bc3 VS |
479 | ret = win->GetEventHandler()->ProcessEvent(event); |
480 | ||
84c88a17 VS |
481 | // wxMSW doesn't send char events with Alt pressed |
482 | // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x | |
d53fc7c9 | 483 | // will only be sent if it is not in an accelerator table: |
127eab18 | 484 | event2.m_keyCode = wxScanToKeyCode(e, false); |
2b260bc3 VS |
485 | if ( !ret && event2.m_keyCode != 0 ) |
486 | { | |
487 | event2.SetEventType(wxEVT_CHAR); | |
488 | ret = win->GetEventHandler()->ProcessEvent(event2); | |
489 | } | |
7de59551 | 490 | |
84c88a17 | 491 | // Synthetize navigation key event, but do it only if the TAB key |
d53fc7c9 | 492 | // wasn't handled yet: |
84c88a17 VS |
493 | if ( !ret && event.m_keyCode == WXK_TAB && |
494 | win->GetParent() && win->GetParent()->HasFlag(wxTAB_TRAVERSAL) ) | |
495 | { | |
496 | wxNavigationKeyEvent navEvent; | |
497 | navEvent.SetEventObject(win->GetParent()); | |
498 | // Shift-TAB goes in reverse direction: | |
499 | navEvent.SetDirection(!event.m_shiftDown); | |
500 | // Ctrl-TAB changes the (parent) window, i.e. switch notebook page: | |
501 | navEvent.SetWindowChange(event.m_controlDown); | |
502 | navEvent.SetCurrentFocus(wxStaticCast(win, wxWindow)); | |
503 | ret = win->GetParent()->GetEventHandler()->ProcessEvent(navEvent); | |
504 | } | |
7de59551 RD |
505 | |
506 | // Finally, process special meaning keys that are usually | |
d53fc7c9 VS |
507 | // a responsibility of OS or window manager: |
508 | if ( !ret ) | |
509 | ret = wxHandleSpecialKeys(event); | |
7de59551 | 510 | |
2b260bc3 VS |
511 | return ret; |
512 | } | |
7bdc1879 | 513 | } |
a4bbc9f7 VS |
514 | |
515 | // --------------------------------------------------------------------------- | |
516 | // event tables | |
517 | // --------------------------------------------------------------------------- | |
518 | ||
ef344ff8 | 519 | // in wxUniv this class is abstract because it doesn't have DoPopupMenu() |
a4bbc9f7 VS |
520 | IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL, wxWindowBase) |
521 | ||
522 | BEGIN_EVENT_TABLE(wxWindowMGL, wxWindowBase) | |
a4bbc9f7 VS |
523 | END_EVENT_TABLE() |
524 | ||
525 | // =========================================================================== | |
526 | // implementation | |
527 | // =========================================================================== | |
528 | ||
529 | // ---------------------------------------------------------------------------- | |
530 | // constructors and such | |
531 | // ---------------------------------------------------------------------------- | |
532 | ||
1c53456f | 533 | extern wxVideoMode wxGetDefaultDisplayMode(); |
a3e76614 | 534 | |
a4bbc9f7 VS |
535 | void wxWindowMGL::Init() |
536 | { | |
1f43b5c9 VS |
537 | // First of all, make sure window manager is up and running. If it is |
538 | // not the case, initialize it in default display mode | |
539 | if ( !g_winMng ) | |
7b9f73d2 VS |
540 | { |
541 | if ( !wxTheApp->SetDisplayMode(wxGetDefaultDisplayMode()) ) | |
a1f7eb20 | 542 | wxLogFatalError(_("Cannot initialize display.")); |
7b9f73d2 | 543 | } |
1f43b5c9 | 544 | |
a4bbc9f7 | 545 | // mgl specific: |
a4bbc9f7 | 546 | m_wnd = NULL; |
127eab18 WS |
547 | m_isShown = true; |
548 | m_frozen = false; | |
a4bbc9f7 | 549 | m_paintMGLDC = NULL; |
2b260bc3 | 550 | m_eraseBackground = -1; |
a4bbc9f7 VS |
551 | } |
552 | ||
553 | // Destructor | |
554 | wxWindowMGL::~wxWindowMGL() | |
555 | { | |
7de59551 RD |
556 | SendDestroyEvent(); |
557 | ||
127eab18 | 558 | m_isBeingDeleted = true; |
a4bbc9f7 | 559 | |
7cdbf02c VS |
560 | if ( gs_mouseCapture == this ) |
561 | ReleaseMouse(); | |
d46330c5 | 562 | |
7cdbf02c | 563 | if (gs_activeFrame == this) |
d46330c5 | 564 | { |
66858adf VS |
565 | gs_activeFrame = NULL; |
566 | // activate next frame in Z-order: | |
567 | if ( m_wnd->prev ) | |
568 | { | |
569 | wxWindowMGL *win = (wxWindowMGL*)m_wnd->prev->userData; | |
570 | win->SetFocus(); | |
571 | } | |
572 | else if ( m_wnd->next ) | |
573 | { | |
574 | wxWindowMGL *win = (wxWindowMGL*)m_wnd->next->userData; | |
575 | win->SetFocus(); | |
d46330c5 | 576 | } |
d46330c5 | 577 | } |
7de59551 | 578 | |
7cdbf02c | 579 | if ( gs_focusedWindow == this ) |
7bdc1879 | 580 | KillFocus(); |
d46330c5 | 581 | |
7cdbf02c VS |
582 | if ( gs_windowUnderMouse == this ) |
583 | gs_windowUnderMouse = NULL; | |
a4bbc9f7 | 584 | |
a4bbc9f7 VS |
585 | DestroyChildren(); |
586 | ||
a4bbc9f7 VS |
587 | if ( m_wnd ) |
588 | MGL_wmDestroyWindow(m_wnd); | |
589 | } | |
590 | ||
591 | // real construction (Init() must have been called before!) | |
592 | bool wxWindowMGL::Create(wxWindow *parent, | |
593 | wxWindowID id, | |
594 | const wxPoint& pos, | |
595 | const wxSize& size, | |
596 | long style, | |
597 | const wxString& name) | |
598 | { | |
a4bbc9f7 | 599 | if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) |
127eab18 | 600 | return false; |
a4bbc9f7 | 601 | |
544c782d | 602 | if ( parent ) |
7bdc1879 | 603 | parent->AddChild(this); |
a4bbc9f7 | 604 | |
ef344ff8 VS |
605 | int x, y, w, h; |
606 | x = pos.x, y = pos.y; | |
607 | if ( x == -1 ) | |
608 | x = 0; // FIXME_MGL, something better, see GTK+ | |
609 | if ( y == -1 ) | |
610 | y = 0; // FIXME_MGL, something better, see GTK+ | |
82186005 | 611 | AdjustForParentClientOrigin(x, y, 0); |
ef344ff8 VS |
612 | w = WidthDefault(size.x); |
613 | h = HeightDefault(size.y); | |
7de59551 | 614 | |
72fa862b | 615 | long mgl_style = 0; |
7cdbf02c | 616 | window_t *wnd_parent = parent ? parent->GetHandle() : NULL; |
544c782d | 617 | |
e441e1f4 | 618 | if ( style & wxFULL_REPAINT_ON_RESIZE ) |
544c782d | 619 | { |
72fa862b | 620 | mgl_style |= MGL_WM_FULL_REPAINT_ON_RESIZE; |
544c782d | 621 | } |
72fa862b | 622 | if ( style & wxSTAY_ON_TOP ) |
544c782d | 623 | { |
72fa862b | 624 | mgl_style |= MGL_WM_ALWAYS_ON_TOP; |
544c782d VS |
625 | } |
626 | if ( style & wxPOPUP_WINDOW ) | |
627 | { | |
7cdbf02c | 628 | mgl_style |= MGL_WM_ALWAYS_ON_TOP; |
544c782d | 629 | // it is created hidden as other top level windows |
127eab18 | 630 | m_isShown = false; |
7cdbf02c | 631 | wnd_parent = NULL; |
544c782d | 632 | } |
ef344ff8 | 633 | |
58061670 VS |
634 | window_t *wnd = MGL_wmCreateWindow(g_winMng, wnd_parent, x, y, w, h); |
635 | ||
636 | MGL_wmSetWindowFlags(wnd, mgl_style); | |
637 | MGL_wmShowWindow(wnd, m_isShown); | |
7de59551 | 638 | |
58061670 VS |
639 | SetMGLwindow_t(wnd); |
640 | ||
127eab18 | 641 | return true; |
58061670 VS |
642 | } |
643 | ||
644 | void wxWindowMGL::SetMGLwindow_t(struct window_t *wnd) | |
645 | { | |
646 | if ( m_wnd ) | |
647 | MGL_wmDestroyWindow(m_wnd); | |
648 | ||
649 | m_wnd = wnd; | |
650 | if ( !m_wnd ) return; | |
7de59551 | 651 | |
127eab18 | 652 | m_isShown = (bool)m_wnd->visible; |
ef344ff8 | 653 | |
a4bbc9f7 VS |
654 | MGL_wmSetWindowUserData(m_wnd, (void*) this); |
655 | MGL_wmSetWindowPainter(m_wnd, wxWindowPainter); | |
ef344ff8 VS |
656 | MGL_wmPushWindowEventHandler(m_wnd, wxWindowMouseHandler, EVT_MOUSEEVT, 0); |
657 | MGL_wmPushWindowEventHandler(m_wnd, wxWindowKeybHandler, EVT_KEYEVT, 0); | |
58061670 VS |
658 | |
659 | if ( m_cursor.Ok() ) | |
660 | MGL_wmSetWindowCursor(m_wnd, *m_cursor.GetMGLCursor()); | |
661 | else | |
662 | MGL_wmSetWindowCursor(m_wnd, *wxSTANDARD_CURSOR->GetMGLCursor()); | |
a4bbc9f7 VS |
663 | } |
664 | ||
665 | // --------------------------------------------------------------------------- | |
666 | // basic operations | |
667 | // --------------------------------------------------------------------------- | |
668 | ||
669 | void wxWindowMGL::SetFocus() | |
670 | { | |
a46935cb VS |
671 | if ( gs_focusedWindow == this ) return; |
672 | ||
eea93267 VS |
673 | wxWindowMGL *oldFocusedWindow = gs_focusedWindow; |
674 | ||
7cdbf02c | 675 | if ( gs_focusedWindow ) |
eea93267 VS |
676 | { |
677 | gs_toBeFocusedWindow = (wxWindow*)this; | |
7cdbf02c | 678 | gs_focusedWindow->KillFocus(); |
eea93267 VS |
679 | gs_toBeFocusedWindow = NULL; |
680 | } | |
7de59551 | 681 | |
7cdbf02c | 682 | gs_focusedWindow = this; |
7de59551 | 683 | |
2b260bc3 | 684 | MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT, wxMGL_CAPTURE_KEYB); |
a4bbc9f7 | 685 | |
7cdbf02c | 686 | wxWindowMGL *active = wxGetTopLevelParent(this); |
61bd618f | 687 | if ( !(m_windowStyle & wxPOPUP_WINDOW) && active != gs_activeFrame ) |
a4bbc9f7 | 688 | { |
7cdbf02c VS |
689 | if ( gs_activeFrame ) |
690 | { | |
127eab18 | 691 | wxActivateEvent event(wxEVT_ACTIVATE, false, gs_activeFrame->GetId()); |
7cdbf02c VS |
692 | event.SetEventObject(gs_activeFrame); |
693 | gs_activeFrame->GetEventHandler()->ProcessEvent(event); | |
694 | } | |
695 | ||
696 | gs_activeFrame = active; | |
127eab18 | 697 | wxActivateEvent event(wxEVT_ACTIVATE, true, gs_activeFrame->GetId()); |
7cdbf02c VS |
698 | event.SetEventObject(gs_activeFrame); |
699 | gs_activeFrame->GetEventHandler()->ProcessEvent(event); | |
a4bbc9f7 | 700 | } |
7de59551 | 701 | |
a4bbc9f7 VS |
702 | wxFocusEvent event(wxEVT_SET_FOCUS, GetId()); |
703 | event.SetEventObject(this); | |
eea93267 | 704 | event.SetWindow((wxWindow*)oldFocusedWindow); |
a46935cb | 705 | GetEventHandler()->ProcessEvent(event); |
869dabf8 VS |
706 | |
707 | #if wxUSE_CARET | |
708 | // caret needs to be informed about focus change | |
709 | wxCaret *caret = GetCaret(); | |
710 | if ( caret ) | |
711 | caret->OnSetFocus(); | |
712 | #endif // wxUSE_CARET | |
a4bbc9f7 | 713 | } |
32b8ec41 | 714 | |
a4bbc9f7 | 715 | void wxWindowMGL::KillFocus() |
32b8ec41 | 716 | { |
7cdbf02c VS |
717 | if ( gs_focusedWindow != this ) return; |
718 | gs_focusedWindow = NULL; | |
a4bbc9f7 | 719 | |
7bdc1879 | 720 | if ( m_isBeingDeleted ) return; |
7de59551 | 721 | |
a4bbc9f7 VS |
722 | MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB); |
723 | ||
724 | #if wxUSE_CARET | |
725 | // caret needs to be informed about focus change | |
726 | wxCaret *caret = GetCaret(); | |
7bdc1879 | 727 | if ( caret ) |
a4bbc9f7 VS |
728 | caret->OnKillFocus(); |
729 | #endif // wxUSE_CARET | |
730 | ||
a4bbc9f7 VS |
731 | wxFocusEvent event(wxEVT_KILL_FOCUS, GetId()); |
732 | event.SetEventObject(this); | |
eea93267 | 733 | event.SetWindow(gs_toBeFocusedWindow); |
a46935cb | 734 | GetEventHandler()->ProcessEvent(event); |
32b8ec41 VZ |
735 | } |
736 | ||
a4bbc9f7 VS |
737 | // ---------------------------------------------------------------------------- |
738 | // this wxWindowBase function is implemented here (in platform-specific file) | |
739 | // because it is static and so couldn't be made virtual | |
740 | // ---------------------------------------------------------------------------- | |
0fe02759 | 741 | wxWindow *wxWindowBase::DoFindFocus() |
32b8ec41 | 742 | { |
7cdbf02c | 743 | return (wxWindow*)gs_focusedWindow; |
a4bbc9f7 VS |
744 | } |
745 | ||
746 | bool wxWindowMGL::Show(bool show) | |
747 | { | |
748 | if ( !wxWindowBase::Show(show) ) | |
127eab18 | 749 | return false; |
a4bbc9f7 VS |
750 | |
751 | MGL_wmShowWindow(m_wnd, show); | |
7de59551 | 752 | |
ead60ec5 VS |
753 | if (!show && gs_activeFrame == this) |
754 | { | |
66858adf VS |
755 | // activate next frame in Z-order: |
756 | if ( m_wnd->prev ) | |
757 | { | |
758 | wxWindowMGL *win = (wxWindowMGL*)m_wnd->prev->userData; | |
759 | win->SetFocus(); | |
760 | } | |
761 | else if ( m_wnd->next ) | |
762 | { | |
763 | wxWindowMGL *win = (wxWindowMGL*)m_wnd->next->userData; | |
764 | win->SetFocus(); | |
765 | } | |
766 | else | |
767 | { | |
768 | gs_activeFrame = NULL; | |
ead60ec5 VS |
769 | } |
770 | } | |
771 | ||
127eab18 | 772 | return true; |
a4bbc9f7 VS |
773 | } |
774 | ||
775 | // Raise the window to the top of the Z order | |
776 | void wxWindowMGL::Raise() | |
777 | { | |
778 | MGL_wmRaiseWindow(m_wnd); | |
779 | } | |
780 | ||
781 | // Lower the window to the bottom of the Z order | |
782 | void wxWindowMGL::Lower() | |
783 | { | |
784 | MGL_wmLowerWindow(m_wnd); | |
785 | } | |
786 | ||
4116c221 | 787 | void wxWindowMGL::DoCaptureMouse() |
a4bbc9f7 | 788 | { |
7cdbf02c VS |
789 | if ( gs_mouseCapture ) |
790 | MGL_wmUncaptureEvents(gs_mouseCapture->m_wnd, wxMGL_CAPTURE_MOUSE); | |
791 | ||
792 | gs_mouseCapture = this; | |
a4bbc9f7 VS |
793 | MGL_wmCaptureEvents(m_wnd, EVT_MOUSEEVT, wxMGL_CAPTURE_MOUSE); |
794 | } | |
795 | ||
4116c221 | 796 | void wxWindowMGL::DoReleaseMouse() |
a4bbc9f7 | 797 | { |
63fd5f0b | 798 | wxASSERT_MSG( gs_mouseCapture == this, wxT("attempt to release mouse, but this window hasn't captured it") ); |
7de59551 | 799 | |
a4bbc9f7 | 800 | MGL_wmUncaptureEvents(m_wnd, wxMGL_CAPTURE_MOUSE); |
7cdbf02c | 801 | gs_mouseCapture = NULL; |
a4bbc9f7 VS |
802 | } |
803 | ||
804 | /* static */ wxWindow *wxWindowBase::GetCapture() | |
805 | { | |
7cdbf02c | 806 | return (wxWindow*)gs_mouseCapture; |
a4bbc9f7 VS |
807 | } |
808 | ||
809 | bool wxWindowMGL::SetCursor(const wxCursor& cursor) | |
810 | { | |
811 | if ( !wxWindowBase::SetCursor(cursor) ) | |
812 | { | |
813 | // no change | |
127eab18 | 814 | return false; |
a4bbc9f7 VS |
815 | } |
816 | ||
817 | if ( m_cursor.Ok() ) | |
818 | MGL_wmSetWindowCursor(m_wnd, *m_cursor.GetMGLCursor()); | |
ef344ff8 VS |
819 | else |
820 | MGL_wmSetWindowCursor(m_wnd, *wxSTANDARD_CURSOR->GetMGLCursor()); | |
a4bbc9f7 | 821 | |
127eab18 | 822 | return true; |
a4bbc9f7 VS |
823 | } |
824 | ||
825 | void wxWindowMGL::WarpPointer(int x, int y) | |
826 | { | |
8014db41 VS |
827 | int w, h; |
828 | wxDisplaySize(&w, &h); | |
829 | ||
a4bbc9f7 | 830 | ClientToScreen(&x, &y); |
8014db41 VS |
831 | if ( x < 0 ) |
832 | x = 0; | |
833 | if ( y < 0 ) | |
834 | y = 0; | |
835 | if ( x >= w ) | |
836 | x = w-1; | |
837 | if ( y >= h ) | |
838 | y = h-1; | |
7de59551 | 839 | |
a4bbc9f7 VS |
840 | EVT_setMousePos(x, y); |
841 | } | |
842 | ||
a4bbc9f7 VS |
843 | // Set this window to be the child of 'parent'. |
844 | bool wxWindowMGL::Reparent(wxWindowBase *parent) | |
845 | { | |
846 | if ( !wxWindowBase::Reparent(parent) ) | |
127eab18 | 847 | return false; |
a4bbc9f7 VS |
848 | |
849 | MGL_wmReparentWindow(m_wnd, parent->GetHandle()); | |
850 | ||
127eab18 | 851 | return true; |
a4bbc9f7 VS |
852 | } |
853 | ||
854 | ||
855 | // --------------------------------------------------------------------------- | |
856 | // drag and drop | |
857 | // --------------------------------------------------------------------------- | |
858 | ||
859 | #if wxUSE_DRAG_AND_DROP | |
860 | ||
861 | void wxWindowMGL::SetDropTarget(wxDropTarget *pDropTarget) | |
862 | { | |
863 | if ( m_dropTarget != 0 ) { | |
864 | m_dropTarget->Revoke(m_hWnd); | |
865 | delete m_dropTarget; | |
866 | } | |
867 | ||
868 | m_dropTarget = pDropTarget; | |
869 | if ( m_dropTarget != 0 ) | |
870 | m_dropTarget->Register(m_hWnd); | |
871 | } | |
872 | // FIXME_MGL | |
873 | #endif // wxUSE_DRAG_AND_DROP | |
874 | ||
875 | // old style file-manager drag&drop support: we retain the old-style | |
876 | // DragAcceptFiles in parallel with SetDropTarget. | |
127eab18 | 877 | void wxWindowMGL::DragAcceptFiles(bool WXUNUSED(accept)) |
a4bbc9f7 VS |
878 | { |
879 | #if 0 // FIXME_MGL | |
880 | HWND hWnd = GetHwnd(); | |
881 | if ( hWnd ) | |
882 | ::DragAcceptFiles(hWnd, (BOOL)accept); | |
883 | #endif | |
884 | } | |
885 | ||
886 | // --------------------------------------------------------------------------- | |
887 | // moving and resizing | |
888 | // --------------------------------------------------------------------------- | |
889 | ||
890 | // Get total size | |
891 | void wxWindowMGL::DoGetSize(int *x, int *y) const | |
892 | { | |
ea98f686 | 893 | wxASSERT_MSG( m_wnd, wxT("invalid window") ); |
7de59551 | 894 | |
a4bbc9f7 VS |
895 | if (x) *x = m_wnd->width; |
896 | if (y) *y = m_wnd->height; | |
897 | } | |
898 | ||
899 | void wxWindowMGL::DoGetPosition(int *x, int *y) const | |
900 | { | |
ea98f686 VS |
901 | wxASSERT_MSG( m_wnd, wxT("invalid window") ); |
902 | ||
903 | int pX = 0, pY = 0; | |
7de59551 | 904 | AdjustForParentClientOrigin(pX, pY, 0); |
e41dcea5 | 905 | |
ea98f686 VS |
906 | if (x) *x = m_wnd->x - pX; |
907 | if (y) *y = m_wnd->y - pY; | |
a4bbc9f7 VS |
908 | } |
909 | ||
910 | void wxWindowMGL::DoScreenToClient(int *x, int *y) const | |
911 | { | |
912 | int ax, ay; | |
985520bc | 913 | MGL_wmCoordGlobalToLocal(m_wnd, 0, 0, &ax, &ay); |
a4bbc9f7 | 914 | if (x) |
985520bc | 915 | (*x) += ax; |
a4bbc9f7 | 916 | if (y) |
985520bc | 917 | (*y) += ay; |
a4bbc9f7 VS |
918 | } |
919 | ||
920 | void wxWindowMGL::DoClientToScreen(int *x, int *y) const | |
921 | { | |
922 | int ax, ay; | |
985520bc | 923 | MGL_wmCoordLocalToGlobal(m_wnd, 0, 0, &ax, &ay); |
a4bbc9f7 | 924 | if (x) |
985520bc | 925 | (*x) += ax; |
a4bbc9f7 | 926 | if (y) |
985520bc | 927 | (*y) += ay; |
a4bbc9f7 VS |
928 | } |
929 | ||
930 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
931 | void wxWindowMGL::DoGetClientSize(int *x, int *y) const | |
932 | { | |
933 | DoGetSize(x, y); | |
934 | } | |
935 | ||
936 | void wxWindowMGL::DoMoveWindow(int x, int y, int width, int height) | |
937 | { | |
1cdab5d1 MW |
938 | wxRect rcClient(GetClientRect()); |
939 | ||
940 | MGL_wmSetWindowPosition(m_wnd, x, y, width, height); | |
941 | ||
942 | // When the origin or a window stays fixed but the height or width | |
943 | // changes, invalidate the old and new non-client areas | |
944 | if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) && | |
945 | m_wnd->x == x && m_wnd->y == y && | |
946 | rcClient.Intersect(GetClientRect()) != wxRect(0, 0, width, height) ) | |
947 | { | |
948 | wxRegion rgn(0, 0, width, height); | |
949 | rgn.Subtract(rcClient); | |
950 | ||
951 | // This should work I think, but doesn't seem to: | |
952 | //MGL_wmInvalidateWindowRegion(m_wnd, rgn.GetMGLRegion().rgnPointer()); | |
953 | ||
954 | // Use MGL_wmInvalidateWindowRect instead: | |
955 | for (wxRegionIterator it(rgn); it; it++) | |
956 | { | |
957 | rect_t rc; | |
958 | rc.left = it.GetX(); | |
959 | rc.top = it.GetY(); | |
960 | rc.right = rc.left + it.GetW(); | |
961 | rc.bottom = rc.top + it.GetH(); | |
962 | MGL_wmInvalidateWindowRect(m_wnd, &rc); | |
963 | } | |
964 | } | |
a4bbc9f7 VS |
965 | } |
966 | ||
967 | // set the size of the window: if the dimensions are positive, just use them, | |
968 | // but if any of them is equal to -1, it means that we must find the value for | |
969 | // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in | |
970 | // which case -1 is a valid value for x and y) | |
971 | // | |
972 | // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate | |
973 | // the width/height to best suit our contents, otherwise we reuse the current | |
974 | // width/height | |
975 | void wxWindowMGL::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
976 | { | |
977 | // get the current size and position... | |
978 | int currentX, currentY; | |
979 | GetPosition(¤tX, ¤tY); | |
980 | int currentW,currentH; | |
981 | GetSize(¤tW, ¤tH); | |
982 | ||
983 | // ... and don't do anything (avoiding flicker) if it's already ok | |
984 | if ( x == currentX && y == currentY && | |
985 | width == currentW && height == currentH ) | |
986 | { | |
987 | return; | |
988 | } | |
989 | ||
990 | if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
991 | x = currentX; | |
992 | if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) | |
993 | y = currentY; | |
994 | ||
a4bbc9f7 | 995 | AdjustForParentClientOrigin(x, y, sizeFlags); |
a4bbc9f7 VS |
996 | |
997 | wxSize size(-1, -1); | |
998 | if ( width == -1 ) | |
999 | { | |
1000 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) | |
1001 | { | |
1002 | size = DoGetBestSize(); | |
1003 | width = size.x; | |
1004 | } | |
1005 | else | |
1006 | { | |
1007 | // just take the current one | |
1008 | width = currentW; | |
1009 | } | |
1010 | } | |
7de59551 | 1011 | |
a4bbc9f7 VS |
1012 | if ( height == -1 ) |
1013 | { | |
1014 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) | |
1015 | { | |
1016 | if ( size.x == -1 ) | |
1017 | { | |
1018 | size = DoGetBestSize(); | |
1019 | } | |
1020 | //else: already called DoGetBestSize() above | |
1021 | ||
1022 | height = size.y; | |
1023 | } | |
1024 | else | |
1025 | { | |
1026 | // just take the current one | |
1027 | height = currentH; | |
1028 | } | |
1029 | } | |
7de59551 | 1030 | |
6feddea3 | 1031 | int maxWidth = GetMaxWidth(), |
7de59551 | 1032 | minWidth = GetMinWidth(), |
6feddea3 VS |
1033 | maxHeight = GetMaxHeight(), |
1034 | minHeight = GetMinHeight(); | |
7de59551 | 1035 | |
6feddea3 VS |
1036 | if ( minWidth != -1 && width < minWidth ) width = minWidth; |
1037 | if ( maxWidth != -1 && width > maxWidth ) width = maxWidth; | |
1038 | if ( minHeight != -1 && height < minHeight ) height = minHeight; | |
1039 | if ( maxHeight != -1 && height > maxHeight ) height = maxHeight; | |
a4bbc9f7 | 1040 | |
7de59551 | 1041 | if ( m_wnd->x != x || m_wnd->y != y || |
88f2a771 VS |
1042 | (int)m_wnd->width != width || (int)m_wnd->height != height ) |
1043 | { | |
1044 | DoMoveWindow(x, y, width, height); | |
a4bbc9f7 | 1045 | |
127eab18 WS |
1046 | wxSize newSize(width, height); |
1047 | wxSizeEvent event(newSize, GetId()); | |
88f2a771 VS |
1048 | event.SetEventObject(this); |
1049 | GetEventHandler()->ProcessEvent(event); | |
1050 | } | |
a4bbc9f7 VS |
1051 | } |
1052 | ||
1053 | void wxWindowMGL::DoSetClientSize(int width, int height) | |
1054 | { | |
1055 | SetSize(width, height); | |
1056 | } | |
1057 | ||
1058 | // --------------------------------------------------------------------------- | |
1059 | // text metrics | |
1060 | // --------------------------------------------------------------------------- | |
1061 | ||
1062 | int wxWindowMGL::GetCharHeight() const | |
1063 | { | |
1064 | wxScreenDC dc; | |
1065 | dc.SetFont(m_font); | |
1066 | return dc.GetCharHeight(); | |
1067 | } | |
1068 | ||
1069 | int wxWindowMGL::GetCharWidth() const | |
1070 | { | |
1071 | wxScreenDC dc; | |
1072 | dc.SetFont(m_font); | |
1073 | return dc.GetCharWidth(); | |
1074 | } | |
1075 | ||
1076 | void wxWindowMGL::GetTextExtent(const wxString& string, | |
1077 | int *x, int *y, | |
1078 | int *descent, int *externalLeading, | |
1079 | const wxFont *theFont) const | |
1080 | { | |
1081 | wxScreenDC dc; | |
1082 | if (!theFont) | |
1083 | theFont = &m_font; | |
1084 | dc.GetTextExtent(string, x, y, descent, externalLeading, (wxFont*)theFont); | |
1085 | } | |
1086 | ||
a4bbc9f7 | 1087 | |
a4bbc9f7 VS |
1088 | // --------------------------------------------------------------------------- |
1089 | // painting | |
1090 | // --------------------------------------------------------------------------- | |
1091 | ||
1092 | void wxWindowMGL::Clear() | |
1093 | { | |
1094 | wxClientDC dc((wxWindow *)this); | |
1095 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1096 | dc.SetBackground(brush); | |
1097 | dc.Clear(); | |
1098 | } | |
1099 | ||
61bd618f | 1100 | #include "wx/menu.h" |
2b260bc3 | 1101 | void wxWindowMGL::Refresh(bool eraseBack, const wxRect *rect) |
a4bbc9f7 | 1102 | { |
2b260bc3 VS |
1103 | if ( m_eraseBackground == -1 ) |
1104 | m_eraseBackground = eraseBack; | |
1105 | else | |
1106 | m_eraseBackground |= eraseBack; | |
7de59551 | 1107 | |
a4bbc9f7 VS |
1108 | if ( rect ) |
1109 | { | |
1110 | rect_t r; | |
1111 | r.left = rect->GetLeft(), r.right = rect->GetRight(); | |
1112 | r.top = rect->GetTop(), r.bottom = rect->GetBottom(); | |
1113 | MGL_wmInvalidateWindowRect(GetHandle(), &r); | |
1114 | } | |
1115 | else | |
1116 | MGL_wmInvalidateWindow(GetHandle()); | |
1117 | } | |
1118 | ||
1119 | void wxWindowMGL::Update() | |
1120 | { | |
a4bbc9f7 VS |
1121 | if ( !m_frozen ) |
1122 | MGL_wmUpdateDC(g_winMng); | |
1123 | } | |
1124 | ||
1125 | void wxWindowMGL::Freeze() | |
1126 | { | |
127eab18 WS |
1127 | m_frozen = true; |
1128 | m_refreshAfterThaw = false; | |
a4bbc9f7 VS |
1129 | } |
1130 | ||
1131 | void wxWindowMGL::Thaw() | |
1132 | { | |
127eab18 | 1133 | m_frozen = false; |
a4bbc9f7 VS |
1134 | if ( m_refreshAfterThaw ) |
1135 | Refresh(); | |
1136 | } | |
1137 | ||
a4bbc9f7 VS |
1138 | void wxWindowMGL::HandlePaint(MGLDevCtx *dc) |
1139 | { | |
1140 | if ( m_frozen ) | |
1141 | { | |
7de59551 | 1142 | // Don't paint anything if the window is frozen. |
127eab18 | 1143 | m_refreshAfterThaw = true; |
a4bbc9f7 VS |
1144 | return; |
1145 | } | |
7de59551 RD |
1146 | |
1147 | #ifdef __WXDEBUG__ | |
82186005 VS |
1148 | // FIXME_MGL -- debugging stuff, to be removed! |
1149 | static int debugPaintEvents = -1; | |
1150 | if ( debugPaintEvents == -1 ) | |
1151 | debugPaintEvents = wxGetEnv(wxT("WXMGL_DEBUG_PAINT_EVENTS"), NULL); | |
1152 | if ( debugPaintEvents ) | |
1153 | { | |
1154 | dc->setColorRGB(255,0,255); | |
1155 | dc->fillRect(-1000,-1000,2000,2000); | |
1156 | wxUsleep(50); | |
1157 | } | |
b8c0528d VS |
1158 | #endif |
1159 | ||
fd495ab3 VS |
1160 | MGLRegion clip; |
1161 | dc->getClipRegion(clip); | |
1162 | m_updateRegion = wxRegion(clip); | |
a4bbc9f7 VS |
1163 | m_paintMGLDC = dc; |
1164 | ||
a679e129 VS |
1165 | #if wxUSE_CARET |
1166 | // must hide caret temporarily, otherwise we'd get rendering artifacts | |
1167 | wxCaret *caret = GetCaret(); | |
1168 | if ( caret ) | |
1169 | caret->Hide(); | |
1170 | #endif // wxUSE_CARET | |
1171 | ||
2b260bc3 | 1172 | if ( m_eraseBackground != 0 ) |
7bdc1879 | 1173 | { |
2b260bc3 VS |
1174 | wxWindowDC dc((wxWindow*)this); |
1175 | wxEraseEvent eventEr(m_windowId, &dc); | |
1176 | eventEr.SetEventObject(this); | |
1177 | GetEventHandler()->ProcessEvent(eventEr); | |
7bdc1879 | 1178 | } |
2b260bc3 | 1179 | m_eraseBackground = -1; |
a4bbc9f7 VS |
1180 | |
1181 | wxNcPaintEvent eventNc(GetId()); | |
1182 | eventNc.SetEventObject(this); | |
1183 | GetEventHandler()->ProcessEvent(eventNc); | |
7de59551 | 1184 | |
a4bbc9f7 VS |
1185 | wxPaintEvent eventPt(GetId()); |
1186 | eventPt.SetEventObject(this); | |
1187 | GetEventHandler()->ProcessEvent(eventPt); | |
a4bbc9f7 | 1188 | |
a679e129 VS |
1189 | #if wxUSE_CARET |
1190 | if ( caret ) | |
1191 | caret->Show(); | |
1192 | #endif // wxUSE_CARET | |
1193 | ||
7bdc1879 | 1194 | m_paintMGLDC = NULL; |
fd495ab3 | 1195 | m_updateRegion.Clear(); |
a4bbc9f7 VS |
1196 | } |
1197 | ||
1198 | ||
1199 | // Find the wxWindow at the current mouse position, returning the mouse | |
1200 | // position. | |
1201 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) | |
1202 | { | |
1203 | return wxFindWindowAtPoint(pt = wxGetMousePosition()); | |
1204 | } | |
1205 | ||
1206 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) | |
1207 | { | |
1208 | window_t *wnd = MGL_wmGetWindowAtPosition(g_winMng, pt.x, pt.y); | |
1209 | return (wxWindow*)wnd->userData; | |
32b8ec41 | 1210 | } |
d53fc7c9 VS |
1211 | |
1212 | ||
1213 | // --------------------------------------------------------------------------- | |
1214 | // idle events processing | |
1215 | // --------------------------------------------------------------------------- | |
1216 | ||
e39af974 | 1217 | void wxWindowMGL::OnInternalIdle() |
d53fc7c9 | 1218 | { |
e39af974 JS |
1219 | if (wxUpdateUIEvent::CanUpdate(this)) |
1220 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); | |
d53fc7c9 | 1221 | } |