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 <config_features.h> | ||||||||
21 | |||||||||
22 | #include <hintids.hxx> | ||||||||
23 | #include <svl/whiter.hxx> | ||||||||
24 | #include <sfx2/viewfrm.hxx> | ||||||||
25 | #include <basic/sbstar.hxx> | ||||||||
26 | #include <svl/ptitem.hxx> | ||||||||
27 | #include <svl/stritem.hxx> | ||||||||
28 | #include <svl/intitem.hxx> | ||||||||
29 | #include <svl/eitem.hxx> | ||||||||
30 | #include <editeng/colritem.hxx> | ||||||||
31 | #include <editeng/lineitem.hxx> | ||||||||
32 | #include <editeng/boxitem.hxx> | ||||||||
33 | #include <sfx2/dispatch.hxx> | ||||||||
34 | #include <sfx2/request.hxx> | ||||||||
35 | #include <sfx2/objface.hxx> | ||||||||
36 | #include <vcl/EnumContext.hxx> | ||||||||
37 | #include <svx/hlnkitem.hxx> | ||||||||
38 | #include <svx/svdview.hxx> | ||||||||
39 | #include <vcl/commandinfoprovider.hxx> | ||||||||
40 | #include <sal/log.hxx> | ||||||||
41 | |||||||||
42 | #include <doc.hxx> | ||||||||
43 | #include <drawdoc.hxx> | ||||||||
44 | #include <IDocumentSettingAccess.hxx> | ||||||||
45 | #include <IDocumentDrawModelAccess.hxx> | ||||||||
46 | #include <fmturl.hxx> | ||||||||
47 | #include <fmtclds.hxx> | ||||||||
48 | #include <fmtcnct.hxx> | ||||||||
49 | #include <swmodule.hxx> | ||||||||
50 | #include <wrtsh.hxx> | ||||||||
51 | #include <wview.hxx> | ||||||||
52 | #include <uitool.hxx> | ||||||||
53 | #include <frmfmt.hxx> | ||||||||
54 | #include <frmsh.hxx> | ||||||||
55 | #include <frmmgr.hxx> | ||||||||
56 | #include <edtwin.hxx> | ||||||||
57 | #include <swdtflvr.hxx> | ||||||||
58 | #include <viewopt.hxx> | ||||||||
59 | |||||||||
60 | #include <cmdid.h> | ||||||||
61 | #include <strings.hrc> | ||||||||
62 | #include <swabstdlg.hxx> | ||||||||
63 | |||||||||
64 | #include <svx/svxdlg.hxx> | ||||||||
65 | |||||||||
66 | #include <docsh.hxx> | ||||||||
67 | #include <svx/drawitem.hxx> | ||||||||
68 | #include <memory> | ||||||||
69 | |||||||||
70 | #define ShellClass_SwFrameShell | ||||||||
71 | #include <sfx2/msg.hxx> | ||||||||
72 | #include <swslots.hxx> | ||||||||
73 | #include <grfatr.hxx> | ||||||||
74 | #include <fldmgr.hxx> | ||||||||
75 | #include <flyfrm.hxx> | ||||||||
76 | |||||||||
77 | using ::editeng::SvxBorderLine; | ||||||||
78 | using namespace ::com::sun::star; | ||||||||
79 | using namespace ::com::sun::star::uno; | ||||||||
80 | |||||||||
81 | // Prototypes | ||||||||
82 | static void lcl_FrameGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLine& rBorderLine); | ||||||||
83 | static const SwFrameFormat* lcl_GetFrameFormatByName(SwWrtShell const & rSh, const OUString& rName) | ||||||||
84 | { | ||||||||
85 | const size_t nCount = rSh.GetFlyCount(FLYCNTTYPE_FRM); | ||||||||
86 | for( size_t i = 0; i < nCount; ++i ) | ||||||||
87 | { | ||||||||
88 | const SwFrameFormat* pFormat = rSh.GetFlyNum(i, FLYCNTTYPE_FRM); | ||||||||
89 | if(pFormat->GetName() == rName) | ||||||||
90 | return pFormat; | ||||||||
91 | } | ||||||||
92 | return nullptr; | ||||||||
93 | } | ||||||||
94 | |||||||||
95 | SFX_IMPL_INTERFACE(SwFrameShell, SwBaseShell)SfxInterface* SwFrameShell::pInterface = nullptr; SfxInterface * SwFrameShell::GetStaticInterface() { if ( !pInterface ) { pInterface = new SfxInterface( "SwFrameShell", false, GetInterfaceId(), SwBaseShell::GetStaticInterface(), aSwFrameShellSlots_Impl[0 ], sal_uInt16(sizeof(aSwFrameShellSlots_Impl) / sizeof(SfxSlot ) ) ); InitInterface_Impl(); } return pInterface; } SfxInterface * SwFrameShell::GetInterface() const { return GetStaticInterface (); } void SwFrameShell::RegisterInterface(const SfxModule* pMod ) { GetStaticInterface()->Register(pMod); } | ||||||||
96 | |||||||||
97 | void SwFrameShell::InitInterface_Impl() | ||||||||
98 | { | ||||||||
99 | GetStaticInterface()->RegisterPopupMenu("frame"); | ||||||||
100 | |||||||||
101 | GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT1, SfxVisibilityFlags::Invisible, ToolbarId::Frame_Toolbox); | ||||||||
102 | } | ||||||||
103 | |||||||||
104 | void SwFrameShell::ExecMove(SfxRequest& rReq) | ||||||||
105 | { | ||||||||
106 | SwWrtShell& rSh = GetShell(); | ||||||||
107 | sal_uInt16 nSlot = rReq.GetSlot(); | ||||||||
108 | switch (nSlot) | ||||||||
109 | { | ||||||||
110 | case SID_SELECTALL(5000 + 723): | ||||||||
111 | rSh.SelAll(); | ||||||||
112 | rReq.Done(); | ||||||||
113 | break; | ||||||||
114 | } | ||||||||
115 | } | ||||||||
116 | |||||||||
117 | void SwFrameShell::ExecField(const SfxRequest& rReq) | ||||||||
118 | { | ||||||||
119 | SwWrtShell& rSh = GetShell(); | ||||||||
120 | sal_uInt16 nSlot = rReq.GetSlot(); | ||||||||
121 | switch (nSlot) | ||||||||
122 | { | ||||||||
123 | case FN_POSTIT((20000 + 300) + 29): | ||||||||
124 | SwFieldMgr aFieldMgr(&rSh); | ||||||||
125 | rSh.InsertPostIt(aFieldMgr, rReq); | ||||||||
126 | break; | ||||||||
127 | } | ||||||||
128 | } | ||||||||
129 | |||||||||
130 | void SwFrameShell::Execute(SfxRequest &rReq) | ||||||||
131 | { | ||||||||
132 | //First those who do not need FrameMgr. | ||||||||
133 | SwWrtShell &rSh = GetShell(); | ||||||||
134 | bool bMore = false; | ||||||||
135 | const SfxItemSet* pArgs = rReq.GetArgs(); | ||||||||
136 | const SfxPoolItem* pItem; | ||||||||
137 | sal_uInt16 nSlot = rReq.GetSlot(); | ||||||||
138 | |||||||||
139 | switch ( nSlot ) | ||||||||
| |||||||||
140 | { | ||||||||
141 | case FN_FRAME_TO_ANCHOR((20000 + 900) + 59): | ||||||||
142 | if ( rSh.IsFrameSelected() ) | ||||||||
143 | { | ||||||||
144 | rSh.GotoFlyAnchor(); | ||||||||
145 | rSh.EnterStdMode(); | ||||||||
146 | rSh.CallChgLnk(); | ||||||||
147 | } | ||||||||
148 | break; | ||||||||
149 | case SID_FRAME_TO_TOP( 10000 + 286 ): | ||||||||
150 | rSh.SelectionToTop(); | ||||||||
151 | break; | ||||||||
152 | |||||||||
153 | case SID_FRAME_TO_BOTTOM( 10000 + 287 ): | ||||||||
154 | rSh.SelectionToBottom(); | ||||||||
155 | break; | ||||||||
156 | |||||||||
157 | case FN_FRAME_UP((20000 + 400) + 122): | ||||||||
158 | rSh.SelectionToTop( false ); | ||||||||
159 | break; | ||||||||
160 | |||||||||
161 | case FN_FRAME_DOWN((20000 + 400) + 123): | ||||||||
162 | rSh.SelectionToBottom( false ); | ||||||||
163 | break; | ||||||||
164 | case FN_INSERT_FRAME((20000 + 300) + 34): | ||||||||
165 | if (!pArgs) | ||||||||
166 | { | ||||||||
167 | // Frame already exists, open frame dialog for editing. | ||||||||
168 | SfxStringItem aDefPage(FN_FORMAT_FRAME_DLG((20000 + 400) + 56), "columns"); | ||||||||
169 | rSh.GetView().GetViewFrame()->GetDispatcher()->ExecuteList( | ||||||||
170 | FN_FORMAT_FRAME_DLG((20000 + 400) + 56), | ||||||||
171 | SfxCallMode::SYNCHRON|SfxCallMode::RECORD, | ||||||||
172 | { &aDefPage }); | ||||||||
173 | |||||||||
174 | } | ||||||||
175 | else | ||||||||
176 | { | ||||||||
177 | // Frame already exists, only the number of columns will be changed. | ||||||||
178 | sal_uInt16 nCols = 1; | ||||||||
179 | if(pArgs->GetItemState(SID_ATTR_COLUMNSTypedWhichId<SfxUInt16Item>( 10000 + 220 ), false, &pItem) == SfxItemState::SET) | ||||||||
180 | nCols = static_cast<const SfxUInt16Item *>(pItem)->GetValue(); | ||||||||
181 | |||||||||
182 | SfxItemSet aSet(GetPool(),svl::Items<RES_COL,RES_COL>{}); | ||||||||
183 | rSh.GetFlyFrameAttr( aSet ); | ||||||||
184 | SwFormatCol aCol(aSet.Get(RES_COL)); | ||||||||
185 | // GutterWidth will not always passed, hence get firstly | ||||||||
186 | // (see view2: Execute on this slot) | ||||||||
187 | sal_uInt16 nGutterWidth = aCol.GetGutterWidth(); | ||||||||
188 | if(!nCols ) | ||||||||
189 | nCols++; | ||||||||
190 | aCol.Init(nCols, nGutterWidth, aCol.GetWishWidth()); | ||||||||
191 | aSet.Put(aCol); | ||||||||
192 | // Template AutoUpdate | ||||||||
193 | SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat(); | ||||||||
194 | if(pFormat && pFormat->IsAutoUpdateFormat()) | ||||||||
195 | { | ||||||||
196 | rSh.AutoUpdateFrame(pFormat, aSet); | ||||||||
197 | } | ||||||||
198 | else | ||||||||
199 | { | ||||||||
200 | rSh.StartAllAction(); | ||||||||
201 | rSh.SetFlyFrameAttr( aSet ); | ||||||||
202 | rSh.SetModified(); | ||||||||
203 | rSh.EndAllAction(); | ||||||||
204 | } | ||||||||
205 | |||||||||
206 | } | ||||||||
207 | return; | ||||||||
208 | |||||||||
209 | case SID_HYPERLINK_SETLINKTypedWhichId<SvxHyperlinkItem>(10000 + 362): | ||||||||
210 | { | ||||||||
211 | if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_HYPERLINK_SETLINKTypedWhichId<SvxHyperlinkItem>(10000 + 362), false, &pItem)) | ||||||||
212 | { | ||||||||
213 | const SvxHyperlinkItem& rHLinkItem = *static_cast<const SvxHyperlinkItem *>(pItem); | ||||||||
214 | const OUString& rURL = rHLinkItem.GetURL(); | ||||||||
215 | const OUString& rTarget = rHLinkItem.GetTargetFrame(); | ||||||||
216 | |||||||||
217 | SfxItemSet aSet( rSh.GetAttrPool(), svl::Items<RES_URL, RES_URL>{} ); | ||||||||
218 | rSh.GetFlyFrameAttr( aSet ); | ||||||||
219 | SwFormatURL aURL( aSet.Get( RES_URL ) ); | ||||||||
220 | |||||||||
221 | OUString sOldName(rHLinkItem.GetName().toAsciiUpperCase()); | ||||||||
222 | OUString sFlyName(rSh.GetFlyName().toAsciiUpperCase()); | ||||||||
223 | if (sOldName != sFlyName) | ||||||||
224 | { | ||||||||
225 | OUString sName(sOldName); | ||||||||
226 | sal_uInt16 i = 1; | ||||||||
227 | while (rSh.FindFlyByName(sName)) | ||||||||
228 | { | ||||||||
229 | sName = sOldName + "_" + OUString::number(i++); | ||||||||
230 | } | ||||||||
231 | rSh.SetFlyName(sName); | ||||||||
232 | } | ||||||||
233 | aURL.SetURL( rURL, false ); | ||||||||
234 | aURL.SetTargetFrameName(rTarget); | ||||||||
235 | |||||||||
236 | aSet.Put( aURL ); | ||||||||
237 | rSh.SetFlyFrameAttr( aSet ); | ||||||||
238 | } | ||||||||
239 | } | ||||||||
240 | break; | ||||||||
241 | |||||||||
242 | case FN_FRAME_CHAIN((20000 + 1600) + 136): | ||||||||
243 | rSh.GetView().GetEditWin().SetChainMode( !rSh.GetView().GetEditWin().IsChainMode() ); | ||||||||
244 | break; | ||||||||
245 | |||||||||
246 | case FN_FRAME_UNCHAIN((20000 + 1600) + 137): | ||||||||
247 | rSh.Unchain( *rSh.GetFlyFrameFormat() ); | ||||||||
248 | GetView().GetViewFrame()->GetBindings().Invalidate(FN_FRAME_CHAIN((20000 + 1600) + 136)); | ||||||||
249 | break; | ||||||||
250 | case FN_FORMAT_FOOTNOTE_DLG((20000 + 400) + 68): | ||||||||
251 | { | ||||||||
252 | GetView().ExecFormatFootnote(); | ||||||||
253 | break; | ||||||||
254 | } | ||||||||
255 | case FN_NUMBERING_OUTLINE_DLG((20000 + 600) + 12): | ||||||||
256 | { | ||||||||
257 | GetView().ExecNumberingOutline(GetPool()); | ||||||||
258 | rReq.Done(); | ||||||||
259 | break; | ||||||||
260 | } | ||||||||
261 | case SID_OPEN_XML_FILTERSETTINGS( 10000 + 958 ): | ||||||||
262 | { | ||||||||
263 | HandleOpenXmlFilterSettings(rReq); | ||||||||
264 | } | ||||||||
265 | break; | ||||||||
266 | case FN_WORDCOUNT_DIALOG((20000 + 2200) + 98): | ||||||||
267 | { | ||||||||
268 | GetView().UpdateWordCount(this, nSlot); | ||||||||
269 | break; | ||||||||
270 | } | ||||||||
271 | default: bMore = true; | ||||||||
272 | } | ||||||||
273 | |||||||||
274 | if ( !bMore
| ||||||||
275 | { | ||||||||
276 | return; | ||||||||
277 | } | ||||||||
278 | |||||||||
279 | SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr ); | ||||||||
280 | bool bUpdateMgr = true; | ||||||||
281 | bool bCopyToFormat = false; | ||||||||
282 | switch ( nSlot ) | ||||||||
283 | { | ||||||||
284 | case SID_OBJECT_ALIGN_MIDDLE( 10000 + 135 ): | ||||||||
285 | case FN_FRAME_ALIGN_VERT_CENTER((20000 + 400) + 80): | ||||||||
286 | aMgr.SetVertOrientation( text::VertOrientation::CENTER ); | ||||||||
287 | break; | ||||||||
288 | case SID_OBJECT_ALIGN_DOWN( 10000 + 136 ) : | ||||||||
289 | case FN_FRAME_ALIGN_VERT_BOTTOM((20000 + 400) + 79): | ||||||||
290 | aMgr.SetVertOrientation( text::VertOrientation::BOTTOM ); | ||||||||
291 | break; | ||||||||
292 | case SID_OBJECT_ALIGN_UP( 10000 + 134 ) : | ||||||||
293 | case FN_FRAME_ALIGN_VERT_TOP((20000 + 400) + 78): | ||||||||
294 | aMgr.SetVertOrientation( text::VertOrientation::TOP ); | ||||||||
295 | break; | ||||||||
296 | |||||||||
297 | case FN_FRAME_ALIGN_VERT_CHAR_CENTER((20000 + 400) + 170): | ||||||||
298 | aMgr.SetVertOrientation( text::VertOrientation::CHAR_CENTER ); | ||||||||
299 | break; | ||||||||
300 | |||||||||
301 | case FN_FRAME_ALIGN_VERT_CHAR_BOTTOM((20000 + 400) + 169): | ||||||||
302 | aMgr.SetVertOrientation( text::VertOrientation::CHAR_BOTTOM ); | ||||||||
303 | break; | ||||||||
304 | |||||||||
305 | case FN_FRAME_ALIGN_VERT_CHAR_TOP((20000 + 400) + 168): | ||||||||
306 | aMgr.SetVertOrientation( text::VertOrientation::CHAR_TOP ); | ||||||||
307 | break; | ||||||||
308 | |||||||||
309 | case FN_FRAME_ALIGN_VERT_ROW_CENTER((20000 + 400) + 167): | ||||||||
310 | aMgr.SetVertOrientation( text::VertOrientation::LINE_CENTER ); | ||||||||
311 | break; | ||||||||
312 | |||||||||
313 | case FN_FRAME_ALIGN_VERT_ROW_BOTTOM((20000 + 400) + 166): | ||||||||
314 | aMgr.SetVertOrientation( text::VertOrientation::LINE_BOTTOM ); | ||||||||
315 | break; | ||||||||
316 | |||||||||
317 | case FN_FRAME_ALIGN_VERT_ROW_TOP((20000 + 400) + 165): | ||||||||
318 | aMgr.SetVertOrientation( text::VertOrientation::LINE_TOP ); | ||||||||
319 | break; | ||||||||
320 | case SID_OBJECT_ALIGN_CENTER( 10000 + 132 ) : | ||||||||
321 | case FN_FRAME_ALIGN_HORZ_CENTER((20000 + 400) + 77): | ||||||||
322 | aMgr.SetHorzOrientation( text::HoriOrientation::CENTER ); | ||||||||
323 | break; | ||||||||
324 | case SID_OBJECT_ALIGN_RIGHT( 10000 + 133 ): | ||||||||
325 | case FN_FRAME_ALIGN_HORZ_RIGHT((20000 + 400) + 76): | ||||||||
326 | aMgr.SetHorzOrientation( text::HoriOrientation::RIGHT ); | ||||||||
327 | break; | ||||||||
328 | case SID_OBJECT_ALIGN_LEFT( 10000 + 131 ): | ||||||||
329 | case FN_FRAME_ALIGN_HORZ_LEFT((20000 + 400) + 75): | ||||||||
330 | aMgr.SetHorzOrientation( text::HoriOrientation::LEFT ); | ||||||||
331 | break; | ||||||||
332 | |||||||||
333 | case FN_SET_FRM_POSITION((20000 + 400) + 82): | ||||||||
334 | { | ||||||||
335 | aMgr.SetAbsPos(static_cast<const SfxPointItem &>(pArgs->Get | ||||||||
336 | (FN_SET_FRM_POSITION((20000 + 400) + 82))).GetValue()); | ||||||||
337 | } | ||||||||
338 | break; | ||||||||
339 | case SID_ATTR_BRUSH( 10000 + 1 ): | ||||||||
340 | { | ||||||||
341 | if(pArgs) | ||||||||
342 | { | ||||||||
343 | aMgr.SetAttrSet( *pArgs ); | ||||||||
344 | bCopyToFormat = true; | ||||||||
345 | } | ||||||||
346 | } | ||||||||
347 | break; | ||||||||
348 | case SID_ATTR_ULSPACE( 10000 + 49 ): | ||||||||
349 | case SID_ATTR_LRSPACE( 10000 + 48 ): | ||||||||
350 | { | ||||||||
351 | if(pArgs && SfxItemState::SET == pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem)) | ||||||||
352 | { | ||||||||
353 | aMgr.SetAttrSet( *pArgs ); | ||||||||
354 | bCopyToFormat = true; | ||||||||
355 | } | ||||||||
356 | } | ||||||||
357 | break; | ||||||||
358 | |||||||||
359 | case SID_ATTR_TRANSFORMTypedWhichId<SfxInt32Item>( 10000 + 87 ): | ||||||||
360 | { | ||||||||
361 | bool bApplyNewPos = false; | ||||||||
362 | bool bApplyNewSize = false; | ||||||||
363 | |||||||||
364 | Point aNewPos = aMgr.GetPos(); | ||||||||
365 | if (pArgs && | ||||||||
366 | SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TRANSFORM_POS_XTypedWhichId<SfxInt32Item>( 10000 + 88 ), false, &pItem)) | ||||||||
367 | { | ||||||||
368 | aNewPos.setX( static_cast<const SfxInt32Item*>(pItem)->GetValue() ); | ||||||||
369 | bApplyNewPos = true; | ||||||||
370 | } | ||||||||
371 | if (pArgs && | ||||||||
372 | SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TRANSFORM_POS_YTypedWhichId<SfxInt32Item>( 10000 + 89 ), false, &pItem)) | ||||||||
373 | { | ||||||||
374 | aNewPos.setY( static_cast<const SfxInt32Item*>(pItem)->GetValue() ); | ||||||||
375 | bApplyNewPos = true; | ||||||||
376 | } | ||||||||
377 | |||||||||
378 | Size aNewSize = aMgr.GetSize(); | ||||||||
379 | if (pArgs && | ||||||||
380 | SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TRANSFORM_WIDTHTypedWhichId<SfxUInt32Item>( 10000 + 90 ), false, &pItem)) | ||||||||
381 | { | ||||||||
382 | aNewSize.setWidth( static_cast< const SfxUInt32Item* >(pItem)->GetValue() ); | ||||||||
383 | bApplyNewSize = true; | ||||||||
384 | } | ||||||||
385 | |||||||||
386 | if (pArgs && | ||||||||
387 | SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TRANSFORM_HEIGHTTypedWhichId<SfxUInt32Item>( 10000 + 91 ), false, &pItem)) | ||||||||
388 | { | ||||||||
389 | aNewSize.setHeight( static_cast< const SfxUInt32Item* >(pItem)->GetValue() ); | ||||||||
390 | bApplyNewSize = true; | ||||||||
391 | } | ||||||||
392 | |||||||||
393 | if (pArgs && (pArgs->HasItem(SID_ATTR_TRANSFORM_ANGLETypedWhichId<SfxInt32Item>( 10000 + 95 )) || pArgs->HasItem(SID_ATTR_TRANSFORM_DELTA_ANGLETypedWhichId<SfxInt32Item>( 10000 + 96 )))) | ||||||||
394 | { | ||||||||
395 | SfxItemSet aSet(rSh.GetAttrPool(), svl::Items<RES_GRFATR_ROTATION, RES_GRFATR_ROTATION>{} ); | ||||||||
396 | rSh.GetCurAttr(aSet); | ||||||||
397 | const SwRotationGrf& rRotation = aSet.Get(RES_GRFATR_ROTATION); | ||||||||
398 | const sal_uInt32 nOldRot(rRotation.GetValue()); | ||||||||
399 | |||||||||
400 | if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TRANSFORM_DELTA_ANGLETypedWhichId<SfxInt32Item>( 10000 + 96 ), false, &pItem)) | ||||||||
401 | { | ||||||||
402 | const sal_uInt32 nDeltaRot(static_cast<const SfxUInt32Item*>(pItem)->GetValue() / 10); | ||||||||
403 | aMgr.SetRotation(nOldRot, nOldRot + nDeltaRot, rRotation.GetUnrotatedSize()); | ||||||||
404 | } | ||||||||
405 | |||||||||
406 | // RotGrfFlyFrame: Get Value and disable is in SwGrfShell::GetAttrStateForRotation, but the | ||||||||
407 | // value setter uses SID_ATTR_TRANSFORM and a group of three values. Rotation is | ||||||||
408 | // added now, so use it in this central place. Do no forget to convert angle from | ||||||||
409 | // 100th degrees in SID_ATTR_TRANSFORM_ANGLE to 10th degrees in RES_GRFATR_ROTATION | ||||||||
410 | if (pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_TRANSFORM_ANGLETypedWhichId<SfxInt32Item>( 10000 + 95 ), false, &pItem)) | ||||||||
411 | { | ||||||||
412 | const sal_uInt32 nNewRot(static_cast<const SfxUInt32Item*>(pItem)->GetValue() / 10); | ||||||||
413 | |||||||||
414 | // RotGrfFlyFrame: Rotation change here, SwFlyFrameAttrMgr aMgr is available | ||||||||
415 | aMgr.SetRotation(nOldRot, nNewRot, rRotation.GetUnrotatedSize()); | ||||||||
416 | } | ||||||||
417 | } | ||||||||
418 | |||||||||
419 | if (bApplyNewPos) | ||||||||
420 | { | ||||||||
421 | aMgr.SetAbsPos(aNewPos); | ||||||||
422 | } | ||||||||
423 | if ( bApplyNewSize ) | ||||||||
424 | { | ||||||||
425 | aMgr.SetSize( aNewSize ); | ||||||||
426 | } | ||||||||
427 | if (!bApplyNewPos && !bApplyNewSize) | ||||||||
428 | { | ||||||||
429 | bUpdateMgr = false; | ||||||||
430 | } | ||||||||
431 | |||||||||
432 | } | ||||||||
433 | break; | ||||||||
434 | |||||||||
435 | case FN_FORMAT_FRAME_DLG((20000 + 400) + 56): | ||||||||
436 | case FN_DRAW_WRAP_DLG((20000 + 200) + 3): | ||||||||
437 | { | ||||||||
438 | const SelectionType nSel = rSh.GetSelectionType(); | ||||||||
439 | if (nSel & SelectionType::Graphic) | ||||||||
440 | { | ||||||||
441 | rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(FN_FORMAT_GRAFIC_DLG((20000 + 400) + 58)); | ||||||||
442 | bUpdateMgr = false; | ||||||||
443 | } | ||||||||
444 | else | ||||||||
445 | { | ||||||||
446 | SfxItemSet aSet( | ||||||||
447 | GetPool(), | ||||||||
448 | svl::Items< | ||||||||
449 | RES_FRMATR_BEGIN, RES_FRMATR_END - 1, | ||||||||
450 | // FillAttribute support: | ||||||||
451 | XATTR_FILL_FIRST, XATTR_FILL_LAST, | ||||||||
452 | SID_DOCFRAME(5000 + 598), SID_DOCFRAME(5000 + 598), | ||||||||
453 | SID_ATTR_BRUSH( 10000 + 1 ), SID_ATTR_BRUSH( 10000 + 1 ), | ||||||||
454 | SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), | ||||||||
455 | SID_ATTR_LRSPACE( 10000 + 48 ), SID_ATTR_ULSPACE( 10000 + 49 ), | ||||||||
456 | SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ), SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ), | ||||||||
457 | // Items to hand over XPropertyList things like | ||||||||
458 | // XColorList, XHatchList, XGradientList, and | ||||||||
459 | // XBitmapList to the Area TabPage | ||||||||
460 | SID_COLOR_TABLETypedWhichId<SvxColorListItem>( 10000 + 179 ), SID_PATTERN_LISTTypedWhichId<SvxPatternListItem>( 10000 + 183 ), | ||||||||
461 | SID_HTML_MODE(10000 + 414), SID_HTML_MODE(10000 + 414), | ||||||||
462 | FN_GET_PRINT_AREA((20000 + 1000) +32), FN_GET_PRINT_AREA((20000 + 1000) +32), | ||||||||
463 | FN_SURROUND((20000 + 1300) + 3), FN_KEEP_ASPECT_RATIO((20000 + 1300) + 7), | ||||||||
464 | FN_SET_FRM_ALT_NAME((20000 + 1300) + 18), FN_SET_FRM_ALT_NAME((20000 + 1300) + 18), | ||||||||
465 | FN_UNO_DESCRIPTION((20000 + 1300) + 20), FN_UNO_DESCRIPTION((20000 + 1300) + 20), | ||||||||
466 | FN_OLE_IS_MATH((20000 + 2200) + 114), FN_MATH_BASELINE_ALIGNMENT((20000 + 2200) + 115), | ||||||||
467 | FN_PARAM_CHAIN_PREVIOUS((20000 + 2400)+20), FN_PARAM_CHAIN_NEXT((20000 + 2400)+21)>{}); | ||||||||
468 | |||||||||
469 | // create needed items for XPropertyList entries from the DrawModel so that | ||||||||
470 | // the Area TabPage can access them | ||||||||
471 | const SwDrawModel* pDrawModel = rSh.GetView().GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel(); | ||||||||
472 | pDrawModel->PutAreaListItems(aSet); | ||||||||
473 | |||||||||
474 | const SwViewOption* pVOpt = rSh.GetViewOptions(); | ||||||||
475 | if(nSel & SelectionType::Ole) | ||||||||
476 | aSet.Put( SfxBoolItem(FN_KEEP_ASPECT_RATIO((20000 + 1300) + 7), pVOpt->IsKeepRatio()) ); | ||||||||
477 | aSet.Put(SfxUInt16Item(SID_HTML_MODE(10000 + 414), ::GetHtmlMode(GetView().GetDocShell()))); | ||||||||
478 | aSet.Put(SfxStringItem(FN_SET_FRM_NAME((20000 + 1300) + 6), rSh.GetFlyName())); | ||||||||
479 | aSet.Put(SfxStringItem(FN_UNO_DESCRIPTION((20000 + 1300) + 20), rSh.GetObjDescription())); | ||||||||
480 | if( nSel & SelectionType::Ole ) | ||||||||
481 | { | ||||||||
482 | // #i73249# | ||||||||
483 | aSet.Put( SfxStringItem( FN_SET_FRM_ALT_NAME((20000 + 1300) + 18), rSh.GetObjTitle() ) ); | ||||||||
484 | } | ||||||||
485 | |||||||||
486 | const SwRect &rPg = rSh.GetAnyCurRect(CurRectType::Page); | ||||||||
487 | SwFormatFrameSize aFrameSize(SwFrameSize::Variable, rPg.Width(), rPg.Height()); | ||||||||
488 | aFrameSize.SetWhich(GetPool().GetWhich(SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ))); | ||||||||
489 | aSet.Put(aFrameSize); | ||||||||
490 | |||||||||
491 | const SwRect &rPr = rSh.GetAnyCurRect(CurRectType::PagePrt); | ||||||||
492 | SwFormatFrameSize aPrtSize(SwFrameSize::Variable, rPr.Width(), rPr.Height()); | ||||||||
493 | aPrtSize.SetWhich(GetPool().GetWhich(FN_GET_PRINT_AREA((20000 + 1000) +32))); | ||||||||
494 | aSet.Put(aPrtSize); | ||||||||
495 | |||||||||
496 | aSet.Put(aMgr.GetAttrSet()); | ||||||||
497 | aSet.SetParent( aMgr.GetAttrSet().GetParent() ); | ||||||||
498 | |||||||||
499 | // On % values initialize size | ||||||||
500 | SwFormatFrameSize& rSize = const_cast<SwFormatFrameSize&>(aSet.Get(RES_FRM_SIZE)); | ||||||||
501 | if (rSize.GetWidthPercent() && rSize.GetWidthPercent() != SwFormatFrameSize::SYNCED) | ||||||||
502 | rSize.SetWidth(rSh.GetAnyCurRect(CurRectType::FlyEmbedded).Width()); | ||||||||
503 | if (rSize.GetHeightPercent() && rSize.GetHeightPercent() != SwFormatFrameSize::SYNCED) | ||||||||
504 | rSize.SetHeight(rSh.GetAnyCurRect(CurRectType::FlyEmbedded).Height()); | ||||||||
505 | |||||||||
506 | // disable vertical positioning for Math Objects anchored 'as char' if baseline alignment is activated | ||||||||
507 | aSet.Put( SfxBoolItem( FN_MATH_BASELINE_ALIGNMENT((20000 + 2200) + 115), | ||||||||
508 | rSh.GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT ) ) ); | ||||||||
509 | const uno::Reference < embed::XEmbeddedObject > xObj( rSh.GetOleRef() ); | ||||||||
510 | aSet.Put( SfxBoolItem( FN_OLE_IS_MATH((20000 + 2200) + 114), xObj.is() && SotExchange::IsMath( xObj->getClassID() ) ) ); | ||||||||
511 | |||||||||
512 | OString sDefPage; | ||||||||
513 | if(pArgs && pArgs->GetItemState(FN_FORMAT_FRAME_DLG((20000 + 400) + 56), false, &pItem) == SfxItemState::SET) | ||||||||
514 | sDefPage = OUStringToOString(static_cast<const SfxStringItem *>(pItem)->GetValue(), RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))); | ||||||||
515 | |||||||||
516 | aSet.Put(SfxFrameItem( SID_DOCFRAME(5000 + 598), &GetView().GetViewFrame()->GetFrame())); | ||||||||
517 | FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( &GetView()) != nullptr ); | ||||||||
518 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->PutItem(SfxUInt16Item(SID_ATTR_METRICTypedWhichId<SfxUInt16Item>(((((10000 + 1499) + 1) + 499 ) + 1) + 8), static_cast< sal_uInt16 >(eMetric) )); | ||||||||
519 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | ||||||||
520 | ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateFrameTabDialog( | ||||||||
521 | nSel & SelectionType::Graphic ? OUString("PictureDialog") : | ||||||||
522 | nSel & SelectionType::Ole ? OUString("ObjectDialog"): | ||||||||
523 | OUString("FrameDialog"), | ||||||||
524 | GetView().GetViewFrame(), | ||||||||
525 | GetView().GetFrameWeld(), | ||||||||
526 | aSet, | ||||||||
527 | false, | ||||||||
528 | sDefPage)); | ||||||||
529 | |||||||||
530 | if ( nSlot == FN_DRAW_WRAP_DLG((20000 + 200) + 3) ) | ||||||||
531 | { | ||||||||
532 | pDlg->SetCurPageId("wrap"); | ||||||||
533 | } | ||||||||
534 | |||||||||
535 | if ( pDlg->Execute() ) | ||||||||
536 | { | ||||||||
537 | const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); | ||||||||
538 | if(pOutSet) | ||||||||
539 | { | ||||||||
540 | rReq.Done(*pOutSet); | ||||||||
541 | if(nSel & SelectionType::Ole && | ||||||||
542 | SfxItemState::SET == pOutSet->GetItemState(FN_KEEP_ASPECT_RATIO((20000 + 1300) + 7), true, &pItem)) | ||||||||
543 | { | ||||||||
544 | SwViewOption aUsrPref( *pVOpt ); | ||||||||
545 | aUsrPref.SetKeepRatio(static_cast<const SfxBoolItem*>(pItem)->GetValue()); | ||||||||
546 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->ApplyUsrPref(aUsrPref, &GetView()); | ||||||||
547 | } | ||||||||
548 | if (SfxItemState::SET == pOutSet->GetItemState(FN_SET_FRM_ALT_NAME((20000 + 1300) + 18), true, &pItem)) | ||||||||
549 | { | ||||||||
550 | // #i73249# | ||||||||
551 | rSh.SetObjTitle(static_cast<const SfxStringItem*>(pItem)->GetValue()); | ||||||||
552 | } | ||||||||
553 | if (SfxItemState::SET == pOutSet->GetItemState(FN_UNO_DESCRIPTION((20000 + 1300) + 20), true, &pItem)) | ||||||||
554 | rSh.SetObjDescription(static_cast<const SfxStringItem*>(pItem)->GetValue()); | ||||||||
555 | |||||||||
556 | // Template AutoUpdate | ||||||||
557 | SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat(); | ||||||||
558 | if(pFormat && pFormat->IsAutoUpdateFormat()) | ||||||||
559 | { | ||||||||
560 | rSh.AutoUpdateFrame(pFormat, *pOutSet); | ||||||||
561 | // Anything which is not supported by the format must be set hard. | ||||||||
562 | if(SfxItemState::SET == pOutSet->GetItemState(FN_SET_FRM_NAME((20000 + 1300) + 6), false, &pItem)) | ||||||||
563 | rSh.SetFlyName(static_cast<const SfxStringItem*>(pItem)->GetValue()); | ||||||||
564 | SfxItemSet aShellSet( | ||||||||
565 | GetPool(), | ||||||||
566 | svl::Items< | ||||||||
567 | RES_FRM_SIZE, RES_FRM_SIZE, | ||||||||
568 | RES_SURROUND, RES_ANCHOR>{}); | ||||||||
569 | aShellSet.Put(*pOutSet); | ||||||||
570 | aMgr.SetAttrSet(aShellSet); | ||||||||
571 | if(SfxItemState::SET == pOutSet->GetItemState(FN_SET_FRM_NAME((20000 + 1300) + 6), false, &pItem)) | ||||||||
572 | rSh.SetFlyName(static_cast<const SfxStringItem*>(pItem)->GetValue()); | ||||||||
573 | } | ||||||||
574 | else | ||||||||
575 | aMgr.SetAttrSet( *pOutSet ); | ||||||||
576 | |||||||||
577 | const SwFrameFormat* pCurrFlyFormat = rSh.GetFlyFrameFormat(); | ||||||||
578 | if(SfxItemState::SET == | ||||||||
579 | pOutSet->GetItemState(FN_PARAM_CHAIN_PREVIOUS((20000 + 2400)+20), | ||||||||
580 | false, &pItem)) | ||||||||
581 | { | ||||||||
582 | rSh.HideChainMarker(); | ||||||||
583 | |||||||||
584 | OUString sPrevName = | ||||||||
585 | static_cast<const SfxStringItem*>(pItem)->GetValue(); | ||||||||
586 | const SwFormatChain &rChain = pCurrFlyFormat->GetChain(); | ||||||||
587 | //needs cast - no non-const method available | ||||||||
588 | SwFlyFrameFormat* pFlyFormat = | ||||||||
589 | rChain.GetPrev(); | ||||||||
590 | if(pFlyFormat) | ||||||||
591 | { | ||||||||
592 | if (pFlyFormat->GetName() != sPrevName) | ||||||||
593 | { | ||||||||
594 | rSh.Unchain(*pFlyFormat); | ||||||||
595 | } | ||||||||
596 | else | ||||||||
597 | sPrevName.clear(); | ||||||||
598 | } | ||||||||
599 | |||||||||
600 | if (!sPrevName.isEmpty()) | ||||||||
601 | { | ||||||||
602 | //needs cast - no non-const method available | ||||||||
603 | SwFrameFormat* pPrevFormat = const_cast<SwFrameFormat*>( | ||||||||
604 | lcl_GetFrameFormatByName(rSh, sPrevName)); | ||||||||
605 | SAL_WARN_IF(!pPrevFormat, "sw.ui", "No frame found!")do { if (true && (!pPrevFormat)) { switch (sal_detail_log_report (::SAL_DETAIL_LOG_LEVEL_WARN, "sw.ui")) { case SAL_DETAIL_LOG_ACTION_IGNORE : break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << "No frame found!" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/frmsh.cxx" ":" "605" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "No frame found!"), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "No frame found!"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/frmsh.cxx" ":" "605" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "No frame found!") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/frmsh.cxx" ":" "605" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "No frame found!"), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "No frame found!"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/frmsh.cxx" ":" "605" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
606 | if(pPrevFormat) | ||||||||
607 | { | ||||||||
608 | rSh.Chain(*pPrevFormat, *pCurrFlyFormat); | ||||||||
609 | } | ||||||||
610 | } | ||||||||
611 | rSh.SetChainMarker(); | ||||||||
612 | } | ||||||||
613 | if(SfxItemState::SET == | ||||||||
614 | pOutSet->GetItemState(FN_PARAM_CHAIN_NEXT((20000 + 2400)+21), false, | ||||||||
615 | &pItem)) | ||||||||
616 | { | ||||||||
617 | rSh.HideChainMarker(); | ||||||||
618 | OUString sNextName = | ||||||||
619 | static_cast<const SfxStringItem*>(pItem)->GetValue(); | ||||||||
620 | const SwFormatChain &rChain = pCurrFlyFormat->GetChain(); | ||||||||
621 | //needs cast - no non-const method available | ||||||||
622 | SwFlyFrameFormat* pFlyFormat = | ||||||||
623 | rChain.GetNext(); | ||||||||
624 | if(pFlyFormat) | ||||||||
625 | { | ||||||||
626 | if (pFlyFormat->GetName() != sNextName) | ||||||||
627 | { | ||||||||
628 | rSh.Unchain(*const_cast<SwFlyFrameFormat*>(static_cast<const SwFlyFrameFormat*>( pCurrFlyFormat))); | ||||||||
629 | } | ||||||||
630 | else | ||||||||
631 | sNextName.clear(); | ||||||||
632 | } | ||||||||
633 | |||||||||
634 | if (!sNextName.isEmpty()) | ||||||||
635 | { | ||||||||
636 | //needs cast - no non-const method available | ||||||||
637 | SwFrameFormat* pNextFormat = const_cast<SwFrameFormat*>( | ||||||||
638 | lcl_GetFrameFormatByName(rSh, sNextName)); | ||||||||
639 | SAL_WARN_IF(!pNextFormat, "sw.ui", "No frame found!")do { if (true && (!pNextFormat)) { switch (sal_detail_log_report (::SAL_DETAIL_LOG_LEVEL_WARN, "sw.ui")) { case SAL_DETAIL_LOG_ACTION_IGNORE : break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << "No frame found!" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sw.ui" ), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/frmsh.cxx" ":" "639" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "No frame found!"), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "No frame found!"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/frmsh.cxx" ":" "639" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "No frame found!") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/frmsh.cxx" ":" "639" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "No frame found!"), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "No frame found!"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw.ui"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/frmsh.cxx" ":" "639" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||||
640 | if(pNextFormat) | ||||||||
641 | { | ||||||||
642 | rSh.Chain(*const_cast<SwFrameFormat*>( | ||||||||
643 | pCurrFlyFormat), *pNextFormat); | ||||||||
644 | } | ||||||||
645 | } | ||||||||
646 | rSh.SetChainMarker(); | ||||||||
647 | } | ||||||||
648 | } | ||||||||
649 | } | ||||||||
650 | else | ||||||||
651 | bUpdateMgr = false; | ||||||||
652 | } | ||||||||
653 | } | ||||||||
654 | break; | ||||||||
655 | case FN_FRAME_MIRROR_ON_EVEN_PAGES((20000 + 1600) + 140): | ||||||||
656 | { | ||||||||
657 | SwFormatHoriOrient aHori(aMgr.GetHoriOrient()); | ||||||||
658 | bool bMirror = !aHori.IsPosToggle(); | ||||||||
659 | aHori.SetPosToggle(bMirror); | ||||||||
660 | SfxItemSet aSet(GetPool(), svl::Items<RES_HORI_ORIENT, RES_HORI_ORIENT>{}); | ||||||||
661 | aSet.Put(aHori); | ||||||||
662 | aMgr.SetAttrSet(aSet); | ||||||||
663 | bCopyToFormat = true; | ||||||||
664 | rReq.SetReturnValue(SfxBoolItem(nSlot, bMirror)); | ||||||||
665 | } | ||||||||
666 | break; | ||||||||
667 | case FN_NAME_SHAPE((20000 + 1600) + 14): | ||||||||
668 | { | ||||||||
669 | bUpdateMgr = false; | ||||||||
670 | SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList(); | ||||||||
671 | if ( pSdrView && | ||||||||
672 | pSdrView->GetMarkedObjectCount() == 1 ) | ||||||||
673 | { | ||||||||
674 | OUString aName(rSh.GetFlyName()); | ||||||||
675 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); | ||||||||
676 | ScopedVclPtr<AbstractSvxObjectNameDialog> pDlg( | ||||||||
677 | pFact->CreateSvxObjectNameDialog(GetView().GetFrameWeld(), aName)); | ||||||||
678 | |||||||||
679 | if ( pDlg->Execute() == RET_OK ) | ||||||||
680 | { | ||||||||
681 | pDlg->GetName(aName); | ||||||||
682 | rSh.SetFlyName(aName); | ||||||||
683 | } | ||||||||
684 | } | ||||||||
685 | } | ||||||||
686 | break; | ||||||||
687 | // #i73249# | ||||||||
688 | case FN_TITLE_DESCRIPTION_SHAPE((20000 + 1600) + 15): | ||||||||
689 | { | ||||||||
690 | bUpdateMgr = false; | ||||||||
691 | SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList(); | ||||||||
692 | if ( pSdrView && | ||||||||
693 | pSdrView->GetMarkedObjectCount() == 1 ) | ||||||||
694 | { | ||||||||
695 | OUString aDescription(rSh.GetObjDescription()); | ||||||||
696 | OUString aTitle(rSh.GetObjTitle()); | ||||||||
697 | |||||||||
698 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); | ||||||||
699 | ScopedVclPtr<AbstractSvxObjectTitleDescDialog> pDlg( | ||||||||
700 | pFact->CreateSvxObjectTitleDescDialog(GetView().GetFrameWeld(), | ||||||||
701 | aTitle, aDescription )); | ||||||||
702 | |||||||||
703 | if ( pDlg->Execute() == RET_OK ) | ||||||||
704 | { | ||||||||
705 | pDlg->GetDescription(aDescription); | ||||||||
706 | pDlg->GetTitle(aTitle); | ||||||||
707 | |||||||||
708 | rSh.SetObjDescription(aDescription); | ||||||||
709 | rSh.SetObjTitle(aTitle); | ||||||||
710 | } | ||||||||
711 | } | ||||||||
712 | } | ||||||||
713 | break; | ||||||||
714 | default: | ||||||||
715 | assert(!"wrong dispatcher")(static_cast <bool> (!"wrong dispatcher") ? void (0) : __assert_fail ("!\"wrong dispatcher\"", "/home/maarten/src/libreoffice/core/sw/source/uibase/shells/frmsh.cxx" , 715, __extension__ __PRETTY_FUNCTION__)); | ||||||||
716 | return; | ||||||||
717 | } | ||||||||
718 | if ( bUpdateMgr ) | ||||||||
719 | { | ||||||||
720 | SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat(); | ||||||||
721 | if ( bCopyToFormat && pFormat && pFormat->IsAutoUpdateFormat() ) | ||||||||
722 | { | ||||||||
723 | rSh.AutoUpdateFrame(pFormat, aMgr.GetAttrSet()); | ||||||||
724 | } | ||||||||
725 | else | ||||||||
726 | { | ||||||||
727 | aMgr.UpdateFlyFrame(); | ||||||||
728 | } | ||||||||
729 | } | ||||||||
730 | |||||||||
731 | } | ||||||||
732 | |||||||||
733 | void SwFrameShell::GetState(SfxItemSet& rSet) | ||||||||
734 | { | ||||||||
735 | SwWrtShell &rSh = GetShell(); | ||||||||
736 | bool bHtmlMode = 0 != ::GetHtmlMode(rSh.GetView().GetDocShell()); | ||||||||
737 | if (!rSh.IsFrameSelected()) | ||||||||
738 | return; | ||||||||
739 | |||||||||
740 | SfxItemSet aSet( | ||||||||
741 | rSh.GetAttrPool(), | ||||||||
742 | svl::Items< | ||||||||
743 | RES_LR_SPACE, RES_UL_SPACE, | ||||||||
744 | RES_PRINT, RES_HORI_ORIENT>{}); | ||||||||
745 | rSh.GetFlyFrameAttr( aSet ); | ||||||||
746 | |||||||||
747 | bool bProtect = rSh.IsSelObjProtected(FlyProtectFlags::Pos) != FlyProtectFlags::NONE; | ||||||||
748 | bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE; | ||||||||
749 | |||||||||
750 | bProtect |= bParentCntProt; | ||||||||
751 | |||||||||
752 | const FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true); | ||||||||
753 | SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr ); | ||||||||
754 | |||||||||
755 | SfxWhichIter aIter( rSet ); | ||||||||
756 | sal_uInt16 nWhich = aIter.FirstWhich(); | ||||||||
757 | while ( nWhich ) | ||||||||
758 | { | ||||||||
759 | switch ( nWhich ) | ||||||||
760 | { | ||||||||
761 | case RES_FRM_SIZE: | ||||||||
762 | { | ||||||||
763 | const SwFormatFrameSize& aSz(aMgr.GetFrameSize()); | ||||||||
764 | rSet.Put(aSz); | ||||||||
765 | } | ||||||||
766 | break; | ||||||||
767 | case RES_VERT_ORIENT: | ||||||||
768 | case RES_HORI_ORIENT: | ||||||||
769 | case SID_ATTR_ULSPACE( 10000 + 49 ): | ||||||||
770 | case SID_ATTR_LRSPACE( 10000 + 48 ): | ||||||||
771 | case RES_LR_SPACE: | ||||||||
772 | case RES_UL_SPACE: | ||||||||
773 | case RES_PROTECT: | ||||||||
774 | case RES_OPAQUE: | ||||||||
775 | case RES_PRINT: | ||||||||
776 | case RES_SURROUND: | ||||||||
777 | { | ||||||||
778 | rSet.Put(aSet.Get(GetPool().GetWhich(nWhich))); | ||||||||
779 | } | ||||||||
780 | break; | ||||||||
781 | case SID_OBJECT_ALIGN( 10000 + 130 ): | ||||||||
782 | { | ||||||||
783 | if ( bProtect ) | ||||||||
784 | rSet.DisableItem( nWhich ); | ||||||||
785 | } | ||||||||
786 | break; | ||||||||
787 | case SID_OBJECT_ALIGN_LEFT( 10000 + 131 ) : | ||||||||
788 | case SID_OBJECT_ALIGN_CENTER( 10000 + 132 ) : | ||||||||
789 | case SID_OBJECT_ALIGN_RIGHT( 10000 + 133 ) : | ||||||||
790 | case FN_FRAME_ALIGN_HORZ_CENTER((20000 + 400) + 77): | ||||||||
791 | case FN_FRAME_ALIGN_HORZ_RIGHT((20000 + 400) + 76): | ||||||||
792 | case FN_FRAME_ALIGN_HORZ_LEFT((20000 + 400) + 75): | ||||||||
793 | if ( (eFrameType & FrameTypeFlags::FLY_INCNT) || | ||||||||
794 | bProtect || | ||||||||
795 | ((nWhich == FN_FRAME_ALIGN_HORZ_CENTER((20000 + 400) + 77) || nWhich == SID_OBJECT_ALIGN_CENTER( 10000 + 132 )) && | ||||||||
796 | bHtmlMode )) | ||||||||
797 | { | ||||||||
798 | rSet.DisableItem( nWhich ); | ||||||||
799 | } | ||||||||
800 | else | ||||||||
801 | { | ||||||||
802 | sal_Int16 nHoriOrient = -1; | ||||||||
803 | switch(nWhich) | ||||||||
804 | { | ||||||||
805 | case SID_OBJECT_ALIGN_LEFT( 10000 + 131 ): | ||||||||
806 | nHoriOrient = text::HoriOrientation::LEFT; | ||||||||
807 | break; | ||||||||
808 | case SID_OBJECT_ALIGN_CENTER( 10000 + 132 ): | ||||||||
809 | nHoriOrient = text::HoriOrientation::CENTER; | ||||||||
810 | break; | ||||||||
811 | case SID_OBJECT_ALIGN_RIGHT( 10000 + 133 ): | ||||||||
812 | nHoriOrient = text::HoriOrientation::RIGHT; | ||||||||
813 | break; | ||||||||
814 | default: | ||||||||
815 | break; | ||||||||
816 | } | ||||||||
817 | SwFormatHoriOrient aHOrient(aMgr.GetHoriOrient()); | ||||||||
818 | if (nHoriOrient != -1) | ||||||||
819 | rSet.Put(SfxBoolItem(nWhich, nHoriOrient == aHOrient.GetHoriOrient())); | ||||||||
820 | } | ||||||||
821 | break; | ||||||||
822 | case FN_FRAME_ALIGN_VERT_ROW_TOP((20000 + 400) + 165): | ||||||||
823 | case FN_FRAME_ALIGN_VERT_ROW_CENTER((20000 + 400) + 167): | ||||||||
824 | case FN_FRAME_ALIGN_VERT_ROW_BOTTOM((20000 + 400) + 166): | ||||||||
825 | case FN_FRAME_ALIGN_VERT_CHAR_TOP((20000 + 400) + 168): | ||||||||
826 | case FN_FRAME_ALIGN_VERT_CHAR_CENTER((20000 + 400) + 170): | ||||||||
827 | case FN_FRAME_ALIGN_VERT_CHAR_BOTTOM((20000 + 400) + 169): | ||||||||
828 | if ( !(eFrameType & FrameTypeFlags::FLY_INCNT) || bProtect | ||||||||
829 | || (bHtmlMode && FN_FRAME_ALIGN_VERT_CHAR_BOTTOM((20000 + 400) + 169) == nWhich) ) | ||||||||
830 | rSet.DisableItem( nWhich ); | ||||||||
831 | break; | ||||||||
832 | |||||||||
833 | case SID_OBJECT_ALIGN_UP( 10000 + 134 ) : | ||||||||
834 | case SID_OBJECT_ALIGN_MIDDLE( 10000 + 135 ) : | ||||||||
835 | case SID_OBJECT_ALIGN_DOWN( 10000 + 136 ) : | ||||||||
836 | |||||||||
837 | case FN_FRAME_ALIGN_VERT_TOP((20000 + 400) + 78): | ||||||||
838 | case FN_FRAME_ALIGN_VERT_CENTER((20000 + 400) + 80): | ||||||||
839 | case FN_FRAME_ALIGN_VERT_BOTTOM((20000 + 400) + 79): | ||||||||
840 | if ( bProtect || (bHtmlMode && eFrameType & FrameTypeFlags::FLY_ATCNT)) | ||||||||
841 | rSet.DisableItem( nWhich ); | ||||||||
842 | else | ||||||||
843 | { | ||||||||
844 | // These slots need different labels depending on whether they are anchored in a character | ||||||||
845 | // or on a paragraph/page etc. | ||||||||
846 | OUString sNewLabel; | ||||||||
847 | if (eFrameType & FrameTypeFlags::FLY_INCNT) | ||||||||
848 | { | ||||||||
849 | switch (nWhich) | ||||||||
850 | { | ||||||||
851 | case SID_OBJECT_ALIGN_UP( 10000 + 134 ) : | ||||||||
852 | case FN_FRAME_ALIGN_VERT_TOP((20000 + 400) + 78): | ||||||||
853 | sNewLabel = SwResId(STR_FRMUI_TOP_BASEreinterpret_cast<char const *>("STR_FRMUI_TOP_BASE" "\004" u8"Base line at ~top")); | ||||||||
854 | break; | ||||||||
855 | case SID_OBJECT_ALIGN_MIDDLE( 10000 + 135 ) : | ||||||||
856 | case FN_FRAME_ALIGN_VERT_CENTER((20000 + 400) + 80): | ||||||||
857 | sNewLabel = SwResId(STR_FRMUI_CENTER_BASEreinterpret_cast<char const *>("STR_FRMUI_CENTER_BASE" "\004" u8"Base line ~centered")); | ||||||||
858 | break; | ||||||||
859 | case SID_OBJECT_ALIGN_DOWN( 10000 + 136 ) : | ||||||||
860 | case FN_FRAME_ALIGN_VERT_BOTTOM((20000 + 400) + 79): | ||||||||
861 | if(!bHtmlMode) | ||||||||
862 | sNewLabel = SwResId(STR_FRMUI_BOTTOM_BASEreinterpret_cast<char const *>("STR_FRMUI_BOTTOM_BASE" "\004" u8"~Base line at bottom")); | ||||||||
863 | else | ||||||||
864 | rSet.DisableItem( nWhich ); | ||||||||
865 | break; | ||||||||
866 | } | ||||||||
867 | } | ||||||||
868 | else | ||||||||
869 | { | ||||||||
870 | if (nWhich != FN_FRAME_ALIGN_VERT_TOP((20000 + 400) + 78) && | ||||||||
871 | nWhich != SID_OBJECT_ALIGN_UP( 10000 + 134 ) ) | ||||||||
872 | { | ||||||||
873 | if (aMgr.GetAnchor() == RndStdIds::FLY_AT_FLY) | ||||||||
874 | { | ||||||||
875 | const SwFrameFormat* pFormat = rSh.IsFlyInFly(); | ||||||||
876 | if (pFormat) | ||||||||
877 | { | ||||||||
878 | const SwFormatFrameSize& rFrameSz = pFormat->GetFrameSize(); | ||||||||
879 | if (rFrameSz.GetHeightSizeType() != SwFrameSize::Fixed) | ||||||||
880 | { | ||||||||
881 | rSet.DisableItem( nWhich ); | ||||||||
882 | break; | ||||||||
883 | } | ||||||||
884 | } | ||||||||
885 | } | ||||||||
886 | } | ||||||||
887 | OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(GetFrame()->GetFrame().GetFrameInterface())); | ||||||||
888 | switch (nWhich) | ||||||||
889 | { | ||||||||
890 | case SID_OBJECT_ALIGN_UP( 10000 + 134 ) : | ||||||||
891 | case FN_FRAME_ALIGN_VERT_TOP((20000 + 400) + 78): | ||||||||
892 | { | ||||||||
893 | auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(".uno:AlignTop", aModuleName); | ||||||||
894 | sNewLabel = vcl::CommandInfoProvider::GetLabelForCommand(aProperties); | ||||||||
895 | break; | ||||||||
896 | } | ||||||||
897 | case SID_OBJECT_ALIGN_MIDDLE( 10000 + 135 ): | ||||||||
898 | case FN_FRAME_ALIGN_VERT_CENTER((20000 + 400) + 80): | ||||||||
899 | { | ||||||||
900 | auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(".uno:AlignVerticalCenter", aModuleName); | ||||||||
901 | sNewLabel = vcl::CommandInfoProvider::GetLabelForCommand(aProperties); | ||||||||
902 | break; | ||||||||
903 | } | ||||||||
904 | case SID_OBJECT_ALIGN_DOWN( 10000 + 136 ): | ||||||||
905 | case FN_FRAME_ALIGN_VERT_BOTTOM((20000 + 400) + 79): | ||||||||
906 | { | ||||||||
907 | auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(".uno:AlignBottom", aModuleName); | ||||||||
908 | sNewLabel = vcl::CommandInfoProvider::GetLabelForCommand(aProperties); | ||||||||
909 | break; | ||||||||
910 | } | ||||||||
911 | } | ||||||||
912 | } | ||||||||
913 | if ( !sNewLabel.isEmpty() ) | ||||||||
914 | rSet.Put( SfxStringItem( nWhich, sNewLabel )); | ||||||||
915 | } | ||||||||
916 | break; | ||||||||
917 | case SID_HYPERLINK_GETLINK(10000 + 361): | ||||||||
918 | { | ||||||||
919 | SvxHyperlinkItem aHLinkItem; | ||||||||
920 | const SfxPoolItem* pItem; | ||||||||
921 | |||||||||
922 | SfxItemSet aURLSet(GetPool(), svl::Items<RES_URL, RES_URL>{}); | ||||||||
923 | rSh.GetFlyFrameAttr( aURLSet ); | ||||||||
924 | |||||||||
925 | if(SfxItemState::SET == aURLSet.GetItemState(RES_URL, true, &pItem)) | ||||||||
926 | { | ||||||||
927 | const SwFormatURL* pFormatURL = static_cast<const SwFormatURL*>(pItem); | ||||||||
928 | aHLinkItem.SetURL(pFormatURL->GetURL()); | ||||||||
929 | aHLinkItem.SetTargetFrame(pFormatURL->GetTargetFrameName()); | ||||||||
930 | aHLinkItem.SetName(rSh.GetFlyName()); | ||||||||
931 | } | ||||||||
932 | |||||||||
933 | aHLinkItem.SetInsertMode(static_cast<SvxLinkInsertMode>(aHLinkItem.GetInsertMode() | | ||||||||
934 | (bHtmlMode ? HLINK_HTMLMODE : 0))); | ||||||||
935 | |||||||||
936 | rSet.Put(aHLinkItem); | ||||||||
937 | } | ||||||||
938 | break; | ||||||||
939 | |||||||||
940 | case FN_FRAME_CHAIN((20000 + 1600) + 136): | ||||||||
941 | { | ||||||||
942 | const SelectionType nSel = rSh.GetSelectionType(); | ||||||||
943 | if (nSel & SelectionType::Graphic || nSel & SelectionType::Ole) | ||||||||
944 | rSet.DisableItem( FN_FRAME_CHAIN((20000 + 1600) + 136) ); | ||||||||
945 | else | ||||||||
946 | { | ||||||||
947 | const SwFrameFormat *pFormat = rSh.GetFlyFrameFormat(); | ||||||||
948 | if ( bParentCntProt || rSh.GetView().GetEditWin().GetApplyTemplate() || | ||||||||
949 | !pFormat || pFormat->GetChain().GetNext() ) | ||||||||
950 | { | ||||||||
951 | rSet.DisableItem( FN_FRAME_CHAIN((20000 + 1600) + 136) ); | ||||||||
952 | } | ||||||||
953 | else | ||||||||
954 | { | ||||||||
955 | bool bChainMode = rSh.GetView().GetEditWin().IsChainMode(); | ||||||||
956 | rSet.Put( SfxBoolItem( FN_FRAME_CHAIN((20000 + 1600) + 136), bChainMode ) ); | ||||||||
957 | } | ||||||||
958 | } | ||||||||
959 | } | ||||||||
960 | break; | ||||||||
961 | case FN_FRAME_UNCHAIN((20000 + 1600) + 137): | ||||||||
962 | { | ||||||||
963 | const SelectionType nSel = rSh.GetSelectionType(); | ||||||||
964 | if (nSel & SelectionType::Graphic || nSel & SelectionType::Ole) | ||||||||
965 | rSet.DisableItem( FN_FRAME_UNCHAIN((20000 + 1600) + 137) ); | ||||||||
966 | else | ||||||||
967 | { | ||||||||
968 | const SwFrameFormat *pFormat = rSh.GetFlyFrameFormat(); | ||||||||
969 | if ( bParentCntProt || rSh.GetView().GetEditWin().GetApplyTemplate() || | ||||||||
970 | !pFormat || !pFormat->GetChain().GetNext() ) | ||||||||
971 | { | ||||||||
972 | rSet.DisableItem( FN_FRAME_UNCHAIN((20000 + 1600) + 137) ); | ||||||||
973 | } | ||||||||
974 | } | ||||||||
975 | } | ||||||||
976 | break; | ||||||||
977 | case SID_FRAME_TO_TOP( 10000 + 286 ): | ||||||||
978 | case SID_FRAME_TO_BOTTOM( 10000 + 287 ): | ||||||||
979 | case FN_FRAME_UP((20000 + 400) + 122): | ||||||||
980 | case FN_FRAME_DOWN((20000 + 400) + 123): | ||||||||
981 | if ( bParentCntProt ) | ||||||||
982 | rSet.DisableItem( nWhich ); | ||||||||
983 | break; | ||||||||
984 | |||||||||
985 | case SID_ATTR_TRANSFORMTypedWhichId<SfxInt32Item>( 10000 + 87 ): | ||||||||
986 | { | ||||||||
987 | rSet.DisableItem( nWhich ); | ||||||||
988 | } | ||||||||
989 | break; | ||||||||
990 | |||||||||
991 | case SID_ATTR_TRANSFORM_PROTECT_SIZETypedWhichId<SfxBoolItem>( 10000 + 237 ): | ||||||||
992 | { | ||||||||
993 | const FlyProtectFlags eProtection = rSh.IsSelObjProtected( FlyProtectFlags::Size ); | ||||||||
994 | if ( ( eProtection & FlyProtectFlags::Content ) || | ||||||||
995 | ( eProtection & FlyProtectFlags::Size ) ) | ||||||||
996 | { | ||||||||
997 | rSet.Put( SfxBoolItem( SID_ATTR_TRANSFORM_PROTECT_SIZETypedWhichId<SfxBoolItem>( 10000 + 237 ), true ) ); | ||||||||
998 | } | ||||||||
999 | else | ||||||||
1000 | { | ||||||||
1001 | rSet.Put( SfxBoolItem( SID_ATTR_TRANSFORM_PROTECT_SIZETypedWhichId<SfxBoolItem>( 10000 + 237 ), false ) ); | ||||||||
1002 | } | ||||||||
1003 | } | ||||||||
1004 | break; | ||||||||
1005 | |||||||||
1006 | case SID_ATTR_TRANSFORM_WIDTHTypedWhichId<SfxUInt32Item>( 10000 + 90 ): | ||||||||
1007 | { | ||||||||
1008 | rSet.Put( SfxUInt32Item( SID_ATTR_TRANSFORM_WIDTHTypedWhichId<SfxUInt32Item>( 10000 + 90 ), aMgr.GetSize().getWidth() ) ); | ||||||||
1009 | } | ||||||||
1010 | break; | ||||||||
1011 | |||||||||
1012 | case SID_ATTR_TRANSFORM_HEIGHTTypedWhichId<SfxUInt32Item>( 10000 + 91 ): | ||||||||
1013 | { | ||||||||
1014 | rSet.Put( SfxUInt32Item( SID_ATTR_TRANSFORM_HEIGHTTypedWhichId<SfxUInt32Item>( 10000 + 91 ), aMgr.GetSize().getHeight() ) ); | ||||||||
1015 | } | ||||||||
1016 | break; | ||||||||
1017 | |||||||||
1018 | case FN_FORMAT_FRAME_DLG((20000 + 400) + 56): | ||||||||
1019 | { | ||||||||
1020 | const SelectionType nSel = rSh.GetSelectionType(); | ||||||||
1021 | if ( bParentCntProt || nSel & SelectionType::Graphic) | ||||||||
1022 | rSet.DisableItem( nWhich ); | ||||||||
1023 | } | ||||||||
1024 | break; | ||||||||
1025 | // #i73249# | ||||||||
1026 | case FN_TITLE_DESCRIPTION_SHAPE((20000 + 1600) + 15): | ||||||||
1027 | case FN_NAME_SHAPE((20000 + 1600) + 14): | ||||||||
1028 | { | ||||||||
1029 | SwWrtShell &rWrtSh = GetShell(); | ||||||||
1030 | SdrView* pSdrView = rWrtSh.GetDrawViewWithValidMarkList(); | ||||||||
1031 | if ( !pSdrView || | ||||||||
1032 | pSdrView->GetMarkedObjectCount() != 1 ) | ||||||||
1033 | { | ||||||||
1034 | rSet.DisableItem( nWhich ); | ||||||||
1035 | } | ||||||||
1036 | } | ||||||||
1037 | break; | ||||||||
1038 | |||||||||
1039 | case FN_POSTIT((20000 + 300) + 29): | ||||||||
1040 | { | ||||||||
1041 | SwFlyFrame* pFly = rSh.GetSelectedFlyFrame(); | ||||||||
1042 | if (pFly) | ||||||||
1043 | { | ||||||||
1044 | SwFrameFormat* pFormat = pFly->GetFormat(); | ||||||||
1045 | if (pFormat) | ||||||||
1046 | { | ||||||||
1047 | RndStdIds eAnchorId = pFormat->GetAnchor().GetAnchorId(); | ||||||||
1048 | // SwWrtShell::InsertPostIt() only works on as-char and at-char anchored | ||||||||
1049 | // images. | ||||||||
1050 | if (eAnchorId != RndStdIds::FLY_AS_CHAR && eAnchorId != RndStdIds::FLY_AT_CHAR) | ||||||||
1051 | { | ||||||||
1052 | rSet.DisableItem(nWhich); | ||||||||
1053 | } | ||||||||
1054 | } | ||||||||
1055 | } | ||||||||
1056 | } | ||||||||
1057 | break; | ||||||||
1058 | |||||||||
1059 | default: | ||||||||
1060 | /* do nothing */; | ||||||||
1061 | break; | ||||||||
1062 | } | ||||||||
1063 | nWhich = aIter.NextWhich(); | ||||||||
1064 | } | ||||||||
1065 | } | ||||||||
1066 | |||||||||
1067 | SwFrameShell::SwFrameShell(SwView &_rView) : | ||||||||
1068 | SwBaseShell( _rView ) | ||||||||
1069 | { | ||||||||
1070 | SetName("Frame"); | ||||||||
1071 | |||||||||
1072 | // #96392# Use this to announce it is the frame shell who creates the selection. | ||||||||
1073 | SwTransferable::CreateSelection( _rView.GetWrtShell(), this ); | ||||||||
1074 | |||||||||
1075 | SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Frame)); | ||||||||
1076 | } | ||||||||
1077 | |||||||||
1078 | SwFrameShell::~SwFrameShell() | ||||||||
1079 | { | ||||||||
1080 | // #96392# Only clear the selection if it was this frame shell who created it. | ||||||||
1081 | SwTransferable::ClearSelection( GetShell(), this ); | ||||||||
1082 | } | ||||||||
1083 | |||||||||
1084 | void SwFrameShell::ExecFrameStyle(SfxRequest const & rReq) | ||||||||
1085 | { | ||||||||
1086 | SwWrtShell &rSh = GetShell(); | ||||||||
1087 | bool bDefault = false; | ||||||||
1088 | if (!rSh.IsFrameSelected()) | ||||||||
1089 | return; | ||||||||
1090 | // At first pick the default BoxItem out of the pool. | ||||||||
1091 | // If unequal to regular box item, then it has already | ||||||||
1092 | // been changed (New one is no default). | ||||||||
1093 | const SvxBoxItem* pPoolBoxItem = ::GetDfltAttr(RES_BOX); | ||||||||
1094 | |||||||||
1095 | const SfxItemSet *pArgs = rReq.GetArgs(); | ||||||||
1096 | SfxItemSet aFrameSet(rSh.GetAttrPool(), svl::Items<RES_BOX, RES_BOX>{}); | ||||||||
1097 | |||||||||
1098 | rSh.GetFlyFrameAttr( aFrameSet ); | ||||||||
1099 | const SvxBoxItem& rBoxItem = aFrameSet.Get(RES_BOX); | ||||||||
1100 | |||||||||
1101 | if (pPoolBoxItem == &rBoxItem) | ||||||||
1102 | bDefault = true; | ||||||||
1103 | |||||||||
1104 | std::unique_ptr<SvxBoxItem> aBoxItem(rBoxItem.Clone()); | ||||||||
1105 | |||||||||
1106 | SvxBorderLine aBorderLine; | ||||||||
1107 | const SfxPoolItem *pItem = nullptr; | ||||||||
1108 | |||||||||
1109 | if(pArgs) // Any controller can sometimes deliver nothing #48169# | ||||||||
1110 | { | ||||||||
1111 | switch (rReq.GetSlot()) | ||||||||
1112 | { | ||||||||
1113 | case SID_ATTR_BORDER( 10000 + 188 ): | ||||||||
1114 | { | ||||||||
1115 | if (pArgs->GetItemState(RES_BOX, true, &pItem) == SfxItemState::SET) | ||||||||
1116 | { | ||||||||
1117 | std::unique_ptr<SvxBoxItem> aNewBox(static_cast<SvxBoxItem*>(pItem->Clone())); | ||||||||
1118 | const SvxBorderLine* pBorderLine; | ||||||||
1119 | |||||||||
1120 | pBorderLine = aBoxItem->GetTop(); | ||||||||
1121 | if (pBorderLine != nullptr) | ||||||||
1122 | lcl_FrameGetMaxLineWidth(pBorderLine, aBorderLine); | ||||||||
1123 | pBorderLine = aBoxItem->GetBottom(); | ||||||||
1124 | if (pBorderLine != nullptr) | ||||||||
1125 | lcl_FrameGetMaxLineWidth(pBorderLine, aBorderLine); | ||||||||
1126 | pBorderLine = aBoxItem->GetLeft(); | ||||||||
1127 | if (pBorderLine != nullptr) | ||||||||
1128 | lcl_FrameGetMaxLineWidth(pBorderLine, aBorderLine); | ||||||||
1129 | pBorderLine = aBoxItem->GetRight(); | ||||||||
1130 | if (pBorderLine != nullptr) | ||||||||
1131 | lcl_FrameGetMaxLineWidth(pBorderLine, aBorderLine); | ||||||||
1132 | |||||||||
1133 | if(aBorderLine.GetOutWidth() == 0) | ||||||||
1134 | { | ||||||||
1135 | aBorderLine.SetBorderLineStyle( | ||||||||
1136 | SvxBorderLineStyle::SOLID); | ||||||||
1137 | aBorderLine.SetWidth( DEF_LINE_WIDTH_01 ); | ||||||||
1138 | } | ||||||||
1139 | //Set distance only if the request is received from the controller. | ||||||||
1140 | |||||||||
1141 | #if HAVE_FEATURE_SCRIPTING1 | ||||||||
1142 | if(!StarBASIC::IsRunning()) | ||||||||
1143 | #endif | ||||||||
1144 | { | ||||||||
1145 | // TODO: should this copy 4 individual Dist instead? | ||||||||
1146 | aNewBox->SetAllDistances(rBoxItem.GetSmallestDistance()); | ||||||||
1147 | } | ||||||||
1148 | |||||||||
1149 | aBoxItem = std::move(aNewBox); | ||||||||
1150 | |||||||||
1151 | if( aBoxItem->GetTop() != nullptr ) | ||||||||
1152 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::TOP); | ||||||||
1153 | if( aBoxItem->GetBottom() != nullptr ) | ||||||||
1154 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM); | ||||||||
1155 | if( aBoxItem->GetLeft() != nullptr ) | ||||||||
1156 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::LEFT); | ||||||||
1157 | if( aBoxItem->GetRight() != nullptr ) | ||||||||
1158 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT); | ||||||||
1159 | } | ||||||||
1160 | } | ||||||||
1161 | break; | ||||||||
1162 | |||||||||
1163 | case SID_FRAME_LINESTYLETypedWhichId<SvxLineItem>( 10000 + 201 ): | ||||||||
1164 | { | ||||||||
1165 | if (pArgs->GetItemState(SID_FRAME_LINESTYLETypedWhichId<SvxLineItem>( 10000 + 201 ), false, &pItem) == SfxItemState::SET) | ||||||||
1166 | { | ||||||||
1167 | const SvxLineItem* pLineItem = | ||||||||
1168 | static_cast<const SvxLineItem*>(pItem); | ||||||||
1169 | |||||||||
1170 | if ( pLineItem->GetLine() ) | ||||||||
1171 | { | ||||||||
1172 | aBorderLine = *(pLineItem->GetLine()); | ||||||||
1173 | |||||||||
1174 | if (!aBoxItem->GetTop() && !aBoxItem->GetBottom() && | ||||||||
1175 | !aBoxItem->GetLeft() && !aBoxItem->GetRight()) | ||||||||
1176 | { | ||||||||
1177 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::TOP); | ||||||||
1178 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM); | ||||||||
1179 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::LEFT); | ||||||||
1180 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT); | ||||||||
1181 | } | ||||||||
1182 | else | ||||||||
1183 | { | ||||||||
1184 | if( aBoxItem->GetTop() ) | ||||||||
1185 | { | ||||||||
1186 | aBorderLine.SetColor( aBoxItem->GetTop()->GetColor() ); | ||||||||
1187 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::TOP); | ||||||||
1188 | } | ||||||||
1189 | if( aBoxItem->GetBottom() ) | ||||||||
1190 | { | ||||||||
1191 | aBorderLine.SetColor( aBoxItem->GetBottom()->GetColor()); | ||||||||
1192 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM); | ||||||||
1193 | } | ||||||||
1194 | if( aBoxItem->GetLeft() ) | ||||||||
1195 | { | ||||||||
1196 | aBorderLine.SetColor( aBoxItem->GetLeft()->GetColor()); | ||||||||
1197 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::LEFT); | ||||||||
1198 | } | ||||||||
1199 | if( aBoxItem->GetRight() ) | ||||||||
1200 | { | ||||||||
1201 | aBorderLine.SetColor(aBoxItem->GetRight()->GetColor()); | ||||||||
1202 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT); | ||||||||
1203 | } | ||||||||
1204 | } | ||||||||
1205 | } | ||||||||
1206 | else | ||||||||
1207 | { | ||||||||
1208 | aBoxItem->SetLine(nullptr, SvxBoxItemLine::TOP); | ||||||||
1209 | aBoxItem->SetLine(nullptr, SvxBoxItemLine::BOTTOM); | ||||||||
1210 | aBoxItem->SetLine(nullptr, SvxBoxItemLine::LEFT); | ||||||||
1211 | aBoxItem->SetLine(nullptr, SvxBoxItemLine::RIGHT); | ||||||||
1212 | } | ||||||||
1213 | } | ||||||||
1214 | } | ||||||||
1215 | break; | ||||||||
1216 | |||||||||
1217 | case SID_FRAME_LINECOLORTypedWhichId<SvxColorItem>( 10000 + 202 ): | ||||||||
1218 | { | ||||||||
1219 | if (pArgs->GetItemState(SID_FRAME_LINECOLORTypedWhichId<SvxColorItem>( 10000 + 202 ), false, &pItem) == SfxItemState::SET) | ||||||||
1220 | { | ||||||||
1221 | const Color& rNewColor = static_cast<const SvxColorItem*>(pItem)->GetValue(); | ||||||||
1222 | |||||||||
1223 | if (!aBoxItem->GetTop() && !aBoxItem->GetBottom() && | ||||||||
1224 | !aBoxItem->GetLeft() && !aBoxItem->GetRight()) | ||||||||
1225 | { | ||||||||
1226 | aBorderLine.SetColor( rNewColor ); | ||||||||
1227 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::TOP); | ||||||||
1228 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM); | ||||||||
1229 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::LEFT); | ||||||||
1230 | aBoxItem->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT); | ||||||||
1231 | } | ||||||||
1232 | else | ||||||||
1233 | { | ||||||||
1234 | if ( aBoxItem->GetTop() ) | ||||||||
1235 | const_cast<SvxBorderLine*>(aBoxItem->GetTop())->SetColor( rNewColor ); | ||||||||
1236 | if ( aBoxItem->GetBottom() ) | ||||||||
1237 | const_cast<SvxBorderLine*>(aBoxItem->GetBottom())->SetColor( rNewColor ); | ||||||||
1238 | if ( aBoxItem->GetLeft() ) | ||||||||
1239 | const_cast<SvxBorderLine*>(aBoxItem->GetLeft())->SetColor( rNewColor ); | ||||||||
1240 | if ( aBoxItem->GetRight() ) | ||||||||
1241 | const_cast<SvxBorderLine*>(aBoxItem->GetRight())->SetColor( rNewColor ); | ||||||||
1242 | } | ||||||||
1243 | } | ||||||||
1244 | } | ||||||||
1245 | break; | ||||||||
1246 | } | ||||||||
1247 | } | ||||||||
1248 | if (bDefault && (aBoxItem->GetTop() || aBoxItem->GetBottom() || | ||||||||
1249 | aBoxItem->GetLeft() || aBoxItem->GetRight())) | ||||||||
1250 | { | ||||||||
1251 | aBoxItem->SetAllDistances(MIN_BORDER_DIST28); | ||||||||
1252 | } | ||||||||
1253 | aFrameSet.Put( *aBoxItem ); | ||||||||
1254 | // Template AutoUpdate | ||||||||
1255 | SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat(); | ||||||||
1256 | if(pFormat && pFormat->IsAutoUpdateFormat()) | ||||||||
1257 | { | ||||||||
1258 | rSh.AutoUpdateFrame(pFormat, aFrameSet); | ||||||||
1259 | } | ||||||||
1260 | else | ||||||||
1261 | rSh.SetFlyFrameAttr( aFrameSet ); | ||||||||
1262 | |||||||||
1263 | } | ||||||||
1264 | |||||||||
1265 | static void lcl_FrameGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLine& rBorderLine) | ||||||||
1266 | { | ||||||||
1267 | if(pBorderLine->GetWidth() > rBorderLine.GetWidth()) | ||||||||
1268 | rBorderLine.SetWidth(pBorderLine->GetWidth()); | ||||||||
1269 | |||||||||
1270 | rBorderLine.SetBorderLineStyle(pBorderLine->GetBorderLineStyle()); | ||||||||
1271 | rBorderLine.SetColor(pBorderLine->GetColor()); | ||||||||
1272 | } | ||||||||
1273 | |||||||||
1274 | void SwFrameShell::GetLineStyleState(SfxItemSet &rSet) | ||||||||
1275 | { | ||||||||
1276 | SwWrtShell &rSh = GetShell(); | ||||||||
1277 | bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE; | ||||||||
1278 | |||||||||
1279 | if (bParentCntProt) | ||||||||
1280 | { | ||||||||
1281 | if (rSh.IsFrameSelected()) | ||||||||
1282 | rSet.DisableItem( SID_FRAME_LINECOLORTypedWhichId<SvxColorItem>( 10000 + 202 ) ); | ||||||||
1283 | |||||||||
1284 | rSet.DisableItem( SID_ATTR_BORDER( 10000 + 188 ) ); | ||||||||
1285 | rSet.DisableItem( SID_FRAME_LINESTYLETypedWhichId<SvxLineItem>( 10000 + 201 ) ); | ||||||||
1286 | } | ||||||||
1287 | else | ||||||||
1288 | { | ||||||||
1289 | if (rSh.IsFrameSelected()) | ||||||||
1290 | { | ||||||||
1291 | SfxItemSet aFrameSet( rSh.GetAttrPool(), svl::Items<RES_BOX, RES_BOX>{} ); | ||||||||
1292 | |||||||||
1293 | rSh.GetFlyFrameAttr(aFrameSet); | ||||||||
1294 | |||||||||
1295 | const SvxBorderLine* pLine = aFrameSet.Get(RES_BOX).GetTop(); | ||||||||
1296 | rSet.Put(SvxColorItem(pLine ? pLine->GetColor() : Color(), SID_FRAME_LINECOLORTypedWhichId<SvxColorItem>( 10000 + 202 ))); | ||||||||
1297 | } | ||||||||
1298 | } | ||||||||
1299 | } | ||||||||
1300 | |||||||||
1301 | void SwFrameShell::StateInsert(SfxItemSet &rSet) | ||||||||
1302 | { | ||||||||
1303 | const SelectionType nSel = GetShell().GetSelectionType(); | ||||||||
1304 | if ( (nSel & SelectionType::Graphic) | ||||||||
1305 | || (nSel & SelectionType::Ole) ) | ||||||||
1306 | { | ||||||||
1307 | rSet.DisableItem(FN_INSERT_FRAME((20000 + 300) + 34)); | ||||||||
1308 | } | ||||||||
1309 | else if ( GetShell().CursorInsideInputField() ) | ||||||||
1310 | { | ||||||||
1311 | rSet.DisableItem(FN_INSERT_FRAME((20000 + 300) + 34)); | ||||||||
1312 | } | ||||||||
1313 | } | ||||||||
1314 | |||||||||
1315 | void SwFrameShell::GetDrawAttrStateTextFrame(SfxItemSet &rSet) | ||||||||
1316 | { | ||||||||
1317 | SwWrtShell &rSh = GetShell(); | ||||||||
1318 | |||||||||
1319 | if(rSh.IsFrameSelected()) | ||||||||
1320 | { | ||||||||
1321 | rSh.GetFlyFrameAttr(rSet); | ||||||||
1322 | } | ||||||||
1323 | else | ||||||||
1324 | { | ||||||||
1325 | SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList(); | ||||||||
1326 | |||||||||
1327 | if(pSdrView) | ||||||||
1328 | { | ||||||||
1329 | rSet.Put(pSdrView->GetDefaultAttr()); | ||||||||
1330 | } | ||||||||
1331 | } | ||||||||
1332 | } | ||||||||
1333 | |||||||||
1334 | void SwFrameShell::ExecDrawAttrArgsTextFrame(SfxRequest const & rReq) | ||||||||
1335 | { | ||||||||
1336 | const SfxItemSet* pArgs = rReq.GetArgs(); | ||||||||
1337 | SwWrtShell& rSh = GetShell(); | ||||||||
1338 | |||||||||
1339 | if(pArgs) | ||||||||
1340 | { | ||||||||
1341 | if(rSh.IsFrameSelected()) | ||||||||
1342 | { | ||||||||
1343 | rSh.SetFlyFrameAttr(const_cast< SfxItemSet& >(*pArgs)); | ||||||||
1344 | } | ||||||||
1345 | else | ||||||||
1346 | { | ||||||||
1347 | SdrView* pSdrView = rSh.GetDrawViewWithValidMarkList(); | ||||||||
1348 | |||||||||
1349 | if(pSdrView) | ||||||||
1350 | { | ||||||||
1351 | pSdrView->SetDefaultAttr(*pArgs, false); | ||||||||
1352 | } | ||||||||
1353 | } | ||||||||
1354 | } | ||||||||
1355 | else | ||||||||
1356 | { | ||||||||
1357 | SfxDispatcher* pDis = rSh.GetView().GetViewFrame()->GetDispatcher(); | ||||||||
1358 | |||||||||
1359 | switch(rReq.GetSlot()) | ||||||||
1360 | { | ||||||||
1361 | case SID_ATTR_FILL_STYLE( 10000 + 164 ): | ||||||||
1362 | case SID_ATTR_FILL_COLOR( 10000 + 165 ): | ||||||||
1363 | case SID_ATTR_FILL_GRADIENT( 10000 + 166 ): | ||||||||
1364 | case SID_ATTR_FILL_HATCH( 10000 + 167 ): | ||||||||
1365 | case SID_ATTR_FILL_BITMAP( 10000 + 168 ): | ||||||||
1366 | case SID_ATTR_FILL_TRANSPARENCE( 10000 + 1124 ): | ||||||||
1367 | case SID_ATTR_FILL_FLOATTRANSPARENCE( 10000 + 1125 ): | ||||||||
1368 | { | ||||||||
1369 | pDis->Execute(SID_ATTRIBUTES_AREA( 10000 + 142 )); | ||||||||
1370 | break; | ||||||||
1371 | } | ||||||||
1372 | } | ||||||||
1373 | } | ||||||||
1374 | } | ||||||||
1375 | |||||||||
1376 | void SwFrameShell::ExecDrawDlgTextFrame(SfxRequest const & rReq) | ||||||||
1377 | { | ||||||||
1378 | switch(rReq.GetSlot()) | ||||||||
1379 | { | ||||||||
1380 | case SID_ATTRIBUTES_AREA( 10000 + 142 ): | ||||||||
1381 | { | ||||||||
1382 | SwWrtShell& rSh = GetShell(); | ||||||||
1383 | |||||||||
1384 | if(rSh.IsFrameSelected()) | ||||||||
1385 | { | ||||||||
1386 | SdrModel* pDoc = rSh.GetDrawView()->GetModel(); | ||||||||
1387 | SfxItemSet aNewAttr(pDoc->GetItemPool()); | ||||||||
1388 | |||||||||
1389 | // get attributes from FlyFrame | ||||||||
1390 | rSh.GetFlyFrameAttr(aNewAttr); | ||||||||
1391 | |||||||||
1392 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); | ||||||||
1393 | VclPtr<AbstractSvxAreaTabDialog> pDlg(pFact->CreateSvxAreaTabDialog( | ||||||||
1394 | GetView().GetFrameWeld(), | ||||||||
1395 | &aNewAttr, | ||||||||
1396 | pDoc, | ||||||||
1397 | false)); | ||||||||
1398 | |||||||||
1399 | pDlg->StartExecuteAsync([pDlg, this](sal_Int32 nResult){ | ||||||||
1400 | if(nResult == RET_OK) | ||||||||
1401 | { | ||||||||
1402 | // set attributes at FlyFrame | ||||||||
1403 | GetShell().SetFlyFrameAttr(const_cast< SfxItemSet& >(*pDlg->GetOutputItemSet())); | ||||||||
1404 | |||||||||
1405 | static sal_uInt16 aInval[] = | ||||||||
1406 | { | ||||||||
1407 | SID_ATTR_FILL_STYLE( 10000 + 164 ), | ||||||||
1408 | SID_ATTR_FILL_COLOR( 10000 + 165 ), | ||||||||
1409 | SID_ATTR_FILL_TRANSPARENCE( 10000 + 1124 ), | ||||||||
1410 | SID_ATTR_FILL_FLOATTRANSPARENCE( 10000 + 1125 ), | ||||||||
1411 | 0 | ||||||||
1412 | }; | ||||||||
1413 | |||||||||
1414 | SfxBindings &rBnd = GetView().GetViewFrame()->GetBindings(); | ||||||||
1415 | |||||||||
1416 | rBnd.Invalidate(aInval); | ||||||||
1417 | rBnd.Update(SID_ATTR_FILL_STYLE( 10000 + 164 )); | ||||||||
1418 | rBnd.Update(SID_ATTR_FILL_COLOR( 10000 + 165 )); | ||||||||
1419 | rBnd.Update(SID_ATTR_FILL_TRANSPARENCE( 10000 + 1124 )); | ||||||||
1420 | rBnd.Update(SID_ATTR_FILL_FLOATTRANSPARENCE( 10000 + 1125 )); | ||||||||
1421 | } | ||||||||
1422 | pDlg->disposeOnce(); | ||||||||
1423 | }); | ||||||||
1424 | } | ||||||||
1425 | |||||||||
1426 | break; | ||||||||
1427 | } | ||||||||
1428 | } | ||||||||
1429 | } | ||||||||
1430 | |||||||||
1431 | void SwFrameShell::DisableStateTextFrame(SfxItemSet &rSet) | ||||||||
1432 | { | ||||||||
1433 | SfxWhichIter aIter(rSet); | ||||||||
1434 | sal_uInt16 nWhich(aIter.FirstWhich()); | ||||||||
1435 | |||||||||
1436 | while(nWhich) | ||||||||
1437 | { | ||||||||
1438 | switch(nWhich) | ||||||||
1439 | { | ||||||||
1440 | case SID_ATTRIBUTES_AREA( 10000 + 142 ): | ||||||||
1441 | { | ||||||||
1442 | SwWrtShell& rSh = GetShell(); | ||||||||
1443 | |||||||||
1444 | if(!rSh.IsFrameSelected()) | ||||||||
1445 | { | ||||||||
1446 | rSet.DisableItem(nWhich); | ||||||||
1447 | } | ||||||||
1448 | |||||||||
1449 | break; | ||||||||
1450 | } | ||||||||
1451 | default: | ||||||||
1452 | { | ||||||||
1453 | rSet.DisableItem(nWhich); | ||||||||
1454 | break; | ||||||||
1455 | } | ||||||||
1456 | } | ||||||||
1457 | |||||||||
1458 | nWhich = aIter.NextWhich(); | ||||||||
1459 | } | ||||||||
1460 | } | ||||||||
1461 | |||||||||
1462 | /* 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 |