Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/mnuctrls/clipboardctl.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 <comphelper/propertyvalue.hxx>
23
#include <sfx2/tbxctrl.hxx>
24
#include <svl/intitem.hxx>
25
#include <svl/voiditem.hxx>
26
#include <vcl/svapp.hxx>
27
#include <vcl/toolbox.hxx>
28
#include <vcl/weld/Builder.hxx>
29
#include <vcl/weld/Menu.hxx>
30
#include <vcl/weld/Window.hxx>
31
#include <vcl/weld/weldutils.hxx>
32
#include <svx/clipboardctl.hxx>
33
#include <svx/clipfmtitem.hxx>
34
35
#include <svtools/insdlg.hxx>
36
#include <svx/svxids.hrc>
37
38
using namespace ::com::sun::star::uno;
39
using namespace ::com::sun::star::beans;
40
41
42
SFX_IMPL_TOOLBOX_CONTROL( SvxClipBoardControl, SfxVoidItem /*SfxUInt16Item*/ );
43
44
45
SvxClipBoardControl::SvxClipBoardControl(
46
        sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox& rTbx ) :
47
48
0
    SfxToolBoxControl( nSlotId, nId, rTbx ),
49
0
    bDisabled( false )
50
0
{
51
0
    addStatusListener( u".uno:ClipboardFormatItems"_ustr);
52
0
    ToolBox& rBox = GetToolBox();
53
0
    rBox.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rBox.GetItemBits( nId ) );
54
0
    rBox.Invalidate();
55
0
}
Unexecuted instantiation: SvxClipBoardControl::SvxClipBoardControl(unsigned short, o3tl::strong_int<unsigned short, ToolBoxItemIdTag>, ToolBox&)
Unexecuted instantiation: SvxClipBoardControl::SvxClipBoardControl(unsigned short, o3tl::strong_int<unsigned short, ToolBoxItemIdTag>, ToolBox&)
56
57
SvxClipBoardControl::~SvxClipBoardControl()
58
0
{
59
0
}
60
61
void SvxClipBoardControl::CreatePopupWindow()
62
0
{
63
0
    if ( pClipboardFmtItem )
64
0
    {
65
0
        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, u"svx/ui/clipboardmenu.ui"_ustr));
66
0
        std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu(u"menu"_ustr));
67
68
0
        sal_uInt16 nCount = pClipboardFmtItem->Count();
69
0
        for (sal_uInt16 i = 0;  i < nCount;  ++i)
70
0
        {
71
0
            SotClipboardFormatId nFmtID =  pClipboardFmtItem->GetClipbrdFormatId( i );
72
0
            OUString aFmtStr( pClipboardFmtItem->GetClipbrdFormatName( i ) );
73
0
            if (aFmtStr.isEmpty())
74
0
              aFmtStr = SvPasteObjectHelper::GetSotFormatUIName( nFmtID );
75
0
            xPopup->append(OUString::number(static_cast<sal_uInt32>(nFmtID)), aFmtStr);
76
0
        }
77
78
0
        ToolBox& rBox = GetToolBox();
79
0
        ToolBoxItemId nId = GetId();
80
0
        rBox.SetItemDown( nId, true );
81
82
0
        ::tools::Rectangle aRect(rBox.GetItemRect(nId));
83
0
        weld::Window* pParent = weld::GetPopupParent(rBox, aRect);
84
0
        OUString sResult = xPopup->popup_at_rect(pParent, aRect);
85
86
0
        rBox.SetItemDown( nId, false );
87
88
0
        SfxUInt32Item aItem(SID_CLIPBOARD_FORMAT_ITEMS, sResult.toUInt32());
89
90
0
        Any a;
91
0
        aItem.QueryValue( a );
92
0
        Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(u"SelectedFormat"_ustr, a) };
93
0
        Dispatch( u".uno:ClipboardFormatItems"_ustr,
94
0
                  aArgs );
95
0
    }
96
97
0
    GetToolBox().EndSelection();
98
0
}
99
100
void SvxClipBoardControl::StateChangedAtToolBoxControl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
101
0
{
102
0
    if ( SID_CLIPBOARD_FORMAT_ITEMS == nSID )
103
0
    {
104
0
        pClipboardFmtItem.reset();
105
0
        if ( eState >= SfxItemState::DEFAULT )
106
0
        {
107
0
            pClipboardFmtItem.reset( static_cast<SvxClipboardFormatItem*>(pState->Clone()) );
108
0
            GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | ToolBoxItemBits::DROPDOWN );
109
0
        }
110
0
        else if ( !bDisabled )
111
0
            GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~ToolBoxItemBits::DROPDOWN );
112
0
        GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) );
113
0
    }
114
0
    else
115
0
    {
116
        // enable the item as a whole
117
0
        bDisabled = (GetItemState(pState) == SfxItemState::DISABLED);
118
0
        GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SfxItemState::DISABLED) );
119
0
    }
120
0
}
121
122
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */