1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sfx2.hxx" 30 31 #ifndef _MSGBOX_HXX //autogen 32 #include <vcl/msgbox.hxx> 33 #endif 34 #include <svl/stritem.hxx> 35 #ifndef GCC 36 #endif 37 38 #include <sfx2/doctdlg.hxx> 39 #include "docvor.hxx" 40 #include "sfx2/sfxresid.hxx" 41 #include "sfxtypes.hxx" 42 #include <sfx2/dispatch.hxx> 43 #include <sfx2/app.hxx> 44 45 #include <sfx2/sfx.hrc> 46 #include "doc.hrc" 47 #include "doctdlg.hrc" 48 #include <sfx2/basedlgs.hxx> 49 50 //========================================================================= 51 52 SfxDocumentTemplateDlg::SfxDocumentTemplateDlg( Window * pParent, SfxDocumentTemplates* pTempl ) : 53 54 ModalDialog( pParent, SfxResId( DLG_DOC_TEMPLATE ) ), 55 56 aEditFL ( this, SfxResId( FL_EDIT ) ), 57 aNameEd ( this, SfxResId( ED_NAME ) ), 58 aTemplateFL ( this, SfxResId( FL_STYLESHEETS ) ), 59 aRegionFt ( this, SfxResId( FT_SECTION ) ), 60 aRegionLb ( this, SfxResId( LB_SECTION ) ), 61 aTemplateFt ( this, SfxResId( FT_STYLESHEETS ) ), 62 aTemplateLb ( this, SfxResId( LB_STYLESHEETS ) ), 63 64 aOkBt ( this, SfxResId( BT_OK ) ), 65 aCancelBt ( this, SfxResId( BT_CANCEL ) ), 66 aHelpBt ( this, SfxResId( BT_HELP ) ), 67 aEditBt ( this, SfxResId( BT_EDIT ) ), 68 aOrganizeBt ( this, SfxResId( BT_ORGANIZE ) ), 69 70 pTemplates ( pTempl ), 71 pHelper ( NULL ) 72 73 { 74 FreeResource(); 75 76 pHelper = new SfxModalDefParentHelper( this ); 77 aOrganizeBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, OrganizeHdl)); 78 aNameEd.SetModifyHdl(LINK(this, SfxDocumentTemplateDlg, NameModify)); 79 aOkBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, OkHdl)); 80 aEditBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, EditHdl)); 81 Init(); 82 } 83 84 //------------------------------------------------------------------------- 85 86 SfxDocumentTemplateDlg::~SfxDocumentTemplateDlg() 87 { 88 delete pHelper; 89 } 90 91 //------------------------------------------------------------------------- 92 93 IMPL_LINK( SfxDocumentTemplateDlg, EditHdl, Button *, pBut ) 94 { 95 (void)pBut; //unused 96 if ( !aRegionLb.GetSelectEntryCount() || 97 !aTemplateLb.GetSelectEntryCount()) 98 return 0; 99 100 const SfxStringItem aRegion( SID_TEMPLATE_REGIONNAME, aRegionLb.GetSelectEntry() ); 101 const SfxStringItem aName( SID_TEMPLATE_NAME, aTemplateLb.GetSelectEntry() ); 102 SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_OPENTEMPLATE, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD, &aRegion, &aName, 0L ); 103 EndDialog(RET_EDIT_STYLE); 104 105 return 0; 106 } 107 108 //------------------------------------------------------------------------- 109 110 void SfxDocumentTemplateDlg::Init() 111 { 112 if(!pTemplates->IsConstructed()) 113 pTemplates->Construct(); 114 115 const sal_uInt16 nCount = pTemplates->GetRegionCount(); 116 for(sal_uInt16 i = 0; i < nCount; ++i) 117 aRegionLb.InsertEntry(pTemplates->GetFullRegionName(i)); 118 if(!nCount) 119 aRegionLb.InsertEntry(String(SfxResId(STR_STANDARD))); 120 aRegionLb.SelectEntryPos(0); 121 if(nCount) 122 { 123 aRegionLb.SetSelectHdl(LINK(this, SfxDocumentTemplateDlg, RegionSelect)); 124 RegionSelect(&aRegionLb); 125 aTemplateLb.SetSelectHdl(LINK(this, SfxDocumentTemplateDlg, TemplateSelect)); 126 aTemplateLb.SetDoubleClickHdl(LINK(this, SfxDocumentTemplateDlg, EditHdl)); 127 } 128 else { 129 Link aLink; 130 aTemplateLb.SetSelectHdl(aLink); 131 aTemplateLb.SetDoubleClickHdl(aLink); 132 } 133 } 134 135 //------------------------------------------------------------------------- 136 137 IMPL_LINK( SfxDocumentTemplateDlg, OrganizeHdl, Button *, pButton ) 138 { 139 (void)pButton; //unused 140 SfxTemplateOrganizeDlg *pDlg = 141 new SfxTemplateOrganizeDlg(this, pTemplates); 142 const short nRet = pDlg->Execute(); 143 delete pDlg; 144 if(RET_OK == nRet) 145 { 146 // View aktualisieren 147 aRegionLb.SetUpdateMode( sal_False ); 148 aRegionLb.Clear(); 149 Init(); 150 aRegionLb.SetUpdateMode( sal_True ); 151 aRegionLb.Invalidate(); 152 aRegionLb.Update(); 153 aCancelBt.SetText(String(SfxResId(STR_CLOSE))); 154 } 155 else if(RET_EDIT_STYLE == nRet) 156 EndDialog(RET_CANCEL); 157 return 0; 158 } 159 160 //------------------------------------------------------------------------- 161 162 IMPL_LINK( SfxDocumentTemplateDlg, OkHdl, Control *, pControl ) 163 { 164 (void)pControl; //unused 165 // pruefen, ob eine Vorlage diesen Namens existiert 166 if(LISTBOX_ENTRY_NOTFOUND != aTemplateLb.GetEntryPos( 167 GetTemplateName())) { 168 QueryBox aQuery(this, SfxResId(MSG_CONFIRM_OVERWRITE_TEMPLATE)); 169 if(RET_NO == aQuery.Execute()) 170 return 0; 171 } 172 EndDialog(RET_OK); 173 return 0; 174 } 175 176 //------------------------------------------------------------------------- 177 178 IMPL_LINK( SfxDocumentTemplateDlg, RegionSelect, ListBox *, pBox ) 179 { 180 const sal_uInt16 nRegion = pBox->GetSelectEntryPos(); 181 const sal_uInt16 nCount = pTemplates->GetCount(nRegion); 182 aTemplateLb.SetUpdateMode(sal_False); 183 aTemplateLb.Clear(); 184 for(sal_uInt16 i = 0; i < nCount; ++i) 185 aTemplateLb.InsertEntry(pTemplates->GetName(nRegion, i)); 186 aTemplateLb.SelectEntryPos(0); 187 aTemplateLb.SetUpdateMode(sal_True); 188 aTemplateLb.Invalidate(); 189 aTemplateLb.Update(); 190 return 0; 191 } 192 193 //------------------------------------------------------------------------- 194 195 IMPL_LINK_INLINE_START( SfxDocumentTemplateDlg, TemplateSelect, ListBox *, pBox ) 196 { 197 aNameEd.SetText(pBox->GetSelectEntry()); 198 NameModify(&aNameEd); 199 return 0; 200 } 201 IMPL_LINK_INLINE_END( SfxDocumentTemplateDlg, TemplateSelect, ListBox *, pBox ) 202 203 //------------------------------------------------------------------------- 204 205 IMPL_LINK( SfxDocumentTemplateDlg, NameModify, Edit *, pBox ) 206 { 207 const String &rText=pBox->GetText(); 208 if(!rText.Len()) 209 aEditBt.Enable(); 210 else 211 { 212 aTemplateLb.SelectEntry(rText); 213 aEditBt.Enable( aTemplateLb.GetSelectEntry() == rText ); 214 } 215 216 aOkBt.Enable( rText.Len() > 0 ); 217 return 0; 218 } 219 220 //------------------------------------------------------------------------- 221 222 String SfxDocumentTemplateDlg::GetTemplatePath() 223 { 224 const String& rPath=GetTemplateName(); 225 if(pTemplates->GetRegionCount()) 226 return pTemplates->GetTemplatePath( 227 aRegionLb.GetSelectEntryPos(), rPath); 228 return pTemplates->GetDefaultTemplatePath(rPath); 229 } 230 231 //------------------------------------------------------------------------- 232 233 void SfxDocumentTemplateDlg::NewTemplate(const String &rPath) 234 { 235 pTemplates->NewTemplate( 236 aRegionLb.GetSelectEntryPos(), GetTemplateName(), rPath); 237 } 238 239