1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
27 #include <cppuhelper/compbase2.hxx>
28 #include <cppuhelper/basemutex.hxx>
30 #include <vcl/svapp.hxx>
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>
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>
54 #include "framework/FrameworkHelper.hxx"
57 #include "DrawViewShell.hxx"
58 #include "drawdoc.hxx"
59 #include "DrawDocShell.hxx"
61 #include "drawview.hxx"
62 #include "sdresid.hxx"
63 #include "undo/undoobjects.hxx"
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
;
79 extern void showTableDesignDialog( ::Window
*, ViewShellBase
& );
81 static void apply_table_style( SdrTableObj
* pObj
, SdrModel
* pModel
, const OUString
& sTableStyle
)
85 Reference
< XNameAccess
> xPool( dynamic_cast< XNameAccess
* >( pModel
->GetStyleSheetPool() ) );
88 const OUString
sFamilyName("table" );
89 Reference
< XNameContainer
> xTableFamily( xPool
->getByName( sFamilyName
), UNO_QUERY_THROW
);
90 OUString
aStdName( "default" );
91 if( !sTableStyle
.isEmpty() )
92 aStdName
= sTableStyle
;
93 Reference
< XIndexAccess
> xStyle( xTableFamily
->getByName( aStdName
), UNO_QUERY_THROW
);
94 pObj
->setTableStyle( xStyle
);
98 OSL_FAIL("sd::apply_default_table_style(), exception caught!");
103 void DrawViewShell::FuTable(SfxRequest
& rReq
)
105 switch( rReq
.GetSlot() )
107 case SID_INSERT_TABLE
:
109 sal_Int32 nColumns
= 0;
111 OUString sTableStyle
;
113 SFX_REQUEST_ARG( rReq
, pCols
, SfxUInt16Item
, SID_ATTR_TABLE_COLUMN
, sal_False
);
114 SFX_REQUEST_ARG( rReq
, pRows
, SfxUInt16Item
, SID_ATTR_TABLE_ROW
, sal_False
);
115 SFX_REQUEST_ARG( rReq
, pStyle
, SfxStringItem
, SID_TABLE_STYLE
, sal_False
);
118 nColumns
= pCols
->GetValue();
121 nRows
= pRows
->GetValue();
124 sTableStyle
= pStyle
->GetValue();
126 if( (nColumns
== 0) || (nRows
== 0) )
128 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
129 ::std::auto_ptr
<SvxAbstractNewTableDialog
> pDlg( pFact
? pFact
->CreateSvxNewTableDialog( NULL
) : 0);
131 if( !pDlg
.get() || (pDlg
->Execute() != RET_OK
) )
134 nColumns
= pDlg
->getColumns();
135 nRows
= pDlg
->getRows();
140 SdrObject
* pPickObj
= mpView
->GetEmptyPresentationObject( PRESOBJ_TABLE
);
143 aRect
= pPickObj
->GetLogicRect();
144 aRect
.setHeight( 200 );
148 Size
aSize( 14100, 200 );
151 Rectangle
aWinRect(aPos
, GetActiveWindow()->GetOutputSizePixel() );
152 aPos
= aWinRect
.Center();
153 aPos
= GetActiveWindow()->PixelToLogic(aPos
);
154 aPos
.X() -= aSize
.Width() / 2;
155 aPos
.Y() -= aSize
.Height() / 2;
156 aRect
= Rectangle(aPos
, aSize
);
159 ::sdr::table::SdrTableObj
* pObj
= new ::sdr::table::SdrTableObj( GetDoc(), aRect
, nColumns
, nRows
);
160 pObj
->NbcSetStyleSheet( GetDoc()->GetDefaultStyleSheet(), sal_True
);
161 apply_table_style( pObj
, GetDoc(), sTableStyle
);
162 SdrPageView
* pPV
= mpView
->GetSdrPageView();
164 // #i123359# if an object is to be replaced/manipulated it may be that it is in text edit mode,
165 // so to be on the safe side call SdrEndTextEdit here
166 SdrTextObj
* pCheckForTextEdit
= dynamic_cast< SdrTextObj
* >(pPickObj
);
168 if(pCheckForTextEdit
&& pCheckForTextEdit
->IsInEditMode())
170 mpView
->SdrEndTextEdit();
173 // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
176 SdPage
* pPage
= static_cast< SdPage
* >(pPickObj
->GetPage());
177 if(pPage
&& pPage
->IsPresObj(pPickObj
))
179 pObj
->SetUserCall( pPickObj
->GetUserCall() );
180 pPage
->InsertPresObj( pObj
, PRESOBJ_TABLE
);
184 GetParentWindow()->GrabFocus();
186 mpView
->ReplaceObjectAtView(pPickObj
, *pPV
, pObj
, sal_True
);
188 mpView
->InsertObjectAtView(pObj
, *pPV
, SDRINSERT_SETDEFLAYER
);
190 Invalidate(SID_DRAWTBX_INSERT
);
192 SfxViewShell
* pViewShell
= GetViewShell();
193 OSL_ASSERT (pViewShell
!=NULL
);
194 SfxBindings
& rBindings
= pViewShell
->GetViewFrame()->GetBindings();
195 rBindings
.Invalidate( SID_INSERT_TABLE
, sal_True
, sal_False
);
198 case SID_TABLEDESIGN
:
200 if( GetDoc() && (GetDoc()->GetDocumentType() == DOCUMENT_TYPE_DRAW
) )
202 // in draw open a modal dialog since we have no tool pane yet
203 showTableDesignDialog( GetActiveWindow(), GetViewShellBase() );
207 // Make the slide transition panel visible (expand it) in the
209 framework::FrameworkHelper::Instance(GetViewShellBase())->RequestSidebarPanel(
210 framework::FrameworkHelper::msTableDesignPanelURL
);
221 // --------------------------------------------------------------------
223 void DrawViewShell::GetTableMenuState( SfxItemSet
&rSet
)
225 bool bIsUIActive
= GetDocSh()->IsUIActive();
228 rSet
.DisableItem( SID_INSERT_TABLE
);
232 String aActiveLayer
= mpDrawView
->GetActiveLayer();
233 SdrPageView
* pPV
= mpDrawView
->GetSdrPageView();
236 ( aActiveLayer
.Len() != 0 && pPV
&& ( pPV
->IsLayerLocked(aActiveLayer
) ||
237 !pPV
->IsLayerVisible(aActiveLayer
) ) ) ||
238 SD_MOD()->GetWaterCan() )
240 rSet
.DisableItem( SID_INSERT_TABLE
);
245 // --------------------------------------------------------------------
247 void CreateTableFromRTF( SvStream
& rStream
, SdDrawDocument
* pModel
)
253 SdrPage
* pPage
= pModel
->GetPage(0);
256 Size
aSize( 200, 200 );
258 Rectangle
aRect (aPos
, aSize
);
259 ::sdr::table::SdrTableObj
* pObj
= new ::sdr::table::SdrTableObj( pModel
, aRect
, 1, 1 );
260 pObj
->NbcSetStyleSheet( pModel
->GetDefaultStyleSheet(), sal_True
);
261 OUString sTableStyle
;
262 apply_table_style( pObj
, pModel
, sTableStyle
);
264 pPage
->NbcInsertObject( pObj
);
266 sdr::table::SdrTableObj::ImportAsRTF( rStream
, *pObj
);
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */