Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/func/fusearch.cxx
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
#include <fusearch.hxx>
21
22
#include <sfx2/viewfrm.hxx>
23
24
#include <sfx2/bindings.hxx>
25
#include <fupoor.hxx>
26
#include <drawdoc.hxx>
27
#include <app.hrc>
28
#include <Outliner.hxx>
29
#include <DrawDocShell.hxx>
30
#include <DrawViewShell.hxx>
31
#include <OutlineViewShell.hxx>
32
#include <NotesPanelViewShell.hxx>
33
#include <ViewShellBase.hxx>
34
35
class SfxRequest;
36
37
namespace sd {
38
39
const sal_uInt16 SidArraySpell[] = {
40
            SID_DRAWINGMODE,
41
            SID_OUTLINE_MODE,
42
            SID_SLIDE_SORTER_MODE,
43
            SID_NOTES_MODE,
44
            SID_HANDOUT_MASTER_MODE,
45
            SID_SLIDE_MASTER_MODE,
46
            SID_NOTES_MASTER_MODE,
47
            0 };
48
49
FuSearch::FuSearch (
50
    ViewShell& rViewSh,
51
    ::sd::Window* pWin,
52
    ::sd::View* pView,
53
    SdDrawDocument& rDoc,
54
    SfxRequest& rReq )
55
0
    : FuPoor(rViewSh, pWin, pView, rDoc, rReq),
56
0
      m_pSdOutliner(nullptr),
57
0
      m_bOwnOutliner(false)
58
0
{
59
0
}
60
61
FuSearch* FuSearch::createPtr(ViewShell& rViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument& rDoc, SfxRequest& rReq)
62
0
{
63
0
    FuSearch* xFunc( new FuSearch( rViewSh, pWin, pView, rDoc, rReq ) );
64
0
    xFunc->DoExecute(rReq);
65
0
    return xFunc;
66
0
}
67
68
void FuSearch::DoExecute( SfxRequest& )
69
0
{
70
0
    mrViewShell.GetViewFrame()->GetBindings().Invalidate( SidArraySpell );
71
72
0
    if ( dynamic_cast< const DrawViewShell *>( &mrViewShell ) !=  nullptr )
73
0
    {
74
0
        m_bOwnOutliner = true;
75
0
        m_pSdOutliner = new SdOutliner( mrDoc, OutlinerMode::TextObject );
76
0
    }
77
0
    else if ( dynamic_cast< const OutlineViewShell *>( &mrViewShell ) !=  nullptr )
78
0
    {
79
0
        m_bOwnOutliner = false;
80
0
        m_pSdOutliner = mrDoc.GetOutliner();
81
0
    }
82
0
    else if ( dynamic_cast< const NotesPanelViewShell *>( &mrViewShell ) !=  nullptr )
83
0
    {
84
0
        ViewShell::ShellType nShellType = mrViewShell.GetViewShellBase().GetMainViewShell()->GetShellType();
85
0
        if( nShellType == ViewShell::ST_OUTLINE )
86
0
        {
87
0
            m_bOwnOutliner = false;
88
0
            m_pSdOutliner = mrDoc.GetOutliner();
89
0
        }
90
0
        if( nShellType == ViewShell::ST_IMPRESS )
91
0
        {
92
0
            m_bOwnOutliner = true;
93
0
            m_pSdOutliner = new SdOutliner( mrDoc, OutlinerMode::TextObject );
94
0
        }
95
0
    }
96
97
0
    if (m_pSdOutliner)
98
0
       m_pSdOutliner->PrepareSpelling();
99
0
}
100
101
FuSearch::~FuSearch()
102
0
{
103
0
    if ( ! mpDocSh->IsInDestruction() && mpDocSh->GetViewShell()!=nullptr)
104
0
        mpDocSh->GetViewShell()->GetViewFrame()->GetBindings().Invalidate( SidArraySpell );
105
106
0
    if (m_pSdOutliner)
107
0
        m_pSdOutliner->EndSpelling();
108
109
0
    if (m_bOwnOutliner)
110
0
        delete m_pSdOutliner;
111
0
}
112
113
void FuSearch::SearchAndReplace( const SvxSearchItem* pSearchItem )
114
0
{
115
0
    ViewShellBase* pBase = dynamic_cast<ViewShellBase*>( SfxViewShell::Current() );
116
0
    ViewShell* pViewShell = nullptr;
117
0
    if (pBase != nullptr)
118
0
        pViewShell = pBase->GetMainViewShell().get();
119
120
0
    if (pViewShell == nullptr)
121
0
        return;
122
123
0
    if (m_pSdOutliner && dynamic_cast<const DrawViewShell*>(pViewShell) && !m_bOwnOutliner)
124
0
    {
125
0
        m_pSdOutliner->EndSpelling();
126
127
0
        m_bOwnOutliner = true;
128
0
        m_pSdOutliner = new SdOutliner(mrDoc, OutlinerMode::TextObject);
129
0
        m_pSdOutliner->PrepareSpelling();
130
0
    }
131
0
    else if (m_pSdOutliner && dynamic_cast<const OutlineViewShell*>(pViewShell) && m_bOwnOutliner)
132
0
    {
133
0
        m_pSdOutliner->EndSpelling();
134
0
        delete m_pSdOutliner;
135
136
0
        m_bOwnOutliner = false;
137
0
        m_pSdOutliner = mrDoc.GetOutliner();
138
0
        m_pSdOutliner->PrepareSpelling();
139
0
    }
140
141
0
    if (m_pSdOutliner)
142
0
    {
143
0
        bool bEndSpelling = m_pSdOutliner->StartSearchAndReplace(pSearchItem);
144
145
0
        if (bEndSpelling)
146
0
        {
147
0
            m_pSdOutliner->EndSpelling();
148
0
            m_pSdOutliner->PrepareSpelling();
149
0
        }
150
0
    }
151
0
}
152
153
} // end of namespace sd
154
155
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */