1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svx.hxx" 30 #include <sfx2/app.hxx> 31 #include <sfx2/tbxctrl.hxx> 32 #include <sfx2/bindings.hxx> 33 #include <sfx2/dispatch.hxx> 34 #include <tools/gen.hxx> 35 #include <svl/intitem.hxx> 36 #include <sot/exchange.hxx> 37 #include <svl/eitem.hxx> 38 #include <vcl/toolbox.hxx> 39 #include <svx/clipboardctl.hxx> 40 #include <svx/clipfmtitem.hxx> 41 42 #include <svtools/insdlg.hxx> 43 #include <svx/svxids.hrc> 44 45 using namespace ::com::sun::star::uno; 46 using namespace ::com::sun::star::beans; 47 48 ///////////////////////////////////////////////////////////////// 49 50 SFX_IMPL_TOOLBOX_CONTROL( SvxClipBoardControl, SfxVoidItem /*SfxUInt16Item*/ ); 51 52 53 SvxClipBoardControl::SvxClipBoardControl( 54 sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) : 55 56 SfxToolBoxControl( nSlotId, nId, rTbx ), 57 pClipboardFmtItem( 0 ), 58 pPopup (0), 59 nItemId (nId), 60 bDisabled( sal_False ) 61 { 62 addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ClipboardFormatItems" ))); 63 ToolBox& rBox = GetToolBox(); 64 rBox.SetItemBits( nId, TIB_DROPDOWN | rBox.GetItemBits( nId ) ); 65 rBox.Invalidate(); 66 } 67 68 69 SvxClipBoardControl::~SvxClipBoardControl() 70 { 71 DelPopup(); 72 delete pClipboardFmtItem; 73 } 74 75 76 SfxPopupWindow* SvxClipBoardControl::CreatePopupWindow() 77 { 78 const SvxClipboardFmtItem* pFmtItem = PTR_CAST( SvxClipboardFmtItem, pClipboardFmtItem ); 79 if ( pFmtItem ) 80 { 81 if (pPopup) 82 pPopup->Clear(); 83 else 84 pPopup = new PopupMenu; 85 86 sal_uInt16 nCount = pFmtItem->Count(); 87 for (sal_uInt16 i = 0; i < nCount; ++i) 88 { 89 sal_uIntPtr nFmtID = pFmtItem->GetClipbrdFormatId( i ); 90 String aFmtStr( pFmtItem->GetClipbrdFormatName( i ) ); 91 if (!aFmtStr.Len()) 92 aFmtStr = SvPasteObjectHelper::GetSotFormatUIName( nFmtID ); 93 pPopup->InsertItem( (sal_uInt16)nFmtID, aFmtStr ); 94 } 95 96 ToolBox& rBox = GetToolBox(); 97 sal_uInt16 nId = GetId(); 98 rBox.SetItemDown( nId, sal_True ); 99 100 pPopup->Execute( &rBox, rBox.GetItemRect( nId ), 101 (rBox.GetAlign() == WINDOWALIGN_TOP || rBox.GetAlign() == WINDOWALIGN_BOTTOM) ? 102 POPUPMENU_EXECUTE_DOWN : POPUPMENU_EXECUTE_RIGHT ); 103 104 rBox.SetItemDown( nId, sal_False ); 105 106 SfxUInt32Item aItem( SID_CLIPBOARD_FORMAT_ITEMS, pPopup->GetCurItemId() ); 107 108 Any a; 109 Sequence< PropertyValue > aArgs( 1 ); 110 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SelectedFormat" )); 111 aItem.QueryValue( a ); 112 aArgs[0].Value = a; 113 Dispatch( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ClipboardFormatItems" )), 114 aArgs ); 115 } 116 117 GetToolBox().EndSelection(); 118 DelPopup(); 119 return 0; 120 } 121 122 123 SfxPopupWindowType SvxClipBoardControl::GetPopupWindowType() const 124 { 125 return SFX_POPUPWINDOW_ONTIMEOUT; 126 } 127 128 129 void SvxClipBoardControl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) 130 { 131 if ( SID_CLIPBOARD_FORMAT_ITEMS == nSID ) 132 { 133 DELETEZ( pClipboardFmtItem ); 134 if ( eState >= SFX_ITEM_AVAILABLE ) 135 { 136 pClipboardFmtItem = pState->Clone(); 137 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) | TIB_DROPDOWN ); 138 } 139 else if ( !bDisabled ) 140 GetToolBox().SetItemBits( GetId(), GetToolBox().GetItemBits( GetId() ) & ~TIB_DROPDOWN ); 141 GetToolBox().Invalidate( GetToolBox().GetItemRect( GetId() ) ); 142 } 143 else 144 { 145 // enable the item as a whole 146 bDisabled = (GetItemState(pState) == SFX_ITEM_DISABLED); 147 GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) ); 148 } 149 } 150 151 152 void SvxClipBoardControl::DelPopup() 153 { 154 if(pPopup) 155 { 156 delete pPopup; 157 pPopup = 0; 158 } 159 } 160 161 162 ///////////////////////////////////////////////////////////////// 163 164