/src/libreoffice/sfx2/source/dialog/styledlg.cxx
Line | Count | Source |
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 <svl/whiter.hxx> |
21 | | #include <svl/style.hxx> |
22 | | |
23 | | #include <sfx2/styledlg.hxx> |
24 | | #include <sfx2/sfxresid.hxx> |
25 | | #include <sfx2/strings.hrc> |
26 | | |
27 | | #include "mgetempl.hxx" |
28 | | |
29 | | #include <vcl/tabs.hrc> |
30 | | #include <vcl/vclenum.hxx> |
31 | | #include <vcl/weld/Dialog.hxx> |
32 | | |
33 | | /* [Description] |
34 | | |
35 | | Constructor: Add Manage TabPage, set ExampleSet from style. |
36 | | */ |
37 | | SfxStyleDialogController::SfxStyleDialogController |
38 | | ( |
39 | | weld::Window* pParent, // Parent |
40 | | const OUString& rUIXMLDescription, const OUString& rID, |
41 | | SfxStyleSheetBase& rStyle // stylesheet to be processed |
42 | | ) |
43 | 0 | : SfxTabDialogController(pParent, rUIXMLDescription, rID, &rStyle.GetItemSet(), true) |
44 | 0 | , m_rStyle(rStyle) |
45 | 0 | { |
46 | | // without ParentSupport suppress the standardButton |
47 | 0 | if (!rStyle.HasParentSupport()) |
48 | 0 | RemoveStandardButton(); |
49 | |
|
50 | 0 | AddTabPage(u"organizer"_ustr, TabResId(RID_TAB_ORGANIZER.aLabel), |
51 | 0 | SfxManageStyleSheetPage::Create, RID_M + RID_TAB_ORGANIZER.sIconName); |
52 | | |
53 | | // With new template always set the management page as the current page |
54 | 0 | if (rStyle.GetName().isEmpty()) |
55 | 0 | SetCurPageId(u"organizer"_ustr); |
56 | 0 | else |
57 | 0 | { |
58 | 0 | OUString sTxt = m_xDialog->get_title() + ": " + rStyle.GetName(); |
59 | 0 | m_xDialog->set_title(sTxt); |
60 | 0 | } |
61 | 0 | m_xExampleSet.reset(&m_rStyle.GetItemSet()); // in SfxTabDialog::Ctor() already created, reset will delete it |
62 | |
|
63 | 0 | GetCancelButton().connect_clicked(LINK(this, SfxStyleDialogController, CancelHdl)); |
64 | 0 | } |
65 | | |
66 | | /* [Description] |
67 | | |
68 | | Destructor: set ExampleSet to NULL, so that SfxTabDialog does not delete |
69 | | the Set from Style. |
70 | | */ |
71 | | SfxStyleDialogController::~SfxStyleDialogController() |
72 | 0 | { |
73 | | // coverity[leaked_storage] - deliberate, ownership is really with m_rStyle |
74 | 0 | m_xExampleSet.release(); |
75 | 0 | } |
76 | | |
77 | | /* [Description] |
78 | | |
79 | | Override so that always RET_OK is returned. |
80 | | */ |
81 | | short SfxStyleDialogController::Ok() |
82 | 0 | { |
83 | 0 | SfxTabDialogController::Ok(); |
84 | | |
85 | | // tdf#171281: Page and List (Pseudo) styles do not support inheritance |
86 | | // via property chips, so applying chip-based resets would discard the |
87 | | // user's modifications instead of restoring parent values. |
88 | 0 | const SfxStyleFamily nFamily = m_rStyle.GetFamily(); |
89 | 0 | if (nFamily != SfxStyleFamily::Pseudo && |
90 | 0 | nFamily != SfxStyleFamily::Page) |
91 | 0 | { |
92 | 0 | SfxItemSet& rStyleSet = m_rStyle.GetItemSet(); |
93 | 0 | for (sal_uInt16 nWhich : m_aInvalidatedWhichIds) |
94 | 0 | rStyleSet.ClearItem(nWhich); |
95 | 0 | } |
96 | |
|
97 | 0 | return RET_OK; |
98 | 0 | } |
99 | | |
100 | | /* [Description] |
101 | | |
102 | | If the dialogue was canceled, then all selected attributes must be reset |
103 | | again. |
104 | | */ |
105 | | IMPL_LINK_NOARG(SfxStyleDialogController, CancelHdl, weld::Button&, void) |
106 | 0 | { |
107 | 0 | SfxTabPage* pPage = GetTabPage(u"organizer"); |
108 | |
|
109 | 0 | const SfxItemSet* pInSet = GetInputSetImpl(); |
110 | 0 | SfxWhichIter aIter(*pInSet); |
111 | 0 | sal_uInt16 nWhich = aIter.FirstWhich(); |
112 | |
|
113 | 0 | while (nWhich) |
114 | 0 | { |
115 | 0 | SfxItemState eState = aIter.GetItemState(false); |
116 | |
|
117 | 0 | if (SfxItemState::DEFAULT == eState) |
118 | 0 | m_xExampleSet->ClearItem(nWhich); |
119 | 0 | else |
120 | 0 | m_xExampleSet->Put(pInSet->Get(nWhich)); |
121 | 0 | nWhich = aIter.NextWhich(); |
122 | 0 | } |
123 | |
|
124 | 0 | if (pPage) |
125 | 0 | pPage->Reset(GetInputSetImpl()); |
126 | |
|
127 | 0 | m_xDialog->response(RET_CANCEL); |
128 | 0 | } |
129 | | |
130 | | OUString SfxStyleDialogController::GenerateUnusedName(SfxStyleSheetBasePool &rPool, SfxStyleFamily eFam) |
131 | 0 | { |
132 | 0 | OUString aNo(SfxResId(STR_NONAME)); |
133 | 0 | sal_uInt16 i = 1; |
134 | 0 | OUString aNoName = aNo + OUString::number(i); |
135 | 0 | while (rPool.Find(aNoName, eFam)) |
136 | 0 | { |
137 | 0 | ++i; |
138 | 0 | aNoName = aNo + OUString::number(i); |
139 | 0 | } |
140 | 0 | return aNoName; |
141 | 0 | } |
142 | | |
143 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |