X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bdb310a72026e7781cda51fd3fc353cbec9151ed..2c1c448a24f343997e60d62a220bbeb4a58bfc7e:/src/generic/treectlg.cpp diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index e9a1973d8b..19b6d7184f 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -44,7 +44,7 @@ class WXDLLEXPORT wxGenericTreeItem; -WX_DEFINE_ARRAY(wxGenericTreeItem *, wxArrayGenericTreeItems); +WX_DEFINE_EXPORTED_ARRAY(wxGenericTreeItem *, wxArrayGenericTreeItems); //WX_DEFINE_OBJARRAY(wxArrayTreeItemIds); // ---------------------------------------------------------------------------- @@ -89,6 +89,7 @@ public: const wxString &name = wxTextCtrlNameStr ); void OnChar( wxKeyEvent &event ); + void OnKeyUp( wxKeyEvent &event ); void OnKillFocus( wxFocusEvent &event ); private: @@ -178,10 +179,10 @@ public: // status inquiries bool HasChildren() const { return !m_children.IsEmpty(); } - bool IsSelected() const { return m_hasHilight; } + bool IsSelected() const { return m_hasHilight != 0; } bool IsExpanded() const { return !m_isCollapsed; } bool HasPlus() const { return m_hasPlus || HasChildren(); } - bool IsBold() const { return m_isBold; } + bool IsBold() const { return m_isBold != 0; } // attributes // get them - may be NULL @@ -266,6 +267,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxTreeTextCtrl,wxTextCtrl); BEGIN_EVENT_TABLE(wxTreeTextCtrl,wxTextCtrl) EVT_CHAR (wxTreeTextCtrl::OnChar) + EVT_KEY_UP (wxTreeTextCtrl::OnKeyUp) EVT_KILL_FOCUS (wxTreeTextCtrl::OnKillFocus) END_EVENT_TABLE() @@ -318,6 +320,21 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event ) event.Skip(); } +void wxTreeTextCtrl::OnKeyUp( wxKeyEvent &event ) +{ + // auto-grow the textctrl: + wxSize parentSize = m_owner->GetSize(); + wxPoint myPos = GetPosition(); + wxSize mySize = GetSize(); + int sx, sy; + GetTextExtent(GetValue() + _T("MM"), &sx, &sy); + if (myPos.x + sx > parentSize.x) sx = parentSize.x - myPos.x; + if (mySize.x > sx) sx = mySize.x; + SetSize(sx, -1); + + event.Skip(); +} + void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) { if (!wxPendingDelete.Member(this)) @@ -615,6 +632,8 @@ void wxGenericTreeCtrl::Init() m_imageListNormal = m_imageListState = (wxImageList *) NULL; + m_ownsImageListNormal = + m_ownsImageListState = FALSE; m_dragCount = 0; m_isDragging = FALSE; @@ -658,6 +677,8 @@ wxGenericTreeCtrl::~wxGenericTreeCtrl() DeleteAllItems(); delete m_renameTimer; + if (m_ownsImageListNormal) delete m_imageListNormal; + if (m_ownsImageListState) delete m_imageListState; } // ----------------------------------------------------------------------------- @@ -1536,7 +1557,7 @@ void wxGenericTreeCtrl::ScrollTo(const wxTreeItemId &item) // We have to call this here because the label in // question might just have been added and no screen // update taken place. - if (m_dirty) wxYield(); + if (m_dirty) wxYieldIfNeeded(); wxGenericTreeItem *gitem = (wxGenericTreeItem*) item.m_pItem; @@ -1629,7 +1650,10 @@ wxImageList *wxGenericTreeCtrl::GetStateImageList() const void wxGenericTreeCtrl::SetImageList(wxImageList *imageList) { + if (m_ownsImageListNormal) delete m_imageListNormal; + m_imageListNormal = imageList; + m_ownsImageListNormal = FALSE; if ( !m_imageListNormal ) return; @@ -1656,7 +1680,21 @@ void wxGenericTreeCtrl::SetImageList(wxImageList *imageList) void wxGenericTreeCtrl::SetStateImageList(wxImageList *imageList) { + if (m_ownsImageListState) delete m_imageListState; m_imageListState = imageList; + m_ownsImageListState = FALSE; +} + +void wxGenericTreeCtrl::AssignImageList(wxImageList *imageList) +{ + SetImageList(imageList); + m_ownsImageListNormal = TRUE; +} + +void wxGenericTreeCtrl::AssignStateImageList(wxImageList *imageList) +{ + SetStateImageList(imageList); + m_ownsImageListState = TRUE; } // ----------------------------------------------------------------------------- @@ -1732,7 +1770,15 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) dc.SetBrush(wxBrush(colBg, wxSOLID)); } - dc.DrawRectangle( item->GetX()-2, item->GetY(), item->GetWidth()+2, total_h ); + 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(), item->GetWidth() - image_w + 2, total_h ); + } + else + dc.DrawRectangle( item->GetX()-2, item->GetY(), item->GetWidth()+2, total_h ); if ( image != NO_IMAGE ) { @@ -2165,7 +2211,7 @@ wxTreeItemId wxGenericTreeCtrl::HitTest(const wxPoint& point, int& flags) // We have to call this here because the label in // question might just have been added and no screen // update taken place. - if (m_dirty) wxYield(); + if (m_dirty) wxYieldIfNeeded(); wxClientDC dc(this); PrepareDC(dc); @@ -2180,7 +2226,10 @@ wxTreeItemId wxGenericTreeCtrl::HitTest(const wxPoint& point, int& flags) 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); + if (m_anchor) + return m_anchor->HitTest( wxPoint(x, y), this, flags); + else + return wxTreeItemId(); } // get the bounding rectangle of the item (or of its label only) @@ -2222,7 +2271,7 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item ) // We have to call this here because the label in // question might just have been added and no screen // update taken place. - if (m_dirty) wxYield(); + if (m_dirty) wxYieldIfNeeded(); wxString s = m_currentEdit->GetText(); int x = m_currentEdit->GetX(); @@ -2254,8 +2303,13 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item ) x = dc.LogicalToDeviceX( x ); y = dc.LogicalToDeviceY( y ); - wxTreeTextCtrl *text = new wxTreeTextCtrl( - this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) ); + wxTreeTextCtrl *text = new wxTreeTextCtrl(this, -1, + &m_renameAccept, + &m_renameRes, + this, + s, + wxPoint(x-4,y-4), + wxSize(w+11,h+8)); text->SetFocus(); } @@ -2365,7 +2419,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) // highlight the current drop target if any DrawDropEffect(m_dropTarget); - wxYield(); + wxYieldIfNeeded(); } } else if ( (event.LeftUp() || event.RightUp()) && m_isDragging ) @@ -2396,7 +2450,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) SetCursor(m_oldCursor); - wxYield(); + wxYieldIfNeeded(); } else { @@ -2411,6 +2465,9 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, GetId()); nevent.m_item = (long) item; nevent.m_code = 0; + CalcScrolledPosition(x, y, + &nevent.m_pointDrag.x, + &nevent.m_pointDrag.y); nevent.SetEventObject(this); GetEventHandler()->ProcessEvent(nevent); } @@ -2431,13 +2488,26 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) m_lastOnSame = FALSE; } } - else + else // !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick() { if ( event.LeftDown() ) { m_lastOnSame = item == m_current; } + if ( flags & wxTREE_HITTEST_ONITEMBUTTON ) + { + // only toggle the item for a single click, double click on + // the button doesn't do anything (it toggles the item twice) + if ( event.LeftDown() ) + { + Toggle( item ); + } + + // don't select the item if the button was clicked + return; + } + // how should the selection work for this event? bool is_multiple, extended_select, unselect_others; EventFlagsToSelType(GetWindowStyleFlag(), @@ -2445,13 +2515,6 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) event.ControlDown(), is_multiple, extended_select, unselect_others); - if ( (flags & wxTREE_HITTEST_ONITEMBUTTON) && event.LeftDown() ) - { - Toggle( item ); - if ( is_multiple ) - return; - } - SelectItem(item, unselect_others, extended_select); if ( event.LeftDClick() ) @@ -2463,6 +2526,9 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() ); nevent.m_item = (long) item; nevent.m_code = 0; + CalcScrolledPosition(x, y, + &nevent.m_pointDrag.x, + &nevent.m_pointDrag.y); nevent.SetEventObject( this ); GetEventHandler()->ProcessEvent( nevent ); }