Update ooo320-m1
[ooovba.git] / sfx2 / source / appl / newhelp.cxx
blob9e0c8a1da35df3320c23590222649c3c377ff755
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: newhelp.cxx,v $
10 * $Revision: 1.130 $
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_sfx2.hxx"
34 #include "newhelp.hxx"
35 #include <sfx2/sfxuno.hxx>
36 #include "sfxresid.hxx"
37 #include "helpinterceptor.hxx"
38 #include "helper.hxx"
39 #include <sfx2/msgpool.hxx>
40 #include <sfx2/app.hxx>
41 #include "sfxtypes.hxx"
42 #include "panelist.hxx"
43 #include "imgmgr.hxx"
44 #include "srchdlg.hxx"
45 #include "sfxhelp.hxx"
47 #include "app.hrc"
48 #include "newhelp.hrc"
49 #include "helpid.hrc"
51 #include <hash_map>
52 #include <rtl/ustrbuf.hxx>
53 #include <comphelper/processfactory.hxx>
54 #include <comphelper/configurationhelper.hxx>
55 #include <toolkit/helper/vclunohelper.hxx>
56 #include <com/sun/star/util/XModifiable.hpp>
57 #include <com/sun/star/frame/XComponentLoader.hpp>
58 #include <com/sun/star/util/XCloseable.hpp>
59 #include <com/sun/star/util/CloseVetoException.hpp>
60 #include <com/sun/star/lang/XComponent.hpp>
61 #include <com/sun/star/lang/DisposedException.hpp>
62 #include <com/sun/star/awt/PosSize.hpp>
63 #include <com/sun/star/awt/XWindow.hpp>
64 #include <com/sun/star/beans/Property.hpp>
65 #include <com/sun/star/beans/PropertyValue.hpp>
66 #include <com/sun/star/beans/XPropertySetInfo.hpp>
67 #include <com/sun/star/container/XIndexAccess.hpp>
68 #include <com/sun/star/frame/XTitle.hpp>
69 #include <com/sun/star/frame/XLayoutManager.hpp>
70 #include <com/sun/star/frame/DispatchResultState.hpp>
71 #include <com/sun/star/frame/XController.hpp>
72 #include <com/sun/star/frame/XDispatch.hpp>
73 #include <com/sun/star/frame/XDispatchProvider.hpp>
74 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
75 #include <com/sun/star/frame/XFrame.hpp>
76 #ifndef _COM_SUN_STAR_TEXT_XBREAKITERATOR_HPP_
77 #include <com/sun/star/i18n/XBreakIterator.hpp>
78 #endif
79 #include <com/sun/star/i18n/WordType.hpp>
80 #include <com/sun/star/lang/XComponent.hpp>
81 #include <com/sun/star/style/XStyle.hpp>
82 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
83 #include <com/sun/star/text/XText.hpp>
84 #include <com/sun/star/text/XTextCursor.hpp>
85 #include <com/sun/star/text/XTextDocument.hpp>
86 #include <com/sun/star/text/XTextRange.hpp>
87 #include <com/sun/star/text/XTextViewCursor.hpp>
88 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
89 #include <com/sun/star/ucb/CommandAbortedException.hpp>
90 #include <com/sun/star/util/URL.hpp>
91 #include <com/sun/star/util/XSearchable.hpp>
92 #include <com/sun/star/util/XSearchDescriptor.hpp>
93 #include <com/sun/star/util/XURLTransformer.hpp>
94 #include <com/sun/star/view/XSelectionSupplier.hpp>
95 #include <com/sun/star/view/XViewSettingsSupplier.hpp>
96 #include <com/sun/star/ui/XDockingAreaAcceptor.hpp>
97 #include <svtools/helpopt.hxx>
98 #include <svtools/historyoptions.hxx>
99 #include <svtools/menuoptions.hxx>
100 #include <svtools/pathoptions.hxx>
101 #include <svtools/viewoptions.hxx>
102 #include <svtools/svtdata.hxx>
103 #include <tools/urlobj.hxx>
104 #include <tools/cachestr.hxx>
105 #include <unotools/streamhelper.hxx>
106 #include <svtools/imagemgr.hxx>
107 #include <svtools/miscopt.hxx>
108 #include <svtools/imgdef.hxx>
109 #include <vcl/unohelp.hxx>
110 #include <vcl/i18nhelp.hxx>
112 #include <ucbhelper/content.hxx>
113 #include <vcl/msgbox.hxx>
114 #include <vcl/waitobj.hxx>
115 #include <unotools/ucbhelper.hxx>
117 #include <sfx2/viewfrm.hxx>
118 #include <sfx2/objsh.hxx>
119 #include <sfx2/docfac.hxx>
121 using namespace ::ucbhelper;
122 using namespace ::com::sun::star::ucb;
124 using namespace ::com::sun::star;
125 using namespace ::com::sun::star::beans;
126 using namespace ::com::sun::star::container;
127 using namespace ::com::sun::star::frame;
128 using namespace ::com::sun::star::i18n;
129 using namespace ::com::sun::star::lang;
130 using namespace ::com::sun::star::style;
131 using namespace ::com::sun::star::text;
132 using namespace ::com::sun::star::uno;
133 using namespace ::com::sun::star::util;
134 using namespace ::com::sun::star::view;
135 using namespace ::com::sun::star::ui;
137 using namespace ::comphelper;
139 extern void AppendConfigToken_Impl( String& rURL, sal_Bool bQuestionMark ); // sfxhelp.cxx
141 // defines ---------------------------------------------------------------
143 #define SPLITSET_ID 0
144 #define COLSET_ID 1
145 #define INDEXWIN_ID 2
146 #define TEXTWIN_ID 3
148 #define TOOLBOX_OFFSET 3
150 #define TBI_INDEX 1001
151 #define TBI_BACKWARD 1002
152 #define TBI_FORWARD 1003
153 #define TBI_START 1004
154 #define TBI_PRINT 1005
155 #define TBI_COPY 1006
156 #define TBI_BOOKMARKS 1007
157 #define TBI_SEARCHDIALOG 1008
158 #define TBI_SOURCEVIEW 1009
159 #define TBI_SELECTIONMODE 1010
160 #define TBI_ONSTARTUP 1011
162 #define CONFIGNAME_HELPWIN DEFINE_CONST_UNICODE("OfficeHelp")
163 #define CONFIGNAME_INDEXWIN DEFINE_CONST_UNICODE("OfficeHelpIndex")
164 #define CONFIGNAME_SEARCHPAGE DEFINE_CONST_UNICODE("OfficeHelpSearch")
165 #define IMAGE_URL DEFINE_CONST_UNICODE("private:factory/")
167 #define PROPERTY_KEYWORDLIST DEFINE_CONST_OUSTRING("KeywordList")
168 #define PROPERTY_KEYWORDREF DEFINE_CONST_OUSTRING("KeywordRef")
169 #define PROPERTY_ANCHORREF DEFINE_CONST_OUSTRING("KeywordAnchorForRef")
170 #define PROPERTY_TITLEREF DEFINE_CONST_OUSTRING("KeywordTitleForRef")
171 #define PROPERTY_TITLE DEFINE_CONST_OUSTRING("Title")
172 #define HELP_URL DEFINE_CONST_OUSTRING("vnd.sun.star.help://")
173 #define HELP_SEARCH_TAG DEFINE_CONST_OUSTRING("/?Query=")
174 #define USERITEM_NAME DEFINE_CONST_OUSTRING("UserItem")
176 #define PACKAGE_SETUP DEFINE_CONST_OUSTRING("/org.openoffice.Setup")
177 #define PATH_OFFICE_FACTORIES DEFINE_CONST_OUSTRING("Office/Factories/")
178 #define KEY_HELP_ON_OPEN DEFINE_CONST_OUSTRING("ooSetupFactoryHelpOnOpen")
179 #define KEY_UI_NAME DEFINE_CONST_OUSTRING("ooSetupFactoryUIName")
181 #define PARSE_URL( aURL ) \
182 Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( \
183 DEFINE_CONST_UNICODE("com.sun.star.util.URLTransformer" )), UNO_QUERY ); \
184 xTrans->parseStrict( aURL )
186 //.........................................................................
187 namespace sfx2
189 //.........................................................................
191 void HandleTaskPaneList( Window* pWindow, BOOL bAddToList )
193 Window* pParent = pWindow->GetParent();
194 DBG_ASSERT( pParent, "HandleTaskPaneList(): every window here should have a parent" );
196 SystemWindow* pSysWin = pParent->GetSystemWindow();
197 if( pSysWin )
199 TaskPaneList* pTaskPaneList = pSysWin->GetTaskPaneList();
200 if( pTaskPaneList )
202 if( bAddToList )
203 pTaskPaneList->AddWindow( pWindow );
204 else
205 pTaskPaneList->RemoveWindow( pWindow );
210 /** Prepare a search string for searching or selecting.
211 For searching every search word needs the postfix '*' and the delimiter ' ' if necessary.
212 For selecting the delimiter '|' is required to search with regular expressions.
213 Samples:
214 search string | output for searching | output for selecting
215 -----------------------------------------------------------
216 "text" | "text*" | "text"
217 "text*" | "text*" | "text"
218 "text menu" | "text* menu*" | "text|menu"
220 String PrepareSearchString( const String& rSearchString,
221 Reference< XBreakIterator > xBreak, bool bForSearch )
223 String sSearchStr;
224 sal_Int32 nStartPos = 0;
225 const Locale aLocale = Application::GetSettings().GetUILocale();
226 Boundary aBoundary = xBreak->getWordBoundary(
227 rSearchString, nStartPos, aLocale, WordType::ANYWORD_IGNOREWHITESPACES, sal_True );
229 while ( aBoundary.startPos != aBoundary.endPos )
231 nStartPos = aBoundary.endPos;
232 String sSearchToken( rSearchString.Copy(
233 (USHORT)aBoundary.startPos, (USHORT)aBoundary.endPos - (USHORT)aBoundary.startPos ) );
234 if ( sSearchToken.Len() > 0 && ( sSearchToken.Len() > 1 || sSearchToken.GetChar(0) != '.' ) )
236 if ( bForSearch && sSearchToken.GetChar( sSearchToken.Len() - 1 ) != '*' )
237 sSearchToken += '*';
239 if ( sSearchToken.Len() > 1 ||
240 ( sSearchToken.Len() > 0 && sSearchToken.GetChar( 0 ) != '*' ) )
242 if ( sSearchStr.Len() > 0 )
244 if ( bForSearch )
245 sSearchStr += ' ';
246 else
247 sSearchStr += '|';
249 sSearchStr += sSearchToken;
252 aBoundary = xBreak->nextWord( rSearchString, nStartPos,
253 aLocale, WordType::ANYWORD_IGNOREWHITESPACES );
256 return sSearchStr;
258 //.........................................................................
259 // namespace sfx2
261 //.........................................................................
263 // struct IndexEntry_Impl ------------------------------------------------
265 struct IndexEntry_Impl
267 sal_Bool m_bSubEntry;
268 String m_aURL;
270 IndexEntry_Impl( const String& rURL, sal_Bool bSubEntry ) :
271 m_bSubEntry( bSubEntry ), m_aURL( rURL ) {}
274 #define NEW_ENTRY( url, bool ) \
275 (void*)(ULONG)( new IndexEntry_Impl( url, bool ) )
277 // struct ContentEntry_Impl ----------------------------------------------
279 struct ContentEntry_Impl
281 String aURL;
282 sal_Bool bIsFolder;
284 ContentEntry_Impl( const String& rURL, sal_Bool bFolder ) :
285 aURL( rURL ), bIsFolder( bFolder ) {}
288 // ContentListBox_Impl ---------------------------------------------------
290 ContentListBox_Impl::ContentListBox_Impl( Window* pParent, const ResId& rResId ) :
292 SvTreeListBox( pParent, rResId ),
294 aOpenBookImage ( SfxResId( IMG_HELP_CONTENT_BOOK_OPEN ) ),
295 aClosedBookImage ( SfxResId( IMG_HELP_CONTENT_BOOK_CLOSED ) ),
296 aDocumentImage ( SfxResId( IMG_HELP_CONTENT_DOC ) )
299 if ( GetSettings().GetStyleSettings().GetWindowColor().IsDark() )
301 aOpenBookImage = Image( SfxResId( IMG_HELP_CONTENT_BOOK_OPEN_HC ) );
302 aClosedBookImage = Image( SfxResId( IMG_HELP_CONTENT_BOOK_CLOSED_HC ) );
303 aDocumentImage = Image( SfxResId( IMG_HELP_CONTENT_DOC_HC ) );
306 SetWindowBits( WB_HIDESELECTION | WB_HSCROLL );
308 SetEntryHeight( 16 );
309 SetSelectionMode( SINGLE_SELECTION );
310 SetSpaceBetweenEntries( 2 );
311 SetNodeBitmaps( aClosedBookImage, aOpenBookImage );
313 SetSublistOpenWithReturn();
314 SetSublistOpenWithLeftRight();
316 InitRoot();
319 // -----------------------------------------------------------------------
321 ContentListBox_Impl::~ContentListBox_Impl()
323 USHORT nPos = 0;
324 SvLBoxEntry* pEntry = GetEntry( nPos++ );
325 while ( pEntry )
327 ::rtl::OUString aTemp( GetEntryText( pEntry ) );
328 ClearChildren( pEntry );
329 delete (ContentEntry_Impl*)pEntry->GetUserData();
330 pEntry = GetEntry( nPos++ );
334 // -----------------------------------------------------------------------
336 void ContentListBox_Impl::InitRoot()
338 String aHelpTreeviewURL( DEFINE_CONST_UNICODE("vnd.sun.star.hier://com.sun.star.help.TreeView/") );
339 ::com::sun::star::uno::Sequence< ::rtl::OUString > aList =
340 SfxContentHelper::GetHelpTreeViewContents( aHelpTreeviewURL );
342 const ::rtl::OUString* pEntries = aList.getConstArray();
343 UINT32 i, nCount = aList.getLength();
344 for ( i = 0; i < nCount; ++i )
346 String aRow( pEntries[i] );
347 String aTitle, aURL;
348 xub_StrLen nIdx = 0;
349 aTitle = aRow.GetToken( 0, '\t', nIdx );
350 aURL = aRow.GetToken( 0, '\t', nIdx );
351 sal_Unicode cFolder = aRow.GetToken( 0, '\t', nIdx ).GetChar(0);
352 sal_Bool bIsFolder = ( '1' == cFolder );
353 SvLBoxEntry* pEntry = InsertEntry( aTitle, aOpenBookImage, aClosedBookImage, NULL, TRUE );
354 if ( bIsFolder )
355 pEntry->SetUserData( new ContentEntry_Impl( aURL, sal_True ) );
359 // -----------------------------------------------------------------------
361 void ContentListBox_Impl::ClearChildren( SvLBoxEntry* pParent )
363 SvLBoxEntry* pEntry = FirstChild( pParent );
364 while ( pEntry )
366 ::rtl::OUString aTemp( GetEntryText( pEntry ) );
367 ClearChildren( pEntry );
368 delete (ContentEntry_Impl*)pEntry->GetUserData();
369 pEntry = NextSibling( pEntry );
373 // -----------------------------------------------------------------------
375 void ContentListBox_Impl::RequestingChilds( SvLBoxEntry* pParent )
379 if ( !pParent->HasChilds() )
381 if ( pParent->GetUserData() )
383 String aTmpURL( ( (ContentEntry_Impl*)pParent->GetUserData() )->aURL );
384 ::com::sun::star::uno::Sequence< ::rtl::OUString > aList =
385 SfxContentHelper::GetHelpTreeViewContents( aTmpURL );
387 const ::rtl::OUString* pEntries = aList.getConstArray();
388 UINT32 i, nCount = aList.getLength();
389 for ( i = 0; i < nCount; ++i )
391 String aRow( pEntries[i] );
392 String aTitle, aURL;
393 xub_StrLen nIdx = 0;
394 aTitle = aRow.GetToken( 0, '\t', nIdx );
395 aURL = aRow.GetToken( 0, '\t', nIdx );
396 sal_Unicode cFolder = aRow.GetToken( 0, '\t', nIdx ).GetChar(0);
397 sal_Bool bIsFolder = ( '1' == cFolder );
398 SvLBoxEntry* pEntry = NULL;
399 if ( bIsFolder )
401 pEntry = InsertEntry( aTitle, aOpenBookImage, aClosedBookImage, pParent, TRUE );
402 pEntry->SetUserData( new ContentEntry_Impl( aURL, sal_True ) );
404 else
406 pEntry = InsertEntry( aTitle, aDocumentImage, aDocumentImage, pParent );
407 Any aAny( ::utl::UCBContentHelper::GetProperty( aURL, String(RTL_CONSTASCII_USTRINGPARAM("TargetURL" ) ) ) );
408 rtl::OUString aTargetURL;
409 if ( aAny >>= aTargetURL )
410 pEntry->SetUserData( new ContentEntry_Impl( aTargetURL, sal_False ) );
416 catch( Exception& )
418 DBG_ERROR( "ContentListBox_Impl::RequestingChilds(): unexpected exception" );
422 // -----------------------------------------------------------------------
424 long ContentListBox_Impl::Notify( NotifyEvent& rNEvt )
426 sal_Bool bHandled = sal_False;
427 if ( rNEvt.GetType() == EVENT_KEYINPUT &&
428 KEY_RETURN == rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
430 GetDoubleClickHdl().Call( NULL );
431 bHandled = sal_True;
434 return bHandled ? 1 : SvTreeListBox::Notify( rNEvt );
437 // -----------------------------------------------------------------------
439 String ContentListBox_Impl::GetSelectEntry() const
441 String aRet;
442 SvLBoxEntry* pEntry = FirstSelected();
443 if ( pEntry && !( (ContentEntry_Impl*)pEntry->GetUserData() )->bIsFolder )
444 aRet = ( (ContentEntry_Impl*)pEntry->GetUserData() )->aURL;
445 return aRet;
448 // class HelpTabPage_Impl ------------------------------------------------
450 HelpTabPage_Impl::HelpTabPage_Impl(
451 Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin, const ResId& rResId ) :
453 TabPage( pParent, rResId ),
455 m_pIdxWin( _pIdxWin )
460 // class ContentTabPage_Impl ---------------------------------------------
462 ContentTabPage_Impl::ContentTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ) :
464 HelpTabPage_Impl( pParent, _pIdxWin, SfxResId( TP_HELP_CONTENT ) ),
466 aContentBox( this, SfxResId( LB_CONTENTS ) )
469 FreeResource();
471 aContentBox.Show();
474 // -----------------------------------------------------------------------
476 void ContentTabPage_Impl::Resize()
478 Size aSize = GetOutputSizePixel();
479 aSize.Width() -= 8;
480 aSize.Height() -= 8;
481 aContentBox.SetPosSizePixel( Point( 4, 4 ), aSize );
484 // -----------------------------------------------------------------------
486 void ContentTabPage_Impl::ActivatePage()
488 if ( !m_pIdxWin->WasCursorLeftOrRight() )
489 SetFocusOnBox();
492 // -----------------------------------------------------------------------
494 Control* ContentTabPage_Impl::GetLastFocusControl()
496 return &aContentBox;
499 // class IndexBox_Impl ---------------------------------------------------
501 IndexBox_Impl::IndexBox_Impl( Window* pParent, const ResId& rResId ) :
503 ComboBox( pParent, rResId )
506 EnableAutocomplete( TRUE );
507 EnableUserDraw( TRUE );
510 // -----------------------------------------------------------------------
512 void IndexBox_Impl::UserDraw( const UserDrawEvent& rUDEvt )
514 IndexEntry_Impl* pEntry = (IndexEntry_Impl*)(ULONG)GetEntryData( rUDEvt.GetItemId() );
515 if ( pEntry && pEntry->m_bSubEntry )
517 // indent sub entries
518 Point aPos( rUDEvt.GetRect().TopLeft() );
519 aPos.X() += 8;
520 aPos.Y() += ( rUDEvt.GetRect().GetHeight() - rUDEvt.GetDevice()->GetTextHeight() ) / 2;
521 String aEntry( GetEntry( rUDEvt.GetItemId() ) );
522 USHORT nPos = aEntry.Search( ';' );
523 rUDEvt.GetDevice()->DrawText( aPos, ( nPos != STRING_NOTFOUND ) ? aEntry.Copy( nPos + 1 ) : aEntry );
525 else
526 DrawEntry( rUDEvt, FALSE, TRUE, TRUE );
529 // -----------------------------------------------------------------------
531 long IndexBox_Impl::Notify( NotifyEvent& rNEvt )
533 sal_Bool bHandled = sal_False;
534 if ( rNEvt.GetType() == EVENT_KEYINPUT &&
535 KEY_RETURN == rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
537 GetDoubleClickHdl().Call( NULL );
538 bHandled = sal_True;
541 return bHandled ? 1 : ComboBox::Notify( rNEvt );
544 // -----------------------------------------------------------------------
546 void IndexBox_Impl::SelectExecutableEntry()
548 USHORT nPos = GetEntryPos( GetText() );
549 if ( nPos != COMBOBOX_ENTRY_NOTFOUND )
551 USHORT nOldPos = nPos;
552 String aEntryText;
553 IndexEntry_Impl* pEntry = (IndexEntry_Impl*)(ULONG)GetEntryData( nPos );
554 USHORT nCount = GetEntryCount();
555 while ( nPos < nCount && ( !pEntry || pEntry->m_aURL.Len() == 0 ) )
557 pEntry = (IndexEntry_Impl*)(ULONG)GetEntryData( ++nPos );
558 aEntryText = GetEntry( nPos );
561 if ( nOldPos != nPos )
562 SetText( aEntryText );
566 // class IndexTabPage_Impl -----------------------------------------------
568 IndexTabPage_Impl::IndexTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ) :
570 HelpTabPage_Impl( pParent, _pIdxWin, SfxResId( TP_HELP_INDEX ) ),
572 aExpressionFT ( this, SfxResId( FT_EXPRESSION ) ),
573 aIndexCB ( this, SfxResId( CB_INDEX ) ),
574 aOpenBtn ( this, SfxResId( PB_OPEN_INDEX ) ),
576 bIsActivated ( sal_False )
579 FreeResource();
581 aOpenBtn.SetClickHdl( LINK( this, IndexTabPage_Impl, OpenHdl ) );
582 Link aTimeoutLink = LINK( this, IndexTabPage_Impl, TimeoutHdl );
583 aFactoryTimer.SetTimeoutHdl( aTimeoutLink );
584 aFactoryTimer.SetTimeout( 300 );
585 aKeywordTimer.SetTimeoutHdl( aTimeoutLink );
586 aFactoryTimer.SetTimeout( 300 );
588 nMinWidth = aOpenBtn.GetSizePixel().Width();
591 // -----------------------------------------------------------------------
593 IndexTabPage_Impl::~IndexTabPage_Impl()
595 ClearIndex();
598 // -----------------------------------------------------------------------
600 namespace sfx2 {
602 struct equalOUString
604 bool operator()( const ::rtl::OUString& rKey1, const ::rtl::OUString& rKey2 ) const
606 return !!( rKey1 == rKey2 );
611 struct hashOUString
613 size_t operator()( const ::rtl::OUString& rName ) const
615 return rName.hashCode();
619 typedef ::std::hash_map< ::rtl::OUString, int, hashOUString, equalOUString > KeywordInfo;
622 #define UNIFY_AND_INSERT_TOKEN( aToken ) \
623 it = \
624 aInfo.insert( sfx2::KeywordInfo::value_type( aToken, 0 ) ).first; \
625 if ( ( tmp = it->second++ ) != 0 ) \
626 nPos = aIndexCB.InsertEntry( aToken + rtl::OUString( append, tmp ) ); \
627 else \
628 nPos = aIndexCB.InsertEntry( aToken )
630 #define INSERT_DATA( j ) \
631 if ( aAnchorList[j].getLength() > 0 ) \
633 aData.append( aRefList[j] ).append( sal_Unicode('#') ).append( aAnchorList[j] ); \
634 aIndexCB.SetEntryData( nPos, NEW_ENTRY( aData.makeStringAndClear(), insert ) ); \
636 else \
637 aIndexCB.SetEntryData( nPos, NEW_ENTRY( aRefList[j], insert ) );
639 // -----------------------------------------------------------------------
641 void IndexTabPage_Impl::InitializeIndex()
643 WaitObject( this );
645 // By now more than 256 equal entries are not allowed
646 sal_Unicode append[256];
647 for( int k = 0; k < 256; ++k )
648 append[k] = sal_Unicode( ' ' );
650 sfx2::KeywordInfo aInfo;
651 aIndexCB.SetUpdateMode( FALSE );
655 ::rtl::OUString aURL = HELP_URL;
656 aURL += ::rtl::OUString( sFactory );
658 String aTemp = aURL;
659 AppendConfigToken_Impl( aTemp, sal_True );
660 aURL = aTemp;
662 Content aCnt( aURL, Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
663 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = aCnt.getProperties();
664 if ( xInfo->hasPropertyByName( PROPERTY_ANCHORREF ) )
666 ::com::sun::star::uno::Sequence< ::rtl::OUString > aPropSeq( 4 );
667 aPropSeq[0] = PROPERTY_KEYWORDLIST;
668 aPropSeq[1] = PROPERTY_KEYWORDREF;
669 aPropSeq[2] = PROPERTY_ANCHORREF;
670 aPropSeq[3] = PROPERTY_TITLEREF;
672 // abi: use one possibly remote call only
673 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aAnySeq =
674 aCnt.getPropertyValues( aPropSeq );
676 ::com::sun::star::uno::Sequence< ::rtl::OUString > aKeywordList;
677 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > aKeywordRefList;
678 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > aAnchorRefList;
679 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > aTitleRefList;
681 if ( ( aAnySeq[0] >>= aKeywordList ) && ( aAnySeq[1] >>= aKeywordRefList ) &&
682 ( aAnySeq[2] >>= aAnchorRefList ) && ( aAnySeq[3] >>= aTitleRefList ) )
684 sal_Bool insert;
685 USHORT nPos;
686 int ndx,tmp;
687 ::rtl::OUString aIndex, aTempString;
688 ::rtl::OUStringBuffer aData( 128 ); // Capacity of up to 128 characters
689 sfx2::KeywordInfo::iterator it;
691 for ( int i = 0; i < aKeywordList.getLength(); ++i )
693 // abi: Do not copy, but use references
694 const ::rtl::OUString& aKeywordPair = aKeywordList[i];
695 DBG_ASSERT( aKeywordPair.getLength() > 0, "invalid help index" );
696 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRefList = aKeywordRefList[i];
697 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aAnchorList = aAnchorRefList[i];
698 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aTitleList = aTitleRefList[i];
700 DBG_ASSERT( aRefList.getLength() == aAnchorList.getLength(),"reference list and title list of different length" );
702 insert = ( ( ndx = aKeywordPair.indexOf( sal_Unicode( ';' ) ) ) == -1 ? sal_False : sal_True );
704 if ( insert )
706 aTempString = aKeywordPair.copy( 0, ndx );
707 if ( aIndex != aTempString )
709 aIndex = aTempString;
710 UNIFY_AND_INSERT_TOKEN( aTempString );
713 else
714 aIndex = ::rtl::OUString();
716 // Assume the token is trimed
717 UNIFY_AND_INSERT_TOKEN( aKeywordPair );
719 sal_uInt32 nRefListLen = aRefList.getLength();
721 DBG_ASSERT( aAnchorList.getLength(), "*IndexTabPage_Impl::InitializeIndex(): AnchorList is empty!" ); \
722 DBG_ASSERT( nRefListLen, "*IndexTabPage_Impl::InitializeIndex(): RefList is empty!" ); \
724 if ( aAnchorList.getLength() && nRefListLen )
726 INSERT_DATA( 0 );
729 for ( sal_uInt32 j = 1; j < nRefListLen ; ++j )
731 aData
732 .append( aKeywordPair )
733 .append( sal_Unicode(' ') )
734 .append( sal_Unicode('-') )
735 .append( sal_Unicode(' ') )
736 .append( aTitleList[j] );
738 aTempString = aData.makeStringAndClear();
739 UNIFY_AND_INSERT_TOKEN( aTempString );
740 INSERT_DATA( j );
746 catch( Exception& )
748 DBG_ERROR( "IndexTabPage_Impl::InitializeIndex(): unexpected exception" );
751 aIndexCB.SetUpdateMode( TRUE );
753 if ( sKeyword.Len() > 0 )
754 aKeywordLink.Call( this );
757 #undef INSERT_DATA
758 #undef UNIFY_AND_INSERT_TOKEN
760 // -----------------------------------------------------------------------
762 void IndexTabPage_Impl::ClearIndex()
764 USHORT nCount = aIndexCB.GetEntryCount();
765 for ( USHORT i = 0; i < nCount; ++i )
766 delete (IndexEntry_Impl*)(ULONG)aIndexCB.GetEntryData(i);
767 aIndexCB.Clear();
770 // -----------------------------------------------------------------------
772 IMPL_LINK( IndexTabPage_Impl, OpenHdl, PushButton*, EMPTYARG )
774 aIndexCB.GetDoubleClickHdl().Call( &aIndexCB );
775 return 0;
778 // -----------------------------------------------------------------------
780 IMPL_LINK( IndexTabPage_Impl, TimeoutHdl, Timer*, pTimer )
782 if ( &aFactoryTimer == pTimer )
783 InitializeIndex();
784 else if ( &aKeywordTimer == pTimer && sKeyword.Len() > 0 )
785 aKeywordLink.Call( this );
786 return 0;
789 // -----------------------------------------------------------------------
791 void IndexTabPage_Impl::Resize()
793 Size aSize = GetSizePixel();
794 if ( aSize.Width() < nMinWidth )
795 aSize.Width() = nMinWidth;
796 Point aPnt = aExpressionFT.GetPosPixel();
797 Size aNewSize = aExpressionFT.GetSizePixel();
798 aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
799 aExpressionFT.SetSizePixel( aNewSize );
801 Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
802 Size aBtnSize = aOpenBtn.GetSizePixel();
804 aPnt = aIndexCB.GetPosPixel();
805 aNewSize = aIndexCB.GetSizePixel();
806 aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
807 aNewSize.Height() = aSize.Height() - aPnt.Y();
808 aNewSize.Height() -= ( aBtnSize.Height() + ( a6Size.Height() * 3 / 2 ) );
809 aIndexCB.SetSizePixel( aNewSize );
811 aPnt.X() += ( aNewSize.Width() - aBtnSize.Width() );
812 aPnt.Y() += aNewSize.Height() + ( a6Size.Height() / 2 );
813 long nMinX = aIndexCB.GetPosPixel().X();
814 if ( aPnt.X() < nMinX )
815 aPnt.X() = nMinX;
816 aOpenBtn.SetPosPixel( aPnt );
819 // -----------------------------------------------------------------------
821 void IndexTabPage_Impl::ActivatePage()
823 if ( !bIsActivated )
825 bIsActivated = sal_True;
826 aFactoryTimer.Start();
829 if ( !m_pIdxWin->WasCursorLeftOrRight() )
830 SetFocusOnBox();
833 // -----------------------------------------------------------------------
835 Control* IndexTabPage_Impl::GetLastFocusControl()
837 return &aOpenBtn;
840 // -----------------------------------------------------------------------
842 void IndexTabPage_Impl::SetDoubleClickHdl( const Link& rLink )
844 aIndexCB.SetDoubleClickHdl( rLink );
847 // -----------------------------------------------------------------------
849 void IndexTabPage_Impl::SetFactory( const String& rFactory )
851 String sNewFactory( rFactory );
852 DBG_ASSERT( sNewFactory.Len() > 0, "empty factory" );
853 bool bValid = m_pIdxWin->IsValidFactory( rFactory );
855 if ( sFactory.Len() == 0 && !bValid )
857 sNewFactory = SfxHelp::GetDefaultHelpModule();
858 bValid = true;
861 if ( sNewFactory != sFactory && bValid )
863 sFactory = sNewFactory;
864 ClearIndex();
865 if ( bIsActivated )
866 aFactoryTimer.Start();
870 // -----------------------------------------------------------------------
872 String IndexTabPage_Impl::GetSelectEntry() const
874 String aRet;
875 IndexEntry_Impl* pEntry = (IndexEntry_Impl*)(ULONG)aIndexCB.GetEntryData( aIndexCB.GetEntryPos( aIndexCB.GetText() ) );
876 if ( pEntry )
877 aRet = pEntry->m_aURL;
878 return aRet;
881 // -----------------------------------------------------------------------
883 void IndexTabPage_Impl::SetKeyword( const String& rKeyword )
885 sKeyword = rKeyword;
887 if ( aIndexCB.GetEntryCount() > 0 )
888 aKeywordTimer.Start();
889 else if ( !bIsActivated )
890 aFactoryTimer.Start();
893 // -----------------------------------------------------------------------
895 sal_Bool IndexTabPage_Impl::HasKeyword() const
897 sal_Bool bRet = sal_False;
898 if ( sKeyword.Len() > 0 )
900 USHORT nPos = aIndexCB.GetEntryPos( sKeyword );
901 bRet = ( nPos != LISTBOX_ENTRY_NOTFOUND );
904 return bRet;
907 // -----------------------------------------------------------------------
908 //added by BerryJia for fixing Bug98251, 2002-12-11
909 sal_Bool IndexTabPage_Impl::HasKeywordIgnoreCase()
911 sal_Bool bRet = sal_False;
912 if ( sKeyword.Len() > 0 )
914 USHORT nEntries = aIndexCB.GetEntryCount();
915 String sIndexItem;
916 const vcl::I18nHelper& rI18nHelper = GetSettings().GetLocaleI18nHelper();
917 for ( USHORT n = 0; n < nEntries; n++)
919 sIndexItem = aIndexCB.GetEntry( n );
920 if (rI18nHelper.MatchString( sIndexItem, sKeyword ))
922 sKeyword = sIndexItem;
923 bRet = sal_True;
928 return bRet;
931 // -----------------------------------------------------------------------
933 void IndexTabPage_Impl::OpenKeyword()
935 if ( sKeyword.Len() > 0 )
937 aIndexCB.SetText( sKeyword );
938 aIndexCB.GetDoubleClickHdl().Call( NULL );
939 sKeyword.Erase();
943 // class SearchBox_Impl --------------------------------------------------
945 long SearchBox_Impl::PreNotify( NotifyEvent& rNEvt )
947 sal_Bool bHandled = sal_False;
948 if ( !IsInDropDown() &&
949 rNEvt.GetWindow() == GetSubEdit() &&
950 rNEvt.GetType() == EVENT_KEYINPUT &&
951 KEY_RETURN == rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
953 aSearchLink.Call( NULL );
954 bHandled = sal_True;
956 return bHandled ? 1 : ComboBox::PreNotify( rNEvt );
959 // -----------------------------------------------------------------------
961 void SearchBox_Impl::Select()
963 if ( !IsTravelSelect() )
964 aSearchLink.Call( NULL );
967 // class SearchResultsBox_Impl -------------------------------------------
969 long SearchResultsBox_Impl::Notify( NotifyEvent& rNEvt )
971 sal_Bool bHandled = sal_False;
972 if ( rNEvt.GetType() == EVENT_KEYINPUT &&
973 KEY_RETURN == rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
975 GetDoubleClickHdl().Call( NULL );
976 bHandled = sal_True;
979 return bHandled ? 1 : ListBox::Notify( rNEvt );
982 // class SearchTabPage_Impl ----------------------------------------------
984 SearchTabPage_Impl::SearchTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ) :
986 HelpTabPage_Impl( pParent, _pIdxWin, SfxResId( TP_HELP_SEARCH ) ),
988 aSearchFT ( this, SfxResId( FT_SEARCH ) ),
989 aSearchED ( this, SfxResId( ED_SEARCH ) ),
990 aSearchBtn ( this, SfxResId( PB_SEARCH ) ),
991 aFullWordsCB ( this, SfxResId( CB_FULLWORDS ) ),
992 aScopeCB ( this, SfxResId( CB_SCOPE ) ),
993 aResultsLB ( this, SfxResId( LB_RESULT ) ),
994 aOpenBtn ( this, SfxResId( PB_OPEN_SEARCH ) ),
995 xBreakIterator ( vcl::unohelper::CreateBreakIterator() )
998 FreeResource();
1000 Link aLink = LINK( this, SearchTabPage_Impl, SearchHdl );
1001 aSearchED.SetSearchLink( aLink );
1002 aSearchBtn.SetClickHdl( aLink );
1003 aSearchED.SetModifyHdl( LINK( this, SearchTabPage_Impl, ModifyHdl ) );
1004 aOpenBtn.SetClickHdl( LINK( this, SearchTabPage_Impl, OpenHdl ) );
1006 aMinSize = GetSizePixel();
1008 SvtViewOptions aViewOpt( E_TABPAGE, CONFIGNAME_SEARCHPAGE );
1009 if ( aViewOpt.Exists() )
1011 String aUserData;
1012 Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
1013 ::rtl::OUString aTemp;
1014 if ( aUserItem >>= aTemp )
1016 aUserData = String( aTemp );
1017 BOOL bChecked = ( 1 == aUserData.GetToken(0).ToInt32() ) ? TRUE : FALSE;
1018 aFullWordsCB.Check( bChecked );
1019 bChecked = ( 1 == aUserData.GetToken(1).ToInt32() ) ? TRUE : FALSE;
1020 aScopeCB.Check( bChecked );
1022 for ( USHORT i = 2; i < aUserData.GetTokenCount(); ++i )
1024 String aToken = aUserData.GetToken(i);
1025 aSearchED.InsertEntry( INetURLObject::decode(
1026 aToken, '%', INetURLObject::DECODE_WITH_CHARSET ) );
1031 ModifyHdl( &aSearchED );
1034 // -----------------------------------------------------------------------
1036 SearchTabPage_Impl::~SearchTabPage_Impl()
1038 SvtViewOptions aViewOpt( E_TABPAGE, CONFIGNAME_SEARCHPAGE );
1039 sal_Int32 nChecked = aFullWordsCB.IsChecked() ? 1 : 0;
1040 String aUserData = String::CreateFromInt32( nChecked );
1041 aUserData += ';';
1042 nChecked = aScopeCB.IsChecked() ? 1 : 0;
1043 aUserData += String::CreateFromInt32( nChecked );
1044 aUserData += ';';
1045 USHORT nCount = Min( aSearchED.GetEntryCount(), (USHORT)10 ); // save only 10 entries
1047 for ( USHORT i = 0; i < nCount; ++i )
1049 rtl::OUString aText = aSearchED.GetEntry(i);
1050 aUserData += String(INetURLObject::encode(
1051 aText, INetURLObject::PART_UNO_PARAM_VALUE, '%',
1052 INetURLObject::ENCODE_ALL ));
1053 aUserData += ';';
1056 aUserData.EraseTrailingChars(';');
1057 Any aUserItem = makeAny( ::rtl::OUString( aUserData ) );
1058 aViewOpt.SetUserItem( USERITEM_NAME, aUserItem );
1061 // -----------------------------------------------------------------------
1063 void SearchTabPage_Impl::ClearSearchResults()
1065 USHORT nCount = aResultsLB.GetEntryCount();
1066 for ( USHORT i = 0; i < nCount; ++i )
1067 delete (String*)(ULONG)aResultsLB.GetEntryData(i);
1068 aResultsLB.Clear();
1069 aResultsLB.Update();
1072 // -----------------------------------------------------------------------
1074 void SearchTabPage_Impl::RememberSearchText( const String& rSearchText )
1076 for ( USHORT i = 0; i < aSearchED.GetEntryCount(); ++i )
1078 if ( rSearchText == aSearchED.GetEntry(i) )
1080 aSearchED.RemoveEntry(i);
1081 break;
1085 aSearchED.InsertEntry( rSearchText, 0 );
1088 // -----------------------------------------------------------------------
1090 IMPL_LINK( SearchTabPage_Impl, SearchHdl, PushButton*, EMPTYARG )
1092 String aSearchText = TRIM( aSearchED.GetText() );
1093 if ( aSearchText.Len() > 0 )
1095 EnterWait();
1096 ClearSearchResults();
1097 RememberSearchText( aSearchText );
1098 String aSearchURL = HELP_URL;
1099 aSearchURL += aFactory;
1100 aSearchURL += String( HELP_SEARCH_TAG );
1101 if ( !aFullWordsCB.IsChecked() )
1102 aSearchText = sfx2::PrepareSearchString( aSearchText, xBreakIterator, true );
1103 aSearchURL += aSearchText;
1104 AppendConfigToken_Impl( aSearchURL, sal_False );
1105 if ( aScopeCB.IsChecked() )
1106 aSearchURL += DEFINE_CONST_UNICODE("&Scope=Heading");
1107 Sequence< ::rtl::OUString > aFactories = SfxContentHelper::GetResultSet( aSearchURL );
1108 const ::rtl::OUString* pFacs = aFactories.getConstArray();
1109 UINT32 i, nCount = aFactories.getLength();
1110 for ( i = 0; i < nCount; ++i )
1112 String aRow( pFacs[i] );
1113 String aTitle, aType;
1114 xub_StrLen nIdx = 0;
1115 aTitle = aRow.GetToken( 0, '\t', nIdx );
1116 aType = aRow.GetToken( 0, '\t', nIdx );
1117 String* pURL = new String( aRow.GetToken( 0, '\t', nIdx ) );
1118 USHORT nPos = aResultsLB.InsertEntry( aTitle );
1119 aResultsLB.SetEntryData( nPos, (void*)(ULONG)pURL );
1121 LeaveWait();
1123 if ( !nCount )
1125 InfoBox aBox( this, SfxResId( RID_INFO_NOSEARCHRESULTS ) );
1126 aBox.SetText( String( SfxResId( STR_HELP_WINDOW_TITLE ) ) );
1127 aBox.Execute();
1130 return 0;
1133 // -----------------------------------------------------------------------
1135 IMPL_LINK( SearchTabPage_Impl, OpenHdl, PushButton*, EMPTYARG )
1137 aResultsLB.GetDoubleClickHdl().Call( &aResultsLB );
1138 return 0;
1141 // -----------------------------------------------------------------------
1143 IMPL_LINK( SearchTabPage_Impl, ModifyHdl, Edit*, EMPTYARG )
1145 String aSearchText = TRIM( aSearchED.GetText() );
1146 aSearchBtn.Enable( aSearchText.Len() > 0 );
1147 return 0;
1150 // -----------------------------------------------------------------------
1152 void SearchTabPage_Impl::Resize()
1154 Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
1155 Size aSize = GetSizePixel();
1156 if ( aSize.Width() < aMinSize.Width() )
1157 aSize.Width() = aMinSize.Width();
1158 Point aPnt = aSearchFT.GetPosPixel();
1159 Size aNewSize = aSearchFT.GetSizePixel();
1160 aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
1161 aSearchFT.SetSizePixel( aNewSize );
1162 aNewSize.Height() = aResultsLB.GetSizePixel().Height();
1163 aResultsLB.SetSizePixel( aNewSize );
1164 aNewSize.Height() = aFullWordsCB.GetSizePixel().Height();
1165 aFullWordsCB.SetSizePixel( aNewSize );
1166 aScopeCB.SetSizePixel( aNewSize );
1167 aNewSize = aSearchED.GetSizePixel();
1168 aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 ) -
1169 ( aSearchBtn.GetSizePixel().Width() + ( aPnt.X() / 2 ) );
1170 aSearchED.SetSizePixel( aNewSize );
1171 Point aNewPnt = aSearchBtn.GetPosPixel();
1172 aNewPnt.X() = aPnt.X() + aNewSize.Width() + ( aPnt.X() / 2 );
1173 aSearchBtn.SetPosPixel( aNewPnt );
1175 if ( aSize.Height() > aMinSize.Height() )
1177 long n3Height = a6Size.Height() / 2;
1178 Size aBtnSize = aOpenBtn.GetSizePixel();
1179 long nExtraHeight = aBtnSize.Height() + n3Height;
1181 aPnt = aResultsLB.GetPosPixel();
1182 aNewSize = aResultsLB.GetSizePixel();
1183 aNewSize.Height() = aSize.Height() - aPnt.Y();
1184 aNewSize.Height() -= ( nExtraHeight + ( a6Size.Height() * 3 / 2 ) );
1185 aResultsLB.SetSizePixel( aNewSize );
1187 aPnt.X() += ( aNewSize.Width() - aBtnSize.Width() );
1188 aPnt.Y() += aNewSize.Height() + a6Size.Height();
1189 aOpenBtn.SetPosPixel( aPnt );
1193 // -----------------------------------------------------------------------
1195 void SearchTabPage_Impl::ActivatePage()
1197 if ( !m_pIdxWin->WasCursorLeftOrRight() )
1198 aSearchED.GrabFocus();
1201 // -----------------------------------------------------------------------
1203 Control* SearchTabPage_Impl::GetLastFocusControl()
1205 return &aOpenBtn;
1208 // -----------------------------------------------------------------------
1210 void SearchTabPage_Impl::SetDoubleClickHdl( const Link& rLink )
1212 aResultsLB.SetDoubleClickHdl( rLink );
1215 // -----------------------------------------------------------------------
1217 String SearchTabPage_Impl::GetSelectEntry() const
1219 String aRet;
1220 String* pData = (String*)(ULONG)aResultsLB.GetEntryData( aResultsLB.GetSelectEntryPos() );
1221 if ( pData )
1222 aRet = String( *pData );
1223 return aRet;
1226 // -----------------------------------------------------------------------
1228 void SearchTabPage_Impl::ClearPage()
1230 ClearSearchResults();
1231 aSearchED.SetText( String() );
1234 // -----------------------------------------------------------------------
1236 sal_Bool SearchTabPage_Impl::OpenKeyword( const String& rKeyword )
1238 sal_Bool bRet = sal_False;
1239 aSearchED.SetText( rKeyword );
1240 SearchHdl( NULL );
1241 if ( aResultsLB.GetEntryCount() > 0 )
1243 // found keyword -> open it
1244 aResultsLB.SelectEntryPos(0);
1245 OpenHdl( NULL );
1246 bRet = sal_True;
1249 return bRet;
1252 // class BookmarksTabPage_Impl -------------------------------------------
1254 void GetBookmarkEntry_Impl
1256 Sequence< PropertyValue >& aBookmarkEntry,
1257 ::rtl::OUString& rTitle,
1258 ::rtl::OUString& rURL
1261 for ( int i = 0; i < aBookmarkEntry.getLength(); i++ )
1263 PropertyValue aValue = aBookmarkEntry[i];
1264 if ( aValue.Name == HISTORY_PROPERTYNAME_URL )
1265 aValue.Value >>= rURL;
1266 else if ( aValue.Name == HISTORY_PROPERTYNAME_TITLE )
1267 aValue.Value >>= rTitle;
1271 // -----------------------------------------------------------------------
1273 BookmarksBox_Impl::BookmarksBox_Impl( Window* pParent, const ResId& rResId ) :
1275 ListBox( pParent, rResId )
1280 // -----------------------------------------------------------------------
1282 BookmarksBox_Impl::~BookmarksBox_Impl()
1284 // save bookmarks to configuration
1285 SvtHistoryOptions aHistOpt;
1286 aHistOpt.Clear( eHELPBOOKMARKS );
1287 rtl::OUString sEmpty;
1288 USHORT nCount = GetEntryCount();
1289 for ( USHORT i = 0; i < nCount; ++i )
1291 String aTitle = GetEntry(i);
1292 String* pURL = (String*)(ULONG)GetEntryData(i);
1293 aHistOpt.AppendItem( eHELPBOOKMARKS, rtl::OUString( *pURL ), sEmpty, rtl::OUString( aTitle ), sEmpty );
1294 delete pURL;
1298 // -----------------------------------------------------------------------
1300 void BookmarksBox_Impl::DoAction( USHORT nAction )
1302 switch ( nAction )
1304 case MID_OPEN :
1305 GetDoubleClickHdl().Call( NULL );
1306 break;
1308 case MID_RENAME :
1310 USHORT nPos = GetSelectEntryPos();
1311 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1313 SfxAddHelpBookmarkDialog_Impl aDlg( this, sal_True );
1314 aDlg.SetTitle( GetEntry( nPos ) );
1315 if ( aDlg.Execute() == RET_OK )
1317 String* pURL = (String*)(ULONG)GetEntryData( nPos );
1318 RemoveEntry( nPos );
1319 rtl::OUString aImageURL = IMAGE_URL;
1320 aImageURL += INetURLObject( *pURL ).GetHost();
1321 nPos = InsertEntry( aDlg.GetTitle(), SvFileInformationManager::GetImage( aImageURL ) );
1322 SetEntryData( nPos, (void*)(ULONG)( new String( *pURL ) ) );
1323 SelectEntryPos( nPos );
1324 delete pURL;
1327 break;
1330 case MID_DELETE :
1332 USHORT nPos = GetSelectEntryPos();
1333 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1335 RemoveEntry( nPos );
1336 USHORT nCount = GetEntryCount();
1337 if ( nCount )
1339 if ( nPos >= nCount )
1340 nPos = nCount - 1;
1341 SelectEntryPos( nPos );
1344 break;
1349 // -----------------------------------------------------------------------
1351 long BookmarksBox_Impl::Notify( NotifyEvent& rNEvt )
1353 long nRet = 0;
1354 USHORT nType = rNEvt.GetType();
1355 if ( EVENT_KEYINPUT == nType )
1357 USHORT nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
1358 if ( KEY_DELETE == nCode && GetEntryCount() > 0 )
1360 DoAction( MID_DELETE );
1361 nRet = 1;
1363 else if ( KEY_RETURN == nCode )
1365 GetDoubleClickHdl().Call( NULL );
1366 nRet = 1;
1369 else if ( EVENT_COMMAND == nType )
1371 const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
1372 if ( pCEvt->GetCommand() == COMMAND_CONTEXTMENU )
1374 PopupMenu aMenu( SfxResId( MENU_HELP_BOOKMARKS ) );
1375 sal_uInt16 nId = aMenu.Execute( this, pCEvt->GetMousePosPixel() );
1376 if ( nId != MENU_ITEM_NOTFOUND )
1377 DoAction( nId );
1378 nRet = 1;
1382 return nRet ? nRet : ListBox::Notify( rNEvt );
1385 // class BookmarksTabPage_Impl -------------------------------------------
1387 BookmarksTabPage_Impl::BookmarksTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ) :
1389 HelpTabPage_Impl( pParent, _pIdxWin, SfxResId( TP_HELP_BOOKMARKS ) ),
1391 aBookmarksFT ( this, SfxResId( FT_BOOKMARKS ) ),
1392 aBookmarksBox ( this, SfxResId( LB_BOOKMARKS ) ),
1393 aBookmarksPB ( this, SfxResId( PB_BOOKMARKS ) )
1396 FreeResource();
1398 nMinWidth = aBookmarksPB.GetSizePixel().Width();
1400 aBookmarksPB.SetClickHdl( LINK( this, BookmarksTabPage_Impl, OpenHdl ) );
1402 // load bookmarks from configuration
1403 Sequence< Sequence< PropertyValue > > aBookmarkSeq;
1404 aBookmarkSeq = SvtHistoryOptions().GetList( eHELPBOOKMARKS );
1406 ::rtl::OUString aTitle;
1407 ::rtl::OUString aURL;
1409 UINT32 i, nCount = aBookmarkSeq.getLength();
1410 for ( i = 0; i < nCount; ++i )
1412 GetBookmarkEntry_Impl( aBookmarkSeq[i], aTitle, aURL );
1413 AddBookmarks( aTitle, aURL );
1417 // -----------------------------------------------------------------------
1419 IMPL_LINK( BookmarksTabPage_Impl, OpenHdl, PushButton*, EMPTYARG )
1421 aBookmarksBox.GetDoubleClickHdl().Call( &aBookmarksBox );
1422 return 0;
1425 // -----------------------------------------------------------------------
1427 void BookmarksTabPage_Impl::Resize()
1429 Size aSize = GetSizePixel();
1430 if ( aSize.Width() < nMinWidth )
1431 aSize.Width() = nMinWidth;
1432 Point aPnt = aBookmarksFT.GetPosPixel();
1433 Size aNewSize = aBookmarksFT.GetSizePixel();
1434 aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
1435 aBookmarksFT.SetSizePixel( aNewSize );
1437 Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
1438 Size aBtnSize = aBookmarksPB.GetSizePixel();
1440 aPnt = aBookmarksBox.GetPosPixel();
1441 aNewSize = aBookmarksBox.GetSizePixel();
1442 aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
1443 aNewSize.Height() = aSize.Height() - aPnt.Y();
1444 aNewSize.Height() -= ( aBtnSize.Height() + ( a6Size.Height() * 3 / 2 ) );
1445 aBookmarksBox.SetSizePixel( aNewSize );
1447 aPnt.X() += ( aNewSize.Width() - aBtnSize.Width() );
1448 aPnt.Y() += aNewSize.Height() + ( a6Size.Height() / 2 );
1449 long nMinX = aBookmarksBox.GetPosPixel().X();
1450 if ( aPnt.X() < nMinX )
1451 aPnt.X() = nMinX;
1452 aBookmarksPB.SetPosPixel( aPnt );
1455 // -----------------------------------------------------------------------
1457 void BookmarksTabPage_Impl::ActivatePage()
1459 if ( !m_pIdxWin->WasCursorLeftOrRight() )
1460 SetFocusOnBox();
1463 // -----------------------------------------------------------------------
1465 Control* BookmarksTabPage_Impl::GetLastFocusControl()
1467 return &aBookmarksPB;
1470 // -----------------------------------------------------------------------
1472 void BookmarksTabPage_Impl::SetDoubleClickHdl( const Link& rLink )
1474 aBookmarksBox.SetDoubleClickHdl( rLink );
1477 // -----------------------------------------------------------------------
1479 String BookmarksTabPage_Impl::GetSelectEntry() const
1481 String aRet;
1482 String* pData = (String*)(ULONG)aBookmarksBox.GetEntryData( aBookmarksBox.GetSelectEntryPos() );
1483 if ( pData )
1484 aRet = String( *pData );
1485 return aRet;
1488 // -----------------------------------------------------------------------
1490 void BookmarksTabPage_Impl::AddBookmarks( const String& rTitle, const String& rURL )
1492 rtl::OUString aImageURL = IMAGE_URL;
1493 aImageURL += INetURLObject( rURL ).GetHost();
1494 USHORT nPos = aBookmarksBox.InsertEntry( rTitle, SvFileInformationManager::GetImage( aImageURL ) );
1495 aBookmarksBox.SetEntryData( nPos, (void*)(ULONG)( new String( rURL ) ) );
1498 // class SfxHelpIndexWindow_Impl -----------------------------------------
1500 sal_Bool SfxHelpWindow_Impl::splitHelpURL(const ::rtl::OUString& sHelpURL,
1501 ::rtl::OUString& sFactory,
1502 ::rtl::OUString& sContent,
1503 ::rtl::OUString& sAnchor )
1505 Reference < XURLTransformer > xParser( ::comphelper::getProcessServiceFactory()->createInstance(
1506 DEFINE_CONST_UNICODE("com.sun.star.util.URLTransformer" )), UNO_QUERY_THROW );
1508 URL aURL;
1509 aURL.Complete = sHelpURL;
1510 sal_Bool bResult = xParser->parseStrict(aURL);
1512 sFactory = aURL.Server;
1513 sContent = aURL.Path.copy(1); // strip "/"!
1514 sAnchor = aURL.Mark;
1516 return bResult;
1519 ::rtl::OUString SfxHelpWindow_Impl::buildHelpURL(const ::rtl::OUString& sFactory ,
1520 const ::rtl::OUString& sContent ,
1521 const ::rtl::OUString& sAnchor ,
1522 sal_Bool bUseQuestionMark)
1524 ::rtl::OUStringBuffer sHelpURL(256);
1525 sHelpURL.append(HELP_URL);
1526 sHelpURL.append(sFactory);
1527 sHelpURL.append(sContent);
1528 String sURL = String(sHelpURL.makeStringAndClear());
1529 AppendConfigToken_Impl(sURL, bUseQuestionMark);
1530 if (sAnchor.getLength())
1531 sURL += String(sAnchor);
1532 return ::rtl::OUString(sURL);
1535 void SfxHelpWindow_Impl::loadHelpContent(const ::rtl::OUString& sHelpURL, sal_Bool bAddToHistory)
1537 Reference< XComponentLoader > xLoader(getTextFrame(), UNO_QUERY);
1538 if (!xLoader.is())
1539 return;
1541 // --> PB 2007-03-12 #134037#
1542 // If a print job runs do not open a new page
1543 Reference< XFrame > xTextFrame = pTextWin->getFrame();
1544 Reference< XController > xTextController ;
1545 if (xTextFrame.is())
1546 xTextController = xTextFrame->getController ();
1547 if ( xTextController.is() && !xTextController->suspend( sal_True ) )
1549 xTextController->suspend( sal_False );
1550 return;
1552 // <--
1554 // save url to history
1555 if (bAddToHistory)
1556 pHelpInterceptor->addURL(sHelpURL);
1558 if ( !IsWait() )
1559 EnterWait();
1560 sal_Bool bSuccess = sal_False;
1561 // TODO implement locale fallback ... see below while(sal_True)
1565 Reference< XComponent > xContent = xLoader->loadComponentFromURL(sHelpURL, DEFINE_CONST_UNICODE("_self"), 0, Sequence< PropertyValue >());
1566 if (xContent.is())
1568 bSuccess = sal_True;
1569 // break;
1572 catch(const RuntimeException&)
1573 { throw; }
1574 catch(const Exception&)
1575 { /*break;*/ }
1577 /* TODO try next locale ...
1578 no further locale available? => break loop and show error page
1581 openDone(sHelpURL, bSuccess);
1582 if ( IsWait() )
1583 LeaveWait();
1586 SfxHelpIndexWindow_Impl::SfxHelpIndexWindow_Impl( SfxHelpWindow_Impl* _pParent ) :
1588 Window( _pParent, SfxResId( WIN_HELPINDEX ) ),
1590 aActiveLB ( this, SfxResId( LB_ACTIVE ) ),
1591 aActiveLine ( this, SfxResId( FL_ACTIVE ) ),
1592 aTabCtrl ( this, SfxResId( TC_INDEX ) ),
1594 aIndexKeywordLink ( LINK( this, SfxHelpIndexWindow_Impl, KeywordHdl ) ),
1595 pParentWin ( _pParent ),
1597 pCPage ( NULL ),
1598 pIPage ( NULL ),
1599 pSPage ( NULL ),
1600 pBPage ( NULL ),
1602 bWasCursorLeftOrRight( false ),
1603 bIsInitDone ( false )
1606 FreeResource();
1608 sfx2::AddToTaskPaneList( this );
1610 aTabCtrl.SetActivatePageHdl( LINK( this, SfxHelpIndexWindow_Impl, ActivatePageHdl ) );
1611 aTabCtrl.Show();
1613 sal_Int32 nPageId = HELP_INDEX_PAGE_INDEX;
1614 SvtViewOptions aViewOpt( E_TABDIALOG, CONFIGNAME_INDEXWIN );
1615 if ( aViewOpt.Exists() )
1616 nPageId = aViewOpt.GetPageID();
1617 aTabCtrl.SetCurPageId( (USHORT)nPageId );
1618 ActivatePageHdl( &aTabCtrl );
1619 aActiveLB.SetSelectHdl( LINK( this, SfxHelpIndexWindow_Impl, SelectHdl ) );
1620 nMinWidth = ( aActiveLB.GetSizePixel().Width() / 2 );
1622 aTimer.SetTimeoutHdl( LINK( this, SfxHelpIndexWindow_Impl, InitHdl ) );
1623 aTimer.SetTimeout( 200 );
1624 aTimer.Start();
1627 // -----------------------------------------------------------------------
1629 SfxHelpIndexWindow_Impl::~SfxHelpIndexWindow_Impl()
1631 sfx2::RemoveFromTaskPaneList( this );
1633 DELETEZ( pCPage );
1634 DELETEZ( pIPage );
1635 DELETEZ( pSPage );
1636 DELETEZ( pBPage );
1638 for ( USHORT i = 0; i < aActiveLB.GetEntryCount(); ++i )
1639 delete (String*)(ULONG)aActiveLB.GetEntryData(i);
1641 SvtViewOptions aViewOpt( E_TABDIALOG, CONFIGNAME_INDEXWIN );
1642 aViewOpt.SetPageID( (sal_Int32)aTabCtrl.GetCurPageId() );
1645 // -----------------------------------------------------------------------
1647 void SfxHelpIndexWindow_Impl::Initialize()
1649 String aHelpURL = HELP_URL;
1650 AppendConfigToken_Impl( aHelpURL, sal_True );
1651 Sequence< ::rtl::OUString > aFactories = SfxContentHelper::GetResultSet( aHelpURL );
1652 const ::rtl::OUString* pFacs = aFactories.getConstArray();
1653 UINT32 i, nCount = aFactories.getLength();
1654 for ( i = 0; i < nCount; ++i )
1656 String aRow( pFacs[i] );
1657 String aTitle, aType, aURL;
1658 xub_StrLen nIdx = 0;
1659 aTitle = aRow.GetToken( 0, '\t', nIdx );
1660 aType = aRow.GetToken( 0, '\t', nIdx );
1661 aURL = aRow.GetToken( 0, '\t', nIdx );
1662 String* pFactory = new String( INetURLObject( aURL ).GetHost() );
1663 USHORT nPos = aActiveLB.InsertEntry( aTitle );
1664 aActiveLB.SetEntryData( nPos, (void*)(ULONG)pFactory );
1667 aActiveLB.SetDropDownLineCount( (USHORT)nCount );
1668 if ( aActiveLB.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND )
1669 SetActiveFactory();
1672 // -----------------------------------------------------------------------
1674 void SfxHelpIndexWindow_Impl::SetActiveFactory()
1676 DBG_ASSERT( pIPage, "index page not initialized" );
1677 if ( !bIsInitDone && !aActiveLB.GetEntryCount() )
1679 aTimer.Stop();
1680 InitHdl( NULL );
1683 for ( USHORT i = 0; i < aActiveLB.GetEntryCount(); ++i )
1685 String* pFactory = (String*)(ULONG)aActiveLB.GetEntryData(i);
1686 pFactory->ToLowerAscii();
1687 if ( *pFactory == pIPage->GetFactory() )
1689 if ( aActiveLB.GetSelectEntryPos() != i )
1691 aActiveLB.SelectEntryPos(i);
1692 aSelectFactoryLink.Call( NULL );
1694 break;
1699 // -----------------------------------------------------------------------
1701 HelpTabPage_Impl* SfxHelpIndexWindow_Impl::GetCurrentPage( USHORT& rCurId )
1703 rCurId = aTabCtrl.GetCurPageId();
1704 HelpTabPage_Impl* pPage = NULL;
1706 switch ( rCurId )
1708 case HELP_INDEX_PAGE_CONTENTS:
1710 pPage = GetContentPage();
1711 break;
1714 case HELP_INDEX_PAGE_INDEX:
1716 pPage = GetIndexPage();
1717 break;
1720 case HELP_INDEX_PAGE_SEARCH:
1722 pPage = GetSearchPage();
1723 break;
1726 case HELP_INDEX_PAGE_BOOKMARKS:
1728 pPage = GetBookmarksPage();
1729 break;
1733 DBG_ASSERT( pPage, "SfxHelpIndexWindow_Impl::GetCurrentPage(): no current page" );
1734 return pPage;
1737 // -----------------------------------------------------------------------
1739 IMPL_LINK( SfxHelpIndexWindow_Impl, ActivatePageHdl, TabControl *, pTabCtrl )
1741 USHORT nId = 0;
1742 TabPage* pPage = GetCurrentPage( nId );
1743 pTabCtrl->SetTabPage( nId, pPage );
1744 return 0;
1747 // -----------------------------------------------------------------------
1749 IMPL_LINK( SfxHelpIndexWindow_Impl, SelectHdl, ListBox *, EMPTYARG )
1751 aTimer.Start();
1753 return 0;
1756 // -----------------------------------------------------------------------
1758 IMPL_LINK( SfxHelpIndexWindow_Impl, InitHdl, Timer *, EMPTYARG )
1760 bIsInitDone = true;
1761 Initialize();
1763 // now use the timer for selection
1764 aTimer.SetTimeoutHdl( LINK( this, SfxHelpIndexWindow_Impl, SelectFactoryHdl ) );
1765 aTimer.SetTimeout( 1000 );
1767 return 0;
1770 // -----------------------------------------------------------------------
1772 IMPL_LINK( SfxHelpIndexWindow_Impl, SelectFactoryHdl, Timer *, EMPTYARG )
1774 String* pFactory = (String*)(ULONG)aActiveLB.GetEntryData( aActiveLB.GetSelectEntryPos() );
1775 if ( pFactory )
1777 String aFactory( *pFactory );
1778 aFactory.ToLowerAscii();
1779 SetFactory( aFactory, sal_False );
1780 aSelectFactoryLink.Call( this );
1783 return 0;
1786 // -----------------------------------------------------------------------
1788 IMPL_LINK( SfxHelpIndexWindow_Impl, KeywordHdl, IndexTabPage_Impl *, EMPTYARG )
1790 // keyword found on index?
1791 sal_Bool bIndex = pIPage->HasKeyword();
1792 //The following two lines are added by BerryJia for fixing Bug98251, 2002-12-11
1793 if( !bIndex)
1794 bIndex = pIPage->HasKeywordIgnoreCase();
1795 // then set index or search page as current.
1796 USHORT nPageId = ( bIndex ) ? HELP_INDEX_PAGE_INDEX : HELP_INDEX_PAGE_SEARCH;
1797 if ( nPageId != aTabCtrl.GetCurPageId() )
1799 aTabCtrl.SetCurPageId( nPageId );
1800 ActivatePageHdl( &aTabCtrl );
1803 // at last we open the keyword
1804 if ( bIndex )
1805 pIPage->OpenKeyword();
1806 else if ( !pSPage->OpenKeyword( sKeyword ) )
1807 pParentWin->ShowStartPage();
1809 return 0;
1812 // -----------------------------------------------------------------------
1814 void SfxHelpIndexWindow_Impl::Resize()
1816 Size aSize = GetOutputSizePixel();
1817 if ( aSize.Width() < nMinWidth )
1818 aSize.Width() = nMinWidth;
1820 Point aPnt = aActiveLB.GetPosPixel();
1821 Size aNewSize = aActiveLB.GetSizePixel();
1822 aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
1823 aActiveLB.SetSizePixel( aNewSize );
1824 aPnt = aActiveLine.GetPosPixel();
1825 aNewSize = aActiveLine.GetSizePixel();
1826 aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
1827 aActiveLine.SetSizePixel( aNewSize );
1828 aPnt = aTabCtrl.GetPosPixel();
1829 aNewSize = aSize;
1830 aSize.Width() -= aPnt.X();
1831 aSize.Height() -= aPnt.Y();
1832 aTabCtrl.SetSizePixel( aSize );
1835 // -----------------------------------------------------------------------
1837 long SfxHelpIndexWindow_Impl::PreNotify( NotifyEvent& rNEvt )
1839 long nDone = 0;
1840 USHORT nType = rNEvt.GetType();
1841 if ( EVENT_KEYINPUT == nType && rNEvt.GetKeyEvent() )
1843 const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
1844 USHORT nCode = rKeyCode.GetCode();
1846 if ( KEY_TAB == nCode )
1848 // don't exit index pane with <TAB>
1849 USHORT nPageId = 0;
1850 HelpTabPage_Impl* pCurPage = GetCurrentPage( nPageId );
1851 Control* pControl = pCurPage->GetLastFocusControl();
1852 BOOL bShift = rKeyCode.IsShift();
1853 BOOL bCtrl = rKeyCode.IsMod1();
1854 if ( !bCtrl && bShift && aActiveLB.HasChildPathFocus() )
1856 pControl->GrabFocus();
1857 nDone = 1;
1859 else if ( !bCtrl && !bShift && pControl->HasChildPathFocus() )
1861 aActiveLB.GrabFocus();
1862 nDone = 1;
1864 else if ( bCtrl )
1866 // <STRG><TAB> moves through the pages
1867 if ( nPageId < HELP_INDEX_PAGE_LAST )
1868 nPageId++;
1869 else
1870 nPageId = HELP_INDEX_PAGE_FIRST;
1871 aTabCtrl.SetCurPageId( (USHORT)nPageId );
1872 ActivatePageHdl( &aTabCtrl );
1873 nDone = 1;
1876 else if ( aTabCtrl.HasFocus() && ( KEY_LEFT == nCode || KEY_RIGHT == nCode ) )
1878 bWasCursorLeftOrRight = true;
1882 return nDone ? nDone : Window::PreNotify( rNEvt );
1885 // -----------------------------------------------------------------------
1887 void SfxHelpIndexWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
1889 Window::DataChanged( rDCEvt );
1891 if ( ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
1892 ( rDCEvt.GetType() == DATACHANGED_DISPLAY ) ) &&
1893 ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
1895 SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFaceColor() ) );
1899 // -----------------------------------------------------------------------
1901 void SfxHelpIndexWindow_Impl::SetDoubleClickHdl( const Link& rLink )
1903 aPageDoubleClickLink = rLink;
1904 if ( pCPage )
1905 pCPage->SetOpenHdl( aPageDoubleClickLink );
1906 if ( pIPage )
1907 pIPage->SetDoubleClickHdl( aPageDoubleClickLink );
1908 if ( pSPage )
1909 pSPage->SetDoubleClickHdl( aPageDoubleClickLink );
1910 if ( pBPage )
1911 pBPage->SetDoubleClickHdl( aPageDoubleClickLink );
1914 // -----------------------------------------------------------------------
1916 void SfxHelpIndexWindow_Impl::SetFactory( const String& rFactory, sal_Bool bActive )
1918 if ( rFactory.Len() > 0 )
1920 GetIndexPage()->SetFactory( rFactory );
1921 // the index page did a check if rFactory is valid,
1922 // so the index page always returns a valid factory
1923 GetSearchPage()->SetFactory( GetIndexPage()->GetFactory() );
1924 if ( bActive )
1925 SetActiveFactory();
1929 // -----------------------------------------------------------------------
1931 String SfxHelpIndexWindow_Impl::GetSelectEntry() const
1933 String sRet;
1935 switch ( aTabCtrl.GetCurPageId() )
1937 case HELP_INDEX_PAGE_CONTENTS:
1938 sRet = pCPage->GetSelectEntry();
1939 break;
1941 case HELP_INDEX_PAGE_INDEX:
1942 sRet = pIPage->GetSelectEntry();
1943 break;
1945 case HELP_INDEX_PAGE_SEARCH:
1946 sRet = pSPage->GetSelectEntry();
1947 break;
1949 case HELP_INDEX_PAGE_BOOKMARKS:
1950 sRet = pBPage->GetSelectEntry();
1951 break;
1954 return sRet;
1957 // -----------------------------------------------------------------------
1959 void SfxHelpIndexWindow_Impl::AddBookmarks( const String& rTitle, const String& rURL )
1961 GetBookmarksPage()->AddBookmarks( rTitle, rURL );
1964 // -----------------------------------------------------------------------
1966 bool SfxHelpIndexWindow_Impl::IsValidFactory( const String& _rFactory )
1968 bool bValid = false;
1969 for ( USHORT i = 0; i < aActiveLB.GetEntryCount(); ++i )
1971 String* pFactory = (String*)(ULONG)aActiveLB.GetEntryData(i);
1972 if ( *pFactory == _rFactory )
1974 bValid = true;
1975 break;
1978 return bValid;
1981 // -----------------------------------------------------------------------
1983 void SfxHelpIndexWindow_Impl::ClearSearchPage()
1985 if ( pSPage )
1986 pSPage->ClearPage();
1989 // -----------------------------------------------------------------------
1991 void SfxHelpIndexWindow_Impl::GrabFocusBack()
1993 if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_CONTENTS && pCPage )
1994 pCPage->SetFocusOnBox();
1995 else if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_INDEX && pIPage )
1996 pIPage->SetFocusOnBox();
1997 else if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_SEARCH && pSPage )
1998 pSPage->SetFocusOnBox();
1999 else if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_BOOKMARKS && pBPage )
2000 pBPage->SetFocusOnBox();
2003 // -----------------------------------------------------------------------
2005 sal_Bool SfxHelpIndexWindow_Impl::HasFocusOnEdit() const
2007 sal_Bool bRet = sal_False;
2008 if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_INDEX && pIPage )
2009 bRet = pIPage->HasFocusOnEdit();
2010 else if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_SEARCH && pSPage )
2011 bRet = pSPage->HasFocusOnEdit();
2012 return bRet;
2015 // -----------------------------------------------------------------------
2017 String SfxHelpIndexWindow_Impl::GetSearchText() const
2019 String sRet;
2020 if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_SEARCH && pSPage )
2021 sRet = pSPage->GetSearchText();
2022 return sRet;
2025 // -----------------------------------------------------------------------
2027 sal_Bool SfxHelpIndexWindow_Impl::IsFullWordSearch() const
2029 sal_Bool bRet = sal_False;
2030 if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_SEARCH && pSPage )
2031 bRet = pSPage->IsFullWordSearch();
2032 return bRet;
2035 // -----------------------------------------------------------------------
2037 void SfxHelpIndexWindow_Impl::OpenKeyword( const String& rKeyword )
2039 sKeyword = rKeyword;
2040 DBG_ASSERT( pIPage, "invalid index page" );
2041 pIPage->SetKeyword( sKeyword );
2044 // -----------------------------------------------------------------------
2046 void SfxHelpIndexWindow_Impl::SelectExecutableEntry()
2048 if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_INDEX && pIPage )
2049 pIPage->SelectExecutableEntry();
2052 // class TextWin_Impl ----------------------------------------------------
2054 TextWin_Impl::TextWin_Impl( Window* p ) : DockingWindow( p, 0 )
2058 TextWin_Impl::~TextWin_Impl()
2062 long TextWin_Impl::Notify( NotifyEvent& rNEvt )
2064 if( ( rNEvt.GetType() == EVENT_KEYINPUT ) && rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_TAB )
2065 return GetParent()->Notify( rNEvt );
2066 else
2067 return DockingWindow::Notify( rNEvt );
2070 // -----------------------------------------------------------------------
2071 // remove docking area acceptor from layoutmanager, so it will not layout anything further .-)
2072 void lcl_disableLayoutOfFrame(const Reference< XFrame >& xFrame)
2074 static const ::rtl::OUString PROP_LAYOUT_MANAGER(DEFINE_CONST_UNICODE("LayoutManager"));
2076 Reference< XPropertySet > xPropSet(xFrame, UNO_QUERY_THROW);
2077 xPropSet->setPropertyValue(PROP_LAYOUT_MANAGER, makeAny(Reference< XLayoutManager >()));
2080 // class SfxHelpTextWindow_Impl ------------------------------------------
2082 SfxHelpTextWindow_Impl::SfxHelpTextWindow_Impl( SfxHelpWindow_Impl* pParent ) :
2084 Window( pParent, WB_CLIPCHILDREN | WB_TABSTOP | WB_DIALOGCONTROL ),
2086 aToolBox ( this, 0 ),
2087 aOnStartupCB ( this, SfxResId( RID_HELP_ONSTARTUP_BOX ) ),
2088 aIndexOnImage ( SfxResId( IMG_HELP_TOOLBOX_INDEX_ON ) ),
2089 aIndexOffImage ( SfxResId( IMG_HELP_TOOLBOX_INDEX_OFF ) ),
2090 aIndexOnText ( SfxResId( STR_HELP_BUTTON_INDEX_ON ) ),
2091 aIndexOffText ( SfxResId( STR_HELP_BUTTON_INDEX_OFF ) ),
2092 aOnStartupText ( SfxResId( RID_HELP_ONSTARTUP_TEXT ) ),
2093 pHelpWin ( pParent ),
2094 pTextWin ( new TextWin_Impl( this ) ),
2095 pSrchDlg ( NULL ),
2096 nMinPos ( 0 ),
2097 bIsDebug ( sal_False ),
2098 bIsIndexOn ( sal_False ),
2099 bIsInClose ( sal_False ),
2100 bIsFullWordSearch ( sal_False )
2103 sfx2::AddToTaskPaneList( &aToolBox );
2105 xFrame = Reference < XFrame > ( ::comphelper::getProcessServiceFactory()->createInstance(
2106 DEFINE_CONST_UNICODE("com.sun.star.frame.Frame") ), UNO_QUERY );
2107 xFrame->initialize( VCLUnoHelper::GetInterface ( pTextWin ) );
2108 xFrame->setName( DEFINE_CONST_UNICODE("OFFICE_HELP") );
2109 lcl_disableLayoutOfFrame(xFrame);
2111 aToolBox.SetHelpId( HID_HELP_TOOLBOX );
2113 aToolBox.InsertItem( TBI_INDEX, aIndexOffText );
2114 aToolBox.SetHelpId( TBI_INDEX, HID_HELP_TOOLBOXITEM_INDEX );
2115 aToolBox.InsertSeparator();
2116 aToolBox.InsertItem( TBI_BACKWARD, String( SfxResId( STR_HELP_BUTTON_PREV ) ) );
2117 aToolBox.SetHelpId( TBI_BACKWARD, HID_HELP_TOOLBOXITEM_BACKWARD );
2118 aToolBox.InsertItem( TBI_FORWARD, String( SfxResId( STR_HELP_BUTTON_NEXT ) ) );
2119 aToolBox.SetHelpId( TBI_FORWARD, HID_HELP_TOOLBOXITEM_FORWARD );
2120 aToolBox.InsertItem( TBI_START, String( SfxResId( STR_HELP_BUTTON_START ) ) );
2121 aToolBox.SetHelpId( TBI_START, HID_HELP_TOOLBOXITEM_START );
2122 aToolBox.InsertSeparator();
2123 aToolBox.InsertItem( TBI_PRINT, String( SfxResId( STR_HELP_BUTTON_PRINT ) ) );
2124 aToolBox.SetHelpId( TBI_PRINT, HID_HELP_TOOLBOXITEM_PRINT );
2125 aToolBox.InsertItem( TBI_BOOKMARKS, String( SfxResId( STR_HELP_BUTTON_ADDBOOKMARK ) ) );
2126 aToolBox.SetHelpId( TBI_BOOKMARKS, HID_HELP_TOOLBOXITEM_BOOKMARKS );
2127 aToolBox.InsertItem( TBI_SEARCHDIALOG, String( SfxResId( STR_HELP_BUTTON_SEARCHDIALOG ) ) );
2128 aToolBox.SetHelpId( TBI_SEARCHDIALOG, HID_HELP_TOOLBOXITEM_SEARCHDIALOG );
2130 InitToolBoxImages();
2131 aToolBox.Show();
2132 InitOnStartupBox( false );
2133 aOnStartupCB.SetClickHdl( LINK( this, SfxHelpTextWindow_Impl, CheckHdl ) );
2135 aSelectTimer.SetTimeoutHdl( LINK( this, SfxHelpTextWindow_Impl, SelectHdl ) );
2136 aSelectTimer.SetTimeout( 1000 );
2138 char* pEnv = getenv( "help_debug" );
2139 if ( pEnv )
2140 bIsDebug = sal_True;
2142 SvtMiscOptions().AddListener( LINK( this, SfxHelpTextWindow_Impl, NotifyHdl ) );
2144 if ( aOnStartupCB.GetHelpId() == 0 )
2145 aOnStartupCB.SetHelpId( HID_HELP_ONSTARTUP_BOX );
2148 // -----------------------------------------------------------------------
2150 SfxHelpTextWindow_Impl::~SfxHelpTextWindow_Impl()
2152 sfx2::RemoveFromTaskPaneList( &aToolBox );
2154 bIsInClose = sal_True;
2155 SvtMiscOptions().RemoveListener( LINK( this, SfxHelpTextWindow_Impl, NotifyHdl ) );
2156 delete pSrchDlg;
2159 // -----------------------------------------------------------------------
2161 sal_Bool SfxHelpTextWindow_Impl::HasSelection() const
2163 // is there any selection in the text and not only a cursor?
2164 sal_Bool bRet = sal_False;
2165 Reference < XTextRange > xRange = getCursor();
2166 if ( xRange.is() )
2168 Reference < XText > xText = xRange->getText();
2169 Reference < XTextCursor > xCursor = xText->createTextCursorByRange( xRange );
2170 bRet = !xCursor->isCollapsed();
2173 return bRet;
2176 // -----------------------------------------------------------------------
2178 void SfxHelpTextWindow_Impl::InitToolBoxImages()
2180 sal_Bool bLarge = SvtMiscOptions().AreCurrentSymbolsLarge();
2181 sal_Bool bHiContrast = GetBackground().GetColor().IsDark();
2183 aIndexOnImage = Image( SfxResId(
2184 bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_INDEX_ON : IMG_HELP_TOOLBOX_L_INDEX_ON
2185 : bHiContrast ? IMG_HELP_TOOLBOX_HC_INDEX_ON : IMG_HELP_TOOLBOX_INDEX_ON ) );
2186 aIndexOffImage = Image( SfxResId(
2187 bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_INDEX_OFF : IMG_HELP_TOOLBOX_L_INDEX_OFF
2188 : bHiContrast ? IMG_HELP_TOOLBOX_HC_INDEX_OFF : IMG_HELP_TOOLBOX_INDEX_OFF ) );
2189 aToolBox.SetItemImage( TBI_INDEX, bIsIndexOn ? aIndexOffImage : aIndexOnImage );
2191 aToolBox.SetItemImage( TBI_BACKWARD, Image( SfxResId(
2192 bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_PREV : IMG_HELP_TOOLBOX_L_PREV
2193 : bHiContrast ? IMG_HELP_TOOLBOX_HC_PREV : IMG_HELP_TOOLBOX_PREV ) ) );
2194 aToolBox.SetItemImage( TBI_FORWARD, Image( SfxResId(
2195 bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_NEXT : IMG_HELP_TOOLBOX_L_NEXT
2196 : bHiContrast ? IMG_HELP_TOOLBOX_HC_NEXT : IMG_HELP_TOOLBOX_NEXT ) ) );
2197 aToolBox.SetItemImage( TBI_START, Image( SfxResId(
2198 bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_START : IMG_HELP_TOOLBOX_L_START
2199 : bHiContrast ? IMG_HELP_TOOLBOX_HC_START : IMG_HELP_TOOLBOX_START ) ) );
2200 aToolBox.SetItemImage( TBI_PRINT, Image( SfxResId(
2201 bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_PRINT : IMG_HELP_TOOLBOX_L_PRINT
2202 : bHiContrast ? IMG_HELP_TOOLBOX_HC_PRINT : IMG_HELP_TOOLBOX_PRINT ) ) );
2203 aToolBox.SetItemImage( TBI_BOOKMARKS, Image( SfxResId(
2204 bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_BOOKMARKS : IMG_HELP_TOOLBOX_L_BOOKMARKS
2205 : bHiContrast ? IMG_HELP_TOOLBOX_HC_BOOKMARKS : IMG_HELP_TOOLBOX_BOOKMARKS ) ) );
2206 aToolBox.SetItemImage( TBI_SEARCHDIALOG, Image( SfxResId(
2207 bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_SEARCHDIALOG : IMG_HELP_TOOLBOX_L_SEARCHDIALOG
2208 : bHiContrast ? IMG_HELP_TOOLBOX_HC_SEARCHDIALOG : IMG_HELP_TOOLBOX_SEARCHDIALOG ) ) );
2210 Size aSize = aToolBox.CalcWindowSizePixel();
2211 aSize.Height() += TOOLBOX_OFFSET;
2212 aToolBox.SetPosSizePixel( Point( 0, TOOLBOX_OFFSET ), aSize );
2214 SvtMiscOptions aMiscOptions;
2215 if ( aMiscOptions.GetToolboxStyle() != aToolBox.GetOutStyle() )
2216 aToolBox.SetOutStyle( aMiscOptions.GetToolboxStyle() );
2219 // -----------------------------------------------------------------------
2221 void SfxHelpTextWindow_Impl::InitOnStartupBox( bool bOnlyText )
2223 sCurrentFactory = SfxHelp::GetCurrentModuleIdentifier();
2225 Reference< XMultiServiceFactory > xMultiServiceFac = ::comphelper::getProcessServiceFactory();
2226 Reference< XInterface > xConfig;
2227 ::rtl::OUString sPath( PATH_OFFICE_FACTORIES );
2228 sPath += sCurrentFactory;
2229 ::rtl::OUString sKey( KEY_HELP_ON_OPEN );
2231 // Attention: This check boy knows two states:
2232 // 1) Reading of the config key fails with an exception or by getting an empty Any (!) => check box must be hidden
2233 // 2) We read TRUE/FALSE => check box must be shown and enabled/disabled
2235 bool bHideBox = true;
2236 sal_Bool bHelpAtStartup = sal_False;
2239 xConfiguration = ConfigurationHelper::openConfig(
2240 xMultiServiceFac, PACKAGE_SETUP, ConfigurationHelper::E_STANDARD );
2241 if ( xConfiguration.is() )
2243 Any aAny = ConfigurationHelper::readRelativeKey( xConfiguration, sPath, sKey );
2244 if (aAny >>= bHelpAtStartup)
2245 bHideBox = false;
2248 catch( Exception& )
2250 bHideBox = true;
2253 if ( bHideBox )
2254 aOnStartupCB.Hide();
2255 else
2257 // detect module name
2258 String sModuleName;
2260 if ( xConfiguration.is() )
2262 ::rtl::OUString sTemp;
2263 sKey = KEY_UI_NAME;
2266 Any aAny = ConfigurationHelper::readRelativeKey( xConfiguration, sPath, sKey );
2267 aAny >>= sTemp;
2269 catch( Exception& )
2271 DBG_ERRORFILE( "SfxHelpTextWindow_Impl::InitOnStartupBox(): unexpected exception" );
2273 sModuleName = String( sTemp );
2276 if ( sModuleName.Len() > 0 )
2278 // set module name in checkbox text
2279 String sText( aOnStartupText );
2280 sText.SearchAndReplace( String::CreateFromAscii( "%MODULENAME" ), sModuleName );
2281 aOnStartupCB.SetText( sText );
2282 // and show it
2283 aOnStartupCB.Show();
2284 // set check state
2285 aOnStartupCB.Check( bHelpAtStartup );
2286 aOnStartupCB.SaveValue();
2288 // calculate and set optimal width of the onstartup checkbox
2289 String sCBText( DEFINE_CONST_UNICODE( "XXX" ) );
2290 sCBText += aOnStartupCB.GetText();
2291 long nTextWidth = aOnStartupCB.GetTextWidth( sCBText );
2292 Size aSize = aOnStartupCB.GetSizePixel();
2293 aSize.Width() = nTextWidth;
2294 aOnStartupCB.SetSizePixel( aSize );
2295 SetOnStartupBoxPosition();
2298 if ( !bOnlyText )
2300 // set position of the checkbox
2301 Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
2302 Size aTBSize = aToolBox.GetSizePixel();
2303 Size aCBSize = aOnStartupCB.GetSizePixel();
2304 Point aPnt = aToolBox.GetPosPixel();
2305 aPnt.X() += aTBSize.Width() + a3Size.Width();
2306 aPnt.Y() += ( ( aTBSize.Height() - aCBSize.Height() ) / 2 );
2307 aOnStartupCB.SetPosPixel( aPnt );
2308 nMinPos = aPnt.X();
2313 // -----------------------------------------------------------------------
2315 void SfxHelpTextWindow_Impl::SetOnStartupBoxPosition()
2317 long nX = Max( GetOutputSizePixel().Width() - aOnStartupCB.GetSizePixel().Width(), nMinPos );
2318 Point aPos = aOnStartupCB.GetPosPixel();
2319 aPos.X() = nX;
2320 aOnStartupCB.SetPosPixel( aPos );
2323 // -----------------------------------------------------------------------
2325 Reference< XBreakIterator > SfxHelpTextWindow_Impl::GetBreakIterator()
2327 if ( !xBreakIterator.is() )
2328 xBreakIterator = vcl::unohelper::CreateBreakIterator();
2329 DBG_ASSERT( xBreakIterator.is(), "Could not create BreakIterator" );
2330 return xBreakIterator;
2333 // -----------------------------------------------------------------------
2335 Reference< XTextRange > SfxHelpTextWindow_Impl::getCursor() const
2337 // return the current cursor
2338 Reference< XTextRange > xCursor;
2342 Reference < XSelectionSupplier > xSelSup( xFrame->getController(), UNO_QUERY );
2343 if ( xSelSup.is() )
2345 Any aAny = xSelSup->getSelection();
2346 Reference < XIndexAccess > xSelection;
2347 if ( aAny >>= xSelection )
2349 if ( xSelection->getCount() == 1 )
2351 aAny = xSelection->getByIndex(0);
2352 aAny >>= xCursor;
2357 catch( Exception& )
2359 DBG_ERROR( "SfxHelpTextWindow_Impl::getCursor(): unexpected exception" );
2362 return xCursor;
2365 // -----------------------------------------------------------------------
2367 bool SfxHelpTextWindow_Impl::isHandledKey( const KeyCode& _rKeyCode )
2369 bool bRet = false;
2370 USHORT nCode = _rKeyCode.GetCode();
2372 // the keys <STRG><A> (select all), <STRG><C> (copy),
2373 // <STRG><F> (find), <STRG><P> (print) and <STRG><W> (close window)
2374 // were handled in help
2375 if ( _rKeyCode.IsMod1() &&
2376 ( KEY_A == nCode || KEY_C == nCode || KEY_F == nCode || KEY_P == nCode || KEY_W == nCode ) )
2378 if ( KEY_F == nCode )
2379 DoSearch();
2380 else
2381 bRet = true;
2384 return bRet;
2387 // -----------------------------------------------------------------------
2389 IMPL_LINK( SfxHelpTextWindow_Impl, SelectHdl, Timer*, EMPTYARG )
2393 // select the words, which are equal to the search text of the search page
2394 Reference < XController > xController = xFrame->getController();
2395 if ( xController.is() )
2397 // get document
2398 Reference < XSearchable > xSearchable( xController->getModel(), UNO_QUERY );
2399 if ( xSearchable.is() )
2401 // create descriptor, set string and find all words
2402 Reference < XSearchDescriptor > xSrchDesc = xSearchable->createSearchDescriptor();
2403 Reference < XPropertySet > xPropSet( xSrchDesc, UNO_QUERY );
2404 xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchRegularExpression"),
2405 makeAny( sal_Bool( sal_True ) ) );
2406 if ( bIsFullWordSearch )
2407 xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchWords"),
2408 makeAny( sal_Bool( sal_True ) ) );
2410 String sSearchString = sfx2::PrepareSearchString( aSearchText, GetBreakIterator(), false );
2411 xSrchDesc->setSearchString( sSearchString );
2412 Reference< XIndexAccess > xSelection = xSearchable->findAll( xSrchDesc );
2414 // then select all found words
2415 Reference < XSelectionSupplier > xSelectionSup( xController, UNO_QUERY );
2416 if ( xSelectionSup.is() )
2418 Any aAny;
2419 aAny <<= xSelection;
2420 xSelectionSup->select( aAny );
2425 catch( Exception& )
2427 DBG_ERROR( "SfxHelpTextWindow_Impl::SelectHdl(): unexpected exception" );
2430 return 1;
2433 // -----------------------------------------------------------------------
2435 IMPL_LINK( SfxHelpTextWindow_Impl, NotifyHdl, SvtMiscOptions*, pOptions )
2437 (void)pOptions; // unused variable
2438 InitToolBoxImages();
2439 Resize();
2440 aToolBox.Invalidate();
2441 return 0;
2444 // -----------------------------------------------------------------------
2446 IMPL_LINK( SfxHelpTextWindow_Impl, FindHdl, sfx2::SearchDialog*, pDlg )
2448 bool bWrapAround = ( NULL == pDlg );
2449 if ( bWrapAround )
2450 pDlg = pSrchDlg;
2451 DBG_ASSERT( pDlg, "invalid search dialog" );
2452 String sSearchText = pDlg->GetSearchText();
2455 // select the words, which are equal to the search text of the search page
2456 Reference < XController > xController = xFrame->getController();
2457 if ( xController.is() )
2459 // get document
2460 Reference < XSearchable > xSearchable( xController->getModel(), UNO_QUERY );
2461 if ( xSearchable.is() )
2463 // create descriptor, set string and find all words
2464 Reference < XSearchDescriptor > xSrchDesc = xSearchable->createSearchDescriptor();
2465 Reference < XPropertySet > xPropSet( xSrchDesc, UNO_QUERY );
2466 xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchWords"), makeAny( sal_Bool( pDlg->IsOnlyWholeWords() != false ) ) );
2467 xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchCaseSensitive"), makeAny( sal_Bool( pDlg->IsMarchCase() != false ) ) );
2468 xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchBackwards"), makeAny( sal_Bool( pDlg->IsSearchBackwards() != false ) ) );
2469 xSrchDesc->setSearchString( sSearchText );
2470 Reference< XInterface > xSelection;
2471 Reference< XTextRange > xCursor = getCursor();
2473 if ( xCursor.is() )
2475 if ( pDlg->IsSearchBackwards() )
2476 xCursor = xCursor->getStart();
2477 xSelection = xSearchable->findNext( xCursor, xSrchDesc );
2479 else
2480 xSelection = xSearchable->findFirst( xSrchDesc );
2482 // then select the found word
2483 if ( xSelection.is() )
2485 Reference < XSelectionSupplier > xSelectionSup( xController, UNO_QUERY );
2486 if ( xSelectionSup.is() )
2488 Any aAny;
2489 aAny <<= xSelection;
2490 xSelectionSup->select( aAny );
2493 else if ( pDlg->IsWrapAround() && !bWrapAround )
2495 Reference < text::XTextViewCursorSupplier > xCrsrSupp( xController, uno::UNO_QUERY );
2496 Reference < text::XTextViewCursor > xTVCrsr( xCrsrSupp->getViewCursor(), uno::UNO_QUERY );
2497 if ( xTVCrsr.is() )
2499 Reference < text::XTextDocument > xDoc( xController->getModel(), uno::UNO_QUERY );
2500 Reference < text::XText > xText = xDoc->getText();
2501 if ( xText.is() )
2503 if ( pDlg->IsSearchBackwards() )
2504 xTVCrsr->gotoRange( xText->getEnd(), sal_False );
2505 else
2506 xTVCrsr->gotoRange( xText->getStart(), sal_False );
2507 FindHdl( NULL );
2511 else
2513 DBG_ASSERT( pSrchDlg, "no search dialog" );
2514 InfoBox aBox( pSrchDlg, SfxResId( RID_INFO_NOSEARCHTEXTFOUND ) );
2515 aBox.Execute();
2516 pSrchDlg->SetFocusOnEdit();
2521 catch( Exception& )
2523 DBG_ERROR( "SfxHelpTextWindow_Impl::SelectHdl(): unexpected exception" );
2526 return 0;
2529 // -----------------------------------------------------------------------
2531 IMPL_LINK( SfxHelpTextWindow_Impl, CloseHdl, sfx2::SearchDialog*, pDlg )
2533 if ( pDlg )
2534 delete pSrchDlg;
2535 pSrchDlg = NULL;
2536 return 0;
2539 // -----------------------------------------------------------------------
2541 IMPL_LINK( SfxHelpTextWindow_Impl, CheckHdl, CheckBox*, pBox )
2543 if ( xConfiguration.is() )
2545 sal_Bool bChecked = pBox->IsChecked();
2546 ::rtl::OUString sPath( PATH_OFFICE_FACTORIES );
2547 sPath += sCurrentFactory;
2550 ConfigurationHelper::writeRelativeKey(
2551 xConfiguration, sPath, KEY_HELP_ON_OPEN, makeAny( bChecked ) );
2552 ConfigurationHelper::flush( xConfiguration );
2554 catch( Exception& )
2556 DBG_ERRORFILE( "SfxHelpTextWindow_Impl::CheckHdl(): unexpected exception" );
2560 return 0;
2563 // -----------------------------------------------------------------------
2565 void SfxHelpTextWindow_Impl::Resize()
2567 Size aSize = GetOutputSizePixel();
2568 long nToolBoxHeight = aToolBox.GetSizePixel().Height() + TOOLBOX_OFFSET;
2569 aSize.Height() -= nToolBoxHeight;
2570 pTextWin->SetPosSizePixel( Point( 0, nToolBoxHeight ), aSize );
2571 SetOnStartupBoxPosition();
2574 // -----------------------------------------------------------------------
2576 long SfxHelpTextWindow_Impl::PreNotify( NotifyEvent& rNEvt )
2578 long nDone = 0;
2579 USHORT nType = rNEvt.GetType();
2580 if ( EVENT_COMMAND == nType && rNEvt.GetCommandEvent() )
2582 const CommandEvent* pCmdEvt = rNEvt.GetCommandEvent();
2583 Window* pCmdWin = rNEvt.GetWindow();
2585 if ( pCmdEvt->GetCommand() == COMMAND_CONTEXTMENU && pCmdWin != this && pCmdWin != &aToolBox )
2587 sal_Bool bHiContrast = GetSettings().GetStyleSettings().GetMenuColor().IsDark();
2588 Point aPos;
2589 if ( pCmdEvt->IsMouseEvent() )
2590 aPos = pCmdEvt->GetMousePosPixel();
2591 else
2592 aPos = Point( pTextWin->GetPosPixel().X() + 20, 20 );
2593 aPos.Y() += pTextWin->GetPosPixel().Y();
2594 PopupMenu aMenu;
2595 if ( bIsIndexOn )
2596 aMenu.InsertItem( TBI_INDEX, aIndexOffText, Image( SfxResId(
2597 bHiContrast ? IMG_HELP_TOOLBOX_HC_INDEX_OFF : IMG_HELP_TOOLBOX_INDEX_OFF ) ) );
2598 else
2599 aMenu.InsertItem( TBI_INDEX, aIndexOnText, Image( SfxResId(
2600 bHiContrast ? IMG_HELP_TOOLBOX_HC_INDEX_ON : IMG_HELP_TOOLBOX_INDEX_ON ) ) );
2601 aMenu.SetHelpId( TBI_INDEX, HID_HELP_TOOLBOXITEM_INDEX );
2602 aMenu.InsertSeparator();
2603 aMenu.InsertItem( TBI_BACKWARD, String( SfxResId( STR_HELP_BUTTON_PREV ) ),
2604 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_PREV : IMG_HELP_TOOLBOX_PREV ) ) );
2605 aMenu.SetHelpId( TBI_BACKWARD, HID_HELP_TOOLBOXITEM_BACKWARD );
2606 aMenu.EnableItem( TBI_BACKWARD, pHelpWin->HasHistoryPredecessor() );
2607 aMenu.InsertItem( TBI_FORWARD, String( SfxResId( STR_HELP_BUTTON_NEXT ) ),
2608 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_NEXT : IMG_HELP_TOOLBOX_NEXT ) ) );
2609 aMenu.SetHelpId( TBI_FORWARD, HID_HELP_TOOLBOXITEM_FORWARD );
2610 aMenu.EnableItem( TBI_FORWARD, pHelpWin->HasHistorySuccessor() );
2611 aMenu.InsertItem( TBI_START, String( SfxResId( STR_HELP_BUTTON_START ) ),
2612 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_START : IMG_HELP_TOOLBOX_START ) ) );
2613 aMenu.SetHelpId( TBI_START, HID_HELP_TOOLBOXITEM_START );
2614 aMenu.InsertSeparator();
2615 aMenu.InsertItem( TBI_PRINT, String( SfxResId( STR_HELP_BUTTON_PRINT ) ),
2616 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_PRINT : IMG_HELP_TOOLBOX_PRINT ) ) );
2617 aMenu.SetHelpId( TBI_PRINT, HID_HELP_TOOLBOXITEM_PRINT );
2618 aMenu.InsertItem( TBI_BOOKMARKS, String( SfxResId( STR_HELP_BUTTON_ADDBOOKMARK ) ),
2619 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_BOOKMARKS : IMG_HELP_TOOLBOX_BOOKMARKS ) ) );
2620 aMenu.SetHelpId( TBI_BOOKMARKS, HID_HELP_TOOLBOXITEM_BOOKMARKS );
2621 aMenu.InsertItem( TBI_SEARCHDIALOG, String( SfxResId( STR_HELP_BUTTON_SEARCHDIALOG ) ),
2622 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_SEARCHDIALOG : IMG_HELP_TOOLBOX_SEARCHDIALOG ) ) );
2623 aMenu.SetHelpId( TBI_SEARCHDIALOG, HID_HELP_TOOLBOXITEM_SEARCHDIALOG );
2624 aMenu.InsertSeparator();
2625 aMenu.InsertItem( TBI_SELECTIONMODE, String( SfxResId( STR_HELP_MENU_TEXT_SELECTION_MODE ) ) );
2626 aMenu.SetHelpId( TBI_SELECTIONMODE, HID_HELP_TEXT_SELECTION_MODE );
2627 Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
2628 URL aURL;
2629 aURL.Complete = DEFINE_CONST_UNICODE(".uno:SelectTextMode");
2630 PARSE_URL( aURL );
2631 Reference < XDispatch > xDisp = xProv.is() ?
2632 xProv->queryDispatch( aURL, rtl::OUString(), 0 ) : Reference < XDispatch >();
2633 if(xDisp.is())
2635 HelpStatusListener_Impl* pStateListener;
2636 Reference<XStatusListener>xStateListener = pStateListener =
2637 new HelpStatusListener_Impl(xDisp, aURL );
2638 FeatureStateEvent rEvent = pStateListener->GetStateEvent();
2639 sal_Bool bCheck = sal_False;
2640 rEvent.State >>= bCheck;
2641 aMenu.CheckItem(TBI_SELECTIONMODE, bCheck);
2643 aMenu.InsertSeparator();
2644 aMenu.InsertItem( TBI_COPY, String( SfxResId( STR_HELP_MENU_TEXT_COPY ) ),
2645 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_COPY : IMG_HELP_TOOLBOX_COPY ) ) );
2646 aMenu.SetHelpId( TBI_COPY, SID_COPY );
2647 aMenu.EnableItem( TBI_COPY, HasSelection() );
2649 if ( bIsDebug )
2651 aMenu.InsertSeparator();
2652 aMenu.InsertItem( TBI_SOURCEVIEW, String( SfxResId( STR_HELP_BUTTON_SOURCEVIEW ) ) );
2655 if( SvtMenuOptions().IsEntryHidingEnabled() == sal_False )
2656 aMenu.SetMenuFlags( aMenu.GetMenuFlags() | MENU_FLAG_HIDEDISABLEDENTRIES );
2658 USHORT nId = aMenu.Execute( this, aPos );
2659 pHelpWin->DoAction( nId );
2660 nDone = 1;
2663 else if ( EVENT_KEYINPUT == nType && rNEvt.GetKeyEvent() )
2665 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
2666 const KeyCode& rKeyCode = pKEvt->GetKeyCode();
2667 USHORT nKeyGroup = rKeyCode.GetGroup();
2668 USHORT nKey = rKeyCode.GetCode();
2669 if ( KEYGROUP_ALPHA == nKeyGroup && !isHandledKey( rKeyCode ) )
2671 // do nothing disables the writer accelerators
2672 nDone = 1;
2674 else if ( rKeyCode.IsMod1() && ( KEY_F4 == nKey || KEY_W == nKey ) )
2676 // <STRG><F4> or <STRG><W> -> close top frame
2677 pHelpWin->CloseWindow();
2678 nDone = 1;
2680 else if ( KEY_TAB == nKey && aOnStartupCB.HasChildPathFocus() )
2682 aToolBox.GrabFocus();
2683 nDone = 1;
2687 return nDone ? nDone : Window::PreNotify( rNEvt );
2690 // -----------------------------------------------------------------------
2692 void SfxHelpTextWindow_Impl::GetFocus()
2694 if ( !bIsInClose )
2698 if( xFrame.is() )
2700 Reference< ::com::sun::star::awt::XWindow > xWindow = xFrame->getComponentWindow();
2701 if( xWindow.is() )
2702 xWindow->setFocus();
2705 catch( Exception& )
2707 DBG_ERRORFILE( "SfxHelpTextWindow_Impl::GetFocus(): unexpected exception" );
2712 // -----------------------------------------------------------------------
2714 void SfxHelpTextWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
2716 Window::DataChanged( rDCEvt );
2718 if ( ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
2719 ( rDCEvt.GetType() == DATACHANGED_DISPLAY ) ) &&
2720 ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
2722 SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFaceColor() ) );
2723 InitToolBoxImages();
2727 // -----------------------------------------------------------------------
2729 void SfxHelpTextWindow_Impl::ToggleIndex( sal_Bool bOn )
2731 bIsIndexOn = bOn;
2732 if ( bIsIndexOn )
2734 aToolBox.SetItemImage( TBI_INDEX, aIndexOffImage );
2735 aToolBox.SetItemText( TBI_INDEX, aIndexOffText );
2737 else
2739 aToolBox.SetItemImage( TBI_INDEX, aIndexOnImage );
2740 aToolBox.SetItemText( TBI_INDEX, aIndexOnText );
2744 // -----------------------------------------------------------------------
2746 void SfxHelpTextWindow_Impl::SelectSearchText( const String& rSearchText, sal_Bool _bIsFullWordSearch )
2748 aSearchText = rSearchText;
2749 bIsFullWordSearch = _bIsFullWordSearch;
2750 aSelectTimer.Start();
2753 // -----------------------------------------------------------------------
2755 void SfxHelpTextWindow_Impl::SetPageStyleHeaderOff() const
2757 #ifdef DBG_UTIL
2758 sal_Bool bSetOff = sal_False;
2759 #endif
2760 // set off the pagestyle header to prevent print output of the help URL
2763 Reference < XController > xController = xFrame->getController();
2764 Reference < XSelectionSupplier > xSelSup( xController, UNO_QUERY );
2765 if ( xSelSup.is() )
2767 Reference < XIndexAccess > xSelection;
2768 if ( xSelSup->getSelection() >>= xSelection )
2770 Reference < XTextRange > xRange;
2771 if ( xSelection->getByIndex(0) >>= xRange )
2773 Reference < XText > xText = xRange->getText();
2774 Reference < XPropertySet > xProps( xText->createTextCursorByRange( xRange ), UNO_QUERY );
2775 ::rtl::OUString sStyleName;
2776 if ( xProps->getPropertyValue( DEFINE_CONST_OUSTRING("PageStyleName") ) >>= sStyleName )
2778 Reference < XStyleFamiliesSupplier > xStyles( xController->getModel(), UNO_QUERY );
2779 Reference < XNameContainer > xContainer;
2780 if ( xStyles->getStyleFamilies()->getByName( DEFINE_CONST_OUSTRING("PageStyles") )
2781 >>= xContainer )
2783 Reference < XStyle > xStyle;
2784 if ( xContainer->getByName( sStyleName ) >>= xStyle )
2786 Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
2787 xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("HeaderIsOn"),
2788 makeAny( sal_Bool( sal_False ) ) );
2790 Reference< XModifiable > xReset(xStyles, UNO_QUERY);
2791 xReset->setModified(sal_False);
2792 #ifdef DBG_UTIL
2793 bSetOff = sal_True;
2794 #endif
2802 catch( Exception& )
2804 DBG_ERRORFILE( "SfxHelpTextWindow_Impl::SetPageStyleHeaderOff(): unexpected exception" );
2807 #ifdef DBG_UTIL
2808 if ( !bSetOff )
2810 DBG_ERRORFILE( "SfxHelpTextWindow_Impl::SetPageStyleHeaderOff(): set off failed" );
2812 #endif
2815 // -----------------------------------------------------------------------
2817 void SfxHelpTextWindow_Impl::CloseFrame()
2819 bIsInClose = sal_True;
2822 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > xCloseable ( xFrame, ::com::sun::star::uno::UNO_QUERY );
2823 if (xCloseable.is())
2824 xCloseable->close(sal_True);
2826 catch( ::com::sun::star::util::CloseVetoException& )
2831 // -----------------------------------------------------------------------
2833 void SfxHelpTextWindow_Impl::DoSearch()
2835 if ( !pSrchDlg )
2837 // create the search dialog
2838 pSrchDlg = new sfx2::SearchDialog( pTextWin, DEFINE_CONST_UNICODE("HelpSearchDialog") );
2839 // set handler
2840 pSrchDlg->SetFindHdl( LINK( this, SfxHelpTextWindow_Impl, FindHdl ) );
2841 pSrchDlg->SetCloseHdl( LINK( this, SfxHelpTextWindow_Impl, CloseHdl ) );
2842 // get selected text of the help page to set it as the search text
2843 Reference< XTextRange > xCursor = getCursor();
2844 if ( xCursor.is() )
2846 String sText = xCursor->getString();
2847 if ( sText.Len() > 0 )
2848 pSrchDlg->SetSearchText( sText );
2850 pSrchDlg->Show();
2854 // class SfxHelpWindow_Impl ----------------------------------------------
2856 void SfxHelpWindow_Impl::Resize()
2858 SplitWindow::Resize();
2859 InitSizes();
2862 // -----------------------------------------------------------------------
2864 void SfxHelpWindow_Impl::Split()
2866 static long nMinSplitSize = 5;
2867 static long nMaxSplitSize = 99 - nMinSplitSize;
2869 SplitWindow::Split();
2871 nIndexSize = GetItemSize( INDEXWIN_ID );
2872 nTextSize = GetItemSize( TEXTWIN_ID );
2874 BOOL bMod = FALSE;
2875 if( nIndexSize < nMinSplitSize )
2877 nIndexSize = nMinSplitSize;
2878 nTextSize = nMaxSplitSize;
2880 bMod = TRUE;
2882 else if( nTextSize < nMinSplitSize )
2884 nTextSize = nMinSplitSize;
2885 nIndexSize = nMaxSplitSize;
2887 bMod = TRUE;
2889 else
2890 bMod = FALSE;
2892 if( bMod )
2894 SetItemSize( INDEXWIN_ID, nIndexSize );
2895 SetItemSize( TEXTWIN_ID, nTextSize );
2898 InitSizes();
2901 // -----------------------------------------------------------------------
2903 void SfxHelpWindow_Impl::GetFocus()
2905 pTextWin->GrabFocus();
2908 // -----------------------------------------------------------------------
2910 void SfxHelpWindow_Impl::MakeLayout()
2912 if ( nHeight > 0 && xWindow.is() )
2914 Window* pScreenWin = VCLUnoHelper::GetWindow( xWindow );
2916 /* #i55528#
2917 Hide() / Show() will produce starnge effects.
2918 The returned size (used later to be written back into the configuration)
2919 isnt the right after a resize during the window is hidden.
2920 If this resize is done if the window is visible evyrthing works as aspected.
2921 Some VCL-patches could not solve this problem so I've established the
2922 workaround: resize the help window if it's visible .-)
2924 // pScreenWin->Hide();
2926 ::com::sun::star::awt::Rectangle aRect = xWindow->getPosSize();
2927 sal_Int32 nOldWidth = bIndex ? nCollapseWidth : nExpandWidth;
2928 sal_Int32 nWidth = bIndex ? nExpandWidth : nCollapseWidth;
2929 xWindow->setPosSize( aRect.X, aRect.Y, nWidth, nHeight, ::com::sun::star::awt::PosSize::SIZE );
2931 if ( aRect.Width > 0 && aRect.Height > 0 )
2933 Rectangle aScreenRect = pScreenWin->GetClientWindowExtentsRelative( NULL );
2934 Point aNewPos = aScreenRect.TopLeft();
2935 sal_Int32 nDiffWidth = nOldWidth - nWidth;
2936 aNewPos.X() += nDiffWidth;
2937 pScreenWin->SetPosPixel( aNewPos );
2939 else if ( aWinPos.X() > 0 && aWinPos.Y() > 0 )
2940 pScreenWin->SetPosPixel( aWinPos );
2942 // pScreenWin->Show();
2945 Clear();
2947 if ( bIndex )
2949 pIndexWin->Show();
2950 InsertItem( COLSET_ID, 100, SPLITWINDOW_APPEND, SPLITSET_ID, SWIB_PERCENTSIZE | SWIB_COLSET );
2951 InsertItem( INDEXWIN_ID, pIndexWin, nIndexSize, SPLITWINDOW_APPEND, COLSET_ID, SWIB_PERCENTSIZE );
2952 InsertItem( TEXTWIN_ID, pTextWin, nTextSize, SPLITWINDOW_APPEND, COLSET_ID, SWIB_PERCENTSIZE );
2954 else
2956 pIndexWin->Hide();
2957 InsertItem( COLSET_ID, 100, SPLITWINDOW_APPEND, SPLITSET_ID, SWIB_PERCENTSIZE | SWIB_COLSET );
2958 InsertItem( TEXTWIN_ID, pTextWin, 100, SPLITWINDOW_APPEND, 1, SWIB_PERCENTSIZE );
2962 // -----------------------------------------------------------------------
2964 void SfxHelpWindow_Impl::InitSizes()
2966 if ( xWindow.is() )
2968 ::com::sun::star::awt::Rectangle aRect = xWindow->getPosSize();
2969 nHeight = aRect.Height;
2971 if ( bIndex )
2973 nExpandWidth = aRect.Width;
2974 nCollapseWidth = nExpandWidth * nTextSize / 100;
2976 else
2978 nCollapseWidth = aRect.Width;
2979 nExpandWidth = nCollapseWidth * 100 / nTextSize;
2984 // -----------------------------------------------------------------------
2986 void SfxHelpWindow_Impl::LoadConfig()
2988 SvtViewOptions aViewOpt( E_WINDOW, CONFIGNAME_HELPWIN );
2989 if ( aViewOpt.Exists() )
2991 bIndex = aViewOpt.IsVisible();
2992 String aUserData;
2993 Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
2994 rtl::OUString aTemp;
2995 if ( aUserItem >>= aTemp )
2997 aUserData = String( aTemp );
2998 DBG_ASSERT( aUserData.GetTokenCount() == 6, "invalid user data" );
2999 USHORT nIdx = 0;
3000 nIndexSize = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
3001 nTextSize = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
3002 sal_Int32 nWidth = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
3003 nHeight = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
3004 aWinPos.X() = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
3005 aWinPos.Y() = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
3006 if ( bIndex )
3008 nExpandWidth = nWidth;
3009 nCollapseWidth = nExpandWidth * nTextSize / 100;
3011 else
3013 nCollapseWidth = nWidth;
3014 nExpandWidth = nCollapseWidth * 100 / nTextSize;
3018 pTextWin->ToggleIndex( bIndex );
3022 // -----------------------------------------------------------------------
3024 void SfxHelpWindow_Impl::SaveConfig()
3026 SvtViewOptions aViewOpt( E_WINDOW, CONFIGNAME_HELPWIN );
3027 sal_Int32 nW = 0, nH = 0;
3029 if ( xWindow.is() )
3031 ::com::sun::star::awt::Rectangle aRect = xWindow->getPosSize();
3032 nW = aRect.Width;
3033 nH = aRect.Height;
3036 aViewOpt.SetVisible( bIndex );
3037 String aUserData = String::CreateFromInt32( nIndexSize );
3038 aUserData += ';';
3039 aUserData += String::CreateFromInt32( nTextSize );
3040 aUserData += ';';
3041 aUserData += String::CreateFromInt32( nW );
3042 aUserData += ';';
3043 aUserData += String::CreateFromInt32( nH );
3045 Window* pScreenWin = VCLUnoHelper::GetWindow( xWindow );
3046 aWinPos = pScreenWin->GetWindowExtentsRelative( NULL ).TopLeft();
3047 aUserData += ';';
3048 aUserData += String::CreateFromInt32( aWinPos.X() );
3049 aUserData += ';';
3050 aUserData += String::CreateFromInt32( aWinPos.Y() );
3052 aViewOpt.SetUserItem( USERITEM_NAME, makeAny( rtl::OUString( aUserData ) ) );
3055 // -----------------------------------------------------------------------
3057 void SfxHelpWindow_Impl::ShowStartPage()
3059 ::rtl::OUString sHelpURL = SfxHelpWindow_Impl::buildHelpURL(pIndexWin->GetFactory(),
3060 DEFINE_CONST_UNICODE("/start"),
3061 ::rtl::OUString(),
3062 sal_True);
3063 loadHelpContent(sHelpURL);
3066 // -----------------------------------------------------------------------
3068 IMPL_LINK( SfxHelpWindow_Impl, SelectHdl, ToolBox* , pToolBox )
3070 if ( pToolBox )
3072 bGrabFocusToToolBox = pToolBox->HasChildPathFocus();
3073 DoAction( pToolBox->GetCurItemId() );
3076 return 1;
3079 //-------------------------------------------------------------------------
3081 IMPL_LINK( SfxHelpWindow_Impl, OpenHdl, SfxHelpIndexWindow_Impl* , EMPTYARG )
3083 pIndexWin->SelectExecutableEntry();
3084 String aEntry = pIndexWin->GetSelectEntry();
3086 if ( aEntry.Len() < 1 )
3087 return 0;
3089 ::rtl::OUString sHelpURL;
3091 // INetURLObject aObj(aEntry);
3092 // BOOL bComplete = ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP );
3094 BOOL bComplete = rtl::OUString(aEntry).toAsciiLowerCase().match(rtl::OUString::createFromAscii("vnd.sun.star.help"),0);
3096 if (bComplete)
3097 sHelpURL = ::rtl::OUString(aEntry);
3098 else
3100 String aId;
3101 String aAnchor = String('#');
3102 if ( aEntry.GetTokenCount( '#' ) == 2 )
3104 aId = aEntry.GetToken( 0, '#' );
3105 aAnchor += aEntry.GetToken( 1, '#' );
3107 else
3108 aId = aEntry;
3110 aEntry = '/';
3111 aEntry += aId;
3113 sHelpURL = SfxHelpWindow_Impl::buildHelpURL(pIndexWin->GetFactory(),
3114 aEntry,
3115 aAnchor,
3116 sal_True);
3119 loadHelpContent(sHelpURL);
3121 return 0;
3124 //-------------------------------------------------------------------------
3126 IMPL_LINK( SfxHelpWindow_Impl, SelectFactoryHdl, SfxHelpIndexWindow_Impl* , pWin )
3128 if ( sTitle.Len() == 0 )
3129 sTitle = GetParent()->GetText();
3131 String aNewTitle = sTitle;
3132 aNewTitle += DEFINE_CONST_UNICODE(" - ");
3133 aNewTitle += pIndexWin->GetActiveFactoryTitle();
3135 Reference< XTitle > xTitle(xFrame, UNO_QUERY);
3136 if (xTitle.is ())
3137 xTitle->setTitle (aNewTitle);
3139 if ( pWin )
3140 ShowStartPage();
3141 pIndexWin->ClearSearchPage();
3143 return 0;
3146 // -----------------------------------------------------------------------
3148 IMPL_LINK( SfxHelpWindow_Impl, ChangeHdl, HelpListener_Impl*, pListener )
3150 SetFactory( pListener->GetFactory() );
3151 return 0;
3154 // -----------------------------------------------------------------------
3156 void SfxHelpWindow_Impl::openDone(const ::rtl::OUString& sURL ,
3157 sal_Bool bSuccess)
3159 INetURLObject aObj( sURL );
3160 if ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP )
3161 SetFactory( aObj.GetHost() );
3162 if ( IsWait() )
3163 LeaveWait();
3164 if ( bGrabFocusToToolBox )
3166 pTextWin->GetToolBox().GrabFocus();
3167 bGrabFocusToToolBox = sal_False;
3169 else
3170 pIndexWin->GrabFocusBack();
3171 if ( bSuccess )
3173 // set some view settings: "prevent help tips" and "helpid == 68245"
3176 Reference < XController > xController = pTextWin->getFrame()->getController();
3177 if ( xController.is() )
3179 Reference < XViewSettingsSupplier > xSettings( xController, UNO_QUERY );
3180 Reference < XPropertySet > xViewProps = xSettings->getViewSettings();
3181 Reference< XPropertySetInfo > xInfo = xViewProps->getPropertySetInfo();
3182 Any aBoolAny = makeAny( sal_Bool( sal_True ) );
3183 xViewProps->setPropertyValue( DEFINE_CONST_OUSTRING("PreventHelpTips"), aBoolAny );
3184 xViewProps->setPropertyValue( DEFINE_CONST_OUSTRING("ShowGraphics"), aBoolAny );
3185 xViewProps->setPropertyValue( DEFINE_CONST_OUSTRING("ShowTables"), aBoolAny );
3186 xViewProps->setPropertyValue( DEFINE_CONST_OUSTRING("HelpURL"), makeAny( DEFINE_CONST_OUSTRING("HID:68245") ) );
3187 ::rtl::OUString sProperty( DEFINE_CONST_OUSTRING("IsExecuteHyperlinks") );
3188 if ( xInfo->hasPropertyByName( sProperty ) )
3189 xViewProps->setPropertyValue( sProperty, aBoolAny );
3190 xController->restoreViewData(pHelpInterceptor->GetViewData());
3193 catch( Exception& )
3195 DBG_ERROR( "SfxHelpWindow_Impl::OpenDoneHdl(): unexpected exception" );
3198 // When the SearchPage opens the help doc, then select all words, which are equal to its text
3199 String sSearchText = TRIM( pIndexWin->GetSearchText() );
3200 if ( sSearchText.Len() > 0 )
3201 pTextWin->SelectSearchText( sSearchText, pIndexWin->IsFullWordSearch() );
3203 // no page style header -> this prevents a print output of the URL
3204 pTextWin->SetPageStyleHeaderOff();
3208 // -----------------------------------------------------------------------
3210 SfxHelpWindow_Impl::SfxHelpWindow_Impl(
3211 const ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame >& rFrame,
3212 Window* pParent, WinBits ) :
3214 SplitWindow( pParent, WB_3DLOOK | WB_NOSPLITDRAW ),
3216 xFrame ( rFrame ),
3217 pIndexWin ( NULL ),
3218 pTextWin ( NULL ),
3219 pHelpInterceptor ( new HelpInterceptor_Impl() ),
3220 pHelpListener ( new HelpListener_Impl( pHelpInterceptor ) ),
3221 nExpandWidth ( 0 ),
3222 nCollapseWidth ( 0 ),
3223 nHeight ( 0 ),
3224 nIndexSize ( 40 ),
3225 nTextSize ( 60 ),
3226 bIndex ( sal_True ),
3227 bGrabFocusToToolBox ( sal_False ),
3228 aWinPos ( 0, 0 ),
3229 sTitle ( pParent->GetText() )
3231 SetHelpId( HID_HELP_WINDOW );
3232 SetStyle( GetStyle() | WB_DIALOGCONTROL );
3234 pHelpInterceptor->InitWaiter( this );
3235 pIndexWin = new SfxHelpIndexWindow_Impl( this );
3236 pIndexWin->SetDoubleClickHdl( LINK( this, SfxHelpWindow_Impl, OpenHdl ) );
3237 pIndexWin->SetSelectFactoryHdl( LINK( this, SfxHelpWindow_Impl, SelectFactoryHdl ) );
3238 pIndexWin->Show();
3239 pTextWin = new SfxHelpTextWindow_Impl( this );
3240 Reference < XFramesSupplier > xSup( rFrame, UNO_QUERY );
3241 Reference < XFrames > xFrames = xSup->getFrames();
3242 xFrames->append( pTextWin->getFrame() );
3243 pTextWin->SetSelectHdl( LINK( this, SfxHelpWindow_Impl, SelectHdl ) );
3244 pTextWin->Show();
3245 pHelpInterceptor->setInterception( pTextWin->getFrame() );
3246 pHelpListener->SetChangeHdl( LINK( this, SfxHelpWindow_Impl, ChangeHdl ) );
3247 LoadConfig();
3250 // -----------------------------------------------------------------------
3252 SfxHelpWindow_Impl::~SfxHelpWindow_Impl()
3254 SaveConfig();
3255 Window* pDel = pIndexWin;
3256 pIndexWin = NULL;
3257 delete pDel;
3259 pTextWin->CloseFrame();
3260 delete pTextWin;
3263 // -----------------------------------------------------------------------
3265 long SfxHelpWindow_Impl::PreNotify( NotifyEvent& rNEvt )
3267 sal_Bool bHandled = sal_False;
3268 if ( rNEvt.GetType() == EVENT_KEYINPUT )
3270 // Backward == <ALT><LEFT> or <BACKSPACE> Forward == <ALT><RIGHT>
3271 const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
3272 USHORT nKey = rKeyCode.GetCode();
3273 if ( ( rKeyCode.IsMod2() && ( KEY_LEFT == nKey || KEY_RIGHT == nKey ) ) ||
3274 ( !rKeyCode.GetModifier() && KEY_BACKSPACE == nKey && !pIndexWin->HasFocusOnEdit() ) )
3276 DoAction( rKeyCode.GetCode() == KEY_RIGHT ? TBI_FORWARD : TBI_BACKWARD );
3277 bHandled = sal_True;
3279 else if ( rKeyCode.IsMod1() && ( KEY_F4 == nKey || KEY_W == nKey ) )
3281 // <STRG><F4> or <STRG><W> -> close top frame
3282 CloseWindow();
3283 bHandled = sal_True;
3286 return bHandled ? 1 : Window::PreNotify( rNEvt );
3289 // -----------------------------------------------------------------------
3291 void SfxHelpWindow_Impl::setContainerWindow( Reference < ::com::sun::star::awt::XWindow > xWin )
3293 xWindow = xWin;
3294 MakeLayout();
3297 // -----------------------------------------------------------------------
3299 void SfxHelpWindow_Impl::SetFactory( const String& rFactory )
3301 pIndexWin->SetFactory( rFactory, sal_True );
3304 // -----------------------------------------------------------------------
3306 void SfxHelpWindow_Impl::SetHelpURL( const String& rURL )
3308 INetURLObject aObj( rURL );
3309 if ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP )
3310 SetFactory( aObj.GetHost() );
3313 // -----------------------------------------------------------------------
3315 void SfxHelpWindow_Impl::DoAction( USHORT nActionId )
3317 switch ( nActionId )
3319 case TBI_INDEX :
3321 bIndex = !bIndex;
3322 MakeLayout();
3323 pTextWin->ToggleIndex( bIndex );
3324 break;
3327 case TBI_START :
3329 ShowStartPage();
3330 break;
3333 case TBI_BACKWARD :
3334 case TBI_FORWARD :
3336 URL aURL;
3337 aURL.Complete = DEFINE_CONST_UNICODE(".uno:Backward");
3338 if ( TBI_FORWARD == nActionId )
3339 aURL.Complete = DEFINE_CONST_UNICODE(".uno:Forward");
3340 PARSE_URL( aURL );
3341 pHelpInterceptor->dispatch( aURL, Sequence < PropertyValue >() );
3342 break;
3345 case TBI_SEARCHDIALOG :
3347 pTextWin->DoSearch();
3348 break;
3351 case TBI_PRINT :
3352 case TBI_SOURCEVIEW :
3353 case TBI_COPY :
3354 case TBI_SELECTIONMODE:
3356 Reference < XDispatchProvider > xProv( pTextWin->getFrame(), UNO_QUERY );
3357 if ( xProv.is() )
3359 URL aURL;
3360 if ( TBI_PRINT == nActionId )
3361 aURL.Complete = DEFINE_CONST_UNICODE(".uno:Print");
3362 else if ( TBI_SOURCEVIEW == nActionId )
3363 aURL.Complete = DEFINE_CONST_UNICODE(".uno:SourceView");
3364 else if ( TBI_COPY == nActionId )
3365 aURL.Complete = DEFINE_CONST_UNICODE(".uno:Copy");
3366 else if ( TBI_SELECTIONMODE == nActionId )
3367 aURL.Complete = DEFINE_CONST_UNICODE(".uno:SelectTextMode");
3368 else
3369 aURL.Complete = DEFINE_CONST_UNICODE(".uno:SearchDialog");
3370 PARSE_URL( aURL );
3371 Reference < XDispatch > xDisp = xProv->queryDispatch( aURL, String(), 0 );
3372 if ( xDisp.is() )
3373 xDisp->dispatch( aURL, Sequence < PropertyValue >() );
3375 break;
3378 case TBI_BOOKMARKS :
3380 String aURL = pHelpInterceptor->GetCurrentURL();
3381 if ( aURL.Len() > 0 )
3385 Content aCnt( aURL, Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
3386 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = aCnt.getProperties();
3387 if ( xInfo->hasPropertyByName( PROPERTY_TITLE ) )
3389 ::com::sun::star::uno::Any aAny = aCnt.getPropertyValue( PROPERTY_TITLE );
3390 rtl::OUString aValue;
3391 if ( aAny >>= aValue )
3393 String aTitle( aValue );
3394 SfxAddHelpBookmarkDialog_Impl aDlg( this, sal_False );
3395 aDlg.SetTitle( aTitle );
3396 if ( aDlg.Execute() == RET_OK )
3398 aTitle = aDlg.GetTitle();
3399 pIndexWin->AddBookmarks( aTitle, aURL );
3404 catch( Exception& )
3406 DBG_ERROR( "SfxHelpWindow_Impl::DoAction(): unexpected exception" );
3409 break;
3414 // -----------------------------------------------------------------------
3416 void SfxHelpWindow_Impl::CloseWindow()
3420 // search for top frame
3421 Reference< XFramesSupplier > xCreator = getTextFrame()->getCreator();
3422 while ( xCreator.is() && !xCreator->isTop() )
3424 xCreator = xCreator->getCreator();
3427 // when found, close it
3428 if ( xCreator.is() && xCreator->isTop() )
3430 Reference < XCloseable > xCloser( xCreator, UNO_QUERY );
3431 if ( xCloser.is() )
3432 xCloser->close( sal_False );
3435 catch( Exception& )
3437 DBG_ERRORFILE( "SfxHelpWindow_Impl::CloseWindow(): caught an exception" );
3441 // -----------------------------------------------------------------------
3443 void SfxHelpWindow_Impl::UpdateToolbox()
3445 pTextWin->GetToolBox().EnableItem( TBI_BACKWARD, pHelpInterceptor->HasHistoryPred() );
3446 pTextWin->GetToolBox().EnableItem( TBI_FORWARD, pHelpInterceptor->HasHistorySucc() );
3449 // -----------------------------------------------------------------------
3451 sal_Bool SfxHelpWindow_Impl::HasHistoryPredecessor() const
3453 return pHelpInterceptor->HasHistoryPred();
3456 // -----------------------------------------------------------------------
3458 sal_Bool SfxHelpWindow_Impl::HasHistorySuccessor() const
3460 return pHelpInterceptor->HasHistorySucc();
3463 // class SfxAddHelpBookmarkDialog_Impl -----------------------------------
3465 SfxAddHelpBookmarkDialog_Impl::SfxAddHelpBookmarkDialog_Impl( Window* pParent, sal_Bool bRename ) :
3467 ModalDialog( pParent, SfxResId( DLG_HELP_ADDBOOKMARK ) ),
3469 aTitleFT ( this, SfxResId( FT_BOOKMARK_TITLE ) ),
3470 aTitleED ( this, SfxResId( ED_BOOKMARK_TITLE ) ),
3471 aOKBtn ( this, SfxResId( PB_BOOKMARK_OK ) ),
3472 aEscBtn ( this, SfxResId( PB_BOOKMARK_CANCEL ) ),
3473 aHelpBtn ( this, SfxResId( PB_BOOKMARK_HELP ) )
3476 if ( bRename )
3477 SetText( String( SfxResId( STR_BOOKMARK_RENAME ) ) );
3479 FreeResource();
3482 // -----------------------------------------------------------------------
3484 SfxAddHelpBookmarkDialog_Impl::~SfxAddHelpBookmarkDialog_Impl()
3488 // -----------------------------------------------------------------------
3490 void SfxAddHelpBookmarkDialog_Impl::SetTitle( const String& rTitle )
3492 aTitleED.SetText( rTitle );
3493 aTitleED.SetSelection( Selection( 0, rTitle.Len() ) );