00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "precomp.h"
00010 #include "API/Core/Math/point.h"
00011 #include "API/GUI/popupmenu.h"
00012 #include "API/GUI/stylemanager.h"
00013 #include "API/GUI/gui_manager.h"
00014
00015 CL_PopupMenu *CL_PopupMenu::create(
00016 const CL_ComponentOptions &options,
00017 CL_Component *parent,
00018 CL_StyleManager *style)
00019 {
00020 return (CL_PopupMenu *) style->create_component("popupmenu", options, parent);
00021 }
00022
00023 CL_PopupMenu *CL_PopupMenu::create(
00024 const CL_Point &pos,
00025 CL_Component *parent,
00026 CL_StyleManager *style)
00027 {
00028 CL_ComponentOptions options;
00029 options.add_option_as_int("x", pos.x);
00030 options.add_option_as_int("y", pos.y);
00031
00032 return (CL_PopupMenu *) style->create_component("popupmenu", options, parent);
00033 }
00034
00035 CL_PopupMenu::CL_PopupMenu(const CL_ComponentOptions &options, CL_Component *parent)
00036 : CL_MenuData(parent)
00037 {
00038 int x = 0, y = 0, width = 0, height = 0;
00039
00040 show(false);
00041 checkable = false;
00042
00043 if(options.exists("x"))
00044 x = options.get_value_as_int("x");
00045 if(options.exists("y"))
00046 y = options.get_value_as_int("y");
00047 if(options.exists("width"))
00048 width = options.get_value_as_int("width");
00049 if(options.exists("height"))
00050 height = options.get_value_as_int("height");
00051 if(options.exists("visible"))
00052 show(options.get_value_as_bool("visible"));
00053 if(options.exists("enabled"))
00054 enable(options.get_value_as_bool("enabled"));
00055
00056 set_position(CL_Rect(x, y, x + width, y + height));
00057
00058 slots.add_slot(sig_got_focus().connect(CL_CreateSlot(this, &CL_PopupMenu::on_got_focus)));
00059 }
00060
00061 void CL_PopupMenu::close()
00062 {
00063 show(false);
00064 popup(false);
00065 sig_cancelled();
00066
00067 CL_MenuData::close();
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 void CL_PopupMenu::close_children()
00084 {
00085 std::list<CL_Component *> &children = get_children();
00086 for (
00087 std::list<CL_Component *>::iterator it = children.begin();
00088 it != children.end();
00089 it++)
00090 {
00091 CL_MenuItem *item = (CL_MenuItem *)(*it);
00092 item->close();
00093
00094 }
00095 }
00096
00097 void CL_PopupMenu::on_got_focus()
00098 {
00099 close_children();
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 void CL_PopupMenu::on_item_activated(CL_MenuItem *item, CL_PopupMenu *child)
00113 {
00114 CL_MenuData::on_item_activated(item, child);
00115
00116 if(child)
00117 {
00118 if(child->is_visible())
00119 {
00120 child->close_children();
00121 return;
00122 }
00123 get_gui_manager()->add_child(child);
00124
00125
00126
00127 }
00128 }