Skip to content

Commit

Permalink
Merge pull request #11 from ariccio/fix-blank-header-ctrl
Browse files Browse the repository at this point in the history
Fixes #8 (sorting issue)
  • Loading branch information
ariccio committed Nov 9, 2015
2 parents 87481ea + 9c2717d commit 1339892
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 82 deletions.
71 changes: 44 additions & 27 deletions WinDirStat/windirstat/TreeListControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,25 @@ inline INT CTreeListItem::concrete_compare( _In_ const CTreeListItem* const othe
if ( other->m_parent == NULL ) {
return 2;
}

if ( m_parent == other->m_parent ) {
#ifdef DEBUG
ASSERT( ( m_vi && other->m_vi ) || ( (!m_vi) && (!other->m_vi) ) );
if ( m_vi && other->m_vi ) {
ASSERT( m_vi->indent == other->m_vi->indent );
}
else{
ASSERT( ( !m_vi ) && ( !other->m_vi ) );
}
#endif
const auto thisBranch = static_cast< const CTreeListItem* >( this );//ugly, I know
return thisBranch->CompareSibling( other, subitem );
}

const auto my_indent = GetIndent( );
const auto other_indent = other->GetIndent( );

ASSERT( my_indent != other_indent );
if ( my_indent < other_indent ) {
return concrete_compare( other->m_parent, subitem );
}
Expand Down Expand Up @@ -596,38 +609,39 @@ bool CTreeListItem::HasSiblings( ) const {
}

void CTreeListItem::SetVisible( _In_ const bool next_state_visible ) const {
if ( next_state_visible ) {
m_vi.reset( new VISIBLEINFO );
if ( !next_state_visible ) {
ASSERT( m_vi != nullptr );
m_vi.reset( );
return;
}
m_vi.reset( new VISIBLEINFO );
m_vi->isExpanded = false;
if ( m_parent == NULL ) {
m_vi->indent = 0;
m_vi->isExpanded = false;
if ( m_parent == NULL ) {
m_vi->indent = 0;
return;
}
ASSERT( m_parent != NULL );
m_vi->indent = m_parent->GetIndent( ) + 1;
if ( m_attr.compressed ) {
auto uncompressed_size_temp = get_uncompressed_file_size( this );
if ( uncompressed_size_temp == 0 ) {
uncompressed_size_temp = m_size;
}
if ( uncompressed_size_temp == UINT64_ERROR ) {
uncompressed_size_temp = m_size;
}
if ( uncompressed_size_temp != 0 ) {
const auto uncompressed_size = uncompressed_size_temp;
const auto ratio = ( static_cast< const double >( m_size ) / static_cast< const double >( uncompressed_size ) );
m_vi->ntfs_compression_ratio = ratio;
}
else {
ASSERT( m_parent != NULL );
m_vi->indent = m_parent->GetIndent( ) + 1;
if ( m_attr.compressed ) {
auto uncompressed_size_temp = get_uncompressed_file_size( this );
if ( uncompressed_size_temp == 0 ) {
uncompressed_size_temp = m_size;
}
if ( uncompressed_size_temp == UINT64_ERROR ) {
uncompressed_size_temp = m_size;
}
if ( uncompressed_size_temp != 0 ) {
const auto uncompressed_size = uncompressed_size_temp;
const auto ratio = ( static_cast< const double >( m_size ) / static_cast< const double >( uncompressed_size ) );
m_vi->ntfs_compression_ratio = ratio;
}
else {
m_vi->ntfs_compression_ratio = 1;
}
}
m_vi->ntfs_compression_ratio = 1;
}
m_vi->isExpanded = false;
return;
}
ASSERT( m_vi != nullptr );
m_vi.reset( );
m_vi->isExpanded = false;
return;
}

std::wstring CTreeListItem::GetPath( ) const {
Expand Down Expand Up @@ -1892,9 +1906,12 @@ void CTreeListControl::ExpandItem( _In_ _In_range_( 0, INT_MAX ) const int i, _I

item->SortChildren( this );


TRACE( _T( "Setting redraw FALSE\r\n" ) );
CWnd::SetRedraw( FALSE );
ExpandItemInsertChildren( item, i, scroll );
CWnd::SetRedraw( TRUE );
TRACE( _T( "Setting redraw TRUE\r\n" ) );

item->SetExpanded( true );

Expand Down
3 changes: 2 additions & 1 deletion WinDirStat/windirstat/datastructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ enum class Treemap_STYLE {
namespace UpdateAllViews_ENUM {
// Hints for UpdateAllViews()
enum {
HINT_NULL, // General update
HINT_NULL, // General update (passed by CView::OnInitialUpdate( ))
HINT_NEWROOT, // Root item has changed - clear everything.
HINT_SELECTIONCHANGED, // The selection has changed, EnsureVisible.
HINT_SHOWNEWSELECTION, // The selection has changed, Show Path
Expand All @@ -124,6 +124,7 @@ namespace UpdateAllViews_ENUM {
HINT_LISTSTYLECHANGED, // Options: List style (grid/stripes) or treelist colors changed
HINT_TREEMAPSTYLECHANGED, // Options: Treemap style (grid, colors etc.) changed
};
static_assert( HINT_NULL == 0, "CView::OnInitialUpdate( ) passes 0, should be equal to HINT_NULL" );

}

Expand Down
26 changes: 20 additions & 6 deletions WinDirStat/windirstat/directory_enumeration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,17 @@ namespace {
}

_Success_( return < UINT64_ERROR )
const std::uint64_t get_uncompressed_file_size( const std::wstring path ) {
const std::uint64_t get_uncompressed_file_size( const std::wstring path, const bool inside_assert ) {
const HANDLE file_handle = CreateFileW( path.c_str( ), ( FILE_READ_ATTRIBUTES bitor FILE_READ_EA ), ( FILE_SHARE_READ bitor FILE_SHARE_WRITE ), NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
if ( file_handle == INVALID_HANDLE_VALUE ) {


//So that we don't create two log messages inside an assert
//assumes that assert is like:
// ASSERT( get_uncompressed_file_size( some_folder_path, true ) == UINT64_ERROR );
//...which will fail.
if ( inside_assert ) {
return UINT64_ERROR;
}
const rsize_t str_size = 128u;
wchar_t str_buff[ str_size ] = { 0 };
rsize_t chars_written = 0;
Expand Down Expand Up @@ -961,17 +968,24 @@ WDS_DECLSPEC_NOTHROW bool DoSomeWork( _In_ CTreeListItem* const ThisCItem, std::
}

_Success_( return < UINT64_ERROR )
WDS_DECLSPEC_NOTHROW const std::uint64_t get_uncompressed_file_size( const CTreeListItem* const item ) {
WDS_DECLSPEC_NOTHROW const std::uint64_t get_uncompressed_file_size( _In_ const CTreeListItem* const item ) {
const auto derived_item = static_cast< const CTreeListItem* const >( item );

if ( derived_item->m_child_info.m_child_info_ptr != nullptr ) {
TRACE( _T( "It looks like item `%s` has children, we can skip querying compressed file size.\r\n" ), derived_item->GetPath( ).c_str( ) );
const std::wstring path( derived_item->GetPath( ) );
ASSERT( get_uncompressed_file_size( path.c_str( ), true ) == UINT64_ERROR );
return UINT64_ERROR;
}

std::wstring path_holder( derived_item->GetPath( ) );

auto strcmp_path = path_holder.compare( 0, 4, L"\\\\?\\", 0, 4 );
const auto strcmp_path = path_holder.compare( 0, 4, L"\\\\?\\", 0, 4 );
if ( strcmp_path != 0 ) {
path_holder = ( L"\\\\?\\" + path_holder );
}

return get_uncompressed_file_size( std::move( path_holder ) );

return get_uncompressed_file_size( std::move( path_holder ), false );
}

#ifdef WDS_DIRECTORY_ENUMERATION_PUSHED_MACRO_NEW
Expand Down
2 changes: 1 addition & 1 deletion WinDirStat/windirstat/directory_enumeration.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ std::pair<DOUBLE, bool> DoSomeWorkShim ( _Inout_ CTreeListItem


_Success_( return < UINT64_ERROR )
const std::uint64_t get_uncompressed_file_size( const CTreeListItem* const item );
const std::uint64_t get_uncompressed_file_size( _In_ const CTreeListItem* const item );

#else

Expand Down
11 changes: 11 additions & 0 deletions WinDirStat/windirstat/dirstatview.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,19 @@ class CDirstatView final : public CView {
}

virtual void OnInitialUpdate( ) override final {
/*
void CView::OnInitialUpdate()
{
OnUpdate(NULL, 0, NULL); // initial update
}
*/

//OnUpdate(NULL, 0, NULL) calls CGraphView::OnUpdate
//also CDirstatView::OnUpdate?

CView::OnInitialUpdate( );
}
//Called by CView::OnPaint
virtual void OnDraw( CDC* pDC ) override final {
ASSERT_VALID( pDC );
CView::OnDraw( pDC );
Expand Down
7 changes: 7 additions & 0 deletions WinDirStat/windirstat/graphview.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ public: \
}

virtual void OnInitialUpdate( ) override final {
/*
void CView::OnInitialUpdate()
{
OnUpdate(NULL, 0, NULL); // initial update
}
*/
//OnUpdate(NULL, 0, NULL) calls CGraphView::OnUpdate
CView::OnInitialUpdate( );
}

Expand Down
16 changes: 8 additions & 8 deletions WinDirStat/windirstat/ownerdrawnlistcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ class COwnerDrawnListItem {


INT CompareS( _In_ const COwnerDrawnListItem* const other, _In_ const SSorting& sorting ) const {
if ( sorting.column1 == column::COL_NAME ) {
#pragma warning( suppress: 4711 )//C4711: function 'int __cdecl signum<int>(int)' selected for automatic inline expansion
const auto sort_result = signum( wcscmp( m_name, other->m_name ) );

if ( sort_result != 0 ) {
return sort_result;
}
}
// if ( sorting.column1 == column::COL_NAME ) {
//#pragma warning( suppress: 4711 )//C4711: function 'int __cdecl signum<int>(int)' selected for automatic inline expansion
// const auto sort_result = signum( wcscmp( m_name, other->m_name ) );
//
// if ( sort_result != 0 ) {
// return sort_result;
// }
// }

auto r_1 = compare_interface( other, sorting.column1 );
if ( abs( r_1 ) < 2 && !sorting.ascending1 ) {
Expand Down
8 changes: 8 additions & 0 deletions WinDirStat/windirstat/typeview.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,18 @@ class CTypeView final : public CView {
BOOL g_fRedrawEnabled;

virtual void OnInitialUpdate( ) override final {
/*
void CView::OnInitialUpdate()
{
OnUpdate(NULL, 0, NULL); // initial update
}
*/
//OnUpdate(NULL, 0, NULL) calls CTypeView::OnUpdate
CView::OnInitialUpdate( );
}
virtual void OnUpdate ( CView* pSender, LPARAM lHint, CObject* pHint ) override final;

//Called by CView::OnPaint
virtual void OnDraw( CDC* pDC ) override final {
ASSERT_VALID( pDC );
CView::OnDraw( pDC );
Expand Down
41 changes: 2 additions & 39 deletions WinDirStat/windirstat/windirstat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,58 +405,21 @@ void CDirstatApp::OnFileOpen( ) {
if ( !( path_str.empty( ) ) ) {
m_pDocTemplate->OpenDocumentFile( path_str.c_str( ), true );
}

//CSelectDrivesDlg dlg;
//if ( IDOK == dlg.DoModal( ) ) {
// //ASSERT( dlg.m_folder_name_heap == dlg.m_folderName.GetString( ) );
// const auto path = EncodeSelection( static_cast<RADIO>( dlg.m_radio ), dlg.m_folder_name_heap.c_str( ), dlg.m_drives );
// if ( path.find( '|' ) == std::wstring::npos ) {
// m_pDocTemplate->OpenDocumentFile( path.c_str( ), true );
// }
// }
}

void CDirstatApp::OnFileOpenLight( ) {
/*
// const UINT flags = ( BIF_RETURNONLYFSDIRS bitor BIF_USENEWUI bitor BIF_NONEWFOLDERBUTTON );
// WTL::CFolderDialog bob { NULL, global_strings::select_folder_dialog_title_text, flags };
// //ASSERT( m_folder_name_heap.compare( m_folderName ) == 0 );
// bob.SetInitialFolder( m_folder_name_heap.c_str( ) );
// auto resDoModal = bob.DoModal( );
// if ( resDoModal == IDOK ) {
// m_folder_name_heap = bob.GetFolderPath( );
// //m_folderName = m_folder_name_heap.c_str( );
// //ASSERT( m_folder_name_heap.compare( m_folderName ) == 0 );
// TRACE( _T( "User chose: %s\r\n" ), m_folder_name_heap.c_str( ) );
// }
// else {
// TRACE( _T( "user hit cancel - no changes necessary.\r\n" ) );
// }
*/
const UINT flags = ( BIF_RETURNONLYFSDIRS bitor BIF_USENEWUI bitor BIF_NONEWFOLDERBUTTON );
WTL::CFolderDialog bob { NULL, global_strings::select_folder_dialog_title_text, flags };
//ASSERT( m_folder_name_heap.compare( m_folderName ) == 0 );
auto resDoModal = bob.DoModal( );
if ( resDoModal == IDOK ) {
PCWSTR const m_folder_name_heap( bob.GetFolderPath( ) );
if ( wcslen( m_folder_name_heap ) > 0 ) {

//Here, calls CSingleDocTemplate::OpenDocumentFile (in docsingl.cpp)
m_pDocTemplate->OpenDocumentFile( m_folder_name_heap, TRUE );
}
}
//const auto path_str = test_file_open( );
//if ( !( path_str.empty( ) ) ) {
// m_pDocTemplate->OpenDocumentFile( path_str.c_str( ), true );
// }

//CSelectDrivesDlg dlg;
//if ( IDOK == dlg.DoModal( ) ) {
// //ASSERT( dlg.m_folder_name_heap == dlg.m_folderName.GetString( ) );
// const auto path = EncodeSelection( static_cast<RADIO>( dlg.m_radio ), dlg.m_folder_name_heap.c_str( ), dlg.m_drives );
// if ( path.find( '|' ) == std::wstring::npos ) {
// m_pDocTemplate->OpenDocumentFile( path.c_str( ), true );
// }
// }
}

BOOL CDirstatApp::OnIdle( _In_ LONG lCount ) {
Expand Down

0 comments on commit 1339892

Please sign in to comment.