Exemplo n.º 1
0
static void
handle_event(XEvent * event)
{
    XWindowAttributes wa;
/*    fprintf(stderr,"event:handle_event entered\n");*/
    set_window(event->xany.window);
    if (event->type == MotionNotify) {
/*        fprintf(stderr,"event:handle_event type=MotionNotify\n");*/
        handle_motion_event((XMotionEvent *)event);
        motion = 1;
        return;
    }
    make_busy_cursors();
    switch (event->type) {
      case DestroyNotify:
/*        fprintf(stderr,"event:handle_event type=DestroyNotify\n");*/
        break;
      case Expose:
/*        fprintf(stderr,"event:handle_event type=Expose\n");*/
        XGetWindowAttributes(gXDisplay, gWindow->fMainWindow, &wa);
        if ((gWindow->width == 0 && gWindow->height == 0) ||
            (wa.width != gWindow->width || wa.height != gWindow->height)) {
            gWindow->width = wa.width;
            gWindow->height = wa.height;
            display_page(gWindow->page);
            gWindow->fWindowHashTable = gWindow->page->fLinkHashTable;
        }
        else                    /** just redraw the thing **/
            expose_page(gWindow->page);
        XFlush(gXDisplay);
        clear_exposures(gWindow->fMainWindow);
        clear_exposures(gWindow->fScrollWindow);
        break;
      case ButtonPress:
/*        fprintf(stderr,"event:handle_event type=ButtonPress\n");*/
        handle_button(event->xbutton.button, (XButtonEvent *)event);
        XFlush(gXDisplay);
        if (gWindow) {
            while (XCheckTypedWindowEvent(gXDisplay, gWindow->fMainWindow,
                                          Expose, event));
            while (XCheckTypedWindowEvent(gXDisplay, gWindow->fScrollWindow,
                                          Expose, event));
        }
        break;
      case KeyPress:
/*        fprintf(stderr,"event:handle_event type=KeyPress\n");*/
        handle_key(event);
        if (gWindow) {
            while (XCheckTypedWindowEvent(gXDisplay, gWindow->fMainWindow,
                                          Expose, event));
            while (XCheckTypedWindowEvent(gXDisplay, gWindow->fScrollWindow,
                                          Expose, event));
        }
        break;
      case MapNotify:
/*        fprintf(stderr,"event:handle_event type=MapNotify\n");*/
        create_window();
        break;

      case SelectionNotify:
/*        fprintf(stderr,"event:handle_event type=SelectionNotify\n");*/
        /* this is in response to a previous request in an input area */
        if ( gSavedInputAreaLink ) {
            XSelectionEvent *pSelEvent;
            Atom dataProperty;
            pSelEvent = (XSelectionEvent *) event;
            dataProperty = XInternAtom(gXDisplay, "PASTE_SELECTION", False);
            /* change the input focus */

        /*  change_input_focus(gSavedInputAreaLink); */

            /* try to get the selection as a window property */

            if ( pSelEvent->requestor == gWindow->fMainWindow &&
                 pSelEvent->selection == XA_PRIMARY &&
            /*   pSelEvent->time      == CurrentTime && */
                 pSelEvent->target    == XA_STRING &&
                 pSelEvent->property == dataProperty )
            {
                Atom actual_type;
                int  actual_format;
                unsigned long nitems, leftover;
                char *pSelection = NULL;

                if (Success == XGetWindowProperty(gXDisplay,
                    gWindow->fMainWindow,
                    pSelEvent->property, 0L, 100000000L, True,
                    AnyPropertyType, &actual_type, &actual_format,
                    &nitems, &leftover, (unsigned char **) &pSelection) )
                {
                    char *pBuffer;
                    InputItem *item = gSavedInputAreaLink->reference.string;

                    for (pBuffer = pSelection; *pBuffer; ++pBuffer)
                        add_buffer_to_sym(pBuffer, item);

                    XFree(pSelection);
                }
            }

            /* clear the link info */

            gSavedInputAreaLink = NULL;
        }
        break;

      default:
/*        fprintf(stderr,"event:handle_event type=default\n");*/
        break;
    }

}
Exemplo n.º 2
0
int
read_seq_write_rand(command_list *cl, DCB_registered_src *r_src, unsigned char is_overlay, cfile *out_cfh, unsigned long buf_size)
{
	unsigned char *buf;
	unsigned char *p;
	unsigned long x, start=0, end=0, len=0;
	unsigned long max_pos = 0, pos = 0;
	unsigned long offset;
	signed long tmp_len;
	dcb_src_read_func read_func;
	cfile_window *cfw;
	u_dcb_src u_src;
	
	#define END_POS(x) ((x).src_pos + (x).len)
	pos = 0;
	max_pos = 0;

	if(is_overlay) {
		read_func = r_src->mask_read_func;
	} else {
		read_func = r_src->read_func;
	}
	assert(read_func != NULL);
	u_src = r_src->src_ptr;
	if(0 != cseek(u_src.cfh, 0, CSEEK_FSTART)) {
		ap_printf("cseeked failed: bailing, io_error 0\n");
		return IO_ERROR;
	}

	if((buf = (unsigned char *)malloc(buf_size)) == NULL) {
		return MEM_ERROR;
	}

	// we should *never* go backwards
	u_src.cfh->state_flags |= CFILE_FLAG_BACKWARD_SEEKS;		

	while(start < cl->com_count) {
		if(pos < cl->full_command[start].src_pos) {
			pos = cl->full_command[start].src_pos;
			max_pos = END_POS(cl->full_command[start]);
		} else {
			while(start < cl->com_count && pos > cl->full_command[start].src_pos) {
				start++;
			}
			if(start == cl->com_count)
				continue;
			pos = cl->full_command[start].src_pos;
			max_pos = MAX(max_pos, END_POS(cl->full_command[start]));
		}
		if(end < start) {
			end = start;
		}
		while(end < cl->com_count && cl->full_command[end].src_pos < max_pos) {
			max_pos = MAX(max_pos, END_POS(cl->full_command[end]));
			end++;
		}
		if(pos == max_pos) {
			continue;
		}
		while(pos < max_pos) {
			len = MIN(max_pos - pos, buf_size);
			x = read_func(u_src, pos, buf, len);
//			if(len < max_pos - pos)
//				v0printf("buffered %lu, max was %lu\n", len, max_pos - pos);
			if(len != x){
				ap_printf("x=%lu, pos=%lu, len=%lu\n", x, pos, len);
				ap_printf("bailing, io_error 2\n");
				free(buf);
				return IO_ERROR;
			}
			for(x=start; x < end; x++) {
				offset = MAX(cl->full_command[x].src_pos, pos);
				tmp_len = MIN(END_POS(cl->full_command[x]), pos + len) - offset;
					
				if(tmp_len > 0) { 
					if(cl->full_command[x].ver_pos + (offset - cl->full_command[x].src_pos) !=
						cseek(out_cfh, cl->full_command[x].ver_pos + (offset - cl->full_command[x].src_pos),
						CSEEK_FSTART)) {
						ap_printf("bailing, io_error 3\n");
						free(buf);
						return IO_ERROR;
					}
					if(is_overlay) {
						p = buf + offset - pos;
						cfw = expose_page(out_cfh);
						if(cfw->write_end == 0) {
							cfw->write_start = cfw->pos;
						}
						while(buf + offset - pos + tmp_len > p) {
							if(cfw->pos == cfw->end) {
								cfw->write_end = cfw->end;
								cfw = next_page(out_cfh);
								if(cfw->end == 0) {
									ap_printf("bailing from applying overlay mask in read_seq_writ_rand\n");
									free(buf);
									return IO_ERROR;
								}
							}
							cfw->buff[cfw->pos] += *p;
							p++;
							cfw->pos++;
						}
						cfw->write_end = cfw->pos;
					} else {
						if(tmp_len != cwrite(out_cfh, buf + offset - pos, tmp_len)) {
							ap_printf("bailing, io_error 4\n");
							free(buf);
							return IO_ERROR;
						}
					}
				}
			}
			pos += len;
		}
	}
	u_src.cfh->state_flags &= ~CFILE_FLAG_BACKWARD_SEEKS;
	free(buf);
	return 0;
}