2000-09-18 16:15:01 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-09 09:56:17 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2005-09-09 09:56:17 +00:00
|
|
|
* $RCSfile: chartins.cxx,v $
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-03-12 11:55:25 +00:00
|
|
|
* $Revision: 1.18 $
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-03-12 11:55:25 +00:00
|
|
|
* last change: $Author: rt $ $Date: 2008-03-12 12:55:25 $
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2005-09-09 09:56:17 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-09 09:56:17 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2005-09-09 09:56:17 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2005-09-09 09:56:17 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2005-09-09 09:56:17 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 22:19:12 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_sw.hxx"
|
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
#ifndef _SFXVIEWFRM_HXX //autogen
|
|
|
|
#include <sfx2/viewfrm.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _MSGBOX_HXX //autogen
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _SFXDISPATCH_HXX //autogen
|
|
|
|
#include <sfx2/dispatch.hxx>
|
|
|
|
#endif
|
2007-05-22 15:39:27 +00:00
|
|
|
#ifndef _BASEDLGS_HXX
|
|
|
|
#include <sfx2/basedlgs.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
#endif
|
2007-05-22 15:39:27 +00:00
|
|
|
#include <IDocumentUndoRedo.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2006-05-02 14:23:59 +00:00
|
|
|
#include <sfx2/app.hxx>
|
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
#ifndef _SWTYPES_HXX
|
|
|
|
#include <swtypes.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _SWMODULE_HXX
|
|
|
|
#include <swmodule.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _WRTSH_HXX
|
|
|
|
#include <wrtsh.hxx>
|
|
|
|
#endif
|
2007-05-22 15:39:27 +00:00
|
|
|
#ifndef _SWDOCSH_HXX
|
|
|
|
#include <docsh.hxx>
|
|
|
|
#endif
|
2000-09-18 16:15:01 +00:00
|
|
|
#ifndef _VIEW_HXX
|
|
|
|
#include <view.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _CHARTINS_HXX
|
|
|
|
#include <chartins.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _TABLEMGR_HXX
|
|
|
|
#include <tablemgr.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _FRMFMT_HXX
|
|
|
|
#include <frmfmt.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _SWTABLE_HXX
|
|
|
|
#include <swtable.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _TBLSEL_HXX
|
|
|
|
#include <tblsel.hxx>
|
|
|
|
#endif
|
2007-05-22 15:39:27 +00:00
|
|
|
#ifndef _UNOOBJ_HXX
|
|
|
|
#include <unoobj.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _UNOCHART_HXX
|
|
|
|
#include <unochart.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _AUTOEDIT_HXX
|
|
|
|
#include <autoedit.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _DOC_HXX
|
|
|
|
#include <doc.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <edtwin.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
#ifndef _CMDID_H
|
|
|
|
#include <cmdid.h>
|
|
|
|
#endif
|
|
|
|
#ifndef _CHARTINS_HRC
|
|
|
|
#include <chartins.hrc>
|
|
|
|
#endif
|
2007-05-22 15:39:27 +00:00
|
|
|
#include <anchoredobject.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2003-09-19 07:47:35 +00:00
|
|
|
#include <sot/clsids.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
#include <cppuhelper/bootstrap.hxx>
|
|
|
|
#include <cppuhelper/component_context.hxx>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <com/sun/star/chart2/data/XDataProvider.hpp>
|
|
|
|
#include <com/sun/star/chart2/data/XDataReceiver.hpp>
|
|
|
|
#include <com/sun/star/chart/ChartDataRowSource.hpp>
|
|
|
|
#include <com/sun/star/frame/XComponentLoader.hpp>
|
|
|
|
#include <com/sun/star/lang/XInitialization.hpp>
|
|
|
|
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
|
|
|
|
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
|
|
|
|
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
2008-03-12 11:55:25 +00:00
|
|
|
using ::rtl::OUString;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
Point SwGetChartDialogPos( const Window *pParentWin, const Size& rDialogSize, const Rectangle& rLogicChart )
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2007-05-22 15:39:27 +00:00
|
|
|
// !! positioning code according to spepc; similar to Calc fuins2.cxx
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
Point aRet;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
DBG_ASSERT( pParentWin, "Window not found" );
|
|
|
|
if (pParentWin)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2007-05-22 15:39:27 +00:00
|
|
|
Rectangle aObjPixel = pParentWin->LogicToPixel( rLogicChart, pParentWin->GetMapMode() );
|
|
|
|
Rectangle aObjAbs( pParentWin->OutputToAbsoluteScreenPixel( aObjPixel.TopLeft() ),
|
|
|
|
pParentWin->OutputToAbsoluteScreenPixel( aObjPixel.BottomRight() ) );
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
Rectangle aDesktop = pParentWin->GetDesktopRectPixel();
|
|
|
|
Size aSpace = pParentWin->LogicToPixel( Size( 8, 12 ), MAP_APPFONT );
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
BOOL bLayoutRTL = ::GetActiveView()->GetWrtShell().IsTableRightToLeft();
|
|
|
|
bool bCenterHor = false;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
if ( aDesktop.Bottom() - aObjAbs.Bottom() >= rDialogSize.Height() + aSpace.Height() )
|
|
|
|
{
|
|
|
|
// first preference: below the chart
|
|
|
|
aRet.Y() = aObjAbs.Bottom() + aSpace.Height();
|
|
|
|
bCenterHor = true;
|
|
|
|
}
|
|
|
|
else if ( aObjAbs.Top() - aDesktop.Top() >= rDialogSize.Height() + aSpace.Height() )
|
|
|
|
{
|
|
|
|
// second preference: above the chart
|
|
|
|
aRet.Y() = aObjAbs.Top() - rDialogSize.Height() - aSpace.Height();
|
|
|
|
bCenterHor = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool bFitLeft = ( aObjAbs.Left() - aDesktop.Left() >= rDialogSize.Width() + aSpace.Width() );
|
|
|
|
bool bFitRight = ( aDesktop.Right() - aObjAbs.Right() >= rDialogSize.Width() + aSpace.Width() );
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
if ( bFitLeft || bFitRight )
|
|
|
|
{
|
|
|
|
// if both fit, prefer right in RTL mode, left otherwise
|
|
|
|
bool bPutRight = bFitRight && ( bLayoutRTL || !bFitLeft );
|
|
|
|
if ( bPutRight )
|
|
|
|
aRet.X() = aObjAbs.Right() + aSpace.Width();
|
|
|
|
else
|
|
|
|
aRet.X() = aObjAbs.Left() - rDialogSize.Width() - aSpace.Width();
|
|
|
|
|
|
|
|
// center vertically
|
|
|
|
aRet.Y() = aObjAbs.Top() + ( aObjAbs.GetHeight() - rDialogSize.Height() ) / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// doesn't fit on any edge - put at the bottom of the screen
|
|
|
|
aRet.Y() = aDesktop.Bottom() - rDialogSize.Height();
|
|
|
|
bCenterHor = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( bCenterHor )
|
|
|
|
aRet.X() = aObjAbs.Left() + ( aObjAbs.GetWidth() - rDialogSize.Width() ) / 2;
|
|
|
|
|
|
|
|
// limit to screen (centering might lead to invalid positions)
|
|
|
|
if ( aRet.X() + rDialogSize.Width() - 1 > aDesktop.Right() )
|
|
|
|
aRet.X() = aDesktop.Right() - rDialogSize.Width() + 1;
|
|
|
|
if ( aRet.X() < aDesktop.Left() )
|
|
|
|
aRet.X() = aDesktop.Left();
|
|
|
|
if ( aRet.Y() + rDialogSize.Height() - 1 > aDesktop.Bottom() )
|
|
|
|
aRet.Y() = aDesktop.Bottom() - rDialogSize.Height() + 1;
|
|
|
|
if ( aRet.Y() < aDesktop.Top() )
|
|
|
|
aRet.Y() = aDesktop.Top();
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
return aRet;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------
|
|
|
|
Beschreibung:
|
|
|
|
------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
void SwInsertChart(Window* pParent, SfxBindings* pBindings )
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2007-09-27 11:32:27 +00:00
|
|
|
(void) pParent;
|
|
|
|
(void) pBindings;
|
2007-05-22 15:39:27 +00:00
|
|
|
SwView *pView = ::GetActiveView();
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
// get range string of marked data
|
|
|
|
SwWrtShell &rWrtShell = pView->GetWrtShell();
|
|
|
|
uno::Reference< chart2::data::XDataProvider > xDataProvider;
|
|
|
|
uno::Reference< frame::XModel > xChartModel;
|
|
|
|
OUString aRangeString;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
if( rWrtShell.IsCrsrInTbl())
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2007-05-22 15:39:27 +00:00
|
|
|
if (!rWrtShell.IsTableMode())
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2007-05-22 15:39:27 +00:00
|
|
|
// select whole table
|
|
|
|
rWrtShell.GetView().GetViewFrame()->GetDispatcher()->
|
|
|
|
Execute(FN_TABLE_SELECT_ALL, SFX_CALLMODE_SYNCHRON);
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2007-05-22 15:39:27 +00:00
|
|
|
if( ! rWrtShell.IsTblComplexForChart())
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2007-05-22 15:39:27 +00:00
|
|
|
SwFrmFmt* pTblFmt = rWrtShell.GetTableFmt();
|
|
|
|
String aCurrentTblName = pTblFmt->GetName();
|
|
|
|
// String aText( String::CreateFromAscii("<.>") ); // was used for UI
|
|
|
|
// aText.Insert( rWrtShell.GetBoxNms(), 2);
|
|
|
|
// aText.Insert( aCurrentTblName, 1 );
|
|
|
|
aRangeString = aCurrentTblName;
|
|
|
|
aRangeString += OUString::valueOf( sal_Unicode('.') );
|
|
|
|
aRangeString += rWrtShell.GetBoxNms();
|
|
|
|
|
|
|
|
// get table data provider
|
|
|
|
xDataProvider.set( pView->GetDocShell()->getIDocumentChartDataProviderAccess()->GetChartDataProvider( true ) );
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-22 15:39:27 +00:00
|
|
|
SwFlyFrmFmt *pFlyFrmFmt = 0;
|
|
|
|
xChartModel.set( SwTableFUNC( &rWrtShell, FALSE ).InsertChart( xDataProvider, (sal_True == xDataProvider.is()), aRangeString, &pFlyFrmFmt ));
|
|
|
|
|
|
|
|
//open wizard
|
|
|
|
//@todo get context from writer if that has one
|
|
|
|
uno::Reference< uno::XComponentContext > xContext(
|
|
|
|
::cppu::defaultBootstrap_InitialComponentContext() );
|
|
|
|
if( xContext.is() && xChartModel.is() && xDataProvider.is())
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2007-05-22 15:39:27 +00:00
|
|
|
uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
|
|
|
|
if(xMCF.is())
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2007-05-22 15:39:27 +00:00
|
|
|
uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
|
|
|
|
xMCF->createInstanceWithContext(
|
|
|
|
C2U("com.sun.star.comp.chart2.WizardDialog")
|
|
|
|
, xContext), uno::UNO_QUERY);
|
|
|
|
uno::Reference< lang::XInitialization > xInit( xDialog, uno::UNO_QUERY );
|
|
|
|
if( xInit.is() )
|
|
|
|
{
|
|
|
|
uno::Reference< awt::XWindow > xDialogParentWindow(0);
|
|
|
|
// initialize dialog
|
|
|
|
uno::Sequence<uno::Any> aSeq(2);
|
|
|
|
uno::Any* pArray = aSeq.getArray();
|
|
|
|
beans::PropertyValue aParam1;
|
|
|
|
aParam1.Name = C2U("ParentWindow");
|
|
|
|
aParam1.Value <<= uno::makeAny(xDialogParentWindow);
|
|
|
|
beans::PropertyValue aParam2;
|
|
|
|
aParam2.Name = C2U("ChartModel");
|
|
|
|
aParam2.Value <<= uno::makeAny(xChartModel);
|
|
|
|
pArray[0] <<= uno::makeAny(aParam1);
|
|
|
|
pArray[1] <<= uno::makeAny(aParam2);
|
|
|
|
xInit->initialize( aSeq );
|
|
|
|
|
|
|
|
// try to set the dialog's position so it doesn't hide the chart
|
|
|
|
uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
|
|
|
|
if ( xDialogProps.is() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//get dialog size:
|
|
|
|
awt::Size aDialogAWTSize;
|
|
|
|
if( xDialogProps->getPropertyValue( ::rtl::OUString::createFromAscii("Size") )
|
|
|
|
>>= aDialogAWTSize )
|
|
|
|
{
|
|
|
|
Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
|
|
|
|
if ( aDialogSize.Width() > 0 && aDialogSize.Height() > 0 )
|
|
|
|
{
|
|
|
|
//calculate and set new position
|
|
|
|
SwRect aSwRect;
|
|
|
|
if (pFlyFrmFmt)
|
|
|
|
aSwRect = pFlyFrmFmt->GetAnchoredObj()->GetObjRectWithSpaces();
|
|
|
|
Rectangle aRect( aSwRect.SVRect() );
|
|
|
|
Point aDialogPos = SwGetChartDialogPos( &rWrtShell.GetView().GetEditWin(), aDialogSize, aRect );
|
|
|
|
xDialogProps->setPropertyValue( ::rtl::OUString::createFromAscii("Position"),
|
|
|
|
uno::makeAny( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( uno::Exception& )
|
|
|
|
{
|
|
|
|
DBG_ERROR( "Chart wizard couldn't be positioned automatically\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int16 nDialogRet = xDialog->execute();
|
|
|
|
if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL )
|
|
|
|
{
|
|
|
|
rWrtShell.Undo();
|
|
|
|
rWrtShell.getIDocumentUndoRedoAccess()->ClearRedo();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG_ASSERT( nDialogRet == ui::dialogs::ExecutableDialogResults::OK,
|
|
|
|
"dialog execution failed" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
|
|
|
|
if( xComponent.is())
|
|
|
|
xComponent->dispose();
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void __EXPORT AutoEdit::KeyInput( const KeyEvent& rEvt )
|
|
|
|
{
|
|
|
|
USHORT nCode = rEvt.GetKeyCode().GetCode();
|
|
|
|
if( nCode != KEY_SPACE )
|
|
|
|
Edit::KeyInput( rEvt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|