xref: /trunk/main/sfx2/source/inc/sfxpicklist.hxx (revision 353d8f4d)
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 _SFX_PICKLIST_HXX_
25 #define _SFX_PICKLIST_HXX_
26 
27 #include <osl/mutex.hxx>
28 #include <tools/string.hxx>
29 #include <vcl/menu.hxx>
30 #include <svl/lstner.hxx>
31 #include <com/sun/star/util/XStringWidth.hpp>
32 
33 #include <vector>
34 
35 #define PICKLIST_MAXSIZE  100
36 
37 class SfxPickList : public SfxListener
38 {
39 	struct PickListEntry
40 	{
PickListEntrySfxPickList::PickListEntry41 		PickListEntry( const String& _aName, const String& _aFilter, const String& _aTitle ) :
42 			aName( _aName ), aFilter( _aFilter ), aTitle( _aTitle ) {}
43 
44 		String		aName;
45 		String		aFilter;
46 		String		aTitle;
47 		String		aOptions;
48 	};
49 
50 	static SfxPickList*				pUniqueInstance;
51 	static osl::Mutex*				pMutex;
52 
53 	std::vector< PickListEntry* >	m_aPicklistVector;
54 	sal_uInt32						m_nAllowedMenuSize;
55 	::com::sun::star::uno::Reference< ::com::sun::star::util::XStringWidth > m_xStringLength;
56 
57 							SfxPickList( sal_uInt32 nMenuSize );
58 							~SfxPickList();
59 
60 	static osl::Mutex*		GetOrCreateMutex();
61 
62 	void					CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, const String& aURL, sal_uInt32 nNo );
63 	PickListEntry*			GetPickListEntry( sal_uInt32 nIndex );
64 	void					CreatePickListEntries();
65 	void					RemovePickListEntries();
66 
67 	public:
68 		static SfxPickList*	GetOrCreate( const sal_uInt32 nMenuSize );
69 		static SfxPickList*	Get();
70 		static void			Delete();
71 
GetAllowedMenuSize()72 		sal_uInt32			GetAllowedMenuSize() { return m_nAllowedMenuSize; }
GetNumOfEntries() const73 		sal_uInt32			GetNumOfEntries() const { return m_aPicklistVector.size(); }
74 		void				CreateMenuEntries( Menu* pMenu );
75 		void				ExecuteMenuEntry( sal_uInt16 nId );
76 		void				ExecuteEntry( sal_uInt32 nIndex );
77 		String				GetMenuEntryTitle( sal_uInt32 nIndex );
78 
79 		virtual void		Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
80 };
81 
82 #endif // _SFX_PICKLIST_HXX_
83