#ifdef __GNUC__ #pragma implementation "Frame.h" #endif //#include #include "Frame.h" #include #include enum box { ULCORNER, TLINE, URCORNER, RLINE, LRCORNER, BLINE, LLCORNER, LLINE, TTEE, RTEE, BTEE, LTEE, PLUS }; static CHTYPE border[3][13] = { { ACS_ULCORNER, ACS_HLINE, ACS_URCORNER, /* standard */ ACS_VLINE, ACS_LRCORNER, ACS_HLINE, ACS_LLCORNER, ACS_VLINE, ACS_TTEE, ACS_RTEE, ACS_BTEE, ACS_LTEE, ACS_PLUS }, /* double line */ { 201, 205, 187, 186, 188, 205, 200, 186, 203, 185, 202, 204, 206 }, /* thick line (not right yet) */ { 220, 220, 220, 222, 223, 223, 223, 221, 220, 221, 223, 222, 219 } }; void Frame::draw(const Rect &r) { int plen = loc.width(); char *buf = (char *)alloca(plen); CHTYPE *b = border[type % 3]; CHTYPE chl = b[LLINE] | attr; CHTYPE chr = b[RLINE] | attr; //fprintf(stderr,"(%d,%d,%d,%d)\t", loc.r1,loc.c1,loc.r2,loc.c2); //fprintf(stderr,"(%d,%d,%d,%d)\n", r.r1,r.c1,r.r2,r.c2); for (int i = r.r1; i <= r.r2; ++i) { if (i == 0) { /* top row */ CHTYPE *cbuf = (CHTYPE *)alloca(plen * sizeof *cbuf); int len = title ? strlen(title) : 0; if (len > plen - 2) len = plen - 2; cbuf[0] = b[ULCORNER] | attr; int j; for (j = 1; j < plen - 1; ++j) cbuf[j] = b[TLINE] | attr; cbuf[plen - 1] = b[URCORNER] | attr; int n = (plen - len) / 2; for (j = 0; j < len; ++j) cbuf[j + n] = title[j] | attr | A_UNDERLINE; write(0,0,plen,cbuf); #if 0 for (j = 0; j < plen; ++j) buf[j] = cbuf[j]; write(0,0,plen,buf,attr); #endif } else if (i < loc.r2 - loc.r1) { /* middle rows */ write(i,0,1,&chl); write(i,plen - 1,1,&chr); } else { /* bottom row */ int len = desc ? strlen(desc) : 0; if (len > plen - 2) len = plen - 2; buf[0] = b[LLCORNER]; memset(buf+1,b[BLINE],plen - 2); buf[plen - 1] = b[LRCORNER]; memcpy(buf + (plen - len) / 2,desc,len); write(i,0,plen,buf,attr); } } } void Frame::set(const Rect &r) { Rect r1(r.intersect(Rect(loc.r1,loc.c1,loc.r1,loc.c2))); Rect r2(r.intersect(Rect(loc.r1,loc.c1,loc.r2,loc.c1))); Rect r3(r.intersect(Rect(loc.r1,loc.c2,loc.r2,loc.c2))); Rect r4(r.intersect(Rect(loc.r2,loc.c1,loc.r2,loc.c2))); Window::set(r1); Window::set(r2); Window::set(r3); Window::set(r4); } void Frame::setphys(const Rect &r) { Window::setphys(r.expand(1)); } FrameWin::FrameWin(const char *title,const char *subtitle) { frame = new Frame(title,subtitle); } FramedWin::FramedWin(const char *title,const char *subtitle): FrameWin(title,subtitle) { } void FrameWin::setframe(Frame *f) { delete frame; frame = f; } void FrameWin::setphys(const Rect &r) { if (frame) frame->setphys(r); Window::setphys(r); } void FramedWin::setphys(const Rect &r) { ChildWin::setphys(r); if (frame) frame->setphys(loc); } void FrameWin::top() { if (frame) frame->top(); Window::top(); } void FramedWin::top() { FrameWin::top(); ChildWin::top(); } void FramedWin::hide() { ChildWin::hide(); FrameWin::hide(); } void FrameWin::hide() { Window::hide(); if (frame) frame->hide(); } void FrameWin::bury() { if (frame) frame->bury(); Window::bury(); } void FramedWin::bury() { FrameWin::bury(); ChildWin::bury(); } FrameWin::~FrameWin() { hide(); setframe(0); } void Frame::set(const char *t,const char *d,CHTYPE a) { title = t; desc = d; attr = a; redraw(); } Frame::Frame(const char *t,const char *d,CHTYPE a) { title = t; desc = d; attr = a; type = 0; curtype(0); }