]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/uma.cpp
include wxWindows headers using "..." instead of <...>
[wxWidgets.git] / src / mac / carbon / uma.cpp
index f95b4c52bd0425d79cc228e962f2fdebd140d47f..2c70ef47b762087471d27444223f1671164acb1b 100644 (file)
@@ -1,11 +1,20 @@
-#include <wx/mac/uma.h>
-#include <wx/mac/aga.h>
+#include "wx/defs.h"
+#include "wx/dc.h"
+#include "wx/mac/uma.h"
+#include "wx/mac/aga.h"
 
-
-#include "Navigation.h"
+#ifndef __DARWIN__
+  #include <Navigation.h>
+#endif
 
 // init
 
+#if !TARGET_CARBON
+#define        GetControlOwner( control ) (**control).contrlOwner
+// since we always call this in the right context we don't have to set and reset the port
+#define InvalWindowRgn( window , rgn ) InvalRgn( rgn )
+#endif
+
 static bool    sUMAHasAppearance = false ;
 static long sUMAAppearanceVersion = 0 ;
 extern int gAGABackgroundColor ;
@@ -75,10 +84,16 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls )
 #endif // UMA_USE_WINDOWMGR
 #endif
                
+#ifndef __DARWIN__
+#if TARGET_CARBON
+// Call currently implicitely done :           InitFloatingWindows() ;
+#else
        if ( sUMAHasWindowManager )
                InitFloatingWindows() ;
        else
                InitWindows();
