2020-03-05 06:44:53 +00:00
|
|
|
#include <Array.h>
|
|
|
|
#include "event.h"
|
2020-03-19 02:32:44 +00:00
|
|
|
#include "qwaq-draw.h"
|
2020-03-19 02:04:02 +00:00
|
|
|
#include "qwaq-garray.h"
|
2020-03-05 06:44:53 +00:00
|
|
|
#include "qwaq-group.h"
|
2020-03-19 02:32:44 +00:00
|
|
|
#include "qwaq-view.h"
|
2020-03-05 06:44:53 +00:00
|
|
|
|
|
|
|
@implementation Group
|
2020-03-14 10:45:07 +00:00
|
|
|
|
2020-03-19 07:27:30 +00:00
|
|
|
-initWithContext: (id<TextContext>) context owner: (View *) owner
|
2020-03-05 06:44:53 +00:00
|
|
|
{
|
|
|
|
if (!(self = [super init])) {
|
|
|
|
return nil;
|
|
|
|
}
|
2020-03-19 07:27:30 +00:00
|
|
|
self.owner = owner;
|
2020-03-19 02:32:44 +00:00
|
|
|
self.context = context;
|
2020-03-19 07:27:30 +00:00
|
|
|
focused = -1;
|
2020-03-05 15:32:09 +00:00
|
|
|
views = [[Array array] retain];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-05 06:44:53 +00:00
|
|
|
-(void)dealloc
|
|
|
|
{
|
|
|
|
[views release];
|
|
|
|
}
|
|
|
|
|
|
|
|
-insert: (View *) view
|
|
|
|
{
|
2020-03-06 02:53:40 +00:00
|
|
|
[views addObject: view];
|
2020-03-19 10:00:03 +00:00
|
|
|
[view setOwner: self];
|
2020-03-19 02:32:44 +00:00
|
|
|
[view setContext: context];
|
2020-03-05 06:44:53 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-remove: (View *) view
|
|
|
|
{
|
|
|
|
int index = [views indexOfObject: view];
|
|
|
|
if (index != NotFound) {
|
|
|
|
if (focused == index) {
|
|
|
|
focused = -1;
|
|
|
|
} else if (focused > index) {
|
|
|
|
focused--;
|
|
|
|
}
|
|
|
|
[views removeObjectAtIndex: index];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-19 12:28:55 +00:00
|
|
|
-(Rect) rect
|
|
|
|
{
|
|
|
|
if (owner) {
|
|
|
|
return [owner rect];
|
|
|
|
}
|
|
|
|
return {[self origin], [self size]};
|
|
|
|
}
|
|
|
|
|
|
|
|
-(Point) origin
|
|
|
|
{
|
|
|
|
if (owner) {
|
|
|
|
return [owner origin];
|
|
|
|
}
|
|
|
|
return {0, 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
-(Extent) size
|
|
|
|
{
|
|
|
|
if (owner) {
|
|
|
|
return [owner size];
|
|
|
|
}
|
|
|
|
return [context size];
|
|
|
|
}
|
|
|
|
|
2020-03-06 02:53:40 +00:00
|
|
|
static BOOL
|
|
|
|
not_dont_draw (id aView, void *aGroup)
|
|
|
|
{
|
|
|
|
View *view = aView;
|
|
|
|
Group *group = (Group *) aGroup;
|
2020-03-14 10:45:07 +00:00
|
|
|
|
2020-03-19 02:32:44 +00:00
|
|
|
return !([view options] & ofDontDraw);
|
2020-03-06 02:53:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 06:44:53 +00:00
|
|
|
-draw
|
|
|
|
{
|
2020-03-06 02:53:40 +00:00
|
|
|
[views makeObjectsPerformSelector: @selector(draw)
|
|
|
|
if: not_dont_draw
|
|
|
|
with: self];
|
2020-03-05 06:44:53 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-19 02:32:44 +00:00
|
|
|
-redraw
|
|
|
|
{
|
2020-03-19 09:39:11 +00:00
|
|
|
if (owner) {
|
|
|
|
[owner redraw];
|
|
|
|
} else {
|
|
|
|
[self draw];
|
|
|
|
if (__obj_responds_to (context, @selector(refresh))) {
|
|
|
|
[(id)context refresh];
|
|
|
|
}
|
|
|
|
}
|
2020-03-19 02:32:44 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-19 06:55:57 +00:00
|
|
|
static View *
|
|
|
|
find_mouse_view(Group *group, Point pos)
|
|
|
|
{
|
|
|
|
for (int i = [group.views count]; i--; ) {
|
|
|
|
View *v = [group.views objectAtIndex: i];
|
|
|
|
if ([v containsPoint: pos]) {
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2020-03-05 06:44:53 +00:00
|
|
|
-handleEvent: (qwaq_event_t *) event
|
|
|
|
{
|
|
|
|
if (event.what & qe_focused) {
|
|
|
|
if (focused >= 0) {
|
|
|
|
[[views objectAtIndex:focused] handleEvent: event];
|
|
|
|
}
|
|
|
|
} else if (event.what & qe_positional) {
|
2020-03-19 09:40:21 +00:00
|
|
|
Point origin = {};
|
|
|
|
if (owner) {
|
|
|
|
origin = [owner origin];
|
|
|
|
}
|
|
|
|
event.mouse.x -= origin.x;
|
|
|
|
event.mouse.y -= origin.y;
|
2020-03-19 06:55:57 +00:00
|
|
|
Point pos = {event.mouse.x, event.mouse.y};
|
|
|
|
if (mouse_grabbed) {
|
|
|
|
[mouse_grabbed handleEvent: event];
|
|
|
|
} else {
|
|
|
|
if (mouse_within && ![mouse_within containsPoint: pos]) {
|
|
|
|
[mouse_within onMouseLeave: pos];
|
|
|
|
mouse_within = nil;
|
|
|
|
}
|
|
|
|
if (!mouse_within) {
|
|
|
|
mouse_within = find_mouse_view (self, pos);
|
|
|
|
if (mouse_within) {
|
|
|
|
[mouse_within onMouseEnter: pos];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mouse_within) {
|
|
|
|
[mouse_within handleEvent: event];
|
|
|
|
}
|
|
|
|
}
|
2020-03-19 09:40:21 +00:00
|
|
|
event.mouse.x += origin.x;
|
|
|
|
event.mouse.y += origin.y;
|
2020-03-05 06:44:53 +00:00
|
|
|
} else {
|
|
|
|
// broadcast
|
|
|
|
[views makeObjectsPerformSelector: @selector(draw) withObject: event];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
2020-03-19 07:27:30 +00:00
|
|
|
|
|
|
|
-(void) grabMouse
|
|
|
|
{
|
|
|
|
mouse_grabbed = mouse_within;
|
|
|
|
[owner grabMouse];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) releaseMouse
|
|
|
|
{
|
2020-03-19 10:00:03 +00:00
|
|
|
mouse_grabbed = nil;
|
|
|
|
[owner releaseMouse];
|
2020-03-19 07:27:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 06:44:53 +00:00
|
|
|
@end
|