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 
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 
31 #include <cmdid.h>
32 #include <swtypes.hxx>
33 #include <view.hxx>
34 #include <wrtsh.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 <globals.hrc>
44 #include <strings.hrc>
45 #include <chrdlgmodes.hxx>
46 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
47 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
48 #include <SwStyleNameMapper.hxx>
49 #include <sfx2/filedlghelper.hxx>
50 #include <sfx2/viewfrm.hxx>
51 
52 #include <svx/svxdlg.hxx>
53 #include <svx/svxids.hrc>
54 #include <svx/flagsdef.hxx>
55 #include <svx/dialogs.hrc>
56 
57 using namespace ::com::sun::star::ui::dialogs;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star::uno;
60 using namespace ::sfx2;
61 
62 SwCharDlg::SwCharDlg(weld::Window* pParent, SwView& rVw, const SfxItemSet& rCoreSet,
63  SwCharDlgMode nDialogMode, const OUString* pStr)
64  : SfxTabDialogController(pParent, "modules/swriter/ui/characterproperties.ui",
65  "CharacterPropertiesDialog", &rCoreSet, pStr != nullptr)
66  , m_rView(rVw)
67  , m_nDialogMode(nDialogMode)
68 {
69  if (pStr)
70  {
71  m_xDialog->set_title(m_xDialog->get_title() + SwResId(STR_TEXTCOLL_HEADER) + *pStr + ")");
72  }
74  AddTabPage("font", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_CHAR_NAME), nullptr);
75  AddTabPage("fonteffects", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_CHAR_EFFECTS), nullptr);
76  AddTabPage("position", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_POSITION ), nullptr );
77  AddTabPage("asianlayout", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_TWOLINES ), nullptr );
78  AddTabPage("hyperlink", SwCharURLPage::Create, nullptr);
79  AddTabPage("background", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BKG ), nullptr );
80  AddTabPage("borders", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BORDER ), nullptr );
81 
83  {
84  RemoveTabPage("hyperlink");
85  RemoveTabPage("background");
86  RemoveTabPage("asianlayout");
87  }
88  else
89  {
90  SvtCJKOptions aCJKOptions;
91  if (!aCJKOptions.IsDoubleLinesEnabled())
92  RemoveTabPage("asianlayout");
93  }
94 
96  RemoveTabPage("borders");
97 }
98 
100 {
101 }
102 
103 // set FontList
104 void SwCharDlg::PageCreated(const OString& rId, SfxTabPage &rPage)
105 {
106  SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
107  if (rId == "font")
108  {
109  SvxFontListItem aFontListItem( *static_cast<const SvxFontListItem*>(
110  ( m_rView.GetDocShell()->GetItem( SID_ATTR_CHAR_FONTLIST ) ) ) );
111  aSet.Put (SvxFontListItem( aFontListItem.GetFontList(), SID_ATTR_CHAR_FONTLIST));
113  aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
114  rPage.PageCreated(aSet);
115  }
116  else if (rId == "fonteffects")
117  {
119  rPage.PageCreated(aSet);
120  }
121  else if (rId == "position")
122  {
123  aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
124  rPage.PageCreated(aSet);
125  }
126  else if (rId == "asianlayout")
127  {
128  aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
129  rPage.PageCreated(aSet);
130  }
131  else if (rId == "background")
132  {
133  aSet.Put(SfxUInt32Item(SID_FLAG_TYPE,static_cast<sal_uInt32>(SvxBackgroundTabFlags::SHOW_HIGHLIGHTING)));
134  rPage.PageCreated(aSet);
135  }
136 }
137 
139  : SfxTabPage(pParent, "modules/swriter/ui/charurlpage.ui", "CharURLPage", &rCoreSet)
140  , bModified(false)
141  , m_xURLED(m_xBuilder->weld_entry("urled"))
142  , m_xTextFT(m_xBuilder->weld_label("textft"))
143  , m_xTextED(m_xBuilder->weld_entry("texted"))
144  , m_xNameED(m_xBuilder->weld_entry("nameed"))
145  , m_xTargetFrameLB(m_xBuilder->weld_combo_box("targetfrmlb"))
146  , m_xURLPB(m_xBuilder->weld_button("urlpb"))
147  , m_xEventPB(m_xBuilder->weld_button("eventpb"))
148  , m_xVisitedLB(m_xBuilder->weld_combo_box("visitedlb"))
149  , m_xNotVisitedLB(m_xBuilder->weld_combo_box("unvisitedlb"))
150  , m_xCharStyleContainer(m_xBuilder->weld_widget("charstyle"))
151 {
152  // tdf#120188 like SfxManageStyleSheetPage limit the width of the style combos
153  const int nMaxWidth(m_xVisitedLB->get_approximate_digit_width() * 50);
154  m_xVisitedLB->set_size_request(nMaxWidth , -1);
155  m_xNotVisitedLB->set_size_request(nMaxWidth , -1);
156 
157  const SfxPoolItem* pItem;
158  SfxObjectShell* pShell;
159  if(SfxItemState::SET == rCoreSet.GetItemState(SID_HTML_MODE, false, &pItem) ||
160  ( nullptr != ( pShell = SfxObjectShell::Current()) &&
161  nullptr != (pItem = pShell->GetItem(SID_HTML_MODE))))
162  {
163  sal_uInt16 nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
164  if (HTMLMODE_ON & nHtmlMode)
165  m_xCharStyleContainer->hide();
166  }
167 
168  m_xURLPB->connect_clicked(LINK( this, SwCharURLPage, InsertFileHdl));
169  m_xEventPB->connect_clicked(LINK( this, SwCharURLPage, EventHdl));
170 
171  SwView *pView = ::GetActiveView();
174  m_xVisitedLB->set_active_id(OUString::number(RES_POOLCHR_INET_VISIT));
175  m_xVisitedLB->save_value();
176  m_xNotVisitedLB->set_active_id(OUString::number(RES_POOLCHR_INET_NORMAL));
177  m_xNotVisitedLB->save_value();
178 
179  std::unique_ptr<TargetList> pList( new TargetList );
181 
182  m_xTargetFrameLB->freeze();
183  size_t nCount = pList->size();
184  for (size_t i = 0; i < nCount; ++i)
185  {
186  m_xTargetFrameLB->append_text(pList->at(i));
187  }
188  m_xTargetFrameLB->thaw();
189 }
190 
192 {
193  disposeOnce();
194 }
195 
197 {
198  pINetItem.reset();
200 }
201 
203 {
204  const SfxPoolItem* pItem;
205  if (SfxItemState::SET == rSet->GetItemState(RES_TXTATR_INETFMT, false, &pItem))
206  {
207  const SwFormatINetFormat* pINetFormat = static_cast<const SwFormatINetFormat*>( pItem);
208  m_xURLED->set_text(INetURLObject::decode(pINetFormat->GetValue(),
210  m_xURLED->save_value();
211  m_xNameED->set_text(pINetFormat->GetName());
212  m_xNameED->save_value();
213 
214  OUString sEntry = pINetFormat->GetVisitedFormat();
215  if (sEntry.isEmpty())
216  {
217  OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing visited character format at hyperlink attribute" );
219  }
220  m_xVisitedLB->set_active_text(sEntry);
221 
222  sEntry = pINetFormat->GetINetFormat();
223  if (sEntry.isEmpty())
224  {
225  OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing unvisited character format at hyperlink attribute" );
227  }
228  m_xNotVisitedLB->set_active_text(sEntry);
229 
230  m_xTargetFrameLB->set_entry_text(pINetFormat->GetTargetFrame());
231  m_xVisitedLB->save_value();
232  m_xNotVisitedLB->save_value();
233  m_xTargetFrameLB->save_value();
235 
236  if( pINetFormat->GetMacroTable() )
237  pINetItem->SetMacroTable(*pINetFormat->GetMacroTable());
238  }
239  if (SfxItemState::SET == rSet->GetItemState(FN_PARAM_SELECTION, false, &pItem))
240  {
241  m_xTextED->set_text(static_cast<const SfxStringItem*>(pItem)->GetValue());
242  m_xTextFT->set_sensitive(false);
243  m_xTextED->set_sensitive(false);
244  }
245 }
246 
248 {
249  OUString sURL = m_xURLED->get_text();
250  if (!sURL.isEmpty())
251  {
253  // #i100683# file URLs should be normalized in the UI
254  if ( comphelper::isFileUrl(sURL) )
255  sURL = URIHelper::simpleNormalizedMakeRelative(OUString(), sURL);
256  }
257 
258  SwFormatINetFormat aINetFormat(sURL, m_xTargetFrameLB->get_active_text());
259  aINetFormat.SetName(m_xNameED->get_text());
260  bool bURLModified = m_xURLED->get_value_changed_from_saved();
261  bool bNameModified = m_xNameED->get_value_changed_from_saved();
262  bool bTargetModified = m_xTargetFrameLB->get_value_changed_from_saved();
263  bModified = bURLModified || bNameModified || bTargetModified;
264 
265  // set valid settings first
266  OUString sEntry = m_xVisitedLB->get_active_text();
268  aINetFormat.SetVisitedFormatAndId( sEntry, nId );
269 
270  sEntry = m_xNotVisitedLB->get_active_text();
272  aINetFormat.SetINetFormatAndId( sEntry, nId );
273 
274  if (pINetItem && !pINetItem->GetMacroTable().empty())
275  aINetFormat.SetMacroTable(&pINetItem->GetMacroTable());
276 
277  if (m_xVisitedLB->get_value_changed_from_saved())
278  bModified = true;
279 
280  if (m_xNotVisitedLB->get_value_changed_from_saved())
281  bModified = true;
282 
283  if (bNameModified)
284  {
285  bModified = true;
286  rSet->Put(SfxStringItem(FN_PARAM_SELECTION, m_xTextED->get_text()));
287  }
288  if(bModified)
289  rSet->Put(aINetFormat);
290  return bModified;
291 }
292 
294 {
295  return VclPtr<SwCharURLPage>::Create(pParent, *rAttrSet);
296 }
297 
299 {
300  FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
301  FileDialogFlags::NONE, GetFrameWeld());
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  bModified |= SwMacroAssignDlg::INetFormatDlg(GetDialogFrameWeld(),
312  ::GetActiveView()->GetWrtShell(), pINetItem);
313 }
314 
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void Reset(const SfxItemSet *rSet) override
Definition: chardlg.cxx:202
#define SVX_ENABLE_FLASH
virtual void PageCreated(const SfxAllItemSet &aSet)
static SfxAbstractDialogFactory * Create()
SwView * GetActiveView()
Definition: swmodul1.cxx:123
static void GetDefaultTargetList(TargetList &)
std::string GetValue
SW_DLLPUBLIC void FillCharStyleListBox(weld::ComboBox &rToFill, SwDocShell *pDocSh, bool bSorted=false, bool bWithDefault=false)
Definition: uitool.cxx:716
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
std::unique_ptr< weld::Button > m_xEventPB
Definition: chrdlg.hxx:53
void RemoveTabPage(const OString &rName)
sal_Int16 nId
SwCharURLPage(TabPageParent pParent, const SfxItemSet &rSet)
Definition: chardlg.cxx:138
SfxItemSet * GetInputSetImpl()
static SfxObjectShell * Current()
std::unique_ptr< weld::ComboBox > m_xNotVisitedLB
Definition: chrdlg.hxx:55
std::unique_ptr< weld::Entry > m_xNameED
Definition: chrdlg.hxx:50
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: chardlg.cxx:247
SVL_DLLPUBLIC OUString simpleNormalizedMakeRelative(OUString const &baseUriReference, OUString const &uriReference)
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
virtual CreateTabPage GetTabPageCreatorFunc(sal_uInt16 nId)=0
virtual ~SwCharDlg() override
Definition: chardlg.cxx:99
#define SVX_PREVIEW_CHARACTER
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
std::unique_ptr< weld::Button > m_xURLPB
Definition: chrdlg.hxx:52
const SvxMacroTableDtor * GetMacroTable() const
Definition: fmtinfmt.hxx:132
virtual void dispose() override
SwCharDlgMode
Definition: chrdlgmodes.hxx:14
const OUString & GetName() const
Definition: fmtinfmt.hxx:80
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Internet visited.
Definition: poolfmt.hxx:122
std::unique_ptr< weld::Entry > m_xTextED
Definition: chrdlg.hxx:49
bool IsDoubleLinesEnabled() const
std::unique_ptr< weld::Entry > m_xURLED
Definition: chrdlg.hxx:47
int i
IMPL_LINK_NOARG(SwCharURLPage, InsertFileHdl, weld::Button &, void)
Definition: chardlg.cxx:298
#define FN_INET_FIELD_MACRO
Definition: cmdid.h:759
HTMLMODE_ON
SwView & m_rView
Definition: chrdlg.hxx:30
Internet normal.
Definition: poolfmt.hxx:121
weld::Window * GetFrameWeld(SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
#define RES_TXTATR_INETFMT
Definition: hintids.hxx:141
SwDocShell * GetDocShell()
Definition: view.cxx:1115
std::unique_ptr< weld::Label > m_xTextFT
Definition: chrdlg.hxx:48
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rAttrSet)
Definition: chardlg.cxx:293
bool bModified
Definition: chrdlg.hxx:45
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const OUString & GetVisitedFormat() const
Definition: fmtinfmt.hxx:120
#define FN_PARAM_SELECTION
Definition: cmdid.h:767
virtual void dispose() override
Definition: chardlg.cxx:196
static bool INetFormatDlg(weld::Window *pParent, SwWrtShell &rSh, std::unique_ptr< SvxMacroItem > &rpINetItem)
Definition: macassgn.cxx:108
#define ERRCODE_NONE
const OUString & GetTargetFrame() const
Definition: fmtinfmt.hxx:89
COMPHELPER_DLLPUBLIC bool isFileUrl(OUString const &url)
static VclPtr< reference_type > Create(Arg &&...arg)
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
virtual void PageCreated(const OString &rId, SfxTabPage &rPage) override
Definition: chardlg.cxx:104
SwCharDlgMode const m_nDialogMode
Definition: chrdlg.hxx:31
virtual ~SwCharURLPage() override
Definition: chardlg.cxx:191
const OUString & GetINetFormat() const
Definition: fmtinfmt.hxx:102
std::unique_ptr< weld::Widget > m_xCharStyleContainer
Definition: chrdlg.hxx:56
std::unique_ptr< weld::ComboBox > m_xTargetFrameLB
Definition: chrdlg.hxx:51
SwCharDlg(weld::Window *pParent, SwView &pVw, const SfxItemSet &rCoreSet, SwCharDlgMode nDialogMode, const OUString *pFormatStr)
Definition: chardlg.cxx:62
std::unique_ptr< SvxMacroItem > pINetItem
Definition: chrdlg.hxx:44
std::unique_ptr< weld::ComboBox > m_xVisitedLB
Definition: chrdlg.hxx:54
::std::vector< OUString > TargetList
void SetName(const OUString &rNm)
Definition: fmtinfmt.hxx:84
Definition: view.hxx:146
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)
static OUString decode(OUString const &rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)