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 #ifndef _TOOLKIT_AWT_VCLXMENU_HXX_
23 #define _TOOLKIT_AWT_VCLXMENU_HXX_
24 
25 #include <toolkit/dllapi.h>
26 #include <toolkit/helper/listenermultiplexer.hxx>
27 
28 #include <com/sun/star/awt/XMenuBar.hpp>
29 #include <com/sun/star/awt/XPopupMenu.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/lang/XTypeProvider.hpp>
32 #include <com/sun/star/lang/XUnoTunnel.hpp>
33 
34 #include <cppuhelper/weak.hxx>
35 #include <osl/mutex.hxx>
36 #include <tools/link.hxx>
37 #include <tools/list.hxx>
38 
39 namespace css = ::com::sun::star;
40 
41 class Menu;
42 class MenuBar;
43 class VclSimpleEvent;
44 
45 DECLARE_LIST( PopupMenuRefList, css::uno::Reference< css::awt::XPopupMenu >* )
46 
47 class TOOLKIT_DLLPUBLIC VCLXMenu : public css::awt::XMenuBar,
48                                    public css::awt::XPopupMenu,
49                                    public css::lang::XServiceInfo,
50                                    public css::lang::XTypeProvider,
51                                    public css::lang::XUnoTunnel,
52                                    public ::cppu::OWeakObject
53 {
54 private:
55     ::osl::Mutex                maMutex;
56     Menu*                       mpMenu;
57     MenuListenerMultiplexer     maMenuListeners;
58     PopupMenuRefList            maPopupMenueRefs;
59 
60 protected:
GetMutex()61     ::osl::Mutex&               GetMutex() { return maMutex; }
62 
63     DECL_LINK( MenuEventListener, VclSimpleEvent* );
64 
65     void ImplCreateMenu( sal_Bool bPopup );
66 
67 public:
68     VCLXMenu();
69     VCLXMenu( Menu* pMenu );
70     ~VCLXMenu();
71 
GetMenu() const72     Menu*    GetMenu() const { return mpMenu; }
73     sal_Bool IsPopupMenu() const;
74 
75     // css::uno::XInterface
76     css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) throw(css::uno::RuntimeException);
acquire()77     void SAL_CALL acquire() throw() { OWeakObject::acquire(); }
release()78     void SAL_CALL release() throw() { OWeakObject::release(); }
79 
80     // css::lang::XUnoTunnel
81     static const css::uno::Sequence< sal_Int8 >&  GetUnoTunnelId() throw();
82     static VCLXMenu* GetImplementation( const css::uno::Reference< css::uno::XInterface >& rxIFace ) throw();
83     sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& rIdentifier ) throw(css::uno::RuntimeException);
84 
85     // css::lang::XTypeProvider
86     css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() throw(css::uno::RuntimeException);
87     css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(css::uno::RuntimeException);
88 
89     // css::awt::XMenu
90     virtual void SAL_CALL addMenuListener( const css::uno::Reference< css::awt::XMenuListener >& xListener ) throw (css::uno::RuntimeException);
91     virtual void SAL_CALL removeMenuListener( const css::uno::Reference< css::awt::XMenuListener >& xListener ) throw (css::uno::RuntimeException);
92     virtual void SAL_CALL insertItem( ::sal_Int16 nItemId, const ::rtl::OUString& aText, ::sal_Int16 nItemStyle, ::sal_Int16 nItemPos ) throw (css::uno::RuntimeException);
93     virtual void SAL_CALL removeItem( ::sal_Int16 nItemPos, ::sal_Int16 nCount ) throw (css::uno::RuntimeException);
94     virtual void SAL_CALL clear(  ) throw (css::uno::RuntimeException);
95     virtual ::sal_Int16 SAL_CALL getItemCount(  ) throw (css::uno::RuntimeException);
96     virtual ::sal_Int16 SAL_CALL getItemId( ::sal_Int16 nItemPos ) throw (css::uno::RuntimeException);
97     virtual ::sal_Int16 SAL_CALL getItemPos( ::sal_Int16 nItemId ) throw (css::uno::RuntimeException);
98     virtual css::awt::MenuItemType SAL_CALL getItemType( ::sal_Int16 nItemPos ) throw (css::uno::RuntimeException);
99     virtual void SAL_CALL enableItem( ::sal_Int16 nItemId, ::sal_Bool bEnable ) throw (css::uno::RuntimeException);
100     virtual ::sal_Bool SAL_CALL isItemEnabled( ::sal_Int16 nItemId ) throw (css::uno::RuntimeException);
101     virtual void SAL_CALL hideDisabledEntries( ::sal_Bool bHide ) throw (css::uno::RuntimeException);
102     virtual void SAL_CALL enableAutoMnemonics( ::sal_Bool bEnable ) throw (css::uno::RuntimeException);
103     virtual void SAL_CALL setItemText( ::sal_Int16 nItemId, const ::rtl::OUString& aText ) throw (css::uno::RuntimeException);
104     virtual ::rtl::OUString SAL_CALL getItemText( ::sal_Int16 nItemId ) throw (css::uno::RuntimeException);
105     virtual void SAL_CALL setCommand( ::sal_Int16 nItemId, const ::rtl::OUString& aCommand ) throw (css::uno::RuntimeException);
106     virtual ::rtl::OUString SAL_CALL getCommand( ::sal_Int16 nItemId ) throw (css::uno::RuntimeException);
107     virtual void SAL_CALL setHelpCommand( ::sal_Int16 nItemId, const ::rtl::OUString& aCommand ) throw (css::uno::RuntimeException);
108     virtual ::rtl::OUString SAL_CALL getHelpCommand( ::sal_Int16 nItemId ) throw (css::uno::RuntimeException);
109     virtual void SAL_CALL setHelpText( ::sal_Int16 nItemId, const ::rtl::OUString& sHelpText ) throw (css::uno::RuntimeException);
110     virtual ::rtl::OUString SAL_CALL getHelpText( ::sal_Int16 nItemId ) throw (css::uno::RuntimeException);
111     virtual void SAL_CALL setTipHelpText( ::sal_Int16 nItemId, const ::rtl::OUString& sTipHelpText ) throw (css::uno::RuntimeException);
112     virtual ::rtl::OUString SAL_CALL getTipHelpText( ::sal_Int16 nItemId ) throw (css::uno::RuntimeException);
113     virtual ::sal_Bool SAL_CALL isPopupMenu(  ) throw (css::uno::RuntimeException);
114     virtual void SAL_CALL setPopupMenu( ::sal_Int16 nItemId, const css::uno::Reference< css::awt::XPopupMenu >& aPopupMenu ) throw (css::uno::RuntimeException);
115     virtual css::uno::Reference< css::awt::XPopupMenu > SAL_CALL getPopupMenu( ::sal_Int16 nItemId ) throw (css::uno::RuntimeException);
116 
117     // css::awt::XPopupMenu
118     virtual void SAL_CALL insertSeparator( ::sal_Int16 nItemPos ) throw (css::uno::RuntimeException);
119     virtual void SAL_CALL setDefaultItem( ::sal_Int16 nItemId ) throw (css::uno::RuntimeException);
120     virtual ::sal_Int16 SAL_CALL getDefaultItem(  ) throw (css::uno::RuntimeException);
121     virtual void SAL_CALL checkItem( ::sal_Int16 nItemId, ::sal_Bool bCheck ) throw (css::uno::RuntimeException);
122     virtual ::sal_Bool SAL_CALL isItemChecked( ::sal_Int16 nItemId ) throw (css::uno::RuntimeException);
123     virtual ::sal_Int16 SAL_CALL execute( const css::uno::Reference< css::awt::XWindowPeer >& Parent, const css::awt::Rectangle& Position, ::sal_Int16 Direction ) throw (css::uno::RuntimeException);
124     virtual ::sal_Bool SAL_CALL isInExecute(  ) throw (css::uno::RuntimeException);
125     virtual void SAL_CALL endExecute(  ) throw (css::uno::RuntimeException);
126     virtual void SAL_CALL setAcceleratorKeyEvent( ::sal_Int16 nItemId, const css::awt::KeyEvent& aKeyEvent ) throw (css::uno::RuntimeException);
127     virtual css::awt::KeyEvent SAL_CALL getAcceleratorKeyEvent( ::sal_Int16 nItemId ) throw (css::uno::RuntimeException);
128     virtual void SAL_CALL setItemImage( ::sal_Int16 nItemId, const css::uno::Reference< css::graphic::XGraphic >& xGraphic, ::sal_Bool bScale ) throw (css::uno::RuntimeException);
129     virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL getItemImage( ::sal_Int16 nItemId ) throw (css::uno::RuntimeException);
130 
131     // css::lang::XServiceInfo
132     virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (css::uno::RuntimeException);
133     virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (css::uno::RuntimeException);
134     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (css::uno::RuntimeException);
135 };
136 
137 class TOOLKIT_DLLPUBLIC VCLXMenuBar : public VCLXMenu
138 {
139 public:
140     VCLXMenuBar();
141     VCLXMenuBar( MenuBar* pMenuBar );
142 };
143 
144 class TOOLKIT_DLLPUBLIC VCLXPopupMenu : public VCLXMenu
145 {
146 public:
147     VCLXPopupMenu();
148 };
149 
150 #endif
151