aswang  1.0
ComboBox.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 "Combobox.h"
00021 
00022 using namespace aswang;
00023 
00024 long ComboBox::AddString(AswangStr s) const {
00025         if(hWnd != NULL) {
00026                 return (LONG)SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)s.c_str());
00027         }
00028         return -1;
00029 }
00030 
00031 long ComboBox::AddString(AswangStr s,long data) const {
00032         if(hWnd != NULL) {
00033                 long result = (LONG)SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)s.c_str());
00034                 if(result != CB_ERR)
00035                         SendMessage(hWnd,CB_SETITEMDATA,result,data);
00036                 return result;
00037         }
00038         return -1;
00039 }
00040 
00041 long ComboBox::AddUniqueString(AswangStr s) const {
00042         if(hWnd != NULL) {
00043                 if(FindString(s)<0)
00044                         return (LONG)SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)s.c_str());
00045         }
00046         return -1;
00047 }
00048 
00049 long ComboBox::AddUniqueString(AswangStr s,long data) const {
00050         if(hWnd != NULL) {
00051                 if(FindString(s)<0) {
00052                         long result = (LONG)SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)s.c_str());
00053                         if(result != CB_ERR)
00054                                 SendMessage(hWnd,CB_SETITEMDATA,result,data);
00055                         return result;
00056                 }
00057         }
00058         return -1;
00059 }
00060 
00061 long ComboBox::FindPrefix(AswangStr s,long index) const {
00062         if(hWnd != NULL) {
00063                 long result = (LONG)SendMessage(hWnd,CB_FINDSTRING,(WPARAM)index,(LPARAM)s.c_str());
00064                 if(result >= CB_OKAY)
00065                         return result;
00066         }
00067         return -1;
00068 }
00069 
00070 long ComboBox::FindString(AswangStr s,long index) const {
00071         if(hWnd != NULL) {
00072                 long result = (LONG)SendMessage(hWnd,CB_FINDSTRINGEXACT,(WPARAM)index,(LPARAM)s.c_str());
00073                 if(result >= CB_OKAY)
00074                         return result;
00075         }
00076         return -1;
00077 }
00078 
00079 long ComboBox::Count() const {
00080         if(hWnd != NULL) {
00081                 return (LONG)SendMessage(hWnd,CB_GETCOUNT,0,0);
00082         }
00083         return 0;
00084 }
00085 
00086 AswangStr ComboBox::GetSelectedString() const {
00087         if(hWnd != NULL) {
00088                 long index = (LONG)SendMessage(hWnd,CB_GETCURSEL,0,0);
00089                 if(index >= CB_OKAY) {
00090                         return GetString(index);
00091                 }
00092         }
00093         return AswangStr();
00094 }
00095 
00096 long ComboBox::GetSelectedIndex() const {
00097         if(hWnd != NULL) {
00098                 return (LONG)SendMessage(hWnd,CB_GETCURSEL,0,0);
00099         }
00100         return -1;
00101 }
00102 
00103 void ComboBox::SetSelectedIndex(long index) const {
00104         if(hWnd != NULL) {
00105                 SendMessage(hWnd,CB_SETCURSEL,index,0);
00106         }
00107 }
00108 
00109 AswangStr ComboBox::GetString(long index) const {
00110         AswangStr s;
00111         if(hWnd != NULL && index >= 0) {
00112                 long len = (LONG)SendMessage(hWnd,CB_GETLBTEXTLEN,index,0);
00113                 if(len > CB_ERR) {
00114                         _TCHAR *txt = new _TCHAR[len+1];
00115                         txt[len]=0;
00116                         if(SendMessage(hWnd,CB_GETLBTEXT,index,(LPARAM)txt) > CB_ERR) {
00117                                 s = txt;
00118                         }
00119                         delete[] txt;
00120                 }
00121         }
00122         return s;
00123 }
00124 
00125 void ComboBox::DeleteString(long index) const {
00126         if(hWnd != NULL && index >= 0) {
00127                 SendMessage(hWnd,CB_DELETESTRING,index,0);
00128         }
00129 }
00130 
00131 HWND ComboBox::GetEditWindow() const {
00132         if(hWnd != NULL) {
00133                 COMBOBOXINFO cbi;
00134                 memset(&cbi,0,sizeof(cbi));
00135                 cbi.cbSize=sizeof(cbi);
00136                 GetComboBoxInfo(hWnd,&cbi);
00137                 return cbi.hwndItem;
00138         }
00139         return NULL;
00140 }
00141 
00142 void ComboBox::SetItemData(long index,long data) const {
00143         if(hWnd != NULL && index >=0) {
00144                 SendMessage(hWnd,CB_SETITEMDATA,index,data);
00145         }
00146 }
00147 
00148 long ComboBox::GetItemData(long index) const {
00149         if(hWnd != NULL && index >= 0) {
00150                 return (LONG)SendMessage(hWnd,CB_GETITEMDATA,index,0);
00151         }
00152         return -1;
00153 }
00154 
00155 long ComboBox::operator [] (long index) const {
00156         return GetItemData(index);
00157 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines