Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUIMenuBase.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIMenuBase.cpp
00003         created:        5/4/2005
00004         author:         Tomas Lindquist Olsen (based on code by Paul D Turner)
00005         
00006         purpose:        Implementation of MenuBase widget base class
00007 *************************************************************************/
00008 /*************************************************************************
00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Lesser General Public
00014     License as published by the Free Software Foundation; either
00015     version 2.1 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Lesser General Public License for more details.
00021 
00022     You should have received a copy of the GNU Lesser General Public
00023     License along with this library; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #include "elements/CEGUIMenuBase.h"
00027 #include "elements/CEGUIPopupMenu.h"
00028 #include "elements/CEGUIMenuItem.h"
00029 
00030 // Start of CEGUI namespace section
00031 namespace CEGUI
00032 {
00033 
00034 /*************************************************************************
00035 Definition of Properties for this class
00036 *************************************************************************/
00037 MenuBaseProperties::ItemSpacing                 MenuBase::d_itemSpacingProperty;
00038 MenuBaseProperties::HorzPadding                 MenuBase::d_horzPaddingProperty;
00039 MenuBaseProperties::VertPadding                 MenuBase::d_vertPaddingProperty;
00040 MenuBaseProperties::BorderWidth                 MenuBase::d_borderWidthProperty;
00041 MenuBaseProperties::BackgroundColours   MenuBase::d_backgroundColoursProperty;
00042 MenuBaseProperties::AllowMultiplePopups MenuBase::d_allowMultiplePopupsProperty;
00043 
00044 
00045 /*************************************************************************
00046         Constants
00047 *************************************************************************/
00048 const colour MenuBase::DefaultBackgroundColour = 0xFFFFFFFF;
00049 
00050 // event strings
00051 const String MenuBase::EventNamespace("MenuBase");
00052 const String MenuBase::EventPopupOpened( (utf8*)"PopupOpened" );
00053 const String MenuBase::EventPopupClosed( (utf8*)"PopupClosed" );
00054 
00055 /*************************************************************************
00056         Constructor for MenuBase base class.
00057 *************************************************************************/
00058 MenuBase::MenuBase(const String& type, const String& name)
00059         : ItemListBase(type, name),
00060         d_itemSpacing(0.0f),
00061         d_horzPadding(0.0f),
00062         d_vertPadding(0.0f),
00063         d_borderWidth(0.0f),
00064         d_backgroundColours(DefaultBackgroundColour),
00065         d_popup(NULL),
00066         d_allowMultiplePopups(false)
00067 {
00068         // add new events specific to MenuBase.
00069         addMenuBaseEvents();
00070         
00071         // add properties for MenuBase class
00072         addMenuBaseProperties();
00073 }
00074 
00075 
00076 /*************************************************************************
00077         Destructor for MenuBase base class.
00078 *************************************************************************/
00079 MenuBase::~MenuBase(void)
00080 {
00081 }
00082 
00083 
00084 /*************************************************************************
00085         Change the currently open MenuItem PopupMenu
00086 *************************************************************************/
00087 void MenuBase::changePopupMenuItem(MenuItem* item)
00088 {
00089         if (!d_allowMultiplePopups&&d_popup==item)
00090                 return;
00091 
00092         if (!d_allowMultiplePopups&&d_popup!=NULL)
00093         {
00094                 d_popup->closePopupMenu(false);
00095                 WindowEventArgs we(d_popup->getPopupMenu());
00096                 d_popup = NULL;
00097                 onPopupClosed(we);
00098         }
00099 
00100         if (item!=NULL)
00101         {
00102                 d_popup = item;
00103                 d_popup->getPopupMenu()->openPopupMenu();
00104                 WindowEventArgs we(d_popup->getPopupMenu());
00105                 onPopupOpened(we);
00106         }
00107 
00108 }
00109 
00110 
00111 /*************************************************************************
00112         Add MenuBase specific events    
00113 *************************************************************************/
00114 void MenuBase::addMenuBaseEvents(void)
00115 {
00116         addEvent(EventPopupOpened);
00117         addEvent(EventPopupClosed);
00118 }
00119 
00120 
00121 /*************************************************************************
00122         handler invoked internally when the a MenuItem attached to this
00123         MenuBase opens its popup.
00124 *************************************************************************/
00125 void MenuBase::onPopupOpened(WindowEventArgs& e)
00126 {
00127         fireEvent(EventPopupOpened, e, EventNamespace);
00128 }
00129 
00130 
00131 /*************************************************************************
00132         handler invoked internally when the a MenuItem attached to this
00133         MenuBase closes its popup.
00134 *************************************************************************/
00135 void MenuBase::onPopupClosed(WindowEventArgs& e)
00136 {
00137         fireEvent(EventPopupClosed, e, EventNamespace);
00138 }
00139 
00140 
00141 void MenuBase::addMenuBaseProperties(void)
00142 {
00143         addProperty(&d_itemSpacingProperty);
00144     addProperty(&d_horzPaddingProperty);
00145     addProperty(&d_vertPaddingProperty);
00146     addProperty(&d_borderWidthProperty);
00147     addProperty(&d_backgroundColoursProperty);
00148     addProperty(&d_allowMultiplePopupsProperty);
00149 }
00150 
00151 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:32 2005 for Crazy Eddies GUI System by  doxygen 1.4.3