sprint 1-alpha
sprint/gtl/DialogConf.h
Go to the documentation of this file.
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 _DIALOG_CONF_H
00023 #define _DIALOG_CONF_H
00024 
00029 #include <windows.h>
00030 #include <sprint/gtl/ExtraCtrl.h> // GetDlgItemText
00031 #include <sprint/gtl/ComboBox.h>
00032 
00033 #include <vector>
00034 #include <string>
00035 
00036 namespace sprint {
00037         namespace gtl {
00038 
00039 // Stub classes
00040 struct set;
00041 struct get;
00042 
00043 struct set { typedef get neg; };
00044 struct get { typedef set neg; };
00045 
00059 template<class T>
00060 class Conf;
00061 
00064 template<>
00065 class Conf<set> {
00066   HWND m_hwnd;
00067 
00068   inline HWND GetDlgItem(UINT id)const { return ::GetDlgItem(m_hwnd, id); } 
00069   public:
00070     Conf(HWND hwnd) : m_hwnd(hwnd) {}
00071     
00072     inline bool CheckBox(UINT id, bool check)const { return ::CheckDlgButton(m_hwnd, id, check ? BST_CHECKED     : BST_UNCHECKED        )==TRUE; }
00073     
00074     inline bool Edit(UINT id, const char *string, unsigned int size)const {  return ::SetDlgItemText(m_hwnd, id, string) == TRUE; }      
00075     inline bool Edit(UINT id, const std::string & str)const { return ::SetDlgItemText(m_hwnd, id, str.c_str()) == TRUE; }      
00076     inline bool Edit(UINT id, int value)const { return ::SetDlgItemInt(m_hwnd, id, value, TRUE  ) == TRUE; }      
00077     
00078     bool Edit(UINT id, unsigned int value)const { return ::SetDlgItemInt(m_hwnd, id, value, FALSE       ) == TRUE; }      
00079     bool Edit(UINT id, float value, int precision) const;
00080 
00081     bool Combo(UINT id, unsigned int index, const char **list)const;        
00082     bool Combo(UINT id, unsigned int index, const std::vector<std::string> & list)const;        
00083     bool ComboData(UINT id, unsigned int index, const char **list)const;            
00084     bool ComboData(UINT id, int index, const char **list)const;            
00085 
00086     bool Slider(UINT id, unsigned int value, unsigned int max)const;
00087     
00088     template<class T>
00089     bool ListView(UINT iItem, UINT iSubItem, T value);
00090 
00091     template<class V>
00092     inline bool Radio(UINT id, const V & value, const V & var) const 
00093     {
00094     return ::CheckDlgButton(m_hwnd, id, (var == value) ? BST_CHECKED     : BST_UNCHECKED        ) == TRUE;    
00095     }
00096 
00097 };
00098 
00099 // get
00100 template<>
00101 class Conf<get> {
00102   HWND m_hwnd;
00103   
00104   inline HWND GetDlgItem(UINT id)const { return ::GetDlgItem(m_hwnd, id); } 
00105   public:
00106     Conf(HWND hwnd) : m_hwnd(hwnd) {}
00107     
00108     inline bool CheckBox(UINT id, bool & check) const {  check =  IsDlgButtonChecked(m_hwnd, id) == BST_CHECKED; return true; }
00109 
00110     inline bool Edit(UINT id, char *string, unsigned int size) const { return ::GetDlgItemText(m_hwnd, id, string, size) == TRUE; }
00111         inline bool Edit(UINT id, std::string & str) const { return sprint::gtl::GetDlgItemText(m_hwnd, id, str); }
00112     bool Edit(UINT id, int & value) const { BOOL status; value = ::GetDlgItemInt(m_hwnd, id, &status, TRUE); return status; }
00113     bool Edit(UINT id, unsigned int & value) const { BOOL status; value = ::GetDlgItemInt(m_hwnd, id, &status, FALSE); return status==TRUE; }
00114     bool Edit(UINT id, float & value, int precision) const;
00115 
00116     inline bool Combo(UINT id, unsigned int & index, const char **list) const { index = ComboBox(GetDlgItem(id)).GetCurSel(); return true; }  
00117     inline bool Combo(UINT id, unsigned int & index, const std::vector<std::string> & list) const  { index = ComboBox(GetDlgItem(id)).GetCurSel(); return true; }  
00118     bool ComboData(UINT id, unsigned int & index, const char **list) const;            
00119     bool ComboData(UINT id, int & index, const char **list) const;            
00120 
00121     bool Slider(UINT id, unsigned int & value, unsigned int max) const;
00122 
00123     template<class T>
00124     bool ListView(UINT iItem, UINT iSubItem, T & value);
00125 
00126     template<class V>
00127     inline void Radio(UINT id, const V & value, V & var) const 
00128     {
00129            if(IsDlgButtonChecked(m_hwnd, id) == BST_CHECKED )
00130               var = value;
00131     }
00132 
00133 };
00134 
00135 
00136         }
00137 
00138 }
00139 
00140 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines