tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ComboBox.cpp (1398B)


      1 // Windows/Control/ComboBox.cpp
      2 
      3 #include "StdAfx.h"
      4 
      5 #ifndef _UNICODE
      6 #include "../../Common/StringConvert.h"
      7 #endif
      8 
      9 #include "ComboBox.h"
     10 
     11 #ifndef _UNICODE
     12 extern bool g_IsNT;
     13 #endif
     14 
     15 namespace NWindows {
     16 namespace NControl {
     17 
     18 LRESULT CComboBox::GetLBText(int index, CSysString &s)
     19 {
     20  s.Empty();
     21  LRESULT len = GetLBTextLen(index); // length, excluding the terminating null character
     22  if (len == CB_ERR)
     23    return len;
     24  LRESULT len2 = GetLBText(index, s.GetBuf((unsigned)len));
     25  if (len2 == CB_ERR)
     26    return len;
     27  if (len > len2)
     28    len = len2;
     29  s.ReleaseBuf_CalcLen((unsigned)len);
     30  return len;
     31 }
     32 
     33 #ifndef _UNICODE
     34 LRESULT CComboBox::AddString(LPCWSTR s)
     35 {
     36  if (g_IsNT)
     37    return SendMsgW(CB_ADDSTRING, 0, (LPARAM)s);
     38  return AddString(GetSystemString(s));
     39 }
     40 
     41 LRESULT CComboBox::GetLBText(int index, UString &s)
     42 {
     43  s.Empty();
     44  if (g_IsNT)
     45  {
     46    LRESULT len = SendMsgW(CB_GETLBTEXTLEN, index, 0);
     47    if (len == CB_ERR)
     48      return len;
     49    LRESULT len2 = SendMsgW(CB_GETLBTEXT, index, (LPARAM)s.GetBuf((unsigned)len));
     50    if (len2 == CB_ERR)
     51      return len;
     52    if (len > len2)
     53      len = len2;
     54    s.ReleaseBuf_CalcLen((unsigned)len);
     55    return len;
     56  }
     57  AString sa;
     58  LRESULT len = GetLBText(index, sa);
     59  if (len == CB_ERR)
     60    return len;
     61  s = GetUnicodeString(sa);
     62  return s.Len();
     63 }
     64 #endif
     65 
     66 }}