UPLOAD - DOSUIT07.ZIP - CLUSTER.HPP

 
Output of file : CLUSTER.HPP contained in archive : DOSUIT07.ZIP

// Clusters - Groups with automatic placing (and optional border)
#ifndef CLUSTER_HPP
#define CLUSTER_HPP

#ifndef GROUP_HPP
#include "group.hpp"
#endif

/*
The Cluster is the basis of the automatic layout of VObjects on the
screen. This is the base class for the different types of Cluster you
will actually use - e.g. the HCluster (for horizontal rows of
VObjects), and the VCluster (for vertical columns of VObjects).
*/
class Cluster : public Group {
public:
Cluster(AlignFlag a,const char *n = "Cluster",BorderFlag f = BFnone);

BorderFlag testbFlag(BorderFlag f) const { return BorderFlag (bflags & f); }

virtual void realign(int resize = 0) = 0;

virtual void setwidth(const coord w);
virtual void setheight(const coord h);
virtual void paint(Rectangle r);
virtual int setfocus(int tabstop = 1); // 1 if will accept focus, else 0
virtual void resetfocus();
virtual char *inspectinfo(char *buffer = 0,const char *s = 0) const;

//~ Adding VObjects
virtual void addDone();
Cluster& operator+ (const ObjectCollection &c)
{ add(c); return *this; };
Cluster& operator+ (const ObjectCollection *c)
{ add(*c); return *this; }
Cluster& operator+ (VObject *c)
{ add(c); return *this; }

protected:
AlignFlag alignment;

private:
BorderFlag bflags;
};

/*
A Cluster of VObjects automatically laid out in a horizontal row.
The VObjects to be laid out are passed in an ObjectCollection.
ObjectCollection has an addition operator provided which enables a
list of VObjects to be created during the call to the constructor.

For example, an HCluster might be created as follows ...
HCluster *h = new HCluster(ObjectCollection(3)
+ new TextEdit(string, 10, "Enter me")
+ new Button("~Push me")
+ new Text("Text item")
);

This construct is useful, because it allows nested clusters to be
constructed with a single statement. With sensible indentation, it is
easy to see how the different VObjects relate to one another, and how
they will be laid out on the screen.
*/
class HCluster : public Cluster {
friend class RCluster; // allows RowClusters to add items efficiently
public:
// vararg constructors are obsolete.
HCluster(VObject *v,...)/*!*/;
HCluster(AlignFlag a,VObject *v,...)/*!*/;
HCluster(const char *name,AlignFlag a,VObject *v,...)/*!*/;
HCluster(const char *name,AlignFlag a,BorderFlag f,VObject *v,...)/*!*/;

HCluster(const char *name = "HCluster",AlignFlag a = AFexpand,
BorderFlag f = BFnone);
HCluster(const ObjectCollection &contents, const char *name,
AlignFlag a = AFexpand,BorderFlag f = BFnone);
HCluster(const ObjectCollection &contents,
AlignFlag a = AFexpand,BorderFlag f = BFnone);

virtual void realign(int resize = 0);
virtual coord minwidth() const;
virtual coord minheight() const;
virtual coord maxwidth() const;
virtual coord maxheight() const;
virtual int kbdevent(KeyboardEvent& e);
};

/*
A Cluster of VObjects automatically laid out in a vertical column.
The VObjects to be laid out are passed in an ObjectCollection.
ObjectCollection has an addition operator provided which enables a
list of VObjects to be created during the call to the constructor.

For example, a VCluster might be created as follows ...
VCluster *v = new VCluster(ObjectCollection(3)
+ new TextEdit(string, 10, "Enter me")
+ new Button("~Push me")
+ new Text("Text item")
);

This construct is useful, because it allows nested clusters to be
constructed with a single statement. With sensible indentation, it is
easy to see how the different VObjects relate to one another, and how
they will be laid out on the screen.
*/
class VCluster : public Cluster {
friend class CCluster; // allows ColumnClusters to add items efficiently
public:
// vararg constructors are obsolete
VCluster(VObject *v,...)/*!*/;
VCluster(AlignFlag a,VObject *v,...)/*!*/;
VCluster(const char *name,AlignFlag a,VObject *v,...)/*!*/;
VCluster(const char *name,AlignFlag a,BorderFlag f,VObject *v,...)/*!*/;

VCluster(const char *name = "VCluster",AlignFlag a = AFexpand,
BorderFlag f = BFnone);
VCluster(const ObjectCollection &contents, const char *name,
AlignFlag a = AFexpand,BorderFlag f = BFnone);
VCluster(const ObjectCollection &contents,
AlignFlag a = AFexpand,BorderFlag f = BFnone);

virtual void realign(int resize = 0);
virtual coord minwidth() const;
virtual coord minheight() const;
virtual coord maxwidth() const;
virtual coord maxheight() const;
virtual int kbdevent(KeyboardEvent& e);
};

/*
A Cluster of VObjects automatically laid out in columns.
The VObjects to be laid out are passed in an ObjectCollection.
ObjectCollection has an addition operator provided which enables a
list of VObjects to be created during the call to the constructor.
*/
class CCluster : public HCluster {
int nitems;
void build(const ObjectCollection &contents);
protected:
virtual void add1(VObject *v); // Add object without resizing
virtual int remove1(VObject *v);// Remove object without resizing
public:
CCluster(int rowsPerColumn = 2, const char *name = "CCluster",
AlignFlag a = AFexpand, BorderFlag f = BFnone);
CCluster(const ObjectCollection &contents, int rowsPerColumn,
const char *name, AlignFlag a = AFexpand,BorderFlag f = BFnone);
CCluster(const ObjectCollection &contents, int rowsPerColumn = 2,
AlignFlag a = AFexpand,BorderFlag f = BFnone);

virtual void realign(int resize = 0);
};

/*
A Cluster of VObjects automatically laid out in rows.
The VObjects to be laid out are passed in an ObjectCollection.
ObjectCollection has an addition operator provided which enables a
list of VObjects to be created during the call to the constructor.
*/
class RCluster : public VCluster {
int nitems;
void build(const ObjectCollection &contents);
protected:
virtual void add1(VObject *v); // Add object without resizing
virtual int remove1(VObject *v);// Remove object without resizing
public:
RCluster(int columnsPerRow = 2, const char *name = "RCluster",
AlignFlag a = AFexpand, BorderFlag f = BFnone);
RCluster(const ObjectCollection &contents, int columnsPerRow,
const char *name, AlignFlag a = AFexpand,BorderFlag f = BFnone);
RCluster(const ObjectCollection &contents, int columnsPerRow = 2,
AlignFlag a = AFexpand,BorderFlag f = BFnone);

virtual void realign(int resize = 0);
};

#endif