File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <comphelper/string.hxx> | ||||||||
21 | #include <scitems.hxx> | ||||||||
22 | |||||||||
23 | #include <editeng/adjustitem.hxx> | ||||||||
24 | #include <svx/clipfmtitem.hxx> | ||||||||
25 | #include <editeng/contouritem.hxx> | ||||||||
26 | #include <editeng/crossedoutitem.hxx> | ||||||||
27 | #include <editeng/eeitem.hxx> | ||||||||
28 | #include <editeng/editeng.hxx> | ||||||||
29 | #include <editeng/editview.hxx> | ||||||||
30 | #include <editeng/escapementitem.hxx> | ||||||||
31 | #include <editeng/flditem.hxx> | ||||||||
32 | #include <editeng/flstitem.hxx> | ||||||||
33 | #include <editeng/fontitem.hxx> | ||||||||
34 | #include <editeng/frmdiritem.hxx> | ||||||||
35 | #include <editeng/lrspitem.hxx> | ||||||||
36 | #include <editeng/lspcitem.hxx> | ||||||||
37 | #include <editeng/ulspitem.hxx> | ||||||||
38 | #include <editeng/urlfieldhelper.hxx> | ||||||||
39 | #include <svx/hlnkitem.hxx> | ||||||||
40 | #include <svx/svdoutl.hxx> | ||||||||
41 | #include <svx/sdooitm.hxx> | ||||||||
42 | #include <editeng/postitem.hxx> | ||||||||
43 | #include <editeng/scripttypeitem.hxx> | ||||||||
44 | #include <editeng/shdditem.hxx> | ||||||||
45 | #include <editeng/udlnitem.hxx> | ||||||||
46 | #include <editeng/wghtitem.hxx> | ||||||||
47 | #include <editeng/writingmodeitem.hxx> | ||||||||
48 | #include <sfx2/dispatch.hxx> | ||||||||
49 | #include <sfx2/objface.hxx> | ||||||||
50 | #include <sfx2/objsh.hxx> | ||||||||
51 | #include <sfx2/request.hxx> | ||||||||
52 | #include <sfx2/viewfrm.hxx> | ||||||||
53 | #include <svtools/cliplistener.hxx> | ||||||||
54 | #include <vcl/transfer.hxx> | ||||||||
55 | #include <svl/stritem.hxx> | ||||||||
56 | #include <svl/whiter.hxx> | ||||||||
57 | #include <svl/languageoptions.hxx> | ||||||||
58 | |||||||||
59 | #include <svx/svxdlg.hxx> | ||||||||
60 | #include <vcl/EnumContext.hxx> | ||||||||
61 | #include <vcl/unohelp2.hxx> | ||||||||
62 | |||||||||
63 | #include <sc.hrc> | ||||||||
64 | #include <globstr.hrc> | ||||||||
65 | #include <scresid.hxx> | ||||||||
66 | #include <scmod.hxx> | ||||||||
67 | #include <drtxtob.hxx> | ||||||||
68 | #include <viewdata.hxx> | ||||||||
69 | #include <document.hxx> | ||||||||
70 | #include <drawview.hxx> | ||||||||
71 | #include <viewutil.hxx> | ||||||||
72 | #include <tabvwsh.hxx> | ||||||||
73 | #include <gridwin.hxx> | ||||||||
74 | |||||||||
75 | #define ShellClass_ScDrawTextObjectBar | ||||||||
76 | #include <scslots.hxx> | ||||||||
77 | |||||||||
78 | using namespace ::com::sun::star; | ||||||||
79 | |||||||||
80 | SFX_IMPL_INTERFACE(ScDrawTextObjectBar, SfxShell)SfxInterface* ScDrawTextObjectBar::pInterface = nullptr; SfxInterface * ScDrawTextObjectBar::GetStaticInterface() { if ( !pInterface ) { pInterface = new SfxInterface( "ScDrawTextObjectBar", false , GetInterfaceId(), SfxShell::GetStaticInterface(), aScDrawTextObjectBarSlots_Impl [0], sal_uInt16(sizeof(aScDrawTextObjectBarSlots_Impl) / sizeof (SfxSlot) ) ); InitInterface_Impl(); } return pInterface; } SfxInterface * ScDrawTextObjectBar::GetInterface() const { return GetStaticInterface (); } void ScDrawTextObjectBar::RegisterInterface(const SfxModule * pMod) { GetStaticInterface()->Register(pMod); } | ||||||||
81 | |||||||||
82 | void ScDrawTextObjectBar::InitInterface_Impl() | ||||||||
83 | { | ||||||||
84 | GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT1, | ||||||||
85 | SfxVisibilityFlags::Standard | SfxVisibilityFlags::Server, | ||||||||
86 | ToolbarId::Text_Toolbox_Sc); | ||||||||
87 | |||||||||
88 | GetStaticInterface()->RegisterPopupMenu("drawtext"); | ||||||||
89 | |||||||||
90 | GetStaticInterface()->RegisterChildWindow(ScGetFontWorkId()); | ||||||||
91 | } | ||||||||
92 | |||||||||
93 | |||||||||
94 | // disable not wanted accelerators | ||||||||
95 | |||||||||
96 | void ScDrawTextObjectBar::StateDisableItems( SfxItemSet &rSet ) | ||||||||
97 | { | ||||||||
98 | SfxWhichIter aIter(rSet); | ||||||||
99 | sal_uInt16 nWhich = aIter.FirstWhich(); | ||||||||
100 | |||||||||
101 | while (nWhich) | ||||||||
102 | { | ||||||||
103 | rSet.DisableItem( nWhich ); | ||||||||
104 | nWhich = aIter.NextWhich(); | ||||||||
105 | } | ||||||||
106 | } | ||||||||
107 | |||||||||
108 | ScDrawTextObjectBar::ScDrawTextObjectBar(ScViewData& rData) : | ||||||||
109 | SfxShell(rData.GetViewShell()), | ||||||||
110 | mrViewData(rData), | ||||||||
111 | bPastePossible(false) | ||||||||
112 | { | ||||||||
113 | SetPool( mrViewData.GetScDrawView()->GetDefaultAttr().GetPool() ); | ||||||||
114 | |||||||||
115 | // At the switching-over the UndoManager is changed to edit mode | ||||||||
116 | SfxUndoManager* pMgr = mrViewData.GetSfxDocShell()->GetUndoManager(); | ||||||||
117 | SetUndoManager( pMgr ); | ||||||||
118 | if ( !mrViewData.GetDocument().IsUndoEnabled() ) | ||||||||
119 | { | ||||||||
120 | pMgr->SetMaxUndoActionCount( 0 ); | ||||||||
121 | } | ||||||||
122 | |||||||||
123 | SetName("DrawText"); | ||||||||
124 | SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::DrawText)); | ||||||||
125 | } | ||||||||
126 | |||||||||
127 | ScDrawTextObjectBar::~ScDrawTextObjectBar() | ||||||||
128 | { | ||||||||
129 | if ( mxClipEvtLstnr.is() ) | ||||||||
130 | { | ||||||||
131 | mxClipEvtLstnr->RemoveListener( mrViewData.GetActiveWin() ); | ||||||||
132 | |||||||||
133 | // The listener may just now be waiting for the SolarMutex and call the link | ||||||||
134 | // afterwards, in spite of RemoveListener. So the link has to be reset, too. | ||||||||
135 | mxClipEvtLstnr->ClearCallbackLink(); | ||||||||
136 | } | ||||||||
137 | } | ||||||||
138 | |||||||||
139 | // Functions | ||||||||
140 | |||||||||
141 | void ScDrawTextObjectBar::Execute( SfxRequest &rReq ) | ||||||||
142 | { | ||||||||
143 | ScDrawView* pView = mrViewData.GetScDrawView(); | ||||||||
144 | OutlinerView* pOutView = pView->GetTextEditOutlinerView(); | ||||||||
145 | Outliner* pOutliner = pView->GetTextEditOutliner(); | ||||||||
146 | |||||||||
147 | if (!pOutView || !pOutliner) | ||||||||
148 | { | ||||||||
149 | ExecuteGlobal( rReq ); // on whole objects | ||||||||
150 | return; | ||||||||
151 | } | ||||||||
152 | |||||||||
153 | const SfxItemSet* pReqArgs = rReq.GetArgs(); | ||||||||
154 | sal_uInt16 nSlot = rReq.GetSlot(); | ||||||||
155 | switch ( nSlot ) | ||||||||
156 | { | ||||||||
157 | case SID_COPY(5000 + 711): | ||||||||
158 | pOutView->Copy(); | ||||||||
159 | break; | ||||||||
160 | |||||||||
161 | case SID_CUT(5000 + 710): | ||||||||
162 | pOutView->Cut(); | ||||||||
163 | break; | ||||||||
164 | |||||||||
165 | case SID_PASTE(5000 + 712): | ||||||||
166 | pOutView->PasteSpecial(); | ||||||||
167 | break; | ||||||||
168 | |||||||||
169 | case SID_CLIPBOARD_FORMAT_ITEMS(5000 + 312): | ||||||||
170 | { | ||||||||
171 | SotClipboardFormatId nFormat = SotClipboardFormatId::NONE; | ||||||||
172 | const SfxPoolItem* pItem; | ||||||||
173 | if ( pReqArgs && | ||||||||
174 | pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET && | ||||||||
175 | dynamic_cast<const SfxUInt32Item*>( pItem) != nullptr ) | ||||||||
176 | { | ||||||||
177 | nFormat = static_cast<SotClipboardFormatId>(static_cast<const SfxUInt32Item*>(pItem)->GetValue()); | ||||||||
178 | } | ||||||||
179 | |||||||||
180 | if ( nFormat != SotClipboardFormatId::NONE ) | ||||||||
181 | { | ||||||||
182 | if (nFormat == SotClipboardFormatId::STRING) | ||||||||
183 | pOutView->Paste(); | ||||||||
184 | else | ||||||||
185 | pOutView->PasteSpecial(); | ||||||||
186 | } | ||||||||
187 | } | ||||||||
188 | break; | ||||||||
189 | |||||||||
190 | case SID_PASTE_SPECIAL(5000 + 311): | ||||||||
191 | ExecutePasteContents( rReq ); | ||||||||
192 | break; | ||||||||
193 | |||||||||
194 | case SID_PASTE_UNFORMATTED(5000 + 314): | ||||||||
195 | pOutView->Paste(); | ||||||||
196 | break; | ||||||||
197 | |||||||||
198 | case SID_SELECTALL(5000 + 723): | ||||||||
199 | { | ||||||||
200 | sal_Int32 nCount = pOutliner->GetParagraphCount(); | ||||||||
201 | ESelection aSel( 0,0,nCount,0 ); | ||||||||
202 | pOutView->SetSelection( aSel ); | ||||||||
203 | } | ||||||||
204 | break; | ||||||||
205 | |||||||||
206 | case SID_CHARMAP((10000 + 500) + 3): | ||||||||
207 | { | ||||||||
208 | const SvxFontItem& rItem = pOutView->GetAttribs().Get(EE_CHAR_FONTINFO); | ||||||||
209 | |||||||||
210 | OUString aString; | ||||||||
211 | std::shared_ptr<SvxFontItem> aNewItem(std::make_shared<SvxFontItem>(EE_CHAR_FONTINFO)); | ||||||||
212 | |||||||||
213 | const SfxItemSet *pArgs = rReq.GetArgs(); | ||||||||
214 | const SfxPoolItem* pItem = nullptr; | ||||||||
215 | if( pArgs ) | ||||||||
216 | pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP((10000 + 500) + 3)), false, &pItem); | ||||||||
217 | |||||||||
218 | if ( pItem ) | ||||||||
219 | { | ||||||||
220 | aString = static_cast<const SfxStringItem*>(pItem)->GetValue(); | ||||||||
221 | const SfxPoolItem* pFtItem = nullptr; | ||||||||
222 | pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR( 10000 + 1120 )), false, &pFtItem); | ||||||||
223 | const SfxStringItem* pFontItem = dynamic_cast<const SfxStringItem*>( pFtItem ); | ||||||||
224 | if ( pFontItem ) | ||||||||
225 | { | ||||||||
226 | const OUString& aFontName(pFontItem->GetValue()); | ||||||||
227 | vcl::Font aFont(aFontName, Size(1,1)); // Size only because of CTOR | ||||||||
228 | aNewItem = std::make_shared<SvxFontItem>( | ||||||||
229 | aFont.GetFamilyType(), aFont.GetFamilyName(), | ||||||||
230 | aFont.GetStyleName(), aFont.GetPitch(), | ||||||||
231 | aFont.GetCharSet(), ATTR_FONT); | ||||||||
232 | } | ||||||||
233 | else | ||||||||
234 | { | ||||||||
235 | aNewItem.reset(rItem.Clone()); | ||||||||
236 | } | ||||||||
237 | } | ||||||||
238 | else | ||||||||
239 | ScViewUtil::ExecuteCharMap( rItem, *mrViewData.GetViewShell()->GetViewFrame() ); | ||||||||
240 | |||||||||
241 | if ( !aString.isEmpty() ) | ||||||||
242 | { | ||||||||
243 | SfxItemSet aSet( pOutliner->GetEmptyItemSet() ); | ||||||||
244 | // tdf#125054 | ||||||||
245 | // checked against original, indeed aNewItem looks as if it can have | ||||||||
246 | // either WhichID EE_CHAR_FONTINFO or ATTR_FONT when it was reset | ||||||||
247 | // above, original uses '= SvxFontItem(..., ATTR_FONT). | ||||||||
248 | // BUT beware: the operator=() did not copy the WhichID when resetting, | ||||||||
249 | // so it indeed has WhichID of EE_CHAR_FONTINFO despite copying an Item | ||||||||
250 | // that was constructed using ATTR_FONT as WhichID (!) | ||||||||
251 | aSet.Put( *aNewItem, EE_CHAR_FONTINFO ); | ||||||||
252 | |||||||||
253 | // If nothing is selected, then SetAttribs of the View selects a word | ||||||||
254 | pOutView->GetOutliner()->QuickSetAttribs( aSet, pOutView->GetSelection() ); | ||||||||
255 | pOutView->InsertText(aString); | ||||||||
256 | } | ||||||||
257 | |||||||||
258 | Invalidate( SID_ATTR_CHAR_FONT( 10000 + 7 ) ); | ||||||||
259 | } | ||||||||
260 | break; | ||||||||
261 | |||||||||
262 | case SID_HYPERLINK_SETLINKTypedWhichId<SvxHyperlinkItem>(10000 + 362): | ||||||||
263 | if( pReqArgs ) | ||||||||
264 | { | ||||||||
265 | const SfxPoolItem* pItem; | ||||||||
266 | if ( pReqArgs->GetItemState( SID_HYPERLINK_SETLINKTypedWhichId<SvxHyperlinkItem>(10000 + 362), true, &pItem ) == SfxItemState::SET ) | ||||||||
267 | { | ||||||||
268 | const SvxHyperlinkItem* pHyper = static_cast<const SvxHyperlinkItem*>(pItem); | ||||||||
269 | const OUString& rName = pHyper->GetName(); | ||||||||
270 | const OUString& rURL = pHyper->GetURL(); | ||||||||
271 | const OUString& rTarget = pHyper->GetTargetFrame(); | ||||||||
272 | SvxLinkInsertMode eMode = pHyper->GetInsertMode(); | ||||||||
273 | |||||||||
274 | bool bDone = false; | ||||||||
275 | if (eMode == HLINK_DEFAULT || eMode == HLINK_FIELD) | ||||||||
276 | { | ||||||||
277 | pOutView->SelectFieldAtCursor(); | ||||||||
278 | |||||||||
279 | // insert new field | ||||||||
280 | SvxURLField aURLField( rURL, rName, SvxURLFormat::Repr ); | ||||||||
281 | aURLField.SetTargetFrame( rTarget ); | ||||||||
282 | SvxFieldItem aURLItem( aURLField, EE_FEATURE_FIELD ); | ||||||||
283 | pOutView->InsertField( aURLItem ); | ||||||||
284 | |||||||||
285 | bDone = true; | ||||||||
286 | } | ||||||||
287 | |||||||||
288 | if (!bDone) | ||||||||
289 | ExecuteGlobal( rReq ); // normal at View | ||||||||
290 | |||||||||
291 | // If "text" is received by InsertURL of ViewShell, then the DrawShell is turned off !!! | ||||||||
292 | } | ||||||||
293 | } | ||||||||
294 | break; | ||||||||
295 | |||||||||
296 | case SID_OPEN_HYPERLINK( 10000 + 955 ): | ||||||||
297 | if (const SvxFieldData* pField = pOutView->GetFieldAtCursor()) | ||||||||
298 | { | ||||||||
299 | if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField)) | ||||||||
300 | { | ||||||||
301 | ScGlobal::OpenURL(pURLField->GetURL(), pURLField->GetTargetFrame(), true); | ||||||||
302 | } | ||||||||
303 | } | ||||||||
304 | break; | ||||||||
305 | |||||||||
306 | case SID_EDIT_HYPERLINK( 10000 + 978 ): | ||||||||
307 | { | ||||||||
308 | // Ensure the field is selected first | ||||||||
309 | pOutView->SelectFieldAtCursor(); | ||||||||
310 | mrViewData.GetViewShell()->GetViewFrame()->GetDispatcher()->Execute(SID_HYPERLINK_DIALOG(5000 + 678)); | ||||||||
311 | } | ||||||||
312 | break; | ||||||||
313 | |||||||||
314 | case SID_COPY_HYPERLINK_LOCATION( 10000 + 1193 ): | ||||||||
315 | { | ||||||||
316 | const SvxFieldData* pField = pOutView->GetFieldAtCursor(); | ||||||||
317 | if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField)) | ||||||||
318 | { | ||||||||
319 | uno::Reference<datatransfer::clipboard::XClipboard> xClipboard | ||||||||
320 | = pOutView->GetWindow()->GetClipboard(); | ||||||||
321 | vcl::unohelper::TextDataObject::CopyStringTo(pURLField->GetURL(), xClipboard); | ||||||||
322 | } | ||||||||
323 | } | ||||||||
324 | break; | ||||||||
325 | |||||||||
326 | case SID_REMOVE_HYPERLINK( 10000 + 459 ): | ||||||||
327 | { | ||||||||
328 | // Ensure the field is selected first | ||||||||
329 | URLFieldHelper::RemoveURLField(pOutView->GetEditView()); | ||||||||
330 | } | ||||||||
331 | break; | ||||||||
332 | |||||||||
333 | case SID_ENABLE_HYPHENATION((26000) + 87): | ||||||||
334 | case SID_TEXTDIRECTION_LEFT_TO_RIGHT( 10000 + 907 ): | ||||||||
335 | case SID_TEXTDIRECTION_TOP_TO_BOTTOM( 10000 + 908 ): | ||||||||
336 | pView->ScEndTextEdit(); // end text edit before switching direction | ||||||||
337 | ExecuteGlobal( rReq ); | ||||||||
338 | // restore consistent state between shells and functions: | ||||||||
339 | mrViewData.GetDispatcher().Execute(SID_OBJECT_SELECT( 10000 + 128 ), SfxCallMode::SLOT | SfxCallMode::RECORD); | ||||||||
340 | break; | ||||||||
341 | |||||||||
342 | case SID_THES(5000 + 698): | ||||||||
343 | { | ||||||||
344 | OUString aReplaceText; | ||||||||
345 | const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(SID_THES(5000 + 698)); | ||||||||
346 | if (pItem2) | ||||||||
347 | aReplaceText = pItem2->GetValue(); | ||||||||
348 | if (!aReplaceText.isEmpty()) | ||||||||
349 | ReplaceTextWithSynonym( pOutView->GetEditView(), aReplaceText ); | ||||||||
350 | } | ||||||||
351 | break; | ||||||||
352 | |||||||||
353 | case SID_THESAURUS( 10000 + 245 ): | ||||||||
354 | { | ||||||||
355 | pOutView->StartThesaurus(); | ||||||||
356 | } | ||||||||
357 | break; | ||||||||
358 | |||||||||
359 | } | ||||||||
360 | } | ||||||||
361 | |||||||||
362 | void ScDrawTextObjectBar::GetState( SfxItemSet& rSet ) | ||||||||
363 | { | ||||||||
364 | SfxViewFrame* pViewFrm = mrViewData.GetViewShell()->GetViewFrame(); | ||||||||
365 | bool bHasFontWork = pViewFrm->HasChildWindow(SID_FONTWORK( 10000 + 256 )); | ||||||||
366 | bool bDisableFontWork = false; | ||||||||
367 | |||||||||
368 | if (IsNoteEdit()) | ||||||||
369 | { | ||||||||
370 | // #i21255# notes now support rich text formatting (#i74140# but not fontwork) | ||||||||
371 | bDisableFontWork = true; | ||||||||
372 | } | ||||||||
373 | |||||||||
374 | if ( bDisableFontWork ) | ||||||||
375 | rSet.DisableItem( SID_FONTWORK( 10000 + 256 ) ); | ||||||||
376 | else | ||||||||
377 | rSet.Put(SfxBoolItem(SID_FONTWORK( 10000 + 256 ), bHasFontWork)); | ||||||||
378 | |||||||||
379 | if ( rSet.GetItemState( SID_HYPERLINK_GETLINK(10000 + 361) ) != SfxItemState::UNKNOWN ) | ||||||||
380 | { | ||||||||
381 | SvxHyperlinkItem aHLinkItem; | ||||||||
382 | SdrView* pView = mrViewData.GetScDrawView(); | ||||||||
383 | OutlinerView* pOutView = pView->GetTextEditOutlinerView(); | ||||||||
384 | if ( pOutView ) | ||||||||
385 | { | ||||||||
386 | bool bField = false; | ||||||||
387 | const SvxFieldData* pField = pOutView->GetFieldAtCursor(); | ||||||||
388 | if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField)) | ||||||||
389 | { | ||||||||
390 | aHLinkItem.SetName( pURLField->GetRepresentation() ); | ||||||||
391 | aHLinkItem.SetURL( pURLField->GetURL() ); | ||||||||
392 | aHLinkItem.SetTargetFrame( pURLField->GetTargetFrame() ); | ||||||||
393 | bField = true; | ||||||||
394 | } | ||||||||
395 | |||||||||
396 | if (!bField) | ||||||||
397 | { | ||||||||
398 | // use selected text as name for urls | ||||||||
399 | OUString sReturn = pOutView->GetSelected(); | ||||||||
400 | sal_Int32 nLen = std::min<sal_Int32>(sReturn.getLength(), 255); | ||||||||
401 | sReturn = sReturn.copy(0, nLen); | ||||||||
402 | aHLinkItem.SetName(comphelper::string::stripEnd(sReturn, ' ')); | ||||||||
403 | } | ||||||||
404 | } | ||||||||
405 | rSet.Put(aHLinkItem); | ||||||||
406 | } | ||||||||
407 | |||||||||
408 | if (rSet.GetItemState(SID_OPEN_HYPERLINK( 10000 + 955 )) != SfxItemState::UNKNOWN | ||||||||
409 | || rSet.GetItemState(SID_EDIT_HYPERLINK( 10000 + 978 )) != SfxItemState::UNKNOWN | ||||||||
410 | || rSet.GetItemState(SID_COPY_HYPERLINK_LOCATION( 10000 + 1193 )) != SfxItemState::UNKNOWN | ||||||||
411 | || rSet.GetItemState(SID_REMOVE_HYPERLINK( 10000 + 459 )) != SfxItemState::UNKNOWN) | ||||||||
412 | { | ||||||||
413 | SdrView* pView = mrViewData.GetScDrawView(); | ||||||||
414 | if( !URLFieldHelper::IsCursorAtURLField(pView->GetTextEditOutlinerView()) ) | ||||||||
415 | { | ||||||||
416 | rSet.DisableItem( SID_OPEN_HYPERLINK( 10000 + 955 ) ); | ||||||||
417 | rSet.DisableItem( SID_EDIT_HYPERLINK( 10000 + 978 ) ); | ||||||||
418 | rSet.DisableItem( SID_COPY_HYPERLINK_LOCATION( 10000 + 1193 ) ); | ||||||||
419 | rSet.DisableItem( SID_REMOVE_HYPERLINK( 10000 + 459 ) ); | ||||||||
420 | } | ||||||||
421 | } | ||||||||
422 | |||||||||
423 | if( rSet.GetItemState( SID_TRANSLITERATE_HALFWIDTH( 10000 + 914 ) ) != SfxItemState::UNKNOWN ) | ||||||||
424 | ScViewUtil::HideDisabledSlot( rSet, pViewFrm->GetBindings(), SID_TRANSLITERATE_HALFWIDTH( 10000 + 914 ) ); | ||||||||
425 | if( rSet.GetItemState( SID_TRANSLITERATE_FULLWIDTH( 10000 + 915 ) ) != SfxItemState::UNKNOWN ) | ||||||||
426 | ScViewUtil::HideDisabledSlot( rSet, pViewFrm->GetBindings(), SID_TRANSLITERATE_FULLWIDTH( 10000 + 915 ) ); | ||||||||
427 | if( rSet.GetItemState( SID_TRANSLITERATE_HIRAGANA( 10000 + 916 ) ) != SfxItemState::UNKNOWN ) | ||||||||
428 | ScViewUtil::HideDisabledSlot( rSet, pViewFrm->GetBindings(), SID_TRANSLITERATE_HIRAGANA( 10000 + 916 ) ); | ||||||||
429 | if( rSet.GetItemState( SID_TRANSLITERATE_KATAKANA( 10000 + 917 ) ) != SfxItemState::UNKNOWN ) | ||||||||
430 | ScViewUtil::HideDisabledSlot( rSet, pViewFrm->GetBindings(), SID_TRANSLITERATE_KATAKANA( 10000 + 917 ) ); | ||||||||
431 | |||||||||
432 | if ( rSet.GetItemState( SID_ENABLE_HYPHENATION((26000) + 87) ) != SfxItemState::UNKNOWN ) | ||||||||
433 | { | ||||||||
434 | SdrView* pView = mrViewData.GetScDrawView(); | ||||||||
435 | SfxItemSet aAttrs( pView->GetModel()->GetItemPool() ); | ||||||||
436 | pView->GetAttributes( aAttrs ); | ||||||||
437 | if( aAttrs.GetItemState( EE_PARA_HYPHENATE ) >= SfxItemState::DEFAULT ) | ||||||||
438 | { | ||||||||
439 | bool bValue = aAttrs.Get( EE_PARA_HYPHENATE ).GetValue(); | ||||||||
440 | rSet.Put( SfxBoolItem( SID_ENABLE_HYPHENATION((26000) + 87), bValue ) ); | ||||||||
441 | } | ||||||||
442 | } | ||||||||
443 | |||||||||
444 | if ( rSet.GetItemState( SID_THES(5000 + 698) ) != SfxItemState::UNKNOWN || | ||||||||
445 | rSet.GetItemState( SID_THESAURUS( 10000 + 245 ) ) != SfxItemState::UNKNOWN ) | ||||||||
446 | { | ||||||||
447 | SdrView * pView = mrViewData.GetScDrawView(); | ||||||||
448 | OutlinerView* pOutView = pView->GetTextEditOutlinerView(); | ||||||||
449 | |||||||||
450 | OUString aStatusVal; | ||||||||
451 | LanguageType nLang = LANGUAGE_NONELanguageType(0x00FF); | ||||||||
452 | bool bIsLookUpWord = false; | ||||||||
453 | if ( pOutView ) | ||||||||
454 | { | ||||||||
455 | EditView& rEditView = pOutView->GetEditView(); | ||||||||
456 | bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, rEditView ); | ||||||||
457 | } | ||||||||
458 | rSet.Put( SfxStringItem( SID_THES(5000 + 698), aStatusVal ) ); | ||||||||
459 | |||||||||
460 | // disable thesaurus main menu and context menu entry if there is nothing to look up | ||||||||
461 | bool bCanDoThesaurus = ScModule::HasThesaurusLanguage( nLang ); | ||||||||
462 | if (!bIsLookUpWord || !bCanDoThesaurus) | ||||||||
463 | rSet.DisableItem( SID_THES(5000 + 698) ); | ||||||||
464 | if (!bCanDoThesaurus) | ||||||||
465 | rSet.DisableItem( SID_THESAURUS( 10000 + 245 ) ); | ||||||||
466 | } | ||||||||
467 | |||||||||
468 | if (GetObjectShell()->isContentExtractionLocked()) | ||||||||
469 | { | ||||||||
470 | rSet.DisableItem(SID_COPY(5000 + 711)); | ||||||||
471 | rSet.DisableItem(SID_CUT(5000 + 710)); | ||||||||
472 | } | ||||||||
473 | } | ||||||||
474 | |||||||||
475 | IMPL_LINK( ScDrawTextObjectBar, ClipboardChanged, TransferableDataHelper*, pDataHelper, void )void ScDrawTextObjectBar::LinkStubClipboardChanged(void * instance , TransferableDataHelper* data) { return static_cast<ScDrawTextObjectBar *>(instance)->ClipboardChanged(data); } void ScDrawTextObjectBar ::ClipboardChanged(TransferableDataHelper* pDataHelper) | ||||||||
476 | { | ||||||||
477 | bPastePossible = ( pDataHelper->HasFormat( SotClipboardFormatId::STRING ) || pDataHelper->HasFormat( SotClipboardFormatId::RTF ) | ||||||||
478 | || pDataHelper->HasFormat( SotClipboardFormatId::RICHTEXT ) ); | ||||||||
479 | |||||||||
480 | SfxBindings& rBindings = mrViewData.GetBindings(); | ||||||||
481 | rBindings.Invalidate( SID_PASTE(5000 + 712) ); | ||||||||
482 | rBindings.Invalidate( SID_PASTE_SPECIAL(5000 + 311) ); | ||||||||
483 | rBindings.Invalidate( SID_PASTE_UNFORMATTED(5000 + 314) ); | ||||||||
484 | rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS(5000 + 312) ); | ||||||||
485 | } | ||||||||
486 | |||||||||
487 | void ScDrawTextObjectBar::GetClipState( SfxItemSet& rSet ) | ||||||||
488 | { | ||||||||
489 | SdrView* pView = mrViewData.GetScDrawView(); | ||||||||
490 | if ( !pView->GetTextEditOutlinerView() ) | ||||||||
491 | { | ||||||||
492 | GetGlobalClipState( rSet ); | ||||||||
493 | return; | ||||||||
494 | } | ||||||||
495 | |||||||||
496 | if ( !mxClipEvtLstnr.is() ) | ||||||||
497 | { | ||||||||
498 | // create listener | ||||||||
499 | mxClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScDrawTextObjectBar, ClipboardChanged )::tools::detail::makeLink( ::tools::detail::castTo<ScDrawTextObjectBar *>(this), &ScDrawTextObjectBar::LinkStubClipboardChanged ) ); | ||||||||
500 | vcl::Window* pWin = mrViewData.GetActiveWin(); | ||||||||
501 | mxClipEvtLstnr->AddListener( pWin ); | ||||||||
502 | |||||||||
503 | // get initial state | ||||||||
504 | TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mrViewData.GetActiveWin() ) ); | ||||||||
505 | bPastePossible = ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) || aDataHelper.HasFormat( SotClipboardFormatId::RTF ) | ||||||||
506 | || aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) ); | ||||||||
507 | } | ||||||||
508 | |||||||||
509 | SfxWhichIter aIter( rSet ); | ||||||||
510 | sal_uInt16 nWhich = aIter.FirstWhich(); | ||||||||
511 | while (nWhich) | ||||||||
512 | { | ||||||||
513 | switch (nWhich) | ||||||||
514 | { | ||||||||
515 | case SID_PASTE(5000 + 712): | ||||||||
516 | case SID_PASTE_SPECIAL(5000 + 311): | ||||||||
517 | case SID_PASTE_UNFORMATTED(5000 + 314): | ||||||||
518 | if( !bPastePossible ) | ||||||||
519 | rSet.DisableItem( nWhich ); | ||||||||
520 | break; | ||||||||
521 | case SID_CLIPBOARD_FORMAT_ITEMS(5000 + 312): | ||||||||
522 | if ( bPastePossible ) | ||||||||
523 | { | ||||||||
524 | SvxClipboardFormatItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS(5000 + 312) ); | ||||||||
525 | TransferableDataHelper aDataHelper( | ||||||||
526 | TransferableDataHelper::CreateFromSystemClipboard( mrViewData.GetActiveWin() ) ); | ||||||||
527 | |||||||||
528 | if ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) ) | ||||||||
529 | aFormats.AddClipbrdFormat( SotClipboardFormatId::STRING ); | ||||||||
530 | if ( aDataHelper.HasFormat( SotClipboardFormatId::RTF ) ) | ||||||||
531 | aFormats.AddClipbrdFormat( SotClipboardFormatId::RTF ); | ||||||||
532 | if ( aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) ) | ||||||||
533 | aFormats.AddClipbrdFormat( SotClipboardFormatId::RICHTEXT ); | ||||||||
534 | |||||||||
535 | rSet.Put( aFormats ); | ||||||||
536 | } | ||||||||
537 | else | ||||||||
538 | rSet.DisableItem( nWhich ); | ||||||||
539 | break; | ||||||||
540 | } | ||||||||
541 | nWhich = aIter.NextWhich(); | ||||||||
542 | } | ||||||||
543 | } | ||||||||
544 | |||||||||
545 | // Attributes | ||||||||
546 | |||||||||
547 | void ScDrawTextObjectBar::ExecuteToggle( SfxRequest &rReq ) | ||||||||
548 | { | ||||||||
549 | // Underline | ||||||||
550 | |||||||||
551 | SdrView* pView = mrViewData.GetScDrawView(); | ||||||||
552 | |||||||||
553 | sal_uInt16 nSlot = rReq.GetSlot(); | ||||||||
554 | |||||||||
555 | SfxItemSet aSet( pView->GetDefaultAttr() ); | ||||||||
556 | |||||||||
557 | SfxItemSet aViewAttr(pView->GetModel()->GetItemPool()); | ||||||||
558 | pView->GetAttributes(aViewAttr); | ||||||||
559 | |||||||||
560 | // Underline | ||||||||
561 | FontLineStyle eOld = aViewAttr.Get(EE_CHAR_UNDERLINE).GetLineStyle(); | ||||||||
562 | FontLineStyle eNew = eOld; | ||||||||
563 | switch (nSlot) | ||||||||
564 | { | ||||||||
565 | case SID_ULINE_VAL_NONE(10000 + 1195): | ||||||||
566 | eNew = LINESTYLE_NONE; | ||||||||
567 | break; | ||||||||
568 | case SID_ULINE_VAL_SINGLE(10000 + 1196): | ||||||||
569 | eNew = ( eOld == LINESTYLE_SINGLE ) ? LINESTYLE_NONE : LINESTYLE_SINGLE; | ||||||||
570 | break; | ||||||||
571 | case SID_ULINE_VAL_DOUBLE(10000 + 1197): | ||||||||
572 | eNew = ( eOld == LINESTYLE_DOUBLE ) ? LINESTYLE_NONE : LINESTYLE_DOUBLE; | ||||||||
573 | break; | ||||||||
574 | case SID_ULINE_VAL_DOTTED(10000 + 1198): | ||||||||
575 | eNew = ( eOld == LINESTYLE_DOTTED ) ? LINESTYLE_NONE : LINESTYLE_DOTTED; | ||||||||
576 | break; | ||||||||
577 | default: | ||||||||
578 | break; | ||||||||
579 | } | ||||||||
580 | aSet.Put( SvxUnderlineItem( eNew, EE_CHAR_UNDERLINE ) ); | ||||||||
581 | |||||||||
582 | pView->SetAttributes( aSet ); | ||||||||
583 | rReq.Done(); | ||||||||
584 | mrViewData.GetScDrawView()->InvalidateDrawTextAttrs(); | ||||||||
585 | } | ||||||||
586 | |||||||||
587 | static void lcl_RemoveFields( OutlinerView& rOutView ) | ||||||||
588 | { | ||||||||
589 | //! Outliner should have RemoveFields with a selection | ||||||||
590 | |||||||||
591 | Outliner* pOutliner = rOutView.GetOutliner(); | ||||||||
592 | if (!pOutliner) return; | ||||||||
593 | |||||||||
594 | ESelection aOldSel = rOutView.GetSelection(); | ||||||||
595 | ESelection aSel = aOldSel; | ||||||||
596 | aSel.Adjust(); | ||||||||
597 | sal_Int32 nNewEnd = aSel.nEndPos; | ||||||||
598 | |||||||||
599 | bool bUpdate = pOutliner->GetUpdateMode(); | ||||||||
600 | bool bChanged = false; | ||||||||
601 | |||||||||
602 | //! GetPortions and GetAttribs should be const! | ||||||||
603 | EditEngine& rEditEng = const_cast<EditEngine&>(pOutliner->GetEditEngine()); | ||||||||
604 | |||||||||
605 | sal_Int32 nParCount = pOutliner->GetParagraphCount(); | ||||||||
606 | for (sal_Int32 nPar=0; nPar<nParCount; nPar++) | ||||||||
607 | if ( nPar >= aSel.nStartPara && nPar <= aSel.nEndPara ) | ||||||||
608 | { | ||||||||
609 | std::vector<sal_Int32> aPortions; | ||||||||
610 | rEditEng.GetPortions( nPar, aPortions ); | ||||||||
611 | |||||||||
612 | for ( size_t nPos = aPortions.size(); nPos; ) | ||||||||
613 | { | ||||||||
614 | --nPos; | ||||||||
615 | sal_Int32 nEnd = aPortions[ nPos ]; | ||||||||
616 | sal_Int32 nStart = nPos ? aPortions[ nPos - 1 ] : 0; | ||||||||
617 | // fields are single characters | ||||||||
618 | if ( nEnd == nStart+1 && | ||||||||
619 | ( nPar > aSel.nStartPara || nStart >= aSel.nStartPos ) && | ||||||||
620 | ( nPar < aSel.nEndPara || nEnd <= aSel.nEndPos ) ) | ||||||||
621 | { | ||||||||
622 | ESelection aFieldSel( nPar, nStart, nPar, nEnd ); | ||||||||
623 | SfxItemSet aSet = rEditEng.GetAttribs( aFieldSel ); | ||||||||
624 | if ( aSet.GetItemState( EE_FEATURE_FIELD ) == SfxItemState::SET ) | ||||||||
625 | { | ||||||||
626 | if (!bChanged) | ||||||||
627 | { | ||||||||
628 | if (bUpdate) | ||||||||
629 | pOutliner->SetUpdateMode( false ); | ||||||||
630 | OUString aName = ScResId( STR_UNDO_DELETECONTENTSreinterpret_cast<char const *>("STR_UNDO_DELETECONTENTS" "\004" u8"Delete") ); | ||||||||
631 | ViewShellId nViewShellId(-1); | ||||||||
632 | if (ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell()) | ||||||||
633 | nViewShellId = pViewSh->GetViewShellId(); | ||||||||
634 | pOutliner->GetUndoManager().EnterListAction( aName, aName, 0, nViewShellId ); | ||||||||
635 | bChanged = true; | ||||||||
636 | } | ||||||||
637 | |||||||||
638 | OUString aFieldText = rEditEng.GetText( aFieldSel ); | ||||||||
639 | pOutliner->QuickInsertText( aFieldText, aFieldSel ); | ||||||||
640 | if ( nPar == aSel.nEndPara ) | ||||||||
641 | { | ||||||||
642 | nNewEnd = nNewEnd + aFieldText.getLength(); | ||||||||
643 | --nNewEnd; | ||||||||
644 | } | ||||||||
645 | } | ||||||||
646 | } | ||||||||
647 | } | ||||||||
648 | } | ||||||||
649 | |||||||||
650 | if (bUpdate && bChanged) | ||||||||
651 | { | ||||||||
652 | pOutliner->GetUndoManager().LeaveListAction(); | ||||||||
653 | pOutliner->SetUpdateMode( true ); | ||||||||
654 | } | ||||||||
655 | |||||||||
656 | if ( aOldSel == aSel ) // aSel is adjusted | ||||||||
657 | aOldSel.nEndPos = nNewEnd; | ||||||||
658 | else | ||||||||
659 | aOldSel.nStartPos = nNewEnd; // if aOldSel is backwards | ||||||||
660 | rOutView.SetSelection( aOldSel ); | ||||||||
661 | } | ||||||||
662 | |||||||||
663 | void ScDrawTextObjectBar::ExecuteAttr( SfxRequest &rReq ) | ||||||||
664 | { | ||||||||
665 | SdrView* pView = mrViewData.GetScDrawView(); | ||||||||
666 | const SfxItemSet* pArgs = rReq.GetArgs(); | ||||||||
667 | sal_uInt16 nSlot = rReq.GetSlot(); | ||||||||
668 | |||||||||
669 | SfxItemSet aEditAttr( pView->GetModel()->GetItemPool() ); | ||||||||
670 | pView->GetAttributes( aEditAttr ); | ||||||||
671 | SfxItemSet aNewAttr( *aEditAttr.GetPool(), aEditAttr.GetRanges() ); | ||||||||
672 | |||||||||
673 | bool bSet = true; | ||||||||
674 | switch ( nSlot ) | ||||||||
| |||||||||
675 | { | ||||||||
676 | case SID_ALIGNLEFT((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22 )) + 20)) + 29)) + 20))+6): | ||||||||
677 | case SID_ALIGN_ANY_LEFT( 10000 + 1002 ): | ||||||||
678 | case SID_ATTR_PARA_ADJUST_LEFT( 10000 + 28 ): | ||||||||
679 | aNewAttr.Put( SvxAdjustItem( SvxAdjust::Left, EE_PARA_JUST ) ); | ||||||||
680 | break; | ||||||||
681 | |||||||||
682 | case SID_ALIGNCENTERHOR((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22 )) + 20)) + 29)) + 20))+8): | ||||||||
683 | case SID_ALIGN_ANY_HCENTER( 10000 + 1003 ): | ||||||||
684 | case SID_ATTR_PARA_ADJUST_CENTER( 10000 + 30 ): | ||||||||
685 | aNewAttr.Put( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) ); | ||||||||
686 | break; | ||||||||
687 | |||||||||
688 | case SID_ALIGNRIGHT((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22 )) + 20)) + 29)) + 20))+7): | ||||||||
689 | case SID_ALIGN_ANY_RIGHT( 10000 + 1004 ): | ||||||||
690 | case SID_ATTR_PARA_ADJUST_RIGHT( 10000 + 29 ): | ||||||||
691 | aNewAttr.Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) ); | ||||||||
692 | break; | ||||||||
693 | |||||||||
694 | case SID_ALIGNBLOCK((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22 )) + 20)) + 29)) + 20))+9): | ||||||||
695 | case SID_ALIGN_ANY_JUSTIFIED( 10000 + 1005 ): | ||||||||
696 | case SID_ATTR_PARA_ADJUST_BLOCK( 10000 + 31 ): | ||||||||
697 | aNewAttr.Put( SvxAdjustItem( SvxAdjust::Block, EE_PARA_JUST ) ); | ||||||||
698 | break; | ||||||||
699 | |||||||||
700 | case SID_ATTR_PARA_LINESPACE_10( 10000 + 34 ): | ||||||||
701 | { | ||||||||
702 | SvxLineSpacingItem aItem( LINE_SPACE_DEFAULT_HEIGHT200, EE_PARA_SBL ); | ||||||||
703 | aItem.SetPropLineSpace( 100 ); | ||||||||
704 | aNewAttr.Put( aItem ); | ||||||||
705 | } | ||||||||
706 | break; | ||||||||
707 | |||||||||
708 | case SID_ATTR_PARA_LINESPACE_15( 10000 + 35 ): | ||||||||
709 | { | ||||||||
710 | SvxLineSpacingItem aItem( LINE_SPACE_DEFAULT_HEIGHT200, EE_PARA_SBL ); | ||||||||
711 | aItem.SetPropLineSpace( 150 ); | ||||||||
712 | aNewAttr.Put( aItem ); | ||||||||
713 | } | ||||||||
714 | break; | ||||||||
715 | |||||||||
716 | case SID_ATTR_PARA_LINESPACE_20( 10000 + 36 ): | ||||||||
717 | { | ||||||||
718 | SvxLineSpacingItem aItem( LINE_SPACE_DEFAULT_HEIGHT200, EE_PARA_SBL ); | ||||||||
719 | aItem.SetPropLineSpace( 200 ); | ||||||||
720 | aNewAttr.Put( aItem ); | ||||||||
721 | } | ||||||||
722 | break; | ||||||||
723 | |||||||||
724 | case SID_SET_SUPER_SCRIPT( 10000 + 294 ): | ||||||||
725 | { | ||||||||
726 | SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT); | ||||||||
727 | SvxEscapement eEsc = static_cast<SvxEscapement>(aEditAttr.Get( EE_CHAR_ESCAPEMENT ).GetEnumValue()); | ||||||||
728 | |||||||||
729 | if( eEsc == SvxEscapement::Superscript ) | ||||||||
730 | aItem.SetEscapement( SvxEscapement::Off ); | ||||||||
731 | else | ||||||||
732 | aItem.SetEscapement( SvxEscapement::Superscript ); | ||||||||
733 | aNewAttr.Put( aItem ); | ||||||||
734 | } | ||||||||
735 | break; | ||||||||
736 | |||||||||
737 | case SID_SET_SUB_SCRIPT( 10000 + 295 ): | ||||||||
738 | { | ||||||||
739 | SvxEscapementItem aItem(EE_CHAR_ESCAPEMENT); | ||||||||
740 | SvxEscapement eEsc = static_cast<SvxEscapement>(aEditAttr.Get( EE_CHAR_ESCAPEMENT ).GetEnumValue()); | ||||||||
741 | |||||||||
742 | if( eEsc == SvxEscapement::Subscript ) | ||||||||
743 | aItem.SetEscapement( SvxEscapement::Off ); | ||||||||
744 | else | ||||||||
745 | aItem.SetEscapement( SvxEscapement::Subscript ); | ||||||||
746 | aNewAttr.Put( aItem ); | ||||||||
747 | } | ||||||||
748 | break; | ||||||||
749 | |||||||||
750 | case SID_TABLE_VERT_NONE( 10000 + 1075 ): | ||||||||
751 | case SID_TABLE_VERT_CENTER( 10000 + 1074 ): | ||||||||
752 | case SID_TABLE_VERT_BOTTOM( 10000 + 1073 ): | ||||||||
753 | { | ||||||||
754 | SdrTextVertAdjust eTVA = SDRTEXTVERTADJUST_TOP; | ||||||||
755 | if (nSlot == SID_TABLE_VERT_CENTER( 10000 + 1074 )) | ||||||||
756 | eTVA = SDRTEXTVERTADJUST_CENTER; | ||||||||
757 | else if (nSlot == SID_TABLE_VERT_BOTTOM( 10000 + 1073 )) | ||||||||
758 | eTVA = SDRTEXTVERTADJUST_BOTTOM; | ||||||||
759 | aNewAttr.Put(SdrTextVertAdjustItem(eTVA)); | ||||||||
760 | } | ||||||||
761 | break; | ||||||||
762 | |||||||||
763 | case SID_PARASPACE_INCREASE( 10000 + 1145 ): | ||||||||
764 | case SID_PARASPACE_DECREASE( 10000 + 1146 ): | ||||||||
765 | { | ||||||||
766 | SvxULSpaceItem aULSpace( aEditAttr.Get( EE_PARA_ULSPACE ) ); | ||||||||
767 | sal_uInt16 nUpper = aULSpace.GetUpper(); | ||||||||
768 | sal_uInt16 nLower = aULSpace.GetLower(); | ||||||||
769 | |||||||||
770 | if ( nSlot == SID_PARASPACE_INCREASE( 10000 + 1145 ) ) | ||||||||
771 | { | ||||||||
772 | nUpper += 100; | ||||||||
773 | nLower += 100; | ||||||||
774 | } | ||||||||
775 | else | ||||||||
776 | { | ||||||||
777 | nUpper = std::max< sal_Int16 >( nUpper - 100, 0 ); | ||||||||
778 | nLower = std::max< sal_Int16 >( nLower - 100, 0 ); | ||||||||
779 | } | ||||||||
780 | |||||||||
781 | aULSpace.SetUpper( nUpper ); | ||||||||
782 | aULSpace.SetLower( nLower ); | ||||||||
783 | aNewAttr.Put( aULSpace ); | ||||||||
784 | } | ||||||||
785 | break; | ||||||||
786 | |||||||||
787 | default: | ||||||||
788 | bSet = false; | ||||||||
789 | } | ||||||||
790 | |||||||||
791 | bool bDone = true; | ||||||||
792 | bool bArgsInReq = ( pArgs != nullptr ); | ||||||||
793 | |||||||||
794 | if ( !bArgsInReq
| ||||||||
795 | { | ||||||||
796 | switch ( nSlot ) | ||||||||
797 | { | ||||||||
798 | case SID_TEXT_STANDARD((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 18): // delete hard text attributes | ||||||||
799 | { | ||||||||
800 | OutlinerView* pOutView = pView->IsTextEdit() ? | ||||||||
801 | pView->GetTextEditOutlinerView() : nullptr; | ||||||||
802 | if ( pOutView ) | ||||||||
803 | pOutView->Paint( tools::Rectangle() ); | ||||||||
804 | |||||||||
805 | SfxItemSet aEmptyAttr( *aEditAttr.GetPool(), svl::Items<EE_ITEMS_START, EE_ITEMS_END>{} ); | ||||||||
806 | pView->SetAttributes( aEmptyAttr, true ); | ||||||||
807 | |||||||||
808 | if ( pOutView ) | ||||||||
809 | { | ||||||||
810 | lcl_RemoveFields( *pOutView ); | ||||||||
811 | pOutView->ShowCursor(); | ||||||||
812 | } | ||||||||
813 | |||||||||
814 | rReq.Done( aEmptyAttr ); | ||||||||
815 | mrViewData.GetScDrawView()->InvalidateDrawTextAttrs(); | ||||||||
816 | bDone = false; // already happened here | ||||||||
817 | } | ||||||||
818 | break; | ||||||||
819 | |||||||||
820 | case SID_GROW_FONT_SIZE( 10000 + 1042 ): | ||||||||
821 | case SID_SHRINK_FONT_SIZE( 10000 + 1043 ): | ||||||||
822 | { | ||||||||
823 | OutlinerView* pOutView = pView->IsTextEdit() ? | ||||||||
824 | pView->GetTextEditOutlinerView() : nullptr; | ||||||||
825 | if ( pOutView ) | ||||||||
826 | { | ||||||||
827 | const SvxFontListItem* pFontListItem = static_cast< const SvxFontListItem* > | ||||||||
828 | ( SfxObjectShell::Current()->GetItem( SID_ATTR_CHAR_FONTLIST( 10000 + 22 ) ) ); | ||||||||
829 | const FontList* pFontList = pFontListItem ? pFontListItem->GetFontList() : nullptr; | ||||||||
830 | pOutView->GetEditView().ChangeFontSize( nSlot == SID_GROW_FONT_SIZE( 10000 + 1042 ), pFontList ); | ||||||||
831 | mrViewData.GetBindings().Invalidate( SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ) ); | ||||||||
832 | bDone = false; | ||||||||
833 | } | ||||||||
834 | } | ||||||||
835 | break; | ||||||||
836 | |||||||||
837 | case SID_CHAR_DLG_EFFECT( 10000 + 1133 ): | ||||||||
838 | case SID_CHAR_DLG( 10000 + 296 ): // dialog button | ||||||||
839 | case SID_ATTR_CHAR_FONT( 10000 + 7 ): // Controller not shown | ||||||||
840 | case SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ): | ||||||||
841 | bDone = ExecuteCharDlg( aEditAttr, aNewAttr , nSlot); | ||||||||
842 | break; | ||||||||
843 | |||||||||
844 | case SID_PARA_DLG( 10000 + 297 ): | ||||||||
845 | bDone = ExecuteParaDlg( aEditAttr, aNewAttr ); | ||||||||
846 | break; | ||||||||
847 | |||||||||
848 | case SID_ATTR_CHAR_WEIGHT( 10000 + 9 ): | ||||||||
849 | aNewAttr.Put( aEditAttr.Get( EE_CHAR_WEIGHT ) ); | ||||||||
850 | break; | ||||||||
851 | |||||||||
852 | case SID_ATTR_CHAR_POSTURE( 10000 + 8 ): | ||||||||
853 | aNewAttr.Put( aEditAttr.Get( EE_CHAR_ITALIC ) ); | ||||||||
854 | break; | ||||||||
855 | |||||||||
856 | case SID_ATTR_CHAR_UNDERLINE( 10000 + 14 ): | ||||||||
857 | aNewAttr.Put( aEditAttr.Get( EE_CHAR_UNDERLINE ) ); | ||||||||
858 | break; | ||||||||
859 | |||||||||
860 | case SID_ATTR_CHAR_OVERLINE( ((10000 + 1499) + 1) + 68 ): | ||||||||
861 | aNewAttr.Put( aEditAttr.Get( EE_CHAR_OVERLINE ) ); | ||||||||
862 | break; | ||||||||
863 | |||||||||
864 | case SID_ATTR_CHAR_CONTOUR( 10000 + 12 ): | ||||||||
865 | aNewAttr.Put( aEditAttr.Get( EE_CHAR_OUTLINE ) ); | ||||||||
866 | break; | ||||||||
867 | |||||||||
868 | case SID_ATTR_CHAR_SHADOWED( 10000 + 10 ): | ||||||||
869 | aNewAttr.Put( aEditAttr.Get( EE_CHAR_SHADOW ) ); | ||||||||
870 | break; | ||||||||
871 | |||||||||
872 | case SID_ATTR_CHAR_STRIKEOUT( 10000 + 13 ): | ||||||||
873 | aNewAttr.Put( aEditAttr.Get( EE_CHAR_STRIKEOUT ) ); | ||||||||
874 | break; | ||||||||
875 | |||||||||
876 | case SID_DRAWTEXT_ATTR_DLG((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 19): | ||||||||
877 | { | ||||||||
878 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); | ||||||||
879 | ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTextTabDialog(mrViewData.GetDialogParent(), &aEditAttr, pView)); | ||||||||
880 | |||||||||
881 | bDone = ( RET_OK == pDlg->Execute() ); | ||||||||
882 | |||||||||
883 | if ( bDone ) | ||||||||
884 | aNewAttr.Put( *pDlg->GetOutputItemSet() ); | ||||||||
885 | |||||||||
886 | pDlg.disposeAndClear(); | ||||||||
887 | |||||||||
888 | SfxBindings& rBindings = mrViewData.GetBindings(); | ||||||||
889 | rBindings.Invalidate( SID_TABLE_VERT_NONE( 10000 + 1075 ) ); | ||||||||
890 | rBindings.Invalidate( SID_TABLE_VERT_CENTER( 10000 + 1074 ) ); | ||||||||
891 | rBindings.Invalidate( SID_TABLE_VERT_BOTTOM( 10000 + 1073 ) ); | ||||||||
892 | } | ||||||||
893 | break; | ||||||||
894 | } | ||||||||
895 | } | ||||||||
896 | |||||||||
897 | if ( bSet || bDone ) | ||||||||
898 | { | ||||||||
899 | rReq.Done( aNewAttr ); | ||||||||
900 | pArgs = rReq.GetArgs(); | ||||||||
901 | } | ||||||||
902 | |||||||||
903 | if ( !pArgs ) | ||||||||
904 | return; | ||||||||
905 | |||||||||
906 | if ( bArgsInReq && | ||||||||
907 | ( nSlot == SID_ATTR_CHAR_FONT( 10000 + 7 ) || nSlot == SID_ATTR_CHAR_FONTHEIGHT( 10000 + 15 ) || | ||||||||
908 | nSlot == SID_ATTR_CHAR_WEIGHT( 10000 + 9 ) || nSlot == SID_ATTR_CHAR_POSTURE( 10000 + 8 ) ) ) | ||||||||
909 | { | ||||||||
910 | // font items from toolbox controller have to be applied for the right script type | ||||||||
911 | |||||||||
912 | // #i78017 establish the same behaviour as in Writer | ||||||||
913 | SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX; | ||||||||
914 | if (nSlot == SID_ATTR_CHAR_FONT( 10000 + 7 )) | ||||||||
915 | nScript = pView->GetScriptType(); | ||||||||
916 | |||||||||
917 | SfxItemPool& rPool = GetPool(); | ||||||||
918 | SvxScriptSetItem aSetItem( nSlot, rPool ); | ||||||||
919 | sal_uInt16 nWhich = rPool.GetWhich( nSlot ); | ||||||||
920 | aSetItem.PutItemForScriptType( nScript, pArgs->Get( nWhich ) ); | ||||||||
921 | |||||||||
922 | pView->SetAttributes( aSetItem.GetItemSet() ); | ||||||||
923 | } | ||||||||
924 | else if( nSlot == SID_ATTR_PARA_LRSPACE( 10000 + 43 ) ) | ||||||||
925 | { | ||||||||
926 | sal_uInt16 nId = SID_ATTR_PARA_LRSPACE( 10000 + 43 ); | ||||||||
927 | const SvxLRSpaceItem& rItem = static_cast<const SvxLRSpaceItem&>( | ||||||||
928 | pArgs->Get( nId )); | ||||||||
929 | SfxItemSet aAttr( GetPool(), svl::Items<EE_PARA_LRSPACE, EE_PARA_LRSPACE>{} ); | ||||||||
930 | nId = EE_PARA_LRSPACE; | ||||||||
931 | SvxLRSpaceItem aLRSpaceItem( rItem.GetLeft(), | ||||||||
932 | rItem.GetRight(), rItem.GetTextLeft(), | ||||||||
933 | rItem.GetTextFirstLineOffset(), nId ); | ||||||||
934 | aAttr.Put( aLRSpaceItem ); | ||||||||
935 | pView->SetAttributes( aAttr ); | ||||||||
936 | } | ||||||||
937 | else if( nSlot == SID_ATTR_PARA_LINESPACE( 10000 + 33 ) ) | ||||||||
938 | { | ||||||||
939 | SvxLineSpacingItem aLineSpaceItem = static_cast<const SvxLineSpacingItem&>(pArgs->Get( | ||||||||
940 | GetPool().GetWhich(nSlot))); | ||||||||
941 | SfxItemSet aAttr( GetPool(), svl::Items<EE_PARA_SBL, EE_PARA_SBL>{} ); | ||||||||
942 | aAttr.Put( aLineSpaceItem ); | ||||||||
943 | pView->SetAttributes( aAttr ); | ||||||||
944 | } | ||||||||
945 | else if( nSlot == SID_ATTR_PARA_ULSPACE( 10000 + 42 ) ) | ||||||||
946 | { | ||||||||
947 | SvxULSpaceItem aULSpaceItem = static_cast<const SvxULSpaceItem&>(pArgs->Get( | ||||||||
948 | GetPool().GetWhich(nSlot))); | ||||||||
949 | SfxItemSet aAttr( GetPool(), svl::Items<EE_PARA_ULSPACE, EE_PARA_ULSPACE>{} ); | ||||||||
950 | aULSpaceItem.SetWhich(EE_PARA_ULSPACE); | ||||||||
951 | aAttr.Put( aULSpaceItem ); | ||||||||
952 | pView->SetAttributes( aAttr ); | ||||||||
953 | } | ||||||||
954 | else | ||||||||
955 | { | ||||||||
956 | // use args directly | ||||||||
957 | pView->SetAttributes( *pArgs ); | ||||||||
958 | } | ||||||||
959 | mrViewData.GetScDrawView()->InvalidateDrawTextAttrs(); | ||||||||
960 | } | ||||||||
961 | |||||||||
962 | void ScDrawTextObjectBar::GetAttrState( SfxItemSet& rDestSet ) | ||||||||
963 | { | ||||||||
964 | if ( IsNoteEdit() ) | ||||||||
965 | { | ||||||||
966 | // issue 21255 - Notes now support rich text formatting. | ||||||||
967 | } | ||||||||
968 | |||||||||
969 | SvtLanguageOptions aLangOpt; | ||||||||
970 | bool bDisableCTLFont = !aLangOpt.IsCTLFontEnabled(); | ||||||||
971 | bool bDisableVerticalText = !aLangOpt.IsVerticalTextEnabled(); | ||||||||
972 | |||||||||
973 | SdrView* pView = mrViewData.GetScDrawView(); | ||||||||
974 | SfxItemSet aAttrSet(pView->GetModel()->GetItemPool()); | ||||||||
975 | pView->GetAttributes(aAttrSet); | ||||||||
976 | |||||||||
977 | // direct attributes | ||||||||
978 | |||||||||
979 | rDestSet.Put( aAttrSet ); | ||||||||
980 | |||||||||
981 | // choose font info according to selection script type | ||||||||
982 | |||||||||
983 | SvtScriptType nScript = pView->GetScriptType(); | ||||||||
984 | |||||||||
985 | // #i55929# input-language-dependent script type (depends on input language if nothing selected) | ||||||||
986 | SvtScriptType nInputScript = nScript; | ||||||||
987 | OutlinerView* pOutView = pView->GetTextEditOutlinerView(); | ||||||||
988 | if (pOutView && !pOutView->GetSelection().HasRange()) | ||||||||
989 | { | ||||||||
990 | LanguageType nInputLang = mrViewData.GetActiveWin()->GetInputLanguage(); | ||||||||
991 | if (nInputLang != LANGUAGE_DONTKNOWLanguageType(0x03FF) && nInputLang != LANGUAGE_SYSTEMLanguageType(0x0000)) | ||||||||
992 | nInputScript = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang ); | ||||||||
993 | } | ||||||||
994 | |||||||||
995 | // #i55929# according to spec, nInputScript is used for font and font height only | ||||||||
996 | if ( rDestSet.GetItemState( EE_CHAR_FONTINFO ) != SfxItemState::UNKNOWN ) | ||||||||
997 | ScViewUtil::PutItemScript( rDestSet, aAttrSet, EE_CHAR_FONTINFO, nInputScript ); | ||||||||
998 | if ( rDestSet.GetItemState( EE_CHAR_FONTHEIGHT ) != SfxItemState::UNKNOWN ) | ||||||||
999 | ScViewUtil::PutItemScript( rDestSet, aAttrSet, EE_CHAR_FONTHEIGHT, nInputScript ); | ||||||||
1000 | if ( rDestSet.GetItemState( EE_CHAR_WEIGHT ) != SfxItemState::UNKNOWN ) | ||||||||
1001 | ScViewUtil::PutItemScript( rDestSet, aAttrSet, EE_CHAR_WEIGHT, nScript ); | ||||||||
1002 | if ( rDestSet.GetItemState( EE_CHAR_ITALIC ) != SfxItemState::UNKNOWN ) | ||||||||
1003 | ScViewUtil::PutItemScript( rDestSet, aAttrSet, EE_CHAR_ITALIC, nScript ); | ||||||||
1004 | // Alignment | ||||||||
1005 | |||||||||
1006 | SvxAdjust eAdj = aAttrSet.Get(EE_PARA_JUST).GetAdjust(); | ||||||||
1007 | switch( eAdj ) | ||||||||
1008 | { | ||||||||
1009 | case SvxAdjust::Left: | ||||||||
1010 | { | ||||||||
1011 | rDestSet.Put( SfxBoolItem( SID_ALIGNLEFT((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22 )) + 20)) + 29)) + 20))+6), true ) ); | ||||||||
1012 | rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_LEFT( 10000 + 28 ), true ) ); | ||||||||
1013 | } | ||||||||
1014 | break; | ||||||||
1015 | case SvxAdjust::Center: | ||||||||
1016 | { | ||||||||
1017 | rDestSet.Put( SfxBoolItem( SID_ALIGNCENTERHOR((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22 )) + 20)) + 29)) + 20))+8), true ) ); | ||||||||
1018 | rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_CENTER( 10000 + 30 ), true ) ); | ||||||||
1019 | } | ||||||||
1020 | break; | ||||||||
1021 | case SvxAdjust::Right: | ||||||||
1022 | { | ||||||||
1023 | rDestSet.Put( SfxBoolItem( SID_ALIGNRIGHT((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22 )) + 20)) + 29)) + 20))+7), true ) ); | ||||||||
1024 | rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_RIGHT( 10000 + 29 ), true ) ); | ||||||||
1025 | } | ||||||||
1026 | break; | ||||||||
1027 | case SvxAdjust::Block: | ||||||||
1028 | { | ||||||||
1029 | rDestSet.Put( SfxBoolItem( SID_ALIGNBLOCK((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22 )) + 20)) + 29)) + 20))+9), true ) ); | ||||||||
1030 | rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_ADJUST_BLOCK( 10000 + 31 ), true ) ); | ||||||||
1031 | } | ||||||||
1032 | break; | ||||||||
1033 | default: | ||||||||
1034 | { | ||||||||
1035 | // added to avoid warnings | ||||||||
1036 | } | ||||||||
1037 | } | ||||||||
1038 | // pseudo slots for Format menu | ||||||||
1039 | rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_LEFT( 10000 + 1002 ), eAdj == SvxAdjust::Left ) ); | ||||||||
1040 | rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_HCENTER( 10000 + 1003 ), eAdj == SvxAdjust::Center ) ); | ||||||||
1041 | rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_RIGHT( 10000 + 1004 ), eAdj == SvxAdjust::Right ) ); | ||||||||
1042 | rDestSet.Put( SfxBoolItem( SID_ALIGN_ANY_JUSTIFIED( 10000 + 1005 ), eAdj == SvxAdjust::Block ) ); | ||||||||
1043 | |||||||||
1044 | SvxLRSpaceItem aLR = aAttrSet.Get( EE_PARA_LRSPACE ); | ||||||||
1045 | aLR.SetWhich(SID_ATTR_PARA_LRSPACE( 10000 + 43 )); | ||||||||
1046 | rDestSet.Put(aLR); | ||||||||
1047 | Invalidate( SID_ATTR_PARA_LRSPACE( 10000 + 43 ) ); | ||||||||
1048 | SfxItemState eState = aAttrSet.GetItemState( EE_PARA_LRSPACE ); | ||||||||
1049 | if ( eState == SfxItemState::DONTCARE ) | ||||||||
1050 | rDestSet.InvalidateItem(SID_ATTR_PARA_LRSPACE( 10000 + 43 )); | ||||||||
1051 | //xuxu for Line Space | ||||||||
1052 | SvxLineSpacingItem aLineSP = aAttrSet.Get( EE_PARA_SBL ); | ||||||||
1053 | aLineSP.SetWhich(SID_ATTR_PARA_LINESPACE( 10000 + 33 )); | ||||||||
1054 | rDestSet.Put(aLineSP); | ||||||||
1055 | Invalidate(SID_ATTR_PARA_LINESPACE( 10000 + 33 )); | ||||||||
1056 | eState = aAttrSet.GetItemState( EE_PARA_SBL ); | ||||||||
1057 | if ( eState == SfxItemState::DONTCARE ) | ||||||||
1058 | rDestSet.InvalidateItem(SID_ATTR_PARA_LINESPACE( 10000 + 33 )); | ||||||||
1059 | //xuxu for UL Space | ||||||||
1060 | SvxULSpaceItem aULSP = aAttrSet.Get( EE_PARA_ULSPACE ); | ||||||||
1061 | aULSP.SetWhich(SID_ATTR_PARA_ULSPACE( 10000 + 42 )); | ||||||||
1062 | rDestSet.Put(aULSP); | ||||||||
1063 | Invalidate(SID_ATTR_PARA_ULSPACE( 10000 + 42 )); | ||||||||
1064 | Invalidate(SID_PARASPACE_INCREASE( 10000 + 1145 )); | ||||||||
1065 | Invalidate(SID_PARASPACE_DECREASE( 10000 + 1146 )); | ||||||||
1066 | eState = aAttrSet.GetItemState( EE_PARA_ULSPACE ); | ||||||||
1067 | if( eState >= SfxItemState::DEFAULT ) | ||||||||
1068 | { | ||||||||
1069 | if ( !aULSP.GetUpper() && !aULSP.GetLower() ) | ||||||||
1070 | rDestSet.DisableItem( SID_PARASPACE_DECREASE( 10000 + 1146 ) ); | ||||||||
1071 | } | ||||||||
1072 | else | ||||||||
1073 | { | ||||||||
1074 | rDestSet.DisableItem( SID_PARASPACE_INCREASE( 10000 + 1145 ) ); | ||||||||
1075 | rDestSet.DisableItem( SID_PARASPACE_DECREASE( 10000 + 1146 ) ); | ||||||||
1076 | rDestSet.InvalidateItem(SID_ATTR_PARA_ULSPACE( 10000 + 42 )); | ||||||||
1077 | } | ||||||||
1078 | |||||||||
1079 | // Line spacing | ||||||||
1080 | |||||||||
1081 | sal_uInt16 nLineSpace = aAttrSet.Get( EE_PARA_SBL ).GetPropLineSpace(); | ||||||||
1082 | switch( nLineSpace ) | ||||||||
1083 | { | ||||||||
1084 | case 100: | ||||||||
1085 | rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_10( 10000 + 34 ), true ) ); | ||||||||
1086 | break; | ||||||||
1087 | case 150: | ||||||||
1088 | rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_15( 10000 + 35 ), true ) ); | ||||||||
1089 | break; | ||||||||
1090 | case 200: | ||||||||
1091 | rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_LINESPACE_20( 10000 + 36 ), true ) ); | ||||||||
1092 | break; | ||||||||
1093 | } | ||||||||
1094 | |||||||||
1095 | // super-/subscript | ||||||||
1096 | SvxEscapement eEsc = static_cast<SvxEscapement>(aAttrSet.Get( EE_CHAR_ESCAPEMENT ).GetEnumValue()); | ||||||||
1097 | rDestSet.Put(SfxBoolItem(SID_SET_SUPER_SCRIPT( 10000 + 294 ), eEsc == SvxEscapement::Superscript)); | ||||||||
1098 | rDestSet.Put(SfxBoolItem(SID_SET_SUB_SCRIPT( 10000 + 295 ), eEsc == SvxEscapement::Subscript)); | ||||||||
1099 | |||||||||
1100 | // Underline | ||||||||
1101 | eState = aAttrSet.GetItemState( EE_CHAR_UNDERLINE ); | ||||||||
1102 | if ( eState == SfxItemState::DONTCARE ) | ||||||||
1103 | { | ||||||||
1104 | rDestSet.InvalidateItem( SID_ULINE_VAL_NONE(10000 + 1195) ); | ||||||||
1105 | rDestSet.InvalidateItem( SID_ULINE_VAL_SINGLE(10000 + 1196) ); | ||||||||
1106 | rDestSet.InvalidateItem( SID_ULINE_VAL_DOUBLE(10000 + 1197) ); | ||||||||
1107 | rDestSet.InvalidateItem( SID_ULINE_VAL_DOTTED(10000 + 1198) ); | ||||||||
1108 | } | ||||||||
1109 | else | ||||||||
1110 | { | ||||||||
1111 | FontLineStyle eUnderline = aAttrSet.Get(EE_CHAR_UNDERLINE).GetLineStyle(); | ||||||||
1112 | rDestSet.Put(SfxBoolItem(SID_ULINE_VAL_SINGLE(10000 + 1196), eUnderline == LINESTYLE_SINGLE)); | ||||||||
1113 | rDestSet.Put(SfxBoolItem(SID_ULINE_VAL_DOUBLE(10000 + 1197), eUnderline == LINESTYLE_DOUBLE)); | ||||||||
1114 | rDestSet.Put(SfxBoolItem(SID_ULINE_VAL_DOTTED(10000 + 1198), eUnderline == LINESTYLE_DOTTED)); | ||||||||
1115 | rDestSet.Put(SfxBoolItem(SID_ULINE_VAL_NONE(10000 + 1195), eUnderline == LINESTYLE_NONE)); | ||||||||
1116 | } | ||||||||
1117 | |||||||||
1118 | // horizontal / vertical | ||||||||
1119 | |||||||||
1120 | bool bLeftToRight = true; | ||||||||
1121 | |||||||||
1122 | SdrOutliner* pOutl = pView->GetTextEditOutliner(); | ||||||||
1123 | if( pOutl ) | ||||||||
1124 | { | ||||||||
1125 | if( pOutl->IsVertical() ) | ||||||||
1126 | bLeftToRight = false; | ||||||||
1127 | } | ||||||||
1128 | else | ||||||||
1129 | bLeftToRight = aAttrSet.Get( SDRATTR_TEXTDIRECTION ).GetValue() == css::text::WritingMode_LR_TB; | ||||||||
1130 | |||||||||
1131 | if ( bDisableVerticalText ) | ||||||||
1132 | { | ||||||||
1133 | rDestSet.DisableItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT( 10000 + 907 ) ); | ||||||||
1134 | rDestSet.DisableItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM( 10000 + 908 ) ); | ||||||||
1135 | } | ||||||||
1136 | else | ||||||||
1137 | { | ||||||||
1138 | rDestSet.Put( SfxBoolItem( SID_TEXTDIRECTION_LEFT_TO_RIGHT( 10000 + 907 ), bLeftToRight ) ); | ||||||||
1139 | rDestSet.Put( SfxBoolItem( SID_TEXTDIRECTION_TOP_TO_BOTTOM( 10000 + 908 ), !bLeftToRight ) ); | ||||||||
1140 | } | ||||||||
1141 | |||||||||
1142 | // left-to-right or right-to-left | ||||||||
1143 | |||||||||
1144 | if ( !bLeftToRight || bDisableCTLFont ) | ||||||||
1145 | { | ||||||||
1146 | // disabled if vertical | ||||||||
1147 | rDestSet.DisableItem( SID_ATTR_PARA_LEFT_TO_RIGHT( 10000 + 950 ) ); | ||||||||
1148 | rDestSet.DisableItem( SID_ATTR_PARA_RIGHT_TO_LEFT( 10000 + 951 ) ); | ||||||||
1149 | } | ||||||||
1150 | else if ( aAttrSet.GetItemState( EE_PARA_WRITINGDIR ) == SfxItemState::DONTCARE ) | ||||||||
1151 | { | ||||||||
1152 | rDestSet.InvalidateItem( SID_ATTR_PARA_LEFT_TO_RIGHT( 10000 + 950 ) ); | ||||||||
1153 | rDestSet.InvalidateItem( SID_ATTR_PARA_RIGHT_TO_LEFT( 10000 + 951 ) ); | ||||||||
1154 | } | ||||||||
1155 | else | ||||||||
1156 | { | ||||||||
1157 | SvxFrameDirection eAttrDir = aAttrSet.Get( EE_PARA_WRITINGDIR ).GetValue(); | ||||||||
1158 | if ( eAttrDir == SvxFrameDirection::Environment ) | ||||||||
1159 | { | ||||||||
1160 | // get "environment" direction from page style | ||||||||
1161 | if ( mrViewData.GetDocument().GetEditTextDirection( mrViewData.GetTabNo() ) == EEHorizontalTextDirection::R2L ) | ||||||||
1162 | eAttrDir = SvxFrameDirection::Horizontal_RL_TB; | ||||||||
1163 | else | ||||||||
1164 | eAttrDir = SvxFrameDirection::Horizontal_LR_TB; | ||||||||
1165 | } | ||||||||
1166 | rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_LEFT_TO_RIGHT( 10000 + 950 ), ( eAttrDir == SvxFrameDirection::Horizontal_LR_TB ) ) ); | ||||||||
1167 | rDestSet.Put( SfxBoolItem( SID_ATTR_PARA_RIGHT_TO_LEFT( 10000 + 951 ), ( eAttrDir == SvxFrameDirection::Horizontal_RL_TB ) ) ); | ||||||||
1168 | } | ||||||||
1169 | } | ||||||||
1170 | |||||||||
1171 | void ScDrawTextObjectBar::ExecuteTrans( const SfxRequest& rReq ) | ||||||||
1172 | { | ||||||||
1173 | TransliterationFlags nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() ); | ||||||||
1174 | if ( nType == TransliterationFlags::NONE ) | ||||||||
1175 | return; | ||||||||
1176 | |||||||||
1177 | ScDrawView* pView = mrViewData.GetScDrawView(); | ||||||||
1178 | OutlinerView* pOutView = pView->GetTextEditOutlinerView(); | ||||||||
1179 | if ( pOutView ) | ||||||||
1180 | { | ||||||||
1181 | // change selected text in object | ||||||||
1182 | pOutView->TransliterateText( nType ); | ||||||||
1183 | } | ||||||||
1184 | else | ||||||||
1185 | { | ||||||||
1186 | //! apply to whole objects? | ||||||||
1187 | } | ||||||||
1188 | } | ||||||||
1189 | |||||||||
1190 | void ScDrawTextObjectBar::GetStatePropPanelAttr(SfxItemSet &rSet) | ||||||||
1191 | { | ||||||||
1192 | SfxWhichIter aIter( rSet ); | ||||||||
1193 | sal_uInt16 nWhich = aIter.FirstWhich(); | ||||||||
1194 | |||||||||
1195 | SdrView* pView = mrViewData.GetScDrawView(); | ||||||||
1196 | |||||||||
1197 | SfxItemSet aEditAttr(pView->GetModel()->GetItemPool()); | ||||||||
1198 | pView->GetAttributes(aEditAttr); | ||||||||
1199 | //SfxItemSet aAttrs( *aEditAttr.GetPool(), aEditAttr.GetRanges() ); | ||||||||
1200 | |||||||||
1201 | while ( nWhich ) | ||||||||
1202 | { | ||||||||
1203 | sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich) | ||||||||
1204 | ? GetPool().GetSlotId(nWhich) | ||||||||
1205 | : nWhich; | ||||||||
1206 | switch ( nSlotId ) | ||||||||
1207 | { | ||||||||
1208 | case SID_TABLE_VERT_NONE( 10000 + 1075 ): | ||||||||
1209 | case SID_TABLE_VERT_CENTER( 10000 + 1074 ): | ||||||||
1210 | case SID_TABLE_VERT_BOTTOM( 10000 + 1073 ): | ||||||||
1211 | bool bContour = false; | ||||||||
1212 | SfxItemState eConState = aEditAttr.GetItemState( SDRATTR_TEXT_CONTOURFRAME ); | ||||||||
1213 | if( eConState != SfxItemState::DONTCARE ) | ||||||||
1214 | { | ||||||||
1215 | bContour = aEditAttr.Get( SDRATTR_TEXT_CONTOURFRAME ).GetValue(); | ||||||||
1216 | } | ||||||||
1217 | if (bContour) break; | ||||||||
1218 | |||||||||
1219 | SfxItemState eVState = aEditAttr.GetItemState( SDRATTR_TEXT_VERTADJUST ); | ||||||||
1220 | //SfxItemState eHState = aAttrs.GetItemState( SDRATTR_TEXT_HORZADJUST ); | ||||||||
1221 | |||||||||
1222 | //if(SfxItemState::DONTCARE != eVState && SfxItemState::DONTCARE != eHState) | ||||||||
1223 | if(SfxItemState::DONTCARE != eVState) | ||||||||
1224 | { | ||||||||
1225 | SdrTextVertAdjust eTVA = aEditAttr.Get(SDRATTR_TEXT_VERTADJUST).GetValue(); | ||||||||
1226 | bool bSet = (nSlotId == SID_TABLE_VERT_NONE( 10000 + 1075 ) && eTVA == SDRTEXTVERTADJUST_TOP) || | ||||||||
1227 | (nSlotId == SID_TABLE_VERT_CENTER( 10000 + 1074 ) && eTVA == SDRTEXTVERTADJUST_CENTER) || | ||||||||
1228 | (nSlotId == SID_TABLE_VERT_BOTTOM( 10000 + 1073 ) && eTVA == SDRTEXTVERTADJUST_BOTTOM); | ||||||||
1229 | rSet.Put(SfxBoolItem(nSlotId, bSet)); | ||||||||
1230 | } | ||||||||
1231 | else | ||||||||
1232 | { | ||||||||
1233 | rSet.Put(SfxBoolItem(nSlotId, false)); | ||||||||
1234 | } | ||||||||
1235 | break; | ||||||||
1236 | } | ||||||||
1237 | nWhich = aIter.NextWhich(); | ||||||||
1238 | } | ||||||||
1239 | } | ||||||||
1240 | |||||||||
1241 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
5 | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | * contributor license agreements. See the NOTICE file distributed |
13 | * with this work for additional information regarding copyright |
14 | * ownership. The ASF licenses this file to you under the Apache |
15 | * License, Version 2.0 (the "License"); you may not use this file |
16 | * except in compliance with the License. You may obtain a copy of |
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | */ |
19 | |
20 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||||||||
2 | /* | ||||||||
3 | * This file is part of the LibreOffice project. | ||||||||
4 | * | ||||||||
5 | * This Source Code Form is subject to the terms of the Mozilla Public | ||||||||
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||||||
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||||||
8 | * | ||||||||
9 | * This file incorporates work covered by the following license notice: | ||||||||
10 | * | ||||||||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | ||||||||
12 | * contributor license agreements. See the NOTICE file distributed | ||||||||
13 | * with this work for additional information regarding copyright | ||||||||
14 | * ownership. The ASF licenses this file to you under the Apache | ||||||||
15 | * License, Version 2.0 (the "License"); you may not use this file | ||||||||
16 | * except in compliance with the License. You may obtain a copy of | ||||||||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | ||||||||
18 | */ | ||||||||
19 | |||||||||
20 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||
22 | |||||||||
23 | #include "sal/config.h" | ||||||||
24 | |||||||||
25 | #include <cassert> | ||||||||
26 | #include <cstddef> | ||||||||
27 | #include <functional> | ||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
29 | #include <type_traits> | ||||||||
30 | #endif | ||||||||
31 | |||||||||
32 | #include "sal/types.h" | ||||||||
33 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
48 | /** Constructor... | ||||||||
49 | */ | ||||||||
50 | Reference() | ||||||||
51 | : m_pBody (NULL__null) | ||||||||
52 | {} | ||||||||
53 | |||||||||
54 | |||||||||
55 | /** Constructor... | ||||||||
56 | */ | ||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||
58 | : m_pBody (pBody) | ||||||||
59 | { | ||||||||
60 | } | ||||||||
61 | |||||||||
62 | /** Constructor... | ||||||||
63 | */ | ||||||||
64 | Reference (reference_type * pBody) | ||||||||
65 | : m_pBody (pBody) | ||||||||
66 | { | ||||||||
67 | if (m_pBody) | ||||||||
68 | m_pBody->acquire(); | ||||||||
69 | } | ||||||||
70 | |||||||||
71 | /** Copy constructor... | ||||||||
72 | */ | ||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||
75 | { | ||||||||
76 | if (m_pBody) | ||||||||
77 | m_pBody->acquire(); | ||||||||
78 | } | ||||||||
79 | |||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
81 | /** Move constructor... | ||||||||
82 | */ | ||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||
85 | { | ||||||||
86 | handle.m_pBody = nullptr; | ||||||||
87 | } | ||||||||
88 | #endif | ||||||||
89 | |||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||
92 | |||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||
94 | |||||||||
95 | @param rRef another reference | ||||||||
96 | */ | ||||||||
97 | template< class derived_type > | ||||||||
98 | inline Reference( | ||||||||
99 | const Reference< derived_type > & rRef, | ||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||
101 | : m_pBody (rRef.get()) | ||||||||
102 | { | ||||||||
103 | if (m_pBody) | ||||||||
104 | m_pBody->acquire(); | ||||||||
105 | } | ||||||||
106 | #endif | ||||||||
107 | |||||||||
108 | /** Destructor... | ||||||||
109 | */ | ||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||
111 | { | ||||||||
112 | if (m_pBody
| ||||||||
113 | m_pBody->release(); | ||||||||
114 | } | ||||||||
115 | |||||||||
116 | /** Set... | ||||||||
117 | Similar to assignment. | ||||||||
118 | */ | ||||||||
119 | Reference<reference_type> & | ||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||
121 | { | ||||||||
122 | if (pBody) | ||||||||
123 | pBody->acquire(); | ||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||
125 | m_pBody = pBody; | ||||||||
126 | if (pOld) | ||||||||
127 | pOld->release(); | ||||||||
128 | return *this; | ||||||||
129 | } | ||||||||
130 | |||||||||
131 | /** Assignment. | ||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||
133 | bind it to the body represented by the handle. | ||||||||
134 | */ | ||||||||
135 | Reference<reference_type> & | ||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||
137 | { | ||||||||
138 | return set( handle.m_pBody ); | ||||||||
139 | } | ||||||||
140 | |||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
142 | /** Assignment. | ||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||
144 | * bind it to the body represented by the handle, and | ||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||
146 | */ | ||||||||
147 | Reference<reference_type> & | ||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||
149 | { | ||||||||
150 | // self-movement guts ourself | ||||||||
151 | if (m_pBody) | ||||||||
152 | m_pBody->release(); | ||||||||
153 | m_pBody = handle.m_pBody; | ||||||||
154 | handle.m_pBody = nullptr; | ||||||||
155 | return *this; | ||||||||
156 | } | ||||||||
157 | #endif | ||||||||
158 | |||||||||
159 | /** Assignment... | ||||||||
160 | */ | ||||||||
161 | Reference<reference_type> & | ||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||
163 | { | ||||||||
164 | return set( pBody ); | ||||||||
165 | } | ||||||||
166 | |||||||||
167 | /** Unbind the body from this handle. | ||||||||
168 | Note that for a handle representing a large body, | ||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||
171 | since in the second case two large objects exist in memory | ||||||||
172 | (the old body and the new body). | ||||||||
173 | */ | ||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||
175 | { | ||||||||
176 | if (m_pBody) | ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
| |||||||||
193 | } | ||||||||
194 | |||||||||
195 | |||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||
197 | */ | ||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||
199 | { | ||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||
201 | return m_pBody; | ||||||||
202 | } | ||||||||
203 | |||||||||
204 | |||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||
206 | */ | ||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||
208 | { | ||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||
210 | return *m_pBody; | ||||||||
211 | } | ||||||||
212 | |||||||||
213 | |||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||
215 | */ | ||||||||
216 | bool SAL_CALL is() const | ||||||||
217 | { | ||||||||
218 | return (m_pBody != NULL__null); | ||||||||
219 | } | ||||||||
220 | |||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||
223 | */ | ||||||||
224 | explicit operator bool() const | ||||||||
225 | { | ||||||||
226 | return is(); | ||||||||
227 | } | ||||||||
228 | #endif | ||||||||
229 | |||||||||
230 | /** Returns True if this points to pBody. | ||||||||
231 | */ | ||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||
233 | { | ||||||||
234 | return (m_pBody == pBody); | ||||||||
235 | } | ||||||||
236 | |||||||||
237 | |||||||||
238 | /** Returns True if handle points to the same body. | ||||||||
239 | */ | ||||||||
240 | bool | ||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||
242 | { | ||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | |||||||||
247 | /** Needed to place References into STL collection. | ||||||||
248 | */ | ||||||||
249 | bool | ||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||
251 | { | ||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||
253 | } | ||||||||
254 | |||||||||
255 | |||||||||
256 | /** Needed to place References into STL collection. | ||||||||
257 | */ | ||||||||
258 | bool | ||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||
260 | { | ||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||
262 | } | ||||||||
263 | |||||||||
264 | |||||||||
265 | /** Needed to place References into STL collection. | ||||||||
266 | */ | ||||||||
267 | bool | ||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||
269 | { | ||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||
271 | } | ||||||||
272 | }; | ||||||||
273 | |||||||||
274 | } // namespace rtl | ||||||||
275 | |||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
277 | namespace std | ||||||||
278 | { | ||||||||
279 | |||||||||
280 | /// @cond INTERNAL | ||||||||
281 | /** | ||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||
283 | |||||||||
284 | @since LibreOffice 6.3 | ||||||||
285 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||
288 | { | ||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||
290 | { return std::size_t(s.get()); } | ||||||||
291 | }; | ||||||||
292 | /// @endcond | ||||||||
293 | |||||||||
294 | } | ||||||||
295 | |||||||||
296 | #endif | ||||||||
297 | |||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||
299 | |||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
5 | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | * contributor license agreements. See the NOTICE file distributed |
13 | * with this work for additional information regarding copyright |
14 | * ownership. The ASF licenses this file to you under the Apache |
15 | * License, Version 2.0 (the "License"); you may not use this file |
16 | * except in compliance with the License. You may obtain a copy of |
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | */ |
19 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |