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 <tools/urlobj.hxx>
21 #include <vcl/settings.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/weld.hxx>
24 #include <unotools/pathoptions.hxx>
25 #include <sfx2/app.hxx>
26 #include <sfx2/module.hxx>
27 #include <sfx2/filedlghelper.hxx>
28 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
30 #include <strings.hrc>
32 #include <svx/xlnwtit.hxx>
33 #include <svx/xlndsit.hxx>
34 #include <svx/xlnclit.hxx>
35 #include <svx/xpool.hxx>
36 #include <svx/xtable.hxx>
38 #include <svx/drawitem.hxx>
39 #include <cuitabline.hxx>
40 #include <dlgname.hxx>
41 #include <defdlgname.hxx>
42 #include <svx/svxdlg.hxx>
43 #include <dialmgr.hxx>
44 #include <svx/dlgutil.hxx>
45 #include <svx/dialmgr.hxx>
46 #include <svx/dialogs.hrc>
47 #include <svx/strings.hrc>
48 #include <svx/svxids.hrc>
49 #include <cuitabarea.hxx>
50 #include <svtools/unitconv.hxx>
52 #define XOUT_WIDTH 150
54 using namespace com::sun::star
;
57 SvxLineDefTabPage::SvxLineDefTabPage(TabPageParent pParent
, const SfxItemSet
& rInAttrs
)
58 : SfxTabPage(pParent
, "cui/ui/linestyletabpage.ui", "LineStylePage", &rInAttrs
)
60 , aXLineAttr(rInAttrs
.GetPool())
61 , rXLSet(aXLineAttr
.GetItemSet())
62 , pnDashListState(nullptr)
66 , m_xLbLineStyles(new SvxLineLB(m_xBuilder
->weld_combo_box("LB_LINESTYLES")))
67 , m_xLbType1(m_xBuilder
->weld_combo_box("LB_TYPE_1"))
68 , m_xLbType2(m_xBuilder
->weld_combo_box("LB_TYPE_2"))
69 , m_xNumFldNumber1(m_xBuilder
->weld_spin_button("NUM_FLD_1"))
70 , m_xNumFldNumber2(m_xBuilder
->weld_spin_button("NUM_FLD_2"))
71 , m_xMtrLength1(m_xBuilder
->weld_metric_spin_button("MTR_FLD_LENGTH_1", FieldUnit::CM
))
72 , m_xMtrLength2(m_xBuilder
->weld_metric_spin_button("MTR_FLD_LENGTH_2", FieldUnit::CM
))
73 , m_xMtrDistance(m_xBuilder
->weld_metric_spin_button("MTR_FLD_DISTANCE", FieldUnit::CM
))
74 , m_xCbxSynchronize(m_xBuilder
->weld_check_button("CBX_SYNCHRONIZE"))
75 , m_xBtnAdd(m_xBuilder
->weld_button("BTN_ADD"))
76 , m_xBtnModify(m_xBuilder
->weld_button("BTN_MODIFY"))
77 , m_xBtnDelete(m_xBuilder
->weld_button("BTN_DELETE"))
78 , m_xBtnLoad(m_xBuilder
->weld_button("BTN_LOAD"))
79 , m_xBtnSave(m_xBuilder
->weld_button("BTN_SAVE"))
80 , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder
, "CTL_PREVIEW", m_aCtlPreview
))
82 // this page needs ExchangeSupport
86 eFUnit
= GetModuleFieldUnit( rInAttrs
);
92 eFUnit
= FieldUnit::MM
;
94 default: ; //prevent warning
96 SetFieldUnit(*m_xMtrDistance
, eFUnit
);
97 SetFieldUnit(*m_xMtrLength1
, eFUnit
);
98 SetFieldUnit(*m_xMtrLength2
, eFUnit
);
100 // determine PoolUnit
101 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
102 DBG_ASSERT( pPool
, "Where is the pool?" );
103 ePoolUnit
= pPool
->GetMetric( SID_ATTR_LINE_WIDTH
);
105 rXLSet
.Put( XLineStyleItem(drawing::LineStyle_DASH
) );
106 rXLSet
.Put( XLineWidthItem(XOUT_WIDTH
) );
107 rXLSet
.Put( XLineDashItem( OUString(), XDash( css::drawing::DashStyle_RECT
, 3, 7, 2, 40, 15 ) ) );
108 rXLSet
.Put( XLineColorItem(OUString(), COL_BLACK
) );
111 m_aCtlPreview
.SetLineAttributes(aXLineAttr
.GetItemSet());
113 m_xBtnAdd
->connect_clicked(LINK(this, SvxLineDefTabPage
, ClickAddHdl_Impl
));
114 m_xBtnModify
->connect_clicked(LINK(this, SvxLineDefTabPage
, ClickModifyHdl_Impl
));
115 m_xBtnDelete
->connect_clicked(LINK(this, SvxLineDefTabPage
, ClickDeleteHdl_Impl
));
116 m_xBtnLoad
->connect_clicked(LINK(this, SvxLineDefTabPage
, ClickLoadHdl_Impl
));
117 m_xBtnSave
->connect_clicked(LINK(this, SvxLineDefTabPage
, ClickSaveHdl_Impl
));
119 m_xNumFldNumber1
->connect_value_changed(LINK(this, SvxLineDefTabPage
, ChangeNumber1Hdl_Impl
));
120 m_xNumFldNumber2
->connect_value_changed(LINK(this, SvxLineDefTabPage
, ChangeNumber2Hdl_Impl
));
121 m_xLbLineStyles
->connect_changed(LINK(this, SvxLineDefTabPage
, SelectLinestyleListBoxHdl_Impl
));
123 // #i122042# switch off default adding of 'none' and 'solid' entries
124 // for this ListBox; we want to select only editable/dashed styles
125 m_xLbLineStyles
->setAddStandardFields(false);
127 // absolute (in mm) or relative (in %)
128 m_xCbxSynchronize
->connect_toggled(LINK(this, SvxLineDefTabPage
, ChangeMetricHdl_Impl
));
130 // preview must be updated when there's something changed
131 Link
<weld::ComboBox
&, void> aLink
= LINK(this, SvxLineDefTabPage
, SelectTypeListBoxHdl_Impl
);
132 m_xLbType1
->connect_changed(aLink
);
133 m_xLbType2
->connect_changed(aLink
);
134 Link
<weld::MetricSpinButton
&,void> aLink2
= LINK( this, SvxLineDefTabPage
, ChangePreviewHdl_Impl
);
135 m_xMtrLength1
->connect_value_changed(aLink2
);
136 m_xMtrLength2
->connect_value_changed(aLink2
);
137 m_xMtrDistance
->connect_value_changed(aLink2
);
142 SvxLineDefTabPage::~SvxLineDefTabPage()
147 void SvxLineDefTabPage::dispose()
149 m_xCtlPreview
.reset();
150 m_xLbLineStyles
.reset();
151 SfxTabPage::dispose();
154 void SvxLineDefTabPage::Construct()
156 // Line style fill; do *not* add default fields here
157 m_xLbLineStyles
->Fill( pDashList
);
160 void SvxLineDefTabPage::ActivatePage( const SfxItemSet
& )
162 if( nDlgType
== 0 ) // area dialog
164 // ActivatePage() is called before the dialog receives PageCreated() !!!
167 if (*pPageType
== PageType::Gradient
&&
170 m_xLbLineStyles
->set_active(*pPosDashLb
);
172 // so that a possibly existing line style is discarded
173 SelectLinestyleHdl_Impl( nullptr );
175 // determining (and possibly cutting) the name
176 // and displaying it in the GroupBox
177 // OUString aString( CuiResId( RID_SVXSTR_TABLE ) );
179 INetURLObject
aURL( pDashList
->GetPath() );
181 aURL
.Append( pDashList
->GetName() );
182 DBG_ASSERT( aURL
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
184 *pPageType
= PageType::Area
; // 2
185 *pPosDashLb
= LISTBOX_ENTRY_NOTFOUND
;
191 DeactivateRC
SvxLineDefTabPage::DeactivatePage( SfxItemSet
* _pSet
)
196 FillItemSet( _pSet
);
198 return DeactivateRC::LeavePage
;
201 void SvxLineDefTabPage::CheckChanges_Impl()
203 // is here used to NOT lose changes
204 //css::drawing::DashStyle eXDS;
206 if( m_xNumFldNumber1
->get_value_changed_from_saved() ||
207 m_xMtrLength1
->get_value_changed_from_saved() ||
208 m_xLbType1
->get_value_changed_from_saved() ||
209 m_xNumFldNumber2
->get_value_changed_from_saved() ||
210 m_xMtrLength2
->get_value_changed_from_saved() ||
211 m_xLbType2
->get_value_changed_from_saved() ||
212 m_xMtrDistance
->get_value_changed_from_saved() )
214 std::unique_ptr
<weld::MessageDialog
> xMessDlg(Application::CreateMessageDialog(GetDialogFrameWeld(),
215 VclMessageType::Warning
, VclButtonsType::Cancel
,
216 CuiResId(RID_SVXSTR_ASK_CHANGE_LINESTYLE
)));
217 xMessDlg
->set_title(SvxResId(RID_SVXSTR_LINESTYLE
));
218 xMessDlg
->add_button(CuiResId(RID_SVXSTR_CHANGE
), RET_BTN_1
);
219 xMessDlg
->add_button(CuiResId(RID_SVXSTR_ADD
), RET_BTN_2
);
221 short nRet
= xMessDlg
->run();
227 ClickModifyHdl_Impl(*m_xBtnModify
);
233 ClickAddHdl_Impl(*m_xBtnAdd
);
242 int nPos
= m_xLbLineStyles
->get_active();
250 bool SvxLineDefTabPage::FillItemSet( SfxItemSet
* rAttrs
)
252 if( nDlgType
== 0 ) // line dialog
254 if( *pPageType
== PageType::Hatch
)
258 OUString
aString(m_xLbLineStyles
->get_active_text());
259 rAttrs
->Put( XLineStyleItem( drawing::LineStyle_DASH
) );
260 rAttrs
->Put( XLineDashItem( aString
, aDash
) );
267 void SvxLineDefTabPage::Reset( const SfxItemSet
* rAttrs
)
269 if( rAttrs
->GetItemState( GetWhich( XATTR_LINESTYLE
) ) != SfxItemState::DONTCARE
)
271 drawing::LineStyle eXLS
= static_cast<const XLineStyleItem
&>( rAttrs
->Get( GetWhich( XATTR_LINESTYLE
) ) ).GetValue();
275 case drawing::LineStyle_NONE
:
276 case drawing::LineStyle_SOLID
:
277 m_xLbLineStyles
->set_active(0);
279 case drawing::LineStyle_DASH
:
281 const XLineDashItem
& rDashItem
= rAttrs
->Get( XATTR_LINEDASH
);
282 aDash
= rDashItem
.GetDashValue();
284 m_xLbLineStyles
->set_active(-1);
285 m_xLbLineStyles
->set_active_text(rDashItem
.GetName());
292 SelectLinestyleHdl_Impl( nullptr );
294 // determine button state
295 if( pDashList
->Count() )
297 m_xBtnModify
->set_sensitive(true);
298 m_xBtnDelete
->set_sensitive(true);
299 m_xBtnSave
->set_sensitive(true);
303 m_xBtnModify
->set_sensitive(false);
304 m_xBtnDelete
->set_sensitive(false);
305 m_xBtnSave
->set_sensitive(false);
309 VclPtr
<SfxTabPage
> SvxLineDefTabPage::Create(TabPageParent pParent
, const SfxItemSet
* rOutAttrs
)
311 return VclPtr
<SvxLineDefTabPage
>::Create(pParent
, *rOutAttrs
);
314 IMPL_LINK(SvxLineDefTabPage
, SelectLinestyleListBoxHdl_Impl
, weld::ComboBox
&, rListBox
, void)
316 SelectLinestyleHdl_Impl(&rListBox
);
319 void SvxLineDefTabPage::SelectLinestyleHdl_Impl(const weld::ComboBox
* p
)
321 if(pDashList
->Count())
323 int nTmp
= m_xLbLineStyles
->get_active();
326 OSL_ENSURE(false, "OOps, non-existent LineDash selected (!)");
330 aDash
= pDashList
->GetDash( nTmp
)->GetDash();
334 rXLSet
.Put( XLineDashItem( OUString(), aDash
) );
337 m_aCtlPreview
.SetLineAttributes(aXLineAttr
.GetItemSet());
338 m_aCtlPreview
.Invalidate();
340 // Is not set before, in order to take the new style
341 // only if there was an entry selected in the ListBox.
342 // If it was called via Reset(), then p is == NULL
344 *pPageType
= PageType::Hatch
;
348 IMPL_LINK_NOARG(SvxLineDefTabPage
, ChangePreviewHdl_Impl
, weld::MetricSpinButton
&, void)
351 m_aCtlPreview
.Invalidate();
354 IMPL_LINK_NOARG(SvxLineDefTabPage
, ChangeNumber1Hdl_Impl
, weld::SpinButton
&, void)
356 if (m_xNumFldNumber1
->get_value() == 0)
358 m_xNumFldNumber2
->set_min(1);
362 m_xNumFldNumber2
->set_min(0);
365 ChangePreviewHdl_Impl(*m_xMtrLength1
);
368 IMPL_LINK_NOARG(SvxLineDefTabPage
, ChangeNumber2Hdl_Impl
, weld::SpinButton
&, void)
370 if (m_xNumFldNumber2
->get_value() == 0)
372 m_xNumFldNumber1
->set_min(1);
376 m_xNumFldNumber1
->set_min(0);
379 ChangePreviewHdl_Impl(*m_xMtrLength1
);
382 IMPL_LINK( SvxLineDefTabPage
, ChangeMetricHdl_Impl
, weld::ToggleButton
&, r
, void)
384 ChangeMetricHdl_Impl(&r
);
387 void SvxLineDefTabPage::ChangeMetricHdl_Impl(const weld::ToggleButton
* p
)
389 if( !m_xCbxSynchronize
->get_active() && m_xMtrLength1
->get_unit() != eFUnit
)
391 long nTmp1
, nTmp2
, nTmp3
;
393 // was changed with Control
396 nTmp1
= GetCoreValue( *m_xMtrLength1
, ePoolUnit
) * XOUT_WIDTH
/ 100;
397 nTmp2
= GetCoreValue( *m_xMtrLength2
, ePoolUnit
) * XOUT_WIDTH
/ 100;
398 nTmp3
= GetCoreValue( *m_xMtrDistance
, ePoolUnit
) * XOUT_WIDTH
/ 100;
402 nTmp1
= GetCoreValue( *m_xMtrLength1
, ePoolUnit
);
403 nTmp2
= GetCoreValue( *m_xMtrLength2
, ePoolUnit
);
404 nTmp3
= GetCoreValue( *m_xMtrDistance
, ePoolUnit
);
406 m_xMtrLength1
->set_digits(2);
407 m_xMtrLength2
->set_digits(2);
408 m_xMtrDistance
->set_digits(2);
411 m_xMtrLength1
->set_unit(eFUnit
);
412 m_xMtrLength2
->set_unit(eFUnit
);
413 m_xMtrDistance
->set_unit(eFUnit
);
415 SetMetricValue( *m_xMtrLength1
, nTmp1
, ePoolUnit
);
416 SetMetricValue( *m_xMtrLength2
, nTmp2
, ePoolUnit
);
417 SetMetricValue( *m_xMtrDistance
, nTmp3
, ePoolUnit
);
419 else if( m_xCbxSynchronize
->get_active() && m_xMtrLength1
->get_unit() != FieldUnit::PERCENT
)
421 long nTmp1
, nTmp2
, nTmp3
;
423 // was changed with Control
426 nTmp1
= GetCoreValue( *m_xMtrLength1
, ePoolUnit
) * 100 / XOUT_WIDTH
;
427 nTmp2
= GetCoreValue( *m_xMtrLength2
, ePoolUnit
) * 100 / XOUT_WIDTH
;
428 nTmp3
= GetCoreValue( *m_xMtrDistance
, ePoolUnit
) * 100 / XOUT_WIDTH
;
432 nTmp1
= GetCoreValue( *m_xMtrLength1
, ePoolUnit
);
433 nTmp2
= GetCoreValue( *m_xMtrLength2
, ePoolUnit
);
434 nTmp3
= GetCoreValue( *m_xMtrDistance
, ePoolUnit
);
437 m_xMtrLength1
->set_digits(0);
438 m_xMtrLength2
->set_digits(0);
439 m_xMtrDistance
->set_digits(0);
441 m_xMtrLength1
->set_unit(FieldUnit::PERCENT
);
442 m_xMtrLength2
->set_unit(FieldUnit::PERCENT
);
443 m_xMtrDistance
->set_unit(FieldUnit::PERCENT
);
445 SetMetricValue( *m_xMtrLength1
, nTmp1
, ePoolUnit
);
446 SetMetricValue( *m_xMtrLength2
, nTmp2
, ePoolUnit
);
447 SetMetricValue( *m_xMtrDistance
, nTmp3
, ePoolUnit
);
450 SelectTypeHdl_Impl( nullptr );
453 IMPL_LINK( SvxLineDefTabPage
, SelectTypeListBoxHdl_Impl
, weld::ComboBox
&, rListBox
, void )
455 SelectTypeHdl_Impl(&rListBox
);
458 void SvxLineDefTabPage::SelectTypeHdl_Impl(const weld::ComboBox
* p
)
460 if (p
== m_xLbType1
.get() || !p
)
462 if (m_xLbType1
->get_active() == 0)
464 m_xMtrLength1
->set_sensitive(false);
465 m_xMtrLength1
->set_text("");
467 else if (!m_xMtrLength1
->get_sensitive())
469 m_xMtrLength1
->set_sensitive(true);
470 m_xMtrLength1
->reformat();
474 if (p
== m_xLbType2
.get() || !p
)
476 if (m_xLbType2
->get_active() == 0)
478 m_xMtrLength2
->set_sensitive(false);
479 m_xMtrLength2
->set_text("");
481 else if (!m_xMtrLength2
->get_sensitive())
483 m_xMtrLength2
->set_sensitive(true);
484 m_xMtrLength2
->reformat();
487 ChangePreviewHdl_Impl(*m_xMtrLength1
);
490 IMPL_LINK_NOARG(SvxLineDefTabPage
, ClickAddHdl_Impl
, weld::Button
&, void)
492 OUString
aNewName(SvxResId(RID_SVXSTR_LINESTYLE
));
493 OUString
aDesc(CuiResId(RID_SVXSTR_DESC_LINESTYLE
));
496 long nCount
= pDashList
->Count();
498 bool bDifferent
= false;
500 while ( !bDifferent
)
502 aName
= aNewName
+ " " + OUString::number( j
++ );
505 for ( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
506 if ( aName
== pDashList
->GetDash( i
)->GetName() )
510 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
511 ScopedVclPtr
<AbstractSvxNameDialog
> pDlg(pFact
->CreateSvxNameDialog(GetDialogFrameWeld(), aName
, aDesc
));
514 while ( bLoop
&& pDlg
->Execute() == RET_OK
)
516 pDlg
->GetName( aName
);
519 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
521 if( aName
== pDashList
->GetDash( i
)->GetName() )
530 long nDashCount
= pDashList
->Count();
531 pDashList
->Insert( std::make_unique
<XDashEntry
>(aDash
, aName
), nDashCount
);
532 m_xLbLineStyles
->Append( *pDashList
->GetDash(nDashCount
), pDashList
->GetUiBitmap(nDashCount
) );
534 m_xLbLineStyles
->set_active(m_xLbLineStyles
->get_count() - 1);
536 *pnDashListState
|= ChangeType::MODIFIED
;
538 *pPageType
= PageType::Hatch
;
540 // save values for changes recognition (-> method)
541 m_xNumFldNumber1
->save_value();
542 m_xMtrLength1
->save_value();
543 m_xLbType1
->save_value();
544 m_xNumFldNumber2
->save_value();
545 m_xMtrLength2
->save_value();
546 m_xLbType2
->save_value();
547 m_xMtrDistance
->save_value();
551 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
552 std::unique_ptr
<weld::MessageDialog
> xBox(xBuilder
->weld_message_dialog("DuplicateNameDialog"));
556 pDlg
.disposeAndClear();
558 // determine button state
559 if ( pDashList
->Count() )
561 m_xBtnModify
->set_sensitive(true);
562 m_xBtnDelete
->set_sensitive(true);
563 m_xBtnSave
->set_sensitive(true);
567 IMPL_LINK_NOARG(SvxLineDefTabPage
, ClickModifyHdl_Impl
, weld::Button
&, void)
569 int nPos
= m_xLbLineStyles
->get_active();
572 OUString
aDesc(CuiResId(RID_SVXSTR_DESC_LINESTYLE
));
573 OUString
aName( pDashList
->GetDash( nPos
)->GetName() );
574 OUString aOldName
= aName
;
576 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
577 ScopedVclPtr
<AbstractSvxNameDialog
> pDlg(pFact
->CreateSvxNameDialog(GetDialogFrameWeld(), aName
, aDesc
));
579 long nCount
= pDashList
->Count();
582 while ( bLoop
&& pDlg
->Execute() == RET_OK
)
584 pDlg
->GetName( aName
);
585 bool bDifferent
= true;
587 for( long i
= 0; i
< nCount
&& bDifferent
; i
++ )
589 if( aName
== pDashList
->GetDash( i
)->GetName() &&
599 pDashList
->Replace(std::make_unique
<XDashEntry
>(aDash
, aName
), nPos
);
600 m_xLbLineStyles
->Modify(*pDashList
->GetDash(nPos
), nPos
, pDashList
->GetUiBitmap(nPos
));
602 m_xLbLineStyles
->set_active(nPos
);
604 *pnDashListState
|= ChangeType::MODIFIED
;
606 *pPageType
= PageType::Hatch
;
608 // save values for changes recognition (-> method)
609 m_xNumFldNumber1
->save_value();
610 m_xMtrLength1
->save_value();
611 m_xLbType1
->save_value();
612 m_xNumFldNumber2
->save_value();
613 m_xMtrLength2
->save_value();
614 m_xLbType2
->save_value();
615 m_xMtrDistance
->save_value();
619 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
620 std::unique_ptr
<weld::MessageDialog
> xBox(xBuilder
->weld_message_dialog("DuplicateNameDialog"));
627 IMPL_LINK_NOARG(SvxLineDefTabPage
, ClickDeleteHdl_Impl
, weld::Button
&, void)
629 int nPos
= m_xLbLineStyles
->get_active();
632 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/querydeletelinestyledialog.ui"));
633 std::unique_ptr
<weld::MessageDialog
> xQueryBox(xBuilder
->weld_message_dialog("AskDelLineStyleDialog"));
634 if (xQueryBox
->run() == RET_YES
)
636 pDashList
->Remove(nPos
);
637 m_xLbLineStyles
->remove(nPos
);
638 m_xLbLineStyles
->set_active(0);
640 SelectLinestyleHdl_Impl( nullptr );
641 *pPageType
= PageType::Area
; // style should not be taken
643 *pnDashListState
|= ChangeType::MODIFIED
;
645 ChangePreviewHdl_Impl( *m_xMtrLength1
);
649 // determine button state
650 if ( !pDashList
->Count() )
652 m_xBtnModify
->set_sensitive(false);
653 m_xBtnDelete
->set_sensitive(false);
654 m_xBtnSave
->set_sensitive(false);
658 IMPL_LINK_NOARG(SvxLineDefTabPage
, ClickLoadHdl_Impl
, weld::Button
&, void)
660 sal_uInt16 nReturn
= RET_YES
;
662 if ( *pnDashListState
& ChangeType::MODIFIED
)
664 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/querysavelistdialog.ui"));
665 std::unique_ptr
<weld::MessageDialog
> xBox(xBuilder
->weld_message_dialog("AskSaveList"));
667 nReturn
= xBox
->run();
669 if ( nReturn
== RET_YES
)
673 if ( nReturn
!= RET_CANCEL
)
675 ::sfx2::FileDialogHelper
aDlg(css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
676 FileDialogFlags::NONE
, GetDialogFrameWeld());
677 OUString
aStrFilterType( "*.sod" );
678 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
679 OUString
aPalettePath(SvtPathOptions().GetPalettePath());
681 sal_Int32 nIndex
= 0;
684 aLastDir
= aPalettePath
.getToken(0, ';', nIndex
);
688 INetURLObject
aFile(aLastDir
);
689 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
691 if( aDlg
.Execute() == ERRCODE_NONE
)
693 INetURLObject
aURL( aDlg
.GetPath() );
694 INetURLObject
aPathURL( aURL
);
696 aPathURL
.removeSegment();
697 aPathURL
.removeFinalSlash();
699 XDashListRef pDshLst
= XPropertyList::AsDashList(XPropertyList::CreatePropertyList( XPropertyListType::Dash
, aPathURL
.GetMainURL( INetURLObject::DecodeMechanism::NONE
), "" ));
700 pDshLst
->SetName( aURL
.getName() );
702 if( pDshLst
->Load() )
705 static_cast<SvxLineTabDialog
*>(GetDialogController())->SetNewDashList( pDashList
);
707 m_xLbLineStyles
->clear();
708 m_xLbLineStyles
->Fill( pDashList
);
711 pDashList
->SetName( aURL
.getName() );
713 *pnDashListState
|= ChangeType::CHANGED
;
714 *pnDashListState
&= ~ChangeType::MODIFIED
;
718 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/querynoloadedfiledialog.ui"));
719 std::unique_ptr
<weld::MessageDialog
> xBox(xBuilder
->weld_message_dialog("NoLoadedFileDialog"));
725 // determine button state
726 if ( pDashList
->Count() )
728 m_xBtnModify
->set_sensitive(true);
729 m_xBtnDelete
->set_sensitive(true);
730 m_xBtnSave
->set_sensitive(true);
734 m_xBtnModify
->set_sensitive(false);
735 m_xBtnDelete
->set_sensitive(false);
736 m_xBtnSave
->set_sensitive(false);
740 IMPL_LINK_NOARG(SvxLineDefTabPage
, ClickSaveHdl_Impl
, weld::Button
&, void)
742 ::sfx2::FileDialogHelper
aDlg(css::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE
, FileDialogFlags::NONE
, GetDialogFrameWeld());
743 OUString
aStrFilterType( "*.sod" );
744 aDlg
.AddFilter( aStrFilterType
, aStrFilterType
);
746 OUString
aPalettePath(SvtPathOptions().GetPalettePath());
748 sal_Int32 nIndex
= 0;
751 aLastDir
= aPalettePath
.getToken(0, ';', nIndex
);
755 INetURLObject
aFile(aLastDir
);
756 DBG_ASSERT( aFile
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
758 if( !pDashList
->GetName().isEmpty() )
760 aFile
.Append( pDashList
->GetName() );
762 if( aFile
.getExtension().isEmpty() )
763 aFile
.SetExtension( "sod" );
766 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
767 if ( aDlg
.Execute() == ERRCODE_NONE
)
769 INetURLObject
aURL( aDlg
.GetPath() );
770 INetURLObject
aPathURL( aURL
);
772 aPathURL
.removeSegment();
773 aPathURL
.removeFinalSlash();
775 pDashList
->SetName( aURL
.getName() );
776 pDashList
->SetPath( aPathURL
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
778 if( pDashList
->Save() )
780 *pnDashListState
&= ~ChangeType::MODIFIED
;
784 std::unique_ptr
<weld::Builder
> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/querynosavefiledialog.ui"));
785 std::unique_ptr
<weld::MessageDialog
> xBox(xBuilder
->weld_message_dialog("NoSaveFileDialog"));
791 void SvxLineDefTabPage::FillDash_Impl()
793 css::drawing::DashStyle eXDS
;
795 if (m_xCbxSynchronize
->get_active())
796 eXDS
= css::drawing::DashStyle_RECTRELATIVE
;
798 eXDS
= css::drawing::DashStyle_RECT
;
800 aDash
.SetDashStyle( eXDS
);
801 aDash
.SetDots( static_cast<sal_uInt8
>(m_xNumFldNumber1
->get_value()) );
802 aDash
.SetDotLen( m_xLbType1
->get_active() == 0 ? 0 : GetCoreValue( *m_xMtrLength1
, ePoolUnit
) );
803 aDash
.SetDashes( static_cast<sal_uInt8
>(m_xNumFldNumber2
->get_value()) );
804 aDash
.SetDashLen( m_xLbType2
->get_active() == 0 ? 0 : GetCoreValue( *m_xMtrLength2
, ePoolUnit
) );
805 aDash
.SetDistance( GetCoreValue( *m_xMtrDistance
, ePoolUnit
) );
807 rXLSet
.Put( XLineDashItem( OUString(), aDash
) );
810 m_aCtlPreview
.SetLineAttributes(aXLineAttr
.GetItemSet());
813 void SvxLineDefTabPage::FillDialog_Impl()
815 css::drawing::DashStyle eXDS
= aDash
.GetDashStyle(); // css::drawing::DashStyle_RECT, css::drawing::DashStyle_ROUND
816 if( eXDS
== css::drawing::DashStyle_RECTRELATIVE
)
817 m_xCbxSynchronize
->set_active(true);
819 m_xCbxSynchronize
->set_active(false);
821 m_xNumFldNumber1
->set_value(aDash
.GetDots());
822 SetMetricValue( *m_xMtrLength1
, aDash
.GetDotLen(), ePoolUnit
);
823 m_xLbType1
->set_active(aDash
.GetDotLen() == 0 ? 0 : 1);
824 m_xNumFldNumber2
->set_value(aDash
.GetDashes());
825 SetMetricValue( *m_xMtrLength2
, aDash
.GetDashLen(), ePoolUnit
);
826 m_xLbType2
->set_active(aDash
.GetDashLen() == 0 ? 0 : 1);
827 SetMetricValue( *m_xMtrDistance
, aDash
.GetDistance(), ePoolUnit
);
829 ChangeMetricHdl_Impl(nullptr);
831 // save values for changes recognition (-> method)
832 m_xNumFldNumber1
->save_value();
833 m_xMtrLength1
->save_value();
834 m_xLbType1
->save_value();
835 m_xNumFldNumber2
->save_value();
836 m_xMtrLength2
->save_value();
837 m_xLbType2
->save_value();
838 m_xMtrDistance
->save_value();
841 void SvxLineDefTabPage::DataChanged( const DataChangedEvent
& rDCEvt
)
843 SfxTabPage::DataChanged( rDCEvt
);
845 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) && (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
847 auto nOldSelect
= m_xLbLineStyles
->get_active();
848 m_xLbLineStyles
->clear();
849 m_xLbLineStyles
->Fill(pDashList
);
850 m_xLbLineStyles
->set_active(nOldSelect
);
854 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */