Line data Source code
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 <vcl/msgbox.hxx>
21 : #include <unotools/pathoptions.hxx>
22 : #include <sfx2/app.hxx>
23 : #include <sfx2/objsh.hxx>
24 : #include <svx/dialogs.hrc>
25 :
26 : #include <cuires.hrc>
27 :
28 : #include "cuitabarea.hxx"
29 : #include "cuitabline.hxx"
30 : #include "dlgname.hxx"
31 : #include <dialmgr.hxx>
32 : #include <svx/svdmodel.hxx>
33 : #include <svx/xtable.hxx>
34 : #include "svx/drawitem.hxx"
35 :
36 0 : SvxLineTabDialog::SvxLineTabDialog
37 : (
38 : vcl::Window* pParent,
39 : const SfxItemSet* pAttr,
40 : SdrModel* pModel,
41 : const SdrObject* pSdrObj,
42 : bool bHasObj
43 : ) :
44 :
45 : SfxTabDialog ( pParent
46 : , "LineDialog"
47 : , "cui/ui/linedialog.ui"
48 : , pAttr ),
49 : m_nLineTabPage(0),
50 : m_nShadowTabPage(0),
51 : m_nStyleTabPage(0),
52 : m_nEndTabPage(0),
53 : pDrawModel ( pModel ),
54 : pObj ( pSdrObj ),
55 : rOutAttrs ( *pAttr ),
56 : pColorList ( pModel->GetColorList() ),
57 : mpNewColorList ( pModel->GetColorList() ),
58 : pDashList ( pModel->GetDashList() ),
59 : pNewDashList ( pModel->GetDashList() ),
60 : pLineEndList ( pModel->GetLineEndList() ),
61 : pNewLineEndList ( pModel->GetLineEndList() ),
62 : bObjSelected ( bHasObj ),
63 : nLineEndListState( ChangeType::NONE ),
64 : nDashListState( ChangeType::NONE ),
65 : mnColorListState( ChangeType::NONE ),
66 : nPageType( 0 ), // We use it here primarily to get the right attributes with FillItemSet
67 : nPosDashLb( 0 ),
68 : nPosLineEndLb( 0 ),
69 0 : mbAreaTP( false )
70 : {
71 0 : bool bLineOnly = false;
72 0 : if( pObj && pObj->GetObjInventor() == SdrInventor )
73 : {
74 0 : switch( pObj->GetObjIdentifier() )
75 : {
76 : case OBJ_LINE:
77 : case OBJ_PLIN:
78 : case OBJ_PATHLINE:
79 : case OBJ_FREELINE:
80 : case OBJ_MEASURE:
81 : case OBJ_EDGE:
82 0 : bLineOnly = true;
83 :
84 : default:
85 0 : break;
86 : }
87 :
88 : }
89 :
90 0 : m_nLineTabPage = AddTabPage( "RID_SVXPAGE_LINE", SvxLineTabPage::Create, 0);
91 0 : if( bLineOnly )
92 0 : m_nShadowTabPage = AddTabPage( "RID_SVXPAGE_SHADOW", SvxShadowTabPage::Create, 0 );
93 : else
94 0 : RemoveTabPage( "RID_SVXPAGE_SHADOW" );
95 :
96 0 : m_nStyleTabPage = AddTabPage( "RID_SVXPAGE_LINE_DEF", SvxLineDefTabPage::Create, 0);
97 0 : m_nEndTabPage = AddTabPage( "RID_SVXPAGE_LINEEND_DEF", SvxLineEndDefTabPage::Create, 0);
98 :
99 0 : SetCurPageId( "RID_SVXPAGE_LINE" );
100 :
101 0 : CancelButton& rBtnCancel = GetCancelButton();
102 0 : rBtnCancel.SetClickHdl( LINK( this, SvxLineTabDialog, CancelHdlImpl ) );
103 0 : }
104 :
105 :
106 :
107 0 : void SvxLineTabDialog::SavePalettes()
108 : {
109 0 : SfxObjectShell* pShell = SfxObjectShell::Current();
110 0 : if( mpNewColorList != pDrawModel->GetColorList() )
111 : {
112 0 : pDrawModel->SetPropertyList( static_cast<XPropertyList *>(mpNewColorList.get()) );
113 0 : if ( pShell )
114 0 : pShell->PutItem( SvxColorListItem( mpNewColorList, SID_COLOR_TABLE ) );
115 0 : pColorList = pDrawModel->GetColorList();
116 : }
117 0 : if( pNewDashList != pDrawModel->GetDashList() )
118 : {
119 0 : pDrawModel->SetPropertyList( static_cast<XPropertyList *>(pNewDashList.get()) );
120 0 : if ( pShell )
121 0 : pShell->PutItem( SvxDashListItem( pNewDashList, SID_DASH_LIST ) );
122 0 : pDashList = pDrawModel->GetDashList();
123 : }
124 0 : if( pNewLineEndList != pDrawModel->GetLineEndList() )
125 : {
126 0 : pDrawModel->SetPropertyList( static_cast<XPropertyList *>(pNewLineEndList.get()) );
127 0 : if ( pShell )
128 0 : pShell->PutItem( SvxLineEndListItem( pNewLineEndList, SID_LINEEND_LIST ) );
129 0 : pLineEndList = pDrawModel->GetLineEndList();
130 : }
131 :
132 : // Save the tables when they have been changed
133 0 : OUString aPalettePath(SvtPathOptions().GetPalettePath());
134 0 : OUString aPath;
135 0 : sal_Int32 nIndex = 0;
136 0 : do
137 : {
138 0 : aPath = aPalettePath.getToken(0, ';', nIndex);
139 : }
140 0 : while (nIndex >= 0);
141 :
142 0 : if( nDashListState & ChangeType::MODIFIED )
143 : {
144 0 : pDashList->SetPath( aPath );
145 0 : pDashList->Save();
146 :
147 : // Notify ToolBoxControls
148 0 : if ( pShell )
149 0 : pShell->PutItem( SvxDashListItem( pDashList, SID_DASH_LIST ) );
150 : }
151 :
152 0 : if( nLineEndListState & ChangeType::MODIFIED )
153 : {
154 0 : pLineEndList->SetPath( aPath );
155 0 : pLineEndList->Save();
156 :
157 : // Notify ToolBoxControls
158 0 : if ( pShell )
159 0 : pShell->PutItem( SvxLineEndListItem( pLineEndList, SID_LINEEND_LIST ) );
160 : }
161 :
162 0 : if( mnColorListState & ChangeType::MODIFIED )
163 : {
164 0 : pColorList->SetPath( aPath );
165 0 : pColorList->Save();
166 :
167 : // Notify ToolBoxControls
168 0 : if ( pShell )
169 0 : pShell->PutItem( SvxColorListItem( pColorList, SID_COLOR_TABLE ) );
170 0 : }
171 0 : }
172 :
173 :
174 :
175 0 : short SvxLineTabDialog::Ok()
176 : {
177 0 : SavePalettes();
178 :
179 : // We return RET_OK if at least one TabPage in FillItemSet() returns sal_True.
180 : // We do this by default at the moment.
181 0 : return( SfxTabDialog::Ok() );
182 : }
183 :
184 :
185 :
186 0 : IMPL_LINK_NOARG(SvxLineTabDialog, CancelHdlImpl)
187 : {
188 0 : SavePalettes();
189 :
190 0 : EndDialog( RET_CANCEL );
191 0 : return 0;
192 : }
193 :
194 0 : void SvxLineTabDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
195 : {
196 0 : if( nId == m_nLineTabPage)
197 : {
198 0 : static_cast<SvxLineTabPage&>(rPage).SetColorList( pColorList );
199 0 : static_cast<SvxLineTabPage&>(rPage).SetDashList( pDashList );
200 0 : static_cast<SvxLineTabPage&>(rPage).SetLineEndList( pLineEndList );
201 0 : static_cast<SvxLineTabPage&>(rPage).SetDlgType( 0 );
202 0 : static_cast<SvxLineTabPage&>(rPage).SetPageType( nPageType );
203 0 : static_cast<SvxLineTabPage&>(rPage).SetPosDashLb( &nPosDashLb );
204 0 : static_cast<SvxLineTabPage&>(rPage).SetPosLineEndLb( &nPosLineEndLb );
205 0 : static_cast<SvxLineTabPage&>(rPage).SetDashChgd( &nDashListState );
206 0 : static_cast<SvxLineTabPage&>(rPage).SetLineEndChgd( &nLineEndListState );
207 0 : static_cast<SvxLineTabPage&>(rPage).SetObjSelected( bObjSelected );
208 0 : static_cast<SvxLineTabPage&>(rPage).Construct();
209 0 : static_cast<SvxLineTabPage&>(rPage).SetColorChgd( &mnColorListState );
210 : // ActivatePage() is not called the first time
211 0 : static_cast<SvxLineTabPage&>(rPage).ActivatePage( rOutAttrs );
212 : }
213 0 : else if(nId == m_nStyleTabPage)
214 : {
215 0 : static_cast<SvxLineDefTabPage&>(rPage).SetDashList( pDashList );
216 0 : static_cast<SvxLineDefTabPage&>(rPage).SetDlgType( 0 );
217 0 : static_cast<SvxLineDefTabPage&>(rPage).SetPageType( &nPageType );
218 0 : static_cast<SvxLineDefTabPage&>(rPage).SetPosDashLb( &nPosDashLb );
219 0 : static_cast<SvxLineDefTabPage&>(rPage).SetDashChgd( &nDashListState );
220 0 : static_cast<SvxLineDefTabPage&>(rPage).SetObjSelected( bObjSelected );
221 0 : static_cast<SvxLineDefTabPage&>(rPage).Construct();
222 : }
223 0 : else if(nId == m_nEndTabPage)
224 : {
225 0 : static_cast<SvxLineEndDefTabPage&>(rPage).SetLineEndList( pLineEndList );
226 0 : static_cast<SvxLineEndDefTabPage&>(rPage).SetPolyObj( pObj );
227 0 : static_cast<SvxLineEndDefTabPage&>(rPage).SetDlgType( 0 );
228 0 : static_cast<SvxLineEndDefTabPage&>(rPage).SetPageType( &nPageType );
229 0 : static_cast<SvxLineEndDefTabPage&>(rPage).SetPosLineEndLb( &nPosLineEndLb );
230 0 : static_cast<SvxLineEndDefTabPage&>(rPage).SetLineEndChgd( &nLineEndListState );
231 0 : static_cast<SvxLineEndDefTabPage&>(rPage).SetObjSelected( bObjSelected );
232 0 : static_cast<SvxLineEndDefTabPage&>(rPage).Construct();
233 : }
234 0 : else if (nId == m_nShadowTabPage)
235 : {
236 0 : static_cast<SvxShadowTabPage&>(rPage).SetColorList( pColorList );
237 0 : static_cast<SvxShadowTabPage&>(rPage).SetPageType( nPageType );
238 0 : static_cast<SvxShadowTabPage&>(rPage).SetDlgType( 0 );
239 0 : static_cast<SvxShadowTabPage&>(rPage).SetAreaTP( &mbAreaTP );
240 0 : static_cast<SvxShadowTabPage&>(rPage).SetColorChgd( &mnColorListState );
241 0 : static_cast<SvxShadowTabPage&>(rPage).Construct();
242 : }
243 0 : }
244 :
245 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|