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 <sfx2/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 :
34 : #include <app.hrc>
35 :
36 :
37 : // Globals ******************************************************************
38 :
39 : static sal_uInt16 aPageRg[] = {
40 : FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART_AT,
41 : 0
42 : };
43 :
44 0 : SwParagraphNumTabPage::SwParagraphNumTabPage(Window* pParent, const SfxItemSet& rAttr ) :
45 : SfxTabPage(pParent, "NumParaPage", "modules/swriter/ui/numparapage.ui", rAttr),
46 :
47 : msOutlineNumbering( SW_RES( STR_OUTLINE_NUMBERING ) ),
48 : bModified(sal_False),
49 0 : bCurNumrule(sal_False)
50 : {
51 0 : get(m_pOutlineStartBX, "boxOUTLINE");
52 0 : get(m_pOutlineLvLB, "comboLB_OUTLINE_LEVEL");
53 :
54 0 : get(m_pNumberStyleBX, "boxNUMBER_STYLE");
55 0 : get(m_pNumberStyleLB, "comboLB_NUMBER_STYLE");
56 :
57 0 : get(m_pNewStartBX, "boxNEW_START");
58 0 : get(m_pNewStartCB, "checkCB_NEW_START");
59 0 : m_pNewStartCB->SetState(STATE_NOCHECK);
60 0 : get(m_pNewStartNumberCB, "checkCB_NUMBER_NEW_START");
61 0 : m_pNewStartNumberCB->SetState(STATE_NOCHECK);
62 0 : get(m_pNewStartNF, "spinNF_NEW_START");
63 :
64 0 : get(m_pCountParaFram, "frameFL_COUNT_PARA");
65 0 : get(m_pCountParaCB, "checkCB_COUNT_PARA");
66 0 : m_pCountParaCB->SetState(STATE_NOCHECK);
67 0 : get(m_pRestartParaCountCB, "checkCB_RESTART_PARACOUNT");
68 0 : m_pRestartParaCountCB->SetState(STATE_NOCHECK);
69 :
70 0 : get(m_pRestartBX, "boxRESTART_NO");
71 0 : get(m_pRestartNF, "spinNF_RESTART_PARA");
72 :
73 : const SfxPoolItem* pItem;
74 : SfxObjectShell* pObjSh;
75 0 : if(SFX_ITEM_SET == rAttr.GetItemState(SID_HTML_MODE, sal_False, &pItem) ||
76 0 : ( 0 != ( pObjSh = SfxObjectShell::Current()) &&
77 0 : 0 != (pItem = pObjSh->GetItem(SID_HTML_MODE))))
78 : {
79 0 : sal_uInt16 nHtmlMode = ((const SfxUInt16Item*)pItem)->GetValue();
80 :
81 0 : if (HTMLMODE_ON & nHtmlMode)
82 0 : m_pCountParaFram->Hide();
83 : }
84 :
85 0 : m_pNewStartCB->SetClickHdl(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
86 0 : m_pNewStartNumberCB->SetClickHdl(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
87 0 : m_pNumberStyleLB->SetSelectHdl(LINK(this, SwParagraphNumTabPage, StyleHdl_Impl));
88 0 : m_pCountParaCB->SetClickHdl(LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
89 0 : m_pRestartParaCountCB->SetClickHdl( LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
90 0 : }
91 :
92 0 : SwParagraphNumTabPage::~SwParagraphNumTabPage()
93 : {
94 0 : }
95 :
96 0 : SfxTabPage* SwParagraphNumTabPage::Create( Window* pParent,
97 : const SfxItemSet& rSet )
98 : {
99 0 : return new SwParagraphNumTabPage(pParent, rSet);
100 : }
101 :
102 0 : sal_uInt16* SwParagraphNumTabPage::GetRanges()
103 : {
104 0 : return aPageRg;
105 : }
106 :
107 0 : sal_Bool SwParagraphNumTabPage::FillItemSet( SfxItemSet& rSet )
108 : {
109 0 : if( m_pOutlineLvLB->GetSelectEntryPos() != m_pOutlineLvLB->GetSavedValue())
110 : {
111 0 : sal_uInt16 aOutlineLv = m_pOutlineLvLB->GetSelectEntryPos();
112 0 : const SfxUInt16Item* pOldOutlineLv = (const SfxUInt16Item*)GetOldItem( rSet, SID_ATTR_PARA_OUTLINE_LEVEL);
113 0 : SfxUInt16Item* pOutlineLv = (SfxUInt16Item*)pOldOutlineLv->Clone();
114 0 : pOutlineLv->SetValue( aOutlineLv );
115 0 : rSet.Put(*pOutlineLv);
116 0 : delete pOutlineLv;
117 0 : bModified = sal_True;
118 : }
119 :
120 0 : if( m_pNumberStyleLB->GetSelectEntryPos() != m_pNumberStyleLB->GetSavedValue())
121 : {
122 0 : OUString aStyle;
123 0 : if(m_pNumberStyleLB->GetSelectEntryPos())
124 0 : aStyle = m_pNumberStyleLB->GetSelectEntry();
125 0 : const SfxStringItem* pOldRule = (const SfxStringItem*)GetOldItem( rSet, SID_ATTR_PARA_NUMRULE);
126 0 : SfxStringItem* pRule = (SfxStringItem*)pOldRule->Clone();
127 0 : pRule->SetValue(aStyle);
128 0 : rSet.Put(*pRule);
129 0 : delete pRule;
130 0 : bModified = sal_True;
131 : }
132 0 : if(m_pNewStartCB->GetState() != m_pNewStartCB->GetSavedValue() ||
133 0 : m_pNewStartNumberCB->GetState() != m_pNewStartNumberCB->GetSavedValue()||
134 0 : m_pNewStartNF->GetText() != m_pNewStartNF->GetSavedValue())
135 : {
136 0 : bModified = sal_True;
137 0 : bool bNewStartChecked = STATE_CHECK == m_pNewStartCB->GetState();
138 0 : bool bNumberNewStartChecked = STATE_CHECK == m_pNewStartNumberCB->GetState();
139 0 : rSet.Put(SfxBoolItem(FN_NUMBER_NEWSTART, bNewStartChecked));
140 : rSet.Put(SfxUInt16Item(FN_NUMBER_NEWSTART_AT,
141 0 : bNumberNewStartChecked && bNewStartChecked ? (sal_uInt16)m_pNewStartNF->GetValue() : USHRT_MAX));
142 : }
143 :
144 0 : if(m_pCountParaCB->GetSavedValue() != m_pCountParaCB->GetState() ||
145 0 : m_pRestartParaCountCB->GetSavedValue() != m_pRestartParaCountCB->GetState() ||
146 0 : m_pRestartNF->GetSavedValue() != m_pRestartNF->GetText() )
147 : {
148 0 : SwFmtLineNumber aFmt;
149 0 : aFmt.SetStartValue( static_cast< sal_uLong >(m_pRestartParaCountCB->GetState() == STATE_CHECK ?
150 0 : m_pRestartNF->GetValue() : 0 ));
151 0 : aFmt.SetCountLines( m_pCountParaCB->IsChecked() );
152 0 : rSet.Put(aFmt);
153 0 : bModified = sal_True;
154 : }
155 0 : return bModified;
156 : }
157 :
158 0 : void SwParagraphNumTabPage::Reset( const SfxItemSet& rSet )
159 : {
160 0 : bool bHasNumberStyle = false;
161 :
162 0 : SfxItemState eItemState = rSet.GetItemState( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) );
163 :
164 : sal_Int16 nOutlineLv;
165 0 : if( eItemState >= SFX_ITEM_AVAILABLE )
166 : {
167 0 : nOutlineLv = ((const SfxUInt16Item &)rSet.Get( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) )).GetValue();
168 0 : m_pOutlineLvLB->SelectEntryPos( nOutlineLv ) ;
169 : }
170 : else
171 : {
172 0 : m_pOutlineLvLB->SetNoSelection();
173 : }
174 0 : m_pOutlineLvLB->SaveValue();
175 :
176 0 : eItemState = rSet.GetItemState( GetWhich(SID_ATTR_PARA_NUMRULE) );
177 :
178 0 : OUString aStyle;
179 0 : if( eItemState >= SFX_ITEM_AVAILABLE )
180 : {
181 0 : aStyle = ((const SfxStringItem &)rSet.Get( GetWhich(SID_ATTR_PARA_NUMRULE) )).GetValue();
182 0 : if(aStyle.isEmpty())
183 0 : aStyle = m_pNumberStyleLB->GetEntry(0);
184 :
185 0 : if( aStyle == "Outline")
186 : {
187 0 : m_pNumberStyleLB->InsertEntry( msOutlineNumbering );
188 0 : m_pNumberStyleLB->SelectEntry( msOutlineNumbering );
189 0 : m_pNumberStyleLB->RemoveEntry(msOutlineNumbering);
190 0 : m_pNumberStyleLB->SaveValue();
191 : }
192 : else
193 0 : m_pNumberStyleLB->SelectEntry( aStyle );
194 :
195 0 : bHasNumberStyle = true;
196 : }
197 : else
198 : {
199 0 : m_pNumberStyleLB->SetNoSelection();
200 : }
201 :
202 0 : m_pNumberStyleLB->SaveValue();
203 :
204 0 : eItemState = rSet.GetItemState( FN_NUMBER_NEWSTART );
205 0 : if(eItemState > SFX_ITEM_AVAILABLE )
206 : {
207 0 : bCurNumrule = sal_True;
208 0 : const SfxBoolItem& rStart = (const SfxBoolItem&)rSet.Get(FN_NUMBER_NEWSTART);
209 :
210 0 : m_pNewStartCB->SetState(rStart.GetValue() ? STATE_CHECK : STATE_NOCHECK );
211 :
212 0 : m_pNewStartCB->EnableTriState(sal_False);
213 : }
214 : else
215 0 : m_pNewStartCB->SetState(bHasNumberStyle ? STATE_NOCHECK : STATE_DONTKNOW);
216 :
217 0 : m_pNewStartCB->SaveValue();
218 :
219 0 : eItemState = rSet.GetItemState( FN_NUMBER_NEWSTART_AT);
220 0 : if( eItemState > SFX_ITEM_AVAILABLE )
221 : {
222 0 : sal_uInt16 nNewStart = ((const SfxUInt16Item&)rSet.Get(FN_NUMBER_NEWSTART_AT)).GetValue();
223 0 : m_pNewStartNumberCB->Check(USHRT_MAX != nNewStart);
224 0 : if(USHRT_MAX == nNewStart)
225 0 : nNewStart = 1;
226 :
227 0 : m_pNewStartNF->SetValue(nNewStart);
228 0 : m_pNewStartNumberCB->EnableTriState(sal_False);
229 : }
230 : else
231 0 : m_pNewStartCB->SetState(STATE_DONTKNOW);
232 0 : NewStartHdl_Impl(m_pNewStartCB);
233 0 : m_pNewStartNF->SaveValue();
234 0 : m_pNewStartNumberCB->SaveValue();
235 0 : StyleHdl_Impl(m_pNumberStyleLB);
236 0 : if( SFX_ITEM_AVAILABLE <= rSet.GetItemState(RES_LINENUMBER))
237 : {
238 0 : SwFmtLineNumber& rNum = (SwFmtLineNumber&)rSet.Get(RES_LINENUMBER);
239 0 : sal_uLong nStartValue = rNum.GetStartValue();
240 0 : bool bCount = rNum.IsCount();
241 0 : m_pCountParaCB->SetState( bCount ? STATE_CHECK : STATE_NOCHECK );
242 0 : m_pRestartParaCountCB->SetState( 0 != nStartValue ? STATE_CHECK : STATE_NOCHECK );
243 0 : m_pRestartNF->SetValue(nStartValue == 0 ? 1 : nStartValue);
244 0 : LineCountHdl_Impl(m_pCountParaCB);
245 0 : m_pCountParaCB->EnableTriState(sal_False);
246 0 : m_pRestartParaCountCB->EnableTriState(sal_False);
247 : }
248 : else
249 : {
250 0 : m_pCountParaCB->SetState(STATE_DONTKNOW);
251 0 : m_pRestartParaCountCB->SetState(STATE_DONTKNOW);
252 : }
253 0 : m_pCountParaCB->SaveValue();
254 0 : m_pRestartParaCountCB->SaveValue();
255 0 : m_pRestartNF->SaveValue();
256 :
257 0 : bModified = sal_False;
258 0 : }
259 :
260 0 : void SwParagraphNumTabPage::DisableOutline()
261 : {
262 0 : m_pOutlineStartBX->Disable();
263 0 : }
264 :
265 0 : void SwParagraphNumTabPage::DisableNumbering()
266 : {
267 0 : m_pNumberStyleBX->Disable();
268 0 : }
269 :
270 0 : void SwParagraphNumTabPage::EnableNewStart()
271 : {
272 0 : m_pNewStartCB->Show();
273 0 : m_pNewStartBX->Show();
274 0 : }
275 :
276 0 : IMPL_LINK_NOARG(SwParagraphNumTabPage, NewStartHdl_Impl)
277 : {
278 0 : bool bEnable = m_pNewStartCB->IsChecked();
279 0 : m_pNewStartNumberCB->Enable(bEnable);
280 0 : m_pNewStartNF->Enable(bEnable && m_pNewStartNumberCB->IsChecked());
281 0 : return 0;
282 : }
283 :
284 0 : IMPL_LINK_NOARG(SwParagraphNumTabPage, LineCountHdl_Impl)
285 : {
286 0 : m_pRestartParaCountCB->Enable(m_pCountParaCB->IsChecked());
287 :
288 0 : bool bEnableRestartValue = m_pRestartParaCountCB->IsEnabled() &&
289 0 : m_pRestartParaCountCB->IsChecked();
290 0 : m_pRestartBX->Enable(bEnableRestartValue);
291 :
292 0 : return 0;
293 : }
294 :
295 0 : IMPL_LINK( SwParagraphNumTabPage, StyleHdl_Impl, ListBox*, pBox )
296 : {
297 0 : bool bEnable = bCurNumrule || pBox->GetSelectEntryPos() > 0;
298 0 : m_pNewStartCB->Enable(bEnable);
299 0 : NewStartHdl_Impl(m_pNewStartCB);
300 :
301 0 : return 0;
302 0 : }
303 :
304 :
305 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|