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 <vcl/settings.hxx>
21 #include <unotools/viewoptions.hxx>
22 #include "cuihyperdlg.hxx"
23 #include "hlinettp.hxx"
24 #include "hlmailtp.hxx"
25 #include "hldoctp.hxx"
26 #include "hldocntp.hxx"
27 #include <svx/svxids.hrc>
29 using ::com::sun::star::uno::Reference
;
30 using ::com::sun::star::frame::XFrame
;
34 //# Childwindow-Wrapper-Class #
38 SvxHlinkCtrl::SvxHlinkCtrl( sal_uInt16 _nId
, SfxBindings
& rBindings
, SvxHpLinkDlg
* pDlg
)
39 : SfxControllerItem ( _nId
, rBindings
)
40 , aRdOnlyForwarder ( SID_READONLY_MODE
, *this )
45 void SvxHlinkCtrl::dispose()
47 aRdOnlyForwarder
.dispose();
48 ::SfxControllerItem::dispose();
51 void SvxHlinkCtrl::StateChanged( sal_uInt16 nSID
, SfxItemState eState
,
52 const SfxPoolItem
* pState
)
54 if ( eState
== SfxItemState::DEFAULT
&& !pParent
->IsDisposed() )
58 case SID_HYPERLINK_GETLINK
:
60 pParent
->SetPage( const_cast<SvxHyperlinkItem
*>(static_cast<const SvxHyperlinkItem
*>(pState
)) );
63 case SID_READONLY_MODE
:
65 pParent
->SetReadOnlyMode( static_cast<const SfxBoolItem
*>(pState
)->GetValue() );
80 //# Hyperlink - Dialog #
84 /*************************************************************************
86 |* Constructor / Destructor
88 |************************************************************************/
90 SvxHpLinkDlg::SvxHpLinkDlg (vcl::Window
* pParent
, SfxBindings
* pBindings
)
91 : IconChoiceDialog( pParent
, "HyperlinkDialog", "cui/ui/hyperlinkdialog.ui" ),
92 maCtrl ( SID_HYPERLINK_GETLINK
, *pBindings
, this ),
93 mpBindings ( pBindings
),
97 SetUniqueId( HID_HYPERLINK_DIALOG
);
102 SvxIconChoiceCtrlEntry
*pEntry
;
104 aStrTitle
= CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLINETTP
);
105 aImage
= Image( CUI_RES ( RID_SVXBMP_HLINETTP
) );
106 pEntry
= AddTabPage ( RID_SVXPAGE_HYPERLINK_INTERNET
, aStrTitle
, aImage
, SvxHyperlinkInternetTp::Create
);
107 pEntry
->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLINETTP_HELP
) );
108 aStrTitle
= CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLMAILTP
);
109 aImage
= Image( CUI_RES ( RID_SVXBMP_HLMAILTP
) );
110 pEntry
= AddTabPage ( RID_SVXPAGE_HYPERLINK_MAIL
, aStrTitle
, aImage
, SvxHyperlinkMailTp::Create
);
111 pEntry
->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLMAILTP_HELP
) );
112 aStrTitle
= CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCTP
);
113 aImage
= Image( CUI_RES ( RID_SVXBMP_HLDOCTP
) );
114 pEntry
= AddTabPage ( RID_SVXPAGE_HYPERLINK_DOCUMENT
, aStrTitle
, aImage
, SvxHyperlinkDocTp::Create
);
115 pEntry
->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCTP_HELP
) );
116 aStrTitle
= CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP
);
117 aImage
= Image( CUI_RES ( RID_SVXBMP_HLDOCNTP
) );
118 pEntry
= AddTabPage ( RID_SVXPAGE_HYPERLINK_NEWDOCUMENT
, aStrTitle
, aImage
, SvxHyperlinkNewDocTp::Create
);
119 pEntry
->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP_HELP
) );
121 // set OK/Cancel - button
122 GetCancelButton().SetText ( CUI_RESSTR(RID_SVXSTR_HYPDLG_CLOSEBUT
) );
124 // create itemset for tabpages
125 mpItemSet
= new SfxItemSet( SfxGetpApp()->GetPool(), SID_HYPERLINK_GETLINK
,
126 SID_HYPERLINK_SETLINK
);
128 SvxHyperlinkItem aItem
;
129 mpItemSet
->Put (aItem
, SID_HYPERLINK_GETLINK
);
131 SetInputSet (mpItemSet
);
133 //loop through the pages and get their max bounds and lock that down
134 ShowPage(RID_SVXPAGE_HYPERLINK_NEWDOCUMENT
);
135 VclBox
*pBox
= get_content_area();
136 Size
aMaxPrefSize(pBox
->get_preferred_size());
137 ShowPage(RID_SVXPAGE_HYPERLINK_DOCUMENT
);
138 Size
aSize(pBox
->get_preferred_size());
139 aMaxPrefSize
.Width() = std::max(aMaxPrefSize
.Width(), aSize
.Width());
140 aMaxPrefSize
.Height() = std::max(aMaxPrefSize
.Height(), aSize
.Height());
141 ShowPage(RID_SVXPAGE_HYPERLINK_MAIL
);
142 aSize
= pBox
->get_preferred_size();
143 aMaxPrefSize
.Width() = std::max(aMaxPrefSize
.Width(), aSize
.Width());
144 aMaxPrefSize
.Height() = std::max(aMaxPrefSize
.Height(), aSize
.Height());
145 ShowPage(RID_SVXPAGE_HYPERLINK_INTERNET
);
146 aSize
= pBox
->get_preferred_size();
147 aMaxPrefSize
.Width() = std::max(aMaxPrefSize
.Width(), aSize
.Width());
148 aMaxPrefSize
.Height() = std::max(aMaxPrefSize
.Height(), aSize
.Height());
149 pBox
->set_width_request(aMaxPrefSize
.Width());
150 pBox
->set_height_request(aMaxPrefSize
.Height());
152 SetCurPageId(RID_SVXPAGE_HYPERLINK_INTERNET
);
157 pBindings
->Update( SID_READONLY_MODE
);
159 GetOKButton().SetClickHdl ( LINK ( this, SvxHpLinkDlg
, ClickOkHdl_Impl
) );
160 GetApplyButton().SetClickHdl ( LINK ( this, SvxHpLinkDlg
, ClickApplyHdl_Impl
) );
161 GetCancelButton().SetClickHdl( LINK ( this, SvxHpLinkDlg
, ClickCloseHdl_Impl
) );
164 SvxHpLinkDlg::~SvxHpLinkDlg ()
169 void SvxHpLinkDlg::dispose()
171 // delete config item, so the base class (IconChoiceDialog) can not load it on the next start
172 SvtViewOptions
aViewOpt( E_TABDIALOG
, OUString::number(SID_HYPERLINK_DIALOG
) );
180 IconChoiceDialog::dispose();
183 /*************************************************************************
185 |* Close Dialog-Window
187 |************************************************************************/
189 bool SvxHpLinkDlg::Close()
191 GetDispatcher()->Execute( SID_HYPERLINK_DIALOG
,
192 SfxCallMode::ASYNCHRON
|
193 SfxCallMode::RECORD
);
197 void SvxHpLinkDlg::Apply()
199 SfxItemSet
aItemSet( SfxGetpApp()->GetPool(), SID_HYPERLINK_GETLINK
,
200 SID_HYPERLINK_SETLINK
);
202 SvxHyperlinkTabPageBase
* pCurrentPage
= static_cast<SvxHyperlinkTabPageBase
*>(
203 GetTabPage( GetCurPageId() ) );
205 if ( pCurrentPage
->AskApply() )
207 pCurrentPage
->FillItemSet( &aItemSet
);
209 const SvxHyperlinkItem
*aItem
= static_cast<const SvxHyperlinkItem
*>(
210 aItemSet
.GetItem (SID_HYPERLINK_SETLINK
));
212 if ( aItem
->GetURL() != aStrEmpty
)
213 GetDispatcher()->Execute( SID_HYPERLINK_SETLINK
, SfxCallMode::ASYNCHRON
|
214 SfxCallMode::RECORD
, aItem
, 0L);
216 static_cast<SvxHyperlinkTabPageBase
*>( GetTabPage( GetCurPageId() ) )->DoApply();
220 /*************************************************************************
222 |* When extra window is visible and its never moved by user, then move that
225 |************************************************************************/
227 void SvxHpLinkDlg::Move()
229 SvxHyperlinkTabPageBase
* pCurrentPage
= static_cast<SvxHyperlinkTabPageBase
*>(
230 GetTabPage ( GetCurPageId() ) );
232 if( pCurrentPage
->IsMarkWndVisible () )
234 // Pos&Size of this dialog-window
235 Point
aDlgPos ( GetPosPixel () );
236 Size
aDlgSize ( GetSizePixel () );
238 // Size of Office-Main-Window
239 Size
aWindowSize( SfxGetpApp()->GetTopWindow()->GetSizePixel() );
241 // Size of Extrawindow
242 Size
aExtraWndSize( pCurrentPage
->GetSizeExtraWnd() );
245 if( aDlgPos
.X()+(1.02*aDlgSize
.Width())+aExtraWndSize
.Width() > aWindowSize
.Width() )
247 if( aDlgPos
.X() - ( 0.02*aDlgSize
.Width() ) - aExtraWndSize
.Width() < 0 )
249 // Pos Extrawindow anywhere
250 bDoInvalid
= pCurrentPage
->MoveToExtraWnd( Point( 1, long(1.1*aDlgPos
.Y()) ), true );
254 // Pos Extrawindow on the left side of Dialog
255 bDoInvalid
= pCurrentPage
->MoveToExtraWnd( aDlgPos
-
256 Point( long(0.02*aDlgSize
.Width()), 0 ) -
257 Point( aExtraWndSize
.Width(), 0 ) );
262 // Pos Extrawindow on the right side of Dialog
263 bDoInvalid
= pCurrentPage
->MoveToExtraWnd ( aDlgPos
+ Point( long(1.02*aDlgSize
.Width()), 0 ) );
267 Invalidate(INVALIDATE_BACKGROUND
);
273 /// Click on OK button
274 IMPL_LINK_NOARG(SvxHpLinkDlg
, ClickOkHdl_Impl
)
282 /*************************************************************************
284 |* Click on Apply-button
286 |************************************************************************/
288 IMPL_LINK_NOARG(SvxHpLinkDlg
, ClickApplyHdl_Impl
)
295 /*************************************************************************
297 |* Click on Close-button
299 |************************************************************************/
301 IMPL_LINK_NOARG(SvxHpLinkDlg
, ClickCloseHdl_Impl
)
308 /*************************************************************************
312 |************************************************************************/
314 sal_uInt16
SvxHpLinkDlg::SetPage ( SvxHyperlinkItem
* pItem
)
316 sal_uInt16 nPageId
= RID_SVXPAGE_HYPERLINK_INTERNET
;
318 OUString
aStrURL(pItem
->GetURL());
319 INetURLObject
aURL(aStrURL
);
320 INetProtocol eProtocolTyp
= aURL
.GetProtocol();
322 switch ( eProtocolTyp
)
324 case INetProtocol::Http
:
325 case INetProtocol::Ftp
:
326 nPageId
= RID_SVXPAGE_HYPERLINK_INTERNET
;
328 case INetProtocol::File
:
329 nPageId
= RID_SVXPAGE_HYPERLINK_DOCUMENT
;
331 case INetProtocol::Mailto
:
332 nPageId
= RID_SVXPAGE_HYPERLINK_MAIL
;
335 if (aStrURL
.startsWith("#"))
336 nPageId
= RID_SVXPAGE_HYPERLINK_DOCUMENT
;
339 eProtocolTyp
= INetProtocol::NotValid
;
340 nPageId
= GetCurPageId();
347 SvxHyperlinkTabPageBase
* pCurrentPage
= static_cast<SvxHyperlinkTabPageBase
*>(GetTabPage( nPageId
));
349 mbIsHTMLDoc
= (pItem
->GetInsertMode() & HLINK_HTMLMODE
) != 0;
351 IconChoicePage
* pPage
= GetTabPage (nPageId
);
354 SfxItemSet
& aPageSet
= (SfxItemSet
&)pPage
->GetItemSet ();
355 aPageSet
.Put ( *pItem
);
357 pCurrentPage
->Reset( aPageSet
);
360 pCurrentPage
->SetInitFocus(); // #92535# grab the focus only once at initialization
367 /*************************************************************************
369 |* Enable/Disable ReadOnly mode
371 |************************************************************************/
373 void SvxHpLinkDlg::SetReadOnlyMode( bool bRdOnly
)
375 mbReadOnly
= bRdOnly
;
377 GetOKButton().Disable();
379 GetOKButton().Enable();
382 /*************************************************************************
384 |* late-initialization of newly created pages
386 |************************************************************************/
388 void SvxHpLinkDlg::PageCreated( sal_uInt16
/*nId*/, IconChoicePage
& rPage
)
390 SvxHyperlinkTabPageBase
& rHyperlinkPage
= dynamic_cast< SvxHyperlinkTabPageBase
& >( rPage
);
391 Reference
< XFrame
> xDocumentFrame
;
393 xDocumentFrame
= mpBindings
->GetActiveFrame();
394 OSL_ENSURE( xDocumentFrame
.is(), "SvxHpLinkDlg::PageCreated: macro assignment functionality won't work with a proper frame!" );
395 rHyperlinkPage
.SetDocumentFrame( xDocumentFrame
);
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */