connwrap - initialize gnutls session in cw_connect
[centerim.git] / kkconsui / src / textwindow.cc
blobae44db8aa22ae11fb4ea832da3fe4a30a7179074
1 /*
3 * kkconsui textwindow class
4 * $Id: textwindow.cc,v 1.9 2002/11/23 15:42:09 konst Exp $
6 * Copyright (C) 1999-2001 by Konstantin Klyagin <k@thekonst.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * USA
25 #include "textwindow.h"
27 textwindow::textwindow() {
28 x1 = x2 = y1 = y2 = options = 0;
31 textwindow::textwindow(int xx1, int yy1, int xx2, int yy2, int wcolor,
32 int noptions, int tcolor, const char *tfmt, ...) {
33 char buf[10240];
35 setoptions(noptions);
36 setcoords(xx1, yy1, xx2, yy2);
37 setcolor(wcolor);
39 if(tfmt) {
40 va_list ap;
41 va_start(ap, tfmt);
42 vsprintf(buf, tfmt, ap);
43 va_end(ap);
44 set_title(tcolor, buf);
48 textwindow::textwindow(const textwindow &aw): abstractuicontrol(aw) {
49 title = aw.title;
50 wc = aw.wc;
51 tc = aw.tc;
52 options = aw.options;
55 textwindow::~textwindow() {
58 void textwindow::setcoords(int ax1, int ay1, int ax2, int ay2) {
59 x1 = ax1;
60 x2 = ax2;
61 y1 = ay1;
62 y2 = ay2;
64 if(options & TW_CENTERED) {
65 int h = y2-y1, w = x2-x1;
66 y1 = (LINES-h)/2;
67 y2 = y1 + h;
68 x1 = (COLS-w)/2;
69 x2 = x1 + w;
73 void textwindow::setcolor(int awc) {
74 wc = awc;
77 void textwindow::setoptions(int aoptions) {
78 options = aoptions;
79 setcoords(x1, y1, x2, y2);
82 void textwindow::set_titlef(int color, const char *fmt, ...) {
83 va_list ap;
84 char buf[10240];
86 va_start(ap, fmt);
87 vsprintf(buf, fmt, ap);
88 va_end(ap);
90 set_title(color, buf);
93 void textwindow::set_title(int color, const string &atitle) {
94 title = atitle;
95 tc = color;
97 if(fisopen) {
98 attrset(wc);
99 mvhline(y1, x1+1, HLINE, x2-x1-1);
100 write(((x2 - x1) - title.size())/2, 0, tc, title);
104 void textwindow::writef(int x, int y, const char *fmt, ...) {
105 char buf[10240];
106 va_list ap;
108 va_start(ap, fmt);
109 vsprintf(buf, fmt, ap);
110 va_end(ap);
112 write(x, y, wc, buf);
115 void textwindow::writef(int x, int y, int c, const char *fmt, ...) {
116 char buf[10240];
117 va_list ap;
119 va_start(ap, fmt);
120 vsprintf(buf, fmt, ap);
121 va_end(ap);
123 write(x, y, c, buf);
126 void textwindow::write(int x, int y, const string &text) {
127 write(x, y, wc, text);
130 void textwindow::write(int x, int y, int c, const string &text) {
131 int i;
132 string dtext;
134 if(fisopen && (y < y2-y1)) {
135 for(i = 0; (i < text.size()) && (i < x2-x1-x); i++)
136 dtext += KT_DISP_FILTER(text[i]);
138 attrset(c);
139 mvprintw(y1 + y, x1 + x, "%s", dtext.c_str());
140 refresh();
144 void textwindow::gotoxy(int x, int y) {
145 if(fisopen) kgotoxy(x1 + x, y1 + y);
148 void textwindow::redraw() {
149 if(fisopen) {
150 int i;
151 attrset(wc);
153 if(options & TW_NOBORDER) {
154 for(i = y1; i < y2; i++) mvhline(i, x1, ' ', x2-x1);
155 } else {
156 for(i = y1; i <= y2; i++) mvhline(i, x1, ' ', x2-x1+1);
158 if(!(options & TW_SPACEBORDER)) {
159 mvaddch(y1, x1, ULCORNER); mvaddch(y2, x2, LRCORNER);
160 mvaddch(y1, x2, URCORNER); mvaddch(y2, x1, LLCORNER);
162 mvvline(y1 + 1, x1, VLINE, y2-y1-1);
163 mvvline(y1 + 1, x2, VLINE, y2-y1-1);
164 mvhline(y1, x1 + 1, HLINE, x2-x1-1);
165 mvhline(y2, x1 + 1, HLINE, x2-x1-1);
169 if(!title.empty()) {
170 attrset(tc);
171 mvprintw(y1, x1+((x2-x1)-title.size())/2, "%s", title.c_str());
174 refresh();
178 void textwindow::open() {
179 if(!fisopen) {
180 fisopen = true;
181 screenbuffer.save(x1, y1, x2, y2);
182 redraw();
186 void textwindow::separatey(int y) {
187 attrset(wc);
188 mvhline(y1 + y, x1 + 1, HLINE, x2 - x1 - 1);
189 mvaddch(y1 + y, x1, LTEE);
190 mvaddch(y1 + y, x2, RTEE);
191 refresh();
194 void textwindow::separatex(int x) {
195 attrset(wc);
196 mvvline(y1 + 1, x1 + x, VLINE, y2 - y1 - 1);
197 mvaddch(y1, x1 + x, TTEE);
198 mvaddch(y2, x1 + x, BTEE);
199 refresh();
202 bool textwindow::isbordered() {
203 return !(options & TW_NOBORDER);
206 void textwindow::close() {
207 abstractuicontrol::close();