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