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