Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/dlg/diactrl.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 <sal/config.h>
21
22
#include <comphelper/propertyvalue.hxx>
23
#include <utility>
24
#include <tools/fldunit.hxx>
25
#include <vcl/fieldvalues.hxx>
26
#include <vcl/settings.hxx>
27
#include <vcl/svapp.hxx>
28
#include <vcl/toolbox.hxx>
29
#include <svl/intitem.hxx>
30
#include <tools/debug.hxx>
31
32
#include <strings.hrc>
33
34
#include <diactrl.hxx>
35
#include <SlideSorter.hxx>
36
37
#include <sdresid.hxx>
38
#include <app.hrc>
39
40
#include <com/sun/star/frame/XDispatchProvider.hpp>
41
#include <com/sun/star/frame/XFrame.hpp>
42
43
using namespace ::com::sun::star;
44
45
SFX_IMPL_TOOLBOX_CONTROL( SdTbxCtlDiaPages,  SfxUInt16Item )
46
47
namespace
48
{
49
    OUString format_number(int nSlides)
50
0
    {
51
0
        OUString aSlides(SdResId(STR_SLIDES, nSlides));
52
0
        return aSlides.replaceFirst("%1", OUString::number(nSlides));
53
0
    }
54
}
55
56
// SdPagesField
57
SdPagesField::SdPagesField( vcl::Window* pParent,
58
                            uno::Reference< frame::XFrame > xFrame )
59
0
    : InterimItemWindow(pParent, u"modules/simpress/ui/pagesfieldbox.ui"_ustr, u"PagesFieldBox"_ustr)
60
0
    , m_xWidget(m_xBuilder->weld_spin_button(u"pagesfield"_ustr))
61
0
    , m_xFrame(std::move(xFrame))
