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