diff -uNr old/sc/inc/sc.hrc new/sc/inc/sc.hrc --- old/sc/inc/sc.hrc 2008-11-19 15:48:58.000000000 +0800 +++ new/sc/inc/sc.hrc 2008-12-03 19:36:44.000000000 +0800 @@ -1626,7 +1626,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 2008-11-19 15:44:10.000000000 +0800 +++ new/sc/source/ui/src/sortdlg.src 2008-12-19 10:45:08.000000000 +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 , 33 ) ; + WordBreak = TRUE ; + Text [ en-US ] = "Some cells next to the selection also contain data.\ and you might want to include them in the sort.Do \ you want to extend the sort range to %1,or sort only the selected range %2?"; + }; + FixedText FT_TIP + { + Pos = MAP_APPFONT ( 8 , 55 ) ; + Size = MAP_APPFONT ( 170 , 33 ) ; + WordBreak = TRUE ; + Text [ en-US ] = "Tip: the sort range is automatically selected if the cell marker is placed inside a list before executing sorting."; + }; + PushButton BTN_EXTSORT + { + Pos = MAP_APPFONT ( 6 , 38 ) ; + Size = MAP_APPFONT ( 55 , 14 ) ; + TabStop = TRUE ; + DefButton = TRUE ; + Text [ en-US ] = "Extend selection"; + }; + PushButton BTN_CURSORT + { + Pos = MAP_APPFONT ( 66 , 38 ) ; + Size = MAP_APPFONT ( 60 , 14 ) ; + TabStop = TRUE ; + DefButton = TRUE ; + Text [ en-US ] = "Current selection"; + }; + CancelButton BTN_CANCEL + { + Pos = MAP_APPFONT ( 131 , 38 ) ; + 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 2008-11-19 15:48:00.000000000 +0800 +++ new/sc/source/ui/view/cellsh2.cxx 2008-12-06 16:00:36.000000000 +0800 @@ -338,34 +338,118 @@ SCCOL nCol = GetViewData()->GetCurX(); SCCOL nTab = GetViewData()->GetTabNo(); ScDocument* pDoc = GetViewData()->GetDocument(); + ScDocShell* pDocSh = GetViewData()->GetDocShell(); + ScDirection eFillDir= DIR_TOP; BOOL bHasHeader = FALSE; + BOOL bSort = TRUE; - pDBData->GetSortParam( aSortParam ); + 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); + if( aSortParam.nCol1 != aSortParam.nCol2 ) + eFillDir = DIR_LEFT; + if( aSortParam.nRow1 != aSortParam.nRow2 ) + eFillDir = DIR_TOP; + + SCSIZE nCount = pDoc->GetEmptyLinesInBlock( aSortParam.nCol1, aSortParam.nRow1, nTab, + aSortParam.nCol2, aSortParam.nRow2, nTab, eFillDir ); + + ScRange aRange; + if( nCount > 0 ) + { + aRange = ScRange( aSortParam.nCol1,sal::static_int_cast( nCount ),GetViewData()->GetTabNo() ); + pDBData = pDocSh->GetDBData( aRange, SC_DB_MAKE, FALSE ); + pDBData->GetArea( aRange ); + } + + ScRange aExternalRange( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() ); + pDBData = pDocSh->GetDBData( aExternalRange, SC_DB_MAKE, FALSE ); + pDBData->GetArea( aExternalRange ); + + if(( aSortParam.nCol1 == aSortParam.nCol2 && aExternalRange.aStart.Col() != aExternalRange.aEnd.Col() ) || + ( aSortParam.nRow1 == aSortParam.nRow2 && aExternalRange.aStart.Row() != aExternalRange.aEnd.Row() ) || + aRange.aStart.Row() != aRange.aEnd.Row() && aRange.aStart.Col() != aRange.aEnd.Col()) + { + BOOL bWholeColumn = FALSE; + USHORT nFmt = SCA_VALID; + String aExtendStr; + if( aRange.aStart.Row() != aRange.aEnd.Row() && aRange.aStart.Col() != aRange.aEnd.Col() ) + { + pTabViewShell->AddHighlightRange( aRange,Color( COL_LIGHTBLUE ) ); + ScRange rExtendRange( aRange.aStart.Col(), aRange.aStart.Row(), nTab, aRange.aEnd.Col(), aRange.aEnd.Row(), nTab ); + rExtendRange.Format( aExtendStr, nFmt, pDoc ); + bWholeColumn = TRUE; + } + else + { + 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( aSortParam.nCol1, aSortParam.nRow1, nTab, aSortParam.nCol2, aSortParam.nRow2, nTab ); + String aCurrentStr; + 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 + switch( pWarningDlg->Execute() ) + { + case BTN_EXTEND_RANGE: + if( bWholeColumn ) + { + pTabViewShell->MarkRange( aRange, FALSE ); + pDBData->SetArea( nTab, aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row() ); + } + else + { + pTabViewShell->MarkRange( aExternalRange, FALSE ); + pDBData->SetArea( nTab, aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row() ); + } + break; + case BTN_CURRENT_SELECTION: + pDBData->SetArea( nTab, aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2 ); + break; + default: + bSort = FALSE; + } + delete pWarningDlg; + pTabViewShell->ClearHighlightRanges(); + } + else + pDBData->SetArea( nTab, aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2 ); + + if( bSort ) + { + 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 + pTabViewShell->UISort( aSortParam ); // Teilergebnisse bei Bedarf neu + + rReq.Done(); + } - rReq.Done(); } break; @@ -377,136 +461,296 @@ { ScSortParam aSortParam; ScDBData* pDBData = pTabViewShell->GetDBData(); - pDBData->GetSortParam( aSortParam ); - aSortParam.bInplace = TRUE; // von Basic immer + SCCOL nTab = GetViewData()->GetTabNo(); + ScDocument* pDoc = GetViewData()->GetDocument(); + ScDocShell* pDocSh = GetViewData()->GetDocShell(); + ScDirection eFillDir= DIR_BOTTOM; + BOOL bSort = TRUE; + + pDBData->GetSortParam( aSortParam ); + + if( aSortParam.nCol1 != aSortParam.nCol2 ) + eFillDir=DIR_LEFT; + if( aSortParam.nRow1 != aSortParam.nRow2 ) + eFillDir=DIR_TOP; - 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(); + SCSIZE nCount = pDoc->GetEmptyLinesInBlock( aSortParam.nCol1, aSortParam.nRow1, nTab, + aSortParam.nCol2, aSortParam.nRow2, nTab, eFillDir ); - // Teilergebnisse bei Bedarf neu - pTabViewShell->UISort( aSortParam ); - rReq.Done(); + ScRange aRange; + if( nCount > 0 ) + { + aRange = ScRange( aSortParam.nCol1,sal::static_int_cast( nCount ),GetViewData()->GetTabNo() ); + pDBData = pDocSh->GetDBData( aRange, SC_DB_MAKE, FALSE ); + pDBData->GetArea( aRange ); + } + + ScRange aExternalRange( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() ); + pDBData = pDocSh->GetDBData( aExternalRange, SC_DB_MAKE, FALSE ); + pDBData->GetArea( aExternalRange ); + + if(( aSortParam.nCol1 == aSortParam.nCol2 && aExternalRange.aStart.Col() != aExternalRange.aEnd.Col() ) || + ( aSortParam.nRow1 == aSortParam.nRow2 && aExternalRange.aStart.Row() != aExternalRange.aEnd.Row() ) || + aRange.aStart.Row() != aRange.aEnd.Row() && aRange.aStart.Col() != aRange.aEnd.Col()) + { + BOOL bWholeColumn = FALSE; + USHORT nFmt = SCA_VALID; + String aExtendStr; + if( aRange.aStart.Row() != aRange.aEnd.Row() && aRange.aStart.Col() != aRange.aEnd.Col() ) + { + pTabViewShell->AddHighlightRange( aRange,Color( COL_LIGHTBLUE ) ); + ScRange rExtendRange( aRange.aStart.Col(), aRange.aStart.Row(), nTab, aRange.aEnd.Col(), aRange.aEnd.Row(), nTab ); + rExtendRange.Format( aExtendStr, nFmt, pDoc ); + bWholeColumn = TRUE; + } + else + { + 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( aSortParam.nCol1, aSortParam.nRow1, nTab, aSortParam.nCol2, aSortParam.nRow2, nTab ); + String aCurrentStr; + 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 + switch( pWarningDlg->Execute() ) + { + case BTN_EXTEND_RANGE: + if( bWholeColumn ) + { + pTabViewShell->MarkRange( aRange, FALSE ); + pDBData->SetArea( nTab, aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row() ); + } + else + { + pTabViewShell->MarkRange( aExternalRange, FALSE ); + pDBData->SetArea( nTab, aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row() ); + } + break; + case BTN_CURRENT_SELECTION: + pDBData->SetArea( nTab, aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2 ); + break; + default: + bSort = FALSE; + } + delete pWarningDlg; + pTabViewShell->ClearHighlightRanges(); + } + else + pDBData->SetArea( nTab, aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2 ); + + if( bSort ) + { + pDBData->GetSortParam( aSortParam ); + 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 { - //CHINA001 ScSortDlg* pDlg = NULL; SfxAbstractTabDialog* pDlg = NULL; ScSortParam aSortParam; SfxItemSet aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA ); - ScDBData* pDBData = pTabViewShell->GetDBData(); - pDBData->GetSortParam( aSortParam ); + ScDBData* pDBData = pTabViewShell->GetDBData(); + SCCOL nTab = GetViewData()->GetTabNo(); + ScDocument* pDoc = GetViewData()->GetDocument(); + ScDocShell* pDocSh = GetViewData()->GetDocShell(); + ScDirection eFillDir= DIR_BOTTOM; + BOOL bSort = TRUE; + + pDBData->GetSortParam( aSortParam ); + + if( aSortParam.nCol1 != aSortParam.nCol2 ) + eFillDir=DIR_LEFT; + if( aSortParam.nRow1 != aSortParam.nRow2 ) + eFillDir=DIR_TOP; - aArgSet.Put( ScSortItem( SCITEM_SORTDATA, GetViewData(), &aSortParam ) ); - //CHINA001 pDlg = new ScSortDlg( pTabViewShell->GetDialogParent(), &aArgSet ); - ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); - DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 + SCSIZE nCount = pDoc->GetEmptyLinesInBlock( aSortParam.nCol1, aSortParam.nRow1, nTab, + aSortParam.nCol2, aSortParam.nRow2, nTab, eFillDir ); - 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(); + ScRange aRange; + if( nCount > 0 ) + { + aRange = ScRange( aSortParam.nCol1,sal::static_int_cast( nCount ),GetViewData()->GetTabNo() ); + pDBData = pDocSh->GetDBData( aRange, SC_DB_MAKE, FALSE ); + pDBData->GetArea( aRange ); + } - // Teilergebnisse bei Bedarf neu - pTabViewShell->UISort( rOutParam ); + ScRange aExternalRange( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() ); + pDBData = pDocSh->GetDBData( aExternalRange, SC_DB_MAKE, FALSE ); + pDBData->GetArea( aExternalRange ); + + if(( aSortParam.nCol1 == aSortParam.nCol2 && aExternalRange.aStart.Col() != aExternalRange.aEnd.Col() ) || + ( aSortParam.nRow1 == aSortParam.nRow2 && aExternalRange.aStart.Row() != aExternalRange.aEnd.Row() ) || + aRange.aStart.Row() != aRange.aEnd.Row() && aRange.aStart.Col() != aRange.aEnd.Col()) + { + BOOL bWholeColumn = FALSE; + USHORT nFmt = SCA_VALID; + String aExtendStr; + if( aRange.aStart.Row() != aRange.aEnd.Row() && aRange.aStart.Col() != aRange.aEnd.Col() ) + { + pTabViewShell->AddHighlightRange( aRange,Color( COL_LIGHTBLUE ) ); + ScRange rExtendRange( aRange.aStart.Col(), aRange.aStart.Row(), nTab, aRange.aEnd.Col(), aRange.aEnd.Row(), nTab ); + rExtendRange.Format( aExtendStr, nFmt, pDoc ); + bWholeColumn = TRUE; + } + else + { + 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 ); + } - 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] ) ); - } - } + ScRange rCurrentRange( aSortParam.nCol1, aSortParam.nRow1, nTab, aSortParam.nCol2, aSortParam.nRow2, nTab ); + String aCurrentStr; + rCurrentRange.Format( aCurrentStr, nFmt, pDoc ); - rReq.Done(); - } - else - GetViewData()->GetDocShell()->CancelAutoDBRange(); + ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); + DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 - delete pDlg; - } - } - break; + VclAbstractDialog* pWarningDlg = pFact->CreateScSortWarningDlg( pTabViewShell->GetDialogParent(),aExtendStr,aCurrentStr,RID_SCDLG_SORT_WARNING ); + DBG_ASSERT(pWarningDlg, "Dialog create fail!");//CHINA001 + switch( pWarningDlg->Execute() ) + { + case BTN_EXTEND_RANGE: + if( bWholeColumn ) + { + pTabViewShell->MarkRange( aRange, FALSE ); + pDBData->SetArea( nTab, aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row() ); + } + else + { + pTabViewShell->MarkRange( aExternalRange, FALSE ); + pDBData->SetArea( nTab, aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row() ); + } + break; + case BTN_CURRENT_SELECTION: + pDBData->SetArea( nTab, aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2 ); + break; + default: + bSort = FALSE; + } + delete pWarningDlg; + pTabViewShell->ClearHighlightRanges(); + } + else + pDBData->SetArea( nTab, aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2 ); -/* - { + if( bSort ) + { + pDBData->GetSortParam( aSortParam ); + aArgSet.Put( ScSortItem( SCITEM_SORTDATA, GetViewData(), &aSortParam ) ); - USHORT nId = ScPivotLayoutWrapper::GetChildWindowId(); - SfxChildWindow* pWnd = pSfxApp->GetChildWindow( nId ); + ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); + DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 - pScMod->SetRefDialog( nId, pWnd ? FALSE : TRUE ); + 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(); + delete pDlg; + } + } } break; -*/ case SID_FILTER: {