📄 treelistctrl.cpp
字号:
if(w != info.GetWidth()) {
m_total_col_width += info.GetWidth() - w;
m_owner->AdjustMyScrollbars();
m_owner->m_dirty = TRUE;
}
Refresh();
}
// ---------------------------------------------------------------------------
// wxTreeListItem
// ---------------------------------------------------------------------------
wxTreeListItem::wxTreeListItem(wxTreeListMainWindow *owner,
wxTreeListItem *parent,
const wxArrayString& text,
int image, int selImage,
wxTreeItemData *data)
: m_text(text)
{
m_images[wxTreeItemIcon_Normal] = image;
m_images[wxTreeItemIcon_Selected] = selImage;
m_images[wxTreeItemIcon_Expanded] = NO_IMAGE;
m_images[wxTreeItemIcon_SelectedExpanded] = NO_IMAGE;
m_data = data;
m_x = m_y = 0;
m_isCollapsed = TRUE;
m_hasHilight = FALSE;
m_hasPlus = FALSE;
m_isBold = FALSE;
m_owner = owner;
m_parent = parent;
m_attr = (wxTreeItemAttr *)NULL;
m_ownsAttr = FALSE;
// We don't know the height here yet.
m_width = 0;
m_height = 0;
}
wxTreeListItem::~wxTreeListItem()
{
delete m_data;
if (m_ownsAttr) delete m_attr;
wxASSERT_MSG( m_children.IsEmpty(),
wxT("please call DeleteChildren() before deleting the item") );
}
void wxTreeListItem::DeleteChildren(wxTreeListMainWindow *tree)
{
size_t count = m_children.Count();
for ( size_t n = 0; n < count; n++ )
{
wxTreeListItem *child = m_children[n];
if (tree)
tree->SendDeleteEvent(child);
child->DeleteChildren(tree);
delete child;
}
m_children.Empty();
}
void wxTreeListItem::SetText( const wxString &text )
{
if(m_text.GetCount() > 0) m_text[0] = text;
else {
m_text.Add(text);
}
}
size_t wxTreeListItem::GetChildrenCount(bool recursively) const
{
size_t count = m_children.Count();
if ( !recursively )
return count;
size_t total = count;
for (size_t n = 0; n < count; ++n)
{
total += m_children[n]->GetChildrenCount();
}
return total;
}
void wxTreeListItem::GetSize( int &x, int &y,
const wxTreeListMainWindow *theButton )
{
int bottomY=m_y+theButton->GetLineHeight(this);
if ( y < bottomY ) y = bottomY;
int width = m_x + m_width;
if ( x < width ) x = width;
if (IsExpanded())
{
size_t count = m_children.Count();
for ( size_t n = 0; n < count; ++n )
{
m_children[n]->GetSize( x, y, theButton );
}
}
}
wxTreeListItem *wxTreeListItem::HitTest(const wxPoint& point,
const wxTreeListMainWindow *theCtrl,
int &flags,
int level)
{
// for a hidden root node, don't evaluate it, but do evaluate children
if (!(theCtrl->HasFlag(wxTR_HIDE_ROOT) && (level == 0)))
{
// evaluate the item
int h = theCtrl->GetLineHeight(this);
if ((point.y > m_y) && (point.y <= m_y + h))
{
// check for above/below middle
int y_mid = m_y + h/2;
if (point.y < y_mid )
flags |= wxTREE_HITTEST_ONITEMUPPERPART;
else
flags |= wxTREE_HITTEST_ONITEMLOWERPART;
// check for button hit
int xCross = m_x; // - theCtrl->GetLineSpacing();
#ifdef __WXMAC__
// according to the drawing code the triangels are drawn
// at -4 , -4 from the position up to +10/+10 max
if ((point.x > xCross-4) && (point.x < xCross+10) &&
(point.y > y_mid-4) && (point.y < y_mid+10) &&
HasPlus() && theCtrl->HasButtons() )
#else
// 5 is the size of the plus sign
if ((point.x > xCross-6) && (point.x < xCross+6) &&
(point.y > y_mid-6) && (point.y < y_mid+6) &&
HasPlus() && theCtrl->HasButtons() )
#endif
{
flags |= wxTREE_HITTEST_ONITEMBUTTON;
return this;
}
// check for image hit
if (theCtrl->m_imgWidth > 0 && GetImage() != NO_IMAGE) {
int imgX = m_x - theCtrl->m_imgWidth2;
if (HasPlus() && theCtrl->HasButtons())
imgX += theCtrl->m_btnWidth + LINEATROOT;
int imgY = y_mid - theCtrl->m_imgHeight2;
if ((point.x >= imgX) && (point.x <= (imgX + theCtrl->m_imgWidth)) &&
(point.y >= imgY) && (point.y <= (imgY + theCtrl->m_imgHeight))) {
flags |= wxTREE_HITTEST_ONITEMICON;
return this;
}
}
// check for label hit
int lblX = m_x - theCtrl->m_imgWidth2 + theCtrl->m_imgWidth + MARGIN;
if ((point.x >= lblX) && (point.x <= (m_x + m_width)) &&
(point.y >= m_y) && (point.y <= (m_y + h))) {
flags |= wxTREE_HITTEST_ONITEMLABEL;
return this;
}
// else check for indent
if (point.x < m_x) {
flags |= wxTREE_HITTEST_ONITEMINDENT;
return this;
}
// else check for item right???
if (point.x > m_x + m_width) {
flags |= wxTREE_HITTEST_ONITEMRIGHT;
return this;
}
}
// if children are expanded, fall through to evaluate them
if (m_isCollapsed) return (wxTreeListItem*) NULL;
}
// evaluate children
size_t count = m_children.Count();
for ( size_t n = 0; n < count; n++ )
{
wxTreeListItem *res = m_children[n]->HitTest(point, theCtrl,
flags, level + 1);
if ( res != NULL )
return res;
}
return (wxTreeListItem*) NULL;
}
// ALB
wxTreeListItem *wxTreeListItem::HitTest(const wxPoint& point,
const wxTreeListMainWindow *theCtrl,
int &flags, int& column, int level)
{
column = theCtrl->GetMainColumn(); //-1;
wxTreeListItem* res = HitTest(point, theCtrl, flags, level);
if(!res) {
column = -1;
return res;
}
wxTreeListHeaderWindow* header_win = theCtrl->m_owner->GetHeaderWindow();
if (point.x >= header_win->GetWidth())
column = -1;
else if(flags & wxTREE_HITTEST_ONITEMINDENT) {
int x = 0;
for(size_t i = 0; i < theCtrl->GetMainColumn(); ++i) {
if (!header_win->GetColumnShown(i)) continue;
int w = header_win->GetColumnWidth(i);
if(point.x >= x && point.x < x+w) {
flags ^= wxTREE_HITTEST_ONITEMINDENT;
flags |= wxTREE_HITTEST_ONITEMCOLUMN;
column = i;
return res;
}
}
}
else if(flags & wxTREE_HITTEST_ONITEMRIGHT) {
int x = 0;
size_t i;
for(i = 0; i < theCtrl->GetMainColumn()+1; ++i) {
if (!header_win->GetColumnShown(i)) continue;
x += header_win->GetColumnWidth(i);
}
for(i = theCtrl->GetMainColumn()+1; i < theCtrl->GetColumnCount(); ++i) {
if (!header_win->GetColumnShown(i)) continue;
int w = header_win->GetColumnWidth(i);
if(point.x >= x && point.x < x+w) {
flags ^= wxTREE_HITTEST_ONITEMRIGHT;
flags |= wxTREE_HITTEST_ONITEMCOLUMN;
column = i;
return res;
}
x += w;
}
}
return res;
}
int wxTreeListItem::GetCurrentImage() const
{
int image = NO_IMAGE;
if ( IsExpanded() )
{
if ( IsSelected() )
{
image = GetImage(wxTreeItemIcon_SelectedExpanded);
}
if ( image == NO_IMAGE )
{
// we usually fall back to the normal item, but try just the
// expanded one (and not selected) first in this case
image = GetImage(wxTreeItemIcon_Expanded);
}
}
else // not expanded
{
if ( IsSelected() )
image = GetImage(wxTreeItemIcon_Selected);
}
// maybe it doesn't have the specific image we want,
// try the default one instead
if ( image == NO_IMAGE ) image = GetImage();
return image;
}
// ---------------------------------------------------------------------------
// wxTreeListMainWindow implementation
// ---------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxTreeListMainWindow, wxScrolledWindow)
BEGIN_EVENT_TABLE(wxTreeListMainWindow, wxScrolledWindow)
EVT_PAINT (wxTreeListMainWindow::OnPaint)
EVT_MOUSE_EVENTS (wxTreeListMainWindow::OnMouse)
EVT_CHAR (wxTreeListMainWindow::OnChar)
EVT_SET_FOCUS (wxTreeListMainWindow::OnSetFocus)
EVT_KILL_FOCUS (wxTreeListMainWindow::OnKillFocus)
EVT_IDLE (wxTreeListMainWindow::OnIdle)
EVT_SCROLLWIN (wxTreeListMainWindow::OnScroll)
END_EVENT_TABLE()
// ---------------------------------------------------------------------------
// construction/destruction
// ---------------------------------------------------------------------------
void wxTreeListMainWindow::Init()
{
m_current = m_key_current = m_anchor = (wxTreeListItem *) NULL;
m_hasFocus = FALSE;
m_dirty = FALSE;
m_lineHeight = LINEHEIGHT;
m_indent = MININDENT; // min. indent
m_linespacing = 4;
m_imgWidth = 0, m_imgWidth2 = 0;
m_imgHeight = 0, m_imgHeight2 = 0;
m_hilightBrush = new wxBrush
(
wxSystemSettings::GetColour
(
wxSYS_COLOUR_HIGHLIGHT
),
wxSOLID
);
m_hilightUnfocusedBrush = new wxBrush
(
wxSystemSettings::GetColour
(
wxSYS_COLOUR_BTNSHADOW
),
wxSOLID
);
m_imageListNormal = m_imageListButtons =
m_imageListState = (wxImageList *) NULL;
m_ownsImageListNormal = m_ownsImageListButtons =
m_ownsImageListState = FALSE;
m_dragCount = 0;
m_isDragging = FALSE;
m_dropTarget = m_oldSelection = (wxTreeListItem *)NULL;
m_renameTimer = new wxTreeListRenameTimer( this );
m_lastOnSame = FALSE;
m_findTimer = new wxTimer (this, -1);
m_underMouse = NULL;
#ifdef __WXMAC_CARBON__
m_normalFont.MacCreateThemeFont( kThemeViewsFont ) ;
#else
m_normalFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
#endif
m_boldFont = wxFont( m_normalFont.GetPointSize(),
m_normalFont.GetFamily(),
m_normalFont.GetStyle(),
wxBOLD,
m_normalFont.GetUnderlined(),
m_normalFont.GetFaceName(),
m_normalFont.GetEncoding());
}
bool wxTreeListMainWindow::Create(wxTreeListCtrl *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxValidator &validator,
const wxString& name )
{
#ifdef __WXMAC__
if ( !(style & wxTR_DONT_ADJUST_MAC))
{
int major,minor;
wxGetOsVersion( &major, &minor );
if (style & wxTR_HAS_BUTTONS) style |= wxTR_TWIST_BUTTONS;
if (style & wxTR_HAS_BUTTONS) style &= ~wxTR_HAS_BUTTONS;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -