]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/listbox.cpp
atsu for textctrl
[wxWidgets.git] / src / os2 / listbox.cpp
index 4a057dea63afee9ad72f9085dcc9e98e296e54ac..e8a6013682dd3f934cf3bab537ba174cff409663 100644 (file)
 
 #if wxUSE_LISTBOX
 
 
 #if wxUSE_LISTBOX
 
-#include "wx/window.h"
-#include "wx/os2/private.h"
+#include "wx/listbox.h"
 
 #ifndef WX_PRECOMP
 
 #ifndef WX_PRECOMP
-#include "wx/listbox.h"
-#include "wx/settings.h"
-#include "wx/brush.h"
-#include "wx/font.h"
-#include "wx/dc.h"
-#include "wx/dcscreen.h"
-#include "wx/utils.h"
-#include "wx/scrolwin.h"
+    #include "wx/dynarray.h"
+    #include "wx/settings.h"
+    #include "wx/brush.h"
+    #include "wx/font.h"
+    #include "wx/dc.h"
+    #include "wx/dcscreen.h"
+    #include "wx/utils.h"
+    #include "wx/scrolwin.h"
+    #include "wx/log.h"
+    #include "wx/window.h"
 #endif
 
 #endif
 
+#include "wx/os2/private.h"
+
 #define INCL_M
 #include <os2.h>
 
 #define INCL_M
 #include <os2.h>
 
-#include "wx/dynarray.h"
-#include "wx/log.h"
-
 #if wxUSE_OWNER_DRAWN
     #include  "wx/ownerdrw.h"
 #endif
 
 #if wxUSE_OWNER_DRAWN
     #include  "wx/ownerdrw.h"
 #endif
 
-  IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
+IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControlWithItems)
 
 // ============================================================================
 // list box item declaration and implementation
 
 // ============================================================================
 // list box item declaration and implementation
@@ -252,113 +252,78 @@ void wxListBox::DoSetFirstItem(int N)
     ::WinSendMsg(GetHwnd(), LM_SETTOPINDEX, MPFROMLONG(N), (MPARAM)0);
 } // end of wxListBox::DoSetFirstItem
 
     ::WinSendMsg(GetHwnd(), LM_SETTOPINDEX, MPFROMLONG(N), (MPARAM)0);
 } // end of wxListBox::DoSetFirstItem
 
-void wxListBox::Delete(int N)
+void wxListBox::DoDeleteOneItem(unsigned int n)
 {
 {
-    wxCHECK_RET( IsValid(N),
+    wxCHECK_RET( IsValid(n),
                  wxT("invalid index in wxListBox::Delete") );
 
 #if wxUSE_OWNER_DRAWN
                  wxT("invalid index in wxListBox::Delete") );
 
 #if wxUSE_OWNER_DRAWN
-    delete m_aItems[N];
-    m_aItems.RemoveAt(N);
-#else // !wxUSE_OWNER_DRAWN
-    if (HasClientObjectData())
-    {
-        delete GetClientObject(N);
-    }
+    delete m_aItems[n];
+    m_aItems.RemoveAt(n);
 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
 
 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
 
-    ::WinSendMsg(GetHwnd(), LM_DELETEITEM, (MPARAM)N, (MPARAM)0);
+    ::WinSendMsg(GetHwnd(), LM_DELETEITEM, (MPARAM)n, (MPARAM)0);
     m_nNumItems--;
 } // end of wxListBox::DoSetFirstItem
 
     m_nNumItems--;
 } // end of wxListBox::DoSetFirstItem
 
-int wxListBox::DoAppend(const wxString& rsItem)
+int wxListBox::DoInsertItems(const wxArrayStringsAdapter & items,
+                             unsigned int pos,
+                             void **clientData,
+                             wxClientDataType type)
 {
     long lIndex = 0;
     LONG lIndexType = 0;
 {
     long lIndex = 0;
     LONG lIndexType = 0;
+    bool incrementPos = false;
 
 
-    if (m_windowStyle & wxLB_SORT)
+    if (IsSorted())
         lIndexType = LIT_SORTASCENDING;
         lIndexType = LIT_SORTASCENDING;
-    else
+    else if (pos == GetCount())
         lIndexType = LIT_END;
         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)
+    else
     {
     {
-        wxOwnerDrawn*               pNewItem = CreateItem(lIndex); // dummy argument
-        wxScreenDC                  vDc;
-
-
-        pNewItem->SetName(rsItem);
-        m_aItems.Insert(pNewItem, lIndex);
-        ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, (MPARAM)lIndex, MPFROMP(pNewItem));
-        pNewItem->SetFont(GetFont());
+        lIndexType = (LONG)pos;
+        incrementPos = true;
     }
     }
