2002-01-21 23:30:43 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2002-01-21 23:30:43 +03:00
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
2002-01-21 23:30:43 +03:00
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
2001-11-05 02:05:21 +03:00
|
|
|
#include "cmCursesStringWidget.h"
|
2001-12-13 21:28:41 +03:00
|
|
|
#include "cmCursesMainForm.h"
|
2001-12-04 19:16:04 +03:00
|
|
|
|
2001-11-05 02:05:21 +03:00
|
|
|
inline int ctrl(int z)
|
|
|
|
{
|
|
|
|
return (z&037);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCursesStringWidget::cmCursesStringWidget(int width, int height,
|
2002-10-24 02:03:27 +04:00
|
|
|
int left, int top) :
|
2001-11-05 02:05:21 +03:00
|
|
|
cmCursesWidget(width, height, left, top)
|
|
|
|
{
|
|
|
|
m_InEdit = false;
|
|
|
|
m_Type = cmCacheManager::STRING;
|
|
|
|
set_field_fore(m_Field, A_NORMAL);
|
|
|
|
set_field_back(m_Field, A_STANDOUT);
|
|
|
|
field_opts_off(m_Field, O_STATIC);
|
|
|
|
}
|
|
|
|
|
2002-11-05 01:37:21 +03:00
|
|
|
void cmCursesStringWidget::OnTab(cmCursesMainForm*, WINDOW*)
|
|
|
|
{
|
|
|
|
//FORM* form = fm->GetForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW*)
|
|
|
|
{
|
|
|
|
FORM* form = fm->GetForm();
|
|
|
|
if (m_InEdit)
|
|
|
|
{
|
|
|
|
cmCursesForm::LogMessage("String widget leaving edit.");
|
|
|
|
m_InEdit = false;
|
|
|
|
fm->PrintKeys();
|
|
|
|
delete[] m_OriginalString;
|
|
|
|
// trick to force forms to update the field buffer
|
|
|
|
form_driver(form, REQ_NEXT_FIELD);
|
|
|
|
form_driver(form, REQ_PREV_FIELD);
|
|
|
|
m_Done = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmCursesForm::LogMessage("String widget entering edit.");
|
|
|
|
m_InEdit = true;
|
|
|
|
fm->PrintKeys();
|
|
|
|
char* buf = field_buffer(m_Field, 0);
|
|
|
|
m_OriginalString = new char[strlen(buf)+1];
|
|
|
|
strcpy(m_OriginalString, buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-05 16:52:31 +03:00
|
|
|
void cmCursesStringWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW*)
|
2002-11-05 01:37:21 +03:00
|
|
|
{
|
|
|
|
form_driver(fm->GetForm(), key);
|
|
|
|
}
|
2001-11-05 02:05:21 +03:00
|
|
|
|
2001-12-13 21:28:41 +03:00
|
|
|
bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
|
2002-10-24 02:03:27 +04:00
|
|
|
WINDOW* w)
|
2001-11-05 02:05:21 +03:00
|
|
|
{
|
2001-12-13 21:28:41 +03:00
|
|
|
int x,y;
|
|
|
|
|
|
|
|
FORM* form = fm->GetForm();
|
2001-11-05 02:05:21 +03:00
|
|
|
// 10 == enter
|
2003-02-17 17:59:03 +03:00
|
|
|
if (!m_InEdit && ( key != 10 && key != KEY_ENTER ) )
|
2001-11-05 02:05:21 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-11-05 01:37:21 +03:00
|
|
|
m_OriginalString=0;
|
|
|
|
m_Done = false;
|
2001-11-05 02:05:21 +03:00
|
|
|
|
2001-12-04 19:16:04 +03:00
|
|
|
char debugMessage[128];
|
|
|
|
|
2001-11-05 02:05:21 +03:00
|
|
|
// <Enter> is used to change edit mode (like <Esc> in vi).
|
2002-11-05 01:37:21 +03:00
|
|
|
while(!m_Done)
|
2001-11-05 02:05:21 +03:00
|
|
|
{
|
2001-12-04 19:16:04 +03:00
|
|
|
sprintf(debugMessage, "String widget handling input, key: %d", key);
|
|
|
|
cmCursesForm::LogMessage(debugMessage);
|
2001-12-13 21:28:41 +03:00
|
|
|
|
|
|
|
fm->PrintKeys();
|
|
|
|
|
|
|
|
getmaxyx(stdscr, y, x);
|
|
|
|
// If window too small, handle 'q' only
|
|
|
|
if ( x < cmCursesMainForm::MIN_WIDTH ||
|
2002-10-24 02:03:27 +04:00
|
|
|
y < cmCursesMainForm::MIN_HEIGHT )
|
2001-12-13 21:28:41 +03:00
|
|
|
{
|
|
|
|
// quit
|
|
|
|
if ( key == 'q' )
|
2002-10-24 02:03:27 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2001-12-13 21:28:41 +03:00
|
|
|
else
|
2002-10-24 02:03:27 +04:00
|
|
|
{
|
|
|
|
key=getch();
|
|
|
|
continue;
|
|
|
|
}
|
2001-12-13 21:28:41 +03:00
|
|
|
}
|
|
|
|
|
2001-11-06 06:10:52 +03:00
|
|
|
// If resize occured during edit, move out of edit mode
|
|
|
|
if (!m_InEdit && ( key != 10 && key != KEY_ENTER ) )
|
2001-11-05 02:05:21 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// 10 == enter
|
2001-11-06 06:10:52 +03:00
|
|
|
if (key == 10 || key == KEY_ENTER)
|
2001-11-05 02:05:21 +03:00
|
|
|
{
|
2002-11-05 01:37:21 +03:00
|
|
|
this->OnReturn(fm, w);
|
2001-11-05 02:05:21 +03:00
|
|
|
}
|
2001-11-30 23:04:25 +03:00
|
|
|
else if ( key == KEY_DOWN || key == ctrl('n') ||
|
2002-10-24 02:03:27 +04:00
|
|
|
key == KEY_UP || key == ctrl('p') ||
|
|
|
|
key == KEY_NPAGE || key == ctrl('d') ||
|
|
|
|
key == KEY_PPAGE || key == ctrl('u'))
|
2001-11-30 23:04:25 +03:00
|
|
|
{
|
|
|
|
m_InEdit = false;
|
2002-11-05 01:37:21 +03:00
|
|
|
delete[] m_OriginalString;
|
2001-11-30 23:04:25 +03:00
|
|
|
// trick to force forms to update the field buffer
|
|
|
|
form_driver(form, REQ_NEXT_FIELD);
|
|
|
|
form_driver(form, REQ_PREV_FIELD);
|
|
|
|
return false;
|
|
|
|
}
|
2001-11-06 06:10:52 +03:00
|
|
|
// esc
|
2001-11-05 02:05:21 +03:00
|
|
|
else if (key == 27)
|
|
|
|
{
|
|
|
|
if (m_InEdit)
|
2002-10-24 02:03:27 +04:00
|
|
|
{
|
|
|
|
m_InEdit = false;
|
|
|
|
fm->PrintKeys();
|
2002-11-05 01:37:21 +03:00
|
|
|
this->SetString(m_OriginalString);
|
|
|
|
delete[] m_OriginalString;
|
2002-10-24 02:03:27 +04:00
|
|
|
touchwin(w);
|
|
|
|
wrefresh(w);
|
|
|
|
return true;
|
|
|
|
}
|
2001-11-05 02:05:21 +03:00
|
|
|
}
|
2002-11-05 01:37:21 +03:00
|
|
|
else if ( key == 9 )
|
|
|
|
{
|
|
|
|
this->OnTab(fm, w);
|
|
|
|
}
|
2001-11-05 02:05:21 +03:00
|
|
|
else if ( key == KEY_LEFT || key == ctrl('b') )
|
|
|
|
{
|
|
|
|
form_driver(form, REQ_PREV_CHAR);
|
|
|
|
}
|
|
|
|
else if ( key == KEY_RIGHT || key == ctrl('f') )
|
|
|
|
{
|
|
|
|
form_driver(form, REQ_NEXT_CHAR);
|
|
|
|
}
|
2001-11-06 06:10:52 +03:00
|
|
|
else if ( key == ctrl('k') )
|
|
|
|
{
|
|
|
|
form_driver(form, REQ_CLR_EOL);
|
|
|
|
}
|
2004-04-16 00:11:11 +04:00
|
|
|
else if ( key == ctrl('a') || key == KEY_HOME )
|
2001-11-06 06:10:52 +03:00
|
|
|
{
|
|
|
|
form_driver(form, REQ_BEG_FIELD);
|
|
|
|
}
|
2004-04-16 00:11:11 +04:00
|
|
|
else if ( key == ctrl('e') || key == KEY_END )
|
2001-11-06 06:10:52 +03:00
|
|
|
{
|
|
|
|
form_driver(form, REQ_END_FIELD);
|
|
|
|
}
|
|
|
|
else if ( key == ctrl('d') || key == 127 ||
|
2002-10-24 02:03:27 +04:00
|
|
|
key == KEY_BACKSPACE || key == KEY_DC )
|
2001-11-05 02:05:21 +03:00
|
|
|
{
|
2004-04-16 00:11:11 +04:00
|
|
|
if ( form->curcol > 0 )
|
|
|
|
{
|
|
|
|
form_driver(form, REQ_DEL_PREV);
|
|
|
|
}
|
2001-11-05 02:05:21 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-11-05 01:37:21 +03:00
|
|
|
this->OnType(key, fm, w);
|
|
|
|
}
|
|
|
|
if ( !m_Done )
|
|
|
|
{
|
|
|
|
touchwin(w);
|
|
|
|
wrefresh(w);
|
|
|
|
|
|
|
|
key=getch();
|
2001-11-05 02:05:21 +03:00
|
|
|
}
|
|
|
|
}
|
2002-11-05 01:37:21 +03:00
|
|
|
return true;
|
2001-11-05 02:05:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCursesStringWidget::SetString(const char* value)
|
|
|
|
{
|
|
|
|
this->SetValue(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* cmCursesStringWidget::GetString()
|
|
|
|
{
|
|
|
|
return this->GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* cmCursesStringWidget::GetValue()
|
|
|
|
{
|
|
|
|
return field_buffer(m_Field, 0);
|
|
|
|
}
|
2001-12-13 21:28:41 +03:00
|
|
|
|
|
|
|
bool cmCursesStringWidget::PrintKeys()
|
|
|
|
{
|
|
|
|
int x,y;
|
|
|
|
getmaxyx(stdscr, y, x);
|
|
|
|
if ( x < cmCursesMainForm::MIN_WIDTH ||
|
|
|
|
y < cmCursesMainForm::MIN_HEIGHT )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_InEdit)
|
|
|
|
{
|
|
|
|
char firstLine[512];
|
|
|
|
// Clean the toolbar
|
|
|
|
for(int i=0; i<512; i++)
|
|
|
|
{
|
|
|
|
firstLine[i] = ' ';
|
|
|
|
}
|
|
|
|
firstLine[511] = '\0';
|
|
|
|
curses_move(y-4,0);
|
|
|
|
printw(firstLine);
|
|
|
|
curses_move(y-3,0);
|
|
|
|
printw(firstLine);
|
|
|
|
curses_move(y-2,0);
|
|
|
|
printw(firstLine);
|
|
|
|
curses_move(y-1,0);
|
|
|
|
printw(firstLine);
|
|
|
|
|
|
|
|
sprintf(firstLine, "Editing option, press [enter] to leave edit.");
|
|
|
|
curses_move(y-3,0);
|
|
|
|
printw(firstLine);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|