1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*
* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>.
*
* Project: IDFetch.
* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine).
* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead).
* Mentoring organization: Gentoo Linux.
* Sponsored by GSOC 2010.
*
* This file is part of Segget.
*
* Segget is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Segget is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Segget; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "twindow.h"
#include "str.h"
string sms;
void Twindow::init(string caption_, int height_, int width_, int y_, int x_){
caption=caption_;
height=height_;
width=width_;
y=y_;
x=x_;
window=newwin(height,width,y,x);
}
void Twindow::toggle(){
visible=not(visible);
}
void Twindow::msg_line(uint y, string msg_text){
try{
// cout << msg_text;
msg_text=msg_text+" ";
mvwaddstr(window,y,1,msg_text.substr(0,width-2).c_str());
// mvwprintw(screen,y,1,ready_msg_text.c_str());
// mvwprintw(screen,y,1,msg_text.substr(0,max_x-2).c_str());
// mvaddstr();
}catch(...){
// error_log_no_msg("Error in tui.cpp: msg()");
}
}
void Twindow::msg_short(uint y, uint x, string msg_text){
try{
mvwaddstr(window,y,x,msg_text.c_str());
}catch(...){
// error_log_no_msg("Error in tui.cpp: msg()");
}
}
void Twindow::up(int inc){
int tmp_top_position=top_position-inc;
notfresh=TRUE;
if (tmp_top_position<0){
top_position=0;
}else{
top_position=tmp_top_position;
}
sms="UP"+toString(top_position);
}
void Twindow::down(uint inc){
uint tmp_top_position=top_position+inc;
// if we need to scroll down
if (max_received_screenline_num>bottom_screenline_num){
notfresh=TRUE;
if (tmp_top_position>(max_received_screenline_num-bottom_screenline_num)){
//set to max if it's over the limit
top_position=max_received_screenline_num-bottom_screenline_num;
}else{
top_position=tmp_top_position;
}
}
sms="DOWN "+toString(top_position)+"------>"+toString(bottom_screenline_num);
}
void Twindow::center(uint max_y, uint max_x){
y=(max_y-height)/2;
x=(max_x-width)/2;
mvwin(window,y,x);
}
void Twindow::resize(uint new_height, uint new_width, uint new_y, uint new_x){
y=new_y;
x=new_x;
height=new_height;
width=new_width;
mvwin(window,y,x);
wresize(window,height,width);
}
void Twindow::make_frame(){
wclear(window);
box(window, ACS_VLINE, ACS_HLINE);
mvwaddstr(window,0,(width-caption.length())/2,caption.c_str());
// msg_short(0,width-20,"[Lines:"+toString(top_position+1)+"-"+toString(top_position+bottom_screenline_num)+"/"+toString(max_received_screenline_num)+"]");
// msg_short(0,width-20,"[Lines:"+toString(top_position+1)+"-"+toString(top_position+bottom_screenline_num)+"/"+toString(screen_lines.size())+"]");
}
void Twindow::refresh(){
if (notfresh){
show();
}
}
void Twindow::show(){
if (visible){
compose();
}
}
|