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_sd.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <sal/config.h> 32*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/drawing/XSelectionFunction.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx> 38*cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <vcl/svapp.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include <svx/svdotable.hxx> 43*cdf0e10cSrcweir #include <svx/sdr/overlay/overlayobjectcell.hxx> 44*cdf0e10cSrcweir #include <svx/sdr/overlay/overlaymanager.hxx> 45*cdf0e10cSrcweir #include <svx/svxids.hrc> 46*cdf0e10cSrcweir #include <editeng/outlobj.hxx> 47*cdf0e10cSrcweir #include <svx/svdoutl.hxx> 48*cdf0e10cSrcweir #include <svx/svdpagv.hxx> 49*cdf0e10cSrcweir #include <svx/svdetc.hxx> 50*cdf0e10cSrcweir #include <editeng/editstat.hxx> 51*cdf0e10cSrcweir #include <editeng/unolingu.hxx> 52*cdf0e10cSrcweir #include <svx/sdrpagewindow.hxx> 53*cdf0e10cSrcweir #include <svx/sdr/table/tabledesign.hxx> 54*cdf0e10cSrcweir #include <svx/svxdlg.hxx> 55*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir #include <svl/itempool.hxx> 58*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 59*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 60*cdf0e10cSrcweir #include <sfx2/bindings.hxx> 61*cdf0e10cSrcweir #include <sfx2/request.hxx> 62*cdf0e10cSrcweir #include <svl/style.hxx> 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx" 65*cdf0e10cSrcweir #include "app.hrc" 66*cdf0e10cSrcweir #include "glob.hrc" 67*cdf0e10cSrcweir #include "DrawViewShell.hxx" 68*cdf0e10cSrcweir #include "drawdoc.hxx" 69*cdf0e10cSrcweir #include "DrawDocShell.hxx" 70*cdf0e10cSrcweir #include "Window.hxx" 71*cdf0e10cSrcweir #include "drawview.hxx" 72*cdf0e10cSrcweir #include "sdresid.hxx" 73*cdf0e10cSrcweir #include "undo/undoobjects.hxx" 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir using ::rtl::OUString; 76*cdf0e10cSrcweir using namespace ::sd; 77*cdf0e10cSrcweir using namespace ::sdr::table; 78*cdf0e10cSrcweir using namespace ::com::sun::star; 79*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 80*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 81*cdf0e10cSrcweir using namespace ::com::sun::star::util; 82*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 83*cdf0e10cSrcweir using namespace ::com::sun::star::container; 84*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 85*cdf0e10cSrcweir using namespace ::com::sun::star::drawing; 86*cdf0e10cSrcweir using namespace ::com::sun::star::linguistic2; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir namespace css = ::com::sun::star; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir namespace sd 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir extern void showTableDesignDialog( ::Window*, ViewShellBase& ); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir static void apply_table_style( SdrTableObj* pObj, SdrModel* pModel, const OUString& sTableStyle ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir if( pModel && pObj ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir Reference< XNameAccess > xPool( dynamic_cast< XNameAccess* >( pModel->GetStyleSheetPool() ) ); 99*cdf0e10cSrcweir if( xPool.is() ) try 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir const OUString sFamilyName( RTL_CONSTASCII_USTRINGPARAM( "table" ) ); 102*cdf0e10cSrcweir Reference< XNameContainer > xTableFamily( xPool->getByName( sFamilyName ), UNO_QUERY_THROW ); 103*cdf0e10cSrcweir OUString aStdName( RTL_CONSTASCII_USTRINGPARAM("default") ); 104*cdf0e10cSrcweir if( sTableStyle.getLength() ) 105*cdf0e10cSrcweir aStdName = sTableStyle; 106*cdf0e10cSrcweir Reference< XIndexAccess > xStyle( xTableFamily->getByName( aStdName ), UNO_QUERY_THROW ); 107*cdf0e10cSrcweir pObj->setTableStyle( xStyle ); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir catch( Exception& ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir DBG_ERROR("sd::apply_default_table_style(), exception caught!"); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir void DrawViewShell::FuTable(SfxRequest& rReq) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir switch( rReq.GetSlot() ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir case SID_INSERT_TABLE: 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir sal_Int32 nColumns = 0; 123*cdf0e10cSrcweir sal_Int32 nRows = 0; 124*cdf0e10cSrcweir OUString sTableStyle; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pCols, SfxUInt16Item, SID_ATTR_TABLE_COLUMN, sal_False ); 127*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pRows, SfxUInt16Item, SID_ATTR_TABLE_ROW, sal_False ); 128*cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pStyle, SfxStringItem, SID_TABLE_STYLE, sal_False ); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir if( pCols ) 131*cdf0e10cSrcweir nColumns = pCols->GetValue(); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir if( pRows ) 134*cdf0e10cSrcweir nRows = pRows->GetValue(); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir if( pStyle ) 137*cdf0e10cSrcweir sTableStyle = pStyle->GetValue(); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir if( (nColumns == 0) || (nRows == 0) ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 142*cdf0e10cSrcweir ::std::auto_ptr<SvxAbstractNewTableDialog> pDlg( pFact ? pFact->CreateSvxNewTableDialog( NULL ) : 0); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir if( !pDlg.get() || (pDlg->Execute() != RET_OK) ) 145*cdf0e10cSrcweir break; 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir nColumns = pDlg->getColumns(); 148*cdf0e10cSrcweir nRows = pDlg->getRows(); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir Rectangle aRect; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir SdrObject* pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_TABLE ); 154*cdf0e10cSrcweir if( pPickObj ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir aRect = pPickObj->GetLogicRect(); 157*cdf0e10cSrcweir aRect.setHeight( 200 ); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir else 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir Size aSize( 14100, 200 ); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir Point aPos; 164*cdf0e10cSrcweir Rectangle aWinRect(aPos, GetActiveWindow()->GetOutputSizePixel() ); 165*cdf0e10cSrcweir aPos = aWinRect.Center(); 166*cdf0e10cSrcweir aPos = GetActiveWindow()->PixelToLogic(aPos); 167*cdf0e10cSrcweir aPos.X() -= aSize.Width() / 2; 168*cdf0e10cSrcweir aPos.Y() -= aSize.Height() / 2; 169*cdf0e10cSrcweir aRect = Rectangle(aPos, aSize); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir ::sdr::table::SdrTableObj* pObj = new ::sdr::table::SdrTableObj( GetDoc(), aRect, nColumns, nRows ); 173*cdf0e10cSrcweir pObj->NbcSetStyleSheet( GetDoc()->GetDefaultStyleSheet(), sal_True ); 174*cdf0e10cSrcweir apply_table_style( pObj, GetDoc(), sTableStyle ); 175*cdf0e10cSrcweir SdrPageView* pPV = mpView->GetSdrPageView(); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj 178*cdf0e10cSrcweir if( pPickObj ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage()); 181*cdf0e10cSrcweir if(pPage && pPage->IsPresObj(pPickObj)) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir pObj->SetUserCall( pPickObj->GetUserCall() ); 184*cdf0e10cSrcweir pPage->InsertPresObj( pObj, PRESOBJ_TABLE ); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir GetParentWindow()->GrabFocus(); 189*cdf0e10cSrcweir if( pPickObj ) 190*cdf0e10cSrcweir mpView->ReplaceObjectAtView(pPickObj, *pPV, pObj, sal_True ); 191*cdf0e10cSrcweir else 192*cdf0e10cSrcweir mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER); 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir Invalidate(SID_DRAWTBX_INSERT); 195*cdf0e10cSrcweir rReq.Ignore(); 196*cdf0e10cSrcweir SfxViewShell* pViewShell = GetViewShell(); 197*cdf0e10cSrcweir OSL_ASSERT (pViewShell!=NULL); 198*cdf0e10cSrcweir SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings(); 199*cdf0e10cSrcweir rBindings.Invalidate( SID_INSERT_TABLE, sal_True, sal_False ); 200*cdf0e10cSrcweir break; 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir case SID_TABLEDESIGN: 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir if( GetDoc() && (GetDoc()->GetDocumentType() == DOCUMENT_TYPE_DRAW) ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir // in draw open a modal dialog since we have no tool pane yet 207*cdf0e10cSrcweir showTableDesignDialog( GetActiveWindow(), GetViewShellBase() ); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir else 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir // Make the slide transition panel visible (expand it) in the 212*cdf0e10cSrcweir // tool pane. 213*cdf0e10cSrcweir framework::FrameworkHelper::Instance(GetViewShellBase())->RequestTaskPanel( 214*cdf0e10cSrcweir framework::FrameworkHelper::msTableDesignPanelURL); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir Cancel(); 218*cdf0e10cSrcweir rReq.Done (); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir default: 221*cdf0e10cSrcweir break; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir // -------------------------------------------------------------------- 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir void DrawViewShell::GetTableMenuState( SfxItemSet &rSet ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir bool bIsUIActive = GetDocSh()->IsUIActive(); 230*cdf0e10cSrcweir if( bIsUIActive ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir rSet.DisableItem( SID_INSERT_TABLE ); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir else 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir String aActiveLayer = mpDrawView->GetActiveLayer(); 237*cdf0e10cSrcweir SdrPageView* pPV = mpDrawView->GetSdrPageView(); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir if( bIsUIActive || 240*cdf0e10cSrcweir ( aActiveLayer.Len() != 0 && pPV && ( pPV->IsLayerLocked(aActiveLayer) || 241*cdf0e10cSrcweir !pPV->IsLayerVisible(aActiveLayer) ) ) || 242*cdf0e10cSrcweir SD_MOD()->GetWaterCan() ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir rSet.DisableItem( SID_INSERT_TABLE ); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir // -------------------------------------------------------------------- 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir rStream.Seek( 0 ); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir if( pModel ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir SdrPage* pPage = pModel->GetPage(0); 258*cdf0e10cSrcweir if( pPage ) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir Size aSize( 200, 200 ); 261*cdf0e10cSrcweir Point aPos; 262*cdf0e10cSrcweir Rectangle aRect (aPos, aSize); 263*cdf0e10cSrcweir ::sdr::table::SdrTableObj* pObj = new ::sdr::table::SdrTableObj( pModel, aRect, 1, 1 ); 264*cdf0e10cSrcweir pObj->NbcSetStyleSheet( pModel->GetDefaultStyleSheet(), sal_True ); 265*cdf0e10cSrcweir OUString sTableStyle; 266*cdf0e10cSrcweir apply_table_style( pObj, pModel, sTableStyle ); 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir pPage->NbcInsertObject( pObj ); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir sdr::table::SdrTableObj::ImportAsRTF( rStream, *pObj ); 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir } 276