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