]>
Commit | Line | Data |
---|---|---|
0e320a79 | 1 | ///////////////////////////////////////////////////////////////////////////// |
ab1ce969 | 2 | // Name: src/os2/checkbox.cpp |
0e320a79 | 3 | // Purpose: wxCheckBox |
37f214d5 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
37f214d5 | 6 | // Created: 10/13/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
37f214d5 | 8 | // Copyright: (c) David Webster |
65571936 | 9 | // Licence: wxWindows licence |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
37f214d5 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
ab1ce969 WS |
15 | #include "wx/checkbox.h" |
16 | ||
37f214d5 | 17 | #ifndef WX_PRECOMP |
37f214d5 | 18 | #include "wx/brush.h" |
a4a16252 SN |
19 | #include "wx/scrolwin.h" |
20 | #include "wx/dcscreen.h" | |
21 | #include "wx/settings.h" | |
0e320a79 DW |
22 | #endif |
23 | ||
37f214d5 DW |
24 | #include "wx/os2/private.h" |
25 | ||
26 | // ---------------------------------------------------------------------------- | |
27 | // macros | |
28 | // ---------------------------------------------------------------------------- | |
0e320a79 | 29 | |
0e320a79 DW |
30 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) |
31 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) | |
0e320a79 | 32 | |
f289196b DW |
33 | extern void wxAssociateWinWithHandle( HWND hWnd |
34 | ,wxWindowOS2* pWin | |
35 | ); | |
36 | ||
37f214d5 DW |
37 | // ============================================================================ |
38 | // implementation | |
39 | // ============================================================================ | |
40 | ||
41 | // ---------------------------------------------------------------------------- | |
42 | // wxCheckBox | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
6670f564 WS |
45 | bool wxCheckBox::OS2Command( WXUINT WXUNUSED(uParam), |
46 | WXWORD WXUNUSED(wId) ) | |
37f214d5 | 47 | { |
6670f564 | 48 | wxCommandEvent rEvent( wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId ); |
5d44b24e DW |
49 | rEvent.SetInt(GetValue()); |
50 | rEvent.SetEventObject(this); | |
51 | ProcessCommand(rEvent); | |
6670f564 | 52 | return true; |
5d44b24e DW |
53 | } // end of wxCheckBox::OS2Command |
54 | ||
ab1ce969 WS |
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 ) | |
0e320a79 | 63 | { |
a086de98 DW |
64 | if (!CreateControl( pParent |
65 | ,vId | |
66 | ,rPos | |
67 | ,rSize | |
68 | ,lStyle | |
1d0edc0f | 69 | ,rValidator |
a086de98 DW |
70 | ,rsName |
71 | )) | |
ab1ce969 | 72 | return false; |
a086de98 | 73 | |
f289196b | 74 | |
ab1ce969 | 75 | long osStyle = BS_AUTOCHECKBOX | WS_TABSTOP | WS_VISIBLE; |
a086de98 | 76 | |
ab1ce969 | 77 | bool bOk = OS2CreateControl( wxT("BUTTON") |
f289196b DW |
78 | ,osStyle |
79 | ,rPos | |
80 | ,rSize | |
81 | ,rsLabel | |
82 | ,0 | |
83 | ); | |
84 | m_backgroundColour = pParent->GetBackgroundColour(); | |
ab1ce969 WS |
85 | |
86 | LONG lColor = (LONG)m_backgroundColour.GetPixel(); | |
f289196b DW |
87 | ::WinSetPresParam( m_hWnd |
88 | ,PP_BACKGROUNDCOLOR | |
89 | ,sizeof(LONG) | |
90 | ,(PVOID)&lColor | |
91 | ); | |
92 | wxAssociateWinWithHandle(m_hWnd, this); | |
93 | return bOk; | |
5d44b24e | 94 | } // end of wxCheckBox::Create |
0e320a79 | 95 | |
ab1ce969 | 96 | void wxCheckBox::SetLabel( const wxString& rsLabel ) |
0e320a79 | 97 | { |
ab1ce969 | 98 | wxString sLabel=::wxPMTextToLabel(rsLabel); |
e94d504d | 99 | ::WinSetWindowText(GetHwnd(), (PSZ)sLabel.c_str()); |
5d44b24e | 100 | } // end of wxCheckBox::SetLabel |
0e320a79 | 101 | |
e78c4d50 | 102 | wxSize wxCheckBox::DoGetBestSize() const |
0e320a79 | 103 | { |
c5f975dd SN |
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; | |
6670f564 WS |
107 | int nWidthCheckbox; |
108 | int nHeightCheckbox; | |
109 | wxString sStr = wxGetWindowText(GetHWND()); | |
37f214d5 | 110 | |
6670f564 | 111 | if (!sStr.empty()) |
37f214d5 | 112 | { |
5d44b24e DW |
113 | GetTextExtent( sStr |
114 | ,&nWidthCheckbox | |
115 | ,&nHeightCheckbox | |
116 | ); | |
c5f975dd | 117 | nWidthCheckbox += nCheckSize; |
37f214d5 | 118 | |
5d44b24e DW |
119 | if (nHeightCheckbox < nCheckSize) |
120 | nHeightCheckbox = nCheckSize; | |
37f214d5 DW |
121 | } |
122 | else | |
123 | { | |
5d44b24e DW |
124 | nWidthCheckbox = nCheckSize; |
125 | nHeightCheckbox = nCheckSize; | |
37f214d5 DW |
126 | } |
127 | ||
ab1ce969 | 128 | return wxSize( nWidthCheckbox, nHeightCheckbox ); |
5d44b24e | 129 | } // end of wxCheckBox::DoGetBestSize |
0e320a79 | 130 | |
ab1ce969 | 131 | void wxCheckBox::SetValue( bool bValue ) |
0e320a79 | 132 | { |
5d44b24e DW |
133 | ::WinSendMsg(GetHwnd(), BM_SETCHECK, (MPARAM)bValue, 0); |
134 | } // end of wxCheckBox::SetValue | |
0e320a79 | 135 | |
37f214d5 DW |
136 | #ifndef BST_CHECKED |
137 | #define BST_CHECKED 0x0001 | |
138 | #endif | |
139 | ||
0e320a79 DW |
140 | bool wxCheckBox::GetValue() const |
141 | { | |
5d44b24e DW |
142 | return((LONGFROMMR(::WinSendMsg(GetHwnd(), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0)) == 1L)); |
143 | } // end of wxCheckBox::GetValue | |
0e320a79 | 144 | |
ab1ce969 | 145 | void wxCheckBox::Command ( wxCommandEvent& rEvent ) |
37f214d5 | 146 | { |
5d44b24e DW |
147 | SetValue((rEvent.GetInt() != 0)); |
148 | ProcessCommand(rEvent); | |
149 | } // end of wxCheckBox:: Command | |
0e320a79 | 150 | |
37f214d5 DW |
151 | // ---------------------------------------------------------------------------- |
152 | // wxBitmapCheckBox | |
153 | // ---------------------------------------------------------------------------- | |
154 | ||
6670f564 WS |
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) | |
0e320a79 | 163 | { |
5d44b24e | 164 | SetName(rsName); |
5d4b632b | 165 | #if wxUSE_VALIDATORS |
5d44b24e | 166 | SetValidator(rValidator); |
5d4b632b | 167 | #endif |
5d44b24e DW |
168 | if (pParent) |
169 | pParent->AddChild(this); | |
0e320a79 | 170 | |
5d44b24e DW |
171 | SetBackgroundColour(pParent->GetBackgroundColour()) ; |
172 | SetForegroundColour(pParent->GetForegroundColour()) ; | |
173 | m_windowStyle = lStyle; | |
37f214d5 | 174 | |
5d44b24e | 175 | if (vId == -1) |
0e320a79 DW |
176 | m_windowId = NewControlId(); |
177 | else | |
5d44b24e | 178 | m_windowId = vId; |
0e320a79 | 179 | |
5d44b24e DW |
180 | int nX = rPos.x; |
181 | int nY = rPos.y; | |
182 | int nWidth = rSize.x; | |
183 | int nHeight = rSize.y; | |
0e320a79 | 184 | |
5d44b24e DW |
185 | m_nCheckWidth = -1 ; |
186 | m_nCheckHeight = -1 ; | |
892b89f3 | 187 | // long msStyle = CHECK_FLAGS; |
0e320a79 | 188 | |
5d44b24e | 189 | HWND hButton = 0; // TODO: Create the bitmap checkbox |
0e320a79 | 190 | |
5d44b24e | 191 | m_hWnd = (WXHWND)hButton; |
0e320a79 | 192 | |
5d44b24e | 193 | // |
37f214d5 | 194 | // Subclass again for purposes of dialog editing mode |
5d44b24e DW |
195 | // |
196 | SubclassWin((WXHWND)hButton); | |
37f214d5 | 197 | |
5d44b24e DW |
198 | SetSize( nX |
199 | ,nY | |
200 | ,nWidth | |
201 | ,nHeight | |
202 | ); | |
37f214d5 | 203 | |
5d44b24e | 204 | ::WinShowWindow(hButton, TRUE); |
6670f564 | 205 | return true; |
5d44b24e | 206 | } // end of wxBitmapCheckBox::Create |
0e320a79 | 207 | |
6670f564 | 208 | void wxBitmapCheckBox::SetLabel( const wxBitmap& WXUNUSED(rBitmap) ) |
0e320a79 | 209 | { |
37f214d5 | 210 | wxFAIL_MSG(wxT("not implemented")); |
5d44b24e | 211 | } // end of wxBitmapCheckBox::SetLabel |