]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
1e6feb95 | 2 | // Name: src/msw/bmpbuttn.cpp |
2bda0e17 KB |
3 | // Purpose: wxBitmapButton |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
2bda0e17 KB |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
1e6feb95 | 16 | #pragma hdrstop |
2bda0e17 KB |
17 | #endif |
18 | ||
1e6feb95 VZ |
19 | #if wxUSE_BMPBUTTON |
20 | ||
910b0053 WS |
21 | #include "wx/bmpbuttn.h" |
22 | ||
2bda0e17 | 23 | #ifndef WX_PRECOMP |
84f19880 | 24 | #include "wx/log.h" |
47e92c41 | 25 | #include "wx/dcmemory.h" |
155ecd4c | 26 | #include "wx/image.h" |
2bda0e17 KB |
27 | #endif |
28 | ||
29 | #include "wx/msw/private.h" | |
025f7d77 | 30 | #include "wx/msw/dc.h" // for wxDCTemp |
4e9da8b7 | 31 | |
37005692 | 32 | #include "wx/msw/uxtheme.h" |
4e9da8b7 | 33 | |
37005692 | 34 | #if wxUSE_UXTHEME |
4e9da8b7 RD |
35 | // no need to include tmschema.h |
36 | #ifndef BP_PUSHBUTTON | |
37 | #define BP_PUSHBUTTON 1 | |
38 | ||
39 | #define PBS_NORMAL 1 | |
40 | #define PBS_HOT 2 | |
41 | #define PBS_PRESSED 3 | |
42 | #define PBS_DISABLED 4 | |
43 | #define PBS_DEFAULTED 5 | |
44 | ||
45 | #define TMT_CONTENTMARGINS 3602 | |
46 | #endif | |
47 | #endif // wxUSE_UXTHEME | |
48 | ||
49 | #ifndef ODS_NOFOCUSRECT | |
50 | #define ODS_NOFOCUSRECT 0x0200 | |
51 | #endif | |
2bda0e17 | 52 | |
bc9fb572 JS |
53 | // ---------------------------------------------------------------------------- |
54 | // macros | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
57 | #if wxUSE_EXTENDED_RTTI | |
58 | ||
59 | WX_DEFINE_FLAGS( wxBitmapButtonStyle ) | |
60 | ||
3ff066a4 | 61 | wxBEGIN_FLAGS( wxBitmapButtonStyle ) |
bc9fb572 JS |
62 | // new style border flags, we put them first to |
63 | // use them for streaming out | |
3ff066a4 SC |
64 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
65 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
66 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
67 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
68 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
69 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
fcf90ee1 | 70 | |
bc9fb572 | 71 | // old style border flags |
3ff066a4 SC |
72 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
73 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
74 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
75 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
76 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 77 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
78 | |
79 | // standard window styles | |
3ff066a4 SC |
80 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
81 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
82 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
83 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 84 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
85 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
86 | wxFLAGS_MEMBER(wxVSCROLL) | |
87 | wxFLAGS_MEMBER(wxHSCROLL) | |
88 | ||
89 | wxFLAGS_MEMBER(wxBU_AUTODRAW) | |
90 | wxFLAGS_MEMBER(wxBU_LEFT) | |
91 | wxFLAGS_MEMBER(wxBU_RIGHT) | |
92 | wxFLAGS_MEMBER(wxBU_TOP) | |
93 | wxFLAGS_MEMBER(wxBU_BOTTOM) | |
94 | wxEND_FLAGS( wxBitmapButtonStyle ) | |
bc9fb572 JS |
95 | |
96 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxBitmapButton, wxButton,"wx/bmpbuttn.h") | |
97 | ||
3ff066a4 | 98 | wxBEGIN_PROPERTIES_TABLE(wxBitmapButton) |
af498247 | 99 | wxPROPERTY_FLAGS( WindowStyle , wxBitmapButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
3ff066a4 | 100 | wxEND_PROPERTIES_TABLE() |
bc9fb572 | 101 | |
3ff066a4 SC |
102 | wxBEGIN_HANDLERS_TABLE(wxBitmapButton) |
103 | wxEND_HANDLERS_TABLE() | |
bc9fb572 | 104 | |
3ff066a4 | 105 | wxCONSTRUCTOR_5( wxBitmapButton , wxWindow* , Parent , wxWindowID , Id , wxBitmap , Bitmap , wxPoint , Position , wxSize , Size ) |
bc9fb572 JS |
106 | |
107 | #else | |
2bda0e17 | 108 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) |
bc9fb572 | 109 | #endif |
2bda0e17 | 110 | |
a6fd0fde VZ |
111 | BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase) |
112 | EVT_SYS_COLOUR_CHANGED(wxBitmapButton::OnSysColourChanged) | |
113 | END_EVENT_TABLE() | |
114 | ||
066f1b7a SC |
115 | /* |
116 | TODO PROPERTIES : | |
117 | ||
118 | long "style" , wxBU_AUTODRAW | |
119 | bool "default" , 0 | |
120 | bitmap "selected" , | |
121 | bitmap "focus" , | |
122 | bitmap "disabled" , | |
123 | */ | |
124 | ||
56c74796 VZ |
125 | bool wxBitmapButton::Create(wxWindow *parent, |
126 | wxWindowID id, | |
127 | const wxBitmap& bitmap, | |
128 | const wxPoint& pos, | |
129 | const wxSize& size, long style, | |
b4bde7a7 | 130 | const wxValidator& validator, |
56c74796 | 131 | const wxString& name) |
2bda0e17 | 132 | { |
8e4c2912 | 133 | if ( !wxBitmapButtonBase::Create(parent, id, pos, size, style, |
a2117591 | 134 | validator, name) ) |
56c74796 | 135 | return false; |
2bda0e17 | 136 | |
56c74796 | 137 | SetBitmapLabel(bitmap); |
2bda0e17 | 138 | |
e9f935cb VZ |
139 | if ( !size.IsFullySpecified() ) |
140 | { | |
141 | // As our bitmap has just changed, our best size has changed as well so | |
142 | // reset the initial size using the new value. | |
143 | SetInitialSize(size); | |
144 | } | |
145 | ||
d50dbf7c VZ |
146 | return true; |
147 | } | |
148 | ||
2352862a | 149 | void wxBitmapButton::DoSetBitmap(const wxBitmap& bitmap, State which) |
5f1f21d2 | 150 | { |
2352862a | 151 | if ( bitmap.IsOk() ) |
5f1f21d2 | 152 | { |
2352862a VZ |
153 | switch ( which ) |
154 | { | |
155 | #if wxUSE_IMAGE | |
156 | case State_Normal: | |
157 | if ( !HasFlag(wxBU_AUTODRAW) && !m_disabledSetByUser ) | |
158 | { | |
159 | wxImage img(bitmap.ConvertToImage().ConvertToGreyscale()); | |
a6fd73d3 | 160 | wxBitmapButtonBase::DoSetBitmap(img, State_Disabled); |
2352862a VZ |
161 | } |
162 | break; | |
5f1f21d2 VZ |
163 | #endif // wxUSE_IMAGE |
164 | ||
2352862a VZ |
165 | case State_Focused: |
166 | // if the focus bitmap is specified but current one isn't, use | |
167 | // the focus bitmap for hovering as well if this is consistent | |
168 | // with the current Windows version look and feel | |
169 | // | |
170 | // rationale: this is compatible with the old wxGTK behaviour | |
171 | // and also makes it much easier to do "the right thing" for | |
172 | // all platforms (some of them, such as Windows XP, have "hot" | |
173 | // buttons while others don't) | |
174 | if ( !m_hoverSetByUser ) | |
a6fd73d3 | 175 | wxBitmapButtonBase::DoSetBitmap(bitmap, State_Current); |
2352862a VZ |
176 | break; |
177 | ||
178 | case State_Current: | |
179 | // don't overwrite it with the focused bitmap | |
180 | m_hoverSetByUser = true; | |
181 | break; | |
182 | ||
183 | case State_Disabled: | |
184 | // don't overwrite it with the version automatically created | |
185 | // from the normal one | |
186 | m_disabledSetByUser = true; | |
187 | break; | |
4d51143c VZ |
188 | |
189 | default: | |
190 | // nothing special to do but include the default clause to | |
191 | // suppress gcc warnings | |
192 | ; | |
2352862a VZ |
193 | } |
194 | } | |
5f1f21d2 | 195 | |
2352862a | 196 | wxBitmapButtonBase::DoSetBitmap(bitmap, which); |
7996ff80 VZ |
197 | } |
198 | ||
1e6feb95 | 199 | #endif // wxUSE_BMPBUTTON |