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 "GraphicObjectBar.hxx"
28 
29 #include <limits.h>
30 #include <vcl/msgbox.hxx>
31 #include <svl/whiter.hxx>
32 #include <svl/itempool.hxx>
33 #include <sfx2/app.hxx>
34 #include <sfx2/shell.hxx>
35 #include <svx/svxids.hrc>
36 #include <sfx2/request.hxx>
37 #include <sfx2/basedlgs.hxx>
38 #include <svx/svdograf.hxx>
39 #include <svx/grfflt.hxx>
40 #include <svl/aeitem.hxx>
41 #include <svx/grafctrl.hxx>
42 
43 
44 #include <sfx2/objface.hxx>
45 
46 #include "app.hrc"
47 #include "res_bmp.hrc"
48 #include "glob.hrc"
49 #include "strings.hrc"
50 #include "DrawDocShell.hxx"
51 #include "ViewShell.hxx"
52 #include "Window.hxx"
53 #include "drawview.hxx"
54 #include "sdresid.hxx"
55 #include "drawdoc.hxx"
56 
57 using namespace sd;
58 #define GraphicObjectBar
59 #include "sdslots.hxx"
60 
61 namespace sd {
62 
63 
64 
65 // -----------------------
66 // - GraphicObjectBar -
67 // -----------------------
68 
SFX_IMPL_INTERFACE(GraphicObjectBar,SfxShell,SdResId (STR_GRAFOBJECTBARSHELL))69 SFX_IMPL_INTERFACE( GraphicObjectBar, SfxShell, SdResId( STR_GRAFOBJECTBARSHELL ) )
70 {
71 }
72 
73 // -----------------------------------------------------------------------------
74 
75 TYPEINIT1( GraphicObjectBar, SfxShell );
76 
77 // -----------------------------------------------------------------------------
78 
GraphicObjectBar(ViewShell * pSdViewShell,::sd::View * pSdView)79 GraphicObjectBar::GraphicObjectBar (
80     ViewShell* pSdViewShell,
81     ::sd::View* pSdView )
82     : SfxShell (pSdViewShell->GetViewShell()),
83       mpView	 ( pSdView ),
84       mpViewSh ( pSdViewShell ),
85       nMappedSlotFilter ( SID_GRFFILTER_INVERT )
86 {
87 	DrawDocShell* pDocShell = mpViewSh->GetDocSh();
88 
89 	SetPool( &pDocShell->GetPool() );
90 	SetUndoManager( pDocShell->GetUndoManager() );
91 	SetRepeatTarget( mpView );
92 	SetHelpId( SD_IF_SDDRAWGRAFOBJECTBAR );
93 	SetName( String( RTL_CONSTASCII_USTRINGPARAM( "Graphic objectbar" )));
94 }
95 
96 // -----------------------------------------------------------------------------
97 
~GraphicObjectBar()98 GraphicObjectBar::~GraphicObjectBar()
99 {
100 	SetRepeatTarget( NULL );
101 }
102 
103 // -----------------------------------------------------------------------------
104 
GetAttrState(SfxItemSet & rSet)105 void GraphicObjectBar::GetAttrState( SfxItemSet& rSet )
106 {
107 	if( mpView )
108 		SvxGrafAttrHelper::GetGrafAttrState( rSet, *mpView );
109 }
110 
111 // -----------------------------------------------------------------------------
112 
Execute(SfxRequest & rReq)113 void GraphicObjectBar::Execute( SfxRequest& rReq )
114 {
115 	if( mpView )
116 	{
117 		SvxGrafAttrHelper::ExecuteGrafAttr( rReq, *mpView );
118 		Invalidate();
119 	}
120 }
121 
122 // -----------------------------------------------------------------------------
123 
GetFilterState(SfxItemSet & rSet)124 void GraphicObjectBar::GetFilterState( SfxItemSet& rSet )
125 {
126 	const SdrMarkList&	rMarkList = mpView->GetMarkedObjectList();
127 	sal_Bool				bEnable = sal_False;
128 
129 	if( rMarkList.GetMarkCount() == 1 )
130 	{
131 		SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
132 
133 		if( pObj && pObj->ISA( SdrGrafObj ) && ( ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP ) )
134 			bEnable = sal_True;
135 	}
136 
137 	if( !bEnable )
138 		SvxGraphicFilter::DisableGraphicFilterSlots( rSet );
139 }
140 
141 // -----------------------------------------------------------------------------
142 
ExecuteFilter(SfxRequest & rReq)143 void GraphicObjectBar::ExecuteFilter( SfxRequest& rReq )
144 {
145 	const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
146 
147 	if( rMarkList.GetMarkCount() == 1 )
148 	{
149 		SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
150 
151 		if( pObj && pObj->ISA( SdrGrafObj ) && ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP )
152 		{
153 			GraphicObject aFilterObj( ( (SdrGrafObj*) pObj )->GetGraphicObject() );
154 
155 			if( SVX_GRAPHICFILTER_ERRCODE_NONE ==
156 				SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ) )
157 			{
158 				SdrPageView* pPageView = mpView->GetSdrPageView();
159 
160 				if( pPageView )
161 				{
162 					SdrGrafObj*	pFilteredObj = (SdrGrafObj*) pObj->Clone();
163 					String		aStr( mpView->GetDescriptionOfMarkedObjects() );
164 
165 					aStr.Append( sal_Unicode(' ') );
166 					aStr.Append( String( SdResId( STR_UNDO_GRAFFILTER ) ) );
167 					mpView->BegUndo( aStr );
168 					pFilteredObj->SetGraphicObject( aFilterObj );
169 					::sd::View* const pView = mpView;
170 					pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj );
171 					pView->EndUndo();
172 					return;
173 				}
174 			}
175 		}
176 	}
177 
178 	Invalidate();
179 }
180 
181 } // end of namespace sd
182