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