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 #ifndef INCLUDED_SFX_NEWHELP_HXX 24 #define INCLUDED_SFX_NEWHELP_HXX 25 26 #include <cppuhelper/implbase1.hxx> 27 #include <com/sun/star/uno/Reference.h> 28 #include <com/sun/star/frame/XDispatchResultListener.hpp> 29 #include <com/sun/star/frame/XDispatch.hpp> 30 #include <com/sun/star/frame/XFrame.hpp> 31 32 namespace com { namespace sun { namespace star { namespace awt { class XWindow; } } } } 33 namespace com { namespace sun { namespace star { namespace frame { class XFrame; } } } } 34 namespace com { namespace sun { namespace star { namespace i18n { class XBreakIterator; } } } } 35 namespace com { namespace sun { namespace star { namespace text { class XTextRange; } } } } 36 37 #include <vcl/window.hxx> 38 #include <vcl/toolbox.hxx> 39 #include <vcl/tabpage.hxx> 40 #include <vcl/splitwin.hxx> 41 #include <vcl/tabctrl.hxx> 42 #include <vcl/combobox.hxx> 43 #include <vcl/fixed.hxx> 44 #include <vcl/button.hxx> 45 #include <vcl/lstbox.hxx> 46 #include <vcl/dialog.hxx> 47 #include <svtools/svtreebx.hxx> 48 #include <unotools/moduleoptions.hxx> 49 50 #include "srchdlg.hxx" 51 52 // class OpenStatusListener_Impl ----------------------------------------- 53 54 class OpenStatusListener_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::frame::XDispatchResultListener > 55 { 56 private: 57 sal_Bool m_bFinished; 58 sal_Bool m_bSuccess; 59 Link m_aOpenLink; 60 String m_sURL; 61 62 public: 63 OpenStatusListener_Impl() : m_bFinished( sal_False ), m_bSuccess( sal_False ) {} 64 65 virtual void SAL_CALL dispatchFinished( const ::com::sun::star::frame::DispatchResultEvent& Event ) throw(::com::sun::star::uno::RuntimeException); 66 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); 67 68 inline sal_Bool IsFinished() const { return m_bFinished; } 69 inline sal_Bool IsSuccessful() const { return m_bSuccess; } 70 inline void SetURL( const String& rURL ) { m_sURL = rURL; } 71 inline String GetURL() const { return m_sURL; } 72 inline void SetOpenHdl( const Link& rLink ) { m_aOpenLink = rLink; } 73 }; 74 75 // ContentListBox_Impl --------------------------------------------------- 76 77 class ContentListBox_Impl : public SvTreeListBox 78 { 79 private: 80 Image aOpenBookImage; 81 Image aClosedBookImage; 82 Image aDocumentImage; 83 84 void InitRoot(); 85 void ClearChildren( SvLBoxEntry* pParent ); 86 87 public: 88 ContentListBox_Impl( Window* pParent, const ResId& rResId ); 89 ~ContentListBox_Impl(); 90 91 92 virtual void RequestingChilds( SvLBoxEntry* pParent ); 93 virtual long Notify( NotifyEvent& rNEvt ); 94 95 inline void SetOpenHdl( const Link& rLink ) { SetDoubleClickHdl( rLink ); } 96 String GetSelectEntry() const; 97 }; 98 99 // class HelpTabPage_Impl ------------------------------------------------ 100 101 class SfxHelpIndexWindow_Impl; 102 103 class HelpTabPage_Impl : public TabPage 104 { 105 protected: 106 SfxHelpIndexWindow_Impl* m_pIdxWin; 107 108 public: 109 HelpTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin, const ResId& rResId ); 110 111 virtual Control* GetLastFocusControl() = 0; 112 }; 113 114 // class ContentTabPage_Impl --------------------------------------------- 115 116 class ContentTabPage_Impl : public HelpTabPage_Impl 117 { 118 private: 119 ContentListBox_Impl aContentBox; 120 121 public: 122 ContentTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ); 123 124 virtual void Resize(); 125 virtual void ActivatePage(); 126 virtual Control* GetLastFocusControl(); 127 128 inline void SetOpenHdl( const Link& rLink ) { aContentBox.SetOpenHdl( rLink ); } 129 inline String GetSelectEntry() const { return aContentBox.GetSelectEntry(); } 130 inline void SetFocusOnBox() { aContentBox.GrabFocus(); } 131 }; 132 133 // class IndexTabPage_Impl ----------------------------------------------- 134 135 class IndexBox_Impl : public ComboBox 136 { 137 public: 138 IndexBox_Impl( Window* pParent, const ResId& rResId ); 139 140 virtual void UserDraw( const UserDrawEvent& rUDEvt ); 141 virtual long Notify( NotifyEvent& rNEvt ); 142 143 void SelectExecutableEntry(); 144 }; 145 146 class IndexTabPage_Impl : public HelpTabPage_Impl 147 { 148 private: 149 FixedText aExpressionFT; 150 IndexBox_Impl aIndexCB; 151 PushButton aOpenBtn; 152 153 Timer aFactoryTimer; 154 Timer aKeywordTimer; 155 Link aKeywordLink; 156 157 String sFactory; 158 String sKeyword; 159 160 long nMinWidth; 161 sal_Bool bIsActivated; 162 163 void InitializeIndex(); 164 void ClearIndex(); 165 166 DECL_LINK( OpenHdl, PushButton* ); 167 DECL_LINK( TimeoutHdl, Timer* ); 168 169 public: 170 IndexTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ); 171 ~IndexTabPage_Impl(); 172 173 virtual void Resize(); 174 virtual void ActivatePage(); 175 virtual Control* GetLastFocusControl(); 176 177 void SetDoubleClickHdl( const Link& rLink ); 178 void SetFactory( const String& rFactory ); 179 inline String GetFactory() const { return sFactory; } 180 String GetSelectEntry() const; 181 inline void SetFocusOnBox() { aIndexCB.GrabFocus(); } 182 inline sal_Bool HasFocusOnEdit() const { return aIndexCB.HasChildPathFocus(); } 183 184 inline void SetKeywordHdl( const Link& rLink ) { aKeywordLink = rLink; } 185 void SetKeyword( const String& rKeyword ); 186 sal_Bool HasKeyword() const; 187 sal_Bool HasKeywordIgnoreCase(); //added by BerryJia for fixing Bug98251, 2002-12-11 188 void OpenKeyword(); 189 190 inline void SelectExecutableEntry() { aIndexCB.SelectExecutableEntry(); } 191 }; 192 193 // class SearchTabPage_Impl ---------------------------------------------- 194 195 class SearchBox_Impl : public ComboBox 196 { 197 private: 198 Link aSearchLink; 199 200 public: 201 SearchBox_Impl( Window* pParent, const ResId& rResId ) : 202 ComboBox( pParent, rResId ) { SetDropDownLineCount( 5 ); } 203 204 virtual long PreNotify( NotifyEvent& rNEvt ); 205 virtual void Select(); 206 207 inline void SetSearchLink( const Link& rLink ) { aSearchLink = rLink; } 208 }; 209 210 class SearchResultsBox_Impl : public ListBox 211 { 212 public: 213 SearchResultsBox_Impl( Window* pParent, const ResId& rResId ) : ListBox( pParent, rResId ) {} 214 215 virtual long Notify( NotifyEvent& rNEvt ); 216 }; 217 218 class SearchTabPage_Impl : public HelpTabPage_Impl 219 { 220 private: 221 FixedText aSearchFT; 222 SearchBox_Impl aSearchED; 223 PushButton aSearchBtn; 224 CheckBox aFullWordsCB; 225 CheckBox aScopeCB; 226 SearchResultsBox_Impl aResultsLB; 227 PushButton aOpenBtn; 228 229 Size aMinSize; 230 String aFactory; 231 232 ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > 233 xBreakIterator; 234 235 void ClearSearchResults(); 236 void RememberSearchText( const String& rSearchText ); 237 238 DECL_LINK( SearchHdl, PushButton* ); 239 DECL_LINK( OpenHdl, PushButton* ); 240 DECL_LINK( ModifyHdl, Edit* ); 241 242 public: 243 SearchTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ); 244 ~SearchTabPage_Impl(); 245 246 virtual void Resize(); 247 virtual void ActivatePage(); 248 virtual Control* GetLastFocusControl(); 249 250 void SetDoubleClickHdl( const Link& rLink ); 251 inline void SetFactory( const String& rFactory ) { aFactory = rFactory; } 252 String GetSelectEntry() const; 253 void ClearPage(); 254 inline void SetFocusOnBox() { aResultsLB.GrabFocus(); } 255 inline sal_Bool HasFocusOnEdit() const { return aSearchED.HasChildPathFocus(); } 256 inline String GetSearchText() const { return aSearchED.GetText(); } 257 inline sal_Bool IsFullWordSearch() const { return aFullWordsCB.IsChecked(); } 258 sal_Bool OpenKeyword( const String& rKeyword ); 259 }; 260 261 // class BookmarksTabPage_Impl ------------------------------------------- 262 263 class BookmarksBox_Impl : public ListBox 264 { 265 private: 266 void DoAction( sal_uInt16 nAction ); 267 268 public: 269 BookmarksBox_Impl( Window* pParent, const ResId& rResId ); 270 ~BookmarksBox_Impl(); 271 272 virtual long Notify( NotifyEvent& rNEvt ); 273 }; 274 275 class BookmarksTabPage_Impl : public HelpTabPage_Impl 276 { 277 private: 278 FixedText aBookmarksFT; 279 BookmarksBox_Impl aBookmarksBox; 280 PushButton aBookmarksPB; 281 282 long nMinWidth; 283 284 DECL_LINK( OpenHdl, PushButton* ); 285 286 public: 287 BookmarksTabPage_Impl( Window* pParent, SfxHelpIndexWindow_Impl* _pIdxWin ); 288 289 virtual void Resize(); 290 virtual void ActivatePage(); 291 virtual Control* GetLastFocusControl(); 292 293 void SetDoubleClickHdl( const Link& rLink ); 294 String GetSelectEntry() const; 295 void AddBookmarks( const String& rTitle, const String& rURL ); 296 inline void SetFocusOnBox() { aBookmarksBox.GrabFocus(); } 297 }; 298 299 // class SfxHelpIndexWindow_Impl ----------------------------------------- 300 301 class SfxHelpWindow_Impl; 302 303 class SfxHelpIndexWindow_Impl : public Window 304 { 305 private: 306 ListBox aActiveLB; 307 FixedLine aActiveLine; 308 309 TabControl aTabCtrl; 310 Timer aTimer; 311 312 Link aSelectFactoryLink; 313 Link aPageDoubleClickLink; 314 Link aIndexKeywordLink; 315 String sKeyword; 316 317 SfxHelpWindow_Impl* pParentWin; 318 319 ContentTabPage_Impl* pCPage; 320 IndexTabPage_Impl* pIPage; 321 SearchTabPage_Impl* pSPage; 322 BookmarksTabPage_Impl* pBPage; 323 324 long nMinWidth; 325 bool bWasCursorLeftOrRight; 326 bool bIsInitDone; 327 328 void Initialize(); 329 void SetActiveFactory(); 330 HelpTabPage_Impl* GetCurrentPage( sal_uInt16& rCurId ); 331 332 inline ContentTabPage_Impl* GetContentPage(); 333 inline IndexTabPage_Impl* GetIndexPage(); 334 inline SearchTabPage_Impl* GetSearchPage(); 335 inline BookmarksTabPage_Impl* GetBookmarksPage(); 336 337 DECL_LINK( ActivatePageHdl, TabControl* ); 338 DECL_LINK( SelectHdl, ListBox* ); 339 DECL_LINK( InitHdl, Timer* ); 340 DECL_LINK( SelectFactoryHdl, Timer* ); 341 DECL_LINK( KeywordHdl, IndexTabPage_Impl* ); 342 343 public: 344 SfxHelpIndexWindow_Impl( SfxHelpWindow_Impl* pParent ); 345 ~SfxHelpIndexWindow_Impl(); 346 347 virtual void Resize(); 348 virtual long PreNotify( NotifyEvent& rNEvt ); 349 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 350 351 void SetDoubleClickHdl( const Link& rLink ); 352 inline void SetSelectFactoryHdl( const Link& rLink ) { aSelectFactoryLink = rLink; } 353 void SetFactory( const String& rFactory, sal_Bool bActive ); 354 inline String GetFactory() const { return pIPage->GetFactory(); } 355 String GetSelectEntry() const; 356 void AddBookmarks( const String& rTitle, const String& rURL ); 357 bool IsValidFactory( const String& _rFactory ); 358 inline String GetActiveFactoryTitle() const { return aActiveLB.GetSelectEntry(); } 359 inline void UpdateTabControl() { aTabCtrl.Invalidate(); } 360 void ClearSearchPage(); 361 void GrabFocusBack(); 362 sal_Bool HasFocusOnEdit() const; 363 String GetSearchText() const; 364 sal_Bool IsFullWordSearch() const; 365 void OpenKeyword( const String& rKeyword ); 366 void SelectExecutableEntry(); 367 inline bool WasCursorLeftOrRight(); 368 }; 369 370 // inlines --------------------------------------------------------------- 371 372 ContentTabPage_Impl* SfxHelpIndexWindow_Impl::GetContentPage() 373 { 374 if ( !pCPage ) 375 { 376 pCPage = new ContentTabPage_Impl( &aTabCtrl, this ); 377 pCPage->SetOpenHdl( aPageDoubleClickLink ); 378 } 379 return pCPage; 380 } 381 IndexTabPage_Impl* SfxHelpIndexWindow_Impl::GetIndexPage() 382 { 383 if ( !pIPage ) 384 { 385 pIPage = new IndexTabPage_Impl( &aTabCtrl, this ); 386 pIPage->SetDoubleClickHdl( aPageDoubleClickLink ); 387 pIPage->SetKeywordHdl( aIndexKeywordLink ); 388 } 389 return pIPage; 390 } 391 392 SearchTabPage_Impl* SfxHelpIndexWindow_Impl::GetSearchPage() 393 { 394 if ( !pSPage ) 395 { 396 pSPage = new SearchTabPage_Impl( &aTabCtrl, this ); 397 pSPage->SetDoubleClickHdl( aPageDoubleClickLink ); 398 } 399 return pSPage; 400 } 401 402 BookmarksTabPage_Impl* SfxHelpIndexWindow_Impl::GetBookmarksPage() 403 { 404 if ( !pBPage ) 405 { 406 pBPage = new BookmarksTabPage_Impl( &aTabCtrl, this ); 407 pBPage->SetDoubleClickHdl( aPageDoubleClickLink ); 408 } 409 return pBPage; 410 } 411 412 bool SfxHelpIndexWindow_Impl::WasCursorLeftOrRight() 413 { 414 bool bRet = bWasCursorLeftOrRight; 415 bWasCursorLeftOrRight = false; 416 return bRet; 417 } 418 419 // class TextWin_Impl ---------------------------------------------------- 420 421 class TextWin_Impl : public DockingWindow 422 { 423 public: 424 TextWin_Impl( Window* pParent ); 425 virtual ~TextWin_Impl(); 426 427 virtual long Notify( NotifyEvent& rNEvt ); 428 }; 429 430 // class SfxHelpTextWindow_Impl ------------------------------------------ 431 432 class SvtMiscOptions; 433 class SfxHelpWindow_Impl; 434 435 class SfxHelpTextWindow_Impl : public Window 436 { 437 private: 438 ToolBox aToolBox; 439 CheckBox aOnStartupCB; 440 Timer aSelectTimer; 441 Image aIndexOnImage; 442 Image aIndexOffImage; 443 String aIndexOnText; 444 String aIndexOffText; 445 String aSearchText; 446 String aOnStartupText; 447 ::rtl::OUString sCurrentFactory; 448 449 SfxHelpWindow_Impl* pHelpWin; 450 Window* pTextWin; 451 sfx2::SearchDialog* pSrchDlg; 452 ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > 453 xFrame; 454 ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > 455 xBreakIterator; 456 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 457 xConfiguration; 458 long nMinPos; 459 sal_Bool bIsDebug; 460 sal_Bool bIsIndexOn; 461 sal_Bool bIsInClose; 462 sal_Bool bIsFullWordSearch; 463 464 sal_Bool HasSelection() const; 465 void InitToolBoxImages(); 466 void InitOnStartupBox( bool bOnlyText ); 467 void SetOnStartupBoxPosition(); 468 469 ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > 470 GetBreakIterator(); 471 ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > 472 getCursor() const; 473 bool isHandledKey( const KeyCode& _rKeyCode ); 474 475 DECL_LINK( SelectHdl, Timer* ); 476 DECL_LINK( NotifyHdl, SvtMiscOptions* ); 477 DECL_LINK( FindHdl, sfx2::SearchDialog* ); 478 DECL_LINK( CloseHdl, sfx2::SearchDialog* ); 479 DECL_LINK( CheckHdl, CheckBox* ); 480 481 public: 482 SfxHelpTextWindow_Impl( SfxHelpWindow_Impl* pParent ); 483 ~SfxHelpTextWindow_Impl(); 484 485 virtual void Resize(); 486 virtual long PreNotify( NotifyEvent& rNEvt ); 487 virtual void GetFocus(); 488 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 489 490 inline ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > 491 getFrame() const { return xFrame; } 492 493 inline void SetSelectHdl( const Link& rLink ) { aToolBox.SetSelectHdl( rLink ); } 494 void ToggleIndex( sal_Bool bOn ); 495 void SelectSearchText( const String& rSearchText, sal_Bool _bIsFullWordSearch ); 496 void SetPageStyleHeaderOff() const; 497 inline ToolBox& GetToolBox() { return aToolBox; } 498 void CloseFrame(); 499 void DoSearch(); 500 }; 501 502 // class SfxHelpWindow_Impl ---------------------------------------------- 503 504 class HelpInterceptor_Impl; 505 class HelpListener_Impl; 506 class SfxHelpWindow_Impl : public SplitWindow 507 { 508 private: 509 friend class SfxHelpIndexWindow_Impl; 510 511 ::com::sun::star::uno::Reference < ::com::sun::star::awt::XWindow > 512 xWindow; 513 ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatchResultListener > 514 xOpenListener; 515 ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > 516 xFrame; 517 518 SfxHelpIndexWindow_Impl* pIndexWin; 519 SfxHelpTextWindow_Impl* pTextWin; 520 HelpInterceptor_Impl* pHelpInterceptor; 521 HelpListener_Impl* pHelpListener; 522 523 sal_Int32 nExpandWidth; 524 sal_Int32 nCollapseWidth; 525 sal_Int32 nHeight; 526 long nIndexSize; 527 long nTextSize; 528 sal_Bool bIndex; 529 sal_Bool bGrabFocusToToolBox; 530 Point aWinPos; 531 String sTitle; 532 String sKeyword; 533 534 virtual void Resize(); 535 virtual void Split(); 536 virtual void GetFocus(); 537 538 void MakeLayout(); 539 void InitSizes(); 540 void LoadConfig(); 541 void SaveConfig(); 542 void ShowStartPage(); 543 544 DECL_LINK( SelectHdl, ToolBox* ); 545 DECL_LINK( OpenHdl, SfxHelpIndexWindow_Impl* ); 546 DECL_LINK( SelectFactoryHdl, SfxHelpIndexWindow_Impl* ); 547 DECL_LINK( ChangeHdl, HelpListener_Impl* ); 548 549 public: 550 SfxHelpWindow_Impl( const ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame >& rFrame, 551 Window* pParent, WinBits nBits ); 552 ~SfxHelpWindow_Impl(); 553 554 virtual long PreNotify( NotifyEvent& rNEvt ); 555 556 void setContainerWindow( 557 ::com::sun::star::uno::Reference < ::com::sun::star::awt::XWindow > xWin ); 558 inline ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > 559 getTextFrame() const { return pTextWin->getFrame(); } 560 inline ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatchResultListener > 561 getOpenListener() const { return xOpenListener; } 562 563 void SetFactory( const String& rFactory ); 564 void SetHelpURL( const String& rURL ); 565 void DoAction( sal_uInt16 nActionId ); 566 void CloseWindow(); 567 568 void UpdateToolbox(); 569 inline void OpenKeyword( const String& rKeyword ) { pIndexWin->OpenKeyword( rKeyword ); } 570 inline String GetFactory() const { return pIndexWin->GetFactory(); } 571 572 sal_Bool HasHistoryPredecessor() const; // forward to interceptor 573 sal_Bool HasHistorySuccessor() const; // forward to interceptor 574 575 void openDone(const ::rtl::OUString& sURL , 576 sal_Bool bSuccess); 577 578 static sal_Bool splitHelpURL(const ::rtl::OUString& sHelpURL, 579 ::rtl::OUString& sFactory, 580 ::rtl::OUString& sContent, 581 ::rtl::OUString& sAnchor ); 582 583 static ::rtl::OUString buildHelpURL(const ::rtl::OUString& sFactory , 584 const ::rtl::OUString& sContent , 585 const ::rtl::OUString& sAnchor , 586 sal_Bool bUseQuestionMark); 587 588 void loadHelpContent(const ::rtl::OUString& sHelpURL , 589 sal_Bool bAddToHistory = sal_True); 590 }; 591 592 class SfxAddHelpBookmarkDialog_Impl : public ModalDialog 593 { 594 private: 595 FixedText aTitleFT; 596 Edit aTitleED; 597 OKButton aOKBtn; 598 CancelButton aEscBtn; 599 HelpButton aHelpBtn; 600 601 public: 602 SfxAddHelpBookmarkDialog_Impl( Window* pParent, sal_Bool bRename = sal_True ); 603 ~SfxAddHelpBookmarkDialog_Impl(); 604 605 void SetTitle( const String& rTitle ); 606 inline String GetTitle() const { return aTitleED.GetText(); } 607 }; 608 609 #endif // #ifndef INCLUDED_SFX_NEWHELP_HXX 610 611