00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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& ) {}
00078 Select& operator=(const Select& ) { return *this; }
00079 std::string m_name;
00080 std::list<Value *> m_values;
00081 long m_selected;
00082 std::string m_selected_str;
00083 };
00084
00085 }
00086
00087
00088 #endif // _CGIPP_SELECT_H