// Name: listctrl.cpp
// Purpose:
// Author: Robert Roebling
-// Created: 01/02/97
-// Id:
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#pragma implementation "listctrl.h"
#endif
+#include "wx/dcscreen.h"
+#include "wx/app.h"
#include "wx/listctrl.h"
//-----------------------------------------------------------------------------
void wxListItemData::SetSize( int const width, int height )
{
- m_width = width;
- m_height = height;
+ if (width != -1) m_width = width;
+ if (height != -1) m_height = height;
}
void wxListItemData::SetColour( wxColour *col )
wxNode *node = m_items.First();
while (node)
{
- wxListItemData *info = (wxListItemData*)node->Data();
- dc->SetClippingRegion( info->GetX(), info->GetY(), info->GetWidth(), info->GetHeight() );
- info->GetText( s );
+ wxListItemData *item = (wxListItemData*)node->Data();
+ dc->SetClippingRegion( item->GetX(), item->GetY(), item->GetWidth()-3, item->GetHeight() );
+ int x = item->GetX();
+ if (item->HasImage())
+ {
+ int y = 0;
+ m_owner->DrawImage( item->GetImage(), dc, x, item->GetY() );
+ m_owner->GetImageSize( item->GetImage(), x, y );
+ x += item->GetX() + 5;
+ }
+ if (item->HasText())
+ {
+ item->GetText( s );
if (hilight)
dc->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
else
- dc->SetTextForeground( info->GetColour() );
- dc->DrawText( s, info->GetX()+2, info->GetY() );
+ dc->SetTextForeground( *item->GetColour() );
+ dc->DrawText( s, x, item->GetY() );
+ }
dc->DestroyClippingRegion();
node = node->Next();
}
if (hilight)
dc->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
else
- dc->SetTextForeground( item->GetColour() );
+ dc->SetTextForeground( * item->GetColour() );
dc->DrawText( s, m_bound_label.x, m_bound_label.y );
}
}
m_owner = (wxListMainWindow *) NULL;
m_currentCursor = (wxCursor *) NULL;
m_resizeCursor = (wxCursor *) NULL;
+ m_isDraging = FALSE;
}
wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner,
// m_currentCursor = wxSTANDARD_CURSOR;
m_currentCursor = (wxCursor *) NULL;
m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
+ m_isDraging = FALSE;
}
void wxListHeaderWindow::DoDrawRect( wxPaintDC *dc, int x, int y, int w, int h )
dc.BeginDrawing();
- dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) );
+ dc.SetFont( *GetFont() );
int w = 0;
int h = 0;
GetClientSize( &w, &h );
dc.SetTextForeground( *wxBLACK );
+ if (m_foregroundColour.Ok()) dc.SetTextForeground( m_foregroundColour );
x = 1;
y = 1;
dc.EndDrawing();
}
+void wxListHeaderWindow::DrawCurrent()
+{
+ int x1 = m_currentX;
+ int y1 = 0;
+ int x2 = m_currentX-1;
+ int y2 = 0;
+ m_owner->GetClientSize( (int*)NULL, &y2 );
+ ClientToScreen( &x1, &y1 );
+ m_owner->ClientToScreen( &x2, &y2 );
+
+ wxScreenDC dc;
+ dc.SetLogicalFunction( wxXOR );
+ dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) );
+ dc.SetBrush( *wxTRANSPARENT_BRUSH );
+
+ dc.DrawLine( x1, y1, x2, y2 );
+
+ dc.SetLogicalFunction( wxCOPY );
+
+ dc.SetPen( wxNullPen );
+ dc.SetBrush( wxNullBrush );
+}
+
void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
{
- float fx = 0;
- float fy = 0;
- event.Position( &fx, &fy );
- int x = (int)fx;
- int y = (int)fy;
- if (event.Moving())
+ int x = event.GetX();
+ int y = event.GetY();
+ if (m_isDraging)
{
- bool hit = FALSE;
- int xpos = 0;
- for (int j = 0; j < m_owner->GetColumnCount(); j++)
+ DrawCurrent();
+ if (event.ButtonUp())
{
- xpos += m_owner->GetColumnWidth( j );
- if ((abs(x-xpos) < 2) && (y < 14)) { hit = TRUE; break; }
+// wxScreenDC::EndDrawingOnTop();
+ ReleaseMouse();
+ m_isDraging = FALSE;
+ m_owner->SetColumnWidth( m_column, m_currentX-m_minX );
}
- if (hit)
+ else
+ {
+ int size_x = 0;
+ GetClientSize( &size_x, (int*) NULL );
+ if (x > m_minX+7)
+ m_currentX = x;
+ else
+ m_currentX = m_minX+7;
+ if (m_currentX > size_x-7) m_currentX = size_x-7;
+ DrawCurrent();
+ }
+ return;
+ }
+
+ m_minX = 0;
+ bool hit_border = FALSE;
+ int xpos = 0;
+ for (int j = 0; j < m_owner->GetColumnCount(); j++)
+ {
+ xpos += m_owner->GetColumnWidth( j );
+ if ((abs(x-xpos) < 3) && (y < 22))
+ {
+ hit_border = TRUE;
+ m_column = j;
+ break;
+ }
+ m_minX = xpos;
+ }
+
+ if (event.LeftDown() && hit_border)
+ {
+ m_isDraging = TRUE;
+ m_currentX = x;
+// wxScreenDC::StartDrawingOnTop( m_owner );
+ DrawCurrent();
+ CaptureMouse();
+ return;
+ }
+
+ if (event.Moving())
+ {
+ if (hit_border)
{
if (m_currentCursor == wxSTANDARD_CURSOR) SetCursor( m_resizeCursor );
m_currentCursor = m_resizeCursor;
m_current = (wxListLineData *) NULL;
m_visibleLines = 0;
m_hilightBrush = (wxBrush *) NULL;
- m_myFont = (wxFont *) NULL;
m_xScroll = 0;
m_yScroll = 0;
m_dirty = TRUE;
m_small_spacing = 30;
m_normal_spacing = 40;
// AllowDoubleClick( TRUE );
- m_myFont = wxNORMAL_FONT;
m_hasFocus = FALSE;
m_dragCount = 0;
m_isCreated = FALSE;
wxListMainWindow::~wxListMainWindow( void )
{
-// if (m_hilightColour) delete m_hilightColour;
-// if (m_hilightBrush) delete m_hilightBrush;
-// if (m_myFont) delete m_myFont;
+ if (m_hilightBrush) delete m_hilightBrush;
delete m_renameTimer;
+// if (m_hilightColour) delete m_hilightColour;
// delete m_text;
}
dc.BeginDrawing();
-// dc.SetFont( *m_myFont );
- dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) );
+ dc.SetFont( *GetFont() );
wxNode *node = m_lines.First();
while (node)
void wxListMainWindow::ActivateLine( wxListLineData *line )
{
- if (!m_parent) return;
- wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, m_parent->GetId() );
- le.SetEventObject( m_parent );
+ if (!GetParent()) return;
+ wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
+ le.SetEventObject( GetParent() );
le.m_code = 0;
le.m_itemIndex = GetIndexOfLine( line );
le.m_col = 0;
void wxListMainWindow::SendNotify( wxListLineData *line, wxEventType command )
{
- if (!m_parent) return;
- wxListEvent le( command, m_parent->GetId() );
- le.SetEventObject( m_parent );
+ if (!GetParent()) return;
+ wxListEvent le( command, GetParent()->GetId() );
+ le.SetEventObject( GetParent() );
le.m_code = 0;
le.m_itemIndex = GetIndexOfLine( line );
le.m_col = 0;
void wxListMainWindow::RenameLine( wxListLineData *line, const wxString &newName )
{
- if (!m_parent) return;
+ if (!GetParent()) return;
- wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, m_parent->GetId() );
- le.SetEventObject( m_parent );
+ wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
+ le.SetEventObject( GetParent() );
le.m_code = 0;
le.m_itemIndex = GetIndexOfLine( line );
le.m_col = 0;
void wxListMainWindow::OnMouse( wxMouseEvent &event )
{
- if (m_parent->ProcessEvent( event)) return;
+ if (GetParent()->GetEventHandler()->ProcessEvent( event)) return;
if (!m_current) return;
if (m_dirty) return;
if (event.Dragging() && (m_dragCount > 3))
{
m_dragCount = 0;
- wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_DRAG, m_parent->GetId() );
+ wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_DRAG, GetParent()->GetId() );
le.SetEventObject( this );
le.m_code = 0;
le.m_itemIndex = 0;
m_hasFocus = TRUE;
RefreshLine( m_current );
- if (!m_parent) return;
+ if (!GetParent()) return;
- wxFocusEvent event( wxEVT_SET_FOCUS, m_parent->GetId() );
- event.SetEventObject( m_parent );
- m_parent->ProcessEvent( event );
+ wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
+ event.SetEventObject( GetParent() );
+ GetParent()->GetEventHandler()->ProcessEvent( event );
}
void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
*/
}
-wxFont *wxListMainWindow::GetMyFont( void )
-{
- return m_myFont;
-}
-
void wxListMainWindow::DrawImage( int index, wxPaintDC *dc, int x, int y )
{
if ((m_mode & wxLC_ICON) && (m_normal_image_list))
{
m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
}
+ if ((m_mode & wxLC_REPORT) && (m_small_image_list))
+ {
+ m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
+ return;
+ }
}
void wxListMainWindow::GetImageSize( int index, int &width, int &height )
m_small_image_list->GetSize( index, width, height );
return;
}
+ if ((m_mode & wxLC_REPORT) && (m_small_image_list))
+ {
+ m_small_image_list->GetSize( index, width, height );
+ return;
+ }
width = 0;
height = 0;
}
wxListHeaderData *column = (wxListHeaderData*)node->Data();
column->SetItem( item );
}
+ wxListCtrl *lc = (wxListCtrl*) GetParent();
+ if (lc->m_headerWin) lc->m_headerWin->Refresh();
}
void wxListMainWindow::SetColumnWidth( int col, int width )
{
+ if (!(m_mode & wxLC_REPORT)) return;
+
m_dirty = TRUE;
+
wxNode *node = m_columns.Nth( col );
if (node)
{
wxListHeaderData *column = (wxListHeaderData*)node->Data();
column->SetWidth( width );
}
+
+ node = m_lines.First();
+ while (node)
+ {
+ wxListLineData *line = (wxListLineData*)node->Data();
+ wxNode *n = line->m_items.Nth( col );
+ if (n)
+ {
+ wxListItemData *item = (wxListItemData*)n->Data();
+ item->SetSize( width, -1 );
+ }
+ node = node->Next();
+ }
+
+ wxListCtrl *lc = (wxListCtrl*) GetParent();
+ if (lc->m_headerWin) lc->m_headerWin->Refresh();
}
void wxListMainWindow::GetColumn( int col, wxListItem &item )
if (line->IsHilighted()) ret++;
node = node->Next();
}
- return 0;
+ return ret;
}
void wxListMainWindow::SetMode( long mode )
void wxListMainWindow::CalculatePositions( void )
{
wxPaintDC dc( this );
- dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT ) );
+ dc.SetFont( *GetFont() );
int iconSpacing = 0;
if (m_mode & wxLC_ICON) iconSpacing = m_normal_spacing;
bool wxListMainWindow::OnListNotify( wxListEvent &event )
{
- if (m_parent) m_parent->ProcessEvent( event );
+ if (GetParent()) GetParent()->GetEventHandler()->ProcessEvent( event );
return FALSE;
}
m_imageListState = (wxImageList *) NULL;
}
-wxListCtrl::wxListCtrl( wxWindow *parent, wxWindowID id,
- const wxPoint &pos, const wxSize &size,
- long style, const wxString &name )
-
-{
- Create( parent, id, pos, size, style, name );
-}
-
wxListCtrl::~wxListCtrl(void)
{
}
bool wxListCtrl::Create( wxWindow *parent, wxWindowID id,
const wxPoint &pos, const wxSize &size,
- long style, const wxString &name )
+ long style, const wxValidator &validator,
+ const wxString &name )
{
m_imageListNormal = (wxImageList *) NULL;
m_imageListSmall = (wxImageList *) NULL;
bool ret = wxControl::Create( parent, id, pos, size, s, name );
+ SetValidator( validator );
+
m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, s );
if (GetWindowStyleFlag() & wxLC_REPORT)
m_mainWin->Refresh();
}
+void wxListCtrl::SetBackgroundColour( const wxColour &colour )
+{
+ m_mainWin->SetBackgroundColour( colour );
+ m_headerWin->SetBackgroundColour( colour );
+ m_mainWin->m_dirty = TRUE;
+}
+
+void wxListCtrl::SetForegroundColour( const wxColour &colour )
+{
+ m_mainWin->SetForegroundColour( colour );
+ m_headerWin->SetForegroundColour( colour );
+ m_mainWin->m_dirty = TRUE;
+}
+
+void wxListCtrl::SetFont( const wxFont &font )
+{
+ m_mainWin->SetFont( font );
+ m_headerWin->SetFont( font );
+ m_mainWin->m_dirty = TRUE;
+}