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/toolbox.hxx>
28 #include <svx/clipboardctl.hxx>
29 #include <svx/clipfmtitem.hxx>
31 #include <svtools/insdlg.hxx>
32 #include <svx/svxids.hrc>
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::beans
;
37 /////////////////////////////////////////////////////////////////
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
),
46 pClipboardFmtItem( 0 ),
48 bDisabled( sal_False
)
50 addStatusListener( OUString( ".uno:ClipboardFormatItems" ));
51 ToolBox
& rBox
= GetToolBox();
52 rBox
.SetItemBits( nId
, TIB_DROPDOWN
| rBox
.GetItemBits( nId
) );
57 SvxClipBoardControl::~SvxClipBoardControl()
60 delete pClipboardFmtItem
;
64 SfxPopupWindow
* SvxClipBoardControl::CreatePopupWindow()
66 const SvxClipboardFmtItem
* pFmtItem
= PTR_CAST( SvxClipboardFmtItem
, pClipboardFmtItem
);
72 pPopup
= new PopupMenu
;
74 sal_uInt16 nCount
= pFmtItem
->Count();
75 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
77 sal_uIntPtr nFmtID
= pFmtItem
->GetClipbrdFormatId( i
);
78 String
aFmtStr( pFmtItem
->GetClipbrdFormatName( i
) );
80 aFmtStr
= SvPasteObjectHelper::GetSotFormatUIName( nFmtID
);
81 pPopup
->InsertItem( (sal_uInt16
)nFmtID
, aFmtStr
);
84 ToolBox
& rBox
= GetToolBox();
85 sal_uInt16 nId
= GetId();
86 rBox
.SetItemDown( nId
, sal_True
);
88 pPopup
->Execute( &rBox
, rBox
.GetItemRect( nId
),
89 (rBox
.GetAlign() == WINDOWALIGN_TOP
|| rBox
.GetAlign() == WINDOWALIGN_BOTTOM
) ?
90 POPUPMENU_EXECUTE_DOWN
: POPUPMENU_EXECUTE_RIGHT
);
92 rBox
.SetItemDown( nId
, sal_False
);
94 SfxUInt32Item
aItem( SID_CLIPBOARD_FORMAT_ITEMS
, pPopup
->GetCurItemId() );
97 Sequence
< PropertyValue
> aArgs( 1 );
98 aArgs
[0].Name
= OUString( "SelectedFormat" );
99 aItem
.QueryValue( a
);
101 Dispatch( OUString( ".uno:ClipboardFormatItems" ),
105 GetToolBox().EndSelection();
111 SfxPopupWindowType
SvxClipBoardControl::GetPopupWindowType() const
113 return SFX_POPUPWINDOW_ONTIMEOUT
;
117 void SvxClipBoardControl::StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
119 if ( SID_CLIPBOARD_FORMAT_ITEMS
== nSID
)
121 DELETEZ( pClipboardFmtItem
);
122 if ( eState
>= SFX_ITEM_AVAILABLE
)
124 pClipboardFmtItem
= pState
->Clone();
125 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | TIB_DROPDOWN
);
127 else if ( !bDisabled
)
128 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~TIB_DROPDOWN
);
129 GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) );
133 // enable the item as a whole
134 bDisabled
= (GetItemState(pState
) == SFX_ITEM_DISABLED
);
135 GetToolBox().EnableItem( GetId(), (GetItemState(pState
) != SFX_ITEM_DISABLED
) );
140 void SvxClipBoardControl::DelPopup()
150 /////////////////////////////////////////////////////////////////
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */