fdo#30944 Add popup menu function to charts to export them as a graphic

Add popup menu function "Export as Graphic" to charts to export
the chart as a graphic. Currently it works only with raster formats
like PNG and JPG but not with vector formats like SVG.

Change-Id: Ieeda21ff971f2ad31bab2248e8b509883b5cbcd0
This commit is contained in:
Tomaž Vajngerl 2012-10-08 07:43:59 +02:00
parent fa30508fd3
commit cbb0babb67
6 changed files with 98 additions and 15 deletions

View file

@ -529,6 +529,9 @@
#define SID_NEW_SLOTS (SID_KEYFUNC_END)
#define SID_NEW_TABLENAME (SID_NEW_SLOTS+1)
#define SID_EXPORT_AS_GRAPHIC (SID_NEW_SLOTS+2)
#define FID_MERGE_TOGGLE (SID_NEW_SLOTS+10)
#define SID_ATTR_ROWHEADERS (SID_NEW_SLOTS+11)
#define SID_ATTR_COLHEADERS (SID_NEW_SLOTS+12)
@ -1126,4 +1129,3 @@
#define RID_SCPAGE_DEFAULTS (SC_OOO_BUILD_START + 10)
#endif

View file

@ -16,7 +16,16 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// ===========================================================================
interface ChartSelection
{
SID_EXPORT_AS_GRAPHIC
[
ExecMethod = ExecuteExportAsGraphic;
StateMethod = GetExportAsGraphicState;
]
}
shell ScChartShell : ScDrawShell
{
import ChartSelection;
}

View file

@ -24,7 +24,7 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
//--------------------------------------------------------------------------
SfxVoidItem AcceptChanges FID_CHG_ACCEPT
()
[
@ -2919,10 +2919,10 @@ SfxVoidItem SolverDialog SID_OPENDLG_OPTSOLVER
Synchron;
/* config: */
AccelConfig = FALSE,
MenuConfig = FALSE,
StatusBarConfig = FALSE,
ToolBoxConfig = FALSE,
AccelConfig = FALSE,
MenuConfig = FALSE,
StatusBarConfig = FALSE,
ToolBoxConfig = FALSE,
GroupId = GID_OPTIONS;
]
@ -8342,3 +8342,27 @@ SfxVoidItem EnterString SID_ENTER_STRING
ToolBoxConfig = FALSE,
GroupId = GID_INTERN;
]
SfxVoidItem ExportAsGraphic SID_EXPORT_AS_GRAPHIC
()
[
/* flags: */
AutoUpdate = FALSE,
Cachable = Cachable,
FastCall = FALSE,
HasCoreId = FALSE,
HasDialog = FALSE,
ReadOnlyDoc = TRUE,
Toggle = FALSE,
Container = FALSE,
RecordAbsolute = FALSE,
RecordPerSet;
Synchron;
/* config: */
AccelConfig = TRUE,
MenuConfig = TRUE,
StatusBarConfig = FALSE,
ToolBoxConfig = TRUE,
GroupId = GID_CHART;
]

View file

@ -17,8 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <editeng/eeitem.hxx>
#include <svx/fontwork.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdobj.hxx>
#include <svx/graphichelper.hxx>
#include <svl/srchitem.hxx>
#include <sfx2/app.hxx>
#include <sfx2/objface.hxx>
@ -34,15 +36,13 @@
#include "docpool.hxx"
#include "drawview.hxx"
#include "scresid.hxx"
#include <svx/svdobj.hxx>
#define ScChartShell
#include "scslots.hxx"
SFX_IMPL_INTERFACE(ScChartShell, ScDrawShell, ScResId(SCSTR_CHARTSHELL) )
{
SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT | SFX_VISIBILITY_STANDARD | SFX_VISIBILITY_SERVER,
ScResId(RID_DRAW_OBJECTBAR) );
SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_CHART) );
}
@ -52,14 +52,55 @@ TYPEINIT1( ScChartShell, ScDrawShell );
ScChartShell::ScChartShell(ScViewData* pData) :
ScDrawShell(pData)
{
SetHelpId(HID_SCSHELL_CHARTSH);
SetName(rtl::OUString("ChartObject"));
SetHelpId( HID_SCSHELL_CHARTSH );
SetName( OUString("ChartObject") );
}
ScChartShell::~ScChartShell()
{
}
void ScChartShell::GetExportAsGraphicState( SfxItemSet& rSet )
{
ScDrawView* pView = GetViewData()->GetScDrawView();
const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
bool bEnable = false;
if( rMarkList.GetMarkCount() == 1 )
{
SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
if( pObj && pObj->ISA( SdrOle2Obj ) )
bEnable = true;
}
if( !bEnable )
rSet.DisableItem( SID_EXPORT_AS_GRAPHIC );
}
void ScChartShell::ExecuteExportAsGraphic( SfxRequest& )
{
ScDrawView* pView = GetViewData()->GetScDrawView();
const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
if( rMarkList.GetMarkCount() == 1 )
{
SdrObject* pObject = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
if( pObject && pObject->ISA( SdrOle2Obj ) )
{
SdrOle2Obj* aOle2Object = ((SdrOle2Obj*) pObject)->Clone();
aOle2Object->NbcResize(Point(), Fraction(1,1), Fraction(1,1));
Graphic* pGraphic = aOle2Object->GetGraphic();
if( pGraphic != NULL )
{
String sGrfNm, sFilterNm;
GraphicHelper::ExportGraphic( *pGraphic, String("") );
}
}
}
Invalidate();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -619,6 +619,12 @@ Menu RID_POPUP_CHART
MenuItem { Separator = TRUE ; };
//------------------------------
ITEM_GROUP_MENU
MenuItem
{
Identifier = SID_EXPORT_AS_GRAPHIC ;
Command = ".uno:ExportAsGraphic" ;
Text [ en-US ] = "Export as graphic.." ;
};
};
};

View file

@ -23,7 +23,6 @@
#include <sfx2/shell.hxx>
#include "shellids.hxx"
#include <sfx2/module.hxx>
#include <svx/svdmark.hxx>
class ScViewData;
@ -39,6 +38,8 @@ public:
ScChartShell(ScViewData* pData);
virtual ~ScChartShell();
void ExecuteExportAsGraphic(SfxRequest& rReq);
void GetExportAsGraphicState(SfxItemSet &rSet);
};
#endif