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