1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: doctdlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #ifndef _MSGBOX_HXX //autogen
35 #include <vcl/msgbox.hxx>
37 #include <svtools/stritem.hxx>
41 #include <sfx2/doctdlg.hxx>
43 #include "sfxresid.hxx"
44 #include "sfxtypes.hxx"
45 #include <sfx2/dispatch.hxx>
46 #include <sfx2/app.hxx>
48 #include <sfx2/sfx.hrc>
50 #include "doctdlg.hrc"
51 #include <sfx2/basedlgs.hxx>
53 //=========================================================================
55 SfxDocumentTemplateDlg::SfxDocumentTemplateDlg( Window
* pParent
, SfxDocumentTemplates
* pTempl
) :
57 ModalDialog( pParent
, SfxResId( DLG_DOC_TEMPLATE
) ),
59 aEditFL ( this, SfxResId( FL_EDIT
) ),
60 aNameEd ( this, SfxResId( ED_NAME
) ),
61 aTemplateFL ( this, SfxResId( FL_STYLESHEETS
) ),
62 aRegionFt ( this, SfxResId( FT_SECTION
) ),
63 aRegionLb ( this, SfxResId( LB_SECTION
) ),
64 aTemplateFt ( this, SfxResId( FT_STYLESHEETS
) ),
65 aTemplateLb ( this, SfxResId( LB_STYLESHEETS
) ),
67 aOkBt ( this, SfxResId( BT_OK
) ),
68 aCancelBt ( this, SfxResId( BT_CANCEL
) ),
69 aHelpBt ( this, SfxResId( BT_HELP
) ),
70 aEditBt ( this, SfxResId( BT_EDIT
) ),
71 aOrganizeBt ( this, SfxResId( BT_ORGANIZE
) ),
73 pTemplates ( pTempl
),
79 pHelper
= new SfxModalDefParentHelper( this );
80 aOrganizeBt
.SetClickHdl(LINK(this, SfxDocumentTemplateDlg
, OrganizeHdl
));
81 aNameEd
.SetModifyHdl(LINK(this, SfxDocumentTemplateDlg
, NameModify
));
82 aOkBt
.SetClickHdl(LINK(this, SfxDocumentTemplateDlg
, OkHdl
));
83 aEditBt
.SetClickHdl(LINK(this, SfxDocumentTemplateDlg
, EditHdl
));
87 //-------------------------------------------------------------------------
89 SfxDocumentTemplateDlg::~SfxDocumentTemplateDlg()
94 //-------------------------------------------------------------------------
96 IMPL_LINK( SfxDocumentTemplateDlg
, EditHdl
, Button
*, pBut
)
99 if ( !aRegionLb
.GetSelectEntryCount() ||
100 !aTemplateLb
.GetSelectEntryCount())
103 const SfxStringItem
aRegion( SID_TEMPLATE_REGIONNAME
, aRegionLb
.GetSelectEntry() );
104 const SfxStringItem
aName( SID_TEMPLATE_NAME
, aTemplateLb
.GetSelectEntry() );
105 SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_OPENTEMPLATE
, SFX_CALLMODE_ASYNCHRON
|SFX_CALLMODE_RECORD
, &aRegion
, &aName
, 0L );
106 EndDialog(RET_EDIT_STYLE
);
111 //-------------------------------------------------------------------------
113 void SfxDocumentTemplateDlg::Init()
115 if(!pTemplates
->IsConstructed())
116 pTemplates
->Construct();
118 const USHORT nCount
= pTemplates
->GetRegionCount();
119 for(USHORT i
= 0; i
< nCount
; ++i
)
120 aRegionLb
.InsertEntry(pTemplates
->GetFullRegionName(i
));
122 aRegionLb
.InsertEntry(String(SfxResId(STR_STANDARD
)));
123 aRegionLb
.SelectEntryPos(0);
126 aRegionLb
.SetSelectHdl(LINK(this, SfxDocumentTemplateDlg
, RegionSelect
));
127 RegionSelect(&aRegionLb
);
128 aTemplateLb
.SetSelectHdl(LINK(this, SfxDocumentTemplateDlg
, TemplateSelect
));
129 aTemplateLb
.SetDoubleClickHdl(LINK(this, SfxDocumentTemplateDlg
, EditHdl
));
133 aTemplateLb
.SetSelectHdl(aLink
);
134 aTemplateLb
.SetDoubleClickHdl(aLink
);
138 //-------------------------------------------------------------------------
140 IMPL_LINK( SfxDocumentTemplateDlg
, OrganizeHdl
, Button
*, pButton
)
142 (void)pButton
; //unused
143 SfxTemplateOrganizeDlg
*pDlg
=
144 new SfxTemplateOrganizeDlg(this, pTemplates
);
145 const short nRet
= pDlg
->Execute();
149 // View aktualisieren
150 aRegionLb
.SetUpdateMode( FALSE
);
153 aRegionLb
.SetUpdateMode( TRUE
);
154 aRegionLb
.Invalidate();
156 aCancelBt
.SetText(String(SfxResId(STR_CLOSE
)));
158 else if(RET_EDIT_STYLE
== nRet
)
159 EndDialog(RET_CANCEL
);
163 //-------------------------------------------------------------------------
165 IMPL_LINK( SfxDocumentTemplateDlg
, OkHdl
, Control
*, pControl
)
167 (void)pControl
; //unused
168 // pruefen, ob eine Vorlage diesen Namens existiert
169 if(LISTBOX_ENTRY_NOTFOUND
!= aTemplateLb
.GetEntryPos(
170 GetTemplateName())) {
171 QueryBox
aQuery(this, SfxResId(MSG_CONFIRM_OVERWRITE_TEMPLATE
));
172 if(RET_NO
== aQuery
.Execute())
179 //-------------------------------------------------------------------------
181 IMPL_LINK( SfxDocumentTemplateDlg
, RegionSelect
, ListBox
*, pBox
)
183 const USHORT nRegion
= pBox
->GetSelectEntryPos();
184 const USHORT nCount
= pTemplates
->GetCount(nRegion
);
185 aTemplateLb
.SetUpdateMode(FALSE
);
187 for(USHORT i
= 0; i
< nCount
; ++i
)
188 aTemplateLb
.InsertEntry(pTemplates
->GetName(nRegion
, i
));
189 aTemplateLb
.SelectEntryPos(0);
190 aTemplateLb
.SetUpdateMode(TRUE
);
191 aTemplateLb
.Invalidate();
192 aTemplateLb
.Update();
196 //-------------------------------------------------------------------------
198 IMPL_LINK_INLINE_START( SfxDocumentTemplateDlg
, TemplateSelect
, ListBox
*, pBox
)
200 aNameEd
.SetText(pBox
->GetSelectEntry());
201 NameModify(&aNameEd
);
204 IMPL_LINK_INLINE_END( SfxDocumentTemplateDlg
, TemplateSelect
, ListBox
*, pBox
)
206 //-------------------------------------------------------------------------
208 IMPL_LINK( SfxDocumentTemplateDlg
, NameModify
, Edit
*, pBox
)
210 const String
&rText
=pBox
->GetText();
215 aTemplateLb
.SelectEntry(rText
);
216 aEditBt
.Enable( aTemplateLb
.GetSelectEntry() == rText
);
219 aOkBt
.Enable( rText
.Len() > 0 );
223 //-------------------------------------------------------------------------
225 String
SfxDocumentTemplateDlg::GetTemplatePath()
227 const String
& rPath
=GetTemplateName();
228 if(pTemplates
->GetRegionCount())
229 return pTemplates
->GetTemplatePath(
230 aRegionLb
.GetSelectEntryPos(), rPath
);
231 return pTemplates
->GetDefaultTemplatePath(rPath
);
234 //-------------------------------------------------------------------------
236 void SfxDocumentTemplateDlg::NewTemplate(const String
&rPath
)
238 pTemplates
->NewTemplate(
239 aRegionLb
.GetSelectEntryPos(), GetTemplateName(), rPath
);