android: Update app-specific/MIME type icons
[LibreOffice.git] / cui / source / dialogs / cuihyperdlg.cxx
blob86fd3c1a2c8f89e84f3d67e4527c36d3e803c312
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
36 #include <vector>
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::frame::XFrame;
42 //# #
43 //# Childwindow-Wrapper-Class #
44 //# #
47 SvxHlinkCtrl::SvxHlinkCtrl( sal_uInt16 _nId, SfxBindings & rBindings, SvxHpLinkDlg* pDlg )
48 : SfxControllerItem ( _nId, rBindings )
49 , aRdOnlyForwarder ( SID_READONLY_MODE, *this )
51 pParent = pDlg;
54 void SvxHlinkCtrl::dispose()
56 pParent = nullptr;
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))
65 return;
67 switch ( nSID )
69 case SID_HYPERLINK_GETLINK :
71 pParent->SetPage( static_cast<const SvxHyperlinkItem*>(pState) );
73 break;
74 case SID_READONLY_MODE :
76 pParent->SetReadOnlyMode( static_cast<const SfxBoolItem*>(pState)->GetValue() );
78 break;
82 // tdf#90496 - remember last used view in hyperlink dialog
83 OUString SvxHpLinkDlg::msRememberedPageId("internet");
85 //# #
86 //# Hyperlink - Dialog #
87 //# #
88 SvxHpLinkDlg::SvxHpLinkDlg(SfxBindings* pBindings, SfxChildWindow* pChild, weld::Window* pParent)
89 : SfxModelessDialogController(pBindings, pChild, pParent, "cui/ui/hyperlinkdialog.ui", "HyperlinkDialog")
90 , pSet ( nullptr )
91 , maCtrl ( SID_HYPERLINK_GETLINK, *pBindings, this )
92 , mbIsHTMLDoc ( false )
93 , m_xIconCtrl(m_xBuilder->weld_notebook("tabcontrol"))
94 , m_xOKBtn(m_xBuilder->weld_button("ok"))
95 , m_xApplyBtn(m_xBuilder->weld_button("apply"))
96 , m_xCancelBtn(m_xBuilder->weld_button("cancel"))
97 , m_xHelpBtn(m_xBuilder->weld_button("help"))
98 , m_xResetBtn(m_xBuilder->weld_button("reset"))
100 m_xIconCtrl->connect_enter_page( LINK ( this, SvxHpLinkDlg, ChosePageHdl_Impl ) );
101 m_xIconCtrl->show();
103 // ItemSet
104 if ( pSet )
106 pExampleSet.reset(new SfxItemSet( *pSet ));
107 pOutSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ));
110 // Buttons
111 m_xOKBtn->show();
112 m_xApplyBtn->show();
113 m_xCancelBtn->show();
114 m_xHelpBtn->show();
115 m_xResetBtn->show();
117 mbGrabFocus = true;
119 // set OK/Cancel - button
120 m_xCancelBtn->set_label(CuiResId(RID_CUISTR_HYPDLG_CLOSEBUT));
122 // create itemset for tabpages
123 mpItemSet = std::make_unique<SfxItemSetFixed<SID_HYPERLINK_GETLINK,
124 SID_HYPERLINK_SETLINK>>( SfxGetpApp()->GetPool());
126 SvxHyperlinkItem aItem(SID_HYPERLINK_GETLINK);
127 mpItemSet->Put(aItem);
129 SetInputSet (mpItemSet.get());
131 // insert pages
132 AddTabPage("internet", SvxHyperlinkInternetTp::Create);
133 AddTabPage("mail", SvxHyperlinkMailTp::Create);
134 if (!comphelper::LibreOfficeKit::isActive())
136 AddTabPage("document", SvxHyperlinkDocTp::Create);
137 AddTabPage("newdocument", SvxHyperlinkNewDocTp::Create);
140 // tdf#90496 - remember last used view in hyperlink dialog
141 SetCurPageId(msRememberedPageId);
143 // Init Dialog
144 Start();
146 GetBindings().Update(SID_HYPERLINK_GETLINK);
147 GetBindings().Update(SID_READONLY_MODE);
149 m_xResetBtn->connect_clicked( LINK( this, SvxHpLinkDlg, ResetHdl ) );
150 m_xOKBtn->connect_clicked( LINK ( this, SvxHpLinkDlg, ClickOkHdl_Impl ) );
151 m_xApplyBtn->connect_clicked ( LINK ( this, SvxHpLinkDlg, ClickApplyHdl_Impl ) );
154 SvxHpLinkDlg::~SvxHpLinkDlg()
156 mbGrabFocus = false; // don't do any grab if tear-down moves focus around during destruction
158 // delete config item, so the base class (SfxModelessDialogController) can not load it on the next start
159 SvtViewOptions aViewOpt( EViewType::TabDialog, OUString::number(SID_HYPERLINK_DIALOG) );
160 aViewOpt.Delete();
162 mpItemSet.reset();
164 maCtrl.dispose();
166 maPageList.clear();
168 pRanges.reset();
169 pOutSet.reset();
172 void SvxHpLinkDlg::Activate() {
173 if (mbGrabFocus) {
174 static_cast<SvxHyperlinkTabPageBase *>(GetTabPage(GetCurPageId()))->SetInitFocus();
175 mbGrabFocus = false;
177 SfxModelessDialogController::Activate();
180 void SvxHpLinkDlg::Close()
182 if (IsClosing())
183 return;
184 if (SfxViewFrame* pViewFrame = SfxViewFrame::Current())
185 pViewFrame->ToggleChildWindow(SID_HYPERLINK_DIALOG);
188 void SvxHpLinkDlg::Apply()
190 SfxItemSetFixed<SID_HYPERLINK_GETLINK, SID_HYPERLINK_SETLINK> aItemSet( SfxGetpApp()->GetPool() );
192 SvxHyperlinkTabPageBase* pCurrentPage = static_cast<SvxHyperlinkTabPageBase*>(
193 GetTabPage( GetCurPageId() ) );
195 pCurrentPage->FillItemSet( &aItemSet );
197 const SvxHyperlinkItem *aItem = aItemSet.GetItem(SID_HYPERLINK_SETLINK);
198 if ( !aItem->GetURL().isEmpty() )
199 GetDispatcher()->ExecuteList(SID_HYPERLINK_SETLINK,
200 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, { aItem });
202 static_cast<SvxHyperlinkTabPageBase*>( GetTabPage( GetCurPageId() ) )->DoApply();
205 /// Click on OK button
206 IMPL_LINK_NOARG(SvxHpLinkDlg, ClickOkHdl_Impl, weld::Button&, void)
208 Apply();
209 m_xDialog->response(RET_OK);
212 /*************************************************************************
214 |* Click on Apply-button
216 |************************************************************************/
217 IMPL_LINK_NOARG(SvxHpLinkDlg, ClickApplyHdl_Impl, weld::Button&, void)
219 Apply();
222 /*************************************************************************
224 |* Set Page
226 |************************************************************************/
227 void SvxHpLinkDlg::SetPage ( SvxHyperlinkItem const * pItem )
229 OUString sPageId("internet");
231 OUString aStrURL(pItem->GetURL());
232 INetURLObject aURL(aStrURL);
233 INetProtocol eProtocolTyp = aURL.GetProtocol();
235 switch ( eProtocolTyp )
237 case INetProtocol::Http :
238 case INetProtocol::Ftp :
239 sPageId = "internet";
240 break;
241 case INetProtocol::File :
242 sPageId = "document";
243 break;
244 case INetProtocol::Mailto :
245 sPageId = "mail";
246 break;
247 default :
248 if (aStrURL.startsWith("#"))
249 sPageId = "document";
250 else
252 // not valid
253 sPageId = GetCurPageId();
255 break;
258 ShowPage (sPageId);
260 SvxHyperlinkTabPageBase* pCurrentPage = static_cast<SvxHyperlinkTabPageBase*>(GetTabPage( sPageId ));
262 mbIsHTMLDoc = (pItem->GetInsertMode() & HLINK_HTMLMODE) != 0;
264 IconChoicePage* pPage = GetTabPage (sPageId);
265 if(pPage)
267 SfxItemSet& aPageSet = const_cast<SfxItemSet&>(pPage->GetItemSet ());
268 aPageSet.Put ( *pItem );
270 pCurrentPage->Reset( aPageSet );
274 /*************************************************************************
276 |* Enable/Disable ReadOnly mode
278 |************************************************************************/
279 void SvxHpLinkDlg::SetReadOnlyMode( bool bRdOnly )
281 m_xOKBtn->set_sensitive(!bRdOnly);
284 /*************************************************************************
286 |* late-initialization of newly created pages
288 |************************************************************************/
289 void SvxHpLinkDlg::PageCreated(IconChoicePage& rPage)
291 SvxHyperlinkTabPageBase& rHyperlinkPage = dynamic_cast< SvxHyperlinkTabPageBase& >( rPage );
292 Reference< XFrame > xDocumentFrame = GetBindings().GetActiveFrame();
293 OSL_ENSURE( xDocumentFrame.is(), "SvxHpLinkDlg::PageCreated: macro assignment functionality won't work with a proper frame!" );
294 rHyperlinkPage.SetDocumentFrame( xDocumentFrame );
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */