android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / table / colwd.cxx
blob2440d8696fac869d1946d94400e6fa43e29e2dce
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 #include <svtools/unitconv.hxx>
21 #include <colwd.hxx>
22 #include <tablemgr.hxx>
23 #include <wrtsh.hxx>
24 #include <wdocsh.hxx>
25 #include <view.hxx>
26 #include <swmodule.hxx>
27 #include <usrpref.hxx>
29 IMPL_LINK_NOARG(SwTableWidthDlg, LoseFocusHdl, weld::SpinButton&, void)
31 sal_uInt16 nId = o3tl::narrowing<sal_uInt16>(m_xColNF->get_value()) - 1;
32 const SwTwips lWidth = m_rFnc.GetColWidth(nId);
33 m_xWidthMF->set_max(m_xWidthMF->normalize(m_rFnc.GetMaxColWidth(nId)), FieldUnit::TWIP);
34 m_xWidthMF->set_value(m_xWidthMF->normalize(lWidth), FieldUnit::TWIP);
37 SwTableWidthDlg::SwTableWidthDlg(weld::Window *pParent, SwTableFUNC &rTableFnc)
38 : GenericDialogController(pParent, "modules/swriter/ui/columnwidth.ui", "ColumnWidthDialog")
39 , m_rFnc(rTableFnc)
40 , m_xColNF(m_xBuilder->weld_spin_button("column"))
41 , m_xWidthMF(m_xBuilder->weld_metric_spin_button("width", FieldUnit::CM))
43 bool bIsWeb = rTableFnc.GetShell()
44 && (dynamic_cast< const SwWebDocShell* >(
45 rTableFnc.GetShell()->GetView().GetDocShell()) != nullptr );
46 FieldUnit eFieldUnit = SW_MOD()->GetUsrPref( bIsWeb )->GetMetric();
47 ::SetFieldUnit(*m_xWidthMF, eFieldUnit);
49 m_xColNF->set_max(m_rFnc.GetColCount() + 1);
50 m_xColNF->set_value(m_rFnc.GetCurColNum() + 1);
52 if (m_rFnc.GetColCount() == 0)
53 m_xWidthMF->set_min(m_xWidthMF->normalize(m_rFnc.GetColWidth(0)), FieldUnit::TWIP);
54 else
55 m_xWidthMF->set_min(m_xWidthMF->normalize(MINLAY), FieldUnit::TWIP);
56 m_xColNF->connect_value_changed(LINK(this, SwTableWidthDlg, LoseFocusHdl));
57 LoseFocusHdl(*m_xColNF);
60 void SwTableWidthDlg::Apply()
62 m_rFnc.InitTabCols();
63 m_rFnc.SetColWidth(o3tl::narrowing<sal_uInt16>(m_xColNF->get_value() - 1),
64 o3tl::narrowing<sal_uInt16>(m_xWidthMF->denormalize(m_xWidthMF->get_value(FieldUnit::TWIP))));
67 short SwTableWidthDlg::run()
69 short nRet = GenericDialogController::run();
70 if (nRet == RET_OK)
71 Apply();
72 return nRet;
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */