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