diff --git a/WinDirStat/windirstat/TreeListControl.cpp b/WinDirStat/windirstat/TreeListControl.cpp index 8ceb926..3b1d0e3 100644 --- a/WinDirStat/windirstat/TreeListControl.cpp +++ b/WinDirStat/windirstat/TreeListControl.cpp @@ -124,12 +124,15 @@ struct compare_CTreeListItems { const bool CTreeListItem::set_plusminus_and_title_rects( _In_ const RECT rcLabel, _In_ const RECT rc_const ) const { const POINT rc_top_left = { rc_const.left, rc_const.top }; - const RECT _rcPlusMinus = { 0, 0, 0, 0 }; + const RECT _rcPlusMinus = { 0, rcLabel.top, rcLabel.left, rcLabel.bottom }; //const CRect rcLabel_( rcLabel ); RECT temp_rect = _rcPlusMinus; VERIFY( ::OffsetRect( &temp_rect, -( rc_top_left.x ), -( rc_top_left.y ) ) ); const RECT& new_plus_minus_rect = temp_rect; + RECT test_rect = temp_rect; + normalize_RECT( test_rect ); + SetPlusMinusRect( new_plus_minus_rect ); RECT new_title_rect = rcLabel; @@ -180,6 +183,7 @@ bool CTreeListItem::DrawSubitem( RANGE_ENUM_COL const column::ENUM_COL subitem, DrawLabel( list, pdc, rcLabel, state, width, focusLeft, false ); if ( width != NULL ) { *width = ( rcLabel.right - rcLabel.left ); + set_plusminus_and_title_rects( rcLabel, rc_const ); return true; } return set_plusminus_and_title_rects( rcLabel, rc_const ); @@ -835,8 +839,8 @@ RECT CTreeListControl::DrawNode_Indented( _In_ const CTreeListItem* const item, CDC dcmem; VERIFY( dcmem.CreateCompatibleDC( &pdc ) ); CSelectObject sonodes( dcmem, ( IsItemStripeColor( item ) ? m_bmNodes1 : m_bmNodes0 ) ); - auto ysrc = ( NODE_HEIGHT / 2 ) - ( m_rowHeight / 2 ); - bool didBitBlt = DrawNodeNullWidth( item, pdc, rcRest, dcmem, ysrc ); + const auto ysrc = ( NODE_HEIGHT / 2 ) - ( m_rowHeight / 2 ); + const bool didBitBlt = DrawNodeNullWidth( item, pdc, rcRest, dcmem, ysrc ); rcRest.left += ( item->GetIndent( ) - 1 ) * INDENT_WIDTH; const auto node = EnumNode( item ); ASSERT_VALID( &dcmem ); @@ -891,6 +895,9 @@ void CTreeListControl::OnLButtonDown( UINT nFlags, CPoint point ) { const auto rc = GetWholeSubitemRect( i, 0, thisHeader ); const POINT temp = { rc.left, rc.top }; + //given temp == { 0, 84 }; + //given point == { 200, 89 }; + //pt == { 200, 5 }; WTL::CPoint pt = ( point - temp ); @@ -981,7 +988,7 @@ _Success_( return == true ) bool CTreeListControl::CollapseItem( _In_ _In_range_ } TRACE( _T( "Collapsing item %i: %s\r\n" ), i, item->m_name.get( ) ); //WTL::CWaitCursor wc; - //SetRedraw( FALSE ); + SetRedraw( FALSE ); bool selectNode = false; const auto item_number_to_delete = ( i + 1 ); @@ -1007,7 +1014,7 @@ _Success_( return == true ) bool CTreeListControl::CollapseItem( _In_ _In_range_ SelectItem( i ); } - //SetRedraw( TRUE ); + SetRedraw( TRUE ); const auto item_count = GetItemCount( ); #ifdef DEBUG const auto local_var = GetItem( i ); diff --git a/WinDirStat/windirstat/globalhelpers.cpp b/WinDirStat/windirstat/globalhelpers.cpp index 76ea260..4e0b812 100644 --- a/WinDirStat/windirstat/globalhelpers.cpp +++ b/WinDirStat/windirstat/globalhelpers.cpp @@ -1439,9 +1439,14 @@ _Pre_satisfies_( handle != INVALID_HANDLE_VALUE ) _At_( handle, _Post_invalid_ ) _At_( handle, _Pre_valid_ ) void close_handle( const HANDLE handle ) { - const auto res = CloseHandle( handle ); - //TODO: trace error message + //If [CloseHandle] succeeds, the return value is nonzero. + const BOOL res = CloseHandle( handle ); ASSERT( res != 0 ); + if ( !res ) { + TRACE( _T( "Closing handle failed!\r\n" ) ); + } + //TODO: trace error message + } #else diff --git a/WinDirStat/windirstat/graphview.cpp b/WinDirStat/windirstat/graphview.cpp index 02a2f03..5bffa5c 100644 --- a/WinDirStat/windirstat/graphview.cpp +++ b/WinDirStat/windirstat/graphview.cpp @@ -25,9 +25,84 @@ #include "options.h" #include "mainframe.h" +/* -IMPLEMENT_DYNCREATE( CGraphView, CView ) +#define IMPLEMENT_DYNCREATE(class_name, base_class_name) \ + CObject* PASCAL class_name::CreateObject() \ + { return new class_name; } \ + IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, \ + class_name::CreateObject, NULL) +#define IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew, class_init) \ + AFX_COMDAT const CRuntimeClass class_name::class##class_name = { \ + #class_name, sizeof(class class_name), wSchema, pfnNew, \ + RUNTIME_CLASS(base_class_name), NULL, class_init }; \ + CRuntimeClass* class_name::GetRuntimeClass() const \ + { return RUNTIME_CLASS(class_name); } + +#define RUNTIME_CLASS(class_name) _RUNTIME_CLASS(class_name) +#define _RUNTIME_CLASS(class_name) ((CRuntimeClass*)(&class_name::class##class_name)) +--------------------------------------------------------------------- + + CObject* PASCAL CGraphView::CreateObject( ) { + return new CGraphView; + } + + AFX_COMDAT const CRuntimeClass CGraphView::classCGraphView = { "CGraphView", sizeof( class CGraphView ), 0xFFFF, CGraphView::CreateObject, ((CRuntimeClass*)(&CView::classCView)), NULL, NULL }; + + CRuntimeClass* CGraphView::GetRuntimeClass( ) const { + return ((CRuntimeClass*)(&CGraphView::classCGraphView)); + } + +*/ + +//IMPLEMENT_DYNCREATE( CGraphView, CView ) + + + /* +#define BEGIN_MESSAGE_MAP(theClass, baseClass) \ + PTM_WARNING_DISABLE \ + const AFX_MSGMAP* theClass::GetMessageMap() const \ + { return GetThisMessageMap(); } \ + const AFX_MSGMAP* PASCAL theClass::GetThisMessageMap() \ + { \ + typedef theClass ThisClass; \ + typedef baseClass TheBaseClass; \ + static const AFX_MSGMAP_ENTRY _messageEntries[] = \ + { + + +#define END_MESSAGE_MAP() \ + {0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } \ + }; \ + static const AFX_MSGMAP messageMap = \ + { &TheBaseClass::GetThisMessageMap, &_messageEntries[0] }; \ + return &messageMap; \ + } \ + PTM_WARNING_RESTORE + +------------------------------------------------------------- +#define BEGIN_MESSAGE_MAP(CGraphView, CView ) \ + PTM_WARNING_DISABLE \ + const AFX_MSGMAP* CGraphView::GetMessageMap() const { + return GetThisMessageMap( ); + } + const AFX_MSGMAP* PASCAL CGraphView::GetThisMessageMap( ) { + typedef CGraphView ThisClass; + typedef CView TheBaseClass; + static const AFX_MSGMAP_ENTRY _messageEntries[ ] = { + + +#define END_MESSAGE_MAP() \ + {0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } + }; + static const AFX_MSGMAP messageMap = { &TheBaseClass::GetThisMessageMap, &_messageEntries[0] }; + return &messageMap; + } + PTM_WARNING_RESTORE + + */ + /* BEGIN_MESSAGE_MAP( CGraphView, CView ) ON_WM_SIZE( ) ON_WM_LBUTTONDOWN( ) @@ -38,6 +113,90 @@ BEGIN_MESSAGE_MAP( CGraphView, CView ) ON_WM_TIMER( ) //ON_COMMAND(ID_POPUP_CANCEL, OnPopupCancel) END_MESSAGE_MAP( ) + */ + +AFX_COMDAT const CRuntimeClass CGraphView::classCGraphView = { "CGraphView", sizeof( class CGraphView ), 0xFFFF, &( CGraphView::CreateObject ), const_cast( &CView::classCView ), NULL, NULL }; + +const AFX_MSGMAP* CGraphView::GetMessageMap( ) const { + return GetThisMessageMap( ); + } + +const AFX_MSGMAP* PASCAL CGraphView::GetThisMessageMap( ) { + typedef CGraphView ThisClass; + typedef CView TheBaseClass; + static const AFX_MSGMAP_ENTRY _messageEntries[ ] = { + + { + WM_SIZE, + 0, + 0, + 0, + AfxSig_vwii, + (AFX_PMSG)(AFX_PMSGW) (static_cast( &ThisClass::OnSize)) + }, + + { + WM_LBUTTONDOWN, + 0, + 0, + 0, + AfxSig_vwp, + (AFX_PMSG)(AFX_PMSGW) (static_cast( &ThisClass::OnLButtonDown)) + }, + { + WM_SETFOCUS, + 0, + 0, + 0, + AfxSig_vW, + (AFX_PMSG)(AFX_PMSGW)(static_cast( &ThisClass::OnSetFocus)) + }, + { + WM_CONTEXTMENU, + 0, + 0, + 0, + AfxSig_vWp, + (AFX_PMSG)(AFX_PMSGW)(static_cast( &ThisClass::OnContextMenu)) + }, + { + WM_MOUSEMOVE, + 0, + 0, + 0, + AfxSig_vwp, + (AFX_PMSG)(AFX_PMSGW)(static_cast( &ThisClass::OnMouseMove)) + }, + { + WM_DESTROY, + 0, + 0, + 0, + AfxSig_vv, + (AFX_PMSG)(AFX_PMSGW)(static_cast( &ThisClass::OnDestroy)) + }, + { + WM_TIMER, + 0, + 0, + 0, + AfxSig_v_up_v, + (AFX_PMSG)(AFX_PMSGW)(static_cast( &ThisClass::OnTimer)) + }, + { + 0, + 0, + 0, + 0, + AfxSig_end, + (AFX_PMSG)0 + } + }; + + static const AFX_MSGMAP messageMap = { &TheBaseClass::GetThisMessageMap, &_messageEntries[ 0 ] }; + return &messageMap; +} + void CGraphView::DrawEmptyView( _In_ CDC& pScreen_Device_Context ) { TRACE( _T( "Drawing Empty view...\r\n" ) ); @@ -288,16 +447,16 @@ void CGraphView::RenderHighlightRectangle( _In_ CDC& pdc, _In_ RECT rc_ ) const } } -#ifdef _DEBUG -void CGraphView::AssertValid( ) const { - CView::AssertValid( ); - } +//#ifdef _DEBUG +//void CGraphView::AssertValid( ) const { +// CView::AssertValid( ); +// } -void CGraphView::Dump( CDumpContext& dc ) const { - TRACE( _T( "CGraphView::Dump\r\n" ) ); - CView::Dump( dc ); - } -#endif +//void CGraphView::Dump( CDumpContext& dc ) const { +// TRACE( _T( "CGraphView::Dump\r\n" ) ); +// CView::Dump( dc ); +// } +//#endif void CGraphView::OnSize( UINT nType, INT cx, INT cy ) { CView::OnSize( nType, cx, cy ); diff --git a/WinDirStat/windirstat/graphview.h b/WinDirStat/windirstat/graphview.h index f7ac387..8cecc03 100644 --- a/WinDirStat/windirstat/graphview.h +++ b/WinDirStat/windirstat/graphview.h @@ -27,7 +27,38 @@ class CGraphView final : public CView { m_dimmedSize.cy = 0; m_showTreemap = CPersistence::GetShowTreemap( ); } - DECLARE_DYNCREATE(CGraphView) + + /* +#define DECLARE_DYNCREATE(class_name) \ + DECLARE_DYNAMIC(class_name) \ + static CObject* PASCAL CreateObject(); + +#define DECLARE_DYNAMIC(class_name) \ +public: \ + static const CRuntimeClass class##class_name; \ + virtual CRuntimeClass* GetRuntimeClass() const; \ + +---------------------------------------- + +public: + static const CRuntimeClass classCGraphView; + virtual CRuntimeClass* GetRuntimeClass( ) const; + static CObject* PASCAL CreateObject( ); + + */ + +public: + static const CRuntimeClass classCGraphView; + + virtual CRuntimeClass* GetRuntimeClass( ) const final { + return const_cast( &CGraphView::classCGraphView ); + } + + static CObject* PASCAL CreateObject( ) { + return new CGraphView; + } + + //DECLARE_DYNCREATE(CGraphView) public: //virtual ~CGraphView(); @@ -98,14 +129,17 @@ class CGraphView final : public CView { //only called from one place inline void RecurseHighlightChildren( _In_ CDC& pdc, _In_ const CItemBranch& item, _In_ const std::wstring& ext ) const; + +protected: + //TODO: use plain old SIZE struct + WTL::CSize m_size; // Current size of view + public: bool m_recalculationSuspended : 1; // True while the user is resizing the window. //C4820: 'CGraphView' : '3' bytes padding added after data member 'CGraphView::m_showTreemap' bool m_showTreemap : 1; // False, if the user switched off the treemap (by F9). protected: - //C4820: 'CGraphView' : '4' bytes padding added after data member 'CGraphView::m_size' - WTL::CSize m_size; // Current size of view CTreemap m_treemap; // Treemap generator CBitmap m_bitmap; // Cached view. If m_hObject is NULL, the view must be recalculated. WTL::CSize m_dimmedSize; // Size of bitmap m_dimmed @@ -113,7 +147,20 @@ class CGraphView final : public CView { UINT_PTR m_timer; // We need a timer to realize when the mouse left our window. CMainFrame* const m_frameptr; CDirstatApp* m_appptr; - DECLARE_MESSAGE_MAP() + + /* +#define DECLARE_MESSAGE_MAP() \ +protected: \ + static const AFX_MSGMAP* PASCAL GetThisMessageMap(); \ + virtual const AFX_MSGMAP* GetMessageMap() const; \ +------------------------------------------------------- + + */ + + +protected: + static const AFX_MSGMAP* PASCAL GetThisMessageMap( ); + virtual const AFX_MSGMAP* GetMessageMap( ) const final; afx_msg void OnSize(UINT nType, INT cx, INT cy); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnSetFocus(CWnd* pOldWnd); @@ -125,8 +172,13 @@ class CGraphView final : public CView { public: #ifdef _DEBUG - virtual void AssertValid() const; - virtual void Dump(CDumpContext& dc) const; + virtual void AssertValid( ) const final { + CView::AssertValid( ); + } + virtual void Dump( CDumpContext& dc ) const final { + TRACE( _T( "CGraphView::Dump\r\n" ) ); + CView::Dump( dc ); + } #endif //afx_msg void OnPopupCancel(); }; diff --git a/WinDirStat/windirstat/mainframe.cpp b/WinDirStat/windirstat/mainframe.cpp index 6211764..a9dcb20 100644 --- a/WinDirStat/windirstat/mainframe.cpp +++ b/WinDirStat/windirstat/mainframe.cpp @@ -46,17 +46,21 @@ namespace { IDC_DEADFOCUS // ID of dead-focus window }; + void failed_to_open_clipboard( ) { + displayWindowsMsgBoxWithError( ); + displayWindowsMsgBoxWithMessage( L"Cannot open the clipboard." ); + TRACE( _T( "Cannot open the clipboard!\r\n" ) ); + } + class COpenClipboard { public: COpenClipboard( const COpenClipboard& in ) = delete; COpenClipboard& operator=( const COpenClipboard& in ) = delete; - COpenClipboard( CWnd* const owner, const bool empty = true ) : m_open( owner->OpenClipboard( ) ) { - //m_open = owner->OpenClipboard( ); + COpenClipboard( CWnd* const owner, const bool empty ) : m_open { owner->OpenClipboard( ) } { if ( !m_open ) { - displayWindowsMsgBoxWithError( ); - displayWindowsMsgBoxWithMessage( L"Cannot open the clipboard." ); - TRACE( _T( "Cannot open the clipboard!\r\n" ) ); + failed_to_open_clipboard( ); + return; } if ( empty ) { if ( !EmptyClipboard( ) ) { @@ -191,15 +195,20 @@ void CMySplitterWnd::StopTracking( _In_ BOOL bAccept ) { if ( !bAccept ) { return; } - CRect rcClient; - GetClientRect( rcClient ); + RECT rcClient = { 0, 0, 0, 0 }; + ASSERT( ::IsWindow( m_hWnd ) ); + + //"If [GetClientRect] succeeds, the return value is nonzero. To get extended error information, call GetLastError." + VERIFY( ::GetClientRect( m_hWnd, &rcClient ) ); + + INT dummy = 0; if ( GetColumnCount( ) > 1 ) { INT cxLeft = 0; GetColumnInfo( 0, cxLeft, dummy ); - if ( rcClient.Width( ) > 0 ) { - m_splitterPos = static_cast< DOUBLE >( cxLeft ) / static_cast< DOUBLE >( rcClient.Width( ) ); + if ( ( rcClient.right - rcClient.left ) > 0 ) { + m_splitterPos = static_cast< DOUBLE >( cxLeft ) / static_cast< DOUBLE >( rcClient.right - rcClient.left ); } m_wasTrackedByUser = true; m_userSplitterPos = m_splitterPos; @@ -207,8 +216,8 @@ void CMySplitterWnd::StopTracking( _In_ BOOL bAccept ) { } INT cyUpper = 0; GetRowInfo( 0, cyUpper, dummy ); - if ( rcClient.Height( ) > 0 ) { - m_splitterPos = static_cast< DOUBLE >( cyUpper ) / static_cast< DOUBLE >( rcClient.Height( ) ); + if ( ( rcClient.bottom - rcClient.top ) > 0 ) { + m_splitterPos = static_cast< DOUBLE >( cyUpper ) / static_cast< DOUBLE >( rcClient.bottom - rcClient.top ); } m_wasTrackedByUser = true; m_userSplitterPos = m_splitterPos; @@ -218,8 +227,13 @@ void CMySplitterWnd::StopTracking( _In_ BOOL bAccept ) { void CMySplitterWnd::SetSplitterPos( _In_ const DOUBLE pos ) { m_splitterPos = pos; - CRect rcClient; - GetClientRect( &rcClient ); + + + RECT rcClient = { 0, 0, 0, 0 }; + + ASSERT( ::IsWindow( m_hWnd ) ); + //"If [GetClientRect] succeeds, the return value is nonzero. To get extended error information, call GetLastError." + VERIFY( ::GetClientRect( m_hWnd, &rcClient ) ); if ( GetColumnCount( ) > 1 ) { ASSERT( m_pColInfo != NULL ); @@ -227,7 +241,7 @@ void CMySplitterWnd::SetSplitterPos( _In_ const DOUBLE pos ) { CPersistence::SetSplitterPos( m_persistenceName, m_wasTrackedByUser, m_userSplitterPos ); return; } - const auto cxLeft = static_cast< INT >( pos * ( rcClient.Width( ) ) ); + const auto cxLeft = static_cast< INT >( pos * ( rcClient.right - rcClient.left ) ); if ( cxLeft >= 0 ) { SetColumnInfo( 0, cxLeft, 0 ); RecalcLayout( ); @@ -242,7 +256,7 @@ void CMySplitterWnd::SetSplitterPos( _In_ const DOUBLE pos ) { CPersistence::SetSplitterPos( m_persistenceName, m_wasTrackedByUser, m_userSplitterPos ); return; } - const auto cyUpper = static_cast< INT >( pos * ( rcClient.Height( ) ) ); + const auto cyUpper = static_cast< INT >( pos * ( rcClient.bottom - rcClient.top ) ); if ( cyUpper >= 0 ) { SetRowInfo( 0, cyUpper, 0 ); RecalcLayout( ); @@ -423,11 +437,16 @@ void CMainFrame::OnDestroy( ) { } BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext ) { + const SIZE GraphView_size = { 100, 100 }; + const SIZE DirstatView_size = { 700, 500 }; + const SIZE TypeView_size = { 100, 500 }; + VERIFY( m_wndSplitter.CreateStatic( this, 2, 1 ) ); - VERIFY( m_wndSplitter.CreateView( 1, 0, RUNTIME_CLASS( CGraphView ), WTL::CSize( 100, 100 ), pContext ) ); - VERIFY( m_wndSubSplitter.CreateStatic( &m_wndSplitter, static_cast< INT >( 1 ), static_cast< INT >( 2 ), WS_CHILD | WS_VISIBLE | WS_BORDER, static_cast< UINT >( m_wndSplitter.IdFromRowCol( 0, 0 ) ) ) ); - VERIFY( m_wndSubSplitter.CreateView( 0, 0, RUNTIME_CLASS( CDirstatView ), WTL::CSize( 700, 500 ), pContext ) ); - VERIFY( m_wndSubSplitter.CreateView( 0, 1, RUNTIME_CLASS( CTypeView ), WTL::CSize( 100, 500 ), pContext ) ); + VERIFY( m_wndSplitter.CreateView( 1, 0, RUNTIME_CLASS( CGraphView ), GraphView_size, pContext ) ); + + VERIFY( m_wndSubSplitter.CreateStatic( &m_wndSplitter, 1, 2, WS_CHILD | WS_VISIBLE | WS_BORDER, static_cast< UINT >( m_wndSplitter.IdFromRowCol( 0, 0 ) ) ) ); + VERIFY( m_wndSubSplitter.CreateView( 0, 0, RUNTIME_CLASS( CDirstatView ), DirstatView_size, pContext ) ); + VERIFY( m_wndSubSplitter.CreateView( 0, 1, RUNTIME_CLASS( CTypeView ), TypeView_size, pContext ) ); //MinimizeGraphView( ); m_wndSplitter.SetSplitterPos( 1.0 ); diff --git a/WinDirStat/windirstat/ownerdrawnlistcontrol.h b/WinDirStat/windirstat/ownerdrawnlistcontrol.h index ef0fd57..6761eed 100644 --- a/WinDirStat/windirstat/ownerdrawnlistcontrol.h +++ b/WinDirStat/windirstat/ownerdrawnlistcontrol.h @@ -241,6 +241,21 @@ namespace { std::terminate( ); } } + inline RECT adjust_rect_for_grid_by_value( _In_ const bool show_grid, _In_ RECT rc_temp ) { + if ( show_grid ) { + rc_temp.bottom--; + rc_temp.right--; + return rc_temp; + } + return rc_temp; + } + + inline void adjust_rect_for_grid( _In_ const bool show_grid, _Inout_ RECT& rcItem_temp ) { + if ( show_grid ) { + rcItem_temp.bottom--; + rcItem_temp.right--; + } + } void check_validity_of_resize_size( _In_ const int resize_size, _In_ const rsize_t stack_array_size ) { if ( resize_size == -1 ) { @@ -326,21 +341,25 @@ namespace { //thisLoopSize has essentially the range of RANGE_ENUM_COL, but it's never zero. template void draw_focus_rects( _In_ _In_range_( 1, 8 ) const rsize_t thisLoopSize, _In_ CDC& dcmem, _In_ _In_reads_( thisLoopSize ) const RECT( &rects_draw )[ count ], _In_ _In_reads_( thisLoopSize ) const int( &focusLefts )[ count ], _In_ CDC* pdc, _Inout_ RECT& rcFocus, _In_ const RECT& rcItem, _In_ const bool drawFocus ) { - if ( drawFocus ) { - draw_focus_rects_draw_focus( thisLoopSize, dcmem, rects_draw, focusLefts, pdc, rcFocus, rcItem ); + return draw_focus_rects_draw_focus( thisLoopSize, dcmem, rects_draw, focusLefts, pdc, rcFocus, rcItem ); } - else { - for ( size_t i = 0; i < thisLoopSize; i++ ) { - if ( focusLefts[ i ] > rects_draw[ i ].left ) { - rcFocus.left = focusLefts[ i ]; - } - rcFocus.right = rects_draw[ i ].right; - VERIFY( pdc->BitBlt( ( rcItem.left + rects_draw[ i ].left ), ( rcItem.top + rects_draw[ i ].top ), ( rects_draw[ i ].right - rects_draw[ i ].left ), ( rects_draw[ i ].bottom - rects_draw[ i ].top ), &dcmem, rects_draw[ i ].left, rects_draw[ i ].top, SRCCOPY ) ); + for ( size_t i = 0; i < thisLoopSize; i++ ) { + if ( focusLefts[ i ] > rects_draw[ i ].left ) { + rcFocus.left = focusLefts[ i ]; } + rcFocus.right = rects_draw[ i ].right; + VERIFY( pdc->BitBlt( ( rcItem.left + rects_draw[ i ].left ), ( rcItem.top + rects_draw[ i ].top ), ( rects_draw[ i ].right - rects_draw[ i ].left ), ( rects_draw[ i ].bottom - rects_draw[ i ].top ), &dcmem, rects_draw[ i ].left, rects_draw[ i ].top, SRCCOPY ) ); } } + template + void map_column_number_to_ENUM_and_build_drawable_rect( const rsize_t thisLoopSize, _In_ const INT( &order )[ count ], _Out_ _Out_writes_( thisLoopSize ) column::ENUM_COL( &subitems_temp )[ count ], _Out_ _Out_writes_( thisLoopSize ) RECT( &rects_temp )[ count ], _In_ const PDRAWITEMSTRUCT pdis, _Inout_ const COwnerDrawnListCtrl* const this_ctrl, _Inout_ CHeaderCtrl* thisHeaderCtrl, _In_ const RECT rcItem ) { + iterate_over_columns_and_populate_column_fields_( thisLoopSize, order, subitems_temp ); + build_array_of_rects_from_subitem_rects( thisLoopSize, subitems_temp, rects_temp, pdis, this_ctrl, thisHeaderCtrl ); + build_array_of_drawable_rects_by_offsetting_( thisLoopSize, rects_temp, rcItem.left, rcItem.top ); + } + 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; @@ -394,27 +413,19 @@ class COwnerDrawnListCtrl : public CListCtrl { const auto pdc = CDC::FromHandle( pdis->hDC ); const auto bIsFullRowSelection = m_showFullRowSelection; ASSERT_VALID( pdc ); - RECT rcItem_temp( pdis->rcItem ); - if ( m_showGrid ) { - rcItem_temp.bottom--; - rcItem_temp.right--; - } + //RECT rcItem_temp( pdis->rcItem ); + + const RECT rcItem = adjust_rect_for_grid_by_value( m_showGrid, pdis->rcItem ); + + //adjust_rect_for_grid( m_showGrid, rcItem_temp ); + - const RECT& rcItem = rcItem_temp; CDC dcmem; //compiler seems to vectorize this! VERIFY( dcmem.CreateCompatibleDC( pdc ) ); CBitmap bm; VERIFY( bm.CreateCompatibleBitmap( pdc, ( rcItem.right - rcItem.left ), ( rcItem.bottom - rcItem.top ) ) ); CSelectObject sobm( dcmem, bm ); - /* - inline CRect CRect::operator-(_In_ POINT pt) const throw() - { - CRect rect(*this); - ::OffsetRect(&rect, -pt.x, -pt.y); - return rect; - } - */ RECT rect_to_fill_solidly = rcItem; const tagPOINT point_to_offset_by = { rcItem.left, rcItem.top }; VERIFY( ::OffsetRect( &rect_to_fill_solidly, -( point_to_offset_by.x ), -( point_to_offset_by.y ) ) ); @@ -435,7 +446,7 @@ class COwnerDrawnListCtrl : public CListCtrl { const auto thisHeaderCtrl = GetHeaderCtrl( );//HORRENDOUSLY slow. Pessimisation of memory access, iterates (with a for loop!) over a map. MAXIMUM branch prediction failures! Maximum Bad Speculation stalls! const auto resize_size = thisHeaderCtrl->GetItemCount( ); - //void check_validity_of_resize_size( _In_ const int resize_size, _In_ const rsize_t stack_array_size ) + check_validity_of_resize_size( resize_size, stack_array_size ); //order_temp.resize( static_cast( resize_size ) ); @@ -443,21 +454,16 @@ class COwnerDrawnListCtrl : public CListCtrl { VERIFY( thisHeaderCtrl->GetOrderArray( order_temp, resize_size )) ; - #ifdef DEBUG for ( rsize_t i = 0; i < static_cast( resize_size - 1 ); ++i ) { - if ( static_cast( i ) != order_temp[ i ] ) { - TRACE( _T( "order[%i]: %i \r\n" ), static_cast( i ), order_temp[ i ] ); - } + ASSERT( static_cast< INT >( i ) == order_temp[ i ] ); } - #endif - const auto thisLoopSize = static_cast( resize_size ); + + const rsize_t thisLoopSize = static_cast( resize_size ); if ( is_right_aligned_cache.empty( ) ) { repopulate_right_aligned_cache( is_right_aligned_cache, thisLoopSize, thisHeaderCtrl, this ); - //is_right_aligned_cache.reserve( thisLoopSize ); - //for ( size_t i = 0; i < thisLoopSize; ++i ) { - // is_right_aligned_cache.push_back( IsColumnRightAligned( static_cast( i ), thisHeaderCtrl ) ); - // } } + ASSERT( thisLoopSize < 8 ); + RECT rcFocus = rcItem; //rcFocus.DeflateRect( 0, LABEL_Y_MARGIN - 1 ); @@ -465,39 +471,31 @@ class COwnerDrawnListCtrl : public CListCtrl { const INT (&order)[ stack_array_size ] = order_temp; - ASSERT( thisLoopSize < 8 ); - column::ENUM_COL subitems_temp[ stack_array_size ]; - + int focusLefts_temp[ stack_array_size ] = { 0 }; RECT rects_temp[ stack_array_size ] = { 0 }; //RECT rects_draw_temp[ stack_array_size ] = { 0 }; - int focusLefts_temp[ stack_array_size ] = { 0 }; - - iterate_over_columns_and_populate_column_fields_( thisLoopSize, order, subitems_temp ); - - build_array_of_rects_from_subitem_rects( thisLoopSize, subitems_temp, rects_temp, pdis, this, thisHeaderCtrl ); - - build_array_of_drawable_rects_by_offsetting_( thisLoopSize, rects_temp, rcItem.left, rcItem.top ); + //build map of column# -> ENUM_COL + //build drawable rect for each column + map_column_number_to_ENUM_and_build_drawable_rect( thisLoopSize, order, subitems_temp, rects_temp, pdis, this, thisHeaderCtrl, rcItem ); const column::ENUM_COL (&subitems)[ stack_array_size ] = subitems_temp; - const RECT (&rects_draw)[ stack_array_size ] = rects_temp; build_focusLefts_from_drawable_rects( thisLoopSize, rects_draw, focusLefts_temp ); + draw_proper_text_for_each_column( item, thisLoopSize, subitems, dcmem, rects_draw, pdis, focusLefts_temp, showSelectionAlways, bIsFullRowSelection, is_right_aligned_cache, this ); const int (&focusLefts)[ stack_array_size ] = focusLefts_temp; draw_focus_rects( thisLoopSize, dcmem, rects_draw, focusLefts, pdc, rcFocus, rcItem, drawFocus ); - if ( drawFocus ) { pdc->DrawFocusRect( &rcFocus ); } - //VERIFY( dcmem.DeleteDC( ) ); } @@ -868,24 +866,6 @@ class COwnerDrawnListCtrl : public CListCtrl { return ( m_showStripes && ( i % 2 != 0 ) ); } - //_Success_( return != COLORREF( 0 ) ) - //COLORREF GetItemBackgroundColor( _In_ const COwnerDrawnListItem* const item ) const { - // const auto itemPos = FindListItem( item ); - // if ( itemPos != -1 ) { - // return GetItemBackgroundColor( itemPos ); - // } - // return COLORREF( 0 ); - // } - - //_Success_( return != COLORREF( 0 ) ) - //COLORREF GetItemSelectionBackgroundColor( _In_ const COwnerDrawnListItem* const item ) const { - // const auto itemPos = FindListItem( item ); - // if ( itemPos != -1 ) { - // return GetItemSelectionBackgroundColor( itemPos ); - // } - // return COLORREF( 0 ); - // } - bool IsItemStripeColor( _In_ const COwnerDrawnListItem* const item ) const { const auto itemPos = FindListItem( item ); if ( itemPos >= 0 ) { @@ -1134,7 +1114,7 @@ class COwnerDrawnListCtrl : public CListCtrl { } CClientDC dc( const_cast< COwnerDrawnListCtrl* >( this ) ); - RECT rc { 0, 0, 1000, 1000 }; + RECT rc { 0, 0, 1000, NODE_HEIGHT }; INT width = 0; INT dummy = rc.left; @@ -1213,8 +1193,8 @@ class COwnerDrawnListCtrl : public CListCtrl { { WM_NOTIFY, static_cast( static_cast( HDN_DIVIDERDBLCLICKW ) ), - static_cast( 0 ), - static_cast( 0 ), + static_cast( 0u ), + static_cast( 0u ), AfxSigNotify_v, reinterpret_cast(static_cast< void (AFX_MSG_CALL CCmdTarget::*)(NMHDR*, LRESULT*) >(&ThisClass::OnHdnDividerdblclick)) }, @@ -1222,8 +1202,8 @@ class COwnerDrawnListCtrl : public CListCtrl { { WM_NOTIFY, static_cast( static_cast( HDN_DIVIDERDBLCLICKA ) ), - static_cast( 0 ), - static_cast( 0 ), + static_cast( 0u ), + static_cast( 0u ), AfxSigNotify_v, reinterpret_cast(static_cast< void (AFX_MSG_CALL CCmdTarget::*)(NMHDR*, LRESULT*) >(&ThisClass::OnHdnDividerdblclick)) }, @@ -1231,8 +1211,8 @@ class COwnerDrawnListCtrl : public CListCtrl { { WM_NOTIFY, static_cast( static_cast( HDN_ITEMCLICKW ) ), - static_cast( 0 ), - static_cast( 0 ), + static_cast( 0u ), + static_cast( 0u ), AfxSigNotify_v, reinterpret_cast(static_cast< void (AFX_MSG_CALL CCmdTarget::*)(NMHDR*, LRESULT*) >(&ThisClass::OnHdnItemclick)) }, @@ -1240,8 +1220,8 @@ class COwnerDrawnListCtrl : public CListCtrl { { WM_NOTIFY, static_cast( static_cast( HDN_ITEMCLICKA ) ), - static_cast( 0 ), - static_cast( 0 ), + static_cast( 0u ), + static_cast( 0u ), AfxSigNotify_v, reinterpret_cast(static_cast< void (AFX_MSG_CALL CCmdTarget::*)(NMHDR*, LRESULT*) >(&ThisClass::OnHdnItemclick)) }, @@ -1250,8 +1230,8 @@ class COwnerDrawnListCtrl : public CListCtrl { { WM_NOTIFY, static_cast( static_cast( HDN_ITEMDBLCLICKW ) ), - static_cast( 0 ), - static_cast( 0 ), + static_cast( 0u ), + static_cast( 0u ), AfxSigNotify_v, reinterpret_cast(static_cast< void (AFX_MSG_CALL CCmdTarget::*)(NMHDR*, LRESULT*) >(&ThisClass::OnHdnItemdblclick)) }, @@ -1259,8 +1239,8 @@ class COwnerDrawnListCtrl : public CListCtrl { { WM_NOTIFY, static_cast( static_cast( HDN_ITEMDBLCLICKA ) ), - static_cast( 0 ), - static_cast( 0 ), + static_cast( 0u ), + static_cast( 0u ), AfxSigNotify_v, reinterpret_cast(static_cast< void (AFX_MSG_CALL CCmdTarget::*)(NMHDR*, LRESULT*) >(&ThisClass::OnHdnItemdblclick)) }, @@ -1269,8 +1249,8 @@ class COwnerDrawnListCtrl : public CListCtrl { { WM_NOTIFY, static_cast( static_cast( HDN_ITEMCHANGINGW ) ), - static_cast( 0 ), - static_cast( 0 ), + static_cast( 0u ), + static_cast( 0u ), AfxSigNotify_v, reinterpret_cast(static_cast(&ThisClass::OnHdnItemchanging)) }, @@ -1278,8 +1258,8 @@ class COwnerDrawnListCtrl : public CListCtrl { { WM_NOTIFY, static_cast( static_cast( HDN_ITEMCHANGINGA ) ), - static_cast( 0 ), - static_cast( 0 ), + static_cast( 0u ), + static_cast( 0u ), AfxSigNotify_v, reinterpret_cast(static_cast(&ThisClass::OnHdnItemchanging)) }, @@ -1287,48 +1267,48 @@ class COwnerDrawnListCtrl : public CListCtrl { { WM_NOTIFY+WM_REFLECT_BASE, static_cast( static_cast( LVN_GETDISPINFO ) ), - 0, - 0, + 0u, + 0u, AfxSigNotify_v, reinterpret_cast(static_cast(&ThisClass::OnLvnGetdispinfo)) }, { WM_ERASEBKGND, - 0, - 0, - 0, + 0u, + 0u, + 0u, AfxSig_bD, static_cast( reinterpret_cast( static_cast(&ThisClass::OnEraseBkgnd) ) ) }, { WM_VSCROLL, - 0, - 0, - 0, + 0u, + 0u, + 0u, AfxSig_vwwW, static_cast( reinterpret_cast( static_cast(&ThisClass::OnVScroll) ) ) }, { WM_SHOWWINDOW, - 0, - 0, - 0, + 0u, + 0u, + 0u, AfxSig_vbw, static_cast( reinterpret_cast( static_cast(&ThisClass::OnShowWindow) ) ) }, { WM_DESTROY, - 0, - 0, - 0, + 0u, + 0u, + 0u, AfxSig_vv, static_cast( reinterpret_cast( static_cast(&ThisClass::OnDestroy) ) ) }, { - 0, - 0, - 0, - 0, + 0u, + 0u, + 0u, + 0u, AfxSig_end, (AFX_PMSG)( 0 ) } @@ -1693,7 +1673,7 @@ namespace{ } template - void build_array_of_rects_from_subitem_rects( _In_ _In_range_( 1, count ) const size_t thisLoopSize, _In_ _In_reads_( thisLoopSize ) const column::ENUM_COL( &subitems_temp )[ count ], _Out_ _Out_writes_( thisLoopSize ) RECT( &rects_temp )[ count ], _In_ PDRAWITEMSTRUCT pdis, _In_ const COwnerDrawnListCtrl* const owner_drawn_list_ctrl, _In_ CHeaderCtrl* const thisHeaderCtrl ) { + void build_array_of_rects_from_subitem_rects( _In_ _In_range_( 1, count ) const size_t thisLoopSize, _In_ _In_reads_( thisLoopSize ) const column::ENUM_COL( &subitems_temp )[ count ], _Out_ _Out_writes_( thisLoopSize ) RECT( &rects_temp )[ count ], _In_ const PDRAWITEMSTRUCT pdis, _In_ const COwnerDrawnListCtrl* const owner_drawn_list_ctrl, _In_ CHeaderCtrl* const thisHeaderCtrl ) { for ( size_t i = 0; i < thisLoopSize; ++i ) { rects_temp[ i ] = owner_drawn_list_ctrl->GetWholeSubitemRect( static_cast( pdis->itemID ), subitems_temp[ i ], thisHeaderCtrl ); } diff --git a/WinDirStat/windirstat/stdafx.h b/WinDirStat/windirstat/stdafx.h index 6b10202..020b659 100644 --- a/WinDirStat/windirstat/stdafx.h +++ b/WinDirStat/windirstat/stdafx.h @@ -159,7 +159,7 @@ static_assert( _WIN32_WINNT >= 0x0600, "" ); // Add support for ATL/WTL //#define _WTL_FORWARD_DECLARE_CSTRING #define _WTL_NO_AUTOMATIC_NAMESPACE - +//_ATL_NO_AUTOMATIC_NAMESPACE #include // base ATL classes