xref: /AOO41X/main/sd/source/ui/table/tableobjectbar.cxx (revision ca62e2c2083b5d0995f1245bad6c2edfb455fbec)
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 <sfx2/sidebar/EnumContext.hxx>
36 #include <svl/whiter.hxx>
37 #include <svl/itempool.hxx>
38 #include <svx/svdomedia.hxx>
39 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
40 #include <svx/svxdlg.hxx>
41 #include <svx/dialogs.hrc>
42 #include <svx/svxids.hrc>
43 
44 #include "app.hrc"
45 #include "res_bmp.hrc"
46 #include "glob.hrc"
47 #include "strings.hrc"
48 #include "DrawDocShell.hxx"
49 #include "ViewShell.hxx"
50 #include "Window.hxx"
51 #include "drawview.hxx"
52 #include "sdresid.hxx"
53 #include "drawdoc.hxx"
54 #include "DrawViewShell.hxx"
55 
56 #include "tableobjectbar.hxx"
57 
58 using namespace sd;
59 using namespace sd::ui::table;
60 
61 #define TableObjectBar
62 #include "sdslots.hxx"
63 
64 
65 namespace sd { namespace ui { namespace table {
66 
67 /** creates a table object bar for the given ViewShell */
CreateTableObjectBar(ViewShell & rShell,::sd::View * pView)68 SfxShell* CreateTableObjectBar( ViewShell& rShell, ::sd::View* pView )
69 {
70     return new TableObjectBar( &rShell, pView );
71 }
72 
73 
74 /** registers the interfaces from the table ui */
RegisterInterfaces(SfxModule * pMod)75 void RegisterInterfaces(SfxModule* pMod)
76 {
77     TableObjectBar::RegisterInterface(pMod);
78 }
79 
80 // ------------------
81 // - TableObjectBar -
82 // ------------------
83 
84 TYPEINIT1( TableObjectBar, SfxShell );
85 
86 // -----------------------------------------------------------------------------
87 
SFX_IMPL_INTERFACE(TableObjectBar,SfxShell,SdResId (STR_TABLEOBJECTBARSHELL))88 SFX_IMPL_INTERFACE( TableObjectBar, SfxShell, SdResId( STR_TABLEOBJECTBARSHELL ) )
89 {
90 }
91 
92 // -----------------------------------------------------------------------------
93 
TableObjectBar(ViewShell * pSdViewShell,::sd::View * pSdView)94 TableObjectBar::TableObjectBar( ViewShell* pSdViewShell, ::sd::View* pSdView )
95 :   SfxShell( pSdViewShell->GetViewShell() )
96 ,   mpView( pSdView )
97 ,   mpViewSh( pSdViewShell )
98 {
99     DrawDocShell* pDocShell = mpViewSh->GetDocSh();
100     if( pDocShell )
101     {
102         SetPool( &pDocShell->GetPool() );
103         SetUndoManager( pDocShell->GetUndoManager() );
104     }
105     SetRepeatTarget( mpView );
106     SetHelpId( SD_IF_SDDRAWTABLEOBJECTBAR );
107     SetName( String( SdResId( RID_DRAW_TABLE_TOOLBOX ) ) );
108     SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Table));
109 }
110 
111 // -----------------------------------------------------------------------------
112 
~TableObjectBar()113 TableObjectBar::~TableObjectBar()
114 {
115     SetRepeatTarget( NULL );
116 }
117 
118 // -----------------------------------------------------------------------------
119 
GetState(SfxItemSet & rSet)120 void TableObjectBar::GetState( SfxItemSet& rSet )
121 {
122     bool bReadOnly = false;
123 
124     if( bReadOnly )
125     {
126         rSet.DisableItem (SID_INSERT_TABLE );
127     }
128 
129     if( mpView )
130     {
131         rtl::Reference< sdr::SelectionController > xController( mpView->getSelectionController() );
132         if( xController.is() )
133         {
134             xController->GetState( rSet );
135         }
136     }
137 }
138 
139 // -----------------------------------------------------------------------------
140 
GetAttrState(SfxItemSet & rSet)141 void TableObjectBar::GetAttrState( SfxItemSet& rSet )
142 {
143     DrawViewShell* pDrawViewShell = dynamic_cast< DrawViewShell* >( mpViewSh );
144     if( pDrawViewShell )
145         pDrawViewShell->GetAttrState( rSet );
146 }
147 
148 // -----------------------------------------------------------------------------
149 
Execute(SfxRequest & rReq)150 void TableObjectBar::Execute( SfxRequest& rReq )
151 {
152     if( mpView )
153     {
154         SdrView* pView = mpView;
155         SfxBindings* pBindings = &mpViewSh->GetViewFrame()->GetBindings();
156 
157         rtl::Reference< sdr::SelectionController > xController( mpView->getSelectionController() );
158         sal_uLong nSlotId = rReq.GetSlot();
159         if( xController.is() )
160         {
161             switch( nSlotId )
162             {
163             case SID_TABLE_INSERT_ROW_DLG:
164             case SID_TABLE_INSERT_COL_DLG:
165             {
166                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
167                 ::std::auto_ptr<SvxAbstractInsRowColDlg> pDlg( pFact ? pFact->CreateSvxInsRowColDlg( mpView->GetViewShell()->GetParentWindow(), nSlotId == SID_TABLE_INSERT_COL_DLG, SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommand()) : 0);
168 
169                 if( pDlg.get() && (pDlg->Execute() == 1) )
170                 {
171                     if( nSlotId == SID_TABLE_INSERT_ROW_DLG )
172                         nSlotId = SID_TABLE_INSERT_ROW;
173                     else
174                         nSlotId = SID_TABLE_INSERT_COL;
175 
176                     rReq.AppendItem( SfxInt16Item( (sal_uInt16)nSlotId, (sal_uInt16)pDlg->getInsertCount() ) );
177                     rReq.AppendItem( SfxBoolItem( SID_TABLE_PARAM_INSERT_AFTER, !pDlg->isInsertBefore() ) );
178 
179                      rReq.SetSlot( (sal_uInt16)nSlotId );
180                 }
181             }
182             }
183 
184             xController->Execute( rReq );
185         }
186 
187         // note: we may be deleted at this point, no more member access possible
188 
189         switch( rReq.GetSlot() )
190         {
191         case SID_ATTR_BORDER:
192         case SID_TABLE_MERGE_CELLS:
193         case SID_TABLE_SPLIT_CELLS:
194         case SID_OPTIMIZE_TABLE:
195         case SID_TABLE_DELETE_ROW:
196         case SID_TABLE_DELETE_COL:
197         case SID_FORMAT_TABLE_DLG:
198         case SID_TABLE_INSERT_ROW:
199         case SID_TABLE_INSERT_COL:
200         {
201             pView->AdjustMarkHdl();
202             pBindings->Invalidate( SID_TABLE_DELETE_ROW );
203             pBindings->Invalidate( SID_TABLE_DELETE_COL );
204             pBindings->Invalidate( SID_FRAME_LINESTYLE );
205             pBindings->Invalidate( SID_FRAME_LINECOLOR );
206             pBindings->Invalidate( SID_ATTR_BORDER );
207             pBindings->Invalidate( SID_ATTR_FILL_STYLE );
208             pBindings->Invalidate( SID_ATTR_FILL_TRANSPARENCE );
209             pBindings->Invalidate( SID_ATTR_FILL_FLOATTRANSPARENCE );
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