File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
2 | /* | |||
3 | * This file is part of the LibreOffice project. | |||
4 | * | |||
5 | * This Source Code Form is subject to the terms of the Mozilla Public | |||
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this | |||
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |||
8 | * | |||
9 | * This file incorporates work covered by the following license notice: | |||
10 | * | |||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | |||
12 | * contributor license agreements. See the NOTICE file distributed | |||
13 | * with this work for additional information regarding copyright | |||
14 | * ownership. The ASF licenses this file to you under the Apache | |||
15 | * License, Version 2.0 (the "License"); you may not use this file | |||
16 | * except in compliance with the License. You may obtain a copy of | |||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | |||
18 | */ | |||
19 | ||||
20 | #include <sal/config.h> | |||
21 | ||||
22 | #include <map> | |||
23 | #include <vector> | |||
24 | ||||
25 | #include <config_feature_desktop.h> | |||
26 | ||||
27 | #include <svx/strings.hrc> | |||
28 | #include <svx/dialmgr.hxx> | |||
29 | ||||
30 | #include <comphelper/propertysequence.hxx> | |||
31 | #include <cppuhelper/queryinterface.hxx> | |||
32 | #include <cppuhelper/supportsservice.hxx> | |||
33 | #include <cppuhelper/weak.hxx> | |||
34 | #include <com/sun/star/beans/PropertyValue.hpp> | |||
35 | #include <com/sun/star/beans/XPropertySet.hpp> | |||
36 | #include <com/sun/star/frame/DispatchDescriptor.hpp> | |||
37 | #include <com/sun/star/frame/XDispatch.hpp> | |||
38 | #include <com/sun/star/frame/XDispatchProvider.hpp> | |||
39 | #include <com/sun/star/frame/XLayoutManager.hpp> | |||
40 | #include <com/sun/star/frame/XStatusListener.hpp> | |||
41 | #include <com/sun/star/lang/XInitialization.hpp> | |||
42 | #include <com/sun/star/lang/XServiceInfo.hpp> | |||
43 | #include <com/sun/star/text/XTextRange.hpp> | |||
44 | #include <com/sun/star/ui/XUIElement.hpp> | |||
45 | #include <com/sun/star/util/URL.hpp> | |||
46 | #include <com/sun/star/util/URLTransformer.hpp> | |||
47 | #include <com/sun/star/util/SearchAlgorithms.hpp> | |||
48 | #include <com/sun/star/util/SearchAlgorithms2.hpp> | |||
49 | ||||
50 | #include <vcl/InterimItemWindow.hxx> | |||
51 | #include <svl/ctloptions.hxx> | |||
52 | #include <svl/srchitem.hxx> | |||
53 | #include <svtools/acceleratorexecute.hxx> | |||
54 | #include <svtools/toolboxcontroller.hxx> | |||
55 | #include <toolkit/helper/vclunohelper.hxx> | |||
56 | #include <vcl/toolbox.hxx> | |||
57 | #include <vcl/svapp.hxx> | |||
58 | #include <rtl/instance.hxx> | |||
59 | #include <svx/labelitemwindow.hxx> | |||
60 | #include <svx/srchdlg.hxx> | |||
61 | #include <vcl/event.hxx> | |||
62 | ||||
63 | #include <findtextfield.hxx> | |||
64 | ||||
65 | using namespace css; | |||
66 | ||||
67 | namespace { | |||
68 | ||||
69 | const char COMMAND_FINDTEXT[] = ".uno:FindText"; | |||
70 | const char COMMAND_DOWNSEARCH[] = ".uno:DownSearch"; | |||
71 | const char COMMAND_UPSEARCH[] = ".uno:UpSearch"; | |||
72 | const char COMMAND_FINDALL[] = ".uno:FindAll"; | |||
73 | const char COMMAND_MATCHCASE[] = ".uno:MatchCase"; | |||
74 | const char COMMAND_SEARCHFORMATTED[] = ".uno:SearchFormattedDisplayString"; | |||
75 | ||||
76 | const sal_Int32 REMEMBER_SIZE = 10; | |||
77 | ||||
78 | class CheckButtonItemWindow final : public InterimItemWindow | |||
79 | { | |||
80 | public: | |||
81 | CheckButtonItemWindow(vcl::Window* pParent, const OUString& rLabel) | |||
82 | : InterimItemWindow(pParent, "svx/ui/checkbuttonbox.ui", "CheckButtonBox") | |||
83 | , m_xWidget(m_xBuilder->weld_check_button("checkbutton")) | |||
84 | { | |||
85 | InitControlBase(m_xWidget.get()); | |||
86 | ||||
87 | m_xWidget->connect_key_press(LINK(this, CheckButtonItemWindow, KeyInputHdl)::tools::detail::makeLink( ::tools::detail::castTo<CheckButtonItemWindow *>(this), &CheckButtonItemWindow::LinkStubKeyInputHdl )); | |||
88 | m_xWidget->set_label(rLabel); | |||
89 | SetSizePixel(m_xWidget->get_preferred_size()); | |||
90 | } | |||
91 | ||||
92 | bool get_active() const | |||
93 | { | |||
94 | return m_xWidget->get_active(); | |||
95 | } | |||
96 | ||||
97 | virtual void dispose() override | |||
98 | { | |||
99 | m_xWidget.reset(); | |||
100 | InterimItemWindow::dispose(); | |||
101 | } | |||
102 | ||||
103 | virtual ~CheckButtonItemWindow() override | |||
104 | { | |||
105 | disposeOnce(); | |||
106 | } | |||
107 | ||||
108 | private: | |||
109 | std::unique_ptr<weld::CheckButton> m_xWidget; | |||
110 | ||||
111 | DECL_LINK(KeyInputHdl, const KeyEvent&, bool)static bool LinkStubKeyInputHdl(void *, const KeyEvent&); bool KeyInputHdl(const KeyEvent&); | |||
112 | }; | |||
113 | ||||
114 | IMPL_LINK(CheckButtonItemWindow, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)bool CheckButtonItemWindow::LinkStubKeyInputHdl(void * instance , const KeyEvent& data) { return static_cast<CheckButtonItemWindow *>(instance)->KeyInputHdl(data); } bool CheckButtonItemWindow ::KeyInputHdl(const KeyEvent& rKeyEvent) | |||
115 | { | |||
116 | return ChildKeyInput(rKeyEvent); | |||
117 | } | |||
118 | ||||
119 | void impl_executeSearch( const css::uno::Reference< css::uno::XComponentContext >& rxContext, | |||
120 | const css::uno::Reference< css::frame::XFrame >& xFrame, | |||
121 | const ToolBox* pToolBox, | |||
122 | const bool aSearchBackwards, | |||
123 | const bool aFindAll = false ) | |||
124 | { | |||
125 | css::uno::Reference< css::util::XURLTransformer > xURLTransformer( css::util::URLTransformer::create( rxContext ) ); | |||
126 | css::util::URL aURL; | |||
127 | aURL.Complete = ".uno:ExecuteSearch"; | |||
128 | xURLTransformer->parseStrict(aURL); | |||
129 | ||||
130 | OUString sFindText; | |||
131 | bool aMatchCase = false; | |||
132 | bool bSearchFormatted = false; | |||
133 | if ( pToolBox ) | |||
134 | { | |||
135 | ToolBox::ImplToolItems::size_type nItemCount = pToolBox->GetItemCount(); | |||
136 | for ( ToolBox::ImplToolItems::size_type i=0; i<nItemCount; ++i ) | |||
137 | { | |||
138 | sal_uInt16 id = pToolBox->GetItemId(i); | |||
139 | OUString sItemCommand = pToolBox->GetItemCommand(id); | |||
140 | if ( sItemCommand == COMMAND_FINDTEXT ) | |||
141 | { | |||
142 | FindTextFieldControl* pItemWin = static_cast<FindTextFieldControl*>(pToolBox->GetItemWindow(id)); | |||
143 | if (pItemWin) | |||
144 | { | |||
145 | sFindText = pItemWin->get_active_text(); | |||
146 | if (aFindAll) | |||
147 | pItemWin->GetFocus(); | |||
148 | } | |||
149 | } else if ( sItemCommand == COMMAND_MATCHCASE ) | |||
150 | { | |||
151 | CheckButtonItemWindow* pItemWin = static_cast<CheckButtonItemWindow*>(pToolBox->GetItemWindow(id)); | |||
152 | if (pItemWin) | |||
153 | aMatchCase = pItemWin->get_active(); | |||
154 | } else if ( sItemCommand == COMMAND_SEARCHFORMATTED ) | |||
155 | { | |||
156 | CheckButtonItemWindow* pItemWin = static_cast<CheckButtonItemWindow*>(pToolBox->GetItemWindow(id)); | |||
157 | if (pItemWin) | |||
158 | bSearchFormatted = pItemWin->get_active(); | |||
159 | } | |||
160 | } | |||
161 | } | |||
162 | ||||
163 | SvtCTLOptions aCTLOptions; | |||
164 | TransliterationFlags nFlags = TransliterationFlags::NONE; | |||
165 | if (!aMatchCase) | |||
166 | nFlags |= TransliterationFlags::IGNORE_CASE; | |||
167 | if (aCTLOptions.IsCTLFontEnabled()) | |||
168 | nFlags |= TransliterationFlags::IGNORE_DIACRITICS_CTL | |||
169 | | TransliterationFlags::IGNORE_KASHIDA_CTL; | |||
170 | ||||
171 | auto aArgs( comphelper::InitPropertySequence( { | |||
172 | { "SearchItem.SearchString", css::uno::makeAny( sFindText ) }, | |||
173 | { "SearchItem.Backward", css::uno::makeAny( aSearchBackwards ) }, | |||
174 | { "SearchItem.SearchFlags", css::uno::makeAny( sal_Int32(0) ) }, | |||
175 | { "SearchItem.TransliterateFlags", css::uno::makeAny( static_cast<sal_Int32>(nFlags) ) }, | |||
176 | { "SearchItem.Command", css::uno::makeAny( static_cast<sal_Int16>(aFindAll ?SvxSearchCmd::FIND_ALL : SvxSearchCmd::FIND ) ) }, | |||
177 | { "SearchItem.AlgorithmType", css::uno::makeAny( sal_Int16(css::util::SearchAlgorithms_ABSOLUTE) ) }, | |||
178 | { "SearchItem.AlgorithmType2", css::uno::makeAny( sal_Int16(css::util::SearchAlgorithms2::ABSOLUTE) ) }, | |||
179 | { "SearchItem.SearchFormatted", css::uno::makeAny( bSearchFormatted ) } | |||
180 | } ) ); | |||
181 | ||||
182 | css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider(xFrame, css::uno::UNO_QUERY); | |||
183 | if ( xDispatchProvider.is() ) | |||
184 | { | |||
185 | css::uno::Reference< css::frame::XDispatch > xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 ); | |||
186 | if ( xDispatch.is() && !aURL.Complete.isEmpty() ) | |||
187 | xDispatch->dispatch( aURL, aArgs ); | |||
188 | } | |||
189 | } | |||
190 | ||||
191 | } | |||
192 | ||||
193 | FindTextFieldControl::FindTextFieldControl( vcl::Window* pParent, | |||
194 | css::uno::Reference< css::frame::XFrame > const & xFrame, | |||
195 | const css::uno::Reference< css::uno::XComponentContext >& xContext) : | |||
196 | InterimItemWindow(pParent, "svx/ui/findbox.ui", "FindBox"), | |||
197 | m_nAsyncGetFocusId(nullptr), | |||
198 | m_xWidget(m_xBuilder->weld_combo_box("find")), | |||
199 | m_xFrame(xFrame), | |||
200 | m_xContext(xContext), | |||
201 | m_pAcc(svt::AcceleratorExecute::createAcceleratorHelper()) | |||
202 | { | |||
203 | m_xWidget->set_entry_placeholder_text(SvxResId(RID_SVXSTR_FINDBAR_FINDreinterpret_cast<char const *>("RID_SVXSTR_FINDBAR_FIND" "\004" u8"Find"))); | |||
204 | m_xWidget->set_entry_completion(true, true); | |||
205 | m_pAcc->init(m_xContext, m_xFrame); | |||
206 | ||||
207 | m_xWidget->connect_focus_in(LINK(this, FindTextFieldControl, FocusInHdl)::tools::detail::makeLink( ::tools::detail::castTo<FindTextFieldControl *>(this), &FindTextFieldControl::LinkStubFocusInHdl)); | |||
208 | m_xWidget->connect_key_press(LINK(this, FindTextFieldControl, KeyInputHdl)::tools::detail::makeLink( ::tools::detail::castTo<FindTextFieldControl *>(this), &FindTextFieldControl::LinkStubKeyInputHdl)); | |||
209 | m_xWidget->connect_entry_activate(LINK(this, FindTextFieldControl, ActivateHdl)::tools::detail::makeLink( ::tools::detail::castTo<FindTextFieldControl *>(this), &FindTextFieldControl::LinkStubActivateHdl)); | |||
210 | ||||
211 | m_xWidget->set_size_request(250, -1); | |||
212 | SetSizePixel(m_xWidget->get_preferred_size()); | |||
213 | } | |||
214 | ||||
215 | void FindTextFieldControl::Remember_Impl(const OUString& rStr) | |||
216 | { | |||
217 | const sal_Int32 nCount = m_xWidget->get_count(); | |||
218 | ||||
219 | for (sal_Int32 i=0; i<nCount; ++i) | |||
220 | { | |||
221 | if (rStr == m_xWidget->get_text(i)) | |||
222 | return; | |||
223 | } | |||
224 | ||||
225 | if (nCount == REMEMBER_SIZE) | |||
226 | m_xWidget->remove(REMEMBER_SIZE-1); | |||
227 | ||||
228 | m_xWidget->insert_text(0, rStr); | |||
229 | } | |||
230 | ||||
231 | void FindTextFieldControl::SetTextToSelected_Impl() | |||
232 | { | |||
233 | OUString aString; | |||
234 | ||||
235 | try | |||
236 | { | |||
237 | css::uno::Reference<css::frame::XController> xController(m_xFrame->getController(), css::uno::UNO_SET_THROW); | |||
238 | css::uno::Reference<css::frame::XModel> xModel(xController->getModel(), css::uno::UNO_SET_THROW); | |||
239 | css::uno::Reference<css::container::XIndexAccess> xIndexAccess(xModel->getCurrentSelection(), css::uno::UNO_QUERY_THROW); | |||
240 | if (xIndexAccess->getCount() > 0) | |||
241 | { | |||
242 | css::uno::Reference<css::text::XTextRange> xTextRange(xIndexAccess->getByIndex(0), css::uno::UNO_QUERY_THROW); | |||
243 | aString = xTextRange->getString(); | |||
244 | } | |||
245 | } | |||
246 | catch ( ... ) | |||
247 | { | |||
248 | } | |||
249 | ||||
250 | if ( !aString.isEmpty() ) | |||
251 | { | |||
252 | // If something is selected in the document, prepopulate with this | |||
253 | m_xWidget->set_entry_text(aString); | |||
254 | m_aChangeHdl.Call(*m_xWidget); | |||
255 | } | |||
256 | else if (get_count() > 0) | |||
257 | { | |||
258 | // Else, prepopulate with last search word (fdo#84256) | |||
259 | m_xWidget->set_entry_text(m_xWidget->get_text(0)); | |||
260 | } | |||
261 | } | |||
262 | ||||
263 | IMPL_LINK(FindTextFieldControl, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)bool FindTextFieldControl::LinkStubKeyInputHdl(void * instance , const KeyEvent& data) { return static_cast<FindTextFieldControl *>(instance)->KeyInputHdl(data); } bool FindTextFieldControl ::KeyInputHdl(const KeyEvent& rKeyEvent) | |||
264 | { | |||
265 | if (isDisposed()) | |||
266 | return true; | |||
267 | ||||
268 | bool bRet = false; | |||
269 | ||||
270 | bool bShift = rKeyEvent.GetKeyCode().IsShift(); | |||
271 | bool bMod1 = rKeyEvent.GetKeyCode().IsMod1(); | |||
272 | sal_uInt16 nCode = rKeyEvent.GetKeyCode().GetCode(); | |||
273 | ||||
274 | // Close the search bar on Escape | |||
275 | if ( KEY_ESCAPE == nCode ) | |||
276 | { | |||
277 | bRet = true; | |||
278 | GrabFocusToDocument(); | |||
279 | ||||
280 | // hide the findbar | |||
281 | css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY); | |||
282 | if (xPropSet.is()) | |||
283 | { | |||
284 | css::uno::Reference< css::frame::XLayoutManager > xLayoutManager; | |||
285 | css::uno::Any aValue = xPropSet->getPropertyValue("LayoutManager"); | |||
286 | aValue >>= xLayoutManager; | |||
287 | if (xLayoutManager.is()) | |||
288 | { | |||
289 | const OUString sResourceURL( "private:resource/toolbar/findbar" ); | |||
290 | xLayoutManager->hideElement( sResourceURL ); | |||
291 | xLayoutManager->destroyElement( sResourceURL ); | |||
292 | } | |||
293 | } | |||
294 | } | |||
295 | // Select text in the search box when Ctrl-F pressed | |||
296 | else if ( bMod1 && nCode == KEY_F ) | |||
297 | m_xWidget->select_entry_region(0, -1); | |||
298 | ||||
299 | // Execute the search when Return, Ctrl-G or F3 pressed | |||
300 | else if ( KEY_RETURN == nCode || (bMod1 && (KEY_G == nCode)) || (KEY_F3 == nCode) ) | |||
301 | { | |||
302 | ActivateFind(bShift); | |||
303 | m_xWidget->grab_focus(); | |||
304 | bRet = true; | |||
305 | } | |||
306 | else | |||
307 | { | |||
308 | auto awtKey = svt::AcceleratorExecute::st_VCLKey2AWTKey(rKeyEvent.GetKeyCode()); | |||
309 | const OUString aCommand(m_pAcc->findCommand(awtKey)); | |||
310 | if (aCommand == ".uno:SearchDialog") | |||
311 | bRet = m_pAcc->execute(awtKey); | |||
312 | } | |||
313 | ||||
314 | return bRet || ChildKeyInput(rKeyEvent); | |||
315 | } | |||
316 | ||||
317 | void FindTextFieldControl::ActivateFind(bool bShift) | |||
318 | { | |||
319 | Remember_Impl(m_xWidget->get_active_text()); | |||
320 | ||||
321 | vcl::Window* pWindow = GetParent(); | |||
322 | ToolBox* pToolBox = static_cast<ToolBox*>(pWindow); | |||
323 | ||||
324 | impl_executeSearch(m_xContext, m_xFrame, pToolBox, bShift); | |||
325 | } | |||
326 | ||||
327 | IMPL_LINK_NOARG(FindTextFieldControl, ActivateHdl, weld::ComboBox&, bool)bool FindTextFieldControl::LinkStubActivateHdl(void * instance , weld::ComboBox& data) { return static_cast<FindTextFieldControl *>(instance)->ActivateHdl(data); } bool FindTextFieldControl ::ActivateHdl(__attribute__ ((unused)) weld::ComboBox&) | |||
328 | { | |||
329 | if (isDisposed()) | |||
330 | return true; | |||
331 | ||||
332 | ActivateFind(false); | |||
333 | ||||
334 | return true; | |||
335 | } | |||
336 | ||||
337 | IMPL_LINK_NOARG(FindTextFieldControl, OnAsyncGetFocus, void*, void)void FindTextFieldControl::LinkStubOnAsyncGetFocus(void * instance , void* data) { return static_cast<FindTextFieldControl *> (instance)->OnAsyncGetFocus(data); } void FindTextFieldControl ::OnAsyncGetFocus(__attribute__ ((unused)) void*) | |||
338 | { | |||
339 | m_nAsyncGetFocusId = nullptr; | |||
340 | m_xWidget->select_entry_region(0, -1); | |||
341 | } | |||
342 | ||||
343 | IMPL_LINK_NOARG(FindTextFieldControl, FocusInHdl, weld::Widget&, void)void FindTextFieldControl::LinkStubFocusInHdl(void * instance , weld::Widget& data) { return static_cast<FindTextFieldControl *>(instance)->FocusInHdl(data); } void FindTextFieldControl ::FocusInHdl(__attribute__ ((unused)) weld::Widget&) | |||
344 | { | |||
345 | if (m_nAsyncGetFocusId) | |||
346 | return; | |||
347 | // do it async to defeat entry in combobox having its own ideas about the focus | |||
348 | m_nAsyncGetFocusId = Application::PostUserEvent(LINK(this, FindTextFieldControl, OnAsyncGetFocus)::tools::detail::makeLink( ::tools::detail::castTo<FindTextFieldControl *>(this), &FindTextFieldControl::LinkStubOnAsyncGetFocus )); | |||
349 | } | |||
350 | ||||
351 | void FindTextFieldControl::dispose() | |||
352 | { | |||
353 | if (m_nAsyncGetFocusId) | |||
354 | { | |||
355 | Application::RemoveUserEvent(m_nAsyncGetFocusId); | |||
356 | m_nAsyncGetFocusId = nullptr; | |||
357 | } | |||
358 | m_xWidget.reset(); | |||
359 | InterimItemWindow::dispose(); | |||
360 | } | |||
361 | ||||
362 | FindTextFieldControl::~FindTextFieldControl() | |||
363 | { | |||
364 | disposeOnce(); | |||
365 | } | |||
366 | ||||
367 | void FindTextFieldControl::connect_changed(const Link<weld::ComboBox&, void>& rLink) | |||
368 | { | |||
369 | m_aChangeHdl = rLink; | |||
370 | m_xWidget->connect_changed(rLink); | |||
371 | } | |||
372 | ||||
373 | int FindTextFieldControl::get_count() const | |||
374 | { | |||
375 | return m_xWidget->get_count(); | |||
376 | } | |||
377 | ||||
378 | OUString FindTextFieldControl::get_text(int nIndex) const | |||
379 | { | |||
380 | return m_xWidget->get_text(nIndex); | |||
381 | } | |||
382 | ||||
383 | OUString FindTextFieldControl::get_active_text() const | |||
384 | { | |||
385 | return m_xWidget->get_active_text(); | |||
386 | } | |||
387 | ||||
388 | void FindTextFieldControl::append_text(const OUString& rText) | |||
389 | { | |||
390 | m_xWidget->append_text(rText); | |||
391 | } | |||
392 | ||||
393 | void FindTextFieldControl::set_entry_message_type(weld::EntryMessageType eType) | |||
394 | { | |||
395 | m_xWidget->set_entry_message_type(eType); | |||
396 | } | |||
397 | ||||
398 | void FindTextFieldControl::GetFocus() | |||
399 | { | |||
400 | if (m_xWidget) | |||
401 | { | |||
402 | m_xWidget->grab_focus(); | |||
403 | FocusInHdl(*m_xWidget); | |||
404 | } | |||
405 | InterimItemWindow::GetFocus(); | |||
406 | } | |||
407 | ||||
408 | namespace { | |||
409 | ||||
410 | class SearchToolbarControllersManager | |||
411 | { | |||
412 | public: | |||
413 | ||||
414 | SearchToolbarControllersManager(); | |||
415 | ||||
416 | static SearchToolbarControllersManager& createControllersManager(); | |||
417 | ||||
418 | void registryController( const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Reference< css::frame::XStatusListener >& xStatusListener, const OUString& sCommandURL ); | |||
419 | void freeController ( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL ); | |||
420 | css::uno::Reference< css::frame::XStatusListener > findController( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL ); | |||
421 | ||||
422 | void saveSearchHistory(const FindTextFieldControl* m_pFindTextFieldControl); | |||
423 | void loadSearchHistory(FindTextFieldControl* m_pFindTextFieldControl); | |||
424 | ||||
425 | private: | |||
426 | ||||
427 | typedef ::std::vector< css::beans::PropertyValue > SearchToolbarControllersVec; | |||
428 | typedef ::std::map< css::uno::Reference< css::frame::XFrame >, SearchToolbarControllersVec > SearchToolbarControllersMap; | |||
429 | SearchToolbarControllersMap aSearchToolbarControllersMap; | |||
430 | std::vector<OUString> m_aSearchStrings; | |||
431 | ||||
432 | }; | |||
433 | ||||
434 | SearchToolbarControllersManager::SearchToolbarControllersManager() | |||
435 | { | |||
436 | } | |||
437 | ||||
438 | class theSearchToolbarControllersManager | |||
439 | : public rtl::Static<SearchToolbarControllersManager, | |||
440 | theSearchToolbarControllersManager> | |||
441 | { | |||
442 | }; | |||
443 | ||||
444 | SearchToolbarControllersManager& SearchToolbarControllersManager::createControllersManager() | |||
445 | { | |||
446 | return theSearchToolbarControllersManager::get(); | |||
447 | } | |||
448 | ||||
449 | void SearchToolbarControllersManager::saveSearchHistory(const FindTextFieldControl* pFindTextFieldControl) | |||
450 | { | |||
451 | const sal_Int32 nECount( pFindTextFieldControl->get_count() ); | |||
452 | m_aSearchStrings.resize( nECount ); | |||
453 | for( sal_Int32 i=0; i<nECount; ++i ) | |||
454 | { | |||
455 | m_aSearchStrings[i] = pFindTextFieldControl->get_text(i); | |||
456 | } | |||
457 | } | |||
458 | ||||
459 | void SearchToolbarControllersManager::loadSearchHistory(FindTextFieldControl* pFindTextFieldControl) | |||
460 | { | |||
461 | for( size_t i=0; i<m_aSearchStrings.size(); ++i ) | |||
462 | { | |||
463 | pFindTextFieldControl->append_text(m_aSearchStrings[i]); | |||
464 | } | |||
465 | } | |||
466 | ||||
467 | void SearchToolbarControllersManager::registryController( const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Reference< css::frame::XStatusListener >& xStatusListener, const OUString& sCommandURL ) | |||
468 | { | |||
469 | SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame); | |||
470 | if (pIt == aSearchToolbarControllersMap.end()) | |||
471 | { | |||
472 | SearchToolbarControllersVec lControllers(1); | |||
473 | lControllers[0].Name = sCommandURL; | |||
474 | lControllers[0].Value <<= xStatusListener; | |||
475 | aSearchToolbarControllersMap.emplace(xFrame, lControllers); | |||
476 | } | |||
477 | else | |||
478 | { | |||
479 | sal_Int32 nSize = pIt->second.size(); | |||
480 | for (sal_Int32 i=0; i<nSize; ++i) | |||
481 | { | |||
482 | if (pIt->second[i].Name == sCommandURL) | |||
483 | return; | |||
484 | } | |||
485 | ||||
486 | pIt->second.resize(nSize+1); | |||
487 | pIt->second[nSize].Name = sCommandURL; | |||
488 | pIt->second[nSize].Value <<= xStatusListener; | |||
489 | } | |||
490 | } | |||
491 | ||||
492 | void SearchToolbarControllersManager::freeController( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL ) | |||
493 | { | |||
494 | SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame); | |||
495 | if (pIt != aSearchToolbarControllersMap.end()) | |||
496 | { | |||
497 | auto pItCtrl = std::find_if(pIt->second.begin(), pIt->second.end(), | |||
498 | [&sCommandURL](const css::beans::PropertyValue& rCtrl) { return rCtrl.Name == sCommandURL; }); | |||
499 | if (pItCtrl != pIt->second.end()) | |||
500 | pIt->second.erase(pItCtrl); | |||
501 | ||||
502 | if (pIt->second.empty()) | |||
503 | aSearchToolbarControllersMap.erase(pIt); | |||
504 | } | |||
505 | } | |||
506 | ||||
507 | css::uno::Reference< css::frame::XStatusListener > SearchToolbarControllersManager::findController( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL ) | |||
508 | { | |||
509 | css::uno::Reference< css::frame::XStatusListener > xStatusListener; | |||
510 | ||||
511 | SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame); | |||
512 | if (pIt != aSearchToolbarControllersMap.end()) | |||
513 | { | |||
514 | auto pItCtrl = std::find_if(pIt->second.begin(), pIt->second.end(), | |||
515 | [&sCommandURL](const css::beans::PropertyValue& rCtrl) { return rCtrl.Name == sCommandURL; }); | |||
516 | if (pItCtrl != pIt->second.end()) | |||
517 | pItCtrl->Value >>= xStatusListener; | |||
518 | } | |||
519 | ||||
520 | return xStatusListener; | |||
521 | } | |||
522 | ||||
523 | class FindTextToolbarController : public svt::ToolboxController, | |||
524 | public css::lang::XServiceInfo | |||
525 | { | |||
526 | public: | |||
527 | ||||
528 | FindTextToolbarController( const css::uno::Reference< css::uno::XComponentContext > & rxContext ); | |||
529 | ||||
530 | // XInterface | |||
531 | virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; | |||
532 | virtual void SAL_CALL acquire() throw () override; | |||
533 | virtual void SAL_CALL release() throw () override; | |||
534 | ||||
535 | // XServiceInfo | |||
536 | virtual OUString SAL_CALL getImplementationName() override; | |||
537 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; | |||
538 | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; | |||
539 | ||||
540 | // XComponent | |||
541 | virtual void SAL_CALL dispose() override; | |||
542 | ||||
543 | // XInitialization | |||
544 | virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; | |||
545 | ||||
546 | // XToolbarController | |||
547 | virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override; | |||
548 | ||||
549 | // XStatusListener | |||
550 | virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override; | |||
551 | ||||
552 | DECL_LINK(EditModifyHdl, weld::ComboBox&, void)static void LinkStubEditModifyHdl(void *, weld::ComboBox& ); void EditModifyHdl(weld::ComboBox&); | |||
553 | ||||
554 | private: | |||
555 | ||||
556 | void textfieldChanged(); | |||
557 | ||||
558 | VclPtr<FindTextFieldControl> m_pFindTextFieldControl; | |||
559 | ||||
560 | sal_uInt16 m_nDownSearchId; | |||
561 | sal_uInt16 m_nUpSearchId; | |||
562 | sal_uInt16 m_nFindAllId; | |||
563 | ||||
564 | }; | |||
565 | ||||
566 | FindTextToolbarController::FindTextToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext ) | |||
567 | : svt::ToolboxController(rxContext, css::uno::Reference< css::frame::XFrame >(), COMMAND_FINDTEXT) | |||
568 | , m_pFindTextFieldControl(nullptr) | |||
569 | , m_nDownSearchId(0) | |||
570 | , m_nUpSearchId(0) | |||
571 | , m_nFindAllId(0) | |||
572 | { | |||
573 | } | |||
574 | ||||
575 | // XInterface | |||
576 | css::uno::Any SAL_CALL FindTextToolbarController::queryInterface( const css::uno::Type& aType ) | |||
577 | { | |||
578 | css::uno::Any a = ToolboxController::queryInterface( aType ); | |||
579 | if ( a.hasValue() ) | |||
580 | return a; | |||
581 | ||||
582 | return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) ); | |||
583 | } | |||
584 | ||||
585 | void SAL_CALL FindTextToolbarController::acquire() throw () | |||
586 | { | |||
587 | ToolboxController::acquire(); | |||
588 | } | |||
589 | ||||
590 | void SAL_CALL FindTextToolbarController::release() throw () | |||
591 | { | |||
592 | ToolboxController::release(); | |||
593 | } | |||
594 | ||||
595 | // XServiceInfo | |||
596 | OUString SAL_CALL FindTextToolbarController::getImplementationName() | |||
597 | { | |||
598 | return "com.sun.star.svx.FindTextToolboxController"; | |||
599 | } | |||
600 | ||||
601 | sal_Bool SAL_CALL FindTextToolbarController::supportsService( const OUString& ServiceName ) | |||
602 | { | |||
603 | return cppu::supportsService(this, ServiceName); | |||
604 | } | |||
605 | ||||
606 | css::uno::Sequence< OUString > SAL_CALL FindTextToolbarController::getSupportedServiceNames() | |||
607 | { | |||
608 | return { "com.sun.star.frame.ToolbarController" }; | |||
609 | } | |||
610 | ||||
611 | // XComponent | |||
612 | void SAL_CALL FindTextToolbarController::dispose() | |||
613 | { | |||
614 | SolarMutexGuard aSolarMutexGuard; | |||
615 | ||||
616 | SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL); | |||
617 | ||||
618 | svt::ToolboxController::dispose(); | |||
619 | if (m_pFindTextFieldControl != nullptr) { | |||
620 | SearchToolbarControllersManager::createControllersManager() | |||
621 | .saveSearchHistory(m_pFindTextFieldControl); | |||
622 | m_pFindTextFieldControl.disposeAndClear(); | |||
623 | } | |||
624 | } | |||
625 | ||||
626 | // XInitialization | |||
627 | void SAL_CALL FindTextToolbarController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) | |||
628 | { | |||
629 | svt::ToolboxController::initialize(aArguments); | |||
630 | ||||
631 | VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( getParent() ); | |||
632 | ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get()); | |||
633 | if ( pToolBox ) | |||
634 | { | |||
635 | m_nDownSearchId = pToolBox->GetItemId(COMMAND_DOWNSEARCH); | |||
636 | m_nUpSearchId = pToolBox->GetItemId(COMMAND_UPSEARCH); | |||
637 | m_nFindAllId = pToolBox->GetItemId(COMMAND_FINDALL); | |||
638 | } | |||
639 | ||||
640 | SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); | |||
641 | } | |||
642 | ||||
643 | css::uno::Reference< css::awt::XWindow > SAL_CALL FindTextToolbarController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& xParent ) | |||
644 | { | |||
645 | css::uno::Reference< css::awt::XWindow > xItemWindow; | |||
646 | ||||
647 | VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent ); | |||
648 | if ( pParent ) | |||
649 | { | |||
650 | ToolBox* pToolbar = static_cast<ToolBox*>(pParent.get()); | |||
651 | m_pFindTextFieldControl = VclPtr<FindTextFieldControl>::Create(pToolbar, m_xFrame, m_xContext); | |||
652 | ||||
653 | m_pFindTextFieldControl->connect_changed(LINK(this, FindTextToolbarController, EditModifyHdl)::tools::detail::makeLink( ::tools::detail::castTo<FindTextToolbarController *>(this), &FindTextToolbarController::LinkStubEditModifyHdl )); | |||
654 | SearchToolbarControllersManager::createControllersManager().loadSearchHistory(m_pFindTextFieldControl); | |||
655 | } | |||
656 | xItemWindow = VCLUnoHelper::GetInterface( m_pFindTextFieldControl ); | |||
657 | ||||
658 | return xItemWindow; | |||
659 | } | |||
660 | ||||
661 | // XStatusListener | |||
662 | void SAL_CALL FindTextToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent ) | |||
663 | { | |||
664 | SolarMutexGuard aSolarMutexGuard; | |||
665 | if ( m_bDisposed ) | |||
666 | return; | |||
667 | ||||
668 | OUString aFeatureURL = rEvent.FeatureURL.Complete; | |||
669 | if ( aFeatureURL == "AppendSearchHistory" ) | |||
670 | { | |||
671 | m_pFindTextFieldControl->Remember_Impl(m_pFindTextFieldControl->get_active_text()); | |||
672 | } | |||
673 | // enable up/down buttons in case there is already text (from the search history) | |||
674 | textfieldChanged(); | |||
675 | } | |||
676 | ||||
677 | IMPL_LINK_NOARG(FindTextToolbarController, EditModifyHdl, weld::ComboBox&, void)void FindTextToolbarController::LinkStubEditModifyHdl(void * instance , weld::ComboBox& data) { return static_cast<FindTextToolbarController *>(instance)->EditModifyHdl(data); } void FindTextToolbarController ::EditModifyHdl(__attribute__ ((unused)) weld::ComboBox&) | |||
678 | { | |||
679 | // Clear SearchLabel when search string altered | |||
680 | #if HAVE_FEATURE_DESKTOP1 | |||
681 | SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::Empty); | |||
682 | #endif | |||
683 | ||||
684 | textfieldChanged(); | |||
685 | } | |||
686 | ||||
687 | void FindTextToolbarController::textfieldChanged() { | |||
688 | // enable or disable item DownSearch/UpSearch/FindAll of findbar | |||
689 | VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( getParent() ); | |||
690 | ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get()); | |||
691 | if ( pToolBox && m_pFindTextFieldControl ) | |||
692 | { | |||
693 | bool enableButtons = !m_pFindTextFieldControl->get_active_text().isEmpty(); | |||
694 | pToolBox->EnableItem(m_nDownSearchId, enableButtons); | |||
695 | pToolBox->EnableItem(m_nUpSearchId, enableButtons); | |||
696 | pToolBox->EnableItem(m_nFindAllId, enableButtons); | |||
697 | } | |||
698 | } | |||
699 | ||||
700 | class UpDownSearchToolboxController : public svt::ToolboxController, | |||
701 | public css::lang::XServiceInfo | |||
702 | { | |||
703 | public: | |||
704 | enum Type { UP, DOWN }; | |||
705 | ||||
706 | UpDownSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext, Type eType ); | |||
707 | ||||
708 | // XInterface | |||
709 | virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; | |||
710 | virtual void SAL_CALL acquire() throw () override; | |||
711 | virtual void SAL_CALL release() throw () override; | |||
712 | ||||
713 | // XServiceInfo | |||
714 | virtual OUString SAL_CALL getImplementationName() override; | |||
715 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; | |||
716 | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; | |||
717 | ||||
718 | // XComponent | |||
719 | virtual void SAL_CALL dispose() override; | |||
720 | ||||
721 | // XInitialization | |||
722 | virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; | |||
723 | ||||
724 | // XToolbarController | |||
725 | virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override; | |||
726 | ||||
727 | // XStatusListener | |||
728 | virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; | |||
729 | ||||
730 | private: | |||
731 | Type meType; | |||
732 | }; | |||
733 | ||||
734 | UpDownSearchToolboxController::UpDownSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext, Type eType ) | |||
735 | : svt::ToolboxController( rxContext, | |||
736 | css::uno::Reference< css::frame::XFrame >(), | |||
737 | (eType == UP) ? OUString( COMMAND_UPSEARCH ): OUString( COMMAND_DOWNSEARCH ) ), | |||
738 | meType( eType ) | |||
739 | { | |||
740 | } | |||
741 | ||||
742 | // XInterface | |||
743 | css::uno::Any SAL_CALL UpDownSearchToolboxController::queryInterface( const css::uno::Type& aType ) | |||
744 | { | |||
745 | css::uno::Any a = ToolboxController::queryInterface( aType ); | |||
746 | if ( a.hasValue() ) | |||
747 | return a; | |||
748 | ||||
749 | return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) ); | |||
750 | } | |||
751 | ||||
752 | void SAL_CALL UpDownSearchToolboxController::acquire() throw () | |||
753 | { | |||
754 | ToolboxController::acquire(); | |||
755 | } | |||
756 | ||||
757 | void SAL_CALL UpDownSearchToolboxController::release() throw () | |||
758 | { | |||
759 | ToolboxController::release(); | |||
760 | } | |||
761 | ||||
762 | // XServiceInfo | |||
763 | OUString SAL_CALL UpDownSearchToolboxController::getImplementationName() | |||
764 | { | |||
765 | return meType == UpDownSearchToolboxController::UP? | |||
766 | OUString( "com.sun.star.svx.UpSearchToolboxController" ) : | |||
767 | OUString( "com.sun.star.svx.DownSearchToolboxController" ); | |||
768 | } | |||
769 | ||||
770 | sal_Bool SAL_CALL UpDownSearchToolboxController::supportsService( const OUString& ServiceName ) | |||
771 | { | |||
772 | return cppu::supportsService(this, ServiceName); | |||
773 | } | |||
774 | ||||
775 | css::uno::Sequence< OUString > SAL_CALL UpDownSearchToolboxController::getSupportedServiceNames() | |||
776 | { | |||
777 | return { "com.sun.star.frame.ToolbarController" }; | |||
778 | } | |||
779 | ||||
780 | // XComponent | |||
781 | void SAL_CALL UpDownSearchToolboxController::dispose() | |||
782 | { | |||
783 | SolarMutexGuard aSolarMutexGuard; | |||
784 | ||||
785 | SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL); | |||
786 | ||||
787 | svt::ToolboxController::dispose(); | |||
788 | } | |||
789 | ||||
790 | // XInitialization | |||
791 | void SAL_CALL UpDownSearchToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) | |||
792 | { | |||
793 | svt::ToolboxController::initialize( aArguments ); | |||
794 | SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); | |||
795 | } | |||
796 | ||||
797 | // XToolbarController | |||
798 | void SAL_CALL UpDownSearchToolboxController::execute( sal_Int16 /*KeyModifier*/ ) | |||
799 | { | |||
800 | if ( m_bDisposed ) | |||
801 | throw css::lang::DisposedException(); | |||
802 | ||||
803 | VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( getParent() ); | |||
804 | ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get()); | |||
805 | ||||
806 | impl_executeSearch(m_xContext, m_xFrame, pToolBox, meType == UP ); | |||
807 | ||||
808 | css::frame::FeatureStateEvent aEvent; | |||
809 | aEvent.FeatureURL.Complete = "AppendSearchHistory"; | |||
810 | css::uno::Reference< css::frame::XStatusListener > xStatusListener = SearchToolbarControllersManager::createControllersManager().findController(m_xFrame, COMMAND_FINDTEXT); | |||
811 | if (xStatusListener.is()) | |||
812 | xStatusListener->statusChanged( aEvent ); | |||
813 | } | |||
814 | ||||
815 | // XStatusListener | |||
816 | void SAL_CALL UpDownSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ ) | |||
817 | { | |||
818 | } | |||
819 | ||||
820 | class MatchCaseToolboxController : public svt::ToolboxController, | |||
821 | public css::lang::XServiceInfo | |||
822 | { | |||
823 | public: | |||
824 | MatchCaseToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); | |||
825 | ||||
826 | // XInterface | |||
827 | virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; | |||
828 | virtual void SAL_CALL acquire() throw () override; | |||
829 | virtual void SAL_CALL release() throw () override; | |||
830 | ||||
831 | // XServiceInfo | |||
832 | virtual OUString SAL_CALL getImplementationName() override; | |||
833 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; | |||
834 | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; | |||
835 | ||||
836 | // XComponent | |||
837 | virtual void SAL_CALL dispose() override; | |||
838 | ||||
839 | // XInitialization | |||
840 | virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; | |||
841 | ||||
842 | // XToolbarController | |||
843 | virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override; | |||
844 | ||||
845 | // XStatusListener | |||
846 | virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; | |||
847 | ||||
848 | private: | |||
849 | VclPtr<CheckButtonItemWindow> m_xMatchCaseControl; | |||
850 | }; | |||
851 | ||||
852 | MatchCaseToolboxController::MatchCaseToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext ) | |||
853 | : svt::ToolboxController( rxContext, | |||
854 | css::uno::Reference< css::frame::XFrame >(), | |||
855 | COMMAND_MATCHCASE ) | |||
856 | , m_xMatchCaseControl(nullptr) | |||
857 | { | |||
858 | } | |||
859 | ||||
860 | // XInterface | |||
861 | css::uno::Any SAL_CALL MatchCaseToolboxController::queryInterface( const css::uno::Type& aType ) | |||
862 | { | |||
863 | css::uno::Any a = ToolboxController::queryInterface( aType ); | |||
864 | if ( a.hasValue() ) | |||
865 | return a; | |||
866 | ||||
867 | return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) ); | |||
868 | } | |||
869 | ||||
870 | void SAL_CALL MatchCaseToolboxController::acquire() throw () | |||
871 | { | |||
872 | ToolboxController::acquire(); | |||
873 | } | |||
874 | ||||
875 | void SAL_CALL MatchCaseToolboxController::release() throw () | |||
876 | { | |||
877 | ToolboxController::release(); | |||
878 | } | |||
879 | ||||
880 | // XServiceInfo | |||
881 | OUString SAL_CALL MatchCaseToolboxController::getImplementationName() | |||
882 | { | |||
883 | return "com.sun.star.svx.MatchCaseToolboxController"; | |||
884 | } | |||
885 | ||||
886 | sal_Bool SAL_CALL MatchCaseToolboxController::supportsService( const OUString& ServiceName ) | |||
887 | { | |||
888 | return cppu::supportsService(this, ServiceName); | |||
889 | } | |||
890 | ||||
891 | css::uno::Sequence< OUString > SAL_CALL MatchCaseToolboxController::getSupportedServiceNames() | |||
892 | { | |||
893 | return { "com.sun.star.frame.ToolbarController" }; | |||
894 | } | |||
895 | ||||
896 | // XComponent | |||
897 | void SAL_CALL MatchCaseToolboxController::dispose() | |||
898 | { | |||
899 | SolarMutexGuard aSolarMutexGuard; | |||
900 | ||||
901 | SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL); | |||
902 | ||||
903 | svt::ToolboxController::dispose(); | |||
904 | ||||
905 | m_xMatchCaseControl.disposeAndClear(); | |||
906 | } | |||
907 | ||||
908 | // XInitialization | |||
909 | void SAL_CALL MatchCaseToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) | |||
910 | { | |||
911 | svt::ToolboxController::initialize(aArguments); | |||
912 | ||||
913 | SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); | |||
914 | } | |||
915 | ||||
916 | css::uno::Reference< css::awt::XWindow > SAL_CALL MatchCaseToolboxController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& xParent ) | |||
917 | { | |||
918 | css::uno::Reference< css::awt::XWindow > xItemWindow; | |||
919 | ||||
920 | VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent ); | |||
921 | if ( pParent ) | |||
922 | { | |||
923 | ToolBox* pToolbar = static_cast<ToolBox*>(pParent.get()); | |||
924 | m_xMatchCaseControl = VclPtr<CheckButtonItemWindow>::Create(pToolbar, SvxResId(RID_SVXSTR_FINDBAR_MATCHCASEreinterpret_cast<char const *>("RID_SVXSTR_FINDBAR_MATCHCASE" "\004" u8"Match Case"))); | |||
925 | } | |||
926 | xItemWindow = VCLUnoHelper::GetInterface(m_xMatchCaseControl); | |||
927 | ||||
928 | return xItemWindow; | |||
929 | } | |||
930 | ||||
931 | // XStatusListener | |||
932 | void SAL_CALL MatchCaseToolboxController::statusChanged( const css::frame::FeatureStateEvent& ) | |||
933 | { | |||
934 | } | |||
935 | ||||
936 | class SearchFormattedToolboxController : public svt::ToolboxController, | |||
937 | public css::lang::XServiceInfo | |||
938 | { | |||
939 | public: | |||
940 | SearchFormattedToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); | |||
941 | ||||
942 | // XInterface | |||
943 | virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; | |||
944 | virtual void SAL_CALL acquire() throw () override; | |||
945 | virtual void SAL_CALL release() throw () override; | |||
946 | ||||
947 | // XServiceInfo | |||
948 | virtual OUString SAL_CALL getImplementationName() override; | |||
949 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; | |||
950 | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; | |||
951 | ||||
952 | // XComponent | |||
953 | virtual void SAL_CALL dispose() override; | |||
954 | ||||
955 | // XInitialization | |||
956 | virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; | |||
957 | ||||
958 | // XToolbarController | |||
959 | virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override; | |||
960 | ||||
961 | // XStatusListener | |||
962 | virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; | |||
963 | ||||
964 | private: | |||
965 | VclPtr<CheckButtonItemWindow> m_xSearchFormattedControl; | |||
966 | }; | |||
967 | ||||
968 | SearchFormattedToolboxController::SearchFormattedToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext ) | |||
969 | : svt::ToolboxController( rxContext, | |||
970 | css::uno::Reference< css::frame::XFrame >(), | |||
971 | COMMAND_SEARCHFORMATTED ) | |||
972 | , m_xSearchFormattedControl(nullptr) | |||
973 | { | |||
974 | } | |||
975 | ||||
976 | // XInterface | |||
977 | css::uno::Any SAL_CALL SearchFormattedToolboxController::queryInterface( const css::uno::Type& aType ) | |||
978 | { | |||
979 | css::uno::Any a = ToolboxController::queryInterface( aType ); | |||
980 | if ( a.hasValue() ) | |||
981 | return a; | |||
982 | ||||
983 | return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) ); | |||
984 | } | |||
985 | ||||
986 | void SAL_CALL SearchFormattedToolboxController::acquire() throw () | |||
987 | { | |||
988 | ToolboxController::acquire(); | |||
989 | } | |||
990 | ||||
991 | void SAL_CALL SearchFormattedToolboxController::release() throw () | |||
992 | { | |||
993 | ToolboxController::release(); | |||
994 | } | |||
995 | ||||
996 | // XServiceInfo | |||
997 | OUString SAL_CALL SearchFormattedToolboxController::getImplementationName() | |||
998 | { | |||
999 | return "com.sun.star.svx.SearchFormattedToolboxController"; | |||
1000 | } | |||
1001 | ||||
1002 | sal_Bool SAL_CALL SearchFormattedToolboxController::supportsService( const OUString& ServiceName ) | |||
1003 | { | |||
1004 | return cppu::supportsService(this, ServiceName); | |||
1005 | } | |||
1006 | ||||
1007 | css::uno::Sequence< OUString > SAL_CALL SearchFormattedToolboxController::getSupportedServiceNames() | |||
1008 | { | |||
1009 | return { "com.sun.star.frame.ToolbarController" }; | |||
1010 | } | |||
1011 | ||||
1012 | // XComponent | |||
1013 | void SAL_CALL SearchFormattedToolboxController::dispose() | |||
1014 | { | |||
1015 | SolarMutexGuard aSolarMutexGuard; | |||
1016 | ||||
1017 | SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL); | |||
1018 | ||||
1019 | svt::ToolboxController::dispose(); | |||
1020 | ||||
1021 | m_xSearchFormattedControl.disposeAndClear(); | |||
1022 | } | |||
1023 | ||||
1024 | // XInitialization | |||
1025 | void SAL_CALL SearchFormattedToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) | |||
1026 | { | |||
1027 | svt::ToolboxController::initialize(aArguments); | |||
1028 | ||||
1029 | SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); | |||
1030 | } | |||
1031 | ||||
1032 | css::uno::Reference< css::awt::XWindow > SAL_CALL SearchFormattedToolboxController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& xParent ) | |||
1033 | { | |||
1034 | css::uno::Reference< css::awt::XWindow > xItemWindow; | |||
1035 | ||||
1036 | VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent ); | |||
1037 | if ( pParent ) | |||
1038 | { | |||
1039 | ToolBox* pToolbar = static_cast<ToolBox*>(pParent.get()); | |||
1040 | m_xSearchFormattedControl = VclPtr<CheckButtonItemWindow>::Create(pToolbar, SvxResId(RID_SVXSTR_FINDBAR_SEARCHFORMATTEDreinterpret_cast<char const *>("RID_SVXSTR_FINDBAR_SEARCHFORMATTED" "\004" u8"Formatted Display"))); | |||
1041 | } | |||
1042 | xItemWindow = VCLUnoHelper::GetInterface(m_xSearchFormattedControl); | |||
1043 | ||||
1044 | return xItemWindow; | |||
1045 | } | |||
1046 | ||||
1047 | // XStatusListener | |||
1048 | void SAL_CALL SearchFormattedToolboxController::statusChanged( const css::frame::FeatureStateEvent& ) | |||
1049 | { | |||
1050 | } | |||
1051 | ||||
1052 | class FindAllToolboxController : public svt::ToolboxController, | |||
1053 | public css::lang::XServiceInfo | |||
1054 | { | |||
1055 | public: | |||
1056 | FindAllToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); | |||
1057 | ||||
1058 | // XInterface | |||
1059 | virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; | |||
1060 | virtual void SAL_CALL acquire() throw () override; | |||
1061 | virtual void SAL_CALL release() throw () override; | |||
1062 | ||||
1063 | // XServiceInfo | |||
1064 | virtual OUString SAL_CALL getImplementationName() override; | |||
1065 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; | |||
1066 | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; | |||
1067 | ||||
1068 | // XComponent | |||
1069 | virtual void SAL_CALL dispose() override; | |||
1070 | ||||
1071 | // XInitialization | |||
1072 | virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; | |||
1073 | ||||
1074 | // XToolbarController | |||
1075 | virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override; | |||
1076 | ||||
1077 | // XStatusListener | |||
1078 | virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; | |||
1079 | }; | |||
1080 | ||||
1081 | FindAllToolboxController::FindAllToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext ) | |||
1082 | : svt::ToolboxController( rxContext, | |||
1083 | css::uno::Reference< css::frame::XFrame >(), | |||
1084 | ".uno:FindAll" ) | |||
1085 | { | |||
1086 | } | |||
1087 | ||||
1088 | // XInterface | |||
1089 | css::uno::Any SAL_CALL FindAllToolboxController::queryInterface( const css::uno::Type& aType ) | |||
1090 | { | |||
1091 | css::uno::Any a = ToolboxController::queryInterface( aType ); | |||
1092 | if ( a.hasValue() ) | |||
1093 | return a; | |||
1094 | ||||
1095 | return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) ); | |||
1096 | } | |||
1097 | ||||
1098 | void SAL_CALL FindAllToolboxController::acquire() throw () | |||
1099 | { | |||
1100 | ToolboxController::acquire(); | |||
1101 | } | |||
1102 | ||||
1103 | void SAL_CALL FindAllToolboxController::release() throw () | |||
1104 | { | |||
1105 | ToolboxController::release(); | |||
1106 | } | |||
1107 | ||||
1108 | // XServiceInfo | |||
1109 | OUString SAL_CALL FindAllToolboxController::getImplementationName() | |||
1110 | { | |||
1111 | return "com.sun.star.svx.FindAllToolboxController"; | |||
1112 | } | |||
1113 | ||||
1114 | ||||
1115 | sal_Bool SAL_CALL FindAllToolboxController::supportsService( const OUString& ServiceName ) | |||
1116 | { | |||
1117 | return cppu::supportsService(this, ServiceName); | |||
1118 | } | |||
1119 | ||||
1120 | css::uno::Sequence< OUString > SAL_CALL FindAllToolboxController::getSupportedServiceNames() | |||
1121 | { | |||
1122 | return { "com.sun.star.frame.ToolbarController" }; | |||
1123 | } | |||
1124 | ||||
1125 | // XComponent | |||
1126 | void SAL_CALL FindAllToolboxController::dispose() | |||
1127 | { | |||
1128 | SolarMutexGuard aSolarMutexGuard; | |||
1129 | ||||
1130 | SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL); | |||
1131 | ||||
1132 | svt::ToolboxController::dispose(); | |||
1133 | } | |||
1134 | ||||
1135 | // XInitialization | |||
1136 | void SAL_CALL FindAllToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) | |||
1137 | { | |||
1138 | svt::ToolboxController::initialize( aArguments ); | |||
1139 | SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); | |||
1140 | } | |||
1141 | ||||
1142 | // XToolbarController | |||
1143 | void SAL_CALL FindAllToolboxController::execute( sal_Int16 /*KeyModifier*/ ) | |||
1144 | { | |||
1145 | if ( m_bDisposed ) | |||
1146 | throw css::lang::DisposedException(); | |||
1147 | ||||
1148 | VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( getParent() ); | |||
1149 | ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get()); | |||
1150 | ||||
1151 | impl_executeSearch(m_xContext, m_xFrame, pToolBox, false, true); | |||
1152 | } | |||
1153 | ||||
1154 | // XStatusListener | |||
1155 | void SAL_CALL FindAllToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ ) | |||
1156 | { | |||
1157 | } | |||
1158 | ||||
1159 | class ExitSearchToolboxController : public svt::ToolboxController, | |||
1160 | public css::lang::XServiceInfo | |||
1161 | { | |||
1162 | public: | |||
1163 | ExitSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); | |||
1164 | ||||
1165 | // XInterface | |||
1166 | virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; | |||
1167 | virtual void SAL_CALL acquire() throw () override; | |||
1168 | virtual void SAL_CALL release() throw () override; | |||
1169 | ||||
1170 | // XServiceInfo | |||
1171 | virtual OUString SAL_CALL getImplementationName() override; | |||
1172 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; | |||
1173 | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; | |||
1174 | ||||
1175 | // XComponent | |||
1176 | virtual void SAL_CALL dispose() override; | |||
1177 | ||||
1178 | // XInitialization | |||
1179 | virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; | |||
1180 | ||||
1181 | // XToolbarController | |||
1182 | virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override; | |||
1183 | ||||
1184 | // XStatusListener | |||
1185 | virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; | |||
1186 | }; | |||
1187 | ||||
1188 | ExitSearchToolboxController::ExitSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext ) | |||
1189 | : svt::ToolboxController( rxContext, | |||
1190 | css::uno::Reference< css::frame::XFrame >(), | |||
1191 | ".uno:ExitSearch" ) | |||
1192 | { | |||
1193 | } | |||
1194 | ||||
1195 | // XInterface | |||
1196 | css::uno::Any SAL_CALL ExitSearchToolboxController::queryInterface( const css::uno::Type& aType ) | |||
1197 | { | |||
1198 | css::uno::Any a = ToolboxController::queryInterface( aType ); | |||
1199 | if ( a.hasValue() ) | |||
1200 | return a; | |||
1201 | ||||
1202 | return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) ); | |||
1203 | } | |||
1204 | ||||
1205 | void SAL_CALL ExitSearchToolboxController::acquire() throw () | |||
1206 | { | |||
1207 | ToolboxController::acquire(); | |||
1208 | } | |||
1209 | ||||
1210 | void SAL_CALL ExitSearchToolboxController::release() throw () | |||
1211 | { | |||
1212 | ToolboxController::release(); | |||
1213 | } | |||
1214 | ||||
1215 | // XServiceInfo | |||
1216 | OUString SAL_CALL ExitSearchToolboxController::getImplementationName() | |||
1217 | { | |||
1218 | return "com.sun.star.svx.ExitFindbarToolboxController"; | |||
1219 | } | |||
1220 | ||||
1221 | ||||
1222 | sal_Bool SAL_CALL ExitSearchToolboxController::supportsService( const OUString& ServiceName ) | |||
1223 | { | |||
1224 | return cppu::supportsService(this, ServiceName); | |||
1225 | } | |||
1226 | ||||
1227 | css::uno::Sequence< OUString > SAL_CALL ExitSearchToolboxController::getSupportedServiceNames() | |||
1228 | { | |||
1229 | return { "com.sun.star.frame.ToolbarController" }; | |||
1230 | } | |||
1231 | ||||
1232 | // XComponent | |||
1233 | void SAL_CALL ExitSearchToolboxController::dispose() | |||
1234 | { | |||
1235 | SolarMutexGuard aSolarMutexGuard; | |||
1236 | ||||
1237 | SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL); | |||
1238 | ||||
1239 | svt::ToolboxController::dispose(); | |||
1240 | } | |||
1241 | ||||
1242 | // XInitialization | |||
1243 | void SAL_CALL ExitSearchToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) | |||
1244 | { | |||
1245 | svt::ToolboxController::initialize( aArguments ); | |||
1246 | SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); | |||
1247 | } | |||
1248 | ||||
1249 | // XToolbarController | |||
1250 | void SAL_CALL ExitSearchToolboxController::execute( sal_Int16 /*KeyModifier*/ ) | |||
1251 | { | |||
1252 | vcl::Window *pFocusWindow = Application::GetFocusWindow(); | |||
1253 | if ( pFocusWindow ) | |||
1254 | pFocusWindow->GrabFocusToDocument(); | |||
1255 | ||||
1256 | // hide the findbar | |||
1257 | css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY); | |||
1258 | if (xPropSet.is()) | |||
1259 | { | |||
1260 | css::uno::Reference< css::frame::XLayoutManager > xLayoutManager; | |||
1261 | css::uno::Any aValue = xPropSet->getPropertyValue("LayoutManager"); | |||
1262 | aValue >>= xLayoutManager; | |||
1263 | if (xLayoutManager.is()) | |||
1264 | { | |||
1265 | const OUString sResourceURL( "private:resource/toolbar/findbar" ); | |||
1266 | xLayoutManager->hideElement( sResourceURL ); | |||
1267 | xLayoutManager->destroyElement( sResourceURL ); | |||
1268 | } | |||
1269 | } | |||
1270 | } | |||
1271 | ||||
1272 | // XStatusListener | |||
1273 | void SAL_CALL ExitSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ ) | |||
1274 | { | |||
1275 | } | |||
1276 | ||||
1277 | class SearchLabelToolboxController : public svt::ToolboxController, | |||
1278 | public css::lang::XServiceInfo | |||
1279 | { | |||
1280 | public: | |||
1281 | SearchLabelToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); | |||
1282 | ||||
1283 | // XInterface | |||
1284 | virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; | |||
1285 | virtual void SAL_CALL acquire() throw () override; | |||
1286 | virtual void SAL_CALL release() throw () override; | |||
1287 | ||||
1288 | // XServiceInfo | |||
1289 | virtual OUString SAL_CALL getImplementationName() override; | |||
1290 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; | |||
1291 | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; | |||
1292 | ||||
1293 | // XComponent | |||
1294 | virtual void SAL_CALL dispose() override; | |||
1295 | ||||
1296 | // XInitialization | |||
1297 | virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; | |||
1298 | ||||
1299 | // XToolbarController | |||
1300 | virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override; | |||
1301 | ||||
1302 | // XStatusListener | |||
1303 | virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; | |||
1304 | ||||
1305 | private: | |||
1306 | VclPtr<LabelItemWindow> m_xSL; | |||
1307 | }; | |||
1308 | ||||
1309 | SearchLabelToolboxController::SearchLabelToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext ) | |||
1310 | : svt::ToolboxController( rxContext, | |||
1311 | css::uno::Reference< css::frame::XFrame >(), | |||
1312 | ".uno:SearchLabel" ) | |||
1313 | { | |||
1314 | } | |||
1315 | ||||
1316 | // XInterface | |||
1317 | css::uno::Any SAL_CALL SearchLabelToolboxController::queryInterface( const css::uno::Type& aType ) | |||
1318 | { | |||
1319 | css::uno::Any a = ToolboxController::queryInterface( aType ); | |||
1320 | if ( a.hasValue() ) | |||
1321 | return a; | |||
1322 | ||||
1323 | return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) ); | |||
1324 | } | |||
1325 | ||||
1326 | void SAL_CALL SearchLabelToolboxController::acquire() throw () | |||
1327 | { | |||
1328 | ToolboxController::acquire(); | |||
1329 | } | |||
1330 | ||||
1331 | void SAL_CALL SearchLabelToolboxController::release() throw () | |||
1332 | { | |||
1333 | ToolboxController::release(); | |||
1334 | } | |||
1335 | ||||
1336 | // XServiceInfo | |||
1337 | OUString SAL_CALL SearchLabelToolboxController::getImplementationName() | |||
1338 | { | |||
1339 | return "com.sun.star.svx.SearchLabelToolboxController"; | |||
1340 | } | |||
1341 | ||||
1342 | ||||
1343 | sal_Bool SAL_CALL SearchLabelToolboxController::supportsService( const OUString& ServiceName ) | |||
1344 | { | |||
1345 | return cppu::supportsService(this, ServiceName); | |||
1346 | } | |||
1347 | ||||
1348 | css::uno::Sequence< OUString > SAL_CALL SearchLabelToolboxController::getSupportedServiceNames() | |||
1349 | { | |||
1350 | return { "com.sun.star.frame.ToolbarController" }; | |||
1351 | } | |||
1352 | ||||
1353 | // XComponent | |||
1354 | void SAL_CALL SearchLabelToolboxController::dispose() | |||
1355 | { | |||
1356 | SolarMutexGuard aSolarMutexGuard; | |||
1357 | ||||
1358 | SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL); | |||
1359 | ||||
1360 | svt::ToolboxController::dispose(); | |||
1361 | m_xSL.disposeAndClear(); | |||
| ||||
1362 | } | |||
1363 | ||||
1364 | // XInitialization | |||
1365 | void SAL_CALL SearchLabelToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) | |||
1366 | { | |||
1367 | svt::ToolboxController::initialize( aArguments ); | |||
1368 | SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); | |||
1369 | } | |||
1370 | ||||
1371 | // XStatusListener | |||
1372 | void SAL_CALL SearchLabelToolboxController::statusChanged( const css::frame::FeatureStateEvent& ) | |||
1373 | { | |||
1374 | if (m_xSL) | |||
1375 | { | |||
1376 | OUString aStr = SvxSearchDialogWrapper::GetSearchLabel(); | |||
1377 | m_xSL->set_label(aStr); | |||
1378 | m_xSL->SetOptimalSize(); | |||
1379 | Size aSize(m_xSL->GetSizePixel()); | |||
1380 | long nWidth = !aStr.isEmpty() ? aSize.getWidth() : 16; | |||
1381 | m_xSL->SetSizePixel(Size(nWidth, aSize.Height())); | |||
1382 | } | |||
1383 | } | |||
1384 | ||||
1385 | css::uno::Reference< css::awt::XWindow > SAL_CALL SearchLabelToolboxController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) | |||
1386 | { | |||
1387 | ToolBox* pToolBox = nullptr; | |||
1388 | sal_uInt16 nId = 0; | |||
1389 | if (getToolboxId(nId, &pToolBox)) | |||
1390 | pToolBox->SetItemWindowNonInteractive(nId, true); | |||
1391 | ||||
1392 | m_xSL = VclPtr<LabelItemWindow>::Create(VCLUnoHelper::GetWindow(Parent), ""); | |||
1393 | m_xSL->SetSizePixel(Size(16, m_xSL->GetSizePixel().Height())); | |||
1394 | return VCLUnoHelper::GetInterface(m_xSL); | |||
1395 | } | |||
1396 | ||||
1397 | // protocol handler for "vnd.sun.star.findbar:*" URLs | |||
1398 | // The dispatch object will be used for shortcut commands for findbar | |||
1399 | class FindbarDispatcher : public css::lang::XServiceInfo, | |||
1400 | public css::lang::XInitialization, | |||
1401 | public css::frame::XDispatchProvider, | |||
1402 | public css::frame::XDispatch, | |||
1403 | public ::cppu::OWeakObject | |||
1404 | { | |||
1405 | public: | |||
1406 | ||||
1407 | FindbarDispatcher(); | |||
1408 | virtual ~FindbarDispatcher() override; | |||
1409 | ||||
1410 | // XInterface | |||
1411 | virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; | |||
1412 | virtual void SAL_CALL acquire() throw() override; | |||
1413 | virtual void SAL_CALL release() throw() override; | |||
1414 | ||||
1415 | // XServiceInfo | |||
1416 | virtual OUString SAL_CALL getImplementationName() override; | |||
1417 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; | |||
1418 | virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; | |||
1419 | ||||
1420 | // XInitialization | |||
1421 | virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; | |||
1422 | ||||
1423 | // XDispatchProvider | |||
1424 | virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch( const css::util::URL& aURL, const OUString& sTargetFrameName , sal_Int32 nSearchFlags ) override; | |||
1425 | virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptions ) override; | |||
1426 | ||||
1427 | // XDispatch | |||
1428 | virtual void SAL_CALL dispatch( const css::util::URL& aURL, const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) override; | |||
1429 | virtual void SAL_CALL addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xListener, const css::util::URL& aURL ) override; | |||
1430 | virtual void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xListener, const css::util::URL& aURL ) override; | |||
1431 | ||||
1432 | private: | |||
1433 | ||||
1434 | css::uno::Reference< css::frame::XFrame > m_xFrame; | |||
1435 | ||||
1436 | }; | |||
1437 | ||||
1438 | FindbarDispatcher::FindbarDispatcher() | |||
1439 | { | |||
1440 | } | |||
1441 | ||||
1442 | FindbarDispatcher::~FindbarDispatcher() | |||
1443 | { | |||
1444 | m_xFrame = nullptr; | |||
1445 | } | |||
1446 | ||||
1447 | // XInterface | |||
1448 | css::uno::Any SAL_CALL FindbarDispatcher::queryInterface( const css::uno::Type& aType ) | |||
1449 | { | |||
1450 | css::uno::Any aReturn( ::cppu::queryInterface( aType, | |||
1451 | static_cast< css::lang::XServiceInfo* >(this), | |||
1452 | static_cast< css::lang::XInitialization* >(this), | |||
1453 | static_cast< css::frame::XDispatchProvider* >(this), | |||
1454 | static_cast< css::frame::XDispatch* >(this)) ); | |||
1455 | ||||
1456 | if ( aReturn.hasValue() ) | |||
1457 | return aReturn; | |||
1458 | ||||
1459 | return OWeakObject::queryInterface( aType ); | |||
1460 | } | |||
1461 | ||||
1462 | void SAL_CALL FindbarDispatcher::acquire() throw() | |||
1463 | { | |||
1464 | OWeakObject::acquire(); | |||
1465 | } | |||
1466 | ||||
1467 | void SAL_CALL FindbarDispatcher::release() throw() | |||
1468 | { | |||
1469 | OWeakObject::release(); | |||
1470 | } | |||
1471 | ||||
1472 | // XServiceInfo | |||
1473 | OUString SAL_CALL FindbarDispatcher::getImplementationName() | |||
1474 | { | |||
1475 | return "com.sun.star.comp.svx.Impl.FindbarDispatcher"; | |||
1476 | } | |||
1477 | ||||
1478 | sal_Bool SAL_CALL FindbarDispatcher::supportsService( const OUString& ServiceName ) | |||
1479 | { | |||
1480 | return cppu::supportsService(this, ServiceName); | |||
1481 | } | |||
1482 | ||||
1483 | css::uno::Sequence< OUString > SAL_CALL FindbarDispatcher::getSupportedServiceNames() | |||
1484 | { | |||
1485 | return { "com.sun.star.comp.svx.FindbarDispatcher", "com.sun.star.frame.ProtocolHandler" }; | |||
1486 | } | |||
1487 | ||||
1488 | // XInitialization | |||
1489 | void SAL_CALL FindbarDispatcher::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) | |||
1490 | { | |||
1491 | if ( aArguments.hasElements() ) | |||
1492 | aArguments[0] >>= m_xFrame; | |||
1493 | } | |||
1494 | ||||
1495 | // XDispatchProvider | |||
1496 | css::uno::Reference< css::frame::XDispatch > SAL_CALL FindbarDispatcher::queryDispatch( const css::util::URL& aURL, const OUString& /*sTargetFrameName*/, sal_Int32 /*nSearchFlags*/ ) | |||
1497 | { | |||
1498 | css::uno::Reference< css::frame::XDispatch > xDispatch; | |||
1499 | ||||
1500 | if ( aURL.Protocol == "vnd.sun.star.findbar:" ) | |||
1501 | xDispatch = this; | |||
1502 | ||||
1503 | return xDispatch; | |||
1504 | } | |||
1505 | ||||
1506 | css::uno::Sequence < css::uno::Reference< css::frame::XDispatch > > SAL_CALL FindbarDispatcher::queryDispatches( const css::uno::Sequence < css::frame::DispatchDescriptor >& seqDescripts ) | |||
1507 | { | |||
1508 | sal_Int32 nCount = seqDescripts.getLength(); | |||
1509 | css::uno::Sequence < css::uno::Reference < XDispatch > > lDispatcher( nCount ); | |||
1510 | ||||
1511 | std::transform(seqDescripts.begin(), seqDescripts.end(), lDispatcher.begin(), | |||
1512 | [this](const css::frame::DispatchDescriptor& rDescript) -> css::uno::Reference < XDispatch > { | |||
1513 | return queryDispatch( rDescript.FeatureURL, rDescript.FrameName, rDescript.SearchFlags ); }); | |||
1514 | ||||
1515 | return lDispatcher; | |||
1516 | } | |||
1517 | ||||
1518 | // XDispatch | |||
1519 | void SAL_CALL FindbarDispatcher::dispatch( const css::util::URL& aURL, const css::uno::Sequence < css::beans::PropertyValue >& /*lArgs*/ ) | |||
1520 | { | |||
1521 | //vnd.sun.star.findbar:FocusToFindbar - set cursor to the FindTextFieldControl of the findbar | |||
1522 | if ( aURL.Path != "FocusToFindbar" ) | |||
1523 | return; | |||
1524 | ||||
1525 | css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY); | |||
1526 | if(!xPropSet.is()) | |||
1527 | return; | |||
1528 | ||||
1529 | css::uno::Reference< css::frame::XLayoutManager > xLayoutManager; | |||
1530 | css::uno::Any aValue = xPropSet->getPropertyValue("LayoutManager"); | |||
1531 | aValue >>= xLayoutManager; | |||
1532 | if (!xLayoutManager.is()) | |||
1533 | return; | |||
1534 | ||||
1535 | const OUString sResourceURL( "private:resource/toolbar/findbar" ); | |||
1536 | css::uno::Reference< css::ui::XUIElement > xUIElement = xLayoutManager->getElement(sResourceURL); | |||
1537 | if (!xUIElement.is()) | |||
1538 | { | |||
1539 | // show the findbar if necessary | |||
1540 | xLayoutManager->createElement( sResourceURL ); | |||
1541 | xLayoutManager->showElement( sResourceURL ); | |||
1542 | xUIElement = xLayoutManager->getElement( sResourceURL ); | |||
1543 | if ( !xUIElement.is() ) | |||
1544 | return; | |||
1545 | } | |||
1546 | ||||
1547 | css::uno::Reference< css::awt::XWindow > xWindow(xUIElement->getRealInterface(), css::uno::UNO_QUERY); | |||
1548 | VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow ); | |||
1549 | ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get()); | |||
1550 | pToolBox->set_id("FindBar"); | |||
1551 | if ( !pToolBox ) | |||
1552 | return; | |||
1553 | ||||
1554 | ToolBox::ImplToolItems::size_type nItemCount = pToolBox->GetItemCount(); | |||
1555 | for ( ToolBox::ImplToolItems::size_type i=0; i<nItemCount; ++i ) | |||
1556 | { | |||
1557 | sal_uInt16 id = pToolBox->GetItemId(i); | |||
1558 | OUString sItemCommand = pToolBox->GetItemCommand(id); | |||
1559 | if ( sItemCommand == COMMAND_FINDTEXT ) | |||
1560 | { | |||
1561 | vcl::Window* pItemWin = pToolBox->GetItemWindow( id ); | |||
1562 | if ( pItemWin ) | |||
1563 | { | |||
1564 | SolarMutexGuard aSolarMutexGuard; | |||
1565 | FindTextFieldControl* pFindTextFieldControl = dynamic_cast<FindTextFieldControl*>(pItemWin); | |||
1566 | if ( pFindTextFieldControl ) | |||
1567 | pFindTextFieldControl->SetTextToSelected_Impl(); | |||
1568 | pItemWin->GrabFocus(); | |||
1569 | return; | |||
1570 | } | |||
1571 | } | |||
1572 | } | |||
1573 | } | |||
1574 | ||||
1575 | void SAL_CALL FindbarDispatcher::addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xControl*/, const css::util::URL& /*aURL*/ ) | |||
1576 | { | |||
1577 | } | |||
1578 | ||||
1579 | void SAL_CALL FindbarDispatcher::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xControl*/, const css::util::URL& /*aURL*/ ) | |||
1580 | { | |||
1581 | } | |||
1582 | ||||
1583 | } | |||
1584 | ||||
1585 | extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface * | |||
1586 | com_sun_star_svx_FindTextToolboxController_get_implementation( | |||
1587 | css::uno::XComponentContext *context, | |||
1588 | css::uno::Sequence<css::uno::Any> const &) | |||
1589 | { | |||
1590 | return cppu::acquire(new FindTextToolbarController(context)); | |||
1591 | } | |||
1592 | ||||
1593 | extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface * | |||
1594 | com_sun_star_svx_ExitFindbarToolboxController_get_implementation( | |||
1595 | css::uno::XComponentContext *context, | |||
1596 | css::uno::Sequence<css::uno::Any> const &) | |||
1597 | { | |||
1598 | return cppu::acquire(new ExitSearchToolboxController(context)); | |||
1599 | } | |||
1600 | ||||
1601 | extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface * | |||
1602 | com_sun_star_svx_UpSearchToolboxController_get_implementation( | |||
1603 | css::uno::XComponentContext *context, | |||
1604 | css::uno::Sequence<css::uno::Any> const &) | |||
1605 | { | |||
1606 | return cppu::acquire(new UpDownSearchToolboxController(context, UpDownSearchToolboxController::UP)); | |||
1607 | } | |||
1608 | ||||
1609 | extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface * | |||
1610 | com_sun_star_svx_DownSearchToolboxController_get_implementation( | |||
1611 | css::uno::XComponentContext *context, | |||
1612 | css::uno::Sequence<css::uno::Any> const &) | |||
1613 | { | |||
1614 | return cppu::acquire(new UpDownSearchToolboxController(context, UpDownSearchToolboxController::DOWN)); | |||
1615 | } | |||
1616 | ||||
1617 | extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface * | |||
1618 | com_sun_star_svx_MatchCaseToolboxController_get_implementation( | |||
1619 | css::uno::XComponentContext *context, | |||
1620 | css::uno::Sequence<css::uno::Any> const &) | |||
1621 | { | |||
1622 | return cppu::acquire(new MatchCaseToolboxController(context)); | |||
1623 | } | |||
1624 | ||||
1625 | extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface * | |||
1626 | com_sun_star_svx_SearchFormattedToolboxController_get_implementation( | |||
1627 | css::uno::XComponentContext *context, | |||
1628 | css::uno::Sequence<css::uno::Any> const &) | |||
1629 | { | |||
1630 | return cppu::acquire(new SearchFormattedToolboxController(context)); | |||
1631 | } | |||
1632 | ||||
1633 | extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface * | |||
1634 | com_sun_star_svx_FindAllToolboxController_get_implementation( | |||
1635 | css::uno::XComponentContext *context, | |||
1636 | css::uno::Sequence<css::uno::Any> const &) | |||
1637 | { | |||
1638 | return cppu::acquire(new FindAllToolboxController(context)); | |||
1639 | } | |||
1640 | ||||
1641 | extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface * | |||
1642 | com_sun_star_svx_SearchLabelToolboxController_get_implementation( | |||
1643 | css::uno::XComponentContext *context, | |||
1644 | css::uno::Sequence<css::uno::Any> const &) | |||
1645 | { | |||
1646 | return cppu::acquire(new SearchLabelToolboxController(context)); | |||
1647 | } | |||
1648 | ||||
1649 | extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface * | |||
1650 | com_sun_star_comp_svx_Impl_FindbarDispatcher_get_implementation( | |||
1651 | SAL_UNUSED_PARAMETER__attribute__ ((unused)) css::uno::XComponentContext *, | |||
1652 | css::uno::Sequence<css::uno::Any> const &) | |||
1653 | { | |||
1654 | return cppu::acquire(new FindbarDispatcher); | |||
1655 | } | |||
1656 | ||||
1657 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
5 | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | * contributor license agreements. See the NOTICE file distributed |
13 | * with this work for additional information regarding copyright |
14 | * ownership. The ASF licenses this file to you under the Apache |
15 | * License, Version 2.0 (the "License"); you may not use this file |
16 | * except in compliance with the License. You may obtain a copy of |
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | */ |
19 | |
20 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||||||||
2 | /* | ||||||||
3 | * This file is part of the LibreOffice project. | ||||||||
4 | * | ||||||||
5 | * This Source Code Form is subject to the terms of the Mozilla Public | ||||||||
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||||||
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||||||
8 | * | ||||||||
9 | * This file incorporates work covered by the following license notice: | ||||||||
10 | * | ||||||||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | ||||||||
12 | * contributor license agreements. See the NOTICE file distributed | ||||||||
13 | * with this work for additional information regarding copyright | ||||||||
14 | * ownership. The ASF licenses this file to you under the Apache | ||||||||
15 | * License, Version 2.0 (the "License"); you may not use this file | ||||||||
16 | * except in compliance with the License. You may obtain a copy of | ||||||||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | ||||||||
18 | */ | ||||||||
19 | |||||||||
20 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||
22 | |||||||||
23 | #include "sal/config.h" | ||||||||
24 | |||||||||
25 | #include <cassert> | ||||||||
26 | #include <cstddef> | ||||||||
27 | #include <functional> | ||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
29 | #include <type_traits> | ||||||||
30 | #endif | ||||||||
31 | |||||||||
32 | #include "sal/types.h" | ||||||||
33 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
48 | /** Constructor... | ||||||||
49 | */ | ||||||||
50 | Reference() | ||||||||
51 | : m_pBody (NULL__null) | ||||||||
52 | {} | ||||||||
53 | |||||||||
54 | |||||||||
55 | /** Constructor... | ||||||||
56 | */ | ||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||
58 | : m_pBody (pBody) | ||||||||
59 | { | ||||||||
60 | } | ||||||||
61 | |||||||||
62 | /** Constructor... | ||||||||
63 | */ | ||||||||
64 | Reference (reference_type * pBody) | ||||||||
65 | : m_pBody (pBody) | ||||||||
66 | { | ||||||||
67 | if (m_pBody) | ||||||||
68 | m_pBody->acquire(); | ||||||||
69 | } | ||||||||
70 | |||||||||
71 | /** Copy constructor... | ||||||||
72 | */ | ||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||
75 | { | ||||||||
76 | if (m_pBody) | ||||||||
77 | m_pBody->acquire(); | ||||||||
78 | } | ||||||||
79 | |||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
81 | /** Move constructor... | ||||||||
82 | */ | ||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||
85 | { | ||||||||
86 | handle.m_pBody = nullptr; | ||||||||
87 | } | ||||||||
88 | #endif | ||||||||
89 | |||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||
92 | |||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||
94 | |||||||||
95 | @param rRef another reference | ||||||||
96 | */ | ||||||||
97 | template< class derived_type > | ||||||||
98 | inline Reference( | ||||||||
99 | const Reference< derived_type > & rRef, | ||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||
101 | : m_pBody (rRef.get()) | ||||||||
102 | { | ||||||||
103 | if (m_pBody) | ||||||||
104 | m_pBody->acquire(); | ||||||||
105 | } | ||||||||
106 | #endif | ||||||||
107 | |||||||||
108 | /** Destructor... | ||||||||
109 | */ | ||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||
111 | { | ||||||||
112 | if (m_pBody) | ||||||||
113 | m_pBody->release(); | ||||||||
114 | } | ||||||||
115 | |||||||||
116 | /** Set... | ||||||||
117 | Similar to assignment. | ||||||||
118 | */ | ||||||||
119 | Reference<reference_type> & | ||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||
121 | { | ||||||||
122 | if (pBody) | ||||||||
123 | pBody->acquire(); | ||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||
125 | m_pBody = pBody; | ||||||||
126 | if (pOld) | ||||||||
127 | pOld->release(); | ||||||||
128 | return *this; | ||||||||
129 | } | ||||||||
130 | |||||||||
131 | /** Assignment. | ||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||
133 | bind it to the body represented by the handle. | ||||||||
134 | */ | ||||||||
135 | Reference<reference_type> & | ||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||
137 | { | ||||||||
138 | return set( handle.m_pBody ); | ||||||||
139 | } | ||||||||
140 | |||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
142 | /** Assignment. | ||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||
144 | * bind it to the body represented by the handle, and | ||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||
146 | */ | ||||||||
147 | Reference<reference_type> & | ||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||
149 | { | ||||||||
150 | // self-movement guts ourself | ||||||||
151 | if (m_pBody) | ||||||||
152 | m_pBody->release(); | ||||||||
153 | m_pBody = handle.m_pBody; | ||||||||
154 | handle.m_pBody = nullptr; | ||||||||
155 | return *this; | ||||||||
156 | } | ||||||||
157 | #endif | ||||||||
158 | |||||||||
159 | /** Assignment... | ||||||||
160 | */ | ||||||||
161 | Reference<reference_type> & | ||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||
163 | { | ||||||||
164 | return set( pBody ); | ||||||||
165 | } | ||||||||
166 | |||||||||
167 | /** Unbind the body from this handle. | ||||||||
168 | Note that for a handle representing a large body, | ||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||
171 | since in the second case two large objects exist in memory | ||||||||
172 | (the old body and the new body). | ||||||||
173 | */ | ||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||
175 | { | ||||||||
176 | if (m_pBody
| ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
| |||||||||
193 | } | ||||||||
194 | |||||||||
195 | |||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||
197 | */ | ||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||
199 | { | ||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||
201 | return m_pBody; | ||||||||
202 | } | ||||||||
203 | |||||||||
204 | |||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||
206 | */ | ||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||
208 | { | ||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||
210 | return *m_pBody; | ||||||||
211 | } | ||||||||
212 | |||||||||
213 | |||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||
215 | */ | ||||||||
216 | bool SAL_CALL is() const | ||||||||
217 | { | ||||||||
218 | return (m_pBody != NULL__null); | ||||||||
219 | } | ||||||||
220 | |||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||
223 | */ | ||||||||
224 | explicit operator bool() const | ||||||||
225 | { | ||||||||
226 | return is(); | ||||||||
227 | } | ||||||||
228 | #endif | ||||||||
229 | |||||||||
230 | /** Returns True if this points to pBody. | ||||||||
231 | */ | ||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||
233 | { | ||||||||
234 | return (m_pBody == pBody); | ||||||||
235 | } | ||||||||
236 | |||||||||
237 | |||||||||
238 | /** Returns True if handle points to the same body. | ||||||||
239 | */ | ||||||||
240 | bool | ||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||
242 | { | ||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | |||||||||
247 | /** Needed to place References into STL collection. | ||||||||
248 | */ | ||||||||
249 | bool | ||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||
251 | { | ||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||
253 | } | ||||||||
254 | |||||||||
255 | |||||||||
256 | /** Needed to place References into STL collection. | ||||||||
257 | */ | ||||||||
258 | bool | ||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||
260 | { | ||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||
262 | } | ||||||||
263 | |||||||||
264 | |||||||||
265 | /** Needed to place References into STL collection. | ||||||||
266 | */ | ||||||||
267 | bool | ||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||
269 | { | ||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||
271 | } | ||||||||
272 | }; | ||||||||
273 | |||||||||
274 | } // namespace rtl | ||||||||
275 | |||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
277 | namespace std | ||||||||
278 | { | ||||||||
279 | |||||||||
280 | /// @cond INTERNAL | ||||||||
281 | /** | ||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||
283 | |||||||||
284 | @since LibreOffice 6.3 | ||||||||
285 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||
288 | { | ||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||
290 | { return std::size_t(s.get()); } | ||||||||
291 | }; | ||||||||
292 | /// @endcond | ||||||||
293 | |||||||||
294 | } | ||||||||
295 | |||||||||
296 | #endif | ||||||||
297 | |||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||
299 | |||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
5 | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | * contributor license agreements. See the NOTICE file distributed |
13 | * with this work for additional information regarding copyright |
14 | * ownership. The ASF licenses this file to you under the Apache |
15 | * License, Version 2.0 (the "License"); you may not use this file |
16 | * except in compliance with the License. You may obtain a copy of |
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | */ |
19 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |