#include "wx/listctrl.h"
-#if ((!defined(__WXMSW__) && !(defined(__WXMAC__) && wxOSX_USE_CARBON)) || defined(__WXUNIVERSAL__))
- // if we have a native version, its implementation file does all this
- IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
- IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
- IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
-
- IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxGenericListCtrl)
-#endif
-
#ifndef WX_PRECOMP
#include "wx/scrolwin.h"
#include "wx/timer.h"
else
colText = *wxBLACK;
#else
- colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
+ if ( hasFocus )
+ colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
+ else
+ colText = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT);
#endif
}
else if ( attr && attr->HasTextColour() )
int xOld = x;
x += width;
- const int wText = width - 8;
+ width -= 8;
+ const int wText = width;
wxDCClipper clipper(*dc, xOld, rect.y, wText, rect.height);
if ( item->HasImage() )
}
if ( item->HasText() )
- DrawTextFormatted(dc, item->GetText(), col, xOld, yMid, wText);
+ DrawTextFormatted(dc, item->GetText(), col, xOld, yMid, width);
}
}
// NB: The code below is not really Mac-specific, but since we are close
// to 2.8 release and I don't have time to test on other platforms, I
-// defined this only for wxMac. If this behavior is desired on
+// defined this only for wxMac. If this behaviour is desired on
// other platforms, please go ahead and revise or remove the #ifdef.
#ifdef __WXMAC__
if ( !m_owner->IsVirtual() && (item.m_mask & wxLIST_MASK_STATE) &&
m_text->PushEventHandler(this);
}
-void wxListTextCtrlWrapper::EndEdit(bool discardChanges)
+void wxListTextCtrlWrapper::EndEdit(EndReason reason)
{
m_aboutToFinish = true;
- if ( discardChanges )
+ switch ( reason )
{
- m_owner->OnRenameCancelled(m_itemEdited);
+ case End_Accept:
+ // Notify the owner about the changes
+ AcceptChanges();
- Finish( true );
- }
- else
- {
- // Notify the owner about the changes
- AcceptChanges();
+ // Even if vetoed, close the control (consistent with MSW)
+ Finish( true );
+ break;
- // Even if vetoed, close the control (consistent with MSW)
- Finish( true );
+ case End_Discard:
+ m_owner->OnRenameCancelled(m_itemEdited);
+
+ Finish( true );
+ break;
+
+ case End_Destroy:
+ // Don't generate any notifications for the control being destroyed
+ // and don't set focus to it neither.
+ Finish(false);
+ break;
}
}
switch ( event.m_keyCode )
{
case WXK_RETURN:
- EndEdit( false );
+ EndEdit( End_Accept );
break;
case WXK_ESCAPE:
- EndEdit( true );
+ EndEdit( End_Discard );
break;
default:
wxListMainWindow::~wxListMainWindow()
{
+ if ( m_textctrlWrapper )
+ m_textctrlWrapper->EndEdit(wxListTextCtrlWrapper::End_Destroy);
+
DoDeleteAllItems();
WX_CLEAR_LIST(wxListHeaderDataList, m_columns);
WX_CLEAR_ARRAY(m_aColWidths);
// 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_textctrlWrapper )
- m_textctrlWrapper->EndEdit( false );
+ m_textctrlWrapper->EndEdit(wxListTextCtrlWrapper::End_Accept);
#endif // __WXMAC__
if ( event.LeftDown() )
if (parent->GetEventHandler()->ProcessEvent( ke ))
return;
+ // send a list event
+ wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, parent->GetId() );
+ le.m_itemIndex = m_current;
+ if (HasCurrent())
+ GetLine(m_current)->GetItem( 0, le.m_item );
+ le.m_code = event.GetKeyCode();
+ le.SetEventObject( parent );
+ if (parent->GetEventHandler()->ProcessEvent( le ))
+ return;
+
event.Skip();
}
{
wxWindow *parent = GetParent();
- // send a list_key event up
- if ( HasCurrent() )
- {
- wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
- le.m_itemIndex = m_current;
- GetLine(m_current)->GetItem( 0, le.m_item );
- le.m_code = event.GetKeyCode();
- le.SetEventObject( parent );
- parent->GetEventHandler()->ProcessEvent( le );
- }
-
// propagate the char event upwards
wxKeyEvent ke(event);
ke.SetEventObject( parent );
wxListLineData *line = new wxListLineData(this);
line->SetItem( item.m_col, item );
+ if ( item.m_mask & wxLIST_MASK_IMAGE && item.GetImage() != -1)
+ {
+ // Reset the buffered height if it's not big enough for the new image.
+ if (m_small_image_list)
+ {
+ int imageWidth, imageHeight;
+ m_small_image_list->GetSize(item.GetImage(),
+ imageWidth, imageHeight);
+
+ if ( imageHeight > m_lineHeight )
+ m_lineHeight = 0;
+ }
+ }
m_lines.Insert( line, id );
wxListItem info;
info.m_text = label;
info.m_image = imageIndex;
- info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE;
+ info.m_mask = wxLIST_MASK_TEXT;
+ if (imageIndex > -1)
+ info.m_mask |= wxLIST_MASK_IMAGE;
info.m_itemId = index;
return InsertItem( info );
}
void wxGenericListCtrl::DoClientToScreen( int *x, int *y ) const
{
- m_mainWin->DoClientToScreen(x, y);
+ // It's not clear whether this can be called before m_mainWin is created
+ // but it seems better to be on the safe side and check.
+ if ( m_mainWin )
+ m_mainWin->DoClientToScreen(x, y);
+ else
+ wxControl::DoClientToScreen(x, y);
}
void wxGenericListCtrl::DoScreenToClient( int *x, int *y ) const
{
- m_mainWin->DoScreenToClient(x, y);
+ // At least in wxGTK/Univ build this method can be called before m_mainWin
+ // is created so avoid crashes in this case.
+ if ( m_mainWin )
+ m_mainWin->DoScreenToClient(x, y);
+ else
+ wxControl::DoScreenToClient(x, y);
}
void wxGenericListCtrl::SetFocus()