1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
28
SvxLineTabDialog(weld::Window * pParent,const SfxItemSet * pAttr,SdrModel * pModel,const SdrObject * pSdrObj,bool bHasObj)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)
32 , pDrawModel(pModel)
33 , pObj(pSdrObj)
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
45 , nPosDashLb(0)
46 , nPosLineEndLb(0)
47 {
48 bool bLineOnly = false;
49 if( pObj && pObj->GetObjInventor() == SdrInventor::Default )
50 {
51 switch( pObj->GetObjIdentifier() )
52 {
53 case OBJ_LINE:
54 case OBJ_PLIN:
55 case OBJ_PATHLINE:
56 case OBJ_FREELINE:
57 case OBJ_MEASURE:
58 case OBJ_EDGE:
59 bLineOnly = true;
60 break;
61
62 default:
63 break;
64 }
65
66 }
67
68 AddTabPage("RID_SVXPAGE_LINE", SvxLineTabPage::Create, nullptr);
69 if( bLineOnly )
70 AddTabPage("RID_SVXPAGE_SHADOW", SvxShadowTabPage::Create, nullptr);
71 else
72 RemoveTabPage( "RID_SVXPAGE_SHADOW" );
73
74 AddTabPage("RID_SVXPAGE_LINE_DEF", SvxLineDefTabPage::Create, nullptr);
75 AddTabPage("RID_SVXPAGE_LINEEND_DEF", SvxLineEndDefTabPage::Create, nullptr);
76
77 weld::Button& rBtnCancel = GetCancelButton();
78 rBtnCancel.connect_clicked(LINK(this, SvxLineTabDialog, CancelHdlImpl));
79 }
80
SavePalettes()81 void SvxLineTabDialog::SavePalettes()
82 {
83 SfxObjectShell* pShell = SfxObjectShell::Current();
84 if( mpNewColorList != pDrawModel->GetColorList() )
85 {
86 pDrawModel->SetPropertyList( static_cast<XPropertyList *>(mpNewColorList.get()) );
87 if ( pShell )
88 pShell->PutItem( SvxColorListItem( mpNewColorList, SID_COLOR_TABLE ) );
89 pColorList = pDrawModel->GetColorList();
90 }
91 if( pNewDashList != pDrawModel->GetDashList() )
92 {
93 pDrawModel->SetPropertyList( static_cast<XPropertyList *>(pNewDashList.get()) );
94 if ( pShell )
95 pShell->PutItem( SvxDashListItem( pNewDashList, SID_DASH_LIST ) );
96 pDashList = pDrawModel->GetDashList();
97 }
98 if( pNewLineEndList != pDrawModel->GetLineEndList() )
99 {
100 pDrawModel->SetPropertyList( static_cast<XPropertyList *>(pNewLineEndList.get()) );
101 if ( pShell )
102 pShell->PutItem( SvxLineEndListItem( pNewLineEndList, SID_LINEEND_LIST ) );
103 pLineEndList = pDrawModel->GetLineEndList();
104 }
105
106 // Save the tables when they have been changed
107 OUString aPalettePath(SvtPathOptions().GetPalettePath());
108 OUString aPath;
109 sal_Int32 nIndex = 0;
110 do
111 {
112 aPath = aPalettePath.getToken(0, ';', nIndex);
113 }
114 while (nIndex >= 0);
115
116 if( nDashListState & ChangeType::MODIFIED )
117 {
118 pDashList->SetPath( aPath );
119 pDashList->Save();
120
121 // Notify ToolBoxControls
122 if ( pShell )
123 pShell->PutItem( SvxDashListItem( pDashList, SID_DASH_LIST ) );
124 }
125
126 if( nLineEndListState & ChangeType::MODIFIED )
127 {
128 pLineEndList->SetPath( aPath );
129 pLineEndList->Save();
130
131 // Notify ToolBoxControls
132 if ( pShell )
133 pShell->PutItem( SvxLineEndListItem( pLineEndList, SID_LINEEND_LIST ) );
134 }
135
136 if( mnColorListState & ChangeType::MODIFIED )
137 {
138 pColorList->SetPath( aPath );
139 pColorList->Save();
140
141 // Notify ToolBoxControls
142 if ( pShell )
143 pShell->PutItem( SvxColorListItem( pColorList, SID_COLOR_TABLE ) );
144 }
145 }
146
Ok()147 short SvxLineTabDialog::Ok()
148 {
149 SavePalettes();
150
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();
154 }
155
IMPL_LINK_NOARG(SvxLineTabDialog,CancelHdlImpl,weld::Button &,void)156 IMPL_LINK_NOARG(SvxLineTabDialog, CancelHdlImpl, weld::Button&, void)
157 {
158 SavePalettes();
159
160 m_xDialog->response(RET_CANCEL);
161 }
162
PageCreated(const OString & rId,SfxTabPage & rPage)163 void SvxLineTabDialog::PageCreated(const OString& rId, SfxTabPage &rPage)
164 {
165 if (rId == "RID_SVXPAGE_LINE")
166 {
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 );
178 }
179 else if (rId == "RID_SVXPAGE_LINE_DEF")
180 {
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();
187 }
188 else if (rId == "RID_SVXPAGE_LINEEND_DEF")
189 {
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();
197 }
198 else if (rId == "RID_SVXPAGE_SHADOW")
199 {
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 );
204 }
205 }
206
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
208