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 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 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)) { wxMacBitmapButton* peer = new wxMacBitmapButton(wxpeer, bitmap, style); OSStatus err; WXWindow macParent = MAC_WXHWND(parent->MacGetTopLevelWindowRef()); Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); ControlButtonContentInfo info; peer->InitButtonContentInfo(info, bitmap); if ( info.contentType == kControlContentIconRef ) { err = CreateIconControl ( macParent, &bounds, &info, false, peer->GetControlRefAddr() ); } else // normal bevel button { err = CreateBevelButtonControl ( macParent, &bounds, CFSTR(""), style & wxBU_AUTODRAW ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel, kControlBehaviorOffsetContents, &info, 0, // menu id (no associated menu) 0, // menu behaviour (unused) 0, // menu placement (unused too) peer->GetControlRefAddr() ); } verify_noerr( err ); wxMacReleaseBitmapButton( &info ); return peer; }
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 }
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; }
// 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 } } }