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  SwInsertTableOptions& rInsTableOpts,
41  SwTableAutoFormat const*& prTAFormat )
42 {
43  if (m_xTabBtn->get_active())
44  {
45  //0x0b mustn't be set when re-converting table into text
46  bIsKeepColumn = !m_xKeepColumn->get_visible() || m_xKeepColumn->get_active();
47  rDelim = bIsKeepColumn ? 0x09 : 0x0b;
48  nSaveButtonState = 0;
49  }
50  else if (m_xSemiBtn->get_active())
51  {
52  rDelim = ';';
53  nSaveButtonState = 1;
54  }
55  else if (m_xOtherBtn->get_active() && !m_xOtherEd->get_text().isEmpty())
56  {
57  uOther = m_xOtherEd->get_text()[0];
58  rDelim = uOther;
59  nSaveButtonState = 3;
60  }
61  else
62  {
63  nSaveButtonState = 2;
64  rDelim = cParaDelim;
65  if (m_xOtherBtn->get_active())
66  {
67  nSaveButtonState = 3;
68  uOther = 0;
69  }
70  }
71 
73  if (m_xHeaderCB->get_active())
74  nInsMode |= SwInsertTableFlags::Headline;
75  if (m_xRepeatHeaderCB->get_sensitive() && m_xRepeatHeaderCB->get_active())
76  rInsTableOpts.mnRowsToRepeat = m_xRepeatHeaderNF->get_value();
77  else
78  rInsTableOpts.mnRowsToRepeat = 0;
79  if (!m_xDontSplitCB->get_active())
81 
82  if (mxTAutoFormat)
83  prTAFormat = new SwTableAutoFormat(*mxTAutoFormat);
84 
85  rInsTableOpts.mnInsMode = nInsMode;
86 }
87 
90  "modules/swriter/ui/converttexttable.ui", "ConvertTextTableDialog")
91  , m_xTabBtn(m_xBuilder->weld_radio_button("tabs"))
92  , m_xSemiBtn(m_xBuilder->weld_radio_button("semicolons"))
93  , m_xParaBtn(m_xBuilder->weld_radio_button("paragraph"))
94  , m_xOtherBtn(m_xBuilder->weld_radio_button("other"))
95  , m_xOtherEd(m_xBuilder->weld_entry("othered"))
96  , m_xKeepColumn(m_xBuilder->weld_check_button("keepcolumn"))
97  , m_xOptions(m_xBuilder->weld_container("options"))
98  , m_xHeaderCB(m_xBuilder->weld_check_button("headingcb"))
99  , m_xRepeatHeaderCB(m_xBuilder->weld_check_button("repeatheading"))
100  , m_xRepeatRows(m_xBuilder->weld_container("repeatrows"))
101  , m_xRepeatHeaderNF(m_xBuilder->weld_spin_button("repeatheadersb"))
102  , m_xDontSplitCB(m_xBuilder->weld_check_button("dontsplitcb"))
103  , m_xAutoFormatBtn(m_xBuilder->weld_button("autofmt"))
104  , pShell(&rView.GetWrtShell())
105 {
106  if (nSaveButtonState > -1)
107  {
108  switch (nSaveButtonState)
109  {
110  case 0:
111  m_xTabBtn->set_active(true);
112  m_xKeepColumn->set_active(bIsKeepColumn);
113  break;
114  case 1:
115  m_xSemiBtn->set_active(true);
116  break;
117  case 2:
118  m_xParaBtn->set_active(true);
119  break;
120  case 3:
121  m_xOtherBtn->set_active(true);
122  if (uOther)
123  m_xOtherEd->set_text(OUString(uOther));
124  break;
125  }
126 
127  }
128  if( bToTable )
129  {
130  m_xDialog->set_title(SwResId(STR_CONVERT_TEXT_TABLE));
131  m_xAutoFormatBtn->connect_clicked(LINK(this, SwConvertTableDlg, AutoFormatHdl));
132  m_xAutoFormatBtn->show();
133  m_xKeepColumn->show();
134  m_xKeepColumn->set_sensitive(m_xTabBtn->get_active());
135  }
136  else
137  {
138  //hide insert options
139  m_xOptions->hide();
140  }
141  m_xKeepColumn->save_state();
142 
143  Link<weld::Button&,void> aLk( LINK(this, SwConvertTableDlg, BtnHdl) );
144  m_xTabBtn->connect_clicked(aLk);
145  m_xSemiBtn->connect_clicked(aLk);
146  m_xParaBtn->connect_clicked(aLk);
147  m_xOtherBtn->connect_clicked(aLk);
148  m_xOtherEd->set_sensitive(m_xOtherBtn->get_active());
149 
150  const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
151 
152  bool bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell())&HTMLMODE_ON);
153 
154  SwInsertTableOptions aInsOpts = pModOpt->GetInsTableFlags(bHTMLMode);
155  SwInsertTableFlags nInsTableFlags = aInsOpts.mnInsMode;
156 
157  m_xHeaderCB->set_active(bool(nInsTableFlags & SwInsertTableFlags::Headline));
158  m_xRepeatHeaderCB->set_active(aInsOpts.mnRowsToRepeat > 0);
159  m_xDontSplitCB->set_active(!(nInsTableFlags & SwInsertTableFlags::SplitLayout));
160 
161  m_xHeaderCB->connect_clicked(LINK(this, SwConvertTableDlg, CheckBoxHdl));
162  m_xRepeatHeaderCB->connect_clicked(LINK(this, SwConvertTableDlg, ReapeatHeaderCheckBoxHdl));
163  ReapeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
164  CheckBoxHdl(*m_xHeaderCB);
165 }
166 
168 {
170 
171  ScopedVclPtr<AbstractSwAutoFormatDlg> pDlg(rFact.CreateSwAutoFormatDlg(m_xDialog.get(), pShell, false, mxTAutoFormat.get()));
172  if (RET_OK == pDlg->Execute())
173  mxTAutoFormat = pDlg->FillAutoFormatOfIndex();
174 }
175 
176 IMPL_LINK(SwConvertTableDlg, BtnHdl, weld::Button&, rButton, void)
177 {
178  if (&rButton == m_xTabBtn.get())
179  m_xKeepColumn->set_state(m_xKeepColumn->get_saved_state());
180  else
181  {
182  if (m_xKeepColumn->get_sensitive())
183  m_xKeepColumn->save_state();
184  m_xKeepColumn->set_active(true);
185  }
186  m_xKeepColumn->set_sensitive(m_xTabBtn->get_active());
187  m_xOtherEd->set_sensitive(m_xOtherBtn->get_active());
188 }
189 
191 {
192  m_xRepeatHeaderCB->set_sensitive(m_xHeaderCB->get_active());
193  ReapeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
194 }
195 
196 IMPL_LINK_NOARG(SwConvertTableDlg, ReapeatHeaderCheckBoxHdl, weld::Button&, void)
197 {
198  bool bEnable = m_xHeaderCB->get_active() && m_xRepeatHeaderCB->get_active();
199  m_xRepeatRows->set_sensitive(bEnable);
200 }
201 
202 /* 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:167
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:88
HTMLMODE_ON
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:337
std::unique_ptr< weld::Entry > m_xOtherEd
Definition: convert.hxx:37
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
SwDocShell * GetDocShell()
Definition: view.cxx:1107
IMPL_LINK(SwConvertTableDlg, BtnHdl, weld::Button &, rButton, void)
Definition: convert.cxx:176
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