1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #ifndef INCLUDED_SFX2_SOURCE_APPL_NEWHELP_HXX
20 #define INCLUDED_SFX2_SOURCE_APPL_NEWHELP_HXX
21 
22 #include <com/sun/star/uno/Reference.h>
23 #include <com/sun/star/frame/XFrame2.hpp>
24 
25 #include <rtl/ustrbuf.hxx>
26 #include <vcl/builderpage.hxx>
27 #include <vcl/dockwin.hxx>
28 #include <vcl/idle.hxx>
29 #include <vcl/keycod.hxx>
30 #include <vcl/weld.hxx>
31 #include <vcl/window.hxx>
32 
33 #include <srchdlg.hxx>
34 
35 // context menu ids
36 #define MID_OPEN                                1
37 #define MID_RENAME                              2
38 #define MID_DELETE                              3
39 
40 namespace com::sun::star::awt { class XWindow; }
41 namespace com::sun::star::i18n { class XBreakIterator; }
42 namespace com::sun::star::text { class XTextRange; }
43 
44 // class HelpTabPage_Impl ------------------------------------------------
45 
46 class SfxHelpIndexWindow_Impl;
47 
48 class HelpTabPage_Impl : public BuilderPage
49 {
50 protected:
51     SfxHelpIndexWindow_Impl*    m_pIdxWin;
52 
53 public:
54     HelpTabPage_Impl(weld::Widget* pParent, SfxHelpIndexWindow_Impl* _pIdxWin,
55         const OString& rID, const OUString& rUIXMLDescription);
56     virtual ~HelpTabPage_Impl() override;
57 };
58 
59 // class ContentTabPage_Impl ---------------------------------------------
60 
61 class ContentTabPage_Impl : public HelpTabPage_Impl
62 {
63 private:
64     std::unique_ptr<weld::TreeView> m_xContentBox;
65     std::unique_ptr<weld::TreeIter> m_xScratchIter;
66     OUString aOpenBookImage;
67     OUString aClosedBookImage;
68     OUString aDocumentImage;
69 
70     Link<LinkParamNone*, void> aDoubleClickHdl;
71 
72     DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);
73     DECL_LINK(ExpandingHdl, const weld::TreeIter&, bool);
74     DECL_LINK(CollapsingHdl, const weld::TreeIter&, bool);
75 
76     void            ClearChildren(const weld::TreeIter* pParent);
77     void            InitRoot();
78 public:
79     ContentTabPage_Impl(weld::Widget* pParent, SfxHelpIndexWindow_Impl* _pIdxWin);
80     virtual ~ContentTabPage_Impl() override;
81 
82     void     SetDoubleClickHdl(const Link<LinkParamNone*, void>& rLink);
83     OUString GetSelectedEntry() const;
SetFocusOnBox()84     void     SetFocusOnBox() { m_xContentBox->grab_focus(); }
85 };
86 
87 class IndexTabPage_Impl : public HelpTabPage_Impl
88 {
89 private:
90     std::unique_ptr<weld::Entry> m_xIndexEntry;
91     std::unique_ptr<weld::TreeView> m_xIndexList;
92     std::unique_ptr<weld::Button> m_xOpenBtn;
93 
94     Idle                aFactoryIdle;
95     Idle                aAutoCompleteIdle;
96     Timer               aKeywordTimer;
97     Link<IndexTabPage_Impl&,void> aKeywordLink;
98 
99     OUString            sFactory;
100     OUString            sKeyword;
101 
102     bool                bIsActivated;
103     int                 nRowHeight;
104     int                 nAllHeight;
105 
106     void                InitializeIndex();
107     void                ClearIndex();
108 
109     Link<LinkParamNone*, void> aDoubleClickHdl;
110 
111     DECL_LINK(OpenHdl, weld::Button&, void);
112     DECL_LINK(IdleHdl, Timer*, void);
113     DECL_LINK(AutoCompleteHdl, Timer*, void);
114     DECL_LINK(TimeoutHdl, Timer*, void);
115     DECL_LINK(TreeChangeHdl, weld::TreeView&, void);
116     DECL_LINK(EntryChangeHdl, weld::Entry&, void);
117     DECL_LINK(ActivateHdl, weld::Entry&, bool);
118     DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);
119     DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
120     DECL_LINK(CustomGetSizeHdl, weld::TreeView::get_size_args, Size);
121     DECL_LINK(CustomRenderHdl, weld::TreeView::render_args, void);
122     DECL_LINK(ResizeHdl, const Size&, void);
123 
124     int starts_with(const OUString& rStr, int nStartRow, bool bCaseSensitive);
125 
126 public:
127     IndexTabPage_Impl(weld::Widget* pParent, SfxHelpIndexWindow_Impl* pIdxWin);
128     virtual ~IndexTabPage_Impl() override;
129 
130     virtual void        Activate() override;
131 
132     void                SetDoubleClickHdl(const Link<LinkParamNone*, void>& rLink);
133     void                SetFactory( const OUString& rFactory );
GetFactory() const134     const OUString&     GetFactory() const { return sFactory; }
135     OUString            GetSelectedEntry() const;
SetFocusOnBox()136     void                SetFocusOnBox() { m_xIndexEntry->grab_focus(); }
HasFocusOnEdit() const137     bool                HasFocusOnEdit() const { return m_xIndexEntry->has_focus(); }
138 
SetKeywordHdl(const Link<IndexTabPage_Impl &,void> & rLink)139     void                SetKeywordHdl( const Link<IndexTabPage_Impl&,void>& rLink ) { aKeywordLink = rLink; }
140     void                SetKeyword( const OUString& rKeyword );
141     bool                HasKeyword() const;
142     bool                HasKeywordIgnoreCase();
143     void                OpenKeyword();
144 
145     void         SelectExecutableEntry();
146 };
147 
148 class SearchTabPage_Impl : public HelpTabPage_Impl
149 {
150 private:
151     std::unique_ptr<weld::ComboBox> m_xSearchED;
152     std::unique_ptr<weld::Button> m_xSearchBtn;
153     std::unique_ptr<weld::CheckButton> m_xFullWordsCB;
154     std::unique_ptr<weld::CheckButton> m_xScopeCB;
155     std::unique_ptr<weld::TreeView> m_xResultsLB;
156     std::unique_ptr<weld::Button> m_xOpenBtn;
157 
158     Link<LinkParamNone*, void> aDoubleClickHdl;
159 
160     OUString                       aFactory;
161 
162     css::uno::Reference< css::i18n::XBreakIterator >
163                                    xBreakIterator;
164 
165     void ClearSearchResults();
166     void RememberSearchText( const OUString& rSearchText );
167     void Search();
168 
169     DECL_LINK(ClickHdl, weld::Button&, void);
170     DECL_LINK(OpenHdl, weld::Button&, void);
171     DECL_LINK(ModifyHdl, weld::ComboBox&, void);
172     DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);
173     DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
174 
175 public:
176     SearchTabPage_Impl(weld::Widget* pParent, SfxHelpIndexWindow_Impl* pIdxWin);
177     virtual ~SearchTabPage_Impl() override;
178 
179     void         SetDoubleClickHdl(const Link<LinkParamNone*, void>& rLink);
SetFactory(const OUString & rFactory)180     void         SetFactory( const OUString& rFactory ) { aFactory = rFactory; }
181     OUString     GetSelectedEntry() const;
182     void         ClearPage();
SetFocusOnBox()183     void         SetFocusOnBox() { m_xResultsLB->grab_focus(); }
HasFocusOnEdit() const184     bool         HasFocusOnEdit() const { return m_xSearchED->has_focus(); }
GetSearchText() const185     OUString     GetSearchText() const { return m_xSearchED->get_active_text(); }
IsFullWordSearch() const186     bool         IsFullWordSearch() const { return m_xFullWordsCB->get_active(); }
187     bool         OpenKeyword( const OUString& rKeyword );
188 };
189 
190 class BookmarksTabPage_Impl : public HelpTabPage_Impl
191 {
192 private:
193     std::unique_ptr<weld::TreeView> m_xBookmarksBox;
194     std::unique_ptr<weld::Button> m_xBookmarksPB;
195 
196     Link<LinkParamNone*, void> aDoubleClickHdl;
197 
198     DECL_LINK(OpenHdl, weld::Button&, void);
199     DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);
200     DECL_LINK(CommandHdl, const CommandEvent&, bool);
201     DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
202 
203     void DoAction(std::string_view rAction);
204 
205 public:
206     BookmarksTabPage_Impl(weld::Widget* pParent, SfxHelpIndexWindow_Impl* pIdxWin);
207     virtual ~BookmarksTabPage_Impl() override;
208 
209     void                SetDoubleClickHdl(const Link<LinkParamNone*, void>& rLink);
210     OUString            GetSelectedEntry() const;
211     void                AddBookmarks( const OUString& rTitle, const OUString& rURL );
SetFocusOnBox()212     void                SetFocusOnBox() { m_xBookmarksBox->grab_focus(); }
213 };
214 
215 // class SfxHelpIndexWindow_Impl -----------------------------------------
216 
217 class SfxHelpWindow_Impl;
218 
219 class SfxHelpIndexWindow_Impl
220 {
221 private:
222     std::unique_ptr<weld::Builder> m_xBuilder;
223     std::unique_ptr<weld::Container> m_xContainer;
224     std::unique_ptr<weld::ComboBox> m_xActiveLB;
225     std::unique_ptr<weld::Notebook> m_xTabCtrl;
226 
227     Idle                aIdle;
228 
229     Link<SfxHelpIndexWindow_Impl*,void> aSelectFactoryLink;
230     Link<LinkParamNone*,void>           aPageDoubleClickLink;
231     Link<IndexTabPage_Impl&,void>       aIndexKeywordLink;
232     OUString                            sKeyword;
233 
234     VclPtr<SfxHelpWindow_Impl>     pParentWin;
235 
236     std::unique_ptr<ContentTabPage_Impl> xCPage;
237     std::unique_ptr<IndexTabPage_Impl> xIPage;
238     std::unique_ptr<SearchTabPage_Impl> xSPage;
239     std::unique_ptr<BookmarksTabPage_Impl> xBPage;
240 
241     bool                bIsInitDone;
242 
243     void                Initialize();
244     void                SetActiveFactory();
245     HelpTabPage_Impl*   GetPage(std::string_view );
246 
247     inline ContentTabPage_Impl*     GetContentPage();
248     inline IndexTabPage_Impl*       GetIndexPage();
249     inline SearchTabPage_Impl*      GetSearchPage();
250     inline BookmarksTabPage_Impl*   GetBookmarksPage();
251 
252     DECL_LINK(ActivatePageHdl, const OString&, void);
253     DECL_LINK(SelectHdl, weld::ComboBox&, void);
254     DECL_LINK(InitHdl, Timer *, void);
255     DECL_LINK(SelectFactoryHdl, Timer *, void);
256     DECL_LINK(KeywordHdl, IndexTabPage_Impl&, void);
257     DECL_LINK(ContentTabPageDoubleClickHdl, LinkParamNone*, void);
258     DECL_LINK(TabPageDoubleClickHdl, LinkParamNone*, void);
259     DECL_LINK(IndexTabPageDoubleClickHdl, LinkParamNone*, void);
260 
261 public:
262     explicit SfxHelpIndexWindow_Impl(SfxHelpWindow_Impl* pParent, weld::Container* pContainer);
263     ~SfxHelpIndexWindow_Impl();
264 
265     void                SetDoubleClickHdl(const Link<LinkParamNone*, void>& rLink);
SetSelectFactoryHdl(const Link<SfxHelpIndexWindow_Impl *,void> & rLink)266     void                SetSelectFactoryHdl( const Link<SfxHelpIndexWindow_Impl*,void>& rLink ) { aSelectFactoryLink = rLink; }
267     void                SetFactory( const OUString& rFactory, bool bActive );
GetFactory() const268     OUString const &    GetFactory() const { return xIPage->GetFactory(); }
269     OUString            GetSelectedEntry() const;
270     void                AddBookmarks( const OUString& rTitle, const OUString& rURL );
271     bool                IsValidFactory( std::u16string_view _rFactory );
GetActiveFactoryTitle() const272     OUString            GetActiveFactoryTitle() const { return m_xActiveLB->get_active_text(); }
273     void                ClearSearchPage();
274     void                GrabFocusBack();
275     bool                HasFocusOnEdit() const;
276     OUString            GetSearchText() const;
277     bool                IsFullWordSearch() const;
278     void                OpenKeyword( const OUString& rKeyword );
279     void                SelectExecutableEntry();
280 
281     weld::Window*       GetFrameWeld() const;
282 };
283 
284 // inlines ---------------------------------------------------------------
285 
GetContentPage()286 ContentTabPage_Impl* SfxHelpIndexWindow_Impl::GetContentPage()
287 {
288     if (!xCPage)
289     {
290         xCPage.reset(new ContentTabPage_Impl(m_xTabCtrl->get_page("contents"), this));
291         xCPage->SetDoubleClickHdl(LINK(this, SfxHelpIndexWindow_Impl, ContentTabPageDoubleClickHdl));
292     }
293     return xCPage.get();
294 }
295 
GetIndexPage()296 IndexTabPage_Impl* SfxHelpIndexWindow_Impl::GetIndexPage()
297 {
298     if (!xIPage)
299     {
300         xIPage.reset(new IndexTabPage_Impl(m_xTabCtrl->get_page("index"), this));
301         xIPage->SetDoubleClickHdl( LINK(this, SfxHelpIndexWindow_Impl, IndexTabPageDoubleClickHdl) );
302         xIPage->SetKeywordHdl( aIndexKeywordLink );
303     }
304     return xIPage.get();
305 }
306 
GetSearchPage()307 SearchTabPage_Impl* SfxHelpIndexWindow_Impl::GetSearchPage()
308 {
309     if (!xSPage)
310     {
311         xSPage.reset(new SearchTabPage_Impl(m_xTabCtrl->get_page("find"), this));
312         xSPage->SetDoubleClickHdl( LINK(this, SfxHelpIndexWindow_Impl, TabPageDoubleClickHdl) );
313     }
314     return xSPage.get();
315 }
316 
GetBookmarksPage()317 BookmarksTabPage_Impl* SfxHelpIndexWindow_Impl::GetBookmarksPage()
318 {
319     if (!xBPage)
320     {
321         xBPage.reset(new BookmarksTabPage_Impl(m_xTabCtrl->get_page("bookmarks"), this));
322         xBPage->SetDoubleClickHdl( LINK(this, SfxHelpIndexWindow_Impl, TabPageDoubleClickHdl) );
323     }
324     return xBPage.get();
325 }
326 
327 // class TextWin_Impl ----------------------------------------------------
328 class TextWin_Impl : public DockingWindow
329 {
330 public:
331     explicit                TextWin_Impl( vcl::Window* pParent );
332 
333     virtual bool            EventNotify( NotifyEvent& rNEvt ) override;
334 };
335 
336 // class SfxHelpTextWindow_Impl ------------------------------------------
337 
338 class SvtMiscOptions;
339 class SfxHelpWindow_Impl;
340 
341 class SfxHelpTextWindow_Impl : public vcl::Window
342 {
343 private:
344     std::unique_ptr<weld::Toolbar> xToolBox;
345     std::unique_ptr<weld::CheckButton>  xOnStartupCB;
346     std::unique_ptr<weld::Menu>  xMenu;
347     Idle                    aSelectIdle;
348     OUString                aIndexOnImage;
349     OUString                aIndexOffImage;
350     OUString                aIndexOnText;
351     OUString                aIndexOffText;
352     OUString                aSearchText;
353     OUString                aOnStartupText;
354     OUString                sCurrentFactory;
355 
356     VclPtr<SfxHelpWindow_Impl>     xHelpWin;
357     VclPtr<vcl::Window>            pTextWin;
358     std::shared_ptr<sfx2::SearchDialog> m_xSrchDlg;
359     css::uno::Reference < css::frame::XFrame2 >
360                             xFrame;
361     css::uno::Reference< css::i18n::XBreakIterator >
362                             xBreakIterator;
363     css::uno::Reference< css::uno::XInterface >
364                             xConfiguration;
365     bool                    bIsDebug;
366     bool                    bIsIndexOn;
367     bool                    bIsInClose;
368     bool                    bIsFullWordSearch;
369 
370     bool                    HasSelection() const;
371     void                    InitToolBoxImages();
372     void                    InitOnStartupBox();
373 
374     css::uno::Reference< css::i18n::XBreakIterator > const &
375                             GetBreakIterator();
376     css::uno::Reference< css::text::XTextRange >
377                             getCursor() const;
378     bool                    isHandledKey( const vcl::KeyCode& _rKeyCode );
379 
380     DECL_LINK(        SelectHdl, Timer *, void);
381     DECL_LINK(        NotifyHdl, LinkParamNone*, void );
382     DECL_LINK(        FindHdl, sfx2::SearchDialog&, void );
383     DECL_LINK(        CloseHdl, LinkParamNone*, void );
384     DECL_LINK(        CheckHdl, weld::Toggleable&, void );
385     void                    FindHdl(sfx2::SearchDialog*);
386 
387 public:
388     explicit SfxHelpTextWindow_Impl(SfxHelpWindow_Impl* pHelpWin, weld::Builder& rBuilder, vcl::Window* pParent);
389     virtual ~SfxHelpTextWindow_Impl() override;
390     virtual void dispose() override;
391 
392     virtual void            Resize() override;
393     virtual bool            PreNotify( NotifyEvent& rNEvt ) override;
394     virtual void            GetFocus() override;
395     virtual void            DataChanged( const DataChangedEvent& rDCEvt ) override;
396 
397     const css::uno::Reference < css::frame::XFrame2 >&
getFrame() const398                             getFrame() const { return xFrame; }
399 
SetSelectHdl(const Link<const OString &,void> & rLink)400     void                    SetSelectHdl(const Link<const OString&, void>& rLink) { xToolBox->connect_clicked(rLink); }
401     void                    ToggleIndex( bool bOn );
402     void                    SelectSearchText( const OUString& rSearchText, bool _bIsFullWordSearch );
403     void                    SetPageStyleHeaderOff() const;
GetToolBox()404     weld::Toolbar&          GetToolBox() { return *xToolBox; }
405     void                    CloseFrame();
406     void                    DoSearch();
407 };
408 
409 // class SfxHelpWindow_Impl ----------------------------------------------
410 
411 class HelpInterceptor_Impl;
412 class HelpListener_Impl;
413 class SfxHelpWindow_Impl : public ResizableDockingWindow
414 {
415 private:
416 friend class SfxHelpIndexWindow_Impl;
417 
418     std::unique_ptr<weld::Builder> m_xBuilder;
419     std::unique_ptr<weld::Paned> m_xContainer;
420     std::unique_ptr<weld::Container> m_xHelpPaneWindow;
421     std::unique_ptr<weld::Container> m_xHelpTextWindow;
422     css::uno::Reference<css::awt::XWindow> m_xHelpTextXWindow;
423 
424     css::uno::Reference < css::awt::XWindow >
425                                 xWindow;
426     css::uno::Reference < css::frame::XFrame2 >
427                                 xFrame;
428 
429     std::unique_ptr<SfxHelpIndexWindow_Impl> xIndexWin;
430     VclPtr<SfxHelpTextWindow_Impl>     pTextWin;
431     HelpInterceptor_Impl*       pHelpInterceptor;
432     rtl::Reference<HelpListener_Impl> pHelpListener;
433 
434     bool                bIndex;
435     bool                bGrabFocusToToolBox;
436     bool                bSplit;
437     int                 nWidth;
438     int                 nIndexSize;
439     Point               aWinPos;
440     Size                aWinSize;
441     OUString            sTitle;
442 
443     virtual void        GetFocus() override;
444 
445     void                MakeLayout();
446     void                LoadConfig();
447     void                SaveConfig();
448     void                ShowStartPage();
449     void                Split();
450 
451     DECL_LINK(SelectHdl, const OString&, void);
452     DECL_LINK(OpenHdl, LinkParamNone*, void);
453     DECL_LINK(SelectFactoryHdl, SfxHelpIndexWindow_Impl*, void);
454     DECL_LINK(ChangeHdl, HelpListener_Impl&, void);
455     DECL_LINK(ResizeHdl, const Size&, void);
456 
457 public:
458     SfxHelpWindow_Impl( const css::uno::Reference < css::frame::XFrame2 >& rFrame,
459                         vcl::Window* pParent );
460     virtual ~SfxHelpWindow_Impl() override;
461     virtual void dispose() override;
462 
463     virtual bool        PreNotify( NotifyEvent& rNEvt ) override;
464 
465     void                setContainerWindow( const css::uno::Reference < css::awt::XWindow >& xWin );
466     css::uno::Reference < css::frame::XFrame2 > const &
getTextFrame() const467                         getTextFrame() const { return pTextWin->getFrame(); }
468 
469     void                SetFactory( const OUString& rFactory );
470     void                SetHelpURL( const OUString& rURL );
471     void                DoAction(std::string_view rAction);
472     void                CloseWindow();
473 
GetContainer()474     weld::Container*    GetContainer() { return m_xHelpTextWindow.get(); }
475 
476     void                UpdateToolbox();
OpenKeyword(const OUString & rKeyword)477     void                OpenKeyword( const OUString& rKeyword ) { xIndexWin->OpenKeyword( rKeyword ); }
478 
479     bool                HasHistoryPredecessor() const;      // forward to interceptor
480     bool                HasHistorySuccessor() const;        // forward to interceptor
481 
482     void                openDone(const OUString& sURL    ,
483                                        bool         bSuccess);
484 
485     static OUString     buildHelpURL(std::u16string_view sFactory        ,
486                                      std::u16string_view sContent        ,
487                                      std::u16string_view sAnchor);
488 
489     void                loadHelpContent(const OUString& sHelpURL                ,
490                                               bool         bAddToHistory = true);
491 };
492 
493 class SfxAddHelpBookmarkDialog_Impl : public weld::GenericDialogController
494 {
495 private:
496     std::unique_ptr<weld::Entry> m_xTitleED;
497     std::unique_ptr<weld::Label> m_xAltTitle;
498 public:
499     SfxAddHelpBookmarkDialog_Impl(weld::Widget* pParent, bool bRename);
500 
501     void SetTitle( const OUString& rTitle );
GetTitle() const502     OUString GetTitle() const { return m_xTitleED->get_text(); }
503 };
504 
505 /// Appends ?Language=xy&System=abc to the help URL in rURL
506 void AppendConfigToken(OUStringBuffer& rURL, bool bQuestionMark);
507 
508 #endif // INCLUDED_SFX2_SOURCE_APPL_NEWHELP_HXX
509 
510 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
511