1 /***************************************************************************
2                           aWindow.cxx - a Window abstraction layer (uses a
3                                   subclass of string to provide windowing
4                                   functionality on text terminals).
5                              -------------------
6     begin                : Thu Mar  1 13:15:18 IST 2001
7     copyright            : (C) 2001 by Arie Tal
8     email                : tal_arie@yahoo.com
9  ***************************************************************************/
10 
11 /***************************************************************************
12  *                                                                         *
13  *   This program is free software; you can redistribute it and/or modify  *
14  *   it under the terms of the GNU General Public License as published by  *
15  *   the Free Software Foundation; either version 2 of the License, or     *
16  *   (at your option) any later version.                                   *
17  *                                                                         *
18  ***************************************************************************/
19 
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 
24 #include <string.h> //PORT: moved as first because ofstrlen.
25 #include "aWindow.h"
26 
27 int
28 aWindow::initialized = 0 ;
29 
30 int
31 aWindow::nextWindow = 0 ;
32 
33 aWindow*
34 aWindow::openWindows[MAX_WINDOWS] ;
35 
36 //char
37 //aWindow::buffer[MAX_SCREEN_WIDTH] ;
38 
39 
aWindow(Screen * sc)40 aWindow::aWindow(Screen* sc) {
41   scr = sc ;
42   window_handle = 0 ;
43   flip_reverse = 0 ;
44   if (!initialized)
45     initializeWindows() ;
46 
47   openWindows[nextWindow++] = this ;
48 }
49 
aWindow(Screen * sc,int nlines,int ncols,int begin_y,int begin_x,int b)50 aWindow::aWindow(Screen* sc, int nlines, int ncols, int begin_y, int begin_x, int b) {
51   scr = sc ;
52   flip_reverse = 0 ;
53   if (!initialized)
54     initializeWindows() ;
55 
56   window_handle = scr->allocateNewWindow(nlines, ncols, begin_y, begin_x, b) ;
57 
58   openWindows[nextWindow++] = this ;
59 }
60 
61 void
initializeWindows()62 aWindow::initializeWindows()
63 {
64   for (int i=0; i< MAX_WINDOWS; i++) {
65     openWindows[i] = (aWindow *)0 ;
66   }
67   initialized = 1 ;
68 }
69 
~aWindow()70 aWindow::~aWindow()
71 {
72   if (window_handle) {
73     scr->closeAllocatedWindow(window_handle) ;
74   }
75   scr->AttrOff(REVERSE_ATTR) ;
76 }
77 
78 
79 
80 void
setWindowTopTitle(char * str)81 aWindow::setWindowTopTitle(char *str)
82 {
83   static char buf[MAX_SCREEN_WIDTH] ;
84   buf[0]=' ' ;
85   strcpy(buf+1, str) ;
86   strcat(buf," ") ;
87   scr->setWindowTopTitle(buf, window_handle) ;
88 }
89 
90 void
MVAddStrAttr(int y,int x,char * str,char * attr)91 aWindow::MVAddStrAttr(int y, int x, char *str, char *attr)
92 {
93    buffer[0]='\0' ;
94    char *ptr = buffer ;
95 
96    while (*attr) {
97       switch (*attr++) {
98       case '1':
99          if (*buffer) {
100             MVAddStr(y,x,buffer) ;
101             x+= ptr-buffer ;
102             buffer[0]='\0' ;
103             ptr = buffer ;
104          } /* endif */
105          AttrOn(REVERSE_ATTR) ;
106          break;
107       case '!':
108          if (*buffer) {
109             MVAddStr(y,x,buffer) ;
110             x+= ptr-buffer ;
111             buffer[0]='\0' ;
112             ptr = buffer ;
113          } /* endif */
114          AttrOff(REVERSE_ATTR) ;
115          break;
116       case '2':
117          if (*buffer) {
118             MVAddStr(y,x,buffer) ;
119             x+= ptr-buffer ;
120             buffer[0]='\0' ;
121             ptr = buffer ;
122          } /* endif */
123          AttrOn(BOLD_ATTR) ;
124          break;
125       case '@':
126          if (*buffer) {
127             MVAddStr(y,x,buffer) ;
128             x+= ptr-buffer ;
129             buffer[0]='\0' ;
130             ptr = buffer ;
131          } /* endif */
132          AttrOff(BOLD_ATTR) ;
133          break;
134       case '3':
135          if (*buffer) {
136             MVAddStr(y,x,buffer) ;
137             x+= ptr-buffer ;
138             buffer[0]='\0' ;
139             ptr = buffer ;
140          } /* endif */
141          AttrOn(BOLD2_ATTR) ;
142          break;
143       case '#':
144          if (*buffer) {
145             MVAddStr(y,x,buffer) ;
146             x+= ptr-buffer ;
147             buffer[0]='\0' ;
148             ptr = buffer ;
149          } /* endif */
150          AttrOff(BOLD2_ATTR) ;
151          break;
152       case '4':
153          if (*buffer) {
154             MVAddStr(y,x,buffer) ;
155             x+= ptr-buffer ;
156             buffer[0]='\0' ;
157             ptr = buffer ;
158          } /* endif */
159          AttrOn(BOLD3_ATTR) ;
160          break;
161       case '$':
162          if (*buffer) {
163             MVAddStr(y,x,buffer) ;
164             x+= ptr-buffer ;
165             buffer[0]='\0' ;
166             ptr = buffer ;
167          } /* endif */
168          AttrOff(BOLD3_ATTR) ;
169          break;
170       default:
171          if (*str)
172             *ptr++ = *str++ ;
173          *ptr = '\0' ;
174          break;
175        }
176    } /* endwhile */
177          if (*buffer) {
178             MVAddStr(y,x,buffer) ;
179             x+= ptr-buffer ;
180             buffer[0]='\0' ;
181             ptr = buffer ;
182          } /* endif */
183   AttrOff(REVERSE_ATTR) ;
184   AttrOff(BOLD_ATTR) ;
185   AttrOff(BOLD2_ATTR) ;
186   AttrOff(BOLD3_ATTR) ;
187   SetAttr(NORMAL_ATTR) ;
188 }
189 
190 
191