LibreOffice Module sw (master)  1
convert.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 <modcfg.hxx>
21 #include <sfx2/htmlmode.hxx>
22 #include <viewopt.hxx>
23 #include <swmodule.hxx>
24 #include <convert.hxx>
25 #include <tablemgr.hxx>
26 #include <view.hxx>
27 #include <tblafmt.hxx>
28 
29 #include <strings.hrc>
30 #include <swabstdlg.hxx>
31 #include <swuiexp.hxx>
32 #include <memory>
33 
34 //keep the state of the buttons on runtime
35 static int nSaveButtonState = -1; // 0: tab, 1: semicolon, 2: paragraph, 3: other, -1: not yet used
36 static bool bIsKeepColumn = true;
37 static sal_Unicode uOther = ',';
38 
40  SwTableAutoFormat const*& prTAFormat)
41 {
42  if (m_xTabBtn->get_active())
43  {
44  //0x0b mustn't be set when re-converting table into text
45  bIsKeepColumn = !m_xKeepColumn->get_visible() || m_xKeepColumn->get_active();
46  rDelim = bIsKeepColumn ? 0x09 : 0x0b;
47  nSaveButtonState = 0;
48  }
49  else if (m_xSemiBtn->get_active())
50  {
51  rDelim = ';';
52  nSaveButtonState = 1;
53  }
54  else if (m_xOtherBtn->get_active() && !m_xOtherEd->get_text().isEmpty())
55  {
56  uOther = m_xOtherEd->get_text()[0];
57  rDelim = uOther;
58  nSaveButtonState = 3;
59  }
60  else
61  {
62  nSaveButtonState = 2;
63  rDelim = cParaDelim;
64  if (m_xOtherBtn->get_active())
65  {
66  nSaveButtonState = 3;
67  uOther = 0;
68  }
69  }
70 
72  if (m_xHeaderCB->get_active())
73  nInsMode |= SwInsertTableFlags::Headline;
74  if (m_xRepeatHeaderCB->get_sensitive() && m_xRepeatHeaderCB->get_active())
75  rInsTableOpts.mnRowsToRepeat = m_xRepeatHeaderNF->get_value();
76  else
77  rInsTableOpts.mnRowsToRepeat = 0;
78  if (!m_xDontSplitCB->get_active())
80 
81  if (mxTAutoFormat)
82  prTAFormat = new SwTableAutoFormat(*mxTAutoFormat);
83 
84  rInsTableOpts.mnInsMode = nInsMode;
85 }
86 
88  : SfxDialogController(rView.GetFrameWeld(), "modules/swriter/ui/converttexttable.ui",
89  "ConvertTextTableDialog")
90  , m_xTabBtn(m_xBuilder->weld_radio_button("tabs"))
91  , m_xSemiBtn(m_xBuilder->weld_radio_button("semicolons"))
92  , m_xParaBtn(m_xBuilder->weld_radio_button("paragraph"))
93  , m_xOtherBtn(m_xBuilder->weld_radio_button("other"))
94  , m_xOtherEd(m_xBuilder->weld_entry("othered"))
95  , m_xKeepColumn(m_xBuilder->weld_check_button("keepcolumn"))
96  , m_xOptions(m_xBuilder->weld_container("options"))
97  , m_xHeaderCB(m_xBuilder->weld_check_button("headingcb"))
98  , m_xRepeatHeaderCB(m_xBuilder->weld_check_button("repeatheading"))
99  , m_xRepeatRows(m_xBuilder->weld_container("repeatrows"))
100  , m_xRepeatHeaderNF(m_xBuilder->weld_spin_button("repeatheadersb"))
101  , m_xDontSplitCB(m_xBuilder->weld_check_button("dontsplitcb"))
102  , m_xAutoFormatBtn(m_xBuilder->weld_button("autofmt"))
103  , pShell(&rView.GetWrtShell())
104 {
105  if (nSaveButtonState > -1)
106  {
107  switch (nSaveButtonState)
108  {
109  case 0:
110  m_xTabBtn->set_active(true);
111  m_xKeepColumn->set_active(bIsKeepColumn);
112  break;
113  case 1:
114  m_xSemiBtn->set_active(true);
115  break;
116  case 2:
117  m_xParaBtn->set_active(true);
118  break;
119  case 3:
120  m_xOtherBtn->set_active(true);
121  if (uOther)
122  m_xOtherEd->set_text(OUString(uOther));
123  break;
124  }
125  }
126  if (bToTable)
127  {
128  m_xDialog->set_title(SwResId(STR_CONVERT_TEXT_TABLE));
129  m_xAutoFormatBtn->connect_clicked(LINK(this, SwConvertTableDlg, AutoFormatHdl));
130  m_xAutoFormatBtn->show();
131  m_xKeepColumn->show();
132  m_xKeepColumn->set_sensitive(m_xTabBtn->get_active());
133  }
134  else
135  {
136  //hide insert options
137  m_xOptions->hide();
138  }
139  m_xKeepColumn->save_state();
140 
142  m_xTabBtn->connect_clicked(aLk);
143  m_xSemiBtn->connect_clicked(aLk);
144  m_xParaBtn->connect_clicked(aLk);
145  m_xOtherBtn->connect_clicked(aLk);
146  m_xOtherEd->set_sensitive(m_xOtherBtn->get_active());
147 
148  const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
149 
150  bool bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell()) & HTMLMODE_ON);
151 
152  SwInsertTableOptions aInsOpts = pModOpt->GetInsTableFlags(bHTMLMode);
153  SwInsertTableFlags nInsTableFlags = aInsOpts.mnInsMode;
154 
155  m_xHeaderCB->set_active(bool(nInsTableFlags & SwInsertTableFlags::Headline));
156  m_xRepeatHeaderCB->set_active(aInsOpts.mnRowsToRepeat > 0);
157  m_xDontSplitCB->set_active(!(nInsTableFlags & SwInsertTableFlags::SplitLayout));
158 
159  m_xHeaderCB->connect_clicked(LINK(this, SwConvertTableDlg, CheckBoxHdl));
160  m_xRepeatHeaderCB->connect_clicked(LINK(this, SwConvertTableDlg, ReapeatHeaderCheckBoxHdl));
161  ReapeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
162  CheckBoxHdl(*m_xHeaderCB);
163 }
164 
166 {
168 
170  rFact.CreateSwAutoFormatDlg(m_xDialog.get(), pShell, false, mxTAutoFormat.get()));
171  if (RET_OK == pDlg->Execute())
172  mxTAutoFormat = pDlg->FillAutoFormatOfIndex();
173 }
174 
175 IMPL_LINK(SwConvertTableDlg, BtnHdl, weld::Button&, rButton, void)
176 {
177  if (&rButton == m_xTabBtn.get())
178  m_xKeepColumn->set_state(m_xKeepColumn->get_saved_state());
179  else
180  {
181  if (m_xKeepColumn->get_sensitive())
182  m_xKeepColumn->save_state();
183  m_xKeepColumn->set_active(true);
184  }
185  m_xKeepColumn->set_sensitive(m_xTabBtn->get_active());
186  m_xOtherEd->set_sensitive(m_xOtherBtn->get_active());
187 }
188 
190 {
191  m_xRepeatHeaderCB->set_sensitive(m_xHeaderCB->get_active());
192  ReapeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
193 }
194 
195 IMPL_LINK_NOARG(SwConvertTableDlg, ReapeatHeaderCheckBoxHdl, weld::Button&, void)
196 {
197  bool bEnable = m_xHeaderCB->get_active() && m_xRepeatHeaderCB->get_active();
198  m_xRepeatRows->set_sensitive(bEnable);
199 }
200 
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Button > m_xAutoFormatBtn
Definition: convert.hxx:49
std::unique_ptr< weld::CheckButton > m_xRepeatHeaderCB
Definition: convert.hxx:43
static bool bIsKeepColumn
Definition: convert.cxx:36
virtual std::unique_ptr< SwTableAutoFormat > FillAutoFormatOfIndex() const =0
SwInsertTableFlags mnInsMode
Definition: itabenum.hxx:40
std::unique_ptr< weld::RadioButton > m_xTabBtn
Definition: convert.hxx:33
virtual short Execute()=0
sal_uInt16 mnRowsToRepeat
Definition: itabenum.hxx:41
SwInsertTableFlags
Definition: itabenum.hxx:25
std::unique_ptr< weld::CheckButton > m_xDontSplitCB
Definition: convert.hxx:48
sal_uInt16 sal_Unicode
std::unique_ptr< weld::CheckButton > m_xHeaderCB
Definition: convert.hxx:42
virtual VclPtr< AbstractSwAutoFormatDlg > CreateSwAutoFormatDlg(weld::Window *pParent, SwWrtShell *pShell, bool bSetAutoFormat=true, const SwTableAutoFormat *pSelFormat=nullptr)=0
IMPL_LINK_NOARG(SwConvertTableDlg, AutoFormatHdl, weld::Button &, void)
Definition: convert.cxx:165
static sal_Unicode uOther
Definition: convert.cxx:37
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
#define SW_MOD()
Definition: swmodule.hxx:255
SwAbstractDialogFactory & GetFactory()
Definition: swuiexp.cxx:26
SwConvertTableDlg(SwView &rView, bool bToTable)
Definition: convert.cxx:87
HTMLMODE_ON
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:345
std::unique_ptr< weld::Entry > m_xOtherEd
Definition: convert.hxx:37
OUString SwResId(const char *pId)
Definition: swmodule.cxx:165
SwDocShell * GetDocShell()
Definition: view.cxx:1109
IMPL_LINK(SwConvertTableDlg, BtnHdl, weld::Button &, rButton, void)
Definition: convert.cxx:175
std::unique_ptr< weld::RadioButton > m_xOtherBtn
Definition: convert.hxx:36
const char cParaDelim
Definition: tablemgr.hxx:41
std::unique_ptr< weld::Container > m_xOptions
Definition: convert.hxx:40
std::unique_ptr< weld::CheckButton > m_xKeepColumn
Definition: convert.hxx:38
static int nSaveButtonState
Definition: convert.cxx:35
RET_OK
Reference< XExecutableDialog > m_xDialog
std::unique_ptr< SwTableAutoFormat > mxTAutoFormat
Definition: convert.hxx:51
std::unique_ptr< weld::RadioButton > m_xSemiBtn
Definition: convert.hxx:34
std::unique_ptr< weld::SpinButton > m_xRepeatHeaderNF
Definition: convert.hxx:46
const SwInsertTableOptions & GetInsTableFlags(bool bHTML) const
Definition: modcfg.hxx:303
void GetValues(sal_Unicode &rDelim, SwInsertTableOptions &rInsTableOpts, SwTableAutoFormat const *&prTAFormat)
Definition: convert.cxx:39
std::unique_ptr< weld::RadioButton > m_xParaBtn
Definition: convert.hxx:35
Definition: view.hxx:144