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