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