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