]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/listctrl.cpp
Added BCC include dir in XRC makefile
[wxWidgets.git] / src / generic / listctrl.cpp
index 51f600fa5b09dd23d5ebade1aee250e1ff59acbd..bf85914d4cf7cf0f7ff639e4e2163a7b2f65b3bc 100644 (file)
@@ -495,7 +495,9 @@ private:
     // common part of all ctors
     void Init();
 
-    void SendListEvent(wxEventType type, wxPoint pos);
+    // generate and process the list event of the given type, return true if
+    // it wasn't vetoed, i.e. if we should proceed
+    bool SendListEvent(wxEventType type, wxPoint pos);
 
     DECLARE_DYNAMIC_CLASS(wxListHeaderWindow)
     DECLARE_EVENT_TABLE()
@@ -1774,17 +1776,30 @@ void wxListLineData::DrawTextFormatted(wxDC *dc,
 
     // determine if the string can fit inside the current width
     dc->GetTextExtent(text, &w, &h);
-
-    // if it can, draw it
     if (w <= width)
     {
+        // it can, draw it using the items alignment
         m_owner->GetColumn(col, item);
-        if (item.m_format == wxLIST_FORMAT_LEFT)
-            dc->DrawText(text, x, y);
-        else if (item.m_format == wxLIST_FORMAT_RIGHT)
-            dc->DrawText(text, x + width - w, y);
-        else if (item.m_format == wxLIST_FORMAT_CENTER)
-            dc->DrawText(text, x + ((width - w) / 2), y);
+        switch ( item.GetAlign() )
+        {
+            default:
+                wxFAIL_MSG( _T("unknown list item format") );
+                // fall through
+
+            case wxLIST_FORMAT_LEFT:
+                // nothing to do
+                break;
+
+            case wxLIST_FORMAT_RIGHT:
+                x += width - w;
+                break;
+
+            case wxLIST_FORMAT_CENTER:
+                x += (width - w) / 2;
+                break;
+        }
+
+        dc->DrawText(text, x, y);
     }
     else // otherwise, truncate and add an ellipsis if possible
     {
@@ -1793,13 +1808,17 @@ void wxListLineData::DrawTextFormatted(wxDC *dc,
         dc->GetTextExtent(ellipsis, &base_w, &h);
 
         // continue until we have enough space or only one character left
-        drawntext = text.Left(text.Length() - 1);
-        while (drawntext.Length() > 1)
+        wxCoord w_c, h_c;
+        size_t len = text.Length();
+        drawntext = text.Left(len);
+        while (len > 1)
         {
-            dc->GetTextExtent(drawntext, &w, &h);
+            dc->GetTextExtent(drawntext.Last(), &w_c, &h_c);
+            drawntext.RemoveLast();
+            len--;
+            w -= w_c;
             if (w + base_w <= width)
                 break;
-            drawntext = drawntext.Left(drawntext.Length() - 1);
         }
 
         // if still not enough space, remove ellipsis characters
@@ -2005,28 +2024,68 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
 
         DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 );
 
-        // if we have an image, draw it on the right of the label
-        int image = item.m_image;
+        // see if we have enough space for the column label
+
+        // for this we need the width of the text
+        wxCoord wLabel;
+        dc.GetTextExtent(item.GetText(), &wLabel, NULL);
+        wLabel += 2*EXTRA_WIDTH;
+
+        // and the width of the icon, if any
+        static const int MARGIN_BETWEEN_TEXT_AND_ICON = 2;
+        int ix = 0,     // init them just to suppress the compiler warnings
+            iy = 0;
+        const int image = item.m_image;
+        wxImageListType *imageList;
         if ( image != -1 )
         {
-            wxImageListType *imageList = m_owner->m_small_image_list;
+            imageList = m_owner->m_small_image_list;
             if ( imageList )
             {
-                int ix, iy;
                 imageList->GetSize(image, ix, iy);
+                wLabel += ix + MARGIN_BETWEEN_TEXT_AND_ICON;
+            }
+        }
+        else
+        {
+            imageList = NULL;
+        }
 
-                imageList->Draw
-                           (
-                            image,
-                            dc,
-                            x + cw - ix - 1,
-                            HEADER_OFFSET_Y + (h - 4 - iy)/2,
-                            wxIMAGELIST_DRAW_TRANSPARENT
-                           );
+        // ignore alignment if there is not enough space anyhow
+        int xAligned;
+        switch ( wLabel < cw ? item.GetAlign() : wxLIST_FORMAT_LEFT )
+        {
+            default:
+                wxFAIL_MSG( _T("unknown list item format") );
+                // fall through
 
-                cw -= ix + 2;
-            }
-            //else: ignore the column image
+            case wxLIST_FORMAT_LEFT:
+                xAligned = x;
+                break;
+
+            case wxLIST_FORMAT_RIGHT:
+                xAligned = x + cw - wLabel;
+                break;
+
+            case wxLIST_FORMAT_CENTER:
+                xAligned = x + (cw - wLabel) / 2;
+                break;
+        }
+
+
+        // if we have an image, draw it on the right of the label
+        if ( imageList )
+        {
+            imageList->Draw
+                       (
+                        image,
+                        dc,
+                        xAligned + wLabel - ix - MARGIN_BETWEEN_TEXT_AND_ICON,
+                        HEADER_OFFSET_Y + (h - 4 - iy)/2,
+                        wxIMAGELIST_DRAW_TRANSPARENT
+                       );
+
+            cw -= ix + MARGIN_BETWEEN_TEXT_AND_ICON;
         }
 
         // draw the text clipping it so that it doesn't overwrite the column
@@ -2034,7 +2093,7 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
         wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 );
 
         dc.DrawText( item.GetText(),
-                     x + EXTRA_WIDTH, HEADER_OFFSET_Y + EXTRA_HEIGHT );
+                     xAligned + EXTRA_WIDTH, HEADER_OFFSET_Y + EXTRA_HEIGHT );
 
         x += wCol;
     }
@@ -2077,8 +2136,7 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
 
     if (m_isDragging)
     {
-        SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING,
-                      event.GetPosition());
+        SendListEvent(wxEVT_COMMAND_LIST_COL_DRAGGING, event.GetPosition());
 
         // we don't draw the line beyond our window, but we allow dragging it
         // there
@@ -2097,8 +2155,7 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
             m_isDragging = FALSE;
             m_dirty = TRUE;
             m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
-            SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG,
-                          event.GetPosition());
+            SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG, event.GetPosition());
         }
         else
         {
@@ -2151,12 +2208,15 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
         {
             if (hit_border && event.LeftDown())
             {
-                m_isDragging = TRUE;
-                m_currentX = x;
-                DrawCurrent();
-                CaptureMouse();
-                SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
-                              event.GetPosition());
+                if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
+                                   event.GetPosition()) )
+                {
+                    m_isDragging = TRUE;
+                    m_currentX = x;
+                    DrawCurrent();
+                    CaptureMouse();
+                }
+                //else: column resizing was vetoed by the user code
             }
             else // click on a column
             {
@@ -2191,7 +2251,7 @@ void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
     m_owner->SetFocus();
 }
 
-void wxListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos)
+bool wxListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos)
 {
     wxWindow *parent = GetParent();
     wxListEvent le( type, parent->GetId() );
@@ -2205,7 +2265,7 @@ void wxListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos)
     le.m_pointDrag.y -= GetSize().y;
 
     le.m_col = m_column;
-    parent->GetEventHandler()->ProcessEvent( le );
+    return !parent->GetEventHandler()->ProcessEvent( le ) || le.IsAllowed();
 }
 
 //-----------------------------------------------------------------------------
@@ -2527,8 +2587,16 @@ wxCoord wxListMainWindow::GetLineHeight() const
 
         if ( y < SCROLL_UNIT_Y )
             y = SCROLL_UNIT_Y;
-        y += EXTRA_HEIGHT;
 
+        if ( m_small_image_list && m_small_image_list->GetImageCount() )
+        {
+            int iw = 0;
+            int ih = 0;
+            m_small_image_list->GetSize(0, iw, ih);
+            y = wxMax(y, ih);
+        }
+
+        y += EXTRA_HEIGHT;
         self->m_lineHeight = y + LINE_SPACING;
     }
 
@@ -3135,6 +3203,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
 
         wxListEvent le( command, GetParent()->GetId() );
         le.SetEventObject( GetParent() );
+        le.m_itemIndex = current;
         le.m_pointDrag = m_dragStart;
         GetParent()->GetEventHandler()->ProcessEvent( le );
 
@@ -3355,7 +3424,7 @@ void wxListMainWindow::OnChar( wxKeyEvent &event )
         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 = (int)event.KeyCode();
+        le.m_code = event.GetKeyCode();
         le.SetEventObject( parent );
         parent->GetEventHandler()->ProcessEvent( le );
     }
@@ -3372,7 +3441,7 @@ void wxListMainWindow::OnChar( wxKeyEvent &event )
     ke.SetEventObject( parent );
     if (parent->GetEventHandler()->ProcessEvent( ke )) return;
 
-    if (event.KeyCode() == WXK_TAB)
+    if (event.GetKeyCode() == WXK_TAB)
     {
         wxNavigationKeyEvent nevent;
         nevent.SetWindowChange( event.ControlDown() );
@@ -3390,7 +3459,7 @@ void wxListMainWindow::OnChar( wxKeyEvent &event )
         return;
     }
 
-    switch (event.KeyCode())
+    switch (event.GetKeyCode())
     {
         case WXK_UP:
             if ( m_current > 0 )
@@ -3633,6 +3702,7 @@ void wxListMainWindow::SetImageList( wxImageListType *imageList, int which )
     {
         m_small_image_list = imageList;
         m_small_spacing = width + 14;
+        m_lineHeight = 0;  // ensure that the line height will be recalc'd
     }
 }
 
@@ -3806,16 +3876,10 @@ void wxListMainWindow::SetItem( wxListItem &item )
         line->SetItem( item.m_col, item );
     }
 
-    if ( InReportView() )
-    {
-        // just refresh the line to show the new value of the text/image
-        RefreshLine((size_t)id);
-    }
-    else // !report
-    {
-        // refresh everything (resulting in horrible flicker - FIXME!)
-        m_dirty = TRUE;
-    }
+    // update the item on screen
+    wxRect rectItem;
+    GetItemRect(id, rectItem);
+    RefreshRect(rectItem);
 }
 
 void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
@@ -4654,7 +4718,7 @@ bool wxGenericListCtrl::Create(wxWindow *parent,
         return FALSE;
 
     // don't create the inner window with the border
-    style &= ~wxSUNKEN_BORDER;
+    style &= ~wxBORDER_MASK;
 
     m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style );
 
@@ -4850,6 +4914,8 @@ bool wxGenericListCtrl::SetItemData( long item, long data )
 bool wxGenericListCtrl::GetItemRect( long item, wxRect &rect,  int WXUNUSED(code) ) const
 {
     m_mainWin->GetItemRect( item, rect );
+    if ( m_mainWin->HasHeader() )
+        rect.y += HEADER_HEIGHT + 1;
     return TRUE;
 }