2020-02-29 15:40:55 +00:00
|
|
|
#include "qwaq-curses.h"
|
2020-03-24 04:33:28 +00:00
|
|
|
#include "qwaq-listener.h"
|
2020-02-29 15:40:55 +00:00
|
|
|
#include "qwaq-view.h"
|
2020-03-05 06:44:53 +00:00
|
|
|
#include "qwaq-group.h"
|
2020-02-29 15:40:55 +00:00
|
|
|
|
|
|
|
@implementation View
|
|
|
|
|
2020-03-05 15:32:09 +00:00
|
|
|
-init
|
|
|
|
{
|
2020-03-24 04:33:28 +00:00
|
|
|
if (!(self = [super init])) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
onReceiveFocus = [[ListenerGroup alloc] init];
|
|
|
|
onReleaseFocus = [[ListenerGroup alloc] init];
|
|
|
|
return self;
|
2020-03-05 15:32:09 +00:00
|
|
|
}
|
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
-initWithRect: (Rect) rect
|
|
|
|
{
|
|
|
|
if (!(self = [super init])) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
self.rect = rect;
|
|
|
|
self.absRect = rect;
|
2020-03-24 04:33:28 +00:00
|
|
|
onReceiveFocus = [[ListenerGroup alloc] init];
|
|
|
|
onReleaseFocus = [[ListenerGroup alloc] init];
|
2020-02-29 15:40:55 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-05 06:44:53 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
if (owner) {
|
|
|
|
[owner remove:self];
|
|
|
|
}
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2020-03-19 02:32:44 +00:00
|
|
|
- setContext: (id<TextContext>) context
|
|
|
|
{
|
|
|
|
textContext = context;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) options
|
|
|
|
{
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2020-03-24 04:33:28 +00:00
|
|
|
- (int) state
|
|
|
|
{
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2020-03-05 06:44:53 +00:00
|
|
|
static void
|
|
|
|
updateScreenCursor (View *view)
|
|
|
|
{
|
2020-03-24 04:34:45 +00:00
|
|
|
// XXX this does not work
|
|
|
|
/* while ((view.state & sfInFocus) && view.owner) {
|
2020-03-05 06:44:53 +00:00
|
|
|
View *owner = (View *) view.owner;
|
|
|
|
if (view.cursor.x >= 0 && view.cursor.x < view.xlen
|
|
|
|
&& view.cursor.y >= 0 && view.cursor.y < view.ylen) {
|
|
|
|
owner.cursor.x = view.cursor.x + view.xpos;
|
|
|
|
owner.cursor.y = view.cursor.y + view.ypos;
|
|
|
|
owner.cursorState = view.cursorState;
|
|
|
|
} else {
|
|
|
|
owner.cursorState = 0;
|
|
|
|
}
|
|
|
|
view = owner;
|
|
|
|
}
|
|
|
|
if (view.state & sfInFocus) {
|
|
|
|
if (view.cursor.x >= 0 && view.cursor.x < view.xlen
|
|
|
|
&& view.cursor.y >= 0 && view.cursor.y < view.ylen) {
|
|
|
|
curs_set (view.cursorState);
|
|
|
|
move(view.cursor.x, view.cursor.y);
|
|
|
|
} else {
|
|
|
|
curs_set (0);
|
|
|
|
}
|
2020-03-24 04:34:45 +00:00
|
|
|
}*/
|
2020-03-05 06:44:53 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 06:22:54 +00:00
|
|
|
-draw
|
2020-02-29 15:40:55 +00:00
|
|
|
{
|
2020-03-05 06:44:53 +00:00
|
|
|
state |= sfDrawn;
|
|
|
|
updateScreenCursor (self);
|
2020-02-29 15:40:55 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-05 06:44:53 +00:00
|
|
|
-hide
|
2020-03-03 12:30:47 +00:00
|
|
|
{
|
2020-03-05 06:44:53 +00:00
|
|
|
if (state & sfDrawn) {
|
|
|
|
state &= ~sfDrawn;
|
|
|
|
updateScreenCursor (self);
|
|
|
|
}
|
2020-03-03 12:30:47 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-redraw
|
|
|
|
{
|
2020-03-05 06:44:53 +00:00
|
|
|
if ((state & sfDrawn) && !(options & ofDontDraw)) {
|
|
|
|
[self draw];
|
|
|
|
[owner redraw];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-setOwner: (Group *) owner
|
|
|
|
{
|
|
|
|
self.owner = owner;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-23 13:08:30 +00:00
|
|
|
-setGrowMode: (int) mode
|
|
|
|
{
|
|
|
|
growMode = mode;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-19 06:55:57 +00:00
|
|
|
- (Rect) rect
|
2020-03-05 06:44:53 +00:00
|
|
|
{
|
2020-03-19 06:55:57 +00:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2020-03-19 09:38:24 +00:00
|
|
|
-(Point)origin
|
|
|
|
{
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(Extent)size
|
|
|
|
{
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-19 06:55:57 +00:00
|
|
|
-(int) containsPoint: (Point) point
|
|
|
|
{
|
|
|
|
return rectContainsPoint (rect, point);
|
2020-03-03 12:30:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 07:27:30 +00:00
|
|
|
-(void) grabMouse
|
|
|
|
{
|
|
|
|
[owner grabMouse];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) releaseMouse
|
|
|
|
{
|
|
|
|
[owner releaseMouse];
|
|
|
|
}
|
|
|
|
|
2020-03-09 17:58:30 +00:00
|
|
|
- (void) forward: (SEL) sel : (@va_list) args
|
2020-03-06 08:25:19 +00:00
|
|
|
{
|
2020-03-09 17:58:30 +00:00
|
|
|
if (!textContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!__obj_responds_to (textContext, sel)) {
|
|
|
|
[self error: "no implementation for %s", sel_get_name (sel)];
|
|
|
|
}
|
|
|
|
obj_msg_sendv (textContext, sel, args);
|
2020-03-06 08:25:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) refresh
|
|
|
|
{
|
2020-03-17 16:39:12 +00:00
|
|
|
if (__obj_responds_to (textContext, @selector(refresh))) {
|
|
|
|
[(id)textContext refresh];
|
|
|
|
}
|
2020-03-06 08:25:19 +00:00
|
|
|
}
|
2020-03-06 08:57:33 +00:00
|
|
|
|
2020-03-06 08:25:19 +00:00
|
|
|
- (void) mvprintf: (Point) pos, string fmt, ...
|
|
|
|
{
|
|
|
|
pos.x += xpos;
|
|
|
|
pos.y += ypos;
|
|
|
|
[textContext mvvprintf: pos, fmt, @args];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mvvprintf: (Point) pos, string fmt, @va_list args
|
|
|
|
{
|
|
|
|
pos.x += xpos;
|
|
|
|
pos.y += ypos;
|
|
|
|
[textContext mvvprintf: pos, fmt, args];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mvaddch: (Point) pos, int ch
|
|
|
|
{
|
|
|
|
pos.x += xpos;
|
|
|
|
pos.y += ypos;
|
|
|
|
[textContext mvaddch: pos, ch];
|
|
|
|
}
|
|
|
|
|
2020-03-23 11:14:32 +00:00
|
|
|
-move: (Point) delta
|
|
|
|
{
|
|
|
|
xpos += delta.x;
|
|
|
|
ypos += delta.y;
|
|
|
|
if (xpos + xlen < 1) {
|
|
|
|
xpos = 1 - xlen;
|
|
|
|
}
|
|
|
|
if (ypos < 0) {
|
|
|
|
ypos = 0;
|
|
|
|
}
|
|
|
|
if (owner) {
|
|
|
|
Extent s = [owner size];
|
|
|
|
if (xpos > s.width - 1) {
|
|
|
|
xpos = s.width - 1;
|
|
|
|
}
|
|
|
|
if (ypos > s.height - 1) {
|
|
|
|
ypos = s.height - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-resize: (Extent) delta
|
|
|
|
{
|
|
|
|
xlen += delta.width;
|
|
|
|
ylen += delta.height;
|
|
|
|
if (xlen < 1) {
|
|
|
|
xlen = 1;
|
|
|
|
}
|
|
|
|
if (ylen < 1) {
|
|
|
|
ylen = 1;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-25 05:39:37 +00:00
|
|
|
-move:(Point)dpos andResize:(Extent)dsize
|
|
|
|
{
|
|
|
|
[self move: dpos];
|
|
|
|
[self resize: dsize];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-23 11:14:32 +00:00
|
|
|
-grow: (Extent) delta
|
|
|
|
{
|
|
|
|
Point dpos = {};
|
|
|
|
Extent dsize = {};
|
|
|
|
|
|
|
|
if (growMode & gfGrowLoX) {
|
|
|
|
dpos.x += delta.width;
|
|
|
|
dsize.width -= delta.width;
|
|
|
|
}
|
|
|
|
if (growMode & gfGrowHiX) {
|
|
|
|
dsize.width += delta.width;
|
|
|
|
}
|
|
|
|
if (growMode & gfGrowLoY) {
|
|
|
|
dpos.y += delta.height;
|
|
|
|
dsize.height -= delta.height;
|
|
|
|
}
|
|
|
|
if (growMode & gfGrowHiY) {
|
|
|
|
dsize.height += delta.height;
|
|
|
|
}
|
|
|
|
int save_state = state;
|
|
|
|
state &= ~sfDrawn;
|
2020-03-25 05:39:37 +00:00
|
|
|
[self move: dpos andResize: dsize];
|
2020-03-23 11:14:32 +00:00
|
|
|
state = save_state;
|
|
|
|
[self redraw];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-14 10:45:07 +00:00
|
|
|
-handleEvent: (qwaq_event_t *) event
|
|
|
|
{
|
2020-03-24 04:33:28 +00:00
|
|
|
if (event.what & (qe_mousedown | qe_mouseclick)
|
|
|
|
&& options & ofCanFocus && !(state & (sfDisabled | sfInFocus))) {
|
|
|
|
[owner selectView: self];
|
|
|
|
if (!(options & ofFirstClick)) {
|
|
|
|
event.what = qe_none;
|
|
|
|
}
|
|
|
|
}
|
2020-03-14 10:45:07 +00:00
|
|
|
return self;
|
|
|
|
}
|
2020-02-29 15:40:55 +00:00
|
|
|
|
2020-03-24 04:33:28 +00:00
|
|
|
-takeFocus
|
|
|
|
{
|
|
|
|
state |= sfInFocus;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-loseFocus
|
|
|
|
{
|
|
|
|
state &= ~sfInFocus;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(ListenerGroup *) onReceiveFocus
|
|
|
|
{
|
|
|
|
return onReceiveFocus;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(ListenerGroup *) onReleaseFocus
|
|
|
|
{
|
|
|
|
return onReleaseFocus;
|
|
|
|
}
|
|
|
|
|
2020-03-26 02:18:00 +00:00
|
|
|
-raise
|
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-19 06:55:57 +00:00
|
|
|
- (void) onMouseEnter: (Point) pos
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) onMouseLeave: (Point) pos
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-12 17:46:25 +00:00
|
|
|
@end
|