From: <zou...@us...> - 2008-02-11 14:47:47
|
Revision: 1003 http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=1003&view=rev Author: zouzou123gen Date: 2008-02-11 06:47:45 -0800 (Mon, 11 Feb 2008) Log Message: ----------- extended menus everywhere, option to use basic menus Modified Paths: -------------- dcplusplus/trunk/dcpp/SettingsManager.cpp dcplusplus/trunk/dcpp/SettingsManager.h dcplusplus/trunk/smartwin/include/smartwin/GCCHeaders.h dcplusplus/trunk/smartwin/include/smartwin/WidgetFactory.h dcplusplus/trunk/smartwin/include/smartwin/WidgetFactoryPlatformSmartWinDesktop.h dcplusplus/trunk/smartwin/source/widgets/WidgetTabView.cpp dcplusplus/trunk/win32/ADLSearchFrame.cpp dcplusplus/trunk/win32/AdvancedPage.cpp dcplusplus/trunk/win32/DirectoryListingFrame.cpp dcplusplus/trunk/win32/FavHubsFrame.cpp dcplusplus/trunk/win32/FavHubsFrame.h dcplusplus/trunk/win32/FinishedFrameBase.h dcplusplus/trunk/win32/HubFrame.cpp dcplusplus/trunk/win32/MDIChildFrame.h dcplusplus/trunk/win32/MainWindow.cpp dcplusplus/trunk/win32/MainWindow.h dcplusplus/trunk/win32/PrivateFrame.cpp dcplusplus/trunk/win32/PublicHubsFrame.cpp dcplusplus/trunk/win32/QueueFrame.cpp dcplusplus/trunk/win32/QueueFrame.h dcplusplus/trunk/win32/SearchFrame.cpp dcplusplus/trunk/win32/ShellContextMenu.cpp dcplusplus/trunk/win32/SpyFrame.cpp dcplusplus/trunk/win32/SpyFrame.h dcplusplus/trunk/win32/TransferView.cpp dcplusplus/trunk/win32/UserInfoBase.h dcplusplus/trunk/win32/UsersFrame.cpp dcplusplus/trunk/win32/WaitingUsersFrame.cpp dcplusplus/trunk/win32/WinUtil.cpp dcplusplus/trunk/win32/WinUtil.h Added Paths: ----------- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenu.h dcplusplus/trunk/smartwin/source/widgets/WidgetMenu.cpp Removed Paths: ------------- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenu.h dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenuExtended.h dcplusplus/trunk/smartwin/source/widgets/WidgetMenu.cpp dcplusplus/trunk/smartwin/source/widgets/WidgetMenuExtended.cpp Modified: dcplusplus/trunk/dcpp/SettingsManager.cpp =================================================================== --- dcplusplus/trunk/dcpp/SettingsManager.cpp 2008-02-10 21:35:52 UTC (rev 1002) +++ dcplusplus/trunk/dcpp/SettingsManager.cpp 2008-02-11 14:47:45 UTC (rev 1003) @@ -77,7 +77,7 @@ "UseTLS", "AutoSearchLimit", "AltSortOrder", "AutoKickNoFavs", "PromptPassword", "SpyFrameIgnoreTthSearches", "DontDlAlreadyQueued", "MaxCommandLength", "AllowUntrustedHubs", "AllowUntrustedClients", "TLSPort", "FastHash", "SortFavUsersFirst", "ShowShellMenu", "MinSegmentSize", "FollowLinks", - "SendBloom", + "SendBloom", "OwnerDrawnMenus", "SENTRY", // Int64 "TotalUpload", "TotalDownload", @@ -273,6 +273,7 @@ setDefault(MIN_SEGMENT_SIZE, 1024); setDefault(FOLLOW_LINKS, false); setDefault(SEND_BLOOM, true); + setDefault(OWNER_DRAWN_MENUS, true); #ifdef _WIN32 setDefault(MAIN_WINDOW_STATE, SW_SHOWNORMAL); Modified: dcplusplus/trunk/dcpp/SettingsManager.h =================================================================== --- dcplusplus/trunk/dcpp/SettingsManager.h 2008-02-10 21:35:52 UTC (rev 1002) +++ dcplusplus/trunk/dcpp/SettingsManager.h 2008-02-11 14:47:45 UTC (rev 1003) @@ -90,7 +90,7 @@ USE_TLS, AUTO_SEARCH_LIMIT, ALT_SORT_ORDER, AUTO_KICK_NO_FAVS, PROMPT_PASSWORD, SPY_FRAME_IGNORE_TTH_SEARCHES, DONT_DL_ALREADY_QUEUED, MAX_COMMAND_LENGTH, ALLOW_UNTRUSTED_HUBS, ALLOW_UNTRUSTED_CLIENTS, TLS_PORT, FAST_HASH, SORT_FAVUSERS_FIRST, SHOW_SHELL_MENU, MIN_SEGMENT_SIZE, FOLLOW_LINKS, - SEND_BLOOM, + SEND_BLOOM, OWNER_DRAWN_MENUS, INT_LAST }; enum Int64Setting { INT64_FIRST = INT_LAST + 1, Modified: dcplusplus/trunk/smartwin/include/smartwin/GCCHeaders.h =================================================================== --- dcplusplus/trunk/smartwin/include/smartwin/GCCHeaders.h 2008-02-10 21:35:52 UTC (rev 1002) +++ dcplusplus/trunk/smartwin/include/smartwin/GCCHeaders.h 2008-02-11 14:47:45 UTC (rev 1003) @@ -81,6 +81,14 @@ #define COLOR_MENUBAR 30 #define ODS_HOTLIGHT 0x0040 #define ODS_INACTIVE 0x0080 + #if(_WIN32_WINNT >= 0x0500) + #ifndef ODS_NOACCEL + #define ODS_NOACCEL 0x0100 + #endif + #ifndef DT_HIDEPREFIX + #define DT_HIDEPREFIX 0x00100000 + #endif + #endif // Additional (gcc, normally) stuff Modified: dcplusplus/trunk/smartwin/include/smartwin/WidgetFactory.h =================================================================== --- dcplusplus/trunk/smartwin/include/smartwin/WidgetFactory.h 2008-02-10 21:35:52 UTC (rev 1002) +++ dcplusplus/trunk/smartwin/include/smartwin/WidgetFactory.h 2008-02-11 14:47:45 UTC (rev 1003) @@ -42,7 +42,6 @@ #include "widgets/WidgetMDIChild.h" #include "widgets/WidgetMDIFrame.h" #include "widgets/WidgetMDIParent.h" -#include "widgets/WidgetMenu.h" #include "widgets/WidgetMessageBox.h" #include "widgets/WidgetProgressBar.h" #include "widgets/WidgetRadioButton.h" @@ -202,12 +201,6 @@ /// Static object type. typedef typename WidgetStatic::ObjectType WidgetStaticPtr; - /// Menu class type. - typedef SmartWin::WidgetMenu WidgetMenu; - - /// Menu object type. - typedef typename WidgetMenu::ObjectType WidgetMenuPtr; - /// CheckBox class type. typedef SmartWin::WidgetCheckBox WidgetCheckBox; @@ -325,12 +318,6 @@ */ WidgetTreeViewPtr attachTreeView( unsigned id ); - /// Creates a Menu and returns a pointer to it. - /** The returned object is of type std::tr1::shared_ptr< WidgetMenu >, but you should use the typedef WidgetMenuPtr and not < br > - * the shared_ptr itself since this may change in future releases. - */ - WidgetMenuPtr createMenu(const typename WidgetMenu::Seed& cs = WidgetMenu::Seed()); - /// Creates a Edit Control and returns a pointer to it. /** DON'T delete the returned pointer!!! */ @@ -577,13 +564,6 @@ } template<typename ContainerWidgetType> -typename WidgetFactory< ContainerWidgetType >::WidgetMenuPtr -WidgetFactory< ContainerWidgetType >::createMenu(const typename WidgetMenu::Seed & cs) -{ - return WidgetCreator< WidgetMenu >::create( cs ); -} - -template<typename ContainerWidgetType> typename WidgetFactory< ContainerWidgetType >::WidgetTextBoxPtr WidgetFactory< ContainerWidgetType >::createTextBox( const typename WidgetTextBox::Seed & cs ) { Modified: dcplusplus/trunk/smartwin/include/smartwin/WidgetFactoryPlatformSmartWinDesktop.h =================================================================== --- dcplusplus/trunk/smartwin/include/smartwin/WidgetFactoryPlatformSmartWinDesktop.h 2008-02-10 21:35:52 UTC (rev 1002) +++ dcplusplus/trunk/smartwin/include/smartwin/WidgetFactoryPlatformSmartWinDesktop.h 2008-02-11 14:47:45 UTC (rev 1003) @@ -32,7 +32,7 @@ #include "WidgetFactoryPlatformCommon.h" #include "widgets/WidgetRichTextBox.h" #include "widgets/WidgetChooseFont.h" -#include "widgets/WidgetMenuExtended.h" +#include "widgets/WidgetMenu.h" #include "widgets/WidgetToolbar.h" #include "widgets/WidgetCoolbar.h" #include "WidgetCreator.h" @@ -56,11 +56,11 @@ /// RichEditBox object type. typedef typename WidgetRichTextBox::ObjectType WidgetRichTextBoxPtr; - /// ExtendedMenu class type. - typedef SmartWin::WidgetMenuExtended WidgetMenuExtended; + /// Menu class type. + typedef SmartWin::WidgetMenu WidgetMenu; - /// ExtendedMenu object type. - typedef typename WidgetMenuExtended::ObjectType WidgetMenuExtendedPtr; + /// Menu object type. + typedef typename WidgetMenu::ObjectType WidgetMenuPtr; /// ChooseFont class and object type. typedef SmartWin::WidgetChooseFont< SmartWin::Widget > WidgetChooseFont; @@ -113,14 +113,14 @@ return WidgetCreator< WidgetRichTextBox >::attach( this, id ); } - /// Creates an Extended Menu - /** The returned object is of type std::tr1::shared_ptr< WidgetMenuExtended >, but - * you should use the typedef WidgetMenuExtendedPtr and not <br> + /// Creates a Menu + /** The returned object is of type std::tr1::shared_ptr< WidgetMenu >, but + * you should use the typedef WidgetMenuPtr and not <br> * the shared_ptr itself since this may change in future releases. */ - WidgetMenuExtendedPtr createExtendedMenu(const typename WidgetMenuExtended::Seed& cs = WidgetMenuExtended::Seed()) + WidgetMenuPtr createMenu(const typename WidgetMenu::Seed& cs = WidgetMenu::Seed()) { - return WidgetCreator< WidgetMenuExtended >::create( this, cs ); + return WidgetCreator< WidgetMenu >::create( this, cs ); } /// Creates a Tool Bar and returns a pointer to it. Deleted: dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenu.h =================================================================== --- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenu.h 2008-02-10 21:35:52 UTC (rev 1002) +++ dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenu.h 2008-02-11 14:47:45 UTC (rev 1003) @@ -1,536 +0,0 @@ -/* - Copyright ( c ) 2005, Thomas Hansen - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met : - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the SmartWin++ nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -#ifndef WidgetMenu_h -#define WidgetMenu_h - -#include "../Application.h" -#include "../BasicTypes.h" -#include "../Dispatchers.h" -#include "../Widget.h" -#include "../xCeption.h" - -namespace SmartWin -{ -// begin namespace SmartWin - -// Forward declaring friends -template< class WidgetType > -class WidgetCreator; - -class WidgetMenu; - -class WidgetMenuBase : boost::noncopyable { -public: - - HMENU handle() { - return itsHandle; - } -protected: - WidgetMenuBase() : itsHandle(NULL) { } - virtual ~WidgetMenuBase() { - if(itsHandle) { - ::DestroyMenu(itsHandle); - } - } - - // Children, only "popup" menus are supposed to have children - std::vector< std::tr1::shared_ptr<WidgetMenu> > itsChildren; - - HMENU itsHandle; - - typedef std::map<unsigned, Widget::CallbackType> CallbackMap; - CallbackMap callbacks; - - void addCommands(Widget* widget); - -}; - -template< typename WidgetMenuType, enum Platform > -class WidgetMenuPlatformImplementation; - -/// Specialized functions in menu for Windows CE Windows API version -template<typename WidgetMenuType> -class WidgetMenuPlatformImplementation< WidgetMenuType, SmartWinCE > : - public WidgetMenuBase -{ - -public: - struct Seed { - Seed() { } - }; - - typedef std::tr1::shared_ptr< WidgetMenuType > WidgetMenuPtr; - - /// Actually creates the Menu - /** You should call WidgetFactory::createMenu if you instantiate class directly. - * <br> - * Only if you DERIVE from class you should call this function directly. - */ - void create(const typename WidgetMenuType::Seed cs) - { - itsCmdBar = CommandBar_Create( Application::instance().getAppHandle(), this->getParent()->handle(), 1 ); - if ( !itsCmdBar ) - { - xCeption x( _T( "CommandBar_Create in WidgetMenu::create fizzled..." ) ); - throw x; - } - itsHandle = ::CreateMenu(); - if ( !itsHandle ) - { - xCeption x( _T( "CreateMenu in WidgetMenu::create fizzled..." ) ); - throw x; - } - // Why on EARTH this works I have no idea whatsoever, but apparently it does... (casting to string!) - LPTSTR menuName = reinterpret_cast< LPTSTR >( itsHandle ); - CommandBar_InsertMenubarEx( itsCmdBar, reinterpret_cast< HINSTANCE >( 0 ), menuName, 0 ); - - // Since we're defaulting the window creation to no capture and no title we must add the X in the command bar... - CommandBar_AddAdornments( itsCmdBar, 0, 0 ); - } - - /// Appends a popup to the menu - /** Everything you "append" to a menu is added sequentially to the menu! <br> - * This specific "append" function appends a "popup" menu which is a menu - * containg other menus. <br> - * With other words a menu which is not an "option" but rather a new "subgroup". - * <br> - * The "File" menu of most application is for instance a "popup" menu while the - * File/Print is NOT a popup. <br> - * To append items to the popup created call one of the appendItem overloaded - * functions on the returned value of this function. <br> - * Also, although references to all menu objects must be kept ( since they're - * not collected automatically like other Widgets ) <br> - * you don't have to keep a reference to the return value of this function since - * it's being added as a reference to the children list <br> - * of the "this" object. <br> - * See the WidgetMenu sample project for a demonstration. - */ - WidgetMenuPtr appendPopup( const SmartUtil::tstring & name ) - { - WidgetMenuPtr retVal = WidgetMenuPtr( new WidgetMenuType( ) ); - HMENU popup = CreatePopupMenu(); - retVal->itsHandle = reinterpret_cast< HWND >( popup ); - ::AppendMenu( handle(), MF_POPUP, reinterpret_cast< unsigned int >( retVal->handle() ), name.c_str() ); - itsChildren.push_back( retVal ); - retVal->Widget::registerWidget(); - return retVal; - } - - WidgetMenuPlatformImplementation() - : Widget(0), itsCmdBar( 0 ) - {} - - virtual ~WidgetMenuPlatformImplementation() - { - if ( itsCmdBar ) - { - CommandBar_Destroy( itsCmdBar ); - } - } -private: - HWND itsCmdBar; -}; - -/// Specialized functions in menu for desktop Windows API version -template< typename WidgetMenuType > -class WidgetMenuPlatformImplementation< WidgetMenuType, SmartWinDesktop > : - public WidgetMenuBase -{ -protected: - WidgetMenuPlatformImplementation() { } -public: - struct Seed { - Seed(bool popup_) : popup(popup_) { } - Seed() : popup(false) { } - bool popup; - }; - - typedef std::tr1::shared_ptr< WidgetMenuType > WidgetMenuPtr; - - /// Attaches the menu to a parent window - /** Note! Menus can be switched between at runtime, you can have several menus - * that the EventHandlerClass switches between. <br> - * This can be done by attaching another menu object. <br> - * For an example of this see the WidgetMenu project. - */ - void attach( Widget * mainWindow ) - { - addCommands(mainWindow); - ::SetMenu( mainWindow->handle(), handle() ); - } - - /// Actually creates the Menu - /** You should call WidgetFactory::createMenu if you instantiate class directly. - * <br> - * Only if you DERIVE from class you should call this function directly. - */ - void create(const Seed& cs) - { - if(cs.popup) { - itsHandle = ::CreatePopupMenu(); - } else { - itsHandle = ::CreateMenu(); - } - if ( !itsHandle ) - { - xCeption x( _T( "CreateMenu in WidgetManu::create fizzled..." ) ); - throw x; - } - } - - /// Appends a popup to the menu - /** Everything you "append" to a menu is added sequentially to the menu <br> - * This specific "append" function appends a "popup" menu which is a menu - * containg other menus. <br> - * With other words a menu which is not an "option" but rather a new "subgroup". - * <br> - * The "File" menu of most application is for instance a "popup" menu while the - * File/Print is often NOT a popup. <br> - * To append items to the popup created call one of the appendItem overloaded - * functions on the returned value of this function. <br> - * Also, although references to all menu objects must be kept ( since they're - * not collected automatically like other Widgets ) <br> - * you don't have to keep a reference to the return value of this function since - * it's being added as a reference to the children list <br> - * of the "this" object. <br> - * See the WidgetMenu project for a demonstration. - */ - WidgetMenuPtr appendPopup( const SmartUtil::tstring & name ) - { - - WidgetMenuPtr retVal = WidgetMenuPtr( new WidgetMenuType( ) ); - - retVal->create(Seed(true)); - ::AppendMenu( handle(), MF_POPUP, reinterpret_cast< unsigned int >( retVal->handle() ), name.c_str() ); - itsChildren.push_back( retVal ); - return retVal; - } - - /// Returns the "System Menu" - /** The system menu is a special menu that ( normally ) is accessed by pressing - * the "window icon" at the top left of the window. <br> - * In SmartWin++ this menu can ALSO be easily manipulated and added items to - * etc... <br> - * Also, although references to all menu objects must be kept ( since they're - * not collected automatically like other Widgets ) <br> - * you don't have to keep a reference to the return value of this function since - * it's being added as a reference to the children list <br> - * of the "this" object. <br> - * See the WidgetMenu sample project for a demonstration. - */ -#ifdef PORT_ME - WidgetMenuPtr getSystemMenu() - { - HMENU h = ::GetSystemMenu( internal_::getTypedParentOrThrow < EventHandlerClass * >( this )->handle(), FALSE ); - WidgetMenuPtr sysMenu( new WidgetMenu( this->getParent() ) ); - sysMenu->Widget::itsHandle = reinterpret_cast< HWND >( h ); - sysMenu->Widget::registerWidget(); - sysMenu->isSysMenu = true; - - // We're assuming that the system menu has the same lifespan as the "this" - // menu, we must keep a reference to te system menu otherwise it will be - // "lost", therefore we add it up as a child to the "this" menu... - itsChildren.push_back( sysMenu ); - return sysMenu; - } -#endif -}; - -/// Menu class -/** \ingroup WidgetControls - * \WidgetUsageInfo - * \image html menu.PNG - * Class for creating a Menu Control which then can be attached to a WidgetWindow. - * <br> - * Note for Desktop applications only! <br> - * After you have created a menu you must call WidgetMenu::attach() to make it - * "attach" to the WidgetWindow you want it to belong to. <br> - * Related class : <br> - * WidgetMenuExtended - */ -class WidgetMenu : - public WidgetMenuPlatformImplementation< WidgetMenu, CurrentPlatform >, - public boost::enable_shared_from_this<WidgetMenu > -{ -protected: - typedef WidgetMenuPlatformImplementation< WidgetMenu, CurrentPlatform > PlatformImplementation; - - // friends - friend class WidgetMenuPlatformImplementation< WidgetMenu, CurrentPlatform >; - friend class WidgetCreator< WidgetMenu >; -public: - - WidgetMenu(); - - struct IdDispatcher - { - typedef std::tr1::function<void (unsigned)> F; - - IdDispatcher(const F& f_) : f(f_) { } - - bool operator()(const MSG& msg, LRESULT& ret) { - f(LOWORD(msg.wParam)); - return true; - } - - F f; - }; - - typedef Dispatchers::VoidVoid<> SimpleDispatcher; - - /// Class type - typedef WidgetMenu ThisType; - - /// Object type - typedef PlatformImplementation::WidgetMenuPtr ObjectType; - - /// Creational info - typedef PlatformImplementation::Seed Seed; - /// \ingroup eventsSignatures - - /// \ingroup EventHandlersWidgetMenu - /// Appends a "normal" menu item - /** eventHandler is the function that will receive the "click" event from the - * menu item. <br> - * Event handler's signature must be "void foo(unsigned int )" - * and it must be contained as a member <br> - * of the class that is defined as the EventHandlerClass, normally either the - * WidgetWindow derived class or the class derived from WidgetMenu. <br> - * See e.g. WidgetFun for an example. <br> - * The reason to why we have this "id" is because the same event handler can be - * defined for several menu items <br> - * even in fact across menu objects, therefore this number should be unique - * across the application. - */ - void appendItem( unsigned int id, const SmartUtil::tstring & name, const IdDispatcher::F& f ) { - appendItem(id, name, (ULONG_PTR)0, f); - } - void appendItem( unsigned int id, const SmartUtil::tstring & name, ULONG_PTR data, const IdDispatcher::F& f ); - void appendItem( unsigned int id, const SmartUtil::tstring & name, ULONG_PTR data, const SimpleDispatcher::F& f ); - void appendItem( unsigned int id, const SmartUtil::tstring& name, ULONG_PTR data = NULL); - - ULONG_PTR getData(unsigned int id, bool byPosition = false); - - /// Appends a separator item to the menu - /** A menu separator is basically just "air" between menu items. <br> - * A separator cannot be "clicked" or "chosen". - */ - void appendSeparatorItem(); - - /// Returns the text of a specific menu item - /** Which menu item you wish to retrieve the text for is defined by the "id" - * parameter of the function. - */ - SmartUtil::tstring getText( unsigned idOrPos, bool byPos ); - - /// Sets the text of a specific menu item - /** Which menu item you wish to set the text is defined by the "id" - * parameter of the function. - */ - void setText( unsigned id, const SmartUtil::tstring& text ); - - /// Checks (or uncheck) a specific menu item - /** Which menu item you wish to check ( or uncheck ) is passed in as the "id" - * parameter. <br> - * If the "value" parameter is true the item will be checked, otherwise it will - * be unchecked - */ - void checkItem( unsigned id, bool value = true ); - - /// Returns a boolean indicating if a specific menu item is checked or not - /** Which menu item you wish to check must be passed as the "id" parameter of the - * function - */ - bool getCheckedState( unsigned id ); - - /// Enables (or disables) a specific menu item - /** Which menu item you wish to enable ( or disable ) is passed in as the "id" - * parameter. <br> - * If the "value" parameter is true the item becomes enabled, otherwise disabled - */ - void setItemEnabled( unsigned id, bool value = true ); - - /// Returns a boolean indicating if a specific menu item is enabled or not - /** Which menu item you wish to check must be passed as the "id" parameter to the - * function. - */ - bool getItemEnabled( unsigned id ); - - /// Return the id associated with a certain position - UINT getId(unsigned postition); - - /// Return the number of items in the menu - int getCount(); - - UINT getMenuState(UINT id, bool byPosition = false); - - /// Return true if the item is a separator (by position) - bool isSeparator(UINT id, bool byPosition = false); - /// Return true if the menu item is checked - bool isChecked(UINT id, bool byPosition = false); - /// Return true if the menu item is a popup menu - bool isPopup(UINT id, bool byPosition = false); - /// Return true if the menu item is enabled (not grey and not disabled) - bool isEnabled(UINT id, bool byPosition = false); - - void setDefaultItem(UINT id, bool byPosition = false); - - ObjectType getChild(UINT position); - - /// Displays and handles a menu which can appear anywhere in the window. - /** Typically called by a Right Mouse click. If both the x and the y coordinates - * are - 1 ( default ), it'll show the context menu at the mouse position when - * the system last received a message, basically the "right" place. Depending on - * the flags it might return the id of the menu item selected, or 0 if none was - * chosen. Flags with TPM_RETURNCMD will return the menu - item, but not call - * the Event Handler. - * < ul > - * < li >TPM_CENTERALIGN : Centers the shortcut menu horizontally relative to the coordinate specified by the x parameter< /li > - * < li >TPM_LEFTALIGN : Function positions the shortcut menu so that its left side is aligned with the coordinate specified by the x parameter< /li > - * < li >TPM_RIGHTALIGN : Opposite of LEFTALIGN< /li > - * < li >TPM_BOTTOMALIGN : Aligns menu bottoms to the coordinate specified by the y parameter< /li > - * < li >TPM_TOPALIGN : Opposite of BOTTOMALIGN< /li > - * < li >TPM_VCENTERALIGN : Centers vertically relative to the y parameter< /li > - * < li >TPM_NONOTIFY : Restricts the menu from sending notifications when user clicks item< /li > - * < li >TPM_RETURNCMD : returns the menu item identifier of the user's selection in the return value but DOES NOT carry out the event handler< /li > - * < li >TPM_LEFTBUTTON : Restricts users to selecting menu items with only left mouse button< /li > - * < li >TPM_RIGHTBUTTON : User can choose menu item with both mouse buttons< /li > - * < /ul > - * None of the following are used by default but can be manually chosen if you - * manually call SystemParametersInfo - * < ul > - * < li >TPM_HORNEGANIMATION : Animates the menu from right to left< /li > - * < li >TPM_HORPOSANIMATION : Animates the menu from left to right< /li > - * < li >TPM_NOANIMATION : Displays menu without animation< /li > - * < li >TPM_VERNEGANIMATION : Animates the menu from bottom to top< /li > - * < li >TPM_VERPOSANIMATION : Animates the menu from top to bottom< /li > - * < /ul > - */ - unsigned trackPopupMenu( Widget * mainWindow, const ScreenCoordinate& sc, unsigned flags = 0 ); - - bool isSystemMenu() - { - return isSysMenu; - } - -private: - // True is menu is "system menu" (icon in top left of window) - bool isSysMenu; -}; - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Implementation of class -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -inline ULONG_PTR WidgetMenu::getData(unsigned int id, bool byPosition) { - MENUITEMINFO mii = { sizeof(MENUITEMINFO) }; - mii.fMask = MIIM_DATA; - ::GetMenuItemInfo(this->handle(), id, byPosition, &mii); - return mii.dwItemData; -} - -inline void WidgetMenu::appendSeparatorItem() -{ - ::AppendMenu( this->handle(), MF_SEPARATOR, 0, 0 ); -} - -inline UINT WidgetMenu::getId(UINT position) -{ - return ::GetMenuItemID( this->handle(), position ); -} - -inline void WidgetMenu::checkItem( unsigned id, bool value ) -{ - ::CheckMenuItem( this->handle(), id, value ? MF_CHECKED : MF_UNCHECKED ); -} - -inline bool WidgetMenu::getCheckedState( unsigned id ) -{ - return isChecked(id); -} - -inline void WidgetMenu::setItemEnabled( unsigned id, bool value ) -{ - if ( ::EnableMenuItem( this->handle(), id, value ? MF_ENABLED : MF_GRAYED ) == - 1 ) - { - xCeption x( _T( "Couldn't enable/disable the menu item, item doesn't exist" ) ); - throw x; - } -} - -inline bool WidgetMenu::getItemEnabled( unsigned id ) -{ - return isEnabled(id); -} - -inline int WidgetMenu::getCount() -{ - int count = ::GetMenuItemCount( this->handle() ); - if( count == -1 ) - throw xCeption( _T( "Couldn't get item count in getCount()" ) ); - return count; -} - -inline UINT WidgetMenu::getMenuState( UINT id, bool byPosition ) -{ - return ::GetMenuState(this->handle(), id, byPosition ? MF_BYPOSITION : MF_BYCOMMAND); -} - -inline void WidgetMenu::setDefaultItem( UINT id, bool byPosition ) -{ - ::SetMenuDefaultItem(this->handle(), id, byPosition); -} - -inline bool WidgetMenu::isChecked( UINT id, bool byPosition ) -{ - return (getMenuState(id, byPosition) & MF_CHECKED) == MF_CHECKED; -} - -inline bool WidgetMenu::isEnabled( UINT id, bool byPosition ) -{ - return !(getMenuState(id, byPosition) & (MF_DISABLED | MF_GRAYED)); -} - -inline bool WidgetMenu::isPopup( UINT id, bool byPosition ) -{ - return (getMenuState(id, byPosition) & MF_POPUP) == MF_POPUP; -} - -inline bool WidgetMenu::isSeparator( UINT id, bool byPosition ) -{ - return (getMenuState(id, byPosition) & MF_SEPARATOR) == MF_SEPARATOR; -} - -inline WidgetMenu::WidgetMenu( ) - : isSysMenu( false ) -{ -} -// end namespace SmartWin -} - -#endif Copied: dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenu.h (from rev 1000, dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenuExtended.h) =================================================================== --- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenu.h (rev 0) +++ dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenu.h 2008-02-11 14:47:45 UTC (rev 1003) @@ -0,0 +1,530 @@ +/* + Copyright ( c ) 2005, Thomas Hansen + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met : + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the SmartWin++ nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef WINCE +#ifndef WidgetMenu_h +#define WidgetMenu_h + +#include "../Application.h" +#include "../BasicTypes.h" +#include "../CanvasClasses.h" +#include "../Dispatchers.h" + +namespace SmartWin +{ +// begin namespace SmartWin + +// Forward declaring friends +template< class WidgetType > +class WidgetCreator; + +/// Contains information about menu item +struct MenuItemData +{ + /// Menu item text color + COLORREF TextColor; + + /// Menu item font + FontPtr Font; + + /// Menu item image + BitmapPtr Image; + + /// Creates new menu item with specified data + MenuItemData( + FontPtr font = FontPtr( new SmartWin::Font( ( HFONT )::GetStockObject( DEFAULT_GUI_FONT ), false ) ), + BitmapPtr image = BitmapPtr( new Bitmap( ( HBITMAP ) NULL ) ), // defaults to empty bitmap + COLORREF textColor = ::GetSysColor( COLOR_MENUTEXT ) ) + : TextColor( textColor ), + Font( font ), + Image( image ) + {} +}; + +/// \ingroup GlobalStuff +// MenuItemDataPtr type, contains rendering data for e.g. WidgetMenu +/** Helps easily create color values and so on for a WidgetMenu item! <br> +* Each Menu Item can have different colors and so on, use this smart pointer to set +* those values! +*/ +typedef std::tr1::shared_ptr< MenuItemData > MenuItemDataPtr; + +namespace private_ +{ + // //////////////////////////////////////////////////////////////////////// + // Menu item data wrapper, used internally + // MENUITEMINFO's dwItemData *should* point to it + // //////////////////////////////////////////////////////////////////////// + struct ItemDataWrapper + { + // The menu item belongs to + // For some messages (e.g. WM_MEASUREITEM), + // Windows doesn't specify it, so + // we need to keep this + HMENU menu; + + // Item index in the menu + // This is needed, because ID's for items + // are not unique (although Windows claims) + // e.g. we can have an item with ID 0, + // that is either separator or popup menu + int index; + + // Specifies if item is menu title + bool isMenuTitleItem; + + // Contains item data + MenuItemDataPtr data; + + // Wrapper Constructor + ItemDataWrapper( HMENU owner, int itemIndex, MenuItemDataPtr itemData, bool isTitleItem = false ) + : menu( owner ) + , index( itemIndex ) + , isMenuTitleItem( isTitleItem ) + , data( itemData ) + {} + + ~ItemDataWrapper() + {} + }; +} + +/// Struct for coloring different areas of WidgetMenu +/** Contains the different color settings of the WidgetMenu <br> +* Default values to constructor makes menu look roughly like MSVC++7.1 menus +*/ +struct MenuColorInfo +{ + /// Menu color + COLORREF colorMenu; + + /// Strip bar color + COLORREF colorStrip; + + /// Menu bar color + COLORREF colorMenuBar; + + /// Highlighted menu item color + COLORREF colorHighlight; + + /// Title text color + COLORREF colorTitleText; + + /// Item image background color, used for transparency effects + COLORREF colorImageBackground; + + /// Constructs MenuColorInfo objects + /** If all the default arguments are used it will construct an object making + * menus look roughly like they do in MSVC++ 7.1 <br> + * Pass your own arguments to construct other color effects + */ + MenuColorInfo( COLORREF menuColor = ColorUtilities::darkenColor( ::GetSysColor( COLOR_WINDOW ), 0.02 ), + COLORREF stripColor = ColorUtilities::darkenColor( ::GetSysColor( COLOR_3DFACE ), 0.02 ), + COLORREF menuBarColor = ::GetSysColor( COLOR_MENUBAR ), + COLORREF highlightColor = ::GetSysColor( COLOR_HIGHLIGHT ), + COLORREF titleTextColor = ::GetSysColor( COLOR_MENUTEXT ), + COLORREF imageBackground = RGB( 0, 0, 0 ) ) // black + : colorMenu( menuColor ), + colorStrip( stripColor ), + colorMenuBar( menuBarColor ), + colorHighlight( highlightColor ), + colorTitleText( titleTextColor ), + colorImageBackground( imageBackground ) + {} +}; + +/// Menu class +/** \ingroup WidgetControls +* \WidgetUsageInfo +* \image html menu.png +* Class for creating a Menu Control which then can be attached to e.g. a +* WidgetWindow. <br> +* Note for Desktop version only! <br> +* After you have created a menu you must call WidgetMenu::attach() to make it +* "attach" to the WidgetWindow you want it to belong to. <br> +* Do not be fooled, a WidgetMenu is a much more advanced menu type then the +* "normal" WidgetMenu and contains support for visualizations far beyond the +* capabilities of the WidgetMenu. <br> +* If you need those truly awesome visual menu effects use this menu control instead +* of the WidgetMenu. +*/ +class WidgetMenu : public boost::enable_shared_from_this< WidgetMenu > +{ + // friends + friend class WidgetCreator< WidgetMenu >; + +public: + /// Type of object + typedef WidgetMenu ThisType; + + /// Object type + typedef std::tr1::shared_ptr<WidgetMenu> ObjectType; + + struct Seed { + Seed(bool ownerDrawn_ = true, const MenuColorInfo& colorInfo_ = MenuColorInfo()) : popup(true), ownerDrawn(ownerDrawn_), colorInfo(colorInfo_) { } + bool popup; + bool ownerDrawn; + MenuColorInfo colorInfo; + }; + + struct IdDispatcher + { + typedef std::tr1::function<void (unsigned)> F; + + IdDispatcher(const F& f_) : f(f_) { } + + bool operator()(const MSG& msg, LRESULT& ret) { + f(LOWORD(msg.wParam)); + return true; + } + + F f; + }; + + typedef Dispatchers::VoidVoid<> SimpleDispatcher; + + struct DrawItemDispatcher { + typedef std::tr1::function<bool (int, LPDRAWITEMSTRUCT)> F; + + DrawItemDispatcher(const F& f_) : f(f_) { } + + bool operator()(const MSG& msg, LRESULT& ret) { + return f(msg.wParam, reinterpret_cast<LPDRAWITEMSTRUCT>(msg.lParam)); + } + + F f; + }; + + struct MeasureItemDispatcher { + typedef std::tr1::function<bool (LPMEASUREITEMSTRUCT)> F; + + MeasureItemDispatcher(const F& f_) : f(f_) { } + + bool operator()(const MSG& msg, LRESULT& ret) { + return f(reinterpret_cast<LPMEASUREITEMSTRUCT>(msg.lParam)); + } + + F f; + }; + + /// Rendering settting settings + static const int borderGap; /// Gap between the border and item + static const int pointerGap; /// Gap between item text and sub - menu pointer + static const int textIconGap; /// Gap between text and icon + static const int textBorderGap; /// Gap between text and rectangel border + static const int separatorHeight; /// Defines default height for rectangle containing separator + static const int minSysMenuItemWidth; /// Minimum width for system menu items + static Point defaultImageSize; /// Default image size, used when no image is available + + HMENU handle() const { + return itsHandle; + } + + HWND getParent() const { + return itsParent ? itsParent->handle() : 0; + } + + /// Actually creates the menu + /** Creates the menu, the menu will be created initially empty! + */ + void create(const Seed& cs); + + /// Attaches the menu to the parent window + void attach(); + + /// Appends a popup to the menu + /** Everything you "append" to a menu is added sequentially to the menu <br> + * This specific "append" function appends a "popup" menu which is a menu + * containing other menus. <br> + * With other words a menu which is not an "option" but rather a new "subgroup". + * <br> + * The "File" menu of most application is for instance a "popup" menu while the + * File/Print is often NOT a popup. <br> + * To append items to the popup created call one of the appendItem overloaded + * functions on the returned value of this function. <br> + * Also, although references to all menu objects must be kept ( since they're + * not collected automatically like other Widgets ) <br> + * you don't have to keep a reference to the return value of this function since + * it's being added as a reference to the children list of the "this" object. + * <br> + * A popup is basically another branch in the menu hierarchy <br> + * See the WidgetMenu project for a demonstration. + */ + ObjectType appendPopup( const SmartUtil::tstring & text, MenuItemDataPtr itemData = MenuItemDataPtr(new MenuItemData()) ); + + /// Returns the "System Menu" + /** The system menu is a special menu that ( normally ) is accessed by pressing + * the "window icon" at the top left of the window. <br> + * In SmartWin++ this menu can ALSO be easily manipulated and added items to + * etc... <br> + * Also, although references to all menu objects must be kept ( since they're + * not collected automatically like other Widgets ) <br> + * you don't have to keep a reference to the return value of this function since + * it's being added as a reference to the children list <br> + * of the "this" object. <br> + * See the WidgetMenu sample project for a demonstration. + */ + ObjectType getSystemMenu(); + + /// Setting event handler for Draw Item Event + /** The Draw Item Event will be raised when the menu needs to draw itself, if you + * wish to truly be creative and be 100% in control you must handle this Event + * and do the actualy drawing of the Menu yourself, but for most people it will + * be enough to just manipulate the background colors etc of the MenuItemData + * given to the menu in the appendItem function <br> + * Note! <br> + * If this event is handled you also MUST handle the Measure Item Event!! + */ + bool handleDrawItem(int id, LPDRAWITEMSTRUCT drawInfo); + + /// Setting event handler for Measure Item Event + /** The Measure Item Event is nessecary to handle if you want to draw the menu + * yourself since it is inside this Event Handler you're telling the system how + * much space you need to actually do the drawing <br> + * Note! <br> + * If this event is handled you also MUST handle the Draw Item Event!! + */ + bool handleMeasureItem(LPMEASUREITEMSTRUCT measureInfo); + + /// Appends a separator item to the menu + /** A menu separator is basically just "air" between menu items.< br > + * A separator cannot be "clicked" or "chosen". + */ + void appendSeparatorItem(); + + /// Appends a Menu Item + /** eventHandler is the function that will receive the "click" event from the + * menu item. <br> + * Event handler's signature must be "void foo( ObjectType, unsigned + * int )" and it must be contained as a member <br> + * of the class that is defined as the Widget, normally either the + * WidgetWindow derived class or the class derived from WidgetMenu. <br> + * See e.g. WidgetMenu for an example. <br> + * The reason to why we have this "id" is because the same event handler can be + * defined for several menu items even in fact across menu objects, therefore + * this number should be unique across the application. + */ + void appendItem(unsigned int id, const SmartUtil::tstring & text, MenuItemDataPtr itemData = MenuItemDataPtr(new MenuItemData())); + + template<typename DispatcherType> + void appendItem(unsigned int id, const SmartUtil::tstring & text, const typename DispatcherType::F& f, MenuItemDataPtr itemData = MenuItemDataPtr(new MenuItemData())) { + appendItem(id, text, itemData); + callbacks.insert(std::make_pair(id, DispatcherType(f))); + } + + void appendItem(unsigned int id, const SmartUtil::tstring & text, const IdDispatcher::F& f, MenuItemDataPtr itemData = MenuItemDataPtr(new MenuItemData())) { + appendItem<IdDispatcher>(id, text, f, itemData); + } + + void appendItem(unsigned int id, const SmartUtil::tstring & text, BitmapPtr image); + + template<typename DispatcherType> + void appendItem(unsigned int id, const SmartUtil::tstring & text, const typename DispatcherType::F& f, BitmapPtr image) { + MenuItemDataPtr itemData(new MenuItemData()); + if(ownerDrawn) + itemData->Image = image; + appendItem<DispatcherType>(id, text, f, itemData); + } + + void appendItem(unsigned int id, const SmartUtil::tstring & text, const IdDispatcher::F& f, BitmapPtr image) { + appendItem<IdDispatcher>(id, text, f, image); + } + + /// Removes specified item from this menu + /** Call this function to actually DELETE a menu item from the menu hierarchy. + * Note that you have to specify the item position; and whenever you remove an item, + * all subsequent items change positions. To remove a range of items, remove from + * end to start. + */ + void removeItem( unsigned itemIndex ); + + /// Remove all items from the menu + /** Will also delete any submenus. + */ + void removeAllItems(); + + /// Return the number of items in the menu + int getCount(); + + /// Displays and handles a menu which can appear anywhere in the window. + /** Typically called by a Right Mouse click. If both the x and the y coordinate + * is - 1 ( default ) it'll show the context menu on the position the mouse was + * at when the system last recieved a message, basically the "right" place... + * <br> + * Depending on the flags it might return the id of the menu item selected, or 0 + * if none was chosen. Flags with TPM_RETURNCMD will return the menu - item, but + * not do the menu command. + * < ul > + * < li >TPM_CENTERALIGN : Centers the shortcut menu horizontally relative to the coordinate specified by the x parameter< /li > + * < li >TPM_LEFTALIGN : Function positions the shortcut menu so that its left side is aligned with the coordinate specified by the x parameter< /li > + * < li >TPM_RIGHTALIGN : Opposite of LEFTALIGN< /li > + * < li >TPM_BOTTOMALIGN : Aligns menu bottoms to the coordinate specified by the y parameter< /li > + * < li >TPM_TOPALIGN : Opposite of BOTTOMALIGN< /li > + * < li >TPM_VCENTERALIGN : Centers vertically relative to the y parameter< /li > + * < li >TPM_NONOTIFY : Restricts the menu from sending notifications when user clicks item< /li > + * < li >TPM_RETURNCMD : returns the menu item identifier of the user's selection in the return value but DOES NOT carry out the event handler< /li > + * < li >TPM_LEFTBUTTON : Restricts users to selecting menu items with only left mouse button< /li > + * < li >TPM_RIGHTBUTTON : User can choose menu item with both mouse buttons< /li > + * < /ul > + * None of the following are used by default but can be manually chosen if you + * manually call SystemParametersInfo + * < ul > + * < li >TPM_HORNEGANIMATION : Animates the menu from right to left< /li > + * < li >TPM_HORPOSANIMATION : Animates the menu from left to right< /li > + * < li >TPM_NOANIMATION : Displays menu without animation< /li > + * < li >TPM_VERNEGANIMATION : Animates the menu from bottom to top< /li > + * < li >TPM_VERPOSANIMATION : Animates the menu from top to bottom< /li > + * < /ul > + */ + unsigned trackPopupMenu( Widget * mainWindow, const ScreenCoordinate& sc, unsigned flags = 0 ); + + /// Sets menu title + /** A WidgetMenu can have a title, this function sets that title + */ + void setTitle( const SmartUtil::tstring & title, bool drawSidebar = false ); + + /// Sets title font + /** Create a font through e.g. createFont in WidgetFactory or similar and set the + * title font to the menu title through using this function + */ + void setTitleFont( FontPtr font ); + + /// Removes menu title + /** If clearSidebar is true, sidebar is removed + */ + void clearTitle( bool clearSidebar = false ); + + /// Checks (or uncheck) a specific menu item + /** Which menu item you wish to check ( or uncheck ) is passed in as the "id" + * parameter. <br> + * If the "value" parameter is true the item will be checked, otherwise it will + * be unchecked + */ + void checkItem( unsigned id, bool value = true ); + + /// Enables (or disables) a specific menu item + /** Which menu item you wish to enable ( or disable ) is passed in as the "id" + * parameter. <br> + * If the "value" parameter is true the item becomes enabled, otherwise disabled + */ + void setItemEnabled( unsigned id, bool byPosition = false, bool value = true ); + + UINT getMenuState(UINT id, bool byPosition = false); + + /// Return true if the item is a separator (by position) + bool isSeparator(UINT id, bool byPosition = false); + /// Return true if the menu item is checked + bool isChecked(UINT id, bool byPosition = false); + /// Return true if the menu item is a popup menu + bool isPopup(UINT id, bool byPosition = false); + /// Return true if the menu item is enabled (not grey and not disabled) + bool isEnabled(UINT id, bool byPosition = false); + + void setDefaultItem(UINT id, bool byPosition = false); + + /// Returns true if menu is "system menu" (icon in top left of window) + bool isSystemMenu() + { + return isSysMenu; + } + + /// Returns the text of a specific menu item + /** Which menu item you wish to retrieve the text for is defined by the "id" + * parameter of the function. + */ + SmartUtil::tstring getText( unsigned idOrPos, bool byPos ); + + /// Sets the text of a specific menu item + /** Which menu item you wish to set the text is defined by the "id" + * parameter of the function. + */ + void setText( unsigned id, const SmartUtil::tstring& text ); + + /// Returns item data + MenuItemDataPtr getData( int itemIndex ); + + ObjectType getChild(UINT position); + + virtual ~WidgetMenu(); + +private: + /// Constructor Taking pointer to parent + explicit WidgetMenu( SmartWin::Widget * parent ); + + // This is used during menu destruction + static void destroyItemDataWrapper( private_::ItemDataWrapper * wrapper ); + + // True is menu is "system menu" (icon in top left of window) + bool isSysMenu; + + // work around for gcc + std::vector< ObjectType > & itsChildrenRef; + + // work around for gcc + std::vector < private_::ItemDataWrapper * > & itsItemDataRef; + + // its sub menus + std::vector< ObjectType > itsChildren; + + // its item data + std::vector < private_::ItemDataWrapper * > itsItemData; + + HMENU itsHandle; + + Widget* itsParent; + + bool ownerDrawn; + + // Contains information about menu colors + MenuColorInfo itsColorInfo; + + // Menu title + SmartUtil::tstring itsTitle; + + // Menu title font + FontPtr itsTitleFont; + + // if true title is drawn as sidebar + bool drawSidebar; + + typedef std::map<unsigned, Widget::CallbackType> CallbackMap; + CallbackMap callbacks; + + void addCommands(Widget* widget); + + // Returns item index in the menu item list + // If no item with specified id is found, - 1 is returned + int getItemIndex( unsigned int id ); + + WidgetMenu( const WidgetMenu & ); // Never implemented intentionally +}; + +// end namespace SmartWin +} + +#endif +#endif Deleted: dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenuExtended.h =================================================================== --- dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenuExtended.h 2008-02-10 21:35:52 UTC (rev 1002) +++ dcplusplus/trunk/smartwin/include/smartwin/widgets/WidgetMenuExtended.h 2008-02-11 14:47:45 UTC (rev 1003) @@ -1,638 +0,0 @@ -/* - Copyright ( c ) 2005, Thomas Hansen - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met : - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the SmartWin++ nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -#ifndef WINCE -#ifndef WidgetMenuExtended_h -#define WidgetMenuExtended_h - -#include "../Application.h" -#include "../BasicTypes.h" -#include "../CanvasClasses.h" - -namespace SmartWin -{ -// begin namespace SmartWin - -// Forward declaring friends -template< class WidgetType > -class WidgetCreator; - -/// Contains extended information about extended menu item -struct MenuItemData -{ - /// Menu item text color - COLORREF TextColor; - - /// Menu item font - FontPtr Font; - - /// Menu item image - BitmapPtr Image; - - /// Creates new menu item with specified data - MenuItemData( - FontPtr font = FontPtr( new SmartWin::Font( ( HFONT )::GetStockObject( DEFAULT_GUI_FONT ), false ) ), // defaults to SYSTEM_FONT - BitmapPtr image = BitmapPtr( new Bitmap( ( HBITMAP ) NULL ) ), // defaults to empty bitmap - COLORREF textColor = ::GetSysColor( COLOR_MENUTEXT ) ) - : TextColor( textColor ), - Font( font ), - Image( image ) - {} -}; - -/// \ingroup GlobalStuff -// MenuItemDataPtr type, contains rendering data for e.g. WidgetMenuExtended -/** Helps easily create color values and so on for a WidgetMenuExtended item! <br> -* Each Menu Item can have different colors and so on, use this smart pointer to set -* those values! -*/ -typedef std::tr1::shared_ptr< MenuItemData > MenuItemDataPtr; - -namespace private_ -{ - // //////////////////////////////////////////////////////////////////////// - // Menu item data wrapper, used internally - // MENUITEMINFO's dwItemData *should* point to it - // //////////////////////////////////////////////////////////////////////// - struct ItemDataWrapper - { - // The menu item belongs to - // For some messages (e.g. WM_MEASUREITEM), - // Windows doesn't specify it, so - // we need to keep this - HMENU menu; - - // Item index in the menu - // This is needed, because ID's for items - // are not unique (although Windows claims) - // e.g. we can have an item with ID 0, - // that is either separator or popup menu - int index; - - // Specifies if item is menu title - bool isMenuTitleItem; - - // Contains item data - MenuItemDataPtr data; - - // Wrapper Constructor - ItemDataWrapper( HMENU owner, int itemIndex, MenuItemDataPtr itemData, bool isTitleItem = false ) - : menu( owner ) - , index( itemIndex ) - , isMenuTitleItem( isTitleItem ) - , data( itemData ) - {} - - ~ItemDataWrapper() - {} - }; -} - -/// Struct for coloring different areas of WidgetMenuExtended -/** Contains the different color settings of the WidgetMenuExtended <br> -* Default values to constructor makes menu look roughly like MSVC++7.1 menus -*/ -struct MenuColorInfo -{ - /// Menu color - COLORREF colorMenu; - - /// Strip bar color - COLORREF colorStrip; - - /// Menu bar color - COLORREF colorMenuBar; - - /// Highlighted menu item color - COLORREF colorHighlight; - - /// Title text color - COLORREF colorTitleText; - - /// Item image background color, used for transparency effects - COLORREF colorImageBackground; - - /// Constructs MenuColorInfo objects - /** If all the default arguments are used it will construct an object making - * menus look roughly like they do in MSVC++ 7.1 <br> - * Pass your own arguments to construct other color effects - */ - MenuColorInfo( COLORREF menuColor = ColorUtilities::darkenColor( ::GetSysColor( COLOR_WINDOW ), 0.02 ), - COLORREF stripColor = ColorUtilities::darkenColor( ::GetSysColor( COLOR_3DFACE ), 0.02 ), - COLORREF menuBarColor = ::GetSysColor( COLOR_MENUBAR ), - COLORREF highlightColor = ::GetSysColor( COLOR_HIGHLIGHT ), - COLORREF titleTextColor = ::GetSysColor( COLOR_MENUTEXT ), - COLORREF imageBackground = RGB( 0, 0, 0 ) ) // black - : colorMenu( menuColor ), - colorStrip( stripColor ), - colorMenuBar( menuBarColor ), - colorHighlight( highlightColor ), - colorTitleText( titleTextColor ), - colorImageBackground( imageBackground ) - {} -}; - -// Platform specific implementation -template< class MenuType, Platform > -class WidgetMenuExtendedPlatformImplementation; - -/// Specialized functions in menu for desktop Windows API version -/** This class contains all the functions in the WidgetMenuExtended which only works -* in the Desktop Version of the OS. <br> -* Though WidgetMenuExtended class does not actually WORK on WinCE we plan to MAKE -* it work in future versions, therefore we have created the CurrentPlatform -* specialization classes for it here...!! -*/ -template< typename MenuType > -class WidgetMenuExtendedPlatformImplementation< MenuType, SmartWinDesktop > -{ -public: - typedef std::tr1::shared_ptr< MenuType > WidgetMenuExtendedPtr; - - struct Seed { - Seed(const MenuColorInfo& colorInfo_ = MenuColorInfo()) : popup(true), colorInfo(colorInfo_) { } - bool popup; - MenuColorInfo colorInfo; - }; - - HMENU handle() const { - return itsHandle; - } - - HWND getParent() const { - return itsParent ? itsParent->handle() : 0; - } - - /// Actually creates the menu - /** Creates the menu, the menu will be created initially empty! - */ - void create(const Seed& cs); - - /// Attaches the menu to the parent window - void attach(); - - /// Appends a popup to the menu - /** Everything you "append" to a menu is added sequentially to the menu <br> - * This specific "append" function appends a "popup" menu which is a menu - * containing other menus. <br> - * With other words a menu which is not an "option" but rather a new "subgroup". - * <br> - * The "File" menu of most application is for instance a "popup" menu while the - * File/Print is often NOT a popup. <br> - * To append items to the popup created call one of the appendItem overloaded - * functions on the returned value of this function. <br> - * Also, although references to all menu objects must be kept ( since they're - * not collected automatically like other Widgets ) <br> - * you don't have to keep a reference to the return value of this function since - * it's being added as a reference to the children list of the "this" object. - * <br> - * A popup is basically another branch in the menu hierarchy <br> - * See the WidgetMenu project for a demonstration. - */ - WidgetMenuExtendedPtr appendPopup( const SmartUtil::tstring & text, MenuItemDataPtr itemData = MenuItemDataPtr(new MenuItemData()) ); - - /// Returns the "System Menu" - /** The system menu is a special menu that ( normally ) is accessed by pressing - * the "window icon" at the top left of the window. <br> - * In SmartWin++ this menu can ALSO be easily manipulated and added items to - * etc... <br> - * Also, although references to all menu objects must be kept ( since they're - * not collected automatically like other Widgets ) <br> - * you don't have to keep a reference to the return value of this function since - * it's being added as a reference to the children list <br> - * of the "this" object. <br> - * See the WidgetMenu sample project for a demonstration. - */ - WidgetMenuExtendedPtr getSystemMenu(); - - /// Rendering settting settings - static const int borderGap; /// Gap between the border and item - static const int pointerGap; /// Gap between item text and sub - menu pointer - static const int textIconGap; /// Gap between text and icon - static const int textBorderGap; /// Gap between text and rectangel border - static const int separatorHeight; /// Defines default height for rectangle containing separator - static const int minSysMenuItemWidth; /// Minimum width for system menu items - static Point defaultImageSize; /// Default image size, used when no image is available - -protected: - // its sub menus - std::vector< WidgetMenuExtendedPtr > itsChildren; - - // its item data - std::vector < private_::ItemDataWrapper * > itsItemData; - - HMENU itsHandle; - - Widget* itsParent; - - // Contains information about menu colors - MenuColorInfo itsColorInfo; - - typedef std::map<unsigned, Widget::CallbackType> CallbackMap; - CallbackMap callbacks; - - void addCommands(Widget* widget); -}; - -/// Extended Menu class -/** \ingroup WidgetControls -* \WidgetUsageInfo -* \image html menuextended.png -* Class for creating an Extended Menu Control which then can be attached to e.g. a -* WidgetWindow. <br> -* Note for Desktop version only! <br> -* After you have created a menu you must call WidgetMenu::attach() to make it -* "attach" to the WidgetWindow you want it to belong to. <br> -* Do not be fooled, a WidgetMenuExtended is a much more advanced menu type then the -* "normal" WidgetMenu and contains support for visualizations far beyond the -* capabilities of the WidgetMenu. <br> -* If you need those truly awesome visual menu effects use this menu control instead -* of the WidgetMenu. -*/ -class WidgetMenuExtended : - public WidgetMenuExtendedPlatformImplementation< WidgetMenuExtended, CurrentPlatform >, - public boost::enable_shared_from_this< WidgetMenuExtended > -{ - // friends - friend class WidgetMenuExtendedPlatformImplementation< WidgetMenuExtended, CurrentPlatform >; - friend class WidgetCreator< WidgetMenuExtended >; - - typedef WidgetMenuExtendedPlatformImplementation< WidgetMenuExtended, CurrentPlatform > Implementation; -public: - /// Type of object - typedef WidgetMenuExtended ThisType; - - /// Object type - typedef WidgetMenuExtendedPlatformImplementation< WidgetMenuExtended, CurrentPlatform >::WidgetMenuExtendedPtr ObjectType; - - struct IdDispatcher - { - typedef std::tr1::function<void (unsigned)> F; - - IdDispatcher(const F& f_) : f(f_) { } - - bool operator()(const MSG& msg, LRESULT& ret) { - f(LOWORD(msg.wParam)); - return true; - } - - F f; - }; - - struct DrawItemDispatcher { - typedef std::tr1::function<bool (int, LPDRAWITEMSTRUCT)> F; - - DrawItemDispatcher(const F& f_) : f(f_) { } - - bool operator()(const MSG& msg, LRESULT& ret) { - return f(msg.wParam, reinterpret_cast<LPDRAW... [truncated message content] |