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

menuitem.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 "../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 // Overridden to restrict popupmenus to show on draw
00067 /*void CL_MenuItem::update()
00068 {
00069         sig_begin_paint();
00070         sig_paint();
00071         sig_end_paint();
00072 }
00073 */
00074 void CL_MenuItem::on_key_down(CL_Component *comp, CL_InputDevice *device, CL_Key key)
00075 {
00076 //      ((CL_MenuData *)parent)->on_item_activated(this, submenu);
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 //              std::cout << pos.x1 << "," << pos.x2 << "," << get_height() << std::endl;
00098                 submenu->set_position(pos.x1, pos.y1 + get_height());
00099 //              submenu->set_focus();
00100                 submenu->show();
00101         }
00102 //      if(submenu == (CL_PopupMenu*)false)
00103 //              ((CL_MenuData *)parent)->real_parent->set_focus();
00104 }
00105 
00106 /*
00107 void CL_MenuItem::close_children()
00108 {
00109         for (
00110                 std::list<CL_Component *>::iterator it = children.begin();
00111                 it != children.end();
00112                 it++)
00113         {
00114                 CL_PopupMenu *menu = (CL_PopupMenu *)(*it);
00115                 menu->show(false);
00116                 menu->close_children();
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 //      ((CL_MenuData *)parent)->on_item_activated(this, submenu);
00136 }

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