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