xref: /aoo41x/main/sw/source/ui/chrdlg/numpara.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 
37 #include "cmdid.h"
38 #include "swtypes.hxx"
39 #include "hintids.hxx"
40 #include "globals.hrc"
41 #include "helpid.h"
42 #include <sfx2/objsh.hxx>
43 #include <svx/htmlmode.hxx>
44 #ifndef _SVX_SVXIDS_HRC
45 #include <svx/svxids.hrc>
46 #endif
47 #include <svl/eitem.hxx>
48 #include <svl/stritem.hxx>
49 #include <svl/intitem.hxx>
50 #include <fmtline.hxx>
51 #include <numpara.hxx>
52 #include <numpara.hrc>
53 // --> OD 2008-04-14 #outlinelevel#
54 #include <app.hrc>
55 // <--
56 
57 // Globals ******************************************************************
58 
59 static sal_uInt16 __FAR_DATA aPageRg[] = {
60 	FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART_AT,
61 	0
62 };
63 /*-----------------31.01.98 08:34-------------------
64 
65 --------------------------------------------------*/
66 SwParagraphNumTabPage::SwParagraphNumTabPage(Window* pParent,
67 												const SfxItemSet& rAttr ) :
68 	SfxTabPage(pParent, SW_RES(TP_NUMPARA), rAttr),
69 	aOutlineStartFL	        ( this, SW_RES( FL_OUTLINE_START )),
70 	aOutlineLvFT		    ( this, SW_RES( FT_OUTLINE_LEVEL )),
71 	aOutlineLvLB		    ( this, SW_RES( LB_OUTLINE_LEVEL )),
72     aNewStartFL             ( this, SW_RES( FL_NEW_START ) ),
73     aNumberStyleFT          ( this, SW_RES( FT_NUMBER_STYLE ) ),
74 	aNumberStyleLB          ( this, SW_RES( LB_NUMBER_STYLE ) ),
75    	aNewStartCB          	( this, SW_RES( CB_NEW_START ) ),
76     aNewStartNumberCB       ( this, SW_RES( CB_NUMBER_NEW_START ) ),
77 	aNewStartNF          	( this, SW_RES( NF_NEW_START ) ),
78     aCountParaFL            ( this, SW_RES( FL_COUNT_PARA        ) ),
79 	aCountParaCB            ( this, SW_RES( CB_COUNT_PARA        ) ),
80 	aRestartParaCountCB     ( this, SW_RES( CB_RESTART_PARACOUNT ) ),
81 	aRestartFT              ( this, SW_RES( FT_RESTART_NO        ) ),
82 	aRestartNF              ( this, SW_RES( NF_RESTART_PARA      ) ),
83     // --> OD 2008-04-14 #outlinelevel#
84     msOutlineNumbering( SW_RES( STR_OUTLINE_NUMBERING ) ),
85     // <--
86     bModified(sal_False),
87 	bCurNumrule(sal_False)
88 {
89 	FreeResource();
90 
91 	const SfxPoolItem* pItem;
92 	SfxObjectShell* pObjSh;
93 	if(SFX_ITEM_SET == rAttr.GetItemState(SID_HTML_MODE, sal_False, &pItem) ||
94 		( 0 != ( pObjSh = SfxObjectShell::Current()) &&
95 					0 != (pItem = pObjSh->GetItem(SID_HTML_MODE))))
96 	{
97 		sal_uInt16 nHtmlMode = ((const SfxUInt16Item*)pItem)->GetValue();
98 		if(HTMLMODE_ON & nHtmlMode)
99 		{
100             aCountParaFL        .Hide();
101 			aCountParaCB        .Hide();
102 			aRestartParaCountCB .Hide();
103 			aRestartFT          .Hide();
104 			aRestartNF          .Hide();
105 		}
106 	}
107 	aNewStartCB.SetClickHdl(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
108     aNewStartNumberCB.SetClickHdl(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
109 	aNumberStyleLB.SetSelectHdl(LINK(this, SwParagraphNumTabPage, StyleHdl_Impl));
110 	aCountParaCB.SetClickHdl(LINK(this,
111 					SwParagraphNumTabPage, LineCountHdl_Impl));
112 	aRestartParaCountCB.SetClickHdl(
113 					LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
114 	aNewStartNF.SetAccessibleName(aNewStartNumberCB.GetText());
115 	aNewStartNF.SetAccessibleRelationLabeledBy(&aNewStartNumberCB);
116 }
117 /*-----------------31.01.98 08:34-------------------
118 
119 --------------------------------------------------*/
120 SwParagraphNumTabPage::~SwParagraphNumTabPage()
121 {
122 }
123 
124 /*-----------------31.01.98 08:38-------------------
125 
126 --------------------------------------------------*/
127 SfxTabPage*	SwParagraphNumTabPage::Create(	Window* pParent,
128 								const SfxItemSet& rSet )
129 {
130 	return new SwParagraphNumTabPage(pParent, rSet);
131 }
132 
133 /*-----------------31.01.98 08:38-------------------
134 
135 --------------------------------------------------*/
136 sal_uInt16*	SwParagraphNumTabPage::GetRanges()
137 {
138 	return aPageRg;
139 }
140 
141 /*-----------------31.01.98 08:38-------------------
142 
143 --------------------------------------------------*/
144 sal_Bool	SwParagraphNumTabPage::FillItemSet( SfxItemSet& rSet )
145 {
146 	//<-#outline level, added by zhaojianwei
147 	if( aOutlineLvLB.GetSelectEntryPos() != aOutlineLvLB.GetSavedValue())
148 	{
149 		sal_uInt16 aOutlineLv = aOutlineLvLB.GetSelectEntryPos();
150 		const SfxUInt16Item* pOldOutlineLv = (const SfxUInt16Item*)GetOldItem( rSet, SID_ATTR_PARA_OUTLINE_LEVEL);
151 		SfxUInt16Item* pOutlineLv = (SfxUInt16Item*)pOldOutlineLv->Clone();
152 		pOutlineLv->SetValue( aOutlineLv );
153 		rSet.Put(*pOutlineLv);
154 		delete pOutlineLv;
155 		bModified = sal_True;
156 	}
157 	//<-end
158 	if(	aNumberStyleLB.GetSelectEntryPos() != aNumberStyleLB.GetSavedValue())
159 	{
160 		String aStyle;
161 		if(aNumberStyleLB.GetSelectEntryPos())
162 			aStyle = aNumberStyleLB.GetSelectEntry();
163 		const SfxStringItem* pOldRule = (const SfxStringItem*)GetOldItem( rSet, SID_ATTR_PARA_NUMRULE);
164 		SfxStringItem* pRule = (SfxStringItem*)pOldRule->Clone();
165 		pRule->SetValue(aStyle);
166 		rSet.Put(*pRule);
167 		delete pRule;
168 		bModified = sal_True;
169 	}
170 	if(aNewStartCB.GetState() != aNewStartCB.GetSavedValue() ||
171         aNewStartNumberCB.GetState() != aNewStartNumberCB.GetSavedValue()||
172         aNewStartNF.GetText() != aNewStartNF.GetSavedValue())
173 	{
174 		bModified = sal_True;
175         sal_Bool bNewStartChecked = STATE_CHECK == aNewStartCB.GetState();
176         sal_Bool bNumberNewStartChecked = STATE_CHECK == aNewStartNumberCB.GetState();
177         rSet.Put(SfxBoolItem(FN_NUMBER_NEWSTART, bNewStartChecked));
178         rSet.Put(SfxUInt16Item(FN_NUMBER_NEWSTART_AT,
179                   bNumberNewStartChecked && bNewStartChecked ? (sal_uInt16)aNewStartNF.GetValue() : USHRT_MAX));
180 	}
181 
182 	if(aCountParaCB.GetSavedValue() != aCountParaCB.GetState() ||
183 		aRestartParaCountCB.GetSavedValue() != aRestartParaCountCB.GetState() ||
184 			aRestartNF.GetSavedValue() != aRestartNF.GetText() )
185 	{
186 		SwFmtLineNumber aFmt;
187         aFmt.SetStartValue( static_cast< sal_uLong >(aRestartParaCountCB.GetState() == STATE_CHECK ?
188                                 aRestartNF.GetValue() : 0 ));
189 		aFmt.SetCountLines( aCountParaCB.IsChecked() );
190 		rSet.Put(aFmt);
191 		bModified = sal_True;
192 	}
193 	return bModified;
194 }
195 
196 /*-----------------31.01.98 08:38-------------------
197 
198 --------------------------------------------------*/
199 void	SwParagraphNumTabPage::Reset( const SfxItemSet& rSet )
200 {
201 	sal_Bool bHasNumberStyle = sal_False;
202 
203 	SfxItemState eItemState = rSet.GetItemState( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) );
204 
205 	sal_Int16 nOutlineLv;
206 	if( eItemState >= SFX_ITEM_AVAILABLE )
207 	{
208 		nOutlineLv = ((const SfxUInt16Item &)rSet.Get( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) )).GetValue();
209 		aOutlineLvLB.SelectEntryPos( nOutlineLv ) ;
210 	}
211 	else
212 	{
213 		aOutlineLvLB.SetNoSelection();
214 	}
215 	aOutlineLvLB.SaveValue();
216 
217 	eItemState = rSet.GetItemState( GetWhich(SID_ATTR_PARA_NUMRULE) );
218 
219 	String aStyle;
220 	if( eItemState >= SFX_ITEM_AVAILABLE )
221 	{
222 		aStyle = ((const SfxStringItem &)rSet.Get( GetWhich(SID_ATTR_PARA_NUMRULE) )).GetValue();
223 		if(!aStyle.Len())
224 			aStyle = aNumberStyleLB.GetEntry(0);
225 
226 		if( aStyle.EqualsAscii("Outline"))// == String::CreateFromAscii("Outline")) //maybe need modify,zhaojianwei
227 		{
228 			aNumberStyleLB.InsertEntry( msOutlineNumbering );
229 			aNumberStyleLB.SelectEntry( msOutlineNumbering );
230 			aNumberStyleLB.RemoveEntry(msOutlineNumbering);
231 			aNumberStyleLB.SaveValue();
232 		}
233 		else
234 			aNumberStyleLB.SelectEntry( aStyle );
235 
236 		bHasNumberStyle = sal_True;
237 	}
238 	else
239 	{
240 		aNumberStyleLB.SetNoSelection();
241 	}
242 
243 	aNumberStyleLB.SaveValue();
244 
245 	eItemState = rSet.GetItemState( FN_NUMBER_NEWSTART );
246 	if(eItemState > SFX_ITEM_AVAILABLE )
247     {
248         bCurNumrule = sal_True;
249 		const SfxBoolItem& rStart = (const SfxBoolItem&)rSet.Get(FN_NUMBER_NEWSTART);
250 		aNewStartCB.SetState(
251             rStart.GetValue() ?
252 						STATE_CHECK : STATE_NOCHECK );
253 		aNewStartCB.EnableTriState(sal_False);
254 	}
255 	else
256         aNewStartCB.SetState(bHasNumberStyle ? STATE_NOCHECK : STATE_DONTKNOW);
257 	aNewStartCB.SaveValue();
258 
259 	eItemState = rSet.GetItemState( FN_NUMBER_NEWSTART_AT);
260 	if( eItemState > SFX_ITEM_AVAILABLE )
261 	{
262 		sal_uInt16 nNewStart = ((const SfxUInt16Item&)rSet.Get(FN_NUMBER_NEWSTART_AT)).GetValue();
263         aNewStartNumberCB.Check(USHRT_MAX != nNewStart);
264         if(USHRT_MAX == nNewStart)
265 			nNewStart = 1;
266 
267 		aNewStartNF.SetValue(nNewStart);
268 		aNewStartNumberCB.EnableTriState(sal_False);
269     }
270     else
271         aNewStartCB.SetState(STATE_DONTKNOW);
272     NewStartHdl_Impl(&aNewStartCB);
273     aNewStartNF.SaveValue();
274     aNewStartNumberCB.SaveValue();
275 	StyleHdl_Impl(&aNumberStyleLB);
276 	if( SFX_ITEM_AVAILABLE <= rSet.GetItemState(RES_LINENUMBER))
277 	{
278 		SwFmtLineNumber& rNum = (SwFmtLineNumber&)rSet.Get(RES_LINENUMBER);
279 		sal_uLong nStartValue = rNum.GetStartValue();
280 		sal_Bool bCount = rNum.IsCount();
281 		aCountParaCB.SetState( bCount ? STATE_CHECK : STATE_NOCHECK );
282 		aRestartParaCountCB.SetState( 0 != nStartValue ? STATE_CHECK : STATE_NOCHECK );
283 		aRestartNF.SetValue(nStartValue == 0 ? 1 : nStartValue);
284 		LineCountHdl_Impl(&aCountParaCB);
285 		aCountParaCB.EnableTriState(sal_False);
286 		aRestartParaCountCB.EnableTriState(sal_False);
287 	}
288 	else
289 	{
290 		aCountParaCB.SetState(STATE_DONTKNOW);
291 		aRestartParaCountCB.SetState(STATE_DONTKNOW);
292 	}
293 	aCountParaCB.SaveValue();
294 	aRestartParaCountCB.SaveValue();
295 	aRestartNF.SaveValue();
296 
297 	bModified = sal_False;
298 }
299 
300 /*-----------------31.01.98 08:38-------------------
301 
302 --------------------------------------------------*/
303 void SwParagraphNumTabPage::DisableOutline()
304 {
305 	aOutlineLvFT.Disable();
306 	aOutlineLvLB.Disable();
307 }
308 void SwParagraphNumTabPage::DisableNumbering()
309 {
310 	aNumberStyleFT.Disable();
311 	aNumberStyleLB.Disable();
312 }
313 
314 /*-----------------31.01.98 08:38-------------------
315 
316 --------------------------------------------------*/
317 void SwParagraphNumTabPage::EnableNewStart()
318 {
319 	aNewStartCB.Show();
320 	aNewStartNumberCB.Show();
321 	aNewStartNF.Show();
322 }
323 
324 /*-----------------31.01.98 08:56-------------------
325 
326 --------------------------------------------------*/
327 IMPL_LINK( SwParagraphNumTabPage, NewStartHdl_Impl, CheckBox*, EMPTYARG )
328 {
329     sal_Bool bEnable = aNewStartCB.IsChecked();
330     aNewStartNumberCB.Enable(bEnable);
331     aNewStartNF.Enable(bEnable && aNewStartNumberCB.IsChecked());
332 	return 0;
333 }
334 
335 /*-----------------05.02.98 10:01-------------------
336 
337 --------------------------------------------------*/
338 IMPL_LINK( SwParagraphNumTabPage, LineCountHdl_Impl, CheckBox* , EMPTYARG)
339 {
340 	aRestartParaCountCB.Enable(aCountParaCB.IsChecked());
341 
342 	sal_Bool bEnableRestartValue = aRestartParaCountCB.IsEnabled() &&
343 												aRestartParaCountCB.IsChecked();
344 	aRestartFT.Enable(bEnableRestartValue);
345 	aRestartNF.Enable(bEnableRestartValue);
346 
347 	return 0;
348 }
349 
350 /*-----------------05.02.98 13:39-------------------
351 
352 --------------------------------------------------*/
353 IMPL_LINK( SwParagraphNumTabPage, StyleHdl_Impl, ListBox*, pBox )
354 {
355 //	String dd=aNumberStyleLB.GetSavedValue();
356 //	if(	msOutlineNumbering == dd)
357 	{
358 	}
359 	sal_Bool bEnable = bCurNumrule || pBox->GetSelectEntryPos() > 0;
360 	aNewStartCB.Enable(bEnable);
361 	NewStartHdl_Impl(&aNewStartCB);
362 
363 	return 0;
364 }
365 
366 
367