xref: /AOO41X/main/sfx2/source/appl/newhelp.cxx (revision ef78578695eb50178a84d88895834f308d563849)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26 
27 #include "newhelp.hxx"
28 #include <sfx2/sfxuno.hxx>
29 #include "sfx2/sfxresid.hxx"
30 #include "helpinterceptor.hxx"
31 #include "helper.hxx"
32 #include <sfx2/msgpool.hxx>
33 #include <sfx2/app.hxx>
34 #include "sfxtypes.hxx"
35 #include "panelist.hxx"
36 #include "sfx2/imgmgr.hxx"
37 #include "srchdlg.hxx"
38 #include "sfx2/sfxhelp.hxx"
39 
40 #include "app.hrc"
41 #include "newhelp.hrc"
42 #include "helpid.hrc"
43 
44 #include <hash_map>
45 #include <rtl/ustrbuf.hxx>
46 #include <comphelper/processfactory.hxx>
47 #include <comphelper/configurationhelper.hxx>
48 #include <toolkit/helper/vclunohelper.hxx>
49 #include <com/sun/star/util/XModifiable.hpp>
50 #include <com/sun/star/frame/XComponentLoader.hpp>
51 #include <com/sun/star/util/XCloseable.hpp>
52 #include <com/sun/star/util/CloseVetoException.hpp>
53 #include <com/sun/star/lang/XComponent.hpp>
54 #include <com/sun/star/lang/DisposedException.hpp>
55 #include <com/sun/star/awt/PosSize.hpp>
56 #include <com/sun/star/awt/XWindow.hpp>
57 #include <com/sun/star/beans/Property.hpp>
58 #include <com/sun/star/beans/PropertyValue.hpp>
59 #include <com/sun/star/beans/XPropertySetInfo.hpp>
60 #include <com/sun/star/container/XIndexAccess.hpp>
61 #include <com/sun/star/frame/XTitle.hpp>
62 #include <com/sun/star/frame/XLayoutManager.hpp>
63 #include <com/sun/star/frame/DispatchResultState.hpp>
64 #include <com/sun/star/frame/XController.hpp>
65 #include <com/sun/star/frame/XDispatch.hpp>
66 #include <com/sun/star/frame/XDispatchProvider.hpp>
67 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
68 #include <com/sun/star/frame/XFrame.hpp>
69 #ifndef _COM_SUN_STAR_TEXT_XBREAKITERATOR_HPP_
70 #include <com/sun/star/i18n/XBreakIterator.hpp>
71 #endif
72 #include <com/sun/star/i18n/WordType.hpp>
73 #include <com/sun/star/lang/XComponent.hpp>
74 #include <com/sun/star/style/XStyle.hpp>
75 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
76 #include <com/sun/star/text/XText.hpp>
77 #include <com/sun/star/text/XTextCursor.hpp>
78 #include <com/sun/star/text/XTextDocument.hpp>
79 #include <com/sun/star/text/XTextRange.hpp>
80 #include <com/sun/star/text/XTextViewCursor.hpp>
81 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
82 #include <com/sun/star/ucb/CommandAbortedException.hpp>
83 #include <com/sun/star/util/URL.hpp>
84 #include <com/sun/star/util/XSearchable.hpp>
85 #include <com/sun/star/util/XSearchDescriptor.hpp>
86 #include <com/sun/star/util/XURLTransformer.hpp>
87 #include <com/sun/star/view/XSelectionSupplier.hpp>
88 #include <com/sun/star/view/XViewSettingsSupplier.hpp>
89 #include <com/sun/star/ui/XDockingAreaAcceptor.hpp>
90 #include <svtools/helpopt.hxx>
91 #include <unotools/historyoptions.hxx>
92 #include <svtools/menuoptions.hxx>
93 #include <unotools/pathoptions.hxx>
94 #include <unotools/viewoptions.hxx>
95 #include <svtools/svtdata.hxx>
96 #include <tools/urlobj.hxx>
97 #include <tools/cachestr.hxx>
98 #include <unotools/streamhelper.hxx>
99 #include <svtools/imagemgr.hxx>
100 #include <svtools/miscopt.hxx>
101 #include <svtools/imgdef.hxx>
102 #include <vcl/unohelp.hxx>
103 #include <vcl/i18nhelp.hxx>
104 
105 #include <ucbhelper/content.hxx>
106 #include <vcl/msgbox.hxx>
107 #include <vcl/waitobj.hxx>
108 #include <unotools/ucbhelper.hxx>
109 
110 #include <sfx2/viewfrm.hxx>
111 #include <sfx2/objsh.hxx>
112 #include <sfx2/docfac.hxx>
113 
114 using namespace ::ucbhelper;
115 using namespace ::com::sun::star::ucb;
116 
117 using namespace ::com::sun::star;
118 using namespace ::com::sun::star::beans;
119 using namespace ::com::sun::star::container;
120 using namespace ::com::sun::star::frame;
121 using namespace ::com::sun::star::i18n;
122 using namespace ::com::sun::star::lang;
123 using namespace ::com::sun::star::style;
124 using namespace ::com::sun::star::text;
125 using namespace ::com::sun::star::uno;
126 using namespace ::com::sun::star::util;
127 using namespace ::com::sun::star::view;
128 using namespace ::com::sun::star::ui;
129 
130 using namespace ::comphelper;
131 
132 extern void AppendConfigToken_Impl( String& rURL, sal_Bool bQuestionMark ); // sfxhelp.cxx
133 
134 // defines ---------------------------------------------------------------
135 
136 #define SPLITSET_ID         0
137 #define COLSET_ID           1
138 #define INDEXWIN_ID         2
139 #define TEXTWIN_ID          3
140 
141 #define TOOLBOX_OFFSET      3
142 
143 #define TBI_INDEX           1001
144 #define TBI_BACKWARD        1002
145 #define TBI_FORWARD         1003
146 #define TBI_START           1004
147 #define TBI_PRINT           1005
148 #define TBI_COPY            1006
149 #define TBI_BOOKMARKS       1007
150 #define TBI_SEARCHDIALOG    1008
151 #define TBI_SOURCEVIEW      1009
152 #define TBI_SELECTIONMODE   1010
153 #define TBI_ONSTARTUP       1011
154 
155 #define CONFIGNAME_HELPWIN      DEFINE_CONST_UNICODE("OfficeHelp")
156 #define CONFIGNAME_INDEXWIN     DEFINE_CONST_UNICODE("OfficeHelpIndex")
157 #define CONFIGNAME_SEARCHPAGE   DEFINE_CONST_UNICODE("OfficeHelpSearch")
158 #define IMAGE_URL               DEFINE_CONST_UNICODE("private:factory/")
159 
160 #define PROPERTY_KEYWORDLIST    DEFINE_CONST_OUSTRING("KeywordList")
161 #define PROPERTY_KEYWORDREF     DEFINE_CONST_OUSTRING("KeywordRef")
162 #define PROPERTY_ANCHORREF      DEFINE_CONST_OUSTRING("KeywordAnchorForRef")
163 #define PROPERTY_TITLEREF       DEFINE_CONST_OUSTRING("KeywordTitleForRef")
164 #define PROPERTY_TITLE          DEFINE_CONST_OUSTRING("Title")
165 #define HELP_URL                DEFINE_CONST_OUSTRING("vnd.sun.star.help://")
166 #define HELP_SEARCH_TAG         DEFINE_CONST_OUSTRING("/?Query=")
167 #define USERITEM_NAME           DEFINE_CONST_OUSTRING("UserItem")
168 
169 #define PACKAGE_SETUP           DEFINE_CONST_OUSTRING("/org.openoffice.Setup")
170 #define PATH_OFFICE_FACTORIES   DEFINE_CONST_OUSTRING("Office/Factories/")
171 #define KEY_HELP_ON_OPEN        DEFINE_CONST_OUSTRING("ooSetupFactoryHelpOnOpen")
172 #define KEY_UI_NAME             DEFINE_CONST_OUSTRING("ooSetupFactoryUIName")
173 
174 #define PARSE_URL( aURL ) \
175     Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( \
176             DEFINE_CONST_UNICODE("com.sun.star.util.URLTransformer" )), UNO_QUERY ); \
177     xTrans->parseStrict( aURL )
178 
179 //.........................................................................
180 namespace sfx2
181 {
182 //.........................................................................
183 
HandleTaskPaneList(Window * pWindow,sal_Bool bAddToList)184     void HandleTaskPaneList( Window* pWindow, sal_Bool bAddToList )
185     {
186         Window* pParent = pWindow->GetParent();
187         DBG_ASSERT( pParent, "HandleTaskPaneList(): every window here should have a parent" );
188 
189         SystemWindow* pSysWin = pParent->GetSystemWindow();
190         if( pSysWin )
191         {
192             TaskPaneList* pTaskPaneList = pSysWin->GetTaskPaneList();
193             if( pTaskPaneList )
194             {
195                 if( bAddToList )
196                     pTaskPaneList->AddWindow( pWindow );
197                 else
198                     pTaskPaneList->RemoveWindow( pWindow );
199             }
200         }
201     }
202 
203     /** Prepare a search string for searching or selecting.
204         For searching every search word needs the postfix '*' and the delimiter ' ' if necessary.
205         For selecting the delimiter '|' is required to search with regular expressions.
206         Samples:
207         search string | output for searching | output for selecting
208         -----------------------------------------------------------
209         "text"        | "text*"              | "text"
210         "text*"       | "text*"              | "text"
211         "text menu"   | "text* menu*"        | "text|menu"
212     */
PrepareSearchString(const String & rSearchString,Reference<XBreakIterator> xBreak,bool bForSearch)213     String PrepareSearchString( const String& rSearchString,
214                                 Reference< XBreakIterator > xBreak, bool bForSearch )
215     {
216         String sSearchStr;
217         sal_Int32 nStartPos = 0;
218         const Locale aLocale = Application::GetSettings().GetUILocale();
219         Boundary aBoundary = xBreak->getWordBoundary(
220             rSearchString, nStartPos, aLocale, WordType::ANYWORD_IGNOREWHITESPACES, sal_True );
221 
222         while ( aBoundary.startPos != aBoundary.endPos )
223         {
224             nStartPos = aBoundary.endPos;
225             String sSearchToken( rSearchString.Copy(
226                 (sal_uInt16)aBoundary.startPos, (sal_uInt16)aBoundary.endPos - (sal_uInt16)aBoundary.startPos ) );
227             if ( sSearchToken.Len() > 0 && ( sSearchToken.Len() > 1 || sSearchToken.GetChar(0) != '.' ) )
228             {
229                 if ( bForSearch && sSearchToken.GetChar( sSearchToken.Len() - 1 ) != '*' )
230                     sSearchToken += '*';
231 
232                 if ( sSearchToken.Len() > 1 ||
233                      ( sSearchToken.Len() > 0 && sSearchToken.GetChar( 0 ) != '*' ) )
234                 {
235                     if ( sSearchStr.Len() > 0 )
236                     {
237                         if ( bForSearch )
238                             sSearchStr += ' ';
239                         else
240                             sSearchStr += '|';
241                     }
242                     sSearchStr += sSearchToken;
243                 }
244             }
245             aBoundary = xBreak->nextWord( rSearchString, nStartPos,
246                                           aLocale, WordType::ANYWORD_IGNOREWHITESPACES );
247         }
248 
249         return sSearchStr;
250     }
251 //.........................................................................
252 // namespace sfx2
253 }
254 //.........................................................................
255 
256 // struct IndexEntry_Impl ------------------------------------------------
257 
258 struct IndexEntry_Impl
259 {
260     sal_Bool        m_bSubEntry;
261     String          m_aURL;
262 
IndexEntry_ImplIndexEntry_Impl263     IndexEntry_Impl( const String& rURL, sal_Bool bSubEntry ) :
264         m_bSubEntry( bSubEntry ), m_aURL( rURL ) {}
265 };
266 
267 #define NEW_ENTRY( url, bool ) \
268     (void*)(sal_uIntPtr)( new IndexEntry_Impl( url, bool ) )
269 
270 // struct ContentEntry_Impl ----------------------------------------------
271 
272 struct ContentEntry_Impl
273 {
274     String      aURL;
275     sal_Bool    bIsFolder;
276 
ContentEntry_ImplContentEntry_Impl277     ContentEntry_Impl( const String& rURL, sal_Bool bFolder ) :
278         aURL( rURL ), bIsFolder( bFolder ) {}
279 };
280 
281 // ContentListBox_Impl ---------------------------------------------------
282 
ContentListBox_Impl(Window * pParent,const ResId & rResId)283 ContentListBox_Impl::ContentListBox_Impl( Window* pParent, const ResId& rResId ) :
284 
285     SvTreeListBox( pParent, rResId ),
286 
287     aOpenBookImage      ( SfxResId( IMG_HELP_CONTENT_BOOK_OPEN ) ),
288     aClosedBookImage    ( SfxResId( IMG_HELP_CONTENT_BOOK_CLOSED ) ),
289     aDocumentImage      ( SfxResId( IMG_HELP_CONTENT_DOC ) )
290 
291 {
292     if ( GetSettings().GetStyleSettings().GetHighContrastMode() )
293     {
294         aOpenBookImage = Image( SfxResId( IMG_HELP_CONTENT_BOOK_OPEN_HC ) );
295         aClosedBookImage = Image( SfxResId( IMG_HELP_CONTENT_BOOK_CLOSED_HC ) );
296         aDocumentImage = Image( SfxResId( IMG_HELP_CONTENT_DOC_HC ) );
297     }
298 
299     SetStyle( GetStyle() | WB_HIDESELECTION | WB_HSCROLL );
300 
301     SetEntryHeight( 16 );
302     SetSelectionMode( SINGLE_SELECTION );
303     SetSpaceBetweenEntries( 2 );
304     SetNodeBitmaps( aClosedBookImage, aOpenBookImage );
305 
306     SetSublistOpenWithReturn();
307     SetSublistOpenWithLeftRight();
308 
309     InitRoot();
310 }
311 
312 // -----------------------------------------------------------------------
313 
~ContentListBox_Impl()314 ContentListBox_Impl::~ContentListBox_Impl()
315 {
316     sal_uInt16 nPos = 0;
317     SvLBoxEntry* pEntry = GetEntry( nPos++ );
318     while ( pEntry )
319     {
320         ::rtl::OUString aTemp( GetEntryText( pEntry ) );
321         ClearChildren( pEntry );
322         delete (ContentEntry_Impl*)pEntry->GetUserData();
323         pEntry = GetEntry( nPos++ );
324     }
325 }
326 
327 // -----------------------------------------------------------------------
328 
InitRoot()329 void ContentListBox_Impl::InitRoot()
330 {
331     String aHelpTreeviewURL( DEFINE_CONST_UNICODE("vnd.sun.star.hier://com.sun.star.help.TreeView/") );
332     ::com::sun::star::uno::Sequence< ::rtl::OUString > aList =
333         SfxContentHelper::GetHelpTreeViewContents( aHelpTreeviewURL );
334 
335     const ::rtl::OUString* pEntries  = aList.getConstArray();
336     sal_uInt32 i, nCount = aList.getLength();
337     for ( i = 0; i < nCount; ++i )
338     {
339         String aRow( pEntries[i] );
340         String aTitle, aURL;
341         xub_StrLen nIdx = 0;
342         aTitle = aRow.GetToken( 0, '\t', nIdx );
343         aURL = aRow.GetToken( 0, '\t', nIdx );
344         sal_Unicode cFolder = aRow.GetToken( 0, '\t', nIdx ).GetChar(0);
345         sal_Bool bIsFolder = ( '1' == cFolder );
346         SvLBoxEntry* pEntry = InsertEntry( aTitle, aOpenBookImage, aClosedBookImage, NULL, sal_True );
347         if ( bIsFolder )
348             pEntry->SetUserData( new ContentEntry_Impl( aURL, sal_True ) );
349     }
350 }
351 
352 // -----------------------------------------------------------------------
353 
ClearChildren(SvLBoxEntry * pParent)354 void ContentListBox_Impl::ClearChildren( SvLBoxEntry* pParent )
355 {
356     SvLBoxEntry* pEntry = FirstChild( pParent );
357     while ( pEntry )
358     {
359         ::rtl::OUString aTemp( GetEntryText( pEntry ) );
360         ClearChildren( pEntry );
361         delete (ContentEntry_Impl*)pEntry->GetUserData();
362         pEntry = NextSibling( pEntry );
363     }
364 }
365 
366 // -----------------------------------------------------------------------
367 
RequestingChilds(SvLBoxEntry * pParent)368 void ContentListBox_Impl::RequestingChilds( SvLBoxEntry* pParent )
369 {
370     try
371     {
372         if ( !pParent->HasChilds() )
373         {
374             if ( pParent->GetUserData() )
375             {
376                 String aTmpURL( ( (ContentEntry_Impl*)pParent->GetUserData()  )->aURL );
377                 ::com::sun::star::uno::Sequence< ::rtl::OUString > aList =
378                     SfxContentHelper::GetHelpTreeViewContents( aTmpURL );
379 
380                 const ::rtl::OUString* pEntries  = aList.getConstArray();
381                 sal_uInt32 i, nCount = aList.getLength();
382                 for ( i = 0; i < nCount; ++i )
383                 {
384                     String aRow( pEntries[i] );
385                     String aTitle, aURL;
386                     xub_StrLen nIdx = 0;
387                     aTitle = aRow.GetToken( 0, '\t', nIdx );
388                     aURL = aRow.GetToken( 0, '\t', nIdx );
389                     sal_Unicode cFolder = aRow.GetToken( 0, '\t', nIdx ).GetChar(0);
390                     sal_Bool bIsFolder = ( '1' == cFolder );
391                     SvLBoxEntry* pEntry = NULL;
392                     if ( bIsFolder )
393                     {
394                         pEntry = InsertEntry( aTitle, aOpenBookImage, aClosedBookImage, pParent, sal_True );
395                         pEntry->SetUserData( new ContentEntry_Impl( aURL, sal_True ) );
396                     }
397                     else
398                     {
399                         pEntry = InsertEntry( aTitle, aDocumentImage, aDocumentImage, pParent );
400                         Any aAny( ::utl::UCBContentHelper::GetProperty( aURL, String(RTL_CONSTASCII_USTRINGPARAM("TargetURL" ) ) ) );
401                         rtl::OUString aTargetURL;
402                         if ( aAny >>=  aTargetURL )
403                             pEntry->SetUserData( new ContentEntry_Impl( aTargetURL, sal_False ) );
404                     }
405                 }
406             }
407         }
408     }
409     catch( Exception& )
410     {
411         DBG_ERROR( "ContentListBox_Impl::RequestingChilds(): unexpected exception" );
412     }
413 }
414 
415 // -----------------------------------------------------------------------
416 
Notify(NotifyEvent & rNEvt)417 long ContentListBox_Impl::Notify( NotifyEvent& rNEvt )
418 {
419     sal_Bool bHandled = sal_False;
420     if ( rNEvt.GetType() == EVENT_KEYINPUT &&
421          KEY_RETURN == rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
422     {
423         GetDoubleClickHdl().Call( NULL );
424         bHandled = sal_True;
425     }
426 
427     return bHandled ? 1 : SvTreeListBox::Notify( rNEvt );
428 }
429 
430 // -----------------------------------------------------------------------
431 
GetSelectEntry() const432 String ContentListBox_Impl::GetSelectEntry() const
433 {
434     String aRet;
435     SvLBoxEntry* pEntry = FirstSelected();
436     if ( pEntry && !( (ContentEntry_Impl*)pEntry->GetUserData()  )->bIsFolder )
437         aRet = ( (ContentEntry_Impl*)pEntry->GetUserData() )->aURL;
438     return aRet;
439 }
440 
441 // class HelpTabPage_Impl ------------------------------------------------
442 
HelpTabPage_Impl(Window * pParent,SfxHelpIndexWindow_Impl * _pIdxWin,const ResId & rResId)443 HelpTabPage_Impl::HelpTabPage_Impl(
444     Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin, const ResId& rResId ) :
445 
446     TabPage( pParent, rResId ),
447 
448     m_pIdxWin( _pIdxWin )
449 
450 {
451 }
452 
453 // class ContentTabPage_Impl ---------------------------------------------
454 
ContentTabPage_Impl(Window * pParent,SfxHelpIndexWindow_Impl * _pIdxWin)455 ContentTabPage_Impl::ContentTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ) :
456 
457     HelpTabPage_Impl( pParent, _pIdxWin, SfxResId( TP_HELP_CONTENT ) ),
458 
459     aContentBox( this, SfxResId( LB_CONTENTS ) )
460 
461 {
462     FreeResource();
463 
464     aContentBox.Show();
465 }
466 
467 // -----------------------------------------------------------------------
468 
Resize()469 void ContentTabPage_Impl::Resize()
470 {
471     Size aSize = GetOutputSizePixel();
472     aSize.Width() -= 8;
473     aSize.Height() -= 8;
474     aContentBox.SetPosSizePixel( Point( 4, 4 ), aSize );
475 }
476 
477 // -----------------------------------------------------------------------
478 
ActivatePage()479 void ContentTabPage_Impl::ActivatePage()
480 {
481     if ( !m_pIdxWin->WasCursorLeftOrRight() )
482         SetFocusOnBox();
483 }
484 
485 // -----------------------------------------------------------------------
486 
GetLastFocusControl()487 Control* ContentTabPage_Impl::GetLastFocusControl()
488 {
489     return &aContentBox;
490 }
491 
492 // class IndexBox_Impl ---------------------------------------------------
493 
IndexBox_Impl(Window * pParent,const ResId & rResId)494 IndexBox_Impl::IndexBox_Impl( Window* pParent, const ResId& rResId ) :
495 
496     ComboBox( pParent, rResId )
497 
498 {
499     EnableAutocomplete( sal_True );
500     EnableUserDraw( sal_True );
501 }
502 
503 // -----------------------------------------------------------------------
504 
UserDraw(const UserDrawEvent & rUDEvt)505 void IndexBox_Impl::UserDraw( const UserDrawEvent& rUDEvt )
506 {
507     IndexEntry_Impl* pEntry = (IndexEntry_Impl*)(sal_uIntPtr)GetEntryData( rUDEvt.GetItemId() );
508     if ( pEntry && pEntry->m_bSubEntry )
509     {
510         // indent sub entries
511         Point aPos( rUDEvt.GetRect().TopLeft() );
512         aPos.X() += 8;
513         aPos.Y() += ( rUDEvt.GetRect().GetHeight() - rUDEvt.GetDevice()->GetTextHeight() ) / 2;
514         String aEntry( GetEntry( rUDEvt.GetItemId() ) );
515         sal_uInt16 nPos = aEntry.Search( ';' );
516         rUDEvt.GetDevice()->DrawText( aPos, ( nPos != STRING_NOTFOUND ) ? aEntry.Copy( nPos + 1 ) : aEntry );
517     }
518     else
519         DrawEntry( rUDEvt, sal_False, sal_True, sal_True );
520 }
521 
522 // -----------------------------------------------------------------------
523 
Notify(NotifyEvent & rNEvt)524 long IndexBox_Impl::Notify( NotifyEvent& rNEvt )
525 {
526     sal_Bool bHandled = sal_False;
527     if ( rNEvt.GetType() == EVENT_KEYINPUT &&
528          KEY_RETURN == rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
529     {
530         GetDoubleClickHdl().Call( NULL );
531         bHandled = sal_True;
532     }
533 
534     return bHandled ? 1 : ComboBox::Notify( rNEvt );
535 }
536 
537 // -----------------------------------------------------------------------
538 
SelectExecutableEntry()539 void IndexBox_Impl::SelectExecutableEntry()
540 {
541     sal_uInt16 nPos = GetEntryPos( GetText() );
542     if ( nPos != COMBOBOX_ENTRY_NOTFOUND )
543     {
544         sal_uInt16 nOldPos = nPos;
545         String aEntryText;
546         IndexEntry_Impl* pEntry = (IndexEntry_Impl*)(sal_uIntPtr)GetEntryData( nPos );
547         sal_uInt16 nCount = GetEntryCount();
548         while ( nPos < nCount && ( !pEntry || pEntry->m_aURL.Len() == 0 ) )
549         {
550             pEntry = (IndexEntry_Impl*)(sal_uIntPtr)GetEntryData( ++nPos );
551             aEntryText = GetEntry( nPos );
552         }
553 
554         if ( nOldPos != nPos )
555             SetText( aEntryText );
556     }
557 }
558 
559 // class IndexTabPage_Impl -----------------------------------------------
560 
IndexTabPage_Impl(Window * pParent,SfxHelpIndexWindow_Impl * _pIdxWin)561 IndexTabPage_Impl::IndexTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ) :
562 
563     HelpTabPage_Impl( pParent, _pIdxWin, SfxResId( TP_HELP_INDEX ) ),
564 
565     aExpressionFT   ( this, SfxResId( FT_EXPRESSION ) ),
566     aIndexCB        ( this, SfxResId( CB_INDEX ) ),
567     aOpenBtn        ( this, SfxResId( PB_OPEN_INDEX ) ),
568 
569     bIsActivated    ( sal_False )
570 
571 {
572     FreeResource();
573 
574     aOpenBtn.SetClickHdl( LINK( this, IndexTabPage_Impl, OpenHdl ) );
575     Link aTimeoutLink = LINK( this, IndexTabPage_Impl, TimeoutHdl );
576     aFactoryTimer.SetTimeoutHdl( aTimeoutLink );
577     aFactoryTimer.SetTimeout( 300 );
578     aKeywordTimer.SetTimeoutHdl( aTimeoutLink );
579     aFactoryTimer.SetTimeout( 300 );
580 
581     nMinWidth = aOpenBtn.GetSizePixel().Width();
582 }
583 
584 // -----------------------------------------------------------------------
585 
~IndexTabPage_Impl()586 IndexTabPage_Impl::~IndexTabPage_Impl()
587 {
588     ClearIndex();
589 }
590 
591 // -----------------------------------------------------------------------
592 
593 namespace sfx2 {
594 
595     struct equalOUString
596     {
operator ()sfx2::equalOUString597         bool operator()( const ::rtl::OUString& rKey1, const ::rtl::OUString& rKey2 ) const
598         {
599             return !!( rKey1 == rKey2 );
600         }
601     };
602 
603 
604     struct hashOUString
605     {
operator ()sfx2::hashOUString606         size_t operator()( const ::rtl::OUString& rName ) const
607         {
608             return rName.hashCode();
609         }
610     };
611 
612     typedef ::std::hash_map< ::rtl::OUString, int, hashOUString, equalOUString > KeywordInfo;
613 }
614 
615 #define UNIFY_AND_INSERT_TOKEN( aToken )                                                            \
616     it =                                                                                            \
617     aInfo.insert( sfx2::KeywordInfo::value_type( aToken, 0 ) ).first;                               \
618     if ( ( tmp = it->second++ ) != 0 )                                                              \
619        nPos = aIndexCB.InsertEntry( aToken + rtl::OUString( append, tmp ) );                        \
620     else                                                                                            \
621        nPos = aIndexCB.InsertEntry( aToken )
622 
623 #define INSERT_DATA( j )                                                                            \
624     if ( aAnchorList[j].getLength() > 0 )                                                           \
625     {                                                                                               \
626         aData.append( aRefList[j] ).append( sal_Unicode('#') ).append( aAnchorList[j] );            \
627         aIndexCB.SetEntryData( nPos, NEW_ENTRY( aData.makeStringAndClear(), insert ) );             \
628     }                                                                                               \
629     else                                                                                            \
630         aIndexCB.SetEntryData( nPos, NEW_ENTRY( aRefList[j], insert ) );
631 
632 // -----------------------------------------------------------------------
633 
InitializeIndex()634 void IndexTabPage_Impl::InitializeIndex()
635 {
636     WaitObject( this );
637 
638     // By now more than 256 equal entries are not allowed
639     sal_Unicode append[256];
640     for( int k = 0; k < 256; ++k )
641         append[k] = sal_Unicode( ' ' );
642 
643     sfx2::KeywordInfo aInfo;
644     aIndexCB.SetUpdateMode( sal_False );
645 
646     try
647     {
648         ::rtl::OUString aURL = HELP_URL;
649         aURL += ::rtl::OUString( sFactory );
650 
651         String aTemp = aURL;
652         AppendConfigToken_Impl( aTemp, sal_True );
653         aURL = aTemp;
654 
655         Content aCnt( aURL, Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
656         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = aCnt.getProperties();
657         if ( xInfo->hasPropertyByName( PROPERTY_ANCHORREF ) )
658         {
659             ::com::sun::star::uno::Sequence< ::rtl::OUString > aPropSeq( 4 );
660             aPropSeq[0] = PROPERTY_KEYWORDLIST;
661             aPropSeq[1] = PROPERTY_KEYWORDREF;
662             aPropSeq[2] = PROPERTY_ANCHORREF;
663             aPropSeq[3] = PROPERTY_TITLEREF;
664 
665             // abi: use one possibly remote call only
666             ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aAnySeq =
667                   aCnt.getPropertyValues( aPropSeq );
668 
669             ::com::sun::star::uno::Sequence< ::rtl::OUString > aKeywordList;
670             ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > aKeywordRefList;
671             ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > aAnchorRefList;
672             ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > aTitleRefList;
673 
674             if ( ( aAnySeq[0] >>= aKeywordList ) && ( aAnySeq[1] >>= aKeywordRefList ) &&
675                  ( aAnySeq[2] >>= aAnchorRefList ) && ( aAnySeq[3] >>= aTitleRefList ) )
676             {
677                 sal_Bool insert;
678                 sal_uInt16 nPos;
679                 int ndx,tmp;
680                 ::rtl::OUString aIndex, aTempString;
681                 ::rtl::OUStringBuffer aData( 128 );            // Capacity of up to 128 characters
682                 sfx2::KeywordInfo::iterator it;
683 
684                 for ( int i = 0; i < aKeywordList.getLength(); ++i )
685                 {
686                     // abi: Do not copy, but use references
687                     const ::rtl::OUString& aKeywordPair = aKeywordList[i];
688                     DBG_ASSERT( aKeywordPair.getLength() > 0, "invalid help index" );
689                     const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRefList = aKeywordRefList[i];
690                     const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aAnchorList = aAnchorRefList[i];
691                     const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aTitleList = aTitleRefList[i];
692 
693                     DBG_ASSERT( aRefList.getLength() == aAnchorList.getLength(),"reference list and title list of different length" );
694 
695                     insert = ( ( ndx = aKeywordPair.indexOf( sal_Unicode( ';' ) ) ) == -1 ? sal_False : sal_True );
696 
697                     if ( insert )
698                     {
699                         aTempString = aKeywordPair.copy( 0, ndx );
700                         if ( aIndex != aTempString )
701                         {
702                             aIndex = aTempString;
703                             UNIFY_AND_INSERT_TOKEN( aTempString );
704                         }
705                     }
706                     else
707                         aIndex = ::rtl::OUString();
708 
709                     // Assume the token is trimed
710                     UNIFY_AND_INSERT_TOKEN( aKeywordPair );
711 
712                     sal_uInt32 nRefListLen = aRefList.getLength();
713 
714                     DBG_ASSERT( aAnchorList.getLength(), "*IndexTabPage_Impl::InitializeIndex(): AnchorList is empty!" );           \
715                     DBG_ASSERT( nRefListLen, "*IndexTabPage_Impl::InitializeIndex(): RefList is empty!" );          \
716 
717                     if ( aAnchorList.getLength() && nRefListLen )
718                     {
719                         INSERT_DATA( 0 );
720                     }
721 
722                     for ( sal_uInt32 j = 1; j < nRefListLen ; ++j )
723                     {
724                         aData
725                             .append( aKeywordPair )
726                             .append( sal_Unicode(' ') )
727                             .append( sal_Unicode('-') )
728                             .append( sal_Unicode(' ') )
729                             .append( aTitleList[j] );
730 
731                         aTempString = aData.makeStringAndClear();
732                         UNIFY_AND_INSERT_TOKEN( aTempString );
733                         INSERT_DATA( j );
734                     }
735                 }
736             }
737         }
738     }
739     catch( Exception& )
740     {
741         DBG_ERROR( "IndexTabPage_Impl::InitializeIndex(): unexpected exception" );
742     }
743 
744     aIndexCB.SetUpdateMode( sal_True );
745 
746     if ( sKeyword.Len() > 0 )
747         aKeywordLink.Call( this );
748 }
749 
750 #undef INSERT_DATA
751 #undef UNIFY_AND_INSERT_TOKEN
752 
753 // -----------------------------------------------------------------------
754 
ClearIndex()755 void IndexTabPage_Impl::ClearIndex()
756 {
757     sal_uInt16 nCount = aIndexCB.GetEntryCount();
758     for ( sal_uInt16 i = 0; i < nCount; ++i )
759         delete (IndexEntry_Impl*)(sal_uIntPtr)aIndexCB.GetEntryData(i);
760     aIndexCB.Clear();
761 }
762 
763 // -----------------------------------------------------------------------
764 
IMPL_LINK(IndexTabPage_Impl,OpenHdl,PushButton *,EMPTYARG)765 IMPL_LINK( IndexTabPage_Impl, OpenHdl, PushButton*, EMPTYARG )
766 {
767     aIndexCB.GetDoubleClickHdl().Call( &aIndexCB );
768     return 0;
769 }
770 
771 // -----------------------------------------------------------------------
772 
IMPL_LINK(IndexTabPage_Impl,TimeoutHdl,Timer *,pTimer)773 IMPL_LINK( IndexTabPage_Impl, TimeoutHdl, Timer*, pTimer )
774 {
775     if ( &aFactoryTimer == pTimer )
776         InitializeIndex();
777     else if ( &aKeywordTimer == pTimer && sKeyword.Len() > 0 )
778         aKeywordLink.Call( this );
779     return 0;
780 }
781 
782 // -----------------------------------------------------------------------
783 
Resize()784 void IndexTabPage_Impl::Resize()
785 {
786     Size aSize = GetSizePixel();
787     if ( aSize.Width() < nMinWidth )
788         aSize.Width() = nMinWidth;
789     Point aPnt = aExpressionFT.GetPosPixel();
790     Size aNewSize = aExpressionFT.GetSizePixel();
791     aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
792     aExpressionFT.SetSizePixel( aNewSize );
793 
794     Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
795     Size aBtnSize = aOpenBtn.GetSizePixel();
796 
797     aPnt = aIndexCB.GetPosPixel();
798     aNewSize = aIndexCB.GetSizePixel();
799     aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
800     aNewSize.Height() = aSize.Height() - aPnt.Y();
801     aNewSize.Height() -= ( aBtnSize.Height() + ( a6Size.Height() * 3 / 2 ) );
802     aIndexCB.SetSizePixel( aNewSize );
803 
804     aPnt.X() += ( aNewSize.Width() - aBtnSize.Width() );
805     aPnt.Y() += aNewSize.Height() + ( a6Size.Height() / 2 );
806     long nMinX = aIndexCB.GetPosPixel().X();
807     if ( aPnt.X() < nMinX )
808         aPnt.X() = nMinX;
809     aOpenBtn.SetPosPixel( aPnt );
810 }
811 
812 // -----------------------------------------------------------------------
813 
ActivatePage()814 void IndexTabPage_Impl::ActivatePage()
815 {
816     if ( !bIsActivated )
817     {
818         bIsActivated = sal_True;
819         aFactoryTimer.Start();
820     }
821 
822     if ( !m_pIdxWin->WasCursorLeftOrRight() )
823         SetFocusOnBox();
824 }
825 
826 // -----------------------------------------------------------------------
827 
GetLastFocusControl()828 Control* IndexTabPage_Impl::GetLastFocusControl()
829 {
830     return &aOpenBtn;
831 }
832 
833 // -----------------------------------------------------------------------
834 
SetDoubleClickHdl(const Link & rLink)835 void IndexTabPage_Impl::SetDoubleClickHdl( const Link& rLink )
836 {
837     aIndexCB.SetDoubleClickHdl( rLink );
838 }
839 
840 // -----------------------------------------------------------------------
841 
SetFactory(const String & rFactory)842 void IndexTabPage_Impl::SetFactory( const String& rFactory )
843 {
844     String sNewFactory( rFactory );
845     DBG_ASSERT( sNewFactory.Len() > 0, "empty factory" );
846     bool bValid = m_pIdxWin->IsValidFactory( rFactory );
847 
848     if ( sFactory.Len() == 0 && !bValid )
849     {
850         sNewFactory = SfxHelp::GetDefaultHelpModule();
851         bValid = true;
852     }
853 
854     if ( sNewFactory != sFactory && bValid )
855     {
856         sFactory = sNewFactory;
857         ClearIndex();
858         if ( bIsActivated )
859             aFactoryTimer.Start();
860     }
861 }
862 
863 // -----------------------------------------------------------------------
864 
GetSelectEntry() const865 String IndexTabPage_Impl::GetSelectEntry() const
866 {
867     String aRet;
868     IndexEntry_Impl* pEntry = (IndexEntry_Impl*)(sal_uIntPtr)aIndexCB.GetEntryData( aIndexCB.GetEntryPos( aIndexCB.GetText() ) );
869     if ( pEntry )
870         aRet = pEntry->m_aURL;
871     return aRet;
872 }
873 
874 // -----------------------------------------------------------------------
875 
SetKeyword(const String & rKeyword)876 void IndexTabPage_Impl::SetKeyword( const String& rKeyword )
877 {
878     sKeyword = rKeyword;
879 
880     if ( aIndexCB.GetEntryCount() > 0 )
881         aKeywordTimer.Start();
882     else if ( !bIsActivated )
883         aFactoryTimer.Start();
884 }
885 
886 // -----------------------------------------------------------------------
887 
HasKeyword() const888 sal_Bool IndexTabPage_Impl::HasKeyword() const
889 {
890     sal_Bool bRet = sal_False;
891     if ( sKeyword.Len() > 0 )
892     {
893         sal_uInt16 nPos = aIndexCB.GetEntryPos( sKeyword );
894         bRet = ( nPos != LISTBOX_ENTRY_NOTFOUND );
895     }
896 
897     return bRet;
898 }
899 
900 // -----------------------------------------------------------------------
901 //added by BerryJia for fixing Bug98251, 2002-12-11
HasKeywordIgnoreCase()902 sal_Bool IndexTabPage_Impl::HasKeywordIgnoreCase()
903 {
904     sal_Bool bRet = sal_False;
905     if ( sKeyword.Len() > 0 )
906     {
907         sal_uInt16 nEntries = aIndexCB.GetEntryCount();
908         String sIndexItem;
909         const vcl::I18nHelper& rI18nHelper = GetSettings().GetLocaleI18nHelper();
910         for ( sal_uInt16 n = 0; n < nEntries; n++)
911         {
912             sIndexItem = aIndexCB.GetEntry( n );
913             if (rI18nHelper.MatchString( sIndexItem, sKeyword ))
914             {
915                 sKeyword = sIndexItem;
916                 bRet = sal_True;
917             }
918         }
919     }
920 
921     return bRet;
922 }
923 
924 // -----------------------------------------------------------------------
925 
OpenKeyword()926 void IndexTabPage_Impl::OpenKeyword()
927 {
928     if ( sKeyword.Len() > 0 )
929     {
930         aIndexCB.SetText( sKeyword );
931         aIndexCB.GetDoubleClickHdl().Call( NULL );
932         sKeyword.Erase();
933     }
934 }
935 
936 // class SearchBox_Impl --------------------------------------------------
937 
PreNotify(NotifyEvent & rNEvt)938 long SearchBox_Impl::PreNotify( NotifyEvent& rNEvt )
939 {
940     sal_Bool bHandled = sal_False;
941     if ( !IsInDropDown() &&
942          rNEvt.GetWindow() == GetSubEdit() &&
943          rNEvt.GetType() == EVENT_KEYINPUT &&
944          KEY_RETURN == rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
945     {
946         aSearchLink.Call( NULL );
947         bHandled = sal_True;
948     }
949     return bHandled ? 1 : ComboBox::PreNotify( rNEvt );
950 }
951 
952 // -----------------------------------------------------------------------
953 
Select()954 void SearchBox_Impl::Select()
955 {
956     if ( !IsTravelSelect() )
957         aSearchLink.Call( NULL );
958 }
959 
960 // class SearchResultsBox_Impl -------------------------------------------
961 
Notify(NotifyEvent & rNEvt)962 long SearchResultsBox_Impl::Notify( NotifyEvent& rNEvt )
963 {
964     sal_Bool bHandled = sal_False;
965     if ( rNEvt.GetType() == EVENT_KEYINPUT &&
966          KEY_RETURN == rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
967     {
968         GetDoubleClickHdl().Call( NULL );
969         bHandled = sal_True;
970     }
971 
972     return bHandled ? 1 : ListBox::Notify( rNEvt );
973 }
974 
975 // class SearchTabPage_Impl ----------------------------------------------
976 
SearchTabPage_Impl(Window * pParent,SfxHelpIndexWindow_Impl * _pIdxWin)977 SearchTabPage_Impl::SearchTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ) :
978 
979     HelpTabPage_Impl( pParent, _pIdxWin, SfxResId( TP_HELP_SEARCH ) ),
980 
981     aSearchFT       ( this, SfxResId( FT_SEARCH ) ),
982     aSearchED       ( this, SfxResId( ED_SEARCH ) ),
983     aSearchBtn      ( this, SfxResId( PB_SEARCH ) ),
984     aFullWordsCB    ( this, SfxResId( CB_FULLWORDS ) ),
985     aScopeCB        ( this, SfxResId( CB_SCOPE ) ),
986     aResultsLB      ( this, SfxResId( LB_RESULT ) ),
987     aOpenBtn        ( this, SfxResId( PB_OPEN_SEARCH ) ),
988     xBreakIterator  ( vcl::unohelper::CreateBreakIterator() )
989 
990 {
991     FreeResource();
992 
993     Link aLink = LINK( this, SearchTabPage_Impl, SearchHdl );
994     aSearchED.SetSearchLink( aLink );
995     aSearchBtn.SetClickHdl( aLink );
996     aSearchED.SetModifyHdl( LINK( this, SearchTabPage_Impl, ModifyHdl ) );
997     aOpenBtn.SetClickHdl( LINK( this, SearchTabPage_Impl, OpenHdl ) );
998 
999     aMinSize = GetSizePixel();
1000 
1001     SvtViewOptions aViewOpt( E_TABPAGE, CONFIGNAME_SEARCHPAGE );
1002     if ( aViewOpt.Exists() )
1003     {
1004         String aUserData;
1005         Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
1006         ::rtl::OUString aTemp;
1007         if ( aUserItem >>= aTemp )
1008         {
1009             aUserData = String( aTemp );
1010             sal_Bool bChecked = ( 1 == aUserData.GetToken(0).ToInt32() ) ? sal_True : sal_False;
1011             aFullWordsCB.Check( bChecked );
1012             bChecked = ( 1 == aUserData.GetToken(1).ToInt32() ) ? sal_True : sal_False;
1013             aScopeCB.Check( bChecked );
1014 
1015             for ( sal_uInt16 i = 2; i < aUserData.GetTokenCount(); ++i )
1016             {
1017                 String aToken = aUserData.GetToken(i);
1018                 aSearchED.InsertEntry( INetURLObject::decode(
1019                     aToken, '%', INetURLObject::DECODE_WITH_CHARSET ) );
1020             }
1021         }
1022     }
1023 
1024     ModifyHdl( &aSearchED );
1025 }
1026 
1027 // -----------------------------------------------------------------------
1028 
~SearchTabPage_Impl()1029 SearchTabPage_Impl::~SearchTabPage_Impl()
1030 {
1031     SvtViewOptions aViewOpt( E_TABPAGE, CONFIGNAME_SEARCHPAGE );
1032     sal_Int32 nChecked = aFullWordsCB.IsChecked() ? 1 : 0;
1033     String aUserData = String::CreateFromInt32( nChecked );
1034     aUserData += ';';
1035     nChecked = aScopeCB.IsChecked() ? 1 : 0;
1036     aUserData += String::CreateFromInt32( nChecked );
1037     aUserData += ';';
1038     sal_uInt16 nCount = Min( aSearchED.GetEntryCount(), (sal_uInt16)10 );  // save only 10 entries
1039 
1040     for ( sal_uInt16 i = 0; i < nCount; ++i )
1041     {
1042         rtl::OUString aText = aSearchED.GetEntry(i);
1043         aUserData += String(INetURLObject::encode(
1044             aText, INetURLObject::PART_UNO_PARAM_VALUE, '%',
1045             INetURLObject::ENCODE_ALL ));
1046         aUserData += ';';
1047     }
1048 
1049     aUserData.EraseTrailingChars(';');
1050     Any aUserItem = makeAny( ::rtl::OUString( aUserData ) );
1051     aViewOpt.SetUserItem( USERITEM_NAME, aUserItem );
1052 }
1053 
1054 // -----------------------------------------------------------------------
1055 
ClearSearchResults()1056 void SearchTabPage_Impl::ClearSearchResults()
1057 {
1058     sal_uInt16 nCount = aResultsLB.GetEntryCount();
1059     for ( sal_uInt16 i = 0; i < nCount; ++i )
1060         delete (String*)(sal_uIntPtr)aResultsLB.GetEntryData(i);
1061     aResultsLB.Clear();
1062     aResultsLB.Update();
1063 }
1064 
1065 // -----------------------------------------------------------------------
1066 
RememberSearchText(const String & rSearchText)1067 void SearchTabPage_Impl::RememberSearchText( const String& rSearchText )
1068 {
1069     for ( sal_uInt16 i = 0; i < aSearchED.GetEntryCount(); ++i )
1070     {
1071         if ( rSearchText == aSearchED.GetEntry(i) )
1072         {
1073             aSearchED.RemoveEntry(i);
1074             break;
1075         }
1076     }
1077 
1078     aSearchED.InsertEntry( rSearchText, 0 );
1079 }
1080 
1081 // -----------------------------------------------------------------------
1082 
IMPL_LINK(SearchTabPage_Impl,SearchHdl,PushButton *,EMPTYARG)1083 IMPL_LINK( SearchTabPage_Impl, SearchHdl, PushButton*, EMPTYARG )
1084 {
1085     String aSearchText = TRIM( aSearchED.GetText() );
1086     if ( aSearchText.Len() > 0 )
1087     {
1088         EnterWait();
1089         ClearSearchResults();
1090         RememberSearchText( aSearchText );
1091         String aSearchURL = HELP_URL;
1092         aSearchURL += aFactory;
1093         aSearchURL += String( HELP_SEARCH_TAG );
1094         if ( !aFullWordsCB.IsChecked() )
1095             aSearchText = sfx2::PrepareSearchString( aSearchText, xBreakIterator, true );
1096         aSearchURL += aSearchText;
1097         AppendConfigToken_Impl( aSearchURL, sal_False );
1098         if ( aScopeCB.IsChecked() )
1099             aSearchURL += DEFINE_CONST_UNICODE("&Scope=Heading");
1100         Sequence< ::rtl::OUString > aFactories = SfxContentHelper::GetResultSet( aSearchURL );
1101         const ::rtl::OUString* pFacs  = aFactories.getConstArray();
1102         sal_uInt32 i, nCount = aFactories.getLength();
1103         for ( i = 0; i < nCount; ++i )
1104         {
1105             String aRow( pFacs[i] );
1106             String aTitle, aType;
1107             xub_StrLen nIdx = 0;
1108             aTitle = aRow.GetToken( 0, '\t', nIdx );
1109             aType = aRow.GetToken( 0, '\t', nIdx );
1110             String* pURL = new String( aRow.GetToken( 0, '\t', nIdx ) );
1111             sal_uInt16 nPos = aResultsLB.InsertEntry( aTitle );
1112             aResultsLB.SetEntryData( nPos, (void*)(sal_uIntPtr)pURL );
1113         }
1114         LeaveWait();
1115 
1116         if ( !nCount )
1117         {
1118             InfoBox aBox( this, SfxResId( RID_INFO_NOSEARCHRESULTS ) );
1119             aBox.SetText( String( SfxResId( STR_HELP_WINDOW_TITLE ) ) );
1120             aBox.Execute();
1121         }
1122     }
1123     return 0;
1124 }
1125 
1126 // -----------------------------------------------------------------------
1127 
IMPL_LINK(SearchTabPage_Impl,OpenHdl,PushButton *,EMPTYARG)1128 IMPL_LINK( SearchTabPage_Impl, OpenHdl, PushButton*, EMPTYARG )
1129 {
1130     aResultsLB.GetDoubleClickHdl().Call( &aResultsLB );
1131     return 0;
1132 }
1133 
1134 // -----------------------------------------------------------------------
1135 
IMPL_LINK(SearchTabPage_Impl,ModifyHdl,Edit *,EMPTYARG)1136 IMPL_LINK( SearchTabPage_Impl, ModifyHdl, Edit*, EMPTYARG )
1137 {
1138     String aSearchText = TRIM( aSearchED.GetText() );
1139     aSearchBtn.Enable( aSearchText.Len() > 0 );
1140     return 0;
1141 }
1142 
1143 // -----------------------------------------------------------------------
1144 
Resize()1145 void SearchTabPage_Impl::Resize()
1146 {
1147     Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
1148     Size aSize = GetSizePixel();
1149     if ( aSize.Width() < aMinSize.Width() )
1150         aSize.Width() = aMinSize.Width();
1151     Point aPnt = aSearchFT.GetPosPixel();
1152     Size aNewSize = aSearchFT.GetSizePixel();
1153     aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
1154     aSearchFT.SetSizePixel( aNewSize );
1155     aNewSize.Height() = aResultsLB.GetSizePixel().Height();
1156     aResultsLB.SetSizePixel( aNewSize );
1157     aNewSize.Height() = aFullWordsCB.GetSizePixel().Height();
1158     aFullWordsCB.SetSizePixel( aNewSize );
1159     aScopeCB.SetSizePixel( aNewSize );
1160     aNewSize = aSearchED.GetSizePixel();
1161     aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 ) -
1162                        ( aSearchBtn.GetSizePixel().Width() + ( aPnt.X() / 2 ) );
1163     aSearchED.SetSizePixel( aNewSize );
1164     Point aNewPnt = aSearchBtn.GetPosPixel();
1165     aNewPnt.X() = aPnt.X() + aNewSize.Width() + ( aPnt.X() / 2 );
1166     aSearchBtn.SetPosPixel( aNewPnt );
1167 
1168     if ( aSize.Height() > aMinSize.Height() )
1169     {
1170         long n3Height = a6Size.Height() / 2;
1171         Size aBtnSize = aOpenBtn.GetSizePixel();
1172         long nExtraHeight = aBtnSize.Height() + n3Height;
1173 
1174         aPnt = aResultsLB.GetPosPixel();
1175         aNewSize = aResultsLB.GetSizePixel();
1176         aNewSize.Height() = aSize.Height() - aPnt.Y();
1177         aNewSize.Height() -= ( nExtraHeight + ( a6Size.Height() * 3 / 2 ) );
1178         aResultsLB.SetSizePixel( aNewSize );
1179 
1180         aPnt.X() += ( aNewSize.Width() - aBtnSize.Width() );
1181         aPnt.Y() += aNewSize.Height() + a6Size.Height();
1182         aOpenBtn.SetPosPixel( aPnt );
1183     }
1184 }
1185 
1186 // -----------------------------------------------------------------------
1187 
ActivatePage()1188 void SearchTabPage_Impl::ActivatePage()
1189 {
1190     if ( !m_pIdxWin->WasCursorLeftOrRight() )
1191         aSearchED.GrabFocus();
1192 }
1193 
1194 // -----------------------------------------------------------------------
1195 
GetLastFocusControl()1196 Control* SearchTabPage_Impl::GetLastFocusControl()
1197 {
1198     return &aOpenBtn;
1199 }
1200 
1201 // -----------------------------------------------------------------------
1202 
SetDoubleClickHdl(const Link & rLink)1203 void SearchTabPage_Impl::SetDoubleClickHdl( const Link& rLink )
1204 {
1205     aResultsLB.SetDoubleClickHdl( rLink );
1206 }
1207 
1208 // -----------------------------------------------------------------------
1209 
GetSelectEntry() const1210 String SearchTabPage_Impl::GetSelectEntry() const
1211 {
1212     String aRet;
1213     String* pData = (String*)(sal_uIntPtr)aResultsLB.GetEntryData( aResultsLB.GetSelectEntryPos() );
1214     if ( pData )
1215         aRet = String( *pData );
1216     return aRet;
1217 }
1218 
1219 // -----------------------------------------------------------------------
1220 
ClearPage()1221 void SearchTabPage_Impl::ClearPage()
1222 {
1223     ClearSearchResults();
1224     aSearchED.SetText( String() );
1225 }
1226 
1227 // -----------------------------------------------------------------------
1228 
OpenKeyword(const String & rKeyword)1229 sal_Bool SearchTabPage_Impl::OpenKeyword( const String& rKeyword )
1230 {
1231     sal_Bool bRet = sal_False;
1232     aSearchED.SetText( rKeyword );
1233     SearchHdl( NULL );
1234     if ( aResultsLB.GetEntryCount() > 0 )
1235     {
1236         // found keyword -> open it
1237         aResultsLB.SelectEntryPos(0);
1238         OpenHdl( NULL );
1239         bRet = sal_True;
1240     }
1241 
1242     return bRet;
1243 }
1244 
1245 // class BookmarksTabPage_Impl -------------------------------------------
1246 
GetBookmarkEntry_Impl(Sequence<PropertyValue> & aBookmarkEntry,::rtl::OUString & rTitle,::rtl::OUString & rURL)1247 void GetBookmarkEntry_Impl
1248 (
1249     Sequence< PropertyValue >& aBookmarkEntry,
1250     ::rtl::OUString& rTitle,
1251     ::rtl::OUString& rURL
1252 )
1253 {
1254     for ( int i = 0; i < aBookmarkEntry.getLength(); i++ )
1255     {
1256         PropertyValue aValue = aBookmarkEntry[i];
1257         if ( aValue.Name == HISTORY_PROPERTYNAME_URL )
1258             aValue.Value >>= rURL;
1259         else if ( aValue.Name == HISTORY_PROPERTYNAME_TITLE )
1260             aValue.Value >>= rTitle;
1261     }
1262 }
1263 
1264 // -----------------------------------------------------------------------
1265 
BookmarksBox_Impl(Window * pParent,const ResId & rResId)1266 BookmarksBox_Impl::BookmarksBox_Impl( Window* pParent, const ResId& rResId ) :
1267 
1268     ListBox( pParent, rResId )
1269 
1270 {
1271 }
1272 
1273 // -----------------------------------------------------------------------
1274 
~BookmarksBox_Impl()1275 BookmarksBox_Impl::~BookmarksBox_Impl()
1276 {
1277     // save bookmarks to configuration
1278     SvtHistoryOptions aHistOpt;
1279     aHistOpt.Clear( eHELPBOOKMARKS );
1280     rtl::OUString sEmpty;
1281     sal_uInt16 nCount = GetEntryCount();
1282     for ( sal_uInt16 i = 0; i < nCount; ++i )
1283     {
1284         String aTitle = GetEntry(i);
1285         String* pURL = (String*)(sal_uIntPtr)GetEntryData(i);
1286         aHistOpt.AppendItem( eHELPBOOKMARKS, rtl::OUString( *pURL ), sEmpty, rtl::OUString( aTitle ), sEmpty );
1287         delete pURL;
1288     }
1289 }
1290 
1291 // -----------------------------------------------------------------------
1292 
DoAction(sal_uInt16 nAction)1293 void BookmarksBox_Impl::DoAction( sal_uInt16 nAction )
1294 {
1295     switch ( nAction )
1296     {
1297         case MID_OPEN :
1298             GetDoubleClickHdl().Call( NULL );
1299             break;
1300 
1301         case MID_RENAME :
1302         {
1303             sal_uInt16 nPos = GetSelectEntryPos();
1304             if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1305             {
1306                 SfxAddHelpBookmarkDialog_Impl aDlg( this, sal_True );
1307                 aDlg.SetTitle( GetEntry( nPos ) );
1308                 if ( aDlg.Execute() == RET_OK )
1309                 {
1310                     String* pURL = (String*)(sal_uIntPtr)GetEntryData( nPos );
1311                     RemoveEntry( nPos );
1312                     rtl::OUString aImageURL = IMAGE_URL;
1313                     aImageURL += INetURLObject( *pURL ).GetHost();
1314                     nPos = InsertEntry( aDlg.GetTitle(), SvFileInformationManager::GetImage( aImageURL ) );
1315                     SetEntryData( nPos, (void*)(sal_uIntPtr)( new String( *pURL ) ) );
1316                     SelectEntryPos( nPos );
1317                     delete pURL;
1318                 }
1319             }
1320             break;
1321         }
1322 
1323         case MID_DELETE :
1324         {
1325             sal_uInt16 nPos = GetSelectEntryPos();
1326             if ( nPos != LISTBOX_ENTRY_NOTFOUND )
1327             {
1328                 RemoveEntry( nPos );
1329                 sal_uInt16 nCount = GetEntryCount();
1330                 if ( nCount )
1331                 {
1332                     if ( nPos >= nCount )
1333                         nPos = nCount - 1;
1334                     SelectEntryPos( nPos );
1335                 }
1336             }
1337             break;
1338         }
1339     }
1340 }
1341 
1342 // -----------------------------------------------------------------------
1343 
Notify(NotifyEvent & rNEvt)1344 long BookmarksBox_Impl::Notify( NotifyEvent& rNEvt )
1345 {
1346     long nRet = 0;
1347     sal_uInt16 nType = rNEvt.GetType();
1348     if ( EVENT_KEYINPUT == nType )
1349     {
1350         sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
1351         if ( KEY_DELETE == nCode && GetEntryCount() > 0 )
1352         {
1353             DoAction( MID_DELETE );
1354             nRet = 1;
1355         }
1356         else if ( KEY_RETURN == nCode )
1357         {
1358             GetDoubleClickHdl().Call( NULL );
1359             nRet = 1;
1360         }
1361     }
1362     else if ( EVENT_COMMAND == nType )
1363     {
1364         const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
1365         if ( pCEvt->GetCommand() == COMMAND_CONTEXTMENU )
1366         {
1367             PopupMenu aMenu( SfxResId( MENU_HELP_BOOKMARKS ) );
1368             sal_uInt16 nId = aMenu.Execute( this, pCEvt->GetMousePosPixel() );
1369             if ( nId != MENU_ITEM_NOTFOUND )
1370                 DoAction( nId );
1371             nRet = 1;
1372         }
1373     }
1374 
1375     return nRet ? nRet : ListBox::Notify( rNEvt );
1376 }
1377 
1378 // class BookmarksTabPage_Impl -------------------------------------------
1379 
BookmarksTabPage_Impl(Window * pParent,SfxHelpIndexWindow_Impl * _pIdxWin)1380 BookmarksTabPage_Impl::BookmarksTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ) :
1381 
1382     HelpTabPage_Impl( pParent, _pIdxWin, SfxResId( TP_HELP_BOOKMARKS ) ),
1383 
1384     aBookmarksFT    ( this, SfxResId( FT_BOOKMARKS ) ),
1385     aBookmarksBox   ( this, SfxResId( LB_BOOKMARKS ) ),
1386     aBookmarksPB    ( this, SfxResId( PB_BOOKMARKS ) )
1387 
1388 {
1389     FreeResource();
1390 
1391     nMinWidth = aBookmarksPB.GetSizePixel().Width();
1392 
1393     aBookmarksPB.SetClickHdl( LINK( this, BookmarksTabPage_Impl, OpenHdl ) );
1394 
1395     // load bookmarks from configuration
1396     Sequence< Sequence< PropertyValue > > aBookmarkSeq;
1397     aBookmarkSeq = SvtHistoryOptions().GetList( eHELPBOOKMARKS );
1398 
1399     ::rtl::OUString aTitle;
1400     ::rtl::OUString aURL;
1401 
1402     sal_uInt32 i, nCount = aBookmarkSeq.getLength();
1403     for ( i = 0; i < nCount; ++i )
1404     {
1405         GetBookmarkEntry_Impl( aBookmarkSeq[i], aTitle, aURL );
1406         AddBookmarks( aTitle, aURL );
1407     }
1408 }
1409 
1410 // -----------------------------------------------------------------------
1411 
IMPL_LINK(BookmarksTabPage_Impl,OpenHdl,PushButton *,EMPTYARG)1412 IMPL_LINK( BookmarksTabPage_Impl, OpenHdl, PushButton*, EMPTYARG )
1413 {
1414     aBookmarksBox.GetDoubleClickHdl().Call( &aBookmarksBox );
1415     return 0;
1416 }
1417 
1418 // -----------------------------------------------------------------------
1419 
Resize()1420 void BookmarksTabPage_Impl::Resize()
1421 {
1422     Size aSize = GetSizePixel();
1423     if ( aSize.Width() < nMinWidth )
1424         aSize.Width() = nMinWidth;
1425     Point aPnt = aBookmarksFT.GetPosPixel();
1426     Size aNewSize = aBookmarksFT.GetSizePixel();
1427     aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
1428     aBookmarksFT.SetSizePixel( aNewSize );
1429 
1430     Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
1431     Size aBtnSize = aBookmarksPB.GetSizePixel();
1432 
1433     aPnt = aBookmarksBox.GetPosPixel();
1434     aNewSize = aBookmarksBox.GetSizePixel();
1435     aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
1436     aNewSize.Height() = aSize.Height() - aPnt.Y();
1437     aNewSize.Height() -= ( aBtnSize.Height() + ( a6Size.Height() * 3 / 2 ) );
1438     aBookmarksBox.SetSizePixel( aNewSize );
1439 
1440     aPnt.X() += ( aNewSize.Width() - aBtnSize.Width() );
1441     aPnt.Y() += aNewSize.Height() + ( a6Size.Height() / 2 );
1442     long nMinX = aBookmarksBox.GetPosPixel().X();
1443     if ( aPnt.X() < nMinX )
1444         aPnt.X() = nMinX;
1445     aBookmarksPB.SetPosPixel( aPnt );
1446 }
1447 
1448 // -----------------------------------------------------------------------
1449 
ActivatePage()1450 void BookmarksTabPage_Impl::ActivatePage()
1451 {
1452     if ( !m_pIdxWin->WasCursorLeftOrRight() )
1453         SetFocusOnBox();
1454 }
1455 
1456 // -----------------------------------------------------------------------
1457 
GetLastFocusControl()1458 Control* BookmarksTabPage_Impl::GetLastFocusControl()
1459 {
1460     return &aBookmarksPB;
1461 }
1462 
1463 // -----------------------------------------------------------------------
1464 
SetDoubleClickHdl(const Link & rLink)1465 void BookmarksTabPage_Impl::SetDoubleClickHdl( const Link& rLink )
1466 {
1467     aBookmarksBox.SetDoubleClickHdl( rLink );
1468 }
1469 
1470 // -----------------------------------------------------------------------
1471 
GetSelectEntry() const1472 String BookmarksTabPage_Impl::GetSelectEntry() const
1473 {
1474     String aRet;
1475     String* pData = (String*)(sal_uIntPtr)aBookmarksBox.GetEntryData( aBookmarksBox.GetSelectEntryPos() );
1476     if ( pData )
1477         aRet = String( *pData );
1478     return aRet;
1479 }
1480 
1481 // -----------------------------------------------------------------------
1482 
AddBookmarks(const String & rTitle,const String & rURL)1483 void BookmarksTabPage_Impl::AddBookmarks( const String& rTitle, const String& rURL )
1484 {
1485     rtl::OUString aImageURL = IMAGE_URL;
1486     aImageURL += INetURLObject( rURL ).GetHost();
1487     sal_uInt16 nPos = aBookmarksBox.InsertEntry( rTitle, SvFileInformationManager::GetImage( aImageURL ) );
1488     aBookmarksBox.SetEntryData( nPos, (void*)(sal_uIntPtr)( new String( rURL ) ) );
1489 }
1490 
1491 // class SfxHelpIndexWindow_Impl -----------------------------------------
1492 
splitHelpURL(const::rtl::OUString & sHelpURL,::rtl::OUString & sFactory,::rtl::OUString & sContent,::rtl::OUString & sAnchor)1493 sal_Bool SfxHelpWindow_Impl::splitHelpURL(const ::rtl::OUString& sHelpURL,
1494                                                 ::rtl::OUString& sFactory,
1495                                                 ::rtl::OUString& sContent,
1496                                                 ::rtl::OUString& sAnchor )
1497 {
1498     Reference < XURLTransformer > xParser( ::comphelper::getProcessServiceFactory()->createInstance(
1499             DEFINE_CONST_UNICODE("com.sun.star.util.URLTransformer" )), UNO_QUERY_THROW );
1500 
1501     URL aURL;
1502     aURL.Complete = sHelpURL;
1503     sal_Bool bResult = xParser->parseStrict(aURL);
1504 
1505     sFactory = aURL.Server;
1506     sContent = aURL.Path.copy(1); // strip "/"!
1507     sAnchor  = aURL.Mark;
1508 
1509     return bResult;
1510 }
1511 
buildHelpURL(const::rtl::OUString & sFactory,const::rtl::OUString & sContent,const::rtl::OUString & sAnchor,sal_Bool bUseQuestionMark)1512 ::rtl::OUString SfxHelpWindow_Impl::buildHelpURL(const ::rtl::OUString& sFactory        ,
1513                                                  const ::rtl::OUString& sContent        ,
1514                                                  const ::rtl::OUString& sAnchor         ,
1515                                                        sal_Bool         bUseQuestionMark)
1516 {
1517     ::rtl::OUStringBuffer sHelpURL(256);
1518     sHelpURL.append(HELP_URL);
1519     sHelpURL.append(sFactory);
1520     sHelpURL.append(sContent);
1521     String sURL = String(sHelpURL.makeStringAndClear());
1522     AppendConfigToken_Impl(sURL, bUseQuestionMark);
1523     if (sAnchor.getLength())
1524         sURL += String(sAnchor);
1525     return ::rtl::OUString(sURL);
1526 }
1527 
loadHelpContent(const::rtl::OUString & sHelpURL,sal_Bool bAddToHistory)1528 void SfxHelpWindow_Impl::loadHelpContent(const ::rtl::OUString& sHelpURL, sal_Bool bAddToHistory)
1529 {
1530     Reference< XComponentLoader > xLoader(getTextFrame(), UNO_QUERY);
1531     if (!xLoader.is())
1532         return;
1533 
1534     // --> PB 2007-03-12 #134037#
1535     // If a print job runs do not open a new page
1536     Reference< XFrame >      xTextFrame      = pTextWin->getFrame();
1537     Reference< XController > xTextController ;
1538     if (xTextFrame.is())
1539         xTextController = xTextFrame->getController ();
1540     if ( xTextController.is() && !xTextController->suspend( sal_True ) )
1541     {
1542         xTextController->suspend( sal_False );
1543         return;
1544     }
1545     // <--
1546 
1547     // save url to history
1548     if (bAddToHistory)
1549         pHelpInterceptor->addURL(sHelpURL);
1550 
1551     if ( !IsWait() )
1552         EnterWait();
1553     sal_Bool bSuccess = sal_False;
1554 // TODO implement locale fallback ... see below    while(sal_True)
1555     {
1556         try
1557         {
1558             Reference< XComponent > xContent = xLoader->loadComponentFromURL(sHelpURL, DEFINE_CONST_UNICODE("_self"), 0, Sequence< PropertyValue >());
1559             if (xContent.is())
1560             {
1561                 bSuccess = sal_True;
1562 //                break;
1563             }
1564         }
1565         catch(const RuntimeException&)
1566             { throw; }
1567         catch(const Exception&)
1568             { /*break;*/ }
1569 
1570         /* TODO try next locale ...
1571                 no further locale available? => break loop and show error page
1572         */
1573     }
1574     openDone(sHelpURL, bSuccess);
1575     if ( IsWait() )
1576         LeaveWait();
1577 }
1578 
SfxHelpIndexWindow_Impl(SfxHelpWindow_Impl * _pParent)1579 SfxHelpIndexWindow_Impl::SfxHelpIndexWindow_Impl( SfxHelpWindow_Impl* _pParent ) :
1580 
1581     Window( _pParent, SfxResId( WIN_HELPINDEX ) ),
1582 
1583     aActiveLB           ( this, SfxResId( LB_ACTIVE ) ),
1584     aActiveLine         ( this, SfxResId( FL_ACTIVE ) ),
1585     aTabCtrl            ( this, SfxResId( TC_INDEX ) ),
1586 
1587     aIndexKeywordLink   ( LINK( this, SfxHelpIndexWindow_Impl, KeywordHdl ) ),
1588     pParentWin          ( _pParent ),
1589 
1590     pCPage              ( NULL ),
1591     pIPage              ( NULL ),
1592     pSPage              ( NULL ),
1593     pBPage              ( NULL ),
1594 
1595     bWasCursorLeftOrRight( false ),
1596     bIsInitDone          ( false )
1597 
1598 {
1599     FreeResource();
1600 
1601     sfx2::AddToTaskPaneList( this );
1602 
1603     aTabCtrl.SetActivatePageHdl( LINK( this, SfxHelpIndexWindow_Impl, ActivatePageHdl ) );
1604     aTabCtrl.Show();
1605 
1606     sal_Int32 nPageId = HELP_INDEX_PAGE_INDEX;
1607     SvtViewOptions aViewOpt( E_TABDIALOG, CONFIGNAME_INDEXWIN );
1608     if ( aViewOpt.Exists() )
1609         nPageId = aViewOpt.GetPageID();
1610     aTabCtrl.SetCurPageId( (sal_uInt16)nPageId );
1611     ActivatePageHdl( &aTabCtrl );
1612     aActiveLB.SetSelectHdl( LINK( this, SfxHelpIndexWindow_Impl, SelectHdl ) );
1613     nMinWidth = ( aActiveLB.GetSizePixel().Width() / 2 );
1614 
1615     aTimer.SetTimeoutHdl( LINK( this, SfxHelpIndexWindow_Impl, InitHdl ) );
1616     aTimer.SetTimeout( 200 );
1617     aTimer.Start();
1618 }
1619 
1620 // -----------------------------------------------------------------------
1621 
~SfxHelpIndexWindow_Impl()1622 SfxHelpIndexWindow_Impl::~SfxHelpIndexWindow_Impl()
1623 {
1624     sfx2::RemoveFromTaskPaneList( this );
1625 
1626     DELETEZ( pCPage );
1627     DELETEZ( pIPage );
1628     DELETEZ( pSPage );
1629     DELETEZ( pBPage );
1630 
1631     for ( sal_uInt16 i = 0; i < aActiveLB.GetEntryCount(); ++i )
1632         delete (String*)(sal_uIntPtr)aActiveLB.GetEntryData(i);
1633 
1634     SvtViewOptions aViewOpt( E_TABDIALOG, CONFIGNAME_INDEXWIN );
1635     aViewOpt.SetPageID( (sal_Int32)aTabCtrl.GetCurPageId() );
1636 }
1637 
1638 // -----------------------------------------------------------------------
1639 
Initialize()1640 void SfxHelpIndexWindow_Impl::Initialize()
1641 {
1642     String aHelpURL = HELP_URL;
1643     AppendConfigToken_Impl( aHelpURL, sal_True );
1644     Sequence< ::rtl::OUString > aFactories = SfxContentHelper::GetResultSet( aHelpURL );
1645     const ::rtl::OUString* pFacs  = aFactories.getConstArray();
1646     sal_uInt32 i, nCount = aFactories.getLength();
1647     for ( i = 0; i < nCount; ++i )
1648     {
1649         String aRow( pFacs[i] );
1650         String aTitle, aType, aURL;
1651         xub_StrLen nIdx = 0;
1652         aTitle = aRow.GetToken( 0, '\t', nIdx );
1653         aType = aRow.GetToken( 0, '\t', nIdx );
1654         aURL = aRow.GetToken( 0, '\t', nIdx );
1655         String* pFactory = new String( INetURLObject( aURL ).GetHost() );
1656         sal_uInt16 nPos = aActiveLB.InsertEntry( aTitle );
1657         aActiveLB.SetEntryData( nPos, (void*)(sal_uIntPtr)pFactory );
1658     }
1659 
1660     aActiveLB.SetDropDownLineCount( (sal_uInt16)nCount );
1661     if ( aActiveLB.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND )
1662         SetActiveFactory();
1663 }
1664 
1665 // -----------------------------------------------------------------------
1666 
SetActiveFactory()1667 void SfxHelpIndexWindow_Impl::SetActiveFactory()
1668 {
1669     DBG_ASSERT( pIPage, "index page not initialized" );
1670     if ( !bIsInitDone && !aActiveLB.GetEntryCount() )
1671     {
1672         aTimer.Stop();
1673         InitHdl( NULL );
1674     }
1675 
1676     for ( sal_uInt16 i = 0; i < aActiveLB.GetEntryCount(); ++i )
1677     {
1678         String* pFactory = (String*)(sal_uIntPtr)aActiveLB.GetEntryData(i);
1679         pFactory->ToLowerAscii();
1680         if ( *pFactory == pIPage->GetFactory() )
1681         {
1682             if ( aActiveLB.GetSelectEntryPos() != i )
1683             {
1684                 aActiveLB.SelectEntryPos(i);
1685                 aSelectFactoryLink.Call( NULL );
1686             }
1687             break;
1688         }
1689     }
1690 }
1691 
1692 // -----------------------------------------------------------------------
1693 
GetCurrentPage(sal_uInt16 & rCurId)1694 HelpTabPage_Impl* SfxHelpIndexWindow_Impl::GetCurrentPage( sal_uInt16& rCurId )
1695 {
1696     rCurId = aTabCtrl.GetCurPageId();
1697     HelpTabPage_Impl* pPage = NULL;
1698 
1699     switch ( rCurId )
1700     {
1701         case HELP_INDEX_PAGE_CONTENTS:
1702         {
1703             pPage = GetContentPage();
1704             break;
1705         }
1706 
1707         case HELP_INDEX_PAGE_INDEX:
1708         {
1709             pPage = GetIndexPage();
1710             break;
1711         }
1712 
1713         case HELP_INDEX_PAGE_SEARCH:
1714         {
1715             pPage = GetSearchPage();
1716             break;
1717         }
1718 
1719         case HELP_INDEX_PAGE_BOOKMARKS:
1720         {
1721             pPage = GetBookmarksPage();
1722             break;
1723         }
1724     }
1725 
1726     DBG_ASSERT( pPage, "SfxHelpIndexWindow_Impl::GetCurrentPage(): no current page" );
1727     return pPage;
1728 }
1729 
1730 // -----------------------------------------------------------------------
1731 
IMPL_LINK(SfxHelpIndexWindow_Impl,ActivatePageHdl,TabControl *,pTabCtrl)1732 IMPL_LINK( SfxHelpIndexWindow_Impl, ActivatePageHdl, TabControl *, pTabCtrl )
1733 {
1734     sal_uInt16 nId = 0;
1735     TabPage* pPage = GetCurrentPage( nId );
1736     pTabCtrl->SetTabPage( nId, pPage );
1737     return 0;
1738 }
1739 
1740 // -----------------------------------------------------------------------
1741 
IMPL_LINK(SfxHelpIndexWindow_Impl,SelectHdl,ListBox *,EMPTYARG)1742 IMPL_LINK( SfxHelpIndexWindow_Impl, SelectHdl, ListBox *, EMPTYARG )
1743 {
1744     aTimer.Start();
1745 
1746     return 0;
1747 }
1748 
1749 // -----------------------------------------------------------------------
1750 
IMPL_LINK(SfxHelpIndexWindow_Impl,InitHdl,Timer *,EMPTYARG)1751 IMPL_LINK( SfxHelpIndexWindow_Impl, InitHdl, Timer *, EMPTYARG )
1752 {
1753     bIsInitDone = true;
1754     Initialize();
1755 
1756     // now use the timer for selection
1757     aTimer.SetTimeoutHdl( LINK( this, SfxHelpIndexWindow_Impl, SelectFactoryHdl ) );
1758     aTimer.SetTimeout( 1000 );
1759 
1760     return 0;
1761 }
1762 
1763 // -----------------------------------------------------------------------
1764 
IMPL_LINK(SfxHelpIndexWindow_Impl,SelectFactoryHdl,Timer *,EMPTYARG)1765 IMPL_LINK( SfxHelpIndexWindow_Impl, SelectFactoryHdl, Timer *, EMPTYARG )
1766 {
1767     String* pFactory = (String*)(sal_uIntPtr)aActiveLB.GetEntryData( aActiveLB.GetSelectEntryPos() );
1768     if ( pFactory )
1769     {
1770         String aFactory( *pFactory );
1771         aFactory.ToLowerAscii();
1772         SetFactory( aFactory, sal_False );
1773         aSelectFactoryLink.Call( this );
1774     }
1775 
1776     return 0;
1777 }
1778 
1779 // -----------------------------------------------------------------------
1780 
IMPL_LINK(SfxHelpIndexWindow_Impl,KeywordHdl,IndexTabPage_Impl *,EMPTYARG)1781 IMPL_LINK( SfxHelpIndexWindow_Impl, KeywordHdl, IndexTabPage_Impl *, EMPTYARG )
1782 {
1783     // keyword found on index?
1784     sal_Bool bIndex = pIPage->HasKeyword();
1785     //The following two lines are added by BerryJia for fixing Bug98251, 2002-12-11
1786     if( !bIndex)
1787         bIndex = pIPage->HasKeywordIgnoreCase();
1788     // then set index or search page as current.
1789     sal_uInt16 nPageId = ( bIndex ) ? HELP_INDEX_PAGE_INDEX :  HELP_INDEX_PAGE_SEARCH;
1790     if ( nPageId != aTabCtrl.GetCurPageId() )
1791     {
1792         aTabCtrl.SetCurPageId( nPageId );
1793         ActivatePageHdl( &aTabCtrl );
1794     }
1795 
1796     // at last we open the keyword
1797     if ( bIndex )
1798         pIPage->OpenKeyword();
1799     else if ( !pSPage->OpenKeyword( sKeyword ) )
1800         pParentWin->ShowStartPage();
1801 
1802     return 0;
1803 }
1804 
1805 // -----------------------------------------------------------------------
1806 
Resize()1807 void SfxHelpIndexWindow_Impl::Resize()
1808 {
1809     Size aSize = GetOutputSizePixel();
1810     if ( aSize.Width() < nMinWidth )
1811         aSize.Width() = nMinWidth;
1812 
1813     Point aPnt = aActiveLB.GetPosPixel();
1814     Size aNewSize = aActiveLB.GetSizePixel();
1815     aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
1816     aActiveLB.SetSizePixel( aNewSize );
1817     aPnt = aActiveLine.GetPosPixel();
1818     aNewSize = aActiveLine.GetSizePixel();
1819     aNewSize.Width() = aSize.Width() - ( aPnt.X() * 2 );
1820     aActiveLine.SetSizePixel( aNewSize );
1821     aPnt = aTabCtrl.GetPosPixel();
1822     aNewSize = aSize;
1823     aSize.Width() -= aPnt.X();
1824     aSize.Height() -= aPnt.Y();
1825     aTabCtrl.SetSizePixel( aSize );
1826 }
1827 
1828 // -----------------------------------------------------------------------
1829 
PreNotify(NotifyEvent & rNEvt)1830 long SfxHelpIndexWindow_Impl::PreNotify( NotifyEvent& rNEvt )
1831 {
1832     long nDone = 0;
1833     sal_uInt16 nType = rNEvt.GetType();
1834     if ( EVENT_KEYINPUT == nType && rNEvt.GetKeyEvent() )
1835     {
1836         const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
1837         sal_uInt16 nCode = rKeyCode.GetCode();
1838 
1839         if (  KEY_TAB == nCode )
1840         {
1841             // don't exit index pane with <TAB>
1842             sal_uInt16 nPageId = 0;
1843             HelpTabPage_Impl* pCurPage = GetCurrentPage( nPageId );
1844             Control* pControl = pCurPage->GetLastFocusControl();
1845             sal_Bool bShift = rKeyCode.IsShift();
1846             sal_Bool bCtrl = rKeyCode.IsMod1();
1847             if ( !bCtrl && bShift && aActiveLB.HasChildPathFocus() )
1848             {
1849                 pControl->GrabFocus();
1850                 nDone = 1;
1851             }
1852             else if ( !bCtrl && !bShift && pControl->HasChildPathFocus() )
1853             {
1854                 aActiveLB.GrabFocus();
1855                 nDone = 1;
1856             }
1857             else if ( bCtrl )
1858             {
1859                 // <STRG><TAB> moves through the pages
1860                 if ( nPageId < HELP_INDEX_PAGE_LAST )
1861                     nPageId++;
1862                 else
1863                     nPageId = HELP_INDEX_PAGE_FIRST;
1864                 aTabCtrl.SetCurPageId( (sal_uInt16)nPageId );
1865                 ActivatePageHdl( &aTabCtrl );
1866                 nDone = 1;
1867             }
1868         }
1869         else if ( aTabCtrl.HasFocus() && ( KEY_LEFT == nCode || KEY_RIGHT == nCode ) )
1870         {
1871             bWasCursorLeftOrRight = true;
1872         }
1873     }
1874 
1875     return nDone ? nDone : Window::PreNotify( rNEvt );
1876 }
1877 
1878 // -----------------------------------------------------------------------
1879 
DataChanged(const DataChangedEvent & rDCEvt)1880 void SfxHelpIndexWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
1881 {
1882     Window::DataChanged( rDCEvt );
1883 
1884     if ( ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
1885            ( rDCEvt.GetType() == DATACHANGED_DISPLAY ) ) &&
1886          ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
1887     {
1888         SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFaceColor() ) );
1889     }
1890 }
1891 
1892 // -----------------------------------------------------------------------
1893 
SetDoubleClickHdl(const Link & rLink)1894 void SfxHelpIndexWindow_Impl::SetDoubleClickHdl( const Link& rLink )
1895 {
1896     aPageDoubleClickLink = rLink;
1897     if ( pCPage )
1898         pCPage->SetOpenHdl( aPageDoubleClickLink );
1899     if ( pIPage )
1900         pIPage->SetDoubleClickHdl( aPageDoubleClickLink );
1901     if ( pSPage )
1902         pSPage->SetDoubleClickHdl( aPageDoubleClickLink );
1903     if ( pBPage )
1904         pBPage->SetDoubleClickHdl( aPageDoubleClickLink );
1905 }
1906 
1907 // -----------------------------------------------------------------------
1908 
SetFactory(const String & rFactory,sal_Bool bActive)1909 void SfxHelpIndexWindow_Impl::SetFactory( const String& rFactory, sal_Bool bActive )
1910 {
1911     if ( rFactory.Len() > 0 )
1912     {
1913         GetIndexPage()->SetFactory( rFactory );
1914         // the index page did a check if rFactory is valid,
1915         // so the index page always returns a valid factory
1916         GetSearchPage()->SetFactory( GetIndexPage()->GetFactory() );
1917         if ( bActive )
1918             SetActiveFactory();
1919     }
1920 }
1921 
1922 // -----------------------------------------------------------------------
1923 
GetSelectEntry() const1924 String SfxHelpIndexWindow_Impl::GetSelectEntry() const
1925 {
1926     String sRet;
1927 
1928     switch ( aTabCtrl.GetCurPageId() )
1929     {
1930         case HELP_INDEX_PAGE_CONTENTS:
1931             sRet = pCPage->GetSelectEntry();
1932             break;
1933 
1934         case HELP_INDEX_PAGE_INDEX:
1935             sRet = pIPage->GetSelectEntry();
1936             break;
1937 
1938         case HELP_INDEX_PAGE_SEARCH:
1939             sRet = pSPage->GetSelectEntry();
1940             break;
1941 
1942         case HELP_INDEX_PAGE_BOOKMARKS:
1943             sRet = pBPage->GetSelectEntry();
1944             break;
1945     }
1946 
1947     return sRet;
1948 }
1949 
1950 // -----------------------------------------------------------------------
1951 
AddBookmarks(const String & rTitle,const String & rURL)1952 void SfxHelpIndexWindow_Impl::AddBookmarks( const String& rTitle, const String& rURL )
1953 {
1954     GetBookmarksPage()->AddBookmarks( rTitle, rURL );
1955 }
1956 
1957 // -----------------------------------------------------------------------
1958 
IsValidFactory(const String & _rFactory)1959 bool SfxHelpIndexWindow_Impl::IsValidFactory( const String& _rFactory )
1960 {
1961     bool bValid = false;
1962     for ( sal_uInt16 i = 0; i < aActiveLB.GetEntryCount(); ++i )
1963     {
1964         String* pFactory = (String*)(sal_uIntPtr)aActiveLB.GetEntryData(i);
1965         if ( *pFactory == _rFactory )
1966         {
1967             bValid = true;
1968             break;
1969         }
1970     }
1971     return bValid;
1972 }
1973 
1974 // -----------------------------------------------------------------------
1975 
ClearSearchPage()1976 void SfxHelpIndexWindow_Impl::ClearSearchPage()
1977 {
1978     if ( pSPage )
1979         pSPage->ClearPage();
1980 }
1981 
1982 // -----------------------------------------------------------------------
1983 
GrabFocusBack()1984 void SfxHelpIndexWindow_Impl::GrabFocusBack()
1985 {
1986     if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_CONTENTS && pCPage )
1987         pCPage->SetFocusOnBox();
1988     else if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_INDEX && pIPage )
1989         pIPage->SetFocusOnBox();
1990     else if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_SEARCH && pSPage )
1991         pSPage->SetFocusOnBox();
1992     else if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_BOOKMARKS && pBPage )
1993         pBPage->SetFocusOnBox();
1994 }
1995 
1996 // -----------------------------------------------------------------------
1997 
HasFocusOnEdit() const1998 sal_Bool SfxHelpIndexWindow_Impl::HasFocusOnEdit() const
1999 {
2000     sal_Bool bRet = sal_False;
2001     if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_INDEX && pIPage )
2002         bRet = pIPage->HasFocusOnEdit();
2003     else if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_SEARCH && pSPage )
2004         bRet = pSPage->HasFocusOnEdit();
2005     return bRet;
2006 }
2007 
2008 // -----------------------------------------------------------------------
2009 
GetSearchText() const2010 String SfxHelpIndexWindow_Impl::GetSearchText() const
2011 {
2012     String sRet;
2013     if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_SEARCH && pSPage )
2014         sRet = pSPage->GetSearchText();
2015     return sRet;
2016 }
2017 
2018 // -----------------------------------------------------------------------
2019 
IsFullWordSearch() const2020 sal_Bool SfxHelpIndexWindow_Impl::IsFullWordSearch() const
2021 {
2022     sal_Bool bRet = sal_False;
2023     if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_SEARCH && pSPage )
2024         bRet = pSPage->IsFullWordSearch();
2025     return bRet;
2026 }
2027 
2028 // -----------------------------------------------------------------------
2029 
OpenKeyword(const String & rKeyword)2030 void SfxHelpIndexWindow_Impl::OpenKeyword( const String& rKeyword )
2031 {
2032     sKeyword = rKeyword;
2033     DBG_ASSERT( pIPage, "invalid index page" );
2034     pIPage->SetKeyword( sKeyword );
2035 }
2036 
2037 // -----------------------------------------------------------------------
2038 
SelectExecutableEntry()2039 void SfxHelpIndexWindow_Impl::SelectExecutableEntry()
2040 {
2041     if ( aTabCtrl.GetCurPageId() == HELP_INDEX_PAGE_INDEX && pIPage )
2042         pIPage->SelectExecutableEntry();
2043 }
2044 
2045 // class TextWin_Impl ----------------------------------------------------
2046 
TextWin_Impl(Window * p)2047 TextWin_Impl::TextWin_Impl( Window* p ) : DockingWindow( p, 0 )
2048 {
2049 }
2050 
~TextWin_Impl()2051 TextWin_Impl::~TextWin_Impl()
2052 {
2053 }
2054 
Notify(NotifyEvent & rNEvt)2055 long TextWin_Impl::Notify( NotifyEvent& rNEvt )
2056 {
2057     if( ( rNEvt.GetType() == EVENT_KEYINPUT ) && rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_TAB )
2058         return GetParent()->Notify( rNEvt );
2059     else
2060         return DockingWindow::Notify( rNEvt );
2061 }
2062 
2063 // -----------------------------------------------------------------------
2064 // remove docking area acceptor from layoutmanager, so it will not layout anything further .-)
lcl_disableLayoutOfFrame(const Reference<XFrame> & xFrame)2065 void lcl_disableLayoutOfFrame(const Reference< XFrame >& xFrame)
2066 {
2067     static const ::rtl::OUString PROP_LAYOUT_MANAGER(DEFINE_CONST_UNICODE("LayoutManager"));
2068 
2069     Reference< XPropertySet > xPropSet(xFrame, UNO_QUERY_THROW);
2070     xPropSet->setPropertyValue(PROP_LAYOUT_MANAGER, makeAny(Reference< XLayoutManager >()));
2071 }
2072 
2073 // class SfxHelpTextWindow_Impl ------------------------------------------
2074 
SfxHelpTextWindow_Impl(SfxHelpWindow_Impl * pParent)2075 SfxHelpTextWindow_Impl::SfxHelpTextWindow_Impl( SfxHelpWindow_Impl* pParent ) :
2076 
2077     Window( pParent, WB_CLIPCHILDREN | WB_TABSTOP | WB_DIALOGCONTROL ),
2078 
2079     aToolBox            ( this, 0 ),
2080     aOnStartupCB        ( this, SfxResId( RID_HELP_ONSTARTUP_BOX ) ),
2081     aIndexOnImage       ( SfxResId( IMG_HELP_TOOLBOX_INDEX_ON ) ),
2082     aIndexOffImage      ( SfxResId( IMG_HELP_TOOLBOX_INDEX_OFF ) ),
2083     aIndexOnText        ( SfxResId( STR_HELP_BUTTON_INDEX_ON ) ),
2084     aIndexOffText       ( SfxResId( STR_HELP_BUTTON_INDEX_OFF ) ),
2085     aOnStartupText      ( SfxResId( RID_HELP_ONSTARTUP_TEXT ) ),
2086     pHelpWin            ( pParent ),
2087     pTextWin            ( new TextWin_Impl( this ) ),
2088     pSrchDlg            ( NULL ),
2089     nMinPos             ( 0 ),
2090     bIsDebug            ( sal_False ),
2091     bIsIndexOn          ( sal_False ),
2092     bIsInClose          ( sal_False ),
2093     bIsFullWordSearch   ( sal_False )
2094 
2095 {
2096     sfx2::AddToTaskPaneList( &aToolBox );
2097 
2098     xFrame = Reference < XFrame > ( ::comphelper::getProcessServiceFactory()->createInstance(
2099         DEFINE_CONST_UNICODE("com.sun.star.frame.Frame") ), UNO_QUERY );
2100     xFrame->initialize( VCLUnoHelper::GetInterface ( pTextWin ) );
2101     xFrame->setName( DEFINE_CONST_UNICODE("OFFICE_HELP") );
2102     lcl_disableLayoutOfFrame(xFrame);
2103 
2104     aToolBox.SetHelpId( HID_HELP_TOOLBOX );
2105 
2106     aToolBox.InsertItem( TBI_INDEX, aIndexOffText );
2107     aToolBox.SetHelpId( TBI_INDEX, HID_HELP_TOOLBOXITEM_INDEX );
2108     aToolBox.InsertSeparator();
2109     aToolBox.InsertItem( TBI_BACKWARD, String( SfxResId( STR_HELP_BUTTON_PREV ) ) );
2110     aToolBox.SetHelpId( TBI_BACKWARD, HID_HELP_TOOLBOXITEM_BACKWARD );
2111     aToolBox.InsertItem( TBI_FORWARD, String( SfxResId( STR_HELP_BUTTON_NEXT ) ) );
2112     aToolBox.SetHelpId( TBI_FORWARD, HID_HELP_TOOLBOXITEM_FORWARD );
2113     aToolBox.InsertItem( TBI_START, String( SfxResId( STR_HELP_BUTTON_START ) ) );
2114     aToolBox.SetHelpId( TBI_START, HID_HELP_TOOLBOXITEM_START );
2115     aToolBox.InsertSeparator();
2116     aToolBox.InsertItem( TBI_PRINT, String( SfxResId( STR_HELP_BUTTON_PRINT ) ) );
2117     aToolBox.SetHelpId( TBI_PRINT, HID_HELP_TOOLBOXITEM_PRINT );
2118     aToolBox.InsertItem( TBI_BOOKMARKS, String( SfxResId( STR_HELP_BUTTON_ADDBOOKMARK ) ) );
2119     aToolBox.SetHelpId( TBI_BOOKMARKS, HID_HELP_TOOLBOXITEM_BOOKMARKS );
2120     aToolBox.InsertItem( TBI_SEARCHDIALOG, String( SfxResId( STR_HELP_BUTTON_SEARCHDIALOG ) ) );
2121     aToolBox.SetHelpId( TBI_SEARCHDIALOG, HID_HELP_TOOLBOXITEM_SEARCHDIALOG );
2122 
2123     InitToolBoxImages();
2124     aToolBox.Show();
2125     InitOnStartupBox( false );
2126     aOnStartupCB.SetClickHdl( LINK( this, SfxHelpTextWindow_Impl, CheckHdl ) );
2127 
2128     aSelectTimer.SetTimeoutHdl( LINK( this, SfxHelpTextWindow_Impl, SelectHdl ) );
2129     aSelectTimer.SetTimeout( 1000 );
2130 
2131     char* pEnv = getenv( "help_debug" );
2132     if ( pEnv )
2133         bIsDebug = sal_True;
2134 
2135     SvtMiscOptions().AddListenerLink( LINK( this, SfxHelpTextWindow_Impl, NotifyHdl ) );
2136 
2137     if ( !aOnStartupCB.GetHelpId().getLength() )
2138         aOnStartupCB.SetHelpId( HID_HELP_ONSTARTUP_BOX );
2139 }
2140 
2141 // -----------------------------------------------------------------------
2142 
~SfxHelpTextWindow_Impl()2143 SfxHelpTextWindow_Impl::~SfxHelpTextWindow_Impl()
2144 {
2145     sfx2::RemoveFromTaskPaneList( &aToolBox );
2146 
2147     bIsInClose = sal_True;
2148     SvtMiscOptions().RemoveListenerLink( LINK( this, SfxHelpTextWindow_Impl, NotifyHdl ) );
2149     delete pSrchDlg;
2150 }
2151 
2152 // -----------------------------------------------------------------------
2153 
HasSelection() const2154 sal_Bool SfxHelpTextWindow_Impl::HasSelection() const
2155 {
2156     // is there any selection in the text and not only a cursor?
2157     sal_Bool bRet = sal_False;
2158     Reference < XTextRange > xRange = getCursor();
2159     if ( xRange.is() )
2160     {
2161         Reference < XText > xText = xRange->getText();
2162         Reference < XTextCursor > xCursor = xText->createTextCursorByRange( xRange );
2163         bRet = !xCursor->isCollapsed();
2164     }
2165 
2166     return bRet;
2167 }
2168 
2169 // -----------------------------------------------------------------------
2170 
InitToolBoxImages()2171 void SfxHelpTextWindow_Impl::InitToolBoxImages()
2172 {
2173     sal_Bool bLarge = SvtMiscOptions().AreCurrentSymbolsLarge();
2174     sal_Bool bHiContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
2175 
2176     aIndexOnImage = Image( SfxResId(
2177         bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_INDEX_ON : IMG_HELP_TOOLBOX_L_INDEX_ON
2178                : bHiContrast ? IMG_HELP_TOOLBOX_HC_INDEX_ON : IMG_HELP_TOOLBOX_INDEX_ON ) );
2179     aIndexOffImage = Image( SfxResId(
2180         bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_INDEX_OFF : IMG_HELP_TOOLBOX_L_INDEX_OFF
2181                : bHiContrast ? IMG_HELP_TOOLBOX_HC_INDEX_OFF : IMG_HELP_TOOLBOX_INDEX_OFF ) );
2182     aToolBox.SetItemImage( TBI_INDEX, bIsIndexOn ? aIndexOffImage : aIndexOnImage );
2183 
2184     aToolBox.SetItemImage( TBI_BACKWARD, Image( SfxResId(
2185         bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_PREV : IMG_HELP_TOOLBOX_L_PREV
2186                : bHiContrast ? IMG_HELP_TOOLBOX_HC_PREV : IMG_HELP_TOOLBOX_PREV ) ) );
2187     aToolBox.SetItemImage( TBI_FORWARD, Image( SfxResId(
2188         bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_NEXT : IMG_HELP_TOOLBOX_L_NEXT
2189                : bHiContrast ? IMG_HELP_TOOLBOX_HC_NEXT : IMG_HELP_TOOLBOX_NEXT ) ) );
2190     aToolBox.SetItemImage( TBI_START, Image( SfxResId(
2191         bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_START : IMG_HELP_TOOLBOX_L_START
2192                : bHiContrast ? IMG_HELP_TOOLBOX_HC_START : IMG_HELP_TOOLBOX_START ) ) );
2193     aToolBox.SetItemImage( TBI_PRINT, Image( SfxResId(
2194         bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_PRINT : IMG_HELP_TOOLBOX_L_PRINT
2195                : bHiContrast ? IMG_HELP_TOOLBOX_HC_PRINT : IMG_HELP_TOOLBOX_PRINT ) ) );
2196     aToolBox.SetItemImage( TBI_BOOKMARKS, Image( SfxResId(
2197         bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_BOOKMARKS : IMG_HELP_TOOLBOX_L_BOOKMARKS
2198                : bHiContrast ? IMG_HELP_TOOLBOX_HC_BOOKMARKS : IMG_HELP_TOOLBOX_BOOKMARKS ) ) );
2199     aToolBox.SetItemImage( TBI_SEARCHDIALOG, Image( SfxResId(
2200         bLarge ? bHiContrast ? IMG_HELP_TOOLBOX_HCL_SEARCHDIALOG : IMG_HELP_TOOLBOX_L_SEARCHDIALOG
2201                : bHiContrast ? IMG_HELP_TOOLBOX_HC_SEARCHDIALOG : IMG_HELP_TOOLBOX_SEARCHDIALOG ) ) );
2202 
2203     Size aSize = aToolBox.CalcWindowSizePixel();
2204     aSize.Height() += TOOLBOX_OFFSET;
2205     aToolBox.SetPosSizePixel( Point( 0, TOOLBOX_OFFSET ), aSize );
2206 
2207     SvtMiscOptions aMiscOptions;
2208     if ( aMiscOptions.GetToolboxStyle() != aToolBox.GetOutStyle() )
2209         aToolBox.SetOutStyle( aMiscOptions.GetToolboxStyle() );
2210 }
2211 
2212 // -----------------------------------------------------------------------
2213 
InitOnStartupBox(bool bOnlyText)2214 void SfxHelpTextWindow_Impl::InitOnStartupBox( bool bOnlyText )
2215 {
2216     sCurrentFactory = SfxHelp::GetCurrentModuleIdentifier();
2217 
2218     Reference< XMultiServiceFactory > xMultiServiceFac = ::comphelper::getProcessServiceFactory();
2219     Reference< XInterface > xConfig;
2220     ::rtl::OUString sPath( PATH_OFFICE_FACTORIES );
2221     sPath += sCurrentFactory;
2222     ::rtl::OUString sKey( KEY_HELP_ON_OPEN );
2223 
2224     // Attention: This check boy knows two states:
2225     // 1) Reading of the config key fails with an exception or by getting an empty Any (!) => check box must be hidden
2226     // 2) We read sal_True/sal_False => check box must be shown and enabled/disabled
2227 
2228     bool bHideBox = true;
2229     sal_Bool bHelpAtStartup = sal_False;
2230     try
2231     {
2232         xConfiguration = ConfigurationHelper::openConfig(
2233             xMultiServiceFac, PACKAGE_SETUP, ConfigurationHelper::E_STANDARD );
2234         if ( xConfiguration.is() )
2235         {
2236             Any aAny = ConfigurationHelper::readRelativeKey( xConfiguration, sPath, sKey );
2237             if (aAny >>= bHelpAtStartup)
2238                 bHideBox = false;
2239         }
2240     }
2241     catch( Exception& )
2242     {
2243         bHideBox = true;
2244     }
2245 
2246     if ( bHideBox )
2247         aOnStartupCB.Hide();
2248     else
2249     {
2250         // detect module name
2251         String sModuleName;
2252 
2253         if ( xConfiguration.is() )
2254         {
2255             ::rtl::OUString sTemp;
2256             sKey = KEY_UI_NAME;
2257             try
2258             {
2259                 Any aAny = ConfigurationHelper::readRelativeKey( xConfiguration, sPath, sKey );
2260                 aAny >>= sTemp;
2261             }
2262             catch( Exception& )
2263             {
2264                 DBG_ERRORFILE( "SfxHelpTextWindow_Impl::InitOnStartupBox(): unexpected exception" );
2265             }
2266             sModuleName = String( sTemp );
2267         }
2268 
2269         if ( sModuleName.Len() > 0 )
2270         {
2271             // set module name in checkbox text
2272             String sText( aOnStartupText );
2273             sText.SearchAndReplace( String::CreateFromAscii( "%MODULENAME" ), sModuleName );
2274             aOnStartupCB.SetText( sText );
2275             // and show it
2276             aOnStartupCB.Show();
2277             // set check state
2278             aOnStartupCB.Check( bHelpAtStartup );
2279             aOnStartupCB.SaveValue();
2280 
2281             // calculate and set optimal width of the onstartup checkbox
2282             String sCBText( DEFINE_CONST_UNICODE( "XXX" ) );
2283             sCBText += aOnStartupCB.GetText();
2284             long nTextWidth = aOnStartupCB.GetTextWidth( sCBText );
2285             Size aSize = aOnStartupCB.GetSizePixel();
2286             aSize.Width() = nTextWidth;
2287             aOnStartupCB.SetSizePixel( aSize );
2288             SetOnStartupBoxPosition();
2289         }
2290 
2291         if ( !bOnlyText )
2292         {
2293             // set position of the checkbox
2294             Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
2295             Size aTBSize = aToolBox.GetSizePixel();
2296             Size aCBSize = aOnStartupCB.GetSizePixel();
2297             Point aPnt = aToolBox.GetPosPixel();
2298             aPnt.X() += aTBSize.Width() + a3Size.Width();
2299             aPnt.Y() += ( ( aTBSize.Height() - aCBSize.Height() ) / 2 );
2300             aOnStartupCB.SetPosPixel( aPnt );
2301             nMinPos = aPnt.X();
2302         }
2303     }
2304 }
2305 
2306 // -----------------------------------------------------------------------
2307 
SetOnStartupBoxPosition()2308 void SfxHelpTextWindow_Impl::SetOnStartupBoxPosition()
2309 {
2310     long nX = Max( GetOutputSizePixel().Width() - aOnStartupCB.GetSizePixel().Width(), nMinPos );
2311     Point aPos = aOnStartupCB.GetPosPixel();
2312     aPos.X() = nX;
2313     aOnStartupCB.SetPosPixel( aPos );
2314 }
2315 
2316 // -----------------------------------------------------------------------
2317 
GetBreakIterator()2318 Reference< XBreakIterator > SfxHelpTextWindow_Impl::GetBreakIterator()
2319 {
2320     if ( !xBreakIterator.is() )
2321         xBreakIterator = vcl::unohelper::CreateBreakIterator();
2322     DBG_ASSERT( xBreakIterator.is(), "Could not create BreakIterator" );
2323     return xBreakIterator;
2324 }
2325 
2326 // -----------------------------------------------------------------------
2327 
getCursor() const2328 Reference< XTextRange > SfxHelpTextWindow_Impl::getCursor() const
2329 {
2330     // return the current cursor
2331     Reference< XTextRange > xCursor;
2332 
2333     try
2334     {
2335         Reference < XSelectionSupplier > xSelSup( xFrame->getController(), UNO_QUERY );
2336         if ( xSelSup.is() )
2337         {
2338             Any aAny = xSelSup->getSelection();
2339             Reference < XIndexAccess > xSelection;
2340             if ( aAny >>= xSelection )
2341             {
2342                 if ( xSelection->getCount() == 1 )
2343                 {
2344                     aAny = xSelection->getByIndex(0);
2345                     aAny >>= xCursor;
2346                 }
2347             }
2348         }
2349     }
2350     catch( Exception& )
2351     {
2352         DBG_ERROR( "SfxHelpTextWindow_Impl::getCursor(): unexpected exception" );
2353     }
2354 
2355     return xCursor;
2356 }
2357 
2358 // -----------------------------------------------------------------------
2359 
isHandledKey(const KeyCode & _rKeyCode)2360 bool SfxHelpTextWindow_Impl::isHandledKey( const KeyCode& _rKeyCode )
2361 {
2362     bool bRet = false;
2363     sal_uInt16 nCode = _rKeyCode.GetCode();
2364 
2365     // the keys <STRG><A> (select all), <STRG><C> (copy),
2366     //          <STRG><F> (find), <STRG><P> (print) and <STRG><W> (close window)
2367     // were handled in help
2368     if ( _rKeyCode.IsMod1() &&
2369          ( KEY_A == nCode || KEY_C == nCode || KEY_F == nCode || KEY_P == nCode || KEY_W == nCode ) )
2370     {
2371         if ( KEY_F == nCode )
2372             DoSearch();
2373         else
2374             bRet = true;
2375     }
2376 
2377     return bRet;
2378 }
2379 
2380 // -----------------------------------------------------------------------
2381 
IMPL_LINK(SfxHelpTextWindow_Impl,SelectHdl,Timer *,EMPTYARG)2382 IMPL_LINK( SfxHelpTextWindow_Impl, SelectHdl, Timer*, EMPTYARG )
2383 {
2384     try
2385     {
2386         // select the words, which are equal to the search text of the search page
2387         Reference < XController > xController = xFrame->getController();
2388         if ( xController.is() )
2389         {
2390             // get document
2391             Reference < XSearchable > xSearchable( xController->getModel(), UNO_QUERY );
2392             if ( xSearchable.is() )
2393             {
2394                 // create descriptor, set string and find all words
2395                 Reference < XSearchDescriptor > xSrchDesc = xSearchable->createSearchDescriptor();
2396                 Reference < XPropertySet > xPropSet( xSrchDesc, UNO_QUERY );
2397                 xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchRegularExpression"),
2398                                             makeAny( sal_Bool( sal_True ) ) );
2399                 if ( bIsFullWordSearch )
2400                     xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchWords"),
2401                                                 makeAny( sal_Bool( sal_True ) ) );
2402 
2403                 String sSearchString = sfx2::PrepareSearchString( aSearchText, GetBreakIterator(), false );
2404                 xSrchDesc->setSearchString( sSearchString );
2405                 Reference< XIndexAccess > xSelection = xSearchable->findAll( xSrchDesc );
2406 
2407                 // then select all found words
2408                 Reference < XSelectionSupplier > xSelectionSup( xController, UNO_QUERY );
2409                 if ( xSelectionSup.is() )
2410                 {
2411                     Any aAny;
2412                     aAny <<= xSelection;
2413                     xSelectionSup->select( aAny );
2414                 }
2415             }
2416         }
2417     }
2418     catch( Exception& )
2419     {
2420         DBG_ERROR( "SfxHelpTextWindow_Impl::SelectHdl(): unexpected exception" );
2421     }
2422 
2423     return 1;
2424 }
2425 
2426 // -----------------------------------------------------------------------
2427 
IMPL_LINK(SfxHelpTextWindow_Impl,NotifyHdl,SvtMiscOptions *,pOptions)2428 IMPL_LINK( SfxHelpTextWindow_Impl, NotifyHdl, SvtMiscOptions*, pOptions )
2429 {
2430     (void)pOptions; // unused variable
2431     InitToolBoxImages();
2432     Resize();
2433     aToolBox.Invalidate();
2434     return 0;
2435 }
2436 
2437 // -----------------------------------------------------------------------
2438 
IMPL_LINK(SfxHelpTextWindow_Impl,FindHdl,sfx2::SearchDialog *,pDlg)2439 IMPL_LINK( SfxHelpTextWindow_Impl, FindHdl, sfx2::SearchDialog*, pDlg )
2440 {
2441     bool bWrapAround = ( NULL == pDlg );
2442     if ( bWrapAround )
2443         pDlg = pSrchDlg;
2444     DBG_ASSERT( pDlg, "invalid search dialog" );
2445     String sSearchText = pDlg->GetSearchText();
2446     try
2447     {
2448         // select the words, which are equal to the search text of the search page
2449         Reference < XController > xController = xFrame->getController();
2450         if ( xController.is() )
2451         {
2452             // get document
2453             Reference < XSearchable > xSearchable( xController->getModel(), UNO_QUERY );
2454             if ( xSearchable.is() )
2455             {
2456                 // create descriptor, set string and find all words
2457                 Reference < XSearchDescriptor > xSrchDesc = xSearchable->createSearchDescriptor();
2458                 Reference < XPropertySet > xPropSet( xSrchDesc, UNO_QUERY );
2459                 xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchWords"), makeAny( sal_Bool( pDlg->IsOnlyWholeWords() != false ) ) );
2460                 xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchCaseSensitive"), makeAny( sal_Bool( pDlg->IsMarchCase() != false ) ) );
2461                 xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("SearchBackwards"), makeAny( sal_Bool( pDlg->IsSearchBackwards() != false ) ) );
2462                 xSrchDesc->setSearchString( sSearchText );
2463                 Reference< XInterface > xSelection;
2464                 Reference< XTextRange > xCursor = getCursor();
2465 
2466                 if ( xCursor.is() )
2467                 {
2468                     if ( pDlg->IsSearchBackwards() )
2469                         xCursor = xCursor->getStart();
2470                     xSelection = xSearchable->findNext( xCursor, xSrchDesc );
2471                 }
2472                 else
2473                     xSelection = xSearchable->findFirst( xSrchDesc );
2474 
2475                 // then select the found word
2476                 if ( xSelection.is() )
2477                 {
2478                     Reference < XSelectionSupplier > xSelectionSup( xController, UNO_QUERY );
2479                     if ( xSelectionSup.is() )
2480                     {
2481                         Any aAny;
2482                         aAny <<= xSelection;
2483                         xSelectionSup->select( aAny );
2484                     }
2485                 }
2486                 else if ( pDlg->IsWrapAround() && !bWrapAround )
2487                 {
2488                     Reference < text::XTextViewCursorSupplier > xCrsrSupp( xController, uno::UNO_QUERY );
2489                     Reference < text::XTextViewCursor > xTVCrsr( xCrsrSupp->getViewCursor(), uno::UNO_QUERY );
2490                     if ( xTVCrsr.is() )
2491                     {
2492                         Reference < text::XTextDocument > xDoc( xController->getModel(), uno::UNO_QUERY );
2493                         Reference < text::XText > xText = xDoc->getText();
2494                         if ( xText.is() )
2495                         {
2496                             if ( pDlg->IsSearchBackwards() )
2497                                 xTVCrsr->gotoRange( xText->getEnd(), sal_False );
2498                             else
2499                                 xTVCrsr->gotoRange( xText->getStart(), sal_False );
2500                             FindHdl( NULL );
2501                         }
2502                     }
2503                 }
2504                 else
2505                 {
2506                     DBG_ASSERT( pSrchDlg, "no search dialog" );
2507                     InfoBox aBox( pSrchDlg, SfxResId( RID_INFO_NOSEARCHTEXTFOUND ) );
2508                     aBox.Execute();
2509                     pSrchDlg->SetFocusOnEdit();
2510                 }
2511             }
2512         }
2513     }
2514     catch( Exception& )
2515     {
2516         DBG_ERROR( "SfxHelpTextWindow_Impl::SelectHdl(): unexpected exception" );
2517     }
2518 
2519     return 0;
2520 }
2521 
2522 // -----------------------------------------------------------------------
2523 
IMPL_LINK(SfxHelpTextWindow_Impl,CloseHdl,sfx2::SearchDialog *,pDlg)2524 IMPL_LINK( SfxHelpTextWindow_Impl, CloseHdl, sfx2::SearchDialog*, pDlg )
2525 {
2526     if ( pDlg )
2527         delete pSrchDlg;
2528     pSrchDlg = NULL;
2529     return 0;
2530 }
2531 
2532 // -----------------------------------------------------------------------
2533 
IMPL_LINK(SfxHelpTextWindow_Impl,CheckHdl,CheckBox *,pBox)2534 IMPL_LINK( SfxHelpTextWindow_Impl, CheckHdl, CheckBox*, pBox )
2535 {
2536     if ( xConfiguration.is() )
2537     {
2538         sal_Bool bChecked = pBox->IsChecked();
2539         ::rtl::OUString sPath( PATH_OFFICE_FACTORIES );
2540         sPath += sCurrentFactory;
2541         try
2542         {
2543             ConfigurationHelper::writeRelativeKey(
2544                 xConfiguration, sPath, KEY_HELP_ON_OPEN, makeAny( bChecked ) );
2545             ConfigurationHelper::flush( xConfiguration );
2546         }
2547         catch( Exception& )
2548         {
2549             DBG_ERRORFILE( "SfxHelpTextWindow_Impl::CheckHdl(): unexpected exception" );
2550         }
2551     }
2552 
2553     return 0;
2554 }
2555 
2556 // -----------------------------------------------------------------------
2557 
Resize()2558 void SfxHelpTextWindow_Impl::Resize()
2559 {
2560     Size aSize = GetOutputSizePixel();
2561     long nToolBoxHeight = aToolBox.GetSizePixel().Height() + TOOLBOX_OFFSET;
2562     aSize.Height() -= nToolBoxHeight;
2563     pTextWin->SetPosSizePixel( Point( 0, nToolBoxHeight  ), aSize );
2564     SetOnStartupBoxPosition();
2565 }
2566 
2567 // -----------------------------------------------------------------------
2568 
PreNotify(NotifyEvent & rNEvt)2569 long SfxHelpTextWindow_Impl::PreNotify( NotifyEvent& rNEvt )
2570 {
2571     long nDone = 0;
2572     sal_uInt16 nType = rNEvt.GetType();
2573     if ( EVENT_COMMAND == nType && rNEvt.GetCommandEvent() )
2574     {
2575         const CommandEvent* pCmdEvt = rNEvt.GetCommandEvent();
2576         Window* pCmdWin = rNEvt.GetWindow();
2577 
2578         if ( pCmdEvt->GetCommand() == COMMAND_CONTEXTMENU && pCmdWin != this && pCmdWin != &aToolBox )
2579         {
2580             sal_Bool bHiContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
2581             Point aPos;
2582             if ( pCmdEvt->IsMouseEvent() )
2583                 aPos = pCmdEvt->GetMousePosPixel();
2584             else
2585                 aPos = Point( pTextWin->GetPosPixel().X() + 20, 20 );
2586             aPos.Y() += pTextWin->GetPosPixel().Y();
2587             PopupMenu aMenu;
2588             if ( bIsIndexOn )
2589                 aMenu.InsertItem( TBI_INDEX, aIndexOffText, Image( SfxResId(
2590                     bHiContrast ? IMG_HELP_TOOLBOX_HC_INDEX_OFF : IMG_HELP_TOOLBOX_INDEX_OFF ) ) );
2591             else
2592                 aMenu.InsertItem( TBI_INDEX, aIndexOnText, Image( SfxResId(
2593                     bHiContrast ? IMG_HELP_TOOLBOX_HC_INDEX_ON : IMG_HELP_TOOLBOX_INDEX_ON ) ) );
2594             aMenu.SetHelpId( TBI_INDEX, HID_HELP_TOOLBOXITEM_INDEX );
2595             aMenu.InsertSeparator();
2596             aMenu.InsertItem( TBI_BACKWARD, String( SfxResId( STR_HELP_BUTTON_PREV ) ),
2597                 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_PREV : IMG_HELP_TOOLBOX_PREV ) ) );
2598             aMenu.SetHelpId( TBI_BACKWARD, HID_HELP_TOOLBOXITEM_BACKWARD );
2599             aMenu.EnableItem( TBI_BACKWARD, pHelpWin->HasHistoryPredecessor() );
2600             aMenu.InsertItem( TBI_FORWARD, String( SfxResId( STR_HELP_BUTTON_NEXT ) ),
2601                 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_NEXT : IMG_HELP_TOOLBOX_NEXT ) ) );
2602             aMenu.SetHelpId( TBI_FORWARD, HID_HELP_TOOLBOXITEM_FORWARD );
2603             aMenu.EnableItem( TBI_FORWARD, pHelpWin->HasHistorySuccessor() );
2604             aMenu.InsertItem( TBI_START, String( SfxResId( STR_HELP_BUTTON_START ) ),
2605                 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_START : IMG_HELP_TOOLBOX_START ) ) );
2606             aMenu.SetHelpId( TBI_START, HID_HELP_TOOLBOXITEM_START );
2607             aMenu.InsertSeparator();
2608             aMenu.InsertItem( TBI_PRINT, String( SfxResId( STR_HELP_BUTTON_PRINT ) ),
2609                 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_PRINT : IMG_HELP_TOOLBOX_PRINT ) ) );
2610             aMenu.SetHelpId( TBI_PRINT, HID_HELP_TOOLBOXITEM_PRINT );
2611             aMenu.InsertItem( TBI_BOOKMARKS, String( SfxResId( STR_HELP_BUTTON_ADDBOOKMARK ) ),
2612                 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_BOOKMARKS : IMG_HELP_TOOLBOX_BOOKMARKS ) ) );
2613             aMenu.SetHelpId( TBI_BOOKMARKS, HID_HELP_TOOLBOXITEM_BOOKMARKS );
2614             aMenu.InsertItem( TBI_SEARCHDIALOG, String( SfxResId( STR_HELP_BUTTON_SEARCHDIALOG ) ),
2615                 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_SEARCHDIALOG : IMG_HELP_TOOLBOX_SEARCHDIALOG ) ) );
2616             aMenu.SetHelpId( TBI_SEARCHDIALOG, HID_HELP_TOOLBOXITEM_SEARCHDIALOG );
2617             aMenu.InsertSeparator();
2618             aMenu.InsertItem( TBI_SELECTIONMODE, String( SfxResId( STR_HELP_MENU_TEXT_SELECTION_MODE ) ) );
2619             aMenu.SetHelpId( TBI_SELECTIONMODE, HID_HELP_TEXT_SELECTION_MODE );
2620             Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
2621             URL aURL;
2622             aURL.Complete = DEFINE_CONST_UNICODE(".uno:SelectTextMode");
2623             PARSE_URL( aURL );
2624             Reference < XDispatch > xDisp = xProv.is() ?
2625                     xProv->queryDispatch( aURL, rtl::OUString(), 0 ) : Reference < XDispatch >();
2626             if(xDisp.is())
2627             {
2628                 HelpStatusListener_Impl* pStateListener;
2629                 Reference<XStatusListener>xStateListener = pStateListener =
2630                                         new HelpStatusListener_Impl(xDisp, aURL );
2631                 FeatureStateEvent rEvent = pStateListener->GetStateEvent();
2632                 sal_Bool bCheck = sal_False;
2633                 rEvent.State >>= bCheck;
2634                 aMenu.CheckItem(TBI_SELECTIONMODE, bCheck);
2635             }
2636             aMenu.InsertSeparator();
2637             aMenu.InsertItem( TBI_COPY, String( SfxResId( STR_HELP_MENU_TEXT_COPY ) ),
2638                 Image( SfxResId( bHiContrast ? IMG_HELP_TOOLBOX_HC_COPY : IMG_HELP_TOOLBOX_COPY ) ) );
2639             aMenu.SetHelpId( TBI_COPY, ".uno:Copy" );
2640             aMenu.EnableItem( TBI_COPY, HasSelection() );
2641 
2642             if ( bIsDebug )
2643             {
2644                 aMenu.InsertSeparator();
2645                 aMenu.InsertItem( TBI_SOURCEVIEW, String( SfxResId( STR_HELP_BUTTON_SOURCEVIEW ) ) );
2646             }
2647 
2648             if( SvtMenuOptions().IsEntryHidingEnabled() == sal_False )
2649                 aMenu.SetMenuFlags( aMenu.GetMenuFlags() | MENU_FLAG_HIDEDISABLEDENTRIES );
2650 
2651             sal_uInt16 nId = aMenu.Execute( this, aPos );
2652             pHelpWin->DoAction( nId );
2653             nDone = 1;
2654         }
2655     }
2656     else if ( EVENT_KEYINPUT == nType && rNEvt.GetKeyEvent() )
2657     {
2658         const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
2659         const KeyCode& rKeyCode = pKEvt->GetKeyCode();
2660         sal_uInt16 nKeyGroup = rKeyCode.GetGroup();
2661         sal_uInt16 nKey = rKeyCode.GetCode();
2662         if ( KEYGROUP_ALPHA == nKeyGroup &&  !isHandledKey( rKeyCode ) )
2663         {
2664             // do nothing disables the writer accelerators
2665             nDone = 1;
2666         }
2667         else if ( rKeyCode.IsMod1() && ( KEY_F4 == nKey || KEY_W == nKey ) )
2668         {
2669             // <STRG><F4> or <STRG><W> -> close top frame
2670             pHelpWin->CloseWindow();
2671             nDone = 1;
2672         }
2673         else if ( KEY_TAB == nKey && aOnStartupCB.HasChildPathFocus() )
2674         {
2675             aToolBox.GrabFocus();
2676             nDone = 1;
2677         }
2678     }
2679 
2680     return nDone ? nDone : Window::PreNotify( rNEvt );
2681 }
2682 
2683 // -----------------------------------------------------------------------
2684 
GetFocus()2685 void SfxHelpTextWindow_Impl::GetFocus()
2686 {
2687     if ( !bIsInClose )
2688     {
2689         try
2690         {
2691             if( xFrame.is() )
2692             {
2693                 Reference< ::com::sun::star::awt::XWindow > xWindow = xFrame->getComponentWindow();
2694                 if( xWindow.is() )
2695                     xWindow->setFocus();
2696             }
2697         }
2698         catch( Exception& )
2699         {
2700             DBG_ERRORFILE( "SfxHelpTextWindow_Impl::GetFocus(): unexpected exception" );
2701         }
2702     }
2703 }
2704 
2705 // -----------------------------------------------------------------------
2706 
DataChanged(const DataChangedEvent & rDCEvt)2707 void SfxHelpTextWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
2708 {
2709     Window::DataChanged( rDCEvt );
2710 
2711     if ( ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
2712            ( rDCEvt.GetType() == DATACHANGED_DISPLAY ) ) &&
2713          ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
2714     {
2715         SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFaceColor() ) );
2716         InitToolBoxImages();
2717     }
2718 }
2719 
2720 // -----------------------------------------------------------------------
2721 
ToggleIndex(sal_Bool bOn)2722 void SfxHelpTextWindow_Impl::ToggleIndex( sal_Bool bOn )
2723 {
2724     bIsIndexOn = bOn;
2725     if ( bIsIndexOn )
2726     {
2727         aToolBox.SetItemImage( TBI_INDEX, aIndexOffImage );
2728         aToolBox.SetItemText( TBI_INDEX, aIndexOffText );
2729     }
2730     else
2731     {
2732         aToolBox.SetItemImage( TBI_INDEX, aIndexOnImage );
2733         aToolBox.SetItemText( TBI_INDEX, aIndexOnText );
2734     }
2735 }
2736 
2737 // -----------------------------------------------------------------------
2738 
SelectSearchText(const String & rSearchText,sal_Bool _bIsFullWordSearch)2739 void SfxHelpTextWindow_Impl::SelectSearchText( const String& rSearchText, sal_Bool _bIsFullWordSearch )
2740 {
2741     aSearchText = rSearchText;
2742     bIsFullWordSearch = _bIsFullWordSearch;
2743     aSelectTimer.Start();
2744 }
2745 
2746 // -----------------------------------------------------------------------
2747 
SetPageStyleHeaderOff() const2748 void SfxHelpTextWindow_Impl::SetPageStyleHeaderOff() const
2749 {
2750 #ifdef DBG_UTIL
2751     sal_Bool bSetOff = sal_False;
2752 #endif
2753     // set off the pagestyle header to prevent print output of the help URL
2754     try
2755     {
2756         Reference < XController > xController = xFrame->getController();
2757         Reference < XSelectionSupplier > xSelSup( xController, UNO_QUERY );
2758         if ( xSelSup.is() )
2759         {
2760             Reference < XIndexAccess > xSelection;
2761             if ( xSelSup->getSelection() >>= xSelection )
2762             {
2763                 Reference < XTextRange > xRange;
2764                 if ( xSelection->getByIndex(0) >>= xRange )
2765                 {
2766                     Reference < XText > xText = xRange->getText();
2767                     Reference < XPropertySet > xProps( xText->createTextCursorByRange( xRange ), UNO_QUERY );
2768                     ::rtl::OUString sStyleName;
2769                     if ( xProps->getPropertyValue( DEFINE_CONST_OUSTRING("PageStyleName") ) >>= sStyleName )
2770                     {
2771                         Reference < XStyleFamiliesSupplier > xStyles( xController->getModel(), UNO_QUERY );
2772                         Reference < XNameContainer > xContainer;
2773                         if ( xStyles->getStyleFamilies()->getByName( DEFINE_CONST_OUSTRING("PageStyles") )
2774                              >>= xContainer )
2775                         {
2776                             Reference < XStyle > xStyle;
2777                             if ( xContainer->getByName( sStyleName ) >>= xStyle )
2778                             {
2779                                 Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
2780                                 xPropSet->setPropertyValue( DEFINE_CONST_OUSTRING("HeaderIsOn"),
2781                                                             makeAny( sal_Bool( sal_False ) ) );
2782 
2783                                 Reference< XModifiable > xReset(xStyles, UNO_QUERY);
2784                                 xReset->setModified(sal_False);
2785 #ifdef DBG_UTIL
2786                                 bSetOff = sal_True;
2787 #endif
2788                             }
2789                         }
2790                     }
2791                 }
2792             }
2793         }
2794     }
2795     catch( Exception& )
2796     {
2797         DBG_ERRORFILE( "SfxHelpTextWindow_Impl::SetPageStyleHeaderOff(): unexpected exception" );
2798     }
2799 
2800 #ifdef DBG_UTIL
2801     if ( !bSetOff )
2802     {
2803         DBG_ERRORFILE( "SfxHelpTextWindow_Impl::SetPageStyleHeaderOff(): set off failed" );
2804     }
2805 #endif
2806 }
2807 
2808 // -----------------------------------------------------------------------
2809 
CloseFrame()2810 void SfxHelpTextWindow_Impl::CloseFrame()
2811 {
2812     bIsInClose = sal_True;
2813     try
2814     {
2815         ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > xCloseable  ( xFrame, ::com::sun::star::uno::UNO_QUERY );
2816         if (xCloseable.is())
2817             xCloseable->close(sal_True);
2818     }
2819     catch( ::com::sun::star::util::CloseVetoException& )
2820     {
2821     }
2822 }
2823 
2824 // -----------------------------------------------------------------------
2825 
DoSearch()2826 void SfxHelpTextWindow_Impl::DoSearch()
2827 {
2828     if ( !pSrchDlg )
2829     {
2830         // create the search dialog
2831         pSrchDlg = new sfx2::SearchDialog( pTextWin, DEFINE_CONST_UNICODE("HelpSearchDialog") );
2832         // set handler
2833         pSrchDlg->SetFindHdl( LINK( this, SfxHelpTextWindow_Impl, FindHdl ) );
2834         pSrchDlg->SetCloseHdl( LINK( this, SfxHelpTextWindow_Impl, CloseHdl ) );
2835         // get selected text of the help page to set it as the search text
2836         Reference< XTextRange > xCursor = getCursor();
2837         if ( xCursor.is() )
2838         {
2839             String sText = xCursor->getString();
2840             if ( sText.Len() > 0 )
2841                 pSrchDlg->SetSearchText( sText );
2842         }
2843         pSrchDlg->Show();
2844     }
2845 }
2846 
2847 // class SfxHelpWindow_Impl ----------------------------------------------
2848 
Resize()2849 void SfxHelpWindow_Impl::Resize()
2850 {
2851     SplitWindow::Resize();
2852     InitSizes();
2853 }
2854 
2855 // -----------------------------------------------------------------------
2856 
Split()2857 void SfxHelpWindow_Impl::Split()
2858 {
2859     static long nMinSplitSize = 5;
2860     static long nMaxSplitSize = 99 - nMinSplitSize;
2861 
2862     SplitWindow::Split();
2863 
2864     nIndexSize = GetItemSize( INDEXWIN_ID );
2865     nTextSize = GetItemSize( TEXTWIN_ID );
2866 
2867     sal_Bool        bMod = sal_False;
2868     if( nIndexSize < nMinSplitSize )
2869     {
2870         nIndexSize = nMinSplitSize;
2871         nTextSize = nMaxSplitSize;
2872 
2873         bMod = sal_True;
2874     }
2875     else if( nTextSize < nMinSplitSize )
2876     {
2877         nTextSize = nMinSplitSize;
2878         nIndexSize = nMaxSplitSize;
2879 
2880         bMod = sal_True;
2881     }
2882     else
2883         bMod = sal_False;
2884 
2885     if( bMod )
2886     {
2887         SetItemSize( INDEXWIN_ID, nIndexSize );
2888         SetItemSize( TEXTWIN_ID, nTextSize );
2889     }
2890 
2891     InitSizes();
2892 }
2893 
2894 // -----------------------------------------------------------------------
2895 
GetFocus()2896 void SfxHelpWindow_Impl::GetFocus()
2897 {
2898     pTextWin->GrabFocus();
2899 }
2900 
2901 // -----------------------------------------------------------------------
2902 
MakeLayout()2903 void SfxHelpWindow_Impl::MakeLayout()
2904 {
2905     if ( nHeight > 0 && xWindow.is() )
2906     {
2907         Window* pScreenWin = VCLUnoHelper::GetWindow( xWindow );
2908 
2909         /* #i55528#
2910             Hide() / Show() will produce starnge effects.
2911             The returned size (used later to be written back into the configuration)
2912             isnt the right after a resize during the window is hidden.
2913             If this resize is done if the window is visible evyrthing works as aspected.
2914             Some VCL-patches could not solve this problem so I've established the
2915             workaround: resize the help window if it's visible .-)
2916         */
2917 //      pScreenWin->Hide();
2918 
2919         ::com::sun::star::awt::Rectangle aRect = xWindow->getPosSize();
2920         sal_Int32 nOldWidth = bIndex ? nCollapseWidth : nExpandWidth;
2921         sal_Int32 nWidth = bIndex ? nExpandWidth : nCollapseWidth;
2922         xWindow->setPosSize( aRect.X, aRect.Y, nWidth, nHeight, ::com::sun::star::awt::PosSize::SIZE );
2923 
2924         if ( aRect.Width > 0 && aRect.Height > 0 )
2925         {
2926             Rectangle aScreenRect = pScreenWin->GetClientWindowExtentsRelative( NULL );
2927             Point aNewPos = aScreenRect.TopLeft();
2928             sal_Int32 nDiffWidth = nOldWidth - nWidth;
2929             aNewPos.X() += nDiffWidth;
2930             pScreenWin->SetPosPixel( aNewPos );
2931         }
2932         else if ( aWinPos.X() > 0 && aWinPos.Y() > 0 )
2933             pScreenWin->SetPosPixel( aWinPos );
2934 
2935 //      pScreenWin->Show();
2936     }
2937 
2938     Clear();
2939 
2940     if ( bIndex )
2941     {
2942         pIndexWin->Show();
2943         InsertItem( COLSET_ID, 100, SPLITWINDOW_APPEND, SPLITSET_ID, SWIB_PERCENTSIZE | SWIB_COLSET );
2944         InsertItem( INDEXWIN_ID, pIndexWin, nIndexSize, SPLITWINDOW_APPEND, COLSET_ID, SWIB_PERCENTSIZE );
2945         InsertItem( TEXTWIN_ID, pTextWin, nTextSize, SPLITWINDOW_APPEND, COLSET_ID, SWIB_PERCENTSIZE );
2946     }
2947     else
2948     {
2949         pIndexWin->Hide();
2950         InsertItem( COLSET_ID, 100, SPLITWINDOW_APPEND, SPLITSET_ID, SWIB_PERCENTSIZE | SWIB_COLSET );
2951         InsertItem( TEXTWIN_ID, pTextWin, 100, SPLITWINDOW_APPEND, 1, SWIB_PERCENTSIZE );
2952     }
2953 }
2954 
2955 // -----------------------------------------------------------------------
2956 
InitSizes()2957 void SfxHelpWindow_Impl::InitSizes()
2958 {
2959     if ( xWindow.is() )
2960     {
2961         ::com::sun::star::awt::Rectangle aRect = xWindow->getPosSize();
2962         nHeight = aRect.Height;
2963 
2964         if ( bIndex )
2965         {
2966             nExpandWidth = aRect.Width;
2967             nCollapseWidth = nExpandWidth * nTextSize / 100;
2968         }
2969         else
2970         {
2971             nCollapseWidth = aRect.Width;
2972             nExpandWidth = nCollapseWidth * 100 / nTextSize;
2973         }
2974     }
2975 }
2976 
2977 // -----------------------------------------------------------------------
2978 
LoadConfig()2979 void SfxHelpWindow_Impl::LoadConfig()
2980 {
2981     SvtViewOptions aViewOpt( E_WINDOW, CONFIGNAME_HELPWIN );
2982     if ( aViewOpt.Exists() )
2983     {
2984         bIndex = aViewOpt.IsVisible();
2985         String aUserData;
2986         Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
2987         rtl::OUString aTemp;
2988         if ( aUserItem >>= aTemp )
2989         {
2990             aUserData = String( aTemp );
2991             DBG_ASSERT( aUserData.GetTokenCount() == 6, "invalid user data" );
2992             sal_uInt16 nIdx = 0;
2993             nIndexSize = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
2994             nTextSize = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
2995             sal_Int32 nWidth = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
2996             nHeight = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
2997             aWinPos.X() = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
2998             aWinPos.Y() = aUserData.GetToken( 0, ';', nIdx ).ToInt32();
2999             if ( bIndex )
3000             {
3001                 nExpandWidth = nWidth;
3002                 nCollapseWidth = nExpandWidth * nTextSize / 100;
3003             }
3004             else
3005             {
3006                 nCollapseWidth = nWidth;
3007                 nExpandWidth = nCollapseWidth * 100 / nTextSize;
3008             }
3009         }
3010 
3011         pTextWin->ToggleIndex( bIndex );
3012     }
3013 }
3014 
3015 // -----------------------------------------------------------------------
3016 
SaveConfig()3017 void SfxHelpWindow_Impl::SaveConfig()
3018 {
3019     SvtViewOptions aViewOpt( E_WINDOW, CONFIGNAME_HELPWIN );
3020     sal_Int32 nW = 0, nH = 0;
3021 
3022     if ( xWindow.is() )
3023     {
3024         ::com::sun::star::awt::Rectangle aRect = xWindow->getPosSize();
3025         nW = aRect.Width;
3026         nH = aRect.Height;
3027     }
3028 
3029     aViewOpt.SetVisible( bIndex );
3030     String aUserData = String::CreateFromInt32( nIndexSize );
3031     aUserData += ';';
3032     aUserData += String::CreateFromInt32( nTextSize );
3033     aUserData += ';';
3034     aUserData += String::CreateFromInt32( nW );
3035     aUserData += ';';
3036     aUserData += String::CreateFromInt32( nH );
3037 
3038     Window* pScreenWin = VCLUnoHelper::GetWindow( xWindow );
3039     aWinPos = pScreenWin->GetWindowExtentsRelative( NULL ).TopLeft();
3040     aUserData += ';';
3041     aUserData += String::CreateFromInt32( aWinPos.X() );
3042     aUserData += ';';
3043     aUserData += String::CreateFromInt32( aWinPos.Y() );
3044 
3045     aViewOpt.SetUserItem( USERITEM_NAME, makeAny( rtl::OUString( aUserData ) ) );
3046 }
3047 
3048 // -----------------------------------------------------------------------
3049 
ShowStartPage()3050 void SfxHelpWindow_Impl::ShowStartPage()
3051 {
3052     ::rtl::OUString sHelpURL = SfxHelpWindow_Impl::buildHelpURL(pIndexWin->GetFactory(),
3053                                                                 DEFINE_CONST_UNICODE("/start"),
3054                                                                 ::rtl::OUString(),
3055                                                                 sal_True);
3056     loadHelpContent(sHelpURL);
3057 }
3058 
3059 // -----------------------------------------------------------------------
3060 
IMPL_LINK(SfxHelpWindow_Impl,SelectHdl,ToolBox *,pToolBox)3061 IMPL_LINK( SfxHelpWindow_Impl, SelectHdl, ToolBox* , pToolBox )
3062 {
3063     if ( pToolBox )
3064     {
3065         bGrabFocusToToolBox = pToolBox->HasChildPathFocus();
3066         DoAction( pToolBox->GetCurItemId() );
3067     }
3068 
3069     return 1;
3070 }
3071 
3072 //-------------------------------------------------------------------------
3073 
IMPL_LINK(SfxHelpWindow_Impl,OpenHdl,SfxHelpIndexWindow_Impl *,EMPTYARG)3074 IMPL_LINK( SfxHelpWindow_Impl, OpenHdl, SfxHelpIndexWindow_Impl* , EMPTYARG )
3075 {
3076     pIndexWin->SelectExecutableEntry();
3077     String aEntry = pIndexWin->GetSelectEntry();
3078 
3079     if ( aEntry.Len() < 1 )
3080         return 0;
3081 
3082     ::rtl::OUString sHelpURL;
3083 
3084 //  INetURLObject aObj(aEntry);
3085 //  sal_Bool bComplete = ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP );
3086 
3087     sal_Bool bComplete = rtl::OUString(aEntry).toAsciiLowerCase().match(rtl::OUString::createFromAscii("vnd.sun.star.help"),0);
3088 
3089     if (bComplete)
3090         sHelpURL = ::rtl::OUString(aEntry);
3091     else
3092     {
3093         String aId;
3094         String aAnchor = String('#');
3095         if ( aEntry.GetTokenCount( '#' ) == 2 )
3096         {
3097             aId = aEntry.GetToken( 0, '#' );
3098             aAnchor += aEntry.GetToken( 1, '#' );
3099         }
3100         else
3101             aId = aEntry;
3102 
3103         aEntry  = '/';
3104         aEntry += aId;
3105 
3106         sHelpURL = SfxHelpWindow_Impl::buildHelpURL(pIndexWin->GetFactory(),
3107                                                     aEntry,
3108                                                     aAnchor,
3109                                                     sal_True);
3110     }
3111 
3112     loadHelpContent(sHelpURL);
3113 
3114     return 0;
3115 }
3116 
3117 //-------------------------------------------------------------------------
3118 
IMPL_LINK(SfxHelpWindow_Impl,SelectFactoryHdl,SfxHelpIndexWindow_Impl *,pWin)3119 IMPL_LINK( SfxHelpWindow_Impl, SelectFactoryHdl, SfxHelpIndexWindow_Impl* , pWin )
3120 {
3121     if ( sTitle.Len() == 0 )
3122         sTitle = GetParent()->GetText();
3123 
3124     String aNewTitle = sTitle;
3125     aNewTitle += DEFINE_CONST_UNICODE(" - ");
3126     aNewTitle += pIndexWin->GetActiveFactoryTitle();
3127 
3128     Reference< XTitle > xTitle(xFrame, UNO_QUERY);
3129     if (xTitle.is ())
3130         xTitle->setTitle (aNewTitle);
3131 
3132     if ( pWin )
3133         ShowStartPage();
3134     pIndexWin->ClearSearchPage();
3135 
3136     return 0;
3137 }
3138 
3139 // -----------------------------------------------------------------------
3140 
IMPL_LINK(SfxHelpWindow_Impl,ChangeHdl,HelpListener_Impl *,pListener)3141 IMPL_LINK( SfxHelpWindow_Impl, ChangeHdl, HelpListener_Impl*, pListener )
3142 {
3143     SetFactory( pListener->GetFactory() );
3144     return 0;
3145 }
3146 
3147 // -----------------------------------------------------------------------
3148 
openDone(const::rtl::OUString & sURL,sal_Bool bSuccess)3149 void SfxHelpWindow_Impl::openDone(const ::rtl::OUString& sURL    ,
3150                                         sal_Bool         bSuccess)
3151 {
3152     INetURLObject aObj( sURL );
3153     if ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP )
3154         SetFactory( aObj.GetHost() );
3155     if ( IsWait() )
3156         LeaveWait();
3157     if ( bGrabFocusToToolBox )
3158     {
3159         pTextWin->GetToolBox().GrabFocus();
3160         bGrabFocusToToolBox = sal_False;
3161     }
3162     else
3163         pIndexWin->GrabFocusBack();
3164     if ( bSuccess )
3165     {
3166         // set some view settings: "prevent help tips" and "helpid == 68245"
3167         try
3168         {
3169             Reference < XController > xController = pTextWin->getFrame()->getController();
3170             if ( xController.is() )
3171             {
3172                 Reference < XViewSettingsSupplier > xSettings( xController, UNO_QUERY );
3173                 Reference < XPropertySet > xViewProps = xSettings->getViewSettings();
3174                 Reference< XPropertySetInfo > xInfo = xViewProps->getPropertySetInfo();
3175                 Any aBoolAny = makeAny( sal_Bool( sal_True ) );
3176                 xViewProps->setPropertyValue( DEFINE_CONST_OUSTRING("ShowContentTips"), makeAny( sal_Bool( sal_False ) ) );
3177                 xViewProps->setPropertyValue( DEFINE_CONST_OUSTRING("ShowGraphics"), aBoolAny );
3178                 xViewProps->setPropertyValue( DEFINE_CONST_OUSTRING("ShowTables"), aBoolAny );
3179                 xViewProps->setPropertyValue( DEFINE_CONST_OUSTRING("HelpURL"), makeAny( DEFINE_CONST_OUSTRING("HID:SFX2_HID_HELP_ONHELP") ) );
3180                 ::rtl::OUString sProperty( DEFINE_CONST_OUSTRING("IsExecuteHyperlinks") );
3181                 if ( xInfo->hasPropertyByName( sProperty ) )
3182                     xViewProps->setPropertyValue( sProperty, aBoolAny );
3183                 xController->restoreViewData(pHelpInterceptor->GetViewData());
3184             }
3185         }
3186         catch( Exception& )
3187         {
3188             DBG_ERROR( "SfxHelpWindow_Impl::OpenDoneHdl(): unexpected exception" );
3189         }
3190 
3191         // When the SearchPage opens the help doc, then select all words, which are equal to its text
3192         String sSearchText = TRIM( pIndexWin->GetSearchText() );
3193         if ( sSearchText.Len() > 0 )
3194             pTextWin->SelectSearchText( sSearchText, pIndexWin->IsFullWordSearch() );
3195 
3196         // no page style header -> this prevents a print output of the URL
3197         pTextWin->SetPageStyleHeaderOff();
3198     }
3199 }
3200 
3201 // -----------------------------------------------------------------------
3202 
SfxHelpWindow_Impl(const::com::sun::star::uno::Reference<::com::sun::star::frame::XFrame> & rFrame,Window * pParent,WinBits)3203 SfxHelpWindow_Impl::SfxHelpWindow_Impl(
3204     const ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame >& rFrame,
3205     Window* pParent, WinBits ) :
3206 
3207     SplitWindow( pParent, WB_3DLOOK | WB_NOSPLITDRAW ),
3208 
3209     xFrame              ( rFrame ),
3210     pIndexWin           ( NULL ),
3211     pTextWin            ( NULL ),
3212     pHelpInterceptor    ( new HelpInterceptor_Impl() ),
3213     pHelpListener       ( new HelpListener_Impl( pHelpInterceptor ) ),
3214     nExpandWidth        ( 0 ),
3215     nCollapseWidth      ( 0 ),
3216     nHeight             ( 0 ),
3217     nIndexSize          ( 40 ),
3218     nTextSize           ( 60 ),
3219     bIndex              ( sal_True ),
3220     bGrabFocusToToolBox ( sal_False ),
3221     aWinPos             ( 0, 0 ),
3222     sTitle              ( pParent->GetText() )
3223 {
3224     SetHelpId( HID_HELP_WINDOW );
3225     SetStyle( GetStyle() | WB_DIALOGCONTROL );
3226 
3227     pHelpInterceptor->InitWaiter( this );
3228     pIndexWin = new SfxHelpIndexWindow_Impl( this );
3229     pIndexWin->SetDoubleClickHdl( LINK( this, SfxHelpWindow_Impl, OpenHdl ) );
3230     pIndexWin->SetSelectFactoryHdl( LINK( this, SfxHelpWindow_Impl, SelectFactoryHdl ) );
3231     pIndexWin->Show();
3232     pTextWin = new SfxHelpTextWindow_Impl( this );
3233     Reference < XFramesSupplier > xSup( rFrame, UNO_QUERY );
3234     Reference < XFrames > xFrames = xSup->getFrames();
3235     xFrames->append( pTextWin->getFrame() );
3236     pTextWin->SetSelectHdl( LINK( this, SfxHelpWindow_Impl, SelectHdl ) );
3237     pTextWin->Show();
3238     pHelpInterceptor->setInterception( pTextWin->getFrame() );
3239     pHelpListener->SetChangeHdl( LINK( this, SfxHelpWindow_Impl, ChangeHdl ) );
3240     LoadConfig();
3241 }
3242 
3243 // -----------------------------------------------------------------------
3244 
~SfxHelpWindow_Impl()3245 SfxHelpWindow_Impl::~SfxHelpWindow_Impl()
3246 {
3247     SaveConfig();
3248     Window* pDel = pIndexWin;
3249     pIndexWin = NULL;
3250     delete pDel;
3251 
3252     pTextWin->CloseFrame();
3253     delete pTextWin;
3254 }
3255 
3256 // -----------------------------------------------------------------------
3257 
PreNotify(NotifyEvent & rNEvt)3258 long SfxHelpWindow_Impl::PreNotify( NotifyEvent& rNEvt )
3259 {
3260     sal_Bool bHandled = sal_False;
3261     if ( rNEvt.GetType() == EVENT_KEYINPUT )
3262     {
3263         // Backward == <ALT><LEFT> or <BACKSPACE> Forward == <ALT><RIGHT>
3264         const KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
3265         sal_uInt16 nKey = rKeyCode.GetCode();
3266         if ( ( rKeyCode.IsMod2() && ( KEY_LEFT == nKey || KEY_RIGHT == nKey ) ) ||
3267              ( !rKeyCode.GetModifier() && KEY_BACKSPACE == nKey && !pIndexWin->HasFocusOnEdit() ) )
3268         {
3269             DoAction( rKeyCode.GetCode() == KEY_RIGHT ? TBI_FORWARD : TBI_BACKWARD );
3270             bHandled = sal_True;
3271         }
3272         else if ( rKeyCode.IsMod1() && ( KEY_F4 == nKey || KEY_W == nKey ) )
3273         {
3274             // <STRG><F4> or <STRG><W> -> close top frame
3275             CloseWindow();
3276             bHandled = sal_True;
3277         }
3278     }
3279     return bHandled ? 1 : Window::PreNotify( rNEvt );
3280 }
3281 
3282 // -----------------------------------------------------------------------
3283 
setContainerWindow(Reference<::com::sun::star::awt::XWindow> xWin)3284 void SfxHelpWindow_Impl::setContainerWindow( Reference < ::com::sun::star::awt::XWindow > xWin )
3285 {
3286     xWindow = xWin;
3287     MakeLayout();
3288 }
3289 
3290 // -----------------------------------------------------------------------
3291 
SetFactory(const String & rFactory)3292 void SfxHelpWindow_Impl::SetFactory( const String& rFactory )
3293 {
3294     pIndexWin->SetFactory( rFactory, sal_True );
3295 }
3296 
3297 // -----------------------------------------------------------------------
3298 
SetHelpURL(const String & rURL)3299 void SfxHelpWindow_Impl::SetHelpURL( const String& rURL )
3300 {
3301     INetURLObject aObj( rURL );
3302     if ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP )
3303         SetFactory( aObj.GetHost() );
3304 }
3305 
3306 // -----------------------------------------------------------------------
3307 
DoAction(sal_uInt16 nActionId)3308 void SfxHelpWindow_Impl::DoAction( sal_uInt16 nActionId )
3309 {
3310     switch ( nActionId )
3311     {
3312         case TBI_INDEX :
3313         {
3314             bIndex = !bIndex;
3315             MakeLayout();
3316             pTextWin->ToggleIndex( bIndex );
3317             break;
3318         }
3319 
3320         case TBI_START :
3321         {
3322             ShowStartPage();
3323             break;
3324         }
3325 
3326         case TBI_BACKWARD :
3327         case TBI_FORWARD :
3328         {
3329             URL aURL;
3330             aURL.Complete = DEFINE_CONST_UNICODE(".uno:Backward");
3331             if ( TBI_FORWARD == nActionId )
3332                 aURL.Complete = DEFINE_CONST_UNICODE(".uno:Forward");
3333             PARSE_URL( aURL );
3334             pHelpInterceptor->dispatch( aURL, Sequence < PropertyValue >() );
3335             break;
3336         }
3337 
3338         case TBI_SEARCHDIALOG :
3339         {
3340             pTextWin->DoSearch();
3341             break;
3342         }
3343 
3344         case TBI_PRINT :
3345         case TBI_SOURCEVIEW :
3346         case TBI_COPY :
3347         case TBI_SELECTIONMODE:
3348         {
3349             Reference < XDispatchProvider > xProv( pTextWin->getFrame(), UNO_QUERY );
3350             if ( xProv.is() )
3351             {
3352                 URL aURL;
3353                 if ( TBI_PRINT == nActionId )
3354                     aURL.Complete = DEFINE_CONST_UNICODE(".uno:Print");
3355                 else if ( TBI_SOURCEVIEW == nActionId )
3356                     aURL.Complete = DEFINE_CONST_UNICODE(".uno:SourceView");
3357                 else if ( TBI_COPY == nActionId )
3358                     aURL.Complete = DEFINE_CONST_UNICODE(".uno:Copy");
3359                 else if ( TBI_SELECTIONMODE == nActionId )
3360                     aURL.Complete = DEFINE_CONST_UNICODE(".uno:SelectTextMode");
3361                 else
3362                     aURL.Complete = DEFINE_CONST_UNICODE(".uno:SearchDialog");
3363                 PARSE_URL( aURL );
3364                 Reference < XDispatch > xDisp = xProv->queryDispatch( aURL, String(), 0 );
3365                 if ( xDisp.is() )
3366                     xDisp->dispatch( aURL, Sequence < PropertyValue >() );
3367             }
3368             break;
3369         }
3370 
3371         case TBI_BOOKMARKS :
3372         {
3373             String aURL = pHelpInterceptor->GetCurrentURL();
3374             if ( aURL.Len() > 0 )
3375             {
3376                 try
3377                 {
3378                     Content aCnt( aURL, Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
3379                     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = aCnt.getProperties();
3380                     if ( xInfo->hasPropertyByName( PROPERTY_TITLE ) )
3381                     {
3382                         ::com::sun::star::uno::Any aAny = aCnt.getPropertyValue( PROPERTY_TITLE );
3383                         rtl::OUString aValue;
3384                         if ( aAny >>= aValue )
3385                         {
3386                             String aTitle( aValue );
3387                             SfxAddHelpBookmarkDialog_Impl aDlg( this, sal_False );
3388                             aDlg.SetTitle( aTitle );
3389                             if ( aDlg.Execute() == RET_OK )
3390                             {
3391                                 aTitle = aDlg.GetTitle();
3392                                 pIndexWin->AddBookmarks( aTitle, aURL );
3393                             }
3394                         }
3395                     }
3396                 }
3397                 catch( Exception& )
3398                 {
3399                     DBG_ERROR( "SfxHelpWindow_Impl::DoAction(): unexpected exception" );
3400                 }
3401             }
3402             break;
3403         }
3404     }
3405 }
3406 
3407 // -----------------------------------------------------------------------
3408 
CloseWindow()3409 void SfxHelpWindow_Impl::CloseWindow()
3410 {
3411     try
3412     {
3413         // search for top frame
3414         Reference< XFramesSupplier > xCreator = getTextFrame()->getCreator();
3415         while ( xCreator.is() && !xCreator->isTop() )
3416         {
3417             xCreator = xCreator->getCreator();
3418         }
3419 
3420         // when found, close it
3421         if ( xCreator.is() && xCreator->isTop() )
3422         {
3423             Reference < XCloseable > xCloser( xCreator, UNO_QUERY );
3424             if ( xCloser.is() )
3425                 xCloser->close( sal_False );
3426         }
3427     }
3428     catch( Exception& )
3429     {
3430         DBG_ERRORFILE( "SfxHelpWindow_Impl::CloseWindow(): caught an exception" );
3431     }
3432 }
3433 
3434 // -----------------------------------------------------------------------
3435 
UpdateToolbox()3436 void SfxHelpWindow_Impl::UpdateToolbox()
3437 {
3438     pTextWin->GetToolBox().EnableItem( TBI_BACKWARD, pHelpInterceptor->HasHistoryPred() );
3439     pTextWin->GetToolBox().EnableItem( TBI_FORWARD, pHelpInterceptor->HasHistorySucc() );
3440 }
3441 
3442 // -----------------------------------------------------------------------
3443 
HasHistoryPredecessor() const3444 sal_Bool SfxHelpWindow_Impl::HasHistoryPredecessor() const
3445 {
3446     return pHelpInterceptor->HasHistoryPred();
3447 }
3448 
3449 // -----------------------------------------------------------------------
3450 
HasHistorySuccessor() const3451 sal_Bool SfxHelpWindow_Impl::HasHistorySuccessor() const
3452 {
3453     return pHelpInterceptor->HasHistorySucc();
3454 }
3455 
3456 // class SfxAddHelpBookmarkDialog_Impl -----------------------------------
3457 
SfxAddHelpBookmarkDialog_Impl(Window * pParent,sal_Bool bRename)3458 SfxAddHelpBookmarkDialog_Impl::SfxAddHelpBookmarkDialog_Impl( Window* pParent, sal_Bool bRename ) :
3459 
3460     ModalDialog( pParent, SfxResId( DLG_HELP_ADDBOOKMARK ) ),
3461 
3462     aTitleFT    ( this, SfxResId( FT_BOOKMARK_TITLE ) ),
3463     aTitleED    ( this, SfxResId( ED_BOOKMARK_TITLE ) ),
3464     aOKBtn      ( this, SfxResId( PB_BOOKMARK_OK ) ),
3465     aEscBtn     ( this, SfxResId( PB_BOOKMARK_CANCEL ) ),
3466     aHelpBtn    ( this, SfxResId( PB_BOOKMARK_HELP ) )
3467 
3468 {
3469     if ( bRename )
3470         SetText( String( SfxResId( STR_BOOKMARK_RENAME ) ) );
3471 
3472     FreeResource();
3473 }
3474 
3475 // -----------------------------------------------------------------------
3476 
~SfxAddHelpBookmarkDialog_Impl()3477 SfxAddHelpBookmarkDialog_Impl::~SfxAddHelpBookmarkDialog_Impl()
3478 {
3479 }
3480 
3481 // -----------------------------------------------------------------------
3482 
SetTitle(const String & rTitle)3483 void SfxAddHelpBookmarkDialog_Impl::SetTitle( const String& rTitle )
3484 {
3485     aTitleED.SetText( rTitle );
3486     aTitleED.SetSelection( Selection( 0, rTitle.Len() ) );
3487 }
3488 
3489