]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/bmpbuttn.cpp
trying to avoid redraw problems at wrong places
[wxWidgets.git] / src / mac / carbon / bmpbuttn.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: bmpbuttn.cpp
3// Purpose: wxBitmapButton
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "bmpbuttn.h"
14#endif
15
d8c736e5 16#include "wx/window.h"
e9576ca5
SC
17#include "wx/bmpbuttn.h"
18
2f1ae414 19#if !USE_SHARED_LIBRARY
e9576ca5 20IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
2f1ae414 21#endif
e9576ca5 22
d497dca4 23#include "wx/mac/uma.h"
72055702 24#include "wx/bitmap.h"
7c551d95 25
e9576ca5
SC
26bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
27 const wxPoint& pos,
28 const wxSize& size, long style,
29 const wxValidator& validator,
30 const wxString& name)
31{
b45ed7a2
VZ
32 if ( !wxBitmapButtonBase::Create(parent, id, _T(""), pos, size,
33 style, validator, name) )
34 return false;
35
d460ed40 36 m_bmpNormal = bitmap;
7c551d95 37
827e7a48
RR
38 if (style & wxBU_AUTODRAW)
39 {
40 m_marginX = wxDEFAULT_BUTTON_MARGIN;
41 m_marginY = wxDEFAULT_BUTTON_MARGIN;
42 }
43 else
44 {
45 m_marginX = 0;
46 m_marginY = 0;
47 }
e9576ca5 48
e9576ca5
SC
49 int width = size.x;
50 int height = size.y;
51
e9576ca5 52 if ( width == -1 && bitmap.Ok())
b45ed7a2 53 width = bitmap.GetWidth() + 2*m_marginX;
e9576ca5
SC
54
55 if ( height == -1 && bitmap.Ok())
b45ed7a2 56 height = bitmap.GetHeight() + 2*m_marginY;
e9576ca5 57
e40298d5
JS
58 Rect bounds ;
59 Str255 title ;
f125ccf2 60 m_bmpNormal = bitmap;
e40298d5
JS
61 wxBitmapRefData * bmap = NULL ;
62
63 if ( m_bmpNormal.Ok() )
64 bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ;
65
427ff662 66 MacPreControlCreate( parent , id , wxEmptyString , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
7c551d95 67
e40298d5
JS
68 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 ,
69 kControlBehaviorOffsetContents +
70 ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ?
71 kControlContentCIconHandle : kControlContentPictHandle ) , 0,
72 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
427ff662 73 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
e40298d5
JS
74
75 ControlButtonContentInfo info ;
76 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
77 if ( info.contentType != kControlNoContent )
78 {
79 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
be295828 80 }
e40298d5 81 MacPostControlCreate() ;
e9576ca5 82
7c551d95 83 return TRUE;
e9576ca5
SC
84}
85
86void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
87{
d460ed40 88 m_bmpNormal = bitmap;
3dec57ad 89
d460ed40
GD
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 ) ;
3dec57ad 95 }
e9576ca5
SC
96}
97