]> git.saurik.com Git - wxWidgets.git/blob - src/os2/checkbox.cpp
implemented menu drawing in the GTK theme
[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 // ============================================================================
33 // implementation
34 // ============================================================================
35
36 // ----------------------------------------------------------------------------
37 // wxCheckBox
38 // ----------------------------------------------------------------------------
39
40 bool wxCheckBox::OS2Command(
41 WXUINT WXUNUSED(uParam)
42 , WXWORD WXUNUSED(wId)
43 )
44 {
45 wxCommandEvent rEvent( wxEVT_COMMAND_CHECKBOX_CLICKED
46 ,m_windowId
47 );
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 #if wxUSE_VALIDATORS
62 , const wxValidator& rValidator
63 #endif
64 , const wxString& rsName
65 )
66 {
67 SetName(rsName);
68 #if wxUSE_VALIDATORS
69 SetValidator(rValidator);
70 #endif
71 if (pParent)
72 pParent->AddChild(this);
73
74 SetBackgroundColour(pParent->GetBackgroundColour());
75 SetForegroundColour(pParent->GetForegroundColour());
76 m_windowStyle = lStyle;
77
78 wxString sLabel = rsLabel;
79
80 if (sLabel == wxT(""))
81 sLabel = wxT(" "); // Apparently needed or checkbox won't show
82
83 if (vId == -1 )
84 m_windowId = NewControlId();
85 else
86 m_windowId = vId;
87
88 int nX = rPos.x;
89 int nY = rPos.y;
90 int nWidth = rSize.x;
91 int nHeight = rSize.y;
92 long lSstyle = 0L;
93
94 lSstyle = BS_AUTOCHECKBOX |
95 WS_TABSTOP |
96 WS_VISIBLE;
97 if (lStyle & wxCLIP_SIBLINGS )
98 lSstyle |= WS_CLIPSIBLINGS;
99
100 m_hWnd = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent)
101 ,WC_BUTTON
102 ,rsLabel.c_str()
103 ,lSstyle
104 ,0, 0, 0, 0
105 ,GetWinHwnd(pParent)
106 ,HWND_TOP
107 ,(HMENU)m_windowId
108 ,NULL
109 ,NULL
110 );
111
112 //
113 // Subclass again for purposes of dialog editing mode
114 //
115 SubclassWin(m_hWnd);
116
117 LONG lColor = (LONG)m_backgroundColour.GetPixel();
118
119 ::WinSetPresParam( m_hWnd
120 ,PP_BACKGROUNDCOLOR
121 ,sizeof(LONG)
122 ,(PVOID)&lColor
123 );
124
125 wxFont* pTextFont = new wxFont( 10
126 ,wxMODERN
127 ,wxNORMAL
128 ,wxNORMAL
129 );
130 SetFont(*pTextFont);
131 SetSize( nX
132 ,nY
133 ,nWidth
134 ,nHeight
135 );
136 delete pTextFont;
137 return TRUE;
138 } // end of wxCheckBox::Create
139
140 void wxCheckBox::SetLabel(
141 const wxString& rsLabel
142 )
143 {
144 ::WinSetWindowText(GetHwnd(), rsLabel.c_str());
145 } // end of wxCheckBox::SetLabel
146
147 wxSize wxCheckBox::DoGetBestSize() const
148 {
149 static int nCheckSize = 0;
150
151 if (!nCheckSize)
152 {
153 wxScreenDC vDc;
154
155 vDc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
156
157 //
158 // The height of a standard button in the dialog units is 8,
159 // translate this to pixels (as one dialog unit is precisely equal to
160 // 8 character heights, it's just the char height)
161 //
162 nCheckSize = vDc.GetCharHeight();
163 }
164
165 int nWidthCheckbox;
166 int nHeightCheckbox;
167 wxString sStr = wxGetWindowText(GetHWND());
168
169 if (!sStr.IsEmpty())
170 {
171 GetTextExtent( sStr
172 ,&nWidthCheckbox
173 ,&nHeightCheckbox
174 );
175 nWidthCheckbox += nCheckSize + GetCharWidth();
176
177 if (nHeightCheckbox < nCheckSize)
178 nHeightCheckbox = nCheckSize;
179 }
180 else
181 {
182 nWidthCheckbox = nCheckSize;
183 nHeightCheckbox = nCheckSize;
184 }
185
186 return wxSize( nWidthCheckbox
187 ,nHeightCheckbox
188 );
189 } // end of wxCheckBox::DoGetBestSize
190
191 void wxCheckBox::SetValue(
192 bool bValue
193 )
194 {
195 ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0);
196 } // end of wxCheckBox::SetValue
197
198 #ifndef BST_CHECKED
199 #define BST_CHECKED 0x0001
200 #endif
201
202 bool wxCheckBox::GetValue() const
203 {
204 return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L));
205 } // end of wxCheckBox::GetValue
206
207 void wxCheckBox::Command (
208 wxCommandEvent& rEvent
209 )
210 {
211 SetValue((rEvent.GetInt() != 0));
212 ProcessCommand(rEvent);
213 } // end of wxCheckBox:: Command
214
215 // ----------------------------------------------------------------------------
216 // wxBitmapCheckBox
217 // ----------------------------------------------------------------------------
218
219 bool wxBitmapCheckBox::Create(
220 wxWindow* pParent
221 , wxWindowID vId
222 , const wxBitmap* pLabel
223 , const wxPoint& rPos
224 , const wxSize& rSize
225 , long lStyle
226 #if wxUSE_VALIDATORS
227 , const wxValidator& rValidator
228 #endif
229 , const wxString& rsName
230 )
231 {
232 SetName(rsName);
233 #if wxUSE_VALIDATORS
234 SetValidator(rValidator);
235 #endif
236 if (pParent)
237 pParent->AddChild(this);
238
239 SetBackgroundColour(pParent->GetBackgroundColour()) ;
240 SetForegroundColour(pParent->GetForegroundColour()) ;
241 m_windowStyle = lStyle;
242
243 if (vId == -1)
244 m_windowId = NewControlId();
245 else
246 m_windowId = vId;
247
248 int nX = rPos.x;
249 int nY = rPos.y;
250 int nWidth = rSize.x;
251 int nHeight = rSize.y;
252
253 m_nCheckWidth = -1 ;
254 m_nCheckHeight = -1 ;
255 // long msStyle = CHECK_FLAGS;
256
257 HWND hButton = 0; // TODO: Create the bitmap checkbox
258
259 m_hWnd = (WXHWND)hButton;
260
261 //
262 // Subclass again for purposes of dialog editing mode
263 //
264 SubclassWin((WXHWND)hButton);
265
266 SetSize( nX
267 ,nY
268 ,nWidth
269 ,nHeight
270 );
271
272 ::WinShowWindow(hButton, TRUE);
273 return TRUE;
274 } // end of wxBitmapCheckBox::Create
275
276 void wxBitmapCheckBox::SetLabel(
277 const wxBitmap& rBitmap
278 )
279 {
280 wxFAIL_MSG(wxT("not implemented"));
281 } // end of wxBitmapCheckBox::SetLabel
282