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
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
, ...) {
36 setcoords(xx1
, yy1
, xx2
, yy2
);
42 vsprintf(buf
, tfmt
, ap
);
44 set_title(tcolor
, buf
);
48 textwindow::textwindow(const textwindow
&aw
): abstractuicontrol(aw
) {
55 textwindow::~textwindow() {
58 void textwindow::setcoords(int ax1
, int ay1
, int ax2
, int ay2
) {
64 if(options
& TW_CENTERED
) {
65 int h
= y2
-y1
, w
= x2
-x1
;
73 void textwindow::setcolor(int awc
) {
77 void textwindow::setoptions(int aoptions
) {
79 setcoords(x1
, y1
, x2
, y2
);
82 void textwindow::set_titlef(int color
, const char *fmt
, ...) {
87 vsprintf(buf
, fmt
, ap
);
90 set_title(color
, buf
);
93 void textwindow::set_title(int color
, const string
&atitle
) {
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
, ...) {
109 vsprintf(buf
, fmt
, ap
);
112 write(x
, y
, wc
, buf
);
115 void textwindow::writef(int x
, int y
, int c
, const char *fmt
, ...) {
120 vsprintf(buf
, fmt
, ap
);
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
) {
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
]);
139 mvprintw(y1
+ y
, x1
+ x
, "%s", dtext
.c_str());
144 void textwindow::gotoxy(int x
, int y
) {
145 if(fisopen
) kgotoxy(x1
+ x
, y1
+ y
);
148 void textwindow::redraw() {
153 if(options
& TW_NOBORDER
) {
154 for(i
= y1
; i
< y2
; i
++) mvhline(i
, x1
, ' ', x2
-x1
);
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);
171 mvprintw(y1
, x1
+((x2
-x1
)-title
.size())/2, "%s", title
.c_str());
178 void textwindow::open() {
181 screenbuffer
.save(x1
, y1
, x2
, y2
);
186 void textwindow::separatey(int y
) {
188 mvhline(y1
+ y
, x1
+ 1, HLINE
, x2
- x1
- 1);
189 mvaddch(y1
+ y
, x1
, LTEE
);
190 mvaddch(y1
+ y
, x2
, RTEE
);
194 void textwindow::separatex(int x
) {
196 mvvline(y1
+ 1, x1
+ x
, VLINE
, y2
- y1
- 1);
197 mvaddch(y1
, x1
+ x
, TTEE
);
198 mvaddch(y2
, x1
+ x
, BTEE
);
202 bool textwindow::isbordered() {
203 return !(options
& TW_NOBORDER
);
206 void textwindow::close() {
207 abstractuicontrol::close();