tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / miscdlgs / inscldlg.cxx
blob21ede36e8f3b5eca6bfb61eefd79188a178182d7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #undef SC_DLLIMPLEMENTATION
22 #include <inscldlg.hxx>
23 #include <viewdata.hxx>
24 #include <strings.hrc>
25 #include <scresid.hxx>
27 static sal_uInt8 nInsItemChecked = 0;
29 ScInsertCellDlg::ScInsertCellDlg(weld::Window* pParent, bool bDisallowCellMove)
30 : GenericDialogController(pParent, u"modules/scalc/ui/insertcells.ui"_ustr,
31 u"InsertCellsDialog"_ustr)
32 , m_xBtnCellsDown(m_xBuilder->weld_radio_button(u"down"_ustr))
33 , m_xBtnCellsRight(m_xBuilder->weld_radio_button(u"right"_ustr))
34 , m_xBtnInsRow(m_xBuilder->weld_radio_button(u"rows"_ustr))
35 , m_xBtnInsCol(m_xBuilder->weld_radio_button(u"cols"_ustr))
36 , m_xNumberOfRows(m_xBuilder->weld_spin_button(u"number_of_rows"_ustr))
37 , m_xNumberOfCols(m_xBuilder->weld_spin_button(u"number_of_columns"_ustr))
39 const ScViewData* pViewData = ScDocShell::GetViewData();
40 if (pViewData && pViewData->GetDocument().IsLayoutRTL(pViewData->GetTabNo()))
41 m_xBtnCellsRight->set_label(ScResId(SCSTR_INSERT_RTL));
43 m_xNumberOfRows->set_range(1, MAX_INS_ROWS);
44 m_xNumberOfRows->set_value(1);
45 m_xNumberOfCols->set_range(1, MAX_INS_COLS);
46 m_xNumberOfCols->set_value(1);
48 m_xBtnInsRow->connect_toggled(LINK(this, ScInsertCellDlg, RadioButtonsHdl));
49 m_xBtnInsCol->connect_toggled(LINK(this, ScInsertCellDlg, RadioButtonsHdl));
51 bool bColCount = false;
52 bool bRowsCount = false;
53 if (bDisallowCellMove)
55 m_xBtnCellsDown->set_sensitive(false);
56 m_xBtnCellsRight->set_sensitive(false);
57 m_xBtnInsRow->set_active(true);
59 bRowsCount = true;
60 switch (nInsItemChecked)
62 case 2:
63 m_xBtnInsRow->set_active(true);
64 break;
65 case 3:
66 m_xBtnInsCol->set_active(true);
67 bRowsCount = false;
68 bColCount = true;
69 break;
70 default:
71 m_xBtnInsRow->set_active(true);
72 break;
75 else
77 switch (nInsItemChecked)
79 case 0:
80 m_xBtnCellsDown->set_active(true);
81 break;
82 case 1:
83 m_xBtnCellsRight->set_active(true);
84 break;
85 case 2:
86 m_xBtnInsRow->set_active(true);
87 bRowsCount = true;
88 bColCount = false;
89 break;
90 case 3:
91 m_xBtnInsCol->set_active(true);
92 bRowsCount = false;
93 bColCount = true;
94 break;
98 // if some cells are selected, then disable the SpinButtons
99 const bool bMarked = pViewData && pViewData->GetMarkData().IsMarked();
100 m_xNumberOfCols->set_sensitive(bColCount && !bMarked);
101 m_xNumberOfRows->set_sensitive(bRowsCount && !bMarked);
104 ScInsertCellDlg::~ScInsertCellDlg() {}
106 InsCellCmd ScInsertCellDlg::GetInsCellCmd() const
108 InsCellCmd nReturn = INS_NONE;
110 if (m_xBtnCellsDown->get_active())
112 nInsItemChecked = 0;
113 nReturn = INS_CELLSDOWN;
115 else if (m_xBtnCellsRight->get_active())
117 nInsItemChecked = 1;
118 nReturn = INS_CELLSRIGHT;
120 else if (m_xBtnInsRow->get_active())
122 nInsItemChecked = 2;
123 nReturn = INS_INSROWS_BEFORE;
125 else if (m_xBtnInsCol->get_active())
127 nInsItemChecked = 3;
128 nReturn = INS_INSCOLS_BEFORE;
131 return nReturn;
134 size_t ScInsertCellDlg::GetCount() const
136 switch (nInsItemChecked)
138 case 2:
139 return m_xNumberOfRows->get_value() - 1;
140 case 3:
141 return m_xNumberOfCols->get_value() - 1;
142 default:
143 return 0;
147 IMPL_LINK_NOARG(ScInsertCellDlg, RadioButtonsHdl, weld::Toggleable&, void)
149 m_xNumberOfRows->set_sensitive(m_xBtnInsRow->get_active());
150 m_xNumberOfCols->set_sensitive(m_xBtnInsCol->get_active());
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */