Bug Summary

File:home/maarten/src/libreoffice/core/sd/source/ui/view/drtxtob.cxx
Warning:line 260, column 29
Called C++ object pointer is null

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 drtxtob.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 -isystem /usr/include/dbus-1.0 -isystem /usr/lib64/dbus-1.0/include -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 SD_DLLIMPLEMENTATION -D SDUI_DLL_NAME="libsduilo.so" -D SYSTEM_LIBXML -D ENABLE_SDREMOTE -D ENABLE_SDREMOTE_BLUETOOTH -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/external/bluez_bluetooth/inc -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/sd/inc -I /home/maarten/src/libreoffice/core/sd/source/ui/inc -I /home/maarten/src/libreoffice/core/sd/source/ui/slidesorter/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sd/sdi -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/oox/generated -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -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/sd/source/ui/view/drtxtob.cxx

/home/maarten/src/libreoffice/core/sd/source/ui/view/drtxtob.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 <TextObjectBar.hxx>
21
22#include <svx/svxids.hrc>
23
24#include <com/sun/star/linguistic2/XThesaurus.hpp>
25
26#include <editeng/eeitem.hxx>
27#include <editeng/udlnitem.hxx>
28#include <editeng/ulspitem.hxx>
29#include <editeng/lspcitem.hxx>
30#include <editeng/adjustitem.hxx>
31#include <editeng/editview.hxx>
32#include <editeng/outliner.hxx>
33#include <editeng/unolingu.hxx>
34#include <editeng/kernitem.hxx>
35#include <svl/whiter.hxx>
36#include <svl/itempool.hxx>
37#include <svl/stritem.hxx>
38#include <svl/style.hxx>
39#include <svl/languageoptions.hxx>
40#include <sfx2/tplpitem.hxx>
41#include <editeng/escapementitem.hxx>
42#include <svx/svdoutl.hxx>
43#include <editeng/scripttypeitem.hxx>
44#include <editeng/writingmodeitem.hxx>
45#include <editeng/frmdiritem.hxx>
46#include <editeng/fhgtitem.hxx>
47#include <comphelper/lok.hxx>
48
49#include <sfx2/objface.hxx>
50
51#include <drawdoc.hxx>
52#include <DrawDocShell.hxx>
53#include <DrawViewShell.hxx>
54#include <OutlineViewShell.hxx>
55#include <Window.hxx>
56#include <OutlineView.hxx>
57
58using namespace sd;
59using namespace ::com::sun::star;
60
61#define ShellClass_TextObjectBar
62#include <sdslots.hxx>
63
64namespace sd {
65
66/**
67 * Declare default interface (Slotmap must not be empty, therefore enter
68 * something that (hopefully) never occurs.
69 */
70SFX_IMPL_INTERFACE(TextObjectBar, SfxShell)SfxInterface* TextObjectBar::pInterface = nullptr; SfxInterface
* TextObjectBar::GetStaticInterface() { if ( !pInterface ) { pInterface
= new SfxInterface( "TextObjectBar", false, GetInterfaceId()
, SfxShell::GetStaticInterface(), aTextObjectBarSlots_Impl[0]
, sal_uInt16(sizeof(aTextObjectBarSlots_Impl) / sizeof(SfxSlot
) ) ); InitInterface_Impl(); } return pInterface; } SfxInterface
* TextObjectBar::GetInterface() const { return GetStaticInterface
(); } void TextObjectBar::RegisterInterface(const SfxModule* pMod
) { GetStaticInterface()->Register(pMod); }
71
72void TextObjectBar::InitInterface_Impl()
73{
74}
75
76
77TextObjectBar::TextObjectBar (
78 ViewShell* pSdViewSh,
79 SfxItemPool& rItemPool,
80 ::sd::View* pSdView )
81 : SfxShell(pSdViewSh->GetViewShell()),
82 mpViewShell( pSdViewSh ),
83 mpView( pSdView )
84{
85 SetPool(&rItemPool);
86
87 if( mpView )
88 {
89 OutlineView* pOutlinerView = dynamic_cast< OutlineView* >( mpView );
90 if( pOutlinerView )
91 {
92 SetUndoManager(&pOutlinerView->GetOutliner().GetUndoManager());
93 }
94 else
95 {
96 DrawDocShell* pDocShell = mpView->GetDoc().GetDocSh();
97 if( pDocShell )
98 {
99 SetUndoManager(pDocShell->GetUndoManager());
100 DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >( pSdViewSh );
101 if ( pDrawViewShell )
102 SetRepeatTarget(pSdView);
103 }
104 }
105 }
106
107 SetName( "TextObjectBar");
108
109 // SetHelpId( SD_IF_SDDRAWTEXTOBJECTBAR );
110}
111
112TextObjectBar::~TextObjectBar()
113{
114 SetRepeatTarget(nullptr);
115}
116
117void TextObjectBar::GetCharState( SfxItemSet& rSet )
118{
119 SfxItemSet aCharAttrSet( mpView->GetDoc().GetPool() );
120 mpView->GetAttributes( aCharAttrSet );
121
122 SfxItemSet aNewAttr( mpViewShell->GetPool(),svl::Items<EE_ITEMS_START,EE_ITEMS_END>{});
123
124 aNewAttr.Put(aCharAttrSet, false);
125 rSet.Put(aNewAttr, false);
126
127 SvxKerningItem aKern = aCharAttrSet.Get( EE_CHAR_KERNING );
128 //aKern.SetWhich(SID_ATTR_CHAR_KERNING);
129 rSet.Put(aKern);
130
131 SfxItemState eState = aCharAttrSet.GetItemState( EE_CHAR_KERNING );
132 if ( eState == SfxItemState::DONTCARE )
133 {
134 rSet.InvalidateItem(EE_CHAR_KERNING);
135 }
136}
137
138/**
139 * Status of attribute items.
140 */
141void TextObjectBar::GetAttrState( SfxItemSet& rSet )
142{
143 SfxWhichIter aIter( rSet );
144 sal_uInt16 nWhich = aIter.FirstWhich();
145 SfxItemSet aAttrSet( mpView->GetDoc().GetPool() );
146 SvtLanguageOptions aLangOpt;
147 bool bDisableParagraphTextDirection = !aLangOpt.IsCTLFontEnabled();
1
Assuming the condition is false
148 bool bDisableVerticalText = !aLangOpt.IsVerticalTextEnabled();
2
Assuming the condition is false
149
150 mpView->GetAttributes( aAttrSet );
151
152 while ( nWhich )
3
Loop condition is true. Entering loop body
153 {
154 sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich)
4
Calling 'SfxItemPool::IsWhich'
6
Returning from 'SfxItemPool::IsWhich'
7
'?' condition is false
155 ? GetPool().GetSlotId(nWhich)
156 : nWhich;
157
158 switch ( nSlotId )
8
Control jumps to 'case 10151:' at line 242
159 {
160 case SID_ATTR_CHAR_FONT( 10000 + 7 ):
161 case SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ):
162 case SID_ATTR_CHAR_WEIGHT( 10000 + 9 ):
163 case SID_ATTR_CHAR_POSTURE( 10000 + 8 ):
164 case SID_ATTR_CHAR_SHADOWED( 10000 + 10 ):
165 case SID_ATTR_CHAR_STRIKEOUT( 10000 + 13 ):
166 case SID_ATTR_CHAR_CASEMAP( 10000 + 19 ):
167 {
168 sal_uInt16 stretchX = 100;
169 SvxScriptSetItem aSetItem( nSlotId, GetPool() );
170 aSetItem.GetItemSet().Put( aAttrSet, false );
171
172 SvtScriptType nScriptType = mpView->GetScriptType();
173
174 if( (nSlotId == SID_ATTR_CHAR_FONT( 10000 + 7 )) || (nSlotId == SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 )) )
175 {
176 // input language should be preferred over
177 // current cursor position to detect script type
178 OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
179 SdrOutliner *pOutliner = mpView->GetTextEditOutliner();
180
181 assert(mpViewShell)(static_cast <bool> (mpViewShell) ? void (0) : __assert_fail
("mpViewShell", "/home/maarten/src/libreoffice/core/sd/source/ui/view/drtxtob.cxx"
, 181, __extension__ __PRETTY_FUNCTION__))
;
182
183 if( dynamic_cast< const OutlineView *>( mpView ) != nullptr)
184 {
185 pOLV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
186 mpViewShell->GetActiveWindow());
187 }
188
189 sal_uInt16 stretchY = 100;
190 if( pOutliner )
191 pOutliner->GetGlobalCharStretching( stretchX, stretchY );
192
193 if(pOLV && !pOLV->GetSelection().HasRange())
194 {
195 if (mpViewShell->GetViewShell() && mpViewShell->GetViewShell()->GetWindow())
196 {
197 LanguageType nInputLang = mpViewShell->GetViewShell()->GetWindow()->GetInputLanguage();
198 if(nInputLang != LANGUAGE_DONTKNOWLanguageType(0x03FF) && nInputLang != LANGUAGE_SYSTEMLanguageType(0x0000))
199 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
200 }
201 }
202 }
203
204 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
205 if( pI )
206 {
207 if( nSlotId == SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ) )
208 {
209 SvxFontHeightItem aFontItem = dynamic_cast<const SvxFontHeightItem&>(*pI);
210 aFontItem.SetHeight(aFontItem.GetHeight(), stretchX, aFontItem.GetPropUnit());
211 aFontItem.SetWhich(nWhich);
212 aAttrSet.Put( aFontItem );
213 }
214 else
215 {
216 aAttrSet.Put( pI->CloneSetWhich(nWhich) );
217 }
218 }
219 else
220 {
221 aAttrSet.InvalidateItem( nWhich );
222 }
223 }
224 break;
225
226 case SID_STYLE_APPLY(5000 + 552):
227 case SID_STYLE_FAMILY2((5000 + 541) + 1):
228 {
229 SfxStyleSheet* pStyleSheet = mpView->GetStyleSheetFromMarked();
230 if( pStyleSheet )
231 rSet.Put( SfxTemplateItem( nWhich, pStyleSheet->GetName() ) );
232 else
233 {
234 rSet.Put( SfxTemplateItem( nWhich, OUString() ) );
235 }
236 }
237 break;
238
239 case SID_OUTLINE_LEFT( 10000 + 152 ):
240 case SID_OUTLINE_RIGHT( 10000 + 153 ):
241 case SID_OUTLINE_UP( 10000 + 150 ):
242 case SID_OUTLINE_DOWN( 10000 + 151 ):
243 {
244 bool bDisableLeft = true;
245 bool bDisableRight = true;
246 bool bDisableUp = true;
247 bool bDisableDown = true;
248
249 //fdo#78151 it doesn't make sense to promote or demote outline levels in master view.
250 const DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >(mpViewShell);
251 const bool bInMasterView = pDrawViewShell && pDrawViewShell->GetEditMode() == EditMode::MasterPage;
9
Assuming 'pDrawViewShell' is null
252
253 if (!bInMasterView
9.1
'bInMasterView' is false
9.1
'bInMasterView' is false
)
10
Taking true branch
254 {
255 OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
256
257 if( dynamic_cast< const OutlineView *>( mpView ) != nullptr)
11
Taking true branch
258 {
259 pOLV = static_cast<OutlineView*>(mpView)->GetViewByWindow(
260 mpViewShell->GetActiveWindow());
12
Called C++ object pointer is null
261 }
262
263 bool bOutlineViewSh = dynamic_cast< const OutlineViewShell *>( mpViewShell ) != nullptr;
264
265 if (pOLV)
266 {
267 // Outliner at outline-mode
268 ::Outliner* pOutl = pOLV->GetOutliner();
269
270 std::vector<Paragraph*> aSelList;
271 pOLV->CreateSelectionList(aSelList);
272 Paragraph* pPara = aSelList.empty() ? nullptr : *(aSelList.begin());
273
274 // find out if we are an OutlineView
275 bool bIsOutlineView(OutlinerMode::OutlineView == pOLV->GetOutliner()->GetMode());
276
277 // This is ONLY for OutlineViews
278 if(bIsOutlineView)
279 {
280 // allow move up if position is 2 or greater OR it
281 // is a title object (and thus depth==1)
282 if(pOutl->GetAbsPos(pPara) > 1 || ( ::Outliner::HasParaFlag(pPara,ParaFlag::ISPAGE) && pOutl->GetAbsPos(pPara) > 0 ) )
283 {
284 // not at top
285 bDisableUp = false;
286 }
287 }
288 else
289 {
290 // old behaviour for OutlinerMode::OutlineObject
291 if(pOutl->GetAbsPos(pPara) > 0)
292 {
293 // not at top
294 bDisableUp = false;
295 }
296 }
297
298 for (const auto& rpItem : aSelList)
299 {
300 pPara = rpItem;
301
302 sal_Int16 nDepth = pOutl->GetDepth( pOutl->GetAbsPos( pPara ) );
303
304 if (nDepth > 0 || (bOutlineViewSh && (nDepth <= 0) && !::Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE )) )
305 {
306 // not minimum depth
307 bDisableLeft = false;
308 }
309
310 if( (nDepth < pOLV->GetOutliner()->GetMaxDepth() && ( !bOutlineViewSh || pOutl->GetAbsPos(pPara) != 0 )) ||
311 (bOutlineViewSh && (nDepth <= 0) && ::Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) && pOutl->GetAbsPos(pPara) != 0) )
312 {
313 // not maximum depth and not at top
314 bDisableRight = false;
315 }
316 }
317
318 if ( ( pOutl->GetAbsPos(pPara) < pOutl->GetParagraphCount() - 1 ) &&
319 ( pOutl->GetParagraphCount() > 1 || !bOutlineViewSh) )
320 {
321 // not last paragraph
322 bDisableDown = false;
323 }
324
325 // disable when first para and 2nd is not a title
326 pPara = aSelList.empty() ? nullptr : *(aSelList.begin());
327
328 if(!bDisableDown && bIsOutlineView
329 && pPara
330 && 0 == pOutl->GetAbsPos(pPara)
331 && pOutl->GetParagraphCount() > 1
332 && !::Outliner::HasParaFlag( pOutl->GetParagraph(1), ParaFlag::ISPAGE ) )
333 {
334 // Needs to be disabled
335 bDisableDown = true;
336 }
337 }
338 }
339
340 if (bDisableLeft)
341 rSet.DisableItem(SID_OUTLINE_LEFT( 10000 + 152 ));
342 if (bDisableRight)
343 rSet.DisableItem(SID_OUTLINE_RIGHT( 10000 + 153 ));
344 if (bDisableUp)
345 rSet.DisableItem(SID_OUTLINE_UP( 10000 + 150 ));
346 if (bDisableDown)
347 rSet.DisableItem(SID_OUTLINE_DOWN( 10000 + 151 ));
348 }
349 break;
350
351 case SID_TEXTDIRECTION_LEFT_TO_RIGHT( 10000 + 907 ):
352 case SID_TEXTDIRECTION_TOP_TO_BOTTOM( 10000 + 908 ):
353 {
354 if ( bDisableVerticalText )
355 {
356 rSet.DisableItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT( 10000 + 907 ) );
357 rSet.DisableItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM( 10000 + 908 ) );
358 }
359 else
360 {
361 bool bLeftToRight = true;
362
363 SdrOutliner* pOutl = mpView->GetTextEditOutliner();
364 if( pOutl )
365 {
366 if( pOutl->IsVertical() )
367 bLeftToRight = false;
368 }
369 else
370 bLeftToRight = aAttrSet.Get( SDRATTR_TEXTDIRECTION ).GetValue() == css::text::WritingMode_LR_TB;
371
372 rSet.Put( SfxBoolItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT( 10000 + 907 ), bLeftToRight ) );
373 rSet.Put( SfxBoolItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM( 10000 + 908 ), !bLeftToRight ) );
374
375 if( !bLeftToRight )
376 bDisableParagraphTextDirection = true;
377 }
378 }
379 break;
380
381 case SID_ULINE_VAL_NONE(10000 + 1195):
382 case SID_ULINE_VAL_SINGLE(10000 + 1196):
383 case SID_ULINE_VAL_DOUBLE(10000 + 1197):
384 case SID_ULINE_VAL_DOTTED(10000 + 1198):
385 {
386 if( aAttrSet.GetItemState( EE_CHAR_UNDERLINE ) >= SfxItemState::DEFAULT )
387 {
388 FontLineStyle eLineStyle = aAttrSet.Get(EE_CHAR_UNDERLINE).GetLineStyle();
389
390 switch (nSlotId)
391 {
392 case SID_ULINE_VAL_NONE(10000 + 1195):
393 rSet.Put(SfxBoolItem(nSlotId, eLineStyle == LINESTYLE_NONE));
394 break;
395 case SID_ULINE_VAL_SINGLE(10000 + 1196):
396 rSet.Put(SfxBoolItem(nSlotId, eLineStyle == LINESTYLE_SINGLE));
397 break;
398 case SID_ULINE_VAL_DOUBLE(10000 + 1197):
399 rSet.Put(SfxBoolItem(nSlotId, eLineStyle == LINESTYLE_DOUBLE));
400 break;
401 case SID_ULINE_VAL_DOTTED(10000 + 1198):
402 rSet.Put(SfxBoolItem(nSlotId, eLineStyle == LINESTYLE_DOTTED));
403 break;
404 }
405 }
406 }
407 break;
408
409 case SID_GROW_FONT_SIZE( 10000 + 1042 ):
410 case SID_SHRINK_FONT_SIZE( 10000 + 1043 ):
411 {
412 // todo
413 }
414 break;
415
416 case SID_THES(5000 + 698):
417 {
418 if (mpView->GetTextEditOutlinerView())
419 {
420 EditView & rEditView = mpView->GetTextEditOutlinerView()->GetEditView();
421 OUString aStatusVal;
422 LanguageType nLang = LANGUAGE_NONELanguageType(0x00FF);
423 bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, rEditView );
424 rSet.Put( SfxStringItem( SID_THES(5000 + 698), aStatusVal ) );
425
426 // disable "Thesaurus" context menu entry if there is nothing to look up
427 uno::Reference< linguistic2::XThesaurus > xThes( LinguMgr::GetThesaurus() );
428 if (!bIsLookUpWord ||
429 !xThes.is() || nLang == LANGUAGE_NONELanguageType(0x00FF) || !xThes->hasLocale( LanguageTag( nLang). getLocale() ))
430 rSet.DisableItem( SID_THES(5000 + 698) );
431 }
432 else
433 {
434 rSet.DisableItem( SID_THES(5000 + 698) );
435 }
436 }
437 break;
438
439 default:
440 break;
441 }
442
443 nWhich = aIter.NextWhich();
444 }
445
446 rSet.Put( aAttrSet, false ); // <- sal_False, so DontCare-Status gets acquired
447
448 // these are disabled in outline-mode
449 if (!mpViewShell || dynamic_cast< const DrawViewShell *>( mpViewShell ) == nullptr)
450 {
451 rSet.DisableItem( SID_ATTR_PARA_ADJUST_LEFT( 10000 + 28 ) );
452 rSet.DisableItem( SID_ATTR_PARA_ADJUST_RIGHT( 10000 + 29 ) );
453 rSet.DisableItem( SID_ATTR_PARA_ADJUST_CENTER( 10000 + 30 ) );
454 rSet.DisableItem( SID_ATTR_PARA_ADJUST_BLOCK( 10000 + 31 ) );
455 rSet.DisableItem( SID_ATTR_PARA_LINESPACE_10( 10000 + 34 ) );
456 rSet.DisableItem( SID_ATTR_PARA_LINESPACE_15( 10000 + 35 ) );
457 rSet.DisableItem( SID_ATTR_PARA_LINESPACE_20( 10000 + 36 ) );
458 rSet.DisableItem( SID_DEC_INDENT( 10000 + 461 ) );
459 rSet.DisableItem( SID_INC_INDENT( 10000 + 462 ) );
460 rSet.DisableItem( SID_PARASPACE_INCREASE( 10000 + 1145 ) );
461 rSet.DisableItem( SID_PARASPACE_DECREASE( 10000 + 1146 ) );
462 rSet.DisableItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM( 10000 + 908 ) );
463 rSet.DisableItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT( 10000 + 907 ) );
464 rSet.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT( 10000 + 950 ) );
465 rSet.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT( 10000 + 951 ) );
466 }
467 else
468 {
469 // paragraph spacing
470 OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
471 if( pOLV )
472 {
473 ESelection aSel = pOLV->GetSelection();
474 aSel.Adjust();
475 sal_Int32 nStartPara = aSel.nStartPara;
476 sal_Int32 nEndPara = aSel.nEndPara;
477 if( !aSel.HasRange() )
478 {
479 nStartPara = 0;
480 nEndPara = pOLV->GetOutliner()->GetParagraphCount() - 1;
481 }
482 long nUpper = 0;
483
484 for( sal_Int32 nPara = nStartPara; nPara <= nEndPara; nPara++ )
485 {
486 const SfxItemSet& rItems = pOLV->GetOutliner()->GetParaAttribs( nPara );
487 const SvxULSpaceItem& rItem = rItems.Get( EE_PARA_ULSPACE );
488 nUpper = std::max( nUpper, static_cast<long>(rItem.GetUpper()) );
489 }
490 if( nUpper == 0 )
491 rSet.DisableItem( SID_PARASPACE_DECREASE( 10000 + 1146 ) );
492 }
493 else
494 {
495 // never disabled at the moment!
496 //rSet.DisableItem( SID_PARASPACE_INCREASE );
497 //rSet.DisableItem( SID_PARASPACE_DECREASE );
498 }
499
500 // paragraph justification
501 const SvxLRSpaceItem& aLR = aAttrSet.Get( EE_PARA_LRSPACE );
502 rSet.Put(aLR);
503 SvxAdjust eAdj = aAttrSet.Get( EE_PARA_JUST ).GetAdjust();
504 switch( eAdj )
505 {
506 case SvxAdjust::Left:
507 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_LEFT( 10000 + 28 ), true ) );
508 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_CENTER( 10000 + 30 ), false ) );
509 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_RIGHT( 10000 + 29 ), false ) );
510 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_BLOCK( 10000 + 31 ), false ) );
511 break;
512 case SvxAdjust::Center:
513 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_CENTER( 10000 + 30 ), true ) );
514 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_LEFT( 10000 + 28 ), false ) );
515 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_RIGHT( 10000 + 29 ), false ) );
516 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_BLOCK( 10000 + 31 ), false ) );
517 break;
518 case SvxAdjust::Right:
519 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_RIGHT( 10000 + 29 ), true ) );
520 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_CENTER( 10000 + 30 ), false ) );
521 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_LEFT( 10000 + 28 ), false ) );
522 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_BLOCK( 10000 + 31 ), false ) );
523 break;
524 case SvxAdjust::Block:
525 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_BLOCK( 10000 + 31 ), true ) );
526 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_CENTER( 10000 + 30 ), false ) );
527 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_RIGHT( 10000 + 29 ), false ) );
528 rSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_LEFT( 10000 + 28 ), false ) );
529 break;
530 default:
531 break;
532 }
533
534 Invalidate(SID_ATTR_PARA_ADJUST_LEFT( 10000 + 28 ));
535 Invalidate(SID_ATTR_PARA_ADJUST_CENTER( 10000 + 30 ));
536 Invalidate(SID_ATTR_PARA_ADJUST_RIGHT( 10000 + 29 ));
537 Invalidate(SID_ATTR_PARA_ADJUST_BLOCK( 10000 + 31 ));
538 Invalidate(SID_ATTR_PARA_LINESPACE( 10000 + 33 ));
539 Invalidate(SID_ATTR_PARA_ULSPACE( 10000 + 42 ));
540
541 // paragraph text direction
542 if( bDisableParagraphTextDirection )
543 {
544 rSet.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT( 10000 + 950 ) );
545 rSet.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT( 10000 + 951 ) );
546 }
547 else
548 {
549 switch( aAttrSet.Get( EE_PARA_WRITINGDIR ).GetValue() )
550 {
551 case SvxFrameDirection::Vertical_LR_TB:
552 case SvxFrameDirection::Vertical_RL_TB:
553 {
554 rSet.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT( 10000 + 950 ) );
555 rSet.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT( 10000 + 951 ) );
556 }
557 break;
558
559 case SvxFrameDirection::Horizontal_LR_TB:
560 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT( 10000 + 950 ), true ) );
561 rSet.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT( 10000 + 951 ), false ) );
562 break;
563
564 case SvxFrameDirection::Horizontal_RL_TB:
565 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT( 10000 + 950 ), false ) );
566 rSet.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT( 10000 + 951 ), true ) );
567 break;
568
569 // The case for the superordinate object is missing.
570 case SvxFrameDirection::Environment:
571 {
572 SdDrawDocument& rDoc = mpView->GetDoc();
573 css::text::WritingMode eMode = rDoc.GetDefaultWritingMode();
574 bool bIsLeftToRight(false);
575
576 if(css::text::WritingMode_LR_TB == eMode
577 || css::text::WritingMode_TB_RL == eMode)
578 {
579 bIsLeftToRight = true;
580 }
581
582 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT( 10000 + 950 ), bIsLeftToRight ) );
583 rSet.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT( 10000 + 951 ), !bIsLeftToRight ) );
584 }
585 break;
586 default: break;
587 }
588 }
589
590 SvxLRSpaceItem aLRSpace = aAttrSet.Get( EE_PARA_LRSPACE );
591 aLRSpace.SetWhich(SID_ATTR_PARA_LRSPACE( 10000 + 43 ));
592 rSet.Put(aLRSpace);
593 Invalidate(SID_ATTR_PARA_LRSPACE( 10000 + 43 ));
594
595 //Added by xuxu
596 SfxItemState eState = aAttrSet.GetItemState( EE_PARA_LRSPACE );
597 if ( eState == SfxItemState::DONTCARE )
598 {
599 rSet.InvalidateItem(EE_PARA_LRSPACE);
600 rSet.InvalidateItem(SID_ATTR_PARA_LRSPACE( 10000 + 43 ));
601 }
602 sal_uInt16 nLineSpace = aAttrSet.Get( EE_PARA_SBL ).GetPropLineSpace();
603 switch( nLineSpace )
604 {
605 case 100:
606 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_10( 10000 + 34 ), true ) );
607 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_15( 10000 + 35 ), false ) );
608 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_20( 10000 + 36 ), false ) );
609 break;
610 case 150:
611 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_15( 10000 + 35 ), true ) );
612 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_10( 10000 + 34 ), false ) );
613 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_20( 10000 + 36 ), false ) );
614 break;
615 case 200:
616 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_20( 10000 + 36 ), true ) );
617 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_10( 10000 + 34 ), false ) );
618 rSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_15( 10000 + 35 ), false ) );
619 break;
620 }
621 }
622
623 // justification (superscript, subscript) is also needed in outline-mode
624 SvxEscapement eEsc = static_cast<SvxEscapement>(aAttrSet.Get( EE_CHAR_ESCAPEMENT ).GetEnumValue());
625 rSet.Put(SfxBoolItem(SID_SET_SUPER_SCRIPT( 10000 + 294 ), eEsc == SvxEscapement::Superscript));
626 rSet.Put(SfxBoolItem(SID_SET_SUB_SCRIPT( 10000 + 295 ), eEsc == SvxEscapement::Subscript));
627}
628
629} // end of namespace sd
630
631/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/svl/itempool.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_SVL_ITEMPOOL_HXX
21#define INCLUDED_SVL_ITEMPOOL_HXX
22
23#include <svl/poolitem.hxx>
24#include <svl/svldllapi.h>
25#include <svl/typedwhich.hxx>
26#include <memory>
27#include <vector>
28#include <o3tl/sorted_vector.hxx>
29
30class SfxBroadcaster;
31struct SfxItemPool_Impl;
32
33struct SfxItemInfo
34{
35 sal_uInt16 _nSID;
36 bool _bPoolable;
37};
38
39class SfxItemPool;
40
41class SVL_DLLPUBLIC__attribute__ ((visibility("default"))) SfxItemPoolUser
42{
43public:
44 virtual void ObjectInDestruction(const SfxItemPool& rSfxItemPool) = 0;
45
46protected:
47 ~SfxItemPoolUser() {}
48};
49
50/** Base class for providers of defaults of SfxPoolItems.
51 *
52 * The derived classes hold the concrete (const) instances which are referenced in several places
53 * (usually within a single document).
54 * This helps to lower the amount of calls to lifecycle methods, speeds up comparisons within a document
55 * and facilitates loading and saving of attributes.
56 */
57class SVL_DLLPUBLIC__attribute__ ((visibility("default"))) SfxItemPool
58{
59 friend struct SfxItemPool_Impl;
60 friend class SfxItemSet;
61 friend class SfxAllItemSet;
62
63 const SfxItemInfo* pItemInfos;
64 std::unique_ptr<SfxItemPool_Impl> pImpl;
65
66public:
67 void AddSfxItemPoolUser(SfxItemPoolUser& rNewUser);
68 void RemoveSfxItemPoolUser(SfxItemPoolUser& rOldUser);
69
70private:
71 sal_uInt16 GetIndex_Impl(sal_uInt16 nWhich) const;
72 sal_uInt16 GetSize_Impl() const;
73
74 SVL_DLLPRIVATE__attribute__ ((visibility("hidden"))) bool IsItemPoolable_Impl( sal_uInt16 nWhich ) const;
75
76public:
77 // for default SfxItemSet::CTOR, set default WhichRanges
78 void FillItemIdRanges_Impl( std::unique_ptr<sal_uInt16[]>& pWhichRanges ) const;
79 const sal_uInt16* GetFrozenIdRanges() const;
80
81protected:
82 static inline void ClearRefCount(SfxPoolItem& rItem);
83 static inline void AddRef(const SfxPoolItem& rItem);
84 static inline sal_uInt32 ReleaseRef(const SfxPoolItem& rItem, sal_uInt32 n = 1);
85
86public:
87 SfxItemPool( const SfxItemPool &rPool,
88 bool bCloneStaticDefaults = false );
89 SfxItemPool( const OUString &rName,
90 sal_uInt16 nStart, sal_uInt16 nEnd,
91 const SfxItemInfo *pItemInfos,
92 std::vector<SfxPoolItem*> *pDefaults = nullptr );
93
94protected:
95 virtual ~SfxItemPool();
96
97public:
98 static void Free(SfxItemPool* pPool);
99
100 SfxBroadcaster& BC();
101
102 void SetPoolDefaultItem( const SfxPoolItem& );
103
104 const SfxPoolItem* GetPoolDefaultItem( sal_uInt16 nWhich ) const;
105 template<class T> const T* GetPoolDefaultItem( TypedWhichId<T> nWhich ) const
106 { return static_cast<const T*>(GetPoolDefaultItem(sal_uInt16(nWhich))); }
107
108 void ResetPoolDefaultItem( sal_uInt16 nWhich );
109
110 void SetDefaults(std::vector<SfxPoolItem*>* pDefaults);
111 void ClearDefaults();
112 void ReleaseDefaults( bool bDelete = false );
113 static void ReleaseDefaults( std::vector<SfxPoolItem*> *pDefaults, bool bDelete = false );
114
115 virtual MapUnit GetMetric( sal_uInt16 nWhich ) const;
116 void SetDefaultMetric( MapUnit eNewMetric );
117
118 /** Request string representation of pool items.
119
120 This virtual function produces a string representation
121 from the respective SfxItemPool subclass' known SfxPoolItems.
122
123 Subclasses, please override this method, and handle
124 SfxPoolItems that don't return useful/complete information on
125 SfxPoolItem::GetPresentation()
126
127 This baseclass yields the unmodified string representation of
128 rItem.
129
130 @param[in] rItem
131 SfxPoolItem to query the string representation of
132
133 @param[in] ePresent
134 requested kind of representation - see SfxItemPresentation
135
136 @param[in] eMetric
137 requested unit of measure of the representation
138
139 @param[out] rText
140 string representation of 'rItem'
141
142 @return true if it has a valid string representation
143 */
144 virtual bool GetPresentation( const SfxPoolItem& rItem,
145 MapUnit ePresentationMetric,
146 OUString& rText,
147 const IntlWrapper& rIntlWrapper ) const;
148 virtual SfxItemPool* Clone() const;
149 const OUString& GetName() const;
150
151 template<class T> const T& Put( std::unique_ptr<T> xItem, sal_uInt16 nWhich = 0 )
152 { return static_cast<const T&>(PutImpl( *xItem.release(), nWhich, /*bPassingOwnership*/true)); }
153 template<class T> const T& Put( const T& rItem, sal_uInt16 nWhich = 0 )
154 { return static_cast<const T&>(PutImpl( rItem, nWhich, /*bPassingOwnership*/false)); }
155 void Remove( const SfxPoolItem& );
156
157 const SfxPoolItem& GetDefaultItem( sal_uInt16 nWhich ) const;
158 template<class T> const T& GetDefaultItem( TypedWhichId<T> nWhich ) const
159 { return static_cast<const T&>(GetDefaultItem(sal_uInt16(nWhich))); }
160
161 bool CheckItemInPool(const SfxPoolItem *) const;
162
163 struct Item2Range
164 {
165 o3tl::sorted_vector<SfxPoolItem*>::const_iterator m_begin;
166 o3tl::sorted_vector<SfxPoolItem*>::const_iterator m_end;
167 o3tl::sorted_vector<SfxPoolItem*>::const_iterator const & begin() const { return m_begin; }
168 o3tl::sorted_vector<SfxPoolItem*>::const_iterator const & end() const { return m_end; }
169 };
170 const SfxPoolItem * GetItem2Default(sal_uInt16 nWhich) const;
171 template<class T> const T* GetItem2Default( TypedWhichId<T> nWhich ) const
172 { return static_cast<const T*>(GetItem2Default(sal_uInt16(nWhich))); }
173
174 sal_uInt32 GetItemCount2(sal_uInt16 nWhich) const;
175 Item2Range GetItemSurrogates(sal_uInt16 nWhich) const;
176 /*
177 This is only valid for SfxPoolItem that override IsSortable and operator<.
178 Returns a range of items defined by using operator<.
179 @param rNeedle must be the same type or a supertype of the pool items for nWhich.
180 */
181 std::vector<const SfxPoolItem*> FindItemSurrogate(sal_uInt16 nWhich, SfxPoolItem const & rNeedle) const;
182
183 sal_uInt16 GetFirstWhich() const;
184 sal_uInt16 GetLastWhich() const;
185 bool IsInRange( sal_uInt16 nWhich ) const;
186 void SetSecondaryPool( SfxItemPool *pPool );
187 SfxItemPool* GetSecondaryPool() const;
188 SfxItemPool* GetMasterPool() const;
189 void FreezeIdRanges();
190
191 void Delete();
192
193 bool IsItemPoolable( sal_uInt16 nWhich ) const;
194 bool IsItemPoolable( const SfxPoolItem &rItem ) const
195 { return IsItemPoolable( rItem.Which() ); }
196 void SetItemInfos( const SfxItemInfo *pInfos );
197 sal_uInt16 GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
198 sal_uInt16 GetSlotId( sal_uInt16 nWhich ) const;
199 sal_uInt16 GetTrueWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
200 sal_uInt16 GetTrueSlotId( sal_uInt16 nWhich ) const;
201
202 static bool IsWhich(sal_uInt16 nId) {
203 return nId
4.1
'nId' is not equal to 0, which participates in a condition later
4.1
'nId' is not equal to 0, which participates in a condition later
&& nId <= SFX_WHICH_MAX; }
5
Assuming 'nId' is > 'SFX_WHICH_MAX', which participates in a condition later
204 static bool IsSlot(sal_uInt16 nId) {
205 return nId && nId > SFX_WHICH_MAX; }
206
207 void dumpAsXml(xmlTextWriterPtr pWriter) const;
208
209protected:
210 virtual const SfxPoolItem& PutImpl( const SfxPoolItem&, sal_uInt16 nWhich = 0, bool bPassingOwnership = false );
211private:
212 const SfxItemPool& operator=(const SfxItemPool &) = delete;
213
214 //IDs below or equal are Which IDs, IDs above slot IDs
215 static const sal_uInt16 SFX_WHICH_MAX = 4999;
216};
217
218// only the pool may manipulate the reference counts
219inline void SfxItemPool::ClearRefCount(SfxPoolItem& rItem)
220{
221 rItem.SetRefCount(0);
222}
223
224// only the pool may manipulate the reference counts
225inline void SfxItemPool::AddRef(const SfxPoolItem& rItem)
226{
227 rItem.AddRef();
228}
229
230// only the pool may manipulate the reference counts
231inline sal_uInt32 SfxItemPool::ReleaseRef(const SfxPoolItem& rItem, sal_uInt32 n)
232{
233 return rItem.ReleaseRef(n);
234}
235
236#endif
237
238/* vim:set shiftwidth=4 softtabstop=4 expandtab: */