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