Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name page.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D CUI_DLLIMPLEMENTATION -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/epoxy/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/qrcodegen/cpp/ -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/liborcus/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/liborcus/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/curl/include -I /home/maarten/src/libreoffice/core/external/clew/source/include -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/cui/inc -I /home/maarten/src/libreoffice/core/cui/source/inc -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/cui/source/tabpages/page.cxx

/home/maarten/src/libreoffice/core/cui/source/tabpages/page.cxx

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 <memory>
21#include <sfx2/objsh.hxx>
22#include <sfx2/printer.hxx>
23#include <sfx2/viewsh.hxx>
24#include <svl/languageoptions.hxx>
25#include <svtools/unitconv.hxx>
26#include <vcl/svapp.hxx>
27#include <vcl/weld.hxx>
28#include <sfx2/htmlmode.hxx>
29#include <sal/macros.h>
30#include <osl/diagnose.h>
31
32#include <svx/strings.hrc>
33#include <svx/dialmgr.hxx>
34#include <page.hxx>
35#include <svx/pageitem.hxx>
36#include <editeng/brushitem.hxx>
37#include <editeng/boxitem.hxx>
38#include <editeng/shaditem.hxx>
39#include <editeng/pbinitem.hxx>
40#include <editeng/lrspitem.hxx>
41#include <editeng/ulspitem.hxx>
42#include <editeng/sizeitem.hxx>
43#include <editeng/frmdiritem.hxx>
44#include <svx/dlgutil.hxx>
45#include <editeng/paperinf.hxx>
46#include <svl/stritem.hxx>
47#include <editeng/eerdll.hxx>
48#include <editeng/editrids.hrc>
49#include <svx/svxids.hrc>
50#include <svtools/optionsdrawinglayer.hxx>
51#include <svl/slstitm.hxx>
52#include <svx/xdef.hxx>
53#include <svx/unobrushitemhelper.hxx>
54#include <svx/SvxNumOptionsTabPageHelper.hxx>
55
56// static ----------------------------------------------------------------
57
58// #i19922# - tdf#126051 see svx/source/dialog/hdft.cxx and sw/source/uibase/sidebar/PageMarginControl.hxx
59const long MINBODY = 56; // 1mm in twips rounded
60
61const sal_uInt16 SvxPageDescPage::pRanges[] =
62{
63 SID_ATTR_BORDER_OUTER( 10000 + 24 ),
64 SID_ATTR_BORDER_SHADOW( 10000 + 25 ),
65 SID_ATTR_LRSPACE( 10000 + 48 ),
66 SID_ATTR_PAGE_SHAREDTypedWhichId<SfxBoolItem>( 10000 + 61 ),
67 SID_SWREGISTER_COLLECTION( 10000 + 451 ),
68 SID_SWREGISTER_MODE( 10000 + 467 ),
69 0
70};
71// ------- Mapping page layout ------------------------------------------
72
73const SvxPageUsage aArr[] =
74{
75 SvxPageUsage::All,
76 SvxPageUsage::Mirror,
77 SvxPageUsage::Right,
78 SvxPageUsage::Left
79};
80
81
82static sal_uInt16 PageUsageToPos_Impl( SvxPageUsage nUsage )
83{
84 for ( size_t i = 0; i < SAL_N_ELEMENTS(aArr)(sizeof(sal_n_array_size(aArr))); ++i )
85 if ( aArr[i] == nUsage )
86 return i;
87 return 3;
88}
89
90
91static SvxPageUsage PosToPageUsage_Impl( sal_uInt16 nPos )
92{
93 if ( nPos >= SAL_N_ELEMENTS(aArr)(sizeof(sal_n_array_size(aArr))) )
94 return SvxPageUsage::NONE;
95 return aArr[nPos];
96}
97
98
99static Size GetMinBorderSpace_Impl( const SvxShadowItem& rShadow, const SvxBoxItem& rBox )
100{
101 Size aSz;
102 aSz.setHeight( rShadow.CalcShadowSpace( SvxShadowItemSide::BOTTOM ) + rBox.CalcLineSpace( SvxBoxItemLine::BOTTOM ) );
103 aSz.AdjustHeight(rShadow.CalcShadowSpace( SvxShadowItemSide::TOP ) + rBox.CalcLineSpace( SvxBoxItemLine::TOP ) );
104 aSz.setWidth( rShadow.CalcShadowSpace( SvxShadowItemSide::LEFT ) + rBox.CalcLineSpace( SvxBoxItemLine::LEFT ) );
105 aSz.AdjustWidth(rShadow.CalcShadowSpace( SvxShadowItemSide::RIGHT ) + rBox.CalcLineSpace( SvxBoxItemLine::RIGHT ) );
106 return aSz;
107}
108
109
110static long ConvertLong_Impl( const long nIn, MapUnit eUnit )
111{
112 return OutputDevice::LogicToLogic( nIn, eUnit, MapUnit::MapTwip );
113}
114
115static bool IsEqualSize_Impl( const SvxSizeItem* pSize, const Size& rSize )
116{
117 if ( pSize )
118 {
119 Size aSize = pSize->GetSize();
120 long nDiffW = std::abs( rSize.Width () - aSize.Width () );
121 long nDiffH = std::abs( rSize.Height() - aSize.Height() );
122 return ( nDiffW < 10 && nDiffH < 10 );
123 }
124 else
125 return false;
126}
127
128
129#define MARGIN_LEFT( MarginPosition(0x0001) ) ( MarginPosition(0x0001) )
130#define MARGIN_RIGHT( MarginPosition(0x0002) ) ( MarginPosition(0x0002) )
131#define MARGIN_TOP( MarginPosition(0x0004) ) ( MarginPosition(0x0004) )
132#define MARGIN_BOTTOM( MarginPosition(0x0008) ) ( MarginPosition(0x0008) )
133
134// class SvxPageDescPage --------------------------------------------------
135
136std::unique_ptr<SfxTabPage> SvxPageDescPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet )
137{
138 return std::make_unique<SvxPageDescPage>(pPage, pController, *rSet);
139}
140
141SvxPageDescPage::SvxPageDescPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttr)
142 : SfxTabPage(pPage, pController, "cui/ui/pageformatpage.ui", "PageFormatPage", &rAttr)
143 , bLandscape(false)
144 , eMode(SVX_PAGE_MODE_STANDARD)
145 , ePaperStart(PAPER_A3)
146 , m_nPos(0)
147 , mpDefPrinter(nullptr)
148 , mbDelPrinter(false)
149 , mbEnableDrawingLayerFillStyles(false)
150 , m_xPaperSizeBox(new SvxPaperSizeListBox(m_xBuilder->weld_combo_box("comboPageFormat")))
151 , m_xPaperWidthEdit(m_xBuilder->weld_metric_spin_button("spinWidth", FieldUnit::CM))
152 , m_xPaperHeightEdit(m_xBuilder->weld_metric_spin_button("spinHeight", FieldUnit::CM))
153 , m_xOrientationFT(m_xBuilder->weld_label("labelOrientation"))
154 , m_xPortraitBtn(m_xBuilder->weld_radio_button("radiobuttonPortrait"))
155 , m_xLandscapeBtn(m_xBuilder->weld_radio_button("radiobuttonLandscape"))
156 , m_xTextFlowLbl(m_xBuilder->weld_label("labelTextFlow"))
157 , m_xTextFlowBox(new svx::FrameDirectionListBox(m_xBuilder->weld_combo_box("comboTextFlowBox")))
158 , m_xPaperTrayBox(m_xBuilder->weld_combo_box("comboPaperTray"))
159 , m_xLeftMarginLbl(m_xBuilder->weld_label("labelLeftMargin"))
160 , m_xLeftMarginEdit(m_xBuilder->weld_metric_spin_button("spinMargLeft", FieldUnit::CM))
161 , m_xRightMarginLbl(m_xBuilder->weld_label("labelRightMargin"))
162 , m_xRightMarginEdit(m_xBuilder->weld_metric_spin_button("spinMargRight", FieldUnit::CM))
163 , m_xTopMarginEdit(m_xBuilder->weld_metric_spin_button("spinMargTop", FieldUnit::CM))
164 , m_xBottomMarginEdit(m_xBuilder->weld_metric_spin_button("spinMargBot", FieldUnit::CM))
165 , m_xPageText(m_xBuilder->weld_label("labelPageLayout"))
166 , m_xLayoutBox(m_xBuilder->weld_combo_box("comboPageLayout"))
167 , m_xNumberFormatText(m_xBuilder->weld_label("labelPageNumbers"))
168 , m_xNumberFormatBox(new SvxPageNumberListBox(m_xBuilder->weld_combo_box("comboLayoutFormat")))
169 , m_xTblAlignFT(m_xBuilder->weld_label("labelTblAlign"))
170 , m_xHorzBox(m_xBuilder->weld_check_button("checkbuttonHorz"))
171 , m_xVertBox(m_xBuilder->weld_check_button("checkbuttonVert"))
172 , m_xAdaptBox(m_xBuilder->weld_check_button("checkAdaptBox"))
173 , m_xRegisterCB(m_xBuilder->weld_check_button("checkRegisterTrue"))
174 , m_xRegisterFT(m_xBuilder->weld_label("labelRegisterStyle"))
175 , m_xRegisterLB(m_xBuilder->weld_combo_box("comboRegisterStyle"))
176 // Strings stored in UI
177 , m_xInsideLbl(m_xBuilder->weld_label("labelInner"))
178 , m_xOutsideLbl(m_xBuilder->weld_label("labelOuter"))
179 , m_xPrintRangeQueryText(m_xBuilder->weld_label("labelMsg"))
180 , m_xBspWin(new weld::CustomWeld(*m_xBuilder, "drawingareaPageDirection", m_aBspWin))
181{
182 m_xRegisterLB->set_size_request(m_xRegisterLB->get_approximate_digit_width() * 20, -1);
183
184 bBorderModified = false;
185 m_aBspWin.EnableRTL(false);
186
187 // this page needs ExchangeSupport
188 SetExchangeSupport();
189
190 SvtLanguageOptions aLangOptions;
191 bool bCJK = aLangOptions.IsAsianTypographyEnabled();
192 bool bCTL = aLangOptions.IsCTLFontEnabled();
193 bool bWeb = false;
194 const SfxPoolItem* pItem;
195
196 SfxObjectShell* pShell;
197 if(SfxItemState::SET == rAttr.GetItemState(SID_HTML_MODE(10000 + 414), false, &pItem) ||
198 ( nullptr != (pShell = SfxObjectShell::Current()) &&
199 nullptr != (pItem = pShell->GetItem(SID_HTML_MODE(10000 + 414)))))
200 bWeb = 0 != (static_cast<const SfxUInt16Item*>(pItem)->GetValue() & HTMLMODE_ON);
201
202 // fill text flow listbox with valid entries
203
204 m_xTextFlowBox->append(SvxFrameDirection::Horizontal_LR_TB, SvxResId(RID_SVXSTR_PAGEDIR_LTR_HORIreinterpret_cast<char const *>("RID_SVXSTR_PAGEDIR_LTR_HORI"
"\004" u8"Left-to-right (horizontal)")
));
205
206 if (bCTL)
207 m_xTextFlowBox->append(SvxFrameDirection::Horizontal_RL_TB, SvxResId(RID_SVXSTR_PAGEDIR_RTL_HORIreinterpret_cast<char const *>("RID_SVXSTR_PAGEDIR_RTL_HORI"
"\004" u8"Right-to-left (horizontal)")
));
208
209
210 // #109989# do not show vertical directions in Writer/Web
211 if( !bWeb && bCJK )
212 {
213 m_xTextFlowBox->append(SvxFrameDirection::Vertical_RL_TB, SvxResId(RID_SVXSTR_PAGEDIR_RTL_VERTreinterpret_cast<char const *>("RID_SVXSTR_PAGEDIR_RTL_VERT"
"\004" u8"Right-to-left (vertical)")
));
214 m_xTextFlowBox->append(SvxFrameDirection::Vertical_LR_TB, SvxResId(RID_SVXSTR_PAGEDIR_LTR_VERTreinterpret_cast<char const *>("RID_SVXSTR_PAGEDIR_LTR_VERT"
"\004" u8"Left-to-right (vertical)")
));
215 }
216
217 // #109989# show the text direction box in Writer/Web too
218 if( (bCJK || bCTL) &&
219 SfxItemState::UNKNOWN < rAttr.GetItemState(GetWhich( SID_ATTR_FRAMEDIRECTION( 10000 + 944 ) )))
220 {
221 m_xTextFlowLbl->show();
222 m_xTextFlowBox->show();
223 m_xTextFlowBox->connect_changed(LINK(this, SvxPageDescPage, FrameDirectionModify_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubFrameDirectionModify_Impl
)
);
224
225 m_aBspWin.EnableFrameDirection(true);
226 }
227 Init_Impl();
228
229 FieldUnit eFUnit = GetModuleFieldUnit( rAttr );
230 SetFieldUnit( *m_xLeftMarginEdit, eFUnit );
231 SetFieldUnit( *m_xRightMarginEdit, eFUnit );
232 SetFieldUnit( *m_xTopMarginEdit, eFUnit );
233 SetFieldUnit( *m_xBottomMarginEdit, eFUnit );
234 SetFieldUnit( *m_xPaperWidthEdit, eFUnit );
235 SetFieldUnit( *m_xPaperHeightEdit, eFUnit );
236
237 if ( SfxViewShell::Current() && SfxViewShell::Current()->GetPrinter() )
238 {
239 mpDefPrinter = SfxViewShell::Current()->GetPrinter();
240 }
241 else
242 {
243 mpDefPrinter = VclPtr<Printer>::Create();
244 mbDelPrinter = true;
245 }
246
247 MapMode aOldMode = mpDefPrinter->GetMapMode();
248 mpDefPrinter->SetMapMode(MapMode(MapUnit::MapTwip));
249
250 // set first- and last-values for the margins
251 Size aPaperSize = mpDefPrinter->GetPaperSize();
252 Size aPrintSize = mpDefPrinter->GetOutputSize();
253
254 /*
255 * To convert a point ( 0,0 ) into logic coordinates
256 * looks like nonsense; but it makes sense when the
257 * coordinate system's origin has been moved.
258 */
259 Point aPrintOffset = mpDefPrinter->GetPageOffset() - mpDefPrinter->PixelToLogic( Point() );
260 mpDefPrinter->SetMapMode( aOldMode );
261
262 nFirstLeftMargin = m_xLeftMarginEdit->convert_value_from(m_xLeftMarginEdit->normalize(aPrintOffset.X()), FieldUnit::TWIP);
263 nFirstRightMargin = m_xRightMarginEdit->convert_value_from(m_xRightMarginEdit->normalize(aPaperSize.Width() - aPrintSize.Width() - aPrintOffset.X()), FieldUnit::TWIP);
264 nFirstTopMargin = m_xTopMarginEdit->convert_value_from(m_xTopMarginEdit->normalize(aPrintOffset.Y() ), FieldUnit::TWIP);
265 nFirstBottomMargin = m_xBottomMarginEdit->convert_value_from(m_xBottomMarginEdit->normalize(aPaperSize.Height() - aPrintSize.Height() - aPrintOffset.Y()), FieldUnit::TWIP );
266 nLastLeftMargin = m_xLeftMarginEdit->convert_value_from(m_xLeftMarginEdit->normalize(aPrintOffset.X() + aPrintSize.Width()), FieldUnit::TWIP);
267 nLastRightMargin = m_xRightMarginEdit->convert_value_from(m_xRightMarginEdit->normalize(aPrintOffset.X() + aPrintSize.Width()), FieldUnit::TWIP);
268 nLastTopMargin = m_xTopMarginEdit->convert_value_from(m_xTopMarginEdit->normalize(aPrintOffset.Y() + aPrintSize.Height()), FieldUnit::TWIP);
269 nLastBottomMargin = m_xBottomMarginEdit->convert_value_from(m_xBottomMarginEdit->normalize(aPrintOffset.Y() + aPrintSize.Height()), FieldUnit::TWIP);
270
271 // #i4219# get DrawingLayer options
272 const SvtOptionsDrawinglayer aDrawinglayerOpt;
273
274 // #i4219# take Maximum now from configuration (1/100th cm)
275 // was: 11900 -> 119 cm ;new value 3 meters -> 300 cm -> 30000
276 m_xPaperWidthEdit->set_max(m_xPaperWidthEdit->normalize(aDrawinglayerOpt.GetMaximumPaperWidth()), FieldUnit::CM);
277 m_xPaperHeightEdit->set_max(m_xPaperHeightEdit->normalize(aDrawinglayerOpt.GetMaximumPaperHeight()), FieldUnit::CM);
278
279 // #i4219# also for margins (1/100th cm). Was: 9999, keeping.
280 m_xLeftMarginEdit->set_max(m_xLeftMarginEdit->normalize(aDrawinglayerOpt.GetMaximumPaperLeftMargin()), FieldUnit::MM);
281 m_xRightMarginEdit->set_max(m_xRightMarginEdit->normalize(aDrawinglayerOpt.GetMaximumPaperRightMargin()), FieldUnit::MM);
282 m_xTopMarginEdit->set_max(m_xTopMarginEdit->normalize(aDrawinglayerOpt.GetMaximumPaperTopMargin()), FieldUnit::MM);
283 m_xBottomMarginEdit->set_max(m_xBottomMarginEdit->normalize(aDrawinglayerOpt.GetMaximumPaperBottomMargin()), FieldUnit::MM);
284
285 // Get the i18n framework numberings and add them to the listbox.
286 SvxNumOptionsTabPageHelper::GetI18nNumbering(m_xNumberFormatBox->get_widget(), std::numeric_limits<sal_uInt16>::max());
287}
288
289SvxPageDescPage::~SvxPageDescPage()
290{
291 if(mbDelPrinter)
1
Assuming field 'mbDelPrinter' is true
2
Taking true branch
292 {
293 mpDefPrinter.disposeAndClear();
3
Calling 'VclPtr::disposeAndClear'
294 mbDelPrinter = false;
295 }
296}
297
298void SvxPageDescPage::Init_Impl()
299{
300 // adjust the handler
301 m_xLayoutBox->connect_changed(LINK(this, SvxPageDescPage, LayoutHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubLayoutHdl_Impl)
);
302
303 m_xPaperSizeBox->connect_changed(LINK(this, SvxPageDescPage, PaperSizeSelect_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubPaperSizeSelect_Impl
)
);
304 m_xPaperWidthEdit->connect_value_changed( LINK(this, SvxPageDescPage, PaperSizeModify_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubPaperSizeModify_Impl
)
);
305 m_xPaperHeightEdit->connect_value_changed(LINK(this, SvxPageDescPage, PaperSizeModify_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubPaperSizeModify_Impl
)
);
306 m_xLandscapeBtn->connect_clicked(LINK(this, SvxPageDescPage, SwapOrientation_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubSwapOrientation_Impl
)
);
307 m_xPortraitBtn->connect_clicked(LINK(this, SvxPageDescPage, SwapOrientation_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubSwapOrientation_Impl
)
);
308
309 Link<weld::MetricSpinButton&, void> aLink = LINK(this, SvxPageDescPage, BorderModify_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubBorderModify_Impl
)
;
310 m_xLeftMarginEdit->connect_value_changed(aLink);
311 m_xRightMarginEdit->connect_value_changed(aLink);
312 m_xTopMarginEdit->connect_value_changed(aLink);
313 m_xBottomMarginEdit->connect_value_changed(aLink);
314
315 m_xHorzBox->connect_toggled(LINK(this, SvxPageDescPage, CenterHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubCenterHdl_Impl)
);
316 m_xVertBox->connect_toggled(LINK(this, SvxPageDescPage, CenterHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubCenterHdl_Impl)
);
317}
318
319void SvxPageDescPage::Reset( const SfxItemSet* rSet )
320{
321 SfxItemPool* pPool = rSet->GetPool();
322 DBG_ASSERT( pPool, "Where is the pool?" )do { if (true && (!(pPool))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/page.cxx"
":" "322" ": "), "%s", "Where is the pool?"); } } while (false
)
;
323 MapUnit eUnit = pPool->GetMetric( GetWhich( SID_ATTR_LRSPACE( 10000 + 48 ) ) );
324
325 // adjust margins (right/left)
326 const SfxPoolItem* pItem = GetItem( *rSet, SID_ATTR_LRSPACE( 10000 + 48 ) );
327
328 if ( pItem )
329 {
330 const SvxLRSpaceItem& rLRSpace = static_cast<const SvxLRSpaceItem&>(*pItem);
331 SetMetricValue( *m_xLeftMarginEdit, rLRSpace.GetLeft(), eUnit );
332 m_aBspWin.SetLeft(
333 static_cast<sal_uInt16>(ConvertLong_Impl( rLRSpace.GetLeft(), eUnit )) );
334 SetMetricValue( *m_xRightMarginEdit, rLRSpace.GetRight(), eUnit );
335 m_aBspWin.SetRight(
336 static_cast<sal_uInt16>(ConvertLong_Impl( rLRSpace.GetRight(), eUnit )) );
337 }
338
339 // adjust margins (top/bottom)
340 pItem = GetItem( *rSet, SID_ATTR_ULSPACE( 10000 + 49 ) );
341
342 if ( pItem )
343 {
344 const SvxULSpaceItem& rULSpace = static_cast<const SvxULSpaceItem&>(*pItem);
345 SetMetricValue( *m_xTopMarginEdit, rULSpace.GetUpper(), eUnit );
346 m_aBspWin.SetTop(
347 static_cast<sal_uInt16>(ConvertLong_Impl( static_cast<long>(rULSpace.GetUpper()), eUnit )) );
348 SetMetricValue( *m_xBottomMarginEdit, rULSpace.GetLower(), eUnit );
349 m_aBspWin.SetBottom(
350 static_cast<sal_uInt16>(ConvertLong_Impl( static_cast<long>(rULSpace.GetLower()), eUnit )) );
351 }
352
353 // general page data
354 SvxNumType eNumType = SVX_NUM_ARABIC;
355 bLandscape = ( mpDefPrinter->GetOrientation() == Orientation::Landscape );
356 SvxPageUsage nUse = SvxPageUsage::All;
357 pItem = GetItem( *rSet, SID_ATTR_PAGETypedWhichId<SvxPageItem>( 10000 + 50 ) );
358
359 if ( pItem )
360 {
361 const SvxPageItem& rItem = static_cast<const SvxPageItem&>(*pItem);
362 eNumType = rItem.GetNumType();
363 nUse = rItem.GetPageUsage();
364 bLandscape = rItem.IsLandscape();
365 }
366
367 // alignment
368 m_xLayoutBox->set_active(::PageUsageToPos_Impl(nUse));
369 m_aBspWin.SetUsage( nUse );
370 LayoutHdl_Impl( *m_xLayoutBox );
371
372 //adjust numeration type of the page style
373 m_xNumberFormatBox->set_active_id(eNumType);
374
375 m_xPaperTrayBox->clear();
376 sal_uInt8 nPaperBin = PAPERBIN_PRINTER_SETTINGS(sal_uInt8(0xFF));
377 pItem = GetItem( *rSet, SID_ATTR_PAGE_PAPERBINTypedWhichId<SvxPaperBinItem>( 10000 + 54 ) );
378
379 if ( pItem )
380 {
381 nPaperBin = static_cast<const SvxPaperBinItem*>(pItem)->GetValue();
382
383 if ( nPaperBin >= mpDefPrinter->GetPaperBinCount() )
384 nPaperBin = PAPERBIN_PRINTER_SETTINGS(sal_uInt8(0xFF));
385 }
386
387 OUString aBinName;
388
389 if ( PAPERBIN_PRINTER_SETTINGS(sal_uInt8(0xFF)) == nPaperBin )
390 aBinName = EditResId(RID_SVXSTR_PAPERBIN_SETTINGSreinterpret_cast<char const *>("RID_SVXSTR_PAPERBIN_SETTINGS"
"\004" u8"[From printer settings]")
);
391 else
392 aBinName = mpDefPrinter->GetPaperBinName( static_cast<sal_uInt16>(nPaperBin) );
393
394 m_xPaperTrayBox->append(OUString::number(nPaperBin), aBinName);
395 m_xPaperTrayBox->set_active_text(aBinName);
396 // reset focus handler to default first so know none already connected
397 m_xPaperTrayBox->connect_focus_in(Link<weld::Widget&, void>());
398 // update the list when widget gets focus
399 m_xPaperTrayBox->connect_focus_in(LINK(this, SvxPageDescPage, PaperBinHdl_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubPaperBinHdl_Impl)
);
400
401 Size aPaperSize = SvxPaperInfo::GetPaperSize( mpDefPrinter );
402 pItem = GetItem( *rSet, SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) );
403
404 if ( pItem )
405 aPaperSize = static_cast<const SvxSizeItem*>(pItem)->GetSize();
406
407 bool bOrientationSupport =
408 mpDefPrinter->HasSupport( PrinterSupport::SetOrientation );
409
410 if ( !bOrientationSupport &&
411 aPaperSize.Width() > aPaperSize.Height() )
412 bLandscape = true;
413
414 // tdf#130548 disable callbacks on the other of a pair of the radiogroup
415 // when toggling its partner
416 m_xLandscapeBtn->connect_clicked(Link<weld::Button&, void>());
417 m_xPortraitBtn->connect_clicked(Link<weld::Button&, void>());
418
419 m_xLandscapeBtn->set_active(bLandscape);
420 m_xPortraitBtn->set_active(!bLandscape);
421
422 m_xLandscapeBtn->connect_clicked(LINK(this, SvxPageDescPage, SwapOrientation_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubSwapOrientation_Impl
)
);
423 m_xPortraitBtn->connect_clicked(LINK(this, SvxPageDescPage, SwapOrientation_Impl)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubSwapOrientation_Impl
)
);
424
425 m_aBspWin.SetSize( Size( ConvertLong_Impl( aPaperSize.Width(), eUnit ),
426 ConvertLong_Impl( aPaperSize.Height(), eUnit ) ) );
427
428 aPaperSize = OutputDevice::LogicToLogic(aPaperSize, MapMode(eUnit), MapMode(MapUnit::Map100thMM));
429 if ( bLandscape )
430 Swap( aPaperSize );
431
432 // Actual Paper Format
433 Paper ePaper = SvxPaperInfo::GetSvxPaper( aPaperSize, MapUnit::Map100thMM );
434
435 if ( PAPER_USER != ePaper )
436 aPaperSize = SvxPaperInfo::GetPaperSize( ePaper, MapUnit::Map100thMM );
437
438 if ( bLandscape )
439 Swap( aPaperSize );
440
441 // write values into the edits
442 SetMetricValue( *m_xPaperHeightEdit, aPaperSize.Height(), MapUnit::Map100thMM );
443 SetMetricValue( *m_xPaperWidthEdit, aPaperSize.Width(), MapUnit::Map100thMM );
444 m_xPaperSizeBox->clear();
445
446 m_xPaperSizeBox->FillPaperSizeEntries( ( ePaperStart == PAPER_A3 ) ? PaperSizeApp::Std : PaperSizeApp::Draw );
447 m_xPaperSizeBox->set_active_id( ePaper );
448
449 // application specific
450
451 switch ( eMode )
452 {
453 case SVX_PAGE_MODE_CENTER:
454 {
455 m_xTblAlignFT->show();
456 m_xHorzBox->show();
457 m_xVertBox->show();
458 DisableVerticalPageDir();
459
460 // horizontal alignment
461 pItem = GetItem( *rSet, SID_ATTR_PAGE_EXT1( 10000 + 55 ) );
462 m_xHorzBox->set_active(pItem && static_cast<const SfxBoolItem*>(pItem)->GetValue());
463
464 // vertical alignment
465 pItem = GetItem( *rSet, SID_ATTR_PAGE_EXT2TypedWhichId<SfxBoolItem>( 10000 + 56 ) );
466 m_xVertBox->set_active(pItem && static_cast<const SfxBoolItem*>(pItem)->GetValue());
467
468 // set example window on the table
469 m_aBspWin.SetTable( true );
470 m_aBspWin.SetHorz(m_xHorzBox->get_active());
471 m_aBspWin.SetVert(m_xVertBox->get_active());
472
473 break;
474 }
475
476 case SVX_PAGE_MODE_PRESENTATION:
477 {
478 DisableVerticalPageDir();
479 m_xAdaptBox->show();
480 pItem = GetItem( *rSet, SID_ATTR_PAGE_EXT1( 10000 + 55 ) );
481 m_xAdaptBox->set_active( pItem &&
482 static_cast<const SfxBoolItem*>(pItem)->GetValue() );
483
484 //!!! hidden, because not implemented by StarDraw
485 m_xLayoutBox->hide();
486 m_xPageText->hide();
487
488 break;
489 }
490 default: ;//prevent warning
491 }
492
493
494 // display background and border in the example
495 ResetBackground_Impl( *rSet );
496//! UpdateExample_Impl();
497 RangeHdl_Impl();
498
499 InitHeadFoot_Impl( *rSet );
500
501 bBorderModified = false;
502 SwapFirstValues_Impl( false );
503 UpdateExample_Impl();
504
505 m_xLeftMarginEdit->save_value();
506 m_xRightMarginEdit->save_value();
507 m_xTopMarginEdit->save_value();
508 m_xBottomMarginEdit->save_value();
509 m_xLayoutBox->save_value();
510 m_xNumberFormatBox->save_value();
511 m_xPaperSizeBox->save_value();
512 m_xPaperWidthEdit->save_value();
513 m_xPaperHeightEdit->save_value();
514 m_xPortraitBtn->save_state();
515 m_xLandscapeBtn->save_state();
516 m_xPaperTrayBox->save_value();
517 m_xVertBox->save_state();
518 m_xHorzBox->save_state();
519 m_xAdaptBox->save_state();
520
521 CheckMarginEdits( true );
522
523
524 if(SfxItemState::SET == rSet->GetItemState(SID_SWREGISTER_MODE( 10000 + 467 )))
525 {
526 m_xRegisterCB->set_active(static_cast<const SfxBoolItem&>(rSet->Get(
527 SID_SWREGISTER_MODE( 10000 + 467 ))).GetValue());
528 m_xRegisterCB->save_state();
529 RegisterModify(*m_xRegisterCB);
530 }
531 if(SfxItemState::SET == rSet->GetItemState(SID_SWREGISTER_COLLECTION( 10000 + 451 )))
532 {
533 m_xRegisterLB->set_active_text(
534 static_cast<const SfxStringItem&>(rSet->Get(SID_SWREGISTER_COLLECTION( 10000 + 451 ))).GetValue());
535 m_xRegisterLB->save_value();
536 }
537
538 SfxItemState eState = rSet->GetItemState( GetWhich( SID_ATTR_FRAMEDIRECTION( 10000 + 944 ) ),
539 true, &pItem );
540 if( SfxItemState::UNKNOWN != eState )
541 {
542 SvxFrameDirection nVal = SfxItemState::SET == eState
543 ? static_cast<const SvxFrameDirectionItem*>(pItem)->GetValue()
544 : SvxFrameDirection::Horizontal_LR_TB;
545 m_xTextFlowBox->set_active_id(nVal);
546
547 m_xTextFlowBox->save_value();
548 m_aBspWin.SetFrameDirection(nVal);
549 }
550}
551
552void SvxPageDescPage::FillUserData()
553{
554 if (SVX_PAGE_MODE_PRESENTATION == eMode)
555 SetUserData(m_xAdaptBox->get_active() ? OUString("1") : OUString("0")) ;
556
557}
558
559bool SvxPageDescPage::FillItemSet( SfxItemSet* rSet )
560{
561 bool bModified = false;
562 const SfxItemSet& rOldSet = GetItemSet();
563 SfxItemPool* pPool = rOldSet.GetPool();
564 DBG_ASSERT( pPool, "Where is the pool?" )do { if (true && (!(pPool))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/page.cxx"
":" "564" ": "), "%s", "Where is the pool?"); } } while (false
)
;
565 sal_uInt16 nWhich = GetWhich( SID_ATTR_LRSPACE( 10000 + 48 ) );
566 MapUnit eUnit = pPool->GetMetric( nWhich );
567 const SfxPoolItem* pOld = nullptr;
568
569 // copy old left and right margins
570 SvxLRSpaceItem aMargin( static_cast<const SvxLRSpaceItem&>(rOldSet.Get( nWhich )) );
571
572 // copy old top and bottom margins
573 nWhich = GetWhich( SID_ATTR_ULSPACE( 10000 + 49 ) );
574 SvxULSpaceItem aTopMargin( static_cast<const SvxULSpaceItem&>(rOldSet.Get( nWhich )) );
575
576 if (m_xLeftMarginEdit->get_value_changed_from_saved())
577 {
578 aMargin.SetLeft( static_cast<sal_uInt16>(GetCoreValue( *m_xLeftMarginEdit, eUnit )) );
579 bModified = true;
580 }
581
582 if (m_xRightMarginEdit->get_value_changed_from_saved())
583 {
584 aMargin.SetRight( static_cast<sal_uInt16>(GetCoreValue( *m_xRightMarginEdit, eUnit )) );
585 bModified = true;
586 }
587
588 // set left and right margins
589 if (bModified)
590 {
591 pOld = GetOldItem( *rSet, SID_ATTR_LRSPACE( 10000 + 48 ) );
592
593 if ( !pOld || *static_cast<const SvxLRSpaceItem*>(pOld) != aMargin )
594 rSet->Put( aMargin );
595 else
596 bModified = false;
597 }
598
599 bool bMod = false;
600
601 if (m_xTopMarginEdit->get_value_changed_from_saved())
602 {
603 aTopMargin.SetUpper( static_cast<sal_uInt16>(GetCoreValue( *m_xTopMarginEdit, eUnit )) );
604 bMod = true;
605 }
606
607 if (m_xBottomMarginEdit->get_value_changed_from_saved())
608 {
609 aTopMargin.SetLower( static_cast<sal_uInt16>(GetCoreValue( *m_xBottomMarginEdit, eUnit )) );
610 bMod = true;
611 }
612
613 // set top and bottom margins
614
615 if ( bMod )
616 {
617 pOld = GetOldItem( *rSet, SID_ATTR_ULSPACE( 10000 + 49 ) );
618
619 if ( !pOld || *static_cast<const SvxULSpaceItem*>(pOld) != aTopMargin )
620 {
621 bModified = true;
622 rSet->Put( aTopMargin );
623 }
624 }
625
626 // paper tray
627 nWhich = GetWhich( SID_ATTR_PAGE_PAPERBINTypedWhichId<SvxPaperBinItem>( 10000 + 54 ) );
628 sal_Int32 nPos = m_xPaperTrayBox->get_active();
629 sal_uInt16 nBin = m_xPaperTrayBox->get_id(nPos).toInt32();
630 pOld = GetOldItem( *rSet, SID_ATTR_PAGE_PAPERBINTypedWhichId<SvxPaperBinItem>( 10000 + 54 ) );
631
632 if ( !pOld || static_cast<const SvxPaperBinItem*>(pOld)->GetValue() != nBin )
633 {
634 rSet->Put( SvxPaperBinItem( nWhich, static_cast<sal_uInt8>(nBin) ) );
635 bModified = true;
636 }
637
638 Paper ePaper = m_xPaperSizeBox->get_active_id();
639 bool bChecked = m_xLandscapeBtn->get_active();
640
641 if ( PAPER_USER == ePaper )
642 {
643 if ( m_xPaperSizeBox->get_value_changed_from_saved() ||
644 m_xPaperWidthEdit->get_value_changed_from_saved() ||
645 m_xPaperHeightEdit->get_value_changed_from_saved() ||
646 m_xLandscapeBtn->get_state_changed_from_saved() )
647 {
648 Size aSize( GetCoreValue( *m_xPaperWidthEdit, eUnit ),
649 GetCoreValue( *m_xPaperHeightEdit, eUnit ) );
650 pOld = GetOldItem( *rSet, SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) );
651
652 if ( !pOld || static_cast<const SvxSizeItem*>(pOld)->GetSize() != aSize )
653 {
654 rSet->Put( SvxSizeItem( GetWhich(SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 )), aSize ) );
655 bModified = true;
656 }
657 }
658 }
659 else
660 {
661 if (m_xPaperSizeBox->get_value_changed_from_saved() || m_xLandscapeBtn->get_state_changed_from_saved())
662 {
663 Size aSize( SvxPaperInfo::GetPaperSize( ePaper, eUnit ) );
664
665 if ( bChecked )
666 Swap( aSize );
667
668 pOld = GetOldItem( *rSet, SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) );
669
670 if ( !pOld || static_cast<const SvxSizeItem*>(pOld)->GetSize() != aSize )
671 {
672 rSet->Put( SvxSizeItem( GetWhich(SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 )), aSize ) );
673 bModified = true;
674 }
675 }
676 }
677
678 nWhich = GetWhich( SID_ATTR_PAGETypedWhichId<SvxPageItem>( 10000 + 50 ) );
679 SvxPageItem aPage( static_cast<const SvxPageItem&>(rOldSet.Get( nWhich )) );
680 bMod = m_xLayoutBox->get_value_changed_from_saved();
681
682 if ( bMod )
683 aPage.SetPageUsage(::PosToPageUsage_Impl(m_xLayoutBox->get_active()));
684
685 if (m_xLandscapeBtn->get_state_changed_from_saved())
686 {
687 aPage.SetLandscape(bChecked);
688 bMod = true;
689 }
690
691 //Get the NumType value
692 if (m_xNumberFormatBox->get_value_changed_from_saved())
693 {
694 SvxNumType nEntryData = m_xNumberFormatBox->get_active_id();
695 aPage.SetNumType( nEntryData );
696 bMod = true;
697 }
698
699 if ( bMod )
700 {
701 pOld = GetOldItem( *rSet, SID_ATTR_PAGETypedWhichId<SvxPageItem>( 10000 + 50 ) );
702
703 if ( !pOld || *static_cast<const SvxPageItem*>(pOld) != aPage )
704 {
705 rSet->Put( aPage );
706 bModified = true;
707 }
708 }
709 else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich ) )
710 rSet->ClearItem( nWhich );
711 else
712 rSet->Put( rOldSet.Get( nWhich ) );
713
714 // evaluate mode specific controls
715
716 switch ( eMode )
717 {
718 case SVX_PAGE_MODE_CENTER:
719 {
720 if (m_xHorzBox->get_state_changed_from_saved())
721 {
722 SfxBoolItem aHorz( GetWhich( SID_ATTR_PAGE_EXT1( 10000 + 55 ) ),
723 m_xHorzBox->get_active() );
724 rSet->Put( aHorz );
725 bModified = true;
726 }
727
728 if (m_xVertBox->get_state_changed_from_saved())
729 {
730 SfxBoolItem aVert( GetWhich( SID_ATTR_PAGE_EXT2TypedWhichId<SfxBoolItem>( 10000 + 56 ) ),
731 m_xVertBox->get_active() );
732 rSet->Put( aVert );
733 bModified = true;
734 }
735 break;
736 }
737
738 case SVX_PAGE_MODE_PRESENTATION:
739 {
740 // always put so that draw can evaluate this
741 rSet->Put( SfxBoolItem( GetWhich( SID_ATTR_PAGE_EXT1( 10000 + 55 ) ),
742 m_xAdaptBox->get_active() ) );
743 bModified = true;
744 break;
745 }
746 default: ;//prevent warning
747
748 }
749
750 if (m_xRegisterCB->get_visible() &&
751 (m_xRegisterCB->get_active() || m_xRegisterCB->get_state_changed_from_saved()))
752 {
753 const SfxBoolItem& rRegItem = static_cast<const SfxBoolItem&>(rOldSet.Get(SID_SWREGISTER_MODE( 10000 + 467 )));
754 std::unique_ptr<SfxBoolItem> pRegItem(rRegItem.Clone());
755 bool bCheck = m_xRegisterCB->get_active();
756 pRegItem->SetValue(bCheck);
757 rSet->Put(std::move(pRegItem));
758 bModified = true;
759 if(bCheck)
760 {
761 bModified = true;
762 rSet->Put(SfxStringItem(SID_SWREGISTER_COLLECTION( 10000 + 451 ),
763 m_xRegisterLB->get_active_text()));
764 }
765 }
766
767 if (m_xTextFlowBox->get_visible() && m_xTextFlowBox->get_value_changed_from_saved())
768 {
769 SvxFrameDirection eDirection = m_xTextFlowBox->get_active_id();
770 rSet->Put( SvxFrameDirectionItem( eDirection, GetWhich( SID_ATTR_FRAMEDIRECTION( 10000 + 944 ) ) ) );
771 bModified = true;
772 }
773
774 return bModified;
775}
776
777IMPL_LINK_NOARG(SvxPageDescPage, LayoutHdl_Impl, weld::ComboBox&, void)void SvxPageDescPage::LinkStubLayoutHdl_Impl(void * instance,
weld::ComboBox& data) { return static_cast<SvxPageDescPage
*>(instance)->LayoutHdl_Impl(data); } void SvxPageDescPage
::LayoutHdl_Impl(__attribute__ ((unused)) weld::ComboBox&
)
778{
779 // switch inside outside
780 const SvxPageUsage nUsage = PosToPageUsage_Impl(m_xLayoutBox->get_active());
781
782 if (nUsage == SvxPageUsage::Mirror)
783 {
784 m_xLeftMarginLbl->hide();
785 m_xRightMarginLbl->hide();
786 m_xInsideLbl->show();
787 m_xOutsideLbl->show();
788 }
789 else
790 {
791 m_xLeftMarginLbl->show();
792 m_xRightMarginLbl->show();
793 m_xInsideLbl->hide();
794 m_xOutsideLbl->hide();
795 }
796 UpdateExample_Impl( true );
797}
798
799IMPL_LINK_NOARG(SvxPageDescPage, PaperBinHdl_Impl, weld::Widget&, void)void SvxPageDescPage::LinkStubPaperBinHdl_Impl(void * instance
, weld::Widget& data) { return static_cast<SvxPageDescPage
*>(instance)->PaperBinHdl_Impl(data); } void SvxPageDescPage
::PaperBinHdl_Impl(__attribute__ ((unused)) weld::Widget&
)
800{
801 // tdf#124226 disconnect so not called again, unless Reset occurs
802 m_xPaperTrayBox->connect_focus_in(Link<weld::Widget&, void>());
803
804 OUString aOldName = m_xPaperTrayBox->get_active_text();
805 m_xPaperTrayBox->freeze();
806 m_xPaperTrayBox->clear();
807 m_xPaperTrayBox->append(OUString::number(PAPERBIN_PRINTER_SETTINGS(sal_uInt8(0xFF))), EditResId(RID_SVXSTR_PAPERBIN_SETTINGSreinterpret_cast<char const *>("RID_SVXSTR_PAPERBIN_SETTINGS"
"\004" u8"[From printer settings]")
));
808 OUString aPaperBin(EditResId(RID_SVXSTR_PAPERBINreinterpret_cast<char const *>("RID_SVXSTR_PAPERBIN" "\004"
u8"Paper tray")
));
809 const sal_uInt16 nBinCount = mpDefPrinter->GetPaperBinCount();
810
811 for (sal_uInt16 i = 0; i < nBinCount; ++i)
812 {
813 OUString aName = mpDefPrinter->GetPaperBinName(i);
814 if (aName.isEmpty())
815 {
816 aName = aPaperBin + " " + OUString::number( i+1 );
817 }
818 m_xPaperTrayBox->append(OUString::number(i), aName);
819 }
820 m_xPaperTrayBox->set_active_text(aOldName);
821 m_xPaperTrayBox->thaw();
822
823 // tdf#123650 explicitly grab-focus after the modification otherwise gtk loses track
824 // of there the focus should be
825 m_xPaperTrayBox->grab_focus();
826}
827
828IMPL_LINK_NOARG(SvxPageDescPage, PaperSizeSelect_Impl, weld::ComboBox&, void)void SvxPageDescPage::LinkStubPaperSizeSelect_Impl(void * instance
, weld::ComboBox& data) { return static_cast<SvxPageDescPage
*>(instance)->PaperSizeSelect_Impl(data); } void SvxPageDescPage
::PaperSizeSelect_Impl(__attribute__ ((unused)) weld::ComboBox
&)
829{
830 Paper ePaper = m_xPaperSizeBox->get_active_id();
831
832 if ( ePaper == PAPER_USER )
833 return;
834
835 Size aSize( SvxPaperInfo::GetPaperSize( ePaper, MapUnit::Map100thMM ) );
836
837 if (m_xLandscapeBtn->get_active())
838 Swap( aSize );
839
840 if ( aSize.Height() < m_xPaperHeightEdit->get_min( FieldUnit::MM_100TH ) )
841 m_xPaperHeightEdit->set_min(
842 m_xPaperHeightEdit->normalize( aSize.Height() ), FieldUnit::MM_100TH );
843 if ( aSize.Width() < m_xPaperWidthEdit->get_min( FieldUnit::MM_100TH ) )
844 m_xPaperWidthEdit->set_min(
845 m_xPaperWidthEdit->normalize( aSize.Width() ), FieldUnit::MM_100TH );
846 SetMetricValue( *m_xPaperHeightEdit, aSize.Height(), MapUnit::Map100thMM );
847 SetMetricValue( *m_xPaperWidthEdit, aSize.Width(), MapUnit::Map100thMM );
848
849 CalcMargin_Impl();
850
851 RangeHdl_Impl();
852 UpdateExample_Impl( true );
853
854 if ( eMode != SVX_PAGE_MODE_PRESENTATION )
855 return;
856
857 // Draw: if paper format the margin shall be 1 cm
858 long nTmp = 0;
859 bool bScreen = (( PAPER_SCREEN_4_3 == ePaper )||( PAPER_SCREEN_16_9 == ePaper)||( PAPER_SCREEN_16_10 == ePaper));
860
861 if ( !bScreen )
862 // no margin if screen
863 nTmp = 1; // accordingly 1 cm
864
865 if ( bScreen || m_xRightMarginEdit->get_value(FieldUnit::NONE) == 0 )
866 SetMetricValue( *m_xRightMarginEdit, nTmp, MapUnit::MapCM );
867 if ( bScreen || m_xLeftMarginEdit->get_value(FieldUnit::NONE) == 0 )
868 SetMetricValue( *m_xLeftMarginEdit, nTmp, MapUnit::MapCM );
869 if ( bScreen || m_xBottomMarginEdit->get_value(FieldUnit::NONE) == 0 )
870 SetMetricValue( *m_xBottomMarginEdit, nTmp, MapUnit::MapCM );
871 if ( bScreen || m_xTopMarginEdit->get_value(FieldUnit::NONE) == 0 )
872 SetMetricValue( *m_xTopMarginEdit, nTmp, MapUnit::MapCM );
873 UpdateExample_Impl( true );
874}
875
876IMPL_LINK_NOARG(SvxPageDescPage, PaperSizeModify_Impl, weld::MetricSpinButton&, void)void SvxPageDescPage::LinkStubPaperSizeModify_Impl(void * instance
, weld::MetricSpinButton& data) { return static_cast<SvxPageDescPage
*>(instance)->PaperSizeModify_Impl(data); } void SvxPageDescPage
::PaperSizeModify_Impl(__attribute__ ((unused)) weld::MetricSpinButton
&)
877{
878 sal_uInt16 nWhich = GetWhich( SID_ATTR_LRSPACE( 10000 + 48 ) );
879 MapUnit eUnit = GetItemSet().GetPool()->GetMetric( nWhich );
880 Size aSize( GetCoreValue( *m_xPaperWidthEdit, eUnit ),
881 GetCoreValue( *m_xPaperHeightEdit, eUnit ) );
882
883 if ( aSize.Width() > aSize.Height() )
884 {
885 m_xLandscapeBtn->set_active(true);
886 bLandscape = true;
887 }
888 else
889 {
890 m_xPortraitBtn->set_active(true);
891 bLandscape = false;
892 }
893
894 Paper ePaper = SvxPaperInfo::GetSvxPaper( aSize, eUnit );
895 m_xPaperSizeBox->set_active_id( ePaper );
896 UpdateExample_Impl( true );
897
898 RangeHdl_Impl();
899}
900
901IMPL_LINK(SvxPageDescPage, SwapOrientation_Impl, weld::Button&, rBtn, void)void SvxPageDescPage::LinkStubSwapOrientation_Impl(void * instance
, weld::Button& data) { return static_cast<SvxPageDescPage
*>(instance)->SwapOrientation_Impl(data); } void SvxPageDescPage
::SwapOrientation_Impl(weld::Button& rBtn)
902{
903 if (
904 !((!bLandscape && &rBtn == m_xLandscapeBtn.get()) ||
905 (bLandscape && &rBtn == m_xPortraitBtn.get()))
906 )
907 return;
908
909 bLandscape = m_xLandscapeBtn->get_active();
910
911 const long lWidth = GetCoreValue( *m_xPaperWidthEdit, MapUnit::Map100thMM );
912 const long lHeight = GetCoreValue( *m_xPaperHeightEdit, MapUnit::Map100thMM );
913
914 // swap width and height
915 SetMetricValue(*m_xPaperWidthEdit, lHeight, MapUnit::Map100thMM);
916 SetMetricValue(*m_xPaperHeightEdit, lWidth, MapUnit::Map100thMM);
917
918 // recalculate margins if necessary
919 CalcMargin_Impl();
920
921 PaperSizeSelect_Impl(m_xPaperSizeBox->get_widget());
922 RangeHdl_Impl();
923 SwapFirstValues_Impl(bBorderModified);
924 UpdateExample_Impl(true);
925}
926
927void SvxPageDescPage::SwapFirstValues_Impl( bool bSet )
928{
929 MapMode aOldMode = mpDefPrinter->GetMapMode();
930 Orientation eOri = Orientation::Portrait;
931
932 if ( bLandscape )
933 eOri = Orientation::Landscape;
934 Orientation eOldOri = mpDefPrinter->GetOrientation();
935 mpDefPrinter->SetOrientation( eOri );
936 mpDefPrinter->SetMapMode(MapMode(MapUnit::MapTwip));
937
938 // set first- and last-values for margins
939 Size aPaperSize = mpDefPrinter->GetPaperSize();
940 Size aPrintSize = mpDefPrinter->GetOutputSize();
941 /*
942 * To convert a point ( 0,0 ) into logic coordinates
943 * looks like nonsense; but it makes sense if the
944 * coordinate system's origin has been moved.
945 */
946 Point aPrintOffset = mpDefPrinter->GetPageOffset() - mpDefPrinter->PixelToLogic( Point() );
947 mpDefPrinter->SetMapMode( aOldMode );
948 mpDefPrinter->SetOrientation( eOldOri );
949
950 sal_Int64 nSetL = m_xLeftMarginEdit->denormalize(
951 m_xLeftMarginEdit->get_value( FieldUnit::TWIP ) );
952 sal_Int64 nSetR = m_xRightMarginEdit->denormalize(
953 m_xRightMarginEdit->get_value( FieldUnit::TWIP ) );
954 sal_Int64 nSetT = m_xTopMarginEdit->denormalize(
955 m_xTopMarginEdit->get_value( FieldUnit::TWIP ) );
956 sal_Int64 nSetB = m_xBottomMarginEdit->denormalize(
957 m_xBottomMarginEdit->get_value( FieldUnit::TWIP ) );
958
959 long nNewL = aPrintOffset.X();
960 long nNewR = aPaperSize.Width() - aPrintSize.Width() - aPrintOffset.X();
961 long nNewT = aPrintOffset.Y();
962 long nNewB = aPaperSize.Height() - aPrintSize.Height() - aPrintOffset.Y();
963
964 nFirstLeftMargin = m_xLeftMarginEdit->convert_value_from(m_xLeftMarginEdit->normalize(nNewL), FieldUnit::TWIP);
965 nFirstRightMargin = m_xRightMarginEdit->convert_value_from(m_xRightMarginEdit->normalize(nNewR), FieldUnit::TWIP);
966 nFirstTopMargin = m_xTopMarginEdit->convert_value_from(m_xTopMarginEdit->normalize(nNewT), FieldUnit::TWIP);
967 nFirstBottomMargin = m_xBottomMarginEdit->convert_value_from(m_xBottomMarginEdit->normalize(nNewB), FieldUnit::TWIP);
968
969 if ( !bSet )
970 return;
971
972 if ( nSetL < nNewL )
973 m_xLeftMarginEdit->set_value( m_xLeftMarginEdit->normalize( nNewL ),
974 FieldUnit::TWIP );
975 if ( nSetR < nNewR )
976 m_xRightMarginEdit->set_value( m_xRightMarginEdit->normalize( nNewR ),
977 FieldUnit::TWIP );
978 if ( nSetT < nNewT )
979 m_xTopMarginEdit->set_value( m_xTopMarginEdit->normalize( nNewT ),
980 FieldUnit::TWIP );
981 if ( nSetB < nNewB )
982 m_xBottomMarginEdit->set_value( m_xBottomMarginEdit->normalize( nNewB ),
983 FieldUnit::TWIP );
984}
985
986IMPL_LINK_NOARG(SvxPageDescPage, BorderModify_Impl, weld::MetricSpinButton&, void)void SvxPageDescPage::LinkStubBorderModify_Impl(void * instance
, weld::MetricSpinButton& data) { return static_cast<SvxPageDescPage
*>(instance)->BorderModify_Impl(data); } void SvxPageDescPage
::BorderModify_Impl(__attribute__ ((unused)) weld::MetricSpinButton
&)
987{
988 if ( !bBorderModified )
989 bBorderModified = true;
990 UpdateExample_Impl();
991
992 RangeHdl_Impl();
993}
994
995void SvxPageDescPage::UpdateExample_Impl( bool bResetbackground )
996{
997 // Size
998 Size aSize( GetCoreValue( *m_xPaperWidthEdit, MapUnit::MapTwip ),
999 GetCoreValue( *m_xPaperHeightEdit, MapUnit::MapTwip ) );
1000
1001 m_aBspWin.SetSize( aSize );
1002
1003 // Margins
1004 m_aBspWin.SetTop( GetCoreValue( *m_xTopMarginEdit, MapUnit::MapTwip ) );
1005 m_aBspWin.SetBottom( GetCoreValue( *m_xBottomMarginEdit, MapUnit::MapTwip ) );
1006 m_aBspWin.SetLeft( GetCoreValue( *m_xLeftMarginEdit, MapUnit::MapTwip ) );
1007 m_aBspWin.SetRight( GetCoreValue( *m_xRightMarginEdit, MapUnit::MapTwip ) );
1008
1009 // Layout
1010 m_aBspWin.SetUsage(PosToPageUsage_Impl(m_xLayoutBox->get_active()));
1011 if ( bResetbackground )
1012 m_aBspWin.ResetBackground();
1013 m_aBspWin.Invalidate();
1014}
1015
1016
1017void SvxPageDescPage::ResetBackground_Impl(const SfxItemSet& rSet)
1018{
1019 sal_uInt16 nWhich(GetWhich(SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 )));
1020
1021 if (SfxItemState::SET == rSet.GetItemState(nWhich, false))
1022 {
1023 const SvxSetItem& rSetItem = static_cast< const SvxSetItem& >(rSet.Get(nWhich, false));
1024 const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
1025 const SfxBoolItem& rOn = static_cast< const SfxBoolItem& >(rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ONTypedWhichId<SfxBoolItem>( 10000 + 59 ))));
1026
1027 if(rOn.GetValue())
1028 {
1029 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aHeaderFillAttributes;
1030
1031 if(mbEnableDrawingLayerFillStyles)
1032 {
1033 // create FillAttributes directly from DrawingLayer FillStyle entries
1034 aHeaderFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(rTmpSet);
1035 }
1036 else
1037 {
1038 nWhich = GetWhich(SID_ATTR_BRUSH( 10000 + 1 ));
1039
1040 if(SfxItemState::SET == rTmpSet.GetItemState(nWhich))
1041 {
1042 // create FillAttributes from SvxBrushItem
1043 const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rTmpSet.Get(nWhich));
1044 SfxItemSet aTempSet(*rTmpSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
1045
1046 setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
1047 aHeaderFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet);
1048 }
1049 }
1050
1051 m_aBspWin.setHeaderFillAttributes(aHeaderFillAttributes);
1052 }
1053 }
1054
1055 nWhich = GetWhich(SID_ATTR_PAGE_FOOTERSETTypedWhichId<SvxSetItem>( 10000 + 58 ));
1056
1057 if (SfxItemState::SET == rSet.GetItemState(nWhich, false))
1058 {
1059 const SvxSetItem& rSetItem = static_cast< const SvxSetItem& >(rSet.Get(nWhich,false));
1060 const SfxItemSet& rTmpSet = rSetItem.GetItemSet();
1061 const SfxBoolItem& rOn = static_cast< const SfxBoolItem& >(rTmpSet.Get(GetWhich(SID_ATTR_PAGE_ONTypedWhichId<SfxBoolItem>( 10000 + 59 ))));
1062
1063 if(rOn.GetValue())
1064 {
1065 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFooterFillAttributes;
1066
1067 if(mbEnableDrawingLayerFillStyles)
1068 {
1069 // create FillAttributes directly from DrawingLayer FillStyle entries
1070 aFooterFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(rTmpSet);
1071 }
1072 else
1073 {
1074 nWhich = GetWhich(SID_ATTR_BRUSH( 10000 + 1 ));
1075
1076 if(SfxItemState::SET == rTmpSet.GetItemState(nWhich))
1077 {
1078 // create FillAttributes from SvxBrushItem
1079 const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rTmpSet.Get(nWhich));
1080 SfxItemSet aTempSet(*rTmpSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
1081
1082 setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
1083 aFooterFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet);
1084 }
1085 }
1086
1087 m_aBspWin.setFooterFillAttributes(aFooterFillAttributes);
1088 }
1089 }
1090
1091 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aPageFillAttributes;
1092
1093 if(mbEnableDrawingLayerFillStyles)
1094 {
1095 // create FillAttributes directly from DrawingLayer FillStyle entries
1096 aPageFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(rSet);
1097 }
1098 else
1099 {
1100 const SfxPoolItem* pItem = GetItem(rSet, SID_ATTR_BRUSH( 10000 + 1 ));
1101
1102 if(pItem)
1103 {
1104 // create FillAttributes from SvxBrushItem
1105 const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(*pItem);
1106 SfxItemSet aTempSet(*rSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
1107
1108 setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
1109 aPageFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet);
1110 }
1111 }
1112
1113 m_aBspWin.setPageFillAttributes(aPageFillAttributes);
1114}
1115
1116void SvxPageDescPage::InitHeadFoot_Impl( const SfxItemSet& rSet )
1117{
1118 bLandscape = m_xLandscapeBtn->get_active();
1119 const SfxPoolItem* pItem = GetItem( rSet, SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) );
1120
1121 if ( pItem )
1122 m_aBspWin.SetSize( static_cast<const SvxSizeItem*>(pItem)->GetSize() );
1123
1124 const SvxSetItem* pSetItem = nullptr;
1125
1126 // evaluate header attributes
1127
1128 if ( SfxItemState::SET ==
1129 rSet.GetItemState( GetWhich( SID_ATTR_PAGE_HEADERSETTypedWhichId<SvxSetItem>( 10000 + 57 ) ),
1130 false, reinterpret_cast<const SfxPoolItem**>(&pSetItem) ) )
1131 {
1132 const SfxItemSet& rHeaderSet = pSetItem->GetItemSet();
1133 const SfxBoolItem& rHeaderOn =
1134 static_cast<const SfxBoolItem&>(rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_ONTypedWhichId<SfxBoolItem>( 10000 + 59 ) ) ));
1135
1136 if ( rHeaderOn.GetValue() )
1137 {
1138 const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>(
1139 rHeaderSet.Get( GetWhich( SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) ) ));
1140 const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>(
1141 rHeaderSet.Get( GetWhich( SID_ATTR_ULSPACE( 10000 + 49 ) ) ));
1142 long nDist = rUL.GetLower();
1143 m_aBspWin.SetHdHeight( rSize.GetSize().Height() - nDist );
1144 m_aBspWin.SetHdDist( nDist );
1145 const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>(
1146 rHeaderSet.Get( GetWhich( SID_ATTR_LRSPACE( 10000 + 48 ) ) ));
1147 m_aBspWin.SetHdLeft( rLR.GetLeft() );
1148 m_aBspWin.SetHdRight( rLR.GetRight() );
1149 m_aBspWin.SetHeader( true );
1150 }
1151 else
1152 m_aBspWin.SetHeader( false );
1153
1154 // show background and border in the example
1155 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aHeaderFillAttributes;
1156
1157 if(mbEnableDrawingLayerFillStyles)
1158 {
1159 // create FillAttributes directly from DrawingLayer FillStyle entries
1160 aHeaderFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(rHeaderSet);
1161 }
1162 else
1163 {
1164 const sal_uInt16 nWhich(GetWhich(SID_ATTR_BRUSH( 10000 + 1 )));
1165
1166 if(rHeaderSet.GetItemState(nWhich) >= SfxItemState::DEFAULT)
1167 {
1168 // aBspWin.SetHdColor(rItem.GetColor());
1169 const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rHeaderSet.Get(nWhich));
1170 SfxItemSet aTempSet(*rHeaderSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
1171
1172 setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
1173 aHeaderFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet);
1174 }
1175 }
1176
1177 m_aBspWin.setHeaderFillAttributes(aHeaderFillAttributes);
1178 }
1179
1180 // evaluate footer attributes
1181
1182 if ( SfxItemState::SET !=
1183 rSet.GetItemState( GetWhich( SID_ATTR_PAGE_FOOTERSETTypedWhichId<SvxSetItem>( 10000 + 58 ) ),
1184 false, reinterpret_cast<const SfxPoolItem**>(&pSetItem) ) )
1185 return;
1186
1187 const SfxItemSet& rFooterSet = pSetItem->GetItemSet();
1188 const SfxBoolItem& rFooterOn =
1189 static_cast<const SfxBoolItem&>(rFooterSet.Get( GetWhich( SID_ATTR_PAGE_ONTypedWhichId<SfxBoolItem>( 10000 + 59 ) ) ));
1190
1191 if ( rFooterOn.GetValue() )
1192 {
1193 const SvxSizeItem& rSize = static_cast<const SvxSizeItem&>(
1194 rFooterSet.Get( GetWhich( SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) ) ));
1195 const SvxULSpaceItem& rUL = static_cast<const SvxULSpaceItem&>(
1196 rFooterSet.Get( GetWhich( SID_ATTR_ULSPACE( 10000 + 49 ) ) ));
1197 long nDist = rUL.GetUpper();
1198 m_aBspWin.SetFtHeight( rSize.GetSize().Height() - nDist );
1199 m_aBspWin.SetFtDist( nDist );
1200 const SvxLRSpaceItem& rLR = static_cast<const SvxLRSpaceItem&>(
1201 rFooterSet.Get( GetWhich( SID_ATTR_LRSPACE( 10000 + 48 ) ) ));
1202 m_aBspWin.SetFtLeft( rLR.GetLeft() );
1203 m_aBspWin.SetFtRight( rLR.GetRight() );
1204 m_aBspWin.SetFooter( true );
1205 }
1206 else
1207 m_aBspWin.SetFooter( false );
1208
1209 // show background and border in the example
1210 drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFooterFillAttributes;
1211
1212 if(mbEnableDrawingLayerFillStyles)
1213 {
1214 // create FillAttributes directly from DrawingLayer FillStyle entries
1215 aFooterFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(rFooterSet);
1216 }
1217 else
1218 {
1219 const sal_uInt16 nWhich(GetWhich(SID_ATTR_BRUSH( 10000 + 1 )));
1220
1221 if(rFooterSet.GetItemState(nWhich) >= SfxItemState::DEFAULT)
1222 {
1223 // aBspWin.SetFtColor(rItem.GetColor());
1224 const SvxBrushItem& rItem = static_cast<const SvxBrushItem&>(rFooterSet.Get(nWhich));
1225 SfxItemSet aTempSet(*rFooterSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
1226
1227 setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
1228 aFooterFillAttributes = std::make_shared<drawinglayer::attribute::SdrAllFillAttributesHelper>(aTempSet);
1229 }
1230 }
1231
1232 m_aBspWin.setFooterFillAttributes(aFooterFillAttributes);
1233}
1234
1235void SvxPageDescPage::ActivatePage( const SfxItemSet& rSet )
1236{
1237 InitHeadFoot_Impl( rSet );
1238 UpdateExample_Impl();
1239 ResetBackground_Impl( rSet );
1240 RangeHdl_Impl();
1241}
1242
1243DeactivateRC SvxPageDescPage::DeactivatePage( SfxItemSet* _pSet )
1244{
1245 // Inquiry whether the page margins are beyond the printing area.
1246 // If not, ask user whether they shall be taken.
1247 // If not, stay on the TabPage.
1248 Paper ePaper = m_xPaperSizeBox->get_active_id();
1249
1250 if ( ePaper != PAPER_SCREEN_4_3 && ePaper != PAPER_SCREEN_16_9 && ePaper != PAPER_SCREEN_16_10 && IsMarginOutOfRange() )
1251 {
1252 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
1253 VclMessageType::Question, VclButtonsType::YesNo,
1254 m_xPrintRangeQueryText->get_label()));
1255 xQueryBox->set_default_response(RET_NO);
1256 if (xQueryBox->run() == RET_NO)
1257 {
1258 weld::MetricSpinButton* pField = nullptr;
1259 if ( IsPrinterRangeOverflow( *m_xLeftMarginEdit, nFirstLeftMargin, nLastLeftMargin, MARGIN_LEFT( MarginPosition(0x0001) ) ) )
1260 pField = m_xLeftMarginEdit.get();
1261 if ( IsPrinterRangeOverflow( *m_xRightMarginEdit, nFirstRightMargin, nLastRightMargin, MARGIN_RIGHT( MarginPosition(0x0002) ) )
1262 && !pField )
1263 pField = m_xRightMarginEdit.get();
1264 if ( IsPrinterRangeOverflow( *m_xTopMarginEdit, nFirstTopMargin, nLastTopMargin, MARGIN_TOP( MarginPosition(0x0004) ) )
1265 && !pField )
1266 pField = m_xTopMarginEdit.get();
1267 if ( IsPrinterRangeOverflow( *m_xBottomMarginEdit, nFirstBottomMargin, nLastBottomMargin, MARGIN_BOTTOM( MarginPosition(0x0008) ) )
1268 && !pField )
1269 pField = m_xBottomMarginEdit.get();
1270 if ( pField )
1271 pField->grab_focus();
1272 UpdateExample_Impl();
1273 return DeactivateRC::KeepPage;
1274 }
1275 else
1276 CheckMarginEdits( false );
1277 }
1278
1279 if ( _pSet )
1280 {
1281 FillItemSet( _pSet );
1282
1283 // put portray/landscape if applicable
1284 sal_uInt16 nWh = GetWhich( SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) );
1285 MapUnit eUnit = GetItemSet().GetPool()->GetMetric( nWh );
1286 Size aSize( GetCoreValue( *m_xPaperWidthEdit, eUnit ),
1287 GetCoreValue( *m_xPaperHeightEdit, eUnit ) );
1288
1289 // put, if current size is different to the value in _pSet
1290 const SvxSizeItem* pSize = GetItem( *_pSet, SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ) );
1291 if ( aSize.Width() && ( !pSize || !IsEqualSize_Impl( pSize, aSize ) ) )
1292 _pSet->Put( SvxSizeItem( nWh, aSize ) );
1293 }
1294
1295 return DeactivateRC::LeavePage;
1296}
1297
1298void SvxPageDescPage::RangeHdl_Impl()
1299{
1300 // example window
1301 long nHHeight = m_aBspWin.GetHdHeight();
1302 long nHDist = m_aBspWin.GetHdDist();
1303
1304 long nFHeight = m_aBspWin.GetFtHeight();
1305 long nFDist = m_aBspWin.GetFtDist();
1306
1307 long nHFLeft = std::max(m_aBspWin.GetHdLeft(), m_aBspWin.GetFtLeft());
1308 long nHFRight = std::max(m_aBspWin.GetHdRight(), m_aBspWin.GetFtRight());
1309
1310 // current values for page margins
1311 long nBT = static_cast<long>(m_xTopMarginEdit->denormalize(m_xTopMarginEdit->get_value(FieldUnit::TWIP)));
1312 long nBB = static_cast<long>(m_xBottomMarginEdit->denormalize(m_xBottomMarginEdit->get_value(FieldUnit::TWIP)));
1313 long nBL = static_cast<long>(m_xLeftMarginEdit->denormalize(m_xLeftMarginEdit->get_value(FieldUnit::TWIP)));
1314 long nBR = static_cast<long>(m_xRightMarginEdit->denormalize(m_xRightMarginEdit->get_value(FieldUnit::TWIP)));
1315
1316 // calculate width of page border
1317 const SfxItemSet* _pSet = &GetItemSet();
1318 Size aBorder;
1319
1320 if ( _pSet->GetItemState( GetWhich(SID_ATTR_BORDER_SHADOW( 10000 + 25 )) ) >=
1321 SfxItemState::DEFAULT &&
1322 _pSet->GetItemState( GetWhich(SID_ATTR_BORDER_OUTER( 10000 + 24 )) ) >=
1323 SfxItemState::DEFAULT )
1324 {
1325 aBorder = GetMinBorderSpace_Impl(
1326 static_cast<const SvxShadowItem&>(_pSet->Get(GetWhich(SID_ATTR_BORDER_SHADOW( 10000 + 25 )))),
1327 static_cast<const SvxBoxItem&>(_pSet->Get(GetWhich(SID_ATTR_BORDER_OUTER( 10000 + 24 )))));
1328 }
1329
1330 // limits paper
1331 // maximum is 54 cm
1332
1333 long nMin = nHHeight + nHDist + nFDist + nFHeight + nBT + nBB +
1334 MINBODY + aBorder.Height();
1335 m_xPaperHeightEdit->set_min(m_xPaperHeightEdit->normalize(nMin), FieldUnit::TWIP);
1336
1337 nMin = MINBODY + nBL + nBR + aBorder.Width();
1338 m_xPaperWidthEdit->set_min(m_xPaperWidthEdit->normalize(nMin), FieldUnit::TWIP);
1339
1340 long nH = static_cast<long>(m_xPaperHeightEdit->denormalize(m_xPaperHeightEdit->get_value(FieldUnit::TWIP)));
1341 long nW = static_cast<long>(m_xPaperWidthEdit->denormalize(m_xPaperWidthEdit->get_value(FieldUnit::TWIP)));
1342
1343 // Top
1344 long nMax = nH - nBB - aBorder.Height() - MINBODY -
1345 nFDist - nFHeight - nHDist - nHHeight;
1346
1347 m_xTopMarginEdit->set_max(m_xTopMarginEdit->normalize(nMax), FieldUnit::TWIP);
1348
1349 // Bottom
1350 nMax = nH - nBT - aBorder.Height() - MINBODY -
1351 nFDist - nFHeight - nHDist - nHHeight;
1352
1353 m_xBottomMarginEdit->set_max(m_xTopMarginEdit->normalize(nMax), FieldUnit::TWIP);
1354
1355 // Left
1356 nMax = nW - nBR - MINBODY - aBorder.Width() - nHFLeft - nHFRight;
1357 m_xLeftMarginEdit->set_max(m_xLeftMarginEdit->normalize(nMax), FieldUnit::TWIP);
1358
1359 // Right
1360 nMax = nW - nBL - MINBODY - aBorder.Width() - nHFLeft - nHFRight;
1361 m_xRightMarginEdit->set_max(m_xRightMarginEdit->normalize(nMax), FieldUnit::TWIP);
1362}
1363
1364void SvxPageDescPage::CalcMargin_Impl()
1365{
1366 // current values for page margins
1367 long nBT = GetCoreValue( *m_xTopMarginEdit, MapUnit::MapTwip );
1368 long nBB = GetCoreValue( *m_xBottomMarginEdit, MapUnit::MapTwip );
1369
1370 long nBL = GetCoreValue( *m_xLeftMarginEdit, MapUnit::MapTwip );
1371 long nBR = GetCoreValue( *m_xRightMarginEdit, MapUnit::MapTwip );
1372
1373 long nH = GetCoreValue( *m_xPaperHeightEdit, MapUnit::MapTwip );
1374 long nW = GetCoreValue( *m_xPaperWidthEdit, MapUnit::MapTwip );
1375
1376 long nWidth = nBL + nBR + MINBODY;
1377 long nHeight = nBT + nBB + MINBODY;
1378
1379 if ( nWidth <= nW && nHeight <= nH )
1380 return;
1381
1382 if ( nWidth > nW )
1383 {
1384 long nTmp = nBL <= nBR ? nBR : nBL;
1385 nTmp -= nWidth - nW;
1386
1387 if ( nBL <= nBR )
1388 SetMetricValue( *m_xRightMarginEdit, nTmp, MapUnit::MapTwip );
1389 else
1390 SetMetricValue( *m_xLeftMarginEdit, nTmp, MapUnit::MapTwip );
1391 }
1392
1393 if ( nHeight > nH )
1394 {
1395 long nTmp = nBT <= nBB ? nBB : nBT;
1396 nTmp -= nHeight - nH;
1397
1398 if ( nBT <= nBB )
1399 SetMetricValue( *m_xBottomMarginEdit, nTmp, MapUnit::MapTwip );
1400 else
1401 SetMetricValue( *m_xTopMarginEdit, nTmp, MapUnit::MapTwip );
1402 }
1403}
1404
1405IMPL_LINK_NOARG(SvxPageDescPage, CenterHdl_Impl, weld::ToggleButton&, void)void SvxPageDescPage::LinkStubCenterHdl_Impl(void * instance,
weld::ToggleButton& data) { return static_cast<SvxPageDescPage
*>(instance)->CenterHdl_Impl(data); } void SvxPageDescPage
::CenterHdl_Impl(__attribute__ ((unused)) weld::ToggleButton&
)
1406{
1407 m_aBspWin.SetHorz(m_xHorzBox->get_active());
1408 m_aBspWin.SetVert(m_xVertBox->get_active());
1409 UpdateExample_Impl();
1410}
1411
1412void SvxPageDescPage::SetCollectionList(const std::vector<OUString> &aList)
1413{
1414 OSL_ENSURE(!aList.empty(), "Empty string list")do { if (true && (!(!aList.empty()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/cui/source/tabpages/page.cxx"
":" "1414" ": "), "%s", "Empty string list"); } } while (false
)
;
1415
1416 sStandardRegister = aList[0];
1417 m_xRegisterLB->freeze();
1418 for (size_t i = 1; i < aList.size(); ++i)
1419 m_xRegisterLB->append_text(aList[i]);
1420 m_xRegisterLB->thaw();
1421
1422 m_xRegisterCB->show();
1423 m_xRegisterFT->show();
1424 m_xRegisterLB->show();
1425 m_xRegisterCB->connect_toggled(LINK(this, SvxPageDescPage, RegisterModify)::tools::detail::makeLink( ::tools::detail::castTo<SvxPageDescPage
*>(this), &SvxPageDescPage::LinkStubRegisterModify)
);
1426}
1427
1428IMPL_LINK(SvxPageDescPage, RegisterModify, weld::ToggleButton&, rBox, void)void SvxPageDescPage::LinkStubRegisterModify(void * instance,
weld::ToggleButton& data) { return static_cast<SvxPageDescPage
*>(instance)->RegisterModify(data); } void SvxPageDescPage
::RegisterModify(weld::ToggleButton& rBox)
1429{
1430 bool bEnable = false;
1431 if (rBox.get_active())
1432 {
1433 bEnable = true;
1434 if (m_xRegisterLB->get_active() == -1)
1435 m_xRegisterLB->set_active_text(sStandardRegister);
1436 }
1437 m_xRegisterFT->set_sensitive(bEnable);
1438 m_xRegisterLB->set_sensitive(bEnable);
1439}
1440
1441void SvxPageDescPage::DisableVerticalPageDir()
1442{
1443 m_xTextFlowBox->remove_id(SvxFrameDirection::Vertical_RL_TB);
1444 m_xTextFlowBox->remove_id(SvxFrameDirection::Vertical_LR_TB);
1445 if (m_xTextFlowBox->get_count() < 2)
1446 {
1447 m_xTextFlowLbl->hide();
1448 m_xTextFlowBox->hide();
1449 m_aBspWin.EnableFrameDirection( false );
1450 }
1451}
1452
1453IMPL_LINK_NOARG(SvxPageDescPage, FrameDirectionModify_Impl, weld::ComboBox&, void)void SvxPageDescPage::LinkStubFrameDirectionModify_Impl(void *
instance, weld::ComboBox& data) { return static_cast<
SvxPageDescPage *>(instance)->FrameDirectionModify_Impl
(data); } void SvxPageDescPage::FrameDirectionModify_Impl(__attribute__
((unused)) weld::ComboBox&)
1454{
1455 m_aBspWin.SetFrameDirection(m_xTextFlowBox->get_active_id());
1456 m_aBspWin.Invalidate();
1457}
1458
1459bool SvxPageDescPage::IsPrinterRangeOverflow(
1460 weld::MetricSpinButton& rField, long nFirstMargin, long nLastMargin, MarginPosition nPos )
1461{
1462 bool bRet = false;
1463 bool bCheck = ( ( m_nPos & nPos ) == 0 );
1464 long nValue = rField.get_value(FieldUnit::NONE);
1465 if ( bCheck &&
1466 ( nValue < nFirstMargin || nValue > nLastMargin ) &&
1467 rField.get_value_changed_from_saved() )
1468 {
1469 rField.set_value(nValue < nFirstMargin ? nFirstMargin : nLastMargin, FieldUnit::NONE);
1470 bRet = true;
1471 }
1472
1473 return bRet;
1474}
1475
1476/** Check if a value of a margin edit is outside the printer paper margins
1477 and save this information.
1478*/
1479void SvxPageDescPage::CheckMarginEdits( bool _bClear )
1480{
1481 if ( _bClear )
1482 m_nPos = 0;
1483
1484 sal_Int64 nValue = m_xLeftMarginEdit->get_value(FieldUnit::NONE);
1485 if ( nValue < nFirstLeftMargin || nValue > nLastLeftMargin )
1486 m_nPos |= MARGIN_LEFT( MarginPosition(0x0001) );
1487 nValue = m_xRightMarginEdit->get_value(FieldUnit::NONE);
1488 if ( nValue < nFirstRightMargin || nValue > nLastRightMargin )
1489 m_nPos |= MARGIN_RIGHT( MarginPosition(0x0002) );
1490 nValue = m_xTopMarginEdit->get_value(FieldUnit::NONE);
1491 if ( nValue < nFirstTopMargin || nValue > nLastTopMargin )
1492 m_nPos |= MARGIN_TOP( MarginPosition(0x0004) );
1493 nValue = m_xBottomMarginEdit->get_value(FieldUnit::NONE);
1494 if ( nValue < nFirstBottomMargin || nValue > nLastBottomMargin )
1495 m_nPos |= MARGIN_BOTTOM( MarginPosition(0x0008) );
1496}
1497
1498bool SvxPageDescPage::IsMarginOutOfRange() const
1499{
1500 bool bRet = ( ( ( !( m_nPos & MARGIN_LEFT( MarginPosition(0x0001) ) ) &&
1501 m_xLeftMarginEdit->get_value_changed_from_saved() ) &&
1502 ( m_xLeftMarginEdit->get_value(FieldUnit::NONE) < nFirstLeftMargin ||
1503 m_xLeftMarginEdit->get_value(FieldUnit::NONE) > nLastLeftMargin ) ) ||
1504 ( ( !( m_nPos & MARGIN_RIGHT( MarginPosition(0x0002) ) ) &&
1505 m_xRightMarginEdit->get_value_changed_from_saved() ) &&
1506 ( m_xRightMarginEdit->get_value(FieldUnit::NONE) < nFirstRightMargin ||
1507 m_xRightMarginEdit->get_value(FieldUnit::NONE) > nLastRightMargin ) ) ||
1508 ( ( !( m_nPos & MARGIN_TOP( MarginPosition(0x0004) ) ) &&
1509 m_xTopMarginEdit->get_value_changed_from_saved() ) &&
1510 ( m_xTopMarginEdit->get_value(FieldUnit::NONE) < nFirstTopMargin ||
1511 m_xTopMarginEdit->get_value(FieldUnit::NONE) > nLastTopMargin ) ) ||
1512 ( ( !( m_nPos & MARGIN_BOTTOM( MarginPosition(0x0008) ) ) &&
1513 m_xBottomMarginEdit->get_value_changed_from_saved() ) &&
1514 ( m_xBottomMarginEdit->get_value(FieldUnit::NONE) < nFirstBottomMargin ||
1515 m_xBottomMarginEdit->get_value(FieldUnit::NONE) > nLastBottomMargin ) ) );
1516 return bRet;
1517}
1518
1519void SvxPageDescPage::PageCreated(const SfxAllItemSet& aSet)
1520{
1521 const SfxUInt16Item* pModeItem = aSet.GetItem(SID_ENUM_PAGE_MODETypedWhichId<SfxUInt16Item>( 10000 + 1038 ), false);
1522 const SfxUInt16Item* pPaperStartItem = aSet.GetItem(SID_PAPER_STARTTypedWhichId<SfxUInt16Item>( 10000 + 1039 ), false);
1523 const SfxUInt16Item* pPaperEndItem = aSet.GetItem(SID_PAPER_ENDTypedWhichId<SfxUInt16Item>( 10000 + 1040 ), false);
1524 const SfxStringListItem* pCollectListItem = aSet.GetItem<SfxStringListItem>(SID_COLLECT_LIST( 10000 + 1041 ), false);
1525 const SfxBoolItem* pSupportDrawingLayerFillStyleItem = aSet.GetItem<SfxBoolItem>(SID_DRAWINGLAYER_FILLSTYLES( 10000 + 1144), false);
1526 const SfxBoolItem* pIsImpressDoc = aSet.GetItem<SfxBoolItem>(SID_IMPRESS_DOCTypedWhichId<SfxBoolItem>( 10000 + 1194 ), false);
1527
1528 if (pModeItem)
1529 {
1530 eMode = static_cast<SvxModeType>(pModeItem->GetValue());
1531 }
1532
1533 if(pPaperStartItem && pPaperEndItem)
1534 {
1535 SetPaperFormatRanges(static_cast<Paper>(pPaperStartItem->GetValue()));
1536 }
1537
1538 if(pCollectListItem)
1539 {
1540 SetCollectionList(pCollectListItem->GetList());
1541 }
1542
1543 if(pSupportDrawingLayerFillStyleItem)
1544 {
1545 const bool bNew(pSupportDrawingLayerFillStyleItem->GetValue());
1546
1547 mbEnableDrawingLayerFillStyles = bNew;
1548 }
1549
1550 if (pIsImpressDoc)
1551 m_xNumberFormatText->set_label(SvxResId(STR_SLIDE_NUMBERSreinterpret_cast<char const *>("STR_SLIDE_NUMBERS" "\004"
u8"Slide numbers:")
));
1552}
1553
1554/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx

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#ifndef INCLUDED_VCL_PTR_HXX
21#define INCLUDED_VCL_PTR_HXX
22
23#include <sal/config.h>
24
25#include <rtl/ref.hxx>
26
27#include <utility>
28#include <type_traits>
29
30#ifdef DBG_UTIL
31#ifndef _WIN32
32#include <vcl/vclmain.hxx>
33#endif
34#endif
35
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase(
44 int (*)[sizeof(T)])
45{ return std::is_base_of<VclReferenceBase, T>::value; }
46
47} // namespace vcl::detail
48
49/**
50 * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses.
51 *
52 * For more details on the design please see vcl/README.lifecycle
53 *
54 * @param reference_type must be a subclass of vcl::Window
55 */
56template <class reference_type>
57class VclPtr
58{
59 static_assert(
60 vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
61 nullptr),
62 "template argument type must be derived from VclReferenceBase");
63
64 ::rtl::Reference<reference_type> m_rInnerRef;
65
66public:
67 /** Constructor...
68 */
69 VclPtr()
70 : m_rInnerRef()
71 {}
72
73 /** Constructor...
74 */
75 VclPtr (reference_type * pBody)
76 : m_rInnerRef(pBody)
77 {}
78
79 /** Constructor... that doesn't take a ref.
80 */
81 VclPtr (reference_type * pBody, __sal_NoAcquire)
82 : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
83 {}
84
85 /** Up-casting conversion constructor: Copies interface reference.
86
87 Does not work for up-casts to ambiguous bases. For the special case of
88 up-casting to Reference< XInterface >, see the corresponding conversion
89 operator.
90
91 @param rRef another reference
92 */
93 template< class derived_type >
94 VclPtr(
95 const VclPtr< derived_type > & rRef,
96 typename std::enable_if<
97 std::is_base_of<reference_type, derived_type>::value, int>::type
98 = 0 )
99 : m_rInnerRef( static_cast<reference_type*>(rRef) )
100 {
101 }
102
103#if defined(DBG_UTIL) && !defined(_WIN32)
104 virtual ~VclPtr()
105 {
106 assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain
::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 // We can be one of the intermediate counts, but if we are the last
108 // VclPtr keeping this object alive, then something forgot to call dispose().
109 assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
110 && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
;
111 }
112 VclPtr(VclPtr const &) = default;
113 VclPtr(VclPtr &&) = default;
114 VclPtr & operator =(VclPtr const &) = default;
115 VclPtr & operator =(VclPtr &&) = default;
116#endif
117
118 /**
119 * A construction helper for VclPtr. Since VclPtr types are created
120 * with a reference-count of one - to help fit into the existing
121 * code-flow; this helps us to construct them easily.
122 *
123 * For more details on the design please see vcl/README.lifecycle
124 *
125 * @tparam reference_type must be a subclass of vcl::Window
126 */
127 template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg)
128 {
129 return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE );
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
4
Calling copy constructor for 'Reference<Printer>'
7
Returning from copy constructor for 'Reference<Printer>'
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
8
Calling 'Reference::clear'
15
Returning; memory was released
205 if (aTmp.get()) {
16
Calling 'Reference::get'
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
310 {}
311
312 /**
313 Assignment that releases the last reference.
314 */
315 void disposeAndReset(reference_type *pBody)
316 {
317 if (pBody != this->get()) {
318 VclPtr<reference_type>::disposeAndClear();
319 VclPtr<reference_type>::set(pBody);
320 }
321 }
322
323 /**
324 Assignment that releases the last reference.
325 */
326 ScopedVclPtr<reference_type>& operator = (reference_type * pBody)
327 {
328 disposeAndReset(pBody);
329 return *this;
330 }
331
332 /** Up-casting conversion constructor: Copies interface reference.
333
334 Does not work for up-casts to ambiguous bases. For the special case of
335 up-casting to Reference< XInterface >, see the corresponding conversion
336 operator.
337
338 @param rRef another reference
339 */
340 template< class derived_type >
341 ScopedVclPtr(
342 const VclPtr< derived_type > & rRef,
343 typename std::enable_if<
344 std::is_base_of<reference_type, derived_type>::value, int>::type
345 = 0 )
346 : VclPtr<reference_type>( rRef )
347 {
348 }
349
350 /** Up-casting assignment operator.
351
352 Does not work for up-casts to ambiguous bases.
353
354 @param rRef another VclPtr
355 */
356 template<typename derived_type>
357 typename std::enable_if<
358 std::is_base_of<reference_type, derived_type>::value,
359 ScopedVclPtr &>::type
360 operator =(VclPtr<derived_type> const & rRef)
361 {
362 disposeAndReset(rRef.get());
363 return *this;
364 }
365
366 /**
367 * Override and disallow this, to prevent people accidentally calling it and actually
368 * getting VclPtr::Create and getting a naked VclPtr<> instance
369 */
370 template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete;
371
372 ~ScopedVclPtr()
373 {
374 VclPtr<reference_type>::disposeAndClear();
375 assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get(
) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 375, __extension__ __PRETTY_FUNCTION__))
; // make sure there are no lingering references
376 }
377
378private:
379 // Most likely we don't want this default copy-constructor.
380 ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete;
381 // And certainly we don't want a default assignment operator.
382 ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete;
383 // And disallow reset as that doesn't call disposeAndClear on the original reference
384 void reset() = delete;
385 void reset(reference_type *pBody) = delete;
386
387protected:
388 ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
389 : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
390 {}
391};
392
393/**
394 * A construction helper for ScopedVclPtr. Since VclPtr types are created
395 * with a reference-count of one - to help fit into the existing
396 * code-flow; this helps us to construct them easily.
397 *
398 * For more details on the design please see vcl/README.lifecycle
399 *
400 * @param reference_type must be a subclass of vcl::Window
401 */
402#if defined _MSC_VER
403#pragma warning(push)
404#pragma warning(disable: 4521) // " multiple copy constructors specified"
405#endif
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
410 template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
411 : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
412 {
413 }
414
415 /**
416 * Override and disallow this, to prevent people accidentally calling it and actually
417 * getting VclPtr::Create and getting a naked VclPtr<> instance
418 */
419 template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete;
420
421private:
422 // Prevent the above perfect forwarding ctor from hijacking (accidental)
423 // attempts at ScopedVclPtrInstance copy construction (where the hijacking
424 // would typically lead to somewhat obscure error messages); both non-const
425 // and const variants are needed here, as the ScopedVclPtr base class has a
426 // const--variant copy ctor, so the implicitly declared copy ctor for
427 // ScopedVclPtrInstance would also be the const variant, so non-const copy
428 // construction attempts would be hijacked by the perfect forwarding ctor;
429 // but if we only declared a non-const variant here, the const variant would
430 // no longer be implicitly declared (as there would already be an explicitly
431 // declared copy ctor), so const copy construction attempts would then be
432 // hijacked by the perfect forwarding ctor:
433 ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
434 ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
435};
436#if defined _MSC_VER
437#pragma warning(pop)
438#endif
439
440#endif // INCLUDED_VCL_PTR_HXX
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

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#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
5
Assuming field 'm_pBody' is non-null
6
Taking true branch
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody)
113 m_pBody->release();
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody
8.1
Field 'm_pBody' is non-null
8.1
Field 'm_pBody' is non-null
8.1
Field 'm_pBody' is non-null
8.1
Field 'm_pBody' is non-null
)
9
Taking true branch
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
10
Calling 'VclReferenceBase::release'
14
Returning; memory was released
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
17
Use of memory after it is freed
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

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#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
11
Assuming the condition is true
12
Taking true branch
40 delete this;
13
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif