X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/674ac8b919eecbc201b5f23b470a567cd0565e10..d73dd2b2fc9557b95a342f00f032c3c52833297d:/src/generic/treectrl.cpp diff --git a/src/generic/treectrl.cpp b/src/generic/treectrl.cpp index af2d4cf2e3..64b87f0b13 100644 --- a/src/generic/treectrl.cpp +++ b/src/generic/treectrl.cpp @@ -182,6 +182,23 @@ private: // implementation // ============================================================================= +// ---------------------------------------------------------------------------- +// private functions +// ---------------------------------------------------------------------------- + +// translate the key or mouse event flags to the type of selection we're +// dealing with +static void EventFlagsToSelType(long style, + bool shiftDown, + bool ctrlDown, + bool *is_multiple, + bool *extended_select, + bool *unselect_others) +{ + *is_multiple = (style & wxTR_MULTIPLE) != 0; + *extended_select = shiftDown && is_multiple; + *unselect_others = !(extended_select || (ctrlDown && is_multiple)); +} // ----------------------------------------------------------------------------- // wxTreeRenameTimer (internal) @@ -235,14 +252,23 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event ) { (*m_accept) = TRUE; (*m_res) = GetValue(); - m_owner->SetFocus(); + + if (!wxPendingDelete.Member(this)) + wxPendingDelete.Append(this); + + if ((*m_accept) && ((*m_res) != m_startValue)) + m_owner->OnRenameAccept(); + return; } if (event.m_keyCode == WXK_ESCAPE) { (*m_accept) = FALSE; (*m_res) = ""; - m_owner->SetFocus(); + + if (!wxPendingDelete.Member(this)) + wxPendingDelete.Append(this); + return; } event.Skip(); @@ -250,9 +276,8 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event ) void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) { - if (wxPendingDelete.Member(this)) return; - - wxPendingDelete.Append(this); + if (!wxPendingDelete.Member(this)) + wxPendingDelete.Append(this); if ((*m_accept) && ((*m_res) != m_startValue)) m_owner->OnRenameAccept(); @@ -302,7 +327,7 @@ wxGenericTreeItem::wxGenericTreeItem(wxGenericTreeItem *parent, m_parent = parent; m_attr = (wxTreeItemAttr *)NULL; - + // We don't know the height here yet. m_width = 0; m_height = 0; @@ -458,7 +483,7 @@ wxGenericTreeItem *wxGenericTreeItem::HitTest( const wxPoint& point, } flags|=wxTREE_HITTEST_NOWHERE; - + return (wxGenericTreeItem*) NULL; } @@ -533,6 +558,11 @@ void wxTreeCtrl::Init() wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID ); + m_normalBrush = new wxBrush + ( + wxSystemSettings::GetSystemColour(wxSYS_COLOUR_LISTBOX), + wxSOLID + ); m_imageListNormal = m_imageListState = (wxImageList *) NULL; @@ -563,7 +593,7 @@ bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, SetValidator( validator ); #endif - SetBackgroundColour( *wxWHITE ); + SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) ); // m_dottedPen = wxPen( "grey", 0, wxDOT ); too slow under XFree86 m_dottedPen = wxPen( "grey", 0, 0 ); @@ -573,6 +603,7 @@ bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, wxTreeCtrl::~wxTreeCtrl() { wxDELETE( m_hilightBrush ); + wxDELETE( m_normalBrush ); DeleteAllItems(); @@ -781,7 +812,7 @@ wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& item, long& cookie) co wxArrayGenericTreeItems& children = item.m_pItem->GetChildren(); if ( (size_t)cookie < children.Count() ) { - return children.Item(cookie++); + return children.Item((size_t)cookie++); } else { @@ -913,7 +944,7 @@ wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text, if (!HasFlag(wxTR_MULTIPLE)) { m_current = m_key_current = m_anchor; - m_current->SetHilight( TRUE ); + m_current->SetHilight( TRUE ); } Refresh(); @@ -946,7 +977,7 @@ wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parentId, int index = parent->GetChildren().Index(idPrevious.m_pItem); wxASSERT_MSG( index != wxNOT_FOUND, wxT("previous item in wxTreeCtrl::InsertItem() is not a sibling") ); - + return DoInsertItem(parentId, (size_t)++index, text, image, selImage, data); } @@ -1171,7 +1202,7 @@ bool wxTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem *crt_item, wxGenericT crt_item->SetHilight(select); RefreshLine(crt_item); - if (crt_item==last_item) + if (crt_item==last_item) return TRUE; if (crt_item->HasChildren()) @@ -1180,9 +1211,9 @@ bool wxTreeCtrl::TagAllChildrenUntilLast(wxGenericTreeItem *crt_item, wxGenericT size_t count = children.Count(); for ( size_t n = 0; n < count; ++n ) { - if (TagAllChildrenUntilLast(children[n], last_item, select)) + if (TagAllChildrenUntilLast(children[n], last_item, select)) return TRUE; - } + } } return FALSE; @@ -1195,7 +1226,7 @@ void wxTreeCtrl::SelectItemRange(wxGenericTreeItem *item1, wxGenericTreeItem *it // choice first' and 'last' between item1 and item2 if (item1->GetY()GetY()) - { + { first=item1; last=item2; } @@ -1433,16 +1464,16 @@ void wxTreeCtrl::SetImageList(wxImageList *imageList) m_lineHeight = (int)(dc.GetCharHeight() + 4); int width = 0, height = 0, n = m_imageListNormal->GetImageCount(); - + for (int i = 0; i < n ; i++) { m_imageListNormal->GetSize(i, width, height); if (height > m_lineHeight) m_lineHeight = height; } - if (m_lineHeight < 40) + if (m_lineHeight < 40) m_lineHeight += 2; // at least 2 pixels - else + else m_lineHeight += m_lineHeight/10; // otherwise 10% extra spacing #endif } @@ -1506,6 +1537,13 @@ void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) int total_h = GetLineHeight(item); + wxColour colBg; + if ( attr && attr->HasBackgroundColour() ) + colBg = attr->GetBackgroundColour(); + else + colBg = m_backgroundColour; + dc.SetBrush(wxBrush(colBg, wxSOLID)); + dc.DrawRectangle( item->GetX()-2, item->GetY(), item->GetWidth()+2, total_h ); if ( image != NO_IMAGE ) @@ -1518,10 +1556,7 @@ void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) dc.DestroyClippingRegion(); } - bool hasBgCol = attr && attr->HasBackgroundColour(); - dc.SetBackgroundMode(hasBgCol ? wxSOLID : wxTRANSPARENT); - if ( hasBgCol ) - dc.SetTextBackground(attr->GetBackgroundColour()); + dc.SetBackgroundMode(wxTRANSPARENT); dc.DrawText( item->GetText(), image_w + item->GetX(), item->GetY() + ((total_h > text_h) ? (total_h - text_h)/2 : 0)); @@ -1592,7 +1627,7 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int & else colText = *wxBLACK; - brush = wxWHITE_BRUSH; + brush = m_normalBrush; } // prepare to draw @@ -1713,7 +1748,7 @@ void wxTreeCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) void wxTreeCtrl::OnChar( wxKeyEvent &event ) { wxTreeEvent te( wxEVT_COMMAND_TREE_KEY_DOWN, GetId() ); - te.m_code = event.KeyCode(); + te.m_code = (int)event.KeyCode(); te.SetEventObject( this ); GetEventHandler()->ProcessEvent( te ); @@ -1723,9 +1758,12 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event ) return; } - bool is_multiple=(GetWindowStyleFlag() & wxTR_MULTIPLE); - bool extended_select=(event.ShiftDown() && is_multiple); - bool unselect_others=!(extended_select || (event.ControlDown() && is_multiple)); + // how should the selection work for this event? + bool is_multiple, extended_select, unselect_others; + EventFlagsToSelType(GetWindowStyleFlag(), + event.ShiftDown(), + event.ControlDown(), + &is_multiple, &extended_select, &unselect_others); switch (event.KeyCode()) { @@ -1905,8 +1943,8 @@ wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& flags) wxClientDC dc(this); PrepareDC(dc); - long x = dc.DeviceToLogicalX( (long)point.x ); - long y = dc.DeviceToLogicalY( (long)point.y ); + wxCoord x = dc.DeviceToLogicalX( point.x ); + wxCoord y = dc.DeviceToLogicalY( point.y ); int w, h; GetSize(&w, &h); @@ -1993,8 +2031,8 @@ void wxTreeCtrl::OnMouse( wxMouseEvent &event ) wxClientDC dc(this); PrepareDC(dc); - long x = dc.DeviceToLogicalX( (long)event.GetX() ); - long y = dc.DeviceToLogicalY( (long)event.GetY() ); + wxCoord x = dc.DeviceToLogicalX( event.GetX() ); + wxCoord y = dc.DeviceToLogicalY( event.GetY() ); int flags=0; wxGenericTreeItem *item = m_anchor->HitTest( wxPoint(x,y), this, flags); @@ -2026,12 +2064,12 @@ void wxTreeCtrl::OnMouse( wxMouseEvent &event ) if (item == NULL) return; /* we hit the blank area */ if (event.RightDown()) { - wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,GetId()); - nevent.m_item=item; - nevent.m_code=0; - nevent.SetEventObject(this); - GetEventHandler()->ProcessEvent(nevent); - return; + wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,GetId()); + nevent.m_item=item; + nevent.m_code=0; + nevent.SetEventObject(this); + GetEventHandler()->ProcessEvent(nevent); + return; } if (event.LeftUp() && (item == m_current) && @@ -2042,9 +2080,12 @@ void wxTreeCtrl::OnMouse( wxMouseEvent &event ) return; } - bool is_multiple=(GetWindowStyleFlag() & wxTR_MULTIPLE); - bool extended_select=(event.ShiftDown() && is_multiple); - bool unselect_others=!(extended_select || (event.ControlDown() && is_multiple)); + // how should the selection work for this event? + bool is_multiple, extended_select, unselect_others; + EventFlagsToSelType(GetWindowStyleFlag(), + event.ShiftDown(), + event.ControlDown(), + &is_multiple, &extended_select, &unselect_others); if (onButton) { @@ -2105,9 +2146,9 @@ void wxTreeCtrl::CalculateSize( wxGenericTreeItem *item, wxDC &dc ) int total_h = (image_h > text_h) ? image_h : text_h; - if (total_h < 40) + if (total_h < 40) total_h += 2; // at least 2 pixels - else + else total_h += total_h/10; // otherwise 10% extra spacing item->SetHeight(total_h);