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 
24 
25 #ifndef _WINFILEOPENIMPL_HXX_
26 #define _WINFILEOPENIMPL_HXX_
27 
28 //------------------------------------------------------------------------
29 // includes
30 //------------------------------------------------------------------------
31 
32 #ifndef _COM_SUN_STAR_UI_DIALOGS_XEXTENDEDFILEPICKER_HPP_
33 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
34 #endif
35 #include <com/sun/star/ui/dialogs/FilePickerEvent.hpp>
36 #include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
37 #include "FilterContainer.hxx"
38 #include "FileOpenDlg.hxx"
39 #include "previewadapter.hxx"
40 #include "helppopupwindow.hxx"
41 #include "customcontrol.hxx"
42 #include "customcontrolfactory.hxx"
43 #include "..\misc\resourceprovider.hxx"
44 
45 #include <utility>
46 #include <memory>
47 #include <vector>
48 #include <osl/conditn.hxx>
49 
50 //------------------------------------------------------------------------
51 // deklarations
52 //------------------------------------------------------------------------
53 
54 // forward declaration
55 class CFilePicker;
56 class CFilePickerState;
57 class CExecuteFilePickerState;
58 class CNonExecuteFilePickerState;
59 
60 class CWinFileOpenImpl : public CFileOpenDialog
61 {
62 public:
63 	CWinFileOpenImpl(
64 		CFilePicker* aFilePicker,
65 		sal_Bool bFileOpenDialog = sal_True,
66 		sal_uInt32 dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
67 		sal_uInt32 dwTemplateId = 0,
68 		HINSTANCE hInstance = 0 );
69 
70 	virtual ~CWinFileOpenImpl( );
71 
72 	//-----------------------------------------------------------------------------------------
73 	// XExecutableDialog
74 	//-----------------------------------------------------------------------------------------
75 
76 	virtual sal_Int16 SAL_CALL execute(  ) throw( ::com::sun::star::uno::RuntimeException );
77 
78 	//-----------------------------------------------------------------------------------------
79 	// XFilePicker
80 	//-----------------------------------------------------------------------------------------
81 
82     virtual void SAL_CALL setDefaultName( const ::rtl::OUString& aName )
83 		throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
84 
85 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFiles(  )
86 		throw(::com::sun::star::uno::RuntimeException );
87 
88 	virtual void SAL_CALL setDisplayDirectory( const ::rtl::OUString& aDirectory )
89 		throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
90 
91 	virtual ::rtl::OUString SAL_CALL getDisplayDirectory( ) throw ( ::com::sun::star::uno::RuntimeException );
92 
93 	//-----------------------------------------------------------------------------------------
94 	// XFilterManager
95 	//-----------------------------------------------------------------------------------------
96 
97 	virtual void SAL_CALL appendFilter( const ::rtl::OUString& aTitle, const ::rtl::OUString& aFilter )
98 		throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
99 
100     virtual void SAL_CALL setCurrentFilter( const ::rtl::OUString& aTitle )
101 		throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
102 
103     virtual ::rtl::OUString  SAL_CALL getCurrentFilter( )
104 		throw( ::com::sun::star::uno::RuntimeException );
105 
106     //-----------------------------------------------------------------------------------------
107 	// XFilterGroupManager
108 	//-----------------------------------------------------------------------------------------
109 
110     virtual void SAL_CALL appendFilterGroup( const ::rtl::OUString& sGroupTitle, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aFilters )
111         throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
112 
113 	//-----------------------------------------------------------------------------------------
114 	// XFilePickerControlAccess
115 	//-----------------------------------------------------------------------------------------
116 
117 	virtual void SAL_CALL setValue( sal_Int16 aControlId, sal_Int16 aControlAction, const ::com::sun::star::uno::Any& aValue )
118 		throw( ::com::sun::star::uno::RuntimeException );
119 
120 	virtual ::com::sun::star::uno::Any SAL_CALL getValue( sal_Int16 aControlId, sal_Int16 aControlAction )
121 		throw( ::com::sun::star::uno::RuntimeException );
122 
123 	virtual void SAL_CALL enableControl( sal_Int16 aControlId, sal_Bool bEnable )
124 		throw( ::com::sun::star::uno::RuntimeException );
125 
126     virtual void SAL_CALL setLabel( sal_Int16 aControlId, const ::rtl::OUString& aLabel )
127 		throw (::com::sun::star::uno::RuntimeException);
128 
129     virtual ::rtl::OUString SAL_CALL getLabel( sal_Int16 aControlId )
130 		throw ( ::com::sun::star::uno::RuntimeException);
131 
132     //------------------------------------------------
133     // XFilePreview
134     //------------------------------------------------
135 
136     virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats(  )
137         throw (::com::sun::star::uno::RuntimeException);
138 
139     virtual sal_Int32 SAL_CALL getTargetColorDepth( )
140         throw (::com::sun::star::uno::RuntimeException);
141 
142     virtual sal_Int32 SAL_CALL getAvailableWidth( )
143         throw (::com::sun::star::uno::RuntimeException);
144 
145     virtual sal_Int32 SAL_CALL getAvailableHeight( )
146         throw (::com::sun::star::uno::RuntimeException);
147 
148     virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const ::com::sun::star::uno::Any& aImage )
149         throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
150 
151     virtual sal_Bool SAL_CALL setShowState( sal_Bool bShowState )
152         throw (::com::sun::star::uno::RuntimeException);
153 
154     virtual sal_Bool SAL_CALL getShowState( )
155         throw (::com::sun::star::uno::RuntimeException);
156 
157 	//------------------------------------------------
158     // XCancelable
159     //------------------------------------------------
160 
161     virtual void SAL_CALL cancel( );
162 
163 	//------------------------------------------------
164     // Implementation details
165     //------------------------------------------------
166 
167 protected:
168     sal_Int16 SAL_CALL getFocused( );
169 
170 	virtual bool SAL_CALL preModal( );
171 	virtual void SAL_CALL postModal( sal_Int16 nDialogResult );
172 
173 	virtual sal_uInt32 SAL_CALL onFileOk();
174 	virtual void SAL_CALL onSelChanged( HWND hwndListBox );
175 
176 	// only called back if OFN_EXPLORER is set
177 	virtual void SAL_CALL onInitDone();
178 	virtual void SAL_CALL onFolderChanged();
179 	virtual void SAL_CALL onTypeChanged( sal_uInt32 nFilterIndex );
180 
181 	// call base class method first when overloading
182 	virtual void SAL_CALL onInitDialog( HWND hwndDlg );
183 
184 	virtual sal_uInt32 SAL_CALL onCtrlCommand( HWND hwndDlg, sal_uInt16 ctrlId, sal_uInt16 notifyCode );
185 
186 
187 	void onWMSize();
188 	void onWMShow(sal_Bool bShow);
189 	void onWMWindowPosChanged();
190 	void onCustomControlHelpRequest(LPHELPINFO lphi);
191 
192 private:
193     inline void SAL_CALL appendFilterGroupSeparator( );
194 
195 	inline sal_Bool SAL_CALL IsCustomControlHelpRequested(LPHELPINFO lphi) const;
196 
197     void EnlargeStdControlLabels() const;
198 
199     // initialize all controls from cache
200     void SAL_CALL InitControlLabel( HWND hWnd );
201 	void SAL_CALL InitCustomControlContainer(HWND hCustomControl);
202 
203     // save the control state
204     void SAL_CALL CacheControlState(HWND hWnd);
205 
206     void SAL_CALL SetDefaultExtension();
207     void SAL_CALL InitialSetDefaultName();
208 
209 	static LRESULT CALLBACK SubClassFunc(HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam);
210 
211 	static BOOL CALLBACK EnumChildWndProc( HWND hWnd, LPARAM lParam );
212 
213 private:
214 	std::auto_ptr<CFilterContainer>			m_filterContainer;
215     std::auto_ptr<CPreviewAdapter>	   		m_Preview;
216 	std::auto_ptr<CCustomControlFactory>	m_CustomControlFactory;
217 	std::auto_ptr<CCustomControl>			m_CustomControls;
218 	CFilePicker*							m_FilePicker;
219 	WNDPROC									m_pfnOldDlgProc;
220     rtl::OUString							m_defaultName;
221     sal_Bool								m_bInitialSelChanged;
222     CHelpPopupWindow						m_HelpPopupWindow;
223     CFilePickerState*						m_FilePickerState;
224     CExecuteFilePickerState*				m_ExecuteFilePickerState;
225     CNonExecuteFilePickerState*				m_NonExecuteFilePickerState;
226     CResourceProvider						m_ResProvider;
227 };
228 
229 
230 #endif
231