2007/05/18 16:12:16 bm 1.1.2.42: #i74635# ResMgr cleanup ResId -> SchResId 2007/03/07 15:19:17 bm 1.1.2.41: #i75204# set m_aLastValidRangeString correctly in isValid() 2007/03/07 13:15:02 bm 1.1.2.40: #i75179# enable WB_FORCECTRLBACKGROUND bit to allow setting red background of controls 2007/02/27 13:45:31 bm 1.1.2.39: Disable controls and tabs when invalid ranges were entered 2007/02/26 13:10:56 bm 1.1.2.38: use different foreground and background for invalid ranges, like in Firefox. 2007/02/09 12:31:18 bm 1.1.2.37: implement adaptions for different look in wizard and stand-alone source data dialog, according to spec FlexibleSourceRangeSelection 2007/02/08 21:25:35 iha 1.1.2.36: resync m195 -> m202 2006/11/10 21:03:06 iha 1.1.2.35: prevent immidiate redraw in wizard and according dialogs (important for charts with many data) 2006/10/27 14:59:20 iha 1.1.2.34: name consolidation 2006/10/24 11:55:16 bm 1.1.2.33: enable range chooser in Calc 2006/10/09 17:18:33 bm 1.1.2.32: hide range chooser buttons if no range chooser is available (instead of just disabling) 2006/10/09 16:01:49 bm 1.1.2.31: only enable range chooser buttons if a range chooser component is available 2006/05/29 17:55:17 iha 1.1.2.30: replaced STR_OBJECT_SOURCE_DATA by STR_OBJECT_DATA_RANGE 2006/03/17 13:27:26 bm 1.1.2.29: disable radio-buttons and check-boxes if the range is invalid or complex 2005/11/14 17:55:41 iha 1.1.2.28: don't update model again at end of execute as this was done already - undo is done outside of the dialog 2005/11/14 15:20:37 iha 1.1.2.27: removed superfluous include 2005/11/11 13:56:16 iha 1.1.2.26: remove direct view update call 2005/11/09 12:35:21 bm 1.1.2.25: setDirty only if changes do not come from initControlsFromModel 2005/10/11 09:20:17 bm 1.1.2.24: license header change 2005/09/02 11:43:28 bm 1.1.2.23: initControlsFromModel: checkboxes were set the other way round 2005/05/20 13:31:57 bm 1.1.2.22: string construction with resid problem 2005/05/12 13:56:39 bm 1.1.2.21: API change XDataProvider 2005/04/19 14:34:41 bm 1.1.2.20: fixing the data source/range chooser dialogs 2005/04/15 14:48:09 bm 1.1.2.19: data source and range choose dialog rework 2004/09/15 15:39:01 iha 1.1.2.18: implement api redesign 2004/07/05 11:35:42 iha 1.1.2.17: correct update cycle 2004/06/30 16:14:17 bm 1.1.2.16: some fixes 2004/06/29 12:21:54 bm 1.1.2.15: shared data for range chooser and data source tab pages 2004/06/23 13:03:06 bm 1.1.2.14: change defaults for arguments that are not yet automatically detected 2004/06/17 13:05:11 bm 1.1.2.13: some minor preliminary fixes 2004/06/17 12:46:54 bm 1.1.2.12: oops, checked in a test 2004/06/17 10:03:25 bm 1.1.2.11: data source dialog is a tab dialog now using the same tabpages as the wizard 2004/06/09 18:43:47 iha 1.1.2.10: minor resource changes 2004/06/08 19:28:13 iha 1.1.2.9: changed title 2004/05/27 15:55:21 iha 1.1.2.8: #i20344# provide charttype template; added parameter bDoLiveUpdate 2004/05/26 13:18:40 bm 1.1.2.7: dialog behaviour improvements 2004/05/17 17:33:52 iha 1.1.2.6: provide object naming; resource cleanup 2004/05/10 17:07:42 iha 1.1.2.5: swapped FirstCellAsLabel and HasCategories 2004/05/10 15:42:48 iha 1.1.2.4: catch invalid range exception 2004/05/07 16:36:54 iha 1.1.2.3: #i20344# init controls from model and apply changes from controls to model 2004/05/05 20:57:02 iha 1.1.2.2: #i20344# start getting to work; added FixedLine; added title 2004/04/07 21:25:56 iha 1.1.2.1: i20344 new
386 lines
13 KiB
C++
386 lines
13 KiB
C++
/*************************************************************************
|
|
*
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
*
|
|
* $RCSfile: tp_RangeChooser.cxx,v $
|
|
*
|
|
* $Revision: 1.2 $
|
|
*
|
|
* last change: $Author: vg $ $Date: 2007-05-22 17:47:43 $
|
|
*
|
|
* The Contents of this file are made available subject to
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
|
*
|
|
*
|
|
* GNU Lesser General Public License Version 2.1
|
|
* =============================================
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
*
|
|
* 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.
|
|
*
|
|
* 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.
|
|
*
|
|
* 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
|
|
*
|
|
************************************************************************/
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
#include "precompiled_chart2.hxx"
|
|
|
|
#include "tp_RangeChooser.hxx"
|
|
#include "tp_RangeChooser.hrc"
|
|
#include "Strings.hrc"
|
|
#include "ResId.hxx"
|
|
#include "macros.hxx"
|
|
#include "NoWarningThisInCTOR.hxx"
|
|
#include "DataSourceHelper.hxx"
|
|
#include "DiagramHelper.hxx"
|
|
#include "ChartTypeTemplateProvider.hxx"
|
|
#include "DialogModel.hxx"
|
|
#include "RangeSelectionHelper.hxx"
|
|
|
|
#ifndef _COM_SUN_STAR_AWT_XTOPWINDOW_HPP_
|
|
#include <com/sun/star/awt/XTopWindow.hpp>
|
|
#endif
|
|
#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_
|
|
#include <com/sun/star/embed/EmbedStates.hpp>
|
|
#endif
|
|
#ifndef _COM_SUN_STAR_EMBED_XCOMPONENTSUPPLIER_HPP_
|
|
#include <com/sun/star/embed/XComponentSupplier.hpp>
|
|
#endif
|
|
|
|
namespace
|
|
{
|
|
void lcl_ShowChooserButton(
|
|
::chart::RangeSelectionButton & rChooserButton,
|
|
Edit & rEditField,
|
|
BOOL bShow )
|
|
{
|
|
if( rChooserButton.IsVisible() != bShow )
|
|
{
|
|
rChooserButton.Show( bShow );
|
|
sal_Int32 nWidhtDiff = 10 + 2;
|
|
if( bShow )
|
|
nWidhtDiff = -nWidhtDiff;
|
|
Size aSize = rChooserButton.PixelToLogic( rEditField.GetSizePixel(), MAP_APPFONT );
|
|
aSize.setWidth( aSize.getWidth() + nWidhtDiff );
|
|
rEditField.SetSizePixel( rChooserButton.LogicToPixel( aSize, MAP_APPFONT ));
|
|
}
|
|
}
|
|
void lcl_enableRangeChoosing( bool bEnable, Dialog * pDialog )
|
|
{
|
|
if( pDialog )
|
|
{
|
|
pDialog->Show( bEnable ? FALSE : TRUE );
|
|
pDialog->SetModalInputMode( bEnable ? FALSE : TRUE );
|
|
}
|
|
}
|
|
void lcl_shiftControlY( Control & rControl, long nYOffset )
|
|
{
|
|
Point aPos( rControl.GetPosPixel());
|
|
aPos.setY( aPos.getY() + nYOffset );
|
|
rControl.SetPosPixel( aPos );
|
|
}
|
|
} // anonymous namespace
|
|
|
|
//.............................................................................
|
|
namespace chart
|
|
{
|
|
//.............................................................................
|
|
using namespace ::com::sun::star;
|
|
using namespace ::com::sun::star::chart2;
|
|
|
|
using ::com::sun::star::uno::Reference;
|
|
using ::com::sun::star::uno::Sequence;
|
|
|
|
|
|
RangeChooserTabPage::RangeChooserTabPage( Window* pParent
|
|
, DialogModel & rDialogModel
|
|
, ChartTypeTemplateProvider* pTemplateProvider
|
|
, Dialog * pParentDialog
|
|
, bool bHideDescription /* = false */ )
|
|
|
|
: OWizardPage( pParent, SchResId(TP_RANGECHOOSER) )
|
|
|
|
, m_aFT_Caption( this, SchResId( FT_CAPTION_FOR_WIZARD ) )
|
|
, m_aFT_Range( this, SchResId( FT_RANGE ) )
|
|
, m_aED_Range( this, SchResId( ED_RANGE ) )
|
|
, m_aIB_Range( this, SchResId( IB_RANGE ) )
|
|
, m_aRB_Rows( this, SchResId( RB_DATAROWS ) )
|
|
, m_aRB_Columns( this, SchResId( RB_DATACOLS ) )
|
|
, m_aCB_FirstRowAsLabel( this, SchResId( CB_FIRST_ROW_ASLABELS ) )
|
|
, m_aCB_FirstColumnAsLabel( this, SchResId( CB_FIRST_COLUMN_ASLABELS ) )
|
|
, m_nChangingControlCalls(0)
|
|
, m_bIsDirty(false)
|
|
, m_xDataProvider( 0 )
|
|
, m_aLastValidRangeString()
|
|
, m_xCurrentChartTypeTemplate(0)
|
|
, m_pTemplateProvider(pTemplateProvider)
|
|
, m_rDialogModel( rDialogModel )
|
|
, m_pParentDialog( pParentDialog )
|
|
, m_pTabPageNotifiable( dynamic_cast< TabPageNotifiable * >( pParentDialog ))
|
|
{
|
|
FreeResource();
|
|
|
|
if( bHideDescription )
|
|
{
|
|
// note: the offset should be a negative value for shifting upwards, the
|
|
// 4 is for the offset difference between a wizard page and a tab-page
|
|
long nYOffset = - ( m_aFT_Range.GetPosPixel().getY() - m_aFT_Caption.GetPosPixel().getY() + 4 );
|
|
m_aFT_Caption.Hide();
|
|
|
|
// shift all controls by the offset space saved by hiding the caption
|
|
lcl_shiftControlY( m_aFT_Range, nYOffset );
|
|
lcl_shiftControlY( m_aED_Range, nYOffset );
|
|
lcl_shiftControlY( m_aIB_Range, nYOffset );
|
|
lcl_shiftControlY( m_aRB_Rows, nYOffset );
|
|
lcl_shiftControlY( m_aRB_Columns, nYOffset );
|
|
lcl_shiftControlY( m_aCB_FirstRowAsLabel, nYOffset );
|
|
lcl_shiftControlY( m_aCB_FirstColumnAsLabel, nYOffset );
|
|
}
|
|
else
|
|
{
|
|
// make font of caption bold
|
|
Font aFont( m_aFT_Caption.GetControlFont() );
|
|
aFont.SetWeight( WEIGHT_BOLD );
|
|
m_aFT_Caption.SetControlFont( aFont );
|
|
|
|
// no mnemonic
|
|
m_aFT_Caption.SetStyle( m_aFT_Caption.GetStyle() | WB_NOLABEL );
|
|
}
|
|
|
|
this->SetText( String(SchResId(STR_PAGE_DATA_RANGE)) );
|
|
m_aIB_Range.SetQuickHelpText( String(SchResId(STR_TIP_SELECT_RANGE)) );
|
|
|
|
// set defaults as long as DetectArguments does not work
|
|
m_aRB_Columns.Check();
|
|
m_aCB_FirstColumnAsLabel.Check();
|
|
m_aCB_FirstRowAsLabel.Check();
|
|
|
|
// BM: Note, that the range selection is not available, if there is no view.
|
|
// This happens for charts having their own embedded spreadsheet. If you
|
|
// force to get the range selection here, this would mean when entering this
|
|
// page the calc view would be created in this case. So, I enable the
|
|
// button here, and in the worst case nothing happens when it is pressed.
|
|
// Not nice, but I see no better solution for the moment.
|
|
m_aIB_Range.SetClickHdl( LINK( this, RangeChooserTabPage, ChooseRangeHdl ));
|
|
|
|
// #i75179# enable setting the background to a different color
|
|
m_aED_Range.SetStyle( m_aED_Range.GetStyle() | WB_FORCECTRLBACKGROUND );
|
|
|
|
m_aED_Range.SetModifyHdl( LINK( this, RangeChooserTabPage, EditRangeHdl ));
|
|
m_aRB_Rows.SetToggleHdl( LINK( this, RangeChooserTabPage, ToogleRowsColumnsHdl ) );
|
|
m_aCB_FirstRowAsLabel.SetToggleHdl( LINK( this, RangeChooserTabPage, ToogleLabelHdl ) );
|
|
m_aCB_FirstColumnAsLabel.SetToggleHdl( LINK( this, RangeChooserTabPage, ToogleLabelHdl ) );
|
|
}
|
|
|
|
RangeChooserTabPage::~RangeChooserTabPage()
|
|
{
|
|
}
|
|
|
|
void RangeChooserTabPage::ActivatePage()
|
|
{
|
|
OWizardPage::ActivatePage();
|
|
|
|
initControlsFromModel();
|
|
}
|
|
|
|
void RangeChooserTabPage::initControlsFromModel()
|
|
{
|
|
m_nChangingControlCalls++;
|
|
|
|
if(m_pTemplateProvider)
|
|
{
|
|
m_xCurrentChartTypeTemplate = m_pTemplateProvider->getCurrentTemplate();
|
|
}
|
|
|
|
bool bUseColumns = ! m_aRB_Rows.IsChecked();
|
|
bool bFirstCellAsLabel = bUseColumns ? m_aCB_FirstRowAsLabel.IsChecked() : m_aCB_FirstColumnAsLabel.IsChecked();
|
|
bool bHasCategories = bUseColumns ? m_aCB_FirstColumnAsLabel.IsChecked() : m_aCB_FirstRowAsLabel.IsChecked();
|
|
|
|
bool bIsValid = m_rDialogModel.allArgumentsForRectRangeDetected();
|
|
if( bIsValid )
|
|
m_rDialogModel.detectArguments(
|
|
m_aLastValidRangeString, bUseColumns, bFirstCellAsLabel, bHasCategories );
|
|
else
|
|
m_aLastValidRangeString = String::EmptyString();
|
|
|
|
m_aED_Range.SetText( m_aLastValidRangeString );
|
|
|
|
m_aRB_Rows.Check( !bUseColumns );
|
|
m_aRB_Columns.Check( bUseColumns );
|
|
|
|
m_aCB_FirstRowAsLabel.Check( m_aRB_Rows.IsChecked()?bHasCategories:bFirstCellAsLabel );
|
|
m_aCB_FirstColumnAsLabel.Check( m_aRB_Columns.IsChecked()?bHasCategories:bFirstCellAsLabel );
|
|
|
|
isValid();
|
|
|
|
m_nChangingControlCalls--;
|
|
}
|
|
|
|
void RangeChooserTabPage::changeModelAccordingToControls()
|
|
{
|
|
changeDialogModelAccordingToControls();
|
|
}
|
|
|
|
void RangeChooserTabPage::changeDialogModelAccordingToControls()
|
|
{
|
|
if(m_nChangingControlCalls>0)
|
|
return;
|
|
|
|
if( !m_xCurrentChartTypeTemplate.is() )
|
|
{
|
|
if(m_pTemplateProvider)
|
|
m_xCurrentChartTypeTemplate.set( m_pTemplateProvider->getCurrentTemplate());
|
|
if( !m_xCurrentChartTypeTemplate.is())
|
|
{
|
|
OSL_ENSURE( false, "Need a template to change data source" );
|
|
return;
|
|
}
|
|
}
|
|
|
|
if( isDirty() )
|
|
{
|
|
sal_Bool bFirstCellAsLabel = ( m_aCB_FirstColumnAsLabel.IsChecked() && !m_aRB_Columns.IsChecked() )
|
|
|| ( m_aCB_FirstRowAsLabel.IsChecked() && !m_aRB_Rows.IsChecked() );
|
|
sal_Bool bHasCategories = ( m_aCB_FirstColumnAsLabel.IsChecked() && m_aRB_Columns.IsChecked() )
|
|
|| ( m_aCB_FirstRowAsLabel.IsChecked() && m_aRB_Rows.IsChecked() );
|
|
|
|
Sequence< beans::PropertyValue > aArguments(
|
|
DataSourceHelper::createArguments(
|
|
m_aRB_Columns.IsChecked(), bFirstCellAsLabel, bHasCategories ) );
|
|
|
|
// only if range is valid
|
|
if( m_aLastValidRangeString.equals( m_aED_Range.GetText()))
|
|
{
|
|
m_rDialogModel.setTemplate( m_xCurrentChartTypeTemplate );
|
|
aArguments.realloc( aArguments.getLength() + 1 );
|
|
aArguments[aArguments.getLength() - 1] =
|
|
beans::PropertyValue( C2U("CellRangeRepresentation"), -1,
|
|
uno::makeAny( m_aLastValidRangeString ),
|
|
beans::PropertyState_DIRECT_VALUE );
|
|
m_rDialogModel.setData( aArguments );
|
|
m_bIsDirty = false;
|
|
}
|
|
|
|
//@todo warn user that the selected range is not valid
|
|
//@todo better: disable OK-Button if range is invalid
|
|
}
|
|
}
|
|
|
|
bool RangeChooserTabPage::isValid()
|
|
{
|
|
::rtl::OUString aRange( m_aED_Range.GetText());
|
|
bool bIsValid = ( aRange.getLength() == 0 ) ||
|
|
m_rDialogModel.getRangeSelectionHelper()->verifyCellRange( aRange );
|
|
|
|
if( bIsValid )
|
|
{
|
|
m_aED_Range.SetControlForeground();
|
|
m_aED_Range.SetControlBackground();
|
|
if( m_pTabPageNotifiable )
|
|
m_pTabPageNotifiable->setValidPage( this );
|
|
m_aLastValidRangeString = aRange;
|
|
}
|
|
else
|
|
{
|
|
m_aED_Range.SetControlBackground( RANGE_SELECTION_INVALID_RANGE_BACKGROUND_COLOR );
|
|
m_aED_Range.SetControlForeground( RANGE_SELECTION_INVALID_RANGE_FOREGROUND_COLOR );
|
|
if( m_pTabPageNotifiable )
|
|
m_pTabPageNotifiable->setInvalidPage( this );
|
|
}
|
|
|
|
// enable/disable controls
|
|
m_aRB_Rows.Enable( bIsValid );
|
|
m_aRB_Columns.Enable( bIsValid );
|
|
m_aCB_FirstRowAsLabel.Enable( bIsValid );
|
|
m_aCB_FirstColumnAsLabel.Enable( bIsValid );
|
|
BOOL bShowIB = m_rDialogModel.getRangeSelectionHelper()->hasRangeSelection();
|
|
lcl_ShowChooserButton( m_aIB_Range, m_aED_Range, bShowIB );
|
|
|
|
return bIsValid;
|
|
}
|
|
|
|
|
|
IMPL_LINK( RangeChooserTabPage, ToogleRowsColumnsHdl, void*, EMPTYARG )
|
|
{
|
|
setDirty();
|
|
changeDialogModelAccordingToControls();
|
|
return 0;
|
|
}
|
|
IMPL_LINK( RangeChooserTabPage, ToogleLabelHdl, CheckBox*, EMPTYARG /* pCheckBox */ )
|
|
{
|
|
setDirty();
|
|
changeDialogModelAccordingToControls();
|
|
return 0;
|
|
}
|
|
IMPL_LINK( RangeChooserTabPage, EditRangeHdl, void*, EMPTYARG )
|
|
{
|
|
setDirty();
|
|
if( isValid())
|
|
changeDialogModelAccordingToControls();
|
|
return 0;
|
|
}
|
|
IMPL_LINK( RangeChooserTabPage, ChooseRangeHdl, void *, EMPTYARG )
|
|
{
|
|
rtl::OUString aRange = m_aED_Range.GetText();
|
|
rtl::OUString aTitle( String( SchResId( STR_PAGE_DATA_RANGE ) ));
|
|
|
|
lcl_enableRangeChoosing( true, m_pParentDialog );
|
|
m_rDialogModel.getRangeSelectionHelper()->chooseRange( aRange, aTitle, *this );
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
void RangeChooserTabPage::listeningFinished( const ::rtl::OUString & rNewRange )
|
|
{
|
|
//user has selected a new range
|
|
|
|
rtl::OUString aRange( rNewRange );
|
|
|
|
m_rDialogModel.startControllerLockTimer();
|
|
|
|
// stop listening
|
|
m_rDialogModel.getRangeSelectionHelper()->stopRangeListening();
|
|
|
|
//update dialog state
|
|
m_aED_Range.SetText( String( aRange ) );
|
|
ToTop();
|
|
GrabFocus();
|
|
|
|
setDirty();
|
|
if( isValid())
|
|
changeDialogModelAccordingToControls();
|
|
|
|
lcl_enableRangeChoosing( false, m_pParentDialog );
|
|
}
|
|
void RangeChooserTabPage::disposingRangeSelection()
|
|
{
|
|
m_rDialogModel.getRangeSelectionHelper()->stopRangeListening( false );
|
|
}
|
|
|
|
void RangeChooserTabPage::setDirty()
|
|
{
|
|
if( m_nChangingControlCalls == 0 )
|
|
m_bIsDirty = true;
|
|
}
|
|
|
|
bool RangeChooserTabPage::isDirty() const
|
|
{
|
|
return m_bIsDirty;
|
|
}
|
|
|
|
//.............................................................................
|
|
} //namespace chart
|
|
//.............................................................................
|