]> git.saurik.com Git - wxWidgets.git/blame - src/mac/uma.cpp
added wxListView class: this is going to be a wxListCtrl with human (inter)face
[wxWidgets.git] / src / mac / 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
93f0fe75
GD
292#if TARGET_CARBON && PM_USE_SESSION_APIS
293OSStatus UMAPrOpen(PMPrintSession *macPrintSession)
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 313 #if PM_USE_SESSION_APIS
93f0fe75 314 err = PMCreateSession(macPrintSession) ;
a689a4d0
GD
315 #else
316 err = PMBegin() ;
317 #endif
5b781a67
SC
318 wxASSERT( err == noErr ) ;
319 }
320 return err ;
2f1ae414
SC
321#endif
322}
323
93f0fe75
GD
324#if TARGET_CARBON && PM_USE_SESSION_APIS
325OSStatus UMAPrClose(PMPrintSession *macPrintSession)
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 346 #if PM_USE_SESSION_APIS
93f0fe75
GD
347 err = PMRelease(*macPrintSession) ;
348 *macPrintSession = kPMNoReference;
a689a4d0
GD
349 #else
350 err = PMEnd() ;
351 #endif
5b781a67
SC
352 }
353 --gPrOpenCounter ;
354 return err ;
2f1ae414
SC
355#endif
356}
357
72e7876b
SC
358#if !TARGET_CARBON
359
360pascal QDGlobalsPtr GetQDGlobalsPtr (void)
361{
362 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
363}
364
365#endif
366
367void 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
389void 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
401GrafPtr 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
411void UMADisposeWindow( WindowRef inWindowRef )
412{
413 wxASSERT( inWindowRef != NULL ) ;
414 DisposeWindow( inWindowRef ) ;
415}
416
417void UMASetWTitleC( WindowRef inWindowRef , const char *title )
418{
419 Str255 ptitle ;
420 strncpy( (char*)ptitle , title , 96 ) ;
421 ptitle[96] = 0 ;
03e11df5
GD
422#if TARGET_CARBON
423 c2pstrcpy( ptitle, (char *)ptitle ) ;
424#else
72e7876b 425 c2pstr( (char*)ptitle ) ;
03e11df5 426#endif
72e7876b
SC
427 SetWTitle( inWindowRef , ptitle ) ;
428}
03e11df5 429
72e7876b
SC
430void UMAGetWTitleC( WindowRef inWindowRef , char *title )
431{
432 GetWTitle( inWindowRef , (unsigned char*)title ) ;
03e11df5
GD
433#if TARGET_CARBON
434 p2cstrcpy( title, (unsigned char *)title ) ;
435#else
72e7876b 436 p2cstr( (unsigned char*)title ) ;
03e11df5 437#endif
72e7876b
SC
438}
439
440void UMAShowWindow( WindowRef inWindowRef )
441{
442 ShowWindow( inWindowRef ) ;
fdaf613a 443
72e7876b
SC
444}
445
446void UMAHideWindow( WindowRef inWindowRef )
447{
448 HideWindow( inWindowRef) ;
449}
450
451void UMASelectWindow( WindowRef inWindowRef )
452{
453 SelectWindow( inWindowRef ) ;
454}
455
456void UMABringToFront( WindowRef inWindowRef )
457{
458 BringToFront( inWindowRef ) ;
459}
460
461void UMASendBehind( WindowRef inWindowRef , WindowRef behindWindow )
462{
463 SendBehind( inWindowRef , behindWindow ) ;
464}
465
466void UMACloseWindow(WindowRef inWindowRef)
467{
468#if TARGET_CARBON
469#else
470 CloseWindow( inWindowRef ) ;
471#endif
472}
473
474// appearance additions
475
476void UMAActivateControl( ControlHandle inControl )
477{
2f1ae414 478#if UMA_USE_APPEARANCE
3f4902f5 479 if ( UMAHasAppearance() )
fdaf613a
SC
480 {
481 if ( !UMAIsControlActive( inControl ) )
482 {
483 bool visible = IsControlVisible( inControl ) ;
484 if ( visible )
485 SetControlVisibility( inControl , false , false ) ;
3f4902f5 486 ::ActivateControl( inControl ) ;
fdaf613a
SC
487 if ( visible ) {
488 SetControlVisibility( inControl , true , false ) ;
c36f0244
SC
489 Rect ctrlBounds ;
490 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
fdaf613a
SC
491 }
492 }
3f4902f5
GD
493 }
494 else
2f1ae414
SC
495#endif
496#if !TARGET_CARBON
3f4902f5
GD
497 {
498 AGAActivateControl( inControl ) ;
499 }
2f1ae414 500#else
3f4902f5
GD
501 {
502 }
503#endif
72e7876b
SC
504}
505
506void UMADrawControl( ControlHandle inControl )
507{
3f4902f5
GD
508 WindowRef theWindow = GetControlOwner(inControl) ;
509 RgnHandle updateRgn = NewRgn() ;
be57fda6 510#if TARGET_CARBON
3f4902f5
GD
511 GetWindowRegion( theWindow , kWindowUpdateRgn, updateRgn ) ;
512#else
513 GetWindowUpdateRgn( theWindow , updateRgn ) ;
514#endif
be57fda6
SC
515 Point zero = { 0 , 0 } ;
516 LocalToGlobal( &zero ) ;
517 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
2f1ae414 518#if UMA_USE_APPEARANCE
3f4902f5
GD
519 if ( UMAHasAppearance() )
520 {
521 ::DrawControlInCurrentPort( inControl ) ;
522 }
523 else
2f1ae414
SC
524#endif
525#if !TARGET_CARBON
3f4902f5
GD
526 {
527 AGADrawControl( inControl ) ;
528 }
2f1ae414 529#else
3f4902f5
GD
530 {
531 }
532#endif
65608e3b 533#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
3f4902f5
GD
534 InvalWindowRgn( theWindow, updateRgn) ;
535#else
536 InvalRgn( updateRgn ) ;
2f1ae414 537#endif
be57fda6
SC
538 DisposeRgn( updateRgn ) ;
539
72e7876b
SC
540}
541
542void UMAMoveControl( ControlHandle inControl , short x , short y )
543{
3f4902f5
GD
544 if ( UMAHasAppearance() )
545 {
fdaf613a
SC
546 bool visible = UMAIsControlVisible( inControl ) ;
547 if ( visible ) {
548 SetControlVisibility( inControl , false , false ) ;
c36f0244
SC
549 Rect ctrlBounds ;
550 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
fdaf613a 551 }
3f4902f5 552 ::MoveControl( inControl , x , y ) ;
fdaf613a
SC
553 if ( visible ) {
554 SetControlVisibility( inControl , true , false ) ;
c36f0244
SC
555 Rect ctrlBounds ;
556 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
fdaf613a 557 }
3f4902f5 558 }
72e7876b
SC
559}
560
561void UMASizeControl( ControlHandle inControl , short x , short y )
562{
3f4902f5
GD
563 if ( UMAHasAppearance() )
564 {
fdaf613a
SC
565 bool visible = UMAIsControlVisible( inControl ) ;
566 if ( visible ) {
567 SetControlVisibility( inControl , false , false ) ;
c36f0244
SC
568 Rect ctrlBounds ;
569 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
fdaf613a 570 }
3f4902f5 571 ::SizeControl( inControl , x , y ) ;
fdaf613a
SC
572 if ( visible ) {
573 SetControlVisibility( inControl , true , false ) ;
c36f0244
SC
574 Rect ctrlBounds ;
575 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
fdaf613a 576 }
3f4902f5 577 }
72e7876b
SC
578}
579
580void UMADeactivateControl( ControlHandle inControl )
581{
3f4902f5
GD
582 if ( UMAHasAppearance() )
583 {
fdaf613a
SC
584 if ( UMAIsControlActive( inControl ) )
585 {
586 bool visible = IsControlVisible( inControl ) ;
587 if ( visible )
588 SetControlVisibility( inControl , false , false ) ;
3f4902f5 589 ::DeactivateControl( inControl ) ;
fdaf613a
SC
590 if ( visible ) {
591 SetControlVisibility( inControl , true , false ) ;
c36f0244
SC
592 Rect ctrlBounds ;
593 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
fdaf613a
SC
594 }
595 }
3f4902f5 596 }
72e7876b
SC
597}
598
3f4902f5
GD
599void UMASetThemeWindowBackground (WindowRef inWindow,
600 ThemeBrush inBrush,
601 Boolean inUpdate)
2f1ae414
SC
602{
603#if UMA_USE_APPEARANCE
3f4902f5
GD
604 if ( UMAHasAppearance() )
605 {
606 ::SetThemeWindowBackground( inWindow ,inBrush , inUpdate ) ;
607 }
608 else
2f1ae414
SC
609#endif
610#if !TARGET_CARBON
3f4902f5
GD
611 {
612 AGASetThemeWindowBackground( inWindow , inBrush , inUpdate ) ;
613 }
2f1ae414 614#else
3f4902f5
GD
615 {
616 }
2f1ae414 617#endif
72e7876b
SC
618}
619
2f1ae414
SC
620void 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}
72e7876b 645
3f4902f5
GD
646ControlHandle 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)
72e7876b
SC
655{
656 ControlHandle theControl = NULL ;
2f1ae414 657#if UMA_USE_APPEARANCE
72e7876b
SC
658 if ( UMAHasAppearance() )
659 {
660 theControl = NewControl( owningWindow , boundsRect , controlTitle , initiallyVisible ,
661 initialValue , minimumValue , maximumValue , procID , controlReference ) ;
662 }
663 else
2f1ae414
SC
664#endif
665#if !TARGET_CARBON
72e7876b
SC
666 {
667 theControl = AGANewControl( owningWindow , boundsRect , controlTitle , initiallyVisible ,
668 initialValue , minimumValue , maximumValue , procID , controlReference ) ;
669 }
2f1ae414
SC
670#else
671 {
672 }
673#endif
72e7876b
SC
674 return theControl ;
675}
676
677void UMADisposeControl (ControlHandle theControl)
678{
3f4902f5
GD
679 if ( UMAHasAppearance() )
680 {
681 ::DisposeControl( theControl ) ;
682 }
683 else
684 {
685 ::DisposeControl( theControl ) ;
686 }
72e7876b
SC
687}
688
3f4902f5
GD
689void UMAHiliteControl (ControlHandle inControl,
690 ControlPartCode hiliteState)
691{
3f4902f5
GD
692 if ( UMAHasAppearance() )
693 {
694 ::HiliteControl( inControl , hiliteState ) ;
695 }
696 else
697 {
698 ::HiliteControl( inControl , hiliteState ) ;
699 }
72e7876b
SC
700}
701
fdaf613a 702// shows the control and adds the region to the update region
3f4902f5 703void UMAShowControl (ControlHandle inControl)
72e7876b 704{
3f4902f5
GD
705 if ( UMAHasAppearance() )
706 {
fdaf613a 707 SetControlVisibility( inControl , true , false ) ;
c36f0244
SC
708 Rect ctrlBounds ;
709 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
3f4902f5 710 }
72e7876b
SC
711}
712
fdaf613a 713// Hides the control and adds the region to the update region
3f4902f5 714void UMAHideControl (ControlHandle inControl)
72e7876b 715{
3f4902f5
GD
716 if ( UMAHasAppearance() )
717 {
718 ::HideControl( inControl ) ;
719 }
720 else
721 {
722 ::HideControl( inControl ) ;
723 }
72e7876b
SC
724}
725
726
727void UMASetControlVisibility (ControlHandle inControl,
728 Boolean inIsVisible,
729 Boolean inDoDraw)
3f4902f5
GD
730{
731 if ( UMAHasAppearance() )
732 {
2f1ae414 733#if UMA_USE_APPEARANCE
3f4902f5 734 ::SetControlVisibility( inControl , inIsVisible, inDoDraw ) ;
2f1ae414 735#endif
3f4902f5 736 }
72e7876b
SC
737}
738
739
740
741bool UMAIsControlActive (ControlHandle inControl)
742{
2f1ae414
SC
743#if TARGET_CARBON
744 return IsControlActive( inControl ) ;
745#else
746#if UMA_USE_APPEARANCE
72e7876b
SC
747 if ( UMAHasAppearance() )
748 {
749 return IsControlActive( inControl ) ;
750 }
751 else
2f1ae414 752#endif
72e7876b 753 return (**inControl).contrlHilite == 0 ;
2f1ae414 754#endif
72e7876b
SC
755}
756
757
758bool UMAIsControlVisible (ControlHandle inControl)
759{
2f1ae414 760#if UMA_USE_APPEARANCE
72e7876b
SC
761 if ( UMAHasAppearance() )
762 {
763 return IsControlVisible( inControl ) ;
764 }
fdaf613a 765 else
2f1ae414 766#endif
fdaf613a
SC
767 {
768#if !TARGET_CARBON
769 return (**inControl).contrlVis == 255 ;
770#endif
771 }
72e7876b
SC
772 return true ;
773}
774
775OSErr UMAGetBestControlRect (ControlHandle inControl,
776 Rect * outRect,
777 SInt16 * outBaseLineOffset)
778{
2f1ae414 779#if UMA_USE_APPEARANCE
72e7876b
SC
780 if ( UMAHasAppearance() )
781 {
782 return GetBestControlRect( inControl , outRect , outBaseLineOffset ) ;
783 }
784 else
2f1ae414
SC
785#endif
786#if !TARGET_CARBON
72e7876b
SC
787 {
788 return AGAGetBestControlRect( inControl , outRect , outBaseLineOffset ) ;
789 }
2f1ae414
SC
790#else
791 {
792 return noErr ;
793 }
794#endif
72e7876b
SC
795}
796
797
798OSErr UMASetControlFontStyle (ControlHandle inControl,
799 const ControlFontStyleRec * inStyle)
800{
2f1ae414 801#if UMA_USE_APPEARANCE
72e7876b
SC
802 if ( UMAHasAppearance() )
803 {
804 return ::SetControlFontStyle( inControl , inStyle ) ;
805 }
806 else
2f1ae414
SC
807#endif
808#if !TARGET_CARBON
72e7876b 809 return AGASetControlFontStyle( inControl , inStyle ) ;
2f1ae414
SC
810#else
811 {
812 return noErr ;
813 }
814#endif
72e7876b
SC
815}
816
817
818
819// control hierarchy
820
821OSErr UMACreateRootControl (WindowPtr inWindow,
822 ControlHandle * outControl)
823{
2f1ae414 824#if UMA_USE_APPEARANCE
72e7876b
SC
825 if ( UMAHasAppearance() )
826 {
827 return CreateRootControl( inWindow , outControl ) ;
828 }
829 else
2f1ae414
SC
830#endif
831#if !TARGET_CARBON
72e7876b 832 return AGACreateRootControl( inWindow , outControl ) ;
2f1ae414
SC
833#else
834 {
835 return noErr ;
836 }
837#endif
72e7876b
SC
838}
839
840
841
842OSErr UMAEmbedControl (ControlHandle inControl,
843 ControlHandle inContainer)
844{
2f1ae414 845#if UMA_USE_APPEARANCE
72e7876b
SC
846 if ( UMAHasAppearance() )
847 {
848 return EmbedControl( inControl , inContainer ) ;
849 }
850 else
2f1ae414
SC
851#endif
852#if !TARGET_CARBON
72e7876b 853 return AGAEmbedControl( inControl , inContainer ) ; ;
2f1ae414
SC
854#else
855 {
856 return noErr ;
857 }
858#endif
72e7876b
SC
859}
860
861
862
863// keyboard focus
864OSErr UMASetKeyboardFocus (WindowPtr inWindow,
865 ControlHandle inControl,
866 ControlFocusPart inPart)
867{
2f1ae414
SC
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
72e7876b
SC
878 if ( UMAHasAppearance() )
879 {
2f1ae414 880 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
72e7876b
SC
881 }
882 else
2f1ae414
SC
883#endif
884#if !TARGET_CARBON
885 err = AGASetKeyboardFocus( inWindow , inControl , inPart ) ;
886#else
887 {
888 }
889#endif
890 SetPort( port ) ;
891 return err ;
72e7876b
SC
892}
893
894
895
896
897// events
898
899ControlPartCode UMAHandleControlClick (ControlHandle inControl,
900 Point inWhere,
901 SInt16 inModifiers,
902 ControlActionUPP inAction)
903{
2f1ae414 904#if UMA_USE_APPEARANCE
72e7876b
SC
905 if ( UMAHasAppearance() )
906 {
907 return HandleControlClick( inControl , inWhere , inModifiers , inAction ) ;
908 }
909 else
2f1ae414
SC
910#endif
911#if !TARGET_CARBON
72e7876b
SC
912 {
913 return AGAHandleControlClick( inControl , inWhere , inModifiers , inAction ) ;
914 }
2f1ae414
SC
915#else
916 {
917 return noErr ;
918 }
919#endif
72e7876b
SC
920}
921
922
923SInt16 UMAHandleControlKey (ControlHandle inControl,
924 SInt16 inKeyCode,
925 SInt16 inCharCode,
926 SInt16 inModifiers)
927{
2f1ae414 928#if UMA_USE_APPEARANCE
72e7876b
SC
929 if ( UMAHasAppearance() )
930 {
931 return HandleControlKey( inControl , inKeyCode , inCharCode , inModifiers ) ;
932 }
933 else
2f1ae414
SC
934#endif
935#if !TARGET_CARBON
72e7876b
SC
936 {
937 return AGAHandleControlKey(inControl , inKeyCode , inCharCode , inModifiers ) ;
938 }
2f1ae414
SC
939#else
940 {
941 return noErr ;
942 }
943#endif
72e7876b
SC
944}
945
946
947
948void UMAIdleControls (WindowPtr inWindow)
949{
2f1ae414 950#if UMA_USE_APPEARANCE
72e7876b
SC
951 if ( UMAHasAppearance() )
952 {
953 IdleControls( inWindow ) ;
954 }
955 else
2f1ae414
SC
956#endif
957#if !TARGET_CARBON
72e7876b
SC
958 {
959 AGAIdleControls( inWindow ) ;
960 }
2f1ae414
SC
961#else
962 {
963 }
964#endif
72e7876b
SC
965}
966
967void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
968{
3f4902f5 969 RgnHandle updateRgn = NewRgn() ;
be57fda6 970#if TARGET_CARBON
3f4902f5
GD
971 GetWindowRegion( inWindow , kWindowUpdateRgn, updateRgn ) ;
972#else
973 GetWindowUpdateRgn( inWindow , updateRgn ) ;
974#endif
be57fda6
SC
975 Point zero = { 0 , 0 } ;
976 LocalToGlobal( &zero ) ;
977 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
2f1ae414 978#if UMA_USE_APPEARANCE
3f4902f5
GD
979 if ( UMAHasAppearance() )
980 {
981 UpdateControls( inWindow , inRgn ) ;
982 }
983 else
2f1ae414
SC
984#endif
985#if !TARGET_CARBON
3f4902f5
GD
986 {
987 AGAUpdateControls( inWindow , inRgn ) ;
988 }
2f1ae414 989#else
3f4902f5
GD
990 {
991 }
992#endif
65608e3b 993#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
3f4902f5
GD
994 InvalWindowRgn( inWindow, updateRgn) ;
995#else
996 InvalRgn( updateRgn ) ;
2f1ae414 997#endif
be57fda6
SC
998 DisposeRgn( updateRgn ) ;
999
72e7876b
SC
1000}
1001
1002OSErr UMAGetRootControl( WindowPtr inWindow , ControlHandle *outControl )
1003{
2f1ae414 1004#if UMA_USE_APPEARANCE
72e7876b
SC
1005 if ( UMAHasAppearance() )
1006 {
1007 return GetRootControl( inWindow , outControl ) ;
1008 }
1009 else
2f1ae414
SC
1010#endif
1011#if !TARGET_CARBON
72e7876b
SC
1012 {
1013 return AGAGetRootControl( inWindow , outControl ) ;
1014 }
2f1ae414
SC
1015#else
1016 {
1017 return noErr ;
1018 }
1019#endif
72e7876b
SC
1020}
1021
1022
1023// handling control data
1024
1025OSErr UMASetControlData (ControlHandle inControl,
1026 ControlPartCode inPart,
1027 ResType inTagName,
1028 Size inSize,
1029 Ptr inData)
1030{
2f1ae414 1031#if UMA_USE_APPEARANCE
72e7876b
SC
1032 if ( UMAHasAppearance() )
1033 {
1034 return SetControlData( inControl , inPart , inTagName , inSize , inData ) ;
1035 }
1036 else
2f1ae414
SC
1037#endif
1038#if !TARGET_CARBON
72e7876b 1039 return AGASetControlData( inControl , inPart , inTagName , inSize , inData ) ;
2f1ae414
SC
1040#else
1041 {
1042 return noErr ;
1043 }
1044#endif
72e7876b
SC
1045}
1046
1047
1048
1049OSErr UMAGetControlData (ControlHandle inControl,
1050 ControlPartCode inPart,
1051 ResType inTagName,
1052 Size inBufferSize,
1053 Ptr outBuffer,
1054 Size * outActualSize)
1055{
2f1ae414 1056#if UMA_USE_APPEARANCE
72e7876b
SC
1057 if ( UMAHasAppearance() )
1058 {
1059 return ::GetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ;
1060 }
1061 else
2f1ae414
SC
1062#endif
1063#if !TARGET_CARBON
72e7876b
SC
1064 {
1065 return AGAGetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ;
1066 }
2f1ae414
SC
1067#else
1068 {
1069 return noErr ;
1070 }
1071#endif
72e7876b
SC
1072}
1073
1074
1075OSErr UMAGetControlDataSize (ControlHandle inControl,
1076 ControlPartCode inPart,
1077 ResType inTagName,
1078 Size * outMaxSize)
1079{
2f1ae414 1080#if UMA_USE_APPEARANCE
72e7876b
SC
1081 if ( UMAHasAppearance() )
1082 {
1083 return GetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ;
1084 }
1085 else
2f1ae414
SC
1086#endif
1087#if !TARGET_CARBON
72e7876b
SC
1088 {
1089 return AGAGetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ;
1090 }
2f1ae414
SC
1091#else
1092 {
1093 return noErr ;
1094 }
1095#endif
72e7876b
SC
1096}
1097
1098
1099
1100
1101
1102// system 8.0 changes
1103
1104short UMAFindWindow( Point inPoint , WindowRef *outWindow )
1105{
1106 // todo add the additional area codes
1107 return FindWindow( inPoint , outWindow ) ;
1108}
1109
1110OSStatus 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
1119OSStatus 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
1128void UMADrawGrowIcon( WindowRef inWindowRef )
1129{
1130 DrawGrowIcon( inWindowRef ) ;
1131}
1132
1133OSStatus UMACollapseWindow( WindowRef inWindowRef , Boolean inCollapseIt )
1134{
1135 return CollapseWindow( inWindowRef , inCollapseIt ) ;
1136}
1137
1138OSStatus UMACollapseAllWindows( Boolean inCollapseEm )
1139{
1140 return CollapseAllWindows( inCollapseEm ) ;
1141}
1142
1143Boolean UMAIsWindowCollapsed( WindowRef inWindowRef )
1144{
1145 return IsWindowCollapsed( inWindowRef ) ;
1146}
1147
1148Boolean UMAIsWindowCollapsable( WindowRef inWindowRef )
1149{
1150 return IsWindowCollapsable( inWindowRef ) ;
1151}
1152
1153// system 8.5 changes<MacWindows.h>
1154OSStatus 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 ;
2f1ae414
SC
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 }
72e7876b 1216 break ;
2f1ae414 1217 case kDocumentWindowClass :
72e7876b 1218 default :
2f1ae414
SC
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 }
72e7876b
SC
1236 break ;
1237 }
1238 }
1239 else
1240 {
1241 switch( windowClass )
1242 {
1243 case kMovableModalWindowClass :
1244 procID = movableDBoxProc;
72e7876b 1245 break ;
2f1ae414
SC
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 }
72e7876b 1290 break ;
2f1ae414 1291 case kDocumentWindowClass :
72e7876b 1292 default :
2f1ae414
SC
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 ;
72e7876b
SC
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
1320OSStatus 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
1332OSStatus 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
1343void UMAShowFloatingWindows()
1344{
1345#if UMA_USE_WINDOWMGR
1346 if ( UMAHasWindowManager() )
1347 {
1348 ShowFloatingWindows() ;
1349 }
1350#endif
1351}
1352
1353void UMAHideFloatingWindows()
1354{
1355#if UMA_USE_WINDOWMGR
1356 if ( UMAHasWindowManager() )
1357 {
1358 HideFloatingWindows() ;
1359 }
1360#endif
1361}
1362
1363Boolean UMAAreFloatingWindowsVisible()
1364{
1365#if UMA_USE_WINDOWMGR
1366 if ( UMAHasWindowManager() )
1367 {
1368 return AreFloatingWindowsVisible() ;
1369 }
1370#endif
1371 return false ;
1372}
1373
1374WindowRef 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
1388WindowRef 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
1402WindowRef UMAGetActiveNonFloatingWindow()
1403{
1404 return NULL ;
1405}
1406
1407bool UMAIsWindowFloating( WindowRef inWindow )
1408{
1409 WindowClass cl ;
1410
1411 UMAGetWindowClass( inWindow , &cl ) ;
1412 return cl == kFloatingWindowClass ;
1413}
1414
1415bool UMAIsWindowModal( WindowRef inWindow )
1416{
1417 WindowClass cl ;
1418
1419 UMAGetWindowClass( inWindow , &cl ) ;
1420 return cl < kFloatingWindowClass ;
1421}
1422
1423// others
1424
1425void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
1426{
1427 if ( inWindowRef )
1428 {
1429// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
1430// if ( inActivate != isHightlited )
c809f3be
SC
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 ) ;
72e7876b
SC
1450 }
1451}
2f1ae414
SC
1452OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
1453{
1454#if UMA_USE_APPEARANCE
03e11df5
GD
1455 if ( UMAHasAppearance() )
1456 {
1457 ::DrawThemePlacard( inRect , inState ) ;
1458 }
1459 else
2f1ae414
SC
1460#endif
1461#if !TARGET_CARBON
03e11df5
GD
1462 {
1463 }
2f1ae414 1464#else
03e11df5
GD
1465 {
1466 }
2f1ae414 1467#endif
fdaf613a 1468 return noErr ;
2f1ae414 1469}
72e7876b 1470