62
0
{
63
0
    InitControlBase(m_xWidget.get());
64
65
    // set parameter of MetricFields
66
0
    m_xWidget->set_digits(0);
67
0
    m_xWidget->set_range(1, MAX_PAGES_PER_ROW);
68
0
    m_xWidget->set_increments(1, 5);
69
0
    m_xWidget->connect_value_changed(LINK(this, SdPagesField, ModifyHdl));
70
0
    m_xWidget->set_value_formatter(LINK(this, SdPagesField, OutputHdl));
71
0
    m_xWidget->set_text_parser(LINK(this, SdPagesField, spin_button_input));
72
0
    m_xWidget->connect_key_press(LINK(this, SdPagesField, KeyInputHdl));
73
74
0
    auto width = std::max(m_xWidget->get_pixel_size(format_number(1)).Width(),
75
0
                          m_xWidget->get_pixel_size(format_number(15)).Width());
76
0
    int chars = ceil(width / m_xWidget->get_approximate_digit_width());
77
0
    m_xWidget->set_width_chars(chars);
78
79
0
    SetSizePixel(m_xWidget->get_preferred_size());
80
0
}
Unexecuted instantiation: SdPagesField::SdPagesField(vcl::Window*, com::sun::star::uno::Reference<com::sun::star::frame::XFrame>)
Unexecuted instantiation: SdPagesField::SdPagesField(vcl::Window*, com::sun::star::uno::Reference<com::sun::star::frame::XFrame>)
81
82
IMPL_LINK(SdPagesField, KeyInputHdl, const KeyEvent&, rKEvt, bool)
83
0
{
84
0
    return ChildKeyInput(rKEvt);
85
0
}
86
87
void SdPagesField::dispose()
88
0
{
89
0
    m_xWidget.reset();
90
0
    InterimItemWindow::dispose();
91
0
}
92
93
SdPagesField::~SdPagesField()
94
0
{
95
0
    disposeOnce();
96
0
}
97
98
void SdPagesField::set_sensitive(bool bSensitive)
99
0
{
100
0
    Enable(bSensitive);
101
0
    m_xWidget->set_sensitive(bSensitive);
102
0
    if (!bSensitive)
103
0
        m_xWidget->set_text(u""_ustr);
104
0
}
105
106
void SdPagesField::UpdatePagesField( const SfxUInt16Item* pItem )
107
0
{
108
0
    if (pItem)
109
0
        m_xWidget->set_value(pItem->GetValue());
110
0
    else
111
0
        m_xWidget->set_text(OUString());
112
0
}
113
114
IMPL_STATIC_LINK(SdPagesField, OutputHdl, sal_Int64, nValue, OUString)
115
0
{
116
0
    return format_number(nValue);
117
0
}
118
119
IMPL_LINK(SdPagesField, spin_button_input, const OUString&, rText, std::optional<int>)
120
0
{
121
0
    const LocaleDataWrapper& rLocaleData = Application::GetSettings().GetLocaleDataWrapper();
122
0
    double fResult(0.0);
123
0
    bool bRet = vcl::TextToValue(rText, fResult, 0, m_xWidget->get_digits(), rLocaleData, FieldUnit::NONE);
124
0
    if (!bRet)
125
0
        return {};
126
127
0
    if (fResult > SAL_MAX_INT32)
128
0
        fResult = SAL_MAX_INT32;
129
0
    else if (fResult < SAL_MIN_INT32)
130
0
        fResult = SAL_MIN_INT32;
131
132
0
    return std::optional<int>(std::round(fResult));
133
0
}
134
135
IMPL_LINK_NOARG(SdPagesField, ModifyHdl, weld::SpinButton&, void)
136
0
{
137
0
    SfxUInt16Item aItem(SID_PAGES_PER_ROW, m_xWidget->get_value());
138
139
0
    uno::Any a;
140
0
    aItem.QueryValue( a );
141
0
    uno::Sequence< beans::PropertyValue > aArgs{ comphelper::makePropertyValue(u"PagesPerRow"_ustr, a) };
142
0
    SfxToolBoxControl::Dispatch( ::uno::Reference< ::frame::XDispatchProvider >( m_xFrame->getController(), ::uno::UNO_QUERY ),
143
0
                                 u".uno:PagesPerRow"_ustr,
144
0
                                 aArgs );
145
0
}
146
147
SdTbxCtlDiaPages::SdTbxCtlDiaPages( sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox& rTbx ) :
148
0
    SfxToolBoxControl( nSlotId, nId, rTbx )
149
0
{
150
0
}
151
152
SdTbxCtlDiaPages::~SdTbxCtlDiaPages()
153
0
{
154
0
}
155
156
void SdTbxCtlDiaPages::StateChangedAtToolBoxControl( sal_uInt16,
157
                SfxItemState eState, const SfxPoolItem* pState )
158
0
{
159
0
    SdPagesField* pFld = static_cast<SdPagesField*>( GetToolBox().GetItemWindow( GetId() ) );
160
0
    DBG_ASSERT( pFld, "Window not found" );
161
162
0
    if ( eState == SfxItemState::DISABLED )
163
0
    {
164
0
        pFld->set_sensitive(false);
165
0
    }
166
0
    else
167
0
    {
168
0
        pFld->set_sensitive(true);
169
170
0
        const SfxUInt16Item* pItem = nullptr;
171
0
        if ( eState == SfxItemState::DEFAULT )
172
0
        {
173
0
            pItem = dynamic_cast< const SfxUInt16Item* >( pState );
174
0
            DBG_ASSERT( pItem, "sd::SdTbxCtlDiaPages::StateChanged(), wrong item type!" );
175
0
        }
176
177
0
        pFld->UpdatePagesField( pItem );
178
0
    }
179
0
}
180
181
VclPtr<InterimItemWindow> SdTbxCtlDiaPages::CreateItemWindow( vcl::Window* pParent )
182
0
{
183
0
    VclPtr<SdPagesField> pWindow = VclPtr<SdPagesField>::Create(pParent, m_xFrame);
184
0
    pWindow->Show();
185
186
0
    return pWindow;
187
0
}
188
189
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */