tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / svx / source / mnuctrls / clipboardctl.cxx
blobb49ff207f8a9ad0f4a95e5ddd33d3aa6ffdda430
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 <svl/voiditem.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/toolbox.hxx>
28 #include <vcl/weldutils.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, ToolBoxItemId nId, ToolBox& rTbx ) :
45 SfxToolBoxControl( nSlotId, nId, rTbx ),
46 bDisabled( false )
48 addStatusListener( u".uno:ClipboardFormatItems"_ustr);
49 ToolBox& rBox = GetToolBox();
50 rBox.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rBox.GetItemBits( nId ) );
51 rBox.Invalidate();
54 SvxClipBoardControl::~SvxClipBoardControl()
58 void SvxClipBoardControl::CreatePopupWindow()
60 if ( pClipboardFmtItem )
62 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, u"svx/ui/clipboardmenu.ui"_ustr));
63 std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu(u"menu"_ustr));
65 sal_uInt16 nCount = pClipboardFmtItem->Count();
66 for (sal_uInt16 i = 0; i < nCount; ++i)
68 SotClipboardFormatId nFmtID = pClipboardFmtItem->GetClipbrdFormatId( i );
69 OUString aFmtStr( pClipboardFmtItem->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(u"SelectedFormat"_ustr, a) };
90 Dispatch( u".uno:ClipboardFormatItems"_ustr,
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( static_cast<SvxClipboardFormatItem*>(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: */