xref: /aoo41x/main/sfx2/source/doc/doctdlg.cxx (revision d119d52d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26 
27 #ifndef _MSGBOX_HXX //autogen
28 #include <vcl/msgbox.hxx>
29 #endif
30 #include <svl/stritem.hxx>
31 #ifndef GCC
32 #endif
33 
34 #include <sfx2/doctdlg.hxx>
35 #include "docvor.hxx"
36 #include "sfx2/sfxresid.hxx"
37 #include "sfxtypes.hxx"
38 #include <sfx2/dispatch.hxx>
39 #include <sfx2/app.hxx>
40 
41 #include <sfx2/sfx.hrc>
42 #include "doc.hrc"
43 #include "doctdlg.hrc"
44 #include <sfx2/basedlgs.hxx>
45 
46 //=========================================================================
47 
SfxDocumentTemplateDlg(Window * pParent,SfxDocumentTemplates * pTempl)48 SfxDocumentTemplateDlg::SfxDocumentTemplateDlg(	Window * pParent, SfxDocumentTemplates* pTempl ) :
49 
50 	ModalDialog( pParent, SfxResId( DLG_DOC_TEMPLATE ) ),
51 
52 	aEditFL		( this, SfxResId( FL_EDIT ) ),
53 	aNameEd		( this, SfxResId( ED_NAME ) ),
54 	aTemplateFL	( this, SfxResId( FL_STYLESHEETS ) ),
55 	aRegionFt	( this, SfxResId( FT_SECTION ) ),
56 	aRegionLb	( this, SfxResId( LB_SECTION ) ),
57 	aTemplateFt	( this, SfxResId( FT_STYLESHEETS ) ),
58 	aTemplateLb	( this, SfxResId( LB_STYLESHEETS ) ),
59 
60 	aOkBt		( this, SfxResId( BT_OK ) ),
61 	aCancelBt	( this, SfxResId( BT_CANCEL ) ),
62 	aHelpBt		( this, SfxResId( BT_HELP ) ),
63 	aEditBt		( this, SfxResId( BT_EDIT ) ),
64 	aOrganizeBt	( this, SfxResId( BT_ORGANIZE ) ),
65 
66 	pTemplates	( pTempl ),
67 	pHelper		( NULL )
68 
69 {
70 	FreeResource();
71 
72 	pHelper = new SfxModalDefParentHelper( this );
73 	aOrganizeBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, OrganizeHdl));
74 	aNameEd.SetModifyHdl(LINK(this, SfxDocumentTemplateDlg, NameModify));
75 	aOkBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, OkHdl));
76 	aEditBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, EditHdl));
77 	Init();
78 }
79 
80 //-------------------------------------------------------------------------
81 
~SfxDocumentTemplateDlg()82 SfxDocumentTemplateDlg::~SfxDocumentTemplateDlg()
83 {
84 	delete pHelper;
85 }
86 
87 //-------------------------------------------------------------------------
88 
IMPL_LINK(SfxDocumentTemplateDlg,EditHdl,Button *,pBut)89 IMPL_LINK( SfxDocumentTemplateDlg, EditHdl, Button *, pBut )
90 {
91     (void)pBut; //unused
92 	if ( !aRegionLb.GetSelectEntryCount() ||
93 		 !aTemplateLb.GetSelectEntryCount())
94 		return 0;
95 
96 	const SfxStringItem aRegion( SID_TEMPLATE_REGIONNAME, aRegionLb.GetSelectEntry() );
97 	const SfxStringItem aName( SID_TEMPLATE_NAME, aTemplateLb.GetSelectEntry() );
98     SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_OPENTEMPLATE, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD, &aRegion, &aName, 0L );
99 	EndDialog(RET_EDIT_STYLE);
100 
101 	return 0;
102 }
103 
104 //-------------------------------------------------------------------------
105 
Init()106 void SfxDocumentTemplateDlg::Init()
107 {
108 	if(!pTemplates->IsConstructed())
109 		pTemplates->Construct();
110 
111 	const sal_uInt16 nCount = pTemplates->GetRegionCount();
112 	for(sal_uInt16 i = 0; i < nCount; ++i)
113 		aRegionLb.InsertEntry(pTemplates->GetFullRegionName(i));
114 	if(!nCount)
115 		aRegionLb.InsertEntry(String(SfxResId(STR_STANDARD)));
116 	aRegionLb.SelectEntryPos(0);
117 	if(nCount)
118 	{
119 		aRegionLb.SetSelectHdl(LINK(this, SfxDocumentTemplateDlg, RegionSelect));
120 		RegionSelect(&aRegionLb);
121 		aTemplateLb.SetSelectHdl(LINK(this, SfxDocumentTemplateDlg, TemplateSelect));
122 		aTemplateLb.SetDoubleClickHdl(LINK(this, SfxDocumentTemplateDlg, EditHdl));
123 	}
124 	else {
125 		Link aLink;
126 		aTemplateLb.SetSelectHdl(aLink);
127 		aTemplateLb.SetDoubleClickHdl(aLink);
128 	}
129 }
130 
131 //-------------------------------------------------------------------------
132 
IMPL_LINK(SfxDocumentTemplateDlg,OrganizeHdl,Button *,pButton)133 IMPL_LINK( SfxDocumentTemplateDlg, OrganizeHdl, Button *, pButton )
134 {
135     (void)pButton; //unused
136 	SfxTemplateOrganizeDlg *pDlg =
137 		new SfxTemplateOrganizeDlg(this, pTemplates);
138 	const short nRet = pDlg->Execute();
139 	delete pDlg;
140 	if(RET_OK == nRet)
141 	{
142 		// View aktualisieren
143 		aRegionLb.SetUpdateMode( sal_False );
144 		aRegionLb.Clear();
145 		Init();
146 		aRegionLb.SetUpdateMode( sal_True );
147 		aRegionLb.Invalidate();
148 		aRegionLb.Update();
149 		aCancelBt.SetText(String(SfxResId(STR_CLOSE)));
150 	}
151 	else if(RET_EDIT_STYLE == nRet)
152 		EndDialog(RET_CANCEL);
153 	return 0;
154 }
155 
156 //-------------------------------------------------------------------------
157 
IMPL_LINK(SfxDocumentTemplateDlg,OkHdl,Control *,pControl)158 IMPL_LINK( SfxDocumentTemplateDlg, OkHdl, Control *, pControl )
159 {
160     (void)pControl; //unused
161     // pruefen, ob eine Vorlage diesen Namens existiert
162 	if(LISTBOX_ENTRY_NOTFOUND != aTemplateLb.GetEntryPos(
163 		GetTemplateName())) {
164 		QueryBox aQuery(this, SfxResId(MSG_CONFIRM_OVERWRITE_TEMPLATE));
165 		if(RET_NO == aQuery.Execute())
166 			return 0;
167 	}
168 	EndDialog(RET_OK);
169 	return 0;
170 }
171 
172 //-------------------------------------------------------------------------
173 
IMPL_LINK(SfxDocumentTemplateDlg,RegionSelect,ListBox *,pBox)174 IMPL_LINK( SfxDocumentTemplateDlg, RegionSelect, ListBox *, pBox )
175 {
176 	const sal_uInt16 nRegion = pBox->GetSelectEntryPos();
177 	const sal_uInt16 nCount = pTemplates->GetCount(nRegion);
178 	aTemplateLb.SetUpdateMode(sal_False);
179 	aTemplateLb.Clear();
180 	for(sal_uInt16 i = 0; i < nCount; ++i)
181 		aTemplateLb.InsertEntry(pTemplates->GetName(nRegion, i));
182 	aTemplateLb.SelectEntryPos(0);
183 	aTemplateLb.SetUpdateMode(sal_True);
184 	aTemplateLb.Invalidate();
185 	aTemplateLb.Update();
186 	return 0;
187 }
188 
189 //-------------------------------------------------------------------------
190 
IMPL_LINK_INLINE_START(SfxDocumentTemplateDlg,TemplateSelect,ListBox *,pBox)191 IMPL_LINK_INLINE_START( SfxDocumentTemplateDlg, TemplateSelect, ListBox *, pBox )
192 {
193 	aNameEd.SetText(pBox->GetSelectEntry());
194 	NameModify(&aNameEd);
195 	return 0;
196 }
IMPL_LINK_INLINE_END(SfxDocumentTemplateDlg,TemplateSelect,ListBox *,pBox)197 IMPL_LINK_INLINE_END( SfxDocumentTemplateDlg, TemplateSelect, ListBox *, pBox )
198 
199 //-------------------------------------------------------------------------
200 
201 IMPL_LINK( SfxDocumentTemplateDlg, NameModify, Edit *, pBox )
202 {
203 	const String &rText=pBox->GetText();
204 	if(!rText.Len())
205 		aEditBt.Enable();
206 	else
207 	{
208 		aTemplateLb.SelectEntry(rText);
209 		aEditBt.Enable( aTemplateLb.GetSelectEntry() == rText );
210 	}
211 
212 	aOkBt.Enable( rText.Len() > 0 );
213 	return 0;
214 }
215 
216 //-------------------------------------------------------------------------
217 
GetTemplatePath()218 String SfxDocumentTemplateDlg::GetTemplatePath()
219 {
220 	const String& rPath=GetTemplateName();
221 	if(pTemplates->GetRegionCount())
222 		return pTemplates->GetTemplatePath(
223 			aRegionLb.GetSelectEntryPos(), rPath);
224 	return pTemplates->GetDefaultTemplatePath(rPath);
225 }
226 
227 //-------------------------------------------------------------------------
228 
NewTemplate(const String & rPath)229 void SfxDocumentTemplateDlg::NewTemplate(const String &rPath)
230 {
231 	pTemplates->NewTemplate(
232 		aRegionLb.GetSelectEntryPos(), GetTemplateName(), rPath);
233 }
234 
235