]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/listctrl.cpp
Changed BidEndianOrdered to BigEndianOrdered in datstrm.h
[wxWidgets.git] / src / generic / listctrl.cpp
index e319bca803cd03265c1201d6a77c8f7e8aa0bbe1..65f568eb3ba43c0b5570ef1a92ed962538f33ada 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "wx/dcscreen.h"
 #include "wx/app.h"
-#include "wx/generic/listctrl.h"
+#include "wx/listctrl.h"
 #include "wx/generic/imaglist.h"
 
 //-----------------------------------------------------------------------------
@@ -685,7 +685,7 @@ wxListHeaderWindow::wxListHeaderWindow( void )
     m_owner = (wxListMainWindow *) NULL;
     m_currentCursor = (wxCursor *) NULL;
     m_resizeCursor = (wxCursor *) NULL;
-    m_isDraging = FALSE;
+    m_isDragging = FALSE;
 }
 
 wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner,
@@ -697,7 +697,8 @@ wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMain
 //  m_currentCursor = wxSTANDARD_CURSOR;
     m_currentCursor = (wxCursor *) NULL;
     m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
-    m_isDraging = FALSE;
+    m_isDragging = FALSE;
+    SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) );
 }
 
 wxListHeaderWindow::~wxListHeaderWindow( void )
@@ -780,7 +781,7 @@ void wxListHeaderWindow::DrawCurrent()
     m_owner->ClientToScreen( &x2, &y2 );
 
     wxScreenDC dc;
-    dc.SetLogicalFunction( wxXOR );
+    dc.SetLogicalFunction( wxINVERT );
     dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) );
     dc.SetBrush( *wxTRANSPARENT_BRUSH );
 
@@ -796,13 +797,13 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
 {
     int x = event.GetX();
     int y = event.GetY();
-    if (m_isDraging)
+    if (m_isDragging)
     {
         DrawCurrent();
         if (event.ButtonUp())
         {
             ReleaseMouse();
-            m_isDraging = FALSE;
+            m_isDragging = FALSE;
             m_owner->SetColumnWidth( m_column, m_currentX-m_minX );
         }
         else
@@ -837,7 +838,7 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
 
     if (event.LeftDown() && hit_border)
     {
-        m_isDraging = TRUE;
+        m_isDragging = TRUE;
         m_currentX = x;
         DrawCurrent();
         CaptureMouse();
@@ -898,6 +899,9 @@ wxListTextCtrl::wxListTextCtrl( wxWindow *parent, const wxWindowID id,
     m_res = res;
     m_accept = accept;
     m_owner = owner;
+    (*m_accept) = FALSE;
+    (*m_res) = "";
+    m_startValue = value;
 }
 
 void wxListTextCtrl::OnChar( wxKeyEvent &event )
@@ -906,17 +910,14 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event )
     {
         (*m_accept) = TRUE;
         (*m_res) = GetValue();
-        m_owner->OnRenameAccept();
-//      Show( FALSE );
-        Destroy();
+       m_owner->SetFocus();
         return;
     }
     if (event.m_keyCode == WXK_ESCAPE)
     {
         (*m_accept) = FALSE;
         (*m_res) = "";
-//      Show( FALSE );
-        Destroy();
+       m_owner->SetFocus();
         return;
     }
     event.Skip();
@@ -924,11 +925,12 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event )
 
 void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
 {
-    (*m_accept) = FALSE;
-    (*m_res) = "";
-//  Show( FALSE );
-    Destroy();
-    return;
+    if (wxPendingDelete.Member(this)) return;
+
+    wxPendingDelete.Append(this);
+    
+    if ((*m_accept) && ((*m_res) != m_startValue))
+        m_owner->OnRenameAccept();
 }
 
 //-----------------------------------------------------------------------------
@@ -1139,31 +1141,31 @@ void wxListMainWindow::DeleteLine( wxListLineData *line )
     SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM );
 }
 
-void wxListMainWindow::StartLabelEdit( wxListLineData *line )
-{
-    SendNotify( line, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT );
-}
+/* *** */
 
