]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/listbox.cpp
We need to update the scrollbar even if it's not shown, otherwise it can get stuck...
[wxWidgets.git] / src / os2 / listbox.cpp
index 968cd9a851b95f46d1e77b2775c8611b602df2a8..8e785dc5d9632401b08a2b2a38e670148caa827d 100644 (file)
@@ -21,6 +21,7 @@
 #include "wx/brush.h"
 #include "wx/font.h"
 #include "wx/dc.h"
+#include "wx/dcscreen.h"
 #include "wx/utils.h"
 #include "wx/scrolwin.h"
 #endif
@@ -55,7 +56,7 @@ wxListBoxItem::wxListBoxItem(
   const wxString& rsStr
 )
 : wxOwnerDrawn( rsStr
-               ,FALSE
+               ,false
               )
 {
     //
@@ -84,6 +85,23 @@ wxListBox::wxListBox()
     m_nSelected = 0;
 } // end of wxListBox::wxListBox
 
+bool wxListBox::Create(
+  wxWindow*                         pParent
+, wxWindowID                        vId
+, const wxPoint&                    rPos
+, const wxSize&                     rSize
+, const wxArrayString&              asChoices
+, long                              lStyle
+, const wxValidator&                rValidator
+, const wxString&                   rsName
+)
+{
+    wxCArrayString chs(asChoices);
+
+    return Create(pParent, vId, rPos, rSize, chs.GetCount(), chs.GetStrings(),
+                  lStyle, rValidator, rsName);
+}
+
 bool wxListBox::Create(
   wxWindow*                         pParent
 , wxWindowID                        vId
@@ -92,9 +110,7 @@ bool wxListBox::Create(
 , int                               n
 , const wxString                    asChoices[]
 , long                              lStyle
-#if wxUSE_VALIDATORS
 , const wxValidator&                rValidator
-#endif
 , const wxString&                   rsName
 )
 {
@@ -112,7 +128,7 @@ bool wxListBox::Create(
 
     wxSystemSettings                vSettings;
 
-    SetBackgroundColour(vSettings.GetSystemColour(wxSYS_COLOUR_WINDOW));
+    SetBackgroundColour(vSettings.GetColour(wxSYS_COLOUR_WINDOW));
     SetForegroundColour(pParent->GetForegroundColour());
 
     m_windowId = (vId == -1) ? (int)NewControlId() : vId;
@@ -156,7 +172,7 @@ bool wxListBox::Create(
                                       );
     if (m_hWnd == 0)
     {
-        return FALSE;
+        return false;
     }
 
     //
@@ -178,7 +194,7 @@ bool wxListBox::Create(
     SetFont(*pTextFont);
 
     //
-    // Set standard wxWindows colors for Listbox items and highlighting
+    // Set standard wxWidgets colors for Listbox items and highlighting
     //
     wxColour                        vColour;
 
@@ -205,7 +221,7 @@ bool wxListBox::Create(
             ,nHeight
            );
     delete pTextFont;
-    return TRUE;
+    return true;
 } // end of wxListBox::Create
 
 wxListBox::~wxListBox()
@@ -265,28 +281,30 @@ int wxListBox::DoAppend(
   const wxString&                   rsItem
 )
 {
-    int                             nIndex = 0;
-    SHORT                           nIndexType = 0;
+    long                            lIndex = 0;
+    LONG                            lIndexType = 0;
 
     if (m_windowStyle & wxLB_SORT)
-        nIndexType = LIT_SORTASCENDING;
+        lIndexType = LIT_SORTASCENDING;
     else
-        nIndexType = LIT_END;
-    nIndex = (int)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)nIndexType, (MPARAM)rsItem.c_str());
+        lIndexType = LIT_END;
+    lIndex = (long)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)rsItem.c_str());
     m_nNumItems++;
 
 #if wxUSE_OWNER_DRAWN
     if (m_windowStyle & wxLB_OWNERDRAW)
     {
-        wxOwnerDrawn*               pNewItem = CreateItem(nIndex); // dummy argument
+        wxOwnerDrawn*               pNewItem = CreateItem(lIndex); // dummy argument
+        wxScreenDC                  vDc;
+
 
         pNewItem->SetName(rsItem);
-        m_aItems.Insert(pNewItem, nIndex);
-        ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, (MPARAM)((SHORT)nIndex), MPFROMP(pNewItem));
+        m_aItems.Insert(pNewItem, lIndex);
+        ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, (MPARAM)lIndex, MPFROMP(pNewItem));
         pNewItem->SetFont(GetFont());
     }
 #endif
-    return nIndex;
+    return (int)lIndex;
 } // end of wxListBox::DoAppend
 
 void wxListBox::DoSetItems(
@@ -295,9 +313,8 @@ void wxListBox::DoSetItems(
 )
 {
     BOOL                            bHideAndShow = IsShown();
-    int                             nCount = 0;
     int                             i;
-    SHORT                           nIndexType = 0;
+    LONG                            lIndexType = 0;
 
     if (bHideAndShow)
     {
@@ -309,10 +326,10 @@ void wxListBox::DoSetItems(
     {
 
         if (m_windowStyle & wxLB_SORT)
-            nIndexType = LIT_SORTASCENDING;
+            lIndexType = LIT_SORTASCENDING;
         else
-            nIndexType = LIT_END;
-        ::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)nIndexType, (MPARAM)raChoices[i].c_str());
+            lIndexType = LIT_END;
+        ::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)raChoices[i].c_str());
 
         if (ppClientData)
         {
@@ -410,13 +427,15 @@ void wxListBox::SetSelection(
                  ,MPFROMLONG(N)
                  ,(MPARAM)bSelect
                 );
+    if(m_windowStyle & wxLB_OWNERDRAW)
+        Refresh();
 } // end of wxListBox::SetSelection
 
 bool wxListBox::IsSelected(
   int                               N
 ) const
 {
-    wxCHECK_MSG( N >= 0 && N < m_nNumItems, FALSE,
+    wxCHECK_MSG( N >= 0 && N < m_nNumItems, false,
                  wxT("invalid index in wxListBox::Selected") );
 
     LONG                            lItem;
@@ -614,7 +633,7 @@ void wxListBox::DoInsertItems(
         m_aItems.Insert(pNewItem, nIndex);
         ::WinSendMsg( GetHwnd()
                      ,LM_SETITEMHANDLE
-                     ,(MPARAM)((SHORT)nIndex)
+                     ,(MPARAM)((LONG)nIndex)
                      ,MPFROMP(pNewItem)
                     );
         m_nNumItems += nItems;
@@ -766,7 +785,7 @@ bool wxListBox::OS2Command(
         //
         // Some event we're not interested in
         //
-        return FALSE;
+        return false;
     }
     wxCommandEvent                  vEvent( eEvtType
                                            ,m_windowId
@@ -791,7 +810,7 @@ bool wxListBox::OS2Command(
     {
         n = -1;
     }
-    vEvent.m_commandInt = n;
+    vEvent.SetInt(n);
     return GetEventHandler()->ProcessEvent(vEvent);
 } // end of wxListBox::OS2Command
 
@@ -807,21 +826,152 @@ bool wxListBox::OS2Command(
 //
 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE    (1)
 
-bool wxListBox::OS2OnMeasure(WXMEASUREITEMSTRUCT *item)
+long wxListBox::OS2OnMeasure(
+  WXMEASUREITEMSTRUCT*              pItem
+)
 {
+    if (!pItem)
+        pItem = (WXMEASUREITEMSTRUCT*)new OWNERITEM;
+
+    POWNERITEM                      pMeasureStruct = (POWNERITEM)pItem;
+    wxScreenDC                      vDc;
+
     //
-    // TODO: Get to this eventually
+    // Only owner-drawn control should receive this message
     //
-    return TRUE;
-}
+    wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
+
+    vDc.SetFont(GetFont());
 
-bool wxListBox::OS2OnDraw(WXDRAWITEMSTRUCT *item)
+    wxCoord                         vHeight;
+    wxCoord                         vWidth;
+
+    GetSize( &vWidth
+            ,NULL
+           );
+
+    pMeasureStruct->rclItem.xRight = (USHORT)vWidth;
+    pMeasureStruct->rclItem.xLeft  = 0;
+    pMeasureStruct->rclItem.yTop   = 0;
+    pMeasureStruct->rclItem.yBottom = 0;
+
+    vHeight = (wxCoord)(vDc.GetCharHeight() * 2.5);
+    pMeasureStruct->rclItem.yTop  = (USHORT)vHeight;
+
+    return long(MRFROM2SHORT((USHORT)vHeight, (USHORT)vWidth));
+} // end of wxListBox::OS2OnMeasure
+
+bool wxListBox::OS2OnDraw (
+  WXDRAWITEMSTRUCT*                 pItem
+)
 {
+    POWNERITEM                      pDrawStruct = (POWNERITEM)pItem;
+    LONG                            lItemID = pDrawStruct->idItem;
+    int                             eAction = 0;
+    int                             eStatus = 0;
+
     //
-    // TODO: Get to this eventually
+    // Only owner-drawn control should receive this message
     //
-    return FALSE;
-}
+    wxCHECK(((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false);
+
+
+    //
+    // The item may be -1 for an empty listbox
+    //
+    if (lItemID == -1L)
+        return false;
+
+    wxListBoxItem*                   pData = (wxListBoxItem*)PVOIDFROMMR( ::WinSendMsg( GetHwnd()
+                                                                                       ,LM_QUERYITEMHANDLE
+                                                                                       ,MPFROMLONG(pDrawStruct->idItem)
+                                                                                       ,(MPARAM)0
+                                                                                      )
+                                                                        );
+
+    wxCHECK(pData, false );
+
+    wxDC                              vDc;
+    wxRect                            vRect( wxPoint( pDrawStruct->rclItem.xLeft
+                                                     ,pDrawStruct->rclItem.yTop
+                                                    )
+                                            ,wxPoint( pDrawStruct->rclItem.xRight
+                                                     ,pDrawStruct->rclItem.yBottom
+                                                    )
+                                           );
+
+    vDc.SetHPS(pDrawStruct->hps);
+
+    if (pDrawStruct->fsAttribute == pDrawStruct->fsAttributeOld)
+    {
+        //
+        // Entire Item needs to be redrawn (either it has reappeared from
+        // behind another window or is being displayed for the first time
+        //
+        eAction = wxOwnerDrawn::wxODDrawAll;
+
+        if (pDrawStruct->fsAttribute & MIA_HILITED)
+        {
+            //
+            // If it is currently selected we let the system handle it
+            //
+            eStatus |= wxOwnerDrawn::wxODSelected;
+        }
+        if (pDrawStruct->fsAttribute & MIA_CHECKED)
+        {
+            //
+            // If it is currently checked we draw our own
+            //
+            eStatus |= wxOwnerDrawn::wxODChecked;
+            pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_CHECKED;
+        }
+        if (pDrawStruct->fsAttribute & MIA_DISABLED)
+        {
+            //
+            // If it is currently disabled we let the system handle it
+            //
+            eStatus |= wxOwnerDrawn::wxODDisabled;
+        }
+        //
+        // Don't really care about framed (indicationg focus) or NoDismiss
+        //
+    }
+    else
+    {
+        if (pDrawStruct->fsAttribute & MIA_HILITED)
+        {
+            eAction = wxOwnerDrawn::wxODDrawAll;
+            eStatus |= wxOwnerDrawn::wxODSelected;
+            //
+            // Keep the system from trying to highlight with its bogus colors
+            //
+            pDrawStruct->fsAttributeOld = pDrawStruct->fsAttribute &= ~MIA_HILITED;
+        }
+        else if (!(pDrawStruct->fsAttribute & MIA_HILITED))
+        {
+            eAction = wxOwnerDrawn::wxODDrawAll;
+            eStatus = 0;
+            //
+            // Keep the system from trying to highlight with its bogus colors
+            //
+            pDrawStruct->fsAttribute = pDrawStruct->fsAttributeOld &= ~MIA_HILITED;
+        }
+        else
+        {
+            //
+            // For now we don't care about anything else
+            // just ignore the entire message!
+            //
+            return true;
+        }
+    }
+    return pData->OnDrawItem( vDc
+                             ,vRect
+                             ,(wxOwnerDrawn::wxODAction)eAction
+                             ,(wxOwnerDrawn::wxODStatus)eStatus
+                            );
+} // end of wxListBox::OS2OnDraw
+
 #endif // ndef for wxUSE_OWNER_DRAWN
 
 #endif // ndef for wxUSE_LISTBOX