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