1 // page-lcd.cxx - description. -*- C++ -*-
3 // Copyright (C) 1999, 2000 Red Hat.
4 // This file is part of SID and is licensed under the GPL.
5 // See the file COPYING.SID for conditions for redistribution.
10 PagerUI :: PagerUI(lcd_driver& lcd)
17 root->id = 0; // invalid id or only valid for root element.
22 NROWS = lcd_drobj.get_numrows();
23 NCOLS = lcd_drobj.get_numcols();
24 // assuming lcd is already initialized by the program during its start.
25 // MAKE SURE ASSUMPTION IS RIGHT
29 // Displays message. Arrow is drawn only on the current line.
31 PagerUI :: draw_line( bool curr, int num, string msg )
33 // write a text string
34 lcd_drobj.send_cmd( lcd_driver::SET_AWRITE );
37 lcd_drobj.auto_write( 0x80 ); // prints arrow
40 lcd_drobj.auto_write( 0 ); // prints space
44 lcd_drobj.auto_write(0); // putting a blank.
45 lcd_drobj.auto_write( '0' + num - ' ' ); // prints number
51 sprintf (s, "%d", num);
53 lcd_drobj.auto_write (string_rep[0] - ' ');
54 lcd_drobj.auto_write (string_rep[1] - ' ');
56 lcd_drobj.auto_write( 0 ); // prints blank/space.
58 for( unsigned int i=0; i < msg.size(); i++ )
59 lcd_drobj.auto_write( msg[i] - ' ' );
61 lcd_drobj.reset_auto( 8 );
65 PagerUI :: draw_screen() {
69 lcd_drobj.mem_set (0, 0, NROWS*NCOLS);
70 for( row=0; row<NROWS; row++ ) {
71 lcd_drobj.set_word_reg( lcd_driver::SET_ADP, row*NCOLS, 0 );
72 // always points at start of line
74 i = first_visible + row;
76 if( row == (NROWS - 1) ) {
77 if( i < (total - 1) ) { // more than 6 msgs.
80 lcd_drobj.send_cmd( lcd_driver::SET_AWRITE );
82 for( unsigned c=0; c < (NCOLS - msg.size()); c++ )
83 lcd_drobj.auto_write( 0 );
85 for( unsigned c=0; c<msg.size(); c++ )
86 lcd_drobj.auto_write( msg[c] - ' ' );
88 lcd_drobj.reset_auto( 8 );
95 draw_line( i == curr_line, i + 1, msg );
98 cerr << "gee - aren't there more lines to draw?" << endl;
100 lcd_drobj.send_cmd( lcd_driver::SET_AWRITE );
102 for( unsigned c=0; c<NCOLS; c++ )
103 lcd_drobj.auto_write( 0 ); // printing blanks.
105 lcd_drobj.reset_auto( 8 );
110 // Store new message.
112 PagerUI :: append( int id, string message ) {
113 if( total > MAX_MSGS ) {
114 cerr << " Cannot store more than 9 messages. Contact Rony or Fassi \n";
118 Entry *curr = new Entry;
121 curr->prev = root->prev;
123 curr->time_msg = message;
125 root->prev->next = curr;
129 select_line( total - 1 );
133 PagerUI :: remove( int index ) {
135 if ( root->next != root) {
136 Entry* curr = root->next;
139 if ( index >= total )
142 for ( i=0; i<index; i++ )
145 msg = curr->time_msg;
146 curr->prev->next = curr->next;
147 curr->next->prev = curr->prev;
151 if (total < 0) cerr << " total is less than zero ?? \n";
156 cerr << " Root next is root and index > 0 \n";
158 cout << " Root next is root and index is 0 \n";
164 PagerUI :: message( int index ) {
166 Entry* curr = root->next;
171 for( i=0; i<index; i++ )
174 return curr->time_msg;
178 PagerUI :: delete_selected() {
179 string msg = remove( curr_line );
181 if (curr_line >= total) {
183 curr_line = total - 1;
187 // need to think about first visible.
188 check_firstvisible();
192 PagerUI :: select_line( int line ) {
194 for (int i = first_visible; i < (total - 1); ++i) {
195 if ( (i + (NROWS - 1)) >= (total - 1) )
196 { // There is no "more" on current display
204 PagerUI :: current_id() {
206 Entry* curr = root->next;
209 return 0; // changed it from -1
211 for( i=0; i < curr_line; i++ )
217 PagerUI :: ~PagerUI() {
218 while( root->next != root )
226 if( curr_line > 0 ) {
228 check_firstvisible();
234 if( curr_line < (total - 1) ) {
236 out_ofrange (curr_line);
241 bool PagerUI :: out_ofrange (int curr_pos)
243 if ( total > NROWS ) {
244 // there are more msgs then lcd rows
245 if ( (first_visible + (NROWS - 1)) < (total -1) ) {
246 // it means "more" is on display.
247 int temp = first_visible + (NROWS - 1);
249 if (curr_line < temp)
253 // Yup I am out of visible range
254 first_visible += (NROWS -2); // or first_visible = temp -1
262 return false; // Total !> NROWS thus all msgs can be displayed.
265 void PagerUI::check_firstvisible()
267 if ( curr_line < first_visible)
269 first_visible = curr_line - (NROWS -1);
270 // Put first visible so that curr_line is last
271 if (first_visible < 0) first_visible = 0;
272 else if ( (first_visible + (NROWS -1)) < (total -1) )
273 first_visible++; // because more is going to show up.