void wxListHeaderData::GetItem( wxListItem& item )
{
- item.m_mask = m_mask;
- item.m_text = m_text;
- item.m_image = m_image;
- item.m_format = m_format;
- item.m_width = m_width;
- item.m_state = m_state;
+ long mask = item.m_mask;
+ if ( !mask )
+ {
+ // by default, get everything for backwards compatibility
+ mask = -1;
+ }
+
+ if ( mask & wxLIST_MASK_STATE )
+ item.m_state = m_state;
+ if ( mask & wxLIST_MASK_TEXT )
+ item.m_text = m_text;
+ if ( mask & wxLIST_MASK_IMAGE )
+ item.m_image = m_image;
+ if ( mask & wxLIST_MASK_WIDTH )
+ item.m_width = m_width;
+ if ( mask & wxLIST_MASK_FORMAT )
+ item.m_format = m_format;
}
int wxListHeaderData::GetImage() const
BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow)
EVT_PAINT (wxListHeaderWindow::OnPaint)
EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse)
- EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus)
END_EVENT_TABLE()
void wxListHeaderWindow::Init()
}
}
-void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
-{
- m_owner->SetFocus();
- m_owner->Update();
-}
-
bool wxListHeaderWindow::SendListEvent(wxEventType type, const wxPoint& pos)
{
wxWindow *parent = GetParent();
wxListMainWindow::wxListMainWindow( wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
- const wxSize& size,
- long style,
- const wxString &name )
- : wxWindow( parent, id, pos, size, style, name )
+ const wxSize& size )
+ : wxWindow( parent, id, pos, size,
+ wxWANTS_CHARS | wxBORDER_NONE )
{
Init();
GetParent()->GetId());
evCache.SetEventObject( GetParent() );
evCache.m_oldItemIndex = visibleFrom;
+ evCache.m_item.m_itemId =
evCache.m_itemIndex = visibleTo;
GetParent()->GetEventHandler()->ProcessEvent( evCache );
}
wxListEvent le( command, GetParent()->GetId() );
le.SetEventObject( GetParent() );
+ le.m_item.m_itemId =
le.m_itemIndex = line;
// set only for events which have position
wxCHECK_MSG( (item >= 0) && ((size_t)item < GetItemCount()), NULL,
wxT("wrong index in wxGenericListCtrl::EditLabel()") );
- wxASSERT_MSG( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)),
+ wxASSERT_MSG( textControlClass->IsKindOf(wxCLASSINFO(wxTextCtrl)),
wxT("EditLabel() needs a text control") );
size_t itemEdit = (size_t)item;
wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
le.SetEventObject( GetParent() );
+ le.m_item.m_itemId =
le.m_itemIndex = item;
wxListLineData *data = GetLine(itemEdit);
wxCHECK_MSG( data, NULL, wxT("invalid index in EditLabel()") );
{
wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
le.SetEventObject( GetParent() );
+ le.m_item.m_itemId =
le.m_itemIndex = itemEdit;
wxListLineData *data = GetLine(itemEdit);
le.SetEditCanceled(true);
le.SetEventObject( GetParent() );
+ le.m_item.m_itemId =
le.m_itemIndex = itemEdit;
wxListLineData *data = GetLine(itemEdit);
}
}
+ // Update drag events counter first as we must do it even if the mouse is
+ // not on any item right now as we must keep count in case we started
+ // dragging from the empty control area but continued to do it over a valid
+ // item -- in this situation we must not start dragging this item.
if (event.Dragging())
- {
- if (m_dragCount == 0)
- {
- // we have to report the raw, physical coords as we want to be
- // able to call HitTest(event.m_pointDrag) from the user code to
- // get the item being dragged
- m_dragStart = event.GetPosition();
- }
-
m_dragCount++;
-
- if (m_dragCount != 3)
- return;
-
- int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
- : wxEVT_COMMAND_LIST_BEGIN_DRAG;
-
- wxListEvent le( command, GetParent()->GetId() );
- le.SetEventObject( GetParent() );
- le.m_itemIndex = m_lineLastClicked;
- le.m_pointDrag = m_dragStart;
- GetParent()->GetEventHandler()->ProcessEvent( le );
-
- return;
- }
else
- {
m_dragCount = 0;
- }
+ // The only mouse event that can be generated without any valid item is
+ // wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK as it can be useful to have a global
+ // popup menu for the list control itself which should be shown even when
+ // the user clicks outside of any item.
if ( !hitResult )
{
// outside of any item
return;
}
+ if ( event.Dragging() )
+ {
+ if (m_dragCount == 1)
+ {
+ // we have to report the raw, physical coords as we want to be
+ // able to call HitTest(event.m_pointDrag) from the user code to
+ // get the item being dragged
+ m_dragStart = event.GetPosition();
+ }
+
+ if (m_dragCount != 3)
+ return;
+
+ int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
+ : wxEVT_COMMAND_LIST_BEGIN_DRAG;
+
+ SendNotify( m_lineLastClicked, command, m_dragStart );
+
+ return;
+ }
+
bool forceClick = false;
if (event.ButtonDClick())
{
// send a list event
wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, parent->GetId() );
+ le.m_item.m_itemId =
le.m_itemIndex = m_current;
if (HasCurrent())
GetLine(m_current)->GetItem( 0, le.m_item );
}
}
-int wxListMainWindow::GetTextLength( const wxString &s ) const
-{
- wxClientDC dc( wxConstCast(this, wxListMainWindow) );
- dc.SetFont( GetFont() );
-
- wxCoord lw;
- dc.GetTextExtent( s, &lw, NULL );
-
- return lw + AUTOSIZE_COL_MARGIN;
-}
-
void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
{
m_dirty = true;
// columns
// ----------------------------------------------------------------------------
-void wxListMainWindow::SetColumn( int col, wxListItem &item )
+int
+wxListMainWindow::ComputeMinHeaderWidth(const wxListHeaderData* column) const
+{
+ wxClientDC dc(const_cast<wxListMainWindow*>(this));
+
+ int width = dc.GetTextExtent(column->GetText()).x + AUTOSIZE_COL_MARGIN;
+
+ width += 2*EXTRA_WIDTH;
+
+ // check for column header's image availability
+ const int image = column->GetImage();
+ if ( image != -1 )
+ {
+ if ( m_small_image_list )
+ {
+ int ix = 0, iy = 0;
+ m_small_image_list->GetSize(image, ix, iy);
+ width += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE;
+ }
+ }
+
+ return width;
+}
+
+void wxListMainWindow::SetColumn( int col, const wxListItem &item )
{
wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
wxCHECK_RET( node, wxT("invalid column index in SetColumn") );
- if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
- item.m_width = GetTextLength( item.m_text );
-
wxListHeaderData *column = node->GetData();
column->SetItem( item );
+ if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
+ column->SetWidth(ComputeMinHeaderWidth(column));
+
wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
if ( headerWin )
headerWin->m_dirty = true;
if (width == wxLIST_AUTOSIZE_USEHEADER)
{
- width = GetTextLength(column->GetText());
- width += 2*EXTRA_WIDTH;
-
- // check for column header's image availability
- const int image = column->GetImage();
- if ( image != -1 )
- {
- if ( m_small_image_list )
- {
- int ix = 0, iy = 0;
- m_small_image_list->GetSize(image, ix, iy);
- width += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE;
- }
- }
+ width = ComputeMinHeaderWidth(column);
}
else if ( width == wxLIST_AUTOSIZE )
{
- if ( IsVirtual() )
- {
- // TODO: determine the max width somehow...
- width = WIDTH_COL_DEFAULT;
- }
- else // !virtual
+ width = ComputeMinHeaderWidth(column);
+
+ if ( !IsVirtual() )
{
wxClientDC dc(this);
dc.SetFont( GetFont() );
m_aColWidths.Item(col)->nMaxWidth = max;
}
- max = m_aColWidths.Item(col)->nMaxWidth;
- width = max + AUTOSIZE_COL_MARGIN;
+ max = m_aColWidths.Item(col)->nMaxWidth + AUTOSIZE_COL_MARGIN;
+ if ( width < max )
+ width = max;
}
}
}
}
- // update the item on screen
- wxRect rectItem;
- GetItemRect(id, rectItem);
- RefreshRect(rectItem);
+ // update the item on screen unless we're going to update everything soon
+ // anyhow
+ if ( !m_dirty )
+ {
+ wxRect rectItem;
+ GetItemRect(id, rectItem);
+ RefreshRect(rectItem);
+ }
}
void wxListMainWindow::SetItemStateAll(long state, long stateMask)
|| i == count - 1)
{
// Adjust all items in this row to have the same
- // width to ensure that they all align horizontally.
- size_t firstRowLine = i - currentlyVisibleLines + 1;
- for (size_t j = firstRowLine; j <= i; j++)
+ // width to ensure that they all align horizontally in
+ // icon view.
+ if ( HasFlag(wxLC_ICON) || HasFlag(wxLC_SMALL_ICON) )
{
- GetLine(j)->m_gi->ExtendWidth(maxWidthInThisRow);
+ size_t firstRowLine = i - currentlyVisibleLines + 1;
+ for (size_t j = firstRowLine; j <= i; j++)
+ {
+ GetLine(j)->m_gi->ExtendWidth(maxWidthInThisRow);
+ }
}
currentlyVisibleLines = 0;
RefreshLines(id, GetItemCount() - 1);
}
-void wxListMainWindow::InsertColumn( long col, wxListItem &item )
+void wxListMainWindow::InsertColumn( long col, const wxListItem &item )
{
m_dirty = true;
if ( InReportView() )
{
+ wxListHeaderData *column = new wxListHeaderData( item );
if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
- item.m_width = GetTextLength( item.m_text );
+ column->SetWidth(ComputeMinHeaderWidth(column));
- wxListHeaderData *column = new wxListHeaderData( item );
wxColWidthInfo *colWidthInfo = new wxColWidthInfo();
bool insert = (col >= 0) && ((size_t)col < m_columns.GetCount());
IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl, wxControl)
-BEGIN_EVENT_TABLE(wxGenericListCtrl,wxControl)
+BEGIN_EVENT_TABLE(wxGenericListCtrl,wxListCtrlBase)
EVT_SIZE(wxGenericListCtrl::OnSize)
EVT_SCROLLWIN(wxGenericListCtrl::OnScroll)
END_EVENT_TABLE()
wxASSERT_MSG( (style & wxLC_MASK_TYPE),
wxT("wxListCtrl style should have exactly one mode bit set") );
- if ( !wxControl::Create( parent, id, pos, size, style|wxVSCROLL|wxHSCROLL, validator, name ) )
+ if ( !wxListCtrlBase::Create( parent, id, pos, size,
+ style | wxVSCROLL | wxHSCROLL,
+ validator, name ) )
return false;
-#ifdef __WXGTK__
- style &= ~wxBORDER_MASK;
- style |= wxBORDER_THEME;
-#endif
-
- m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0, 0), size, style );
+ m_mainWin = new wxListMainWindow(this, wxID_ANY, wxPoint(0, 0), size);
SetTargetWindow( m_mainWin );
WXWPARAM wParam,
WXLPARAM lParam)
{
- WXLRESULT rc = wxControl::MSWWindowProc(nMsg, wParam, lParam);
+ WXLRESULT rc = wxListCtrlBase::MSWWindowProc(nMsg, wParam, lParam);
// we need to process arrows ourselves for scrolling
if ( nMsg == WM_GETDLGCODE )
return true;
}
-bool wxGenericListCtrl::SetColumn( int col, wxListItem& item )
+bool wxGenericListCtrl::SetColumn( int col, const wxListItem& item )
{
m_mainWin->SetColumn( col, item );
return true;
return InsertItem( info );
}
-long wxGenericListCtrl::InsertColumn( long col, wxListItem &item )
+long wxGenericListCtrl::DoInsertColumn( long col, const wxListItem &item )
{
wxCHECK_MSG( InReportView(), -1, wxT("can't add column in non report mode") );
return 0;
}
-long wxGenericListCtrl::InsertColumn( long col, const wxString &heading,
- int format, int width )
-{
- wxListItem item;
- item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
- item.m_text = heading;
- if (width >= -2)
- {
- item.m_mask |= wxLIST_MASK_WIDTH;
- item.m_width = width;
- }
-
- item.m_format = format;
-
- return InsertColumn( col, item );
-}
-
bool wxGenericListCtrl::ScrollList( int dx, int dy )
{
return m_mainWin->ScrollList(dx, dy);
if ( m_mainWin )
m_mainWin->DoClientToScreen(x, y);
else
- wxControl::DoClientToScreen(x, y);
+ wxListCtrlBase::DoClientToScreen(x, y);
}
void wxGenericListCtrl::DoScreenToClient( int *x, int *y ) const
if ( m_mainWin )
m_mainWin->DoScreenToClient(x, y);
else
- wxControl::DoScreenToClient(x, y);
-}
-
-void wxGenericListCtrl::SetFocus()
-{
- // The test in window.cpp fails as we are a composite
- // window, so it checks against "this", but not m_mainWin.
- if ( DoFindFocus() != this )
- m_mainWin->SetFocus();
+ wxListCtrlBase::DoScreenToClient(x, y);
}
wxSize wxGenericListCtrl::DoGetBestClientSize() const
{
- // Something is better than nothing even if this is completely arbitrary.
- wxSize sizeBest(100, 80);
+ // The base class version can compute the best size in report view only.
+ wxSize sizeBest = wxListCtrlBase::DoGetBestClientSize();
if ( !InReportView() )
{