]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/listbox.cpp
applied the workaround for XUnionRectWithRegion() returning ampty result if the rect...
[wxWidgets.git] / src / os2 / listbox.cpp
index f99ec829ec8f1908f5d3fc98a43a3b01fc258694..9f9f1de5d28afada32461669d3806eed61b5c756 100644 (file)
@@ -143,15 +143,6 @@ bool wxListBox::Create(
     //
     lStyle |= LS_NOADJUSTPOS;
 
-    //
-    // If the parent is a scrolled window the controls must
-    // have this style or they will overlap the scrollbars
-    //
-    if (pParent)
-        if (pParent->IsKindOf(CLASSINFO(wxScrolledWindow)) ||
-            pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow)))
-            lStyle |= WS_CLIPSIBLINGS;
-
     m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent) // Parent
                                        ,WC_LISTBOX          // Default Listbox class
                                        ,"LISTBOX"           // Control's name
@@ -179,7 +170,12 @@ bool wxListBox::Create(
     {
         Append(asChoices[lUi]);
     }
-    SetFont(*wxSMALL_FONT);
+    wxFont*                          pTextFont = new wxFont( 10
+                                                            ,wxMODERN
+                                                            ,wxNORMAL
+                                                            ,wxNORMAL
+                                                           );
+    SetFont(*pTextFont);
 
     //
     // Set standard wxWindows colors for Listbox items and highlighting
@@ -208,6 +204,7 @@ bool wxListBox::Create(
             ,nWidth
             ,nHeight
            );
+    delete pTextFont;
     return TRUE;
 } // end of wxListBox::Create
 
@@ -282,9 +279,12 @@ int wxListBox::DoAppend(
     if (m_windowStyle & wxLB_OWNERDRAW)
     {
         wxOwnerDrawn*               pNewItem = CreateItem(nIndex); // dummy argument
+        wxScreenDC                  vDc;
+        wxCoord                     vHeight;
+
 
         pNewItem->SetName(rsItem);
-        m_aItems.Add(pNewItem);
+        m_aItems.Insert(pNewItem, nIndex);
         ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, (MPARAM)((SHORT)nIndex), MPFROMP(pNewItem));
         pNewItem->SetFont(GetFont());
     }
@@ -334,24 +334,18 @@ void wxListBox::DoSetItems(
         //
         // First delete old items
         //
-        size_t                      lUi = m_aItems.Count();
-
-        while (lUi-- != 0)
-        {
-            delete m_aItems[lUi];
-        }
-        m_aItems.Empty();
+        WX_CLEAR_ARRAY(m_aItems);
 
         //
         // Then create new ones
         //
-        for (lUi = 0; lUi < (size_t)m_nNumItems; lUi++)
+        for (size_t ui = 0; ui < (size_t)m_nNumItems; ui++)
         {
-            wxOwnerDrawn*           pNewItem = CreateItem(lUi);
+            wxOwnerDrawn*           pNewItem = CreateItem(ui);
 
-            pNewItem->SetName(raChoices[lUi]);
+            pNewItem->SetName(raChoices[ui]);
             m_aItems.Add(pNewItem);
-            ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(lUi), MPFROMP(pNewItem));
+            ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(ui), MPFROMP(pNewItem));
         }
     }
 #endif // wxUSE_OWNER_DRAWN
@@ -419,6 +413,8 @@ void wxListBox::SetSelection(
                  ,MPFROMLONG(N)
                  ,(MPARAM)bSelect
                 );
+    if(m_windowStyle & wxLB_OWNERDRAW)
+        Refresh();
 } // end of wxListBox::SetSelection
 
 bool wxListBox::IsSelected(
@@ -430,8 +426,18 @@ bool wxListBox::IsSelected(
 
     LONG                            lItem;
 
-    lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)N, (MPARAM)0));
-    return (lItem != LIT_NONE);
+    if (GetWindowStyleFlag() & wxLB_EXTENDED)
+    {
+        if (N == 0)
+            lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0));
+        else
+            lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)(N - 1), (MPARAM)0));
+    }
+    else
+    {
+        lItem = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION, (MPARAM)LIT_FIRST, (MPARAM)0));
+    }
+    return (lItem == (LONG)N && lItem != LIT_NONE);
 } // end of wxListBox::IsSelected
 
 wxClientData* wxListBox::DoGetItemClientObject(
@@ -599,8 +605,25 @@ void wxListBox::DoInsertItems(
     int                             nItems = asItems.GetCount();
 
     for (int i = 0; i < nItems; i++)
-        ::WinSendMsg(GetHwnd(), LM_INSERTITEM, MPFROMLONG((LONG)(i + nPos)), (MPARAM)asItems[i].c_str());
-    m_nNumItems += nItems;
+    {
+        int                         nIndex = (int)::WinSendMsg( GetHwnd()
+                                                               ,LM_INSERTITEM
+                                                               ,MPFROMLONG((LONG)(i + nPos))
+                                                               ,(MPARAM)asItems[i].c_str()
+                                                              );
+
+        wxOwnerDrawn*               pNewItem = CreateItem(nIndex);
+
+        pNewItem->SetName(asItems[i]);
+        pNewItem->SetFont(GetFont());
+        m_aItems.Insert(pNewItem, nIndex);
+        ::WinSendMsg( GetHwnd()
+                     ,LM_SETITEMHANDLE
+                     ,(MPARAM)((SHORT)nIndex)
+                     ,MPFROMP(pNewItem)
+                    );
+        m_nNumItems += nItems;
+    }
 } // end of wxListBox::DoInsertItems
 
 void wxListBox::SetString(
@@ -789,21 +812,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());
+
+    wxCoord                         vHeight;
+    wxCoord                         vWidth;
 
-bool wxListBox::OS2OnDraw(WXDRAWITEMSTRUCT *item)
+    GetSize( &vWidth
+            ,NULL
+           );
+
+    pMeasureStruct->rclItem.xRight = (USHORT)vWidth;
+    pMeasureStruct->rclItem.xLeft  = 0;
+    pMeasureStruct->rclItem.yTop   = 0;
+    pMeasureStruct->rclItem.yBottom = 0;
+
+    vHeight = 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