/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 | | |
31 | | /* [Description] |
32 | | |
33 | | Constructor: Add Manage TabPage, set ExampleSet from style. |
34 | | */ |
35 | | SfxStyleDialogController::SfxStyleDialogController |
36 | | ( |
37 | | weld::Window* pParent, // Parent |
38 | | const OUString& rUIXMLDescription, const OUString& rID, |
39 | | SfxStyleSheetBase& rStyle // stylesheet to be processed |
40 | | ) |
41 | 0 | : SfxTabDialogController(pParent, rUIXMLDescription, rID, &rStyle.GetItemSet(), true) |
42 | 0 | , m_rStyle(rStyle) |
43 | 0 | { |
44 | | // without ParentSupport suppress the standardButton |
45 | 0 | if (!rStyle.HasParentSupport()) |
46 | 0 | RemoveStandardButton(); |
47 | |
|
48 | 0 | AddTabPage(u"organizer"_ustr, TabResId(RID_TAB_ORGANIZER.aLabel), |
49 | 0 | SfxManageStyleSheetPage::Create, RID_M + RID_TAB_ORGANIZER.sIconName); |
50 | | |
51 | | // With new template always set the management page as the current page |
52 | 0 | if (rStyle.GetName().isEmpty()) |
53 | 0 | SetCurPageId(u"organizer"_ustr); |
54 | 0 | else |
55 | 0 | { |
56 | 0 | OUString sTxt = m_xDialog->get_title() + ": " + rStyle.GetName(); |
57 | 0 | m_xDialog->set_title(sTxt); |
58 | 0 | } |
59 | 0 | m_xExampleSet.reset(&m_rStyle.GetItemSet()); // in SfxTabDialog::Ctor() already created, reset will delete it |
60 | |
|
61 | 0 | GetCancelButton().connect_clicked(LINK(this, SfxStyleDialogController, CancelHdl)); |
62 | 0 | } |
63 | | |
64 | | /* [Description] |
65 | | |
66 | | Destructor: set ExampleSet to NULL, so that SfxTabDialog does not delete |
67 | | the Set from Style. |
68 | | */ |
69 | | SfxStyleDialogController::~SfxStyleDialogController() |
70 | 0 | { |
71 | | // coverity[leaked_storage] - deliberate, ownership is really with m_rStyle |
72 | 0 | m_xExampleSet.release(); |
73 | 0 | } |
74 | | |
75 | | /* [Description] |
76 | | |
77 | | Override so that always RET_OK is returned. |
78 | | */ |
79 | | short SfxStyleDialogController::Ok() |
80 | 0 | { |
81 | 0 | SfxTabDialogController::Ok(); |
82 | 0 | return RET_OK; |
83 | 0 | } |
84 | | |
85 | | /* [Description] |
86 | | |
87 | | If the dialogue was canceled, then all selected attributes must be reset |
88 | | again. |
89 | | */ |
90 | | IMPL_LINK_NOARG(SfxStyleDialogController, CancelHdl, weld::Button&, void) |
91 | 0 | { |
92 | 0 | SfxTabPage* pPage = GetTabPage(u"organizer"); |
93 | |
|
94 | 0 | const SfxItemSet* pInSet = GetInputSetImpl(); |
95 | 0 | SfxWhichIter aIter(*pInSet); |
96 | 0 | sal_uInt16 nWhich = aIter.FirstWhich(); |
97 | |
|
98 | 0 | while (nWhich) |
99 | 0 | { |
100 | 0 | SfxItemState eState = aIter.GetItemState(false); |
101 | |
|
102 | 0 | if (SfxItemState::DEFAULT == eState) |
103 | 0 | m_xExampleSet->ClearItem(nWhich); |
104 | 0 | else |
105 | 0 | m_xExampleSet->Put(pInSet->Get(nWhich)); |
106 | 0 | nWhich = aIter.NextWhich(); |
107 | 0 | } |
108 | |
|
109 | 0 | if (pPage) |
110 | 0 | pPage->Reset(GetInputSetImpl()); |
111 | |
|
112 | 0 | m_xDialog->response(RET_CANCEL); |
113 | 0 | } |
114 | | |
115 | | OUString SfxStyleDialogController::GenerateUnusedName(SfxStyleSheetBasePool &rPool, SfxStyleFamily eFam) |
116 | 0 | { |
117 | 0 | OUString aNo(SfxResId(STR_NONAME)); |
118 | 0 | sal_uInt16 i = 1; |
119 | 0 | OUString aNoName = aNo + OUString::number(i); |
120 | 0 | while (rPool.Find(aNoName, eFam)) |
121 | 0 | { |
122 | 0 | ++i; |
123 | 0 | aNoName = aNo + OUString::number(i); |
124 | 0 | } |
125 | 0 | return aNoName; |
126 | 0 | } |
127 | | |
128 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |