xref: /trunk/main/sc/source/ui/view/tabvwshh.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_sc.hxx"
30 
31 
32 
33 // INCLUDE ---------------------------------------------------------------
34 
35 #include <svx/svdmark.hxx>
36 #include <svx/svdoole2.hxx>
37 #include <svx/svdview.hxx>
38 #include <sfx2/app.hxx>
39 #include <sfx2/objsh.hxx>
40 #include <sfx2/request.hxx>
41 #include <basic/sbxcore.hxx>
42 #include <svl/whiter.hxx>
43 #include <vcl/msgbox.hxx>
44 
45 #include "tabvwsh.hxx"
46 #include "client.hxx"
47 #include "document.hxx"
48 #include "docsh.hxx"
49 #include "sc.hrc"
50 #include "drwlayer.hxx"     // GetVisibleName
51 #include "retypepassdlg.hxx"
52 #include "tabprotection.hxx"
53 
54 #include <memory>
55 
56 using namespace com::sun::star;
57 
58 //------------------------------------------------------------------
59 
60 void ScTabViewShell::ExecuteSbx( SfxRequest& /* rReq */ )
61 {
62     //  SID_RANGE_OFFSET (Offset),
63     //  SID_PIVOT_CREATE (DataPilotCreate) - removed (old Basic)
64 }
65 
66 void ScTabViewShell::GetSbxState( SfxItemSet& /* rSet */ )
67 {
68     //  SID_RANGE_REGION (CurrentRegion) - removed (old Basic)
69 }
70 
71 //------------------------------------------------------------------
72 
73 void ScTabViewShell::ExecuteObject( SfxRequest& rReq )
74 {
75     sal_uInt16 nSlotId = rReq.GetSlot();
76     const SfxItemSet* pReqArgs = rReq.GetArgs();
77 
78         //  Objekte aktivieren/deaktivieren immer auf der sichtbaren View
79 
80     ScTabViewShell* pVisibleSh = this;
81     if ( nSlotId == SID_OLE_SELECT || nSlotId == SID_OLE_ACTIVATE || nSlotId == SID_OLE_DEACTIVATE )
82     {
83         DBG_ERROR("old slot SID_OLE...");
84     }
85 
86     switch (nSlotId)
87     {
88         case SID_OLE_SELECT:
89         case SID_OLE_ACTIVATE:
90             {
91                 //  in beiden Faellen erstmal auf der sichtbaren View selektieren
92 
93                 String aName;
94                 SdrView* pDrView = GetSdrView();
95                 if (pDrView)
96                 {
97                     const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
98                     if (rMarkList.GetMarkCount() == 1)
99                         aName = ScDrawLayer::GetVisibleName( rMarkList.GetMark(0)->GetMarkedSdrObj() );
100                 }
101                 pVisibleSh->SelectObject( aName );
102 
103                 //  aktivieren
104 
105                 if ( nSlotId == SID_OLE_ACTIVATE )
106                     pVisibleSh->DoVerb( 0 );
107             }
108             break;
109         case SID_OLE_DEACTIVATE:
110             pVisibleSh->DeactivateOle();
111             break;
112 
113         case SID_OBJECT_LEFT:
114         case SID_OBJECT_TOP:
115         case SID_OBJECT_WIDTH:
116         case SID_OBJECT_HEIGHT:
117             {
118                 sal_Bool bDone = sal_False;
119                 const SfxPoolItem* pItem;
120                 if ( pReqArgs && pReqArgs->GetItemState( nSlotId, sal_True, &pItem ) == SFX_ITEM_SET )
121                 {
122                     long nNewVal = ((const SfxInt32Item*)pItem)->GetValue();
123                     if ( nNewVal < 0 )
124                         nNewVal = 0;
125 
126                     //! von irgendwas in 1/100mm umrechnen ??????
127 
128                     SdrView* pDrView = GetSdrView();
129                     if ( pDrView )
130                     {
131                         const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
132                         if (rMarkList.GetMarkCount() == 1)
133                         {
134                             SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
135                             Rectangle aRect = pObj->GetLogicRect();
136 
137                             if ( nSlotId == SID_OBJECT_LEFT )
138                                 pDrView->MoveMarkedObj( Size( nNewVal - aRect.Left(), 0 ) );
139                             else if ( nSlotId == SID_OBJECT_TOP )
140                                 pDrView->MoveMarkedObj( Size( 0, nNewVal - aRect.Top() ) );
141                             else if ( nSlotId == SID_OBJECT_WIDTH )
142                                 pDrView->ResizeMarkedObj( aRect.TopLeft(),
143                                                 Fraction( nNewVal, aRect.GetWidth() ),
144                                                 Fraction( 1, 1 ) );
145                             else // if ( nSlotId == SID_OBJECT_HEIGHT )
146                                 pDrView->ResizeMarkedObj( aRect.TopLeft(),
147                                                 Fraction( 1, 1 ),
148                                                 Fraction( nNewVal, aRect.GetHeight() ) );
149                             bDone = sal_True;
150                         }
151                     }
152                 }
153                 if (!bDone)
154                     SbxBase::SetError( SbxERR_BAD_PARAMETER );  // Basic-Fehler
155             }
156             break;
157 
158     }
159 }
160 
161 uno::Reference < embed::XEmbeddedObject > lcl_GetSelectedObj( SdrView* pDrView )       //! Member von ScDrawView?
162 {
163     uno::Reference < embed::XEmbeddedObject > xRet;
164     if (pDrView)
165     {
166         const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
167         if (rMarkList.GetMarkCount() == 1)
168         {
169             SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
170             if (pObj->GetObjIdentifier() == OBJ_OLE2)
171             {
172                 SdrOle2Obj* pOle2Obj = (SdrOle2Obj*) pObj;
173                 xRet = pOle2Obj->GetObjRef();
174             }
175         }
176     }
177 
178     return xRet;
179 }
180 
181 void ScTabViewShell::GetObjectState( SfxItemSet& rSet )
182 {
183     //  SID_OLE_OBJECT - removed (old Basic)
184 
185     SfxWhichIter aIter(rSet);
186     sal_uInt16 nWhich = aIter.FirstWhich();
187     while ( nWhich )
188     {
189         switch (nWhich)
190         {
191             case SID_ACTIVE_OBJ_NAME:
192                 {
193                     String aName;
194                     uno::Reference < embed::XEmbeddedObject > xOLE = lcl_GetSelectedObj( GetSdrView() );
195                     if (xOLE.is())
196                     {
197                         aName = GetViewData()->GetSfxDocShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xOLE );
198                     }
199                     rSet.Put( SfxStringItem( nWhich, aName ) );
200                 }
201                 break;
202             case SID_OBJECT_LEFT:
203             case SID_OBJECT_TOP:
204             case SID_OBJECT_WIDTH:
205             case SID_OBJECT_HEIGHT:
206                 {
207                     SdrView* pDrView = GetSdrView();
208                     if ( pDrView )
209                     {
210                         const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
211                         if (rMarkList.GetMarkCount() == 1)
212                         {
213                             SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
214                             Rectangle aRect = pObj->GetLogicRect();
215 
216                             long nVal;
217                             if ( nWhich == SID_OBJECT_LEFT )
218                                 nVal = aRect.Left();
219                             else if ( nWhich == SID_OBJECT_TOP )
220                                 nVal = aRect.Top();
221                             else if ( nWhich == SID_OBJECT_WIDTH )
222                                 nVal = aRect.GetWidth();
223                             else // if ( nWhich == SID_OBJECT_HEIGHT )
224                                 nVal = aRect.GetHeight();
225 
226                             //! von 1/100mm in irgendwas umrechnen ??????
227 
228                             rSet.Put( SfxInt32Item( nWhich, nVal ) );
229                         }
230                     }
231                 }
232                 break;
233         }
234         nWhich = aIter.NextWhich();
235     }
236 }
237 
238 void ScTabViewShell::AddAccessibilityObject( SfxListener& rObject )
239 {
240     if (!pAccessibilityBroadcaster)
241         pAccessibilityBroadcaster = new SfxBroadcaster;
242 
243     rObject.StartListening( *pAccessibilityBroadcaster );
244     ScDocument* pDoc = GetViewData()->GetDocument();
245     if (pDoc)
246         pDoc->AddUnoObject(rObject);
247 }
248 
249 void ScTabViewShell::RemoveAccessibilityObject( SfxListener& rObject )
250 {
251     if (pAccessibilityBroadcaster)
252     {
253         rObject.EndListening( *pAccessibilityBroadcaster );
254         ScDocument* pDoc = GetViewData()->GetDocument();
255         if (pDoc)
256             pDoc->RemoveUnoObject(rObject);
257     }
258     else
259     {
260         DBG_ERROR("kein Accessibility-Broadcaster?");
261     }
262 }
263 
264 void ScTabViewShell::BroadcastAccessibility( const SfxHint &rHint )
265 {
266     if (pAccessibilityBroadcaster)
267         pAccessibilityBroadcaster->Broadcast( rHint );
268 }
269 
270 sal_Bool ScTabViewShell::HasAccessibilityObjects()
271 {
272     return pAccessibilityBroadcaster != NULL;
273 }
274 
275 bool ScTabViewShell::ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
276 {
277     using ::std::auto_ptr;
278 
279     ScDocument* pDoc = GetViewData()->GetDocument();
280 
281     auto_ptr<ScRetypePassDlg> pDlg(new ScRetypePassDlg(GetDialogParent()));
282     pDlg->SetDataFromDocument(*pDoc);
283     pDlg->SetDesiredHash(eDesiredHash);
284     if (pDlg->Execute() != RET_OK)
285         return false;
286 
287     pDlg->WriteNewDataToDocument(*pDoc);
288     return true;
289 }
290 
291 
292 
293 
294