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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
|
/* -*- 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 <view.hxx>
#include <wrtsh.hxx>
#include <cption.hxx>
#include <fldmgr.hxx>
#include <expfld.hxx>
#include <numrule.hxx>
#include <poolfmt.hxx>
#include <docsh.hxx>
#include <frmfmt.hxx>
#include <calc.hxx>
#include <uitool.hxx>
#include <doc.hxx>
#include <modcfg.hxx>
#include <swmodule.hxx>
#include <com/sun/star/text/GraphicCrop.hpp>
#include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
#include <com/sun/star/text/XTextTableCursor.hpp>
#include <com/sun/star/text/XTextTablesSupplier.hpp>
#include <com/sun/star/text/TableColumnSeparator.hpp>
#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
#include <com/sun/star/text/XTextFramesSupplier.hpp>
#include <com/sun/star/text/XTextFrame.hpp>
#include <comphelper/string.hxx>
#include <vcl/weld.hxx>
#include <initui.hxx>
#include <globals.hrc>
#include <strings.hrc>
#include <SwStyleNameMapper.hxx>
using namespace ::com::sun::star;
class SwSequenceOptionDialog : public weld::GenericDialogController
{
SwView& m_rView;
OUString const m_aFieldTypeName;
std::unique_ptr<weld::ComboBox> m_xLbLevel;
std::unique_ptr<weld::Entry> m_xEdDelim;
std::unique_ptr<weld::ComboBox> m_xLbCharStyle;
std::unique_ptr<weld::CheckButton> m_xApplyBorderAndShadowCB;
//#i61007# order of captions
std::unique_ptr<weld::ComboBox> m_xLbCaptionOrder;
public:
SwSequenceOptionDialog(weld::Window *pParent, SwView &rV, const OUString& rSeqFieldType);
void Apply();
bool IsApplyBorderAndShadow() { return m_xApplyBorderAndShadowCB->get_active(); }
void SetApplyBorderAndShadow( bool bSet ) { m_xApplyBorderAndShadowCB->set_active(bSet); }
//#i61007# order of captions
bool IsOrderNumberingFirst() const { return m_xLbCaptionOrder->get_active() == 1; }
void SetOrderNumberingFirst(bool bSet) { m_xLbCaptionOrder->set_active(bSet ? 1 : 0); }
void SetCharacterStyle(const OUString& rStyle);
OUString GetCharacterStyle() const;
short execute()
{
int nRet = run();
if (nRet == RET_OK)
Apply();
return nRet;
}
};
OUString SwCaptionDialog::our_aSepTextSave(": "); // Caption separator text
//Resolves: tdf#47427 disallow typing *or* pasting invalid content into the category box
OUString TextFilterAutoConvert::filter(const OUString &rText)
{
if (!rText.isEmpty() && rText != m_sNone && !SwCalc::IsValidVarName(rText))
return m_sLastGoodText;
m_sLastGoodText = rText;
return rText;
}
SwCaptionDialog::SwCaptionDialog( vcl::Window *pParent, SwView &rV ) :
SvxStandardDialog( pParent, "InsertCaptionDialog", "modules/swriter/ui/insertcaption.ui" ),
m_sNone( SwResId(SW_STR_NONE) ),
m_aTextFilter(m_sNone),
rView( rV ),
pMgr( new SwFieldMgr(rView.GetWrtShellPtr()) ),
bCopyAttributes( false ),
bOrderNumberingFirst( SW_MOD()->GetModuleConfig()->IsCaptionOrderNumberingFirst() )
{
get(m_pTextEdit, "caption_edit");
get(m_pCategoryBox, "category");
m_pCategoryBox->SetTextFilter(&m_aTextFilter);
get(m_pFormatText, "numbering_label");
get(m_pFormatBox, "numbering");
get(m_pNumberingSeparatorFT, "num_separator");
get(m_pNumberingSeparatorED, "num_separator_edit");
get(m_pSepText, "separator_label");
get(m_pSepEdit, "separator_edit");
get(m_pPosText, "position_label");
get(m_pPosBox, "position");
get(m_pPreview, "preview");
get(m_pOKButton, "ok");
get(m_pAutoCaptionButton, "auto");
get(m_pOptionButton, "options");
//#i61007# order of captions
ApplyCaptionOrder();
SwWrtShell &rSh = rView.GetWrtShell();
uno::Reference< frame::XModel > xModel = rView.GetDocShell()->GetBaseModel();
SelectionType eType = rSh.GetSelectionType();
if ( eType & SelectionType::Ole )
{
eType = SelectionType::Graphic;
uno::Reference< text::XTextEmbeddedObjectsSupplier > xObjs(xModel, uno::UNO_QUERY);
xNameAccess = xObjs->getEmbeddedObjects();
}
Link<Edit&,void> aLk = LINK( this, SwCaptionDialog, ModifyHdl );
m_pCategoryBox->SetModifyHdl( aLk );
m_pTextEdit->SetModifyHdl( aLk );
m_pNumberingSeparatorED->SetModifyHdl ( aLk );
m_pSepEdit->SetModifyHdl( aLk );
m_pCategoryBox->SetSelectHdl( LINK(this, SwCaptionDialog, SelectHdl) );
m_pFormatBox->SetSelectHdl( LINK(this, SwCaptionDialog, SelectListBoxHdl) );
m_pOptionButton->SetClickHdl( LINK( this, SwCaptionDialog, OptionHdl ) );
m_pAutoCaptionButton->SetClickHdl(LINK(this, SwCaptionDialog, CaptionHdl));
m_pCategoryBox->InsertEntry( m_sNone );
size_t nCount = pMgr->GetFieldTypeCount();
for (size_t i = 0; i < nCount; ++i)
{
SwFieldType *pType = pMgr->GetFieldType( SwFieldIds::Unknown, i );
if( pType->Which() == SwFieldIds::SetExp &&
static_cast<SwSetExpFieldType *>( pType)->GetType() & nsSwGetSetExpType::GSE_SEQ )
m_pCategoryBox->InsertEntry(pType->GetName());
}
OUString sString;
sal_uInt16 nPoolId = 0;
if (eType & SelectionType::Graphic)
{
nPoolId = RES_POOLCOLL_LABEL_FIGURE;
sString = ::GetOldGrfCat();
bCopyAttributes = true;
//if not OLE
if(!xNameAccess.is())
{
uno::Reference< text::XTextGraphicObjectsSupplier > xGraphics(xModel, uno::UNO_QUERY);
xNameAccess = xGraphics->getGraphicObjects();
}
}
else if( eType & SelectionType::Table )
{
nPoolId = RES_POOLCOLL_LABEL_TABLE;
sString = ::GetOldTabCat();
uno::Reference< text::XTextTablesSupplier > xTables(xModel, uno::UNO_QUERY);
xNameAccess = xTables->getTextTables();
}
else if( eType & SelectionType::Frame )
{
nPoolId = RES_POOLCOLL_LABEL_FRAME;
sString = ::GetOldFrameCat();
uno::Reference< text::XTextFramesSupplier > xFrames(xModel, uno::UNO_QUERY);
xNameAccess = xFrames->getTextFrames();
}
else if( eType == SelectionType::Text )
{
nPoolId = RES_POOLCOLL_LABEL_FRAME;
sString = ::GetOldFrameCat();
}
else if( eType & SelectionType::DrawObject )
{
nPoolId = RES_POOLCOLL_LABEL_DRAWING;
sString = ::GetOldDrwCat();
}
if( nPoolId )
{
if (!sString.isEmpty())
m_pCategoryBox->SetText( sString );
else
m_pCategoryBox->SetText(
SwStyleNameMapper::GetUIName( nPoolId, OUString() ));
}
// aFormatBox
sal_uInt16 nSelFormat = SVX_NUM_ARABIC;
nCount = pMgr->GetFieldTypeCount();
for ( size_t i = nCount; i; )
{
SwFieldType* pFieldType = pMgr->GetFieldType(SwFieldIds::Unknown, --i);
if( pFieldType->GetName() == m_pCategoryBox->GetText() )
{
nSelFormat = static_cast<sal_uInt16>(static_cast<SwSetExpFieldType*>(pFieldType)->GetSeqFormat());
break;
}
}
sal_uInt16 nFormatCount = pMgr->GetFormatCount(TYP_SEQFLD, false);
for ( sal_uInt16 i = 0; i < nFormatCount; ++i )
{
m_pFormatBox->InsertEntry( pMgr->GetFormatStr(TYP_SEQFLD, i) );
const sal_uInt16 nFormatId = pMgr->GetFormatId(TYP_SEQFLD, i);
m_pFormatBox->SetEntryData( i, reinterpret_cast<void*>( nFormatId ) );
if( nFormatId == nSelFormat )
m_pFormatBox->SelectEntryPos( i );
}
// aPosBox
if (eType == SelectionType::Graphic
|| eType == SelectionType::Table
|| eType == (SelectionType::Table | SelectionType::NumberList)
|| eType == (SelectionType::Table | SelectionType::Text)
|| eType == (SelectionType::Table | SelectionType::NumberList | SelectionType::Text)
|| eType == SelectionType::DrawObject
|| eType == (SelectionType::DrawObject | SelectionType::Ornament))
{
m_pPosBox->InsertEntry(SwResId(STR_CAPTION_ABOVE));
m_pPosBox->InsertEntry(SwResId(STR_CAPTION_BELOW));
}
else if(eType == SelectionType::Frame
|| eType == SelectionType::Text)
{
m_pPosBox->InsertEntry(SwResId(STR_CAPTION_BEGINNING));
m_pPosBox->InsertEntry(SwResId(STR_CAPTION_END ));
}
if (eType & SelectionType::Table)
{
m_pPosBox->SelectEntryPos(0);
}
else
{
m_pPosBox->SelectEntryPos(1);
}
m_pCategoryBox->GetModifyHdl().Call(*m_pCategoryBox);
m_pSepEdit->SetText(our_aSepTextSave);
m_pTextEdit->GrabFocus();
DrawSample();
}
void SwCaptionDialog::Apply()
{
InsCaptionOpt aOpt;
aOpt.UseCaption() = true;
OUString aName( m_pCategoryBox->GetText() );
if ( aName == m_sNone )
{
aOpt.SetCategory( OUString() );
aOpt.SetNumSeparator( OUString() );
}
else
{
aOpt.SetCategory(comphelper::string::strip(aName, ' '));
aOpt.SetNumSeparator( m_pNumberingSeparatorED->GetText() );
}
aOpt.SetNumType( static_cast<sal_uInt16>(reinterpret_cast<sal_uIntPtr>(m_pFormatBox->GetSelectedEntryData())) );
aOpt.SetSeparator( m_pSepEdit->IsEnabled() ? m_pSepEdit->GetText() : OUString() );
aOpt.SetCaption( m_pTextEdit->GetText() );
aOpt.SetPos( m_pPosBox->GetSelectedEntryPos() );
aOpt.IgnoreSeqOpts() = true;
aOpt.CopyAttributes() = bCopyAttributes;
aOpt.SetCharacterStyle( sCharacterStyle );
rView.InsertCaption( &aOpt );
our_aSepTextSave = m_pSepEdit->GetText();
}
IMPL_LINK_NOARG( SwCaptionDialog, OptionHdl, Button*, void )
{
OUString sFieldTypeName = m_pCategoryBox->GetText();
if(sFieldTypeName == m_sNone)
sFieldTypeName.clear();
SwSequenceOptionDialog aDlg(GetFrameWeld(), rView, sFieldTypeName);
aDlg.SetApplyBorderAndShadow(bCopyAttributes);
aDlg.SetCharacterStyle( sCharacterStyle );
aDlg.SetOrderNumberingFirst( bOrderNumberingFirst );
aDlg.execute();
bCopyAttributes = aDlg.IsApplyBorderAndShadow();
sCharacterStyle = aDlg.GetCharacterStyle();
//#i61007# order of captions
if( bOrderNumberingFirst != aDlg.IsOrderNumberingFirst() )
{
bOrderNumberingFirst = aDlg.IsOrderNumberingFirst();
SW_MOD()->GetModuleConfig()->SetCaptionOrderNumberingFirst(bOrderNumberingFirst);
ApplyCaptionOrder();
}
DrawSample();
}
IMPL_LINK_NOARG(SwCaptionDialog, SelectListBoxHdl, ListBox&, void)
{
DrawSample();
}
IMPL_LINK_NOARG(SwCaptionDialog, SelectHdl, ComboBox&, void)
{
DrawSample();
}
IMPL_LINK_NOARG(SwCaptionDialog, ModifyHdl, Edit&, void)
{
SwWrtShell &rSh = rView.GetWrtShell();
OUString sFieldTypeName = m_pCategoryBox->GetText();
bool bCorrectFieldName = !sFieldTypeName.isEmpty();
bool bNone = sFieldTypeName == m_sNone;
SwFieldType* pType = (bCorrectFieldName && !bNone)
? rSh.GetFieldType( SwFieldIds::SetExp, sFieldTypeName )
: nullptr;
m_pOKButton->Enable( bCorrectFieldName &&
(!pType ||
static_cast<SwSetExpFieldType*>(pType)->GetType() == nsSwGetSetExpType::GSE_SEQ) );
m_pOptionButton->Enable( m_pOKButton->IsEnabled() && !bNone );
m_pNumberingSeparatorFT->Enable( bOrderNumberingFirst && !bNone );
m_pNumberingSeparatorED->Enable( bOrderNumberingFirst && !bNone );
m_pFormatText->Enable( !bNone );
m_pFormatBox->Enable( !bNone );
m_pSepText->Enable( !bNone );
m_pSepEdit->Enable( !bNone );
DrawSample();
}
IMPL_LINK_NOARG(SwCaptionDialog, CaptionHdl, Button*, void)
{
SfxItemSet aSet( rView.GetDocShell()->GetDoc()->GetAttrPool() );
ScopedVclPtrInstance< SwCaptionOptDlg > aDlg( this, aSet );
aDlg->Execute();
}
void SwCaptionDialog::DrawSample()
{
OUString aStr;
OUString sCaption = m_pTextEdit->GetText();
// number
OUString sFieldTypeName = m_pCategoryBox->GetText();
bool bNone = sFieldTypeName == m_sNone;
if( !bNone )
{
const sal_uInt16 nNumFormat = static_cast<sal_uInt16>(reinterpret_cast<sal_uIntPtr>(m_pFormatBox->GetSelectedEntryData()));
if( SVX_NUM_NUMBER_NONE != nNumFormat )
{
// category
//#i61007# order of captions
if( !bOrderNumberingFirst )
{
aStr = sFieldTypeName;
if ( !aStr.isEmpty() )
aStr += " ";
}
SwWrtShell &rSh = rView.GetWrtShell();
SwSetExpFieldType* pFieldType = static_cast<SwSetExpFieldType*>(rSh.GetFieldType(
SwFieldIds::SetExp, sFieldTypeName ));
if( pFieldType && pFieldType->GetOutlineLvl() < MAXLEVEL )
{
SwNumberTree::tNumberVector aNumVector;
aNumVector.insert(aNumVector.end(), pFieldType->GetOutlineLvl() + 1, 1);
OUString sNumber( rSh.GetOutlineNumRule()->
MakeNumString(aNumVector, false ));
if( !sNumber.isEmpty() )
aStr += sNumber + pFieldType->GetDelimiter();
}
switch( nNumFormat )
{
case SVX_NUM_CHARS_UPPER_LETTER: aStr += "A"; break;
case SVX_NUM_CHARS_UPPER_LETTER_N: aStr += "A"; break;
case SVX_NUM_CHARS_LOWER_LETTER: aStr += "a"; break;
case SVX_NUM_CHARS_LOWER_LETTER_N: aStr += "a"; break;
case SVX_NUM_ROMAN_UPPER: aStr += "I"; break;
case SVX_NUM_ROMAN_LOWER: aStr += "i"; break;
default: aStr += "1"; break;
}
//#i61007# order of captions
if( bOrderNumberingFirst )
{
aStr += m_pNumberingSeparatorED->GetText() + sFieldTypeName;
}
}
if( !sCaption.isEmpty() )
{
aStr += m_pSepEdit->GetText();
}
}
aStr += sCaption;
// do preview!
m_pPreview->SetPreviewText( aStr );
}
SwCaptionDialog::~SwCaptionDialog()
{
disposeOnce();
}
void SwCaptionDialog::dispose()
{
pMgr.reset();
m_pTextEdit.clear();
m_pCategoryBox.clear();
m_pFormatText.clear();
m_pFormatBox.clear();
m_pNumberingSeparatorFT.clear();
m_pNumberingSeparatorED.clear();
m_pSepText.clear();
m_pSepEdit.clear();
m_pPosText.clear();
m_pPosBox.clear();
m_pOKButton.clear();
m_pAutoCaptionButton.clear();
m_pOptionButton.clear();
m_pPreview.clear();
SvxStandardDialog::dispose();
}
SwSequenceOptionDialog::SwSequenceOptionDialog(weld::Window *pParent, SwView &rV, const OUString& rSeqFieldType )
: GenericDialogController(pParent, "modules/swriter/ui/captionoptions.ui", "CaptionOptionsDialog")
, m_rView(rV)
, m_aFieldTypeName(rSeqFieldType)
, m_xLbLevel(m_xBuilder->weld_combo_box("level"))
, m_xEdDelim(m_xBuilder->weld_entry("separator"))
, m_xLbCharStyle(m_xBuilder->weld_combo_box("style"))
, m_xApplyBorderAndShadowCB(m_xBuilder->weld_check_button("border_and_shadow"))
, m_xLbCaptionOrder(m_xBuilder->weld_combo_box("caption_order"))
{
SwWrtShell &rSh = m_rView.GetWrtShell();
const OUString sNone(SwResId(SW_STR_NONE));
m_xLbLevel->append_text(sNone);
for (sal_uInt16 n = 0; n < MAXLEVEL; ++n)
m_xLbLevel->append_text(OUString::number(n + 1));
SwSetExpFieldType* pFieldType = static_cast<SwSetExpFieldType*>(rSh.GetFieldType(
SwFieldIds::SetExp, m_aFieldTypeName ));
sal_Unicode nLvl = MAXLEVEL;
OUString sDelim(": ");
if( pFieldType )
{
sDelim = pFieldType->GetDelimiter();
nLvl = pFieldType->GetOutlineLvl();
}
m_xLbLevel->set_active(nLvl < MAXLEVEL ? nLvl + 1 : 0);
m_xEdDelim->set_text(sDelim);
m_xLbCharStyle->append_text(sNone);
::FillCharStyleListBox(*m_xLbCharStyle, m_rView.GetDocShell(), true, true);
m_xLbCharStyle->set_active(0);
}
void SwSequenceOptionDialog::Apply()
{
SwWrtShell &rSh = m_rView.GetWrtShell();
SwSetExpFieldType* pFieldType = static_cast<SwSetExpFieldType*>(rSh.GetFieldType(
SwFieldIds::SetExp, m_aFieldTypeName ));
sal_Int8 nLvl = static_cast<sal_Int8>(m_xLbLevel->get_active() - 1);
sal_Unicode cDelim = m_xEdDelim->get_text()[0];
bool bUpdate = true;
if( pFieldType )
{
pFieldType->SetDelimiter( OUString(cDelim) );
pFieldType->SetOutlineLvl( nLvl );
}
else if( !m_aFieldTypeName.isEmpty() && nLvl < MAXLEVEL )
{
// then we have to insert that
SwSetExpFieldType aFieldType( rSh.GetDoc(), m_aFieldTypeName, nsSwGetSetExpType::GSE_SEQ );
aFieldType.SetDelimiter( OUString(cDelim) );
aFieldType.SetOutlineLvl( nLvl );
rSh.InsertFieldType( aFieldType );
}
else
bUpdate = false;
if( bUpdate )
rSh.UpdateExpFields();
}
OUString SwSequenceOptionDialog::GetCharacterStyle() const
{
if (m_xLbCharStyle->get_active() != -1)
return m_xLbCharStyle->get_active_text();
return OUString();
}
void SwSequenceOptionDialog::SetCharacterStyle(const OUString& rStyle)
{
const int nPos = m_xLbCharStyle->find_text(rStyle);
if (nPos == -1)
m_xLbCharStyle->set_active(0);
else
m_xLbCharStyle->set_active(nPos);
}
// #i61007# order of captions
void SwCaptionDialog::ApplyCaptionOrder()
{
m_pNumberingSeparatorFT->Enable(bOrderNumberingFirst);
m_pNumberingSeparatorED->Enable(bOrderNumberingFirst);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|