PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms UITypeEditor issue

Reply

UITypeEditor issue

 
Thread Tools Rate Thread
Old 25-06-2003, 04:45 PM   #1
David W. Simmonds
Guest
 
Posts: n/a
Default UITypeEditor issue


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:rawing:esign::UITypeEditor
{
public:
virtual bool
GetPaintValueSupported(System::ComponentModel::ITypeDescriptorContext*
context);
virtual bool GetPaintValueSupported();
virtual void PaintValue(System::Object* value,
System:rawing::Graphics* canvas, System:rawing::Rectangle rectangle);
virtual void PaintValue(PaintValueEventArgs* e);
virtual System::Object*
EditValue(System::ComponentModel::ITypeDescriptorContext* context,
System::IServiceProvider* provider, System::Object* value);
virtual System:rawing:esign::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:rawing:esign::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:rawing::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;
}


  Reply With Quote
Old 01-07-2003, 11:58 AM   #2
Xin Huang
Guest
 
Posts: n/a
Default RE: UITypeEditor issue

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.

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off