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