Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <sal/config.h>
31 : : #include <com/sun/star/uno/XComponentContext.hpp>
32 : : #include <com/sun/star/drawing/XSelectionFunction.hpp>
33 : : #include <com/sun/star/awt/KeyModifier.hpp>
34 : : #include <com/sun/star/lang/XInitialization.hpp>
35 : :
36 : : #include <cppuhelper/compbase2.hxx>
37 : : #include <cppuhelper/basemutex.hxx>
38 : :
39 : : #include <vcl/svapp.hxx>
40 : :
41 : : #include <svx/svdotable.hxx>
42 : : #include <svx/sdr/overlay/overlayobjectcell.hxx>
43 : : #include <svx/sdr/overlay/overlaymanager.hxx>
44 : : #include <svx/svxids.hrc>
45 : : #include <editeng/outlobj.hxx>
46 : : #include <svx/svdoutl.hxx>
47 : : #include <svx/svdpagv.hxx>
48 : : #include <svx/svdetc.hxx>
49 : : #include <editeng/editstat.hxx>
50 : : #include <editeng/unolingu.hxx>
51 : : #include <svx/sdrpagewindow.hxx>
52 : : #include <svx/sdr/table/tabledesign.hxx>
53 : : #include <svx/svxdlg.hxx>
54 : : #include <vcl/msgbox.hxx>
55 : :
56 : : #include <svl/itempool.hxx>
57 : : #include <sfx2/viewfrm.hxx>
58 : : #include <sfx2/dispatch.hxx>
59 : : #include <sfx2/bindings.hxx>
60 : : #include <sfx2/request.hxx>
61 : : #include <svl/style.hxx>
62 : :
63 : : #include "framework/FrameworkHelper.hxx"
64 : : #include "app.hrc"
65 : : #include "glob.hrc"
66 : : #include "DrawViewShell.hxx"
67 : : #include "drawdoc.hxx"
68 : : #include "DrawDocShell.hxx"
69 : : #include "Window.hxx"
70 : : #include "drawview.hxx"
71 : : #include "sdresid.hxx"
72 : : #include "undo/undoobjects.hxx"
73 : :
74 : : using ::rtl::OUString;
75 : : using namespace ::sd;
76 : : using namespace ::sdr::table;
77 : : using namespace ::com::sun::star;
78 : : using namespace ::com::sun::star::uno;
79 : : using namespace ::com::sun::star::beans;
80 : : using namespace ::com::sun::star::util;
81 : : using namespace ::com::sun::star::frame;
82 : : using namespace ::com::sun::star::container;
83 : : using namespace ::com::sun::star::lang;
84 : : using namespace ::com::sun::star::drawing;
85 : : using namespace ::com::sun::star::linguistic2;
86 : :
87 : : namespace sd
88 : : {
89 : : extern void showTableDesignDialog( ::Window*, ViewShellBase& );
90 : :
91 : 0 : static void apply_table_style( SdrTableObj* pObj, SdrModel* pModel, const OUString& sTableStyle )
92 : : {
93 [ # # ][ # # ]: 0 : if( pModel && pObj )
94 : : {
95 [ # # ][ # # ]: 0 : Reference< XNameAccess > xPool( dynamic_cast< XNameAccess* >( pModel->GetStyleSheetPool() ) );
[ # # ]
96 [ # # ]: 0 : if( xPool.is() ) try
97 : : {
98 : 0 : const OUString sFamilyName("table" );
99 [ # # ][ # # ]: 0 : Reference< XNameContainer > xTableFamily( xPool->getByName( sFamilyName ), UNO_QUERY_THROW );
[ # # ]
100 : 0 : OUString aStdName( "default" );
101 [ # # ]: 0 : if( !sTableStyle.isEmpty() )
102 : 0 : aStdName = sTableStyle;
103 [ # # ][ # # ]: 0 : Reference< XIndexAccess > xStyle( xTableFamily->getByName( aStdName ), UNO_QUERY_THROW );
[ # # ]
104 [ # # ][ # # ]: 0 : pObj->setTableStyle( xStyle );
105 : : }
106 [ # # ]: 0 : catch( Exception& )
107 : : {
108 : : OSL_FAIL("sd::apply_default_table_style(), exception caught!");
109 : 0 : }
110 : : }
111 : 0 : }
112 : :
113 : 0 : void DrawViewShell::FuTable(SfxRequest& rReq)
114 : : {
115 [ # # # ]: 0 : switch( rReq.GetSlot() )
116 : : {
117 : : case SID_INSERT_TABLE:
118 : : {
119 : 0 : sal_Int32 nColumns = 0;
120 : 0 : sal_Int32 nRows = 0;
121 : 0 : OUString sTableStyle;
122 : :
123 [ # # ][ # # ]: 0 : SFX_REQUEST_ARG( rReq, pCols, SfxUInt16Item, SID_ATTR_TABLE_COLUMN, sal_False );
124 [ # # ][ # # ]: 0 : SFX_REQUEST_ARG( rReq, pRows, SfxUInt16Item, SID_ATTR_TABLE_ROW, sal_False );
125 [ # # ][ # # ]: 0 : SFX_REQUEST_ARG( rReq, pStyle, SfxStringItem, SID_TABLE_STYLE, sal_False );
126 : :
127 [ # # ]: 0 : if( pCols )
128 : 0 : nColumns = pCols->GetValue();
129 : :
130 [ # # ]: 0 : if( pRows )
131 : 0 : nRows = pRows->GetValue();
132 : :
133 [ # # ]: 0 : if( pStyle )
134 [ # # ]: 0 : sTableStyle = pStyle->GetValue();
135 : :
136 [ # # ][ # # ]: 0 : if( (nColumns == 0) || (nRows == 0) )
137 : : {
138 [ # # ]: 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
139 [ # # ][ # # ]: 0 : ::std::auto_ptr<SvxAbstractNewTableDialog> pDlg( pFact ? pFact->CreateSvxNewTableDialog( NULL ) : 0);
140 : :
141 [ # # ][ # # ]: 0 : if( !pDlg.get() || (pDlg->Execute() != RET_OK) )
[ # # ][ # # ]
142 : : break;
143 : :
144 [ # # ]: 0 : nColumns = pDlg->getColumns();
145 [ # # ][ # # ]: 0 : nRows = pDlg->getRows();
[ # # ]
146 : : }
147 : :
148 [ # # ]: 0 : Rectangle aRect;
149 : :
150 [ # # ]: 0 : SdrObject* pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_TABLE );
151 [ # # ]: 0 : if( pPickObj )
152 : : {
153 [ # # ]: 0 : aRect = pPickObj->GetLogicRect();
154 : 0 : aRect.setHeight( 200 );
155 : : }
156 : : else
157 : : {
158 : 0 : Size aSize( 14100, 200 );
159 : :
160 : 0 : Point aPos;
161 [ # # ][ # # ]: 0 : Rectangle aWinRect(aPos, GetActiveWindow()->GetOutputSizePixel() );
162 [ # # ]: 0 : aPos = aWinRect.Center();
163 [ # # ][ # # ]: 0 : aPos = GetActiveWindow()->PixelToLogic(aPos);
164 : 0 : aPos.X() -= aSize.Width() / 2;
165 : 0 : aPos.Y() -= aSize.Height() / 2;
166 [ # # ]: 0 : aRect = Rectangle(aPos, aSize);
167 : : }
168 : :
169 [ # # ][ # # ]: 0 : ::sdr::table::SdrTableObj* pObj = new ::sdr::table::SdrTableObj( GetDoc(), aRect, nColumns, nRows );
[ # # ]
170 [ # # ][ # # ]: 0 : pObj->NbcSetStyleSheet( GetDoc()->GetDefaultStyleSheet(), sal_True );
171 [ # # ][ # # ]: 0 : apply_table_style( pObj, GetDoc(), sTableStyle );
172 : 0 : SdrPageView* pPV = mpView->GetSdrPageView();
173 : :
174 : : // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
175 [ # # ]: 0 : if( pPickObj )
176 : : {
177 [ # # ]: 0 : SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
178 [ # # ][ # # ]: 0 : if(pPage && pPage->IsPresObj(pPickObj))
[ # # ][ # # ]
179 : : {
180 [ # # ][ # # ]: 0 : pObj->SetUserCall( pPickObj->GetUserCall() );
181 [ # # ]: 0 : pPage->InsertPresObj( pObj, PRESOBJ_TABLE );
182 : : }
183 : : }
184 : :
185 [ # # ]: 0 : GetParentWindow()->GrabFocus();
186 [ # # ]: 0 : if( pPickObj )
187 [ # # ]: 0 : mpView->ReplaceObjectAtView(pPickObj, *pPV, pObj, sal_True );
188 : : else
189 [ # # ]: 0 : mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER);
190 : :
191 [ # # ]: 0 : Invalidate(SID_DRAWTBX_INSERT);
192 [ # # ]: 0 : rReq.Ignore();
193 [ # # ]: 0 : SfxViewShell* pViewShell = GetViewShell();
194 : : OSL_ASSERT (pViewShell!=NULL);
195 : 0 : SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings();
196 [ # # ]: 0 : rBindings.Invalidate( SID_INSERT_TABLE, sal_True, sal_False );
197 : 0 : break;
198 : : }
199 : : case SID_TABLEDESIGN:
200 : : {
201 [ # # ][ # # ]: 0 : if( GetDoc() && (GetDoc()->GetDocumentType() == DOCUMENT_TYPE_DRAW) )
[ # # ]
202 : : {
203 : : // in draw open a modal dialog since we have no tool pane yet
204 : 0 : showTableDesignDialog( GetActiveWindow(), GetViewShellBase() );
205 : : }
206 : : else
207 : : {
208 : : // Make the slide transition panel visible (expand it) in the
209 : : // tool pane.
210 : 0 : framework::FrameworkHelper::Instance(GetViewShellBase())->RequestTaskPanel(
211 [ # # ]: 0 : framework::FrameworkHelper::msTableDesignPanelURL);
212 : : }
213 : :
214 : 0 : Cancel();
215 : 0 : rReq.Done ();
216 : : }
217 : : default:
218 : 0 : break;
219 : : }
220 : 0 : }
221 : :
222 : : // --------------------------------------------------------------------
223 : :
224 : 36 : void DrawViewShell::GetTableMenuState( SfxItemSet &rSet )
225 : : {
226 : 36 : bool bIsUIActive = GetDocSh()->IsUIActive();
227 [ - + ]: 36 : if( bIsUIActive )
228 : : {
229 : 0 : rSet.DisableItem( SID_INSERT_TABLE );
230 : : }
231 : : else
232 : : {
233 [ + - ]: 36 : String aActiveLayer = mpDrawView->GetActiveLayer();
234 : 36 : SdrPageView* pPV = mpDrawView->GetSdrPageView();
235 : :
236 [ + - ][ + - ]: 180 : if( bIsUIActive ||
[ + - - + ]
[ - + ]
[ + - + - ]
237 [ + - ]: 72 : ( aActiveLayer.Len() != 0 && pPV && ( pPV->IsLayerLocked(aActiveLayer) ||
238 [ + - ]: 36 : !pPV->IsLayerVisible(aActiveLayer) ) ) ||
239 [ + - ]: 36 : SD_MOD()->GetWaterCan() )
240 : : {
241 [ # # ]: 0 : rSet.DisableItem( SID_INSERT_TABLE );
242 [ + - ]: 36 : }
243 : : }
244 : 36 : }
245 : :
246 : : // --------------------------------------------------------------------
247 : :
248 : 0 : void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel )
249 : : {
250 : 0 : rStream.Seek( 0 );
251 : :
252 [ # # ]: 0 : if( pModel )
253 : : {
254 : 0 : SdrPage* pPage = pModel->GetPage(0);
255 [ # # ]: 0 : if( pPage )
256 : : {
257 : 0 : Size aSize( 200, 200 );
258 : 0 : Point aPos;
259 [ # # ]: 0 : Rectangle aRect (aPos, aSize);
260 [ # # ][ # # ]: 0 : ::sdr::table::SdrTableObj* pObj = new ::sdr::table::SdrTableObj( pModel, aRect, 1, 1 );
261 [ # # ]: 0 : pObj->NbcSetStyleSheet( pModel->GetDefaultStyleSheet(), sal_True );
262 : 0 : OUString sTableStyle;
263 [ # # ]: 0 : apply_table_style( pObj, pModel, sTableStyle );
264 : :
265 [ # # ]: 0 : pPage->NbcInsertObject( pObj );
266 : :
267 [ # # ]: 0 : sdr::table::SdrTableObj::ImportAsRTF( rStream, *pObj );
268 : : }
269 : : }
270 : 0 : }
271 : :
272 : : }
273 : :
274 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|