]> git.saurik.com Git - wxWidgets.git/blame - src/msw/tglbtn.cpp
disable workaround for lack of alpha support in native static bitmap control for...
[wxWidgets.git] / src / msw / tglbtn.cpp
CommitLineData
1db8dc4a
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/tglbtn.cpp
3// Purpose: Definition of the wxToggleButton class, which implements a
4// toggle button under wxMSW.
f1e01716
WS
5// Author: John Norris, minor changes by Axel Schlueter
6// and William Gallafent.
1db8dc4a
VZ
7// Modified by:
8// Created: 08.02.01
9// RCS-ID: $Id$
10// Copyright: (c) 2000 Johnny C. Norris II
706fb893 11// License: wxWindows licence
1db8dc4a
VZ
12/////////////////////////////////////////////////////////////////////////////
13
14// ============================================================================
8907154c 15// declarations
1db8dc4a
VZ
16// ============================================================================
17
18// ----------------------------------------------------------------------------
19// headers
20// ----------------------------------------------------------------------------
21
22#include "wx/wxprec.h"
23
24#ifdef __BORLANDC__
25 #pragma hdrstop
26#endif
27
1db8dc4a
VZ
28#if wxUSE_TOGGLEBTN
29
f1e01716
WS
30#include "wx/tglbtn.h"
31
1db8dc4a
VZ
32#ifndef WX_PRECOMP
33 #include "wx/button.h"
34 #include "wx/brush.h"
35 #include "wx/dcscreen.h"
36 #include "wx/settings.h"
37
38 #include "wx/log.h"
39#endif // WX_PRECOMP
40
41#include "wx/msw/private.h"
9016f3ad 42#include "wx/msw/private/button.h"
1db8dc4a
VZ
43
44// ----------------------------------------------------------------------------
45// macros
46// ----------------------------------------------------------------------------
47
48IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
49DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
50
1db8dc4a
VZ
51// ============================================================================
52// implementation
53// ============================================================================
54
55// ----------------------------------------------------------------------------
56// wxToggleButton
57// ----------------------------------------------------------------------------
58
1db8dc4a 59// Single check box item
9016f3ad
VZ
60bool wxToggleButton::Create(wxWindow *parent,
61 wxWindowID id,
1db8dc4a
VZ
62 const wxString& label,
63 const wxPoint& pos,
64 const wxSize& size, long style,
65 const wxValidator& validator,
66 const wxString& name)
67{
b67e8d38 68 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
bfbb0b4c
WS
69 return false;
70
9016f3ad
VZ
71 // if the label contains several lines we must explicitly tell the button
72 // about it or it wouldn't draw it correctly ("\n"s would just appear as
73 // black boxes)
74 //
75 // NB: we do it here and not in MSWGetStyle() because we need the label
76 // value and the label is not set yet when MSWGetStyle() is called
77 WXDWORD exstyle;
78 WXDWORD msStyle = MSWGetStyle(style, &exstyle);
79 msStyle |= wxMSWButton::GetMultilineStyle(label);
80
81 return MSWCreateControl(_T("BUTTON"), msStyle, pos, size, label, exstyle);
b67e8d38 82}
1db8dc4a 83
b67e8d38
RD
84WXDWORD wxToggleButton::MSWGetStyle(long style, WXDWORD *exstyle) const
85{
86 WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
1db8dc4a 87
b67e8d38 88 msStyle |= BS_AUTOCHECKBOX | BS_PUSHLIKE | WS_TABSTOP;
b0766406 89
9016f3ad 90 if ( style & wxBU_LEFT )
1db8dc4a 91 msStyle |= BS_LEFT;
9016f3ad 92 if ( style & wxBU_RIGHT )
1db8dc4a 93 msStyle |= BS_RIGHT;
9016f3ad 94 if ( style & wxBU_TOP )
1db8dc4a 95 msStyle |= BS_TOP;
9016f3ad 96 if ( style & wxBU_BOTTOM )
1db8dc4a 97 msStyle |= BS_BOTTOM;
1db8dc4a 98
b67e8d38 99 return msStyle;
1db8dc4a
VZ
100}
101
1db8dc4a
VZ
102wxSize wxToggleButton::DoGetBestSize() const
103{
9016f3ad
VZ
104 return wxMSWButton::ComputeBestSize(wx_const_cast(wxToggleButton *, this));
105}
106
107void wxToggleButton::SetLabel(const wxString& label)
108{
109 wxMSWButton::UpdateMultilineStyle(GetHwnd(), label);
110
111 wxToggleButtonBase::SetLabel(label);
1db8dc4a
VZ
112}
113
114void wxToggleButton::SetValue(bool val)
115{
bfbb0b4c 116 ::SendMessage(GetHwnd(), BM_SETCHECK, val, 0);
1db8dc4a
VZ
117}
118
1db8dc4a
VZ
119bool wxToggleButton::GetValue() const
120{
9016f3ad 121 return ::SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED;
1db8dc4a
VZ
122}
123
9016f3ad 124void wxToggleButton::Command(wxCommandEvent& event)
1db8dc4a 125{
9016f3ad
VZ
126 SetValue(event.GetInt() != 0);
127 ProcessCommand(event);
128}
129
130bool wxToggleButton::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
131{
132 wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
133 event.SetInt(GetValue());
134 event.SetEventObject(this);
135 ProcessCommand(event);
136 return true;
1db8dc4a
VZ
137}
138
139#endif // wxUSE_TOGGLEBTN