Skip to content

Commit

Permalink
CPreview now uses ATL, COwnerDrawnListItem string
Browse files Browse the repository at this point in the history
COwnerDrawnListItem now block allocates names for child strings.
  • Loading branch information
ariccio committed Feb 21, 2015
1 parent 1837212 commit e3ede6e
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 102 deletions.
39 changes: 25 additions & 14 deletions WinDirStat/windirstat/SelectDrivesDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ namespace {
UINT WMU_THREADFINISHED = RegisterWindowMessageW( _T( "{F03D3293-86E0-4c87-B559-5FD103F5AF58}" ) );

const rsize_t volume_name_size = ( MAX_PATH + 1u );
const rsize_t max_number_of_named_drives = 32u;
const rsize_t volume_name_pool_size = ( volume_name_size * max_number_of_named_drives );


std::tuple<bool, PWSTR, std::uint64_t, std::uint64_t> RetrieveDriveInformation_GetVolumeName_succeeded( _In_ const std::wstring path, _In_ _Null_terminated_ wchar_t( &volume_name )[ volume_name_size ], _Inout_ _Pre_writable_size_( volume_name_size ) PWSTR formatted_volume_name ) {
std::uint64_t total = 0;
std::uint64_t free = 0;
Expand Down Expand Up @@ -50,21 +54,25 @@ namespace {
thisDriveItem->m_used = 0;
}

void SetDriveInformation_copy_name_and_set_m_used( _In_ CDriveItem* const thisDriveItem, _In_ const std::wstring name ) {
void SetDriveInformation_copy_name_and_set_m_used( _In_ CDriveItem* const thisDriveItem, _In_ const std::wstring name, _In_ Children_String_Heap_Manager* name_pool ) {

ASSERT( name.length( ) < UINT16_MAX );
const auto new_name_length = static_cast<std::uint16_t>( name.length( ) );

PWSTR new_name_ptr_temp = nullptr;
const HRESULT copy_res = allocate_and_copy_name_str( new_name_ptr_temp, new_name_length, name );
//const HRESULT copy_res = allocate_and_copy_name_str( new_name_ptr_temp, new_name_length, name );
const HRESULT copy_res = name_pool->copy_name_str_into_buffer( new_name_ptr_temp, ( new_name_length + 1u ), name );


ASSERT( SUCCEEDED( copy_res ) );
if ( !SUCCEEDED( copy_res ) ) {
displayWindowsMsgBoxWithMessage( L"Failed to allocate & copy name str! (SetDriveInformation, success)(aborting!)" );
displayWindowsMsgBoxWithMessage( name.c_str( ) );
std::terminate( );
}

PCWSTR const new_name_ptr = new_name_ptr_temp;
thisDriveItem->m_name.reset( new_name_ptr );
thisDriveItem->m_name = new_name_ptr;
thisDriveItem->m_name_length = new_name_length;
if ( thisDriveItem->m_totalBytes == 0 ) {
return;
Expand All @@ -74,19 +82,19 @@ namespace {
thisDriveItem->m_used = static_cast<DOUBLE>( thisDriveItem->m_totalBytes - thisDriveItem->m_freeBytes ) / static_cast<DOUBLE>( thisDriveItem->m_totalBytes );
}

void SetDriveInformation_failure( _In_ CDriveItem* thisDriveItem, _In_ const std::wstring name ) {
void SetDriveInformation_failure( _In_ CDriveItem* const thisDriveItem ) {
thisDriveItem->m_totalBytes = UINT64_MAX;
thisDriveItem->m_freeBytes = UINT64_MAX;
thisDriveItem->m_used = -1;
}

void SetDriveInformation( _In_ CDriveItem* thisDriveItem, _In_ const bool success, _In_ const std::wstring name, _In_ const std::uint64_t total, _In_ const std::uint64_t free ) {
void SetDriveInformation( _In_ CDriveItem* const thisDriveItem, _In_ const bool success, _In_ const std::wstring name, _In_ const std::uint64_t total, _In_ const std::uint64_t free, _In_ Children_String_Heap_Manager* const name_pool ) {
if ( success ) {
SetDriveInformation_set_valid_info( thisDriveItem, name, total, free );
return SetDriveInformation_copy_name_and_set_m_used( thisDriveItem, name );
return SetDriveInformation_copy_name_and_set_m_used( thisDriveItem, name, name_pool );
}
SetDriveInformation_failure( thisDriveItem, name );
SetDriveInformation_copy_name_and_set_m_used( thisDriveItem, name );
SetDriveInformation_failure( thisDriveItem );
SetDriveInformation_copy_name_and_set_m_used( thisDriveItem, name, name_pool );
return;
}

Expand Down Expand Up @@ -300,8 +308,9 @@ IMPLEMENT_DYNAMIC(CSelectDrivesDlg, CDialog)

UINT CSelectDrivesDlg::_serial;


#pragma warning(suppress:4355)
CSelectDrivesDlg::CSelectDrivesDlg( CWnd* pParent /*=NULL*/ ) : CDialog( CSelectDrivesDlg::IDD, pParent ), m_radio( RADIO_ALLLOCALDRIVES ), m_layout( static_cast<CWnd*>( this ), global_strings::select_drives_dialog_layout ) {
CSelectDrivesDlg::CSelectDrivesDlg( CWnd* pParent /*=NULL*/ ) : CDialog( CSelectDrivesDlg::IDD, pParent ), m_radio( RADIO_ALLLOCALDRIVES ), m_layout( static_cast<CWnd*>( this ), global_strings::select_drives_dialog_layout ), m_name_pool( volume_name_pool_size ) {
_serial++;
//InitializeCriticalSection_wrapper( _csRunningThreads );
InitializeCriticalSection_wrapper( m_running_threads_CRITICAL_SECTION );
Expand Down Expand Up @@ -395,9 +404,9 @@ void CSelectDrivesDlg::buildSelectList( ) {
const auto drives = GetLogicalDrives( );
INT i = 0;
DWORD mask = 0x00000001;
m_list.m_drives.reset( new CDriveItem[ 32 ] );
m_list.m_drives.reset( new CDriveItem[ max_number_of_named_drives ] );
m_list.m_drives_count = 0;
for ( i = 0; i < 32; i++, mask <<= 1 ) {
for ( i = 0; i < static_cast<int>( max_number_of_named_drives ); i++, mask <<= 1 ) {
if ( ( drives bitand mask ) == 0 ) {
continue;
}
Expand All @@ -414,6 +423,7 @@ void CSelectDrivesDlg::buildSelectList( ) {
}

const rsize_t drive_name_length = ( drive_name_buffer_size - chars_remaining );
ASSERT( wcslen( drive_name_buffer ) == drive_name_length );

const auto type = GetDriveTypeW( drive_name_buffer );
if ( ( type == DRIVE_UNKNOWN ) || ( type == DRIVE_NO_ROOT_DIR ) ) {
Expand All @@ -435,8 +445,9 @@ void CSelectDrivesDlg::buildSelectList( ) {
ASSERT( drive_name_length < UINT16_MAX );

PWSTR new_name_ptr = nullptr;
//const HRESULT copy_res = allocate_and_copy_name_str( new_name_ptr, new_name_length, s.GetString( ) );
const HRESULT copy_res = allocate_and_copy_name_str( new_name_ptr, drive_name_length, drive_name_buffer );
//const HRESULT copy_res = allocate_and_copy_name_str( new_name_ptr, drive_name_length, drive_name_buffer );
const HRESULT copy_res = m_name_pool.copy_name_str_into_buffer( new_name_ptr, ( drive_name_length + 1u ), drive_name_buffer );

ASSERT( SUCCEEDED( copy_res ) );
if ( !SUCCEEDED( copy_res ) ) {
displayWindowsMsgBoxWithMessage( L"Failed to allocate & copy name str! (buildSelectList)(aborting!)" );
Expand Down Expand Up @@ -702,7 +713,7 @@ LRESULT _Function_class_( "GUI_THREAD" ) CSelectDrivesDlg::OnWmuThreadFinished(
//EnterCriticalSection( &_csRunningThreads );
EnterCriticalSection( &m_running_threads_CRITICAL_SECTION );

SetDriveInformation( item, success, std::move( name ), total, free );
SetDriveInformation( item, success, std::move( name ), total, free, &m_name_pool );

LeaveCriticalSection( &m_running_threads_CRITICAL_SECTION );
//LeaveCriticalSection( &_csRunningThreads );
Expand Down
1 change: 1 addition & 0 deletions WinDirStat/windirstat/SelectDrivesDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class CSelectDrivesDlg final : public CDialog {
std::vector<std::wstring> m_drives; // out. Valid if m_radio != RADIO_AFOLDER
CRITICAL_SECTION m_running_threads_CRITICAL_SECTION;
_Guarded_by_( m_running_threads_CRITICAL_SECTION ) std::vector<CDriveInformationThread*> m_running_threads;
Children_String_Heap_Manager m_name_pool;
protected:
static UINT _serial; // Each Instance of this dialog gets a serial number
CDrivesList m_list;
Expand Down
30 changes: 15 additions & 15 deletions WinDirStat/windirstat/TreeListControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace {
}
while ( ( steps_from_target > 0 ) && ( child != static_cast< const CItemBranch* >( item ) ) );

TRACE( _T( "halted at: %s\r\n" ), child->m_name.get( ) );
TRACE( _T( "halted at: %s\r\n" ), child->m_name );

//END new algorithm
}
Expand Down Expand Up @@ -205,7 +205,7 @@ void CTreeListItem::childNotNull( _In_ CItemBranch* const aTreeListChild, const
//TRACE( _T( "aTreeListChild: %s\r\n" ), aTreeListChild->GetText( column::COL_NAME ).c_str( ) );
ASSERT( m_vi->cache_sortedChildren.at( i ) == aTreeListChild );
//ASSERT( m_vi->cache_sortedChildren.at( i )->GetText( column::COL_NAME ).compare( aTreeListChild->GetText( column::COL_NAME ) ) == 0 );
ASSERT( wcscmp( m_vi->cache_sortedChildren.at( i )->m_name.get( ), aTreeListChild->m_name.get( ) ) == 0u );
ASSERT( wcscmp( m_vi->cache_sortedChildren.at( i )->m_name, aTreeListChild->m_name ) == 0u );
m_vi->cache_sortedChildren.at( i ) = aTreeListChild;
}
}
Expand Down Expand Up @@ -388,7 +388,7 @@ void CTreeListControl::adjustColumnSize( _In_ const CTreeListItem* const item_at
static_assert( std::is_convertible<std::underlying_type<column::ENUM_COL>::type, int>::value, "we're gonna need to do this!" );

const auto w = GetSubItemWidth( item_at_index, column::COL_NAME ) + 5;
ASSERT( w == ( GetStringWidth( item_at_index->m_name.get( ) ) + 15 ) );
ASSERT( w == ( GetStringWidth( item_at_index->m_name ) + 15 ) );
const auto colWidth = GetColumnWidth( static_cast<int>( column::COL_NAME ) );
if ( colWidth < w ) {
VERIFY( SetColumnWidth( 0, w + colWidth ) );
Expand Down Expand Up @@ -425,7 +425,7 @@ void CTreeListControl::expand_item_then_scroll_to_it( _In_ const CTreeListItem*
}

INT CTreeListControl::find_item_then_show_first_try_failed( _In_ const CTreeListItem* const thisPath, const int i ) {
TRACE( _T( "Searching %s ( this path element ) for next path element...not found! Expanding %I64d...\r\n" ), thisPath->m_name.get( ), i );
TRACE( _T( "Searching %s ( this path element ) for next path element...not found! Expanding %I64d...\r\n" ), thisPath->m_name, i );
ExpandItemNoScroll( i );

//we expect to find the item on the second try.
Expand All @@ -449,7 +449,7 @@ void CTreeListControl::find_item_then_show( _In_ const CTreeListItem* const this
}
else {
//if we've found the item, then we should close anything that we opened in the process?
TRACE( _T( "Searching %s for next path element...found! path.at( %I64d ), index: %i\r\n" ), thisPath->m_name.get( ), std::int64_t( i ), index );
TRACE( _T( "Searching %s for next path element...found! path.at( %I64d ), index: %i\r\n" ), thisPath->m_name, std::int64_t( i ), index );
index = collapse_parent_plus_one_through_index( thisPath, index, parent );
TRACE( _T( "Collapsing items [%i, %i), new index %i. Item count: %i\r\n" ), ( parent + 1 ), index, index, GetItemCount( ) );
}
Expand Down Expand Up @@ -600,8 +600,8 @@ void CTreeListControl::SelectAndShowItem( _In_ const CTreeListItem* const item,

#ifdef DEBUG
for ( size_t inner = 0; inner < path.size( ); ++inner ) {
ASSERT( path.at( inner )->m_name.get( ) != NULL );
TRACE( _T( "path component %I64u: `%s` (%p)\r\n" ), std::uint64_t( inner ), path.at( inner )->m_name.get( ), path.at( inner ) );
ASSERT( path.at( inner )->m_name != NULL );
TRACE( _T( "path component %I64u: `%s` (%p)\r\n" ), std::uint64_t( inner ), path.at( inner )->m_name, path.at( inner ) );
}
#endif

Expand Down Expand Up @@ -971,7 +971,7 @@ int CTreeListControl::countItemsToDelete( _In_ const CTreeListItem* const item,
}
todelete++;
}
TRACE( _T( "Need to delete %i items from %s\r\n" ), todelete, item->m_name.get( ) );
TRACE( _T( "Need to delete %i items from %s\r\n" ), todelete, item->m_name );
return todelete;
}

Expand All @@ -983,10 +983,10 @@ _Success_( return == true ) bool CTreeListControl::CollapseItem( _In_ _In_range_
return false;
}
if ( !item->IsExpanded( ) ) {
TRACE( _T( "ERROR: Collapsing item %i: %s...it's not expanded!\r\n" ), i, item->m_name.get( ) );
TRACE( _T( "ERROR: Collapsing item %i: %s...it's not expanded!\r\n" ), i, item->m_name );
return false;
}
TRACE( _T( "Collapsing item %i: %s\r\n" ), i, item->m_name.get( ) );
TRACE( _T( "Collapsing item %i: %s\r\n" ), i, item->m_name );
//WTL::CWaitCursor wc;
SetRedraw( FALSE );

Expand All @@ -1000,7 +1000,7 @@ _Success_( return == true ) bool CTreeListControl::CollapseItem( _In_ _In_range_
ASSERT( local_var != NULL );
if ( local_var != NULL ) {
ASSERT( item_number_to_delete == FindListItem( local_var ) );
TRACE( _T( "deleting item %i (%i/%i), %s\r\n" ), ( item_number_to_delete ), m, todelete, local_var->m_name.get( ) );
TRACE( _T( "deleting item %i (%i/%i), %s\r\n" ), ( item_number_to_delete ), m, todelete, local_var->m_name );
}
else {
TRACE( _T( "deleting item %i (%i/%i), %s\r\n" ), ( item_number_to_delete ), m, todelete, L"ERROR: NULL POINTER!" );
Expand All @@ -1018,7 +1018,7 @@ _Success_( return == true ) bool CTreeListControl::CollapseItem( _In_ _In_range_
const auto item_count = GetItemCount( );
#ifdef DEBUG
const auto local_var = GetItem( i );
TRACE( _T( "Redrawing items %i (`%s`) to %i....\r\n" ), i, ( ( local_var != NULL ) ? local_var->m_name.get( ) : L"" ), ( item_count ) );
TRACE( _T( "Redrawing items %i (`%s`) to %i....\r\n" ), i, ( ( local_var != NULL ) ? local_var->m_name : L"" ), ( item_count ) );

#endif
VERIFY( RedrawItems( i, item_count ) );
Expand Down Expand Up @@ -1102,14 +1102,14 @@ void CTreeListControl::ExpandItemInsertChildren( _In_ const CTreeListItem* const
static_assert( column::COL_NAME == 0, "GetSubItemWidth used to accept an INT as the second parameter. The value of zero, I believe, should be COL_NAME" );
//static_assert( COL_NAME__ == 0, "GetSubItemWidth used to accept an INT as the second parameter. The value of zero, I believe, should be COL_NAME" );
auto maxwidth = GetSubItemWidth( item, column::COL_NAME );
ASSERT( maxwidth == ( GetStringWidth( item->m_name.get( ) ) + 10 ) );
ASSERT( maxwidth == ( GetStringWidth( item->m_name ) + 10 ) );
const auto count = item->GetChildrenCount_( );
if ( count == 0 ) {
TRACE( _T( "item `%s` has a child count of ZERO! Not expanding! \r\n" ), item->m_name.get( ) );
TRACE( _T( "item `%s` has a child count of ZERO! Not expanding! \r\n" ), item->m_name );
return;
}
const auto myCount = static_cast<size_t>( GetItemCount( ) );
TRACE( _T( "Expanding %s! Must insert %i items!\r\n" ), item->m_name.get( ), count );
TRACE( _T( "Expanding %s! Must insert %i items!\r\n" ), item->m_name, count );
SetItemCount( static_cast<INT>( ( count >= myCount) ? ( count + 1 ) : ( myCount + 1 ) ) );

insertItemsAdjustWidths( item, count, maxwidth, scroll, i );
Expand Down
2 changes: 1 addition & 1 deletion WinDirStat/windirstat/TreeListControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class CTreeListItem : public COwnerDrawnListItem {

public:
const CTreeListItem* m_parent;

Children_String_Heap_Manager m_name_pool;
// Data needed to display the item.
mutable std::unique_ptr<VISIBLEINFO> m_vi = nullptr;
};
Expand Down
8 changes: 4 additions & 4 deletions WinDirStat/windirstat/colorbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#include "colorbutton.h"


BEGIN_MESSAGE_MAP(CColorButton::CPreview, CWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
//BEGIN_MESSAGE_MAP(CColorButton::CPreview, CWnd)
// ON_WM_PAINT()
// ON_WM_LBUTTONDOWN()
//END_MESSAGE_MAP()

BEGIN_MESSAGE_MAP( CColorButton, CButton )
ON_WM_PAINT( )
Expand Down
Loading

0 comments on commit e3ede6e

Please sign in to comment.