00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "precomp.h"
00010 #include "../API/GUI/menudata.h"
00011 #include "../API/GUI/menuitem.h"
00012 #include "../API/GUI/popupmenu.h"
00013 #include "../API/GUI/gui_manager.h"
00014
00015 CL_MenuItem *CL_MenuItem::create(
00016 const CL_ComponentOptions &options,
00017 CL_Component *parent,
00018 CL_StyleManager *style)
00019 {
00020 return (CL_MenuItem *) style->create_component("menuitem", options, parent);
00021 }
00022
00023 CL_MenuItem::CL_MenuItem(const CL_ComponentOptions &options, CL_Component *parent)
00024 : CL_Component(parent)
00025 {
00026 init(1);
00027
00028 if(options.exists("text"))
00029 text = options.get_value("text");
00030 if(options.exists("separator"))
00031 separator = options.get_value_as_bool("separator");
00032 if(options.exists("enabled"))
00033 show(options.get_value_as_bool("enabled"));
00034 if(options.exists("checked"))
00035 {
00036 checked = options.get_value_as_bool("checked");
00037 checkable = true;
00038 }
00039 }
00040
00041 void CL_MenuItem::add_child(CL_Component *child)
00042 {
00043 CL_Component::add_child(child, true);
00044 submenu = (CL_PopupMenu *)child;
00045 }
00046
00047 void CL_MenuItem::init(int id)
00048 {
00049 this->id = id;
00050
00051 submenu = NULL;
00052 separator = false;
00053 checked = false;
00054 checkable = false;
00055 highlighted = false;
00056
00057 timer_popup.set_interval(250);
00058 timer_popup.disable();
00059 slots.add_slot(timer_popup.sig_timer.connect(CL_CreateSlot(this, &CL_MenuItem::on_timer_popup)));
00060
00061 slots.add_slot(sig_key_down().connect(CL_CreateSlot(this, &CL_MenuItem::on_key_down)));
00062 slots.add_slot(sig_mouse_entered().connect(CL_CreateSlot(this, &CL_MenuItem::on_mouse_enter)));
00063 slots.add_slot(sig_mouse_left().connect(CL_CreateSlot(this, &CL_MenuItem::on_mouse_leave)));
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 void CL_MenuItem::on_key_down(CL_Component *comp, CL_InputDevice *device, CL_Key key)
00075 {
00076
00077 sig_clicked();
00078
00079 if(checkable)
00080 {
00081 checked = !checked;
00082 return;
00083 }
00084
00085 if(separator)
00086 return;
00087
00088 std::list<CL_Component *> children;
00089 children = get_children();
00090
00091 if(children.size())
00092 {
00093 CL_Component *submenu = *(children.begin());
00094 get_gui_manager()->add_child(submenu);
00095
00096 CL_Rect pos = get_screen_rect();
00097
00098 submenu->set_position(pos.x1, pos.y1 + get_height());
00099
00100 submenu->show();
00101 }
00102
00103
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 void CL_MenuItem::on_mouse_enter()
00121 {
00122 highlighted = true;
00123 timer_popup.enable();
00124 }
00125
00126 void CL_MenuItem::on_mouse_leave()
00127 {
00128 highlighted = false;
00129 timer_popup.disable();
00130 }
00131
00132 void CL_MenuItem::on_timer_popup()
00133 {
00134 timer_popup.disable();
00135
00136 }