Listctrl updates

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1123 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1998-12-07 13:28:56 +00:00
parent 6daa06370b
commit e487524e49
4 changed files with 73 additions and 74 deletions

View File

@@ -548,37 +548,37 @@ class wxListCtrl: public wxControl
long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator, long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator,
const wxString &name = "listctrl" ); const wxString &name = "listctrl" );
void OnSize( wxSizeEvent &event ); void OnSize( wxSizeEvent &event );
bool GetColumn( int col, wxListItem& item ); bool GetColumn( int col, wxListItem& item ) const;
bool SetColumn( int col, wxListItem& item ); bool SetColumn( int col, wxListItem& item );
int GetColumnWidth( int col ); int GetColumnWidth( int col ) const;
bool SetColumnWidth( int col, int width); bool SetColumnWidth( int col, int width);
int GetCountPerPage(void); // not the same in wxGLC as in Windows, I think int GetCountPerPage(void) const; // not the same in wxGLC as in Windows, I think
// wxText& GetEditControl(void) const; // not supported in wxGLC // wxText& GetEditControl(void) const; // not supported in wxGLC
bool GetItem( wxListItem& info ); bool GetItem( wxListItem& info ) const;
bool SetItem( wxListItem& info ) ; bool SetItem( wxListItem& info ) ;
long SetItem( long index, int col, const wxString& label, int imageId = -1 ); long SetItem( long index, int col, const wxString& label, int imageId = -1 );
int GetItemState( long item, long stateMask ); int GetItemState( long item, long stateMask ) const;
bool SetItemState( long item, long state, long stateMask); bool SetItemState( long item, long state, long stateMask);
bool SetItemImage( long item, int image, int selImage); bool SetItemImage( long item, int image, int selImage);
wxString GetItemText( long item ); wxString GetItemText( long item ) const;
void SetItemText( long item, const wxString& str ); void SetItemText( long item, const wxString& str );
long GetItemData( long item ); long GetItemData( long item ) const;
bool SetItemData( long item, long data ); bool SetItemData( long item, long data );
bool GetItemRect( long item, wxRectangle& rect, int code = wxLIST_RECT_BOUNDS ); bool GetItemRect( long item, wxRectangle& rect, int code = wxLIST_RECT_BOUNDS ) const;
bool GetItemPosition( long item, wxPoint& pos ); bool GetItemPosition( long item, wxPoint& pos ) const;
bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC
int GetItemCount(void); int GetItemCount(void) const;
void SetItemSpacing( int spacing, bool isSmall = FALSE ); void SetItemSpacing( int spacing, bool isSmall = FALSE );
int GetItemSpacing( bool isSmall ); int GetItemSpacing( bool isSmall ) const;
int GetSelectedItemCount(void); int GetSelectedItemCount(void) const;
// wxColour GetTextColour(void) const; // wxGLC has colours for every Item (see wxListItem) // wxColour GetTextColour(void) const; // wxGLC has colours for every Item (see wxListItem)
// void SetTextColour(const wxColour& col); // void SetTextColour(const wxColour& col);
long GetTopItem(void); long GetTopItem(void) const;
void SetSingleStyle( long style, bool add = TRUE ) ; void SetSingleStyle( long style, bool add = TRUE ) ;
void SetWindowStyleFlag(long style); void SetWindowStyleFlag(long style);
void RecreateWindow(void) {}; void RecreateWindow(void) {};
long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const; long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const;
wxImageList *GetImageList(int which); wxImageList *GetImageList(int which) const;
void SetImageList(wxImageList *imageList, int which) ; void SetImageList(wxImageList *imageList, int which) ;
bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
bool DeleteItem( long item ); bool DeleteItem( long item );

View File

