]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/bmpbuttn.cpp
Added code to show off wxDbGrid (contributed by Paul and Roger Gammans) in wxUSE_NEW_...
[wxWidgets.git] / src / mac / carbon / bmpbuttn.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: bmpbuttn.cpp
3// Purpose: wxBitmapButton
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "bmpbuttn.h"
14#endif
15
16#include "wx/bmpbuttn.h"
17
2f1ae414 18#if !USE_SHARED_LIBRARY
e9576ca5 19IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
2f1ae414 20#endif
e9576ca5 21
7c551d95
SC
22#include <wx/mac/uma.h>
23
2f1ae414 24PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ;
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{
32 m_buttonBitmap = bitmap;
7c551d95 33
e9576ca5
SC
34 m_marginX = 0;
35 m_marginY = 0;
36
37 int x = pos.x;
38 int y = pos.y;
39 int width = size.x;
40 int height = size.y;
41
42 if (id == -1)
43 m_windowId = NewControlId();
44 else
45 m_windowId = id;
46
47 if ( width == -1 && bitmap.Ok())
48 width = bitmap.GetWidth() + 2*m_marginX;
49
50 if ( height == -1 && bitmap.Ok())
51 height = bitmap.GetHeight() + 2*m_marginY;
52
7c551d95
SC
53 Rect bounds ;
54 Str255 title ;
3dec57ad
SC
55 m_buttonBitmap = bitmap;
56 wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
57
7c551d95
SC
58 MacPreControlCreate( parent , id , "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
59
fdaf613a 60 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 ,
3dec57ad
SC
61 kControlBehaviorOffsetContents +
62 ( bmap->m_bitmapType == kMacBitmapTypeIcon ? kControlContentCIconHandle : kControlContentPictHandle ) , 0,
37e2cb08 63 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
7c551d95
SC
64 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
65
3dec57ad
SC
66 ControlButtonContentInfo info ;
67
68
7c551d95
SC
69 if ( m_buttonBitmap.Ok() )
70 {
3dec57ad
SC
71 if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
72 info.contentType = kControlContentPictHandle ;
73 info.u.picture = bmap->m_hPict ;
74 }
7c551d95
SC
75 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
76 {
3dec57ad 77 info.contentType = kControlContentPictHandle ;
2f1ae414
SC
78 if ( m_buttonBitmap.GetMask() )
79 {
3dec57ad 80 info.u.picture = MakePict( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ) ;
2f1ae414
SC
81 }
82 else
83 {
3dec57ad 84 info.u.picture = MakePict( bmap->m_hBitmap , NULL ) ;
2f1ae414 85 }
7c551d95 86 }
3dec57ad
SC
87 else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
88 {
89 info.contentType = kControlContentCIconHandle ;
90 info.u.cIconHandle = bmap->m_hIcon ;
91 }
7c551d95 92 }
7c551d95
SC
93
94 UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
95
96 MacPostControlCreate() ;
e9576ca5 97
7c551d95 98 return TRUE;
e9576ca5
SC
99}
100
101void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
102{
3dec57ad 103 ControlButtonContentInfo info ;
e9576ca5 104 m_buttonBitmap = bitmap;
3dec57ad 105
7c551d95
SC
106 if ( m_buttonBitmap.Ok() )
107 {
108 wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
109 if ( bmap->m_bitmapType == kMacBitmapTypePict )
3dec57ad
SC
110 {
111 info.contentType = kControlContentPictHandle ;
112 info.u.picture = bmap->m_hPict ;
113 }
7c551d95
SC
114 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
115 {
3dec57ad 116 info.contentType = kControlContentPictHandle ;
2f1ae414
SC
117 if ( m_buttonBitmap.GetMask() )
118 {
3dec57ad 119 info.u.picture = MakePict( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ) ;
2f1ae414
SC
120 }
121 else
122 {
3dec57ad 123 info.u.picture = MakePict( bmap->m_hBitmap , NULL ) ;
2f1ae414 124 }
7c551d95 125 }
3dec57ad
SC
126 else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
127 {
128 info.contentType = kControlContentCIconHandle ;
129 info.u.cIconHandle = bmap->m_hIcon ;
130 }
131
132 UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
133 }
e9576ca5
SC
134}
135