1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svl/style.hxx>
24 #include <docfnote.hxx>
25 #include <impfnote.hxx>
26 #include <ftninfo.hxx>
28 #include <pagedesc.hxx>
29 #include <charfmt.hxx>
30 #include <docstyle.hxx>
33 #include <poolfmt.hxx>
38 #include <SwStyleNameMapper.hxx>
40 SwFootNoteOptionDlg::SwFootNoteOptionDlg( Window
*pParent
, SwWrtShell
&rS
) :
41 SfxTabDialog( pParent
, SW_RES(DLG_DOC_FOOTNOTE
) ),
47 aOldOkHdl
= GetOKButton().GetClickHdl();
48 GetOKButton().SetClickHdl( LINK( this, SwFootNoteOptionDlg
, OkHdl
) );
50 AddTabPage( TP_FOOTNOTEOPTION
, SwFootNoteOptionPage::Create
, 0 );
51 AddTabPage( TP_ENDNOTEOPTION
, SwEndNoteOptionPage::Create
, 0 );
54 void SwFootNoteOptionDlg::PageCreated( sal_uInt16
/*nId*/, SfxTabPage
&rPage
)
56 ((SwEndNoteOptionPage
&)rPage
).SetShell( rSh
);
59 SwFootNoteOptionDlg::~SwFootNoteOptionDlg()
63 IMPL_LINK( SwFootNoteOptionDlg
, OkHdl
, Button
*, pBtn
)
65 SfxItemSet
aDummySet(rSh
.GetAttrPool(), 1, 1 );
66 SfxTabPage
*pPage
= GetTabPage( TP_FOOTNOTEOPTION
);
68 pPage
->FillItemSet( aDummySet
);
69 pPage
= GetTabPage( TP_ENDNOTEOPTION
);
71 pPage
->FillItemSet( aDummySet
);
72 aOldOkHdl
.Call( pBtn
);
77 //----------------------------------------------------------------------
80 SwEndNoteOptionPage::SwEndNoteOptionPage(Window
*pParent
, bool bEN
,
81 const SfxItemSet
&rSet
)
83 bEN
? OString("EndnotePage") : OString("FootnotePage"),
84 bEN
? OUString("modules/swriter/ui/endnotepage.ui") : OUString("modules/swriter/ui/footnotepage.ui"),
90 get(m_pNumViewBox
, "numberinglb");
91 get(m_pOffsetLbl
, "offset");
92 get(m_pOffsetFld
, "offsetnf");
93 get(m_pPrefixED
, "prefix");
94 get(m_pSuffixED
, "suffix");
98 get(m_pNumCountBox
, "countinglb");
99 m_pNumCountBox
->SetSelectHdl(LINK(this, SwEndNoteOptionPage
, NumCountHdl
));
100 aNumDoc
= m_pNumCountBox
->GetEntry(FTNNUM_DOC
);
101 aNumPage
= m_pNumCountBox
->GetEntry(FTNNUM_PAGE
);
102 aNumChapter
= m_pNumCountBox
->GetEntry(FTNNUM_CHAPTER
);
103 get(m_pPosPageBox
, "pospagecb");
104 m_pPosPageBox
->SetClickHdl(LINK(this, SwEndNoteOptionPage
, PosPageHdl
));
105 get(m_pPosChapterBox
, "posdoccb");
106 m_pPosChapterBox
->SetClickHdl(LINK(this, SwEndNoteOptionPage
, PosChapterHdl
));
107 get(m_pPosFT
, "pos");
108 m_pPosPageBox
->SetAccessibleRelationMemberOf(m_pPosFT
);
109 m_pPosChapterBox
->SetAccessibleRelationMemberOf(m_pPosFT
);
110 get(m_pContEdit
, "conted");
111 get(m_pContFromEdit
, "contfromed");
114 get(m_pStylesContainer
, "allstyles");
115 get(m_pParaTemplBox
, "parastylelb");
116 get(m_pPageTemplLbl
, "pagestyleft");
117 get(m_pPageTemplBox
, "pagestylelb");
118 get(m_pFtnCharAnchorTemplBox
, "charanchorstylelb");
119 get(m_pFtnCharTextTemplBox
, "charstylelb");
122 void SwEndNoteOptionPage::Reset( const SfxItemSet
& )
124 SwEndNoteInfo
*pInf
= bEndNote
? new SwEndNoteInfo( pSh
->GetEndNoteInfo() )
125 : new SwFtnInfo( pSh
->GetFtnInfo() );
126 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
129 if (PTR_CAST(SwWebDocShell
, pDocSh
))
130 m_pStylesContainer
->Hide();
138 const SwFtnInfo
&rInf
= pSh
->GetFtnInfo();
139 // set position (page, chapter)
140 if ( rInf
.ePos
== FTNPOS_PAGE
)
142 m_pPosPageBox
->Check();
143 m_pPageTemplLbl
->Enable(sal_False
);
144 m_pPageTemplBox
->Enable(sal_False
);
148 m_pPosChapterBox
->Check();
149 m_pNumCountBox
->RemoveEntry(aNumPage
);
150 m_pNumCountBox
->RemoveEntry(aNumChapter
);
154 m_pContEdit
->SetText(rInf
.aQuoVadis
);
155 m_pContFromEdit
->SetText(rInf
.aErgoSum
);
158 SelectNumbering(rInf
.eNum
);
163 m_pNumViewBox
->SelectNumberingType( pInf
->aFmt
.GetNumberingType());
164 m_pOffsetFld
->SetValue(pInf
->nFtnOffset
+ 1);
165 m_pPrefixED
->SetText(pInf
->GetPrefix().replaceAll("\t", "\\t")); // fdo#65666
166 m_pSuffixED
->SetText(pInf
->GetSuffix().replaceAll("\t", "\\t"));
168 const SwCharFmt
* pCharFmt
= pInf
->GetCharFmt(
169 *pSh
->GetView().GetDocShell()->GetDoc());
170 m_pFtnCharTextTemplBox
->SelectEntry(pCharFmt
->GetName());
171 m_pFtnCharTextTemplBox
->SaveValue();
173 pCharFmt
= pInf
->GetAnchorCharFmt( *pSh
->GetDoc() );
174 m_pFtnCharAnchorTemplBox
->SelectEntry( pCharFmt
->GetName() );
175 m_pFtnCharAnchorTemplBox
->SaveValue();
177 // styles special regions
179 SfxStyleSheetBasePool
* pStyleSheetPool
= pSh
->GetView().GetDocShell()->GetStyleSheetPool();
180 pStyleSheetPool
->SetSearchMask(SFX_STYLE_FAMILY_PARA
, SWSTYLEBIT_EXTRA
);
181 SfxStyleSheetBase
*pStyle
= pStyleSheetPool
->First();
184 m_pParaTemplBox
->InsertEntry(pStyle
->GetName());
185 pStyle
= pStyleSheetPool
->Next();
189 SwStyleNameMapper::FillUIName( static_cast< sal_uInt16
>(bEndNote
? RES_POOLCOLL_ENDNOTE
190 : RES_POOLCOLL_FOOTNOTE
), sStr
);
191 if(LISTBOX_ENTRY_NOTFOUND
== m_pParaTemplBox
->GetEntryPos( sStr
) )
192 m_pParaTemplBox
->InsertEntry( sStr
);
194 SwTxtFmtColl
* pColl
= pInf
->GetFtnTxtColl();
196 m_pParaTemplBox
->SelectEntry( sStr
); // Default
199 OSL_ENSURE(!pColl
->IsDefault(), "default style for footnotes is wrong");
200 const sal_uInt16 nPos
= m_pParaTemplBox
->GetEntryPos(pColl
->GetName());
201 if( LISTBOX_ENTRY_NOTFOUND
!= nPos
)
202 m_pParaTemplBox
->SelectEntryPos( nPos
);
205 m_pParaTemplBox
->InsertEntry(pColl
->GetName());
206 m_pParaTemplBox
->SelectEntry(pColl
->GetName());
211 for( i
= RES_POOLPAGE_BEGIN
; i
< RES_POOLPAGE_END
; ++i
)
212 m_pPageTemplBox
->InsertEntry(SwStyleNameMapper::GetUIName( i
, aEmptyStr
));
214 sal_uInt16 nCount
= pSh
->GetPageDescCnt();
215 for(i
= 0; i
< nCount
; ++i
)
217 const SwPageDesc
&rPageDesc
= pSh
->GetPageDesc(i
);
218 if(LISTBOX_ENTRY_NOTFOUND
== m_pPageTemplBox
->GetEntryPos(rPageDesc
.GetName()))
219 m_pPageTemplBox
->InsertEntry(rPageDesc
.GetName());
222 m_pPageTemplBox
->SelectEntry( pInf
->GetPageDesc( *pSh
->GetDoc() )->GetName());
226 SwEndNoteOptionPage::~SwEndNoteOptionPage()
230 SfxTabPage
*SwEndNoteOptionPage::Create( Window
*pParent
, const SfxItemSet
&rSet
)
232 return new SwEndNoteOptionPage( pParent
, true, rSet
);
235 /*------------------------------------------------------------------------
236 Description: Different kinds of numbering; because the Listbox has
237 varying numbers of entries, here are functions to
238 set and query the intended kind of numbering.
239 ------------------------------------------------------------------------*/
240 void SwEndNoteOptionPage::SelectNumbering(int eNum
)
252 sSelect
= aNumChapter
;
254 #if OSL_DEBUG_LEVEL > 0
256 OSL_FAIL("Which numbering type?");
259 m_pNumCountBox
->SelectEntry(sSelect
);
260 NumCountHdl(m_pNumCountBox
);
265 int SwEndNoteOptionPage::GetNumbering() const
267 const sal_uInt16 nPos
= m_pNumCountBox
->GetSelectEntryPos();
268 return (int) bPosDoc
? nPos
+ 1: nPos
;
271 void SwEndNoteOptionPage::SetShell( SwWrtShell
&rShell
)
274 // collect character templates
275 m_pFtnCharTextTemplBox
->Clear();
276 m_pFtnCharAnchorTemplBox
->Clear();
277 ::FillCharStyleListBox(*m_pFtnCharTextTemplBox
,
278 pSh
->GetView().GetDocShell());
280 ::FillCharStyleListBox(*m_pFtnCharAnchorTemplBox
,
281 pSh
->GetView().GetDocShell());
284 /*------------------------------------------------------------------------
285 Description: Handler behind the button to collect the footnote at the
286 page. In this case all kinds of numbering can be used.
287 ------------------------------------------------------------------------*/
290 IMPL_LINK_NOARG(SwEndNoteOptionPage
, PosPageHdl
)
292 const SwFtnNum eNum
= (const SwFtnNum
)GetNumbering();
294 if(LISTBOX_ENTRY_NOTFOUND
== m_pNumCountBox
->GetEntryPos(aNumPage
))
296 m_pNumCountBox
->InsertEntry(aNumPage
, FTNNUM_PAGE
);
297 m_pNumCountBox
->InsertEntry(aNumChapter
, FTNNUM_CHAPTER
);
298 SelectNumbering(eNum
);
300 m_pPageTemplLbl
->Enable(sal_False
);
301 m_pPageTemplBox
->Enable(sal_False
);
306 IMPL_LINK_NOARG(SwEndNoteOptionPage
, NumCountHdl
)
308 sal_Bool bEnable
= sal_True
;
309 if( m_pNumCountBox
->GetEntryCount() - 1 != m_pNumCountBox
->GetSelectEntryPos() )
312 m_pOffsetFld
->SetValue(1);
314 m_pOffsetLbl
->Enable(bEnable
);
315 m_pOffsetFld
->Enable(bEnable
);
319 /*------------------------------------------------------------------------
320 Description: Handler behind the button to collect the footnote at the
321 chapter or end of the document. In this case no pagewise
322 numbering can be used.
323 ------------------------------------------------------------------------*/
326 IMPL_LINK_NOARG_INLINE_START(SwEndNoteOptionPage
, PosChapterHdl
)
329 SelectNumbering(FTNNUM_DOC
);
332 m_pNumCountBox
->RemoveEntry(aNumPage
);
333 m_pNumCountBox
->RemoveEntry(aNumChapter
);
334 m_pPageTemplLbl
->Enable();
335 m_pPageTemplBox
->Enable();
338 IMPL_LINK_NOARG_INLINE_END(SwEndNoteOptionPage
, PosChapterHdl
)
340 static SwCharFmt
* lcl_GetCharFormat( SwWrtShell
* pSh
, const String
& rCharFmtName
)
343 sal_uInt16 nChCount
= pSh
->GetCharFmtCount();
344 for(sal_uInt16 i
= 0; i
< nChCount
; i
++)
346 SwCharFmt
& rChFmt
= pSh
->GetCharFmt(i
);
347 if(rChFmt
.GetName() == rCharFmtName
)
355 SfxStyleSheetBasePool
* pPool
= pSh
->GetView().GetDocShell()->GetStyleSheetPool();
356 SfxStyleSheetBase
* pBase
;
357 pBase
= pPool
->Find(rCharFmtName
, SFX_STYLE_FAMILY_CHAR
);
359 pBase
= &pPool
->Make(rCharFmtName
, SFX_STYLE_FAMILY_CHAR
);
360 pFmt
= ((SwDocStyleSheet
*)pBase
)->GetCharFmt();
365 sal_Bool
SwEndNoteOptionPage::FillItemSet( SfxItemSet
& )
367 SwEndNoteInfo
*pInf
= bEndNote
? new SwEndNoteInfo() : new SwFtnInfo();
369 pInf
->nFtnOffset
= static_cast< sal_uInt16
>(m_pOffsetFld
->GetValue() -1);
370 pInf
->aFmt
.SetNumberingType(m_pNumViewBox
->GetSelectedNumberingType() );
371 pInf
->SetPrefix(m_pPrefixED
->GetText().replaceAll("\\t", "\t"));
372 pInf
->SetSuffix(m_pSuffixED
->GetText().replaceAll("\\t", "\t"));
374 pInf
->SetCharFmt( lcl_GetCharFormat( pSh
,
375 m_pFtnCharTextTemplBox
->GetSelectEntry() ) );
376 pInf
->SetAnchorCharFmt( lcl_GetCharFormat( pSh
,
377 m_pFtnCharAnchorTemplBox
->GetSelectEntry() ) );
379 // paragraph template
380 sal_uInt16 nPos
= m_pParaTemplBox
->GetSelectEntryPos();
381 if(LISTBOX_ENTRY_NOTFOUND
!= nPos
)
383 const String
aFmtName( m_pParaTemplBox
->GetSelectEntry() );
384 SwTxtFmtColl
*pColl
= pSh
->GetParaStyle(aFmtName
, SwWrtShell::GETSTYLE_CREATEANY
);
385 OSL_ENSURE(pColl
, "paragraph style not found");
386 pInf
->SetFtnTxtColl(*pColl
);
390 pInf
->ChgPageDesc( pSh
->FindPageDescByName(
391 m_pPageTemplBox
->GetSelectEntry(), sal_True
) );
395 if ( !(*pInf
== pSh
->GetEndNoteInfo()) )
396 pSh
->SetEndNoteInfo( *pInf
);
400 SwFtnInfo
*pI
= (SwFtnInfo
*)pInf
;
401 pI
->ePos
= m_pPosPageBox
->IsChecked() ? FTNPOS_PAGE
: FTNPOS_CHAPTER
;
402 pI
->eNum
= (SwFtnNum
)GetNumbering();
403 pI
->aQuoVadis
= m_pContEdit
->GetText();
404 pI
->aErgoSum
= m_pContFromEdit
->GetText();
405 if ( !(*pI
== pSh
->GetFtnInfo()) )
406 pSh
->SetFtnInfo( *pI
);
412 SwFootNoteOptionPage::SwFootNoteOptionPage( Window
*pParent
, const SfxItemSet
&rSet
) :
413 SwEndNoteOptionPage( pParent
, false, rSet
)
417 SwFootNoteOptionPage::~SwFootNoteOptionPage()
421 SfxTabPage
*SwFootNoteOptionPage::Create(Window
*pParent
, const SfxItemSet
&rSet
)
423 return new SwFootNoteOptionPage( pParent
, rSet
);
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */