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 28*cdf0e10cSrcweir #ifndef _MTAFOP_HXX_ 29*cdf0e10cSrcweir #define _MTAFOP_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <sal/types.h> 32*cdf0e10cSrcweir #include <rtl/ustring.hxx> 33*cdf0e10cSrcweir #include <osl/mutex.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <utility> 36*cdf0e10cSrcweir #ifdef __MINGW32__ 37*cdf0e10cSrcweir #include <windows.h> 38*cdf0e10cSrcweir #endif 39*cdf0e10cSrcweir #if defined _MSC_VER 40*cdf0e10cSrcweir #pragma warning(push, 1) 41*cdf0e10cSrcweir #pragma warning(disable: 4917) 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #include <objidl.h> 44*cdf0e10cSrcweir #include <shlobj.h> 45*cdf0e10cSrcweir #if defined _MSC_VER 46*cdf0e10cSrcweir #pragma warning(pop) 47*cdf0e10cSrcweir #endif 48*cdf0e10cSrcweir #include "..\misc\WinImplHelper.hxx" 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //---------------------------------------------------------------- 51*cdf0e10cSrcweir // a simple helper class used to provide a buffer for different 52*cdf0e10cSrcweir // Win32 file and directory functions 53*cdf0e10cSrcweir //---------------------------------------------------------------- 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir class CAutoPathBuff 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir public: 58*cdf0e10cSrcweir CAutoPathBuff( size_t size = 0 ) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir if (0 == size) 61*cdf0e10cSrcweir size = 32000; // max path length under Win2000 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir pBuff = new sal_Unicode[size]; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir OSL_POSTCOND(pBuff,"Could not allocate path buffer"); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir ~CAutoPathBuff( ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir delete [] pBuff; 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir operator sal_Unicode*( ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir OSL_PRECOND( pBuff, \ 76*cdf0e10cSrcweir "No path buffer allocated" ); 77*cdf0e10cSrcweir return pBuff; 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir sal_Unicode* get( ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir OSL_PRECOND( pBuff, \ 83*cdf0e10cSrcweir "No path buffer allocated" ); 84*cdf0e10cSrcweir return pBuff; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir private: 88*cdf0e10cSrcweir sal_Unicode* pBuff; 89*cdf0e10cSrcweir }; 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //-------------------------------------------------------- 92*cdf0e10cSrcweir // the Mta-Ole clipboard class is for internal use only! 93*cdf0e10cSrcweir // only one instance of this class should be created, the 94*cdf0e10cSrcweir // user has to ensure this! 95*cdf0e10cSrcweir // the class is not thread-safe because it will be used 96*cdf0e10cSrcweir // only from within the clipboard service and the methods 97*cdf0e10cSrcweir // of the clipboard service are already synchronized 98*cdf0e10cSrcweir //-------------------------------------------------------- 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir class CMtaFolderPicker 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir public: 103*cdf0e10cSrcweir CMtaFolderPicker( sal_uInt32 Flags ); 104*cdf0e10cSrcweir virtual ~CMtaFolderPicker( ); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir // shell functions 107*cdf0e10cSrcweir sal_Bool SAL_CALL browseForFolder( ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir virtual void SAL_CALL setDisplayDirectory( const rtl::OUString& aDirectory ); 110*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getDisplayDirectory( ); 111*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getDirectory( ); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir virtual void SAL_CALL setDescription( const rtl::OUString& aDescription ); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir virtual void SAL_CALL setTitle( const rtl::OUString& aTitle ); 116*cdf0e10cSrcweir rtl::OUString SAL_CALL getTitle( ); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir //----------------------------------------------------- 119*cdf0e10cSrcweir // XCancellable 120*cdf0e10cSrcweir //----------------------------------------------------- 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir virtual void SAL_CALL cancel( ); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir protected: 125*cdf0e10cSrcweir void SAL_CALL enableOk( sal_Bool bEnable ); 126*cdf0e10cSrcweir void SAL_CALL setSelection( const rtl::OUString& aDirectory ); 127*cdf0e10cSrcweir void SAL_CALL setStatusText( const rtl::OUString& aStatusText ); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir virtual void SAL_CALL onInitialized( ); 130*cdf0e10cSrcweir virtual void SAL_CALL onSelChanged( const rtl::OUString& aNewPath ) = 0; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir private: 133*cdf0e10cSrcweir sal_uInt32 onValidateFailed(); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // helper functions 136*cdf0e10cSrcweir LPITEMIDLIST SAL_CALL getItemIdListFromPath( const rtl::OUString& aDirectory ); 137*cdf0e10cSrcweir rtl::OUString SAL_CALL getPathFromItemIdList( LPCITEMIDLIST lpItemIdList ); 138*cdf0e10cSrcweir void SAL_CALL releaseItemIdList( LPITEMIDLIST lpItemIdList ); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir unsigned int run( ); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir // create a hidden windows which serves as an request 143*cdf0e10cSrcweir // target; so we guarantee synchronization 144*cdf0e10cSrcweir sal_Bool SAL_CALL createStaRequestWindow( ); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir //--------------------------------------------------------------- 147*cdf0e10cSrcweir // message handler functions; remeber these functions are called 148*cdf0e10cSrcweir // from a different thread context! 149*cdf0e10cSrcweir //--------------------------------------------------------------- 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir sal_Bool SAL_CALL onBrowseForFolder( ); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir static LRESULT CALLBACK StaWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 154*cdf0e10cSrcweir static unsigned int WINAPI StaThreadProc( LPVOID pParam ); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir static int CALLBACK FolderPickerCallback( HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData ); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir protected: 159*cdf0e10cSrcweir HWND m_hwnd; 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir private: 162*cdf0e10cSrcweir ATOM SAL_CALL RegisterStaRequestWindowClass( ); 163*cdf0e10cSrcweir void SAL_CALL UnregisterStaRequestWindowClass( ); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir private: 166*cdf0e10cSrcweir HANDLE m_hStaThread; 167*cdf0e10cSrcweir unsigned m_uStaThreadId; 168*cdf0e10cSrcweir HANDLE m_hEvtThrdReady; 169*cdf0e10cSrcweir HWND m_hwndStaRequestWnd; 170*cdf0e10cSrcweir rtl::OUString m_dialogTitle; 171*cdf0e10cSrcweir rtl::OUString m_Description; 172*cdf0e10cSrcweir rtl::OUString m_displayDir; 173*cdf0e10cSrcweir rtl::OUString m_SelectedDir; 174*cdf0e10cSrcweir BROWSEINFOW m_bi; 175*cdf0e10cSrcweir CAutoPathBuff m_pathBuff; 176*cdf0e10cSrcweir HINSTANCE m_hInstance; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // the request window class has to be registered only 179*cdf0e10cSrcweir // once per process, so multiple instance of this class 180*cdf0e10cSrcweir // share the registered window class 181*cdf0e10cSrcweir static ATOM s_ClassAtom; 182*cdf0e10cSrcweir static osl::Mutex s_Mutex; 183*cdf0e10cSrcweir static sal_Int32 s_StaRequestWndRegisterCount; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir // prevent copy and assignment 186*cdf0e10cSrcweir private: 187*cdf0e10cSrcweir CMtaFolderPicker( const CMtaFolderPicker& ); 188*cdf0e10cSrcweir CMtaFolderPicker& operator=( const CMtaFolderPicker& ); 189*cdf0e10cSrcweir }; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir #endif 192