// headers
// ----------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "listctrl.h"
- #pragma implementation "listctrlbase.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
// when autosizing the columns, add some slack
static const int AUTOSIZE_COL_MARGIN = 10;
-// default and minimal widths for the header columns
+// default width for the header columns
static const int WIDTH_COL_DEFAULT = 80;
-static const int WIDTH_COL_MIN = 10;
// the space between the image and the text in the report mode
static const int IMAGE_MARGIN_IN_REPORT_MODE = 5;
WX_DECLARE_LIST(wxListItemData, wxListItemDataList);
#include "wx/listimpl.cpp"
-WX_DEFINE_LIST(wxListItemDataList);
+WX_DEFINE_LIST(wxListItemDataList)
class wxListLineData
{
void GetItem( int index, wxListItem &info );
wxString GetText(int index) const;
- void SetText( int index, const wxString s );
+ void SetText( int index, const wxString& s );
wxListItemAttr *GetAttr() const;
void SetAttr(wxListItemAttr *attr);
WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData, wxListLineDataArray);
#include "wx/arrimpl.cpp"
-WX_DEFINE_OBJARRAY(wxListLineDataArray);
+WX_DEFINE_OBJARRAY(wxListLineDataArray)
//-----------------------------------------------------------------------------
// wxListHeaderWindow (internal)
// generate and process the list event of the given type, return true if
// it wasn't vetoed, i.e. if we should proceed
- bool SendListEvent(wxEventType type, wxPoint pos);
+ bool SendListEvent(wxEventType type, const wxPoint& pos);
DECLARE_DYNAMIC_CLASS(wxListHeaderWindow)
DECLARE_EVENT_TABLE()
public:
wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit);
+ void AcceptChangesAndFinish();
+
protected:
void OnChar( wxKeyEvent &event );
void OnKeyUp( wxKeyEvent &event );
WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList);
#include "wx/listimpl.cpp"
-WX_DEFINE_LIST(wxListHeaderDataList);
+WX_DEFINE_LIST(wxListHeaderDataList)
class wxListMainWindow : public wxScrolledWindow
{
wxString GetItemText(long item) const
{
wxListItem info;
+ info.m_mask = wxLIST_MASK_TEXT;
info.m_itemId = item;
GetItem( info );
return info.m_text;
// send out a wxListEvent
void SendNotify( size_t line,
wxEventType command,
- wxPoint point = wxDefaultPosition );
+ const wxPoint& point = wxDefaultPosition );
// override base class virtual to reset m_lineHeight when the font changes
virtual bool SetFont(const wxFont& font)
m_lineBeforeLastClicked,
m_lineSelectSingleOnUp;
+ wxListTextCtrl* m_textctrl;
+
protected:
// the total count of items in a virtual list control
size_t m_countVirt;
// get the colour to be used for drawing the rules
wxColour GetRuleColour() const
{
-#ifdef __WXMAC__
- return *wxWHITE;
-#else
return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT);
-#endif
}
private:
void wxListItemData::GetItem( wxListItem &info ) const
{
- info.m_text = m_text;
- info.m_image = m_image;
- info.m_data = m_data;
+ long mask = info.m_mask;
+ if ( !mask )
+ {
+ // by default, get everything for backwards compatibility
+ mask = -1;
+ }
+
+ if ( mask & wxLIST_MASK_TEXT )
+ info.m_text = m_text;
+ if ( mask & wxLIST_MASK_IMAGE )
+ info.m_image = m_image;
+ if ( mask & wxLIST_MASK_DATA )
+ info.m_data = m_data;
if ( m_attr )
{
void wxListHeaderData::SetWidth( int w )
{
- m_width = w;
- if (m_width < 0)
- m_width = WIDTH_COL_DEFAULT;
- else if (m_width < WIDTH_COL_MIN)
- m_width = WIDTH_COL_MIN;
+ m_width = w < 0 ? WIDTH_COL_DEFAULT : w;
}
void wxListHeaderData::SetFormat( int format )
return s;
}
-void wxListLineData::SetText( int index, const wxString s )
+void wxListLineData::SetText( int index, const wxString& s )
{
wxListItemDataList::compatibility_iterator node = m_items.Item( index );
if (node)
// end of the current column
int xpos = 0;
- // find the column where this event occured
+ // find the column where this event occurred
int col,
countCol = m_owner->GetColumnCount();
for (col = 0; col < countCol; col++)
m_owner->Update();
}
-bool wxListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos)
+bool wxListHeaderWindow::SendListEvent(wxEventType type, const wxPoint& pos)
{
wxWindow *parent = GetParent();
wxListEvent le( type, parent->GetId() );
if ( !m_finished )
{
wxPendingDelete.Append(this);
-
+ m_owner->m_textctrl = NULL;
+
m_finished = true;
m_owner->SetFocusIgnoringChildren();
return true;
}
+void wxListTextCtrl::AcceptChangesAndFinish()
+{
+ m_aboutToFinish = true;
+ // Notify the owner about the changes
+ AcceptChanges();
+ // Even if vetoed, close the control (consistent with MSW)
+ Finish();
+}
+
void wxListTextCtrl::OnChar( wxKeyEvent &event )
{
switch ( event.m_keyCode )
{
case WXK_RETURN:
- m_aboutToFinish = true;
- // Notify the owner about the changes
- AcceptChanges();
- // Even if vetoed, close the control (consistent with MSW)
- Finish();
+ AcceptChangesAndFinish();
break;
case WXK_ESCAPE:
void wxListTextCtrl::OnKillFocus( wxFocusEvent &event )
{
- if ( !m_finished )
+ if ( !m_finished && !m_aboutToFinish )
{
// We must finish regardless of success, otherwise we'll get
// focus problems:
m_lastOnSame = false;
m_renameTimer = new wxListRenameTimer( this );
-
+ m_textctrl = NULL;
+
m_current =
m_lineLastClicked =
m_lineSelectSingleOnUp =
wxSOLID
);
- wxSize sz = size;
- sz.y = 25;
-
SetScrollbars( 0, 0, 0, 0, 0, 0 );
wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes();
void wxListMainWindow::SendNotify( size_t line,
wxEventType command,
- wxPoint point )
+ const wxPoint& point )
{
wxListEvent le( command, GetParent()->GetId() );
le.SetEventObject( GetParent() );
if ( m_dirty )
wxSafeYield();
- wxListTextCtrl *text = new wxListTextCtrl(this, itemEdit);
-
- text->SetFocus();
+ m_textctrl = new wxListTextCtrl(this, itemEdit);
+ m_textctrl->SetFocus();
}
void wxListMainWindow::OnRenameTimer()
void wxListMainWindow::OnMouse( wxMouseEvent &event )
{
+#ifdef __WXMAC__
+ // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
+ // shutdown the edit control when the mouse is clicked elsewhere on the
+ // listctrl because the order of events is different (or something like
+ // that,) so explicitly end the edit if it is active.
+ if ( event.LeftDown() && m_textctrl)
+ {
+ m_textctrl->AcceptChangesAndFinish();
+ }
+#endif
+
event.SetEventObject( GetParent() );
if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
return;
HighlightAll( false );
ReverseHighlight(m_lineSelectSingleOnUp);
}
- else if (m_lastOnSame)
+ if (m_lastOnSame)
{
if ((current == m_current) &&
(hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
- HasFlag(wxLC_EDIT_LABELS) )
+ HasFlag(wxLC_EDIT_LABELS) )
{
m_renameTimer->Start( 100, true );
}
}
else
{
- // This is neccessary , because after a DnD operation in
+ // This is necessary, because after a DnD operation in
// from and to ourself, the up event is swallowed by the
// DnD code. So on next non-up event (which means here and
// now) m_lineSelectSingleOnUp should be reset.
m_lineLastClicked = current;
size_t oldCurrent = m_current;
+ bool oldWasSelected = IsHighlighted(m_current);
+
bool cmdModifierDown = event.CmdDown();
if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
{
}
// forceClick is only set if the previous click was on another item
- m_lastOnSame = !forceClick && (m_current == oldCurrent);
+ m_lastOnSame = !forceClick && (m_current == oldCurrent) && oldWasSelected;
}
}
wxListLineData *line = GetLine((size_t)id);
line->SetItem( item.m_col, item );
+ // Set item state if user wants
+ if ( item.m_mask & wxLIST_MASK_STATE )
+ SetItemState( item.m_itemId, item.m_state, item.m_state );
+
if (InReportView())
{
// update the Max Width Cache if needed
return;
}
- wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(),
- _T("invalid list ctrl item index in SetItem") );
+ wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(),
+ _T("invalid list ctrl item index in SetItem") );
size_t oldCurrent = m_current;
size_t item = (size_t)litem; // safe because of the check above
wxListLineData *line = GetLine((size_t)item.m_itemId);
line->GetItem( item.m_col, item );
+
+ // Get item state if user wants it
+ if ( item.m_mask & wxLIST_MASK_STATE )
+ item.m_state = GetItemState( item.m_itemId, wxLIST_STATE_SELECTED |
+ wxLIST_STATE_FOCUSED );
}
// ----------------------------------------------------------------------------
ResetVisibleLinesRange();
// FIXME
-#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
+#if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
wxScrolledWindow::OnScroll(event);
#else
HandleOnScroll( event );
wxUIntPtr wxGenericListCtrl::GetItemData( long item ) const
{
wxListItem info;
+ info.m_mask = wxLIST_MASK_DATA;
info.m_itemId = item;
m_mainWin->GetItem( info );
return info.m_data;
return info.GetBackgroundColour();
}
+void wxGenericListCtrl::SetItemFont( long item, const wxFont &f )
+{
+ wxListItem info;
+ info.m_itemId = item;
+ info.SetFont( f );
+ m_mainWin->SetItem( info );
+}
+
+wxFont wxGenericListCtrl::GetItemFont( long item ) const
+{
+ wxListItem info;
+ info.m_itemId = item;
+ m_mainWin->GetItem( info );
+ return info.GetFont();
+}
+
int wxGenericListCtrl::GetSelectedItemCount() const
{
return m_mainWin->GetSelectedItemCount();