Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sfx2 / source / dialog / styledlg.cxx
blob2384e2471fb0e4f5734c3ae80bb78fd17cf7deb1
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>
23 #include <sfx2/styledlg.hxx>
24 #include <sfx2/sfxresid.hxx>
25 #include <sfx2/strings.hrc>
27 #include "mgetempl.hxx"
29 /* [Description]
31 Constructor: Add Manage TabPage, set ExampleSet from style.
33 SfxStyleDialogController::SfxStyleDialogController
35 weld::Window* pParent, // Parent
36 const OUString& rUIXMLDescription, const OUString& rID,
37 SfxStyleSheetBase& rStyle // stylesheet to be processed
39 : SfxTabDialogController(pParent, rUIXMLDescription, rID, &rStyle.GetItemSet(), true)
40 , m_rStyle(rStyle)
42 // without ParentSupport suppress the standardButton
43 if (!rStyle.HasParentSupport())
44 RemoveStandardButton();
46 AddTabPage("organizer", SfxManageStyleSheetPage::Create, nullptr);
48 // With new template always set the management page as the current page
49 if (rStyle.GetName().isEmpty())
50 SetCurPageId("organizer");
51 else
53 OUString sTxt = m_xDialog->get_title() + ": " + rStyle.GetName();
54 m_xDialog->set_title(sTxt);
56 m_xExampleSet.reset(&m_rStyle.GetItemSet()); // in SfxTabDialog::Ctor() already created, reset will delete it
58 GetCancelButton().connect_clicked(LINK(this, SfxStyleDialogController, CancelHdl));
61 /* [Description]
63 Destructor: set ExampleSet to NULL, so that SfxTabDialog does not delete
64 the Set from Style.
66 SfxStyleDialogController::~SfxStyleDialogController()
68 // coverity[leaked_storage] - deliberate, ownership is really with m_rStyle
69 m_xExampleSet.release();
72 /* [Description]
74 Override so that always RET_OK is returned.
76 short SfxStyleDialogController::Ok()
78 SfxTabDialogController::Ok();
79 return RET_OK;
82 /* [Description]
84 If the dialogue was canceled, then all selected attributes must be reset
85 again.
87 IMPL_LINK_NOARG(SfxStyleDialogController, CancelHdl, weld::Button&, void)
89 SfxTabPage* pPage = GetTabPage(u"organizer");
91 const SfxItemSet* pInSet = GetInputSetImpl();
92 SfxWhichIter aIter(*pInSet);
93 sal_uInt16 nWhich = aIter.FirstWhich();
95 while (nWhich)
97 SfxItemState eState = aIter.GetItemState(false);
99 if (SfxItemState::DEFAULT == eState)
100 m_xExampleSet->ClearItem(nWhich);
101 else
102 m_xExampleSet->Put(pInSet->Get(nWhich));
103 nWhich = aIter.NextWhich();
106 if (pPage)
107 pPage->Reset(GetInputSetImpl());
109 m_xDialog->response(RET_CANCEL);
112 OUString SfxStyleDialogController::GenerateUnusedName(SfxStyleSheetBasePool &rPool, SfxStyleFamily eFam)
114 OUString aNo(SfxResId(STR_NONAME));
115 sal_uInt16 i = 1;
116 OUString aNoName = aNo + OUString::number(i);
117 while (rPool.Find(aNoName, eFam))
119 ++i;
120 aNoName = aNo + OUString::number(i);
122 return aNoName;
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */