// 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)
{
(*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();
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();
m_parent = parent;
m_attr = (wxTreeItemAttr *)NULL;
-
+
// We don't know the height here yet.
m_width = 0;
m_height = 0;
}
flags|=wxTREE_HITTEST_NOWHERE;
-
+
return (wxGenericTreeItem*) NULL;
}
wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT),
wxSOLID
);
+ m_normalBrush = new wxBrush
+ (
+ wxSystemSettings::GetSystemColour(wxSYS_COLOUR_LISTBOX),
+ wxSOLID
+ );
m_imageListNormal =
m_imageListState = (wxImageList *) NULL;
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 );
wxTreeCtrl::~wxTreeCtrl()
{
wxDELETE( m_hilightBrush );
+ wxDELETE( m_normalBrush );
DeleteAllItems();
wxArrayGenericTreeItems& children = item.m_pItem->GetChildren();
if ( (size_t)cookie < children.Count() )
{
- return children.Item(cookie++);
+ return children.Item((size_t)cookie++);
}
else
{
if (!HasFlag(wxTR_MULTIPLE))
{
m_current = m_key_current = m_anchor;
- m_current->SetHilight( TRUE );
+ m_current->SetHilight( TRUE );
}
Refresh();
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);
}
crt_item->SetHilight(select);
RefreshLine(crt_item);
- if (crt_item==last_item)
+ if (crt_item==last_item)
return TRUE;
if (crt_item->HasChildren())
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;
// choice first' and 'last' between item1 and item2
if (item1->GetY()<item2->GetY())
- {
+ {
first=item1;
last=item2;
}
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
}
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 )
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));
else
colText = *wxBLACK;
- brush = wxWHITE_BRUSH;
+ brush = m_normalBrush;
}
// prepare to draw
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 );
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())
{
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);
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);
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) &&
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)
{
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);