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 <helpid.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 <chrdlg.hrc>
46 #include <chrdlgmodes.hxx>
47 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
48 #include <com/sun/star/ui/dialogs/XFilePicker2.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 );
177  const SfxFrame& rFrame = pView->GetViewFrame()->GetFrame();
178  rFrame.GetTargetList(*pList);
179  if ( !pList->empty() )
180  {
181  size_t nCount = pList->size();
182 
183  for ( size_t i = 0; i < nCount; i++ )
184  {
185  m_pTargetFrameLB->InsertEntry( pList->at( i ) );
186  }
187  }
188 }
189 
191 {
192  disposeOnce();
193 }
194 
196 {
197  delete pINetItem;
198  m_pURLED.clear();
199  m_pTextFT.clear();
200  m_pTextED.clear();
201  m_pNameED.clear();
203  m_pURLPB.clear();
204  m_pEventPB.clear();
209 }
210 
212 {
213  const SfxPoolItem* pItem;
214  if ( SfxItemState::SET == rSet->GetItemState( RES_TXTATR_INETFMT, false, &pItem ) )
215  {
216  const SwFormatINetFormat* pINetFormat = static_cast<const SwFormatINetFormat*>( pItem);
219  m_pURLED->SaveValue();
220  m_pNameED->SetText(pINetFormat->GetName());
221 
222  OUString sEntry = pINetFormat->GetVisitedFormat();
223  if (sEntry.isEmpty())
224  {
225  OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing visited character format at hyperlink attribute" );
227  }
228  m_pVisitedLB->SelectEntry( sEntry );
229 
230  sEntry = pINetFormat->GetINetFormat();
231  if (sEntry.isEmpty())
232  {
233  OSL_ENSURE( false, "<SwCharURLPage::Reset(..)> - missing unvisited character format at hyperlink attribute" );
235  }
236  m_pNotVisitedLB->SelectEntry(sEntry);
237 
238  m_pTargetFrameLB->SetText(pINetFormat->GetTargetFrame());
239  m_pVisitedLB-> SaveValue();
241  m_pTargetFrameLB-> SaveValue();
243 
244  if( pINetFormat->GetMacroTable() )
245  pINetItem->SetMacroTable( *pINetFormat->GetMacroTable() );
246  }
247  if(SfxItemState::SET == rSet->GetItemState(FN_PARAM_SELECTION, false, &pItem))
248  {
249  m_pTextED->SetText(static_cast<const SfxStringItem*>(pItem)->GetValue());
250  m_pTextFT->Enable( false );
251  m_pTextED->Enable( false );
252  }
253 }
254 
256 {
257  OUString sURL = m_pURLED->GetText();
258  if(!sURL.isEmpty())
259  {
261  // #i100683# file URLs should be normalized in the UI
262  if ( comphelper::isFileUrl(sURL) )
263  sURL = URIHelper::simpleNormalizedMakeRelative(OUString(), sURL);
264  }
265 
266  SwFormatINetFormat aINetFormat(sURL, m_pTargetFrameLB->GetText());
267  aINetFormat.SetName(m_pNameED->GetText());
268  bool bURLModified = m_pURLED->IsValueChangedFromSaved();
269  bool bNameModified = m_pNameED->IsModified();
270  bool bTargetModified = m_pTargetFrameLB->IsValueChangedFromSaved();
271  bModified = bURLModified || bNameModified || bTargetModified;
272 
273  // set valid settings first
274  OUString sEntry = m_pVisitedLB->GetSelectEntry();
276  aINetFormat.SetVisitedFormatAndId( sEntry, nId );
277 
278  sEntry = m_pNotVisitedLB->GetSelectEntry();
280  aINetFormat.SetINetFormatAndId( sEntry, nId );
281 
282  if( pINetItem && !pINetItem->GetMacroTable().empty() )
283  aINetFormat.SetMacroTable( &pINetItem->GetMacroTable() );
284 
286  bModified = true;
287 
289  bModified = true;
290 
291  if(m_pTextED->IsModified())
292  {
293  bModified = true;
295  }
296  if(bModified)
297  rSet->Put(aINetFormat);
298  return bModified;
299 }
300 
302  const SfxItemSet* rAttrSet )
303 {
304  return VclPtr<SwCharURLPage>::Create( pParent, *rAttrSet );
305 }
306 
307 IMPL_LINK_NOARG(SwCharURLPage, InsertFileHdl, Button*, void)
308 {
309  FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE );
310  if( aDlgHelper.Execute() == ERRCODE_NONE )
311  {
312  Reference < XFilePicker2 > 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
SfxViewFrame * GetViewFrame() 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:211
#define SVX_ENABLE_FLASH
virtual void PageCreated(const SfxAllItemSet &aSet)
static SfxAbstractDialogFactory * Create()
SwView * GetActiveView()
Definition: swmodul1.cxx:122
void SetClickHdl(const Link< Button *, void > &rLink)
OUString SwResId(sal_uInt16 nId)
Definition: swtypes.hxx:138
std::string GetValue
pEdit SetText(aStr)
void SaveValue()
IMPL_LINK_NOARG(SwCharURLPage, InsertFileHdl, Button *, void)
Definition: chardlg.cxx:307
void SaveValue()
sal_Int16 nId
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName, bool bDisambiguate)
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:255
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)
void GetTargetList(TargetList &) const
HTMLMODE_ON
void SelectEntry(const OUString &rStr, bool bSelect=true)
const OUString & GetValue() const
Definition: fmtinfmt.hxx:71
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:107
VclPtr< ComboBox > m_pTargetFrameLB
Definition: chrdlg.hxx:62
SfxFrame & GetFrame() const
#define SVX_PREVIEW_CHARACTER
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
const SvxMacroTableDtor * GetMacroTable() const
Definition: fmtinfmt.hxx:128
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:76
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:743
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
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:1063
bool bModified
Definition: chrdlg.hxx:71
sal_Int32 GetEntryPos(const OUString &rStr) const
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, bool bRelativeNonURIs=false, FSysStyle eStyle=FSysStyle::Detect)
const SvxMacroTableDtor & GetMacroTable() const
const OUString & GetVisitedFormat() const
Definition: fmtinfmt.hxx:116
#define FN_PARAM_SELECTION
Definition: cmdid.h:751
sal_uInt16 m_nCharPosId
Definition: chrdlg.hxx:41
virtual void dispose() override
Definition: chardlg.cxx:195
#define ERRCODE_NONE
const OUString & GetTargetFrame() const
Definition: fmtinfmt.hxx:85
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
OUString GetSelectEntry(sal_Int32 nSelIndex=0) const
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:190
const OUString & GetINetFormat() const
Definition: fmtinfmt.hxx:98
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:301
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:80
Definition: view.hxx:146
bool IsValueChangedFromSaved() const
SvxMacroItem * pINetItem
Definition: chrdlg.hxx:70
void RemoveTabPage(const OString &rName)
static OUString decode(OUString const &rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)