xref: /trunk/main/sfx2/source/dialog/filedlgimpl.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1*353d8f4dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*353d8f4dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*353d8f4dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*353d8f4dSAndrew Rist  * distributed with this work for additional information
6*353d8f4dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*353d8f4dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*353d8f4dSAndrew Rist  * "License"); you may not use this file except in compliance
9*353d8f4dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*353d8f4dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*353d8f4dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*353d8f4dSAndrew Rist  * software distributed under the License is distributed on an
15*353d8f4dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*353d8f4dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*353d8f4dSAndrew Rist  * specific language governing permissions and limitations
18*353d8f4dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*353d8f4dSAndrew Rist  *************************************************************/
21*353d8f4dSAndrew Rist 
22*353d8f4dSAndrew Rist 
23cdf0e10cSrcweir #ifndef _SFX_FILEDLGIMPL_HXX
24cdf0e10cSrcweir #define _SFX_FILEDLGIMPL_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <vcl/timer.hxx>
27cdf0e10cSrcweir #include <vcl/graph.hxx>
28cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
29cdf0e10cSrcweir #include <com/sun/star/beans/StringPair.hpp>
30cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
31cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
32cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
33cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XDialogClosedListener.hpp>
34cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR
37cdf0e10cSrcweir #include <svl/svstdarr.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
40cdf0e10cSrcweir #include <comphelper/sequenceasvector.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir class SfxFilterMatcher;
43cdf0e10cSrcweir class GraphicFilter;
44cdf0e10cSrcweir class FileDialogHelper;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace sfx2
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     typedef ::com::sun::star::beans::StringPair FilterPair;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     class FileDialogHelper_Impl :
51cdf0e10cSrcweir         public ::cppu::WeakImplHelper2<
52cdf0e10cSrcweir             ::com::sun::star::ui::dialogs::XFilePickerListener,
53cdf0e10cSrcweir             ::com::sun::star::ui::dialogs::XDialogClosedListener >
54cdf0e10cSrcweir     {
55cdf0e10cSrcweir         friend class FileDialogHelper;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir         ::com::sun::star::uno::Reference < ::com::sun::star::ui::dialogs::XFilePicker > mxFileDlg;
58cdf0e10cSrcweir         ::com::sun::star::uno::Reference < ::com::sun::star::container::XNameAccess >   mxFilterCFG;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir         std::vector< FilterPair >   maFilters;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir         SfxFilterMatcher*           mpMatcher;
63cdf0e10cSrcweir         GraphicFilter*              mpGraphicFilter;
64cdf0e10cSrcweir         FileDialogHelper*           mpAntiImpl;
65cdf0e10cSrcweir         Window*                     mpPreferredParentWindow;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir         ::comphelper::SequenceAsVector< ::rtl::OUString > mlLastURLs;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         ::rtl::OUString             maPath;
70cdf0e10cSrcweir         ::rtl::OUString             maFileName;
71cdf0e10cSrcweir         ::rtl::OUString             maCurFilter;
72cdf0e10cSrcweir         ::rtl::OUString             maSelectFilter;
73cdf0e10cSrcweir         ::rtl::OUString             maButtonLabel;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         Timer                       maPreViewTimer;
76cdf0e10cSrcweir         Graphic                     maGraphic;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         const short                 m_nDialogType;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         SfxFilterFlags              m_nMustFlags;
81cdf0e10cSrcweir         SfxFilterFlags              m_nDontFlags;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         sal_uIntPtr                     mnPostUserEventId;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         ErrCode                     mnError;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         FileDialogHelper::Context   meContext;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         sal_Bool                    mbHasPassword           : 1;
90cdf0e10cSrcweir         sal_Bool                    mbIsPwdEnabled          : 1;
91cdf0e10cSrcweir         sal_Bool                    m_bHaveFilterOptions    : 1;
92cdf0e10cSrcweir         sal_Bool                    mbHasVersions           : 1;
93cdf0e10cSrcweir         sal_Bool                    mbHasAutoExt            : 1;
94cdf0e10cSrcweir         sal_Bool                    mbHasLink               : 1;
95cdf0e10cSrcweir         sal_Bool                    mbHasPreview            : 1;
96cdf0e10cSrcweir         sal_Bool                    mbShowPreview           : 1;
97cdf0e10cSrcweir         sal_Bool                    mbIsSaveDlg             : 1;
98cdf0e10cSrcweir         sal_Bool                    mbExport                : 1;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         sal_Bool                    mbDeleteMatcher         : 1;
101cdf0e10cSrcweir         sal_Bool                    mbInsert                : 1;
102cdf0e10cSrcweir         sal_Bool                    mbSystemPicker          : 1;
103cdf0e10cSrcweir         sal_Bool                    mbPwdCheckBoxState      : 1;
104cdf0e10cSrcweir         sal_Bool                    mbSelection             : 1;
105cdf0e10cSrcweir         sal_Bool                    mbSelectionEnabled      : 1;
106cdf0e10cSrcweir         sal_Bool                    mbHasSelectionBox       : 1;
107cdf0e10cSrcweir         sal_Bool                    mbSelectionFltrEnabled  : 1;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     private:
110cdf0e10cSrcweir         void                    addFilters( sal_Int64 nFlags,
111cdf0e10cSrcweir                                             const String& rFactory,
112cdf0e10cSrcweir                                             SfxFilterFlags nMust,
113cdf0e10cSrcweir                                             SfxFilterFlags nDont );
114cdf0e10cSrcweir         void                    addFilter( const ::rtl::OUString& rFilterName,
115cdf0e10cSrcweir                                            const ::rtl::OUString& rExtension );
116cdf0e10cSrcweir         void                    addGraphicFilter();
117cdf0e10cSrcweir         void                    enablePasswordBox( sal_Bool bInit );
118cdf0e10cSrcweir         void                    updateFilterOptionsBox();
119cdf0e10cSrcweir         void                    updateExportButton();
120cdf0e10cSrcweir         void                    updateSelectionBox();
121cdf0e10cSrcweir         void                    updateVersions();
122cdf0e10cSrcweir         void                    updatePreviewState( sal_Bool _bUpdatePreviewWindow = sal_True );
123cdf0e10cSrcweir         void                    dispose();
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         void                    loadConfig();
126cdf0e10cSrcweir         void                    saveConfig();
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         const SfxFilter*        getCurentSfxFilter();
129cdf0e10cSrcweir         sal_Bool                updateExtendedControl( sal_Int16 _nExtendedControlId, sal_Bool _bEnable );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         ErrCode                 getGraphic( const ::rtl::OUString& rURL, Graphic& rGraphic ) const;
132cdf0e10cSrcweir         void                    setDefaultValues();
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         void                    preExecute();
135cdf0e10cSrcweir         void                    postExecute( sal_Int16 _nResult );
136cdf0e10cSrcweir         sal_Int16               implDoExecute();
137cdf0e10cSrcweir         void                    implStartExecute();
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         void                    correctVirtualDialogType();
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         void                    setControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir         sal_Bool                CheckFilterOptionsCapability( const SfxFilter* _pFilter );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         sal_Bool                isInOpenMode() const;
146cdf0e10cSrcweir         String                  getCurrentFilterUIName() const;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         void                    LoadLastUsedFilter( const ::rtl::OUString& _rContextIdentifier );
149cdf0e10cSrcweir         void                    SaveLastUsedFilter( const ::rtl::OUString& _rContextIdentifier );
150cdf0e10cSrcweir         void                    SaveLastUsedFilter( void );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         void                    implInitializeFileName( );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         void                    implGetAndCacheFiles( const ::com::sun::star::uno::Reference< XInterface >& xPicker  ,
155cdf0e10cSrcweir                                                             SvStringsDtor*&               rpURLList,
156cdf0e10cSrcweir                                                       const SfxFilter*                    pFilter  );
157cdf0e10cSrcweir         String                  implEnsureURLExtension(const String& sURL      ,
158cdf0e10cSrcweir                                                        const String& sExtension);
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         DECL_LINK( TimeOutHdl_Impl, Timer* );
161cdf0e10cSrcweir         DECL_LINK( HandleEvent, FileDialogHelper* );
162cdf0e10cSrcweir         DECL_LINK( InitControls, void* );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     public:
165cdf0e10cSrcweir         // XFilePickerListener methods
166cdf0e10cSrcweir         virtual void SAL_CALL               fileSelectionChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
167cdf0e10cSrcweir         virtual void SAL_CALL               directoryChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
168cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL    helpRequested( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
169cdf0e10cSrcweir         virtual void SAL_CALL               controlStateChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent ) throw( ::com::sun::star::uno::RuntimeException );
170cdf0e10cSrcweir         virtual void SAL_CALL               dialogSizeChanged() throw( ::com::sun::star::uno::RuntimeException );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         // XDialogClosedListener methods
173cdf0e10cSrcweir         virtual void SAL_CALL               dialogClosed( const ::com::sun::star::ui::dialogs::DialogClosedEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException);
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         // XEventListener methods
176cdf0e10cSrcweir         virtual void SAL_CALL       disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         // handle XFilePickerListener events
179cdf0e10cSrcweir         void                    handleFileSelectionChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
180cdf0e10cSrcweir         void                    handleDirectoryChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
181cdf0e10cSrcweir         ::rtl::OUString         handleHelpRequested( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
182cdf0e10cSrcweir         void                    handleControlStateChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
183cdf0e10cSrcweir         void                    handleDialogSizeChanged();
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         // Own methods
186cdf0e10cSrcweir                                 FileDialogHelper_Impl(
187cdf0e10cSrcweir                                     FileDialogHelper* _pAntiImpl,
188cdf0e10cSrcweir                                     const short nDialogType,
189cdf0e10cSrcweir                                     sal_Int64 nFlags,
190cdf0e10cSrcweir                                     sal_Int16 nDialog = SFX2_IMPL_DIALOG_CONFIG,
191cdf0e10cSrcweir                                     Window* _pPreferredParentWindow = NULL,
192cdf0e10cSrcweir                                     const String& sStandardDir = String::CreateFromAscii( "" ),
193cdf0e10cSrcweir                                     const ::com::sun::star::uno::Sequence< ::rtl::OUString >&   rBlackList = ::com::sun::star::uno::Sequence< ::rtl::OUString >()
194cdf0e10cSrcweir                                 );
195cdf0e10cSrcweir         virtual                 ~FileDialogHelper_Impl();
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         ErrCode                 execute( SvStringsDtor*& rpURLList,
198cdf0e10cSrcweir                                          SfxItemSet *&   rpSet,
199cdf0e10cSrcweir                                          String&         rFilter );
200cdf0e10cSrcweir         ErrCode                 execute();
201cdf0e10cSrcweir 
202cdf0e10cSrcweir         void                    setFilter( const ::rtl::OUString& rFilter );
203cdf0e10cSrcweir 
204cdf0e10cSrcweir         /** sets the directory which should be browsed
205cdf0e10cSrcweir 
206cdf0e10cSrcweir             <p>If the given path does not point to a valid (existent and accessible) folder, the request
207cdf0e10cSrcweir             is silently dropped</p>
208cdf0e10cSrcweir         */
209cdf0e10cSrcweir         void                    displayFolder( const ::rtl::OUString& rPath );
210cdf0e10cSrcweir         void                    setFileName( const ::rtl::OUString& _rFile );
211cdf0e10cSrcweir 
212cdf0e10cSrcweir         ::rtl::OUString         getPath() const;
213cdf0e10cSrcweir         ::rtl::OUString         getFilter() const;
214cdf0e10cSrcweir         void                    getRealFilter( String& _rFilter ) const;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir         ErrCode                 getGraphic( Graphic& rGraphic ) const;
217cdf0e10cSrcweir         void                    createMatcher( const String& rFactory );
218cdf0e10cSrcweir 
219cdf0e10cSrcweir         sal_Bool                isShowFilterExtensionEnabled() const;
220cdf0e10cSrcweir         void                    addFilterPair( const ::rtl::OUString& rFilter,
221cdf0e10cSrcweir                                                const ::rtl::OUString& rFilterWithExtension );
222cdf0e10cSrcweir         ::rtl::OUString         getFilterName( const ::rtl::OUString& rFilterWithExtension ) const;
223cdf0e10cSrcweir         ::rtl::OUString         getFilterWithExtension( const ::rtl::OUString& rFilter ) const;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         void                    SetContext( FileDialogHelper::Context _eNewContext );
226cdf0e10cSrcweir 
isSystemFilePicker() const227cdf0e10cSrcweir         inline sal_Bool         isSystemFilePicker() const { return mbSystemPicker; }
isPasswordEnabled() const228cdf0e10cSrcweir         inline sal_Bool         isPasswordEnabled() const { return mbIsPwdEnabled; }
229cdf0e10cSrcweir     };
230cdf0e10cSrcweir 
231cdf0e10cSrcweir }   // end of namespace sfx2
232cdf0e10cSrcweir 
233cdf0e10cSrcweir #endif // _SFX_FILEDLGIMPL_HXX
234