-#endif
-    return (int)lIndex;
-} // end of wxListBox::DoAppend
 
 
-void wxListBox::DoSetItems( const wxArrayString& raChoices,
-                            void** ppClientData )
-{
-    BOOL bHideAndShow = IsShown();
-    LONG lIndexType = 0;
+    int n = wxNOT_FOUND;
 
 
-    if (bHideAndShow)
-    {
-        ::WinShowWindow(GetHwnd(), FALSE);
-    }
-    ::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0);
-    m_nNumItems = raChoices.GetCount();
-    for (size_t i = 0; i < m_nNumItems; i++)
+    unsigned int count = items.GetCount();
+    for (unsigned int i = 0; i < count; i++)
     {
     {
-        if (m_windowStyle & wxLB_SORT)
-            lIndexType = LIT_SORTASCENDING;
-        else
-            lIndexType = LIT_END;
-        ::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)raChoices[i].c_str());
-
-        if (ppClientData)
+        n = (int)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)items[i].wx_str());
+        if (n < 0)
         {
         {
-#if wxUSE_OWNER_DRAWN
-            wxASSERT_MSG(ppClientData[i] == NULL,
-                         wxT("Can't use client data with owner-drawn listboxes"));
-#else // !wxUSE_OWNER_DRAWN
-            ::WinSendMsg(WinUtil_GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(lCount), MPFROMP(ppClientData[i]));
-#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
+            wxLogLastError(_T("WinSendMsg(LM_INSERTITEM)"));
+            n = wxNOT_FOUND;
+            break;
         }
         }
-    }
+        ++m_nNumItems;
 
 #if wxUSE_OWNER_DRAWN
 
 #if wxUSE_OWNER_DRAWN
-    if ( m_windowStyle & wxLB_OWNERDRAW )
-    {
-        //
-        // First delete old items
-        //
-        WX_CLEAR_ARRAY(m_aItems);
-
-        //
-        // Then create new ones
-        //
-        for (size_t ui = 0; ui < m_nNumItems; ui++)
+        if (HasFlag(wxLB_OWNERDRAW))
         {
         {
-            wxOwnerDrawn*           pNewItem = CreateItem(ui);
-
-            pNewItem->SetName(raChoices[ui]);
-            m_aItems.Add(pNewItem);
-            ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(ui), MPFROMP(pNewItem));
+            wxOwnerDrawn*               pNewItem = CreateItem(n); // dummy argument
+            wxScreenDC                  vDc; // FIXME: is it really needed here?
+    
+            pNewItem->SetName(items[i]);
+            m_aItems.Insert(pNewItem, n);
+            ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, (MPARAM)n, MPFROMP(pNewItem));
+            pNewItem->SetFont(GetFont());
         }
         }
+#endif
+        AssignNewItemClientData(n, clientData, i, type);
+
+        if (incrementPos)
+            ++lIndexType;
     }
     }
-#endif // wxUSE_OWNER_DRAWN
-    ::WinShowWindow(GetHwnd(), TRUE);
-} // end of wxListBox::DoSetItems
 
 
-void wxListBox::Clear()
+    return n;
+} // end of wxListBox::DoInsertAppendItemsWithData
+
+void wxListBox::DoClear()
 {
 #if wxUSE_OWNER_DRAWN
 {
 #if wxUSE_OWNER_DRAWN
-    size_t lUiCount = m_aItems.Count();
+    unsigned int lUiCount = m_aItems.Count();
 
     while (lUiCount-- != 0)
     {
 
     while (lUiCount-- != 0)
     {
@@ -366,15 +331,7 @@ void wxListBox::Clear()
     }
 
     m_aItems.Clear();
     }
 
     m_aItems.Clear();
-#else // !wxUSE_OWNER_DRAWN
-    if (HasClientObjectData())
-    {
-        for (size_t n = 0; n < (size_t)m_lNumItems; n++)
-        {
-            delete GetClientObject(n);
-        }
-    }
-#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
+#endif // wxUSE_OWNER_DRAWN
     ::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0);
 
     m_nNumItems = 0;
     ::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0);
 
     m_nNumItems = 0;
@@ -414,12 +371,7 @@ bool wxListBox::IsSelected( int N ) const
     return (lItem == (LONG)N && lItem != LIT_NONE);
 } // end of wxListBox::IsSelected
 
     return (lItem == (LONG)N && lItem != LIT_NONE);
 } // end of wxListBox::IsSelected
 
-wxClientData* wxListBox::DoGetItemClientObject(int n) const
-{
-    return (wxClientData *)DoGetItemClientData(n);
-}
-
-void* wxListBox::DoGetItemClientData(int n) const
+void* wxListBox::DoGetItemClientData(unsigned int n) const
 {
     wxCHECK_MSG( IsValid(n), NULL,
                  wxT("invalid index in wxListBox::GetClientData") );
 {
     wxCHECK_MSG( IsValid(n), NULL,
                  wxT("invalid index in wxListBox::GetClientData") );
@@ -427,12 +379,7 @@ void* wxListBox::DoGetItemClientData(int n) const
     return((void *)::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE, MPFROMLONG(n), (MPARAM)0));
 } // end of wxListBox::DoGetItemClientData
 
     return((void *)::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE, MPFROMLONG(n), (MPARAM)0));
 } // end of wxListBox::DoGetItemClientData
 
-void wxListBox::DoSetItemClientObject(int n, wxClientData* pClientData)
-{
-    DoSetItemClientData(n, pClientData);
-} // end of wxListBox::DoSetItemClientObject
-
-void wxListBox::DoSetItemClientData(int n, void* pClientData)
+void wxListBox::DoSetItemClientData(unsigned int n, void* pClientData)
 {
     wxCHECK_RET( IsValid(n),
                  wxT("invalid index in wxListBox::SetClientData") );
 {
     wxCHECK_RET( IsValid(n),
                  wxT("invalid index in wxListBox::SetClientData") );
@@ -533,118 +480,85 @@ int wxListBox::GetSelection() const
                      ));
 } // end of wxListBox::GetSelection
 
                      ));
 } // end of wxListBox::GetSelection
 
-wxString wxListBox::GetString( int N ) const
+wxString wxListBox::GetString(unsigned int n) const
 {
     LONG     lLen = 0;
     wxChar*  zBuf;
     wxString sResult;
 
 {
     LONG     lLen = 0;
     wxChar*  zBuf;
     wxString sResult;
 
-    wxCHECK_MSG( IsValid(N), wxEmptyString,
+    wxCHECK_MSG( IsValid(n), wxEmptyString,
                  wxT("invalid index in wxListBox::GetClientData") );
 
                  wxT("invalid index in wxListBox::GetClientData") );
 
-    lLen = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)N, (MPARAM)0));
+    lLen = LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)n, (MPARAM)0));
     zBuf = new wxChar[lLen + 1];
     zBuf = new wxChar[lLen + 1];
-    ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT, MPFROM2SHORT((SHORT)N, (SHORT)lLen), (MPARAM)zBuf);
+    ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT, MPFROM2SHORT((SHORT)n, (SHORT)lLen), (MPARAM)zBuf);
     zBuf[lLen] = '\0';
     sResult = zBuf;
     delete [] zBuf;
     return sResult;
 } // end of wxListBox::GetString
 
     zBuf[lLen] = '\0';
     sResult = zBuf;
     delete [] zBuf;
     return sResult;
 } // end of wxListBox::GetString
 
-void wxListBox::DoInsertItems( const wxArrayString& asItems,
-                               int nPos )
+void wxListBox::SetString(unsigned int n, const wxString& rsString)
 {
 {
-    wxCHECK_RET( IsValidInsert(nPos),
-                 wxT("invalid index in wxListBox::InsertItems") );
-
-    size_t nItems = asItems.GetCount();
-
-    for (size_t i = 0; i < nItems; i++)
-    {
-        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)((LONG)nIndex)
-                     ,MPFROMP(pNewItem)
-                    );
-        m_nNumItems += nItems;
-    }
-} // end of wxListBox::DoInsertItems
-
-void wxListBox::SetString(int N, const wxString& rsString)
-{
-    wxCHECK_RET( IsValid(N),
+    wxCHECK_RET( IsValid(n),
                  wxT("invalid index in wxListBox::SetString") );
 
     //
     // Remember the state of the item
     //
                  wxT("invalid index in wxListBox::SetString") );
 
     //
     // Remember the state of the item
     //
-    bool           bWasSelected = IsSelected(N);
+    bool           bWasSelected = IsSelected(n);
     void*          pOldData = NULL;
     wxClientData*  pOldObjData = NULL;
 
     void*          pOldData = NULL;
     wxClientData*  pOldObjData = NULL;
 
-    if (m_clientDataItemsType == wxClientData_Void)
-        pOldData = GetClientData(N);
-    else if (m_clientDataItemsType == wxClientData_Object)
-        pOldObjData = GetClientObject(N);
+    if ( HasClientUntypedData() )
+        pOldData = GetClientData(n);
+    else if ( HasClientObjectData() )
+        pOldObjData = GetClientObject(n);
 
     //
     // Delete and recreate it
     //
     ::WinSendMsg( GetHwnd()
                  ,LM_DELETEITEM
 
     //
     // Delete and recreate it
     //
     ::WinSendMsg( GetHwnd()
                  ,LM_DELETEITEM
-                 ,(MPARAM)N
+                 ,(MPARAM)n
                  ,(MPARAM)0
                 );
 
                  ,(MPARAM)0
                 );
 
-    int                             nNewN = N;
+    int nNewN = n;
 
 
-    if (N == (int)(m_nNumItems - 1))
+    if (n == (m_nNumItems - 1))
         nNewN = -1;
 
     ::WinSendMsg( GetHwnd()
                  ,LM_INSERTITEM
                  ,(MPARAM)nNewN
         nNewN = -1;
 
     ::WinSendMsg( GetHwnd()
                  ,LM_INSERTITEM
                  ,(MPARAM)nNewN
-                 ,(MPARAM)rsString.c_str()
+                 ,(MPARAM)rsString.wx_str()
                 );
 
     //
     // Restore the client data
     //
     if (pOldData)
                 );
 
     //
     // Restore the client data
     //
     if (pOldData)
-        SetClientData( N
-                      ,pOldData
-                     );
+        SetClientData(n, pOldData);
     else if (pOldObjData)
     else if (pOldObjData)
-        SetClientObject( N
-                        ,pOldObjData
-                       );
+        SetClientObject(n, pOldObjData);
 
     //
     // We may have lost the selection
     //
     if (bWasSelected)
 
     //
     // We may have lost the selection
     //
     if (bWasSelected)
-        Select(N);
+        Select(n);
 
 #if wxUSE_OWNER_DRAWN
     if (m_windowStyle & wxLB_OWNERDRAW)
         //
         // Update item's text
         //
 
 #if wxUSE_OWNER_DRAWN
     if (m_windowStyle & wxLB_OWNERDRAW)
         //
         // Update item's text
         //
-        m_aItems[N]->SetName(rsString);
+        m_aItems[n]->SetName(rsString);
 #endif  //USE_OWNER_DRAWN
 } // end of wxListBox::SetString
 
 #endif  //USE_OWNER_DRAWN
 } // end of wxListBox::SetString
 
-size_t wxListBox::GetCount() const
+unsigned int wxListBox::GetCount() const
 {
     return m_nNumItems;
 }
 {
     return m_nNumItems;
 }
@@ -664,7 +578,7 @@ wxSize wxListBox::DoGetBestSize() const
     int        nCy;
     wxFont     vFont = (wxFont)GetFont();
 
     int        nCy;
     wxFont     vFont = (wxFont)GetFont();
 
-    for (size_t i = 0; i < m_nNumItems; i++)
+    for (unsigned int i = 0; i < m_nNumItems; i++)
     {
         wxString vStr(GetString(i));
 
     {
         wxString vStr(GetString(i));
 
@@ -746,7 +660,7 @@ bool wxListBox::OS2Command(
         n = -1;
     }
     vEvent.SetInt(n);
         n = -1;
     }
     vEvent.SetInt(n);
-    return GetEventHandler()->ProcessEvent(vEvent);
+    return HandleWindowEvent(vEvent);
 } // end of wxListBox::OS2Command
 
 // ----------------------------------------------------------------------------
 } // end of wxListBox::OS2Command
 
 // ----------------------------------------------------------------------------