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