1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "cmdid.h"
#include "swtypes.hxx"
#include "hintids.hxx"
#include "globals.hrc"
#include "helpid.h"
#include <sfx2/objsh.hxx>
#include <sfx2/htmlmode.hxx>
#include <svx/svxids.hrc>
#include <svl/eitem.hxx>
#include <svl/stritem.hxx>
#include <svl/intitem.hxx>
#include <fmtline.hxx>
#include <numpara.hxx>
#include <app.hrc>
#include <sfx2/app.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/sfxhelp.hxx>
#include <sfx2/viewsh.hxx>
const sal_uInt16 SwParagraphNumTabPage::aPageRg[] = {
FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART_AT,
0
};
SwParagraphNumTabPage::SwParagraphNumTabPage(vcl::Window* pParent, const SfxItemSet& rAttr ) :
SfxTabPage(pParent, "NumParaPage", "modules/swriter/ui/numparapage.ui", &rAttr),
msOutlineNumbering( SW_RES( STR_OUTLINE_NUMBERING ) ),
bModified(false),
bCurNumrule(false)
{
get(m_pOutlineStartBX, "boxOUTLINE");
get(m_pOutlineLvLB, "comboLB_OUTLINE_LEVEL");
get(m_pNumberStyleBX, "boxNUMBER_STYLE");
get(m_pNumberStyleLB, "comboLB_NUMBER_STYLE");
get(m_pEditNumStyleBtn, "editnumstyle");
get(m_pNewStartBX, "boxNEW_START");
get(m_pNewStartCB, "checkCB_NEW_START");
m_pNewStartCB->SetState(TRISTATE_FALSE);
get(m_pNewStartNumberCB, "checkCB_NUMBER_NEW_START");
m_pNewStartNumberCB->SetState(TRISTATE_FALSE);
get(m_pNewStartNF, "spinNF_NEW_START");
get(m_pCountParaFram, "frameFL_COUNT_PARA");
get(m_pCountParaCB, "checkCB_COUNT_PARA");
m_pCountParaCB->SetState(TRISTATE_FALSE);
get(m_pRestartParaCountCB, "checkCB_RESTART_PARACOUNT");
m_pRestartParaCountCB->SetState(TRISTATE_FALSE);
get(m_pRestartBX, "boxRESTART_NO");
get(m_pRestartNF, "spinNF_RESTART_PARA");
sal_Int32 numSelectPos = m_pNumberStyleLB->GetSelectEntryPos();
if ( numSelectPos == 0 )
m_pEditNumStyleBtn->Disable();
else
m_pEditNumStyleBtn->Enable();
const SfxPoolItem* pItem;
SfxObjectShell* pObjSh;
if(SfxItemState::SET == rAttr.GetItemState(SID_HTML_MODE, false, &pItem) ||
( 0 != ( pObjSh = SfxObjectShell::Current()) &&
0 != (pItem = pObjSh->GetItem(SID_HTML_MODE))))
{
const sal_uInt16 nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
if (HTMLMODE_ON & nHtmlMode)
m_pCountParaFram->Hide();
}
m_pNewStartCB->SetClickHdl(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
m_pNewStartNumberCB->SetClickHdl(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
m_pNumberStyleLB->SetSelectHdl(LINK(this, SwParagraphNumTabPage, StyleHdl_Impl));
m_pCountParaCB->SetClickHdl(LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
m_pRestartParaCountCB->SetClickHdl( LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
m_pNumberStyleLB->SetSelectHdl( LINK( this, SwParagraphNumTabPage, EditNumStyleSelectHdl_Impl ) );
m_pEditNumStyleBtn->SetClickHdl( LINK(this, SwParagraphNumTabPage, EditNumStyleHdl_Impl));
}
SwParagraphNumTabPage::~SwParagraphNumTabPage()
{
disposeOnce();
}
void SwParagraphNumTabPage::dispose()
{
m_pOutlineStartBX.clear();
m_pOutlineLvLB.clear();
m_pNumberStyleBX.clear();
m_pNumberStyleLB.clear();
m_pEditNumStyleBtn.clear();
m_pNewStartCB.clear();
m_pNewStartBX.clear();
m_pNewStartNumberCB.clear();
m_pNewStartNF.clear();
m_pCountParaFram.clear();
m_pCountParaCB.clear();
m_pRestartParaCountCB.clear();
m_pRestartBX.clear();
m_pRestartNF.clear();
SfxTabPage::dispose();
}
VclPtr<SfxTabPage> SwParagraphNumTabPage::Create( vcl::Window* pParent,
const SfxItemSet* rSet )
{
return VclPtr<SwParagraphNumTabPage>::Create(pParent, *rSet);
}
bool SwParagraphNumTabPage::FillItemSet( SfxItemSet* rSet )
{
if( m_pOutlineLvLB->IsValueChangedFromSaved())
{
const sal_uInt16 aOutlineLv = m_pOutlineLvLB->GetSelectEntryPos();
const SfxUInt16Item* pOldOutlineLv = static_cast<const SfxUInt16Item*>(GetOldItem( *rSet, SID_ATTR_PARA_OUTLINE_LEVEL));
if (pOldOutlineLv)
{
SfxUInt16Item* pOutlineLv = static_cast<SfxUInt16Item*>(pOldOutlineLv->Clone());
pOutlineLv->SetValue( aOutlineLv );
rSet->Put(*pOutlineLv);
delete pOutlineLv;
bModified = true;
}
}
if( m_pNumberStyleLB->IsValueChangedFromSaved())
{
OUString aStyle;
if(m_pNumberStyleLB->GetSelectEntryPos())
aStyle = m_pNumberStyleLB->GetSelectEntry();
const SfxStringItem* pOldRule = static_cast<const SfxStringItem*>(GetOldItem( *rSet, SID_ATTR_PARA_NUMRULE));
SfxStringItem* pRule = pOldRule ? static_cast<SfxStringItem*>(pOldRule->Clone()) : NULL;
if (pRule)
{
pRule->SetValue(aStyle);
rSet->Put(*pRule);
delete pRule;
bModified = true;
}
}
if(m_pNewStartCB->IsValueChangedFromSaved() ||
m_pNewStartNumberCB->IsValueChangedFromSaved()||
m_pNewStartNF->IsValueChangedFromSaved())
{
bModified = true;
bool bNewStartChecked = TRISTATE_TRUE == m_pNewStartCB->GetState();
bool bNumberNewStartChecked = TRISTATE_TRUE == m_pNewStartNumberCB->GetState();
rSet->Put(SfxBoolItem(FN_NUMBER_NEWSTART, bNewStartChecked));
rSet->Put(SfxUInt16Item(FN_NUMBER_NEWSTART_AT,
bNumberNewStartChecked && bNewStartChecked ? (sal_uInt16)m_pNewStartNF->GetValue() : USHRT_MAX));
}
if(m_pCountParaCB->IsValueChangedFromSaved()||
m_pRestartParaCountCB->IsValueChangedFromSaved() ||
m_pRestartNF->IsValueChangedFromSaved() )
{
SwFormatLineNumber aFormat;
aFormat.SetStartValue( static_cast< sal_uLong >(m_pRestartParaCountCB->GetState() == TRISTATE_TRUE ?
m_pRestartNF->GetValue() : 0 ));
aFormat.SetCountLines( m_pCountParaCB->IsChecked() );
rSet->Put(aFormat);
bModified = true;
}
return bModified;
}
void SwParagraphNumTabPage::Reset( const SfxItemSet* rSet )
{
bool bHasNumberStyle = false;
SfxItemState eItemState = rSet->GetItemState( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) );
sal_Int16 nOutlineLv;
if( eItemState >= SfxItemState::DEFAULT )
{
nOutlineLv = static_cast<const SfxUInt16Item &>(rSet->Get( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) )).GetValue();
m_pOutlineLvLB->SelectEntryPos( nOutlineLv ) ;
}
else
{
m_pOutlineLvLB->SetNoSelection();
}
m_pOutlineLvLB->SaveValue();
eItemState = rSet->GetItemState( GetWhich(SID_ATTR_PARA_NUMRULE) );
if( eItemState >= SfxItemState::DEFAULT )
{
OUString aStyle = static_cast<const SfxStringItem &>(rSet->Get( GetWhich(SID_ATTR_PARA_NUMRULE) )).GetValue();
if(aStyle.isEmpty())
aStyle = m_pNumberStyleLB->GetEntry(0);
if( aStyle == "Outline")
{
m_pNumberStyleLB->InsertEntry( msOutlineNumbering );
m_pNumberStyleLB->SelectEntry( msOutlineNumbering );
m_pNumberStyleLB->RemoveEntry(msOutlineNumbering);
m_pNumberStyleLB->SaveValue();
}
else
m_pNumberStyleLB->SelectEntry( aStyle );
bHasNumberStyle = true;
}
else
{
m_pNumberStyleLB->SetNoSelection();
}
m_pNumberStyleLB->SaveValue();
eItemState = rSet->GetItemState( FN_NUMBER_NEWSTART );
if(eItemState > SfxItemState::DEFAULT )
{
bCurNumrule = true;
const SfxBoolItem& rStart = static_cast<const SfxBoolItem&>(rSet->Get(FN_NUMBER_NEWSTART));
m_pNewStartCB->SetState(rStart.GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
m_pNewStartCB->EnableTriState(false);
}
else
m_pNewStartCB->SetState(bHasNumberStyle ? TRISTATE_FALSE : TRISTATE_INDET);
m_pNewStartCB->SaveValue();
eItemState = rSet->GetItemState( FN_NUMBER_NEWSTART_AT);
if( eItemState > SfxItemState::DEFAULT )
{
const sal_uInt16 nNewStart = static_cast<const SfxUInt16Item&>(rSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue();
const bool bNotMax = USHRT_MAX != nNewStart;
m_pNewStartNumberCB->Check(bNotMax);
m_pNewStartNF->SetValue(bNotMax ? nNewStart : 1);
m_pNewStartNumberCB->EnableTriState(false);
}
else
m_pNewStartCB->SetState(TRISTATE_INDET);
NewStartHdl_Impl(m_pNewStartCB);
m_pNewStartNF->SaveValue();
m_pNewStartNumberCB->SaveValue();
StyleHdl_Impl(m_pNumberStyleLB);
if( SfxItemState::DEFAULT <= rSet->GetItemState(RES_LINENUMBER))
{
const SwFormatLineNumber& rNum = static_cast<const SwFormatLineNumber&>(rSet->Get(RES_LINENUMBER));
sal_uLong nStartValue = rNum.GetStartValue();
bool bCount = rNum.IsCount();
m_pCountParaCB->SetState( bCount ? TRISTATE_TRUE : TRISTATE_FALSE );
m_pRestartParaCountCB->SetState( 0 != nStartValue ? TRISTATE_TRUE : TRISTATE_FALSE );
m_pRestartNF->SetValue(nStartValue == 0 ? 1 : nStartValue);
LineCountHdl_Impl(m_pCountParaCB);
m_pCountParaCB->EnableTriState(false);
m_pRestartParaCountCB->EnableTriState(false);
}
else
{
m_pCountParaCB->SetState(TRISTATE_INDET);
m_pRestartParaCountCB->SetState(TRISTATE_INDET);
}
m_pCountParaCB->SaveValue();
m_pRestartParaCountCB->SaveValue();
m_pRestartNF->SaveValue();
bModified = false;
}
void SwParagraphNumTabPage::DisableOutline()
{
m_pOutlineStartBX->Disable();
}
void SwParagraphNumTabPage::DisableNumbering()
{
m_pNumberStyleBX->Disable();
}
void SwParagraphNumTabPage::EnableNewStart()
{
m_pNewStartCB->Show();
m_pNewStartBX->Show();
}
IMPL_LINK_NOARG(SwParagraphNumTabPage, NewStartHdl_Impl)
{
bool bEnable = m_pNewStartCB->IsChecked();
m_pNewStartNumberCB->Enable(bEnable);
m_pNewStartNF->Enable(bEnable && m_pNewStartNumberCB->IsChecked());
return 0;
}
IMPL_LINK_NOARG(SwParagraphNumTabPage, LineCountHdl_Impl)
{
m_pRestartParaCountCB->Enable(m_pCountParaCB->IsChecked());
bool bEnableRestartValue = m_pRestartParaCountCB->IsEnabled() &&
m_pRestartParaCountCB->IsChecked();
m_pRestartBX->Enable(bEnableRestartValue);
return 0;
}
IMPL_LINK_NOARG( SwParagraphNumTabPage, EditNumStyleSelectHdl_Impl )
{
sal_Int32 numSelectPos = m_pNumberStyleLB->GetSelectEntryPos();
if ( numSelectPos == 0 )
m_pEditNumStyleBtn->Disable();
else
m_pEditNumStyleBtn->Enable();
return 0;
}
IMPL_LINK_NOARG(SwParagraphNumTabPage, EditNumStyleHdl_Impl)
{
OUString aTemplName(m_pNumberStyleLB->GetSelectEntry());
ExecuteEditNumStyle_Impl( SID_STYLE_EDIT, aTemplName, OUString(),SFX_STYLE_FAMILY_PARA, 0 );
return 0;
}
// Internal: Perform functions through the Dispatcher
bool SwParagraphNumTabPage::ExecuteEditNumStyle_Impl(
sal_uInt16 nId, const OUString &rStr, const OUString& rRefStr, sal_uInt16 nFamily,
sal_uInt16 nMask, const sal_uInt16* pModifier)
{
SfxDispatcher &rDispatcher = *SfxViewShell::Current()->GetDispatcher();
SfxStringItem aItem(nId, rStr);
SfxUInt16Item aFamily(SID_STYLE_FAMILY, nFamily);
SfxUInt16Item aMask( SID_STYLE_MASK, nMask );
SfxStringItem aUpdName(SID_STYLE_UPD_BY_EX_NAME, rStr);
SfxStringItem aRefName( SID_STYLE_REFERENCE, rRefStr );
const SfxPoolItem* pItems[ 6 ];
sal_uInt16 nCount = 0;
if( !rStr.isEmpty() )
pItems[ nCount++ ] = &aItem;
pItems[ nCount++ ] = &aFamily;
if( nMask )
pItems[ nCount++ ] = &aMask;
if( !rRefStr.isEmpty() )
pItems[ nCount++ ] = &aRefName;
pItems[ nCount++ ] = 0;
sal_uInt16 nModi = pModifier ? *pModifier : 0;
const SfxPoolItem* mpItem = rDispatcher.Execute(
nId, SfxCallMode::SYNCHRON | SfxCallMode::RECORD | SfxCallMode::MODAL,
pItems, nModi );
if ( !mpItem )
return false;
return true;
}
IMPL_LINK( SwParagraphNumTabPage, StyleHdl_Impl, ListBox*, pBox )
{
bool bEnable = bCurNumrule || pBox->GetSelectEntryPos() > 0;
m_pNewStartCB->Enable(bEnable);
NewStartHdl_Impl(m_pNewStartCB);
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|