Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ariccio committed Jan 29, 2015
1 parent 6d5d329 commit 0fa4f19
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 64 deletions.
Binary file modified WinDirStat/altWinDirStat.smproj
Binary file not shown.
6 changes: 3 additions & 3 deletions WinDirStat/windirstat/TreeListControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,10 +837,11 @@ void CTreeListControl::insertItemsAdjustWidths( _In_ const CTreeListItem* const
for ( size_t c = 0; c < count; c++ ) {
ASSERT( count == item->GetChildrenCount_( ) );
const auto child = item->GetSortedChild( c );//m_vi->cache_sortedChildren[i];
ASSERT( child != NULL );
if ( child != NULL ) {
InsertItem( child, i + static_cast<INT_PTR>( 1 ) + static_cast<INT_PTR>( c ) );
if ( scroll ) {
const auto w = GetSubItemWidth( child, column::COL_NAME );//does drawing???
const auto w = GetSubItemWidth( child, column::COL_NAME );
if ( w > maxwidth ) {
ASSERT( w >= 0 );
if ( w >= 0 ) {
Expand All @@ -849,7 +850,6 @@ void CTreeListControl::insertItemsAdjustWidths( _In_ const CTreeListItem* const
}
}
}
ASSERT( child != NULL );
}
ASSERT( maxwidth >= 0 );
if ( maxwidth < 0 ) {
Expand Down Expand Up @@ -878,7 +878,7 @@ void CTreeListControl::ExpandItemInsertChildren( _In_ const CTreeListItem* const
const auto count = item->GetChildrenCount_( );
const auto myCount = static_cast<size_t>( GetItemCount( ) );
TRACE( _T( "Expanding %s! Must insert %i items!\r\n" ), item->m_name.get( ), count );
SetItemCount( static_cast<INT>( ( count >= myCount) ? count + 1 : myCount + 1 ) );
SetItemCount( static_cast<INT>( ( count >= myCount) ? ( count + 1 ) : ( myCount + 1 ) ) );

insertItemsAdjustWidths( item, count, maxwidth, scroll, i );

Expand Down
106 changes: 62 additions & 44 deletions WinDirStat/windirstat/ownerdrawnlistcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,18 @@ namespace {
}
}

void second_try_failed( _In_ const column::ENUM_COL subitem, _In_ const rsize_t sizeNeeded, _In_ const rsize_t new_size_needed ) {
displayWindowsMsgBoxWithMessage( L"COwnerDrawnListCtrl::GetSubItemWidth, second try of `item->GetText_WriteToStackBuffer` failed!!(aborting)" );
std::wstring err_str;
err_str += L"DEBUGGING INFO: subitem: ";
err_str += std::to_wstring( subitem );
err_str += L", size of buffer in characters: ";
err_str += std::to_wstring( sizeNeeded );
err_str += L", returned size needed: ";
err_str += std::to_wstring( new_size_needed );
displayWindowsMsgBoxWithMessage( err_str.c_str( ) );
}

}


Expand Down Expand Up @@ -995,6 +1007,7 @@ class COwnerDrawnListCtrl : public CListCtrl {
ASSERT( subitem != column::COL_NAME );
const HRESULT res = item->GetText_WriteToStackBuffer( subitem, buffer.get( ), size_needed, new_size_needed, chars_written );
if ( !SUCCEEDED( res ) ) {

displayWindowsMsgBoxWithMessage( L"COwnerDrawnListCtrl::DrawText_dynamic failed!!(aborting)" );
std::wstring err_str;
err_str += L"DEBUGGING INFO: subitem: ";
Expand Down Expand Up @@ -1053,33 +1066,69 @@ class COwnerDrawnListCtrl : public CListCtrl {
}

protected:

INT first_try_failed( _In_ const COwnerDrawnListItem* const item, _In_ _In_range_( 0, INT_MAX ) const column::ENUM_COL subitem, _In_ CHeaderCtrl* const thisHeaderCtrl, _In_ RECT& rc, _In_ CClientDC& dc, _In_ const rsize_t sizeNeeded ) const {
ASSERT( sizeNeeded < 33000 );
std::unique_ptr<_Null_terminated_ wchar_t[ ]> buffer( std::make_unique<_Null_terminated_ wchar_t[ ]>( sizeNeeded + 2 ) );
SecureZeroMemory( buffer.get( ), ( ( sizeNeeded + 2 ) * sizeof( wchar_t ) ) );

rsize_t new_size_needed = 0;
rsize_t chars_written_2 = 0;
ASSERT( subitem != column::COL_NAME );
const HRESULT res_2 = item->GetText_WriteToStackBuffer( subitem, buffer.get( ), sizeNeeded, new_size_needed, chars_written_2 );
if ( !SUCCEEDED( res_2 ) ) {
second_try_failed( subitem, sizeNeeded, new_size_needed );
abort( );
}
if ( chars_written_2 == 0 ) {
return 0;
}
CSelectObject sofont( dc, *( GetFont( ) ) );
const auto align = IsColumnRightAligned( subitem, thisHeaderCtrl ) ? DT_RIGHT : DT_LEFT;
dc.DrawTextW( buffer.get( ), static_cast<int>( chars_written_2 ), &rc, DT_SINGLELINE | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX | DT_NOCLIP | static_cast<UINT>( align ) );

::InflateRect( &rc, TEXT_X_MARGIN, 0 );
//rc.InflateRect( TEXT_X_MARGIN, 0 );

return ( rc.right - rc.left );

}

INT GetWidthFastPath( _In_ const COwnerDrawnListItem* const item, _In_ _In_range_( 0, INT_MAX ) const column::ENUM_COL subitem, _In_ CHeaderCtrl* const thisHeaderCtrl, _In_ RECT& rc, _In_ CClientDC& dc ) const {
//column::COL_NAME requires very little work!
if ( item->m_name_length == 0 ) {
return 0;
}
CSelectObject sofont( dc, *( GetFont( ) ) );
const auto align = IsColumnRightAligned( subitem, thisHeaderCtrl ) ? DT_RIGHT : DT_LEFT;
dc.DrawTextW( item->m_name.get( ), static_cast<int>( item->m_name_length ), &rc, DT_SINGLELINE | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX | DT_NOCLIP | static_cast<UINT>( align ) );

::InflateRect( &rc, TEXT_X_MARGIN, 0 );
//rc.InflateRect( TEXT_X_MARGIN, 0 );
return ( rc.right - rc.left );
}

_Success_( return >= 0 ) _Ret_range_( 0, INT_MAX ) _On_failure_( _Ret_range_( -1, -1 ) )
INT GetSubItemWidth( _In_ const COwnerDrawnListItem* const item, _In_ _In_range_( 0, INT_MAX ) const column::ENUM_COL subitem ) const {
if ( item == NULL ) {
return -1;
}
INT width = 0;
const auto thisHeaderCtrl = GetHeaderCtrl( );

CClientDC dc( const_cast< COwnerDrawnListCtrl* >( this ) );
RECT rc { 0, 0, 1000, 1000 };

INT dummy = rc.left;
//it appears that if the item draws itself, then we must ask it to do so in order to find out how wide it is.
//TODO: find a better way to do this!
//BUGBUG: this is an extremely slow way of doing this!
if ( item->DrawSubitem_( subitem, dc, rc, 0, &width, &dummy ) ) {
return width;
}

const auto thisHeaderCtrl = GetHeaderCtrl( );
if ( subitem == column::COL_NAME ) {
//column::COL_NAME requires very little work!
if ( item->m_name_length == 0 ) {
return 0;
}
CSelectObject sofont( dc, *( GetFont( ) ) );
const auto align = IsColumnRightAligned( subitem, thisHeaderCtrl ) ? DT_RIGHT : DT_LEFT;
dc.DrawTextW( item->m_name.get( ), static_cast<int>( item->m_name_length ), &rc, DT_SINGLELINE | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX | DT_NOCLIP | static_cast<UINT>( align ) );

::InflateRect( &rc, TEXT_X_MARGIN, 0 );
//rc.InflateRect( TEXT_X_MARGIN, 0 );
return ( rc.right - rc.left );
return GetWidthFastPath( item, subitem, thisHeaderCtrl, rc, dc );
}


Expand All @@ -1091,38 +1140,7 @@ class COwnerDrawnListCtrl : public CListCtrl {
ASSERT( subitem != column::COL_NAME );
const HRESULT res_1 = item->GetText_WriteToStackBuffer( subitem, psz_subitem_formatted_text, subitem_text_size, sizeNeeded, chars_written );
if ( !SUCCEEDED( res_1 ) ) {
ASSERT( sizeNeeded < 33000 );
std::unique_ptr<_Null_terminated_ wchar_t[ ]> buffer( std::make_unique<_Null_terminated_ wchar_t[ ]>( sizeNeeded + 2 ) );
SecureZeroMemory( buffer.get( ), ( ( sizeNeeded + 2 ) * sizeof( wchar_t ) ) );

rsize_t new_size_needed = 0;
rsize_t chars_written_2 = 0;
ASSERT( subitem != column::COL_NAME );
const HRESULT res_2 = item->GetText_WriteToStackBuffer( subitem, buffer.get( ), sizeNeeded, new_size_needed, chars_written_2 );
if ( !SUCCEEDED( res_2 ) ) {
displayWindowsMsgBoxWithMessage( L"COwnerDrawnListCtrl::GetSubItemWidth, second try of `item->GetText_WriteToStackBuffer` failed!!(aborting)" );
std::wstring err_str;
err_str += L"DEBUGGING INFO: subitem: ";
err_str += std::to_wstring( subitem );
err_str += L", size of buffer in characters: ";
err_str += std::to_wstring( sizeNeeded );
err_str += L", returned size needed: ";
err_str += std::to_wstring( new_size_needed );
displayWindowsMsgBoxWithMessage( err_str.c_str( ) );

abort( );
}
if ( chars_written_2 == 0 ) {
return 0;
}
CSelectObject sofont( dc, *( GetFont( ) ) );
const auto align = IsColumnRightAligned( subitem, thisHeaderCtrl ) ? DT_RIGHT : DT_LEFT;
dc.DrawTextW( buffer.get( ), static_cast<int>( chars_written_2 ), &rc, DT_SINGLELINE | DT_VCENTER | DT_CALCRECT | DT_NOPREFIX | DT_NOCLIP | static_cast<UINT>( align ) );

::InflateRect( &rc, TEXT_X_MARGIN, 0 );
//rc.InflateRect( TEXT_X_MARGIN, 0 );

return ( rc.right - rc.left );
return first_try_failed( item, subitem, thisHeaderCtrl, rc, dc, sizeNeeded );
}

if ( chars_written == 0 ) {
Expand Down
25 changes: 10 additions & 15 deletions WinDirStat/windirstat/treemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,17 @@ class CTreemap {
if ( num_times_heap__used > 0 ) {
TRACE( _T( "typeview used the heap\r\n" ) );
}
return;
}
else {
TRACE( _T( "number of times DrawCushion used stack: %I64u\r\n" ), std::uint64_t( num_times_stack_used ) );
TRACE( _T( "number of times DrawCushion used heap : %I64u\r\n" ), std::uint64_t( num_times_heap__used ) );
if ( ( stack_v_total != 1 ) && ( stack_size_av > 0 ) ) {
TRACE( _T( "percent of stack uses vs. total : %f\r\n" ), stack_v_total );
}
if ( ( heap__v_total != 1 ) && ( heap__size_av > 0 ) ) {
TRACE( _T( "percent of heap uses vs. total : %f\r\n" ), heap__v_total );
}
if ( heap__size_av > 0 ) {
TRACE( _T( "average size of heap allocation : %f\r\n" ), heap__size_av );
}
if ( stack_size_av > 0 ){
TRACE( _T( "average size of stack allocation : %f\r\n" ), stack_size_av );
}
TRACE( _T( "number of times DrawCushion used stack: %I64u\r\n" ), std::uint64_t( num_times_stack_used ) );
TRACE( _T( "number of times DrawCushion used heap : %I64u\r\n" ), std::uint64_t( num_times_heap__used ) );
if ( ( stack_v_total != 1 ) && ( stack_size_av > 0 ) ) {
TRACE( _T( "percent of stack uses vs. total : %f\r\n" ), stack_v_total );
TRACE( _T( "average size of stack allocation : %f\r\n" ), stack_size_av );
}
if ( ( heap__v_total != 1 ) && ( heap__size_av > 0 ) ) {
TRACE( _T( "percent of heap uses vs. total : %f\r\n" ), heap__v_total );
TRACE( _T( "average size of heap allocation : %f\r\n" ), heap__size_av );
}
}
#else
Expand Down
4 changes: 2 additions & 2 deletions WinDirStat/windirstat/windirstat.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalOptions>/Gw /Bt+ /Qvec-report:2 /Zo</AdditionalOptions>
<AdditionalOptions>/Gw /Bt+ /Qvec-report:2 /Zo /Zc:inline</AdditionalOptions>
<StringPooling>true</StringPooling>
<EnableParallelCodeGeneration>false</EnableParallelCodeGeneration>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
Expand Down Expand Up @@ -526,7 +526,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>EnableAllWarnings</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalOptions>/Gw /Bt+ /Qvec-report:2 /Zo</AdditionalOptions>
<AdditionalOptions>/Gw /Bt+ /Qvec-report:2 /Zo /Zc:inline</AdditionalOptions>
<StringPooling>true</StringPooling>
<EnableParallelCodeGeneration>false</EnableParallelCodeGeneration>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
Expand Down

0 comments on commit 0fa4f19

Please sign in to comment.