LibreOffice Module svx (master) 1
clipboardctl.cxx
Go to the documentation of this file.
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
23#include <sfx2/tbxctrl.hxx>
24#include <svl/intitem.hxx>
25#include <vcl/svapp.hxx>
26#include <vcl/toolbox.hxx>
27#include <vcl/weldutils.hxx>
28#include <svx/clipboardctl.hxx>
29#include <svx/clipfmtitem.hxx>
30
31#include <svtools/insdlg.hxx>
32#include <svx/svxids.hrc>
33
34using namespace ::com::sun::star::uno;
35using namespace ::com::sun::star::beans;
36
37
39
40
42 sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox& rTbx ) :
43
44 SfxToolBoxControl( nSlotId, nId, rTbx ),
45 bDisabled( false )
46{
47 addStatusListener( ".uno:ClipboardFormatItems");
48 ToolBox& rBox = GetToolBox();
49 rBox.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rBox.GetItemBits( nId ) );
50 rBox.Invalidate();
51}
52
54{
55}
56
58{
59 const SvxClipboardFormatItem* pFmtItem = dynamic_cast<SvxClipboardFormatItem*>( pClipboardFmtItem.get() );
60 if ( pFmtItem )
61 {
62 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, "svx/ui/clipboardmenu.ui"));
63 std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu("menu"));
64
65 sal_uInt16 nCount = pFmtItem->Count();
66 for (sal_uInt16 i = 0; i < nCount; ++i)
67 {
68 SotClipboardFormatId nFmtID = pFmtItem->GetClipbrdFormatId( i );
69 OUString aFmtStr( pFmtItem->GetClipbrdFormatName( i ) );
70 if (aFmtStr.isEmpty())
72 xPopup->append(OUString::number(static_cast<sal_uInt32>(nFmtID)), aFmtStr);
73 }
74
75 ToolBox& rBox = GetToolBox();
77 rBox.SetItemDown( nId, true );
78
80 weld::Window* pParent = weld::GetPopupParent(rBox, aRect);
81 OUString sResult = xPopup->popup_at_rect(pParent, aRect);
82
83 rBox.SetItemDown( nId, false );
84
85 SfxUInt32Item aItem(SID_CLIPBOARD_FORMAT_ITEMS, sResult.toUInt32());
86
87 Any a;
88 aItem.QueryValue( a );
89 Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue("SelectedFormat", a) };
90 Dispatch( ".uno:ClipboardFormatItems",
91 aArgs );
92 }
93
95}
96
98{
99 if ( SID_CLIPBOARD_FORMAT_ITEMS == nSID )
100 {
101 pClipboardFmtItem.reset();
102 if ( eState >= SfxItemState::DEFAULT )
103 {
104 pClipboardFmtItem.reset( pState->Clone() );
105 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | ToolBoxItemBits::DROPDOWN );
106 }
107 else if ( !bDisabled )
108 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~ToolBoxItemBits::DROPDOWN );
109 GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) );
110 }
111 else
112 {
113 // enable the item as a whole
114 bDisabled = (GetItemState(pState) == SfxItemState::DISABLED);
115 GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SfxItemState::DISABLED) );
116 }
117}
118
119/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)
ToolBoxItemId GetId() const
ToolBox & GetToolBox() const
static SfxItemState GetItemState(const SfxPoolItem *pState)
static OUString GetSotFormatUIName(SotClipboardFormatId nId)
std::unique_ptr< SfxPoolItem > pClipboardFmtItem
SvxClipBoardControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
virtual ~SvxClipBoardControl() override
void CreatePopupWindow() override
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
OUString const & GetClipbrdFormatName(sal_uInt16 nPos) const
sal_uInt16 Count() const
SotClipboardFormatId GetClipbrdFormatId(sal_uInt16 nPos) const
void EndSelection()
void SetItemDown(ToolBoxItemId nItemId, bool bDown)
void EnableItem(ToolBoxItemId nItemId, bool bEnable=true)
tools::Rectangle GetItemRect(ToolBoxItemId nItemId)
ToolBoxItemBits GetItemBits(ToolBoxItemId nItemId) const
void SetItemBits(ToolBoxItemId nItemId, ToolBoxItemBits nBits)
void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
SFX_IMPL_TOOLBOX_CONTROL(SvxClipBoardControl, SfxVoidItem)
int nCount
SotClipboardFormatId
uno_Any a
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
int i
weld::Window * GetPopupParent(vcl::Window &rOutWin, tools::Rectangle &rRect)
sal_Int16 nId
SfxItemState