------------------------------------------------------------ revno: 3216 committer: poy <p...@123gen.com> branch nick: trunk timestamp: Sun 2013-03-10 13:52:24 +0100 message: slightly improve tree lists modified: dwt/src/widgets/Header.cpp dwt/src/widgets/Tree.cpp dwt/test/TreeTest.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/Header.cpp' --- dwt/src/widgets/Header.cpp 2013-01-18 21:28:38 +0000 +++ dwt/src/widgets/Header.cpp 2013-03-10 12:52:24 +0000 @@ -36,7 +36,8 @@ const TCHAR Header::windowClass[] = WC_HEADER; Header::Seed::Seed() : -BaseType::Seed(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS) + /// @todo add HDS_DRAGDROP when the tree has better support for col ordering + BaseType::Seed(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS) { } === modified file 'dwt/src/widgets/Tree.cpp' --- dwt/src/widgets/Tree.cpp 2013-01-18 21:28:38 +0000 +++ dwt/src/widgets/Tree.cpp 2013-03-10 12:52:24 +0000 @@ -226,8 +226,14 @@ } HeaderPtr Tree::getHeader() { - if(header == NULL) { + if(!header) { header = WidgetCreator<Header>::create(this); + header->setFont(getFont()); + + // todo if col 0 was dragged, reset texts... + header->onRaw([this](WPARAM, LPARAM) -> LRESULT { tree->redraw(); return 0; }, Message(WM_NOTIFY, HDN_ENDDRAG)); + header->onRaw([this](WPARAM, LPARAM) -> LRESULT { tree->redraw(); return 0; }, Message(WM_NOTIFY, HDN_ITEMCHANGED)); + layout(); } @@ -306,12 +312,20 @@ for(size_t i = 0; i < ret.size(); ++i) { ret[i] = getColumn(i); } - return ret; } std::vector<int> Tree::getColumnOrderImpl() const { - return std::vector<int>(); // TODO + std::vector<int> ret; + if(!header) { + return ret; + } + + ret.resize(getColumnCount()); + if(!Header_GetOrderArray(header->handle(), ret.size(), ret.data())) { + ret.clear(); + } + return ret; } void Tree::setColumnOrderImpl(const std::vector<int>& columns) { @@ -319,44 +333,51 @@ } std::vector<int> Tree::getColumnWidthsImpl() const { - return std::vector<int>(); // TODO + std::vector<int> ret; + if(!header) { + return ret; + } + + ret.resize(getColumnCount()); + for(size_t i = 0; i < ret.size(); ++i) { + ret[i] = header->getWidth(i); + } + return ret; } void Tree::setColumnWidthImpl(unsigned column, int width) { // TODO } -static const int INSET = 3; - LRESULT Tree::prePaint(NMTVCUSTOMDRAW& nmcd) { return CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYPOSTPAINT; } LRESULT Tree::prePaintItem(NMTVCUSTOMDRAW& nmcd) { - // Clip the default item drawing to the column width + // Clip the default item (column 0) drawing to the column width auto clipRect = nmcd.nmcd.rc; - auto w = header->getWidth(0); + auto w = header->getWidth(Header_OrderToIndex(header->handle(), 0)); clipRect.right = clipRect.left + w; - auto hRgn = ::CreateRectRgn (clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); + Region region { clipRect }; POINT pt = { 0 }; - auto hDC = nmcd.nmcd.hdc; - ::GetWindowOrgEx(hDC, &pt); - ::OffsetRgn (hRgn, -pt.x, -pt.y); - ::SelectClipRgn (hDC, hRgn); - ::DeleteObject (hRgn); + FreeCanvas canvas { nmcd.nmcd.hdc }; + ::GetWindowOrgEx(canvas.handle(), &pt); + ::OffsetRgn(region.handle(), -pt.x, -pt.y); + ::SelectClipRgn(canvas.handle(), region.handle()); - ::SaveDC(hDC); + ::SaveDC(canvas.handle()); return CDRF_DODEFAULT | CDRF_NOTIFYPOSTPAINT; } LRESULT Tree::postPaintItem(NMTVCUSTOMDRAW& nmcd) { - auto hDC = nmcd.nmcd.hdc; - ::RestoreDC (hDC, -1); + FreeCanvas canvas { nmcd.nmcd.hdc }; + + ::RestoreDC(canvas.handle(), -1); // Remove previously set clip region - ::SelectClipRgn(hDC, NULL); + ::SelectClipRgn(canvas.handle(), nullptr); auto item = (HTREEITEM)nmcd.nmcd.dwItemSpec; @@ -364,25 +385,23 @@ auto clientSize = tree->getClientSize(); - int x = header->getWidth(0); + int x = header->getWidth(Header_OrderToIndex(header->handle(), 0)); auto columns = getColumnCount(); - ::SetTextColor(hDC, nmcd.clrText); - ::SetBkColor(hDC, nmcd.clrTextBk); + canvas.setTextColor(nmcd.clrText); + canvas.setBkColor(nmcd.clrTextBk); + auto selectFont(canvas.select(*getFont())); for(size_t i = 1; i < columns; ++i) { - auto width = header->getWidth(i); - - RECT rect = { x, nmcd.nmcd.rc.top, x + width, nmcd.nmcd.rc.bottom }; - - rect.left += INSET - 1; - - if (rect.left < rect.right) { - auto text = getText(item, i); - - if (!text.empty()) { - int flags = DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS; - ::DrawText (hDC, text.c_str(), text.size (), &rect, flags); + auto index = Header_OrderToIndex(header->handle(), i); + auto width = header->getWidth(index); + + if(width > 0) { + Rectangle rect { x, nmcd.nmcd.rc.top, width, nmcd.nmcd.rc.bottom - nmcd.nmcd.rc.top }; + + auto text = getText(item, index); + if(!text.empty()) { + canvas.drawText(text, rect, DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_END_ELLIPSIS); } } @@ -398,7 +417,7 @@ } LRESULT Tree::draw(NMTVCUSTOMDRAW& nmcd) { - if(nmcd.nmcd.rc.left >= nmcd.nmcd.rc.right || nmcd.nmcd.rc.top >= nmcd.nmcd.rc.bottom || getColumnCount() < 2) { + if(!header || nmcd.nmcd.rc.left >= nmcd.nmcd.rc.right || nmcd.nmcd.rc.top >= nmcd.nmcd.rc.bottom) { return CDRF_DODEFAULT; } === modified file 'dwt/test/TreeTest.cpp' --- dwt/test/TreeTest.cpp 2012-12-08 17:44:30 +0000 +++ dwt/test/TreeTest.cpp 2013-03-10 12:52:24 +0000 @@ -11,8 +11,9 @@ window->create(); window->onClosing([] { return ::PostQuitMessage(0), true; }); - auto tree = window->addChild(dwt::Tree::Seed()); - //tree.setHeaderVisible(true); + dwt::Tree::Seed seed; + seed.style |= TVS_HASBUTTONS | TVS_LINESATROOT; + auto tree = window->addChild(seed); tree->addColumn(_T("Column 1"), 200, dwt::Column::LEFT); tree->addColumn(_T("Column 2"), 200, dwt::Column::CENTER);
_______________________________________________ Mailing list: https://launchpad.net/~linuxdcpp-team Post to : linuxdcpp-team@lists.launchpad.net Unsubscribe : https://launchpad.net/~linuxdcpp-team More help : https://help.launchpad.net/ListHelp