Coverage Report

Created: 2026-02-14 09:37

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