LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/cui/source/dialogs - hlmarkwn.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 182 0.0 %
Date: 2013-07-09 Functions: 0 23 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/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/Desktop.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/helper/vclunohelper.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 :     OUString aUStrURL;
     212             : 
     213           0 :     EnterWait();
     214             : 
     215           0 :     ClearTree();
     216             : 
     217           0 :     xub_StrLen nPos = aStrURL.Search ( sal_Unicode('#') );
     218             : 
     219           0 :     if( nPos != 0 )
     220           0 :         aUStrURL = OUString( aStrURL );
     221             : 
     222           0 :     if( !RefreshFromDoc ( aUStrURL ) )
     223           0 :         maLbTree.Invalidate();
     224             : 
     225           0 :     if ( nPos != STRING_NOTFOUND )
     226             :     {
     227           0 :         String aStrMark = aStrURL.Copy ( nPos+1 );
     228           0 :         SelectEntry ( aStrMark );
     229             :     }
     230             : 
     231           0 :     LeaveWait();
     232             : 
     233           0 :     maStrLastURL = aStrURL;
     234           0 : }
     235             : 
     236             : /*************************************************************************
     237             : |*
     238             : |* get links from document
     239             : |*
     240             : |************************************************************************/
     241             : 
     242           0 : sal_Bool SvxHlinkDlgMarkWnd::RefreshFromDoc( OUString aURL )
     243             : {
     244           0 :     mnError = LERR_NOERROR;
     245             : 
     246           0 :     uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
     247           0 :     uno::Reference< lang::XComponent > xComp;
     248             : 
     249           0 :     if( !aURL.isEmpty() )
     250             :     {
     251             :         // load from url
     252           0 :         uno::Reference< frame::XComponentLoader > xLoader( xDesktop, uno::UNO_QUERY );
     253           0 :         if( xLoader.is() )
     254             :         {
     255             :             try
     256             :             {
     257           0 :                 uno::Sequence< beans::PropertyValue > aArg(1);
     258           0 :                 aArg.getArray()[0].Name = OUString( "Hidden" );
     259           0 :                 aArg.getArray()[0].Value <<= (sal_Bool) sal_True;
     260           0 :                 xComp = xLoader->loadComponentFromURL( aURL, OUString( "_blank" ), 0, aArg );
     261             :             }
     262           0 :             catch( const io::IOException& )
     263             :             {
     264             : 
     265             :             }
     266           0 :             catch( const lang::IllegalArgumentException& )
     267             :             {
     268             : 
     269             :             }
     270           0 :         }
     271             :     }
     272             :     else
     273             :     {
     274             :         // the component with user focus ( current document )
     275           0 :         xComp = xDesktop->getCurrentComponent();
     276             :     }
     277             : 
     278           0 :     if( xComp.is() )
     279             :     {
     280           0 :         uno::Reference< document::XLinkTargetSupplier > xLTS( xComp, uno::UNO_QUERY );
     281             : 
     282           0 :         if( xLTS.is() )
     283             :         {
     284           0 :             if( FillTree( xLTS->getLinks() ) == 0 )
     285           0 :                 mnError = LERR_NOENTRIES;
     286             :         }
     287             :         else
     288           0 :             mnError = LERR_DOCNOTOPEN;
     289             : 
     290           0 :         if ( !aURL.isEmpty() )
     291           0 :             xComp->dispose();
     292             :     }
     293             :     else
     294             :     {
     295           0 :         if( !aURL.isEmpty() )
     296           0 :             mnError=LERR_DOCNOTOPEN;
     297             :     }
     298           0 :     return (mnError==0);
     299             : }
     300             : /*************************************************************************
     301             : |*
     302             : |* Fill Tree-Control
     303             : |*
     304             : |************************************************************************/
     305             : 
     306           0 : int SvxHlinkDlgMarkWnd::FillTree( uno::Reference< container::XNameAccess > xLinks, SvTreeListEntry* pParentEntry )
     307             : {
     308           0 :     int nEntries=0;
     309           0 :     const uno::Sequence< OUString > aNames( xLinks->getElementNames() );
     310           0 :     const sal_uLong nLinks = aNames.getLength();
     311           0 :     const OUString* pNames = aNames.getConstArray();
     312             : 
     313           0 :     Color aMaskColor( COL_LIGHTMAGENTA );
     314           0 :     const OUString aProp_LinkDisplayName( "LinkDisplayName" );
     315           0 :     const OUString aProp_LinkTarget( "com.sun.star.document.LinkTarget" );
     316           0 :     const OUString aProp_LinkDisplayBitmap( "LinkDisplayBitmap" );
     317           0 :     for( sal_uLong i = 0; i < nLinks; i++ )
     318             :     {
     319           0 :         uno::Any aAny;
     320           0 :         OUString aLink( *pNames++ );
     321             : 
     322           0 :         sal_Bool bError = sal_False;
     323             :         try
     324             :         {
     325           0 :             aAny = xLinks->getByName( aLink );
     326             :         }
     327           0 :         catch(const uno::Exception&)
     328             :         {
     329             :             // if the name of the target was invalid (like empty headings)
     330             :             // no object can be provided
     331           0 :             bError = sal_True;
     332             :         }
     333           0 :         if(bError)
     334           0 :             continue;
     335             : 
     336           0 :         uno::Reference< beans::XPropertySet > xTarget;
     337             : 
     338           0 :         if( aAny >>= xTarget )
     339             :         {
     340             :             try
     341             :             {
     342             :                 // get name to display
     343           0 :                 aAny = xTarget->getPropertyValue( aProp_LinkDisplayName );
     344           0 :                 OUString aDisplayName;
     345           0 :                 aAny >>= aDisplayName;
     346           0 :                 String aStrDisplayname ( aDisplayName );
     347             : 
     348             :                 // is it a target ?
     349           0 :                 uno::Reference< lang::XServiceInfo > xSI( xTarget, uno::UNO_QUERY );
     350           0 :                 sal_Bool bIsTarget = xSI->supportsService( aProp_LinkTarget );
     351             : 
     352             :                 // create userdata
     353           0 :                 TargetData *pData = new TargetData ( aLink, bIsTarget );
     354             : 
     355             :                 SvTreeListEntry* pEntry;
     356             : 
     357             :                 try
     358             :                 {
     359             :                     // get bitmap for the tree-entry
     360           0 :                     uno::Reference< awt::XBitmap > aXBitmap( xTarget->getPropertyValue( aProp_LinkDisplayBitmap ), uno::UNO_QUERY );
     361           0 :                     if( aXBitmap.is() )
     362             :                     {
     363           0 :                         Image aBmp( VCLUnoHelper::GetBitmap( aXBitmap ).GetBitmap(), aMaskColor );
     364             :                         // insert Displayname into treelist with bitmaps
     365             :                         pEntry = maLbTree.InsertEntry ( aStrDisplayname,
     366             :                                                         aBmp, aBmp,
     367             :                                                         pParentEntry,
     368             :                                                         sal_False, LIST_APPEND,
     369           0 :                                                         (void*)pData );
     370           0 :                         nEntries++;
     371             :                     }
     372             :                     else
     373             :                     {
     374             :                         // insert Displayname into treelist without bitmaps
     375             :                         pEntry = maLbTree.InsertEntry ( aStrDisplayname,
     376             :                                                         pParentEntry,
     377             :                                                         sal_False, LIST_APPEND,
     378           0 :                                                         (void*)pData );
     379           0 :                         nEntries++;
     380           0 :                     }
     381             :                 }
     382           0 :                 catch(const com::sun::star::uno::Exception&)
     383             :                 {
     384             :                     // insert Displayname into treelist without bitmaps
     385             :                     pEntry = maLbTree.InsertEntry ( aStrDisplayname,
     386             :                                                     pParentEntry,
     387             :                                                     sal_False, LIST_APPEND,
     388           0 :                                                     (void*)pData );
     389           0 :                     nEntries++;
     390             :                 }
     391             : 
     392           0 :                 uno::Reference< document::XLinkTargetSupplier > xLTS( xTarget, uno::UNO_QUERY );
     393           0 :                 if( xLTS.is() )
     394           0 :                     nEntries += FillTree( xLTS->getLinks(), pEntry );
     395             :             }
     396           0 :             catch(const com::sun::star::uno::Exception&)
     397             :             {
     398             :             }
     399             :         }
     400           0 :     }
     401             : 
     402           0 :     return nEntries;
     403             : }
     404             : 
     405             : /*************************************************************************
     406             : |*
     407             : |* Clear Tree
     408             : |*
     409             : |************************************************************************/
     410             : 
     411           0 : void SvxHlinkDlgMarkWnd::ClearTree()
     412             : {
     413           0 :     SvTreeListEntry* pEntry = maLbTree.First();
     414             : 
     415           0 :     while ( pEntry )
     416             :     {
     417           0 :         TargetData* pUserData = ( TargetData * ) pEntry->GetUserData();
     418           0 :         delete pUserData;
     419             : 
     420           0 :         pEntry = maLbTree.Next( pEntry );
     421             :     }
     422             : 
     423           0 :     maLbTree.Clear();
     424           0 : }
     425             : 
     426             : /*************************************************************************
     427             : |*
     428             : |* Find Entry for Strng
     429             : |*
     430             : |************************************************************************/
     431             : 
     432           0 : SvTreeListEntry* SvxHlinkDlgMarkWnd::FindEntry ( String aStrName )
     433             : {
     434           0 :     sal_Bool bFound=sal_False;
     435           0 :     SvTreeListEntry* pEntry = maLbTree.First();
     436             : 
     437           0 :     while ( pEntry && !bFound )
     438             :     {
     439           0 :         TargetData* pUserData = ( TargetData * ) pEntry->GetUserData ();
     440           0 :         if ( aStrName == String( pUserData->aUStrLinkname ) )
     441           0 :             bFound = sal_True;
     442             :         else
     443           0 :             pEntry = maLbTree.Next( pEntry );
     444             :     }
     445             : 
     446           0 :     return pEntry;
     447             : }
     448             : 
     449             : /*************************************************************************
     450             : |*
     451             : |* Select Entry
     452             : |*
     453             : |************************************************************************/
     454             : 
     455           0 : void SvxHlinkDlgMarkWnd::SelectEntry ( String aStrMark )
     456             : {
     457           0 :     SvTreeListEntry* pEntry = FindEntry ( aStrMark );
     458           0 :     if ( pEntry )
     459             :     {
     460           0 :         maLbTree.Select ( pEntry );
     461           0 :         maLbTree.MakeVisible ( pEntry );
     462             :     }
     463           0 : }
     464             : 
     465             : /*************************************************************************
     466             : |*
     467             : |* Click on Apply-Button / Doubleclick on item in tree
     468             : |*
     469             : |************************************************************************/
     470             : 
     471           0 : IMPL_LINK_NOARG(SvxHlinkDlgMarkWnd, ClickApplyHdl_Impl)
     472             : {
     473           0 :     SvTreeListEntry* pEntry = maLbTree.GetCurEntry();
     474             : 
     475           0 :     if ( pEntry )
     476             :     {
     477           0 :         TargetData *pData = ( TargetData * )pEntry->GetUserData();
     478             : 
     479           0 :         if ( pData->bIsTarget )
     480             :         {
     481           0 :             String aStrMark ( pData->aUStrLinkname );
     482           0 :             mpParent->SetMarkStr ( aStrMark );
     483             :         }
     484             :     }
     485             : 
     486           0 :     return( 0L );
     487             : }
     488             : 
     489             : /*************************************************************************
     490             : |*
     491             : |* Click on Close-Button
     492             : |*
     493             : |************************************************************************/
     494             : 
     495           0 : IMPL_LINK_NOARG(SvxHlinkDlgMarkWnd, ClickCloseHdl_Impl)
     496             : {
     497           0 :     Close();
     498             : 
     499           0 :     return( 0L );
     500           0 : }
     501             : 
     502             : 
     503             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10