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