~ubuntu-branches/ubuntu/trusty/cmake3/trusty-updates

« back to all changes in this revision

Viewing changes to Source/CursesDialog/cmCursesLongMessageForm.cxx

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2017-02-23 17:55:24 UTC
  • Revision ID: package-import@ubuntu.com-20170223175524-5nh7s4pu97fsa0t7
Tags: upstream-3.5.1
ImportĀ upstreamĀ versionĀ 3.5.1

Show diffs side-by-side

added added

removed removed

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