]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/bmpbuttn.cpp
* In _GSocket_Get_Mac_Socket(), do not call CFSocketSetSocketFlags to turn
[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
1169a919
JS
26wxBitmapButtonBase::wxBitmapButtonBase()
27 : m_bmpNormal(),
28 m_bmpSelected(),
29 m_bmpFocus(),
30 m_bmpDisabled(),
31 m_marginX(0),
32 m_marginY(0)
33{
34}
35
e9576ca5
SC
36bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
37 const wxPoint& pos,
38 const wxSize& size, long style,
39 const wxValidator& validator,
40 const wxString& name)
41{
bf19e3f6
SC
42 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
43 // essentially creates an additional button
44 if ( !wxControl::Create(parent, id, pos, size,
b45ed7a2
VZ
45 style, validator, name) )
46 return false;
47
d460ed40 48 m_bmpNormal = bitmap;
7c551d95 49
827e7a48
RR
50 if (style & wxBU_AUTODRAW)
51 {
52 m_marginX = wxDEFAULT_BUTTON_MARGIN;
53 m_marginY = wxDEFAULT_BUTTON_MARGIN;
54 }
55 else
56 {
57 m_marginX = 0;
58 m_marginY = 0;
59 }
e9576ca5 60
e9576ca5
SC
61 int width = size.x;
62 int height = size.y;
63
e9576ca5 64 if ( width == -1 && bitmap.Ok())
b45ed7a2 65 width = bitmap.GetWidth() + 2*m_marginX;
e9576ca5
SC
66
67 if ( height == -1 && bitmap.Ok())
b45ed7a2 68 height = bitmap.GetHeight() + 2*m_marginY;
e9576ca5 69
e40298d5
JS
70 Rect bounds ;
71 Str255 title ;
f125ccf2 72 m_bmpNormal = bitmap;
e40298d5
JS
73 wxBitmapRefData * bmap = NULL ;
74
75 if ( m_bmpNormal.Ok() )
76 bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ;
77
427ff662 78 MacPreControlCreate( parent , id , wxEmptyString , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
7c551d95 79
e40298d5
JS
80 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 ,
81 kControlBehaviorOffsetContents +
82 ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ?
83 kControlContentCIconHandle : kControlContentPictHandle ) , 0,
84 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
427ff662 85 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
e40298d5
JS
86
87 ControlButtonContentInfo info ;
88 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
89 if ( info.contentType != kControlNoContent )
90 {
91 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
be295828 92 }
e40298d5 93 MacPostControlCreate() ;
e9576ca5 94
7c551d95 95 return TRUE;
e9576ca5
SC
96}
97
98void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
99{
d460ed40 100 m_bmpNormal = bitmap;
3dec57ad 101
d460ed40
GD
102 ControlButtonContentInfo info ;
103 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
104 if ( info.contentType != kControlNoContent )
105 {
106 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
3dec57ad 107 }
e9576ca5
SC
108}
109