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