Skip to content

Commit

Permalink
fixed fucking bug with goddamned context menu.
Browse files Browse the repository at this point in the history
Did I ever mention that I hate MFC?
  • Loading branch information
ariccio committed Jan 31, 2015
1 parent 00abc98 commit 639fefc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
33 changes: 15 additions & 18 deletions WinDirStat/windirstat/TreeListControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ namespace
NODE_LINE
};
const LONG NODE_WIDTH = 15; // Width of a node within IDB_NODES

const LONG INDENT_WIDTH = 18;

const LONG HOTNODE_CX = 9; // Size and position of the +/- buttons
const LONG HOTNODE_CY = 9;
const LONG HOTNODE_X = 0;
Expand Down Expand Up @@ -155,17 +153,11 @@ void CTreeListItem::SortChildren( ) {

const auto thisBranch = static_cast<const CItemBranch* >( this );

//auto children_vec = thisBranch->size_sorted_vector_of_children( );
//m_vi->cache_sortedChildren = std::move( children_vec );

m_vi->cache_sortedChildren = thisBranch->size_sorted_vector_of_children( );

if ( !m_vi->cache_sortedChildren.empty( ) ) {
//qsort( m_vi->cache_sortedChildren.data( ), m_vi->cache_sortedChildren.size( ) -1, sizeof( CTreeListItem * ), &_compareProc_orig );

std::sort( m_vi->cache_sortedChildren.begin( ), m_vi->cache_sortedChildren.end( ), &_compareProc2 );
////std::sort( m_vi->cache_sortedChildren.begin( ), m_vi->cache_sortedChildren.end( ), TreeListItemSortStruct( ) );
//m_vi->cache_sortedChildren.shrink_to_fit( );
}
}

Expand All @@ -175,6 +167,7 @@ bool CTreeListItem::_compareProc2( const CTreeListItem* const lhs, const CTreeLi
}

std::uint64_t CTreeListItem::size_recurse_( ) const {
static_assert( std::is_same<decltype( std::declval<CTreeListItem>( ).size_recurse_( ) ), decltype( std::declval<CItemBranch>( ).size_recurse( ) )>::value , "The return type of CTreeListItem::size_recurse_ needs to be fixed!!" );
return static_cast< const CItemBranch* >( this )->size_recurse( );
}

Expand All @@ -184,14 +177,11 @@ std::uint32_t CTreeListItem::GetChildrenCount_( ) const {
return static_cast< const CItemBranch* >( this )->m_childCount;
}



_Ret_maybenull_
CItemBranch* CTreeListItem::children_ptr( ) const {
return static_cast< const CItemBranch* >( this )->m_children.get( );
}


_Success_( return != NULL ) _Must_inspect_result_ _Ret_maybenull_
CTreeListItem* CTreeListItem::GetSortedChild( _In_ const size_t i ) const {
ASSERT( m_vi != nullptr );
Expand Down Expand Up @@ -364,7 +354,7 @@ void CTreeListControl::expand_item_no_scroll_then_doWhateverJDoes( _In_ const CT
}
}

