00001 /*********************************************************************** 00002 filename: CEGUIMenuItem.h 00003 created: 2/4/2005 00004 author: Tomas Lindquist Olsen (based on code by Paul D Turner) 00005 00006 purpose: Interface to base class for MenuItem widget 00007 *************************************************************************/ 00008 /*************************************************************************** 00009 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining 00012 * a copy of this software and associated documentation files (the 00013 * "Software"), to deal in the Software without restriction, including 00014 * without limitation the rights to use, copy, modify, merge, publish, 00015 * distribute, sublicense, and/or sell copies of the Software, and to 00016 * permit persons to whom the Software is furnished to do so, subject to 00017 * the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be 00020 * included in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00023 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00024 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00025 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00026 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00027 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00028 * OTHER DEALINGS IN THE SOFTWARE. 00029 ***************************************************************************/ 00030 #ifndef _CEGUIMenuItem_h_ 00031 #define _CEGUIMenuItem_h_ 00032 00033 #include "CEGUIBase.h" 00034 #include "CEGUIWindow.h" 00035 #include "elements/CEGUIItemEntry.h" 00036 00037 // Start of CEGUI namespace section 00038 namespace CEGUI 00039 { 00040 00045 class CEGUIEXPORT MenuItem : public ItemEntry 00046 { 00047 public: 00048 static const String EventNamespace; 00049 static const String WidgetTypeName; 00050 00051 /************************************************************************* 00052 Event name constants 00053 *************************************************************************/ 00054 // generated internally by Window 00055 static const String EventClicked; 00056 00057 00058 /************************************************************************* 00059 Accessor type functions 00060 *************************************************************************/ 00068 bool isHovering(void) const {return d_hovering;} 00069 00070 00078 bool isPushed(void) const {return d_pushed;} 00079 00080 00085 bool isOpened(void) const {return d_opened;} 00086 00087 00095 PopupMenu* getPopupMenu(void) const {return d_popup;} 00096 00097 00098 /************************************************************************* 00099 Manipulators 00100 *************************************************************************/ 00111 void setPopupMenu(PopupMenu* popup); 00112 00113 00121 void openPopupMenu(bool notify=true); 00122 00123 00134 void closePopupMenu(bool notify=true); 00135 00136 00144 bool togglePopupMenu(void); 00145 00146 00147 /************************************************************************* 00148 Construction and Destruction 00149 *************************************************************************/ 00154 MenuItem(const String& type, const String& name); 00155 00156 00161 virtual ~MenuItem(void); 00162 00163 00164 protected: 00165 /************************************************************************* 00166 New Event Handlers 00167 *************************************************************************/ 00172 virtual void onClicked(WindowEventArgs& e); 00173 00174 00175 /************************************************************************* 00176 Overridden event handlers 00177 *************************************************************************/ 00178 virtual void onMouseMove(MouseEventArgs& e); 00179 virtual void onMouseButtonDown(MouseEventArgs& e); 00180 virtual void onMouseButtonUp(MouseEventArgs& e); 00181 virtual void onCaptureLost(WindowEventArgs& e); 00182 virtual void onMouseLeaves(MouseEventArgs& e); 00183 virtual void onTextChanged(WindowEventArgs& e); 00184 00185 00186 /************************************************************************* 00187 Implementation Functions 00188 *************************************************************************/ 00199 void updateInternalState(const Point& mouse_pos); 00200 00201 00209 void closeAllMenuItemPopups(); 00210 00211 00222 void setPopupMenu_impl(PopupMenu* popup,bool add_as_child=true); 00223 00224 00235 virtual bool testClassName_impl(const String& class_name) const 00236 { 00237 if (class_name=="MenuItem") return true; 00238 return ItemEntry::testClassName_impl(class_name); 00239 } 00240 00241 00242 /************************************************************************* 00243 Implementation Data 00244 *************************************************************************/ 00245 bool d_pushed; 00246 bool d_hovering; 00247 bool d_opened; 00248 00249 PopupMenu* d_popup; 00250 00251 bool d_popupWasClosed; 00252 00253 00254 private: 00255 /************************************************************************* 00256 Private methods 00257 *************************************************************************/ 00258 void addMenuItemProperties(void); 00259 00260 00265 virtual void addChild_impl(Window* wnd); 00266 }; 00267 00268 } // End of CEGUI namespace section 00269 00270 #endif // end of guard _CEGUIMenuItem_h_