xref: /trunk/main/cui/source/inc/selector.hxx (revision cdf0e10c)
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 #ifndef _SVXSELECTOR_HXX
28 #define _SVXSELECTOR_HXX
29 
30 #include <vcl/lstbox.hxx>
31 #include <vcl/fixed.hxx>
32 #include <vcl/group.hxx>
33 #include <vcl/menubtn.hxx>
34 #include <svtools/svtreebx.hxx>
35 
36 #include <com/sun/star/uno/XComponentContext.hpp>
37 #include <com/sun/star/frame/XFrame.hpp>
38 #include <com/sun/star/container/XNameAccess.hpp>
39 #include <com/sun/star/script/browse/XBrowseNode.hpp>
40 
41 #define _SVSTDARR_USHORTS
42 #define _SVSTDARR_STRINGSDTOR
43 #include <svl/svstdarr.hxx>		// SvUShorts
44 #include <sfx2/minarray.hxx>
45 
46 #define SVX_CFGGROUP_FUNCTION 1
47 #define SVX_CFGFUNCTION_SLOT  2
48 #define SVX_CFGGROUP_SCRIPTCONTAINER  3
49 #define SVX_CFGFUNCTION_SCRIPT 4
50 
51 struct SvxGroupInfo_Impl
52 {
53 	sal_uInt16 		    nKind;
54 	sal_uInt16 		    nOrd;
55     ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >
56                     xBrowseNode;
57     ::rtl::OUString sURL;
58     ::rtl::OUString sHelpText;
59 	sal_Bool		    bWasOpened;
60 
61 	SvxGroupInfo_Impl( sal_uInt16 n, sal_uInt16 nr )
62         :nKind( n )
63         ,nOrd( nr )
64         ,xBrowseNode()
65         ,sURL()
66         ,sHelpText()
67         ,bWasOpened(sal_False)
68     {
69     }
70 
71 	SvxGroupInfo_Impl( sal_uInt16 n, sal_uInt16 nr, const ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >& _rxNode )
72         :nKind( n )
73         ,nOrd( nr )
74         ,xBrowseNode( _rxNode )
75         ,sURL()
76         ,sHelpText()
77         ,bWasOpened(sal_False)
78     {
79     }
80 
81     SvxGroupInfo_Impl( sal_uInt16 n, sal_uInt16 nr, const ::rtl::OUString& _rURL, const ::rtl::OUString& _rHelpText )
82         :nKind( n )
83         ,nOrd( nr )
84         ,xBrowseNode()
85         ,sURL( _rURL )
86         ,sHelpText( _rHelpText )
87         ,bWasOpened(sal_False)
88     {
89     }
90 };
91 
92 typedef SvxGroupInfo_Impl* SvxGroupInfoPtr;
93 SV_DECL_PTRARR_DEL(SvxGroupInfoArr_Impl, SvxGroupInfoPtr, 5, 5)
94 
95 class ImageProvider
96 {
97 public:
98     virtual ~ImageProvider() {}
99 
100 	virtual Image GetImage( const rtl::OUString& rCommandURL ) = 0;
101 };
102 
103 class SvxConfigFunctionListBox_Impl : public SvTreeListBox
104 {
105 friend class SvxConfigGroupListBox_Impl;
106 	Timer							aTimer;
107 	SvLBoxEntry*					pCurEntry;
108 	SvxGroupInfoArr_Impl			aArr;
109 	SvLBoxEntry*					m_pDraggingEntry;
110 
111 	DECL_LINK(						TimerHdl, Timer* );
112 	virtual void 					MouseMove( const MouseEvent& rMEvt );
113 
114 public:
115 									SvxConfigFunctionListBox_Impl( Window*, const ResId& );
116 									~SvxConfigFunctionListBox_Impl();
117 	void							ClearAll();
118 	String							GetHelpText( SvLBoxEntry *pEntry );
119 	using Window::GetHelpText;
120 	SvLBoxEntry*					GetLastSelectedEntry();
121 	void							FunctionSelected();
122 
123 	// drag n drop methods
124 	virtual sal_Int8	AcceptDrop( const AcceptDropEvent& rEvt );
125 
126 	virtual DragDropMode	NotifyStartDrag(
127 		TransferDataContainer&, SvLBoxEntry* );
128 
129 	virtual void		DragFinished( sal_Int8 );
130 };
131 
132 class SvxConfigGroupListBox_Impl : public SvTreeListBox
133 {
134 	SvxGroupInfoArr_Impl			aArr;
135     bool                            m_bShowSlots;
136 
137 	SvxConfigFunctionListBox_Impl*	pFunctionListBox;
138 	ImageProvider*					m_pImageProvider;
139 
140 	::com::sun::star::uno::Reference
141 		< ::com::sun::star::frame::XFrame > m_xFrame;
142 
143 	::com::sun::star::uno::Reference
144 		< ::com::sun::star::container::XNameAccess > m_xModuleCommands;
145 
146     Image m_hdImage;
147     Image m_hdImage_hc;
148     Image m_libImage;
149     Image m_libImage_hc;
150     Image m_macImage;
151     Image m_macImage_hc;
152     Image m_docImage;
153     Image m_docImage_hc;
154     ::rtl::OUString m_sMyMacros;
155     ::rtl::OUString m_sProdMacros;
156     Image GetImage( ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode > node, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xCtx, bool bIsRootNode, bool bHighContrast );
157     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface  > getDocumentModel( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xCtx, ::rtl::OUString& docName );
158 
159 private:
160     void    fillScriptList(
161         const ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >& _rxRootNode,
162         SvLBoxEntry* _pParentEntry,
163         bool _bCheapChildsOnDemand
164     );
165 
166 protected:
167 	virtual void	RequestingChilds( SvLBoxEntry *pEntry);
168 	virtual sal_Bool	Expand( SvLBoxEntry* pParent );
169 	using SvListView::Expand;
170 
171 public:
172 			SvxConfigGroupListBox_Impl (
173 				Window* pParent, const ResId&,
174 				bool _bShowSlots,
175 				const ::com::sun::star::uno::Reference
176 					< ::com::sun::star::frame::XFrame >& xFrame
177 			);
178 
179 			~SvxConfigGroupListBox_Impl();
180 
181 	void	Init();
182 	void	Open( SvLBoxEntry*, sal_Bool );
183 	void	ClearAll();
184 	void	GroupSelected();
185 
186 	void 	SetFunctionListBox( SvxConfigFunctionListBox_Impl *pBox )
187 		{ pFunctionListBox = pBox; }
188 
189 	void	SetImageProvider( ImageProvider* provider )
190 		{ m_pImageProvider = provider; }
191 };
192 
193 class SvxScriptSelectorDialog : public ModelessDialog
194 {
195 	FixedText						aDialogDescription;
196 	FixedText						aGroupText;
197 	SvxConfigGroupListBox_Impl 		aCategories;
198 	FixedText						aFunctionText;
199 	SvxConfigFunctionListBox_Impl	aCommands;
200 	OKButton						aOKButton;
201 	CancelButton					aCancelButton;
202 	HelpButton						aHelpButton;
203 	FixedLine						aDescription;
204 	FixedText						aDescriptionText;
205 
206 	sal_Bool							m_bShowSlots;
207 	Link							m_aAddHdl;
208 
209 	DECL_LINK( ClickHdl, Button * );
210 	DECL_LINK( SelectHdl, Control* );
211 	DECL_LINK( FunctionDoubleClickHdl, Control* );
212 
213 	void								UpdateUI();
214 	void								ResizeControls();
215 
216 public:
217 
218 	SvxScriptSelectorDialog (
219 		Window* pParent = NULL,
220 		sal_Bool bShowSlots = sal_False,
221 		const ::com::sun::star::uno::Reference
222 			< ::com::sun::star::frame::XFrame >& xFrame = 0
223 	);
224 
225 	~SvxScriptSelectorDialog ( );
226 
227 	void		SetAddHdl( const Link& rLink ) { m_aAddHdl = rLink; }
228 	const Link&	GetAddHdl() const { return m_aAddHdl; }
229 
230 	void		SetImageProvider( ImageProvider* provider )
231 		{ aCategories.SetImageProvider( provider ); }
232 
233 	String		GetScriptURL() const;
234 	String		GetSelectedDisplayName();
235 	String		GetSelectedHelpText();
236 	void		SetRunLabel();
237 	void		SetDialogDescription(const String& rDescription);
238 };
239 
240 #endif
241