void CTreeListControl::pathZeroNotNull( _In_ const CTreeListItem* const pathZero, _In_range_( 0, INT_MAX ) const int index, _In_ const bool showWholePath ) {
void CTreeListControl::expand_item_then_scroll_to_it( _In_ const CTreeListItem* const pathZero, _In_range_( 0, INT_MAX ) const int index, _In_ const bool showWholePath ) {
expand_item_no_scroll_then_doWhateverJDoes( pathZero, index );
ASSERT( index != -1 );
//void adjustColumnSize( CTreeListItem* item_at_index )
Expand All @@ -379,7 +369,7 @@ void CTreeListControl::pathZeroNotNull( _In_ const CTreeListItem* const pathZero
SelectItem( index );
}

void CTreeListControl::thisPathNotNull( _In_ const CTreeListItem* const thisPath, const int i, int& parent, _In_ const bool showWholePath, _In_ const CTreeListItem* const target_item_in_path ) {
void CTreeListControl::find_item_then_show( _In_ const CTreeListItem* const thisPath, const int i, int& parent, _In_ const bool showWholePath, _In_ const CTreeListItem* const target_item_in_path ) {
//auto index = FindTreeItem( thisPath );
auto index = FindListItem( thisPath );
if ( index == -1 ) {
Expand Down Expand Up @@ -410,7 +400,7 @@ void CTreeListControl::thisPathNotNull( _In_ const CTreeListItem* const thisPath
if ( target_item_in_path != NULL ) {
//if target_item_in_path is found, then we expand (the item?), adjust the name column width, and scroll to it.
if ( index != -1 ) {
pathZeroNotNull( target_item_in_path, index, showWholePath );
expand_item_then_scroll_to_it( target_item_in_path, index, showWholePath );
}
}
}
Expand Down Expand Up @@ -608,7 +598,7 @@ void CTreeListControl::SelectAndShowItem( _In_ const CTreeListItem* const item,
const auto thisPath = path.at( static_cast<size_t>( i ) );
if ( thisPath != NULL ) {
ASSERT( static_cast<std::uint64_t>( i ) < INT_MAX );
thisPathNotNull( thisPath, static_cast<int>( i ), parent, showWholePath, path.at( 0 ) );
find_item_then_show( thisPath, static_cast<int>( i ), parent, showWholePath, path.at( 0 ) );
}
ASSERT( thisPath != NULL );
}
Expand Down Expand Up @@ -770,7 +760,8 @@ void CTreeListControl::PrepareDefaultMenu( _In_ const CItemBranch* const item, _
VERIFY( menu->DeleteMenu( 0, MF_BYPOSITION ) ); // Remove separator
}
else {
const auto command = MAKEINTRESOURCEW( item->IsExpanded( ) && item->HasChildren( ) ? IDS_COLLAPSE : IDS_EXPAND );
//const auto command = MAKEINTRESOURCEW( item->IsExpanded( ) && item->HasChildren( ) ? IDS_COLLAPSE : IDS_EXPAND );
const auto command = ( item->IsExpanded( ) && item->HasChildren( ) ? L"Co&llapse" : L"E&xpand" );
VERIFY( menu->ModifyMenuW( ID_POPUP_TOGGLE, MF_BYCOMMAND | MF_STRING, ID_POPUP_TOGGLE, command ) );
VERIFY( menu->SetDefaultItem( ID_POPUP_TOGGLE, false ) );
}
Expand Down Expand Up @@ -811,9 +802,11 @@ CTreeListItem* CTreeListControl::GetItem( _In_ _In_range_( 0, INT_MAX ) const in
void CTreeListControl::SetRootItem( _In_opt_ const CTreeListItem* const root ) {
VERIFY( DeleteAllItems( ) );
if ( root != NULL ) {
SetRedraw( FALSE );
InsertItem( root, 0 );
//ExpandItem( static_cast<int>( 0 ), true );//otherwise ambiguous call - is it a NULL pointer?
ExpandItemAndScroll( static_cast<int>( 0 ) );//otherwise ambiguous call - is it a NULL pointer?
SetRedraw( TRUE );
}
}

Expand Down Expand Up @@ -937,12 +930,14 @@ void CTreeListControl::ToggleExpansion( _In_ _In_range_( 0, INT_MAX ) const INT
const auto item_at_i = GetItem( i );
ASSERT( item_at_i != NULL );
if ( item_at_i != NULL ) {
SetRedraw( FALSE );
if ( item_at_i->IsExpanded( ) ) {
VERIFY( CollapseItem( i ) );
return;
}
//ExpandItem( i, true );
ExpandItemAndScroll( i );
SetRedraw( TRUE );
}
}

Expand Down Expand Up @@ -1125,7 +1120,7 @@ void CTreeListControl::ExpandItem( _In_ _In_range_( 0, INT_MAX ) const int i, _I
}

WTL::CWaitCursor wc; // TODO: smart WaitCursor. In CollapseItem(), too.
SetRedraw( FALSE );
//SetRedraw( FALSE );
//LockWindowUpdate( );
#ifdef PERF_DEBUG_SLEEP
Sleep( 1000 );
Expand Down Expand Up @@ -1178,7 +1173,7 @@ void CTreeListControl::ExpandItem( _In_ _In_range_( 0, INT_MAX ) const int i, _I
//static cast to int is safe here, range of i should never be more than INT32_MAX
VERIFY( EnsureVisible( static_cast<int>( i ), false ) );
}
SetRedraw( TRUE );
//SetRedraw( TRUE );
}

void CTreeListControl::handle_VK_LEFT( _In_ const CTreeListItem* const item, _In_ _In_range_( 0, INT32_MAX ) const int i ) {
Expand All @@ -1195,7 +1190,9 @@ void CTreeListControl::handle_VK_LEFT( _In_ const CTreeListItem* const item, _In
void CTreeListControl::handle_VK_RIGHT( _In_ const CTreeListItem* const item, _In_ _In_range_( 0, INT_MAX ) const int i ) {
if ( !item->IsExpanded( ) ) {
//ExpandItem( i, true );
SetRedraw( FALSE );
ExpandItemAndScroll( i );
SetRedraw( TRUE );
}
else if ( item->GetChildrenCount_( ) > 0 ) {
const auto sortedItemAtZero = item->GetSortedChild( 0 );
Expand Down
4 changes: 2 additions & 2 deletions WinDirStat/windirstat/TreeListControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ class CTreeListControl final : public COwnerDrawnListCtrl {
void OnChildAdded ( _In_opt_ const CTreeListItem* const parent, _In_ CTreeListItem* const child, _In_ const bool isDone );
INT GetItemScrollPosition ( _In_ const CTreeListItem* const item ) const;
int EnumNode ( _In_ const CTreeListItem* const item ) const;
void thisPathNotNull ( _In_ const CTreeListItem* const thisPath, const int i, int& parent, _In_ const bool showWholePath, _In_ const CTreeListItem* const target_item_in_path );
void pathZeroNotNull ( _In_ const CTreeListItem* const pathZero, _In_range_( 0, INT_MAX ) const int index, _In_ const bool showWholePath );
void find_item_then_show ( _In_ const CTreeListItem* const thisPath, const int i, int& parent, _In_ const bool showWholePath, _In_ const CTreeListItem* const target_item_in_path );
void expand_item_then_scroll_to_it ( _In_ const CTreeListItem* const pathZero, _In_range_( 0, INT_MAX ) const int index, _In_ const bool showWholePath );
void expand_item_no_scroll_then_doWhateverJDoes ( _In_ const CTreeListItem* const pathZero, _In_range_( 0, INT_MAX ) const int parent );
void handle_VK_RIGHT ( _In_ const CTreeListItem* const item, _In_ _In_range_( 0, INT_MAX ) const int i );
void adjustColumnSize ( _In_ const CTreeListItem* const item_at_index );
Expand Down
2 changes: 1 addition & 1 deletion WinDirStat/windirstat/globalhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ void FormatVolumeName( _In_ const std::wstring& rootPath, _In_z_ PCWSTR volumeNa
#pragma strict_gs_check(push, on)
_Success_( SUCCEEDED( return ) ) HRESULT GetFullPathName_WriteToStackBuffer( _In_z_ PCWSTR relativePath, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_full_path, _In_range_( 128, 512 ) const DWORD strSize, _Out_ rsize_t& chars_written ) {
const DWORD dw = GetFullPathNameW( relativePath, strSize, psz_full_path, NULL );
ASSERT( dw >= 0 );
//ASSERT( dw >= 0 );
if ( dw == 0 ) {
static_assert( !SUCCEEDED( E_FAIL ), "" );
return E_FAIL;
Expand Down
1 change: 1 addition & 0 deletions WinDirStat/windirstat/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ void CItemBranch::refresh_sizeCache( ) const {

_Ret_range_( 0, UINT64_MAX )
std::uint64_t CItemBranch::size_recurse( ) const {
static_assert( std::is_same<decltype( std::declval<CItemBranch>( ).size_recurse( ) ), decltype( std::declval<CItemBranch>( ).m_size )>::value , "The return type of CItemBranch::size_recurse needs to be fixed!!" );
//if ( m_type == IT_FILE ) {
if ( !m_children ) {
ASSERT( m_childCount == 0 );
Expand Down

0 comments on commit 639fefc

Please sign in to comment.