diff --git a/ChangeLog b/ChangeLog index e2379bb5..d44c2c9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2016-10-02 Markus Gans + * The input cursor is now controlled by the virtual terminal + 2016-10-02 Markus Gans * FStatusBar and FMenuBar use now the always-on-top window option diff --git a/src/fapp.cpp b/src/fapp.cpp index 34a502b1..e26713af 100644 --- a/src/fapp.cpp +++ b/src/fapp.cpp @@ -19,7 +19,7 @@ FWidget* FApplication::active_window = 0; // the active window FWidget* FApplication::focus_widget = 0; // has keyboard input focus FWidget* FApplication::clicked_widget = 0; // is focused by click FWidget* FApplication::open_menu = 0; // currently open menu -FWidget* FApplication::move_size_widget = 0; // move/size by keyboard +FWidget* FApplication::move_size_widget = 0; // move/size by keyboard FPoint* FApplication::zero_point = 0; // zero point (x=0, y=0) int FApplication::quit_code = 0; bool FApplication::quit_now = false; @@ -101,7 +101,7 @@ void FApplication::init() std::fill_n (sgr_mouse, sizeof(sgr_mouse), '\0'); std::fill_n (urxvt_mouse, sizeof(urxvt_mouse), '\0'); // init bit field with 0 - memset(&b_state, 0x00, sizeof(b_state)); + std::memset(&b_state, 0x00, sizeof(b_state)); // interpret the command line options cmd_options(); } @@ -110,10 +110,10 @@ void FApplication::init() void FApplication::setExitMessage (std::string message) { quit_now = true; - snprintf ( FTerm::exit_message - , sizeof(FTerm::exit_message) - , "%s" - ,message.c_str() ); + std::snprintf ( FTerm::exit_message + , sizeof(FTerm::exit_message) + , "%s" + , message.c_str() ); } //---------------------------------------------------------------------- @@ -141,7 +141,7 @@ void FApplication::cmd_options () if ( c == 0 ) { - if ( strcmp(long_options[idx].name, "encoding") == 0 ) + if ( std::strcmp(long_options[idx].name, "encoding") == 0 ) { FString encoding(optarg); encoding = encoding.toUpper(); @@ -158,10 +158,10 @@ void FApplication::cmd_options () + std::string(encoding.c_str()) ); } - if ( strcmp(long_options[idx].name, "no-optimize-cursor") == 0 ) + if ( std::strcmp(long_options[idx].name, "no-optimize-cursor") == 0 ) setCursorOptimisation (false); - if ( strcmp(long_options[idx].name, "vgafont") == 0 ) + if ( std::strcmp(long_options[idx].name, "vgafont") == 0 ) { bool ret = setVGAFont(); @@ -169,7 +169,7 @@ void FApplication::cmd_options () setExitMessage ("VGAfont is not supported by this terminal"); } - if ( strcmp(long_options[idx].name, "newfont") == 0 ) + if ( std::strcmp(long_options[idx].name, "newfont") == 0 ) { bool ret = setNewFont(); @@ -366,7 +366,7 @@ void FApplication::processKeyboardEvent() case fc::Fkey_extended_mouse: { int n = 3; - int len = int(strlen(fifo_buf)); + int len = int(std::strlen(fifo_buf)); while ( n < len && n < fifo_buf_size ) { @@ -395,7 +395,7 @@ void FApplication::processKeyboardEvent() case fc::Fkey_urxvt_mouse: { int n = 2; - int len = int(strlen(fifo_buf)); + int len = int(std::strlen(fifo_buf)); while ( n < len && n < fifo_buf_size ) { @@ -435,10 +435,8 @@ void FApplication::processKeyboardEvent() && ! k_press_ev.isAccepted() && ! k_down_ev.isAccepted() ) { - bool accpt = false; // switch to a specific dialog with Meta + 1..9 - if ( ! accpt ) - accpt = processDialogSwitchAccelerator(); + bool accpt = processDialogSwitchAccelerator(); // windows keyboard accelerator if ( ! accpt ) @@ -455,7 +453,7 @@ void FApplication::processKeyboardEvent() FWidget* root_widget = getRootWidget(); if ( root_widget ) - accpt = processAccelerator (root_widget); + processAccelerator (root_widget); } } } @@ -464,7 +462,7 @@ void FApplication::processKeyboardEvent() } // end of switch } - fifo_offset = int(strlen(fifo_buf)); + fifo_offset = int(std::strlen(fifo_buf)); } // send key up event @@ -963,7 +961,7 @@ bool FApplication::parseX11Mouse() y = uChar(x11_mouse[2] - 0x20); new_mouse_position.setPoint(x,y); // fill bit field with 0 - memset(&b_state, 0x00, sizeof(b_state)); + std::memset(&b_state, 0x00, sizeof(b_state)); if ( (x11_mouse[0] & key_shift) == key_shift ) b_state.shift_button = Pressed; @@ -1056,7 +1054,7 @@ bool FApplication::parseSGRMouse() new_mouse_position.setPoint(x,y); // fill bit field with 0 - memset(&b_state, 0x00, sizeof(b_state)); + std::memset(&b_state, 0x00, sizeof(b_state)); if ( (button & key_shift) == key_shift ) b_state.shift_button = Pressed; @@ -1253,7 +1251,7 @@ bool FApplication::parseUrxvtMouse() new_mouse_position.setPoint(x,y); // fill bit field with 0 - memset(&b_state, 0x00, sizeof(b_state)); + std::memset(&b_state, 0x00, sizeof(b_state)); if ( (button & key_shift) == key_shift ) b_state.shift_button = Pressed; @@ -1292,7 +1290,7 @@ bool FApplication::parseUrxvtMouse() bool FApplication::processGpmEvent() { // fill bit field with 0 - memset(&b_state, 0x00, sizeof(b_state)); + std::memset(&b_state, 0x00, sizeof(b_state)); if ( Gpm_GetEvent(&gpm_ev) == 1 ) { @@ -1786,12 +1784,12 @@ bool FApplication::processNextEvent() //---------------------------------------------------------------------- void FApplication::print_cmd_Options () { - ::printf("\nFinalCut Options:\n" + std::printf ( "\nFinalCut Options:\n" " --encoding Sets the character encoding mode\n" " {UTF8, VT100, PC, ASCII}\n" " --no-optimized-cursor No cursor optimisation\n" " --vgafont Set the standard vga 8x16 font\n" - " --newfont Enables the graphical font\n"); + " --newfont Enables the graphical font\n" ); } //---------------------------------------------------------------------- @@ -1806,26 +1804,12 @@ void FApplication::setMainWidget (FWidget* widget) //---------------------------------------------------------------------- int FApplication::exec() // run { - FWidget* widget; - if ( quit_now ) return EXIT_FAILURE; quit_now = false; quit_code = 0; - // set the cursor to the focus widget - widget = getFocusWidget(); - - if ( widget - && widget->isVisible() - && widget->hasVisibleCursor() ) - { - widget->setCursor(); - showCursor(); - flush_out(); - } - enter_loop(); return quit_code; } diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 047fecee..3d835c98 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -104,12 +104,12 @@ void FButton::setHotkeyAccelerator() if ( hotkey ) { - if ( isalpha(hotkey) || isdigit(hotkey) ) + if ( std::isalpha(hotkey) || std::isdigit(hotkey) ) { - addAccelerator (tolower(hotkey)); - addAccelerator (toupper(hotkey)); + addAccelerator (std::tolower(hotkey)); + addAccelerator (std::toupper(hotkey)); // Meta + hotkey - addAccelerator (fc::Fmkey_meta + tolower(hotkey)); + addAccelerator (fc::Fmkey_meta + std::tolower(hotkey)); } else addAccelerator (getHotkey()); @@ -137,7 +137,7 @@ void FButton::draw() FString txt; FWidget* parent_widget = getParentWidget(); int active_focus; - int d, i, j, x, mono_offset, margin; + int d, i, j, x, mono_offset, mono_1st_char, margin; int length, hotkeypos, hotkey_offset, space; bool is_ActiveFocus, is_Active, is_Focus, is_Flat; bool is_NonFlatShadow, is_NoUnderline; @@ -199,10 +199,14 @@ void FButton::draw() txt = "<" + txt + ">"; length = int(txt.getLength()); src = const_cast(txt.wc_str()); + mono_1st_char = 1; mono_offset = 2; } else + { + mono_1st_char = 0; mono_offset = 0; + } // find hotkey position in string // + generate a new string without the '&'-sign @@ -292,7 +296,7 @@ void FButton::draw() i = getWidth() - length - 1; i = int(i / 2); - if ( getHeight() > 1 ) + if ( getHeight() >= 2 ) j = int((getHeight()-1) / 2); else j=0; @@ -304,7 +308,7 @@ void FButton::draw() print (space); // █ if ( hotkeypos == -1 ) - setCursorPos (1+margin+i, 1+j ); // first character + setCursorPos (1+margin+i+mono_1st_char, 1+j ); // first character else setCursorPos (1+margin+i+hotkeypos, 1+j ); // hotkey @@ -345,7 +349,7 @@ void FButton::draw() for (x=i+length; x < getWidth()-1; x++) print (space); // █ - if ( getHeight() > 1 ) + if ( getHeight() >= 2 ) { for (i=0; i < j; i++) { @@ -516,7 +520,7 @@ void FButton::hide() return; blank = new char[size+1]; - memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', uLong(size)); blank[size] = '\0'; for (int y=0; y < getHeight()+s+(f << 1); y++) diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index c492f5ca..30bc2e91 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -73,8 +73,8 @@ bool FButtonGroup::isRadioButton(FToggleButton* button) const if ( ! button ) return false; - return bool ( strcmp ( button->getClassName() - , const_cast("FRadioButton") ) == 0 ); + return bool ( std::strcmp ( button->getClassName() + , const_cast("FRadioButton") ) == 0 ); } //---------------------------------------------------------------------- @@ -197,12 +197,12 @@ void FButtonGroup::setHotkeyAccelerator() if ( hotkey ) { - if ( isalpha(hotkey) || isdigit(hotkey) ) + if ( std::isalpha(hotkey) || std::isdigit(hotkey) ) { - addAccelerator (tolower(hotkey)); - addAccelerator (toupper(hotkey)); + addAccelerator (std::tolower(hotkey)); + addAccelerator (std::toupper(hotkey)); // Meta + hotkey - addAccelerator (fc::Fmkey_meta + tolower(hotkey)); + addAccelerator (fc::Fmkey_meta + std::tolower(hotkey)); } else addAccelerator (getHotkey()); @@ -325,7 +325,7 @@ void FButtonGroup::hide() return; blank = new char[size+1]; - memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', uLong(size)); blank[size] = '\0'; for (int y=0; y < getHeight(); y++) diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 232f01d8..cd189a0b 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -172,7 +172,7 @@ void FDialog::drawBorder() if ( isNewFont() ) { - for (int y=y1; y <= y2; y++) + for (int y=y1; y < y2; y++) { printPos (x1, y); // border left ⎸ @@ -457,7 +457,6 @@ void FDialog::cb_move (FWidget*, void*) setMoveSizeWidget(this); save_geometry = getGeometry(); - redraw(); tooltip = new FToolTip(this); if ( isResizeable() ) @@ -571,6 +570,7 @@ void FDialog::draw() clearArea(); drawBorder(); drawTitleBar(); + setCursorPos(2, getHeight() - 1); if ( (flags & fc::shadow) != 0 ) drawDialogShadow(); @@ -626,25 +626,21 @@ void FDialog::onKeyPress (FKeyEvent* ev) { case fc::Fkey_up: move (getX(), getY() - 1); - redraw(); ev->accept(); break; case fc::Fkey_down: move (getX(), getY() + 1); - redraw(); ev->accept(); break; case fc::Fkey_left: move (getX() - 1, getY()); - redraw(); ev->accept(); break; case fc::Fkey_right: move (getX() + 1, getY()); - redraw(); ev->accept(); break; @@ -1192,19 +1188,6 @@ void FDialog::show() FWindow::show(); - // set the cursor to the focus widget - FWidget* focus_widget = FWidget::getFocusWidget(); - - if ( focus_widget - && focus_widget->isVisible() - && focus_widget->hasVisibleCursor() - && focus_widget->isCursorInside() ) - { - focus_widget->setCursor(); - showCursor(); - flush_out(); - } - if ( isModal() ) { FApplication* fapp = static_cast(getRootWidget()); @@ -1254,7 +1237,7 @@ void FDialog::move (int x, int y) height = getHeight(); // Avoid to move widget completely outside the terminal - if ( x+width-1 < 1 || x > getMaxWidth() || y < 1 || y > getMaxHeight() ) + if ( x+width <= 1 || x > getMaxWidth() || y < 1 || y > getMaxHeight() ) return; if ( isZoomed() ) @@ -1289,20 +1272,20 @@ void FDialog::move (int x, int y) if ( dy > 0 ) restoreVTerm (old_x+width+rsw-dx, old_y, dx, getHeight()+bsh-dy); else - restoreVTerm (old_x+width+rsw-dx, old_y+abs(dy), dx, height+bsh-abs(dy)); + restoreVTerm (old_x+width+rsw-dx, old_y+std::abs(dy), dx, height+bsh-std::abs(dy)); } else { if ( dy > 0 ) - restoreVTerm (old_x, old_y, abs(dx), height+bsh-dy); + restoreVTerm (old_x, old_y, std::abs(dx), height+bsh-dy); else - restoreVTerm (old_x, old_y+abs(dy), abs(dx), height+bsh-abs(dy)); + restoreVTerm (old_x, old_y+std::abs(dy), std::abs(dx), height+bsh-std::abs(dy)); } if ( dy > 0 ) restoreVTerm (old_x, old_y+height+bsh-dy, width+rsw, dy); else - restoreVTerm (old_x, old_y, width+rsw, abs(dy)); + restoreVTerm (old_x, old_y, width+rsw, std::abs(dy)); } else { @@ -1338,9 +1321,7 @@ void FDialog::move (int x, int y) && focus_widget->hasVisibleCursor() ) { FPoint cursor_pos = focus_widget->getCursorPos(); - - if ( ! focus_widget->setCursorPos(cursor_pos) ) - hideCursor(); + focus_widget->setCursorPos(cursor_pos); } updateTerminal(); @@ -1416,9 +1397,7 @@ void FDialog::setSize (int w, int h, bool adjust) && focus_widget->hasVisibleCursor() ) { FPoint cursor_pos = focus_widget->getCursorPos(); - - if ( ! focus_widget->setCursorPos(cursor_pos) ) - hideCursor(); + focus_widget->setCursorPos(cursor_pos); } } diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 198d3847..32e19b42 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -218,10 +218,10 @@ inline bool FFileDialog::pattern_match ( const char* pattern { search[0] = '.'; search[1] = '\0'; - strncat(search, pattern, sizeof(search) - strlen(search) - 1); + std::strncat(search, pattern, sizeof(search) - std::strlen(search) - 1); } else - strncpy(search, pattern, sizeof(search) - 1); + std::strncpy(search, pattern, sizeof(search) - 1); if ( fnmatch (search, fname, FNM_PERIOD) == 0 ) return true; @@ -243,7 +243,7 @@ void FFileDialog::clear() while ( iter != end ) { - free ((*iter).name); + std::free ((*iter).name); ++iter; } @@ -263,7 +263,7 @@ int FFileDialog::numOfDirs() while ( iter != end ) { - if ( (*iter).type == DT_DIR && strcmp((*iter).name, ".") != 0 ) + if ( (*iter).type == DT_DIR && std::strcmp((*iter).name, ".") != 0 ) n++; ++iter; @@ -313,7 +313,7 @@ int FFileDialog::changeDir (const FString& dirname) while ( iter != end ) { - if ( strcmp((*iter).name, baseName) == 0 ) + if ( std::strcmp((*iter).name, baseName) == 0 ) { filebrowser->setCurrentItem(i); filename->setText(FString(baseName) + '/'); @@ -391,7 +391,7 @@ void FFileDialog::cb_processActivate (FWidget*, void*) while ( iter != end ) { - if ( strcmp((*iter).name, input) == 0 && (*iter).type == DT_DIR ) + if ( std::strcmp((*iter).name, input) == 0 && (*iter).type == DT_DIR ) { found = true; changeDir(input); @@ -644,7 +644,7 @@ int FFileDialog::readDir() continue; } - if ( dir[0] == '/' && dir[1] == '\0' && strcmp(next->d_name, "..") == 0 ) + if ( dir[0] == '/' && dir[1] == '\0' && std::strcmp(next->d_name, "..") == 0 ) continue; dir_entry entry; @@ -655,8 +655,8 @@ int FFileDialog::readDir() { char resolved_path[MAXPATHLEN] = {}; char symLink[MAXPATHLEN] = {}; - strncpy(symLink, dir, sizeof(symLink) - 1); - strncat(symLink, next->d_name, sizeof(symLink) - strlen(symLink) - 1); + std::strncpy (symLink, dir, sizeof(symLink) - 1); + std::strncat (symLink, next->d_name, sizeof(symLink) - std::strlen(symLink) - 1); if ( realpath(symLink, resolved_path) != 0 ) // follow link { @@ -675,7 +675,7 @@ int FFileDialog::readDir() else if ( pattern_match(filter, entry.name) ) dir_entries.push_back (entry); else - free(entry.name); + std::free(entry.name); } else if (errno != 0) { @@ -695,7 +695,7 @@ int FFileDialog::readDir() return -2; } - if ( strcmp((*dir_entries.begin()).name, "..") == 0 ) + if ( std::strcmp((*dir_entries.begin()).name, "..") == 0 ) start=1; else start=0; diff --git a/src/flabel.cpp b/src/flabel.cpp index 10fdac0d..6ec3db69 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -130,12 +130,12 @@ void FLabel::setHotkeyAccelerator() if ( hotkey ) { - if ( isalpha(hotkey) || isdigit(hotkey) ) + if ( std::isalpha(hotkey) || std::isdigit(hotkey) ) { - addAccelerator (tolower(hotkey)); - addAccelerator (toupper(hotkey)); + addAccelerator (std::tolower(hotkey)); + addAccelerator (std::toupper(hotkey)); // Meta + hotkey - addAccelerator (fc::Fmkey_meta + tolower(hotkey)); + addAccelerator (fc::Fmkey_meta + std::tolower(hotkey)); } else addAccelerator (getHotkey()); @@ -193,7 +193,7 @@ void FLabel::printLine ( wchar_t*& line for (int z=0; z < to_char; z++) { - if ( ! iswprint(wint_t(line[z])) ) + if ( ! std::iswprint(wint_t(line[z])) ) { if ( ! isNewFont() && ( int(line[z]) < fc::NF_rev_left_arrow2 || int(line[z]) > fc::NF_check_mark ) ) @@ -266,7 +266,7 @@ void FLabel::draw() hotkeypos = -1; - if ( multiline && getHeight() > 1 ) + if ( multiline && getHeight() >= 2 ) { uInt y = 0; uInt text_lines = uInt(multiline_text.size()); @@ -282,7 +282,7 @@ void FLabel::draw() if ( ! hotkey_printed ) hotkeypos = getHotkeyPos(src, dest, length); else - wcsncpy(dest, src, length); + std::wcsncpy(dest, src, length); printPos (1, 1+int(y)); @@ -361,7 +361,7 @@ void FLabel::hide() return; blank = new char[size+1]; - memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', uLong(size)); blank[getWidth()] = '\0'; printPos (1,1); print (blank); diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 6d8c3dee..a01c2911 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -58,9 +58,6 @@ FLineEdit::~FLineEdit() // destructor if ( isUrxvtTerminal() ) setXTermCursorColor("rgb:ffff/ffff/ffff"); } - - if ( hasFocus() ) - hideCursor(); } // private methods of FLineEdit @@ -221,15 +218,10 @@ void FLineEdit::drawInputField() if ( isShadow ) drawShadow (); - updateVTerm(true); - // set the cursor to the first pos. setCursorPos (2+cursor_pos-text_offset, 1); - if ( isCursorInside() && hasFocus() && isHiddenCursor() ) - showCursor(); - else if ( ! isHiddenCursor() ) - hideCursor(); + updateVTerm(true); } //---------------------------------------------------------------------- @@ -313,7 +305,7 @@ void FLineEdit::hide() return; blank = new char[size+1]; - memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', uLong(size)); blank[size] = '\0'; for (int y=0; y < getHeight()+s; y++) @@ -781,17 +773,11 @@ void FLineEdit::onHide (FHideEvent*) if ( isUrxvtTerminal() ) setXTermCursorColor("rgb:ffff/ffff/ffff"); } - - if ( hasFocus() ) - hideCursor(); } //---------------------------------------------------------------------- void FLineEdit::onFocusIn (FFocusEvent*) { - if ( isCursorInside() ) - showCursor(); - if ( insert_mode ) { setXTermCursorStyle(fc::blinking_underline); @@ -835,8 +821,6 @@ void FLineEdit::onFocusOut (FFocusEvent*) if ( isUrxvtTerminal() ) setXTermCursorColor("rgb:ffff/ffff/ffff"); } - - hideCursor(); } //---------------------------------------------------------------------- diff --git a/src/flistbox.cpp b/src/flistbox.cpp index c626894c..efd9bee8 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -141,7 +141,7 @@ void FListBox::draw() setReverse(true); if ( isNewFont() ) - drawBorder (1, getWidth() - 1, 1, getHeight()); + drawBorder (1, 1, getWidth() - 1, getHeight()); else drawBorder(); @@ -220,7 +220,7 @@ void FListBox::drawList() uInt start, end, inc_len; bool isFocus; - if ( data.empty() || getHeight() < 4 || getWidth() < 5 ) + if ( data.empty() || getHeight() <= 2 || getWidth() <= 4 ) return; isFocus = ((flags & fc::focus) != 0); @@ -466,12 +466,6 @@ void FListBox::drawList() unsetBold(); updateVTerm(true); - updateTerminal(); - flush_out(); - - if ( hasFocus() ) - setCursor(); - last_yoffset = yoffset; last_current = current; } diff --git a/src/fmenu.cpp b/src/fmenu.cpp index cfeda04e..49a1e40e 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -255,22 +255,22 @@ bool FMenu::isWindowsMenu (FWidget* w) const //---------------------------------------------------------------------- bool FMenu::isMenuBar (FWidget* w) const { - return bool ( strcmp ( w->getClassName() - , const_cast("FMenuBar") ) == 0 ); + return bool ( std::strcmp ( w->getClassName() + , const_cast("FMenuBar") ) == 0 ); } //---------------------------------------------------------------------- bool FMenu::isMenu (FWidget* w) const { - return bool ( strcmp ( w->getClassName() - , const_cast("FMenu") ) == 0 ); + return bool ( std::strcmp ( w->getClassName() + , const_cast("FMenu") ) == 0 ); } //---------------------------------------------------------------------- bool FMenu::isRadioMenuItem (FWidget* w) const { - return bool ( strcmp ( w->getClassName() - , const_cast("FRadioMenuItem") ) == 0 ); + return bool ( std::strcmp ( w->getClassName() + , const_cast("FRadioMenuItem") ) == 0 ); } //---------------------------------------------------------------------- @@ -516,9 +516,9 @@ bool FMenu::hotkeyMenu (FKeyEvent*& ev) int hotkey = (*iter)->getHotkey(); int key = ev->key(); - if ( isalpha(hotkey) || isdigit(hotkey) ) + if ( std::isalpha(hotkey) || std::isdigit(hotkey) ) { - if ( tolower(hotkey) == key || toupper(hotkey) == key ) + if ( std::tolower(hotkey) == key || std::toupper(hotkey) == key ) found = true; } else if ( hotkey == key ) @@ -594,7 +594,7 @@ void FMenu::draw() clearArea(); drawBorder(); drawItems(); - drawMenuShadow(); + drawShadow(); if ( isMonochron() ) setReverse(false); @@ -602,57 +602,6 @@ void FMenu::draw() updateVTerm(true); } -//---------------------------------------------------------------------- -void FMenu::drawBorder() -{ - if ( isNewFont() ) - { - int x1 = 1; - int x2 = 1 + getWidth() - 1; - int y1 = 1; - int y2 = 1 + getHeight() - 1; - - printPos (x1, y1); - print (fc::NF_border_corner_upper_left); // ⎡ - - for (int x=x1+1; x < x2; x++) - print (fc::NF_border_line_upper); // ¯ - - print (fc::NF_rev_border_corner_upper_right); // ⎤ - - for (int y=y1+1; y <= y2; y++) - { - printPos (x1, y); - // border left ⎸ - print (fc::NF_border_line_left); - printPos (x2, y); - // border right⎹ - print (fc::NF_rev_border_line_right); - } - - printPos (x1, y2); - // lower left corner border ⎣ - print (fc::NF_border_corner_lower_left); - - for (int x=1; x < getWidth()-1; x++) // low line _ - print (fc::NF_border_line_bottom); - - printPos (x2, y2); - // lower right corner border ⎦ - print (fc::NF_rev_border_corner_lower_right); - } - else - { - FWidget::drawBorder(); - } -} - -//---------------------------------------------------------------------- -void FMenu::drawMenuShadow() -{ - drawShadow(); -} - //---------------------------------------------------------------------- void FMenu::drawItems() { @@ -770,13 +719,25 @@ void FMenu::drawItems() if ( hotkeypos == -1 ) { + // set cursor to the first character if ( is_selected ) - setCursorPos (1, 2 + y); // first character + { + if ( is_checkable ) + (*iter)->setCursorPos (3, 1); + else + (*iter)->setCursorPos (2, 1); + } } else { if ( is_selected ) - setCursorPos (1 + hotkeypos, 2 + y); // hotkey + { + // set cursor to the hotkey position + if ( is_checkable ) + (*iter)->setCursorPos (3 + hotkeypos, 1); + else + (*iter)->setCursorPos (2 + hotkeypos, 1); + } txt_length--; to_char--; @@ -784,7 +745,7 @@ void FMenu::drawItems() for (int z=0; z < to_char; z++) { - if ( ! iswprint(wint_t(item_text[z])) ) + if ( ! std::iswprint(wint_t(item_text[z])) ) { if ( ! isNewFont() && ( int(item_text[z]) < fc::NF_rev_left_arrow2 @@ -854,9 +815,6 @@ void FMenu::drawItems() ++iter; y++; } - - if ( hasFocus() ) - setCursor(); } //---------------------------------------------------------------------- @@ -1464,19 +1422,6 @@ void FMenu::show() return; FWindow::show(); - - // set the cursor to the focus widget - FWidget* focus_widget = FWidget::getFocusWidget(); - - if ( focus_widget - && focus_widget->isVisible() - && focus_widget->hasVisibleCursor() - && focus_widget->isCursorInside() ) - { - focus_widget->setCursor(); - showCursor(); - flush_out(); - } } //---------------------------------------------------------------------- diff --git a/src/fmenu.h b/src/fmenu.h index f60d6f99..5a6702bf 100644 --- a/src/fmenu.h +++ b/src/fmenu.h @@ -82,10 +82,6 @@ class FMenu : public FWindow, public FMenuList bool hotkeyMenu (FKeyEvent*&); int getHotkeyPos (wchar_t*&, wchar_t*&, uInt); void draw(); - // make every drawBorder from FWidget available - using FWidget::drawBorder; - virtual void drawBorder(); - void drawMenuShadow(); void drawItems(); void drawSeparator(int); void processActivate(); diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 6af944cf..7c2c2632 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -227,7 +227,7 @@ bool FMenuBar::hotkeyMenu (FKeyEvent*& ev) int hotkey = (*iter)->getHotkey(); int key = ev->key(); - if ( fc::Fmkey_meta + tolower(hotkey) == key ) + if ( fc::Fmkey_meta + std::tolower(hotkey) == key ) { FMenuItem* sel_item = getSelectedItem(); @@ -397,7 +397,7 @@ void FMenuBar::drawItems() if ( startpos > screenWidth-z ) break; - if ( ! iswprint(wint_t(item_text[z])) ) + if ( ! std::iswprint(wint_t(item_text[z])) ) { if ( ! isNewFont() && ( int(item_text[z]) < fc::NF_rev_left_arrow2 || int(item_text[z]) > fc::NF_check_mark ) ) @@ -913,7 +913,7 @@ void FMenuBar::hide() return; blank = new char[screenWidth+1]; - memset(blank, ' ', uLong(screenWidth)); + std::memset(blank, ' ', uLong(screenWidth)); blank[screenWidth] = '\0'; printPos (1,1); print (blank); diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index 1b359cbd..e0af3dd1 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -199,7 +199,7 @@ void FMenuItem::init (FWidget* parent) menubar_ptr->calculateDimensions(); if ( hotkey ) // Meta + hotkey - menubar_ptr->addAccelerator (fc::Fmkey_meta + tolower(hotkey), this); + menubar_ptr->addAccelerator (fc::Fmkey_meta + std::tolower(hotkey), this); } this->addCallback @@ -357,8 +357,8 @@ bool FMenuItem::isMenuBar (FWidget* w) const if ( ! w ) return false; else - return bool( strcmp ( w->getClassName() - , const_cast("FMenuBar") ) == 0 ); + return bool( std::strcmp ( w->getClassName() + , const_cast("FMenuBar") ) == 0 ); } //---------------------------------------------------------------------- @@ -367,10 +367,10 @@ bool FMenuItem::isMenu (FWidget* w) const if ( ! w ) return false; - bool m1 = ( strcmp ( w->getClassName() - , const_cast("FMenu") ) == 0 ); - bool m2 = ( strcmp ( w->getClassName() - , const_cast("FDialogListMenu") ) == 0 ); + bool m1 = ( std::strcmp ( w->getClassName() + , const_cast("FMenu") ) == 0 ); + bool m2 = ( std::strcmp ( w->getClassName() + , const_cast("FDialogListMenu") ) == 0 ); return bool( m1 || m2 ); } @@ -752,7 +752,7 @@ bool FMenuItem::setEnable (bool on) if ( super && isMenuBar(super) ) { // Meta + hotkey - super->addAccelerator (fc::Fmkey_meta + tolower(hotkey), this); + super->addAccelerator (fc::Fmkey_meta + std::tolower(hotkey), this); } } else diff --git a/src/foptiattr.cpp b/src/foptiattr.cpp index 6a5879c6..12c16c74 100644 --- a/src/foptiattr.cpp +++ b/src/foptiattr.cpp @@ -2,7 +2,7 @@ // Provides: class FOptiAttr #include "foptiattr.h" -#include "string.h" +#include //---------------------------------------------------------------------- // class FOptiAttr @@ -228,7 +228,7 @@ void FOptiAttr::change_color (char_data*& term, char_data*& next) char* sgr_49; char* op = F_orig_pair.cap; - if ( op && strncmp (op, CSI "39;49;25m", 11) == 0 ) + if ( op && std::strncmp (op, CSI "39;49;25m", 11) == 0 ) sgr_49 = const_cast(CSI "49;25m"); else sgr_49 = const_cast(CSI "49m"); @@ -377,19 +377,19 @@ bool FOptiAttr::caused_reset_attributes (char*& cap, uChar test) if ( cap ) { - if ( (test & test_ansi_reset) && strncmp (cap, CSI "m", 3) == 0 ) + if ( (test & test_ansi_reset) && std::strncmp (cap, CSI "m", 3) == 0 ) return true; - if ( (test & test_adm3_reset) && strncmp (cap, ESC "G0", 3) == 0 ) + if ( (test & test_adm3_reset) && std::strncmp (cap, ESC "G0", 3) == 0 ) return true; - if ( (test & same_like_ue) && ue && strcmp (cap, ue) == 0 ) + if ( (test & same_like_ue) && ue && std::strcmp (cap, ue) == 0 ) return true; - if ( (test & same_like_se) && se && strcmp (cap, se) == 0 ) + if ( (test & same_like_se) && se && std::strcmp (cap, se) == 0 ) return true; - if ( (test & same_like_me) && me && strcmp (cap, me) == 0 ) + if ( (test & same_like_me) && me && std::strcmp (cap, me) == 0 ) return true; } @@ -457,7 +457,7 @@ inline bool FOptiAttr::append_sequence (char*& seq) { if ( seq ) { - strncat (attr_ptr, seq, sizeof(attr_buf) - strlen(attr_ptr) - 1 ); + std::strncat (attr_ptr, seq, sizeof(attr_buf) - std::strlen(attr_ptr) - 1 ); return true; } else @@ -469,7 +469,7 @@ inline bool FOptiAttr::replace_sequence (char*& seq) { if ( seq ) { - strncpy (attr_ptr, seq, sizeof(attr_buf) - 1); + std::strncpy (attr_ptr, seq, sizeof(attr_buf) - 1); return true; } else @@ -479,7 +479,7 @@ inline bool FOptiAttr::replace_sequence (char*& seq) //---------------------------------------------------------------------- inline bool FOptiAttr::setTermBold (char_data*& term) { - if ( append_sequence(F_enter_bold_mode.cap) ) + if ( term && append_sequence(F_enter_bold_mode.cap) ) return (term->bold = true); else return false; @@ -562,7 +562,7 @@ inline bool FOptiAttr::unsetTermItalic (char_data*& term) //---------------------------------------------------------------------- inline bool FOptiAttr::setTermUnderline (char_data*& term) { - if ( append_sequence(F_enter_underline_mode.cap) ) + if ( term && append_sequence(F_enter_underline_mode.cap) ) return (term->underline = true); else return false; @@ -1530,7 +1530,7 @@ char* FOptiAttr::change_attribute (char_data*& term, char_data*& next) setTermDoubleUnderline(term); } - if ( fake_reverse ) + if ( term && fake_reverse ) term->reverse = true; return attr_buf; diff --git a/src/foptimove.cpp b/src/foptimove.cpp index c998130a..d2d0f897 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -77,17 +77,17 @@ int FOptiMove::capDuration (char*& cap, int affcnt) for (p=cap; *p; p++) { // check for delay with padding character - if ( p[0] == '$' && p[1] == '<' && strchr(p, '>') ) + if ( p[0] == '$' && p[1] == '<' && std::strchr(p, '>') ) { float num=0; for (p += 2; *p != '>'; p++) { - if ( isdigit(uChar(*p)) ) + if ( std::isdigit(uChar(*p)) ) num = num * 10 + float(*p - '0'); else if ( *p == '*' ) num *= float(affcnt); - else if ( *p == '.' && *++p != '>' && isdigit(uChar(*p)) ) + else if ( *p == '.' && *++p != '>' && std::isdigit(uChar(*p)) ) num += float((*p - '0') / 10.0); } @@ -112,7 +112,7 @@ void FOptiMove::set_cursor_home (char*& cap) { F_cursor_home.cap = cap; F_cursor_home.duration = capDuration (cap, 0); - F_cursor_home.length = int(strlen(cap)); + F_cursor_home.length = int(std::strlen(cap)); } } @@ -123,7 +123,7 @@ void FOptiMove::set_cursor_to_ll (char*& cap) { F_cursor_to_ll.cap = cap; F_cursor_to_ll.duration = capDuration (cap, 0); - F_cursor_to_ll.length = int(strlen(cap)); + F_cursor_to_ll.length = int(std::strlen(cap)); } } @@ -134,7 +134,7 @@ void FOptiMove::set_carriage_return (char*& cap) { F_carriage_return.cap = cap; F_carriage_return.duration = capDuration (cap, 0); - F_carriage_return.length = int(strlen(cap)); + F_carriage_return.length = int(std::strlen(cap)); } } @@ -145,7 +145,7 @@ void FOptiMove::set_tabular (char*& cap) { F_tab.cap = cap; F_tab.duration = capDuration (cap, 0); - F_tab.length = int(strlen(cap)); + F_tab.length = int(std::strlen(cap)); } } @@ -156,7 +156,7 @@ void FOptiMove::set_back_tab (char*& cap) { F_back_tab.cap = cap; F_back_tab.duration = capDuration (cap, 0); - F_back_tab.length = int(strlen(cap)); + F_back_tab.length = int(std::strlen(cap)); } } @@ -167,7 +167,7 @@ void FOptiMove::set_cursor_up (char*& cap) { F_cursor_up.cap = cap; F_cursor_up.duration = capDuration (cap, 0); - F_cursor_up.length = int(strlen(cap)); + F_cursor_up.length = int(std::strlen(cap)); } } @@ -178,7 +178,7 @@ void FOptiMove::set_cursor_down (char*& cap) { F_cursor_down.cap = cap; F_cursor_down.duration = capDuration (cap, 0); - F_cursor_down.length = int(strlen(cap)); + F_cursor_down.length = int(std::strlen(cap)); } } @@ -189,7 +189,7 @@ void FOptiMove::set_cursor_left (char*& cap) { F_cursor_left.cap = cap; F_cursor_left.duration = capDuration (cap, 0); - F_cursor_left.length = int(strlen(cap)); + F_cursor_left.length = int(std::strlen(cap)); } } @@ -200,7 +200,7 @@ void FOptiMove::set_cursor_right (char*& cap) { F_cursor_right.cap = cap; F_cursor_right.duration = capDuration (cap, 0); - F_cursor_right.length = int(strlen(cap)); + F_cursor_right.length = int(std::strlen(cap)); } } @@ -212,7 +212,7 @@ void FOptiMove::set_cursor_address (char*& cap) char* temp = tgoto(cap, 23, 23); F_cursor_address.cap = cap; F_cursor_address.duration = capDuration (temp, 1); - F_cursor_address.length = int(strlen(cap)); + F_cursor_address.length = int(std::strlen(cap)); } } @@ -224,7 +224,7 @@ void FOptiMove::set_column_address (char*& cap) char* temp = tparm(cap, 23); F_column_address.cap = cap; F_column_address.duration = capDuration (temp, 1); - F_column_address.length = int(strlen(cap)); + F_column_address.length = int(std::strlen(cap)); } } @@ -236,7 +236,7 @@ void FOptiMove::set_row_address (char*& cap) char* temp = tparm(cap, 23); F_row_address.cap = cap; F_row_address.duration = capDuration (temp, 1); - F_row_address.length = int(strlen(cap)); + F_row_address.length = int(std::strlen(cap)); } } @@ -248,7 +248,7 @@ void FOptiMove::set_parm_up_cursor (char*& cap) char* temp = tparm(cap, 23); F_parm_up_cursor.cap = cap; F_parm_up_cursor.duration = capDuration (temp, 1); - F_parm_up_cursor.length = int(strlen(cap)); + F_parm_up_cursor.length = int(std::strlen(cap)); } } @@ -260,7 +260,7 @@ void FOptiMove::set_parm_down_cursor (char*& cap) char* temp = tparm(cap, 23); F_parm_down_cursor.cap = cap; F_parm_down_cursor.duration = capDuration (temp, 1); - F_parm_down_cursor.length = int(strlen(cap)); + F_parm_down_cursor.length = int(std::strlen(cap)); } } @@ -272,7 +272,7 @@ void FOptiMove::set_parm_left_cursor (char*& cap) char* temp = tparm(cap, 23); F_parm_left_cursor.cap = cap; F_parm_left_cursor.duration = capDuration (temp, 1); - F_parm_left_cursor.length = int(strlen(cap)); + F_parm_left_cursor.length = int(std::strlen(cap)); } } @@ -284,7 +284,7 @@ void FOptiMove::set_parm_right_cursor (char*& cap) char* temp = tparm(cap, 23); F_parm_right_cursor.cap = cap; F_parm_right_cursor.duration = capDuration (temp, 1); - F_parm_right_cursor.length = int(strlen(cap)); + F_parm_right_cursor.length = int(std::strlen(cap)); } } @@ -320,8 +320,8 @@ int FOptiMove::repeatedAppend (capability& o, int count, char* dst) register size_t dst_len; register int total; - src_len = strlen(o.cap); - dst_len = ( dst != 0 ) ? strlen(dst) : 0; + src_len = std::strlen(o.cap); + dst_len = ( dst != 0 ) ? std::strlen(dst) : 0; total = 0; if ( (dst_len + uInt(count) * src_len) < sizeof(move_buf)-1 ) @@ -334,7 +334,7 @@ int FOptiMove::repeatedAppend (capability& o, int count, char* dst) while ( count-- > 0 ) { - strcpy (dst, o.cap); + std::strcpy (dst, o.cap); dst += src_len; } } @@ -364,7 +364,7 @@ int FOptiMove::relativeMove ( char*& move if ( F_row_address.cap ) { if ( move ) - strcpy (move, tparm(F_row_address.cap, to_y)); + std::strcpy (move, tparm(F_row_address.cap, to_y)); vtime = F_row_address.duration; } @@ -376,7 +376,7 @@ int FOptiMove::relativeMove ( char*& move if ( F_parm_down_cursor.cap && F_parm_down_cursor.duration < vtime ) { if ( move ) - strcpy (move, tparm(F_parm_down_cursor.cap, num)); + std::strcpy (move, tparm(F_parm_down_cursor.cap, num)); vtime = F_parm_down_cursor.duration; } @@ -396,7 +396,7 @@ int FOptiMove::relativeMove ( char*& move if ( F_parm_up_cursor.cap && F_parm_up_cursor.duration < vtime ) { if ( move ) - strcpy (move, tparm(F_parm_up_cursor.cap, num)); + std::strcpy (move, tparm(F_parm_up_cursor.cap, num)); vtime = F_parm_up_cursor.duration; } @@ -422,9 +422,9 @@ int FOptiMove::relativeMove ( char*& move if ( F_column_address.cap ) { - strncat ( hmove - , tparm(F_column_address.cap, to_x) - , sizeof(hmove) - strlen(hmove) - 1 ); + std::strncat ( hmove + , tparm(F_column_address.cap, to_x) + , sizeof(hmove) - std::strlen(hmove) - 1 ); htime = F_column_address.duration; } @@ -434,9 +434,9 @@ int FOptiMove::relativeMove ( char*& move if ( F_parm_right_cursor.cap && F_parm_right_cursor.duration < htime ) { - strncat ( hmove - , tparm(F_parm_right_cursor.cap, num) - , sizeof(hmove) - strlen(hmove) - 1 ); + std::strncat ( hmove + , tparm(F_parm_right_cursor.cap, num) + , sizeof(hmove) - std::strlen(hmove) - 1 ); htime = F_parm_right_cursor.duration; } @@ -472,7 +472,7 @@ int FOptiMove::relativeMove ( char*& move if ( htime_r < htime ) { - strcpy (hmove, str); + std::strcpy (hmove, str); htime = htime_r; } @@ -484,9 +484,9 @@ int FOptiMove::relativeMove ( char*& move if ( F_parm_left_cursor.cap && F_parm_left_cursor.duration < htime ) { - strncat ( hmove - , tparm(F_parm_left_cursor.cap, num) - , sizeof(hmove) - strlen(hmove) - 1 ); + std::strncat ( hmove + , tparm(F_parm_left_cursor.cap, num) + , sizeof(hmove) - std::strlen(hmove) - 1 ); htime = F_parm_left_cursor.duration; } @@ -522,7 +522,7 @@ int FOptiMove::relativeMove ( char*& move if ( htime_l < htime ) { - strcpy (hmove, str); + std::strcpy (hmove, str); htime = htime_l; } @@ -537,7 +537,7 @@ int FOptiMove::relativeMove ( char*& move if ( *move ) strcat (move, hmove); else - strcpy (move, hmove); + std::strcpy (move, hmove); } } @@ -558,7 +558,7 @@ inline bool FOptiMove::isWideMove ( int xold, int yold { return bool ( (xnew > MOVE_LIMIT) && (xnew < screen_width - 1 - MOVE_LIMIT) - && (abs(xnew-xold) + abs(ynew-yold) > MOVE_LIMIT) ); + && (std::abs(xnew-xold) + std::abs(ynew-yold) > MOVE_LIMIT) ); } //---------------------------------------------------------------------- @@ -577,7 +577,7 @@ char* FOptiMove::cursor_move (int xold, int yold, int xnew, int ynew) if ( move_xy ) { method = 0; - strncpy (move_ptr, move_xy, sizeof(move_buf) - 1); + std::strncpy (move_ptr, move_xy, sizeof(move_buf) - 1); move_time = F_cursor_address.duration; if ( xold < 0 @@ -670,20 +670,20 @@ char* FOptiMove::cursor_move (int xold, int yold, int xnew, int ynew) case 2: if ( F_carriage_return.cap ) { - strncpy (move_ptr, F_carriage_return.cap, sizeof(move_buf) - 1); + std::strncpy (move_ptr, F_carriage_return.cap, sizeof(move_buf) - 1); move_ptr += F_carriage_return.length; relativeMove (move_ptr, 0, yold, xnew, ynew); } break; case 3: - strncpy (move_ptr, F_cursor_home.cap, sizeof(move_buf) - 1); + std::strncpy (move_ptr, F_cursor_home.cap, sizeof(move_buf) - 1); move_ptr += F_cursor_home.length; relativeMove (move_ptr, 0, 0, xnew, ynew); break; case 4: - strncpy (move_ptr, F_cursor_to_ll.cap, sizeof(move_buf) - 1); + std::strncpy (move_ptr, F_cursor_to_ll.cap, sizeof(move_buf) - 1); move_ptr += F_cursor_to_ll.length; relativeMove (move_ptr, 0, screen_height-1, xnew, ynew); break; @@ -692,14 +692,14 @@ char* FOptiMove::cursor_move (int xold, int yold, int xnew, int ynew) move_buf[0] = '\0'; if ( xold >= 0 ) - strncat ( move_ptr - , F_carriage_return.cap - , sizeof(move_buf) - strlen(move_ptr) - 1 ); + std::strncat ( move_ptr + , F_carriage_return.cap + , sizeof(move_buf) - std::strlen(move_ptr) - 1 ); - strncat ( move_ptr - , F_cursor_left.cap - , sizeof(move_buf) - strlen(move_ptr) - 1 ); - move_ptr += strlen(move_buf); + std::strncat ( move_ptr + , F_cursor_left.cap + , sizeof(move_buf) - std::strlen(move_ptr) - 1 ); + move_ptr += std::strlen(move_buf); relativeMove (move_ptr, screen_width-1, yold-1, xnew, ynew); break; @@ -717,22 +717,22 @@ char* FOptiMove::cursor_move (int xold, int yold, int xnew, int ynew) //---------------------------------------------------------------------- void FOptiMove::printDurations() { - ::printf (" speed: %d baud\n", baudrate); - ::printf (" char_duration: %d ms\n", char_duration); - ::printf (" cursor_home: %d ms\n", F_cursor_home.duration); - ::printf (" cursor_to_ll: %d ms\n", F_cursor_to_ll.duration); - ::printf (" carriage_return: %d ms\n", F_carriage_return.duration); - ::printf (" tab: %d ms\n", F_tab.duration); - ::printf (" back_tab: %d ms\n", F_back_tab.duration); - ::printf (" cursor_up: %d ms\n", F_cursor_up.duration); - ::printf (" cursor_down: %d ms\n", F_cursor_down.duration); - ::printf (" cursor_left: %d ms\n", F_cursor_left.duration); - ::printf (" cursor_right: %d ms\n", F_cursor_right.duration); - ::printf (" cursor_address: %d ms\n", F_cursor_address.duration); - ::printf (" column_address: %d ms\n", F_column_address.duration); - ::printf (" row_address: %d ms\n", F_row_address.duration); - ::printf (" parm_up_cursor: %d ms\n", F_parm_up_cursor.duration); - ::printf (" parm_down_cursor: %d ms\n", F_parm_down_cursor.duration); - ::printf (" parm_left_cursor: %d ms\n", F_parm_left_cursor.duration); - ::printf ("parm_right_cursor: %d ms\n", F_parm_right_cursor.duration); + std::printf (" speed: %d baud\n", baudrate); + std::printf (" char_duration: %d ms\n", char_duration); + std::printf (" cursor_home: %d ms\n", F_cursor_home.duration); + std::printf (" cursor_to_ll: %d ms\n", F_cursor_to_ll.duration); + std::printf (" carriage_return: %d ms\n", F_carriage_return.duration); + std::printf (" tab: %d ms\n", F_tab.duration); + std::printf (" back_tab: %d ms\n", F_back_tab.duration); + std::printf (" cursor_up: %d ms\n", F_cursor_up.duration); + std::printf (" cursor_down: %d ms\n", F_cursor_down.duration); + std::printf (" cursor_left: %d ms\n", F_cursor_left.duration); + std::printf (" cursor_right: %d ms\n", F_cursor_right.duration); + std::printf (" cursor_address: %d ms\n", F_cursor_address.duration); + std::printf (" column_address: %d ms\n", F_column_address.duration); + std::printf (" row_address: %d ms\n", F_row_address.duration); + std::printf (" parm_up_cursor: %d ms\n", F_parm_up_cursor.duration); + std::printf (" parm_down_cursor: %d ms\n", F_parm_down_cursor.duration); + std::printf (" parm_left_cursor: %d ms\n", F_parm_left_cursor.duration); + std::printf ("parm_right_cursor: %d ms\n", F_parm_right_cursor.duration); } diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index 4d191fad..87b8b233 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -201,7 +201,7 @@ void FProgressbar::hide() return; blank = new char[size+1]; - memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', uLong(size)); blank[size] = '\0'; for (int y=0; y < getHeight()+s; y++) diff --git a/src/frect.h b/src/frect.h index e1e72f9b..2148d391 100644 --- a/src/frect.h +++ b/src/frect.h @@ -160,11 +160,11 @@ inline FPoint FRect::getLowerRightPos() const //---------------------------------------------------------------------- inline int FRect::getWidth() const -{ return X2 - X1 + 1; } +{ return short(X2 - X1 + 1); } //---------------------------------------------------------------------- inline int FRect::getHeight() const -{ return Y2 - Y1 + 1; } +{ return short(Y2 - Y1 + 1); } //---------------------------------------------------------------------- inline short& FRect::x1_ref() diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index 42c60b10..7dfba296 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -73,8 +73,8 @@ void FStatusKey::init (FWidget* parent) { setGeometry (1,1,1,1); - if ( parent && strcmp ( parent->getClassName() - , const_cast("FStatusBar") ) == 0 ) + if ( parent && std::strcmp ( parent->getClassName() + , const_cast("FStatusBar") ) == 0 ) { setStatusbar( static_cast(parent) ); @@ -359,7 +359,7 @@ void FStatusBar::hide() return; blank = new char[screenWidth+1]; - memset(blank, ' ', uLong(screenWidth)); + std::memset(blank, ' ', uLong(screenWidth)); blank[screenWidth] = '\0'; printPos (1, 1); print (blank); @@ -733,7 +733,4 @@ void FStatusBar::cb_statuskey_activated (FWidget* widget, void*) if ( isVisible() && isShown() ) redraw(); - - if ( ! isHiddenCursor() ) - hideCursor(); } diff --git a/src/fstring.cpp b/src/fstring.cpp index 52734864..13b8bdc7 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -222,7 +222,7 @@ inline void FString::initLength (uInt len) length = len; bufsize = FWDBUFFER + len + 1; string = new wchar_t[bufsize](); - wmemset(string, L'\0', bufsize); + std::wmemset (string, L'\0', bufsize); } } @@ -232,7 +232,7 @@ inline void FString::_replace (const wchar_t* s) if ( string ) delete[](string); - length = uInt(wcslen(s)); + length = uInt(std::wcslen(s)); bufsize = FWDBUFFER + length + 1; try @@ -250,7 +250,7 @@ inline void FString::_replace (const wchar_t* s) << e.what() << std::endl; return; }*/ - wcscpy (string, s); + std::wcscpy (string, s); } //---------------------------------------------------------------------- @@ -272,7 +272,7 @@ inline void FString::_insert (uInt pos, uInt len, const wchar_t* s) return; } - wcscpy (string, s); + std::wcscpy (string, s); return; } else @@ -392,18 +392,18 @@ inline char* FString::wc_to_c_str (const wchar_t* s) const if ( c_string ) delete[](c_string); - size = int(wcslen(s)) + 1; + size = int(std::wcslen(s)) + 1; dest_size = size * int(CHAR_SIZE); src = s; - mbstate_t state; - memset (&state, '\0', sizeof(mbstate_t)); + std::mbstate_t state; + std::memset (&state, '\0', sizeof(mbstate_t)); try { c_string = new char[dest_size](); // pre-initialiaze the whole string with '\0' - memset (c_string, '\0', size_t(dest_size)); + std::memset (c_string, '\0', size_t(dest_size)); } catch (const std::bad_alloc& ex) { @@ -411,7 +411,7 @@ inline char* FString::wc_to_c_str (const wchar_t* s) const return 0; } - mblength = int(wcsrtombs (c_string, &src, uLong(dest_size), &state)); + mblength = int(std::wcsrtombs (c_string, &src, uLong(dest_size), &state)); if ( mblength == -1 && errno != EILSEQ ) { @@ -447,17 +447,17 @@ inline wchar_t* FString::c_to_wc_str (const char* s) const } } - size = int(strlen(s)) + 1; + size = int(std::strlen(s)) + 1; dest_size = size * int(CHAR_SIZE); src = s; - mbstate_t state; - memset (&state, '\0', sizeof(mbstate_t)); + std::mbstate_t state; + std::memset (&state, '\0', sizeof(mbstate_t)); try { dest = new wchar_t[size](); // pre-initialiaze the whole string with '\0' - wmemset (dest, L'\0', size_t(size)); + std::wmemset (dest, L'\0', size_t(size)); } catch (const std::bad_alloc& ex) { @@ -465,7 +465,7 @@ inline wchar_t* FString::c_to_wc_str (const char* s) const return 0; } - wclength = int(mbsrtowcs (dest, &src, uLong(dest_size), &state)); + wclength = int(std::mbsrtowcs (dest, &src, uLong(dest_size), &state)); if ( wclength == -1 ) { @@ -501,12 +501,12 @@ inline wchar_t* FString::extractToken ( wchar_t** rest if ( ! *token ) return 0; - *rest = wcspbrk(token, delim); + *rest = std::wcspbrk(token, delim); if ( *rest ) *(*rest)++ = '\0'; else - *rest = token + wcslen(token); + *rest = token + std::wcslen(token); return token; } @@ -659,7 +659,7 @@ const FString& FString::operator += (const std::wstring& s) //---------------------------------------------------------------------- const FString& FString::operator += (const wchar_t* s) { - _insert (length, uInt(wcslen(s)), s); + _insert (length, uInt(std::wcslen(s)), s); return (*this); } @@ -684,7 +684,7 @@ const FString& FString::operator += (const char* s) if ( wc_string ) { - _insert (length, uInt(strlen(s)), wc_string); + _insert (length, uInt(std::strlen(s)), wc_string); delete[] wc_string; } @@ -731,7 +731,7 @@ const FString FString::operator + (const std::wstring& s) const FString FString::operator + (const wchar_t* s) { FString tmp(string); - tmp._insert (length, uInt(wcslen(s)), s); + tmp._insert (length, uInt(std::wcslen(s)), s); return (tmp); } @@ -744,7 +744,7 @@ const FString FString::operator + (const std::string& s) if ( ! wc_string ) return (tmp); - tmp._insert (length, uInt(wcslen(wc_string)), wc_string); + tmp._insert (length, uInt(std::wcslen(wc_string)), wc_string); delete[] wc_string; return (tmp); } @@ -758,7 +758,7 @@ const FString FString::operator + (const char* s) if ( ! wc_string ) return (tmp); - tmp._insert (length, uInt(wcslen(wc_string)), wc_string); + tmp._insert (length, uInt(std::wcslen(wc_string)), wc_string); delete[] wc_string; return (tmp); } @@ -789,8 +789,8 @@ const FString FString::operator + (const char c) const FString operator + (const FString& s1, const FString& s2) { FString tmp(s1); - tmp._insert ( uInt(wcslen(s1.wc_str())) - , uInt(wcslen(s2.wc_str())) + tmp._insert ( uInt(std::wcslen(s1.wc_str())) + , uInt(std::wcslen(s2.wc_str())) , s2.wc_str() ); return (tmp); } @@ -799,7 +799,7 @@ const FString operator + (const FString& s1, const FString& s2) const FString operator + (const FString& s, const wchar_t c) { FString tmp(s); - tmp._insert ( uInt(wcslen(s.wc_str())), 1, &c); + tmp._insert ( uInt(std::wcslen(s.wc_str())), 1, &c); return (tmp); } @@ -807,8 +807,8 @@ const FString operator + (const FString& s, const wchar_t c) const FString operator + (const std::wstring& s1, const FString& s2) { FString tmp(s1); - tmp._insert ( uInt(wcslen(s1.c_str())) - , uInt(wcslen(s2.wc_str())) + tmp._insert ( uInt(std::wcslen(s1.c_str())) + , uInt(std::wcslen(s2.wc_str())) , s2.wc_str() ); return (tmp); } @@ -817,8 +817,8 @@ const FString operator + (const std::wstring& s1, const FString& s2) const FString operator + (const wchar_t* s1, const FString& s2) { FString tmp(s1); - tmp._insert ( uInt(wcslen(s1)) - , uInt(wcslen(s2.wc_str())) + tmp._insert ( uInt(std::wcslen(s1)) + , uInt(std::wcslen(s2.wc_str())) , s2.wc_str() ); return (tmp); } @@ -828,7 +828,7 @@ const FString operator + (const std::string& s1, const FString& s2) { FString tmp(s1); tmp._insert ( tmp.getLength() - , uInt(wcslen(s2.wc_str())) + , uInt(std::wcslen(s2.wc_str())) , s2.wc_str() ); return (tmp); } @@ -838,7 +838,7 @@ const FString operator + (const char* s1, const FString& s2) { FString tmp(s1); tmp._insert ( tmp.getLength() - , uInt(wcslen(s2.wc_str())) + , uInt(std::wcslen(s2.wc_str())) , s2.wc_str() ); return (tmp); } @@ -847,7 +847,7 @@ const FString operator + (const char* s1, const FString& s2) const FString operator + (const wchar_t c, const FString& s) { FString tmp(c); - tmp._insert (1, uInt(wcslen(s.wc_str())), s.wc_str()); + tmp._insert (1, uInt(std::wcslen(s.wc_str())), s.wc_str()); return (tmp); } @@ -855,7 +855,7 @@ const FString operator + (const wchar_t c, const FString& s) const FString operator + (const char c, const FString& s) { FString tmp(c); - tmp._insert (1, uInt(wcslen(s.wc_str())), s.wc_str()); + tmp._insert (1, uInt(std::wcslen(s.wc_str())), s.wc_str()); return (tmp); } @@ -920,7 +920,7 @@ FString& FString::sprintf (const wchar_t* format, ...) va_list args; va_start (args, format); - vswprintf (buffer, buf_size, format, args); + std::vswprintf (buffer, buf_size, format, args); va_end (args); _replace (buffer); @@ -938,14 +938,14 @@ FString& FString::sprintf (const char* format, ...) buffer = buf; va_start (args, format); - len = vsnprintf (buffer, sizeof(buf), format, args); + len = std::vsnprintf (buffer, sizeof(buf), format, args); va_end (args); if ( len >= int(sizeof(buf)) ) { buffer = new char[len+1](); va_start (args, format); - vsnprintf (buffer, uLong(len+1), format, args); + std::vsnprintf (buffer, uLong(len+1), format, args); va_end (args); } @@ -1004,7 +1004,7 @@ FString FString::toLower() const { while ( *p ) { - *p = wchar_t(towlower(uInt(*p))); + *p = wchar_t(std::towlower(uInt(*p))); p++; } } @@ -1023,7 +1023,7 @@ FString FString::toUpper() const { while ( *p ) { - *p = wchar_t(towupper(uInt(*p))); + *p = wchar_t(std::towupper(uInt(*p))); p++; } } @@ -1111,7 +1111,7 @@ long FString::toLong() const p++; } - while ( isdigit(*p) ) + while ( std::isdigit(*p) ) { register uChar d = uChar((*p) - L'0'); @@ -1125,7 +1125,7 @@ long FString::toLong() const p++; } - if ( *p != L'\0' && ! isdigit(*p) ) + if ( *p != L'\0' && ! std::isdigit(*p) ) throw std::invalid_argument ("no valid number"); return num; @@ -1157,7 +1157,7 @@ uLong FString::toULong() const p++; } - while ( isdigit(*p) ) + while ( std::isdigit(*p) ) { register uChar d = uChar((*p) - L'0'); @@ -1171,7 +1171,7 @@ uLong FString::toULong() const p++; } - if ( *p != L'\0' && ! isdigit(*p) ) + if ( *p != L'\0' && ! std::isdigit(*p) ) throw std::invalid_argument ("no valid number"); return num; @@ -1201,7 +1201,7 @@ double FString::toDouble() const if ( ! *string ) throw std::invalid_argument ("empty value"); - ret = wcstod(string, &p); + ret = std::wcstod(string, &p); if ( p != 0 && *p != '\0' ) throw std::invalid_argument ("no valid floating point value"); @@ -1211,7 +1211,7 @@ double FString::toDouble() const if ( ret >= HUGE_VAL || ret <= -HUGE_VAL ) throw std::overflow_error ("overflow"); - if ( fabs(ret) < DBL_EPSILON ) // ret == 0.0l + if ( std::fabs(ret) < DBL_EPSILON ) // ret == 0.0l throw std::underflow_error ("underflow"); } @@ -1230,7 +1230,7 @@ FString FString::ltrim() const p = s.string; - while ( iswspace(uInt(*p)) ) + while ( std::iswspace(uInt(*p)) ) p++; return FString(p); @@ -1250,9 +1250,9 @@ FString FString::rtrim() const p = s.string; last = p + length; - while ( iswspace(uInt(*--last)) && last > p ); + while ( std::iswspace(uInt(*--last)) && last > p ); - if ( last == p && iswspace(uInt(*last)) ) + if ( last == p && std::iswspace(uInt(*last)) ) s.clear(); else *(last+1) = '\0'; @@ -1580,7 +1580,7 @@ bool FString::operator < (const FString& s) const if ( ! (string || s.string) ) return false; - return (wcscmp(string, s.string) < 0); + return (std::wcscmp(string, s.string) < 0); } //---------------------------------------------------------------------- @@ -1640,7 +1640,7 @@ bool FString::operator <= (const FString& s) const if ( ! (string || s.string) ) return true; - return (wcscmp(string, s.string) <= 0); + return (std::wcscmp(string, s.string) <= 0); } //---------------------------------------------------------------------- @@ -1697,7 +1697,7 @@ bool FString::operator == (const FString& s) const if ( ! (string || s.string) ) return true; - return (wcscmp(string, s.string) == 0); + return (std::wcscmp(string, s.string) == 0); } //---------------------------------------------------------------------- @@ -1754,7 +1754,7 @@ bool FString::operator != (const FString& s) const if ( ! (string || s.string) ) return false; - return (wcscmp(string, s.string) != 0); + return (std::wcscmp(string, s.string) != 0); } //---------------------------------------------------------------------- @@ -1814,7 +1814,7 @@ bool FString::operator >= (const FString& s) const if ( ! (string || s.string) ) return true; - return (wcscmp(string, s.string) >= 0); + return (std::wcscmp(string, s.string) >= 0); } //---------------------------------------------------------------------- @@ -1874,7 +1874,7 @@ bool FString::operator > (const FString& s) const if ( ! (string || s.string) ) return false; - return (wcscmp(string, s.string) > 0); + return (std::wcscmp(string, s.string) > 0); } //---------------------------------------------------------------------- @@ -1937,7 +1937,7 @@ const FString& FString::insert (const wchar_t* s, uInt pos) if ( pos >= length ) throw std::out_of_range(""); - _insert (pos, uInt(wcslen(s)), s); + _insert (pos, uInt(std::wcslen(s)), s); return (*this); } @@ -1980,7 +1980,7 @@ FString FString::replace (const FString& from, const FString& to) while ( *p ) { - if ( wcsncmp(p, from.string, from_length) == 0 ) + if ( std::wcsncmp(p, from.string, from_length) == 0 ) { s._remove(pos, from_length); s._insert(pos, to_length, to.string); @@ -2409,7 +2409,7 @@ FString FString::replaceControlCodes() const { *p = L' '; } - else if ( ! iswprint(wint_t(*p)) ) + else if ( ! std::iswprint(wint_t(*p)) ) *p = L' '; p++; @@ -2518,11 +2518,11 @@ const FString& FString::overwrite (const FString& s, uInt pos) { if (length >= (pos + s.length)) { - wcsncpy(string + pos, s.string, s.length); + std::wcsncpy (string + pos, s.string, s.length); } else { - wcsncpy (string + pos, s.string, length - pos); + std::wcsncpy (string + pos, s.string, length - pos); _insert (length, pos + s.length - length, s.string + length - pos); } @@ -2532,15 +2532,15 @@ const FString& FString::overwrite (const FString& s, uInt pos) //---------------------------------------------------------------------- const FString& FString::overwrite (const wchar_t* s, uInt pos) { - uInt len = uInt(wcslen(s)); + uInt len = uInt(std::wcslen(s)); if (length >= (pos+len) ) { - wcsncpy (string + pos, s, len); + std::wcsncpy (string + pos, s, len); } else { - wcsncpy (string + pos, s, length - pos); + std::wcsncpy (string + pos, s, length - pos); _insert (length, pos + len - length, s + length - pos); } @@ -2570,13 +2570,13 @@ const FString& FString::remove (uInt pos, uInt len) //---------------------------------------------------------------------- bool FString::includes (const FString& s) { - return (wcsstr(string, s.string) != 0); + return (std::wcsstr(string, s.string) != 0); } //---------------------------------------------------------------------- bool FString::includes (const wchar_t* s) { - return (wcsstr(string, s) != 0); + return (std::wcsstr(string, s) != 0); } //---------------------------------------------------------------------- @@ -2588,7 +2588,7 @@ bool FString::includes (const char* s) if ( ! wc_string ) return false; - ret = bool(wcsstr(string, wc_string) != 0); + ret = bool(std::wcsstr(string, wc_string) != 0); delete[] wc_string; return (ret); } @@ -2599,7 +2599,7 @@ bool FString::includes (const wchar_t c) wchar_t s[2]; s[0] = c; s[1] = L'\0'; - return (wcsstr(string, s) != 0); + return (std::wcsstr(string, s) != 0); } //---------------------------------------------------------------------- @@ -2608,5 +2608,5 @@ bool FString::includes (const char c) wchar_t s[2]; s[0] = wchar_t(c & 0xff); s[1] = L'\0'; - return (wcsstr(string, s) != 0); + return (std::wcsstr(string, s) != 0); } diff --git a/src/fswitch.cpp b/src/fswitch.cpp index de09f401..24cc8d06 100644 --- a/src/fswitch.cpp +++ b/src/fswitch.cpp @@ -62,7 +62,7 @@ void FSwitch::drawCheckButton() { if ( isMonochron() ) { - wcsncpy ( on, L" ", 6); + std::wcsncpy ( on, L" ", 6); setBold(true); } else if ( getMaxColor() < 16 ) @@ -113,7 +113,7 @@ void FSwitch::drawCheckButton() { if ( isMonochron() ) { - wcsncpy ( off, L"", 6); + std::wcsncpy ( off, L"", 6); setBold(true); } else if ( getMaxColor() < 16 ) diff --git a/src/fterm.cpp b/src/fterm.cpp index f193685a..51582b56 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -26,8 +26,6 @@ int (*FTerm::Fputchar)(int); int FTerm::stdin_no; int FTerm::stdout_no; int FTerm::fd_tty; -int FTerm::x_term_pos; -int FTerm::y_term_pos; int FTerm::max_color; int FTerm::stdin_status_flags; uInt FTerm::baudrate; @@ -85,6 +83,7 @@ char FTerm::termtype[30] = ""; char* FTerm::term_name = 0; char* FTerm::locale_name = 0; char* FTerm::locale_xterm = 0; +FPoint* FTerm::term_pos = 0; FPoint* FTerm::mouse = 0; FPoint* FTerm::cursor = 0; FRect* FTerm::term = 0; @@ -101,6 +100,7 @@ FTerm::modifier_key FTerm::mod_key; FTerm::term_area* FTerm::vterm = 0; FTerm::term_area* FTerm::vdesktop = 0; FTerm::term_area* FTerm::last_area = 0; +FTerm::term_area* FTerm::active_area = 0; std::queue* FTerm::output_buffer = 0; std::map* FTerm::vt100_alt_char = 0; std::map* \ @@ -133,14 +133,12 @@ FTerm::FTerm() vterm = 0; vdesktop = 0; last_area = 0; - x_term_pos = -1; - y_term_pos = -1; - - opti_move = new FOptiMove(); - opti_attr = new FOptiAttr(); - term = new FRect(0,0,0,0); - mouse = new FPoint(0,0); - cursor = new FPoint(0,0); + opti_move = new FOptiMove(); + opti_attr = new FOptiAttr(); + term = new FRect(0,0,0,0); + term_pos = new FPoint(-1,-1); + mouse = new FPoint(0,0); + cursor = new FPoint(0,0); init(); } @@ -154,13 +152,14 @@ FTerm::~FTerm() // destructor this->finish(); delete cursor; delete mouse; + delete term_pos; delete term; delete opti_attr; delete opti_move; if ( exit_message[0] ) { - fprintf (stderr, "Warning: %s\n", exit_message); + std::fprintf (stderr, "Warning: %s\n", exit_message); } } } @@ -272,11 +271,11 @@ int FTerm::isConsole() void FTerm::identifyTermType() { // Import the untrusted environment variable TERM - const char* term_env = getenv(const_cast("TERM")); + const char* term_env = std::getenv(const_cast("TERM")); if ( term_env ) { - strncpy (termtype, term_env, sizeof(termtype) - 1); + std::strncpy (termtype, term_env, sizeof(termtype) - 1); return; } else if ( term_name ) @@ -290,10 +289,10 @@ void FTerm::identifyTermType() // linux tty1 // vt100 ttys0 - FILE *fp; + std::FILE *fp; - if ( (fp = fopen("/etc/ttytype", "r")) != 0 - || (fp = fopen("/etc/ttys", "r")) != 0 ) + if ( (fp = std::fopen("/etc/ttytype", "r")) != 0 + || (fp = std::fopen("/etc/ttys", "r")) != 0 ) { char* p; char* type; @@ -301,7 +300,7 @@ void FTerm::identifyTermType() char str[BUFSIZ]; // get term basename - const char* term_basename = strrchr(term_name, '/'); + const char* term_basename = std::strrchr(term_name, '/'); if ( term_basename == 0 ) term_basename = term_name; @@ -316,7 +315,7 @@ void FTerm::identifyTermType() while ( *p ) { - if ( isspace(uChar(*p)) ) + if ( std::isspace(uChar(*p)) ) *p = '\0'; else if ( type == 0 ) type = p; @@ -326,20 +325,20 @@ void FTerm::identifyTermType() p++; } - if ( type != 0 && name != 0 && ! strcmp(name, term_basename) ) + if ( type != 0 && name != 0 && ! std::strcmp(name, term_basename) ) { - strncpy (termtype, type, sizeof(termtype) - 1); - fclose(fp); + std::strncpy (termtype, type, sizeof(termtype) - 1); + std::fclose(fp); return; } } - fclose(fp); + std::fclose(fp); } } // use vt100 if not found - strncpy (termtype, const_cast("vt100"), 6); + std::strncpy (termtype, const_cast("vt100"), 6); } //---------------------------------------------------------------------- @@ -416,9 +415,9 @@ int FTerm::setScreenFont ( uChar* fontdata, uInt count } for (uInt i=0; i < count; i++) - memcpy ( const_cast(font.data + bytes_per_line*32*i) - , &fontdata[i * font.height] - , font.height); + std::memcpy ( const_cast(font.data + bytes_per_line*32*i) + , &fontdata[i * font.height] + , font.height); } // font operation ret = ioctl (fd_tty, KDFONTOP, &font); @@ -575,7 +574,7 @@ int FTerm::parseKeyString ( char* buffer , timeval* time_keypressed ) { register uChar firstchar = uChar(buffer[0]); - register size_t buf_len = strlen(buffer); + register size_t buf_len = std::strlen(buffer); const long key_timeout = 100000; // 100 ms int key, len, n; @@ -600,9 +599,9 @@ int FTerm::parseKeyString ( char* buffer for (int i=0; Fkey[i].tname[0] != 0; i++) { char* k = Fkey[i].string; - len = (k) ? int(strlen(k)) : 0; + len = (k) ? int(std::strlen(k)) : 0; - if ( k && strncmp(k, buffer, uInt(len)) == 0 ) // found + if ( k && std::strncmp(k, buffer, uInt(len)) == 0 ) // found { n = len; @@ -621,9 +620,9 @@ int FTerm::parseKeyString ( char* buffer for (int i=0; Fmetakey[i].string[0] != 0; i++) { char* kmeta = Fmetakey[i].string; // The string is never null - len = int(strlen(kmeta)); + len = int(std::strlen(kmeta)); - if ( strncmp(kmeta, buffer, uInt(len)) == 0 ) // found + if ( std::strncmp(kmeta, buffer, uInt(len)) == 0 ) // found { if ( len == 2 && ( buffer[1] == 'O' || buffer[1] == '[' @@ -820,11 +819,12 @@ void FTerm::signal_handler (int signum) case SIGILL: case SIGSEGV: term_object->finish(); - fflush (stderr); fflush (stdout); - fprintf ( stderr - , "\nProgram stopped: signal %d (%s)\n" - , signum - , strsignal(signum) ); + std::fflush (stderr); + std::fflush (stdout); + std::fprintf ( stderr + , "\nProgram stopped: signal %d (%s)\n" + , signum + , strsignal(signum) ); std::terminate(); } } @@ -837,58 +837,58 @@ char* FTerm::init_256colorTerminal() char *s1, *s2, *s3, *s4, *s5, *s6; // Enable 256 color capabilities - s1 = getenv("COLORTERM"); - s2 = getenv("VTE_VERSION"); - s3 = getenv("XTERM_VERSION"); - s4 = getenv("ROXTERM_ID"); - s5 = getenv("KONSOLE_DBUS_SESSION"); - s6 = getenv("KONSOLE_DCOP"); + s1 = std::getenv("COLORTERM"); + s2 = std::getenv("VTE_VERSION"); + s3 = std::getenv("XTERM_VERSION"); + s4 = std::getenv("ROXTERM_ID"); + s5 = std::getenv("KONSOLE_DBUS_SESSION"); + s6 = std::getenv("KONSOLE_DCOP"); if ( s1 != 0 ) - strncat (local256, s1, sizeof(local256) - strlen(local256) - 1); + std::strncat (local256, s1, sizeof(local256) - std::strlen(local256) - 1); if ( s2 != 0 ) - strncat (local256, s2, sizeof(local256) - strlen(local256) - 1); + std::strncat (local256, s2, sizeof(local256) - std::strlen(local256) - 1); if ( s3 != 0 ) - strncat (local256, s3, sizeof(local256) - strlen(local256) - 1); + std::strncat (local256, s3, sizeof(local256) - std::strlen(local256) - 1); if ( s4 != 0 ) - strncat (local256, s4, sizeof(local256) - strlen(local256) - 1); + std::strncat (local256, s4, sizeof(local256) - std::strlen(local256) - 1); if ( s5 != 0 ) - strncat (local256, s5, sizeof(local256) - strlen(local256) - 1); + std::strncat (local256, s5, sizeof(local256) - std::strlen(local256) - 1); if ( s6 != 0 ) - strncat (local256, s6, sizeof(local256) - strlen(local256) - 1); + std::strncat (local256, s6, sizeof(local256) - std::strlen(local256) - 1); - if ( strlen(local256) > 0 ) + if ( std::strlen(local256) > 0 ) { - if ( strncmp(termtype, "xterm", 5) == 0 ) + if ( std::strncmp(termtype, "xterm", 5) == 0 ) new_termtype = const_cast("xterm-256color"); - if ( strncmp(termtype, "screen", 6) == 0 ) + if ( std::strncmp(termtype, "screen", 6) == 0 ) { new_termtype = const_cast("screen-256color"); screen_terminal = true; - char* tmux = getenv("TMUX"); + char* tmux = std::getenv("TMUX"); - if ( tmux && strlen(tmux) != 0 ) + if ( tmux && std::strlen(tmux) != 0 ) tmux_terminal = true; } - if ( strncmp(termtype, "Eterm", 5) == 0 ) + if ( std::strncmp(termtype, "Eterm", 5) == 0 ) new_termtype = const_cast("Eterm-256color"); - if ( strncmp(termtype, "mlterm", 6) == 0 ) + if ( std::strncmp(termtype, "mlterm", 6) == 0 ) { new_termtype = const_cast("mlterm-256color"); mlterm_terminal = true; } - if ( strncmp(termtype, "rxvt", 4) != 0 + if ( std::strncmp(termtype, "rxvt", 4) != 0 && s1 - && strncmp(s1, "rxvt-xpm", 8) == 0 ) + && std::strncmp(s1, "rxvt-xpm", 8) == 0 ) { new_termtype = const_cast("rxvt-256color"); rxvt_terminal = true; @@ -896,22 +896,20 @@ char* FTerm::init_256colorTerminal() color256 = true; } - else if ( strstr (termtype, "256color") ) + else if ( std::strstr (termtype, "256color") ) color256 = true; else color256 = false; - if ( (s5 && strlen(s5) > 0) || (s6 && strlen(s6) > 0) ) + if ( (s5 && std::strlen(s5) > 0) || (s6 && std::strlen(s6) > 0) ) kde_konsole = true; - if ( (s1 && strncmp(s1, "gnome-terminal", 14) == 0) || s2 ) + if ( (s1 && std::strncmp(s1, "gnome-terminal", 14) == 0) || s2 ) { - if ( color256 ) - new_termtype = const_cast("gnome-256color"); - else - new_termtype = const_cast("gnome"); - gnome_terminal = true; + // Each gnome-terminal should be able to use 256 colors + color256 = true; + new_termtype = const_cast("gnome-256color"); } return new_termtype; @@ -938,7 +936,7 @@ char* FTerm::parseAnswerbackMsg (char*& current_termtype) putty_terminal = false; if ( cygwin_terminal ) - putchar (BS[0]); // cygwin needs a backspace to delete the '♣' char + std::putchar (BS[0]); // cygwin needs a backspace to delete the '♣' char return new_termtype; } @@ -1021,12 +1019,10 @@ char* FTerm::parseSecDA (char*& current_termtype) } else if ( terminal_id_version > 1000 ) { - gnome_terminal = true; // vte / gnome terminal - - if ( color256 ) - new_termtype = const_cast("gnome-256color"); - else - new_termtype = const_cast("gnome"); + gnome_terminal = true; + // Each gnome-terminal should be able to use 256 colors + color256 = true; + new_termtype = const_cast("gnome-256color"); } break; @@ -1040,7 +1036,7 @@ char* FTerm::parseSecDA (char*& current_termtype) new_termtype = const_cast("xterm-256color"); // application escape key mode putstring (CSI "?7727h"); - fflush(stdout); + std::fflush(stdout); break; case 83: // screen @@ -1051,8 +1047,8 @@ char* FTerm::parseSecDA (char*& current_termtype) rxvt_terminal = true; force_vt100 = true; // this rxvt terminal support on utf-8 - if ( strncmp(termtype, "rxvt-", 5) != 0 - || strncmp(termtype, "rxvt-cygwin-native", 5) == 0 ) + if ( std::strncmp(termtype, "rxvt-", 5) != 0 + || std::strncmp(termtype, "rxvt-cygwin-native", 5) == 0 ) new_termtype = const_cast("rxvt-16color"); break; @@ -1060,7 +1056,7 @@ char* FTerm::parseSecDA (char*& current_termtype) rxvt_terminal = true; urxvt_terminal = true; - if ( strncmp(termtype, "rxvt-", 5) != 0 ) + if ( std::strncmp(termtype, "rxvt-", 5) != 0 ) { if ( color256 ) new_termtype = const_cast("rxvt-256color"); @@ -1287,7 +1283,7 @@ void FTerm::init_termcaps() const_cast(CSI "5m"); // set enter/exit alternative charset mode for rxvt terminal - if ( rxvt_terminal && strncmp(termtype, "rxvt-16color", 12) == 0 ) + if ( rxvt_terminal && std::strncmp(termtype, "rxvt-16color", 12) == 0 ) { tcap[t_enter_alt_charset_mode].string = \ const_cast(ESC "(0"); @@ -1401,7 +1397,7 @@ void FTerm::init_termcaps() // test for standard ECMA-48 (ANSI X3.64) terminal if ( tcap[t_exit_underline_mode].string - && strncmp(tcap[t_exit_underline_mode].string, CSI "24m", 5) == 0 ) + && std::strncmp(tcap[t_exit_underline_mode].string, CSI "24m", 5) == 0 ) { // seems to be a ECMA-48 (ANSI X3.64) compatible terminal tcap[t_enter_dbl_underline_mode].string = \ @@ -1441,26 +1437,26 @@ void FTerm::init_termcaps() Fkey[i].string = tgetstr(Fkey[i].tname, &buffer); // fallback for rxvt with TERM=xterm - if ( strncmp(Fkey[i].tname, "khx", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "khx", 3) == 0 ) Fkey[i].string = const_cast(CSI "7~"); // home key - if ( strncmp(Fkey[i].tname, "@7x", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "@7x", 3) == 0 ) Fkey[i].string = const_cast(CSI "8~"); // end key - if ( strncmp(Fkey[i].tname, "k1x", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "k1x", 3) == 0 ) Fkey[i].string = const_cast(CSI "11~"); // F1 - if ( strncmp(Fkey[i].tname, "k2x", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "k2x", 3) == 0 ) Fkey[i].string = const_cast(CSI "12~"); // F2 - if ( strncmp(Fkey[i].tname, "k3x", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "k3x", 3) == 0 ) Fkey[i].string = const_cast(CSI "13~"); // F3 - if ( strncmp(Fkey[i].tname, "k4x", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "k4x", 3) == 0 ) Fkey[i].string = const_cast(CSI "14~"); // F4 // fallback for TERM=ansi - if ( strncmp(Fkey[i].tname, "@7X", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "@7X", 3) == 0 ) Fkey[i].string = const_cast(CSI "K"); // end key } @@ -1469,34 +1465,34 @@ void FTerm::init_termcaps() // ..110380-using-arrow-keys-shell-scripts.html key_up_string = tgetstr(const_cast("ku"), &buffer); - if ( (key_up_string && (strcmp(key_up_string, CSI "A") == 0)) + if ( (key_up_string && (std::strcmp(key_up_string, CSI "A") == 0)) || ( tcap[t_cursor_up].string - && (strcmp(tcap[t_cursor_up].string, CSI "A") == 0)) ) + && (std::strcmp(tcap[t_cursor_up].string, CSI "A") == 0)) ) { for (int i=0; Fkey[i].tname[0] != 0; i++) { - if ( strncmp(Fkey[i].tname, "kux", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "kux", 3) == 0 ) Fkey[i].string = const_cast(CSI "A"); // key up - if ( strncmp(Fkey[i].tname, "kdx", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "kdx", 3) == 0 ) Fkey[i].string = const_cast(CSI "B"); // key down - if ( strncmp(Fkey[i].tname, "krx", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "krx", 3) == 0 ) Fkey[i].string = const_cast(CSI "C"); // key right - if ( strncmp(Fkey[i].tname, "klx", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "klx", 3) == 0 ) Fkey[i].string = const_cast(CSI "D"); // key left - if ( strncmp(Fkey[i].tname, "k1X", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "k1X", 3) == 0 ) Fkey[i].string = const_cast(ESC "OP"); // PF1 - if ( strncmp(Fkey[i].tname, "k2X", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "k2X", 3) == 0 ) Fkey[i].string = const_cast(ESC "OQ"); // PF2 - if ( strncmp(Fkey[i].tname, "k3X", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "k3X", 3) == 0 ) Fkey[i].string = const_cast(ESC "OR"); // PF3 - if ( strncmp(Fkey[i].tname, "k4X", 3) == 0 ) + if ( std::strncmp(Fkey[i].tname, "k4X", 3) == 0 ) Fkey[i].string = const_cast(ESC "OS"); // PF4 } } @@ -1585,7 +1581,7 @@ void FTerm::init_encoding() { // detect encoding and set the Fputchar function pointer - if ( isatty(stdout_no) && ! strcmp(nl_langinfo(CODESET), "UTF-8") ) + if ( isatty(stdout_no) && ! std::strcmp(nl_langinfo(CODESET), "UTF-8") ) { utf8_console = true; Encoding = fc::UTF8; @@ -1595,7 +1591,7 @@ void FTerm::init_encoding() setUTF8(true); } else if ( isatty(stdout_no) - && (strlen(termtype) > 0) + && (std::strlen(termtype) > 0) && (tcap[t_exit_alt_charset_mode].string != 0) ) { vt100_console = true; @@ -1775,25 +1771,28 @@ void FTerm::init() // initialize 256 colors terminals new_termtype = init_256colorTerminal(); - if ( strncmp(termtype, "cygwin", 6) == 0 ) + if ( std::strncmp(termtype, "cygwin", 6) == 0 ) cygwin_terminal = true; else cygwin_terminal = false; - if ( strncmp(termtype, "rxvt-cygwin-native", 18) == 0 ) + if ( std::strncmp(termtype, "rxvt-cygwin-native", 18) == 0 ) rxvt_terminal = true; // Test for Linux console - if ( strncmp(termtype, const_cast("linux"), 5) == 0 - || strncmp(termtype, const_cast("con"), 3) == 0 ) + if ( std::strncmp(termtype, const_cast("linux"), 5) == 0 + || std::strncmp(termtype, const_cast("con"), 3) == 0 ) linux_terminal = true; else linux_terminal = false; - // terminal detection... + // start terminal detection... setRawMode(); + // Identify the terminal via the answerback-message new_termtype = parseAnswerbackMsg (new_termtype); + + // Identify the terminal via the secondary device attributes (SEC_DA) new_termtype = parseSecDA (new_termtype); unsetRawMode(); @@ -1803,8 +1802,8 @@ void FTerm::init() unsetNonBlockingInput(); // Test if the terminal is a xterm - if ( strncmp(termtype, const_cast("xterm"), 5) == 0 - || strncmp(termtype, const_cast("Eterm"), 4) == 0 ) + if ( std::strncmp(termtype, const_cast("xterm"), 5) == 0 + || std::strncmp(termtype, const_cast("Eterm"), 4) == 0 ) xterm = true; else xterm = false; @@ -1813,7 +1812,7 @@ void FTerm::init() if ( new_termtype ) { setenv(const_cast("TERM"), new_termtype, 1); - strncpy (termtype, new_termtype, strlen(new_termtype)+1); + std::strncpy (termtype, new_termtype, std::strlen(new_termtype)+1); } // Initializes variables for the current terminal @@ -1821,37 +1820,37 @@ void FTerm::init() init_alt_charset(); // init current locale - locale_name = setlocale(LC_ALL, ""); - locale_name = setlocale(LC_NUMERIC, ""); + locale_name = std::setlocale (LC_ALL, ""); + locale_name = std::setlocale (LC_NUMERIC, ""); // get XTERM_LOCALE - locale_xterm = getenv("XTERM_LOCALE"); + locale_xterm = std::getenv("XTERM_LOCALE"); // set LC_ALL to XTERM_LOCALE if ( locale_xterm ) - locale_name = setlocale(LC_ALL, locale_xterm); + locale_name = std::setlocale (LC_ALL, locale_xterm); // TeraTerm can not show UTF-8 character - if ( tera_terminal && ! strcmp(nl_langinfo(CODESET), "UTF-8") ) - locale_name = setlocale(LC_ALL, "en_US"); + if ( tera_terminal && ! std::strcmp(nl_langinfo(CODESET), "UTF-8") ) + locale_name = std::setlocale (LC_ALL, "en_US"); // if locale C => switch from 7bit ascii -> latin1 - if ( isatty(stdout_no) && ! strcmp(nl_langinfo(CODESET), "ANSI_X3.4-1968") ) - locale_name = setlocale(LC_ALL, "en_US"); + if ( isatty(stdout_no) && ! std::strcmp(nl_langinfo(CODESET), "ANSI_X3.4-1968") ) + locale_name = std::setlocale (LC_ALL, "en_US"); // try to found a meaningful content for locale_name if ( locale_name ) - locale_name = setlocale(LC_CTYPE, 0); + locale_name = std::setlocale (LC_CTYPE, 0); else { - locale_name = getenv("LC_ALL"); + locale_name = std::getenv("LC_ALL"); if ( ! locale_name ) { - locale_name = getenv("LC_CTYPE"); + locale_name = std::getenv("LC_CTYPE"); if ( ! locale_name ) - locale_name = getenv("LANG"); + locale_name = std::getenv("LANG"); } } @@ -1878,28 +1877,28 @@ void FTerm::init() if ( tcap[t_keypad_xmit].string ) { putstring (tcap[t_keypad_xmit].string); - fflush(stdout); + std::fflush(stdout); } // save current cursor position if ( tcap[t_save_cursor].string ) { putstring (tcap[t_save_cursor].string); - fflush(stdout); + std::fflush(stdout); } // saves the screen and the cursor position if ( tcap[t_enter_ca_mode].string ) { putstring (tcap[t_enter_ca_mode].string); - fflush(stdout); + std::fflush(stdout); } // enable alternate charset if ( tcap[t_enable_acs].string ) { putstring (tcap[t_enable_acs].string); - fflush(stdout); + std::fflush(stdout); } setXTermCursorStyle(fc::blinking_underline); @@ -2014,14 +2013,14 @@ void FTerm::finish() if ( tcap[t_exit_attribute_mode].string ) { putstring (tcap[t_exit_attribute_mode].string); - fflush(stdout); + std::fflush(stdout); } // turn off pc charset mode if ( tcap[t_exit_pc_charset_mode].string ) { putstring (tcap[t_exit_pc_charset_mode].string); - fflush(stdout); + std::fflush(stdout); } // reset xterm color settings to default @@ -2051,7 +2050,7 @@ void FTerm::finish() { // normal escape key mode putstring (CSI "?7727l"); - fflush(stdout); + std::fflush(stdout); } if ( linux_terminal ) @@ -2085,21 +2084,21 @@ void FTerm::finish() if ( tcap[t_exit_ca_mode].string ) { putstring (tcap[t_exit_ca_mode].string); - fflush(stdout); + std::fflush(stdout); } // restore cursor to position of last save_cursor if ( tcap[t_restore_cursor].string ) { putstring (tcap[t_restore_cursor].string); - fflush(stdout); + std::fflush(stdout); } // leave 'keyboard_transmit' mode if ( tcap[t_keypad_local].string ) { putstring (tcap[t_keypad_local].string); - fflush(stdout); + std::fflush(stdout); } if ( linux_terminal && utf8_console ) @@ -2193,14 +2192,17 @@ void FTerm::createArea (term_area*& area) // initialize virtual window area = new term_area; - area->width = -1; - area->height = -1; - area->right_shadow = 0; - area->bottom_shadow = 0; - area->changes = 0; - area->text = 0; - area->visible = false; - area->widget = static_cast(this); + area->width = -1; + area->height = -1; + area->right_shadow = 0; + area->bottom_shadow = 0; + area->input_cursor_x = -1;; + area->input_cursor_y = -1;; + area->input_cursor_visible = false; + area->changes = 0; + area->text = 0; + area->visible = false; + area->widget = static_cast(this); resizeArea (area); } @@ -2386,7 +2388,7 @@ void FTerm::restoreVTerm (int x, int y, int w, int h) if ( tmp->trans_shadow ) // transparent shadow { // keep the current vterm character - memcpy (&s_ch, sc, sizeof(FOptiAttr::char_data)); + std::memcpy (&s_ch, sc, sizeof(FOptiAttr::char_data)); s_ch.fg_color = tmp->fg_color; s_ch.bg_color = tmp->bg_color; s_ch.reverse = false; @@ -2404,7 +2406,7 @@ void FTerm::restoreVTerm (int x, int y, int w, int h) else if ( tmp->inherit_bg ) { // add the covered background to this character - memcpy (&i_ch, tmp, sizeof(FOptiAttr::char_data)); + std::memcpy (&i_ch, tmp, sizeof(FOptiAttr::char_data)); i_ch.bg_color = sc->bg_color; // last background color; sc = &i_ch; } @@ -2417,7 +2419,7 @@ void FTerm::restoreVTerm (int x, int y, int w, int h) } } - memcpy (tc, sc, sizeof(FOptiAttr::char_data)); + std::memcpy (tc, sc, sizeof(FOptiAttr::char_data)); if ( short(vterm->changes[y+ty].xmin) > x ) vterm->changes[y+ty].xmin = uInt(x); @@ -2429,7 +2431,7 @@ void FTerm::restoreVTerm (int x, int y, int w, int h) } //---------------------------------------------------------------------- -FTerm::covered_state FTerm::isCovered (int x, int y, FTerm::term_area* area) const +FTerm::covered_state FTerm::isCovered (int x, int y, FTerm::term_area* area) { bool found; FTerm::covered_state is_covered; @@ -2488,6 +2490,15 @@ FTerm::covered_state FTerm::isCovered (int x, int y, FTerm::term_area* area) con return is_covered; } +//---------------------------------------------------------------------- +void FTerm::updateVTerm (bool on) +{ + vterm_updates = on; + + if ( on ) + updateVTerm (last_area); +} + //---------------------------------------------------------------------- void FTerm::updateVTerm (FTerm::term_area* area) { @@ -2518,7 +2529,7 @@ void FTerm::updateVTerm (FTerm::term_area* area) if ( ax < 0 ) { - ol = abs(ax); + ol = std::abs(ax); ax = 0; } @@ -2567,7 +2578,7 @@ void FTerm::updateVTerm (FTerm::term_area* area) { // add the overlapping color to this character FOptiAttr::char_data ch, oc; - memcpy (&ch, ac, sizeof(FOptiAttr::char_data)); + std::memcpy (&ch, ac, sizeof(FOptiAttr::char_data)); oc = getOverlappedCharacter (gx+1 - ol, gy+1, area->widget); ch.fg_color = oc.fg_color; ch.bg_color = oc.bg_color; @@ -2581,14 +2592,14 @@ void FTerm::updateVTerm (FTerm::term_area* area) || ch.code == fc::FullBlock ) ch.code = ' '; - memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); + std::memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); } else if ( ac->transparent ) // transparent { // restore one character on vterm FOptiAttr::char_data ch; ch = getCoveredCharacter (gx+1 - ol, gy+1, area->widget); - memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); + std::memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); } else // not transparent { @@ -2609,19 +2620,19 @@ void FTerm::updateVTerm (FTerm::term_area* area) || ch.code == fc::FullBlock ) ch.code = ' '; - memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); + std::memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); } else if ( ac->inherit_bg ) { // add the covered background to this character FOptiAttr::char_data ch, cc; - memcpy (&ch, ac, sizeof(FOptiAttr::char_data)); + std::memcpy (&ch, ac, sizeof(FOptiAttr::char_data)); cc = getCoveredCharacter (gx+1 - ol, gy+1, area->widget); ch.bg_color = cc.bg_color; - memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); + std::memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); } else // default - memcpy (tc, ac, sizeof(FOptiAttr::char_data)); + std::memcpy (tc, ac, sizeof(FOptiAttr::char_data)); } modified = true; @@ -2646,20 +2657,83 @@ void FTerm::updateVTerm (FTerm::term_area* area) area->changes[y].xmax = 0; } } + + updateVTermCursor(area); } //---------------------------------------------------------------------- -void FTerm::updateVTerm (bool on) +bool FTerm::updateVTermCursor (FTerm::term_area* area) { - vterm_updates = on; + if ( ! area ) + return false; - if ( on ) - updateVTerm (last_area); + if ( area != active_area ) + return false; + + if ( ! area->visible ) + return false; + + if ( area->input_cursor_visible ) + { + int cx, cy, ax, ay, x, y; + // cursor position + cx = area->input_cursor_x; + cy = area->input_cursor_y; + // widget position + ax = area->widget->getTermX() - 1; + ay = area->widget->getTermY() - 1; + // area position + x = ax + cx - 1; + y = ay + cy - 1; + + if ( isInsideArea(cx, cy, area) + && isInsideTerminal(x+1, y+1) + && isCovered(x, y, area) == non_covered ) + { + vterm->input_cursor_x = x; + vterm->input_cursor_y = y; + vterm->input_cursor_visible = true; + return true; + } + } + + vterm->input_cursor_visible = false; + return false; +} + +//---------------------------------------------------------------------- +bool FTerm::isInsideArea (int x, int y, FTerm::term_area* area) +{ + // Check whether the coordinates are within the area + int ax, ay, aw, ah; + ax = 0; + ay = 0; + aw = area->width; + ah = area->height; + FRect area_geometry(ax, ay, aw, ah); + + if ( area_geometry.contains(x,y) ) + return true; + else + return false; +} + +//---------------------------------------------------------------------- +void FTerm::setAreaCursor (int x, int y, bool visible, FTerm::term_area* area) +{ + if ( ! area ) + return; + + area->input_cursor_x = x; + area->input_cursor_y = y; + area->input_cursor_visible = visible; + updateVTerm (area); } //---------------------------------------------------------------------- void FTerm::getArea (int ax, int ay, FTerm::term_area* area) { + // Copies a block from the virtual terminal position to the given area int y_end; int length; FOptiAttr::char_data* tc; // terminal character @@ -2683,9 +2757,9 @@ void FTerm::getArea (int ax, int ay, FTerm::term_area* area) for (int y=0; y < y_end; y++) // line loop { - ac = &area->text[y * area->width]; tc = &vterm->text[(ay+y) * vterm->width + ax]; - memcpy (ac, tc, sizeof(FOptiAttr::char_data) * unsigned(length)); + ac = &area->text[y * area->width]; + std::memcpy (ac, tc, sizeof(FOptiAttr::char_data) * unsigned(length)); if ( short(area->changes[y].xmin) > 0 ) area->changes[y].xmin = 0; @@ -2698,6 +2772,7 @@ void FTerm::getArea (int ax, int ay, FTerm::term_area* area) //---------------------------------------------------------------------- void FTerm::getArea (int x, int y, int w, int h, FTerm::term_area* area) { + // Copies a block from the virtual terminal rectangle to the given area int y_end, length, dx, dy; FOptiAttr::char_data* tc; // terminal character FOptiAttr::char_data* ac; // area character @@ -2729,7 +2804,7 @@ void FTerm::getArea (int x, int y, int w, int h, FTerm::term_area* area) int line_len = area->width + area->right_shadow; tc = &vterm->text[(y+_y-1) * vterm->width + x-1]; ac = &area->text[(dy+_y) * line_len + dx]; - memcpy (ac, tc, sizeof(FOptiAttr::char_data) * unsigned(length)); + std::memcpy (ac, tc, sizeof(FOptiAttr::char_data) * unsigned(length)); if ( short(area->changes[dy+_y].xmin) > dx ) area->changes[dy+_y].xmin = uInt(dx); @@ -2742,6 +2817,7 @@ void FTerm::getArea (int x, int y, int w, int h, FTerm::term_area* area) //---------------------------------------------------------------------- void FTerm::putArea (const FPoint& pos, FTerm::term_area* area) { + // Copies the given area block to the virtual terminal position if ( ! area ) return; @@ -2754,6 +2830,7 @@ void FTerm::putArea (const FPoint& pos, FTerm::term_area* area) //---------------------------------------------------------------------- void FTerm::putArea (int ax, int ay, FTerm::term_area* area) { + // Copies the given area block to the virtual terminal position int aw, ah, rsh, bsh, y_end, length, ol; FOptiAttr::char_data* tc; // terminal character FOptiAttr::char_data* ac; // area character @@ -2774,7 +2851,7 @@ void FTerm::putArea (int ax, int ay, FTerm::term_area* area) if ( ax < 0 ) { - ol = abs(ax); + ol = std::abs(ax); ax = 0; } @@ -2800,7 +2877,7 @@ void FTerm::putArea (int ax, int ay, FTerm::term_area* area) // Line has only covered characters tc = &vterm->text[(ay+y) * vterm->width + ax]; ac = &area->text[y * line_len + ol]; - memcpy (tc, ac, sizeof(FOptiAttr::char_data) * unsigned(length)); + std::memcpy (tc, ac, sizeof(FOptiAttr::char_data) * unsigned(length)); } else { @@ -2815,7 +2892,7 @@ void FTerm::putArea (int ax, int ay, FTerm::term_area* area) // restore one character on vterm FOptiAttr::char_data ch; ch = getCoveredCharacter (ax+x+1, ay+y+1, area->widget); - memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); + std::memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); } else // not transparent { @@ -2836,19 +2913,19 @@ void FTerm::putArea (int ax, int ay, FTerm::term_area* area) || ch.code == fc::FullBlock ) ch.code = ' '; - memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); + std::memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); } else if ( ac->inherit_bg ) { // add the covered background to this character FOptiAttr::char_data ch, cc; - memcpy (&ch, ac, sizeof(FOptiAttr::char_data)); + std::memcpy (&ch, ac, sizeof(FOptiAttr::char_data)); cc = getCoveredCharacter (ax+x+1, ay+y+1, area->widget); ch.bg_color = cc.bg_color; - memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); + std::memcpy (tc, &ch, sizeof(FOptiAttr::char_data)); } else // default - memcpy (tc, ac, sizeof(FOptiAttr::char_data)); + std::memcpy (tc, ac, sizeof(FOptiAttr::char_data)); } } } @@ -2865,7 +2942,7 @@ void FTerm::putArea (int ax, int ay, FTerm::term_area* area) void FTerm::clearArea() { term_area* area; - FWindow* area_widget; + FWindow* window; FWidget* widget; FOptiAttr::char_data default_char; int total_width; @@ -2892,10 +2969,10 @@ void FTerm::clearArea() default_char.inherit_bg = next_attribute.inherit_bg; widget = static_cast(this); - area_widget = FWindow::getWindowWidget(widget); + window = FWindow::getWindowWidget(widget); - if ( area_widget ) - area = area_widget->getVWin(); + if ( window ) + area = window->getVWin(); else area = vdesktop; @@ -3028,7 +3105,7 @@ FOptiAttr::char_data FTerm::getCharacter ( int char_type if ( tmp->trans_shadow ) // transparent shadow { // keep the current vterm character - memcpy (&s_ch, cc, sizeof(FOptiAttr::char_data)); + std::memcpy (&s_ch, cc, sizeof(FOptiAttr::char_data)); s_ch.fg_color = tmp->fg_color; s_ch.bg_color = tmp->bg_color; s_ch.reverse = false; @@ -3038,7 +3115,7 @@ FOptiAttr::char_data FTerm::getCharacter ( int char_type else if ( tmp->inherit_bg ) { // add the covered background to this character - memcpy (&i_ch, tmp, sizeof(FOptiAttr::char_data)); + std::memcpy (&i_ch, tmp, sizeof(FOptiAttr::char_data)); i_ch.bg_color = cc->bg_color; // last background color cc = &i_ch; } @@ -3057,6 +3134,7 @@ FOptiAttr::char_data FTerm::getCharacter ( int char_type return *cc; } + // public methods of FTerm //---------------------------------------------------------------------- bool FTerm::setVGAFont() @@ -3080,7 +3158,7 @@ bool FTerm::setVGAFont() oscPrefix(); putstring (OSC "50;vga" BEL); oscPostfix(); - fflush(stdout); + std::fflush(stdout); NewFont = false; pc_charset_console = true; Encoding = fc::PC; @@ -3149,7 +3227,7 @@ bool FTerm::setNewFont() oscPrefix(); putstring (OSC "50;8x16graph" BEL); oscPostfix(); - fflush(stdout); + std::fflush(stdout); pc_charset_console = true; Encoding = fc::PC; @@ -3225,7 +3303,7 @@ bool FTerm::setOldFont() oscPostfix(); } - fflush(stdout); + std::fflush(stdout); retval = true; } else if ( linux_terminal ) @@ -3275,7 +3353,7 @@ void FTerm::setConsoleCursor (fc::consoleCursorStyle style) return; putstringf (CSI "?%dc", style); - fflush(stdout); + std::fflush(stdout); } } @@ -3294,10 +3372,10 @@ void FTerm::getTermSize() { char* str; term->setPos(1,1); - str = getenv("COLUMNS"); - term->setWidth(str ? atoi(str) : 80); - str = getenv("LINES"); - term->setHeight(str ? atoi(str) : 25); + str = std::getenv("COLUMNS"); + term->setWidth(str ? std::atoi(str) : 80); + str = std::getenv("LINES"); + term->setHeight(str ? std::atoi(str) : 25); } else { @@ -3314,7 +3392,7 @@ void FTerm::setTermSize (int term_width, int term_height) if ( xterm ) { putstringf (CSI "8;%d;%dt", term_height, term_width); - fflush(stdout); + std::fflush(stdout); } } @@ -3323,14 +3401,17 @@ void FTerm::createVTerm() { // initialize virtual terminal vterm = new term_area; - vterm->width = -1; - vterm->height = -1; - vterm->right_shadow = 0; - vterm->bottom_shadow = 0; - vterm->changes = 0; - vterm->text = 0; - vterm->visible = true; - vterm->widget = static_cast(this); + vterm->width = -1; + vterm->height = -1; + vterm->right_shadow = 0; + vterm->bottom_shadow = 0; + vterm->input_cursor_x = -1;; + vterm->input_cursor_y = -1;; + vterm->input_cursor_visible = false; + vterm->changes = 0; + vterm->text = 0; + vterm->visible = true; + vterm->widget = static_cast(this); resizeVTerm(); } @@ -3417,12 +3498,19 @@ void FTerm::putVTerm() updateTerminal(); } +//---------------------------------------------------------------------- +void FTerm::updateTerminal (bool on) +{ + stop_terminal_updates = bool(! on); + + if ( on ) + updateTerminal(); +} + //---------------------------------------------------------------------- void FTerm::updateTerminal() { term_area* vt; - FWidget* focus_widget; - FApplication* fapp; int term_width, term_height; if ( stop_terminal_updates @@ -3461,13 +3549,13 @@ void FTerm::updateTerminal() FOptiAttr::char_data* print_char; print_char = &vt->text[y * uInt(vt->width) + x]; - if ( x_term_pos == term_width - && y_term_pos == term_height ) + if ( term_pos->getX() == term_width + && term_pos->getY() == term_height ) appendLowerRight (print_char); else appendCharacter (print_char); - x_term_pos++; + term_pos->x_ref()++; } vt->changes[y].xmin = uInt(vt->width); @@ -3475,50 +3563,61 @@ void FTerm::updateTerminal() } // cursor wrap - if ( x_term_pos > term_width ) + if ( term_pos->getX() > term_width ) { - if ( y_term_pos == term_height ) - x_term_pos--; + if ( term_pos->getY() == term_height ) + term_pos->x_ref()--; else { if ( eat_nl_glitch ) { - x_term_pos = -1; - y_term_pos = -1; + term_pos->setPoint(-1,-1); } else if ( automatic_right_margin ) { - x_term_pos = 0; - y_term_pos++; + term_pos->setX(0); + term_pos->y_ref()++; } else - x_term_pos--; + term_pos->x_ref()--; } } } - // set the cursor to the focus widget - fapp = static_cast(term_object); - focus_widget = fapp->focusWidget(); - - if ( focus_widget - && focus_widget->isVisible() - && focus_widget->isCursorInside() ) - { - focus_widget->setCursor(); - - if ( focus_widget->hasVisibleCursor() ) - showCursor(); - } + // sets the new input cursor position + updateTerminalCursor(); } //---------------------------------------------------------------------- -void FTerm::updateTerminal (bool on) +bool FTerm::updateTerminalCursor() { - stop_terminal_updates = bool(! on); + // updates the input cursor visibility and the position + if ( vterm && vterm->input_cursor_visible ) + { + int x = vterm->input_cursor_x; + int y = vterm->input_cursor_y; - if ( on ) - updateTerminal(); + if ( isInsideTerminal(x+1, y+1) ) + { + setTermXY (x,y); + showCursor(); + return true; + } + } + else + hideCursor(); + + return false; +} + +//---------------------------------------------------------------------- +bool FTerm::isInsideTerminal (int x, int y) +{ + // Check whether the coordinates are within the virtual terminal + if ( term->contains(x,y) ) + return true; + else + return false; } //---------------------------------------------------------------------- @@ -3530,7 +3629,7 @@ void FTerm::setKDECursor (fc::kdeKonsoleCursorShape style) oscPrefix(); putstringf (OSC "50;CursorShape=%d" BEL, style); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3548,7 +3647,7 @@ FString FTerm::getXTermFont() oscPrefix(); putstring (OSC "50;?" BEL); // get font oscPostfix(); - fflush(stdout); + std::fflush(stdout); usleep(150000); // wait 150 ms // read the terminal answer @@ -3579,7 +3678,7 @@ FString FTerm::getXTermTitle() int n; char temp[512] = {}; putstring (CSI "21t"); // get title - fflush(stdout); + std::fflush(stdout); usleep(150000); // wait 150 ms // read the terminal answer @@ -3603,7 +3702,7 @@ void FTerm::setXTermCursorStyle (fc::xtermCursorStyle style) if ( (xterm || mintty_terminal) && ! (gnome_terminal || kde_konsole) ) { putstringf (CSI "%d q", style); - fflush(stdout); + std::fflush(stdout); } } @@ -3618,7 +3717,7 @@ void FTerm::setXTermTitle (const FString& title) oscPrefix(); putstringf (OSC "0;%s" BEL, title.c_str()); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3633,7 +3732,7 @@ void FTerm::setXTermForeground (const FString& fg) oscPrefix(); putstringf (OSC "10;%s" BEL, fg.c_str()); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3648,7 +3747,7 @@ void FTerm::setXTermBackground (const FString& bg) oscPrefix(); putstringf (OSC "11;%s" BEL, bg.c_str()); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3663,7 +3762,7 @@ void FTerm::setXTermCursorColor (const FString& cc) oscPrefix(); putstringf (OSC "12;%s" BEL, cc.c_str()); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3676,7 +3775,7 @@ void FTerm::setXTermMouseForeground (const FString& mfg) oscPrefix(); putstringf (OSC "13;%s" BEL, mfg.c_str()); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3689,7 +3788,7 @@ void FTerm::setXTermMouseBackground (const FString& mbg) oscPrefix(); putstringf (OSC "14;%s" BEL, mbg.c_str()); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3702,7 +3801,7 @@ void FTerm::setXTermHighlightBackground (const FString& hbg) oscPrefix(); putstringf (OSC "17;%s" BEL, hbg.c_str()); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3715,7 +3814,7 @@ void FTerm::resetXTermColors() oscPrefix(); putstringf (OSC "104" BEL); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3728,7 +3827,7 @@ void FTerm::resetXTermForeground() oscPrefix(); putstring (OSC "110" BEL); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3741,7 +3840,7 @@ void FTerm::resetXTermBackground() oscPrefix(); putstring (OSC "111" BEL); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3754,7 +3853,7 @@ void FTerm::resetXTermCursorColor() oscPrefix(); putstring (OSC "112" BEL); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3767,7 +3866,7 @@ void FTerm::resetXTermMouseForeground() oscPrefix(); putstring (OSC "113" BEL); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3780,7 +3879,7 @@ void FTerm::resetXTermMouseBackground() oscPrefix(); putstring (OSC "114" BEL); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3793,7 +3892,7 @@ void FTerm::resetXTermHighlightBackground() oscPrefix(); putstringf (OSC "117" BEL); oscPostfix(); - fflush(stdout); + std::fflush(stdout); } } @@ -3835,7 +3934,7 @@ void FTerm::resetColorMap() ioctl (0, PIO_CMAP, &map); }*/ - fflush(stdout); + std::fflush(stdout); } //---------------------------------------------------------------------- @@ -3876,7 +3975,7 @@ void FTerm::setPalette (short index, int r, int g, int b) ioctl (0, PIO_CMAP, &map); */ } - fflush(stdout); + std::fflush(stdout); } //---------------------------------------------------------------------- @@ -3899,7 +3998,7 @@ void FTerm::xtermMouse (bool on) CSI "?1000l" // disable x11 mouse tracking CSI "?1001r"); // restore old highlight mouse tracking - fflush(stdout); + std::fflush(stdout); } @@ -3954,10 +4053,10 @@ bool FTerm::gpmMouse (bool on) void FTerm::setTermXY (register int x, register int y) { // sets the hardware cursor to the given (x,y) position - int term_width, term_height; + int term_x, term_y, term_width, term_height; char* move_str; - if ( x_term_pos == x && y_term_pos == y ) + if ( term_pos->getX() == x && term_pos->getY() == y ) return; term_width = term->getWidth(); @@ -3969,14 +4068,17 @@ void FTerm::setTermXY (register int x, register int y) x %= term_width; } - if ( y_term_pos >= term_height ) - y_term_pos = term_height - 1; + if ( term_pos->getY() >= term_height ) + term_pos->setY(term_height - 1); if ( y >= term_height ) y = term_height - 1; + term_x = term_pos->getX(); + term_y = term_pos->getY(); + if ( cursor_optimisation ) - move_str = opti_move->cursor_move (x_term_pos, y_term_pos, x, y); + move_str = opti_move->cursor_move (term_x, term_y, x, y); else move_str = tgoto(tcap[t_cursor_address].string, x, y); @@ -3984,8 +4086,7 @@ void FTerm::setTermXY (register int x, register int y) appendOutputBuffer(move_str); flush_out(); - x_term_pos = x; - y_term_pos = y; + term_pos->setPoint(x,y); } //---------------------------------------------------------------------- @@ -4005,7 +4106,7 @@ void FTerm::setBeep (int Hz, int ms) putstringf ( CSI "10;%d]" CSI "11;%d]" , Hz, ms ); - fflush(stdout); + std::fflush(stdout); } //---------------------------------------------------------------------- @@ -4018,7 +4119,7 @@ void FTerm::resetBeep() // default duration: 125 ms putstring ( CSI "10;750]" CSI "11;125]" ); - fflush(stdout); + std::fflush(stdout); } //---------------------------------------------------------------------- @@ -4027,7 +4128,7 @@ void FTerm::beep() if ( tcap[t_bell].string ) { putstring (tcap[t_bell].string); - fflush(stdout); + std::fflush(stdout); } } @@ -4068,24 +4169,6 @@ bool FTerm::hideCursor (bool on) return hidden_cursor; } -//---------------------------------------------------------------------- -bool FTerm::isCursorInside() -{ - // Checked whether the cursor is within the visual terminal - FWidget* w; - w = static_cast(this); - - int x = w->getCursorPos().getX(); - int y = w->getCursorPos().getY(); - x += w->getTermX() - 1; - y += w->getTermY() - 1; - - if ( term->contains(x,y) ) - return true; - else - return false; -} - //---------------------------------------------------------------------- void FTerm::setEncoding (std::string enc) { @@ -4178,7 +4261,7 @@ bool FTerm::setUTF8 (bool on) // UTF-8 (Unicode) putstring (ESC "%@"); } - fflush(stdout); + std::fflush(stdout); return utf8_state; } @@ -4188,7 +4271,7 @@ bool FTerm::setRawMode (bool on) if ( on == raw_mode ) return raw_mode; - fflush(stdout); + std::fflush(stdout); if ( on ) { @@ -4251,8 +4334,8 @@ FString FTerm::getAnswerbackMsg() tv.tv_sec = 0; tv.tv_usec = 150000; // 150 ms - putchar (ENQ[0]); // send enquiry character - fflush(stdout); + std::putchar (ENQ[0]); // send enquiry character + std::fflush(stdout); // read the answerback message if ( select (stdin_no+1, &ifds, 0, 0, &tv) > 0) @@ -4288,12 +4371,12 @@ FString FTerm::getSecDA() tv.tv_usec = 550000; // 150 ms // get the secondary device attributes - putchar (SECDA[0]); - putchar (SECDA[1]); - putchar (SECDA[2]); - putchar (SECDA[3]); + std::putchar (SECDA[0]); + std::putchar (SECDA[1]); + std::putchar (SECDA[2]); + std::putchar (SECDA[3]); - fflush(stdout); + std::fflush(stdout); usleep(150000); // min. wait time 150 ms (need for mintty) // read the answer @@ -4321,7 +4404,7 @@ int FTerm::printf (const wchar_t* format, ...) va_list args; va_start (args, format); - vswprintf (buffer, buf_size, format, args); + std::vswprintf (buffer, buf_size, format, args); va_end (args); FString str(buffer); @@ -4339,14 +4422,14 @@ int FTerm::printf (const char* format, ...) buffer = buf; va_start (args, format); - len = vsnprintf (buffer, sizeof(buf), format, args); + len = std::vsnprintf (buffer, sizeof(buf), format, args); va_end (args); if ( len >= int(sizeof(buf)) ) { buffer = new char[len+1](); va_start (args, format); - vsnprintf (buffer, uLong(len+1), format, args); + std::vsnprintf (buffer, uLong(len+1), format, args); va_end (args); } @@ -4432,10 +4515,10 @@ int FTerm::print (FString& s) if ( ! area ) { - FWidget* area_widget = w->getRootWidget(); + FWidget* root = w->getRootWidget(); area = vdesktop; - if ( ! area_widget ) + if ( ! root ) return -1; } @@ -4448,14 +4531,14 @@ int FTerm::print (FTerm::term_area* area, FString& s) assert ( ! s.isNull() ); register int len = 0; const wchar_t* p; - FWidget* area_widget; + FWidget* window; if ( ! area ) return -1; - area_widget = area->widget; + window = area->widget; - if ( ! area_widget ) + if ( ! window ) return -1; p = s.wc_str(); @@ -4517,8 +4600,8 @@ int FTerm::print (FTerm::term_area* area, FString& s) nc.trans_shadow = next_attribute.trans_shadow; nc.inherit_bg = next_attribute.inherit_bg; - int ax = x - area_widget->getTermX(); - int ay = y - area_widget->getTermY(); + int ax = x - window->getTermX(); + int ay = y - window->getTermY(); if ( area && ax >= 0 && ay >= 0 @@ -4547,7 +4630,7 @@ int FTerm::print (FTerm::term_area* area, FString& s) } // copy character to area - memcpy (ac, &nc, sizeof(nc)); + std::memcpy (ac, &nc, sizeof(nc)); if ( ax < short(area->changes[ay].xmin) ) area->changes[ay].xmin = uInt(ax); @@ -4563,11 +4646,11 @@ int FTerm::print (FTerm::term_area* area, FString& s) rsh = area->right_shadow; bsh = area->bottom_shadow; - const FRect& area_geometry = area_widget->getTermGeometry(); + const FRect& area_geometry = window->getTermGeometry(); if ( cursor->x_ref() > area_geometry.getX2()+rsh ) { - cursor->x_ref() = short(area_widget->getTermX()); + cursor->x_ref() = short(window->getTermX()); cursor->y_ref()++; } @@ -4597,10 +4680,10 @@ int FTerm::print (register int c) if ( ! area ) { - FWidget* area_widget = w->getRootWidget(); + FWidget* root = w->getRootWidget(); area = vdesktop; - if ( ! area_widget ) + if ( ! root ) return -1; } @@ -4611,7 +4694,7 @@ int FTerm::print (register int c) int FTerm::print (FTerm::term_area* area, register int c) { FOptiAttr::char_data nc; // next character - FWidget* area_widget; + FWidget* window; int rsh, bsh, ax, ay; short x, y; @@ -4640,13 +4723,13 @@ int FTerm::print (FTerm::term_area* area, register int c) x = short(cursor->getX()); y = short(cursor->getY()); - area_widget = area->widget; + window = area->widget; - if ( ! area_widget ) + if ( ! window ) return -1; - ax = x - area_widget->getTermX(); - ay = y - area_widget->getTermY(); + ax = x - window->getTermX(); + ay = y - window->getTermY(); if ( ax >= 0 && ay >= 0 && ax < area->width + area->right_shadow @@ -4675,7 +4758,7 @@ int FTerm::print (FTerm::term_area* area, register int c) } // copy character to area - memcpy (ac, &nc, sizeof(nc)); + std::memcpy (ac, &nc, sizeof(nc)); if ( ax < short(area->changes[ay].xmin) ) area->changes[ay].xmin = uInt(ax); @@ -4688,11 +4771,11 @@ int FTerm::print (FTerm::term_area* area, register int c) cursor->x_ref()++; rsh = area->right_shadow; bsh = area->bottom_shadow; - const FRect& area_geometry = area_widget->getTermGeometry(); + const FRect& area_geometry = window->getTermGeometry(); if ( cursor->x_ref() > area_geometry.getX2()+rsh ) { - cursor->x_ref() = short(area_widget->getTermX()); + cursor->x_ref() = short(window->getTermX()); cursor->y_ref()++; } @@ -4831,7 +4914,7 @@ int FTerm::appendLowerRight (FOptiAttr::char_data*& screen_char) y = term->getHeight() - 1; setTermXY (x, y); appendCharacter (screen_char); - x_term_pos++; + term_pos->x_ref()++; setTermXY (x, y); screen_char--; @@ -4882,7 +4965,7 @@ int FTerm::appendOutputBuffer (int ch) { output_buffer->push(ch); - if ( output_buffer->size() >= 2048 ) + if ( output_buffer->size() >= TERMINAL_OUTPUT_BUFFER_SIZE ) flush_out(); return ch; @@ -4897,7 +4980,7 @@ void FTerm::flush_out() output_buffer->pop(); } - fflush(stdout); + std::fflush(stdout); } //---------------------------------------------------------------------- @@ -4910,22 +4993,22 @@ void FTerm::putstringf (const char* format, ...) buffer = buf; va_start (args, format); - vsnprintf (buffer, sizeof(buf), format, args); + std::vsnprintf (buffer, sizeof(buf), format, args); va_end (args); - tputs (buffer, 1, putchar); + tputs (buffer, 1, std::putchar); } //---------------------------------------------------------------------- inline void FTerm::putstring (const char* s, int affcnt) { - tputs (s, affcnt, putchar); + tputs (s, affcnt, std::putchar); } //---------------------------------------------------------------------- int FTerm::putchar_ASCII (register int c) { - if ( putchar(char(c)) == EOF ) + if ( std::putchar(char(c)) == EOF ) return 0; else return 1; @@ -4937,31 +5020,31 @@ int FTerm::putchar_UTF8 (register int c) if (c < 0x80) { // 1 Byte (7-bit): 0xxxxxxx - putchar (c); + std::putchar (c); return 1; } else if (c < 0x800) { // 2 byte (11-bit): 110xxxxx 10xxxxxx - putchar (0xc0 | (c >> 6) ); - putchar (0x80 | (c & 0x3f) ); + std::putchar (0xc0 | (c >> 6) ); + std::putchar (0x80 | (c & 0x3f) ); return 2; } else if (c < 0x10000) { // 3 byte (16-bit): 1110xxxx 10xxxxxx 10xxxxxx - putchar (0xe0 | (c >> 12) ); - putchar (0x80 | ((c >> 6) & 0x3f) ); - putchar (0x80 | (c & 0x3f) ); + std::putchar (0xe0 | (c >> 12) ); + std::putchar (0x80 | ((c >> 6) & 0x3f) ); + std::putchar (0x80 | (c & 0x3f) ); return 3; } else if (c < 0x200000) { // 4 byte (21-bit): 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - putchar (0xf0 | (c >> 18) ); - putchar (0x80 | ((c >> 12) & 0x3f) ); - putchar (0x80 | ((c >> 6) & 0x3f) ); - putchar (0x80 | (c & 0x3f)); + std::putchar (0xf0 | (c >> 18) ); + std::putchar (0x80 | ((c >> 12) & 0x3f) ); + std::putchar (0x80 | ((c >> 6) & 0x3f) ); + std::putchar (0x80 | (c & 0x3f)); return 4; } else @@ -4973,7 +5056,7 @@ int FTerm::UTF8decode(char* utf8) { register int ucs=0; - for (register int i=0; i < int(strlen(utf8)); ++i) + for (register int i=0; i < int(std::strlen(utf8)); ++i) { register uChar ch = uChar(utf8[i]); diff --git a/src/fterm.h b/src/fterm.h index 88d5f1e8..cd55036c 100644 --- a/src/fterm.h +++ b/src/fterm.h @@ -88,6 +88,9 @@ // parseKeyString return value #define NEED_MORE_DATA -1 +// Buffer size for character output on the terminal +#define TERMINAL_OUTPUT_BUFFER_SIZE 32768 + // class forward declaration class FWidget; @@ -151,17 +154,16 @@ class FTerm static char* locale_name; static char* locale_xterm; static uChar x11_button_state; - static FRect* term; - static FPoint* mouse; - static FPoint* cursor; + static FRect* term; // current terminal geometry + static FPoint* term_pos; // terminal cursor position + static FPoint* mouse; // mouse click position + static FPoint* cursor; // virtual print cursor static int stdin_status_flags; static int stdin_no; static int stdout_no; static int max_color; static int fd_tty; static uInt baudrate; - static int x_term_pos; - static int y_term_pos; static bool resize_term; static char exit_message[8192]; @@ -235,16 +237,20 @@ class FTerm int height; int right_shadow; int bottom_shadow; + int input_cursor_x; + int input_cursor_y; + int input_cursor_visible; FWidget* widget; line_changes* changes; FOptiAttr::char_data* text; bool visible; } term_area; - static term_area* vterm; // virtual terminal - static term_area* vdesktop; // virtual desktop - static term_area* last_area; // last used area - term_area* vwin; // virtual window + static term_area* vterm; // virtual terminal + static term_area* vdesktop; // virtual desktop + static term_area* last_area; // last used area + static term_area* active_area; // active area + term_area* vwin; // virtual window private: // Disable copy constructor @@ -293,10 +299,14 @@ class FTerm void removeArea (FTerm::term_area*&); // reference to pointer void restoreVTerm (const FRect&); void restoreVTerm (int, int, int, int); - FTerm::covered_state isCovered (const FPoint&, FTerm::term_area*) const; - FTerm::covered_state isCovered (int, int, FTerm::term_area*) const; - void updateVTerm (FTerm::term_area*); + static FTerm::covered_state isCovered (const FPoint&, FTerm::term_area*); + static FTerm::covered_state isCovered (int, int, FTerm::term_area*); void updateVTerm (bool); + void updateVTerm (FTerm::term_area*); + static bool updateVTermCursor (FTerm::term_area*); + static bool isInsideArea (int, int, FTerm::term_area*); + void setAreaCursor (const FPoint&, bool, FTerm::term_area*); + void setAreaCursor (int, int, bool, FTerm::term_area*); void getArea (const FPoint&, FTerm::term_area*); void getArea (int, int, FTerm::term_area*); void getArea (const FRect&, FTerm::term_area*); @@ -348,8 +358,10 @@ class FTerm void createVTerm(); static void resizeVTerm(); static void putVTerm(); - static void updateTerminal(); static void updateTerminal (bool); + static void updateTerminal(); + static bool updateTerminalCursor(); + static bool isInsideTerminal (int, int); static void setKDECursor (fc::kdeKonsoleCursorShape); static FString getXTermFont(); static FString getXTermTitle(); @@ -393,7 +405,6 @@ class FTerm static bool hideCursor(); static bool showCursor(); static bool isHiddenCursor(); - bool isCursorInside(); static void setEncoding (std::string); static std::string getEncoding(); @@ -466,9 +477,15 @@ class FTerm // FTerm inline functions //---------------------------------------------------------------------- inline FTerm::covered_state FTerm::isCovered ( const FPoint& pos - , FTerm::term_area* area) const + , FTerm::term_area* area) { return isCovered (pos.getX(), pos.getY(), area); } +//---------------------------------------------------------------------- +inline void FTerm::setAreaCursor ( const FPoint& pos + , bool visible + , FTerm::term_area* area) +{ setAreaCursor (pos.getX(), pos.getY(), visible, area); } + //---------------------------------------------------------------------- inline void FTerm::getArea (const FPoint& pos, FTerm::term_area* area) { return getArea (pos.getX(), pos.getY(), area); } diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 3d227d0a..b903cffd 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -126,7 +126,7 @@ void FTextView::drawText() { uInt start, end; - if ( data.empty() || getHeight() < 4 || getWidth() < 5 ) + if ( data.empty() || getHeight() <= 2 || getWidth() <= 2 ) return; start = 0; @@ -158,8 +158,8 @@ void FTextView::drawText() bool utf8 = (Encoding == fc::UTF8) ? true : false; // only printable and 1 column per character - if ( ( (utf8 && iswprint(wint_t(ch))) - || (!utf8 && ch < 256 && isprint(ch)) ) + if ( ( (utf8 && std::iswprint(wint_t(ch))) + || (!utf8 && ch < 256 && std::isprint(ch)) ) && wcwidth(ch) == 1 ) { print (ch); @@ -194,7 +194,7 @@ void FTextView::adjustSize() int last_line = int(getRows()); int max_width = int(maxLineWidth); - if ( xoffset > max_width - width - nf_offset - 1 ) + if ( xoffset >= max_width - width - nf_offset ) xoffset = max_width - width - nf_offset - 1; if ( xoffset < 0 ) @@ -262,7 +262,7 @@ void FTextView::hide() return; blank = new char[size+1]; - memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', uLong(size)); blank[size] = '\0'; for (int y=0; y < getHeight(); y++) @@ -916,7 +916,7 @@ void FTextView::clear() return; blank = new char[size+1]; - memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', uLong(size)); blank[size] = '\0'; for (int y=0; y < getHeight() + nf_offset - 2; y++) diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index c0177cda..e05ba934 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -24,8 +24,8 @@ FToggleButton::FToggleButton(FWidget* parent) { init(); - if ( parent && strcmp ( parent->getClassName() - , const_cast("FButtonGroup") ) == 0 ) + if ( parent && std::strcmp ( parent->getClassName() + , const_cast("FButtonGroup") ) == 0 ) { setGroup( static_cast(parent) ); @@ -47,8 +47,8 @@ FToggleButton::FToggleButton (const FString& txt, FWidget* parent) init(); setText(txt); - if ( parent && strcmp ( parent->getClassName() - , const_cast("FButtonGroup") ) == 0 ) + if ( parent && std::strcmp ( parent->getClassName() + , const_cast("FButtonGroup") ) == 0 ) { setGroup( static_cast(parent) ); @@ -64,9 +64,6 @@ FToggleButton::~FToggleButton() // destructor if ( group() ) group()->remove(this); - - if ( hasFocus() ) - hideCursor(); } @@ -142,12 +139,12 @@ void FToggleButton::setHotkeyAccelerator() if ( hotkey ) { - if ( isalpha(hotkey) || isdigit(hotkey) ) + if ( std::isalpha(hotkey) || std::isdigit(hotkey) ) { - addAccelerator (tolower(hotkey)); - addAccelerator (toupper(hotkey)); + addAccelerator (std::tolower(hotkey)); + addAccelerator (std::toupper(hotkey)); // Meta + hotkey - addAccelerator (fc::Fmkey_meta + tolower(hotkey)); + addAccelerator (fc::Fmkey_meta + std::tolower(hotkey)); } else addAccelerator (getHotkey()); @@ -175,17 +172,7 @@ void FToggleButton::draw() // set the cursor to the button if ( isRadioButton() || isCheckboxButton() ) - { setCursorPos (2, 1); - - if ( isCursorInside() && hasFocus() ) - { - if ( isHiddenCursor() ) - showCursor(); - } - else if ( ! isHiddenCursor() ) - hideCursor(); - } } //---------------------------------------------------------------------- @@ -289,15 +276,15 @@ FButtonGroup* FToggleButton::group() const //---------------------------------------------------------------------- bool FToggleButton::isRadioButton() const { - return ( strcmp ( getClassName() - , const_cast("FRadioButton") ) == 0 ); + return ( std::strcmp ( getClassName() + , const_cast("FRadioButton") ) == 0 ); } //---------------------------------------------------------------------- bool FToggleButton::isCheckboxButton() const { - return ( strcmp ( getClassName() - , const_cast("FCheckBox") ) == 0 ); + return ( std::strcmp ( getClassName() + , const_cast("FCheckBox") ) == 0 ); } //---------------------------------------------------------------------- @@ -387,7 +374,7 @@ void FToggleButton::hide() return; blank = new char[size+1]; - memset(blank, ' ', uLong(size)); + std::memset(blank, ' ', uLong(size)); blank[size] = '\0'; printPos (1, 1); print (blank); @@ -465,9 +452,6 @@ bool FToggleButton::setFocus (bool on) setForegroundColor (wc.toggle_button_active_focus_fg); setBackgroundColor (wc.toggle_button_active_focus_bg); - if ( isCursorInside() && (isRadioButton() || isCheckboxButton()) ) - showCursor(); - if ( statusBar() ) { FString msg = getStatusbarMessage(); @@ -486,7 +470,6 @@ bool FToggleButton::setFocus (bool on) { setForegroundColor (wc.toggle_button_active_fg); setBackgroundColor (wc.toggle_button_active_bg); - hideCursor(); if ( statusBar() ) statusBar()->clearMessage(); @@ -593,19 +576,9 @@ void FToggleButton::onAccel (FAccelEvent* ev) } } -//---------------------------------------------------------------------- -void FToggleButton::onHide (FHideEvent*) -{ - if ( hasFocus() ) - hideCursor(); -} - //---------------------------------------------------------------------- void FToggleButton::onFocusIn (FFocusEvent*) { - if ( isCursorInside() && (isRadioButton() || isCheckboxButton()) ) - showCursor(); - if ( statusBar() ) statusBar()->drawMessage(); } @@ -619,8 +592,6 @@ void FToggleButton::onFocusOut (FFocusEvent* out_ev) statusBar()->drawMessage(); } - hideCursor(); - if ( group() ) { if ( ! focus_inside_group && isRadioButton() ) diff --git a/src/ftogglebutton.h b/src/ftogglebutton.h index fbe81fd2..16c014cf 100644 --- a/src/ftogglebutton.h +++ b/src/ftogglebutton.h @@ -87,7 +87,6 @@ class FToggleButton : public FWidget void onMouseDown (FMouseEvent*); void onMouseUp (FMouseEvent*); void onAccel (FAccelEvent*); - void onHide (FHideEvent*); void onFocusIn (FFocusEvent*); void onFocusOut (FFocusEvent*); diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 3249d771..079e458f 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -373,11 +373,11 @@ FTerm::term_area* FWidget::getPrintArea() return print_area; else { - FWidget* area_widget = FWindow::getWindowWidget(this); + FWidget* window = FWindow::getWindowWidget(this); - if ( area_widget ) + if ( window ) { - term_area* area = area_widget->getVWin(); + term_area* area = window->getVWin(); if ( area ) { @@ -449,7 +449,7 @@ void FWidget::adjustSize() if ( getWidth() < size_hints.min_width ) adjust_wsize.setWidth(size_hints.min_width); - if ( getWidth() < 1 ) + if ( getWidth() <= 0 ) adjust_wsize.setWidth(1); // reduce the height if not enough space @@ -459,7 +459,7 @@ void FWidget::adjustSize() if ( getHeight() < size_hints.min_height ) adjust_wsize.setWidth(size_hints.min_height); - if ( getHeight() < 1 ) + if ( getHeight() <= 0 ) adjust_wsize.setHeight(1); } @@ -852,10 +852,12 @@ bool FWidget::focusPrevChild() { if ( prev == this ) return false; + prev->setFocus(); FFocusEvent in (fc::FocusIn_Event); in.setFocusType(fc::FocusPreviousWidget); FApplication::sendEvent(prev, &in); + if ( in.isAccepted() ) { this->draw(); @@ -1908,37 +1910,36 @@ void FWidget::move (int x, int y) return; // Avoid to move widget completely outside the terminal - if ( x+getWidth()-1 < 1 || x > getMaxWidth() || y < 1 || y > getMaxHeight() ) + if ( x+getWidth() <= 1 || x > getMaxWidth() || y < 1 || y > getMaxHeight() ) return; wsize.setPos(x,y); adjust_wsize.setPos(x,y); } -//---------------------------------------------------------------------- -bool FWidget::setCursor() -{ - FPoint* wcursor = &widget_cursor_position; - - if ( isCursorInside() ) - { - setTermXY ( getTermX() + wcursor->getX() - 2 - , getTermY() + wcursor->getY() - 2 ); - return true; - } - else - return false; -} - //---------------------------------------------------------------------- bool FWidget::setCursorPos (register int x, register int y) { widget_cursor_position.setPoint(x,y); - if ( isCursorInside() ) - return true; - else - return false; + if ( (flags & fc::focus) != 0 && ! isWindowWidget() ) + { + FWidget* window = FWindow::getWindowWidget(this); + + if ( window ) + { + if ( term_area* area = window->getVWin() ) + { + setAreaCursor ( getTermX() - window->getTermX() + x + , getTermY() - window->getTermY() + y + , visible_cursor + , area ); + return true; + } + } + } + + return false; } //---------------------------------------------------------------------- @@ -2070,7 +2071,7 @@ void FWidget::clearShadow() else if ( FWidget* p = getParentWidget() ) setColor (wc.shadow_fg, p->getBackgroundColor()); - if ( x2 < offset.getX2() + 1 ) + if ( x2 <= offset.getX2() ) { for (int i=0; i < getHeight(); i++) { @@ -2079,7 +2080,7 @@ void FWidget::clearShadow() } } - if ( y2 < offset.getY2() + 1 ) + if ( y2 <= offset.getY2() ) { printPos (x1+1, y2+1); diff --git a/src/fwidget.h b/src/fwidget.h index a6bc6b51..0e486cf2 100644 --- a/src/fwidget.h +++ b/src/fwidget.h @@ -419,11 +419,13 @@ class FWidget : public FObject, public FTerm virtual bool setDisable(); bool isEnabled() const; + // input cursor visibility for the widget virtual bool setVisibleCursor(bool); virtual bool setVisibleCursor(); virtual bool unsetVisibleCursor(); bool hasVisibleCursor() const; + // widget focusing virtual bool focusFirstChild(); virtual bool focusLastChild(); virtual bool setFocus (bool); @@ -434,13 +436,17 @@ class FWidget : public FObject, public FTerm void setFocusable(); void unsetFocusable(); + // ignore padding from the parent widget bool ignorePadding (bool); bool ignorePadding(); bool acceptPadding(); bool isPaddingIgnored(); + // get the primary widget colors short getForegroundColor() const; short getBackgroundColor() const; + + // positioning int getX() const; int getY() const; const FPoint getPos() const; @@ -493,7 +499,6 @@ class FWidget : public FObject, public FTerm virtual void move (int, int); int getFlags() const; - bool setCursor(); FPoint getCursorPos(); bool setCursorPos (const FPoint&); bool setCursorPos (register int, register int); diff --git a/src/fwindow.cpp b/src/fwindow.cpp index 15f01e65..c074ca5d 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -137,6 +137,51 @@ void FWindow::adjustSize() // public methods of FWindow +//---------------------------------------------------------------------- +void FWindow::drawBorder() +{ + if ( isNewFont() ) + { + int x1 = 1; + int x2 = 1 + getWidth() - 1; + int y1 = 1; + int y2 = 1 + getHeight() - 1; + + printPos (x1, y1); + print (fc::NF_border_corner_upper_left); // ⎡ + + for (int x=x1+1; x < x2; x++) + print (fc::NF_border_line_upper); // ¯ + + print (fc::NF_rev_border_corner_upper_right); // ⎤ + + for (int y=y1+1; y < y2; y++) + { + printPos (x1, y); + // border left ⎸ + print (fc::NF_border_line_left); + printPos (x2, y); + // border right⎹ + print (fc::NF_rev_border_line_right); + } + + printPos (x1, y2); + // lower left corner border ⎣ + print (fc::NF_border_corner_lower_left); + + for (int x=2; x < getWidth(); x++) // low line _ + print (fc::NF_border_line_bottom); + + printPos (x2, y2); + // lower right corner border ⎦ + print (fc::NF_rev_border_corner_lower_right); + } + else + { + FWidget::drawBorder(); + } +} + //---------------------------------------------------------------------- void FWindow::show() { @@ -627,7 +672,10 @@ bool FWindow::activateWindow (bool on) { // activate/deactivate this window if ( on ) + { FApplication::active_window = this; + active_area = getVWin(); + } return window_active = (on) ? true : false; } diff --git a/src/fwindow.h b/src/fwindow.h index 64899868..a34b6864 100644 --- a/src/fwindow.h +++ b/src/fwindow.h @@ -78,6 +78,9 @@ class FWindow : public FWidget ~FWindow (); const char* getClassName() const; + // make every drawBorder from FWidget available + using FWidget::drawBorder; + virtual void drawBorder(); virtual void show(); virtual void hide(); virtual void setWidth (int, bool = true); diff --git a/test/calculator.cpp b/test/calculator.cpp index 83809654..d6271bcb 100644 --- a/test/calculator.cpp +++ b/test/calculator.cpp @@ -235,7 +235,7 @@ Calc::Calc (FWidget* parent) L"&=" }; - setlocale(LC_NUMERIC, "C"); + std::setlocale(LC_NUMERIC, "C"); setText ("calculator"); setGeometry (19, 6, 37, 18); addAccelerator('q'); // press 'q' to quit @@ -425,7 +425,7 @@ bool Calc::isOperatorKey(int key) void Calc::setDisplay (lDouble d) { char buffer[33]; - snprintf (buffer, sizeof(buffer), "%32.11Lg", d); + std::snprintf (buffer, sizeof(buffer), "%32.11Lg", d); input = buffer; } @@ -450,10 +450,10 @@ void Calc::calcInfixOperator() switch ( infix_operator ) { case '*': - if ( fabs(a) > LDBL_EPSILON ) // a != 0.0L + if ( std::fabs(a) > LDBL_EPSILON ) // a != 0.0L { // ln(a * b) = ln(a) + ln(b) - if ( log(abs(a)) + log(abs(b)) <= log(LDBL_MAX) ) + if ( std::log(std::abs(a)) + std::log(std::abs(b)) <= std::log(LDBL_MAX) ) a *= b; else error = true; @@ -463,16 +463,16 @@ void Calc::calcInfixOperator() break; case '/': - if ( fabs(b) > LDBL_EPSILON ) // b != 0.0L + if ( std::fabs(b) > LDBL_EPSILON ) // b != 0.0L a /= b; else error = true; break; case '+': - if ( fabs(a) > LDBL_EPSILON ) // a != 0.0L + if ( std::fabs(a) > LDBL_EPSILON ) // a != 0.0L { - if ( log(abs(a)) + log(abs(1 + b/a)) <= log(LDBL_MAX) ) + if ( std::log(std::abs(a)) + std::log(std::abs(1 + b/a)) <= std::log(LDBL_MAX) ) a += b; else error = true; @@ -482,9 +482,9 @@ void Calc::calcInfixOperator() break; case '-': - if ( fabs(b) > LDBL_EPSILON ) // b != 0.0L + if ( std::fabs(b) > LDBL_EPSILON ) // b != 0.0L { - if ( log(abs(a)) + log(abs(1 - b/a)) <= log(LDBL_MAX) ) + if ( std::log(std::abs(a)) + std::log(std::abs(1 - b/a)) <= std::log(LDBL_MAX) ) a -= b; else error = true; @@ -494,7 +494,7 @@ void Calc::calcInfixOperator() break; case '^': - a = pow(a, b); + a = std::pow(a, b); if ( errno == EDOM || errno == ERANGE ) error = true; @@ -523,7 +523,7 @@ void Calc::onKeyPress (FKeyEvent* ev) else input = input.left(input.getLength() - 1); - a = atof(input.c_str()); + a = std::atof(input.c_str()); drawDispay(); updateTerminal(); } @@ -541,6 +541,7 @@ void Calc::onKeyPress (FKeyEvent* ev) break; default: + FDialog::onKeyPress(ev); break; } } @@ -586,7 +587,7 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) { if ( arcus_mode ) { - *x = log(*x + sqrt((*x) * (*x) + 1)); + *x = std::log(*x + std::sqrt((*x) * (*x) + 1)); if ( errno == EDOM || errno == ERANGE ) error = true; @@ -595,16 +596,16 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) error = true; } else - *x = sinh(*x); + *x = std::sinh(*x); } else { if ( arcus_mode ) - *x = asin(*x) * 180.0L/PI; - else if ( fabs(fmod(*x,180.0L)) < LDBL_EPSILON ) // x/180 = 0 + *x = std::asin(*x) * 180.0L/PI; + else if ( std::fabs(std::fmod(*x,180.0L)) < LDBL_EPSILON ) // x/180 = 0 *x = 0.0L; else - *x = sin(*x * PI/180.0L); + *x = std::sin(*x * PI/180.0L); } if ( errno == EDOM ) @@ -622,7 +623,7 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) { if ( arcus_mode ) { - *x = log(*x + sqrt((*x) * (*x) - 1)); + *x = std::log(*x + std::sqrt((*x) * (*x) - 1)); if ( errno == EDOM || errno == ERANGE ) error = true; @@ -631,16 +632,16 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) error = true; } else - *x = cosh(*x); + *x = std::cosh(*x); } else { if ( arcus_mode ) - *x = acos(*x) * 180.0L/PI; - else if ( fabs(fmod(*x - 90.0L,180.0L)) < LDBL_EPSILON ) // (x - 90)/180 == 0 + *x = std::acos(*x) * 180.0L/PI; + else if ( std::fabs(std::fmod(*x - 90.0L,180.0L)) < LDBL_EPSILON ) // (x - 90)/180 == 0 *x = 0.0L; else - *x = cos(*x * PI/180.0L); + *x = std::cos(*x * PI/180.0L); } if ( errno == EDOM ) @@ -659,7 +660,7 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) if ( arcus_mode ) if ( *x < 1 ) { - *x = 0.5L * log((1+(*x))/(1-(*x))); + *x = 0.5L * std::log((1+(*x))/(1-(*x))); if ( errno == EDOM || errno == ERANGE ) error = true; @@ -667,21 +668,21 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) else error = true; else - *x = tanh(*x); + *x = std::tanh(*x); } else { if ( arcus_mode ) - *x = atan(*x) * 180.0L/PI; + *x = std::atan(*x) * 180.0L/PI; else // Test if (x/180) != 0 and x/90 == 0 - if ( fabs(fmod(*x,180.0L)) > LDBL_EPSILON - && fabs(fmod(*x,90.0L)) < LDBL_EPSILON ) + if ( std::fabs(std::fmod(*x,180.0L)) > LDBL_EPSILON + && std::fabs(std::fmod(*x,90.0L)) < LDBL_EPSILON ) error = true; - else if ( fabs(fmod(*x,180.0L)) < LDBL_EPSILON ) // x/180 == 0 + else if ( std::fabs(std::fmod(*x,180.0L)) < LDBL_EPSILON ) // x/180 == 0 *x = 0.0L; else - *x = tan(*x * PI/180.0L); + *x = std::tan(*x * PI/180.0L); } if ( errno == EDOM ) @@ -695,7 +696,7 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) break; case Reciprocal: // 1/x - if ( fabs(*x) < LDBL_EPSILON ) // x == 0 + if ( std::fabs(*x) < LDBL_EPSILON ) // x == 0 error = true; else { @@ -717,7 +718,7 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) break; case Natural_logarithm: // ln - *x = log(*x); + *x = std::log(*x); if ( errno == EDOM || errno == ERANGE ) error = true; @@ -726,7 +727,7 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) break; case Powers_of_e: // eˣ - *x = exp(*x); + *x = std::exp(*x); if ( errno == ERANGE ) error = true; @@ -743,7 +744,7 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) break; case Square_root: // sqrt - *x = sqrt(*x); + *x = std::sqrt(*x); if ( errno == EDOM || errno == ERANGE ) error = true; @@ -760,7 +761,7 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) break; case Common_logarithm: // lg - *x = log10(*x); + *x = std::log10(*x); if ( errno == EDOM || errno == ERANGE ) error = true; @@ -769,7 +770,7 @@ void Calc::cb_buttonClicked (FWidget*, void* data_ptr) break; case Powers_of_ten: // 10ˣ - *x = pow(10,*x); + *x = std::pow(10,*x); if ( errno == EDOM || errno == ERANGE ) error = true; diff --git a/test/keyboard.cpp b/test/keyboard.cpp index 121e0bba..fc5454ed 100644 --- a/test/keyboard.cpp +++ b/test/keyboard.cpp @@ -34,7 +34,7 @@ keyboard::keyboard (FWidget* parent) void keyboard::onKeyPress (FKeyEvent* ev) { int key_id = ev->key(); - ::printf("Key %s (id %d)\n\r", getKeyName(key_id).c_str(), key_id); + std::printf("Key %s (id %d)\n\r", getKeyName(key_id).c_str(), key_id); } //---------------------------------------------------------------------- diff --git a/test/mandelbrot.cpp b/test/mandelbrot.cpp index f5eb6b3a..dae22246 100644 --- a/test/mandelbrot.cpp +++ b/test/mandelbrot.cpp @@ -58,16 +58,17 @@ void Mandelbrot::draw() xoffset = 2; yoffset = 2; + current_line = 0; Cols = getClientWidth(); Lines = getClientHeight(); - current_line = 1; dX = (x_max - x_min) / (Cols - 1); dY = (y_max - y_min) / Lines; - for (y0=y_min; y0 < y_max && current_line <= Lines; y0+=dY) + for (y0=y_min; y0 < y_max && current_line < Lines; y0+=dY) { - printPos (xoffset, yoffset+current_line); + current_line++; + printPos (xoffset, yoffset + current_line); for (x0=x_min; x0 < x_max; x0+=dX) { @@ -90,8 +91,6 @@ void Mandelbrot::draw() print(' '); } - - current_line++; } updateVTerm(true); diff --git a/test/menu.cpp b/test/menu.cpp index a79ca322..ea0f4738 100644 --- a/test/menu.cpp +++ b/test/menu.cpp @@ -276,14 +276,14 @@ void Menu::adjustSize() int main (int argc, char* argv[]) { - if ( argv[1] && ( strcmp(argv[1], "--help") == 0 - || strcmp(argv[1], "-h") == 0 ) ) + if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0 + || std::strcmp(argv[1], "-h") == 0 ) ) { std::cout << "Generic options:" << std::endl << " -h, --help " << "Display this help and exit" << std::endl; FApplication::print_cmd_Options(); - exit(EXIT_SUCCESS); + std::exit(EXIT_SUCCESS); } FApplication app (argc, argv); diff --git a/test/string-operations.cpp b/test/string-operations.cpp index 49675fdf..3cc5edf3 100644 --- a/test/string-operations.cpp +++ b/test/string-operations.cpp @@ -14,12 +14,12 @@ int main (int, char**) printf ("----------------[ terminal ]-------------------\n"); // init current locale - printf (" Locale: %s\n", setlocale(LC_CTYPE, "") ); + printf (" Locale: %s\n", std::setlocale(LC_CTYPE, "") ); - if ( isatty(1) && ! strcmp(nl_langinfo(CODESET), "ANSI_X3.4-1968") ) + if ( isatty(1) && ! std::strcmp(nl_langinfo(CODESET), "ANSI_X3.4-1968") ) { // locale C -> switch from 7bit ascii -> latin1 - setlocale(LC_ALL, "en_US"); + std::setlocale(LC_ALL, "en_US"); } printf (" Codeset: %s\n", nl_langinfo(CODESET)); @@ -155,7 +155,7 @@ int main (int, char**) std::cerr << "Arithmetic error: " << ex.what() << std::endl; } - setlocale(LC_NUMERIC, "C"); + std::setlocale(LC_NUMERIC, "C"); try { @@ -185,7 +185,7 @@ int main (int, char**) std::cout << " setNumber: " << num3 << " (long double)" << std::endl; - setlocale (LC_NUMERIC, ""); + std::setlocale (LC_NUMERIC, ""); FString fnum1, fnum2; #if defined(__LP64__) || defined(_LP64) // 64-bit architecture diff --git a/test/timer.cpp b/test/timer.cpp index e957b116..5d3cc5e7 100644 --- a/test/timer.cpp +++ b/test/timer.cpp @@ -39,7 +39,7 @@ timer::timer (FWidget* parent) //---------------------------------------------------------------------- void timer::onTimer (FTimerEvent* ev) { - ::printf("timer event, id %d\n\r", ev->timerId() ); + std::printf("timer event, id %d\n\r", ev->timerId() ); } //---------------------------------------------------------------------- diff --git a/test/transparent.cpp b/test/transparent.cpp index e35aeb48..c2f72af3 100644 --- a/test/transparent.cpp +++ b/test/transparent.cpp @@ -267,14 +267,14 @@ void MainWindow::onTimer (FTimerEvent*) int main (int argc, char* argv[]) { - if ( argv[1] && ( strcmp(argv[1], "--help") == 0 - || strcmp(argv[1], "-h") == 0 ) ) + if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0 + || std::strcmp(argv[1], "-h") == 0 ) ) { std::cout << "Generic options:" << std::endl << " -h, --help " << "Display this help and exit" << std::endl; FApplication::print_cmd_Options(); - exit(EXIT_SUCCESS); + std::exit(EXIT_SUCCESS); } FApplication app (argc, argv); diff --git a/test/ui.cpp b/test/ui.cpp index 6650dca0..65e17a5b 100644 --- a/test/ui.cpp +++ b/test/ui.cpp @@ -895,14 +895,14 @@ int main (int argc, char* argv[]) FString ver = F_VERSION; // library version FString title = "The FINAL CUT " + ver + " (C) 2016 by Markus Gans"; - if ( argv[1] && ( strcmp(argv[1], "--help") == 0 - || strcmp(argv[1], "-h") == 0 ) ) + if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0 + || std::strcmp(argv[1], "-h") == 0 ) ) { std::cout << "Generic options:" << std::endl << " -h, --help " << "Display this help and exit" << std::endl; FApplication::print_cmd_Options(); - exit(EXIT_SUCCESS); + std::exit(EXIT_SUCCESS); } FApplication app(argc, argv); diff --git a/test/watch.cpp b/test/watch.cpp index 137c8527..46e89bcb 100644 --- a/test/watch.cpp +++ b/test/watch.cpp @@ -117,11 +117,11 @@ watch::~watch() void watch::printTime() { FString str; - struct tm* now; - time_t t; + std::tm* now; + std::time_t t; - t = time(0); // get current time - now = localtime(&t); + t = std::time(0); // get current time + now = std::localtime(&t); if ( sec ) str.sprintf("%02d:%02d:%02d", now->tm_hour, now->tm_min, now->tm_sec); diff --git a/test/windows.cpp b/test/windows.cpp index dd2db845..63232972 100644 --- a/test/windows.cpp +++ b/test/windows.cpp @@ -565,14 +565,14 @@ void Window::adjustSize() int main (int argc, char* argv[]) { - if ( argv[1] && ( strcmp(argv[1], "--help") == 0 - || strcmp(argv[1], "-h") == 0 ) ) + if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0 + || std::strcmp(argv[1], "-h") == 0 ) ) { std::cout << "Generic options:" << std::endl << " -h, --help " << "Display this help and exit" << std::endl; FApplication::print_cmd_Options(); - exit(EXIT_SUCCESS); + std::exit(EXIT_SUCCESS); } FApplication app (argc, argv);