1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "GraphicObjectBar.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <limits.h>
30cdf0e10cSrcweir #include <vcl/msgbox.hxx>
31cdf0e10cSrcweir #include <svl/whiter.hxx>
32cdf0e10cSrcweir #include <svl/itempool.hxx>
33cdf0e10cSrcweir #include <sfx2/app.hxx>
34cdf0e10cSrcweir #include <sfx2/shell.hxx>
35cdf0e10cSrcweir #include <svx/svxids.hrc>
36cdf0e10cSrcweir #include <sfx2/request.hxx>
37cdf0e10cSrcweir #include <sfx2/basedlgs.hxx>
38cdf0e10cSrcweir #include <svx/svdograf.hxx>
39cdf0e10cSrcweir #include <svx/grfflt.hxx>
40cdf0e10cSrcweir #include <svl/aeitem.hxx>
41cdf0e10cSrcweir #include <svx/grafctrl.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <sfx2/objface.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include "app.hrc"
47cdf0e10cSrcweir #include "res_bmp.hrc"
48cdf0e10cSrcweir #include "glob.hrc"
49cdf0e10cSrcweir #include "strings.hrc"
50cdf0e10cSrcweir #include "DrawDocShell.hxx"
51cdf0e10cSrcweir #include "ViewShell.hxx"
52cdf0e10cSrcweir #include "Window.hxx"
53cdf0e10cSrcweir #include "drawview.hxx"
54cdf0e10cSrcweir #include "sdresid.hxx"
55cdf0e10cSrcweir #include "drawdoc.hxx"
56cdf0e10cSrcweir 
57cdf0e10cSrcweir using namespace sd;
58cdf0e10cSrcweir #define GraphicObjectBar
59cdf0e10cSrcweir #include "sdslots.hxx"
60cdf0e10cSrcweir 
61cdf0e10cSrcweir namespace sd {
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 
65cdf0e10cSrcweir // -----------------------
66cdf0e10cSrcweir // - GraphicObjectBar -
67cdf0e10cSrcweir // -----------------------
68cdf0e10cSrcweir 
SFX_IMPL_INTERFACE(GraphicObjectBar,SfxShell,SdResId (STR_GRAFOBJECTBARSHELL))69cdf0e10cSrcweir SFX_IMPL_INTERFACE( GraphicObjectBar, SfxShell, SdResId( STR_GRAFOBJECTBARSHELL ) )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // -----------------------------------------------------------------------------
74cdf0e10cSrcweir 
75cdf0e10cSrcweir TYPEINIT1( GraphicObjectBar, SfxShell );
76cdf0e10cSrcweir 
77cdf0e10cSrcweir // -----------------------------------------------------------------------------
78cdf0e10cSrcweir 
GraphicObjectBar(ViewShell * pSdViewShell,::sd::View * pSdView)79cdf0e10cSrcweir GraphicObjectBar::GraphicObjectBar (
80cdf0e10cSrcweir     ViewShell* pSdViewShell,
81cdf0e10cSrcweir     ::sd::View* pSdView )
82cdf0e10cSrcweir     : SfxShell (pSdViewShell->GetViewShell()),
83cdf0e10cSrcweir       mpView	 ( pSdView ),
84cdf0e10cSrcweir       mpViewSh ( pSdViewShell ),
85cdf0e10cSrcweir       nMappedSlotFilter ( SID_GRFFILTER_INVERT )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	DrawDocShell* pDocShell = mpViewSh->GetDocSh();
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	SetPool( &pDocShell->GetPool() );
90cdf0e10cSrcweir 	SetUndoManager( pDocShell->GetUndoManager() );
91cdf0e10cSrcweir 	SetRepeatTarget( mpView );
92cdf0e10cSrcweir 	SetHelpId( SD_IF_SDDRAWGRAFOBJECTBAR );
93cdf0e10cSrcweir 	SetName( String( RTL_CONSTASCII_USTRINGPARAM( "Graphic objectbar" )));
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir // -----------------------------------------------------------------------------
97cdf0e10cSrcweir 
~GraphicObjectBar()98cdf0e10cSrcweir GraphicObjectBar::~GraphicObjectBar()
99cdf0e10cSrcweir {
100cdf0e10cSrcweir 	SetRepeatTarget( NULL );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // -----------------------------------------------------------------------------
104cdf0e10cSrcweir 
GetAttrState(SfxItemSet & rSet)105cdf0e10cSrcweir void GraphicObjectBar::GetAttrState( SfxItemSet& rSet )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	if( mpView )
108cdf0e10cSrcweir 		SvxGrafAttrHelper::GetGrafAttrState( rSet, *mpView );
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir // -----------------------------------------------------------------------------
112cdf0e10cSrcweir 
Execute(SfxRequest & rReq)113cdf0e10cSrcweir void GraphicObjectBar::Execute( SfxRequest& rReq )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 	if( mpView )
116cdf0e10cSrcweir 	{
117cdf0e10cSrcweir 		SvxGrafAttrHelper::ExecuteGrafAttr( rReq, *mpView );
118cdf0e10cSrcweir 		Invalidate();
119cdf0e10cSrcweir 	}
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir // -----------------------------------------------------------------------------
123cdf0e10cSrcweir 
GetFilterState(SfxItemSet & rSet)124cdf0e10cSrcweir void GraphicObjectBar::GetFilterState( SfxItemSet& rSet )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	const SdrMarkList&	rMarkList = mpView->GetMarkedObjectList();
127cdf0e10cSrcweir 	sal_Bool				bEnable = sal_False;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	if( rMarkList.GetMarkCount() == 1 )
130cdf0e10cSrcweir 	{
131cdf0e10cSrcweir 		SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 		if( pObj && pObj->ISA( SdrGrafObj ) && ( ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP ) )
134cdf0e10cSrcweir 			bEnable = sal_True;
135cdf0e10cSrcweir 	}
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	if( !bEnable )
138cdf0e10cSrcweir 		SvxGraphicFilter::DisableGraphicFilterSlots( rSet );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir // -----------------------------------------------------------------------------
142cdf0e10cSrcweir 
ExecuteFilter(SfxRequest & rReq)143cdf0e10cSrcweir void GraphicObjectBar::ExecuteFilter( SfxRequest& rReq )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir 	const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 	if( rMarkList.GetMarkCount() == 1 )
148cdf0e10cSrcweir 	{
149cdf0e10cSrcweir 		SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 		if( pObj && pObj->ISA( SdrGrafObj ) && ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP )
152cdf0e10cSrcweir 		{
153cdf0e10cSrcweir 			GraphicObject aFilterObj( ( (SdrGrafObj*) pObj )->GetGraphicObject() );
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 			if( SVX_GRAPHICFILTER_ERRCODE_NONE ==
156cdf0e10cSrcweir 				SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ) )
157cdf0e10cSrcweir 			{
158cdf0e10cSrcweir 				SdrPageView* pPageView = mpView->GetSdrPageView();
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 				if( pPageView )
161cdf0e10cSrcweir 				{
162cdf0e10cSrcweir 					SdrGrafObj*	pFilteredObj = (SdrGrafObj*) pObj->Clone();
163cdf0e10cSrcweir 					String		aStr( mpView->GetDescriptionOfMarkedObjects() );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 					aStr.Append( sal_Unicode(' ') );
166cdf0e10cSrcweir 					aStr.Append( String( SdResId( STR_UNDO_GRAFFILTER ) ) );
167cdf0e10cSrcweir 					mpView->BegUndo( aStr );
168cdf0e10cSrcweir 					pFilteredObj->SetGraphicObject( aFilterObj );
169cdf0e10cSrcweir 					::sd::View* const pView = mpView;
170cdf0e10cSrcweir 					pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj );
171cdf0e10cSrcweir 					pView->EndUndo();
172cdf0e10cSrcweir 					return;
173cdf0e10cSrcweir 				}
174cdf0e10cSrcweir 			}
175cdf0e10cSrcweir 		}
176cdf0e10cSrcweir 	}
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 	Invalidate();
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir } // end of namespace sd
182