void vvStampsModel::GetValue(
	wxVariant&            cValue,
	const wxDataViewItem& cItem,
	unsigned int          uColumn
	) const
{
	wxASSERT(cItem.IsOk());

	const DataItem* pItem = this->ConvertDataItem(cItem);

	switch (static_cast<Column>(uColumn))
	{
	case COLUMN_B_CHECKED:
		cValue = pItem->bChecked;
		return;

	case COLUMN_BS_NAME:
	case COLUMN_S_NAME:
		cValue = pItem->sName;
		return;

	case COLUMN_U_COUNT:
		cValue = static_cast<long>(pItem->uCount);
		return;

	default:
		wxLogError("Unknown StampsModel column: %u", uColumn);
		cValue.MakeNull();
		return;
	}
}
Пример #2
0
void PgStatement::GetFieldValue
  (
  int         nIndex,
  wxVariant&  v
  )
  {
  int nIsNull = PQgetisnull(pgr, nCurrentRecord, nIndex);
  if(nIsNull != 0)
    {
    v.MakeNull();
    return;
    }

	char * sz = PQgetvalue(pgr, nCurrentRecord, nIndex);

  Oid typ = PQftype(pgr, nIndex);
  switch(typ)
    {
    case PG_OID_BOOLEAN:
      {
      bool b = (sz[0] == 't')? true : false;
      v = b;
      break;
      }
    case PG_OID_OID:
    case PG_OID_INT4:
    case PG_OID_TRANSACTIONID:
      {
      long n = atol(sz);
      v = n;
      break;
      }
    case PG_OID_DOUBLE:
      {
      double d = atof(sz);
      v = d;
      break;
      }
    case PG_OID_NAME:
    case PG_OID_TEXT:
    case PG_OID_VARCHAR_LENGTH:
      {
      //int nFormat = PQfformat(pgr, nIndex); // 0 => text, 1 => binary
      wxString s(sz, wxConvLocal);
      //wxString s = wxConvUTF8.cMB2WX(sz);
      v = s;
      break;
      }
    // Items we don't know how to handle
    case PG_OID_TEXTARRAY:
    case PG_OID_ACLITEMARRAY:
      v = wxT("");
      break;

    default:
      throw wx::Exception(wxT("PgStatement::GetFieldValue() Unhandled data type %d"), typ);
    }
  }
Пример #3
0
bool MSWVariantToVariant(VARIANTARG& va, wxVariant& vx)
{
    switch(va.vt)
    {
	case VT_VARIANT | VT_BYREF:
		return MSWVariantToVariant(*va.pvarVal, vx);

    case VT_I2:
    case VT_I4:
        vx = (long) va.iVal;
        return true;

    case VT_I2 | VT_BYREF:
    case VT_I4 | VT_BYREF:
        vx = (long) *va.piVal;
        return true;

    case VT_BSTR:
        vx = wxString(va.bstrVal);
        return true;

    case VT_BSTR | VT_BYREF:
        vx = wxString(*va.pbstrVal);
        return true;

	case VT_BOOL:
		vx = (va.boolVal != FALSE);
		return true;

	case VT_BOOL | VT_BYREF:
		vx = (*va.pboolVal != FALSE);
		return true;

    default:
        vx.MakeNull();
        return false;
    };
};
Пример #4
0
WXDLLEXPORT bool
wxConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant, long flags)
{
    bool ok = true;
    if ( oleVariant.vt & VT_ARRAY )
    {
        if ( flags & wxOleConvertVariant_ReturnSafeArrays  )
        {
            variant.SetData(new wxVariantDataSafeArray(oleVariant.parray));
        }
        else
        {
            switch (oleVariant.vt & VT_TYPEMASK)
            {
                case VT_I2:
                    ok = wxSafeArray<VT_I2>::ConvertToVariant(oleVariant.parray, variant);
                    break;
                case VT_I4:
                    ok = wxSafeArray<VT_I4>::ConvertToVariant(oleVariant.parray, variant);
                    break;
                case VT_R4:
                    ok = wxSafeArray<VT_R4>::ConvertToVariant(oleVariant.parray, variant);
                    break;
                case VT_R8:
                    ok = wxSafeArray<VT_R8>::ConvertToVariant(oleVariant.parray, variant);
                    break;
                case VT_VARIANT:
                    ok = wxSafeArray<VT_VARIANT>::ConvertToVariant(oleVariant.parray, variant);
                    break;
                case VT_BSTR:
                    {
                        wxArrayString strings;
                        if ( wxSafeArray<VT_BSTR>::ConvertToArrayString(oleVariant.parray, strings) )
                            variant = strings;
                        else
                            ok = false;
                    }
                    break;
                default:
                    ok = false;
                    break;
            }
            if ( !ok )
            {
                wxLogDebug(wxT("unhandled VT_ARRAY type %x in wxConvertOleToVariant"),
                           oleVariant.vt & VT_TYPEMASK);
                variant = wxVariant();
            }
        }
    }
    else if ( oleVariant.vt & VT_BYREF )
    {
        switch ( oleVariant.vt & VT_TYPEMASK )
        {
            case VT_VARIANT:
                {
                    VARIANTARG& oleReference = *((LPVARIANT)oleVariant.byref);
                    if (!wxConvertOleToVariant(oleReference,variant))
                        return false;
                    break;
                }

            default:
                wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: [as yet] unhandled reference %X"),
                            oleVariant.vt);
                return false;
        }
    }
    else // simply type (not array or reference)
    {
        switch ( oleVariant.vt & VT_TYPEMASK )
        {
            case VT_ERROR:
                variant.SetData(new wxVariantDataErrorCode(oleVariant.scode));
                break;

            case VT_CY:
                variant.SetData(new wxVariantDataCurrency(oleVariant.cyVal));
                break;

            case VT_BSTR:
                {
                    wxString str(wxConvertStringFromOle(oleVariant.bstrVal));
                    variant = str;
                }
                break;

            case VT_DATE:
#if wxUSE_DATETIME
                {
                    SYSTEMTIME st;
                    VariantTimeToSystemTime(oleVariant.date, &st);

                    wxDateTime date;
                    date.SetFromMSWSysTime(st);
                    variant = date;
                }
#endif // wxUSE_DATETIME
                break;

#if wxUSE_LONGLONG
            case VT_I8:
                variant = wxLongLong(oleVariant.llVal);
                break;
#endif // wxUSE_LONGLONG

            case VT_I4:
                variant = (long) oleVariant.lVal;
                break;

            case VT_I2:
                variant = (long) oleVariant.iVal;
                break;

            case VT_BOOL:
                variant = oleVariant.boolVal != 0;
                break;

            case VT_R4:
                variant = oleVariant.fltVal;
                break;

            case VT_R8:
                variant = oleVariant.dblVal;
                break;

            case VT_DISPATCH:
                variant = (void*) oleVariant.pdispVal;
                break;

            case VT_NULL:
            case VT_EMPTY:
                variant.MakeNull();
                break;

            default:
                wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: Unknown variant value type %X -> %X"),
                           oleVariant.vt,oleVariant.vt&VT_TYPEMASK);
                return false;
        }
    }

    return ok;
}
Пример #5
0
WXDLLEXPORT bool
wxConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant)
{
    bool ok = true;
    if ( oleVariant.vt & VT_ARRAY )
    {
        // TODO: We currently return arrays as wxVariant of the list type
        //       containing the flattened form of array but we should allow
        //       getting it as wxVariantDataSafeArray instead. Doing this is
        //       simple, we'd just need to do something like this:
        //
        //  if ( oleVariant.parray && SafeArrayGetDim(oleVariant.parray) > 1 )
        //  {
        //      variant.SetData(new wxVariantDataSafeArray(oleVariant.parray));
        //  }
        //
        //      but currently we don't do it for compatibility reasons.
        switch (oleVariant.vt & VT_TYPEMASK)
        {
            case VT_I2:
                ok = wxSafeArray<VT_I2>::ConvertToVariant(oleVariant.parray, variant);
                break;
            case VT_I4:
                ok = wxSafeArray<VT_I4>::ConvertToVariant(oleVariant.parray, variant);
                break;
            case VT_R4:
                ok = wxSafeArray<VT_R4>::ConvertToVariant(oleVariant.parray, variant);
                break;
            case VT_R8:
                ok = wxSafeArray<VT_R8>::ConvertToVariant(oleVariant.parray, variant);
                break;
            case VT_VARIANT:
                ok = wxSafeArray<VT_VARIANT>::ConvertToVariant(oleVariant.parray, variant);
                break;
            case VT_BSTR:
                {
                    wxArrayString strings;
                    if ( wxSafeArray<VT_BSTR>::ConvertToArrayString(oleVariant.parray, strings) )
                        variant = strings;
                    else
                        ok = false;
                }
                break;
            default:
                ok = false;
                break;
        }
        if ( !ok )
        {
            wxLogDebug(wxT("unhandled VT_ARRAY type %x in wxConvertOleToVariant"),
                       oleVariant.vt & VT_TYPEMASK);
            variant = wxVariant();
        }
    }
    else if ( oleVariant.vt & VT_BYREF )
    {
        switch ( oleVariant.vt & VT_TYPEMASK )
        {
            case VT_VARIANT:
                {
                    VARIANTARG& oleReference = *((LPVARIANT)oleVariant.byref);
                    if (!wxConvertOleToVariant(oleReference,variant))
                        return false;
                    break;
                }

            default:
                wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: [as yet] unhandled reference %X"),
                            oleVariant.vt);
                return false;
        }
    }
    else // simply type (not array or reference)
    {
        switch ( oleVariant.vt & VT_TYPEMASK )
        {
            case VT_ERROR:
                variant.SetData(new wxVariantDataErrorCode(oleVariant.scode));
                break;

            case VT_CY:
                variant.SetData(new wxVariantDataCurrency(oleVariant.cyVal));
                break;

            case VT_BSTR:
                {
                    wxString str(wxConvertStringFromOle(oleVariant.bstrVal));
                    variant = str;
                }
                break;

            case VT_DATE:
#if wxUSE_DATETIME
                {
                    SYSTEMTIME st;
                    VariantTimeToSystemTime(oleVariant.date, &st);

                    wxDateTime date;
                    date.SetFromMSWSysTime(st);
                    variant = date;
                }
#endif // wxUSE_DATETIME
                break;

                // See the comment before the __VISUALC6__ test above.
#if wxUSE_LONGLONG && !defined(__VISUALC6__)
            case VT_I8:
                variant = wxLongLong(oleVariant.llVal);
                break;
#endif // wxUSE_LONGLONG

            case VT_I4:
                variant = (long) oleVariant.lVal;
                break;

            case VT_I2:
                variant = (long) oleVariant.iVal;
                break;

            case VT_BOOL:
                variant = oleVariant.boolVal != 0;
                break;

            case VT_R4:
                variant = oleVariant.fltVal;
                break;

            case VT_R8:
                variant = oleVariant.dblVal;
                break;

            case VT_DISPATCH:
                variant = (void*) oleVariant.pdispVal;
                break;

            case VT_NULL:
                variant.MakeNull();
                break;

            case VT_EMPTY:
                break;    // Ignore Empty Variant, used only during destruction of objects

            default:
                wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: Unknown variant value type %X -> %X"),
                           oleVariant.vt,oleVariant.vt&VT_TYPEMASK);
                return false;
        }
    }

    return ok;
}
Пример #6
0
WXDLLEXPORT bool
wxConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant)
{
    bool ok = true;
    if ( oleVariant.vt & VT_ARRAY )
    {

        // Compute the total number of elements in all array dimensions
        int cElements = 1;
        for ( int cDims = 0; cDims < oleVariant.parray->cDims; cDims++ )
            cElements *= oleVariant.parray->rgsabound[cDims].cElements;

        // Get a pointer to the data
        void* pvdata;
        HRESULT hr = SafeArrayAccessData(oleVariant.parray, &pvdata);
        if ( FAILED(hr) )
            return false;

        switch (oleVariant.vt & VT_TYPEMASK)
        {
        case VT_VARIANT:
        {
            variant.ClearList();
            VARIANTARG *variant_data=(VARIANTARG*)pvdata;
            for ( int i = 0; i < cElements; i++ )
            {
                VARIANTARG& oleElement = variant_data[i];
                wxVariant vElement;
                if ( !wxConvertOleToVariant(oleElement, vElement) )
                {
                    ok = false;
                    variant.ClearList();
                    break;
                }

                variant.Append(vElement);
            }
        }
        break;

        case VT_BSTR:
        {
            wxArrayString strings;
            BSTR *string_val=(BSTR*)pvdata;
            for ( int i = 0; i < cElements; ++i )
            {
                wxString str=wxConvertStringFromOle(*string_val);
                strings.Add(str);
                ++string_val;
            }
            variant=strings;
        }
        break;

        default:
            wxLogDebug(wxT("unhandled VT_ARRAY type %x in wxConvertOleToVariant"),
                       oleVariant.vt & VT_TYPEMASK);
            variant = wxVariant();
            ok = false;
            break;
        }

        SafeArrayUnaccessData(oleVariant.parray);
    }
    else if ( oleVariant.vt & VT_BYREF )
    {
        switch ( oleVariant.vt & VT_TYPEMASK )
        {
        case VT_VARIANT:
        {
            VARIANTARG& oleReference = *((LPVARIANT)oleVariant.byref);
            if (!wxConvertOleToVariant(oleReference,variant))
                return false;
            break;
        }

        default:
            wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: [as yet] unhandled reference %X"),
                       oleVariant.vt);
            return false;
        }
    }
    else // simply type (not array or reference)
    {
        switch ( oleVariant.vt & VT_TYPEMASK )
        {
        case VT_BSTR:
        {
            wxString str(wxConvertStringFromOle(oleVariant.bstrVal));
            variant = str;
        }
        break;

        case VT_DATE:
#if wxUSE_DATETIME
        {
            SYSTEMTIME st;
            VariantTimeToSystemTime(oleVariant.date, &st);

            wxDateTime date;
            date.SetFromMSWSysTime(st);
            variant = date;
        }
#endif // wxUSE_DATETIME
        break;

        case VT_I4:
            variant = (long) oleVariant.lVal;
            break;

        case VT_I2:
            variant = (long) oleVariant.iVal;
            break;

        case VT_BOOL:
            variant = oleVariant.boolVal != 0;
            break;

        case VT_R8:
            variant = oleVariant.dblVal;
            break;

        case VT_DISPATCH:
            variant = (void*) oleVariant.pdispVal;
            break;

        case VT_NULL:
            variant.MakeNull();
            break;

        case VT_EMPTY:
            break;    // Ignore Empty Variant, used only during destruction of objects

        default:
            wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: Unknown variant value type %X -> %X"),
                       oleVariant.vt,oleVariant.vt&VT_TYPEMASK);
            return false;
        }
    }

    return ok;
}