LCOV - code coverage report
Current view: top level - libreoffice/cui/source/dialogs - hlmarkwn.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 189 0.5 %
Date: 2012-12-17 Functions: 2 23 8.7 %
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/wrkwin.hxx>
      21             : #include <dialmgr.hxx>
      22             : #include <sfx2/docfile.hxx>
      23             : #include <vcl/svapp.hxx>
      24             : #include <vcl/settings.hxx>
      25             : 
      26             : // UNO-Stuff
      27             : #include <comphelper/processfactory.hxx>
      28             : #include <com/sun/star/awt/XBitmap.hpp>
      29             : #include <com/sun/star/frame/XDesktop.hpp>
      30             : #include <com/sun/star/frame/XComponentLoader.hpp>
      31             : #include <com/sun/star/beans/PropertyValue.hpp>
      32             : #include <com/sun/star/document/XLinkTargetSupplier.hpp>
      33             : #include <com/sun/star/beans/XPropertySet.hpp>
      34             : 
      35             : #include <toolkit/unohlp.hxx>
      36             : #include "svtools/treelistentry.hxx"
      37             : 
      38             : #include <cuires.hrc>
      39             : #include "hlmarkwn.hrc"
      40             : #include "hlmarkwn.hxx"
      41             : #include "hltpbase.hxx"
      42             : 
      43             : using namespace ::com::sun::star;
      44             : using namespace ::rtl;
      45             : 
      46             : /*************************************************************************
      47             : |*
      48             : |* Userdata-struct for tree-entries
      49             : |*
      50             : |************************************************************************/
      51             : 
      52           0 : struct TargetData
      53             : {
      54             :     OUString        aUStrLinkname;
      55             :     sal_Bool        bIsTarget;
      56             : 
      57           0 :     TargetData ( OUString aUStrLName, sal_Bool bTarget )
      58           0 :         :   bIsTarget ( bTarget )
      59             :     {
      60           0 :         if ( bIsTarget )
      61           0 :             aUStrLinkname = aUStrLName;
      62           0 :     }
      63             : };
      64             : 
      65             : 
      66             : //########################################################################
      67             : //#                                                                      #
      68             : //# Tree-Window                                                          #
      69             : //#                                                                      #
      70             : //########################################################################
      71             : 
      72           0 : SvxHlmarkTreeLBox::SvxHlmarkTreeLBox( Window* pParent, const ResId& rResId )
      73             : : SvTreeListBox ( pParent, rResId ),
      74           0 :   mpParentWnd   ( (SvxHlinkDlgMarkWnd*) pParent )
      75             : {
      76           0 :     SetNodeDefaultImages();
      77           0 : }
      78             : 
      79           0 : void SvxHlmarkTreeLBox::Paint( const Rectangle& rRect )
      80             : {
      81           0 :     if( mpParentWnd->mnError == LERR_NOERROR )
      82             :     {
      83           0 :         SvTreeListBox::Paint(rRect);
      84             :     }
      85             :     else
      86             :     {
      87           0 :         Erase();
      88             : 
      89           0 :         Rectangle aDrawRect( Point( 0, 0 ), GetSizePixel() );
      90             : 
      91           0 :         String aStrMessage;
      92             : 
      93           0 :         switch( mpParentWnd->mnError )
      94             :         {
      95             :         case LERR_NOENTRIES :
      96           0 :             aStrMessage = CUI_RESSTR( RID_SVXSTR_HYPDLG_ERR_LERR_NOENTRIES );
      97           0 :             break;
      98             :         case LERR_DOCNOTOPEN :
      99           0 :             aStrMessage = CUI_RESSTR( RID_SVXSTR_HYPDLG_ERR_LERR_DOCNOTOPEN );
     100           0 :             break;
     101             :         }
     102             : 
     103           0 :         DrawText( aDrawRect, aStrMessage, TEXT_DRAW_LEFT | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
     104             :     }
     105             : 
     106           0 : }
     107             : 
     108             : //########################################################################
     109             : //#                                                                      #
     110             : //# Window-Class                                                         #
     111             : //#                                                                      #
     112             : //########################################################################
     113             : 
     114             : /*************************************************************************
     115             : |*
     116             : |* Contructor / Destructor
     117             : |*
     118             : |************************************************************************/
     119             : 
     120           0 : SvxHlinkDlgMarkWnd::SvxHlinkDlgMarkWnd( SvxHyperlinkTabPageBase *pParent )
     121           0 : :   ModalDialog( (Window*)pParent, CUI_RES ( RID_SVXFLOAT_HYPERLINK_MARKWND ) ),
     122           0 :     maBtApply( this, CUI_RES (BT_APPLY) ),
     123           0 :     maBtClose( this, CUI_RES (BT_CLOSE) ),
     124           0 :     maLbTree ( this, CUI_RES (TLB_MARK) ),
     125             :     mbUserMoved ( sal_False ),
     126             :     mpParent    ( pParent ),
     127           0 :     mnError     ( LERR_NOERROR )
     128             : {
     129           0 :     FreeResource();
     130             : 
     131           0 :     maBtApply.SetClickHdl       ( LINK ( this, SvxHlinkDlgMarkWnd, ClickApplyHdl_Impl ) );
     132           0 :     maBtClose.SetClickHdl       ( LINK ( this, SvxHlinkDlgMarkWnd, ClickCloseHdl_Impl ) );
     133           0 :     maLbTree.SetDoubleClickHdl  ( LINK ( this, SvxHlinkDlgMarkWnd, ClickApplyHdl_Impl ) );
     134             : 
     135             :     // add lines to the Tree-ListBox
     136           0 :     maLbTree.SetStyle( maLbTree.GetStyle() | WB_TABSTOP | WB_BORDER | WB_HASLINES |
     137             :                             WB_HASBUTTONS |  //WB_HASLINESATROOT |
     138           0 :                             WB_HSCROLL | WB_HASBUTTONSATROOT );
     139             : 
     140           0 :     maLbTree.SetAccessibleName(String(CUI_RES(STR_MARK_TREE)));
     141             : 
     142           0 : }
     143             : 
     144           0 : SvxHlinkDlgMarkWnd::~SvxHlinkDlgMarkWnd()
     145             : {
     146           0 :     ClearTree();
     147           0 : }
     148             : 
     149             : /*************************************************************************
     150             : |*
     151             : |* Set an errorstatus
     152             : |*
     153             : |************************************************************************/
     154             : 
     155           0 : sal_uInt16 SvxHlinkDlgMarkWnd::SetError( sal_uInt16 nError)
     156             : {
     157           0 :     sal_uInt16 nOldError = mnError;
     158           0 :     mnError = nError;
     159             : 
     160           0 :     if( mnError != LERR_NOERROR )
     161           0 :         ClearTree();
     162             : 
     163           0 :     maLbTree.Invalidate();
     164             : 
     165           0 :     return nOldError;
     166             : }
     167             : 
     168             : /*************************************************************************
     169             : |*
     170             : |* Move window
     171             : |*
     172             : |************************************************************************/
     173             : 
     174           0 : sal_Bool SvxHlinkDlgMarkWnd::MoveTo ( Point aNewPos )
     175             : {
     176           0 :     if ( !mbUserMoved )
     177             :     {
     178           0 :         sal_Bool bOldStatus = mbUserMoved;
     179           0 :         SetPosPixel ( aNewPos );
     180           0 :         mbUserMoved = bOldStatus;
     181             :     }
     182             : 
     183           0 :     return mbUserMoved;
     184             : }
     185             : 
     186           0 : void SvxHlinkDlgMarkWnd::Move ()
     187             : {
     188           0 :     Window::Move();
     189             : 
     190           0 :     if ( IsReallyVisible() )
     191           0 :         mbUserMoved = sal_True;
     192           0 : }
     193             : 
     194           0 : sal_Bool SvxHlinkDlgMarkWnd::ConnectToDialog( sal_Bool bDoit )
     195             : {
     196           0 :     sal_Bool bOldStatus = mbUserMoved;
     197             : 
     198           0 :     mbUserMoved = !bDoit;
     199             : 
     200           0 :     return bOldStatus;
     201             : }
     202             : 
     203             : /*************************************************************************
     204             : |*
     205             : |* Interface to refresh tree
     206             : |*
     207             : |************************************************************************/
     208             : 
     209           0 : void SvxHlinkDlgMarkWnd::RefreshTree ( String aStrURL )
     210             : {
     211           0 :     String aEmptyStr;
     212           0 :     OUString aUStrURL;
     213             : 
     214           0 :     EnterWait();
     215             : 
     216           0 :     ClearTree();
     217             : 
     218           0 :     xub_StrLen nPos = aStrURL.Search ( sal_Unicode('#') );
     219             : 
     220           0 :     if( nPos != 0 )
     221           0 :         aUStrURL = ::rtl::OUString( aStrURL );
     222             : 
     223           0 :     if( !RefreshFromDoc ( aUStrURL ) )
     224           0 :         maLbTree.Invalidate();
     225             : 
     226           0 :     if ( nPos != STRING_NOTFOUND )
     227             :     {
     228           0 :         String aStrMark = aStrURL.Copy ( nPos+1 );
     229           0 :         SelectEntry ( aStrMark );
     230             :     }
     231             : 
     232           0 :     LeaveWait();
     233             : 
     234           0 :     maStrLastURL = aStrURL;
     235           0 : }
     236             : 
     237             : /*************************************************************************
     238             : |*
     239             : |* get links from document
     240             : |*
     241             : |************************************************************************/
     242             : 
     243           0 : sal_Bool SvxHlinkDlgMarkWnd::RefreshFromDoc( OUString aURL )
     244             : {
     245           0 :     mnError = LERR_NOERROR;
     246             : 
     247           0 :     uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
     248           0 :     if( xFactory.is() )
     249             :     {
     250           0 :         uno::Reference< frame::XDesktop > xDesktop( xFactory->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" )) ),
     251           0 :                     uno::UNO_QUERY );
     252           0 :         if( xDesktop.is() )
     253             :         {
     254           0 :             uno::Reference< lang::XComponent > xComp;
     255             : 
     256           0 :             if( !aURL.isEmpty() )
     257             :             {
     258             :                 // load from url
     259           0 :                 uno::Reference< frame::XComponentLoader > xLoader( xDesktop, uno::UNO_QUERY );
     260           0 :                 if( xLoader.is() )
     261             :                 {
     262             :                     try
     263             :                     {
     264           0 :                         uno::Sequence< beans::PropertyValue > aArg(1);
     265           0 :                         aArg.getArray()[0].Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "Hidden" ));
     266           0 :                         aArg.getArray()[0].Value <<= (sal_Bool) sal_True;
     267           0 :                         xComp = xLoader->loadComponentFromURL( aURL, OUString(RTL_CONSTASCII_USTRINGPARAM( "_blank" )), 0, aArg );
     268             :                     }
     269           0 :                     catch( const io::IOException& )
     270             :                     {
     271             : 
     272             :                     }
     273           0 :                     catch( const lang::IllegalArgumentException& )
     274             :                     {
     275             : 
     276             :                     }
     277           0 :                 }
     278             :             }
     279             :             else
     280             :             {
     281             :                 // the component with user focus ( current document )
     282           0 :                 xComp = xDesktop->getCurrentComponent();
     283             :             }
     284             : 
     285           0 :             if( xComp.is() )
     286             :             {
     287           0 :                 uno::Reference< document::XLinkTargetSupplier > xLTS( xComp, uno::UNO_QUERY );
     288             : 
     289           0 :                 if( xLTS.is() )
     290             :                 {
     291           0 :                     if( FillTree( xLTS->getLinks() ) == 0 )
     292           0 :                         mnError = LERR_NOENTRIES;
     293             :                 }
     294             :                 else
     295           0 :                     mnError = LERR_DOCNOTOPEN;
     296             : 
     297           0 :                 if ( !aURL.isEmpty() )
     298           0 :                     xComp->dispose();
     299             :             }
     300             :             else
     301             :             {
     302           0 :                 if( !aURL.isEmpty() )
     303           0 :                     mnError=LERR_DOCNOTOPEN;
     304           0 :             }
     305           0 :         }
     306             :     }
     307           0 :     return (mnError==0);
     308             : }
     309             : /*************************************************************************
     310             : |*
     311             : |* Fill Tree-Control
     312             : |*
     313             : |************************************************************************/
     314             : 
     315           0 : int SvxHlinkDlgMarkWnd::FillTree( uno::Reference< container::XNameAccess > xLinks, SvTreeListEntry* pParentEntry )
     316             : {
     317           0 :     int nEntries=0;
     318           0 :     const uno::Sequence< OUString > aNames( xLinks->getElementNames() );
     319           0 :     const sal_uLong nLinks = aNames.getLength();
     320           0 :     const OUString* pNames = aNames.getConstArray();
     321             : 
     322           0 :     Color aMaskColor( COL_LIGHTMAGENTA );
     323           0 :     const OUString aProp_LinkDisplayName( RTL_CONSTASCII_USTRINGPARAM( "LinkDisplayName" ) );
     324           0 :     const OUString aProp_LinkTarget( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.LinkTarget" ) );
     325           0 :     const OUString aProp_LinkDisplayBitmap( RTL_CONSTASCII_USTRINGPARAM( "LinkDisplayBitmap" ) );
     326           0 :     for( sal_uLong i = 0; i < nLinks; i++ )
     327             :     {
     328           0 :         uno::Any aAny;
     329           0 :         OUString aLink( *pNames++ );
     330             : 
     331           0 :         sal_Bool bError = sal_False;
     332             :         try
     333             :         {
     334           0 :             aAny = xLinks->getByName( aLink );
     335             :         }
     336           0 :         catch(const uno::Exception&)
     337             :         {
     338             :             // if the name of the target was invalid (like empty headings)
     339             :             // no object can be provided
     340           0 :             bError = sal_True;
     341             :         }
     342           0 :         if(bError)
     343           0 :             continue;
     344             : 
     345           0 :         uno::Reference< beans::XPropertySet > xTarget;
     346             : 
     347           0 :         if( aAny >>= xTarget )
     348             :         {
     349             :             try
     350             :             {
     351             :                 // get name to display
     352           0 :                 aAny = xTarget->getPropertyValue( aProp_LinkDisplayName );
     353           0 :                 OUString aDisplayName;
     354           0 :                 aAny >>= aDisplayName;
     355           0 :                 String aStrDisplayname ( aDisplayName );
     356             : 
     357             :                 // is it a target ?
     358           0 :                 uno::Reference< lang::XServiceInfo > xSI( xTarget, uno::UNO_QUERY );
     359           0 :                 sal_Bool bIsTarget = xSI->supportsService( aProp_LinkTarget );
     360             : 
     361             :                 // create userdata
     362           0 :                 TargetData *pData = new TargetData ( aLink, bIsTarget );
     363             : 
     364             :                 SvTreeListEntry* pEntry;
     365             : 
     366             :                 try
     367             :                 {
     368             :                     // get bitmap for the tree-entry
     369           0 :                     uno::Reference< awt::XBitmap > aXBitmap( xTarget->getPropertyValue( aProp_LinkDisplayBitmap ), uno::UNO_QUERY );
     370           0 :                     if( aXBitmap.is() )
     371             :                     {
     372           0 :                         Image aBmp( VCLUnoHelper::GetBitmap( aXBitmap ).GetBitmap(), aMaskColor );
     373             :                         // insert Displayname into treelist with bitmaps
     374             :                         pEntry = maLbTree.InsertEntry ( aStrDisplayname,
     375             :                                                         aBmp, aBmp,
     376             :                                                         pParentEntry,
     377             :                                                         sal_False, LIST_APPEND,
     378           0 :                                                         (void*)pData );
     379           0 :                         nEntries++;
     380             :                     }
     381             :                     else
     382             :                     {
     383             :                         // insert Displayname into treelist without bitmaps
     384             :                         pEntry = maLbTree.InsertEntry ( aStrDisplayname,
     385             :                                                         pParentEntry,
     386             :                                                         sal_False, LIST_APPEND,
     387           0 :                                                         (void*)pData );
     388           0 :                         nEntries++;
     389           0 :                     }
     390             :                 }
     391           0 :                 catch(const com::sun::star::uno::Exception&)
     392             :                 {
     393             :                     // insert Displayname into treelist without bitmaps
     394             :                     pEntry = maLbTree.InsertEntry ( aStrDisplayname,
     395             :                                                     pParentEntry,
     396             :                                                     sal_False, LIST_APPEND,
     397           0 :                                                     (void*)pData );
     398           0 :                     nEntries++;
     399             :                 }
     400             : 
     401           0 :                 uno::Reference< document::XLinkTargetSupplier > xLTS( xTarget, uno::UNO_QUERY );
     402           0 :                 if( xLTS.is() )
     403           0 :                     nEntries += FillTree( xLTS->getLinks(), pEntry );
     404             :             }
     405           0 :             catch(const com::sun::star::uno::Exception&)
     406             :             {
     407             :             }
     408             :         }
     409           0 :     }
     410             : 
     411           0 :     return nEntries;
     412             : }
     413             : 
     414             : /*************************************************************************
     415             : |*
     416             : |* Clear Tree
     417             : |*
     418             : |************************************************************************/
     419             : 
     420           0 : void SvxHlinkDlgMarkWnd::ClearTree()
     421             : {
     422           0 :     SvTreeListEntry* pEntry = maLbTree.First();
     423             : 
     424           0 :     while ( pEntry )
     425             :     {
     426           0 :         TargetData* pUserData = ( TargetData * ) pEntry->GetUserData();
     427           0 :         delete pUserData;
     428             : 
     429           0 :         pEntry = maLbTree.Next( pEntry );
     430             :     }
     431             : 
     432           0 :     maLbTree.Clear();
     433           0 : }
     434             : 
     435             : /*************************************************************************
     436             : |*
     437             : |* Find Entry for Strng
     438             : |*
     439             : |************************************************************************/
     440             : 
     441           0 : SvTreeListEntry* SvxHlinkDlgMarkWnd::FindEntry ( String aStrName )
     442             : {
     443           0 :     sal_Bool bFound=sal_False;
     444           0 :     SvTreeListEntry* pEntry = maLbTree.First();
     445             : 
     446           0 :     while ( pEntry && !bFound )
     447             :     {
     448           0 :         TargetData* pUserData = ( TargetData * ) pEntry->GetUserData ();
     449           0 :         if ( aStrName == String( pUserData->aUStrLinkname ) )
     450           0 :             bFound = sal_True;
     451             :         else
     452           0 :             pEntry = maLbTree.Next( pEntry );
     453             :     }
     454             : 
     455           0 :     return pEntry;
     456             : }
     457             : 
     458             : /*************************************************************************
     459             : |*
     460             : |* Select Entry
     461             : |*
     462             : |************************************************************************/
     463             : 
     464           0 : void SvxHlinkDlgMarkWnd::SelectEntry ( String aStrMark )
     465             : {
     466           0 :     SvTreeListEntry* pEntry = FindEntry ( aStrMark );
     467           0 :     if ( pEntry )
     468             :     {
     469           0 :         maLbTree.Select ( pEntry );
     470           0 :         maLbTree.MakeVisible ( pEntry );
     471             :     }
     472           0 : }
     473             : 
     474             : /*************************************************************************
     475             : |*
     476             : |* Click on Apply-Button / Doubleclick on item in tree
     477             : |*
     478             : |************************************************************************/
     479             : 
     480           0 : IMPL_LINK_NOARG(SvxHlinkDlgMarkWnd, ClickApplyHdl_Impl)
     481             : {
     482           0 :     SvTreeListEntry* pEntry = maLbTree.GetCurEntry();
     483             : 
     484           0 :     if ( pEntry )
     485             :     {
     486           0 :         TargetData *pData = ( TargetData * )pEntry->GetUserData();
     487             : 
     488           0 :         if ( pData->bIsTarget )
     489             :         {
     490           0 :             String aStrMark ( pData->aUStrLinkname );
     491           0 :             mpParent->SetMarkStr ( aStrMark );
     492             :         }
     493             :     }
     494             : 
     495           0 :     return( 0L );
     496             : }
     497             : 
     498             : /*************************************************************************
     499             : |*
     500             : |* Click on Close-Button
     501             : |*
     502             : |************************************************************************/
     503             : 
     504           0 : IMPL_LINK_NOARG(SvxHlinkDlgMarkWnd, ClickCloseHdl_Impl)
     505             : {
     506           0 :     Close();
     507             : 
     508           0 :     return( 0L );
     509           6 : }
     510             : 
     511             : 
     512             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10