Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/tbxctrls/itemwin.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 <com/sun/star/drawing/FillStyle.hpp>
21
#include <com/sun/star/frame/XDispatchProvider.hpp>
22
#include <com/sun/star/frame/XFrame.hpp>
23
24
#include <comphelper/propertyvalue.hxx>
25
#include <sfx2/tbxctrl.hxx>
26
#include <sfx2/viewsh.hxx>
27
#include <sfx2/module.hxx>
28
29
#include <vcl/event.hxx>
30
#include <vcl/svapp.hxx>
31
#include <vcl/settings.hxx>
32
#include <vcl/virdev.hxx>
33
34
#include <svx/dialmgr.hxx>
35
#include <svx/strings.hrc>
36
37
#include <svx/xlnwtit.hxx>
38
#include <svx/xtable.hxx>
39
#include <svx/itemwin.hxx>
40
#include <svtools/unitconv.hxx>
41
#include "linemetricbox.hxx"
42
43
using namespace ::com::sun::star;
44
using namespace ::com::sun::star::uno;
45
using namespace ::com::sun::star::frame;
46
using namespace ::com::sun::star::beans;
47
48
SvxMetricField::SvxMetricField(
49
    vcl::Window* pParent, const Reference< XFrame >& rFrame )
50
0
    : InterimItemWindow(pParent, u"svx/ui/metricfieldbox.ui"_ustr, u"MetricFieldBox"_ustr)
51
0
    , m_xWidget(m_xBuilder->weld_metric_spin_button(u"metricfield"_ustr, FieldUnit::MM))
52
0
    , nCurValue(0)
53
0
    , eDestPoolUnit(MapUnit::Map100thMM)
54
0
    , eDlgUnit(SfxModule::GetModuleFieldUnit(rFrame))
55
0
    , mxFrame(rFrame)
56
0
{
57
0
    InitControlBase(&m_xWidget->get_widget());
58
59
0
    m_xWidget->set_range(0, 5000, FieldUnit::NONE);
60
0
    m_xWidget->connect_value_changed(LINK(this, SvxMetricField, ModifyHdl));
61
0
    m_xWidget->connect_focus_in(LINK(this, SvxMetricField, FocusInHdl));
62
0
    m_xWidget->get_widget().connect_key_press(LINK(this, SvxMetricField, KeyInputHdl));
63
64
0
    SetFieldUnit(*m_xWidget, eDlgUnit);
65
66
0
    SetSizePixel(m_xWidget->get_preferred_size());
67
0
}
Unexecuted instantiation: SvxMetricField::SvxMetricField(vcl::Window*, com::sun::star::uno::Reference<com::sun::star::frame::XFrame> const&)
Unexecuted instantiation: SvxMetricField::SvxMetricField(vcl::Window*, com::sun::star::uno::Reference<com::sun::star::frame::XFrame> const&)
68
69
void SvxMetricField::dispose()
70
0
{
71
0
    m_xWidget.reset();
72
0
    InterimItemWindow::dispose();
73
0
}
74
75
SvxMetricField::~SvxMetricField()
76
0
{
77
0
    disposeOnce();
78
0
}
79
80
void SvxMetricField::set_sensitive(bool bSensitive)
81
0
{
82
0
    Enable(bSensitive);
83
0
    m_xWidget->set_sensitive(bSensitive);
84
0
    if (!bSensitive)
85
0
        m_xWidget->set_text(u""_ustr);
86
0
}
87
88
void SvxMetricField::Update( const XLineWidthItem* pItem )
89
0
{
90
0
    if ( pItem )
91
0
    {
92
        // tdf#132169 we always get the value in MapUnit::Map100thMM but have
93
        // to set it in the core metric of the target application
94
0
        if (pItem->GetValue() != GetCoreValue(*m_xWidget, MapUnit::Map100thMM))
95
0
            SetMetricValue(*m_xWidget, pItem->GetValue(), MapUnit::Map100thMM);
96
0
    }
97
0
    else
98
0
        m_xWidget->set_text(u""_ustr);
99
0
}
100
101
IMPL_LINK_NOARG(SvxMetricField, ModifyHdl, weld::MetricSpinButton&, void)
102
0
{
103
0
    auto nTmp = GetCoreValue(*m_xWidget, eDestPoolUnit);
104
0
    XLineWidthItem aLineWidthItem( nTmp );
105
106
0
    Any a;
107
0
    aLineWidthItem.QueryValue( a );
108
0
    Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(u"LineWidth"_ustr, a) };
109
0
    SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
110
0
                                 u".uno:LineWidth"_ustr,
111
0
                                 aArgs );
