update dev300-m58
[ooovba.git] / sw / source / ui / misc / linenum.cxx
blobc799cb9ec956021579243a67ea39f13cfc0e415f
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: linenum.cxx,v $
10 * $Revision: 1.12 $
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 <sfx2/viewfrm.hxx>
40 #include <svtools/style.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <view.hxx>
43 #include <wrtsh.hxx>
44 #include <docsh.hxx>
45 #include <charfmt.hxx>
47 //#ifndef _FLDMGR_HXX //autogen
48 //#include <fldmgr.hxx>
49 //#endif
52 #include <docstyle.hxx>
54 #include "fldbas.hxx"
55 #include "lineinfo.hxx"
56 #include "globals.hrc"
57 #include "linenum.hrc"
58 #include "linenum.hxx"
59 #include "uitool.hxx"
61 #include <IDocumentStylePoolAccess.hxx>
63 /*--------------------------------------------------------------------
64 Beschreibung:
65 --------------------------------------------------------------------*/
67 SwLineNumberingDlg::SwLineNumberingDlg(SwView *pVw) :
68 SfxSingleTabDialog(&pVw->GetViewFrame()->GetWindow(), 0, 0),
69 pSh(pVw->GetWrtShellPtr())
71 // TabPage erzeugen
72 SetTabPage(SwLineNumberingPage::Create(this, *(SfxItemSet*)0));
74 GetOKButton()->SetClickHdl(LINK(this, SwLineNumberingDlg, OKHdl));
77 /*--------------------------------------------------------------------
78 Beschreibung:
79 --------------------------------------------------------------------*/
81 __EXPORT SwLineNumberingDlg::~SwLineNumberingDlg()
85 /*--------------------------------------------------------------------
86 Beschreibung:
87 --------------------------------------------------------------------*/
89 IMPL_LINK( SwLineNumberingDlg, OKHdl, Button *, EMPTYARG )
91 if (GetOKButton()->IsEnabled())
93 SfxTabPage* pCurPage = GetTabPage();
94 if( pCurPage )
95 pCurPage->FillItemSet(*(SfxItemSet*)0);
97 EndDialog( RET_OK );
100 return 0;
103 /*-----------------------------------------------------------------------
104 Beschreibung:
105 -----------------------------------------------------------------------*/
107 SwLineNumberingPage::SwLineNumberingPage( Window* pParent,
108 const SfxItemSet& rSet )
109 : SfxTabPage(pParent, SW_RES(TP_LINENUMBERING), rSet),
110 aNumberingOnCB ( this, SW_RES( CB_NUMBERING_ON )),
111 aCharStyleFT ( this, SW_RES( FT_CHAR_STYLE )),
112 aCharStyleLB ( this, SW_RES( LB_CHAR_STYLE )),
113 aFormatFT ( this, SW_RES( FT_FORMAT )),
114 aFormatLB ( this, SW_RES( LB_FORMAT ), INSERT_NUM_EXTENDED_TYPES),
115 aPosFT ( this, SW_RES( FT_POS )),
116 aPosLB ( this, SW_RES( LB_POS )),
117 aOffsetFT ( this, SW_RES( FT_OFFSET )),
118 aOffsetMF ( this, SW_RES( MF_OFFSET )),
119 aNumIntervalFT ( this, SW_RES( FT_NUM_INVERVAL )),
120 aNumIntervalNF ( this, SW_RES( NF_NUM_INVERVAL )),
121 aNumRowsFT ( this, SW_RES( FT_NUM_ROWS )),
122 aDisplayFL ( this, SW_RES( FL_DISPLAY )),
123 aDivisorFT ( this, SW_RES( FT_DIVISOR )),
124 aDivisorED ( this, SW_RES( ED_DIVISOR )),
125 aDivIntervalFT ( this, SW_RES( FT_DIV_INTERVAL )),
126 aDivIntervalNF ( this, SW_RES( NF_DIV_INTERVAL )),
127 aDivRowsFT ( this, SW_RES( FT_DIV_ROWS )),
128 aDivisorFL ( this, SW_RES( FL_DIVISOR )),
129 aCountEmptyLinesCB ( this, SW_RES( CB_COUNT_EMPTYLINES )),
130 aCountFrameLinesCB ( this, SW_RES( CB_COUNT_FRAMELINES )),
131 aRestartEachPageCB ( this, SW_RES( CB_RESTART_PAGE )),
132 aCountFL ( this, SW_RES( FL_COUNT ))
135 FreeResource();
136 SwLineNumberingDlg *pDlg = (SwLineNumberingDlg *)GetParent();
137 pSh = pDlg->GetWrtShell();
138 // Zeichenvorlagen
139 ::FillCharStyleListBox(aCharStyleLB, pSh->GetView().GetDocShell());
142 /*-----------------------------------------------------------------------
143 Beschreibung:
144 -----------------------------------------------------------------------*/
146 __EXPORT SwLineNumberingPage::~SwLineNumberingPage()
150 /*-----------------------------------------------------------------------
151 Beschreibung:
152 -----------------------------------------------------------------------*/
154 SfxTabPage* __EXPORT SwLineNumberingPage::Create( Window* pParent, const SfxItemSet& rSet )
156 return new SwLineNumberingPage( pParent, rSet );
159 /*-----------------------------------------------------------------------
160 Beschreibung:
161 -----------------------------------------------------------------------*/
163 void __EXPORT SwLineNumberingPage::Reset( const SfxItemSet& )
165 const SwLineNumberInfo &rInf = pSh->GetLineNumberInfo();
166 IDocumentStylePoolAccess* pIDSPA = pSh->getIDocumentStylePoolAccess();
168 String sStyleName(rInf.GetCharFmt( *pIDSPA )->GetName());
169 const USHORT nPos = aCharStyleLB.GetEntryPos(sStyleName);
171 if (nPos != LISTBOX_ENTRY_NOTFOUND)
172 aCharStyleLB.SelectEntryPos(nPos);
173 else
175 if (sStyleName.Len())
177 aCharStyleLB.InsertEntry(sStyleName);
178 aCharStyleLB.SelectEntry(sStyleName);
182 // Format
183 // SwFldMgr aMgr( pSh );
184 USHORT nSelFmt = rInf.GetNumType().GetNumberingType();
185 // USHORT nCnt = aMgr.GetFormatCount( TYP_SEQFLD, FALSE );
187 // for( USHORT i = 0; i < nCnt; i++)
188 // {
189 // aFormatLB.InsertEntry(aMgr.GetFormatStr( TYP_SEQFLD, i));
190 // USHORT nFmtId = aMgr.GetFormatId( TYP_SEQFLD, i );
191 // aFormatLB.SetEntryData( i, (void*)nFmtId );
192 // if( nFmtId == nSelFmt )
193 // aFormatLB.SelectEntryPos( i );
194 // }
195 aFormatLB.SelectNumberingType(nSelFmt);
197 // if ( !aFormatLB.GetSelectEntryCount() )
198 // aFormatLB.SelectEntryPos(aFormatLB.GetEntryCount() - 1);
200 // Position
201 aPosLB.SelectEntryPos((USHORT)rInf.GetPos());
203 // Offset
204 USHORT nOffset = rInf.GetPosFromLeft();
205 if (nOffset == USHRT_MAX)
206 nOffset = 0;
208 aOffsetMF.SetValue(aOffsetMF.Normalize(nOffset), FUNIT_TWIP);
210 // Numerierungsoffset
211 aNumIntervalNF.SetValue(rInf.GetCountBy());
213 // Teiler
214 aDivisorED.SetText(rInf.GetDivider());
216 // Teileroffset
217 aDivIntervalNF.SetValue(rInf.GetDividerCountBy());
219 // Zaehlen
220 aCountEmptyLinesCB.Check(rInf.IsCountBlankLines());
221 aCountFrameLinesCB.Check(rInf.IsCountInFlys());
222 aRestartEachPageCB.Check(rInf.IsRestartEachPage());
224 aNumberingOnCB.Check(rInf.IsPaintLineNumbers());
226 aNumberingOnCB.SetClickHdl(LINK(this, SwLineNumberingPage, LineOnOffHdl));
227 aDivisorED.SetModifyHdl(LINK(this, SwLineNumberingPage, ModifyHdl));
228 ModifyHdl();
229 LineOnOffHdl();
232 /*--------------------------------------------------------------------
233 Beschreibung: Modify
234 --------------------------------------------------------------------*/
236 IMPL_LINK( SwLineNumberingPage, ModifyHdl, Edit *, EMPTYARG )
238 BOOL bHasValue = aDivisorED.GetText().Len() != 0;
240 aDivIntervalFT.Enable(bHasValue);
241 aDivIntervalNF.Enable(bHasValue);
242 aDivRowsFT.Enable(bHasValue);
244 return 0;
247 /*--------------------------------------------------------------------
248 Beschreibung: On/Off
249 --------------------------------------------------------------------*/
251 IMPL_LINK( SwLineNumberingPage, LineOnOffHdl, CheckBox *, EMPTYARG )
253 BOOL bEnable = aNumberingOnCB.IsChecked();
255 aCharStyleFT.Enable(bEnable);
256 aCharStyleLB.Enable(bEnable);
257 aFormatFT.Enable(bEnable);
258 aFormatLB.Enable(bEnable);
259 aPosFT.Enable(bEnable);
260 aPosLB.Enable(bEnable);
261 aOffsetFT.Enable(bEnable);
262 aOffsetMF.Enable(bEnable);
263 aNumIntervalFT.Enable(bEnable);
264 aNumIntervalNF.Enable(bEnable);
265 aNumRowsFT.Enable(bEnable);
266 aDisplayFL.Enable(bEnable);
267 aDivisorFT.Enable(bEnable);
268 aDivisorED.Enable(bEnable);
269 aDivIntervalFT.Enable(bEnable);
270 aDivIntervalNF.Enable(bEnable);
271 aDivRowsFT.Enable(bEnable);
272 aDivisorFL.Enable(bEnable);
273 aCountEmptyLinesCB.Enable(bEnable);
274 aCountFrameLinesCB.Enable(bEnable);
275 aRestartEachPageCB.Enable(bEnable);
276 aCountFL.Enable(bEnable);
278 return 0;
281 /*-----------------------------------------------------------------------
282 Beschreibung:
283 -----------------------------------------------------------------------*/
285 BOOL __EXPORT SwLineNumberingPage::FillItemSet( SfxItemSet& )
287 SwLineNumberInfo aInf(pSh->GetLineNumberInfo());
289 // Zeichenvorlagen
290 String sCharFmtName(aCharStyleLB.GetSelectEntry());
291 SwCharFmt *pCharFmt = pSh->FindCharFmtByName(sCharFmtName);
293 if (!pCharFmt)
295 SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
296 SfxStyleSheetBase* pBase;
297 pBase = pPool->Find(sCharFmtName, SFX_STYLE_FAMILY_CHAR);
298 if(!pBase)
299 pBase = &pPool->Make(sCharFmtName, SFX_STYLE_FAMILY_CHAR);
300 pCharFmt = ((SwDocStyleSheet*)pBase)->GetCharFmt();
303 if (pCharFmt)
304 aInf.SetCharFmt(pCharFmt);
306 // Format
307 SvxNumberType aType;
308 aType.SetNumberingType(aFormatLB.GetSelectedNumberingType());
309 aInf.SetNumType(aType);
311 // Position
312 aInf.SetPos((LineNumberPosition)aPosLB.GetSelectEntryPos());
314 // Offset
315 aInf.SetPosFromLeft((USHORT)aOffsetMF.Denormalize(aOffsetMF.GetValue(FUNIT_TWIP)));
317 // Numerierungsoffset
318 aInf.SetCountBy((USHORT)aNumIntervalNF.GetValue());
320 // Teiler
321 aInf.SetDivider(aDivisorED.GetText());
323 // Teileroffset
324 aInf.SetDividerCountBy((USHORT)aDivIntervalNF.GetValue());
326 // Zaehlen
327 aInf.SetCountBlankLines(aCountEmptyLinesCB.IsChecked());
328 aInf.SetCountInFlys(aCountFrameLinesCB.IsChecked());
329 aInf.SetRestartEachPage(aRestartEachPageCB.IsChecked());
331 aInf.SetPaintLineNumbers(aNumberingOnCB.IsChecked());
333 pSh->SetLineNumberInfo(aInf);
335 return FALSE;