]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/uma.cpp
ed700c09fb842ed8971f062dffd04b04a1227592
[wxWidgets.git] / src / mac / carbon / uma.cpp
1 #include "wx/defs.h"
2 #include "wx/dc.h"
3 #include "wx/mac/uma.h"
4 #include "wx/mac/aga.h"
5
6 #ifdef __UNIX__
7 #include <Carbon/Carbon.h>
8 #else
9 #include <Navigation.h>
10 #endif
11
12 // init
13
14 #if !TARGET_CARBON
15 #define GetControlOwner( control ) (**control).contrlOwner
16 // since we always call this in the right context we don't have to set and reset the port
17 #define InvalWindowRgn( window , rgn ) InvalRgn( rgn )
18 #endif
19
20 static bool sUMAHasAppearance = false ;
21 static long sUMAAppearanceVersion = 0 ;
22 extern int gAGABackgroundColor ;
23 bool UMAHasAppearance() { return sUMAHasAppearance ; }
24 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; }
25
26 static bool sUMAHasWindowManager = false ;
27 static long sUMAWindowManagerAttr = 0 ;
28
29 bool UMAHasWindowManager() { return sUMAHasWindowManager ; }
30 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; }
31 void UMACleanupToolbox()
32 {
33 #if UMA_USE_APPEARANCE
34 if ( sUMAHasAppearance )
35 {
36 UnregisterAppearanceClient() ;
37 }
38 #endif
39 if ( NavServicesAvailable() )
40 {
41 NavUnload() ;
42 }
43 }
44 void UMAInitToolbox( UInt16 inMoreMastersCalls )
45 {
46 #if !TARGET_CARBON
47 ::MaxApplZone();
48 for (long i = 1; i <= inMoreMastersCalls; i++)
49 ::MoreMasters();
50
51 ::InitGraf(&qd.thePort);
52 ::InitFonts();
53 ::InitMenus();
54 ::TEInit();
55 ::InitDialogs(0L);
56 ::FlushEvents(everyEvent, 0);
57 ::InitCursor();
58 long total,contig;
59 PurgeSpace(&total, &contig);
60 #else
61 InitCursor();
62 #endif
63
64 #if UMA_USE_APPEARANCE
65 long theAppearance ;
66 if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr )
67 {
68 sUMAHasAppearance = true ;
69 RegisterAppearanceClient();
70 if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr )
71 {
72 sUMAAppearanceVersion = theAppearance ;
73 }
74 else
75 {
76 sUMAAppearanceVersion = 0x0100 ;
77 }
78 }
79 #endif // UMA_USE_APPEARANCE
80 #if UMA_USE_8_6
81 #if UMA_USE_WINDOWMGR
82 if ( Gestalt( gestaltWindowMgrAttr, &sUMAWindowManagerAttr ) == noErr )
83 {
84 sUMAHasWindowManager = sUMAWindowManagerAttr & gestaltWindowMgrPresent ;
85 }
86 #endif // UMA_USE_WINDOWMGR
87 #endif
88
89 #ifndef __UNIX__
90 #if TARGET_CARBON
91 // Call currently implicitely done : InitFloatingWindows() ;
92 #else
93 if ( sUMAHasWindowManager )
94 InitFloatingWindows() ;
95 else
96 InitWindows();
97 #endif
98 #endif
99
100 if ( NavServicesAvailable() )
101 {
102 NavLoad() ;
103 }
104 }
105
106 // process manager
107 long UMAGetProcessMode()
108 {
109 OSErr err ;
110 ProcessInfoRec processinfo;
111 ProcessSerialNumber procno ;
112
113 procno.highLongOfPSN = NULL ;
114 procno.lowLongOfPSN = kCurrentProcess ;
115 processinfo.processInfoLength = sizeof(ProcessInfoRec);
116 processinfo.processName = NULL;
117 processinfo.processAppSpec = NULL;
118
119 err = ::GetProcessInformation( &procno , &processinfo ) ;
120 wxASSERT( err == noErr ) ;
121 return processinfo.processMode ;
122 }
123
124 bool UMAGetProcessModeDoesActivateOnFGSwitch()
125 {
126 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ;
127 }
128
129 // menu manager
130
131 void UMASetMenuTitle( MenuRef menu , StringPtr title )
132 {
133 #if !TARGET_CARBON
134 long size = GetHandleSize( (Handle) menu ) ;
135 const long headersize = 14 ;
136 int oldlen = (**menu).menuData[0] + 1;
137 int newlen = title[0] + 1 ;
138
139 if ( oldlen < newlen )
140 {
141 // enlarge before adjusting
142 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
143 }
144
145 if ( oldlen != newlen )
146 memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
147
148 memcpy( (char*) (**menu).menuData , title , newlen ) ;
149 if ( oldlen > newlen )
150 {
151 // shrink after
152 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
153 }
154 #else
155 SetMenuTitle( menu , title ) ;
156 #endif
157 }
158
159 UInt32 UMAMenuEvent( EventRecord *inEvent )
160 {
161 #if UMA_USE_APPEARANCE
162 if ( UMAHasAppearance() )
163 {
164 return MenuEvent( inEvent ) ;
165 }
166 else
167 #endif
168 {
169 if ( inEvent->what == keyDown && inEvent->modifiers & cmdKey)
170 {
171 return MenuKey( inEvent->message & charCodeMask ) ;
172 }
173 return NULL ;
174 }
175 }
176
177 void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
178 {
179 #if UMA_USE_8_6 || TARGET_CARBON
180 EnableMenuItem( inMenu , inItem ) ;
181 #else
182 EnableItem( inMenu , inItem ) ;
183 #endif
184 }
185
186 void UMADisableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
187 {
188 #if UMA_USE_8_6 || TARGET_CARBON
189 DisableMenuItem( inMenu , inItem ) ;
190 #else
191 DisableItem( inMenu , inItem ) ;
192 #endif
193 }
194
195 void UMAAppendSubMenuItem( MenuRef menu , StringPtr l , SInt16 id )
196 {
197 Str255 label ;
198 memcpy( label , l , l[0]+1 ) ;
199 // hardcoded adding of the submenu combination for mac
200
201 int theEnd = label[0] + 1;
202 if (theEnd > 251)
203 theEnd = 251; // mac allows only 255 characters
204 label[theEnd++] = '/';
205 label[theEnd++] = hMenuCmd;
206 label[theEnd++] = '!';
207 label[theEnd++] = id ;
208 label[theEnd] = 0x00;
209 label[0] = theEnd;
210 MacAppendMenu(menu, label);
211 }
212
213 void UMAInsertSubMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 id )
214 {
215 Str255 label ;
216 memcpy( label , l , l[0]+1 ) ;
217 // hardcoded adding of the submenu combination for mac
218
219 int theEnd = label[0] + 1;
220 if (theEnd > 251)
221 theEnd = 251; // mac allows only 255 characters
222 label[theEnd++] = '/';
223 label[theEnd++] = hMenuCmd;
224 label[theEnd++] = '!';
225 label[theEnd++] = id;
226 label[theEnd] = 0x00;
227 label[0] = theEnd;
228 MacInsertMenuItem(menu, label , item);
229 }
230
231 void UMAAppendMenuItem( MenuRef menu , StringPtr l , SInt16 key, UInt8 modifiers )
232 {
233 Str255 label ;
234 memcpy( label , l , l[0]+1 ) ;
235 if ( key )
236 {
237 int pos = label[0] ;
238 label[++pos] = '/';
239 label[++pos] = toupper( key );
240 label[0] = pos ;
241 }
242 MacAppendMenu( menu , label ) ;
243 }
244
245 void UMAInsertMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 key, UInt8 modifiers )
246 {
247 Str255 label ;
248 memcpy( label , l , l[0]+1 ) ;
249 if ( key )
250 {
251 int pos = label[0] ;
252 label[++pos] = '/';
253 label[++pos] = toupper( key );
254 label[0] = pos ;
255 }
256 MacInsertMenuItem( menu , label , item) ;
257 }
258
259 void UMADrawMenuBar()
260 {
261 DrawMenuBar() ;
262 }
263
264
265 void UMASetMenuItemText( MenuRef menu , MenuItemIndex item , StringPtr label )
266 {
267 ::SetMenuItemText( menu , item , label ) ;
268 }
269
270 MenuRef UMANewMenu( SInt16 menuid , StringPtr label )
271 {
272 return ::NewMenu(menuid, label);
273 }
274
275 void UMADisposeMenu( MenuRef menu )
276 {
277 DisposeMenu( menu ) ;
278 }
279 void UMADeleteMenu( SInt16 menuId )
280 {
281 ::DeleteMenu( menuId ) ;
282 }
283
284 void UMAInsertMenu( MenuRef insertMenu , SInt16 afterId )
285 {
286 ::InsertMenu( insertMenu , afterId ) ;
287 }
288
289
290 // quickdraw
291
292 int gPrOpenCounter = 0 ;
293
294 OSStatus UMAPrOpen()
295 {
296 #if !TARGET_CARBON
297 OSErr err = noErr ;
298 ++gPrOpenCounter ;
299 if ( gPrOpenCounter == 1 )
300 {
301 PrOpen() ;
302 err = PrError() ;
303 wxASSERT( err == noErr ) ;
304 }
305 return err ;
306 #else
307 OSStatus err = noErr ;
308 ++gPrOpenCounter ;
309 if ( gPrOpenCounter == 1 )
310 {
311 err = PMBegin() ;
312 wxASSERT( err == noErr ) ;
313 }
314 return err ;
315 #endif
316 }
317
318 OSStatus UMAPrClose()
319 {
320 #if !TARGET_CARBON
321 OSErr err = noErr ;
322 wxASSERT( gPrOpenCounter >= 1 ) ;
323 if ( gPrOpenCounter == 1 )
324 {
325 PrClose() ;
326 err = PrError() ;
327 wxASSERT( err == noErr ) ;
328 }
329 --gPrOpenCounter ;
330 return err ;
331 #else
332 OSStatus err = noErr ;
333 wxASSERT( gPrOpenCounter >= 1 ) ;
334 if ( gPrOpenCounter == 1 )
335 {
336 err = PMEnd() ;
337 }
338 --gPrOpenCounter ;
339 return err ;
340 #endif
341 }
342
343 #if !TARGET_CARBON
344
345 pascal QDGlobalsPtr GetQDGlobalsPtr (void)
346 {
347 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
348 }
349
350 #endif
351
352 void UMAShowWatchCursor()
353 {
354 OSErr err = noErr;
355
356 CursHandle watchFob = GetCursor (watchCursor);
357
358 if (!watchFob)
359 err = nilHandleErr;
360 else
361 {
362 #if TARGET_CARBON
363 Cursor preservedArrow;
364 GetQDGlobalsArrow (&preservedArrow);
365 SetQDGlobalsArrow (*watchFob);
366 InitCursor ( );
367 SetQDGlobalsArrow (&preservedArrow);
368 #else
369 SetCursor (*watchFob);
370 #endif
371 }
372 }
373
374 void UMAShowArrowCursor()
375 {
376 #if TARGET_CARBON
377 Cursor arrow;
378 SetCursor (GetQDGlobalsArrow (&arrow));
379 #else
380 SetCursor (&(qd.arrow));
381 #endif
382 }
383
384 // window manager
385
386 GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
387 {
388 wxASSERT( inWindowRef != NULL ) ;
389 #if TARGET_CARBON
390 return GetWindowPort( inWindowRef ) ;
391 #else
392 return (GrafPtr) inWindowRef ;
393 #endif
394 }
395
396 void UMADisposeWindow( WindowRef inWindowRef )
397 {
398 wxASSERT( inWindowRef != NULL ) ;
399 DisposeWindow( inWindowRef ) ;
400 }
401
402 void UMASetWTitleC( WindowRef inWindowRef , const char *title )
403 {
404 Str255 ptitle ;
405 strncpy( (char*)ptitle , title , 96 ) ;
406 ptitle[96] = 0 ;
407 #if TARGET_CARBON
408 c2pstrcpy( ptitle, (char *)ptitle ) ;
409 #else
410 c2pstr( (char*)ptitle ) ;
411 #endif
412 SetWTitle( inWindowRef , ptitle ) ;
413 }
414
415 void UMAGetWTitleC( WindowRef inWindowRef , char *title )
416 {
417 GetWTitle( inWindowRef , (unsigned char*)title ) ;
418 #if TARGET_CARBON
419 p2cstrcpy( title, (unsigned char *)title ) ;
420 #else
421 p2cstr( (unsigned char*)title ) ;
422 #endif
423 }
424
425 void UMAShowWindow( WindowRef inWindowRef )
426 {
427 ShowWindow( inWindowRef ) ;
428 }
429
430 void UMAHideWindow( WindowRef inWindowRef )
431 {
432 HideWindow( inWindowRef) ;
433 }
434
435 void UMASelectWindow( WindowRef inWindowRef )
436 {
437 SelectWindow( inWindowRef ) ;
438 }
439
440 void UMABringToFront( WindowRef inWindowRef )
441 {
442 BringToFront( inWindowRef ) ;
443 }
444
445 void UMASendBehind( WindowRef inWindowRef , WindowRef behindWindow )
446 {
447 SendBehind( inWindowRef , behindWindow ) ;
448 }
449
450 void UMACloseWindow(WindowRef inWindowRef)
451 {
452 #if TARGET_CARBON
453 #else
454 CloseWindow( inWindowRef ) ;
455 #endif
456 }
457
458 // appearance additions
459
460 void UMAActivateControl( ControlHandle inControl )
461 {
462 WindowRef theWindow = GetControlOwner(inControl) ;
463 RgnHandle updateRgn = NewRgn() ;
464 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
465 GetWindowRegion( theWindow , kWindowUpdateRgn, updateRgn ) ;
466 #else
467 GetWindowUpdateRgn( theWindow , updateRgn ) ;
468 #endif
469 #if UMA_USE_APPEARANCE
470 if ( UMAHasAppearance() )
471 {
472 ::ActivateControl( inControl ) ;
473 }
474 else
475 #endif
476 #if !TARGET_CARBON
477 {
478 AGAActivateControl( inControl ) ;
479 }
480 #else
481 {
482 }
483 #endif
484 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
485 InvalWindowRgn( theWindow, updateRgn) ;
486 #else
487 InvalRgn( updateRgn ) ;
488 #endif
489 }
490
491 void UMADrawControl( ControlHandle inControl )
492 {
493 WindowRef theWindow = GetControlOwner(inControl) ;
494 RgnHandle updateRgn = NewRgn() ;
495 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
496 GetWindowRegion( theWindow , kWindowUpdateRgn, updateRgn ) ;
497 #else
498 GetWindowUpdateRgn( theWindow , updateRgn ) ;
499 #endif
500 #if UMA_USE_APPEARANCE
501 if ( UMAHasAppearance() )
502 {
503 ::DrawControlInCurrentPort( inControl ) ;
504 }
505 else
506 #endif
507 #if !TARGET_CARBON
508 {
509 AGADrawControl( inControl ) ;
510 }
511 #else
512 {
513 }
514 #endif
515 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
516 InvalWindowRgn( theWindow, updateRgn) ;
517 #else
518 InvalRgn( updateRgn ) ;
519 #endif
520 }
521
522 void UMAMoveControl( ControlHandle inControl , short x , short y )
523 {
524 WindowRef theWindow = GetControlOwner(inControl) ;
525 RgnHandle updateRgn = NewRgn() ;
526 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
527 GetWindowRegion( theWindow , kWindowUpdateRgn, updateRgn ) ;
528 #else
529 GetWindowUpdateRgn( theWindow , updateRgn ) ;
530 #endif
531 #if UMA_USE_APPEARANCE
532 if ( UMAHasAppearance() )
533 {
534 ::MoveControl( inControl , x , y ) ;
535 }
536 else
537 #endif
538 #if !TARGET_CARBON
539 {
540 AGAMoveControl( inControl , x ,y ) ;
541 }
542 #else
543 {
544 }
545 #endif
546 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
547 InvalWindowRgn( theWindow, updateRgn) ;
548 #else
549 InvalRgn( updateRgn ) ;
550 #endif
551 }
552
553 void UMASizeControl( ControlHandle inControl , short x , short y )
554 {
555 WindowRef theWindow = GetControlOwner(inControl) ;
556 RgnHandle updateRgn = NewRgn() ;
557 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
558 GetWindowRegion( theWindow , kWindowUpdateRgn, updateRgn ) ;
559 #else
560 GetWindowUpdateRgn( theWindow , updateRgn ) ;
561 #endif
562 #if UMA_USE_APPEARANCE
563 if ( UMAHasAppearance() )
564 {
565 ::SizeControl( inControl , x , y ) ;
566 }
567 else
568 #endif
569 #if !TARGET_CARBON
570 {
571 AGASizeControl( inControl , x ,y ) ;
572 }
573 #else
574 {
575 }
576 #endif
577 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
578 InvalWindowRgn( theWindow, updateRgn) ;
579 #else
580 InvalRgn( updateRgn ) ;
581 #endif
582
583 }
584
585 void UMADeactivateControl( ControlHandle inControl )
586 {
587 WindowRef theWindow = GetControlOwner(inControl) ;
588 RgnHandle updateRgn = NewRgn() ;
589 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
590 GetWindowRegion( theWindow , kWindowUpdateRgn, updateRgn ) ;
591 #else
592 GetWindowUpdateRgn( theWindow , updateRgn ) ;
593 #endif
594 #if UMA_USE_APPEARANCE
595 if ( UMAHasAppearance() )
596 {
597 ::DeactivateControl( inControl ) ;
598 }
599 else
600 #endif
601 #if !TARGET_CARBON
602 {
603 AGADeactivateControl( inControl ) ;
604 }
605 #else
606 {
607 }
608 #endif
609 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
610 InvalWindowRgn( theWindow, updateRgn) ;
611 #else
612 InvalRgn( updateRgn ) ;
613 #endif
614 }
615
616 void UMASetThemeWindowBackground (WindowRef inWindow,
617 ThemeBrush inBrush,
618 Boolean inUpdate)
619 {
620 #if UMA_USE_APPEARANCE
621 if ( UMAHasAppearance() )
622 {
623 ::SetThemeWindowBackground( inWindow ,inBrush , inUpdate ) ;
624 }
625 else
626 #endif
627 #if !TARGET_CARBON
628 {
629 AGASetThemeWindowBackground( inWindow , inBrush , inUpdate ) ;
630 }
631 #else
632 {
633 }
634 #endif
635 }
636
637 void UMAApplyThemeBackground (ThemeBackgroundKind inKind,
638 const Rect * bounds,
639 ThemeDrawState inState,
640 SInt16 inDepth,
641 Boolean inColorDev)
642 {
643 #if UMA_USE_APPEARANCE
644 if ( UMAHasAppearance() )
645 {
646 /*
647 if ( sUMAAppearanceVersion >= 0x0110 )
648 ::ApplyThemeBackground( inKind ,bounds , inState , inDepth , inColorDev ) ;
649 */
650 }
651 else
652 #endif
653 #if !TARGET_CARBON
654 {
655 AGAApplyThemeBackground( inKind ,bounds , inState , inDepth , inColorDev ) ;
656 }
657 #else
658 {
659 }
660 #endif
661 }
662
663 ControlHandle UMANewControl(WindowPtr owningWindow,
664 const Rect * boundsRect,
665 ConstStr255Param controlTitle,
666 Boolean initiallyVisible,
667 SInt16 initialValue,
668 SInt16 minimumValue,
669 SInt16 maximumValue,
670 SInt16 procID,
671 SInt32 controlReference)
672 {
673 ControlHandle theControl = NULL ;
674 #if UMA_USE_APPEARANCE
675 if ( UMAHasAppearance() )
676 {
677 theControl = NewControl( owningWindow , boundsRect , controlTitle , initiallyVisible ,
678 initialValue , minimumValue , maximumValue , procID , controlReference ) ;
679 }
680 else
681 #endif
682 #if !TARGET_CARBON
683 {
684 theControl = AGANewControl( owningWindow , boundsRect , controlTitle , initiallyVisible ,
685 initialValue , minimumValue , maximumValue , procID , controlReference ) ;
686 }
687 #else
688 {
689 }
690 #endif
691 return theControl ;
692 }
693
694 void UMADisposeControl (ControlHandle theControl)
695 {
696 if ( UMAHasAppearance() )
697 {
698 ::DisposeControl( theControl ) ;
699 }
700 else
701 {
702 ::DisposeControl( theControl ) ;
703 }
704 }
705
706 void UMAHiliteControl (ControlHandle inControl,
707 ControlPartCode hiliteState)
708 {
709 WindowRef theWindow = GetControlOwner(inControl) ;
710 RgnHandle updateRgn = NewRgn() ;
711 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
712 GetWindowRegion( theWindow , kWindowUpdateRgn, updateRgn ) ;
713 #else
714 GetWindowUpdateRgn( theWindow , updateRgn ) ;
715 #endif
716 if ( UMAHasAppearance() )
717 {
718 ::HiliteControl( inControl , hiliteState ) ;
719 }
720 else
721 {
722 ::HiliteControl( inControl , hiliteState ) ;
723 }
724 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
725 InvalWindowRgn( theWindow, updateRgn) ;
726 #else
727 InvalRgn( updateRgn ) ;
728 #endif
729 }
730
731 void UMAShowControl (ControlHandle inControl)
732 {
733 WindowRef theWindow = GetControlOwner(inControl) ;
734 RgnHandle updateRgn = NewRgn() ;
735 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
736 GetWindowRegion( theWindow , kWindowUpdateRgn, updateRgn ) ;
737 #else
738 GetWindowUpdateRgn( theWindow , updateRgn ) ;
739 #endif
740 if ( UMAHasAppearance() )
741 {
742 ::ShowControl( inControl ) ;
743 }
744 else
745 {
746 ::ShowControl( inControl ) ;
747 }
748 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
749 InvalWindowRgn( theWindow, updateRgn) ;
750 #else
751 InvalRgn( updateRgn ) ;
752 #endif
753 }
754
755
756 void UMAHideControl (ControlHandle inControl)
757 {
758 if ( UMAHasAppearance() )
759 {
760 ::HideControl( inControl ) ;
761 }
762 else
763 {
764 ::HideControl( inControl ) ;
765 }
766 }
767
768
769 void UMASetControlVisibility (ControlHandle inControl,
770 Boolean inIsVisible,
771 Boolean inDoDraw)
772 {
773 if ( UMAHasAppearance() )
774 {
775 #if UMA_USE_APPEARANCE
776 ::SetControlVisibility( inControl , inIsVisible, inDoDraw ) ;
777 #endif
778 }
779 }
780
781
782
783 bool UMAIsControlActive (ControlHandle inControl)
784 {
785 #if TARGET_CARBON
786 return IsControlActive( inControl ) ;
787 #else
788 #if UMA_USE_APPEARANCE
789 if ( UMAHasAppearance() )
790 {
791 return IsControlActive( inControl ) ;
792 }
793 else
794 #endif
795 return (**inControl).contrlHilite == 0 ;
796 #endif
797 }
798
799
800 bool UMAIsControlVisible (ControlHandle inControl)
801 {
802 #if UMA_USE_APPEARANCE
803 if ( UMAHasAppearance() )
804 {
805 return IsControlVisible( inControl ) ;
806 }
807 #endif
808 return true ;
809 }
810
811 OSErr UMAGetBestControlRect (ControlHandle inControl,
812 Rect * outRect,
813 SInt16 * outBaseLineOffset)
814 {
815 #if UMA_USE_APPEARANCE
816 if ( UMAHasAppearance() )
817 {
818 return GetBestControlRect( inControl , outRect , outBaseLineOffset ) ;
819 }
820 else
821 #endif
822 #if !TARGET_CARBON
823 {
824 return AGAGetBestControlRect( inControl , outRect , outBaseLineOffset ) ;
825 }
826 #else
827 {
828 return noErr ;
829 }
830 #endif
831 }
832
833
834 OSErr UMASetControlFontStyle (ControlHandle inControl,
835 const ControlFontStyleRec * inStyle)
836 {
837 #if UMA_USE_APPEARANCE
838 if ( UMAHasAppearance() )
839 {
840 return ::SetControlFontStyle( inControl , inStyle ) ;
841 }
842 else
843 #endif
844 #if !TARGET_CARBON
845 return AGASetControlFontStyle( inControl , inStyle ) ;
846 #else
847 {
848 return noErr ;
849 }
850 #endif
851 }
852
853
854
855 // control hierarchy
856
857 OSErr UMACreateRootControl (WindowPtr inWindow,
858 ControlHandle * outControl)
859 {
860 #if UMA_USE_APPEARANCE
861 if ( UMAHasAppearance() )
862 {
863 return CreateRootControl( inWindow , outControl ) ;
864 }
865 else
866 #endif
867 #if !TARGET_CARBON
868 return AGACreateRootControl( inWindow , outControl ) ;
869 #else
870 {
871 return noErr ;
872 }
873 #endif
874 }
875
876
877
878 OSErr UMAEmbedControl (ControlHandle inControl,
879 ControlHandle inContainer)
880 {
881 #if UMA_USE_APPEARANCE
882 if ( UMAHasAppearance() )
883 {
884 return EmbedControl( inControl , inContainer ) ;
885 }
886 else
887 #endif
888 #if !TARGET_CARBON
889 return AGAEmbedControl( inControl , inContainer ) ; ;
890 #else
891 {
892 return noErr ;
893 }
894 #endif
895 }
896
897
898
899 // keyboard focus
900 OSErr UMASetKeyboardFocus (WindowPtr inWindow,
901 ControlHandle inControl,
902 ControlFocusPart inPart)
903 {
904 OSErr err = noErr;
905 GrafPtr port ;
906 GetPort( &port ) ;
907 #if TARGET_CARBON
908 SetPort( GetWindowPort( inWindow ) ) ;
909 #else
910 SetPort( inWindow ) ;
911 #endif
912 SetOrigin( 0 , 0 ) ;
913 #if UMA_USE_APPEARANCE
914 if ( UMAHasAppearance() )
915 {
916 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
917 }
918 else
919 #endif
920 #if !TARGET_CARBON
921 err = AGASetKeyboardFocus( inWindow , inControl , inPart ) ;
922 #else
923 {
924 }
925 #endif
926 SetPort( port ) ;
927 return err ;
928 }
929
930
931
932
933 // events
934
935 ControlPartCode UMAHandleControlClick (ControlHandle inControl,
936 Point inWhere,
937 SInt16 inModifiers,
938 ControlActionUPP inAction)
939 {
940 #if UMA_USE_APPEARANCE
941 if ( UMAHasAppearance() )
942 {
943 return HandleControlClick( inControl , inWhere , inModifiers , inAction ) ;
944 }
945 else
946 #endif
947 #if !TARGET_CARBON
948 {
949 return AGAHandleControlClick( inControl , inWhere , inModifiers , inAction ) ;
950 }
951 #else
952 {
953 return noErr ;
954 }
955 #endif
956 }
957
958
959 SInt16 UMAHandleControlKey (ControlHandle inControl,
960 SInt16 inKeyCode,
961 SInt16 inCharCode,
962 SInt16 inModifiers)
963 {
964 #if UMA_USE_APPEARANCE
965 if ( UMAHasAppearance() )
966 {
967 return HandleControlKey( inControl , inKeyCode , inCharCode , inModifiers ) ;
968 }
969 else
970 #endif
971 #if !TARGET_CARBON
972 {
973 return AGAHandleControlKey(inControl , inKeyCode , inCharCode , inModifiers ) ;
974 }
975 #else
976 {
977 return noErr ;
978 }
979 #endif
980 }
981
982
983
984 void UMAIdleControls (WindowPtr inWindow)
985 {
986 #if UMA_USE_APPEARANCE
987 if ( UMAHasAppearance() )
988 {
989 IdleControls( inWindow ) ;
990 }
991 else
992 #endif
993 #if !TARGET_CARBON
994 {
995 AGAIdleControls( inWindow ) ;
996 }
997 #else
998 {
999 }
1000 #endif
1001 }
1002
1003 void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
1004 {
1005 RgnHandle updateRgn = NewRgn() ;
1006 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
1007 GetWindowRegion( inWindow , kWindowUpdateRgn, updateRgn ) ;
1008 #else
1009 GetWindowUpdateRgn( inWindow , updateRgn ) ;
1010 #endif
1011 #if UMA_USE_APPEARANCE
1012 if ( UMAHasAppearance() )
1013 {
1014 UpdateControls( inWindow , inRgn ) ;
1015 }
1016 else
1017 #endif
1018 #if !TARGET_CARBON
1019 {
1020 AGAUpdateControls( inWindow , inRgn ) ;
1021 }
1022 #else
1023 {
1024 }
1025 #endif
1026 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
1027 InvalWindowRgn( inWindow, updateRgn) ;
1028 #else
1029 InvalRgn( updateRgn ) ;
1030 #endif
1031 }
1032
1033 OSErr UMAGetRootControl( WindowPtr inWindow , ControlHandle *outControl )
1034 {
1035 #if UMA_USE_APPEARANCE
1036 if ( UMAHasAppearance() )
1037 {
1038 return GetRootControl( inWindow , outControl ) ;
1039 }
1040 else
1041 #endif
1042 #if !TARGET_CARBON
1043 {
1044 return AGAGetRootControl( inWindow , outControl ) ;
1045 }
1046 #else
1047 {
1048 return noErr ;
1049 }
1050 #endif
1051 }
1052
1053
1054 // handling control data
1055
1056 OSErr UMASetControlData (ControlHandle inControl,
1057 ControlPartCode inPart,
1058 ResType inTagName,
1059 Size inSize,
1060 Ptr inData)
1061 {
1062 #if UMA_USE_APPEARANCE
1063 if ( UMAHasAppearance() )
1064 {
1065 return SetControlData( inControl , inPart , inTagName , inSize , inData ) ;
1066 }
1067 else
1068 #endif
1069 #if !TARGET_CARBON
1070 return AGASetControlData( inControl , inPart , inTagName , inSize , inData ) ;
1071 #else
1072 {
1073 return noErr ;
1074 }
1075 #endif
1076 }
1077
1078
1079
1080 OSErr UMAGetControlData (ControlHandle inControl,
1081 ControlPartCode inPart,
1082 ResType inTagName,
1083 Size inBufferSize,
1084 Ptr outBuffer,
1085 Size * outActualSize)
1086 {
1087 #if UMA_USE_APPEARANCE
1088 if ( UMAHasAppearance() )
1089 {
1090 return ::GetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ;
1091 }
1092 else
1093 #endif
1094 #if !TARGET_CARBON
1095 {
1096 return AGAGetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ;
1097 }
1098 #else
1099 {
1100 return noErr ;
1101 }
1102 #endif
1103 }
1104
1105
1106 OSErr UMAGetControlDataSize (ControlHandle inControl,
1107 ControlPartCode inPart,
1108 ResType inTagName,
1109 Size * outMaxSize)
1110 {
1111 #if UMA_USE_APPEARANCE
1112 if ( UMAHasAppearance() )
1113 {
1114 return GetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ;
1115 }
1116 else
1117 #endif
1118 #if !TARGET_CARBON
1119 {
1120 return AGAGetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ;
1121 }
1122 #else
1123 {
1124 return noErr ;
1125 }
1126 #endif
1127 }
1128
1129
1130
1131
1132
1133 // system 8.0 changes
1134
1135 short UMAFindWindow( Point inPoint , WindowRef *outWindow )
1136 {
1137 // todo add the additional area codes
1138 return FindWindow( inPoint , outWindow ) ;
1139 }
1140
1141 OSStatus UMAGetWindowFeatures( WindowRef inWindowRef , UInt32 *outFeatures )
1142 {
1143 #if UMA_USE_WINDOWMGR
1144 return GetWindowFeatures( inWindowRef , outFeatures ) ;
1145 #else
1146 return 0 ;
1147 #endif
1148 }
1149
1150 OSStatus UMAGetWindowRegion( WindowRef inWindowRef , WindowRegionCode inRegionCode , RgnHandle ioWinRgn )
1151 {
1152 #if UMA_USE_WINDOWMGR
1153 return GetWindowRegion( inWindowRef , inRegionCode , ioWinRgn ) ;
1154 #else
1155 return 0 ;
1156 #endif
1157 }
1158
1159 void UMADrawGrowIcon( WindowRef inWindowRef )
1160 {
1161 DrawGrowIcon( inWindowRef ) ;
1162 }
1163
1164 OSStatus UMACollapseWindow( WindowRef inWindowRef , Boolean inCollapseIt )
1165 {
1166 return CollapseWindow( inWindowRef , inCollapseIt ) ;
1167 }
1168
1169 OSStatus UMACollapseAllWindows( Boolean inCollapseEm )
1170 {
1171 return CollapseAllWindows( inCollapseEm ) ;
1172 }
1173
1174 Boolean UMAIsWindowCollapsed( WindowRef inWindowRef )
1175 {
1176 return IsWindowCollapsed( inWindowRef ) ;
1177 }
1178
1179 Boolean UMAIsWindowCollapsable( WindowRef inWindowRef )
1180 {
1181 return IsWindowCollapsable( inWindowRef ) ;
1182 }
1183
1184 // system 8.5 changes<MacWindows.h>
1185 OSStatus UMACreateNewWindow( WindowClass windowClass , WindowAttributes attributes , const Rect *bounds, WindowRef *outWindow )
1186 {
1187 #if UMA_USE_WINDOWMGR
1188 if ( UMAHasWindowManager() )
1189 {
1190 return CreateNewWindow( windowClass , attributes, bounds, outWindow ) ;
1191 }
1192 else
1193 #endif
1194 {
1195 short procID ;
1196 if ( UMAHasAppearance() )
1197 {
1198 switch( windowClass )
1199 {
1200 case kMovableModalWindowClass :
1201 procID = kWindowMovableModalDialogProc;
1202 break ;
1203 case kModalWindowClass :
1204 procID = kWindowShadowDialogProc;
1205 break ;
1206 case kFloatingWindowClass :
1207 if ( attributes & kWindowSideTitlebarAttribute )
1208 {
1209 if( ( attributes & kWindowResizableAttribute ) &&
1210 ( attributes & kWindowFullZoomAttribute ) )
1211 {
1212 procID = kWindowFloatSideFullZoomGrowProc ;
1213 }
1214 else if( attributes & kWindowFullZoomAttribute )
1215 {
1216 procID = kWindowFloatSideFullZoomProc;
1217 }
1218 else if ( attributes & kWindowResizableAttribute )
1219 {
1220 procID = kWindowFloatSideGrowProc;
1221 }
1222 else
1223 {
1224 procID = kWindowFloatSideProc;
1225 }
1226 }
1227 else
1228 {
1229 if( ( attributes & kWindowResizableAttribute ) &&
1230 ( attributes & kWindowFullZoomAttribute ) )
1231 {
1232 procID = kWindowFloatFullZoomGrowProc ;
1233 }
1234 else if( attributes & kWindowFullZoomAttribute )
1235 {
1236 procID = kWindowFloatFullZoomProc;
1237 }
1238 else if ( attributes & kWindowResizableAttribute )
1239 {
1240 procID = kWindowFloatGrowProc;
1241 }
1242 else
1243 {
1244 procID = kWindowFloatProc;
1245 }
1246 }
1247 break ;
1248 case kDocumentWindowClass :
1249 default :
1250 if( ( attributes & kWindowResizableAttribute ) &&
1251 ( attributes & kWindowFullZoomAttribute ) )
1252 {
1253 procID = kWindowFullZoomGrowDocumentProc;
1254 }
1255 else if( attributes & kWindowFullZoomAttribute )
1256 {
1257 procID = kWindowFullZoomDocumentProc;
1258 }
1259 else if ( attributes & kWindowResizableAttribute )
1260 {
1261 procID = kWindowGrowDocumentProc;
1262 }
1263 else
1264 {
1265 procID = kWindowDocumentProc;
1266 }
1267 break ;
1268 }
1269 }
1270 else
1271 {
1272 switch( windowClass )
1273 {
1274 case kMovableModalWindowClass :
1275 procID = movableDBoxProc;
1276 break ;
1277 case kModalWindowClass :
1278 procID = altDBoxProc;
1279 break ;
1280 case kFloatingWindowClass :
1281 if ( attributes & kWindowSideTitlebarAttribute )
1282 {
1283 if( ( attributes & kWindowResizableAttribute ) &&
1284 ( attributes & kWindowFullZoomAttribute ) )
1285 {
1286 procID = floatSideZoomGrowProc ;
1287 }
1288 else if( attributes & kWindowFullZoomAttribute )
1289 {
1290 procID = floatSideZoomProc;
1291 }
1292 else if ( attributes & kWindowResizableAttribute )
1293 {
1294 procID = floatSideGrowProc;
1295 }
1296 else
1297 {
1298 procID = floatSideProc;
1299 }
1300 }
1301 else
1302 {
1303 if( ( attributes & kWindowResizableAttribute ) &&
1304 ( attributes & kWindowFullZoomAttribute ) )
1305 {
1306 procID = floatZoomGrowProc ;
1307 }
1308 else if( attributes & kWindowFullZoomAttribute )
1309 {
1310 procID = floatZoomProc;
1311 }
1312 else if ( attributes & kWindowResizableAttribute )
1313 {
1314 procID = floatGrowProc;
1315 }
1316 else
1317 {
1318 procID = floatProc;
1319 }
1320 }
1321 break ;
1322 case kDocumentWindowClass :
1323 default :
1324 if( ( attributes & kWindowResizableAttribute ) &&
1325 ( attributes & kWindowFullZoomAttribute ) )
1326 {
1327 procID = zoomDocProc;
1328 }
1329 else if( attributes & kWindowFullZoomAttribute )
1330 {
1331 procID = zoomNoGrow;
1332 }
1333 else if ( attributes & kWindowResizableAttribute )
1334 {
1335 procID = documentProc;
1336 }
1337 else
1338 {
1339 procID = noGrowDocProc;
1340 }
1341 break ;
1342 break ;
1343 }
1344 }
1345 *outWindow = NewCWindow(nil, bounds, "\p", false, procID, (WindowRef) -1 /*behind*/,
1346 attributes & kWindowCloseBoxAttribute , (long)NULL);
1347 return noErr ;
1348 }
1349 }
1350
1351 OSStatus UMAGetWindowClass( WindowRef inWindowRef , WindowClass *outWindowClass )
1352 {
1353 #if UMA_USE_WINDOWMGR
1354 if ( UMAHasWindowManager() )
1355 {
1356 return GetWindowClass( inWindowRef , outWindowClass ) ;
1357 }
1358 else
1359 #endif
1360 return kDocumentWindowClass ;
1361 }
1362
1363 OSStatus UMAGetWindowAttributes( WindowRef inWindowRef , WindowAttributes *outAttributes )
1364 {
1365 #if UMA_USE_WINDOWMGR
1366 if ( UMAHasWindowManager() )
1367 {
1368 return GetWindowAttributes( inWindowRef , outAttributes ) ;
1369 }
1370 #endif
1371 return kWindowNoAttributes ;
1372 }
1373
1374 void UMAShowFloatingWindows()
1375 {
1376 #if UMA_USE_WINDOWMGR
1377 if ( UMAHasWindowManager() )
1378 {
1379 ShowFloatingWindows() ;
1380 }
1381 #endif
1382 }
1383
1384 void UMAHideFloatingWindows()
1385 {
1386 #if UMA_USE_WINDOWMGR
1387 if ( UMAHasWindowManager() )
1388 {
1389 HideFloatingWindows() ;
1390 }
1391 #endif
1392 }
1393
1394 Boolean UMAAreFloatingWindowsVisible()
1395 {
1396 #if UMA_USE_WINDOWMGR
1397 if ( UMAHasWindowManager() )
1398 {
1399 return AreFloatingWindowsVisible() ;
1400 }
1401 #endif
1402 return false ;
1403 }
1404
1405 WindowRef UMAFrontNonFloatingWindow()
1406 {
1407 #if UMA_USE_WINDOWMGR
1408 if ( UMAHasWindowManager() )
1409 {
1410 return FrontNonFloatingWindow() ;
1411 }
1412 else
1413 #endif
1414 {
1415 return FrontWindow() ;
1416 }
1417 }
1418
1419 WindowRef UMAFrontWindow()
1420 {
1421 #if UMA_USE_WINDOWMGR
1422 if ( UMAHasWindowManager() )
1423 {
1424 return FrontWindow() ;
1425 }
1426 else
1427 #endif
1428 {
1429 return FrontWindow() ;
1430 }
1431 }
1432
1433 WindowRef UMAGetActiveNonFloatingWindow()
1434 {
1435 return NULL ;
1436 }
1437
1438 bool UMAIsWindowFloating( WindowRef inWindow )
1439 {
1440 WindowClass cl ;
1441
1442 UMAGetWindowClass( inWindow , &cl ) ;
1443 return cl == kFloatingWindowClass ;
1444 }
1445
1446 bool UMAIsWindowModal( WindowRef inWindow )
1447 {
1448 WindowClass cl ;
1449
1450 UMAGetWindowClass( inWindow , &cl ) ;
1451 return cl < kFloatingWindowClass ;
1452 }
1453
1454 // others
1455
1456 void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
1457 {
1458 if ( inWindowRef )
1459 {
1460 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
1461 // if ( inActivate != isHightlited )
1462 GrafPtr port ;
1463 GetPort( &port ) ;
1464 #if TARGET_CARBON
1465 SetPort( GetWindowPort( inWindowRef ) ) ;
1466 #else
1467 SetPort( inWindowRef ) ;
1468 #endif
1469 SetOrigin( 0 , 0 ) ;
1470 HiliteWindow( inWindowRef , inActivate ) ;
1471 ControlHandle control = NULL ;
1472 UMAGetRootControl( inWindowRef , & control ) ;
1473 if ( control )
1474 {
1475 if ( inActivate )
1476 UMAActivateControl( control ) ;
1477 else
1478 UMADeactivateControl( control ) ;
1479 }
1480 SetPort( port ) ;
1481 }
1482 }
1483 OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
1484 {
1485 #if UMA_USE_APPEARANCE
1486 if ( UMAHasAppearance() )
1487 {
1488 ::DrawThemePlacard( inRect , inState ) ;
1489 }
1490 else
1491 #endif
1492 #if !TARGET_CARBON
1493 {
1494 }
1495 #else
1496 {
1497 }
1498 #endif
1499 }
1500