Lots of updates fixing radiobox processing, checkboxes and add notebook control.
[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(
45 WXUINT WXUNUSED(uParam)
46 , WXWORD WXUNUSED(wId)
47 )
48 {
49 wxCommandEvent rEvent( wxEVT_COMMAND_CHECKBOX_CLICKED
50 ,m_windowId
51 );
52 rEvent.SetInt(GetValue());
53 rEvent.SetEventObject(this);
54 ProcessCommand(rEvent);
55 return TRUE;
56 } // end of wxCheckBox::OS2Command
57
58 bool wxCheckBox::Create(
59 wxWindow* pParent
60 , wxWindowID vId
61 , const wxString& rsLabel
62 , const wxPoint& rPos
63 , const wxSize& rSize
64 , long lStyle
65 #if wxUSE_VALIDATORS
66 , const wxValidator& rValidator
67 #endif
68 , const wxString& rsName
69 )
70 {
71 LONG lColor;
72 bool bOk;
73
74 if (!CreateControl( pParent
75 ,vId
76 ,rPos
77 ,rSize
78 ,lStyle
79 #if wxUSE_VALIDATORS
80 ,rValidator
81 #endif
82 ,rsName
83 ))
84 return FALSE;
85
86
87 long osStyle = BS_AUTOCHECKBOX |
88 WS_TABSTOP |
89 WS_VISIBLE;
90
91 bOk = OS2CreateControl( wxT("BUTTON")
92 ,osStyle
93 ,rPos
94 ,rSize
95 ,rsLabel
96 ,0
97 );
98 m_backgroundColour = pParent->GetBackgroundColour();
99 lColor = (LONG)m_backgroundColour.GetPixel();
100 ::WinSetPresParam( m_hWnd
101 ,PP_BACKGROUNDCOLOR
102 ,sizeof(LONG)
103 ,(PVOID)&lColor
104 );
105 wxAssociateWinWithHandle(m_hWnd, this);
106 return bOk;
107 } // end of wxCheckBox::Create
108
109 void wxCheckBox::SetLabel(
110 const wxString& rsLabel
111 )
112 {
113 ::WinSetWindowText(GetHwnd(), rsLabel.c_str());
114 } // end of wxCheckBox::SetLabel
115
116 wxSize wxCheckBox::DoGetBestSize() const
117 {
118 static int nCheckSize = 0;
119
120 if (!nCheckSize)
121 {
122 wxScreenDC vDc;
123
124 vDc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
125
126 //
127 // The height of a standard button in the dialog units is 8,
128 // translate this to pixels (as one dialog unit is precisely equal to
129 // 8 character heights, it's just the char height)
130 //
131 nCheckSize = vDc.GetCharHeight();
132 }
133
134 int nWidthCheckbox;
135 int nHeightCheckbox;
136 wxString sStr = wxGetWindowText(GetHWND());
137
138 if (!sStr.IsEmpty())
139 {
140 GetTextExtent( sStr
141 ,&nWidthCheckbox
142 ,&nHeightCheckbox
143 );
144 nWidthCheckbox += nCheckSize + GetCharWidth();
145
146 if (nHeightCheckbox < nCheckSize)
147 nHeightCheckbox = nCheckSize;
148 }
149 else
150 {
151 nWidthCheckbox = nCheckSize;
152 nHeightCheckbox = nCheckSize;
153 }
154
155 return wxSize( nWidthCheckbox
156 ,nHeightCheckbox
157 );
158 } // end of wxCheckBox::DoGetBestSize
159
160 void wxCheckBox::SetValue(
161 bool bValue
162 )
163 {
164 ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0);
165 } // end of wxCheckBox::SetValue
166
167 #ifndef BST_CHECKED
168 #define BST_CHECKED 0x0001
169 #endif
170
171 bool wxCheckBox::GetValue() const
172 {
173 return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L));
174 } // end of wxCheckBox::GetValue
175
176 void wxCheckBox::Command (
177 wxCommandEvent& rEvent
178 )
179 {
180 SetValue((rEvent.GetInt() != 0));
181 ProcessCommand(rEvent);
182 } // end of wxCheckBox:: Command
183
184 // ----------------------------------------------------------------------------
185 // wxBitmapCheckBox
186 // ----------------------------------------------------------------------------
187
188 bool wxBitmapCheckBox::Create(
189 wxWindow* pParent
190 , wxWindowID vId
191 , const wxBitmap* pLabel
192 , const wxPoint& rPos
193 , const wxSize& rSize
194 , long lStyle
195 #if wxUSE_VALIDATORS
196 , const wxValidator& rValidator
197 #endif
198 , const wxString& rsName
199 )
200 {
201 SetName(rsName);
202 #if wxUSE_VALIDATORS
203 SetValidator(rValidator);
204 #endif
205 if (pParent)
206 pParent->AddChild(this);
207
208 SetBackgroundColour(pParent->GetBackgroundColour()) ;
209 SetForegroundColour(pParent->GetForegroundColour()) ;
210 m_windowStyle = lStyle;
211
212 if (vId == -1)
213 m_windowId = NewControlId();
214 else
215 m_windowId = vId;
216
217 int nX = rPos.x;
218 int nY = rPos.y;
219 int nWidth = rSize.x;
220 int nHeight = rSize.y;
221
222 m_nCheckWidth = -1 ;
223 m_nCheckHeight = -1 ;
224 // long msStyle = CHECK_FLAGS;
225
226 HWND hButton = 0; // TODO: Create the bitmap checkbox
227
228 m_hWnd = (WXHWND)hButton;
229
230 //
231 // Subclass again for purposes of dialog editing mode
232 //
233 SubclassWin((WXHWND)hButton);
234
235 SetSize( nX
236 ,nY
237 ,nWidth
238 ,nHeight
239 );
240
241 ::WinShowWindow(hButton, TRUE);
242 return TRUE;
243 } // end of wxBitmapCheckBox::Create
244
245 void wxBitmapCheckBox::SetLabel(
246 const wxBitmap& rBitmap
247 )
248 {
249 wxFAIL_MSG(wxT("not implemented"));
250 } // end of wxBitmapCheckBox::SetLabel
251