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 optpage.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 EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -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/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/sw/inc -I /home/maarten/src/libreoffice/core/sw/source/uibase/inc -I /home/maarten/src/libreoffice/core/sw/source/ui/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sw/sdi -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/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/oovbaapi/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/sw/source/ui/config/optpage.cxx

/home/maarten/src/libreoffice/core/sw/source/ui/config/optpage.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 <sal/config.h>
21
22#include <utility>
23
24#include <optpage.hxx>
25#include <doc.hxx>
26#include <hintids.hxx>
27#include <cmdid.h>
28#include <fmtcol.hxx>
29#include <charatr.hxx>
30#include <swtypes.hxx>
31#include <view.hxx>
32#include <docsh.hxx>
33#include <IDocumentDeviceAccess.hxx>
34#include <IDocumentSettingAccess.hxx>
35
36#include <swmodule.hxx>
37#include <wrtsh.hxx>
38#include <cfgitems.hxx>
39#include <poolfmt.hxx>
40#include <uiitems.hxx>
41#include <printdata.hxx>
42#include <modcfg.hxx>
43#include <crstate.hxx>
44#include <viewopt.hxx>
45#include <globals.hrc>
46#include <strings.hrc>
47#include <swwrtshitem.hxx>
48
49#include <editeng/fhgtitem.hxx>
50#include <editeng/fontitem.hxx>
51#include <editeng/langitem.hxx>
52#include <editeng/svxenum.hxx>
53#include <sal/macros.h>
54#include <sfx2/dialoghelper.hxx>
55#include <sfx2/dispatch.hxx>
56#include <sfx2/printer.hxx>
57#include <sfx2/bindings.hxx>
58#include <sfx2/viewfrm.hxx>
59#include <svl/ctloptions.hxx>
60#include <svl/eitem.hxx>
61#include <svl/cjkoptions.hxx>
62#include <svtools/ctrltool.hxx>
63#include <svtools/unitconv.hxx>
64#include <sfx2/htmlmode.hxx>
65
66#include <vcl/settings.hxx>
67#include <vcl/svapp.hxx>
68
69#include <optload.hxx>
70
71#include <svtools/miscopt.hxx>
72
73using namespace ::com::sun::star;
74
75namespace {
76
77void drawRect(vcl::RenderContext& rRenderContext, const tools::Rectangle &rRect, const Color &rFillColor, const Color &rLineColor)
78{
79 rRenderContext.SetFillColor(rFillColor);
80 rRenderContext.SetLineColor(rLineColor);
81 rRenderContext.DrawRect(rRect);
82}
83
84}
85
86// Tools->Options->Writer->View
87// Tools->Options->Writer/Web->View
88SwContentOptPage::SwContentOptPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet)
89 : SfxTabPage(pPage, pController, "modules/swriter/ui/viewoptionspage.ui", "ViewOptionsPage", &rCoreSet)
90 , m_xCrossCB(m_xBuilder->weld_check_button("helplines"))
91 , m_xHMetric(m_xBuilder->weld_combo_box("hrulercombobox"))
92 , m_xVRulerCBox(m_xBuilder->weld_check_button("vruler"))
93 , m_xVRulerRightCBox(m_xBuilder->weld_check_button("vrulerright"))
94 , m_xVMetric(m_xBuilder->weld_combo_box("vrulercombobox"))
95 , m_xSmoothCBox(m_xBuilder->weld_check_button("smoothscroll"))
96 , m_xGrfCB(m_xBuilder->weld_check_button("graphics"))
97 , m_xTableCB(m_xBuilder->weld_check_button("tables"))
98 , m_xDrwCB(m_xBuilder->weld_check_button("drawings"))
99 , m_xPostItCB(m_xBuilder->weld_check_button("comments"))
100 , m_xSettingsFrame(m_xBuilder->weld_frame("settingsframe"))
101 , m_xSettingsLabel(m_xBuilder->weld_label("settingslabel"))
102 , m_xMetricLabel(m_xBuilder->weld_label("measureunitlabel"))
103 , m_xMetricLB(m_xBuilder->weld_combo_box("measureunit"))
104 , m_xShowInlineTooltips(m_xBuilder->weld_check_button("changestooltip"))
105 , m_xShowOutlineContentVisibilityButton(m_xBuilder->weld_check_button("outlinecontentvisibilitybutton"))
106 , m_xFieldHiddenCB(m_xBuilder->weld_check_button("hiddentextfield"))
107 , m_xFieldHiddenParaCB(m_xBuilder->weld_check_button("hiddenparafield"))
108{
109 SvtMiscOptions aMiscOptions;
110 if (!aMiscOptions.IsExperimentalMode())
111 m_xShowOutlineContentVisibilityButton->hide();
112
113 /* This part is visible only with Writer/Web->View dialogue. */
114 const SfxPoolItem* pItem;
115 if (! (SfxItemState::SET == rCoreSet.GetItemState(SID_HTML_MODE(10000 + 414), false, &pItem )
116 && static_cast<const SfxUInt16Item*>(pItem)->GetValue() & HTMLMODE_ON))
117 {
118 m_xSettingsFrame->hide();
119 m_xSettingsLabel->hide();
120 m_xMetricLabel->hide();
121 m_xMetricLB->hide();
122 }
123
124 SvtCJKOptions aCJKOptions;
125 if(!aCJKOptions.IsVerticalTextEnabled() )
126 m_xVRulerRightCBox->hide();
127 m_xVRulerCBox->connect_toggled(LINK(this, SwContentOptPage, VertRulerHdl )::tools::detail::makeLink( ::tools::detail::castTo<SwContentOptPage
*>(this), &SwContentOptPage::LinkStubVertRulerHdl)
);
128
129 for (size_t i = 0; i < SwFieldUnitTable::Count(); ++i)
130 {
131 const OUString sMetric = SwFieldUnitTable::GetString(i);
132 FieldUnit eFUnit = SwFieldUnitTable::GetValue(i);
133
134 switch ( eFUnit )
135 {
136 case FieldUnit::MM:
137 case FieldUnit::CM:
138 case FieldUnit::POINT:
139 case FieldUnit::PICA:
140 case FieldUnit::INCH:
141 case FieldUnit::CHAR: // add two units , 'character' and 'line' , their ticks are not fixed
142 case FieldUnit::LINE:
143 {
144 // only use these metrics
145 // a horizontal ruler has not the 'line' unit
146 // there isn't 'line' unit in HTML format
147 if (eFUnit != FieldUnit::LINE)
148 {
149 m_xMetricLB->append(OUString::number(static_cast<sal_uInt32>(eFUnit)), sMetric);
150 m_xHMetric->append(OUString::number(static_cast<sal_uInt32>(eFUnit)), sMetric);
151 }
152 // a vertical ruler has not the 'character' unit
153 if (eFUnit != FieldUnit::CHAR)
154 {
155 m_xVMetric->append(OUString::number(static_cast<sal_uInt32>(eFUnit)), sMetric);
156 }
157 break;
158 }
159 default:;//prevent warning
160 }
161 }
162}
163
164SwContentOptPage::~SwContentOptPage()
165{
166}
167
168std::unique_ptr<SfxTabPage> SwContentOptPage::Create( weld::Container* pPage, weld::DialogController* pController,
169 const SfxItemSet* rAttrSet)
170{
171 return std::make_unique<SwContentOptPage>(pPage, pController, *rAttrSet);
172}
173
174static void lcl_SelectMetricLB(weld::ComboBox& rMetric, sal_uInt16 nSID, const SfxItemSet& rSet)
175{
176 const SfxPoolItem* pItem;
177 if( rSet.GetItemState( nSID, false, &pItem ) >= SfxItemState::DEFAULT )
178 {
179 FieldUnit eFieldUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
180 for (sal_Int32 i = 0, nEntryCount = rMetric.get_count(); i < nEntryCount; ++i)
181 {
182 if (rMetric.get_id(i).toUInt32() == static_cast<sal_uInt32>(eFieldUnit))
183 {
184 rMetric.set_active(i);
185 break;
186 }
187 }
188 }
189 rMetric.save_value();
190}
191
192void SwContentOptPage::Reset(const SfxItemSet* rSet)
193{
194 const SwElemItem* pElemAttr = nullptr;
195
196 rSet->GetItemState( FN_PARAM_ELEM((20000 + 1100)+21) , false,
197 reinterpret_cast<const SfxPoolItem**>(&pElemAttr) );
198 if(pElemAttr)
199 {
200 m_xTableCB->set_active(pElemAttr->m_bTable);
201 m_xGrfCB->set_active(pElemAttr->m_bGraphic);
202 m_xDrwCB->set_active(pElemAttr->m_bDrawing);
203 m_xPostItCB->set_active(pElemAttr->m_bNotes);
204 m_xCrossCB->set_active(pElemAttr->m_bCrosshair);
205 m_xVRulerCBox->set_active(pElemAttr->m_bVertRuler);
206 m_xVRulerRightCBox->set_active(pElemAttr->m_bVertRulerRight);
207 m_xSmoothCBox->set_active(pElemAttr->m_bSmoothScroll);
208 m_xShowInlineTooltips->set_active(pElemAttr->m_bShowInlineTooltips);
209 m_xShowOutlineContentVisibilityButton->set_active(pElemAttr->m_bShowOutlineContentVisibilityButton);
210 m_xFieldHiddenCB->set_active( pElemAttr->m_bFieldHiddenText );
211 m_xFieldHiddenParaCB->set_active( pElemAttr->m_bShowHiddenPara );
212 if (GetActiveWrtShell()->GetViewOptions()->IsShowOutlineContentVisibilityButton() != pElemAttr->m_bShowOutlineContentVisibilityButton)
213 GetActiveWrtShell()->GetView().GetDocShell()->GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON((20000 + 200) + 63));
214 }
215 m_xMetricLB->set_active(-1);
216 lcl_SelectMetricLB(*m_xMetricLB, SID_ATTR_METRICTypedWhichId<SfxUInt16Item>(((((10000 + 1499) + 1) + 499
) + 1) + 8)
, *rSet);
217 lcl_SelectMetricLB(*m_xHMetric, FN_HSCROLL_METRIC((20000 + 200) + 53), *rSet);
218 lcl_SelectMetricLB(*m_xVMetric, FN_VSCROLL_METRIC((20000 + 200) + 54), *rSet);
219}
220
221bool SwContentOptPage::FillItemSet(SfxItemSet* rSet)
222{
223 const SwElemItem* pOldAttr = static_cast<const SwElemItem*>(
224 GetOldItem(GetItemSet(), FN_PARAM_ELEM((20000 + 1100)+21)));
225
226 SwElemItem aElem;
227 aElem.m_bTable = m_xTableCB->get_active();
228 aElem.m_bGraphic = m_xGrfCB->get_active();
229 aElem.m_bDrawing = m_xDrwCB->get_active();
230 aElem.m_bNotes = m_xPostItCB->get_active();
231 aElem.m_bCrosshair = m_xCrossCB->get_active();
232 aElem.m_bVertRuler = m_xVRulerCBox->get_active();
233 aElem.m_bVertRulerRight = m_xVRulerRightCBox->get_active();
234 aElem.m_bSmoothScroll = m_xSmoothCBox->get_active();
235 aElem.m_bShowInlineTooltips = m_xShowInlineTooltips->get_active();
236 aElem.m_bShowOutlineContentVisibilityButton = m_xShowOutlineContentVisibilityButton->get_active();
237 aElem.m_bFieldHiddenText = m_xFieldHiddenCB->get_active();
238 aElem.m_bShowHiddenPara = m_xFieldHiddenParaCB->get_active();
239
240 if (GetActiveWrtShell()->GetViewOptions()->IsShowOutlineContentVisibilityButton() != aElem.m_bShowOutlineContentVisibilityButton)
241 GetActiveWrtShell()->GetView().GetDocShell()->GetDispatcher()->Execute(FN_SHOW_OUTLINECONTENTVISIBILITYBUTTON((20000 + 200) + 63));
242
243 bool bRet = !pOldAttr || aElem != *pOldAttr;
244 if(bRet)
245 bRet = nullptr != rSet->Put(aElem);
246
247 sal_Int32 nMPos = m_xMetricLB->get_active();
248 sal_Int32 nGlobalMetricPos = nMPos;
249 if ( m_xMetricLB->get_value_changed_from_saved() )
250 {
251 const sal_uInt16 nFieldUnit = m_xMetricLB->get_id(nMPos).toUInt32();
252 rSet->Put( SfxUInt16Item( SID_ATTR_METRICTypedWhichId<SfxUInt16Item>(((((10000 + 1499) + 1) + 499
) + 1) + 8)
, nFieldUnit ) );
253 bRet = true;
254 }
255
256 nMPos = m_xHMetric->get_active();
257 if ( m_xHMetric->get_value_changed_from_saved() || nMPos != nGlobalMetricPos )
258 {
259 const sal_uInt16 nFieldUnit = m_xHMetric->get_id(nMPos).toUInt32();
260 rSet->Put( SfxUInt16Item( FN_HSCROLL_METRIC((20000 + 200) + 53), nFieldUnit ) );
261 bRet = true;
262 }
263 nMPos = m_xVMetric->get_active();
264 if ( m_xVMetric->get_value_changed_from_saved() || nMPos != nGlobalMetricPos )
265 {
266 const sal_uInt16 nFieldUnit = m_xVMetric->get_id(nMPos).toUInt32();
267 rSet->Put( SfxUInt16Item( FN_VSCROLL_METRIC((20000 + 200) + 54), nFieldUnit ) );
268 bRet = true;
269 }
270
271 return bRet;
272}
273
274IMPL_LINK(SwContentOptPage, VertRulerHdl, weld::ToggleButton&, rBox, void)void SwContentOptPage::LinkStubVertRulerHdl(void * instance, weld
::ToggleButton& data) { return static_cast<SwContentOptPage
*>(instance)->VertRulerHdl(data); } void SwContentOptPage
::VertRulerHdl(weld::ToggleButton& rBox)
275{
276 m_xVRulerRightCBox->set_sensitive(rBox.get_sensitive() && rBox.get_active());
277}
278
279// TabPage Printer additional settings
280SwAddPrinterTabPage::SwAddPrinterTabPage(weld::Container* pPage, weld::DialogController* pController,
281 const SfxItemSet& rCoreSet)
282 : SfxTabPage(pPage, pController, "modules/swriter/ui/printoptionspage.ui", "PrintOptionsPage", &rCoreSet)
283 , sNone(SwResId(SW_STR_NONEreinterpret_cast<char const *>("SW_STR_NONE" "\004" u8"[None]"
)
))
284 , bAttrModified(false)
285 , bPreview(false)
286 , m_xGrfCB(m_xBuilder->weld_check_button("graphics"))
287 , m_xCtrlFieldCB(m_xBuilder->weld_check_button("formcontrols"))
288 , m_xBackgroundCB(m_xBuilder->weld_check_button("background"))
289 , m_xBlackFontCB(m_xBuilder->weld_check_button("inblack"))
290 , m_xPrintHiddenTextCB(m_xBuilder->weld_check_button("hiddentext"))
291 , m_xPrintTextPlaceholderCB(m_xBuilder->weld_check_button("textplaceholder"))
292 , m_xPagesFrame(m_xBuilder->weld_widget("pagesframe"))
293 , m_xLeftPageCB(m_xBuilder->weld_check_button("leftpages"))
294 , m_xRightPageCB(m_xBuilder->weld_check_button("rightpages"))
295 , m_xProspectCB(m_xBuilder->weld_check_button("brochure"))
296 , m_xProspectCB_RTL(m_xBuilder->weld_check_button("rtl"))
297 , m_xCommentsFrame(m_xBuilder->weld_widget("commentsframe"))
298 , m_xNoRB(m_xBuilder->weld_radio_button("none"))
299 , m_xOnlyRB(m_xBuilder->weld_radio_button("only"))
300 , m_xEndRB(m_xBuilder->weld_radio_button("end"))
301 , m_xEndPageRB(m_xBuilder->weld_radio_button("endpage"))
302 , m_xInMarginsRB(m_xBuilder->weld_radio_button("inmargins"))
303 , m_xPrintEmptyPagesCB(m_xBuilder->weld_check_button("blankpages"))
304 , m_xPaperFromSetupCB(m_xBuilder->weld_check_button("papertray"))
305 , m_xFaxLB(m_xBuilder->weld_combo_box("fax"))
306{
307 Link<weld::ToggleButton&,void> aLk = LINK( this, SwAddPrinterTabPage, AutoClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwAddPrinterTabPage
*>(this), &SwAddPrinterTabPage::LinkStubAutoClickHdl)
;
308 m_xGrfCB->connect_toggled( aLk );
309 m_xRightPageCB->connect_toggled( aLk );
310 m_xLeftPageCB->connect_toggled( aLk );
311 m_xCtrlFieldCB->connect_toggled( aLk );
312 m_xBackgroundCB->connect_toggled( aLk );
313 m_xBlackFontCB->connect_toggled( aLk );
314 m_xPrintHiddenTextCB->connect_toggled( aLk );
315 m_xPrintTextPlaceholderCB->connect_toggled( aLk );
316 m_xProspectCB->connect_toggled( aLk );
317 m_xProspectCB_RTL->connect_toggled( aLk );
318 m_xPaperFromSetupCB->connect_toggled( aLk );
319 m_xPrintEmptyPagesCB->connect_toggled( aLk );
320 m_xEndPageRB->connect_toggled( aLk );
321 m_xInMarginsRB->connect_toggled( aLk );
322 m_xEndRB->connect_toggled( aLk );
323 m_xOnlyRB->connect_toggled( aLk );
324 m_xNoRB->connect_toggled( aLk );
325 m_xFaxLB->connect_changed( LINK( this, SwAddPrinterTabPage, SelectHdl )::tools::detail::makeLink( ::tools::detail::castTo<SwAddPrinterTabPage
*>(this), &SwAddPrinterTabPage::LinkStubSelectHdl)
);
326
327 const SfxPoolItem* pItem;
328 if(SfxItemState::SET == rCoreSet.GetItemState(SID_HTML_MODE(10000 + 414), false, &pItem )
329 && static_cast<const SfxUInt16Item*>(pItem)->GetValue() & HTMLMODE_ON)
330 {
331 m_xLeftPageCB->hide();
332 m_xRightPageCB->hide();
333 m_xPrintHiddenTextCB->hide();
334 m_xPrintTextPlaceholderCB->hide();
335 m_xPrintEmptyPagesCB->hide();
336 }
337 m_xProspectCB_RTL->set_sensitive(false);
338 SvtCTLOptions aCTLOptions;
339 m_xProspectCB_RTL->set_visible(aCTLOptions.IsCTLFontEnabled());
340}
341
342SwAddPrinterTabPage::~SwAddPrinterTabPage()
343{
344}
345
346void SwAddPrinterTabPage::SetPreview(bool bPrev)
347{
348 bPreview = bPrev;
349 m_xCommentsFrame->set_sensitive(!bPreview);
350 m_xPagesFrame->set_sensitive(!bPreview);
351}
352
353std::unique_ptr<SfxTabPage> SwAddPrinterTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
354 const SfxItemSet* rAttrSet )
355{
356 return std::make_unique<SwAddPrinterTabPage>(pPage, pController, *rAttrSet);
357}
358
359bool SwAddPrinterTabPage::FillItemSet( SfxItemSet* rCoreSet )
360{
361 if ( bAttrModified )
362 {
363 SwAddPrinterItem aAddPrinterAttr;
364 aAddPrinterAttr.m_bPrintGraphic = m_xGrfCB->get_active();
365 aAddPrinterAttr.m_bPrintTable = true; // always enabled since CWS printerpullgpages /*m_xTabCB->get_active();*/
366 aAddPrinterAttr.m_bPrintDraw = m_xGrfCB->get_active(); // UI merged with m_xGrfCB in CWS printerpullgpages
367 aAddPrinterAttr.m_bPrintControl = m_xCtrlFieldCB->get_active();
368 aAddPrinterAttr.m_bPrintPageBackground = m_xBackgroundCB->get_active();
369 aAddPrinterAttr.m_bPrintBlackFont = m_xBlackFontCB->get_active();
370 aAddPrinterAttr.m_bPrintHiddenText = m_xPrintHiddenTextCB->get_active();
371 aAddPrinterAttr.m_bPrintTextPlaceholder = m_xPrintTextPlaceholderCB->get_active();
372
373 aAddPrinterAttr.m_bPrintLeftPages = m_xLeftPageCB->get_active();
374 aAddPrinterAttr.m_bPrintRightPages = m_xRightPageCB->get_active();
375 aAddPrinterAttr.m_bPrintReverse = false; // handled by vcl itself since CWS printerpullpages /*m_xReverseCB->get_active()*/;
376 aAddPrinterAttr.m_bPrintProspect = m_xProspectCB->get_active();
377 aAddPrinterAttr.m_bPrintProspectRTL = m_xProspectCB_RTL->get_active();
378 aAddPrinterAttr.m_bPaperFromSetup = m_xPaperFromSetupCB->get_active();
379 aAddPrinterAttr.m_bPrintEmptyPages = m_xPrintEmptyPagesCB->get_active();
380 aAddPrinterAttr.m_bPrintSingleJobs = true; // handled by vcl in new print dialog since CWS printerpullpages /*m_xSingleJobsCB->get_active()*/;
381
382 if (m_xNoRB->get_active()) aAddPrinterAttr.m_nPrintPostIts =
383 SwPostItMode::NONE;
384 if (m_xOnlyRB->get_active()) aAddPrinterAttr.m_nPrintPostIts =
385 SwPostItMode::Only;
386 if (m_xEndRB->get_active()) aAddPrinterAttr.m_nPrintPostIts =
387 SwPostItMode::EndDoc;
388 if (m_xEndPageRB->get_active()) aAddPrinterAttr.m_nPrintPostIts =
389 SwPostItMode::EndPage;
390 if (m_xInMarginsRB->get_active()) aAddPrinterAttr.m_nPrintPostIts =
391 SwPostItMode::InMargins;
392
393 const OUString sFax = m_xFaxLB->get_active_text();
394 aAddPrinterAttr.m_sFaxName = sNone == sFax ? OUString() : sFax;
395 rCoreSet->Put(aAddPrinterAttr);
396 }
397 return bAttrModified;
398}
399
400void SwAddPrinterTabPage::Reset( const SfxItemSet* )
401{
402 const SfxItemSet& rSet = GetItemSet();
403 const SwAddPrinterItem* pAddPrinterAttr = nullptr;
404
405 if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_ADDPRINTER((20000 + 1100)+18) , false,
406 reinterpret_cast<const SfxPoolItem**>(&pAddPrinterAttr) ))
407 {
408 m_xGrfCB->set_active(pAddPrinterAttr->m_bPrintGraphic || pAddPrinterAttr->m_bPrintDraw);
409 m_xCtrlFieldCB->set_active( pAddPrinterAttr->m_bPrintControl);
410 m_xBackgroundCB->set_active( pAddPrinterAttr->m_bPrintPageBackground);
411 m_xBlackFontCB->set_active( pAddPrinterAttr->m_bPrintBlackFont);
412 m_xPrintHiddenTextCB->set_active( pAddPrinterAttr->m_bPrintHiddenText);
413 m_xPrintTextPlaceholderCB->set_active(pAddPrinterAttr->m_bPrintTextPlaceholder);
414 m_xLeftPageCB->set_active( pAddPrinterAttr->m_bPrintLeftPages);
415 m_xRightPageCB->set_active( pAddPrinterAttr->m_bPrintRightPages);
416 m_xPaperFromSetupCB->set_active(pAddPrinterAttr->m_bPaperFromSetup);
417 m_xPrintEmptyPagesCB->set_active(pAddPrinterAttr->m_bPrintEmptyPages);
418 m_xProspectCB->set_active( pAddPrinterAttr->m_bPrintProspect);
419 m_xProspectCB_RTL->set_active( pAddPrinterAttr->m_bPrintProspectRTL);
420
421 m_xNoRB->set_active(pAddPrinterAttr->m_nPrintPostIts== SwPostItMode::NONE ) ;
422 m_xOnlyRB->set_active(pAddPrinterAttr->m_nPrintPostIts== SwPostItMode::Only ) ;
423 m_xEndRB->set_active(pAddPrinterAttr->m_nPrintPostIts== SwPostItMode::EndDoc ) ;
424 m_xEndPageRB->set_active(pAddPrinterAttr->m_nPrintPostIts== SwPostItMode::EndPage ) ;
425 m_xInMarginsRB->set_active(pAddPrinterAttr->m_nPrintPostIts== SwPostItMode::InMargins ) ;
426 auto nFound = m_xFaxLB->find_text(pAddPrinterAttr->m_sFaxName);
427 if (nFound != -1)
428 m_xFaxLB->set_active(nFound);
429 else
430 m_xFaxLB->set_active(0);
431 }
432 if (m_xProspectCB->get_active())
433 {
434 m_xProspectCB_RTL->set_sensitive(true);
435 m_xNoRB->set_sensitive( false );
436 m_xOnlyRB->set_sensitive( false );
437 m_xEndRB->set_sensitive( false );
438 m_xEndPageRB->set_sensitive( false );
439 }
440 else
441 m_xProspectCB_RTL->set_sensitive( false );
442}
443
444IMPL_LINK_NOARG(SwAddPrinterTabPage, AutoClickHdl, weld::ToggleButton&, void)void SwAddPrinterTabPage::LinkStubAutoClickHdl(void * instance
, weld::ToggleButton& data) { return static_cast<SwAddPrinterTabPage
*>(instance)->AutoClickHdl(data); } void SwAddPrinterTabPage
::AutoClickHdl(__attribute__ ((unused)) weld::ToggleButton&
)
445{
446 bAttrModified = true;
447 bool bIsProspect = m_xProspectCB->get_active();
448 if (!bIsProspect)
449 m_xProspectCB_RTL->set_active( false );
450 m_xProspectCB_RTL->set_sensitive( bIsProspect );
451 m_xNoRB->set_sensitive( !bIsProspect );
452 m_xOnlyRB->set_sensitive( !bIsProspect );
453 m_xEndRB->set_sensitive( !bIsProspect );
454 m_xEndPageRB->set_sensitive( !bIsProspect );
455 m_xInMarginsRB->set_sensitive( !bIsProspect );
456}
457
458void SwAddPrinterTabPage::SetFax( const std::vector<OUString>& rFaxLst )
459{
460 m_xFaxLB->append_text(sNone);
461 for(const auto & i : rFaxLst)
462 {
463 m_xFaxLB->append_text(i);
464 }
465 m_xFaxLB->set_active(0);
466}
467
468IMPL_LINK_NOARG(SwAddPrinterTabPage, SelectHdl, weld::ComboBox&, void)void SwAddPrinterTabPage::LinkStubSelectHdl(void * instance, weld
::ComboBox& data) { return static_cast<SwAddPrinterTabPage
*>(instance)->SelectHdl(data); } void SwAddPrinterTabPage
::SelectHdl(__attribute__ ((unused)) weld::ComboBox&)
469{
470 bAttrModified=true;
471}
472
473void SwAddPrinterTabPage::PageCreated( const SfxAllItemSet& aSet)
474{
475 const SfxBoolItem* pListItem = aSet.GetItem<SfxBoolItem>(SID_FAX_LIST(((20000) + 800) + 116), false);
476 const SfxBoolItem* pPreviewItem = aSet.GetItem<SfxBoolItem>(SID_PREVIEWFLAG_TYPE(((20000) + 800) + 114), false);
477 if (pPreviewItem)
478 {
479 SetPreview(pPreviewItem->GetValue());
480 Reset(&aSet);
481 }
482 if (pListItem && pListItem->GetValue())
483 {
484 std::vector<OUString> aFaxList;
485 const std::vector<OUString>& rPrinters = Printer::GetPrinterQueues();
486 for (const auto & rPrinter : rPrinters)
487 aFaxList.insert(aFaxList.begin(), rPrinter);
488 SetFax( aFaxList );
489 }
490}
491
492// Tabpage Standardfonts
493SwStdFontTabPage::SwStdFontTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
494 : SfxTabPage(pPage, pController, "modules/swriter/ui/optfonttabpage.ui", "OptFontTabPage", &rSet)
495 , m_pPrt(nullptr)
496 , m_pFontConfig(nullptr)
497 , m_pWrtShell(nullptr)
498 , m_eLanguage( GetAppLanguage() )
499 , m_bListDefault(false)
500 , m_bSetListDefault(true)
501 , m_bLabelDefault(false)
502 , m_bSetLabelDefault(true)
503 , m_bIdxDefault(false)
504 , m_bSetIdxDefault(true)
505 , m_bDisposePrinter(false)
506 , m_bListHeightDefault(false)
507 , m_bLabelHeightDefault(false)
508 , m_bIndexHeightDefault(false)
509 , m_nFontGroup(FONT_GROUP_DEFAULT0)
510 , m_sScriptWestern(SwResId(ST_SCRIPT_WESTERNreinterpret_cast<char const *>("ST_SCRIPT_WESTERN" "\004"
u8"Western")
))
511 , m_sScriptAsian(SwResId(ST_SCRIPT_ASIANreinterpret_cast<char const *>("ST_SCRIPT_ASIAN" "\004"
u8"Asian")
))
512 , m_sScriptComplex(SwResId(ST_SCRIPT_CTLreinterpret_cast<char const *>("ST_SCRIPT_CTL" "\004" u8"CTL"
)
))
513 , m_xLabelFT(m_xBuilder->weld_label("label1"))
514 , m_xStandardBox(m_xBuilder->weld_combo_box("standardbox"))
515 , m_xStandardHeightLB(new FontSizeBox(m_xBuilder->weld_combo_box("standardheight")))
516 , m_xTitleBox(m_xBuilder->weld_combo_box("titlebox"))
517 , m_xTitleHeightLB(new FontSizeBox(m_xBuilder->weld_combo_box("titleheight")))
518 , m_xListBox(m_xBuilder->weld_combo_box("listbox"))
519 , m_xListHeightLB(new FontSizeBox(m_xBuilder->weld_combo_box("listheight")))
520 , m_xLabelBox(m_xBuilder->weld_combo_box("labelbox"))
521 , m_xLabelHeightLB(new FontSizeBox(m_xBuilder->weld_combo_box("labelheight")))
522 , m_xIdxBox(m_xBuilder->weld_combo_box("idxbox"))
523 , m_xIndexHeightLB(new FontSizeBox(m_xBuilder->weld_combo_box("indexheight")))
524 , m_xStandardPB(m_xBuilder->weld_button("standard"))
525{
526 m_xStandardBox->make_sorted();
527 m_xTitleBox->make_sorted();
528 m_xListBox->make_sorted();
529 m_xLabelBox->make_sorted();
530 m_xIdxBox->make_sorted();
531
532 m_xStandardPB->connect_clicked(LINK(this, SwStdFontTabPage, StandardHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwStdFontTabPage
*>(this), &SwStdFontTabPage::LinkStubStandardHdl)
);
533 m_xStandardBox->connect_changed( LINK(this, SwStdFontTabPage, ModifyHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwStdFontTabPage
*>(this), &SwStdFontTabPage::LinkStubModifyHdl)
);
534 m_xListBox->connect_changed( LINK(this, SwStdFontTabPage, ModifyHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwStdFontTabPage
*>(this), &SwStdFontTabPage::LinkStubModifyHdl)
);
535 m_xLabelBox->connect_changed( LINK(this, SwStdFontTabPage, ModifyHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwStdFontTabPage
*>(this), &SwStdFontTabPage::LinkStubModifyHdl)
);
536 m_xIdxBox->connect_changed( LINK(this, SwStdFontTabPage, ModifyHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwStdFontTabPage
*>(this), &SwStdFontTabPage::LinkStubModifyHdl)
);
537 Link<weld::Widget&,void> aFocusLink = LINK( this, SwStdFontTabPage, LoseFocusHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwStdFontTabPage
*>(this), &SwStdFontTabPage::LinkStubLoseFocusHdl)
;
538 m_xStandardBox->connect_focus_out( aFocusLink );
539 m_xTitleBox->connect_focus_out( aFocusLink );
540 m_xListBox->connect_focus_out( aFocusLink );
541 m_xLabelBox->connect_focus_out( aFocusLink );
542 m_xIdxBox->connect_focus_out( aFocusLink );
543}
544
545SwStdFontTabPage::~SwStdFontTabPage()
546{
547 m_xIndexHeightLB.reset();
548 m_xLabelHeightLB.reset();
549 m_xListHeightLB.reset();
550 m_xTitleHeightLB.reset();
551 m_xStandardHeightLB.reset();
552 m_pFontList.reset();
553 if (m_bDisposePrinter)
1
Assuming field 'm_bDisposePrinter' is true
2
Taking true branch
554 m_pPrt.disposeAndClear();
3
Calling 'VclPtr::disposeAndClear'
555 else
556 m_pPrt.clear();
557}
558
559std::unique_ptr<SfxTabPage> SwStdFontTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
560 const SfxItemSet* rAttrSet )
561{
562 return std::make_unique<SwStdFontTabPage>(pPage, pController, *rAttrSet);
563}
564
565static void lcl_SetColl(SwWrtShell* pWrtShell, sal_uInt16 nType,
566 SfxPrinter const * pPrt, const OUString& rStyle,
567 sal_uInt16 nFontWhich)
568{
569 vcl::Font aFont( rStyle, Size( 0, 10 ) );
570 if( pPrt )
571 aFont = pPrt->GetFontMetric( aFont );
572 SwTextFormatColl *pColl = pWrtShell->GetTextCollFromPool(nType);
573 pColl->SetFormatAttr(SvxFontItem(aFont.GetFamilyType(), aFont.GetFamilyName(),
574 OUString(), aFont.GetPitch(), aFont.GetCharSet(), nFontWhich));
575}
576
577static void lcl_SetColl(SwWrtShell* pWrtShell, sal_uInt16 nType,
578 sal_Int32 nHeight, sal_uInt16 nFontHeightWhich)
579{
580 float fSize = static_cast<float>(nHeight) / 10;
581 nHeight = CalcToUnit( fSize, MapUnit::MapTwip );
582 SwTextFormatColl *pColl = pWrtShell->GetTextCollFromPool(nType);
583 pColl->SetFormatAttr(SvxFontHeightItem(nHeight, 100, nFontHeightWhich));
584}
585
586bool SwStdFontTabPage::FillItemSet( SfxItemSet* )
587{
588 SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule
::Writer)))
->GetModuleConfig()->SetDefaultFontInCurrDocOnly(false);
589
590 const OUString sStandard = m_xStandardBox->get_active_text();
591 const OUString sTitle = m_xTitleBox->get_active_text();
592 const OUString sList = m_xListBox->get_active_text();
593 const OUString sLabel = m_xLabelBox->get_active_text();
594 const OUString sIdx = m_xIdxBox->get_active_text();
595
596 bool bStandardHeightChanged = m_xStandardHeightLB->get_value_changed_from_saved();
597 bool bTitleHeightChanged = m_xTitleHeightLB->get_value_changed_from_saved();
598 bool bListHeightChanged = m_xListHeightLB->get_value_changed_from_saved() && !m_bListHeightDefault;
599 bool bLabelHeightChanged = m_xLabelHeightLB->get_value_changed_from_saved() && !m_bLabelHeightDefault;
600 bool bIndexHeightChanged = m_xIndexHeightLB->get_value_changed_from_saved() && !m_bIndexHeightDefault;
601
602 m_pFontConfig->SetFontStandard(sStandard, m_nFontGroup);
603 m_pFontConfig->SetFontOutline(sTitle, m_nFontGroup);
604 m_pFontConfig->SetFontList(sList, m_nFontGroup);
605 m_pFontConfig->SetFontCaption(sLabel, m_nFontGroup);
606 m_pFontConfig->SetFontIndex(sIdx, m_nFontGroup);
607 if(bStandardHeightChanged)
608 {
609 float fSize = static_cast<float>(m_xStandardHeightLB->get_value()) / 10;
610 m_pFontConfig->SetFontHeight( CalcToUnit( fSize, MapUnit::MapTwip ), FONT_STANDARD0, m_nFontGroup );
611 }
612 if(bTitleHeightChanged)
613 {
614 float fSize = static_cast<float>(m_xTitleHeightLB->get_value()) / 10;
615 m_pFontConfig->SetFontHeight( CalcToUnit( fSize, MapUnit::MapTwip ), FONT_OUTLINE1, m_nFontGroup );
616 }
617 if(bListHeightChanged)
618 {
619 float fSize = static_cast<float>(m_xListHeightLB->get_value()) / 10;
620 m_pFontConfig->SetFontHeight( CalcToUnit( fSize, MapUnit::MapTwip ), FONT_LIST2, m_nFontGroup );
621 }
622 if(bLabelHeightChanged)
623 {
624 float fSize = static_cast<float>(m_xLabelHeightLB->get_value()) / 10;
625 m_pFontConfig->SetFontHeight( CalcToUnit( fSize, MapUnit::MapTwip ), FONT_CAPTION3, m_nFontGroup );
626 }
627 if(bIndexHeightChanged)
628 {
629 float fSize = static_cast<float>(m_xIndexHeightLB->get_value()) / 10;
630 m_pFontConfig->SetFontHeight( CalcToUnit( fSize, MapUnit::MapTwip ), FONT_INDEX4, m_nFontGroup );
631 }
632
633 if(m_pWrtShell)
634 {
635 m_pWrtShell->StartAllAction();
636 SfxPrinter* pPrinter = m_pWrtShell->getIDocumentDeviceAccess().getPrinter( false );
637 bool bMod = false;
638 const sal_uInt16 nFontWhich =
639 m_nFontGroup == FONT_GROUP_DEFAULT0 ? RES_CHRATR_FONT :
640 FONT_GROUP_CJK1 == m_nFontGroup ? RES_CHRATR_CJK_FONT : RES_CHRATR_CTL_FONT;
641 const sal_uInt16 nFontHeightWhich =
642 m_nFontGroup == FONT_GROUP_DEFAULT0 ? RES_CHRATR_FONTSIZE :
643 FONT_GROUP_CJK1 == m_nFontGroup ? RES_CHRATR_CJK_FONTSIZE : RES_CHRATR_CTL_FONTSIZE;
644 if(sStandard != m_sShellStd)
645 {
646 vcl::Font aFont( sStandard, Size( 0, 10 ) );
647 if( pPrinter )
648 aFont = pPrinter->GetFontMetric( aFont );
649 m_pWrtShell->SetDefault(SvxFontItem(aFont.GetFamilyType(), aFont.GetFamilyName(),
650 OUString(), aFont.GetPitch(), aFont.GetCharSet(), nFontWhich));
651 SwTextFormatColl *pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_STANDARD);
652 pColl->ResetFormatAttr(nFontWhich);
653 bMod = true;
654 }
655 if(bStandardHeightChanged)
656 {
657 float fSize = static_cast<float>(m_xStandardHeightLB->get_value()) / 10;
658 m_pWrtShell->SetDefault(SvxFontHeightItem( CalcToUnit( fSize, MapUnit::MapTwip ), 100, nFontHeightWhich ) );
659 SwTextFormatColl *pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_STANDARD);
660 pColl->ResetFormatAttr(nFontHeightWhich);
661 bMod = true;
662 }
663
664 if(sTitle != m_sShellTitle )
665 {
666 lcl_SetColl(m_pWrtShell, RES_POOLCOLL_HEADLINE_BASE, pPrinter, sTitle, nFontWhich);
667 bMod = true;
668 }
669 if(bTitleHeightChanged)
670 {
671 lcl_SetColl(m_pWrtShell, RES_POOLCOLL_HEADLINE_BASE,
672 sal::static_int_cast< sal_uInt16, sal_Int64 >(m_xTitleHeightLB->get_value()), nFontHeightWhich);
673 bMod = true;
674 }
675 if(sList != m_sShellList && (!m_bListDefault || !m_bSetListDefault ))
676 {
677 lcl_SetColl(m_pWrtShell, RES_POOLCOLL_NUMBER_BULLET_BASE, pPrinter, sList, nFontWhich);
678 bMod = true;
679 }
680 if(bListHeightChanged)
681 {
682 lcl_SetColl(m_pWrtShell, RES_POOLCOLL_NUMBER_BULLET_BASE,
683 sal::static_int_cast< sal_uInt16, sal_Int64 >(m_xListHeightLB->get_value()), nFontHeightWhich);
684 bMod = true;
685 }
686 if(sLabel != m_sShellLabel && (!m_bLabelDefault || !m_bSetLabelDefault))
687 {
688 lcl_SetColl(m_pWrtShell, RES_POOLCOLL_LABEL, pPrinter, sLabel, nFontWhich);
689 bMod = true;
690 }
691 if(bLabelHeightChanged)
692 {
693 lcl_SetColl(m_pWrtShell, RES_POOLCOLL_LABEL,
694 sal::static_int_cast< sal_uInt16, sal_Int64 >(m_xLabelHeightLB->get_value()), nFontHeightWhich);
695 bMod = true;
696 }
697 if(sIdx != m_sShellIndex && (!m_bIdxDefault || !m_bSetIdxDefault))
698 {
699 lcl_SetColl(m_pWrtShell, RES_POOLCOLL_REGISTER_BASE, pPrinter, sIdx, nFontWhich);
700 bMod = true;
701 }
702 if(bIndexHeightChanged)
703 {
704 lcl_SetColl(m_pWrtShell, RES_POOLCOLL_REGISTER_BASE,
705 sal::static_int_cast< sal_uInt16, sal_Int64 >(m_xIndexHeightLB->get_value()), nFontHeightWhich);
706 bMod = true;
707 }
708 if ( bMod )
709 m_pWrtShell->SetModified();
710 m_pWrtShell->EndAllAction();
711 }
712 return false;
713}
714
715void SwStdFontTabPage::Reset( const SfxItemSet* rSet)
716{
717 const SfxPoolItem* pLang;
718 const sal_uInt16 nLangSlot = m_nFontGroup == FONT_GROUP_DEFAULT0 ? SID_ATTR_LANGUAGE(((((10000 + 1499) + 1) + 499) + 1) + 7) :
719 FONT_GROUP_CJK1 == m_nFontGroup ? SID_ATTR_CHAR_CJK_LANGUAGE( 10000 + 889 ) : SID_ATTR_CHAR_CTL_LANGUAGE( 10000 + 894 );
720
721 if( SfxItemState::SET == rSet->GetItemState(nLangSlot, false, &pLang))
722 m_eLanguage = static_cast<const SvxLanguageItem*>(pLang)->GetValue();
723
724 OUString sToReplace = m_sScriptWestern;
725 if(FONT_GROUP_CJK1 == m_nFontGroup )
726 sToReplace = m_sScriptAsian;
727 else if(FONT_GROUP_CTL2 == m_nFontGroup )
728 sToReplace = m_sScriptComplex;
729 m_xLabelFT->set_label(m_xLabelFT->get_label().replaceFirst("%1", sToReplace));
730
731 const SfxPoolItem* pItem;
732
733 if (m_bDisposePrinter)
734 {
735 m_pPrt.disposeAndClear();
736 m_bDisposePrinter = false;
737 }
738
739 if(SfxItemState::SET == rSet->GetItemState(FN_PARAM_PRINTER((20000 + 1100)+78), false, &pItem))
740 {
741 m_pPrt = static_cast<SfxPrinter*>(static_cast<const SwPtrItem*>(pItem)->GetValue());
742 }
743 else
744 {
745 auto pPrinterSet = std::make_unique<SfxItemSet>( *rSet->GetPool(),
746 svl::Items<SID_PRINTER_NOTFOUND_WARN(5000 + 320), SID_PRINTER_NOTFOUND_WARN(5000 + 320),
747 SID_PRINTER_CHANGESTODOC(5000 + 324), SID_PRINTER_CHANGESTODOC(5000 + 324)>{} );
748 m_pPrt = VclPtr<SfxPrinter>::Create(std::move(pPrinterSet));
749 m_bDisposePrinter = true;
750 }
751 m_pFontList.reset(new FontList( m_pPrt ));
752 // #i94536# prevent duplication of font entries when 'reset' button is pressed
753 if( !m_xStandardBox->get_count() )
754 {
755 // get the set of distinct available family names
756 std::set< OUString > aFontNames;
757 int nFontNames = m_pPrt->GetDevFontCount();
758 for( int i = 0; i < nFontNames; i++ )
759 {
760 FontMetric aFontMetric( m_pPrt->GetDevFont( i ) );
761 aFontNames.insert( aFontMetric.GetFamilyName() );
762 }
763
764 // insert to listboxes
765 for( const auto& rFontName : aFontNames )
766 {
767 m_xStandardBox->append_text( rFontName );
768 m_xTitleBox->append_text( rFontName );
769 m_xListBox->append_text( rFontName );
770 m_xLabelBox->append_text( rFontName );
771 m_xIdxBox->append_text( rFontName );
772 }
773 }
774 if(SfxItemState::SET == rSet->GetItemState(FN_PARAM_STDFONTS((20000 + 1100)+79), false, &pItem))
775 {
776 m_pFontConfig = static_cast<SwStdFontConfig*>(static_cast<const SwPtrItem*>(pItem)->GetValue());
777 }
778
779 if(SfxItemState::SET == rSet->GetItemState(FN_PARAM_WRTSHELL((20000 + 2400)), false, &pItem))
780 {
781 m_pWrtShell = static_cast<SwWrtShell*>(static_cast<const SwPtrItem*>(pItem)->GetValue());
782 }
783 OUString sStdBackup;
784 OUString sOutBackup;
785 OUString sListBackup;
786 OUString sCapBackup;
787 OUString sIdxBackup;
788 sal_Int32 nStandardHeight = -1;
789 sal_Int32 nTitleHeight = -1;
790 sal_Int32 nListHeight = -1;
791 sal_Int32 nLabelHeight = -1;
792 sal_Int32 nIndexHeight = -1;
793
794 if(!m_pWrtShell)
795 {
796 sStdBackup = m_pFontConfig->GetFontStandard(m_nFontGroup);
797 sOutBackup = m_pFontConfig->GetFontOutline(m_nFontGroup);
798 sListBackup= m_pFontConfig->GetFontList(m_nFontGroup);
799 sCapBackup = m_pFontConfig->GetFontCaption(m_nFontGroup);
800 sIdxBackup = m_pFontConfig->GetFontIndex(m_nFontGroup);
801 nStandardHeight = m_pFontConfig->GetFontHeight( FONT_STANDARD0, m_nFontGroup, m_eLanguage );
802 nTitleHeight = m_pFontConfig->GetFontHeight( FONT_OUTLINE1 , m_nFontGroup, m_eLanguage );
803 nListHeight = m_pFontConfig->GetFontHeight( FONT_LIST2 , m_nFontGroup, m_eLanguage );
804 nLabelHeight = m_pFontConfig->GetFontHeight( FONT_CAPTION3 , m_nFontGroup, m_eLanguage );
805 nIndexHeight = m_pFontConfig->GetFontHeight( FONT_INDEX4 , m_nFontGroup, m_eLanguage );
806 if( nStandardHeight <= 0)
807 nStandardHeight = SwStdFontConfig::GetDefaultHeightFor( FONT_STANDARD0 + m_nFontGroup * FONT_PER_GROUP5, m_eLanguage);
808 if( nTitleHeight <= 0)
809 nTitleHeight = SwStdFontConfig::GetDefaultHeightFor( FONT_OUTLINE1 + m_nFontGroup * FONT_PER_GROUP5, m_eLanguage);
810 if( nListHeight <= 0)
811 nListHeight = SwStdFontConfig::GetDefaultHeightFor( FONT_LIST2 + m_nFontGroup * FONT_PER_GROUP5, m_eLanguage);
812 if( nLabelHeight <= 0)
813 nLabelHeight = SwStdFontConfig::GetDefaultHeightFor( FONT_CAPTION3 + m_nFontGroup * FONT_PER_GROUP5, m_eLanguage);
814 if( nIndexHeight <= 0)
815 nIndexHeight = SwStdFontConfig::GetDefaultHeightFor( FONT_INDEX4 + m_nFontGroup * FONT_PER_GROUP5, m_eLanguage);
816 }
817 else
818 {
819 SwTextFormatColl *pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_STANDARD);
820 const SvxFontItem& rFont = !m_nFontGroup ? pColl->GetFont() :
821 FONT_GROUP_CJK1 == m_nFontGroup ? pColl->GetCJKFont() : pColl->GetCTLFont();
822 m_sShellStd = sStdBackup = rFont.GetFamilyName();
823
824 const sal_uInt16 nFontHeightWhich =
825 m_nFontGroup == FONT_GROUP_DEFAULT0 ? RES_CHRATR_FONTSIZE :
826 FONT_GROUP_CJK1 == m_nFontGroup ? RES_CHRATR_CJK_FONTSIZE : RES_CHRATR_CTL_FONTSIZE;
827 const SvxFontHeightItem& rFontHeightStandard = static_cast<const SvxFontHeightItem& >(pColl->GetFormatAttr(nFontHeightWhich));
828 nStandardHeight = static_cast<sal_Int32>(rFontHeightStandard.GetHeight());
829
830 pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_HEADLINE_BASE);
831 const SvxFontItem& rFontHL = !m_nFontGroup ? pColl->GetFont() :
832 FONT_GROUP_CJK1 == m_nFontGroup ? pColl->GetCJKFont() : pColl->GetCTLFont();
833 m_sShellTitle = sOutBackup = rFontHL.GetFamilyName();
834
835 const SvxFontHeightItem& rFontHeightTitle = static_cast<const SvxFontHeightItem&>(pColl->GetFormatAttr( nFontHeightWhich ));
836 nTitleHeight = static_cast<sal_Int32>(rFontHeightTitle.GetHeight());
837
838 const sal_uInt16 nFontWhich =
839 m_nFontGroup == FONT_GROUP_DEFAULT0 ? RES_CHRATR_FONT :
840 FONT_GROUP_CJK1 == m_nFontGroup ? RES_CHRATR_CJK_FONT : RES_CHRATR_CTL_FONT;
841 pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_NUMBER_BULLET_BASE);
842 const SvxFontItem& rFontLS = !m_nFontGroup ? pColl->GetFont() :
843 FONT_GROUP_CJK1 == m_nFontGroup ? pColl->GetCJKFont() : pColl->GetCTLFont();
844 m_bListDefault = SfxItemState::DEFAULT == pColl->GetAttrSet().GetItemState(nFontWhich, false);
845 m_sShellList = sListBackup = rFontLS.GetFamilyName();
846
847 const SvxFontHeightItem& rFontHeightList = static_cast<const SvxFontHeightItem&>(pColl->GetFormatAttr(nFontHeightWhich));
848 nListHeight = static_cast<sal_Int32>(rFontHeightList.GetHeight());
849 m_bListHeightDefault = SfxItemState::DEFAULT == pColl->GetAttrSet().GetItemState(nFontWhich, false);
850
851 pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_LABEL);
852 m_bLabelDefault = SfxItemState::DEFAULT == pColl->GetAttrSet().GetItemState(nFontWhich, false);
853 const SvxFontItem& rFontCP = !m_nFontGroup ? pColl->GetFont() :
854 FONT_GROUP_CJK1 == m_nFontGroup ? pColl->GetCJKFont() : pColl->GetCTLFont();
855 m_sShellLabel = sCapBackup = rFontCP.GetFamilyName();
856 const SvxFontHeightItem& rFontHeightLabel = static_cast<const SvxFontHeightItem&>(pColl->GetFormatAttr(nFontHeightWhich));
857 nLabelHeight = static_cast<sal_Int32>(rFontHeightLabel.GetHeight());
858 m_bLabelHeightDefault = SfxItemState::DEFAULT == pColl->GetAttrSet().GetItemState(nFontWhich, false);
859
860 pColl = m_pWrtShell->GetTextCollFromPool(RES_POOLCOLL_REGISTER_BASE);
861 m_bIdxDefault = SfxItemState::DEFAULT == pColl->GetAttrSet().GetItemState(nFontWhich, false);
862 const SvxFontItem& rFontIDX = !m_nFontGroup ? pColl->GetFont() :
863 FONT_GROUP_CJK1 == m_nFontGroup ? pColl->GetCJKFont() : pColl->GetCTLFont();
864 m_sShellIndex = sIdxBackup = rFontIDX.GetFamilyName();
865 const SvxFontHeightItem& rFontHeightIndex = static_cast<const SvxFontHeightItem&>(pColl->GetFormatAttr(nFontHeightWhich));
866 nIndexHeight = static_cast<sal_Int32>(rFontHeightIndex.GetHeight());
867 m_bIndexHeightDefault = SfxItemState::DEFAULT == pColl->GetAttrSet().GetItemState(nFontWhich, false);
868 }
869 m_xStandardBox->set_entry_text(sStdBackup );
870 m_xTitleBox->set_entry_text(sOutBackup );
871 m_xListBox->set_entry_text(sListBackup);
872 m_xLabelBox->set_entry_text(sCapBackup );
873 m_xIdxBox->set_entry_text(sIdxBackup );
874
875 FontMetric aFontMetric( m_pFontList->Get(sStdBackup, sStdBackup) );
876 m_xStandardHeightLB->Fill( &aFontMetric, m_pFontList.get() );
877 aFontMetric = m_pFontList->Get(sOutBackup, sOutBackup );
878 m_xTitleHeightLB->Fill( &aFontMetric, m_pFontList.get() );
879 aFontMetric = m_pFontList->Get(sListBackup,sListBackup);
880 m_xListHeightLB->Fill( &aFontMetric, m_pFontList.get() );
881 aFontMetric = m_pFontList->Get(sCapBackup, sCapBackup );
882 m_xLabelHeightLB->Fill( &aFontMetric, m_pFontList.get() );
883 aFontMetric = m_pFontList->Get(sIdxBackup, sIdxBackup );
884 m_xIndexHeightLB->Fill( &aFontMetric, m_pFontList.get() );
885
886 m_xStandardHeightLB->set_value( CalcToPoint( nStandardHeight, MapUnit::MapTwip, 10 ) );
887 m_xTitleHeightLB->set_value( CalcToPoint( nTitleHeight , MapUnit::MapTwip, 10 ) );
888 m_xListHeightLB->set_value( CalcToPoint( nListHeight , MapUnit::MapTwip, 10 ) );
889 m_xLabelHeightLB->set_value( CalcToPoint( nLabelHeight , MapUnit::MapTwip, 10 ));
890 m_xIndexHeightLB->set_value( CalcToPoint( nIndexHeight , MapUnit::MapTwip, 10 ));
891
892 m_xStandardBox->save_value();
893 m_xTitleBox->save_value();
894 m_xListBox->save_value();
895 m_xLabelBox->save_value();
896 m_xIdxBox->save_value();
897
898 m_xStandardHeightLB->save_value();
899 m_xTitleHeightLB->save_value();
900 m_xListHeightLB->save_value();
901 m_xLabelHeightLB->save_value();
902 m_xIndexHeightLB->save_value();
903}
904
905IMPL_LINK_NOARG(SwStdFontTabPage, StandardHdl, weld::Button&, void)void SwStdFontTabPage::LinkStubStandardHdl(void * instance, weld
::Button& data) { return static_cast<SwStdFontTabPage *
>(instance)->StandardHdl(data); } void SwStdFontTabPage
::StandardHdl(__attribute__ ((unused)) weld::Button&)
906{
907 sal_uInt8 nFontOffset = m_nFontGroup * FONT_PER_GROUP5;
908 m_xStandardBox->set_entry_text(SwStdFontConfig::GetDefaultFor(FONT_STANDARD0 + nFontOffset, m_eLanguage));
909 m_xTitleBox->set_entry_text(SwStdFontConfig::GetDefaultFor(FONT_OUTLINE1 + nFontOffset, m_eLanguage));
910 m_xListBox->set_entry_text(SwStdFontConfig::GetDefaultFor(FONT_LIST2 + nFontOffset, m_eLanguage));
911 m_xLabelBox->set_entry_text(SwStdFontConfig::GetDefaultFor(FONT_CAPTION3 + nFontOffset, m_eLanguage));
912 m_xIdxBox->set_entry_text(SwStdFontConfig::GetDefaultFor(FONT_INDEX4 + nFontOffset, m_eLanguage));
913
914 m_xStandardBox->save_value();
915 m_xTitleBox->save_value();
916 m_xListBox->save_value();
917 m_xLabelBox->save_value();
918 m_xIdxBox->save_value();
919
920 m_xStandardHeightLB->set_value( CalcToPoint(
921 SwStdFontConfig::GetDefaultHeightFor(FONT_STANDARD0 + nFontOffset, m_eLanguage),
922 MapUnit::MapTwip, 10 ));
923 m_xTitleHeightLB->set_value(CalcToPoint(
924 SwStdFontConfig::GetDefaultHeightFor(FONT_OUTLINE1 +
925 nFontOffset, m_eLanguage), MapUnit::MapTwip, 10 ));
926 m_xListHeightLB->set_value(CalcToPoint(
927 SwStdFontConfig::GetDefaultHeightFor(FONT_LIST2 + nFontOffset, m_eLanguage),
928 MapUnit::MapTwip, 10 ));
929 m_xLabelHeightLB->set_value(CalcToPoint(
930 SwStdFontConfig::GetDefaultHeightFor(FONT_CAPTION3 + nFontOffset, m_eLanguage),
931 MapUnit::MapTwip, 10 ));
932 m_xIndexHeightLB->set_value(CalcToPoint(
933 SwStdFontConfig::GetDefaultHeightFor(FONT_INDEX4 + nFontOffset, m_eLanguage),
934 MapUnit::MapTwip, 10 ));
935}
936
937IMPL_LINK( SwStdFontTabPage, ModifyHdl, weld::ComboBox&, rBox, void )void SwStdFontTabPage::LinkStubModifyHdl(void * instance, weld
::ComboBox& data) { return static_cast<SwStdFontTabPage
*>(instance)->ModifyHdl(data); } void SwStdFontTabPage
::ModifyHdl(weld::ComboBox& rBox)
938{
939 if (&rBox == m_xStandardBox.get())
940 {
941 const OUString sEntry = rBox.get_active_text();
942 if(m_bSetListDefault && m_bListDefault)
943 m_xListBox->set_entry_text(sEntry);
944 if(m_bSetLabelDefault && m_bLabelDefault)
945 m_xLabelBox->set_entry_text(sEntry);
946 if(m_bSetIdxDefault && m_bIdxDefault)
947 m_xIdxBox->set_entry_text(sEntry);
948 }
949 else if (&rBox == m_xListBox.get())
950 {
951 m_bSetListDefault = false;
952 }
953 else if (&rBox == m_xLabelBox.get())
954 {
955 m_bSetLabelDefault = false;
956 }
957 else if (&rBox == m_xIdxBox.get())
958 {
959 m_bSetIdxDefault = false;
960 }
961}
962
963IMPL_LINK( SwStdFontTabPage, LoseFocusHdl, weld::Widget&, rControl, void )void SwStdFontTabPage::LinkStubLoseFocusHdl(void * instance, weld
::Widget& data) { return static_cast<SwStdFontTabPage *
>(instance)->LoseFocusHdl(data); } void SwStdFontTabPage
::LoseFocusHdl(weld::Widget& rControl)
964{
965 weld::ComboBox& rBox = dynamic_cast<weld::ComboBox&>(rControl);
966 FontSizeBox* pHeightLB = nullptr;
967 const OUString sEntry = rBox.get_active_text();
968 if (&rBox == m_xStandardBox.get())
969 {
970 pHeightLB = m_xStandardHeightLB.get();
971 }
972 else if (&rBox == m_xTitleBox.get())
973 {
974 pHeightLB = m_xTitleHeightLB.get();
975 }
976 else if (&rBox == m_xListBox.get())
977 {
978 pHeightLB = m_xListHeightLB.get();
979 }
980 else if (&rBox == m_xLabelBox.get())
981 {
982 pHeightLB = m_xLabelHeightLB.get();
983 }
984 else /*if (&rBox == m_xIndexHeightLB.get())*/
985 {
986 pHeightLB = m_xIndexHeightLB.get();
987 }
988 FontMetric aFontMetric( m_pFontList->Get(sEntry, sEntry) );
989 pHeightLB->Fill( &aFontMetric, m_pFontList.get() );
990}
991
992void SwStdFontTabPage::PageCreated( const SfxAllItemSet& aSet)
993{
994 const SfxUInt16Item* pFlagItem = aSet.GetItem<SfxUInt16Item>(SID_FONTMODE_TYPE(((20000) + 800) + 115), false);
995 if (pFlagItem)
996 m_nFontGroup = sal::static_int_cast< sal_uInt8, sal_uInt16>( pFlagItem->GetValue() );
997}
998
999SwTableOptionsTabPage::SwTableOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
1000 : SfxTabPage(pPage, pController, "modules/swriter/ui/opttablepage.ui", "OptTablePage", &rSet)
1001 , m_pWrtShell(nullptr)
1002 , m_bHTMLMode(false)
1003 , m_xHeaderCB(m_xBuilder->weld_check_button("header"))
1004 , m_xRepeatHeaderCB(m_xBuilder->weld_check_button("repeatheader"))
1005 , m_xDontSplitCB(m_xBuilder->weld_check_button("dontsplit"))
1006 , m_xBorderCB(m_xBuilder->weld_check_button("border"))
1007 , m_xNumFormattingCB(m_xBuilder->weld_check_button("numformatting"))
1008 , m_xNumFormatFormattingCB(m_xBuilder->weld_check_button("numfmtformatting"))
1009 , m_xNumAlignmentCB(m_xBuilder->weld_check_button("numalignment"))
1010 , m_xRowMoveMF(m_xBuilder->weld_metric_spin_button("rowmove", FieldUnit::CM))
1011 , m_xColMoveMF(m_xBuilder->weld_metric_spin_button("colmove", FieldUnit::CM))
1012 , m_xRowInsertMF(m_xBuilder->weld_metric_spin_button("rowinsert", FieldUnit::CM))
1013 , m_xColInsertMF(m_xBuilder->weld_metric_spin_button("colinsert", FieldUnit::CM))
1014 , m_xFixRB(m_xBuilder->weld_radio_button("fix"))
1015 , m_xFixPropRB(m_xBuilder->weld_radio_button("fixprop"))
1016 , m_xVarRB(m_xBuilder->weld_radio_button("var"))
1017{
1018 Link<weld::Button&,void> aLnk(LINK(this, SwTableOptionsTabPage, CheckBoxHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwTableOptionsTabPage
*>(this), &SwTableOptionsTabPage::LinkStubCheckBoxHdl
)
);
1019 m_xNumFormattingCB->connect_clicked(aLnk);
1020 m_xNumFormatFormattingCB->connect_clicked(aLnk);
1021 m_xHeaderCB->connect_clicked(aLnk);
1022}
1023
1024SwTableOptionsTabPage::~SwTableOptionsTabPage()
1025{
1026}
1027
1028std::unique_ptr<SfxTabPage> SwTableOptionsTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
1029 const SfxItemSet* rAttrSet )
1030{
1031 return std::make_unique<SwTableOptionsTabPage>(pPage, pController, *rAttrSet);
1032}
1033
1034bool SwTableOptionsTabPage::FillItemSet( SfxItemSet* )
1035{
1036 bool bRet = false;
1037 SwModuleOptions* pModOpt = SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule
::Writer)))
->GetModuleConfig();
1038
1039 if (m_xRowMoveMF->get_value_changed_from_saved())
1040 pModOpt->SetTableHMove( static_cast<sal_uInt16>(m_xRowMoveMF->denormalize( m_xRowMoveMF->get_value(FieldUnit::TWIP))));
1041
1042 if (m_xColMoveMF->get_value_changed_from_saved())
1043 pModOpt->SetTableVMove( static_cast<sal_uInt16>(m_xColMoveMF->denormalize( m_xColMoveMF->get_value(FieldUnit::TWIP))));
1044
1045 if (m_xRowInsertMF->get_value_changed_from_saved())
1046 pModOpt->SetTableHInsert(static_cast<sal_uInt16>(m_xRowInsertMF->denormalize( m_xRowInsertMF->get_value(FieldUnit::TWIP))));
1047
1048 if (m_xColInsertMF->get_value_changed_from_saved())
1049 pModOpt->SetTableVInsert(static_cast<sal_uInt16>(m_xColInsertMF->denormalize( m_xColInsertMF->get_value(FieldUnit::TWIP))));
1050
1051 TableChgMode eMode;
1052 if (m_xFixRB->get_active())
1053 eMode = TableChgMode::FixedWidthChangeAbs;
1054 else if(m_xFixPropRB->get_active())
1055 eMode = TableChgMode::FixedWidthChangeProp;
1056 else
1057 eMode = TableChgMode::VarWidthChangeAbs;
1058 if(eMode != pModOpt->GetTableMode())
1059 {
1060 pModOpt->SetTableMode(eMode);
1061 // the table-keyboard-mode has changed, now the current
1062 // table should know about that too.
1063 if(m_pWrtShell && SelectionType::Table & m_pWrtShell->GetSelectionType())
1064 {
1065 m_pWrtShell->SetTableChgMode(eMode);
1066 static sal_uInt16 aInva[] =
1067 { FN_TABLE_MODE_FIX((20000 + 400) + 189),
1068 FN_TABLE_MODE_FIX_PROP((20000 + 400) + 190),
1069 FN_TABLE_MODE_VARIABLE((20000 + 400) + 191),
1070 0
1071 };
1072 m_pWrtShell->GetView().GetViewFrame()->GetBindings().Invalidate( aInva );
1073 }
1074
1075 bRet = true;
1076 }
1077
1078 SwInsertTableOptions aInsOpts( SwInsertTableFlags::NONE, 0 );
1079
1080 if (m_xHeaderCB->get_active())
1081 aInsOpts.mnInsMode |= SwInsertTableFlags::Headline;
1082
1083 if (m_xRepeatHeaderCB->get_sensitive())
1084 aInsOpts.mnRowsToRepeat = m_xRepeatHeaderCB->get_active() ? 1 : 0;
1085
1086 if (!m_xDontSplitCB->get_active())
1087 aInsOpts.mnInsMode |= SwInsertTableFlags::SplitLayout;
1088
1089 if (m_xBorderCB->get_active())
1090 aInsOpts.mnInsMode |= SwInsertTableFlags::DefaultBorder;
1091
1092 if (m_xHeaderCB->get_state_changed_from_saved() ||
1093 m_xRepeatHeaderCB->get_state_changed_from_saved() ||
1094 m_xDontSplitCB->get_state_changed_from_saved() ||
1095 m_xBorderCB->get_state_changed_from_saved())
1096 {
1097 pModOpt->SetInsTableFlags(m_bHTMLMode, aInsOpts);
1098 }
1099
1100 if (m_xNumFormattingCB->get_state_changed_from_saved())
1101 {
1102 pModOpt->SetInsTableFormatNum(m_bHTMLMode, m_xNumFormattingCB->get_active());
1103 bRet = true;
1104 }
1105
1106 if (m_xNumFormatFormattingCB->get_state_changed_from_saved())
1107 {
1108 pModOpt->SetInsTableChangeNumFormat(m_bHTMLMode, m_xNumFormatFormattingCB->get_active());
1109 bRet = true;
1110 }
1111
1112 if (m_xNumAlignmentCB->get_state_changed_from_saved())
1113 {
1114 pModOpt->SetInsTableAlignNum(m_bHTMLMode, m_xNumAlignmentCB->get_active());
1115 bRet = true;
1116 }
1117
1118 return bRet;
1119}
1120
1121void SwTableOptionsTabPage::Reset( const SfxItemSet* rSet)
1122{
1123 const SwModuleOptions* pModOpt = SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule
::Writer)))
->GetModuleConfig();
1124 if ( rSet->GetItemState( SID_ATTR_METRICTypedWhichId<SfxUInt16Item>(((((10000 + 1499) + 1) + 499
) + 1) + 8)
) >= SfxItemState::DEFAULT )
1125 {
1126 const SfxUInt16Item& rItem = rSet->Get( SID_ATTR_METRICTypedWhichId<SfxUInt16Item>(((((10000 + 1499) + 1) + 499
) + 1) + 8)
);
1127 FieldUnit eFieldUnit = static_cast<FieldUnit>(rItem.GetValue());
1128 ::SetFieldUnit( *m_xRowMoveMF, eFieldUnit );
1129 ::SetFieldUnit( *m_xColMoveMF, eFieldUnit );
1130 ::SetFieldUnit( *m_xRowInsertMF, eFieldUnit );
1131 ::SetFieldUnit( *m_xColInsertMF, eFieldUnit );
1132 }
1133
1134 m_xRowMoveMF->set_value(m_xRowMoveMF->normalize(pModOpt->GetTableHMove()), FieldUnit::TWIP);
1135 m_xColMoveMF->set_value(m_xColMoveMF->normalize(pModOpt->GetTableVMove()), FieldUnit::TWIP);
1136 m_xRowInsertMF->set_value(m_xRowInsertMF->normalize(pModOpt->GetTableHInsert()), FieldUnit::TWIP);
1137 m_xColInsertMF->set_value(m_xColInsertMF->normalize(pModOpt->GetTableVInsert()), FieldUnit::TWIP);
1138
1139 switch(pModOpt->GetTableMode())
1140 {
1141 case TableChgMode::FixedWidthChangeAbs: m_xFixRB->set_active(true); break;
1142 case TableChgMode::FixedWidthChangeProp: m_xFixPropRB->set_active(true); break;
1143 case TableChgMode::VarWidthChangeAbs: m_xVarRB->set_active(true); break;
1144 }
1145 const SfxPoolItem* pItem;
1146 if(SfxItemState::SET == rSet->GetItemState(SID_HTML_MODE(10000 + 414), false, &pItem))
1147 {
1148 m_bHTMLMode = 0 != (static_cast<const SfxUInt16Item*>(pItem)->GetValue() & HTMLMODE_ON);
1149 }
1150
1151 // hide certain controls for html
1152 if (m_bHTMLMode)
1153 {
1154 m_xRepeatHeaderCB->hide();
1155 m_xDontSplitCB->hide();
1156 }
1157
1158 SwInsertTableOptions aInsOpts = pModOpt->GetInsTableFlags(m_bHTMLMode);
1159 const SwInsertTableFlags nInsTableFlags = aInsOpts.mnInsMode;
1160
1161 m_xHeaderCB->set_active(bool(nInsTableFlags & SwInsertTableFlags::Headline));
1162 m_xRepeatHeaderCB->set_active((!m_bHTMLMode) && (aInsOpts.mnRowsToRepeat > 0));
1163 m_xDontSplitCB->set_active(!(nInsTableFlags & SwInsertTableFlags::SplitLayout));
1164 m_xBorderCB->set_active(bool(nInsTableFlags & SwInsertTableFlags::DefaultBorder));
1165
1166 m_xNumFormattingCB->set_active(pModOpt->IsInsTableFormatNum(m_bHTMLMode));
1167 m_xNumFormatFormattingCB->set_active(pModOpt->IsInsTableChangeNumFormat(m_bHTMLMode));
1168 m_xNumAlignmentCB->set_active(pModOpt->IsInsTableAlignNum(m_bHTMLMode));
1169
1170 m_xHeaderCB->save_state();
1171 m_xRepeatHeaderCB->save_state();
1172 m_xDontSplitCB->save_state();
1173 m_xBorderCB->save_state();
1174 m_xNumFormattingCB->save_state();
1175 m_xNumFormatFormattingCB->save_state();
1176 m_xNumAlignmentCB->save_state();
1177 m_xRowMoveMF->save_value();
1178 m_xColMoveMF->save_value();
1179 m_xRowInsertMF->save_value();
1180 m_xColInsertMF->save_value();
1181
1182 CheckBoxHdl(*m_xHeaderCB);
1183}
1184
1185IMPL_LINK_NOARG(SwTableOptionsTabPage, CheckBoxHdl, weld::Button&, void)void SwTableOptionsTabPage::LinkStubCheckBoxHdl(void * instance
, weld::Button& data) { return static_cast<SwTableOptionsTabPage
*>(instance)->CheckBoxHdl(data); } void SwTableOptionsTabPage
::CheckBoxHdl(__attribute__ ((unused)) weld::Button&)
1186{
1187 m_xNumFormatFormattingCB->set_sensitive(m_xNumFormattingCB->get_active());
1188 m_xNumAlignmentCB->set_sensitive(m_xNumFormattingCB->get_active());
1189 m_xRepeatHeaderCB->set_sensitive(m_xHeaderCB->get_active());
1190}
1191
1192void SwTableOptionsTabPage::PageCreated( const SfxAllItemSet& aSet)
1193{
1194 const SwWrtShellItem* pWrtSh = aSet.GetItem<SwWrtShellItem>(SID_WRT_SHELL(((20000) + 800) + 117), false);
1195 if (pWrtSh)
1196 m_pWrtShell = pWrtSh->GetValue();
1197}
1198
1199SwShdwCursorOptionsTabPage::SwShdwCursorOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
1200 : SfxTabPage(pPage, pController, "modules/swriter/ui/optformataidspage.ui", "OptFormatAidsPage", &rSet)
1201 , m_pWrtShell(nullptr)
1202 , m_xParaCB(m_xBuilder->weld_check_button("paragraph"))
1203 , m_xSHyphCB(m_xBuilder->weld_check_button("hyphens"))
1204 , m_xSpacesCB(m_xBuilder->weld_check_button("spaces"))
1205 , m_xHSpacesCB(m_xBuilder->weld_check_button("nonbreak"))
1206 , m_xTabCB(m_xBuilder->weld_check_button("tabs"))
1207 , m_xTabLabel(m_xBuilder->weld_label("tabs_label"))
1208 , m_xBreakCB(m_xBuilder->weld_check_button("break"))
1209 , m_xCharHiddenCB(m_xBuilder->weld_check_button("hiddentext"))
1210 , m_xBookmarkCB(m_xBuilder->weld_check_button("bookmarks"))
1211 , m_xBookmarkLabel(m_xBuilder->weld_label("bookmarks_label"))
1212 , m_xDirectCursorFrame(m_xBuilder->weld_frame("directcrsrframe"))
1213 , m_xOnOffCB(m_xBuilder->weld_check_button("cursoronoff"))
1214 , m_xDirectCursorFillMode(m_xBuilder->weld_combo_box("cxDirectCursorFillMode"))
1215 , m_xCursorProtFrame(m_xBuilder->weld_frame("crsrprotframe"))
1216 , m_xCursorInProtCB(m_xBuilder->weld_check_button("cursorinprot"))
1217 , m_xMathBaselineAlignmentCB(m_xBuilder->weld_check_button("mathbaseline"))
1218{
1219 const SfxPoolItem* pItem = nullptr;
1220 SwFillMode eMode = SwFillMode::Tab;
1221 bool bIsOn = false;
1222
1223 if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_SHADOWCURSOR((20000 + 2400)+8), false, &pItem ))
1224 {
1225 auto& aOpt = *static_cast<const SwShadowCursorItem*>(pItem);
1226 eMode = aOpt.GetMode();
1227 bIsOn = aOpt.IsOn();
1228 }
1229 m_xOnOffCB->set_active( bIsOn );
1230
1231 m_xDirectCursorFillMode->set_active( static_cast<int>(eMode) );
1232 if(SfxItemState::SET != rSet.GetItemState(SID_HTML_MODE(10000 + 414), false, &pItem )
1233 || !(static_cast<const SfxUInt16Item*>(pItem)->GetValue() & HTMLMODE_ON))
1234 return;
1235
1236 m_xTabCB->hide();
1237 m_xTabLabel->hide();
1238 m_xCharHiddenCB->hide();
1239 m_xBookmarkCB->hide();
1240 m_xBookmarkLabel->hide();
1241
1242 m_xDirectCursorFrame->hide();
1243 m_xOnOffCB->hide();
1244 m_xDirectCursorFillMode->hide();
1245 m_xCursorProtFrame->hide();
1246 m_xCursorInProtCB->hide();
1247}
1248
1249SwShdwCursorOptionsTabPage::~SwShdwCursorOptionsTabPage()
1250{
1251}
1252
1253std::unique_ptr<SfxTabPage> SwShdwCursorOptionsTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet )
1254{
1255 return std::make_unique<SwShdwCursorOptionsTabPage>(pPage, pController, *rSet);
1256}
1257
1258void SwShdwCursorOptionsTabPage::PageCreated( const SfxAllItemSet& aSet )
1259{
1260 const SwWrtShellItem* pWrtSh = aSet.GetItem<SwWrtShellItem>(SID_WRT_SHELL(((20000) + 800) + 117), false);
1261 if (pWrtSh)
1262 m_pWrtShell = pWrtSh->GetValue();
1263}
1264
1265bool SwShdwCursorOptionsTabPage::FillItemSet( SfxItemSet* rSet )
1266{
1267 SwShadowCursorItem aOpt;
1268 aOpt.SetOn( m_xOnOffCB->get_active() );
1269
1270 SwFillMode eMode = static_cast<SwFillMode>(m_xDirectCursorFillMode->get_active());
1271 aOpt.SetMode( eMode );
1272
1273 bool bRet = false;
1274 const SfxPoolItem* pItem = nullptr;
1275 if( SfxItemState::SET != rSet->GetItemState( FN_PARAM_SHADOWCURSOR((20000 + 2400)+8), false, &pItem )
1276 || static_cast<const SwShadowCursorItem&>(*pItem) != aOpt )
1277 {
1278 rSet->Put( aOpt );
1279 bRet = true;
1280 }
1281
1282 if (m_pWrtShell) {
1283 m_pWrtShell->GetDoc()->getIDocumentSettingAccess().set( DocumentSettingId::MATH_BASELINE_ALIGNMENT,
1284 m_xMathBaselineAlignmentCB->get_active() );
1285 bRet |= m_xMathBaselineAlignmentCB->get_state_changed_from_saved();
1286 }
1287
1288 if( m_xCursorInProtCB->get_state_changed_from_saved())
1289 {
1290 rSet->Put(SfxBoolItem(FN_PARAM_CRSR_IN_PROTECTED((20000 + 2400)+13), m_xCursorInProtCB->get_active()));
1291 bRet = true;
1292 }
1293
1294 const SwDocDisplayItem* pOldAttr = static_cast<const SwDocDisplayItem*>(
1295 GetOldItem(GetItemSet(), FN_PARAM_DOCDISP((20000 + 1100)+20)));
1296
1297 SwDocDisplayItem aDisp;
1298
1299 aDisp.m_bParagraphEnd = m_xParaCB->get_active();
1300 aDisp.m_bTab = m_xTabCB->get_active();
1301 aDisp.m_bSpace = m_xSpacesCB->get_active();
1302 aDisp.m_bNonbreakingSpace = m_xHSpacesCB->get_active();
1303 aDisp.m_bSoftHyphen = m_xSHyphCB->get_active();
1304 aDisp.m_bCharHiddenText = m_xCharHiddenCB->get_active();
1305 aDisp.m_bBookmarks = m_xBookmarkCB->get_active();
1306 aDisp.m_bManualBreak = m_xBreakCB->get_active();
1307
1308 bRet |= (!pOldAttr || aDisp != *pOldAttr);
1309 if(bRet)
1310 bRet = nullptr != rSet->Put(aDisp);
1311
1312 return bRet;
1313}
1314
1315void SwShdwCursorOptionsTabPage::Reset( const SfxItemSet* rSet )
1316{
1317 const SfxPoolItem* pItem = nullptr;
1318 SwFillMode eMode = SwFillMode::Tab;
1319 bool bIsOn = false;
1320
1321 if( SfxItemState::SET == rSet->GetItemState( FN_PARAM_SHADOWCURSOR((20000 + 2400)+8), false, &pItem ))
1322 {
1323 auto& aOpt = *static_cast<const SwShadowCursorItem*>(pItem);
1324 eMode = aOpt.GetMode();
1325 bIsOn = aOpt.IsOn();
1326 }
1327 m_xOnOffCB->set_active( bIsOn );
1328
1329 m_xDirectCursorFillMode->set_active( static_cast<int>(eMode) );
1330 if (m_pWrtShell) {
1331 m_xMathBaselineAlignmentCB->set_active( m_pWrtShell->GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT ) );
1332 m_xMathBaselineAlignmentCB->save_state();
1333 } else {
1334 m_xMathBaselineAlignmentCB->hide();
1335 }
1336
1337 if( SfxItemState::SET == rSet->GetItemState( FN_PARAM_CRSR_IN_PROTECTED((20000 + 2400)+13), false, &pItem ))
1338 m_xCursorInProtCB->set_active(static_cast<const SfxBoolItem*>(pItem)->GetValue());
1339 m_xCursorInProtCB->save_state();
1340
1341 const SwDocDisplayItem* pDocDisplayAttr = nullptr;
1342
1343 rSet->GetItemState( FN_PARAM_DOCDISP((20000 + 1100)+20), false,
1344 reinterpret_cast<const SfxPoolItem**>(&pDocDisplayAttr) );
1345 if(pDocDisplayAttr)
1346 {
1347 m_xParaCB->set_active( pDocDisplayAttr->m_bParagraphEnd );
1348 m_xTabCB->set_active( pDocDisplayAttr->m_bTab );
1349 m_xSpacesCB->set_active( pDocDisplayAttr->m_bSpace );
1350 m_xHSpacesCB->set_active( pDocDisplayAttr->m_bNonbreakingSpace );
1351 m_xSHyphCB->set_active( pDocDisplayAttr->m_bSoftHyphen );
1352 m_xCharHiddenCB->set_active( pDocDisplayAttr->m_bCharHiddenText );
1353 m_xBookmarkCB->set_active(pDocDisplayAttr->m_bBookmarks);
1354 m_xBreakCB->set_active( pDocDisplayAttr->m_bManualBreak );
1355 }
1356}
1357
1358namespace {
1359
1360// TabPage for Redlining
1361struct CharAttr
1362{
1363 sal_uInt16 nItemId;
1364 sal_uInt16 nAttr;
1365};
1366
1367}
1368
1369// Edit corresponds to Paste-attributes
1370CharAttr const aRedlineAttr[] =
1371{
1372 { SID_ATTR_CHAR_CASEMAP( 10000 + 19 ), sal_uInt16(SvxCaseMap::NotMapped) },
1373 { SID_ATTR_CHAR_WEIGHT( 10000 + 9 ), WEIGHT_BOLD },
1374 { SID_ATTR_CHAR_POSTURE( 10000 + 8 ), ITALIC_NORMAL },
1375 { SID_ATTR_CHAR_UNDERLINE( 10000 + 14 ), LINESTYLE_SINGLE },
1376 { SID_ATTR_CHAR_UNDERLINE( 10000 + 14 ), LINESTYLE_DOUBLE },
1377 { SID_ATTR_CHAR_STRIKEOUT( 10000 + 13 ), STRIKEOUT_SINGLE },
1378 { SID_ATTR_CHAR_CASEMAP( 10000 + 19 ), sal_uInt16(SvxCaseMap::Uppercase) },
1379 { SID_ATTR_CHAR_CASEMAP( 10000 + 19 ), sal_uInt16(SvxCaseMap::Lowercase) },
1380 { SID_ATTR_CHAR_CASEMAP( 10000 + 19 ), sal_uInt16(SvxCaseMap::SmallCaps) },
1381 { SID_ATTR_CHAR_CASEMAP( 10000 + 19 ), sal_uInt16(SvxCaseMap::Capitalize) },
1382 { SID_ATTR_BRUSH( 10000 + 1 ), 0 }
1383};
1384// Items from aRedlineAttr relevant for InsertAttr: strikethrough is
1385// not used
1386static sal_uInt16 aInsertAttrMap[] = { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10 };
1387
1388// Items from aRedlineAttr relevant for DeleteAttr: underline and
1389// double underline is not used
1390static sal_uInt16 aDeletedAttrMap[] = { 0, 1, 2, 5, 6, 7, 8, 9, 10 };
1391
1392// Items from aRedlineAttr relevant for ChangeAttr: strikethrough is
1393// not used
1394static sal_uInt16 aChangedAttrMap[] = { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10 };
1395
1396// Preview of selection
1397SwMarkPreview::SwMarkPreview()
1398 : m_aTransCol(COL_TRANSPARENT)
1399 , m_aMarkCol(COL_LIGHTRED)
1400 , nMarkPos(0)
1401
1402{
1403 InitColors();
1404}
1405
1406SwMarkPreview::~SwMarkPreview()
1407{
1408}
1409
1410void SwMarkPreview::InitColors()
1411{
1412 // m_aTransCol and m_aMarkCol are _not_ changed because they are set from outside!
1413
1414 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
1415 m_aBgCol = rSettings.GetWindowColor();
1416
1417 bool bHC = rSettings.GetHighContrastMode();
1418 m_aLineCol = bHC? SwViewOption::GetFontColor() : COL_BLACK;
1419 m_aShadowCol = bHC? m_aBgCol : rSettings.GetShadowColor();
1420 m_aTextCol = bHC? SwViewOption::GetFontColor() : COL_GRAY;
1421 m_aPrintAreaCol = m_aTextCol;
1422}
1423
1424void SwMarkPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle &/*rRect*/)
1425{
1426 const Size aSz(GetOutputSizePixel());
1427
1428 // Page
1429 aPage.SetSize(Size(aSz.Width() - 3, aSz.Height() - 3));
1430
1431 const long nOutWPix = aPage.GetWidth();
1432 const long nOutHPix = aPage.GetHeight();
1433
1434 // PrintArea
1435 const long nLBorder = 8;
1436 const long nRBorder = 8;
1437 const long nTBorder = 4;
1438 const long nBBorder = 4;
1439
1440 aLeftPagePrtArea = tools::Rectangle(Point(nLBorder, nTBorder), Point((nOutWPix - 1) - nRBorder, (nOutHPix - 1) - nBBorder));
1441 const long nWidth = aLeftPagePrtArea.GetWidth();
1442 const long nCorr = (nWidth & 1) != 0 ? 0 : 1;
1443 aLeftPagePrtArea.SetSize(Size(nWidth / 2 - (nLBorder + nRBorder) / 2 + nCorr, aLeftPagePrtArea.GetHeight()));
1444
1445 aRightPagePrtArea = aLeftPagePrtArea;
1446 aRightPagePrtArea.Move(aLeftPagePrtArea.GetWidth() + nLBorder + nRBorder + 1, 0);
1447
1448 // draw shadow
1449 tools::Rectangle aShadow(aPage);
1450 aShadow += Point(3, 3);
1451 drawRect(rRenderContext, aShadow, m_aShadowCol, m_aTransCol);
1452
1453 // draw page
1454 drawRect(rRenderContext, aPage, m_aBgCol, m_aLineCol);
1455
1456 // draw separator
1457 tools::Rectangle aPageSeparator(aPage);
1458 aPageSeparator.SetSize(Size(2, aPageSeparator.GetHeight()));
1459 aPageSeparator.Move(aPage.GetWidth() / 2 - 1, 0);
1460 drawRect(rRenderContext, aPageSeparator, m_aLineCol, m_aTransCol);
1461
1462 PaintPage(rRenderContext, aLeftPagePrtArea);
1463 PaintPage(rRenderContext, aRightPagePrtArea);
1464
1465 tools::Rectangle aLeftMark(Point(aPage.Left() + 2, aLeftPagePrtArea.Top() + 4), Size(aLeftPagePrtArea.Left() - 4, 2));
1466 tools::Rectangle aRightMark(Point(aRightPagePrtArea.Right() + 2, aRightPagePrtArea.Bottom() - 6), Size(aLeftPagePrtArea.Left() - 4, 2));
1467
1468 switch (nMarkPos)
1469 {
1470 case 1: // left
1471 aRightMark.SetPos(Point(aRightPagePrtArea.Left() - 2 - aRightMark.GetWidth(), aRightMark.Top()));
1472 break;
1473
1474 case 2: // right
1475 aLeftMark.SetPos(Point(aLeftPagePrtArea.Right() + 2, aLeftMark.Top()));
1476 break;
1477
1478 case 3: // outside
1479 break;
1480
1481 case 4: // inside
1482 aLeftMark.SetPos(Point(aLeftPagePrtArea.Right() + 2, aLeftMark.Top()));
1483 aRightMark.SetPos(Point(aRightPagePrtArea.Left() - 2 - aRightMark.GetWidth(), aRightMark.Top()));
1484 break;
1485
1486 case 0: // none
1487 default:
1488 return;
1489 }
1490 drawRect(rRenderContext, aLeftMark, m_aMarkCol, m_aTransCol);
1491 drawRect(rRenderContext, aRightMark, m_aMarkCol, m_aTransCol);
1492}
1493
1494void SwMarkPreview::PaintPage(vcl::RenderContext& rRenderContext, const tools::Rectangle &rRect)
1495{
1496 // draw PrintArea
1497 drawRect(rRenderContext, rRect, m_aTransCol, m_aPrintAreaCol);
1498
1499 // draw Testparagraph
1500
1501 tools::Rectangle aTextLine = rRect;
1502 aTextLine.SetSize(Size(aTextLine.GetWidth(), 2));
1503 aTextLine.AdjustLeft(4 );
1504 aTextLine.AdjustRight( -4 );
1505 aTextLine.Move(0, 4);
1506
1507 const long nStep = aTextLine.GetHeight() + 2;
1508 const long nLines = rRect.GetHeight() / (aTextLine.GetHeight() + 2) - 1;
1509
1510 // simulate text
1511 for (long i = 0; i < nLines; ++i)
1512 {
1513 if (i == (nLines - 1))
1514 aTextLine.SetSize(Size(aTextLine.GetWidth() / 2, aTextLine.GetHeight()));
1515
1516 if (aPage.IsInside(aTextLine))
1517 drawRect(rRenderContext, aTextLine, m_aTextCol, m_aTransCol);
1518
1519 aTextLine.Move(0, nStep);
1520 }
1521 aTextLine.Move(0, -nStep);
1522}
1523
1524void SwMarkPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
1525{
1526 Size aInitialSize = getPreviewOptionsSize(pDrawingArea->get_ref_device());
1527 pDrawingArea->set_size_request(aInitialSize.Width(), aInitialSize.Height());
1528 weld::CustomWidgetController::SetDrawingArea(pDrawingArea);
1529 SetOutputSizePixel(aInitialSize);
1530}
1531
1532namespace
1533{
1534 void lcl_FillRedlineAttrListBox(
1535 weld::ComboBox& rLB, const AuthorCharAttr& rAttrToSelect,
1536 const sal_uInt16* pAttrMap, const size_t nAttrMapSize)
1537 {
1538 for (size_t i = 0; i != nAttrMapSize; ++i)
1539 {
1540 CharAttr const & rAttr(aRedlineAttr[pAttrMap[i]]);
1541 rLB.set_id(i, OUString::number(reinterpret_cast<sal_Int64>(&rAttr)));
1542 if (rAttr.nItemId == rAttrToSelect.m_nItemId &&
1543 rAttr.nAttr == rAttrToSelect.m_nAttr)
1544 rLB.set_active(i);
1545 }
1546 }
1547}
1548
1549SwRedlineOptionsTabPage::SwRedlineOptionsTabPage(weld::Container* pPage, weld::DialogController* pController,
1550 const SfxItemSet& rSet)
1551 : SfxTabPage(pPage, pController, "modules/swriter/ui/optredlinepage.ui", "OptRedLinePage", &rSet)
1552 , m_xInsertLB(m_xBuilder->weld_combo_box("insert"))
1553 , m_xInsertColorLB(new ColorListBox(m_xBuilder->weld_menu_button("insertcolor"), pController->getDialog()))
1554 , m_xInsertedPreviewWN(new SvxFontPrevWindow)
1555 , m_xInsertedPreview(new weld::CustomWeld(*m_xBuilder, "insertedpreview", *m_xInsertedPreviewWN))
1556 , m_xDeletedLB(m_xBuilder->weld_combo_box("deleted"))
1557 , m_xDeletedColorLB(new ColorListBox(m_xBuilder->weld_menu_button("deletedcolor"), pController->getDialog()))
1558 , m_xDeletedPreviewWN(new SvxFontPrevWindow)
1559 , m_xDeletedPreview(new weld::CustomWeld(*m_xBuilder, "deletedpreview", *m_xDeletedPreviewWN))
1560 , m_xChangedLB(m_xBuilder->weld_combo_box("changed"))
1561 , m_xChangedColorLB(new ColorListBox(m_xBuilder->weld_menu_button("changedcolor"), pController->getDialog()))
1562 , m_xChangedPreviewWN(new SvxFontPrevWindow)
1563 , m_xChangedPreview(new weld::CustomWeld(*m_xBuilder, "changedpreview", *m_xChangedPreviewWN))
1564 , m_xMarkPosLB(m_xBuilder->weld_combo_box("markpos"))
1565 , m_xMarkColorLB(new ColorListBox(m_xBuilder->weld_menu_button("markcolor"), pController->getDialog()))
1566 , m_xMarkPreviewWN(new SwMarkPreview)
1567 , m_xMarkPreview(new weld::CustomWeld(*m_xBuilder, "markpreview", *m_xMarkPreviewWN))
1568{
1569 Size aPreviewSize(getPreviewOptionsSize(m_xMarkPreviewWN->GetDrawingArea()->get_ref_device()));
1570
1571 m_xInsertColorLB->SetSlotId(SID_AUTHOR_COLOR( 10000 + 1168 ), true);
1572 m_xDeletedColorLB->SetSlotId(SID_AUTHOR_COLOR( 10000 + 1168 ), true);
1573 m_xChangedColorLB->SetSlotId(SID_AUTHOR_COLOR( 10000 + 1168 ), true);
1574
1575 m_xInsertedPreviewWN->set_size_request(aPreviewSize.Width(), aPreviewSize.Height());
1576 m_xDeletedPreviewWN->set_size_request(aPreviewSize.Width(), aPreviewSize.Height());
1577 m_xChangedPreviewWN->set_size_request(aPreviewSize.Width(), aPreviewSize.Height());
1578 m_xMarkPreviewWN->set_size_request(aPreviewSize.Width(), aPreviewSize.Height());
1579
1580 for (sal_Int32 i = 0, nEntryCount = m_xInsertLB->get_count(); i < nEntryCount; ++i)
1581 {
1582 const OUString sEntry(m_xInsertLB->get_text(i));
1583 m_xDeletedLB->append_text(sEntry);
1584 m_xChangedLB->append_text(sEntry);
1585 };
1586
1587 // remove strikethrough from insert and change and underline + double
1588 // underline from delete
1589 m_xInsertLB->remove(5);
1590 m_xChangedLB->remove(5);
1591 m_xDeletedLB->remove(4);
1592 m_xDeletedLB->remove(3);
1593
1594 Link<weld::ComboBox&,void> aLk = LINK(this, SwRedlineOptionsTabPage, AttribHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwRedlineOptionsTabPage
*>(this), &SwRedlineOptionsTabPage::LinkStubAttribHdl
)
;
1595 m_xInsertLB->connect_changed( aLk );
1596 m_xDeletedLB->connect_changed( aLk );
1597 m_xChangedLB->connect_changed( aLk );
1598
1599 Link<ColorListBox&,void> aLk2 = LINK(this, SwRedlineOptionsTabPage, ColorHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwRedlineOptionsTabPage
*>(this), &SwRedlineOptionsTabPage::LinkStubColorHdl)
;
1600 m_xInsertColorLB->SetSelectHdl( aLk2 );
1601 m_xDeletedColorLB->SetSelectHdl( aLk2 );
1602 m_xChangedColorLB->SetSelectHdl( aLk2 );
1603
1604 m_xMarkPosLB->connect_changed(LINK(this, SwRedlineOptionsTabPage, ChangedMaskPrevHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwRedlineOptionsTabPage
*>(this), &SwRedlineOptionsTabPage::LinkStubChangedMaskPrevHdl
)
);
1605 m_xMarkColorLB->SetSelectHdl(LINK(this, SwRedlineOptionsTabPage, ChangedMaskColorPrevHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwRedlineOptionsTabPage
*>(this), &SwRedlineOptionsTabPage::LinkStubChangedMaskColorPrevHdl
)
);
1606}
1607
1608SwRedlineOptionsTabPage::~SwRedlineOptionsTabPage()
1609{
1610 m_xInsertColorLB.reset();
1611 m_xInsertedPreview.reset();
1612 m_xInsertedPreviewWN.reset();
1613 m_xDeletedColorLB.reset();
1614 m_xDeletedPreview.reset();
1615 m_xDeletedPreviewWN.reset();
1616 m_xChangedColorLB.reset();
1617 m_xChangedPreview.reset();
1618 m_xChangedPreviewWN.reset();
1619 m_xMarkColorLB.reset();
1620 m_xMarkPreview.reset();
1621 m_xMarkPreviewWN.reset();
1622}
1623
1624std::unique_ptr<SfxTabPage> SwRedlineOptionsTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
1625{
1626 return std::make_unique<SwRedlineOptionsTabPage>(pPage, pController, *rSet);
1627}
1628
1629bool SwRedlineOptionsTabPage::FillItemSet( SfxItemSet* )
1630{
1631 CharAttr *pAttr;
1632 SwModuleOptions *pOpt = SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule
::Writer)))
->GetModuleConfig();
1633
1634 AuthorCharAttr aInsertedAttr;
1635 AuthorCharAttr aDeletedAttr;
1636 AuthorCharAttr aChangedAttr;
1637
1638 AuthorCharAttr aOldInsertAttr(pOpt->GetInsertAuthorAttr());
1639 AuthorCharAttr aOldDeletedAttr(pOpt->GetDeletedAuthorAttr());
1640 AuthorCharAttr aOldChangedAttr(pOpt->GetFormatAuthorAttr());
1641
1642 Color nOldMarkColor = pOpt->GetMarkAlignColor();
1643 sal_uInt16 nOldMarkMode = pOpt->GetMarkAlignMode();
1644
1645 sal_Int32 nPos = m_xInsertLB->get_active();
1646 if (nPos != -1)
1647 {
1648 pAttr = reinterpret_cast<CharAttr*>(m_xInsertLB->get_id(nPos).toInt64());
1649 aInsertedAttr.m_nItemId = pAttr->nItemId;
1650 aInsertedAttr.m_nAttr = pAttr->nAttr;
1651 aInsertedAttr.m_nColor = m_xInsertColorLB->GetSelectEntryColor();
1652 pOpt->SetInsertAuthorAttr(aInsertedAttr);
1653 }
1654
1655 nPos = m_xDeletedLB->get_active();
1656 if (nPos != -1)
1657 {
1658 pAttr = reinterpret_cast<CharAttr*>(m_xDeletedLB->get_id(nPos).toInt64());
1659 aDeletedAttr.m_nItemId = pAttr->nItemId;
1660 aDeletedAttr.m_nAttr = pAttr->nAttr;
1661 aDeletedAttr.m_nColor = m_xDeletedColorLB->GetSelectEntryColor();
1662 pOpt->SetDeletedAuthorAttr(aDeletedAttr);
1663 }
1664
1665 nPos = m_xChangedLB->get_active();
1666 if (nPos != -1)
1667 {
1668 pAttr = reinterpret_cast<CharAttr*>(m_xChangedLB->get_id(nPos).toInt64());
1669 aChangedAttr.m_nItemId = pAttr->nItemId;
1670 aChangedAttr.m_nAttr = pAttr->nAttr;
1671 aChangedAttr.m_nColor = m_xChangedColorLB->GetSelectEntryColor();
1672 pOpt->SetFormatAuthorAttr(aChangedAttr);
1673 }
1674
1675 nPos = 0;
1676 switch (m_xMarkPosLB->get_active())
1677 {
1678 case 0: nPos = text::HoriOrientation::NONE; break;
1679 case 1: nPos = text::HoriOrientation::LEFT; break;
1680 case 2: nPos = text::HoriOrientation::RIGHT; break;
1681 case 3: nPos = text::HoriOrientation::OUTSIDE; break;
1682 case 4: nPos = text::HoriOrientation::INSIDE; break;
1683 }
1684 pOpt->SetMarkAlignMode(nPos);
1685 pOpt->SetMarkAlignColor(m_xMarkColorLB->GetSelectEntryColor());
1686
1687 if (!(aInsertedAttr == aOldInsertAttr) ||
1688 !(aDeletedAttr == aOldDeletedAttr) ||
1689 !(aChangedAttr == aOldChangedAttr) ||
1690 nOldMarkColor != pOpt->GetMarkAlignColor() ||
1691 nOldMarkMode != pOpt->GetMarkAlignMode() )
1692 {
1693 // update all documents
1694 SwDocShell* pDocShell = static_cast<SwDocShell*>(SfxObjectShell::GetFirst(checkSfxObjectShell<SwDocShell>));
1695
1696 while( pDocShell )
1697 {
1698 pDocShell->GetWrtShell()->UpdateRedlineAttr();
1699 pDocShell = static_cast<SwDocShell*>(SfxObjectShell::GetNext(*pDocShell, checkSfxObjectShell<SwDocShell>));
1700 }
1701 }
1702
1703 return false;
1704}
1705
1706void SwRedlineOptionsTabPage::Reset( const SfxItemSet* )
1707{
1708 const SwModuleOptions *pOpt = SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule
::Writer)))
->GetModuleConfig();
1709
1710 const AuthorCharAttr &rInsertAttr = pOpt->GetInsertAuthorAttr();
1711 const AuthorCharAttr &rDeletedAttr = pOpt->GetDeletedAuthorAttr();
1712 const AuthorCharAttr &rChangedAttr = pOpt->GetFormatAuthorAttr();
1713
1714 // initialise preview
1715 InitFontStyle(*m_xInsertedPreviewWN, SwResId(STR_OPT_PREVIEW_INSERTEDreinterpret_cast<char const *>("optredlinepage|insertedpreview"
"\004" u8"Insert")
));
1716 InitFontStyle(*m_xDeletedPreviewWN, SwResId(STR_OPT_PREVIEW_DELETEDreinterpret_cast<char const *>("optredlinepage|deletedpreview"
"\004" u8"Delete")
));
1717 InitFontStyle(*m_xChangedPreviewWN, SwResId(STR_OPT_PREVIEW_CHANGEDreinterpret_cast<char const *>("optredlinepage|changedpreview"
"\004" u8"Attributes")
));
1718
1719 Color nColor = rInsertAttr.m_nColor;
1720 m_xInsertColorLB->SelectEntry(nColor);
1721
1722 nColor = rDeletedAttr.m_nColor;
1723 m_xDeletedColorLB->SelectEntry(nColor);
1724
1725 nColor = rChangedAttr.m_nColor;
1726 m_xChangedColorLB->SelectEntry(nColor);
1727
1728 m_xMarkColorLB->SelectEntry(pOpt->GetMarkAlignColor());
1729
1730 m_xInsertLB->set_active(0);
1731 m_xDeletedLB->set_active(0);
1732 m_xChangedLB->set_active(0);
1733
1734 lcl_FillRedlineAttrListBox(*m_xInsertLB, rInsertAttr, aInsertAttrMap, SAL_N_ELEMENTS(aInsertAttrMap)(sizeof(sal_n_array_size(aInsertAttrMap))));
1735 lcl_FillRedlineAttrListBox(*m_xDeletedLB, rDeletedAttr, aDeletedAttrMap, SAL_N_ELEMENTS(aDeletedAttrMap)(sizeof(sal_n_array_size(aDeletedAttrMap))));
1736 lcl_FillRedlineAttrListBox(*m_xChangedLB, rChangedAttr, aChangedAttrMap, SAL_N_ELEMENTS(aChangedAttrMap)(sizeof(sal_n_array_size(aChangedAttrMap))));
1737
1738 sal_Int32 nPos = 0;
1739 switch (pOpt->GetMarkAlignMode())
1740 {
1741 case text::HoriOrientation::NONE: nPos = 0; break;
1742 case text::HoriOrientation::LEFT: nPos = 1; break;
1743 case text::HoriOrientation::RIGHT: nPos = 2; break;
1744 case text::HoriOrientation::OUTSIDE: nPos = 3; break;
1745 case text::HoriOrientation::INSIDE: nPos = 4; break;
1746 }
1747 m_xMarkPosLB->set_active(nPos);
1748
1749 // show settings in preview
1750 AttribHdl(*m_xInsertLB);
1751 ColorHdl(*m_xInsertColorLB);
1752 AttribHdl(*m_xDeletedLB);
1753 ColorHdl(*m_xInsertColorLB);
1754 AttribHdl(*m_xChangedLB);
1755 ColorHdl(*m_xChangedColorLB);
1756
1757 ChangedMaskPrev();
1758}
1759
1760IMPL_LINK( SwRedlineOptionsTabPage, AttribHdl, weld::ComboBox&, rLB, void )void SwRedlineOptionsTabPage::LinkStubAttribHdl(void * instance
, weld::ComboBox& data) { return static_cast<SwRedlineOptionsTabPage
*>(instance)->AttribHdl(data); } void SwRedlineOptionsTabPage
::AttribHdl(weld::ComboBox& rLB)
1761{
1762 SvxFontPrevWindow *pPrev = nullptr;
1763 ColorListBox *pColorLB;
1764
1765 if (&rLB == m_xInsertLB.get())
1766 {
1767 pColorLB = m_xInsertColorLB.get();
1768 pPrev = m_xInsertedPreviewWN.get();
1769 }
1770 else if (&rLB == m_xDeletedLB.get())
1771 {
1772 pColorLB = m_xDeletedColorLB.get();
1773 pPrev = m_xDeletedPreviewWN.get();
1774 }
1775 else
1776 {
1777 pColorLB = m_xChangedColorLB.get();
1778 pPrev = m_xChangedPreviewWN.get();
1779 }
1780
1781 SvxFont& rFont = pPrev->GetFont();
1782 SvxFont& rCJKFont = pPrev->GetCJKFont();
1783
1784 rFont.SetWeight(WEIGHT_NORMAL);
1785 rCJKFont.SetWeight(WEIGHT_NORMAL);
1786 rFont.SetItalic(ITALIC_NONE);
1787 rCJKFont.SetItalic(ITALIC_NONE);
1788 rFont.SetUnderline(LINESTYLE_NONE);
1789 rCJKFont.SetUnderline(LINESTYLE_NONE);
1790 rFont.SetStrikeout(STRIKEOUT_NONE);
1791 rCJKFont.SetStrikeout(STRIKEOUT_NONE);
1792 rFont.SetCaseMap(SvxCaseMap::NotMapped);
1793 rCJKFont.SetCaseMap(SvxCaseMap::NotMapped);
1794
1795 Color aColor = pColorLB->GetSelectEntryColor();
1796
1797 if (aColor == COL_NONE_COLOR::Color(0x80, 0xFF, 0xFF, 0xFF))
1798 {
1799 rFont.SetColor( COL_BLACK );
1800 rCJKFont.SetColor( COL_BLACK );
1801 }
1802 else if (aColor == COL_TRANSPARENT)
1803 {
1804 rFont.SetColor( COL_RED );
1805 rCJKFont.SetColor( COL_RED );
1806 }
1807 else
1808 {
1809 rFont.SetColor(aColor);
1810 rCJKFont.SetColor(aColor);
1811 }
1812
1813 sal_Int32 nPos = rLB.get_active();
1814 if( nPos == -1)
1815 nPos = 0;
1816
1817 CharAttr* pAttr = reinterpret_cast<CharAttr*>(rLB.get_id(nPos).toInt64());
1818 //switch off preview background color
1819 pPrev->ResetColor();
1820 switch (pAttr->nItemId)
1821 {
1822 case SID_ATTR_CHAR_WEIGHT( 10000 + 9 ):
1823 rFont.SetWeight( static_cast<FontWeight>(pAttr->nAttr) );
1824 rCJKFont.SetWeight( static_cast<FontWeight>(pAttr->nAttr) );
1825 break;
1826
1827 case SID_ATTR_CHAR_POSTURE( 10000 + 8 ):
1828 rFont.SetItalic( static_cast<FontItalic>(pAttr->nAttr) );
1829 rCJKFont.SetItalic( static_cast<FontItalic>(pAttr->nAttr) );
1830 break;
1831
1832 case SID_ATTR_CHAR_UNDERLINE( 10000 + 14 ):
1833 rFont.SetUnderline( static_cast<FontLineStyle>(pAttr->nAttr) );
1834 rCJKFont.SetUnderline( static_cast<FontLineStyle>(pAttr->nAttr) );
1835 break;
1836
1837 case SID_ATTR_CHAR_STRIKEOUT( 10000 + 13 ):
1838 rFont.SetStrikeout( static_cast<FontStrikeout>(pAttr->nAttr) );
1839 rCJKFont.SetStrikeout( static_cast<FontStrikeout>(pAttr->nAttr) );
1840 break;
1841
1842 case SID_ATTR_CHAR_CASEMAP( 10000 + 19 ):
1843 rFont.SetCaseMap( static_cast<SvxCaseMap>(pAttr->nAttr) );
1844 rCJKFont.SetCaseMap( static_cast<SvxCaseMap>(pAttr->nAttr) );
1845 break;
1846
1847 case SID_ATTR_BRUSH( 10000 + 1 ):
1848 {
1849 Color aBgColor = pColorLB->GetSelectEntryColor();
1850 if (aBgColor != COL_NONE_COLOR::Color(0x80, 0xFF, 0xFF, 0xFF))
1851 pPrev->SetColor(aBgColor);
1852 else
1853 pPrev->SetColor(COL_LIGHTGRAY);
1854 rFont.SetColor( COL_BLACK );
1855 rCJKFont.SetColor( COL_BLACK );
1856 }
1857 break;
1858 }
1859
1860 pPrev->Invalidate();
1861}
1862
1863IMPL_LINK(SwRedlineOptionsTabPage, ColorHdl, ColorListBox&, rListBox, void)void SwRedlineOptionsTabPage::LinkStubColorHdl(void * instance
, ColorListBox& data) { return static_cast<SwRedlineOptionsTabPage
*>(instance)->ColorHdl(data); } void SwRedlineOptionsTabPage
::ColorHdl(ColorListBox& rListBox)
1864{
1865 ColorListBox* pColorLB = &rListBox;
1866 SvxFontPrevWindow *pPrev = nullptr;
1867 weld::ComboBox* pLB;
1868
1869 if (pColorLB == m_xInsertColorLB.get())
1870 {
1871 pLB = m_xInsertLB.get();
1872 pPrev = m_xInsertedPreviewWN.get();
1873 }
1874 else if (pColorLB == m_xDeletedColorLB.get())
1875 {
1876 pLB = m_xDeletedLB.get();
1877 pPrev = m_xDeletedPreviewWN.get();
1878 }
1879 else
1880 {
1881 pLB = m_xChangedLB.get();
1882 pPrev = m_xChangedPreviewWN.get();
1883 }
1884
1885 SvxFont& rFont = pPrev->GetFont();
1886 SvxFont& rCJKFont = pPrev->GetCJKFont();
1887 sal_Int32 nPos = pLB->get_active();
1888 if( nPos == -1)
1889 nPos = 0;
1890
1891 CharAttr* pAttr = reinterpret_cast<CharAttr*>(pLB->get_id(nPos).toInt64());
1892
1893 if( pAttr->nItemId == SID_ATTR_BRUSH( 10000 + 1 ) )
1894 {
1895 rFont.SetColor( COL_BLACK );
1896 rCJKFont.SetColor( COL_BLACK );
1897
1898 Color aBgColor = pColorLB->GetSelectEntryColor();
1899 if (aBgColor != COL_NONE_COLOR::Color(0x80, 0xFF, 0xFF, 0xFF))
1900 pPrev->SetColor(aBgColor);
1901 else
1902 pPrev->SetColor(COL_LIGHTGRAY);
1903 }
1904 else
1905 {
1906 Color aColor = pColorLB->GetSelectEntryColor();
1907
1908 if (aColor == COL_NONE_COLOR::Color(0x80, 0xFF, 0xFF, 0xFF))
1909 {
1910 rFont.SetColor( COL_BLACK );
1911 rCJKFont.SetColor( COL_BLACK );
1912 }
1913 else if (aColor == COL_TRANSPARENT)
1914 {
1915 rFont.SetColor( COL_RED );
1916 rCJKFont.SetColor( COL_RED );
1917 }
1918 else
1919 {
1920 rFont.SetColor(aColor);
1921 rCJKFont.SetColor(aColor);
1922 }
1923 }
1924
1925 pPrev->Invalidate();
1926}
1927
1928void SwRedlineOptionsTabPage::ChangedMaskPrev()
1929{
1930 m_xMarkPreviewWN->SetMarkPos(m_xMarkPosLB->get_active());
1931 m_xMarkPreviewWN->SetColor(m_xMarkColorLB->GetSelectEntryColor());
1932
1933 m_xMarkPreviewWN->Invalidate();
1934}
1935
1936IMPL_LINK_NOARG(SwRedlineOptionsTabPage, ChangedMaskPrevHdl, weld::ComboBox&, void)void SwRedlineOptionsTabPage::LinkStubChangedMaskPrevHdl(void
* instance, weld::ComboBox& data) { return static_cast<
SwRedlineOptionsTabPage *>(instance)->ChangedMaskPrevHdl
(data); } void SwRedlineOptionsTabPage::ChangedMaskPrevHdl(__attribute__
((unused)) weld::ComboBox&)
1937{
1938 ChangedMaskPrev();
1939}
1940
1941IMPL_LINK_NOARG(SwRedlineOptionsTabPage, ChangedMaskColorPrevHdl, ColorListBox&, void)void SwRedlineOptionsTabPage::LinkStubChangedMaskColorPrevHdl
(void * instance, ColorListBox& data) { return static_cast
<SwRedlineOptionsTabPage *>(instance)->ChangedMaskColorPrevHdl
(data); } void SwRedlineOptionsTabPage::ChangedMaskColorPrevHdl
(__attribute__ ((unused)) ColorListBox&)
1942{
1943 ChangedMaskPrev();
1944}
1945
1946void SwRedlineOptionsTabPage::InitFontStyle(SvxFontPrevWindow& rExampleWin, const OUString& rText)
1947{
1948 const AllSettings& rAllSettings = Application::GetSettings();
1949 LanguageType eLangType = rAllSettings.GetUILanguageTag().getLanguageType();
1950 Color aBackCol( rAllSettings.GetStyleSettings().GetWindowColor() );
1951 SvxFont& rFont = rExampleWin.GetFont();
1952 SvxFont& rCJKFont = rExampleWin.GetCJKFont();
1953 SvxFont& rCTLFont = rExampleWin.GetCTLFont();
1954
1955 OutputDevice& rDevice = rExampleWin.GetDrawingArea()->get_ref_device();
1956
1957 vcl::Font aFont( OutputDevice::GetDefaultFont( DefaultFontType::SERIF, eLangType,
1958 GetDefaultFontFlags::OnlyOne, &rDevice ) );
1959 vcl::Font aCJKFont( OutputDevice::GetDefaultFont( DefaultFontType::CJK_TEXT, eLangType,
1960 GetDefaultFontFlags::OnlyOne, &rDevice ) );
1961 vcl::Font aCTLFont( OutputDevice::GetDefaultFont( DefaultFontType::CTL_TEXT, eLangType,
1962 GetDefaultFontFlags::OnlyOne, &rDevice ) );
1963 const Size aDefSize( 0, 12 );
1964 aFont.SetFontSize( aDefSize );
1965 aCJKFont.SetFontSize( aDefSize );
1966 aCTLFont.SetFontSize( aDefSize );
1967
1968 aFont.SetFillColor( aBackCol );
1969 aCJKFont.SetFillColor( aBackCol );
1970 aCTLFont.SetFillColor( aBackCol );
1971
1972 aFont.SetWeight( WEIGHT_NORMAL );
1973 aCJKFont.SetWeight( WEIGHT_NORMAL );
1974 aCTLFont.SetWeight( WEIGHT_NORMAL );
1975
1976 rFont = aFont;
1977 rCJKFont = aCJKFont;
1978 rCTLFont = aCTLFont;
1979
1980 const Size aNewSize( 0, rExampleWin.GetOutputSizePixel().Height() * 2 / 3 );
1981 rFont.SetFontSize( aNewSize );
1982 rCJKFont.SetFontSize( aNewSize );
1983
1984 rExampleWin.SetFont( rFont, rCJKFont,rCTLFont );
1985 rExampleWin.SetPreviewText(rText);
1986
1987 rExampleWin.SetBackColor(aBackCol);
1988}
1989
1990SwCompareOptionsTabPage::SwCompareOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
1991 : SfxTabPage(pPage, pController, "modules/swriter/ui/optcomparison.ui", "OptComparison", &rSet)
1992 , m_xAutoRB(m_xBuilder->weld_radio_button("auto"))
1993 , m_xWordRB(m_xBuilder->weld_radio_button("byword"))
1994 , m_xCharRB(m_xBuilder->weld_radio_button("bycharacter"))
1995 , m_xRsidCB(m_xBuilder->weld_check_button("useRSID"))
1996 , m_xIgnoreCB(m_xBuilder->weld_check_button("ignore"))
1997 , m_xLenNF(m_xBuilder->weld_spin_button("ignorelen"))
1998 , m_xStoreRsidCB(m_xBuilder->weld_check_button("storeRSID"))
1999{
2000 Link<weld::Button&,void> aLnk( LINK( this, SwCompareOptionsTabPage, ComparisonHdl )::tools::detail::makeLink( ::tools::detail::castTo<SwCompareOptionsTabPage
*>(this), &SwCompareOptionsTabPage::LinkStubComparisonHdl
)
);
2001 m_xAutoRB->connect_clicked( aLnk );
2002 m_xWordRB->connect_clicked( aLnk );
2003 m_xCharRB->connect_clicked( aLnk );
2004
2005 m_xIgnoreCB->connect_clicked( LINK( this, SwCompareOptionsTabPage, IgnoreHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwCompareOptionsTabPage
*>(this), &SwCompareOptionsTabPage::LinkStubIgnoreHdl
)
);
2006}
2007
2008SwCompareOptionsTabPage::~SwCompareOptionsTabPage()
2009{
2010}
2011
2012std::unique_ptr<SfxTabPage> SwCompareOptionsTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
2013{
2014 return std::make_unique<SwCompareOptionsTabPage>(pPage, pController, *rAttrSet);
2015}
2016
2017bool SwCompareOptionsTabPage::FillItemSet( SfxItemSet* )
2018{
2019 bool bRet = false;
2020 SwModuleOptions *pOpt = SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule
::Writer)))
->GetModuleConfig();
2021
2022 if( m_xAutoRB->get_state_changed_from_saved() ||
2023 m_xWordRB->get_state_changed_from_saved() ||
2024 m_xCharRB->get_state_changed_from_saved() )
2025 {
2026 SwCompareMode eCmpMode = SwCompareMode::Auto;
2027
2028 if ( m_xAutoRB->get_active() ) eCmpMode = SwCompareMode::Auto;
2029 if ( m_xWordRB->get_active() ) eCmpMode = SwCompareMode::ByWord;
2030 if ( m_xCharRB->get_active() ) eCmpMode = SwCompareMode::ByChar;
2031
2032 pOpt->SetCompareMode( eCmpMode );
2033 bRet = true;
2034 }
2035
2036 if( m_xRsidCB->get_state_changed_from_saved() )
2037 {
2038 pOpt->SetUseRsid( m_xRsidCB->get_active() );
2039 bRet = true;
2040 }
2041
2042 if( m_xIgnoreCB->get_state_changed_from_saved() )
2043 {
2044 pOpt->SetIgnorePieces( m_xIgnoreCB->get_active() );
2045 bRet = true;
2046 }
2047
2048 if( m_xLenNF->get_value_changed_from_saved() )
2049 {
2050 pOpt->SetPieceLen( m_xLenNF->get_value() );
2051 bRet = true;
2052 }
2053
2054 if (m_xStoreRsidCB->get_state_changed_from_saved())
2055 {
2056 pOpt->SetStoreRsid(m_xStoreRsidCB->get_active());
2057 bRet = true;
2058 }
2059
2060 return bRet;
2061}
2062
2063void SwCompareOptionsTabPage::Reset( const SfxItemSet* )
2064{
2065 SwModuleOptions *pOpt = SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule
::Writer)))
->GetModuleConfig();
2066
2067 SwCompareMode eCmpMode = pOpt->GetCompareMode();
2068 if( eCmpMode == SwCompareMode::Auto )
2069 {
2070 m_xAutoRB->set_active(true);
2071 m_xRsidCB->set_sensitive(false);
2072 m_xIgnoreCB->set_sensitive(false);
2073 m_xLenNF->set_sensitive(false);
2074 }
2075 else if( eCmpMode == SwCompareMode::ByWord )
2076 {
2077 m_xWordRB->set_active(true);
2078 m_xRsidCB->set_sensitive(true);
2079 m_xIgnoreCB->set_sensitive(true);
2080 m_xLenNF->set_sensitive(true);
2081 }
2082 else if( eCmpMode == SwCompareMode::ByChar)
2083 {
2084 m_xCharRB->set_active(true);
2085 m_xRsidCB->set_sensitive(true);
2086 m_xIgnoreCB->set_sensitive(true);
2087 m_xLenNF->set_sensitive(true);
2088 }
2089 m_xAutoRB->save_state();
2090 m_xWordRB->save_state();
2091 m_xCharRB->save_state();
2092
2093 m_xRsidCB->set_active( pOpt->IsUseRsid() );
2094 m_xRsidCB->save_state();
2095
2096 m_xIgnoreCB->set_active( pOpt->IsIgnorePieces() );
2097 m_xIgnoreCB->save_state();
2098
2099 m_xLenNF->set_sensitive( m_xIgnoreCB->get_active() && eCmpMode != SwCompareMode::Auto );
2100
2101 m_xLenNF->set_value( pOpt->GetPieceLen() );
2102 m_xLenNF->save_value();
2103
2104 m_xStoreRsidCB->set_active(pOpt->IsStoreRsid());
2105 m_xStoreRsidCB->save_state();
2106}
2107
2108IMPL_LINK_NOARG(SwCompareOptionsTabPage, ComparisonHdl, weld::Button&, void)void SwCompareOptionsTabPage::LinkStubComparisonHdl(void * instance
, weld::Button& data) { return static_cast<SwCompareOptionsTabPage
*>(instance)->ComparisonHdl(data); } void SwCompareOptionsTabPage
::ComparisonHdl(__attribute__ ((unused)) weld::Button&)
2109{
2110 bool bChecked = !m_xAutoRB->get_active();
2111 m_xRsidCB->set_sensitive( bChecked );
2112 m_xIgnoreCB->set_sensitive( bChecked );
2113 m_xLenNF->set_sensitive( bChecked && m_xIgnoreCB->get_active() );
2114}
2115
2116IMPL_LINK_NOARG(SwCompareOptionsTabPage, IgnoreHdl, weld::Button&, void)void SwCompareOptionsTabPage::LinkStubIgnoreHdl(void * instance
, weld::Button& data) { return static_cast<SwCompareOptionsTabPage
*>(instance)->IgnoreHdl(data); } void SwCompareOptionsTabPage
::IgnoreHdl(__attribute__ ((unused)) weld::Button&)
2117{
2118 m_xLenNF->set_sensitive(m_xIgnoreCB->get_active());
2119}
2120
2121#ifdef DBG_UTIL
2122
2123SwTestTabPage::SwTestTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet)
2124 : SfxTabPage(pPage, pController, "modules/swriter/ui/opttestpage.ui", "OptTestPage", &rCoreSet)
2125 , bAttrModified( false )
2126 , m_xTest1CBox(m_xBuilder->weld_check_button("unused"))
2127 , m_xTest2CBox(m_xBuilder->weld_check_button("dynamic"))
2128 , m_xTest3CBox(m_xBuilder->weld_check_button("nocalm"))
2129 , m_xTest4CBox(m_xBuilder->weld_check_button("wysiwygdbg"))
2130 , m_xTest5CBox(m_xBuilder->weld_check_button("noidle"))
2131 , m_xTest6CBox(m_xBuilder->weld_check_button("noscreenadj"))
2132 , m_xTest7CBox(m_xBuilder->weld_check_button("winformat"))
2133 , m_xTest8CBox(m_xBuilder->weld_check_button("noscroll"))
2134 , m_xTest9CBox(m_xBuilder->weld_check_button("DrawingLayerNotLoading"))
2135 , m_xTest10CBox(m_xBuilder->weld_check_button("AutoFormatByInput"))
2136{
2137 Init();
2138}
2139
2140SwTestTabPage::~SwTestTabPage()
2141{
2142}
2143
2144std::unique_ptr<SfxTabPage> SwTestTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
2145 const SfxItemSet* rAttrSet )
2146{
2147 return std::make_unique<SwTestTabPage>(pPage, pController, *rAttrSet);
2148}
2149
2150bool SwTestTabPage::FillItemSet( SfxItemSet* rCoreSet )
2151{
2152
2153 if ( bAttrModified )
2154 {
2155 SwTestItem aTestItem;
2156 aTestItem.m_bTest1=m_xTest1CBox->get_active();
2157 aTestItem.m_bTest2=m_xTest2CBox->get_active();
2158 aTestItem.m_bTest3=m_xTest3CBox->get_active();
2159 aTestItem.m_bTest4=m_xTest4CBox->get_active();
2160 aTestItem.m_bTest5=m_xTest5CBox->get_active();
2161 aTestItem.m_bTest6=m_xTest6CBox->get_active();
2162 aTestItem.m_bTest7=m_xTest7CBox->get_active();
2163 aTestItem.m_bTest8=m_xTest8CBox->get_active();
2164 aTestItem.m_bTest9=m_xTest9CBox->get_active();
2165 aTestItem.m_bTest10=m_xTest10CBox->get_active();
2166 rCoreSet->Put(aTestItem);
2167 }
2168 return bAttrModified;
2169}
2170
2171void SwTestTabPage::Reset( const SfxItemSet* )
2172{
2173 const SfxItemSet& rSet = GetItemSet();
2174 const SwTestItem* pTestAttr = nullptr;
2175
2176 if( SfxItemState::SET != rSet.GetItemState( FN_PARAM_SWTEST((20000 + 1100)+22) , false,
2177 reinterpret_cast<const SfxPoolItem**>(&pTestAttr) ))
2178 return;
2179
2180 m_xTest1CBox->set_active(pTestAttr->m_bTest1);
2181 m_xTest2CBox->set_active(pTestAttr->m_bTest2);
2182 m_xTest3CBox->set_active(pTestAttr->m_bTest3);
2183 m_xTest4CBox->set_active(pTestAttr->m_bTest4);
2184 m_xTest5CBox->set_active(pTestAttr->m_bTest5);
2185 m_xTest6CBox->set_active(pTestAttr->m_bTest6);
2186 m_xTest7CBox->set_active(pTestAttr->m_bTest7);
2187 m_xTest8CBox->set_active(pTestAttr->m_bTest8);
2188 m_xTest9CBox->set_active(pTestAttr->m_bTest9);
2189 m_xTest10CBox->set_active(pTestAttr->m_bTest10);
2190}
2191
2192void SwTestTabPage::Init()
2193{
2194 // handler
2195 Link<weld::Button&,void> aLk = LINK( this, SwTestTabPage, AutoClickHdl )::tools::detail::makeLink( ::tools::detail::castTo<SwTestTabPage
*>(this), &SwTestTabPage::LinkStubAutoClickHdl)
;
2196 m_xTest1CBox->connect_clicked( aLk );
2197 m_xTest2CBox->connect_clicked( aLk );
2198 m_xTest3CBox->connect_clicked( aLk );
2199 m_xTest4CBox->connect_clicked( aLk );
2200 m_xTest5CBox->connect_clicked( aLk );
2201 m_xTest6CBox->connect_clicked( aLk );
2202 m_xTest7CBox->connect_clicked( aLk );
2203 m_xTest8CBox->connect_clicked( aLk );
2204 m_xTest9CBox->connect_clicked( aLk );
2205 m_xTest10CBox->connect_clicked( aLk );
2206}
2207
2208IMPL_LINK_NOARG(SwTestTabPage, AutoClickHdl, weld::Button&, void)void SwTestTabPage::LinkStubAutoClickHdl(void * instance, weld
::Button& data) { return static_cast<SwTestTabPage *>
(instance)->AutoClickHdl(data); } void SwTestTabPage::AutoClickHdl
(__attribute__ ((unused)) weld::Button&)
2209{
2210 bAttrModified = true;
2211}
2212
2213#endif
2214
2215/* 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<SfxPrinter>'
7
Returning from copy constructor for 'Reference<SfxPrinter>'
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