diff --git a/source/worksheet/worksheet.cpp b/source/worksheet/worksheet.cpp index bdec992d..5ca606c2 100644 --- a/source/worksheet/worksheet.cpp +++ b/source/worksheet/worksheet.cpp @@ -290,13 +290,17 @@ void worksheet::freeze_panes(xlnt::cell top_left_cell) void worksheet::freeze_panes(const cell_reference &ref) { + if (ref == "A1") + { + unfreeze_panes(); + return; + } if (!has_view()) { d_->views_.push_back(sheet_view()); } auto &primary_view = d_->views_.front(); - if (!primary_view.has_pane()) { primary_view.pane(pane()); @@ -307,38 +311,40 @@ void worksheet::freeze_panes(const cell_reference &ref) primary_view.clear_selections(); primary_view.add_selection(selection()); - - if (ref == "A1") + primary_view.add_selection(selection()); + if (ref.column() == "A") // no column is frozen { - unfreeze_panes(); - } - else if (ref.column() == "A") - { - primary_view.add_selection(selection()); primary_view.selection(0).pane(pane_corner::bottom_left); + primary_view.selection(0).sqref("A1"); primary_view.selection(0).active_cell(ref.make_offset(0, -1)); // cell above + primary_view.selection(1).pane(pane_corner::bottom_right); + primary_view.selection(1).sqref("A1"); primary_view.selection(1).active_cell(ref); primary_view.pane().active_pane = pane_corner::bottom_left; primary_view.pane().y_split = ref.row() - 1; } - else if (ref.row() == 1) + else if (ref.row() == 1) // no row is frozen { - primary_view.add_selection(selection()); primary_view.selection(0).pane(pane_corner::top_right); + primary_view.selection(0).sqref("A1"); primary_view.selection(0).active_cell(ref.make_offset(-1, 0)); // cell to the left + primary_view.selection(1).pane(pane_corner::bottom_right); + primary_view.selection(1).sqref("A1"); primary_view.selection(1).active_cell(ref); primary_view.pane().active_pane = pane_corner::top_right; primary_view.pane().x_split = ref.column_index() - 1; } - else + else // column and row is frozen { - primary_view.add_selection(selection()); primary_view.add_selection(selection()); primary_view.selection(0).pane(pane_corner::top_right); + primary_view.selection(0).sqref("A1"); primary_view.selection(0).active_cell(ref.make_offset(0, -1)); // cell above primary_view.selection(1).pane(pane_corner::bottom_left); + primary_view.selection(1).sqref("A1"); primary_view.selection(1).active_cell(ref.make_offset(-1, 0)); // cell to the left primary_view.selection(2).pane(pane_corner::bottom_right); + primary_view.selection(2).sqref("A1"); primary_view.selection(2).active_cell(ref); primary_view.pane().active_pane = pane_corner::bottom_right; primary_view.pane().x_split = ref.column_index() - 1; diff --git a/tests/worksheet/worksheet_test_suite.hpp b/tests/worksheet/worksheet_test_suite.hpp index e43021f5..16115b09 100644 --- a/tests/worksheet/worksheet_test_suite.hpp +++ b/tests/worksheet/worksheet_test_suite.hpp @@ -495,7 +495,7 @@ public: xlnt_assert_equals(view.selections().size(), 2); xlnt_assert_equals(view.selections()[0].active_cell(), "A3"); xlnt_assert_equals(view.selections()[0].pane(), xlnt::pane_corner::bottom_left); - xlnt_assert_equals(view.selections()[0].sqref(), "A1"); + xlnt_assert_equals(view.selections()[0].sqref(), "A1"); // TODO: document sqref and clarify whether 'A1' is the intended value here xlnt_assert_equals(view.pane().active_pane, xlnt::pane_corner::bottom_left); xlnt_assert_equals(view.pane().state, xlnt::pane_state::frozen); xlnt_assert_equals(view.pane().top_left_cell.get(), "A4"); @@ -512,7 +512,7 @@ public: xlnt_assert_equals(view.selections().size(), 2); xlnt_assert_equals(view.selections()[0].active_cell(), "C1"); xlnt_assert_equals(view.selections()[0].pane(), xlnt::pane_corner::top_right); - xlnt_assert_equals(view.selections()[0].sqref(), "A1"); + xlnt_assert_equals(view.selections()[0].sqref(), "A1"); // TODO: document sqref and clarify whether 'A1' is the intended value here xlnt_assert_equals(view.pane().active_pane, xlnt::pane_corner::top_right); xlnt_assert_equals(view.pane().state, xlnt::pane_state::frozen); xlnt_assert_equals(view.pane().top_left_cell.get(), "D1"); @@ -531,7 +531,7 @@ public: xlnt_assert_equals(view.selections()[1].pane(), xlnt::pane_corner::bottom_left); xlnt_assert_equals(view.selections()[2].active_cell(), "D4"); xlnt_assert_equals(view.selections()[2].pane(), xlnt::pane_corner::bottom_right); - xlnt_assert_equals(view.selections()[2].sqref(), "A1"); + xlnt_assert_equals(view.selections()[2].sqref(), "A1"); // TODO: document sqref and clarify whether 'A1' is the intended value here xlnt_assert_equals(view.pane().active_pane, xlnt::pane_corner::bottom_right); xlnt_assert_equals(view.pane().state, xlnt::pane_state::frozen); xlnt_assert_equals(view.pane().top_left_cell.get(), "D4");