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 <unotools/pathoptions.hxx>
21 #include <sfx2/objsh.hxx>
22 #include <svx/svxids.hrc>
23 #include <cuitabarea.hxx>
24 #include <cuitabline.hxx>
25 #include <svx/svdmodel.hxx>
26 #include <svx/xtable.hxx>
27 #include <svx/drawitem.hxx>
29 SvxLineTabDialog::SvxLineTabDialog(weld::Window
* pParent
, const SfxItemSet
* pAttr
,
30 SdrModel
* pModel
, const SdrObject
* pSdrObj
, bool bHasObj
)
31 : SfxTabDialogController(pParent
, "cui/ui/linedialog.ui", "LineDialog", pAttr
)
34 , pColorList(pModel
->GetColorList())
35 , mpNewColorList(pModel
->GetColorList())
36 , pDashList(pModel
->GetDashList())
37 , pNewDashList(pModel
->GetDashList())
38 , pLineEndList(pModel
->GetLineEndList())
39 , pNewLineEndList(pModel
->GetLineEndList())
40 , bObjSelected(bHasObj
)
41 , nLineEndListState(ChangeType::NONE
)
42 , nDashListState(ChangeType::NONE
)
43 , mnColorListState(ChangeType::NONE
)
44 , nPageType(PageType::Area
) // We use it here primarily to get the right attributes with FillItemSet
48 bool bLineOnly
= false;
49 if( pObj
&& pObj
->GetObjInventor() == SdrInventor::Default
)
51 switch( pObj
->GetObjIdentifier() )
68 AddTabPage("RID_SVXPAGE_LINE", SvxLineTabPage::Create
, nullptr);
70 AddTabPage("RID_SVXPAGE_SHADOW", SvxShadowTabPage::Create
, nullptr);
72 RemoveTabPage( "RID_SVXPAGE_SHADOW" );
74 AddTabPage("RID_SVXPAGE_LINE_DEF", SvxLineDefTabPage::Create
, nullptr);
75 AddTabPage("RID_SVXPAGE_LINEEND_DEF", SvxLineEndDefTabPage::Create
, nullptr);
77 weld::Button
& rBtnCancel
= GetCancelButton();
78 rBtnCancel
.connect_clicked(LINK(this, SvxLineTabDialog
, CancelHdlImpl
));
81 void SvxLineTabDialog::SavePalettes()
83 SfxObjectShell
* pShell
= SfxObjectShell::Current();
84 if( mpNewColorList
!= pDrawModel
->GetColorList() )
86 pDrawModel
->SetPropertyList( static_cast<XPropertyList
*>(mpNewColorList
.get()) );
88 pShell
->PutItem( SvxColorListItem( mpNewColorList
, SID_COLOR_TABLE
) );
89 pColorList
= pDrawModel
->GetColorList();
91 if( pNewDashList
!= pDrawModel
->GetDashList() )
93 pDrawModel
->SetPropertyList( static_cast<XPropertyList
*>(pNewDashList
.get()) );
95 pShell
->PutItem( SvxDashListItem( pNewDashList
, SID_DASH_LIST
) );
96 pDashList
= pDrawModel
->GetDashList();
98 if( pNewLineEndList
!= pDrawModel
->GetLineEndList() )
100 pDrawModel
->SetPropertyList( static_cast<XPropertyList
*>(pNewLineEndList
.get()) );
102 pShell
->PutItem( SvxLineEndListItem( pNewLineEndList
, SID_LINEEND_LIST
) );
103 pLineEndList
= pDrawModel
->GetLineEndList();
106 // Save the tables when they have been changed
107 OUString
aPalettePath(SvtPathOptions().GetPalettePath());
109 sal_Int32 nIndex
= 0;
112 aPath
= aPalettePath
.getToken(0, ';', nIndex
);
116 if( nDashListState
& ChangeType::MODIFIED
)
118 pDashList
->SetPath( aPath
);
121 // Notify ToolBoxControls
123 pShell
->PutItem( SvxDashListItem( pDashList
, SID_DASH_LIST
) );
126 if( nLineEndListState
& ChangeType::MODIFIED
)
128 pLineEndList
->SetPath( aPath
);
129 pLineEndList
->Save();
131 // Notify ToolBoxControls
133 pShell
->PutItem( SvxLineEndListItem( pLineEndList
, SID_LINEEND_LIST
) );
136 if( mnColorListState
& ChangeType::MODIFIED
)
138 pColorList
->SetPath( aPath
);
141 // Notify ToolBoxControls
143 pShell
->PutItem( SvxColorListItem( pColorList
, SID_COLOR_TABLE
) );
147 short SvxLineTabDialog::Ok()
151 // We return RET_OK if at least one TabPage in FillItemSet() returns sal_True.
152 // We do this by default at the moment.
153 return SfxTabDialogController::Ok();
156 IMPL_LINK_NOARG(SvxLineTabDialog
, CancelHdlImpl
, weld::Button
&, void)
160 m_xDialog
->response(RET_CANCEL
);
163 void SvxLineTabDialog::PageCreated(const OString
& rId
, SfxTabPage
&rPage
)
165 if (rId
== "RID_SVXPAGE_LINE")
167 static_cast<SvxLineTabPage
&>(rPage
).SetDashList( pDashList
);
168 static_cast<SvxLineTabPage
&>(rPage
).SetLineEndList( pLineEndList
);
169 static_cast<SvxLineTabPage
&>(rPage
).SetDlgType( 0 );
170 static_cast<SvxLineTabPage
&>(rPage
).SetPageType( nPageType
);
171 static_cast<SvxLineTabPage
&>(rPage
).SetPosDashLb( &nPosDashLb
);
172 static_cast<SvxLineTabPage
&>(rPage
).SetPosLineEndLb( &nPosLineEndLb
);
173 static_cast<SvxLineTabPage
&>(rPage
).SetDashChgd( &nDashListState
);
174 static_cast<SvxLineTabPage
&>(rPage
).SetLineEndChgd( &nLineEndListState
);
175 static_cast<SvxLineTabPage
&>(rPage
).SetObjSelected( bObjSelected
);
176 static_cast<SvxLineTabPage
&>(rPage
).Construct();
177 static_cast<SvxLineTabPage
&>(rPage
).SetColorChgd( &mnColorListState
);
179 else if (rId
== "RID_SVXPAGE_LINE_DEF")
181 static_cast<SvxLineDefTabPage
&>(rPage
).SetDashList( pDashList
);
182 static_cast<SvxLineDefTabPage
&>(rPage
).SetDlgType( 0 );
183 static_cast<SvxLineDefTabPage
&>(rPage
).SetPageType( &nPageType
);
184 static_cast<SvxLineDefTabPage
&>(rPage
).SetPosDashLb( &nPosDashLb
);
185 static_cast<SvxLineDefTabPage
&>(rPage
).SetDashChgd( &nDashListState
);
186 static_cast<SvxLineDefTabPage
&>(rPage
).Construct();
188 else if (rId
== "RID_SVXPAGE_LINEEND_DEF")
190 static_cast<SvxLineEndDefTabPage
&>(rPage
).SetLineEndList( pLineEndList
);
191 static_cast<SvxLineEndDefTabPage
&>(rPage
).SetPolyObj( pObj
);
192 static_cast<SvxLineEndDefTabPage
&>(rPage
).SetDlgType( 0 );
193 static_cast<SvxLineEndDefTabPage
&>(rPage
).SetPageType( &nPageType
);
194 static_cast<SvxLineEndDefTabPage
&>(rPage
).SetPosLineEndLb( &nPosLineEndLb
);
195 static_cast<SvxLineEndDefTabPage
&>(rPage
).SetLineEndChgd( &nLineEndListState
);
196 static_cast<SvxLineEndDefTabPage
&>(rPage
).Construct();
198 else if (rId
== "RID_SVXPAGE_SHADOW")
200 static_cast<SvxShadowTabPage
&>(rPage
).SetColorList( pColorList
);
201 static_cast<SvxShadowTabPage
&>(rPage
).SetPageType( nPageType
);
202 static_cast<SvxShadowTabPage
&>(rPage
).SetDlgType( 0 );
203 static_cast<SvxShadowTabPage
&>(rPage
).SetColorChgd( &mnColorListState
);
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */