1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include <sfx2/msg.hxx>
28 #include <sfx2/app.hxx>
29 #include <sfx2/sfxsids.hrc>
30 #include <sfx2/request.hxx>
31 #include <sfx2/objface.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/msgpool.hxx>
35 #include <svl/whiter.hxx>
36 #include <svl/itempool.hxx>
37 #include <svx/svdomedia.hxx>
38 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
39 #include <svx/svxdlg.hxx>
40 #include <svx/dialogs.hrc>
41 #include <svx/svxids.hrc>
42 
43 #include "app.hrc"
44 #include "res_bmp.hrc"
45 #include "glob.hrc"
46 #include "strings.hrc"
47 #include "DrawDocShell.hxx"
48 #include "ViewShell.hxx"
49 #include "Window.hxx"
50 #include "drawview.hxx"
51 #include "sdresid.hxx"
52 #include "drawdoc.hxx"
53 #include "DrawViewShell.hxx"
54 
55 #include "tableobjectbar.hxx"
56 
57 using namespace sd;
58 using namespace sd::ui::table;
59 
60 #define TableObjectBar
61 #include "sdslots.hxx"
62 
63 
64 namespace sd { namespace ui { namespace table {
65 
66 /** creates a table object bar for the given ViewShell */
67 SfxShell* CreateTableObjectBar( ViewShell& rShell, ::sd::View* pView )
68 {
69 	return new TableObjectBar( &rShell, pView );
70 }
71 
72 
73 /** registers the interfaces from the table ui */
74 void RegisterInterfaces(SfxModule* pMod)
75 {
76 	TableObjectBar::RegisterInterface(pMod);
77 }
78 
79 // ------------------
80 // - TableObjectBar -
81 // ------------------
82 
83 TYPEINIT1( TableObjectBar, SfxShell );
84 
85 // -----------------------------------------------------------------------------
86 
87 SFX_IMPL_INTERFACE( TableObjectBar, SfxShell, SdResId( STR_TABLEOBJECTBARSHELL ) )
88 {
89 }
90 
91 // -----------------------------------------------------------------------------
92 
93 TableObjectBar::TableObjectBar( ViewShell* pSdViewShell, ::sd::View* pSdView )
94 :	SfxShell( pSdViewShell->GetViewShell() )
95 ,	mpView( pSdView )
96 ,	mpViewSh( pSdViewShell )
97 {
98 	DrawDocShell* pDocShell = mpViewSh->GetDocSh();
99 	if( pDocShell )
100 	{
101 		SetPool( &pDocShell->GetPool() );
102 		SetUndoManager( pDocShell->GetUndoManager() );
103 	}
104 	SetRepeatTarget( mpView );
105 	SetHelpId( SD_IF_SDDRAWTABLEOBJECTBAR );
106 	SetName( String( SdResId( RID_DRAW_TABLE_TOOLBOX ) ) );
107 }
108 
109 // -----------------------------------------------------------------------------
110 
111 TableObjectBar::~TableObjectBar()
112 {
113 	SetRepeatTarget( NULL );
114 }
115 
116 // -----------------------------------------------------------------------------
117 
118 void TableObjectBar::GetState( SfxItemSet& rSet )
119 {
120 	bool bReadOnly = false;
121 
122 	if( bReadOnly )
123 	{
124         rSet.DisableItem (SID_INSERT_TABLE );
125 	}
126 
127 	if( mpView )
128 	{
129 		rtl::Reference< sdr::SelectionController > xController( mpView->getSelectionController() );
130 		if( xController.is() )
131 		{
132 			xController->GetState( rSet );
133 		}
134 	}
135 }
136 
137 // -----------------------------------------------------------------------------
138 
139 void TableObjectBar::GetAttrState( SfxItemSet& rSet )
140 {
141 	DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >( mpViewSh );
142 	if( pDrawViewShell )
143 		pDrawViewShell->GetAttrState( rSet );
144 }
145 
146 // -----------------------------------------------------------------------------
147 
148 void TableObjectBar::Execute( SfxRequest& rReq )
149 {
150 	if( mpView )
151 	{
152 		SdrView* pView = mpView;
153 		SfxBindings* pBindings = &mpViewSh->GetViewFrame()->GetBindings();
154 
155 		rtl::Reference< sdr::SelectionController > xController( mpView->getSelectionController() );
156 		sal_uLong nSlotId = rReq.GetSlot();
157 		if( xController.is() )
158 		{
159 		    switch( nSlotId )
160 		    {
161 		    case SID_TABLE_INSERT_ROW_DLG:
162 		    case SID_TABLE_INSERT_COL_DLG:
163 		    {
164                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
165 	            ::std::auto_ptr<SvxAbstractInsRowColDlg> pDlg( pFact ? pFact->CreateSvxInsRowColDlg( mpView->GetViewShell()->GetParentWindow(), nSlotId == SID_TABLE_INSERT_COL_DLG, SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommand()) : 0);
166 
167 		        if( pDlg.get() && (pDlg->Execute() == 1) )
168 		        {
169 		            if( nSlotId == SID_TABLE_INSERT_ROW_DLG )
170 		                nSlotId = SID_TABLE_INSERT_ROW;
171 		            else
172 		                nSlotId = SID_TABLE_INSERT_COL;
173 
174 		            rReq.AppendItem( SfxInt16Item( (sal_uInt16)nSlotId, (sal_uInt16)pDlg->getInsertCount() ) );
175 		            rReq.AppendItem( SfxBoolItem( SID_TABLE_PARAM_INSERT_AFTER, !pDlg->isInsertBefore() ) );
176 
177 		             rReq.SetSlot( (sal_uInt16)nSlotId );
178 		        }
179 		    }
180 		    }
181 
182 			xController->Execute( rReq );
183 		}
184 
185 		// note: we may be deleted at this point, no more member access possible
186 
187 		switch( rReq.GetSlot() )
188 		{
189 		case SID_ATTR_BORDER:
190 		case SID_TABLE_MERGE_CELLS:
191 		case SID_TABLE_SPLIT_CELLS:
192 		case SID_OPTIMIZE_TABLE:
193 		case SID_TABLE_DELETE_ROW:
194 		case SID_TABLE_DELETE_COL:
195 		case SID_FORMAT_TABLE_DLG:
196 		case SID_TABLE_INSERT_ROW:
197 		case SID_TABLE_INSERT_COL:
198 		{
199 			pView->AdjustMarkHdl();
200 			pBindings->Invalidate( SID_TABLE_DELETE_ROW );
201 			pBindings->Invalidate( SID_TABLE_DELETE_COL );
202 			pBindings->Invalidate( SID_FRAME_LINESTYLE );
203 			pBindings->Invalidate( SID_FRAME_LINECOLOR );
204 			pBindings->Invalidate( SID_ATTR_BORDER );
205 			pBindings->Invalidate( SID_ATTR_FILL_STYLE );
206 			pBindings->Invalidate( SID_ATTR_FILL_TRANSPARENCE );
207 			pBindings->Invalidate( SID_ATTR_FILL_FLOATTRANSPARENCE );
208 			pBindings->Invalidate( SID_TABLE_MERGE_CELLS );
209 			pBindings->Invalidate( SID_TABLE_SPLIT_CELLS );
210 			pBindings->Invalidate( SID_OPTIMIZE_TABLE );
211 			pBindings->Invalidate( SID_TABLE_VERT_BOTTOM );
212 			pBindings->Invalidate( SID_TABLE_VERT_CENTER );
213 			pBindings->Invalidate( SID_TABLE_VERT_NONE );
214 			break;
215 		}
216 		case SID_TABLE_VERT_BOTTOM:
217 		case SID_TABLE_VERT_CENTER:
218 		case SID_TABLE_VERT_NONE:
219 		{
220 			pBindings->Invalidate( SID_TABLE_VERT_BOTTOM );
221 			pBindings->Invalidate( SID_TABLE_VERT_CENTER );
222 			pBindings->Invalidate( SID_TABLE_VERT_NONE );
223 			break;
224 		}
225 		}
226 
227 		pBindings->Invalidate( SID_UNDO );
228 		pBindings->Invalidate( SID_REDO );
229 	}
230 }
231 
232 } } }
233