Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

combobox_generic.cpp

Go to the documentation of this file.
00001 /*
00002         ClanGUI, copyrights by various people. Have a look in the CREDITS file.
00003         
00004         This sourcecode is distributed using the Library GNU Public Licence,
00005         version 2 or (at your option) any later version. Please read LICENSE
00006         for details.
00007 */
00008 
00009 #include "precomp.h"
00010 #include "combobox_generic.h"
00011 #include "API/GUI/component_options.h"
00012 
00013 CL_ComponentOptions CL_ComboBox_Generic::create_options(
00014         const CL_Rect &pos)
00015 {
00016         CL_ComponentOptions options;
00017 
00018         options.add_option_as_int("x", pos.x1);
00019         options.add_option_as_int("y", pos.y1);
00020         options.add_option_as_int("width", pos.get_width());
00021         // TODO: This should be automatically calculated
00022         options.add_option_as_int("height", 16);
00023 
00024         return options;
00025 }
00026 
00027 CL_ComboBox_Generic::CL_ComboBox_Generic(CL_ComboBox *self, const CL_ComponentOptions &options, CL_StyleManager *style)
00028 :
00029         combobox(self)
00030 {
00031         highlighted_item = 0;
00032         select_button = NULL;
00033         activated = false;
00034 
00035         int num_values = options.count("value");
00036         for (int i=0;i<num_values;i++)
00037         {
00038                 items.push_back(options.get_value("value", i));
00039         }
00040 }
00041 
00042 CL_ComboBox_Generic::~CL_ComboBox_Generic()
00043 {
00044 }
00045 
00046 int CL_ComboBox_Generic::get_count() const
00047 {
00048         return items.size();
00049 }
00050 
00051 std::list<std::string> &CL_ComboBox_Generic::get_items()
00052 {
00053         return items;
00054 }
00055 
00056 std::string CL_ComboBox_Generic::get_current_text() const
00057 {
00058         int count = highlighted_item;
00059         std::list<std::string>::const_iterator it;
00060         for (it = items.begin(); it != items.end() && count > 0; it++, count--);
00061                 if (it != items.end())
00062                         return *it;
00063 
00064         char buf[100];
00065         sprintf(buf, "Listbox has illegal value: %d", highlighted_item);
00066         throw CL_Error(buf);
00067 }
00068 
00069 std::string CL_ComboBox_Generic::get_text(int index) const
00070 {
00071         return "";
00072 }
00073 
00074 int CL_ComboBox_Generic::get_current_item() const
00075 {
00076         return 0;
00077 }
00078 
00079 bool CL_ComboBox_Generic::is_selected(int index) const
00080 {
00081         return false;
00082 }
00083 
00084 int CL_ComboBox_Generic::insert_item(const std::string &text, int index)
00085 {
00086         return 0;
00087 }
00088 
00089 void CL_ComboBox_Generic::remove_item(int index)
00090 {
00091 }
00092 
00093 void CL_ComboBox_Generic::change_item(const std::string &text, int index)
00094 {
00095 }
00096 
00097 void CL_ComboBox_Generic::set_current_item(int index)
00098 {
00099         highlighted_item = index;
00100         sig_highlighted(highlighted_item);
00101 }
00102 
00103 void CL_ComboBox_Generic::clear_selection()
00104 {
00105 }
00106 
00107 void CL_ComboBox_Generic::sort(bool ascending)
00108 {
00109 }
00110 
00111 void CL_ComboBox_Generic::clear()
00112 {
00113 }
00114 
00115 void CL_ComboBox_Generic::set_select_button(CL_Button *_select_button)
00116 {
00117         // TODO: Fix this:
00118 /*      select_button = _select_button;
00119         slot_clicked = select_button->sig_clicked().connect(CL_CreateSlot(this, &CL_ComboBox_Generic::select_clicked));
00120         combobox->add_child(select_button, true);
00121 
00122         CL_ComponentOptions b_options;
00123         #ifdef BORLAND
00124                 b_options.options.insert(std::make_pair(std::string("x"), std::string("0")));
00125                 b_options.options.insert(std::make_pair(std::string("y"), std::string("0")));
00126                 b_options.options.insert(std::make_pair(std::string("width"), std::string(CL_String(combobox->get_width()-select_button->get_width()))));
00127                 b_options.options.insert(std::make_pair(std::string("height"), std::string(CL_String(combobox->get_height()))));
00128         #else
00129                 b_options.options.insert(std::make_pair<std::string, std::string>("x", "0"));
00130                 b_options.options.insert(std::make_pair<std::string, std::string>("y", "0"));
00131                 b_options.options.insert(std::make_pair<std::string, std::string>("width", CL_String(combobox->get_width()-select_button->get_width())));
00132                 b_options.options.insert(std::make_pair<std::string, std::string>("height", CL_String(combobox->get_height())));
00133         #endif
00134 
00135         CL_Button *text_area_button = new CL_Button(b_options, this);
00136         slot_pressed = text_area_button->sig_pressed.connect(CL_CreateSlot(this, &CL_ComboBox::select_clicked));
00137         add_child(text_area_button, true);
00138 */
00139 }
00140 
00141 void CL_ComboBox_Generic::select_clicked()
00142 {
00143 /*      if (skip_next_activation)
00144         {
00145                 skip_next_activation = false;
00146                 return;
00147         }
00148         activated = !activated;
00149         if (activated) sig_activated(highlighted_item);
00150 */
00151 }

Generated at Wed Apr 4 19:53:59 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001