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 <hintids.hxx> | |||
21 | #include <svl/zforlist.hxx> | |||
22 | #include <svl/stritem.hxx> | |||
23 | #include <svl/whiter.hxx> | |||
24 | #include <unotools/moduleoptions.hxx> | |||
25 | #include <editeng/lrspitem.hxx> | |||
26 | #include <editeng/ulspitem.hxx> | |||
27 | #include <editeng/brushitem.hxx> | |||
28 | #include <editeng/boxitem.hxx> | |||
29 | #include <editeng/shaditem.hxx> | |||
30 | #include <editeng/spltitem.hxx> | |||
31 | #include <editeng/keepitem.hxx> | |||
32 | #include <editeng/lineitem.hxx> | |||
33 | #include <editeng/colritem.hxx> | |||
34 | #include <editeng/frmdiritem.hxx> | |||
35 | #include <svx/numinf.hxx> | |||
36 | #include <svx/svddef.hxx> | |||
37 | #include <svx/svxdlg.hxx> | |||
38 | #include <sfx2/bindings.hxx> | |||
39 | #include <vcl/weld.hxx> | |||
40 | #include <sfx2/request.hxx> | |||
41 | #include <sfx2/dispatch.hxx> | |||
42 | #include <sfx2/objface.hxx> | |||
43 | #include <sfx2/viewfrm.hxx> | |||
44 | #include <vcl/EnumContext.hxx> | |||
45 | #include <o3tl/enumrange.hxx> | |||
46 | #include <comphelper/lok.hxx> | |||
47 | #include <LibreOfficeKit/LibreOfficeKitEnums.h> | |||
48 | #include <editeng/itemtype.hxx> | |||
49 | ||||
50 | #include <fmtornt.hxx> | |||
51 | #include <fmtlsplt.hxx> | |||
52 | #include <fmtrowsplt.hxx> | |||
53 | #include <fmtfsize.hxx> | |||
54 | #include <swmodule.hxx> | |||
55 | #include <wrtsh.hxx> | |||
56 | #include <wview.hxx> | |||
57 | #include <frmatr.hxx> | |||
58 | #include <uitool.hxx> | |||
59 | #include <inputwin.hxx> | |||
60 | #include <uiitems.hxx> | |||
61 | #include <tabsh.hxx> | |||
62 | #include <swtablerep.hxx> | |||
63 | #include <tablemgr.hxx> | |||
64 | #include <cellatr.hxx> | |||
65 | #include <frmfmt.hxx> | |||
66 | #include <swundo.hxx> | |||
67 | #include <swtable.hxx> | |||
68 | #include <docsh.hxx> | |||
69 | #include <tblsel.hxx> | |||
70 | #include <viewopt.hxx> | |||
71 | ||||
72 | #include <strings.hrc> | |||
73 | #include <cmdid.h> | |||
74 | #include <unobaseclass.hxx> | |||
75 | ||||
76 | #define ShellClass_SwTableShell | |||
77 | #include <sfx2/msg.hxx> | |||
78 | #include <swslots.hxx> | |||
79 | ||||
80 | #include <swabstdlg.hxx> | |||
81 | ||||
82 | #include <memory> | |||
83 | ||||
84 | using ::editeng::SvxBorderLine; | |||
85 | using namespace ::com::sun::star; | |||
86 | ||||
87 | SFX_IMPL_INTERFACE(SwTableShell, SwBaseShell)SfxInterface* SwTableShell::pInterface = nullptr; SfxInterface * SwTableShell::GetStaticInterface() { if ( !pInterface ) { pInterface = new SfxInterface( "SwTableShell", false, GetInterfaceId(), SwBaseShell::GetStaticInterface(), aSwTableShellSlots_Impl[0 ], sal_uInt16(sizeof(aSwTableShellSlots_Impl) / sizeof(SfxSlot ) ) ); InitInterface_Impl(); } return pInterface; } SfxInterface * SwTableShell::GetInterface() const { return GetStaticInterface (); } void SwTableShell::RegisterInterface(const SfxModule* pMod ) { GetStaticInterface()->Register(pMod); } | |||
88 | ||||
89 | void SwTableShell::InitInterface_Impl() | |||
90 | { | |||
91 | GetStaticInterface()->RegisterPopupMenu("table"); | |||
92 | GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT1, SfxVisibilityFlags::Invisible, ToolbarId::Table_Toolbox); | |||
93 | } | |||
94 | ||||
95 | ||||
96 | const sal_uInt16 aUITableAttrRange[] = | |||
97 | { | |||
98 | XATTR_FILL_FIRST, XATTR_FILL_LAST, | |||
99 | FN_PARAM_TABLE_NAME((20000 + 1100)+44), FN_PARAM_TABLE_NAME((20000 + 1100)+44), | |||
100 | FN_PARAM_TABLE_HEADLINE((20000 + 1100)+50), FN_PARAM_TABLE_HEADLINE((20000 + 1100)+50), | |||
101 | FN_PARAM_TABLE_SPACE((20000 + 1100)+51), FN_PARAM_TABLE_SPACE((20000 + 1100)+51), | |||
102 | FN_TABLE_REP((20000 + 400) + 99), FN_TABLE_REP((20000 + 400) + 99), | |||
103 | SID_RULER_BORDERSTypedWhichId<SvxRulerItem>( 10000 + 80 ), SID_RULER_BORDERSTypedWhichId<SvxRulerItem>( 10000 + 80 ), | |||
104 | RES_LR_SPACE, RES_UL_SPACE, | |||
105 | SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), SID_ATTR_BORDER_SHADOW( 10000 + 25 ), | |||
106 | RES_BOX, RES_SHADOW, | |||
107 | RES_BACKGROUND, RES_BACKGROUND, | |||
108 | SID_BACKGRND_DESTINATION( 10000 + 404 ), SID_BACKGRND_DESTINATION( 10000 + 404 ), | |||
109 | SID_HTML_MODE(10000 + 414), SID_HTML_MODE(10000 + 414), | |||
110 | SID_ATTR_BRUSH_ROW( 10000 + 368 ), SID_ATTR_BRUSH_TABLE( 10000 + 453 ), | |||
111 | RES_PAGEDESC, RES_BREAK, | |||
112 | RES_KEEP, RES_KEEP, | |||
113 | RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT, | |||
114 | FN_TABLE_SET_VERT_ALIGN((20000 + 400) + 188), FN_TABLE_SET_VERT_ALIGN((20000 + 400) + 188), | |||
115 | RES_FRAMEDIR, RES_FRAMEDIR, | |||
116 | RES_ROW_SPLIT, RES_ROW_SPLIT, | |||
117 | FN_TABLE_BOX_TEXTORIENTATION((20000 + 400) + 192), FN_TABLE_BOX_TEXTORIENTATION((20000 + 400) + 192), | |||
118 | // #i29550# | |||
119 | RES_COLLAPSING_BORDERS, RES_COLLAPSING_BORDERS, | |||
120 | // <-- collapsing borders | |||
121 | 0 | |||
122 | }; | |||
123 | ||||
124 | const sal_uInt16* SwuiGetUITableAttrRange() | |||
125 | { | |||
126 | return aUITableAttrRange; | |||
127 | } | |||
128 | ||||
129 | static void lcl_SetAttr( SwWrtShell &rSh, const SfxPoolItem &rItem ) | |||
130 | { | |||
131 | SfxItemSet aSet( rSh.GetView().GetPool(), {{rItem.Which(), rItem.Which()}}); | |||
132 | aSet.Put( rItem ); | |||
133 | rSh.SetTableAttr( aSet ); | |||
134 | } | |||
135 | ||||
136 | static std::shared_ptr<SwTableRep> lcl_TableParamToItemSet( SfxItemSet& rSet, SwWrtShell &rSh ) | |||
137 | { | |||
138 | std::shared_ptr<SwTableRep> pRep; | |||
139 | ||||
140 | SwFrameFormat *pFormat = rSh.GetTableFormat(); | |||
141 | SwTabCols aCols; | |||
142 | rSh.GetTabCols( aCols ); | |||
143 | ||||
144 | //At first get the simple attributes. | |||
145 | rSet.Put( SfxStringItem( FN_PARAM_TABLE_NAME((20000 + 1100)+44), pFormat->GetName())); | |||
146 | rSet.Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE((20000 + 1100)+50), rSh.GetRowsToRepeat() ) ); | |||
147 | rSet.Put( pFormat->GetShadow() ); | |||
148 | rSet.Put(SfxUInt16Item(FN_TABLE_SET_VERT_ALIGN((20000 + 400) + 188), rSh.GetBoxAlign())); | |||
149 | rSet.Put( pFormat->GetFrameDir() ); | |||
150 | ||||
151 | SvxULSpaceItem aULSpace( pFormat->GetULSpace() ); | |||
152 | rSet.Put( aULSpace ); | |||
153 | ||||
154 | const sal_uInt16 nBackgroundDestination = rSh.GetViewOptions()->GetTableDest(); | |||
155 | rSet.Put(SfxUInt16Item(SID_BACKGRND_DESTINATION( 10000 + 404 ), nBackgroundDestination )); | |||
156 | std::unique_ptr<SvxBrushItem> aBrush(std::make_unique<SvxBrushItem>(RES_BACKGROUND)); | |||
157 | if(rSh.GetRowBackground(aBrush)) | |||
158 | { | |||
159 | aBrush->SetWhich(SID_ATTR_BRUSH_ROW( 10000 + 368 )); | |||
160 | rSet.Put( *aBrush ); | |||
161 | } | |||
162 | else | |||
163 | rSet.InvalidateItem(SID_ATTR_BRUSH_ROW( 10000 + 368 )); | |||
164 | rSh.GetTabBackground(aBrush); | |||
165 | aBrush->SetWhich(SID_ATTR_BRUSH_TABLE( 10000 + 453 )); | |||
166 | rSet.Put( *aBrush ); | |||
167 | ||||
168 | // text direction in boxes | |||
169 | std::unique_ptr<SvxFrameDirectionItem> aBoxDirection(std::make_unique<SvxFrameDirectionItem>(SvxFrameDirection::Environment, RES_FRAMEDIR)); | |||
170 | if(rSh.GetBoxDirection( aBoxDirection )) | |||
171 | { | |||
172 | aBoxDirection->SetWhich(FN_TABLE_BOX_TEXTORIENTATION((20000 + 400) + 192)); | |||
173 | rSet.Put(*aBoxDirection); | |||
174 | } | |||
175 | ||||
176 | bool bSelectAll = rSh.StartsWithTable() && rSh.ExtendedSelectedAll(); | |||
177 | bool bTableSel = rSh.IsTableMode() || bSelectAll; | |||
178 | if(!bTableSel) | |||
179 | { | |||
180 | rSh.StartAllAction(); | |||
181 | rSh.Push(); | |||
182 | rSh.GetView().GetViewFrame()->GetDispatcher()->Execute( FN_TABLE_SELECT_ALL((20000 + 400) + 115) ); | |||
183 | } | |||
184 | SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ) ); | |||
185 | ||||
186 | // Table variant: If multiple table cells are selected. | |||
187 | rSh.GetCursor(); //Thus GetCursorCnt() returns the right thing | |||
188 | aBoxInfo.SetTable ((rSh.IsTableMode() && rSh.GetCursorCnt() > 1) || | |||
189 | !bTableSel); | |||
190 | // Always show distance field. | |||
191 | aBoxInfo.SetDist (true); | |||
192 | // Set minimum size in tables and paragraphs. | |||
193 | aBoxInfo.SetMinDist( !bTableSel || rSh.IsTableMode() || | |||
194 | rSh.GetSelectionType() & | |||
195 | (SelectionType::Text | SelectionType::Table)); | |||
196 | // Always set the default spacing. | |||
197 | aBoxInfo.SetDefDist (MIN_BORDER_DIST28); | |||
198 | // Individual lines can have DontCare status only in tables. | |||
199 | aBoxInfo.SetValid( SvxBoxInfoItemValidFlags::DISABLE, !bTableSel || !rSh.IsTableMode() ); | |||
200 | ||||
201 | rSet.Put(aBoxInfo); | |||
202 | rSh.GetTabBorders( rSet ); | |||
203 | ||||
204 | //row split | |||
205 | std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit(); | |||
206 | if(pSplit) | |||
207 | rSet.Put(std::move(pSplit)); | |||
208 | ||||
209 | if(!bTableSel) | |||
210 | { | |||
211 | rSh.ClearMark(); | |||
212 | rSh.Pop(SwCursorShell::PopMode::DeleteCurrent); | |||
213 | rSh.EndAllAction(); | |||
214 | } | |||
215 | ||||
216 | SwTabCols aTabCols; | |||
217 | rSh.GetTabCols( aTabCols ); | |||
218 | ||||
219 | // Pointer will be deleted after the dialogue execution. | |||
220 | pRep = std::make_shared<SwTableRep>(aTabCols); | |||
221 | pRep->SetSpace(aCols.GetRightMax()); | |||
222 | ||||
223 | sal_uInt16 nPercent = 0; | |||
224 | auto nWidth = ::GetTableWidth(pFormat, aCols, &nPercent, &rSh ); | |||
225 | // The table width is wrong for relative values. | |||
226 | if (nPercent) | |||
227 | nWidth = pRep->GetSpace() * nPercent / 100; | |||
228 | const sal_uInt16 nAlign = pFormat->GetHoriOrient().GetHoriOrient(); | |||
229 | pRep->SetAlign(nAlign); | |||
230 | SvxLRSpaceItem aLRSpace( pFormat->GetLRSpace() ); | |||
231 | SwTwips nLeft = aLRSpace.GetLeft(); | |||
232 | SwTwips nRight = aLRSpace.GetRight(); | |||
233 | SwTwips nDiff = pRep->GetSpace() - nRight - nLeft - nWidth; | |||
234 | if(nAlign != text::HoriOrientation::FULL && std::abs(nDiff) > 2) | |||
235 | { | |||
236 | SwTwips nLR = pRep->GetSpace() - nWidth; | |||
237 | switch ( nAlign ) | |||
238 | { | |||
239 | case text::HoriOrientation::CENTER: | |||
240 | nLeft = nRight = nLR / 2; | |||
241 | break; | |||
242 | case text::HoriOrientation::LEFT: | |||
243 | nRight = nLR; | |||
244 | nLeft = 0; | |||
245 | break; | |||
246 | case text::HoriOrientation::RIGHT: | |||
247 | nLeft = nLR; | |||
248 | nRight = 0; | |||
249 | break; | |||
250 | case text::HoriOrientation::LEFT_AND_WIDTH: | |||
251 | nRight = nLR - nLeft; | |||
252 | break; | |||
253 | case text::HoriOrientation::NONE: | |||
254 | if(!nPercent) | |||
255 | nWidth = pRep->GetSpace() - nLeft - nRight; | |||
256 | break; | |||
257 | } | |||
258 | } | |||
259 | pRep->SetLeftSpace(nLeft); | |||
260 | pRep->SetRightSpace(nRight); | |||
261 | ||||
262 | pRep->SetWidth(nWidth); | |||
263 | pRep->SetWidthPercent(nPercent); | |||
264 | // Are individual rows / cells are selected, the column processing will be changed. | |||
265 | pRep->SetLineSelected(bTableSel && ! rSh.HasWholeTabSelection()); | |||
266 | rSet.Put(SwPtrItem(FN_TABLE_REP((20000 + 400) + 99), pRep.get())); | |||
267 | return pRep; | |||
268 | } | |||
269 | ||||
270 | void ItemSetToTableParam( const SfxItemSet& rSet, | |||
271 | SwWrtShell &rSh ) | |||
272 | { | |||
273 | rSh.StartAllAction(); | |||
274 | rSh.StartUndo( SwUndoId::TABLE_ATTR ); | |||
275 | const SfxPoolItem* pItem = nullptr; | |||
276 | ||||
277 | if(SfxItemState::SET == rSet.GetItemState(SID_BACKGRND_DESTINATION( 10000 + 404 ), false, &pItem)) | |||
278 | { | |||
279 | SwViewOption aUsrPref( *rSh.GetViewOptions() ); | |||
280 | aUsrPref.SetTableDest(static_cast<sal_uInt8>(static_cast<const SfxUInt16Item*>(pItem)->GetValue())); | |||
281 | SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule ::Writer)))->ApplyUsrPref(aUsrPref, &rSh.GetView()); | |||
282 | } | |||
283 | bool bBorder = ( SfxItemState::SET == rSet.GetItemState( RES_BOX ) || | |||
284 | SfxItemState::SET == rSet.GetItemState( SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ) ) ); | |||
285 | pItem = nullptr; | |||
286 | bool bBackground = SfxItemState::SET == rSet.GetItemState( RES_BACKGROUND, false, &pItem ); | |||
287 | const SfxPoolItem* pRowItem = nullptr, *pTableItem = nullptr; | |||
288 | bBackground |= SfxItemState::SET == rSet.GetItemState( SID_ATTR_BRUSH_ROW( 10000 + 368 ), false, &pRowItem ); | |||
289 | bBackground |= SfxItemState::SET == rSet.GetItemState( SID_ATTR_BRUSH_TABLE( 10000 + 453 ), false, &pTableItem ); | |||
290 | const SfxPoolItem* pSplit = nullptr; | |||
291 | bool bRowSplit = SfxItemState::SET == rSet.GetItemState( RES_ROW_SPLIT, false, &pSplit ); | |||
292 | const SfxPoolItem* pBoxDirection = nullptr; | |||
293 | bool bBoxDirection = SfxItemState::SET == rSet.GetItemState( FN_TABLE_BOX_TEXTORIENTATION((20000 + 400) + 192), false, &pBoxDirection ); | |||
294 | if( bBackground || bBorder || bRowSplit || bBoxDirection) | |||
295 | { | |||
296 | // The border will be applied to the present selection. | |||
297 | // If there is no selection, the table will be completely selected. | |||
298 | // The background will always be applied to the current state. | |||
299 | bool bTableSel = rSh.IsTableMode(); | |||
300 | rSh.StartAllAction(); | |||
301 | ||||
302 | if(bBackground) | |||
303 | { | |||
304 | if(pItem) | |||
305 | rSh.SetBoxBackground( *static_cast<const SvxBrushItem*>(pItem) ); | |||
306 | if(pRowItem) | |||
307 | { | |||
308 | std::unique_ptr<SvxBrushItem> aBrush(static_cast<SvxBrushItem*>(pRowItem->Clone())); | |||
309 | aBrush->SetWhich(RES_BACKGROUND); | |||
310 | rSh.SetRowBackground(*aBrush); | |||
311 | } | |||
312 | if(pTableItem) | |||
313 | { | |||
314 | std::unique_ptr<SvxBrushItem> aBrush(static_cast<SvxBrushItem*>(pTableItem->Clone())); | |||
315 | aBrush->SetWhich(RES_BACKGROUND); | |||
316 | rSh.SetTabBackground( *aBrush ); | |||
317 | } | |||
318 | } | |||
319 | ||||
320 | if(bBoxDirection) | |||
321 | { | |||
322 | SvxFrameDirectionItem aDirection( SvxFrameDirection::Environment, RES_FRAMEDIR ); | |||
323 | aDirection.SetValue(static_cast< const SvxFrameDirectionItem* >(pBoxDirection)->GetValue()); | |||
324 | rSh.SetBoxDirection(aDirection); | |||
325 | } | |||
326 | ||||
327 | if(bBorder || bRowSplit) | |||
328 | { | |||
329 | rSh.Push(); | |||
330 | if(!bTableSel) | |||
331 | { | |||
332 | rSh.GetView().GetViewFrame()->GetDispatcher()->Execute( FN_TABLE_SELECT_ALL((20000 + 400) + 115) ); | |||
333 | } | |||
334 | if(bBorder) | |||
335 | rSh.SetTabBorders( rSet ); | |||
336 | ||||
337 | if(bRowSplit) | |||
338 | { | |||
339 | rSh.SetRowSplit(*static_cast<const SwFormatRowSplit*>(pSplit)); | |||
340 | } | |||
341 | ||||
342 | if(!bTableSel) | |||
343 | { | |||
344 | rSh.ClearMark(); | |||
345 | } | |||
346 | rSh.Pop(SwCursorShell::PopMode::DeleteCurrent); | |||
347 | } | |||
348 | ||||
349 | rSh.EndAllAction(); | |||
350 | } | |||
351 | ||||
352 | SwTabCols aTabCols; | |||
353 | bool bTabCols = false; | |||
354 | SwTableRep* pRep = nullptr; | |||
355 | SwFrameFormat *pFormat = rSh.GetTableFormat(); | |||
356 | SfxItemSet aSet( rSh.GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END-1>{} ); | |||
357 | if(SfxItemState::SET == rSet.GetItemState( FN_TABLE_REP((20000 + 400) + 99), false, &pItem )) | |||
358 | { | |||
359 | pRep = static_cast<SwTableRep*>(static_cast<const SwPtrItem*>(pItem)->GetValue()); | |||
360 | ||||
361 | const SwTwips nWidth = pRep->GetWidth(); | |||
362 | if ( text::HoriOrientation::FULL == pRep->GetAlign() ) | |||
363 | { | |||
364 | SwFormatHoriOrient aAttr( pFormat->GetHoriOrient() ); | |||
365 | aAttr.SetHoriOrient( text::HoriOrientation::FULL ); | |||
366 | aSet.Put( aAttr ); | |||
367 | } | |||
368 | else | |||
369 | { | |||
370 | SwFormatFrameSize aSz( SwFrameSize::Variable, nWidth ); | |||
371 | if(pRep->GetWidthPercent()) | |||
372 | { | |||
373 | aSz.SetWidthPercent( static_cast<sal_uInt8>(pRep->GetWidthPercent()) ); | |||
374 | } | |||
375 | aSet.Put(aSz); | |||
376 | } | |||
377 | ||||
378 | SvxLRSpaceItem aLRSpace( RES_LR_SPACE ); | |||
379 | aLRSpace.SetLeft(pRep->GetLeftSpace()); | |||
380 | aLRSpace.SetRight(pRep->GetRightSpace()); | |||
381 | aSet.Put( aLRSpace ); | |||
382 | ||||
383 | sal_Int16 eOrient = pRep->GetAlign(); | |||
384 | SwFormatHoriOrient aAttr( 0, eOrient ); | |||
385 | aSet.Put( aAttr ); | |||
386 | // The item must only be recorded while manual alignment, so that the | |||
387 | // alignment is not overwritten by the distances while recording. | |||
388 | if(eOrient != text::HoriOrientation::NONE) | |||
389 | const_cast<SfxItemSet&>(rSet).ClearItem( SID_ATTR_LRSPACE( 10000 + 48 ) ); | |||
390 | ||||
391 | if(pRep->HasColsChanged()) | |||
392 | { | |||
393 | bTabCols = true; | |||
394 | } | |||
395 | } | |||
396 | ||||
397 | if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_TABLE_HEADLINE((20000 + 1100)+50), false, &pItem)) | |||
398 | rSh.SetRowsToRepeat( static_cast<const SfxUInt16Item*>(pItem)->GetValue() ); | |||
399 | ||||
400 | if( SfxItemState::SET == rSet.GetItemState( FN_TABLE_SET_VERT_ALIGN((20000 + 400) + 188), false, &pItem)) | |||
401 | rSh.SetBoxAlign(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); | |||
402 | ||||
403 | if( SfxItemState::SET == rSet.GetItemState( FN_PARAM_TABLE_NAME((20000 + 1100)+44), false, &pItem )) | |||
404 | rSh.SetTableName( *pFormat, static_cast<const SfxStringItem*>(pItem)->GetValue() ); | |||
405 | ||||
406 | // Copy the chosen attributes in the ItemSet. | |||
407 | static const sal_uInt16 aIds[] = | |||
408 | { | |||
409 | RES_PAGEDESC, | |||
410 | RES_BREAK, | |||
411 | RES_KEEP, | |||
412 | RES_LAYOUT_SPLIT, | |||
413 | RES_UL_SPACE, | |||
414 | RES_SHADOW, | |||
415 | RES_FRAMEDIR, | |||
416 | // #i29550# | |||
417 | RES_COLLAPSING_BORDERS, | |||
418 | // <-- collapsing borders | |||
419 | 0 | |||
420 | }; | |||
421 | for( const sal_uInt16* pIds = aIds; *pIds; ++pIds ) | |||
422 | if( SfxItemState::SET == rSet.GetItemState( *pIds, false, &pItem)) | |||
423 | aSet.Put( *pItem ); | |||
424 | ||||
425 | if(bTabCols) | |||
426 | { | |||
427 | rSh.GetTabCols( aTabCols ); | |||
428 | bool bSingleLine = pRep->FillTabCols( aTabCols ); | |||
429 | rSh.SetTabCols( aTabCols, bSingleLine ); | |||
430 | } | |||
431 | ||||
432 | if( aSet.Count() ) | |||
433 | rSh.SetTableAttr( aSet ); | |||
434 | ||||
435 | rSh.EndUndo( SwUndoId::TABLE_ATTR ); | |||
436 | rSh.EndAllAction(); | |||
437 | } | |||
438 | ||||
439 | static void lcl_TabGetMaxLineWidth(const SvxBorderLine* pBorderLine, SvxBorderLine& rBorderLine) | |||
440 | { | |||
441 | if(pBorderLine->GetWidth() > rBorderLine.GetWidth()) | |||
442 | rBorderLine.SetWidth(pBorderLine->GetWidth()); | |||
443 | ||||
444 | rBorderLine.SetBorderLineStyle(pBorderLine->GetBorderLineStyle()); | |||
445 | rBorderLine.SetColor(pBorderLine->GetColor()); | |||
446 | } | |||
447 | ||||
448 | void SwTableShell::Execute(SfxRequest &rReq) | |||
449 | { | |||
450 | const SfxItemSet* pArgs = rReq.GetArgs(); | |||
451 | SwWrtShell &rSh = GetShell(); | |||
452 | ||||
453 | // At first the slots which doesn't need a FrameMgr. | |||
454 | bool bMore = false; | |||
455 | const SfxPoolItem* pItem = nullptr; | |||
456 | sal_uInt16 nSlot = rReq.GetSlot(); | |||
457 | if(pArgs) | |||
| ||||
458 | pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem); | |||
459 | bool bCallDone = false; | |||
460 | switch ( nSlot ) | |||
461 | { | |||
462 | case SID_ATTR_BORDER( 10000 + 188 ): | |||
463 | { | |||
464 | if(!pArgs) | |||
465 | break; | |||
466 | // Create items, because we have to rework anyway. | |||
467 | std::shared_ptr<SvxBoxItem> aBox(std::make_shared<SvxBoxItem>(RES_BOX)); | |||
468 | SfxItemSet aCoreSet( GetPool(), | |||
469 | svl::Items<RES_BOX, RES_BOX, | |||
470 | SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 )>{}); | |||
471 | SvxBoxInfoItem aCoreInfo( SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ) ); | |||
472 | aCoreSet.Put(aCoreInfo); | |||
473 | rSh.GetTabBorders( aCoreSet ); | |||
474 | const SvxBoxItem& rCoreBox = aCoreSet.Get(RES_BOX); | |||
475 | const SfxPoolItem *pBoxItem = nullptr; | |||
476 | if ( pArgs->GetItemState(RES_BOX, true, &pBoxItem) == SfxItemState::SET ) | |||
477 | { | |||
478 | aBox.reset(static_cast<SvxBoxItem*>(pBoxItem->Clone())); | |||
479 | sal_uInt16 nDefValue = MIN_BORDER_DIST28; | |||
480 | if ( !rReq.IsAPI() ) | |||
481 | nDefValue = 55; | |||
482 | if (!rReq.IsAPI() || aBox->GetSmallestDistance() < MIN_BORDER_DIST28) | |||
483 | { | |||
484 | for( SvxBoxItemLine k : o3tl::enumrange<SvxBoxItemLine>() ) | |||
485 | aBox->SetDistance( std::max(rCoreBox.GetDistance(k), nDefValue) , k ); | |||
486 | } | |||
487 | } | |||
488 | else | |||
489 | OSL_ENSURE( false, "where is BoxItem?" )do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/tabsh.cxx" ":" "489" ": "), "%s", "where is BoxItem?"); } } while (false ); | |||
490 | ||||
491 | //since the drawing layer also supports borders the which id might be a different one | |||
492 | std::shared_ptr<SvxBoxInfoItem> aInfo(std::make_shared<SvxBoxInfoItem>(SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ))); | |||
493 | if (pArgs->GetItemState(SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), true, &pBoxItem) == SfxItemState::SET) | |||
494 | { | |||
495 | aInfo.reset(static_cast<SvxBoxInfoItem*>(pBoxItem->Clone())); | |||
496 | } | |||
497 | else if( pArgs->GetItemState(SDRATTR_TABLE_BORDER_INNER, true, &pBoxItem) == SfxItemState::SET ) | |||
498 | { | |||
499 | aInfo.reset(static_cast<SvxBoxInfoItem*>(pBoxItem->Clone())); | |||
500 | aInfo->SetWhich(SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 )); | |||
501 | } | |||
502 | ||||
503 | aInfo->SetTable( true ); | |||
504 | aInfo->SetValid( SvxBoxInfoItemValidFlags::DISABLE, false ); | |||
505 | ||||
506 | // The attributes of all lines will be read and the strongest wins. | |||
507 | const SvxBorderLine* pBorderLine; | |||
508 | SvxBorderLine aBorderLine; | |||
509 | if ((pBorderLine = rCoreBox.GetTop()) != nullptr) | |||
510 | lcl_TabGetMaxLineWidth(pBorderLine, aBorderLine); | |||
511 | if ((pBorderLine = rCoreBox.GetBottom()) != nullptr) | |||
512 | lcl_TabGetMaxLineWidth(pBorderLine, aBorderLine); | |||
513 | if ((pBorderLine = rCoreBox.GetLeft()) != nullptr) | |||
514 | lcl_TabGetMaxLineWidth(pBorderLine, aBorderLine); | |||
515 | if ((pBorderLine = rCoreBox.GetRight()) != nullptr) | |||
516 | lcl_TabGetMaxLineWidth(pBorderLine, aBorderLine); | |||
517 | if ((pBorderLine = aCoreInfo.GetHori()) != nullptr) | |||
518 | lcl_TabGetMaxLineWidth(pBorderLine, aBorderLine); | |||
519 | if ((pBorderLine = aCoreInfo.GetVert()) != nullptr) | |||
520 | lcl_TabGetMaxLineWidth(pBorderLine, aBorderLine); | |||
521 | ||||
522 | if(aBorderLine.GetOutWidth() == 0) | |||
523 | { | |||
524 | aBorderLine.SetBorderLineStyle(SvxBorderLineStyle::SOLID); | |||
525 | aBorderLine.SetWidth( DEF_LINE_WIDTH_510 ); | |||
526 | } | |||
527 | ||||
528 | if( aBox->GetTop() != nullptr ) | |||
529 | { | |||
530 | aBox->SetLine(&aBorderLine, SvxBoxItemLine::TOP); | |||
531 | } | |||
532 | if( aBox->GetBottom() != nullptr ) | |||
533 | { | |||
534 | aBox->SetLine(&aBorderLine, SvxBoxItemLine::BOTTOM); | |||
535 | } | |||
536 | if( aBox->GetLeft() != nullptr ) | |||
537 | { | |||
538 | aBox->SetLine(&aBorderLine, SvxBoxItemLine::LEFT); | |||
539 | } | |||
540 | if( aBox->GetRight() != nullptr ) | |||
541 | { | |||
542 | aBox->SetLine(&aBorderLine, SvxBoxItemLine::RIGHT); | |||
543 | } | |||
544 | if( aInfo->GetHori() != nullptr ) | |||
545 | { | |||
546 | aInfo->SetLine(&aBorderLine, SvxBoxInfoItemLine::HORI); | |||
547 | } | |||
548 | if( aInfo->GetVert() != nullptr ) | |||
549 | { | |||
550 | aInfo->SetLine(&aBorderLine, SvxBoxInfoItemLine::VERT); | |||
551 | } | |||
552 | ||||
553 | aCoreSet.Put( *aBox ); | |||
554 | aCoreSet.Put( *aInfo ); | |||
555 | rSh.SetTabBorders( aCoreSet ); | |||
556 | ||||
557 | // we must record the "real" values because otherwise the lines can't be reconstructed on playtime | |||
558 | // the coding style of the controller (setting lines with width 0) is not transportable via Query/PutValue in | |||
559 | // the SvxBoxItem | |||
560 | rReq.AppendItem( *aBox ); | |||
561 | rReq.AppendItem( *aInfo ); | |||
562 | bCallDone = true; | |||
563 | break; | |||
564 | } | |||
565 | case FN_INSERT_TABLE((20000 + 300) + 30): | |||
566 | InsertTable( rReq ); | |||
567 | break; | |||
568 | case FN_FORMAT_TABLE_DLG((20000 + 400) + 60): | |||
569 | { | |||
570 | //#127012# get the bindings before the dialog is called | |||
571 | // it might happen that this shell is removed after closing the dialog | |||
572 | SfxBindings& rBindings = GetView().GetViewFrame()->GetBindings(); | |||
573 | SfxItemSet aCoreSet( GetPool(), aUITableAttrRange); | |||
574 | ||||
575 | FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( &rSh.GetView()) != nullptr ); | |||
576 | 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))); | |||
577 | std::shared_ptr<SwTableRep> pTableRep(::lcl_TableParamToItemSet(aCoreSet, rSh)); | |||
578 | ||||
579 | aCoreSet.Put(SfxUInt16Item(SID_HTML_MODE(10000 + 414), ::GetHtmlMode(GetView().GetDocShell()))); | |||
580 | rSh.GetTableAttr(aCoreSet); | |||
581 | // GetTableAttr overwrites the background! | |||
582 | std::unique_ptr<SvxBrushItem> aBrush(std::make_unique<SvxBrushItem>(RES_BACKGROUND)); | |||
583 | if(rSh.GetBoxBackground(aBrush)) | |||
584 | aCoreSet.Put( *aBrush ); | |||
585 | else | |||
586 | aCoreSet.InvalidateItem( RES_BACKGROUND ); | |||
587 | ||||
588 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
589 | VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSwTableTabDlg(GetView().GetFrameWeld(), &aCoreSet, &rSh)); | |||
590 | ||||
591 | if (pDlg) | |||
592 | { | |||
593 | if (pItem) | |||
594 | pDlg->SetCurPageId(OUStringToOString(static_cast<const SfxStringItem *>(pItem)->GetValue(), RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)))); | |||
595 | ||||
596 | auto pRequest = std::make_shared<SfxRequest>(rReq); | |||
597 | rReq.Ignore(); // the 'old' request is not relevant any more | |||
598 | ||||
599 | auto xPaM(std::make_shared<SwPaM>(*rSh.GetCursor(), nullptr)); // tdf#135636 make a copy to use at later apply | |||
600 | pDlg->StartExecuteAsync([pDlg, pRequest, pTableRep, &rBindings, &rSh, xPaM](sal_Int32 nResult){ | |||
601 | if (RET_OK == nResult) | |||
602 | { | |||
603 | rSh.SetSelection(*xPaM); // tdf#135636 set the table selected at dialog launch as current selection | |||
604 | ||||
605 | const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); | |||
606 | ||||
607 | //to record FN_INSERT_TABLE correctly | |||
608 | pRequest->SetSlot(FN_FORMAT_TABLE_DLG((20000 + 400) + 60)); | |||
609 | pRequest->Done(*pOutSet); | |||
610 | ||||
611 | ItemSetToTableParam(*pOutSet, rSh); | |||
612 | } | |||
613 | ||||
614 | rBindings.Update(SID_RULER_BORDERSTypedWhichId<SvxRulerItem>( 10000 + 80 )); | |||
615 | rBindings.Update(SID_ATTR_TABSTOP( 10000 + 2 )); | |||
616 | rBindings.Update(SID_RULER_BORDERS_VERTICAL( 10000 + 948 )); | |||
617 | rBindings.Update(SID_ATTR_TABSTOP_VERTICAL( 10000 + 946 )); | |||
618 | ||||
619 | pDlg->disposeOnce(); | |||
620 | }); | |||
621 | } | |||
622 | else | |||
623 | { | |||
624 | if (rReq.GetArgs()) | |||
625 | ItemSetToTableParam(*rReq.GetArgs(), rSh); | |||
626 | ||||
627 | rBindings.Update(SID_RULER_BORDERSTypedWhichId<SvxRulerItem>( 10000 + 80 )); | |||
628 | rBindings.Update(SID_ATTR_TABSTOP( 10000 + 2 )); | |||
629 | rBindings.Update(SID_RULER_BORDERS_VERTICAL( 10000 + 948 )); | |||
630 | rBindings.Update(SID_ATTR_TABSTOP_VERTICAL( 10000 + 946 )); | |||
631 | } | |||
632 | ||||
633 | break; | |||
634 | } | |||
635 | case SID_ATTR_BRUSH( 10000 + 1 ): | |||
636 | case SID_ATTR_BRUSH_ROW( 10000 + 368 ) : | |||
637 | case SID_ATTR_BRUSH_TABLE( 10000 + 453 ) : | |||
638 | if(rReq.GetArgs()) | |||
639 | ItemSetToTableParam(*rReq.GetArgs(), rSh); | |||
640 | break; | |||
641 | case FN_NUM_FORMAT_TABLE_DLG((20000 + 400) + 45): | |||
642 | { | |||
643 | SwView* pView = GetActiveView(); | |||
644 | if(pView) | |||
645 | { | |||
646 | FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( pView) != nullptr ); | |||
647 | 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))); | |||
648 | SvNumberFormatter* pFormatter = rSh.GetNumberFormatter(); | |||
649 | SfxItemSet aCoreSet( | |||
650 | GetPool(), | |||
651 | svl::Items< | |||
652 | SID_ATTR_NUMBERFORMAT_VALUETypedWhichId<SfxUInt32Item>( 10000 + 85 ), | |||
653 | SID_ATTR_NUMBERFORMAT_INFOTypedWhichId<SvxNumberInfoItem>( 10000 + 86 )>{}); | |||
654 | ||||
655 | SfxItemSet aBoxSet( *aCoreSet.GetPool(), | |||
656 | svl::Items<RES_BOXATR_FORMAT, RES_BOXATR_FORMAT, | |||
657 | RES_BOXATR_VALUE, RES_BOXATR_VALUE>{} ); | |||
658 | rSh.GetTableBoxFormulaAttrs( aBoxSet ); | |||
659 | ||||
660 | SfxItemState eState = aBoxSet.GetItemState(RES_BOXATR_FORMAT); | |||
661 | if(eState == SfxItemState::DEFAULT) | |||
662 | { | |||
663 | aCoreSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUETypedWhichId<SfxUInt32Item>( 10000 + 85 ), | |||
664 | pFormatter->GetFormatIndex(NF_TEXT, LANGUAGE_SYSTEMLanguageType(0x0000)))); | |||
665 | } | |||
666 | else | |||
667 | aCoreSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUETypedWhichId<SfxUInt32Item>( 10000 + 85 ), | |||
668 | aBoxSet.Get( | |||
669 | RES_BOXATR_FORMAT ).GetValue() )); | |||
670 | ||||
671 | OUString sCurText( rSh.GetTableBoxText() ); | |||
672 | aCoreSet.Put( SvxNumberInfoItem( pFormatter, | |||
673 | aBoxSet.Get( | |||
674 | RES_BOXATR_VALUE).GetValue(), | |||
675 | sCurText, SID_ATTR_NUMBERFORMAT_INFOTypedWhichId<SvxNumberInfoItem>( 10000 + 86 ) )); | |||
676 | ||||
677 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
678 | ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateNumFormatDialog(GetView().GetFrameWeld(), aCoreSet)); | |||
679 | ||||
680 | if (RET_OK == pDlg->Execute()) | |||
681 | { | |||
682 | const SvxNumberInfoItem* pNumberFormatItem | |||
683 | = GetView().GetDocShell()->GetItem( SID_ATTR_NUMBERFORMAT_INFOTypedWhichId<SvxNumberInfoItem>( 10000 + 86 ) ); | |||
684 | ||||
685 | if( pNumberFormatItem ) | |||
686 | { | |||
687 | for ( sal_uInt32 key : pNumberFormatItem->GetDelFormats() ) | |||
688 | pNumberFormatItem->GetNumberFormatter()->DeleteEntry( key ); | |||
689 | } | |||
690 | ||||
691 | const SfxPoolItem* pNumberFormatValueItem = nullptr; | |||
692 | if( SfxItemState::SET == pDlg->GetOutputItemSet()->GetItemState( | |||
693 | SID_ATTR_NUMBERFORMAT_VALUETypedWhichId<SfxUInt32Item>( 10000 + 85 ), false, &pNumberFormatValueItem )) | |||
694 | { | |||
695 | SfxItemSet aBoxFormatSet( *aCoreSet.GetPool(), | |||
696 | svl::Items<RES_BOXATR_FORMAT, RES_BOXATR_FORMAT>{} ); | |||
697 | aBoxFormatSet.Put( SwTableBoxNumFormat( | |||
698 | static_cast<const SfxUInt32Item*>(pNumberFormatValueItem)->GetValue() )); | |||
699 | rSh.SetTableBoxFormulaAttrs( aBoxFormatSet ); | |||
700 | ||||
701 | } | |||
702 | } | |||
703 | } | |||
704 | break; | |||
705 | } | |||
706 | case FN_CALC_TABLE((20000 + 100) + 29): | |||
707 | rSh.UpdateTable(); | |||
708 | bCallDone = true; | |||
709 | break; | |||
710 | case FN_TABLE_DELETE_COL((20000 + 400) + 104): | |||
711 | if ( rSh.DeleteCol() && rSh.HasSelection() ) | |||
712 | rSh.EnterStdMode(); | |||
713 | bCallDone = true; | |||
714 | break; | |||
715 | case FN_END_TABLE((20000 + 900) + 48): | |||
716 | rSh.MoveTable( GotoCurrTable, fnTableEnd ); | |||
717 | bCallDone = true; | |||
718 | break; | |||
719 | case FN_START_TABLE((20000 + 900) + 47): | |||
720 | rSh.MoveTable( GotoCurrTable, fnTableStart ); | |||
721 | bCallDone = true; | |||
722 | break; | |||
723 | case FN_GOTO_NEXT_CELL((20000 + 400) + 145): | |||
724 | { | |||
725 | bool bAppendLine = true; | |||
726 | if( pItem ) | |||
727 | bAppendLine = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
728 | rReq.SetReturnValue( SfxBoolItem( nSlot, | |||
729 | rSh.GoNextCell( bAppendLine ) ) ); | |||
730 | bCallDone = true; | |||
731 | break; | |||
732 | } | |||
733 | case FN_GOTO_PREV_CELL((20000 + 400) + 146): | |||
734 | rReq.SetReturnValue( SfxBoolItem( nSlot, rSh.GoPrevCell() ) ); | |||
735 | bCallDone = true; | |||
736 | break; | |||
737 | case FN_TABLE_DELETE_ROW((20000 + 400) + 103): | |||
738 | if ( rSh.DeleteRow() && rSh.HasSelection() ) | |||
739 | rSh.EnterStdMode(); | |||
740 | bCallDone = true; | |||
741 | break; | |||
742 | case FN_TABLE_MERGE_CELLS((20000 + 400) + 106): | |||
743 | if ( rSh.IsTableMode() ) | |||
744 | switch ( rSh.MergeTab() ) | |||
745 | { | |||
746 | case TableMergeErr::Ok: | |||
747 | bCallDone = true; | |||
748 | [[fallthrough]]; | |||
749 | case TableMergeErr::NoSelection: | |||
750 | break; | |||
751 | case TableMergeErr::TooComplex: | |||
752 | { | |||
753 | std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetView().GetFrameWeld(), | |||
754 | VclMessageType::Info, VclButtonsType::Ok, | |||
755 | SwResId(STR_ERR_TABLE_MERGEreinterpret_cast<char const *>("STR_ERR_TABLE_MERGE" "\004" u8"Selected table cells are too complex to merge.")))); | |||
756 | xInfoBox->run(); | |||
757 | break; | |||
758 | } | |||
759 | default: | |||
760 | OSL_ENSURE( false, "unknown return value MergeTab.")do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/tabsh.cxx" ":" "760" ": "), "%s", "unknown return value MergeTab."); } } while (false); | |||
761 | break; | |||
762 | } | |||
763 | break; | |||
764 | case SID_TABLE_MINIMAL_COLUMN_WIDTH( 10000 + 1185 ): | |||
765 | case FN_TABLE_ADJUST_CELLS((20000 + 400) + 121): | |||
766 | case FN_TABLE_BALANCE_CELLS((20000 + 400) + 182): | |||
767 | { | |||
768 | bool bBalance = (FN_TABLE_BALANCE_CELLS((20000 + 400) + 182) == nSlot); | |||
769 | const bool bNoShrink = FN_TABLE_ADJUST_CELLS((20000 + 400) + 121) == nSlot; | |||
770 | if ( rSh.IsAdjustCellWidthAllowed(bBalance) ) | |||
771 | { | |||
772 | { | |||
773 | // remove actions to make a valid table selection | |||
774 | UnoActionRemoveContext aRemoveContext(rSh.GetDoc()); | |||
775 | } | |||
776 | rSh.AdjustCellWidth(bBalance, bNoShrink); | |||
777 | } | |||
778 | bCallDone = true; | |||
779 | break; | |||
780 | } | |||
781 | case SID_TABLE_MINIMAL_ROW_HEIGHT( 10000 + 1186 ): | |||
782 | { | |||
783 | const SwFormatFrameSize aSz; | |||
784 | rSh.SetRowHeight( aSz ); | |||
785 | bCallDone = true; | |||
786 | break; | |||
787 | } | |||
788 | case FN_TABLE_OPTIMAL_HEIGHT((20000 + 400) + 128): | |||
789 | { | |||
790 | rSh.BalanceRowHeight(/*bTstOnly=*/false, /*bOptimize=*/true); | |||
791 | rSh.BalanceRowHeight(/*bTstOnly=*/false, /*bOptimize=*/false); | |||
792 | bCallDone = true; | |||
793 | break; | |||
794 | } | |||
795 | case FN_TABLE_BALANCE_ROWS((20000 + 400) + 183): | |||
796 | if ( rSh.BalanceRowHeight(true) ) | |||
797 | rSh.BalanceRowHeight(false); | |||
798 | bCallDone = true; | |||
799 | break; | |||
800 | case FN_TABLE_SELECT_ALL((20000 + 400) + 115): | |||
801 | rSh.EnterStdMode(); | |||
802 | rSh.MoveTable( GotoCurrTable, fnTableStart ); | |||
803 | rSh.SttSelect(); | |||
804 | rSh.MoveTable( GotoCurrTable, fnTableEnd ); | |||
805 | rSh.EndSelect(); | |||
806 | bCallDone = true; | |||
807 | break; | |||
808 | case FN_TABLE_SELECT_COL((20000 + 400) + 114): | |||
809 | rSh.EnterStdMode(); | |||
810 | rSh.SelectTableCol(); | |||
811 | bCallDone = true; | |||
812 | break; | |||
813 | case FN_TABLE_SELECT_ROW((20000 + 400) + 113): | |||
814 | rSh.EnterStdMode(); | |||
815 | rSh.SelectTableRow(); | |||
816 | bCallDone = true; | |||
817 | break; | |||
818 | case FN_TABLE_SET_READ_ONLY_CELLS((20000 + 400) + 117): | |||
819 | rSh.ProtectCells(); | |||
820 | rSh.ResetSelect( nullptr, false ); | |||
821 | bCallDone = true; | |||
822 | break; | |||
823 | case FN_TABLE_UNSET_READ_ONLY_CELLS((20000 + 400) + 119): | |||
824 | rSh.UnProtectCells(); | |||
825 | bCallDone = true; | |||
826 | break; | |||
827 | case SID_AUTOFORMATTypedWhichId<SfxStringItem>( 10000 + 242 ): | |||
828 | { | |||
829 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
830 | ScopedVclPtr<AbstractSwAutoFormatDlg> pDlg(pFact->CreateSwAutoFormatDlg(GetView().GetFrameWeld(), &rSh)); | |||
831 | pDlg->Execute(); | |||
832 | break; | |||
833 | } | |||
834 | case FN_TABLE_SET_ROW_HEIGHT((20000 + 400) + 107): | |||
835 | { | |||
836 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
837 | ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwTableHeightDialog(GetView().GetFrameWeld(), rSh)); | |||
838 | pDlg->Execute(); | |||
839 | break; | |||
840 | } | |||
841 | case FN_NUMBER_BULLETS((20000 + 100) + 21): | |||
842 | case FN_NUM_BULLET_ON((20000 + 100) + 38): | |||
843 | OSL_ENSURE( false, "function may not be called now." )do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/tabsh.cxx" ":" "843" ": "), "%s", "function may not be called now."); } } while (false); | |||
844 | break; | |||
845 | ||||
846 | ||||
847 | // 2015/06 The following two are deprecated but kept for ascending | |||
848 | // compatibility | |||
849 | case FN_TABLE_INSERT_COL((20000 + 400) + 102): | |||
850 | case FN_TABLE_INSERT_ROW((20000 + 400) + 101): | |||
851 | // fallback | |||
852 | case FN_TABLE_INSERT_COL_BEFORE((20000 + 400) + 112): | |||
853 | case FN_TABLE_INSERT_ROW_BEFORE((20000 + 400) + 111): | |||
854 | case FN_TABLE_INSERT_COL_AFTER((20000 + 400) + 116): | |||
855 | case FN_TABLE_INSERT_ROW_AFTER((20000 + 400) + 109): | |||
856 | { | |||
857 | bool bColumn = rReq.GetSlot() == FN_TABLE_INSERT_COL_BEFORE((20000 + 400) + 112) | |||
858 | || rReq.GetSlot() == FN_TABLE_INSERT_COL_AFTER((20000 + 400) + 116) | |||
859 | || rReq.GetSlot() == FN_TABLE_INSERT_COL((20000 + 400) + 102); | |||
860 | sal_uInt16 nCount = 0; | |||
861 | bool bAfter = true; | |||
862 | if (pItem) | |||
863 | { | |||
864 | nCount = static_cast<const SfxInt16Item* >(pItem)->GetValue(); | |||
865 | if(SfxItemState::SET == pArgs->GetItemState(FN_PARAM_INSERT_AFTER((20000 + 1100)+29), true, &pItem)) | |||
866 | bAfter = static_cast<const SfxBoolItem* >(pItem)->GetValue(); | |||
867 | } | |||
868 | else if( !rReq.IsAPI() ) | |||
869 | { | |||
870 | SwSelBoxes aBoxes; | |||
871 | ::GetTableSel( rSh, aBoxes ); | |||
872 | if ( !aBoxes.empty() ) | |||
873 | { | |||
874 | long maxX = 0; | |||
875 | long maxY = 0; | |||
876 | long minX = std::numeric_limits<long>::max(); | |||
877 | long minY = std::numeric_limits<long>::max(); | |||
878 | long nbBoxes = aBoxes.size(); | |||
879 | for ( long i = 0; i < nbBoxes; i++ ) | |||
880 | { | |||
881 | Point aCoord ( aBoxes[i]->GetCoordinates() ); | |||
882 | if ( aCoord.X() < minX ) minX = aCoord.X(); | |||
883 | if ( aCoord.X() > maxX ) maxX = aCoord.X(); | |||
884 | if ( aCoord.Y() < minY ) minY = aCoord.Y(); | |||
885 | if ( aCoord.Y() > maxY ) maxY = aCoord.Y(); | |||
886 | } | |||
887 | if (bColumn) | |||
888 | nCount = maxX - minX + 1; | |||
889 | else | |||
890 | nCount = maxY - minY + 1; | |||
891 | } | |||
892 | bAfter = rReq.GetSlot() == FN_TABLE_INSERT_COL_AFTER((20000 + 400) + 116) | |||
893 | || rReq.GetSlot() == FN_TABLE_INSERT_ROW_AFTER((20000 + 400) + 109) | |||
894 | || rReq.GetSlot() == FN_TABLE_INSERT_ROW((20000 + 400) + 101) | |||
895 | || rReq.GetSlot() == FN_TABLE_INSERT_COL((20000 + 400) + 102); | |||
896 | } | |||
897 | ||||
898 | if( nCount ) | |||
899 | { | |||
900 | // i74180: Table border patch submitted by chensuchun: | |||
901 | // -->get the SvxBoxInfoItem of the table before insert | |||
902 | SfxItemSet aCoreSet( GetPool(), aUITableAttrRange); | |||
903 | ::lcl_TableParamToItemSet( aCoreSet, rSh ); | |||
904 | bool bSetInnerBorders = false; | |||
905 | SwUndoId nUndoId = SwUndoId::EMPTY; | |||
906 | // <--End | |||
907 | ||||
908 | if( bColumn ) | |||
909 | { | |||
910 | rSh.StartUndo( SwUndoId::TABLE_INSCOL ); | |||
911 | rSh.InsertCol( nCount, bAfter ); | |||
912 | bSetInnerBorders = true; | |||
913 | nUndoId = SwUndoId::TABLE_INSCOL; | |||
914 | } | |||
915 | else if ( !rSh.IsInRepeatedHeadline() ) | |||
916 | { | |||
917 | rSh.StartUndo( SwUndoId::TABLE_INSROW ); | |||
918 | rSh.InsertRow( nCount, bAfter ); | |||
919 | bSetInnerBorders = true; | |||
920 | nUndoId = SwUndoId::TABLE_INSROW; | |||
921 | } | |||
922 | ||||
923 | // -->after inserting,reset the inner table borders | |||
924 | if ( bSetInnerBorders ) | |||
925 | { | |||
926 | const SvxBoxInfoItem& aBoxInfo(aCoreSet.Get(SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ))); | |||
927 | SfxItemSet aSet( GetPool(), svl::Items<SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), | |||
928 | SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 )>{}); | |||
929 | aSet.Put( aBoxInfo ); | |||
930 | ItemSetToTableParam( aSet, rSh ); | |||
931 | rSh.EndUndo( nUndoId ); | |||
932 | } | |||
933 | ||||
934 | bCallDone = true; | |||
935 | break; | |||
936 | } | |||
937 | ||||
938 | nSlot = bColumn ? FN_TABLE_INSERT_COL_DLG((20000 + 400) + 142) : FN_TABLE_INSERT_ROW_DLG((20000 + 400) + 143); | |||
939 | ||||
940 | [[fallthrough]]; // on Count = 0 appears the dialog | |||
941 | } | |||
942 | case FN_TABLE_INSERT_COL_DLG((20000 + 400) + 142): | |||
943 | case FN_TABLE_INSERT_ROW_DLG((20000 + 400) + 143): | |||
944 | { | |||
945 | const SfxSlot* pSlot = GetStaticInterface()->GetSlot(nSlot); | |||
946 | if ( FN_TABLE_INSERT_ROW_DLG((20000 + 400) + 143) != nSlot || !rSh.IsInRepeatedHeadline()) | |||
947 | { | |||
948 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); | |||
949 | ScopedVclPtr<SvxAbstractInsRowColDlg> pDlg(pFact->CreateSvxInsRowColDlg(GetView().GetFrameWeld(), | |||
950 | nSlot == FN_TABLE_INSERT_COL_DLG((20000 + 400) + 142), pSlot->GetCommand())); | |||
951 | if( pDlg->Execute() == 1 ) | |||
952 | { | |||
953 | const sal_uInt16 nDispatchSlot = (nSlot == FN_TABLE_INSERT_COL_DLG((20000 + 400) + 142)) | |||
954 | ? FN_TABLE_INSERT_COL_AFTER((20000 + 400) + 116) : FN_TABLE_INSERT_ROW_AFTER((20000 + 400) + 109); | |||
955 | SfxUInt16Item aCountItem( nDispatchSlot, pDlg->getInsertCount() ); | |||
956 | SfxBoolItem aAfter( FN_PARAM_INSERT_AFTER((20000 + 1100)+29), !pDlg->isInsertBefore() ); | |||
957 | SfxViewFrame* pVFrame = GetView().GetViewFrame(); | |||
958 | if( pVFrame ) | |||
959 | pVFrame->GetDispatcher()->ExecuteList(nDispatchSlot, | |||
960 | SfxCallMode::SYNCHRON|SfxCallMode::RECORD, | |||
961 | { &aCountItem, &aAfter }); | |||
962 | } | |||
963 | } | |||
964 | break; | |||
965 | } | |||
966 | case FN_TABLE_SPLIT_CELLS((20000 + 400) + 105): | |||
967 | { | |||
968 | long nCount=0; | |||
969 | bool bHorizontal=true; | |||
970 | bool bProportional = false; | |||
971 | const SfxInt32Item* pSplit = rReq.GetArg<SfxInt32Item>(FN_TABLE_SPLIT_CELLS((20000 + 400) + 105)); | |||
972 | const SfxBoolItem* pHor = rReq.GetArg<SfxBoolItem>(FN_PARAM_1((20000 + 1100)+60)); | |||
973 | const SfxBoolItem* pProp = rReq.GetArg<SfxBoolItem>(FN_PARAM_2((20000 + 1100)+61)); | |||
974 | if ( pSplit ) | |||
975 | { | |||
976 | nCount = pSplit->GetValue(); | |||
977 | if ( pHor ) | |||
978 | bHorizontal = pHor->GetValue(); | |||
979 | if ( pProp ) | |||
980 | bProportional = pProp->GetValue(); | |||
981 | } | |||
982 | else | |||
983 | { | |||
984 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); | |||
985 | const long nMaxVert = rSh.GetAnyCurRect( CurRectType::Frame ).Width() / MINLAY23; | |||
986 | ScopedVclPtr<SvxAbstractSplitTableDialog> pDlg(pFact->CreateSvxSplitTableDialog(GetView().GetFrameWeld(), rSh.IsTableVertical(), nMaxVert)); | |||
987 | if(rSh.IsSplitVerticalByDefault()) | |||
988 | pDlg->SetSplitVerticalByDefault(); | |||
989 | if( pDlg->Execute() == RET_OK ) | |||
990 | { | |||
991 | nCount = pDlg->GetCount(); | |||
992 | bHorizontal = pDlg->IsHorizontal(); | |||
993 | bProportional = pDlg->IsProportional(); | |||
994 | rReq.AppendItem( SfxInt32Item( FN_TABLE_SPLIT_CELLS((20000 + 400) + 105), nCount ) ); | |||
995 | rReq.AppendItem( SfxBoolItem( FN_PARAM_1((20000 + 1100)+60), bHorizontal ) ); | |||
996 | rReq.AppendItem( SfxBoolItem( FN_PARAM_2((20000 + 1100)+61), bProportional ) ); | |||
997 | ||||
998 | // tdf#60242: remember choice for next time | |||
999 | bool bVerticalWasChecked = !pDlg->IsHorizontal(); | |||
1000 | rSh.SetSplitVerticalByDefault(bVerticalWasChecked); | |||
1001 | } | |||
1002 | } | |||
1003 | ||||
1004 | if ( nCount>1 ) | |||
1005 | { | |||
1006 | rSh.SplitTab(!bHorizontal, static_cast< sal_uInt16 >( nCount-1 ), bProportional ); | |||
1007 | bCallDone = true; | |||
1008 | } | |||
1009 | else | |||
1010 | rReq.Ignore(); | |||
1011 | break; | |||
1012 | } | |||
1013 | ||||
1014 | case FN_TABLE_SPLIT_TABLE((20000 + 1600) + 142): | |||
1015 | { | |||
1016 | const SfxUInt16Item* pType = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1((20000 + 1100)+60)); | |||
1017 | if( pType ) | |||
1018 | { | |||
1019 | switch( static_cast<SplitTable_HeadlineOption>(pType->GetValue()) ) | |||
1020 | { | |||
1021 | case SplitTable_HeadlineOption::NONE : | |||
1022 | case SplitTable_HeadlineOption::BorderCopy: | |||
1023 | case SplitTable_HeadlineOption::ContentCopy: | |||
1024 | case SplitTable_HeadlineOption::BoxAttrCopy: | |||
1025 | case SplitTable_HeadlineOption::BoxAttrAllCopy: | |||
1026 | rSh.SplitTable(static_cast<SplitTable_HeadlineOption>(pType->GetValue())) ; | |||
1027 | break; | |||
1028 | default: ;//wrong parameter, do nothing | |||
1029 | } | |||
1030 | } | |||
1031 | else | |||
1032 | { | |||
1033 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
1034 | ScopedVclPtr<AbstractSplitTableDialog> pDlg(pFact->CreateSplitTableDialog(GetView().GetFrameWeld(), rSh)); | |||
1035 | pDlg->Execute(); | |||
1036 | rReq.AppendItem( SfxUInt16Item( FN_PARAM_1((20000 + 1100)+60), static_cast<sal_uInt16>(pDlg->GetSplitMode()) ) ); | |||
1037 | bCallDone = true; | |||
1038 | } | |||
1039 | break; | |||
1040 | } | |||
1041 | ||||
1042 | case FN_TABLE_MERGE_TABLE((20000 + 1600) + 152): | |||
1043 | { | |||
1044 | bool bPrev = rSh.CanMergeTable(); | |||
1045 | bool bNext = rSh.CanMergeTable( false ); | |||
1046 | ||||
1047 | if( bPrev && bNext ) | |||
1048 | { | |||
1049 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); | |||
1050 | ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateTableMergeDialog(GetView().GetFrameWeld(), bPrev)); | |||
1051 | if( RET_OK != pDlg->Execute()) | |||
1052 | bPrev = bNext = false; | |||
1053 | } | |||
1054 | ||||
1055 | if( bPrev || bNext ) | |||
1056 | rSh.MergeTable( bPrev ); | |||
1057 | break; | |||
1058 | } | |||
1059 | ||||
1060 | case FN_TABLE_MODE_FIX((20000 + 400) + 189) : | |||
1061 | case FN_TABLE_MODE_FIX_PROP((20000 + 400) + 190) : | |||
1062 | case FN_TABLE_MODE_VARIABLE((20000 + 400) + 191) : | |||
1063 | { | |||
1064 | rSh.SetTableChgMode( FN_TABLE_MODE_FIX((20000 + 400) + 189) == nSlot | |||
1065 | ? TableChgMode::FixedWidthChangeAbs | |||
1066 | : FN_TABLE_MODE_FIX_PROP((20000 + 400) + 190) == nSlot | |||
1067 | ? TableChgMode::FixedWidthChangeProp | |||
1068 | : TableChgMode::VarWidthChangeAbs ); | |||
1069 | ||||
1070 | SfxBindings& rBind = GetView().GetViewFrame()->GetBindings(); | |||
1071 | static sal_uInt16 aInva[] = | |||
1072 | { FN_TABLE_MODE_FIX((20000 + 400) + 189), | |||
1073 | FN_TABLE_MODE_FIX_PROP((20000 + 400) + 190), | |||
1074 | FN_TABLE_MODE_VARIABLE((20000 + 400) + 191), | |||
1075 | 0 | |||
1076 | }; | |||
1077 | rBind.Invalidate( aInva ); | |||
1078 | bCallDone = true; | |||
1079 | break; | |||
1080 | } | |||
1081 | case FN_TABLE_AUTOSUM((20000 + 400) + 195): | |||
1082 | { | |||
1083 | SfxViewFrame* pVFrame = GetView().GetViewFrame(); | |||
1084 | pVFrame->GetDispatcher()->Execute(FN_EDIT_FORMULA((20000 + 100) + 28), SfxCallMode::SYNCHRON); | |||
1085 | const sal_uInt16 nId = SwInputChild::GetChildWindowId(); | |||
1086 | SwInputChild* pChildWin = static_cast<SwInputChild*>(pVFrame-> | |||
1087 | GetChildWindow( nId )); | |||
1088 | OUString sSum; | |||
1089 | GetShell().GetAutoSum(sSum); | |||
1090 | if( pChildWin ) | |||
1091 | pChildWin->SetFormula( sSum ); | |||
1092 | ||||
1093 | break; | |||
1094 | } | |||
1095 | case FN_TABLE_HEADLINE_REPEAT((20000 + 400) + 120): | |||
1096 | if(0 != rSh.GetRowsToRepeat()) | |||
1097 | rSh.SetRowsToRepeat( 0 ); | |||
1098 | else | |||
1099 | rSh.SetRowsToRepeat(rSh.GetRowSelectionFromTop()); | |||
1100 | break; | |||
1101 | case FN_TABLE_SELECT_CELL((20000 + 400) + 130) : | |||
1102 | rSh.SelectTableCell(); | |||
1103 | break; | |||
1104 | case FN_TABLE_DELETE_TABLE((20000 + 400) + 129) : | |||
1105 | { | |||
1106 | rSh.StartAction(); | |||
1107 | rSh.StartUndo(); | |||
1108 | rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(FN_TABLE_SELECT_ALL((20000 + 400) + 115)); | |||
1109 | rSh.DeleteTable(); | |||
1110 | rSh.EndUndo(); | |||
1111 | rSh.EndAction(); | |||
1112 | //'this' is already destroyed | |||
1113 | return; | |||
1114 | } | |||
1115 | case SID_ATTR_TABLE_ROW_HEIGHT((20000 + 400) + 193): | |||
1116 | { | |||
1117 | const SfxUInt32Item* pItem2 = rReq.GetArg<SfxUInt32Item>(SID_ATTR_TABLE_ROW_HEIGHT((20000 + 400) + 193)); | |||
1118 | if (pItem2) | |||
1119 | { | |||
1120 | long nNewHeight = pItem2->GetValue(); | |||
1121 | std::unique_ptr<SwFormatFrameSize> pHeight = rSh.GetRowHeight(); | |||
1122 | if ( pHeight ) | |||
1123 | { | |||
1124 | if (pHeight->GetHeightSizeType() == SwFrameSize::Variable) | |||
1125 | pHeight->SetHeightSizeType(SwFrameSize::Minimum); | |||
1126 | pHeight->SetHeight(nNewHeight); | |||
1127 | rSh.SetRowHeight(*pHeight); | |||
1128 | } | |||
1129 | } | |||
1130 | return; | |||
1131 | } | |||
1132 | case SID_ATTR_TABLE_COLUMN_WIDTH((20000 + 1600) + 194): | |||
1133 | { | |||
1134 | const SfxUInt32Item* pItem2 = rReq.GetArg<SfxUInt32Item>(SID_ATTR_TABLE_COLUMN_WIDTH((20000 + 1600) + 194)); | |||
1135 | if (pItem2) | |||
1136 | { | |||
1137 | long nNewWidth = pItem2->GetValue(); | |||
1138 | SwTableFUNC aFunc( &rSh ); | |||
1139 | aFunc.InitTabCols(); | |||
1140 | aFunc.SetColWidth(aFunc.GetCurColNum(), nNewWidth); | |||
1141 | } | |||
1142 | return; | |||
1143 | } | |||
1144 | default: | |||
1145 | bMore = true; | |||
1146 | } | |||
1147 | ||||
1148 | if ( !bMore ) | |||
1149 | { | |||
1150 | if(bCallDone) | |||
1151 | rReq.Done(); | |||
1152 | return; | |||
1153 | } | |||
1154 | ||||
1155 | // Now the slots which are working directly on the TableFormat. | |||
1156 | switch ( nSlot ) | |||
1157 | { | |||
1158 | case SID_ATTR_ULSPACE( 10000 + 49 ): | |||
1159 | if(pItem) | |||
1160 | { | |||
1161 | SvxULSpaceItem aULSpace( *static_cast<const SvxULSpaceItem*>(pItem) ); | |||
1162 | aULSpace.SetWhich( RES_UL_SPACE ); | |||
1163 | ::lcl_SetAttr( rSh, aULSpace ); | |||
1164 | } | |||
1165 | break; | |||
1166 | ||||
1167 | case SID_ATTR_LRSPACE( 10000 + 48 ): | |||
1168 | if(pItem) | |||
1169 | { | |||
1170 | SfxItemSet aSet( GetPool(), svl::Items<RES_LR_SPACE, RES_LR_SPACE, | |||
1171 | RES_HORI_ORIENT, RES_HORI_ORIENT>{} ); | |||
1172 | SvxLRSpaceItem aLRSpace( *static_cast<const SvxLRSpaceItem*>(pItem) ); | |||
1173 | aLRSpace.SetWhich( RES_LR_SPACE ); | |||
1174 | aSet.Put( aLRSpace ); | |||
1175 | rSh.SetTableAttr( aSet ); | |||
1176 | } | |||
1177 | break; | |||
1178 | // The last case branch which needs a table manager!! | |||
1179 | case FN_TABLE_SET_COL_WIDTH((20000 + 400) + 108): | |||
1180 | { | |||
1181 | SwTableFUNC aMgr( &rSh ); | |||
1182 | aMgr.ColWidthDlg(GetView().GetFrameWeld()); | |||
1183 | break; | |||
1184 | } | |||
1185 | case SID_TABLE_VERT_NONE( 10000 + 1075 ): | |||
1186 | case SID_TABLE_VERT_CENTER( 10000 + 1074 ): | |||
1187 | case SID_TABLE_VERT_BOTTOM( 10000 + 1073 ): | |||
1188 | { | |||
1189 | const sal_uInt16 nAlign = nSlot == SID_TABLE_VERT_NONE( 10000 + 1075 ) ? | |||
1190 | text::VertOrientation::NONE : | |||
1191 | nSlot == SID_TABLE_VERT_CENTER( 10000 + 1074 ) ? | |||
1192 | text::VertOrientation::CENTER : text::VertOrientation::BOTTOM; | |||
1193 | rSh.SetBoxAlign(nAlign); | |||
1194 | bCallDone = true; | |||
1195 | break; | |||
1196 | } | |||
1197 | ||||
1198 | case SID_ATTR_PARA_SPLIT( 10000 + 39 ): | |||
1199 | if ( pItem ) | |||
1200 | { | |||
1201 | SwFormatLayoutSplit aSplit( static_cast<const SvxFormatSplitItem*>(pItem)->GetValue()); | |||
1202 | SfxItemSet aSet(GetPool(), svl::Items<RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT>{} ); | |||
1203 | aSet.Put(aSplit); | |||
1204 | rSh.SetTableAttr(aSet); | |||
1205 | } | |||
1206 | break; | |||
1207 | ||||
1208 | case SID_ATTR_PARA_KEEP( 10000 + 66 ): | |||
1209 | if ( pItem ) | |||
1210 | { | |||
1211 | SvxFormatKeepItem aKeep( *static_cast<const SvxFormatKeepItem*>(pItem) ); | |||
1212 | aKeep.SetWhich( RES_KEEP ); | |||
1213 | SfxItemSet aSet(GetPool(), svl::Items<RES_KEEP, RES_KEEP>{} ); | |||
1214 | aSet.Put(aKeep); | |||
1215 | rSh.SetTableAttr(aSet); | |||
1216 | } | |||
1217 | break; | |||
1218 | case FN_TABLE_ROW_SPLIT((20000 + 1600) + 153) : | |||
1219 | { | |||
1220 | const SfxBoolItem* pBool = static_cast<const SfxBoolItem*>(pItem); | |||
1221 | std::unique_ptr<SwFormatRowSplit> pSplit; | |||
1222 | if(!pBool) | |||
1223 | { | |||
1224 | pSplit = rSh.GetRowSplit(); | |||
1225 | if(pSplit) | |||
1226 | pSplit->SetValue(!pSplit->GetValue()); | |||
1227 | else | |||
1228 | pSplit.reset(new SwFormatRowSplit(true)); | |||
1229 | } | |||
1230 | else | |||
1231 | { | |||
1232 | pSplit.reset(new SwFormatRowSplit(pBool->GetValue())); | |||
1233 | } | |||
1234 | rSh.SetRowSplit( *pSplit ); | |||
1235 | break; | |||
1236 | } | |||
1237 | ||||
1238 | default: | |||
1239 | OSL_ENSURE( false, "wrong Dispatcher" )do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/tabsh.cxx" ":" "1239" ": "), "%s", "wrong Dispatcher"); } } while (false ); | |||
1240 | return; | |||
1241 | } | |||
1242 | if(bCallDone) | |||
1243 | rReq.Done(); | |||
1244 | } | |||
1245 | ||||
1246 | void SwTableShell::GetState(SfxItemSet &rSet) | |||
1247 | { | |||
1248 | SfxWhichIter aIter( rSet ); | |||
1249 | SwWrtShell &rSh = GetShell(); | |||
1250 | SwFrameFormat *pFormat = rSh.GetTableFormat(); | |||
1251 | // os #124829# crash report: in case of an invalid shell selection return immediately | |||
1252 | if(!pFormat) | |||
1253 | return; | |||
1254 | sal_uInt16 nSlot = aIter.FirstWhich(); | |||
1255 | while ( nSlot ) | |||
1256 | { | |||
1257 | switch ( nSlot ) | |||
1258 | { | |||
1259 | case FN_TABLE_MERGE_CELLS((20000 + 400) + 106): | |||
1260 | if ( !rSh.IsTableMode() ) | |||
1261 | rSet.DisableItem(FN_TABLE_MERGE_CELLS((20000 + 400) + 106)); | |||
1262 | break; | |||
1263 | case SID_TABLE_MINIMAL_COLUMN_WIDTH( 10000 + 1185 ): | |||
1264 | case FN_TABLE_ADJUST_CELLS((20000 + 400) + 121): | |||
1265 | if ( !rSh.IsAdjustCellWidthAllowed() ) | |||
1266 | rSet.DisableItem(nSlot); | |||
1267 | break; | |||
1268 | ||||
1269 | case FN_TABLE_BALANCE_CELLS((20000 + 400) + 182): | |||
1270 | if ( !rSh.IsAdjustCellWidthAllowed(true) ) | |||
1271 | rSet.DisableItem(FN_TABLE_BALANCE_CELLS((20000 + 400) + 182)); | |||
1272 | break; | |||
1273 | ||||
1274 | case FN_TABLE_OPTIMAL_HEIGHT((20000 + 400) + 128): | |||
1275 | case FN_TABLE_BALANCE_ROWS((20000 + 400) + 183): | |||
1276 | if ( !rSh.BalanceRowHeight(true) ) | |||
1277 | rSet.DisableItem(nSlot); | |||
1278 | break; | |||
1279 | case FN_OPTIMIZE_TABLE((20000 + 400) + 110): | |||
1280 | if ( !rSh.IsTableMode() && | |||
1281 | !rSh.IsAdjustCellWidthAllowed() && | |||
1282 | !rSh.IsAdjustCellWidthAllowed(true) && | |||
1283 | !rSh.BalanceRowHeight(true) ) | |||
1284 | rSet.DisableItem(FN_OPTIMIZE_TABLE((20000 + 400) + 110)); | |||
1285 | break; | |||
1286 | case SID_INSERT_DIAGRAM( 10000 + 140 ): | |||
1287 | { | |||
1288 | SvtModuleOptions aMOpt; | |||
1289 | if ( !aMOpt.IsMath() || rSh.IsTableComplexForChart() ) | |||
1290 | rSet.DisableItem(nSlot); | |||
1291 | } | |||
1292 | break; | |||
1293 | ||||
1294 | case FN_INSERT_TABLE((20000 + 300) + 30): | |||
1295 | if ( rSh.CursorInsideInputField() ) | |||
1296 | { | |||
1297 | rSet.DisableItem( nSlot ); | |||
1298 | } | |||
1299 | break; | |||
1300 | ||||
1301 | case SID_TABLE_MINIMAL_ROW_HEIGHT( 10000 + 1186 ): | |||
1302 | { | |||
1303 | // Disable if auto height already is enabled. | |||
1304 | std::unique_ptr<SwFormatFrameSize> pSz = rSh.GetRowHeight(); | |||
1305 | if ( pSz ) | |||
1306 | { | |||
1307 | if ( SwFrameSize::Variable == pSz->GetHeightSizeType() ) | |||
1308 | rSet.DisableItem( nSlot ); | |||
1309 | } | |||
1310 | break; | |||
1311 | } | |||
1312 | case FN_TABLE_INSERT_ROW((20000 + 400) + 101): | |||
1313 | case FN_TABLE_INSERT_ROW_AFTER((20000 + 400) + 109): | |||
1314 | case FN_TABLE_INSERT_ROW_DLG((20000 + 400) + 143): | |||
1315 | if ( rSh.IsInRepeatedHeadline() ) | |||
1316 | rSet.DisableItem( nSlot ); | |||
1317 | break; | |||
1318 | case RES_LR_SPACE: | |||
1319 | rSet.Put(pFormat->GetLRSpace()); | |||
1320 | break; | |||
1321 | case RES_UL_SPACE: | |||
1322 | rSet.Put(pFormat->GetULSpace()); | |||
1323 | break; | |||
1324 | ||||
1325 | case SID_TABLE_VERT_NONE( 10000 + 1075 ): | |||
1326 | case SID_TABLE_VERT_CENTER( 10000 + 1074 ): | |||
1327 | case SID_TABLE_VERT_BOTTOM( 10000 + 1073 ): | |||
1328 | { | |||
1329 | const sal_uInt16 nAlign = rSh.GetBoxAlign(); | |||
1330 | bool bSet = (nSlot == SID_TABLE_VERT_NONE( 10000 + 1075 ) && nAlign == text::VertOrientation::NONE) || | |||
1331 | (nSlot == SID_TABLE_VERT_CENTER( 10000 + 1074 ) && nAlign == text::VertOrientation::CENTER) || | |||
1332 | (nSlot == SID_TABLE_VERT_BOTTOM( 10000 + 1073 ) && nAlign == text::VertOrientation::BOTTOM); | |||
1333 | rSet.Put(SfxBoolItem(nSlot, bSet)); | |||
1334 | break; | |||
1335 | } | |||
1336 | ||||
1337 | case FN_TABLE_MODE_FIX((20000 + 400) + 189) : | |||
1338 | case FN_TABLE_MODE_FIX_PROP((20000 + 400) + 190) : | |||
1339 | case FN_TABLE_MODE_VARIABLE((20000 + 400) + 191) : | |||
1340 | { | |||
1341 | TableChgMode nMode = rSh.GetTableChgMode(); | |||
1342 | bool bSet = (nSlot == FN_TABLE_MODE_FIX((20000 + 400) + 189) && nMode == TableChgMode::FixedWidthChangeAbs) || | |||
1343 | (nSlot == FN_TABLE_MODE_FIX_PROP((20000 + 400) + 190) && nMode == TableChgMode::FixedWidthChangeProp) || | |||
1344 | (nSlot == FN_TABLE_MODE_VARIABLE((20000 + 400) + 191) && nMode == TableChgMode::VarWidthChangeAbs); | |||
1345 | rSet.Put(SfxBoolItem(nSlot, bSet)); | |||
1346 | } | |||
1347 | break; | |||
1348 | ||||
1349 | case SID_ATTR_PARA_SPLIT( 10000 + 39 ): | |||
1350 | rSet.Put( pFormat->GetKeep() ); | |||
1351 | break; | |||
1352 | ||||
1353 | case SID_ATTR_PARA_KEEP( 10000 + 66 ): | |||
1354 | rSet.Put( pFormat->GetLayoutSplit() ); | |||
1355 | break; | |||
1356 | case FN_TABLE_SPLIT_TABLE((20000 + 1600) + 142): | |||
1357 | if ( rSh.IsInHeadline() ) | |||
1358 | rSet.DisableItem( nSlot ); | |||
1359 | break; | |||
1360 | case FN_TABLE_MERGE_TABLE((20000 + 1600) + 152): | |||
1361 | { | |||
1362 | bool bAsk; | |||
1363 | if( !rSh.CanMergeTable( true, &bAsk )) | |||
1364 | rSet.DisableItem( nSlot ); | |||
1365 | break; | |||
1366 | } | |||
1367 | ||||
1368 | case FN_TABLE_DELETE_ROW((20000 + 400) + 103): | |||
1369 | { | |||
1370 | SwSelBoxes aBoxes; | |||
1371 | ::GetTableSel( rSh, aBoxes, SwTableSearchType::Row ); | |||
1372 | if( ::HasProtectedCells( aBoxes )) | |||
1373 | rSet.DisableItem( nSlot ); | |||
1374 | } | |||
1375 | break; | |||
1376 | case FN_TABLE_DELETE_COL((20000 + 400) + 104): | |||
1377 | { | |||
1378 | SwSelBoxes aBoxes; | |||
1379 | ::GetTableSel( rSh, aBoxes, SwTableSearchType::Col ); | |||
1380 | if( ::HasProtectedCells( aBoxes )) | |||
1381 | rSet.DisableItem( nSlot ); | |||
1382 | } | |||
1383 | break; | |||
1384 | ||||
1385 | case FN_TABLE_UNSET_READ_ONLY_CELLS((20000 + 400) + 119): | |||
1386 | // disable in readonly sections, but enable in protected cells | |||
1387 | if( !rSh.CanUnProtectCells() ) | |||
1388 | rSet.DisableItem( nSlot ); | |||
1389 | break; | |||
1390 | case RES_ROW_SPLIT: | |||
1391 | { | |||
1392 | const SwFormatLayoutSplit& rTabSplit = pFormat->GetLayoutSplit(); | |||
1393 | if ( !rTabSplit.GetValue() ) | |||
1394 | { | |||
1395 | rSet.DisableItem( nSlot ); | |||
1396 | } | |||
1397 | else | |||
1398 | { | |||
1399 | std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit(); | |||
1400 | if(pSplit) | |||
1401 | rSet.Put(std::move(pSplit)); | |||
1402 | else | |||
1403 | rSet.InvalidateItem( nSlot ); | |||
1404 | } | |||
1405 | break; | |||
1406 | } | |||
1407 | case FN_TABLE_HEADLINE_REPEAT((20000 + 400) + 120): | |||
1408 | if(0 != rSh.GetRowsToRepeat()) | |||
1409 | rSet.Put(SfxBoolItem(nSlot, true)); | |||
1410 | else if(!rSh.GetRowSelectionFromTop()) | |||
1411 | rSet.DisableItem( nSlot ); | |||
1412 | else | |||
1413 | rSet.Put(SfxBoolItem(nSlot, false)); | |||
1414 | break; | |||
1415 | case FN_TABLE_SELECT_CELL((20000 + 400) + 130) : | |||
1416 | if(rSh.HasBoxSelection()) | |||
1417 | rSet.DisableItem( nSlot ); | |||
1418 | break; | |||
1419 | case SID_ATTR_TABLE_ROW_HEIGHT((20000 + 400) + 193): | |||
1420 | { | |||
1421 | SfxUInt32Item aRowHeight(SID_ATTR_TABLE_ROW_HEIGHT((20000 + 400) + 193)); | |||
1422 | std::unique_ptr<SwFormatFrameSize> pHeight = rSh.GetRowHeight(); | |||
1423 | if (pHeight) | |||
1424 | { | |||
1425 | long nHeight = pHeight->GetHeight(); | |||
1426 | aRowHeight.SetValue(nHeight); | |||
1427 | rSet.Put(aRowHeight); | |||
1428 | ||||
1429 | if (comphelper::LibreOfficeKit::isActive()) | |||
1430 | { | |||
1431 | // TODO: set correct unit | |||
1432 | MapUnit eTargetUnit = MapUnit::MapInch; | |||
1433 | OUString sHeight = GetMetricText(nHeight, | |||
1434 | MapUnit::MapTwip, eTargetUnit, nullptr); | |||
1435 | ||||
1436 | OUString sPayload = ".uno:TableRowHeight=" + sHeight; | |||
1437 | ||||
1438 | GetViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, | |||
1439 | OUStringToOString(sPayload, RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11))).getStr()); | |||
1440 | } | |||
1441 | } | |||
1442 | break; | |||
1443 | } | |||
1444 | case SID_ATTR_TABLE_COLUMN_WIDTH((20000 + 1600) + 194): | |||
1445 | { | |||
1446 | SfxUInt32Item aColumnWidth(SID_ATTR_TABLE_COLUMN_WIDTH((20000 + 1600) + 194)); | |||
1447 | SwTableFUNC aFunc( &rSh ); | |||
1448 | aFunc.InitTabCols(); | |||
1449 | SwTwips nWidth = aFunc.GetColWidth(aFunc.GetCurColNum()); | |||
1450 | aColumnWidth.SetValue(nWidth); | |||
1451 | rSet.Put(aColumnWidth); | |||
1452 | ||||
1453 | if (comphelper::LibreOfficeKit::isActive()) | |||
1454 | { | |||
1455 | // TODO: set correct unit | |||
1456 | MapUnit eTargetUnit = MapUnit::MapInch; | |||
1457 | OUString sWidth = GetMetricText(nWidth, | |||
1458 | MapUnit::MapTwip, eTargetUnit, nullptr); | |||
1459 | ||||
1460 | OUString sPayload = ".uno:TableColumWidth=" + sWidth; | |||
1461 | ||||
1462 | GetViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, | |||
1463 | OUStringToOString(sPayload, RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11))).getStr()); | |||
1464 | } | |||
1465 | ||||
1466 | break; | |||
1467 | } | |||
1468 | } | |||
1469 | nSlot = aIter.NextWhich(); | |||
1470 | } | |||
1471 | } | |||
1472 | ||||
1473 | SwTableShell::SwTableShell(SwView &_rView) : | |||
1474 | SwBaseShell(_rView) | |||
1475 | { | |||
1476 | SetName("Table"); | |||
1477 | SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Table)); | |||
1478 | } | |||
1479 | ||||
1480 | void SwTableShell::GetFrameBorderState(SfxItemSet &rSet) | |||
1481 | { | |||
1482 | SfxItemSet aCoreSet( GetPool(), | |||
1483 | svl::Items<RES_BOX, RES_BOX, | |||
1484 | SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 )>{} ); | |||
1485 | SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ) ); | |||
1486 | aCoreSet.Put( aBoxInfo ); | |||
1487 | GetShell().GetTabBorders( aCoreSet ); | |||
1488 | rSet.Put( aCoreSet ); | |||
1489 | } | |||
1490 | ||||
1491 | void SwTableShell::ExecTableStyle(SfxRequest& rReq) | |||
1492 | { | |||
1493 | SwWrtShell &rSh = GetShell(); | |||
1494 | const SfxItemSet *pArgs = rReq.GetArgs(); | |||
1495 | if(!pArgs) | |||
1496 | return; | |||
1497 | ||||
1498 | switch ( rReq.GetSlot() ) | |||
1499 | { | |||
1500 | case SID_FRAME_LINESTYLETypedWhichId<SvxLineItem>( 10000 + 201 ): | |||
1501 | case SID_FRAME_LINECOLORTypedWhichId<SvxColorItem>( 10000 + 202 ): | |||
1502 | if ( rReq.GetSlot() == SID_FRAME_LINESTYLETypedWhichId<SvxLineItem>( 10000 + 201 ) ) | |||
1503 | { | |||
1504 | const SvxLineItem &rLineItem = pArgs->Get( SID_FRAME_LINESTYLETypedWhichId<SvxLineItem>( 10000 + 201 ) ); | |||
1505 | const SvxBorderLine* pBorderLine = rLineItem.GetLine(); | |||
1506 | rSh.SetTabLineStyle( nullptr, true, pBorderLine); | |||
1507 | } | |||
1508 | else | |||
1509 | { | |||
1510 | const SvxColorItem &rNewColorItem = pArgs->Get( SID_FRAME_LINECOLORTypedWhichId<SvxColorItem>( 10000 + 202 ) ); | |||
1511 | rSh.SetTabLineStyle( &rNewColorItem.GetValue() ); | |||
1512 | } | |||
1513 | ||||
1514 | rReq.Done(); | |||
1515 | ||||
1516 | break; | |||
1517 | } | |||
1518 | } | |||
1519 | ||||
1520 | void SwTableShell::GetLineStyleState(SfxItemSet &rSet) | |||
1521 | { | |||
1522 | SfxItemSet aCoreSet( GetPool(), | |||
1523 | svl::Items<RES_BOX, RES_BOX, | |||
1524 | SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ), SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 )>{}); | |||
1525 | SvxBoxInfoItem aCoreInfo( SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ) ); | |||
1526 | aCoreSet.Put(aCoreInfo); | |||
1527 | GetShell().GetTabBorders( aCoreSet ); | |||
1528 | ||||
1529 | const SvxBoxItem& rBoxItem = aCoreSet.Get( RES_BOX ); | |||
1530 | const SvxBorderLine* pLine = rBoxItem.GetTop(); | |||
1531 | ||||
1532 | rSet.Put( SvxColorItem( pLine ? pLine->GetColor() : Color(), SID_FRAME_LINECOLORTypedWhichId<SvxColorItem>( 10000 + 202 ) ) ); | |||
1533 | SvxLineItem aLine( SID_FRAME_LINESTYLETypedWhichId<SvxLineItem>( 10000 + 201 ) ); | |||
1534 | aLine.SetLine(pLine); | |||
1535 | rSet.Put( aLine ); | |||
1536 | } | |||
1537 | ||||
1538 | void SwTableShell::ExecNumberFormat(SfxRequest const & rReq) | |||
1539 | { | |||
1540 | const SfxItemSet* pArgs = rReq.GetArgs(); | |||
1541 | SwWrtShell &rSh = GetShell(); | |||
1542 | ||||
1543 | // At first the slots, which doesn't need a FrameMgr. | |||
1544 | const SfxPoolItem* pItem = nullptr; | |||
1545 | const sal_uInt16 nSlot = rReq.GetSlot(); | |||
1546 | if(pArgs) | |||
1547 | pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem); | |||
1548 | ||||
1549 | // Always acquire the language from the current cursor position. | |||
1550 | LanguageType eLang = rSh.GetCurLang(); | |||
1551 | SvNumberFormatter* pFormatter = rSh.GetNumberFormatter(); | |||
1552 | sal_uInt32 nNumberFormat = NUMBERFORMAT_ENTRY_NOT_FOUND; | |||
1553 | SvNumFormatType nFormatType = SvNumFormatType::ALL; | |||
1554 | sal_uInt16 nOffset = 0; | |||
1555 | ||||
1556 | switch ( nSlot ) | |||
1557 | { | |||
1558 | case FN_NUMBER_FORMAT((20000 + 1600) + 120): | |||
1559 | if( pItem ) | |||
1560 | { | |||
1561 | // Determine index for string. | |||
1562 | OUString aCode( static_cast<const SfxStringItem*>(pItem)->GetValue() ); | |||
1563 | nNumberFormat = pFormatter->GetEntryKey( aCode, eLang ); | |||
1564 | if( NUMBERFORMAT_ENTRY_NOT_FOUND == nNumberFormat ) | |||
1565 | { | |||
1566 | // Re-enter | |||
1567 | sal_Int32 nErrPos; | |||
1568 | SvNumFormatType nType; | |||
1569 | if( !pFormatter->PutEntry( aCode, nErrPos, nType, | |||
1570 | nNumberFormat, eLang )) | |||
1571 | nNumberFormat = NUMBERFORMAT_ENTRY_NOT_FOUND; | |||
1572 | } | |||
1573 | } | |||
1574 | break; | |||
1575 | case FN_NUMBER_STANDARD((20000 + 1600) + 121): nFormatType = SvNumFormatType::NUMBER; break; | |||
1576 | case FN_NUMBER_SCIENTIFIC((20000 + 1600) + 124): nFormatType = SvNumFormatType::SCIENTIFIC; break; | |||
1577 | case FN_NUMBER_DATE((20000 + 1600) + 125): nFormatType = SvNumFormatType::DATE; break; | |||
1578 | case FN_NUMBER_TIME((20000 + 1600) + 126): nFormatType = SvNumFormatType::TIME; break; | |||
1579 | case FN_NUMBER_CURRENCY((20000 + 1600) + 127): nFormatType = SvNumFormatType::CURRENCY; break; | |||
1580 | case FN_NUMBER_PERCENT((20000 + 1600) + 128): nFormatType = SvNumFormatType::PERCENT; break; | |||
1581 | ||||
1582 | case FN_NUMBER_TWODEC((20000 + 1600) + 123): // #.##0,00 | |||
1583 | nFormatType = SvNumFormatType::NUMBER; | |||
1584 | nOffset = NF_NUMBER_1000DEC2; | |||
1585 | break; | |||
1586 | ||||
1587 | default: | |||
1588 | OSL_FAIL("wrong dispatcher")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/tabsh.cxx" ":" "1588" ": "), "%s", "wrong dispatcher"); } } while (false ); | |||
1589 | return; | |||
1590 | } | |||
1591 | ||||
1592 | if( nFormatType != SvNumFormatType::ALL ) | |||
1593 | nNumberFormat = pFormatter->GetStandardFormat( nFormatType, eLang ) + nOffset; | |||
1594 | ||||
1595 | if( NUMBERFORMAT_ENTRY_NOT_FOUND != nNumberFormat ) | |||
1596 | { | |||
1597 | SfxItemSet aBoxSet( GetPool(), svl::Items<RES_BOXATR_FORMAT, RES_BOXATR_FORMAT>{} ); | |||
1598 | aBoxSet.Put( SwTableBoxNumFormat( nNumberFormat )); | |||
1599 | rSh.SetTableBoxFormulaAttrs( aBoxSet ); | |||
1600 | } | |||
1601 | ||||
1602 | } | |||
1603 | ||||
1604 | /* 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 |