+#endif
+#endif
 
        if ( NavServicesAvailable() )
        {
@@ -274,7 +289,11 @@ void UMAInsertMenu( MenuRef insertMenu , SInt16 afterId )
 
 int gPrOpenCounter = 0 ;
 
-OSStatus UMAPrOpen() 
+#if TARGET_CARBON && PM_USE_SESSION_APIS
+OSStatus UMAPrOpen(PMPrintSession *macPrintSession)
+#else
+OSStatus UMAPrOpen()
+#endif
 {
 #if !TARGET_CARBON
        OSErr err = noErr ;
@@ -291,14 +310,22 @@ OSStatus UMAPrOpen()
        ++gPrOpenCounter ;
        if ( gPrOpenCounter == 1 )
        {
-               err = PMBegin() ;
+  #if PM_USE_SESSION_APIS
+           err = PMCreateSession(macPrintSession) ;
+  #else
+           err = PMBegin() ;
+  #endif
                wxASSERT( err == noErr ) ;
        }
        return err ;
 #endif
 }
 
-OSStatus UMAPrClose() 
+#if TARGET_CARBON && PM_USE_SESSION_APIS
+OSStatus UMAPrClose(PMPrintSession *macPrintSession)
+#else
+OSStatus UMAPrClose()
+#endif
 {
 #if !TARGET_CARBON
        OSErr err = noErr ;
@@ -316,7 +343,12 @@ OSStatus UMAPrClose()
        wxASSERT( gPrOpenCounter >= 1 ) ;
        if ( gPrOpenCounter == 1 )
        {
-               err = PMEnd() ;
+  #if PM_USE_SESSION_APIS
+           err = PMRelease(*macPrintSession) ;
+           *macPrintSession = kPMNoReference;
+  #else
+           err = PMEnd() ;
+  #endif
        }
        --gPrOpenCounter ;
        return err ;
@@ -387,18 +419,28 @@ void                      UMASetWTitleC( WindowRef inWindowRef , const char *title )
        Str255  ptitle ;
        strncpy( (char*)ptitle , title , 96 ) ;
        ptitle[96] = 0 ;
+#if TARGET_CARBON
+       c2pstrcpy( ptitle, (char *)ptitle ) ;
+#else
        c2pstr( (char*)ptitle ) ;
+#endif
        SetWTitle( inWindowRef , ptitle ) ;
 }
+
 void                   UMAGetWTitleC( WindowRef inWindowRef , char *title ) 
 {
        GetWTitle( inWindowRef , (unsigned char*)title ) ;
+#if TARGET_CARBON
+       p2cstrcpy( title, (unsigned char *)title ) ;
+#else
        p2cstr( (unsigned char*)title ) ;
+#endif
 }
 
 void                   UMAShowWindow( WindowRef inWindowRef ) 
 {
        ShowWindow( inWindowRef ) ;
+
 }
 
 void                   UMAHideWindow( WindowRef inWindowRef ) 
@@ -434,116 +476,144 @@ void                    UMACloseWindow(WindowRef inWindowRef)
 void UMAActivateControl( ControlHandle inControl ) 
 {
 #if UMA_USE_APPEARANCE
-       if ( UMAHasAppearance() )
-       {
-       ::ActivateControl( inControl ) ;
-   }
-   else
+    if ( UMAHasAppearance() )
+    { 
+      if ( !UMAIsControlActive( inControl ) )
+      {
+        bool visible = IsControlVisible( inControl ) ;
+        if ( visible )
+          SetControlVisibility( inControl , false , false ) ;
+        ::ActivateControl( inControl ) ;
+        if ( visible ) {
+          SetControlVisibility( inControl , true , false ) ;
+          Rect ctrlBounds ;
+          InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
+        }
+       }
+    }
+    else
 #endif
 #if !TARGET_CARBON
-   {
-       AGAActivateControl( inControl ) ;
-   }
+    {
+        AGAActivateControl( inControl ) ;
+    }
 #else
-       {
-       }
+    {
+    }
 #endif
 }
 
 void UMADrawControl( ControlHandle inControl ) 
 {
+    WindowRef theWindow = GetControlOwner(inControl) ;
+    RgnHandle updateRgn = NewRgn() ;
+#if TARGET_CARBON
+    GetWindowRegion( theWindow , kWindowUpdateRgn, updateRgn ) ;
+#else
+    GetWindowUpdateRgn( theWindow , updateRgn ) ;
+#endif
+       Point zero = { 0 , 0 } ;
+       LocalToGlobal( &zero ) ;
+       OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
 #if UMA_USE_APPEARANCE
-       if ( UMAHasAppearance() )
-       {
-       ::DrawControlInCurrentPort( inControl ) ;
-   }
-   else
+    if ( UMAHasAppearance() )
+    {
+        ::DrawControlInCurrentPort( inControl ) ;
+    }
+    else
 #endif
 #if !TARGET_CARBON
-   {
-       AGADrawControl( inControl ) ;
-   }
+    {
+        AGADrawControl( inControl ) ;
+    }
 #else
-       {
-       }
+    {
+    }
+#endif
+#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
+    InvalWindowRgn( theWindow, updateRgn) ;
+#else
+    InvalRgn( updateRgn ) ;
 #endif
+       DisposeRgn( updateRgn ) ;
+
 }
 
 void UMAMoveControl( ControlHandle inControl , short x , short y ) 
 {
-#if UMA_USE_APPEARANCE
-       if ( UMAHasAppearance() )
-       {
-               ::MoveControl( inControl , x , y ) ;
-   }
-   else
-#endif
-#if !TARGET_CARBON
-   {
-       AGAMoveControl( inControl , x ,y  ) ;
-   }
-#else
-       {
-       }
-#endif
+    if ( UMAHasAppearance() )
+    {
+        bool visible = UMAIsControlVisible( inControl ) ;
+        if ( visible ) {
+          SetControlVisibility( inControl , false , false ) ;
+          Rect ctrlBounds ;
+          InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
+        }
+        ::MoveControl( inControl , x , y ) ;
+        if ( visible ) {
+          SetControlVisibility( inControl , true , false ) ;
+          Rect ctrlBounds ;
+          InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
+        }
+    }
 }
 
 void UMASizeControl( ControlHandle inControl , short x , short y ) 
 {
-#if UMA_USE_APPEARANCE
-       if ( UMAHasAppearance() )
-       {
-               ::SizeControl( inControl , x , y ) ;
-   }
-   else
-#endif
-#if !TARGET_CARBON
-   {
-       AGASizeControl( inControl , x ,y  ) ;
-   }
-#else
-       {
-       }
-#endif
+    if ( UMAHasAppearance() )
+    {
+        bool visible = UMAIsControlVisible( inControl ) ;
+        if ( visible ) {
+          SetControlVisibility( inControl , false , false ) ;
+          Rect ctrlBounds ;
+          InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
+        }
+        ::SizeControl( inControl , x , y ) ;
+        if ( visible ) {
+          SetControlVisibility( inControl , true , false ) ;
+          Rect ctrlBounds ;
+          InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
+        }
+    }
 }
 
 void UMADeactivateControl( ControlHandle inControl ) 
 {
-#if UMA_USE_APPEARANCE
-       if ( UMAHasAppearance() )
-       {
-       ::DeactivateControl( inControl ) ;
-   }
-   else
-#endif
-#if !TARGET_CARBON
-   {
-        AGADeactivateControl( inControl ) ;
-   }
-#else
-       {
-       }
-#endif
-}
-
-void                   UMASetThemeWindowBackground             (WindowRef                              inWindow,
-                                                                ThemeBrush                     inBrush,
-                                                                Boolean                                inUpdate)
+    if ( UMAHasAppearance() )
+    {
+      if ( UMAIsControlActive( inControl ) )
+      {
+        bool visible = IsControlVisible( inControl ) ;
+        if ( visible )
+          SetControlVisibility( inControl , false , false ) ;
+        ::DeactivateControl( inControl ) ;
+        if ( visible ) {
+          SetControlVisibility( inControl , true , false ) ;
+          Rect ctrlBounds ;
+          InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
+        }
+       }
+    }
+}
+
+void UMASetThemeWindowBackground              (WindowRef                               inWindow,
+                                               ThemeBrush                      inBrush,
+                                               Boolean                                 inUpdate)
 {
 #if UMA_USE_APPEARANCE
-       if ( UMAHasAppearance() )
-       {
-       ::SetThemeWindowBackground( inWindow ,inBrush , inUpdate ) ;
-   }
-   else
+    if ( UMAHasAppearance() )
+    {
+        ::SetThemeWindowBackground( inWindow ,inBrush , inUpdate ) ;
+    }
+    else
 #endif
 #if !TARGET_CARBON
-   {
-       AGASetThemeWindowBackground( inWindow , inBrush , inUpdate ) ;
-   }
+    {
+        AGASetThemeWindowBackground( inWindow , inBrush , inUpdate ) ;
+    }
 #else
-       {
-       }
+    {
+    }
 #endif
 }
 
