Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "cmdid.h"
21 : #include "swtypes.hxx"
22 : #include "hintids.hxx"
23 : #include "globals.hrc"
24 : #include "helpid.h"
25 : #include <sfx2/objsh.hxx>
26 : #include <svx/htmlmode.hxx>
27 : #include <svx/svxids.hrc>
28 : #include <svl/eitem.hxx>
29 : #include <svl/stritem.hxx>
30 : #include <svl/intitem.hxx>
31 : #include <fmtline.hxx>
32 : #include <numpara.hxx>
33 : #include <numpara.hrc>
34 :
35 : #include <app.hrc>
36 :
37 :
38 : // Globals ******************************************************************
39 :
40 : static sal_uInt16 aPageRg[] = {
41 : FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART_AT,
42 : 0
43 : };
44 :
45 0 : SwParagraphNumTabPage::SwParagraphNumTabPage(Window* pParent,
46 : const SfxItemSet& rAttr ) :
47 : SfxTabPage(pParent, SW_RES(TP_NUMPARA), rAttr),
48 : aOutlineStartFL ( this, SW_RES( FL_OUTLINE_START )),
49 : aOutlineLvFT ( this, SW_RES( FT_OUTLINE_LEVEL )),
50 : aOutlineLvLB ( this, SW_RES( LB_OUTLINE_LEVEL )),
51 : aNewStartFL ( this, SW_RES( FL_NEW_START ) ),
52 : aNumberStyleFT ( this, SW_RES( FT_NUMBER_STYLE ) ),
53 : aNumberStyleLB ( this, SW_RES( LB_NUMBER_STYLE ) ),
54 : aNewStartCB ( this, SW_RES( CB_NEW_START ) ),
55 : aNewStartNumberCB ( this, SW_RES( CB_NUMBER_NEW_START ) ),
56 : aNewStartNF ( this, SW_RES( NF_NEW_START ) ),
57 : aCountParaFL ( this, SW_RES( FL_COUNT_PARA ) ),
58 : aCountParaCB ( this, SW_RES( CB_COUNT_PARA ) ),
59 : aRestartParaCountCB ( this, SW_RES( CB_RESTART_PARACOUNT ) ),
60 : aRestartFT ( this, SW_RES( FT_RESTART_NO ) ),
61 : aRestartNF ( this, SW_RES( NF_RESTART_PARA ) ),
62 : msOutlineNumbering( SW_RES( STR_OUTLINE_NUMBERING ) ),
63 : bModified(sal_False),
64 0 : bCurNumrule(sal_False)
65 : {
66 0 : FreeResource();
67 :
68 : const SfxPoolItem* pItem;
69 : SfxObjectShell* pObjSh;
70 0 : if(SFX_ITEM_SET == rAttr.GetItemState(SID_HTML_MODE, sal_False, &pItem) ||
71 : ( 0 != ( pObjSh = SfxObjectShell::Current()) &&
72 0 : 0 != (pItem = pObjSh->GetItem(SID_HTML_MODE))))
73 : {
74 0 : sal_uInt16 nHtmlMode = ((const SfxUInt16Item*)pItem)->GetValue();
75 0 : if(HTMLMODE_ON & nHtmlMode)
76 : {
77 0 : aCountParaFL .Hide();
78 0 : aCountParaCB .Hide();
79 0 : aRestartParaCountCB .Hide();
80 0 : aRestartFT .Hide();
81 0 : aRestartNF .Hide();
82 : }
83 : }
84 0 : aNewStartCB.SetClickHdl(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
85 0 : aNewStartNumberCB.SetClickHdl(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
86 0 : aNumberStyleLB.SetSelectHdl(LINK(this, SwParagraphNumTabPage, StyleHdl_Impl));
87 : aCountParaCB.SetClickHdl(LINK(this,
88 0 : SwParagraphNumTabPage, LineCountHdl_Impl));
89 : aRestartParaCountCB.SetClickHdl(
90 0 : LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
91 0 : aNewStartNF.SetAccessibleName(aNewStartNumberCB.GetText());
92 0 : aNewStartNF.SetAccessibleRelationLabeledBy(&aNewStartNumberCB);
93 0 : }
94 :
95 0 : SwParagraphNumTabPage::~SwParagraphNumTabPage()
96 : {
97 0 : }
98 :
99 0 : SfxTabPage* SwParagraphNumTabPage::Create( Window* pParent,
100 : const SfxItemSet& rSet )
101 : {
102 0 : return new SwParagraphNumTabPage(pParent, rSet);
103 : }
104 :
105 0 : sal_uInt16* SwParagraphNumTabPage::GetRanges()
106 : {
107 0 : return aPageRg;
108 : }
109 :
110 0 : sal_Bool SwParagraphNumTabPage::FillItemSet( SfxItemSet& rSet )
111 : {
112 0 : if( aOutlineLvLB.GetSelectEntryPos() != aOutlineLvLB.GetSavedValue())
113 : {
114 0 : sal_uInt16 aOutlineLv = aOutlineLvLB.GetSelectEntryPos();
115 0 : const SfxUInt16Item* pOldOutlineLv = (const SfxUInt16Item*)GetOldItem( rSet, SID_ATTR_PARA_OUTLINE_LEVEL);
116 0 : SfxUInt16Item* pOutlineLv = (SfxUInt16Item*)pOldOutlineLv->Clone();
117 0 : pOutlineLv->SetValue( aOutlineLv );
118 0 : rSet.Put(*pOutlineLv);
119 0 : delete pOutlineLv;
120 0 : bModified = sal_True;
121 : }
122 :
123 0 : if( aNumberStyleLB.GetSelectEntryPos() != aNumberStyleLB.GetSavedValue())
124 : {
125 0 : String aStyle;
126 0 : if(aNumberStyleLB.GetSelectEntryPos())
127 0 : aStyle = aNumberStyleLB.GetSelectEntry();
128 0 : const SfxStringItem* pOldRule = (const SfxStringItem*)GetOldItem( rSet, SID_ATTR_PARA_NUMRULE);
129 0 : SfxStringItem* pRule = (SfxStringItem*)pOldRule->Clone();
130 0 : pRule->SetValue(aStyle);
131 0 : rSet.Put(*pRule);
132 0 : delete pRule;
133 0 : bModified = sal_True;
134 : }
135 0 : if(aNewStartCB.GetState() != aNewStartCB.GetSavedValue() ||
136 0 : aNewStartNumberCB.GetState() != aNewStartNumberCB.GetSavedValue()||
137 0 : aNewStartNF.GetText() != aNewStartNF.GetSavedValue())
138 : {
139 0 : bModified = sal_True;
140 0 : sal_Bool bNewStartChecked = STATE_CHECK == aNewStartCB.GetState();
141 0 : sal_Bool bNumberNewStartChecked = STATE_CHECK == aNewStartNumberCB.GetState();
142 0 : rSet.Put(SfxBoolItem(FN_NUMBER_NEWSTART, bNewStartChecked));
143 : rSet.Put(SfxUInt16Item(FN_NUMBER_NEWSTART_AT,
144 0 : bNumberNewStartChecked && bNewStartChecked ? (sal_uInt16)aNewStartNF.GetValue() : USHRT_MAX));
145 : }
146 :
147 0 : if(aCountParaCB.GetSavedValue() != aCountParaCB.GetState() ||
148 0 : aRestartParaCountCB.GetSavedValue() != aRestartParaCountCB.GetState() ||
149 0 : aRestartNF.GetSavedValue() != aRestartNF.GetText() )
150 : {
151 0 : SwFmtLineNumber aFmt;
152 0 : aFmt.SetStartValue( static_cast< sal_uLong >(aRestartParaCountCB.GetState() == STATE_CHECK ?
153 0 : aRestartNF.GetValue() : 0 ));
154 0 : aFmt.SetCountLines( aCountParaCB.IsChecked() );
155 0 : rSet.Put(aFmt);
156 0 : bModified = sal_True;
157 : }
158 0 : return bModified;
159 : }
160 :
161 0 : void SwParagraphNumTabPage::Reset( const SfxItemSet& rSet )
162 : {
163 0 : sal_Bool bHasNumberStyle = sal_False;
164 :
165 0 : SfxItemState eItemState = rSet.GetItemState( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) );
166 :
167 : sal_Int16 nOutlineLv;
168 0 : if( eItemState >= SFX_ITEM_AVAILABLE )
169 : {
170 0 : nOutlineLv = ((const SfxUInt16Item &)rSet.Get( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) )).GetValue();
171 0 : aOutlineLvLB.SelectEntryPos( nOutlineLv ) ;
172 : }
173 : else
174 : {
175 0 : aOutlineLvLB.SetNoSelection();
176 : }
177 0 : aOutlineLvLB.SaveValue();
178 :
179 0 : eItemState = rSet.GetItemState( GetWhich(SID_ATTR_PARA_NUMRULE) );
180 :
181 0 : String aStyle;
182 0 : if( eItemState >= SFX_ITEM_AVAILABLE )
183 : {
184 0 : aStyle = ((const SfxStringItem &)rSet.Get( GetWhich(SID_ATTR_PARA_NUMRULE) )).GetValue();
185 0 : if(!aStyle.Len())
186 0 : aStyle = aNumberStyleLB.GetEntry(0);
187 :
188 0 : if( aStyle.EqualsAscii("Outline"))
189 : {
190 0 : aNumberStyleLB.InsertEntry( msOutlineNumbering );
191 0 : aNumberStyleLB.SelectEntry( msOutlineNumbering );
192 0 : aNumberStyleLB.RemoveEntry(msOutlineNumbering);
193 0 : aNumberStyleLB.SaveValue();
194 : }
195 : else
196 0 : aNumberStyleLB.SelectEntry( aStyle );
197 :
198 0 : bHasNumberStyle = sal_True;
199 : }
200 : else
201 : {
202 0 : aNumberStyleLB.SetNoSelection();
203 : }
204 :
205 0 : aNumberStyleLB.SaveValue();
206 :
207 0 : eItemState = rSet.GetItemState( FN_NUMBER_NEWSTART );
208 0 : if(eItemState > SFX_ITEM_AVAILABLE )
209 : {
210 0 : bCurNumrule = sal_True;
211 0 : const SfxBoolItem& rStart = (const SfxBoolItem&)rSet.Get(FN_NUMBER_NEWSTART);
212 : aNewStartCB.SetState(
213 0 : rStart.GetValue() ?
214 0 : STATE_CHECK : STATE_NOCHECK );
215 0 : aNewStartCB.EnableTriState(sal_False);
216 : }
217 : else
218 0 : aNewStartCB.SetState(bHasNumberStyle ? STATE_NOCHECK : STATE_DONTKNOW);
219 0 : aNewStartCB.SaveValue();
220 :
221 0 : eItemState = rSet.GetItemState( FN_NUMBER_NEWSTART_AT);
222 0 : if( eItemState > SFX_ITEM_AVAILABLE )
223 : {
224 0 : sal_uInt16 nNewStart = ((const SfxUInt16Item&)rSet.Get(FN_NUMBER_NEWSTART_AT)).GetValue();
225 0 : aNewStartNumberCB.Check(USHRT_MAX != nNewStart);
226 0 : if(USHRT_MAX == nNewStart)
227 0 : nNewStart = 1;
228 :
229 0 : aNewStartNF.SetValue(nNewStart);
230 0 : aNewStartNumberCB.EnableTriState(sal_False);
231 : }
232 : else
233 0 : aNewStartCB.SetState(STATE_DONTKNOW);
234 0 : NewStartHdl_Impl(&aNewStartCB);
235 0 : aNewStartNF.SaveValue();
236 0 : aNewStartNumberCB.SaveValue();
237 0 : StyleHdl_Impl(&aNumberStyleLB);
238 0 : if( SFX_ITEM_AVAILABLE <= rSet.GetItemState(RES_LINENUMBER))
239 : {
240 0 : SwFmtLineNumber& rNum = (SwFmtLineNumber&)rSet.Get(RES_LINENUMBER);
241 0 : sal_uLong nStartValue = rNum.GetStartValue();
242 0 : sal_Bool bCount = rNum.IsCount();
243 0 : aCountParaCB.SetState( bCount ? STATE_CHECK : STATE_NOCHECK );
244 0 : aRestartParaCountCB.SetState( 0 != nStartValue ? STATE_CHECK : STATE_NOCHECK );
245 0 : aRestartNF.SetValue(nStartValue == 0 ? 1 : nStartValue);
246 0 : LineCountHdl_Impl(&aCountParaCB);
247 0 : aCountParaCB.EnableTriState(sal_False);
248 0 : aRestartParaCountCB.EnableTriState(sal_False);
249 : }
250 : else
251 : {
252 0 : aCountParaCB.SetState(STATE_DONTKNOW);
253 0 : aRestartParaCountCB.SetState(STATE_DONTKNOW);
254 : }
255 0 : aCountParaCB.SaveValue();
256 0 : aRestartParaCountCB.SaveValue();
257 0 : aRestartNF.SaveValue();
258 :
259 0 : bModified = sal_False;
260 0 : }
261 :
262 0 : void SwParagraphNumTabPage::DisableOutline()
263 : {
264 0 : aOutlineLvFT.Disable();
265 0 : aOutlineLvLB.Disable();
266 0 : }
267 :
268 0 : void SwParagraphNumTabPage::DisableNumbering()
269 : {
270 0 : aNumberStyleFT.Disable();
271 0 : aNumberStyleLB.Disable();
272 0 : }
273 :
274 0 : void SwParagraphNumTabPage::EnableNewStart()
275 : {
276 0 : aNewStartCB.Show();
277 0 : aNewStartNumberCB.Show();
278 0 : aNewStartNF.Show();
279 0 : }
280 :
281 0 : IMPL_LINK_NOARG(SwParagraphNumTabPage, NewStartHdl_Impl)
282 : {
283 0 : sal_Bool bEnable = aNewStartCB.IsChecked();
284 0 : aNewStartNumberCB.Enable(bEnable);
285 0 : aNewStartNF.Enable(bEnable && aNewStartNumberCB.IsChecked());
286 0 : return 0;
287 : }
288 :
289 0 : IMPL_LINK_NOARG(SwParagraphNumTabPage, LineCountHdl_Impl)
290 : {
291 0 : aRestartParaCountCB.Enable(aCountParaCB.IsChecked());
292 :
293 0 : sal_Bool bEnableRestartValue = aRestartParaCountCB.IsEnabled() &&
294 0 : aRestartParaCountCB.IsChecked();
295 0 : aRestartFT.Enable(bEnableRestartValue);
296 0 : aRestartNF.Enable(bEnableRestartValue);
297 :
298 0 : return 0;
299 : }
300 :
301 0 : IMPL_LINK( SwParagraphNumTabPage, StyleHdl_Impl, ListBox*, pBox )
302 : {
303 0 : sal_Bool bEnable = bCurNumrule || pBox->GetSelectEntryPos() > 0;
304 0 : aNewStartCB.Enable(bEnable);
305 0 : NewStartHdl_Impl(&aNewStartCB);
306 :
307 0 : return 0;
308 0 : }
309 :
310 :
311 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|