@@ -55,7 +55,7 @@ BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo) EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo)
EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected) EVT_LIST_ITEM_SELECTED(LIST_CTRL, MyListCtrl::OnSelected)
EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected) EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected)
EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnKeyDown) EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
END_EVENT_TABLE() END_EVENT_TABLE()
IMPLEMENT_APP(MyApp) IMPLEMENT_APP(MyApp)
@@ -374,7 +374,7 @@ void MyListCtrl::OnDeleteItem(wxListEvent& WXUNUSED(event))
text->WriteText("OnDeleteItem\n"); text->WriteText("OnDeleteItem\n");
} }
void MyListCtrl::OnGetInfo(wxListEvent& event) void MyListCtrl::OnGetInfo(wxListEvent& /*event*/)
{ {
if ( !wxGetApp().GetTopWindow() ) if ( !wxGetApp().GetTopWindow() )
return; return;
@@ -449,7 +449,7 @@ void MyListCtrl::OnDeselected(wxListEvent& WXUNUSED(event))
text->WriteText("OnDeselected\n"); text->WriteText("OnDeselected\n");
} }
void MyListCtrl::OnKeyDown(wxListEvent& WXUNUSED(event)) void MyListCtrl::OnListKeyDown(wxListEvent& WXUNUSED(event))
{ {
if ( !wxGetApp().GetTopWindow() ) if ( !wxGetApp().GetTopWindow() )
return; return;
@@ -458,6 +458,6 @@ void MyListCtrl::OnKeyDown(wxListEvent& WXUNUSED(event))
if ( !text ) if ( !text )
return; return;
text->WriteText("OnKeyDown\n"); text->WriteText("OnListKeyDown\n");
} }

View File

@@ -36,7 +36,7 @@ public:
void OnSetInfo(wxListEvent& event); void OnSetInfo(wxListEvent& event);
void OnSelected(wxListEvent& event); void OnSelected(wxListEvent& event);
void OnDeselected(wxListEvent& event); void OnDeselected(wxListEvent& event);
void OnKeyDown(wxListEvent& event); void OnListKeyDown(wxListEvent& event);
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@@ -1313,7 +1313,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
void wxListMainWindow::MoveToFocus( void ) void wxListMainWindow::MoveToFocus( void )
{ {
if (!m_current) return; if (!m_current) return;
/*
int x = 0; int x = 0;
int y = 0; int y = 0;
int w = 0; int w = 0;
@@ -1328,7 +1328,8 @@ void wxListMainWindow::MoveToFocus( void )
int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
if ((y > y_s) && (y+h < y_s+h_p)) return; if ((y > y_s) && (y+h < y_s+h_p)) return;
if (y-y_s < 5) SetScrollPos( wxVERTICAL, (y-5)/m_yScroll ); if (y-y_s < 5) SetScrollPos( wxVERTICAL, (y-5)/m_yScroll );
if (y+h+5 > y_s+h_p) SetScrollPos( wxVERTICAL, (y+h-h_p+h+5)/m_yScroll ); if (y+h+5 > y_s+h_p) SetScrollPos( wxVERTICAL, (y+h-h_p+h+15)/m_yScroll );
m_dirty = TRUE;
} }
else else
{ {
@@ -1336,9 +1337,9 @@ void wxListMainWindow::MoveToFocus( void )
int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL ); int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
if ((x > x_s) && (x+w < x_s+w_p)) return; if ((x > x_s) && (x+w < x_s+w_p)) return;
if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll ); if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll );
if (x+w > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+5)/m_xScroll ); if (x+w-5 > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+15)/m_xScroll );
m_dirty = TRUE;
} }
*/
} }
void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown ) void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown )
@@ -1859,37 +1860,28 @@ long wxListMainWindow::GetMode( void ) const
void wxListMainWindow::CalculatePositions( void ) void wxListMainWindow::CalculatePositions( void )
{ {
if (!m_lines.First()) return;
wxPaintDC dc( this ); wxPaintDC dc( this );
dc.SetFont( *GetFont() ); dc.SetFont( *GetFont() );
int iconSpacing = 0; int iconSpacing = 0;
if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing; if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing;
if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing; if (m_mode & wxLC_SMALL_ICON) iconSpacing = m_small_spacing;
wxNode *node = m_lines.First();
while (node) // we take the first line (which also can be an icon or
{ // an a text item in wxLC_ICON and wxLC_LIST modes) to
wxListLineData *line = (wxListLineData*)node->Data(); // measure the size of the line
line->CalculateSize( &dc, iconSpacing );
node = node->Next();
}
int lineWidth = 0; int lineWidth = 0;
int lineHeight = 0; int lineHeight = 0;
int lineSpacing = 0; int lineSpacing = 0;
node = m_lines.First(); wxListLineData *line = (wxListLineData*)m_lines.First()->Data();
if (node) line->CalculateSize( &dc, iconSpacing );
{ int dummy = 0;
wxListLineData *line = (wxListLineData*)node->Data(); line->GetSize( dummy, lineSpacing );
int dummy = 0; lineSpacing += 4;
line->GetSize( dummy, lineSpacing );
lineSpacing += 4;
}
else
{
// just in case
lineSpacing = 4 + (int)dc.GetCharHeight();
}
int clientWidth = 0; int clientWidth = 0;
int clientHeight = 0; int clientHeight = 0;
@@ -1897,15 +1889,17 @@ void wxListMainWindow::CalculatePositions( void )
if (m_mode & wxLC_REPORT) if (m_mode & wxLC_REPORT)
{ {
int x = 4; int x = 4;
int y = 3; int y = 1;
int entireHeight = m_lines.Number() * lineSpacing + 10; int entireHeight = m_lines.Number() * lineSpacing + 10;
SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+10) / m_yScroll, 0, 0, TRUE ); int scroll_pos = GetScrollPos( wxVERTICAL );
SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+10) / m_yScroll, 0, scroll_pos, TRUE );
GetClientSize( &clientWidth, &clientHeight ); GetClientSize( &clientWidth, &clientHeight );
node = m_lines.First(); wxNode* node = m_lines.First();
while (node) while (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = (wxListLineData*)node->Data();
line->CalculateSize( &dc, iconSpacing );
line->SetPosition( &dc, x, y, clientWidth ); line->SetPosition( &dc, x, y, clientWidth );
int col_x = 2; int col_x = 2;
for (int i = 0; i < GetColumnCount(); i++) for (int i = 0; i < GetColumnCount(); i++)
@@ -1919,7 +1913,10 @@ void wxListMainWindow::CalculatePositions( void )
} }
else else
{ {
// At first, we try without any scrollbar // at first we try without any scrollbar. if the items don't
// fit into the window, we recalculate after subtracting an
// approximated 15 pt for the horizontal scrollbar
GetSize( &clientWidth, &clientHeight ); GetSize( &clientWidth, &clientHeight );
int entireWidth = 0; int entireWidth = 0;
@@ -1928,34 +1925,36 @@ void wxListMainWindow::CalculatePositions( void )
{ {
entireWidth = 0; entireWidth = 0;
int x = 5; int x = 5;
int y = 6; int y = 3;
int maxWidth = 0; int maxWidth = 0;
node = m_lines.First(); wxNode *node = m_lines.First();
while (node) while (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = (wxListLineData*)node->Data();
line->CalculateSize( &dc, iconSpacing );
line->SetPosition( &dc, x, y, clientWidth ); line->SetPosition( &dc, x, y, clientWidth );
line->GetSize( lineWidth, lineHeight ); line->GetSize( lineWidth, lineHeight );
if (lineWidth > maxWidth) maxWidth = lineWidth; if (lineWidth > maxWidth) maxWidth = lineWidth;
y += lineSpacing; y += lineSpacing;
if (y+lineHeight > clientHeight-4) if (y+lineSpacing-8 > clientHeight-6)
{ {
y = 6; y = 3;
x += maxWidth+13; x += maxWidth+13;
entireWidth += maxWidth+13; entireWidth += maxWidth+13;
maxWidth = 0; maxWidth = 0;
} }
node = node->Next(); node = node->Next();
if (!node) entireWidth += maxWidth; if (!node) entireWidth += maxWidth;
if ((tries == 0) && (entireWidth > clientWidth)) if ((tries == 0) && (entireWidth > clientWidth))
{ {
clientHeight -= 14; // scrollbar height clientHeight -= 15; // scrollbar height
break; break;
} }
if (!node) tries = 1; if (!node) tries = 1; // everything fits, no second try required
} }
} }
SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, 0, 0, TRUE ); int scroll_pos = GetScrollPos( wxHORIZONTAL );
SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE );
} }
m_visibleLines = (clientHeight-4) / (lineSpacing); m_visibleLines = (clientHeight-4) / (lineSpacing);
} }
@@ -2346,7 +2345,7 @@ void wxListCtrl::SetWindowStyleFlag( long flag )
wxWindow::SetWindowStyleFlag( flag ); wxWindow::SetWindowStyleFlag( flag );
} }
bool wxListCtrl::GetColumn(int col, wxListItem &item) bool wxListCtrl::GetColumn(int col, wxListItem &item) const
{ {
m_mainWin->GetColumn( col, item ); m_mainWin->GetColumn( col, item );
return TRUE; return TRUE;
@@ -2358,7 +2357,7 @@ bool wxListCtrl::SetColumn( int col, wxListItem& item )
return TRUE; return TRUE;
} }
int wxListCtrl::GetColumnWidth( int col ) int wxListCtrl::GetColumnWidth( int col ) const
{ {
return m_mainWin->GetColumnWidth( col ); return m_mainWin->GetColumnWidth( col );
} }
@@ -2369,7 +2368,7 @@ bool wxListCtrl::SetColumnWidth( int col, int width )
return TRUE; return TRUE;
} }
int wxListCtrl::GetCountPerPage(void) int wxListCtrl::GetCountPerPage(void) const
{ {
return m_mainWin->GetCountPerPage(); // different from Windows ? return m_mainWin->GetCountPerPage(); // different from Windows ?
} }
@@ -2380,7 +2379,7 @@ wxText& wxListCtrl::GetEditControl(void) const
} }
*/ */
bool wxListCtrl::GetItem( wxListItem &info ) bool wxListCtrl::GetItem( wxListItem &info ) const
{ {
m_mainWin->GetItem( info ); m_mainWin->GetItem( info );
return TRUE; return TRUE;
@@ -2409,7 +2408,7 @@ long wxListCtrl::SetItem( long index, int col, const wxString& label, int imageI
return TRUE; return TRUE;
} }
int wxListCtrl::GetItemState( long item, long stateMask ) int wxListCtrl::GetItemState( long item, long stateMask ) const
{ {
return m_mainWin->GetItemState( item, stateMask ); return m_mainWin->GetItemState( item, stateMask );
} }
@@ -2430,7 +2429,7 @@ bool wxListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) )
return TRUE; return TRUE;
} }
wxString wxListCtrl::GetItemText( long item ) wxString wxListCtrl::GetItemText( long item ) const
{ {
wxListItem info; wxListItem info;
info.m_itemId = item; info.m_itemId = item;
@@ -2447,7 +2446,7 @@ void wxListCtrl::SetItemText( long item, const wxString &str )
m_mainWin->SetItem( info ); m_mainWin->SetItem( info );
} }
long wxListCtrl::GetItemData( long item ) long wxListCtrl::GetItemData( long item ) const
{ {
wxListItem info; wxListItem info;
info.m_itemId = item; info.m_itemId = item;
@@ -2465,13 +2464,13 @@ bool wxListCtrl::SetItemData( long item, long data )
return TRUE; return TRUE;
} }
bool wxListCtrl::GetItemRect( long item, wxRectangle &rect, int WXUNUSED(code) ) bool wxListCtrl::GetItemRect( long item, wxRectangle &rect, int WXUNUSED(code) ) const
{ {
m_mainWin->GetItemRect( item, rect ); m_mainWin->GetItemRect( item, rect );
return TRUE; return TRUE;
} }
bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) bool wxListCtrl::GetItemPosition( long item, wxPoint& pos ) const
{ {
m_mainWin->GetItemPosition( item, pos ); m_mainWin->GetItemPosition( item, pos );
return TRUE; return TRUE;
@@ -2482,7 +2481,7 @@ bool wxListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(p
return 0; return 0;
} }
int wxListCtrl::GetItemCount(void) int wxListCtrl::GetItemCount(void) const
{ {
return m_mainWin->GetItemCount(); return m_mainWin->GetItemCount();
} }
@@ -2492,12 +2491,12 @@ void wxListCtrl::SetItemSpacing( int spacing, bool isSmall )
m_mainWin->SetItemSpacing( spacing, isSmall ); m_mainWin->SetItemSpacing( spacing, isSmall );
} }
int wxListCtrl::GetItemSpacing( bool isSmall ) int wxListCtrl::GetItemSpacing( bool isSmall ) const
{ {
return m_mainWin->GetItemSpacing( isSmall ); return m_mainWin->GetItemSpacing( isSmall );
} }
int wxListCtrl::GetSelectedItemCount(void) int wxListCtrl::GetSelectedItemCount(void) const
{ {
return m_mainWin->GetSelectedItemCount(); return m_mainWin->GetSelectedItemCount();
} }
@@ -2512,7 +2511,7 @@ void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
} }
*/ */
long wxListCtrl::GetTopItem(void) long wxListCtrl::GetTopItem(void) const
{ {
return 0; return 0;
} }
@@ -2522,7 +2521,7 @@ long wxListCtrl::GetNextItem( long item, int geom, int state ) const
return m_mainWin->GetNextItem( item, geom, state ); return m_mainWin->GetNextItem( item, geom, state );
} }
wxImageList *wxListCtrl::GetImageList(int which) wxImageList *wxListCtrl::GetImageList(int which) const
{ {
if (which == wxIMAGE_LIST_NORMAL) if (which == wxIMAGE_LIST_NORMAL)
{ {