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