Coverage Report

Created: 2026-02-14 09:37

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