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