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