/src/libreoffice/svx/source/mnuctrls/clipboardctl.cxx
Line | Count | Source |
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 <sal/config.h> |
21 | | |
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> |
31 | | |
32 | | #include <svtools/insdlg.hxx> |
33 | | #include <svx/svxids.hrc> |
34 | | |
35 | | using namespace ::com::sun::star::uno; |
36 | | using namespace ::com::sun::star::beans; |
37 | | |
38 | | |
39 | | SFX_IMPL_TOOLBOX_CONTROL( SvxClipBoardControl, SfxVoidItem /*SfxUInt16Item*/ ); |
40 | | |
41 | | |
42 | | SvxClipBoardControl::SvxClipBoardControl( |
43 | | sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox& rTbx ) : |
44 | | |
45 | 0 | SfxToolBoxControl( nSlotId, nId, rTbx ), |
46 | 0 | bDisabled( false ) |
47 | 0 | { |
48 | 0 | addStatusListener( u".uno:ClipboardFormatItems"_ustr); |
49 | 0 | ToolBox& rBox = GetToolBox(); |
50 | 0 | rBox.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rBox.GetItemBits( nId ) ); |
51 | 0 | rBox.Invalidate(); |
52 | 0 | } |
53 | | |
54 | | SvxClipBoardControl::~SvxClipBoardControl() |
55 | 0 | { |
56 | 0 | } |
57 | | |
58 | | void SvxClipBoardControl::CreatePopupWindow() |
59 | 0 | { |
60 | 0 | if ( pClipboardFmtItem ) |
61 | 0 | { |
62 | 0 | std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, u"svx/ui/clipboardmenu.ui"_ustr)); |
63 | 0 | std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu(u"menu"_ustr)); |
64 | |
|
65 | 0 | sal_uInt16 nCount = pClipboardFmtItem->Count(); |
66 | 0 | for (sal_uInt16 i = 0; i < nCount; ++i) |
67 | 0 | { |
68 | 0 | SotClipboardFormatId nFmtID = pClipboardFmtItem->GetClipbrdFormatId( i ); |
69 | 0 | OUString aFmtStr( pClipboardFmtItem->GetClipbrdFormatName( i ) ); |
70 | 0 | if (aFmtStr.isEmpty()) |
71 | 0 | aFmtStr = SvPasteObjectHelper::GetSotFormatUIName( nFmtID ); |
72 | 0 | xPopup->append(OUString::number(static_cast<sal_uInt32>(nFmtID)), aFmtStr); |
73 | 0 | } |
74 | |
|
75 | 0 | ToolBox& rBox = GetToolBox(); |
76 | 0 | ToolBoxItemId nId = GetId(); |
77 | 0 | rBox.SetItemDown( nId, true ); |
78 | |
|
79 | 0 | ::tools::Rectangle aRect(rBox.GetItemRect(nId)); |
80 | 0 | weld::Window* pParent = weld::GetPopupParent(rBox, aRect); |
81 | 0 | OUString sResult = xPopup->popup_at_rect(pParent, aRect); |
82 | |
|
83 | 0 | rBox.SetItemDown( nId, false ); |
84 | |
|
85 | 0 | SfxUInt32Item aItem(SID_CLIPBOARD_FORMAT_ITEMS, sResult.toUInt32()); |
86 | |
|
87 | 0 | Any a; |
88 | 0 | aItem.QueryValue( a ); |
89 | 0 | Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(u"SelectedFormat"_ustr, a) }; |
90 | 0 | Dispatch( u".uno:ClipboardFormatItems"_ustr, |
91 | 0 | aArgs ); |
92 | 0 | } |
93 | |
|
94 | 0 | GetToolBox().EndSelection(); |
95 | 0 | } |
96 | | |
97 | | void SvxClipBoardControl::StateChangedAtToolBoxControl( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) |
98 | 0 | { |
99 | 0 | if ( SID_CLIPBOARD_FORMAT_ITEMS == nSID ) |
100 | 0 | { |
101 | 0 | pClipboardFmtItem.reset(); |
102 | 0 | if ( eState >= SfxItemState::DEFAULT ) |
103 | 0 | { |
104 | 0 | pClipboardFmtItem.reset( static_cast<SvxClipboardFormatItem*>(pState->Clone()) ); |
105 | 0 | GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | ToolBoxItemBits::DROPDOWN ); |
106 | 0 | } |
107 | 0 | else if ( !bDisabled ) |
108 | 0 | GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~ToolBoxItemBits::DROPDOWN ); |
109 | 0 | GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) ); |
110 | 0 | } |
111 | 0 | else |
112 | 0 | { |
113 | | // enable the item as a whole |
114 | 0 | bDisabled = (GetItemState(pState) == SfxItemState::DISABLED); |
115 | 0 | GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SfxItemState::DISABLED) ); |
116 | 0 | } |
117 | 0 | } |
118 | | |
119 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |