]>
Commit | Line | Data |
---|---|---|
489468fe | 1 | ///////////////////////////////////////////////////////////////////////////// |
524c47aa | 2 | // Name: src/osx/carbon/nonownedwnd.cpp |
489468fe SC |
3 | // Purpose: implementation of wxNonOwnedWindow |
4 | // Author: Stefan Csomor | |
5 | // Created: 2008-03-24 | |
6 | // RCS-ID: $Id: nonownedwnd.cpp 50329 2007-11-29 17:00:58Z VS $ | |
7 | // Copyright: (c) Stefan Csomor 2008 | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // For compilers that support precompilation, includes "wx.h". | |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifndef WX_PRECOMP | |
15 | #include "wx/app.h" | |
16 | #endif // WX_PRECOMP | |
17 | ||
18 | #include "wx/hashmap.h" | |
19 | #include "wx/evtloop.h" | |
20 | #include "wx/tooltip.h" | |
21 | #include "wx/nonownedwnd.h" | |
22 | ||
1f0c8f31 | 23 | #include "wx/osx/private.h" |
489468fe SC |
24 | #include "wx/settings.h" |
25 | #include "wx/frame.h" | |
26 | ||
27 | #if wxUSE_SYSTEM_OPTIONS | |
28 | #include "wx/sysopt.h" | |
29 | #endif | |
30 | ||
524c47aa SC |
31 | // ============================================================================ |
32 | // wxNonOwnedWindow implementation | |
33 | // ============================================================================ | |
b2680ced | 34 | |
e185a681 SC |
35 | // unified title and toolbar constant - not in Tiger headers, so we duplicate it here |
36 | #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7) | |
37 | ||
b2680ced SC |
38 | IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCarbonImpl , wxNonOwnedWindowImpl ) |
39 | ||
b2680ced SC |
40 | WXWindow wxNonOwnedWindowCarbonImpl::GetWXWindow() const |
41 | { | |
42 | return (WXWindow) m_macWindow; | |
43 | } | |
44 | void wxNonOwnedWindowCarbonImpl::Raise() | |
45 | { | |
46 | ::SelectWindow( m_macWindow ) ; | |
47 | } | |
48 | ||
49 | void wxNonOwnedWindowCarbonImpl::Lower() | |
50 | { | |
51 | ::SendBehind( m_macWindow , NULL ) ; | |
52 | } | |
53 | ||
dbc7ceb9 KO |
54 | void wxNonOwnedWindowCarbonImpl::ShowWithoutActivating() |
55 | { | |
56 | bool plainTransition = true; | |
57 | ||
58 | #if wxUSE_SYSTEM_OPTIONS | |
59 | if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) | |
60 | plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ; | |
61 | #endif | |
62 | ||
63 | if ( plainTransition ) | |
64 | ::ShowWindow( (WindowRef)m_macWindow ); | |
65 | else | |
66 | ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL ); | |
67 | } | |
68 | ||
b2680ced SC |
69 | bool wxNonOwnedWindowCarbonImpl::Show(bool show) |
70 | { | |
71 | bool plainTransition = true; | |
72 | ||
73 | #if wxUSE_SYSTEM_OPTIONS | |
74 | if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) | |
75 | plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ; | |
76 | #endif | |
77 | ||
78 | if (show) | |
79 | { | |
dbc7ceb9 | 80 | ShowWithoutActivating(); |
b2680ced | 81 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
b2680ced SC |
82 | } |
83 | else | |
84 | { | |
85 | #if wxOSX_USE_CARBON | |
86 | if ( plainTransition ) | |
87 | ::HideWindow( (WindowRef)m_macWindow ); | |
88 | else | |
89 | ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowHideTransitionAction, NULL ); | |
90 | #endif | |
91 | } | |
92 | return true; | |
93 | } | |
94 | ||
95 | void wxNonOwnedWindowCarbonImpl::Update() | |
96 | { | |
97 | HIWindowFlush(m_macWindow) ; | |
98 | } | |
99 | ||
100 | bool wxNonOwnedWindowCarbonImpl::SetTransparent(wxByte alpha) | |
101 | { | |
102 | OSStatus result = SetWindowAlpha((WindowRef)m_macWindow, (CGFloat)((alpha)/255.0)); | |
103 | return result == noErr; | |
104 | } | |
105 | ||
106 | bool wxNonOwnedWindowCarbonImpl::SetBackgroundColour(const wxColour& col ) | |
107 | { | |
108 | if ( col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground)) ) | |
109 | { | |
110 | SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDocumentWindowBackground, false ) ; | |
4d949e7f SC |
111 | m_wxPeer->SetBackgroundStyle(wxBG_STYLE_SYSTEM); |
112 | // call directly if object is not yet completely constructed | |
113 | if ( m_wxPeer->GetNonOwnedPeer() == NULL ) | |
114 | SetBackgroundStyle(wxBG_STYLE_SYSTEM); | |
b2680ced SC |
115 | } |
116 | else if ( col == wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive)) ) | |
117 | { | |
118 | SetThemeWindowBackground( (WindowRef) m_macWindow, kThemeBrushDialogBackgroundActive, false ) ; | |
4d949e7f SC |
119 | m_wxPeer->SetBackgroundStyle(wxBG_STYLE_SYSTEM); |
120 | // call directly if object is not yet completely constructed | |
121 | if ( m_wxPeer->GetNonOwnedPeer() == NULL ) | |
122 | SetBackgroundStyle(wxBG_STYLE_SYSTEM); | |
b2680ced SC |
123 | } |
124 | return true; | |
125 | } | |
126 | ||
127 | void wxNonOwnedWindowCarbonImpl::SetExtraStyle( long exStyle ) | |
128 | { | |
129 | if ( m_macWindow != NULL ) | |
130 | { | |
131 | bool metal = exStyle & wxFRAME_EX_METAL ; | |
132 | ||
133 | if ( MacGetMetalAppearance() != metal ) | |
134 | { | |
135 | if ( MacGetUnifiedAppearance() ) | |
136 | MacSetUnifiedAppearance( !metal ) ; | |
137 | ||
138 | MacSetMetalAppearance( metal ) ; | |
139 | } | |
140 | } | |
141 | } | |
142 | ||
143 | bool wxNonOwnedWindowCarbonImpl::SetBackgroundStyle(wxBackgroundStyle style) | |
03647350 | 144 | { |
b2680ced SC |
145 | if ( style == wxBG_STYLE_TRANSPARENT ) |
146 | { | |
147 | OSStatus err = HIWindowChangeFeatures( m_macWindow, 0, kWindowIsOpaque ); | |
148 | verify_noerr( err ); | |
149 | err = ReshapeCustomWindow( m_macWindow ); | |
150 | verify_noerr( err ); | |
151 | } | |
152 | ||
153 | return true ; | |
154 | } | |
155 | ||
156 | bool wxNonOwnedWindowCarbonImpl::CanSetTransparent() | |
157 | { | |
158 | return true; | |
159 | } | |
160 | ||
161 | void wxNonOwnedWindowCarbonImpl::GetContentArea( int &left , int &top , int &width , int &height ) const | |
162 | { | |
163 | Rect content, structure ; | |
164 | ||
165 | GetWindowBounds( m_macWindow, kWindowStructureRgn , &structure ) ; | |
166 | GetWindowBounds( m_macWindow, kWindowContentRgn , &content ) ; | |
167 | ||
168 | left = content.left - structure.left ; | |
169 | top = content.top - structure.top ; | |
170 | width = content.right - content.left ; | |
171 | height = content.bottom - content.top ; | |
172 | } | |
173 | ||
174 | void wxNonOwnedWindowCarbonImpl::MoveWindow(int x, int y, int width, int height) | |
175 | { | |
176 | Rect bounds = { y , x , y + height , x + width } ; | |
177 | verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
178 | } | |
179 | ||
180 | void wxNonOwnedWindowCarbonImpl::GetPosition( int &x, int &y ) const | |
181 | { | |
182 | Rect bounds ; | |
183 | ||
184 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
185 | ||
186 | x = bounds.left ; | |
187 | y = bounds.top ; | |
188 | } | |
189 | ||
190 | void wxNonOwnedWindowCarbonImpl::GetSize( int &width, int &height ) const | |
191 | { | |
192 | Rect bounds ; | |
193 | ||
194 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
195 | ||
196 | width = bounds.right - bounds.left ; | |
197 | height = bounds.bottom - bounds.top ; | |
198 | } | |
199 | ||
200 | bool wxNonOwnedWindowCarbonImpl::MacGetUnifiedAppearance() const | |
201 | { | |
202 | return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute ; | |
203 | } | |
204 | ||
205 | void wxNonOwnedWindowCarbonImpl::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear ) | |
206 | { | |
207 | ChangeWindowAttributes( m_macWindow, attributesToSet, attributesToClear ) ; | |
208 | } | |
209 | ||
210 | wxUint32 wxNonOwnedWindowCarbonImpl::MacGetWindowAttributes() const | |
211 | { | |
212 | UInt32 attr = 0 ; | |
213 | GetWindowAttributes( m_macWindow, &attr ) ; | |
214 | return attr ; | |
215 | } | |
216 | ||
217 | void wxNonOwnedWindowCarbonImpl::MacSetMetalAppearance( bool set ) | |
218 | { | |
219 | if ( MacGetUnifiedAppearance() ) | |
220 | MacSetUnifiedAppearance( false ) ; | |
221 | ||
222 | MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , | |
223 | set ? kWindowNoAttributes : kWindowMetalAttribute ) ; | |
224 | } | |
225 | ||
226 | bool wxNonOwnedWindowCarbonImpl::MacGetMetalAppearance() const | |
227 | { | |
228 | return MacGetWindowAttributes() & kWindowMetalAttribute ; | |
229 | } | |
230 | ||
231 | void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set ) | |
232 | { | |
233 | if ( MacGetMetalAppearance() ) | |
234 | MacSetMetalAppearance( false ) ; | |
235 | ||
236 | MacChangeWindowAttributes( set ? kWindowUnifiedTitleAndToolbarAttribute : kWindowNoAttributes , | |
237 | set ? kWindowNoAttributes : kWindowUnifiedTitleAndToolbarAttribute) ; | |
238 | ||
239 | // For some reason, Tiger uses white as the background color for this appearance, | |
240 | // while most apps using it use the typical striped background. Restore that behavior | |
241 | // for wx. | |
242 | // TODO: Determine if we need this on Leopard as well. (should be harmless either way, | |
243 | // though) | |
03647350 | 244 | // since when creating the peering is not yet completely set-up we call both setters |
524c47aa | 245 | // explicitely |
b2680ced | 246 | m_wxPeer->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ; |
524c47aa | 247 | SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ) ; |
b2680ced | 248 | } |
489468fe | 249 | |
489468fe SC |
250 | |
251 | // ---------------------------------------------------------------------------- | |
252 | // globals | |
253 | // ---------------------------------------------------------------------------- | |
254 | ||
255 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); | |
256 | ||
b2680ced | 257 | |
489468fe SC |
258 | // --------------------------------------------------------------------------- |
259 | // Carbon Events | |
260 | // --------------------------------------------------------------------------- | |
261 | ||
262 | static const EventTypeSpec eventList[] = | |
263 | { | |
264 | // TODO: remove control related event like key and mouse (except for WindowLeave events) | |
265 | ||
266 | { kEventClassKeyboard, kEventRawKeyDown } , | |
267 | { kEventClassKeyboard, kEventRawKeyRepeat } , | |
268 | { kEventClassKeyboard, kEventRawKeyUp } , | |
269 | { kEventClassKeyboard, kEventRawKeyModifiersChanged } , | |
270 | ||
271 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , | |
272 | { kEventClassTextInput, kEventTextInputUpdateActiveInputArea } , | |
273 | ||
274 | { kEventClassWindow , kEventWindowShown } , | |
275 | { kEventClassWindow , kEventWindowActivated } , | |
276 | { kEventClassWindow , kEventWindowDeactivated } , | |
277 | { kEventClassWindow , kEventWindowBoundsChanging } , | |
278 | { kEventClassWindow , kEventWindowBoundsChanged } , | |
279 | { kEventClassWindow , kEventWindowClose } , | |
280 | { kEventClassWindow , kEventWindowGetRegion } , | |
281 | ||
282 | // we have to catch these events on the toplevel window level, | |
283 | // as controls don't get the raw mouse events anymore | |
284 | ||
285 | { kEventClassMouse , kEventMouseDown } , | |
286 | { kEventClassMouse , kEventMouseUp } , | |
287 | { kEventClassMouse , kEventMouseWheelMoved } , | |
288 | { kEventClassMouse , kEventMouseMoved } , | |
289 | { kEventClassMouse , kEventMouseDragged } , | |
290 | } ; | |
291 | ||
292 | static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
293 | { | |
294 | OSStatus result = eventNotHandledErr ; | |
295 | // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl) | |
296 | // FindFocus does not return the actual focus window, but the enclosing window | |
297 | wxWindow* focus = wxWindow::DoFindFocus(); | |
298 | if ( focus == NULL ) | |
b2680ced | 299 | focus = data ? ((wxNonOwnedWindowImpl*) data)->GetWXPeer() : NULL ; |
489468fe SC |
300 | |
301 | unsigned char charCode ; | |
302 | wxChar uniChar[2] ; | |
303 | uniChar[0] = 0; | |
304 | uniChar[1] = 0; | |
305 | ||
306 | UInt32 keyCode ; | |
307 | UInt32 modifiers ; | |
308 | Point point ; | |
309 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
310 | ||
311 | #if wxUSE_UNICODE | |
312 | ByteCount dataSize = 0 ; | |
313 | if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr ) | |
314 | { | |
315 | UniChar buf[2] ; | |
316 | int numChars = dataSize / sizeof( UniChar) + 1; | |
317 | ||
318 | UniChar* charBuf = buf ; | |
319 | ||
320 | if ( numChars * 2 > 4 ) | |
321 | charBuf = new UniChar[ numChars ] ; | |
322 | GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ; | |
323 | charBuf[ numChars - 1 ] = 0; | |
324 | ||
325 | #if SIZEOF_WCHAR_T == 2 | |
326 | uniChar = charBuf[0] ; | |
327 | #else | |
328 | wxMBConvUTF16 converter ; | |
329 | converter.MB2WC( uniChar , (const char*)charBuf , 2 ) ; | |
330 | #endif | |
331 | ||
332 | if ( numChars * 2 > 4 ) | |
333 | delete[] charBuf ; | |
334 | } | |
335 | #endif | |
336 | ||
337 | GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &charCode ); | |
338 | GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
339 | GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers ); | |
340 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &point ); | |
341 | ||
342 | UInt32 message = (keyCode << 8) + charCode; | |
343 | switch ( GetEventKind( event ) ) | |
344 | { | |
345 | case kEventRawKeyRepeat : | |
346 | case kEventRawKeyDown : | |
347 | { | |
348 | WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ; | |
349 | WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
350 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
351 | if ( /* focus && */ wxTheApp->MacSendKeyDownEvent( | |
352 | focus , message , modifiers , when , point.h , point.v , uniChar[0] ) ) | |
353 | { | |
354 | result = noErr ; | |
355 | } | |
356 | wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ; | |
357 | } | |
358 | break ; | |
359 | ||
360 | case kEventRawKeyUp : | |
361 | if ( /* focus && */ wxTheApp->MacSendKeyUpEvent( | |
362 | focus , message , modifiers , when , point.h , point.v , uniChar[0] ) ) | |
363 | { | |
364 | result = noErr ; | |
365 | } | |
366 | break ; | |
367 | ||
368 | case kEventRawKeyModifiersChanged : | |
369 | { | |
370 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
371 | ||
372 | event.m_shiftDown = modifiers & shiftKey; | |
373 | event.m_controlDown = modifiers & controlKey; | |
374 | event.m_altDown = modifiers & optionKey; | |
375 | event.m_metaDown = modifiers & cmdKey; | |
376 | event.m_x = point.h; | |
377 | event.m_y = point.v; | |
378 | ||
379 | #if wxUSE_UNICODE | |
380 | event.m_uniChar = uniChar[0] ; | |
381 | #endif | |
382 | ||
383 | event.SetTimestamp(when); | |
384 | event.SetEventObject(focus); | |
385 | ||
386 | if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & controlKey ) | |
387 | { | |
388 | event.m_keyCode = WXK_CONTROL ; | |
389 | event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
390 | focus->HandleWindowEvent( event ) ; | |
391 | } | |
392 | if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & shiftKey ) | |
393 | { | |
394 | event.m_keyCode = WXK_SHIFT ; | |
395 | event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
396 | focus->HandleWindowEvent( event ) ; | |
397 | } | |
398 | if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & optionKey ) | |
399 | { | |
400 | event.m_keyCode = WXK_ALT ; | |
401 | event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
402 | focus->HandleWindowEvent( event ) ; | |
403 | } | |
404 | if ( /* focus && */ (modifiers ^ wxApp::s_lastModifiers ) & cmdKey ) | |
405 | { | |
406 | event.m_keyCode = WXK_COMMAND ; | |
407 | event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
408 | focus->HandleWindowEvent( event ) ; | |
409 | } | |
410 | ||
411 | wxApp::s_lastModifiers = modifiers ; | |
412 | } | |
413 | break ; | |
414 | ||
415 | default: | |
416 | break; | |
417 | } | |
418 | ||
419 | return result ; | |
420 | } | |
421 | ||
422 | // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr | |
423 | // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the | |
424 | // mouse down at all | |
425 | // | |
426 | // This handler can also be called from app level where data (ie target window) may be null or a non wx window | |
427 | ||
489468fe SC |
428 | EventMouseButton g_lastButton = 0 ; |
429 | bool g_lastButtonWasFakeRight = false ; | |
430 | ||
431 | void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) | |
432 | { | |
433 | UInt32 modifiers = cEvent.GetParameter<UInt32>(kEventParamKeyModifiers, typeUInt32) ; | |
434 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; | |
435 | ||
436 | // these parameters are not given for all events | |
437 | EventMouseButton button = 0 ; | |
438 | UInt32 clickCount = 0 ; | |
439 | UInt32 mouseChord = 0; | |
440 | ||
441 | cEvent.GetParameter<EventMouseButton>( kEventParamMouseButton, typeMouseButton , &button ) ; | |
442 | cEvent.GetParameter<UInt32>( kEventParamClickCount, typeUInt32 , &clickCount ) ; | |
443 | // the chord is the state of the buttons pressed currently | |
444 | cEvent.GetParameter<UInt32>( kEventParamMouseChord, typeUInt32 , &mouseChord ) ; | |
445 | ||
446 | wxevent.m_x = screenMouseLocation.h; | |
447 | wxevent.m_y = screenMouseLocation.v; | |
448 | wxevent.m_shiftDown = modifiers & shiftKey; | |
449 | wxevent.m_controlDown = modifiers & controlKey; | |
450 | wxevent.m_altDown = modifiers & optionKey; | |
451 | wxevent.m_metaDown = modifiers & cmdKey; | |
452 | wxevent.m_clickCount = clickCount; | |
453 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
454 | ||
455 | // a control click is interpreted as a right click | |
456 | bool thisButtonIsFakeRight = false ; | |
457 | if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) ) | |
458 | { | |
459 | button = kEventMouseButtonSecondary ; | |
460 | thisButtonIsFakeRight = true ; | |
461 | } | |
462 | ||
463 | // otherwise we report double clicks by connecting a left click with a ctrl-left click | |
464 | if ( clickCount > 1 && button != g_lastButton ) | |
465 | clickCount = 1 ; | |
466 | ||
467 | // we must make sure that our synthetic 'right' button corresponds in | |
468 | // mouse down, moved and mouse up, and does not deliver a right down and left up | |
469 | ||
470 | if ( cEvent.GetKind() == kEventMouseDown ) | |
471 | { | |
472 | g_lastButton = button ; | |
473 | g_lastButtonWasFakeRight = thisButtonIsFakeRight ; | |
474 | } | |
475 | ||
476 | if ( button == 0 ) | |
477 | { | |
478 | g_lastButton = 0 ; | |
479 | g_lastButtonWasFakeRight = false ; | |
480 | } | |
481 | else if ( g_lastButton == kEventMouseButtonSecondary && g_lastButtonWasFakeRight ) | |
482 | button = g_lastButton ; | |
483 | ||
484 | // Adjust the chord mask to remove the primary button and add the | |
485 | // secondary button. It is possible that the secondary button is | |
486 | // already pressed, e.g. on a mouse connected to a laptop, but this | |
487 | // possibility is ignored here: | |
488 | if( thisButtonIsFakeRight && ( mouseChord & 1U ) ) | |
489 | mouseChord = ((mouseChord & ~1U) | 2U); | |
490 | ||
491 | if(mouseChord & 1U) | |
492 | wxevent.m_leftDown = true ; | |
493 | if(mouseChord & 2U) | |
494 | wxevent.m_rightDown = true ; | |
495 | if(mouseChord & 4U) | |
496 | wxevent.m_middleDown = true ; | |
497 | ||
498 | // translate into wx types | |
499 | switch ( cEvent.GetKind() ) | |
500 | { | |
501 | case kEventMouseDown : | |
502 | switch ( button ) | |
503 | { | |
504 | case kEventMouseButtonPrimary : | |
505 | wxevent.SetEventType( clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ; | |
506 | break ; | |
507 | ||
508 | case kEventMouseButtonSecondary : | |
509 | wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ; | |
510 | break ; | |
511 | ||
512 | case kEventMouseButtonTertiary : | |
513 | wxevent.SetEventType( clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ; | |
514 | break ; | |
515 | ||
516 | default: | |
517 | break ; | |
518 | } | |
519 | break ; | |
520 | ||
521 | case kEventMouseUp : | |
522 | switch ( button ) | |
523 | { | |
524 | case kEventMouseButtonPrimary : | |
525 | wxevent.SetEventType( wxEVT_LEFT_UP ) ; | |
526 | break ; | |
527 | ||
528 | case kEventMouseButtonSecondary : | |
529 | wxevent.SetEventType( wxEVT_RIGHT_UP ) ; | |
530 | break ; | |
531 | ||
532 | case kEventMouseButtonTertiary : | |
533 | wxevent.SetEventType( wxEVT_MIDDLE_UP ) ; | |
534 | break ; | |
535 | ||
536 | default: | |
537 | break ; | |
538 | } | |
539 | break ; | |
540 | ||
541 | case kEventMouseWheelMoved : | |
542 | { | |
543 | wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ; | |
544 | ||
545 | EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ; | |
546 | SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeSInt32) ; | |
547 | ||
548 | wxevent.m_wheelRotation = delta; | |
549 | wxevent.m_wheelDelta = 1; | |
550 | wxevent.m_linesPerAction = 1; | |
551 | if ( axis == kEventMouseWheelAxisX ) | |
552 | wxevent.m_wheelAxis = 1; | |
553 | } | |
554 | break ; | |
555 | ||
556 | case kEventMouseEntered : | |
557 | case kEventMouseExited : | |
558 | case kEventMouseDragged : | |
559 | case kEventMouseMoved : | |
560 | wxevent.SetEventType( wxEVT_MOTION ) ; | |
561 | break; | |
562 | default : | |
563 | break ; | |
564 | } | |
565 | } | |
566 | ||
567 | #define NEW_CAPTURE_HANDLING 1 | |
568 | ||
569 | pascal OSStatus | |
570 | wxMacTopLevelMouseEventHandler(EventHandlerCallRef WXUNUSED(handler), | |
571 | EventRef event, | |
572 | void *data) | |
573 | { | |
b2680ced | 574 | wxNonOwnedWindow* toplevelWindow = data ? ((wxNonOwnedWindowImpl*) data)->GetWXPeer() : NULL ; |
489468fe SC |
575 | |
576 | OSStatus result = eventNotHandledErr ; | |
577 | ||
578 | wxMacCarbonEvent cEvent( event ) ; | |
579 | ||
580 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; | |
581 | Point windowMouseLocation = screenMouseLocation ; | |
582 | ||
583 | WindowRef window = NULL; | |
584 | short windowPart = ::FindWindow(screenMouseLocation, &window); | |
585 | ||
586 | wxWindow* currentMouseWindow = NULL ; | |
587 | ControlRef control = NULL ; | |
588 | ||
589 | #if NEW_CAPTURE_HANDLING | |
590 | if ( wxApp::s_captureWindow ) | |
591 | { | |
592 | window = (WindowRef) wxApp::s_captureWindow->MacGetTopLevelWindowRef() ; | |
593 | windowPart = inContent ; | |
594 | } | |
595 | #endif | |
596 | ||
597 | if ( window ) | |
598 | { | |
b2680ced | 599 | QDGlobalToLocalPoint( GetWindowPort( window ), &windowMouseLocation ); |
489468fe SC |
600 | |
601 | if ( wxApp::s_captureWindow | |
602 | #if !NEW_CAPTURE_HANDLING | |
603 | && wxApp::s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent | |
604 | #endif | |
605 | ) | |
606 | { | |
607 | currentMouseWindow = wxApp::s_captureWindow ; | |
608 | } | |
609 | else if ( (IsWindowActive(window) && windowPart == inContent) ) | |
610 | { | |
611 | ControlPartCode part ; | |
612 | control = FindControlUnderMouse( windowMouseLocation , window , &part ) ; | |
613 | // if there is no control below the mouse position, send the event to the toplevel window itself | |
614 | if ( control == 0 ) | |
615 | { | |
b2680ced | 616 | currentMouseWindow = (wxWindow*) toplevelWindow ; |
489468fe SC |
617 | } |
618 | else | |
619 | { | |
b2680ced | 620 | currentMouseWindow = (wxWindow*) wxFindWindowFromWXWidget( (WXWidget) control ) ; |
489468fe SC |
621 | #ifndef __WXUNIVERSAL__ |
622 | if ( currentMouseWindow == NULL && cEvent.GetKind() == kEventMouseMoved ) | |
623 | { | |
624 | #if wxUSE_TOOLBAR | |
625 | // for wxToolBar to function we have to send certaint events to it | |
626 | // instead of its children (wxToolBarTools) | |
627 | ControlRef parent ; | |
628 | GetSuperControl(control, &parent ); | |
f742eaaf RR |
629 | wxWindow *wxparent = (wxWindow*) wxFindWindowFromWXWidget((WXWidget) parent ) ; |
630 | if ( wxparent && wxparent->IsKindOf( CLASSINFO( wxToolBar ) ) ) | |
631 | currentMouseWindow = wxparent ; | |
489468fe SC |
632 | #endif |
633 | } | |
634 | #endif | |
635 | } | |
636 | ||
637 | // disabled windows must not get any input messages | |
638 | if ( currentMouseWindow && !currentMouseWindow->MacIsReallyEnabled() ) | |
639 | currentMouseWindow = NULL; | |
640 | } | |
641 | } | |
642 | ||
643 | wxMouseEvent wxevent(wxEVT_LEFT_DOWN); | |
644 | SetupMouseEvent( wxevent , cEvent ) ; | |
645 | ||
646 | // handle all enter / leave events | |
647 | ||
648 | if ( currentMouseWindow != g_MacLastWindow ) | |
649 | { | |
650 | if ( g_MacLastWindow ) | |
651 | { | |
652 | wxMouseEvent eventleave(wxevent); | |
653 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
654 | g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
655 | eventleave.SetEventObject( g_MacLastWindow ) ; | |
656 | wxevent.SetId( g_MacLastWindow->GetId() ) ; | |
657 | ||
658 | #if wxUSE_TOOLTIPS | |
659 | wxToolTip::RelayEvent( g_MacLastWindow , eventleave); | |
660 | #endif | |
661 | ||
662 | g_MacLastWindow->HandleWindowEvent(eventleave); | |
663 | } | |
664 | ||
665 | if ( currentMouseWindow ) | |
666 | { | |
667 | wxMouseEvent evententer(wxevent); | |
668 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
669 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
670 | evententer.SetEventObject( currentMouseWindow ) ; | |
671 | wxevent.SetId( currentMouseWindow->GetId() ) ; | |
672 | ||
673 | #if wxUSE_TOOLTIPS | |
674 | wxToolTip::RelayEvent( currentMouseWindow , evententer ); | |
675 | #endif | |
676 | ||
677 | currentMouseWindow->HandleWindowEvent(evententer); | |
678 | } | |
679 | ||
680 | g_MacLastWindow = currentMouseWindow ; | |
681 | } | |
682 | ||
683 | if ( windowPart == inMenuBar ) | |
684 | { | |
685 | // special case menu bar, as we are having a low-level runloop we must do it ourselves | |
686 | if ( cEvent.GetKind() == kEventMouseDown ) | |
687 | { | |
688 | ::MenuSelect( screenMouseLocation ) ; | |
689 | ::HiliteMenu(0); | |
690 | result = noErr ; | |
691 | } | |
03647350 | 692 | } |
524c47aa SC |
693 | else if ( window && windowPart == inProxyIcon ) |
694 | { | |
695 | // special case proxy icon bar, as we are having a low-level runloop we must do it ourselves | |
696 | if ( cEvent.GetKind() == kEventMouseDown ) | |
697 | { | |
698 | if ( ::TrackWindowProxyDrag( window, screenMouseLocation ) != errUserWantsToDragWindow ) | |
699 | { | |
700 | // TODO Track change of file path and report back | |
701 | result = noErr ; | |
702 | } | |
703 | } | |
489468fe SC |
704 | } |
705 | else if ( currentMouseWindow ) | |
706 | { | |
707 | wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent(); | |
708 | ||
709 | currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ; | |
710 | ||
711 | wxevent.SetEventObject( currentMouseWindow ) ; | |
712 | wxevent.SetId( currentMouseWindow->GetId() ) ; | |
713 | ||
714 | // make tooltips current | |
715 | ||
716 | #if wxUSE_TOOLTIPS | |
717 | if ( wxevent.GetEventType() == wxEVT_MOTION ) | |
718 | wxToolTip::RelayEvent( currentMouseWindow , wxevent ); | |
719 | #endif | |
720 | ||
721 | if ( currentMouseWindow->HandleWindowEvent(wxevent) ) | |
722 | { | |
723 | if ((currentMouseWindowParent != NULL) && | |
724 | (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL)) | |
725 | currentMouseWindow = NULL; | |
726 | ||
727 | result = noErr; | |
728 | } | |
729 | else | |
730 | { | |
731 | // if the user code did _not_ handle the event, then perform the | |
732 | // default processing | |
733 | if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN ) | |
734 | { | |
735 | // ... that is set focus to this window | |
736 | if (currentMouseWindow->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow) | |
737 | currentMouseWindow->SetFocus(); | |
738 | } | |
739 | } | |
740 | ||
741 | if ( cEvent.GetKind() == kEventMouseUp && wxApp::s_captureWindow ) | |
742 | { | |
743 | wxApp::s_captureWindow = NULL ; | |
744 | // update cursor ? | |
745 | } | |
746 | ||
747 | // update cursor | |
748 | ||
749 | wxWindow* cursorTarget = currentMouseWindow ; | |
750 | wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ; | |
03647350 | 751 | |
489468fe SC |
752 | extern wxCursor gGlobalCursor; |
753 | ||
754 | if (!gGlobalCursor.IsOk()) | |
755 | { | |
756 | while ( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) ) | |
757 | { | |
758 | cursorTarget = cursorTarget->GetParent() ; | |
759 | if ( cursorTarget ) | |
760 | cursorPoint += cursorTarget->GetPosition(); | |
761 | } | |
762 | } | |
763 | ||
764 | } | |
765 | else // currentMouseWindow == NULL | |
766 | { | |
f742eaaf RR |
767 | if (toplevelWindow && !control) |
768 | { | |
769 | extern wxCursor gGlobalCursor; | |
770 | if (!gGlobalCursor.IsOk()) | |
771 | { | |
772 | // update cursor when over toolbar and titlebar etc. | |
fc1e45d9 | 773 | wxSTANDARD_CURSOR->MacInstall() ; |
f742eaaf RR |
774 | } |
775 | } | |
03647350 | 776 | |
489468fe SC |
777 | // don't mess with controls we don't know about |
778 | // for some reason returning eventNotHandledErr does not lead to the correct behaviour | |
779 | // so we try sending them the correct control directly | |
780 | if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control ) | |
781 | { | |
782 | EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ; | |
783 | Point clickLocation = windowMouseLocation ; | |
784 | ||
785 | HIPoint hiPoint ; | |
786 | hiPoint.x = clickLocation.h ; | |
787 | hiPoint.y = clickLocation.v ; | |
788 | HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ; | |
789 | clickLocation.h = (int)hiPoint.x ; | |
790 | clickLocation.v = (int)hiPoint.y ; | |
791 | ||
792 | HandleControlClick( control , clickLocation , modifiers , (ControlActionUPP ) -1 ) ; | |
793 | result = noErr ; | |
794 | } | |
795 | } | |
796 | ||
797 | return result ; | |
798 | } | |
799 | ||
800 | static pascal OSStatus | |
801 | wxNonOwnedWindowEventHandler(EventHandlerCallRef WXUNUSED(handler), | |
802 | EventRef event, | |
803 | void *data) | |
804 | { | |
805 | OSStatus result = eventNotHandledErr ; | |
806 | ||
807 | wxMacCarbonEvent cEvent( event ) ; | |
808 | ||
809 | // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ; | |
b2680ced | 810 | wxNonOwnedWindow* toplevelWindow = data ? ((wxNonOwnedWindowImpl*) data)->GetWXPeer() : NULL; |
489468fe SC |
811 | |
812 | switch ( GetEventKind( event ) ) | |
813 | { | |
814 | case kEventWindowActivated : | |
815 | { | |
524c47aa | 816 | toplevelWindow->HandleActivated( cEvent.GetTicks() , true) ; |
489468fe SC |
817 | // we still sending an eventNotHandledErr in order to allow for default processing |
818 | } | |
819 | break ; | |
820 | ||
821 | case kEventWindowDeactivated : | |
822 | { | |
524c47aa | 823 | toplevelWindow->HandleActivated( cEvent.GetTicks() , false) ; |
489468fe SC |
824 | // we still sending an eventNotHandledErr in order to allow for default processing |
825 | } | |
826 | break ; | |
827 | ||
828 | case kEventWindowShown : | |
829 | toplevelWindow->Refresh() ; | |
830 | result = noErr ; | |
831 | break ; | |
832 | ||
833 | case kEventWindowClose : | |
834 | toplevelWindow->Close() ; | |
835 | result = noErr ; | |
836 | break ; | |
837 | ||
838 | case kEventWindowBoundsChanged : | |
839 | { | |
840 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes, typeUInt32) ; | |
841 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
842 | wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ; | |
843 | if ( attributes & kWindowBoundsChangeSizeChanged ) | |
844 | { | |
524c47aa | 845 | toplevelWindow->HandleResized(cEvent.GetTicks() ) ; |
489468fe SC |
846 | } |
847 | ||
848 | if ( attributes & kWindowBoundsChangeOriginChanged ) | |
849 | { | |
524c47aa | 850 | toplevelWindow->HandleMoved(cEvent.GetTicks() ) ; |
489468fe SC |
851 | } |
852 | ||
853 | result = noErr ; | |
854 | } | |
855 | break ; | |
856 | ||
857 | case kEventWindowBoundsChanging : | |
858 | { | |
859 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
860 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
861 | ||
862 | if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) ) | |
863 | { | |
864 | // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates | |
f71d8b3d SC |
865 | int left , top , width , height ; |
866 | // structure width | |
867 | int swidth, sheight; | |
868 | ||
869 | toplevelWindow->GetNonOwnedPeer()->GetContentArea(left, top, width, height); | |
870 | toplevelWindow->GetNonOwnedPeer()->GetSize(swidth, sheight); | |
871 | int deltawidth = swidth - width; | |
872 | int deltaheight = sheight - height; | |
524c47aa | 873 | wxRect adjustR( |
489468fe SC |
874 | newRect.left - left, |
875 | newRect.top - top, | |
f71d8b3d SC |
876 | newRect.right - newRect.left + deltawidth, |
877 | newRect.bottom - newRect.top + deltaheight ) ; | |
489468fe | 878 | |
524c47aa | 879 | toplevelWindow->HandleResizing( cEvent.GetTicks(), &adjustR ); |
03647350 VZ |
880 | |
881 | const Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + top + adjustR.height - deltaheight , | |
f71d8b3d | 882 | adjustR.x + left + adjustR.width - deltawidth } ; |
489468fe SC |
883 | if ( !EqualRect( &newRect , &adjustedRect ) ) |
884 | cEvent.SetParameter<Rect>( kEventParamCurrentBounds , &adjustedRect ) ; | |
489468fe SC |
885 | } |
886 | ||
887 | result = noErr ; | |
888 | } | |
889 | break ; | |
890 | ||
891 | case kEventWindowGetRegion : | |
892 | { | |
893 | if ( toplevelWindow->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) | |
894 | { | |
895 | WindowRegionCode windowRegionCode ; | |
896 | ||
897 | // Fetch the region code that is being queried | |
898 | GetEventParameter( event, | |
899 | kEventParamWindowRegionCode, | |
900 | typeWindowRegionCode, NULL, | |
901 | sizeof windowRegionCode, NULL, | |
902 | &windowRegionCode ) ; | |
903 | ||
904 | // If it is the opaque region code then set the | |
905 | // region to empty and return noErr to stop event | |
906 | // propagation | |
907 | if ( windowRegionCode == kWindowOpaqueRgn ) { | |
908 | RgnHandle region; | |
909 | GetEventParameter( event, | |
910 | kEventParamRgnHandle, | |
911 | typeQDRgnHandle, NULL, | |
912 | sizeof region, NULL, | |
913 | ®ion) ; | |
914 | SetEmptyRgn(region) ; | |
915 | result = noErr ; | |
916 | } | |
917 | } | |
918 | } | |
919 | break ; | |
920 | ||
921 | default : | |
922 | break ; | |
923 | } | |
924 | ||
925 | return result ; | |
926 | } | |
927 | ||
928 | // mix this in from window.cpp | |
929 | pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ; | |
930 | ||
931 | pascal OSStatus wxNonOwnedEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
932 | { | |
933 | OSStatus result = eventNotHandledErr ; | |
934 | ||
935 | switch ( GetEventClass( event ) ) | |
936 | { | |
937 | case kEventClassTextInput : | |
524c47aa SC |
938 | { |
939 | // TODO remove as soon as all events are on implementation classes only | |
940 | wxNonOwnedWindow* toplevelWindow = data ? ((wxNonOwnedWindowImpl*) data)->GetWXPeer() : NULL; | |
941 | ||
942 | result = wxMacUnicodeTextEventHandler( handler, event , toplevelWindow ) ; | |
943 | } | |
489468fe SC |
944 | break ; |
945 | ||
946 | case kEventClassKeyboard : | |
947 | result = KeyboardEventHandler( handler, event , data ) ; | |
948 | break ; | |
949 | ||
950 | case kEventClassWindow : | |
951 | result = wxNonOwnedWindowEventHandler( handler, event , data ) ; | |
952 | break ; | |
953 | ||
954 | case kEventClassMouse : | |
955 | result = wxMacTopLevelMouseEventHandler( handler, event , data ) ; | |
956 | break ; | |
957 | ||
958 | default : | |
959 | break ; | |
960 | } | |
961 | ||
962 | return result ; | |
963 | } | |
964 | ||
965 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxNonOwnedEventHandler ) | |
966 | ||
967 | // --------------------------------------------------------------------------- | |
b2680ced SC |
968 | // Support functions for shaped windows, based on Apple's CustomWindow sample at |
969 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
489468fe SC |
970 | // --------------------------------------------------------------------------- |
971 | ||
b2680ced SC |
972 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) |
973 | { | |
974 | GetWindowPortBounds(window, inRect); | |
975 | Point pt = { inRect->top ,inRect->left }; | |
976 | QDLocalToGlobalPoint( GetWindowPort( window ), &pt ); | |
977 | inRect->bottom += pt.v - inRect->top; | |
978 | inRect->right += pt.h - inRect->left; | |
979 | inRect->top = pt.v; | |
980 | inRect->left = pt.h; | |
981 | } | |
489468fe | 982 | |
b2680ced SC |
983 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef WXUNUSED(window), SInt32 param) |
984 | { | |
985 | /*------------------------------------------------------ | |
986 | Define which options your custom window supports. | |
987 | --------------------------------------------------------*/ | |
988 | //just enable everything for our demo | |
989 | *(OptionBits*)param = | |
990 | //kWindowCanGrow | | |
991 | //kWindowCanZoom | | |
992 | kWindowCanCollapse | | |
993 | //kWindowCanGetWindowRegion | | |
994 | //kWindowHasTitleBar | | |
995 | //kWindowSupportsDragHilite | | |
996 | kWindowCanDrawInCurrentPort | | |
997 | //kWindowCanMeasureTitle | | |
998 | kWindowWantsDisposeAtProcessDeath | | |
999 | kWindowSupportsGetGrowImageRegion | | |
1000 | kWindowDefSupportsColorGrafPort; | |
489468fe | 1001 | |
b2680ced SC |
1002 | return 1; |
1003 | } | |
489468fe | 1004 | |
b2680ced SC |
1005 | // The content region is left as a rectangle matching the window size, this is |
1006 | // so the origin in the paint event, and etc. still matches what the | |
1007 | // programmer expects. | |
1008 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
489468fe | 1009 | { |
b2680ced SC |
1010 | SetEmptyRgn(rgn); |
1011 | wxNonOwnedWindow* win = wxNonOwnedWindow::GetFromWXWindow((WXWindow)window); | |
1012 | if (win) | |
1013 | { | |
1014 | Rect r ; | |
1015 | wxShapedMacWindowGetPos( window, &r ) ; | |
1016 | RectRgn( rgn , &r ) ; | |
1017 | } | |
489468fe SC |
1018 | } |
1019 | ||
b2680ced SC |
1020 | // The structure region is set to the shape given to the SetShape method. |
1021 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
489468fe | 1022 | { |
b2680ced | 1023 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); |
489468fe | 1024 | |
b2680ced SC |
1025 | SetEmptyRgn(rgn); |
1026 | if (cachedRegion) | |
1027 | { | |
1028 | Rect windowRect; | |
1029 | wxShapedMacWindowGetPos(window, &windowRect); // how big is the window | |
1030 | CopyRgn(cachedRegion, rgn); // make a copy of our cached region | |
1031 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window | |
1032 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size | |
1033 | } | |
489468fe SC |
1034 | } |
1035 | ||
b2680ced | 1036 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) |
489468fe | 1037 | { |
b2680ced SC |
1038 | GetWindowRegionPtr rgnRec = (GetWindowRegionPtr)param; |
1039 | ||
1040 | if (rgnRec == NULL) | |
1041 | return paramErr; | |
1042 | ||
1043 | switch (rgnRec->regionCode) | |
489468fe | 1044 | { |
b2680ced SC |
1045 | case kWindowStructureRgn: |
1046 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
489468fe | 1047 | break; |
489468fe | 1048 | |
b2680ced SC |
1049 | case kWindowContentRgn: |
1050 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1051 | break; | |
489468fe | 1052 | |
b2680ced SC |
1053 | default: |
1054 | SetEmptyRgn(rgnRec->winRgn); | |
1055 | break; | |
1056 | } | |
489468fe | 1057 | |
b2680ced | 1058 | return noErr; |
489468fe SC |
1059 | } |
1060 | ||
b2680ced SC |
1061 | // Determine the region of the window which was hit |
1062 | // | |
1063 | static SInt32 wxShapedMacWindowHitTest(WindowRef window, SInt32 param) | |
489468fe | 1064 | { |
b2680ced SC |
1065 | Point hitPoint; |
1066 | static RgnHandle tempRgn = NULL; | |
489468fe | 1067 | |
b2680ced SC |
1068 | if (tempRgn == NULL) |
1069 | tempRgn = NewRgn(); | |
1070 | ||
1071 | // get the point clicked | |
1072 | SetPt( &hitPoint, LoWord(param), HiWord(param) ); | |
1073 | ||
1074 | // Mac OS 8.5 or later | |
1075 | wxShapedMacWindowStructureRegion(window, tempRgn); | |
1076 | if (PtInRgn( hitPoint, tempRgn )) //in window content region? | |
1077 | return wInContent; | |
1078 | ||
1079 | // no significant area was hit | |
1080 | return wNoHit; | |
489468fe SC |
1081 | } |
1082 | ||
b2680ced | 1083 | static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode), WindowRef window, SInt16 message, SInt32 param) |
489468fe | 1084 | { |
b2680ced SC |
1085 | switch (message) |
1086 | { | |
1087 | case kWindowMsgHitTest: | |
1088 | return wxShapedMacWindowHitTest(window, param); | |
489468fe | 1089 | |
b2680ced SC |
1090 | case kWindowMsgGetFeatures: |
1091 | return wxShapedMacWindowGetFeatures(window, param); | |
489468fe | 1092 | |
b2680ced SC |
1093 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow |
1094 | case kWindowMsgGetRegion: | |
1095 | return wxShapedMacWindowGetRegion(window, param); | |
489468fe | 1096 | |
b2680ced SC |
1097 | default: |
1098 | break; | |
1099 | } | |
489468fe | 1100 | |
b2680ced SC |
1101 | return 0; |
1102 | } | |
489468fe | 1103 | |
b2680ced | 1104 | // implementation |
489468fe | 1105 | |
b2680ced SC |
1106 | typedef struct |
1107 | { | |
1108 | wxPoint m_position ; | |
1109 | wxSize m_size ; | |
1110 | bool m_wasResizable ; | |
1111 | } FullScreenData ; | |
489468fe | 1112 | |
b2680ced SC |
1113 | wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl() |
1114 | { | |
1115 | } | |
489468fe | 1116 | |
b2680ced SC |
1117 | wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow* nonownedwnd) : wxNonOwnedWindowImpl( nonownedwnd) |
1118 | { | |
1119 | m_macEventHandler = NULL; | |
1120 | m_macWindow = NULL; | |
1121 | m_macFullScreenData = NULL ; | |
489468fe SC |
1122 | } |
1123 | ||
b2680ced | 1124 | wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl() |
489468fe | 1125 | { |
489468fe SC |
1126 | #if wxUSE_TOOLTIPS |
1127 | wxToolTip::NotifyWindowDelete(m_macWindow) ; | |
1128 | #endif | |
489468fe SC |
1129 | |
1130 | if ( m_macEventHandler ) | |
1131 | { | |
1132 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
1133 | m_macEventHandler = NULL ; | |
1134 | } | |
1135 | ||
b2680ced SC |
1136 | if ( m_macWindow ) |
1137 | DisposeWindow( m_macWindow ); | |
489468fe | 1138 | |
b2680ced SC |
1139 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; |
1140 | delete data ; | |
1141 | m_macFullScreenData = NULL ; | |
1142 | ||
1143 | m_macWindow = NULL; | |
1144 | ||
1145 | } | |
1146 | ||
0aaa6ace | 1147 | void wxNonOwnedWindowCarbonImpl::WillBeDestroyed() |
03647350 | 1148 | { |
524c47aa SC |
1149 | if ( m_macEventHandler ) |
1150 | { | |
1151 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
1152 | m_macEventHandler = NULL ; | |
1153 | } | |
b2680ced | 1154 | } |
489468fe SC |
1155 | |
1156 | void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window, EventHandlerRef* handler, void *ref) | |
1157 | { | |
1158 | InstallWindowEventHandler(window, GetwxNonOwnedEventHandlerUPP(), | |
1159 | GetEventTypeCount(eventList), eventList, ref, handler ); | |
1160 | } | |
1161 | ||
b2680ced SC |
1162 | bool wxNonOwnedWindowCarbonImpl::SetShape(const wxRegion& region) |
1163 | { | |
1164 | // Make a copy of the region | |
1165 | RgnHandle shapeRegion = NewRgn(); | |
1166 | HIShapeGetAsQDRgn( region.GetWXHRGN(), shapeRegion ); | |
1167 | ||
1168 | // Dispose of any shape region we may already have | |
1169 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef) m_wxPeer->GetWXWindow() ); | |
1170 | if ( oldRgn ) | |
1171 | DisposeRgn(oldRgn); | |
1172 | ||
1173 | // Save the region so we can use it later | |
1174 | SetWRefCon((WindowRef) m_wxPeer->GetWXWindow(), (URefCon)shapeRegion); | |
1175 | ||
1176 | // inform the window manager that the window has changed shape | |
1177 | ReshapeCustomWindow((WindowRef) m_wxPeer->GetWXWindow()); | |
1178 | ||
1179 | return true; | |
1180 | } | |
1181 | ||
1182 | ||
1183 | void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler() | |
489468fe SC |
1184 | { |
1185 | if ( m_macEventHandler != NULL ) | |
1186 | { | |
1187 | verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ; | |
1188 | } | |
1189 | wxNonOwnedWindowInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow),(EventHandlerRef *)&m_macEventHandler,this); | |
1190 | } | |
1191 | ||
b2680ced | 1192 | void wxNonOwnedWindowCarbonImpl::Create( |
489468fe SC |
1193 | wxWindow* parent, |
1194 | const wxPoint& pos, | |
1195 | const wxSize& size, | |
03647350 | 1196 | long style, long extraStyle, |
a4fec5b4 | 1197 | const wxString& WXUNUSED(name) ) |
489468fe | 1198 | { |
b2680ced | 1199 | |
489468fe | 1200 | OSStatus err = noErr ; |
b2680ced | 1201 | Rect theBoundsRect; |
489468fe | 1202 | |
489468fe SC |
1203 | int x = (int)pos.x; |
1204 | int y = (int)pos.y; | |
1205 | ||
b2680ced SC |
1206 | int w = size.x; |
1207 | int h = size.y; | |
489468fe SC |
1208 | |
1209 | ::SetRect(&theBoundsRect, x, y , x + w, y + h); | |
1210 | ||
1211 | // translate the window attributes in the appropriate window class and attributes | |
1212 | WindowClass wclass = 0; | |
1213 | WindowAttributes attr = kWindowNoAttributes ; | |
1214 | WindowGroupRef group = NULL ; | |
1215 | bool activationScopeSet = false; | |
1216 | WindowActivationScope activationScope = kWindowActivationScopeNone; | |
1217 | ||
b2680ced | 1218 | if ( style & wxFRAME_TOOL_WINDOW ) |
489468fe SC |
1219 | { |
1220 | if ( | |
b2680ced SC |
1221 | ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) || |
1222 | ( style & wxSYSTEM_MENU ) || ( style & wxCAPTION ) || | |
1223 | ( style &wxTINY_CAPTION_HORIZ) || ( style &wxTINY_CAPTION_VERT) | |
489468fe SC |
1224 | ) |
1225 | { | |
b2680ced | 1226 | if ( ( style & wxSTAY_ON_TOP ) ) |
489468fe SC |
1227 | wclass = kUtilityWindowClass; |
1228 | else | |
1229 | wclass = kFloatingWindowClass ; | |
1230 | ||
b2680ced | 1231 | if ( ( style &wxTINY_CAPTION_VERT) ) |
489468fe SC |
1232 | attr |= kWindowSideTitlebarAttribute ; |
1233 | } | |
1234 | else | |
1235 | { | |
8f3864f7 | 1236 | if ( style & wxNO_BORDER ) |
b12a7313 KO |
1237 | { |
1238 | wclass = kSimpleWindowClass ; | |
1239 | } | |
1240 | else | |
1241 | { | |
1242 | wclass = kPlainWindowClass ; | |
1243 | } | |
489468fe SC |
1244 | activationScopeSet = true; |
1245 | activationScope = kWindowActivationScopeNone; | |
1246 | } | |
1247 | } | |
b2680ced | 1248 | else if ( ( style & wxPOPUP_WINDOW ) ) |
489468fe | 1249 | { |
b2680ced | 1250 | if ( ( style & wxBORDER_NONE ) ) |
489468fe SC |
1251 | { |
1252 | wclass = kHelpWindowClass ; // has no border | |
1253 | attr |= kWindowNoShadowAttribute; | |
1254 | } | |
1255 | else | |
1256 | { | |
1257 | wclass = kPlainWindowClass ; // has a single line border, it will have to do for now | |
1258 | } | |
1259 | group = GetWindowGroupOfClass(kFloatingWindowClass) ; | |
1260 | // make sure we don't deactivate something | |
1261 | activationScopeSet = true; | |
1262 | activationScope = kWindowActivationScopeNone; | |
1263 | } | |
b2680ced | 1264 | else if ( ( style & wxCAPTION ) ) |
489468fe SC |
1265 | { |
1266 | wclass = kDocumentWindowClass ; | |
1267 | attr |= kWindowInWindowMenuAttribute ; | |
1268 | } | |
b2680ced | 1269 | else if ( ( style & wxFRAME_DRAWER ) ) |
489468fe SC |
1270 | { |
1271 | wclass = kDrawerWindowClass; | |
1272 | } | |
1273 | else | |
1274 | { | |
b2680ced SC |
1275 | if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) || |
1276 | ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) ) | |
489468fe SC |
1277 | { |
1278 | wclass = kDocumentWindowClass ; | |
1279 | } | |
b2680ced | 1280 | else if ( ( style & wxNO_BORDER ) ) |
489468fe SC |
1281 | { |
1282 | wclass = kSimpleWindowClass ; | |
1283 | } | |
1284 | else | |
1285 | { | |
1286 | wclass = kPlainWindowClass ; | |
1287 | } | |
1288 | } | |
1289 | ||
1290 | if ( wclass != kPlainWindowClass ) | |
1291 | { | |
b2680ced | 1292 | if ( ( style & wxMINIMIZE_BOX ) ) |
489468fe SC |
1293 | attr |= kWindowCollapseBoxAttribute ; |
1294 | ||
b2680ced | 1295 | if ( ( style & wxMAXIMIZE_BOX ) ) |
489468fe SC |
1296 | attr |= kWindowFullZoomAttribute ; |
1297 | ||
b2680ced | 1298 | if ( ( style & wxRESIZE_BORDER ) ) |
489468fe SC |
1299 | attr |= kWindowResizableAttribute ; |
1300 | ||
b2680ced | 1301 | if ( ( style & wxCLOSE_BOX) ) |
489468fe SC |
1302 | attr |= kWindowCloseBoxAttribute ; |
1303 | } | |
1304 | attr |= kWindowLiveResizeAttribute; | |
1305 | ||
b2680ced | 1306 | if ( ( style &wxSTAY_ON_TOP) ) |
489468fe SC |
1307 | group = GetWindowGroupOfClass(kUtilityWindowClass) ; |
1308 | ||
b2680ced | 1309 | if ( ( style & wxFRAME_FLOAT_ON_PARENT ) ) |
489468fe SC |
1310 | group = GetWindowGroupOfClass(kFloatingWindowClass) ; |
1311 | ||
1312 | if ( group == NULL && parent != NULL ) | |
1313 | { | |
1314 | WindowRef parenttlw = (WindowRef) parent->MacGetTopLevelWindowRef(); | |
1315 | if( parenttlw ) | |
1316 | group = GetWindowGroupParent( GetWindowGroup( parenttlw ) ); | |
1317 | } | |
1318 | ||
1319 | attr |= kWindowCompositingAttribute; | |
292e5e1f | 1320 | #if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale) |
489468fe SC |
1321 | attr |= kWindowFrameworkScaledAttribute; |
1322 | #endif | |
1323 | ||
b2680ced | 1324 | if ( ( style &wxFRAME_SHAPED) ) |
489468fe SC |
1325 | { |
1326 | WindowDefSpec customWindowDefSpec; | |
1327 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
1328 | customWindowDefSpec.u.defProc = | |
1329 | #ifdef __LP64__ | |
1330 | (WindowDefUPP) wxShapedMacWindowDef; | |
1331 | #else | |
1332 | NewWindowDefUPP(wxShapedMacWindowDef); | |
1333 | #endif | |
1334 | err = ::CreateCustomWindow( &customWindowDefSpec, wclass, | |
1335 | attr, &theBoundsRect, | |
1336 | (WindowRef*) &m_macWindow); | |
1337 | } | |
1338 | else | |
1339 | { | |
1340 | err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; | |
1341 | } | |
1342 | ||
1343 | if ( err == noErr && m_macWindow != NULL && group != NULL ) | |
1344 | SetWindowGroup( (WindowRef) m_macWindow , group ) ; | |
1345 | ||
1346 | wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); | |
1347 | ||
1348 | // setup a separate group for each window, so that overlays can be handled easily | |
1349 | ||
1350 | WindowGroupRef overlaygroup = NULL; | |
1351 | verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse, &overlaygroup )); | |
1352 | verify_noerr( SetWindowGroupParent( overlaygroup, GetWindowGroup( (WindowRef) m_macWindow ))); | |
1353 | verify_noerr( SetWindowGroup( (WindowRef) m_macWindow , overlaygroup )); | |
1354 | ||
1355 | if ( activationScopeSet ) | |
1356 | { | |
1357 | verify_noerr( SetWindowActivationScope( (WindowRef) m_macWindow , activationScope )); | |
1358 | } | |
1359 | ||
1360 | // the create commands are only for content rect, | |
1361 | // so we have to set the size again as structure bounds | |
b2680ced | 1362 | SetWindowBounds( m_macWindow , kWindowStructureRgn , &theBoundsRect ) ; |
489468fe SC |
1363 | |
1364 | // Causes the inner part of the window not to be metal | |
1365 | // if the style is used before window creation. | |
1366 | #if 0 // TARGET_API_MAC_OSX | |
1367 | if ( m_macUsesCompositing && m_macWindow != NULL ) | |
1368 | { | |
1369 | if ( GetExtraStyle() & wxFRAME_EX_METAL ) | |
1370 | MacSetMetalAppearance( true ) ; | |
1371 | } | |
1372 | #endif | |
1373 | ||
1374 | if ( m_macWindow != NULL ) | |
1375 | { | |
1376 | MacSetUnifiedAppearance( true ) ; | |
1377 | } | |
1378 | ||
1379 | HIViewRef growBoxRef = 0 ; | |
b2680ced | 1380 | err = HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef ); |
489468fe SC |
1381 | if ( err == noErr && growBoxRef != 0 ) |
1382 | HIGrowBoxViewSetTransparent( growBoxRef, true ) ; | |
1383 | ||
1384 | // the frame window event handler | |
b2680ced | 1385 | InstallStandardEventHandler( GetWindowEventTarget(m_macWindow) ) ; |
489468fe SC |
1386 | MacInstallTopLevelWindowEventHandler() ; |
1387 | ||
b2680ced SC |
1388 | if ( extraStyle & wxFRAME_EX_METAL) |
1389 | MacSetMetalAppearance(true); | |
489468fe | 1390 | |
b2680ced | 1391 | if ( ( style &wxFRAME_SHAPED) ) |
489468fe SC |
1392 | { |
1393 | // default shape matches the window size | |
1394 | wxRegion rgn( 0, 0, w, h ); | |
1395 | SetShape( rgn ); | |
1396 | } | |
489468fe SC |
1397 | } |
1398 | ||
b2680ced | 1399 | bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show, |
489468fe SC |
1400 | wxShowEffect effect, |
1401 | unsigned timeout) | |
1402 | { | |
489468fe SC |
1403 | WindowTransitionEffect transition = 0 ; |
1404 | switch( effect ) | |
1405 | { | |
1406 | case wxSHOW_EFFECT_ROLL_TO_LEFT: | |
1407 | case wxSHOW_EFFECT_ROLL_TO_RIGHT: | |
1408 | case wxSHOW_EFFECT_ROLL_TO_TOP: | |
1409 | case wxSHOW_EFFECT_ROLL_TO_BOTTOM: | |
1410 | case wxSHOW_EFFECT_SLIDE_TO_LEFT: | |
1411 | case wxSHOW_EFFECT_SLIDE_TO_RIGHT: | |
1412 | case wxSHOW_EFFECT_SLIDE_TO_TOP: | |
1413 | case wxSHOW_EFFECT_SLIDE_TO_BOTTOM: | |
1414 | transition = kWindowGenieTransitionEffect; | |
1415 | break; | |
1416 | case wxSHOW_EFFECT_BLEND: | |
1417 | transition = kWindowFadeTransitionEffect; | |
1418 | break; | |
1419 | case wxSHOW_EFFECT_EXPAND: | |
1420 | // having sheets would be fine, but this might lead to a repositioning | |
1421 | #if 0 | |
1422 | if ( GetParent() ) | |
1423 | transition = kWindowSheetTransitionEffect; | |
1424 | else | |
1425 | #endif | |
1426 | transition = kWindowZoomTransitionEffect; | |
1427 | break; | |
1428 | ||
b43914a8 VZ |
1429 | case wxSHOW_EFFECT_NONE: |
1430 | // wxNonOwnedWindow is supposed to call Show() itself in this case | |
1431 | wxFAIL_MSG( "ShowWithEffect() shouldn't be called" ); | |
1432 | return false; | |
1433 | ||
489468fe SC |
1434 | case wxSHOW_EFFECT_MAX: |
1435 | wxFAIL_MSG( "invalid effect flag" ); | |
1436 | return false; | |
1437 | } | |
1438 | ||
1439 | TransitionWindowOptions options; | |
1440 | options.version = 0; | |
1441 | options.duration = timeout / 1000.0; | |
b2680ced | 1442 | options.window = transition == kWindowSheetTransitionEffect ? (WindowRef) m_wxPeer->GetParent()->MacGetTopLevelWindowRef() :0; |
489468fe SC |
1443 | options.userData = 0; |
1444 | ||
1445 | wxSize size = wxGetDisplaySize(); | |
b2680ced SC |
1446 | Rect bounds; |
1447 | GetWindowBounds( (WindowRef)m_macWindow, kWindowStructureRgn, &bounds ); | |
1448 | CGRect hiBounds = CGRectMake( bounds.left, bounds.top, bounds.right - bounds.left, bounds.bottom - bounds.top ); | |
489468fe | 1449 | |
b2680ced SC |
1450 | switch ( effect ) |
1451 | { | |
1452 | case wxSHOW_EFFECT_ROLL_TO_RIGHT: | |
1453 | case wxSHOW_EFFECT_SLIDE_TO_RIGHT: | |
1454 | hiBounds.origin.x = 0; | |
1455 | hiBounds.size.width = 0; | |
1456 | break; | |
489468fe | 1457 | |
b2680ced SC |
1458 | case wxSHOW_EFFECT_ROLL_TO_LEFT: |
1459 | case wxSHOW_EFFECT_SLIDE_TO_LEFT: | |
1460 | hiBounds.origin.x = size.x; | |
1461 | hiBounds.size.width = 0; | |
1462 | break; | |
489468fe | 1463 | |
b2680ced SC |
1464 | case wxSHOW_EFFECT_ROLL_TO_TOP: |
1465 | case wxSHOW_EFFECT_SLIDE_TO_TOP: | |
1466 | hiBounds.origin.y = size.y; | |
1467 | hiBounds.size.height = 0; | |
1468 | break; | |
489468fe | 1469 | |
b2680ced SC |
1470 | case wxSHOW_EFFECT_ROLL_TO_BOTTOM: |
1471 | case wxSHOW_EFFECT_SLIDE_TO_BOTTOM: | |
1472 | hiBounds.origin.y = 0; | |
1473 | hiBounds.size.height = 0; | |
1474 | break; | |
489468fe | 1475 | |
b2680ced SC |
1476 | default: |
1477 | break; // direction doesn't make sense | |
1478 | } | |
489468fe | 1479 | |
b2680ced SC |
1480 | ::TransitionWindowWithOptions |
1481 | ( | |
1482 | (WindowRef)m_macWindow, | |
1483 | transition, | |
1484 | show ? kWindowShowTransitionAction : kWindowHideTransitionAction, | |
1485 | transition == kWindowGenieTransitionEffect ? &hiBounds : NULL, | |
1486 | false, | |
1487 | &options | |
1488 | ); | |
489468fe | 1489 | |
b2680ced SC |
1490 | if ( show ) |
1491 | { | |
1492 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
1493 | } | |
489468fe | 1494 | |
b2680ced | 1495 | return true; |
489468fe SC |
1496 | } |
1497 | ||
03647350 | 1498 | void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString& title, wxFontEncoding encoding ) |
489468fe | 1499 | { |
b2680ced | 1500 | SetWindowTitleWithCFString( m_macWindow , wxCFStringRef( title , encoding ) ) ; |
489468fe | 1501 | } |
03647350 | 1502 | |
b2680ced | 1503 | bool wxNonOwnedWindowCarbonImpl::IsMaximized() const |
489468fe | 1504 | { |
b2680ced | 1505 | return IsWindowInStandardState( m_macWindow , NULL , NULL ) ; |
489468fe | 1506 | } |
03647350 | 1507 | |
b2680ced | 1508 | bool wxNonOwnedWindowCarbonImpl::IsIconized() const |
489468fe | 1509 | { |
b2680ced | 1510 | return IsWindowCollapsed((WindowRef)GetWXWindow() ) ; |
489468fe | 1511 | } |
03647350 | 1512 | |
b2680ced | 1513 | void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize ) |
489468fe | 1514 | { |
b2680ced SC |
1515 | if ( IsWindowCollapsable( m_macWindow ) ) |
1516 | CollapseWindow( m_macWindow , iconize ) ; | |
489468fe | 1517 | } |
03647350 | 1518 | |
b2680ced | 1519 | void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize) |
489468fe | 1520 | { |
b2680ced SC |
1521 | Point idealSize = { 0 , 0 } ; |
1522 | if ( maximize ) | |
1523 | { | |
1524 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 | |
1525 | HIRect bounds ; | |
1526 | HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal, | |
1527 | &bounds); | |
1528 | idealSize.h = bounds.size.width; | |
1529 | idealSize.v = bounds.size.height; | |
1530 | #else | |
1531 | Rect rect ; | |
1532 | GetAvailableWindowPositioningBounds(GetMainDevice(),&rect) ; | |
1533 | idealSize.h = rect.right - rect.left ; | |
1534 | idealSize.v = rect.bottom - rect.top ; | |
1535 | #endif | |
1536 | } | |
1537 | ZoomWindowIdeal( (WindowRef)GetWXWindow() , maximize ? inZoomOut : inZoomIn , &idealSize ) ; | |
489468fe | 1538 | } |
03647350 | 1539 | |
b2680ced | 1540 | bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const |
489468fe | 1541 | { |
b2680ced | 1542 | return m_macFullScreenData != NULL ; |
489468fe | 1543 | } |
03647350 | 1544 | |
b2680ced | 1545 | bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show, long style) |
489468fe | 1546 | { |
b2680ced | 1547 | if ( show ) |
489468fe | 1548 | { |
b2680ced SC |
1549 | FullScreenData *data = (FullScreenData *)m_macFullScreenData ; |
1550 | delete data ; | |
1551 | data = new FullScreenData() ; | |
1552 | ||
1553 | m_macFullScreenData = data ; | |
1554 | data->m_position = m_wxPeer->GetPosition() ; | |
1555 | data->m_size = m_wxPeer->GetSize() ; | |
1556 | #if wxOSX_USE_CARBON | |
1557 | WindowAttributes attr = 0; | |
1558 | GetWindowAttributes((WindowRef) GetWXWindow(), &attr); | |
1559 | data->m_wasResizable = attr & kWindowResizableAttribute; | |
1560 | if ( style & wxFULLSCREEN_NOMENUBAR ) | |
1561 | HideMenuBar() ; | |
1562 | #endif | |
489468fe | 1563 | |
b2680ced | 1564 | wxRect client = wxGetClientDisplayRect() ; |
489468fe | 1565 | |
b4afc5ec | 1566 | int left, top, width, height ; |
b2680ced | 1567 | int x, y, w, h ; |
489468fe | 1568 | |
b2680ced SC |
1569 | x = client.x ; |
1570 | y = client.y ; | |
1571 | w = client.width ; | |
1572 | h = client.height ; | |
489468fe | 1573 | |
b4afc5ec SC |
1574 | GetContentArea( left, top, width, height ) ; |
1575 | int outerwidth, outerheight; | |
1576 | GetSize( outerwidth, outerheight ); | |
489468fe | 1577 | |
b2680ced SC |
1578 | if ( style & wxFULLSCREEN_NOCAPTION ) |
1579 | { | |
1580 | y -= top ; | |
1581 | h += top ; | |
b4afc5ec | 1582 | // avoid adding the caption twice to the height |
03647350 | 1583 | outerheight -= top; |
b2680ced | 1584 | } |
489468fe | 1585 | |
b2680ced SC |
1586 | if ( style & wxFULLSCREEN_NOBORDER ) |
1587 | { | |
1588 | x -= left ; | |
b4afc5ec SC |
1589 | w += outerwidth - width; |
1590 | h += outerheight - height; | |
b2680ced | 1591 | } |
489468fe | 1592 | |
b2680ced SC |
1593 | if ( style & wxFULLSCREEN_NOTOOLBAR ) |
1594 | { | |
1595 | // TODO | |
1596 | } | |
489468fe | 1597 | |
b2680ced SC |
1598 | if ( style & wxFULLSCREEN_NOSTATUSBAR ) |
1599 | { | |
1600 | // TODO | |
1601 | } | |
489468fe | 1602 | |
b2680ced SC |
1603 | m_wxPeer->SetSize( x , y , w, h ) ; |
1604 | if ( data->m_wasResizable ) | |
1605 | { | |
1606 | #if wxOSX_USE_CARBON | |
1607 | ChangeWindowAttributes( (WindowRef) GetWXWindow() , kWindowNoAttributes , kWindowResizableAttribute ) ; | |
1608 | #endif | |
1609 | } | |
1610 | } | |
1611 | else if ( m_macFullScreenData != NULL ) | |
489468fe | 1612 | { |
b2680ced SC |
1613 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; |
1614 | #if wxOSX_USE_CARBON | |
1615 | ShowMenuBar() ; | |
1616 | if ( data->m_wasResizable ) | |
1617 | ChangeWindowAttributes( (WindowRef) GetWXWindow() , kWindowResizableAttribute , kWindowNoAttributes ) ; | |
1618 | #endif | |
1619 | m_wxPeer->SetPosition( data->m_position ) ; | |
1620 | m_wxPeer->SetSize( data->m_size ) ; | |
1621 | ||
1622 | delete data ; | |
1623 | m_macFullScreenData = NULL ; | |
489468fe | 1624 | } |
b2680ced SC |
1625 | |
1626 | return true; | |
489468fe SC |
1627 | } |
1628 | ||
b2680ced SC |
1629 | // Attracts the users attention to this window if the application is |
1630 | // inactive (should be called when a background event occurs) | |
489468fe | 1631 | |
b2680ced SC |
1632 | static pascal void wxMacNMResponse( NMRecPtr ptr ) |
1633 | { | |
1634 | NMRemove( ptr ) ; | |
1635 | DisposePtr( (Ptr)ptr ) ; | |
489468fe SC |
1636 | } |
1637 | ||
b2680ced | 1638 | void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags)) |
489468fe | 1639 | { |
b2680ced | 1640 | NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ; |
489468fe | 1641 | |
b2680ced SC |
1642 | memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ; |
1643 | notificationRequest->qType = nmType ; | |
1644 | notificationRequest->nmMark = 1 ; | |
1645 | notificationRequest->nmIcon = 0 ; | |
1646 | notificationRequest->nmSound = 0 ; | |
1647 | notificationRequest->nmStr = NULL ; | |
1648 | notificationRequest->nmResp = wxMacNMResponse ; | |
489468fe | 1649 | |
b2680ced | 1650 | verify_noerr( NMInstall( notificationRequest ) ) ; |
489468fe SC |
1651 | } |
1652 | ||
b2680ced | 1653 | void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x, int *y ) |
489468fe | 1654 | { |
b2680ced SC |
1655 | HIPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) ); |
1656 | HIViewRef contentView ; | |
1657 | // TODO check toolbar offset | |
1658 | HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowContentID , &contentView) ; | |
1659 | HIPointConvert( &p, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceView, contentView ); | |
1660 | if ( x ) | |
8f2a8de6 | 1661 | *x = (int)p.x; |
b2680ced | 1662 | if ( y ) |
8f2a8de6 | 1663 | *y = (int)p.y; |
489468fe SC |
1664 | } |
1665 | ||
b2680ced | 1666 | void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x, int *y ) |
489468fe | 1667 | { |
b2680ced SC |
1668 | HIPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) ); |
1669 | HIViewRef contentView ; | |
1670 | // TODO check toolbar offset | |
1671 | HIViewFindByID( HIViewGetRoot( m_macWindow ), kHIViewWindowContentID , &contentView) ; | |
1672 | HIPointConvert( &p, kHICoordSpaceView, contentView, kHICoordSpace72DPIGlobal, NULL ); | |
1673 | if ( x ) | |
8f2a8de6 | 1674 | *x = (int)p.x; |
b2680ced | 1675 | if ( y ) |
8f2a8de6 | 1676 | *y = (int)p.y; |
489468fe | 1677 | } |
524c47aa | 1678 | |
dbc7ceb9 KO |
1679 | bool wxNonOwnedWindowCarbonImpl::IsActive() |
1680 | { | |
1681 | return ActiveNonFloatingWindow() == m_macWindow; | |
1682 | } | |
1683 | ||
524c47aa SC |
1684 | wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size, |
1685 | long style, long extraStyle, const wxString& name ) | |
1686 | { | |
1687 | wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCarbonImpl( wxpeer ); | |
1688 | now->Create( parent, pos, size, style , extraStyle, name ); | |
1689 | return now; | |
1690 | } |