1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: clipboardctl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <sfx2/app.hxx>
34 #include <sfx2/tbxctrl.hxx>
35 #include <sfx2/bindings.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <tools/gen.hxx>
38 #include <svtools/intitem.hxx>
39 #include <sot/exchange.hxx>
40 #include <svtools/eitem.hxx>
41 #include <vcl/toolbox.hxx>
42 #include <clipboardctl.hxx>
43 #include <clipfmtitem.hxx>
45 #include <svtools/insdlg.hxx>
46 #include <svx/svxids.hrc>
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::beans
;
51 /////////////////////////////////////////////////////////////////
53 SFX_IMPL_TOOLBOX_CONTROL( SvxClipBoardControl
, SfxVoidItem
/*SfxUInt16Item*/ );
56 SvxClipBoardControl::SvxClipBoardControl(
57 USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
) :
59 SfxToolBoxControl( nSlotId
, nId
, rTbx
),
60 pClipboardFmtItem( 0 ),
65 addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ClipboardFormatItems" )));
66 ToolBox
& rBox
= GetToolBox();
67 rBox
.SetItemBits( nId
, TIB_DROPDOWN
| rBox
.GetItemBits( nId
) );
72 SvxClipBoardControl::~SvxClipBoardControl()
75 delete pClipboardFmtItem
;
79 SfxPopupWindow
* SvxClipBoardControl::CreatePopupWindow()
81 const SvxClipboardFmtItem
* pFmtItem
= PTR_CAST( SvxClipboardFmtItem
, pClipboardFmtItem
);
87 pPopup
= new PopupMenu
;
89 USHORT nCount
= pFmtItem
->Count();
90 for (USHORT i
= 0; i
< nCount
; ++i
)
92 ULONG nFmtID
= pFmtItem
->GetClipbrdFormatId( i
);
93 String
aFmtStr( pFmtItem
->GetClipbrdFormatName( i
) );
95 aFmtStr
= SvPasteObjectHelper::GetSotFormatUIName( nFmtID
);
96 pPopup
->InsertItem( (USHORT
)nFmtID
, aFmtStr
);
99 ToolBox
& rBox
= GetToolBox();
100 USHORT nId
= GetId();
101 rBox
.SetItemDown( nId
, TRUE
);
103 pPopup
->Execute( &rBox
, rBox
.GetItemRect( nId
),
104 (rBox
.GetAlign() == WINDOWALIGN_TOP
|| rBox
.GetAlign() == WINDOWALIGN_BOTTOM
) ?
105 POPUPMENU_EXECUTE_DOWN
: POPUPMENU_EXECUTE_RIGHT
);
107 rBox
.SetItemDown( nId
, FALSE
);
109 SfxUInt32Item
aItem( SID_CLIPBOARD_FORMAT_ITEMS
, pPopup
->GetCurItemId() );
112 Sequence
< PropertyValue
> aArgs( 1 );
113 aArgs
[0].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SelectedFormat" ));
114 aItem
.QueryValue( a
);
116 Dispatch( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ClipboardFormatItems" )),
120 GetToolBox().EndSelection();
126 SfxPopupWindowType
SvxClipBoardControl::GetPopupWindowType() const
128 return SFX_POPUPWINDOW_ONTIMEOUT
;
132 void SvxClipBoardControl::StateChanged( USHORT nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
134 if ( SID_CLIPBOARD_FORMAT_ITEMS
== nSID
)
136 DELETEZ( pClipboardFmtItem
);
137 if ( eState
>= SFX_ITEM_AVAILABLE
)
139 pClipboardFmtItem
= pState
->Clone();
140 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | TIB_DROPDOWN
);
142 else if ( !bDisabled
)
143 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~TIB_DROPDOWN
);
144 GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) );
148 // enable the item as a whole
149 bDisabled
= (GetItemState(pState
) == SFX_ITEM_DISABLED
);
150 GetToolBox().EnableItem( GetId(), (GetItemState(pState
) != SFX_ITEM_DISABLED
) );
155 void SvxClipBoardControl::DelPopup()
165 /////////////////////////////////////////////////////////////////