LibreOffice Module sd (master) 1
diactrl.cxx
Go to the documentation of this file.
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
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
30#include <strings.hrc>
31
32#include <diactrl.hxx>
33
34#include <sdresid.hxx>
35#include <app.hrc>
36
37#include <com/sun/star/frame/XDispatchProvider.hpp>
38#include <com/sun/star/frame/XFrame.hpp>
39
40using namespace ::com::sun::star;
41
43
44namespace
45{
46 OUString format_number(int nSlides)
47 {
48 OUString aSlides(SdResId(STR_SLIDES, nSlides));
49 return aSlides.replaceFirst("%1", OUString::number(nSlides));
50 }
51}
52
53// SdPagesField
55 uno::Reference< frame::XFrame > xFrame )
56 : InterimItemWindow(pParent, "modules/simpress/ui/pagesfieldbox.ui", "PagesFieldBox")
57 , m_xWidget(m_xBuilder->weld_spin_button("pagesfield"))
58 , m_xFrame(std::move(xFrame))
59{
61
62 // set parameter of MetricFields
63 m_xWidget->set_digits(0);
64 m_xWidget->set_range(1, 15);
65 m_xWidget->set_increments(1, 5);
66 m_xWidget->connect_value_changed(LINK(this, SdPagesField, ModifyHdl));
67 m_xWidget->connect_output(LINK(this, SdPagesField, OutputHdl));
68 m_xWidget->connect_input(LINK(this, SdPagesField, spin_button_input));
69 m_xWidget->connect_key_press(LINK(this, SdPagesField, KeyInputHdl));
70
71 auto width = std::max(m_xWidget->get_pixel_size(format_number(1)).Width(),
72 m_xWidget->get_pixel_size(format_number(15)).Width());
73 int chars = ceil(width / m_xWidget->get_approximate_digit_width());
74 m_xWidget->set_width_chars(chars);
75
76 SetSizePixel(m_xWidget->get_preferred_size());
77}
78
79IMPL_LINK(SdPagesField, KeyInputHdl, const KeyEvent&, rKEvt, bool)
80{
81 return ChildKeyInput(rKEvt);
82}
83
85{
86 m_xWidget.reset();
88}
89
91{
93}
94
95void SdPagesField::set_sensitive(bool bSensitive)
96{
97 Enable(bSensitive);
98 m_xWidget->set_sensitive(bSensitive);
99 if (!bSensitive)
100 m_xWidget->set_text("");
101}
102
104{
105 if (pItem)
106 m_xWidget->set_value(pItem->GetValue());
107 else
108 m_xWidget->set_text(OUString());
109}
110
111IMPL_STATIC_LINK(SdPagesField, OutputHdl, weld::SpinButton&, rSpinButton, void)
112{
113 rSpinButton.set_text(format_number(rSpinButton.get_value()));
114}
115
116IMPL_LINK(SdPagesField, spin_button_input, int*, result, bool)
117{
119 double fResult(0.0);
120 bool bRet = vcl::TextToValue(m_xWidget->get_text(), fResult, 0, m_xWidget->get_digits(), rLocaleData, FieldUnit::NONE);
121 if (bRet)
122 {
123 if (fResult > SAL_MAX_INT32)
124 fResult = SAL_MAX_INT32;
125 else if (fResult < SAL_MIN_INT32)
126 fResult = SAL_MIN_INT32;
127 *result = fResult;
128 }
129 return bRet;
130}
131
133{
134 SfxUInt16Item aItem(SID_PAGES_PER_ROW, m_xWidget->get_value());
135
136 uno::Any a;
137 aItem.QueryValue( a );
138 uno::Sequence< beans::PropertyValue > aArgs{ comphelper::makePropertyValue("PagesPerRow", a) };
139 SfxToolBoxControl::Dispatch( ::uno::Reference< ::frame::XDispatchProvider >( m_xFrame->getController(), ::uno::UNO_QUERY ),
140 ".uno:PagesPerRow",
141 aArgs );
142}
143
145 SfxToolBoxControl( nSlotId, nId, rTbx )
146{
147}
148
150{
151}
152
154 SfxItemState eState, const SfxPoolItem* pState )
155{
156 SdPagesField* pFld = static_cast<SdPagesField*>( GetToolBox().GetItemWindow( GetId() ) );
157 DBG_ASSERT( pFld, "Window not found" );
158
159 if ( eState == SfxItemState::DISABLED )
160 {
161 pFld->set_sensitive(false);
162 }
163 else
164 {
165 pFld->set_sensitive(true);
166
167 const SfxUInt16Item* pItem = nullptr;
168 if ( eState == SfxItemState::DEFAULT )
169 {
170 pItem = dynamic_cast< const SfxUInt16Item* >( pState );
171 DBG_ASSERT( pItem, "sd::SdTbxCtlDiaPages::StateChanged(), wrong item type!" );
172 }
173
174 pFld->UpdatePagesField( pItem );
175 }
176}
177
179{
181 pWindow->Show();
182
183 return pWindow;
184}
185
186/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Image > m_xWidget
css::uno::Reference< css::lang::XComponent > m_xFrame
const LocaleDataWrapper & GetLocaleDataWrapper() const
static const AllSettings & GetSettings()
sal_uInt16 GetValue() const
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
virtual void dispose() override
void InitControlBase(weld::Widget *pWidget)
SdPagesField(vcl::Window *pParent, css::uno::Reference< css::frame::XFrame > xFrame)
Definition: diactrl.cxx:54
void UpdatePagesField(const SfxUInt16Item *pItem)
Definition: diactrl.cxx:103
std::unique_ptr< weld::SpinButton > m_xWidget
Definition: diactrl.hxx:36
virtual void dispose() override
Definition: diactrl.cxx:84
virtual ~SdPagesField() override
Definition: diactrl.cxx:90
void set_sensitive(bool bSensitive)
Definition: diactrl.cxx:95
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
Definition: diactrl.cxx:178
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: diactrl.cxx:153
virtual ~SdTbxCtlDiaPages() override
Definition: diactrl.cxx:149
SdTbxCtlDiaPages(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: diactrl.cxx:144
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)
ToolBoxItemId GetId() const
ToolBox & GetToolBox() const
vcl::Window * GetItemWindow(ToolBoxItemId nItemId) const
static VclPtr< reference_type > Create(Arg &&... arg)
virtual void SetSizePixel(const Size &rNewSize)
void Enable(bool bEnable=true, bool bChild=true)
#define DBG_ASSERT(sCon, aError)
IMPL_STATIC_LINK(SdPagesField, OutputHdl, weld::SpinButton &, rSpinButton, void)
Definition: diactrl.cxx:111
IMPL_LINK_NOARG(SdPagesField, ModifyHdl, weld::SpinButton &, void)
Definition: diactrl.cxx:132
IMPL_LINK(SdPagesField, KeyInputHdl, const KeyEvent &, rKEvt, bool)
Definition: diactrl.cxx:79
uno_Any a
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
bool TextToValue(const OUString &rStr, double &rValue, sal_Int64 nBaseValue, sal_uInt16 nDecDigits, const LocaleDataWrapper &rLocaleDataWrapper, FieldUnit eUnit)
sal_Int16 nId
SfxItemState
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
Reference< XFrame > xFrame
#define SAL_MAX_INT32
#define SAL_MIN_INT32
Any result
SFX_IMPL_TOOLBOX_CONTROL(SwTbxAutoTextCtrl, SfxVoidItem)