]> git.saurik.com Git - wxWidgets.git/blob - src/os2/checkbox.cpp
added container class source
[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 #endif
19
20 #include "wx/os2/private.h"
21
22 // ----------------------------------------------------------------------------
23 // macros
24 // ----------------------------------------------------------------------------
25
26 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
27 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
28
29 // ============================================================================
30 // implementation
31 // ============================================================================
32
33 // ----------------------------------------------------------------------------
34 // wxCheckBox
35 // ----------------------------------------------------------------------------
36
37 bool wxCheckBox::OS2Command(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
38 {
39 wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId);
40 event.SetInt(GetValue());
41 event.SetEventObject(this);
42 ProcessCommand(event);
43 return TRUE;
44 }
45
46 // Single check box item
47 bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
48 const wxPoint& pos,
49 const wxSize& size, long style,
50 #if wxUSE_VALIDATORS
51 const wxValidator& validator,
52 #endif
53 const wxString& name)
54 {
55 SetName(name);
56 #if wxUSE_VALIDATORS
57 SetValidator(validator);
58 #endif
59 if (parent) parent->AddChild(this);
60
61 SetBackgroundColour(parent->GetBackgroundColour()) ;
62 SetForegroundColour(parent->GetForegroundColour()) ;
63
64 m_windowStyle = style;
65
66 wxString Label = label;
67 if (Label == wxT(""))
68 Label = wxT(" "); // Apparently needed or checkbox won't show
69
70 if ( id == -1 )
71 m_windowId = NewControlId();
72 else
73 m_windowId = id;
74
75 int x = pos.x;
76 int y = pos.y;
77 int width = size.x;
78 int height = size.y;
79
80 // TODO: create checkbox
81
82 // Subclass again for purposes of dialog editing mode
83 SubclassWin(m_hWnd);
84
85 SetFont(parent->GetFont());
86
87 SetSize(x, y, width, height);
88
89 return FALSE;
90 }
91
92 void wxCheckBox::SetLabel(const wxString& label)
93 {
94 // TODO
95 }
96
97 wxSize wxCheckBox::DoGetBestSize() const
98 {
99 int wCheckbox, hCheckbox;
100
101 wxString str = wxGetWindowText(GetHWND());
102
103 if ( !str.IsEmpty() )
104 {
105 GetTextExtent(str, &wCheckbox, &hCheckbox);
106 wCheckbox += RADIO_SIZE;
107
108 if ( hCheckbox < RADIO_SIZE )
109 hCheckbox = RADIO_SIZE;
110 }
111 else
112 {
113 wCheckbox = RADIO_SIZE;
114 hCheckbox = RADIO_SIZE;
115 }
116
117 return wxSize(wCheckbox, hCheckbox);
118 }
119
120 void wxCheckBox::SetValue(bool val)
121 {
122 // TODO
123 }
124
125 #ifndef BST_CHECKED
126 #define BST_CHECKED 0x0001
127 #endif
128
129 bool wxCheckBox::GetValue() const
130 {
131 // TODO
132 return FALSE;
133 }
134
135 WXHBRUSH wxCheckBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
136 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
137 {
138 // TODO:
139 /*
140 #if wxUSE_CTL3D
141 if ( m_useCtl3D )
142 {
143 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
144
145 return (WXHBRUSH) hbrush;
146 }
147 #endif
148
149 if (GetParent()->GetTransparentBackground())
150 SetBkMode((HDC) pDC, TRANSPARENT);
151 else
152 SetBkMode((HDC) pDC, OPAQUE);
153
154 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
155 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
156
157 */
158
159 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
160
161
162 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
163 // has a zero usage count.
164 // backgroundBrush->RealizeResource();
165 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
166 }
167
168 void wxCheckBox::Command (wxCommandEvent & event)
169 {
170 SetValue ((event.GetInt() != 0));
171 ProcessCommand (event);
172 }
173
174 // ----------------------------------------------------------------------------
175 // wxBitmapCheckBox
176 // ----------------------------------------------------------------------------
177
178 bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
179 const wxPoint& pos,
180 const wxSize& size, long style,
181 #if wxUSE_VALIDATORS
182 const wxValidator& validator,
183 #endif
184 const wxString& name)
185 {
186 SetName(name);
187 #if wxUSE_VALIDATORS
188 SetValidator(validator);
189 #endif
190 if (parent) parent->AddChild(this);
191
192 SetBackgroundColour(parent->GetBackgroundColour()) ;
193 SetForegroundColour(parent->GetForegroundColour()) ;
194 m_windowStyle = style;
195
196 if ( id == -1 )
197 m_windowId = NewControlId();
198 else
199 m_windowId = id;
200
201 int x = pos.x;
202 int y = pos.y;
203 int width = size.x;
204 int height = size.y;
205
206 checkWidth = -1 ;
207 checkHeight = -1 ;
208 // long msStyle = CHECK_FLAGS;
209
210 HWND wx_button = 0; // TODO: Create the bitmap checkbox
211
212 m_hWnd = (WXHWND)wx_button;
213
214 // Subclass again for purposes of dialog editing mode
215 SubclassWin((WXHWND)wx_button);
216
217 SetSize(x, y, width, height);
218
219 // TODO: ShowWindow(wx_button, SW_SHOW);
220
221 return TRUE;
222 }
223
224 void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap)
225 {
226 wxFAIL_MSG(wxT("not implemented"));
227 }
228