@@ -573,15 +643,15 @@ void                      UMAApplyThemeBackground                 (ThemeBackgroundKind    inKind,
 #endif
 }
 
-ControlHandle UMANewControl(WindowPtr                          owningWindow,
-                                                                const Rect *                   boundsRect,
-                                                                ConstStr255Param               controlTitle,
-                                                                Boolean                                initiallyVisible,
-                                                                SInt16                                 initialValue,
-                                                                SInt16                                 minimumValue,
-                                                                SInt16                                 maximumValue,
-                                                                SInt16                                 procID,
-                                                                SInt32                                 controlReference)
+ControlHandle UMANewControl(WindowPtr                  owningWindow,
+                           const Rect *                boundsRect,
+                           ConstStr255Param            controlTitle,
+                           Boolean                     initiallyVisible,
+                           SInt16                      initialValue,
+                           SInt16                      minimumValue,
+                           SInt16                      maximumValue,
+                           SInt16                      procID,
+                           SInt32                      controlReference)
 {
        ControlHandle theControl = NULL ;
 #if UMA_USE_APPEARANCE
@@ -606,67 +676,64 @@ ControlHandle UMANewControl(WindowPtr                             owningWindow,
 
 void UMADisposeControl (ControlHandle                  theControl)
 {
-       if ( UMAHasAppearance() )
-       {
-       ::DisposeControl( theControl ) ;
-   }
-   else
-   {
-       ::DisposeControl( theControl ) ;
-   }
+    if ( UMAHasAppearance() )
+    {
+        ::DisposeControl( theControl ) ;
+    }
+    else
+    {
+        ::DisposeControl( theControl ) ;
+    }
 }
 
-
-void UMAHiliteControl  (ControlHandle                  theControl,
-                                                                ControlPartCode                hiliteState)
-                                                                {
-       if ( UMAHasAppearance() )
-       {
-       ::HiliteControl( theControl , hiliteState ) ;
-   }
-   else
-   {
-       ::HiliteControl( theControl , hiliteState ) ;
-       }
+void UMAHiliteControl  (ControlHandle                  inControl,
+                        ControlPartCode                hiliteState)
+{
+    if ( UMAHasAppearance() )
+    {
+        ::HiliteControl( inControl , hiliteState ) ;
+    }
+    else
+    {
+        ::HiliteControl( inControl , hiliteState ) ;
+    }
 }
 
-
-void UMAShowControl                                            (ControlHandle                  theControl)
+// shows the control and adds the region to the update region
+void UMAShowControl                                            (ControlHandle                  inControl)
 {
-       if ( UMAHasAppearance() )
-       {
-       ::ShowControl( theControl ) ;
-   }
-   else
-   {
-       ::ShowControl( theControl ) ;
-   }
+    if ( UMAHasAppearance() )
+    {
+        SetControlVisibility( inControl , true , false ) ;
+        Rect ctrlBounds ;
+        InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
+    }
 }
 
-
-void UMAHideControl                                            (ControlHandle                  theControl)
+// Hides the control and adds the region to the update region
+void UMAHideControl                                            (ControlHandle                  inControl)
 {
-       if ( UMAHasAppearance() )
-       {
-       ::HideControl( theControl ) ;
-   }
-   else
-   {
-       ::HideControl( theControl ) ;
-   }
+    if ( UMAHasAppearance() )
+    {
+        ::HideControl( inControl ) ;
+    }
+    else
+    {
+        ::HideControl( inControl ) ;
+    }
 }
 
 
 void UMASetControlVisibility                   (ControlHandle                  inControl,
                                                                 Boolean                                inIsVisible,
                                                                 Boolean                                inDoDraw)
-                                                                {
-       if ( UMAHasAppearance() )
-       {
+{
+    if ( UMAHasAppearance() )
+    {
 #if UMA_USE_APPEARANCE
-       ::SetControlVisibility( inControl , inIsVisible, inDoDraw ) ;
+        ::SetControlVisibility( inControl , inIsVisible, inDoDraw ) ;
 #endif
-   }
+    }
 }
 
 
@@ -695,7 +762,13 @@ bool UMAIsControlVisible                           (ControlHandle                  inControl)
        {
        return IsControlVisible( inControl ) ;
    }
+   else
+#endif
+  {
+#if !TARGET_CARBON
+    return (**inControl).contrlVis == 255 ;
 #endif
+  }
        return true ;
 }
 
@@ -893,21 +966,37 @@ void UMAIdleControls                                      (WindowPtr                              inWindow)
 
 void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn ) 
 {
+    RgnHandle updateRgn = NewRgn() ;
+#if TARGET_CARBON
+    GetWindowRegion( inWindow , kWindowUpdateRgn, updateRgn ) ;
+#else
+    GetWindowUpdateRgn( inWindow , updateRgn ) ;
+#endif
+       Point zero = { 0 , 0 } ;
+       LocalToGlobal( &zero ) ;
+       OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
 #if UMA_USE_APPEARANCE
-       if ( UMAHasAppearance() )
-       {
-               UpdateControls( inWindow , inRgn ) ;
-       }
-       else
+    if ( UMAHasAppearance() )
+    {
+        UpdateControls( inWindow , inRgn ) ;
+    }
+    else
 #endif
 #if !TARGET_CARBON
-       {
-               AGAUpdateControls( inWindow , inRgn ) ;
-       }
+    {
+        AGAUpdateControls( inWindow , inRgn ) ;
+    }
 #else
-       {
-       }
+    {
+    }
 #endif
+#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0332)
+    InvalWindowRgn( inWindow, updateRgn) ;
+#else
+    InvalRgn( updateRgn ) ;
+#endif
+       DisposeRgn( updateRgn ) ;
+
 }
 
 OSErr UMAGetRootControl( WindowPtr inWindow , ControlHandle *outControl ) 
@@ -1339,33 +1428,43 @@ void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
        {
 //             bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
 //             if ( inActivate != isHightlited )
-                               HiliteWindow( inWindowRef , inActivate ) ;
-                               ControlHandle control = NULL ;
-                               UMAGetRootControl( inWindowRef , & control ) ;
-                               if ( control )
-                               {
-                                       if ( inActivate )
-                                               UMAActivateControl( control ) ;
-                                       else
-                                               UMADeactivateControl( control ) ;
-                               }       
+               GrafPtr port ;
+               GetPort( &port ) ;
+#if TARGET_CARBON
+               SetPort( GetWindowPort( inWindowRef ) ) ;
+#else
+               SetPort( inWindowRef ) ;
+#endif
+               SetOrigin( 0 , 0 ) ;
+               HiliteWindow( inWindowRef , inActivate ) ;
+               ControlHandle control = NULL ;
+               UMAGetRootControl( inWindowRef , & control ) ;
+               if ( control )
+               {
+                       if ( inActivate )
+                               UMAActivateControl( control ) ;
+                       else
+                               UMADeactivateControl( control ) ;
+               }       
+               SetPort( port ) ;
        }
 }
 OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState ) 
 {
 #if UMA_USE_APPEARANCE
-       if ( UMAHasAppearance() )
-       {
-               ::DrawThemePlacard( inRect , inState ) ;
-   }
-   else
+  if ( UMAHasAppearance() )
+  {
+    ::DrawThemePlacard( inRect , inState ) ;
+  }
+  else
 #endif
 #if !TARGET_CARBON
-   {
-   }
+  {
+  }
 #else
-       {
-       }
+  {
+  }
 #endif
+  return noErr ;
 }