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