15b190011SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 35b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 45b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file 55b190011SAndrew Rist * distributed with this work for additional information 65b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file 75b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the 85b190011SAndrew Rist * "License"); you may not use this file except in compliance 95b190011SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 115b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 135b190011SAndrew Rist * Unless required by applicable law or agreed to in writing, 145b190011SAndrew Rist * software distributed under the License is distributed on an 155b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 165b190011SAndrew Rist * KIND, either express or implied. See the License for the 175b190011SAndrew Rist * specific language governing permissions and limitations 185b190011SAndrew Rist * under the License. 19cdf0e10cSrcweir * 205b190011SAndrew Rist *************************************************************/ 215b190011SAndrew Rist 225b190011SAndrew 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> 583091fa8aSAndre Fischer #include <sfx2/sidebar/Sidebar.hxx> 59cdf0e10cSrcweir #include <svl/style.hxx> 60cdf0e10cSrcweir 61cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx" 62cdf0e10cSrcweir #include "app.hrc" 63cdf0e10cSrcweir #include "glob.hrc" 64cdf0e10cSrcweir #include "DrawViewShell.hxx" 65cdf0e10cSrcweir #include "drawdoc.hxx" 66cdf0e10cSrcweir #include "DrawDocShell.hxx" 67cdf0e10cSrcweir #include "Window.hxx" 68cdf0e10cSrcweir #include "drawview.hxx" 69cdf0e10cSrcweir #include "sdresid.hxx" 70cdf0e10cSrcweir #include "undo/undoobjects.hxx" 71cdf0e10cSrcweir 72cdf0e10cSrcweir using ::rtl::OUString; 73cdf0e10cSrcweir using namespace ::sd; 74cdf0e10cSrcweir using namespace ::sdr::table; 75cdf0e10cSrcweir using namespace ::com::sun::star; 76cdf0e10cSrcweir using namespace ::com::sun::star::uno; 77cdf0e10cSrcweir using namespace ::com::sun::star::beans; 78cdf0e10cSrcweir using namespace ::com::sun::star::util; 79cdf0e10cSrcweir using namespace ::com::sun::star::frame; 80cdf0e10cSrcweir using namespace ::com::sun::star::container; 81cdf0e10cSrcweir using namespace ::com::sun::star::lang; 82cdf0e10cSrcweir using namespace ::com::sun::star::drawing; 83cdf0e10cSrcweir using namespace ::com::sun::star::linguistic2; 84cdf0e10cSrcweir 85cdf0e10cSrcweir namespace css = ::com::sun::star; 86cdf0e10cSrcweir 87cdf0e10cSrcweir namespace sd 88cdf0e10cSrcweir { 89cdf0e10cSrcweir extern void showTableDesignDialog( ::Window*, ViewShellBase& ); 90cdf0e10cSrcweir 91cdf0e10cSrcweir static void apply_table_style( SdrTableObj* pObj, SdrModel* pModel, const OUString& sTableStyle ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir if( pModel && pObj ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir Reference< XNameAccess > xPool( dynamic_cast< XNameAccess* >( pModel->GetStyleSheetPool() ) ); 96cdf0e10cSrcweir if( xPool.is() ) try 97cdf0e10cSrcweir { 98cdf0e10cSrcweir const OUString sFamilyName( RTL_CONSTASCII_USTRINGPARAM( "table" ) ); 99cdf0e10cSrcweir Reference< XNameContainer > xTableFamily( xPool->getByName( sFamilyName ), UNO_QUERY_THROW ); 100cdf0e10cSrcweir OUString aStdName( RTL_CONSTASCII_USTRINGPARAM("default") ); 101cdf0e10cSrcweir if( sTableStyle.getLength() ) 102cdf0e10cSrcweir aStdName = sTableStyle; 103cdf0e10cSrcweir Reference< XIndexAccess > xStyle( xTableFamily->getByName( aStdName ), UNO_QUERY_THROW ); 104cdf0e10cSrcweir pObj->setTableStyle( xStyle ); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir catch( Exception& ) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir DBG_ERROR("sd::apply_default_table_style(), exception caught!"); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir } 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir void DrawViewShell::FuTable(SfxRequest& rReq) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir switch( rReq.GetSlot() ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir case SID_INSERT_TABLE: 118cdf0e10cSrcweir { 119cdf0e10cSrcweir sal_Int32 nColumns = 0; 120cdf0e10cSrcweir sal_Int32 nRows = 0; 121cdf0e10cSrcweir OUString sTableStyle; 122cdf0e10cSrcweir 123cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pCols, SfxUInt16Item, SID_ATTR_TABLE_COLUMN, sal_False ); 124cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pRows, SfxUInt16Item, SID_ATTR_TABLE_ROW, sal_False ); 125cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pStyle, SfxStringItem, SID_TABLE_STYLE, sal_False ); 126cdf0e10cSrcweir 127cdf0e10cSrcweir if( pCols ) 128cdf0e10cSrcweir nColumns = pCols->GetValue(); 129cdf0e10cSrcweir 130cdf0e10cSrcweir if( pRows ) 131cdf0e10cSrcweir nRows = pRows->GetValue(); 132cdf0e10cSrcweir 133cdf0e10cSrcweir if( pStyle ) 134cdf0e10cSrcweir sTableStyle = pStyle->GetValue(); 135cdf0e10cSrcweir 136cdf0e10cSrcweir if( (nColumns == 0) || (nRows == 0) ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 139cdf0e10cSrcweir ::std::auto_ptr<SvxAbstractNewTableDialog> pDlg( pFact ? pFact->CreateSvxNewTableDialog( NULL ) : 0); 140cdf0e10cSrcweir 141cdf0e10cSrcweir if( !pDlg.get() || (pDlg->Execute() != RET_OK) ) 142cdf0e10cSrcweir break; 143cdf0e10cSrcweir 144cdf0e10cSrcweir nColumns = pDlg->getColumns(); 145cdf0e10cSrcweir nRows = pDlg->getRows(); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir Rectangle aRect; 149cdf0e10cSrcweir 150cdf0e10cSrcweir SdrObject* pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_TABLE ); 151cdf0e10cSrcweir if( pPickObj ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir aRect = pPickObj->GetLogicRect(); 154cdf0e10cSrcweir aRect.setHeight( 200 ); 155cdf0e10cSrcweir } 156cdf0e10cSrcweir else 157cdf0e10cSrcweir { 158cdf0e10cSrcweir Size aSize( 14100, 200 ); 159cdf0e10cSrcweir 160cdf0e10cSrcweir Point aPos; 161cdf0e10cSrcweir Rectangle aWinRect(aPos, GetActiveWindow()->GetOutputSizePixel() ); 162cdf0e10cSrcweir aPos = aWinRect.Center(); 163cdf0e10cSrcweir aPos = GetActiveWindow()->PixelToLogic(aPos); 164cdf0e10cSrcweir aPos.X() -= aSize.Width() / 2; 165cdf0e10cSrcweir aPos.Y() -= aSize.Height() / 2; 166cdf0e10cSrcweir aRect = Rectangle(aPos, aSize); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir ::sdr::table::SdrTableObj* pObj = new ::sdr::table::SdrTableObj( GetDoc(), aRect, nColumns, nRows ); 170cdf0e10cSrcweir pObj->NbcSetStyleSheet( GetDoc()->GetDefaultStyleSheet(), sal_True ); 171cdf0e10cSrcweir apply_table_style( pObj, GetDoc(), sTableStyle ); 172cdf0e10cSrcweir SdrPageView* pPV = mpView->GetSdrPageView(); 173cdf0e10cSrcweir 174*58a71021SArmin Le Grand // #123359# if an object is to be replaced/manipulated it may be that it is in text edit mode, 175*58a71021SArmin Le Grand // so to be on the safe side call SdrEndTextEdit here 176*58a71021SArmin Le Grand SdrTextObj* pCheckForTextEdit = dynamic_cast< SdrTextObj* >(pPickObj); 177*58a71021SArmin Le Grand 178*58a71021SArmin Le Grand if(pCheckForTextEdit && pCheckForTextEdit->IsInEditMode()) 179*58a71021SArmin Le Grand { 180*58a71021SArmin Le Grand mpView->SdrEndTextEdit(); 181*58a71021SArmin Le Grand } 182*58a71021SArmin Le Grand 183cdf0e10cSrcweir // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj 184cdf0e10cSrcweir if( pPickObj ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage()); 187cdf0e10cSrcweir if(pPage && pPage->IsPresObj(pPickObj)) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir pObj->SetUserCall( pPickObj->GetUserCall() ); 190cdf0e10cSrcweir pPage->InsertPresObj( pObj, PRESOBJ_TABLE ); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir GetParentWindow()->GrabFocus(); 195cdf0e10cSrcweir if( pPickObj ) 196cdf0e10cSrcweir mpView->ReplaceObjectAtView(pPickObj, *pPV, pObj, sal_True ); 197cdf0e10cSrcweir else 198cdf0e10cSrcweir mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER); 199cdf0e10cSrcweir 200cdf0e10cSrcweir Invalidate(SID_DRAWTBX_INSERT); 201cdf0e10cSrcweir rReq.Ignore(); 202cdf0e10cSrcweir SfxViewShell* pViewShell = GetViewShell(); 203cdf0e10cSrcweir OSL_ASSERT (pViewShell!=NULL); 204cdf0e10cSrcweir SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings(); 205cdf0e10cSrcweir rBindings.Invalidate( SID_INSERT_TABLE, sal_True, sal_False ); 206cdf0e10cSrcweir break; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir case SID_TABLEDESIGN: 209cdf0e10cSrcweir { 210cdf0e10cSrcweir if( GetDoc() && (GetDoc()->GetDocumentType() == DOCUMENT_TYPE_DRAW) ) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir // in draw open a modal dialog since we have no tool pane yet 213cdf0e10cSrcweir showTableDesignDialog( GetActiveWindow(), GetViewShellBase() ); 214cdf0e10cSrcweir } 215cdf0e10cSrcweir else 216cdf0e10cSrcweir { 2173091fa8aSAndre Fischer // Make the table design panel visible (expand it) in the 2183091fa8aSAndre Fischer // sidebar. 2193091fa8aSAndre Fischer ::sfx2::sidebar::Sidebar::ShowPanel( 2203091fa8aSAndre Fischer ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ImpressTableDesignPanel")), 2213091fa8aSAndre Fischer GetViewFrame()->GetFrame().GetFrameInterface()); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir Cancel(); 225cdf0e10cSrcweir rReq.Done (); 226cdf0e10cSrcweir } 227cdf0e10cSrcweir default: 228cdf0e10cSrcweir break; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir // -------------------------------------------------------------------- 233cdf0e10cSrcweir 234cdf0e10cSrcweir void DrawViewShell::GetTableMenuState( SfxItemSet &rSet ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir bool bIsUIActive = GetDocSh()->IsUIActive(); 237cdf0e10cSrcweir if( bIsUIActive ) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir rSet.DisableItem( SID_INSERT_TABLE ); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir else 242cdf0e10cSrcweir { 243cdf0e10cSrcweir String aActiveLayer = mpDrawView->GetActiveLayer(); 244cdf0e10cSrcweir SdrPageView* pPV = mpDrawView->GetSdrPageView(); 245cdf0e10cSrcweir 246cdf0e10cSrcweir if( bIsUIActive || 247cdf0e10cSrcweir ( aActiveLayer.Len() != 0 && pPV && ( pPV->IsLayerLocked(aActiveLayer) || 248cdf0e10cSrcweir !pPV->IsLayerVisible(aActiveLayer) ) ) || 249cdf0e10cSrcweir SD_MOD()->GetWaterCan() ) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir rSet.DisableItem( SID_INSERT_TABLE ); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir } 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir // -------------------------------------------------------------------- 257cdf0e10cSrcweir 258cdf0e10cSrcweir void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel ) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir rStream.Seek( 0 ); 261cdf0e10cSrcweir 262cdf0e10cSrcweir if( pModel ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir SdrPage* pPage = pModel->GetPage(0); 265cdf0e10cSrcweir if( pPage ) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir Size aSize( 200, 200 ); 268cdf0e10cSrcweir Point aPos; 269cdf0e10cSrcweir Rectangle aRect (aPos, aSize); 270cdf0e10cSrcweir ::sdr::table::SdrTableObj* pObj = new ::sdr::table::SdrTableObj( pModel, aRect, 1, 1 ); 271cdf0e10cSrcweir pObj->NbcSetStyleSheet( pModel->GetDefaultStyleSheet(), sal_True ); 272cdf0e10cSrcweir OUString sTableStyle; 273cdf0e10cSrcweir apply_table_style( pObj, pModel, sTableStyle ); 274cdf0e10cSrcweir 275cdf0e10cSrcweir pPage->NbcInsertObject( pObj ); 276cdf0e10cSrcweir 277cdf0e10cSrcweir sdr::table::SdrTableObj::ImportAsRTF( rStream, *pObj ); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir } 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir } 283