wxTreeListItem *m_shiftItem; // item, where the shift key was pressed
wxTreeListItem *m_editItem; // item, which is currently edited
wxTreeListItem *m_selectItem; // current selected item, not with wxTR_MULTIPLE
-
+ wxTreeListItem *m_select_me;
+
int m_curColumn;
int m_btnWidth, m_btnWidth2;
// implementation
// ===========================================================================
+
+// ---------------------------------------------------------------------------
+// internal helpers
+// ---------------------------------------------------------------------------
+
+// check if the given item is under another one
+static bool IsDescendantOf(const wxTreeListItem *parent, const wxTreeListItem *item)
+{
+ while ( item )
+ {
+ if ( item == parent )
+ {
+ // item is a descendant of parent
+ return true;
+ }
+
+ item = item->GetItemParent();
+ }
+
+ return false;
+}
+
+
// ---------------------------------------------------------------------------
// wxTreeListRenameTimer (internal)
// ---------------------------------------------------------------------------
void wxTreeListHeaderWindow::RefreshColLabel(int col)
{
- if ( col > GetColumnCount() )
+ if ( col >= GetColumnCount() )
return;
int x = 0;
m_shiftItem = (wxTreeListItem*)NULL;
m_editItem = (wxTreeListItem*)NULL;
m_selectItem = (wxTreeListItem*)NULL;
-
+ m_select_me = (wxTreeListItem*)NULL;
+
m_curColumn = -1; // no current column
m_hasFocus = false;
if (major < 10) style |= wxTR_ROW_LINES;
#endif
- wxScrolledWindow::Create (parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name);
+ wxScrolledWindow::Create (parent, id, pos, size, style|wxHSCROLL|wxVSCROLL|wxWANTS_CHARS, name);
#if wxUSE_VALIDATORS
SetValidator(validator);
}
wxTreeListItem *parent = item->GetItemParent();
+
+
+ // m_select_me records whether we need to select
+ // a different item, in idle time.
+ if ( m_select_me && IsDescendantOf(item, m_select_me) )
+ {
+ m_select_me = parent;
+ }
+
+ if ( IsDescendantOf(item, m_curItem) )
+ {
+ // Don't silently change the selection:
+ // do it properly in idle time, so event
+ // handlers get called.
+
+ // m_current = parent;
+ m_curItem = NULL;
+ m_select_me = parent;
+ }
+
+ // remove the item from the tree
if (parent) {
parent->GetChildren().Remove (item); // remove by value
}
SendDeleteEvent (item);
if (m_selectItem == item) m_selectItem = (wxTreeListItem*)NULL;
item->DeleteChildren (this);
+
+ if (item == m_select_me)
+ m_select_me = NULL;
+
delete item;
}
if (unselect_others) {
m_selectItem = (item->IsSelected())? item: (wxTreeListItem*)NULL;
}
-
}
// send event to user code
default:
if (event.GetKeyCode() >= (int)' ') {
if (!m_findTimer->IsRunning()) m_findStr.Clear();
- m_findStr.Append (event.GetKeyCode());
+ m_findStr.Append ((char)event.GetKeyCode());
m_findTimer->Start (FIND_TIMER_TICKS, wxTIMER_ONE_SHOT);
wxTreeItemId prev = m_curItem? (wxTreeItemId*)m_curItem: (wxTreeItemId*)NULL;
while (true) {
m_curItem = (wxTreeListItem*)newItem.m_pItem; // make the new item the current item
RefreshLine (oldItem);
}
-
}
wxTreeItemId wxTreeListMainWindow::HitTest (const wxPoint& point, int& flags, int& column) {
* we actually redraw the tree when everything is over */
if (!m_dirty) return;
-
m_dirty = false;
+ // Check if we need to select the root item
+ // because nothing else has been selected.
+ // Delaying it means that we can invoke event handlers
+ // as required, when a first item is selected.
+ if (!m_owner->HasFlag(wxTR_MULTIPLE) && !m_owner->GetSelection().IsOk())
+ {
+ if (m_select_me)
+ m_owner->SelectItem(m_select_me);
+ else if (m_owner->GetRootItem().IsOk())
+ m_owner->SelectItem(m_owner->GetRootItem());
+ m_select_me = NULL;
+ m_curItem = (wxTreeListItem*)m_owner->GetSelection().m_pItem;
+
+ }
+
CalculatePositions();
Refresh();
AdjustMyScrollbars();
void wxTreeListCtrl::SetColumnWidth(int column, int width)
{
+ if (width == wxLIST_AUTOSIZE_USEHEADER)
+ {
+ wxFont font = m_header_win->GetFont();
+ m_header_win->GetTextExtent(m_header_win->GetColumnText(column), &width, NULL, NULL, NULL, font.Ok()? &font: NULL);
+ //search wxTreeListHeaderWindow::OnPaint to understand this:
+ width += 2*EXTRA_WIDTH + MARGIN;
+ }
+ else if (width == wxLIST_AUTOSIZE)
+ {
+ width = m_main_win->GetBestColumnWidth(column);
+ }
+
m_header_win->SetColumnWidth (column, width);
m_header_win->Refresh();
}