]> git.saurik.com Git - wxWidgets.git/commitdiff
new bitmap code
authorStefan Csomor <csomor@advancedconcepts.ch>
Sat, 16 Feb 2002 13:36:29 +0000 (13:36 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Sat, 16 Feb 2002 13:36:29 +0000 (13:36 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14253 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/bitmap.cpp
src/mac/bmpbuttn.cpp
src/mac/carbon/bitmap.cpp
src/mac/carbon/bmpbuttn.cpp
src/mac/carbon/toolbar.cpp
src/mac/toolbar.cpp

index ec5d91854ef4687790ced68949bdbe0d40c3310b..394ba8c7335eb865c067f07cf2ccae4275d9a5fa 100644 (file)
@@ -289,6 +289,57 @@ PicHandle wxMacCreatePict(GWorldPtr wp, GWorldPtr mask)
   return pict;                  
 }
 
+void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap ) 
+{
+    memset( info , 0 , sizeof(ControlButtonContentInfo) ) ;
+    if ( bitmap.Ok() )
+    {
+        wxBitmapRefData * bmap = (wxBitmapRefData*) ( bitmap.GetRefData()) ;
+        if ( bmap == NULL )
+            return ;
+            
+        if ( bmap->m_bitmapType == kMacBitmapTypePict )
+        {
+            info->contentType = kControlContentPictHandle ;
+            info->u.picture = MAC_WXHMETAFILE(bmap->m_hPict) ;
+        }
+        else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
+        {
+            if ( (bmap->m_width == bmap->m_height) && (bmap->m_width & 0x3 == 0) )
+            {
+                info->contentType = kControlContentCIconHandle ;
+                if ( bitmap.GetMask() )
+                {
+                    info->u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(bitmap.GetMask()->GetMaskBitmap()) ,
+                                                           8 , bmap->m_width ) ;
+                }
+                else
+                {
+                    info->u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ,
+                                                           8 , bmap->m_width ) ;
+                }
+            }
+            else
+            {
+                info->contentType = kControlContentPictHandle ;
+                if ( bitmap.GetMask() )
+                {
+                                   info->u.picture = wxMacCreatePict( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(bitmap.GetMask()->GetMaskBitmap() ) ) ;
+               }
+                else
+                {
+                                   info->u.picture = wxMacCreatePict( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ) ;
+                }
+            }
+        }
+               else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
+               {
+               info->contentType = kControlContentCIconHandle ;
+               info->u.cIconHandle = MAC_WXHICON(bmap->m_hIcon) ;
+               }
+    }
+}
+
 wxBitmapRefData::wxBitmapRefData()
 {
     m_ok = FALSE;
index ed8ee2a469fb9c614ef239f3509c364a2583bb66..de59d6db47c371de0b459354bfebc2829194d65a 100644 (file)
@@ -64,38 +64,11 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
        wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
        
        ControlButtonContentInfo info ;
-       
-
-       if ( m_buttonBitmap.Ok() )
+       wxMacCreateBitmapButton( &info , m_buttonBitmap ) ;
+       if ( info.contentType != kControlNoContent )
        {
-               if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
-           info.contentType = kControlContentPictHandle ;
-                       info.u.picture = MAC_WXHMETAFILE( bmap->m_hPict ) ;
-               }
-               else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
-               {
-                       if ( m_buttonBitmap.GetMask() )
-                       {
-                   info.contentType = kControlContentCIconHandle ;
-                               info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP( bmap->m_hBitmap ) , MAC_WXHBITMAP(m_buttonBitmap.GetMask()->GetMaskBitmap()) ,
-                                   8 , 16 ) ;
-                       }
-                       else
-                       {
-                   info.contentType = kControlContentCIconHandle ;
-                               info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP( bmap->m_hBitmap ) , NULL ,
-                                   8 , 16 ) ;
-                       }
-               }
-               else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
-               {
-               info.contentType = kControlContentCIconHandle ;
-               info.u.cIconHandle = MAC_WXHICON(bmap->m_hIcon) ;
-               }
-       }
-       
-       ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
-
+           ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
+    }
        MacPostControlCreate() ;
 
     return TRUE;
