Bug Summary

File:home/maarten/src/libreoffice/core/sw/source/ui/misc/outline.cxx
Warning:line 891, column 41
Division by zero

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 outline.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/misc/outline.cxx

/home/maarten/src/libreoffice/core/sw/source/ui/misc/outline.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 <hintids.hxx>
21#include <vcl/settings.hxx>
22#include <vcl/virdev.hxx>
23#include <sfx2/tabdlg.hxx>
24#include <editeng/brushitem.hxx>
25#include <unotools/configmgr.hxx>
26#include <SwStyleNameMapper.hxx>
27#include <num.hxx>
28#include <view.hxx>
29#include <docsh.hxx>
30#include <uitool.hxx>
31#include <wrtsh.hxx>
32#include <swmodule.hxx>
33#include <fmtcol.hxx>
34#include <outline.hxx>
35#include <uinums.hxx>
36#include <poolfmt.hxx>
37#include <shellres.hxx>
38#include <svl/style.hxx>
39#include <charfmt.hxx>
40#include <docstyle.hxx>
41#include <viewopt.hxx>
42#include <outline.hrc>
43#include <strings.hrc>
44#include <paratr.hxx>
45
46#include <IDocumentOutlineNodes.hxx>
47
48using namespace ::com::sun::star;
49
50namespace {
51
52class SwNumNamesDlg : public weld::GenericDialogController
53{
54 std::unique_ptr<weld::Entry> m_xFormEdit;
55 std::unique_ptr<weld::TreeView> m_xFormBox;
56 std::unique_ptr<weld::Button> m_xOKBtn;
57
58 DECL_LINK( ModifyHdl, weld::Entry&, void )static void LinkStubModifyHdl(void *, weld::Entry&); void
ModifyHdl(weld::Entry&)
;
59 DECL_LINK( SelectHdl, weld::TreeView&, void )static void LinkStubSelectHdl(void *, weld::TreeView&); void
SelectHdl(weld::TreeView&)
;
60 DECL_LINK( DoubleClickHdl, weld::TreeView&, bool )static bool LinkStubDoubleClickHdl(void *, weld::TreeView&
); bool DoubleClickHdl(weld::TreeView&)
;
61
62public:
63 explicit SwNumNamesDlg(weld::Window *pParent);
64 void SetUserNames(const OUString *pList[]);
65 OUString GetName() const { return m_xFormEdit->get_text(); }
66 int GetCurEntryPos() const { return m_xFormBox->get_selected_index(); }
67};
68
69}
70
71// remember selected entry
72IMPL_LINK( SwNumNamesDlg, SelectHdl, weld::TreeView&, rBox, void )void SwNumNamesDlg::LinkStubSelectHdl(void * instance, weld::
TreeView& data) { return static_cast<SwNumNamesDlg *>
(instance)->SelectHdl(data); } void SwNumNamesDlg::SelectHdl
(weld::TreeView& rBox)
73{
74 m_xFormEdit->set_text(rBox.get_selected_text());
75 m_xFormEdit->select_region(0, -1);
76}
77
78/** set user defined names
79 *
80 * @param pList list of user defined names; unknown positions for the user are 0.
81 */
82void SwNumNamesDlg::SetUserNames(const OUString *pList[])
83{
84 sal_uInt16 nSelect = 0;
85 for (sal_uInt16 i = 0; i < SwChapterNumRules::nMaxRules; ++i)
86 {
87 if(pList[i])
88 {
89 m_xFormBox->remove(i);
90 m_xFormBox->insert_text(i, *pList[i]);
91 if (i == nSelect)
92 nSelect++;
93 }
94 }
95 m_xFormBox->select(nSelect);
96 SelectHdl(*m_xFormBox);
97}
98
99// unlock OK-Button when text is in Edit
100IMPL_LINK( SwNumNamesDlg, ModifyHdl, weld::Entry&, rBox, void )void SwNumNamesDlg::LinkStubModifyHdl(void * instance, weld::
Entry& data) { return static_cast<SwNumNamesDlg *>(
instance)->ModifyHdl(data); } void SwNumNamesDlg::ModifyHdl
(weld::Entry& rBox)
101{
102 m_xOKBtn->set_sensitive(!rBox.get_text().isEmpty());
103}
104
105// DoubleClickHdl
106IMPL_LINK_NOARG(SwNumNamesDlg, DoubleClickHdl, weld::TreeView&, bool)bool SwNumNamesDlg::LinkStubDoubleClickHdl(void * instance, weld
::TreeView& data) { return static_cast<SwNumNamesDlg *
>(instance)->DoubleClickHdl(data); } bool SwNumNamesDlg
::DoubleClickHdl(__attribute__ ((unused)) weld::TreeView&
)
107{
108 m_xDialog->response(RET_OK);
109 return true;
110}
111
112SwNumNamesDlg::SwNumNamesDlg(weld::Window *pParent)
113 : GenericDialogController(pParent,
114 "modules/swriter/ui/numberingnamedialog.ui",
115 "NumberingNameDialog")
116 , m_xFormEdit(m_xBuilder->weld_entry("entry"))
117 , m_xFormBox(m_xBuilder->weld_tree_view("form"))
118 , m_xOKBtn(m_xBuilder->weld_button("ok"))
119{
120 for (size_t i = 0; i < SAL_N_ELEMENTS(OUTLINE_STYLE)(sizeof(sal_n_array_size(OUTLINE_STYLE))); ++i)
121 m_xFormBox->append_text(SwResId(OUTLINE_STYLE[i]));
122
123 m_xFormEdit->connect_changed(LINK(this, SwNumNamesDlg, ModifyHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwNumNamesDlg
*>(this), &SwNumNamesDlg::LinkStubModifyHdl)
);
124 m_xFormBox->connect_changed(LINK(this, SwNumNamesDlg, SelectHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwNumNamesDlg
*>(this), &SwNumNamesDlg::LinkStubSelectHdl)
);
125 m_xFormBox->connect_row_activated(LINK(this, SwNumNamesDlg, DoubleClickHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwNumNamesDlg
*>(this), &SwNumNamesDlg::LinkStubDoubleClickHdl)
);
126 m_xFormBox->set_size_request(-1, m_xFormBox->get_height_rows(9));
127}
128
129static sal_uInt16 lcl_BitToLevel(sal_uInt16 nActLevel)
130{
131 sal_uInt16 nTmp = nActLevel;
132 sal_uInt16 nTmpLevel = 0;
133 while( 0 != (nTmp >>= 1) )
134 nTmpLevel++;
135 return nTmpLevel;
136}
137
138sal_uInt16 SwOutlineTabDialog::nNumLevel = 1;
139
140SwOutlineTabDialog::SwOutlineTabDialog(weld::Window* pParent, const SfxItemSet* pSwItemSet,
141 SwWrtShell &rSh)
142 : SfxTabDialogController(pParent, "modules/swriter/ui/outlinenumbering.ui", "OutlineNumberingDialog", pSwItemSet)
143 , rWrtSh(rSh)
144 , pChapterNumRules(SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule
::Writer)))
->GetChapterNumRules())
145 , bModified(rWrtSh.IsModified())
146 , m_xMenuButton(m_xBuilder->weld_menu_button("format"))
147{
148 m_xMenuButton->connect_toggled(LINK(this, SwOutlineTabDialog, FormHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineTabDialog
*>(this), &SwOutlineTabDialog::LinkStubFormHdl)
);
149 m_xMenuButton->connect_selected(LINK(this, SwOutlineTabDialog, MenuSelectHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineTabDialog
*>(this), &SwOutlineTabDialog::LinkStubMenuSelectHdl)
);
150
151 xNumRule.reset(new SwNumRule(*rSh.GetOutlineNumRule()));
152 GetCancelButton().connect_clicked(LINK(this, SwOutlineTabDialog, CancelHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineTabDialog
*>(this), &SwOutlineTabDialog::LinkStubCancelHdl)
);
153
154 AddTabPage("position", &SwNumPositionTabPage::Create, nullptr);
155 AddTabPage("numbering", &SwOutlineSettingsTabPage::Create, nullptr);
156
157 OUString sHeadline;
158 sal_uInt16 i;
159
160 for( i = 0; i < MAXLEVEL; ++i )
161 {
162 // if the style wasn't created yet, it's still at this position
163 if( !rWrtSh.GetParaStyle( sHeadline =
164 SwStyleNameMapper::GetUIName( static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i),
165 sHeadline )) )
166 aCollNames[i] = sHeadline;
167 }
168
169 // query the text templates' outlining levels
170 const sal_uInt16 nCount = rWrtSh.GetTextFormatCollCount();
171 for(i = 0; i < nCount; ++i )
172 {
173 SwTextFormatColl &rTextColl = rWrtSh.GetTextFormatColl(i);
174 if(!rTextColl.IsDefault())
175 {
176 if(rTextColl.IsAssignedToListLevelOfOutlineStyle())
177 {
178 int nOutLevel = rTextColl.GetAssignedOutlineStyleLevel();
179 aCollNames[ nOutLevel ] = rTextColl.GetName();
180 }
181 }
182 }
183}
184
185SwOutlineTabDialog::~SwOutlineTabDialog()
186{
187}
188
189void SwOutlineTabDialog::PageCreated(const OString& rPageId, SfxTabPage& rPage)
190{
191 if (rPageId == "position")
192 {
193 static_cast<SwNumPositionTabPage&>(rPage).SetWrtShell(&rWrtSh);
194 static_cast<SwNumPositionTabPage&>(rPage).SetOutlineTabDialog(this);
195 }
196 else if (rPageId == "numbering")
197 {
198 static_cast<SwOutlineSettingsTabPage&>(rPage).SetWrtShell(&rWrtSh);
199 }
200}
201
202IMPL_LINK_NOARG(SwOutlineTabDialog, CancelHdl, weld::Button&, void)void SwOutlineTabDialog::LinkStubCancelHdl(void * instance, weld
::Button& data) { return static_cast<SwOutlineTabDialog
*>(instance)->CancelHdl(data); } void SwOutlineTabDialog
::CancelHdl(__attribute__ ((unused)) weld::Button&)
203{
204 if (!bModified)
205 rWrtSh.ResetModified();
206 m_xDialog->response(RET_CANCEL);
207}
208
209IMPL_LINK_NOARG(SwOutlineTabDialog, FormHdl, weld::ToggleButton&, void)void SwOutlineTabDialog::LinkStubFormHdl(void * instance, weld
::ToggleButton& data) { return static_cast<SwOutlineTabDialog
*>(instance)->FormHdl(data); } void SwOutlineTabDialog
::FormHdl(__attribute__ ((unused)) weld::ToggleButton&)
210{
211 if (!m_xMenuButton->get_active())
212 return;
213
214 // fill PopupMenu
215 for(sal_uInt16 i = 0; i < SwChapterNumRules::nMaxRules; ++i)
216 {
217 const SwNumRulesWithName *pRules = pChapterNumRules->GetRules(i);
218 if (!pRules)
219 continue;
220 m_xMenuButton->set_item_label("form" + OString::number(i + 1), pRules->GetName());
221 }
222
223 OString sHelpId(m_xMenuButton->get_item_help_id("form1"));
224 for (sal_Int32 i = 2; i <= 9; ++i)
225 {
226 m_xMenuButton->set_item_help_id("form" + OString::number(i), sHelpId);
227 }
228}
229
230IMPL_LINK(SwOutlineTabDialog, MenuSelectHdl, const OString&, rIdent, void)void SwOutlineTabDialog::LinkStubMenuSelectHdl(void * instance
, const OString& data) { return static_cast<SwOutlineTabDialog
*>(instance)->MenuSelectHdl(data); } void SwOutlineTabDialog
::MenuSelectHdl(const OString& rIdent)
231{
232 sal_uInt8 nLevelNo = 0;
233
234 if (rIdent == "form1")
235 nLevelNo = 1;
236 else if (rIdent == "form2")
237 nLevelNo = 2;
238 else if (rIdent == "form3")
239 nLevelNo = 3;
240 else if (rIdent == "form4")
241 nLevelNo = 4;
242 else if (rIdent == "form5")
243 nLevelNo = 5;
244 else if (rIdent == "form6")
245 nLevelNo = 6;
246 else if (rIdent == "form7")
247 nLevelNo = 7;
248 else if (rIdent == "form8")
249 nLevelNo = 8;
250 else if (rIdent == "form9")
251 nLevelNo = 9;
252 else if (rIdent == "saveas")
253 {
254 SwNumNamesDlg aDlg(m_xDialog.get());
255 const OUString *aStrArr[SwChapterNumRules::nMaxRules];
256 for(sal_uInt16 i = 0; i < SwChapterNumRules::nMaxRules; ++i)
257 {
258 const SwNumRulesWithName *pRules = pChapterNumRules->GetRules(i);
259 if(pRules)
260 aStrArr[i] = &pRules->GetName();
261 else
262 aStrArr[i] = nullptr;
263 }
264 aDlg.SetUserNames(aStrArr);
265 if (aDlg.run() == RET_OK)
266 {
267 const OUString aName(aDlg.GetName());
268 pChapterNumRules->ApplyNumRules( SwNumRulesWithName(
269 *xNumRule, aName ), aDlg.GetCurEntryPos() );
270 m_xMenuButton->set_item_label("form" + OString::number(aDlg.GetCurEntryPos() + 1), aName);
271 }
272 return;
273 }
274
275 if( nLevelNo-- )
276 {
277 const SwNumRulesWithName *pRules = pChapterNumRules->GetRules( nLevelNo );
278 if( pRules )
279 {
280 xNumRule = pRules->MakeNumRule(rWrtSh);
281 xNumRule->SetRuleType( OUTLINE_RULE );
282 SfxTabPage* pOutlinePage = GetTabPage("numbering");
283 assert(pOutlinePage)(static_cast <bool> (pOutlinePage) ? void (0) : __assert_fail
("pOutlinePage", "/home/maarten/src/libreoffice/core/sw/source/ui/misc/outline.cxx"
, 283, __extension__ __PRETTY_FUNCTION__))
;
284 static_cast<SwOutlineSettingsTabPage*>(pOutlinePage)->SetNumRule(xNumRule.get());
285 }
286 else
287 *xNumRule = *rWrtSh.GetOutlineNumRule();
288 }
289
290 SfxTabPage* pPage = GetCurTabPage();
291 pPage->Reset(GetOutputItemSet());
292}
293
294sal_uInt16 SwOutlineTabDialog::GetLevel(const OUString &rFormatName) const
295{
296 for(sal_uInt16 i = 0; i < MAXLEVEL; ++i)
297 {
298 if(aCollNames[i] == rFormatName)
299 return i;
300 }
301 return MAXLEVEL;
302}
303
304short SwOutlineTabDialog::Ok()
305{
306 SfxTabDialogController::Ok();
307 // set levels for all created templates; has to be done in order to
308 // delete possibly cancelled assignments again.
309
310 // encapsulate changes into an action to avoid effects on the current cursor
311 // position during the changes.
312 rWrtSh.StartAction();
313
314 const SwNumRule * pOutlineRule = rWrtSh.GetOutlineNumRule();
315
316 sal_uInt16 i, nCount = rWrtSh.GetTextFormatCollCount();
317 for( i = 0; i < nCount; ++i )
318 {
319 SwTextFormatColl &rTextColl = rWrtSh.GetTextFormatColl(i);
320 if( !rTextColl.IsDefault() )
321 {
322 const SfxPoolItem & rItem =
323 rTextColl.GetFormatAttr(RES_PARATR_NUMRULE, false);
324
325 if (static_cast<sal_uInt8>(GetLevel(rTextColl.GetName())) == MAXLEVEL)
326 {
327 if(rTextColl.IsAssignedToListLevelOfOutlineStyle())
328 {
329 rTextColl.DeleteAssignmentToListLevelOfOutlineStyle();
330 }
331 if (static_cast<const SwNumRuleItem &>(rItem).GetValue() ==
332 pOutlineRule->GetName())
333 {
334 rTextColl.ResetFormatAttr(RES_PARATR_NUMRULE);
335 }
336 }
337 else
338 {
339 rTextColl.AssignToListLevelOfOutlineStyle(GetLevel(rTextColl.GetName()));
340
341 if (static_cast<const SwNumRuleItem &>(rItem).GetValue() !=
342 pOutlineRule->GetName())
343 {
344 SwNumRuleItem aItem(pOutlineRule->GetName());
345 rTextColl.SetFormatAttr(aItem);
346 }
347 }
348 }
349 }
350
351 for(i = 0; i < MAXLEVEL; ++i )
352 {
353 OUString sHeadline;
354 ::SwStyleNameMapper::FillUIName( static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i),
355 sHeadline );
356 SwTextFormatColl* pColl = rWrtSh.FindTextFormatCollByName( sHeadline );
357 if( !pColl && aCollNames[i] != sHeadline)
358 {
359 SwTextFormatColl* pTextColl = rWrtSh.GetTextCollFromPool(
360 static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i) );
361 pTextColl->DeleteAssignmentToListLevelOfOutlineStyle();
362 pTextColl->ResetFormatAttr(RES_PARATR_NUMRULE);
363
364 if( !aCollNames[i].isEmpty() )
365 {
366 pTextColl = rWrtSh.GetParaStyle(
367 aCollNames[i], SwWrtShell::GETSTYLE_CREATESOME);
368 if(pTextColl)
369 {
370 pTextColl->AssignToListLevelOfOutlineStyle(i);
371 SwNumRuleItem aItem(pOutlineRule->GetName());
372 pTextColl->SetFormatAttr(aItem);
373 }
374 }
375 }
376 }
377
378 rWrtSh.SetOutlineNumRule(*xNumRule);
379
380 // #i30443#
381 rWrtSh.EndAction();
382
383 return RET_OK;
384}
385
386SwOutlineSettingsTabPage::SwOutlineSettingsTabPage(weld::Container* pPage, weld::DialogController* pController,
387 const SfxItemSet& rSet)
388 : SfxTabPage(pPage, pController, "modules/swriter/ui/outlinenumberingpage.ui", "OutlineNumberingPage", &rSet)
389 , aNoFormatName(SwResId(SW_STR_NONEreinterpret_cast<char const *>("SW_STR_NONE" "\004" u8"[None]"
)
))
390 , pSh(nullptr)
391 , pNumRule(nullptr)
392 , pCollNames(nullptr)
393 , nActLevel(1)
394 , m_xLevelLB(m_xBuilder->weld_tree_view("level"))
395 , m_xCollBox(m_xBuilder->weld_combo_box("style"))
396 , m_xNumberBox(new SwNumberingTypeListBox(m_xBuilder->weld_combo_box("numbering")))
397 , m_xCharFormatLB(m_xBuilder->weld_combo_box("charstyle"))
398 , m_xAllLevelFT(m_xBuilder->weld_label("sublevelsft"))
399 , m_xAllLevelNF(m_xBuilder->weld_spin_button("sublevelsnf"))
400 , m_xPrefixED(m_xBuilder->weld_entry("prefix"))
401 , m_xSuffixED(m_xBuilder->weld_entry("suffix"))
402 , m_xStartEdit(m_xBuilder->weld_spin_button("startat"))
403 , m_xPreviewWIN(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreviewWIN))
404{
405 SetExchangeSupport();
406
407 m_xNumberBox->Reload(SwInsertNumTypes::NoNumbering | SwInsertNumTypes::Extended);
408 m_xCollBox->make_sorted();
409 m_xCollBox->append_text(aNoFormatName);
410 m_xLevelLB->connect_changed(LINK(this, SwOutlineSettingsTabPage, LevelHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage
*>(this), &SwOutlineSettingsTabPage::LinkStubLevelHdl
)
);
411 m_xAllLevelNF->connect_value_changed(LINK(this, SwOutlineSettingsTabPage, ToggleComplete)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage
*>(this), &SwOutlineSettingsTabPage::LinkStubToggleComplete
)
);
412 m_xCollBox->connect_changed(LINK(this, SwOutlineSettingsTabPage, CollSelect)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage
*>(this), &SwOutlineSettingsTabPage::LinkStubCollSelect
)
);
413 m_xNumberBox->connect_changed(LINK(this, SwOutlineSettingsTabPage, NumberSelect)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage
*>(this), &SwOutlineSettingsTabPage::LinkStubNumberSelect
)
);
414 m_xPrefixED->connect_changed(LINK(this, SwOutlineSettingsTabPage, DelimModify)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage
*>(this), &SwOutlineSettingsTabPage::LinkStubDelimModify
)
);
415 m_xSuffixED->connect_changed(LINK(this, SwOutlineSettingsTabPage, DelimModify)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage
*>(this), &SwOutlineSettingsTabPage::LinkStubDelimModify
)
);
416 m_xStartEdit->connect_value_changed(LINK(this, SwOutlineSettingsTabPage, StartModified)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage
*>(this), &SwOutlineSettingsTabPage::LinkStubStartModified
)
);
417 m_xCharFormatLB->connect_changed(LINK(this, SwOutlineSettingsTabPage, CharFormatHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwOutlineSettingsTabPage
*>(this), &SwOutlineSettingsTabPage::LinkStubCharFormatHdl
)
);
418}
419
420void SwOutlineSettingsTabPage::Update()
421{
422 // if a template was already selected for this level, select it in the ListBox
423 m_xCollBox->set_sensitive(USHRT_MAX(32767 *2 +1) != nActLevel);
424 if(USHRT_MAX(32767 *2 +1) == nActLevel)
425 {
426 bool bSamePrefix = true;
427 bool bSameSuffix = true;
428 bool bSameType = true;
429 bool bSameComplete = true;
430 bool bSameStart = true;
431 bool bSameCharFormat = true;
432
433 const SwNumFormat* aNumFormatArr[MAXLEVEL];
434 const SwCharFormat* pFirstFormat = nullptr;
435
436 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
437 {
438
439 aNumFormatArr[ i ] = &pNumRule->Get(i);
440 if(i == 0)
441 pFirstFormat = aNumFormatArr[i]->GetCharFormat();
442 else
443 {
444 bSameType &= aNumFormatArr[i]->GetNumberingType() == aNumFormatArr[0]->GetNumberingType();
445 bSameStart &= aNumFormatArr[i]->GetStart() == aNumFormatArr[0]->GetStart();
446 bSamePrefix &= aNumFormatArr[i]->GetPrefix() == aNumFormatArr[0]->GetPrefix();
447 bSameSuffix &= aNumFormatArr[i]->GetSuffix() == aNumFormatArr[0]->GetSuffix();
448 bSameComplete &= aNumFormatArr[i]->GetIncludeUpperLevels() == aNumFormatArr[0]->GetIncludeUpperLevels();
449 const SwCharFormat* pFormat = aNumFormatArr[i]->GetCharFormat();
450 bSameCharFormat &= (!pFirstFormat && !pFormat)
451 || (pFirstFormat && pFormat && pFormat->GetName() == pFirstFormat->GetName());
452 }
453 }
454 CheckForStartValue_Impl(aNumFormatArr[0]->GetNumberingType());
455 if (bSameType)
456 m_xNumberBox->SelectNumberingType( aNumFormatArr[0]->GetNumberingType() );
457 else
458 m_xNumberBox->SetNoSelection();
459 if(bSameStart)
460 m_xStartEdit->set_value(aNumFormatArr[0]->GetStart());
461 else
462 m_xStartEdit->set_text(OUString());
463 if(bSamePrefix)
464 m_xPrefixED->set_text(aNumFormatArr[0]->GetPrefix());
465 else
466 m_xPrefixED->set_text(OUString());
467 if(bSameSuffix)
468 m_xSuffixED->set_text(aNumFormatArr[0]->GetSuffix());
469 else
470 m_xSuffixED->set_text(OUString());
471
472 if (bSameCharFormat)
473 {
474 if (pFirstFormat)
475 m_xCharFormatLB->set_active_text(pFirstFormat->GetName());
476 else
477 m_xCharFormatLB->set_active_text(SwViewShell::GetShellRes()->aStrNone);
478 }
479 else
480 m_xCharFormatLB->set_active(-1);
481
482 m_xAllLevelFT->set_sensitive(true);
483 m_xAllLevelNF->set_sensitive(true);
484 m_xAllLevelNF->set_max(MAXLEVEL);
485 if (bSameComplete)
486 {
487 m_xAllLevelNF->set_value(aNumFormatArr[0]->GetIncludeUpperLevels());
488 }
489 else
490 {
491 m_xAllLevelNF->set_text(OUString());
492 }
493 }
494 else
495 {
496 sal_uInt16 nTmpLevel = lcl_BitToLevel(nActLevel);
497 OUString aColl(pCollNames[nTmpLevel]);
498 if(!aColl.isEmpty())
499 m_xCollBox->set_active_text(aColl);
500 else
501 m_xCollBox->set_active_text(aNoFormatName);
502 const SwNumFormat &rFormat = pNumRule->Get(nTmpLevel);
503
504 m_xNumberBox->SelectNumberingType( rFormat.GetNumberingType() );
505 m_xPrefixED->set_text(rFormat.GetPrefix());
506 m_xSuffixED->set_text(rFormat.GetSuffix());
507 const SwCharFormat* pFormat = rFormat.GetCharFormat();
508 if(pFormat)
509 m_xCharFormatLB->set_active_text(pFormat->GetName());
510 else
511 m_xCharFormatLB->set_active_text(SwViewShell::GetShellRes()->aStrNone);
512
513 if(nTmpLevel)
514 {
515 m_xAllLevelFT->set_sensitive(true);
516 m_xAllLevelNF->set_sensitive(true);
517 m_xAllLevelNF->set_max(nTmpLevel + 1);
518 m_xAllLevelNF->set_value(rFormat.GetIncludeUpperLevels());
519 }
520 else
521 {
522 m_xAllLevelNF->set_text(OUString());
523 m_xAllLevelNF->set_sensitive(false);
524 m_xAllLevelFT->set_sensitive(false);
525 }
526 CheckForStartValue_Impl(rFormat.GetNumberingType());
527 m_xStartEdit->set_value( rFormat.GetStart() );
528 }
529 SetModified();
530}
531
532IMPL_LINK( SwOutlineSettingsTabPage, LevelHdl, weld::TreeView&, rBox, void )void SwOutlineSettingsTabPage::LinkStubLevelHdl(void * instance
, weld::TreeView& data) { return static_cast<SwOutlineSettingsTabPage
*>(instance)->LevelHdl(data); } void SwOutlineSettingsTabPage
::LevelHdl(weld::TreeView& rBox)
533{
534 nActLevel = 0;
535 auto aRows = rBox.get_selected_rows();
536 if (std::find(aRows.begin(), aRows.end(), MAXLEVEL) != aRows.end())
537 {
538 nActLevel = 0xFFFF;
539 }
540 else
541 {
542 sal_uInt16 nMask = 1;
543 for( sal_uInt16 i = 0; i < MAXLEVEL; i++ )
544 {
545 if (std::find(aRows.begin(), aRows.end(), i) != aRows.end())
546 nActLevel |= nMask;
547 nMask <<= 1;
548 }
549 }
550 Update();
551}
552
553IMPL_LINK(SwOutlineSettingsTabPage, ToggleComplete, weld::SpinButton&, rEdit, void)void SwOutlineSettingsTabPage::LinkStubToggleComplete(void * instance
, weld::SpinButton& data) { return static_cast<SwOutlineSettingsTabPage
*>(instance)->ToggleComplete(data); } void SwOutlineSettingsTabPage
::ToggleComplete(weld::SpinButton& rEdit)
554{
555 sal_uInt16 nMask = 1;
556 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
557 {
558 if(nActLevel & nMask)
559 {
560 SwNumFormat aNumFormat(pNumRule->Get(i));
561 aNumFormat.SetIncludeUpperLevels( std::min( static_cast<sal_uInt8>(rEdit.get_value()),
562 static_cast<sal_uInt8>(i + 1)) );
563 pNumRule->Set(i, aNumFormat);
564 }
565 nMask <<= 1;
566 }
567 SetModified();
568}
569
570IMPL_LINK( SwOutlineSettingsTabPage, CollSelect, weld::ComboBox&, rBox, void )void SwOutlineSettingsTabPage::LinkStubCollSelect(void * instance
, weld::ComboBox& data) { return static_cast<SwOutlineSettingsTabPage
*>(instance)->CollSelect(data); } void SwOutlineSettingsTabPage
::CollSelect(weld::ComboBox& rBox)
571{
572 sal_uInt8 i;
573
574 const OUString aCollName(rBox.get_active_text());
575 //0xFFFF not allowed here (disable)
576 sal_uInt16 nTmpLevel = lcl_BitToLevel(nActLevel);
577 OUString sOldName( pCollNames[nTmpLevel] );
578
579 for( i = 0; i < MAXLEVEL; ++i)
580 pCollNames[i] = aSaveCollNames[i];
581
582 if(aCollName == aNoFormatName)
583 pCollNames[nTmpLevel].clear();
584 else
585 {
586 pCollNames[nTmpLevel] = aCollName;
587 // template already in use?
588 for( i = 0; i < MAXLEVEL; ++i)
589 if(i != nTmpLevel && pCollNames[i] == aCollName )
590 pCollNames[i].clear();
591 }
592
593 // search the oldname and put it into the current entries
594 if( !sOldName.isEmpty() )
595 for( i = 0; i < MAXLEVEL; ++i)
596 if( aSaveCollNames[ i ] == sOldName && i != nTmpLevel &&
597 pCollNames[ i ].isEmpty() )
598 {
599 sal_uInt8 n;
600 for( n = 0; n < MAXLEVEL; ++n )
601 if( pCollNames[ n ] == sOldName )
602 break;
603
604 if( MAXLEVEL == n )
605 // it was an outline level name and the current entries is zero.
606 pCollNames[ i ] = sOldName;
607 }
608
609 SetModified();
610 CollSave();
611}
612
613void SwOutlineSettingsTabPage::CollSave()
614{
615 for (sal_uInt8 i = 0; i < MAXLEVEL; ++i)
616 aSaveCollNames[i] = pCollNames[i];
617}
618
619IMPL_LINK_NOARG(SwOutlineSettingsTabPage, NumberSelect, weld::ComboBox&, void)void SwOutlineSettingsTabPage::LinkStubNumberSelect(void * instance
, weld::ComboBox& data) { return static_cast<SwOutlineSettingsTabPage
*>(instance)->NumberSelect(data); } void SwOutlineSettingsTabPage
::NumberSelect(__attribute__ ((unused)) weld::ComboBox&)
620{
621 sal_uInt16 nMask = 1;
622 SvxNumType nNumberType = m_xNumberBox->GetSelectedNumberingType();
623 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
624 {
625 if(nActLevel & nMask)
626 {
627 SwNumFormat aNumFormat(pNumRule->Get(i));
628 aNumFormat.SetNumberingType(nNumberType);
629 pNumRule->Set(i, aNumFormat);
630 CheckForStartValue_Impl(nNumberType);
631 }
632 nMask <<= 1;
633 }
634 SetModified();
635}
636
637IMPL_LINK_NOARG(SwOutlineSettingsTabPage, DelimModify, weld::Entry&, void)void SwOutlineSettingsTabPage::LinkStubDelimModify(void * instance
, weld::Entry& data) { return static_cast<SwOutlineSettingsTabPage
*>(instance)->DelimModify(data); } void SwOutlineSettingsTabPage
::DelimModify(__attribute__ ((unused)) weld::Entry&)
638{
639 sal_uInt16 nMask = 1;
640 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
641 {
642 if(nActLevel & nMask)
643 {
644 SwNumFormat aNumFormat(pNumRule->Get(i));
645 aNumFormat.SetPrefix( m_xPrefixED->get_text() );
646 aNumFormat.SetSuffix( m_xSuffixED->get_text() );
647 pNumRule->Set(i, aNumFormat);
648 }
649 nMask <<= 1;
650 }
651 SetModified();
652}
653
654IMPL_LINK( SwOutlineSettingsTabPage, StartModified, weld::SpinButton&, rEdit, void )void SwOutlineSettingsTabPage::LinkStubStartModified(void * instance
, weld::SpinButton& data) { return static_cast<SwOutlineSettingsTabPage
*>(instance)->StartModified(data); } void SwOutlineSettingsTabPage
::StartModified(weld::SpinButton& rEdit)
655{
656 sal_uInt16 nMask = 1;
657 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
658 {
659 if(nActLevel & nMask)
660 {
661 SwNumFormat aNumFormat(pNumRule->Get(i));
662 aNumFormat.SetStart(static_cast<sal_uInt16>(rEdit.get_value()));
663 pNumRule->Set(i, aNumFormat);
664 }
665 nMask <<= 1;
666 }
667 SetModified();
668}
669
670IMPL_LINK_NOARG(SwOutlineSettingsTabPage, CharFormatHdl, weld::ComboBox&, void)void SwOutlineSettingsTabPage::LinkStubCharFormatHdl(void * instance
, weld::ComboBox& data) { return static_cast<SwOutlineSettingsTabPage
*>(instance)->CharFormatHdl(data); } void SwOutlineSettingsTabPage
::CharFormatHdl(__attribute__ ((unused)) weld::ComboBox&)
671{
672 OUString sEntry = m_xCharFormatLB->get_active_text();
673 sal_uInt16 nMask = 1;
674 bool bFormatNone = sEntry == SwViewShell::GetShellRes()->aStrNone;
675 SwCharFormat* pFormat = nullptr;
676 if(!bFormatNone)
677 {
678 sal_uInt16 nChCount = pSh->GetCharFormatCount();
679 for(sal_uInt16 i = 0; i < nChCount; i++)
680 {
681 SwCharFormat& rChFormat = pSh->GetCharFormat(i);
682 if(rChFormat.GetName() == sEntry)
683 {
684 pFormat = &rChFormat;
685 break;
686 }
687 }
688 if(!pFormat)
689 {
690 SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
691 SfxStyleSheetBase* pBase;
692 pBase = pPool->Find(sEntry, SfxStyleFamily::Char);
693 if(!pBase)
694 pBase = &pPool->Make(sEntry, SfxStyleFamily::Page);
695 pFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat();
696
697 }
698 }
699
700 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
701 {
702 if(nActLevel & nMask)
703 {
704 SwNumFormat aNumFormat(pNumRule->Get(i));
705 if(bFormatNone)
706 aNumFormat.SetCharFormat(nullptr);
707 else
708 aNumFormat.SetCharFormat(pFormat);
709 pNumRule->Set(i, aNumFormat);
710 }
711 nMask <<= 1;
712 }
713}
714
715SwOutlineSettingsTabPage::~SwOutlineSettingsTabPage()
716{
717}
718
719void SwOutlineSettingsTabPage::SetWrtShell(SwWrtShell* pShell)
720{
721 pSh = pShell;
722 // query this document's NumRules
723 pNumRule = static_cast<SwOutlineTabDialog*>(GetDialogController())->GetNumRule();
724 pCollNames = static_cast<SwOutlineTabDialog*>(GetDialogController())->GetCollNames();
725
726 CollSave();
727
728 m_aPreviewWIN.SetNumRule(pNumRule);
729 m_aPreviewWIN.SetOutlineNames(pCollNames);
730 // set start value - nActLevel must be 1 here
731 sal_uInt16 nTmpLevel = lcl_BitToLevel(nActLevel);
732 const SwNumFormat& rNumFormat = pNumRule->Get( nTmpLevel );
733 m_xStartEdit->set_value( rNumFormat.GetStart() );
734
735 // create pool formats for headlines
736 for (sal_uInt16 i = 0; i < MAXLEVEL; ++i)
737 {
738 m_xCollBox->append_text( SwStyleNameMapper::GetUIName(
739 static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i), OUString()));
740 m_xLevelLB->append_text( OUString::number(i + 1) );
741 }
742 OUString sStr = "1 - " + OUString::number(MAXLEVEL);
743 m_xLevelLB->append_text(sStr);
744
745 // query the texttemplates' outlining levels
746 const sal_uInt16 nCount = pSh->GetTextFormatCollCount();
747 for (sal_uInt16 i = 0; i < nCount; ++i)
748 {
749 SwTextFormatColl &rTextColl = pSh->GetTextFormatColl(i);
750 if(!rTextColl.IsDefault())
751 {
752 sStr = rTextColl.GetName();
753 if (m_xCollBox->find_text(sStr) == -1)
754 m_xCollBox->append_text(sStr);
755 }
756 }
757
758 m_xNumberBox->SelectNumberingType(rNumFormat.GetNumberingType());
759 SwOutlineNodes::size_type nOutlinePos = pSh->GetOutlinePos(MAXLEVEL);
760 int nTmp = 0;
761 if(nOutlinePos != SwOutlineNodes::npos)
762 {
763 nTmp = static_cast<sal_uInt16>(pSh->getIDocumentOutlineNodesAccess()->getOutlineLevel(nOutlinePos));
764 }
765 m_xLevelLB->select(nTmp-1);
766
767 // collect char styles
768 m_xCharFormatLB->clear();
769 m_xCharFormatLB->append_text(SwViewShell::GetShellRes()->aStrNone);
770
771 // char styles
772 ::FillCharStyleListBox(*m_xCharFormatLB,
773 pSh->GetView().GetDocShell());
774 Update();
775}
776
777void SwOutlineSettingsTabPage::ActivatePage(const SfxItemSet& )
778{
779 nActLevel = SwOutlineTabDialog::GetActNumLevel();
780 if(nActLevel != USHRT_MAX(32767 *2 +1))
781 m_xLevelLB->select(lcl_BitToLevel(nActLevel));
782 else
783 m_xLevelLB->select(MAXLEVEL);
784 LevelHdl(*m_xLevelLB);
785}
786
787DeactivateRC SwOutlineSettingsTabPage::DeactivatePage(SfxItemSet*)
788{
789 SwOutlineTabDialog::SetActNumLevel(nActLevel);
790 return DeactivateRC::LeavePage;
791}
792
793bool SwOutlineSettingsTabPage::FillItemSet( SfxItemSet* )
794{
795 return true;
796}
797
798void SwOutlineSettingsTabPage::Reset( const SfxItemSet* rSet )
799{
800 ActivatePage(*rSet);
801}
802
803std::unique_ptr<SfxTabPage> SwOutlineSettingsTabPage::Create(weld::Container* pPage, weld::DialogController* pController,
804 const SfxItemSet* rAttrSet)
805{
806 return std::make_unique<SwOutlineSettingsTabPage>(pPage, pController, *rAttrSet);
807}
808
809void SwOutlineSettingsTabPage::CheckForStartValue_Impl(sal_uInt16 nNumberingType)
810{
811 bool bIsNull = m_xStartEdit->get_value() == 0;
812 bool bNoZeroAllowed = nNumberingType < SVX_NUM_ARABIC ||
813 SVX_NUM_CHARS_UPPER_LETTER_N == nNumberingType ||
814 SVX_NUM_CHARS_LOWER_LETTER_N == nNumberingType;
815 m_xStartEdit->set_min(bNoZeroAllowed ? 1 : 0);
816 if (bIsNull && bNoZeroAllowed)
817 StartModified(*m_xStartEdit);
818}
819
820static long lcl_DrawBullet(vcl::RenderContext* pVDev, const SwNumFormat& rFormat, long nXStart, long nYStart, const Size& rSize)
821{
822 vcl::Font aTmpFont(pVDev->GetFont());
823
824 // via Uno it's possible that no font has been set!
825 vcl::Font aFont(rFormat.GetBulletFont() ? *rFormat.GetBulletFont() : aTmpFont);
826 Size aTmpSize(rSize);
827 aTmpSize.setWidth( aTmpSize.Width() * ( rFormat.GetBulletRelSize()) );
828 aTmpSize.setWidth( aTmpSize.Width() / 100 ) ;
829 aTmpSize.setHeight( aTmpSize.Height() * ( rFormat.GetBulletRelSize()) );
830 aTmpSize.setHeight( aTmpSize.Height() / 100 ) ;
831 // in case of a height of zero it is drawn in original height
832 if(!aTmpSize.Height())
833 aTmpSize.setHeight( 1 );
834 aFont.SetFontSize(aTmpSize);
835 aFont.SetTransparent(true);
836 Color aBulletColor = rFormat.GetBulletColor();
837 if(aBulletColor == COL_AUTO)
838 aBulletColor = pVDev->GetFillColor().IsDark() ? COL_WHITE : COL_BLACK;
839 else if(aBulletColor == pVDev->GetFillColor())
840 aBulletColor.Invert();
841 aFont.SetColor(aBulletColor);
842 pVDev->SetFont( aFont );
843 sal_UCS4 cBullet = rFormat.GetBulletChar();
844 OUString aText(&cBullet, 1);
845 long nY = nYStart;
846 nY -= ((aTmpSize.Height() - rSize.Height())/ 2);
847 pVDev->DrawText( Point(nXStart, nY), aText );
848 long nRet = pVDev->GetTextWidth(aText);
849
850 pVDev->SetFont(aTmpFont);
851 return nRet;
852}
853
854static long lcl_DrawGraphic(vcl::RenderContext* pVDev, const SwNumFormat &rFormat, long nXStart, long nYStart, long nDivision)
855{
856 const SvxBrushItem* pBrushItem = rFormat.GetBrush();
857 long nRet = 0;
858 if (pBrushItem)
859 {
860 const Graphic* pGraphic = pBrushItem->GetGraphic();
861 if (pGraphic)
862 {
863 Size aGSize( rFormat.GetGraphicSize());
864 aGSize.setWidth( aGSize.Width() / nDivision );
865 nRet = aGSize.Width();
866 aGSize.setHeight( aGSize.Height() / nDivision );
867 pGraphic->Draw(pVDev, Point(nXStart, nYStart), pVDev->PixelToLogic(aGSize));
868 }
869 }
870 return nRet;
871}
872
873void NumberingPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
874{
875 const Size aSize(rRenderContext.PixelToLogic(GetOutputSizePixel()));
1
Value assigned to 'aSize.nA'
876
877 ScopedVclPtrInstance<VirtualDevice> pVDev(rRenderContext);
878 pVDev->SetMapMode(rRenderContext.GetMapMode());
879 pVDev->SetOutputSize(aSize);
880
881 // #101524# OJ
882 pVDev->SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetWindowColor());
883 pVDev->SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetButtonTextColor());
884 pVDev->DrawRect(tools::Rectangle(Point(0,0), aSize));
885
886 if (pActNum)
2
Assuming field 'pActNum' is non-null
3
Taking true branch
887 {
888 long nWidthRelation = 30; // chapter dialog
889 if(nPageWidth)
4
Assuming field 'nPageWidth' is not equal to 0
5
Taking true branch
890 {
891 nWidthRelation = nPageWidth / aSize.Width();
6
Calling 'Size::Width'
8
Returning from 'Size::Width'
9
Division by zero
892 if(bPosition)
893 nWidthRelation = nWidthRelation * 2 / 3;
894 else
895 nWidthRelation = nWidthRelation / 4;
896 }
897
898 // height per level
899 const long nXStep = aSize.Width() / (3 * MAXLEVEL * ((MAXLEVEL < 10) ? 2 : 1));
900 const long nYStep = (aSize.Height() - 6)/ MAXLEVEL;
901 long nYStart = 4;
902 aStdFont = OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, GetAppLanguage(),
903 GetDefaultFontFlags::OnlyOne, &rRenderContext);
904 // #101524# OJ
905 aStdFont.SetColor(SwViewOption::GetFontColor());
906
907 const long nFontHeight = nYStep * ( bPosition ? 15 : 6 ) / 10;
908 aStdFont.SetFontSize(Size( 0, nFontHeight ));
909
910 long nPreNum = pActNum->Get(0).GetStart();
911
912 if (bPosition)
913 {
914 const long nLineHeight = nFontHeight * 8 / 7;
915 sal_uInt8 nStart = 0;
916 while (!(nActLevel & (1 << nStart)))
917 {
918 nStart++;
919 }
920 if(nStart) // so that possible predecessors and successors are showed
921 nStart--;
922
923 SwNumberTree::tNumberVector aNumVector;
924 sal_uInt8 nEnd = std::min(sal_uInt8(nStart + 3), MAXLEVEL);
925 for (sal_uInt8 nLevel = nStart; nLevel < nEnd; ++nLevel)
926 {
927 const SwNumFormat &rFormat = pActNum->Get(nLevel);
928 aNumVector.push_back(rFormat.GetStart());
929
930 long nXStart( 0 );
931 long nTextOffset( 0 );
932 long nNumberXPos( 0 );
933 if (rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION)
934 {
935 nXStart = rFormat.GetAbsLSpace() / nWidthRelation;
936 nTextOffset = rFormat.GetCharTextDistance() / nWidthRelation;
937 nNumberXPos = nXStart;
938 const long nFirstLineOffset = (-rFormat.GetFirstLineOffset()) / nWidthRelation;
939
940 if(nFirstLineOffset <= nNumberXPos)
941 nNumberXPos -= nFirstLineOffset;
942 else
943 nNumberXPos = 0;
944 }
945 else if (rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT)
946 {
947 const long nTmpNumberXPos((rFormat.GetIndentAt() + rFormat.GetFirstLineIndent()) / nWidthRelation);
948 nNumberXPos = (nTmpNumberXPos < 0) ? 0 : nTmpNumberXPos;
949 }
950
951 long nBulletWidth = 0;
952 if (SVX_NUM_BITMAP == rFormat.GetNumberingType())
953 {
954 nBulletWidth = lcl_DrawGraphic(pVDev.get(), rFormat, nNumberXPos,
955 nYStart, nWidthRelation);
956 }
957 else if (SVX_NUM_CHAR_SPECIAL == rFormat.GetNumberingType())
958 {
959 nBulletWidth = lcl_DrawBullet(pVDev.get(), rFormat, nNumberXPos,
960 nYStart, aStdFont.GetFontSize());
961 }
962 else
963 {
964 pVDev->SetFont(aStdFont);
965 if(pActNum->IsContinusNum())
966 aNumVector[nLevel] = nPreNum;
967 OUString aText(pActNum->MakeNumString( aNumVector ));
968 pVDev->DrawText( Point(nNumberXPos, nYStart), aText );
969 nBulletWidth = pVDev->GetTextWidth(aText);
970 nPreNum++;
971 }
972 if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT &&
973 rFormat.GetLabelFollowedBy() == SvxNumberFormat::SPACE )
974 {
975 pVDev->SetFont(aStdFont);
976 OUString aText(' ');
977 pVDev->DrawText( Point(nNumberXPos, nYStart), aText );
978 nBulletWidth += pVDev->GetTextWidth(aText);
979 }
980
981 long nTextXPos(0);
982 if (rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION)
983 {
984 nTextXPos = nXStart;
985 if (nTextOffset < 0)
986 nTextXPos = nTextXPos + nTextOffset;
987 if (nNumberXPos + nBulletWidth + nTextOffset > nTextXPos)
988 nTextXPos = nNumberXPos + nBulletWidth + nTextOffset;
989 }
990 else if (rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT)
991 {
992 switch (rFormat.GetLabelFollowedBy())
993 {
994 case SvxNumberFormat::LISTTAB:
995 {
996 nTextXPos = rFormat.GetListtabPos() / nWidthRelation;
997 if (nTextXPos < nNumberXPos + nBulletWidth)
998 {
999 nTextXPos = nNumberXPos + nBulletWidth;
1000 }
1001 }
1002 break;
1003 case SvxNumberFormat::SPACE:
1004 case SvxNumberFormat::NOTHING:
1005 case SvxNumberFormat::NEWLINE:
1006 {
1007 nTextXPos = nNumberXPos + nBulletWidth;
1008 }
1009 break;
1010 }
1011
1012 nXStart = rFormat.GetIndentAt() / nWidthRelation;
1013 }
1014
1015 tools::Rectangle aRect1(Point(nTextXPos, nYStart + nFontHeight / 2), Size(aSize.Width() / 2, 2));
1016 pVDev->SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetWindowColor()); // COL_BLACK );
1017 pVDev->DrawRect(aRect1);
1018
1019 tools::Rectangle aRect2(Point(nXStart, nYStart + nLineHeight + nFontHeight / 2), Size(aSize.Width() / 2, 2));
1020 pVDev->DrawRect(aRect2);
1021 nYStart += 2 * nLineHeight;
1022 }
1023 }
1024 else
1025 {
1026 SwNumberTree::tNumberVector aNumVector;
1027 const long nLineHeight = nFontHeight * 3 / 2;
1028 for (sal_uInt8 nLevel = 0; nLevel < MAXLEVEL; ++nLevel, nYStart = nYStart + nYStep)
1029 {
1030 const SwNumFormat &rFormat = pActNum->Get(nLevel);
1031 aNumVector.push_back(rFormat.GetStart());
1032 long nXStart(0);
1033 if (rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION)
1034 {
1035 nXStart = rFormat.GetAbsLSpace() / nWidthRelation;
1036 }
1037 else if (rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT)
1038 {
1039 const long nTmpXStart((rFormat.GetIndentAt() + rFormat.GetFirstLineIndent() ) / nWidthRelation);
1040 nXStart = (nTmpXStart < 0) ? 0 : nTmpXStart;
1041 }
1042 nXStart /= 2;
1043 nXStart += 2;
1044 long nTextOffset;
1045 if (SVX_NUM_BITMAP == rFormat.GetNumberingType())
1046 {
1047 lcl_DrawGraphic(pVDev.get(), rFormat, nXStart, nYStart, nWidthRelation);
1048 nTextOffset = nLineHeight + nXStep;
1049 }
1050 else if (SVX_NUM_CHAR_SPECIAL == rFormat.GetNumberingType())
1051 {
1052 nTextOffset = lcl_DrawBullet(pVDev.get(), rFormat, nXStart, nYStart, aStdFont.GetFontSize());
1053 nTextOffset += nXStep;
1054 }
1055 else
1056 {
1057 pVDev->SetFont(aStdFont);
1058 if (pActNum->IsContinusNum())
1059 aNumVector[nLevel] = nPreNum;
1060 OUString aText(pActNum->MakeNumString( aNumVector ));
1061 pVDev->DrawText( Point(nXStart, nYStart), aText );
1062 nTextOffset = pVDev->GetTextWidth(aText) + nXStep;
1063 nPreNum++;
1064 }
1065 pVDev->SetFont(aStdFont);
1066 pVDev->DrawText(
1067 Point(nXStart + nTextOffset, nYStart),
1068 (pOutlineNames == nullptr
1069 ? utl::ConfigManager::getProductName()
1070 : pOutlineNames[nLevel]));
1071 }
1072 }
1073 }
1074 rRenderContext.DrawOutDev(Point(0,0), aSize, Point(0,0), aSize, *pVDev);
1075}
1076
1077/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/tools/gen.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_TOOLS_GEN_HXX
20#define INCLUDED_TOOLS_GEN_HXX
21
22#include <tools/toolsdllapi.h>
23
24#include <limits.h>
25#include <algorithm>
26#include <ostream>
27#include <config_options.h>
28
29class SvStream;
30namespace rtl
31{
32 class OString;
33}
34
35enum TriState { TRISTATE_FALSE, TRISTATE_TRUE, TRISTATE_INDET };
36
37// Pair
38
39class SAL_WARN_UNUSED__attribute__((warn_unused)) Pair
40{
41public:
42 Pair() : nA(0), nB(0) {}
43 Pair( long _nA, long _nB ) : nA(_nA), nB(_nB) {}
44
45 long A() const { return nA; }
46 long B() const { return nB; }
47
48 long& A() { return nA; }
49 long& B() { return nB; }
50
51 TOOLS_DLLPUBLIC__attribute__ ((visibility("default"))) rtl::OString toString() const;
52
53protected:
54 long nA;
55 long nB;
56};
57
58namespace tools::detail {
59
60// Used to implement operator == for subclasses of Pair:
61inline bool equal(Pair const & p1, Pair const & p2)
62{
63 return p1.A() == p2.A() && p1.B() == p2.B();
64}
65
66}
67
68// Point
69
70class Size;
71class SAL_WARN_UNUSED__attribute__((warn_unused)) UNLESS_MERGELIBS(SAL_DLLPUBLIC_EXPORT)__attribute__ ((visibility("default"))) Point final : protected Pair
72{
73public:
74 Point() {}
75 Point( long nX, long nY ) : Pair( nX, nY ) {}
76
77 long X() const { return nA; }
78 long Y() const { return nB; }
79
80 void Move( long nHorzMove, long nVertMove );
81 void Move( Size const & s );
82 long AdjustX( long nHorzMove ) { nA += nHorzMove; return nA; }
83 long AdjustY( long nVertMove ) { nB += nVertMove; return nB; }
84
85 void RotateAround( long& rX, long& rY, short nOrientation ) const;
86 void RotateAround( Point&, short nOrientation ) const;
87
88 Point& operator += ( const Point& rPoint );
89 Point& operator -= ( const Point& rPoint );
90 Point& operator *= ( const long nVal );
91 Point& operator /= ( const long nVal );
92
93 friend inline Point operator+( const Point &rVal1, const Point &rVal2 );
94 friend inline Point operator-( const Point &rVal1, const Point &rVal2 );
95 friend inline Point operator*( const Point &rVal1, const long nVal2 );
96 friend inline Point operator/( const Point &rVal1, const long nVal2 );
97
98 long getX() const { return X(); }
99 long getY() const { return Y(); }
100 void setX(long nX) { nA = nX; }
101 void setY(long nY) { nB = nY; }
102
103 Pair const & toPair() const { return *this; }
104 Pair & toPair() { return *this; }
105
106 using Pair::toString;
107};
108
109inline void Point::Move( long nHorzMove, long nVertMove )
110{
111 nA += nHorzMove;
112 nB += nVertMove;
113}
114
115inline Point& Point::operator += ( const Point& rPoint )
116{
117 nA += rPoint.nA;
118 nB += rPoint.nB;
119 return *this;
120}
121
122inline Point& Point::operator -= ( const Point& rPoint )
123{
124 nA -= rPoint.nA;
125 nB -= rPoint.nB;
126 return *this;
127}
128
129inline Point& Point::operator *= ( const long nVal )
130{
131 nA *= nVal;
132 nB *= nVal;
133 return *this;
134}
135
136inline Point& Point::operator /= ( const long nVal )
137{
138 nA /= nVal;
139 nB /= nVal;
140 return *this;
141}
142
143inline Point operator+( const Point &rVal1, const Point &rVal2 )
144{
145 return Point( rVal1.nA+rVal2.nA, rVal1.nB+rVal2.nB );
146}
147
148inline Point operator-( const Point &rVal1, const Point &rVal2 )
149{
150 return Point( rVal1.nA-rVal2.nA, rVal1.nB-rVal2.nB );
151}
152
153inline Point operator*( const Point &rVal1, const long nVal2 )
154{
155 return Point( rVal1.nA*nVal2, rVal1.nB*nVal2 );
156}
157
158inline Point operator/( const Point &rVal1, const long nVal2 )
159{
160 return Point( rVal1.nA/nVal2, rVal1.nB/nVal2 );
161}
162
163inline bool operator ==(Point const & p1, Point const & p2)
164{
165 return tools::detail::equal(p1.toPair(), p2.toPair());
166}
167
168inline bool operator !=(Point const & p1, Point const & p2)
169{
170 return !(p1 == p2);
171}
172
173template< typename charT, typename traits >
174inline std::basic_ostream<charT, traits> & operator <<(
175 std::basic_ostream<charT, traits> & stream, const Point& point )
176{
177 return stream << point.X() << ',' << point.Y();
178}
179
180// Size
181
182class SAL_WARN_UNUSED__attribute__((warn_unused)) Size final : protected Pair
183{
184public:
185 Size() {}
186 Size( long nWidth, long nHeight ) : Pair( nWidth, nHeight ) {}
187
188 long Width() const { return nA; }
7
Returning zero
189 long Height() const { return nB; }
190
191 long AdjustWidth( long n ) { nA += n; return nA; }
192 long AdjustHeight( long n ) { nB += n; return nB; }
193
194 long getWidth() const { return Width(); }
195 long getHeight() const { return Height(); }
196 void setWidth(long nWidth) { nA = nWidth; }
197 void setHeight(long nHeight) { nB = nHeight; }
198
199 bool IsEmpty() const { return nA <= 0 || nB <= 0; }
200
201 void extendBy(long x, long y)
202 {
203 nA += x;
204 nB += y;
205 }
206
207 Pair const & toPair() const { return *this; }
208 Pair & toPair() { return *this; }
209
210 using Pair::toString;
211};
212
213inline bool operator ==(Size const & s1, Size const & s2)
214{
215 return tools::detail::equal(s1.toPair(), s2.toPair());
216}
217
218inline bool operator !=(Size const & s1, Size const & s2)
219{
220 return !(s1 == s2);
221}
222
223template< typename charT, typename traits >
224inline std::basic_ostream<charT, traits> & operator <<(
225 std::basic_ostream<charT, traits> & stream, const Size& size )
226{
227 return stream << size.Width() << 'x' << size.Height();
228}
229
230inline void Point::Move( Size const & s )
231{
232 AdjustX(s.Width());
233 AdjustY(s.Height());
234}
235
236// Range
237
238#define RANGE_MAX9223372036854775807L LONG_MAX9223372036854775807L
239
240class SAL_WARN_UNUSED__attribute__((warn_unused)) Range final : protected Pair
241{
242public:
243 Range() {}
244 Range( long nMin, long nMax ) : Pair( nMin, nMax ) {}
245
246 long Min() const { return nA; }
247 long Max() const { return nB; }
248 long Len() const { return nB - nA + 1; }
249
250 long& Min() { return nA; }
251 long& Max() { return nB; }
252
253 bool IsInside( long nIs ) const;
254
255 void Justify();
256
257 Pair const & toPair() const { return *this; }
258 Pair & toPair() { return *this; }
259
260 using Pair::toString;
261};
262
263inline bool Range::IsInside( long nIs ) const
264{
265 return ((nA <= nIs) && (nIs <= nB ));
266}
267
268inline void Range::Justify()
269{
270 if ( nA > nB )
271 {
272 long nHelp = nA;
273 nA = nB;
274 nB = nHelp;
275 }
276}
277
278inline bool operator ==(Range const & r1, Range const & r2)
279{
280 return tools::detail::equal(r1.toPair(), r2.toPair());
281}
282
283inline bool operator !=(Range const & r1, Range const & r2)
284{
285 return !(r1 == r2);
286}
287
288template< typename charT, typename traits >
289inline std::basic_ostream<charT, traits> & operator <<(
290 std::basic_ostream<charT, traits> & stream, const Range& range )
291{
292 return stream << range.Min() << '-' << range.Max();
293}
294
295// Selection
296
297#define SELECTION_MIN(-9223372036854775807L -1L) LONG_MIN(-9223372036854775807L -1L)
298#define SELECTION_MAX9223372036854775807L LONG_MAX9223372036854775807L
299
300class SAL_WARN_UNUSED__attribute__((warn_unused)) Selection final : protected Pair
301{
302public:
303 Selection() {}
304 Selection( long nPos ) : Pair( nPos, nPos ) {}
305 Selection( long nMin, long nMax ) : Pair( nMin, nMax ) {}
306
307 long Min() const { return nA; }
308 long Max() const { return nB; }
309 long Len() const { return nB - nA; }
310
311 long& Min() { return nA; }
312 long& Max() { return nB; }
313
314 bool IsInside( long nIs ) const;
315
316 void Justify();
317
318 bool operator !() const { return !Len(); }
319
320 long getMin() const { return Min(); }
321 void setMin(long nMin) { Min() = nMin; }
322 void setMax(long nMax) { Max() = nMax; }
323
324 Pair const & toPair() const { return *this; }
325 Pair & toPair() { return *this; }
326
327 using Pair::toString;
328};
329
330inline bool Selection::IsInside( long nIs ) const
331{
332 return ((nA <= nIs) && (nIs < nB ));
333}
334
335inline void Selection::Justify()
336{
337 if ( nA > nB )
338 {
339 long nHelp = nA;
340 nA = nB;
341 nB = nHelp;
342 }
343}
344
345inline bool operator ==(Selection const & s1, Selection const & s2)
346{
347 return tools::detail::equal(s1.toPair(), s2.toPair());
348}
349
350inline bool operator !=(Selection const & s1, Selection const & s2)
351{
352 return !(s1 == s2);
353}
354
355template< typename charT, typename traits >
356inline std::basic_ostream<charT, traits> & operator <<(
357 std::basic_ostream<charT, traits> & stream, const Selection& selection )
358{
359 return stream << selection.Min() << '-' << selection.Max();
360}
361// Rectangle
362
363#define RECT_MAX9223372036854775807L LONG_MAX9223372036854775807L
364#define RECT_MIN(-9223372036854775807L -1L) LONG_MIN(-9223372036854775807L -1L)
365
366/// Note: this class is a true marvel of engineering: because the author
367/// could not decide whether it's better to have a closed or half-open
368/// interval, they just implemented *both* in the same class!
369///
370/// If you have the misfortune of having to use this class, don't immediately
371/// despair but first take note that the uppercase GetWidth() / GetHeight()
372/// etc. methods interpret the interval as closed, while the lowercase
373/// getWidth() / getHeight() etc. methods interpret the interval as half-open.
374/// Ok, now is the time for despair.
375namespace tools
376{
377class SAL_WARN_UNUSED__attribute__((warn_unused)) TOOLS_DLLPUBLIC__attribute__ ((visibility("default"))) Rectangle final
378{
379 static constexpr short RECT_EMPTY = -32767;
380public:
381 Rectangle();
382 Rectangle( const Point& rLT, const Point& rRB );
383 Rectangle( long nLeft, long nTop,
384 long nRight, long nBottom );
385 /// Constructs an empty Rectangle, with top/left at the specified params
386 Rectangle( long nLeft, long nTop );
387 Rectangle( const Point& rLT, const Size& rSize );
388
389 static Rectangle Justify( const Point& rLT, const Point& rRB );
390
391 long Left() const { return nLeft; }
392 long Right() const;
393 long Top() const { return nTop; }
394 long Bottom() const;
395
396 void SetLeft(long v) { nLeft = v; }
397 void SetRight(long v) { nRight = v; }
398 void SetTop(long v) { nTop = v; }
399 void SetBottom(long v) { nBottom = v; }
400
401 inline Point TopLeft() const;
402 inline Point TopRight() const;
403 inline Point TopCenter() const;
404 inline Point BottomLeft() const;
405 inline Point BottomRight() const;
406 inline Point BottomCenter() const;
407 inline Point LeftCenter() const;
408 inline Point RightCenter() const;
409 inline Point Center() const;
410
411 /// Move the top and left edges by a delta, preserving width and height
412 inline void Move( long nHorzMoveDelta, long nVertMoveDelta );
413 void Move( Size const & s ) { Move(s.Width(), s.Height()); }
414 long AdjustLeft( long nHorzMoveDelta ) { nLeft += nHorzMoveDelta; return nLeft; }
415 long AdjustRight( long nHorzMoveDelta );
416 long AdjustTop( long nVertMoveDelta ) { nTop += nVertMoveDelta; return nTop; }
417 long AdjustBottom( long nVertMoveDelta );
418 inline void SetPos( const Point& rPoint );
419 void SetSize( const Size& rSize );
420 inline Size GetSize() const;
421
422 /// Returns the difference between right and left, assuming the range is inclusive.
423 inline long GetWidth() const;
424 /// Returns the difference between bottom and top, assuming the range is inclusive.
425 inline long GetHeight() const;
426
427 tools::Rectangle& Union( const tools::Rectangle& rRect );
428 tools::Rectangle& Intersection( const tools::Rectangle& rRect );
429 inline tools::Rectangle GetUnion( const tools::Rectangle& rRect ) const;
430 inline tools::Rectangle GetIntersection( const tools::Rectangle& rRect ) const;
431
432 void Justify();
433
434 bool IsInside( const Point& rPOINT ) const;
435 bool IsInside( const tools::Rectangle& rRect ) const;
436 bool IsOver( const tools::Rectangle& rRect ) const;
437
438 void SetEmpty() { nRight = nBottom = RECT_EMPTY; }
439 void SetWidthEmpty() { nRight = RECT_EMPTY; }
440 void SetHeightEmpty() { nBottom = RECT_EMPTY; }
441 inline bool IsEmpty() const;
442 bool IsWidthEmpty() const { return nRight == RECT_EMPTY; }
443 bool IsHeightEmpty() const { return nBottom == RECT_EMPTY; }
444
445 inline bool operator == ( const tools::Rectangle& rRect ) const;
446 inline bool operator != ( const tools::Rectangle& rRect ) const;
447
448 inline tools::Rectangle& operator += ( const Point& rPt );
449 inline tools::Rectangle& operator -= ( const Point& rPt );
450
451 friend inline tools::Rectangle operator + ( const tools::Rectangle& rRect, const Point& rPt );
452 friend inline tools::Rectangle operator - ( const tools::Rectangle& rRect, const Point& rPt );
453
454 // ONE
455 long getX() const { return nLeft; }
456 long getY() const { return nTop; }
457 /// Returns the difference between right and left, assuming the range includes one end, but not the other.
458 long getWidth() const;
459 /// Returns the difference between bottom and top, assuming the range includes one end, but not the other.
460 long getHeight() const;
461 /// Set the left edge of the rectangle to x, preserving the width
462 void setX( long x );
463 /// Set the top edge of the rectangle to y, preserving the height
464 void setY( long y );
465 void setWidth( long n ) { nRight = nLeft + n; }
466 void setHeight( long n ) { nBottom = nTop + n; }
467 /// Returns the string representation of the rectangle, format is "x, y, width, height".
468 rtl::OString toString() const;
469
470 /**
471 * Expands the rectangle in all directions by the input value.
472 */
473 void expand(long nExpandBy);
474 void shrink(long nShrinkBy);
475
476 /**
477 * Sanitizing variants for handling data from the outside
478 */
479 void SaturatingSetSize(const Size& rSize);
480 void SaturatingSetX(long x);
481 void SaturatingSetY(long y);
482
483private:
484 long nLeft;
485 long nTop;
486 long nRight;
487 long nBottom;
488};
489}
490
491inline tools::Rectangle::Rectangle()
492{
493 nLeft = nTop = 0;
494 nRight = nBottom = RECT_EMPTY;
495}
496
497inline tools::Rectangle::Rectangle( const Point& rLT, const Point& rRB )
498{
499 nLeft = rLT.X();
500 nTop = rLT.Y();
501 nRight = rRB.X();
502 nBottom = rRB.Y();
503}
504
505inline tools::Rectangle::Rectangle( long _nLeft, long _nTop,
506 long _nRight, long _nBottom )
507{
508 nLeft = _nLeft;
509 nTop = _nTop;
510 nRight = _nRight;
511 nBottom = _nBottom;
512}
513
514inline tools::Rectangle::Rectangle( long _nLeft, long _nTop )
515{
516 nLeft = _nLeft;
517 nTop = _nTop;
518 nRight = nBottom = RECT_EMPTY;
519}
520
521inline tools::Rectangle::Rectangle( const Point& rLT, const Size& rSize )
522{
523 nLeft = rLT.X();
524 nTop = rLT.Y();
525 nRight = rSize.Width() ? nLeft+(rSize.Width()-1) : RECT_EMPTY;
526 nBottom = rSize.Height() ? nTop+(rSize.Height()-1) : RECT_EMPTY;
527}
528
529inline bool tools::Rectangle::IsEmpty() const
530{
531 return (nRight == RECT_EMPTY) || (nBottom == RECT_EMPTY);
532}
533
534inline Point tools::Rectangle::TopLeft() const
535{
536 return Point( nLeft, nTop );
537}
538
539inline Point tools::Rectangle::TopRight() const
540{
541 return Point( (nRight == RECT_EMPTY) ? nLeft : nRight, nTop );
542}
543
544inline Point tools::Rectangle::BottomLeft() const
545{
546 return Point( nLeft, (nBottom == RECT_EMPTY) ? nTop : nBottom );
547}
548
549inline Point tools::Rectangle::BottomRight() const
550{
551 return Point( (nRight == RECT_EMPTY) ? nLeft : nRight,
552 (nBottom == RECT_EMPTY) ? nTop : nBottom );
553}
554
555inline Point tools::Rectangle::TopCenter() const
556{
557 if ( IsEmpty() )
558 return Point( nLeft, nTop );
559 else
560 return Point( std::min( nLeft, nRight ) + std::abs( (nRight - nLeft)/2 ),
561 std::min( nTop, nBottom) );
562}
563
564inline Point tools::Rectangle::BottomCenter() const
565{
566 if ( IsEmpty() )
567 return Point( nLeft, nTop );
568 else
569 return Point( std::min( nLeft, nRight ) + std::abs( (nRight - nLeft)/2 ),
570 std::max( nTop, nBottom) );
571}
572
573inline Point tools::Rectangle::LeftCenter() const
574{
575 if ( IsEmpty() )
576 return Point( nLeft, nTop );
577 else
578 return Point( std::min( nLeft, nRight ), nTop + (nBottom - nTop)/2 );
579}
580
581inline Point tools::Rectangle::RightCenter() const
582{
583 if ( IsEmpty() )
584 return Point( nLeft, nTop );
585 else
586 return Point( std::max( nLeft, nRight ), nTop + (nBottom - nTop)/2 );
587}
588
589inline Point tools::Rectangle::Center() const
590{
591 if ( IsEmpty() )
592 return Point( nLeft, nTop );
593 else
594 return Point( nLeft+(nRight-nLeft)/2 , nTop+(nBottom-nTop)/2 );
595}
596
597inline void tools::Rectangle::Move( long nHorzMove, long nVertMove )
598{
599 nLeft += nHorzMove;
600 nTop += nVertMove;
601 if ( nRight != RECT_EMPTY )
602 nRight += nHorzMove;
603 if ( nBottom != RECT_EMPTY )
604 nBottom += nVertMove;
605}
606
607inline void tools::Rectangle::SetPos( const Point& rPoint )
608{
609 if ( nRight != RECT_EMPTY )
610 nRight += rPoint.X() - nLeft;
611 if ( nBottom != RECT_EMPTY )
612 nBottom += rPoint.Y() - nTop;
613 nLeft = rPoint.X();
614 nTop = rPoint.Y();
615}
616
617inline long tools::Rectangle::GetWidth() const
618{
619 long n;
620 if ( nRight == RECT_EMPTY )
621 n = 0;
622 else
623 {
624 n = nRight - nLeft;
625 if( n < 0 )
626 n--;
627 else
628 n++;
629 }
630
631 return n;
632}
633
634inline long tools::Rectangle::GetHeight() const
635{
636 long n;
637 if ( nBottom == RECT_EMPTY )
638 n = 0;
639 else
640 {
641 n = nBottom - nTop;
642 if ( n < 0 )
643 n--;
644 else
645 n++;
646 }
647
648 return n;
649}
650
651inline Size tools::Rectangle::GetSize() const
652{
653 return Size( GetWidth(), GetHeight() );
654}
655
656inline tools::Rectangle tools::Rectangle::GetUnion( const tools::Rectangle& rRect ) const
657{
658 tools::Rectangle aTmpRect( *this );
659 return aTmpRect.Union( rRect );
660}
661
662inline tools::Rectangle tools::Rectangle::GetIntersection( const tools::Rectangle& rRect ) const
663{
664 tools::Rectangle aTmpRect( *this );
665 return aTmpRect.Intersection( rRect );
666}
667
668inline bool tools::Rectangle::operator == ( const tools::Rectangle& rRect ) const
669{
670 return (nLeft == rRect.nLeft ) &&
671 (nTop == rRect.nTop ) &&
672 (nRight == rRect.nRight ) &&
673 (nBottom == rRect.nBottom );
674}
675
676inline bool tools::Rectangle::operator != ( const tools::Rectangle& rRect ) const
677{
678 return (nLeft != rRect.nLeft ) ||
679 (nTop != rRect.nTop ) ||
680 (nRight != rRect.nRight ) ||
681 (nBottom != rRect.nBottom );
682}
683
684inline tools::Rectangle& tools::Rectangle::operator +=( const Point& rPt )
685{
686 nLeft += rPt.X();
687 nTop += rPt.Y();
688 if ( nRight != RECT_EMPTY )
689 nRight += rPt.X();
690 if ( nBottom != RECT_EMPTY )
691 nBottom += rPt.Y();
692 return *this;
693}
694
695inline tools::Rectangle& tools::Rectangle::operator -= ( const Point& rPt )
696{
697 nLeft -= rPt.X();
698 nTop -= rPt.Y();
699 if ( nRight != RECT_EMPTY )
700 nRight -= rPt.X();
701 if ( nBottom != RECT_EMPTY )
702 nBottom -= rPt.Y();
703 return *this;
704}
705
706namespace tools
707{
708inline Rectangle operator + ( const Rectangle& rRect, const Point& rPt )
709{
710 return rRect.IsEmpty()
711 ? Rectangle( rRect.nLeft + rPt.X(), rRect.nTop + rPt.Y() )
712 : Rectangle( rRect.nLeft + rPt.X(), rRect.nTop + rPt.Y(),
713 rRect.nRight + rPt.X(), rRect.nBottom + rPt.Y() );
714}
715
716inline Rectangle operator - ( const Rectangle& rRect, const Point& rPt )
717{
718 return rRect.IsEmpty()
719 ? Rectangle( rRect.nLeft - rPt.X(), rRect.nTop - rPt.Y() )
720 : Rectangle( rRect.nLeft - rPt.X(), rRect.nTop - rPt.Y(),
721 rRect.nRight - rPt.X(), rRect.nBottom - rPt.Y() );
722}
723}
724
725template< typename charT, typename traits >
726inline std::basic_ostream<charT, traits> & operator <<(
727 std::basic_ostream<charT, traits> & stream, const tools::Rectangle& rectangle )
728{
729 if (rectangle.IsEmpty())
730 return stream << "EMPTY";
731 else
732 return stream << rectangle.getWidth() << 'x' << rectangle.getHeight()
733 << "@(" << rectangle.getX() << ',' << rectangle.getY() << ")";
734}
735
736#endif
737
738/* vim:set shiftwidth=4 softtabstop=4 expandtab: */