00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "precomp.h"
00010 #include "listbox_default.h"
00011 #include "API/Display/Font/font.h"
00012 #include "API/GUI/scrollbar.h"
00013 #include "API/Display/Display/display.h"
00014
00015 CL_ListBox_Default::CL_ListBox_Default(
00016 CL_ListBox *_listbox,
00017 const CL_ComponentOptions &options,
00018 CL_StyleManager_Default *style)
00019 : CL_ComponentStyle(_listbox), listbox(_listbox)
00020 {
00021 this->style = style;
00022
00023 resources = style->get_resources();
00024 font = CL_Font::load("ListBox/font", resources);
00025
00026 listbox->set_item_height(font->get_height());
00027
00028 CL_Component *client_area = listbox->get_client_area();
00029
00030 int height = client_area->get_height();
00031 int max = height / font->get_height();
00032 listbox->set_max_visible_items(max);
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 slot_paint_background = listbox->sig_paint().connect(CL_CreateSlot(this, &CL_ListBox_Default::on_paint_background));
00047 slot_paint_listbox = client_area->sig_paint().connect(CL_CreateSlot(this, &CL_ListBox_Default::on_paint_listbox));
00048 }
00049
00050 CL_ListBox_Default::~CL_ListBox_Default()
00051 {
00052
00053 }
00054
00055 void CL_ListBox_Default::on_paint_background()
00056 {
00057 int width = listbox->get_width();
00058 int height = listbox->get_height();
00059
00060 if(listbox->is_enabled() == false || listbox->has_focus() == false)
00061 {
00062
00063 style->fill_rect(1, 1, width - 1, height - 1, GUICOLOR_WHITE);
00064
00065
00066 style->draw_rect(0, 0, width, height, GUICOLOR_DARK_OUTLINE);
00067 }
00068 else
00069 {
00070
00071 style->fill_rect(2, 2, width - 2, height - 2, GUICOLOR_WHITE);
00072
00073
00074 style->draw_rect(0, 0, width, height, GUICOLOR_DARK_OUTLINE);
00075
00076
00077 style->draw_box(1, 1, width - 1, height - 1, GUICOLOR_DARKER_SHADE, GUICOLOR_MEDIUM_SHADE);
00078 }
00079 }
00080
00081 void CL_ListBox_Default::on_paint_listbox()
00082 {
00083 int width = listbox->get_client_area()->get_width();
00084 int height = listbox->get_client_area()->get_height();
00085
00086 int pos = 0;
00087
00088 std::list<std::string> items = listbox->get_items();
00089 std::list<std::string>::iterator it;
00090 int offset = listbox->get_top_item();
00091 for (it = items.begin(); it != items.end(); it++)
00092 {
00093 if (pos < listbox->get_top_item())
00094 {
00095 pos++;
00096 continue;
00097 }
00098 if (pos == listbox->get_current_item())
00099 {
00100 int text_width = font->get_text_width((*it).c_str());
00101
00102 if (listbox->has_focus())
00103 {
00104 style->fill_rect(
00105 0,
00106 (pos - offset) * font->get_height(),
00107 width,
00108 (pos + 1 - offset) * font->get_height(),
00109 GUICOLOR_SELECTION);
00110 }
00111 else
00112 {
00113 style->draw_rect(
00114 0,
00115 (pos - offset) * font->get_height(),
00116 width,
00117 (pos + 1 - offset) * font->get_height(),
00118 GUICOLOR_SELECTION);
00119 }
00120 }
00121
00122 font->print_left(
00123 0,
00124 (pos - offset) * font->get_height(),
00125 (*it).c_str());
00126
00127 pos++;
00128 }
00129 }