]> git.saurik.com Git - wxWidgets.git/blob - src/os2/checkbox.cpp
fix for incorrect member initialization order warning
[wxWidgets.git] / src / os2 / checkbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: checkbox.cpp
3 // Purpose: wxCheckBox
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/13/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/checkbox.h"
17 #include "wx/brush.h"
18 #include "wx/scrolwin.h"
19 #include "wx/dcscreen.h"
20 #include "wx/settings.h"
21 #endif
22
23 #include "wx/os2/private.h"
24
25 // ----------------------------------------------------------------------------
26 // macros
27 // ----------------------------------------------------------------------------
28
29 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
30 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
31
32 extern void wxAssociateWinWithHandle( HWND hWnd
33 ,wxWindowOS2* pWin
34 );
35
36 // ============================================================================
37 // implementation
38 // ============================================================================
39
40 // ----------------------------------------------------------------------------
41 // wxCheckBox
42 // ----------------------------------------------------------------------------
43
44 bool wxCheckBox::OS2Command( WXUINT WXUNUSED(uParam),
45 WXWORD WXUNUSED(wId) )
46 {
47 wxCommandEvent rEvent( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
48 rEvent.SetInt(GetValue());
49 rEvent.SetEventObject(this);
50 ProcessCommand(rEvent);
51 return true;
52 } // end of wxCheckBox::OS2Command
53
54 bool wxCheckBox::Create(
55 wxWindow* pParent
56 , wxWindowID vId
57 , const wxString& rsLabel
58 , const wxPoint& rPos
59 , const wxSize& rSize
60 , long lStyle
61 , const wxValidator& rValidator
62 , const wxString& rsName
63 )
64 {
65 LONG lColor;
66 bool bOk;
67
68 if (!CreateControl( pParent
69 ,vId
70 ,rPos
71 ,rSize
72 ,lStyle
73 ,rValidator
74 ,rsName
75 ))
76 return FALSE;
77
78
79 long osStyle = BS_AUTOCHECKBOX |
80 WS_TABSTOP |
81 WS_VISIBLE;
82
83 bOk = OS2CreateControl( wxT("BUTTON")
84 ,osStyle
85 ,rPos
86 ,rSize
87 ,rsLabel
88 ,0
89 );
90 m_backgroundColour = pParent->GetBackgroundColour();
91 lColor = (LONG)m_backgroundColour.GetPixel();
92 ::WinSetPresParam( m_hWnd
93 ,PP_BACKGROUNDCOLOR
94 ,sizeof(LONG)
95 ,(PVOID)&lColor
96 );
97 wxAssociateWinWithHandle(m_hWnd, this);
98 return bOk;
99 } // end of wxCheckBox::Create
100
101 void wxCheckBox::SetLabel(
102 const wxString& rsLabel
103 )
104 {
105 wxString sLabel=::wxPMTextToLabel(rsLabel);
106 ::WinSetWindowText(GetHwnd(), (PSZ)sLabel.c_str());
107 } // end of wxCheckBox::SetLabel
108
109 wxSize wxCheckBox::DoGetBestSize() const
110 {
111 static int nCheckSize = 0;
112
113 if (!nCheckSize)
114 {
115 wxScreenDC vDc;
116
117 vDc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
118
119 //
120 // The height of a standard button in the dialog units is 8,
121 // translate this to pixels (as one dialog unit is precisely equal to
122 // 8 character heights, it's just the char height)
123 //
124 nCheckSize = vDc.GetCharHeight();
125 }
126
127 int nWidthCheckbox;
128 int nHeightCheckbox;
129 wxString sStr = wxGetWindowText(GetHWND());
130
131 if (!sStr.empty())
132 {
133 GetTextExtent( sStr
134 ,&nWidthCheckbox
135 ,&nHeightCheckbox
136 );
137 nWidthCheckbox += nCheckSize + GetCharWidth();
138
139 if (nHeightCheckbox < nCheckSize)
140 nHeightCheckbox = nCheckSize;
141 }
142 else
143 {
144 nWidthCheckbox = nCheckSize;
145 nHeightCheckbox = nCheckSize;
146 }
147
148 return wxSize( nWidthCheckbox
149 ,nHeightCheckbox
150 );
151 } // end of wxCheckBox::DoGetBestSize
152
153 void wxCheckBox::SetValue(
154 bool bValue
155 )
156 {
157 ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0);
158 } // end of wxCheckBox::SetValue
159
160 #ifndef BST_CHECKED
161 #define BST_CHECKED 0x0001
162 #endif
163
164 bool wxCheckBox::GetValue() const
165 {
166 return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L));
167 } // end of wxCheckBox::GetValue
168
169 void wxCheckBox::Command (
170 wxCommandEvent& rEvent
171 )
172 {
173 SetValue((rEvent.GetInt() != 0));
174 ProcessCommand(rEvent);
175 } // end of wxCheckBox:: Command
176
177 // ----------------------------------------------------------------------------
178 // wxBitmapCheckBox
179 // ----------------------------------------------------------------------------
180
181 bool wxBitmapCheckBox::Create( wxWindow* pParent,
182 wxWindowID vId,
183 const wxBitmap* WXUNUSED(pLabel),
184 const wxPoint& rPos,
185 const wxSize& rSize,
186 long lStyle,
187 const wxValidator& rValidator,
188 const wxString& rsName)
189 {
190 SetName(rsName);
191 #if wxUSE_VALIDATORS
192 SetValidator(rValidator);
193 #endif
194 if (pParent)
195 pParent->AddChild(this);
196
197 SetBackgroundColour(pParent->GetBackgroundColour()) ;
198 SetForegroundColour(pParent->GetForegroundColour()) ;
199 m_windowStyle = lStyle;
200
201 if (vId == -1)
202 m_windowId = NewControlId();
203 else
204 m_windowId = vId;
205
206 int nX = rPos.x;
207 int nY = rPos.y;
208 int nWidth = rSize.x;
209 int nHeight = rSize.y;
210
211 m_nCheckWidth = -1 ;
212 m_nCheckHeight = -1 ;
213 // long msStyle = CHECK_FLAGS;
214
215 HWND hButton = 0; // TODO: Create the bitmap checkbox
216
217 m_hWnd = (WXHWND)hButton;
218
219 //
220 // Subclass again for purposes of dialog editing mode
221 //
222 SubclassWin((WXHWND)hButton);
223
224 SetSize( nX
225 ,nY
226 ,nWidth
227 ,nHeight
228 );
229
230 ::WinShowWindow(hButton, TRUE);
231 return true;
232 } // end of wxBitmapCheckBox::Create
233
234 void wxBitmapCheckBox::SetLabel( const wxBitmap& WXUNUSED(rBitmap) )
235 {
236 wxFAIL_MSG(wxT("not implemented"));
237 } // end of wxBitmapCheckBox::SetLabel