1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: numpara.cxx,v $
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
41 #include "swtypes.hxx"
42 #include "hintids.hxx"
43 #include "globals.hrc"
45 #include <sfx2/objsh.hxx>
46 #include <svx/htmlmode.hxx>
47 #ifndef _SVX_SVXIDS_HRC
48 #include <svx/svxids.hrc>
50 #include <svtools/eitem.hxx>
51 #include <svtools/stritem.hxx>
52 #include <svtools/intitem.hxx>
53 #include <fmtline.hxx>
54 #include <numpara.hxx>
55 #include <numpara.hrc>
56 // --> OD 2008-04-14 #outlinelevel#
60 // Globals ******************************************************************
62 static USHORT __FAR_DATA aPageRg
[] = {
63 FN_NUMBER_NEWSTART
, FN_NUMBER_NEWSTART_AT
,
66 /*-----------------31.01.98 08:34-------------------
68 --------------------------------------------------*/
69 SwParagraphNumTabPage::SwParagraphNumTabPage(Window
* pParent
,
70 const SfxItemSet
& rAttr
) :
71 SfxTabPage(pParent
, SW_RES(TP_NUMPARA
), rAttr
),
72 aOutlineStartFL ( this, SW_RES( FL_OUTLINE_START
)),
73 aOutlineLvFT ( this, SW_RES( FT_OUTLINE_LEVEL
)),
74 aOutlineLvLB ( this, SW_RES( LB_OUTLINE_LEVEL
)),
75 aNumberStyleFT ( this, SW_RES( FT_NUMBER_STYLE
) ),
76 aNumberStyleLB ( this, SW_RES( LB_NUMBER_STYLE
) ),
77 aNewStartFL ( this, SW_RES( FL_NEW_START
) ),
78 aNewStartCB ( this, SW_RES( CB_NEW_START
) ),
79 aNewStartNumberCB ( this, SW_RES( CB_NUMBER_NEW_START
) ),
80 aNewStartNF ( this, SW_RES( NF_NEW_START
) ),
81 aCountParaFL ( this, SW_RES( FL_COUNT_PARA
) ),
82 aCountParaCB ( this, SW_RES( CB_COUNT_PARA
) ),
83 aRestartParaCountCB ( this, SW_RES( CB_RESTART_PARACOUNT
) ),
84 aRestartFT ( this, SW_RES( FT_RESTART_NO
) ),
85 aRestartNF ( this, SW_RES( NF_RESTART_PARA
) ),
86 // --> OD 2008-04-14 #outlinelevel#
87 msOutlineNumbering( SW_RES( STR_OUTLINE_NUMBERING
) ),
94 const SfxPoolItem
* pItem
;
95 SfxObjectShell
* pObjSh
;
96 if(SFX_ITEM_SET
== rAttr
.GetItemState(SID_HTML_MODE
, FALSE
, &pItem
) ||
97 ( 0 != ( pObjSh
= SfxObjectShell::Current()) &&
98 0 != (pItem
= pObjSh
->GetItem(SID_HTML_MODE
))))
100 USHORT nHtmlMode
= ((const SfxUInt16Item
*)pItem
)->GetValue();
101 if(HTMLMODE_ON
& nHtmlMode
)
103 aCountParaFL
.Hide();
104 aCountParaCB
.Hide();
105 aRestartParaCountCB
.Hide();
110 aNewStartCB
.SetClickHdl(LINK(this, SwParagraphNumTabPage
, NewStartHdl_Impl
));
111 aNewStartNumberCB
.SetClickHdl(LINK(this, SwParagraphNumTabPage
, NewStartHdl_Impl
));
112 aNumberStyleLB
.SetSelectHdl(LINK(this, SwParagraphNumTabPage
, StyleHdl_Impl
));
113 aCountParaCB
.SetClickHdl(LINK(this,
114 SwParagraphNumTabPage
, LineCountHdl_Impl
));
115 aRestartParaCountCB
.SetClickHdl(
116 LINK(this, SwParagraphNumTabPage
, LineCountHdl_Impl
));
118 /*-----------------31.01.98 08:34-------------------
120 --------------------------------------------------*/
121 SwParagraphNumTabPage::~SwParagraphNumTabPage()
125 /*-----------------31.01.98 08:38-------------------
127 --------------------------------------------------*/
128 SfxTabPage
* SwParagraphNumTabPage::Create( Window
* pParent
,
129 const SfxItemSet
& rSet
)
131 return new SwParagraphNumTabPage(pParent
, rSet
);
134 /*-----------------31.01.98 08:38-------------------
136 --------------------------------------------------*/
137 USHORT
* SwParagraphNumTabPage::GetRanges()
142 /*-----------------31.01.98 08:38-------------------
144 --------------------------------------------------*/
145 BOOL
SwParagraphNumTabPage::FillItemSet( SfxItemSet
& rSet
)
147 //<-#outline level, added by zhaojianwei
148 if( aOutlineLvLB
.GetSelectEntryPos() != aOutlineLvLB
.GetSavedValue())
150 USHORT aOutlineLv
= aOutlineLvLB
.GetSelectEntryPos();
151 const SfxUInt16Item
* pOldOutlineLv
= (const SfxUInt16Item
*)GetOldItem( rSet
, SID_ATTR_PARA_OUTLINE_LEVEL
);
152 SfxUInt16Item
* pOutlineLv
= (SfxUInt16Item
*)pOldOutlineLv
->Clone();
153 pOutlineLv
->SetValue( aOutlineLv
);
154 rSet
.Put(*pOutlineLv
);
159 if( aNumberStyleLB
.GetSelectEntryPos() != aNumberStyleLB
.GetSavedValue())
162 if(aNumberStyleLB
.GetSelectEntryPos())
163 aStyle
= aNumberStyleLB
.GetSelectEntry();
164 const SfxStringItem
* pOldRule
= (const SfxStringItem
*)GetOldItem( rSet
, SID_ATTR_PARA_NUMRULE
);
165 SfxStringItem
* pRule
= (SfxStringItem
*)pOldRule
->Clone();
166 pRule
->SetValue(aStyle
);
171 if(aNewStartCB
.GetState() != aNewStartCB
.GetSavedValue() ||
172 aNewStartNumberCB
.GetState() != aNewStartNumberCB
.GetSavedValue()||
173 aNewStartNF
.GetText() != aNewStartNF
.GetSavedValue())
176 BOOL bNewStartChecked
= STATE_CHECK
== aNewStartCB
.GetState();
177 BOOL bNumberNewStartChecked
= STATE_CHECK
== aNewStartNumberCB
.GetState();
178 rSet
.Put(SfxBoolItem(FN_NUMBER_NEWSTART
, bNewStartChecked
));
179 rSet
.Put(SfxUInt16Item(FN_NUMBER_NEWSTART_AT
,
180 bNumberNewStartChecked
&& bNewStartChecked
? (USHORT
)aNewStartNF
.GetValue() : USHRT_MAX
));
183 if(aCountParaCB
.GetSavedValue() != aCountParaCB
.GetState() ||
184 aRestartParaCountCB
.GetSavedValue() != aRestartParaCountCB
.GetState() ||
185 aRestartNF
.GetSavedValue() != aRestartNF
.GetText() )
187 SwFmtLineNumber aFmt
;
188 aFmt
.SetStartValue( static_cast< ULONG
>(aRestartParaCountCB
.GetState() == STATE_CHECK
?
189 aRestartNF
.GetValue() : 0 ));
190 aFmt
.SetCountLines( aCountParaCB
.IsChecked() );
197 /*-----------------31.01.98 08:38-------------------
199 --------------------------------------------------*/
200 void SwParagraphNumTabPage::Reset( const SfxItemSet
& rSet
)
202 BOOL bHasNumberStyle
= FALSE
;
204 SfxItemState eItemState
= rSet
.GetItemState( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL
) );
206 sal_Int16 nOutlineLv
;
207 if( eItemState
>= SFX_ITEM_AVAILABLE
)
209 nOutlineLv
= ((const SfxUInt16Item
&)rSet
.Get( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL
) )).GetValue();
210 aOutlineLvLB
.SelectEntryPos( nOutlineLv
) ;
214 aOutlineLvLB
.SetNoSelection();
216 aOutlineLvLB
.SaveValue();
218 eItemState
= rSet
.GetItemState( GetWhich(SID_ATTR_PARA_NUMRULE
) );
221 if( eItemState
>= SFX_ITEM_AVAILABLE
)
223 aStyle
= ((const SfxStringItem
&)rSet
.Get( GetWhich(SID_ATTR_PARA_NUMRULE
) )).GetValue();
225 aStyle
= aNumberStyleLB
.GetEntry(0);
227 if( aStyle
.EqualsAscii("Outline"))// == String::CreateFromAscii("Outline")) //maybe need modify,zhaojianwei
229 aNumberStyleLB
.InsertEntry( msOutlineNumbering
);
230 aNumberStyleLB
.SelectEntry( msOutlineNumbering
);
231 aNumberStyleLB
.RemoveEntry(msOutlineNumbering
);
232 aNumberStyleLB
.SaveValue();
235 aNumberStyleLB
.SelectEntry( aStyle
);
237 bHasNumberStyle
= TRUE
;
241 aNumberStyleLB
.SetNoSelection();
244 aNumberStyleLB
.SaveValue();
246 eItemState
= rSet
.GetItemState( FN_NUMBER_NEWSTART
);
247 if(eItemState
> SFX_ITEM_AVAILABLE
)
250 const SfxBoolItem
& rStart
= (const SfxBoolItem
&)rSet
.Get(FN_NUMBER_NEWSTART
);
251 aNewStartCB
.SetState(
253 STATE_CHECK
: STATE_NOCHECK
);
254 aNewStartCB
.EnableTriState(FALSE
);
257 aNewStartCB
.SetState(bHasNumberStyle
? STATE_NOCHECK
: STATE_DONTKNOW
);
258 aNewStartCB
.SaveValue();
260 eItemState
= rSet
.GetItemState( FN_NUMBER_NEWSTART_AT
);
261 if( eItemState
> SFX_ITEM_AVAILABLE
)
263 USHORT nNewStart
= ((const SfxUInt16Item
&)rSet
.Get(FN_NUMBER_NEWSTART_AT
)).GetValue();
264 aNewStartNumberCB
.Check(USHRT_MAX
!= nNewStart
);
265 if(USHRT_MAX
== nNewStart
)
268 aNewStartNF
.SetValue(nNewStart
);
269 aNewStartNumberCB
.EnableTriState(FALSE
);
272 aNewStartCB
.SetState(STATE_DONTKNOW
);
273 NewStartHdl_Impl(&aNewStartCB
);
274 aNewStartNF
.SaveValue();
275 aNewStartNumberCB
.SaveValue();
276 StyleHdl_Impl(&aNumberStyleLB
);
277 if( SFX_ITEM_AVAILABLE
<= rSet
.GetItemState(RES_LINENUMBER
))
279 SwFmtLineNumber
& rNum
= (SwFmtLineNumber
&)rSet
.Get(RES_LINENUMBER
);
280 ULONG nStartValue
= rNum
.GetStartValue();
281 BOOL bCount
= rNum
.IsCount();
282 aCountParaCB
.SetState( bCount
? STATE_CHECK
: STATE_NOCHECK
);
283 aRestartParaCountCB
.SetState( 0 != nStartValue
? STATE_CHECK
: STATE_NOCHECK
);
284 aRestartNF
.SetValue(nStartValue
== 0 ? 1 : nStartValue
);
285 LineCountHdl_Impl(&aCountParaCB
);
286 aCountParaCB
.EnableTriState(FALSE
);
287 aRestartParaCountCB
.EnableTriState(FALSE
);
291 aCountParaCB
.SetState(STATE_DONTKNOW
);
292 aRestartParaCountCB
.SetState(STATE_DONTKNOW
);
294 aCountParaCB
.SaveValue();
295 aRestartParaCountCB
.SaveValue();
296 aRestartNF
.SaveValue();
301 /*-----------------31.01.98 08:38-------------------
303 --------------------------------------------------*/
304 void SwParagraphNumTabPage::DisableOutline()
306 aOutlineLvFT
.Disable();
307 aOutlineLvLB
.Disable();
309 void SwParagraphNumTabPage::DisableNumbering()
311 aNumberStyleFT
.Disable();
312 aNumberStyleLB
.Disable();
315 /*-----------------31.01.98 08:38-------------------
317 --------------------------------------------------*/
318 void SwParagraphNumTabPage::EnableNewStart()
321 aNewStartNumberCB
.Show();
325 /*-----------------31.01.98 08:56-------------------
327 --------------------------------------------------*/
328 IMPL_LINK( SwParagraphNumTabPage
, NewStartHdl_Impl
, CheckBox
*, EMPTYARG
)
330 BOOL bEnable
= aNewStartCB
.IsChecked();
331 aNewStartNumberCB
.Enable(bEnable
);
332 aNewStartNF
.Enable(bEnable
&& aNewStartNumberCB
.IsChecked());
336 /*-----------------05.02.98 10:01-------------------
338 --------------------------------------------------*/
339 IMPL_LINK( SwParagraphNumTabPage
, LineCountHdl_Impl
, CheckBox
* , EMPTYARG
)
341 aRestartParaCountCB
.Enable(aCountParaCB
.IsChecked());
343 BOOL bEnableRestartValue
= aRestartParaCountCB
.IsEnabled() &&
344 aRestartParaCountCB
.IsChecked();
345 aRestartFT
.Enable(bEnableRestartValue
);
346 aRestartNF
.Enable(bEnableRestartValue
);
351 /*-----------------05.02.98 13:39-------------------
353 --------------------------------------------------*/
354 IMPL_LINK( SwParagraphNumTabPage
, StyleHdl_Impl
, ListBox
*, pBox
)
356 // String dd=aNumberStyleLB.GetSavedValue();
357 // if( msOutlineNumbering == dd)
360 BOOL bEnable
= bCurNumrule
|| pBox
->GetSelectEntryPos() > 0;
361 aNewStartCB
.Enable(bEnable
);
362 NewStartHdl_Impl(&aNewStartCB
);