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