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