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