← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3234: table-tree fixes

 

------------------------------------------------------------
revno: 3234
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sat 2013-03-23 17:45:15 +0100
message:
  table-tree fixes
modified:
  dwt/src/widgets/TableTree.cpp
  dwt/test/TableTreeTest.cpp
  win32/TransferView.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dwt/src/widgets/TableTree.cpp'
--- dwt/src/widgets/TableTree.cpp	2013-03-22 14:59:39 +0000
+++ dwt/src/widgets/TableTree.cpp	2013-03-23 16:45:15 +0000
@@ -113,17 +113,26 @@
 
 void TableTree::collapse(LPARAM parent) {
 	util::HoldRedraw hold { this };
-	for(auto child: items[parent].children) {
-		auto pos = findData(child);
-		if(pos != -1) {
-			sendMsg(LVM_DELETEITEM, pos, 0);
-		}
+
+	auto pos = findData(parent);
+	auto n = items[parent].children.size();
+
+	// assume children are all at the right pos.
+	for(size_t i = 0; i < n; ++i) {
+		sendMsg(LVM_DELETEITEM, pos + 1, 0);
 	}
+
 	items[parent].switchExp(*this);
+
+	// special case, see TableTreeTest
+	if(n == 1 && pos == static_cast<int>(size()) - 1) {
+		Control::redraw(false);
+	}
 }
 
 void TableTree::expand(LPARAM parent) {
 	util::HoldRedraw hold { this };
+
 	LVITEM item = { LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_INDENT, findData(parent) };
 	item.pszText = LPSTR_TEXTCALLBACK;
 	item.iImage = I_IMAGECALLBACK;
@@ -133,7 +142,9 @@
 		item.lParam = child;
 		sendMsg(LVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&item));
 	}
+
 	resort();
+
 	items[parent].switchExp(*this);
 }
 
@@ -272,10 +283,11 @@
 
 bool TableTree::handleLeftMouseDown(const MouseEvent& me) {
 	auto hit = hitTest(me.pos);
-	if(hit.second == 0) {
+	if(hit.second == 0) { // first column
 		auto it = items.find(getData(hit.first));
 		if(it != items.end() && it->second.glyphRect.contains(ClientCoordinate(me.pos, this).getPoint())) {
 			it->second.expanded ? collapse(it->first) : expand(it->first);
+			return true;
 		}
 	}
 	return false;

=== modified file 'dwt/test/TableTreeTest.cpp'
--- dwt/test/TableTreeTest.cpp	2013-03-16 14:40:25 +0000
+++ dwt/test/TableTreeTest.cpp	2013-03-23 16:45:15 +0000
@@ -6,6 +6,8 @@
 
 using dwt::tstring;
 
+#if 1 // make this 0 to test a redraw problem that occurs when the last parent has 1 child.
+
 const size_t COLUMNS = 3;
 const size_t ROWS = 100;
 
@@ -14,6 +16,18 @@
 
 const auto IMAGE_SIZE = 32;
 
+#else
+
+const size_t COLUMNS = 3;
+const size_t ROWS = 10;
+
+const size_t PARENT = 9;
+const size_t CHILDREN = 1;
+
+const auto IMAGE_SIZE = 32;
+
+#endif
+
 struct Item {
 	tstring texts[COLUMNS];
 };

=== modified file 'win32/TransferView.cpp'
--- win32/TransferView.cpp	2013-03-22 16:30:58 +0000
+++ win32/TransferView.cpp	2013-03-23 16:45:15 +0000
@@ -133,12 +133,10 @@
 	switch(col) {
 	case COLUMN_STATUS:
 		{
-			// avoid returning 0
-			auto ret = !a->transferred && !b->transferred ? compare(a->size, b->size) :
+			return !a->transferred && !b->transferred ? compare(a->size, b->size) :
 				!b->transferred ? -1 :
 				!a->transferred ? 1 :
 				compare(a->size / a->transferred, b->size / b->transferred);
-			return ret ? ret : compare(a->getText(COLUMN_PATH), b->getText(COLUMN_PATH));
 		}
 	case COLUMN_TIMELEFT: return compare(a->timeleft(), b->timeleft());
 	case COLUMN_SPEED: return compare(a->speed, b->speed);
@@ -563,7 +561,7 @@
 		auto col = data.iSubItem;
 		if(col == COLUMN_STATUS) {
 			auto& info = *reinterpret_cast<ItemInfo*>(data.nmcd.lItemlParam);
-			auto connInfo = dynamic_cast<const ConnectionInfo*>(&info);
+			auto connInfo = dynamic_cast<ConnectionInfo*>(&info);
 			if((!connInfo || connInfo->status == ConnectionInfo::STATUS_RUNNING) && info.size > 0 && info.transferred >= 0) {
 				int item = static_cast<int>(data.nmcd.dwItemSpec);
 				drawProgress(data.nmcd.hdc, transfers->getRect(item, col, LVIR_BOUNDS), item, col,