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