My goal is to display in a graphical application properties of my
objects. To do that I am using on windows a graphical control (MFC)
called EPropCtrl with the following definition :
Expand|Select|Wrap|Line Numbers
- class IPropertyHost
- {
- public:
- virtual void GetProperties( EPropList& PropList ) {}
- };
- // EPropCtrl : Windows control (MFC) that looks like a ListBox
- class EPropCtrl
- {
- public:
- SetPropPointer( IPropertyHost* pHost);
- };
Pratically when I want to display/modify properties of a simple class
defined like this :
Expand|Select|Wrap|Line Numbers
- class Simple
- {
- protected:
- int iValue;
- };
IPropertyHost like this :
Expand|Select|Wrap|Line Numbers
- class SimpleProp : public Simple,
- public IPropertyHost
- {
- public:
- virtual void GetProperties( EPropList& PropList )
- {
- PropList.AddPropInt(this,_T("iValue"),&iValue, false);
- }
- IPropertyHost* GetPropPointer() { return this; }
- protected:
- int iValue;
- };
EPropCtrl objPropCtrl; // Graphical window to display/edit propertis
SimpleProp simpleProp; //Objet SimpleProp
objPropCtrl.SetPropPointer( simpleProp.GetPropPointer() );
// --------------- SO FAR EVERYTHING IS OK --------------------------
Now let's consider two objects that wrapps C structures like this :
Expand|Select|Wrap|Line Numbers
- typedef struct tagStructB
- {
- int iSizeB;
- char* szTextB;
- } StructB;
- typedef struct tagStructA
- {
- int iSizeA;
- char* szTextA;
- StructB sStructB;
- } StructA;
- class B
- {
- public:
- B(structB& refStructB) { m_refStructB = refStructB ;}
- int GetSize() {return m_StructB.iSizeB;}
- char* GetText() {return m_StructB.szTextB;}
- protected:
- structB& m_refStructB;
- };
- class A
- {
- public:
- A();
- int GetSize() {return m_StructA.iSizeA;}
- char* GetText() {return m_StructA.szTextA;}
- B& GetB() { return m_B; }
- protected:
- structA m_StructA;
- B m_B;
- };
- Example of use :
- A m_a;
- int iSizeA = m_A.GetSize();
- m_A.GetB().GetSize();
class BProp: public B,
public IPropertyHost
{
public:
virtual void GetProperties( EPropList& PropList )
{
PropList.AddPropInt(this,_T("iSizeB"),&m_refStruct B.iSizeB, false);
PropList.AddPropString(this,_T("szTextB"),&m_refSt ructB.szTextB, false);
}
IPropertyHost* GetPropPointer() { return this; }
};
class AProp: public A,
public IPropertyHost
{
public:
virtual void GetProperties( EPropList& PropList )
{
PropList.AddPropInt(this,_T("iSizeA"),&m__StructA. iSizeA, false);
PropList.AddPropString(this,_T("szTextA"),&m__Stru ctA.szTextA, false);
m_B.GetProperties( PropList ); // <----- CANNOT WORK
}
IPropertyHost* GetPropPointer() { return this; }
};
EPropCtrl objPropCtrl;
AProp objAProp;
objPropCtrl.SetPropPointer( objAProp.GetPropPointer() );
// PROBLEM : I CANNOT call m_B.GetProperties( PropList ) to display B
properties from AProp since Aprop has only a B and not a BProp.
HOw should I change my objets to display my properties ??????????????