#ifndef PANE_H
#define PANE_H

#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
#include <wchar.h>
#include <stdbool.h>

#include "resizeable_buf.h"
#include "colors.h"
#include "x11.h"
#include "script.h"


struct cell {
        wchar_t ch;
        struct char_attr flag;
        struct color * fgcolor;
        struct color * bgcolor;
};

struct line {
        rb_t cs;
        bool edited : 1;
        bool vestigial : 1;
};

#ifdef lines
#undef lines
#endif

struct pane {
        struct {
                int x1,y1;
                int x2,y2;
        } rr; // region needing redrawing;
        bool show_cursor : 1;
        bool redraw_all : 1;
        int cursor_x, cursor_y;
        int width, height;
        int cwidth, cheight;
        GC gc;
        struct color * cursor_color;
        int scrollback;
        rb_t lines;
        XftDraw *d;
        sc_t *sc;
};


// utility
struct pane * pane_create(sc_t *sc);
void pane_setup(struct pane *s, int w, int h);
void pane_draw(struct pane  * p, bool use_pixmap, bool clear_area);
void pane_touchall(struct pane *p);
void pane_toucharea(struct pane *p, int x, int y, int w, int h);
void pane_touchcell(struct pane *p, int x, int y) ;
void pane_scrollback(struct pane *p, int s);
void pane_attach(struct pane *p,struct conn *dpy);
void pane_detach(struct pane *p);

// visual
void pane_setcursor(struct pane *p, int x, int y);
void pane_showcursor(struct pane *p, bool show);

// modify
void pane_clear(struct pane *p, int x, int y, int w, int h, struct cell style);
void pane_slideclear(struct pane *p); // protect and clear

void pane_settext_generic(struct pane * restrict p, int x, int y, void const * restrict s, int len, struct cell style, bool latin1);
struct cell * cell(struct pane *p, int x, int y, bool create);
void pane_partial_scroll(struct pane *p, int sbegin, int send, int y);
void pane_scroll(struct pane *p, int y, bool);  //stores lines in scrollback buffer.
void pane_line_copy(struct pane *p, int sx, int dx, int y, int w);

#endif


