~ubuntu-branches/ubuntu/intrepid/cmake/intrepid-backports

« back to all changes in this revision

Viewing changes to Source/CursesDialog/cmCursesLongMessageForm.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Maitland Bottoms
  • Date: 2002-02-14 18:36:25 UTC
  • Revision ID: james.westby@ubuntu.com-20020214183625-8m44isdas2k4l0f7
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "../cmCacheManager.h"
 
2
#include "../cmSystemTools.h"
 
3
#include "../cmake.h"
 
4
#include "cmCursesLongMessageForm.h"
 
5
#include "cmCursesMainForm.h"
 
6
 
 
7
inline int ctrl(int z)
 
8
{
 
9
    return (z&037);
 
10
 
11
 
 
12
cmCursesLongMessageForm::cmCursesLongMessageForm(std::vector<std::string> 
 
13
                                                 const& messages, const char* 
 
14
                                                 title)
 
15
{
 
16
  // Append all messages into on big string
 
17
  std::vector<std::string>::const_iterator it;
 
18
  for(it=messages.begin(); it != messages.end(); it++)
 
19
    {
 
20
    m_Messages += (*it);
 
21
    // Add one blank line after each message
 
22
    m_Messages += "\n\n";
 
23
    }
 
24
  m_Title = title;
 
25
  m_Fields[0] = 0;
 
26
  m_Fields[1] = 0;
 
27
}
 
28
 
 
29
cmCursesLongMessageForm::~cmCursesLongMessageForm()
 
30
{
 
31
  if (m_Fields[0])
 
32
    {
 
33
    free_field(m_Fields[0]);
 
34
    }
 
35
}
 
36
 
 
37
 
 
38
void cmCursesLongMessageForm::UpdateStatusBar()
 
39
{
 
40
  int x,y;
 
41
  getmaxyx(stdscr, y, x);
 
42
 
 
43
  char bar[cmCursesMainForm::MAX_WIDTH];
 
44
  int size = strlen(m_Title.c_str());
 
45
  if ( size >= cmCursesMainForm::MAX_WIDTH )
 
46
    {
 
47
    size = cmCursesMainForm::MAX_WIDTH-1;
 
48
    }
 
49
  strncpy(bar, m_Title.c_str(), size);
 
50
  for(int i=size-1; i<cmCursesMainForm::MAX_WIDTH; i++) bar[i] = ' ';
 
51
 
 
52
  int width;
 
53
  if (x < cmCursesMainForm::MAX_WIDTH )
 
54
    {
 
55
    width = x;
 
56
    }
 
57
  else
 
58
    {
 
59
    width = cmCursesMainForm::MAX_WIDTH;
 
60
    }
 
61
 
 
62
  bar[width] = '\0';
 
63
 
 
64
  char version[cmCursesMainForm::MAX_WIDTH];
 
65
  char vertmp[128];
 
66
  sprintf(vertmp,"CMake Version %d.%d - %s", cmMakefile::GetMajorVersion(),
 
67
          cmMakefile::GetMinorVersion(),cmMakefile::GetReleaseVersion());
 
68
  int sideSpace = (width-strlen(vertmp));
 
69
  for(int i=0; i<sideSpace; i++) { version[i] = ' '; }
 
70
  sprintf(version+sideSpace, "%s", vertmp);
 
71
  version[width] = '\0';
 
72
 
 
73
  curses_move(y-4,0);
 
74
  attron(A_STANDOUT);
 
75
  printw(bar);
 
76
  attroff(A_STANDOUT);  
 
77
  curses_move(y-3,0);
 
78
  printw(version);
 
79
  pos_form_cursor(m_Form);
 
80
}
 
81
 
 
82
void cmCursesLongMessageForm::PrintKeys()
 
83
{
 
84
  int x,y;
 
85
  getmaxyx(stdscr, y, x);
 
86
  if ( x < cmCursesMainForm::MIN_WIDTH  || 
 
87
       y < cmCursesMainForm::MIN_HEIGHT )
 
88
    {
 
89
    return;
 
90
    }
 
91
  char firstLine[512];
 
92
  sprintf(firstLine,  "Press [e] to exit help");
 
93
 
 
94
  curses_move(y-2,0);
 
95
  printw(firstLine);
 
96
  pos_form_cursor(m_Form);
 
97
  
 
98
}
 
99
 
 
100
void cmCursesLongMessageForm::Render(int left, int top, int width, int height)
 
101
{
 
102
  int x,y;
 
103
  getmaxyx(stdscr, y, x);
 
104
 
 
105
  if (m_Form)
 
106
    {
 
107
    unpost_form(m_Form);
 
108
    free_form(m_Form);
 
109
    m_Form = 0;
 
110
    }
 
111
 
 
112
  const char* msg = m_Messages.c_str();
 
113
 
 
114
  curses_clear();
 
115
 
 
116
  if (m_Fields[0])
 
117
    {
 
118
    free_field(m_Fields[0]);
 
119
    m_Fields[0] = 0;
 
120
    }
 
121
 
 
122
  m_Fields[0] = new_field(y-6, x-2, 1, 1, 0, 0);
 
123
 
 
124
  field_opts_off(m_Fields[0],  O_STATIC);
 
125
 
 
126
  m_Form = new_form(m_Fields);
 
127
  post_form(m_Form);
 
128
 
 
129
  int i=0;
 
130
  form_driver(m_Form, REQ_BEG_FIELD);
 
131
  while(msg[i] != '\0')
 
132
    {
 
133
    if (msg[i] == '\n' && msg[i+1] != '\0')
 
134
      {
 
135
      form_driver(m_Form, REQ_NEW_LINE);
 
136
      }
 
137
    else
 
138
      {
 
139
      form_driver(m_Form, msg[i]);
 
140
      }
 
141
    i++;
 
142
    }
 
143
  form_driver(m_Form, REQ_BEG_FIELD);
 
144
 
 
145
  this->UpdateStatusBar();
 
146
  this->PrintKeys();
 
147
  touchwin(stdscr); 
 
148
  refresh();
 
149
 
 
150
}
 
151
 
 
152
void cmCursesLongMessageForm::HandleInput()
 
153
{
 
154
  if (!m_Form)
 
155
    {
 
156
    return;
 
157
    }
 
158
 
 
159
  char debugMessage[128];
 
160
 
 
161
  while(1)
 
162
    {
 
163
    int key = getch();
 
164
 
 
165
    sprintf(debugMessage, "Message widget handling input, key: %d", key);
 
166
    cmCursesForm::LogMessage(debugMessage);
 
167
 
 
168
    // quit
 
169
    if ( key == 'o' || key == 'e' )
 
170
      {
 
171
      break;
 
172
      }
 
173
    else if ( key == KEY_DOWN || key == ctrl('n') )
 
174
      {
 
175
      form_driver(m_Form, REQ_SCR_FLINE);
 
176
      }
 
177
    else if ( key == KEY_UP  || key == ctrl('p') )
 
178
      {
 
179
      form_driver(m_Form, REQ_SCR_BLINE);
 
180
      }
 
181
    else if ( key == KEY_NPAGE || key == ctrl('d') )
 
182
      {
 
183
      form_driver(m_Form, REQ_SCR_FPAGE);
 
184
      }
 
185
    else if ( key == KEY_PPAGE || key == ctrl('u') )
 
186
      {
 
187
      form_driver(m_Form, REQ_SCR_BPAGE);
 
188
      }
 
189
 
 
190
    this->UpdateStatusBar();
 
191
    this->PrintKeys();
 
192
    touchwin(stdscr); 
 
193
    wrefresh(stdscr); 
 
194
    }
 
195
 
 
196
}