// headers
// -----------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "treectlg.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
wxGenericTreeItem *m_itemEdited;
wxString m_startValue;
bool m_finished;
+ bool m_aboutToFinish;
DECLARE_EVENT_TABLE()
DECLARE_NO_COPY_CLASS(wxTreeTextCtrl)
int m_height; // height of this item
// use bitfields to save size
- int m_isCollapsed :1;
- int m_hasHilight :1; // same as focused
- int m_hasPlus :1; // used for item which doesn't have
+ unsigned int m_isCollapsed :1;
+ unsigned int m_hasHilight :1; // same as focused
+ unsigned int m_hasPlus :1; // used for item which doesn't have
// children but has a [+] button
- int m_isBold :1; // render the label in bold font
- int m_ownsAttr :1; // delete attribute when done
+ unsigned int m_isBold :1; // render the label in bold font
+ unsigned int m_ownsAttr :1; // delete attribute when done
DECLARE_NO_COPY_CLASS(wxGenericTreeItem)
};
{
m_owner = owner;
m_finished = false;
+ m_aboutToFinish = false;
int w = m_itemEdited->GetWidth(),
h = m_itemEdited->GetHeight();
void wxTreeTextCtrl::Finish()
{
- if ( !m_finished )
+ if ( !m_finished )
{
m_owner->ResetTextControl();
switch ( event.m_keyCode )
{
case WXK_RETURN:
+ m_aboutToFinish = true;
// Notify the owner about the changes
AcceptChanges();
-
// Even if vetoed, close the control (consistent with MSW)
Finish();
-
break;
case WXK_ESCAPE:
void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &event )
{
- if ( !m_finished )
+ if ( !m_finished && !m_aboutToFinish )
{
- AcceptChanges();
// We must finish regardless of success, otherwise we'll get
// focus problems:
Finish();
+
+ if ( !AcceptChanges() )
+ m_owner->OnRenameCancelled( m_itemEdited );
}
// We must let the native text control handle focus, too, otherwise
- // it could have problems with the cursor (e.g., in wxGTK):
+ // it could have problems with the cursor (e.g., in wxGTK).
event.Skip();
}
void wxGenericTreeCtrl::SetWindowStyle(const long styles)
{
- if (!HasFlag(wxTR_HIDE_ROOT) && (styles & wxTR_HIDE_ROOT))
+ // Do not try to expand the root node if it hasn't been created yet
+ if (m_anchor && !HasFlag(wxTR_HIDE_ROOT) && (styles & wxTR_HIDE_ROOT))
{
// if we will hide the root, make sure children are visible
m_anchor->SetHasPlus();
{
if ( select )
{
- DoSelectItem(itemId);
+ DoSelectItem(itemId, !HasFlag(wxTR_MULTIPLE));
}
else // deselect
{
}
int total_h = GetLineHeight(item);
+ bool drawItemBackground = false;
if ( item->IsSelected() )
{
#else
dc.SetBrush(*(m_hasFocus ? m_hilightBrush : m_hilightUnfocusedBrush));
#endif
+ drawItemBackground = true;
}
else
{
wxColour colBg;
if ( attr && attr->HasBackgroundColour() )
+ {
+ drawItemBackground = true;
colBg = attr->GetBackgroundColour();
+ }
else
+ {
colBg = m_backgroundColour;
+ }
dc.SetBrush(wxBrush(colBg, wxSOLID));
}
dc.DrawRectangle( item->GetX() + image_w - 2, item->GetY()+offset,
item->GetWidth() - image_w + 2, total_h-offset );
}
- else
+ // On GTK+ 2, drawing a 'normal' background is wrong for themes that
+ // don't allow backgrounds to be customized. Not drawing the background,
+ // except for custom item backgrounds, works for both kinds of theme.
+ else if (drawItemBackground)
{
dc.DrawRectangle( item->GetX()-2, item->GetY()+offset,
item->GetWidth()+2, total_h-offset );
case WXK_MENU:
{
+ // Use the item's bounding rectangle to determine position for the event
+ wxRect ItemRect;
+ GetBoundingRect(m_current, ItemRect, true);
+
wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_MENU, GetId() );
event.m_item = m_current;
+ // Use the left edge, vertical middle
+ event.m_pointDrag = wxPoint(ItemRect.GetX(),
+ ItemRect.GetY() + ItemRect.GetHeight() / 2);
event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event );
break;
nevent.m_pointDrag = CalcScrolledPosition(pt);
nevent.SetEventObject(this);
event.Skip(!GetEventHandler()->ProcessEvent(nevent));
+
+ // Consistent with MSW (for now), send the ITEM_MENU *after*
+ // the RIGHT_CLICK event. TODO: This behavior may change.
+ wxTreeEvent nevent2(wxEVT_COMMAND_TREE_ITEM_MENU, GetId());
+ nevent2.m_item = item;
+ nevent2.m_pointDrag = CalcScrolledPosition(pt);
+ nevent2.SetEventObject(this);
+ GetEventHandler()->ProcessEvent(nevent2);
}
else if ( event.LeftUp() )
{
// this facilitates multiple-item drag-and-drop
- if (item && HasFlag(wxTR_MULTIPLE))
+ if ( /* item && */ HasFlag(wxTR_MULTIPLE))
{
wxArrayTreeItemIds selections;
size_t count = GetSelections(selections);