]> git.saurik.com Git - wxWidgets.git/blob - src/mac/uma.cpp
small adaptions
[wxWidgets.git] / src / mac / uma.cpp
1 #include <wx/mac/uma.h>
2 #include <wx/mac/aga.h>
3
4 // init
5
6 static bool sUMAHasAppearance = false ;
7 static long sUMAAppearanceVersion = 0 ;
8 extern int gAGABackgroundColor ;
9 bool UMAHasAppearance() { return sUMAHasAppearance ; }
10 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; }
11
12 static bool sUMAHasWindowManager = false ;
13 static long sUMAWindowManagerAttr = 0 ;
14
15 bool UMAHasWindowManager() { return sUMAHasWindowManager ; }
16 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; }
17
18 void UMAInitToolbox( UInt16 inMoreMastersCalls )
19 {
20 #if !TARGET_CARBON
21 ::MaxApplZone();
22 for (long i = 1; i <= inMoreMastersCalls; i++)
23 ::MoreMasters();
24
25 ::InitGraf(&qd.thePort);
26 ::InitFonts();
27 ::InitWindows();
28 ::InitMenus();
29 ::TEInit();
30 ::InitDialogs(0L);
31 ::FlushEvents(everyEvent, 0);
32 ::InitCursor();
33 long total,contig;
34 PurgeSpace(&total, &contig);
35 #else
36 InitMenus() ;
37 #endif
38
39 #if UMA_USE_APPEARANCE
40 long theAppearance ;
41 if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr )
42 {
43 sUMAHasAppearance = true ;
44 RegisterAppearanceClient();
45 if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr )
46 {
47 sUMAAppearanceVersion = theAppearance ;
48 }
49 else
50 {
51 sUMAAppearanceVersion = 0x0100 ;
52 }
53 }
54 #endif // UMA_USE_APPEARANCE
55 #if UMA_USE_8_6
56 #if UMA_USE_WINDOWMGR
57 if ( Gestalt( gestaltWindowMgrAttr, &sUMAWindowManagerAttr ) == noErr )
58 {
59 sUMAHasWindowManager = sUMAWindowManagerAttr & gestaltWindowMgrPresent ;
60 }
61 #endif // UMA_USE_WINDOWMGR
62 #endif
63 }
64
65 // process manager
66 long UMAGetProcessMode()
67 {
68 OSErr err ;
69 ProcessInfoRec processinfo;
70 ProcessSerialNumber procno ;
71
72 procno.highLongOfPSN = NULL ;
73 procno.lowLongOfPSN = kCurrentProcess ;
74 processinfo.processInfoLength = sizeof(ProcessInfoRec);
75 processinfo.processName = NULL;
76 processinfo.processAppSpec = NULL;
77
78 err = ::GetProcessInformation( &procno , &processinfo ) ;
79 wxASSERT( err == noErr ) ;
80 return processinfo.processMode ;
81 }
82
83 bool UMAGetProcessModeDoesActivateOnFGSwitch()
84 {
85 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ;
86 }
87
88 // menu manager
89
90 void UMASetMenuTitle( MenuRef menu , ConstStr255Param title )
91 {
92 #if !TARGET_CARBON
93 long size = GetHandleSize( (Handle) menu ) ;
94 const long headersize = 14 ;
95 int oldlen = (**menu).menuData[0] + 1;
96 int newlen = title[0] + 1 ;
97
98 if ( oldlen < newlen )
99 {
100 // enlarge before adjusting
101 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
102 }
103
104 if ( oldlen != newlen )
105 memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
106
107 memcpy( (char*) (**menu).menuData , title , newlen ) ;
108 if ( oldlen > newlen )
109 {
110 // shrink after
111 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
112 }
113 #else
114 SetMenuTitle( menu , title ) ;
115 #endif
116 }
117
118 UInt32 UMAMenuEvent( EventRecord *inEvent )
119 {
120 if ( UMAHasAppearance() )
121 {
122 return MenuEvent( inEvent ) ;
123 }
124 else
125 {
126 if ( inEvent->what == keyDown && inEvent->modifiers & cmdKey)
127 {
128 return MenuKey( inEvent->message & charCodeMask ) ;
129 }
130 return NULL ;
131 }
132 }
133
134 void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
135 {
136 #if UMA_USE_8_6
137 EnableMenuItem( inMenu , inItem ) ;
138 #else
139 EnableItem( inMenu , inItem ) ;
140 #endif
141 }
142
143 void UMADisableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
144 {
145 #if UMA_USE_8_6
146 DisableMenuItem( inMenu , inItem ) ;
147 #else
148 DisableItem( inMenu , inItem ) ;
149 #endif
150 }
151 // quickdraw
152
153 #if !TARGET_CARBON
154
155 pascal QDGlobalsPtr GetQDGlobalsPtr (void)
156 {
157 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
158 }
159
160 #endif
161
162 void UMAShowWatchCursor()
163 {
164 OSErr err = noErr;
165
166 CursHandle watchFob = GetCursor (watchCursor);
167
168 if (!watchFob)
169 err = nilHandleErr;
170 else
171 {
172 #if TARGET_CARBON
173 Cursor preservedArrow;
174 GetQDGlobalsArrow (&preservedArrow);
175 SetQDGlobalsArrow (*watchFob);
176 InitCursor ( );
177 SetQDGlobalsArrow (&preservedArrow);
178 #else
179 SetCursor (*watchFob);
180 #endif
181 }
182 }
183
184 void UMAShowArrowCursor()
185 {
186 #if TARGET_CARBON
187 Cursor arrow;
188 SetCursor (GetQDGlobalsArrow (&arrow));
189 #else
190 SetCursor (&(qd.arrow));
191 #endif
192 }
193
194 // window manager
195
196 GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
197 {
198 wxASSERT( inWindowRef != NULL ) ;
199 #if TARGET_CARBON
200 return GetWindowPort( inWindowRef ) ;
201 #else
202 return (GrafPtr) inWindowRef ;
203 #endif
204 }
205
206 void UMADisposeWindow( WindowRef inWindowRef )
207 {
208 wxASSERT( inWindowRef != NULL ) ;
209 DisposeWindow( inWindowRef ) ;
210 }
211
212 void UMASetWTitleC( WindowRef inWindowRef , const char *title )
213 {
214 Str255 ptitle ;
215 strncpy( (char*)ptitle , title , 96 ) ;
216 ptitle[96] = 0 ;
217 c2pstr( (char*)ptitle ) ;
218 SetWTitle( inWindowRef , ptitle ) ;
219 }
220 void UMAGetWTitleC( WindowRef inWindowRef , char *title )
221 {
222 GetWTitle( inWindowRef , (unsigned char*)title ) ;
223 p2cstr( (unsigned char*)title ) ;
224 }
225
226 void UMAShowWindow( WindowRef inWindowRef )
227 {
228 ShowWindow( inWindowRef ) ;
229 }
230
231 void UMAHideWindow( WindowRef inWindowRef )
232 {
233 HideWindow( inWindowRef) ;
234 }
235
236 void UMASelectWindow( WindowRef inWindowRef )
237 {
238 SelectWindow( inWindowRef ) ;
239 }
240
241 void UMABringToFront( WindowRef inWindowRef )
242 {
243 BringToFront( inWindowRef ) ;
244 }
245
246 void UMASendBehind( WindowRef inWindowRef , WindowRef behindWindow )
247 {
248 SendBehind( inWindowRef , behindWindow ) ;
249 }
250
251 void UMACloseWindow(WindowRef inWindowRef)
252 {
253 #if TARGET_CARBON
254 #else
255 CloseWindow( inWindowRef ) ;
256 #endif
257 }
258
259 // appearance additions
260
261 void UMAActivateControl( ControlHandle inControl )
262 {
263 if ( UMAHasAppearance() )
264 {
265 ::ActivateControl( inControl ) ;
266 }
267 else
268 {
269 AGAActivateControl( inControl ) ;
270 }
271 }
272
273 void UMADrawControl( ControlHandle inControl )
274 {
275 if ( UMAHasAppearance() )
276 {
277 ::DrawControlInCurrentPort( inControl ) ;
278 }
279 else
280 {
281 AGADrawControl( inControl ) ;
282 }
283 }
284
285 void UMAMoveControl( ControlHandle inControl , short x , short y )
286 {
287 if ( UMAHasAppearance() )
288 {
289 ::MoveControl( inControl , x , y ) ;
290 }
291 else
292 {
293 AGAMoveControl( inControl , x ,y ) ;
294 }
295 }
296
297 void UMASizeControl( ControlHandle inControl , short x , short y )
298 {
299 if ( UMAHasAppearance() )
300 {
301 ::SizeControl( inControl , x , y ) ;
302 }
303 else
304 {
305 AGASizeControl( inControl , x ,y ) ;
306 }
307 }
308
309 void UMADeactivateControl( ControlHandle inControl )
310 {
311 if ( UMAHasAppearance() )
312 {
313 ::DeactivateControl( inControl ) ;
314 }
315 else
316 {
317 AGADeactivateControl( inControl ) ;
318 }
319 }
320
321 void UMASetThemeWindowBackground (WindowRef inWindow,
322 ThemeBrush inBrush,
323 Boolean inUpdate){
324 if ( UMAHasAppearance() )
325 {
326 ::SetThemeWindowBackground( inWindow ,inBrush , inUpdate ) ;
327 }
328 else
329 {
330 AGASetThemeWindowBackground( inWindow , inBrush , inUpdate ) ;
331 }
332 }
333
334
335 ControlHandle UMANewControl(WindowPtr owningWindow,
336 const Rect * boundsRect,
337 ConstStr255Param controlTitle,
338 Boolean initiallyVisible,
339 SInt16 initialValue,
340 SInt16 minimumValue,
341 SInt16 maximumValue,
342 SInt16 procID,
343 SInt32 controlReference)
344 {
345 ControlHandle theControl = NULL ;
346 if ( UMAHasAppearance() )
347 {
348 theControl = NewControl( owningWindow , boundsRect , controlTitle , initiallyVisible ,
349 initialValue , minimumValue , maximumValue , procID , controlReference ) ;
350 }
351 else
352 {
353 theControl = AGANewControl( owningWindow , boundsRect , controlTitle , initiallyVisible ,
354 initialValue , minimumValue , maximumValue , procID , controlReference ) ;
355 }
356 return theControl ;
357 }
358
359 void UMADisposeControl (ControlHandle theControl)
360 {
361 if ( UMAHasAppearance() )
362 {
363 ::DisposeControl( theControl ) ;
364 }
365 else
366 {
367 ::DisposeControl( theControl ) ;
368 }
369 }
370
371
372 void UMAHiliteControl (ControlHandle theControl,
373 ControlPartCode hiliteState)
374 {
375 if ( UMAHasAppearance() )
376 {
377 ::HiliteControl( theControl , hiliteState ) ;
378 }
379 else
380 {
381 ::HiliteControl( theControl , hiliteState ) ;
382 }
383 }
384
385
386 void UMAShowControl (ControlHandle theControl)
387 {
388 if ( UMAHasAppearance() )
389 {
390 ::ShowControl( theControl ) ;
391 }
392 else
393 {
394 ::ShowControl( theControl ) ;
395 }
396 }
397
398
399 void UMAHideControl (ControlHandle theControl)
400 {
401 if ( UMAHasAppearance() )
402 {
403 ::HideControl( theControl ) ;
404 }
405 else
406 {
407 ::HideControl( theControl ) ;
408 }
409 }
410
411
412 void UMASetControlVisibility (ControlHandle inControl,
413 Boolean inIsVisible,
414 Boolean inDoDraw)
415 {
416 if ( UMAHasAppearance() )
417 {
418 ::SetControlVisibility( inControl , inIsVisible, inDoDraw ) ;
419 }
420 }
421
422
423
424 bool UMAIsControlActive (ControlHandle inControl)
425 {
426 if ( UMAHasAppearance() )
427 {
428 return IsControlActive( inControl ) ;
429 }
430 else
431 return (**inControl).contrlHilite == 0 ;
432 }
433
434
435 bool UMAIsControlVisible (ControlHandle inControl)
436 {
437 if ( UMAHasAppearance() )
438 {
439 return IsControlVisible( inControl ) ;
440 }
441 return true ;
442 }
443
444 OSErr UMAGetBestControlRect (ControlHandle inControl,
445 Rect * outRect,
446 SInt16 * outBaseLineOffset)
447 {
448 if ( UMAHasAppearance() )
449 {
450 return GetBestControlRect( inControl , outRect , outBaseLineOffset ) ;
451 }
452 else
453 {
454 return AGAGetBestControlRect( inControl , outRect , outBaseLineOffset ) ;
455 }
456 }
457
458
459 OSErr UMASetControlFontStyle (ControlHandle inControl,
460 const ControlFontStyleRec * inStyle)
461 {
462 if ( UMAHasAppearance() )
463 {
464 return ::SetControlFontStyle( inControl , inStyle ) ;
465 }
466 else
467 return AGASetControlFontStyle( inControl , inStyle ) ;
468 }
469
470
471
472 // control hierarchy
473
474 OSErr UMACreateRootControl (WindowPtr inWindow,
475 ControlHandle * outControl)
476 {
477 if ( UMAHasAppearance() )
478 {
479 return CreateRootControl( inWindow , outControl ) ;
480 }
481 else
482 return AGACreateRootControl( inWindow , outControl ) ;
483 }
484
485
486
487 OSErr UMAEmbedControl (ControlHandle inControl,
488 ControlHandle inContainer)
489 {
490 if ( UMAHasAppearance() )
491 {
492 return EmbedControl( inControl , inContainer ) ;
493 }
494 else
495 return AGAEmbedControl( inControl , inContainer ) ; ;
496 }
497
498
499
500 // keyboard focus
501 OSErr UMASetKeyboardFocus (WindowPtr inWindow,
502 ControlHandle inControl,
503 ControlFocusPart inPart)
504 {
505 if ( UMAHasAppearance() )
506 {
507 return SetKeyboardFocus( inWindow , inControl , inPart ) ;
508 }
509 else
510 return AGASetKeyboardFocus( inWindow , inControl , inPart ) ;
511 }
512
513
514
515
516 // events
517
518 ControlPartCode UMAHandleControlClick (ControlHandle inControl,
519 Point inWhere,
520 SInt16 inModifiers,
521 ControlActionUPP inAction)
522 {
523 if ( UMAHasAppearance() )
524 {
525 return HandleControlClick( inControl , inWhere , inModifiers , inAction ) ;
526 }
527 else
528 {
529 return AGAHandleControlClick( inControl , inWhere , inModifiers , inAction ) ;
530 }
531 }
532
533
534 SInt16 UMAHandleControlKey (ControlHandle inControl,
535 SInt16 inKeyCode,
536 SInt16 inCharCode,
537 SInt16 inModifiers)
538 {
539 if ( UMAHasAppearance() )
540 {
541 return HandleControlKey( inControl , inKeyCode , inCharCode , inModifiers ) ;
542 }
543 else
544 {
545 return AGAHandleControlKey(inControl , inKeyCode , inCharCode , inModifiers ) ;
546 }
547 }
548
549
550
551 void UMAIdleControls (WindowPtr inWindow)
552 {
553 if ( UMAHasAppearance() )
554 {
555 IdleControls( inWindow ) ;
556 }
557 else
558 {
559 AGAIdleControls( inWindow ) ;
560 }
561 }
562
563 void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
564 {
565 if ( UMAHasAppearance() )
566 {
567 UpdateControls( inWindow , inRgn ) ;
568 }
569 else
570 {
571 AGAUpdateControls( inWindow , inRgn ) ;
572 }
573 }
574
575 OSErr UMAGetRootControl( WindowPtr inWindow , ControlHandle *outControl )
576 {
577 if ( UMAHasAppearance() )
578 {
579 return GetRootControl( inWindow , outControl ) ;
580 }
581 else
582 {
583 return AGAGetRootControl( inWindow , outControl ) ;
584 }
585 }
586
587
588 // handling control data
589
590 OSErr UMASetControlData (ControlHandle inControl,
591 ControlPartCode inPart,
592 ResType inTagName,
593 Size inSize,
594 Ptr inData)
595 {
596 if ( UMAHasAppearance() )
597 {
598 return SetControlData( inControl , inPart , inTagName , inSize , inData ) ;
599 }
600 else
601 return AGASetControlData( inControl , inPart , inTagName , inSize , inData ) ;
602 }
603
604
605
606 OSErr UMAGetControlData (ControlHandle inControl,
607 ControlPartCode inPart,
608 ResType inTagName,
609 Size inBufferSize,
610 Ptr outBuffer,
611 Size * outActualSize)
612 {
613 if ( UMAHasAppearance() )
614 {
615 return ::GetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ;
616 }
617 else
618 {
619 return AGAGetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ;
620 }
621
622 }
623
624
625 OSErr UMAGetControlDataSize (ControlHandle inControl,
626 ControlPartCode inPart,
627 ResType inTagName,
628 Size * outMaxSize)
629 {
630 if ( UMAHasAppearance() )
631 {
632 return GetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ;
633 }
634 else
635 {
636 return AGAGetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ;
637 }
638 }
639
640
641
642
643
644 // system 8.0 changes
645
646 short UMAFindWindow( Point inPoint , WindowRef *outWindow )
647 {
648 // todo add the additional area codes
649 return FindWindow( inPoint , outWindow ) ;
650 }
651
652 OSStatus UMAGetWindowFeatures( WindowRef inWindowRef , UInt32 *outFeatures )
653 {
654 #if UMA_USE_WINDOWMGR
655 return GetWindowFeatures( inWindowRef , outFeatures ) ;
656 #else
657 return 0 ;
658 #endif
659 }
660
661 OSStatus UMAGetWindowRegion( WindowRef inWindowRef , WindowRegionCode inRegionCode , RgnHandle ioWinRgn )
662 {
663 #if UMA_USE_WINDOWMGR
664 return GetWindowRegion( inWindowRef , inRegionCode , ioWinRgn ) ;
665 #else
666 return 0 ;
667 #endif
668 }
669
670 void UMADrawGrowIcon( WindowRef inWindowRef )
671 {
672 DrawGrowIcon( inWindowRef ) ;
673 }
674
675 OSStatus UMACollapseWindow( WindowRef inWindowRef , Boolean inCollapseIt )
676 {
677 return CollapseWindow( inWindowRef , inCollapseIt ) ;
678 }
679
680 OSStatus UMACollapseAllWindows( Boolean inCollapseEm )
681 {
682 return CollapseAllWindows( inCollapseEm ) ;
683 }
684
685 Boolean UMAIsWindowCollapsed( WindowRef inWindowRef )
686 {
687 return IsWindowCollapsed( inWindowRef ) ;
688 }
689
690 Boolean UMAIsWindowCollapsable( WindowRef inWindowRef )
691 {
692 return IsWindowCollapsable( inWindowRef ) ;
693 }
694
695 // system 8.5 changes<MacWindows.h>
696 OSStatus UMACreateNewWindow( WindowClass windowClass , WindowAttributes attributes , const Rect *bounds, WindowRef *outWindow )
697 {
698 #if UMA_USE_WINDOWMGR
699 if ( UMAHasWindowManager() )
700 {
701 return CreateNewWindow( windowClass , attributes, bounds, outWindow ) ;
702 }
703 else
704 #endif
705 {
706 short procID ;
707 if ( UMAHasAppearance() )
708 {
709 switch( windowClass )
710 {
711 case kMovableModalWindowClass :
712 procID = kWindowMovableModalDialogProc;
713 break ;
714 case kDocumentWindowClass :
715 procID = kWindowFullZoomGrowDocumentProc;
716 break ;
717 default :
718 procID = kWindowMovableModalDialogProc;
719 break ;
720 }
721 }
722 else
723 {
724 switch( windowClass )
725 {
726 case kMovableModalWindowClass :
727 procID = movableDBoxProc;
728 // procID += kMovableModalDialogVariantCode;
729 break ;
730 case kDocumentWindowClass :
731 procID = zoomDocProc;
732 break ;
733 default :
734 procID = documentProc;
735 break ;
736 }
737 }
738 *outWindow = NewCWindow(nil, bounds, "\p", false, procID, (WindowRef) -1 /*behind*/,
739 attributes & kWindowCloseBoxAttribute , (long)NULL);
740 return noErr ;
741 }
742 }
743
744 OSStatus UMAGetWindowClass( WindowRef inWindowRef , WindowClass *outWindowClass )
745 {
746 #if UMA_USE_WINDOWMGR
747 if ( UMAHasWindowManager() )
748 {
749 return GetWindowClass( inWindowRef , outWindowClass ) ;
750 }
751 else
752 #endif
753 return kDocumentWindowClass ;
754 }
755
756 OSStatus UMAGetWindowAttributes( WindowRef inWindowRef , WindowAttributes *outAttributes )
757 {
758 #if UMA_USE_WINDOWMGR
759 if ( UMAHasWindowManager() )
760 {
761 return GetWindowAttributes( inWindowRef , outAttributes ) ;
762 }
763 #endif
764 return kWindowNoAttributes ;
765 }
766
767 void UMAShowFloatingWindows()
768 {
769 #if UMA_USE_WINDOWMGR
770 if ( UMAHasWindowManager() )
771 {
772 ShowFloatingWindows() ;
773 }
774 #endif
775 }
776
777 void UMAHideFloatingWindows()
778 {
779 #if UMA_USE_WINDOWMGR
780 if ( UMAHasWindowManager() )
781 {
782 HideFloatingWindows() ;
783 }
784 #endif
785 }
786
787 Boolean UMAAreFloatingWindowsVisible()
788 {
789 #if UMA_USE_WINDOWMGR
790 if ( UMAHasWindowManager() )
791 {
792 return AreFloatingWindowsVisible() ;
793 }
794 #endif
795 return false ;
796 }
797
798 WindowRef UMAFrontNonFloatingWindow()
799 {
800 #if UMA_USE_WINDOWMGR
801 if ( UMAHasWindowManager() )
802 {
803 return FrontNonFloatingWindow() ;
804 }
805 else
806 #endif
807 {
808 return FrontWindow() ;
809 }
810 }
811
812 WindowRef UMAFrontWindow()
813 {
814 #if UMA_USE_WINDOWMGR
815 if ( UMAHasWindowManager() )
816 {
817 return FrontWindow() ;
818 }
819 else
820 #endif
821 {
822 return FrontWindow() ;
823 }
824 }
825
826 WindowRef UMAGetActiveNonFloatingWindow()
827 {
828 return NULL ;
829 }
830
831 bool UMAIsWindowFloating( WindowRef inWindow )
832 {
833 WindowClass cl ;
834
835 UMAGetWindowClass( inWindow , &cl ) ;
836 return cl == kFloatingWindowClass ;
837 }
838
839 bool UMAIsWindowModal( WindowRef inWindow )
840 {
841 WindowClass cl ;
842
843 UMAGetWindowClass( inWindow , &cl ) ;
844 return cl < kFloatingWindowClass ;
845 }
846
847 // others
848
849 void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
850 {
851 if ( inWindowRef )
852 {
853 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
854 // if ( inActivate != isHightlited )
855 HiliteWindow( inWindowRef , inActivate ) ;
856 }
857 }
858