Line data Source code
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 <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>
28 :
29 : using ::com::sun::star::uno::Reference;
30 : using ::com::sun::star::frame::XFrame;
31 :
32 :
33 : //# #
34 : //# Childwindow-Wrapper-Class #
35 : //# #
36 :
37 :
38 0 : SvxHlinkCtrl::SvxHlinkCtrl( sal_uInt16 _nId, SfxBindings & rBindings, SvxHpLinkDlg* pDlg )
39 : : SfxControllerItem ( _nId, rBindings )
40 0 : , aRdOnlyForwarder ( SID_READONLY_MODE, *this )
41 : {
42 0 : pParent = pDlg;
43 0 : }
44 :
45 0 : void SvxHlinkCtrl::dispose()
46 : {
47 0 : aRdOnlyForwarder.dispose();
48 0 : ::SfxControllerItem::dispose();
49 0 : }
50 :
51 0 : void SvxHlinkCtrl::StateChanged( sal_uInt16 nSID, SfxItemState eState,
52 : const SfxPoolItem* pState )
53 : {
54 0 : if ( eState == SfxItemState::DEFAULT && !pParent->IsDisposed() )
55 : {
56 0 : switch ( nSID )
57 : {
58 : case SID_HYPERLINK_GETLINK :
59 : {
60 0 : pParent->SetPage( const_cast<SvxHyperlinkItem*>(static_cast<const SvxHyperlinkItem*>(pState)) );
61 : }
62 0 : break;
63 : case SID_READONLY_MODE :
64 : {
65 0 : pParent->SetReadOnlyMode( static_cast<const SfxBoolItem*>(pState)->GetValue() );
66 : }
67 0 : break;
68 : }
69 : }
70 0 : }
71 :
72 :
73 :
74 :
75 :
76 :
77 :
78 :
79 : //# #
80 : //# Hyperlink - Dialog #
81 : //# #
82 :
83 :
84 : /*************************************************************************
85 : |*
86 : |* Constructor / Destructor
87 : |*
88 : |************************************************************************/
89 :
90 0 : 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 ),
94 : mbReadOnly ( false ),
95 0 : mbIsHTMLDoc ( false )
96 : {
97 0 : SetUniqueId( HID_HYPERLINK_DIALOG );
98 0 : mbGrabFocus = true;
99 : // insert pages
100 0 : Image aImage;
101 0 : OUString aStrTitle;
102 : SvxIconChoiceCtrlEntry *pEntry;
103 :
104 0 : aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLINETTP );
105 0 : aImage = Image( CUI_RES ( RID_SVXBMP_HLINETTP ) );
106 0 : pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_INTERNET, aStrTitle, aImage, SvxHyperlinkInternetTp::Create );
107 0 : pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLINETTP_HELP ) );
108 0 : aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLMAILTP );
109 0 : aImage = Image( CUI_RES ( RID_SVXBMP_HLMAILTP ) );
110 0 : pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_MAIL, aStrTitle, aImage, SvxHyperlinkMailTp::Create );
111 0 : pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLMAILTP_HELP ) );
112 0 : aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCTP );
113 0 : aImage = Image( CUI_RES ( RID_SVXBMP_HLDOCTP ) );
114 0 : pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_DOCUMENT, aStrTitle, aImage, SvxHyperlinkDocTp::Create );
115 0 : pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCTP_HELP ) );
116 0 : aStrTitle = CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP );
117 0 : aImage = Image( CUI_RES ( RID_SVXBMP_HLDOCNTP ) );
118 0 : pEntry = AddTabPage ( RID_SVXPAGE_HYPERLINK_NEWDOCUMENT, aStrTitle, aImage, SvxHyperlinkNewDocTp::Create );
119 0 : pEntry->SetQuickHelpText( CUI_RESSTR( RID_SVXSTR_HYPERDLG_HLDOCNTP_HELP ) );
120 :
121 : // set OK/Cancel - button
122 0 : GetCancelButton().SetText ( CUI_RESSTR(RID_SVXSTR_HYPDLG_CLOSEBUT) );
123 :
124 : // create itemset for tabpages
125 0 : mpItemSet = new SfxItemSet( SfxGetpApp()->GetPool(), SID_HYPERLINK_GETLINK,
126 0 : SID_HYPERLINK_SETLINK );
127 :
128 0 : SvxHyperlinkItem aItem;
129 0 : mpItemSet->Put (aItem, SID_HYPERLINK_GETLINK);
130 :
131 0 : SetInputSet (mpItemSet);
132 :
133 : //loop through the pages and get their max bounds and lock that down
134 0 : ShowPage(RID_SVXPAGE_HYPERLINK_NEWDOCUMENT);
135 0 : VclBox *pBox = get_content_area();
136 0 : Size aMaxPrefSize(pBox->get_preferred_size());
137 0 : ShowPage(RID_SVXPAGE_HYPERLINK_DOCUMENT);
138 0 : Size aSize(pBox->get_preferred_size());
139 0 : aMaxPrefSize.Width() = std::max(aMaxPrefSize.Width(), aSize.Width());
140 0 : aMaxPrefSize.Height() = std::max(aMaxPrefSize.Height(), aSize.Height());
141 0 : ShowPage(RID_SVXPAGE_HYPERLINK_MAIL);
142 0 : aSize = pBox->get_preferred_size();
143 0 : aMaxPrefSize.Width() = std::max(aMaxPrefSize.Width(), aSize.Width());
144 0 : aMaxPrefSize.Height() = std::max(aMaxPrefSize.Height(), aSize.Height());
145 0 : ShowPage(RID_SVXPAGE_HYPERLINK_INTERNET);
146 0 : aSize = pBox->get_preferred_size();
147 0 : aMaxPrefSize.Width() = std::max(aMaxPrefSize.Width(), aSize.Width());
148 0 : aMaxPrefSize.Height() = std::max(aMaxPrefSize.Height(), aSize.Height());
149 0 : pBox->set_width_request(aMaxPrefSize.Width());
150 0 : pBox->set_height_request(aMaxPrefSize.Height());
151 :
152 0 : SetCurPageId(RID_SVXPAGE_HYPERLINK_INTERNET);
153 :
154 : // Init Dialog
155 0 : Start (false);
156 :
157 0 : pBindings->Update( SID_READONLY_MODE );
158 :
159 0 : GetOKButton().SetClickHdl ( LINK ( this, SvxHpLinkDlg, ClickOkHdl_Impl ) );
160 0 : GetApplyButton().SetClickHdl ( LINK ( this, SvxHpLinkDlg, ClickApplyHdl_Impl ) );
161 0 : GetCancelButton().SetClickHdl( LINK ( this, SvxHpLinkDlg, ClickCloseHdl_Impl ) );
162 0 : }
163 :
164 0 : SvxHpLinkDlg::~SvxHpLinkDlg ()
165 : {
166 0 : disposeOnce();
167 0 : }
168 :
169 0 : void SvxHpLinkDlg::dispose()
170 : {
171 : // delete config item, so the base class (IconChoiceDialog) can not load it on the next start
172 0 : SvtViewOptions aViewOpt( E_TABDIALOG, OUString::number(SID_HYPERLINK_DIALOG) );
173 0 : aViewOpt.Delete();
174 :
175 0 : delete mpItemSet;
176 0 : mpItemSet = NULL;
177 :
178 0 : maCtrl.dispose();
179 :
180 0 : IconChoiceDialog::dispose();
181 0 : }
182 :
183 : /*************************************************************************
184 : |*
185 : |* Close Dialog-Window
186 : |*
187 : |************************************************************************/
188 :
189 0 : bool SvxHpLinkDlg::Close()
190 : {
191 : GetDispatcher()->Execute( SID_HYPERLINK_DIALOG,
192 : SfxCallMode::ASYNCHRON |
193 0 : SfxCallMode::RECORD);
194 0 : return true;
195 : }
196 :
197 0 : void SvxHpLinkDlg::Apply()
198 : {
199 0 : SfxItemSet aItemSet( SfxGetpApp()->GetPool(), SID_HYPERLINK_GETLINK,
200 0 : SID_HYPERLINK_SETLINK );
201 :
202 : SvxHyperlinkTabPageBase* pCurrentPage = static_cast<SvxHyperlinkTabPageBase*>(
203 0 : GetTabPage( GetCurPageId() ) );
204 :
205 0 : if ( pCurrentPage->AskApply() )
206 : {
207 0 : pCurrentPage->FillItemSet( &aItemSet );
208 :
209 : const SvxHyperlinkItem *aItem = static_cast<const SvxHyperlinkItem *>(
210 0 : aItemSet.GetItem (SID_HYPERLINK_SETLINK));
211 0 : OUString aStrEmpty;
212 0 : if ( aItem->GetURL() != aStrEmpty )
213 : GetDispatcher()->Execute( SID_HYPERLINK_SETLINK, SfxCallMode::ASYNCHRON |
214 0 : SfxCallMode::RECORD, aItem, 0L);
215 :
216 0 : static_cast<SvxHyperlinkTabPageBase*>( GetTabPage( GetCurPageId() ) )->DoApply();
217 0 : }
218 0 : }
219 :
220 : /*************************************************************************
221 : |*
222 : |* When extra window is visible and its never moved by user, then move that
223 : |* window, too.
224 : |*
225 : |************************************************************************/
226 :
227 0 : void SvxHpLinkDlg::Move()
228 : {
229 : SvxHyperlinkTabPageBase* pCurrentPage = static_cast<SvxHyperlinkTabPageBase*>(
230 0 : GetTabPage ( GetCurPageId() ) );
231 :
232 0 : if( pCurrentPage->IsMarkWndVisible () )
233 : {
234 : // Pos&Size of this dialog-window
235 0 : Point aDlgPos ( GetPosPixel () );
236 0 : Size aDlgSize ( GetSizePixel () );
237 :
238 : // Size of Office-Main-Window
239 0 : Size aWindowSize( SfxGetpApp()->GetTopWindow()->GetSizePixel() );
240 :
241 : // Size of Extrawindow
242 0 : Size aExtraWndSize( pCurrentPage->GetSizeExtraWnd() );
243 :
244 : bool bDoInvalid ;
245 0 : if( aDlgPos.X()+(1.02*aDlgSize.Width())+aExtraWndSize.Width() > aWindowSize.Width() )
246 : {
247 0 : if( aDlgPos.X() - ( 0.02*aDlgSize.Width() ) - aExtraWndSize.Width() < 0 )
248 : {
249 : // Pos Extrawindow anywhere
250 0 : bDoInvalid = pCurrentPage->MoveToExtraWnd( Point( 1, long(1.1*aDlgPos.Y()) ), true );
251 : }
252 : else
253 : {
254 : // Pos Extrawindow on the left side of Dialog
255 0 : bDoInvalid = pCurrentPage->MoveToExtraWnd( aDlgPos -
256 0 : Point( long(0.02*aDlgSize.Width()), 0 ) -
257 0 : Point( aExtraWndSize.Width(), 0 ) );
258 : }
259 : }
260 : else
261 : {
262 : // Pos Extrawindow on the right side of Dialog
263 0 : bDoInvalid = pCurrentPage->MoveToExtraWnd ( aDlgPos + Point( long(1.02*aDlgSize.Width()), 0 ) );
264 : }
265 :
266 0 : if ( bDoInvalid )
267 0 : Invalidate(InvalidateFlags::Transparent);
268 : }
269 :
270 0 : Window::Move();
271 0 : }
272 :
273 : /// Click on OK button
274 0 : IMPL_LINK_NOARG(SvxHpLinkDlg, ClickOkHdl_Impl)
275 : {
276 0 : Apply();
277 0 : Close();
278 :
279 0 : return 0L;
280 : }
281 :
282 : /*************************************************************************
283 : |*
284 : |* Click on Apply-button
285 : |*
286 : |************************************************************************/
287 :
288 0 : IMPL_LINK_NOARG(SvxHpLinkDlg, ClickApplyHdl_Impl)
289 : {
290 0 : Apply();
291 :
292 0 : return 0L;
293 : }
294 :
295 : /*************************************************************************
296 : |*
297 : |* Click on Close-button
298 : |*
299 : |************************************************************************/
300 :
301 0 : IMPL_LINK_NOARG(SvxHpLinkDlg, ClickCloseHdl_Impl)
302 : {
303 0 : Close();
304 :
305 0 : return 0L;
306 : }
307 :
308 : /*************************************************************************
309 : |*
310 : |* Set Page
311 : |*
312 : |************************************************************************/
313 :
314 0 : sal_uInt16 SvxHpLinkDlg::SetPage ( SvxHyperlinkItem* pItem )
315 : {
316 0 : sal_uInt16 nPageId = RID_SVXPAGE_HYPERLINK_INTERNET;
317 :
318 0 : OUString aStrURL(pItem->GetURL());
319 0 : INetURLObject aURL(aStrURL);
320 0 : INetProtocol eProtocolTyp = aURL.GetProtocol();
321 :
322 0 : switch ( eProtocolTyp )
323 : {
324 : case INetProtocol::Http :
325 : case INetProtocol::Ftp :
326 0 : nPageId = RID_SVXPAGE_HYPERLINK_INTERNET;
327 0 : break;
328 : case INetProtocol::File :
329 0 : nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
330 0 : break;
331 : case INetProtocol::Mailto :
332 0 : nPageId = RID_SVXPAGE_HYPERLINK_MAIL;
333 0 : break;
334 : default :
335 0 : if (aStrURL.startsWith("#"))
336 0 : nPageId = RID_SVXPAGE_HYPERLINK_DOCUMENT;
337 : else
338 : {
339 0 : eProtocolTyp = INetProtocol::NotValid;
340 0 : nPageId = GetCurPageId();
341 : }
342 0 : break;
343 : }
344 :
345 0 : ShowPage (nPageId);
346 :
347 0 : SvxHyperlinkTabPageBase* pCurrentPage = static_cast<SvxHyperlinkTabPageBase*>(GetTabPage( nPageId ));
348 :
349 0 : mbIsHTMLDoc = (pItem->GetInsertMode() & HLINK_HTMLMODE) != 0;
350 :
351 0 : IconChoicePage* pPage = GetTabPage (nPageId);
352 0 : if(pPage)
353 : {
354 0 : SfxItemSet& aPageSet = (SfxItemSet&)pPage->GetItemSet ();
355 0 : aPageSet.Put ( *pItem );
356 :
357 0 : pCurrentPage->Reset( aPageSet );
358 0 : if ( mbGrabFocus )
359 : {
360 0 : pCurrentPage->SetInitFocus(); // #92535# grab the focus only once at initialization
361 0 : mbGrabFocus = false;
362 : }
363 : }
364 0 : return nPageId;
365 : }
366 :
367 : /*************************************************************************
368 : |*
369 : |* Enable/Disable ReadOnly mode
370 : |*
371 : |************************************************************************/
372 :
373 0 : void SvxHpLinkDlg::SetReadOnlyMode( bool bRdOnly )
374 : {
375 0 : mbReadOnly = bRdOnly;
376 0 : if ( bRdOnly )
377 0 : GetOKButton().Disable();
378 : else
379 0 : GetOKButton().Enable();
380 0 : }
381 :
382 : /*************************************************************************
383 : |*
384 : |* late-initialization of newly created pages
385 : |*
386 : |************************************************************************/
387 :
388 0 : void SvxHpLinkDlg::PageCreated( sal_uInt16 /*nId*/, IconChoicePage& rPage )
389 : {
390 0 : SvxHyperlinkTabPageBase& rHyperlinkPage = dynamic_cast< SvxHyperlinkTabPageBase& >( rPage );
391 0 : Reference< XFrame > xDocumentFrame;
392 0 : if ( mpBindings )
393 0 : xDocumentFrame = mpBindings->GetActiveFrame();
394 : OSL_ENSURE( xDocumentFrame.is(), "SvxHpLinkDlg::PageCreated: macro assignment functionality won't work with a proper frame!" );
395 0 : rHyperlinkPage.SetDocumentFrame( xDocumentFrame );
396 0 : }
397 :
398 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|