]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/bmpbuttn.cpp
Fixed saving GIFs on big-endian architectures.
[wxWidgets.git] / src / msw / bmpbuttn.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/bmpbuttn.cpp
3// Purpose: wxBitmapButton
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#if wxUSE_BMPBUTTON
20
21#include "wx/bmpbuttn.h"
22
23#ifndef WX_PRECOMP
24 #include "wx/log.h"
25 #include "wx/dcmemory.h"
26 #include "wx/image.h"
27#endif
28
29#include "wx/msw/private.h"
30#include "wx/msw/dc.h" // for wxDCTemp
31
32#include "wx/msw/uxtheme.h"
33
34#if wxUSE_UXTHEME
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
52
53// ----------------------------------------------------------------------------
54// macros
55// ----------------------------------------------------------------------------
56
57BEGIN_EVENT_TABLE(wxBitmapButton, wxBitmapButtonBase)
58 EVT_SYS_COLOUR_CHANGED(wxBitmapButton::OnSysColourChanged)
59END_EVENT_TABLE()
60
61/*
62TODO PROPERTIES :
63
64long "style" , wxBU_AUTODRAW
65bool "default" , 0
66bitmap "selected" ,
67bitmap "focus" ,
68bitmap "disabled" ,
69*/
70
71bool wxBitmapButton::Create(wxWindow *parent,
72 wxWindowID id,
73 const wxBitmap& bitmap,
74 const wxPoint& pos,
75 const wxSize& size, long style,
76 const wxValidator& validator,
77 const wxString& name)
78{
79 if ( !wxBitmapButtonBase::Create(parent, id, pos, size, style,
80 validator, name) )
81 return false;
82
83 if ( bitmap.IsOk() )
84 SetBitmapLabel(bitmap);
85
86 if ( !size.IsFullySpecified() )
87 {
88 // As our bitmap has just changed, our best size has changed as well so
89 // reset the initial size using the new value.
90 SetInitialSize(size);
91 }
92
93 return true;
94}
95
96void wxBitmapButton::DoSetBitmap(const wxBitmap& bitmap, State which)
97{
98 if ( bitmap.IsOk() )
99 {
100 switch ( which )
101 {
102#if wxUSE_IMAGE
103 case State_Normal:
104 if ( !HasFlag(wxBU_AUTODRAW) && !m_disabledSetByUser )
105 {
106 wxImage img(bitmap.ConvertToImage().ConvertToGreyscale());
107 wxBitmapButtonBase::DoSetBitmap(img, State_Disabled);
108 }
109 break;
110#endif // wxUSE_IMAGE
111
112 case State_Focused:
113 // if the focus bitmap is specified but current one isn't, use
114 // the focus bitmap for hovering as well if this is consistent
115 // with the current Windows version look and feel
116 //
117 // rationale: this is compatible with the old wxGTK behaviour
118 // and also makes it much easier to do "the right thing" for
119 // all platforms (some of them, such as Windows XP, have "hot"
120 // buttons while others don't)
121 if ( !m_hoverSetByUser )
122 wxBitmapButtonBase::DoSetBitmap(bitmap, State_Current);
123 break;
124
125 case State_Current:
126 // don't overwrite it with the focused bitmap
127 m_hoverSetByUser = true;
128 break;
129
130 case State_Disabled:
131 // don't overwrite it with the version automatically created
132 // from the normal one
133 m_disabledSetByUser = true;
134 break;
135
136 default:
137 // nothing special to do but include the default clause to
138 // suppress gcc warnings
139 ;
140 }
141 }
142
143 wxBitmapButtonBase::DoSetBitmap(bitmap, which);
144}
145
146#endif // wxUSE_BMPBUTTON