xref: /trunk/main/sw/source/ui/misc/docfnote.cxx (revision efeef26f)
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_sw.hxx"
26 
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 
31 
32 #include <svl/style.hxx>
33 #include <errhdl.hxx>
34 #include <wrtsh.hxx>
35 #ifndef _VIEW_HXX
36 #include <view.hxx>
37 #endif
38 #ifndef _DOCSH_HXX
39 #include <docsh.hxx>
40 #endif
41 #include <docfnote.hxx>
42 #include <impfnote.hxx>
43 #include <ftninfo.hxx>
44 #include <fmtcol.hxx>
45 #include <pagedesc.hxx>
46 #include <charfmt.hxx>
47 #include <docstyle.hxx>
48 #include <wdocsh.hxx>
49 #include <uitool.hxx>
50 #include <poolfmt.hxx>
51 #include <swstyle.h>
52 #ifndef _HELPID_H
53 #include <helpid.h>
54 #endif
55 #ifndef _MISC_HRC
56 #include <misc.hrc>
57 #endif
58 #ifndef _DOCFNOTE_HRC
59 #include <docfnote.hrc>
60 #endif
61 #ifndef _FRMUI_HRC
62 #include <frmui.hrc>
63 #endif
64 #include <SwStyleNameMapper.hxx>
65 
SwFootNoteOptionDlg(Window * pParent,SwWrtShell & rS)66 SwFootNoteOptionDlg::SwFootNoteOptionDlg( Window *pParent, SwWrtShell &rS ) :
67 	SfxTabDialog( pParent, SW_RES(DLG_DOC_FOOTNOTE) ),
68 	rSh( rS )
69 {
70 	FreeResource();
71 	RemoveResetButton();
72 
73 	aOldOkHdl = GetOKButton().GetClickHdl();
74 	GetOKButton().SetClickHdl( LINK( this, SwFootNoteOptionDlg, OkHdl ) );
75 
76 	AddTabPage( TP_FOOTNOTEOPTION, SwFootNoteOptionPage::Create, 0 );
77 	AddTabPage( TP_ENDNOTEOPTION,  SwEndNoteOptionPage::Create, 0 );
78 }
79 
PageCreated(sal_uInt16,SfxTabPage & rPage)80 void SwFootNoteOptionDlg::PageCreated( sal_uInt16 /*nId*/, SfxTabPage &rPage )
81 {
82 	((SwEndNoteOptionPage&)rPage).SetShell( rSh );
83 }
84 
~SwFootNoteOptionDlg()85 SwFootNoteOptionDlg::~SwFootNoteOptionDlg()
86 {
87 }
88 
IMPL_LINK(SwFootNoteOptionDlg,OkHdl,Button *,pBtn)89 IMPL_LINK( SwFootNoteOptionDlg, OkHdl, Button *, pBtn )
90 {
91     SfxItemSet aDummySet(rSh.GetAttrPool(), 1, 1 );
92 	SfxTabPage *pPage = GetTabPage( TP_FOOTNOTEOPTION );
93 	if ( pPage )
94         pPage->FillItemSet( aDummySet );
95 	pPage = GetTabPage( TP_ENDNOTEOPTION  );
96 	if ( pPage )
97         pPage->FillItemSet( aDummySet );
98 	aOldOkHdl.Call( pBtn );
99 	return 0;
100 }
101 
102 
103 //----------------------------------------------------------------------
104 
105 
SwEndNoteOptionPage(Window * pParent,sal_Bool bEN,const SfxItemSet & rSet)106 SwEndNoteOptionPage::SwEndNoteOptionPage( Window *pParent, sal_Bool bEN,
107 										  const SfxItemSet &rSet ) :
108 	SfxTabPage( pParent, SW_RES(bEN ? TP_ENDNOTEOPTION : TP_FOOTNOTEOPTION), rSet ),
109     aNumFL         (this, SW_RES( FL_NUM        )),
110 
111     aNumTypeFT      (this, SW_RES( FT_NUMTYPE    )),
112     aNumViewBox     (this, SW_RES( LB_NUMVIEW   ), INSERT_NUM_EXTENDED_TYPES),
113     aOffsetLbl      (this, SW_RES( FT_OFFSET    )),
114     aOffsetFld      (this, SW_RES( FLD_OFFSET   )),
115     aNumCountFT     (this, SW_RES( FT_NUMCOUNT   )),
116     aNumCountBox    (this, SW_RES( LB_NUMCOUNT  )),
117     aPrefixFT       (this, SW_RES( FT_PREFIX    )),
118     aPrefixED       (this, SW_RES( ED_PREFIX    )),
119     aSuffixFT       (this, SW_RES( FT_SUFFIX    )),
120     aSuffixED       (this, SW_RES( ED_SUFFIX    )),
121     aPosFT          (this, SW_RES( FT_POS    )),
122     aPosPageBox     (this, SW_RES( RB_POS_PAGE   )),
123     aPosChapterBox  (this, SW_RES( RB_POS_CHAPTER)),
124 
125     aTemplFL       (this, SW_RES( FL_TEMPL      )),
126     aParaTemplLbl   (this, SW_RES( FT_PARA_TEMPL)),
127     aParaTemplBox   (this, SW_RES( LB_PARA_TEMPL)),
128     aPageTemplLbl   (this, SW_RES( FT_PAGE_TEMPL)),
129     aPageTemplBox   (this, SW_RES( LB_PAGE_TEMPL)),
130 
131     aCharTemplFL(          this, SW_RES(FL_CHAR_TEMPL)),
132     aFtnCharAnchorTemplLbl( this, SW_RES( FT_ANCHR_CHARFMT)),
133     aFtnCharAnchorTemplBox( this, SW_RES( LB_ANCHR_CHARFMT)),
134     aFtnCharTextTemplLbl(   this, SW_RES( FT_TEXT_CHARFMT)),
135     aFtnCharTextTemplBox(   this, SW_RES( LB_TEXT_CHARFMT)),
136 
137     aContFL        (this, SW_RES( FL_CONT       )),
138     aContLbl        (this, SW_RES( FT_CONT      )),
139     aContEdit       (this, SW_RES( ED_CONT      )),
140     aContFromLbl    (this, SW_RES( FT_CONT_FROM )),
141     aContFromEdit   (this, SW_RES( ED_CONT_FROM )),
142 
143     aNumDoc(aNumCountBox.GetEntry(FTNNUM_DOC)),
144     aNumPage(aNumCountBox.GetEntry(FTNNUM_PAGE)),
145     aNumChapter(aNumCountBox.GetEntry(FTNNUM_CHAPTER)),
146     pSh( 0 ),
147 	bPosDoc(sal_False),
148 	bEndNote( bEN )
149 {
150 	FreeResource();
151 
152     aPosPageBox.SetClickHdl(LINK(this, SwEndNoteOptionPage, PosPageHdl));
153     aPosChapterBox.SetClickHdl(LINK(this, SwEndNoteOptionPage, PosChapterHdl));
154     aNumCountBox.SetSelectHdl(LINK(this, SwEndNoteOptionPage, NumCountHdl));
155 
156 	aPosPageBox.SetAccessibleRelationMemberOf(&aPosFT);
157 	aPosChapterBox.SetAccessibleRelationMemberOf(&aPosFT);
158 }
159 
Reset(const SfxItemSet &)160 void SwEndNoteOptionPage::Reset( const SfxItemSet& )
161 {
162 	SwEndNoteInfo *pInf = bEndNote ? new SwEndNoteInfo( pSh->GetEndNoteInfo() )
163 								   : new SwFtnInfo( pSh->GetFtnInfo() );
164 	SfxObjectShell * pDocSh = SfxObjectShell::Current();
165 	sal_uInt16 i;
166 
167 	if(PTR_CAST(SwWebDocShell, pDocSh))
168 	{
169 		aParaTemplLbl	.Hide();
170 		aParaTemplBox	.Hide();
171 		aPageTemplLbl	.Hide();
172 		aPageTemplBox	.Hide();
173 		aFtnCharTextTemplLbl.Hide();
174 		aFtnCharTextTemplBox.Hide();
175 		aFtnCharAnchorTemplLbl.Hide();
176 		aFtnCharAnchorTemplBox.Hide();
177         aCharTemplFL   .Hide();
178         aTemplFL       .Hide();
179 	}
180 	if ( bEndNote )
181 	{
182 		aPosPageBox.Hide();
183 		aPosChapterBox.Hide();
184 		aNumCountBox.Hide();
185 		aContLbl.Hide();
186 		aContEdit.Hide();
187 		aContFromLbl.Hide();
188 		aContFromEdit.Hide();
189         aContFL.Hide();
190 		bPosDoc = sal_True;
191 	}
192 	else
193 	{
194 		const SwFtnInfo &rInf = pSh->GetFtnInfo();
195 		// Position (Seite, Kapitel) setzen
196 		if ( rInf.ePos == FTNPOS_PAGE )
197 		{
198 			aPosPageBox.Check();
199 			aPageTemplLbl.Enable(sal_False);
200 			aPageTemplBox.Enable(sal_False);
201 		}
202 		else // if ( rInf.ePos == FTNPOS_CHAPTER )
203 		{
204 			aPosChapterBox.Check();
205 			aNumCountBox.RemoveEntry(aNumPage);
206             aNumCountBox.RemoveEntry(aNumChapter);
207 			bPosDoc = sal_True;
208 		}
209 			// Verweistexte
210 		aContEdit.SetText(rInf.aQuoVadis);
211 		aContFromEdit.SetText(rInf.aErgoSum);
212 
213 			// gesammelt wo
214 		SelectNumbering(rInf.eNum);
215 	}
216 
217 		// Numerierung
218 		// Art
219 	aNumViewBox.SelectNumberingType( pInf->aFmt.GetNumberingType());
220 	aOffsetFld.SetValue(pInf->nFtnOffset + 1);
221 	aPrefixED.SetText(pInf->GetPrefix());
222 	aSuffixED.SetText(pInf->GetSuffix());
223 
224 	const SwCharFmt* pCharFmt = pInf->GetCharFmt(
225 						*pSh->GetView().GetDocShell()->GetDoc());
226 	aFtnCharTextTemplBox.SelectEntry(pCharFmt->GetName());
227 	aFtnCharTextTemplBox.SaveValue();
228 
229 	pCharFmt = pInf->GetAnchorCharFmt( *pSh->GetDoc() );
230 	aFtnCharAnchorTemplBox.SelectEntry( pCharFmt->GetName() );
231 	aFtnCharAnchorTemplBox.SaveValue();
232 
233 		// Vorlagen - Sonderbereiche
234 		// Absatz
235 	SfxStyleSheetBasePool* pStyleSheetPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
236 	pStyleSheetPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SWSTYLEBIT_EXTRA);
237 	SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
238 	while(pStyle)
239 	{
240 		aParaTemplBox.InsertEntry(pStyle->GetName());
241 		pStyle = pStyleSheetPool->Next();
242 	}
243 
244 	String sStr;
245     SwStyleNameMapper::FillUIName( static_cast< sal_uInt16 >(bEndNote ? RES_POOLCOLL_ENDNOTE
246                            : RES_POOLCOLL_FOOTNOTE), sStr );
247 	if(LISTBOX_ENTRY_NOTFOUND == aParaTemplBox.GetEntryPos( sStr ) )
248 		aParaTemplBox.InsertEntry( sStr );
249 
250 	SwTxtFmtColl* pColl = pInf->GetFtnTxtColl();
251 	if( !pColl )
252 		aParaTemplBox.SelectEntry( sStr );		// Default
253 	else
254 	{
255 		ASSERT(!pColl->IsDefault(), "Defaultvorlage fuer Fussnoten ist falsch.");
256 		const sal_uInt16 nPos = aParaTemplBox.GetEntryPos(pColl->GetName());
257 		if( LISTBOX_ENTRY_NOTFOUND != nPos )
258 			aParaTemplBox.SelectEntryPos( nPos );
259 		else
260 		{
261 			aParaTemplBox.InsertEntry(pColl->GetName());
262 			aParaTemplBox.SelectEntry(pColl->GetName());
263 		}
264 	}
265 
266 		// Seite
267     for( i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i )
268 		aPageTemplBox.InsertEntry(SwStyleNameMapper::GetUIName( i, aEmptyStr ));
269 
270 	sal_uInt16 nCount = pSh->GetPageDescCnt();
271 	for(i = 0; i < nCount; ++i)
272 	{
273 		const SwPageDesc &rPageDesc = pSh->GetPageDesc(i);
274 		if(LISTBOX_ENTRY_NOTFOUND == aPageTemplBox.GetEntryPos(rPageDesc.GetName()))
275 			aPageTemplBox.InsertEntry(rPageDesc.GetName());
276 	}
277 
278 	aPageTemplBox.SelectEntry( pInf->GetPageDesc( *pSh->GetDoc() )->GetName());
279 	delete pInf;
280 }
281 
~SwEndNoteOptionPage()282 SwEndNoteOptionPage::~SwEndNoteOptionPage()
283 {
284 }
285 
Create(Window * pParent,const SfxItemSet & rSet)286 SfxTabPage *SwEndNoteOptionPage::Create( Window *pParent, const SfxItemSet &rSet )
287 {
288 	return new SwEndNoteOptionPage( pParent, sal_True, rSet );
289 }
290 
291 /*------------------------------------------------------------------------
292  Beschreibung:	Unterschiedliche Arten der Numerierung; da die Listbox
293 				unterschiedlich viele Eintraege hat, hier Funktionen
294 				fuer das Setzen und Erfragen der gemeinten Art
295 				der Numerierung.
296 ------------------------------------------------------------------------*/
SelectNumbering(int eNum)297 void SwEndNoteOptionPage::SelectNumbering(int eNum)
298 {
299     String sSelect;
300     switch(eNum)
301     {
302         case FTNNUM_DOC:
303             sSelect = aNumDoc;
304         break;
305         case FTNNUM_PAGE:
306             sSelect = aNumPage;
307         break;
308         case FTNNUM_CHAPTER:
309             sSelect = aNumChapter;
310         break;
311 #ifdef DBG_UTIL
312         default:
313             DBG_ERROR("Which numbering type?");
314 #endif
315     }
316     aNumCountBox.SelectEntry(sSelect);
317     NumCountHdl( &aNumCountBox );
318 }
319 
320 
321 
GetNumbering() const322 int SwEndNoteOptionPage::GetNumbering() const
323 {
324 	const sal_uInt16 nPos = aNumCountBox.GetSelectEntryPos();
325 	return (int) bPosDoc? nPos + 1: nPos;
326 }
327 
328 /*-----------------09.02.98 11:17-------------------
329 
330 --------------------------------------------------*/
SetShell(SwWrtShell & rShell)331 void SwEndNoteOptionPage::SetShell( SwWrtShell &rShell )
332 {
333 	pSh = &rShell;
334 	// Zeichenvorlagen sammeln
335 	aFtnCharTextTemplBox.Clear();
336 	aFtnCharAnchorTemplBox.Clear();
337 	::FillCharStyleListBox(aFtnCharTextTemplBox,
338 						pSh->GetView().GetDocShell());
339 
340 	::FillCharStyleListBox(aFtnCharAnchorTemplBox,
341 						pSh->GetView().GetDocShell());
342 }
343 
344 /*------------------------------------------------------------------------
345  Beschreibung:	Handler hinter dem Button fuer Sammeln der Fussnote
346 				auf der Seite.
347 				In diesem Fall koennen alle Numerierungsarten verwendet
348 				werden.
349 ------------------------------------------------------------------------*/
350 
351 
IMPL_LINK(SwEndNoteOptionPage,PosPageHdl,Button *,EMPTYARG)352 IMPL_LINK( SwEndNoteOptionPage, PosPageHdl, Button *, EMPTYARG )
353 {
354 	const SwFtnNum eNum = (const SwFtnNum)GetNumbering();
355 	bPosDoc = sal_False;
356     if(LISTBOX_ENTRY_NOTFOUND == aNumCountBox.GetEntryPos(aNumPage))
357     {
358 		aNumCountBox.InsertEntry(aNumPage, FTNNUM_PAGE);
359         aNumCountBox.InsertEntry(aNumChapter, FTNNUM_CHAPTER);
360         SelectNumbering(eNum);
361 	}
362 	aPageTemplLbl.Enable(sal_False);
363 	aPageTemplBox.Enable(sal_False);
364 
365 	return 0;
366 }
367 
368 /*------------------------------------------------------------------------
369  Beschreibung:
370 ------------------------------------------------------------------------*/
371 
372 
IMPL_LINK(SwEndNoteOptionPage,NumCountHdl,ListBox *,EMPTYARG)373 IMPL_LINK( SwEndNoteOptionPage, NumCountHdl, ListBox*, EMPTYARG )
374 {
375 	sal_Bool bEnable = sal_True;
376 	if( aNumCountBox.GetEntryCount() - 1 != aNumCountBox.GetSelectEntryPos() )
377 	{
378 		bEnable = sal_False;
379 		aOffsetFld.SetValue(1);
380 	}
381 	aOffsetLbl.Enable(bEnable);
382 	aOffsetFld.Enable(bEnable);
383 	return 0;
384 }
385 
386 /*------------------------------------------------------------------------
387  Beschreibung:	Handler hinter dem Button fuer Sammeln der Fussnote
388 				am Kapitel oder Dokumentende.
389 				In diesem Fall kann keine seitenweise Numerierung verwendet
390 				werden.
391 ------------------------------------------------------------------------*/
392 
393 
IMPL_LINK_INLINE_START(SwEndNoteOptionPage,PosChapterHdl,Button *,EMPTYARG)394 IMPL_LINK_INLINE_START( SwEndNoteOptionPage, PosChapterHdl, Button *, EMPTYARG )
395 {
396 	if ( !bPosDoc )
397 		SelectNumbering(FTNNUM_DOC);
398 
399 	bPosDoc = sal_True;
400 	aNumCountBox.RemoveEntry(aNumPage);
401     aNumCountBox.RemoveEntry(aNumChapter);
402     aPageTemplLbl.Enable();
403 	aPageTemplBox.Enable();
404 	return 0;
405 }
IMPL_LINK_INLINE_END(SwEndNoteOptionPage,PosChapterHdl,Button *,EMPTYARG)406 IMPL_LINK_INLINE_END( SwEndNoteOptionPage, PosChapterHdl, Button *, EMPTYARG )
407 
408 SwCharFmt* lcl_GetCharFormat( SwWrtShell* pSh, const String& rCharFmtName )
409 {
410 	SwCharFmt* pFmt = 0;
411 	sal_uInt16 nChCount = pSh->GetCharFmtCount();
412 	for(sal_uInt16 i = 0; i< nChCount; i++)
413 	{
414 		SwCharFmt& rChFmt = pSh->GetCharFmt(i);
415 		if(rChFmt.GetName() == rCharFmtName )
416 		{
417 			pFmt = &rChFmt;
418 			break;
419 		}
420 	}
421 	if(!pFmt)
422 	{
423 		SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
424 		SfxStyleSheetBase* pBase;
425 		pBase = pPool->Find(rCharFmtName, SFX_STYLE_FAMILY_CHAR);
426 		if(!pBase)
427 			pBase = &pPool->Make(rCharFmtName, SFX_STYLE_FAMILY_CHAR);
428 		pFmt = ((SwDocStyleSheet*)pBase)->GetCharFmt();
429 	}
430 	return pFmt;
431 }
432 
FillItemSet(SfxItemSet &)433 sal_Bool SwEndNoteOptionPage::FillItemSet( SfxItemSet & )
434 {
435 	SwEndNoteInfo *pInf = bEndNote ? new SwEndNoteInfo() : new SwFtnInfo();
436 
437     pInf->nFtnOffset = static_cast< sal_uInt16 >(aOffsetFld.GetValue() -1);
438 	pInf->aFmt.SetNumberingType(aNumViewBox.GetSelectedNumberingType() );
439 	pInf->SetPrefix(aPrefixED.GetText());
440 	pInf->SetSuffix(aSuffixED.GetText());
441 
442 	pInf->SetCharFmt( lcl_GetCharFormat( pSh,
443 						aFtnCharTextTemplBox.GetSelectEntry() ) );
444 	pInf->SetAnchorCharFmt( lcl_GetCharFormat( pSh,
445 						aFtnCharAnchorTemplBox.GetSelectEntry() ) );
446 
447 	// Absatzvorlage
448 	sal_uInt16 nPos = aParaTemplBox.GetSelectEntryPos();
449 	if(LISTBOX_ENTRY_NOTFOUND != nPos)
450 	{
451 		const String aFmtName( aParaTemplBox.GetSelectEntry() );
452 		SwTxtFmtColl *pColl = pSh->GetParaStyle(aFmtName, SwWrtShell::GETSTYLE_CREATEANY);
453 		ASSERT(pColl, "Absatzvorlage nicht gefunden.");
454 		pInf->SetFtnTxtColl(*pColl);
455 	}
456 
457 	// Seitenvorlage
458 	pInf->ChgPageDesc( pSh->FindPageDescByName(
459 								aPageTemplBox.GetSelectEntry(), sal_True ) );
460 
461 	if ( bEndNote )
462 	{
463 		if ( !(*pInf == pSh->GetEndNoteInfo()) )
464 			pSh->SetEndNoteInfo( *pInf );
465 	}
466 	else
467 	{
468 		SwFtnInfo *pI = (SwFtnInfo*)pInf;
469 		pI->ePos = aPosPageBox.IsChecked() ? FTNPOS_PAGE : FTNPOS_CHAPTER;
470 		pI->eNum = (SwFtnNum)GetNumbering();
471 		pI->aQuoVadis = aContEdit.GetText();
472 		pI->aErgoSum = aContFromEdit.GetText();
473 		if ( !(*pI == pSh->GetFtnInfo()) )
474 			pSh->SetFtnInfo( *pI );
475 	}
476 	delete pInf;
477 	return sal_True;
478 }
479 
SwFootNoteOptionPage(Window * pParent,const SfxItemSet & rSet)480 SwFootNoteOptionPage::SwFootNoteOptionPage( Window *pParent, const SfxItemSet &rSet ) :
481 	SwEndNoteOptionPage( pParent, sal_False, rSet )
482 {
483 }
484 
~SwFootNoteOptionPage()485 SwFootNoteOptionPage::~SwFootNoteOptionPage()
486 {
487 }
488 
Create(Window * pParent,const SfxItemSet & rSet)489 SfxTabPage *SwFootNoteOptionPage::Create(Window *pParent, const SfxItemSet &rSet )
490 {
491 	return new SwFootNoteOptionPage( pParent, rSet );
492 }
493 
494 
495 
496 
497 
498 
499 
500