1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
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>
38 using ::com::sun::star::uno::Reference
;
39 using ::com::sun::star::frame::XFrame
;
43 //# Childwindow-Wrapper-Class #
47 SvxHlinkCtrl::SvxHlinkCtrl( sal_uInt16 _nId
, SfxBindings
& rBindings
, SvxHpLinkDlg
* pDlg
)
48 : SfxControllerItem ( _nId
, rBindings
)
49 , aRdOnlyForwarder ( SID_READONLY_MODE
, *this )
54 void SvxHlinkCtrl::dispose()
57 aRdOnlyForwarder
.dispose();
58 ::SfxControllerItem::dispose();
61 void SvxHlinkCtrl::StateChangedAtToolBoxControl( sal_uInt16 nSID
, SfxItemState eState
,
62 const SfxPoolItem
* pState
)
64 if (!(eState
== SfxItemState::DEFAULT
&& pParent
))
69 case SID_HYPERLINK_GETLINK
:
71 pParent
->SetPage( static_cast<const SvxHyperlinkItem
*>(pState
) );
74 case SID_READONLY_MODE
:
76 pParent
->SetReadOnlyMode( static_cast<const SfxBoolItem
*>(pState
)->GetValue() );
82 // tdf#90496 - remember last used view in hyperlink dialog
83 OUString
SvxHpLinkDlg::msRememberedPageId(u
"internet"_ustr
);
86 //# Hyperlink - Dialog #
88 SvxHpLinkDlg::SvxHpLinkDlg(SfxBindings
* pBindings
, SfxChildWindow
* pChild
, weld::Window
* pParent
)
89 : SfxModelessDialogController(pBindings
, pChild
, pParent
, u
"cui/ui/hyperlinkdialog.ui"_ustr
, u
"HyperlinkDialog"_ustr
)
91 , maCtrl ( SID_HYPERLINK_GETLINK
, *pBindings
, this )
92 , mbIsHTMLDoc ( false )
93 , m_xIconCtrl(m_xBuilder
->weld_notebook(u
"tabcontrol"_ustr
))
94 , m_xOKBtn(m_xBuilder
->weld_button(u
"ok"_ustr
))
95 , m_xApplyBtn(m_xBuilder
->weld_button(u
"apply"_ustr
))
96 , m_xCancelBtn(m_xBuilder
->weld_button(u
"cancel"_ustr
))
97 , m_xHelpBtn(m_xBuilder
->weld_button(u
"help"_ustr
))
98 , m_xResetBtn(m_xBuilder
->weld_button(u
"reset"_ustr
))
100 m_xIconCtrl
->connect_enter_page( LINK ( this, SvxHpLinkDlg
, ChosePageHdl_Impl
) );
106 pExampleSet
.reset(new SfxItemSet( *pSet
));
107 pOutSet
.reset(new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() ));
112 m_xCancelBtn
->show();
114 if (comphelper::LibreOfficeKit::isActive())
129 // set OK/Cancel - button
130 m_xCancelBtn
->set_label(CuiResId(RID_CUISTR_HYPDLG_CLOSEBUT
));
132 // create itemset for tabpages
133 mpItemSet
= std::make_unique
<SfxItemSetFixed
<SID_HYPERLINK_GETLINK
,
134 SID_HYPERLINK_SETLINK
>>( SfxGetpApp()->GetPool());
136 SvxHyperlinkItem
aItem(SID_HYPERLINK_GETLINK
);
137 mpItemSet
->Put(aItem
);
139 SetInputSet (mpItemSet
.get());
142 AddTabPage(u
"internet"_ustr
, SvxHyperlinkInternetTp::Create
);
143 AddTabPage(u
"mail"_ustr
, SvxHyperlinkMailTp::Create
);
144 if (!comphelper::LibreOfficeKit::isActive())
146 AddTabPage(u
"document"_ustr
, SvxHyperlinkDocTp::Create
);
147 AddTabPage(u
"newdocument"_ustr
, SvxHyperlinkNewDocTp::Create
);
150 // tdf#90496 - remember last used view in hyperlink dialog
151 SetCurPageId(msRememberedPageId
);
156 GetBindings().Update(SID_HYPERLINK_GETLINK
);
157 GetBindings().Update(SID_READONLY_MODE
);
159 m_xResetBtn
->connect_clicked( LINK( this, SvxHpLinkDlg
, ResetHdl
) );
160 m_xOKBtn
->connect_clicked( LINK ( this, SvxHpLinkDlg
, ClickOkHdl_Impl
) );
161 m_xApplyBtn
->connect_clicked ( LINK ( this, SvxHpLinkDlg
, ClickApplyHdl_Impl
) );
164 SvxHpLinkDlg::~SvxHpLinkDlg()
166 mbGrabFocus
= false; // don't do any grab if tear-down moves focus around during destruction
168 // delete config item, so the base class (SfxModelessDialogController) can not load it on the next start
169 SvtViewOptions
aViewOpt( EViewType::TabDialog
, OUString::number(SID_HYPERLINK_DIALOG
) );
182 void SvxHpLinkDlg::Activate() {
184 static_cast<SvxHyperlinkTabPageBase
*>(GetTabPage(GetCurPageId()))->SetInitFocus();
187 SfxModelessDialogController::Activate();
190 void SvxHpLinkDlg::Close()
194 if (SfxViewFrame
* pViewFrame
= SfxViewFrame::Current())
195 pViewFrame
->ToggleChildWindow(SID_HYPERLINK_DIALOG
);
198 void SvxHpLinkDlg::Apply()
200 SfxItemSetFixed
<SID_HYPERLINK_GETLINK
, SID_HYPERLINK_SETLINK
> aItemSet( SfxGetpApp()->GetPool() );
202 SvxHyperlinkTabPageBase
* pCurrentPage
= static_cast<SvxHyperlinkTabPageBase
*>(
203 GetTabPage( GetCurPageId() ) );
205 pCurrentPage
->FillItemSet( &aItemSet
);
207 const SvxHyperlinkItem
*aItem
= aItemSet
.GetItem(SID_HYPERLINK_SETLINK
);
208 if ( !aItem
->GetURL().isEmpty() )
209 GetDispatcher()->ExecuteList(SID_HYPERLINK_SETLINK
,
210 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
, { aItem
});
212 static_cast<SvxHyperlinkTabPageBase
*>( GetTabPage( GetCurPageId() ) )->DoApply();
215 /// Click on OK button
216 IMPL_LINK_NOARG(SvxHpLinkDlg
, ClickOkHdl_Impl
, weld::Button
&, void)
219 m_xDialog
->response(RET_OK
);
222 /*************************************************************************
224 |* Click on Apply-button
226 |************************************************************************/
227 IMPL_LINK_NOARG(SvxHpLinkDlg
, ClickApplyHdl_Impl
, weld::Button
&, void)
232 /*************************************************************************
236 |************************************************************************/
237 void SvxHpLinkDlg::SetPage ( SvxHyperlinkItem
const * pItem
)
239 OUString
sPageId(u
"internet"_ustr
);
241 const OUString
& aStrURL(pItem
->GetURL());
242 INetURLObject
aURL(aStrURL
);
243 INetProtocol eProtocolTyp
= aURL
.GetProtocol();
245 switch ( eProtocolTyp
)
247 case INetProtocol::Http
:
248 case INetProtocol::Ftp
:
249 sPageId
= "internet";
251 case INetProtocol::File
:
252 sPageId
= "document";
254 case INetProtocol::Mailto
:
258 if (aStrURL
.startsWith("#"))
259 sPageId
= "document";
263 sPageId
= GetCurPageId();
270 SvxHyperlinkTabPageBase
* pCurrentPage
= static_cast<SvxHyperlinkTabPageBase
*>(GetTabPage( sPageId
));
272 mbIsHTMLDoc
= (pItem
->GetInsertMode() & HLINK_HTMLMODE
) != 0;
274 IconChoicePage
* pPage
= GetTabPage (sPageId
);
277 SfxItemSet
& aPageSet
= const_cast<SfxItemSet
&>(pPage
->GetItemSet ());
278 aPageSet
.Put ( *pItem
);
280 pCurrentPage
->Reset( aPageSet
);
284 /*************************************************************************
286 |* Enable/Disable ReadOnly mode
288 |************************************************************************/
289 void SvxHpLinkDlg::SetReadOnlyMode( bool bRdOnly
)
291 m_xOKBtn
->set_sensitive(!bRdOnly
);
294 /*************************************************************************
296 |* late-initialization of newly created pages
298 |************************************************************************/
299 void SvxHpLinkDlg::PageCreated(IconChoicePage
& rPage
)
301 SvxHyperlinkTabPageBase
& rHyperlinkPage
= dynamic_cast< SvxHyperlinkTabPageBase
& >( rPage
);
302 Reference
< XFrame
> xDocumentFrame
= GetBindings().GetActiveFrame();
303 OSL_ENSURE( xDocumentFrame
.is(), "SvxHpLinkDlg::PageCreated: macro assignment functionality won't work with a proper frame!" );
304 rHyperlinkPage
.SetDocumentFrame( xDocumentFrame
);
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */