Update makefile and module def for new dynlib stuff. Also some control colouring...
[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 LONG lColor = (LONG)m_backgroundColour.GetPixel();
86
87 ::WinSetPresParam( m_hWnd
88 ,PP_BACKGROUNDCOLOR
89 ,sizeof(LONG)
90 ,(PVOID)&lColor
91 );
92
93 SetFont(parent->GetFont());
94
95 SetSize(x, y, width, height);
96
97 return FALSE;
98 }
99
100 void wxCheckBox::SetLabel(const wxString& label)
101 {
102 // TODO
103 }
104
105 wxSize wxCheckBox::DoGetBestSize() const
106 {
107 int wCheckbox, hCheckbox;
108
109 wxString str = wxGetWindowText(GetHWND());
110
111 if ( !str.IsEmpty() )
112 {
113 GetTextExtent(str, &wCheckbox, &hCheckbox);
114 wCheckbox += RADIO_SIZE;
115
116 if ( hCheckbox < RADIO_SIZE )
117 hCheckbox = RADIO_SIZE;
118 }
119 else
120 {
121 wCheckbox = RADIO_SIZE;
122 hCheckbox = RADIO_SIZE;
123 }
124
125 return wxSize(wCheckbox, hCheckbox);
126 }
127
128 void wxCheckBox::SetValue(bool val)
129 {
130 // TODO
131 }
132
133 #ifndef BST_CHECKED
134 #define BST_CHECKED 0x0001
135 #endif
136
137 bool wxCheckBox::GetValue() const
138 {
139 // TODO
140 return FALSE;
141 }
142
143 WXHBRUSH wxCheckBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
144 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
145 {
146 // TODO:
147 /*
148 #if wxUSE_CTL3D
149 if ( m_useCtl3D )
150 {
151 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
152
153 return (WXHBRUSH) hbrush;
154 }
155 #endif
156
157 if (GetParent()->GetTransparentBackground())
158 SetBkMode((HDC) pDC, TRANSPARENT);
159 else
160 SetBkMode((HDC) pDC, OPAQUE);
161
162 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
163 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
164
165 */
166
167 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
168
169
170 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
171 // has a zero usage count.
172 // backgroundBrush->RealizeResource();
173 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
174 }
175
176 void wxCheckBox::Command (wxCommandEvent & event)
177 {
178 SetValue ((event.GetInt() != 0));
179 ProcessCommand (event);
180 }
181
182 // ----------------------------------------------------------------------------
183 // wxBitmapCheckBox
184 // ----------------------------------------------------------------------------
185
186 bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
187 const wxPoint& pos,
188 const wxSize& size, long style,
189 #if wxUSE_VALIDATORS
190 const wxValidator& validator,
191 #endif
192 const wxString& name)
193 {
194 SetName(name);
195 #if wxUSE_VALIDATORS
196 SetValidator(validator);
197 #endif
198 if (parent) parent->AddChild(this);
199
200 SetBackgroundColour(parent->GetBackgroundColour()) ;
201 SetForegroundColour(parent->GetForegroundColour()) ;
202 m_windowStyle = style;
203
204 if ( id == -1 )
205 m_windowId = NewControlId();
206 else
207 m_windowId = id;
208
209 int x = pos.x;
210 int y = pos.y;
211 int width = size.x;
212 int height = size.y;
213
214 checkWidth = -1 ;
215 checkHeight = -1 ;
216 // long msStyle = CHECK_FLAGS;
217
218 HWND wx_button = 0; // TODO: Create the bitmap checkbox
219
220 m_hWnd = (WXHWND)wx_button;
221
222 // Subclass again for purposes of dialog editing mode
223 SubclassWin((WXHWND)wx_button);
224
225 SetSize(x, y, width, height);
226
227 // TODO: ShowWindow(wx_button, SW_SHOW);
228
229 return TRUE;
230 }
231
232 void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap)
233 {
234 wxFAIL_MSG(wxT("not implemented"));
235 }
236