Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / mnuctrls / clipboardctl.cxx
blob70b2620565bf9959994ec390c62b19f51de8d9dd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <comphelper/propertyvalue.hxx>
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>
31 #include <svtools/insdlg.hxx>
32 #include <svx/svxids.hrc>
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::beans;
38 SFX_IMPL_TOOLBOX_CONTROL( SvxClipBoardControl, SfxVoidItem /*SfxUInt16Item*/ );
41 SvxClipBoardControl::SvxClipBoardControl(
42 sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox& rTbx ) :
44 SfxToolBoxControl( nSlotId, nId, rTbx ),
45 bDisabled( false )
47 addStatusListener( ".uno:ClipboardFormatItems");
48 ToolBox& rBox = GetToolBox();
49 rBox.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rBox.GetItemBits( nId ) );
50 rBox.Invalidate();
53 SvxClipBoardControl::~SvxClipBoardControl()
57 void SvxClipBoardControl::CreatePopupWindow()
59 const SvxClipboardFormatItem* pFmtItem = dynamic_cast<SvxClipboardFormatItem*>( pClipboardFmtItem.get() );
60 if ( pFmtItem )
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"));
65 sal_uInt16 nCount = pFmtItem->Count();
66 for (sal_uInt16 i = 0; i < nCount; ++i)
68 SotClipboardFormatId nFmtID = pFmtItem->GetClipbrdFormatId( i );
69 OUString aFmtStr( pFmtItem->GetClipbrdFormatName( i ) );
70 if (aFmtStr.isEmpty())
71 aFmtStr = SvPasteObjectHelper::GetSotFormatUIName( nFmtID );
72 xPopup->append(OUString::number(static_cast<sal_uInt32>(nFmtID)), aFmtStr);
75 ToolBox& rBox = GetToolBox();
76 ToolBoxItemId nId = GetId();
77 rBox.SetItemDown( nId, true );
79 ::tools::Rectangle aRect(rBox.GetItemRect(nId));
80 weld::Window* pParent = weld::GetPopupParent(rBox, aRect);
81 OUString sResult = xPopup->popup_at_rect(pParent, aRect);
83 rBox.SetItemDown( nId, false );
85 SfxUInt32Item aItem(SID_CLIPBOARD_FORMAT_ITEMS, sResult.toUInt32());
87 Any a;
88 aItem.QueryValue( a );
89 Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue("SelectedFormat", a) };
90 Dispatch( ".uno:ClipboardFormatItems",
91 aArgs );
94 GetToolBox().EndSelection();
97 void SvxClipBoardControl::StateChangedAtToolBoxControl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
99 if ( SID_CLIPBOARD_FORMAT_ITEMS == nSID )
101 pClipboardFmtItem.reset();
102 if ( eState >= SfxItemState::DEFAULT )
104 pClipboardFmtItem.reset( pState->Clone() );
105 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | ToolBoxItemBits::DROPDOWN );
107 else if ( !bDisabled )
108 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~ToolBoxItemBits::DROPDOWN );
109 GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) );
111 else
113 // enable the item as a whole
114 bDisabled = (GetItemState(pState) == SfxItemState::DISABLED);
115 GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SfxItemState::DISABLED) );
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */