LibreOffice Module sw (master) 1
chardlg.cxx
Go to the documentation of this file.
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 <memory>
21#include <hintids.hxx>
22
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>
31
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>
42
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>
49#include <sfx2/frame.hxx>
50#include <comphelper/lok.hxx>
51
52#include <svx/svxdlg.hxx>
53#include <svx/flagsdef.hxx>
54#include <svx/dialogs.hrc>
55
56using namespace ::com::sun::star::ui::dialogs;
57using namespace ::com::sun::star::lang;
58using namespace ::com::sun::star::uno;
59using namespace ::sfx2;
60
61SwCharDlg::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)
67{
68 if (pStr)
69 {
70 m_xDialog->set_title(m_xDialog->get_title() + SwResId(STR_TEXTCOLL_HEADER) + *pStr + ")");
71 }
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 );
80
82 {
83 RemoveTabPage("hyperlink");
84 RemoveTabPage("asianlayout");
85 }
86 else
87 {
89 RemoveTabPage("asianlayout");
90 }
91
93 RemoveTabPage("borders");
94}
95
97{
98}
99
100// set FontList
101void SwCharDlg::PageCreated(const OUString& rId, SfxTabPage &rPage)
102{
103 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
104 if (rId == "font")
105 {
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));
110 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
111 rPage.PageCreated(aSet);
112 }
113 else if (rId == "fonteffects")
114 {
115 aSet.Put(
117 rPage.PageCreated(aSet);
118 }
119 else if (rId == "position")
120 {
121 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
122 rPage.PageCreated(aSet);
123 }
124 else if (rId == "asianlayout")
125 {
126 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
127 rPage.PageCreated(aSet);
128 }
129 else if (rId == "background")
130 {
131 SvxBackgroundTabFlags eFlags(SvxBackgroundTabFlags::SHOW_HIGHLIGHTING);
133 eFlags = SvxBackgroundTabFlags::SHOW_CHAR_BKGCOLOR;
134 aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,static_cast<sal_uInt32>(eFlags)));
135 rPage.PageCreated(aSet);
136 }
137}
138
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"))
152{
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);
157
158 const SfxUInt16Item* pItem = rCoreSet.GetItemIfSet(SID_HTML_MODE, false);
159 if (!pItem)
160 {
162 pItem = pShell->GetItem(SID_HTML_MODE);
163 }
164 if (pItem)
165 {
166 sal_uInt16 nHtmlMode = pItem->GetValue();
167 if (HTMLMODE_ON & nHtmlMode)
168 m_xCharStyleContainer->hide();
169 }
170
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));
176
177 if (SwView* pView = GetActiveView())
178 {
179 ::FillCharStyleListBox(*m_xVisitedLB, pView->GetDocShell());
180 ::FillCharStyleListBox(*m_xNotVisitedLB, pView->GetDocShell());
181 }
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();
186
187 TargetList aList;
189
190 m_xTargetFrameLB->freeze();
191 size_t nCount = aList.size();
192 for (size_t i = 0; i < nCount; ++i)
193 {
194 m_xTargetFrameLB->append_text(aList.at(i));
195 }
196 m_xTargetFrameLB->thaw();
197}
198
200{
201}
202
204{
205 if (const SwFormatINetFormat* pINetFormat = rSet->GetItemIfSet(RES_TXTATR_INETFMT, false))
206 {
207 m_xURLED->set_text(INetURLObject::decode(pINetFormat->GetValue(),
209 m_xURLED->save_value();
210 m_xNameED->set_text(pINetFormat->GetName());
211 m_xNameED->save_value();
212
213 OUString sEntry = pINetFormat->GetVisitedFormat();
214 if (sEntry.isEmpty())
215 {
216 OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing visited character format at hyperlink attribute" );
218 }
219 m_xVisitedLB->set_active_text(sEntry);
220
221 sEntry = pINetFormat->GetINetFormat();
222 if (sEntry.isEmpty())
223 {
224 OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing unvisited character format at hyperlink attribute" );
226 }
227 m_xNotVisitedLB->set_active_text(sEntry);
228
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();
234
235 if( pINetFormat->GetMacroTable() )
236 m_oINetMacroTable = *pINetFormat->GetMacroTable();
237 }
238 if (const SfxStringItem* pItem = rSet->GetItemIfSet(FN_PARAM_SELECTION, false))
239 {
240 m_xTextED->set_text(pItem->GetValue());
241 m_xTextFT->set_sensitive(false);
242 m_xTextED->set_sensitive(false);
243 }
244}
245
247{
248 OUString sURL = m_xURLED->get_text();
249 if (!sURL.isEmpty())
250 {
252 // #i100683# file URLs should be normalized in the UI
253 if ( comphelper::isFileUrl(sURL) )
254 sURL = URIHelper::simpleNormalizedMakeRelative(OUString(), sURL);
255 }
256
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;
263
264 // set valid settings first
265 OUString sEntry = m_xVisitedLB->get_active_text();
267 aINetFormat.SetVisitedFormatAndId( sEntry, nId );
268
269 sEntry = m_xNotVisitedLB->get_active_text();
271 aINetFormat.SetINetFormatAndId( sEntry, nId );
272
273 if (m_oINetMacroTable && !m_oINetMacroTable->empty())
274 aINetFormat.SetMacroTable(&*m_oINetMacroTable);
275
276 if (m_xVisitedLB->get_value_changed_from_saved())
277 m_bModified = true;
278
279 if (m_xNotVisitedLB->get_value_changed_from_saved())
280 m_bModified = true;
281
282 if (bNameModified)
283 {
284 m_bModified = true;
286 }
287 if(m_bModified)
288 rSet->Put(aINetFormat);
289 return m_bModified;
290}
291
292std::unique_ptr<SfxTabPage> SwCharURLPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
293{
294 return std::make_unique<SwCharURLPage>(pPage, pController, *rAttrSet);
295}
296
298{
299 FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
300 FileDialogFlags::NONE, GetFrameWeld());
301 aDlgHelper.SetContext(FileDialogHelper::WriterInsertHyperlink);
302 if( aDlgHelper.Execute() == ERRCODE_NONE )
303 {
304 const Reference<XFilePicker3>& xFP = aDlgHelper.GetFilePicker();
305 m_xURLED->set_text(xFP->getSelectedFiles().getConstArray()[0]);
306 }
307}
308
310{
311 if (SwView* pView = GetActiveView())
313 pView->GetWrtShell(), m_oINetMacroTable);
314}
315
316/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
IMPL_LINK_NOARG(SwCharURLPage, InsertFileHdl, weld::Button &, void)
Definition: chardlg.cxx:297
SwCharDlgMode
Definition: chrdlgmodes.hxx:14
sal_uInt16 GetValue() const
static OUString decode(std::u16string_view rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
static SfxAbstractDialogFactory * Create()
virtual CreateTabPage GetTabPageCreatorFunc(sal_uInt16 nId)=0
static void GetDefaultTargetList(TargetList &)
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
void AddTabPage(const OUString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
void RemoveTabPage(const OUString &rName)
SfxItemSet * GetInputSetImpl()
virtual void PageCreated(const SfxAllItemSet &aSet)
const FontList * GetFontList() const
SwView & m_rView
Definition: chrdlg.hxx:31
SwCharDlgMode m_nDialogMode
Definition: chrdlg.hxx:32
SwCharDlg(weld::Window *pParent, SwView &pVw, const SfxItemSet &rCoreSet, SwCharDlgMode nDialogMode, const OUString *pFormatStr)
Definition: chardlg.cxx:61
virtual void PageCreated(const OUString &rId, SfxTabPage &rPage) override
Definition: chardlg.cxx:101
virtual ~SwCharDlg() override
Definition: chardlg.cxx:96
std::unique_ptr< weld::ComboBox > m_xNotVisitedLB
Definition: chrdlg.hxx:56
std::unique_ptr< weld::ComboBox > m_xTargetFrameLB
Definition: chrdlg.hxx:52
virtual ~SwCharURLPage() override
Definition: chardlg.cxx:199
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
Definition: chardlg.cxx:292
SwCharURLPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: chardlg.cxx:139
std::unique_ptr< weld::Entry > m_xURLED
Definition: chrdlg.hxx:48
std::unique_ptr< weld::Label > m_xTextFT
Definition: chrdlg.hxx:49
virtual void Reset(const SfxItemSet *rSet) override
Definition: chardlg.cxx:203
std::unique_ptr< weld::Widget > m_xCharStyleContainer
Definition: chrdlg.hxx:57
std::optional< SvxMacroTableDtor > m_oINetMacroTable
Definition: chrdlg.hxx:45
std::unique_ptr< weld::Entry > m_xTextED
Definition: chrdlg.hxx:50
std::unique_ptr< weld::Button > m_xEventPB
Definition: chrdlg.hxx:54
std::unique_ptr< weld::ComboBox > m_xVisitedLB
Definition: chrdlg.hxx:55
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: chardlg.cxx:246
std::unique_ptr< weld::Entry > m_xNameED
Definition: chrdlg.hxx:51
bool m_bModified
Definition: chrdlg.hxx:46
std::unique_ptr< weld::Button > m_xURLPB
Definition: chrdlg.hxx:53
void SetVisitedFormatAndId(const OUString &rNm, const sal_uInt16 nId)
Definition: fmtinfmt.hxx:112
void SetMacroTable(const SvxMacroTableDtor *pTable)
Set a new MacroTable or clear the current one.
Definition: fmtatr2.cxx:246
void SetINetFormatAndId(const OUString &rNm, const sal_uInt16 nId)
Definition: fmtinfmt.hxx:94
void SetName(const OUString &rNm)
Definition: fmtinfmt.hxx:84
static bool INetFormatDlg(weld::Window *pParent, SwWrtShell &rSh, std::optional< SvxMacroTableDtor > &rpINetItem)
Definition: macassgn.cxx:103
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
Definition: view.hxx:146
SwDocShell * GetDocShell()
Definition: view.cxx:1193
#define FN_PARAM_SELECTION
Definition: cmdid.h:832
int nCount
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
#define ERRCODE_NONE
SvxBackgroundTabFlags
#define SVX_ENABLE_CHAR_TRANSPARENCY
#define SVX_PREVIEW_CHARACTER
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
HTMLMODE_ON
::std::vector< OUString > TargetList
bool IsDoubleLinesEnabled()
SVL_DLLPUBLIC OUString SmartRel2Abs(INetURLObject const &rTheBaseURIRef, OUString const &rTheRelURIRef, Link< OUString *, bool > const &rMaybeFileHdl=Link< OUString *, bool >(), bool bCheckFileExists=true, bool bIgnoreFragment=false, INetURLObject::EncodeMechanism eEncodeMechanism=INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
SVL_DLLPUBLIC OUString simpleNormalizedMakeRelative(OUString const &baseUriReference, OUString const &uriReference)
COMPHELPER_DLLPUBLIC bool isFileUrl(std::u16string_view url)
int i
sal_Int16 nId
@ RES_POOLCHR_INET_VISIT
Internet visited.
Definition: poolfmt.hxx:121
@ RES_POOLCHR_INET_NORMAL
Internet normal.
Definition: poolfmt.hxx:120
static SfxItemSet & rSet
SwView * GetActiveView()
Definition: swmodul1.cxx:115
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
SW_DLLPUBLIC void FillCharStyleListBox(weld::ComboBox &rToFill, SwDocShell *pDocSh, bool bSorted=false, bool bWithDefault=false)
Definition: uitool.cxx:781