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 <svl/whiter.hxx>
21 : #include <svl/style.hxx>
22 : #include <vcl/msgbox.hxx>
23 :
24 : #include <sfx2/styledlg.hxx>
25 : #include <sfx2/mgetempl.hxx>
26 : #include <sfx2/sfxresid.hxx>
27 : #include <sfx2/sfxuno.hxx>
28 :
29 : #include "dialog.hrc"
30 :
31 : // class SfxStyleDialog --------------------------------------------------
32 :
33 0 : SfxStyleDialog::SfxStyleDialog
34 : (
35 : vcl::Window* pParent, // Parent
36 : const OUString& rID, const OUString& rUIXMLDescription,
37 : SfxStyleSheetBase& rStyle // stylesheet to be processed
38 : )
39 :
40 : /* [Description]
41 :
42 : Constructor: Add Manage TabPage, set ExampleSet from style.
43 : */
44 :
45 : : SfxTabDialog(pParent, rID, rUIXMLDescription,
46 0 : rStyle.GetItemSet().Clone(), true)
47 0 : , pStyle( &rStyle )
48 :
49 : {
50 : // without ParentSupport suppress the standardButton
51 0 : if (!rStyle.HasParentSupport())
52 0 : RemoveStandardButton();
53 :
54 0 : m_nOrganizerId = AddTabPage("organizer", SfxManageStyleSheetPage::Create, 0);
55 :
56 : // With new template always set the management page as the current page
57 :
58 0 : if( rStyle.GetName().isEmpty() )
59 0 : SetCurPageId(m_nOrganizerId);
60 : else
61 : {
62 0 : OUString sTxt = OUString(GetText()) + ": " + rStyle.GetName();
63 0 : SetText( sTxt );
64 : }
65 0 : delete pExampleSet; // in SfxTabDialog::Ctor() already created
66 0 : pExampleSet = &pStyle->GetItemSet();
67 :
68 0 : GetCancelButton().SetClickHdl( LINK(this, SfxStyleDialog, CancelHdl) );
69 0 : }
70 :
71 :
72 :
73 0 : SfxStyleDialog::~SfxStyleDialog()
74 : {
75 0 : disposeOnce();
76 0 : }
77 :
78 : /* [Description]
79 :
80 : Destructor: set ExampleSet to NULL, so that SfxTabDialog does not delete
81 : the Set from Style.
82 : */
83 :
84 0 : void SfxStyleDialog::dispose()
85 : {
86 0 : pExampleSet = 0;
87 0 : pStyle = 0;
88 0 : SfxTabDialog::dispose();
89 0 : }
90 :
91 :
92 :
93 0 : void SfxStyleDialog::RefreshInputSet()
94 :
95 : /* [Description]
96 :
97 : This is called when <SfxTabPage::DeactivatePage(SfxItemSet *)>
98 : returns <SfxTabPage::REFRESH_SET>.
99 : */
100 :
101 : {
102 0 : SfxTabDialog::RefreshInputSet();
103 0 : }
104 :
105 :
106 :
107 0 : short SfxStyleDialog::Ok()
108 :
109 : /* [Description]
110 :
111 : Override so that always RET_OK is returned.
112 : */
113 :
114 : {
115 0 : SfxTabDialog::Ok();
116 0 : return RET_OK;
117 : }
118 :
119 :
120 :
121 0 : IMPL_LINK( SfxStyleDialog, CancelHdl, Button *, pButton )
122 :
123 : /* [Description]
124 :
125 : If the dialogue was canceled, then all selected attributes must be reset
126 : again.
127 : */
128 :
129 : {
130 : (void)pButton; //unused
131 0 : SfxTabPage* pPage = GetTabPage(m_nOrganizerId);
132 :
133 0 : const SfxItemSet* pInSet = GetInputSetImpl();
134 0 : SfxWhichIter aIter( *pInSet );
135 0 : sal_uInt16 nWhich = aIter.FirstWhich();
136 :
137 0 : while ( nWhich )
138 : {
139 0 : SfxItemState eState = pInSet->GetItemState( nWhich, false );
140 :
141 0 : if ( SfxItemState::DEFAULT == eState )
142 0 : pExampleSet->ClearItem( nWhich );
143 : else
144 0 : pExampleSet->Put( pInSet->Get( nWhich ) );
145 0 : nWhich = aIter.NextWhich();
146 : }
147 :
148 0 : if ( pPage )
149 0 : pPage->Reset( GetInputSetImpl() );
150 0 : EndDialog( RET_CANCEL );
151 0 : return 0;
152 : }
153 :
154 0 : OUString SfxStyleDialog::GenerateUnusedName(SfxStyleSheetBasePool &rPool)
155 : {
156 0 : OUString aNoName(SfxResId(STR_NONAME).toString());
157 0 : sal_uInt16 nNo = 1;
158 0 : OUString aNo(aNoName);
159 0 : aNoName += OUString::number(nNo);
160 0 : while (rPool.Find(aNoName))
161 : {
162 0 : ++nNo;
163 0 : aNoName = aNo;
164 0 : aNoName += OUString::number(nNo);
165 : }
166 0 : return aNoName;
167 648 : }
168 :
169 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|