]> git.saurik.com Git - wxWidgets.git/commitdiff
implemented support for column label alignment (closes 215870)
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 2 Jan 2003 21:29:21 +0000 (21:29 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 2 Jan 2003 21:29:21 +0000 (21:29 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18514 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
src/generic/listctrl.cpp

index 17d24adda770bf050dfda4443b166fc978c513e4..0219ad21acda902e1b6c9ab96c3571f20a5f9c0c 100644 (file)
@@ -34,6 +34,7 @@ All:
 - Improved contrib/utils/convertrc parsing (David J. Cooke)
 - Fixed handling of URLs and filenames in wxFileSystem
 - Implemented alignment for wxGrid bool editor and renderer
+- Support wxListCtrl columns alignment for all platforms and not just MSW
 
 OLD CHANGES
 ===========
index 85505af13fda94135d6079116236de0bb9067a5f..a3e4d598025fdaf20f10eb227379630255970718 100644 (file)
@@ -1774,17 +1774,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
     {
@@ -2005,28 +2018,67 @@ 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, iy;
+        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 +2086,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;
     }