use GetText() instead of GetText(wxString&), made some methods inline
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10666 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: listctrl.cpp
|
// Name: generic/listctrl.cpp
|
||||||
// Purpose:
|
// Purpose: generic implementation of wxListCtrl
|
||||||
// Author: Robert Roebling
|
// Author: Robert Roebling
|
||||||
// Id: $Id$
|
// Id: $Id$
|
||||||
// Copyright: (c) 1998 Robert Roebling
|
// Copyright: (c) 1998 Robert Roebling
|
||||||
@@ -65,31 +65,24 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
|
|||||||
|
|
||||||
class WXDLLEXPORT wxListItemData : public wxObject
|
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:
|
public:
|
||||||
wxListItemData();
|
wxListItemData();
|
||||||
~wxListItemData() { delete m_attr; }
|
~wxListItemData() { delete m_attr; }
|
||||||
|
|
||||||
wxListItemData( const wxListItem &info );
|
wxListItemData( const wxListItem &info );
|
||||||
void SetItem( const wxListItem &info );
|
void SetItem( const wxListItem &info );
|
||||||
void SetText( const wxString &s );
|
|
||||||
void SetImage( int image );
|
void SetImage( int image );
|
||||||
void SetData( long data );
|
void SetData( long data );
|
||||||
void SetPosition( int x, int y );
|
void SetPosition( int x, int y );
|
||||||
void SetSize( int width, int height );
|
void SetSize( int width, int height );
|
||||||
bool HasImage() const;
|
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;
|
bool IsHit( int x, int y ) const;
|
||||||
void GetText( wxString &s );
|
|
||||||
const wxString& GetText() { return m_text; }
|
|
||||||
int GetX( void ) const;
|
int GetX( void ) const;
|
||||||
int GetY( void ) const;
|
int GetY( void ) const;
|
||||||
int GetWidth() const;
|
int GetWidth() const;
|
||||||
@@ -99,6 +92,19 @@ public:
|
|||||||
|
|
||||||
wxListItemAttr *GetAttributes() const { return m_attr; }
|
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:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS(wxListItemData);
|
DECLARE_DYNAMIC_CLASS(wxListItemData);
|
||||||
};
|
};
|
||||||
@@ -127,10 +133,14 @@ public:
|
|||||||
void SetFormat( int format );
|
void SetFormat( int format );
|
||||||
void SetHeight( int h );
|
void SetHeight( int h );
|
||||||
bool HasImage() const;
|
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 GetItem( wxListItem &item );
|
||||||
void GetText( wxString &s );
|
|
||||||
|
bool IsHit( int x, int y ) const;
|
||||||
int GetImage() const;
|
int GetImage() const;
|
||||||
int GetWidth() const;
|
int GetWidth() const;
|
||||||
int GetFormat() const;
|
int GetFormat() const;
|
||||||
@@ -172,7 +182,7 @@ public:
|
|||||||
void InitItems( int num );
|
void InitItems( int num );
|
||||||
void SetItem( int index, const wxListItem &info );
|
void SetItem( int index, const wxListItem &info );
|
||||||
void GetItem( int index, 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 );
|
void SetText( int index, const wxString s );
|
||||||
int GetImage( int index );
|
int GetImage( int index );
|
||||||
void GetRect( wxRect &rect );
|
void GetRect( wxRect &rect );
|
||||||
@@ -439,9 +449,12 @@ wxListItemData::wxListItemData( const wxListItem &info )
|
|||||||
|
|
||||||
void wxListItemData::SetItem( const wxListItem &info )
|
void wxListItemData::SetItem( const wxListItem &info )
|
||||||
{
|
{
|
||||||
if (info.m_mask & wxLIST_MASK_TEXT) m_text = info.m_text;
|
if (info.m_mask & wxLIST_MASK_TEXT)
|
||||||
if (info.m_mask & wxLIST_MASK_IMAGE) m_image = info.m_image;
|
SetText(info.m_text);
|
||||||
if (info.m_mask & wxLIST_MASK_DATA) m_data = info.m_data;
|
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() )
|
if ( info.HasAttributes() )
|
||||||
{
|
{
|
||||||
@@ -457,11 +470,6 @@ void wxListItemData::SetItem( const wxListItem &info )
|
|||||||
m_height = 0;
|
m_height = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListItemData::SetText( const wxString &s )
|
|
||||||
{
|
|
||||||
m_text = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxListItemData::SetImage( int image )
|
void wxListItemData::SetImage( int image )
|
||||||
{
|
{
|
||||||
m_image = image;
|
m_image = image;
|
||||||
@@ -489,21 +497,11 @@ bool wxListItemData::HasImage() const
|
|||||||
return (m_image >= 0);
|
return (m_image >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxListItemData::HasText() const
|
|
||||||
{
|
|
||||||
return (!m_text.IsNull());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxListItemData::IsHit( int x, int y ) const
|
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));
|
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
|
int wxListItemData::GetX() const
|
||||||
{
|
{
|
||||||
return m_xpos;
|
return m_xpos;
|
||||||
@@ -610,11 +608,6 @@ bool wxListHeaderData::HasImage() const
|
|||||||
return (m_image != 0);
|
return (m_image != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxListHeaderData::HasText() const
|
|
||||||
{
|
|
||||||
return (m_text.Length() > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxListHeaderData::IsHit( int x, int y ) const
|
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));
|
return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
|
||||||
@@ -629,11 +622,6 @@ void wxListHeaderData::GetItem( wxListItem &item )
|
|||||||
item.m_width = m_width;
|
item.m_width = m_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListHeaderData::GetText( wxString &s )
|
|
||||||
{
|
|
||||||
s = m_text;
|
|
||||||
}
|
|
||||||
|
|
||||||
int wxListHeaderData::GetImage() const
|
int wxListHeaderData::GetImage() const
|
||||||
{
|
{
|
||||||
return m_image;
|
return m_image;
|
||||||
@@ -959,16 +947,18 @@ void wxListLineData::GetItem( int index, wxListItem &info )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListLineData::GetText( int index, wxString &s )
|
wxString wxListLineData::GetText(int index) const
|
||||||
{
|
{
|
||||||
int i = index;
|
wxString s;
|
||||||
wxNode *node = m_items.Nth( i );
|
|
||||||
s = "";
|
wxNode *node = m_items.Nth( index );
|
||||||
if (node)
|
if (node)
|
||||||
{
|
{
|
||||||
wxListItemData *item = (wxListItemData*)node->Data();
|
wxListItemData *item = (wxListItemData*)node->Data();
|
||||||
item->GetText( s );
|
s = item->GetText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxListLineData::SetText( int index, const wxString s )
|
void wxListLineData::SetText( int index, const wxString s )
|
||||||
@@ -1321,7 +1311,7 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
|
|
||||||
DoDrawRect( &dc, x, y, cw, h-2 );
|
DoDrawRect( &dc, x, y, cw, h-2 );
|
||||||
dc.SetClippingRegion( x, y, cw-5, h-4 );
|
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();
|
dc.DestroyClippingRegion();
|
||||||
x += wCol;
|
x += wCol;
|
||||||
|
|
||||||
@@ -1851,8 +1841,7 @@ void wxListMainWindow::EditLabel( long item )
|
|||||||
// update taken place.
|
// update taken place.
|
||||||
if (m_dirty) wxYield();
|
if (m_dirty) wxYield();
|
||||||
|
|
||||||
wxString s;
|
wxString s = m_currentEdit->GetText(0);
|
||||||
m_currentEdit->GetText( 0, s );
|
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int w = 0;
|
int w = 0;
|
||||||
@@ -2483,7 +2472,8 @@ void wxListMainWindow::SetColumn( int col, wxListItem &item )
|
|||||||
wxNode *node = m_columns.Nth( col );
|
wxNode *node = m_columns.Nth( col );
|
||||||
if (node)
|
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();
|
wxListHeaderData *column = (wxListHeaderData*)node->Data();
|
||||||
column->SetItem( item );
|
column->SetItem( item );
|
||||||
}
|
}
|
||||||
@@ -2529,8 +2519,7 @@ void wxListMainWindow::SetColumnWidth( int col, int width )
|
|||||||
}
|
}
|
||||||
if (item->HasText())
|
if (item->HasText())
|
||||||
{
|
{
|
||||||
wxString str;
|
wxString str = item->GetText();
|
||||||
item->GetText( str );
|
|
||||||
dc.GetTextExtent( str, &lx, &ly );
|
dc.GetTextExtent( str, &lx, &ly );
|
||||||
current += lx;
|
current += lx;
|
||||||
}
|
}
|
||||||
@@ -2575,7 +2564,7 @@ void wxListMainWindow::GetColumn( int col, wxListItem &item )
|
|||||||
{
|
{
|
||||||
item.m_format = 0;
|
item.m_format = 0;
|
||||||
item.m_width = 0;
|
item.m_width = 0;
|
||||||
item.m_text = "";
|
item.m_text = _T("");
|
||||||
item.m_image = 0;
|
item.m_image = 0;
|
||||||
item.m_data = 0;
|
item.m_data = 0;
|
||||||
}
|
}
|
||||||
@@ -2618,49 +2607,68 @@ void wxListMainWindow::SetItem( wxListItem &item )
|
|||||||
|
|
||||||
void wxListMainWindow::SetItemState( long item, long state, long stateMask )
|
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
|
// m_dirty = TRUE; no recalcs needed
|
||||||
|
|
||||||
wxListLineData *oldCurrent = m_current;
|
wxListLineData *oldCurrent = m_current;
|
||||||
|
|
||||||
if (stateMask & wxLIST_STATE_FOCUSED)
|
if ( stateMask & wxLIST_STATE_FOCUSED )
|
||||||
{
|
{
|
||||||
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];
|
// don't do anything if this item is already focused
|
||||||
UnfocusLine( m_current );
|
if ( line != 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)
|
|
||||||
{
|
|
||||||
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 (m_mode & wxLC_SINGLE_SEL)
|
|
||||||
{
|
{
|
||||||
UnfocusLine( m_current );
|
UnfocusLine( m_current );
|
||||||
m_current = line;
|
m_current = line;
|
||||||
FocusLine( m_current );
|
FocusLine( m_current );
|
||||||
if (oldCurrent) oldCurrent->Hilight( FALSE );
|
if ( (m_mode & wxLC_SINGLE_SEL) && oldCurrent )
|
||||||
|
oldCurrent->Hilight( FALSE );
|
||||||
|
|
||||||
RefreshLine( m_current );
|
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 );
|
UnfocusLine( m_current );
|
||||||
RefreshLine( line );
|
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 )
|
int wxListMainWindow::GetItemState( long item, long stateMask )
|
||||||
@@ -2695,7 +2703,7 @@ void wxListMainWindow::GetItem( wxListItem &item )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
item.m_mask = 0;
|
item.m_mask = 0;
|
||||||
item.m_text = "";
|
item.m_text = _T("");
|
||||||
item.m_image = 0;
|
item.m_image = 0;
|
||||||
item.m_data = 0;
|
item.m_data = 0;
|
||||||
}
|
}
|
||||||
@@ -3009,9 +3017,10 @@ long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(p
|
|||||||
for (size_t i = (size_t)pos; i < m_lines.GetCount(); i++)
|
for (size_t i = (size_t)pos; i < m_lines.GetCount(); i++)
|
||||||
{
|
{
|
||||||
wxListLineData *line = &m_lines[i];
|
wxListLineData *line = &m_lines[i];
|
||||||
wxString s = "";
|
wxString s = line->GetText(0);
|
||||||
line->GetText( 0, s );
|
if (s == tmp)
|
||||||
if (s == tmp) return pos;
|
return pos;
|
||||||
|
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@@ -3089,7 +3098,8 @@ void wxListMainWindow::InsertColumn( long col, wxListItem &item )
|
|||||||
m_dirty = TRUE;
|
m_dirty = TRUE;
|
||||||
if (m_mode & wxLC_REPORT)
|
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 );
|
wxListHeaderData *column = new wxListHeaderData( item );
|
||||||
if ((col >= 0) && (col < (int)m_columns.GetCount()))
|
if ((col >= 0) && (col < (int)m_columns.GetCount()))
|
||||||
{
|
{
|
||||||
@@ -3179,7 +3189,7 @@ void wxListItem::Clear()
|
|||||||
m_data = 0;
|
m_data = 0;
|
||||||
m_format = wxLIST_FORMAT_CENTRE;
|
m_format = wxLIST_FORMAT_CENTRE;
|
||||||
m_width = 0;
|
m_width = 0;
|
||||||
m_text = wxEmptyString;
|
m_text = _T("");
|
||||||
|
|
||||||
if (m_attr) delete m_attr;
|
if (m_attr) delete m_attr;
|
||||||
m_attr = NULL;
|
m_attr = NULL;
|
||||||
|
Reference in New Issue
Block a user