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

menubar_default.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 "menubar_default.h"
00011 #include "menuitem_default.h"
00012 
00013 CL_MenuBar_Default::CL_MenuBar_Default(
00014         CL_MenuBar *_menubar,
00015         const CL_ComponentOptions &options,
00016         CL_StyleManager_Default *style)
00017 : CL_ComponentStyle(_menubar), menubar(_menubar)
00018 {
00019         this->style = style;
00020         
00021         resources = style->get_resources();
00022 
00023         slot_paint = menubar->sig_paint().connect(CL_CreateSlot(this, &CL_MenuBar_Default::on_paint));
00024 
00025         initialized = false;
00026 }
00027 
00028 void CL_MenuBar_Default::adjust_size()
00029 {
00030         int max_height = 0;
00031         int x = 0;
00032         
00033         std::list<CL_Component *>::iterator it;
00034         std::list<CL_Component *> &children = menubar->get_children();
00035 
00036         // Find maximum height of all items
00037         for (
00038                 it = children.begin();
00039                 it != children.end();
00040                 it++)
00041         {
00042                 CL_MenuItem *menuitem = (CL_MenuItem *)(*it);
00043                 CL_MenuItem_Default *menuitem_default = (CL_MenuItem_Default *)menuitem->get_impl();
00044 
00045                 int height = menuitem_default->calc_height();
00046                 if(height > max_height)
00047                         max_height = height;
00048         }
00049 
00050         // Set size and position of items
00051         for (
00052                 it = children.begin();
00053                 it != children.end();
00054                 it++)
00055         {
00056                 CL_MenuItem *menuitem = (CL_MenuItem *)(*it);
00057                 CL_MenuItem_Default *menuitem_default = (CL_MenuItem_Default *)menuitem->get_impl();
00058 
00059                 int pos = 4;
00060 
00061                 menuitem_default->set_surface_check_pos(pos);
00062                 pos += menuitem_default->calc_surface_check_width();
00063 
00064                 menuitem_default->set_surface_icon_pos(pos);
00065                 pos += menuitem_default->calc_surface_icon_width();
00066         
00067                 menuitem_default->set_text_pos(pos);
00068                 pos += menuitem_default->calc_text_width();
00069         
00070                 menuitem_default->set_surface_submenu_pos(pos);
00071                 pos += menuitem_default->calc_surface_submenu_width();
00072 
00073                 CL_Rect position = CL_Rect(x, 0, x + pos, max_height);
00074 
00075                 menuitem->set_position(position);
00076                 menuitem_default->set_draw_style(false);
00077 
00078                 x += pos;
00079         }
00080 
00081         // If any child is taller than parent, resize parent
00082         CL_Rect parent_rect = menubar->get_position();
00083         CL_Rect children_rect = menubar->get_children_rect();
00084         if(children_rect.get_height() > parent_rect.get_height())
00085                 menubar->set_size(parent_rect.get_width(), children_rect.get_height());
00086 }
00087 
00088 void CL_MenuBar_Default::on_paint()
00089 {
00090         if(initialized == false)
00091         {
00092                 adjust_size();
00093                 initialized = true;
00094         }
00095 
00096         int width = menubar->get_width();
00097         int height = menubar->get_height();
00098         
00099         style->fill_rect(1, 1, width - 1, height - 1, GUICOL_CONTOUR);
00100         style->draw_box(0, 0, width, height, GUICOL_BRIGHT_OUTLINE, GUICOL_BOTTOM_SHADE);
00101 }

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