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 <vcl/msgbox.hxx>
25 #include <svl/urihelper.hxx>
26 #include <svl/stritem.hxx>
27 #include <editeng/flstitem.hxx>
28 #include <sfx2/htmlmode.hxx>
29 #include <svl/cjkoptions.hxx>
30 
31 #include <cmdid.h>
32 #include <helpids.h>
33 #include <swtypes.hxx>
34 #include <view.hxx>
35 #include <wrtsh.hxx>
36 #include <docsh.hxx>
37 #include <uitool.hxx>
38 #include <fmtinfmt.hxx>
39 #include <macassgn.hxx>
40 #include <chrdlg.hxx>
41 #include <swmodule.hxx>
42 #include <poolfmt.hxx>
43 
44 #include <globals.hrc>
45 #include <strings.hrc>
46 #include <chrdlgmodes.hxx>
47 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
48 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
49 #include <SwStyleNameMapper.hxx>
50 #include <sfx2/filedlghelper.hxx>
51 #include <sfx2/viewfrm.hxx>
52 
53 #include <svx/svxdlg.hxx>
54 #include <svx/svxids.hrc>
55 #include <svx/flagsdef.hxx>
56 #include <svx/dialogs.hrc>
57 
58 using namespace ::com::sun::star::ui::dialogs;
59 using namespace ::com::sun::star::lang;
60 using namespace ::com::sun::star::uno;
61 using namespace ::sfx2;
62 
63 SwCharDlg::SwCharDlg(vcl::Window* pParent, SwView& rVw, const SfxItemSet& rCoreSet,
64  SwCharDlgMode nDialogMode, const OUString* pStr)
65  : SfxTabDialog(pParent, "CharacterPropertiesDialog",
66  "modules/swriter/ui/characterproperties.ui", &rCoreSet, pStr != nullptr)
67  , m_rView(rVw)
68  , m_nDialogMode(nDialogMode)
69 {
70  if(pStr)
71  {
72  SetText(GetText() + SwResId(STR_TEXTCOLL_HEADER) + *pStr + ")");
73  }
75  OSL_ENSURE(pFact, "Dialog creation failed!");
76  m_nCharStdId = AddTabPage("font", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_CHAR_NAME), nullptr);
77  m_nCharExtId = AddTabPage("fonteffects", pFact->GetTabPageCreatorFunc(RID_SVXPAGE_CHAR_EFFECTS), nullptr);
78  m_nCharPosId = AddTabPage("position", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_POSITION ), nullptr );
79  m_nCharTwoId = AddTabPage("asianlayout", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_CHAR_TWOLINES ), nullptr );
80  m_nCharUrlId = AddTabPage("hyperlink", SwCharURLPage::Create, nullptr);
81  m_nCharBgdId = AddTabPage("background", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BACKGROUND ), nullptr );
82  m_nCharBrdId = AddTabPage("borders", pFact->GetTabPageCreatorFunc( RID_SVXPAGE_BORDER ), nullptr );
83 
84  SvtCJKOptions aCJKOptions;
86  {
87  RemoveTabPage(m_nCharUrlId);
89  RemoveTabPage(m_nCharTwoId);
90  }
91  else if(!aCJKOptions.IsDoubleLinesEnabled())
92  RemoveTabPage(m_nCharTwoId);
93 
95  RemoveTabPage(m_nCharBrdId);
96 }
97 
99 {
100 }
101 
102 // set FontList
103 void SwCharDlg::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
104 {
105  SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
106  if (nId == m_nCharStdId)
107  {
108  SvxFontListItem aFontListItem( *static_cast<const SvxFontListItem*>(
109  ( m_rView.GetDocShell()->GetItem( SID_ATTR_CHAR_FONTLIST ) ) ) );
110  aSet.Put (SvxFontListItem( aFontListItem.GetFontList(), SID_ATTR_CHAR_FONTLIST));
112  aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
113  rPage.PageCreated(aSet);
114  }
115  else if (nId == m_nCharExtId)
116  {
118  rPage.PageCreated(aSet);
119  }
120  else if (nId == m_nCharPosId)
121  {
122  aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
123  rPage.PageCreated(aSet);
124  }
125  else if (nId == m_nCharTwoId)
126  {
127  aSet.Put (SfxUInt32Item(SID_FLAG_TYPE,SVX_PREVIEW_CHARACTER));
128  rPage.PageCreated(aSet);
129  }
130  else if (nId == m_nCharBgdId)
131  {
132  aSet.Put(SfxUInt32Item(SID_FLAG_TYPE,static_cast<sal_uInt32>(SvxBackgroundTabFlags::SHOW_HIGHLIGHTING)));
133  rPage.PageCreated(aSet);
134  }
135 }
136 
138  : SfxTabPage(pParent, "CharURLPage", "modules/swriter/ui/charurlpage.ui", &rCoreSet)
139  , pINetItem(nullptr)
140  , bModified(false)
141 
142 {
143  get(m_pURLED, "urled");
144  get(m_pTextFT, "textft");
145  get(m_pTextED, "texted");
146  get(m_pNameED, "nameed");
147  get(m_pTargetFrameLB, "targetfrmlb");
148  get(m_pURLPB, "urlpb");
149  get(m_pEventPB, "eventpb");
150  get(m_pVisitedLB, "visitedlb");
151  get(m_pNotVisitedLB, "unvisitedlb");
152  get(m_pCharStyleContainer, "charstyle");
153 
154  const SfxPoolItem* pItem;
155  SfxObjectShell* pShell;
156  if(SfxItemState::SET == rCoreSet.GetItemState(SID_HTML_MODE, false, &pItem) ||
157  ( nullptr != ( pShell = SfxObjectShell::Current()) &&
158  nullptr != (pItem = pShell->GetItem(SID_HTML_MODE))))
159  {
160  sal_uInt16 nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
161  if(HTMLMODE_ON & nHtmlMode)
163  }
164 
165  m_pURLPB->SetClickHdl (LINK( this, SwCharURLPage, InsertFileHdl));
166  m_pEventPB->SetClickHdl(LINK( this, SwCharURLPage, EventHdl ));
167 
168  SwView *pView = ::GetActiveView();
175 
176  std::unique_ptr<TargetList> pList( new TargetList );
178  if ( !pList->empty() )
179  {
180  size_t nCount = pList->size();
181 
182  for ( size_t i = 0; i < nCount; i++ )
183  {
184  m_pTargetFrameLB->InsertEntry( pList->at( i ) );
185  }
186  }
187 }
188 
190 {
191  disposeOnce();
192 }
193 
195 {
196  delete pINetItem;
197  m_pURLED.clear();
198  m_pTextFT.clear();
199  m_pTextED.clear();
200  m_pNameED.clear();
202  m_pURLPB.clear();
203  m_pEventPB.clear();
208 }
209 
211 {
212  const SfxPoolItem* pItem;
213  if ( SfxItemState::SET == rSet->GetItemState( RES_TXTATR_INETFMT, false, &pItem ) )
214  {
215  const SwFormatINetFormat* pINetFormat = static_cast<const SwFormatINetFormat*>( pItem);
218  m_pURLED->SaveValue();
219  m_pNameED->SetText(pINetFormat->GetName());
220 
221  OUString sEntry = pINetFormat->GetVisitedFormat();
222  if (sEntry.isEmpty())
223  {
224  OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing visited character format at hyperlink attribute" );
226  }
227  m_pVisitedLB->SelectEntry( sEntry );
228 
229  sEntry = pINetFormat->GetINetFormat();
230  if (sEntry.isEmpty())
231  {
232  OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing unvisited character format at hyperlink attribute" );
234  }
235  m_pNotVisitedLB->SelectEntry(sEntry);
236 
237  m_pTargetFrameLB->SetText(pINetFormat->GetTargetFrame());
238  m_pVisitedLB-> SaveValue();
240  m_pTargetFrameLB-> SaveValue();
242 
243  if( pINetFormat->GetMacroTable() )
244  pINetItem->SetMacroTable( *pINetFormat->GetMacroTable() );
245  }
246  if(SfxItemState::SET == rSet->GetItemState(FN_PARAM_SELECTION, false, &pItem))
247  {
248  m_pTextED->SetText(static_cast<const SfxStringItem*>(pItem)->GetValue());
249  m_pTextFT->Enable( false );
250  m_pTextED->Enable( false );
251  }
252 }
253 
255 {
256  OUString sURL = m_pURLED->GetText();
257  if(!sURL.isEmpty())
258  {
260  // #i100683# file URLs should be normalized in the UI
261  if ( comphelper::isFileUrl(sURL) )
262  sURL = URIHelper::simpleNormalizedMakeRelative(OUString(), sURL);
263  }
264 
265  SwFormatINetFormat aINetFormat(sURL, m_pTargetFrameLB->GetText());
266  aINetFormat.SetName(m_pNameED->GetText());
267  bool bURLModified = m_pURLED->IsValueChangedFromSaved();
268  bool bNameModified = m_pNameED->IsModified();
269  bool bTargetModified = m_pTargetFrameLB->IsValueChangedFromSaved();
270  bModified = bURLModified || bNameModified || bTargetModified;
271 
272  // set valid settings first
273  OUString sEntry = m_pVisitedLB->GetSelectedEntry();
275  aINetFormat.SetVisitedFormatAndId( sEntry, nId );
276 
277  sEntry = m_pNotVisitedLB->GetSelectedEntry();
279  aINetFormat.SetINetFormatAndId( sEntry, nId );
280 
281  if( pINetItem && !pINetItem->GetMacroTable().empty() )
282  aINetFormat.SetMacroTable( &pINetItem->GetMacroTable() );
283 
285  bModified = true;
286 
288  bModified = true;
289 
290  if(m_pTextED->IsModified())
291  {
292  bModified = true;
294  }
295  if(bModified)
296  rSet->Put(aINetFormat);
297  return bModified;
298 }
299 
301  const SfxItemSet* rAttrSet )
302 {
303  return VclPtr<SwCharURLPage>::Create( pParent, *rAttrSet );
304 }
305 
306 IMPL_LINK_NOARG(SwCharURLPage, InsertFileHdl, Button*, void)
307 {
308  FileDialogHelper aDlgHelper(TemplateDescription::FILEOPEN_SIMPLE,
309  FileDialogFlags::NONE, this);
310  if( aDlgHelper.Execute() == ERRCODE_NONE )
311  {
312  Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
313  m_pURLED->SetText(xFP->getSelectedFiles().getConstArray()[0]);
314  }
315 }
316 
318 {
320  ::GetActiveView()->GetWrtShell(), pINetItem );
321 }
322 
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
VclPtr< Edit > m_pURLED
Definition: chrdlg.hxx:58
OUString GetSelectedEntry(sal_Int32 nSelIndex=0) const
VclPtr< PushButton > m_pURLPB
Definition: chrdlg.hxx:63
sal_uInt16 m_nCharBgdId
Definition: chrdlg.hxx:44
virtual void Reset(const SfxItemSet *rSet) override
Definition: chardlg.cxx:210
#define SVX_ENABLE_FLASH
virtual void PageCreated(const SfxAllItemSet &aSet)
static SfxAbstractDialogFactory * Create()
SwView * GetActiveView()
Definition: swmodul1.cxx:123
void SetClickHdl(const Link< Button *, void > &rLink)
static void GetDefaultTargetList(TargetList &)
std::string GetValue
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
pEdit SetText(aStr)
void SaveValue()
IMPL_LINK_NOARG(SwCharURLPage, InsertFileHdl, Button *, void)
Definition: chardlg.cxx:306
void SaveValue()
sal_Int16 nId
static SfxObjectShell * Current()
sal_uInt16 m_nCharStdId
Definition: chrdlg.hxx:39
SW_DLLPUBLIC void FillCharStyleListBox(ListBox &rToFill, SwDocShell *pDocSh, bool bSorted=false, bool bWithDefault=false)
Definition: uitool.cxx:718
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: chardlg.cxx:254
SwCharURLPage(vcl::Window *pParent, const SfxItemSet &rSet)
Definition: chardlg.cxx:137
virtual bool IsModified() const
SVL_DLLPUBLIC OUString simpleNormalizedMakeRelative(OUString const &baseUriReference, OUString const &uriReference)
HTMLMODE_ON
void SelectEntry(const OUString &rStr, bool bSelect=true)
const OUString & GetValue() const
Definition: fmtinfmt.hxx:72
virtual const SfxPoolItem * Put(const SfxPoolItem &, sal_uInt16 nWhich) override
void Enable(bool bEnable=true, bool bChild=true)
virtual CreateTabPage GetTabPageCreatorFunc(sal_uInt16 nId)=0
virtual ~SwCharDlg() override
Definition: chardlg.cxx:98
static bool INetFormatDlg(vcl::Window *pParent, SwWrtShell &rSh, SvxMacroItem *&rpINetItem)
Definition: macassgn.cxx:108
VclPtr< ComboBox > m_pTargetFrameLB
Definition: chrdlg.hxx:62
#define SVX_PREVIEW_CHARACTER
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
const SvxMacroTableDtor * GetMacroTable() const
Definition: fmtinfmt.hxx:129
virtual void dispose() override
SwCharDlgMode
Definition: chrdlgmodes.hxx:14
bool IsValueChangedFromSaved() const
const SfxPoolItem * Put(const SfxPoolItem &rItem)
VclPtr< ListBox > m_pNotVisitedLB
Definition: chrdlg.hxx:66
const OUString & GetName() const
Definition: fmtinfmt.hxx:77
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
bool empty() const
VclPtr< PushButton > m_pEventPB
Definition: chrdlg.hxx:64
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Internet visited.
Definition: poolfmt.hxx:123
VclPtr< VclContainer > m_pCharStyleContainer
Definition: chrdlg.hxx:68
void SelectEntryPos(sal_Int32 nPos, bool bSelect=true)
static SAL_WARN_UNUSED_RESULT VclPtr< reference_type > Create(Arg &&...arg)
SwCharDlgMode m_nDialogMode
Definition: chrdlg.hxx:37
int i
#define FN_INET_FIELD_MACRO
Definition: cmdid.h:748
SwView & m_rView
Definition: chrdlg.hxx:36
virtual OUString GetText() const override
sal_uInt16 m_nCharTwoId
Definition: chrdlg.hxx:42
Internet normal.
Definition: poolfmt.hxx:122
VclPtr< Edit > m_pNameED
Definition: chrdlg.hxx:61
sal_uInt16 m_nCharUrlId
Definition: chrdlg.hxx:43
OUString SwResId(const char *pId)
Definition: swmodule.cxx:198
VclPtr< Edit > m_pTextED
Definition: chrdlg.hxx:60
SfxItemSet * GetInputSetImpl()
bool bModified
VclPtr< ListBox > m_pVisitedLB
Definition: chrdlg.hxx:65
SwDocShell * GetDocShell()
Definition: view.cxx:1065
bool bModified
Definition: chrdlg.hxx:71
sal_Int32 GetEntryPos(const OUString &rStr) const
const SvxMacroTableDtor & GetMacroTable() const
const OUString & GetVisitedFormat() const
Definition: fmtinfmt.hxx:117
#define FN_PARAM_SELECTION
Definition: cmdid.h:756
sal_uInt16 m_nCharPosId
Definition: chrdlg.hxx:41
virtual void dispose() override
Definition: chardlg.cxx:194
#define ERRCODE_NONE
const OUString & GetTargetFrame() const
Definition: fmtinfmt.hxx:86
COMPHELPER_DLLPUBLIC bool isFileUrl(OUString const &url)
void SetMacroTable(const SvxMacroTableDtor &rTbl)
SwCharDlg(vcl::Window *pParent, SwView &pVw, const SfxItemSet &rCoreSet, SwCharDlgMode nDialogMode, const OUString *pFormatStr)
Definition: chardlg.cxx:63
sal_uInt16 m_nCharBrdId
Definition: chrdlg.hxx:45
VclPtr< FixedText > m_pTextFT
Definition: chrdlg.hxx:59
sal_uInt16 AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
virtual ~SwCharURLPage() override
Definition: chardlg.cxx:189
const OUString & GetINetFormat() const
Definition: fmtinfmt.hxx:99
virtual sal_Int32 InsertEntry(const OUString &rStr, sal_Int32 nPos=COMBOBOX_APPEND)
virtual void SetText(const OUString &rStr) override
static VclPtr< SfxTabPage > Create(vcl::Window *pParent, const SfxItemSet *rAttrSet)
Definition: chardlg.cxx:300
virtual void PageCreated(sal_uInt16 nId, SfxTabPage &rPage) override
Definition: chardlg.cxx:103
virtual void SetText(const OUString &rStr) override
sal_uInt16 m_nCharExtId
Definition: chrdlg.hxx:40
::std::vector< OUString > TargetList
void SetName(const OUString &rNm)
Definition: fmtinfmt.hxx:81
Definition: view.hxx:146
bool IsValueChangedFromSaved() const
SvxMacroItem * pINetItem
Definition: chrdlg.hxx:70
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)
void RemoveTabPage(const OString &rName)
static OUString decode(OUString const &rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)