]> git.saurik.com Git - wxWidgets.git/blob - src/os2/checkbox.cpp
Add missing WXK constants for the control keys
[wxWidgets.git] / src / os2 / checkbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/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 #include "wx/checkbox.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/brush.h"
19 #include "wx/scrolwin.h"
20 #include "wx/dcscreen.h"
21 #include "wx/settings.h"
22 #endif
23
24 #include "wx/os2/private.h"
25
26 // ----------------------------------------------------------------------------
27 // macros
28 // ----------------------------------------------------------------------------
29
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( WXUINT WXUNUSED(uParam),
45 WXWORD WXUNUSED(wId) )
46 {
47 wxCommandEvent rEvent( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId );
48 rEvent.SetInt(GetValue());
49 rEvent.SetEventObject(this);
50 ProcessCommand(rEvent);
51 return true;
52 } // end of wxCheckBox::OS2Command
53
54 bool wxCheckBox::Create(wxWindow* pParent,
55 wxWindowID vId,
56 const wxString& rsLabel,
57 const wxPoint& rPos,
58 const wxSize& rSize,
59 long lStyle,
60 const wxValidator& rValidator,
61 const wxString& rsName )
62 {
63 if (!CreateControl( pParent
64 ,vId
65 ,rPos
66 ,rSize
67 ,lStyle
68 ,rValidator
69 ,rsName
70 ))
71 return false;
72
73
74 long osStyle = BS_AUTOCHECKBOX | WS_TABSTOP | WS_VISIBLE;
75
76 bool bOk = OS2CreateControl( wxT("BUTTON")
77 ,osStyle
78 ,rPos
79 ,rSize
80 ,rsLabel
81 ,0
82 );
83 m_backgroundColour = pParent->GetBackgroundColour();
84
85 LONG lColor = (LONG)m_backgroundColour.GetPixel();
86 ::WinSetPresParam( m_hWnd
87 ,PP_BACKGROUNDCOLOR
88 ,sizeof(LONG)
89 ,(PVOID)&lColor
90 );
91 wxAssociateWinWithHandle(m_hWnd, this);
92 return bOk;
93 } // end of wxCheckBox::Create
94
95 void wxCheckBox::SetLabel( const wxString& rsLabel )
96 {
97 wxString sLabel=::wxPMTextToLabel(rsLabel);
98 ::WinSetWindowText(GetHwnd(), sLabel.c_str());
99 } // end of wxCheckBox::SetLabel
100
101 wxSize wxCheckBox::DoGetBestSize() const
102 {
103 // We should probably compute nCheckSize but it seems to be a constant
104 // independent of its label's font size and not made available by OS/2.
105 int nCheckSize = RADIO_SIZE;
106 int nWidthCheckbox;
107 int nHeightCheckbox;
108 wxString sStr = wxGetWindowText(GetHWND());
109
110 if (!sStr.empty())
111 {
112 GetTextExtent( sStr
113 ,&nWidthCheckbox
114 ,&nHeightCheckbox
115 );
116 nWidthCheckbox += nCheckSize;
117
118 if (nHeightCheckbox < nCheckSize)
119 nHeightCheckbox = nCheckSize;
120 }
121 else
122 {
123 nWidthCheckbox = nCheckSize;
124 nHeightCheckbox = nCheckSize;
125 }
126
127 return wxSize( nWidthCheckbox, nHeightCheckbox );
128 } // end of wxCheckBox::DoGetBestSize
129
130 void wxCheckBox::SetValue( bool bValue )
131 {
132 ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0);
133 } // end of wxCheckBox::SetValue
134
135 #ifndef BST_CHECKED
136 #define BST_CHECKED 0x0001
137 #endif
138
139 bool wxCheckBox::GetValue() const
140 {
141 return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L));
142 } // end of wxCheckBox::GetValue
143
144 void wxCheckBox::Command ( wxCommandEvent& rEvent )
145 {
146 SetValue((rEvent.GetInt() != 0));
147 ProcessCommand(rEvent);
148 } // end of wxCheckBox:: Command
149
150 // ----------------------------------------------------------------------------
151 // wxBitmapCheckBox
152 // ----------------------------------------------------------------------------
153
154 bool wxBitmapCheckBox::Create( wxWindow* pParent,
155 wxWindowID vId,
156 const wxBitmap* WXUNUSED(pLabel),
157 const wxPoint& rPos,
158 const wxSize& rSize,
159 long lStyle,
160 const wxValidator& rValidator,
161 const wxString& rsName)
162 {
163 SetName(rsName);
164 #if wxUSE_VALIDATORS
165 SetValidator(rValidator);
166 #endif
167 if (pParent)
168 pParent->AddChild(this);
169
170 SetBackgroundColour(pParent->GetBackgroundColour()) ;
171 SetForegroundColour(pParent->GetForegroundColour()) ;
172 m_windowStyle = lStyle;
173
174 if (vId == -1)
175 m_windowId = NewControlId();
176 else
177 m_windowId = vId;
178
179 int nX = rPos.x;
180 int nY = rPos.y;
181 int nWidth = rSize.x;
182 int nHeight = rSize.y;
183
184 m_nCheckWidth = -1 ;
185 m_nCheckHeight = -1 ;
186 // long msStyle = CHECK_FLAGS;
187
188 HWND hButton = 0; // TODO: Create the bitmap checkbox
189
190 m_hWnd = (WXHWND)hButton;
191
192 //
193 // Subclass again for purposes of dialog editing mode
194 //
195 SubclassWin((WXHWND)hButton);
196
197 SetSize( nX
198 ,nY
199 ,nWidth
200 ,nHeight
201 );
202
203 ::WinShowWindow(hButton, TRUE);
204 return true;
205 } // end of wxBitmapCheckBox::Create
206
207 void wxBitmapCheckBox::SetLabel( const wxBitmap& WXUNUSED(rBitmap) )
208 {
209 wxFAIL_MSG(wxT("not implemented"));
210 } // end of wxBitmapCheckBox::SetLabel