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(pPage, pController, "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  pINetItem.reset();
194 }
195 
197 {
198  const SfxPoolItem* pItem;
199  if (SfxItemState::SET == rSet->GetItemState(RES_TXTATR_INETFMT, false, &pItem))
200  {
201  const SwFormatINetFormat* pINetFormat = static_cast<const SwFormatINetFormat*>( pItem);
202  m_xURLED->set_text(INetURLObject::decode(pINetFormat->GetValue(),
204  m_xURLED->save_value();
205  m_xNameED->set_text(pINetFormat->GetName());
206  m_xNameED->save_value();
207 
208  OUString sEntry = pINetFormat->GetVisitedFormat();
209  if (sEntry.isEmpty())
210  {
211  OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing visited character format at hyperlink attribute" );
213  }
214  m_xVisitedLB->set_active_text(sEntry);
215 
216  sEntry = pINetFormat->GetINetFormat();
217  if (sEntry.isEmpty())
218  {
219  OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing unvisited character format at hyperlink attribute" );
221  }
222  m_xNotVisitedLB->set_active_text(sEntry);
223 
224  m_xTargetFrameLB->set_entry_text(pINetFormat->GetTargetFrame());
225  m_xVisitedLB->save_value();
226  m_xNotVisitedLB->save_value();
227  m_xTargetFrameLB->save_value();
229 
230  if( pINetFormat->GetMacroTable() )
231  pINetItem->SetMacroTable(*pINetFormat->GetMacroTable());
232  }
233  if (SfxItemState::SET == rSet->GetItemState(FN_PARAM_SELECTION, false, &pItem))
234  {
235  m_xTextED->set_text(static_cast<const SfxStringItem*>(pItem)->GetValue());
236  m_xTextFT->set_sensitive(false);
237  m_xTextED->set_sensitive(false);
238  }
239 }
240 
242 {
243  OUString sURL = m_xURLED->get_text();
244  if (!sURL.isEmpty())
245  {
247  // #i100683# file URLs should be normalized in the UI
248  if ( comphelper::isFileUrl(sURL) )
249  sURL = URIHelper::simpleNormalizedMakeRelative(OUString(), sURL);
250  }
251 
252  SwFormatINetFormat aINetFormat(sURL, m_xTargetFrameLB->get_active_text());
253  aINetFormat.SetName(m_xNameED->get_text());
254  bool bURLModified = m_xURLED->get_value_changed_from_saved();
255  bool bNameModified = m_xNameED->get_value_changed_from_saved();
256  bool bTargetModified = m_xTargetFrameLB->get_value_changed_from_saved();
257  bModified = bURLModified || bNameModified || bTargetModified;
258 
259  // set valid settings first
260  OUString sEntry = m_xVisitedLB->get_active_text();
262  aINetFormat.SetVisitedFormatAndId( sEntry, nId );
263 
264  sEntry = m_xNotVisitedLB->get_active_text();
266  aINetFormat.SetINetFormatAndId( sEntry, nId );
267 
268  if (pINetItem && !pINetItem->GetMacroTable().empty())
269  aINetFormat.SetMacroTable(&pINetItem->GetMacroTable());
270 
271  if (m_xVisitedLB->get_value_changed_from_saved())
272  bModified = true;
273 
274  if (m_xNotVisitedLB->get_value_changed_from_saved())
275  bModified = true;
276 
277  if (bNameModified)
278  {
279  bModified = true;
280  rSet->Put(SfxStringItem(FN_PARAM_SELECTION, m_xTextED->get_text()));
281  }
282  if(bModified)
283  rSet->Put(aINetFormat);
284  return bModified;
285 }
286 
287 std::unique_ptr<SfxTabPage> SwCharURLPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
288 {
289  return std::make_unique<SwCharURLPage>(pPage, pController, *rAttrSet);
290 }
291 
293 {
294  FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
295  FileDialogFlags::NONE, GetFrameWeld());
296  if( aDlgHelper.Execute() == ERRCODE_NONE )
297  {
298  const Reference<XFilePicker3>& xFP = aDlgHelper.GetFilePicker();
299  m_xURLED->set_text(xFP->getSelectedFiles().getConstArray()[0]);
300  }
301 }
302 
304 {
306  ::GetActiveView()->GetWrtShell(), pINetItem);
307 }
308 
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void Reset(const SfxItemSet *rSet) override
Definition: chardlg.cxx:196
#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:734
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
Definition: chardlg.cxx:287
std::unique_ptr< weld::Button > m_xEventPB
Definition: chrdlg.hxx:53
void RemoveTabPage(const OString &rName)
sal_Int16 nId
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:241
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
SwCharURLPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: chardlg.cxx:138
const SvxMacroTableDtor * GetMacroTable() const
Definition: fmtinfmt.hxx:132
SwCharDlgMode
Definition: chrdlgmodes.hxx:14
const OUString & GetName() const
Definition: fmtinfmt.hxx:80
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
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:292
#define FN_INET_FIELD_MACRO
Definition: cmdid.h:769
HTMLMODE_ON
SwView & m_rView
Definition: chrdlg.hxx:30
Internet normal.
Definition: poolfmt.hxx:121
OUString SwResId(const char *pId)
Definition: swmodule.cxx:190
#define RES_TXTATR_INETFMT
Definition: hintids.hxx:142
SwDocShell * GetDocShell()
Definition: view.cxx:1127
std::unique_ptr< weld::Label > m_xTextFT
Definition: chrdlg.hxx:48
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:777
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)
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)