1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __FRAMEWORK_UIELEMENT_NEWMENUCONTROLLER_HXX_
25 #define __FRAMEWORK_UIELEMENT_NEWMENUCONTROLLER_HXX_
26 
27 //_________________________________________________________________________________________________________________
28 //	my own includes
29 //_________________________________________________________________________________________________________________
30 
31 #include <macros/xserviceinfo.hxx>
32 #include <stdtypes.h>
33 
34 //_________________________________________________________________________________________________________________
35 //	interface includes
36 //_________________________________________________________________________________________________________________
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/lang/XTypeProvider.hpp>
39 #include <com/sun/star/lang/XInitialization.hpp>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/frame/XFrame.hpp>
42 #include <com/sun/star/frame/XDispatchProvider.hpp>
43 #include <com/sun/star/frame/XDispatch.hpp>
44 #include <com/sun/star/frame/XStatusListener.hpp>
45 #include <com/sun/star/frame/XPopupMenuController.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
48 
49 //_________________________________________________________________________________________________________________
50 //	includes of other projects
51 //_________________________________________________________________________________________________________________
52 #include <svtools/popupmenucontrollerbase.hxx>
53 #include <toolkit/awt/vclxmenu.hxx>
54 #include <cppuhelper/weak.hxx>
55 #include <rtl/ustring.hxx>
56 #include <vcl/accel.hxx>
57 #ifndef _VCL_MENU_HXX_
58 #include <vcl/menu.hxx>
59 #endif
60 #include <hash_map>
61 
62 namespace framework
63 {
64     struct NewDocument
65     {
66         ::com::sun::star::util::URL                                                 aTargetURL;
67         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >   aArgSeq;
68         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >      xDispatch;
69     };
70 
71 	class NewMenuController :  public svt::PopupMenuControllerBase
72     {
73 		using svt::PopupMenuControllerBase::disposing;
74 
75 		public:
76 		    NewMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
77 		    virtual ~NewMenuController();
78 
79             // XServiceInfo
80 		    DECLARE_XSERVICEINFO
81 
82             // XInitialization
83             virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
84 
85 		    // XStatusListener
86 		    virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
87 
88             // XMenuListener
89             virtual void SAL_CALL itemSelected( const ::com::sun::star::awt::MenuEvent& rEvent ) throw (::com::sun::star::uno::RuntimeException);
90             virtual void SAL_CALL itemActivated( const ::com::sun::star::awt::MenuEvent& rEvent ) throw (::com::sun::star::uno::RuntimeException);
91 
92 		    // XEventListener
93 		    virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException );
94 
95             DECL_STATIC_LINK( NewMenuController, ExecuteHdl_Impl, NewDocument* );
96 
97         private:
98             virtual void impl_setPopupMenu();
99             struct AddInfo
100             {
101                 rtl::OUString aTargetFrame;
102                 rtl::OUString aImageId;
103             };
104 
105             typedef ::std::hash_map< int, AddInfo > AddInfoForId;
106 
107             void fillPopupMenu( com::sun::star::uno::Reference< com::sun::star::awt::XPopupMenu >& rPopupMenu );
108             void retrieveShortcutsFromConfiguration( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >& rAccelCfg,
109                                                      const ::com::sun::star::uno::Sequence< rtl::OUString >& rCommands,
110                                                      std::vector< KeyCode >& aMenuShortCuts );
111             void setAccelerators( PopupMenu* pPopupMenu );
112             void determineAndSetNewDocAccel( PopupMenu* pPopupMenu, const KeyCode& rKeyCode );
113             void setMenuImages( PopupMenu* pPopupMenu, sal_Bool bSetImages, sal_Bool bHiContrast );
114 
115         private:
116             // members
117             sal_Bool            m_bShowImages : 1,
118                                 m_bHiContrast : 1,
119                                 m_bNewMenu    : 1,
120                                 m_bModuleIdentified : 1,
121                                 m_bAcceleratorCfg : 1;
122             AddInfoForId        m_aAddInfoForItem;
123             rtl::OUString       m_aTargetFrame;
124             rtl::OUString       m_aModuleIdentifier;
125             rtl::OUString       m_aEmptyDocURL;
126             ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration > m_xDocAcceleratorManager;
127             ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration > m_xModuleAcceleratorManager;
128             ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration > m_xGlobalAcceleratorManager;
129     };
130 }
131 
132 #endif // __FRAMEWORK_UIELEMENT_NEWMENUCONTROLLER_HXX_
133