@@ -103,38 +76,12 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
 
 void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
 {
-       ControlButtonContentInfo info ;
     m_buttonBitmap = bitmap;
 
-       if ( m_buttonBitmap.Ok() )
+       ControlButtonContentInfo info ;
+       wxMacCreateBitmapButton( &info , m_buttonBitmap ) ;
+       if ( info.contentType != kControlNoContent )
        {
-               wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
-               if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
-           info.contentType = kControlContentPictHandle ;
-                       info.u.picture = MAC_WXHMETAFILE(bmap->m_hPict) ;
-               }
-               else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
-               {
-                       if ( m_buttonBitmap.GetMask() )
-                       {
-                   info.contentType = kControlContentCIconHandle ;
-                               info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(m_buttonBitmap.GetMask()->GetMaskBitmap()) ,
-                                   8 , 16 ) ;
-                       }
-                       else
-                       {
-                   info.contentType = kControlContentCIconHandle ;
-                               info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ,
-                                   8 , 16 ) ;
-                       }
-               }
-               else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
-               {
-               info.contentType = kControlContentCIconHandle ;
-               info.u.cIconHandle = MAC_WXHICON( bmap->m_hIcon ) ;
-               }
-
-               
            ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
     }
 }
index ec5d91854ef4687790ced68949bdbe0d40c3310b..394ba8c7335eb865c067f07cf2ccae4275d9a5fa 100644 (file)
@@ -289,6 +289,57 @@ PicHandle wxMacCreatePict(GWorldPtr wp, GWorldPtr mask)
   return pict;                  
 }
 
+void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap ) 
+{
+    memset( info , 0 , sizeof(ControlButtonContentInfo) ) ;
+    if ( bitmap.Ok() )
+    {
+        wxBitmapRefData * bmap = (wxBitmapRefData*) ( bitmap.GetRefData()) ;
+        if ( bmap == NULL )
+            return ;
+            
+        if ( bmap->m_bitmapType == kMacBitmapTypePict )
+        {
+            info->contentType = kControlContentPictHandle ;
+            info->u.picture = MAC_WXHMETAFILE(bmap->m_hPict) ;
+        }
+        else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
+        {
+            if ( (bmap->m_width == bmap->m_height) && (bmap->m_width & 0x3 == 0) )
+            {
+                info->contentType = kControlContentCIconHandle ;
+                if ( bitmap.GetMask() )
+                {
+                    info->u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(bitmap.GetMask()->GetMaskBitmap()) ,
+                                                           8 , bmap->m_width ) ;
+                }
+                else
+                {
+                    info->u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ,
+                                                           8 , bmap->m_width ) ;
+                }
+            }
+            else
+            {
+                info->contentType = kControlContentPictHandle ;
+                if ( bitmap.GetMask() )
+                {
+                                   info->u.picture = wxMacCreatePict( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(bitmap.GetMask()->GetMaskBitmap() ) ) ;
+               }
+                else
+                {
+                                   info->u.picture = wxMacCreatePict( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ) ;
+                }
+            }
+        }
+               else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
+               {
+               info->contentType = kControlContentCIconHandle ;
+               info->u.cIconHandle = MAC_WXHICON(bmap->m_hIcon) ;
+               }
+    }
+}
+
 wxBitmapRefData::wxBitmapRefData()
 {
     m_ok = FALSE;
index ed8ee2a469fb9c614ef239f3509c364a2583bb66..de59d6db47c371de0b459354bfebc2829194d65a 100644 (file)
@@ -64,38 +64,11 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
        wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
        
        ControlButtonContentInfo info ;
-       
-
-       if ( m_buttonBitmap.Ok() )
+       wxMacCreateBitmapButton( &info , m_buttonBitmap ) ;
+       if ( info.contentType != kControlNoContent )
        {
-               if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
-           info.contentType = kControlContentPictHandle ;
-                       info.u.picture = MAC_WXHMETAFILE( bmap->m_hPict ) ;
-               }
-               else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
-               {
-                       if ( m_buttonBitmap.GetMask() )
-                       {
-                   info.contentType = kControlContentCIconHandle ;
-                               info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP( bmap->m_hBitmap ) , MAC_WXHBITMAP(m_buttonBitmap.GetMask()->GetMaskBitmap()) ,
-                                   8 , 16 ) ;
-                       }
-                       else
-                       {
-                   info.contentType = kControlContentCIconHandle ;
-                               info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP( bmap->m_hBitmap ) , NULL ,
-                                   8 , 16 ) ;
-                       }
-               }
-               else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
-               {
-               info.contentType = kControlContentCIconHandle ;
-               info.u.cIconHandle = MAC_WXHICON(bmap->m_hIcon) ;
-               }
-       }
-       
-       ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
-
+           ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
+    }
        MacPostControlCreate() ;
 
     return TRUE;
@@ -103,38 +76,12 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit
 
 void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
 {
-       ControlButtonContentInfo info ;
     m_buttonBitmap = bitmap;
 
-       if ( m_buttonBitmap.Ok() )
+       ControlButtonContentInfo info ;
+       wxMacCreateBitmapButton( &info , m_buttonBitmap ) ;
+       if ( info.contentType != kControlNoContent )
        {
-               wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
-               if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
-           info.contentType = kControlContentPictHandle ;
-                       info.u.picture = MAC_WXHMETAFILE(bmap->m_hPict) ;
-               }
-               else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
-               {
-                       if ( m_buttonBitmap.GetMask() )
-                       {
-                   info.contentType = kControlContentCIconHandle ;
-                               info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(m_buttonBitmap.GetMask()->GetMaskBitmap()) ,
-                                   8 , 16 ) ;
-                       }
-                       else
-                       {
-                   info.contentType = kControlContentCIconHandle ;
-                               info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ,
-                                   8 , 16 ) ;
-                       }
-               }
-               else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
-               {
-               info.contentType = kControlContentCIconHandle ;
-               info.u.cIconHandle = MAC_WXHICON( bmap->m_hIcon ) ;
-               }
-
-               
            ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
     }
 }
index 66bed14b79934a31ab9f9422a198bb7f96c48240..c7dd11d1956600413792b491c32095c004fed488 100644 (file)
@@ -210,37 +210,14 @@ bool wxToolBar::Realize()
             toolrect.bottom = toolrect.top + toolSize.y ;
             
             ControlButtonContentInfo info ;
-            if ( bmap )
-            {
-                if ( bmap->m_bitmapType == kMacBitmapTypePict )
-                {
-                    info.contentType = kControlContentPictHandle ;
-                    info.u.picture = MAC_WXHMETAFILE(bmap->m_hPict) ;
-                }
-                else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
-                {
-                    if ( tool->GetBitmap1().GetMask() )
-                    {
-                        info.contentType = kControlContentCIconHandle ;
-                        info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(tool->GetBitmap1().GetMask()->GetMaskBitmap()) ,
-                                                               8 , 16 ) ;
-                    }
-                    else
-                    {
-                        info.contentType = kControlContentCIconHandle ;
-                        info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ,
-                                                               8 , 16 ) ;
-                    }
-                }
-            }
-            
+            wxMacCreateBitmapButton( &info , tool->GetBitmap1() ) ;
             ControlHandle m_macToolHandle ;
             
             SInt16 behaviour = kControlBehaviorOffsetContents ;
             if ( tool->CanBeToggled() )
                 behaviour += kControlBehaviorToggles ;
             
-            if ( info.u.cIconHandle ) // since it is a handle we can use one of them
+            if ( info.contentType != kControlNoContent ) 
             {
                 m_macToolHandle = ::NewControl( window , &toolrect , "\p" , false , 0 , 
                                                 behaviour + info.contentType , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ;
index 66bed14b79934a31ab9f9422a198bb7f96c48240..c7dd11d1956600413792b491c32095c004fed488 100644 (file)
@@ -210,37 +210,14 @@ bool wxToolBar::Realize()
             toolrect.bottom = toolrect.top + toolSize.y ;
             
             ControlButtonContentInfo info ;
-            if ( bmap )
-            {
-                if ( bmap->m_bitmapType == kMacBitmapTypePict )
-                {
-                    info.contentType = kControlContentPictHandle ;
-                    info.u.picture = MAC_WXHMETAFILE(bmap->m_hPict) ;
-                }
-                else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
-                {
-                    if ( tool->GetBitmap1().GetMask() )
-                    {
-                        info.contentType = kControlContentCIconHandle ;
-                        info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(tool->GetBitmap1().GetMask()->GetMaskBitmap()) ,
-                                                               8 , 16 ) ;
-                    }
-                    else
-                    {
-                        info.contentType = kControlContentCIconHandle ;
-                        info.u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ,
-                                                               8 , 16 ) ;
-                    }
-                }
-            }
-            
+            wxMacCreateBitmapButton( &info , tool->GetBitmap1() ) ;
             ControlHandle m_macToolHandle ;
             
             SInt16 behaviour = kControlBehaviorOffsetContents ;
             if ( tool->CanBeToggled() )
                 behaviour += kControlBehaviorToggles ;
             
-            if ( info.u.cIconHandle ) // since it is a handle we can use one of them
+            if ( info.contentType != kControlNoContent ) 
             {
                 m_macToolHandle = ::NewControl( window , &toolrect , "\p" , false , 0 , 
                                                 behaviour + info.contentType , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ;