]> git.saurik.com Git - wxWidgets.git/blame - src/univ/bmpbuttn.cpp
Added box style functionality to style manager dialog
[wxWidgets.git] / src / univ / bmpbuttn.cpp
CommitLineData
1e6feb95 1/////////////////////////////////////////////////////////////////////////////
910b0053 2// Name: src/univ/bmpbuttn.cpp
1e6feb95
VZ
3// Purpose: wxBitmapButton implementation
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 25.08.00
7// RCS-ID: $Id$
442b35b5 8// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
1e6feb95
VZ
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#if wxUSE_BMPBUTTON
27
910b0053
WS
28#include "wx/bmpbuttn.h"
29
1e6feb95
VZ
30#ifndef WX_PRECOMP
31 #include "wx/dc.h"
1e6feb95
VZ
32 #include "wx/validate.h"
33#endif
34
35#include "wx/univ/renderer.h"
36
37// ============================================================================
38// implementation
39// ============================================================================
40
1e6feb95
VZ
41BEGIN_EVENT_TABLE(wxBitmapButton, wxButton)
42 EVT_SET_FOCUS(wxBitmapButton::OnSetFocus)
43 EVT_KILL_FOCUS(wxBitmapButton::OnKillFocus)
44END_EVENT_TABLE()
45
46// ----------------------------------------------------------------------------
47// wxBitmapButton
48// ----------------------------------------------------------------------------
49
50bool wxBitmapButton::Create(wxWindow *parent,
51 wxWindowID id,
52 const wxBitmap& bitmap,
53 const wxPoint &pos,
54 const wxSize &size,
55 long style,
56 const wxValidator& validator,
57 const wxString &name)
58{
ef2f095a
VZ
59 // we add wxBU_EXACTFIT because the bitmap buttons are not the standard
60 // ones and so shouldn't be forced to be of the standard size which is
61 // typically too big for them
0966aee3 62 if ( !wxButton::Create(parent, id, bitmap, wxEmptyString,
ef2f095a 63 pos, size, style | wxBU_EXACTFIT, validator, name) )
a290fa5a 64 return false;
1e6feb95 65
2352862a 66 m_bitmaps[State_Normal] = bitmap;
1e6feb95 67
a290fa5a 68 return true;
1e6feb95
VZ
69}
70
71void wxBitmapButton::OnSetBitmap()
72{
73 wxBitmap bmp;
74 if ( !IsEnabled() )
75 {
2352862a 76 bmp = GetBitmapDisabled();
1e6feb95
VZ
77 }
78 else if ( IsPressed() )
79 {
2352862a 80 bmp = GetBitmapPressed();
1e6feb95
VZ
81 }
82 else if ( IsFocused() )
83 {
2352862a 84 bmp = GetBitmapFocus();
1e6feb95 85 }
2352862a 86 //else: just leave it invalid, this means "normal" anyhow in ChangeBitmap()
1e6feb95
VZ
87
88 ChangeBitmap(bmp);
89}
90
91bool wxBitmapButton::ChangeBitmap(const wxBitmap& bmp)
92{
2352862a 93 wxBitmap bitmap = bmp.IsOk() ? bmp : GetBitmapLabel();
d6dc5c6f
VZ
94 if ( bitmap.IsSameAs(m_bitmap) )
95 return false;
1e6feb95 96
d6dc5c6f 97 m_bitmap = bitmap;
1e6feb95 98
d6dc5c6f 99 return true;
1e6feb95
VZ
100}
101
102bool wxBitmapButton::Enable(bool enable)
103{
104 if ( !wxButton::Enable(enable) )
a290fa5a 105 return false;
1e6feb95 106
2352862a 107 if ( !enable && ChangeBitmap(GetBitmapDisabled()) )
1e6feb95
VZ
108 Refresh();
109
a290fa5a 110 return true;
1e6feb95
VZ
111}
112
113bool wxBitmapButton::SetCurrent(bool doit)
114{
2352862a 115 ChangeBitmap(doit ? GetBitmapFocus() : GetBitmapLabel());
1e6feb95
VZ
116
117 return wxButton::SetCurrent(doit);
118}
119
120void wxBitmapButton::OnSetFocus(wxFocusEvent& event)
121{
2352862a 122 if ( ChangeBitmap(GetBitmapFocus()) )
1e6feb95
VZ
123 Refresh();
124
125 event.Skip();
126}
127
128void wxBitmapButton::OnKillFocus(wxFocusEvent& event)
129{
2352862a 130 if ( ChangeBitmap(GetBitmapLabel()) )
1e6feb95
VZ
131 Refresh();
132
133 event.Skip();
134}
135
136void wxBitmapButton::Press()
137{
2352862a 138 ChangeBitmap(GetBitmapPressed());
1e6feb95
VZ
139
140 wxButton::Press();
141}
142
143void wxBitmapButton::Release()
144{
2352862a 145 ChangeBitmap(IsFocused() ? GetBitmapFocus() : GetBitmapLabel());
1e6feb95
VZ
146
147 wxButton::Release();
148}
149
150#endif // wxUSE_BMPBUTTON