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