I just toyed around with ListBox in your controls.cpp tutorial example. If you step through the Insert code you will notice
that DefaultRowCMP<...> is not called (line 1443-1446).
In this particular example it doesn't make any difference though:
Code:
m_lb->SetSortCmp(GG::ListBox::DefaultRowCmp<GG::ListBox::Row>());
m_lb->Insert(new CustomTextRow("Number", 3));
m_lb->Insert(new CustomTextRow("Number", 5));
m_lb->Insert(new CustomTextRow("Number", 1));
m_lb->Insert(new CustomTextRow("Number", 7));
m_lb->Insert(new CustomTextRow("Number", 2));
m_lb->Insert(new CustomTextRow("Number", 4));
m_lb->Insert(new CustomTextRow("Number", 6));
m_lb->SetSortCol(1);
Whereas in "Insert" the vertical row positions are determined correctly, any later sorting (by calling SetSortCol or SetStyle) doesn't update them.
I was wondering anyway wouldn't it be more elegant to have row as a lightweight object that only knows how high it is, and where it's cells are aligned horizontally. But the position is determined by ListBox?
Then to fix the problem that the head row gets deleted during Clear, i just made a little fix. It's not that elegant but it works:
Code:
Index: src/ListBox.cpp
===================================================================
--- src/ListBox.cpp>----(revision 623)
+++ src/ListBox.cpp>----(working copy)
@@ -901,7 +901,9 @@
bool signal = !m_rows.empty(); // inhibit signal if the list box was already empty
m_rows.clear();
m_caret = -1;
+ DetachChild(m_header_row); //header_row gets deleted in DeleteChildren() without this
DeleteChildren();
+ AttachChild(m_header_row);
m_vscroll = 0;
m_hscroll = 0;
m_first_row_shown = m_first_col_shown = 0;