merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / table / tablefunction.cxx
blobed6f8df0a19f3226e74c0bfe11622b9582b6c0cc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tablefunction.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include <sal/config.h>
35 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <com/sun/star/drawing/XSelectionFunction.hpp>
37 #include <com/sun/star/awt/KeyModifier.hpp>
38 #include <com/sun/star/lang/XInitialization.hpp>
40 #include <cppuhelper/compbase2.hxx>
41 #include <cppuhelper/basemutex.hxx>
43 #include <vcl/svapp.hxx>
45 #include <svx/svdotable.hxx>
46 #include <svx/sdr/overlay/overlayobjectcell.hxx>
47 #include <svx/sdr/overlay/overlaymanager.hxx>
48 #include <svx/svxids.hrc>
49 #include <svx/outlobj.hxx>
50 #include <svx/svdoutl.hxx>
51 #include <svx/svdpagv.hxx>
52 #include <svx/svdetc.hxx>
53 #include <svx/editstat.hxx>
54 #include <svx/unolingu.hxx>
55 #include <svx/sdrpagewindow.hxx>
56 #include <svx/sdr/table/tabledesign.hxx>
57 #include <svx/svxdlg.hxx>
58 #include <vcl/msgbox.hxx>
60 #include <svtools/itempool.hxx>
61 #include <sfx2/viewfrm.hxx>
62 #include <sfx2/dispatch.hxx>
63 #include <sfx2/bindings.hxx>
64 #include <sfx2/request.hxx>
65 #include <svtools/style.hxx>
67 #include "framework/FrameworkHelper.hxx"
68 #include "app.hrc"
69 #include "glob.hrc"
70 #include "DrawViewShell.hxx"
71 #include "drawdoc.hxx"
72 #include "DrawDocShell.hxx"
73 #include "Outliner.hxx"
74 #include "Window.hxx"
75 #include "drawview.hxx"
76 #include "sdresid.hxx"
78 using ::rtl::OUString;
79 using namespace ::sd;
80 using namespace ::sdr::table;
81 using namespace ::com::sun::star;
82 using namespace ::com::sun::star::uno;
83 using namespace ::com::sun::star::beans;
84 using namespace ::com::sun::star::util;
85 using namespace ::com::sun::star::frame;
86 using namespace ::com::sun::star::container;
87 using namespace ::com::sun::star::lang;
88 using namespace ::com::sun::star::drawing;
89 using namespace ::com::sun::star::linguistic2;
91 namespace css = ::com::sun::star;
93 namespace sd
95 extern void showTableDesignDialog( ::Window*, ViewShellBase& );
97 static void apply_table_style( SdrTableObj* pObj, SdrModel* pModel, const OUString& sTableStyle )
99 if( pModel && pObj )
101 Reference< XNameAccess > xPool( dynamic_cast< XNameAccess* >( pModel->GetStyleSheetPool() ) );
102 if( xPool.is() ) try
104 const OUString sFamilyName( RTL_CONSTASCII_USTRINGPARAM( "table" ) );
105 Reference< XNameContainer > xTableFamily( xPool->getByName( sFamilyName ), UNO_QUERY_THROW );
106 OUString aStdName( RTL_CONSTASCII_USTRINGPARAM("default") );
107 if( sTableStyle.getLength() )
108 aStdName = sTableStyle;
109 Reference< XIndexAccess > xStyle( xTableFamily->getByName( aStdName ), UNO_QUERY_THROW );
110 pObj->setTableStyle( xStyle );
112 catch( Exception& )
114 DBG_ERROR("sd::apply_default_table_style(), exception caught!");
119 void DrawViewShell::FuTable(SfxRequest& rReq)
121 switch( rReq.GetSlot() )
123 case SID_INSERT_TABLE:
125 sal_Int32 nColumns = 0;
126 sal_Int32 nRows = 0;
127 OUString sTableStyle;
129 SFX_REQUEST_ARG( rReq, pCols, SfxUInt16Item, SID_ATTR_TABLE_COLUMN, sal_False );
130 SFX_REQUEST_ARG( rReq, pRows, SfxUInt16Item, SID_ATTR_TABLE_ROW, sal_False );
131 SFX_REQUEST_ARG( rReq, pStyle, SfxStringItem, SID_TABLE_STYLE, sal_False );
133 if( pCols )
134 nColumns = pCols->GetValue();
136 if( pRows )
137 nRows = pRows->GetValue();
139 if( pStyle )
140 sTableStyle = pStyle->GetValue();
142 if( (nColumns == 0) || (nRows == 0) )
144 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
145 ::std::auto_ptr<SvxAbstractNewTableDialog> pDlg( pFact ? pFact->CreateSvxNewTableDialog( NULL ) : 0);
147 if( !pDlg.get() || (pDlg->Execute() != RET_OK) )
148 break;
150 nColumns = pDlg->getColumns();
151 nRows = pDlg->getRows();
154 Size aSize( 14100, 3000 );
156 ::sd::Outliner* pSdOutliner = GetDoc()->GetOutliner();
157 const long nTextHeight = pSdOutliner->GetTextHeight();
158 aSize.Height() = std::max(aSize.Height(),nRows*nTextHeight);
160 Point aPos;
161 Rectangle aWinRect(aPos, GetActiveWindow()->GetOutputSizePixel() );
162 aPos = aWinRect.Center();
163 aPos = GetActiveWindow()->PixelToLogic(aPos);
164 aPos.X() -= aSize.Width() / 2;
165 aPos.Y() -= aSize.Height() / 2;
166 Rectangle aRect (aPos, aSize);
168 ::sdr::table::SdrTableObj* pObj = new ::sdr::table::SdrTableObj( GetDoc(), aRect, nColumns, nRows );
169 pObj->NbcSetStyleSheet( GetDoc()->GetDefaultStyleSheet(), sal_True );
170 apply_table_style( pObj, GetDoc(), sTableStyle );
171 SdrPageView* pPV = mpView->GetSdrPageView();
172 mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER);
173 Invalidate(SID_DRAWTBX_INSERT);
174 rReq.Ignore();
175 break;
177 case SID_TABLEDESIGN:
179 if( GetDoc() && (GetDoc()->GetDocumentType() == DOCUMENT_TYPE_DRAW) )
181 // in draw open a modal dialog since we have no tool pane yet
182 showTableDesignDialog( GetActiveWindow(), GetViewShellBase() );
184 else
186 // Make the slide transition panel visible (expand it) in the
187 // tool pane.
188 framework::FrameworkHelper::Instance(GetViewShellBase())->RequestTaskPanel(
189 framework::FrameworkHelper::msTableDesignPanelURL);
192 Cancel();
193 rReq.Done ();
195 default:
196 break;
200 // --------------------------------------------------------------------
202 void DrawViewShell::GetTableMenuState( SfxItemSet &rSet )
204 bool bIsUIActive = GetDocSh()->IsUIActive();
205 if( bIsUIActive )
207 rSet.DisableItem( SID_INSERT_TABLE );
209 else
211 String aActiveLayer = mpDrawView->GetActiveLayer();
212 SdrPageView* pPV = mpDrawView->GetSdrPageView();
214 if( bIsUIActive ||
215 ( aActiveLayer.Len() != 0 && pPV && ( pPV->IsLayerLocked(aActiveLayer) ||
216 !pPV->IsLayerVisible(aActiveLayer) ) ) ||
217 SD_MOD()->GetWaterCan() )
219 rSet.DisableItem( SID_INSERT_TABLE );
224 // --------------------------------------------------------------------
226 void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel )
228 rStream.Seek( 0 );
230 if( pModel )
232 SdrPage* pPage = pModel->GetPage(0);
233 if( pPage )
235 Size aSize( 200, 200 );
236 Point aPos;
237 Rectangle aRect (aPos, aSize);
238 ::sdr::table::SdrTableObj* pObj = new ::sdr::table::SdrTableObj( pModel, aRect, 1, 1 );
239 pObj->NbcSetStyleSheet( pModel->GetDefaultStyleSheet(), sal_True );
240 OUString sTableStyle;
241 apply_table_style( pObj, pModel, sTableStyle );
243 pPage->NbcInsertObject( pObj );
245 sdr::table::SdrTableObj::ImportAsRTF( rStream, *pObj );