]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/bmpbuttn.cpp
added conversion routines to CIconHandle
[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
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"
7c551d95 24
2f1ae414 25PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ;
7c551d95 26
e9576ca5
SC
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 m_buttonBitmap = bitmap;
7c551d95 34
e9576ca5
SC
35 m_marginX = 0;
36 m_marginY = 0;
37
38 int x = pos.x;
39 int y = pos.y;
40 int width = size.x;
41 int height = size.y;
42
43 if (id == -1)
44 m_windowId = NewControlId();
45 else
46 m_windowId = id;
47
48 if ( width == -1 && bitmap.Ok())
49 width = bitmap.GetWidth() + 2*m_marginX;
50
51 if ( height == -1 && bitmap.Ok())
52 height = bitmap.GetHeight() + 2*m_marginY;
53
7c551d95
SC
54 Rect bounds ;
55 Str255 title ;
3dec57ad
SC
56 m_buttonBitmap = bitmap;
57 wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
58
7c551d95
SC
59 MacPreControlCreate( parent , id , "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
60
fdaf613a 61 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 ,
3dec57ad
SC
62 kControlBehaviorOffsetContents +
63 ( bmap->m_bitmapType == kMacBitmapTypeIcon ? kControlContentCIconHandle : kControlContentPictHandle ) , 0,
37e2cb08 64 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
7c551d95
SC
65 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
66
3dec57ad
SC
67 ControlButtonContentInfo info ;
68
69
7c551d95
SC
70 if ( m_buttonBitmap.Ok() )
71 {
3dec57ad
SC
72 if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
73 info.contentType = kControlContentPictHandle ;
74 info.u.picture = bmap->m_hPict ;
75 }
7c551d95
SC
76 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
77 {
3dec57ad 78 info.contentType = kControlContentPictHandle ;
2f1ae414
SC
79 if ( m_buttonBitmap.GetMask() )
80 {
3dec57ad 81 info.u.picture = MakePict( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ) ;
2f1ae414
SC
82 }
83 else
84 {
3dec57ad 85 info.u.picture = MakePict( bmap->m_hBitmap , NULL ) ;
2f1ae414 86 }
7c551d95 87 }
3dec57ad
SC
88 else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
89 {
90 info.contentType = kControlContentCIconHandle ;
91 info.u.cIconHandle = bmap->m_hIcon ;
92 }
7c551d95 93 }
7c551d95
SC
94
95 UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
96
97 MacPostControlCreate() ;
e9576ca5 98
7c551d95 99 return TRUE;
e9576ca5
SC
100}
101
102void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
103{
3dec57ad 104 ControlButtonContentInfo info ;
e9576ca5 105 m_buttonBitmap = bitmap;
3dec57ad 106
7c551d95
SC
107 if ( m_buttonBitmap.Ok() )
108 {
109 wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
110 if ( bmap->m_bitmapType == kMacBitmapTypePict )
3dec57ad
SC
111 {
112 info.contentType = kControlContentPictHandle ;
113 info.u.picture = bmap->m_hPict ;
114 }
7c551d95
SC
115 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
116 {
3dec57ad 117 info.contentType = kControlContentPictHandle ;
2f1ae414
SC
118 if ( m_buttonBitmap.GetMask() )
119 {
3dec57ad 120 info.u.picture = MakePict( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ) ;
2f1ae414
SC
121 }
122 else
123 {
3dec57ad 124 info.u.picture = MakePict( bmap->m_hBitmap , NULL ) ;
2f1ae414 125 }
7c551d95 126 }
3dec57ad
SC
127 else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
128 {
129 info.contentType = kControlContentCIconHandle ;
130 info.u.cIconHandle = bmap->m_hIcon ;
131 }
132
133 UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
134 }
e9576ca5
SC
135}
136