なぞの絵

Bayside2004-12-02


難解なマクロを展開したもの

#include "Event.h"

class IEventHandler : public Object
{
public:
    virtual void Invoke(Pointer<Object>, Pointer<EventArgs>) = 0;
};
template <class T> class EventHandler : public IEventHandler
{
private:
    Pointer<T> ptr;
    void(T::*func)(Pointer<Object>, Pointer<EventArgs>);
public:
    EventHandler(Pointer<T> p, void(T::*f)(Pointer<Object>, Pointer<EventArgs>)) : ptr(p), func(f) {}
    virtual ~EventHandler() {}
    virtual void Invoke(Pointer<Object> sender, Pointer<EventArgs> arg) {
        ((ptr.get())->*func)(sender, arg);
    }
};
class EventHandler_S : public IEventHandler
{
private:
    void(*func)(Pointer<Object>, Pointer<EventArgs>);
    public: EventHandler_S(void(*f)(Pointer<Object>, Pointer<EventArgs>)) : func(f) {}
    virtual ~EventHandler_S() {}
    virtual void Invoke(Pointer<Object> sender, Pointer<EventArgs> arg) {
        (*func)(sender, arg);
    }
};

#include "Control.h"

private:
    Pointer<ArrayList<Pointer<IEventHandler> > > TextChanged;
    Pointer<ArrayList<Pointer<IEventHandler> > > ForeColorChanged;
    Pointer<ArrayList<Pointer<IEventHandler> > > BackColorChanged;
    Pointer<ArrayList<Pointer<IMouseEventHandler> > > MouseMove;
    Pointer<ArrayList<Pointer<IMouseEventHandler> > > MouseDown;
    Pointer<ArrayList<Pointer<IMouseEventHandler> > > MouseUp;
    Pointer<ArrayList<Pointer<IEventHandler> > > MouseEnter;
    Pointer<ArrayList<Pointer<IEventHandler> > > MouseLeave;
    Pointer<ArrayList<Pointer<IEventHandler> > > Click;
public:
    void add_TextChanged(Pointer<IEventHandler> delg)
    {
        if (this->TextChanged == 0 ) this->TextChanged = new ArrayList<Pointer<IEventHandler> >;
        this->TextChanged->Add(delg);
    }
    void remove_TextChanged(Pointer<IEventHandler> delg)
    {
        if (this->TextChanged == 0 ) return;
        this->TextChanged->Remove(delg);
        if (this->TextChanged->get_Count() == 0) this->TextChanged.Unset();
    }
    void add_ForeColorChanged(Pointer<IEventHandler> delg)
    {
        if (this->ForeColorChanged == 0 ) this->ForeColorChanged = new ArrayList<Pointer<IEventHandler> >;
        this->ForeColorChanged->Add(delg);
    }
    void remove_ForeColorChanged(Pointer<IEventHandler> delg)
    {
        if (this->ForeColorChanged == 0 ) return;
        this->ForeColorChanged->Remove(delg);
        if (this->ForeColorChanged->get_Count() == 0) this->ForeColorChanged.Unset();
    }
    void add_BackColorChanged(Pointer<IEventHandler> delg)
    {
        if (this->BackColorChanged == 0 ) this->BackColorChanged = new ArrayList<Pointer<IEventHandler> >;
        this->BackColorChanged->Add(delg);
    }
    void remove_BackColorChanged(Pointer<IEventHandler> delg)
    {
        if (this->BackColorChanged == 0 ) return;
        this->BackColorChanged->Remove(delg);
        if (this->BackColorChanged->get_Count() == 0) this->BackColorChanged.Unset();
    }
    void add_MouseMove(Pointer<IMouseEventHandler> delg) 
    {
        if (this->MouseMove == 0 ) this->MouseMove = new ArrayList<Pointer<IMouseEventHandler> >;
        this->MouseMove->Add(delg);
    }
    void remove_MouseMove(Pointer<IMouseEventHandler> delg)
    {
        if (this->MouseMove == 0 ) return;
        this->MouseMove->Remove(delg);
        if (this->MouseMove->get_Count() == 0) this->MouseMove.Unset();
    }
    void add_MouseDown(Pointer<IMouseEventHandler> delg)
    {
        if (this->MouseDown == 0 ) this->MouseDown = new ArrayList<Pointer<IMouseEventHandler> >;
        this->MouseDown->Add(delg);
    }
    void remove_MouseDown(Pointer<IMouseEventHandler> delg)
    {
        if (this->MouseDown == 0 ) return;
        this->MouseDown->Remove(delg);
        if (this->MouseDown->get_Count() == 0) this->MouseDown.Unset();
    }
    void add_MouseUp(Pointer<IMouseEventHandler> delg)
    {
        if (this->MouseUp == 0 ) this->MouseUp = new ArrayList<Pointer<IMouseEventHandler> >;
        this->MouseUp->Add(delg);
    }
    void remove_MouseUp(Pointer<IMouseEventHandler> delg)
    {
        if (this->MouseUp == 0 ) return;
        this->MouseUp->Remove(delg);
        if (this->MouseUp->get_Count() == 0) this->MouseUp.Unset();
    }
    void add_MouseEnter(Pointer<IEventHandler> delg)
    {
        if (this->MouseEnter == 0 ) this->MouseEnter = new ArrayList<Pointer<IEventHandler> >;
        this->MouseEnter->Add(delg);
    }
    void remove_MouseEnter(Pointer<IEventHandler> delg)
    {
        if (this->MouseEnter == 0 ) return;
        this->MouseEnter->Remove(delg);
        if (this->MouseEnter->get_Count() == 0) this->MouseEnter.Unset();
    }
    void add_MouseLeave(Pointer<IEventHandler> delg)
    {
        if (this->MouseLeave == 0 ) this->MouseLeave = new ArrayList<Pointer<IEventHandler> >;
        this->MouseLeave->Add(delg);
    }
    void remove_MouseLeave(Pointer<IEventHandler> delg)
    {
        if (this->MouseLeave == 0 ) return;
        this->MouseLeave->Remove(delg);
        if (this->MouseLeave->get_Count() == 0) this->MouseLeave.Unset();
    }
    void add_Click(Pointer<IEventHandler> delg)
    {
        if (this->Click == 0 ) this->Click = new ArrayList<Pointer<IEventHandler> >;
        this->Click->Add(delg);
    }
    void remove_Click(Pointer<IEventHandler> delg)
    {
        if (this->Click == 0 ) return;
        this->Click->Remove(delg);
        if (this->Click->get_Count() == 0) this->Click.Unset();
    }
