void
TLvColumn::SetText(const tstring& text)
{
  if (!IsRepresentable<int>(text.size() + 1))
    throw TXOwl(_T("TLvColumn::SetText: The text argument is too large (>INT_MAX)"));

  Buffer.assign(text.begin(), text.end());
  Buffer.push_back(_T('\0'));
  SetTextBuffer(&Buffer[0], static_cast<int>(Buffer.size()));
}
TLvItem::TLvItem(uint mask_, bool allocTextBuffer, int bufferSize)
{
  Init();
  if (allocTextBuffer)
  {
    CHECK(bufferSize > 0);
    Buffer.resize(bufferSize);
    SetTextBuffer(&Buffer[0], bufferSize);
  }
  mask = mask_;
}
TLvColumn::TLvColumn(uint mask_, int subitemIndex, int bufferSize)
{
  Init();
  mask = mask_;
  SetSubItem(subitemIndex);
  if (mask_ & LVCF_TEXT)
  {
    CHECK(bufferSize > 0);
    Buffer.resize(bufferSize);
    SetTextBuffer(&Buffer[0], bufferSize);
  }
}
TLvItem::TLvItem(const TListViewCtrl& ctl, int index, int subitemIndex, uint mask_, int bufferSize)
{
  PRECONDITION(ctl.GetHandle());
  Init();
  mask = mask_;
  if (mask_ & LVIF_TEXT)
  {
    CHECK(bufferSize > 0);
    Buffer.resize(bufferSize);
    SetTextBuffer(&Buffer[0], bufferSize);
  }
  ctl.GetItem(*this, index, subitemIndex);  
}
TLvColumn::TLvColumn(const TListViewCtrl& ctl, int index, uint mask_, int subitemIndex, int bufferSize) 
{
  PRECONDITION(ctl.GetHandle());
  Init();
  mask = mask_;
  SetSubItem(subitemIndex);
  if (mask_ & LVCF_TEXT)
  {
    CHECK(bufferSize > 0);
    Buffer.resize(bufferSize);
    SetTextBuffer(&Buffer[0], bufferSize);
  }
  ctl.GetColumn(index, *this);
}
///////////////////////////////////////////////////////////////////////////////
//
// Open()
//
// Purpose:     Open a file resource
//
// Parameters:  hInstance      - instance handle for the resource.  A value of 
//                               NULL specifies the exe (default).
//              lpszResId      - resource name or id (passed via MAKEINTRESOURCE)
//              lpszResType    - resource type string to look for
//              eConvertAction - convert action to take
//              eBomAction     - action to take with BOM
//
// Returns:     BOOL           - returns TRUE if resource opened ok, otherwise FALSE
//
BOOL CResourceTextFile::Open(HINSTANCE hInstance, 
							 LPCTSTR lpszResId, 
							 LPCTSTR lpszResType /*= _T("TEXT")*/,
							 ConvertAction eConvertAction /*= NoConvertAction*/,
							 BomAction eBomAction /*= NoBomAction*/)
{
	BOOL rc = FALSE;

	Close();

	_ASSERTE(lpszResId);
	_ASSERTE(lpszResType);

	m_eConvertAction = eConvertAction;
	TRACE(_T("m_eConvertAction=%d\n"), m_eConvertAction);
	m_eBomAction = eBomAction;
	TRACE(_T("m_eBomAction=%d\n"), m_eBomAction);

	if (lpszResId && lpszResType)
	{
		rc = CResourceFile::Open(hInstance, lpszResId, lpszResType);

		if (rc)
		{
			TCHAR *cp = (TCHAR *) GetByteBuffer();
			DWORD dwSize = (DWORD) GetLength();
			TRACE(_T("dwSize=%d\n"), dwSize);

			rc = SetTextBuffer(cp, dwSize, 
					eConvertAction, eBomAction);

			if (rc)
			{
				m_bText = TRUE;
			}
			else
			{
				TRACE(_T("ERROR SetTextBuffer failed\n"));
				Close();
			}
		}
		else
		{
			TRACE(_T("ERROR Open failed\n"));
		}
	}

	return rc;
}