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