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

combobox_default.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 <stdio.h>
00011 #include "API/Display/Display/surface.h"
00012 #include "API/Display/Font/font.h" 
00013 #include "API/Core/Resources/resource_manager.h"
00014 #include "API/GUI/gui_manager.h"
00015 #include "combobox_default.h"
00016 #include "button_default.h"
00017 
00018 #define X_TEXT_OFFSET 4
00019 #define Y_TEXT_OFFSET 2
00020 
00021 CL_ComboBox_Default::CL_ComboBox_Default(
00022         CL_ComboBox *_combobox,
00023         const CL_ComponentOptions &options,
00024         CL_StyleManager_Default *_style) : CL_ComponentStyle(_combobox), combobox(_combobox)
00025 {
00026         style = _style;
00027         resources = style->get_resources();
00028         fnt_options = CL_Font::load("ComboBox/font", resources);
00029         sur_select_normal = CL_Surface::load("ComboBox/select_normal", resources);
00030         sur_select_toggled = CL_Surface::load("ComboBox/select_toggled", resources);
00031         sur_select_disabled = CL_Surface::load("ComboBox/select_disabled", resources);
00032 
00033         button_width = sur_select_normal->get_width();
00034         button_height = sur_select_normal->get_height();
00035 
00036         CL_Rect pos = combobox->get_position();
00037         pos.y1 += button_height;
00038         combobox->set_position(pos);
00039 
00040         select_list = NULL;
00041         // TODO: Too ugly hack!:
00042 //      combobox->skip_next_activation = false;
00043 
00044         CL_ComponentOptions b_options;
00045         #ifdef BORLAND
00046                 b_options.options.insert(std::make_pair(std::string("x") , std::string(CL_String(combobox->get_width()-button_width-1))));
00047                 b_options.options.insert(std::make_pair(std::string("y") , std::string("0")));
00048                 b_options.options.insert(std::make_pair(std::string("width") , std::string(CL_String(button_width))));
00049                 b_options.options.insert(std::make_pair(std::string("height") , std::string(CL_String(button_height))));
00050                 b_options.options.insert(std::make_pair(std::string("sur_normal") , std::string("Combobox/select_normal")));
00051                 b_options.options.insert(std::make_pair(std::string("sur_toggled") , std::string("Combobox/select_toggled")));
00052                 b_options.options.insert(std::make_pair(std::string("sur_disabled") , std::string("Combobox/select_disabled")));
00053         #else
00054                 b_options.options.insert(std::make_pair<std::string const, std::string>("x", CL_String(combobox->get_width()-button_width-1)));
00055                 b_options.options.insert(std::make_pair<std::string const, std::string>("y", "0"));
00056                 b_options.options.insert(std::make_pair<std::string const, std::string>("width", CL_String(button_width)));
00057                 b_options.options.insert(std::make_pair<std::string const, std::string>("height", CL_String(button_height)));
00058                 b_options.options.insert(std::make_pair<std::string const, std::string>("sur_normal", "Combobox/select_normal"));
00059                 b_options.options.insert(std::make_pair<std::string const, std::string>("sur_toggled", "Combobox/select_toggled"));
00060                 b_options.options.insert(std::make_pair<std::string const, std::string>("sur_disabled", "Combobox/select_disabled"));
00061         #endif
00062 
00063         // TODO: Fix this
00064 /*      combobox->set_select_button(
00065                 new CL_Button_Bitmap(
00066                         b_options,
00067                         combobox,
00068                         style));
00069 */
00070         slot_activated = combobox->sig_activated().connect(CL_CreateSlot(this, &CL_ComboBox_Default::on_listbox_activated));
00071 //      slot_deactivated = combobox->sig_deactivated().connect(CL_CreateSlot(this, &CL_ComboBox_Default::on_listbox_deactivated));
00072         slot_paint = combobox->sig_paint().connect(CL_CreateSlot(this, &CL_ComboBox_Default::on_paint));
00073 }
00074 
00075 CL_ComboBox_Default::~CL_ComboBox_Default()
00076 {
00077 /*      delete fnt_options;
00078         delete sur_select_normal;
00079         delete sur_select_toggled;
00080         delete sur_select_disabled;
00081 */
00082 }
00083 
00084 void CL_ComboBox_Default::on_paint()
00085 {
00086 /*      style->fill_rect(0, 0, combobox->get_width(), combobox->get_height(), GUICOL_TEXT_BG);
00087 
00088         style->draw_line(0, 0, combobox->get_width()-1, 0, GUICOL_TOP_SHADE);
00089         style->draw_line(0, 0, 0, combobox->get_height()-1, GUICOL_TOP_SHADE);
00090 
00091         style->draw_line(1, 1, combobox->get_width()-2, 1, GUICOL_DARK_OUTLINE);
00092         style->draw_line(1, 1, 1, combobox->get_height()-2, GUICOL_DARK_OUTLINE);
00093 
00094         style->draw_line(0, combobox->get_height()-1, combobox->get_width(), combobox->get_height()-1, GUICOL_BRIGHT_OUTLINE);
00095         style->draw_line(combobox->get_width()-1, 0, combobox->get_width()-1, combobox->get_height(), GUICOL_BRIGHT_OUTLINE);
00096 
00097         style->draw_line(1, combobox->get_height()-2, combobox->get_width()-1, combobox->get_height()-2, GUICOL_CONTOUR);
00098         style->draw_line(combobox->get_width()-2, 1, combobox->get_width()-2, combobox->get_height()-1, GUICOL_CONTOUR);
00099 */      
00100         fnt_options->print_left(X_TEXT_OFFSET, Y_TEXT_OFFSET, combobox->get_current_text().c_str());
00101 }
00102 
00103 void CL_ComboBox_Default::on_listbox_activated(int index)
00104 {
00105         // TODO: Fix this:
00106 /*      CL_ComponentOptions b_options;
00107         delete select_list;
00108 
00109         CL_Rect screen = combobox->get_screen_rect();
00110         #ifdef BORLAND
00111                 b_options.options.insert(std::make_pair(std::string("x"), std::string(CL_String(screen.x1))));
00112                 b_options.options.insert(std::make_pair(std::string("y"), std::string(CL_String(screen.y2))));
00113                 b_options.options.insert(std::make_pair(std::string("width"), std::string(CL_String(combobox->get_width()))));
00114                 b_options.options.insert(std::make_pair(std::string("value"), std::string(CL_String(combobox->get_selection()))));
00115         #else
00116                 b_options.options.insert(std::make_pair<std::string const, std::string>("x", CL_String(screen.x1)));
00117                 b_options.options.insert(std::make_pair<std::string const, std::string>("y", CL_String(screen.y2)));
00118                 b_options.options.insert(std::make_pair<std::string const, std::string>("width", CL_String(combobox->get_width())));
00119                 b_options.options.insert(std::make_pair<std::string const, std::string>("value", CL_String(combobox->get_current_item())));
00120         #endif
00121 
00122         select_list = new CL_SelectionList(b_options, NULL, style, fnt_options, combobox->m_options);
00123         selection_slot = select_list->sig_activated.connect(CL_CreateSlot(this, &CL_ComboBox_Default::on_listbox_selection));
00124         selection_cancel_slot = select_list->sig_cancelled.connect(CL_CreateSlot(this, &CL_ComboBox_Default::on_listbox_cancel));
00125         combobox->get_gui_manager()->add_child(select_list);
00126         select_list->set_focus();
00127 */
00128 }
00129 
00130 /*void CL_ComboBox_Default::on_listbox_deactivated()
00131 {
00132         if (select_list != NULL)
00133         {
00134                 select_list->close();
00135 //              get_gui_manager()->remove_component(select_list);
00136                 delete select_list;
00137                 select_list = NULL;
00138         }
00139 }
00140 */
00141 void CL_ComboBox_Default::on_listbox_highlighted(int selection)
00142 {
00143         combobox->set_current_item(selection);
00144         // TODO: fix this
00145 //      combobox->activated = false;
00146 }
00147 
00148 void CL_ComboBox_Default::on_listbox_cancel()
00149 {
00150         // TODO: fix this
00151 //      if (combobox->activated) combobox->skip_next_activation = true;
00153 }

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