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/menu.hxx>
23 #include <vcl/toolbox.hxx>
24 #include <svx/clipboardctl.hxx>
25 #include <svx/clipfmtitem.hxx>
26 
27 #include <svtools/insdlg.hxx>
28 #include <svx/svxids.hrc>
29 
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::beans;
32 
33 
35 
36 
38  sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
39 
40  SfxToolBoxControl( nSlotId, nId, rTbx ),
41  pPopup( nullptr ),
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 
50 
52 {
53  DelPopup();
54 }
55 
57 {
58  const SvxClipboardFormatItem* pFmtItem = dynamic_cast<SvxClipboardFormatItem*>( pClipboardFmtItem.get() );
59  if ( pFmtItem )
60  {
61  if (pPopup)
62  pPopup->Clear();
63  else
65 
66  sal_uInt16 nCount = pFmtItem->Count();
67  for (sal_uInt16 i = 0; i < nCount; ++i)
68  {
69  SotClipboardFormatId nFmtID = pFmtItem->GetClipbrdFormatId( i );
70  OUString aFmtStr( pFmtItem->GetClipbrdFormatName( i ) );
71  if (aFmtStr.isEmpty())
72  aFmtStr = SvPasteObjectHelper::GetSotFormatUIName( nFmtID );
73  pPopup->InsertItem( static_cast<sal_uInt16>(nFmtID), aFmtStr );
74  }
75 
76  ToolBox& rBox = GetToolBox();
77  sal_uInt16 nId = GetId();
78  rBox.SetItemDown( nId, true );
79 
80  pPopup->Execute( &rBox, rBox.GetItemRect( nId ),
81  (rBox.GetAlign() == WindowAlign::Top || rBox.GetAlign() == WindowAlign::Bottom) ?
82  PopupMenuFlags::ExecuteDown : PopupMenuFlags::ExecuteRight );
83 
84  rBox.SetItemDown( nId, false );
85 
86  SfxUInt32Item aItem( SID_CLIPBOARD_FORMAT_ITEMS, pPopup->GetCurItemId() );
87 
88  Any a;
89  Sequence< PropertyValue > aArgs( 1 );
90  aArgs[0].Name = "SelectedFormat";
91  aItem.QueryValue( a );
92  aArgs[0].Value = a;
93  Dispatch( ".uno:ClipboardFormatItems",
94  aArgs );
95  }
96 
98  DelPopup();
99 }
100 
101 void SvxClipBoardControl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
102 {
103  if ( SID_CLIPBOARD_FORMAT_ITEMS == nSID )
104  {
105  pClipboardFmtItem.reset();
106  if ( eState >= SfxItemState::DEFAULT )
107  {
108  pClipboardFmtItem.reset( pState->Clone() );
109  GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | ToolBoxItemBits::DROPDOWN );
110  }
111  else if ( !bDisabled )
112  GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~ToolBoxItemBits::DROPDOWN );
113  GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) );
114  }
115  else
116  {
117  // enable the item as a whole
118  bDisabled = (GetItemState(pState) == SfxItemState::DISABLED);
119  GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SfxItemState::DISABLED) );
120  }
121 }
122 
123 
125 {
126  if(pPopup)
127  {
129  }
130 }
131 
132 
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SotClipboardFormatId GetClipbrdFormatId(sal_uInt16 nPos) const
void Clear()
OUString const & GetClipbrdFormatName(sal_uInt16 nPos) const
void CreatePopupWindow() override
ToolBox & GetToolBox() const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
ToolBoxItemBits GetItemBits(sal_uInt16 nItemId) const
sal_Int16 nId
sal_uInt16 Execute(vcl::Window *pWindow, const Point &rPopupPos)
virtual ~SvxClipBoardControl() override
sal_uInt16 Count() const
VclPtr< PopupMenu > pPopup
int nCount
SotClipboardFormatId
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
tools::Rectangle GetItemRect(sal_uInt16 nItemId)
static OUString GetSotFormatUIName(SotClipboardFormatId nId)
sal_uInt16 GetCurItemId() const
void EndSelection()
int i
uno_Any a
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
void SetItemBits(sal_uInt16 nItemId, ToolBoxItemBits nBits)
void SetItemDown(sal_uInt16 nItemId, bool bDown)
static SfxItemState GetItemState(const SfxPoolItem *pState)
void InsertItem(sal_uInt16 nItemId, const OUString &rStr, MenuItemBits nItemBits=MenuItemBits::NONE, const OString &rIdent=OString(), sal_uInt16 nPos=MENU_APPEND)
SfxItemState
SFX_IMPL_TOOLBOX_CONTROL(SvxClipBoardControl, SfxVoidItem)
unsigned short GetId() const
WindowAlign GetAlign() const
static VclPtr< reference_type > Create(Arg &&...arg)
std::unique_ptr< SfxPoolItem > pClipboardFmtItem
SvxClipBoardControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)