]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/choice.cpp
precompiled headers fix
[wxWidgets.git] / src / os2 / choice.cpp
index 079295ab77803d5ddcb67038361989911acee866..793111d6b57caf85630abab30593f5c73d7635ce 100644 (file)
     #include "wx/choice.h"
     #include "wx/utils.h"
     #include "wx/log.h"
+    #include "wx/settings.h"
 #endif
 
 #include "wx/os2/private.h"
 
 IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
 
+bool wxChoice::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 wxChoice::Create(
   wxWindow*                         pParent
 , wxWindowID                        vId
@@ -30,24 +48,20 @@ bool wxChoice::Create(
 , int                               n
 , const wxString                    asChoices[]
 , long                              lStyle
-#if wxUSE_VALIDATORS
 , const wxValidator&                rValidator
-#endif
 , const wxString&                   rsName
 )
 {
     long                            lSstyle;
 
-    if (!OS2CreateControl( pParent
-                          ,vId
-                          ,rPos
-                          ,rSize
-                          ,lStyle
-#if wxUSE_VALIDATORS
-                          ,rValidator
-#endif
-                          ,rsName
-                         ))
+    if (!CreateControl( pParent
+                       ,vId
+                       ,rPos
+                       ,rSize
+                       ,lStyle
+                       ,rValidator
+                       ,rsName
+                      ))
         return FALSE;
     lSstyle = CBS_DROPDOWNLIST |
               WS_TABSTOP       |
@@ -71,17 +85,23 @@ bool wxChoice::Create(
     // A choice/combobox normally has a white background (or other, depending
     // on global settings) rather than inheriting the parent's background colour.
     //
-    SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
+    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
     for (int i = 0; i < n; i++)
     {
         Append(asChoices[i]);
     }
+    wxFont*                          pTextFont = new wxFont( 10
+                                                            ,wxMODERN
+                                                            ,wxNORMAL
+                                                            ,wxNORMAL
+                                                           );
+    SetFont(*pTextFont);
     SetSize( rPos.x
             ,rPos.y
             ,rSize.x
             ,rSize.y
            );
-
+    delete pTextFont;
     return TRUE;
 } // end of wxChoice::Create
 
@@ -94,7 +114,7 @@ int wxChoice::DoAppend(
 )
 {
     int                             nIndex;
-    SHORT                           nIndexType = 0;
+    LONG                            nIndexType = 0;
 
     if (m_windowStyle & wxLB_SORT)
         nIndexType = LIT_SORTASCENDING;
@@ -108,6 +128,32 @@ int wxChoice::DoAppend(
     return nIndex;
 } // end of wxChoice::DoAppend
 
+int wxChoice::DoInsert(
+  const wxString&                   rsItem,
+  int                               pos
+)
+{
+    wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
+    wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
+
+    if (pos == GetCount())
+        return DoAppend(rsItem);
+
+    int                             nIndex;
+    LONG                            nIndexType = 0;
+
+    if (m_windowStyle & wxLB_SORT)
+        nIndexType = LIT_SORTASCENDING;
+    else
+        nIndexType = pos;
+    nIndex = (int)::WinSendMsg( GetHwnd()
+                               ,LM_INSERTITEM
+                               ,(MPARAM)nIndexType
+                               ,(MPARAM)rsItem.c_str()
+                              );
+    return nIndex;
+} // end of wxChoice::DoInsert
+
 void wxChoice::Delete(
   int                               n
 )
@@ -181,24 +227,48 @@ void wxChoice::SetString(
 , const wxString&                   rsStr
 )
 {
-    wxFAIL_MSG(wxT("not implemented"));
+    LONG                            nIndexType = 0;
+    void*                           pData;
 
-#if 0 // should do this, but no Insert() so far
-    Delete(n);
-    Insert(n + 1, s);
-#endif
+    if ( m_clientDataItemsType != wxClientData_None )
+    {
+        pData = DoGetItemClientData(n);
+    }
+    else // no client data
+    {
+        pData = NULL;
+    }
+
+    ::WinSendMsg(GetHwnd(), LM_DELETEITEM, (MPARAM)n, 0);
+
+    if (m_windowStyle & wxLB_SORT)
+        nIndexType = LIT_SORTASCENDING;
+    else
+        nIndexType = LIT_END;
+    ::WinSendMsg( GetHwnd()
+                 ,LM_INSERTITEM
+                 ,(MPARAM)nIndexType
+                 ,(MPARAM)rsStr.c_str()
+                );
+
+    if (pData)
+    {
+        DoSetItemClientData( n
+                            ,pData
+                           );
+    }
 } // end of wxChoice::SetString
 
 wxString wxChoice::GetString(
   int                               n
 ) const
 {
-    size_t                          nLen = 0;
+    int                             nLen = 0;
     wxString                        sStr = "";
     char*                           zBuf;
 
     nLen = (size_t)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)n, (MPARAM)0));
-    if (nLen)
+    if (nLen != LIT_ERROR && nLen > 0)
     {
         zBuf = new char[nLen + 1];
         ::WinSendMsg( GetHwnd()