1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
23 #include <com/sun/star/util/XReplaceable.hpp>
24 #include <com/sun/star/util/XReplaceDescriptor.hpp>
26 #include <comphelper/servicehelper.hxx>
27 #include <cppuhelper/implbase.hxx>
28 #include <editeng/editdata.hxx>
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 namespace com::sun::star::util
{ class XSearchDescriptor
; }
35 class SvxItemPropertySet
;
36 class SdUnoSearchReplaceDescriptor
;
38 /** this class implements a search or replace operation on a given page or a given sdrobj */
39 class SdUnoSearchReplaceShape
: public css::util::XReplaceable
41 css::drawing::XDrawPage
* mpPage
;
44 css::uno::Reference
< css::text::XTextRange
> Search( const css::uno::Reference
< css::text::XTextRange
>& xText
, SdUnoSearchReplaceDescriptor
* pDescr
);
45 bool Search( const OUString
& rText
, sal_Int32
& nStartPos
, sal_Int32
& nEndPos
, SdUnoSearchReplaceDescriptor
* pDescr
) noexcept
;
46 static ESelection
GetSelection( const css::uno::Reference
< css::text::XTextRange
>& xTextRange
) noexcept
;
47 static css::uno::Reference
< css::drawing::XShape
> GetShape( const css::uno::Reference
< css::text::XTextRange
>& xTextRange
) noexcept
;
48 css::uno::Reference
< css::drawing::XShape
> GetNextShape( const css::uno::Reference
< css::container::XIndexAccess
>& xShapes
, const css::uno::Reference
< css::drawing::XShape
>& xCurrentShape
) noexcept
;
49 css::uno::Reference
< css::drawing::XShape
> GetCurrentShape() const noexcept
;
52 // danger, this c'tor is only usable if the given shape or page is derived
54 SdUnoSearchReplaceShape( css::drawing::XDrawPage
* xPage
) noexcept
;
55 virtual ~SdUnoSearchReplaceShape() noexcept
;
58 virtual css::uno::Reference
< css::util::XReplaceDescriptor
> SAL_CALL
createReplaceDescriptor( ) override
;
59 virtual sal_Int32 SAL_CALL
replaceAll( const css::uno::Reference
< css::util::XSearchDescriptor
>& xDesc
) override
;
62 virtual css::uno::Reference
< css::util::XSearchDescriptor
> SAL_CALL
createSearchDescriptor( ) override
;
63 virtual css::uno::Reference
< css::container::XIndexAccess
> SAL_CALL
findAll( const css::uno::Reference
< css::util::XSearchDescriptor
>& xDesc
) override
;
64 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
findFirst( const css::uno::Reference
< css::util::XSearchDescriptor
>& xDesc
) override
;
65 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
;
68 /* ================================================================= */
70 /** this class holds the parameters and status of a search or replace operation performed
71 by class SdUnoSearchReplaceShape */
73 class SdUnoSearchReplaceDescriptor final
: public ::cppu::WeakImplHelper
< css::util::XReplaceDescriptor
> // public css::util::XSearchDescriptor, css::beans::XPropertySet
75 std::unique_ptr
<SvxItemPropertySet
> mpPropSet
;
82 OUString maReplaceStr
;
85 /// @throws css::uno::RuntimeException
86 SdUnoSearchReplaceDescriptor();
87 virtual ~SdUnoSearchReplaceDescriptor() noexcept override
;
89 bool IsCaseSensitive() const { return mbCaseSensitive
; }
90 bool IsWords() const { return mbWords
; }
93 virtual OUString SAL_CALL
getSearchString( ) override
;
94 virtual void SAL_CALL
setSearchString( const OUString
& aString
) override
;
97 virtual OUString SAL_CALL
getReplaceString( ) override
;
98 virtual void SAL_CALL
setReplaceString( const OUString
& aReplaceString
) override
;
101 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
102 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
103 virtual css::uno::Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) override
;
104 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
;
105 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& aListener
) override
;
106 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
107 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
110 /* ================================================================= */
112 /** this class holds a sequence that is a result from a find all and
113 lets people access it through the XIndexAccess Interface. */
114 class SdUnoFindAllAccess final
: public ::cppu::WeakImplHelper
< css::container::XIndexAccess
> // public css::container::XElementAccess
116 css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> > maSequence
;
119 SdUnoFindAllAccess( css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> > const & rSequence
) noexcept
;
120 virtual ~SdUnoFindAllAccess() noexcept override
;
123 virtual sal_Int32 SAL_CALL
getCount() override
;
124 virtual css::uno::Any SAL_CALL
getByIndex( sal_Int32 Index
) override
;
127 virtual css::uno::Type SAL_CALL
getElementType() override
;
128 virtual sal_Bool SAL_CALL
hasElements() override
;
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */