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