Google
Web alhem.net

Select.h

Go to the documentation of this file.
00001 /*
00002  **     \file Select.h
00003  **     \date  2006-05-05
00004  **     \author grymse@alhem.net
00005 **/
00006 /*
00007 Copyright (C) 2006  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 */
00023 #ifndef _CGIPP_SELECT_H
00024 #define _CGIPP_SELECT_H
00025 
00026 #include <string>
00027 #include <list>
00028 #include "Styled.h"
00029 
00030 
00031 namespace Cgi {
00032 
00033 class Select : public Styled
00034 {
00035         class Value {
00036         public:
00037                 Value(Select& sel,const std::string& text) : m_sel(sel), m_text(text) {}
00038                 virtual ~Value() {}
00039                 virtual void Print() {
00040                         printf("<option%s>%s", Selected() ? " selected" : "", m_text.c_str());
00041                 }
00042                 virtual bool Selected() {
00043                         if (!strcmp(m_text.c_str(), m_sel.m_selected_str.c_str()))
00044                                 return true;
00045                         return false;
00046                 }
00047                 Select& m_sel;
00048                 std::string m_text;
00049         };
00050         class Multi : public Value {
00051         public:
00052                 Multi(Select& sel,long value,const std::string& text) : Value(sel, text), m_value(value) {}
00053                 void Print() {
00054                         printf("<option value=%ld%s>%s", m_value, Selected() ? " selected" : "", m_text.c_str());
00055                 }
00056                 bool Selected() {
00057                         if (m_value == m_sel.m_selected)
00058                                 return true;
00059                         return false;
00060                 }
00061                 long m_value;
00062         };
00063         friend class Value;
00064 public:
00065         Select(const std::string& name);
00066         ~Select();
00067 
00068         void Add(const std::string& value);
00069         void Add(long value,const std::string& description);
00070 
00071         void Selected(const std::string x) { m_selected_str = x; }
00072         void Selected(long x) { m_selected = x; }
00073 
00074         void Print();
00075 
00076 private:
00077         Select(const Select& ) {} // copy constructor
00078         Select& operator=(const Select& ) { return *this; } // assignment operator
00079         std::string m_name;
00080         std::list<Value *> m_values;
00081         long m_selected;
00082         std::string m_selected_str;
00083 };
00084 
00085 } // namespace
00086 
00087 
00088 #endif // _CGIPP_SELECT_H

Generated for cgi++ by doxygen 1.3.7

Page, code, and content Copyright (C) 2004 by Anders Hedström