aswang  1.0
ListBox.cpp
Go to the documentation of this file.
00001 /*
00002         Copyright 2003 Joseph Alvis
00003 
00004     This file is part of Aswang.
00005 
00006     Aswang is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU Lesser General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     Aswang 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
00014     GNU Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public License
00017     along with Aswang.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 #include "ListBox.h"
00021 
00022 using namespace aswang;
00023 
00024 long ListBox::AddString(AswangStr s) const {
00025         if(hWnd != NULL) {
00026                 return (LONG)SendMessage(hWnd,LB_ADDSTRING,0,(LPARAM)s.c_str());
00027         }
00028         return -1;
00029 }
00030 
00031 long ListBox::AddUniqueString(AswangStr s) const {
00032         if(hWnd != NULL) {
00033                 if(FindString(s)<0)
00034                         return (LONG)SendMessage(hWnd,LB_ADDSTRING,0,(LPARAM)s.c_str());
00035         }
00036         return -1;
00037 }
00038 
00039 long ListBox::InsertString(AswangStr s,long index) const {
00040         if(hWnd != NULL) {
00041                 return (LONG)SendMessage(hWnd,LB_INSERTSTRING,index,(LPARAM)s.c_str());
00042         }
00043         return -1;
00044 }
00045 
00046 long ListBox::InsertUniqueString(AswangStr s,long index) const {
00047         if(hWnd != NULL) {
00048                 if(FindString(s)<0)
00049                         return (LONG)SendMessage(hWnd,LB_INSERTSTRING,index,(LPARAM)s.c_str());
00050         }
00051         return -1;
00052 }
00053 
00054 long ListBox::FindPrefix(AswangStr s,long index) const {
00055         if(hWnd != NULL) {
00056                 long result = (LONG)SendMessage(hWnd,LB_FINDSTRING,(WPARAM)index,(LPARAM)s.c_str());
00057                 if(result >= LB_OKAY)
00058                         return result;
00059         }
00060         return -1;
00061 }
00062 
00063 long ListBox::FindString(AswangStr s,long index) const {
00064         if(hWnd != NULL) {
00065                 long result = (LONG)SendMessage(hWnd,LB_FINDSTRINGEXACT,(WPARAM)index,(LPARAM)s.c_str());
00066                 if(result >= LB_OKAY)
00067                         return result;
00068         }
00069         return -1;
00070 }
00071 
00072 long ListBox::Count() const {
00073         if(hWnd != NULL) {
00074                 return (LONG)SendMessage(hWnd,LB_GETCOUNT,0,0);
00075         }
00076         return 0;
00077 }
00078 
00079 AswangStr ListBox::GetSelectedString() const {
00080         if(hWnd != NULL) {
00081                 long index = (LONG)SendMessage(hWnd,LB_GETCURSEL,0,0);
00082                 if(index >= LB_OKAY) {
00083                         return GetString(index);
00084                 }
00085         }
00086         return AswangStr();
00087 }
00088 
00089 long ListBox::GetSelectedIndex() const {
00090         if(hWnd != NULL) {
00091                 return (LONG)SendMessage(hWnd,LB_GETCURSEL,0,0);
00092         }
00093         return -1;
00094 }
00095 
00096 void ListBox::SetSelectedIndex(long index) const {
00097         if(hWnd != NULL) {
00098                 SendMessage(hWnd,LB_SETCURSEL,index,0);
00099         }
00100 }
00101 
00102 long ListBox::GetStringLength(long index) const {
00103         if(hWnd != NULL && index >= 0)
00104                 return (LONG)SendMessage(hWnd,LB_GETTEXTLEN,index,0);
00105         return -1;
00106 }
00107 
00108 AswangStr ListBox::GetString(long index) const {
00109         AswangStr s;
00110         if(hWnd != NULL && index >= 0) {
00111                 long len = (LONG)SendMessage(hWnd,LB_GETTEXTLEN,index,0);
00112                 if(len > LB_ERR) {
00113                         _TCHAR *txt = new _TCHAR[len+1];
00114                         txt[len]=0;
00115                         if(SendMessage(hWnd,LB_GETTEXT,index,(LPARAM)txt) > LB_ERR) {
00116                                 s = txt;
00117                         }
00118                         delete[] txt;
00119                 }
00120         }
00121         return s;
00122 }
00123 
00124 void ListBox::DeleteString(long index) const {
00125         if(hWnd != NULL && index >= 0) {
00126                 SendMessage(hWnd,LB_DELETESTRING,index,0);
00127         }
00128 }
00129 
00130 void ListBox::Clear() const {
00131         if(hWnd !=NULL)
00132                 SendMessage(hWnd,LB_RESETCONTENT,0,0);
00133 }
00134 
00135 long ListBox::GetItemData(long index) const {
00136         if(hWnd != NULL) {
00137                 return (long)SendMessage(hWnd,LB_GETITEMDATA,index,0);
00138         }
00139         return LB_ERR;
00140 }
00141 
00142 void ListBox::SetItemData(long index,long data) const {
00143         if(hWnd != NULL) {
00144                 SendMessage(hWnd,LB_SETITEMDATA,index,data);
00145         }
00146 }
00147 
00148 long ListBox::operator [] (long index) const {
00149         if(hWnd != NULL)
00150                 return (long)SendMessage(hWnd,LB_GETITEMDATA,index,0);
00151         return LB_ERR;
00152 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines