/src/libreoffice/sd/source/ui/inc/unosrch.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <memory> |
23 | | #include <com/sun/star/util/XReplaceable.hpp> |
24 | | #include <com/sun/star/util/XReplaceDescriptor.hpp> |
25 | | |
26 | | #include <comphelper/servicehelper.hxx> |
27 | | #include <cppuhelper/implbase.hxx> |
28 | | #include <editeng/editdata.hxx> |
29 | | |
30 | | namespace com::sun::star::drawing { class XDrawPage; } |
31 | | namespace com::sun::star::drawing { class XShape; } |
32 | | namespace com::sun::star::text { class XTextRange; } |
33 | | |
34 | | class SvxItemPropertySet; |
35 | | class SdUnoSearchReplaceDescriptor; |
36 | | |
37 | | /** this class implements a search or replace operation on a given page or a given sdrobj */ |
38 | | class SdUnoSearchReplaceShape : public css::util::XReplaceable |
39 | | { |
40 | | css::drawing::XDrawPage* mpPage; |
41 | | |
42 | | protected: |
43 | | css::uno::Reference< css::text::XTextRange > Search( const css::uno::Reference< css::text::XTextRange >& xText, SdUnoSearchReplaceDescriptor* pDescr ); |
44 | | bool Search( const OUString& rText, sal_Int32& nStartPos, sal_Int32& nEndPos, SdUnoSearchReplaceDescriptor* pDescr ) noexcept; |
45 | | static ESelection GetSelection( const css::uno::Reference< css::text::XTextRange >& xTextRange ) noexcept; |
46 | | static css::uno::Reference< css::drawing::XShape > GetShape( const css::uno::Reference< css::text::XTextRange >& xTextRange ) noexcept; |
47 | | css::uno::Reference< css::drawing::XShape > GetNextShape( const css::uno::Reference< css::container::XIndexAccess >& xShapes, const css::uno::Reference< css::drawing::XShape >& xCurrentShape ) noexcept; |
48 | | css::uno::Reference< css::drawing::XShape > GetCurrentShape() const noexcept; |
49 | | |
50 | | public: |
51 | | // danger, this c'tor is only usable if the given shape or page is derived |
52 | | // from this class!!! |
53 | | SdUnoSearchReplaceShape( css::drawing::XDrawPage* xPage ) noexcept; |
54 | | virtual ~SdUnoSearchReplaceShape() noexcept; |
55 | | |
56 | | // XReplaceable |
57 | | virtual css::uno::Reference< css::util::XReplaceDescriptor > SAL_CALL createReplaceDescriptor( ) override; |
58 | | virtual sal_Int32 SAL_CALL replaceAll( const css::uno::Reference< css::util::XSearchDescriptor >& xDesc ) override; |
59 | | |
60 | | // XSearchable |
61 | | virtual css::uno::Reference< css::util::XSearchDescriptor > SAL_CALL createSearchDescriptor( ) override; |
62 | | virtual css::uno::Reference< css::container::XIndexAccess > SAL_CALL findAll( const css::uno::Reference< css::util::XSearchDescriptor >& xDesc ) override; |
63 | | virtual css::uno::Reference< css::uno::XInterface > SAL_CALL findFirst( const css::uno::Reference< css::util::XSearchDescriptor >& xDesc ) override; |
64 | | virtual css::uno::Reference< css::uno::XInterface > SAL_CALL findNext( const css::uno::Reference< css::uno::XInterface >& xStartAt, const css::uno::Reference< css::util::XSearchDescriptor >& xDesc ) override; |
65 | | }; |
66 | | |
67 | | /* ================================================================= */ |
68 | | |
69 | | /** this class holds the parameters and status of a search or replace operation performed |
70 | | by class SdUnoSearchReplaceShape */ |
71 | | |
72 | | class SdUnoSearchReplaceDescriptor final : public ::cppu::WeakImplHelper< css::util::XReplaceDescriptor > // public css::util::XSearchDescriptor, css::beans::XPropertySet |
73 | | { |
74 | | std::unique_ptr<SvxItemPropertySet> mpPropSet; |
75 | | |
76 | | bool mbBackwards; |
77 | | bool mbCaseSensitive; |
78 | | bool mbWords; |
79 | | |
80 | | OUString maSearchStr; |
81 | | OUString maReplaceStr; |
82 | | |
83 | | public: |
84 | | /// @throws css::uno::RuntimeException |
85 | | SdUnoSearchReplaceDescriptor(); |
86 | | virtual ~SdUnoSearchReplaceDescriptor() noexcept override; |
87 | | |
88 | 0 | bool IsCaseSensitive() const { return mbCaseSensitive; } |
89 | 0 | bool IsWords() const { return mbWords; } |
90 | | |
91 | | // XSearchDescriptor |
92 | | virtual OUString SAL_CALL getSearchString( ) override; |
93 | | virtual void SAL_CALL setSearchString( const OUString& aString ) override; |
94 | | |
95 | | // XReplaceDescriptor |
96 | | virtual OUString SAL_CALL getReplaceString( ) override; |
97 | | virtual void SAL_CALL setReplaceString( const OUString& aReplaceString ) override; |
98 | | |
99 | | // XPropertySet |
100 | | virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; |
101 | | virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override; |
102 | | virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override; |
103 | | virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override; |
104 | | virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override; |
105 | | virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; |
106 | | virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override; |
107 | | }; |
108 | | |
109 | | /* ================================================================= */ |
110 | | |
111 | | /** this class holds a sequence that is a result from a find all and |
112 | | lets people access it through the XIndexAccess Interface. */ |
113 | | class SdUnoFindAllAccess final : public ::cppu::WeakImplHelper< css::container::XIndexAccess > // public css::container::XElementAccess |
114 | | { |
115 | | css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > maSequence; |
116 | | |
117 | | public: |
118 | | SdUnoFindAllAccess( css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > const & rSequence ) noexcept; |
119 | | virtual ~SdUnoFindAllAccess() noexcept override; |
120 | | |
121 | | // XIndexAccess |
122 | | virtual sal_Int32 SAL_CALL getCount() override ; |
123 | | virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override; |
124 | | |
125 | | // XElementAccess |
126 | | virtual css::uno::Type SAL_CALL getElementType() override; |
127 | | virtual sal_Bool SAL_CALL hasElements() override; |
128 | | }; |
129 | | |
130 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |