android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / config / optload.cxx
blob2c3ef5adbe4e16a275a82b629a79edb97462e46d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <officecfg/Office/Writer.hxx>
21 #include <comphelper/string.hxx>
22 #include <swtypes.hxx>
23 #include <uiitems.hxx>
24 #include <modcfg.hxx>
25 #include <swmodule.hxx>
26 #include <usrpref.hxx>
27 #include <wrtsh.hxx>
28 #include <linkenum.hxx>
29 #include <uitool.hxx>
30 #include <view.hxx>
32 #include <strings.hrc>
33 #include <optload.hrc>
34 #include <cmdid.h>
36 #include <optload.hxx>
37 #include <sfx2/htmlmode.hxx>
38 #include <fldmgr.hxx>
39 #include <poolfmt.hxx>
40 #include <expfld.hxx>
42 #include <svtools/insdlg.hxx>
43 #include <svtools/unitconv.hxx>
44 #include <tools/resary.hxx>
45 #include <vcl/settings.hxx>
47 #include <comphelper/classids.hxx>
48 #include <unotools/configmgr.hxx>
49 #include <SwStyleNameMapper.hxx>
50 #include <numrule.hxx>
52 #include <doc.hxx>
53 #include <svl/cjkoptions.hxx>
55 using namespace ::com::sun::star;
57 #include <svl/eitem.hxx>
59 sal_uInt32 SwFieldUnitTable::Count()
61 return SAL_N_ELEMENTS(STR_ARR_METRIC);
64 OUString SwFieldUnitTable::GetString(sal_uInt32 nPos)
66 if (RESARRAY_INDEX_NOTFOUND != nPos && nPos < Count())
67 return SwResId(STR_ARR_METRIC[nPos].first);
68 return OUString();
71 FieldUnit SwFieldUnitTable::GetValue(sal_uInt32 nPos)
73 if (RESARRAY_INDEX_NOTFOUND != nPos && nPos < Count())
74 return STR_ARR_METRIC[nPos].second;
75 return FieldUnit::NONE;
78 SwLoadOptPage::SwLoadOptPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
79 : SfxTabPage(pPage, pController, "modules/swriter/ui/optgeneralpage.ui", "OptGeneralPage", &rSet)
80 , m_pWrtShell(nullptr)
81 , m_nLastTab(0)
82 , m_nOldLinkMode(MANUAL)
83 , m_xAlwaysRB(m_xBuilder->weld_radio_button("always"))
84 , m_xRequestRB(m_xBuilder->weld_radio_button("onrequest"))
85 , m_xNeverRB(m_xBuilder->weld_radio_button("never"))
86 , m_xAutoUpdateFields(m_xBuilder->weld_check_button("updatefields"))
87 , m_xAutoUpdateCharts(m_xBuilder->weld_check_button("updatecharts"))
88 , m_xMetricLB(m_xBuilder->weld_combo_box("metric"))
89 , m_xTabFT(m_xBuilder->weld_label("tablabel"))
90 , m_xTabMF(m_xBuilder->weld_metric_spin_button("tab", FieldUnit::CM))
91 , m_xUseSquaredPageMode(m_xBuilder->weld_check_button("squaremode"))
92 , m_xUseCharUnit(m_xBuilder->weld_check_button("usecharunit"))
93 , m_xWordCountED(m_xBuilder->weld_entry("wordcount"))
94 , m_xShowStandardizedPageCount(m_xBuilder->weld_check_button("standardizedpageshow"))
95 , m_xStandardizedPageSizeNF(m_xBuilder->weld_spin_button("standardpagesize"))
97 for (sal_uInt32 i = 0; i < SwFieldUnitTable::Count(); ++i)
99 const OUString sMetric = SwFieldUnitTable::GetString(i);
100 FieldUnit eFUnit = SwFieldUnitTable::GetValue(i);
102 switch ( eFUnit )
104 case FieldUnit::MM:
105 case FieldUnit::CM:
106 case FieldUnit::POINT:
107 case FieldUnit::PICA:
108 case FieldUnit::INCH:
110 // use only these metrics
111 m_xMetricLB->append(OUString::number(static_cast<sal_uInt32>(eFUnit)), sMetric);
112 break;
114 default:; //prevent warning
117 m_xMetricLB->connect_changed(LINK(this, SwLoadOptPage, MetricHdl));
119 const SfxUInt16Item* pItem = rSet.GetItemIfSet(SID_HTML_MODE, false);
120 if (pItem && pItem->GetValue() & HTMLMODE_ON)
122 m_xTabFT->hide();
123 m_xTabMF->hide();
126 if(!SvtCJKOptions::IsAsianTypographyEnabled())
128 m_xUseSquaredPageMode->hide();
129 m_xUseCharUnit->hide();
132 m_xShowStandardizedPageCount->connect_toggled(LINK(this, SwLoadOptPage, StandardizedPageCountCheckHdl));
135 SwLoadOptPage::~SwLoadOptPage()
139 std::unique_ptr<SfxTabPage> SwLoadOptPage::Create( weld::Container* pPage, weld::DialogController* pController,
140 const SfxItemSet* rAttrSet )
142 return std::make_unique<SwLoadOptPage>(pPage, pController, *rAttrSet );
145 IMPL_LINK_NOARG(SwLoadOptPage, StandardizedPageCountCheckHdl, weld::Toggleable&, void)
147 m_xStandardizedPageSizeNF->set_sensitive(m_xShowStandardizedPageCount->get_active());
150 bool SwLoadOptPage::FillItemSet( SfxItemSet* rSet )
152 bool bRet = false;
153 SwModule* pMod = SW_MOD();
155 sal_Int32 nNewLinkMode = AUTOMATIC;
156 if (m_xNeverRB->get_active())
157 nNewLinkMode = NEVER;
158 else if (m_xRequestRB->get_active())
159 nNewLinkMode = MANUAL;
161 SwFieldUpdateFlags eFieldFlags = m_xAutoUpdateFields->get_active() ?
162 m_xAutoUpdateCharts->get_active() ? AUTOUPD_FIELD_AND_CHARTS : AUTOUPD_FIELD_ONLY : AUTOUPD_OFF;
164 if (m_xAutoUpdateFields->get_state_changed_from_saved() ||
165 m_xAutoUpdateCharts->get_state_changed_from_saved())
167 pMod->ApplyFieldUpdateFlags(eFieldFlags);
168 if(m_pWrtShell)
170 m_pWrtShell->SetFieldUpdateFlags(eFieldFlags);
171 m_pWrtShell->SetModified();
175 if (nNewLinkMode != m_nOldLinkMode)
177 pMod->ApplyLinkMode(nNewLinkMode);
178 if (m_pWrtShell)
180 m_pWrtShell->SetLinkUpdMode( nNewLinkMode );
181 m_pWrtShell->SetModified();
184 bRet = true;
187 const sal_Int32 nMPos = m_xMetricLB->get_active();
188 if (m_xMetricLB->get_value_changed_from_saved())
190 // Double-Cast for VA3.0
191 const sal_uInt16 nFieldUnit = m_xMetricLB->get_id(nMPos).toUInt32();
192 rSet->Put( SfxUInt16Item( SID_ATTR_METRIC, nFieldUnit ) );
193 bRet = true;
196 if (m_xTabMF->get_visible() && m_xTabMF->get_value_changed_from_saved())
198 rSet->Put(SfxUInt16Item(SID_ATTR_DEFTABSTOP,
199 o3tl::narrowing<sal_uInt16>(m_xTabMF->denormalize(m_xTabMF->get_value(FieldUnit::TWIP)))));
200 bRet = true;
203 bool bIsUseCharUnitFlag = m_xUseCharUnit->get_active();
204 bIsUseCharUnitFlag = bIsUseCharUnitFlag && SvtCJKOptions::IsAsianTypographyEnabled();
205 if( (bIsUseCharUnitFlag ? 1 : 0) != m_xUseCharUnit->get_saved_state())
207 rSet->Put(SfxBoolItem(SID_ATTR_APPLYCHARUNIT, bIsUseCharUnitFlag ));
208 bRet = true;
211 if (m_xWordCountED->get_value_changed_from_saved())
213 std::shared_ptr< comphelper::ConfigurationChanges > batch(
214 comphelper::ConfigurationChanges::create());
215 officecfg::Office::Writer::WordCount::AdditionalSeparators::set(m_xWordCountED->get_text(), batch);
216 batch->commit();
217 bRet = true;
220 if (m_xShowStandardizedPageCount->get_state_changed_from_saved())
222 std::shared_ptr< comphelper::ConfigurationChanges > batch(
223 comphelper::ConfigurationChanges::create());
224 officecfg::Office::Writer::WordCount::ShowStandardizedPageCount::set(
225 m_xShowStandardizedPageCount->get_active(),
226 batch);
227 batch->commit();
228 bRet = true;
231 if (m_xStandardizedPageSizeNF->get_value_changed_from_saved())
233 std::shared_ptr< comphelper::ConfigurationChanges > batch(
234 comphelper::ConfigurationChanges::create());
235 officecfg::Office::Writer::WordCount::StandardizedPageSize::set(
236 m_xStandardizedPageSizeNF->get_value(),
237 batch);
238 batch->commit();
239 bRet = true;
242 if (m_xUseSquaredPageMode->get_state_changed_from_saved())
244 bool bIsSquaredPageModeFlag = m_xUseSquaredPageMode->get_active();
245 pMod->ApplyDefaultPageMode( bIsSquaredPageModeFlag );
246 if ( m_pWrtShell )
248 SwDoc* pDoc = m_pWrtShell->GetDoc();
249 pDoc->SetDefaultPageMode( bIsSquaredPageModeFlag );
250 m_pWrtShell->SetModified();
252 bRet = true;
255 return bRet;
258 void SwLoadOptPage::Reset( const SfxItemSet* rSet)
260 const SwMasterUsrPref* pUsrPref = SW_MOD()->GetUsrPref(false);
261 const SwPtrItem* pShellItem = rSet->GetItemIfSet(FN_PARAM_WRTSHELL, false);
263 if(pShellItem)
264 m_pWrtShell = static_cast<SwWrtShell*>(pShellItem->GetValue());
266 SwFieldUpdateFlags eFieldFlags = AUTOUPD_GLOBALSETTING;
267 m_nOldLinkMode = GLOBALSETTING;
268 if (m_pWrtShell)
270 eFieldFlags = m_pWrtShell->GetFieldUpdateFlags();
271 m_nOldLinkMode = m_pWrtShell->GetLinkUpdMode();
273 if(GLOBALSETTING == m_nOldLinkMode)
274 m_nOldLinkMode = pUsrPref->GetUpdateLinkMode();
275 if(AUTOUPD_GLOBALSETTING == eFieldFlags)
276 eFieldFlags = pUsrPref->GetFieldUpdateFlags();
278 m_xAutoUpdateFields->set_active(eFieldFlags != AUTOUPD_OFF);
279 m_xAutoUpdateCharts->set_active(eFieldFlags == AUTOUPD_FIELD_AND_CHARTS);
281 switch (m_nOldLinkMode)
283 case NEVER: m_xNeverRB->set_active(true); break;
284 case MANUAL: m_xRequestRB->set_active(true); break;
285 case AUTOMATIC: m_xAlwaysRB->set_active(true); break;
288 m_xAutoUpdateFields->save_state();
289 m_xAutoUpdateCharts->save_state();
290 m_xMetricLB->set_active(-1);
291 if ( rSet->GetItemState( SID_ATTR_METRIC ) >= SfxItemState::DEFAULT )
293 const SfxUInt16Item& rItem = rSet->Get( SID_ATTR_METRIC );
294 FieldUnit eFieldUnit = static_cast<FieldUnit>(rItem.GetValue());
296 for (sal_Int32 i = 0, nEntryCount = m_xMetricLB->get_count(); i < nEntryCount; ++i)
298 if (m_xMetricLB->get_id(i).toUInt32() == static_cast<sal_uInt32>(eFieldUnit))
300 m_xMetricLB->set_active(i);
301 break;
304 ::SetFieldUnit(*m_xTabMF, eFieldUnit);
306 m_xMetricLB->save_value();
307 if(const SfxUInt16Item* pItem = rSet->GetItemIfSet(SID_ATTR_DEFTABSTOP, false))
309 m_nLastTab = pItem->GetValue();
310 m_xTabMF->set_value(m_xTabMF->normalize(m_nLastTab), FieldUnit::TWIP);
312 m_xTabMF->save_value();
314 //default page mode loading
315 if(m_pWrtShell)
317 bool bSquaredPageMode = m_pWrtShell->GetDoc()->IsSquaredPageMode();
318 m_xUseSquaredPageMode->set_active( bSquaredPageMode );
319 m_xUseSquaredPageMode->save_state();
322 if(const SfxBoolItem* pItem = rSet->GetItemIfSet(SID_ATTR_APPLYCHARUNIT, false))
324 bool bUseCharUnit = pItem->GetValue();
325 m_xUseCharUnit->set_active(bUseCharUnit);
327 else
329 m_xUseCharUnit->set_active(pUsrPref->IsApplyCharUnit());
331 m_xUseCharUnit->save_state();
333 m_xWordCountED->set_text(officecfg::Office::Writer::WordCount::AdditionalSeparators::get());
334 m_xWordCountED->set_sensitive(!officecfg::Office::Writer::WordCount::AdditionalSeparators::isReadOnly());
335 m_xWordCountED->save_value();
336 m_xShowStandardizedPageCount->set_active(officecfg::Office::Writer::WordCount::ShowStandardizedPageCount::get());
337 m_xShowStandardizedPageCount->set_sensitive(!officecfg::Office::Writer::WordCount::ShowStandardizedPageCount::isReadOnly());
338 m_xShowStandardizedPageCount->save_state();
339 m_xStandardizedPageSizeNF->set_value(officecfg::Office::Writer::WordCount::StandardizedPageSize::get());
340 m_xStandardizedPageSizeNF->set_sensitive(!officecfg::Office::Writer::WordCount::StandardizedPageSize::isReadOnly());
341 m_xStandardizedPageSizeNF->save_value();
342 m_xStandardizedPageSizeNF->set_sensitive(m_xShowStandardizedPageCount->get_active());
345 IMPL_LINK_NOARG(SwLoadOptPage, MetricHdl, weld::ComboBox&, void)
347 const sal_Int32 nMPos = m_xMetricLB->get_active();
348 if(nMPos == -1)
349 return;
351 // Double-Cast for VA3.0
352 FieldUnit eFieldUnit = static_cast<FieldUnit>(m_xMetricLB->get_id(nMPos).toUInt32());
353 bool bModified = m_xTabMF->get_value_changed_from_saved();
354 tools::Long nVal = bModified ?
355 sal::static_int_cast<sal_Int32, sal_Int64 >( m_xTabMF->denormalize( m_xTabMF->get_value( FieldUnit::TWIP ) )) :
356 m_nLastTab;
357 ::SetFieldUnit( *m_xTabMF, eFieldUnit );
358 m_xTabMF->set_value( m_xTabMF->normalize( nVal ), FieldUnit::TWIP );
359 if (!bModified)
360 m_xTabMF->save_value();
363 SwCaptionOptDlg::SwCaptionOptDlg(weld::Window* pParent, const SfxItemSet& rSet)
364 : SfxSingleTabDialogController(pParent, &rSet, "modules/swriter/ui/captiondialog.ui",
365 "CaptionDialog")
367 // create TabPage
368 SetTabPage(SwCaptionOptPage::Create(get_content_area(), this, &rSet));
371 SwCaptionPreview::SwCaptionPreview()
372 : mbFontInitialized(false)
376 void SwCaptionPreview::ApplySettings(vcl::RenderContext& rRenderContext)
378 const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
379 Wallpaper aBack(rSettings.GetWindowColor());
380 rRenderContext.SetBackground(aBack);
381 rRenderContext.SetFillColor(aBack.GetColor());
382 rRenderContext.SetLineColor(aBack.GetColor());
383 rRenderContext.SetTextColor(rSettings.GetWindowTextColor());
385 if (!mbFontInitialized)
387 maFont = rRenderContext.GetFont();
388 maFont.SetFontHeight(maFont.GetFontHeight() * 120 / 100);
389 mbFontInitialized = true;
391 rRenderContext.SetFont(maFont);
394 void SwCaptionPreview::SetPreviewText(const OUString& rText)
396 if (rText != maText)
398 maText = rText;
399 Invalidate();
403 void SwCaptionPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
405 CustomWidgetController::SetDrawingArea(pDrawingArea);
406 Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(106 , 20), MapMode(MapUnit::MapAppFont)));
407 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
410 void SwCaptionPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
412 ApplySettings(rRenderContext);
414 rRenderContext.DrawRect(tools::Rectangle(Point(0, 0), GetOutputSizePixel()));
415 rRenderContext.DrawText(Point(4, 6), maText);
418 IMPL_LINK(SwCaptionOptPage, TextFilterHdl, OUString&, rTest, bool)
420 rTest = m_aTextFilter.filter(rTest);
421 return true;
424 SwCaptionOptPage::SwCaptionOptPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
425 : SfxTabPage(pPage, pController, "modules/swriter/ui/optcaptionpage.ui", "OptCaptionPage", &rSet)
426 , m_sSWTable(SwResId(STR_CAPTION_TABLE))
427 , m_sSWFrame(SwResId(STR_CAPTION_FRAME))
428 , m_sSWGraphic(SwResId(STR_CAPTION_GRAPHIC))
429 , m_sOLE(SwResId(STR_CAPTION_OLE))
430 , m_sBegin(SwResId(STR_CAPTION_BEGINNING))
431 , m_sEnd(SwResId(STR_CAPTION_END))
432 , m_sAbove(SwResId(STR_CAPTION_ABOVE))
433 , m_sBelow(SwResId(STR_CAPTION_BELOW))
434 , m_sNone(SwResId(SW_STR_NONE))
435 , m_nPrevSelectedEntry(-1)
436 , m_pMgr(new SwFieldMgr)
437 , m_bHTMLMode(false)
438 , m_aTextFilter(m_sNone)
439 , m_xCheckLB(m_xBuilder->weld_tree_view("objects"))
440 , m_xLbCaptionOrder(m_xBuilder->weld_combo_box("captionorder"))
441 , m_xSettingsGroup(m_xBuilder->weld_widget("settings"))
442 , m_xCategoryBox(m_xBuilder->weld_combo_box("category"))
443 , m_xFormatText(m_xBuilder->weld_label("numberingft"))
444 , m_xFormatBox(m_xBuilder->weld_combo_box("numbering"))
445 , m_xNumberingSeparatorFT(m_xBuilder->weld_label("numseparatorft"))
446 , m_xNumberingSeparatorED(m_xBuilder->weld_entry("numseparator"))
447 , m_xTextText(m_xBuilder->weld_label("separatorft"))
448 , m_xTextEdit(m_xBuilder->weld_entry("separator"))
449 , m_xPosBox(m_xBuilder->weld_combo_box("position"))
450 , m_xNumCapt(m_xBuilder->weld_widget("numcaption"))
451 , m_xLbLevel(m_xBuilder->weld_combo_box("level"))
452 , m_xEdDelim(m_xBuilder->weld_entry("chapseparator"))
453 , m_xCategory(m_xBuilder->weld_widget("categoryformat"))
454 , m_xCharStyleLB(m_xBuilder->weld_combo_box("charstyle"))
455 , m_xApplyBorderCB(m_xBuilder->weld_check_button("applyborder"))
456 , m_xPreview(new weld::CustomWeld(*m_xBuilder, "preview", m_aPreview))
458 m_xCategoryBox->connect_entry_insert_text(LINK(this, SwCaptionOptPage, TextFilterHdl));
460 m_xCheckLB->enable_toggle_buttons(weld::ColumnToggleType::Check);
462 SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_ABB, m_sIllustration);
463 SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_TABLE, m_sTable);
464 SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_FRAME, m_sText);
465 SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_DRAWING, m_sDrawing);
468 // m_xFormatBox
469 sal_uInt16 nSelFormat = SVX_NUM_ARABIC;
470 SwWrtShell* pSh = ::GetActiveWrtShell();
472 if (pSh)
474 for ( auto i = m_pMgr->GetFieldTypeCount(); i; )
476 SwFieldType* pFieldType = m_pMgr->GetFieldType(SwFieldIds::Unknown, --i);
477 if (!pFieldType->GetName().isEmpty()
478 && pFieldType->GetName() == m_xCategoryBox->get_active_text())
480 nSelFormat = o3tl::narrowing<sal_uInt16>(static_cast<SwSetExpFieldType*>(pFieldType)->GetSeqFormat());
481 break;
485 ::FillCharStyleListBox( *m_xCharStyleLB, pSh->GetView().GetDocShell(), true, true );
488 const sal_uInt16 nCount = m_pMgr->GetFormatCount(SwFieldTypesEnum::Sequence, false);
489 for ( sal_uInt16 i = 0; i < nCount; ++i )
491 const sal_uInt16 nFormatId = m_pMgr->GetFormatId(SwFieldTypesEnum::Sequence, i);
492 m_xFormatBox->append(OUString::number(nFormatId), m_pMgr->GetFormatStr(SwFieldTypesEnum::Sequence, i));
493 if (nFormatId == nSelFormat)
494 m_xFormatBox->set_active(i);
497 for (int i = 0; i < MAXLEVEL; ++i)
498 m_xLbLevel->append_text(OUString::number(i + 1));
500 sal_Unicode nLvl = MAXLEVEL;
501 OUString sDelim(": ");
503 if (pSh)
505 SwSetExpFieldType* pFieldType = static_cast<SwSetExpFieldType*>(m_pMgr->GetFieldType(
506 SwFieldIds::SetExp, m_xCategoryBox->get_active_text() ));
507 if( pFieldType )
509 sDelim = pFieldType->GetDelimiter();
510 nLvl = pFieldType->GetOutlineLvl();
514 m_xLbLevel->set_active(nLvl < MAXLEVEL ? nLvl + 1 : 0);
515 m_xEdDelim->set_text(sDelim);
517 m_xCategoryBox->connect_changed(LINK(this, SwCaptionOptPage, ModifyComboHdl));
518 Link<weld::Entry&,void> aLk = LINK(this, SwCaptionOptPage, ModifyEntryHdl);
519 m_xNumberingSeparatorED->connect_changed(aLk);
520 m_xTextEdit->connect_changed(aLk);
522 m_xCategoryBox->connect_changed(LINK(this, SwCaptionOptPage, SelectHdl));
523 m_xFormatBox->connect_changed(LINK(this, SwCaptionOptPage, SelectListBoxHdl));
525 m_xLbCaptionOrder->connect_changed(LINK(this, SwCaptionOptPage, OrderHdl));
527 m_xCheckLB->connect_changed(LINK(this, SwCaptionOptPage, ShowEntryHdl));
528 m_xCheckLB->connect_toggled(LINK(this, SwCaptionOptPage, ToggleEntryHdl));
531 SwCaptionOptPage::~SwCaptionOptPage()
533 DelUserData();
534 m_pMgr.reset();
535 m_xPreview.reset();
538 std::unique_ptr<SfxTabPage> SwCaptionOptPage::Create(weld::Container* pPage, weld::DialogController* pController,
539 const SfxItemSet* rAttrSet)
541 return std::make_unique<SwCaptionOptPage>(pPage, pController, *rAttrSet);
544 bool SwCaptionOptPage::FillItemSet( SfxItemSet* )
546 bool bRet = false;
547 SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
549 SaveEntry(m_xCheckLB->get_selected_index()); // apply current entry
551 int nCheckCount = 0;
552 for (int i = 0, nCount = m_xCheckLB->n_children(); i < nCount; ++i)
554 if (m_xCheckLB->get_toggle(i) == TRISTATE_TRUE)
555 ++nCheckCount;
556 InsCaptionOpt* pData = weld::fromId<InsCaptionOpt*>(m_xCheckLB->get_id(i));
557 bRet |= pModOpt->SetCapOption(m_bHTMLMode, pData);
560 pModOpt->SetInsWithCaption(m_bHTMLMode, nCheckCount > 0);
562 int nPos = m_xLbCaptionOrder->get_active();
563 pModOpt->SetCaptionOrderNumberingFirst(nPos == 1);
565 return bRet;
568 void SwCaptionOptPage::Reset( const SfxItemSet* rSet)
570 if(const SfxUInt16Item* pItem = rSet->GetItemIfSet(SID_HTML_MODE, false))
572 m_bHTMLMode = 0 != (pItem->GetValue() & HTMLMODE_ON);
575 DelUserData();
576 m_xCheckLB->clear(); // remove all entries
578 // Writer objects
579 int nPos = 0;
580 m_xCheckLB->append();
581 m_xCheckLB->set_toggle(nPos, TRISTATE_FALSE);
582 m_xCheckLB->set_text(nPos, m_sSWTable, 0);
583 SetOptions(nPos++, TABLE_CAP);
584 m_xCheckLB->append();
585 m_xCheckLB->set_toggle(nPos, TRISTATE_FALSE);
586 m_xCheckLB->set_text(nPos, m_sSWFrame, 0);
587 SetOptions(nPos++, FRAME_CAP);
588 m_xCheckLB->append();
589 m_xCheckLB->set_toggle(nPos, TRISTATE_FALSE);
590 m_xCheckLB->set_text(nPos, m_sSWGraphic, 0);
591 SetOptions(nPos++, GRAPHIC_CAP);
593 // get Productname and -version
594 const OUString sWithoutVersion( utl::ConfigManager::getProductName() );
595 const OUString sComplete(
596 sWithoutVersion + " " +
597 utl::ConfigManager::getProductVersion() );
599 SvObjectServerList aObjS;
600 aObjS.FillInsertObjects();
601 aObjS.Remove( SvGlobalName( SO3_SW_CLASSID ) ); // remove Writer-ID
603 for ( sal_uLong i = 0; i < aObjS.Count(); ++i )
605 const SvGlobalName &rOleId = aObjS[i].GetClassName();
606 OUString sClass;
607 if (rOleId == SvGlobalName(SO3_OUT_CLASSID))
608 sClass = m_sOLE;
609 else
610 sClass = aObjS[i].GetHumanName();
611 // don't show product version
612 sClass = sClass.replaceFirst( sComplete, sWithoutVersion );
613 m_xCheckLB->append();
614 m_xCheckLB->set_toggle(nPos, TRISTATE_FALSE);
615 m_xCheckLB->set_text(nPos, sClass, 0);
616 SetOptions( nPos++, OLE_CAP, &rOleId );
618 m_xLbCaptionOrder->set_active(
619 SW_MOD()->GetModuleConfig()->IsCaptionOrderNumberingFirst() ? 1 : 0);
620 m_xCheckLB->select(0);
621 ShowEntryHdl(*m_xCheckLB);
624 void SwCaptionOptPage::SetOptions(const sal_uLong nPos,
625 const SwCapObjType eObjType, const SvGlobalName *pOleId)
627 SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
628 const InsCaptionOpt* pOpt = pModOpt->GetCapOption(m_bHTMLMode, eObjType, pOleId);
630 if (pOpt)
632 InsCaptionOpt* pIns = new InsCaptionOpt(*pOpt);
633 m_xCheckLB->set_id(nPos, weld::toId(pIns));
634 m_xCheckLB->set_toggle(nPos, pOpt->UseCaption() ? TRISTATE_TRUE : TRISTATE_FALSE);
636 else
638 InsCaptionOpt* pIns = new InsCaptionOpt(eObjType, pOleId);
639 m_xCheckLB->set_id(nPos, weld::toId(pIns));
643 void SwCaptionOptPage::DelUserData()
645 for (int i = 0, nCount = m_xCheckLB->n_children(); i < nCount; ++i)
647 delete weld::fromId<InsCaptionOpt*>(m_xCheckLB->get_id(i));
648 m_xCheckLB->set_id(i, "0");
652 void SwCaptionOptPage::UpdateEntry(int nSelEntry)
654 if (nSelEntry != -1)
656 bool bChecked = m_xCheckLB->get_toggle(nSelEntry) == TRISTATE_TRUE;
658 m_xSettingsGroup->set_sensitive(bChecked);
659 bool bNumSep = bChecked && m_xLbCaptionOrder->get_active() == 1;
660 m_xNumberingSeparatorED->set_sensitive( bNumSep );
661 m_xNumberingSeparatorFT->set_sensitive( bNumSep );
663 m_xNumCapt->set_sensitive(bChecked);
664 m_xCategory->set_sensitive(bChecked);
665 m_xPreview->set_sensitive(bChecked);
668 InsCaptionOpt* pOpt = weld::fromId<InsCaptionOpt*>(m_xCheckLB->get_id(nSelEntry));
670 m_xCategoryBox->clear();
671 m_xCategoryBox->append_text(m_sNone);
672 if (::GetActiveWrtShell())
674 const size_t nCount = m_pMgr->GetFieldTypeCount();
676 for (size_t i = 0; i < nCount; ++i)
678 SwFieldType *pType = m_pMgr->GetFieldType( SwFieldIds::Unknown, i );
679 if( pType->Which() == SwFieldIds::SetExp &&
680 static_cast<SwSetExpFieldType *>( pType)->GetType() & nsSwGetSetExpType::GSE_SEQ )
682 m_xCategoryBox->append_text(pType->GetName());
686 else
688 m_xCategoryBox->append_text(m_sIllustration);
689 m_xCategoryBox->append_text(m_sTable);
690 m_xCategoryBox->append_text(m_sText);
691 m_xCategoryBox->append_text(m_sDrawing);
694 if (!pOpt->GetCategory().isEmpty())
696 if (m_xCategoryBox->find_text(pOpt->GetCategory()) == -1)
697 m_xCategoryBox->insert_text(0, pOpt->GetCategory());
698 m_xCategoryBox->set_active_text(pOpt->GetCategory());
700 else
701 m_xCategoryBox->set_active_text(m_sNone);
703 if (m_xCategoryBox->get_active_text().isEmpty())
705 sal_Int32 nPos = 0;
706 switch(pOpt->GetObjType())
708 case OLE_CAP:
709 case GRAPHIC_CAP: nPos = 1; break;
710 case TABLE_CAP: nPos = 2; break;
711 case FRAME_CAP: nPos = 3; break;
713 m_xCategoryBox->set_active(nPos);
716 for (sal_Int32 i = 0; i < m_xFormatBox->get_count(); i++)
718 if (pOpt->GetNumType() == m_xFormatBox->get_id(i).toUInt32())
720 m_xFormatBox->set_active(i);
721 break;
724 m_xTextEdit->set_text(pOpt->GetCaption());
726 m_xPosBox->clear();
727 switch (pOpt->GetObjType())
729 case GRAPHIC_CAP:
730 case TABLE_CAP:
731 case OLE_CAP:
732 m_xPosBox->append_text(m_sAbove);
733 m_xPosBox->append_text(m_sBelow);
734 break;
735 case FRAME_CAP:
736 m_xPosBox->append_text(m_sBegin);
737 m_xPosBox->append_text(m_sEnd);
738 break;
740 m_xPosBox->set_active(pOpt->GetPos());
742 sal_Int32 nLevelPos = ( pOpt->GetLevel() < MAXLEVEL ) ? pOpt->GetLevel() + 1 : 0;
743 m_xLbLevel->set_active(nLevelPos);
744 m_xEdDelim->set_text(pOpt->GetSeparator());
745 m_xNumberingSeparatorED->set_text(pOpt->GetNumSeparator());
746 if (!pOpt->GetCharacterStyle().isEmpty())
747 m_xCharStyleLB->set_active_text(pOpt->GetCharacterStyle());
748 else
749 m_xCharStyleLB->set_active(0);
750 m_xApplyBorderCB->set_sensitive(m_xCategoryBox->get_sensitive() &&
751 pOpt->GetObjType() != TABLE_CAP && pOpt->GetObjType() != FRAME_CAP );
752 m_xApplyBorderCB->set_active(pOpt->CopyAttributes());
755 ModifyHdl();
758 IMPL_LINK_NOARG(SwCaptionOptPage, ShowEntryHdl, weld::TreeView&, void)
760 if (m_nPrevSelectedEntry != -1)
761 SaveEntry(m_nPrevSelectedEntry);
762 UpdateEntry(m_xCheckLB->get_selected_index());
763 m_nPrevSelectedEntry = m_xCheckLB->get_selected_index();
766 IMPL_LINK(SwCaptionOptPage, ToggleEntryHdl, const weld::TreeView::iter_col&, rRowCol, void)
768 UpdateEntry(m_xCheckLB->get_iter_index_in_parent(rRowCol.first));
771 void SwCaptionOptPage::SaveEntry(int nEntry)
773 if (nEntry == -1)
774 return;
776 InsCaptionOpt* pOpt = weld::fromId<InsCaptionOpt*>(m_xCheckLB->get_id(nEntry));
778 pOpt->UseCaption() = m_xCheckLB->get_toggle(nEntry) == TRISTATE_TRUE;
779 const OUString aName(m_xCategoryBox->get_active_text());
780 if (aName == m_sNone)
781 pOpt->SetCategory("");
782 else
783 pOpt->SetCategory(comphelper::string::strip(aName, ' '));
784 pOpt->SetNumType(m_xFormatBox->get_active_id().toUInt32());
785 pOpt->SetCaption(m_xTextEdit->get_sensitive() ? m_xTextEdit->get_text() : OUString() );
786 pOpt->SetPos(m_xPosBox->get_active());
787 int nPos = m_xLbLevel->get_active();
788 sal_Int32 nLevel = (nPos > 0) ? nPos - 1 : MAXLEVEL;
789 pOpt->SetLevel(nLevel);
790 pOpt->SetSeparator(m_xEdDelim->get_text());
791 pOpt->SetNumSeparator(m_xNumberingSeparatorED->get_text());
792 if (m_xCharStyleLB->get_active() == -1)
793 pOpt->SetCharacterStyle("");
794 else
795 pOpt->SetCharacterStyle(m_xCharStyleLB->get_active_text());
796 pOpt->CopyAttributes() = m_xApplyBorderCB->get_active();
799 void SwCaptionOptPage::ModifyHdl()
801 const OUString sFieldTypeName = m_xCategoryBox->get_active_text();
803 if (SfxSingleTabDialogController* pDlg = dynamic_cast<SfxSingleTabDialogController*>(GetDialogController()))
804 pDlg->GetOKButton().set_sensitive(!sFieldTypeName.isEmpty());
805 bool bEnable = m_xCategoryBox->get_sensitive() && sFieldTypeName != m_sNone;
807 m_xFormatText->set_sensitive(bEnable);
808 m_xFormatBox->set_sensitive(bEnable);
809 m_xTextText->set_sensitive(bEnable);
810 m_xTextEdit->set_sensitive(bEnable);
812 InvalidatePreview();
815 IMPL_LINK_NOARG(SwCaptionOptPage, ModifyEntryHdl, weld::Entry&, void)
817 ModifyHdl();
820 IMPL_LINK_NOARG(SwCaptionOptPage, ModifyComboHdl, weld::ComboBox&, void)
822 ModifyHdl();
825 IMPL_LINK_NOARG(SwCaptionOptPage, SelectHdl, weld::ComboBox&, void)
827 InvalidatePreview();
830 IMPL_LINK_NOARG(SwCaptionOptPage, SelectListBoxHdl, weld::ComboBox&, void)
832 InvalidatePreview();
835 IMPL_LINK(SwCaptionOptPage, OrderHdl, weld::ComboBox&, rBox, void)
837 InvalidatePreview();
839 int nSelEntry = m_xCheckLB->get_selected_index();
840 bool bChecked = false;
841 if (nSelEntry != -1)
843 bChecked = m_xCheckLB->get_toggle(nSelEntry) == TRISTATE_TRUE;
846 int nPos = rBox.get_active();
847 m_xNumberingSeparatorFT->set_sensitive(bChecked && nPos == 1);
848 m_xNumberingSeparatorED->set_sensitive(bChecked && nPos == 1);
851 void SwCaptionOptPage::InvalidatePreview()
853 OUString aStr;
855 if (m_xCategoryBox->get_active_text() != m_sNone)
857 //#i61007# order of captions
858 bool bOrderNumberingFirst = m_xLbCaptionOrder->get_active() == 1;
859 // number
860 const sal_uInt16 nNumFormat = m_xFormatBox->get_active_id().toUInt32();
861 if (SVX_NUM_NUMBER_NONE != nNumFormat)
863 //#i61007# order of captions
864 if( !bOrderNumberingFirst )
866 // category
867 aStr += m_xCategoryBox->get_active_text() + " ";
870 if (SwWrtShell *pSh = ::GetActiveWrtShell())
872 SwSetExpFieldType* pFieldType = static_cast<SwSetExpFieldType*>(m_pMgr->GetFieldType(
873 SwFieldIds::SetExp, m_xCategoryBox->get_active_text() ));
874 if( pFieldType && pFieldType->GetOutlineLvl() < MAXLEVEL )
876 sal_uInt8 nLvl = pFieldType->GetOutlineLvl();
877 SwNumberTree::tNumberVector aNumVector;
878 for( sal_uInt8 i = 0; i <= nLvl; ++i )
879 aNumVector.push_back(1);
881 const OUString sNumber( pSh->GetOutlineNumRule()->MakeNumString(
882 aNumVector, false ));
883 if( !sNumber.isEmpty() )
884 aStr += sNumber + pFieldType->GetDelimiter();
888 switch( nNumFormat )
890 case SVX_NUM_CHARS_UPPER_LETTER: aStr += "A"; break;
891 case SVX_NUM_CHARS_UPPER_LETTER_N: aStr += "A"; break;
892 case SVX_NUM_CHARS_LOWER_LETTER: aStr += "a"; break;
893 case SVX_NUM_CHARS_LOWER_LETTER_N: aStr += "a"; break;
894 case SVX_NUM_ROMAN_UPPER: aStr += "I"; break;
895 case SVX_NUM_ROMAN_LOWER: aStr += "i"; break;
896 //case ARABIC:
897 default: aStr += "1"; break;
900 //#i61007# order of captions
901 if( bOrderNumberingFirst )
903 aStr += m_xNumberingSeparatorED->get_text() + m_xCategoryBox->get_active_text();
905 aStr += m_xTextEdit->get_text();
907 m_aPreview.SetPreviewText(aStr);
910 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */