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