UITypeEditor issue

  • Thread starter Thread starter David W. Simmonds
  • Start date Start date
D

David W. Simmonds

I have a property that uses my own editor. It brings up a modal dialog. When
I hit ok on the dialog, the PropertyGrid does not send out a
PropertyValueChanged notification. Is there anything special I have to do to
make this happen?

public __gc class CPictureEditor : public
System::Drawing::Design::UITypeEditor
{
public:
virtual bool
GetPaintValueSupported(System::ComponentModel::ITypeDescriptorContext*
context);
virtual bool GetPaintValueSupported();
virtual void PaintValue(System::Object* value,
System::Drawing::Graphics* canvas, System::Drawing::Rectangle rectangle);
virtual void PaintValue(PaintValueEventArgs* e);
virtual System::Object*
EditValue(System::ComponentModel::ITypeDescriptorContext* context,
System::IServiceProvider* provider, System::Object* value);
virtual System::Drawing::Design::UITypeEditorEditStyle
GetEditStyle(System::ComponentModel::ITypeDescriptorContext* context);
};

public __gc class CPictureConverter : public
System::ComponentModel::TypeConverter
{
public:
virtual bool
GetStandardValuesSupported(System::ComponentModel::ITypeDescriptorContext*
context)
{ return false; }
virtual bool
GetStandardValuesExclusive(System::ComponentModel::ITypeDescriptorContext*
context)
{ return true; }
virtual bool
CanConvertFrom(System::ComponentModel::ITypeDescriptorContext* context,
System::Type* t);
virtual bool
CanConvertTo(System::ComponentModel::ITypeDescriptorContext* context,
System::Type* t);
virtual Object*
ConvertFrom(System::ComponentModel::ITypeDescriptorContext* context,
System::Globalization::CultureInfo* culture, System::Object* o);
virtual Object*
ConvertTo(System::ComponentModel::ITypeDescriptorContext* context,
System::Globalization::CultureInfo* culture, System::Object* o,
System::Type* t);
};

[System::ComponentModel::EditorAttribute(__typeof(CPictureEditor),
__typeof(System::Drawing::Design::UITypeEditor))]
[System::ComponentModel::TypeConverterAttribute(__typeof(CPictureConverter))
]
[Serializable]
public __gc class PictureObj : public
System::Runtime::Serialization::ISerializable
{
private:
CPicture* m_pPicture;
public:
PictureObj()
{
m_pPicture = new CPicture;
}
~PictureObj()
{
delete m_pPicture;
}
PictureObj(System::Runtime::Serialization::SerializationInfo *si,
System::Runtime::Serialization::StreamingContext sc)
{
m_pPicture = new CPicture;
SetObjectData(si, sc);
}
void SetPicture(CPicture* pic) { *m_pPicture = *pic; }
CPicture* GetPicture() { return m_pPicture; }
void GetObjectData(System::Runtime::Serialization::SerializationInfo
*si,
System::Runtime::Serialization::StreamingContext sc);
void SetObjectData(System::Runtime::Serialization::SerializationInfo
*si,
System::Runtime::Serialization::StreamingContext sc);

__property IPicture* get_Picture() { return m_pPicture->m_pImage; }
__property void set_Picture(IPicture* value) { m_pPicture->m_pImage =
value; }
__property System::String* get_ImageExt() { return new
System::String(m_pPicture->m_strImageExt); }
__property void set_ImageExt(System::String* value) {
m_pPicture->m_strImageExt = value; }
};

bool CPictureEditor::GetPaintValueSupported(ITypeDescriptorContext* context)
{
return GetPaintValueSupported();
}
bool CPictureEditor::GetPaintValueSupported()
{
return true;
}
void CPictureEditor::PaintValue(PaintValueEventArgs* e)
{
PaintValue(e->Value, e->Graphics, e->Bounds);
}
void CPictureEditor::PaintValue(Object* value, Graphics* canvas,
System::Drawing::Rectangle rectangle)
{
if (value != NULL)
{
PictureObj* pic = static_cast<PictureObj*>(value);
HBITMAP hBitmap; pic->Picture->get_Handle((OLE_HANDLE*)&hBitmap);
Image* image = Image::FromHbitmap(hBitmap);
if (image != NULL)
canvas->DrawImage(image, rectangle);
}
}
Object* CPictureEditor::EditValue(ITypeDescriptorContext* context,
System::IServiceProvider* provider, Object* value)
{
IWindowsFormsEditorService* pService =
static_cast<IWindowsFormsEditorService*>(provider->GetService(__typeof(IWind
owsFormsEditorService)));
if (pService != NULL)
{
CPictureDlg dlg(AfxGetMainWnd());
if (value != NULL)
{
PictureObj* pic = static_cast<PictureObj*>(value);
dlg.m_Picture = *pic->GetPicture();
}
if (dlg.DoModal() == IDOK)
{
PictureObj* pic = new PictureObj;
pic->SetPicture(&dlg.m_Picture);
return pic;
}
else
return value;
}
return NULL;
}
UITypeEditorEditStyle CPictureEditor::GetEditStyle(ITypeDescriptorContext*
context)
{
return Modal;
}
 
Sorry for slow response. I'm reviewing this problem but found the code is
not compilable. Can you re-post the code that can be directly compiled?

Regards,
Xin

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. (c) 2003 Microsoft Corporation. All
rights reserved.
 
Back
Top