]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/bmpbuttn.cpp
Hopefully fixed library names generated by wx-config for OS/2's PM port.
[wxWidgets.git] / src / mac / carbon / bmpbuttn.cpp
... / ...
CommitLineData
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
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13#pragma implementation "bmpbuttn.h"
14#endif
15
16#include "wx/wxprec.h"
17
18#if wxUSE_BMPBUTTON
19
20#include "wx/window.h"
21#include "wx/bmpbuttn.h"
22
23IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
24
25#include "wx/mac/uma.h"
26#include "wx/bitmap.h"
27
28bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
29 const wxPoint& pos,
30 const wxSize& size, long style,
31 const wxValidator& validator,
32 const wxString& name)
33{
34 m_macIsUserPane = FALSE ;
35
36 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
37 // essentially creates an additional button
38 if ( !wxControl::Create(parent, id, pos, size,
39 style, validator, name) )
40 return false;
41
42 m_bmpNormal = bitmap;
43
44 if (style & wxBU_AUTODRAW)
45 {
46 m_marginX = wxDEFAULT_BUTTON_MARGIN;
47 m_marginY = wxDEFAULT_BUTTON_MARGIN;
48 }
49 else
50 {
51 m_marginX = 0;
52 m_marginY = 0;
53 }
54
55 int width = size.x;
56 int height = size.y;
57
58 if ( bitmap.Ok() )
59 {
60 wxSize newSize = DoGetBestSize();
61 if ( width == -1 )
62 width = newSize.x;
63 if ( height == -1 )
64 height = newSize.y;
65 }
66
67 m_bmpNormal = bitmap;
68
69 ControlButtonContentInfo info ;
70 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
71
72 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
73 m_peer = new wxMacControl( this ) ;
74 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
75 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ) ,
76 kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
77
78 wxMacReleaseBitmapButton( &info ) ;
79 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
80
81 MacPostControlCreate(pos,size) ;
82
83 return TRUE;
84}
85
86void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
87{
88 m_bmpNormal = bitmap;
89 InvalidateBestSize();
90
91 ControlButtonContentInfo info ;
92 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
93 if ( info.contentType != kControlNoContent )
94 {
95 m_peer->SetData( kControlButtonPart , kControlBevelButtonContentTag , info ) ;
96 }
97 wxMacReleaseBitmapButton( &info ) ;
98}
99
100
101wxSize wxBitmapButton::DoGetBestSize() const
102{
103 wxSize best;
104 if (m_bmpNormal.Ok())
105 {
106 best.x = m_bmpNormal.GetWidth() + 2*m_marginX;
107 best.y = m_bmpNormal.GetHeight() + 2*m_marginY;
108 }
109 return best;
110}
111
112#endif