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