X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c0de7af40b81699af98095d782617b517d76699e..e7b3d6babbc006f2936be6827d0b826adbbc82e4:/src/generic/treectrl.cpp diff --git a/src/generic/treectrl.cpp b/src/generic/treectrl.cpp index 67fe811ede..cc6128ab61 100644 --- a/src/generic/treectrl.cpp +++ b/src/generic/treectrl.cpp @@ -313,13 +313,16 @@ wxGenericTreeItem *wxGenericTreeItem::HitTest( const wxPoint& point, if ((point.x >= m_x) && (point.x <= m_x+m_width)) { - int image_w,image_h; - + int image_w = -1; + int image_h; + // assuming every image (normal and selected ) has the same size ! - theTree->m_imageListNormal->GetSize(m_image, image_w, image_h); - if (point.x<=m_x+image_w+1) + if ((m_image!=-1) && theTree->m_imageListNormal) + theTree->m_imageListNormal->GetSize(m_image, image_w, image_h); + + if ((image_w != -1) && (point.x <= m_x + image_w + 1)) flags|=wxTREE_HITTEST_ONITEMICON; - else + else flags|=wxTREE_HITTEST_ONITEMLABEL; return this; @@ -369,7 +372,7 @@ END_EVENT_TABLE() void wxTreeCtrl::Init() { - m_current = + m_current = m_key_current = m_anchor = (wxGenericTreeItem *) NULL; m_hasFocus = FALSE; @@ -403,10 +406,13 @@ bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, wxScrolledWindow::Create( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name ); +#if wxUSE_VALIDATORS SetValidator( validator ); +#endif SetBackgroundColour( *wxWHITE ); - m_dottedPen = wxPen( *wxBLACK, 0, 0 ); +// m_dottedPen = wxPen( "grey", 0, wxDOT ); + m_dottedPen = wxPen( "grey", 0, 0 ); return TRUE; } @@ -923,7 +929,7 @@ void wxTreeCtrl::UnselectAllChildren(wxGenericTreeItem *item) { item->SetHilight(FALSE); RefreshLine(item); - + if (item->HasChildren()) { wxArrayGenericTreeItems& children = item->GetChildren(); @@ -942,7 +948,7 @@ void wxTreeCtrl::UnselectAll() // To stop we must have crt_itemSetHilight(select); RefreshLine(crt_item); - + if (crt_item==last_item) return TRUE; if (crt_item->HasChildren()) @@ -976,7 +982,7 @@ bool wxTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem *crt_item, wxGenericT for ( size_t n = 0; n < count; ++n ) if (TagAllChildrenUntilLast(children[n], last_item, select)) return TRUE; } - + return FALSE; } @@ -986,48 +992,50 @@ void wxTreeCtrl::SelectItemRange(wxGenericTreeItem *item1, wxGenericTreeItem *it wxGenericTreeItem *first=NULL, *last=NULL; // choice first' and 'last' between item1 and item2 - if (item1->GetY()GetY()) + if (item1->GetY()GetY()) { first=item1; last=item2; } - else + else { first=item2; last=item1; } bool select=m_current->HasHilight(); - + if (TagAllChildrenUntilLast(first,last,select)) return; - TagNextChildren(first,last,select); + TagNextChildren(first,last,select); } -void wxTreeCtrl::SelectItem(const wxTreeItemId& itemId, - bool unselect_others, +void wxTreeCtrl::SelectItem(const wxTreeItemId& itemId, + bool unselect_others, bool extended_select) -{ +{ + wxCHECK_RET( itemId.IsOk(), _T("invalid tree item") ); + bool is_single=!(GetWindowStyleFlag() & wxTR_MULTIPLE); //wxCHECK_RET( ( (!unselect_others) && is_single), // _T("this is a single selection tree") ); // to keep going anyhow !!! - if (is_single) + if (is_single) { unselect_others=TRUE; extended_select=FALSE; } wxGenericTreeItem *item = itemId.m_pItem; - + wxTreeEvent event( wxEVT_COMMAND_TREE_SEL_CHANGING, GetId() ); event.m_item = item; event.m_itemOld = m_current; event.SetEventObject( this ); // TODO : Here we don't send any selection mode yet ! - + if ( GetEventHandler()->ProcessEvent( event ) && event.WasVetoed() ) return; @@ -1039,7 +1047,7 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& itemId, } // shift press - if (extended_select) + if (extended_select) { if (m_current == NULL) m_current=m_key_current=GetRootItem().m_pItem; // don't change the mark (m_current) @@ -1084,7 +1092,7 @@ size_t wxTreeCtrl::GetSelections(wxArrayTreeItemIds &array) const } void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item) -{ +{ if (!item.IsOk()) return; wxGenericTreeItem *gitem = item.m_pItem; @@ -1232,7 +1240,7 @@ void wxTreeCtrl::SetImageList(wxImageList *imageList) { m_imageListNormal->GetSize(i, width, height); if(height > m_lineHeight) m_lineHeight = height; - } + } if (m_lineHeight<40) m_lineHeight+=4; // at least 4 pixels (odd such that a line can be drawn in between) else m_lineHeight+=m_lineHeight/10; // otherwise 10% extra spacing @@ -1273,7 +1281,7 @@ int wxTreeCtrl::GetLineHeight(wxGenericTreeItem *item) const if (GetWindowStyleFlag() & wxTR_HAS_VARIABLE_ROW_HIGHT) return item->GetHeight(); else - return m_lineHeight; + return m_lineHeight; } void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) @@ -1384,13 +1392,13 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int & dc.SetPen( *wxGREY_PEN ); dc.SetBrush( *wxWHITE_BRUSH ); dc.DrawRectangle( horizX+(m_indent-5), y-4, 11, 9 ); + dc.SetPen( *wxBLACK_PEN ); dc.DrawLine( horizX+(m_indent-2), y, horizX+(m_indent+3), y ); - if (!item->IsExpanded()) - { dc.DrawLine( horizX+m_indent, y-2, horizX+m_indent, y+3 ); - } + + dc.SetPen( m_dottedPen ); } if (item->HasHilight()) @@ -1406,7 +1414,7 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int & PaintItem(item, dc); - dc.SetPen( *wxBLACK_PEN ); + dc.SetPen( m_dottedPen ); dc.SetTextForeground( *wxBLACK ); dc.SetBrush( *wxWHITE_BRUSH ); } @@ -1417,10 +1425,10 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int & PaintItem(item, dc); - dc.SetPen( *wxBLACK_PEN ); + dc.SetPen( m_dottedPen ); } } - + y = oldY+GetLineHeight(item); if (item->IsExpanded()) @@ -1475,7 +1483,7 @@ void wxTreeCtrl::DrawLine(wxTreeItemId &item, bool below) wxPaintDC dc(this); PrepareDC( dc ); dc.SetLogicalFunction(wxINVERT); - + int w,h,y; GetSize(&w,&h); @@ -1643,7 +1651,8 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event ) else { wxTreeItemId next = GetNextSibling( m_key_current ); - if (next == 0) +// if (next == 0) + if (!next) { wxTreeItemId current = m_key_current; while (current && !next) @@ -1652,7 +1661,8 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event ) if (current) next = GetNextSibling( current ); } } - if (next != 0) +// if (next != 0) + if (next) { SelectItem( next, unselect_others, extended_select ); m_key_current=next.m_pItem; @@ -1719,7 +1729,7 @@ wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& flags) if (point.x>w) flags|=wxTREE_HITTEST_TORIGHT; if (point.y<0) flags|=wxTREE_HITTEST_ABOVE; if (point.y>h) flags|=wxTREE_HITTEST_BELOW; - + return m_anchor->HitTest( wxPoint(x, y), this, flags); } @@ -1798,7 +1808,7 @@ void wxTreeCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) ) } void wxTreeCtrl::CalculateSize( wxGenericTreeItem *item, wxDC &dc ) -{ +{ long text_w = 0; long text_h = 0; // TODO : check for boldness. Here with suppose that font normal and bold @@ -1839,7 +1849,7 @@ void wxTreeCtrl::CalculateLevel( wxGenericTreeItem *item, wxDC &dc, int level, i int horizX = level*m_indent; CalculateSize( item, dc ); - + // set its position item->SetX( horizX+m_indent+m_spacing ); item->SetY( y );