#endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL
#include "wx/selstore.h"
-
#include "wx/renderer.h"
+#include "wx/math.h"
#ifdef __WXMAC__
#include "wx/mac/private.h"
#endif
-#include <math.h>
// NOTE: If using the wxListBox visual attributes works everywhere then this can
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)
+#if WXWIN_COMPATIBILITY_2_4
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO)
+#endif
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN)
void SetItem( const wxListItem &info );
void SetImage( int image ) { m_image = image; }
- void SetData( long data ) { m_data = data; }
+ void SetData( wxUIntPtr data ) { m_data = data; }
void SetPosition( int x, int y );
void SetSize( int width, int height );
int m_image;
// user data associated with the item
- long m_data;
+ wxUIntPtr m_data;
// the item coordinates are not used in report mode, instead this pointer
// is NULL and the owner window is used to retrieve the item position and
virtual ~wxListMainWindow();
+ wxWindow *GetMainWindowOfCompositeControl() { return GetParent(); }
+
bool HasFlag(int flag) const { return m_parent->HasFlag(flag); }
// return true if this is a virtual list control
void Freeze();
void Thaw();
- void SetFocus();
-
void OnRenameTimer();
bool OnRenameAccept(size_t itemEdit, const wxString& value);
void OnRenameCancelled(size_t itemEdit);
void DeleteEverything();
void EnsureVisible( long index );
long FindItem( long start, const wxString& str, bool partial = false );
- long FindItem( long start, long data);
+ long FindItem( long start, wxUIntPtr data);
long FindItem( const wxPoint& pt );
long HitTest( int x, int y, int &flags );
void InsertItem( wxListItem &item );
m_finished = true;
- m_owner->SetFocus();
+ m_owner->SetFocusIgnoringChildren();
}
}
switch ( event.m_keyCode )
{
case WXK_RETURN:
- if ( !AcceptChanges() )
+ if ( AcceptChanges() )
{
- // vetoed by the user code
- break;
+ // Close the text control, changes were accepted
+ Finish();
}
- //else: fall through
+ // else do nothing, do not accept and do not close
+
+ break;
case WXK_ESCAPE:
Finish();
// focus handling
// ----------------------------------------------------------------------------
-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) )
{
if ( GetParent() )
iconSpacing = 0;
// Note that we do not call GetClientSize() here but
- // GetSize() and substract the border size for sunken
+ // GetSize() and subtract 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
return wxNOT_FOUND;
}
-long wxListMainWindow::FindItem(long start, long data)
+long wxListMainWindow::FindItem(long start, wxUIntPtr data)
{
long pos = start;
if (pos < 0)
long wxListMainWindow::FindItem( const wxPoint& pt )
{
- wxPoint p;
- long topItem = GetTopItem();
+ size_t topItem;
+ GetVisibleLinesRange(&topItem, NULL);
- GetItemPosition( GetItemCount()-1, p );
- if( p.y == 0 )
- return topItem;
- long id = (long) floor( pt.y*(GetItemCount()-topItem-1)/p.y+topItem );
- if( id >= 0 && id < (long)GetItemCount() )
- return id;
+ wxPoint p;
+ GetItemPosition( GetItemCount()-1, p );
+ if( p.y == 0 )
+ return topItem;
+ long id = (long) floor( pt.y*double(GetItemCount()-topItem-1)/p.y+topItem );
+ if( id >= 0 && id < (long)GetItemCount() )
+ return id;
- return wxNOT_FOUND;
+ return wxNOT_FOUND;
}
long wxListMainWindow::HitTest( int x, int y, int &flags )
if (item.m_itemId > count)
item.m_itemId = count;
-
+
size_t id = item.m_itemId;
m_dirty = true;
wxListLineData *line = new wxListLineData(this);
- line->SetItem( 0, item );
+ line->SetItem( item.m_col, item );
m_lines.Insert( line, id );
wxListLineData *line2 = *arg2;
wxListItem item;
line1->GetItem( 0, item );
- long data1 = item.m_data;
+ wxUIntPtr data1 = item.m_data;
line2->GetItem( 0, item );
- long data2 = item.m_data;
+ wxUIntPtr data2 = item.m_data;
return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data );
}
m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0,0), size, style );
-#if defined( __WXMAC__ ) && __WXMAC_CARBON__
- wxFont font ;
- font.MacCreateThemeFont( kThemeViewsFont ) ;
- SetFont( font ) ;
+#ifdef __WXMAC_CARBON__
+ // Human Interface Guidelines ask us for a special font in this case
+ if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL )
+ {
+ wxFont font ;
+ font.MacCreateThemeFont( kThemeViewsFont ) ;
+ SetFont( font ) ;
+ }
#endif
if ( InReportView() )
{
return true;
}
-bool wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
+bool
+wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
{
wxListItem info;
info.m_image = image;
m_mainWin->SetItemText(item, str);
}
-long wxGenericListCtrl::GetItemData( long item ) const
+wxUIntPtr wxGenericListCtrl::GetItemData( long item ) const
{
wxListItem info;
info.m_itemId = item;
return m_mainWin->FindItem( start, str, partial );
}
-long wxGenericListCtrl::FindItem( long start, long data )
+long wxGenericListCtrl::FindItem( long start, wxUIntPtr data )
{
return m_mainWin->FindItem( start, data );
}
{
/* The test in window.cpp fails as we are a composite
window, so it checks against "this", but not m_mainWin. */
- if ( FindFocus() != this )
+ if ( DoFindFocus() != this )
m_mainWin->SetFocus();
}
+wxSize wxGenericListCtrl::DoGetBestSize() const
+{
+ // Something is better than nothing...
+ // 100x80 is what the MSW version will get from the default
+ // wxControl::DoGetBestSize
+ return wxSize(100,80);
+}
+
// ----------------------------------------------------------------------------
// virtual list control support
// ----------------------------------------------------------------------------
int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item)) const
{
- // same as above
- wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemImage not supposed to be called") );
-
+ wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL),
+ -1,
+ wxT("List control has an image list, OnGetItemImage should be overridden."));
return -1;
}