]> git.saurik.com Git - wxWidgets.git/blame - src/univ/bmpbuttn.cpp
Generate wxPropertyGrid splitter (column divider) events: wxEVT_PG_COL_BEGIN_DRAG...
[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
41IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
42
43BEGIN_EVENT_TABLE(wxBitmapButton, wxButton)
44 EVT_SET_FOCUS(wxBitmapButton::OnSetFocus)
45 EVT_KILL_FOCUS(wxBitmapButton::OnKillFocus)
46END_EVENT_TABLE()
47
48// ----------------------------------------------------------------------------
49// wxBitmapButton
50// ----------------------------------------------------------------------------
51
52bool wxBitmapButton::Create(wxWindow *parent,
53 wxWindowID id,
54 const wxBitmap& bitmap,
55 const wxPoint &pos,
56 const wxSize &size,
57 long style,
58 const wxValidator& validator,
59 const wxString &name)
60{
ef2f095a
VZ
61 // we add wxBU_EXACTFIT because the bitmap buttons are not the standard
62 // ones and so shouldn't be forced to be of the standard size which is
63 // typically too big for them
0966aee3 64 if ( !wxButton::Create(parent, id, bitmap, wxEmptyString,
ef2f095a 65 pos, size, style | wxBU_EXACTFIT, validator, name) )
a290fa5a 66 return false;
1e6feb95 67
2352862a 68 m_bitmaps[State_Normal] = bitmap;
1e6feb95 69
a290fa5a 70 return true;
1e6feb95
VZ
71}
72
73void wxBitmapButton::OnSetBitmap()
74{
75 wxBitmap bmp;
76 if ( !IsEnabled() )
77 {
2352862a 78 bmp = GetBitmapDisabled();
1e6feb95
VZ
79 }
80 else if ( IsPressed() )
81 {
2352862a 82 bmp = GetBitmapPressed();
1e6feb95
VZ
83 }
84 else if ( IsFocused() )
85 {
2352862a 86 bmp = GetBitmapFocus();
1e6feb95 87 }
2352862a 88 //else: just leave it invalid, this means "normal" anyhow in ChangeBitmap()
1e6feb95
VZ
89
90 ChangeBitmap(bmp);
91}
92
93bool wxBitmapButton::ChangeBitmap(const wxBitmap& bmp)
94{
2352862a 95 wxBitmap bitmap = bmp.IsOk() ? bmp : GetBitmapLabel();
d6dc5c6f
VZ
96 if ( bitmap.IsSameAs(m_bitmap) )
97 return false;
1e6feb95 98
d6dc5c6f 99 m_bitmap = bitmap;
1e6feb95 100
d6dc5c6f 101 return true;
1e6feb95
VZ
102}
103
104bool wxBitmapButton::Enable(bool enable)
105{
106 if ( !wxButton::Enable(enable) )
a290fa5a 107 return false;
1e6feb95 108
2352862a 109 if ( !enable && ChangeBitmap(GetBitmapDisabled()) )
1e6feb95
VZ
110 Refresh();
111
a290fa5a 112 return true;
1e6feb95
VZ
113}
114
115bool wxBitmapButton::SetCurrent(bool doit)
116{
2352862a 117 ChangeBitmap(doit ? GetBitmapFocus() : GetBitmapLabel());
1e6feb95
VZ
118
119 return wxButton::SetCurrent(doit);
120}
121
122void wxBitmapButton::OnSetFocus(wxFocusEvent& event)
123{
2352862a 124 if ( ChangeBitmap(GetBitmapFocus()) )
1e6feb95
VZ
125 Refresh();
126
127 event.Skip();
128}
129
130void wxBitmapButton::OnKillFocus(wxFocusEvent& event)
131{
2352862a 132 if ( ChangeBitmap(GetBitmapLabel()) )
1e6feb95
VZ
133 Refresh();
134
135 event.Skip();
136}
137
138void wxBitmapButton::Press()
139{
2352862a 140 ChangeBitmap(GetBitmapPressed());
1e6feb95
VZ
141
142 wxButton::Press();
143}
144
145void wxBitmapButton::Release()
146{
2352862a 147 ChangeBitmap(IsFocused() ? GetBitmapFocus() : GetBitmapLabel());
1e6feb95
VZ
148
149 wxButton::Release();
150}
151
152#endif // wxUSE_BMPBUTTON