bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / table / tablefunction.cxx
blobc0c4aef5fef63cc67e104853350108c5929dfba4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
21 #include <com/sun/star/uno/XComponentContext.hpp>
22 #include <com/sun/star/drawing/XSelectionFunction.hpp>
23 #include <com/sun/star/awt/KeyModifier.hpp>
24 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <cppuhelper/compbase2.hxx>
27 #include <cppuhelper/basemutex.hxx>
29 #include <vcl/svapp.hxx>
31 #include <svx/svdotable.hxx>
32 #include <svx/sdr/overlay/overlayobjectcell.hxx>
33 #include <svx/sdr/overlay/overlaymanager.hxx>
34 #include <svx/svxids.hrc>
35 #include <editeng/outlobj.hxx>
36 #include <svx/svdoutl.hxx>
37 #include <svx/svdpagv.hxx>
38 #include <svx/svdetc.hxx>
39 #include <editeng/editstat.hxx>
40 #include <editeng/unolingu.hxx>
41 #include <svx/sdrpagewindow.hxx>
42 #include <svx/sdr/table/tabledesign.hxx>
43 #include <svx/svxdlg.hxx>
44 #include <vcl/msgbox.hxx>
46 #include <svl/itempool.hxx>
47 #include <sfx2/viewfrm.hxx>
48 #include <sfx2/dispatch.hxx>
49 #include <sfx2/bindings.hxx>
50 #include <sfx2/request.hxx>
51 #include <sfx2/sidebar/Sidebar.hxx>
52 #include <svl/style.hxx>
54 #include "framework/FrameworkHelper.hxx"
55 #include "TableDesignPane.hxx"
56 #include "app.hrc"
57 #include "glob.hrc"
58 #include "tablefunction.hxx"
59 #include "DrawViewShell.hxx"
60 #include "drawdoc.hxx"
61 #include "DrawDocShell.hxx"
62 #include "Window.hxx"
63 #include "drawview.hxx"
64 #include "sdresid.hxx"
65 #include "undo/undoobjects.hxx"
67 #include <boost/scoped_ptr.hpp>
69 using namespace ::sd;
70 using namespace sdr::table;
71 using namespace ::com::sun::star;
72 using namespace ::com::sun::star::uno;
73 using namespace ::com::sun::star::beans;
74 using namespace ::com::sun::star::util;
75 using namespace ::com::sun::star::frame;
76 using namespace ::com::sun::star::container;
77 using namespace ::com::sun::star::lang;
78 using namespace ::com::sun::star::drawing;
79 using namespace ::com::sun::star::linguistic2;
81 namespace sd
84 static void apply_table_style( SdrTableObj* pObj, SdrModel* pModel, const OUString& sTableStyle )
86 if( pModel && pObj )
88 Reference< XNameAccess > xPool( dynamic_cast< XNameAccess* >( pModel->GetStyleSheetPool() ) );
89 if( xPool.is() ) try
91 const OUString sFamilyName("table" );
92 Reference< XNameContainer > xTableFamily( xPool->getByName( sFamilyName ), UNO_QUERY_THROW );
93 OUString aStdName( "default" );
94 if( !sTableStyle.isEmpty() )
95 aStdName = sTableStyle;
96 Reference< XIndexAccess > xStyle( xTableFamily->getByName( aStdName ), UNO_QUERY_THROW );
97 pObj->setTableStyle( xStyle );
99 catch( Exception& )
101 OSL_FAIL("sd::apply_default_table_style(), exception caught!");
106 void DrawViewShell::FuTable(SfxRequest& rReq)
108 switch( rReq.GetSlot() )
110 case SID_INSERT_TABLE:
112 sal_Int32 nColumns = 0;
113 sal_Int32 nRows = 0;
114 OUString sTableStyle;
116 SFX_REQUEST_ARG( rReq, pCols, SfxUInt16Item, SID_ATTR_TABLE_COLUMN, false );
117 SFX_REQUEST_ARG( rReq, pRows, SfxUInt16Item, SID_ATTR_TABLE_ROW, false );
118 SFX_REQUEST_ARG( rReq, pStyle, SfxStringItem, SID_TABLE_STYLE, false );
120 if( pCols )
121 nColumns = pCols->GetValue();
123 if( pRows )
124 nRows = pRows->GetValue();
126 if( pStyle )
127 sTableStyle = pStyle->GetValue();
129 if( (nColumns == 0) || (nRows == 0) )
131 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
132 boost::scoped_ptr<SvxAbstractNewTableDialog> pDlg( pFact ? pFact->CreateSvxNewTableDialog( NULL ) : 0);
134 if( !pDlg.get() || (pDlg->Execute() != RET_OK) )
135 break;
137 nColumns = pDlg->getColumns();
138 nRows = pDlg->getRows();
141 Rectangle aRect;
143 SdrObject* pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_TABLE );
144 if( pPickObj )
146 aRect = pPickObj->GetLogicRect();
147 aRect.setHeight( 200 );
149 else
151 Size aSize( 14100, 200 );
153 Point aPos;
154 Rectangle aWinRect(aPos, GetActiveWindow()->GetOutputSizePixel() );
155 aPos = aWinRect.Center();
156 aPos = GetActiveWindow()->PixelToLogic(aPos);
157 aPos.X() -= aSize.Width() / 2;
158 aPos.Y() -= aSize.Height() / 2;
159 aRect = Rectangle(aPos, aSize);
162 sdr::table::SdrTableObj* pObj = new sdr::table::SdrTableObj( GetDoc(), aRect, nColumns, nRows );
163 pObj->NbcSetStyleSheet( GetDoc()->GetDefaultStyleSheet(), true );
164 apply_table_style( pObj, GetDoc(), sTableStyle );
165 SdrPageView* pPV = mpView->GetSdrPageView();
167 // #i123359# if an object is to be replaced/manipulated it may be that it is in text edit mode,
168 // so to be on the safe side call SdrEndTextEdit here
169 SdrTextObj* pCheckForTextEdit = dynamic_cast< SdrTextObj* >(pPickObj);
171 if(pCheckForTextEdit && pCheckForTextEdit->IsInEditMode())
173 mpView->SdrEndTextEdit();
176 // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
177 if( pPickObj )
179 SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
180 if(pPage && pPage->IsPresObj(pPickObj))
182 pObj->SetUserCall( pPickObj->GetUserCall() );
183 pPage->InsertPresObj( pObj, PRESOBJ_TABLE );
187 GetParentWindow()->GrabFocus();
188 if( pPickObj )
189 mpView->ReplaceObjectAtView(pPickObj, *pPV, pObj, true );
190 else
191 mpView->InsertObjectAtView(pObj, *pPV, SdrInsertFlags::SETDEFLAYER);
193 Invalidate(SID_DRAWTBX_INSERT);
194 rReq.Ignore();
195 SfxViewShell* pViewShell = GetViewShell();
196 OSL_ASSERT (pViewShell!=NULL);
197 SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings();
198 rBindings.Invalidate( SID_INSERT_TABLE, true, false );
199 break;
201 case SID_TABLEDESIGN:
203 if( GetDoc() && (GetDoc()->GetDocumentType() == DOCUMENT_TYPE_DRAW) )
205 // in draw open a modal dialog since we have no tool pane yet
206 showTableDesignDialog( GetActiveWindow(), GetViewShellBase() );
208 else
210 // First make sure that the sidebar is visible
211 GetViewFrame()->ShowChildWindow(SID_SIDEBAR);
212 ::sfx2::sidebar::Sidebar::ShowPanel(
213 OUString("ImpressTableDesignPanel"),
214 GetViewFrame()->GetFrame().GetFrameInterface());
217 Cancel();
218 rReq.Done ();
220 default:
221 break;
225 void DrawViewShell::GetTableMenuState( SfxItemSet &rSet )
227 OUString aActiveLayer = mpDrawView->GetActiveLayer();
228 SdrPageView* pPV = mpDrawView->GetSdrPageView();
231 ( !aActiveLayer.isEmpty() && pPV && ( pPV->IsLayerLocked(aActiveLayer) ||
232 !pPV->IsLayerVisible(aActiveLayer) ) ) ||
233 SD_MOD()->GetWaterCan() )
235 rSet.DisableItem( SID_INSERT_TABLE );
239 void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel )
241 rStream.Seek( 0 );
243 if( pModel )
245 SdrPage* pPage = pModel->GetPage(0);
246 if( pPage )
248 Size aSize( 200, 200 );
249 Point aPos;
250 Rectangle aRect (aPos, aSize);
251 sdr::table::SdrTableObj* pObj = new sdr::table::SdrTableObj( pModel, aRect, 1, 1 );
252 pObj->NbcSetStyleSheet( pModel->GetDefaultStyleSheet(), true );
253 OUString sTableStyle;
254 apply_table_style( pObj, pModel, sTableStyle );
256 pPage->NbcInsertObject( pObj );
258 sdr::table::SdrTableObj::ImportAsRTF( rStream, *pObj );
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */