From c6f4913a7636367c7f3b677e3a30bbb4e50604e9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Mon, 17 Dec 2001 00:30:23 +0000 Subject: [PATCH] applied patch that adds wxTR_FULL_ROW_HIGHLIGHT to wxTreeCtrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13046 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/treectrl.tex | 4 ++ include/wx/treebase.h | 33 +++++------ src/generic/treectlg.cpp | 115 ++++++++++++++++++++----------------- src/msw/treectrl.cpp | 8 +++ 4 files changed, 92 insertions(+), 68 deletions(-) diff --git a/docs/latex/wx/treectrl.tex b/docs/latex/wx/treectrl.tex index 1b057afcd4..3af18623f5 100644 --- a/docs/latex/wx/treectrl.tex +++ b/docs/latex/wx/treectrl.tex @@ -32,6 +32,10 @@ If both wxTR\_HAS\_BUTTONS and wxTR\_TWIST\_BUTTONS are given, twister buttons are generated. Generic only.} \twocolitem{\windowstyle{wxTR\_NO\_LINES}}{Use this style to hide vertical level connectors.} +\twocolitem{\windowstyle{wxTR\_FULL\_ROW\_HIGHLIGHT}}{Use this style to have the background +colour and the selection highlight extend over the entire horizontal +row of the tree control window. (This flag is ignored under Windows unless you +specified wxTR\_NO\_LINES as well.) } \twocolitem{\windowstyle{wxTR\_LINES\_AT\_ROOT}}{Use this style to show lines between root nodes. Only applicable if wxTR\_HIDE\_ROOT is set and wxTR\_NO\_LINES is not set.} diff --git a/include/wx/treebase.h b/include/wx/treebase.h index fcc8c30811..7a78957235 100644 --- a/include/wx/treebase.h +++ b/include/wx/treebase.h @@ -114,22 +114,23 @@ enum wxTreeItemIcon * wxTreeCtrl flags */ // TODO: maybe renumber these? -#define wxTR_NO_BUTTONS 0x0000 // for convenience -#define wxTR_HAS_BUTTONS 0x0001 // generates a +/- button -#define wxTR_TWIST_BUTTONS 0x0002 // generates a twister button -#define wxTR_NO_LINES 0x0004 // don't generate level connectors -#define wxTR_LINES_AT_ROOT 0x0008 // connect top-level nodes -#define wxTR_MAC_BUTTONS wxTR_TWIST_BUTTONS // backward compatibility -#define wxTR_AQUA_BUTTONS 0x0010 // used internally - -#define wxTR_SINGLE 0x0000 // for convenience -#define wxTR_MULTIPLE 0x0020 // can select multiple items -#define wxTR_EXTENDED 0x0040 // TODO: allow extended selection - -#define wxTR_EDIT_LABELS 0x0200 // can edit item labels -#define wxTR_ROW_LINES 0x0400 // put border around items -#define wxTR_HIDE_ROOT 0x0800 // don't display root node -#define wxTR_HAS_VARIABLE_ROW_HEIGHT 0x0080 // what it says +#define wxTR_NO_BUTTONS 0x0000 // for convenience +#define wxTR_HAS_BUTTONS 0x0001 // generates a +/- button +#define wxTR_TWIST_BUTTONS 0x0002 // generates a twister button +#define wxTR_NO_LINES 0x0004 // don't generate level connectors +#define wxTR_LINES_AT_ROOT 0x0008 // connect top-level nodes +#define wxTR_MAC_BUTTONS wxTR_TWIST_BUTTONS // backward compatibility +#define wxTR_AQUA_BUTTONS 0x0010 // used internally + +#define wxTR_SINGLE 0x0000 // for convenience +#define wxTR_MULTIPLE 0x0020 // can select multiple items +#define wxTR_EXTENDED 0x0040 // TODO: allow extended selection +#define wxTR_FULL_ROW_HIGHLIGHT 0x2000 // highlight full horizontal space + +#define wxTR_EDIT_LABELS 0x0200 // can edit item labels +#define wxTR_ROW_LINES 0x0400 // put border around items +#define wxTR_HIDE_ROOT 0x0800 // don't display root node +#define wxTR_HAS_VARIABLE_ROW_HEIGHT 0x0080 // what it says // TODO: different default styles for wxGTK, wxMotif, whatever? #ifdef __WXMAC__ diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 2a2e7c814d..0b23a9cd09 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -1883,18 +1883,29 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) int offset = HasFlag(wxTR_ROW_LINES) ? 1 : 0; - if ( item->IsSelected() && image != NO_IMAGE ) + if ( HasFlag(wxTR_FULL_ROW_HIGHLIGHT) ) { - // If it's selected, and there's an image, then we should - // take care to leave the area under the image painted in the - // background colour. - dc.DrawRectangle( item->GetX() + image_w - 2, item->GetY()+offset, - item->GetWidth() - image_w + 2, total_h-offset ); + int x, y, w, h; + + DoGetPosition(&x, &y); + DoGetSize(&w, &h); + dc.DrawRectangle(x, item->GetY()+offset, w, total_h-offset); } else { - dc.DrawRectangle( item->GetX()-2, item->GetY()+offset, - item->GetWidth()+2, total_h-offset ); + if ( item->IsSelected() && image != NO_IMAGE ) + { + // If it's selected, and there's an image, then we should + // take care to leave the area under the image painted in the + // background colour. + dc.DrawRectangle( item->GetX() + image_w - 2, item->GetY()+offset, + item->GetWidth() - image_w + 2, total_h-offset ); + } + else + { + dc.DrawRectangle( item->GetX()-2, item->GetY()+offset, + item->GetWidth()+2, total_h-offset ); + } } if ( image != NO_IMAGE ) @@ -1963,6 +1974,50 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level if (IsExposed(exposed_x, exposed_y, 10000, h)) // 10000 = very much { + wxPen *pen = +#ifndef __WXMAC__ + // don't draw rect outline if we already have the + // background color under Mac + (item->IsSelected() && m_hasFocus) ? wxBLACK_PEN : +#endif // !__WXMAC__ + wxTRANSPARENT_PEN; + + wxColour colText; + if ( item->IsSelected() ) + { + colText = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT); + } + else + { + wxTreeItemAttr *attr = item->GetAttributes(); + if (attr && attr->HasTextColour()) + colText = attr->GetTextColour(); + else + colText = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT); + } + + // prepare to draw + dc.SetTextForeground(colText); + dc.SetPen(*pen); + + // draw + PaintItem(item, dc); + + if (HasFlag(wxTR_ROW_LINES)) + { + // if the background colour is white, choose a + // contrasting color for the lines + dc.SetPen(*((GetBackgroundColour() == *wxWHITE) + ? wxMEDIUM_GREY_PEN : wxWHITE_PEN)); + dc.DrawLine(0, y_top, 10000, y_top); + dc.DrawLine(0, y, 10000, y); + } + + // restore DC objects + dc.SetBrush(*wxWHITE_BRUSH); + dc.SetPen(m_dottedPen); + dc.SetTextForeground(*wxBLACK); + if (item->HasPlus() && HasButtons()) // should the item show a button? { if (!HasFlag(wxTR_NO_LINES)) @@ -2069,50 +2124,6 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level x_start = 3; dc.DrawLine(x_start, y_mid, x + m_spacing, y_mid); } - - wxPen *pen = -#ifndef __WXMAC__ - // don't draw rect outline if we already have the - // background color under Mac - (item->IsSelected() && m_hasFocus) ? wxBLACK_PEN : -#endif // !__WXMAC__ - wxTRANSPARENT_PEN; - - wxColour colText; - if ( item->IsSelected() ) - { - colText = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT); - } - else - { - wxTreeItemAttr *attr = item->GetAttributes(); - if (attr && attr->HasTextColour()) - colText = attr->GetTextColour(); - else - colText = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT); - } - - // prepare to draw - dc.SetTextForeground(colText); - dc.SetPen(*pen); - - // draw - PaintItem(item, dc); - - if (HasFlag(wxTR_ROW_LINES)) - { - // if the background colour is white, choose a - // contrasting color for the lines - dc.SetPen(*((GetBackgroundColour() == *wxWHITE) - ? wxMEDIUM_GREY_PEN : wxWHITE_PEN)); - dc.DrawLine(0, y_top, 10000, y_top); - dc.DrawLine(0, y, 10000, y); - } - - // restore DC objects - dc.SetBrush(*wxWHITE_BRUSH); - dc.SetPen(m_dottedPen); - dc.SetTextForeground(*wxBLACK); } if (item->IsExpanded()) diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 69ff37efc2..a0713416ab 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -47,6 +47,7 @@ #if defined(__WIN95__) +#include "wx/app.h" #include "wx/log.h" #include "wx/dynarray.h" #include "wx/imaglist.h" @@ -546,6 +547,13 @@ bool wxTreeCtrl::Create(wxWindow *parent, if ( m_windowStyle & wxTR_LINES_AT_ROOT ) wstyle |= TVS_LINESATROOT; + + if ( m_windowStyle & wxTR_FULL_ROW_HIGHLIGHT ) + { + if ( wxTheApp->GetComCtl32Version() >= 471 ) + wstyle |= TVS_FULLROWSELECT; + } + // using TVS_CHECKBOXES for emulation of a multiselection tree control // doesn't work without the new enough headers -- 2.45.2