merge the formfield patch from ooo-build
[ooovba.git] / fpicker / source / win32 / folderpicker / MtaFop.hxx
blob1246d080ce3853182486f8f7b7c1abba14156a14
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MtaFop.hxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _MTAFOP_HXX_
32 #define _MTAFOP_HXX_
34 #include <sal/types.h>
35 #include <rtl/ustring.hxx>
36 #include <osl/mutex.hxx>
38 #include <utility>
39 #ifdef __MINGW32__
40 #include <windows.h>
41 #endif
42 #if defined _MSC_VER
43 #pragma warning(push, 1)
44 #pragma warning(disable: 4917)
45 #endif
46 #include <objidl.h>
47 #include <shlobj.h>
48 #if defined _MSC_VER
49 #pragma warning(pop)
50 #endif
51 #include "..\misc\WinImplHelper.hxx"
53 //----------------------------------------------------------------
54 // a simple helper class used to provide a buffer for different
55 // Win32 file and directory functions
56 //----------------------------------------------------------------
58 class CAutoPathBuff
60 public:
61 CAutoPathBuff( size_t size = 0 )
63 if (0 == size)
64 size = 32000; // max path length under Win2000
66 pBuff = new sal_Unicode[size];
68 OSL_POSTCOND(pBuff,"Could not allocate path buffer");
71 ~CAutoPathBuff( )
73 delete [] pBuff;
76 operator sal_Unicode*( )
78 OSL_PRECOND( pBuff, \
79 "No path buffer allocated" );
80 return pBuff;
83 sal_Unicode* get( )
85 OSL_PRECOND( pBuff, \
86 "No path buffer allocated" );
87 return pBuff;
90 private:
91 sal_Unicode* pBuff;
94 //--------------------------------------------------------
95 // the Mta-Ole clipboard class is for internal use only!
96 // only one instance of this class should be created, the
97 // user has to ensure this!
98 // the class is not thread-safe because it will be used
99 // only from within the clipboard service and the methods
100 // of the clipboard service are already synchronized
101 //--------------------------------------------------------
103 class CMtaFolderPicker
105 public:
106 CMtaFolderPicker( sal_uInt32 Flags );
107 virtual ~CMtaFolderPicker( );
109 // shell functions
110 sal_Bool SAL_CALL browseForFolder( );
112 virtual void SAL_CALL setDisplayDirectory( const rtl::OUString& aDirectory );
113 virtual rtl::OUString SAL_CALL getDisplayDirectory( );
114 virtual rtl::OUString SAL_CALL getDirectory( );
116 virtual void SAL_CALL setDescription( const rtl::OUString& aDescription );
118 virtual void SAL_CALL setTitle( const rtl::OUString& aTitle );
119 rtl::OUString SAL_CALL getTitle( );
121 //-----------------------------------------------------
122 // XCancellable
123 //-----------------------------------------------------
125 virtual void SAL_CALL cancel( );
127 protected:
128 void SAL_CALL enableOk( sal_Bool bEnable );
129 void SAL_CALL setSelection( const rtl::OUString& aDirectory );
130 void SAL_CALL setStatusText( const rtl::OUString& aStatusText );
132 virtual void SAL_CALL onInitialized( );
133 virtual void SAL_CALL onSelChanged( const rtl::OUString& aNewPath ) = 0;
135 private:
136 sal_uInt32 onValidateFailed();
138 // helper functions
139 LPITEMIDLIST SAL_CALL getItemIdListFromPath( const rtl::OUString& aDirectory );
140 rtl::OUString SAL_CALL getPathFromItemIdList( LPCITEMIDLIST lpItemIdList );
141 void SAL_CALL releaseItemIdList( LPITEMIDLIST lpItemIdList );
143 unsigned int run( );
145 // create a hidden windows which serves as an request
146 // target; so we guarantee synchronization
147 sal_Bool SAL_CALL createStaRequestWindow( );
149 //---------------------------------------------------------------
150 // message handler functions; remeber these functions are called
151 // from a different thread context!
152 //---------------------------------------------------------------
154 sal_Bool SAL_CALL onBrowseForFolder( );
156 static LRESULT CALLBACK StaWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
157 static unsigned int WINAPI StaThreadProc( LPVOID pParam );
159 static int CALLBACK FolderPickerCallback( HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData );
161 protected:
162 HWND m_hwnd;
164 private:
165 ATOM SAL_CALL RegisterStaRequestWindowClass( );
166 void SAL_CALL UnregisterStaRequestWindowClass( );
168 private:
169 HANDLE m_hStaThread;
170 unsigned m_uStaThreadId;
171 HANDLE m_hEvtThrdReady;
172 HWND m_hwndStaRequestWnd;
173 rtl::OUString m_dialogTitle;
174 rtl::OUString m_Description;
175 rtl::OUString m_displayDir;
176 rtl::OUString m_SelectedDir;
177 BROWSEINFOW m_bi;
178 CAutoPathBuff m_pathBuff;
179 HINSTANCE m_hInstance;
181 // the request window class has to be registered only
182 // once per process, so multiple instance of this class
183 // share the registered window class
184 static ATOM s_ClassAtom;
185 static osl::Mutex s_Mutex;
186 static sal_Int32 s_StaRequestWndRegisterCount;
188 // prevent copy and assignment
189 private:
190 CMtaFolderPicker( const CMtaFolderPicker& );
191 CMtaFolderPicker& operator=( const CMtaFolderPicker& );
194 #endif