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

popupmenu_generic.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/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 void CL_PopupMenu::create(CL_Component *parent, int x, int y)
00072 {
00073         real_parent = parent;
00074         
00075         popup = true;
00076         set_parent(NULL);
00077         adjust_size();
00078         set_position(x, y);
00079         show();
00080         set_focus();
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 //              item->close_children();
00094         }
00095 }
00096 
00097 void CL_PopupMenu::on_got_focus()
00098 {
00099         close_children();
00100 }
00101 
00102 /*void CL_PopupMenu::on_popup_close()
00103 {
00104         CL_Component *comp = get_gui_manager()->get_focus_component();
00105         if(comp->is_popup())
00106                 return;
00107 
00108         cancel();
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 //              CL_Rect pos = item->get_screen_rect();
00126 //              child->create(real_parent, pos.x1 + get_width() - 10, pos.y1);
00127         }
00128 }

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