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