Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / ui / chrdlg / chardlg.cxx
blobece33852d7bb510f1d9bb9ea876d6a7b1db748cc
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 <memory>
21 #include <hintids.hxx>
23 #include <comphelper/fileurl.hxx>
24 #include <svl/urihelper.hxx>
25 #include <svl/stritem.hxx>
26 #include <editeng/flstitem.hxx>
27 #include <sfx2/htmlmode.hxx>
28 #include <svl/cjkoptions.hxx>
29 #include <svl/macitem.hxx>
30 #include <osl/diagnose.h>
32 #include <cmdid.h>
33 #include <swtypes.hxx>
34 #include <view.hxx>
35 #include <docsh.hxx>
36 #include <uitool.hxx>
37 #include <fmtinfmt.hxx>
38 #include <macassgn.hxx>
39 #include <chrdlg.hxx>
40 #include <swmodule.hxx>
41 #include <poolfmt.hxx>
43 #include <strings.hrc>
44 #include <chrdlgmodes.hxx>
45 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
46 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
47 #include <SwStyleNameMapper.hxx>
48 #include <sfx2/filedlghelper.hxx>
49 #include <sfx2/frame.hxx>
50 #include <comphelper/lok.hxx>
52 #include <svx/svxdlg.hxx>
53 #include <svx/flagsdef.hxx>
54 #include <svx/dialogs.hrc>
56 using namespace ::com::sun::star::ui::dialogs;
57 using namespace ::com::sun::star::lang;
58 using namespace ::com::sun::star::uno;
59 using namespace ::sfx2;
61 SwCharDlg::SwCharDlg(weld::Window* pParent, SwView& rVw, const SfxItemSet& rCoreSet,
62 SwCharDlgMode nDialogMode, const OUString* pStr)
63 : SfxTabDialogController(pParent, "modules/swriter/ui/characterproperties.ui",
64 "CharacterPropertiesDialog", &rCoreSet, pStr != nullptr)
65 , m_rView(rVw)
66 , m_nDialogMode(nDialogMode)
68 if (pStr)
70 m_xDialog->set_title(m_xDialog->get_title() + SwResId(STR_TEXTCOLL_HEADER) + *pStr + ")");
72 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
73 AddTabPage("font", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_CHAR_NAME), nullptr);
74 AddTabPage("fonteffects", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_CHAR_EFFECTS), nullptr);
75 AddTabPage("position", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_POSITION ), nullptr );
76 AddTabPage("asianlayout", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_TWOLINES ), nullptr );
77 AddTabPage("hyperlink", SwCharURLPage::Create, nullptr);
78 AddTabPage("background", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BKG ), nullptr );
79 AddTabPage("borders", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BORDER ), nullptr );
81 if (m_nDialogMode == SwCharDlgMode::Draw || m_nDialogMode == SwCharDlgMode::Ann)
83 RemoveTabPage("hyperlink");
84 RemoveTabPage("asianlayout");
86 else
88 if (!SvtCJKOptions::IsDoubleLinesEnabled())
89 RemoveTabPage("asianlayout");
92 if (m_nDialogMode != SwCharDlgMode::Std)
93 RemoveTabPage("borders");
96 SwCharDlg::~SwCharDlg()
100 // set FontList
101 void SwCharDlg::PageCreated(const OUString& rId, SfxTabPage &rPage)
103 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
104 if (rId == "font")
106 SvxFontListItem aFontListItem( *static_cast<const SvxFontListItem*>(
107 ( m_rView.GetDocShell()->GetItem( SID_ATTR_CHAR_FONTLIST ) ) ) );
108 aSet.Put (SvxFontListItem( aFontListItem.GetFontList(), SID_ATTR_CHAR_FONTLIST));
109 if(m_nDialogMode != SwCharDlgMode::Draw && m_nDialogMode != SwCharDlgMode::Ann)
110 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
111 rPage.PageCreated(aSet);
113 else if (rId == "fonteffects")
115 aSet.Put(
116 SfxUInt32Item(SID_FLAG_TYPE, SVX_PREVIEW_CHARACTER | SVX_ENABLE_CHAR_TRANSPARENCY));
117 rPage.PageCreated(aSet);
119 else if (rId == "position")
121 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
122 rPage.PageCreated(aSet);
124 else if (rId == "asianlayout")
126 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
127 rPage.PageCreated(aSet);
129 else if (rId == "background")
131 SvxBackgroundTabFlags eFlags(SvxBackgroundTabFlags::SHOW_HIGHLIGHTING);
132 if (m_nDialogMode == SwCharDlgMode::Draw || m_nDialogMode == SwCharDlgMode::Ann)
133 eFlags = SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR;
134 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,static_cast<sal_uInt32>(eFlags)));
135 rPage.PageCreated(aSet);
139 SwCharURLPage::SwCharURLPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet)
140 : SfxTabPage(pPage, pController, "modules/swriter/ui/charurlpage.ui", "CharURLPage", &rCoreSet)
141 , m_bModified(false)
142 , m_xURLED(m_xBuilder->weld_entry("urled"))
143 , m_xTextFT(m_xBuilder->weld_label("textft"))
144 , m_xTextED(m_xBuilder->weld_entry("texted"))
145 , m_xNameED(m_xBuilder->weld_entry("nameed"))
146 , m_xTargetFrameLB(m_xBuilder->weld_combo_box("targetfrmlb"))
147 , m_xURLPB(m_xBuilder->weld_button("urlpb"))
148 , m_xEventPB(m_xBuilder->weld_button("eventpb"))
149 , m_xVisitedLB(m_xBuilder->weld_combo_box("visitedlb"))
150 , m_xNotVisitedLB(m_xBuilder->weld_combo_box("unvisitedlb"))
151 , m_xCharStyleContainer(m_xBuilder->weld_widget("charstyle"))
153 // tdf#120188 like SfxManageStyleSheetPage limit the width of the style combos
154 const int nMaxWidth(m_xVisitedLB->get_approximate_digit_width() * 50);
155 m_xVisitedLB->set_size_request(nMaxWidth , -1);
156 m_xNotVisitedLB->set_size_request(nMaxWidth , -1);
158 const SfxUInt16Item* pItem = rCoreSet.GetItemIfSet(SID_HTML_MODE, false);
159 if (!pItem)
161 if (SfxObjectShell* pShell = SfxObjectShell::Current())
162 pItem = pShell->GetItem(SID_HTML_MODE);
164 if (pItem)
166 sal_uInt16 nHtmlMode = pItem->GetValue();
167 if (HTMLMODE_ON & nHtmlMode)
168 m_xCharStyleContainer->hide();
171 if(comphelper::LibreOfficeKit::isActive())
172 m_xURLPB->hide(); // Hide browse button in online (not supported yet)
173 else
174 m_xURLPB->connect_clicked(LINK( this, SwCharURLPage, InsertFileHdl));
175 m_xEventPB->connect_clicked(LINK( this, SwCharURLPage, EventHdl));
177 if (SwView* pView = GetActiveView())
179 ::FillCharStyleListBox(*m_xVisitedLB, pView->GetDocShell());
180 ::FillCharStyleListBox(*m_xNotVisitedLB, pView->GetDocShell());
182 m_xVisitedLB->set_active_id(OUString::number(RES_POOLCHR_INET_VISIT));
183 m_xVisitedLB->save_value();
184 m_xNotVisitedLB->set_active_id(OUString::number(RES_POOLCHR_INET_NORMAL));
185 m_xNotVisitedLB->save_value();
187 TargetList aList;
188 SfxFrame::GetDefaultTargetList(aList);
190 m_xTargetFrameLB->freeze();
191 size_t nCount = aList.size();
192 for (size_t i = 0; i < nCount; ++i)
194 m_xTargetFrameLB->append_text(aList.at(i));
196 m_xTargetFrameLB->thaw();
199 SwCharURLPage::~SwCharURLPage()
203 void SwCharURLPage::Reset(const SfxItemSet* rSet)
205 if (const SwFormatINetFormat* pINetFormat = rSet->GetItemIfSet(RES_TXTATR_INETFMT, false))
207 m_xURLED->set_text(INetURLObject::decode(pINetFormat->GetValue(),
208 INetURLObject::DecodeMechanism::Unambiguous));
209 m_xURLED->save_value();
210 m_xNameED->set_text(pINetFormat->GetName());
211 m_xNameED->save_value();
213 OUString sEntry = pINetFormat->GetVisitedFormat();
214 if (sEntry.isEmpty())
216 OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing visited character format at hyperlink attribute" );
217 SwStyleNameMapper::FillUIName(RES_POOLCHR_INET_VISIT, sEntry);
219 m_xVisitedLB->set_active_text(sEntry);
221 sEntry = pINetFormat->GetINetFormat();
222 if (sEntry.isEmpty())
224 OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing unvisited character format at hyperlink attribute" );
225 SwStyleNameMapper::FillUIName(RES_POOLCHR_INET_NORMAL, sEntry);
227 m_xNotVisitedLB->set_active_text(sEntry);
229 m_xTargetFrameLB->set_entry_text(pINetFormat->GetTargetFrame());
230 m_xVisitedLB->save_value();
231 m_xNotVisitedLB->save_value();
232 m_xTargetFrameLB->save_value();
233 m_oINetMacroTable.emplace();
235 if( pINetFormat->GetMacroTable() )
236 m_oINetMacroTable = *pINetFormat->GetMacroTable();
238 if (const SfxStringItem* pItem = rSet->GetItemIfSet(FN_PARAM_SELECTION, false))
240 m_xTextED->set_text(pItem->GetValue());
241 m_xTextFT->set_sensitive(false);
242 m_xTextED->set_sensitive(false);
246 bool SwCharURLPage::FillItemSet(SfxItemSet* rSet)
248 OUString sURL = m_xURLED->get_text();
249 if (!sURL.isEmpty())
251 sURL = URIHelper::SmartRel2Abs(INetURLObject(), sURL, Link<OUString *, bool>(), false );
252 // #i100683# file URLs should be normalized in the UI
253 if ( comphelper::isFileUrl(sURL) )
254 sURL = URIHelper::simpleNormalizedMakeRelative(OUString(), sURL);
257 SwFormatINetFormat aINetFormat(sURL, m_xTargetFrameLB->get_active_text());
258 aINetFormat.SetName(m_xNameED->get_text());
259 bool bURLModified = m_xURLED->get_value_changed_from_saved();
260 bool bNameModified = m_xNameED->get_value_changed_from_saved();
261 bool bTargetModified = m_xTargetFrameLB->get_value_changed_from_saved();
262 m_bModified = bURLModified || bNameModified || bTargetModified;
264 // set valid settings first
265 OUString sEntry = m_xVisitedLB->get_active_text();
266 sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( sEntry, SwGetPoolIdFromName::ChrFmt);
267 aINetFormat.SetVisitedFormatAndId( sEntry, nId );
269 sEntry = m_xNotVisitedLB->get_active_text();
270 nId = SwStyleNameMapper::GetPoolIdFromUIName( sEntry, SwGetPoolIdFromName::ChrFmt);
271 aINetFormat.SetINetFormatAndId( sEntry, nId );
273 if (m_oINetMacroTable && !m_oINetMacroTable->empty())
274 aINetFormat.SetMacroTable(&*m_oINetMacroTable);
276 if (m_xVisitedLB->get_value_changed_from_saved())
277 m_bModified = true;
279 if (m_xNotVisitedLB->get_value_changed_from_saved())
280 m_bModified = true;
282 if (bNameModified)
284 m_bModified = true;
285 rSet->Put(SfxStringItem(FN_PARAM_SELECTION, m_xTextED->get_text()));
287 if(m_bModified)
288 rSet->Put(aINetFormat);
289 return m_bModified;
292 std::unique_ptr<SfxTabPage> SwCharURLPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
294 return std::make_unique<SwCharURLPage>(pPage, pController, *rAttrSet);
297 IMPL_LINK_NOARG(SwCharURLPage, InsertFileHdl, weld::Button&, void)
299 FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
300 FileDialogFlags::NONE, GetFrameWeld());
301 aDlgHelper.SetContext(FileDialogHelper::WriterInsertHyperlink);
302 if( aDlgHelper.Execute() == ERRCODE_NONE )
304 const Reference<XFilePicker3>& xFP = aDlgHelper.GetFilePicker();
305 m_xURLED->set_text(xFP->getSelectedFiles().getConstArray()[0]);
309 IMPL_LINK_NOARG(SwCharURLPage, EventHdl, weld::Button&, void)
311 if (SwView* pView = GetActiveView())
312 m_bModified |= SwMacroAssignDlg::INetFormatDlg(GetFrameWeld(),
313 pView->GetWrtShell(), m_oINetMacroTable);
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */