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 __TBUNOSEARCHCONTROLLERS_HXX_
25 #define __TBUNOSEARCHCONTROLLERS_HXX_
26 
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <com/sun/star/frame/DispatchDescriptor.hpp>
29 #include <com/sun/star/frame/XDispatch.hpp>
30 #include <com/sun/star/frame/XDispatchHelper.hpp>
31 #include <com/sun/star/frame/XDispatchProvider.hpp>
32 #include <com/sun/star/frame/XStatusListener.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/lang/XInitialization.hpp>
35 
36 #include <comphelper/sequenceasvector.hxx>
37 #include <cppuhelper/implbase1.hxx>
38 #include <cppuhelper/weak.hxx>
39 #include <svtools/toolboxcontroller.hxx>
40 #include <vcl/combobox.hxx>
41 #include <vcl/window.hxx>
42 
43 #include <map>
44 
45 namespace css = ::com::sun::star        ;
46 namespace svx
47 {
48 
49 class FindTextFieldControl : public ComboBox
50 {
51 public:
52     FindTextFieldControl( Window* pParent, WinBits nStyle,
53         css::uno::Reference< css::frame::XFrame >& xFrame,
54         css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager );
55     virtual ~FindTextFieldControl();
56 
57     virtual void Modify();
58     virtual long PreNotify( NotifyEvent& rNEvt );
59 
60     void InitControls_Impl();
61     void Remember_Impl(const String& rStr);
62 
63 private:
64 
65     css::uno::Reference< css::frame::XFrame > m_xFrame;
66     css::uno::Reference< css::lang::XMultiServiceFactory > m_xServiceManager;
67     sal_Bool m_bToClearTextField;
68 
69 };
70 
71 class SearchToolbarControllersManager
72 {
73 public:
74 
75     SearchToolbarControllersManager();
76     ~SearchToolbarControllersManager();
77 
78     static SearchToolbarControllersManager* createControllersManager();
79 
80     void registryController( const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Reference< css::frame::XStatusListener >& xStatusListener, const ::rtl::OUString& sCommandURL );
81     void freeController ( const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Reference< css::frame::XStatusListener >& xStatusListener, const ::rtl::OUString& sCommandURL );
82     css::uno::Reference< css::frame::XStatusListener > findController( const css::uno::Reference< css::frame::XFrame >& xFrame, const ::rtl::OUString& sCommandURL );
83 
84 private:
85 
86     static SearchToolbarControllersManager* m_pInstance;
87 
88     typedef ::comphelper::SequenceAsVector< css::beans::PropertyValue > SearchToolbarControllersVec;
89     typedef ::std::map< css::uno::Reference< css::frame::XFrame >, SearchToolbarControllersVec > SearchToolbarControllersMap;
90     SearchToolbarControllersMap aSearchToolbarControllersMap;
91 
92 };
93 
94 class FindTextToolbarController : public svt::ToolboxController,
95                                   public css::lang::XServiceInfo
96 {
97 public:
98 
99     FindTextToolbarController( const css::uno::Reference< css::lang::XMultiServiceFactory > & rServiceManager );
100     ~FindTextToolbarController();
101 
102     // XInterface
103     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) throw ( css::uno::RuntimeException );
104     virtual void SAL_CALL acquire() throw ();
105     virtual void SAL_CALL release() throw ();
106 
107     // XServiceInfo
108     virtual ::rtl::OUString SAL_CALL getImplementationName() throw( css::uno::RuntimeException );
109     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( css::uno::RuntimeException );
110     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( css::uno::RuntimeException );
111 
getImplementationName_Static()112     static ::rtl::OUString getImplementationName_Static() throw()
113     {
114         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.svx.FindTextToolboxController" ));
115     }
116 
117     static ::com::sun::star::uno::Sequence< ::rtl::OUString >  getSupportedServiceNames_Static() throw();
118 
119     // XComponent
120     virtual void SAL_CALL dispose() throw ( css::uno::RuntimeException );
121 
122     // XInitialization
123     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException );
124 
125     // XToolbarController
126     virtual void SAL_CALL execute( sal_Int16 KeyModifier ) throw ( css::uno::RuntimeException);
127     virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) throw ( css::uno::RuntimeException );
128 
129     // XStatusListener
130     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) throw ( css::uno::RuntimeException );
131 
132     DECL_LINK(EditModifyHdl, void*);
133 
134 private:
135 
136     FindTextFieldControl* m_pFindTextFieldControl;
137 
138     sal_uInt16 m_nDownSearchId; // item position of findbar
139     sal_uInt16 m_nUpSearchId;   // item position of findbar
140 
141 };
142 
143 class DownSearchToolboxController : public svt::ToolboxController,
144                                     public css::lang::XServiceInfo
145 {
146 public:
147 
148     DownSearchToolboxController( const css::uno::Reference< css::lang::XMultiServiceFactory > & rServiceManager );
149     ~DownSearchToolboxController();
150 
151     // XInterface
152     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) throw ( css::uno::RuntimeException );
153     virtual void SAL_CALL acquire() throw ();
154     virtual void SAL_CALL release() throw ();
155 
156     // XServiceInfo
157     virtual ::rtl::OUString SAL_CALL getImplementationName() throw( css::uno::RuntimeException );
158     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( css::uno::RuntimeException );
159     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( css::uno::RuntimeException );
160 
getImplementationName_Static()161     static ::rtl::OUString getImplementationName_Static() throw()
162     {
163         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.svx.DownSearchToolboxController" ));
164     }
165 
166     static css::uno::Sequence< ::rtl::OUString >  getSupportedServiceNames_Static() throw();
167 
168     // XComponent
169     virtual void SAL_CALL dispose() throw ( css::uno::RuntimeException );
170 
171     // XInitialization
172     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException );
173 
174     // XToolbarController
175     virtual void SAL_CALL execute( sal_Int16 KeyModifier ) throw ( css::uno::RuntimeException);
176 
177     // XStatusListener
178     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) throw ( css::uno::RuntimeException );
179 
180 };
181 
182 class UpSearchToolboxController : public svt::ToolboxController,
183                                   public css::lang::XServiceInfo
184 {
185 public:
186 
187     UpSearchToolboxController( const css::uno::Reference< css::lang::XMultiServiceFactory >& rServiceManager );
188     ~UpSearchToolboxController();
189 
190     // XInterface
191     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) throw ( css::uno::RuntimeException );
192     virtual void SAL_CALL acquire() throw ();
193     virtual void SAL_CALL release() throw ();
194 
195     // XServiceInfo
196     virtual ::rtl::OUString SAL_CALL getImplementationName() throw( css::uno::RuntimeException );
197     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( css::uno::RuntimeException );
198     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( css::uno::RuntimeException );
199 
getImplementationName_Static()200     static ::rtl::OUString getImplementationName_Static() throw()
201     {
202         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.svx.UpSearchToolboxController" ));
203     }
204 
205     static css::uno::Sequence< ::rtl::OUString >  getSupportedServiceNames_Static() throw();
206 
207     // XComponent
208     virtual void SAL_CALL dispose() throw ( css::uno::RuntimeException );
209 
210     // XInitialization
211     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException);
212 
213     // XToolbarController
214     virtual void SAL_CALL execute( sal_Int16 KeyModifier ) throw ( css::uno::RuntimeException );
215 
216     // XStatusListener
217     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) throw ( css::uno::RuntimeException );
218 
219 };
220 
221 // protocol handler for "vnd.sun.star.findbar:*" URLs
222 // The dispatch object will be used for shortcut commands for findbar
223 class FindbarDispatcher : public css::lang::XServiceInfo,
224                           public css::lang::XInitialization,
225                           public css::frame::XDispatchProvider,
226                           public css::frame::XDispatch,
227                           public ::cppu::OWeakObject
228 {
229 public:
230 
231     FindbarDispatcher( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory );
232     virtual ~FindbarDispatcher();
233 
234     // XInterface
235     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) throw ( css::uno::RuntimeException );
236     virtual void SAL_CALL acquire() throw();
237     virtual void SAL_CALL release() throw();
238 
239     // XServiceInfo
240     virtual ::rtl::OUString SAL_CALL getImplementationName() throw( css::uno::RuntimeException );
241     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( css::uno::RuntimeException );
242     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( css::uno::RuntimeException );
243 
getImplementationName_Static()244     static ::rtl::OUString getImplementationName_Static() throw()
245     {
246         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svx.Impl.FindbarDispatcher" ));
247     }
248 
249     static css::uno::Sequence< ::rtl::OUString >  getSupportedServiceNames_Static() throw();
250 
251     // XInitialization
252     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException );
253 
254     // XDispatchProvider
255     virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch( const css::util::URL& aURL, const ::rtl::OUString& sTargetFrameName , sal_Int32 nSearchFlags ) throw( css::uno::RuntimeException );
256     virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptions    ) throw( css::uno::RuntimeException );
257 
258     // XDispatch
259     virtual void SAL_CALL dispatch( const css::util::URL& aURL, const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException );
260     virtual void SAL_CALL addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xListener, const css::util::URL& aURL ) throw( css::uno::RuntimeException );
261     virtual void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xListener, const css::util::URL& aURL ) throw( css::uno::RuntimeException );
262 
263 private:
264 
265     css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory;
266     css::uno::Reference< css::frame::XFrame > m_xFrame;
267 
268 };
269 
270 // createInstance
271 css::uno::Reference< css::uno::XInterface > SAL_CALL FindTextToolbarController_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr );
272 css::uno::Reference< css::uno::XInterface > SAL_CALL DownSearchToolboxController_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr );
273 css::uno::Reference< css::uno::XInterface > SAL_CALL UpSearchToolboxController_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr );
274 css::uno::Reference< css::uno::XInterface > SAL_CALL FindbarDispatcher_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr );
275 
276 }
277 
278 #endif // __TBUNOSEARCHCONTROLLERS_HXX_
279