]> git.saurik.com Git - wxWidgets.git/blame - src/msw/checkbox.cpp
fixed wxBase and GUI separation for sockets code
[wxWidgets.git] / src / msw / checkbox.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
2b5f62a0 2// Name: msw/checkbox.cpp
2bda0e17
KB
3// Purpose: wxCheckBox
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
4438caf4
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
4438caf4 21 #pragma implementation "checkbox.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
4438caf4 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
1e6feb95
VZ
31#if wxUSE_CHECKBOX
32
2bda0e17 33#ifndef WX_PRECOMP
4438caf4
VZ
34 #include "wx/checkbox.h"
35 #include "wx/brush.h"
f6bcfd97
BP
36 #include "wx/dcscreen.h"
37 #include "wx/settings.h"
2bda0e17
KB
38#endif
39
40#include "wx/msw/private.h"
41
2b5f62a0
VZ
42#ifndef BST_CHECKED
43 #define BST_CHECKED 0x0001
44#endif
2bda0e17 45
4438caf4
VZ
46// ============================================================================
47// implementation
48// ============================================================================
49
2b5f62a0
VZ
50IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
51
066f1b7a
SC
52/*
53TODO PROPERTIES :
54
55bool "checked" , 0
56*/
57
4438caf4
VZ
58// ----------------------------------------------------------------------------
59// wxCheckBox
60// ----------------------------------------------------------------------------
61
debe6624 62bool wxCheckBox::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
2bda0e17 63{
4438caf4
VZ
64 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId);
65 event.SetInt(GetValue());
66 event.SetEventObject(this);
67 ProcessCommand(event);
68 return TRUE;
2bda0e17
KB
69}
70
11b6a93b
VZ
71bool wxCheckBox::Create(wxWindow *parent,
72 wxWindowID id,
73 const wxString& label,
74 const wxPoint& pos,
75 const wxSize& size, long style,
76 const wxValidator& validator,
77 const wxString& name)
2bda0e17 78{
787a85c2 79 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
8912d7eb 80 return FALSE;
4438caf4 81
8912d7eb 82 long msStyle = BS_AUTOCHECKBOX | WS_TABSTOP;
4438caf4
VZ
83 if ( style & wxALIGN_RIGHT )
84 msStyle |= BS_LEFTTEXT;
85
8912d7eb 86 return MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, 0);
2bda0e17
KB
87}
88
89void wxCheckBox::SetLabel(const wxString& label)
90{
f6bcfd97 91 SetWindowText(GetHwnd(), label);
2bda0e17
KB
92}
93
f68586e5 94wxSize wxCheckBox::DoGetBestSize() const
2bda0e17 95{
f6bcfd97 96 static int s_checkSize = 0;
81d66cf3 97
f6bcfd97
BP
98 if ( !s_checkSize )
99 {
100 wxScreenDC dc;
a756f210 101 dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
2bda0e17 102
fb1a41cd 103 s_checkSize = dc.GetCharHeight();
f6bcfd97
BP
104 }
105
106 wxString str = wxGetWindowText(GetHWND());
107
108 int wCheckbox, hCheckbox;
4438caf4
VZ
109 if ( !str.IsEmpty() )
110 {
111 GetTextExtent(str, &wCheckbox, &hCheckbox);
f6bcfd97 112 wCheckbox += s_checkSize + GetCharWidth();
27fda0b6 113
f6bcfd97
BP
114 if ( hCheckbox < s_checkSize )
115 hCheckbox = s_checkSize;
4438caf4
VZ
116 }
117 else
2bda0e17 118 {
f6bcfd97
BP
119 wCheckbox = s_checkSize;
120 hCheckbox = s_checkSize;
2bda0e17
KB
121 }
122
4438caf4 123 return wxSize(wCheckbox, hCheckbox);
2bda0e17
KB
124}
125
debe6624 126void wxCheckBox::SetValue(bool val)
2bda0e17 127{
4438caf4 128 SendMessage(GetHwnd(), BM_SETCHECK, val, 0);
2bda0e17
KB
129}
130
bfc6fde4 131bool wxCheckBox::GetValue() const
2bda0e17 132{
2b5f62a0 133 return (SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) & BST_CHECKED) != 0;
2bda0e17
KB
134}
135
2b5f62a0 136void wxCheckBox::Command(wxCommandEvent& event)
2bda0e17 137{
2b5f62a0
VZ
138 SetValue(event.GetInt() != 0);
139 ProcessCommand(event);
2bda0e17 140}
1e6feb95
VZ
141
142#endif // wxUSE_CHECKBOX