1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SVTOOLS_TOOLBARMENU_HXX_
29 #define _SVTOOLS_TOOLBARMENU_HXX_
30 
31 #include "svtools/svtdllapi.h"
32 
33 #include <com/sun/star/frame/FeatureStateEvent.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/frame/XFrame.hpp>
36 
37 #include <vector>
38 
39 #include <rtl/ref.hxx>
40 
41 #include <vcl/ctrl.hxx>
42 #include <vcl/menu.hxx>
43 #include <vcl/dockwin.hxx>
44 
45 class ValueSet;
46 
47 namespace svtools {
48 
49 class ToolbarMenuEntry;
50 struct ToolbarMenu_Impl;
51 
52 class SVT_DLLPUBLIC ToolbarMenu : public DockingWindow
53 {
54 	friend class ToolbarMenuStatusListener;
55 	friend struct ToolbarMenu_Impl;
56 public:
57 					ToolbarMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
58                                  Window* pParentWindow,
59                                  WinBits nBits );
60 
61                     ToolbarMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
62                                  Window* pParentWindow,
63                                  const ResId& rResId );
64 
65                     ~ToolbarMenu();
66 
67     virtual void    MouseMove( const MouseEvent& rMEvt );
68     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
69     virtual void    MouseButtonUp( const MouseEvent& rMEvt );
70     virtual void    KeyInput( const KeyEvent& rKEvent );
71     virtual void    Command( const CommandEvent& rCEvt );
72     virtual void    Paint( const Rectangle& rRect );
73     virtual void    RequestHelp( const HelpEvent& rHEvt );
74 	virtual void	GetFocus();
75     virtual void	LoseFocus();
76 
77 	void			appendEntry( int nEntryId, const String& rStr, MenuItemBits nItemBits = 0 );
78 	void			appendEntry( int nEntryId, const Image& rImage, MenuItemBits nItemBits = 0 );
79 	void			appendEntry( int nEntryId, const String& rStr, const Image& rImage, MenuItemBits nItemBits = 0 );
80 	void			appendEntry( int nEntryId, Control* pControl, MenuItemBits nItemBits = 0 );
81 	void			appendSeparator();
82 
83 	/** creates an empty ValueSet that is initialized and can be inserted with appendEntry. */
84 	ValueSet*		createEmptyValueSetControl();
85 
86 	void			checkEntry( int nEntryId, bool bCheck = true );
87 	bool			isEntryChecked( int nEntryId ) const;
88 
89 	void			enableEntry( int nEntryId, bool bEnable = true );
90 	bool			isEntryEnabled( int nEntryId ) const;
91 
92 	void			setEntryText( int nEntryId, const String& rStr );
93 	const String&	getEntryText( int nEntryId ) const;
94 
95 	void			setEntryImage( int nEntryId, const Image& rImage );
96 	const Image&	getEntryImage( int nEntryId ) const;
97 
98 	const Size&		getMenuSize() const;
99 
100 	void			SetSelectHdl( const Link& rLink );
101 	const Link& 	GetSelectHdl() const;
102 
103 	int				getSelectedEntryId() const;
104 	int				getHighlightedEntryId() const;
105 
106 	void			highlightFirstEntry();
107 
108 protected:
109     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
110 
111 	// todo: move to new base class that will replace SfxPopupWindow
112     void AddStatusListener( const rtl::OUString& rCommandURL );
113     void RemoveStatusListener( const rtl::OUString& rCommandURL );
114     void UpdateStatus( const rtl::OUString& rCommandURL );
115 
116 	bool IsInPopupMode();
117 	void EndPopupMode();
118 
119     // XStatusListener (subclasses must override this one to get the status updates
120 	virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
121 
122     void            StateChanged( StateChangedType nType );
123     void            DataChanged( const DataChangedEvent& rDCEvt );
124 
125 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >	GetFrame() const;
126 private:
127 	DECL_LINK( HighlightHdl, Control * );
128 
129 	void initStatusListener();
130 
131 	void			implInit( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame );
132 	void			initWindow();
133 
134 	Size			implCalcSize();
135 
136 	void			appendEntry( ToolbarMenuEntry* pEntry );
137 
138 	void			implPaint( ToolbarMenuEntry* pThisOnly = NULL, bool bHighlight = false );
139 
140 	void			implHighlightEntry( int nHighlightEntry, bool bHighlight );
141 	void			implHighlightEntry( const MouseEvent& rMEvt, bool bMBDown );
142 
143 	void			implChangeHighlightEntry( int nEntry );
144 	void			implSelectEntry( int nSelectedEntry );
145 
146 	ToolbarMenuEntry*	implCursorUpDown( bool bUp, bool bHomeEnd );
147 	ToolbarMenuEntry*	implGetEntry( int nEntry ) const;
148 	ToolbarMenuEntry*	implSearchEntry( int nEntryId ) const;
149 
150 	ToolbarMenu_Impl*	mpImpl;
151 };
152 
153 } // namespace svtools
154 
155 #endif
156