X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d21d2e5adf7a5acf3b496a9c4e87eab220bd75d8..2d956b58023a4955313a1c1531bc70a0deb0b831:/src/generic/treectlg.cpp diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 86535a229f..562d1a840e 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -59,49 +59,49 @@ static const int NO_IMAGE = -1; // Aqua arrows // ---------------------------------------------------------------------------- - /* XPM */ - static char *aqua_arrow_right[] = { - /* columns rows colors chars-per-pixel */ - "13 11 4 1", - " c None", - "b c #C0C0C0", - "c c #707070", - "d c #A0A0A0", - /* pixels */ - " b ", - " ddb ", - " cccdb ", - " cccccd ", - " ccccccdb ", - " ccccccccd", - " ccccccdb ", - " cccccb ", - " cccdb ", - " ddb ", - " b " - }; - - /* XPM */ - static char *aqua_arrow_down[] = { - /* columns rows colors chars-per-pixel */ - "13 11 4 1", - " c None", - "b c #C0C0C0", - "c c #707070", - "d c #A0A0A0", - /* pixels */ - " ", - " ", - " bdcccccccdb ", - " dcccccccd ", - " bcccccccb ", - " dcccccd ", - " bcccccb ", - " bcccd ", - " dcd ", - " bcb ", - " d " - }; +/* XPM */ +static const char *aqua_arrow_right[] = { +/* columns rows colors chars-per-pixel */ +"13 11 4 1", +" c None", +"b c #C0C0C0", +"c c #707070", +"d c #A0A0A0", +/* pixels */ +" b ", +" ddb ", +" cccdb ", +" cccccd ", +" ccccccdb ", +" ccccccccd", +" ccccccdb ", +" cccccb ", +" cccdb ", +" ddb ", +" b " +}; + +/* XPM */ +static const char *aqua_arrow_down[] = { +/* columns rows colors chars-per-pixel */ +"13 11 4 1", +" c None", +"b c #C0C0C0", +"c c #707070", +"d c #A0A0A0", +/* pixels */ +" ", +" ", +" bdcccccccdb ", +" dcccccccd ", +" bcccccccb ", +" dcccccd ", +" bcccccb ", +" bcccd ", +" dcd ", +" bcb ", +" d " +}; // ----------------------------------------------------------------------------- // private classes @@ -368,7 +368,7 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event ) if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); - + m_finished = TRUE; m_owner->SetFocus(); // This doesn't work. TODO. @@ -424,7 +424,7 @@ void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &event ) (*m_accept) = TRUE; (*m_res) = GetValue(); - + if ((*m_res) != m_startValue) m_owner->OnRenameAccept(); } @@ -669,7 +669,7 @@ void wxGenericTreeCtrl::Init() m_hilightBrush = new wxBrush ( - wxSystemSettings::GetSystemColour + wxSystemSettings::GetColour ( wxSYS_COLOUR_HIGHLIGHT ), @@ -678,7 +678,7 @@ void wxGenericTreeCtrl::Init() m_hilightUnfocusedBrush = new wxBrush ( - wxSystemSettings::GetSystemColour + wxSystemSettings::GetColour ( wxSYS_COLOUR_BTNSHADOW ), @@ -697,7 +697,7 @@ void wxGenericTreeCtrl::Init() m_renameTimer = new wxTreeRenameTimer( this ); m_lastOnSame = FALSE; - m_normalFont = wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT ); + m_normalFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); m_boldFont = wxFont( m_normalFont.GetPointSize(), m_normalFont.GetFamily(), m_normalFont.GetStyle(), @@ -716,7 +716,7 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, #ifdef __WXMAC__ int major,minor; wxGetOsVersion( &major, &minor ); - + if (style & wxTR_HAS_BUTTONS) style |= wxTR_MAC_BUTTONS; if (style & wxTR_HAS_BUTTONS) style &= ~wxTR_HAS_BUTTONS; style &= ~wxTR_LINES_AT_ROOT; @@ -741,9 +741,9 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, wxScrolledWindow::Create( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name ); - // If the tree display has no buttons, but does have - // connecting lines, we can use a narrower layout. - // It may not be a good idea to force this... + // If the tree display has no buttons, but does have + // connecting lines, we can use a narrower layout. + // It may not be a good idea to force this... if (!HasButtons() && !HasFlag(wxTR_NO_LINES)) { m_indent= 10; @@ -754,7 +754,8 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, SetValidator( validator ); #endif - SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) ); + SetForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) ); + SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX) ); // m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86 m_dottedPen = wxPen( wxT("grey"), 0, 0 ); @@ -766,7 +767,7 @@ wxGenericTreeCtrl::~wxGenericTreeCtrl() { delete m_hilightBrush; delete m_hilightUnfocusedBrush; - + if (m_arrowRight) delete m_arrowRight; if (m_arrowDown) delete m_arrowDown; @@ -789,13 +790,13 @@ size_t wxGenericTreeCtrl::GetCount() const void wxGenericTreeCtrl::SetIndent(unsigned int indent) { - m_indent = indent; + m_indent = (unsigned short) indent; m_dirty = TRUE; } void wxGenericTreeCtrl::SetSpacing(unsigned int spacing) { - m_spacing = spacing; + m_spacing = (unsigned short) spacing; m_dirty = TRUE; } @@ -1201,16 +1202,18 @@ wxTreeItemId wxGenericTreeCtrl::AddRoot(const wxString& text, m_anchor = new wxGenericTreeItem((wxGenericTreeItem *)NULL, text, image, selImage, data); + if ( data != NULL ) + { + data->m_pItem = (long) m_anchor; + } + if (HasFlag(wxTR_HIDE_ROOT)) { // if root is hidden, make sure we can navigate // into children m_anchor->SetHasPlus(); - Expand(m_anchor); - } - if ( data != NULL ) - { - data->m_pItem = (long) m_anchor; + m_anchor->Expand(); + CalculatePositions(); } if (!HasFlag(wxTR_MULTIPLE)) @@ -1354,6 +1357,8 @@ void wxGenericTreeCtrl::Expand(const wxTreeItemId& itemId) wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem; wxCHECK_RET( item, _T("invalid item in wxGenericTreeCtrl::Expand") ); + wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT) || itemId != GetRootItem(), + _T("can't expand hidden root") ); if ( !item->HasPlus() ) return; @@ -1398,6 +1403,9 @@ void wxGenericTreeCtrl::ExpandAll(const wxTreeItemId& item) void wxGenericTreeCtrl::Collapse(const wxTreeItemId& itemId) { + wxCHECK_RET( !HasFlag(wxTR_HIDE_ROOT) || itemId != GetRootItem(), + _T("can't collapse hidden root") ); + wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem; if ( !item->IsExpanded() ) @@ -1477,7 +1485,13 @@ void wxGenericTreeCtrl::UnselectAllChildren(wxGenericTreeItem *item) void wxGenericTreeCtrl::UnselectAll() { - UnselectAllChildren((wxGenericTreeItem*) GetRootItem().m_pItem); + wxTreeItemId rootItem = GetRootItem(); + + // the tree might not have the root item at all + if ( rootItem ) + { + UnselectAllChildren((wxGenericTreeItem*) rootItem.m_pItem); + } } // Recursive function ! @@ -1672,10 +1686,22 @@ void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId& item) // first expand all parent branches wxGenericTreeItem *parent = gitem->GetParent(); - while ( parent ) + + if ( HasFlag(wxTR_HIDE_ROOT) ) { - Expand(parent); - parent = parent->GetParent(); + while ( parent != m_anchor ) + { + Expand(parent); + parent = parent->GetParent(); + } + } + else + { + while ( parent ) + { + Expand(parent); + parent = parent->GetParent(); + } } //if (parent) CalculatePositions(); @@ -2046,7 +2072,7 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level wxColour colText; if ( item->IsSelected() ) { - colText = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT); + colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); } else { @@ -2054,7 +2080,7 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level if (attr && attr->HasTextColour()) colText = attr->GetTextColour(); else - colText = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT); + colText = GetForegroundColour(); } // prepare to draw @@ -2108,7 +2134,7 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level else if (HasFlag(wxTR_TWIST_BUTTONS)) { // draw the twisty button here - + if (HasFlag(wxTR_AQUA_BUTTONS)) { if (item->IsExpanded()) @@ -2535,14 +2561,8 @@ wxTreeItemId wxGenericTreeCtrl::HitTest(const wxPoint& point, int& flags) return wxTreeItemId(); } - wxClientDC dc(this); - PrepareDC(dc); - wxCoord x = dc.DeviceToLogicalX( point.x ); - wxCoord y = dc.DeviceToLogicalY( point.y ); - wxGenericTreeItem *hit = m_anchor->HitTest(wxPoint(x, y), - this, - flags, - 0 ); + wxGenericTreeItem *hit = m_anchor->HitTest(CalcUnscrolledPosition(point), + this, flags, 0); if (hit == NULL) { flags = wxTREE_HITTEST_NOWHERE; @@ -2593,10 +2613,10 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item ) if (m_dirty) wxYieldIfNeeded(); wxString s = m_currentEdit->GetText(); - int x = m_currentEdit->GetX(); - int y = m_currentEdit->GetY(); int w = m_currentEdit->GetWidth(); int h = m_currentEdit->GetHeight(); + int x, y; + CalcScrolledPosition(m_currentEdit->GetX(), m_currentEdit->GetY(), &x, &y); int image_h = 0; int image_w = 0; @@ -2617,11 +2637,6 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item ) x += image_w; w -= image_w + 4; // I don't know why +4 is needed - wxClientDC dc(this); - PrepareDC( dc ); - x = dc.LogicalToDeviceX( x ); - y = dc.LogicalToDeviceY( y ); - wxTreeTextCtrl *text = new wxTreeTextCtrl(this, -1, &m_renameAccept, &m_renameRes, @@ -2670,21 +2685,15 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) return; } - wxClientDC dc(this); - PrepareDC(dc); - wxCoord x = dc.DeviceToLogicalX( event.GetX() ); - wxCoord y = dc.DeviceToLogicalY( event.GetY() ); + wxPoint pt = CalcUnscrolledPosition(event.GetPosition()); int flags = 0; - wxGenericTreeItem *item = m_anchor->HitTest( wxPoint(x,y), - this, - flags, - 0 ); + wxGenericTreeItem *item = m_anchor->HitTest(pt, this, flags, 0); if ( event.Dragging() && !m_isDragging ) { if (m_dragCount == 0) - m_dragStart = wxPoint(x,y); + m_dragStart = pt; m_dragCount++; @@ -2761,7 +2770,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) wxTreeEvent event(wxEVT_COMMAND_TREE_END_DRAG, GetId()); event.m_item = (long) item; - event.m_pointDrag = wxPoint(x, y); + event.m_pointDrag = pt; event.SetEventObject(this); (void)GetEventHandler()->ProcessEvent(event); @@ -2787,9 +2796,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) { wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, GetId()); nevent.m_item = (long) item; - CalcScrolledPosition(x, y, - &nevent.m_pointDrag.x, - &nevent.m_pointDrag.y); + nevent.m_pointDrag = CalcScrolledPosition(pt); nevent.SetEventObject(this); GetEventHandler()->ProcessEvent(nevent); } @@ -2850,9 +2857,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) // send activate event first wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() ); nevent.m_item = (long) item; - CalcScrolledPosition(x, y, - &nevent.m_pointDrag.x, - &nevent.m_pointDrag.y); + nevent.m_pointDrag = CalcScrolledPosition(pt); nevent.SetEventObject( this ); if ( !GetEventHandler()->ProcessEvent( nevent ) ) { @@ -2888,7 +2893,10 @@ void wxGenericTreeCtrl::CalculateSize( wxGenericTreeItem *item, wxDC &dc ) wxCoord text_w = 0; wxCoord text_h = 0; - if (item->IsBold()) + wxTreeItemAttr *attr = item->GetAttributes(); + if ( attr && attr->HasFont() ) + dc.SetFont(attr->GetFont()); + else if ( item->IsBold() ) dc.SetFont(m_boldFont); dc.GetTextExtent( item->GetText(), &text_w, &text_h ); @@ -2982,20 +2990,14 @@ void wxGenericTreeCtrl::RefreshSubtree(wxGenericTreeItem *item) { if (m_dirty) return; - wxClientDC dc(this); - PrepareDC(dc); - - int cw = 0; - int ch = 0; - GetClientSize( &cw, &ch ); + wxSize client = GetClientSize(); wxRect rect; - rect.x = dc.LogicalToDeviceX( 0 ); - rect.width = cw; - rect.y = dc.LogicalToDeviceY( item->GetY() ); - rect.height = ch; + CalcScrolledPosition(0, item->GetY(), &rect.x, &rect.y); + rect.width = client.x; + rect.height = client.y; - Refresh( TRUE, &rect ); + Refresh(TRUE, &rect); AdjustMyScrollbars(); } @@ -3004,20 +3006,12 @@ void wxGenericTreeCtrl::RefreshLine( wxGenericTreeItem *item ) { if (m_dirty) return; - wxClientDC dc(this); - PrepareDC( dc ); - - int cw = 0; - int ch = 0; - GetClientSize( &cw, &ch ); - wxRect rect; - rect.x = dc.LogicalToDeviceX( 0 ); - rect.y = dc.LogicalToDeviceY( item->GetY() ); - rect.width = cw; + CalcScrolledPosition(0, item->GetY(), &rect.x, &rect.y); + rect.width = GetClientSize().x; rect.height = GetLineHeight(item); //dc.GetCharHeight() + 6; - Refresh( TRUE, &rect ); + Refresh(TRUE, &rect); } void wxGenericTreeCtrl::RefreshSelected()