/////////////////////////////////////////////////////////////////////////////
-// Name: listctrl.cpp
-// Purpose:
+// Name: generic/listctrl.cpp
+// Purpose: generic implementation of wxListCtrl
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
#pragma hdrstop
#endif
+#if wxUSE_LISTCTRL
+
#include "wx/dcscreen.h"
#include "wx/app.h"
#include "wx/listctrl.h"
#define wxUSE_GENERIC_LIST_EXTENSIONS 1
#endif
+// ----------------------------------------------------------------------------
+// events
+// ----------------------------------------------------------------------------
+
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
+
// ============================================================================
// private classes
// ============================================================================
class WXDLLEXPORT wxListItemData : public wxObject
{
-public:
- wxString m_text;
- int m_image;
- long m_data;
- int m_xpos,m_ypos;
- int m_width,m_height;
-
- wxListItemAttr *m_attr;
-
public:
wxListItemData();
~wxListItemData() { delete m_attr; }
wxListItemData( const wxListItem &info );
void SetItem( const wxListItem &info );
- void SetText( const wxString &s );
void SetImage( int image );
void SetData( long data );
void SetPosition( int x, int y );
void SetSize( int width, int height );
bool HasImage() const;
- bool HasText() const;
+
+ bool HasText() const { return !m_text.empty(); }
+ const wxString& GetText() const { return m_text; }
+ void SetText(const wxString& text) { m_text = text; }
+
bool IsHit( int x, int y ) const;
- void GetText( wxString &s );
- const wxString& GetText() { return m_text; }
+
int GetX( void ) const;
int GetY( void ) const;
int GetWidth() const;
wxListItemAttr *GetAttributes() const { return m_attr; }
+public:
+ int m_image;
+ long m_data;
+ int m_xpos,
+ m_ypos;
+ int m_width,
+ m_height;
+
+ wxListItemAttr *m_attr;
+
+protected:
+ wxString m_text;
+
private:
DECLARE_DYNAMIC_CLASS(wxListItemData);
};
void SetFormat( int format );
void SetHeight( int h );
bool HasImage() const;
- bool HasText() const;
- bool IsHit( int x, int y ) const;
+
+ bool HasText() const { return !m_text.empty(); }
+ const wxString& GetText() const { return m_text; }
+ void SetText(const wxString& text) { m_text = text; }
+
void GetItem( wxListItem &item );
- void GetText( wxString &s );
+
+ bool IsHit( int x, int y ) const;
int GetImage() const;
int GetWidth() const;
int GetFormat() const;
void InitItems( int num );
void SetItem( int index, const wxListItem &info );
void GetItem( int index, wxListItem &info );
- void GetText( int index, wxString &s );
+ wxString GetText(int index) const;
void SetText( int index, const wxString s );
int GetImage( int index );
void GetRect( wxRect &rect );
void wxListItemData::SetItem( const wxListItem &info )
{
- if (info.m_mask & wxLIST_MASK_TEXT) m_text = info.m_text;
- if (info.m_mask & wxLIST_MASK_IMAGE) m_image = info.m_image;
- if (info.m_mask & wxLIST_MASK_DATA) m_data = info.m_data;
+ if (info.m_mask & wxLIST_MASK_TEXT)
+ SetText(info.m_text);
+ if (info.m_mask & wxLIST_MASK_IMAGE)
+ m_image = info.m_image;
+ if (info.m_mask & wxLIST_MASK_DATA)
+ m_data = info.m_data;
if ( info.HasAttributes() )
{
m_height = 0;
}
-void wxListItemData::SetText( const wxString &s )
-{
- m_text = s;
-}
-
void wxListItemData::SetImage( int image )
{
m_image = image;
return (m_image >= 0);
}
-bool wxListItemData::HasText() const
-{
- return (!m_text.IsNull());
-}
-
bool wxListItemData::IsHit( int x, int y ) const
{
return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
}
-void wxListItemData::GetText( wxString &s )
-{
- s = m_text;
-}
-
int wxListItemData::GetX() const
{
return m_xpos;
return (m_image != 0);
}
-bool wxListHeaderData::HasText() const
-{
- return (m_text.Length() > 0);
-}
-
bool wxListHeaderData::IsHit( int x, int y ) const
{
return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
item.m_width = m_width;
}
-void wxListHeaderData::GetText( wxString &s )
-{
- s = m_text;
-}
-
int wxListHeaderData::GetImage() const
{
return m_image;
}
}
-void wxListLineData::GetText( int index, wxString &s )
+wxString wxListLineData::GetText(int index) const
{
- int i = index;
- wxNode *node = m_items.Nth( i );
- s = "";
+ wxString s;
+
+ wxNode *node = m_items.Nth( index );
if (node)
{
wxListItemData *item = (wxListItemData*)node->Data();
- item->GetText( s );
+ s = item->GetText();
}
+
+ return s;
}
void wxListLineData::SetText( int index, const wxString s )
DoDrawRect( &dc, x, y, cw, h-2 );
dc.SetClippingRegion( x, y, cw-5, h-4 );
- dc.DrawText( item.m_text, x+4, y+3 );
+ dc.DrawText( item.GetText(), x+4, y+3 );
dc.DestroyClippingRegion();
x += wCol;
wxPaintDC dc( this );
PrepareDC( dc );
+ int dev_x = 0;
+ int dev_y = 0;
+ CalcScrolledPosition( 0, 0, &dev_x, &dev_y );
+
if (m_dirty) return;
if (m_lines.GetCount() == 0) return;
if (m_mode & wxLC_REPORT)
{
wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
- dc.SetPen(pen);
- dc.SetBrush(* wxTRANSPARENT_BRUSH);
-
wxSize clientSize = GetClientSize();
int lineSpacing = 0;
m_lines[i].Draw( &dc );
// Draw horizontal rule if required
if (GetWindowStyle() & wxLC_HRULES)
- dc.DrawLine(0, i*lineSpacing, clientSize.x, i*lineSpacing);
+ {
+ dc.SetPen(pen);
+ dc.SetBrush(* wxTRANSPARENT_BRUSH);
+ dc.DrawLine(0 - dev_x , i*lineSpacing , clientSize.x - dev_x , i*lineSpacing );
+ }
}
// Draw last horizontal rule
if ((i > (size_t) (y_s / lineSpacing)) && (GetWindowStyle() & wxLC_HRULES))
- dc.DrawLine(0, i*lineSpacing, clientSize.x, i*lineSpacing);
+ {
+ dc.SetPen(pen);
+ dc.SetBrush(* wxTRANSPARENT_BRUSH);
+ dc.DrawLine(0 - dev_x , i*lineSpacing , clientSize.x - dev_x , i*lineSpacing );
+ }
// Draw vertical rules if required
if ((GetWindowStyle() & wxLC_VRULES) && (GetItemCount() > 0))
GetItemRect(0, firstItemRect);
GetItemRect(GetItemCount() - 1, lastItemRect);
int x = firstItemRect.GetX();
+ dc.SetPen(pen);
+ dc.SetBrush(* wxTRANSPARENT_BRUSH);
for (col = 0; col < GetColumnCount(); col++)
{
int colWidth = GetColumnWidth(col);
x += colWidth ;
- dc.DrawLine(x, firstItemRect.GetY() - 1, x, lastItemRect.GetBottom() + 1);
+ dc.DrawLine(x - dev_x, firstItemRect.GetY() - 1 - dev_y, x - dev_x, lastItemRect.GetBottom() + 1 - dev_y);
}
}
}
// update taken place.
if (m_dirty) wxYield();
- wxString s;
- m_currentEdit->GetText( 0, s );
+ wxString s = m_currentEdit->GetText(0);
int x = 0;
int y = 0;
int w = 0;
wxNode *node = m_columns.Nth( col );
if (node)
{
- if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7;
+ if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
+ item.m_width = GetTextLength( item.m_text )+7;
wxListHeaderData *column = (wxListHeaderData*)node->Data();
column->SetItem( item );
}
}
if (item->HasText())
{
- wxString str;
- item->GetText( str );
+ wxString str = item->GetText();
dc.GetTextExtent( str, &lx, &ly );
current += lx;
}
{
item.m_format = 0;
item.m_width = 0;
- item.m_text = "";
+ item.m_text = _T("");
item.m_image = 0;
item.m_data = 0;
}
void wxListMainWindow::SetItemState( long item, long state, long stateMask )
{
+ wxCHECK_RET( item >= 0 && (size_t)item < m_lines.GetCount(),
+ _T("invalid list ctrl item index in SetItem") );
+
// m_dirty = TRUE; no recalcs needed
wxListLineData *oldCurrent = m_current;
- if (stateMask & wxLIST_STATE_FOCUSED)
- {
- if (item >= 0 && (size_t)item < m_lines.GetCount())
- {
- wxListLineData *line = &m_lines[(size_t)item];
- UnfocusLine( m_current );
- m_current = line;
- FocusLine( m_current );
- if ((m_mode & wxLC_SINGLE_SEL) && oldCurrent) oldCurrent->Hilight( FALSE );
- RefreshLine( m_current );
- if (oldCurrent) RefreshLine( oldCurrent );
- }
- }
-
- if (stateMask & wxLIST_STATE_SELECTED)
+ if ( stateMask & wxLIST_STATE_FOCUSED )
{
- bool on = (state & wxLIST_STATE_SELECTED) != 0;
- if (!on && (m_mode & wxLC_SINGLE_SEL)) return;
-
- if (item >= 0 && (size_t)item < m_lines.GetCount())
+ wxListLineData *line = &m_lines[(size_t)item];
+ if ( state & wxLIST_STATE_FOCUSED )
{
- wxListLineData *line = &m_lines[(size_t)item];
- if (m_mode & wxLC_SINGLE_SEL)
+ // don't do anything if this item is already focused
+ if ( line != m_current )
{
UnfocusLine( m_current );
m_current = line;
FocusLine( m_current );
- if (oldCurrent) oldCurrent->Hilight( FALSE );
+ if ( (m_mode & wxLC_SINGLE_SEL) && oldCurrent )
+ oldCurrent->Hilight( FALSE );
+
RefreshLine( m_current );
- if (oldCurrent) RefreshLine( oldCurrent );
+ if ( oldCurrent )
+ RefreshLine( oldCurrent );
}
- bool on = (state & wxLIST_STATE_SELECTED) != 0;
- if (on != line->IsHilighted())
+ }
+ else // unfocus
+ {
+ // don't do anything if this item is not focused
+ if ( line == m_current )
{
- line->Hilight( on );
- RefreshLine( line );
+ UnfocusLine( m_current );
+ m_current = NULL;
}
}
}
+
+ if ( stateMask & wxLIST_STATE_SELECTED )
+ {
+ bool on = (state & wxLIST_STATE_SELECTED) != 0;
+ if (!on && (m_mode & wxLC_SINGLE_SEL))
+ return;
+
+ wxListLineData *line = &m_lines[(size_t)item];
+ if (m_mode & wxLC_SINGLE_SEL)
+ {
+ UnfocusLine( m_current );
+ m_current = line;
+ FocusLine( m_current );
+ if (oldCurrent)
+ oldCurrent->Hilight( FALSE );
+ RefreshLine( m_current );
+ if (oldCurrent)
+ RefreshLine( oldCurrent );
+ }
+
+ if (on != line->IsHilighted())
+ {
+ line->Hilight( on );
+ RefreshLine( line );
+ }
+ }
}
int wxListMainWindow::GetItemState( long item, long stateMask )
if (item >= 0 && (size_t)item < m_lines.GetCount())
{
wxListLineData *line = &m_lines[(size_t)item];
- if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED;
+ if (line->IsHilighted()) ret |= wxLIST_STATE_SELECTED;
}
}
return ret;
else
{
item.m_mask = 0;
- item.m_text = "";
+ item.m_text = _T("");
item.m_image = 0;
item.m_data = 0;
}
for (size_t i = (size_t)pos; i < m_lines.GetCount(); i++)
{
wxListLineData *line = &m_lines[i];
- wxString s = "";
- line->GetText( 0, s );
- if (s == tmp) return pos;
+ wxString s = line->GetText(0);
+ if (s == tmp)
+ return pos;
+
pos++;
}
return -1;
m_dirty = TRUE;
if (m_mode & wxLC_REPORT)
{
- if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text );
+ if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
+ item.m_width = GetTextLength( item.m_text );
wxListHeaderData *column = new wxListHeaderData( item );
if ((col >= 0) && (col < (int)m_columns.GetCount()))
{
void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
{
- wxScrolledWindow::OnScroll( event ) ;
+ // FIXME
+#ifdef __WXGTK__
+ wxScrolledWindow::OnScroll(event);
+#else
+ HandleOnScroll( event );
+#endif
+
#if wxUSE_GENERIC_LIST_EXTENSIONS
if (event.GetOrientation() == wxHORIZONTAL && ( m_mode & wxLC_REPORT ))
{
lc->m_headerWin->Refresh() ;
#ifdef __WXMAC__
- lc->m_headerWin->MacUpdateImmediately() ;
+ lc->m_headerWin->MacUpdateImmediately() ;
#endif
}
}
m_data = 0;
m_format = wxLIST_FORMAT_CENTRE;
m_width = 0;
- m_text = wxEmptyString;
+ m_text = _T("");
if (m_attr) delete m_attr;
m_attr = NULL;
if ( FindFocus() != this )
m_mainWin->SetFocus();
}
+
+#endif // wxUSE_LISTCTRL