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

Generated by: LCOV version 1.10