]> git.saurik.com Git - wxWidgets.git/blame - src/mac/bmpbuttn.cpp
file dialog now remebers list/report and hidden files settings, displays icons for...
[wxWidgets.git] / src / mac / 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
e9576ca5 18IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
e9576ca5 19
7c551d95
SC
20#include <wx/mac/uma.h>
21
22PicHandle MakePict(GWorldPtr wp) ;
23
e9576ca5
SC
24bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
25 const wxPoint& pos,
26 const wxSize& size, long style,
27 const wxValidator& validator,
28 const wxString& name)
29{
30 m_buttonBitmap = bitmap;
7c551d95 31
e9576ca5
SC
32 m_marginX = 0;
33 m_marginY = 0;
34
35 int x = pos.x;
36 int y = pos.y;
37 int width = size.x;
38 int height = size.y;
39
40 if (id == -1)
41 m_windowId = NewControlId();
42 else
43 m_windowId = id;
44
45 if ( width == -1 && bitmap.Ok())
46 width = bitmap.GetWidth() + 2*m_marginX;
47
48 if ( height == -1 && bitmap.Ok())
49 height = bitmap.GetHeight() + 2*m_marginY;
50
8208e181
SC
51 m_macHorizontalBorder = 0 ; // additional pixels around the real control
52 m_macVerticalBorder = 0 ;
7c551d95
SC
53 Rect bounds ;
54 Str255 title ;
55 MacPreControlCreate( parent , id , "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
56
57 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 ,
58 kControlBehaviorOffsetContents + kControlContentPictHandle , 0,
37e2cb08 59 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
7c551d95
SC
60 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
61
62 m_buttonBitmap = bitmap;
63 PicHandle icon = NULL ;
64 if ( m_buttonBitmap.Ok() )
65 {
66 wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
67 if ( bmap->m_bitmapType == kMacBitmapTypePict )
68 icon = bmap->m_hPict ;
69 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
70 {
71 icon = MakePict( bmap->m_hBitmap ) ;
72 }
73 }
74 ControlButtonContentInfo info ;
75
76 info.contentType = kControlContentPictHandle ;
77 info.u.picture = icon ;
78
79 UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
80
81 MacPostControlCreate() ;
e9576ca5 82
7c551d95 83 return TRUE;
e9576ca5
SC
84}
85
86void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
87{
88 m_buttonBitmap = bitmap;
7c551d95
SC
89 PicHandle icon = NULL ;
90 if ( m_buttonBitmap.Ok() )
91 {
92 wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
93 if ( bmap->m_bitmapType == kMacBitmapTypePict )
94 icon = bmap->m_hPict ;
95 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
96 {
97 icon = MakePict( bmap->m_hBitmap ) ;
98 }
99 }
100 ControlButtonContentInfo info ;
101
102 info.contentType = kControlContentPictHandle ;
103 info.u.picture = icon ;
104
105 UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
e9576ca5
SC
106}
107