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