protected:
    void raise_TextChanged(Pointer<Object> sender, Pointer<EventArgs> e)
    {
        if (this->TextChanged == 0 ) return;
        if ((this->TextChanged)->get_Count() > 0)
        {
            Pointer<IEventHandler> h;
            for (int __h = 0; __h < (this->TextChanged)->get_Count() &&
                (&(h = (this->TextChanged)->get_Item(__h)) || true); __h++) h->Invoke(sender, e);
        }
    }
    void raise_ForeColorChanged(Pointer<Object> sender, Pointer<EventArgs> e)
    {
        if (this->ForeColorChanged == 0 ) return;
        if ((this->ForeColorChanged)->get_Count() > 0) {
            Pointer<IEventHandler> h;
            for (int __h = 0; __h < (this->ForeColorChanged)->get_Count() &&
                (&(h = (this->ForeColorChanged)->get_Item(__h)) || true); __h++) h->Invoke(sender, e);
        }
    }
    void raise_BackColorChanged(Pointer<Object> sender, Pointer<EventArgs> e)
    {
        if (this->BackColorChanged == 0 ) return;
        if ((this->BackColorChanged)->get_Count() > 0) {
            Pointer<IEventHandler> h;
            for (int __h = 0; __h < (this->BackColorChanged)->get_Count() &&
                (&(h = (this->BackColorChanged)->get_Item(__h)) || true); __h++) h->Invoke(sender, e);
        }
    }
    void raise_MouseMove(Pointer<Object> sender, Pointer<MouseEventArgs> e)
    {
        if (this->MouseMove == 0 ) return;
        if ((this->MouseMove)->get_Count() > 0)
        {
            Pointer<IMouseEventHandler> h;
            for (int __h = 0; __h < (this->MouseMove)->get_Count() &&
                (&(h = (this->MouseMove)->get_Item(__h)) || true); __h++) h->Invoke(sender, e);
        }
    }
    void raise_MouseDown(Pointer<Object> sender, Pointer<MouseEventArgs> e)
    {
        if (this->MouseDown == 0 ) return;
        if ((this->MouseDown)->get_Count() > 0)
        {
            Pointer<IMouseEventHandler> h;
            for (int __h = 0; __h < (this->MouseDown)->get_Count() &&
                (&(h = (this->MouseDown)->get_Item(__h)) || true); __h++) h->Invoke(sender, e);
        }
    }
    void raise_MouseUp(Pointer<Object> sender, Pointer<MouseEventArgs> e)
    {
        if (this->MouseUp == 0 ) return;
        if ((this->MouseUp)->get_Count() > 0)
        {
            Pointer<IMouseEventHandler> h;
            for (int __h = 0; __h < (this->MouseUp)->get_Count() &&
                (&(h = (this->MouseUp)->get_Item(__h)) || true); __h++) h->Invoke(sender, e);
        }
    }
    void raise_MouseEnter(Pointer<Object> sender, Pointer<EventArgs> e)
    {
        if (this->MouseEnter == 0 ) return;
        if ((this->MouseEnter)->get_Count() > 0)
        {
            Pointer<IEventHandler> h;
            for (int __h = 0; __h < (this->MouseEnter)->get_Count() &&
                (&(h = (this->MouseEnter)->get_Item(__h)) || true); __h++) h->Invoke(sender, e);
        }
    }
    void raise_MouseLeave(Pointer<Object> sender, Pointer<EventArgs> e) 
    {
        if (this->MouseLeave == 0 ) return;
        if ((this->MouseLeave)->get_Count() > 0)
        {
            Pointer<IEventHandler> h;
            for (int __h = 0; __h < (this->MouseLeave)->get_Count() &&
                (&(h = (this->MouseLeave)->get_Item(__h)) || true); __h++) h->Invoke(sender, e);
        }
    }
    void raise_Click(Pointer<Object> sender, Pointer<EventArgs> e)
    {
        if (this->Click == 0 ) return;
        if ((this->Click)->get_Count() > 0)
        {
            Pointer<IEventHandler> h;
            for (int __h = 0; __h < (this->Click)->get_Count() &&
                (&(h = (this->Click)->get_Item(__h)) || true); __h++) h->Invoke(sender, e);
        }
    }

#include "Form.h"

private:
    Pointer<ArrayList<Pointer<IEventHandler> > > Activated;
    Pointer<ArrayList<Pointer<IEventHandler> > > Deactivate;
public:
    void add_Activated(Pointer<IEventHandler> delg)
    {
        if (this->Activated == 0 ) this->Activated = new ArrayList<Pointer<IEventHandler> >;
        this->Activated->Add(delg);
    }
    void remove_Activated(Pointer<IEventHandler> delg)
    {
        if (this->Activated == 0 ) return;
        this->Activated->Remove(delg);
        if (this->Activated->get_Count() == 0) this->Activated.Unset();
    }
    void add_Deactivate(Pointer<IEventHandler> delg)
    {
        if (this->Deactivate == 0 ) this->Deactivate = new ArrayList<Pointer<IEventHandler> >;
        this->Deactivate->Add(delg);
    }
    void remove_Deactivate(Pointer<IEventHandler> delg)
    {
        if (this->Deactivate == 0 ) return;
        this->Deactivate->Remove(delg);
        if (this->Deactivate->get_Count() == 0) this->Deactivate.Unset();
    }
protected:
    void raise_Activated(Pointer<Object> sender, Pointer<EventArgs> e)
    {
        if (this->Activated == 0 ) return;
        if ((this->Activated)->get_Count() > 0)
        {
            Pointer<IEventHandler> h;
            for (int __h = 0; __h < (this->Activated)->get_Count() &&
                (&(h = (this->Activated)->get_Item(__h)) || true); __h++) h->Invoke(sender, e);
        }
    }
    void raise_Deactivate(Pointer<Object> sender, Pointer<EventArgs> e)
    {
        if (this->Deactivate == 0 ) return;
        if ((this->Deactivate)->get_Count() > 0)
        {
            Pointer<IEventHandler> h;
            for (int __h = 0; __h < (this->Deactivate)->get_Count() &&
                (&(h = (this->Deactivate)->get_Item(__h)) || true); __h++) h->Invoke(sender, e);
        }
    }

#include "Timer.h"

private:
    Pointer<ArrayList<Pointer<IEventHandler> > > Tick;
public:
    void add_Tick(Pointer<IEventHandler> delg) {
        if (this->Tick == 0 ) this->Tick = new ArrayList<Pointer<IEventHandler> >;
        this->Tick->Add(delg);
    }
    void remove_Tick(Pointer<IEventHandler> delg) {
        if (this->Tick == 0 ) return;
        this->Tick->Remove(delg);
        if (this->Tick->get_Count() == 0) this->Tick.Unset();
    }
protected:
    void raise_Tick(Pointer<Object> sender, Pointer<EventArgs> e)
    {
        if (this->Tick == 0 ) return;
        if ((this->Tick)->get_Count() > 0)
        {
            Pointer<IEventHandler> h;
            for (int __h = 0; __h < (this->Tick)->get_Count() &&
                (&(h = (this->Tick)->get_Item(__h)) || true); __h++) h->Invoke(sender, e);
        }
    }