xref: /AOO41X/main/sc/source/ui/drawfunc/graphsh.cxx (revision 54628ca40d27d15cc98fe861da7fff7e60c2f7d6)
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_sc.hxx"
26 
27 
28 
29 //------------------------------------------------------------------
30 
31 #include <sfx2/app.hxx>
32 #include <sfx2/objface.hxx>
33 #include <sfx2/request.hxx>
34 #include <svl/whiter.hxx>
35 #include <svx/svdograf.hxx>
36 #include <svx/grfflt.hxx>
37 #include <svx/grafctrl.hxx>
38 
39 #include "graphsh.hxx"
40 #include "sc.hrc"
41 #include "viewdata.hxx"
42 #include "drawview.hxx"
43 #include "scresid.hxx"
44 
45 #define ScGraphicShell
46 #include "scslots.hxx"
47 
48 #define ITEMVALUE(ItemSet,Id,Cast) ((const Cast&)(ItemSet).Get(Id)).GetValue()
49 
50 
51 SFX_IMPL_INTERFACE(ScGraphicShell, ScDrawShell, ScResId(SCSTR_GRAPHICSHELL) )
52 {
53     SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
54                                 ScResId(RID_GRAPHIC_OBJECTBAR) );
55     SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_GRAPHIC) );
56 }
57 
58 TYPEINIT1( ScGraphicShell, ScDrawShell );
59 
60 ScGraphicShell::ScGraphicShell(ScViewData* pData) :
61     ScDrawShell(pData)
62 {
63     SetHelpId(HID_SCSHELL_GRAPHIC);
64     SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("GraphicObject")));
65 }
66 
67 ScGraphicShell::~ScGraphicShell()
68 {
69 }
70 
71 void ScGraphicShell::GetAttrState( SfxItemSet& rSet )
72 {
73     ScDrawView* pView = GetViewData()->GetScDrawView();
74 
75     if( pView )
76         SvxGrafAttrHelper::GetGrafAttrState( rSet, *pView );
77 }
78 
79 void ScGraphicShell::Execute( SfxRequest& rReq )
80 {
81     ScDrawView* pView = GetViewData()->GetScDrawView();
82 
83     if( pView )
84     {
85         SvxGrafAttrHelper::ExecuteGrafAttr( rReq, *pView );
86         Invalidate();
87     }
88 }
89 
90 void ScGraphicShell::GetFilterState( SfxItemSet& rSet )
91 {
92     ScDrawView* pView = GetViewData()->GetScDrawView();
93     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
94     sal_Bool bEnable = sal_False;
95 
96     if( rMarkList.GetMarkCount() == 1 )
97     {
98         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
99 
100         if( pObj && pObj->ISA( SdrGrafObj ) && ( ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP ) )
101             bEnable = sal_True;
102     }
103 
104     if( !bEnable )
105         SvxGraphicFilter::DisableGraphicFilterSlots( rSet );
106 }
107 
108 void ScGraphicShell::ExecuteFilter( SfxRequest& rReq )
109 {
110     ScDrawView* pView = GetViewData()->GetScDrawView();
111     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
112 
113     if( rMarkList.GetMarkCount() == 1 )
114     {
115         SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
116 
117         if( pObj && pObj->ISA( SdrGrafObj ) && ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP )
118         {
119             GraphicObject aFilterObj( ( (SdrGrafObj*) pObj )->GetGraphicObject() );
120 
121             if( SVX_GRAPHICFILTER_ERRCODE_NONE ==
122                 SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ) )
123             {
124                 SdrPageView* pPageView = pView->GetSdrPageView();
125 
126                 if( pPageView )
127                 {
128                     SdrGrafObj* pFilteredObj = (SdrGrafObj*) pObj->Clone();
129                     String      aStr( pView->GetDescriptionOfMarkedObjects() );
130 
131                     aStr.Append( sal_Unicode(' ') );
132                     aStr.Append( String( ScResId( SCSTR_UNDO_GRAFFILTER ) ) );
133                     pView->BegUndo( aStr );
134                     pFilteredObj->SetGraphicObject( aFilterObj );
135                     pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj );
136                     pView->EndUndo();
137                 }
138             }
139         }
140     }
141 
142     Invalidate();
143 }
144 
145