diff -uNr old/sc/inc/sc.hrc new/sc/inc/sc.hrc --- old/sc/inc/sc.hrc 2009-03-25 12:51:08.453125000 +0800 +++ new/sc/inc/sc.hrc 2009-03-30 17:10:20.484375000 +0800 @@ -1629,7 +1629,7 @@ #define RID_SCDLG_CONFLICTS (SC_DIALOGS_START + 145) #define RID_SCDLG_SHAREDOCUMENT (SC_DIALOGS_START + 146) - +#define RID_SCDLG_SORT_WARNING (SC_DIALOGS_START + 147) #define SC_DIALOGS_END (SC_DIALOGS_START + 150) #ifndef STD_MASKCOLOR diff -uNr old/sc/inc/scabstdlg.hxx new/sc/inc/scabstdlg.hxx --- old/sc/inc/scabstdlg.hxx 2008-11-19 15:48:58.000000000 +0800 +++ new/sc/inc/scabstdlg.hxx 2008-12-04 14:21:58.000000000 +0800 @@ -314,6 +314,7 @@ const String& rStrLabel, int nId, BOOL bColDefault = TRUE ) = 0; + virtual VclAbstractDialog * CreateScSortWarningDlg ( Window* pParent, const String& rExtendText, const String& rCurrentText, int nId ) = 0; //add for ScSortWarningDlg virtual AbstractScDataPilotDatabaseDlg * CreateScDataPilotDatabaseDlg (Window* pParent ,int nId ) = 0; //add for ScDataPilotDatabaseDlg virtual AbstractScDataPilotSourceTypeDlg * CreateScDataPilotSourceTypeDlg ( Window* pParent, BOOL bEnableExternal, int nId ) = 0; //add for ScDataPilotSourceTypeDlg diff -uNr old/sc/source/ui/attrdlg/scdlgfact.cxx new/sc/source/ui/attrdlg/scdlgfact.cxx --- old/sc/source/ui/attrdlg/scdlgfact.cxx 2008-11-19 15:45:06.000000000 +0800 +++ new/sc/source/ui/attrdlg/scdlgfact.cxx 2008-12-04 14:22:18.000000000 +0800 @@ -673,6 +673,24 @@ } //add for ScColOrRowDlg end +//add for ScSortWarningDlg begin +VclAbstractDialog * ScAbstractDialogFactory_Impl::CreateScSortWarningDlg( Window* pParent, const String& rExtendText, + const String& rCurrentText, int nId ) +{ + Dialog * pDlg=NULL; + switch ( nId ) + { + case RID_SCDLG_SORT_WARNING: + pDlg = new ScSortWarningDlg( pParent, rExtendText, rCurrentText ); + break; + default: + break; + } + if( pDlg ) + return new VclAbstractDialog_Impl( pDlg ); + return 0; +} +//add for ScSortWarningDlg end //add for ScDataPilotDatabaseDlg begin diff -uNr old/sc/source/ui/attrdlg/scdlgfact.hxx new/sc/source/ui/attrdlg/scdlgfact.hxx --- old/sc/source/ui/attrdlg/scdlgfact.hxx 2008-11-19 15:45:06.000000000 +0800 +++ new/sc/source/ui/attrdlg/scdlgfact.hxx 2008-12-04 14:22:46.000000000 +0800 @@ -63,6 +63,7 @@ class ScStringInputDlg; class ScImportOptionsDlg; class SfxTabDialog; +class ScSortWarningDlg; #define DECL_ABSTDLG_BASE(Class,DialogClass) \ DialogClass* pDlg; \ @@ -381,6 +382,9 @@ const String& rStrLabel, int nId, BOOL bColDefault = TRUE ); + + virtual VclAbstractDialog * CreateScSortWarningDlg( Window* pParent, const String& rExtendText, const String& rCurrentText, int nId ); + virtual AbstractScDataPilotDatabaseDlg * CreateScDataPilotDatabaseDlg (Window* pParent ,int nId ); //add for ScDataPilotDatabaseDlg virtual AbstractScDataPilotSourceTypeDlg * CreateScDataPilotSourceTypeDlg ( Window* pParent, BOOL bEnableExternal, int nId ) ; //add for ScDataPilotSourceTypeDlg diff -uNr old/sc/source/ui/dbgui/sortdlg.cxx new/sc/source/ui/dbgui/sortdlg.cxx --- old/sc/source/ui/dbgui/sortdlg.cxx 2008-11-19 15:44:36.000000000 +0800 +++ new/sc/source/ui/dbgui/sortdlg.cxx 2008-12-19 10:43:52.000000000 +0800 @@ -34,7 +34,7 @@ #undef SC_DLLIMPLEMENTATION - +#include #include "tpsort.hxx" #include "sortdlg.hxx" #include "scresid.hxx" @@ -61,3 +61,42 @@ { } +//================================================================== +ScSortWarningDlg::ScSortWarningDlg( Window* pParent, + const String& rExtendText, + const String& rCurrentText ): + ModalDialog ( pParent, ScResId( RID_SCDLG_SORT_WARNING ) ), + aFtText ( this, ScResId( FT_TEXT ) ), + aFtTip ( this, ScResId( FT_TIP ) ), + aBtnExtSort ( this, ScResId( BTN_EXTSORT ) ), + aBtnCurSort ( this, ScResId( BTN_CURSORT ) ), + aBtnCancel ( this, ScResId( BTN_CANCEL ) ) +{ + String sTextName = aFtText.GetText(); + sTextName.SearchAndReplaceAscii("%1", rExtendText); + sTextName.SearchAndReplaceAscii("%2", rCurrentText); + aFtText.SetText( sTextName ); + + aBtnExtSort .SetClickHdl( LINK( this, ScSortWarningDlg, BtnHdl ) ); + aBtnCurSort .SetClickHdl( LINK( this, ScSortWarningDlg, BtnHdl ) ); + + FreeResource(); +} + +ScSortWarningDlg::~ScSortWarningDlg() +{ +} + +IMPL_LINK( ScSortWarningDlg, BtnHdl, PushButton*, pBtn ) +{ + if ( pBtn == &aBtnExtSort ) + { + EndDialog( BTN_EXTEND_RANGE ); + } + else if( pBtn == &aBtnCurSort ) + { + EndDialog( BTN_CURRENT_SELECTION ); + } + return 0; +} +//========================================================================// diff -uNr old/sc/source/ui/inc/scui_def.hxx new/sc/source/ui/inc/scui_def.hxx --- old/sc/source/ui/inc/scui_def.hxx 2008-11-19 15:47:04.000000000 +0800 +++ new/sc/source/ui/inc/scui_def.hxx 2008-12-03 19:45:20.000000000 +0800 @@ -53,6 +53,8 @@ #define BTN_PASTE_NAME 100 // from namepast.hxx #define BTN_PASTE_LIST 101 // from namepast.hxx +#define BTN_EXTEND_RANGE 150 +#define BTN_CURRENT_SELECTION 151 #define SCRET_REMOVE 0x42 //from subtdlg.hxx #endif diff -uNr old/sc/source/ui/inc/sortdlg.hrc new/sc/source/ui/inc/sortdlg.hrc --- old/sc/source/ui/inc/sortdlg.hrc 2008-11-19 15:47:02.000000000 +0800 +++ new/sc/source/ui/inc/sortdlg.hrc 2008-12-19 10:44:14.000000000 +0800 @@ -32,6 +32,7 @@ #include "sc.hrc" // -> RID_SCDLG_SORT // -> RID_SCPAGE_SORT_FIELDS // -> RID_SCPAGE_SORT_OPTIONS + // -> RID_SCDLG_SORT_WARNING // -> SCSTR_NONAME // -> SCSTR_UNDEFINED // -> SCSTR_FIELD @@ -40,6 +41,7 @@ #define RID_SCDLG_SORT 256 #define RID_SCPAGE_SORT_FIELDS 257 #define RID_SCPAGE_SORT_OPTIONS 258 +#define RID_SCDLG_SORT_WARNING */ #define TP_FIELDS 1 @@ -80,6 +82,12 @@ #define FT_ALGORITHM 18 #define LB_ALGORITHM 19 +//#define RID_SCDLG_SORT_WARNING +#define FT_TEXT 1 +#define FT_TIP 2 +#define BTN_EXTSORT 3 +#define BTN_CURSORT 4 +#define BTN_CANCEL 5 diff -uNr old/sc/source/ui/inc/sortdlg.hxx new/sc/source/ui/inc/sortdlg.hxx --- old/sc/source/ui/inc/sortdlg.hxx 2008-11-19 15:47:04.000000000 +0800 +++ new/sc/source/ui/inc/sortdlg.hxx 2008-12-19 10:44:30.000000000 +0800 @@ -33,8 +33,18 @@ #include +#ifndef _SV_BUTTON_HXX +#include +#endif +#ifndef _SV_DIALOG_HXX +#include +#endif +#ifndef _SV_FIXED_HXX +#include +#endif #ifndef _SFX_HXX #endif +#include "scui_def.hxx" //CHINA001 //================================================================== @@ -61,6 +71,19 @@ inline BOOL ScSortDlg::GetHeaders() const { return bIsHeaders; } inline BOOL ScSortDlg::GetByRows () const { return bIsByRows; } +class ScSortWarningDlg : public ModalDialog +{ +public: + ScSortWarningDlg( Window* pParent, const String& rExtendText,const String& rCurrentText ); + ~ScSortWarningDlg(); + DECL_LINK( BtnHdl, PushButton* ); +private: + FixedText aFtText; + FixedText aFtTip; + PushButton aBtnExtSort; + PushButton aBtnCurSort; + CancelButton aBtnCancel; +}; #endif // SC_SORTDLG_HXX diff -uNr old/sc/source/ui/src/sortdlg.src new/sc/source/ui/src/sortdlg.src --- old/sc/source/ui/src/sortdlg.src 2009-03-12 18:04:37.343750000 +0800 +++ new/sc/source/ui/src/sortdlg.src 2009-04-17 17:03:20.484375000 +0800 @@ -304,4 +304,49 @@ }; }; +ModalDialog RID_SCDLG_SORT_WARNING +{ + OutputSize = TRUE ; + SVLook = TRUE ; + Size = MAP_APPFONT ( 180 , 82 ) ; + Text [ en-US ] = "Sort Range" ; + Moveable = TRUE ; + Closeable = FALSE ; + FixedText FT_TEXT + { + Pos = MAP_APPFONT ( 8 , 3 ) ; + Size = MAP_APPFONT ( 170 , 28 ) ; + WordBreak = TRUE; + Text [ en-US ] = "The cells next to the current selection also contain data.Do you want to extend the sort range to %1, or sort the currently selected range, %2?"; + }; + FixedText FT_TIP + { + Pos = MAP_APPFONT ( 8 , 46 ) ; + Size = MAP_APPFONT ( 170 , 33 ) ; + WordBreak = TRUE ; + Text [ en-US ] = "Tip: The sort range can be detected automatically. Place the cell cursor inside a list and execute sort. The whole region of neighboring non-empty cells will then be sorted."; + }; + PushButton BTN_EXTSORT + { + Pos = MAP_APPFONT ( 6 , 30 ) ; + Size = MAP_APPFONT ( 55 , 14 ) ; + TabStop = TRUE ; + DefButton = TRUE ; + Text [ en-US ] = "Extend selection"; + }; + PushButton BTN_CURSORT + { + Pos = MAP_APPFONT ( 66 , 30 ) ; + Size = MAP_APPFONT ( 60 , 14 ) ; + TabStop = TRUE ; + DefButton = TRUE ; + Text [ en-US ] = "Current selection"; + }; + CancelButton BTN_CANCEL + { + Pos = MAP_APPFONT ( 131 , 30 ) ; + Size = MAP_APPFONT ( 40 , 14 ) ; + TabStop = TRUE ; + }; +}; diff -uNr old/sc/source/ui/view/cellsh2.cxx new/sc/source/ui/view/cellsh2.cxx --- old/sc/source/ui/view/cellsh2.cxx 2009-03-12 18:05:56.609375000 +0800 +++ new/sc/source/ui/view/cellsh2.cxx 2009-04-07 14:14:25.828125000 +0800 @@ -138,6 +138,77 @@ return bRet; } +BOOL lcl_GetSortParam( const ScViewData* pData, ScSortParam& rSortParam ) +{ + ScTabViewShell* pTabViewShell = pData->GetViewShell(); + ScDBData* pDBData = pTabViewShell->GetDBData(); + ScDocument* pDoc = pData->GetDocument(); + SCTAB nTab = pData->GetTabNo(); + ScDirection eFillDir = DIR_TOP; + BOOL bSort = TRUE; + ScRange aExternalRange; + + if( rSortParam.nCol1 != rSortParam.nCol2 ) + eFillDir = DIR_LEFT; + if( rSortParam.nRow1 != rSortParam.nRow2 ) + eFillDir = DIR_TOP; + + SCSIZE nCount = pDoc->GetEmptyLinesInBlock( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab, eFillDir ); + + if( rSortParam.nRow2 == MAXROW ) + aExternalRange = ScRange( rSortParam.nCol1,sal::static_int_cast( nCount ), nTab ); + else + aExternalRange = ScRange( pData->GetCurX(), pData->GetCurY(), nTab ); + + SCROW nStartRow = aExternalRange.aStart.Row(); + SCCOL nStartCol = aExternalRange.aStart.Col(); + SCROW nEndRow = aExternalRange.aEnd.Row(); + SCCOL nEndCol = aExternalRange.aEnd.Col(); + pDoc->GetDataArea( aExternalRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow, FALSE ); + aExternalRange.aStart.SetRow( nStartRow ); + aExternalRange.aStart.SetCol( nStartCol ); + aExternalRange.aEnd.SetRow( nEndRow ); + aExternalRange.aEnd.SetCol( nEndCol ); + + if(( rSortParam.nCol1 == rSortParam.nCol2 && aExternalRange.aStart.Col() != aExternalRange.aEnd.Col() ) || + ( rSortParam.nRow1 == rSortParam.nRow2 && aExternalRange.aStart.Row() != aExternalRange.aEnd.Row() ) ) + { + USHORT nFmt = SCA_VALID; + String aExtendStr,aCurrentStr; + + pTabViewShell->AddHighlightRange( aExternalRange,Color( COL_LIGHTBLUE ) ); + ScRange rExtendRange( aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), nTab, aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row(), nTab ); + rExtendRange.Format( aExtendStr, nFmt, pDoc ); + + ScRange rCurrentRange( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab ); + rCurrentRange.Format( aCurrentStr, nFmt, pDoc ); + + ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); + DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 + + VclAbstractDialog* pWarningDlg = pFact->CreateScSortWarningDlg( pTabViewShell->GetDialogParent(),aExtendStr,aCurrentStr,RID_SCDLG_SORT_WARNING ); + DBG_ASSERT(pWarningDlg, "Dialog create fail!");//CHINA001 + short bResult = pWarningDlg->Execute(); + if( bResult == BTN_EXTEND_RANGE || bResult == BTN_CURRENT_SELECTION ) + { + if( bResult == BTN_EXTEND_RANGE ) + { + pTabViewShell->MarkRange( aExternalRange, FALSE ); + pDBData->SetArea( nTab, aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row() ); + } + } + else + { + bSort = FALSE; + pData->GetDocShell()->CancelAutoDBRange(); + } + + delete pWarningDlg; + pTabViewShell->ClearHighlightRanges(); + } + return bSort; +} + void ScCellShell::ExecuteDB( SfxRequest& rReq ) { ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell(); @@ -329,184 +400,205 @@ } break; - case SID_SORT_DESCENDING: - case SID_SORT_ASCENDING: - { - SfxItemSet aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA ); - ScSortParam aSortParam; - ScDBData* pDBData = pTabViewShell->GetDBData(); - SCCOL nCol = GetViewData()->GetCurX(); - SCCOL nTab = GetViewData()->GetTabNo(); - ScDocument* pDoc = GetViewData()->GetDocument(); - BOOL bHasHeader = FALSE; - - pDBData->GetSortParam( aSortParam ); - - bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, nTab ); - - if( nCol < aSortParam.nCol1 ) - nCol = aSortParam.nCol1; - else if( nCol > aSortParam.nCol2 ) - nCol = aSortParam.nCol2; - - aSortParam.bHasHeader = bHasHeader; - aSortParam.bByRow = TRUE; - aSortParam.bCaseSens = FALSE; - aSortParam.bIncludePattern = FALSE; - aSortParam.bInplace = TRUE; - aSortParam.bDoSort[0] = TRUE; - aSortParam.nField[0] = nCol; - aSortParam.bAscending[0] = (nSlotId == SID_SORT_ASCENDING); - - for ( USHORT i=1; iUISort( aSortParam ); // Teilergebnisse bei Bedarf neu - - rReq.Done(); - } - break; - - case SID_SORT: - { - const SfxItemSet* pArgs = rReq.GetArgs(); - - if ( pArgs ) // Basic - { - ScSortParam aSortParam; - ScDBData* pDBData = pTabViewShell->GetDBData(); - pDBData->GetSortParam( aSortParam ); - aSortParam.bInplace = TRUE; // von Basic immer + case SID_SORT_DESCENDING: + case SID_SORT_ASCENDING: + { + //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data + //the patch comes from maoyg + ScSortParam aSortParam; + ScDBData* pDBData = pTabViewShell->GetDBData(); + ScViewData* pData = GetViewData(); - const SfxPoolItem* pItem; - if ( pArgs->GetItemState( SID_SORT_BYROW, TRUE, &pItem ) == SFX_ITEM_SET ) - aSortParam.bByRow = ((const SfxBoolItem*)pItem)->GetValue(); - if ( pArgs->GetItemState( SID_SORT_HASHEADER, TRUE, &pItem ) == SFX_ITEM_SET ) - aSortParam.bHasHeader = ((const SfxBoolItem*)pItem)->GetValue(); - if ( pArgs->GetItemState( SID_SORT_CASESENS, TRUE, &pItem ) == SFX_ITEM_SET ) - aSortParam.bCaseSens = ((const SfxBoolItem*)pItem)->GetValue(); - if ( pArgs->GetItemState( SID_SORT_ATTRIBS, TRUE, &pItem ) == SFX_ITEM_SET ) - aSortParam.bIncludePattern = ((const SfxBoolItem*)pItem)->GetValue(); - if ( pArgs->GetItemState( SID_SORT_USERDEF, TRUE, &pItem ) == SFX_ITEM_SET ) - { - USHORT nUserIndex = ((const SfxUInt16Item*)pItem)->GetValue(); - aSortParam.bUserDef = ( nUserIndex != 0 ); - if ( nUserIndex ) - aSortParam.nUserIndex = nUserIndex - 1; // Basic: 1-basiert - } - - SCCOLROW nField0 = 0; - if ( pArgs->GetItemState( FN_PARAM_1, TRUE, &pItem ) == SFX_ITEM_SET ) - nField0 = ((const SfxInt32Item*)pItem)->GetValue(); - aSortParam.bDoSort[0] = ( nField0 != 0 ); - aSortParam.nField[0] = nField0 > 0 ? (nField0-1) : 0; - if ( pArgs->GetItemState( FN_PARAM_2, TRUE, &pItem ) == SFX_ITEM_SET ) - aSortParam.bAscending[0] = ((const SfxBoolItem*)pItem)->GetValue(); - SCCOLROW nField1 = 0; - if ( pArgs->GetItemState( FN_PARAM_3, TRUE, &pItem ) == SFX_ITEM_SET ) - nField1 = ((const SfxInt32Item*)pItem)->GetValue(); - aSortParam.bDoSort[1] = ( nField1 != 0 ); - aSortParam.nField[1] = nField1 > 0 ? (nField1-1) : 0; - if ( pArgs->GetItemState( FN_PARAM_4, TRUE, &pItem ) == SFX_ITEM_SET ) - aSortParam.bAscending[1] = ((const SfxBoolItem*)pItem)->GetValue(); - SCCOLROW nField2 = 0; - if ( pArgs->GetItemState( FN_PARAM_5, TRUE, &pItem ) == SFX_ITEM_SET ) - nField2 = ((const SfxInt32Item*)pItem)->GetValue(); - aSortParam.bDoSort[2] = ( nField2 != 0 ); - aSortParam.nField[2] = nField2 > 0 ? (nField2-1) : 0; - if ( pArgs->GetItemState( FN_PARAM_6, TRUE, &pItem ) == SFX_ITEM_SET ) - aSortParam.bAscending[2] = ((const SfxBoolItem*)pItem)->GetValue(); + pDBData->GetSortParam( aSortParam ); - // Teilergebnisse bei Bedarf neu - pTabViewShell->UISort( aSortParam ); - rReq.Done(); - } - else - { - //CHINA001 ScSortDlg* pDlg = NULL; - SfxAbstractTabDialog* pDlg = NULL; - ScSortParam aSortParam; - SfxItemSet aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA ); + if( lcl_GetSortParam( pData, aSortParam ) ) + { + SfxItemSet aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA ); + SCCOL nCol = GetViewData()->GetCurX(); + SCCOL nTab = GetViewData()->GetTabNo(); + ScDocument* pDoc = GetViewData()->GetDocument(); + + pDBData->GetSortParam( aSortParam ); + BOOL bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, nTab ); + + if( nCol < aSortParam.nCol1 ) + nCol = aSortParam.nCol1; + else if( nCol > aSortParam.nCol2 ) + nCol = aSortParam.nCol2; + + aSortParam.bHasHeader = bHasHeader; + aSortParam.bByRow = TRUE; + aSortParam.bCaseSens = FALSE; + aSortParam.bIncludePattern = FALSE; + aSortParam.bInplace = TRUE; + aSortParam.bDoSort[0] = TRUE; + aSortParam.nField[0] = nCol; + aSortParam.bAscending[0] = (nSlotId == SID_SORT_ASCENDING); - ScDBData* pDBData = pTabViewShell->GetDBData(); - pDBData->GetSortParam( aSortParam ); + for ( USHORT i=1; iGetDialogParent(), &aArgSet ); - ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); - DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 + aArgSet.Put( ScSortItem( SCITEM_SORTDATA, GetViewData(), &aSortParam ) ); - pDlg = pFact->CreateScSortDlg( pTabViewShell->GetDialogParent(), &aArgSet, RID_SCDLG_SORT ); - DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 - pDlg->SetCurPageId(1); + pTabViewShell->UISort( aSortParam ); // Teilergebnisse bei Bedarf neu - if ( pDlg->Execute() == RET_OK ) - { - const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); - const ScSortParam& rOutParam = ((const ScSortItem&) - pOutSet->Get( SCITEM_SORTDATA )).GetSortData(); + rReq.Done(); + } + } + break; + + case SID_SORT: + { + const SfxItemSet* pArgs = rReq.GetArgs(); - // Teilergebnisse bei Bedarf neu - pTabViewShell->UISort( rOutParam ); + //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data + //the patch comes from maoyg - if ( rOutParam.bInplace ) - { - rReq.AppendItem( SfxBoolItem( SID_SORT_BYROW, - rOutParam.bByRow ) ); - rReq.AppendItem( SfxBoolItem( SID_SORT_HASHEADER, - rOutParam.bHasHeader ) ); - rReq.AppendItem( SfxBoolItem( SID_SORT_CASESENS, - rOutParam.bCaseSens ) ); - rReq.AppendItem( SfxBoolItem( SID_SORT_ATTRIBS, - rOutParam.bIncludePattern ) ); - USHORT nUser = rOutParam.bUserDef ? ( rOutParam.nUserIndex + 1 ) : 0; - rReq.AppendItem( SfxUInt16Item( SID_SORT_USERDEF, nUser ) ); - if ( rOutParam.bDoSort[0] ) - { - rReq.AppendItem( SfxInt32Item( FN_PARAM_1, - rOutParam.nField[0] + 1 ) ); - rReq.AppendItem( SfxBoolItem( FN_PARAM_2, - rOutParam.bAscending[0] ) ); - } - if ( rOutParam.bDoSort[1] ) - { - rReq.AppendItem( SfxInt32Item( FN_PARAM_3, - rOutParam.nField[1] + 1 ) ); - rReq.AppendItem( SfxBoolItem( FN_PARAM_4, - rOutParam.bAscending[1] ) ); - } - if ( rOutParam.bDoSort[2] ) - { - rReq.AppendItem( SfxInt32Item( FN_PARAM_5, - rOutParam.nField[2] + 1 ) ); - rReq.AppendItem( SfxBoolItem( FN_PARAM_6, - rOutParam.bAscending[2] ) ); - } - } + if ( pArgs ) // Basic + { + ScSortParam aSortParam; + ScDBData* pDBData = pTabViewShell->GetDBData(); + ScViewData* pData = GetViewData(); - rReq.Done(); - } - else - GetViewData()->GetDocShell()->CancelAutoDBRange(); + pDBData->GetSortParam( aSortParam ); - delete pDlg; - } - } - break; + if( lcl_GetSortParam( pData, aSortParam ) ) + { + ScDocument* pDoc = GetViewData()->GetDocument(); -/* - { + pDBData->GetSortParam( aSortParam ); + BOOL bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, pData->GetTabNo() ); + if( bHasHeader ) + aSortParam.bHasHeader = bHasHeader; + + aSortParam.bInplace = TRUE; // von Basic immer + + const SfxPoolItem* pItem; + if ( pArgs->GetItemState( SID_SORT_BYROW, TRUE, &pItem ) == SFX_ITEM_SET ) + aSortParam.bByRow = ((const SfxBoolItem*)pItem)->GetValue(); + if ( pArgs->GetItemState( SID_SORT_HASHEADER, TRUE, &pItem ) == SFX_ITEM_SET ) + aSortParam.bHasHeader = ((const SfxBoolItem*)pItem)->GetValue(); + if ( pArgs->GetItemState( SID_SORT_CASESENS, TRUE, &pItem ) == SFX_ITEM_SET ) + aSortParam.bCaseSens = ((const SfxBoolItem*)pItem)->GetValue(); + if ( pArgs->GetItemState( SID_SORT_ATTRIBS, TRUE, &pItem ) == SFX_ITEM_SET ) + aSortParam.bIncludePattern = ((const SfxBoolItem*)pItem)->GetValue(); + if ( pArgs->GetItemState( SID_SORT_USERDEF, TRUE, &pItem ) == SFX_ITEM_SET ) + { + USHORT nUserIndex = ((const SfxUInt16Item*)pItem)->GetValue(); + aSortParam.bUserDef = ( nUserIndex != 0 ); + if ( nUserIndex ) + aSortParam.nUserIndex = nUserIndex - 1; // Basic: 1-basiert + } + + SCCOLROW nField0 = 0; + if ( pArgs->GetItemState( FN_PARAM_1, TRUE, &pItem ) == SFX_ITEM_SET ) + nField0 = ((const SfxInt32Item*)pItem)->GetValue(); + aSortParam.bDoSort[0] = ( nField0 != 0 ); + aSortParam.nField[0] = nField0 > 0 ? (nField0-1) : 0; + if ( pArgs->GetItemState( FN_PARAM_2, TRUE, &pItem ) == SFX_ITEM_SET ) + aSortParam.bAscending[0] = ((const SfxBoolItem*)pItem)->GetValue(); + SCCOLROW nField1 = 0; + if ( pArgs->GetItemState( FN_PARAM_3, TRUE, &pItem ) == SFX_ITEM_SET ) + nField1 = ((const SfxInt32Item*)pItem)->GetValue(); + aSortParam.bDoSort[1] = ( nField1 != 0 ); + aSortParam.nField[1] = nField1 > 0 ? (nField1-1) : 0; + if ( pArgs->GetItemState( FN_PARAM_4, TRUE, &pItem ) == SFX_ITEM_SET ) + aSortParam.bAscending[1] = ((const SfxBoolItem*)pItem)->GetValue(); + SCCOLROW nField2 = 0; + if ( pArgs->GetItemState( FN_PARAM_5, TRUE, &pItem ) == SFX_ITEM_SET ) + nField2 = ((const SfxInt32Item*)pItem)->GetValue(); + aSortParam.bDoSort[2] = ( nField2 != 0 ); + aSortParam.nField[2] = nField2 > 0 ? (nField2-1) : 0; + if ( pArgs->GetItemState( FN_PARAM_6, TRUE, &pItem ) == SFX_ITEM_SET ) + aSortParam.bAscending[2] = ((const SfxBoolItem*)pItem)->GetValue(); + + // Teilergebnisse bei Bedarf neu + pTabViewShell->UISort( aSortParam ); + rReq.Done(); + } + } + else + { + ScSortParam aSortParam; + ScDBData* pDBData = pTabViewShell->GetDBData(); + ScViewData* pData = GetViewData(); - USHORT nId = ScPivotLayoutWrapper::GetChildWindowId(); - SfxChildWindow* pWnd = pSfxApp->GetChildWindow( nId ); + pDBData->GetSortParam( aSortParam ); - pScMod->SetRefDialog( nId, pWnd ? FALSE : TRUE ); + if( lcl_GetSortParam( pData, aSortParam ) ) + { + SfxAbstractTabDialog* pDlg = NULL; + ScDocument* pDoc = GetViewData()->GetDocument(); + SfxItemSet aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA ); + + pDBData->GetSortParam( aSortParam ); + BOOL bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, pData->GetTabNo() ); + if( bHasHeader ) + aSortParam.bHasHeader = bHasHeader; + + aArgSet.Put( ScSortItem( SCITEM_SORTDATA, GetViewData(), &aSortParam ) ); + + ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); + DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 + + pDlg = pFact->CreateScSortDlg( pTabViewShell->GetDialogParent(), &aArgSet, RID_SCDLG_SORT ); + DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 + pDlg->SetCurPageId(1); + + if ( pDlg->Execute() == RET_OK ) + { + const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); + const ScSortParam& rOutParam = ((const ScSortItem&) + pOutSet->Get( SCITEM_SORTDATA )).GetSortData(); + + // Teilergebnisse bei Bedarf neu + pTabViewShell->UISort( rOutParam ); + + if ( rOutParam.bInplace ) + { + rReq.AppendItem( SfxBoolItem( SID_SORT_BYROW, + rOutParam.bByRow ) ); + rReq.AppendItem( SfxBoolItem( SID_SORT_HASHEADER, + rOutParam.bHasHeader ) ); + rReq.AppendItem( SfxBoolItem( SID_SORT_CASESENS, + rOutParam.bCaseSens ) ); + rReq.AppendItem( SfxBoolItem( SID_SORT_ATTRIBS, + rOutParam.bIncludePattern ) ); + USHORT nUser = rOutParam.bUserDef ? ( rOutParam.nUserIndex + 1 ) : 0; + rReq.AppendItem( SfxUInt16Item( SID_SORT_USERDEF, nUser ) ); + if ( rOutParam.bDoSort[0] ) + { + rReq.AppendItem( SfxInt32Item( FN_PARAM_1, + rOutParam.nField[0] + 1 ) ); + rReq.AppendItem( SfxBoolItem( FN_PARAM_2, + rOutParam.bAscending[0] ) ); + } + if ( rOutParam.bDoSort[1] ) + { + rReq.AppendItem( SfxInt32Item( FN_PARAM_3, + rOutParam.nField[1] + 1 ) ); + rReq.AppendItem( SfxBoolItem( FN_PARAM_4, + rOutParam.bAscending[1] ) ); + } + if ( rOutParam.bDoSort[2] ) + { + rReq.AppendItem( SfxInt32Item( FN_PARAM_5, + rOutParam.nField[2] + 1 ) ); + rReq.AppendItem( SfxBoolItem( FN_PARAM_6, + rOutParam.bAscending[2] ) ); + } + } + + rReq.Done(); + } + else + GetViewData()->GetDocShell()->CancelAutoDBRange(); - } - break; -*/ + delete pDlg; + } + } + } + break; case SID_FILTER: {