diff options
author | Daniel Rentz <dr@openoffice.org> | 2002-10-16 11:13:04 +0000 |
---|---|---|
committer | Daniel Rentz <dr@openoffice.org> | 2002-10-16 11:13:04 +0000 |
commit | 68b3dfa734d08a20365b17b7de91690dacf8fbf0 (patch) | |
tree | b1d29bcac7faa253e3cebbb050bfa2c0f98bf5e5 /sc | |
parent | 0c243f3710f93b0f9b278a83fc886d28a8339939 (diff) |
#88839# store selection correctly
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/inc/content.hxx | 25 | ||||
-rw-r--r-- | sc/source/ui/inc/navsett.hxx | 25 | ||||
-rw-r--r-- | sc/source/ui/navipi/content.cxx | 261 | ||||
-rw-r--r-- | sc/source/ui/navipi/navipi.cxx | 17 |
4 files changed, 178 insertions, 150 deletions
diff --git a/sc/source/ui/inc/content.hxx b/sc/source/ui/inc/content.hxx index dd12de727a2a..1e0f9a61591a 100644 --- a/sc/source/ui/inc/content.hxx +++ b/sc/source/ui/inc/content.hxx @@ -2,9 +2,9 @@ * * $RCSfile: content.hxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: gt $ $Date: 2002-07-19 15:16:30 $ + * last change: $Author: dr $ $Date: 2002-10-16 12:12:37 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -87,6 +87,8 @@ class ScAreaLink; #define SC_CONTENT_DRAWING 8 #define SC_CONTENT_COUNT 9 +const ULONG SC_CONTENT_NOCHILD = ~0UL; + // // TreeListBox fuer Inhalte // @@ -131,8 +133,17 @@ class ScContentTree : public SvTreeListBox ScAddress GetNotePos( ULONG nIndex ); const ScAreaLink* GetLink( ULONG nIndex ); - USHORT GetCurrentContent( String& rValue ); - ULONG GetCurrentIndex( SvLBoxEntry* pCurrent = NULL ); + /** Returns the indexes of the specified listbox entry. + @param rnRootIndex Root index of specified entry is returned. + @param rnChildIndex Index of the entry inside its root is returned (or SC_CONTENT_NOCHILD if entry is root). + @param pEntry The entry to examine. */ + void GetEntryIndexes( USHORT& rnRootIndex, ULONG& rnChildIndex, SvLBoxEntry* pEntry ) const; + + /** Returns the child index of the specified listbox entry. + @param pEntry The entry to examine or NULL for the selected entry. + @return Index of the entry inside its root or SC_CONTENT_NOCHILD if entry is root. */ + ULONG GetChildIndex( SvLBoxEntry* pEntry ) const; + void DoDrag(); void AdjustTitle(); @@ -176,8 +187,10 @@ public: const String& GetHiddenTitle() const { return aHiddenTitle; } - void ApplySettings(); - void StoreSettings(); + /** Applies the navigator settings to the listbox. */ + void ApplySettings(); + /** Stores the current listbox state in the navigator settings. */ + void StoreSettings() const; static BOOL IsInDrag() { return bIsInDrag; } }; diff --git a/sc/source/ui/inc/navsett.hxx b/sc/source/ui/inc/navsett.hxx index 22becd6c7b0d..bd869a1d545c 100644 --- a/sc/source/ui/inc/navsett.hxx +++ b/sc/source/ui/inc/navsett.hxx @@ -2,9 +2,9 @@ * * $RCSfile: navsett.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: dr $ $Date: 2001-11-02 14:15:44 $ + * last change: $Author: dr $ $Date: 2002-10-16 12:12:38 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -66,27 +66,28 @@ #include <tools/solar.h> #endif +#include <vector> + /** Contains settings of the navigator listbox. This includes the expand state of each listbox entry and the index of the selected entry and sub entry. */ class ScNavigatorSettings { private: - BOOL* pExpanded; /// Array of BOOL for expand state. - ULONG nSelected; /// Index of selected entry. - ULONG nSubSelected; /// Index of selected sub entry. + ::std::vector< BOOL > maExpandedVec; /// Array of Booleans for expand state. + USHORT mnRootSelected; /// Index of selected root entry. + ULONG mnChildSelected; /// Index of selected child entry. public: ScNavigatorSettings(); - ~ScNavigatorSettings(); - inline void SetExpanded( ULONG nIndex, BOOL bExpand ) { pExpanded[ nIndex ] = bExpand; } - inline BOOL IsExpanded( ULONG nIndex ) const { return pExpanded[ nIndex ]; } + inline void SetExpanded( USHORT nIndex, BOOL bExpand ) { maExpandedVec[ nIndex ] = bExpand; } + inline BOOL IsExpanded( USHORT nIndex ) const { return maExpandedVec[ nIndex ]; } - inline void SetSelected( ULONG nIndex ) { nSelected = nIndex; } - inline ULONG GetSelected() const { return nSelected; } + inline void SetRootSelected( USHORT nIndex ) { mnRootSelected = nIndex; } + inline USHORT GetRootSelected() const { return mnRootSelected; } - inline void SetSubSelected( ULONG nIndex ) { nSubSelected = nIndex; } - inline ULONG GetSubSelected() const { return nSubSelected; } + inline void SetChildSelected( ULONG nIndex ) { mnChildSelected = nIndex; } + inline ULONG GetChildSelected() const { return mnChildSelected; } }; diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx index 0b8beacb3ccc..c9f5f581f646 100644 --- a/sc/source/ui/navipi/content.cxx +++ b/sc/source/ui/navipi/content.cxx @@ -2,9 +2,9 @@ * * $RCSfile: content.cxx,v $ * - * $Revision: 1.13 $ + * $Revision: 1.14 $ * - * last change: $Author: gt $ $Date: 2002-07-19 15:14:29 $ + * last change: $Author: dr $ $Date: 2002-10-16 12:13:03 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -251,67 +251,53 @@ void ScContentTree::InsertContent( USHORT nType, const String& rValue ) DBG_ERROR("InsertContent ohne Parent"); } -USHORT ScContentTree::GetCurrentContent( String& rValue ) +void ScContentTree::GetEntryIndexes( USHORT& rnRootIndex, ULONG& rnChildIndex, SvLBoxEntry* pEntry ) const { - SvLBoxEntry* pEntry = GetCurEntry(); - if (!pEntry) - { - DBG_ERROR("kein aktueller Eintrag!"); - rValue.Erase(); - return 0; - } - SvLBoxEntry* pParent = GetParent(pEntry); // kann 0 sein, wenn umgeschaltet ist + rnRootIndex = SC_CONTENT_ROOT; + rnChildIndex = SC_CONTENT_NOCHILD; - USHORT nType = 0; - BOOL bRoot = FALSE; - for (USHORT i=1; i<SC_CONTENT_COUNT; i++) + if( !pEntry ) + return; + + SvLBoxEntry* pParent = GetParent( pEntry ); + bool bFound = false; + for( USHORT nRoot = 1; !bFound && (nRoot < SC_CONTENT_COUNT); ++nRoot ) { - if ( pEntry == pRootNodes[i] ) + if( pEntry == pRootNodes[ nRoot ] ) { - bRoot = TRUE; - rValue = GetEntryText(pEntry); + rnRootIndex = nRoot; + rnChildIndex = ~0UL; + bFound = true; } - else if ( pParent && pParent == pRootNodes[i] ) + else if( pParent && (pParent == pRootNodes[ nRoot ]) ) { - nType = i; - rValue = GetEntryText(pEntry); - } - } + rnRootIndex = nRoot; - DBG_ASSERT( bRoot || nType, "ScContentTree: unbekannter Eintrag" ); + // search the entry in all child entries of the parent + ULONG nEntry = 0; + SvLBoxEntry* pIterEntry = FirstChild( pParent ); + while( !bFound && pIterEntry ) + { + if ( pEntry == pIterEntry ) + { + rnChildIndex = nEntry; + bFound = true; // exit the while loop + } + pIterEntry = NextSibling( pIterEntry ); + ++nEntry; + } - return nType; + bFound = true; // exit the for loop + } + } } -ULONG ScContentTree::GetCurrentIndex( SvLBoxEntry* pCurrent ) +ULONG ScContentTree::GetChildIndex( SvLBoxEntry* pEntry ) const { - if (!pCurrent) - pCurrent = GetCurEntry(); - if (!pCurrent) - { - DBG_ERROR("kein aktueller Eintrag!"); - return 0; - } - SvLBoxEntry* pParent = GetParent(pCurrent); - if (!pParent) - { - DBG_ERROR("kein Parent!"); - return 0; - } - - ULONG nIndex = 0; - SvLBoxEntry* pEntry = FirstChild( pParent ); - while (pEntry) - { - if ( pEntry == pCurrent ) - return nIndex; - - pEntry = NextSibling( pEntry ); - ++nIndex; - } - - DBG_ERROR("Eintrag nicht gefunden"); - return 0; + USHORT nRoot; + ULONG nChild; + GetEntryIndexes( nRoot, nChild, pEntry ); + return nChild; } String lcl_GetDBAreaRange( ScDocument* pDoc, const String& rDBName ) @@ -338,13 +324,18 @@ String lcl_GetDBAreaRange( ScDocument* pDoc, const String& rDBName ) IMPL_LINK( ScContentTree, DoubleClickHdl, ScContentTree *, EMPTYARG ) { - String aText; - USHORT nType = GetCurrentContent( aText ); - if ( nType ) + USHORT nType; + ULONG nChild; + SvLBoxEntry* pEntry = GetCurEntry(); + GetEntryIndexes( nType, nChild, pEntry ); + + if( pEntry && (nType != SC_CONTENT_ROOT) && (nChild != SC_CONTENT_NOCHILD) ) { if ( bHiddenDoc ) return 0; //! spaeter... + String aText( GetEntryText( pEntry ) ); + if ( aManualDoc.Len() ) pParentWindow->SetCurrentDoc( aManualDoc ); @@ -352,47 +343,50 @@ IMPL_LINK( ScContentTree, DoubleClickHdl, ScContentTree *, EMPTYARG ) { case SC_CONTENT_TABLE: pParentWindow->SetCurrentTableStr( aText ); - break; + break; + case SC_CONTENT_RANGENAME: pParentWindow->SetCurrentCellStr( aText ); - break; + break; + case SC_CONTENT_DBAREA: - { - // #47905# Wenn gleiche Bereichs- und DB-Namen existieren, wird - // bei SID_CURRENTCELL der Bereichsname genommen. - // DB-Bereiche darum direkt ueber die Adresse anspringen. + { + // #47905# Wenn gleiche Bereichs- und DB-Namen existieren, wird + // bei SID_CURRENTCELL der Bereichsname genommen. + // DB-Bereiche darum direkt ueber die Adresse anspringen. + + String aRangeStr = lcl_GetDBAreaRange( GetSourceDocument(), aText ); + if (aRangeStr.Len()) + pParentWindow->SetCurrentCellStr( aRangeStr ); + } + break; - String aRangeStr = lcl_GetDBAreaRange( GetSourceDocument(), aText ); - if (aRangeStr.Len()) - pParentWindow->SetCurrentCellStr( aRangeStr ); - } - break; case SC_CONTENT_OLEOBJECT: case SC_CONTENT_GRAPHIC: case SC_CONTENT_DRAWING: pParentWindow->SetCurrentObject( aText ); - break; + break; + case SC_CONTENT_NOTE: - { - ULONG nIndex = GetCurrentIndex(); - ScAddress aPos = GetNotePos(nIndex); - pParentWindow->SetCurrentTable( aPos.Tab() ); - pParentWindow->SetCurrentCell( aPos.Col(), aPos.Row() ); - } - break; + { + ScAddress aPos = GetNotePos( nChild ); + pParentWindow->SetCurrentTable( aPos.Tab() ); + pParentWindow->SetCurrentCell( aPos.Col(), aPos.Row() ); + } + break; + case SC_CONTENT_AREALINK: + { + const ScAreaLink* pLink = GetLink( nChild ); + if( pLink ) { - ULONG nIndex = GetCurrentIndex(); - const ScAreaLink* pLink = GetLink(nIndex); - if (pLink) - { - ScRange aRange = pLink->GetDestArea(); - String aRangeStr; - aRange.Format( aRangeStr, SCR_ABS_3D, GetSourceDocument() ); - pParentWindow->SetCurrentCellStr( aRangeStr ); - } + ScRange aRange = pLink->GetDestArea(); + String aRangeStr; + aRange.Format( aRangeStr, SCR_ABS_3D, GetSourceDocument() ); + pParentWindow->SetCurrentCellStr( aRangeStr ); } - break; + } + break; } ScNavigatorDlg::ReleaseFocus(); // set focus into document @@ -421,25 +415,29 @@ void ScContentTree::KeyInput( const KeyEvent& rKEvt ) bUsed = TRUE; break; case 0: + { + SvLBoxEntry* pEntry = GetCurEntry(); + if( pEntry ) { - String aText; - USHORT nType = GetCurrentContent( aText ); - if ( nType == SC_CONTENT_ROOT ) + USHORT nType; + ULONG nChild; + GetEntryIndexes( nType, nChild, pEntry ); + + if( (nType != SC_CONTENT_ROOT) && (nChild == SC_CONTENT_NOCHILD) ) { - SvLBoxEntry* pEntry = GetCurEntry(); - if ( pEntry ) - { - if ( IsExpanded(pEntry) ) - Collapse(pEntry); - else - Expand(pEntry); - } + String aText( GetEntryText( pEntry ) ); + if ( IsExpanded( pEntry ) ) + Collapse( pEntry ); + else + Expand( pEntry ); } else DoubleClickHdl(0); // select content as if double clicked - bUsed = TRUE; } - break; + + bUsed = TRUE; + } + break; } } StoreSettings(); @@ -598,12 +596,15 @@ void __EXPORT ScContentTree::RequestHelp( const HelpEvent& rHEvt ) } else if ( pParent == pRootNodes[SC_CONTENT_AREALINK] ) { - ULONG nIndex = GetCurrentIndex(pEntry); - const ScAreaLink* pLink = GetLink(nIndex); - if (pLink) + ULONG nIndex = GetChildIndex(pEntry); + if( nIndex != SC_CONTENT_NOCHILD ) { - aHelpText = pLink->GetFile(); // Source-Datei als Help-Text - bRet = TRUE; + const ScAreaLink* pLink = GetLink(nIndex); + if (pLink) + { + aHelpText = pLink->GetFile(); // Source-Datei als Help-Text + bRet = TRUE; + } } } @@ -1151,11 +1152,19 @@ void ScContentTree::DoDrag() ScModule* pScMod = SC_MOD(); - String aText; - USHORT nType = GetCurrentContent( aText ); - if ( nType && nType != SC_CONTENT_NOTE - && nType != SC_CONTENT_AREALINK ) // Notizen und AreaLinks gar nicht + USHORT nType; + ULONG nChild; + SvLBoxEntry* pEntry = GetCurEntry(); + GetEntryIndexes( nType, nChild, pEntry ); + + if( pEntry && + (nChild != SC_CONTENT_NOCHILD) && + (nType != SC_CONTENT_ROOT) && + (nType != SC_CONTENT_NOTE) && + (nType != SC_CONTENT_AREALINK) ) { + String aText( GetEntryText( pEntry ) ); + ScDocument* pLocalDoc = NULL; // fuer URL-Drop String aDocName; if (bHiddenDoc) @@ -1479,39 +1488,51 @@ void ScContentTree::ApplySettings() const ScNavigatorSettings* pSettings = pParentWindow->GetSettings(); if( pSettings ) { - for( USHORT nEntry = 1; nEntry < SC_CONTENT_COUNT; nEntry++ ) + USHORT nRootSel = pSettings->GetRootSelected(); + ULONG nChildSel = pSettings->GetChildSelected(); + + for( USHORT nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry ) { if( pRootNodes[ nEntry ] ) { - if( pSettings->IsExpanded( nEntry ) != IsExpanded( pRootNodes[ nEntry ] ) ) + // expand + BOOL bExp = pSettings->IsExpanded( nEntry ); + if( bExp != IsExpanded( pRootNodes[ nEntry ] ) ) { - if( pSettings->IsExpanded( nEntry ) ) + if( bExp ) Expand( pRootNodes[ nEntry ] ); else Collapse( pRootNodes[ nEntry ] ); } - Select( pRootNodes[ nEntry ], (pSettings->GetSelected() == nEntry) ); + + // select + if( nRootSel == nEntry ) + { + SvLBoxEntry* pEntry = NULL; + if( bExp && (nChildSel != SC_CONTENT_NOCHILD) ) + pEntry = GetEntry( pRootNodes[ nEntry ], nChildSel ); + Select( pEntry ? pEntry : pRootNodes[ nEntry ] ); + } } } } } -void ScContentTree::StoreSettings() +void ScContentTree::StoreSettings() const { ScNavigatorSettings* pSettings = pParentWindow->GetSettings(); if( pSettings ) { - for( USHORT nEntry = 1; nEntry < SC_CONTENT_COUNT; nEntry++ ) + for( USHORT nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry ) { - if( pRootNodes[ nEntry ] ) - { - pSettings->SetExpanded( nEntry, IsExpanded( pRootNodes[ nEntry ] ) ); - if( IsSelected( pRootNodes[ nEntry ] ) ) - pSettings->SetSelected( nEntry ); - } - else - pSettings->SetExpanded( nEntry, FALSE ); + BOOL bExp = pRootNodes[ nEntry ] && IsExpanded( pRootNodes[ nEntry ] ); + pSettings->SetExpanded( nEntry, bExp ); } + USHORT nRoot; + ULONG nChild; + GetEntryIndexes( nRoot, nChild, GetCurEntry() ); + pSettings->SetRootSelected( nRoot ); + pSettings->SetChildSelected( nChild ); } } diff --git a/sc/source/ui/navipi/navipi.cxx b/sc/source/ui/navipi/navipi.cxx index 41a1503b4d05..a7703ff2ab5c 100644 --- a/sc/source/ui/navipi/navipi.cxx +++ b/sc/source/ui/navipi/navipi.cxx @@ -2,9 +2,9 @@ * * $RCSfile: navipi.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: nn $ $Date: 2002-06-03 09:55:40 $ + * last change: $Author: dr $ $Date: 2002-10-16 12:13:04 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -601,17 +601,10 @@ void CommandToolBox::DataChanged( const DataChangedEvent& rDCEvt ) //================================================================== ScNavigatorSettings::ScNavigatorSettings() : - pExpanded( new BOOL[ SC_CONTENT_COUNT ] ), - nSelected( 0 ), - nSubSelected( 0 ) + maExpandedVec( SC_CONTENT_COUNT, FALSE ), + mnRootSelected( SC_CONTENT_ROOT ), + mnChildSelected( SC_CONTENT_NOCHILD ) { - for( USHORT nI = 0; nI < SC_CONTENT_COUNT; ++nI ) - pExpanded[ nI ] = FALSE; -} - -ScNavigatorSettings::~ScNavigatorSettings() -{ - delete[] pExpanded; } //================================================================== |