1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sfx2/app.hxx>
21 #include <sfx2/tbxctrl.hxx>
22 #include <sfx2/bindings.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <svl/intitem.hxx>
25 #include <sot/exchange.hxx>
26 #include <svl/eitem.hxx>
27 #include <vcl/menu.hxx>
28 #include <vcl/toolbox.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
, sal_uInt16 nId
, ToolBox
& rTbx
) :
45 SfxToolBoxControl( nSlotId
, nId
, rTbx
),
49 addStatusListener( ".uno:ClipboardFormatItems");
50 ToolBox
& rBox
= GetToolBox();
51 rBox
.SetItemBits( nId
, ToolBoxItemBits::DROPDOWN
| rBox
.GetItemBits( nId
) );
56 SvxClipBoardControl::~SvxClipBoardControl()
62 VclPtr
<SfxPopupWindow
> SvxClipBoardControl::CreatePopupWindow()
64 const SvxClipboardFormatItem
* pFmtItem
= dynamic_cast<SvxClipboardFormatItem
*>( pClipboardFmtItem
.get() );
70 pPopup
= VclPtr
<PopupMenu
>::Create();
72 sal_uInt16 nCount
= pFmtItem
->Count();
73 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
75 SotClipboardFormatId nFmtID
= pFmtItem
->GetClipbrdFormatId( i
);
76 OUString
aFmtStr( pFmtItem
->GetClipbrdFormatName( i
) );
77 if (aFmtStr
.isEmpty())
78 aFmtStr
= SvPasteObjectHelper::GetSotFormatUIName( nFmtID
);
79 pPopup
->InsertItem( static_cast<sal_uInt16
>(nFmtID
), aFmtStr
);
82 ToolBox
& rBox
= GetToolBox();
83 sal_uInt16 nId
= GetId();
84 rBox
.SetItemDown( nId
, true );
86 pPopup
->Execute( &rBox
, rBox
.GetItemRect( nId
),
87 (rBox
.GetAlign() == WindowAlign::Top
|| rBox
.GetAlign() == WindowAlign::Bottom
) ?
88 PopupMenuFlags::ExecuteDown
: PopupMenuFlags::ExecuteRight
);
90 rBox
.SetItemDown( nId
, false );
92 SfxUInt32Item
aItem( SID_CLIPBOARD_FORMAT_ITEMS
, pPopup
->GetCurItemId() );
95 Sequence
< PropertyValue
> aArgs( 1 );
96 aArgs
[0].Name
= "SelectedFormat";
97 aItem
.QueryValue( a
);
99 Dispatch( ".uno:ClipboardFormatItems",
103 GetToolBox().EndSelection();
109 void SvxClipBoardControl::StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
111 if ( SID_CLIPBOARD_FORMAT_ITEMS
== nSID
)
113 pClipboardFmtItem
.reset();
114 if ( eState
>= SfxItemState::DEFAULT
)
116 pClipboardFmtItem
.reset( pState
->Clone() );
117 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | ToolBoxItemBits::DROPDOWN
);
119 else if ( !bDisabled
)
120 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~ToolBoxItemBits::DROPDOWN
);
121 GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) );
125 // enable the item as a whole
126 bDisabled
= (GetItemState(pState
) == SfxItemState::DISABLED
);
127 GetToolBox().EnableItem( GetId(), (GetItemState(pState
) != SfxItemState::DISABLED
) );
132 void SvxClipBoardControl::DelPopup()
136 pPopup
.disposeAndClear();
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */