Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CursesDialog / cmCursesLongMessageForm.cxx
blobbf05ecd095bcb59cf83ef4ffa9f0e83c76fb2a6a
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCursesLongMessageForm.cxx,v $
5 Language: C++
6 Date: $Date: 2006/11/29 22:25:46 $
7 Version: $Revision: 1.16 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "../cmCacheManager.h"
18 #include "../cmSystemTools.h"
19 #include "../cmake.h"
20 #include "../cmVersion.h"
21 #include "cmCursesLongMessageForm.h"
22 #include "cmCursesMainForm.h"
24 inline int ctrl(int z)
26 return (z&037);
29 cmCursesLongMessageForm::cmCursesLongMessageForm(std::vector<std::string>
30 const& messages, const char*
31 title)
33 // Append all messages into on big string
34 std::vector<std::string>::const_iterator it;
35 for(it=messages.begin(); it != messages.end(); it++)
37 this->Messages += (*it);
38 // Add one blank line after each message
39 this->Messages += "\n\n";
41 this->Title = title;
42 this->Fields[0] = 0;
43 this->Fields[1] = 0;
46 cmCursesLongMessageForm::~cmCursesLongMessageForm()
48 if (this->Fields[0])
50 free_field(this->Fields[0]);
55 void cmCursesLongMessageForm::UpdateStatusBar()
57 int x,y;
58 getmaxyx(stdscr, y, x);
60 char bar[cmCursesMainForm::MAX_WIDTH];
61 int size = strlen(this->Title.c_str());
62 if ( size >= cmCursesMainForm::MAX_WIDTH )
64 size = cmCursesMainForm::MAX_WIDTH-1;
66 strncpy(bar, this->Title.c_str(), size);
67 for(int i=size-1; i<cmCursesMainForm::MAX_WIDTH; i++) bar[i] = ' ';
69 int width;
70 if (x < cmCursesMainForm::MAX_WIDTH )
72 width = x;
74 else
76 width = cmCursesMainForm::MAX_WIDTH;
79 bar[width] = '\0';
81 char version[cmCursesMainForm::MAX_WIDTH];
82 char vertmp[128];
83 sprintf(vertmp,"CMake Version %d.%d - %s", cmVersion::GetMajorVersion(),
84 cmVersion::GetMinorVersion(),cmVersion::GetReleaseVersion().c_str());
85 int sideSpace = (width-strlen(vertmp));
86 for(int i=0; i<sideSpace; i++) { version[i] = ' '; }
87 sprintf(version+sideSpace, "%s", vertmp);
88 version[width] = '\0';
90 curses_move(y-4,0);
91 attron(A_STANDOUT);
92 printw(bar);
93 attroff(A_STANDOUT);
94 curses_move(y-3,0);
95 printw(version);
96 pos_form_cursor(this->Form);
99 void cmCursesLongMessageForm::PrintKeys()
101 int x,y;
102 getmaxyx(stdscr, y, x);
103 if ( x < cmCursesMainForm::MIN_WIDTH ||
104 y < cmCursesMainForm::MIN_HEIGHT )
106 return;
108 char firstLine[512];
109 sprintf(firstLine, "Press [e] to exit help");
111 curses_move(y-2,0);
112 printw(firstLine);
113 pos_form_cursor(this->Form);
117 void cmCursesLongMessageForm::Render(int, int, int, int)
119 int x,y;
120 getmaxyx(stdscr, y, x);
122 if (this->Form)
124 unpost_form(this->Form);
125 free_form(this->Form);
126 this->Form = 0;
129 const char* msg = this->Messages.c_str();
131 curses_clear();
133 if (this->Fields[0])
135 free_field(this->Fields[0]);
136 this->Fields[0] = 0;
139 this->Fields[0] = new_field(y-6, x-2, 1, 1, 0, 0);
141 field_opts_off(this->Fields[0], O_STATIC);
143 this->Form = new_form(this->Fields);
144 post_form(this->Form);
146 int i=0;
147 form_driver(this->Form, REQ_BEG_FIELD);
148 while(msg[i] != '\0' && i < 60000)
150 if (msg[i] == '\n' && msg[i+1] != '\0')
152 form_driver(this->Form, REQ_NEW_LINE);
154 else
156 form_driver(this->Form, msg[i]);
158 i++;
160 form_driver(this->Form, REQ_BEG_FIELD);
162 this->UpdateStatusBar();
163 this->PrintKeys();
164 touchwin(stdscr);
165 refresh();
169 void cmCursesLongMessageForm::HandleInput()
171 if (!this->Form)
173 return;
176 char debugMessage[128];
178 for(;;)
180 int key = getch();
182 sprintf(debugMessage, "Message widget handling input, key: %d", key);
183 cmCursesForm::LogMessage(debugMessage);
185 // quit
186 if ( key == 'o' || key == 'e' )
188 break;
190 else if ( key == KEY_DOWN || key == ctrl('n') )
192 form_driver(this->Form, REQ_SCR_FLINE);
194 else if ( key == KEY_UP || key == ctrl('p') )
196 form_driver(this->Form, REQ_SCR_BLINE);
198 else if ( key == KEY_NPAGE || key == ctrl('d') )
200 form_driver(this->Form, REQ_SCR_FPAGE);
202 else if ( key == KEY_PPAGE || key == ctrl('u') )
204 form_driver(this->Form, REQ_SCR_BPAGE);
207 this->UpdateStatusBar();
208 this->PrintKeys();
209 touchwin(stdscr);
210 wrefresh(stdscr);