1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hlmarkwn.cxx,v $
10 * $Revision: 1.19.216.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
37 #include <vcl/wrkwin.hxx>
38 #include <svx/dialmgr.hxx>
39 #include <sfx2/docfile.hxx>
40 #include <vcl/svapp.hxx>
41 #include <vcl/settings.hxx>
44 #include <comphelper/processfactory.hxx>
45 #include <com/sun/star/awt/XBitmap.hpp>
46 #include <com/sun/star/frame/XDesktop.hpp>
47 #include <com/sun/star/frame/XDesktop.hpp>
48 #include <com/sun/star/frame/XComponentLoader.hpp>
49 #include <com/sun/star/beans/PropertyValue.hpp>
50 #include <com/sun/star/document/XLinkTargetSupplier.hpp>
51 #include <com/sun/star/beans/XPropertySet.hpp>
53 #include <toolkit/unohlp.hxx>
55 #include <svx/dialogs.hrc>
56 #include "hlmarkwn.hrc"
57 #include "hlmarkwn.hxx"
58 #include "hltpbase.hxx"
60 using namespace ::com::sun::star
;
61 using namespace ::rtl
;
63 /*************************************************************************
65 |* Userdata-struct for tree-entries
67 |************************************************************************/
71 OUString aUStrLinkname
;
74 TargetData ( OUString aUStrLName
, BOOL bTarget
)
75 : bIsTarget ( bTarget
)
78 aUStrLinkname
= aUStrLName
;
83 //########################################################################
87 //########################################################################
89 SvxHlmarkTreeLBox::SvxHlmarkTreeLBox( Window
* pParent
, const ResId
& rResId
)
90 : SvTreeListBox ( pParent
, rResId
),
91 mpParentWnd ( (SvxHlinkDlgMarkWnd
*) pParent
)
93 SetNodeDefaultImages();
96 void SvxHlmarkTreeLBox::Paint( const Rectangle
& rRect
)
98 if( mpParentWnd
->mnError
== LERR_NOERROR
)
100 SvTreeListBox::Paint(rRect
);
106 Rectangle
aDrawRect( Point( 0, 0 ), GetSizePixel() );
110 switch( mpParentWnd
->mnError
)
112 case LERR_NOENTRIES
:
113 aStrMessage
= SVX_RESSTR( RID_SVXSTR_HYPDLG_ERR_LERR_NOENTRIES
);
115 case LERR_DOCNOTOPEN
:
116 aStrMessage
= SVX_RESSTR( RID_SVXSTR_HYPDLG_ERR_LERR_DOCNOTOPEN
);
120 DrawText( aDrawRect
, aStrMessage
, TEXT_DRAW_LEFT
| TEXT_DRAW_MULTILINE
| TEXT_DRAW_WORDBREAK
);
125 //########################################################################
129 //########################################################################
131 /*************************************************************************
133 |* Contructor / Destructor
135 |************************************************************************/
137 SvxHlinkDlgMarkWnd::SvxHlinkDlgMarkWnd( SvxHyperlinkTabPageBase
*pParent
)
138 : ModalDialog( (Window
*)pParent
, SVX_RES ( RID_SVXFLOAT_HYPERLINK_MARKWND
) ),
139 maBtApply( this, SVX_RES (BT_APPLY
) ),
140 maBtClose( this, SVX_RES (BT_CLOSE
) ),
141 maLbTree ( this, SVX_RES (TLB_MARK
) ),
142 mbUserMoved ( FALSE
),
144 mpParent ( pParent
),
145 mnError ( LERR_NOERROR
)
149 maBtApply
.SetClickHdl ( LINK ( this, SvxHlinkDlgMarkWnd
, ClickApplyHdl_Impl
) );
150 maBtClose
.SetClickHdl ( LINK ( this, SvxHlinkDlgMarkWnd
, ClickCloseHdl_Impl
) );
151 maLbTree
.SetDoubleClickHdl ( LINK ( this, SvxHlinkDlgMarkWnd
, ClickApplyHdl_Impl
) );
153 // Tree-ListBox mit Linien versehen
154 maLbTree
.SetWindowBits( WinBits( WB_TABSTOP
| WB_BORDER
| WB_HASLINES
|
155 WB_HASBUTTONS
| //WB_HASLINESATROOT |
156 WB_HSCROLL
| WB_HASBUTTONSATROOT
) );
159 SvxHlinkDlgMarkWnd::~SvxHlinkDlgMarkWnd()
164 /*************************************************************************
166 |* Set an errorstatus
168 |************************************************************************/
170 USHORT
SvxHlinkDlgMarkWnd::SetError( USHORT nError
)
172 USHORT nOldError
= mnError
;
175 if( mnError
!= LERR_NOERROR
)
178 maLbTree
.Invalidate();
183 /*************************************************************************
187 |************************************************************************/
189 BOOL
SvxHlinkDlgMarkWnd::MoveTo ( Point aNewPos
)
193 BOOL bOldStatus
= mbUserMoved
;
194 SetPosPixel ( aNewPos
);
195 mbUserMoved
= bOldStatus
;
201 void SvxHlinkDlgMarkWnd::Move ()
205 if ( IsReallyVisible() )
209 BOOL
SvxHlinkDlgMarkWnd::ConnectToDialog( BOOL bDoit
)
211 BOOL bOldStatus
= mbUserMoved
;
213 mbUserMoved
= !bDoit
;
218 /*************************************************************************
220 |* Interface to refresh tree
222 |************************************************************************/
224 void SvxHlinkDlgMarkWnd::RefreshTree ( String aStrURL
)
233 xub_StrLen nPos
= aStrURL
.Search ( sal_Unicode('#') );
236 aUStrURL
= ::rtl::OUString( aStrURL
);
238 if( !RefreshFromDoc ( aUStrURL
) )
239 maLbTree
.Invalidate();
241 if ( nPos
!= STRING_NOTFOUND
)
243 String aStrMark
= aStrURL
.Copy ( nPos
+1 );
244 SelectEntry ( aStrMark
);
249 maStrLastURL
= aStrURL
;
252 /*************************************************************************
254 |* get links from document
256 |************************************************************************/
258 BOOL
SvxHlinkDlgMarkWnd::RefreshFromDoc( OUString aURL
)
260 mnError
= LERR_NOERROR
;
262 uno::Reference
< lang::XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
265 uno::Reference
< frame::XDesktop
> xDesktop( xFactory
->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ),
269 uno::Reference
< lang::XComponent
> xComp
;
271 if( aURL
.getLength() )
274 uno::Reference
< frame::XComponentLoader
> xLoader( xDesktop
, uno::UNO_QUERY
);
279 uno::Sequence
< beans::PropertyValue
> aArg(1);
280 aArg
.getArray()[0].Name
= OUString::createFromAscii( "Hidden" );
281 aArg
.getArray()[0].Value
<<= (sal_Bool
) TRUE
;
282 xComp
= xLoader
->loadComponentFromURL( aURL
, OUString::createFromAscii( "_blank" ), 0, aArg
);
284 catch( const io::IOException
& )
288 catch( const lang::IllegalArgumentException
& )
296 // the component with user focus ( current document )
297 xComp
= xDesktop
->getCurrentComponent();
302 uno::Reference
< document::XLinkTargetSupplier
> xLTS( xComp
, uno::UNO_QUERY
);
306 if( FillTree( xLTS
->getLinks() ) == 0 )
307 mnError
= LERR_NOENTRIES
;
310 mnError
= LERR_DOCNOTOPEN
;
312 if ( aURL
.getLength() )
317 if( aURL
.getLength() )
318 mnError
=LERR_DOCNOTOPEN
;
325 void SvxHlinkDlgMarkWnd::Error(int nNr)
331 Rectangle aDrawRect( Point( 0, 0 ), maLbTree.GetSizePixel() );
332 //maLbTree.SetTextColor( Color(COL_BLACK) );
333 //maLbTree.DrawText( aDrawRect, "Keine Ziele im Dokument vorhanden.", TEXT_DRAW_LEFT);// | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
334 maLbTree.DrawText( Point(0,0), "Keine Ziele im Dokument vorhanden.");
335 maLbTree.DrawLine(aDrawRect.TopLeft(), aDrawRect.BottomRight() );
339 Rectangle aDrawRect( Point( 0, 0 ), maLbTree.GetSizePixel() );
340 maLbTree.DrawText( aDrawRect, "Das Dokument konnte nicht ge�ffnet werden.", TEXT_DRAW_LEFT | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
345 /*************************************************************************
349 |************************************************************************/
351 int SvxHlinkDlgMarkWnd::FillTree( uno::Reference
< container::XNameAccess
> xLinks
, SvLBoxEntry
* pParentEntry
)
354 const uno::Sequence
< OUString
> aNames( xLinks
->getElementNames() );
355 const ULONG nLinks
= aNames
.getLength();
356 const OUString
* pNames
= aNames
.getConstArray();
358 Color
aMaskColor( COL_LIGHTMAGENTA
);
359 const OUString
aProp_LinkDisplayName( RTL_CONSTASCII_USTRINGPARAM( "LinkDisplayName" ) );
360 const OUString
aProp_LinkTarget( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.LinkTarget" ) );
361 const OUString
aProp_LinkDisplayBitmap( RTL_CONSTASCII_USTRINGPARAM( "LinkDisplayBitmap" ) );
362 for( ULONG i
= 0; i
< nLinks
; i
++ )
365 OUString
aLink( *pNames
++ );
370 aAny
= xLinks
->getByName( aLink
);
372 catch(const uno::Exception
&)
374 // if the name of the target was invalid (like empty headings)
375 // no object can be provided
381 uno::Reference
< beans::XPropertySet
> xTarget
;
383 if( aAny
>>= xTarget
)
387 // get name to display
388 aAny
= xTarget
->getPropertyValue( aProp_LinkDisplayName
);
389 OUString aDisplayName
;
390 aAny
>>= aDisplayName
;
391 String
aStrDisplayname ( aDisplayName
);
394 uno::Reference
< lang::XServiceInfo
> xSI( xTarget
, uno::UNO_QUERY
);
395 BOOL bIsTarget
= xSI
->supportsService( aProp_LinkTarget
);
398 TargetData
*pData
= new TargetData ( aLink
, bIsTarget
);
404 // get bitmap for the tree-entry
405 uno::Reference
< awt::XBitmap
> aXBitmap( xTarget
->getPropertyValue( aProp_LinkDisplayBitmap
), uno::UNO_QUERY
);
408 Image
aBmp( VCLUnoHelper::GetBitmap( aXBitmap
).GetBitmap(), aMaskColor
);
409 // insert Displayname into treelist with bitmaps
410 pEntry
= maLbTree
.InsertEntry ( aStrDisplayname
,
415 maLbTree
.SetExpandedEntryBmp( pEntry
, aBmp
, BMP_COLOR_HIGHCONTRAST
);
416 maLbTree
.SetCollapsedEntryBmp( pEntry
, aBmp
, BMP_COLOR_HIGHCONTRAST
);
421 // insert Displayname into treelist without bitmaps
422 pEntry
= maLbTree
.InsertEntry ( aStrDisplayname
,
429 catch(const com::sun::star::uno::Exception
&)
431 // insert Displayname into treelist without bitmaps
432 pEntry
= maLbTree
.InsertEntry ( aStrDisplayname
,
439 uno::Reference
< document::XLinkTargetSupplier
> xLTS( xTarget
, uno::UNO_QUERY
);
441 nEntries
+= FillTree( xLTS
->getLinks(), pEntry
);
443 catch(const com::sun::star::uno::Exception
&)
452 /*************************************************************************
456 |************************************************************************/
458 void SvxHlinkDlgMarkWnd::ClearTree()
460 SvLBoxEntry
* pEntry
= maLbTree
.First();
464 TargetData
* pUserData
= ( TargetData
* ) pEntry
->GetUserData();
467 pEntry
= maLbTree
.Next( pEntry
);
473 /*************************************************************************
475 |* Find Entry for Strng
477 |************************************************************************/
479 SvLBoxEntry
* SvxHlinkDlgMarkWnd::FindEntry ( String aStrName
)
482 SvLBoxEntry
* pEntry
= maLbTree
.First();
484 while ( pEntry
&& !bFound
)
486 TargetData
* pUserData
= ( TargetData
* ) pEntry
->GetUserData ();
487 if ( aStrName
== String( pUserData
->aUStrLinkname
) )
490 pEntry
= maLbTree
.Next( pEntry
);
496 /*************************************************************************
500 |************************************************************************/
502 void SvxHlinkDlgMarkWnd::SelectEntry ( String aStrMark
)
504 SvLBoxEntry
* pEntry
= FindEntry ( aStrMark
);
507 maLbTree
.Select ( pEntry
);
508 maLbTree
.MakeVisible ( pEntry
);
512 /*************************************************************************
514 |* Click on Apply-Button / Doubleclick on item in tree
516 |************************************************************************/
518 IMPL_LINK ( SvxHlinkDlgMarkWnd
, ClickApplyHdl_Impl
, void *, EMPTYARG
)
520 SvLBoxEntry
* pEntry
= maLbTree
.GetCurEntry();
524 TargetData
*pData
= ( TargetData
* )pEntry
->GetUserData();
526 if ( pData
->bIsTarget
)
528 String
aStrMark ( pData
->aUStrLinkname
);
529 mpParent
->SetMarkStr ( aStrMark
);
536 /*************************************************************************
538 |* Click on Close-Button
540 |************************************************************************/
542 IMPL_LINK ( SvxHlinkDlgMarkWnd
, ClickCloseHdl_Impl
, void *, EMPTYARG
)