bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / dialog / styledlg.cxx
blob1735f1b28371595616a1dec241c437f6b4929b59
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svl/whiter.hxx>
21 #include <svl/style.hxx>
22 #include <vcl/msgbox.hxx>
24 #include <sfx2/styledlg.hxx>
25 #include <sfx2/mgetempl.hxx>
26 #include <sfx2/sfxresid.hxx>
27 #include <sfx2/sfxuno.hxx>
29 #include "dialog.hrc"
31 // class SfxStyleDialog --------------------------------------------------
33 SfxStyleDialog::SfxStyleDialog
35 vcl::Window* pParent, // Parent
36 const OUString& rID, const OUString& rUIXMLDescription,
37 SfxStyleSheetBase& rStyle // stylesheet to be processed
40 /* [Description]
42 Constructor: Add Manage TabPage, set ExampleSet from style.
45 : SfxTabDialog(pParent, rID, rUIXMLDescription,
46 rStyle.GetItemSet().Clone(), true)
47 , pStyle( &rStyle )
50 // without ParentSupport suppress the standardButton
51 if (!rStyle.HasParentSupport())
52 RemoveStandardButton();
54 m_nOrganizerId = AddTabPage("organizer", SfxManageStyleSheetPage::Create, 0);
56 // With new template always set the management page as the current page
58 if( rStyle.GetName().isEmpty() )
59 SetCurPageId(m_nOrganizerId);
60 else
62 OUString sTxt = OUString(GetText()) + ": " + rStyle.GetName();
63 SetText( sTxt );
65 delete pExampleSet; // in SfxTabDialog::Ctor() already created
66 pExampleSet = &pStyle->GetItemSet();
68 GetCancelButton().SetClickHdl( LINK(this, SfxStyleDialog, CancelHdl) );
73 SfxStyleDialog::~SfxStyleDialog()
75 disposeOnce();
78 /* [Description]
80 Destructor: set ExampleSet to NULL, so that SfxTabDialog does not delete
81 the Set from Style.
84 void SfxStyleDialog::dispose()
86 pExampleSet = 0;
87 pStyle = 0;
88 SfxTabDialog::dispose();
93 void SfxStyleDialog::RefreshInputSet()
95 /* [Description]
97 This is called when <SfxTabPage::DeactivatePage(SfxItemSet *)>
98 returns <SfxTabPage::REFRESH_SET>.
102 SfxTabDialog::RefreshInputSet();
107 short SfxStyleDialog::Ok()
109 /* [Description]
111 Override so that always RET_OK is returned.
115 SfxTabDialog::Ok();
116 return RET_OK;
121 IMPL_LINK( SfxStyleDialog, CancelHdl, Button *, pButton )
123 /* [Description]
125 If the dialogue was canceled, then all selected attributes must be reset
126 again.
130 (void)pButton; //unused
131 SfxTabPage* pPage = GetTabPage(m_nOrganizerId);
133 const SfxItemSet* pInSet = GetInputSetImpl();
134 SfxWhichIter aIter( *pInSet );
135 sal_uInt16 nWhich = aIter.FirstWhich();
137 while ( nWhich )
139 SfxItemState eState = pInSet->GetItemState( nWhich, false );
141 if ( SfxItemState::DEFAULT == eState )
142 pExampleSet->ClearItem( nWhich );
143 else
144 pExampleSet->Put( pInSet->Get( nWhich ) );
145 nWhich = aIter.NextWhich();
148 if ( pPage )
149 pPage->Reset( GetInputSetImpl() );
150 EndDialog( RET_CANCEL );
151 return 0;
154 OUString SfxStyleDialog::GenerateUnusedName(SfxStyleSheetBasePool &rPool)
156 OUString aNoName(SfxResId(STR_NONAME).toString());
157 sal_uInt16 nNo = 1;
158 OUString aNo(aNoName);
159 aNoName += OUString::number(nNo);
160 while (rPool.Find(aNoName))
162 ++nNo;
163 aNoName = aNo;
164 aNoName += OUString::number(nNo);
166 return aNoName;
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */