Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/utlui/tmplctrl.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 <svl/style.hxx>
21
#include <svl/stritem.hxx>
22
#include <sfx2/dispatch.hxx>
23
#include <sfx2/viewfrm.hxx>
24
#include <vcl/commandevent.hxx>
25
#include <vcl/status.hxx>
26
#include <vcl/weld/weldutils.hxx>
27
28
#include <swtypes.hxx>
29
#include <strings.hrc>
30
31
#include <wrtsh.hxx>
32
#include <view.hxx>
33
#include <swmodule.hxx>
34
#include <cmdid.h>
35
#include <docsh.hxx>
36
#include <tmplctrl.hxx>
37
38
SFX_IMPL_STATUSBAR_CONTROL( SwTemplateControl, SfxStringItem );
39
40
SwTemplateControl::SwTemplateControl( sal_uInt16 _nSlotId,
41
                                      sal_uInt16 _nId,
42
                                      StatusBar& rStb ) :
43
0
    SfxStatusBarControl( _nSlotId, _nId, rStb )
44
0
{
45
0
}
46
47
SwTemplateControl::~SwTemplateControl()
48
0
{
49
0
}
50
51
void SwTemplateControl::StateChangedAtStatusBarControl(
52
    sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
53
0
{
54
0
    const SfxStringItem* pItem = nullptr;
55
0
    if (SfxItemState::DEFAULT == eState && (pItem = dynamic_cast<const SfxStringItem*>(pState)))
56
0
    {
57
0
        m_sTemplate = pItem->GetValue();
58
0
        GetStatusBar().SetItemText(GetId(), m_sTemplate);
59
0
        GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_TMPLCTRL_HINT));
60
0
    }
61
0
    else
62
0
    {
63
0
        GetStatusBar().SetItemText(GetId(), OUString());
64
0
        GetStatusBar().SetQuickHelpText(GetId(), u""_ustr);
65
0
    }
66
0
}
67
68
void SwTemplateControl::Paint( const UserDrawEvent&  )
69
0
{
70
0
}
71
72
void SwTemplateControl::Command( const CommandEvent& rCEvt )
73
0
{
74
0
    if ( rCEvt.GetCommand() != CommandEventId::ContextMenu ||
75
0
            GetStatusBar().GetItemText( GetId() ).isEmpty())
76
0
        return;
77
78
0
    {
79
0
        SwView* pView = ::GetActiveView();
80
0
        SwWrtShell *const pWrtShell(pView ? pView->GetWrtShellPtr() : nullptr);
81
0
        if (nullptr != pWrtShell &&
82
0
            !pWrtShell->SwCursorShell::HasSelection()&&
83
0
            !pWrtShell->IsSelFrameMode() &&
84
0
            !pWrtShell->GetSelectedObjCount())
85
0
        {
86
0
            SfxStyleSheetBasePool* pPool = pView->GetDocShell()->
87
0
                                                        GetStyleSheetPool();
88
0
            auto xIter = pPool->CreateIterator(SfxStyleFamily::Page);
89
0
            if (xIter->Count() > 1)
90
0
            {
91
0
                std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, u"modules/swriter/ui/pagestylemenu.ui"_ustr));
92
0
                std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu(u"menu"_ustr));
93
94
0
                sal_uInt32 nCount = 0;
95
0
                SfxStyleSheetBase* pStyle = xIter->First();
96
0
                while( pStyle )
97
0
                {
98
0
                    xPopup->append(OUString::number(++nCount), pStyle->GetName());
99
0
                    pStyle = xIter->Next();
100
0
                }
101
102
0
                ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
103
0
                weld::Window* pParent = weld::GetPopupParent(GetStatusBar(), aRect);
104
0
                OUString sResult = xPopup->popup_at_rect(pParent, aRect);
105
0
                sal_uInt32 nCurrId = sResult.toUInt32();
106
0
                if (nCurrId > 0)
107
0
                {
108
                    // looks a bit awkward, but another way is not possible
109
0
                    pStyle = xIter->operator[]( nCurrId - 1 );
110
0
                    SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() );
111
0
                    pWrtShell->GetView().GetViewFrame().GetDispatcher()->ExecuteList(
112
0
                                FN_SET_PAGE_STYLE,
113
0
                                SfxCallMode::SLOT|SfxCallMode::RECORD,
114
0
                                { &aStyle });
115
0
                }
116
0
            }
117
0
        }
118
0
    }
119
0
}
120
121
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */