Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
25 :
26 : #include <cppuhelper/compbase2.hxx>
27 : #include <cppuhelper/basemutex.hxx>
28 :
29 : #include <vcl/svapp.hxx>
30 :
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>
45 :
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>
53 :
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"
66 :
67 : #include <boost/scoped_ptr.hpp>
68 :
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;
80 :
81 : namespace sd
82 : {
83 :
84 0 : static void apply_table_style( SdrTableObj* pObj, SdrModel* pModel, const OUString& sTableStyle )
85 : {
86 0 : if( pModel && pObj )
87 : {
88 0 : Reference< XNameAccess > xPool( dynamic_cast< XNameAccess* >( pModel->GetStyleSheetPool() ) );
89 0 : if( xPool.is() ) try
90 : {
91 0 : const OUString sFamilyName("table" );
92 0 : Reference< XNameContainer > xTableFamily( xPool->getByName( sFamilyName ), UNO_QUERY_THROW );
93 0 : OUString aStdName( "default" );
94 0 : if( !sTableStyle.isEmpty() )
95 0 : aStdName = sTableStyle;
96 0 : Reference< XIndexAccess > xStyle( xTableFamily->getByName( aStdName ), UNO_QUERY_THROW );
97 0 : pObj->setTableStyle( xStyle );
98 : }
99 0 : catch( Exception& )
100 : {
101 : OSL_FAIL("sd::apply_default_table_style(), exception caught!");
102 0 : }
103 : }
104 0 : }
105 :
106 0 : void DrawViewShell::FuTable(SfxRequest& rReq)
107 : {
108 0 : switch( rReq.GetSlot() )
109 : {
110 : case SID_INSERT_TABLE:
111 : {
112 0 : sal_Int32 nColumns = 0;
113 0 : sal_Int32 nRows = 0;
114 0 : OUString sTableStyle;
115 :
116 0 : SFX_REQUEST_ARG( rReq, pCols, SfxUInt16Item, SID_ATTR_TABLE_COLUMN, false );
117 0 : SFX_REQUEST_ARG( rReq, pRows, SfxUInt16Item, SID_ATTR_TABLE_ROW, false );
118 0 : SFX_REQUEST_ARG( rReq, pStyle, SfxStringItem, SID_TABLE_STYLE, false );
119 :
120 0 : if( pCols )
121 0 : nColumns = pCols->GetValue();
122 :
123 0 : if( pRows )
124 0 : nRows = pRows->GetValue();
125 :
126 0 : if( pStyle )
127 0 : sTableStyle = pStyle->GetValue();
128 :
129 0 : if( (nColumns == 0) || (nRows == 0) )
130 : {
131 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
132 0 : boost::scoped_ptr<SvxAbstractNewTableDialog> pDlg( pFact ? pFact->CreateSvxNewTableDialog( NULL ) : 0);
133 :
134 0 : if( !pDlg.get() || (pDlg->Execute() != RET_OK) )
135 0 : break;
136 :
137 0 : nColumns = pDlg->getColumns();
138 0 : nRows = pDlg->getRows();
139 : }
140 :
141 0 : Rectangle aRect;
142 :
143 0 : SdrObject* pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_TABLE );
144 0 : if( pPickObj )
145 : {
146 0 : aRect = pPickObj->GetLogicRect();
147 0 : aRect.setHeight( 200 );
148 : }
149 : else
150 : {
151 0 : Size aSize( 14100, 200 );
152 :
153 0 : Point aPos;
154 0 : Rectangle aWinRect(aPos, GetActiveWindow()->GetOutputSizePixel() );
155 0 : aPos = aWinRect.Center();
156 0 : aPos = GetActiveWindow()->PixelToLogic(aPos);
157 0 : aPos.X() -= aSize.Width() / 2;
158 0 : aPos.Y() -= aSize.Height() / 2;
159 0 : aRect = Rectangle(aPos, aSize);
160 : }
161 :
162 0 : sdr::table::SdrTableObj* pObj = new sdr::table::SdrTableObj( GetDoc(), aRect, nColumns, nRows );
163 0 : pObj->NbcSetStyleSheet( GetDoc()->GetDefaultStyleSheet(), true );
164 0 : apply_table_style( pObj, GetDoc(), sTableStyle );
165 0 : SdrPageView* pPV = mpView->GetSdrPageView();
166 :
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 0 : SdrTextObj* pCheckForTextEdit = dynamic_cast< SdrTextObj* >(pPickObj);
170 :
171 0 : if(pCheckForTextEdit && pCheckForTextEdit->IsInEditMode())
172 : {
173 0 : mpView->SdrEndTextEdit();
174 : }
175 :
176 : // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
177 0 : if( pPickObj )
178 : {
179 0 : SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
180 0 : if(pPage && pPage->IsPresObj(pPickObj))
181 : {
182 0 : pObj->SetUserCall( pPickObj->GetUserCall() );
183 0 : pPage->InsertPresObj( pObj, PRESOBJ_TABLE );
184 : }
185 : }
186 :
187 0 : GetParentWindow()->GrabFocus();
188 0 : if( pPickObj )
189 0 : mpView->ReplaceObjectAtView(pPickObj, *pPV, pObj, true );
190 : else
191 0 : mpView->InsertObjectAtView(pObj, *pPV, SdrInsertFlags::SETDEFLAYER);
192 :
193 0 : Invalidate(SID_DRAWTBX_INSERT);
194 0 : rReq.Ignore();
195 0 : SfxViewShell* pViewShell = GetViewShell();
196 : OSL_ASSERT (pViewShell!=NULL);
197 0 : SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings();
198 0 : rBindings.Invalidate( SID_INSERT_TABLE, true, false );
199 0 : break;
200 : }
201 : case SID_TABLEDESIGN:
202 : {
203 0 : if( GetDoc() && (GetDoc()->GetDocumentType() == DOCUMENT_TYPE_DRAW) )
204 : {
205 : // in draw open a modal dialog since we have no tool pane yet
206 0 : showTableDesignDialog( GetActiveWindow(), GetViewShellBase() );
207 : }
208 : else
209 : {
210 : // Make the table design panel visible (expand it) in the
211 : // sidebar.
212 : ::sfx2::sidebar::Sidebar::ShowPanel(
213 : OUString("ImpressTableDesignPanel"),
214 0 : GetViewFrame()->GetFrame().GetFrameInterface());
215 : }
216 :
217 0 : Cancel();
218 0 : rReq.Done ();
219 : }
220 : default:
221 0 : break;
222 : }
223 0 : }
224 :
225 116 : void DrawViewShell::GetTableMenuState( SfxItemSet &rSet )
226 : {
227 116 : bool bIsUIActive = GetDocSh()->IsUIActive();
228 116 : if( bIsUIActive )
229 : {
230 0 : rSet.DisableItem( SID_INSERT_TABLE );
231 : }
232 : else
233 : {
234 116 : OUString aActiveLayer = mpDrawView->GetActiveLayer();
235 116 : SdrPageView* pPV = mpDrawView->GetSdrPageView();
236 :
237 232 : if( bIsUIActive ||
238 348 : ( !aActiveLayer.isEmpty() && pPV && ( pPV->IsLayerLocked(aActiveLayer) ||
239 348 : !pPV->IsLayerVisible(aActiveLayer) ) ) ||
240 116 : SD_MOD()->GetWaterCan() )
241 : {
242 0 : rSet.DisableItem( SID_INSERT_TABLE );
243 116 : }
244 : }
245 116 : }
246 :
247 0 : void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel )
248 : {
249 0 : rStream.Seek( 0 );
250 :
251 0 : if( pModel )
252 : {
253 0 : SdrPage* pPage = pModel->GetPage(0);
254 0 : if( pPage )
255 : {
256 0 : Size aSize( 200, 200 );
257 0 : Point aPos;
258 0 : Rectangle aRect (aPos, aSize);
259 0 : sdr::table::SdrTableObj* pObj = new sdr::table::SdrTableObj( pModel, aRect, 1, 1 );
260 0 : pObj->NbcSetStyleSheet( pModel->GetDefaultStyleSheet(), true );
261 0 : OUString sTableStyle;
262 0 : apply_table_style( pObj, pModel, sTableStyle );
263 :
264 0 : pPage->NbcInsertObject( pObj );
265 :
266 0 : sdr::table::SdrTableObj::ImportAsRTF( rStream, *pObj );
267 : }
268 : }
269 0 : }
270 :
271 66 : }
272 :
273 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|