1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // System - Includes ----------------------------------------------------- 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <string> // HACK: prevent conflict between STLPORT and Workshop headers 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir // INCLUDE --------------------------------------------------------------- 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <tools/shl.hxx> 40*cdf0e10cSrcweir #include <svl/intitem.hxx> 41*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 42*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 43*cdf0e10cSrcweir #include <sfx2/viewsh.hxx> 44*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 45*cdf0e10cSrcweir #include <sfx2/imagemgr.hxx> 46*cdf0e10cSrcweir #include <vcl/toolbox.hxx> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include "tbinsert.hxx" 49*cdf0e10cSrcweir #include "tbinsert.hrc" 50*cdf0e10cSrcweir #include "global.hxx" 51*cdf0e10cSrcweir #include "scmod.hxx" 52*cdf0e10cSrcweir #include "scresid.hxx" 53*cdf0e10cSrcweir #include "sc.hrc" 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir // ----------------------------------------------------------------------- 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL( ScTbxInsertCtrl, SfxUInt16Item); 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir //------------------------------------------------------------------ 60*cdf0e10cSrcweir // 61*cdf0e10cSrcweir // ToolBox - Controller 62*cdf0e10cSrcweir // 63*cdf0e10cSrcweir //------------------------------------------------------------------ 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir ScTbxInsertCtrl::ScTbxInsertCtrl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) : 66*cdf0e10cSrcweir SfxToolBoxControl( nSlotId, nId, rTbx ), 67*cdf0e10cSrcweir nLastSlotId(0) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) ); 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir __EXPORT ScTbxInsertCtrl::~ScTbxInsertCtrl() 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir void __EXPORT ScTbxInsertCtrl::StateChanged( sal_uInt16 /* nSID */, SfxItemState eState, 77*cdf0e10cSrcweir const SfxPoolItem* pState ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) ); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir if( eState == SFX_ITEM_AVAILABLE ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir const SfxUInt16Item* pItem = PTR_CAST( SfxUInt16Item, pState ); 85*cdf0e10cSrcweir if(pItem) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir nLastSlotId = pItem->GetValue(); 88*cdf0e10cSrcweir sal_uInt16 nImageId = nLastSlotId ? nLastSlotId : GetSlotId(); 89*cdf0e10cSrcweir rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 90*cdf0e10cSrcweir aSlotURL += rtl::OUString::valueOf( sal_Int32( nImageId )); 91*cdf0e10cSrcweir Image aImage = GetImage( m_xFrame, 92*cdf0e10cSrcweir aSlotURL, 93*cdf0e10cSrcweir hasBigImages(), 94*cdf0e10cSrcweir GetToolBox().GetSettings().GetStyleSettings().GetHighContrastMode() ); 95*cdf0e10cSrcweir GetToolBox().SetItemImage(GetId(), aImage); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir SfxPopupWindow* __EXPORT ScTbxInsertCtrl::CreatePopupWindow() 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir // sal_uInt16 nWinResId, nTbxResId; 103*cdf0e10cSrcweir sal_uInt16 nSlotId = GetSlotId(); 104*cdf0e10cSrcweir if (nSlotId == SID_TBXCTL_INSERT) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir rtl::OUString aInsertBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertbar" )); 107*cdf0e10cSrcweir createAndPositionSubToolBar( aInsertBarResStr ); 108*cdf0e10cSrcweir // nWinResId = RID_TBXCTL_INSERT; 109*cdf0e10cSrcweir // nTbxResId = RID_TOOLBOX_INSERT; 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir else if (nSlotId == SID_TBXCTL_INSCELLS) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir rtl::OUString aInsertCellsBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertcellsbar" )); 114*cdf0e10cSrcweir createAndPositionSubToolBar( aInsertCellsBarResStr ); 115*cdf0e10cSrcweir // nWinResId = RID_TBXCTL_INSCELLS; 116*cdf0e10cSrcweir // nTbxResId = RID_TOOLBOX_INSCELLS; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir else /* SID_TBXCTL_INSOBJ */ 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir rtl::OUString aInsertObjectBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertobjectbar" )); 121*cdf0e10cSrcweir createAndPositionSubToolBar( aInsertObjectBarResStr ); 122*cdf0e10cSrcweir // nWinResId = RID_TBXCTL_INSOBJ; 123*cdf0e10cSrcweir // nTbxResId = RID_TOOLBOX_INSOBJ; 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir /* 126*cdf0e10cSrcweir WindowAlign eNewAlign = ( GetToolBox().IsHorizontal() ) ? WINDOWALIGN_LEFT : WINDOWALIGN_TOP; 127*cdf0e10cSrcweir ScTbxInsertPopup *pWin = new ScTbxInsertPopup( nSlotId, eNewAlign, 128*cdf0e10cSrcweir ScResId(nWinResId), ScResId(nTbxResId), GetBindings() ); 129*cdf0e10cSrcweir pWin->StartPopupMode(&GetToolBox(), sal_True); 130*cdf0e10cSrcweir pWin->StartSelection(); 131*cdf0e10cSrcweir pWin->Show(); 132*cdf0e10cSrcweir return pWin; 133*cdf0e10cSrcweir */ 134*cdf0e10cSrcweir return NULL; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir SfxPopupWindowType __EXPORT ScTbxInsertCtrl::GetPopupWindowType() const 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir return nLastSlotId ? SFX_POPUPWINDOW_ONTIMEOUT : SFX_POPUPWINDOW_ONCLICK; 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir void __EXPORT ScTbxInsertCtrl::Select( sal_Bool /* bMod1 */ ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir SfxViewShell* pCurSh( SfxViewShell::Current() ); 145*cdf0e10cSrcweir SfxDispatcher* pDispatch( 0 ); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir if ( pCurSh ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pCurSh->GetViewFrame(); 150*cdf0e10cSrcweir if ( pViewFrame ) 151*cdf0e10cSrcweir pDispatch = pViewFrame->GetDispatcher(); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir if ( pDispatch ) 155*cdf0e10cSrcweir pDispatch->Execute(nLastSlotId); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir /* 158*cdf0e10cSrcweir //------------------------------------------------------------------ 159*cdf0e10cSrcweir // 160*cdf0e10cSrcweir // Popup - Window 161*cdf0e10cSrcweir // 162*cdf0e10cSrcweir //------------------------------------------------------------------ 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir ScTbxInsertPopup::ScTbxInsertPopup( sal_uInt16 nId, WindowAlign eNewAlign, 165*cdf0e10cSrcweir const ResId& rRIdWin, const ResId& rRIdTbx, 166*cdf0e10cSrcweir SfxBindings& rBindings ) : 167*cdf0e10cSrcweir SfxPopupWindow ( nId, rRIdWin, rBindings), 168*cdf0e10cSrcweir aTbx ( this, GetBindings(), rRIdTbx ), 169*cdf0e10cSrcweir aRIdWinTemp(rRIdWin), 170*cdf0e10cSrcweir aRIdTbxTemp(rRIdTbx) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir aTbx.UseDefault(); 173*cdf0e10cSrcweir FreeResource(); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir aTbx.GetToolBox().SetAlign( eNewAlign ); 176*cdf0e10cSrcweir if (eNewAlign == WINDOWALIGN_LEFT || eNewAlign == WINDOWALIGN_RIGHT) 177*cdf0e10cSrcweir SetText( EMPTY_STRING ); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir Size aSize = aTbx.CalcWindowSizePixel(); 180*cdf0e10cSrcweir aTbx.SetPosSizePixel( Point(), aSize ); 181*cdf0e10cSrcweir SetOutputSizePixel( aSize ); 182*cdf0e10cSrcweir aTbx.GetToolBox().SetSelectHdl( LINK(this, ScTbxInsertPopup, TbxSelectHdl)); 183*cdf0e10cSrcweir aTbxClickHdl = aTbx.GetToolBox().GetClickHdl(); 184*cdf0e10cSrcweir aTbx.GetToolBox().SetClickHdl( LINK(this, ScTbxInsertPopup, TbxClickHdl)); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir ScTbxInsertPopup::~ScTbxInsertPopup() 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir SfxPopupWindow* __EXPORT ScTbxInsertPopup::Clone() const 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir return new ScTbxInsertPopup( GetId(), aTbx.GetToolBox().GetAlign(), 194*cdf0e10cSrcweir aRIdWinTemp, aRIdTbxTemp, 195*cdf0e10cSrcweir (SfxBindings&) GetBindings() ); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir void ScTbxInsertPopup::StartSelection() 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir aTbx.GetToolBox().StartSelection(); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir IMPL_LINK(ScTbxInsertPopup, TbxSelectHdl, ToolBox*, pBox) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir EndPopupMode(); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir sal_uInt16 nLastSlotId = pBox->GetCurItemId(); 208*cdf0e10cSrcweir SfxUInt16Item aItem( GetId(), nLastSlotId ); 209*cdf0e10cSrcweir SfxDispatcher* pDisp = GetBindings().GetDispatcher(); 210*cdf0e10cSrcweir pDisp->Execute( GetId(), SFX_CALLMODE_SYNCHRON, &aItem, 0L ); 211*cdf0e10cSrcweir pDisp->Execute( nLastSlotId, SFX_CALLMODE_ASYNCHRON ); 212*cdf0e10cSrcweir return 0; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir IMPL_LINK(ScTbxInsertPopup, TbxClickHdl, ToolBox*, pBox) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir sal_uInt16 nLastSlotId = pBox->GetCurItemId(); 218*cdf0e10cSrcweir SfxUInt16Item aItem( GetId(), nLastSlotId ); 219*cdf0e10cSrcweir GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_SYNCHRON, &aItem, 0L ); 220*cdf0e10cSrcweir if(aTbxClickHdl.IsSet()) 221*cdf0e10cSrcweir aTbxClickHdl.Call(pBox); 222*cdf0e10cSrcweir return 0; 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir void __EXPORT ScTbxInsertPopup::PopupModeEnd() 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir aTbx.GetToolBox().EndSelection(); 228*cdf0e10cSrcweir SfxPopupWindow::PopupModeEnd(); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir */ 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir 233