1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*f6e50924SAndrew Rist * distributed with this work for additional information
6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at
10*f6e50924SAndrew Rist *
11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist *
13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the
17*f6e50924SAndrew Rist * specific language governing permissions and limitations
18*f6e50924SAndrew Rist * under the License.
19*f6e50924SAndrew Rist *
20*f6e50924SAndrew Rist *************************************************************/
21*f6e50924SAndrew Rist
22*f6e50924SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <sfx2/app.hxx>
27cdf0e10cSrcweir #include <sfx2/tbxctrl.hxx>
28cdf0e10cSrcweir #include <sfx2/bindings.hxx>
29cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
30cdf0e10cSrcweir #include <tools/gen.hxx>
31cdf0e10cSrcweir #include <svl/intitem.hxx>
32cdf0e10cSrcweir #include <sot/exchange.hxx>
33cdf0e10cSrcweir #include <svl/eitem.hxx>
34cdf0e10cSrcweir #include <vcl/toolbox.hxx>
35cdf0e10cSrcweir #include <svx/clipboardctl.hxx>
36cdf0e10cSrcweir #include <svx/clipfmtitem.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include <svtools/insdlg.hxx>
39cdf0e10cSrcweir #include <svx/svxids.hrc>
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir using namespace ::com::sun::star::beans;
43cdf0e10cSrcweir
44cdf0e10cSrcweir /////////////////////////////////////////////////////////////////
45cdf0e10cSrcweir
46cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL( SvxClipBoardControl, SfxVoidItem /*SfxUInt16Item*/ );
47cdf0e10cSrcweir
48cdf0e10cSrcweir
SvxClipBoardControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)49cdf0e10cSrcweir SvxClipBoardControl::SvxClipBoardControl(
50cdf0e10cSrcweir sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
51cdf0e10cSrcweir
52cdf0e10cSrcweir SfxToolBoxControl( nSlotId, nId, rTbx ),
53cdf0e10cSrcweir pClipboardFmtItem( 0 ),
54cdf0e10cSrcweir pPopup (0),
55cdf0e10cSrcweir nItemId (nId),
56cdf0e10cSrcweir bDisabled( sal_False )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ClipboardFormatItems" )));
59cdf0e10cSrcweir ToolBox& rBox = GetToolBox();
60cdf0e10cSrcweir rBox.SetItemBits( nId, TIB_DROPDOWN | rBox.GetItemBits( nId ) );
61cdf0e10cSrcweir rBox.Invalidate();
62cdf0e10cSrcweir }
63cdf0e10cSrcweir
64cdf0e10cSrcweir
~SvxClipBoardControl()65cdf0e10cSrcweir SvxClipBoardControl::~SvxClipBoardControl()
66cdf0e10cSrcweir {
67cdf0e10cSrcweir DelPopup();
68cdf0e10cSrcweir delete pClipboardFmtItem;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
71cdf0e10cSrcweir
CreatePopupWindow()72cdf0e10cSrcweir SfxPopupWindow* SvxClipBoardControl::CreatePopupWindow()
73cdf0e10cSrcweir {
74cdf0e10cSrcweir const SvxClipboardFmtItem* pFmtItem = PTR_CAST( SvxClipboardFmtItem, pClipboardFmtItem );
75cdf0e10cSrcweir if ( pFmtItem )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir if (pPopup)
78cdf0e10cSrcweir pPopup->Clear();
79cdf0e10cSrcweir else
80cdf0e10cSrcweir pPopup = new PopupMenu;
81cdf0e10cSrcweir
82cdf0e10cSrcweir sal_uInt16 nCount = pFmtItem->Count();
83cdf0e10cSrcweir for (sal_uInt16 i = 0; i < nCount; ++i)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir sal_uIntPtr nFmtID = pFmtItem->GetClipbrdFormatId( i );
86cdf0e10cSrcweir String aFmtStr( pFmtItem->GetClipbrdFormatName( i ) );
87cdf0e10cSrcweir if (!aFmtStr.Len())
88cdf0e10cSrcweir aFmtStr = SvPasteObjectHelper::GetSotFormatUIName( nFmtID );
89cdf0e10cSrcweir pPopup->InsertItem( (sal_uInt16)nFmtID, aFmtStr );
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir ToolBox& rBox = GetToolBox();
93cdf0e10cSrcweir sal_uInt16 nId = GetId();
94cdf0e10cSrcweir rBox.SetItemDown( nId, sal_True );
95cdf0e10cSrcweir
96cdf0e10cSrcweir pPopup->Execute( &rBox, rBox.GetItemRect( nId ),
97cdf0e10cSrcweir (rBox.GetAlign() == WINDOWALIGN_TOP || rBox.GetAlign() == WINDOWALIGN_BOTTOM) ?
98cdf0e10cSrcweir POPUPMENU_EXECUTE_DOWN : POPUPMENU_EXECUTE_RIGHT );
99cdf0e10cSrcweir
100cdf0e10cSrcweir rBox.SetItemDown( nId, sal_False );
101cdf0e10cSrcweir
102cdf0e10cSrcweir SfxUInt32Item aItem( SID_CLIPBOARD_FORMAT_ITEMS, pPopup->GetCurItemId() );
103cdf0e10cSrcweir
104cdf0e10cSrcweir Any a;
105cdf0e10cSrcweir Sequence< PropertyValue > aArgs( 1 );
106cdf0e10cSrcweir aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SelectedFormat" ));
107cdf0e10cSrcweir aItem.QueryValue( a );
108cdf0e10cSrcweir aArgs[0].Value = a;
109cdf0e10cSrcweir Dispatch( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ClipboardFormatItems" )),
110cdf0e10cSrcweir aArgs );
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir GetToolBox().EndSelection();
114cdf0e10cSrcweir DelPopup();
115cdf0e10cSrcweir return 0;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
118cdf0e10cSrcweir
GetPopupWindowType() const119cdf0e10cSrcweir SfxPopupWindowType SvxClipBoardControl::GetPopupWindowType() const
120cdf0e10cSrcweir {
121cdf0e10cSrcweir return SFX_POPUPWINDOW_ONTIMEOUT;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir
StateChanged(sal_uInt16 nSID,SfxItemState eState,const SfxPoolItem * pState)125cdf0e10cSrcweir void SvxClipBoardControl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir if ( SID_CLIPBOARD_FORMAT_ITEMS == nSID )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir DELETEZ( pClipboardFmtItem );
130cdf0e10cSrcweir if ( eState >= SFX_ITEM_AVAILABLE )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir pClipboardFmtItem = pState->Clone();
133cdf0e10cSrcweir GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | TIB_DROPDOWN );
134cdf0e10cSrcweir }
135cdf0e10cSrcweir else if ( !bDisabled )
136cdf0e10cSrcweir GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~TIB_DROPDOWN );
137cdf0e10cSrcweir GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir else
140cdf0e10cSrcweir {
141cdf0e10cSrcweir // enable the item as a whole
142cdf0e10cSrcweir bDisabled = (GetItemState(pState) == SFX_ITEM_DISABLED);
143cdf0e10cSrcweir GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
144cdf0e10cSrcweir }
145cdf0e10cSrcweir }
146cdf0e10cSrcweir
147cdf0e10cSrcweir
DelPopup()148cdf0e10cSrcweir void SvxClipBoardControl::DelPopup()
149cdf0e10cSrcweir {
150cdf0e10cSrcweir if(pPopup)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir delete pPopup;
153cdf0e10cSrcweir pPopup = 0;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir }
156cdf0e10cSrcweir
157cdf0e10cSrcweir
158cdf0e10cSrcweir /////////////////////////////////////////////////////////////////
159cdf0e10cSrcweir
160