Esempio n. 1
0
data_content_t *win_textgrid_update(window_t *win)
{
    int jx, ix;
    int spanstart;
    short curstyle;
    window_textgrid_t *dwin = win->data;

    if (!dwin->lines) {
        dwin->alldirty = FALSE;
        return NULL;
    }

    data_content_t *dat = NULL;

    for (jx=0; jx<dwin->height; jx++) {
        tgline_t *ln = &(dwin->lines[jx]);
        if (!dwin->alldirty && !ln->dirty)
            continue;

        if (!dat)
            dat = data_content_alloc(win->updatetag, win->type);

        data_line_t *line = data_line_alloc();
        gen_list_append(&dat->lines, line);
        line->linenum = jx;

        curstyle = -1;
        spanstart = 0;
        for (ix=0; ix<dwin->width; ix++) {
            if (ln->styles[ix] != curstyle) {
                if (ix > spanstart) {
                    data_line_add_span(line, curstyle, ln->chars+spanstart, ix-spanstart);
                    spanstart = ix;
                }

                curstyle = ln->styles[ix];
            }
        }
        if (ix > spanstart) {
            data_line_add_span(line, curstyle, ln->chars+spanstart, ix-spanstart);
            spanstart = ix;
        }

        ln->dirty = FALSE;
    }

    dwin->alldirty = FALSE;

    return dat;
}
Esempio n. 2
0
/* This constructs an update object for the library state. (It's in
   rgwindow.c because most of the work is window-related.)

   This clears all the dirty flags, constructs an update, sends it to
   stdout, and flushes. 

   If special is provided, it goes into the update. It will be freed
   after sending.
*/
void gli_windows_update(data_specialreq_t *special, int newgeneration)
{
    window_t *win;
    int ix;
    data_update_t *update = data_update_alloc();

    if (newgeneration)
        generation++;
    update->gen = generation;

    if (geometry_changed) {
        geometry_changed = FALSE;

        update->usewindows = TRUE;

        for (win=gli_windowlist, ix=0; win; win=win->next, ix++) {
            if (win->type == wintype_Pair)
                continue;
            data_window_t *dat = data_window_alloc(win->updatetag,
                win->type, win->rock);
            dat->size = win->bbox;
            if (win->type == wintype_TextGrid) {
                window_textgrid_t *dwin = win->data;
                dat->gridwidth = dwin->width;
                dat->gridheight = dwin->height;
            }
            gen_list_append(&update->windows, dat);
        }
    }
    
    for (win=gli_windowlist; win; win=win->next) {
        data_content_t *dat = NULL;
        switch (win->type) {
            case wintype_TextGrid:
                dat = win_textgrid_update(win);
                break;
            case wintype_TextBuffer:
                dat = win_textbuffer_update(win);
                break;
        }

        if (dat) {
            gen_list_append(&update->contents, dat);
        }
    }

    for (win=gli_windowlist; win; win=win->next) {
        data_input_t *dat = NULL;
        if (win->char_request) {
            dat = data_input_alloc(win->updatetag, evtype_CharInput);
            dat->gen = win->inputgen;
            if (win->type == wintype_TextGrid) {
                window_textgrid_t *dwin = win->data;
                /* Canonicalize position first? */
                dat->cursorpos = TRUE;
                dat->xpos = dwin->curx;
                dat->ypos = dwin->cury;
            }
        }
        else if (win->line_request) {
            dat = data_input_alloc(win->updatetag, evtype_LineInput);
            dat->gen = win->inputgen;
            if (win->type == wintype_TextBuffer) {
                window_textbuffer_t *dwin = win->data;
                dat->maxlen = dwin->inmax;
                if (dwin->incurpos) {
                    dat->initlen = dwin->incurpos;
                    dat->initstr = dup_buffer(dwin->inbuf, dwin->incurpos, dwin->inunicode);
                }
            }
            else if (win->type == wintype_TextGrid) {
                window_textgrid_t *dwin = win->data;
                /* Canonicalize position first? */
                dat->cursorpos = TRUE;
                dat->xpos = dwin->curx;
                dat->ypos = dwin->cury;
                dat->maxlen = dwin->inmax;
                if (dwin->incurpos) {
                    dat->initlen = dwin->incurpos;
                    dat->initstr = dup_buffer(dwin->inbuf, dwin->incurpos, dwin->inunicode);
                }
            }
        }

        if (win->hyperlink_request) {
            if (!dat)
                dat = data_input_alloc(win->updatetag, evtype_None);
            dat->hyperlink = TRUE;
        }

        if (dat) {
            update->useinputs = TRUE;
            gen_list_append(&update->inputs, dat);
        }
    }

    glui32 timing_msec = 0;
    if (gli_timer_need_update(&timing_msec)) {
        update->includetimer = TRUE;
        update->timer = timing_msec;
    }

    update->specialreq = special;

    data_update_print(update);
    printf("\n"); /* blank line after stanza */
    fflush(stdout);

    data_update_free(update);
}