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