1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <vcl/event.hxx>
22 #include <vcl/settings.hxx>
23 #include <svtools/unitconv.hxx>
25 #include <svx/svddef.hxx>
26 #include <svx/sxcecitm.hxx>
27 #include <svx/sxcgitm.hxx>
28 #include <svx/sxcllitm.hxx>
29 #include <svx/sxctitm.hxx>
31 #include <svx/dlgutil.hxx>
33 #include <transfrm.hxx>
34 #include <bitmaps.hlst>
36 // define ----------------------------------------------------------------
39 #define EXT_FROM_TOP 1
40 #define EXT_FROM_LEFT 2
41 #define EXT_HORIZONTAL 3
42 #define EXT_VERTICAL 4
48 #define BMP_CAPTTYPE_1 1
49 #define BMP_CAPTTYPE_2 2
50 #define BMP_CAPTTYPE_3 3
52 // static ----------------------------------------------------------------
54 const sal_uInt16
SvxCaptionTabPage::pCaptionRanges
[] =
57 SDRATTR_CAPTIONFIXEDANGLE
,
60 SDRATTR_CAPTIONESCDIR
,
61 SDRATTR_CAPTIONESCISREL
,
62 SDRATTR_CAPTIONESCREL
,
63 SDRATTR_CAPTIONESCABS
,
64 SDRATTR_CAPTIONLINELEN
,
65 SDRATTR_CAPTIONFITLINELEN
,
69 SvxCaptionTabPage::SvxCaptionTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rInAttrs
)
70 : SfxTabPage(pPage
, pController
, "cui/ui/calloutpage.ui", "CalloutPage", &rInAttrs
)
71 , nCaptionType(SdrCaptionType::Type1
)
73 , nEscDir(SdrCaptionEscDir::Horizontal
)
83 , m_xMF_SPACING(m_xBuilder
->weld_metric_spin_button("spacing", FieldUnit::MM
))
84 , m_xLB_EXTENSION(m_xBuilder
->weld_combo_box("extension"))
85 , m_xFT_BYFT(m_xBuilder
->weld_label("byft"))
86 , m_xMF_BY(m_xBuilder
->weld_metric_spin_button("by", FieldUnit::MM
))
87 , m_xFT_POSITIONFT(m_xBuilder
->weld_label("positionft"))
88 , m_xLB_POSITION(m_xBuilder
->weld_combo_box("position"))
89 , m_xLineTypes(m_xBuilder
->weld_combo_box("linetypes"))
90 , m_xFT_LENGTHFT(m_xBuilder
->weld_label("lengthft"))
91 , m_xMF_LENGTH(m_xBuilder
->weld_metric_spin_button("length", FieldUnit::MM
))
92 , m_xCB_OPTIMAL(m_xBuilder
->weld_check_button("optimal"))
93 , m_xCT_CAPTTYPE(new SvtValueSet(m_xBuilder
->weld_scrolled_window("valuesetwin")))
94 , m_xCT_CAPTTYPEWin(new weld::CustomWeld(*m_xBuilder
, "valueset", *m_xCT_CAPTTYPE
))
96 Size
aSize(m_xCT_CAPTTYPE
->GetDrawingArea()->get_ref_device().LogicToPixel(Size(187, 38), MapMode(MapUnit::MapAppFont
)));
97 m_xCT_CAPTTYPEWin
->set_size_request(aSize
.Width(), aSize
.Height());
99 assert(m_xLB_POSITION
->get_count() == 6);
100 for (int i
= 0; i
< 3; ++i
)
101 m_aStrHorzList
.push_back(m_xLB_POSITION
->get_text(i
));
102 for (int i
= 3; i
< 6; ++i
)
103 m_aStrVertList
.push_back(m_xLB_POSITION
->get_text(i
));
104 m_xLB_POSITION
->clear();
106 assert(m_xLineTypes
->get_count() == 3);
107 std::vector
<OUString
> aLineTypes
;
108 aLineTypes
.reserve(3);
109 for (int i
= 0; i
< 3; ++i
)
110 aLineTypes
.push_back(m_xLineTypes
->get_text(i
));
112 static_assert(CAPTYPE_BITMAPS_COUNT
== 3, "unexpected");
113 m_aBmpCapTypes
[0] = Image(StockImage::Yes
, RID_SVXBMP_LEGTYP1
);
114 m_aBmpCapTypes
[1] = Image(StockImage::Yes
, RID_SVXBMP_LEGTYP2
);
115 m_aBmpCapTypes
[2] = Image(StockImage::Yes
, RID_SVXBMP_LEGTYP3
);
117 //------------install ValueSet--------------------------
118 m_xCT_CAPTTYPE
->SetStyle( m_xCT_CAPTTYPE
->GetStyle() | WB_ITEMBORDER
| WB_DOUBLEBORDER
| WB_NAMEFIELD
);
119 m_xCT_CAPTTYPE
->SetColCount(5);//XXX
120 m_xCT_CAPTTYPE
->SetLineCount(1);
121 m_xCT_CAPTTYPE
->SetSelectHdl(LINK( this, SvxCaptionTabPage
, SelectCaptTypeHdl_Impl
));
124 m_xCT_CAPTTYPE
->InsertItem(BMP_CAPTTYPE_1
, aImage
, aLineTypes
[0]);
125 m_xCT_CAPTTYPE
->InsertItem(BMP_CAPTTYPE_2
, aImage
, aLineTypes
[1]);
126 m_xCT_CAPTTYPE
->InsertItem(BMP_CAPTTYPE_3
, aImage
, aLineTypes
[2]);
130 m_xLB_EXTENSION
->connect_changed(LINK(this, SvxCaptionTabPage
, ExtensionSelectHdl_Impl
));
131 m_xLB_POSITION
->connect_changed(LINK(this, SvxCaptionTabPage
, PositionSelectHdl_Impl
));
132 m_xCB_OPTIMAL
->connect_toggled(LINK(this, SvxCaptionTabPage
, LineOptHdl_Impl
));
135 SvxCaptionTabPage::~SvxCaptionTabPage()
137 m_xCT_CAPTTYPEWin
.reset();
138 m_xCT_CAPTTYPE
.reset();
141 void SvxCaptionTabPage::Construct()
143 // set rectangle and working area
144 DBG_ASSERT( pView
, "No valid View transferred!" );
147 bool SvxCaptionTabPage::FillItemSet( SfxItemSet
* _rOutAttrs
)
149 SfxItemPool
* pPool
= _rOutAttrs
->GetPool();
150 DBG_ASSERT( pPool
, "Where is the pool?" );
154 nCaptionType
= static_cast<SdrCaptionType
>(m_xCT_CAPTTYPE
->GetSelectedItemId()-1);
156 _rOutAttrs
->Put( SdrCaptionTypeItem( nCaptionType
) );
158 if (m_xMF_SPACING
->get_value_changed_from_saved())
160 eUnit
= pPool
->GetMetric( GetWhich( SDRATTR_CAPTIONGAP
) );
161 _rOutAttrs
->Put( SdrCaptionGapItem( GetCoreValue(*m_xMF_SPACING
, eUnit
) ) );
164 // special treatment!!! XXX
165 if( nCaptionType
==SdrCaptionType::Type1
)
169 case SdrCaptionEscDir::Horizontal
: nEscDir
=SdrCaptionEscDir::Vertical
;break;
170 case SdrCaptionEscDir::Vertical
: nEscDir
=SdrCaptionEscDir::Horizontal
;break;
175 _rOutAttrs
->Put( SdrCaptionEscDirItem( nEscDir
) );
177 bEscRel
= m_xLB_POSITION
->get_visible();
178 _rOutAttrs
->Put( SdrCaptionEscIsRelItem( bEscRel
) );
184 switch (m_xLB_POSITION
->get_active())
186 case POS_TOP
: nVal
=0;break;
187 case POS_MIDDLE
: nVal
=5000;break;
188 case POS_BOTTOM
: nVal
=10000;break;
190 _rOutAttrs
->Put( SdrCaptionEscRelItem( nVal
) );
194 if (m_xMF_BY
->get_value_changed_from_saved())
196 eUnit
= pPool
->GetMetric( GetWhich( SDRATTR_CAPTIONESCABS
) );
197 _rOutAttrs
->Put( SdrCaptionEscAbsItem( GetCoreValue(*m_xMF_BY
, eUnit
) ) );
201 bFitLineLen
= m_xCB_OPTIMAL
->get_active();
202 _rOutAttrs
->Put( SdrCaptionFitLineLenItem( bFitLineLen
) );
206 if (m_xMF_LENGTH
->get_value_changed_from_saved())
208 eUnit
= pPool
->GetMetric( GetWhich( SDRATTR_CAPTIONLINELEN
) );
209 _rOutAttrs
->Put( SdrCaptionLineLenItem( GetCoreValue(*m_xMF_LENGTH
, eUnit
) ) );
213 //NYI-------------the angles have to be added here!!! XXX----------------------
218 void SvxCaptionTabPage::Reset( const SfxItemSet
* )
221 //------------set metric-----------------------------
223 FieldUnit eFUnit
= GetModuleFieldUnit( rOutAttrs
);
230 eFUnit
= FieldUnit::MM
;
232 default: ;//prevent warning
234 SetFieldUnit( *m_xMF_SPACING
, eFUnit
);
235 SetFieldUnit( *m_xMF_BY
, eFUnit
);
236 SetFieldUnit( *m_xMF_LENGTH
, eFUnit
);
238 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
239 DBG_ASSERT( pPool
, "Where is the pool?" );
244 nWhich
= GetWhich( SDRATTR_CAPTIONESCABS
);
245 eUnit
= pPool
->GetMetric( nWhich
);
246 nEscAbs
= static_cast<const SdrCaptionEscAbsItem
&>( rOutAttrs
.Get( nWhich
) ).GetValue();
247 SetMetricValue( *m_xMF_BY
, nEscAbs
, eUnit
);
248 nEscAbs
= m_xMF_BY
->get_value(FieldUnit::NONE
);
250 nWhich
= GetWhich( SDRATTR_CAPTIONESCREL
);
251 nEscRel
= static_cast<long>(static_cast<const SdrCaptionEscRelItem
&>( rOutAttrs
.Get( nWhich
) ).GetValue());
253 //------- line length ----------
254 nWhich
= GetWhich( SDRATTR_CAPTIONLINELEN
);
255 eUnit
= pPool
->GetMetric( nWhich
);
256 nLineLen
= static_cast<const SdrCaptionLineLenItem
&>( rOutAttrs
.Get( nWhich
) ).GetValue();
257 SetMetricValue( *m_xMF_LENGTH
, nLineLen
, eUnit
);
258 nLineLen
= m_xMF_LENGTH
->get_value(FieldUnit::NONE
);
260 //------- distance to box ----------
261 nWhich
= GetWhich( SDRATTR_CAPTIONGAP
);
262 eUnit
= pPool
->GetMetric( nWhich
);
263 nGap
= static_cast<const SdrCaptionGapItem
&>( rOutAttrs
.Get( nWhich
) ).GetValue();
264 SetMetricValue( *m_xMF_SPACING
, nGap
, eUnit
);
265 nGap
= m_xMF_SPACING
->get_value(FieldUnit::NONE
);
267 nCaptionType
= static_cast<const SdrCaptionTypeItem
&>( rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONTYPE
) ) ).GetValue();
268 bFitLineLen
= static_cast<const SfxBoolItem
&>( rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONFITLINELEN
) ) ).GetValue();
269 nEscDir
= static_cast<const SdrCaptionEscDirItem
&>( rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONESCDIR
) ) ).GetValue();
270 bEscRel
= static_cast<const SfxBoolItem
&>( rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONESCISREL
) ) ).GetValue();
272 // special treatment!!! XXX
273 if( nCaptionType
==SdrCaptionType::Type1
)
277 case SdrCaptionEscDir::Horizontal
: nEscDir
=SdrCaptionEscDir::Vertical
;break;
278 case SdrCaptionEscDir::Vertical
: nEscDir
=SdrCaptionEscDir::Horizontal
;break;
283 nPosition
= POS_MIDDLE
;
284 nExtension
= EXT_OPTIMAL
;
286 m_xMF_SPACING
->set_value(nGap
, FieldUnit::NONE
);
288 if( nEscDir
== SdrCaptionEscDir::Horizontal
)
295 nPosition
= POS_BOTTOM
;
296 nExtension
= EXT_HORIZONTAL
;
300 nExtension
= EXT_FROM_TOP
;
301 m_xMF_BY
->set_value(nEscAbs
, FieldUnit::NONE
);
304 else if( nEscDir
== SdrCaptionEscDir::Vertical
)
311 nPosition
= POS_BOTTOM
;
312 nExtension
= EXT_VERTICAL
;
316 nExtension
= EXT_FROM_LEFT
;
317 m_xMF_BY
->set_value(nEscAbs
, FieldUnit::NONE
);
320 else if( nEscDir
== SdrCaptionEscDir::BestFit
)
322 nExtension
= EXT_OPTIMAL
;
325 m_xCB_OPTIMAL
->set_active(bFitLineLen
);
326 m_xMF_LENGTH
->set_value(nLineLen
, FieldUnit::NONE
);
328 m_xLB_EXTENSION
->set_active(nExtension
);
330 SetupExtension_Impl( nExtension
);
331 m_xCT_CAPTTYPE
->SelectItem( static_cast<int>(nCaptionType
)+1 ); // Enum starts at 0!
332 SetupType_Impl( nCaptionType
);
335 std::unique_ptr
<SfxTabPage
> SvxCaptionTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
,
336 const SfxItemSet
* rOutAttrs
)
338 return std::make_unique
<SvxCaptionTabPage
>(pPage
, pController
, *rOutAttrs
);
341 void SvxCaptionTabPage::SetupExtension_Impl( sal_uInt16 nType
)
348 m_xFT_POSITIONFT
->hide();
349 m_xLB_POSITION
->hide();
350 nEscDir
= SdrCaptionEscDir::BestFit
;
356 m_xFT_POSITIONFT
->hide();
357 m_xLB_POSITION
->hide();
358 nEscDir
= SdrCaptionEscDir::Horizontal
;
364 m_xFT_POSITIONFT
->hide();
365 m_xLB_POSITION
->hide();
366 nEscDir
= SdrCaptionEscDir::Vertical
;
370 m_xLB_POSITION
->clear();
371 for (const OUString
& i
: m_aStrHorzList
)
372 m_xLB_POSITION
->append_text(i
);
373 m_xLB_POSITION
->set_active(nPosition
);
377 m_xFT_POSITIONFT
->show();
378 m_xLB_POSITION
->show();
379 nEscDir
= SdrCaptionEscDir::Horizontal
;
383 m_xLB_POSITION
->clear();
384 for (const OUString
& i
: m_aStrVertList
)
385 m_xLB_POSITION
->append_text(i
);
386 m_xLB_POSITION
->set_active(nPosition
);
390 m_xFT_POSITIONFT
->show();
391 m_xLB_POSITION
->show();
392 nEscDir
= SdrCaptionEscDir::Vertical
;
397 IMPL_LINK(SvxCaptionTabPage
, ExtensionSelectHdl_Impl
, weld::ComboBox
&, rListBox
, void)
399 if (&rListBox
== m_xLB_EXTENSION
.get())
401 SetupExtension_Impl(m_xLB_EXTENSION
->get_active());
405 IMPL_LINK(SvxCaptionTabPage
, PositionSelectHdl_Impl
, weld::ComboBox
&, rListBox
, void)
407 if (&rListBox
== m_xLB_POSITION
.get())
409 nPosition
= m_xLB_POSITION
->get_active();
413 IMPL_LINK( SvxCaptionTabPage
, LineOptHdl_Impl
, weld::ToggleButton
&, rButton
, void )
415 if (&rButton
== m_xCB_OPTIMAL
.get())
417 if (m_xCB_OPTIMAL
->get_active() || !m_xCB_OPTIMAL
->get_sensitive())
419 m_xFT_LENGTHFT
->set_sensitive(false);
420 m_xMF_LENGTH
->set_sensitive(false);
424 m_xFT_LENGTHFT
->set_sensitive(true);
425 m_xMF_LENGTH
->set_sensitive(true);
430 IMPL_LINK_NOARG(SvxCaptionTabPage
, SelectCaptTypeHdl_Impl
, SvtValueSet
*, void)
432 SetupType_Impl( static_cast<SdrCaptionType
>(m_xCT_CAPTTYPE
->GetSelectedItemId()) );
435 void SvxCaptionTabPage::SetupType_Impl( SdrCaptionType nType
)
439 case SdrCaptionType::Type1
:
440 case SdrCaptionType::Type2
:
441 m_xFT_LENGTHFT
->set_sensitive(false);
442 m_xCB_OPTIMAL
->set_sensitive(false);
443 LineOptHdl_Impl(*m_xCB_OPTIMAL
);
445 case SdrCaptionType::Type3
:
446 case SdrCaptionType::Type4
:
447 m_xFT_LENGTHFT
->set_sensitive(true);
448 m_xCB_OPTIMAL
->set_sensitive(true);
449 LineOptHdl_Impl(*m_xCB_OPTIMAL
);
454 void SvxCaptionTabPage::FillValueSet()
456 m_xCT_CAPTTYPE
->SetItemImage(BMP_CAPTTYPE_1
, m_aBmpCapTypes
[0] );
457 m_xCT_CAPTTYPE
->SetItemImage(BMP_CAPTTYPE_2
, m_aBmpCapTypes
[1] );
458 m_xCT_CAPTTYPE
->SetItemImage(BMP_CAPTTYPE_3
, m_aBmpCapTypes
[2] );
461 SvxCaptionTabDialog::SvxCaptionTabDialog(weld::Window
* pParent
, const SdrView
* pSdrView
,
462 SvxAnchorIds nAnchorTypes
)
463 : SfxTabDialogController(pParent
, "cui/ui/calloutdialog.ui", "CalloutDialog")
465 , nAnchorCtrls(nAnchorTypes
)
467 assert(pView
); // No valid View transferred!
469 //different positioning page in Writer
470 if (nAnchorCtrls
& (SvxAnchorIds::Paragraph
| SvxAnchorIds::Character
| SvxAnchorIds::Page
| SvxAnchorIds::Fly
))
472 AddTabPage("RID_SVXPAGE_SWPOSSIZE", SvxSwPosSizeTabPage::Create
,
473 SvxSwPosSizeTabPage::GetRanges
);
474 RemoveTabPage("RID_SVXPAGE_POSITION_SIZE");
478 AddTabPage("RID_SVXPAGE_POSITION_SIZE", SvxPositionSizeTabPage::Create
,
479 SvxPositionSizeTabPage::GetRanges
);
480 RemoveTabPage("RID_SVXPAGE_SWPOSSIZE");
482 AddTabPage("RID_SVXPAGE_CAPTION", SvxCaptionTabPage::Create
,
483 SvxCaptionTabPage::GetRanges
);
486 void SvxCaptionTabDialog::PageCreated(const OString
& rId
, SfxTabPage
&rPage
)
488 if (rId
== "RID_SVXPAGE_POSITION_SIZE")
490 static_cast<SvxPositionSizeTabPage
&>( rPage
).SetView( pView
);
491 static_cast<SvxPositionSizeTabPage
&>( rPage
).Construct();
492 if( nAnchorCtrls
& SvxAnchorIds::NoResize
)
493 static_cast<SvxPositionSizeTabPage
&>( rPage
).DisableResize();
495 if( nAnchorCtrls
& SvxAnchorIds::NoProtect
)
496 static_cast<SvxPositionSizeTabPage
&>( rPage
).DisableProtect();
498 else if (rId
== "RID_SVXPAGE_SWPOSSIZE")
500 SvxSwPosSizeTabPage
& rSwPage
= static_cast<SvxSwPosSizeTabPage
&>(rPage
);
501 rSwPage
.EnableAnchorTypes(nAnchorCtrls
);
502 rSwPage
.SetValidateFramePosLink( aValidateLink
);
504 else if (rId
== "RID_SVXPAGE_CAPTION")
506 static_cast<SvxCaptionTabPage
&>( rPage
).SetView( pView
);
507 static_cast<SvxCaptionTabPage
&>( rPage
).Construct();
511 void SvxCaptionTabDialog::SetValidateFramePosLink( const Link
<SvxSwFrameValidation
&,void>& rLink
)
513 aValidateLink
= rLink
;
516 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */