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