sprint 1-alpha
sprint/gtl/ComboBox.h
00001 /******************************************************************************
00002  *  GTL: GUI Template Library 
00003  *    A Cross Platform C++ Wrapper for Win32 users
00004  *  Copyright (C) 2007-2011 Paolo Medici (www.pmx.it)
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Lesser General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2.1 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Lesser General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Lesser General Public
00017  *  License along with this library; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019  *
00020  *******************************************************************************/
00021 
00022 #ifndef _SPRINT_GTL_COMBOBOX_H
00023 #define _SPRINT_GTL_COMBOBOX_H
00024 
00025 #include <sprint/gtl/Window.h>
00026 #include <Commctrl.h> // CB_*
00027 
00028 namespace sprint {
00029         namespace gtl {
00030 
00032 class ComboBox : public CWindow
00033 {
00034 public:
00035 // Constructors
00036 
00042         ComboBox(HWND hWnd = NULL) : CWindow(hWnd)
00043         { }
00044 
00045         ComboBox(CWindow hWnd) : CWindow(hWnd)
00046         { }
00047 
00049 void AddStrings(const TCHAR **list)
00050 {
00051   while(*list)
00052   {
00053      ::SendMessage(m_hwnd, CB_ADDSTRING, 0, (LPARAM) (LPCTSTR) *list);
00054      list++;
00055   }
00056      
00057  }
00058 
00059 int FindItemDataEx(DWORD dwData) const
00060 {
00061         int uItem = GetCount();
00062         for(int i=0;i<uItem;i++)
00063         {
00064                 if(GetItemData(i)==dwData)
00065                         return i;
00066         }
00067         return -1;
00068 }
00069 
00070 // Attributes
00071         static LPCSTR GetWndClassName()
00072         {
00073                 return "COMBOBOX";
00074         }
00075 
00076         // for entire combo box
00077         int GetCount() const
00078         {
00079                 return (int)::SendMessage(m_hwnd, CB_GETCOUNT, 0, 0L);
00080         }
00081 
00082         int GetCurSel() const
00083         {
00084                 return (int)::SendMessage(m_hwnd, CB_GETCURSEL, 0, 0L);
00085         }
00086 
00087         int SetCurSel(int nSelect)
00088         {
00089                 return (int)::SendMessage(m_hwnd, CB_SETCURSEL, nSelect, 0L);
00090         }
00091 
00092         LCID GetLocale() const
00093         {
00094                 return (LCID)::SendMessage(m_hwnd, CB_GETLOCALE, 0, 0L);
00095         }
00096 
00097         LCID SetLocale(LCID nNewLocale)
00098         {
00099                 return (LCID)::SendMessage(m_hwnd, CB_SETLOCALE, (WPARAM)nNewLocale, 0L);
00100         }
00101 
00102         int GetTopIndex() const
00103         {
00104                 return (int)::SendMessage(m_hwnd, CB_GETTOPINDEX, 0, 0L);
00105         }
00106 
00107         int SetTopIndex(int nIndex)
00108         {
00109                 return (int)::SendMessage(m_hwnd, CB_SETTOPINDEX, nIndex, 0L);
00110         }
00111 
00112         UINT GetHorizontalExtent() const
00113         {
00114                 return (UINT)::SendMessage(m_hwnd, CB_GETHORIZONTALEXTENT, 0, 0L);
00115         }
00116 
00117         void SetHorizontalExtent(UINT nExtent)
00118         {
00119                 ::SendMessage(m_hwnd, CB_SETHORIZONTALEXTENT, nExtent, 0L);
00120         }
00121 
00122         int GetDroppedWidth() const
00123         {
00124                 return (int)::SendMessage(m_hwnd, CB_GETDROPPEDWIDTH, 0, 0L);
00125         }
00126 
00127         int SetDroppedWidth(UINT nWidth)
00128         {
00129                 return (int)::SendMessage(m_hwnd, CB_SETDROPPEDWIDTH, nWidth, 0L);
00130         }
00131 
00132 #if ((WINVER >= 0x0500) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
00133         BOOL GetComboBoxInfo(PCOMBOBOXINFO pComboBoxInfo) const
00134         {
00135 #if ((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
00136                 return (BOOL)::SendMessage(m_hwnd, CB_GETCOMBOBOXINFO, 0, (LPARAM)pComboBoxInfo);
00137 #else // !((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
00138                 return ::GetComboBoxInfo(m_hwnd, pComboBoxInfo);
00139 #endif // !((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
00140         }
00141 #endif // ((WINVER >= 0x0500) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
00142 
00143         // for edit control
00144         DWORD GetEditSel() const
00145         {
00146                 return (DWORD)::SendMessage(m_hwnd, CB_GETEDITSEL, 0, 0L);
00147         }
00148 
00149         BOOL SetEditSel(int nStartChar, int nEndChar)
00150         {
00151                 return (BOOL)::SendMessage(m_hwnd, CB_SETEDITSEL, 0, MAKELONG(nStartChar, nEndChar));
00152         }
00153 
00154         // for combobox item
00155         DWORD_PTR GetItemData(int nIndex) const
00156         {
00157                 return (DWORD_PTR)::SendMessage(m_hwnd, CB_GETITEMDATA, nIndex, 0L);
00158         }
00159 
00160         int SetItemData(int nIndex, DWORD_PTR dwItemData)
00161         {
00162                 return (int)::SendMessage(m_hwnd, CB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
00163         }
00164 
00165         void* GetItemDataPtr(int nIndex) const
00166         {
00167                 return (void*)GetItemData(nIndex);
00168         }
00169 
00170         int SetItemDataPtr(int nIndex, void* pData)
00171         {
00172                 return SetItemData(nIndex, (DWORD_PTR)pData);
00173         }
00174 
00175         int GetLBText(int nIndex, LPTSTR lpszText) const
00176         {
00177                 return (int)::SendMessage(m_hwnd, CB_GETLBTEXT, nIndex, (LPARAM)lpszText);
00178         }
00179 
00180         int GetLBTextLen(int nIndex) const
00181         {
00182                 return (int)::SendMessage(m_hwnd, CB_GETLBTEXTLEN, nIndex, 0L);
00183         }
00184 
00185         int GetItemHeight(int nIndex) const
00186         {
00187                 return (int)::SendMessage(m_hwnd, CB_GETITEMHEIGHT, nIndex, 0L);
00188         }
00189 
00190         int SetItemHeight(int nIndex, UINT cyItemHeight)
00191         {
00192                 return (int)::SendMessage(m_hwnd, CB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
00193         }
00194 
00195         BOOL GetExtendedUI() const
00196         {
00197                 return (BOOL)::SendMessage(m_hwnd, CB_GETEXTENDEDUI, 0, 0L);
00198         }
00199 
00200         int SetExtendedUI(BOOL bExtended = TRUE)
00201         {
00202                 return (int)::SendMessage(m_hwnd, CB_SETEXTENDEDUI, bExtended, 0L);
00203         }
00204 
00205         void GetDroppedControlRect(LPRECT lprect) const
00206         {
00207                 ::SendMessage(m_hwnd, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)lprect);
00208         }
00209 
00210         BOOL GetDroppedState() const
00211         {
00212                 return (BOOL)::SendMessage(m_hwnd, CB_GETDROPPEDSTATE, 0, 0L);
00213         }
00214 
00215 #if (_WIN32_WINNT >= 0x0501)
00216         int GetMinVisible() const
00217         {
00218                 return (int)::SendMessage(m_hwnd, CB_GETMINVISIBLE, 0, 0L);
00219         }
00220 
00221         BOOL SetMinVisible(int nMinVisible)
00222         {
00223                 return (BOOL)::SendMessage(m_hwnd, CB_SETMINVISIBLE, nMinVisible, 0L);
00224         }
00225 
00226         // Vista only
00227         BOOL GetCueBannerText(LPWSTR lpwText, int cchText) const
00228         {
00229 #ifndef CB_GETCUEBANNER
00230                 const UINT CB_GETCUEBANNER = (CBM_FIRST + 4);
00231 #endif
00232                 return (BOOL)::SendMessage(m_hwnd, CB_GETCUEBANNER, (WPARAM)lpwText, cchText);
00233         }
00234 
00235         // Vista only
00236         BOOL SetCueBannerText(LPCWSTR lpcwText)
00237         {
00238 #ifndef CB_SETCUEBANNER
00239                 const UINT CB_SETCUEBANNER = (CBM_FIRST + 3);
00240 #endif
00241                 return (BOOL)::SendMessage(m_hwnd, CB_SETCUEBANNER, 0, (LPARAM)lpcwText);
00242         }
00243 #endif // (_WIN32_WINNT >= 0x0501)
00244 
00245 // Operations
00246 
00247         int InitStorage(int nItems, UINT nBytes)
00248         {
00249                 return (int)::SendMessage(m_hwnd, CB_INITSTORAGE, (WPARAM)nItems, nBytes);
00250         }
00251 
00253         void ResetContent()
00254         {
00255                 ::SendMessage(m_hwnd, CB_RESETCONTENT, 0, 0L);
00256         }
00257 
00258         // for edit control
00259         BOOL LimitText(int nMaxChars)
00260         {
00261                 return (BOOL)::SendMessage(m_hwnd, CB_LIMITTEXT, nMaxChars, 0L);
00262         }
00263 
00264         // for drop-down combo boxes
00265         void ShowDropDown(BOOL bShowIt = TRUE)
00266         {
00267                 ::SendMessage(m_hwnd, CB_SHOWDROPDOWN, bShowIt, 0L);
00268         }
00269 
00275         int AddString(LPCTSTR lpszString)
00276         {
00277                 return (int)::SendMessage(m_hwnd, CB_ADDSTRING, 0, (LPARAM)lpszString);
00278         }
00279 
00281         int DeleteString(UINT nIndex)
00282         {
00283                 return (int)::SendMessage(m_hwnd, CB_DELETESTRING, nIndex, 0L);
00284         }
00285 
00287         int InsertString(int nIndex, LPCTSTR lpszString)
00288         {
00289                 return (int)::SendMessage(m_hwnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString);
00290         }
00291 
00292 #ifndef _WIN32_WCE
00293         int Dir(UINT attr, LPCTSTR lpszWildCard)
00294         {
00295                 return (int)::SendMessage(m_hwnd, CB_DIR, attr, (LPARAM)lpszWildCard);
00296         }
00297 #endif // !_WIN32_WCE
00298 
00299         // selection helpers
00300         int FindString(int nStartAfter, LPCTSTR lpszString) const
00301         {
00302                 return (int)::SendMessage(m_hwnd, CB_FINDSTRING, nStartAfter, (LPARAM)lpszString);
00303         }
00304 
00305         int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
00306         {
00307                 return (int)::SendMessage(m_hwnd, CB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
00308         }
00309 
00310         int SelectString(int nStartAfter, LPCTSTR lpszString)
00311         {
00312                 return (int)::SendMessage(m_hwnd, CB_SELECTSTRING, nStartAfter, (LPARAM)lpszString);
00313         }
00314 
00315         // Clipboard operations (TODO: inherit from EDITBOX)
00316 
00318         void Clear()
00319         {
00320                 ::SendMessage(m_hwnd, WM_CLEAR, 0, 0L);
00321         }
00322 
00324         void Copy()
00325         {
00326                 ::SendMessage(m_hwnd, WM_COPY, 0, 0L);
00327         }
00328 
00330         void Cut()
00331         {
00332                 ::SendMessage(m_hwnd, WM_CUT, 0, 0L);
00333         }
00334 
00336         void Paste()
00337         {
00338                 ::SendMessage(m_hwnd, WM_PASTE, 0, 0L);
00339         }
00340 };
00341 
00342 }
00343 
00344 }
00345 
00346 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines