bool wex::grid::find_next(const std::string& text, bool forward) { if (text.empty()) { return false; } static bool recursive = false; static int start_row; static int end_row; static int init_row; static int start_col; static int end_col; wxString text_use = text; if (!find_replace_data::get()->match_case()) { text_use.MakeUpper(); } wxGridCellCoords grid_cursor(GetGridCursorRow(), GetGridCursorCol()); if (forward) { init_row = 0; if (recursive) { start_row = init_row; start_col = 0; } else { start_row = grid_cursor.GetRow() + 1; start_col = grid_cursor.GetCol(); } end_row = GetNumberRows(); end_col = GetNumberCols(); } else { init_row = GetNumberRows() - 1; if (recursive) { start_row = init_row; start_col = GetNumberCols() - 1; } else { start_row = grid_cursor.GetRow() - 1; start_col = grid_cursor.GetCol(); } end_row = -1; end_col = -1; } if (start_col == -1) { start_col = 0; } if (start_row == -1) { start_row = 0; } wxGridCellCoords match; for (int j = start_col; j != end_col && !match; (forward ? j++: j--)) { for (int i = (j == start_col ? start_row: init_row); i != end_row && !match; (forward ? i++: i--)) { wxString text = GetCellValue(i, j); if (!find_replace_data::get()->match_case()) { text.MakeUpper(); } if (find_replace_data::get()->match_word()) { if (text == text_use) { match = wxGridCellCoords(i, j); } } else { if (text.Contains(text_use)) { match = wxGridCellCoords(i, j); } } } } if (!match) { bool result = false; frame::statustext( get_find_result(text, forward, recursive), std::string()); if (!recursive) { recursive = true; result = find_next(text, forward); recursive = false; } return result; } else { recursive = false; SetGridCursor(match.GetRow(), match.GetCol()); MakeCellVisible(match); // though docs say this isn't necessary, it is return true; } }