-void wxListMainWindow::RenameLine( wxListLineData *line, const wxString &newName )
+void wxListMainWindow::EditLabel( long item )
 {
+    wxNode *node = m_lines.Nth( item );
+    wxCHECK_RET( node, _T("wrong index in wxListCtrl::Edit()") );
+    
+    m_currentEdit = (wxListLineData*) node->Data();
+
     wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
     le.SetEventObject( GetParent() );
-    le.m_itemIndex = GetIndexOfLine( line );
-    line->GetItem( 0, le.m_item );
-    le.m_item.m_text = newName;
+    le.m_itemIndex = GetIndexOfLine( m_currentEdit );
+    m_currentEdit->GetItem( 0, le.m_item );
     GetParent()->GetEventHandler()->ProcessEvent( le );
-}
-
-void wxListMainWindow::OnRenameTimer()
-{
-    StartLabelEdit( m_current );
+    
+    if (!le.IsAllowed())
+        return;
+    
     wxString s;
-    m_current->GetText( 0, s );
+    m_currentEdit->GetText( 0, s );
     int x = 0;
     int y = 0;
     int w = 0;
     int h = 0;
-    m_current->GetLabelExtent( x, y, w, h );
+    m_currentEdit->GetLabelExtent( x, y, w, h );
 
     wxClientDC dc(this);
     PrepareDC( dc );
@@ -1175,9 +1177,29 @@ void wxListMainWindow::OnRenameTimer()
     text->SetFocus();
 }
 
+void wxListMainWindow::OnRenameTimer()
+{
+    wxCHECK_RET( m_current, _T("invalid m_current") );
+    
+    Edit( m_lines.IndexOf( m_current ) );
+}
+
 void wxListMainWindow::OnRenameAccept()
 {
-    RenameLine( m_current, m_renameRes );
+    wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
+    le.SetEventObject( GetParent() );
+    le.m_itemIndex = GetIndexOfLine( m_currentEdit );
+    m_currentEdit->GetItem( 0, le.m_item );
+    le.m_item.m_text = m_renameRes;
+    GetParent()->GetEventHandler()->ProcessEvent( le );
+    
+    if (!le.IsAllowed()) return;
+    
+    wxListItem info;
+    info.m_mask = wxLIST_MASK_TEXT;
+    info.m_itemId = le.m_itemIndex;
+    info.m_text = m_renameRes;
+    SetItem( info );
 }
 
 void wxListMainWindow::OnMouse( wxMouseEvent &event )
@@ -1339,7 +1361,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
     }
 }
 
-void wxListMainWindow::MoveToFocus( void )
+void wxListMainWindow::MoveToFocus()
 {
     if (!m_current) return;
   
@@ -1423,6 +1445,14 @@ void wxListMainWindow::OnChar( wxKeyEvent &event )
     ke.SetEventObject( parent );
     if (parent->GetEventHandler()->ProcessEvent( ke )) return;
   
+    if (event.KeyCode() == WXK_TAB)
+    {
+        wxNavigationKeyEvent nevent;
+        nevent.SetDirection( !event.ShiftDown() );
+        nevent.SetCurrentFocus( m_parent );
+        if (m_parent->GetEventHandler()->ProcessEvent( nevent )) return;
+    }
+  
     /* no item -> nothing to do */
     if (!m_current)
     {
@@ -1686,7 +1716,44 @@ void wxListMainWindow::SetColumnWidth( int col, int width )
 
     m_dirty = TRUE;
 
-    wxNode *node = m_columns.Nth( col );
+    wxNode *node = (wxNode*) NULL;
+
+    if (width == wxLIST_AUTOSIZE_USEHEADER) width = 80;
+    if (width == wxLIST_AUTOSIZE)
+    {
+        wxClientDC dc(this);
+        dc.SetFont( GetFont() );
+        int max = 10;
+        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();
+               int current = 0, ix = 0, iy = 0;
+               long lx = 0, ly = 0;
+               if (item->HasImage())
+               {
+                    GetImageSize( item->GetImage(), ix, iy );
+                   current = ix + 5;
+               }
+               if (item->HasText())
+               {
+                   wxString str;
+                   item->GetText( str );
+                   dc.GetTextExtent( str, &lx, &ly );
+                   current += lx;
+               }
+               if (current > max) max = current;
+            }
+            node = node->Next();
+        }
+       width = max+10;
+    }
+
+    node = m_columns.Nth( col );
     if (node)
     {
         wxListHeaderData *column = (wxListHeaderData*)node->Data();
@@ -1742,12 +1809,12 @@ int wxListMainWindow::GetColumnWidth( int col )
     }
 }
 
-int wxListMainWindow::GetColumnCount( void )
+int wxListMainWindow::GetColumnCount()
 {
     return m_columns.Number();
 }
 
-int wxListMainWindow::GetCountPerPage( void )
+int wxListMainWindow::GetCountPerPage()
 {
     return m_visibleLines;
 }
@@ -1780,7 +1847,7 @@ void wxListMainWindow::SetItemState( long item, long state, long stateMask )
             m_current = line;
             FocusLine( m_current );
             RefreshLine( m_current );
-            RefreshLine( oldCurrent );
+            if (oldCurrent) RefreshLine( oldCurrent );
         }
     }
 
@@ -1798,9 +1865,9 @@ void wxListMainWindow::SetItemState( long item, long state, long stateMask )
                 UnfocusLine( m_current );
                 m_current = line;
                 FocusLine( m_current );
-                oldCurrent->Hilight( FALSE );
+                if (oldCurrent) oldCurrent->Hilight( FALSE );
                 RefreshLine( m_current );
-                RefreshLine( oldCurrent );
+                if (oldCurrent) RefreshLine( oldCurrent );
             }
             bool on = state & wxLIST_STATE_SELECTED;
            if (on != line->IsHilighted())
@@ -1853,7 +1920,7 @@ void wxListMainWindow::GetItem( wxListItem &item )
     }
 }
 
-int wxListMainWindow::GetItemCount( void )
+int wxListMainWindow::GetItemCount()
 {
     return m_lines.Number();
 }
@@ -1894,7 +1961,7 @@ bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos)
     return TRUE;
 }
 
-int wxListMainWindow::GetSelectedItemCount( void )
+int wxListMainWindow::GetSelectedItemCount()
 {
     int ret = 0;
     wxNode *node = m_lines.First();
@@ -1926,12 +1993,12 @@ void wxListMainWindow::SetMode( long mode )
     }
 }
 
-long wxListMainWindow::GetMode( void ) const
+long wxListMainWindow::GetMode() const
 {
     return m_mode;
 }
 
-void wxListMainWindow::CalculatePositions( void )
+void wxListMainWindow::CalculatePositions()
 {
     if (!m_lines.First()) return;
 
@@ -2344,7 +2411,9 @@ bool wxListCtrl::Create( wxWindow *parent, wxWindowID id,
 
     bool ret = wxControl::Create( parent, id, pos, size, s, name );
 
+#if wxUSE_VALIDATORS
     SetValidator( validator );
+#endif
   
     if (s & wxSUNKEN_BORDER) s -= wxSUNKEN_BORDER;
 
@@ -2457,12 +2526,6 @@ int wxListCtrl::GetCountPerPage(void) const
   return m_mainWin->GetCountPerPage();  // different from Windows ?
 }
 
-/*
-wxText& wxListCtrl::GetEditControl(void) const
-{
-}
-*/
-
 bool wxListCtrl::GetItem( wxListItem &info ) const
 {
     m_mainWin->GetItem( info );
@@ -2667,11 +2730,10 @@ bool wxListCtrl::DeleteColumn( int col )
     return TRUE;
 }
 
-/*
-wxText& wxListCtrl::Edit( long WXUNUSED(item ) )
+void wxListCtrl::Edit( long item )
 {
+    m_mainWin->Edit( item );
 }
-*/
 
 bool wxListCtrl::EnsureVisible( long item )
 {
@@ -2829,7 +2891,7 @@ bool wxListCtrl::SetBackgroundColour( const wxColour &colour )
     
     if (m_headerWin)
     {
-        m_headerWin->SetBackgroundColour( colour );
+//        m_headerWin->SetBackgroundColour( colour );
     }
 
     return TRUE;