xref: /trunk/main/sw/source/ui/misc/linenum.cxx (revision cdf0e10c)
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 <sfx2/viewfrm.hxx>
37 #include <svl/style.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <view.hxx>
40 #include <wrtsh.hxx>
41 #include <docsh.hxx>
42 #include <charfmt.hxx>
43 
44 //#ifndef _FLDMGR_HXX //autogen
45 //#include <fldmgr.hxx>
46 //#endif
47 
48 
49 #include <docstyle.hxx>
50 
51 #include "fldbas.hxx"
52 #include "lineinfo.hxx"
53 #include "globals.hrc"
54 #include "linenum.hrc"
55 #include "linenum.hxx"
56 #include "uitool.hxx"
57 
58 #include <IDocumentStylePoolAccess.hxx>
59 
60 /*--------------------------------------------------------------------
61 	Beschreibung:
62  --------------------------------------------------------------------*/
63 
64 SwLineNumberingDlg::SwLineNumberingDlg(SwView *pVw) :
65 	SfxSingleTabDialog(&pVw->GetViewFrame()->GetWindow(), 0, 0),
66 	pSh(pVw->GetWrtShellPtr())
67 {
68 	// TabPage erzeugen
69     SetTabPage(SwLineNumberingPage::Create(this, *(SfxItemSet*)0));
70 
71 	GetOKButton()->SetClickHdl(LINK(this, SwLineNumberingDlg, OKHdl));
72 }
73 
74 /*--------------------------------------------------------------------
75 	Beschreibung:
76  --------------------------------------------------------------------*/
77 
78 __EXPORT SwLineNumberingDlg::~SwLineNumberingDlg()
79 {
80 }
81 
82 /*--------------------------------------------------------------------
83 	 Beschreibung:
84  --------------------------------------------------------------------*/
85 
86 IMPL_LINK( SwLineNumberingDlg, OKHdl, Button *, EMPTYARG )
87 {
88 	if (GetOKButton()->IsEnabled())
89 	{
90         SfxTabPage* pCurPage = GetTabPage();
91         if( pCurPage )
92             pCurPage->FillItemSet(*(SfxItemSet*)0);
93 
94 		EndDialog( RET_OK );
95 	}
96 
97 	return 0;
98 }
99 
100 /*-----------------------------------------------------------------------
101 	Beschreibung:
102  -----------------------------------------------------------------------*/
103 
104 SwLineNumberingPage::SwLineNumberingPage( Window* pParent,
105 													const SfxItemSet& rSet )
106 	: SfxTabPage(pParent, SW_RES(TP_LINENUMBERING), rSet),
107 	aNumberingOnCB		( this, SW_RES( CB_NUMBERING_ON )),
108     aDisplayFL          ( this, SW_RES( FL_DISPLAY )),
109     aCharStyleFT		( this, SW_RES( FT_CHAR_STYLE )),
110 	aCharStyleLB		( this, SW_RES( LB_CHAR_STYLE )),
111 	aFormatFT			( this, SW_RES( FT_FORMAT )),
112 	aFormatLB			( this, SW_RES( LB_FORMAT ), INSERT_NUM_EXTENDED_TYPES),
113 	aPosFT				( this, SW_RES( FT_POS )),
114 	aPosLB				( this, SW_RES( LB_POS )),
115 	aOffsetFT   		( this, SW_RES( FT_OFFSET )),
116 	aOffsetMF   		( this, SW_RES( MF_OFFSET )),
117 	aNumIntervalFT		( this, SW_RES( FT_NUM_INVERVAL )),
118 	aNumIntervalNF		( this, SW_RES( NF_NUM_INVERVAL )),
119 	aNumRowsFT			( this, SW_RES( FT_NUM_ROWS )),
120 	aDivisorFL          ( this, SW_RES( FL_DIVISOR )),
121     aDivisorFT			( this, SW_RES( FT_DIVISOR )),
122 	aDivisorED			( this, SW_RES( ED_DIVISOR )),
123 	aDivIntervalFT		( this, SW_RES( FT_DIV_INTERVAL )),
124 	aDivIntervalNF		( this, SW_RES( NF_DIV_INTERVAL )),
125 	aDivRowsFT			( this, SW_RES( FT_DIV_ROWS )),
126 	aCountFL            ( this, SW_RES( FL_COUNT )),
127     aCountEmptyLinesCB	( this, SW_RES( CB_COUNT_EMPTYLINES )),
128 	aCountFrameLinesCB	( this, SW_RES( CB_COUNT_FRAMELINES )),
129 	aRestartEachPageCB	( this, SW_RES( CB_RESTART_PAGE ))
130 
131 {
132 	String sIntervalName = aDivIntervalFT.GetAccessibleName();
133 	sIntervalName += String::CreateFromAscii("(");
134 	sIntervalName += aDivRowsFT.GetAccessibleName();
135 	sIntervalName += String::CreateFromAscii(")");
136 	aDivIntervalNF.SetAccessibleName(sIntervalName);
137 	sIntervalName = aNumIntervalFT.GetAccessibleName();
138 	sIntervalName += String::CreateFromAscii("(");
139 	sIntervalName += aNumRowsFT.GetAccessibleName();
140 	sIntervalName += String::CreateFromAscii(")");
141 	aNumIntervalNF.SetAccessibleName(sIntervalName);
142 
143 	FreeResource();
144 	SwLineNumberingDlg *pDlg = (SwLineNumberingDlg *)GetParent();
145 	pSh = pDlg->GetWrtShell();
146 	// Zeichenvorlagen
147 	::FillCharStyleListBox(aCharStyleLB, pSh->GetView().GetDocShell());
148 }
149 
150 /*-----------------------------------------------------------------------
151 	Beschreibung:
152  -----------------------------------------------------------------------*/
153 
154 __EXPORT SwLineNumberingPage::~SwLineNumberingPage()
155 {
156 }
157 
158 /*-----------------------------------------------------------------------
159 	Beschreibung:
160  -----------------------------------------------------------------------*/
161 
162 SfxTabPage*	__EXPORT SwLineNumberingPage::Create( Window* pParent, const SfxItemSet& rSet )
163 {
164 	return new SwLineNumberingPage( pParent, rSet );
165 }
166 
167 /*-----------------------------------------------------------------------
168 	Beschreibung:
169  -----------------------------------------------------------------------*/
170 
171 void __EXPORT SwLineNumberingPage::Reset( const SfxItemSet&  )
172 {
173 	const SwLineNumberInfo &rInf = pSh->GetLineNumberInfo();
174     IDocumentStylePoolAccess* pIDSPA = pSh->getIDocumentStylePoolAccess();
175 
176     String sStyleName(rInf.GetCharFmt( *pIDSPA )->GetName());
177 	const sal_uInt16 nPos = aCharStyleLB.GetEntryPos(sStyleName);
178 
179 	if (nPos != LISTBOX_ENTRY_NOTFOUND)
180 		aCharStyleLB.SelectEntryPos(nPos);
181 	else
182 	{
183 		if (sStyleName.Len())
184 		{
185 			aCharStyleLB.InsertEntry(sStyleName);
186 			aCharStyleLB.SelectEntry(sStyleName);
187 		}
188 	}
189 
190 	// Format
191 //	SwFldMgr aMgr( pSh );
192 	sal_uInt16 nSelFmt = rInf.GetNumType().GetNumberingType();
193 //	sal_uInt16 nCnt = aMgr.GetFormatCount( TYP_SEQFLD, sal_False );
194 
195 //	for( sal_uInt16 i = 0; i < nCnt; i++)
196 //	{
197 //		aFormatLB.InsertEntry(aMgr.GetFormatStr( TYP_SEQFLD, i));
198 //		sal_uInt16 nFmtId = aMgr.GetFormatId( TYP_SEQFLD, i );
199 //		aFormatLB.SetEntryData( i, (void*)nFmtId );
200 //		if( nFmtId == nSelFmt )
201 //			aFormatLB.SelectEntryPos( i );
202 //	}
203 	aFormatLB.SelectNumberingType(nSelFmt);
204 
205 //	if ( !aFormatLB.GetSelectEntryCount() )
206 //		aFormatLB.SelectEntryPos(aFormatLB.GetEntryCount() - 1);
207 
208 	// Position
209 	aPosLB.SelectEntryPos((sal_uInt16)rInf.GetPos());
210 
211 	// Offset
212 	sal_uInt16 nOffset = rInf.GetPosFromLeft();
213 	if (nOffset == USHRT_MAX)
214 		nOffset = 0;
215 
216 	aOffsetMF.SetValue(aOffsetMF.Normalize(nOffset), FUNIT_TWIP);
217 
218 	// Numerierungsoffset
219 	aNumIntervalNF.SetValue(rInf.GetCountBy());
220 
221 	// Teiler
222 	aDivisorED.SetText(rInf.GetDivider());
223 
224 	// Teileroffset
225 	aDivIntervalNF.SetValue(rInf.GetDividerCountBy());
226 
227 	// Zaehlen
228 	aCountEmptyLinesCB.Check(rInf.IsCountBlankLines());
229 	aCountFrameLinesCB.Check(rInf.IsCountInFlys());
230 	aRestartEachPageCB.Check(rInf.IsRestartEachPage());
231 
232 	aNumberingOnCB.Check(rInf.IsPaintLineNumbers());
233 
234 	aNumberingOnCB.SetClickHdl(LINK(this, SwLineNumberingPage, LineOnOffHdl));
235 	aDivisorED.SetModifyHdl(LINK(this, SwLineNumberingPage, ModifyHdl));
236 	ModifyHdl();
237 	LineOnOffHdl();
238 }
239 
240 /*--------------------------------------------------------------------
241 	Beschreibung: Modify
242  --------------------------------------------------------------------*/
243 
244 IMPL_LINK( SwLineNumberingPage, ModifyHdl, Edit *, EMPTYARG )
245 {
246 	sal_Bool bHasValue = aDivisorED.GetText().Len() != 0;
247 
248 	aDivIntervalFT.Enable(bHasValue);
249 	aDivIntervalNF.Enable(bHasValue);
250 	aDivRowsFT.Enable(bHasValue);
251 
252 	return 0;
253 }
254 
255 /*--------------------------------------------------------------------
256 	Beschreibung: On/Off
257  --------------------------------------------------------------------*/
258 
259 IMPL_LINK( SwLineNumberingPage, LineOnOffHdl, CheckBox *, EMPTYARG )
260 {
261 	sal_Bool bEnable = aNumberingOnCB.IsChecked();
262 
263 	aCharStyleFT.Enable(bEnable);
264 	aCharStyleLB.Enable(bEnable);
265 	aFormatFT.Enable(bEnable);
266 	aFormatLB.Enable(bEnable);
267 	aPosFT.Enable(bEnable);
268 	aPosLB.Enable(bEnable);
269 	aOffsetFT.Enable(bEnable);
270 	aOffsetMF.Enable(bEnable);
271 	aNumIntervalFT.Enable(bEnable);
272 	aNumIntervalNF.Enable(bEnable);
273 	aNumRowsFT.Enable(bEnable);
274     aDisplayFL.Enable(bEnable);
275 	aDivisorFT.Enable(bEnable);
276 	aDivisorED.Enable(bEnable);
277 	aDivIntervalFT.Enable(bEnable);
278 	aDivIntervalNF.Enable(bEnable);
279 	aDivRowsFT.Enable(bEnable);
280     aDivisorFL.Enable(bEnable);
281 	aCountEmptyLinesCB.Enable(bEnable);
282 	aCountFrameLinesCB.Enable(bEnable);
283 	aRestartEachPageCB.Enable(bEnable);
284     aCountFL.Enable(bEnable);
285 
286 	return 0;
287 }
288 
289 /*-----------------------------------------------------------------------
290 	Beschreibung:
291  -----------------------------------------------------------------------*/
292 
293 sal_Bool __EXPORT SwLineNumberingPage::FillItemSet( SfxItemSet& )
294 {
295 	SwLineNumberInfo aInf(pSh->GetLineNumberInfo());
296 
297 	// Zeichenvorlagen
298 	String sCharFmtName(aCharStyleLB.GetSelectEntry());
299 	SwCharFmt *pCharFmt = pSh->FindCharFmtByName(sCharFmtName);
300 
301 	if (!pCharFmt)
302 	{
303 		SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
304 		SfxStyleSheetBase* pBase;
305 		pBase = pPool->Find(sCharFmtName, SFX_STYLE_FAMILY_CHAR);
306 		if(!pBase)
307 			pBase = &pPool->Make(sCharFmtName, SFX_STYLE_FAMILY_CHAR);
308 		pCharFmt = ((SwDocStyleSheet*)pBase)->GetCharFmt();
309 	}
310 
311 	if (pCharFmt)
312 		aInf.SetCharFmt(pCharFmt);
313 
314 	// Format
315 	SvxNumberType aType;
316 	aType.SetNumberingType(aFormatLB.GetSelectedNumberingType());
317 	aInf.SetNumType(aType);
318 
319 	// Position
320 	aInf.SetPos((LineNumberPosition)aPosLB.GetSelectEntryPos());
321 
322 	// Offset
323 	aInf.SetPosFromLeft((sal_uInt16)aOffsetMF.Denormalize(aOffsetMF.GetValue(FUNIT_TWIP)));
324 
325 	// Numerierungsoffset
326 	aInf.SetCountBy((sal_uInt16)aNumIntervalNF.GetValue());
327 
328 	// Teiler
329 	aInf.SetDivider(aDivisorED.GetText());
330 
331 	// Teileroffset
332 	aInf.SetDividerCountBy((sal_uInt16)aDivIntervalNF.GetValue());
333 
334 	// Zaehlen
335 	aInf.SetCountBlankLines(aCountEmptyLinesCB.IsChecked());
336 	aInf.SetCountInFlys(aCountFrameLinesCB.IsChecked());
337 	aInf.SetRestartEachPage(aRestartEachPageCB.IsChecked());
338 
339 	aInf.SetPaintLineNumbers(aNumberingOnCB.IsChecked());
340 
341 	pSh->SetLineNumberInfo(aInf);
342 
343 	return sal_False;
344 }
345 
346 
347