merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / misc / docfnote.cxx
blob004b08de43fe55550679f377fe71efa306b58d33
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docfnote.cxx,v $
10 * $Revision: 1.19.224.1 $
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_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
39 #include <svtools/style.hxx>
40 #include <errhdl.hxx>
41 #include <wrtsh.hxx>
42 #ifndef _VIEW_HXX
43 #include <view.hxx>
44 #endif
45 #ifndef _DOCSH_HXX
46 #include <docsh.hxx>
47 #endif
48 #include <docfnote.hxx>
49 #include <impfnote.hxx>
50 #include <ftninfo.hxx>
51 #include <fmtcol.hxx>
52 #include <pagedesc.hxx>
53 #include <charfmt.hxx>
54 #include <docstyle.hxx>
55 #include <wdocsh.hxx>
56 #include <uitool.hxx>
57 #include <poolfmt.hxx>
58 #include <swstyle.h>
59 #ifndef _HELPID_H
60 #include <helpid.h>
61 #endif
62 #ifndef _MISC_HRC
63 #include <misc.hrc>
64 #endif
65 #ifndef _DOCFNOTE_HRC
66 #include <docfnote.hrc>
67 #endif
68 #ifndef _FRMUI_HRC
69 #include <frmui.hrc>
70 #endif
71 #include <SwStyleNameMapper.hxx>
73 SwFootNoteOptionDlg::SwFootNoteOptionDlg( Window *pParent, SwWrtShell &rS ) :
74 SfxTabDialog( pParent, SW_RES(DLG_DOC_FOOTNOTE) ),
75 rSh( rS )
77 FreeResource();
78 RemoveResetButton();
80 aOldOkHdl = GetOKButton().GetClickHdl();
81 GetOKButton().SetClickHdl( LINK( this, SwFootNoteOptionDlg, OkHdl ) );
83 AddTabPage( TP_FOOTNOTEOPTION, SwFootNoteOptionPage::Create, 0 );
84 AddTabPage( TP_ENDNOTEOPTION, SwEndNoteOptionPage::Create, 0 );
87 void SwFootNoteOptionDlg::PageCreated( USHORT /*nId*/, SfxTabPage &rPage )
89 ((SwEndNoteOptionPage&)rPage).SetShell( rSh );
92 SwFootNoteOptionDlg::~SwFootNoteOptionDlg()
96 IMPL_LINK( SwFootNoteOptionDlg, OkHdl, Button *, pBtn )
98 SfxItemSet aDummySet(rSh.GetAttrPool(), 1, 1 );
99 SfxTabPage *pPage = GetTabPage( TP_FOOTNOTEOPTION );
100 if ( pPage )
101 pPage->FillItemSet( aDummySet );
102 pPage = GetTabPage( TP_ENDNOTEOPTION );
103 if ( pPage )
104 pPage->FillItemSet( aDummySet );
105 aOldOkHdl.Call( pBtn );
106 return 0;
110 //----------------------------------------------------------------------
113 SwEndNoteOptionPage::SwEndNoteOptionPage( Window *pParent, BOOL bEN,
114 const SfxItemSet &rSet ) :
115 SfxTabPage( pParent, SW_RES(bEN ? TP_ENDNOTEOPTION : TP_FOOTNOTEOPTION), rSet ),
116 aNumTypeFT (this, SW_RES( FT_NUMTYPE )),
117 aNumViewBox (this, SW_RES( LB_NUMVIEW ), INSERT_NUM_EXTENDED_TYPES),
118 aOffsetLbl (this, SW_RES( FT_OFFSET )),
119 aOffsetFld (this, SW_RES( FLD_OFFSET )),
120 aNumCountFT (this, SW_RES( FT_NUMCOUNT )),
121 aNumCountBox (this, SW_RES( LB_NUMCOUNT )),
122 aPrefixFT (this, SW_RES( FT_PREFIX )),
123 aPrefixED (this, SW_RES( ED_PREFIX )),
124 aSuffixFT (this, SW_RES( FT_SUFFIX )),
125 aSuffixED (this, SW_RES( ED_SUFFIX )),
126 aPosFT (this, SW_RES( FT_POS )),
127 aPosPageBox (this, SW_RES( RB_POS_PAGE )),
128 aPosChapterBox (this, SW_RES( RB_POS_CHAPTER)),
129 aNumFL (this, SW_RES( FL_NUM )),
131 aParaTemplLbl (this, SW_RES( FT_PARA_TEMPL)),
132 aParaTemplBox (this, SW_RES( LB_PARA_TEMPL)),
133 aPageTemplLbl (this, SW_RES( FT_PAGE_TEMPL)),
134 aPageTemplBox (this, SW_RES( LB_PAGE_TEMPL)),
135 aTemplFL (this, SW_RES( FL_TEMPL )),
137 aFtnCharAnchorTemplLbl( this, SW_RES( FT_ANCHR_CHARFMT)),
138 aFtnCharAnchorTemplBox( this, SW_RES( LB_ANCHR_CHARFMT)),
139 aFtnCharTextTemplLbl( this, SW_RES( FT_TEXT_CHARFMT)),
140 aFtnCharTextTemplBox( this, SW_RES( LB_TEXT_CHARFMT)),
141 aCharTemplFL( this, SW_RES(FL_CHAR_TEMPL)),
143 aContLbl (this, SW_RES( FT_CONT )),
144 aContEdit (this, SW_RES( ED_CONT )),
145 aContFromLbl (this, SW_RES( FT_CONT_FROM )),
146 aContFromEdit (this, SW_RES( ED_CONT_FROM )),
147 aContFL (this, SW_RES( FL_CONT )),
149 aNumDoc(aNumCountBox.GetEntry(FTNNUM_DOC)),
150 aNumPage(aNumCountBox.GetEntry(FTNNUM_PAGE)),
151 aNumChapter(aNumCountBox.GetEntry(FTNNUM_CHAPTER)),
152 pSh( 0 ),
153 bPosDoc(FALSE),
154 bEndNote( bEN )
156 FreeResource();
158 aPosPageBox.SetClickHdl(LINK(this, SwEndNoteOptionPage, PosPageHdl));
159 aPosChapterBox.SetClickHdl(LINK(this, SwEndNoteOptionPage, PosChapterHdl));
160 aNumCountBox.SetSelectHdl(LINK(this, SwEndNoteOptionPage, NumCountHdl));
164 void SwEndNoteOptionPage::Reset( const SfxItemSet& )
166 SwEndNoteInfo *pInf = bEndNote ? new SwEndNoteInfo( pSh->GetEndNoteInfo() )
167 : new SwFtnInfo( pSh->GetFtnInfo() );
168 SfxObjectShell * pDocSh = SfxObjectShell::Current();
169 USHORT i;
171 if(PTR_CAST(SwWebDocShell, pDocSh))
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();
184 if ( bEndNote )
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 = TRUE;
196 else
198 const SwFtnInfo &rInf = pSh->GetFtnInfo();
199 // Position (Seite, Kapitel) setzen
200 if ( rInf.ePos == FTNPOS_PAGE )
202 aPosPageBox.Check();
203 aPageTemplLbl.Enable(FALSE);
204 aPageTemplBox.Enable(FALSE);
206 else // if ( rInf.ePos == FTNPOS_CHAPTER )
208 aPosChapterBox.Check();
209 aNumCountBox.RemoveEntry(aNumPage);
210 aNumCountBox.RemoveEntry(aNumChapter);
211 bPosDoc = TRUE;
213 // Verweistexte
214 aContEdit.SetText(rInf.aQuoVadis);
215 aContFromEdit.SetText(rInf.aErgoSum);
217 // gesammelt wo
218 SelectNumbering(rInf.eNum);
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());
228 const SwCharFmt* pCharFmt = pInf->GetCharFmt(
229 *pSh->GetView().GetDocShell()->GetDoc());
230 aFtnCharTextTemplBox.SelectEntry(pCharFmt->GetName());
231 aFtnCharTextTemplBox.SaveValue();
233 pCharFmt = pInf->GetAnchorCharFmt( *pSh->GetDoc() );
234 aFtnCharAnchorTemplBox.SelectEntry( pCharFmt->GetName() );
235 aFtnCharAnchorTemplBox.SaveValue();
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)
244 aParaTemplBox.InsertEntry(pStyle->GetName());
245 pStyle = pStyleSheetPool->Next();
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 );
254 SwTxtFmtColl* pColl = pInf->GetFtnTxtColl();
255 if( !pColl )
256 aParaTemplBox.SelectEntry( sStr ); // Default
257 else
259 ASSERT(!pColl->IsDefault(), "Defaultvorlage fuer Fussnoten ist falsch.");
260 const USHORT nPos = aParaTemplBox.GetEntryPos(pColl->GetName());
261 if( LISTBOX_ENTRY_NOTFOUND != nPos )
262 aParaTemplBox.SelectEntryPos( nPos );
263 else
265 aParaTemplBox.InsertEntry(pColl->GetName());
266 aParaTemplBox.SelectEntry(pColl->GetName());
270 // Seite
271 for( i = RES_POOLPAGE_BEGIN; i <= RES_POOLPAGE_LANDSCAPE; ++i )
272 aPageTemplBox.InsertEntry(SwStyleNameMapper::GetUIName( i, aEmptyStr ));
274 USHORT nCount = pSh->GetPageDescCnt();
275 for(i = 0; i < nCount; ++i)
277 const SwPageDesc &rPageDesc = pSh->GetPageDesc(i);
278 if(LISTBOX_ENTRY_NOTFOUND == aPageTemplBox.GetEntryPos(rPageDesc.GetName()))
279 aPageTemplBox.InsertEntry(rPageDesc.GetName());
282 aPageTemplBox.SelectEntry( pInf->GetPageDesc( *pSh->GetDoc() )->GetName());
283 delete pInf;
286 SwEndNoteOptionPage::~SwEndNoteOptionPage()
290 SfxTabPage *SwEndNoteOptionPage::Create( Window *pParent, const SfxItemSet &rSet )
292 return new SwEndNoteOptionPage( pParent, TRUE, rSet );
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)
303 String sSelect;
304 switch(eNum)
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
320 aNumCountBox.SelectEntry(sSelect);
321 NumCountHdl( &aNumCountBox );
326 int SwEndNoteOptionPage::GetNumbering() const
328 const USHORT nPos = aNumCountBox.GetSelectEntryPos();
329 return (int) bPosDoc? nPos + 1: nPos;
332 /*-----------------09.02.98 11:17-------------------
334 --------------------------------------------------*/
335 void SwEndNoteOptionPage::SetShell( SwWrtShell &rShell )
337 pSh = &rShell;
338 // Zeichenvorlagen sammeln
339 aFtnCharTextTemplBox.Clear();
340 aFtnCharAnchorTemplBox.Clear();
341 ::FillCharStyleListBox(aFtnCharTextTemplBox,
342 pSh->GetView().GetDocShell());
344 ::FillCharStyleListBox(aFtnCharAnchorTemplBox,
345 pSh->GetView().GetDocShell());
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 ------------------------------------------------------------------------*/
356 IMPL_LINK( SwEndNoteOptionPage, PosPageHdl, Button *, EMPTYARG )
358 const SwFtnNum eNum = (const SwFtnNum)GetNumbering();
359 bPosDoc = FALSE;
360 if(LISTBOX_ENTRY_NOTFOUND == aNumCountBox.GetEntryPos(aNumPage))
362 aNumCountBox.InsertEntry(aNumPage, FTNNUM_PAGE);
363 aNumCountBox.InsertEntry(aNumChapter, FTNNUM_CHAPTER);
364 SelectNumbering(eNum);
366 aPageTemplLbl.Enable(FALSE);
367 aPageTemplBox.Enable(FALSE);
369 return 0;
372 /*------------------------------------------------------------------------
373 Beschreibung:
374 ------------------------------------------------------------------------*/
377 IMPL_LINK( SwEndNoteOptionPage, NumCountHdl, ListBox*, EMPTYARG )
379 BOOL bEnable = TRUE;
380 if( aNumCountBox.GetEntryCount() - 1 != aNumCountBox.GetSelectEntryPos() )
382 bEnable = FALSE;
383 aOffsetFld.SetValue(1);
385 aOffsetLbl.Enable(bEnable);
386 aOffsetFld.Enable(bEnable);
387 return 0;
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 ------------------------------------------------------------------------*/
398 IMPL_LINK_INLINE_START( SwEndNoteOptionPage, PosChapterHdl, Button *, EMPTYARG )
400 if ( !bPosDoc )
401 SelectNumbering(FTNNUM_DOC);
403 bPosDoc = TRUE;
404 aNumCountBox.RemoveEntry(aNumPage);
405 aNumCountBox.RemoveEntry(aNumChapter);
406 aPageTemplLbl.Enable();
407 aPageTemplBox.Enable();
408 return 0;
410 IMPL_LINK_INLINE_END( SwEndNoteOptionPage, PosChapterHdl, Button *, EMPTYARG )
412 SwCharFmt* lcl_GetCharFormat( SwWrtShell* pSh, const String& rCharFmtName )
414 SwCharFmt* pFmt = 0;
415 USHORT nChCount = pSh->GetCharFmtCount();
416 for(USHORT i = 0; i< nChCount; i++)
418 SwCharFmt& rChFmt = pSh->GetCharFmt(i);
419 if(rChFmt.GetName() == rCharFmtName )
421 pFmt = &rChFmt;
422 break;
425 if(!pFmt)
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();
434 return pFmt;
437 BOOL SwEndNoteOptionPage::FillItemSet( SfxItemSet & )
439 SwEndNoteInfo *pInf = bEndNote ? new SwEndNoteInfo() : new SwFtnInfo();
441 pInf->nFtnOffset = static_cast< USHORT >(aOffsetFld.GetValue() -1);
442 pInf->aFmt.SetNumberingType(aNumViewBox.GetSelectedNumberingType() );
443 pInf->SetPrefix(aPrefixED.GetText());
444 pInf->SetSuffix(aSuffixED.GetText());
446 pInf->SetCharFmt( lcl_GetCharFormat( pSh,
447 aFtnCharTextTemplBox.GetSelectEntry() ) );
448 pInf->SetAnchorCharFmt( lcl_GetCharFormat( pSh,
449 aFtnCharAnchorTemplBox.GetSelectEntry() ) );
451 // Absatzvorlage
452 USHORT nPos = aParaTemplBox.GetSelectEntryPos();
453 if(LISTBOX_ENTRY_NOTFOUND != nPos)
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);
461 // Seitenvorlage
462 pInf->ChgPageDesc( pSh->FindPageDescByName(
463 aPageTemplBox.GetSelectEntry(), TRUE ) );
465 if ( bEndNote )
467 if ( !(*pInf == pSh->GetEndNoteInfo()) )
468 pSh->SetEndNoteInfo( *pInf );
470 else
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 );
480 delete pInf;
481 return TRUE;
484 SwFootNoteOptionPage::SwFootNoteOptionPage( Window *pParent, const SfxItemSet &rSet ) :
485 SwEndNoteOptionPage( pParent, FALSE, rSet )
489 SwFootNoteOptionPage::~SwFootNoteOptionPage()
493 SfxTabPage *SwFootNoteOptionPage::Create(Window *pParent, const SfxItemSet &rSet )
495 return new SwFootNoteOptionPage( pParent, rSet );