1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MtaFop.hxx,v $
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 ************************************************************************/
34 #include <sal/types.h>
35 #include <rtl/ustring.hxx>
36 #include <osl/mutex.hxx>
43 #pragma warning(push, 1)
44 #pragma warning(disable: 4917)
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 //----------------------------------------------------------------
61 CAutoPathBuff( size_t size
= 0 )
64 size
= 32000; // max path length under Win2000
66 pBuff
= new sal_Unicode
[size
];
68 OSL_POSTCOND(pBuff
,"Could not allocate path buffer");
76 operator sal_Unicode
*( )
79 "No path buffer allocated" );
86 "No path buffer allocated" );
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
106 CMtaFolderPicker( sal_uInt32 Flags
);
107 virtual ~CMtaFolderPicker( );
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 //-----------------------------------------------------
123 //-----------------------------------------------------
125 virtual void SAL_CALL
cancel( );
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;
136 sal_uInt32
onValidateFailed();
139 LPITEMIDLIST SAL_CALL
getItemIdListFromPath( const rtl::OUString
& aDirectory
);
140 rtl::OUString SAL_CALL
getPathFromItemIdList( LPCITEMIDLIST lpItemIdList
);
141 void SAL_CALL
releaseItemIdList( LPITEMIDLIST lpItemIdList
);
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
);
165 ATOM SAL_CALL
RegisterStaRequestWindowClass( );
166 void SAL_CALL
UnregisterStaRequestWindowClass( );
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
;
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
190 CMtaFolderPicker( const CMtaFolderPicker
& );
191 CMtaFolderPicker
& operator=( const CMtaFolderPicker
& );