// w32dlib - Win32 Control Helpers // // Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk) // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ------------------------------------------------------------------------- // #include "w32dlib/window.h" #include "w32dlib/combobox.h" #include "w32dlib/datax.h" namespace W32DLib { // ------------------------------------------------------------ // ComboBox::ComboBox(Dialog *parent, int resource_id, DataX *datax) : Control(parent,resource_id,datax) { } // ------------------------------------------------------------ // ComboBox::~ComboBox() { } // ------------------------------------------------------------ // void ComboBox::OnSelection(Window *owner, W32DLibCallback callback) { Control::AddCallback(WM_COMMAND,CBN_SELCHANGE,owner,callback); } // ------------------------------------------------------------ // void ComboBox::OnDoubleClick(Window *owner, W32DLibCallback callback) { Control::AddCallback(WM_COMMAND,CBN_DBLCLK,owner,callback); } // ------------------------------------------------------------ // void ComboBox::OnTextChanged(Window *owner, W32DLibCallback callback) { Control::AddCallback(WM_COMMAND,CBN_EDITCHANGE,owner,callback); } // ------------------------------------------------------------ // void ComboBox::Reset() { SendMsg(CB_RESETCONTENT,0,0); } // ------------------------------------------------------------ // void ComboBox::MaxLen(int count) { SendMsg(CB_LIMITTEXT,count,0); } // ------------------------------------------------------------ // int ComboBox::Count() { return SendMsg(CB_GETCOUNT,0,0); } // ------------------------------------------------------------ // int ComboBox::AddString(const char *text) { return SendMsg(CB_ADDSTRING,0,reinterpret_cast(text)); } // ------------------------------------------------------------ // int ComboBox::AddString(const std::string& text) { return AddString(text.c_str()); } // ------------------------------------------------------------ // int ComboBox::AddString(const char *text, int index) { return SendMsg(CB_INSERTSTRING,index,reinterpret_cast(text)); } // ------------------------------------------------------------ // int ComboBox::AddString(const std::string& text, int index) { return AddString(text.c_str(),index); } // ------------------------------------------------------------ // int ComboBox::RemoveString(int index) { return SendMsg(CB_DELETESTRING,index,0); } // ------------------------------------------------------------ // std::string ComboBox::GetString(int index) { std::string result; LRESULT len=SendMsg(CB_GETLBTEXTLEN,index,0); if (len!=CB_ERR) { char *text=new char[len+1]; SendMsg(CB_GETLBTEXT,index,reinterpret_cast(text)); result=text; delete[] text; } return result; } // ------------------------------------------------------------ // int ComboBox::TopRowIndex() { return SendMsg(CB_GETTOPINDEX,0,0); } // ------------------------------------------------------------ // void ComboBox::TopRowIndex(int index) { SendMsg(CB_SETTOPINDEX,index,0); } // ------------------------------------------------------------ // int ComboBox::SelectedIndex() { return SendMsg(CB_GETCURSEL,0,0); } // ------------------------------------------------------------ // void ComboBox::SelectedIndex(int index) { SendMsg(CB_SETCURSEL,index,0); } // ------------------------------------------------------------ // void ComboBox::DoDataExchange(bool set) { if (m_data) { switch(m_data->Type()) { case DataX::eString: case DataX::eBool: Control::DoDataExchange(set); break; case DataX::eInt: if (set) { SelectedIndex(m_data->Int()); } else { m_data->Set(SelectedIndex()); } break; } } } }; // namespace W32DLib // END OF FILE