Branch data 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 : :
21 : : #include <vcl/msgbox.hxx>
22 : : #include <svl/stritem.hxx>
23 : :
24 : : #include <sfx2/doctdlg.hxx>
25 : : #include "docvor.hxx"
26 : : #include "sfx2/sfxresid.hxx"
27 : : #include "sfxtypes.hxx"
28 : : #include <sfx2/dispatch.hxx>
29 : : #include <sfx2/app.hxx>
30 : :
31 : : #include <sfx2/sfx.hrc>
32 : : #include "doc.hrc"
33 : : #include "doctdlg.hrc"
34 : : #include <sfx2/basedlgs.hxx>
35 : :
36 : : //=========================================================================
37 : :
38 : 0 : SfxDocumentTemplateDlg::SfxDocumentTemplateDlg( Window * pParent, SfxDocumentTemplates* pTempl ) :
39 : :
40 : : ModalDialog( pParent, SfxResId( DLG_DOC_TEMPLATE ) ),
41 : :
42 : : aEditFL ( this, SfxResId( FL_EDIT ) ),
43 : : aNameEd ( this, SfxResId( ED_NAME ) ),
44 : : aTemplateFL ( this, SfxResId( FL_STYLESHEETS ) ),
45 : : aRegionFt ( this, SfxResId( FT_SECTION ) ),
46 : : aRegionLb ( this, SfxResId( LB_SECTION ) ),
47 : : aTemplateFt ( this, SfxResId( FT_STYLESHEETS ) ),
48 : : aTemplateLb ( this, SfxResId( LB_STYLESHEETS ) ),
49 : :
50 : : aOkBt ( this, SfxResId( BT_OK ) ),
51 : : aCancelBt ( this, SfxResId( BT_CANCEL ) ),
52 : : aHelpBt ( this, SfxResId( BT_HELP ) ),
53 : : aEditBt ( this, SfxResId( BT_EDIT ) ),
54 : : aOrganizeBt ( this, SfxResId( BT_ORGANIZE ) ),
55 : :
56 : : pTemplates ( pTempl ),
57 [ # # ][ # # ]: 0 : pHelper ( NULL )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
58 : :
59 : : {
60 [ # # ]: 0 : FreeResource();
61 : :
62 [ # # ][ # # ]: 0 : pHelper = new SfxModalDefParentHelper( this );
63 [ # # ]: 0 : aOrganizeBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, OrganizeHdl));
64 [ # # ]: 0 : aNameEd.SetModifyHdl(LINK(this, SfxDocumentTemplateDlg, NameModify));
65 [ # # ]: 0 : aOkBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, OkHdl));
66 [ # # ]: 0 : aEditBt.SetClickHdl(LINK(this, SfxDocumentTemplateDlg, EditHdl));
67 [ # # ]: 0 : Init();
68 : 0 : }
69 : :
70 : : //-------------------------------------------------------------------------
71 : :
72 [ # # ][ # # ]: 0 : SfxDocumentTemplateDlg::~SfxDocumentTemplateDlg()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
73 : : {
74 [ # # ][ # # ]: 0 : delete pHelper;
75 [ # # ]: 0 : }
76 : :
77 : : //-------------------------------------------------------------------------
78 : :
79 : 0 : IMPL_LINK( SfxDocumentTemplateDlg, EditHdl, Button *, pBut )
80 : : {
81 : : (void)pBut; //unused
82 [ # # ][ # # ]: 0 : if ( !aRegionLb.GetSelectEntryCount() ||
[ # # ][ # # ]
83 [ # # ]: 0 : !aTemplateLb.GetSelectEntryCount())
84 : 0 : return 0;
85 : :
86 [ # # ][ # # ]: 0 : const SfxStringItem aRegion( SID_TEMPLATE_REGIONNAME, aRegionLb.GetSelectEntry() );
[ # # ]
87 [ # # ][ # # ]: 0 : const SfxStringItem aName( SID_TEMPLATE_NAME, aTemplateLb.GetSelectEntry() );
[ # # ]
88 [ # # ][ # # ]: 0 : SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_OPENTEMPLATE, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD, &aRegion, &aName, 0L );
[ # # ]
89 [ # # ]: 0 : EndDialog(RET_EDIT_STYLE);
90 : :
91 [ # # ][ # # ]: 0 : return 0;
92 : : }
93 : :
94 : : //-------------------------------------------------------------------------
95 : :
96 : 0 : void SfxDocumentTemplateDlg::Init()
97 : : {
98 [ # # ]: 0 : if(!pTemplates->IsConstructed())
99 : 0 : pTemplates->Construct();
100 : :
101 : 0 : const sal_uInt16 nCount = pTemplates->GetRegionCount();
102 [ # # ]: 0 : for(sal_uInt16 i = 0; i < nCount; ++i)
103 [ # # ]: 0 : aRegionLb.InsertEntry(pTemplates->GetFullRegionName(i));
104 [ # # ]: 0 : if(!nCount)
105 [ # # ][ # # ]: 0 : aRegionLb.InsertEntry(SfxResId(STR_STANDARD).toString());
[ # # ][ # # ]
106 : 0 : aRegionLb.SelectEntryPos(0);
107 [ # # ]: 0 : if(nCount)
108 : : {
109 : 0 : aRegionLb.SetSelectHdl(LINK(this, SfxDocumentTemplateDlg, RegionSelect));
110 : 0 : RegionSelect(&aRegionLb);
111 : 0 : aTemplateLb.SetSelectHdl(LINK(this, SfxDocumentTemplateDlg, TemplateSelect));
112 : 0 : aTemplateLb.SetDoubleClickHdl(LINK(this, SfxDocumentTemplateDlg, EditHdl));
113 : : }
114 : : else {
115 [ # # ]: 0 : Link aLink;
116 : 0 : aTemplateLb.SetSelectHdl(aLink);
117 : 0 : aTemplateLb.SetDoubleClickHdl(aLink);
118 : : }
119 : 0 : }
120 : :
121 : : //-------------------------------------------------------------------------
122 : :
123 : 0 : IMPL_LINK( SfxDocumentTemplateDlg, OrganizeHdl, Button *, pButton )
124 : : {
125 : : (void)pButton; //unused
126 : : SfxTemplateOrganizeDlg *pDlg =
127 [ # # ]: 0 : new SfxTemplateOrganizeDlg(this, pTemplates);
128 : 0 : const short nRet = pDlg->Execute();
129 [ # # ]: 0 : delete pDlg;
130 [ # # ]: 0 : if(RET_OK == nRet)
131 : : {
132 : : // View aktualisieren
133 : 0 : aRegionLb.SetUpdateMode( sal_False );
134 : 0 : aRegionLb.Clear();
135 : 0 : Init();
136 : 0 : aRegionLb.SetUpdateMode( sal_True );
137 : 0 : aRegionLb.Invalidate();
138 : 0 : aRegionLb.Update();
139 [ # # ][ # # ]: 0 : aCancelBt.SetText(SfxResId(STR_CLOSE).toString());
[ # # ][ # # ]
140 : : }
141 [ # # ]: 0 : else if(RET_EDIT_STYLE == nRet)
142 : 0 : EndDialog(RET_CANCEL);
143 : 0 : return 0;
144 : : }
145 : :
146 : : //-------------------------------------------------------------------------
147 : :
148 : 0 : IMPL_LINK( SfxDocumentTemplateDlg, OkHdl, Control *, pControl )
149 : : {
150 : : (void)pControl; //unused
151 : : // Test whether a template with this name exists
152 [ # # ]: 0 : if(LISTBOX_ENTRY_NOTFOUND != aTemplateLb.GetEntryPos(
153 [ # # ]: 0 : GetTemplateName())) {
154 [ # # ][ # # ]: 0 : QueryBox aQuery(this, SfxResId(MSG_CONFIRM_OVERWRITE_TEMPLATE));
155 [ # # ][ # # ]: 0 : if(RET_NO == aQuery.Execute())
156 [ # # ][ # # ]: 0 : return 0;
157 : : }
158 : 0 : EndDialog(RET_OK);
159 : 0 : return 0;
160 : : }
161 : :
162 : : //-------------------------------------------------------------------------
163 : :
164 : 0 : IMPL_LINK( SfxDocumentTemplateDlg, RegionSelect, ListBox *, pBox )
165 : : {
166 : 0 : const sal_uInt16 nRegion = pBox->GetSelectEntryPos();
167 : 0 : const sal_uInt16 nCount = pTemplates->GetCount(nRegion);
168 : 0 : aTemplateLb.SetUpdateMode(sal_False);
169 : 0 : aTemplateLb.Clear();
170 [ # # ]: 0 : for(sal_uInt16 i = 0; i < nCount; ++i)
171 : 0 : aTemplateLb.InsertEntry(pTemplates->GetName(nRegion, i));
172 : 0 : aTemplateLb.SelectEntryPos(0);
173 : 0 : aTemplateLb.SetUpdateMode(sal_True);
174 : 0 : aTemplateLb.Invalidate();
175 : 0 : aTemplateLb.Update();
176 : 0 : return 0;
177 : : }
178 : :
179 : : //-------------------------------------------------------------------------
180 : :
181 : 0 : IMPL_LINK_INLINE_START( SfxDocumentTemplateDlg, TemplateSelect, ListBox *, pBox )
182 : : {
183 [ # # ]: 0 : aNameEd.SetText(pBox->GetSelectEntry());
184 : 0 : NameModify(&aNameEd);
185 : 0 : return 0;
186 : : }
187 : 0 : IMPL_LINK_INLINE_END( SfxDocumentTemplateDlg, TemplateSelect, ListBox *, pBox )
188 : :
189 : : //-------------------------------------------------------------------------
190 : :
191 : 0 : IMPL_LINK( SfxDocumentTemplateDlg, NameModify, Edit *, pBox )
192 : : {
193 : 0 : const String &rText=pBox->GetText();
194 [ # # ]: 0 : if(!rText.Len())
195 [ # # ]: 0 : aEditBt.Enable();
196 : : else
197 : : {
198 [ # # ]: 0 : aTemplateLb.SelectEntry(rText);
199 [ # # ][ # # ]: 0 : aEditBt.Enable( aTemplateLb.GetSelectEntry() == rText );
[ # # ][ # # ]
200 : : }
201 : :
202 [ # # ]: 0 : aOkBt.Enable( rText.Len() > 0 );
203 : 0 : return 0;
204 : : }
205 : :
206 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|