LCOV - code coverage report
Current view: top level - cui/source/dialogs - cuihyperdlg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 156 0.0 %
Date: 2014-11-03 Functions: 0 19 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10