112
0
}
113
114
void SvxMetricField::ReleaseFocus_Impl()
115
0
{
116
0
    if (const SfxViewShell* pViewShell = SfxViewShell::Current())
117
0
    {
118
0
        vcl::Window* pShellWnd = pViewShell->GetWindow();
119
0
        if ( pShellWnd )
120
0
            pShellWnd->GrabFocus();
121
0
    }
122
0
}
123
124
void SvxMetricField::SetDestCoreUnit( MapUnit eUnit )
125
0
{
126
0
    eDestPoolUnit = eUnit;
127
0
}
128
129
void SvxMetricField::RefreshDlgUnit()
130
0
{
131
0
    FieldUnit eTmpUnit = SfxModule::GetModuleFieldUnit( mxFrame );
132
0
    if ( eDlgUnit != eTmpUnit )
133
0
    {
134
0
        eDlgUnit = eTmpUnit;
135
0
        SetFieldUnit(*m_xWidget, eDlgUnit);
136
0
    }
137
0
}
138
139
IMPL_LINK_NOARG(SvxMetricField, FocusInHdl, weld::Widget&, void)
140
0
{
141
0
    nCurValue = m_xWidget->get_value(FieldUnit::NONE);
142
0
}
143
144
IMPL_LINK(SvxMetricField, KeyInputHdl, const KeyEvent&, rKEvt, bool)
145
0
{
146
0
    bool bHandled = false;
147
148
0
    sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
149
150
0
    if (nCode == KEY_ESCAPE)
151
0
    {
152
0
        m_xWidget->set_value(nCurValue, FieldUnit::NONE);
153
0
        ModifyHdl(*m_xWidget);
154
0
        ReleaseFocus_Impl();
155
0
        bHandled = true;
156
0
    }
157
158
0
    return bHandled || ChildKeyInput(rKEvt);
159
0
}
160
161
void SvxMetricField::DataChanged( const DataChangedEvent& rDCEvt )
162
0
{
163
0
    if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
164
0
         (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
165
0
    {
166
0
        SetSizePixel(m_xWidget->get_preferred_size());
167
0
    }
168
169
0
    InterimItemWindow::DataChanged( rDCEvt );
170
0
}
171
172
void SvxFillTypeBox::Fill(weld::ComboBox& rListBox)
173
0
{
174
0
    rListBox.freeze();
175
176
0
    rListBox.append_text(SvxResId(RID_SVXSTR_INVISIBLE));
177
0
    rListBox.append_text(SvxResId(RID_SVXSTR_COLOR));
178
0
    rListBox.append_text(SvxResId(RID_SVXSTR_GRADIENT));
179
0
    rListBox.append_text(SvxResId(RID_SVXSTR_HATCH));
180
0
    rListBox.append_text(SvxResId(RID_SVXSTR_BITMAP));
181
0
    rListBox.append_text(SvxResId(RID_SVXSTR_PATTERN));
182
0
    rListBox.append_text(SvxResId(RID_SVXSTR_USE_BACKGROUND));
183
184
0
    rListBox.thaw();
185
186
0
    rListBox.set_active(1); // solid color
187
0
}
188
189
namespace
190
{
191
    void formatBitmapToSize(Bitmap& rBitmap, const Size& rSize)
192
0
    {
193
0
        if(rBitmap.IsEmpty() || rSize.IsEmpty())
194
0
            return;
195
196
0
        ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
197
0
        pVirtualDevice->SetOutputSizePixel(rSize);
198
199
0
        if(rBitmap.HasAlpha())
200
0
        {
201
0
            const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
202
203
0
            if(rStyleSettings.GetPreviewUsesCheckeredBackground())
204
0
            {
205
0
                const Point aNull(0, 0);
206
0
                static const sal_uInt32 nLen(8);
207
0
                static const Color aW(COL_WHITE);
208
0
                static const Color aG(0xef, 0xef, 0xef);
209
210
0
                pVirtualDevice->DrawCheckered(aNull, rSize, nLen, aW, aG);
211
0
            }
212
0
            else
213
0
            {
214
0
                pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
215
0
                pVirtualDevice->Erase();
216
0
            }
217
0
        }
218
219
0
        if(rBitmap.GetSizePixel().Width() >= rSize.Width() && rBitmap.GetSizePixel().Height() >= rSize.Height())
220
0
        {
221
0
            rBitmap.Scale(rSize);
222
0
            pVirtualDevice->DrawBitmap(Point(0, 0), rBitmap);
223
0
        }
224
0
        else
225
0
        {
226
0
            const Size aBitmapSize(rBitmap.GetSizePixel());
227
228
0
            for(tools::Long y(0); y < rSize.Height(); y += aBitmapSize.Height())
229
0
            {
230
0
                for(tools::Long x(0); x < rSize.Width(); x += aBitmapSize.Width())
231
0
                {
232
0
                    pVirtualDevice->DrawBitmap(
233
0
                        Point(x, y),
234
0
                        rBitmap);
235
0
                }
236
0
            }
237
0
        }
238
239
0
        rBitmap = pVirtualDevice->GetBitmap(Point(0, 0), rSize);
240
0
    }
241
} // end of anonymous namespace
242
243
void SvxFillAttrBox::Fill(weld::ComboBox& rBox, const XHatchListRef &pList)
244
0
{
245
0
    if( !pList.is() )
246
0
        return;
247
248
0
    tools::Long nCount = pList->Count();
249
0
    ScopedVclPtrInstance< VirtualDevice > pVD;
250
0
    rBox.freeze();
251
252
0
    for( tools::Long i = 0; i < nCount; i++ )
253
0
    {
254
0
        const XHatchEntry* pEntry = pList->GetHatch(i);
255
0
        const Bitmap aBitmap = pList->GetUiBitmap( i );
256
0
        if( !aBitmap.IsEmpty() )
257
0
        {
258
0
            const Size aBmpSize(aBitmap.GetSizePixel());
259
0
            pVD->SetOutputSizePixel(aBmpSize, false);
260
0
            pVD->DrawBitmap(Point(), aBitmap);
261
0
            rBox.append(u""_ustr, pEntry->GetName(), *pVD);
262
0
        }
263
0
        else
264
0
            rBox.append_text(pEntry->GetName());
265
0
    }
266
267
0
    rBox.thaw();
268
0
}
269
270
void SvxFillAttrBox::Fill(weld::ComboBox& rBox, const XGradientListRef &pList)
271
0
{
272
0
    if( !pList.is() )
273
0
        return;
274
275
0
    tools::Long nCount = pList->Count();
276
0
    ScopedVclPtrInstance< VirtualDevice > pVD;
277
0
    rBox.freeze();
278
279
0
    for( tools::Long i = 0; i < nCount; i++ )
280
0
    {
281
0
        const XGradientEntry* pEntry = pList->GetGradient(i);
282
0
        const Bitmap aBitmap = pList->GetUiBitmap( i );
283
0
        if( !aBitmap.IsEmpty() )
284
0
        {
285
0
            const Size aBmpSize(aBitmap.GetSizePixel());
286
0
            pVD->SetOutputSizePixel(aBmpSize, false);
287
0
            pVD->DrawBitmap(Point(), aBitmap);
288
0
            rBox.append(u""_ustr, pEntry->GetName(), *pVD);
289
0
        }
290
0
        else
291
0
            rBox.append_text(pEntry->GetName());
292
0
    }
293
294
0
    rBox.thaw();
295
0
}
296
297
void SvxFillAttrBox::Fill(weld::ComboBox& rBox, const XBitmapListRef &pList)
298
0
{
299
0
    if( !pList.is() )
300
0
        return;
301
302
0
    tools::Long nCount = pList->Count();
303
0
    const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
304
0
    const Size aSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
305
0
    ScopedVclPtrInstance< VirtualDevice > pVD;
306
0
    pVD->SetOutputSizePixel(aSize, false);
307
0
    rBox.freeze();
308
309
0
    for( tools::Long i = 0; i < nCount; i++ )
310
0
    {
311
0
        const XBitmapEntry* pEntry = pList->GetBitmap( i );
312
0
        Bitmap aBitmap = pEntry->GetGraphicObject().GetGraphic().GetBitmap();
313
0
        formatBitmapToSize(aBitmap, aSize);
314
0
        pVD->DrawBitmap(Point(), aBitmap);
315
0
        rBox.append(u""_ustr, pEntry->GetName(), *pVD);
316
0
    }
317
318
0
    rBox.thaw();
319
0
}
320
321
void SvxFillAttrBox::Fill(weld::ComboBox& rBox, const XPatternListRef &pList)
322
0
{
323
0
    if( !pList.is() )
324
0
        return;
325
326
0
    tools::Long nCount = pList->Count();
327
0
    const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
328
0
    const Size aSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
329
0
    ScopedVclPtrInstance< VirtualDevice > pVD;
330
0
    pVD->SetOutputSizePixel(aSize, false);
331
0
    rBox.freeze();
332
333
0
    for( tools::Long i = 0; i < nCount; i++ )
334
0
    {
335
0
        const XBitmapEntry* pEntry = pList->GetBitmap( i );
336
0
        Bitmap aBitmap = pEntry->GetGraphicObject().GetGraphic().GetBitmap();
337
0
        formatBitmapToSize(aBitmap, aSize);
338
0
        pVD->DrawBitmap(Point(), aBitmap);
339
0
        rBox.append(u""_ustr, pEntry->GetName(), *pVD);
340
0
    }
341
342
0
    rBox.thaw();
343
344
0
}
345
346
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */