Skip to content

Commit

Permalink
tracked down issue with tiny expand icon
Browse files Browse the repository at this point in the history
Rects are not being properly initialized in the first place!

Also: manually expanded IMPLEMENT_DYNCREATE and DECLARE_DYNAMIC in
graphview
  • Loading branch information
ariccio committed Feb 20, 2015
1 parent 2752036 commit 1837212
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 144 deletions.
17 changes: 12 additions & 5 deletions WinDirStat/windirstat/TreeListControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down
9 changes: 7 additions & 2 deletions WinDirStat/windirstat/globalhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
179 changes: 169 additions & 10 deletions WinDirStat/windirstat/graphview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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( )
Expand All @@ -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<CRuntimeClass*>( &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<void (AFX_MSG_CALL CWnd::*)(UINT, int, int)>( &ThisClass::OnSize))
},

{
WM_LBUTTONDOWN,
0,
0,
0,
AfxSig_vwp,
(AFX_PMSG)(AFX_PMSGW) (static_cast<void (AFX_MSG_CALL CWnd::*)(UINT, CPoint)>( &ThisClass::OnLButtonDown))
},
{
WM_SETFOCUS,
0,
0,
0,
AfxSig_vW,
(AFX_PMSG)(AFX_PMSGW)(static_cast<void (AFX_MSG_CALL CWnd::*)(CWnd*)>( &ThisClass::OnSetFocus))
},
{
WM_CONTEXTMENU,
0,
0,
0,
AfxSig_vWp,
(AFX_PMSG)(AFX_PMSGW)(static_cast<void (AFX_MSG_CALL CWnd::*)(CWnd*, CPoint)>( &ThisClass::OnContextMenu))
},
{
WM_MOUSEMOVE,
0,
0,
0,
AfxSig_vwp,
(AFX_PMSG)(AFX_PMSGW)(static_cast<void (AFX_MSG_CALL CWnd::*)(UINT, CPoint)>( &ThisClass::OnMouseMove))
},
{
WM_DESTROY,
0,
0,
0,
AfxSig_vv,
(AFX_PMSG)(AFX_PMSGW)(static_cast<void (AFX_MSG_CALL CWnd::*)(void)>( &ThisClass::OnDestroy))
},
{
WM_TIMER,
0,
0,
0,
AfxSig_v_up_v,
(AFX_PMSG)(AFX_PMSGW)(static_cast<void (AFX_MSG_CALL CWnd::*)(UINT_PTR)>( &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" ) );
Expand Down Expand Up @@ -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 );
Expand Down
64 changes: 58 additions & 6 deletions WinDirStat/windirstat/graphview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<CRuntimeClass*>( &CGraphView::classCGraphView );
}

static CObject* PASCAL CreateObject( ) {
return new CGraphView;
}

//DECLARE_DYNCREATE(CGraphView)

public:
//virtual ~CGraphView();
Expand Down Expand Up @@ -98,22 +129,38 @@ 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
CBitmap m_dimmed; // Dimmed view. Used during refresh to avoid the ooops-effect.
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);
Expand All @@ -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();
};
Expand Down
Loading

0 comments on commit 1837212

Please sign in to comment.