sprint 1-alpha
|
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_LISTBOX_H 00023 #define _SPRINT_LISTBOX_H 00024 00028 #include <sprint/gtl/Window.h> 00029 00030 namespace sprint { 00031 namespace gtl { 00032 00034 class ListBox : public CWindow 00035 { 00036 public: 00037 // Constructors 00038 ListBox(HWND hWnd = NULL) : CWindow(hWnd) 00039 { } 00040 00041 /* 00042 HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL, 00043 DWORD dwStyle = 0, DWORD dwExStyle = 0, 00044 ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL) 00045 { 00046 return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam); 00047 } 00048 */ 00049 // Attributes 00050 static LPCTSTR GetWndClassName() 00051 { 00052 return "LISTBOX"; 00053 } 00054 00055 // for entire listbox 00056 int GetCount() const 00057 { 00058 return (int)::SendMessage(m_hwnd, LB_GETCOUNT, 0, 0L); 00059 } 00060 00061 #ifndef _WIN32_WCE 00062 int SetCount(int cItems) 00063 { 00064 return (int)::SendMessage(m_hwnd, LB_SETCOUNT, cItems, 0L); 00065 } 00066 #endif // !_WIN32_WCE 00067 00068 int GetHorizontalExtent() const 00069 { 00070 return (int)::SendMessage(m_hwnd, LB_GETHORIZONTALEXTENT, 0, 0L); 00071 } 00072 00073 void SetHorizontalExtent(int cxExtent) 00074 { 00075 ::SendMessage(m_hwnd, LB_SETHORIZONTALEXTENT, cxExtent, 0L); 00076 } 00077 00078 int GetTopIndex() const 00079 { 00080 return (int)::SendMessage(m_hwnd, LB_GETTOPINDEX, 0, 0L); 00081 } 00082 00083 int SetTopIndex(int nIndex) 00084 { 00085 return (int)::SendMessage(m_hwnd, LB_SETTOPINDEX, nIndex, 0L); 00086 } 00087 00088 LCID GetLocale() const 00089 { 00090 return (LCID)::SendMessage(m_hwnd, LB_GETLOCALE, 0, 0L); 00091 } 00092 00093 LCID SetLocale(LCID nNewLocale) 00094 { 00095 return (LCID)::SendMessage(m_hwnd, LB_SETLOCALE, (WPARAM)nNewLocale, 0L); 00096 } 00097 00098 #if (WINVER >= 0x0500) && !defined(_WIN32_WCE) 00099 DWORD GetListBoxInfo() const 00100 { 00101 #if (_WIN32_WINNT >= 0x0501) 00102 return (DWORD)::SendMessage(m_hwnd, LB_GETLISTBOXINFO, 0, 0L); 00103 #else // !(_WIN32_WINNT >= 0x0501) 00104 return ::GetListBoxInfo(m_hwnd); 00105 #endif // !(_WIN32_WINNT >= 0x0501) 00106 } 00107 #endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE) 00108 00109 // for single-selection listboxes 00110 int GetCurSel() const 00111 { 00112 return (int)::SendMessage(m_hwnd, LB_GETCURSEL, 0, 0L); 00113 } 00114 00115 int SetCurSel(int nSelect) 00116 { 00117 return (int)::SendMessage(m_hwnd, LB_SETCURSEL, nSelect, 0L); 00118 } 00119 00120 // for multiple-selection listboxes 00121 int GetSel(int nIndex) const // also works for single-selection 00122 { 00123 return (int)::SendMessage(m_hwnd, LB_GETSEL, nIndex, 0L); 00124 } 00125 00126 int SetSel(int nIndex, BOOL bSelect = TRUE) 00127 { 00128 return (int)::SendMessage(m_hwnd, LB_SETSEL, bSelect, nIndex); 00129 } 00130 00131 int GetSelCount() const 00132 { 00133 return (int)::SendMessage(m_hwnd, LB_GETSELCOUNT, 0, 0L); 00134 } 00135 00136 int GetSelItems(int nMaxItems, LPINT rgIndex) const 00137 { 00138 return (int)::SendMessage(m_hwnd, LB_GETSELITEMS, nMaxItems, (LPARAM)rgIndex); 00139 } 00140 00141 int GetAnchorIndex() const 00142 { 00143 return (int)::SendMessage(m_hwnd, LB_GETANCHORINDEX, 0, 0L); 00144 } 00145 00146 void SetAnchorIndex(int nIndex) 00147 { 00148 ::SendMessage(m_hwnd, LB_SETANCHORINDEX, nIndex, 0L); 00149 } 00150 00151 int GetCaretIndex() const 00152 { 00153 return (int)::SendMessage(m_hwnd, LB_GETCARETINDEX, 0, 0); 00154 } 00155 00156 int SetCaretIndex(int nIndex, BOOL bScroll = TRUE) 00157 { 00158 return (int)::SendMessage(m_hwnd, LB_SETCARETINDEX, nIndex, MAKELONG(bScroll, 0)); 00159 } 00160 00161 // for listbox items 00162 DWORD_PTR GetItemData(int nIndex) const 00163 { 00164 return (DWORD_PTR)::SendMessage(m_hwnd, LB_GETITEMDATA, nIndex, 0L); 00165 } 00166 00167 int SetItemData(int nIndex, DWORD_PTR dwItemData) 00168 { 00169 return (int)::SendMessage(m_hwnd, LB_SETITEMDATA, nIndex, (LPARAM)dwItemData); 00170 } 00171 00172 void* GetItemDataPtr(int nIndex) const 00173 { 00174 return (void*)::SendMessage(m_hwnd, LB_GETITEMDATA, nIndex, 0L); 00175 } 00176 00177 int SetItemDataPtr(int nIndex, void* pData) 00178 { 00179 return SetItemData(nIndex, (DWORD_PTR)pData); 00180 } 00181 00182 int GetItemRect(int nIndex, LPRECT lpRect) const 00183 { 00184 return (int)::SendMessage(m_hwnd, LB_GETITEMRECT, nIndex, (LPARAM)lpRect); 00185 } 00186 00187 int GetText(int nIndex, LPTSTR lpszBuffer) const 00188 { 00189 return (int)::SendMessage(m_hwnd, LB_GETTEXT, nIndex, (LPARAM)lpszBuffer); 00190 } 00191 00192 int GetTextLen(int nIndex) const 00193 { 00194 return (int)::SendMessage(m_hwnd, LB_GETTEXTLEN, nIndex, 0L); 00195 } 00196 00197 int GetItemHeight(int nIndex) const 00198 { 00199 return (int)::SendMessage(m_hwnd, LB_GETITEMHEIGHT, nIndex, 0L); 00200 } 00201 00202 int SetItemHeight(int nIndex, UINT cyItemHeight) 00203 { 00204 return (int)::SendMessage(m_hwnd, LB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0)); 00205 } 00206 00207 // Settable only attributes 00208 void SetColumnWidth(int cxWidth) 00209 { 00210 ::SendMessage(m_hwnd, LB_SETCOLUMNWIDTH, cxWidth, 0L); 00211 } 00212 00213 BOOL SetTabStops(int nTabStops, LPINT rgTabStops) 00214 { 00215 return (BOOL)::SendMessage(m_hwnd, LB_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops); 00216 } 00217 00218 BOOL SetTabStops() 00219 { 00220 return (BOOL)::SendMessage(m_hwnd, LB_SETTABSTOPS, 0, 0L); 00221 } 00222 00223 BOOL SetTabStops(const int& cxEachStop) // takes an 'int' 00224 { 00225 return (BOOL)::SendMessage(m_hwnd, LB_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop); 00226 } 00227 00228 // Operations 00229 int InitStorage(int nItems, UINT nBytes) 00230 { 00231 return (int)::SendMessage(m_hwnd, LB_INITSTORAGE, (WPARAM)nItems, nBytes); 00232 } 00233 00234 void ResetContent() 00235 { 00236 ::SendMessage(m_hwnd, LB_RESETCONTENT, 0, 0L); 00237 } 00238 00239 UINT ItemFromPoint(POINT pt, BOOL& bOutside) const 00240 { 00241 DWORD dw = (DWORD)::SendMessage(m_hwnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(pt.x, pt.y)); 00242 bOutside = (BOOL)HIWORD(dw); 00243 return (UINT)LOWORD(dw); 00244 } 00245 00246 // manipulating listbox items 00247 int AddString(LPCTSTR lpszItem) 00248 { 00249 return (int)::SendMessage(m_hwnd, LB_ADDSTRING, 0, (LPARAM)lpszItem); 00250 } 00251 00252 int DeleteString(UINT nIndex) 00253 { 00254 return (int)::SendMessage(m_hwnd, LB_DELETESTRING, nIndex, 0L); 00255 } 00256 00257 int InsertString(int nIndex, LPCTSTR lpszItem) 00258 { 00259 return (int)::SendMessage(m_hwnd, LB_INSERTSTRING, nIndex, (LPARAM)lpszItem); 00260 } 00261 00262 #ifndef _WIN32_WCE 00263 int Dir(UINT attr, LPCTSTR lpszWildCard) 00264 { 00265 return (int)::SendMessage(m_hwnd, LB_DIR, attr, (LPARAM)lpszWildCard); 00266 } 00267 00268 int AddFile(LPCTSTR lpstrFileName) 00269 { 00270 return (int)::SendMessage(m_hwnd, LB_ADDFILE, 0, (LPARAM)lpstrFileName); 00271 } 00272 #endif // !_WIN32_WCE 00273 00274 // selection helpers 00275 int FindString(int nStartAfter, LPCTSTR lpszItem) const 00276 { 00277 return (int)::SendMessage(m_hwnd, LB_FINDSTRING, nStartAfter, (LPARAM)lpszItem); 00278 } 00279 00280 int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const 00281 { 00282 return (int)::SendMessage(m_hwnd, LB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind); 00283 } 00284 00285 int SelectString(int nStartAfter, LPCTSTR lpszItem) 00286 { 00287 return (int)::SendMessage(m_hwnd, LB_SELECTSTRING, nStartAfter, (LPARAM)lpszItem); 00288 } 00289 00290 int SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem) 00291 { 00292 return bSelect ? (int)::SendMessage(m_hwnd, LB_SELITEMRANGEEX, nFirstItem, nLastItem) : (int)::SendMessage(m_hwnd, LB_SELITEMRANGEEX, nLastItem, nFirstItem); 00293 } 00294 00295 #ifdef WIN32_PLATFORM_WFSP // SmartPhone only messages 00296 DWORD GetInputMode(BOOL bCurrentMode = TRUE) 00297 { 00298 return SendMessage(LB_GETINPUTMODE, 0, (LPARAM)bCurrentMode); 00299 } 00300 00301 BOOL SetInputMode(DWORD dwMode) 00302 { 00303 return SendMessage(LB_SETINPUTMODE, 0, (LPARAM)dwMode); 00304 } 00305 #endif // WIN32_PLATFORM_WFSP 00306 }; 00307 00308 } 00309 } 00310 00311 #endif