void SetBitmap(const wxBitmap& bitmap) { wxBitmap bmp; if ( GetWXPeer()->HasFlag( wxBORDER_NONE ) ) { bmp = wxMakeStdSizeBitmap(bitmap); // TODO set bitmap in peer as well } else bmp = bitmap; ControlButtonContentInfo info; if ( GetWXPeer()->HasFlag( wxBORDER_NONE ) ) { wxMacCreateBitmapButton( &info, bmp, kControlContentIconRef ); if ( info.contentType != kControlNoContent ) SetData( kControlIconPart, kControlIconContentTag, info ); } else { wxMacCreateBitmapButton( &info, bmp ); if ( info.contentType != kControlNoContent ) SetData( kControlButtonPart, kControlBevelButtonContentTag, info ); } wxMacReleaseBitmapButton( &info ); }
void CBOINCBitmapChoice::SetItemBitmap(unsigned int n, const wxBitmap& bitmap) { MenuHandle mhandle = (MenuHandle) m_macPopUpMenuHandle; unsigned int index = n + 1; if ( mhandle == NULL || index == 0) return ; if ( bitmap.Ok() ) { CGImageRef imageRef = (CGImageRef)( bitmap.CGImageCreate() ) ; SetMenuItemIconHandle( mhandle , index , kMenuCGImageRefType , (Handle) imageRef ) ; #if 0// wxUSE_BMPBUTTON ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info , bitmap ) ; if ( info.contentType != kControlNoContent ) { if ( info.contentType == kControlContentIconRef ) SetMenuItemIconHandle( mhandle , index , kMenuIconRefType , (Handle) info.u.iconRef ) ; else if ( info.contentType == kControlContentCGImageRef ) SetMenuItemIconHandle( mhandle , index , kMenuCGImageRefType , (Handle) info.u.imageRef ) ; } wxMacReleaseBitmapButton( &info ) ; #endif } }
void wxMenuItem::UpdateItemBitmap() { if ( !m_parentMenu ) return ; MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ; MenuItemIndex index = m_parentMenu->MacGetIndexFromItem( this ) ; if ( mhandle == NULL || index == 0) return ; if ( m_bitmap.Ok() ) { #if wxUSE_BMPBUTTON ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info , m_bitmap ) ; if ( info.contentType != kControlNoContent ) { if ( info.contentType == kControlContentIconRef ) SetMenuItemIconHandle( mhandle , index , kMenuIconRefType , (Handle) info.u.iconRef ) ; } wxMacReleaseBitmapButton( &info ) ; #endif } }
void wxMenuItem::DoUpdateItemBitmap( WXHMENU menu, wxUint16 index) { MenuHandle mhandle = (MenuHandle) menu; if ( mhandle == NULL || index == 0) return ; if ( m_bitmap.Ok() ) { #if wxUSE_BMPBUTTON ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info , m_bitmap ) ; if ( info.contentType != kControlNoContent ) { if ( info.contentType == kControlContentIconRef ) SetMenuItemIconHandle( mhandle , index , kMenuIconRefType , (Handle) info.u.iconRef ) ; else if ( info.contentType == kControlContentCGImageRef ) SetMenuItemIconHandle( mhandle , index , kMenuCGImageRefType , (Handle) info.u.imageRef ) ; } wxMacReleaseBitmapButton( &info ) ; #endif } }
wxWidgetImplType* wxWidgetImpl::CreateBitmapButton( wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID WXUNUSED(id), const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, long WXUNUSED(extraStyle)) { OSStatus err = noErr; ControlButtonContentInfo info; Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); wxMacControl* peer = new wxMacBitmapButton( wxpeer ); wxBitmap bmp; if ( bitmap.Ok() && (style & wxBORDER_NONE) ) { bmp = wxMakeStdSizeBitmap(bitmap); // TODO set bitmap in peer as well } else bmp = bitmap; if ( style & wxBORDER_NONE ) { // contrary to the docs this control only works with iconrefs wxMacCreateBitmapButton( &info, bmp, kControlContentIconRef ); err = CreateIconControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, &info, false, peer->GetControlRefAddr() ); } else { wxMacCreateBitmapButton( &info, bmp ); err = CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, CFSTR(""), ((style & wxBU_AUTODRAW) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ), kControlBehaviorOffsetContents, &info, 0, 0, 0, peer->GetControlRefAddr() ); } verify_noerr( err ); wxMacReleaseBitmapButton( &info ); return peer; }
void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) { m_bmpNormal = bitmap; InvalidateBestSize(); ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info , m_bmpNormal ) ; if ( info.contentType != kControlNoContent ) { ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; } }
void wxToolBarTool::UpdateToggleImage( bool toggle ) { #ifdef __WXMAC_OSX__ if ( toggle ) { int w = m_bmpNormal.GetWidth() ; int h = m_bmpNormal.GetHeight() ; wxBitmap bmp( w , h ) ; wxMemoryDC dc ; dc.SelectObject( bmp ) ; dc.SetPen( wxNullPen ) ; dc.SetBackground( *wxWHITE ) ; dc.DrawRectangle( 0 , 0 , w , h ) ; dc.DrawBitmap( m_bmpNormal , 0 , 0 , true) ; dc.SelectObject( wxNullBitmap ) ; ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info , bmp ) ; SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ), (Ptr)&info ); wxMacReleaseBitmapButton( &info ) ; } else { ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info , m_bmpNormal ) ; SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ), (Ptr)&info ); wxMacReleaseBitmapButton( &info ) ; } IconTransformType transform = toggle ? kTransformSelected : kTransformNone ; SetControlData( m_controlHandle, 0, kControlIconTransformTag, sizeof( transform ), (Ptr)&transform ); HIViewSetNeedsDisplay( m_controlHandle , true ) ; #else ::SetControl32BitValue( m_controlHandle , toggle ) ; #endif }
// Added by Mark Newsam // When a page is added or deleted to the notebook this function updates // information held in the control so that it matches the order // the user would expect. // void wxNotebook::MacSetupTabs() { m_peer->SetMaximum( GetPageCount() ) ; wxNotebookPage *page; ControlTabInfoRecV1 info; const size_t countPages = GetPageCount(); for (size_t ii = 0; ii < countPages; ii++) { page = m_pages[ii]; info.version = kControlTabInfoVersionOne; info.iconSuiteID = 0; wxMacCFStringHolder cflabel( page->GetLabel(), m_font.GetEncoding() ) ; info.name = cflabel ; m_peer->SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ; if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 ) { const wxBitmap bmap = GetImageList()->GetBitmap( GetPageImage( ii ) ) ; if ( bmap.Ok() ) { ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info, bmap ) ; OSStatus err = m_peer->SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info ); wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ; wxMacReleaseBitmapButton( &info ) ; } } m_peer->SetTabEnabled( ii + 1, true ) ; } #if wxMAC_USE_CORE_GRAPHICS Refresh(); #else Rect bounds; m_peer->GetRectInWindowCoords( &bounds ) ; InvalWindowRect( (WindowRef)MacGetTopLevelWindowRef(), &bounds ); #endif }
wxWidgetImplType* wxWidgetImpl::CreateBitmapToggleButton( wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID WXUNUSED(id), const wxBitmap& label, const wxPoint& pos, const wxSize& size, long WXUNUSED(style), long WXUNUSED(extraStyle)) { Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ; wxMacControl* peer = new wxMacControl(wxpeer) ; ControlButtonContentInfo info; wxMacCreateBitmapButton( &info, label ); verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , kControlBevelButtonNormalBevel , kControlBehaviorOffsetContents | kControlBehaviorToggles , &info , 0 , 0 , 0 , peer->GetControlRefAddr() ) ); wxMacReleaseBitmapButton( &info ) ; return peer; }
void wxMacControl::SetupTabs( const wxNotebook& notebook) { const size_t countPages = notebook.GetPageCount(); SetMaximum( countPages ) ; wxNotebookPage *page; ControlTabInfoRecV1 info; for (size_t ii = 0; ii < countPages; ii++) { page = (wxNotebookPage*) notebook.GetPage(ii); info.version = kControlTabInfoVersionOne; info.iconSuiteID = 0; wxCFStringRef cflabel( page->GetLabel(), page->GetFont().GetEncoding() ) ; info.name = cflabel ; SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ; if ( notebook.GetImageList() && notebook.GetPageImage(ii) >= 0 ) { const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( ii ) ) ; if ( bmap.IsOk() ) { ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info, bmap ) ; OSStatus err = SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info ); if ( err != noErr ) { wxFAIL_MSG("Error when setting icon on tab"); } wxMacReleaseBitmapButton( &info ) ; } } SetTabEnabled( ii + 1, true ) ; } }
void SetBitmap( const wxBitmap& bitmap ) { MenuItemIndex i = FindMenuItemIndex() ; if ( i > 0 ) { if ( bitmap.IsOk() ) { #if wxUSE_BMPBUTTON ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info , bitmap ) ; if ( info.contentType != kControlNoContent ) { if ( info.contentType == kControlContentIconRef ) SetMenuItemIconHandle( m_parentMenuRef, i , kMenuIconRefType , (Handle) info.u.iconRef ) ; else if ( info.contentType == kControlContentCGImageRef ) SetMenuItemIconHandle( m_parentMenuRef, i , kMenuCGImageRefType , (Handle) info.u.imageRef ) ; } wxMacReleaseBitmapButton( &info ) ; #endif } } }
bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) { // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create // essentially creates an additional button if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) return false; m_bmpNormal = bitmap; if (style & wxBU_AUTODRAW) { m_marginX = wxDEFAULT_BUTTON_MARGIN; m_marginY = wxDEFAULT_BUTTON_MARGIN; } else { m_marginX = 0; m_marginY = 0; } int width = size.x; int height = size.y; if ( bitmap.Ok() ) { wxSize newSize = DoGetBestSize(); if ( width == -1 ) width = newSize.x; if ( height == -1 ) height = newSize.y; } Rect bounds ; Str255 title ; m_bmpNormal = bitmap; wxBitmapRefData * bmap = NULL ; if ( m_bmpNormal.Ok() ) bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ; MacPreControlCreate( parent , id , wxEmptyString , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ; m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , kControlBehaviorOffsetContents + ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ? kControlContentCIconHandle : kControlContentPictHandle ) , 0, (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ; wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info , m_bmpNormal ) ; if ( info.contentType != kControlNoContent ) { ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; } MacPostControlCreate() ; return TRUE; }