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