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

popupmenu_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 "popupmenu_default.h"
00011 #include "menuitem_default.h"
00012 
00013 CL_PopupMenu_Default::CL_PopupMenu_Default(
00014         CL_PopupMenu *_popupmenu,
00015         const CL_ComponentOptions &options,
00016         CL_StyleManager_Default *style)
00017 : CL_ComponentStyle(_popupmenu), popupmenu(_popupmenu)
00018 {
00019         this->style = style;
00020         
00021         resources = style->get_resources();
00022 
00023         slot_paint = popupmenu->sig_paint().connect(CL_CreateSlot(this, &CL_PopupMenu_Default::on_paint));
00024 
00025         initialized = false;
00026 }
00027 
00028 void CL_PopupMenu_Default::adjust_size()
00029 {
00030         int max_surface_check_width = 0;
00031         int max_surface_icon_width = 0;
00032         int max_surface_submenu_width = 0;
00033         int max_text_width = 0;
00034         int max_width = 0;
00035         int y = 4;
00036         
00037         std::list<CL_Component *>::iterator it;
00038         std::list<CL_Component *> &children = popupmenu->get_children();
00039 
00040         // Calculate size of items
00041         for (
00042                 it = children.begin();
00043                 it != children.end();
00044                 it++)
00045         {
00046                 CL_MenuItem *menuitem = (CL_MenuItem *)(*it);
00047                 CL_MenuItem_Default *menuitem_default = (CL_MenuItem_Default *)menuitem->get_impl();
00048 
00049                 int surface_check_width = menuitem_default->calc_surface_check_width();
00050                 if(surface_check_width > max_surface_check_width)
00051                         max_surface_check_width = surface_check_width;
00052 
00053                 int surface_icon_width = menuitem_default->calc_surface_icon_width();
00054                 if(surface_icon_width > max_surface_icon_width)
00055                         max_surface_icon_width = surface_icon_width;
00056                 
00057                 int surface_submenu_width = menuitem_default->calc_surface_submenu_width();
00058                 if(surface_submenu_width > max_surface_submenu_width)
00059                         max_surface_submenu_width = surface_submenu_width;
00060 
00061                 int text_width = menuitem_default->calc_text_width();
00062                 if(text_width > max_text_width)
00063                         max_text_width = text_width;
00064 
00065                 int width = menuitem_default->calc_width();
00066                 if(width > max_width)
00067                         max_width = width;
00068         }
00069         
00070         // Set size and position of items
00071         for (
00072                 it = children.begin();
00073                 it != children.end();
00074                 it++)
00075         {
00076                 CL_MenuItem *menuitem = (CL_MenuItem *)(*it);
00077                 CL_MenuItem_Default *menuitem_default = (CL_MenuItem_Default *)menuitem->get_impl();
00078 
00079                 int pos = 4;
00080                 menuitem_default->set_surface_check_pos(pos);
00081                 pos += max_surface_check_width;
00082                 menuitem_default->set_surface_icon_pos(pos);
00083                 pos += max_surface_icon_width;
00084                 menuitem_default->set_text_pos(pos);
00085                 pos += max_text_width;
00086                 menuitem_default->set_surface_submenu_pos(pos);
00087 
00088 //              menuitem_default->draw_submenu_icon = true;
00089 
00090                 int height = menuitem_default->calc_height();
00091                 
00092                 menuitem->set_size(max_width + 4, height);
00093                 menuitem->set_position(4, y);
00094 
00095                 y += height;
00096         }
00097 
00098         // Resize popupmenu based on total children size
00099         CL_Rect pos = popupmenu->get_position();
00100         CL_Rect rect = popupmenu->get_children_rect();
00101         rect.x1 = pos.x1;
00102         rect.y1 = pos.y1;
00103         rect.x2 += pos.x1 + 4;
00104         rect.y2 += pos.y1 + 4;
00105         popupmenu->set_position(rect);
00106 }
00107 
00108 void CL_PopupMenu_Default::on_paint()
00109 {
00110         if(initialized == false)
00111         {
00112                 adjust_size();
00113                 initialized = true;
00114         }
00115 
00116         int width = popupmenu->get_width();
00117         int height = popupmenu->get_height();
00118                 
00119         style->fill_rect(2, 2, width - 2, height - 2, GUICOL_CONTOUR);
00120         style->draw_box(0, 0, width, height, GUICOL_CONTOUR, GUICOL_DARK_OUTLINE);
00121         style->draw_box(1, 1, width - 1, height - 1, GUICOL_BRIGHT_OUTLINE, GUICOL_BOTTOM_SHADE);
00122 }

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