1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <sfx2/msg.hxx>
32*cdf0e10cSrcweir #include <sfx2/app.hxx>
33*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
34*cdf0e10cSrcweir #include <sfx2/request.hxx>
35*cdf0e10cSrcweir #include <sfx2/objface.hxx>
36*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
37*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
38*cdf0e10cSrcweir #include <sfx2/msgpool.hxx>
39*cdf0e10cSrcweir #include <svl/whiter.hxx>
40*cdf0e10cSrcweir #include <svl/itempool.hxx>
41*cdf0e10cSrcweir #include <svx/svdomedia.hxx>
42*cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
43*cdf0e10cSrcweir #include <svx/svxdlg.hxx>
44*cdf0e10cSrcweir #include <svx/dialogs.hrc>
45*cdf0e10cSrcweir #include <svx/svxids.hrc>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include "app.hrc"
48*cdf0e10cSrcweir #include "res_bmp.hrc"
49*cdf0e10cSrcweir #include "glob.hrc"
50*cdf0e10cSrcweir #include "strings.hrc"
51*cdf0e10cSrcweir #include "DrawDocShell.hxx"
52*cdf0e10cSrcweir #include "ViewShell.hxx"
53*cdf0e10cSrcweir #include "Window.hxx"
54*cdf0e10cSrcweir #include "drawview.hxx"
55*cdf0e10cSrcweir #include "sdresid.hxx"
56*cdf0e10cSrcweir #include "drawdoc.hxx"
57*cdf0e10cSrcweir #include "DrawViewShell.hxx"
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #include "tableobjectbar.hxx"
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir using namespace sd;
62*cdf0e10cSrcweir using namespace sd::ui::table;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #define TableObjectBar
65*cdf0e10cSrcweir #include "sdslots.hxx"
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir namespace sd { namespace ui { namespace table {
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir /** creates a table object bar for the given ViewShell */
71*cdf0e10cSrcweir SfxShell* CreateTableObjectBar( ViewShell& rShell, ::sd::View* pView )
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir 	return new TableObjectBar( &rShell, pView );
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir /** registers the interfaces from the table ui */
78*cdf0e10cSrcweir void RegisterInterfaces(SfxModule* pMod)
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	TableObjectBar::RegisterInterface(pMod);
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir // ------------------
84*cdf0e10cSrcweir // - TableObjectBar -
85*cdf0e10cSrcweir // ------------------
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir TYPEINIT1( TableObjectBar, SfxShell );
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir // -----------------------------------------------------------------------------
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir SFX_IMPL_INTERFACE( TableObjectBar, SfxShell, SdResId( STR_TABLEOBJECTBARSHELL ) )
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir // -----------------------------------------------------------------------------
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir TableObjectBar::TableObjectBar( ViewShell* pSdViewShell, ::sd::View* pSdView )
98*cdf0e10cSrcweir :	SfxShell( pSdViewShell->GetViewShell() )
99*cdf0e10cSrcweir ,	mpView( pSdView )
100*cdf0e10cSrcweir ,	mpViewSh( pSdViewShell )
101*cdf0e10cSrcweir {
102*cdf0e10cSrcweir 	DrawDocShell* pDocShell = mpViewSh->GetDocSh();
103*cdf0e10cSrcweir 	if( pDocShell )
104*cdf0e10cSrcweir 	{
105*cdf0e10cSrcweir 		SetPool( &pDocShell->GetPool() );
106*cdf0e10cSrcweir 		SetUndoManager( pDocShell->GetUndoManager() );
107*cdf0e10cSrcweir 	}
108*cdf0e10cSrcweir 	SetRepeatTarget( mpView );
109*cdf0e10cSrcweir 	SetHelpId( SD_IF_SDDRAWTABLEOBJECTBAR );
110*cdf0e10cSrcweir 	SetName( String( SdResId( RID_DRAW_TABLE_TOOLBOX ) ) );
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir // -----------------------------------------------------------------------------
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir TableObjectBar::~TableObjectBar()
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir 	SetRepeatTarget( NULL );
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir // -----------------------------------------------------------------------------
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir void TableObjectBar::GetState( SfxItemSet& rSet )
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir 	bool bReadOnly = false;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 	if( bReadOnly )
127*cdf0e10cSrcweir 	{
128*cdf0e10cSrcweir         rSet.DisableItem (SID_INSERT_TABLE );
129*cdf0e10cSrcweir 	}
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	if( mpView )
132*cdf0e10cSrcweir 	{
133*cdf0e10cSrcweir 		rtl::Reference< sdr::SelectionController > xController( mpView->getSelectionController() );
134*cdf0e10cSrcweir 		if( xController.is() )
135*cdf0e10cSrcweir 		{
136*cdf0e10cSrcweir 			xController->GetState( rSet );
137*cdf0e10cSrcweir 		}
138*cdf0e10cSrcweir 	}
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir // -----------------------------------------------------------------------------
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir void TableObjectBar::GetAttrState( SfxItemSet& rSet )
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir 	DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >( mpViewSh );
146*cdf0e10cSrcweir 	if( pDrawViewShell )
147*cdf0e10cSrcweir 		pDrawViewShell->GetAttrState( rSet );
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir // -----------------------------------------------------------------------------
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir void TableObjectBar::Execute( SfxRequest& rReq )
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir 	if( mpView )
155*cdf0e10cSrcweir 	{
156*cdf0e10cSrcweir 		SdrView* pView = mpView;
157*cdf0e10cSrcweir 		SfxBindings* pBindings = &mpViewSh->GetViewFrame()->GetBindings();
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 		rtl::Reference< sdr::SelectionController > xController( mpView->getSelectionController() );
160*cdf0e10cSrcweir 		sal_uLong nSlotId = rReq.GetSlot();
161*cdf0e10cSrcweir 		if( xController.is() )
162*cdf0e10cSrcweir 		{
163*cdf0e10cSrcweir 		    switch( nSlotId )
164*cdf0e10cSrcweir 		    {
165*cdf0e10cSrcweir 		    case SID_TABLE_INSERT_ROW_DLG:
166*cdf0e10cSrcweir 		    case SID_TABLE_INSERT_COL_DLG:
167*cdf0e10cSrcweir 		    {
168*cdf0e10cSrcweir                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
169*cdf0e10cSrcweir 	            ::std::auto_ptr<SvxAbstractInsRowColDlg> pDlg( pFact ? pFact->CreateSvxInsRowColDlg( mpView->GetViewShell()->GetParentWindow(), nSlotId == SID_TABLE_INSERT_COL_DLG, SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommand()) : 0);
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 		        if( pDlg.get() && (pDlg->Execute() == 1) )
172*cdf0e10cSrcweir 		        {
173*cdf0e10cSrcweir 		            if( nSlotId == SID_TABLE_INSERT_ROW_DLG )
174*cdf0e10cSrcweir 		                nSlotId = SID_TABLE_INSERT_ROW;
175*cdf0e10cSrcweir 		            else
176*cdf0e10cSrcweir 		                nSlotId = SID_TABLE_INSERT_COL;
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 		            rReq.AppendItem( SfxInt16Item( (sal_uInt16)nSlotId, (sal_uInt16)pDlg->getInsertCount() ) );
179*cdf0e10cSrcweir 		            rReq.AppendItem( SfxBoolItem( SID_TABLE_PARAM_INSERT_AFTER, !pDlg->isInsertBefore() ) );
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 		             rReq.SetSlot( (sal_uInt16)nSlotId );
182*cdf0e10cSrcweir 		        }
183*cdf0e10cSrcweir 		    }
184*cdf0e10cSrcweir 		    }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 			xController->Execute( rReq );
187*cdf0e10cSrcweir 		}
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 		// note: we may be deleted at this point, no more member access possible
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 		switch( rReq.GetSlot() )
192*cdf0e10cSrcweir 		{
193*cdf0e10cSrcweir 		case SID_ATTR_BORDER:
194*cdf0e10cSrcweir 		case SID_TABLE_MERGE_CELLS:
195*cdf0e10cSrcweir 		case SID_TABLE_SPLIT_CELLS:
196*cdf0e10cSrcweir 		case SID_OPTIMIZE_TABLE:
197*cdf0e10cSrcweir 		case SID_TABLE_DELETE_ROW:
198*cdf0e10cSrcweir 		case SID_TABLE_DELETE_COL:
199*cdf0e10cSrcweir 		case SID_FORMAT_TABLE_DLG:
200*cdf0e10cSrcweir 		case SID_TABLE_INSERT_ROW:
201*cdf0e10cSrcweir 		case SID_TABLE_INSERT_COL:
202*cdf0e10cSrcweir 		{
203*cdf0e10cSrcweir 			pView->AdjustMarkHdl();
204*cdf0e10cSrcweir 			pBindings->Invalidate( SID_TABLE_DELETE_ROW );
205*cdf0e10cSrcweir 			pBindings->Invalidate( SID_TABLE_DELETE_COL );
206*cdf0e10cSrcweir 			pBindings->Invalidate( SID_FRAME_LINESTYLE );
207*cdf0e10cSrcweir 			pBindings->Invalidate( SID_FRAME_LINECOLOR );
208*cdf0e10cSrcweir 			pBindings->Invalidate( SID_ATTR_BORDER );
209*cdf0e10cSrcweir 			pBindings->Invalidate( SID_ATTR_FILL_STYLE );
210*cdf0e10cSrcweir 			pBindings->Invalidate( SID_TABLE_MERGE_CELLS );
211*cdf0e10cSrcweir 			pBindings->Invalidate( SID_TABLE_SPLIT_CELLS );
212*cdf0e10cSrcweir 			pBindings->Invalidate( SID_OPTIMIZE_TABLE );
213*cdf0e10cSrcweir 			pBindings->Invalidate( SID_TABLE_VERT_BOTTOM );
214*cdf0e10cSrcweir 			pBindings->Invalidate( SID_TABLE_VERT_CENTER );
215*cdf0e10cSrcweir 			pBindings->Invalidate( SID_TABLE_VERT_NONE );
216*cdf0e10cSrcweir 			break;
217*cdf0e10cSrcweir 		}
218*cdf0e10cSrcweir 		case SID_TABLE_VERT_BOTTOM:
219*cdf0e10cSrcweir 		case SID_TABLE_VERT_CENTER:
220*cdf0e10cSrcweir 		case SID_TABLE_VERT_NONE:
221*cdf0e10cSrcweir 		{
222*cdf0e10cSrcweir 			pBindings->Invalidate( SID_TABLE_VERT_BOTTOM );
223*cdf0e10cSrcweir 			pBindings->Invalidate( SID_TABLE_VERT_CENTER );
224*cdf0e10cSrcweir 			pBindings->Invalidate( SID_TABLE_VERT_NONE );
225*cdf0e10cSrcweir 			break;
226*cdf0e10cSrcweir 		}
227*cdf0e10cSrcweir 		}
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 		pBindings->Invalidate( SID_UNDO );
230*cdf0e10cSrcweir 		pBindings->Invalidate( SID_REDO );
231*cdf0e10cSrcweir 	}
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir } } }
235