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