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