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

Generated by: LCOV version 1.10