Files
libreoffice/cui/source/dialogs/hlmarkwn.cxx

601 lines
18 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: clarify Option->Language UI option Patch contributed by Herbert Duerr http://svn.apache.org/viewvc?view=revision&revision=1173991 cws mba34issues01: #i117712#: fix several resource errors introduced by IAccessible2 implementation Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1173991 cws mba34issues01: #i117709#: add missing string resource Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1172348 cws mba34issues01: #i117716#: fix missing resources my removing unused code Patch contributed by Mathias Bauer http://svn.apache.org/viewvc?view=revision&revision=1172345 re-add Crystal, Tango, Oxygen icon theme listings. correct method signature Patch contributed by Jean-Louis 'Hans' Fuchs http://svn.apache.org/viewvc?view=revision&revision=1306725 i#119063 - correct serf integration Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1300521 i#119036 - adapt serf integration -- use transfer-encoding 'chunked' on HTTPS -- switch transfer-encoding between 'chunked' and none on 413 HTTP status code -- refactoring -- improve user experience of certification dialog - only shown once Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1299727 118569: Use whole certification chain for verification. Patch contributed by Andre Fischer http://svn.apache.org/viewvc?view=revision&revision=1295493 serf integration: improve credential input handling Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1294557 warning-free ucb/source/ucp/webdav Patch contributed by Pavel Janik http://svn.apache.org/viewvc?view=revision&revision=1294086 some refactoring to PROPPATCH and PROPFIND requests Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1293281 i#118569: Replace neon with serf Patch contributed by Oliver-Rainer Wittmann http://svn.apache.org/viewvc?view=revision&revision=1292832 http://svn.apache.org/viewvc?view=revision&revision=1292794 remove OS/2 conditionals for now. re-enable webdav unit tests.
2012-10-04 11:25:41 +01:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2009-10-31 00:36:06 +01:00
#include <dialmgr.hxx>
2009-10-31 00:36:06 +01:00
#include <sfx2/docfile.hxx>
#include <unotools/viewoptions.hxx>
2009-10-31 00:36:06 +01:00
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <vcl/wrkwin.hxx>
2009-10-31 00:36:06 +01:00
// UNO-Stuff
#include <comphelper/processfactory.hxx>
#include <comphelper/sequence.hxx>
2009-10-31 00:36:06 +01:00
#include <com/sun/star/awt/XBitmap.hpp>
#include <com/sun/star/frame/Desktop.hpp>
2009-10-31 00:36:06 +01:00
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/document/XLinkTargetSupplier.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <toolkit/helper/vclunohelper.hxx>
#include "svtools/treelistentry.hxx"
2009-10-31 00:36:06 +01:00
#include <cuires.hrc>
2009-10-31 00:36:06 +01:00
#include "hlmarkwn.hrc"
#include "hlmarkwn.hxx"
#include "hltpbase.hxx"
using namespace ::com::sun::star;
using namespace ::rtl;
/*************************************************************************
|*
|* Userdata-struct for tree-entries
|*
|************************************************************************/
struct TargetData
{
OUString aUStrLinkname;
bool bIsTarget;
2009-10-31 00:36:06 +01:00
TargetData (OUString aUStrLName, bool bTarget)
: bIsTarget(bTarget)
2009-10-31 00:36:06 +01:00
{
if (bIsTarget)
2009-10-31 00:36:06 +01:00
aUStrLinkname = aUStrLName;
}
};
//########################################################################
//# #
//# Tree-Window #
//# #
//########################################################################
SvxHlmarkTreeLBox::SvxHlmarkTreeLBox( Window* pParent, const ResId& rResId )
: SvTreeListBox ( pParent, rResId ),
mpParentWnd ( (SvxHlinkDlgMarkWnd*) pParent )
{
SetNodeDefaultImages();
}
void SvxHlmarkTreeLBox::Paint( const Rectangle& rRect )
{
if( mpParentWnd->mnError == LERR_NOERROR )
{
SvTreeListBox::Paint(rRect);
}
else
{
Erase();
Rectangle aDrawRect( Point( 0, 0 ), GetSizePixel() );
OUString aStrMessage;
2009-10-31 00:36:06 +01:00
switch( mpParentWnd->mnError )
{
case LERR_NOENTRIES :
aStrMessage = CUI_RESSTR( RID_SVXSTR_HYPDLG_ERR_LERR_NOENTRIES );
2009-10-31 00:36:06 +01:00
break;
case LERR_DOCNOTOPEN :
aStrMessage = CUI_RESSTR( RID_SVXSTR_HYPDLG_ERR_LERR_DOCNOTOPEN );
2009-10-31 00:36:06 +01:00
break;
}
DrawText( aDrawRect, aStrMessage, TEXT_DRAW_LEFT | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
}
}
//########################################################################
//# #
//# Window-Class #
//# #
//########################################################################
/*************************************************************************
|*
|* Contructor / Destructor
|*
|************************************************************************/
SvxHlinkDlgMarkWnd::SvxHlinkDlgMarkWnd( SvxHyperlinkTabPageBase *pParent )
: ModalDialog( (Window*)pParent, CUI_RES ( RID_SVXFLOAT_HYPERLINK_MARKWND ) ),
maBtOk( this, CUI_RES (BT_OK) ),
maBtClose( this, CUI_RES (BT_CLOSE) ),
maLbTree ( this, CUI_RES (TLB_MARK) ),
mbUserMoved ( sal_False ),
2009-10-31 00:36:06 +01:00
mpParent ( pParent ),
mnError ( LERR_NOERROR )
{
FreeResource();
maBtOk.SetClickHdl ( LINK ( this, SvxHlinkDlgMarkWnd, ClickOkHdl_Impl ) );
2009-10-31 00:36:06 +01:00
maBtClose.SetClickHdl ( LINK ( this, SvxHlinkDlgMarkWnd, ClickCloseHdl_Impl ) );
maLbTree.SetDoubleClickHdl ( LINK ( this, SvxHlinkDlgMarkWnd, ClickOkHdl_Impl ) );
2009-10-31 00:36:06 +01:00
// add lines to the Tree-ListBox
maLbTree.SetStyle( maLbTree.GetStyle() | WB_TABSTOP | WB_BORDER | WB_HASLINES |
2009-10-31 00:36:06 +01:00
WB_HASBUTTONS | //WB_HASLINESATROOT |
WB_HSCROLL | WB_HASBUTTONSATROOT );
maLbTree.SetAccessibleName(CUI_RES(STR_MARK_TREE));
2009-10-31 00:36:06 +01:00
}
SvxHlinkDlgMarkWnd::~SvxHlinkDlgMarkWnd()
{
ClearTree();
}
/*************************************************************************
|*
|* Set an errorstatus
|*
|************************************************************************/
sal_uInt16 SvxHlinkDlgMarkWnd::SetError( sal_uInt16 nError)
2009-10-31 00:36:06 +01:00
{
sal_uInt16 nOldError = mnError;
2009-10-31 00:36:06 +01:00
mnError = nError;
if( mnError != LERR_NOERROR )
ClearTree();
maLbTree.Invalidate();
return nOldError;
}
/*************************************************************************
|*
|* Move window
|*
|************************************************************************/
sal_Bool SvxHlinkDlgMarkWnd::MoveTo ( Point aNewPos )
2009-10-31 00:36:06 +01:00
{
if ( !mbUserMoved )
{
sal_Bool bOldStatus = mbUserMoved;
2009-10-31 00:36:06 +01:00
SetPosPixel ( aNewPos );
mbUserMoved = bOldStatus;
}
return mbUserMoved;
}
void SvxHlinkDlgMarkWnd::Move ()
{
Window::Move();
if ( IsReallyVisible() )
mbUserMoved = sal_True;
2009-10-31 00:36:06 +01:00
}
sal_Bool SvxHlinkDlgMarkWnd::ConnectToDialog( sal_Bool bDoit )
2009-10-31 00:36:06 +01:00
{
sal_Bool bOldStatus = mbUserMoved;
2009-10-31 00:36:06 +01:00
mbUserMoved = !bDoit;
return bOldStatus;
}
namespace
{
void SelectPath(SvTreeListEntry *pEntry, SvxHlmarkTreeLBox &rLbTree,
std::deque<OUString> &rLastSelectedPath)
{
OUString sTitle(rLastSelectedPath.front());
rLastSelectedPath.pop_front();
if (sTitle.isEmpty())
return;
while (pEntry)
{
if (sTitle == rLbTree.GetEntryText(pEntry))
{
rLbTree.Select(pEntry);
rLbTree.MakeVisible(pEntry);
if (!rLastSelectedPath.empty())
{
rLbTree.Expand(pEntry);
SelectPath(rLbTree.FirstChild(pEntry), rLbTree, rLastSelectedPath);
}
break;
}
pEntry = rLbTree.NextSibling(pEntry);
}
}
}
#define TG_SETTING_MANAGER "TargetInDocument"
#define TG_SETTING_LASTMARK "LastSelectedMark"
#define TG_SETTING_LASTPATH "LastSelectedPath"
void SvxHlinkDlgMarkWnd::RestoreLastSelection()
{
bool bSelectedEntry = false;
OUString sLastSelectedMark;
std::deque<OUString> aLastSelectedPath;
SvtViewOptions aViewSettings( E_DIALOG, TG_SETTING_MANAGER );
if (aViewSettings.Exists())
{
//Maybe we might want to have some sort of mru list and keep a mapping
//per document, rather than the current reuse of "the last thing
//selected, regardless of the document"
aViewSettings.GetUserItem(TG_SETTING_LASTMARK) >>= sLastSelectedMark;
uno::Sequence<OUString> aTmp;
aViewSettings.GetUserItem(TG_SETTING_LASTPATH) >>= aTmp;
aLastSelectedPath = comphelper::sequenceToContainer< std::deque<OUString> >(aTmp);
}
//fallback to previous entry selected the last
//time we executed this dialog. First see if
//the exact mark exists and re-use that
if (!sLastSelectedMark.isEmpty())
bSelectedEntry = SelectEntry(sLastSelectedMark);
//Otherwise just select the closest path available
//now to what was available at dialog close time
if (!bSelectedEntry && !aLastSelectedPath.empty())
{
std::deque<OUString> aTmpSelectedPath(aLastSelectedPath);
SelectPath(maLbTree.First(), maLbTree, aTmpSelectedPath);
}
}
2009-10-31 00:36:06 +01:00
/*************************************************************************
|*
|* Interface to refresh tree
|*
|************************************************************************/
void SvxHlinkDlgMarkWnd::RefreshTree (OUString aStrURL)
2009-10-31 00:36:06 +01:00
{
OUString aUStrURL;
EnterWait();
ClearTree();
sal_Int32 nPos = aStrURL.indexOf('#');
2009-10-31 00:36:06 +01:00
if (nPos != 0)
aUStrURL = aStrURL;
2009-10-31 00:36:06 +01:00
if (!RefreshFromDoc(aUStrURL))
2009-10-31 00:36:06 +01:00
maLbTree.Invalidate();
bool bSelectedEntry = false;
if ( nPos != -1 )
2009-10-31 00:36:06 +01:00
{
OUString aStrMark = aStrURL.copy(nPos+1);
bSelectedEntry = SelectEntry(aStrMark);
2009-10-31 00:36:06 +01:00
}
if (!bSelectedEntry)
RestoreLastSelection();
2009-10-31 00:36:06 +01:00
LeaveWait();
maStrLastURL = aStrURL;
}
/*************************************************************************
|*
|* get links from document
|*
|************************************************************************/
sal_Bool SvxHlinkDlgMarkWnd::RefreshFromDoc(OUString aURL)
2009-10-31 00:36:06 +01:00
{
mnError = LERR_NOERROR;
uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
uno::Reference< lang::XComponent > xComp;
if( !aURL.isEmpty() )
2009-10-31 00:36:06 +01:00
{
// load from url
uno::Reference< frame::XComponentLoader > xLoader( xDesktop, uno::UNO_QUERY );
if( xLoader.is() )
2009-10-31 00:36:06 +01:00
{
try
2009-10-31 00:36:06 +01:00
{
uno::Sequence< beans::PropertyValue > aArg(1);
aArg.getArray()[0].Name = OUString( "Hidden" );
aArg.getArray()[0].Value <<= (sal_Bool) sal_True;
xComp = xLoader->loadComponentFromURL( aURL, OUString( "_blank" ), 0, aArg );
2009-10-31 00:36:06 +01:00
}
catch( const io::IOException& )
2009-10-31 00:36:06 +01:00
{
}
catch( const lang::IllegalArgumentException& )
2009-10-31 00:36:06 +01:00
{
2009-10-31 00:36:06 +01:00
}
}
}
else
{
// the component with user focus ( current document )
xComp = xDesktop->getCurrentComponent();
}
if( xComp.is() )
{
uno::Reference< document::XLinkTargetSupplier > xLTS( xComp, uno::UNO_QUERY );
if( xLTS.is() )
{
if( FillTree( xLTS->getLinks() ) == 0 )
mnError = LERR_NOENTRIES;
}
else
mnError = LERR_DOCNOTOPEN;
if ( !aURL.isEmpty() )
xComp->dispose();
}
else
{
if( !aURL.isEmpty() )
mnError=LERR_DOCNOTOPEN;
}
2009-10-31 00:36:06 +01:00
return (mnError==0);
}
/*************************************************************************
|*
|* Fill Tree-Control
|*
|************************************************************************/
int SvxHlinkDlgMarkWnd::FillTree( uno::Reference< container::XNameAccess > xLinks, SvTreeListEntry* pParentEntry )
2009-10-31 00:36:06 +01:00
{
int nEntries=0;
const uno::Sequence< OUString > aNames( xLinks->getElementNames() );
const sal_uLong nLinks = aNames.getLength();
2009-10-31 00:36:06 +01:00
const OUString* pNames = aNames.getConstArray();
Color aMaskColor( COL_LIGHTMAGENTA );
const OUString aProp_LinkDisplayName( "LinkDisplayName" );
const OUString aProp_LinkTarget( "com.sun.star.document.LinkTarget" );
const OUString aProp_LinkDisplayBitmap( "LinkDisplayBitmap" );
for( sal_uLong i = 0; i < nLinks; i++ )
2009-10-31 00:36:06 +01:00
{
uno::Any aAny;
OUString aLink( *pNames++ );
sal_Bool bError = sal_False;
2009-10-31 00:36:06 +01:00
try
{
aAny = xLinks->getByName( aLink );
}
catch(const uno::Exception&)
{
// if the name of the target was invalid (like empty headings)
// no object can be provided
bError = sal_True;
2009-10-31 00:36:06 +01:00
}
if(bError)
continue;
uno::Reference< beans::XPropertySet > xTarget;
if( aAny >>= xTarget )
{
try
{
// get name to display
aAny = xTarget->getPropertyValue( aProp_LinkDisplayName );
OUString aDisplayName;
aAny >>= aDisplayName;
OUString aStrDisplayname ( aDisplayName );
2009-10-31 00:36:06 +01:00
// is it a target ?
uno::Reference< lang::XServiceInfo > xSI( xTarget, uno::UNO_QUERY );
sal_Bool bIsTarget = xSI->supportsService( aProp_LinkTarget );
2009-10-31 00:36:06 +01:00
// create userdata
TargetData *pData = new TargetData ( aLink, bIsTarget );
SvTreeListEntry* pEntry;
2009-10-31 00:36:06 +01:00
try
{
// get bitmap for the tree-entry
uno::Reference< awt::XBitmap > aXBitmap( xTarget->getPropertyValue( aProp_LinkDisplayBitmap ), uno::UNO_QUERY );
if( aXBitmap.is() )
{
Image aBmp( VCLUnoHelper::GetBitmap( aXBitmap ).GetBitmap(), aMaskColor );
// insert Displayname into treelist with bitmaps
pEntry = maLbTree.InsertEntry ( aStrDisplayname,
aBmp, aBmp,
pParentEntry,
sal_False, LIST_APPEND,
2009-10-31 00:36:06 +01:00
(void*)pData );
nEntries++;
}
else
{
// insert Displayname into treelist without bitmaps
pEntry = maLbTree.InsertEntry ( aStrDisplayname,
pParentEntry,
sal_False, LIST_APPEND,
2009-10-31 00:36:06 +01:00
(void*)pData );
nEntries++;
}
}
catch(const com::sun::star::uno::Exception&)
{
// insert Displayname into treelist without bitmaps
pEntry = maLbTree.InsertEntry ( aStrDisplayname,
pParentEntry,
sal_False, LIST_APPEND,
2009-10-31 00:36:06 +01:00
(void*)pData );
nEntries++;
}
uno::Reference< document::XLinkTargetSupplier > xLTS( xTarget, uno::UNO_QUERY );
if( xLTS.is() )
nEntries += FillTree( xLTS->getLinks(), pEntry );
}
catch(const com::sun::star::uno::Exception&)
{
}
}
}
return nEntries;
}
/*************************************************************************
|*
|* Clear Tree
|*
|************************************************************************/
void SvxHlinkDlgMarkWnd::ClearTree()
{
SvTreeListEntry* pEntry = maLbTree.First();
2009-10-31 00:36:06 +01:00
while ( pEntry )
{
TargetData* pUserData = ( TargetData * ) pEntry->GetUserData();
delete pUserData;
pEntry = maLbTree.Next( pEntry );
}
maLbTree.Clear();
}
/*************************************************************************
|*
|* Find Entry for String
2009-10-31 00:36:06 +01:00
|*
|************************************************************************/
SvTreeListEntry* SvxHlinkDlgMarkWnd::FindEntry (OUString aStrName)
2009-10-31 00:36:06 +01:00
{
sal_Bool bFound=sal_False;
SvTreeListEntry* pEntry = maLbTree.First();
2009-10-31 00:36:06 +01:00
while ( pEntry && !bFound )
{
TargetData* pUserData = ( TargetData * ) pEntry->GetUserData ();
if (aStrName == pUserData->aUStrLinkname)
bFound = sal_True;
2009-10-31 00:36:06 +01:00
else
pEntry = maLbTree.Next( pEntry );
}
return pEntry;
}
/*************************************************************************
|*
|* Select Entry
|*
|************************************************************************/
bool SvxHlinkDlgMarkWnd::SelectEntry(OUString aStrMark)
2009-10-31 00:36:06 +01:00
{
SvTreeListEntry* pEntry = FindEntry(aStrMark);
if (!pEntry)
return false;
maLbTree.Select(pEntry);
maLbTree.MakeVisible (pEntry);
return true;
2009-10-31 00:36:06 +01:00
}
/*************************************************************************
|*
|* Click on Ok-Button / Doubleclick on item in tree
2009-10-31 00:36:06 +01:00
|*
|************************************************************************/
IMPL_LINK_NOARG(SvxHlinkDlgMarkWnd, ClickOkHdl_Impl)
2009-10-31 00:36:06 +01:00
{
SvTreeListEntry* pEntry = maLbTree.GetCurEntry();
2009-10-31 00:36:06 +01:00
if ( pEntry )
{
TargetData *pData = ( TargetData * )pEntry->GetUserData();
if ( pData->bIsTarget )
{
mpParent->SetMarkStr(pData->aUStrLinkname);
2009-10-31 00:36:06 +01:00
}
}
return( 0L );
}
/*************************************************************************
|*
|* Click on Close-Button
|*
|************************************************************************/
IMPL_LINK_NOARG(SvxHlinkDlgMarkWnd, ClickCloseHdl_Impl)
2009-10-31 00:36:06 +01:00
{
SvTreeListEntry* pEntry = maLbTree.GetCurEntry();
if ( pEntry )
{
TargetData* pUserData = (TargetData *) pEntry->GetUserData();
OUString sLastSelectedMark = pUserData->aUStrLinkname;
std::deque<OUString> aLastSelectedPath;
if (pEntry)
{
//If the bottommost entry is expanded but nothing
//underneath it is selected leave a dummy entry
if (maLbTree.IsExpanded(pEntry))
aLastSelectedPath.push_front(OUString());
while (pEntry)
{
aLastSelectedPath.push_front(maLbTree.GetEntryText(pEntry));
pEntry = maLbTree.GetParent(pEntry);
}
}
uno::Sequence< beans::NamedValue > aSettings(2);
aSettings[0].Name = TG_SETTING_LASTMARK;
aSettings[0].Value <<= sLastSelectedMark;
aSettings[1].Name = TG_SETTING_LASTPATH;
aSettings[1].Value <<= comphelper::containerToSequence<OUString>(aLastSelectedPath);
// write
SvtViewOptions aViewSettings( E_DIALOG, TG_SETTING_MANAGER );
aViewSettings.SetUserData( aSettings );
}
2009-10-31 00:36:06 +01:00
Close();
return( 0L );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */