workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / cui / source / tabpages / labdlg.cxx
blob2540c5335282ed152313ad8971b01188eb20e511
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <swpossizetabpage.hxx>
21 #include <svtools/unitconv.hxx>
23 #include <svx/svddef.hxx>
24 #include <svx/sxcecitm.hxx>
25 #include <svx/sxcgitm.hxx>
26 #include <svx/sxcllitm.hxx>
27 #include <svx/sxctitm.hxx>
29 #include <svx/dlgutil.hxx>
30 #include <labdlg.hxx>
31 #include <transfrm.hxx>
32 #include <bitmaps.hlst>
34 // define ----------------------------------------------------------------
36 #define EXT_OPTIMAL 0
37 #define EXT_FROM_TOP 1
38 #define EXT_FROM_LEFT 2
39 #define EXT_HORIZONTAL 3
40 #define EXT_VERTICAL 4
42 #define POS_TOP 0
43 #define POS_MIDDLE 1
44 #define POS_BOTTOM 2
46 #define BMP_CAPTTYPE_1 1
47 #define BMP_CAPTTYPE_2 2
48 #define BMP_CAPTTYPE_3 3
50 // static ----------------------------------------------------------------
52 const WhichRangesContainer SvxCaptionTabPage::pCaptionRanges(
53 svl::Items<
54 SDRATTR_CAPTIONTYPE, SDRATTR_CAPTIONFIXEDANGLE,
55 SDRATTR_CAPTIONANGLE, SDRATTR_CAPTIONGAP,
56 SDRATTR_CAPTIONESCDIR, SDRATTR_CAPTIONESCISREL,
57 SDRATTR_CAPTIONESCREL, SDRATTR_CAPTIONESCABS,
58 SDRATTR_CAPTIONLINELEN, SDRATTR_CAPTIONFITLINELEN>);
60 SvxCaptionTabPage::SvxCaptionTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
61 : SfxTabPage(pPage, pController, u"cui/ui/calloutpage.ui"_ustr, u"CalloutPage"_ustr, &rInAttrs)
62 , nCaptionType(SdrCaptionType::Type1)
63 , nGap(0)
64 , nEscDir(SdrCaptionEscDir::Horizontal)
65 , bEscRel(false)
66 , nEscAbs(0)
67 , nEscRel(0)
68 , nLineLen(0)
69 , bFitLineLen(false)
70 , nPosition(0)
71 , nExtension(0)
72 , rOutAttrs(rInAttrs)
73 , pView(nullptr)
74 , m_xMF_SPACING(m_xBuilder->weld_metric_spin_button(u"spacing"_ustr, FieldUnit::MM))
75 , m_xLB_EXTENSION(m_xBuilder->weld_combo_box(u"extension"_ustr))
76 , m_xFT_BYFT(m_xBuilder->weld_label(u"byft"_ustr))
77 , m_xMF_BY(m_xBuilder->weld_metric_spin_button(u"by"_ustr, FieldUnit::MM))
78 , m_xFT_POSITIONFT(m_xBuilder->weld_label(u"positionft"_ustr))
79 , m_xLB_POSITION(m_xBuilder->weld_combo_box(u"position"_ustr))
80 , m_xLineTypes(m_xBuilder->weld_combo_box(u"linetypes"_ustr))
81 , m_xFT_LENGTHFT(m_xBuilder->weld_label(u"lengthft"_ustr))
82 , m_xMF_LENGTH(m_xBuilder->weld_metric_spin_button(u"length"_ustr, FieldUnit::MM))
83 , m_xCB_OPTIMAL(m_xBuilder->weld_check_button(u"optimal"_ustr))
84 , m_xCT_CAPTTYPE(new ValueSet(m_xBuilder->weld_scrolled_window(u"valuesetwin"_ustr, true)))
85 , m_xCT_CAPTTYPEWin(new weld::CustomWeld(*m_xBuilder, u"valueset"_ustr, *m_xCT_CAPTTYPE))
87 Size aSize(m_xCT_CAPTTYPE->GetDrawingArea()->get_ref_device().LogicToPixel(Size(187, 38), MapMode(MapUnit::MapAppFont)));
88 m_xCT_CAPTTYPEWin->set_size_request(aSize.Width(), aSize.Height());
90 assert(m_xLB_POSITION->get_count() == 6);
91 for (int i = 0; i < 3; ++i)
92 m_aStrHorzList.push_back(m_xLB_POSITION->get_text(i));
93 for (int i = 3; i < 6; ++i)
94 m_aStrVertList.push_back(m_xLB_POSITION->get_text(i));
95 m_xLB_POSITION->clear();
97 assert(m_xLineTypes->get_count() == 3);
98 std::vector<OUString> aLineTypes;
99 aLineTypes.reserve(3);
100 for (int i = 0; i < 3; ++i)
101 aLineTypes.push_back(m_xLineTypes->get_text(i));
103 static_assert(CAPTYPE_BITMAPS_COUNT == 3, "unexpected");
104 m_aBmpCapTypes[0] = Image(StockImage::Yes, RID_SVXBMP_LEGTYP1);
105 m_aBmpCapTypes[1] = Image(StockImage::Yes, RID_SVXBMP_LEGTYP2);
106 m_aBmpCapTypes[2] = Image(StockImage::Yes, RID_SVXBMP_LEGTYP3);
108 //------------install ValueSet--------------------------
109 m_xCT_CAPTTYPE->SetStyle( m_xCT_CAPTTYPE->GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER | WB_NAMEFIELD );
110 m_xCT_CAPTTYPE->SetColCount(5);//XXX
111 m_xCT_CAPTTYPE->SetLineCount(1);
112 m_xCT_CAPTTYPE->SetSelectHdl(LINK( this, SvxCaptionTabPage, SelectCaptTypeHdl_Impl));
114 Image aImage;
115 m_xCT_CAPTTYPE->InsertItem(BMP_CAPTTYPE_1, aImage, aLineTypes[0]);
116 m_xCT_CAPTTYPE->InsertItem(BMP_CAPTTYPE_2, aImage, aLineTypes[1]);
117 m_xCT_CAPTTYPE->InsertItem(BMP_CAPTTYPE_3, aImage, aLineTypes[2]);
119 FillValueSet();
121 m_xLB_EXTENSION->connect_changed(LINK(this, SvxCaptionTabPage, ExtensionSelectHdl_Impl));
122 m_xLB_POSITION->connect_changed(LINK(this, SvxCaptionTabPage, PositionSelectHdl_Impl));
123 m_xCB_OPTIMAL->connect_toggled(LINK(this, SvxCaptionTabPage, LineOptHdl_Impl));
126 SvxCaptionTabPage::~SvxCaptionTabPage()
128 m_xCT_CAPTTYPEWin.reset();
129 m_xCT_CAPTTYPE.reset();
132 void SvxCaptionTabPage::Construct()
134 // set rectangle and working area
135 DBG_ASSERT( pView, "No valid View transferred!" );
138 bool SvxCaptionTabPage::FillItemSet( SfxItemSet* _rOutAttrs)
140 SfxItemPool* pPool = _rOutAttrs->GetPool();
141 assert(pPool && "Where is the pool?");
143 MapUnit eUnit;
145 nCaptionType = static_cast<SdrCaptionType>(m_xCT_CAPTTYPE->GetSelectedItemId()-1);
147 _rOutAttrs->Put( SdrCaptionTypeItem( nCaptionType ) );
149 if (m_xMF_SPACING->get_value_changed_from_saved())
151 eUnit = pPool->GetMetric( GetWhich( SDRATTR_CAPTIONGAP ) );
152 _rOutAttrs->Put( SdrCaptionGapItem( GetCoreValue(*m_xMF_SPACING, eUnit ) ) );
155 // special treatment!!! XXX
156 if( nCaptionType==SdrCaptionType::Type1 )
158 switch( nEscDir )
160 case SdrCaptionEscDir::Horizontal: nEscDir=SdrCaptionEscDir::Vertical;break;
161 case SdrCaptionEscDir::Vertical: nEscDir=SdrCaptionEscDir::Horizontal;break;
162 default: break;
166 _rOutAttrs->Put( SdrCaptionEscDirItem( nEscDir ) );
168 bEscRel = m_xLB_POSITION->get_visible();
169 _rOutAttrs->Put( SdrCaptionEscIsRelItem( bEscRel ) );
171 if( bEscRel )
173 tools::Long nVal = 0;
175 switch (m_xLB_POSITION->get_active())
177 case POS_TOP: nVal=0;break;
178 case POS_MIDDLE: nVal=5000;break;
179 case POS_BOTTOM: nVal=10000;break;
181 _rOutAttrs->Put( SdrCaptionEscRelItem( nVal ) );
183 else
185 if (m_xMF_BY->get_value_changed_from_saved())
187 eUnit = pPool->GetMetric( GetWhich( SDRATTR_CAPTIONESCABS ) );
188 _rOutAttrs->Put( SdrCaptionEscAbsItem( GetCoreValue(*m_xMF_BY, eUnit ) ) );
192 bFitLineLen = m_xCB_OPTIMAL->get_active();
193 _rOutAttrs->Put( SdrCaptionFitLineLenItem( bFitLineLen ) );
195 if( ! bFitLineLen )
197 if (m_xMF_LENGTH->get_value_changed_from_saved())
199 eUnit = pPool->GetMetric( GetWhich( SDRATTR_CAPTIONLINELEN ) );
200 _rOutAttrs->Put( SdrCaptionLineLenItem( GetCoreValue(*m_xMF_LENGTH, eUnit ) ) );
204 //NYI-------------the angles have to be added here!!! XXX----------------------
206 return true;
209 void SvxCaptionTabPage::Reset( const SfxItemSet* )
212 //------------set metric-----------------------------
214 FieldUnit eFUnit = GetModuleFieldUnit( rOutAttrs );
216 switch ( eFUnit )
218 case FieldUnit::CM:
219 case FieldUnit::M:
220 case FieldUnit::KM:
221 eFUnit = FieldUnit::MM;
222 break;
223 default: ;//prevent warning
225 SetFieldUnit( *m_xMF_SPACING, eFUnit );
226 SetFieldUnit( *m_xMF_BY, eFUnit );
227 SetFieldUnit( *m_xMF_LENGTH, eFUnit );
229 SfxItemPool* pPool = rOutAttrs.GetPool();
230 assert(pPool && "Where is the pool?");
232 sal_uInt16 nWhich;
233 MapUnit eUnit;
235 nWhich = GetWhich( SDRATTR_CAPTIONESCABS );
236 eUnit = pPool->GetMetric( nWhich );
237 nEscAbs = static_cast<const SdrCaptionEscAbsItem&>( rOutAttrs.Get( nWhich ) ).GetValue();
238 SetMetricValue( *m_xMF_BY, nEscAbs, eUnit );
239 nEscAbs = m_xMF_BY->get_value(FieldUnit::NONE);
241 nWhich = GetWhich( SDRATTR_CAPTIONESCREL );
242 nEscRel = static_cast<tools::Long>(static_cast<const SdrCaptionEscRelItem&>( rOutAttrs.Get( nWhich ) ).GetValue());
244 //------- line length ----------
245 nWhich = GetWhich( SDRATTR_CAPTIONLINELEN );
246 eUnit = pPool->GetMetric( nWhich );
247 nLineLen = static_cast<const SdrCaptionLineLenItem&>( rOutAttrs.Get( nWhich ) ).GetValue();
248 SetMetricValue( *m_xMF_LENGTH, nLineLen, eUnit );
249 nLineLen = m_xMF_LENGTH->get_value(FieldUnit::NONE);
251 //------- distance to box ----------
252 nWhich = GetWhich( SDRATTR_CAPTIONGAP );
253 eUnit = pPool->GetMetric( nWhich );
254 nGap = static_cast<const SdrCaptionGapItem&>( rOutAttrs.Get( nWhich ) ).GetValue();
255 SetMetricValue( *m_xMF_SPACING, nGap, eUnit );
256 nGap = m_xMF_SPACING->get_value(FieldUnit::NONE);
258 nCaptionType = rOutAttrs.Get( GetWhich( SDRATTR_CAPTIONTYPE ) ).GetValue();
259 bFitLineLen = static_cast<const SfxBoolItem&>( rOutAttrs.Get( GetWhich( SDRATTR_CAPTIONFITLINELEN ) ) ).GetValue();
260 nEscDir = rOutAttrs.Get( GetWhich( SDRATTR_CAPTIONESCDIR ) ).GetValue();
261 bEscRel = static_cast<const SfxBoolItem&>( rOutAttrs.Get( GetWhich( SDRATTR_CAPTIONESCISREL ) ) ).GetValue();
263 // special treatment!!! XXX
264 if( nCaptionType==SdrCaptionType::Type1 )
266 switch( nEscDir )
268 case SdrCaptionEscDir::Horizontal: nEscDir=SdrCaptionEscDir::Vertical;break;
269 case SdrCaptionEscDir::Vertical: nEscDir=SdrCaptionEscDir::Horizontal;break;
270 default: break;
274 nPosition = POS_MIDDLE;
275 nExtension = EXT_OPTIMAL;
277 m_xMF_SPACING->set_value(nGap, FieldUnit::NONE);
279 if( nEscDir == SdrCaptionEscDir::Horizontal )
281 if( bEscRel )
283 if( nEscRel < 3333 )
284 nPosition = POS_TOP;
285 if( nEscRel > 6666 )
286 nPosition = POS_BOTTOM;
287 nExtension = EXT_HORIZONTAL;
289 else
291 nExtension = EXT_FROM_TOP;
292 m_xMF_BY->set_value(nEscAbs, FieldUnit::NONE);
295 else if( nEscDir == SdrCaptionEscDir::Vertical )
297 if( bEscRel )
299 if( nEscRel < 3333 )
300 nPosition = POS_TOP;
301 if( nEscRel > 6666 )
302 nPosition = POS_BOTTOM;
303 nExtension = EXT_VERTICAL;
305 else
307 nExtension = EXT_FROM_LEFT;
308 m_xMF_BY->set_value(nEscAbs, FieldUnit::NONE);
311 else if( nEscDir == SdrCaptionEscDir::BestFit )
313 nExtension = EXT_OPTIMAL;
316 m_xCB_OPTIMAL->set_active(bFitLineLen);
317 m_xMF_LENGTH->set_value(nLineLen, FieldUnit::NONE);
319 m_xLB_EXTENSION->set_active(nExtension);
321 SetupExtension_Impl( nExtension );
322 m_xCT_CAPTTYPE->SelectItem( static_cast<int>(nCaptionType)+1 ); // Enum starts at 0!
323 SetupType_Impl( nCaptionType );
326 std::unique_ptr<SfxTabPage> SvxCaptionTabPage::Create(weld::Container* pPage, weld::DialogController* pController,
327 const SfxItemSet* rOutAttrs)
329 return std::make_unique<SvxCaptionTabPage>(pPage, pController, *rOutAttrs);
332 void SvxCaptionTabPage::SetupExtension_Impl( sal_uInt16 nType )
334 switch( nType )
336 case EXT_OPTIMAL:
337 m_xMF_BY->show();
338 m_xFT_BYFT->show();
339 m_xFT_POSITIONFT->hide();
340 m_xLB_POSITION->hide();
341 nEscDir = SdrCaptionEscDir::BestFit;
342 break;
344 case EXT_FROM_TOP:
345 m_xMF_BY->show();
346 m_xFT_BYFT->show();
347 m_xFT_POSITIONFT->hide();
348 m_xLB_POSITION->hide();
349 nEscDir = SdrCaptionEscDir::Horizontal;
350 break;
352 case EXT_FROM_LEFT:
353 m_xMF_BY->show();
354 m_xFT_BYFT->show();
355 m_xFT_POSITIONFT->hide();
356 m_xLB_POSITION->hide();
357 nEscDir = SdrCaptionEscDir::Vertical;
358 break;
360 case EXT_HORIZONTAL:
361 m_xLB_POSITION->clear();
362 for (const OUString & i : m_aStrHorzList)
363 m_xLB_POSITION->append_text(i);
364 m_xLB_POSITION->set_active(nPosition);
366 m_xMF_BY->hide();
367 m_xFT_BYFT->hide();
368 m_xFT_POSITIONFT->show();
369 m_xLB_POSITION->show();
370 nEscDir = SdrCaptionEscDir::Horizontal;
371 break;
373 case EXT_VERTICAL:
374 m_xLB_POSITION->clear();
375 for (const OUString & i : m_aStrVertList)
376 m_xLB_POSITION->append_text(i);
377 m_xLB_POSITION->set_active(nPosition);
379 m_xMF_BY->hide();
380 m_xFT_BYFT->hide();
381 m_xFT_POSITIONFT->show();
382 m_xLB_POSITION->show();
383 nEscDir = SdrCaptionEscDir::Vertical;
384 break;
388 IMPL_LINK(SvxCaptionTabPage, ExtensionSelectHdl_Impl, weld::ComboBox&, rListBox, void)
390 if (&rListBox == m_xLB_EXTENSION.get())
392 SetupExtension_Impl(m_xLB_EXTENSION->get_active());
396 IMPL_LINK(SvxCaptionTabPage, PositionSelectHdl_Impl, weld::ComboBox&, rListBox, void)
398 if (&rListBox == m_xLB_POSITION.get())
400 nPosition = m_xLB_POSITION->get_active();
404 IMPL_LINK( SvxCaptionTabPage, LineOptHdl_Impl, weld::Toggleable&, rButton, void )
406 if (&rButton != m_xCB_OPTIMAL.get())
407 return;
409 if (m_xCB_OPTIMAL->get_active() || !m_xCB_OPTIMAL->get_sensitive())
411 m_xFT_LENGTHFT->set_sensitive(false);
412 m_xMF_LENGTH->set_sensitive(false);
414 else
416 m_xFT_LENGTHFT->set_sensitive(true);
417 m_xMF_LENGTH->set_sensitive(true);
421 IMPL_LINK_NOARG(SvxCaptionTabPage, SelectCaptTypeHdl_Impl, ValueSet*, void)
423 SetupType_Impl( static_cast<SdrCaptionType>(m_xCT_CAPTTYPE->GetSelectedItemId()) );
426 void SvxCaptionTabPage::SetupType_Impl( SdrCaptionType nType )
428 switch( nType )
430 case SdrCaptionType::Type1:
431 case SdrCaptionType::Type2:
432 m_xFT_LENGTHFT->set_sensitive(false);
433 m_xCB_OPTIMAL->set_sensitive(false);
434 LineOptHdl_Impl(*m_xCB_OPTIMAL);
435 break;
436 case SdrCaptionType::Type3:
437 case SdrCaptionType::Type4:
438 m_xFT_LENGTHFT->set_sensitive(true);
439 m_xCB_OPTIMAL->set_sensitive(true);
440 LineOptHdl_Impl(*m_xCB_OPTIMAL);
441 break;
445 void SvxCaptionTabPage::FillValueSet()
447 m_xCT_CAPTTYPE->SetItemImage(BMP_CAPTTYPE_1, m_aBmpCapTypes[0] );
448 m_xCT_CAPTTYPE->SetItemImage(BMP_CAPTTYPE_2, m_aBmpCapTypes[1] );
449 m_xCT_CAPTTYPE->SetItemImage(BMP_CAPTTYPE_3, m_aBmpCapTypes[2] );
452 SvxCaptionTabDialog::SvxCaptionTabDialog(weld::Window* pParent, const SdrView* pSdrView,
453 SvxAnchorIds nAnchorTypes)
454 : SfxTabDialogController(pParent, u"cui/ui/calloutdialog.ui"_ustr, u"CalloutDialog"_ustr)
455 , pView(pSdrView)
456 , nAnchorCtrls(nAnchorTypes)
458 assert(pView); // No valid View transferred!
460 //different positioning page in Writer
461 if (nAnchorCtrls & (SvxAnchorIds::Paragraph | SvxAnchorIds::Character | SvxAnchorIds::Page | SvxAnchorIds::Fly))
463 AddTabPage(u"RID_SVXPAGE_SWPOSSIZE"_ustr, SvxSwPosSizeTabPage::Create,
464 SvxSwPosSizeTabPage::GetRanges );
465 RemoveTabPage(u"RID_SVXPAGE_POSITION_SIZE"_ustr);
467 else
469 AddTabPage(u"RID_SVXPAGE_POSITION_SIZE"_ustr, SvxPositionSizeTabPage::Create,
470 SvxPositionSizeTabPage::GetRanges );
471 RemoveTabPage(u"RID_SVXPAGE_SWPOSSIZE"_ustr);
473 AddTabPage(u"RID_SVXPAGE_CAPTION"_ustr, SvxCaptionTabPage::Create,
474 SvxCaptionTabPage::GetRanges );
477 void SvxCaptionTabDialog::PageCreated(const OUString& rId, SfxTabPage &rPage)
479 if (rId == "RID_SVXPAGE_POSITION_SIZE")
481 static_cast<SvxPositionSizeTabPage&>( rPage ).SetView( pView );
482 static_cast<SvxPositionSizeTabPage&>( rPage ).Construct();
483 if( nAnchorCtrls & SvxAnchorIds::NoResize )
484 static_cast<SvxPositionSizeTabPage&>( rPage ).DisableResize();
486 if( nAnchorCtrls & SvxAnchorIds::NoProtect )
487 static_cast<SvxPositionSizeTabPage&>( rPage ).DisableProtect();
489 else if (rId == "RID_SVXPAGE_SWPOSSIZE")
491 SvxSwPosSizeTabPage& rSwPage = static_cast<SvxSwPosSizeTabPage&>(rPage);
492 rSwPage.EnableAnchorTypes(nAnchorCtrls);
493 rSwPage.SetValidateFramePosLink( aValidateLink );
495 else if (rId == "RID_SVXPAGE_CAPTION")
497 static_cast<SvxCaptionTabPage&>( rPage ).SetView( pView );
498 static_cast<SvxCaptionTabPage&>( rPage ).Construct();
502 void SvxCaptionTabDialog::SetValidateFramePosLink( const Link<SvxSwFrameValidation&,void>& rLink )
504 aValidateLink = rLink;
507 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */