LibreOffice Module sw (master) 1
colwd.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
28
30{
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);
35}
36
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))
42{
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);
48
49 m_xColNF->set_max(m_rFnc.GetColCount() + 1);
50 m_xColNF->set_value(m_rFnc.GetCurColNum() + 1);
51
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);
58}
59
61{
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))));
65}
66
68{
69 short nRet = GenericDialogController::run();
70 if (nRet == RET_OK)
71 Apply();
72 return nRet;
73}
74
75/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void InitTabCols()
Definition: tablemgr.cxx:154
sal_uInt16 GetColCount() const
Definition: tablemgr.cxx:330
SwWrtShell * GetShell() const
Definition: tablemgr.hxx:63
void SetColWidth(sal_uInt16 nNum, SwTwips nWidth)
Definition: tablemgr.cxx:117
SwTwips GetColWidth(sal_uInt16 nNum) const
Definition: tablemgr.cxx:58
sal_uInt16 GetCurColNum() const
Definition: tablemgr.cxx:320
std::unique_ptr< weld::MetricSpinButton > m_xWidthMF
Definition: colwd.hxx:32
void Apply()
Definition: colwd.cxx:60
std::unique_ptr< weld::SpinButton > m_xColNF
Definition: colwd.hxx:31
virtual short run() override
Definition: colwd.cxx:67
SwTableFUNC & m_rFnc
Definition: colwd.hxx:29
SwTableWidthDlg(weld::Window *pParent, SwTableFUNC &rFnc)
Definition: colwd.cxx:37
SwDocShell * GetDocShell()
Definition: view.cxx:1193
const SwView & GetView() const
Definition: wrtsh.hxx:443
IMPL_LINK_NOARG(SwTableWidthDlg, LoseFocusHdl, weld::SpinButton &, void)
Definition: colwd.cxx:29
FieldUnit
sal_Int16 nId
#define SW_MOD()
Definition: swmodule.hxx:254
#define MINLAY
Definition: swtypes.hxx:62
tools::Long SwTwips
Definition: swtypes.hxx:51
RET_OK