]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/mac/carbon/uma.cpp | |
3 | // Purpose: UMA support | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: The wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #if wxUSE_GUI | |
15 | ||
16 | #include "wx/toplevel.h" | |
17 | #include "wx/dc.h" | |
18 | ||
19 | #ifndef __DARWIN__ | |
20 | # include <MacTextEditor.h> | |
21 | # include <Navigation.h> | |
22 | # if defined(TARGET_CARBON) | |
23 | # if PM_USE_SESSION_APIS | |
24 | # include <PMCore.h> | |
25 | # endif | |
26 | # include <PMApplication.h> | |
27 | # else | |
28 | # include <Printing.h> | |
29 | # endif | |
30 | #endif | |
31 | ||
32 | #ifndef __DARWIN__ | |
33 | # include <Scrap.h> | |
34 | #endif | |
35 | ||
36 | #include "wx/mac/uma.h" | |
37 | ||
38 | // since we have decided that we only support 8.6 upwards we are | |
39 | // checking for these minimum requirements in the startup code of | |
40 | // the application so all wxWidgets code can safely assume that appearance 1.1 | |
41 | // windows manager, control manager, navigation services etc. are | |
42 | // present | |
43 | ||
44 | static SInt32 sUMASystemVersion = 0 ; | |
45 | ||
46 | long UMAGetSystemVersion() { return sUMASystemVersion ; } | |
47 | ||
48 | void UMACleanupToolbox() | |
49 | { | |
50 | } | |
51 | ||
52 | void UMAInitToolbox( UInt16 inMoreMastersCalls, bool isEmbedded ) | |
53 | { | |
54 | ::InitCursor(); | |
55 | ||
56 | if ( Gestalt(gestaltSystemVersion, &sUMASystemVersion) != noErr) | |
57 | sUMASystemVersion = 0x0000 ; | |
58 | ||
59 | #ifndef __LP64__ | |
60 | { | |
61 | FontFamilyID fontId ; | |
62 | Str255 fontName ; | |
63 | SInt16 fontSize ; | |
64 | Style fontStyle ; | |
65 | ||
66 | GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; | |
67 | GetFNum( fontName, &fontId ); | |
68 | ||
69 | TXNMacOSPreferredFontDescription fontDescriptions[] = | |
70 | { | |
71 | { fontId , (fontSize << 16) , kTXNDefaultFontStyle, kTXNSystemDefaultEncoding } | |
72 | } ; | |
73 | int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ; | |
74 | ||
75 | OptionBits options = 0 ; | |
76 | ||
77 | if ( UMAGetSystemVersion() < 0x1000 ) | |
78 | options |= kTXNAlwaysUseQuickDrawTextMask ; | |
79 | ||
80 | TXNInitTextension( fontDescriptions, noOfFontDescriptions, options ); | |
81 | } | |
82 | #endif | |
83 | ||
84 | UMASetSystemIsInitialized( true ); | |
85 | } | |
86 | ||
87 | // process manager | |
88 | long UMAGetProcessMode() | |
89 | { | |
90 | OSErr err ; | |
91 | ProcessInfoRec processinfo; | |
92 | ProcessSerialNumber procno ; | |
93 | ||
94 | procno.highLongOfPSN = 0 ; | |
95 | procno.lowLongOfPSN = kCurrentProcess ; | |
96 | processinfo.processInfoLength = sizeof(ProcessInfoRec); | |
97 | processinfo.processName = NULL; | |
98 | #ifndef __LP64__ | |
99 | processinfo.processAppSpec = NULL; | |
100 | #endif | |
101 | ||
102 | err = ::GetProcessInformation( &procno , &processinfo ) ; | |
103 | wxASSERT( err == noErr ) ; | |
104 | ||
105 | return processinfo.processMode ; | |
106 | } | |
107 | ||
108 | bool UMAGetProcessModeDoesActivateOnFGSwitch() | |
109 | { | |
110 | return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ; | |
111 | } | |
112 | ||
113 | // menu manager | |
114 | ||
115 | MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding ) | |
116 | { | |
117 | wxString str = wxStripMenuCodes( title ) ; | |
118 | MenuRef menu ; | |
119 | ||
120 | #if TARGET_CARBON | |
121 | CreateNewMenu( id , 0 , &menu ) ; | |
122 | SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding ) ) ; | |
123 | #else | |
124 | Str255 ptitle ; | |
125 | wxMacStringToPascal( str , ptitle ) ; | |
126 | menu = ::NewMenu( id , ptitle ) ; | |
127 | #endif | |
128 | ||
129 | return menu ; | |
130 | } | |
131 | ||
132 | void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding ) | |
133 | { | |
134 | wxString str = wxStripMenuCodes( title ) ; | |
135 | ||
136 | #if TARGET_CARBON | |
137 | SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding) ) ; | |
138 | ||
139 | #else | |
140 | Str255 ptitle ; | |
141 | wxMacStringToPascal( str , ptitle ) ; | |
142 | SetMenuTitle( menu , ptitle ) ; | |
143 | #endif | |
144 | } | |
145 | ||
146 | void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title, wxFontEncoding encoding ) | |
147 | { | |
148 | // we don't strip the accels here anymore, must be done before | |
149 | wxString str = title ; | |
150 | ||
151 | #if TARGET_CARBON | |
152 | SetMenuItemTextWithCFString( menu , item , wxMacCFStringHolder(str , encoding) ) ; | |
153 | ||
154 | #else | |
155 | Str255 ptitle ; | |
156 | wxMacStringToPascal( str , ptitle ) ; | |
157 | SetMenuItemText( menu , item , ptitle ) ; | |
158 | #endif | |
159 | } | |
160 | ||
161 | UInt32 UMAMenuEvent( EventRecord *inEvent ) | |
162 | { | |
163 | return MenuEvent( inEvent ) ; | |
164 | } | |
165 | ||
166 | void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable) | |
167 | { | |
168 | if ( enable ) | |
169 | EnableMenuItem( inMenu , inItem ) ; | |
170 | else | |
171 | DisableMenuItem( inMenu , inItem ) ; | |
172 | } | |
173 | ||
174 | void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , SInt16 id ) | |
175 | { | |
176 | AppendMenuItemTextWithCFString( menu, | |
177 | CFSTR("A"), 0, 0,NULL); | |
178 | UMASetMenuItemText( menu, (SInt16) ::CountMenuItems(menu), title , encoding ); | |
179 | SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ; | |
180 | } | |
181 | ||
182 | void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id ) | |
183 | { | |
184 | InsertMenuItemTextWithCFString( menu, | |
185 | CFSTR("A"), item, 0, 0); | |
186 | ||
187 | UMASetMenuItemText( menu, item+1, title , encoding ); | |
188 | SetMenuItemHierarchicalID( menu , item+1 , id ) ; | |
189 | } | |
190 | ||
191 | void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry ) | |
192 | { | |
193 | if ( !entry ) | |
194 | return ; | |
195 | ||
196 | UInt8 modifiers = 0 ; | |
197 | SInt16 key = entry->GetKeyCode() ; | |
198 | if ( key ) | |
199 | { | |
200 | bool explicitCommandKey = (entry->GetFlags() & wxACCEL_CTRL); | |
201 | ||
202 | if (entry->GetFlags() & wxACCEL_ALT) | |
203 | modifiers |= kMenuOptionModifier ; | |
204 | ||
205 | if (entry->GetFlags() & wxACCEL_SHIFT) | |
206 | modifiers |= kMenuShiftModifier ; | |
207 | ||
208 | SInt16 glyph = 0 ; | |
209 | SInt16 macKey = key ; | |
210 | if ( key >= WXK_F1 && key <= WXK_F15 ) | |
211 | { | |
212 | if ( !explicitCommandKey ) | |
213 | modifiers |= kMenuNoCommandModifier ; | |
214 | ||
215 | // for some reasons this must be 0 right now | |
216 | // everything else leads to just the first function key item | |
217 | // to be selected. Thanks to Ryan Wilcox for finding out. | |
218 | macKey = 0 ; | |
219 | glyph = kMenuF1Glyph + ( key - WXK_F1 ) ; | |
220 | if ( key >= WXK_F13 ) | |
221 | glyph += 13 ; | |
222 | } | |
223 | else | |
224 | { | |
225 | switch ( key ) | |
226 | { | |
227 | case WXK_BACK : | |
228 | macKey = kBackspaceCharCode ; | |
229 | glyph = kMenuDeleteLeftGlyph ; | |
230 | break ; | |
231 | ||
232 | case WXK_TAB : | |
233 | macKey = kTabCharCode ; | |
234 | glyph = kMenuTabRightGlyph ; | |
235 | break ; | |
236 | ||
237 | case kEnterCharCode : | |
238 | macKey = kEnterCharCode ; | |
239 | glyph = kMenuEnterGlyph ; | |
240 | break ; | |
241 | ||
242 | case WXK_RETURN : | |
243 | macKey = kReturnCharCode ; | |
244 | glyph = kMenuReturnGlyph ; | |
245 | break ; | |
246 | ||
247 | case WXK_ESCAPE : | |
248 | macKey = kEscapeCharCode ; | |
249 | glyph = kMenuEscapeGlyph ; | |
250 | break ; | |
251 | ||
252 | case WXK_SPACE : | |
253 | macKey = ' ' ; | |
254 | glyph = kMenuSpaceGlyph ; | |
255 | break ; | |
256 | ||
257 | case WXK_DELETE : | |
258 | macKey = kDeleteCharCode ; | |
259 | glyph = kMenuDeleteRightGlyph ; | |
260 | break ; | |
261 | ||
262 | case WXK_CLEAR : | |
263 | macKey = kClearCharCode ; | |
264 | glyph = kMenuClearGlyph ; | |
265 | break ; | |
266 | ||
267 | case WXK_PAGEUP : | |
268 | macKey = kPageUpCharCode ; | |
269 | glyph = kMenuPageUpGlyph ; | |
270 | break ; | |
271 | ||
272 | case WXK_PAGEDOWN : | |
273 | macKey = kPageDownCharCode ; | |
274 | glyph = kMenuPageDownGlyph ; | |
275 | break ; | |
276 | ||
277 | case WXK_LEFT : | |
278 | macKey = kLeftArrowCharCode ; | |
279 | glyph = kMenuLeftArrowGlyph ; | |
280 | break ; | |
281 | ||
282 | case WXK_UP : | |
283 | macKey = kUpArrowCharCode ; | |
284 | glyph = kMenuUpArrowGlyph ; | |
285 | break ; | |
286 | ||
287 | case WXK_RIGHT : | |
288 | macKey = kRightArrowCharCode ; | |
289 | glyph = kMenuRightArrowGlyph ; | |
290 | break ; | |
291 | ||
292 | case WXK_DOWN : | |
293 | macKey = kDownArrowCharCode ; | |
294 | glyph = kMenuDownArrowGlyph ; | |
295 | break ; | |
296 | ||
297 | case WXK_HOME : | |
298 | macKey = kHomeCharCode ; | |
299 | glyph = kMenuNorthwestArrowGlyph ; | |
300 | break ; | |
301 | ||
302 | case WXK_END : | |
303 | macKey = kEndCharCode ; | |
304 | glyph = kMenuSoutheastArrowGlyph ; | |
305 | break ; | |
306 | default : | |
307 | macKey = toupper( key ) ; | |
308 | break ; | |
309 | } | |
310 | ||
311 | // we now allow non command key shortcuts | |
312 | // remove in case this gives problems | |
313 | if ( !explicitCommandKey ) | |
314 | modifiers |= kMenuNoCommandModifier ; | |
315 | } | |
316 | ||
317 | // 1d and 1e have special meaning to SetItemCmd, so | |
318 | // do not use for these character codes. | |
319 | if (key != WXK_UP && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_LEFT) | |
320 | SetItemCmd( menu, item , macKey ); | |
321 | ||
322 | SetMenuItemModifiers( menu, item , modifiers ) ; | |
323 | ||
324 | if ( glyph ) | |
325 | SetMenuItemKeyGlyph( menu, item , glyph ) ; | |
326 | } | |
327 | } | |
328 | ||
329 | void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry ) | |
330 | { | |
331 | AppendMenuItemTextWithCFString( menu, | |
332 | CFSTR("A"), 0, 0,NULL); | |
333 | // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise) | |
334 | ChangeMenuItemAttributes( menu , ::CountMenuItems(menu), kMenuItemAttrIgnoreMeta , 0 ) ; | |
335 | UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding ); | |
336 | UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ; | |
337 | } | |
338 | ||
339 | void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry ) | |
340 | { | |
341 | InsertMenuItemTextWithCFString( menu, | |
342 | CFSTR("A"), item, 0, 0); | |
343 | ||
344 | // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise) | |
345 | ChangeMenuItemAttributes( menu , item+1, kMenuItemAttrIgnoreMeta , 0 ) ; | |
346 | UMASetMenuItemText(menu, item+1 , title , encoding ); | |
347 | UMASetMenuItemShortcut( menu , item+1 , entry ) ; | |
348 | } | |
349 | ||
350 | // quickdraw | |
351 | ||
352 | #if !TARGET_CARBON | |
353 | ||
354 | int gPrOpenCounter = 0 ; | |
355 | ||
356 | OSStatus UMAPrOpen() | |
357 | { | |
358 | OSErr err = noErr ; | |
359 | ||
360 | ++gPrOpenCounter ; | |
361 | ||
362 | if ( gPrOpenCounter == 1 ) | |
363 | { | |
364 | PrOpen() ; | |
365 | err = PrError() ; | |
366 | wxASSERT( err == noErr ) ; | |
367 | } | |
368 | ||
369 | return err ; | |
370 | } | |
371 | ||
372 | OSStatus UMAPrClose() | |
373 | { | |
374 | OSErr err = noErr ; | |
375 | ||
376 | wxASSERT( gPrOpenCounter >= 1 ) ; | |
377 | ||
378 | if ( gPrOpenCounter == 1 ) | |
379 | { | |
380 | PrClose() ; | |
381 | err = PrError() ; | |
382 | wxASSERT( err == noErr ) ; | |
383 | } | |
384 | ||
385 | --gPrOpenCounter ; | |
386 | ||
387 | return err ; | |
388 | } | |
389 | ||
390 | pascal QDGlobalsPtr GetQDGlobalsPtr() ; | |
391 | pascal QDGlobalsPtr GetQDGlobalsPtr() | |
392 | { | |
393 | return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA); | |
394 | } | |
395 | ||
396 | #endif | |
397 | ||
398 | void UMAShowWatchCursor() | |
399 | { | |
400 | SetThemeCursor(kThemeWatchCursor); | |
401 | } | |
402 | ||
403 | void UMAShowArrowCursor() | |
404 | { | |
405 | SetThemeCursor(kThemeArrowCursor); | |
406 | } | |
407 | ||
408 | // window manager | |
409 | ||
410 | GrafPtr UMAGetWindowPort( WindowRef inWindowRef ) | |
411 | { | |
412 | wxASSERT( inWindowRef != NULL ) ; | |
413 | ||
414 | #if TARGET_CARBON | |
415 | return (GrafPtr) GetWindowPort( inWindowRef ) ; | |
416 | #else | |
417 | return (GrafPtr) inWindowRef ; | |
418 | #endif | |
419 | } | |
420 | ||
421 | void UMADisposeWindow( WindowRef inWindowRef ) | |
422 | { | |
423 | wxASSERT( inWindowRef != NULL ) ; | |
424 | ||
425 | DisposeWindow( inWindowRef ) ; | |
426 | } | |
427 | ||
428 | void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncoding encoding ) | |
429 | { | |
430 | #if TARGET_CARBON | |
431 | SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title , encoding) ) ; | |
432 | ||
433 | #else | |
434 | Str255 ptitle ; | |
435 | wxMacStringToPascal( title , ptitle ) ; | |
436 | SetWTitle( inWindowRef , ptitle ) ; | |
437 | #endif | |
438 | } | |
439 | ||
440 | // appearance additions | |
441 | ||
442 | void UMASetControlTitle( ControlRef inControl , const wxString& title , wxFontEncoding encoding ) | |
443 | { | |
444 | #if TARGET_CARBON | |
445 | SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ; | |
446 | ||
447 | #else | |
448 | Str255 ptitle ; | |
449 | wxMacStringToPascal( title , ptitle ) ; | |
450 | SetControlTitle( inControl , ptitle ) ; | |
451 | #endif | |
452 | } | |
453 | ||
454 | void UMAActivateControl( ControlRef inControl ) | |
455 | { | |
456 | #if TARGET_API_MAC_OSX | |
457 | ::ActivateControl( inControl ) ; | |
458 | ||
459 | #else | |
460 | // we have to add the control after again to the update rgn | |
461 | // otherwise updates get lost | |
462 | if ( !IsControlActive( inControl ) ) | |
463 | { | |
464 | bool visible = IsControlVisible( inControl ) ; | |
465 | if ( visible ) | |
466 | SetControlVisibility( inControl , false , false ) ; | |
467 | ||
468 | ::ActivateControl( inControl ) ; | |
469 | ||
470 | if ( visible ) | |
471 | { | |
472 | SetControlVisibility( inControl , true , false ) ; | |
473 | ||
474 | Rect ctrlBounds ; | |
475 | InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ; | |
476 | } | |
477 | } | |
478 | #endif | |
479 | } | |
480 | ||
481 | void UMAMoveControl( ControlRef inControl , short x , short y ) | |
482 | { | |
483 | #if TARGET_API_MAC_OSX | |
484 | ::MoveControl( inControl , x , y ) ; | |
485 | ||
486 | #else | |
487 | bool visible = IsControlVisible( inControl ) ; | |
488 | if ( visible ) | |
489 | { | |
490 | SetControlVisibility( inControl , false , false ) ; | |
491 | Rect ctrlBounds ; | |
492 | InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ; | |
493 | } | |
494 | ||
495 | ::MoveControl( inControl , x , y ) ; | |
496 | ||
497 | if ( visible ) | |
498 | { | |
499 | SetControlVisibility( inControl , true , false ) ; | |
500 | Rect ctrlBounds ; | |
501 | InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ; | |
502 | } | |
503 | #endif | |
504 | } | |
505 | ||
506 | void UMASizeControl( ControlRef inControl , short x , short y ) | |
507 | { | |
508 | #if TARGET_API_MAC_OSX | |
509 | ::SizeControl( inControl , x , y ) ; | |
510 | ||
511 | #else | |
512 | bool visible = IsControlVisible( inControl ) ; | |
513 | if ( visible ) | |
514 | { | |
515 | SetControlVisibility( inControl , false , false ) ; | |
516 | Rect ctrlBounds ; | |
517 | InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ; | |
518 | } | |
519 | ||
520 | ::SizeControl( inControl , x , y ) ; | |
521 | ||
522 | if ( visible ) | |
523 | { | |
524 | SetControlVisibility( inControl , true , false ) ; | |
525 | Rect ctrlBounds ; | |
526 | InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ; | |
527 | } | |
528 | #endif | |
529 | } | |
530 | ||
531 | void UMADeactivateControl( ControlRef inControl ) | |
532 | { | |
533 | #if TARGET_API_MAC_OSX | |
534 | ::DeactivateControl( inControl ) ; | |
535 | ||
536 | #else | |
537 | // we have to add the control after again to the update rgn | |
538 | // otherwise updates get lost | |
539 | bool visible = IsControlVisible( inControl ) ; | |
540 | if ( visible ) | |
541 | SetControlVisibility( inControl , false , false ) ; | |
542 | ||
543 | ::DeactivateControl( inControl ) ; | |
544 | ||
545 | if ( visible ) | |
546 | { | |
547 | SetControlVisibility( inControl , true , false ) ; | |
548 | Rect ctrlBounds ; | |
549 | InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ; | |
550 | } | |
551 | #endif | |
552 | } | |
553 | ||
554 | // shows the control and adds the region to the update region | |
555 | void UMAShowControl( ControlRef inControl ) | |
556 | { | |
557 | SetControlVisibility( inControl , true , false ) ; | |
558 | HIViewSetNeedsDisplay( inControl, true ); | |
559 | } | |
560 | ||
561 | // hides the control and adds the region to the update region | |
562 | void UMAHideControl( ControlRef inControl ) | |
563 | { | |
564 | SetControlVisibility( inControl , false , false ) ; | |
565 | HIViewSetNeedsDisplay( inControl, true ); | |
566 | } | |
567 | ||
568 | // keyboard focus | |
569 | OSErr UMASetKeyboardFocus( WindowPtr inWindow, | |
570 | ControlRef inControl, | |
571 | ControlFocusPart inPart ) | |
572 | { | |
573 | OSErr err = noErr; | |
574 | #ifndef __LP64__ | |
575 | GrafPtr port ; | |
576 | ||
577 | GetPort( &port ) ; | |
578 | SetPortWindowPort( inWindow ) ; | |
579 | #endif | |
580 | ||
581 | err = SetKeyboardFocus( inWindow , inControl , inPart ) ; | |
582 | #ifndef __LP64__ | |
583 | SetPort( port ) ; | |
584 | #endif | |
585 | ||
586 | return err ; | |
587 | } | |
588 | ||
589 | bool UMAIsWindowFloating( WindowRef inWindow ) | |
590 | { | |
591 | WindowClass cl ; | |
592 | ||
593 | GetWindowClass( inWindow , &cl ) ; | |
594 | return cl == kFloatingWindowClass ; | |
595 | } | |
596 | ||
597 | bool UMAIsWindowModal( WindowRef inWindow ) | |
598 | { | |
599 | WindowClass cl ; | |
600 | ||
601 | GetWindowClass( inWindow , &cl ) ; | |
602 | return cl < kFloatingWindowClass ; | |
603 | } | |
604 | ||
605 | // others | |
606 | ||
607 | void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate ) | |
608 | { | |
609 | if ( inWindowRef ) | |
610 | { | |
611 | // bool isHighlighted = IsWindowHighlited( inWindowRef ) ; | |
612 | // if ( inActivate != isHighlighted ) | |
613 | #ifndef __LP64__ | |
614 | GrafPtr port ; | |
615 | GetPort( &port ) ; | |
616 | SetPortWindowPort( inWindowRef ) ; | |
617 | #endif | |
618 | HiliteWindow( inWindowRef , inActivate ) ; | |
619 | ControlRef control = NULL ; | |
620 | ::GetRootControl( inWindowRef , &control ) ; | |
621 | if ( control ) | |
622 | { | |
623 | if ( inActivate ) | |
624 | UMAActivateControl( control ) ; | |
625 | else | |
626 | UMADeactivateControl( control ) ; | |
627 | } | |
628 | #ifndef __LP64__ | |
629 | SetPort( port ) ; | |
630 | #endif | |
631 | } | |
632 | } | |
633 | ||
634 | OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState ) | |
635 | { | |
636 | #ifndef __LP64__ | |
637 | return ::DrawThemePlacard( inRect , inState ) ; | |
638 | #else | |
639 | return noErr; | |
640 | #endif | |
641 | } | |
642 | ||
643 | #if !TARGET_CARBON | |
644 | static OSStatus helpMenuStatus = noErr ; | |
645 | static MenuItemIndex firstCustomItemIndex = 0 ; | |
646 | #endif | |
647 | ||
648 | static OSStatus UMAGetHelpMenu( | |
649 | MenuRef * outHelpMenu, | |
650 | MenuItemIndex * outFirstCustomItemIndex, | |
651 | bool allowHelpMenuCreation); | |
652 | ||
653 | static OSStatus UMAGetHelpMenu( | |
654 | MenuRef * outHelpMenu, | |
655 | MenuItemIndex * outFirstCustomItemIndex, | |
656 | bool allowHelpMenuCreation) | |
657 | { | |
658 | #if TARGET_CARBON | |
659 | static bool s_createdHelpMenu = false ; | |
660 | ||
661 | if ( !s_createdHelpMenu && !allowHelpMenuCreation ) | |
662 | { | |
663 | return paramErr ; | |
664 | } | |
665 | ||
666 | OSStatus status = HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ; | |
667 | s_createdHelpMenu = ( status == noErr ) ; | |
668 | return status ; | |
669 | #else | |
670 | wxUnusedVar( allowHelpMenuCreation ) ; | |
671 | MenuRef helpMenuHandle ; | |
672 | ||
673 | helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ; | |
674 | if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr ) | |
675 | firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ; | |
676 | ||
677 | if ( outFirstCustomItemIndex ) | |
678 | *outFirstCustomItemIndex = firstCustomItemIndex ; | |
679 | ||
680 | *outHelpMenu = helpMenuHandle ; | |
681 | ||
682 | return helpMenuStatus ; | |
683 | #endif | |
684 | } | |
685 | ||
686 | OSStatus UMAGetHelpMenu( | |
687 | MenuRef * outHelpMenu, | |
688 | MenuItemIndex * outFirstCustomItemIndex) | |
689 | { | |
690 | return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , true ); | |
691 | } | |
692 | ||
693 | OSStatus UMAGetHelpMenuDontCreate( | |
694 | MenuRef * outHelpMenu, | |
695 | MenuItemIndex * outFirstCustomItemIndex) | |
696 | { | |
697 | return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , false ); | |
698 | } | |
699 | ||
700 | #ifndef __LP64__ | |
701 | ||
702 | wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport ) | |
703 | { | |
704 | m_clip = NULL ; | |
705 | Setup( newport ) ; | |
706 | } | |
707 | ||
708 | wxMacPortStateHelper::wxMacPortStateHelper() | |
709 | { | |
710 | m_clip = NULL ; | |
711 | } | |
712 | ||
713 | void wxMacPortStateHelper::Setup( GrafPtr newport ) | |
714 | { | |
715 | GetPort( &m_oldPort ) ; | |
716 | SetPort( newport ) ; | |
717 | SetOrigin(0, 0); | |
718 | ||
719 | wxASSERT_MSG( m_clip == NULL , wxT("Cannot call setup twice") ) ; | |
720 | m_clip = NewRgn() ; | |
721 | GetClip( m_clip ); | |
722 | m_textFont = GetPortTextFont( (CGrafPtr) newport ); | |
723 | m_textSize = GetPortTextSize( (CGrafPtr) newport ); | |
724 | m_textStyle = GetPortTextFace( (CGrafPtr) newport ); | |
725 | m_textMode = GetPortTextMode( (CGrafPtr) newport ); | |
726 | GetThemeDrawingState( &m_drawingState ) ; | |
727 | m_currentPort = newport ; | |
728 | } | |
729 | ||
730 | void wxMacPortStateHelper::Clear() | |
731 | { | |
732 | if ( m_clip ) | |
733 | { | |
734 | DisposeRgn( m_clip ) ; | |
735 | DisposeThemeDrawingState( m_drawingState ) ; | |
736 | m_clip = NULL ; | |
737 | } | |
738 | } | |
739 | ||
740 | wxMacPortStateHelper::~wxMacPortStateHelper() | |
741 | { | |
742 | if ( m_clip ) | |
743 | { | |
744 | SetPort( m_currentPort ) ; | |
745 | SetClip( m_clip ) ; | |
746 | DisposeRgn( m_clip ) ; | |
747 | TextFont( m_textFont ); | |
748 | TextSize( m_textSize ); | |
749 | TextFace( m_textStyle ); | |
750 | TextMode( m_textMode ); | |
751 | SetThemeDrawingState( m_drawingState , true ) ; | |
752 | SetPort( m_oldPort ) ; | |
753 | } | |
754 | } | |
755 | ||
756 | #endif | |
757 | ||
758 | OSStatus UMAPutScrap( Size size , OSType type , void *data ) | |
759 | { | |
760 | OSStatus err = noErr ; | |
761 | ||
762 | #if !TARGET_CARBON | |
763 | err = PutScrap( size , type , data ) ; | |
764 | #else | |
765 | ScrapRef scrap; | |
766 | err = GetCurrentScrap( &scrap ); | |
767 | if ( err == noErr ) | |
768 | err = PutScrapFlavor( scrap, type , 0, size, data ); | |
769 | #endif | |
770 | ||
771 | return err ; | |
772 | } | |
773 | ||
774 | Rect * UMAGetControlBoundsInWindowCoords( ControlRef theControl, Rect *bounds ) | |
775 | { | |
776 | GetControlBounds( theControl , bounds ) ; | |
777 | ||
778 | #if TARGET_API_MAC_OSX | |
779 | WindowRef tlwref = GetControlOwner( theControl ) ; | |
780 | ||
781 | wxTopLevelWindowMac* tlwwx = wxFindWinFromMacWindow( tlwref ) ; | |
782 | if ( tlwwx != NULL ) | |
783 | { | |
784 | ControlRef rootControl = tlwwx->GetPeer()->GetControlRef() ; | |
785 | HIPoint hiPoint = CGPointMake( 0 , 0 ) ; | |
786 | HIViewConvertPoint( &hiPoint , HIViewGetSuperview(theControl) , rootControl ) ; | |
787 | OffsetRect( bounds , (short) hiPoint.x , (short) hiPoint.y ) ; | |
788 | } | |
789 | #endif | |
790 | ||
791 | return bounds ; | |
792 | } | |
793 | ||
794 | #endif // wxUSE_GUI | |
795 | ||
796 | #if wxUSE_BASE | |
797 | ||
798 | static bool sUMASystemInitialized = false ; | |
799 | ||
800 | bool UMASystemIsInitialized() | |
801 | { | |
802 | return sUMASystemInitialized ; | |
803 | } | |
804 | ||
805 | void UMASetSystemIsInitialized(bool val) | |
806 | { | |
807 | sUMASystemInitialized = val; | |
808 | } | |
809 | ||
810 | #endif // wxUSE_BASE |