]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/bmpbuttn.cpp
Build fix after wxColourBase introduction.
[wxWidgets.git] / src / mac / classic / bmpbuttn.cpp
CommitLineData
2646f485
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: bmpbuttn.cpp
3// Purpose: wxBitmapButton
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
2646f485
SC
10/////////////////////////////////////////////////////////////////////////////
11
2646f485
SC
12#include "wx/window.h"
13#include "wx/bmpbuttn.h"
14
2646f485 15IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
2646f485
SC
16
17#include "wx/mac/uma.h"
18#include "wx/bitmap.h"
19
20bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
21 const wxPoint& pos,
22 const wxSize& size, long style,
23 const wxValidator& validator,
24 const wxString& name)
25{
26 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
27 // essentially creates an additional button
28 if ( !wxControl::Create(parent, id, pos, size,
29 style, validator, name) )
30 return false;
31
32 m_bmpNormal = bitmap;
33
34 if (style & wxBU_AUTODRAW)
35 {
36 m_marginX = wxDEFAULT_BUTTON_MARGIN;
37 m_marginY = wxDEFAULT_BUTTON_MARGIN;
38 }
39 else
40 {
41 m_marginX = 0;
42 m_marginY = 0;
43 }
44
45 int width = size.x;
46 int height = size.y;
47
48 if ( bitmap.Ok() )
49 {
50 wxSize newSize = DoGetBestSize();
51 if ( width == -1 )
52 width = newSize.x;
53 if ( height == -1 )
54 height = newSize.y;
55 }
56
57 Rect bounds ;
58 Str255 title ;
59 m_bmpNormal = bitmap;
60 wxBitmapRefData * bmap = NULL ;
61
62 if ( m_bmpNormal.Ok() )
63 bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ;
64
65 MacPreControlCreate( parent , id , wxEmptyString , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
66
6bc3b8e9 67 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 ,
2646f485
SC
68 kControlBehaviorOffsetContents +
69 ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ?
70 kControlContentCIconHandle : kControlContentPictHandle ) , 0,
71 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
72 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
73
74 ControlButtonContentInfo info ;
75 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
76 if ( info.contentType != kControlNoContent )
77 {
78 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
79 }
80 MacPostControlCreate() ;
81
82 return TRUE;
83}
84
85void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
86{
87 m_bmpNormal = bitmap;
9f884528 88 InvalidateBestSize();
2646f485
SC
89
90 ControlButtonContentInfo info ;
91 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
92 if ( info.contentType != kControlNoContent )
93 {
94 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
95 }
96}
97
98
99wxSize wxBitmapButton::DoGetBestSize() const
100{
101 wxSize best;
102 if (m_bmpNormal.Ok())
103 {
104 best.x = m_bmpNormal.GetWidth() + 2*m_marginX;
105 best.y = m_bmpNormal.GetHeight() + 2*m_marginY;
106 }
107 return best;
108}