1*10ce8018SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*10ce8018SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*10ce8018SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*10ce8018SAndrew Rist  * distributed with this work for additional information
6*10ce8018SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*10ce8018SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*10ce8018SAndrew Rist  * "License"); you may not use this file except in compliance
9*10ce8018SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*10ce8018SAndrew Rist  *
11*10ce8018SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*10ce8018SAndrew Rist  *
13*10ce8018SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*10ce8018SAndrew Rist  * software distributed under the License is distributed on an
15*10ce8018SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*10ce8018SAndrew Rist  * KIND, either express or implied.  See the License for the
17*10ce8018SAndrew Rist  * specific language governing permissions and limitations
18*10ce8018SAndrew Rist  * under the License.
19*10ce8018SAndrew Rist  *
20*10ce8018SAndrew Rist  *************************************************************/
21*10ce8018SAndrew Rist 
22*10ce8018SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef FPICKER_WIN32_VISTA_FILEPICKER_EVENTHANDLER_HXX
25cdf0e10cSrcweir #define FPICKER_WIN32_VISTA_FILEPICKER_EVENTHANDLER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //-----------------------------------------------------------------------------
28cdf0e10cSrcweir // includes
29cdf0e10cSrcweir //-----------------------------------------------------------------------------
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #if defined(_MSC_VER) && (_MSC_VER >= 1400)
32cdf0e10cSrcweir #pragma warning( disable : 4917 )
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "comptr.hxx"
36cdf0e10cSrcweir #include "vistatypes.h"
37cdf0e10cSrcweir #include "IVistaFilePickerInternalNotify.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
40cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx>
43cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.h>
44cdf0e10cSrcweir #include <osl/interlck.h>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <shobjidl.h>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //-----------------------------------------------------------------------------
49cdf0e10cSrcweir // namespace
50cdf0e10cSrcweir //-----------------------------------------------------------------------------
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #ifdef css
53cdf0e10cSrcweir     #error "Clash on using CSS as namespace define."
54cdf0e10cSrcweir #else
55cdf0e10cSrcweir     #define css ::com::sun::star
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir 
58cdf0e10cSrcweir namespace fpicker{
59cdf0e10cSrcweir namespace win32{
60cdf0e10cSrcweir namespace vista{
61cdf0e10cSrcweir 
62cdf0e10cSrcweir //-----------------------------------------------------------------------------
63cdf0e10cSrcweir // types, const etcpp.
64cdf0e10cSrcweir //-----------------------------------------------------------------------------
65cdf0e10cSrcweir 
66cdf0e10cSrcweir //-----------------------------------------------------------------------------
67cdf0e10cSrcweir /** todo document me
68cdf0e10cSrcweir  */
69cdf0e10cSrcweir class VistaFilePickerEventHandler : public ::cppu::BaseMutex
70cdf0e10cSrcweir                                   , public IFileDialogEvents
71cdf0e10cSrcweir                                   , public IFileDialogControlEvents
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     public:
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         //------------------------------------------------------------------------------------
76cdf0e10cSrcweir         // ctor/dtor
77cdf0e10cSrcweir         //------------------------------------------------------------------------------------
78cdf0e10cSrcweir 
79cdf0e10cSrcweir                  VistaFilePickerEventHandler(IVistaFilePickerInternalNotify* pInternalNotify);
80cdf0e10cSrcweir         virtual ~VistaFilePickerEventHandler();
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         //------------------------------------------------------------------------------------
83cdf0e10cSrcweir         // IUnknown
84cdf0e10cSrcweir         //------------------------------------------------------------------------------------
85cdf0e10cSrcweir         virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID rIID    ,
86cdf0e10cSrcweir                                                          void** ppObject);
87cdf0e10cSrcweir         virtual ULONG STDMETHODCALLTYPE AddRef();
88cdf0e10cSrcweir         virtual ULONG STDMETHODCALLTYPE Release();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         //------------------------------------------------------------------------------------
91cdf0e10cSrcweir         // IFileDialogEvents
92cdf0e10cSrcweir         //------------------------------------------------------------------------------------
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         STDMETHODIMP OnFileOk(IFileDialog* pDialog);
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         STDMETHODIMP OnFolderChanging(IFileDialog* pDialog,
97cdf0e10cSrcweir                                       IShellItem*  pFolder);
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         STDMETHODIMP OnFolderChange(IFileDialog* pDialog);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         STDMETHODIMP OnSelectionChange(IFileDialog* pDialog);
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         STDMETHODIMP OnShareViolation(IFileDialog*                 pDialog  ,
104cdf0e10cSrcweir                                       IShellItem*                  pItem    ,
105cdf0e10cSrcweir                                       FDE_SHAREVIOLATION_RESPONSE* pResponse);
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         STDMETHODIMP OnTypeChange(IFileDialog* pDialog);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         STDMETHODIMP OnOverwrite(IFileDialog*            pDialog  ,
110cdf0e10cSrcweir                                  IShellItem*             pItem    ,
111cdf0e10cSrcweir                                  FDE_OVERWRITE_RESPONSE* pResponse);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         //------------------------------------------------------------------------------------
114cdf0e10cSrcweir         // IFileDialogControlEvents
115cdf0e10cSrcweir         //------------------------------------------------------------------------------------
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         STDMETHODIMP OnItemSelected(IFileDialogCustomize* pCustomize,
118cdf0e10cSrcweir                                     DWORD                 nIDCtl    ,
119cdf0e10cSrcweir                                     DWORD                 nIDItem   );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         STDMETHODIMP OnButtonClicked(IFileDialogCustomize* pCustomize,
122cdf0e10cSrcweir                                      DWORD                 nIDCtl    );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         STDMETHODIMP OnCheckButtonToggled(IFileDialogCustomize* pCustomize,
125cdf0e10cSrcweir                                           DWORD                 nIDCtl    ,
126cdf0e10cSrcweir                                           BOOL                  bChecked  );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         STDMETHODIMP OnControlActivating(IFileDialogCustomize* pCustomize,
129cdf0e10cSrcweir                                          DWORD                 nIDCtl    );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         //------------------------------------------------------------------------------------
132cdf0e10cSrcweir         // XFilePickerNotifier
133cdf0e10cSrcweir         //------------------------------------------------------------------------------------
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         virtual void SAL_CALL addFilePickerListener( const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener )
136cdf0e10cSrcweir             throw( css::uno::RuntimeException );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         virtual void SAL_CALL removeFilePickerListener( const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener )
139cdf0e10cSrcweir             throw( css::uno::RuntimeException );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         //------------------------------------------------------------------------------------
142cdf0e10cSrcweir         // native interface
143cdf0e10cSrcweir         //------------------------------------------------------------------------------------
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         //------------------------------------------------------------------------------------
146cdf0e10cSrcweir         /** start listening for file picker events on the given file open dialog COM object.
147cdf0e10cSrcweir          *
148cdf0e10cSrcweir          *  The broadcaster will be cached internaly so deregistration will be easy.
149cdf0e10cSrcweir          *  Further all needed informations are capsulated within this class (e.g. the listener handler).
150cdf0e10cSrcweir          *  Nobody outside must know such informations.
151cdf0e10cSrcweir          *
152cdf0e10cSrcweir          *  Nothing will happen if an inconsistent state will be detected
153cdf0e10cSrcweir          *  (means: double registration will be ignored).
154cdf0e10cSrcweir          *
155cdf0e10cSrcweir          *  @param  pBroadcaster
156cdf0e10cSrcweir          *          reference to the dialog, where we should start listening.
157cdf0e10cSrcweir          */
158cdf0e10cSrcweir         void startListening( const TFileDialog& pBroadcaster );
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         //------------------------------------------------------------------------------------
161cdf0e10cSrcweir         /** stop listening for file picker events on the internaly cached dialog COM object.
162cdf0e10cSrcweir          *
163cdf0e10cSrcweir          *  The  COM dialog provided on the startListeneing() call was cached internaly.
164cdf0e10cSrcweir          *  And now its used to deregister this listener. Doing so the also internaly cached
165cdf0e10cSrcweir          *  listener handle is used. If listener was not already registered - nothing will happen.
166cdf0e10cSrcweir          */
167cdf0e10cSrcweir         void stopListening();
168cdf0e10cSrcweir 
169cdf0e10cSrcweir     public:
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         enum EEventType
172cdf0e10cSrcweir         {
173cdf0e10cSrcweir             E_FILE_SELECTION_CHANGED,
174cdf0e10cSrcweir             E_DIRECTORY_CHANGED,
175cdf0e10cSrcweir             E_HELP_REQUESTED,
176cdf0e10cSrcweir             E_CONTROL_STATE_CHANGED,
177cdf0e10cSrcweir             E_DIALOG_SIZE_CHANGED
178cdf0e10cSrcweir         };
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     private:
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         //------------------------------------------------------------------------------------
183cdf0e10cSrcweir         /// @todo document me
184cdf0e10cSrcweir         void impl_sendEvent(  EEventType eEventType,
185cdf0e10cSrcweir                             ::sal_Int16  nControlID);
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     private:
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         //------------------------------------------------------------------------------------
190cdf0e10cSrcweir         /// ref count for AddRef/Release()
191cdf0e10cSrcweir         oslInterlockedCount m_nRefCount;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         //------------------------------------------------------------------------------------
194cdf0e10cSrcweir         /// unique handle for this listener provided by the broadcaster on registration time
195cdf0e10cSrcweir         DWORD m_nListenerHandle;
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         //------------------------------------------------------------------------------------
198cdf0e10cSrcweir         /// cached file dialog instance (there we listen for events)
199cdf0e10cSrcweir         TFileDialog m_pDialog;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         //---------------------------------------------------------------------
202cdf0e10cSrcweir         IVistaFilePickerInternalNotify* m_pInternalNotify;
203cdf0e10cSrcweir 
204cdf0e10cSrcweir         //---------------------------------------------------------------------
205cdf0e10cSrcweir         /** used to inform file picker listener asynchronously.
206cdf0e10cSrcweir          *  Those listener must be called asynchronously .. because
207cdf0e10cSrcweir          *  every request will block the caller thread. Mostly that will be
208cdf0e10cSrcweir          *  the main thread of the office. Further the global SolarMutex will
209cdf0e10cSrcweir          *  be locked during this time. If we call our listener back now synchronously ..
210cdf0e10cSrcweir          *  we will block on SolarMutex.acquire() forever .-))
211cdf0e10cSrcweir          */
212cdf0e10cSrcweir         ::cppu::OMultiTypeInterfaceContainerHelper m_lListener;
213cdf0e10cSrcweir };
214cdf0e10cSrcweir 
215cdf0e10cSrcweir } // namespace vista
216cdf0e10cSrcweir } // namespace win32
217cdf0e10cSrcweir } // namespace fpicker
218cdf0e10cSrcweir 
219cdf0e10cSrcweir #undef css
220cdf0e10cSrcweir 
221cdf0e10cSrcweir #endif  // FPICKER_WIN32_VISTA_FILEPICKER_EVENTHANDLER_HXX
222