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