TODO
1. we need to implement searching/sorting for virtual controls somehow
- 2. when changing selection the lines are refreshed twice
+ ?2. when changing selection the lines are refreshed twice
*/
// ============================================================================
#if wxUSE_LISTCTRL
-#include "wx/dcscreen.h"
-#include "wx/app.h"
-#include "wx/listctrl.h"
+#ifndef WX_PRECOMP
+ #include "wx/app.h"
+
+ #include "wx/dynarray.h"
+
+ #include "wx/dcscreen.h"
+
+ #include "wx/textctrl.h"
+#endif
+
#include "wx/imaglist.h"
-#include "wx/dynarray.h"
+#include "wx/listctrl.h"
-#ifdef __WXGTK__
-#include <gtk/gtk.h>
-#include "wx/gtk/win_gtk.h"
+#if defined(__WXGTK__)
+ #include <gtk/gtk.h>
+ #include "wx/gtk/win_gtk.h"
#endif
// ----------------------------------------------------------------------------
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_COL_RIGHT_CLICK)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG)
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)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT)
// ----------------------------------------------------------------------------
int CMPFUNC_CONV wxSizeTCmpFn(size_t n1, size_t n2) { return n1 - n2; }
-WX_DEFINE_SORTED_EXPORTED_ARRAY(size_t, wxIndexArray);
+WX_DEFINE_SORTED_EXPORTED_ARRAY_LONG(size_t, wxIndexArray);
// this class is used to store the selected items in the virtual list control
// (but it is not tied to list control and so can be used with other controls
class WXDLLEXPORT wxListHeaderData : public wxObject
{
-protected:
- long m_mask;
- int m_image;
- wxString m_text;
- int m_format;
- int m_width;
- int m_xpos,
- m_ypos;
- int m_height;
-
public:
wxListHeaderData();
wxListHeaderData( const wxListItem &info );
int GetWidth() const;
int GetFormat() const;
+protected:
+ long m_mask;
+ int m_image;
+ wxString m_text;
+ int m_format;
+ int m_width;
+ int m_xpos,
+ m_ypos;
+ int m_height;
+
private:
- DECLARE_DYNAMIC_CLASS(wxListHeaderData);
+ void Init();
};
//-----------------------------------------------------------------------------
wxCursor *m_resizeCursor;
bool m_isDragging;
- // column being resized
+ // column being resized or -1
int m_column;
// divider line position in logical (unscrolled) coords
public:
wxListHeaderWindow();
- virtual ~wxListHeaderWindow();
wxListHeaderWindow( wxWindow *win,
wxWindowID id,
long style = 0,
const wxString &name = "wxlistctrlcolumntitles" );
+ virtual ~wxListHeaderWindow();
+
void DoDrawRect( wxDC *dc, int x, int y, int w, int h );
void DrawCurrent();
void AdjustDC(wxDC& dc);
bool m_dirty;
private:
+ // common part of all ctors
+ void Init();
+
+ void SendListEvent(wxEventType type, wxPoint pos);
+
DECLARE_DYNAMIC_CLASS(wxListHeaderWindow)
DECLARE_EVENT_TABLE()
};
class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl
{
-private:
- bool *m_accept;
- wxString *m_res;
- wxListMainWindow *m_owner;
- wxString m_startValue;
-
public:
- wxListTextCtrl() {}
- wxListTextCtrl( wxWindow *parent, const wxWindowID id,
- bool *accept, wxString *res, wxListMainWindow *owner,
- const wxString &value = "",
- const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
- int style = 0,
- const wxValidator& validator = wxDefaultValidator,
- const wxString &name = "listctrltextctrl" );
+ wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit);
+
+protected:
void OnChar( wxKeyEvent &event );
void OnKeyUp( wxKeyEvent &event );
void OnKillFocus( wxFocusEvent &event );
+ bool AcceptChanges();
+ void Finish();
+
private:
- DECLARE_DYNAMIC_CLASS(wxListTextCtrl);
+ wxListMainWindow *m_owner;
+ wxString m_startValue;
+ size_t m_itemEdited;
+ bool m_finished;
+
DECLARE_EVENT_TABLE()
};
// bring the current item into view
void MoveToFocus() { MoveToItem(m_current); }
+ // start editing the label of the given item
void EditLabel( long item );
+
+ // suspend/resume redrawing the control
+ void Freeze();
+ void Thaw();
+
+ void SetFocus();
+
void OnRenameTimer();
- void OnRenameAccept();
+ bool OnRenameAccept(size_t itemEdit, const wxString& value);
void OnMouse( wxMouseEvent &event );
int GetCountPerPage() const;
void SetItem( wxListItem &item );
- void GetItem( wxListItem &item );
+ void GetItem( wxListItem &item ) const;
void SetItemState( long item, long state, long stateMask );
- int GetItemState( long item, long stateMask );
- void GetItemRect( long index, wxRect &rect );
- bool GetItemPosition( long item, wxPoint& pos );
- int GetSelectedItemCount();
+ int GetItemState( long item, long stateMask ) const;
+ void GetItemRect( long index, wxRect &rect ) const;
+ bool GetItemPosition( long item, wxPoint& pos ) const;
+ int GetSelectedItemCount() const;
+
+ wxString GetItemText(long item) const
+ {
+ wxListItem info;
+ info.m_itemId = item;
+ GetItem( info );
+ return info.m_text;
+ }
+
+ void SetItemText(long item, const wxString& value)
+ {
+ wxListItem info;
+ info.m_mask = wxLIST_MASK_TEXT;
+ info.m_itemId = item;
+ info.m_text = value;
+ SetItem( info );
+ }
// set the scrollbars and update the positions of the items
void RecalculatePositions(bool noRefresh = FALSE);
// refresh the window and the header
void RefreshAll();
- long GetNextItem( long item, int geometry, int state );
+ long GetNextItem( long item, int geometry, int state ) const;
void DeleteItem( long index );
void DeleteAllItems();
void DeleteColumn( int col );
bool IsEmpty() const { return GetItemCount() == 0; }
void SetItemCount(long count);
- void ResetCurrent() { m_current = (size_t)-1; }
+ // change the current (== focused) item, send a notification event
+ void ChangeCurrent(size_t current);
+ void ResetCurrent() { ChangeCurrent((size_t)-1); }
bool HasCurrent() const { return m_current != (size_t)-1; }
// send out a wxListEvent
}
//protected:
- // the array of all line objects for a non virtual list control
+ // the array of all line objects for a non virtual list control (for the
+ // virtual list control we only ever use m_lines[0])
wxListLineDataArray m_lines;
// the list of column objects
// currently focused item or -1
size_t m_current;
- // the item currently being edited or -1
- size_t m_currentEdit;
-
// the number of lines per page
int m_linesPerPage;
bool m_lastOnSame;
wxTimer *m_renameTimer;
- bool m_renameAccept;
- wxString m_renameRes;
bool m_isCreated;
int m_dragCount;
wxPoint m_dragStart;
#ifdef __WXMAC__
return *wxWHITE;
#else
- return wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT);
+ return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT);
#endif
}
// delete all items but don't refresh: called from dtor
void DoDeleteAllItems();
- // called when an item is [un]focuded, i.e. becomes [not] current
- //
- // currently unused
- void OnFocusLine( size_t line );
- void OnUnfocusLine( size_t line );
-
// the height of one line using the current font
wxCoord m_lineHeight;
wxBrush *m_highlightBrush,
*m_highlightUnfocusedBrush;
- DECLARE_DYNAMIC_CLASS(wxListMainWindow);
+ // if this is > 0, the control is frozen and doesn't redraw itself
+ size_t m_freezeCount;
+
+ DECLARE_DYNAMIC_CLASS(wxListMainWindow)
DECLARE_EVENT_TABLE()
};
// stop counting (see comment below)
itemsChanged = NULL;
}
-
- itemsChanged->Add(m_itemsSel[i]);
+ else
+ {
+ itemsChanged->Add(m_itemsSel[i]);
+ }
}
m_itemsSel.RemoveAt(i);
// wxListHeaderData
//-----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData,wxObject);
-
-wxListHeaderData::wxListHeaderData()
+void wxListHeaderData::Init()
{
m_mask = 0;
- m_image = 0;
+ m_image = -1;
m_format = 0;
m_width = 0;
m_xpos = 0;
m_height = 0;
}
+wxListHeaderData::wxListHeaderData()
+{
+ Init();
+}
+
wxListHeaderData::wxListHeaderData( const wxListItem &item )
{
+ Init();
+
SetItem( item );
- m_xpos = 0;
- m_ypos = 0;
- m_height = 0;
}
void wxListHeaderData::SetItem( const wxListItem &item )
{
m_mask = item.m_mask;
- m_text = item.m_text;
- m_image = item.m_image;
- m_format = item.m_format;
- SetWidth(item.m_width);
+ if ( m_mask & wxLIST_MASK_TEXT )
+ m_text = item.m_text;
+
+ if ( m_mask & wxLIST_MASK_IMAGE )
+ m_image = item.m_image;
+
+ if ( m_mask & wxLIST_MASK_FORMAT )
+ m_format = item.m_format;
+
+ if ( m_mask & wxLIST_MASK_WIDTH )
+ SetWidth(item.m_width);
}
void wxListHeaderData::SetPosition( int x, int y )
m_width = w;
if (m_width < 0)
m_width = WIDTH_COL_DEFAULT;
- if (m_width < WIDTH_COL_MIN)
+ else if (m_width < WIDTH_COL_MIN)
m_width = WIDTH_COL_MIN;
}
bool wxListHeaderData::HasImage() const
{
- return (m_image != 0);
+ return m_image != -1;
}
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));
}
-void wxListHeaderData::GetItem( wxListItem &item )
+void wxListHeaderData::GetItem( wxListItem& item )
{
item.m_mask = m_mask;
item.m_text = m_text;
if ( item->HasImage() )
{
- m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4
- + (spacing - m_gi->m_rectIcon.width)/2;
+ m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4 +
+ (m_gi->m_rectAll.width - m_gi->m_rectIcon.width) / 2;
m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4;
}
wxColour colText;
if ( highlighted )
{
- colText = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
+ colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
}
else
{
dc->DrawRectangle( rectHL );
}
- wxListItemDataList::Node *node = m_items.GetFirst();
- wxCHECK_RET( node, _T("no subitems at all??") );
-
- size_t col = 0;
wxCoord x = rect.x + HEADER_OFFSET_X,
y = rect.y + (LINE_SPACING + EXTRA_HEIGHT) / 2;
- while ( node )
+ size_t col = 0;
+ for ( wxListItemDataList::Node *node = m_items.GetFirst();
+ node;
+ node = node->GetNext(), col++ )
{
wxListItemData *item = node->GetData();
- int width = m_owner->GetColumnWidth(col++);
+ int width = m_owner->GetColumnWidth(col);
int xOld = x;
x += width;
{
dc->DrawText( item->GetText(), xOld, y );
}
-
- node = node->GetNext();
}
}
// wxListHeaderWindow
//-----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow);
+IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow)
BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow)
EVT_PAINT (wxListHeaderWindow::OnPaint)
EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus)
END_EVENT_TABLE()
-wxListHeaderWindow::wxListHeaderWindow( void )
+void wxListHeaderWindow::Init()
{
- m_owner = (wxListMainWindow *) NULL;
m_currentCursor = (wxCursor *) NULL;
- m_resizeCursor = (wxCursor *) NULL;
m_isDragging = FALSE;
+ m_dirty = FALSE;
+}
+
+wxListHeaderWindow::wxListHeaderWindow()
+{
+ Init();
+
+ m_owner = (wxListMainWindow *) NULL;
+ m_resizeCursor = (wxCursor *) NULL;
}
-wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner,
- const wxPoint &pos, const wxSize &size,
- long style, const wxString &name ) :
- wxWindow( win, id, pos, size, style, name )
+wxListHeaderWindow::wxListHeaderWindow( wxWindow *win,
+ wxWindowID id,
+ wxListMainWindow *owner,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ const wxString &name )
+ : wxWindow( win, id, pos, size, style, name )
{
+ Init();
+
m_owner = owner;
-// m_currentCursor = wxSTANDARD_CURSOR;
- m_currentCursor = (wxCursor *) NULL;
m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
- m_isDragging = FALSE;
- m_dirty = FALSE;
- SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) );
+ SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
}
-wxListHeaderWindow::~wxListHeaderWindow( void )
+wxListHeaderWindow::~wxListHeaderWindow()
{
delete m_resizeCursor;
}
void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h )
{
-#ifdef __WXGTK__
+#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
GtkStateType state = m_parent->IsEnabled() ? GTK_STATE_NORMAL
: GTK_STATE_INSENSITIVE;
gtk_paint_box (m_wxwindow->style, GTK_PIZZA(m_wxwindow)->bin_window,
state, GTK_SHADOW_OUT,
- (GdkRectangle*) NULL, m_wxwindow, "button",
+ (GdkRectangle*) NULL, m_wxwindow,
+ (char *)"button", // const_cast
x-1, y-1, w+2, h+2);
#elif defined( __WXMAC__ )
const int m_corner = 1;
dc->SetBrush( *wxTRANSPARENT_BRUSH );
- dc->SetPen( wxPen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) );
+ dc->SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) );
dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
dc->DrawLine( x+w-m_corner+1, y, x+w, y+h ); // right (outer)
dc->DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
- wxPen pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID );
+ wxPen pen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ), 1, wxSOLID );
dc->SetPen( pen );
dc->DrawLine( x+w-m_corner, y, x+w-1, y+h ); // right (inner)
void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
-#ifdef __WXGTK__
+#if defined(__WXGTK__)
wxClientDC dc( this );
#else
wxPaintDC dc( this );
int numColumns = m_owner->GetColumnCount();
wxListItem item;
- for (int i = 0; i < numColumns; i++)
+ for ( int i = 0; i < numColumns && x < w; i++ )
{
m_owner->GetColumn( i, item );
int wCol = item.m_width;
- int cw = wCol - 2; // the width of the rect to draw
- int xEnd = x + wCol;
+ // the width of the rect to draw: make it smaller to fit entirely
+ // inside the column rect
+ int cw = wCol - 2;
dc.SetPen( *wxWHITE_PEN );
DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 );
- wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw-5, h-4 );
+
+ // if we have an image, draw it on the right of the label
+ int image = item.m_image;
+ if ( image != -1 )
+ {
+ wxImageList *imageList = m_owner->m_small_image_list;
+ if ( imageList )
+ {
+ int ix, iy;
+ imageList->GetSize(image, ix, iy);
+
+ imageList->Draw
+ (
+ image,
+ dc,
+ x + cw - ix - 1,
+ HEADER_OFFSET_Y + (h - 4 - iy)/2,
+ wxIMAGELIST_DRAW_TRANSPARENT
+ );
+
+ cw -= ix + 2;
+ }
+ //else: ignore the column image
+ }
+
+ // draw the text clipping it so that it doesn't overwrite the column
+ // boundary
+ wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 );
dc.DrawText( item.GetText(),
x + EXTRA_WIDTH, HEADER_OFFSET_Y + EXTRA_HEIGHT );
x += wCol;
-
- if (xEnd > w+5)
- break;
}
+
dc.EndDrawing();
}
{
int x1 = m_currentX;
int y1 = 0;
- ClientToScreen( &x1, &y1 );
+ m_owner->ClientToScreen( &x1, &y1 );
- int x2 = m_currentX-1;
+ int x2 = m_currentX;
int y2 = 0;
m_owner->GetClientSize( NULL, &y2 );
m_owner->ClientToScreen( &x2, &y2 );
if (m_isDragging)
{
+ SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING,
+ event.GetPosition());
+
// we don't draw the line beyond our window, but we allow dragging it
// there
int w = 0;
m_isDragging = FALSE;
m_dirty = TRUE;
m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
+ SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG,
+ event.GetPosition());
}
else
{
int xpos = 0;
// find the column where this event occured
- int countCol = m_owner->GetColumnCount();
- for (int col = 0; col < countCol; col++)
+ int col,
+ countCol = m_owner->GetColumnCount();
+ for (col = 0; col < countCol; col++)
{
xpos += m_owner->GetColumnWidth( col );
m_column = col;
m_minX = xpos;
}
- if (event.LeftDown())
+ if ( col == countCol )
+ m_column = -1;
+
+ if (event.LeftDown() || event.RightUp())
{
- if (hit_border)
+ if (hit_border && event.LeftDown())
{
m_isDragging = TRUE;
m_currentX = x;
DrawCurrent();
CaptureMouse();
+ SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
+ event.GetPosition());
}
- else
+ else // click on a column
{
- wxWindow *parent = GetParent();
- wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, parent->GetId() );
- le.SetEventObject( parent );
- le.m_col = m_column;
- parent->GetEventHandler()->ProcessEvent( le );
+ SendListEvent( event.LeftDown()
+ ? wxEVT_COMMAND_LIST_COL_CLICK
+ : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
+ event.GetPosition());
}
}
else if (event.Moving())
m_owner->SetFocus();
}
+void wxListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos)
+{
+ wxWindow *parent = GetParent();
+ wxListEvent le( type, parent->GetId() );
+ le.SetEventObject( parent );
+ le.m_pointDrag = pos;
+
+ // the position should be relative to the parent window, not
+ // this one for compatibility with MSW and common sense: the
+ // user code doesn't know anything at all about this header
+ // window, so why should it get positions relative to it?
+ le.m_pointDrag.y -= GetSize().y;
+
+ le.m_col = m_column;
+ parent->GetEventHandler()->ProcessEvent( le );
+}
+
//-----------------------------------------------------------------------------
// wxListRenameTimer (internal)
//-----------------------------------------------------------------------------
// wxListTextCtrl (internal)
//-----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl,wxTextCtrl);
-
BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl)
EVT_CHAR (wxListTextCtrl::OnChar)
EVT_KEY_UP (wxListTextCtrl::OnKeyUp)
EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus)
END_EVENT_TABLE()
-wxListTextCtrl::wxListTextCtrl( wxWindow *parent,
- const wxWindowID id,
- bool *accept,
- wxString *res,
- wxListMainWindow *owner,
- const wxString &value,
- const wxPoint &pos,
- const wxSize &size,
- int style,
- const wxValidator& validator,
- const wxString &name )
- : wxTextCtrl( parent, id, value, pos, size, style, validator, name )
-{
- m_res = res;
- m_accept = accept;
+wxListTextCtrl::wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit)
+ : m_startValue(owner->GetItemText(itemEdit)),
+ m_itemEdited(itemEdit)
+{
m_owner = owner;
- (*m_accept) = FALSE;
- (*m_res) = "";
- m_startValue = value;
+ m_finished = FALSE;
+
+ wxRect rectLabel = owner->GetLineLabelRect(itemEdit);
+
+ m_owner->CalcScrolledPosition(rectLabel.x, rectLabel.y,
+ &rectLabel.x, &rectLabel.y);
+
+ (void)Create(owner, wxID_ANY, m_startValue,
+ wxPoint(rectLabel.x-4,rectLabel.y-4),
+ wxSize(rectLabel.width+11,rectLabel.height+8));
}
-void wxListTextCtrl::OnChar( wxKeyEvent &event )
+void wxListTextCtrl::Finish()
{
- if (event.m_keyCode == WXK_RETURN)
+ if ( !m_finished )
{
- (*m_accept) = TRUE;
- (*m_res) = GetValue();
+ wxPendingDelete.Append(this);
+
+ m_finished = TRUE;
+
+ m_owner->SetFocus();
+ }
+}
- if (!wxPendingDelete.Member(this))
- wxPendingDelete.Append(this);
+bool wxListTextCtrl::AcceptChanges()
+{
+ const wxString value = GetValue();
- if ((*m_accept) && ((*m_res) != m_startValue))
- m_owner->OnRenameAccept();
+ if ( value == m_startValue )
+ {
+ // nothing changed, always accept
+ return TRUE;
+ }
- return;
+ if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
+ {
+ // vetoed by the user
+ return FALSE;
}
- if (event.m_keyCode == WXK_ESCAPE)
+
+ // accepted, do rename the item
+ m_owner->SetItemText(m_itemEdited, value);
+
+ return TRUE;
+}
+
+void wxListTextCtrl::OnChar( wxKeyEvent &event )
+{
+ switch ( event.m_keyCode )
{
- (*m_accept) = FALSE;
- (*m_res) = "";
+ case WXK_RETURN:
+ if ( !AcceptChanges() )
+ {
+ // vetoed by the user code
+ break;
+ }
+ //else: fall through
- if (!wxPendingDelete.Member(this))
- wxPendingDelete.Append(this);
+ case WXK_ESCAPE:
+ Finish();
+ break;
- return;
+ default:
+ event.Skip();
}
-
- event.Skip();
}
void wxListTextCtrl::OnKeyUp( wxKeyEvent &event )
{
+ if (m_finished)
+ {
+ event.Skip();
+ return;
+ }
+
// auto-grow the textctrl:
wxSize parentSize = m_owner->GetSize();
wxPoint myPos = GetPosition();
wxSize mySize = GetSize();
int sx, sy;
- GetTextExtent(GetValue() + _T("MM"), &sx, &sy); // FIXME: MM??
+ GetTextExtent(GetValue() + _T("MM"), &sx, &sy);
if (myPos.x + sx > parentSize.x)
sx = parentSize.x - myPos.x;
if (mySize.x > sx)
event.Skip();
}
-void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
+void wxListTextCtrl::OnKillFocus( wxFocusEvent &event )
{
- if (!wxPendingDelete.Member(this))
- wxPendingDelete.Append(this);
+ if ( !m_finished )
+ {
+ (void)AcceptChanges();
+
+ Finish();
+ }
- if ((*m_accept) && ((*m_res) != m_startValue))
- m_owner->OnRenameAccept();
+ event.Skip();
}
//-----------------------------------------------------------------------------
// wxListMainWindow
//-----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow);
+IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow)
BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow)
EVT_PAINT (wxListMainWindow::OnPaint)
m_lastOnSame = FALSE;
m_renameTimer = new wxListRenameTimer( this );
- m_renameAccept = FALSE;
m_current =
- m_currentEdit =
m_lineLastClicked =
m_lineBeforeLastClicked = (size_t)-1;
+
+ m_freezeCount = 0;
}
void wxListMainWindow::InitScrolling()
m_highlightBrush = new wxBrush
(
- wxSystemSettings::GetSystemColour
+ wxSystemSettings::GetColour
(
wxSYS_COLOUR_HIGHLIGHT
),
m_highlightUnfocusedBrush = new wxBrush
(
- wxSystemSettings::GetSystemColour
+ wxSystemSettings::GetColour
(
wxSYS_COLOUR_BTNSHADOW
),
InitScrolling();
SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 );
- SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) );
+ SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ) );
}
wxListMainWindow::~wxListMainWindow()
{
wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
- if ( m_lines.IsEmpty() )
+ wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
+
+ wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
+
+ // we need to recreate the dummy line if the number of columns in the
+ // control changed as it would have the incorrect number of fields
+ // otherwise
+ if ( !m_lines.IsEmpty() &&
+ m_lines[0].m_items.GetCount() != (size_t)GetColumnCount() )
{
- // normal controls are supposed to have something in m_lines
- // already if it's not empty
- wxASSERT_MSG( IsVirtual(), _T("logic error") );
+ self->m_lines.Clear();
+ }
- wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
+ if ( m_lines.IsEmpty() )
+ {
wxListLineData *line = new wxListLineData(self);
self->m_lines.Add(line);
+
+ // don't waste extra memory -- there never going to be anything
+ // else/more in this array
+ self->m_lines.Shrink();
}
return &m_lines[0];
long wxListMainWindow::HitTestLine(size_t line, int x, int y) const
{
+ wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") );
+
wxListLineData *ld = GetLine(line);
if ( ld->HasImage() && GetLineIconRect(line).Inside(x, y) )
return wxLIST_HITTEST_ONITEMICON;
- if ( ld->HasText() )
+ // VS: Testing for "ld->HasText() || InReportView()" instead of
+ // "ld->HasText()" is needed to make empty lines in report view
+ // possible
+ if ( ld->HasText() || InReportView() )
{
wxRect rect = InReportView() ? GetLineRect(line)
: GetLineLabelRect(line);
to = GetItemCount() - 1;
}
- if ( HasCurrent() && m_current > from && m_current <= to )
+ if ( HasCurrent() && m_current >= from && m_current <= to )
{
RefreshLine(m_current);
}
}
}
+void wxListMainWindow::Freeze()
+{
+ m_freezeCount++;
+}
+
+void wxListMainWindow::Thaw()
+{
+ wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen list control?") );
+
+ if ( !--m_freezeCount )
+ {
+ Refresh();
+ }
+}
+
void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
// Note: a wxPaintDC must be constructed even if no drawing is
// done (a Windows requirement).
wxPaintDC dc( this );
- if ( IsEmpty() )
+ if ( IsEmpty() || m_freezeCount )
{
- // empty control. nothing to draw
+ // nothing to draw or not the moment to draw it
return;
}
// what we're trying to avoid
if ( !IsVirtual() && (command != wxEVT_COMMAND_LIST_DELETE_ITEM) )
{
- GetLine(line)->GetItem( 0, le.m_item );
+ if ( line != (size_t)-1 )
+ {
+ GetLine(line)->GetItem( 0, le.m_item );
+ }
+ //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
}
//else: there may be no more such item
GetParent()->GetEventHandler()->ProcessEvent( le );
}
-void wxListMainWindow::OnFocusLine( size_t WXUNUSED(line) )
+void wxListMainWindow::ChangeCurrent(size_t current)
{
-// SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
-}
+ m_current = current;
-void wxListMainWindow::OnUnfocusLine( size_t WXUNUSED(line) )
-{
-// SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
+ SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED);
}
void wxListMainWindow::EditLabel( long item )
wxCHECK_RET( (item >= 0) && ((size_t)item < GetItemCount()),
wxT("wrong index in wxListCtrl::EditLabel()") );
- m_currentEdit = (size_t)item;
+ size_t itemEdit = (size_t)item;
wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
le.SetEventObject( GetParent() );
le.m_itemIndex = item;
- wxListLineData *data = GetLine(m_currentEdit);
+ wxListLineData *data = GetLine(itemEdit);
wxCHECK_RET( data, _T("invalid index in EditLabel()") );
data->GetItem( 0, le.m_item );
- GetParent()->GetEventHandler()->ProcessEvent( le );
-
- if (!le.IsAllowed())
+ if ( GetParent()->GetEventHandler()->ProcessEvent( le ) && !le.IsAllowed() )
+ {
+ // vetoed by user code
return;
+ }
// We have to call this here because the label in question might just have
// been added and no screen update taken place.
- if (m_dirty)
+ if ( m_dirty )
wxSafeYield();
- wxClientDC dc(this);
- PrepareDC( dc );
+ wxListTextCtrl *text = new wxListTextCtrl(this, itemEdit);
- wxString s = data->GetText(0);
- wxRect rectLabel = GetLineLabelRect(m_currentEdit);
-
- rectLabel.x = dc.LogicalToDeviceX( rectLabel.x );
- rectLabel.y = dc.LogicalToDeviceY( rectLabel.y );
-
- wxListTextCtrl *text = new wxListTextCtrl
- (
- this, -1,
- &m_renameAccept,
- &m_renameRes,
- this,
- s,
- wxPoint(rectLabel.x-4,rectLabel.y-4),
- wxSize(rectLabel.width+11,rectLabel.height+8)
- );
text->SetFocus();
}
EditLabel( m_current );
}
-void wxListMainWindow::OnRenameAccept()
+bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value)
{
wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
le.SetEventObject( GetParent() );
- le.m_itemIndex = m_currentEdit;
+ le.m_itemIndex = itemEdit;
- wxListLineData *data = GetLine(m_currentEdit);
- wxCHECK_RET( data, _T("invalid index in OnRenameAccept()") );
+ wxListLineData *data = GetLine(itemEdit);
+ wxCHECK_MSG( data, FALSE, _T("invalid index in OnRenameAccept()") );
data->GetItem( 0, le.m_item );
- le.m_item.m_text = m_renameRes;
- GetParent()->GetEventHandler()->ProcessEvent( le );
-
- if (!le.IsAllowed()) return;
-
- wxListItem info;
- info.m_mask = wxLIST_MASK_TEXT;
- info.m_itemId = le.m_itemIndex;
- info.m_text = m_renameRes;
- info.SetTextColour(le.m_item.GetTextColour());
- SetItem( info );
+ le.m_item.m_text = value;
+ return !GetParent()->GetEventHandler()->ProcessEvent( le ) ||
+ le.IsAllowed();
}
void wxListMainWindow::OnMouse( wxMouseEvent &event )
if (event.Dragging())
{
if (m_dragCount == 0)
- m_dragStart = wxPoint(x,y);
+ {
+ // 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++;
m_renameTimer->Stop();
m_lastOnSame = FALSE;
+#ifdef __WXGTK__
+ // FIXME: wxGTK generates bad sequence of events prior to doubleclick
+ // ("down, up, down, double, up" while other ports
+ // do "down, up, double, up"). We have to have this hack
+ // in place till somebody fixes wxGTK...
if ( current == m_lineBeforeLastClicked )
+#else
+ if ( current == m_lineLastClicked )
+#endif
{
SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) )
{
HighlightAll( FALSE );
- m_current = current;
+
+ ChangeCurrent(current);
ReverseHighlight(m_current);
}
{
if (event.ControlDown())
{
- m_current = current;
+ ChangeCurrent(current);
ReverseHighlight(m_current);
}
else if (event.ShiftDown())
{
- m_current = current;
+ ChangeCurrent(current);
size_t lineFrom = oldCurrent,
lineTo = current;
if (m_current != oldCurrent)
{
RefreshLine( oldCurrent );
- OnUnfocusLine( oldCurrent );
- OnFocusLine( m_current );
}
// forceClick is only set if the previous click was on another item
// items anyhow
if ( event.ShiftDown() && !IsSingleSel() )
{
- m_current = newCurrent;
+ ChangeCurrent(newCurrent);
// select all the items between the old and the new one
if ( oldCurrent > newCurrent )
if ( !event.ControlDown() )
HighlightAll(FALSE);
- m_current = newCurrent;
+ ChangeCurrent(newCurrent);
- HighlightLine( oldCurrent, FALSE );
+ // refresh the old focus to remove it
RefreshLine( oldCurrent );
if ( !event.ControlDown() )
}
}
- OnUnfocusLine( oldCurrent );
- OnFocusLine( m_current );
RefreshLine( m_current );
MoveToFocus();
nevent.SetDirection( !event.ShiftDown() );
nevent.SetEventObject( GetParent()->GetParent() );
nevent.SetCurrentFocus( m_parent );
- if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) return;
+ if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent ))
+ return;
}
/* no item -> nothing to do */
case WXK_SPACE:
if ( IsSingleSel() )
{
- wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
- GetParent()->GetId() );
- le.SetEventObject( GetParent() );
- le.m_itemIndex = m_current;
- GetLine(m_current)->GetItem( 0, le.m_item );
- GetParent()->GetEventHandler()->ProcessEvent( le );
+ SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
if ( IsHighlighted(m_current) )
{
case WXK_RETURN:
case WXK_EXECUTE:
- {
- wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
- GetParent()->GetId() );
- le.SetEventObject( GetParent() );
- le.m_itemIndex = m_current;
- GetLine(m_current)->GetItem( 0, le.m_item );
- GetParent()->GetEventHandler()->ProcessEvent( le );
- }
+ SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
break;
default:
// focus handling
// ----------------------------------------------------------------------------
-#ifdef __WXGTK__
-extern wxWindow *g_focusWindow;
-#endif
+void wxListMainWindow::SetFocus()
+{
+ // VS: wxListMainWindow derives from wxPanel (via wxScrolledWindow) and wxPanel
+ // overrides SetFocus in such way that it does never change focus from
+ // panel's child to the panel itself. Unfortunately, we must be able to change
+ // focus to the panel from wxListTextCtrl because the text control should
+ // disappear when the user clicks outside it.
+
+ wxWindow *oldFocus = FindFocus();
+
+ if ( oldFocus && oldFocus->GetParent() == this )
+ {
+ wxWindow::SetFocus();
+ }
+ else
+ {
+ wxScrolledWindow::SetFocus();
+ }
+}
void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
{
- m_hasFocus = TRUE;
-
- if (!GetParent())
- return;
+ // wxGTK sends us EVT_SET_FOCUS events even if we had never got
+ // EVT_KILL_FOCUS before which means that we finish by redrawing the items
+ // which are already drawn correctly resulting in horrible flicker - avoid
+ // it
+ if ( !m_hasFocus )
+ {
+ m_hasFocus = TRUE;
- RefreshSelected();
+ RefreshSelected();
+ }
-#ifdef __WXGTK__
- g_focusWindow = GetParent();
-#endif
+ if ( !GetParent() )
+ return;
wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
event.SetEventObject( GetParent() );
_T("SetColumnWidth() can only be called in report mode.") );
m_dirty = TRUE;
+ wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
+ if ( headerWin )
+ headerWin->m_dirty = TRUE;
wxListHeaderDataList::Node *node = m_columns.Item( col );
wxCHECK_RET( node, _T("no column?") );
// don't do anything if this item is already focused
if ( item != m_current )
{
- OnUnfocusLine( m_current );
- m_current = item;
- OnFocusLine( m_current );
+ ChangeCurrent(item);
if ( oldCurrent != (size_t)-1 )
{
// don't do anything if this item is not focused
if ( item == m_current )
{
- OnUnfocusLine( m_current );
- m_current = (size_t)-1;
+ ResetCurrent();
+
+ if ( IsSingleSel() )
+ {
+ // we must unselect the old current item as well or we
+ // might end up with more than one selected item in a
+ // single selection control
+ HighlightLine(oldCurrent, FALSE);
+ }
RefreshLine( oldCurrent );
}
// single sel mode
if ( m_current != item )
{
- OnUnfocusLine( m_current );
- m_current = item;
- OnFocusLine( m_current );
+ ChangeCurrent(item);
if ( oldCurrent != (size_t)-1 )
{
}
}
-int wxListMainWindow::GetItemState( long item, long stateMask )
+int wxListMainWindow::GetItemState( long item, long stateMask ) const
{
wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), 0,
_T("invalid list ctrl item index in GetItemState()") );
return ret;
}
-void wxListMainWindow::GetItem( wxListItem &item )
+void wxListMainWindow::GetItem( wxListItem &item ) const
{
wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId < GetItemCount(),
_T("invalid item index in GetItem") );
m_dirty = TRUE;
}
-int wxListMainWindow::GetSelectedItemCount()
+int wxListMainWindow::GetSelectedItemCount() const
{
// deal with the quick case first
if ( IsSingleSel() )
// item position/size
// ----------------------------------------------------------------------------
-void wxListMainWindow::GetItemRect( long index, wxRect &rect )
+void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const
{
wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
_T("invalid index in GetItemRect") );
CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y);
}
-bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos)
+bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const
{
wxRect rect;
GetItemRect(item, rect);
else
iconSpacing = 0;
+ // Note that we do not call GetClientSize() here but
+ // GetSize() and substract the border size for sunken
+ // borders manually. This is technically incorrect,
+ // but we need to know the client area's size WITHOUT
+ // scrollbars here. Since we don't know if there are
+ // any scrollbars, we use GetSize() instead. Another
+ // solution would be to call SetScrollbars() here to
+ // remove the scrollbars and call GetClientSize() then,
+ // but this might result in flicker and - worse - will
+ // reset the scrollbars to 0 which is not good at all
+ // if you resize a dialog/window, but don't want to
+ // reset the window scrolling. RR.
+ // Furthermore, we actually do NOT subtract the border
+ // width as 2 pixels is just the extra space which we
+ // need around the actual content in the window. Other-
+ // wise the text would e.g. touch the upper border. RR.
int clientWidth,
clientHeight;
- GetClientSize( &clientWidth, &clientHeight );
+ GetSize( &clientWidth, &clientHeight );
if ( HasFlag(wxLC_REPORT) )
{
ResetVisibleLinesRange();
SetScrollbars( m_xScroll, m_yScroll,
- (GetHeaderWidth() + m_xScroll - 1)/m_xScroll,
+ GetHeaderWidth() / m_xScroll,
(entireHeight + m_yScroll - 1)/m_yScroll,
GetScrollPos(wxHORIZONTAL),
GetScrollPos(wxVERTICAL),
// fit into the window, we recalculate after subtracting an
// approximated 15 pt for the horizontal scrollbar
- clientHeight -= 4; // sunken frame
-
int entireWidth = 0;
for (int tries = 0; tries < 2; tries++)
{
- entireWidth = 0;
+ // We start with 4 for the border around all items
+ entireWidth = 4;
+
+ if (tries == 1)
+ {
+ // Now we have decided that the items do not fit into the
+ // client area. Unfortunately, wxWindows sometimes thinks
+ // that it does fit and therefore NO horizontal scrollbar
+ // is inserted. This looks ugly, so we fudge here and make
+ // the calculated width bigger than was actually has been
+ // calculated. This ensures that wxScrolledWindows puts
+ // a scrollbar at the bottom of its client area.
+ entireWidth += SCROLL_UNIT_X;
+ }
+
+ // Start at 2,2 so the text does not touch the border
int x = 2;
int y = 2;
int maxWidth = 0;
currentlyVisibleLines++;
wxListLineData *line = GetLine(i);
line->CalculateSize( &dc, iconSpacing );
- line->SetPosition( x, y, clientWidth, iconSpacing );
+ line->SetPosition( x, y, clientWidth, iconSpacing ); // Why clientWidth? (FIXME)
wxSize sizeLine = GetLineSize(i);
if (currentlyVisibleLines > m_linesPerPage)
m_linesPerPage = currentlyVisibleLines;
- // assume that the size of the next one is the same... (FIXME)
- if ( y + sizeLine.y - 6 >= clientHeight )
+ // Assume that the size of the next one is the same... (FIXME)
+ if ( y + sizeLine.y >= clientHeight )
{
currentlyVisibleLines = 0;
y = 2;
entireWidth += maxWidth+6;
maxWidth = 0;
}
+
+ // We have reached the last item.
if ( i == count - 1 )
entireWidth += maxWidth;
- if ((tries == 0) && (entireWidth > clientWidth))
+
+ if ( (tries == 0) && (entireWidth+SCROLL_UNIT_X > clientWidth) )
{
- clientHeight -= 15; // scrollbar height
+ clientHeight -= 15; // We guess the scrollbar height. (FIXME)
m_linesPerPage = 0;
currentlyVisibleLines = 0;
break;
}
+
if ( i == count - 1 )
- tries = 1; // everything fits, no second try required
+ tries = 1; // Everything fits, no second try required.
}
}
{
if ( !HasCurrent() && !IsEmpty() )
{
- m_current = 0;
- }
-
- if ( m_current != (size_t)-1 )
- {
- OnFocusLine( m_current );
+ ChangeCurrent(0);
}
}
long wxListMainWindow::GetNextItem( long item,
int WXUNUSED(geometry),
- int state )
+ int state ) const
{
long ret = item,
max = GetItemCount();
m_dirty = TRUE;
m_columns.DeleteNode( node );
+
+ // invalidate it as it has to be recalculated
+ m_headerWidth = 0;
}
void wxListMainWindow::DoDeleteAllItems()
void wxListMainWindow::DeleteEverything()
{
- DeleteAllItems();
-
m_columns.Clear();
+
+ DeleteAllItems();
}
// ----------------------------------------------------------------------------
// been added and its position is not known yet
if ( m_dirty )
{
- m_dirty = FALSE;
-
RecalculatePositions(TRUE /* no refresh */);
}
{
CalcUnscrolledPosition( x, y, &x, &y );
+ size_t count = GetItemCount();
+
if ( HasFlag(wxLC_REPORT) )
{
size_t current = y / GetLineHeight();
- flags = HitTestLine(current, x, y);
- if ( flags )
- return current;
+ if ( current < count )
+ {
+ flags = HitTestLine(current, x, y);
+ if ( flags )
+ return current;
+ }
}
else // !report
{
// TODO: optimize it too! this is less simple than for report view but
// enumerating all items is still not a way to do it!!
- size_t count = GetItemCount();
for ( size_t current = 0; current < count; current++ )
{
flags = HitTestLine(current, x, y);
{
m_columns.Append( column );
}
+
+ // invalidate it as it has to be recalculated
+ m_headerWidth = 0;
}
}
wxListCtrl* lc = GetListCtrl();
wxCHECK_RET( lc, _T("no listctrl window?") );
- lc->m_headerWin->Refresh() ;
-#ifdef __WXMAC__
- lc->m_headerWin->MacUpdateImmediately() ;
-#endif
+ lc->m_headerWin->Refresh();
+ lc->m_headerWin->Update();
}
}
IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
-wxListItem::wxListItem()
-{
- m_mask = 0;
- m_itemId = 0;
- m_col = 0;
- m_state = 0;
- m_stateMask = 0;
- m_image = 0;
- m_data = 0;
- m_format = wxLIST_FORMAT_CENTRE;
- m_width = 0;
-
- m_attr = NULL;
-}
-
-void wxListItem::Clear()
-{
- m_mask = 0;
- m_itemId = 0;
- m_col = 0;
- m_state = 0;
- m_stateMask = 0;
- m_image = 0;
- m_data = 0;
- m_format = wxLIST_FORMAT_CENTRE;
- m_width = 0;
- m_text = _T("");
-
- ClearAttributes();
-}
-
-void wxListItem::ClearAttributes()
-{
- if (m_attr)
- {
- delete m_attr;
- m_attr = NULL;
- }
-}
-
-// -------------------------------------------------------------------------------------
-// wxListEvent
-// -------------------------------------------------------------------------------------
-
-IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
-
-wxListEvent::wxListEvent( wxEventType commandType, int id )
- : wxNotifyEvent( commandType, id )
-{
- m_code = 0;
- m_itemIndex = 0;
- m_oldItemIndex = 0;
- m_col = 0;
- m_cancelled = FALSE;
- m_pointDrag.x = 0;
- m_pointDrag.y = 0;
-}
-
-void wxListEvent::CopyObject(wxObject& object_dest) const
-{
- wxListEvent *obj = (wxListEvent *)&object_dest;
-
- wxNotifyEvent::CopyObject(object_dest);
-
- obj->m_code = m_code;
- obj->m_itemIndex = m_itemIndex;
- obj->m_oldItemIndex = m_oldItemIndex;
- obj->m_col = m_col;
- obj->m_cancelled = m_cancelled;
- obj->m_pointDrag = m_pointDrag;
- obj->m_item.m_mask = m_item.m_mask;
- obj->m_item.m_itemId = m_item.m_itemId;
- obj->m_item.m_col = m_item.m_col;
- obj->m_item.m_state = m_item.m_state;
- obj->m_item.m_stateMask = m_item.m_stateMask;
- obj->m_item.m_text = m_item.m_text;
- obj->m_item.m_image = m_item.m_image;
- obj->m_item.m_data = m_item.m_data;
- obj->m_item.m_format = m_item.m_format;
- obj->m_item.m_width = m_item.m_width;
-
- if ( m_item.HasAttributes() )
- {
- obj->m_item.SetTextColour(m_item.GetTextColour());
- }
-}
-
// -------------------------------------------------------------------------------------
// wxListCtrl
// -------------------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
+IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
+
BEGIN_EVENT_TABLE(wxListCtrl,wxControl)
EVT_SIZE(wxListCtrl::OnSize)
EVT_IDLE(wxListCtrl::OnIdle)
wxListCtrl::~wxListCtrl()
{
- if ( m_mainWin )
- m_mainWin->ResetCurrent();
-
if (m_ownsImageListNormal)
delete m_imageListNormal;
if (m_ownsImageListSmall)
wxString wxListCtrl::GetItemText( long item ) const
{
- wxListItem info;
- info.m_itemId = item;
- m_mainWin->GetItem( info );
- return info.m_text;
+ return m_mainWin->GetItemText(item);
}
-void wxListCtrl::SetItemText( long item, const wxString &str )
+void wxListCtrl::SetItemText( long item, const wxString& str )
{
- wxListItem info;
- info.m_mask = wxLIST_MASK_TEXT;
- info.m_itemId = item;
- info.m_text = str;
- m_mainWin->SetItem( info );
+ m_mainWin->SetItemText(item, str);
}
long wxListCtrl::GetItemData( long item ) const
return m_mainWin->GetItemSpacing( isSmall );
}
+void wxListCtrl::SetItemTextColour( long item, const wxColour &col )
+{
+ wxListItem info;
+ info.m_itemId = item;
+ info.SetTextColour( col );
+ m_mainWin->SetItem( info );
+}
+
+wxColour wxListCtrl::GetItemTextColour( long item ) const
+{
+ wxListItem info;
+ info.m_itemId = item;
+ m_mainWin->GetItem( info );
+ return info.GetTextColour();
+}
+
+void wxListCtrl::SetItemBackgroundColour( long item, const wxColour &col )
+{
+ wxListItem info;
+ info.m_itemId = item;
+ info.SetBackgroundColour( col );
+ m_mainWin->SetItem( info );
+}
+
+wxColour wxListCtrl::GetItemBackgroundColour( long item ) const
+{
+ wxListItem info;
+ info.m_itemId = item;
+ m_mainWin->GetItem( info );
+ return info.GetBackgroundColour();
+}
+
int wxListCtrl::GetSelectedItemCount() const
{
return m_mainWin->GetSelectedItemCount();
{
size_t count = m_mainWin->m_columns.GetCount();
for ( size_t n = 0; n < count; n++ )
- DeleteColumn(n);
+ DeleteColumn(0);
return TRUE;
}
bool wxListCtrl::DeleteColumn( int col )
{
m_mainWin->DeleteColumn( col );
+
+ // if we don't have the header any longer, we need to relayout the window
+ if ( !GetColumnCount() )
+ {
+ ResizeReportView(FALSE /* no header */);
+ }
+
return TRUE;
}
long wxListCtrl::InsertColumn( long col, wxListItem &item )
{
- wxASSERT( m_headerWin );
+ wxCHECK_MSG( m_headerWin, -1, _T("can't add column in non report mode") );
+
m_mainWin->InsertColumn( col, item );
+
+ // if we hadn't had header before and have it now we need to relayout the
+ // window
+ if ( GetColumnCount() == 1 )
+ {
+ ResizeReportView(TRUE /* have header */);
+ }
+
m_headerWin->Refresh();
return 0;
// event handlers
// ----------------------------------------------------------------------------
-void wxListCtrl::OnSize(wxSizeEvent& event)
+void wxListCtrl::OnSize(wxSizeEvent& WXUNUSED(event))
{
if ( !m_mainWin )
return;
// virtual list control support
// ----------------------------------------------------------------------------
-wxString wxListCtrl::OnGetItemText(long item, long col) const
+wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) const
{
// this is a pure virtual function, in fact - which is not really pure
// because the controls which are not virtual don't need to implement it
- wxFAIL_MSG( _T("not supposed to be called") );
+ wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
return wxEmptyString;
}
-int wxListCtrl::OnGetItemImage(long item) const
+int wxListCtrl::OnGetItemImage(long WXUNUSED(item)) const
{
// same as above
- wxFAIL_MSG( _T("not supposed to be called") );
+ wxFAIL_MSG( _T("wxListCtrl::OnGetItemImage not supposed to be called") );
return -1;
}
m_mainWin->RefreshLines(itemFrom, itemTo);
}
+void wxListCtrl::Freeze()
+{
+ m_mainWin->Freeze();
+}
+
+void wxListCtrl::Thaw()
+{
+ m_mainWin->Thaw();
+}
+
#endif // wxUSE_LISTCTRL
+