Bump version to 6.4-15
[LibreOffice.git] / svx / source / mnuctrls / clipboardctl.cxx
blobf24401e134aaaa53b9aaf8daa0f1accf0c37cd07
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 <sfx2/app.hxx>
21 #include <sfx2/tbxctrl.hxx>
22 #include <sfx2/bindings.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <svl/intitem.hxx>
25 #include <sot/exchange.hxx>
26 #include <svl/eitem.hxx>
27 #include <vcl/menu.hxx>
28 #include <vcl/toolbox.hxx>
29 #include <svx/clipboardctl.hxx>
30 #include <svx/clipfmtitem.hxx>
32 #include <svtools/insdlg.hxx>
33 #include <svx/svxids.hrc>
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
39 SFX_IMPL_TOOLBOX_CONTROL( SvxClipBoardControl, SfxVoidItem /*SfxUInt16Item*/ );
42 SvxClipBoardControl::SvxClipBoardControl(
43 sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
45 SfxToolBoxControl( nSlotId, nId, rTbx ),
46 pPopup( nullptr ),
47 bDisabled( false )
49 addStatusListener( ".uno:ClipboardFormatItems");
50 ToolBox& rBox = GetToolBox();
51 rBox.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rBox.GetItemBits( nId ) );
52 rBox.Invalidate();
56 SvxClipBoardControl::~SvxClipBoardControl()
58 DelPopup();
62 VclPtr<SfxPopupWindow> SvxClipBoardControl::CreatePopupWindow()
64 const SvxClipboardFormatItem* pFmtItem = dynamic_cast<SvxClipboardFormatItem*>( pClipboardFmtItem.get() );
65 if ( pFmtItem )
67 if (pPopup)
68 pPopup->Clear();
69 else
70 pPopup = VclPtr<PopupMenu>::Create();
72 sal_uInt16 nCount = pFmtItem->Count();
73 for (sal_uInt16 i = 0; i < nCount; ++i)
75 SotClipboardFormatId nFmtID = pFmtItem->GetClipbrdFormatId( i );
76 OUString aFmtStr( pFmtItem->GetClipbrdFormatName( i ) );
77 if (aFmtStr.isEmpty())
78 aFmtStr = SvPasteObjectHelper::GetSotFormatUIName( nFmtID );
79 pPopup->InsertItem( static_cast<sal_uInt16>(nFmtID), aFmtStr );
82 ToolBox& rBox = GetToolBox();
83 sal_uInt16 nId = GetId();
84 rBox.SetItemDown( nId, true );
86 pPopup->Execute( &rBox, rBox.GetItemRect( nId ),
87 (rBox.GetAlign() == WindowAlign::Top || rBox.GetAlign() == WindowAlign::Bottom) ?
88 PopupMenuFlags::ExecuteDown : PopupMenuFlags::ExecuteRight );
90 rBox.SetItemDown( nId, false );
92 SfxUInt32Item aItem( SID_CLIPBOARD_FORMAT_ITEMS, pPopup->GetCurItemId() );
94 Any a;
95 Sequence< PropertyValue > aArgs( 1 );
96 aArgs[0].Name = "SelectedFormat";
97 aItem.QueryValue( a );
98 aArgs[0].Value = a;
99 Dispatch( ".uno:ClipboardFormatItems",
100 aArgs );
103 GetToolBox().EndSelection();
104 DelPopup();
105 return nullptr;
109 void SvxClipBoardControl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
111 if ( SID_CLIPBOARD_FORMAT_ITEMS == nSID )
113 pClipboardFmtItem.reset();
114 if ( eState >= SfxItemState::DEFAULT )
116 pClipboardFmtItem.reset( pState->Clone() );
117 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | ToolBoxItemBits::DROPDOWN );
119 else if ( !bDisabled )
120 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~ToolBoxItemBits::DROPDOWN );
121 GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) );
123 else
125 // enable the item as a whole
126 bDisabled = (GetItemState(pState) == SfxItemState::DISABLED);
127 GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SfxItemState::DISABLED) );
132 void SvxClipBoardControl::DelPopup()
134 if(pPopup)
136 pPopup.disposeAndClear();
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */