diff options
Diffstat (limited to 'Source/CursesDialog/cmCursesStringWidget.cxx')
-rw-r--r-- | Source/CursesDialog/cmCursesStringWidget.cxx | 166 |
1 files changed, 61 insertions, 105 deletions
diff --git a/Source/CursesDialog/cmCursesStringWidget.cxx b/Source/CursesDialog/cmCursesStringWidget.cxx index 6bd7b45..3707d0d 100644 --- a/Source/CursesDialog/cmCursesStringWidget.cxx +++ b/Source/CursesDialog/cmCursesStringWidget.cxx @@ -15,30 +15,29 @@ inline int ctrl(int z) { - return (z&037); + return (z & 037); } -cmCursesStringWidget::cmCursesStringWidget(int width, int height, - int left, int top) : - cmCursesWidget(width, height, left, top) +cmCursesStringWidget::cmCursesStringWidget(int width, int height, int left, + int top) + : cmCursesWidget(width, height, left, top) { this->InEdit = false; this->Type = cmState::STRING; - set_field_fore(this->Field, A_NORMAL); - set_field_back(this->Field, A_STANDOUT); - field_opts_off(this->Field, O_STATIC); + set_field_fore(this->Field, A_NORMAL); + set_field_back(this->Field, A_STANDOUT); + field_opts_off(this->Field, O_STATIC); } void cmCursesStringWidget::OnTab(cmCursesMainForm*, WINDOW*) { - //FORM* form = fm->GetForm(); + // FORM* form = fm->GetForm(); } void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW*) { FORM* form = fm->GetForm(); - if (this->InEdit) - { + if (this->InEdit) { cmCursesForm::LogMessage("String widget leaving edit."); this->InEdit = false; fm->PrintKeys(); @@ -47,16 +46,14 @@ void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW*) form_driver(form, REQ_NEXT_FIELD); form_driver(form, REQ_PREV_FIELD); this->Done = true; - } - else - { + } else { cmCursesForm::LogMessage("String widget entering edit."); this->InEdit = true; fm->PrintKeys(); char* buf = field_buffer(this->Field, 0); - this->OriginalString = new char[strlen(buf)+1]; + this->OriginalString = new char[strlen(buf) + 1]; strcpy(this->OriginalString, buf); - } + } } void cmCursesStringWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW*) @@ -67,23 +64,21 @@ void cmCursesStringWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW*) bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) { - int x,y; + int x, y; FORM* form = fm->GetForm(); // 10 == enter - if (!this->InEdit && ( key != 10 && key != KEY_ENTER ) ) - { + if (!this->InEdit && (key != 10 && key != KEY_ENTER)) { return false; - } + } - this->OriginalString=0; + this->OriginalString = 0; this->Done = false; char debugMessage[128]; // <Enter> is used to change edit mode (like <Esc> in vi). - while(!this->Done) - { + while (!this->Done) { sprintf(debugMessage, "String widget handling input, key: %d", key); cmCursesForm::LogMessage(debugMessage); @@ -91,48 +86,36 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, getmaxyx(stdscr, y, x); // If window too small, handle 'q' only - if ( x < cmCursesMainForm::MIN_WIDTH || - y < cmCursesMainForm::MIN_HEIGHT ) - { + if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) { // quit - if ( key == 'q' ) - { + if (key == 'q') { return false; - } - else - { - key=getch(); + } else { + key = getch(); continue; - } } + } // If resize occurred during edit, move out of edit mode - if (!this->InEdit && ( key != 10 && key != KEY_ENTER ) ) - { + if (!this->InEdit && (key != 10 && key != KEY_ENTER)) { return false; - } + } // 10 == enter - if (key == 10 || key == KEY_ENTER) - { + if (key == 10 || key == KEY_ENTER) { this->OnReturn(fm, w); - } - else if ( key == KEY_DOWN || key == ctrl('n') || - key == KEY_UP || key == ctrl('p') || - key == KEY_NPAGE || key == ctrl('d') || - key == KEY_PPAGE || key == ctrl('u')) - { + } else if (key == KEY_DOWN || key == ctrl('n') || key == KEY_UP || + key == ctrl('p') || key == KEY_NPAGE || key == ctrl('d') || + key == KEY_PPAGE || key == ctrl('u')) { this->InEdit = false; delete[] this->OriginalString; // trick to force forms to update the field buffer form_driver(form, REQ_NEXT_FIELD); form_driver(form, REQ_PREV_FIELD); return false; - } + } // esc - else if (key == 27) - { - if (this->InEdit) - { + else if (key == 27) { + if (this->InEdit) { this->InEdit = false; fm->PrintKeys(); this->SetString(this->OriginalString); @@ -140,58 +123,37 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, touchwin(w); wrefresh(w); return true; - } } - else if ( key == 9 ) - { + } else if (key == 9) { this->OnTab(fm, w); - } - else if ( key == KEY_LEFT || key == ctrl('b') ) - { + } else if (key == KEY_LEFT || key == ctrl('b')) { form_driver(form, REQ_PREV_CHAR); - } - else if ( key == KEY_RIGHT || key == ctrl('f') ) - { + } else if (key == KEY_RIGHT || key == ctrl('f')) { form_driver(form, REQ_NEXT_CHAR); - } - else if ( key == ctrl('k') ) - { + } else if (key == ctrl('k')) { form_driver(form, REQ_CLR_EOL); - } - else if ( key == ctrl('a') || key == KEY_HOME ) - { + } else if (key == ctrl('a') || key == KEY_HOME) { form_driver(form, REQ_BEG_FIELD); - } - else if ( key == ctrl('e') || key == KEY_END ) - { + } else if (key == ctrl('e') || key == KEY_END) { form_driver(form, REQ_END_FIELD); + } else if (key == 127 || key == KEY_BACKSPACE) { + FIELD* cur = current_field(form); + form_driver(form, REQ_DEL_PREV); + if (current_field(form) != cur) { + set_current_field(form, cur); } - else if ( key == 127 || - key == KEY_BACKSPACE ) - { - FIELD *cur = current_field(form); - form_driver(form, REQ_DEL_PREV); - if (current_field(form) != cur) - { - set_current_field(form, cur); - } - } - else if ( key == ctrl('d') ||key == KEY_DC ) - { + } else if (key == ctrl('d') || key == KEY_DC) { form_driver(form, REQ_DEL_CHAR); - } - else - { + } else { this->OnType(key, fm, w); - } - if ( !this->Done ) - { + } + if (!this->Done) { touchwin(w); wrefresh(w); - key=getch(); - } + key = getch(); } + } return true; } @@ -212,38 +174,32 @@ const char* cmCursesStringWidget::GetValue() bool cmCursesStringWidget::PrintKeys() { - int x,y; + int x, y; getmaxyx(stdscr, y, x); - if ( x < cmCursesMainForm::MIN_WIDTH || - y < cmCursesMainForm::MIN_HEIGHT ) - { + if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) { return false; - } - if (this->InEdit) - { + } + if (this->InEdit) { char fmt_s[] = "%s"; char firstLine[512]; // Clean the toolbar - for(int i=0; i<512; i++) - { + for (int i = 0; i < 512; i++) { firstLine[i] = ' '; - } + } firstLine[511] = '\0'; - curses_move(y-4,0); + curses_move(y - 4, 0); printw(fmt_s, firstLine); - curses_move(y-3,0); + curses_move(y - 3, 0); printw(fmt_s, firstLine); - curses_move(y-2,0); + curses_move(y - 2, 0); printw(fmt_s, firstLine); - curses_move(y-1,0); + curses_move(y - 1, 0); printw(fmt_s, firstLine); - curses_move(y-3,0); + curses_move(y - 3, 0); printw(fmt_s, "Editing option, press [enter] to leave edit."); return true; - } - else - { + } else { return false; - } + } } |