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