Every object is derived from an abstract object, XObject. It have an
object id associated to it. The library itself maintain a internal table of
instantiated classes. It knows how to send a message to a specific object,
too. There are three types of objects:
- abstract objects, which cannot be instantiated, but only declared. It's
purpose is to provide a general manipulation to a class of objects;
- passive objects, which only displays something, but the user cannot
control them;
- active objects, which the user can do something with them, and which
knows to answer in a way to the user input.
class XObject {
unsigned id; // object's id
XPoint origin, size, cursor; // origin relative to the server, size, cursor position
XRect bounds; // these are the real bounds, in absolute coordinates
XObject *server, *client;
unsigned state;
XObject(XRect _bounds);
virtual void calculateBounds();
virtual void draw();
virtual void handleEvent(XEvent *); // draw the object on the screen
virtual void registerClient(XObject *newClient);
...
}
Each object have a 'state' field associated with it, which indicates the
current properties of the object. Some possible values are:
- SM_VISIBLE indicates that the object is visible on the screen, so it is in
a drawn state;
- SM_FOCUSED indicates that the object have the control at the respective
moment (oly one object can have the control at a moment, so if the user
press, let's say, a key, this object will receive the event);
- SM_DISABLED indicates that the object is deactivated at a moment;
- SM_ACTIVE indicates that the object is active, so the user have a control
to it.
The 'server' field points to the server (owner) of the object, or NULL if
object have no server or it's a server itself.
The 'client' field is a linked list of registered clients of the object (if
he is a server).
If the object is a server (a dialog box, for example), you can insert a
client in it with 'registerClient()' method. This will register the new
client and will adjust his bounds (which are relative to the server). When
the 'draw()' method is called, the server will automatically draw all his
clients. When an event is passed to the server, he'll automatically ask it's
clients to treat the event.
The events are not passed sincronously to the objects to which are
addressed, but using a event queue. That doesn't mean the events will be
delayed, anyway. The application will automatically query the system for
events (from keyboard, from mouse, messages from other objects, UNIX
signals), will find the object that event is addressed to, and will insert
them into the queue.
The structure of an event looks like this:
struct XEvent {
unsigned oid; // object that event appart to
unsigned what; // type of event
struct ev_mouse { // an event from mouse
int buttons;
unsigned dbl;
XPoint where;
} evMouse;
struct ev_keyboard { // an event from keyboard
int keyCode;
char charCode;
unsigned char scanCode;
} evKeyboard;
XMessage evMessage; // a message
}
struct XMessage {
unsigned sid, rid; // Sender and Receiver's ID
unsigned msgClass; // message class
int message;
char *msgText;
void *ptr;
}
Message classes:
- MC_CLIENTTOSERVER, from a client to a server;
- MC_CLIENTTOCLIENT, from a client to another client;
- MC_SERVERTOCLIENT, from a server to a client;
- MC_BROADCAST, broadcast message which is sent to all the objects.
Basically message texts:
- MT_ANSWERREQUEST, used by a server to ask something from a client;
- MT_REQUESTHONORED, used by a client do answer to a server request;
- MT_RELEASEFOCUS, used by a server to ask a client to release the focus
(the client will loose the user control);
- MT_RESUMEFOCUS, used by a server to ask a client to resume the focus (the
client will gain the user control).
Type of events:
- EV_NOTHING, no event for an object;
- EV_MOUSE, an event from mouse;
- EV_kEYBOARD, an event from keyboard;
- EV_MESSAGE, a message from an other object.
A message to an object is, in fact, an event that points to it. The
messages are very important in Xterminal. In fact, Xterminal is based on the
communications between objects.
Conclusions and future work
The latest version of Xterminal may be found on sunsite.unc.edu ftp server,
in /pub/Linux/libs. Further work will be to develop a graphical user interface
for Linux, and to finish the whole object hierarchy.
Xterminal's Hierarchy
Xterminal
|
+- XObject
| +- XtDialog ---- XtDialogBox
| +- XtWindow ---- XtTextEditor
| +- XtButton
| +- XtInputStringField
| +- XtStaticText
| +- XtScrollBar
| +- XtProgressbar
| +- XtBackground
| +- XtDesktop
| +- XtApplication
| +- XtCheckButton
| +- XtRadioButton
| +- XtListBox
| +- XtStatusItem ---- XtStatusLine
| +- XtMenuItem ---- XtSubMenu ---- XtMenu
+- XPoint
+- XRect
+- XMessage
Note: this text was published in
ROSE'96 Proceedings (Technical Sessions) Book, p. 59-63.
You can also read the speech I had.