button .b -text "Hello, world" -command {
puts stdout "hello world"
}
pack .b
interface event { \fbox{event}
int type(); \c{ X event type }
char* name(); \c{type as string}
int x();
int y();
...
void* rawevent(); \c{delivers} raw X event
};
interface event { \fbox{event}
int type(); \c{// X event type }
char* name(); \c{// type as string}
int x();
int y();
int button(int i = 0); \c{// ButtonPress}
int buttonup(int i = 0); \c{// ButtonRelease}
int motion(); \c{// MotionNotify}
int keyevent(); \c{// KeyPress or KeyRelease}
int buttonevent(int i = 0); \c{// ButtonPress or Release}
int keycode();
void trace(); \c{// prints event information}
void* rawevent(); // \c{delivers} raw X event
};
client
class client { }; empty class
command
typedef command(client*, kit*, int argc, char* argv[]);
interface action { \fbox{action}
action(char* name);
action(char* name, handler* h);
action(char* name, command f, client* data = 0);
action(char* name, tcl_command f, ClientData data = 0);
action( handler* h); \ifsli{}{//} anonymous
action( command f, client* data = 0);
action( tcl_command f, ClientData data = 0);
char* name(); \c{// returns the name of an action}
};
class move_handler : public handler { \fbox{move_handler}
public:
move_handler( canvas* cv ) : c(cv) { dragging = 0; }
void press( event& e ) {
x = e.x(); y = e.y();
id = c->overlapping(x, y);
if (id) dragging = 1;
}
void motion( event& e ) {
if (dragging) {
id.move( e.x() - x, e.y() - y );
x = e.x(); y = e.y();
}
}
void release( event& ) { dragging = 0; }
protected:
canvas* c; int dragging; item id; int x,y;
};
c->rectangle(x,y,e.x(),e.y());