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 <sfx2/dispatch.hxx>
21 #include <svx/dlgutil.hxx>
22 #include <svtools/unitconv.hxx>
23 #include <colwd.hxx>
24 #include <tablemgr.hxx>
25 #include <wrtsh.hxx>
26 #include <wdocsh.hxx>
27 #include <view.hxx>
28 #include <swmodule.hxx>
29 #include <modcfg.hxx>
30 #include <usrpref.hxx>
31 
32 #include <cmdid.h>
33 
35 {
36  sal_uInt16 nId = static_cast<sal_uInt16>(m_xColNF->get_value()) - 1;
37  const SwTwips lWidth = m_rFnc.GetColWidth(nId);
38  m_xWidthMF->set_max(m_xWidthMF->normalize(m_rFnc.GetMaxColWidth(nId)), FieldUnit::TWIP);
39  m_xWidthMF->set_value(m_xWidthMF->normalize(lWidth), FieldUnit::TWIP);
40 }
41 
43  : GenericDialogController(pParent, "modules/swriter/ui/columnwidth.ui", "ColumnWidthDialog")
44  , m_rFnc(rTableFnc)
45  , m_xColNF(m_xBuilder->weld_spin_button("column"))
46  , m_xWidthMF(m_xBuilder->weld_metric_spin_button("width", FieldUnit::CM))
47 {
48  bool bIsWeb = rTableFnc.GetShell()
49  && (dynamic_cast< const SwWebDocShell* >(
50  rTableFnc.GetShell()->GetView().GetDocShell()) != nullptr );
51  FieldUnit eFieldUnit = SW_MOD()->GetUsrPref( bIsWeb )->GetMetric();
52  ::SetFieldUnit(*m_xWidthMF, eFieldUnit);
53 
54  m_xColNF->set_max(m_rFnc.GetColCount() + 1);
55  m_xColNF->set_value(m_rFnc.GetCurColNum() + 1);
56 
57  if (m_rFnc.GetColCount() == 0)
58  m_xWidthMF->set_min(m_xWidthMF->normalize(m_rFnc.GetColWidth(0)), FieldUnit::TWIP);
59  else
60  m_xWidthMF->set_min(m_xWidthMF->normalize(MINLAY), FieldUnit::TWIP);
61  m_xColNF->connect_value_changed(LINK(this, SwTableWidthDlg, LoseFocusHdl));
62  LoseFocusHdl(*m_xColNF);
63 }
64 
66 {
68  m_rFnc.SetColWidth(static_cast<sal_uInt16>(m_xColNF->get_value() - 1),
69  static_cast<sal_uInt16>(m_xWidthMF->denormalize(m_xWidthMF->get_value(FieldUnit::TWIP))));
70 }
71 
73 {
74  short nRet = GenericDialogController::run();
75  if (nRet == RET_OK)
76  Apply();
77  return nRet;
78 }
79 
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwTableWidthDlg(weld::Window *pParent, SwTableFUNC &rFnc)
Definition: colwd.cxx:42
FieldUnit
SwTwips GetColWidth(sal_uInt16 nNum) const
Definition: tablemgr.cxx:63
#define MINLAY
Definition: swtypes.hxx:66
sal_Int16 nId
long SwTwips
Definition: swtypes.hxx:49
virtual short run() override
Definition: colwd.cxx:72
const SwView & GetView() const
Definition: wrtsh.hxx:426
void InitTabCols()
Definition: tablemgr.cxx:159
#define SW_MOD()
Definition: swmodule.hxx:256
sal_uInt16 GetColCount() const
Definition: tablemgr.cxx:337
IMPL_LINK_NOARG(SwTableWidthDlg, LoseFocusHdl, weld::SpinButton &, void)
Definition: colwd.cxx:34
SwTableFUNC & m_rFnc
Definition: colwd.hxx:29
SwDocShell * GetDocShell()
Definition: view.cxx:1127
void Apply()
Definition: colwd.cxx:65
sal_uInt16 GetCurColNum() const
Definition: tablemgr.cxx:327
SwWrtShell * GetShell() const
Definition: tablemgr.hxx:65
RET_OK
std::unique_ptr< weld::MetricSpinButton > m_xWidthMF
Definition: colwd.hxx:32
void SetColWidth(sal_uInt16 nNum, SwTwips nWidth)
Definition: tablemgr.cxx:122
std::unique_ptr< weld::SpinButton > m_xColNF
Definition: colwd.hxx:31