LibreOffice Module cui (master)  1
cuihyperdlg.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 <sal/config.h>
21 
22 #include <osl/diagnose.h>
23 #include <comphelper/lok.hxx>
24 #include <unotools/viewoptions.hxx>
25 #include <cuihyperdlg.hxx>
26 #include <hlinettp.hxx>
27 #include <hlmailtp.hxx>
28 #include <hldoctp.hxx>
29 #include <hldocntp.hxx>
30 #include <sfx2/app.hxx>
31 #include <sfx2/viewfrm.hxx>
32 #include <svl/eitem.hxx>
33 #include <svx/svxids.hrc>
34 #include <dialmgr.hxx>
35 #include <strings.hrc>
36 #include <vector>
37 
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::frame::XFrame;
40 
41 
42 //# #
43 //# Childwindow-Wrapper-Class #
44 //# #
45 
46 
47 SvxHlinkCtrl::SvxHlinkCtrl( sal_uInt16 _nId, SfxBindings & rBindings, SvxHpLinkDlg* pDlg )
48  : SfxControllerItem ( _nId, rBindings )
49  , aRdOnlyForwarder ( SID_READONLY_MODE, *this )
50 {
51  pParent = pDlg;
52 }
53 
55 {
56  pParent = nullptr;
59 }
60 
61 void SvxHlinkCtrl::StateChanged( sal_uInt16 nSID, SfxItemState eState,
62  const SfxPoolItem* pState )
63 {
64  if (eState == SfxItemState::DEFAULT && pParent)
65  {
66  switch ( nSID )
67  {
68  case SID_HYPERLINK_GETLINK :
69  {
70  pParent->SetPage( static_cast<const SvxHyperlinkItem*>(pState) );
71  }
72  break;
73  case SID_READONLY_MODE :
74  {
75  pParent->SetReadOnlyMode( static_cast<const SfxBoolItem*>(pState)->GetValue() );
76  }
77  break;
78  }
79  }
80 }
81 
82 //# #
83 //# Hyperlink - Dialog #
84 //# #
86  : SfxModelessDialogController(pBindings, pChild, pParent, "cui/ui/hyperlinkdialog.ui", "HyperlinkDialog")
87  , pSet ( nullptr )
88  , pExampleSet ( nullptr )
89  , maCtrl ( SID_HYPERLINK_GETLINK, *pBindings, this )
90  , mbIsHTMLDoc ( false )
91  , m_xIconCtrl(m_xBuilder->weld_notebook("icon_control"))
92  , m_xOKBtn(m_xBuilder->weld_button("ok"))
93  , m_xApplyBtn(m_xBuilder->weld_button("apply"))
94  , m_xCancelBtn(m_xBuilder->weld_button("cancel"))
95  , m_xHelpBtn(m_xBuilder->weld_button("help"))
96  , m_xResetBtn(m_xBuilder->weld_button("reset"))
97 {
98  m_xIconCtrl->connect_enter_page( LINK ( this, SvxHpLinkDlg, ChosePageHdl_Impl ) );
99  m_xIconCtrl->show();
100 
101  // ItemSet
102  if ( pSet )
103  {
104  pExampleSet = new SfxItemSet( *pSet );
105  pOutSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ));
106  }
107 
108  // Buttons
109  m_xOKBtn->show();
110  m_xApplyBtn->show();
111  m_xCancelBtn->show();
112  m_xHelpBtn->show();
113  m_xResetBtn->show();
114 
115  mbGrabFocus = true;
116 
117  // set OK/Cancel - button
118  m_xCancelBtn->set_label(CuiResId(RID_SVXSTR_HYPDLG_CLOSEBUT));
119 
120  // create itemset for tabpages
121  mpItemSet = std::make_unique<SfxItemSet>( SfxGetpApp()->GetPool(), svl::Items<SID_HYPERLINK_GETLINK,
122  SID_HYPERLINK_SETLINK>{} );
123 
124  SvxHyperlinkItem aItem(SID_HYPERLINK_GETLINK);
125  mpItemSet->Put(aItem);
126 
127  SetInputSet (mpItemSet.get());
128 
129  // insert pages
133  {
136  }
137 
138  SetCurPageId("internet");
139 
140  // Init Dialog
141  Start();
142 
143  GetBindings().Update(SID_READONLY_MODE);
144 
145  m_xResetBtn->connect_clicked( LINK( this, SvxHpLinkDlg, ResetHdl ) );
146  m_xOKBtn->connect_clicked( LINK ( this, SvxHpLinkDlg, ClickOkHdl_Impl ) );
147  m_xApplyBtn->connect_clicked ( LINK ( this, SvxHpLinkDlg, ClickApplyHdl_Impl ) );
148 }
149 
151 {
152  // delete config item, so the base class (SfxModelessDialogController) can not load it on the next start
153  SvtViewOptions aViewOpt( EViewType::TabDialog, OUString::number(SID_HYPERLINK_DIALOG) );
154  aViewOpt.Delete();
155 
156  mpItemSet.reset();
157 
158  maCtrl.dispose();
159 
160  maPageList.clear();
161 
162  pRanges.reset();
163  pOutSet.reset();
164 }
165 
167 {
168  if (IsClosing())
169  return;
170  SfxViewFrame* pViewFrame = SfxViewFrame::Current();
171  if (pViewFrame)
172  pViewFrame->ToggleChildWindow(SID_HYPERLINK_DIALOG);
173 }
174 
176 {
177  SfxItemSet aItemSet( SfxGetpApp()->GetPool(), svl::Items<SID_HYPERLINK_GETLINK,
178  SID_HYPERLINK_SETLINK>{} );
179 
180  SvxHyperlinkTabPageBase* pCurrentPage = static_cast<SvxHyperlinkTabPageBase*>(
181  GetTabPage( GetCurPageId() ) );
182 
183  if ( pCurrentPage->AskApply() )
184  {
185  pCurrentPage->FillItemSet( &aItemSet );
186 
187  const SvxHyperlinkItem *aItem = aItemSet.GetItem(SID_HYPERLINK_SETLINK);
188  if ( !aItem->GetURL().isEmpty() )
189  GetDispatcher()->ExecuteList(SID_HYPERLINK_SETLINK,
190  SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, { aItem });
191 
192  static_cast<SvxHyperlinkTabPageBase*>( GetTabPage( GetCurPageId() ) )->DoApply();
193  }
194 }
195 
197 IMPL_LINK_NOARG(SvxHpLinkDlg, ClickOkHdl_Impl, weld::Button&, void)
198 {
199  Apply();
200  m_xDialog->response(RET_OK);
201 }
202 
203 /*************************************************************************
204 |*
205 |* Click on Apply-button
206 |*
207 |************************************************************************/
208 IMPL_LINK_NOARG(SvxHpLinkDlg, ClickApplyHdl_Impl, weld::Button&, void)
209 {
210  Apply();
211 }
212 
213 /*************************************************************************
214 |*
215 |* Set Page
216 |*
217 |************************************************************************/
219 {
220  OString sPageId("internet");
221 
222  OUString aStrURL(pItem->GetURL());
223  INetURLObject aURL(aStrURL);
224  INetProtocol eProtocolTyp = aURL.GetProtocol();
225 
226  switch ( eProtocolTyp )
227  {
228  case INetProtocol::Http :
229  case INetProtocol::Ftp :
230  sPageId = "internet";
231  break;
232  case INetProtocol::File :
233  sPageId = "document";
234  break;
235  case INetProtocol::Mailto :
236  sPageId = "mail";
237  break;
238  default :
239  if (aStrURL.startsWith("#"))
240  sPageId = "document";
241  else
242  {
243  // not valid
244  sPageId = GetCurPageId();
245  }
246  break;
247  }
248 
249  ShowPage (sPageId);
250 
251  SvxHyperlinkTabPageBase* pCurrentPage = static_cast<SvxHyperlinkTabPageBase*>(GetTabPage( sPageId ));
252 
253  mbIsHTMLDoc = (pItem->GetInsertMode() & HLINK_HTMLMODE) != 0;
254 
255  IconChoicePage* pPage = GetTabPage (sPageId);
256  if(pPage)
257  {
258  SfxItemSet& aPageSet = const_cast<SfxItemSet&>(pPage->GetItemSet ());
259  aPageSet.Put ( *pItem );
260 
261  pCurrentPage->Reset( aPageSet );
262  if ( mbGrabFocus )
263  {
264  pCurrentPage->SetInitFocus(); // #92535# grab the focus only once at initialization
265  mbGrabFocus = false;
266  }
267  }
268 }
269 
270 /*************************************************************************
271 |*
272 |* Enable/Disable ReadOnly mode
273 |*
274 |************************************************************************/
275 void SvxHpLinkDlg::SetReadOnlyMode( bool bRdOnly )
276 {
277  GetOKButton().set_sensitive(!bRdOnly);
278 }
279 
280 /*************************************************************************
281 |*
282 |* late-initialization of newly created pages
283 |*
284 |************************************************************************/
285 void SvxHpLinkDlg::PageCreated(const OString& /*rId*/, IconChoicePage& rPage)
286 {
287  SvxHyperlinkTabPageBase& rHyperlinkPage = dynamic_cast< SvxHyperlinkTabPageBase& >( rPage );
288  Reference< XFrame > xDocumentFrame = GetBindings().GetActiveFrame();
289  OSL_ENSURE( xDocumentFrame.is(), "SvxHpLinkDlg::PageCreated: macro assignment functionality won't work with a proper frame!" );
290  rHyperlinkPage.SetDocumentFrame( xDocumentFrame );
291 }
292 
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::uno::Reference< css::frame::XFrame > GetActiveFrame() const
SvxHlinkCtrl maCtrl
Controller.
Definition: cuihyperdlg.hxx:77
void SetPage(SvxHyperlinkItem const *pItem)
std::unique_ptr< weld::Button > m_xHelpBtn
Definition: cuihyperdlg.hxx:87
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
void SetCurPageId(const OString &rId)
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: cuihyperdlg.cxx:61
std::string GetValue
virtual void dispose() override
Definition: cuihyperdlg.cxx:54
OString GetCurPageId() const
virtual bool FillItemSet(SfxItemSet *) override
Definition: hltpbase.cxx:466
virtual void Close() override
virtual void SetInitFocus()
Definition: hltpbase.cxx:301
void Start()
Definition: iconcdlg.cxx:261
SfxItemSet * pExampleSet
Definition: cuihyperdlg.hxx:74
static std::unique_ptr< IconChoicePage > Create(weld::Container *pWindow, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
Definition: hldoctp.cxx:147
static std::unique_ptr< IconChoicePage > Create(weld::Container *pWindow, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
Definition: hlmailtp.cxx:153
IconChoicePage * GetTabPage(const OString &rPageId)
static std::unique_ptr< IconChoicePage > Create(weld::Container *pWindow, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
Definition: hlinettp.cxx:176
IMPL_LINK_NOARG(SvxHpLinkDlg, ClickOkHdl_Impl, weld::Button &, void)
Click on OK button.
SfxStatusForwarder aRdOnlyForwarder
Definition: cuihyperdlg.hxx:46
SfxApplication * SfxGetpApp()
void ToggleChildWindow(sal_uInt16)
void PageCreated(const OString &rId, IconChoicePage &rPage)
std::unique_ptr< weld::Button > m_xOKBtn
Definition: cuihyperdlg.hxx:84
HLINK_HTMLMODE
INetProtocol
SfxItemPool & GetPool() const
SvxHpLinkDlg(SfxBindings *pBindings, SfxChildWindow *pChild, weld::Window *pParent)
Definition: cuihyperdlg.cxx:85
SvxHlinkCtrl(sal_uInt16 nId, SfxBindings &rBindings, SvxHpLinkDlg *pDlg)
Definition: cuihyperdlg.cxx:47
virtual ~SvxHpLinkDlg() override
const OUString & GetURL() const
static std::unique_ptr< IconChoicePage > Create(weld::Container *pWindow, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
Definition: hldocntp.cxx:229
virtual void dispose()
std::unique_ptr< weld::Notebook > m_xIconCtrl
Definition: cuihyperdlg.hxx:83
std::vector< std::unique_ptr< IconChoicePageData > > maPageList
Definition: cuihyperdlg.hxx:68
const SfxItemSet * pSet
Definition: cuihyperdlg.hxx:72
std::unique_ptr< weld::Button > m_xCancelBtn
Definition: cuihyperdlg.hxx:86
std::unique_ptr< SfxItemSet > pOutSet
Definition: cuihyperdlg.hxx:73
weld::Button & GetOKButton()
SfxItemPool * GetPool() const
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
const SfxItemSet & GetItemSet() const
Definition: iconcdlg.hxx:69
SfxDispatcher * GetDispatcher() const
void Update(sal_uInt16 nId)
std::unique_ptr< sal_uInt16[]> pRanges
Definition: cuihyperdlg.hxx:75
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void SetDocumentFrame(const css::uno::Reference< css::frame::XFrame > &rxDocumentFrame)
Definition: hltpbase.hxx:103
static SfxViewFrame * Current()
SfxItemState
SfxBindings & GetBindings() const
RET_OK
std::unique_ptr< SfxItemSet > mpItemSet
Definition: cuihyperdlg.hxx:78
void ShowPage(const OString &rId)
Definition: iconcdlg.cxx:85
const sal_uInt16 * GetRanges() const
SvxLinkInsertMode GetInsertMode() const
SvxHpLinkDlg * pParent
Definition: cuihyperdlg.hxx:44
std::unique_ptr< weld::Button > m_xApplyBtn
Definition: cuihyperdlg.hxx:85
virtual void Reset(const SfxItemSet &) override
Definition: hltpbase.cxx:443
void SetInputSet(const SfxItemSet *pInSet)
Definition: iconcdlg.cxx:248
void AddTabPage(const OString &rId, CreatePage pCreateFunc)
Definition: iconcdlg.cxx:72
void SetReadOnlyMode(bool bReadOnly)
Tabpage : Basisclass.
Definition: hltpbase.hxx:47
virtual void set_sensitive(bool sensitive)=0
std::unique_ptr< weld::Button > m_xResetBtn
Definition: cuihyperdlg.hxx:88