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 <sfx2/app.hxx>
21 #include <sfx2/module.hxx>
22 #include <swpossizetabpage.hxx>
23 #include <vcl/event.hxx>
24 #include <vcl/settings.hxx>
25 #include <svtools/unitconv.hxx>
27 #include <svx/dialogs.hrc>
28 #include <svx/svddef.hxx>
29 #include <svx/sxcaitm.hxx>
30 #include <svx/sxcecitm.hxx>
31 #include <svx/sxcgitm.hxx>
32 #include <svx/sxcllitm.hxx>
33 #include <svx/sxctitm.hxx>
35 #include <svx/dlgutil.hxx>
37 #include <transfrm.hxx>
38 #include <bitmaps.hlst>
40 // define ----------------------------------------------------------------
43 #define EXT_FROM_TOP 1
44 #define EXT_FROM_LEFT 2
45 #define EXT_HORIZONTAL 3
46 #define EXT_VERTICAL 4
52 #define BMP_CAPTTYPE_1 1
53 #define BMP_CAPTTYPE_2 2
54 #define BMP_CAPTTYPE_3 3
56 // static ----------------------------------------------------------------
58 const sal_uInt16
SvxCaptionTabPage::pCaptionRanges
[] =
61 SDRATTR_CAPTIONFIXEDANGLE
,
64 SDRATTR_CAPTIONESCDIR
,
65 SDRATTR_CAPTIONESCISREL
,
66 SDRATTR_CAPTIONESCREL
,
67 SDRATTR_CAPTIONESCABS
,
68 SDRATTR_CAPTIONLINELEN
,
69 SDRATTR_CAPTIONFITLINELEN
,
73 SvxCaptionTabPage::SvxCaptionTabPage(TabPageParent pParent
, const SfxItemSet
& rInAttrs
)
74 : SfxTabPage(pParent
, "cui/ui/calloutpage.ui", "CalloutPage", &rInAttrs
)
75 , nCaptionType(SdrCaptionType::Type1
)
77 , nEscDir(SdrCaptionEscDir::Horizontal
)
87 , m_xMF_SPACING(m_xBuilder
->weld_metric_spin_button("spacing", FieldUnit::MM
))
88 , m_xLB_EXTENSION(m_xBuilder
->weld_combo_box("extension"))
89 , m_xFT_BYFT(m_xBuilder
->weld_label("byft"))
90 , m_xMF_BY(m_xBuilder
->weld_metric_spin_button("by", FieldUnit::MM
))
91 , m_xFT_POSITIONFT(m_xBuilder
->weld_label("positionft"))
92 , m_xLB_POSITION(m_xBuilder
->weld_combo_box("position"))
93 , m_xLineTypes(m_xBuilder
->weld_combo_box("linetypes"))
94 , m_xFT_LENGTHFT(m_xBuilder
->weld_label("lengthft"))
95 , m_xMF_LENGTH(m_xBuilder
->weld_metric_spin_button("length", FieldUnit::MM
))
96 , m_xCB_OPTIMAL(m_xBuilder
->weld_check_button("optimal"))
97 , m_xCT_CAPTTYPE(new SvtValueSet(m_xBuilder
->weld_scrolled_window("valuesetwin")))
98 , m_xCT_CAPTTYPEWin(new weld::CustomWeld(*m_xBuilder
, "valueset", *m_xCT_CAPTTYPE
))
100 Size
aSize(m_xCT_CAPTTYPE
->GetDrawingArea()->get_ref_device().LogicToPixel(Size(187, 38), MapMode(MapUnit::MapAppFont
)));
101 m_xCT_CAPTTYPEWin
->set_size_request(aSize
.Width(), aSize
.Height());
103 assert(m_xLB_POSITION
->get_count() == 6);
104 for (int i
= 0; i
< 3; ++i
)
105 m_aStrHorzList
.push_back(m_xLB_POSITION
->get_text(i
));
106 for (int i
= 3; i
< 6; ++i
)
107 m_aStrVertList
.push_back(m_xLB_POSITION
->get_text(i
));
108 m_xLB_POSITION
->clear();
110 assert(m_xLineTypes
->get_count() == 3);
111 std::vector
<OUString
> aLineTypes
;
112 aLineTypes
.reserve(3);
113 for (int i
= 0; i
< 3; ++i
)
114 aLineTypes
.push_back(m_xLineTypes
->get_text(i
));
116 static_assert(CAPTYPE_BITMAPS_COUNT
== 3, "unexpected");
117 m_aBmpCapTypes
[0] = Image(StockImage::Yes
, RID_SVXBMP_LEGTYP1
);
118 m_aBmpCapTypes
[1] = Image(StockImage::Yes
, RID_SVXBMP_LEGTYP2
);
119 m_aBmpCapTypes
[2] = Image(StockImage::Yes
, RID_SVXBMP_LEGTYP3
);
121 //------------install ValueSet--------------------------
122 m_xCT_CAPTTYPE
->SetStyle( m_xCT_CAPTTYPE
->GetStyle() | WB_ITEMBORDER
| WB_DOUBLEBORDER
| WB_NAMEFIELD
);
123 m_xCT_CAPTTYPE
->SetColCount(5);//XXX
124 m_xCT_CAPTTYPE
->SetLineCount(1);
125 m_xCT_CAPTTYPE
->SetSelectHdl(LINK( this, SvxCaptionTabPage
, SelectCaptTypeHdl_Impl
));
128 m_xCT_CAPTTYPE
->InsertItem(BMP_CAPTTYPE_1
, aImage
, aLineTypes
[0]);
129 m_xCT_CAPTTYPE
->InsertItem(BMP_CAPTTYPE_2
, aImage
, aLineTypes
[1]);
130 m_xCT_CAPTTYPE
->InsertItem(BMP_CAPTTYPE_3
, aImage
, aLineTypes
[2]);
134 m_xLB_EXTENSION
->connect_changed(LINK(this, SvxCaptionTabPage
, ExtensionSelectHdl_Impl
));
135 m_xLB_POSITION
->connect_changed(LINK(this, SvxCaptionTabPage
, PositionSelectHdl_Impl
));
136 m_xCB_OPTIMAL
->connect_toggled(LINK(this, SvxCaptionTabPage
, LineOptHdl_Impl
));
139 SvxCaptionTabPage::~SvxCaptionTabPage()
144 void SvxCaptionTabPage::dispose()
146 m_xCT_CAPTTYPEWin
.reset();
147 m_xCT_CAPTTYPE
.reset();
148 SfxTabPage::dispose();
151 void SvxCaptionTabPage::Construct()
153 // set rectangle and working area
154 DBG_ASSERT( pView
, "No valid View transferred!" );
157 bool SvxCaptionTabPage::FillItemSet( SfxItemSet
* _rOutAttrs
)
159 SfxItemPool
* pPool
= _rOutAttrs
->GetPool();
160 DBG_ASSERT( pPool
, "Where is the pool?" );
164 nCaptionType
= static_cast<SdrCaptionType
>(m_xCT_CAPTTYPE
->GetSelectedItemId()-1);
166 _rOutAttrs
->Put( SdrCaptionTypeItem( nCaptionType
) );
168 if (m_xMF_SPACING
->get_value_changed_from_saved())
170 eUnit
= pPool
->GetMetric( GetWhich( SDRATTR_CAPTIONGAP
) );
171 _rOutAttrs
->Put( SdrCaptionGapItem( GetCoreValue(*m_xMF_SPACING
, eUnit
) ) );
174 // special treatment!!! XXX
175 if( nCaptionType
==SdrCaptionType::Type1
)
179 case SdrCaptionEscDir::Horizontal
: nEscDir
=SdrCaptionEscDir::Vertical
;break;
180 case SdrCaptionEscDir::Vertical
: nEscDir
=SdrCaptionEscDir::Horizontal
;break;
185 _rOutAttrs
->Put( SdrCaptionEscDirItem( nEscDir
) );
187 bEscRel
= m_xLB_POSITION
->get_visible();
188 _rOutAttrs
->Put( SdrCaptionEscIsRelItem( bEscRel
) );
194 switch (m_xLB_POSITION
->get_active())
196 case POS_TOP
: nVal
=0;break;
197 case POS_MIDDLE
: nVal
=5000;break;
198 case POS_BOTTOM
: nVal
=10000;break;
200 _rOutAttrs
->Put( SdrCaptionEscRelItem( nVal
) );
204 if (m_xMF_BY
->get_value_changed_from_saved())
206 eUnit
= pPool
->GetMetric( GetWhich( SDRATTR_CAPTIONESCABS
) );
207 _rOutAttrs
->Put( SdrCaptionEscAbsItem( GetCoreValue(*m_xMF_BY
, eUnit
) ) );
211 bFitLineLen
= m_xCB_OPTIMAL
->get_active();
212 _rOutAttrs
->Put( SdrCaptionFitLineLenItem( bFitLineLen
) );
216 if (m_xMF_LENGTH
->get_value_changed_from_saved())
218 eUnit
= pPool
->GetMetric( GetWhich( SDRATTR_CAPTIONLINELEN
) );
219 _rOutAttrs
->Put( SdrCaptionLineLenItem( GetCoreValue(*m_xMF_LENGTH
, eUnit
) ) );
223 //NYI-------------the angles have to be added here!!! XXX----------------------
228 void SvxCaptionTabPage::Reset( const SfxItemSet
* )
231 //------------set metric-----------------------------
233 FieldUnit eFUnit
= GetModuleFieldUnit( rOutAttrs
);
240 eFUnit
= FieldUnit::MM
;
242 default: ;//prevent warning
244 SetFieldUnit( *m_xMF_SPACING
, eFUnit
);
245 SetFieldUnit( *m_xMF_BY
, eFUnit
);
246 SetFieldUnit( *m_xMF_LENGTH
, eFUnit
);
248 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
249 DBG_ASSERT( pPool
, "Where is the pool?" );
254 nWhich
= GetWhich( SDRATTR_CAPTIONESCABS
);
255 eUnit
= pPool
->GetMetric( nWhich
);
256 nEscAbs
= static_cast<const SdrCaptionEscAbsItem
&>( rOutAttrs
.Get( nWhich
) ).GetValue();
257 SetMetricValue( *m_xMF_BY
, nEscAbs
, eUnit
);
258 nEscAbs
= m_xMF_BY
->get_value(FieldUnit::NONE
);
260 nWhich
= GetWhich( SDRATTR_CAPTIONESCREL
);
261 nEscRel
= static_cast<long>(static_cast<const SdrCaptionEscRelItem
&>( rOutAttrs
.Get( nWhich
) ).GetValue());
263 //------- line length ----------
264 nWhich
= GetWhich( SDRATTR_CAPTIONLINELEN
);
265 eUnit
= pPool
->GetMetric( nWhich
);
266 nLineLen
= static_cast<const SdrCaptionLineLenItem
&>( rOutAttrs
.Get( nWhich
) ).GetValue();
267 SetMetricValue( *m_xMF_LENGTH
, nLineLen
, eUnit
);
268 nLineLen
= m_xMF_LENGTH
->get_value(FieldUnit::NONE
);
270 //------- distance to box ----------
271 nWhich
= GetWhich( SDRATTR_CAPTIONGAP
);
272 eUnit
= pPool
->GetMetric( nWhich
);
273 nGap
= static_cast<const SdrCaptionGapItem
&>( rOutAttrs
.Get( nWhich
) ).GetValue();
274 SetMetricValue( *m_xMF_SPACING
, nGap
, eUnit
);
275 nGap
= m_xMF_SPACING
->get_value(FieldUnit::NONE
);
277 nCaptionType
= static_cast<const SdrCaptionTypeItem
&>( rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONTYPE
) ) ).GetValue();
278 bFitLineLen
= static_cast<const SfxBoolItem
&>( rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONFITLINELEN
) ) ).GetValue();
279 nEscDir
= static_cast<const SdrCaptionEscDirItem
&>( rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONESCDIR
) ) ).GetValue();
280 bEscRel
= static_cast<const SfxBoolItem
&>( rOutAttrs
.Get( GetWhich( SDRATTR_CAPTIONESCISREL
) ) ).GetValue();
282 // special treatment!!! XXX
283 if( nCaptionType
==SdrCaptionType::Type1
)
287 case SdrCaptionEscDir::Horizontal
: nEscDir
=SdrCaptionEscDir::Vertical
;break;
288 case SdrCaptionEscDir::Vertical
: nEscDir
=SdrCaptionEscDir::Horizontal
;break;
293 nPosition
= POS_MIDDLE
;
294 nExtension
= EXT_OPTIMAL
;
296 m_xMF_SPACING
->set_value(nGap
, FieldUnit::NONE
);
298 if( nEscDir
== SdrCaptionEscDir::Horizontal
)
305 nPosition
= POS_BOTTOM
;
306 nExtension
= EXT_HORIZONTAL
;
310 nExtension
= EXT_FROM_TOP
;
311 m_xMF_BY
->set_value(nEscAbs
, FieldUnit::NONE
);
314 else if( nEscDir
== SdrCaptionEscDir::Vertical
)
321 nPosition
= POS_BOTTOM
;
322 nExtension
= EXT_VERTICAL
;
326 nExtension
= EXT_FROM_LEFT
;
327 m_xMF_BY
->set_value(nEscAbs
, FieldUnit::NONE
);
330 else if( nEscDir
== SdrCaptionEscDir::BestFit
)
332 nExtension
= EXT_OPTIMAL
;
335 m_xCB_OPTIMAL
->set_active(bFitLineLen
);
336 m_xMF_LENGTH
->set_value(nLineLen
, FieldUnit::NONE
);
338 m_xLB_EXTENSION
->set_active(nExtension
);
340 SetupExtension_Impl( nExtension
);
341 m_xCT_CAPTTYPE
->SelectItem( static_cast<int>(nCaptionType
)+1 ); // Enum starts at 0!
342 SetupType_Impl( nCaptionType
);
345 VclPtr
<SfxTabPage
> SvxCaptionTabPage::Create(TabPageParent pParent
,
346 const SfxItemSet
* rOutAttrs
)
348 return VclPtr
<SvxCaptionTabPage
>::Create(pParent
, *rOutAttrs
);
351 void SvxCaptionTabPage::SetupExtension_Impl( sal_uInt16 nType
)
358 m_xFT_POSITIONFT
->hide();
359 m_xLB_POSITION
->hide();
360 nEscDir
= SdrCaptionEscDir::BestFit
;
366 m_xFT_POSITIONFT
->hide();
367 m_xLB_POSITION
->hide();
368 nEscDir
= SdrCaptionEscDir::Horizontal
;
374 m_xFT_POSITIONFT
->hide();
375 m_xLB_POSITION
->hide();
376 nEscDir
= SdrCaptionEscDir::Vertical
;
380 m_xLB_POSITION
->clear();
381 for (const OUString
& i
: m_aStrHorzList
)
382 m_xLB_POSITION
->append_text(i
);
383 m_xLB_POSITION
->set_active(nPosition
);
387 m_xFT_POSITIONFT
->show();
388 m_xLB_POSITION
->show();
389 nEscDir
= SdrCaptionEscDir::Horizontal
;
393 m_xLB_POSITION
->clear();
394 for (const OUString
& i
: m_aStrVertList
)
395 m_xLB_POSITION
->append_text(i
);
396 m_xLB_POSITION
->set_active(nPosition
);
400 m_xFT_POSITIONFT
->show();
401 m_xLB_POSITION
->show();
402 nEscDir
= SdrCaptionEscDir::Vertical
;
407 IMPL_LINK(SvxCaptionTabPage
, ExtensionSelectHdl_Impl
, weld::ComboBox
&, rListBox
, void)
409 if (&rListBox
== m_xLB_EXTENSION
.get())
411 SetupExtension_Impl(m_xLB_EXTENSION
->get_active());
415 IMPL_LINK(SvxCaptionTabPage
, PositionSelectHdl_Impl
, weld::ComboBox
&, rListBox
, void)
417 if (&rListBox
== m_xLB_POSITION
.get())
419 nPosition
= m_xLB_POSITION
->get_active();
423 IMPL_LINK( SvxCaptionTabPage
, LineOptHdl_Impl
, weld::ToggleButton
&, rButton
, void )
425 if (&rButton
== m_xCB_OPTIMAL
.get())
427 if (m_xCB_OPTIMAL
->get_active() || !m_xCB_OPTIMAL
->get_sensitive())
429 m_xFT_LENGTHFT
->set_sensitive(false);
430 m_xMF_LENGTH
->set_sensitive(false);
434 m_xFT_LENGTHFT
->set_sensitive(true);
435 m_xMF_LENGTH
->set_sensitive(true);
440 IMPL_LINK_NOARG(SvxCaptionTabPage
, SelectCaptTypeHdl_Impl
, SvtValueSet
*, void)
442 SetupType_Impl( static_cast<SdrCaptionType
>(m_xCT_CAPTTYPE
->GetSelectedItemId()) );
445 void SvxCaptionTabPage::SetupType_Impl( SdrCaptionType nType
)
449 case SdrCaptionType::Type1
:
450 case SdrCaptionType::Type2
:
451 m_xFT_LENGTHFT
->set_sensitive(false);
452 m_xCB_OPTIMAL
->set_sensitive(false);
453 LineOptHdl_Impl(*m_xCB_OPTIMAL
);
455 case SdrCaptionType::Type3
:
456 case SdrCaptionType::Type4
:
457 m_xFT_LENGTHFT
->set_sensitive(true);
458 m_xCB_OPTIMAL
->set_sensitive(true);
459 LineOptHdl_Impl(*m_xCB_OPTIMAL
);
464 void SvxCaptionTabPage::DataChanged( const DataChangedEvent
& rDCEvt
)
466 SfxTabPage::DataChanged( rDCEvt
);
468 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) && (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
471 void SvxCaptionTabPage::FillValueSet()
473 m_xCT_CAPTTYPE
->SetItemImage(BMP_CAPTTYPE_1
, m_aBmpCapTypes
[0] );
474 m_xCT_CAPTTYPE
->SetItemImage(BMP_CAPTTYPE_2
, m_aBmpCapTypes
[1] );
475 m_xCT_CAPTTYPE
->SetItemImage(BMP_CAPTTYPE_3
, m_aBmpCapTypes
[2] );
478 SvxCaptionTabDialog::SvxCaptionTabDialog(weld::Window
* pParent
, const SdrView
* pSdrView
,
479 SvxAnchorIds nAnchorTypes
)
480 : SfxTabDialogController(pParent
, "cui/ui/calloutdialog.ui", "CalloutDialog")
482 , nAnchorCtrls(nAnchorTypes
)
484 assert(pView
); // No valid View transferred!
486 //different positioning page in Writer
487 if (nAnchorCtrls
& (SvxAnchorIds::Paragraph
| SvxAnchorIds::Character
| SvxAnchorIds::Page
| SvxAnchorIds::Fly
))
489 AddTabPage("RID_SVXPAGE_SWPOSSIZE", SvxSwPosSizeTabPage::Create
,
490 SvxSwPosSizeTabPage::GetRanges
);
491 RemoveTabPage("RID_SVXPAGE_POSITION_SIZE");
495 AddTabPage("RID_SVXPAGE_POSITION_SIZE", SvxPositionSizeTabPage::Create
,
496 SvxPositionSizeTabPage::GetRanges
);
497 RemoveTabPage("RID_SVXPAGE_SWPOSSIZE");
499 AddTabPage("RID_SVXPAGE_CAPTION", SvxCaptionTabPage::Create
,
500 SvxCaptionTabPage::GetRanges
);
503 void SvxCaptionTabDialog::PageCreated(const OString
& rId
, SfxTabPage
&rPage
)
505 if (rId
== "RID_SVXPAGE_POSITION_SIZE")
507 static_cast<SvxPositionSizeTabPage
&>( rPage
).SetView( pView
);
508 static_cast<SvxPositionSizeTabPage
&>( rPage
).Construct();
509 if( nAnchorCtrls
& SvxAnchorIds::NoResize
)
510 static_cast<SvxPositionSizeTabPage
&>( rPage
).DisableResize();
512 if( nAnchorCtrls
& SvxAnchorIds::NoProtect
)
513 static_cast<SvxPositionSizeTabPage
&>( rPage
).DisableProtect();
515 else if (rId
== "RID_SVXPAGE_SWPOSSIZE")
517 SvxSwPosSizeTabPage
& rSwPage
= static_cast<SvxSwPosSizeTabPage
&>(rPage
);
518 rSwPage
.EnableAnchorTypes(nAnchorCtrls
);
519 rSwPage
.SetValidateFramePosLink( aValidateLink
);
521 else if (rId
== "RID_SVXPAGE_CAPTION")
523 static_cast<SvxCaptionTabPage
&>( rPage
).SetView( pView
);
524 static_cast<SvxCaptionTabPage
&>( rPage
).Construct();
528 void SvxCaptionTabDialog::SetValidateFramePosLink( const Link
<SvxSwFrameValidation
&,void>& rLink
)
530 aValidateLink
= rLink
;
533 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */