Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/ribbar/workctrl.cxx
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
20
#include <sal/config.h>
21
22
#include <i18nutil/unicode.hxx>
23
#include <sfx2/dispatch.hxx>
24
#include <sfx2/bindings.hxx>
25
#include <swmodule.hxx>
26
#include <utility>
27
#include <view.hxx>
28
#include <initui.hxx>
29
#include <docsh.hxx>
30
#include <gloshdl.hxx>
31
#include <gloslst.hxx>
32
#include <workctrl.hxx>
33
#include <strings.hrc>
34
#include <cmdid.h>
35
#include <helpids.h>
36
#include <wrtsh.hxx>
37
#include <comphelper/unique_unlock.hxx>
38
#include <cppuhelper/queryinterface.hxx>
39
#include <cppuhelper/supportsservice.hxx>
40
#include <svl/voiditem.hxx>
41
#include <vcl/event.hxx>
42
#include <vcl/menu.hxx>
43
#include <vcl/settings.hxx>
44
#include <vcl/weld/Entry.hxx>
45
#include <rtl/ustring.hxx>
46
#include <swabstdlg.hxx>
47
#include <sfx2/zoomitem.hxx>
48
#include <vcl/svapp.hxx>
49
#include <vcl/weld/Builder.hxx>
50
#include <vcl/weld/Toolbar.hxx>
51
#include <vcl/weld/TransportAsXWindow.hxx>
52
#include <svx/dialmgr.hxx>
53
#include <svx/strings.hrc>
54
#include <bitmaps.hlst>
55
#include <toolkit/helper/vclunohelper.hxx>
56
#include <com/sun/star/frame/XFrame.hpp>
57
58
#include <sfx2/viewfrm.hxx>
59
60
// Size check
61
#define NAVI_ENTRIES 22
62
63
using namespace ::com::sun::star;
64
using namespace ::com::sun::star::uno;
65
using namespace ::com::sun::star::beans;
66
using namespace ::com::sun::star::frame;
67
68
SFX_IMPL_TOOLBOX_CONTROL( SwTbxAutoTextCtrl, SfxVoidItem );
69
70
SwTbxAutoTextCtrl::SwTbxAutoTextCtrl(
71
    sal_uInt16 nSlotId,
72
    ToolBoxItemId nId,
73
    ToolBox& rTbx ) :
74
0
    SfxToolBoxControl( nSlotId, nId, rTbx )
75
0
{
76
0
    rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
77
0
}
Unexecuted instantiation: SwTbxAutoTextCtrl::SwTbxAutoTextCtrl(unsigned short, o3tl::strong_int<unsigned short, ToolBoxItemIdTag>, ToolBox&)
Unexecuted instantiation: SwTbxAutoTextCtrl::SwTbxAutoTextCtrl(unsigned short, o3tl::strong_int<unsigned short, ToolBoxItemIdTag>, ToolBox&)
78
79
SwTbxAutoTextCtrl::~SwTbxAutoTextCtrl()
80
0
{
81
0
}
82
83
void SwTbxAutoTextCtrl::CreatePopupWindow()
84
0
{
85
0
    SwView* pView = ::GetActiveView();
86
0
    if (pView
87
0
        && ((!pView->GetDocShell()->IsReadOnly() && !pView->GetWrtShell().HasReadonlySel())
88
0
            || pView->GetWrtShell().IsSectionEditableInReadonly()))
89
0
    {
90
0
        Link<Menu*,bool> aLnk = LINK(this, SwTbxAutoTextCtrl, PopupHdl);
91
92
0
        ScopedVclPtrInstance<PopupMenu> pPopup;
93
0
        SwGlossaryList* pGlossaryList = ::GetGlossaryList();
94
0
        const size_t nGroupCount = pGlossaryList->GetGroupCount();
95
0
        o3tl::sorted_vector<OUString> titles;
96
0
        for(size_t i = 1; i <= nGroupCount; ++i)
97
0
        {
98
0
            OUString sTitle = pGlossaryList->GetGroupTitle(i - 1);
99
0
            if (sTitle == "My AutoText")
100
0
                sTitle = SwResId(STR_MY_AUTOTEXT);
101
0
            const sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i -1);
102
0
            auto const [it, _] = titles.insert(sTitle);
103
0
            size_t const menuIndex(::std::distance(titles.begin(), it));
104
0
            if(nBlockCount)
105
0
            {
106
0
                sal_uInt16 nIndex = o3tl::narrowing<sal_uInt16>(100*i);
107
                // but insert without extension
108
0
                pPopup->InsertItem(i, sTitle, MenuItemBits::NONE, {}, menuIndex);
109
0
                VclPtrInstance<PopupMenu> pSub;
110
0
                pSub->SetSelectHdl(aLnk);
111
0
                pPopup->SetPopupMenu(i, pSub);
112
0
                for(sal_uInt16 j = 0; j < nBlockCount; j++)
113
0
                {
114
0
                    OUString sLongName(pGlossaryList->GetBlockLongName(i - 1, j));
115
0
                    OUString sShortName(pGlossaryList->GetBlockShortName(i - 1, j));
116
117
0
                    OUString sEntry = sShortName + " - " + sLongName;
118
0
                    pSub->InsertItem(++nIndex, sEntry);
119
0
                }
120
0
            }
121
0
        }
122
123
0
        ToolBox* pToolBox = &GetToolBox();
124
0
        ToolBoxItemId nId = GetId();
125
0
        pToolBox->SetItemDown( nId, true );
126
127
0
        pPopup->Execute( pToolBox, pToolBox->GetItemRect( nId ),
128
0
            (pToolBox->GetAlign() == WindowAlign::Top || pToolBox->GetAlign() == WindowAlign::Bottom) ?
129
0
                PopupMenuFlags::ExecuteDown : PopupMenuFlags::ExecuteRight );
130
131
0
        pToolBox->SetItemDown( nId, false );
132
0
    }
133
0
    GetToolBox().EndSelection();
134
0
}
135
136
void SwTbxAutoTextCtrl::StateChangedAtToolBoxControl( sal_uInt16,
137
                                              SfxItemState,
138
                                              const SfxPoolItem* pState )
139
0
{
140
0
    GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SfxItemState::DISABLED) );
141
0
}
142
143
IMPL_STATIC_LINK(SwTbxAutoTextCtrl, PopupHdl, Menu*, pMenu, bool)
144
0
{
145
0
    sal_uInt16 nId = pMenu->GetCurItemId();
146
147
0
    sal_uInt16 nBlock = nId / 100;
148
149
0
    SwGlossaryList* pGlossaryList = ::GetGlossaryList();
150
0
    OUString sGroup = pGlossaryList->GetGroupName(nBlock - 1);
151
0
    OUString sShortName =
152
0
        pGlossaryList->GetBlockShortName(nBlock - 1, nId - (100 * nBlock) - 1);
153
154
0
    if (SwView* pView = GetActiveView())
155
0
    {
156
0
        SwGlossaryHdl* pGlosHdl = pView->GetGlosHdl();
157
0
        SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
158
0
        ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
159
0
        if ( fnSetActGroup )
160
0
            (*fnSetActGroup)( sGroup );
161
0
        pGlosHdl->SetCurGroup(sGroup, true);
162
0
        pGlosHdl->InsertGlossary(sShortName);
163
0
    }
164
165
0
    return false;
166
0
}
167
168
// Navigation-Popup
169
// determine the order of the toolbox items
170
const sal_uInt16 aNavigationInsertIds[ NAVI_ENTRIES ] =
171
{
172
    NID_TBL,
173
    NID_FRM,
174
    NID_GRF,
175
    NID_OLE,
176
    NID_PGE,
177
    NID_OUTL,
178
    NID_MARK,
179
    NID_DRW,
180
    NID_CTRL,
181
    NID_REG,
182
    NID_BKM,
183
    NID_SEL,
184
    NID_FTN,
185
    NID_POSTIT,
186
    NID_SRCH_REP,
187
    NID_INDEX_ENTRY,
188
    NID_TABLE_FORMULA,
189
    NID_TABLE_FORMULA_ERROR,
190
    NID_RECENCY,
191
    NID_FIELD,
192
    NID_FIELD_BYTYPE,
193
    NID_HYPERLINK
194
};
195
196
OUString constexpr aNavigationImgIds[ NAVI_ENTRIES ] =
197
{
198
    RID_BMP_RIBBAR_TBL,
199
    RID_BMP_RIBBAR_FRM,
200
    RID_BMP_RIBBAR_GRF,
201
    RID_BMP_RIBBAR_OLE,
202
    RID_BMP_RIBBAR_PGE,
203
    RID_BMP_RIBBAR_OUTL,
204
    RID_BMP_RIBBAR_MARK,
205
    RID_BMP_RIBBAR_DRW,
206
    RID_BMP_RIBBAR_CTRL,
207
    RID_BMP_RIBBAR_REG,
208
    RID_BMP_RIBBAR_BKM,
209
    RID_BMP_RIBBAR_SEL,
210
    RID_BMP_RIBBAR_FTN,
211
    RID_BMP_RIBBAR_POSTIT,
212
    RID_BMP_RIBBAR_REP,
213
    RID_BMP_RIBBAR_ENTRY,
214
    RID_BMP_RIBBAR_FORMULA,
215
    RID_BMP_RIBBAR_ERROR,
216
    RID_BMP_RIBBAR_RECENCY,
217
    RID_BMP_RIBBAR_FIELD,
218
    RID_BMP_RIBBAR_FIELD_BYTYPE,
219
    RID_BMP_RIBBAR_HYPERLINK
220
};
221
222
const TranslateId aNavigationStrIds[ NAVI_ENTRIES ] =
223
{
224
    STR_CONTENT_TYPE_TABLE,
225
    STR_CONTENT_TYPE_FRAME,
226
    STR_CONTENT_TYPE_GRAPHIC,
227
    STR_CONTENT_TYPE_OLE,
228
    ST_PGE,
229
    STR_CONTENT_TYPE_OUTLINE,
230
    ST_MARK,
231
    STR_CONTENT_TYPE_DRAWOBJECT,
232
    ST_CTRL,
233
    STR_CONTENT_TYPE_REGION,
234
    STR_CONTENT_TYPE_BOOKMARK,
235
    ST_SEL,
236
    STR_CONTENT_TYPE_FOOTNOTE,
237
    STR_CONTENT_TYPE_POSTIT,
238
    ST_SRCH_REP,
239
    STR_CONTENT_TYPE_INDEX,
240
    ST_TABLE_FORMULA,
241
    ST_TABLE_FORMULA_ERROR,
242
    ST_RECENCY,
243
    STR_CONTENT_TYPE_TEXTFIELD,
244
    ST_FIELD_BYTYPE,
245
    STR_CONTENT_TYPE_URLFIELD
246
};
247
248
// these are global strings
249
const TranslateId STR_IMGBTN_ARY[] =
250
{
251
    STR_IMGBTN_TBL_DOWN,
252
    STR_IMGBTN_FRM_DOWN,
253
    STR_IMGBTN_PGE_DOWN,
254
    STR_IMGBTN_DRW_DOWN,
255
    STR_IMGBTN_CTRL_DOWN,
256
    STR_IMGBTN_REG_DOWN,
257
    STR_IMGBTN_BKM_DOWN,
258
    STR_IMGBTN_GRF_DOWN,
259
    STR_IMGBTN_OLE_DOWN,
260
    STR_IMGBTN_OUTL_DOWN,
261
    STR_IMGBTN_SEL_DOWN,
262
    STR_IMGBTN_FTN_DOWN,
263
    STR_IMGBTN_MARK_DOWN,
264
    STR_IMGBTN_POSTIT_DOWN,
265
    STR_IMGBTN_SRCH_REP_DOWN,
266
    STR_IMGBTN_INDEX_ENTRY_DOWN,
267
    STR_IMGBTN_TBLFML_DOWN,
268
    STR_IMGBTN_TBLFML_ERR_DOWN,
269
    STR_IMGBTN_RECENCY_DOWN,
270
    STR_IMGBTN_FIELD_DOWN,
271
    STR_IMGBTN_FIELD_BYTYPE_DOWN,
272
    STR_IMGBTN_HYPERLINK_DOWN,
273
    STR_IMGBTN_TBL_UP,
274
    STR_IMGBTN_FRM_UP,
275
    STR_IMGBTN_PGE_UP,
276
    STR_IMGBTN_DRW_UP,
277
    STR_IMGBTN_CTRL_UP,
278
    STR_IMGBTN_REG_UP,
279
    STR_IMGBTN_BKM_UP,
280
    STR_IMGBTN_GRF_UP,
281
    STR_IMGBTN_OLE_UP,
282
    STR_IMGBTN_OUTL_UP,
283
    STR_IMGBTN_SEL_UP,
284
    STR_IMGBTN_FTN_UP,
285
    STR_IMGBTN_MARK_UP,
286
    STR_IMGBTN_POSTIT_UP,
287
    STR_IMGBTN_SRCH_REP_UP,
288
    STR_IMGBTN_INDEX_ENTRY_UP,
289
    STR_IMGBTN_TBLFML_UP,
290
    STR_IMGBTN_TBLFML_ERR_UP,
291
    STR_IMGBTN_RECENCY_UP,
292
    STR_IMGBTN_FIELD_UP,
293
    STR_IMGBTN_FIELD_BYTYPE_UP,
294
    STR_IMGBTN_HYPERLINK_UP
295
};
296
297
static OUString lcl_GetScrollToolTip(bool bNext)
298
0
{
299
0
    sal_uInt16 nResId = SwView::GetMoveType();
300
0
    OUString sToolTip = SwResId(STR_IMGBTN_ARY[(!bNext ? NID_COUNT : 0) + nResId - NID_START]);
301
0
    if (nResId == NID_FIELD_BYTYPE)
302
0
    {
303
0
        OUString sFieldType;
304
0
        SwWrtShell* pWrtSh = GetActiveWrtShell();
305
0
        if (pWrtSh)
306
0
        {
307
0
            SwField* pCurField = pWrtSh->GetCurField(true);
308
0
            if (pCurField)
309
0
                sFieldType = SwFieldType::GetTypeStr(pCurField->GetTypeId());
310
0
        }
311
0
        if (!sFieldType.isEmpty())
312
0
            sToolTip = sToolTip.replaceFirst(u"%FIELDTYPE", sFieldType);
313
0
        else
314
0
            sToolTip = SwResId(SW_STR_NONE);
315
0
    }
316
0
    return sToolTip;
317
0
}
318
319
namespace {
320
321
class SwZoomBox_Impl final : public InterimItemWindow
322
{
323
    std::unique_ptr<weld::ComboBox> m_xWidget;
324
    sal_uInt16       m_nSlotId;
325
    bool             m_bRelease;
326
327
    DECL_LINK(SelectHdl, weld::ComboBox&, void);
328
    DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
329
    DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
330
    DECL_LINK(FocusOutHdl, weld::Widget&, void);
331
332
    void Select();
333
334
    void ReleaseFocus();
335
336
public:
337
    SwZoomBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot);
338
339
    virtual void dispose() override
340
0
    {
341
0
        m_xWidget.reset();
342
0
        InterimItemWindow::dispose();
343
0
    }
344
345
    void save_value()
346
0
    {
347
0
        m_xWidget->save_value();
348
0
    }
349
350
    void set_entry_text(const OUString& rText)
351
0
    {
352
0
        m_xWidget->set_entry_text(rText);
353
0
    }
354
355
    virtual ~SwZoomBox_Impl() override
356
0
    {
357
0
        disposeOnce();
358
0
    }
359
};
360
361
}
362
363
SwZoomBox_Impl::SwZoomBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot)
364
0
    : InterimItemWindow(pParent, u"modules/swriter/ui/zoombox.ui"_ustr, u"ZoomBox"_ustr)
365
0
    , m_xWidget(m_xBuilder->weld_combo_box(u"zoom"_ustr))
366
0
    , m_nSlotId(nSlot)
367
0
    , m_bRelease(true)
368
0
{
369
0
    InitControlBase(m_xWidget.get());
370
371
0
    m_xWidget->set_help_id(HID_PVIEW_ZOOM_LB);
372
0
    m_xWidget->set_entry_completion(false);
373
0
    m_xWidget->connect_changed(LINK(this, SwZoomBox_Impl, SelectHdl));
374
0
    m_xWidget->connect_key_press(LINK(this, SwZoomBox_Impl, KeyInputHdl));
375
0
    m_xWidget->connect_entry_activate(LINK(this, SwZoomBox_Impl, ActivateHdl));
376
0
    m_xWidget->connect_focus_out(LINK(this, SwZoomBox_Impl, FocusOutHdl));
377
378
0
    const TranslateId aZoomValues[] =
379
0
    { RID_SVXSTR_ZOOM_25 , RID_SVXSTR_ZOOM_50 ,
380
0
      RID_SVXSTR_ZOOM_75 , RID_SVXSTR_ZOOM_100 ,
381
0
      RID_SVXSTR_ZOOM_150 , RID_SVXSTR_ZOOM_200 ,
382
0
      RID_SVXSTR_ZOOM_WHOLE_PAGE, RID_SVXSTR_ZOOM_PAGE_WIDTH ,
383
0
      RID_SVXSTR_ZOOM_OPTIMAL_VIEW };
384
0
    for(const TranslateId& pZoomValue : aZoomValues)
385
0
    {
386
0
        OUString sEntry = SvxResId(pZoomValue);
387
0
        m_xWidget->append_text(sEntry);
388
0
    }
389
390
0
    int nWidth = m_xWidget->get_pixel_size(SvxResId(RID_SVXSTR_ZOOM_200)).Width();
391
0
    m_xWidget->set_entry_width_chars(std::ceil(nWidth / m_xWidget->get_approximate_digit_width()));
392
393
0
    SetSizePixel(m_xWidget->get_preferred_size());
394
0
}
395
396
IMPL_LINK(SwZoomBox_Impl, SelectHdl, weld::ComboBox&, rComboBox, void)
397
0
{
398
0
    if (rComboBox.changed_by_direct_pick())  // only when picked from the list
399
0
        Select();
400
0
}
401
402
IMPL_LINK_NOARG(SwZoomBox_Impl, ActivateHdl, weld::ComboBox&, bool)
403
0
{
404
0
    Select();
405
0
    return true;
406
0
}
407
408
void SwZoomBox_Impl::Select()
409
0
{
410
0
    if( FN_PREVIEW_ZOOM == m_nSlotId )
411
0
    {
412
0
        bool bNonNumeric = true;
413
414
0
        OUString sEntry = m_xWidget->get_active_text().replaceAll("%", "");
415
0
        SvxZoomItem aZoom(SvxZoomType::PERCENT,100);
416
0
        if(sEntry == SvxResId( RID_SVXSTR_ZOOM_PAGE_WIDTH ) )
417
0
            aZoom.SetType(SvxZoomType::PAGEWIDTH);
418
0
        else if(sEntry == SvxResId( RID_SVXSTR_ZOOM_OPTIMAL_VIEW ) )
419
0
            aZoom.SetType(SvxZoomType::OPTIMAL);
420
0
        else if(sEntry == SvxResId( RID_SVXSTR_ZOOM_WHOLE_PAGE) )
421
0
            aZoom.SetType(SvxZoomType::WHOLEPAGE);
422
0
        else
423
0
        {
424
0
            bNonNumeric = false;
425
426
0
            sal_uInt16 nZoom = o3tl::narrowing<sal_uInt16>(sEntry.toInt32());
427
0
            if(nZoom < MINZOOM)
428
0
                nZoom = MINZOOM;
429
0
            if(nZoom > MAXZOOM)
430
0
                nZoom = MAXZOOM;
431
0
            aZoom.SetValue(nZoom);
432
0
        }
433
434
0
        if (bNonNumeric)
435
0
        {
436
            // put old value back, in case it's effectively the same
437
            // as the picked option and no update to number comes
438
            // back from writer
439
0
            m_xWidget->set_entry_text(m_xWidget->get_saved_value());
440
0
        }
441
442
0
        if (SfxObjectShell* pCurrentShell = SfxObjectShell::Current())
443
0
        {
444
0
            pCurrentShell->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM,
445
0
                    SfxCallMode::ASYNCHRON, { &aZoom });
446
0
        }
447
0
    }
448
0
    ReleaseFocus();
449
0
}
450
451
IMPL_LINK(SwZoomBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
452
0
{
453
0
    bool bHandled = false;
454
455
0
    sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
456
457
0
    switch (nCode)
458
0
    {
459
0
        case KEY_TAB:
460
0
            m_bRelease = false;
461
0
            Select();
462
0
            break;
463
464
0
        case KEY_ESCAPE:
465
0
            m_xWidget->set_entry_text(m_xWidget->get_saved_value());
466
0
            ReleaseFocus();
467
0
            bHandled = true;
468
0
            break;
469
0
    }
470
471
0
    return bHandled || ChildKeyInput(rKEvt);
472
0
}
473
474
IMPL_LINK_NOARG(SwZoomBox_Impl, FocusOutHdl, weld::Widget&, void)
475
0
{
476
0
    if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidgets so double-check if none of those has focus
477
0
        m_xWidget->set_entry_text(m_xWidget->get_saved_value());
478
0
}
479
480
void SwZoomBox_Impl::ReleaseFocus()
481
0
{
482
0
    if ( !m_bRelease )
483
0
    {
484
0
        m_bRelease = true;
485
0
        return;
486
0
    }
487
0
    SfxViewShell* pCurSh = SfxViewShell::Current();
488
489
0
    if ( pCurSh )
490
0
    {
491
0
        vcl::Window* pShellWnd = pCurSh->GetWindow();
492
493
0
        if ( pShellWnd )
494
0
            pShellWnd->GrabFocus();
495
0
    }
496
0
}
497
498
SFX_IMPL_TOOLBOX_CONTROL( SwPreviewZoomControl, SfxUInt16Item);
499
500
SwPreviewZoomControl::SwPreviewZoomControl(
501
    sal_uInt16 nSlotId,
502
    ToolBoxItemId nId,
503
    ToolBox& rTbx) :
504
0
    SfxToolBoxControl( nSlotId, nId, rTbx )
505
0
{
506
0
}
Unexecuted instantiation: SwPreviewZoomControl::SwPreviewZoomControl(unsigned short, o3tl::strong_int<unsigned short, ToolBoxItemIdTag>, ToolBox&)
Unexecuted instantiation: SwPreviewZoomControl::SwPreviewZoomControl(unsigned short, o3tl::strong_int<unsigned short, ToolBoxItemIdTag>, ToolBox&)
507
508
SwPreviewZoomControl::~SwPreviewZoomControl()
509
0
{
510
0
}
511
512
void SwPreviewZoomControl::StateChangedAtToolBoxControl( sal_uInt16 /*nSID*/,
513
                                         SfxItemState eState,
514
                                         const SfxPoolItem* pState )
515
0
{
516
0
    ToolBoxItemId nId = GetId();
517
0
    GetToolBox().EnableItem( nId, (GetItemState(pState) != SfxItemState::DISABLED) );
518
0
    SwZoomBox_Impl* pBox = static_cast<SwZoomBox_Impl*>(GetToolBox().GetItemWindow( GetId() ));
519
0
    if(SfxItemState::DEFAULT <= eState)
520
0
    {
521
0
        OUString sZoom(unicode::formatPercent(static_cast<const SfxUInt16Item*>(pState)->GetValue(),
522
0
            Application::GetSettings().GetUILanguageTag()));
523
0
        pBox->set_entry_text(sZoom);
524
0
        pBox->save_value();
525
0
    }
526
0
}
527
528
VclPtr<InterimItemWindow> SwPreviewZoomControl::CreateItemWindow( vcl::Window *pParent )
529
0
{
530
0
    VclPtrInstance<SwZoomBox_Impl> pRet( pParent, GetSlotId() );
531
0
    return pRet.get();
532
0
}
533
534
namespace {
535
536
class SwJumpToSpecificBox_Impl final : public InterimItemWindow
537
{
538
    std::unique_ptr<weld::Entry> m_xWidget;
539
540
    sal_uInt16 m_nSlotId;
541
542
    DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
543
    DECL_LINK(SelectHdl, weld::Entry&, bool);
544
public:
545
    SwJumpToSpecificBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot);
546
    virtual void dispose() override
547
0
    {
548
0
        m_xWidget.reset();
549
0
        InterimItemWindow::dispose();
550
0
    }
551
    virtual ~SwJumpToSpecificBox_Impl() override
552
0
    {
553
0
        disposeOnce();
554
0
    }
555
};
556
557
}
558
559
IMPL_LINK(SwJumpToSpecificBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
560
0
{
561
0
    return ChildKeyInput(rKEvt);
562
0
}
563
564
SwJumpToSpecificBox_Impl::SwJumpToSpecificBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot)
565
0
    : InterimItemWindow(pParent, u"modules/swriter/ui/jumpposbox.ui"_ustr, u"JumpPosBox"_ustr)
566
0
    , m_xWidget(m_xBuilder->weld_entry(u"jumppos"_ustr))
567
0
    , m_nSlotId(nSlot)
568
0
{
569
0
    InitControlBase(m_xWidget.get());
570
571
0
    m_xWidget->connect_key_press(LINK(this, SwJumpToSpecificBox_Impl, KeyInputHdl));
572
0
    m_xWidget->connect_activate(LINK(this, SwJumpToSpecificBox_Impl, SelectHdl));
573
574
0
    SetSizePixel(m_xWidget->get_preferred_size());
575
0
}
576
577
IMPL_LINK_NOARG(SwJumpToSpecificBox_Impl, SelectHdl, weld::Entry&, bool)
578
0
{
579
0
    OUString sEntry(m_xWidget->get_text());
580
0
    SfxUInt16Item aPageNum(m_nSlotId);
581
0
    aPageNum.SetValue(o3tl::narrowing<sal_uInt16>(sEntry.toInt32()));
582
0
    if (SfxObjectShell* pCurrentShell = SfxObjectShell::Current())
583
0
    {
584
0
        pCurrentShell->GetDispatcher()->ExecuteList(m_nSlotId, SfxCallMode::ASYNCHRON,
585
0
                { &aPageNum });
586
0
    }
587
0
    return true;
588
0
}
589
590
SFX_IMPL_TOOLBOX_CONTROL( SwJumpToSpecificPageControl, SfxUInt16Item);
591
592
SwJumpToSpecificPageControl::SwJumpToSpecificPageControl(
593
    sal_uInt16 nSlotId,
594
    ToolBoxItemId nId,
595
    ToolBox& rTbx) :
596
0
    SfxToolBoxControl( nSlotId, nId, rTbx )
597
0
{}
Unexecuted instantiation: SwJumpToSpecificPageControl::SwJumpToSpecificPageControl(unsigned short, o3tl::strong_int<unsigned short, ToolBoxItemIdTag>, ToolBox&)
Unexecuted instantiation: SwJumpToSpecificPageControl::SwJumpToSpecificPageControl(unsigned short, o3tl::strong_int<unsigned short, ToolBoxItemIdTag>, ToolBox&)
598
599
SwJumpToSpecificPageControl::~SwJumpToSpecificPageControl()
600
0
{}
601
602
VclPtr<InterimItemWindow> SwJumpToSpecificPageControl::CreateItemWindow( vcl::Window *pParent )
603
0
{
604
0
    VclPtrInstance<SwJumpToSpecificBox_Impl> pRet( pParent, GetSlotId() );
605
0
    return pRet.get();
606
0
}
607
608
NavElementBox_Base::NavElementBox_Base(std::unique_ptr<weld::ComboBox> xComboBox,
609
                                       uno::Reference<frame::XFrame> xFrame)
610
0
    : m_xComboBox(std::move(xComboBox))
611
0
    ,m_xFrame(std::move(xFrame))
612
0
{
613
0
    m_xComboBox->set_size_request(100, -1);
614
615
0
    m_xComboBox->make_sorted();
616
0
    m_xComboBox->freeze();
617
0
    for (sal_uInt16 i = 0; i < NID_COUNT; i++)
618
0
         m_xComboBox->append(OUString::number(aNavigationInsertIds[i]),
619
0
                             SwResId(aNavigationStrIds[i]), aNavigationImgIds[i]);
620
0
    m_xComboBox->thaw();
621
622
0
    m_xComboBox->connect_changed(LINK(this, NavElementBox_Base, SelectHdl));
623
0
    m_xComboBox->connect_key_press(LINK(this, NavElementBox_Base, KeyInputHdl));
624
0
}
625
626
NavElementBox_Impl::NavElementBox_Impl(vcl::Window* pParent,
627
                                       const uno::Reference<frame::XFrame>& xFrame)
628
0
    : InterimItemWindow(pParent, u"modules/swriter/ui/combobox.ui"_ustr, u"ComboBox"_ustr)
629
0
    ,NavElementBox_Base(m_xBuilder->weld_combo_box(u"combobox"_ustr), xFrame)
630
0
{
631
0
    SetSizePixel(m_xContainer->get_preferred_size());
632
0
}
Unexecuted instantiation: NavElementBox_Impl::NavElementBox_Impl(vcl::Window*, com::sun::star::uno::Reference<com::sun::star::frame::XFrame> const&)
Unexecuted instantiation: NavElementBox_Impl::NavElementBox_Impl(vcl::Window*, com::sun::star::uno::Reference<com::sun::star::frame::XFrame> const&)
633
634
void NavElementBox_Base::ReleaseFocus_Impl()
635
0
{
636
0
    if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
637
0
        m_xFrame->getContainerWindow()->setFocus();
638
0
}
639
640
IMPL_STATIC_LINK(NavElementBox_Base, SelectHdl, weld::ComboBox&, rComboBox, void)
641
0
{
642
0
    if (!rComboBox.changed_by_direct_pick())  // only when picked from the list
643
0
        return;
644
0
    SfxViewFrame* pViewFrm = SfxViewFrame::Current();
645
0
    if (!pViewFrm)
646
0
        return;
647
0
    SfxUInt32Item aParam(FN_NAV_ELEMENT, rComboBox.get_active_id().toUInt32());
648
0
    const SfxPoolItem* aArgs[2];
649
0
    aArgs[0] = &aParam;
650
0
    aArgs[1] = nullptr;
651
0
    SfxDispatcher* pDispatch = pViewFrm->GetBindings().GetDispatcher();
652
0
    pDispatch->Execute(FN_NAV_ELEMENT, SfxCallMode::SYNCHRON, aArgs);
653
0
}
654
655
void NavElementBox_Base::UpdateBox()
656
0
{
657
0
    sal_uInt16 nMoveType = SwView::GetMoveType();
658
0
    for (size_t i = 0; i < SAL_N_ELEMENTS(aNavigationInsertIds); ++i)
659
0
    {
660
0
        if (nMoveType == aNavigationInsertIds[i])
661
0
        {
662
0
            m_xComboBox->set_active_text(SwResId(aNavigationStrIds[i]));
663
0
            break;
664
0
        }
665
0
    }
666
0
}
667
668
IMPL_LINK(NavElementBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool)
669
0
{
670
0
    return DoKeyInput(rKEvt);
671
0
}
672
673
bool NavElementBox_Base::DoKeyInput(const KeyEvent& /*rKEvt*/)
674
0
{
675
0
    return false;
676
0
}
677
678
bool NavElementBox_Impl::DoKeyInput(const KeyEvent& rKEvt)
679
0
{
680
0
    if (KEY_ESCAPE == rKEvt.GetKeyCode().GetCode())
681
0
    {
682
0
        ReleaseFocus_Impl();
683
0
        return true;
684
0
    }
685
0
    return ChildKeyInput(rKEvt);
686
0
}
687
688
NavElementToolBoxControl::NavElementToolBoxControl( const uno::Reference< uno::XComponentContext >& rxContext )
689
0
 : NavElementToolBoxControl_Base( rxContext,
690
0
                           uno::Reference< frame::XFrame >(),
691
0
                           ".uno:NavElement" ),
692
0
   m_pBox( nullptr )
693
0
{
694
0
}
Unexecuted instantiation: NavElementToolBoxControl::NavElementToolBoxControl(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&)
Unexecuted instantiation: NavElementToolBoxControl::NavElementToolBoxControl(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&)
695
696
// XServiceInfo
697
sal_Bool SAL_CALL NavElementToolBoxControl::supportsService( const OUString& ServiceName )
698
0
{
699
0
    return cppu::supportsService( this, ServiceName );
700
0
}
701
702
OUString SAL_CALL NavElementToolBoxControl::getImplementationName()
703
0
{
704
0
    return u"lo.writer.NavElementToolBoxController"_ustr;
705
0
}
706
707
uno::Sequence< OUString > SAL_CALL NavElementToolBoxControl::getSupportedServiceNames()
708
0
{
709
0
    return { u"com.sun.star.frame.ToolbarController"_ustr };
710
0
}
711
712
// WeakComponentImplHelperBase
713
void NavElementToolBoxControl::disposing(std::unique_lock<std::mutex>& rGuard)
714
0
{
715
0
    svt::ToolboxController::disposing(rGuard);
716
0
    comphelper::unique_unlock aUnlock(rGuard);
717
0
    SolarMutexGuard aSolarMutexGuard;
718
0
    m_xVclBox.disposeAndClear();
719
0
    m_xWeldBox.reset();
720
0
    m_pBox = nullptr;
721
0
}
722
723
// XStatusListener
724
void SAL_CALL NavElementToolBoxControl::statusChanged( const frame::FeatureStateEvent& rEvent )
725
0
{
726
0
    if (!m_pBox)
727
0
        return;
728
729
0
    SolarMutexGuard aSolarMutexGuard;
730
0
    if ( rEvent.FeatureURL.Path != "NavElement" )
731
0
        return;
732
733
0
    if ( rEvent.IsEnabled )
734
0
    {
735
0
        m_pBox->set_sensitive(true);
736
0
        m_pBox->UpdateBox();
737
0
    }
738
0
    else
739
0
        m_pBox->set_sensitive(true);
740
741
0
    if (SwView* pView = GetActiveView())
742
0
    {
743
0
        pView->GetViewFrame().GetBindings().Invalidate(FN_SCROLL_NEXT);
744
0
        pView->GetViewFrame().GetBindings().Invalidate(FN_SCROLL_PREV);
745
0
    }
746
0
}
747
748
// XToolbarController
749
void SAL_CALL NavElementToolBoxControl::execute( sal_Int16 /*KeyModifier*/ )
750
0
{
751
0
}
752
753
void SAL_CALL NavElementToolBoxControl::click()
754
0
{
755
0
}
756
757
void SAL_CALL NavElementToolBoxControl::doubleClick()
758
0
{
759
0
}
760
761
uno::Reference< awt::XWindow > SAL_CALL NavElementToolBoxControl::createPopupWindow()
762
0
{
763
0
    return uno::Reference< awt::XWindow >();
764
0
}
765
766
uno::Reference< awt::XWindow > SAL_CALL NavElementToolBoxControl::createItemWindow(
767
    const uno::Reference< awt::XWindow >& xParent )
768
0
{
769
0
    uno::Reference< awt::XWindow > xItemWindow;
770
771
0
    if (m_pBuilder)
772
0
    {
773
0
        SolarMutexGuard aSolarMutexGuard;
774
775
0
        std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box(u"NavElementWidget"_ustr));
776
777
0
        xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
778
779
0
        m_xWeldBox.reset(new NavElementBox_Base(std::move(xWidget), m_xFrame));
780
0
        m_pBox = m_xWeldBox.get();
781
0
    }
782
0
    else
783
0
    {
784
0
        VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
785
0
        if ( pParent )
786
0
        {
787
0
            SolarMutexGuard aSolarMutexGuard;
788
0
            m_xVclBox = VclPtr<NavElementBox_Impl>::Create( pParent, m_xFrame );
789
0
            m_pBox = m_xVclBox.get();
790
0
            xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox);
791
0
        }
792
0
    }
793
794
0
    return xItemWindow;
795
0
}
796
797
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
798
lo_writer_NavElementToolBoxController_get_implementation(
799
    css::uno::XComponentContext *rxContext,
800
    css::uno::Sequence<css::uno::Any> const &)
801
0
{
802
0
    return cppu::acquire( new NavElementToolBoxControl( rxContext ) );
803
0
}
804
805
namespace {
806
807
typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> PrevNextScrollToolboxController_Base;
808
class PrevNextScrollToolboxController : public PrevNextScrollToolboxController_Base
809
{
810
public:
811
    enum Type { PREVIOUS, NEXT };
812
813
    PrevNextScrollToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext, Type eType );
814
815
    // XServiceInfo
816
    virtual OUString SAL_CALL getImplementationName() override;
817
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
818
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
819
820
    // XStatusListener
821
    virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
822
823
private:
824
    Type                     meType;
825
};
826
827
}
828
829
PrevNextScrollToolboxController::PrevNextScrollToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext, Type eType )
830
0
    : PrevNextScrollToolboxController_Base( rxContext,
831
0
            css::uno::Reference< css::frame::XFrame >(),
832
0
            (eType == PREVIOUS) ? u".uno:ScrollToPrevious"_ustr: u".uno:ScrollToNext"_ustr ),
833
0
      meType( eType )
834
0
{
835
0
    addStatusListener(u".uno:NavElement"_ustr);
836
0
}
837
838
// XServiceInfo
839
OUString SAL_CALL PrevNextScrollToolboxController::getImplementationName()
840
0
{
841
0
    return meType == PrevNextScrollToolboxController::PREVIOUS?
842
0
        u"lo.writer.PreviousScrollToolboxController"_ustr :
843
0
        u"lo.writer.NextScrollToolboxController"_ustr;
844
0
}
845
846
sal_Bool SAL_CALL PrevNextScrollToolboxController::supportsService( const OUString& ServiceName )
847
0
{
848
0
    return cppu::supportsService(this, ServiceName);
849
0
}
850
851
css::uno::Sequence< OUString > SAL_CALL PrevNextScrollToolboxController::getSupportedServiceNames()
852
0
{
853
0
    return { u"com.sun.star.frame.ToolbarController"_ustr };
854
0
}
855
856
// XStatusListener
857
void SAL_CALL PrevNextScrollToolboxController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
858
0
{
859
0
    if (rEvent.FeatureURL.Path == "NavElement")
860
0
    {
861
0
        if (m_pToolbar)
862
0
            m_pToolbar->set_item_tooltip_text(m_aCommandURL, lcl_GetScrollToolTip(meType != PrevNextScrollToolboxController::PREVIOUS));
863
0
        else
864
0
        {
865
0
            ToolBox* pToolBox = nullptr;
866
0
            ToolBoxItemId nId;
867
0
            if (getToolboxId(nId, &pToolBox))
868
0
                pToolBox->SetQuickHelpText(nId, lcl_GetScrollToolTip(meType != PrevNextScrollToolboxController::PREVIOUS));
869
0
        }
870
0
    }
871
0
    else if (rEvent.FeatureURL.Path == "ScrollToPrevious" || rEvent.FeatureURL.Path == "ScrollToNext")
872
0
    {
873
0
        if (m_pToolbar)
874
0
            m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled);
875
0
        else
876
0
        {
877
0
            ToolBox* pToolBox = nullptr;
878
0
            ToolBoxItemId nId;
879
0
            if (getToolboxId(nId, &pToolBox))
880
0
                pToolBox->EnableItem(nId, rEvent.IsEnabled);
881
0
        }
882
0
    }
883
0
}
884
885
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
886
lo_writer_PreviousScrollToolboxController_get_implementation(
887
    css::uno::XComponentContext *context,
888
    css::uno::Sequence<css::uno::Any> const &)
889
0
{
890
0
    return cppu::acquire( new PrevNextScrollToolboxController( context, PrevNextScrollToolboxController::PREVIOUS ) );
891
0
}
892
893
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
894
lo_writer_NextScrollToolboxController_get_implementation(
895
    css::uno::XComponentContext *context,
896
    css::uno::Sequence<css::uno::Any> const &)
897
0
{
898
0
    return cppu::acquire( new PrevNextScrollToolboxController( context, PrevNextScrollToolboxController::NEXT ) );
899
0
}
900
901
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */