diff options
Diffstat (limited to 'sc/source/ui/dbgui/pvlaydlg.cxx')
-rw-r--r-- | sc/source/ui/dbgui/pvlaydlg.cxx | 2113 |
1 files changed, 619 insertions, 1494 deletions
diff --git a/sc/source/ui/dbgui/pvlaydlg.cxx b/sc/source/ui/dbgui/pvlaydlg.cxx index 62b3665ab27b..a1a90731cf0f 100644 --- a/sc/source/ui/dbgui/pvlaydlg.cxx +++ b/sc/source/ui/dbgui/pvlaydlg.cxx @@ -28,19 +28,16 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sc.hxx" - - -//---------------------------------------------------------------------------- - #include "pvlaydlg.hxx" -#include "dbdocfun.hxx" - -#include <sfx2/dispatch.hxx> -#include <vcl/msgbox.hxx> #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp> +#include <sfx2/dispatch.hxx> +#include <vcl/mnemonic.hxx> +#include <vcl/msgbox.hxx> + +#include "dbdocfun.hxx" #include "uiitems.hxx" #include "rangeutl.hxx" #include "document.hxx" @@ -48,8 +45,6 @@ #include "tabvwsh.hxx" #include "reffact.hxx" #include "scresid.hxx" -#include "pvglob.hxx" -//CHINA001 #include "pvfundlg.hxx" #include "globstr.hrc" #include "pivot.hrc" #include "dpobject.hxx" @@ -59,221 +54,140 @@ #include "sc.hrc" //CHINA001 #include "scabstdlg.hxx" //CHINA001 -using namespace com::sun::star; -using ::rtl::OUString; -using ::std::vector; - -//---------------------------------------------------------------------------- - -#define FSTR(index) aFuncNameArr[index-1] -#define STD_FORMAT SCA_VALID | SCA_TAB_3D \ - | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE -long PivotGlobal::nObjHeight = 0; // initialized with resource data -long PivotGlobal::nObjWidth = 0; -long PivotGlobal::nSelSpace = 0; +// ============================================================================ +using namespace ::com::sun::star; +using ::rtl::OUString; -//============================================================================ +// ============================================================================ namespace { -void lcl_FillToPivotField( PivotField& rPivotField, const ScDPFuncData& rFuncData ) -{ - rPivotField.nCol = rFuncData.mnCol; - rPivotField.nFuncMask = rFuncData.mnFuncMask; - rPivotField.maFieldRef = rFuncData.maFieldRef; -} +const sal_uInt16 STD_FORMAT = sal_uInt16( SCA_VALID | SCA_TAB_3D | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE ); -PointerStyle lclGetPointerForField( ScDPFieldType eType ) +OUString lclGetNameWithoutMnemonic( const FixedText& rFixedText ) { - switch( eType ) - { - case TYPE_PAGE: return POINTER_PIVOT_FIELD; - case TYPE_COL: return POINTER_PIVOT_COL; - case TYPE_ROW: return POINTER_PIVOT_ROW; - case TYPE_DATA: return POINTER_PIVOT_FIELD; - case TYPE_SELECT: return POINTER_PIVOT_FIELD; - } - return POINTER_ARROW; + return MnemonicGenerator::EraseAllMnemonicChars( rFixedText.GetText() ); } } // namespace -//============================================================================ - -//---------------------------------------------------------------------------- - -ScDPLayoutDlg::ScDPLayoutDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, - const ScDPObject& rDPObject ) - : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_PIVOT_LAYOUT ), - aFlLayout ( this, ScResId( FL_LAYOUT ) ), - aFtPage ( this, ScResId( FT_PAGE ) ), - aWndPage ( this, ScResId( WND_PAGE ), TYPE_PAGE, &aFtPage ), - aFtCol ( this, ScResId( FT_COL ) ), - aWndCol ( this, ScResId( WND_COL ), TYPE_COL, &aFtCol ), - aFtRow ( this, ScResId( FT_ROW ) ), - aWndRow ( this, ScResId( WND_ROW ), TYPE_ROW, &aFtRow ), - aFtData ( this, ScResId( FT_DATA ) ), - aWndData ( this, ScResId( WND_DATA ), TYPE_DATA, &aFtData ), - aWndSelect ( this, ScResId( WND_SELECT ), TYPE_SELECT, String(ScResId(STR_SELECT)) ), - aSlider ( this, ScResId( WND_HSCROLL ) ), - aFtInfo ( this, ScResId( FT_INFO ) ), - - aFlAreas ( this, ScResId( FL_OUTPUT ) ), - - aFtInArea ( this, ScResId( FT_INAREA) ), - aEdInPos ( this, ScResId( ED_INAREA) ), - aRbInPos ( this, ScResId( RB_INAREA ), &aEdInPos, this ), - - aLbOutPos ( this, ScResId( LB_OUTAREA ) ), - aFtOutArea ( this, ScResId( FT_OUTAREA ) ), - aEdOutPos ( this, this, ScResId( ED_OUTAREA ) ), - aRbOutPos ( this, ScResId( RB_OUTAREA ), &aEdOutPos, this ), - aBtnIgnEmptyRows( this, ScResId( BTN_IGNEMPTYROWS ) ), - aBtnDetectCat ( this, ScResId( BTN_DETECTCAT ) ), - aBtnTotalCol ( this, ScResId( BTN_TOTALCOL ) ), - aBtnTotalRow ( this, ScResId( BTN_TOTALROW ) ), - aBtnFilter ( this, ScResId( BTN_FILTER ) ), - aBtnDrillDown ( this, ScResId( BTN_DRILLDOWN ) ), - - aBtnOk ( this, ScResId( BTN_OK ) ), - aBtnCancel ( this, ScResId( BTN_CANCEL ) ), - aBtnHelp ( this, ScResId( BTN_HELP ) ), - aBtnRemove ( this, ScResId( BTN_REMOVE ) ), - aBtnOptions ( this, ScResId( BTN_OPTIONS ) ), - aBtnMore ( this, ScResId( BTN_MORE ) ), - - aStrUndefined ( ScResId( SCSTR_UNDEFINED ) ), - aStrNewTable ( ScResId( SCSTR_NEWTABLE ) ), - - bIsDrag ( FALSE ), - - pEditActive ( NULL ), - - eLastActiveType ( TYPE_SELECT ), - nOffset ( 0 ), - // - xDlgDPObject ( new ScDPObject( rDPObject ) ), - pViewData ( ((ScTabViewShell*)SfxViewShell::Current())-> - GetViewData() ), - pDoc ( ((ScTabViewShell*)SfxViewShell::Current())-> - GetViewData()->GetDocument() ), - bRefInputMode ( FALSE ) -{ - xDlgDPObject->SetAlive( TRUE ); // needed to get structure information - xDlgDPObject->FillOldParam( thePivotData, FALSE ); - xDlgDPObject->FillLabelData( thePivotData ); - - Init(); - FreeResource(); -} - - -//---------------------------------------------------------------------------- - -ScDPLayoutDlg::~ScDPLayoutDlg() -{ - USHORT nEntries = aLbOutPos.GetEntryCount(); - USHORT i; - - for ( i=2; i<nEntries; i++ ) - delete (String*)aLbOutPos.GetEntryData( i ); -} - - -//---------------------------------------------------------------------------- - -ScDPFieldWindow& ScDPLayoutDlg::GetFieldWindow( ScDPFieldType eType ) -{ - switch( eType ) - { - case TYPE_PAGE: return aWndPage; - case TYPE_ROW: return aWndRow; - case TYPE_COL: return aWndCol; - case TYPE_DATA: return aWndData; - default: - { - // added to avoid warnings - } - } - return aWndSelect; -} - -void __EXPORT ScDPLayoutDlg::Init() -{ - DBG_ASSERT( pViewData && pDoc, - "Ctor-Initialisierung fehlgeschlagen!" ); - - aBtnRemove.SetClickHdl( LINK( this, ScDPLayoutDlg, ClickHdl ) ); - aBtnOptions.SetClickHdl( LINK( this, ScDPLayoutDlg, ClickHdl ) ); - - aFuncNameArr.reserve( FUNC_COUNT ); - for ( USHORT i = 0; i < FUNC_COUNT; ++i ) - aFuncNameArr.push_back( String( ScResId( i + 1 ) ) ); - - aBtnMore.AddWindow( &aFlAreas ); - aBtnMore.AddWindow( &aFtInArea ); - aBtnMore.AddWindow( &aEdInPos ); - aBtnMore.AddWindow( &aRbInPos ); - aBtnMore.AddWindow( &aFtOutArea ); - aBtnMore.AddWindow( &aLbOutPos ); - aBtnMore.AddWindow( &aEdOutPos ); - aBtnMore.AddWindow( &aRbOutPos ); - aBtnMore.AddWindow( &aBtnIgnEmptyRows ); - aBtnMore.AddWindow( &aBtnDetectCat ); - aBtnMore.AddWindow( &aBtnTotalCol ); - aBtnMore.AddWindow( &aBtnTotalRow ); - aBtnMore.AddWindow( &aBtnFilter ); - aBtnMore.AddWindow( &aBtnDrillDown ); - aBtnMore.SetClickHdl( LINK( this, ScDPLayoutDlg, MoreClickHdl ) ); - - { - Size aFieldSize( Window( this, ScResId( WND_FIELD ) ).GetSizePixel() ); - OHEIGHT = aFieldSize.Height(); - OWIDTH = aFieldSize.Width(); - } - SSPACE = Window( this, ScResId( WND_FIELD_SPACE ) ).GetSizePixel().Width(); - - CalcWndSizes(); - - aSelectArr.resize( MAX_LABELS ); - aPageArr.resize( MAX_PAGEFIELDS ); - aColArr.resize( MAX_FIELDS ); - aRowArr.resize( MAX_FIELDS ); - aDataArr.resize( MAX_FIELDS ); - - ScRange inRange; - String inString; - if (xDlgDPObject->GetSheetDesc()) - { - aEdInPos.Enable(); - aRbInPos.Enable(); - aOldRange = xDlgDPObject->GetSheetDesc()->aSourceRange; - aOldRange.Format( inString, SCR_ABS_3D, pDoc, pDoc->GetAddressConvention() ); - aEdInPos.SetText(inString); +// ============================================================================ + +ScPivotLayoutDlg::ScPivotLayoutDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, const ScDPObject& rDPObject ) : + + ScAnyRefDlg( pB, pCW, pParent, RID_SCDLG_PIVOT_LAYOUT ), + + maFlLayout( this, ScResId( FL_LAYOUT ) ), + maScrPage( this, ScResId( SCROLL_PAGE ) ), + maFtPage( this, ScResId( FT_PAGE ) ), + maWndPage( this, ScResId( WND_PAGE ), maScrPage, &maFtPage, lclGetNameWithoutMnemonic( maFtPage ), PIVOTFIELDTYPE_PAGE, HID_SC_DPLAY_PAGE, POINTER_PIVOT_FIELD, 5, 2, 1, 0 ), + maScrCol( this, ScResId( SCROLL_COL ) ), + maFtCol( this, ScResId( FT_COL ) ), + maWndCol( this, ScResId( WND_COL ), maScrCol, &maFtCol, lclGetNameWithoutMnemonic( maFtCol ), PIVOTFIELDTYPE_COL, HID_SC_DPLAY_COLUMN, POINTER_PIVOT_COL, 4, 2, 1, 0 ), + maScrRow( this, ScResId( SCROLL_ROW ) ), + maFtRow( this, ScResId( FT_ROW ) ), + maWndRow( this, ScResId( WND_ROW ), maScrRow, &maFtRow, lclGetNameWithoutMnemonic( maFtRow ), PIVOTFIELDTYPE_ROW, HID_SC_DPLAY_ROW, POINTER_PIVOT_ROW, 1, 8, 1, 0 ), + maScrData( this, ScResId( SCROLL_DATA ) ), + maFtData( this, ScResId( FT_DATA ) ), + maWndData( this, ScResId( WND_DATA ), maScrData, &maFtData, lclGetNameWithoutMnemonic( maFtData ), PIVOTFIELDTYPE_DATA, HID_SC_DPLAY_DATA, POINTER_PIVOT_FIELD, 1, 8, 4, 0 ), + maFlSelect( this, ScResId( FL_SELECT ) ), + maScrSelect( this, ScResId( WND_HSCROLL ) ), + maWndSelect( this, ScResId( WND_SELECT ), maScrSelect, 0, String( ScResId( STR_SELECT ) ), PIVOTFIELDTYPE_SELECT, HID_SC_DPLAY_SELECT, POINTER_PIVOT_FIELD, 2, 10, 1, 2 ), + maFtInfo( this, ScResId( FT_INFO ) ), + + maFlAreas( this, ScResId( FL_OUTPUT ) ), + maFtInArea( this, ScResId( FT_INAREA) ), + maEdInPos( this, ScResId( ED_INAREA) ), + maRbInPos( this, ScResId( RB_INAREA ), &maEdInPos, this ), + maLbOutPos( this, ScResId( LB_OUTAREA ) ), + maFtOutArea( this, ScResId( FT_OUTAREA ) ), + maEdOutPos( this, this, ScResId( ED_OUTAREA ) ), + maRbOutPos( this, ScResId( RB_OUTAREA ), &maEdOutPos, this ), + maBtnIgnEmptyRows( this, ScResId( BTN_IGNEMPTYROWS ) ), + maBtnDetectCat( this, ScResId( BTN_DETECTCAT ) ), + maBtnTotalCol( this, ScResId( BTN_TOTALCOL ) ), + maBtnTotalRow( this, ScResId( BTN_TOTALROW ) ), + maBtnFilter( this, ScResId( BTN_FILTER ) ), + maBtnDrillDown( this, ScResId( BTN_DRILLDOWN ) ), + + maBtnOk( this, ScResId( BTN_OK ) ), + maBtnCancel( this, ScResId( BTN_CANCEL ) ), + maBtnHelp( this, ScResId( BTN_HELP ) ), + maBtnRemove( this, ScResId( BTN_REMOVE ) ), + maBtnOptions( this, ScResId( BTN_OPTIONS ) ), + maBtnMore( this, ScResId( BTN_MORE ) ), + + mxDlgDPObject( new ScDPObject( rDPObject ) ), + mpViewData( ((ScTabViewShell*)SfxViewShell::Current())->GetViewData() ), + mpDoc( ((ScTabViewShell*)SfxViewShell::Current())->GetViewData()->GetDocument() ), + mpFocusWindow( 0 ), + mpTrackingWindow( 0 ), + mpDropWindow( 0 ), + mpActiveEdit( 0 ), + mbRefInputMode( false ) +{ + DBG_ASSERT( mpViewData && mpDoc, "ScPivotLayoutDlg::ScPivotLayoutDlg - missing document or view data" ); + + mxDlgDPObject->SetAlive( true ); // needed to get structure information + mxDlgDPObject->FillOldParam( maPivotData ); + mxDlgDPObject->FillLabelData( maPivotData ); + + maBtnRemove.SetClickHdl( LINK( this, ScPivotLayoutDlg, ClickHdl ) ); + maBtnOptions.SetClickHdl( LINK( this, ScPivotLayoutDlg, ClickHdl ) ); + + // PIVOT_MAXFUNC defined in sc/inc/dpglobal.hxx + maFuncNames.reserve( PIVOT_MAXFUNC ); + for( sal_uInt16 i = 1; i <= PIVOT_MAXFUNC; ++i ) + maFuncNames.push_back( String( ScResId( i ) ) ); + + maBtnMore.AddWindow( &maFlAreas ); + maBtnMore.AddWindow( &maFtInArea ); + maBtnMore.AddWindow( &maEdInPos ); + maBtnMore.AddWindow( &maRbInPos ); + maBtnMore.AddWindow( &maFtOutArea ); + maBtnMore.AddWindow( &maLbOutPos ); + maBtnMore.AddWindow( &maEdOutPos ); + maBtnMore.AddWindow( &maRbOutPos ); + maBtnMore.AddWindow( &maBtnIgnEmptyRows ); + maBtnMore.AddWindow( &maBtnDetectCat ); + maBtnMore.AddWindow( &maBtnTotalCol ); + maBtnMore.AddWindow( &maBtnTotalRow ); + maBtnMore.AddWindow( &maBtnFilter ); + maBtnMore.AddWindow( &maBtnDrillDown ); + maBtnMore.SetClickHdl( LINK( this, ScPivotLayoutDlg, MoreClickHdl ) ); + + if( mxDlgDPObject->GetSheetDesc() ) + { + maEdInPos.Enable(); + maRbInPos.Enable(); + ScRange aRange = mxDlgDPObject->GetSheetDesc()->aSourceRange; + String aString; + aRange.Format( aString, SCR_ABS_3D, mpDoc, mpDoc->GetAddressConvention() ); + maEdInPos.SetText( aString ); } else { - /* Data is not reachable, so could be a remote database */ - aEdInPos.Disable(); - aRbInPos.Disable(); + // data is not reachable, so could be a remote database + maEdInPos.Disable(); + maRbInPos.Disable(); } - InitFields(); + // #i29203# align right border of page window with data window + long nPagePosX = maWndData.GetPosPixel().X() + maWndData.GetSizePixel().Width() - maWndPage.GetSizePixel().Width(); + maWndPage.SetPosPixel( Point( nPagePosX, maWndPage.GetPosPixel().Y() ) ); + maScrPage.SetPosPixel( Point( maScrData.GetPosPixel().X(), maScrPage.GetPosPixel().Y() ) ); + + InitFieldWindows(); - aLbOutPos .SetSelectHdl( LINK( this, ScDPLayoutDlg, SelAreaHdl ) ); - aEdOutPos .SetModifyHdl( LINK( this, ScDPLayoutDlg, EdModifyHdl ) ); - aEdInPos .SetModifyHdl( LINK( this, ScDPLayoutDlg, EdInModifyHdl ) ); - aBtnOk .SetClickHdl ( LINK( this, ScDPLayoutDlg, OkHdl ) ); - aBtnCancel.SetClickHdl ( LINK( this, ScDPLayoutDlg, CancelHdl ) ); - Link aLink = LINK( this, ScDPLayoutDlg, GetFocusHdl ); - if ( aEdInPos.IsEnabled() ) - // Once disabled it will never get enabled, so no need to handle focus. - aEdInPos.SetGetFocusHdl( aLink ); - aEdOutPos.SetGetFocusHdl( aLink ); + maLbOutPos.SetSelectHdl( LINK( this, ScPivotLayoutDlg, SelAreaHdl ) ); + maEdOutPos.SetModifyHdl( LINK( this, ScPivotLayoutDlg, EdOutModifyHdl ) ); + maEdInPos.SetModifyHdl( LINK( this, ScPivotLayoutDlg, EdInModifyHdl ) ); + maBtnOk.SetClickHdl( LINK( this, ScPivotLayoutDlg, OkHdl ) ); + maBtnCancel.SetClickHdl( LINK( this, ScPivotLayoutDlg, CancelHdl ) ); - if ( pViewData && pDoc ) + if( mpViewData && mpDoc ) { /* * Aus den RangeNames des Dokumentes werden nun die @@ -281,11 +195,11 @@ void __EXPORT ScDPLayoutDlg::Init() * um sinnvolle Bereiche handelt */ - aLbOutPos.Clear(); - aLbOutPos.InsertEntry( aStrUndefined, 0 ); - aLbOutPos.InsertEntry( aStrNewTable, 1 ); + maLbOutPos.Clear(); + maLbOutPos.InsertEntry( String( ScResId( SCSTR_UNDEFINED ) ), 0 ); + maLbOutPos.InsertEntry( String( ScResId( SCSTR_NEWTABLE ) ), 1 ); - ScAreaNameIterator aIter( pDoc ); + ScAreaNameIterator aIter( mpDoc ); String aName; ScRange aRange; String aRefStr; @@ -293,1539 +207,750 @@ void __EXPORT ScDPLayoutDlg::Init() { if ( !aIter.WasDBName() ) // hier keine DB-Bereiche ! { - USHORT nInsert = aLbOutPos.InsertEntry( aName ); + sal_uInt16 nInsert = maLbOutPos.InsertEntry( aName ); - aRange.aStart.Format( aRefStr, SCA_ABS_3D, pDoc, pDoc->GetAddressConvention() ); - aLbOutPos.SetEntryData( nInsert, new String( aRefStr ) ); + aRange.aStart.Format( aRefStr, SCA_ABS_3D, mpDoc, mpDoc->GetAddressConvention() ); + maLbOutPos.SetEntryData( nInsert, new String( aRefStr ) ); } } } - if ( thePivotData.nTab != MAXTAB+1 ) + if ( maPivotData.nTab != MAXTAB+1 ) { String aStr; - ScAddress( thePivotData.nCol, - thePivotData.nRow, - thePivotData.nTab ).Format( aStr, STD_FORMAT, pDoc, pDoc->GetAddressConvention() ); - aEdOutPos.SetText( aStr ); - EdModifyHdl(0); + ScAddress( maPivotData.nCol, + maPivotData.nRow, + maPivotData.nTab ).Format( aStr, STD_FORMAT, mpDoc, mpDoc->GetAddressConvention() ); + maEdOutPos.SetText( aStr ); + EdOutModifyHdl( 0 ); } else { - aLbOutPos.SelectEntryPos( aLbOutPos.GetEntryCount()-1 ); + maLbOutPos.SelectEntryPos( maLbOutPos.GetEntryCount()-1 ); SelAreaHdl(NULL); } - aBtnIgnEmptyRows.Check( thePivotData.bIgnoreEmptyRows ); - aBtnDetectCat .Check( thePivotData.bDetectCategories ); - aBtnTotalCol .Check( thePivotData.bMakeTotalCol ); - aBtnTotalRow .Check( thePivotData.bMakeTotalRow ); - - if( const ScDPSaveData* pSaveData = xDlgDPObject->GetSaveData() ) - { - aBtnFilter.Check( pSaveData->GetFilterButton() ); - aBtnDrillDown.Check( pSaveData->GetDrillDown() ); - } - else - { - aBtnFilter.Check(); - aBtnDrillDown.Check(); - } - - aWndPage.SetHelpId( HID_SC_DPLAY_PAGE ); - aWndCol.SetHelpId( HID_SC_DPLAY_COLUMN ); - aWndRow.SetHelpId( HID_SC_DPLAY_ROW ); - aWndData.SetHelpId( HID_SC_DPLAY_DATA ); - aWndSelect.SetHelpId( HID_SC_DPLAY_SELECT ); + maBtnIgnEmptyRows.Check( maPivotData.bIgnoreEmptyRows ); + maBtnDetectCat.Check( maPivotData.bDetectCategories ); + maBtnTotalCol.Check( maPivotData.bMakeTotalCol ); + maBtnTotalRow.Check( maPivotData.bMakeTotalRow ); - InitFocus(); + const ScDPSaveData* pSaveData = mxDlgDPObject->GetSaveData(); + maBtnFilter.Check( !pSaveData || pSaveData->GetFilterButton() ); + maBtnDrillDown.Check( !pSaveData || pSaveData->GetDrillDown() ); -// SetDispatcherLock( TRUE ); // Modal-Modus einschalten + // child event listener handles field movement when keyboard shortcut is pressed + AddChildEventListener( LINK( this, ScPivotLayoutDlg, ChildEventListener ) ); + GrabFieldFocus( maWndSelect ); - //@BugID 54702 Enablen/Disablen nur noch in Basisklasse - //SFX_APPWINDOW->Disable(FALSE); //! allgemeine Methode im ScAnyRefDlg -} - - -//---------------------------------------------------------------------------- - -BOOL __EXPORT ScDPLayoutDlg::Close() -{ - return DoClose( ScPivotLayoutWrapper::GetChildWindowId() ); + FreeResource(); } -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::StateChanged( StateChangedType nStateChange ) +ScPivotLayoutDlg::~ScPivotLayoutDlg() { - ScAnyRefDlg::StateChanged( nStateChange ); + RemoveChildEventListener( LINK( this, ScPivotLayoutDlg, ChildEventListener ) ); - if ( nStateChange == STATE_CHANGE_INITSHOW ) - { - // #124828# Hiding the FixedTexts and clearing the tab stop style bits - // has to be done after assigning the mnemonics, but Paint is too late, - // because the test tool may send key events to the dialog when it isn't visible. - // Mnemonics are assigned in the Dialog::StateChanged for STATE_CHANGE_INITSHOW, - // so this can be done immediately afterwards. - - aWndPage.UseMnemonic(); - aWndCol.UseMnemonic(); - aWndRow.UseMnemonic(); - aWndData.UseMnemonic(); - } + for( sal_uInt16 i = 2, nEntries = maLbOutPos.GetEntryCount(); i < nEntries; ++i ) + delete (String*)maLbOutPos.GetEntryData( i ); } -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::InitWndSelect( const vector<ScDPLabelDataRef>& rLabels ) +ScDPLabelData* ScPivotLayoutDlg::GetLabelData( SCCOL nCol, size_t* pnIndex ) { - size_t nLabelCount = rLabels.size(); - if (nLabelCount > MAX_LABELS) - nLabelCount = MAX_LABELS; - size_t nLast = (nLabelCount > PAGE_SIZE) ? (PAGE_SIZE - 1) : (nLabelCount - 1); - - aLabelDataArr.clear(); - aLabelDataArr.reserve( nLabelCount ); - for ( size_t i=0; i < nLabelCount; i++ ) + ScDPLabelData* pLabelData = 0; + for( ScDPLabelDataVector::iterator aIt = maLabelData.begin(), aEnd = maLabelData.end(); !pLabelData && (aIt != aEnd); ++aIt ) { - aLabelDataArr.push_back(*rLabels[i]); - - if ( i <= nLast ) + if( aIt->mnCol == nCol ) { - aWndSelect.AddField(aLabelDataArr[i].getDisplayName(), i); - aSelectArr[i].reset( new ScDPFuncData( aLabelDataArr[i].mnCol, aLabelDataArr[i].mnFuncMask ) ); + pLabelData = &*aIt; + if( pnIndex ) + *pnIndex = aIt - maLabelData.begin(); } } + return pLabelData; } - -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::InitWnd( PivotField* pArr, long nCount, ScDPFieldType eType ) +String ScPivotLayoutDlg::GetFuncString( sal_uInt16& rnFuncMask, bool bIsValue ) { - if ( pArr && (eType != TYPE_SELECT) ) - { - ScDPFuncDataVec* pInitArr = NULL; - ScDPFieldWindow* pInitWnd = NULL; - BOOL bDataArr = FALSE; + String aStr; - switch ( eType ) + if( (rnFuncMask == PIVOT_FUNC_NONE) || (rnFuncMask == PIVOT_FUNC_AUTO) ) + { + if( bIsValue ) { - case TYPE_PAGE: - pInitArr = &aPageArr; - pInitWnd = &aWndPage; - break; - - case TYPE_COL: - pInitArr = &aColArr; - pInitWnd = &aWndCol; - break; - - case TYPE_ROW: - pInitArr = &aRowArr; - pInitWnd = &aWndRow; - break; - - case TYPE_DATA: - pInitArr = &aDataArr; - pInitWnd = &aWndData; - bDataArr = TRUE; - break; - default: - break; + aStr = GetFuncName( PIVOTSTR_SUM ); + rnFuncMask = PIVOT_FUNC_SUM; } - - if ( pInitArr && pInitWnd ) + else { - long j=0; - for ( long i=0; (i<nCount); i++ ) - { - SCCOL nCol = pArr[i].nCol; - USHORT nMask = pArr[i].nFuncMask; - - if ( nCol != PIVOT_DATA_FIELD ) - { - (*pInitArr)[j].reset( new ScDPFuncData( nCol, nMask, pArr[i].maFieldRef ) ); - - if ( !bDataArr ) - { - pInitWnd->AddField( GetLabelString( nCol ), j ); - } - else - { - ScDPLabelData* pData = GetLabelData( nCol ); - DBG_ASSERT( pData, "ScDPLabelData not found" ); - if (pData) - { - String aStr( GetFuncString( (*pInitArr)[j]->mnFuncMask, - pData->mbIsValue ) ); - - aStr += GetLabelString( nCol ); - pInitWnd->AddField( aStr, j ); - - pData->mnFuncMask = nMask; - } - } - ++j; - } - } -// Do not redraw here -> first the FixedText has to get its mnemonic char -// pInitWnd->Redraw(); - } + aStr = GetFuncName( PIVOTSTR_COUNT ); + rnFuncMask = PIVOT_FUNC_COUNT; + } + } + else if( rnFuncMask == PIVOT_FUNC_SUM ) aStr = GetFuncName( PIVOTSTR_SUM ); + else if( rnFuncMask == PIVOT_FUNC_COUNT ) aStr = GetFuncName( PIVOTSTR_COUNT ); + else if( rnFuncMask == PIVOT_FUNC_AVERAGE ) aStr = GetFuncName( PIVOTSTR_AVG ); + else if( rnFuncMask == PIVOT_FUNC_MAX ) aStr = GetFuncName( PIVOTSTR_MAX ); + else if( rnFuncMask == PIVOT_FUNC_MIN ) aStr = GetFuncName( PIVOTSTR_MIN ); + else if( rnFuncMask == PIVOT_FUNC_PRODUCT ) aStr = GetFuncName( PIVOTSTR_PROD ); + else if( rnFuncMask == PIVOT_FUNC_COUNT_NUM ) aStr = GetFuncName( PIVOTSTR_COUNT2 ); + else if( rnFuncMask == PIVOT_FUNC_STD_DEV ) aStr = GetFuncName( PIVOTSTR_DEV ); + else if( rnFuncMask == PIVOT_FUNC_STD_DEVP ) aStr = GetFuncName( PIVOTSTR_DEV2 ); + else if( rnFuncMask == PIVOT_FUNC_STD_VAR ) aStr = GetFuncName( PIVOTSTR_VAR ); + else if( rnFuncMask == PIVOT_FUNC_STD_VARP ) aStr = GetFuncName( PIVOTSTR_VAR2 ); + else + { + aStr = ScGlobal::GetRscString( STR_TABLE_ERGEBNIS ); + aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " - " ) ); } -} - -//---------------------------------------------------------------------------- + return aStr; +} -void ScDPLayoutDlg::InitFocus() +void ScPivotLayoutDlg::NotifyStartTracking( ScPivotFieldWindow& rSourceWindow ) { - if( aWndSelect.IsEmpty() ) - { - aBtnOk.GrabFocus(); - NotifyFieldFocus( TYPE_SELECT, FALSE ); - } - else - aWndSelect.GrabFocus(); + mpTrackingWindow = &rSourceWindow; + mpDropWindow = 0; + rSourceWindow.NotifyStartTracking(); + StartTracking( STARTTRACK_BUTTONREPEAT ); + SetPointer( Pointer( rSourceWindow.GetDropPointerStyle() ) ); } -void ScDPLayoutDlg::InitFields() +void ScPivotLayoutDlg::NotifyDoubleClick( ScPivotFieldWindow& rSourceWindow ) { - InitWndSelect(thePivotData.maLabelArray); - InitWnd( thePivotData.aPageArr, static_cast<long>(thePivotData.nPageCount), TYPE_PAGE ); - InitWnd( thePivotData.aColArr, static_cast<long>(thePivotData.nColCount), TYPE_COL ); - InitWnd( thePivotData.aRowArr, static_cast<long>(thePivotData.nRowCount), TYPE_ROW ); - InitWnd( thePivotData.aDataArr, static_cast<long>(thePivotData.nDataCount), TYPE_DATA ); - - size_t nLabels = thePivotData.maLabelArray.size(); - aSlider.SetPageSize( PAGE_SIZE ); - aSlider.SetVisibleSize( PAGE_SIZE ); - aSlider.SetLineSize( LINE_SIZE ); - aSlider.SetRange( Range( 0, static_cast<long>(((nLabels+LINE_SIZE-1)/LINE_SIZE)*LINE_SIZE) ) ); - - if ( nLabels > PAGE_SIZE ) - { - aSlider.SetEndScrollHdl( LINK( this, ScDPLayoutDlg, ScrollHdl ) ); - aSlider.Show(); - } - else - aSlider.Hide(); -} + // nothing to do on double-click in selection window + if( rSourceWindow.GetType() == PIVOTFIELDTYPE_SELECT ) + return; -//---------------------------------------------------------------------------- + const ScPivotFuncData* pFuncData = rSourceWindow.GetSelectedFuncData(); + DBG_ASSERT( pFuncData, "ScPivotLayoutDlg::NotifyDoubleClick - invalid selection" ); + if( !pFuncData ) + return; -void ScDPLayoutDlg::AddField( size_t nFromIndex, ScDPFieldType eToType, const Point& rAtPos ) -{ - ScDPFuncData fData( *(aSelectArr[nFromIndex]) ); - size_t nAt = 0; - ScDPFieldWindow* toWnd = NULL; - ScDPFieldWindow* rmWnd1 = NULL; - ScDPFieldWindow* rmWnd2 = NULL; - ScDPFuncDataVec* toArr = NULL; - ScDPFuncDataVec* rmArr1 = NULL; - ScDPFuncDataVec* rmArr2 = NULL; - BOOL bDataArr = FALSE; - - switch ( eToType ) + ScDPLabelData* pLabelData = GetLabelData( pFuncData->mnCol ); + DBG_ASSERT( pLabelData, "ScPivotLayoutDlg::NotifyDoubleClick - missing label data" ); + if( !pLabelData ) + return; + + ScAbstractDialogFactory* pFactory = ScAbstractDialogFactory::Create(); + DBG_ASSERT( pFactory, "ScPivotLayoutDlg::NotifyDoubleClick - ScAbstractDialogFactory creation failed" ); + if( !pFactory ) + return; + + if( rSourceWindow.GetType() == PIVOTFIELDTYPE_DATA ) { - case TYPE_PAGE: - toWnd = &aWndPage; - rmWnd1 = &aWndRow; - rmWnd2 = &aWndCol; - toArr = &aPageArr; - rmArr1 = &aRowArr; - rmArr2 = &aColArr; - break; - - case TYPE_COL: - toWnd = &aWndCol; - rmWnd1 = &aWndPage; - rmWnd2 = &aWndRow; - toArr = &aColArr; - rmArr1 = &aPageArr; - rmArr2 = &aRowArr; - break; - - case TYPE_ROW: - toWnd = &aWndRow; - rmWnd1 = &aWndPage; - rmWnd2 = &aWndCol; - toArr = &aRowArr; - rmArr1 = &aPageArr; - rmArr2 = &aColArr; - break; - - case TYPE_DATA: - toWnd = &aWndData; - toArr = &aDataArr; - bDataArr = TRUE; - break; - - default: + ::std::auto_ptr< AbstractScDPFunctionDlg > xDlg( pFactory->CreateScDPFunctionDlg( + this, RID_SCDLG_DPDATAFIELD, maLabelData, *pLabelData, *pFuncData ) ); + if( xDlg->Execute() == RET_OK ) { - // added to avoid warnings + ScPivotFuncData aFuncData( *pFuncData ); + aFuncData.mnFuncMask = pLabelData->mnFuncMask = xDlg->GetFuncMask(); + aFuncData.maFieldRef = xDlg->GetFieldRef(); + rSourceWindow.ModifySelectedField( aFuncData ); } } - - bool bAllowed = IsOrientationAllowed( fData.mnCol, eToType ); - if ( bAllowed - && (toArr->back().get() == NULL) - && (!Contains( toArr, fData.mnCol, nAt )) ) + else { - // ggF. in anderem Fenster entfernen - if ( rmArr1 ) - { - if ( Contains( rmArr1, fData.mnCol, nAt ) ) - { - rmWnd1->DelField( nAt ); - Remove( rmArr1, nAt ); - } - } - if ( rmArr2 ) - { - if ( Contains( rmArr2, fData.mnCol, nAt ) ) - { - rmWnd2->DelField( nAt ); - Remove( rmArr2, nAt ); - } - } - - ScDPLabelData& rData = aLabelDataArr[nFromIndex+nOffset]; - size_t nAddedAt = 0; + // list of plain names of all data fields + ScDPNameVec aDataFieldNames; + maWndData.WriteFieldNames( aDataFieldNames ); + // allow to modify layout options for row fields, if multiple data fields exist, or if it is not the last row field + bool bLayout = (rSourceWindow.GetType() == PIVOTFIELDTYPE_ROW) && ((aDataFieldNames.size() > 1) || (rSourceWindow.GetSelectedIndex() + 1 < rSourceWindow.GetFieldCount())); - if ( !bDataArr ) - { - if ( toWnd->AddField( rData.getDisplayName(), - DlgPos2WndPos( rAtPos, *toWnd ), - nAddedAt ) ) - { - Insert( toArr, fData, nAddedAt ); - toWnd->GrabFocus(); - } - } - else + ::std::auto_ptr< AbstractScDPSubtotalDlg > xDlg( pFactory->CreateScDPSubtotalDlg( + this, RID_SCDLG_PIVOTSUBT, *mxDlgDPObject, *pLabelData, *pFuncData, aDataFieldNames, bLayout ) ); + if( xDlg->Execute() == RET_OK ) { - USHORT nMask = fData.mnFuncMask; - OUString aStr = GetFuncString( nMask, rData.mbIsValue ); - - aStr += rData.getDisplayName(); - - if ( toWnd->AddField( aStr, - DlgPos2WndPos( rAtPos, *toWnd ), - nAddedAt ) ) - { - fData.mnFuncMask = nMask; - Insert( toArr, fData, nAddedAt ); - toWnd->GrabFocus(); - } + xDlg->FillLabelData( *pLabelData ); + ScPivotFuncData aFuncData( *pFuncData ); + aFuncData.mnFuncMask = pLabelData->mnFuncMask; + rSourceWindow.ModifySelectedField( aFuncData ); } - } } +void ScPivotLayoutDlg::NotifyFieldRemoved( ScPivotFieldWindow& rSourceWindow ) +{ + // update focus: move to selection window, if source window is empty now + GrabFieldFocus( rSourceWindow ); +} -//---------------------------------------------------------------------------- +// protected ------------------------------------------------------------------ -void ScDPLayoutDlg::MoveField( ScDPFieldType eFromType, size_t nFromIndex, ScDPFieldType eToType, const Point& rAtPos ) +void ScPivotLayoutDlg::Tracking( const TrackingEvent& rTEvt ) { - if ( eFromType == TYPE_SELECT ) - AddField( nFromIndex, eToType, rAtPos ); - else if ( eFromType != eToType ) - { - ScDPFieldWindow* fromWnd = NULL; - ScDPFieldWindow* toWnd = NULL; - ScDPFieldWindow* rmWnd1 = NULL; - ScDPFieldWindow* rmWnd2 = NULL; - ScDPFuncDataVec* fromArr = NULL; - ScDPFuncDataVec* toArr = NULL; - ScDPFuncDataVec* rmArr1 = NULL; - ScDPFuncDataVec* rmArr2 = NULL; - size_t nAt = 0; - BOOL bDataArr = FALSE; - - switch ( eFromType ) - { - case TYPE_PAGE: - fromWnd = &aWndPage; - fromArr = &aPageArr; - break; - - case TYPE_COL: - fromWnd = &aWndCol; - fromArr = &aColArr; - break; - - case TYPE_ROW: - fromWnd = &aWndRow; - fromArr = &aRowArr; - break; - - case TYPE_DATA: - fromWnd = &aWndData; - fromArr = &aDataArr; - break; - - default: - { - // added to avoid warnings - } - } + DBG_ASSERT( mpTrackingWindow, "ScPivotLayoutDlg::Tracking - missing tracking source window" ); + if( !mpTrackingWindow ) + return; - switch ( eToType ) - { - case TYPE_PAGE: - toWnd = &aWndPage; - toArr = &aPageArr; - rmWnd1 = &aWndCol; - rmWnd2 = &aWndRow; - rmArr1 = &aColArr; - rmArr2 = &aRowArr; - break; - - case TYPE_COL: - toWnd = &aWndCol; - toArr = &aColArr; - rmWnd1 = &aWndPage; - rmWnd2 = &aWndRow; - rmArr1 = &aPageArr; - rmArr2 = &aRowArr; - break; - - case TYPE_ROW: - toWnd = &aWndRow; - toArr = &aRowArr; - rmWnd1 = &aWndPage; - rmWnd2 = &aWndCol; - rmArr1 = &aPageArr; - rmArr2 = &aColArr; - break; - - case TYPE_DATA: - toWnd = &aWndData; - toArr = &aDataArr; - bDataArr = TRUE; - break; - - default: - { - // added to avoid warnings - } - } + // find target window + const Point& rDialogPos = rTEvt.GetMouseEvent().GetPosPixel(); + ScPivotFieldWindow* pTargetWindow = dynamic_cast< ScPivotFieldWindow* >( FindWindow( rDialogPos ) ); - if ( fromArr && toArr && fromWnd && toWnd ) - { - ScDPFuncData fData( *((*fromArr)[nFromIndex]) ); + // check if the target orientation is allowed for this field + if( pTargetWindow && (mpTrackingWindow != pTargetWindow) && !IsInsertAllowed( *mpTrackingWindow, *pTargetWindow ) ) + pTargetWindow = 0; - bool bAllowed = IsOrientationAllowed( fData.mnCol, eToType ); - if ( bAllowed && Contains( fromArr, fData.mnCol, nAt ) ) - { - fromWnd->DelField( nAt ); - Remove( fromArr, nAt ); + // tracking from selection window: do not show "delete" mouse pointer + PointerStyle eTargetPointer = pTargetWindow ? pTargetWindow->GetDropPointerStyle() : + ((mpTrackingWindow->GetType() == PIVOTFIELDTYPE_SELECT) ? POINTER_NOTALLOWED : POINTER_PIVOT_DELETE); - if ( (toArr->back().get() == NULL) - && (!Contains( toArr, fData.mnCol, nAt )) ) - { - size_t nAddedAt = 0; - if ( !bDataArr ) - { - // ggF. in anderem Fenster entfernen - if ( rmArr1 ) - { - if ( Contains( rmArr1, fData.mnCol, nAt ) ) - { - rmWnd1->DelField( nAt ); - Remove( rmArr1, nAt ); - } - } - if ( rmArr2 ) - { - if ( Contains( rmArr2, fData.mnCol, nAt ) ) - { - rmWnd2->DelField( nAt ); - Remove( rmArr2, nAt ); - } - } + // after calculating pointer style, check if target is selection window + if( pTargetWindow && (pTargetWindow->GetType() == PIVOTFIELDTYPE_SELECT) ) + pTargetWindow = 0; - if ( toWnd->AddField( GetLabelString( fData.mnCol ), - DlgPos2WndPos( rAtPos, *toWnd ), - nAddedAt ) ) - { - Insert( toArr, fData, nAddedAt ); - toWnd->GrabFocus(); - } - } - else - { - String aStr; - USHORT nMask = fData.mnFuncMask; - aStr = GetFuncString( nMask ); - aStr += GetLabelString( fData.mnCol ); - - if ( toWnd->AddField( aStr, - DlgPos2WndPos( rAtPos, *toWnd ), - nAddedAt ) ) - { - fData.mnFuncMask = nMask; - Insert( toArr, fData, nAddedAt ); - toWnd->GrabFocus(); - } - } - } - } - } + // notify windows about tracking + if( mpDropWindow != pTargetWindow ) + { + // tracking window changed + if( mpDropWindow ) + mpDropWindow->NotifyEndTracking( ENDTRACKING_SUSPEND ); + if( pTargetWindow ) + pTargetWindow->NotifyStartTracking(); + mpDropWindow = pTargetWindow; } - else // -> eFromType == eToType + if( mpDropWindow ) + mpDropWindow->NotifyTracking( rDialogPos - pTargetWindow->GetPosPixel() ); + + // end tracking: move or remove field + if( rTEvt.IsTrackingEnded() ) { - ScDPFieldWindow* theWnd = NULL; - ScDPFuncDataVec* theArr = NULL; - size_t nAt = 0; - size_t nToIndex = 0; - Point aToPos; - BOOL bDataArr = FALSE; - - switch ( eFromType ) + bool bCancelled = rTEvt.IsTrackingCanceled(); + if( mpDropWindow ) { - case TYPE_PAGE: - theWnd = &aWndPage; - theArr = &aPageArr; - break; - - case TYPE_COL: - theWnd = &aWndCol; - theArr = &aColArr; - break; - - case TYPE_ROW: - theWnd = &aWndRow; - theArr = &aRowArr; - break; - - case TYPE_DATA: - theWnd = &aWndData; - theArr = &aDataArr; - bDataArr = TRUE; - break; - - default: + mpDropWindow->NotifyEndTracking( bCancelled ? ENDTRACKING_CANCEL : ENDTRACKING_DROP ); + if( !bCancelled ) { - // added to avoid warnings + size_t nInsertIndex = mpDropWindow->GetDropIndex( rDialogPos - mpDropWindow->GetPosPixel() ); + bool bMoved = MoveField( *mpTrackingWindow, *mpDropWindow, nInsertIndex, true ); + // focus drop window, if move was successful, otherwise back to source window + GrabFieldFocus( bMoved ? *mpDropWindow : *mpTrackingWindow ); } } - - ScDPFuncData fData( *((*theArr)[nFromIndex]) ); - - if ( Contains( theArr, fData.mnCol, nAt ) ) + else { - aToPos = DlgPos2WndPos( rAtPos, *theWnd ); - theWnd->GetExistingIndex( aToPos, nToIndex ); - - if ( nToIndex != nAt ) - { - size_t nAddedAt = 0; - - theWnd->DelField( nAt ); - Remove( theArr, nAt ); - - if ( !bDataArr ) - { - if ( theWnd->AddField( GetLabelString( fData.mnCol ), - aToPos, - nAddedAt ) ) - { - Insert( theArr, fData, nAddedAt ); - } - } - else - { - String aStr; - USHORT nMask = fData.mnFuncMask; - aStr = GetFuncString( nMask ); - aStr += GetLabelString( fData.mnCol ); - - if ( theWnd->AddField( aStr, - DlgPos2WndPos( rAtPos, *theWnd ), - nAddedAt ) ) - { - fData.mnFuncMask = nMask; - Insert( theArr, fData, nAddedAt ); - } - } - } + // drop target invalid (outside field windows): remove tracked field + if( !bCancelled ) + mpTrackingWindow->RemoveSelectedField(); + // focus source window (or another window, if it is empty now) + GrabFieldFocus( *mpTrackingWindow ); } + eTargetPointer = POINTER_ARROW; + if( mpTrackingWindow != mpDropWindow ) + mpTrackingWindow->NotifyEndTracking( ENDTRACKING_CANCEL ); + mpTrackingWindow = mpDropWindow = 0; } + SetPointer( eTargetPointer ); } -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::RemoveField( ScDPFieldType eFromType, size_t nIndex ) +void ScPivotLayoutDlg::SetReference( const ScRange& rRef, ScDocument* pDocP ) { - ScDPFuncDataVec* pArr = NULL; - switch( eFromType ) + if( !mbRefInputMode || !mpActiveEdit ) + return; + + if( rRef.aStart != rRef.aEnd ) + RefInputStart( mpActiveEdit ); + + if( mpActiveEdit == &maEdInPos ) { - case TYPE_PAGE: pArr = &aPageArr; break; - case TYPE_COL: pArr = &aColArr; break; - case TYPE_ROW: pArr = &aRowArr; break; - case TYPE_DATA: pArr = &aDataArr; break; - default: - { - // added to avoid warnings - } + String aRefStr; + rRef.Format( aRefStr, SCR_ABS_3D, pDocP, pDocP->GetAddressConvention() ); + mpActiveEdit->SetRefString( aRefStr ); } - - if( pArr ) + else if( mpActiveEdit == &maEdOutPos ) { - ScDPFieldWindow& rWnd = GetFieldWindow( eFromType ); - rWnd.DelField( nIndex ); - Remove( pArr, nIndex ); - if( rWnd.IsEmpty() ) InitFocus(); + String aRefStr; + rRef.aStart.Format( aRefStr, STD_FORMAT, pDocP, pDocP->GetAddressConvention() ); + mpActiveEdit->SetRefString( aRefStr ); } } -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::NotifyMouseButtonUp( const Point& rAt ) +sal_Bool ScPivotLayoutDlg::IsRefInputMode() const { - if ( bIsDrag ) - { - bIsDrag = FALSE; - - ScDPFieldType eDnDToType = TYPE_SELECT; - Point aPos = ScreenToOutputPixel( rAt ); - BOOL bDel = FALSE; - - if ( aRectPage.IsInside( aPos ) ) - { - eDnDToType = TYPE_PAGE; - bDel = FALSE; - } - else if ( aRectCol.IsInside( aPos ) ) - { - eDnDToType = TYPE_COL; - bDel = FALSE; - } - else if ( aRectRow.IsInside( aPos ) ) - { - eDnDToType = TYPE_ROW; - bDel = FALSE; - } - else if ( aRectData.IsInside( aPos ) ) - { - eDnDToType = TYPE_DATA; - bDel = FALSE; - } - else if ( aRectSelect.IsInside( aPos ) ) - { - eDnDToType = TYPE_SELECT; - bDel = TRUE; - } - else - bDel = TRUE; - - if ( bDel ) - RemoveField( eDnDFromType, nDnDFromIndex ); - else - MoveField( eDnDFromType, nDnDFromIndex, eDnDToType, aPos ); - } + return mbRefInputMode; } - -//---------------------------------------------------------------------------- - -PointerStyle ScDPLayoutDlg::NotifyMouseMove( const Point& rAt ) +void ScPivotLayoutDlg::SetActive() { - PointerStyle ePtr = POINTER_ARROW; - - if ( bIsDrag ) + if( mbRefInputMode ) { - Point aPos = ScreenToOutputPixel( rAt ); - ScDPFieldType eCheckTarget = TYPE_SELECT; - - if ( aRectPage.IsInside( aPos ) ) - eCheckTarget = TYPE_PAGE; - else if ( aRectCol.IsInside( aPos ) ) - eCheckTarget = TYPE_COL; - else if ( aRectRow.IsInside( aPos ) ) - eCheckTarget = TYPE_ROW; - else if ( aRectData.IsInside( aPos ) ) - eCheckTarget = TYPE_DATA; - else if ( eDnDFromType != TYPE_SELECT ) - ePtr = POINTER_PIVOT_DELETE; - else if ( aRectSelect.IsInside( aPos ) ) - ePtr = lclGetPointerForField( TYPE_SELECT ); - else - ePtr = POINTER_NOTALLOWED; + if( mpActiveEdit ) + mpActiveEdit->GrabFocus(); - if ( eCheckTarget != TYPE_SELECT ) - { - // check if the target orientation is allowed for this field - ScDPFuncDataVec* fromArr = NULL; - switch ( eDnDFromType ) - { - case TYPE_PAGE: fromArr = &aPageArr; break; - case TYPE_COL: fromArr = &aColArr; break; - case TYPE_ROW: fromArr = &aRowArr; break; - case TYPE_DATA: fromArr = &aDataArr; break; - case TYPE_SELECT: fromArr = &aSelectArr; break; - } - ScDPFuncData fData( *((*fromArr)[nDnDFromIndex]) ); - if (IsOrientationAllowed( fData.mnCol, eCheckTarget )) - ePtr = lclGetPointerForField( eCheckTarget ); - else - ePtr = POINTER_NOTALLOWED; - } + if( mpActiveEdit == &maEdInPos ) + EdInModifyHdl( 0 ); + else if( mpActiveEdit == &maEdOutPos ) + EdOutModifyHdl( 0 ); + } + else + { + GrabFocus(); } - return ePtr; + RefInputDone(); } - -//---------------------------------------------------------------------------- - -PointerStyle ScDPLayoutDlg::NotifyMouseButtonDown( ScDPFieldType eType, size_t nFieldIndex ) +sal_Bool ScPivotLayoutDlg::Close() { - bIsDrag = TRUE; - eDnDFromType = eType; - nDnDFromIndex = nFieldIndex; - return lclGetPointerForField( eType ); + return DoClose( ScPivotLayoutWrapper::GetChildWindowId() ); } +// private -------------------------------------------------------------------- -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::NotifyDoubleClick( ScDPFieldType eType, size_t nFieldIndex ) +ScPivotFieldWindow& ScPivotLayoutDlg::GetFieldWindow( ScPivotFieldType eFieldType ) { - ScDPFuncDataVec* pArr = NULL; - switch ( eType ) + switch( eFieldType ) { - case TYPE_PAGE: pArr = &aPageArr; break; - case TYPE_COL: pArr = &aColArr; break; - case TYPE_ROW: pArr = &aRowArr; break; - case TYPE_DATA: pArr = &aDataArr; break; - default: - { - // added to avoid warnings - } + case PIVOTFIELDTYPE_PAGE: return maWndPage; + case PIVOTFIELDTYPE_ROW: return maWndRow; + case PIVOTFIELDTYPE_COL: return maWndCol; + case PIVOTFIELDTYPE_DATA: return maWndData; + default:; } + return maWndSelect; +} - if ( pArr ) +bool ScPivotLayoutDlg::IsInsertAllowed( const ScPivotFieldWindow& rSourceWindow, const ScPivotFieldWindow& rTargetWindow ) +{ + if( rTargetWindow.GetType() != PIVOTFIELDTYPE_SELECT ) { - if ( nFieldIndex >= pArr->size() ) - { - DBG_ERROR("invalid selection"); - return; - } - - size_t nArrPos = 0; - if( ScDPLabelData* pData = GetLabelData( (*pArr)[nFieldIndex]->mnCol, &nArrPos ) ) + const ScPivotFuncData* pSourceData = rSourceWindow.GetSelectedFuncData(); + ScDPLabelData* pLabelData = pSourceData ? GetLabelData( pSourceData->mnCol ) : 0; + DBG_ASSERT( pLabelData, "ScPivotLayoutDlg::IsInsertAllowed - label data not found" ); + if( pLabelData ) { - ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); - DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 - - switch ( eType ) + sheet::DataPilotFieldOrientation eOrient = sheet::DataPilotFieldOrientation_HIDDEN; + switch( rTargetWindow.GetType() ) { - case TYPE_PAGE: - case TYPE_COL: - case TYPE_ROW: - { - // list of names of all data fields - std::vector< String > aDataFieldNames; - for( ScDPFuncDataVec::const_iterator aIt = aDataArr.begin(), aEnd = aDataArr.end(); - (aIt != aEnd) && aIt->get(); ++aIt ) - { - String aName( GetLabelString( (*aIt)->mnCol ) ); - if( aName.Len() ) - aDataFieldNames.push_back( aName ); - } - - bool bLayout = (eType == TYPE_ROW) && - ((aDataFieldNames.size() > 1) || ((nFieldIndex + 1 < pArr->size()) && (*pArr)[nFieldIndex+1].get())); - - AbstractScDPSubtotalDlg* pDlg = pFact->CreateScDPSubtotalDlg( - this, RID_SCDLG_PIVOTSUBT, - *xDlgDPObject, *pData, *(*pArr)[nFieldIndex], aDataFieldNames, bLayout ); - - if ( pDlg->Execute() == RET_OK ) - { - pDlg->FillLabelData( *pData ); - (*pArr)[nFieldIndex]->mnFuncMask = pData->mnFuncMask; - } - delete pDlg; - } - break; - - case TYPE_DATA: - { - AbstractScDPFunctionDlg* pDlg = pFact->CreateScDPFunctionDlg( - this, RID_SCDLG_DPDATAFIELD, - aLabelDataArr, *pData, *(*pArr)[nFieldIndex] ); - - if ( pDlg->Execute() == RET_OK ) - { - (*pArr)[nFieldIndex]->mnFuncMask = pData->mnFuncMask = pDlg->GetFuncMask(); - (*pArr)[nFieldIndex]->maFieldRef = pDlg->GetFieldRef(); - - String aStr( GetFuncString ( aDataArr[nFieldIndex]->mnFuncMask ) ); - aStr += GetLabelString( aDataArr[nFieldIndex]->mnCol ); - aWndData.SetFieldText( aStr, nFieldIndex ); - } - delete pDlg; - } - break; - - default: - { - // added to avoid warnings - } + case PIVOTFIELDTYPE_PAGE: eOrient = sheet::DataPilotFieldOrientation_PAGE; break; + case PIVOTFIELDTYPE_COL: eOrient = sheet::DataPilotFieldOrientation_COLUMN; break; + case PIVOTFIELDTYPE_ROW: eOrient = sheet::DataPilotFieldOrientation_ROW; break; + case PIVOTFIELDTYPE_DATA: eOrient = sheet::DataPilotFieldOrientation_DATA; break; + default: return false; } + return ScDPObject::IsOrientationAllowed( static_cast< sal_uInt16 >( eOrient ), pLabelData->mnFlags ); } } + return false; } -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::NotifyFieldFocus( ScDPFieldType eType, BOOL bGotFocus ) +void ScPivotLayoutDlg::InitFieldWindows() { - /* Enable Remove/Options buttons on GetFocus in field window. - #107616# Enable them also, if dialog is deactivated (click into document). - The !IsActive() condition handles the case that a LoseFocus event of a - field window would follow the Deactivate event of this dialog. */ - BOOL bEnable = (bGotFocus || !IsActive()) && (eType != TYPE_SELECT); - - // #128113# The TestTool may set the focus into an empty field. - // Then the Remove/Options buttons must be disabled. - if ( bEnable && bGotFocus && GetFieldWindow( eType ).IsEmpty() ) - bEnable = FALSE; - - aBtnRemove.Enable( bEnable ); - aBtnOptions.Enable( bEnable ); - if( bGotFocus ) - eLastActiveType = eType; + maLabelData = maPivotData.maLabelArray; + maWndSelect.ReadDataLabels( maLabelData ); + maWndPage.ReadPivotFields( maPivotData.maPageArr ); + maWndCol.ReadPivotFields( maPivotData.maColArr ); + maWndRow.ReadPivotFields( maPivotData.maRowArr ); + maWndData.ReadPivotFields( maPivotData.maDataArr ); } -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::NotifyMoveField( ScDPFieldType eToType ) +void ScPivotLayoutDlg::GrabFieldFocus( ScPivotFieldWindow& rFieldWindow ) { - ScDPFieldWindow& rWnd = GetFieldWindow( eLastActiveType ); - if( (eToType != TYPE_SELECT) && !rWnd.IsEmpty() ) + if( rFieldWindow.IsEmpty() ) { - MoveField( eLastActiveType, rWnd.GetSelectedField(), eToType, GetFieldWindow( eToType ).GetLastPosition() ); - if( rWnd.IsEmpty() ) - NotifyFieldFocus( eToType, TRUE ); + if( maWndSelect.IsEmpty() ) + maBtnOk.GrabFocus(); else - rWnd.GrabFocus(); - if( eLastActiveType == TYPE_SELECT ) - aWndSelect.SelectNext(); + maWndSelect.GrabFocus(); } else - InitFocus(); -} - -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::NotifyRemoveField( ScDPFieldType eType, size_t nFieldIndex ) -{ - if( eType != TYPE_SELECT ) - RemoveField( eType, nFieldIndex ); + rFieldWindow.GrabFocus(); } -//---------------------------------------------------------------------------- +namespace { -BOOL ScDPLayoutDlg::NotifyMoveSlider( USHORT nKeyCode ) +void lclFindFieldWindow( ScPivotFieldWindow*& rpFieldWindow, const ScPivotFuncData*& rpFuncData, size_t& rnFieldIndex, ScPivotFieldWindow& rFieldWindow ) { - long nOldPos = aSlider.GetThumbPos(); - switch( nKeyCode ) + ScPivotFuncDataEntry aEntry = rFieldWindow.FindFuncDataByCol( rpFuncData->mnCol ); + if( aEntry.first ) { - case KEY_HOME: aSlider.DoScroll( 0 ); break; - case KEY_END: aSlider.DoScroll( aSlider.GetRangeMax() ); break; - case KEY_UP: - case KEY_LEFT: aSlider.DoScrollAction( SCROLL_LINEUP ); break; - case KEY_DOWN: - case KEY_RIGHT: aSlider.DoScrollAction( SCROLL_LINEDOWN ); break; + rpFieldWindow = &rFieldWindow; + rpFuncData = aEntry.first; + rnFieldIndex = aEntry.second; } - return nOldPos != aSlider.GetThumbPos(); -} - -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::Deactivate() -{ - /* #107616# If the dialog has been deactivated (click into document), the LoseFocus - event from field window disables Remove/Options buttons. Re-enable them here by - simulating a GetFocus event. Event order of LoseFocus and Deactivate is not important. - The last event will enable the buttons in both cases (see NotifyFieldFocus). */ - NotifyFieldFocus( eLastActiveType, TRUE ); } -//---------------------------------------------------------------------------- +} // namespace -BOOL ScDPLayoutDlg::Contains( ScDPFuncDataVec* pArr, SCsCOL nCol, size_t& nAt ) +bool ScPivotLayoutDlg::MoveField( ScPivotFieldWindow& rSourceWindow, ScPivotFieldWindow& rTargetWindow, size_t nInsertIndex, bool bMoveExisting ) { - if ( !pArr ) - return FALSE; - - BOOL bFound = FALSE; - size_t i = 0; + // move inside the same window + if( &rSourceWindow == &rTargetWindow ) + return bMoveExisting && rTargetWindow.MoveSelectedField( nInsertIndex ); - while ( (i<pArr->size()) && ((*pArr)[i].get() != NULL) && !bFound ) + // do not insert if not supported by target window + if( !IsInsertAllowed( rSourceWindow, rTargetWindow ) ) { - bFound = ((*pArr)[i]->mnCol == nCol); - if ( bFound ) - nAt = i; - i++; + rSourceWindow.RemoveSelectedField(); + return false; } - return bFound; -} - - -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::Remove( ScDPFuncDataVec* pArr, size_t nAt ) -{ - if ( !pArr || (nAt>=pArr->size()) ) - return; - - pArr->erase( pArr->begin() + nAt ); - pArr->push_back( ScDPFuncDataRef() ); -} - - -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::Insert( ScDPFuncDataVec* pArr, const ScDPFuncData& rFData, size_t nAt ) -{ - if ( !pArr || (nAt>=pArr->size()) ) - return; - - if ( (*pArr)[nAt].get() == NULL ) + // move from one window to another window + if( const ScPivotFuncData* pSourceData = rSourceWindow.GetSelectedFuncData() ) { - (*pArr)[nAt].reset( new ScDPFuncData( rFData ) ); - } - else - { - if ( pArr->back().get() == NULL ) // mind. ein Slot frei? + // move to page/col/row window: try to find existing field in another window + ScPivotFieldWindow* pSourceWindow = &rSourceWindow; + size_t nSourceIndex = rSourceWindow.GetSelectedIndex(); + if( rTargetWindow.GetType() != PIVOTFIELDTYPE_DATA ) { - pArr->insert( pArr->begin() + nAt, ScDPFuncDataRef( new ScDPFuncData( rFData ) ) ); - pArr->erase( pArr->end() - 1 ); + lclFindFieldWindow( pSourceWindow, pSourceData, nSourceIndex, maWndPage ); + lclFindFieldWindow( pSourceWindow, pSourceData, nSourceIndex, maWndCol ); + lclFindFieldWindow( pSourceWindow, pSourceData, nSourceIndex, maWndRow ); } - } -} + // found in target window: move to new position + if( pSourceWindow == &rTargetWindow ) + return bMoveExisting && pSourceWindow->MoveField( nSourceIndex, nInsertIndex ); -//---------------------------------------------------------------------------- + // insert field into target window + rTargetWindow.InsertField( nInsertIndex, *pSourceData ); + // remove field from source window + pSourceWindow->RemoveField( nSourceIndex ); + // remove field from data window, if it is the original source + if( (rSourceWindow.GetType() == PIVOTFIELDTYPE_DATA) && (pSourceWindow->GetType() != PIVOTFIELDTYPE_DATA) ) + rSourceWindow.RemoveSelectedField(); -ScDPLabelData* ScDPLayoutDlg::GetLabelData( SCsCOL nCol, size_t* pnPos ) -{ - ScDPLabelData* pData = 0; - for( ScDPLabelDataVec::iterator aIt = aLabelDataArr.begin(), aEnd = aLabelDataArr.end(); !pData && (aIt != aEnd); ++aIt ) - { - if( aIt->mnCol == nCol ) - { - pData = &*aIt; - if( pnPos ) *pnPos = aIt - aLabelDataArr.begin(); - } + return true; } - return pData; -} - -//---------------------------------------------------------------------------- - -String ScDPLayoutDlg::GetLabelString( SCsCOL nCol ) -{ - ScDPLabelData* pData = GetLabelData( nCol ); - DBG_ASSERT( pData, "LabelData not found" ); - if (pData) - return pData->getDisplayName(); - return String(); + return false; } -//---------------------------------------------------------------------------- +// handlers ------------------------------------------------------------------- -bool ScDPLayoutDlg::IsOrientationAllowed( SCsCOL nCol, ScDPFieldType eType ) +IMPL_LINK( ScPivotLayoutDlg, ClickHdl, PushButton *, pBtn ) { - bool bAllowed = true; - ScDPLabelData* pData = GetLabelData( nCol ); - DBG_ASSERT( pData, "LabelData not found" ); - if (pData) + if( mpFocusWindow ) { - sheet::DataPilotFieldOrientation eOrient = sheet::DataPilotFieldOrientation_HIDDEN; - switch (eType) - { - case TYPE_PAGE: eOrient = sheet::DataPilotFieldOrientation_PAGE; break; - case TYPE_COL: eOrient = sheet::DataPilotFieldOrientation_COLUMN; break; - case TYPE_ROW: eOrient = sheet::DataPilotFieldOrientation_ROW; break; - case TYPE_DATA: eOrient = sheet::DataPilotFieldOrientation_DATA; break; - case TYPE_SELECT: eOrient = sheet::DataPilotFieldOrientation_HIDDEN; break; - } - bAllowed = ScDPObject::IsOrientationAllowed( (USHORT)eOrient, pData->mnFlags ); - } - return bAllowed; -} + /* Raising sub dialogs (from the NotifyDoubleClick function) triggers + VCL child window focus events from this sub dialog which may + invalidate the member mpFocusWindow pointing to the target field + window. This would cause a crash with the following call to the + GrabFieldFocus function, if mpFocusWindow is used directly. */ + ScPivotFieldWindow& rTargetWindow = *mpFocusWindow; -//---------------------------------------------------------------------------- - -String ScDPLayoutDlg::GetFuncString( USHORT& rFuncMask, BOOL bIsValue ) -{ - String aStr; - - if ( rFuncMask == PIVOT_FUNC_NONE - || rFuncMask == PIVOT_FUNC_AUTO ) - { - if ( bIsValue ) + if( pBtn == &maBtnRemove ) { - aStr = FSTR(PIVOTSTR_SUM); - rFuncMask = PIVOT_FUNC_SUM; + rTargetWindow.RemoveSelectedField(); + // focus back to field window + GrabFieldFocus( rTargetWindow ); } - else + else if( pBtn == &maBtnOptions ) { - aStr = FSTR(PIVOTSTR_COUNT); - rFuncMask = PIVOT_FUNC_COUNT; + NotifyDoubleClick( rTargetWindow ); + // focus back to field window + GrabFieldFocus( rTargetWindow ); } } - else if ( rFuncMask == PIVOT_FUNC_SUM ) aStr = FSTR(PIVOTSTR_SUM); - else if ( rFuncMask == PIVOT_FUNC_COUNT ) aStr = FSTR(PIVOTSTR_COUNT); - else if ( rFuncMask == PIVOT_FUNC_AVERAGE ) aStr = FSTR(PIVOTSTR_AVG); - else if ( rFuncMask == PIVOT_FUNC_MAX ) aStr = FSTR(PIVOTSTR_MAX); - else if ( rFuncMask == PIVOT_FUNC_MIN ) aStr = FSTR(PIVOTSTR_MIN); - else if ( rFuncMask == PIVOT_FUNC_PRODUCT ) aStr = FSTR(PIVOTSTR_PROD); - else if ( rFuncMask == PIVOT_FUNC_COUNT_NUM ) aStr = FSTR(PIVOTSTR_COUNT2); - else if ( rFuncMask == PIVOT_FUNC_STD_DEV ) aStr = FSTR(PIVOTSTR_DEV); - else if ( rFuncMask == PIVOT_FUNC_STD_DEVP ) aStr = FSTR(PIVOTSTR_DEV2); - else if ( rFuncMask == PIVOT_FUNC_STD_VAR ) aStr = FSTR(PIVOTSTR_VAR); - else if ( rFuncMask == PIVOT_FUNC_STD_VARP ) aStr = FSTR(PIVOTSTR_VAR2); - else - { - aStr = ScGlobal::GetRscString( STR_TABLE_ERGEBNIS ); - aStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " - " )); - } - - return aStr; -} - - -//---------------------------------------------------------------------------- - -Point ScDPLayoutDlg::DlgPos2WndPos( const Point& rPt, Window& rWnd ) -{ - Point aWndPt( rPt ); - aWndPt.X() = rPt.X()-rWnd.GetPosPixel().X(); - aWndPt.Y() = rPt.Y()-rWnd.GetPosPixel().Y(); - - return aWndPt; -} - - -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::CalcWndSizes() -{ - // row/column/data area sizes - aWndPage.SetSizePixel( Size( MAX_PAGEFIELDS * OWIDTH / 2, 2 * OHEIGHT ) ); - aWndRow.SetSizePixel( Size( OWIDTH, MAX_FIELDS * OHEIGHT ) ); - aWndCol.SetSizePixel( Size( MAX_FIELDS * OWIDTH / 2, 2 * OHEIGHT ) ); - aWndData.SetSizePixel( Size( MAX_FIELDS * OWIDTH / 2, MAX_FIELDS * OHEIGHT ) ); - - // #i29203# align right border of page window with data window - long nDataPosX = aWndData.GetPosPixel().X() + aWndData.GetSizePixel().Width(); - aWndPage.SetPosPixel( Point( nDataPosX - aWndPage.GetSizePixel().Width(), aWndPage.GetPosPixel().Y() ) ); - - // selection area - aWndSelect.SetSizePixel( Size( - 2 * OWIDTH + SSPACE, LINE_SIZE * OHEIGHT + (LINE_SIZE - 1) * SSPACE ) ); - - // scroll bar - Point aSliderPos( aWndSelect.GetPosPixel() ); - Size aSliderSize( aWndSelect.GetSizePixel() ); - aSliderPos.Y() += aSliderSize.Height() + SSPACE; - aSliderSize.Height() = GetSettings().GetStyleSettings().GetScrollBarSize(); - aSlider.SetPosSizePixel( aSliderPos, aSliderSize ); - - aRectPage = Rectangle( aWndPage.GetPosPixel(), aWndPage.GetSizePixel() ); - aRectRow = Rectangle( aWndRow.GetPosPixel(), aWndRow.GetSizePixel() ); - aRectCol = Rectangle( aWndCol.GetPosPixel(), aWndCol.GetSizePixel() ); - aRectData = Rectangle( aWndData.GetPosPixel(), aWndData.GetSizePixel() ); - aRectSelect = Rectangle( aWndSelect.GetPosPixel(), aWndSelect.GetSizePixel() ); -} - - -//---------------------------------------------------------------------------- - -BOOL ScDPLayoutDlg::GetPivotArrays( PivotField* pPageArr, - PivotField* pColArr, - PivotField* pRowArr, - PivotField* pDataArr, - USHORT& rPageCount, - USHORT& rColCount, - USHORT& rRowCount, - USHORT& rDataCount ) -{ - BOOL bFit = TRUE; - USHORT i=0; - - for ( i=0; (i<aDataArr.size()) && (aDataArr[i].get() != NULL ); i++ ) - lcl_FillToPivotField( pDataArr[i], *aDataArr[i] ); - rDataCount = i; - - for ( i=0; (i<aPageArr.size()) && (aPageArr[i].get() != NULL ); i++ ) - lcl_FillToPivotField( pPageArr[i], *aPageArr[i] ); - rPageCount = i; - - for ( i=0; (i<aColArr.size()) && (aColArr[i].get() != NULL ); i++ ) - lcl_FillToPivotField( pColArr[i], *aColArr[i] ); - rColCount = i; - - for ( i=0; (i<aRowArr.size()) && (aRowArr[i].get() != NULL ); i++ ) - lcl_FillToPivotField( pRowArr[i], *aRowArr[i] ); - rRowCount = i; - - if ( rRowCount < aRowArr.size() ) - pRowArr[rRowCount++].nCol = PIVOT_DATA_FIELD; - else if ( rColCount < aColArr.size() ) - pColArr[rColCount++].nCol = PIVOT_DATA_FIELD; - else - bFit = FALSE; // kein Platz fuer Datenfeld - - return bFit; -} - -void ScDPLayoutDlg::UpdateSrcRange() -{ - String theCurPosStr = aEdInPos.GetText(); - USHORT nResult = ScRange().Parse(theCurPosStr, pDoc, pDoc->GetAddressConvention()); - - if ( SCA_VALID != (nResult & SCA_VALID) ) - // invalid source range. - return; - - ScRefAddress start, end; - ConvertDoubleRef(pDoc, theCurPosStr, 1, start, end, pDoc->GetAddressConvention()); - ScRange aNewRange(start.GetAddress(), end.GetAddress()); - ScSheetSourceDesc inSheet = *xDlgDPObject->GetSheetDesc(); - - if (inSheet.aSourceRange == aNewRange) - // new range is identical to the current range. Nothing to do. - return; - - ScTabViewShell * pTabViewShell = pViewData->GetViewShell(); - inSheet.aSourceRange = aNewRange; - xDlgDPObject->SetSheetDesc(inSheet); - xDlgDPObject->FillOldParam( thePivotData, FALSE ); - xDlgDPObject->FillLabelData(thePivotData); - - pTabViewShell->SetDialogDPObject(xDlgDPObject.get()); - aLabelDataArr.clear(); - aWndSelect.ClearFields(); - aWndData.ClearFields(); - aWndRow.ClearFields(); - aWndCol.ClearFields(); - aWndPage.ClearFields(); - - for (size_t i = 0; i < MAX_LABELS; ++i) - aSelectArr[i].reset(); - - for (size_t i = 0; i < MAX_FIELDS; ++i) - { - aRowArr[i].reset(); - aColArr[i].reset(); - aDataArr[i].reset(); - } - - for (size_t i = 0; i < MAX_PAGEFIELDS; ++i) - aPageArr[i].reset(); - - InitFields(); + return 0; } -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::SetReference( const ScRange& rRef, ScDocument* pDocP ) +IMPL_LINK( ScPivotLayoutDlg, OkHdl, OKButton *, EMPTYARG ) { - if ( !bRefInputMode || !pEditActive ) - return; - - if ( rRef.aStart != rRef.aEnd ) - RefInputStart( pEditActive ); - - if ( pEditActive == &aEdInPos ) - { - String aRefStr; - rRef.Format( aRefStr, SCR_ABS_3D, pDocP, pDocP->GetAddressConvention() ); - pEditActive->SetRefString( aRefStr ); - } - else if ( pEditActive == &aEdOutPos ) - { - String aRefStr; - rRef.aStart.Format( aRefStr, STD_FORMAT, pDocP, pDocP->GetAddressConvention() ); - pEditActive->SetRefString( aRefStr ); - } -} - + String aOutPosStr = maEdOutPos.GetText(); + ScAddress aAdrDest; + bool bToNewTable = maLbOutPos.GetSelectEntryPos() == 1; + sal_uInt16 nResult = !bToNewTable ? aAdrDest.Parse( aOutPosStr, mpDoc, mpDoc->GetAddressConvention() ) : 0; -//---------------------------------------------------------------------------- - -void ScDPLayoutDlg::SetActive() -{ - if ( bRefInputMode ) + if( bToNewTable || ((aOutPosStr.Len() > 0) && ((nResult & SCA_VALID) == SCA_VALID)) ) { - if ( pEditActive ) - pEditActive->GrabFocus(); + ScPivotFieldVector aPageFields, aColFields, aRowFields, aDataFields; + maWndPage.WritePivotFields( aPageFields ); + maWndCol.WritePivotFields( aColFields ); + maWndRow.WritePivotFields( aRowFields ); + maWndData.WritePivotFields( aDataFields ); - if ( pEditActive == &aEdInPos ) - EdInModifyHdl( NULL ); - else if ( pEditActive == &aEdOutPos ) - EdModifyHdl( NULL ); - } - else - { - GrabFocus(); - } + // TODO: handle data field in dialog field windows? + aRowFields.resize( aRowFields.size() + 1 ); + aRowFields.back().nCol = PIVOT_DATA_FIELD; - RefInputDone(); -} + ScDPSaveData* pOldSaveData = mxDlgDPObject->GetSaveData(); -//---------------------------------------------------------------------------- -// Handler: -//---------------------------------------------------------------------------- + ScRange aOutRange( aAdrDest ); // bToNewTable is passed separately -IMPL_LINK( ScDPLayoutDlg, ClickHdl, PushButton *, pBtn ) -{ - if( pBtn == &aBtnRemove ) - { - ScDPFieldWindow& rWnd = GetFieldWindow( eLastActiveType ); - RemoveField( eLastActiveType, rWnd.GetSelectedField() ); - if( !rWnd.IsEmpty() ) rWnd.GrabFocus(); - } - else if( pBtn == &aBtnOptions ) - { - ScDPFieldWindow& rWnd = GetFieldWindow( eLastActiveType ); - NotifyDoubleClick( eLastActiveType, rWnd.GetSelectedField() ); - rWnd.GrabFocus(); - } - return 0; -} + ScDPSaveData aSaveData; + aSaveData.SetIgnoreEmptyRows( maBtnIgnEmptyRows.IsChecked() ); + aSaveData.SetRepeatIfEmpty( maBtnDetectCat.IsChecked() ); + aSaveData.SetColumnGrand( maBtnTotalCol.IsChecked() ); + aSaveData.SetRowGrand( maBtnTotalRow.IsChecked() ); + aSaveData.SetFilterButton( maBtnFilter.IsChecked() ); + aSaveData.SetDrillDown( maBtnDrillDown.IsChecked() ); -//---------------------------------------------------------------------------- + uno::Reference< sheet::XDimensionsSupplier > xSource = mxDlgDPObject->GetSource(); -IMPL_LINK( ScDPLayoutDlg, OkHdl, OKButton *, EMPTYARG ) -{ - String aOutPosStr( aEdOutPos.GetText() ); - ScAddress aAdrDest; - BOOL bToNewTable = (aLbOutPos.GetSelectEntryPos() == 1); - USHORT nResult = !bToNewTable ? aAdrDest.Parse( aOutPosStr, pDoc, pDoc->GetAddressConvention() ) : 0; + ScDPObject::ConvertOrientation( aSaveData, aPageFields, sheet::DataPilotFieldOrientation_PAGE, 0, 0, 0, xSource, false ); + ScDPObject::ConvertOrientation( aSaveData, aColFields, sheet::DataPilotFieldOrientation_COLUMN, 0, 0, 0, xSource, false ); + ScDPObject::ConvertOrientation( aSaveData, aRowFields, sheet::DataPilotFieldOrientation_ROW, 0, 0, 0, xSource, false ); + ScDPObject::ConvertOrientation( aSaveData, aDataFields, sheet::DataPilotFieldOrientation_DATA, 0, 0, 0, xSource, false, &aColFields, &aRowFields, &aPageFields ); - if ( bToNewTable - || ( (aOutPosStr.Len() > 0) && (SCA_VALID == (nResult & SCA_VALID)) ) ) - { - //@BugID 54702 Enablen/Disablen nur noch in Basisklasse - //SFX_APPWINDOW->Enable(); - - ScPivotParam theOutParam; - PivotPageFieldArr aPageFieldArr; - PivotFieldArr aColFieldArr; - PivotFieldArr aRowFieldArr; - PivotFieldArr aDataFieldArr; - USHORT nPageCount; - USHORT nColCount; - USHORT nRowCount; - USHORT nDataCount; - - BOOL bFit = GetPivotArrays( aPageFieldArr, aColFieldArr, aRowFieldArr, aDataFieldArr, - nPageCount, nColCount, nRowCount, nDataCount ); - if ( bFit ) + for( ScDPLabelDataVector::const_iterator aIt = maLabelData.begin(), aEnd = maLabelData.end(); aIt != aEnd; ++aIt ) { - ScDPSaveData* pOldSaveData = xDlgDPObject->GetSaveData(); - - ScRange aOutRange( aAdrDest ); // bToNewTable is passed separately - - ScDPSaveData aSaveData; - aSaveData.SetIgnoreEmptyRows( aBtnIgnEmptyRows.IsChecked() ); - aSaveData.SetRepeatIfEmpty( aBtnDetectCat.IsChecked() ); - aSaveData.SetColumnGrand( aBtnTotalCol.IsChecked() ); - aSaveData.SetRowGrand( aBtnTotalRow.IsChecked() ); - aSaveData.SetFilterButton( aBtnFilter.IsChecked() ); - aSaveData.SetDrillDown( aBtnDrillDown.IsChecked() ); - - uno::Reference<sheet::XDimensionsSupplier> xSource = xDlgDPObject->GetSource(); - - ScDPObject::ConvertOrientation( aSaveData, aPageFieldArr, nPageCount, - sheet::DataPilotFieldOrientation_PAGE, NULL, 0, 0, xSource, FALSE ); - ScDPObject::ConvertOrientation( aSaveData, aColFieldArr, nColCount, - sheet::DataPilotFieldOrientation_COLUMN, NULL, 0, 0, xSource, FALSE ); - ScDPObject::ConvertOrientation( aSaveData, aRowFieldArr, nRowCount, - sheet::DataPilotFieldOrientation_ROW, NULL, 0, 0, xSource, FALSE ); - ScDPObject::ConvertOrientation( aSaveData, aDataFieldArr, nDataCount, - sheet::DataPilotFieldOrientation_DATA, NULL, 0, 0, xSource, FALSE, - aColFieldArr, nColCount, aRowFieldArr, nRowCount, aPageFieldArr, nPageCount ); - - for( ScDPLabelDataVec::const_iterator aIt = aLabelDataArr.begin(), aEnd = aLabelDataArr.end(); aIt != aEnd; ++aIt ) + if( ScDPSaveDimension* pDim = aSaveData.GetExistingDimensionByName( aIt->maName ) ) { - if( ScDPSaveDimension* pDim = aSaveData.GetExistingDimensionByName( aIt->maName ) ) + pDim->SetUsedHierarchy( aIt->mnUsedHier ); + pDim->SetShowEmpty( aIt->mbShowAll ); + pDim->SetSortInfo( &aIt->maSortInfo ); + pDim->SetLayoutInfo( &aIt->maLayoutInfo ); + pDim->SetAutoShowInfo( &aIt->maShowInfo ); + ScDPSaveDimension* pOldDim = NULL; + if (pOldSaveData) { - pDim->SetUsedHierarchy( aIt->mnUsedHier ); - pDim->SetShowEmpty( aIt->mbShowAll ); - pDim->SetSortInfo( &aIt->maSortInfo ); - pDim->SetLayoutInfo( &aIt->maLayoutInfo ); - pDim->SetAutoShowInfo( &aIt->maShowInfo ); - ScDPSaveDimension* pOldDim = NULL; - if (pOldSaveData) + // Transfer the existing layout names to new dimension instance. + pOldDim = pOldSaveData->GetExistingDimensionByName(aIt->maName); + if (pOldDim) { - // Transfer the existing layout names to new dimension instance. - pOldDim = pOldSaveData->GetExistingDimensionByName(aIt->maName); - if (pOldDim) - { - const OUString* pLayoutName = pOldDim->GetLayoutName(); - if (pLayoutName) - pDim->SetLayoutName(*pLayoutName); + const OUString* pLayoutName = pOldDim->GetLayoutName(); + if (pLayoutName) + pDim->SetLayoutName(*pLayoutName); - const OUString* pSubtotalName = pOldDim->GetSubtotalName(); - if (pSubtotalName) - pDim->SetSubtotalName(*pSubtotalName); - } + const OUString* pSubtotalName = pOldDim->GetSubtotalName(); + if (pSubtotalName) + pDim->SetSubtotalName(*pSubtotalName); } + } - bool bManualSort = ( aIt->maSortInfo.Mode == sheet::DataPilotFieldSortMode::MANUAL ); + bool bManualSort = ( aIt->maSortInfo.Mode == sheet::DataPilotFieldSortMode::MANUAL ); - // visibility of members - for (vector<ScDPLabelData::Member>::const_iterator itr = aIt->maMembers.begin(), itrEnd = aIt->maMembers.end(); - itr != itrEnd; ++itr) - { - ScDPSaveMember* pMember = pDim->GetMemberByName(itr->maName); + // visibility of members + for (::std::vector<ScDPLabelData::Member>::const_iterator itr = aIt->maMembers.begin(), itrEnd = aIt->maMembers.end(); + itr != itrEnd; ++itr) + { + ScDPSaveMember* pMember = pDim->GetMemberByName(itr->maName); - // #i40054# create/access members only if flags are not default - // (or in manual sorting mode - to keep the order) - if (bManualSort || !itr->mbVisible || !itr->mbShowDetails) - { - pMember->SetIsVisible(itr->mbVisible); - pMember->SetShowDetails(itr->mbShowDetails); - } - if (pOldDim) + // #i40054# create/access members only if flags are not default + // (or in manual sorting mode - to keep the order) + if (bManualSort || !itr->mbVisible || !itr->mbShowDetails) + { + pMember->SetIsVisible(itr->mbVisible); + pMember->SetShowDetails(itr->mbShowDetails); + } + if (pOldDim) + { + // Transfer the existing layout name. + ScDPSaveMember* pOldMember = pOldDim->GetMemberByName(itr->maName); + if (pOldMember) { - // Transfer the existing layout name. - ScDPSaveMember* pOldMember = pOldDim->GetMemberByName(itr->maName); - if (pOldMember) - { - const OUString* pLayoutName = pOldMember->GetLayoutName(); - if (pLayoutName) - pMember->SetLayoutName(*pLayoutName); - } + const OUString* pLayoutName = pOldMember->GetLayoutName(); + if (pLayoutName) + pMember->SetLayoutName(*pLayoutName); } } } } - ScDPSaveDimension* pDim = aSaveData.GetDataLayoutDimension(); - if (pDim && pOldSaveData) + } + ScDPSaveDimension* pDim = aSaveData.GetDataLayoutDimension(); + if (pDim && pOldSaveData) + { + ScDPSaveDimension* pOldDim = pOldSaveData->GetDataLayoutDimension(); + if (pOldDim) { - ScDPSaveDimension* pOldDim = pOldSaveData->GetDataLayoutDimension(); - if (pOldDim) - { - const OUString* pLayoutName = pOldDim->GetLayoutName(); - if (pLayoutName) - pDim->SetLayoutName(*pLayoutName); - } + const OUString* pLayoutName = pOldDim->GetLayoutName(); + if (pLayoutName) + pDim->SetLayoutName(*pLayoutName); } + } - // also transfer grand total name - if (pOldSaveData) - { - const OUString* pGrandTotalName = pOldSaveData->GetGrandTotalName(); - if (pGrandTotalName) - aSaveData.SetGrandTotalName(*pGrandTotalName); - } + // also transfer grand total name + if (pOldSaveData) + { + const OUString* pGrandTotalName = pOldSaveData->GetGrandTotalName(); + if (pGrandTotalName) + aSaveData.SetGrandTotalName(*pGrandTotalName); + } - USHORT nWhichPivot = SC_MOD()->GetPool().GetWhich( SID_PIVOT_TABLE ); - ScPivotItem aOutItem( nWhichPivot, &aSaveData, &aOutRange, bToNewTable ); + sal_uInt16 nWhichPivot = SC_MOD()->GetPool().GetWhich( SID_PIVOT_TABLE ); + ScPivotItem aOutItem( nWhichPivot, &aSaveData, &aOutRange, bToNewTable ); - bRefInputMode = FALSE; // to allow deselecting when switching sheets + mbRefInputMode = false; // to allow deselecting when switching sheets - SetDispatcherLock( FALSE ); - SwitchToDocument(); + SetDispatcherLock( false ); + SwitchToDocument(); - // #95513# don't hide the dialog before executing the slot, instead it is used as - // parent for message boxes in ScTabViewShell::GetDialogParent + // #95513# don't hide the dialog before executing the slot, instead it is used as + // parent for message boxes in ScTabViewShell::GetDialogParent - const SfxPoolItem* pRet = GetBindings().GetDispatcher()->Execute( - SID_PIVOT_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aOutItem, 0L, 0L ); + const SfxPoolItem* pRet = GetBindings().GetDispatcher()->Execute( + SID_PIVOT_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aOutItem, 0L, 0L ); - bool bSuccess = true; - if (pRet) - { - const SfxBoolItem* pItem = dynamic_cast<const SfxBoolItem*>(pRet); - if (pItem) - bSuccess = pItem->GetValue(); - } - if (bSuccess) - // Table successfully inserted. - Close(); - else - { - // Table insertion failed. Keep the dialog open. - bRefInputMode = true; - SetDispatcherLock(true); - } + bool bSuccess = true; + if (pRet) + { + const SfxBoolItem* pItem = dynamic_cast<const SfxBoolItem*>(pRet); + if (pItem) + bSuccess = pItem->GetValue(); } + if (bSuccess) + // Table successfully inserted. + Close(); else { - ErrorBox( this, WinBits( WB_OK | WB_DEF_OK ), - ScGlobal::GetRscString( STR_PIVOT_ERROR ) - ).Execute(); + // Table insertion failed. Keep the dialog open. + mbRefInputMode = true; + SetDispatcherLock(true); } } else { - if ( !aBtnMore.GetState() ) - aBtnMore.SetState( TRUE ); + if( !maBtnMore.GetState() ) + maBtnMore.SetState( true ); - ErrorBox( this, WinBits( WB_OK | WB_DEF_OK ), - ScGlobal::GetRscString( STR_INVALID_TABREF ) - ).Execute(); - aEdOutPos.GrabFocus(); + ErrorBox( this, WinBits( WB_OK | WB_DEF_OK ), ScGlobal::GetRscString( STR_INVALID_TABREF ) ).Execute(); + maEdOutPos.GrabFocus(); } return 0; } - -//---------------------------------------------------------------------------- - -IMPL_LINK( ScDPLayoutDlg, CancelHdl, CancelButton *, EMPTYARG ) +IMPL_LINK( ScPivotLayoutDlg, CancelHdl, CancelButton *, EMPTYARG ) { Close(); return 0; } - -//---------------------------------------------------------------------------- - -IMPL_LINK( ScDPLayoutDlg, MoreClickHdl, MoreButton *, EMPTYARG ) +IMPL_LINK( ScPivotLayoutDlg, MoreClickHdl, MoreButton *, EMPTYARG ) { - if ( aBtnMore.GetState() ) + if ( maBtnMore.GetState() ) { - bRefInputMode = TRUE; - //@BugID 54702 Enablen/Disablen nur noch in Basisklasse - //SFX_APPWINDOW->Enable(); - if ( aEdInPos.IsEnabled() ) + mbRefInputMode = true; + if ( maEdInPos.IsEnabled() ) { - aEdInPos.Enable(); - aEdInPos.GrabFocus(); - aEdInPos.Enable(); + maEdInPos.Enable(); + maEdInPos.GrabFocus(); + maEdInPos.Enable(); } else { - aEdOutPos.Enable(); - aEdOutPos.GrabFocus(); - aEdOutPos.Enable(); + maEdOutPos.Enable(); + maEdOutPos.GrabFocus(); + maEdOutPos.Enable(); } } else { - bRefInputMode = FALSE; - //@BugID 54702 Enablen/Disablen nur noch in Basisklasse - //SFX_APPWINDOW->Disable(FALSE); //! allgemeine Methode im ScAnyRefDlg + mbRefInputMode = false; } return 0; } - -//---------------------------------------------------------------------------- - -IMPL_LINK( ScDPLayoutDlg, EdModifyHdl, Edit *, EMPTYARG ) +IMPL_LINK( ScPivotLayoutDlg, EdOutModifyHdl, Edit *, EMPTYARG ) { - String theCurPosStr = aEdOutPos.GetText(); - USHORT nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() ); + String theCurPosStr = maEdOutPos.GetText(); + sal_uInt16 nResult = ScAddress().Parse( theCurPosStr, mpDoc, mpDoc->GetAddressConvention() ); if ( SCA_VALID == (nResult & SCA_VALID) ) { - String* pStr = NULL; - BOOL bFound = FALSE; - USHORT i = 0; - USHORT nCount = aLbOutPos.GetEntryCount(); + String* pStr = 0; + bool bFound = false; + sal_uInt16 i = 0; + sal_uInt16 nCount = maLbOutPos.GetEntryCount(); for ( i=2; i<nCount && !bFound; i++ ) { - pStr = (String*)aLbOutPos.GetEntryData( i ); + pStr = (String*)maLbOutPos.GetEntryData( i ); bFound = (theCurPosStr == *pStr); } if ( bFound ) - aLbOutPos.SelectEntryPos( --i ); + maLbOutPos.SelectEntryPos( --i ); else - aLbOutPos.SelectEntryPos( 0 ); + maLbOutPos.SelectEntryPos( 0 ); } return 0; } -IMPL_LINK( ScDPLayoutDlg, EdInModifyHdl, Edit *, EMPTYARG ) +IMPL_LINK( ScPivotLayoutDlg, EdInModifyHdl, Edit *, EMPTYARG ) { - UpdateSrcRange(); - return 0; -} + String theCurPosStr = maEdInPos.GetText(); + sal_uInt16 nResult = ScRange().Parse( theCurPosStr, mpDoc, mpDoc->GetAddressConvention() ); + // invalid source range + if( SCA_VALID != (nResult & SCA_VALID) ) + return 0; -//---------------------------------------------------------------------------- + ScRefAddress start, end; + ConvertDoubleRef( mpDoc, theCurPosStr, 1, start, end, mpDoc->GetAddressConvention() ); + ScRange aNewRange( start.GetAddress(), end.GetAddress() ); + ScSheetSourceDesc inSheet = *mxDlgDPObject->GetSheetDesc(); -IMPL_LINK( ScDPLayoutDlg, SelAreaHdl, ListBox *, EMPTYARG ) -{ - String aString; - USHORT nSelPos = aLbOutPos.GetSelectEntryPos(); + // new range is identical to the current range + if( inSheet.aSourceRange == aNewRange ) + return 0; - if ( nSelPos > 1 ) - { - aString = *(String*)aLbOutPos.GetEntryData( nSelPos ); - } - else if ( nSelPos == aLbOutPos.GetEntryCount()-1 ) // auf neue Tabelle? + ScTabViewShell* pTabViewShell = mpViewData->GetViewShell(); + inSheet.aSourceRange = aNewRange; + mxDlgDPObject->SetSheetDesc( inSheet ); + mxDlgDPObject->FillOldParam( maPivotData ); + mxDlgDPObject->FillLabelData( maPivotData ); + + // SetDialogDPObject does not take ownership but makes a copy internally + pTabViewShell->SetDialogDPObject( mxDlgDPObject.get() ); + + // re-initialize the field windows from the new data + InitFieldWindows(); + + return 0; +} + +IMPL_LINK( ScPivotLayoutDlg, SelAreaHdl, ListBox *, EMPTYARG ) +{ + String aString; + sal_uInt16 nSelPos = maLbOutPos.GetSelectEntryPos(); + if( nSelPos > 1 ) { - aEdOutPos.Disable(); - aRbOutPos.Disable(); + aString = *(String*)maLbOutPos.GetEntryData( nSelPos ); } else { - aEdOutPos.Enable(); - aRbOutPos.Enable(); + // do not allow to specify output position, if target is "new sheet" + bool bNewSheet = nSelPos == 1; + maEdOutPos.Enable( !bNewSheet ); + maRbOutPos.Enable( !bNewSheet ); } - aEdOutPos.SetText( aString ); + maEdOutPos.SetText( aString ); return 0; } - -//---------------------------------------------------------------------------- - -IMPL_LINK( ScDPLayoutDlg, ScrollHdl, ScrollBar *, EMPTYARG ) +IMPL_LINK( ScPivotLayoutDlg, ChildEventListener, VclWindowEvent*, pEvent ) { - long nNewOffset = aSlider.GetThumbPos(); - long nOffsetDiff = nNewOffset - nOffset; - nOffset = nNewOffset; - - size_t nFields = std::min< size_t >( aLabelDataArr.size() - nOffset, PAGE_SIZE ); - - aWndSelect.ClearFields(); - - size_t i=0; - for ( i=0; i<nFields; i++ ) + Window* pWindow = pEvent->GetWindow(); + // check that this dialog is the parent of the window, to ignore focus events from sub dialogs + if( (pEvent->GetId() == VCLEVENT_WINDOW_GETFOCUS) && pWindow && (pWindow->GetParent() == this) ) { - const ScDPLabelData& rData = aLabelDataArr[nOffset+i]; - aWndSelect.AddField(rData.getDisplayName(), i); - aSelectArr[i].reset( new ScDPFuncData( rData.mnCol, rData.mnFuncMask ) ); - } - for ( ; i<aSelectArr.size(); i++ ) - aSelectArr[i].reset(); - - aWndSelect.ModifySelectionOffset( nOffsetDiff ); // adjusts selection & redraws - return 0; -} + // check if old window and/or new window are field windows + ScPivotFieldWindow* pSourceWindow = mpFocusWindow; + ScPivotFieldWindow* pTargetWindow = dynamic_cast< ScPivotFieldWindow* >( pWindow ); -//---------------------------------------------------------------------------- + /* Enable or disable the Remove/Options buttons. Do nothing if the + buttons themselves get the focus. + #128113# The TestTool may set the focus into an empty window. Then + the Remove/Options buttons must be disabled. */ + if( (pWindow != &maBtnRemove) && (pWindow != &maBtnOptions) ) + { + bool bEnableButtons = pTargetWindow && (pTargetWindow->GetType() != PIVOTFIELDTYPE_SELECT) && !pTargetWindow->IsEmpty(); + maBtnRemove.Enable( bEnableButtons ); + maBtnOptions.Enable( bEnableButtons ); + /* Remember the new focus window (will not be changed, if + Remove/Option buttons are getting focus, because they need to + know the field window they are working on). */ + mpFocusWindow = pTargetWindow; + } -IMPL_LINK( ScDPLayoutDlg, GetFocusHdl, Control*, pCtrl ) -{ - pEditActive = NULL; - if ( pCtrl == &aEdInPos ) - pEditActive = &aEdInPos; - else if ( pCtrl == &aEdOutPos ) - pEditActive = &aEdOutPos; + /* Move the last selected field to target window, if focus changes via + keyboard shortcut. */ + if( pSourceWindow && pTargetWindow && (pSourceWindow != pTargetWindow) && ((pTargetWindow->GetGetFocusFlags() & GETFOCUS_MNEMONIC) != 0) ) + { + // append field in target window + MoveField( *pSourceWindow, *pTargetWindow, pTargetWindow->GetFieldCount(), false ); + // move cursor in selection window to next field + if( pSourceWindow->GetType() == PIVOTFIELDTYPE_SELECT ) + pSourceWindow->SelectNextField(); + // return focus to source window (if it is not empty) + GrabFieldFocus( pSourceWindow->IsEmpty() ? *pTargetWindow : *pSourceWindow ); + } + mpActiveEdit = dynamic_cast< ::formula::RefEdit* >( pEvent->GetWindow() ); + } return 0; } +// ============================================================================ |