110ce8018SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 310ce8018SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 410ce8018SAndrew Rist * or more contributor license agreements. See the NOTICE file 510ce8018SAndrew Rist * distributed with this work for additional information 610ce8018SAndrew Rist * regarding copyright ownership. The ASF licenses this file 710ce8018SAndrew Rist * to you under the Apache License, Version 2.0 (the 810ce8018SAndrew Rist * "License"); you may not use this file except in compliance 910ce8018SAndrew Rist * with the License. You may obtain a copy of the License at 1010ce8018SAndrew Rist * 1110ce8018SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1210ce8018SAndrew Rist * 1310ce8018SAndrew Rist * Unless required by applicable law or agreed to in writing, 1410ce8018SAndrew Rist * software distributed under the License is distributed on an 1510ce8018SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1610ce8018SAndrew Rist * KIND, either express or implied. See the License for the 1710ce8018SAndrew Rist * specific language governing permissions and limitations 1810ce8018SAndrew Rist * under the License. 1910ce8018SAndrew Rist * 2010ce8018SAndrew Rist *************************************************************/ 2110ce8018SAndrew Rist 2210ce8018SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _MTAFOP_HXX_ 25cdf0e10cSrcweir #define _MTAFOP_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <sal/types.h> 28cdf0e10cSrcweir #include <rtl/ustring.hxx> 29cdf0e10cSrcweir #include <osl/mutex.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <utility> 32cdf0e10cSrcweir #ifdef __MINGW32__ 33cdf0e10cSrcweir #include <windows.h> 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir #if defined _MSC_VER 36cdf0e10cSrcweir #pragma warning(push, 1) 37cdf0e10cSrcweir #pragma warning(disable: 4917) 38cdf0e10cSrcweir #endif 39cdf0e10cSrcweir #include <objidl.h> 40cdf0e10cSrcweir #include <shlobj.h> 41cdf0e10cSrcweir #if defined _MSC_VER 42cdf0e10cSrcweir #pragma warning(pop) 43cdf0e10cSrcweir #endif 44cdf0e10cSrcweir #include "..\misc\WinImplHelper.hxx" 45cdf0e10cSrcweir 46cdf0e10cSrcweir //---------------------------------------------------------------- 47cdf0e10cSrcweir // a simple helper class used to provide a buffer for different 48cdf0e10cSrcweir // Win32 file and directory functions 49cdf0e10cSrcweir //---------------------------------------------------------------- 50cdf0e10cSrcweir 51cdf0e10cSrcweir class CAutoPathBuff 52cdf0e10cSrcweir { 53cdf0e10cSrcweir public: CAutoPathBuff(size_t size=0)54cdf0e10cSrcweir CAutoPathBuff( size_t size = 0 ) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir if (0 == size) 57cdf0e10cSrcweir size = 32000; // max path length under Win2000 58cdf0e10cSrcweir 59cdf0e10cSrcweir pBuff = new sal_Unicode[size]; 60cdf0e10cSrcweir 61cdf0e10cSrcweir OSL_POSTCOND(pBuff,"Could not allocate path buffer"); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir ~CAutoPathBuff()64cdf0e10cSrcweir ~CAutoPathBuff( ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir delete [] pBuff; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir operator sal_Unicode*()69cdf0e10cSrcweir operator sal_Unicode*( ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir OSL_PRECOND( pBuff, \ 72cdf0e10cSrcweir "No path buffer allocated" ); 73cdf0e10cSrcweir return pBuff; 74cdf0e10cSrcweir } 75cdf0e10cSrcweir get()76cdf0e10cSrcweir sal_Unicode* get( ) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir OSL_PRECOND( pBuff, \ 79cdf0e10cSrcweir "No path buffer allocated" ); 80cdf0e10cSrcweir return pBuff; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir private: 84cdf0e10cSrcweir sal_Unicode* pBuff; 85cdf0e10cSrcweir }; 86cdf0e10cSrcweir 87cdf0e10cSrcweir //-------------------------------------------------------- 88cdf0e10cSrcweir // the Mta-Ole clipboard class is for internal use only! 89cdf0e10cSrcweir // only one instance of this class should be created, the 90cdf0e10cSrcweir // user has to ensure this! 91cdf0e10cSrcweir // the class is not thread-safe because it will be used 92cdf0e10cSrcweir // only from within the clipboard service and the methods 93cdf0e10cSrcweir // of the clipboard service are already synchronized 94cdf0e10cSrcweir //-------------------------------------------------------- 95cdf0e10cSrcweir 96cdf0e10cSrcweir class CMtaFolderPicker 97cdf0e10cSrcweir { 98cdf0e10cSrcweir public: 99cdf0e10cSrcweir CMtaFolderPicker( sal_uInt32 Flags ); 100cdf0e10cSrcweir virtual ~CMtaFolderPicker( ); 101cdf0e10cSrcweir 102cdf0e10cSrcweir // shell functions 103cdf0e10cSrcweir sal_Bool SAL_CALL browseForFolder( ); 104cdf0e10cSrcweir 105cdf0e10cSrcweir virtual void SAL_CALL setDisplayDirectory( const rtl::OUString& aDirectory ); 106cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getDisplayDirectory( ); 107cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getDirectory( ); 108cdf0e10cSrcweir 109cdf0e10cSrcweir virtual void SAL_CALL setDescription( const rtl::OUString& aDescription ); 110cdf0e10cSrcweir 111cdf0e10cSrcweir virtual void SAL_CALL setTitle( const rtl::OUString& aTitle ); 112cdf0e10cSrcweir rtl::OUString SAL_CALL getTitle( ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir //----------------------------------------------------- 115cdf0e10cSrcweir // XCancellable 116cdf0e10cSrcweir //----------------------------------------------------- 117cdf0e10cSrcweir 118cdf0e10cSrcweir virtual void SAL_CALL cancel( ); 119cdf0e10cSrcweir 120cdf0e10cSrcweir protected: 121cdf0e10cSrcweir void SAL_CALL enableOk( sal_Bool bEnable ); 122cdf0e10cSrcweir void SAL_CALL setSelection( const rtl::OUString& aDirectory ); 123cdf0e10cSrcweir void SAL_CALL setStatusText( const rtl::OUString& aStatusText ); 124cdf0e10cSrcweir 125cdf0e10cSrcweir virtual void SAL_CALL onInitialized( ); 126cdf0e10cSrcweir virtual void SAL_CALL onSelChanged( const rtl::OUString& aNewPath ) = 0; 127cdf0e10cSrcweir 128cdf0e10cSrcweir private: 129cdf0e10cSrcweir sal_uInt32 onValidateFailed(); 130cdf0e10cSrcweir 131cdf0e10cSrcweir // helper functions 132cdf0e10cSrcweir LPITEMIDLIST SAL_CALL getItemIdListFromPath( const rtl::OUString& aDirectory ); 133cdf0e10cSrcweir rtl::OUString SAL_CALL getPathFromItemIdList( LPCITEMIDLIST lpItemIdList ); 134cdf0e10cSrcweir void SAL_CALL releaseItemIdList( LPITEMIDLIST lpItemIdList ); 135cdf0e10cSrcweir 136cdf0e10cSrcweir unsigned int run( ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir // create a hidden windows which serves as an request 139cdf0e10cSrcweir // target; so we guarantee synchronization 140cdf0e10cSrcweir sal_Bool SAL_CALL createStaRequestWindow( ); 141cdf0e10cSrcweir 142cdf0e10cSrcweir //--------------------------------------------------------------- 143*07a3d7f1SPedro Giffuni // message handler functions; remember these functions are called 144cdf0e10cSrcweir // from a different thread context! 145cdf0e10cSrcweir //--------------------------------------------------------------- 146cdf0e10cSrcweir 147cdf0e10cSrcweir sal_Bool SAL_CALL onBrowseForFolder( ); 148cdf0e10cSrcweir 149cdf0e10cSrcweir static LRESULT CALLBACK StaWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 150cdf0e10cSrcweir static unsigned int WINAPI StaThreadProc( LPVOID pParam ); 151cdf0e10cSrcweir 152cdf0e10cSrcweir static int CALLBACK FolderPickerCallback( HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData ); 153cdf0e10cSrcweir 154cdf0e10cSrcweir protected: 155cdf0e10cSrcweir HWND m_hwnd; 156cdf0e10cSrcweir 157cdf0e10cSrcweir private: 158cdf0e10cSrcweir ATOM SAL_CALL RegisterStaRequestWindowClass( ); 159cdf0e10cSrcweir void SAL_CALL UnregisterStaRequestWindowClass( ); 160cdf0e10cSrcweir 161cdf0e10cSrcweir private: 162cdf0e10cSrcweir HANDLE m_hStaThread; 163cdf0e10cSrcweir unsigned m_uStaThreadId; 164cdf0e10cSrcweir HANDLE m_hEvtThrdReady; 165cdf0e10cSrcweir HWND m_hwndStaRequestWnd; 166cdf0e10cSrcweir rtl::OUString m_dialogTitle; 167cdf0e10cSrcweir rtl::OUString m_Description; 168cdf0e10cSrcweir rtl::OUString m_displayDir; 169cdf0e10cSrcweir rtl::OUString m_SelectedDir; 170cdf0e10cSrcweir BROWSEINFOW m_bi; 171cdf0e10cSrcweir CAutoPathBuff m_pathBuff; 172cdf0e10cSrcweir HINSTANCE m_hInstance; 173cdf0e10cSrcweir 174cdf0e10cSrcweir // the request window class has to be registered only 175cdf0e10cSrcweir // once per process, so multiple instance of this class 176cdf0e10cSrcweir // share the registered window class 177cdf0e10cSrcweir static ATOM s_ClassAtom; 178cdf0e10cSrcweir static osl::Mutex s_Mutex; 179cdf0e10cSrcweir static sal_Int32 s_StaRequestWndRegisterCount; 180cdf0e10cSrcweir 181cdf0e10cSrcweir // prevent copy and assignment 182cdf0e10cSrcweir private: 183cdf0e10cSrcweir CMtaFolderPicker( const CMtaFolderPicker& ); 184cdf0e10cSrcweir CMtaFolderPicker& operator=( const CMtaFolderPicker& ); 185cdf0e10cSrcweir }; 186cdf0e10cSrcweir 187cdf0e10cSrcweir #endif 188