]>
Commit | Line | Data |
---|---|---|
a15eb0a5 SC |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: mac/toplevel.cpp | |
3 | // Purpose: implements wxTopLevelWindow for MSW | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 24.09.01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com) | |
6aa89a22 | 9 | // License: wxWindows licence |
a15eb0a5 SC |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "toplevel.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/app.h" | |
33 | #include "wx/toplevel.h" | |
422644a3 | 34 | #include "wx/frame.h" |
a15eb0a5 SC |
35 | #include "wx/string.h" |
36 | #include "wx/log.h" | |
37 | #include "wx/intl.h" | |
38 | #endif //WX_PRECOMP | |
39 | ||
5f0b2f22 | 40 | #include "wx/mac/uma.h" |
422644a3 | 41 | #include "wx/mac/aga.h" |
7c091673 | 42 | #include "wx/app.h" |
5f0b2f22 | 43 | #include "wx/tooltip.h" |
a07c1212 | 44 | #include "wx/dnd.h" |
5f0b2f22 | 45 | |
dd49c691 SC |
46 | #include "ToolUtils.h" |
47 | ||
48 | ||
34dc8f91 SC |
49 | #define wxMAC_DEBUG_REDRAW 0 |
50 | #ifndef wxMAC_DEBUG_REDRAW | |
51 | #define wxMAC_DEBUG_REDRAW 0 | |
52 | #endif | |
53 | ||
a15eb0a5 SC |
54 | // ---------------------------------------------------------------------------- |
55 | // globals | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
58 | // list of all frames and modeless dialogs | |
32b5be3d RR |
59 | wxWindowList wxModelessWindows; |
60 | ||
61 | // double click testing | |
62 | static Point gs_lastWhere; | |
63 | static long gs_lastWhen = 0; | |
64 | ||
6a7e6411 | 65 | |
45ff8005 | 66 | #if TARGET_CARBON |
6a7e6411 | 67 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); |
45ff8005 | 68 | #endif |
6a7e6411 | 69 | |
a15eb0a5 SC |
70 | // ============================================================================ |
71 | // wxTopLevelWindowMac implementation | |
72 | // ============================================================================ | |
73 | ||
851b3a88 SC |
74 | // --------------------------------------------------------------------------- |
75 | // Carbon Events | |
76 | // --------------------------------------------------------------------------- | |
77 | ||
78 | #if TARGET_CARBON | |
79 | ||
80 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; | |
81 | ||
1542ea39 | 82 | static const EventTypeSpec eventList[] = |
851b3a88 SC |
83 | { |
84 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , | |
c5c9378c | 85 | |
e40298d5 | 86 | { kEventClassKeyboard, kEventRawKeyDown } , |
c5c9378c SC |
87 | { kEventClassKeyboard, kEventRawKeyRepeat } , |
88 | { kEventClassKeyboard, kEventRawKeyUp } , | |
89 | { kEventClassKeyboard, kEventRawKeyModifiersChanged } , | |
90 | ||
851b3a88 SC |
91 | { kEventClassWindow , kEventWindowUpdate } , |
92 | { kEventClassWindow , kEventWindowActivated } , | |
93 | { kEventClassWindow , kEventWindowDeactivated } , | |
94 | { kEventClassWindow , kEventWindowBoundsChanging } , | |
95 | { kEventClassWindow , kEventWindowBoundsChanged } , | |
96 | { kEventClassWindow , kEventWindowClose } , | |
97 | ||
98 | { kEventClassMouse , kEventMouseDown } , | |
99 | { kEventClassMouse , kEventMouseUp } , | |
100 | { kEventClassMouse , kEventMouseMoved } , | |
101 | { kEventClassMouse , kEventMouseDragged } , | |
102 | ||
103 | } ; | |
104 | ||
105 | static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
106 | { | |
107 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 108 | |
c5c9378c | 109 | wxWindow* focus = wxWindow::FindFocus() ; |
e40298d5 | 110 | char charCode ; |
1542ea39 | 111 | UInt32 keyCode ; |
c5c9378c | 112 | UInt32 modifiers ; |
e40298d5 | 113 | Point point ; |
c5c9378c SC |
114 | |
115 | EventRef rawEvent ; | |
1542ea39 | 116 | |
c5c9378c | 117 | GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ; |
1542ea39 | 118 | |
e40298d5 JS |
119 | GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); |
120 | GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
121 | GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
122 | GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, | |
123 | sizeof( Point ), NULL, &point ); | |
124 | ||
e40298d5 JS |
125 | switch ( GetEventKind( event ) ) |
126 | { | |
127 | case kEventTextInputUnicodeForKeyEvent : | |
ace07c80 SC |
128 | // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not |
129 | // get its own kEventTextInputUnicodeForKeyEvent, so we route back the | |
130 | wxControl* control = wxDynamicCast( focus , wxControl ) ; | |
131 | if ( control ) | |
132 | { | |
133 | ControlHandle macControl = (ControlHandle) control->GetMacControl() ; | |
134 | if ( macControl ) | |
135 | { | |
136 | ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ; | |
137 | result = noErr ; | |
138 | } | |
139 | } | |
140 | /* | |
141 | // this may lead to double events sent to a window in case all handlers have skipped the key down event | |
77a4354e VZ |
142 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; |
143 | UInt32 message = (keyCode << 8) + charCode; | |
144 | ||
1542ea39 | 145 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( |
e40298d5 JS |
146 | focus , message , modifiers , when , point.h , point.v ) ) |
147 | { | |
148 | result = noErr ; | |
149 | } | |
ace07c80 | 150 | */ |
e40298d5 JS |
151 | break ; |
152 | } | |
c5c9378c SC |
153 | |
154 | return result ; | |
155 | } | |
156 | ||
157 | static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
158 | { | |
159 | OSStatus result = eventNotHandledErr ; | |
160 | ||
161 | wxWindow* focus = wxWindow::FindFocus() ; | |
e40298d5 | 162 | char charCode ; |
1542ea39 | 163 | UInt32 keyCode ; |
c5c9378c | 164 | UInt32 modifiers ; |
e40298d5 JS |
165 | Point point ; |
166 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
167 | ||
168 | GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); | |
169 | GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
170 | GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
171 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, | |
172 | sizeof( Point ), NULL, &point ); | |
173 | ||
174 | UInt32 message = (keyCode << 8) + charCode; | |
175 | switch( GetEventKind( event ) ) | |
176 | { | |
177 | case kEventRawKeyRepeat : | |
178 | case kEventRawKeyDown : | |
1542ea39 | 179 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( |
e40298d5 JS |
180 | focus , message , modifiers , when , point.h , point.v ) ) |
181 | { | |
182 | result = noErr ; | |
183 | } | |
184 | break ; | |
185 | case kEventRawKeyUp : | |
1542ea39 | 186 | if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent( |
e40298d5 JS |
187 | focus , message , modifiers , when , point.h , point.v ) ) |
188 | { | |
189 | result = noErr ; | |
190 | } | |
191 | break ; | |
192 | case kEventRawKeyModifiersChanged : | |
193 | { | |
194 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
195 | ||
196 | event.m_shiftDown = modifiers & shiftKey; | |
197 | event.m_controlDown = modifiers & controlKey; | |
198 | event.m_altDown = modifiers & optionKey; | |
199 | event.m_metaDown = modifiers & cmdKey; | |
200 | ||
201 | event.m_x = point.h; | |
202 | event.m_y = point.v; | |
203 | event.m_timeStamp = when; | |
204 | wxWindow* focus = wxWindow::FindFocus() ; | |
205 | event.SetEventObject(focus); | |
206 | ||
8d60dc8a | 207 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey ) |
e40298d5 JS |
208 | { |
209 | event.m_keyCode = WXK_CONTROL ; | |
210 | event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
211 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
212 | } | |
8d60dc8a | 213 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey ) |
e40298d5 JS |
214 | { |
215 | event.m_keyCode = WXK_SHIFT ; | |
216 | event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
217 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
218 | } | |
8d60dc8a | 219 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey ) |
e40298d5 JS |
220 | { |
221 | event.m_keyCode = WXK_ALT ; | |
222 | event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
223 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
224 | } | |
225 | wxTheApp->s_lastModifiers = modifiers ; | |
226 | } | |
227 | break ; | |
228 | } | |
851b3a88 SC |
229 | |
230 | return result ; | |
231 | } | |
232 | ||
233 | static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
234 | { | |
235 | OSStatus result = eventNotHandledErr ; | |
236 | ||
e40298d5 JS |
237 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; |
238 | Point point ; | |
239 | UInt32 modifiers = 0; | |
240 | EventMouseButton button = 0 ; | |
241 | UInt32 click = 0 ; | |
1542ea39 | 242 | |
e40298d5 JS |
243 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, |
244 | sizeof( Point ), NULL, &point ); | |
245 | GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, | |
246 | sizeof( UInt32 ), NULL, &modifiers ); | |
247 | GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL, | |
248 | sizeof( EventMouseButton ), NULL, &button ); | |
249 | GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL, | |
250 | sizeof( UInt32 ), NULL, &click ); | |
1542ea39 | 251 | |
e40298d5 JS |
252 | if ( button == 0 || GetEventKind( event ) == kEventMouseUp ) |
253 | modifiers += btnState ; | |
1542ea39 | 254 | |
e40298d5 | 255 | WindowRef window ; |
851b3a88 | 256 | short windowPart = ::FindWindow(point, &window); |
a3195b73 | 257 | |
e40298d5 | 258 | if ( IsWindowActive(window) && windowPart == inContent ) |
851b3a88 | 259 | { |
e40298d5 JS |
260 | switch ( GetEventKind( event ) ) |
261 | { | |
262 | case kEventMouseDown : | |
263 | toplevelWindow->MacFireMouseEvent( mouseDown , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
264 | result = noErr ; | |
265 | break ; | |
266 | case kEventMouseUp : | |
267 | toplevelWindow->MacFireMouseEvent( mouseUp , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
268 | result = noErr ; | |
269 | break ; | |
270 | case kEventMouseMoved : | |
271 | toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
272 | result = noErr ; | |
273 | break ; | |
274 | case kEventMouseDragged : | |
275 | toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
276 | result = noErr ; | |
277 | break ; | |
278 | default : | |
279 | break ; | |
280 | } | |
281 | } | |
1542ea39 | 282 | |
e40298d5 | 283 | return result ; |
1542ea39 | 284 | |
851b3a88 SC |
285 | |
286 | } | |
287 | static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
288 | { | |
289 | OSStatus result = eventNotHandledErr ; | |
290 | OSStatus err = noErr ; | |
291 | ||
e40298d5 JS |
292 | UInt32 attributes; |
293 | WindowRef windowRef ; | |
294 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; | |
1542ea39 | 295 | |
e40298d5 JS |
296 | GetEventParameter( event, kEventParamDirectObject, typeWindowRef, NULL, |
297 | sizeof( WindowRef ), NULL, &windowRef ); | |
1542ea39 | 298 | |
e40298d5 JS |
299 | switch( GetEventKind( event ) ) |
300 | { | |
301 | case kEventWindowUpdate : | |
302 | if ( !wxPendingDelete.Member(toplevelWindow) ) | |
303 | toplevelWindow->MacUpdate( EventTimeToTicks( GetEventTime( event ) ) ) ; | |
304 | result = noErr ; | |
305 | break ; | |
306 | case kEventWindowActivated : | |
307 | toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , true) ; | |
308 | result = noErr ; | |
309 | break ; | |
310 | case kEventWindowDeactivated : | |
311 | toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , false) ; | |
312 | result = noErr ; | |
313 | break ; | |
314 | case kEventWindowClose : | |
315 | toplevelWindow->Close() ; | |
316 | result = noErr ; | |
317 | break ; | |
318 | case kEventWindowBoundsChanged : | |
319 | err = GetEventParameter( event, kEventParamAttributes, typeUInt32, | |
320 | NULL, sizeof( UInt32 ), NULL, &attributes ); | |
321 | if ( err == noErr ) | |
322 | { | |
323 | Rect newContentRect ; | |
324 | ||
325 | GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL, | |
326 | sizeof( newContentRect ), NULL, &newContentRect ); | |
1542ea39 RD |
327 | |
328 | toplevelWindow->SetSize( newContentRect.left , newContentRect.top , | |
329 | newContentRect.right - newContentRect.left , | |
851b3a88 SC |
330 | newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING); |
331 | ||
e40298d5 JS |
332 | result = noErr; |
333 | } | |
334 | break ; | |
f81bfef9 SC |
335 | case kEventWindowBoundsChanging : |
336 | err = GetEventParameter( event, kEventParamAttributes, typeUInt32, | |
337 | NULL, sizeof( UInt32 ), NULL, &attributes ); | |
338 | if ( err == noErr ) | |
339 | { | |
340 | Rect newContentRect ; | |
341 | ||
342 | GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL, | |
343 | sizeof( newContentRect ), NULL, &newContentRect ); | |
344 | ||
345 | wxRect contentRect(newContentRect.left , newContentRect.top , | |
346 | newContentRect.right - newContentRect.left , | |
347 | newContentRect.bottom - newContentRect.top) ; | |
348 | ||
349 | bool handled = false ; | |
350 | if ((attributes & kWindowBoundsChangeSizeChanged) != 0) | |
351 | { | |
352 | wxSizeEvent event(contentRect , toplevelWindow->GetId()); | |
353 | event.SetEventObject(toplevelWindow); | |
354 | handled = toplevelWindow->GetEventHandler()->ProcessEvent(event); | |
355 | contentRect = event.GetRect() ; | |
356 | } | |
357 | else if ( attributes & kWindowBoundsChangeOriginChanged != 0) | |
358 | { | |
359 | wxMoveEvent event(contentRect , toplevelWindow->GetId()); | |
360 | event.SetEventObject(toplevelWindow); | |
361 | handled = toplevelWindow->GetEventHandler()->ProcessEvent(event); | |
362 | contentRect = event.GetRect() ; | |
363 | } | |
364 | if ( handled ) | |
365 | { | |
366 | SetRect( &newContentRect , contentRect.GetLeft() , contentRect.GetTop() , contentRect.GetRight() , contentRect.GetBottom() ) ; | |
367 | SetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, sizeof( newContentRect ), &newContentRect ); | |
368 | } | |
369 | result = noErr ; | |
370 | } | |
371 | break ; | |
e40298d5 JS |
372 | default : |
373 | break ; | |
374 | } | |
375 | return result ; | |
851b3a88 SC |
376 | } |
377 | ||
378 | pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
379 | { | |
380 | OSStatus result = eventNotHandledErr ; | |
381 | ||
382 | switch ( GetEventClass( event ) ) | |
383 | { | |
c5c9378c | 384 | case kEventClassKeyboard : |
e40298d5 | 385 | result = KeyboardEventHandler( handler, event , data ) ; |
c5c9378c | 386 | break ; |
851b3a88 | 387 | case kEventClassTextInput : |
e40298d5 | 388 | result = TextInputEventHandler( handler, event , data ) ; |
851b3a88 SC |
389 | break ; |
390 | case kEventClassWindow : | |
e40298d5 JS |
391 | result = WindowEventHandler( handler, event , data ) ; |
392 | break ; | |
851b3a88 | 393 | case kEventClassMouse : |
e40298d5 JS |
394 | result = MouseEventHandler( handler, event , data ) ; |
395 | break ; | |
851b3a88 SC |
396 | default : |
397 | break ; | |
398 | } | |
399 | return result ; | |
400 | } | |
401 | ||
402 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) | |
403 | ||
5706de1c JS |
404 | // Patch 531199 defined a window event handler, as follows. |
405 | // TODO: merge the moving/sizing event handling with the event | |
406 | // handler above. | |
407 | #if 0 | |
408 | static pascal OSStatus | |
409 | WindowHandler( EventHandlerCallRef inHandler, EventRef inEvent, void* userData ) | |
410 | { | |
411 | Rect bounds; | |
412 | SInt16 height, width; | |
413 | UInt32 attributes; | |
414 | OSStatus result = eventNotHandledErr; | |
415 | ||
416 | GetEventParameter( inEvent, kEventParamAttributes, typeUInt32, NULL, sizeof( UInt32 ), NULL, &attributes ); | |
417 | ||
418 | if ((attributes & (kWindowBoundsChangeSizeChanged | kWindowBoundsChangeOriginChanged)) != 0) | |
419 | { | |
420 | // Extract the current bounds. This is the paramter you get to modify to | |
421 | // alter the window position or size during a window resizing. | |
422 | GetEventParameter( inEvent, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof( bounds ), NULL, &bounds ); | |
423 | ||
424 | wxRect rect; | |
425 | rect.SetLeft(bounds.left); | |
426 | rect.SetTop(bounds.top); | |
427 | rect.SetRight(bounds.right); | |
428 | rect.SetBottom(bounds.bottom); | |
429 | ||
430 | bool rc; | |
431 | wxWindowMac *pWindow = (wxWindowMac*)userData; | |
432 | if ((attributes & kWindowBoundsChangeSizeChanged) != 0) { | |
433 | wxSizeEvent event(rect, pWindow->GetId()); | |
434 | event.SetEventObject(pWindow); | |
435 | rc = pWindow->GetEventHandler()->ProcessEvent(event); | |
436 | rect = event.GetRect(); | |
437 | } | |
438 | else { | |
439 | wxMoveEvent event(rect, pWindow->GetId()); | |
440 | event.SetEventObject(pWindow); | |
441 | rc = pWindow->GetEventHandler()->ProcessEvent(event); | |
442 | rect = event.GetRect(); | |
443 | } | |
444 | ||
445 | if (rc) { | |
446 | bounds.left = rect.GetLeft(); | |
447 | bounds.top = rect.GetTop(); | |
448 | bounds.right = rect.GetRight(); | |
449 | bounds.bottom = rect.GetBottom(); | |
450 | } | |
451 | ||
452 | // Set the current bounds parameter to our adjusted bounds. Return | |
453 | // noErr to indicate we handled this event. | |
454 | SetEventParameter( inEvent, kEventParamCurrentBounds, typeQDRectangle, sizeof( bounds ), &bounds ); | |
455 | result = noErr; | |
456 | } | |
457 | return result; | |
458 | } | |
459 | #endif | |
460 | // WindowHandler | |
461 | ||
851b3a88 SC |
462 | #endif |
463 | ||
5f0b2f22 SC |
464 | // --------------------------------------------------------------------------- |
465 | // wxWindowMac utility functions | |
466 | // --------------------------------------------------------------------------- | |
467 | ||
468 | // Find an item given the Macintosh Window Reference | |
469 | ||
470 | wxList *wxWinMacWindowList = NULL; | |
76a5e5d2 | 471 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef) |
5f0b2f22 SC |
472 | { |
473 | wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); | |
474 | if (!node) | |
475 | return NULL; | |
eb22f2a6 | 476 | return (wxTopLevelWindowMac *)node->GetData(); |
5f0b2f22 SC |
477 | } |
478 | ||
76a5e5d2 | 479 | void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win) |
5f0b2f22 SC |
480 | { |
481 | // adding NULL WindowRef is (first) surely a result of an error and | |
482 | // (secondly) breaks menu command processing | |
427ff662 | 483 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); |
5f0b2f22 SC |
484 | |
485 | if ( !wxWinMacWindowList->Find((long)inWindowRef) ) | |
486 | wxWinMacWindowList->Append((long)inWindowRef, win); | |
487 | } | |
488 | ||
489 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) | |
490 | { | |
491 | wxWinMacWindowList->DeleteObject(win); | |
492 | } | |
493 | ||
494 | ||
a15eb0a5 SC |
495 | // ---------------------------------------------------------------------------- |
496 | // wxTopLevelWindowMac creation | |
497 | // ---------------------------------------------------------------------------- | |
498 | ||
76a5e5d2 | 499 | WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL; |
5f0b2f22 | 500 | |
a15eb0a5 SC |
501 | void wxTopLevelWindowMac::Init() |
502 | { | |
503 | m_iconized = | |
504 | m_maximizeOnShow = FALSE; | |
5f0b2f22 SC |
505 | m_macNoEraseUpdateRgn = NewRgn() ; |
506 | m_macNeedsErasing = false ; | |
6a17ca35 | 507 | m_macWindow = NULL ; |
851b3a88 | 508 | #if TARGET_CARBON |
7c091673 | 509 | m_macEventHandler = NULL ; |
851b3a88 | 510 | #endif |
a15eb0a5 SC |
511 | } |
512 | ||
118f012e SC |
513 | class wxMacDeferredWindowDeleter : public wxObject |
514 | { | |
515 | public : | |
1542ea39 RD |
516 | wxMacDeferredWindowDeleter( WindowRef windowRef ) |
517 | { | |
518 | m_macWindow = windowRef ; | |
118f012e | 519 | } |
1542ea39 RD |
520 | virtual ~wxMacDeferredWindowDeleter() |
521 | { | |
522 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
118f012e SC |
523 | } |
524 | protected : | |
525 | WindowRef m_macWindow ; | |
526 | } ; | |
527 | ||
a15eb0a5 SC |
528 | bool wxTopLevelWindowMac::Create(wxWindow *parent, |
529 | wxWindowID id, | |
530 | const wxString& title, | |
531 | const wxPoint& pos, | |
532 | const wxSize& size, | |
533 | long style, | |
534 | const wxString& name) | |
535 | { | |
536 | // init our fields | |
537 | Init(); | |
538 | ||
539 | m_windowStyle = style; | |
540 | ||
541 | SetName(name); | |
542 | ||
543 | m_windowId = id == -1 ? NewControlId() : id; | |
544 | ||
545 | wxTopLevelWindows.Append(this); | |
546 | ||
547 | if ( parent ) | |
548 | parent->AddChild(this); | |
549 | ||
550 | return TRUE; | |
551 | } | |
552 | ||
553 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
554 | { | |
6a17ca35 SC |
555 | if ( m_macWindow ) |
556 | { | |
557 | wxToolTip::NotifyWindowDelete(m_macWindow) ; | |
118f012e | 558 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; |
6a17ca35 | 559 | } |
1542ea39 | 560 | |
f75363ee | 561 | #if TARGET_CARBON |
7c091673 SC |
562 | if ( m_macEventHandler ) |
563 | { | |
564 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
565 | m_macEventHandler = NULL ; | |
566 | } | |
1542ea39 | 567 | #endif |
851b3a88 | 568 | |
5f0b2f22 SC |
569 | wxRemoveMacWindowAssociation( this ) ; |
570 | ||
a15eb0a5 SC |
571 | if ( wxModelessWindows.Find(this) ) |
572 | wxModelessWindows.DeleteObject(this); | |
573 | ||
76a5e5d2 | 574 | DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; |
a15eb0a5 SC |
575 | } |
576 | ||
577 | ||
578 | // ---------------------------------------------------------------------------- | |
579 | // wxTopLevelWindowMac maximize/minimize | |
580 | // ---------------------------------------------------------------------------- | |
581 | ||
582 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
583 | { | |
584 | // not available on mac | |
585 | } | |
586 | ||
587 | bool wxTopLevelWindowMac::IsMaximized() const | |
588 | { | |
1542ea39 | 589 | return false ; |
a15eb0a5 SC |
590 | } |
591 | ||
592 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
593 | { | |
594 | // not available on mac | |
595 | } | |
596 | ||
597 | bool wxTopLevelWindowMac::IsIconized() const | |
598 | { | |
ed60b502 | 599 | // mac dialogs cannot be iconized |
a15eb0a5 SC |
600 | return FALSE; |
601 | } | |
602 | ||
603 | void wxTopLevelWindowMac::Restore() | |
604 | { | |
605 | // not available on mac | |
606 | } | |
607 | ||
608 | // ---------------------------------------------------------------------------- | |
609 | // wxTopLevelWindowMac misc | |
610 | // ---------------------------------------------------------------------------- | |
611 | ||
612 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) | |
613 | { | |
614 | // this sets m_icon | |
615 | wxTopLevelWindowBase::SetIcon(icon); | |
616 | } | |
5f0b2f22 SC |
617 | |
618 | void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, | |
619 | const wxPoint& pos, | |
620 | const wxSize& size, | |
621 | long style, | |
1542ea39 | 622 | const wxString& name ) |
5f0b2f22 | 623 | { |
e40298d5 JS |
624 | SetName(name); |
625 | m_windowStyle = style; | |
626 | m_isShown = FALSE; | |
1542ea39 | 627 | |
e40298d5 | 628 | // create frame. |
1542ea39 | 629 | |
5f0b2f22 | 630 | Rect theBoundsRect; |
1542ea39 | 631 | |
e40298d5 JS |
632 | m_x = (int)pos.x; |
633 | m_y = (int)pos.y; | |
634 | if ( m_y < 50 ) | |
635 | m_y = 50 ; | |
636 | if ( m_x < 20 ) | |
637 | m_x = 20 ; | |
1542ea39 | 638 | |
e40298d5 | 639 | m_width = size.x; |
1542ea39 | 640 | if (m_width == -1) |
5f0b2f22 | 641 | m_width = 20; |
e40298d5 | 642 | m_height = size.y; |
1542ea39 | 643 | if (m_height == -1) |
5f0b2f22 | 644 | m_height = 20; |
1542ea39 | 645 | |
5f0b2f22 | 646 | ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height); |
1542ea39 | 647 | |
5f0b2f22 | 648 | // translate the window attributes in the appropriate window class and attributes |
1542ea39 | 649 | |
5f0b2f22 SC |
650 | WindowClass wclass = 0; |
651 | WindowAttributes attr = kWindowNoAttributes ; | |
1542ea39 | 652 | |
f5744893 | 653 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 654 | { |
1542ea39 | 655 | if ( |
f5744893 SC |
656 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
657 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
658 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
e40298d5 | 659 | ) |
5f0b2f22 | 660 | { |
f5744893 SC |
661 | wclass = kFloatingWindowClass ; |
662 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
663 | { | |
664 | attr |= kWindowSideTitlebarAttribute ; | |
665 | } | |
666 | } | |
667 | else | |
668 | { | |
2b5f62a0 | 669 | #if TARGET_CARBON |
f5744893 | 670 | wclass = kPlainWindowClass ; |
2b5f62a0 VZ |
671 | #else |
672 | wclass = kFloatingWindowClass ; | |
673 | #endif | |
5f0b2f22 SC |
674 | } |
675 | } | |
676 | else if ( HasFlag( wxCAPTION ) ) | |
677 | { | |
1542ea39 | 678 | wclass = kDocumentWindowClass ; |
5f0b2f22 SC |
679 | } |
680 | else | |
681 | { | |
f5744893 | 682 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
e40298d5 | 683 | HasFlag( wxSYSTEM_MENU ) ) |
f5744893 SC |
684 | { |
685 | wclass = kDocumentWindowClass ; | |
686 | } | |
687 | else | |
688 | { | |
2b5f62a0 | 689 | #if TARGET_CARBON |
f5744893 | 690 | wclass = kPlainWindowClass ; |
2b5f62a0 VZ |
691 | #else |
692 | wclass = kModalWindowClass ; | |
693 | #endif | |
f5744893 | 694 | } |
5f0b2f22 | 695 | } |
1542ea39 | 696 | |
5f0b2f22 SC |
697 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ) |
698 | { | |
699 | attr |= kWindowFullZoomAttribute ; | |
700 | attr |= kWindowCollapseBoxAttribute ; | |
701 | } | |
702 | if ( HasFlag( wxRESIZE_BORDER ) ) | |
703 | { | |
704 | attr |= kWindowResizableAttribute ; | |
705 | } | |
706 | if ( HasFlag( wxSYSTEM_MENU ) ) | |
707 | { | |
708 | attr |= kWindowCloseBoxAttribute ; | |
709 | } | |
1542ea39 | 710 | |
b9c10231 SC |
711 | #if TARGET_CARBON |
712 | #if 0 // having problems right now with that | |
6a7e6411 RD |
713 | if (HasFlag(wxSTAY_ON_TOP)) |
714 | wclass = kUtilityWindowClass; | |
b9c10231 SC |
715 | #endif |
716 | #endif | |
6a7e6411 | 717 | |
45ff8005 | 718 | #if TARGET_CARBON |
6a7e6411 RD |
719 | if ( HasFlag(wxFRAME_SHAPED) ) |
720 | { | |
721 | WindowDefSpec customWindowDefSpec; | |
722 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
723 | customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef); | |
724 | ||
725 | ::CreateCustomWindow( &customWindowDefSpec, wclass, | |
726 | attr, &theBoundsRect, | |
727 | (WindowRef*) &m_macWindow); | |
728 | } | |
729 | else | |
45ff8005 | 730 | #endif |
6a7e6411 RD |
731 | { |
732 | ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; | |
733 | } | |
734 | ||
5f0b2f22 | 735 | wxAssociateWinWithMacWindow( m_macWindow , this ) ; |
427ff662 | 736 | UMASetWTitle( (WindowRef)m_macWindow , title ) ; |
76a5e5d2 | 737 | ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ; |
851b3a88 | 738 | #if TARGET_CARBON |
e40298d5 | 739 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; |
1542ea39 RD |
740 | InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacWindowEventHandlerUPP(), |
741 | GetEventTypeCount(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler)); | |
851b3a88 | 742 | #endif |
5f0b2f22 | 743 | m_macFocus = NULL ; |
6a7e6411 RD |
744 | |
745 | ||
45ff8005 | 746 | #if TARGET_CARBON |
6a7e6411 RD |
747 | if ( HasFlag(wxFRAME_SHAPED) ) |
748 | { | |
749 | // default shape matches the window size | |
750 | wxRegion rgn(0, 0, m_width, m_height); | |
751 | SetShape(rgn); | |
752 | } | |
45ff8005 | 753 | #endif |
5f0b2f22 SC |
754 | } |
755 | ||
1542ea39 | 756 | void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin) |
5f0b2f22 | 757 | { |
76a5e5d2 SC |
758 | ((Point*)localOrigin)->h = 0; |
759 | ((Point*)localOrigin)->v = 0; | |
760 | ((Rect*)clipRect)->left = 0; | |
761 | ((Rect*)clipRect)->top = 0; | |
762 | ((Rect*)clipRect)->right = m_width; | |
763 | ((Rect*)clipRect)->bottom = m_height; | |
5f0b2f22 SC |
764 | *window = m_macWindow ; |
765 | *rootwin = this ; | |
766 | } | |
767 | ||
768 | void wxTopLevelWindowMac::Clear() | |
769 | { | |
e40298d5 | 770 | wxWindow::Clear() ; |
5f0b2f22 SC |
771 | } |
772 | ||
1542ea39 | 773 | WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding() |
5f0b2f22 SC |
774 | { |
775 | return m_macRootControl ; | |
776 | } | |
777 | ||
778 | ||
779 | void wxTopLevelWindowMac::MacUpdate( long timestamp) | |
780 | { | |
66a09d47 | 781 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
76a5e5d2 | 782 | |
1925be65 SC |
783 | RgnHandle visRgn = NewRgn() ; |
784 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), visRgn ); | |
76a5e5d2 | 785 | BeginUpdate( (WindowRef)m_macWindow ) ; |
5f0b2f22 | 786 | |
1542ea39 | 787 | RgnHandle updateRgn = NewRgn(); |
5f0b2f22 | 788 | RgnHandle diffRgn = NewRgn() ; |
1925be65 | 789 | |
5f0b2f22 SC |
790 | if ( updateRgn && diffRgn ) |
791 | { | |
732b3a75 SC |
792 | #if 1 |
793 | // macos internal control redraws clean up areas we'd like to redraw ourselves | |
794 | // therefore we pick the boundary rect and make sure we can redraw it | |
1925be65 SC |
795 | // this has to be intersected by the visRgn in order to avoid drawing over its own |
796 | // boundaries | |
732b3a75 SC |
797 | RgnHandle trueUpdateRgn = NewRgn() ; |
798 | Rect trueUpdateRgnBoundary ; | |
799 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), trueUpdateRgn ); | |
800 | GetRegionBounds( trueUpdateRgn , &trueUpdateRgnBoundary ) ; | |
1925be65 SC |
801 | RectRgn( updateRgn , &trueUpdateRgnBoundary ) ; |
802 | SectRgn( updateRgn , visRgn , updateRgn ) ; | |
732b3a75 SC |
803 | if ( trueUpdateRgn ) |
804 | DisposeRgn( trueUpdateRgn ) ; | |
805 | SetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ) ; | |
806 | #else | |
76a5e5d2 | 807 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); |
732b3a75 | 808 | #endif |
76a5e5d2 | 809 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; |
5f0b2f22 SC |
810 | if ( !EmptyRgn( updateRgn ) ) |
811 | { | |
812 | MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ; | |
813 | } | |
814 | } | |
815 | if ( updateRgn ) | |
816 | DisposeRgn( updateRgn ); | |
817 | if ( diffRgn ) | |
818 | DisposeRgn( diffRgn ); | |
1925be65 SC |
819 | if ( visRgn ) |
820 | DisposeRgn( visRgn ) ; | |
821 | ||
76a5e5d2 SC |
822 | EndUpdate( (WindowRef)m_macWindow ) ; |
823 | SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
5f0b2f22 SC |
824 | m_macNeedsErasing = false ; |
825 | } | |
826 | ||
827 | ||
828 | // Raise the window to the top of the Z order | |
829 | void wxTopLevelWindowMac::Raise() | |
830 | { | |
7f3c339c | 831 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
832 | } |
833 | ||
834 | // Lower the window to the bottom of the Z order | |
835 | void wxTopLevelWindowMac::Lower() | |
836 | { | |
76a5e5d2 | 837 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
838 | } |
839 | ||
1542ea39 | 840 | void wxTopLevelWindowMac::MacFireMouseEvent( |
e40298d5 | 841 | wxUint16 kind , wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp ) |
5f0b2f22 SC |
842 | { |
843 | wxMouseEvent event(wxEVT_LEFT_DOWN); | |
851b3a88 SC |
844 | bool isDown = !(modifiers & btnState) ; // 1 is for up |
845 | bool controlDown = modifiers & controlKey ; // for simulating right mouse | |
1542ea39 | 846 | |
5f0b2f22 | 847 | event.m_leftDown = isDown && !controlDown; |
1542ea39 | 848 | |
5f0b2f22 SC |
849 | event.m_middleDown = FALSE; |
850 | event.m_rightDown = isDown && controlDown; | |
851 | ||
851b3a88 | 852 | if ( kind == mouseDown ) |
5f0b2f22 SC |
853 | { |
854 | if ( controlDown ) | |
855 | event.SetEventType(wxEVT_RIGHT_DOWN ) ; | |
856 | else | |
857 | event.SetEventType(wxEVT_LEFT_DOWN ) ; | |
858 | } | |
851b3a88 | 859 | else if ( kind == mouseUp ) |
5f0b2f22 SC |
860 | { |
861 | if ( controlDown ) | |
862 | event.SetEventType(wxEVT_RIGHT_UP ) ; | |
863 | else | |
864 | event.SetEventType(wxEVT_LEFT_UP ) ; | |
865 | } | |
866 | else | |
867 | { | |
868 | event.SetEventType(wxEVT_MOTION ) ; | |
869 | } | |
870 | ||
851b3a88 SC |
871 | event.m_shiftDown = modifiers & shiftKey; |
872 | event.m_controlDown = modifiers & controlKey; | |
873 | event.m_altDown = modifiers & optionKey; | |
874 | event.m_metaDown = modifiers & cmdKey; | |
5f0b2f22 | 875 | |
851b3a88 SC |
876 | Point localwhere ; |
877 | localwhere.h = x ; | |
878 | localwhere.v = y ; | |
1542ea39 RD |
879 | |
880 | GrafPtr port ; | |
5f0b2f22 | 881 | ::GetPort( &port ) ; |
76a5e5d2 | 882 | ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ; |
5f0b2f22 SC |
883 | ::GlobalToLocal( &localwhere ) ; |
884 | ::SetPort( port ) ; | |
885 | ||
851b3a88 | 886 | if ( kind == mouseDown ) |
5f0b2f22 | 887 | { |
5be55d56 | 888 | if ( timestamp - gs_lastWhen <= (long) GetDblTime() ) |
5f0b2f22 | 889 | { |
32b5be3d | 890 | if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 ) |
5f0b2f22 | 891 | { |
32b5be3d RR |
892 | // This is not right if the second mouse down |
893 | // event occured in a differen window. We | |
894 | // correct this in MacDispatchMouseEvent. | |
5f0b2f22 SC |
895 | if ( controlDown ) |
896 | event.SetEventType(wxEVT_RIGHT_DCLICK ) ; | |
897 | else | |
898 | event.SetEventType(wxEVT_LEFT_DCLICK ) ; | |
899 | } | |
32b5be3d | 900 | gs_lastWhen = 0 ; |
5f0b2f22 SC |
901 | } |
902 | else | |
903 | { | |
851b3a88 | 904 | gs_lastWhen = timestamp ; |
5f0b2f22 | 905 | } |
32b5be3d | 906 | gs_lastWhere = localwhere ; |
5f0b2f22 SC |
907 | } |
908 | ||
909 | event.m_x = localwhere.h; | |
910 | event.m_y = localwhere.v; | |
911 | event.m_x += m_x; | |
912 | event.m_y += m_y; | |
913 | ||
851b3a88 | 914 | event.m_timeStamp = timestamp; |
5f0b2f22 SC |
915 | event.SetEventObject(this); |
916 | if ( wxTheApp->s_captureWindow ) | |
917 | { | |
918 | int x = event.m_x ; | |
919 | int y = event.m_y ; | |
920 | wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ; | |
921 | event.m_x = x ; | |
922 | event.m_y = y ; | |
2e6857fa | 923 | event.SetEventObject( wxTheApp->s_captureWindow ) ; |
5f0b2f22 | 924 | wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; |
1542ea39 | 925 | |
851b3a88 | 926 | if ( kind == mouseUp ) |
5f0b2f22 SC |
927 | { |
928 | wxTheApp->s_captureWindow = NULL ; | |
6b57b49a | 929 | if ( !wxIsBusy() ) |
5f0b2f22 SC |
930 | { |
931 | m_cursor.MacInstall() ; | |
932 | } | |
933 | } | |
934 | } | |
935 | else | |
936 | { | |
937 | MacDispatchMouseEvent( event ) ; | |
938 | } | |
939 | } | |
e40298d5 | 940 | |
851b3a88 | 941 | #if !TARGET_CARBON |
5f0b2f22 | 942 | |
76a5e5d2 | 943 | void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part) |
5f0b2f22 | 944 | { |
1542ea39 | 945 | MacFireMouseEvent( mouseDown , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 946 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
947 | } |
948 | ||
76a5e5d2 | 949 | void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part) |
5f0b2f22 SC |
950 | { |
951 | switch (part) | |
952 | { | |
1542ea39 | 953 | case inContent: |
5f0b2f22 | 954 | { |
1542ea39 | 955 | MacFireMouseEvent( mouseUp , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 956 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
957 | } |
958 | break ; | |
959 | } | |
960 | } | |
961 | ||
76a5e5d2 | 962 | void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part) |
5f0b2f22 SC |
963 | { |
964 | switch (part) | |
965 | { | |
1542ea39 | 966 | case inContent: |
5f0b2f22 | 967 | { |
1542ea39 | 968 | MacFireMouseEvent( nullEvent /*moved*/ , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , |
e40298d5 | 969 | ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; |
5f0b2f22 SC |
970 | } |
971 | break ; | |
972 | } | |
973 | } | |
851b3a88 SC |
974 | |
975 | #endif | |
976 | ||
977 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) | |
5f0b2f22 SC |
978 | { |
979 | wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId); | |
851b3a88 | 980 | event.m_timeStamp = timestamp ; |
5f0b2f22 | 981 | event.SetEventObject(this); |
1542ea39 | 982 | |
5f0b2f22 | 983 | GetEventHandler()->ProcessEvent(event); |
1542ea39 | 984 | |
76a5e5d2 | 985 | UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ; |
1542ea39 | 986 | |
a006e78b JS |
987 | // Early versions of MacOS X don't refresh backgrounds properly, |
988 | // so refresh the whole window on activation and deactivation. | |
989 | long osVersion = UMAGetSystemVersion(); | |
1925be65 | 990 | if (osVersion >= 0x1000 && osVersion < 0x1020 ) |
732b3a75 | 991 | { |
a006e78b | 992 | Refresh(TRUE); |
732b3a75 | 993 | } |
a006e78b | 994 | else |
732b3a75 SC |
995 | { |
996 | // for the moment we have to resolve some redrawing issues like this | |
997 | // the OS is stealing some redrawing areas as soon as it draws a control | |
998 | Refresh(TRUE); | |
999 | } | |
5f0b2f22 SC |
1000 | } |
1001 | ||
851b3a88 SC |
1002 | #if !TARGET_CARBON |
1003 | ||
1542ea39 | 1004 | void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev ) |
5f0b2f22 SC |
1005 | { |
1006 | } | |
1007 | ||
851b3a88 SC |
1008 | #endif |
1009 | ||
5f0b2f22 SC |
1010 | void wxTopLevelWindowMac::SetTitle(const wxString& title) |
1011 | { | |
1012 | wxWindow::SetTitle( title ) ; | |
427ff662 | 1013 | UMASetWTitle( (WindowRef)m_macWindow , title ) ; |
5f0b2f22 SC |
1014 | } |
1015 | ||
1016 | bool wxTopLevelWindowMac::Show(bool show) | |
1017 | { | |
1018 | if ( !wxWindow::Show(show) ) | |
1019 | return FALSE; | |
1020 | ||
1021 | if (show) | |
1542ea39 | 1022 | { |
1925be65 | 1023 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil); |
76a5e5d2 | 1024 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
1025 | // no need to generate events here, they will get them triggered by macos |
1026 | // actually they should be , but apparently they are not | |
1027 | wxSize size(m_width, m_height); | |
1028 | wxSizeEvent event(size, m_windowId); | |
1029 | event.SetEventObject(this); | |
1030 | GetEventHandler()->ProcessEvent(event); | |
1031 | } | |
1032 | else | |
1033 | { | |
1925be65 | 1034 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil); |
5f0b2f22 SC |
1035 | } |
1036 | ||
1037 | if ( !show ) | |
1038 | { | |
1039 | } | |
1040 | else | |
1041 | { | |
1542ea39 | 1042 | Refresh() ; |
5f0b2f22 SC |
1043 | } |
1044 | ||
1045 | return TRUE; | |
1046 | } | |
1047 | ||
1048 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) | |
1049 | { | |
1050 | int former_x = m_x ; | |
1051 | int former_y = m_y ; | |
1052 | int former_w = m_width ; | |
1053 | int former_h = m_height ; | |
1542ea39 | 1054 | |
e40298d5 JS |
1055 | int actualWidth = width; |
1056 | int actualHeight = height; | |
1057 | int actualX = x; | |
1058 | int actualY = y; | |
1542ea39 RD |
1059 | |
1060 | if ((m_minWidth != -1) && (actualWidth < m_minWidth)) | |
5f0b2f22 | 1061 | actualWidth = m_minWidth; |
1542ea39 | 1062 | if ((m_minHeight != -1) && (actualHeight < m_minHeight)) |
5f0b2f22 | 1063 | actualHeight = m_minHeight; |
1542ea39 | 1064 | if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) |
5f0b2f22 | 1065 | actualWidth = m_maxWidth; |
1542ea39 | 1066 | if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) |
5f0b2f22 SC |
1067 | actualHeight = m_maxHeight; |
1068 | ||
1069 | bool doMove = false ; | |
1070 | bool doResize = false ; | |
1542ea39 | 1071 | |
5f0b2f22 SC |
1072 | if ( actualX != former_x || actualY != former_y ) |
1073 | { | |
1074 | doMove = true ; | |
1075 | } | |
1076 | if ( actualWidth != former_w || actualHeight != former_h ) | |
1077 | { | |
1078 | doResize = true ; | |
1079 | } | |
1080 | ||
1081 | if ( doMove || doResize ) | |
1082 | { | |
1083 | m_x = actualX ; | |
1084 | m_y = actualY ; | |
1085 | m_width = actualWidth ; | |
1086 | m_height = actualHeight ; | |
1087 | ||
1088 | if ( doMove ) | |
76a5e5d2 | 1089 | ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost |
1542ea39 | 1090 | |
5f0b2f22 | 1091 | if ( doResize ) |
1542ea39 RD |
1092 | ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true); |
1093 | ||
2b5f62a0 VZ |
1094 | // the OS takes care of invalidating and erasing the new area so we only have to |
1095 | // take care of refreshing for full repaints | |
1096 | ||
1097 | if ( doResize && !HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) ) | |
1098 | Refresh() ; | |
1542ea39 RD |
1099 | |
1100 | ||
5f0b2f22 SC |
1101 | if ( IsKindOf( CLASSINFO( wxFrame ) ) ) |
1102 | { | |
1103 | wxFrame* frame = (wxFrame*) this ; | |
1104 | frame->PositionStatusBar(); | |
1105 | frame->PositionToolBar(); | |
1106 | } | |
1107 | if ( doMove ) | |
1108 | wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified | |
1109 | ||
1110 | MacRepositionScrollBars() ; | |
1111 | if ( doMove ) | |
1112 | { | |
1113 | wxPoint point(m_x, m_y); | |
1114 | wxMoveEvent event(point, m_windowId); | |
1115 | event.SetEventObject(this); | |
1116 | GetEventHandler()->ProcessEvent(event) ; | |
1117 | } | |
1118 | if ( doResize ) | |
1119 | { | |
1120 | MacRepositionScrollBars() ; | |
1121 | wxSize size(m_width, m_height); | |
1122 | wxSizeEvent event(size, m_windowId); | |
1123 | event.SetEventObject(this); | |
1124 | GetEventHandler()->ProcessEvent(event); | |
1125 | } | |
1126 | } | |
1542ea39 | 1127 | |
5f0b2f22 SC |
1128 | } |
1129 | ||
1130 | /* | |
1131 | * Invalidation Mechanism | |
1132 | * | |
1133 | * The update mechanism reflects exactely the windows mechanism | |
1134 | * the rect gets added to the window invalidate region, if the eraseBackground flag | |
1135 | * has been true for any part of the update rgn the background is erased in the entire region | |
1136 | * not just in the specified rect. | |
1137 | * | |
1542ea39 | 1138 | * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have |
5f0b2f22 SC |
1139 | * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event |
1140 | * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window | |
1141 | * will get the eraseBackground event first | |
1142 | */ | |
1542ea39 RD |
1143 | |
1144 | void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground ) | |
5f0b2f22 | 1145 | { |
e40298d5 JS |
1146 | GrafPtr formerPort ; |
1147 | GetPort( &formerPort ) ; | |
1148 | SetPortWindowPort( (WindowRef)m_macWindow ) ; | |
1542ea39 | 1149 | |
e40298d5 | 1150 | m_macNeedsErasing |= eraseBackground ; |
1542ea39 | 1151 | |
e40298d5 JS |
1152 | // if we already know that we will have to erase, there's no need to track the rest |
1153 | if ( !m_macNeedsErasing) | |
5f0b2f22 | 1154 | { |
e40298d5 JS |
1155 | // we end only here if eraseBackground is false |
1156 | // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn | |
1157 | // we will have to erase anyway | |
1542ea39 RD |
1158 | |
1159 | RgnHandle updateRgn = NewRgn(); | |
e40298d5 JS |
1160 | RgnHandle diffRgn = NewRgn() ; |
1161 | if ( updateRgn && diffRgn ) | |
1162 | { | |
1163 | GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn ); | |
1164 | Point pt = {0,0} ; | |
1165 | LocalToGlobal( &pt ) ; | |
1166 | OffsetRgn( updateRgn , -pt.h , -pt.v ) ; | |
1167 | DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; | |
1168 | if ( !EmptyRgn( diffRgn ) ) | |
1169 | { | |
1170 | m_macNeedsErasing = true ; | |
1171 | } | |
1172 | } | |
1173 | if ( updateRgn ) | |
1174 | DisposeRgn( updateRgn ); | |
1175 | if ( diffRgn ) | |
1176 | DisposeRgn( diffRgn ); | |
1542ea39 | 1177 | |
e40298d5 | 1178 | if ( !m_macNeedsErasing ) |
5f0b2f22 | 1179 | { |
e40298d5 JS |
1180 | RgnHandle rectRgn = NewRgn() ; |
1181 | SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ; | |
1182 | UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ; | |
1183 | DisposeRgn( rectRgn ) ; | |
5f0b2f22 SC |
1184 | } |
1185 | } | |
e40298d5 JS |
1186 | InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ; |
1187 | // turn this on to debug the refreshing cycle | |
34dc8f91 | 1188 | #if wxMAC_DEBUG_REDRAW |
e40298d5 | 1189 | PaintRect( rect ) ; |
5f0b2f22 | 1190 | #endif |
e40298d5 | 1191 | SetPort( formerPort ) ; |
5f0b2f22 | 1192 | } |
a07c1212 | 1193 | |
6a7e6411 | 1194 | |
1542ea39 RD |
1195 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) |
1196 | { | |
6a7e6411 RD |
1197 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, |
1198 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); | |
1199 | ||
45ff8005 | 1200 | #if TARGET_CARBON |
6a7e6411 RD |
1201 | // The empty region signifies that the shape should be removed from the |
1202 | // window. | |
1203 | if ( region.IsEmpty() ) | |
1204 | { | |
1205 | wxSize sz = GetClientSize(); | |
1206 | wxRegion rgn(0, 0, sz.x, sz.y); | |
1207 | return SetShape(rgn); | |
1208 | } | |
1209 | ||
1210 | // Make a copy of the region | |
1211 | RgnHandle shapeRegion = NewRgn(); | |
1212 | CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); | |
1213 | ||
1214 | // Dispose of any shape region we may already have | |
1215 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1216 | if ( oldRgn ) | |
1217 | DisposeRgn(oldRgn); | |
1218 | ||
1219 | // Save the region so we can use it later | |
1220 | SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); | |
1221 | ||
1222 | // Tell the window manager that the window has changed shape | |
1223 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); | |
1224 | return TRUE; | |
45ff8005 RD |
1225 | #else |
1226 | return FALSE; | |
1227 | #endif | |
6a7e6411 RD |
1228 | } |
1229 | ||
6a7e6411 RD |
1230 | // --------------------------------------------------------------------------- |
1231 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1232 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1233 | // --------------------------------------------------------------------------- | |
1234 | ||
45ff8005 | 1235 | #if TARGET_CARBON |
1925be65 | 1236 | |
6a7e6411 RD |
1237 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) |
1238 | { | |
1239 | GetWindowPortBounds(window, inRect); | |
1240 | Point pt = {inRect->left, inRect->top}; | |
1241 | SetPort((GrafPtr) GetWindowPort(window)); | |
1242 | LocalToGlobal(&pt); | |
1243 | inRect->top = pt.v; | |
1244 | inRect->left = pt.h; | |
1245 | inRect->bottom += pt.v; | |
1246 | inRect->right += pt.h; | |
1247 | } | |
1248 | ||
1249 | ||
1250 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param) | |
1251 | { | |
1252 | /*------------------------------------------------------ | |
1253 | Define which options your custom window supports. | |
1254 | --------------------------------------------------------*/ | |
1255 | //just enable everything for our demo | |
1256 | *(OptionBits*)param=//kWindowCanGrow| | |
1257 | //kWindowCanZoom| | |
1258 | //kWindowCanCollapse| | |
1259 | //kWindowCanGetWindowRegion| | |
1260 | //kWindowHasTitleBar| | |
1261 | //kWindowSupportsDragHilite| | |
1262 | kWindowCanDrawInCurrentPort| | |
1263 | //kWindowCanMeasureTitle| | |
1264 | kWindowWantsDisposeAtProcessDeath| | |
1265 | kWindowSupportsSetGrowImageRegion| | |
1266 | kWindowDefSupportsColorGrafPort; | |
1267 | return 1; | |
1542ea39 | 1268 | } |
6a7e6411 RD |
1269 | |
1270 | // The content region is left as a rectangle matching the window size, this is | |
1271 | // so the origin in the paint event, and etc. still matches what the | |
1272 | // programmer expects. | |
1273 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1274 | { | |
1275 | SetEmptyRgn(rgn); | |
1276 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1277 | if (win) | |
1278 | { | |
1279 | wxRect r = win->GetRect(); | |
1280 | SetRectRgn(rgn, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom()); | |
1281 | } | |
1282 | } | |
1283 | ||
1284 | // The structure region is set to the shape given to the SetShape method. | |
1285 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1286 | { | |
1287 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1288 | ||
1289 | SetEmptyRgn(rgn); | |
1290 | if (cachedRegion) | |
1291 | { | |
1292 | Rect windowRect; | |
1293 | wxShapedMacWindowGetPos(window, &windowRect); //how big is the window | |
1294 | CopyRgn(cachedRegion, rgn); //make a copy of our cached region | |
1295 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window | |
1296 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size | |
1297 | } | |
1298 | } | |
1299 | ||
1300 | ||
1301 | ||
1302 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) | |
1303 | { | |
1304 | GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param; | |
1305 | ||
1306 | switch(rgnRec->regionCode) | |
1307 | { | |
1308 | case kWindowStructureRgn: | |
1309 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1310 | break; | |
1311 | case kWindowContentRgn: | |
1312 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1313 | break; | |
1314 | default: | |
1315 | SetEmptyRgn(rgnRec->winRgn); | |
1316 | } //switch | |
1317 | ||
1318 | return noErr; | |
1319 | } | |
1320 | ||
1321 | ||
1322 | static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param) | |
1323 | { | |
1324 | /*------------------------------------------------------ | |
1325 | Determine the region of the window which was hit | |
1326 | --------------------------------------------------------*/ | |
1327 | Point hitPoint; | |
1328 | static RgnHandle tempRgn=nil; | |
1329 | ||
1330 | if(!tempRgn) | |
1331 | tempRgn=NewRgn(); | |
1332 | ||
1333 | SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked | |
1334 | ||
1335 | //Mac OS 8.5 or later | |
1336 | wxShapedMacWindowStructureRegion(window, tempRgn); | |
1337 | if (PtInRgn(hitPoint, tempRgn)) //in window content region? | |
1338 | return wInContent; | |
1339 | ||
1340 | return wNoHit;//no significant area was hit. | |
1341 | } | |
1342 | ||
1343 | ||
1344 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param) | |
1345 | { | |
1346 | switch(message) | |
1347 | { | |
1348 | case kWindowMsgHitTest: | |
1349 | return wxShapedMacWindowHitTest(window,param); | |
1350 | ||
1351 | case kWindowMsgGetFeatures: | |
1352 | return wxShapedMacWindowGetFeatures(window,param); | |
1353 | ||
1354 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
1355 | case kWindowMsgGetRegion: | |
1356 | return wxShapedMacWindowGetRegion(window,param); | |
1357 | } | |
1358 | ||
1359 | return 0; | |
1360 | } | |
1925be65 | 1361 | |
45ff8005 | 1362 | #endif |
6a7e6411 | 1363 | // --------------------------------------------------------------------------- |
1925be65 | 1364 |