]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/bmpbuttn.cpp
detection of aqua layout scheme added
[wxWidgets.git] / src / mac / carbon / bmpbuttn.cpp
... / ...
CommitLineData
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/window.h"
17#include "wx/bmpbuttn.h"
18
19#if !USE_SHARED_LIBRARY
20IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
21#endif
22
23#include "wx/mac/uma.h"
24#include "wx/bitmap.h"
25
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;
33
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
53 Rect bounds ;
54 Str255 title ;
55 m_buttonBitmap = bitmap;
56 wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
57
58 MacPreControlCreate( parent , id , "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
59
60 m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 ,
61 kControlBehaviorOffsetContents +
62 ( bmap->m_bitmapType == kMacBitmapTypeIcon ? kControlContentCIconHandle : kControlContentPictHandle ) , 0,
63 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
64 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
65
66 ControlButtonContentInfo info ;
67
68
69 if ( m_buttonBitmap.Ok() )
70 {
71 if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
72 info.contentType = kControlContentPictHandle ;
73 info.u.picture = bmap->m_hPict ;
74 }
75 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
76 {
77 if ( m_buttonBitmap.GetMask() )
78 {
79 info.contentType = kControlContentCIconHandle ;
80 info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ,
81 8 , 16 ) ;
82 }
83 else
84 {
85 info.contentType = kControlContentCIconHandle ;
86 info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , NULL ,
87 8 , 16 ) ;
88 }
89 }
90 else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
91 {
92 info.contentType = kControlContentCIconHandle ;
93 info.u.cIconHandle = bmap->m_hIcon ;
94 }
95 }
96
97 ::SetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
98
99 MacPostControlCreate() ;
100
101 return TRUE;
102}
103
104void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
105{
106 ControlButtonContentInfo info ;
107 m_buttonBitmap = bitmap;
108
109 if ( m_buttonBitmap.Ok() )
110 {
111 wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
112 if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
113 info.contentType = kControlContentPictHandle ;
114 info.u.picture = bmap->m_hPict ;
115 }
116 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
117 {
118 if ( m_buttonBitmap.GetMask() )
119 {
120 info.contentType = kControlContentCIconHandle ;
121 info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ,
122 8 , 16 ) ;
123 }
124 else
125 {
126 info.contentType = kControlContentCIconHandle ;
127 info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , NULL ,
128 8 , 16 ) ;
129 }
130 }
131 else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
132 {
133 info.contentType = kControlContentCIconHandle ;
134 info.u.cIconHandle = bmap->m_hIcon ;
135 }
136
137
138 ::SetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
139 }
140}
141