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