xref: /aoo42x/main/svtools/inc/svtools/fileview.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 _SVT_FILEVIEW_HXX
28 #define	_SVT_FILEVIEW_HXX
29 
30 #include "svtools/svtdllapi.h"
31 #include <com/sun/star/uno/Sequence.h>
32 #include <com/sun/star/ucb/XContent.hpp>
33 #include <vcl/ctrl.hxx>
34 #include <vcl/image.hxx>
35 #include <vcl/fixed.hxx>
36 #ifndef _SV_BUTTON_HXX
37 #include <vcl/button.hxx>
38 #endif
39 #include <vcl/dialog.hxx>
40 #include <rtl/ustring.hxx>
41 
42 // class SvtFileView -----------------------------------------------------
43 
44 #define FILEVIEW_ONLYFOLDER			0x0001
45 #define FILEVIEW_MULTISELECTION		0x0002
46 
47 #define FILEVIEW_SHOW_TITLE			0x0010
48 #define FILEVIEW_SHOW_SIZE			0x0020
49 #define FILEVIEW_SHOW_DATE			0x0040
50 #define FILEVIEW_SHOW_ALL			0x0070
51 
52 class ViewTabListBox_Impl;
53 class SvtFileView_Impl;
54 class SvLBoxEntry;
55 class HeaderBar;
56 class IUrlFilter;
57 
58 /// the result of an action in the FileView
59 enum FileViewResult
60 {
61     eSuccess,
62     eFailure,
63     eTimeout,
64     eStillRunning
65 };
66 
67 /// describes parameters for doing an action on the FileView asynchronously
68 struct FileViewAsyncAction
69 {
70     sal_uInt32  nMinTimeout;    /// minimum time to wait for a result, in milliseconds
71     sal_uInt32  nMaxTimeout;    /// maximum time to wait for a result, in milliseconds, until eTimeout is returned
72     Link        aFinishHandler; /// the handler to be called when the action is finished. Called in every case, no matter of the result
73 
74     FileViewAsyncAction()
75     {
76         nMinTimeout = nMaxTimeout = 0;
77     }
78 };
79 
80 class SVT_DLLPUBLIC SvtFileView : public Control
81 {
82 private:
83     SvtFileView_Impl*       mpImp;
84 
85 	::com::sun::star::uno::Sequence< ::rtl::OUString > mpBlackList;
86 
87 	SVT_DLLPRIVATE void					OpenFolder( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aContents );
88 
89 	DECL_DLLPRIVATE_LINK( 				HeaderSelect_Impl, HeaderBar * );
90 	DECL_DLLPRIVATE_LINK( 				HeaderEndDrag_Impl, HeaderBar * );
91 
92 protected:
93 	virtual void GetFocus();
94 
95 public:
96 	SvtFileView( Window* pParent, const ResId& rResId, sal_Bool bOnlyFolder, sal_Bool bMultiSelection );
97 	SvtFileView( Window* pParent, const ResId& rResId, sal_Int8 nFlags );
98 	~SvtFileView();
99 
100     const String&           GetViewURL() const;
101 	String					GetURL( SvLBoxEntry* pEntry ) const;
102 	String					GetCurrentURL() const;
103 
104     sal_Bool				GetParentURL( String& _rParentURL ) const;
105 	sal_Bool				CreateNewFolder( const String& rNewFolder );
106 
107 	void					SetHelpId( const rtl::OString& rHelpId );
108 	const rtl::OString&		GetHelpId( ) const;
109 	void					SetSizePixel( const Size& rNewSize );
110     using Window::SetPosSizePixel;
111 	virtual void			SetPosSizePixel( const Point& rNewPos, const Size& rNewSize );
112 
113     /** initialize the view with the content of a folder given by URL, and aply an immediate filter
114 
115         @param rFolderURL
116             the URL of the folder whose content is to be read
117         @param rFilter
118             the initial filter to be applied
119         @param pAsyncDescriptor
120             If not <NULL/>, this struct describes the parameters for doing the
121             action asynchronously.
122     */
123 	FileViewResult          Initialize(
124                                 const String& rFolderURL,
125                                 const String& rFilter,
126                                 const FileViewAsyncAction* pAsyncDescriptor,
127 								const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList
128                             );
129 
130 	FileViewResult          Initialize(
131                                 const String& rFolderURL,
132                                 const String& rFilter,
133                                 const FileViewAsyncAction* pAsyncDescriptor );
134     /** initialze the view with a sequence of contents, which have already been obtained elsewhere
135 
136         This method will never return <member>eStillRunning</member>, since it will fill the
137         view synchronously
138     */
139     sal_Bool                Initialize( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aContents );
140 
141     /** initializes the view with the content of a folder given by an UCB content
142     */
143     sal_Bool				Initialize( const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent>& _xContent,
144 										const String& rFilter );
145 
146     /** reads the current content of the current folder again, and applies the given filter to it
147 
148         Note 1: The folder is really read a second time. This implies that any new elements (which were
149         not present when you called Initialize the last time) are now displayed.
150 
151         Note 2: This method must not be called when you previously initialized the view from a sequence
152         of strings, or a UNO content object.
153 
154         @param rFilter
155             the filter to be applied
156         @param pAsyncDescriptor
157             If not <NULL/>, this struct describes the parameters for doing the
158             action asynchronously.
159     */
160 	FileViewResult          ExecuteFilter(
161                                 const String& rFilter,
162                                 const FileViewAsyncAction* pAsyncDescriptor
163                             );
164 
165     /** cancels a running async action (if any)
166 
167         @seealso Initialize
168         @seealso ExecuteFilter
169         @seealso FileViewAsyncAction
170     */
171     void                    CancelRunningAsyncAction();
172 
173     /** initializes the view with the parent folder of the current folder
174 
175         @param rNewURL
176             the URL of the folder which we just navigated to
177         @param pAsyncDescriptor
178             If not <NULL/>, this struct describes the parameters for doing the
179             action asynchronously.
180     */
181 	FileViewResult          PreviousLevel(
182                                 const FileViewAsyncAction* pAsyncDescriptor
183                             );
184 
185     void					SetNoSelection();
186 	void					ResetCursor();
187 
188 	void					SetSelectHdl( const Link& rHdl );
189 	void					SetDoubleClickHdl( const Link& rHdl );
190     void                    SetOpenDoneHdl( const Link& rHdl );
191 
192 	sal_uLong           		GetSelectionCount() const;
193 	SvLBoxEntry*			FirstSelected() const;
194 	SvLBoxEntry*			NextSelected( SvLBoxEntry* pEntry ) const;
195 	void					EnableAutoResize();
196 	void					SetFocus();
197 
198     void                    EnableContextMenu( sal_Bool bEnable );
199     void                    EnableDelete( sal_Bool bEnable );
200 	void					EnableNameReplacing( sal_Bool bEnable = sal_True );
201 								// translate folder names or display doc-title instead of file name
202 								// EnableContextMenu( sal_True )/EnableDelete(sal_True) disable name replacing!
203 
204 							// save and load column size and sort order
205 	String                  GetConfigString() const;
206 	void					SetConfigString( const String& rCfgStr );
207 
208     void                    SetUrlFilter( const IUrlFilter* _pFilter );
209     const IUrlFilter*       GetUrlFilter( ) const;
210 
211     void                    EndInplaceEditing( bool _bCancel );
212 
213 protected:
214     virtual void            StateChanged( StateChangedType nStateChange );
215 };
216 
217 // struct SvtContentEntry ------------------------------------------------
218 
219 struct SvtContentEntry
220 {
221 	sal_Bool	mbIsFolder;
222 	UniString	maURL;
223 
224 	SvtContentEntry( const UniString& rURL, sal_Bool bIsFolder ) :
225 		mbIsFolder( bIsFolder ), maURL( rURL ) {}
226 };
227 
228 namespace svtools {
229 
230 // -----------------------------------------------------------------------
231 // QueryDeleteDlg_Impl
232 // -----------------------------------------------------------------------
233 
234 enum QueryDeleteResult_Impl
235 {
236 	QUERYDELETE_YES = 0,
237 	QUERYDELETE_NO,
238 	QUERYDELETE_ALL,
239 	QUERYDELETE_CANCEL
240 };
241 
242 class SVT_DLLPUBLIC QueryDeleteDlg_Impl : public ModalDialog
243 {
244 	FixedText               _aEntryLabel;
245 	FixedText               _aEntry;
246 	FixedText               _aQueryMsg;
247 
248 	PushButton              _aYesButton;
249 	PushButton              _aAllButton;
250 	PushButton              _aNoButton;
251 	CancelButton            _aCancelButton;
252 
253     QueryDeleteResult_Impl  _eResult;
254 
255 private:
256 
257 	DECL_DLLPRIVATE_STATIC_LINK( QueryDeleteDlg_Impl, ClickLink, PushButton* );
258 
259 public:
260 
261 							QueryDeleteDlg_Impl( Window* pParent,
262 												 const String& rName );
263 
264     void                    EnableAllButton() { _aAllButton.Enable( sal_True ); }
265     QueryDeleteResult_Impl  GetResult() const { return _eResult; }
266 };
267 
268 }
269 
270 #endif // _SVT_FILEVIEW_HXX
271 
272