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
35static int nSaveButtonState = -1; // 0: tab, 1: semicolon, 2: paragraph, 3: other, -1: not yet used
36static bool bIsKeepColumn = true;
37static 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;
48 }
49 else if (m_xSemiBtn->get_active())
50 {
51 rDelim = ';';
53 }
54 else if (m_xOtherBtn->get_active() && !m_xOtherEd->get_text().isEmpty())
55 {
56 uOther = m_xOtherEd->get_text()[0];
57 rDelim = uOther;
59 }
60 else
61 {
63 rDelim = cParaDelim;
64 if (m_xOtherBtn->get_active())
65 {
67 uOther = 0;
68 }
69 }
70
72 if (m_xHeaderCB->get_active())
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 , m_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_toggled(aLk);
143 m_xSemiBtn->connect_toggled(aLk);
144 m_xParaBtn->connect_toggled(aLk);
145 m_xOtherBtn->connect_toggled(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_toggled(LINK(this, SwConvertTableDlg, CheckBoxHdl));
160 m_xRepeatHeaderCB->connect_toggled(LINK(this, SwConvertTableDlg, RepeatHeaderCheckBoxHdl));
161 RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
162 CheckBoxHdl(*m_xHeaderCB);
163}
164
166{
168
170 rFact.CreateSwAutoFormatDlg(m_xDialog.get(), m_pShell, false, mxTAutoFormat.get()));
171 if (RET_OK == pDlg->Execute())
172 mxTAutoFormat = pDlg->FillAutoFormatOfIndex();
173}
174
176{
177 if (!rButton.get_active())
178 return;
179 if (m_xTabBtn->get_active())
180 m_xKeepColumn->set_state(m_xKeepColumn->get_saved_state());
181 else
182 {
183 if (m_xKeepColumn->get_sensitive())
184 m_xKeepColumn->save_state();
185 m_xKeepColumn->set_active(true);
186 }
187 m_xKeepColumn->set_sensitive(m_xTabBtn->get_active());
188 m_xOtherEd->set_sensitive(m_xOtherBtn->get_active());
189}
190
192{
193 m_xRepeatHeaderCB->set_sensitive(m_xHeaderCB->get_active());
194 RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
195}
196
197IMPL_LINK_NOARG(SwConvertTableDlg, RepeatHeaderCheckBoxHdl, weld::Toggleable&, void)
198{
199 bool bEnable = m_xHeaderCB->get_active() && m_xRepeatHeaderCB->get_active();
200 m_xRepeatRows->set_sensitive(bEnable);
201}
202
203/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
virtual VclPtr< AbstractSwAutoFormatDlg > CreateSwAutoFormatDlg(weld::Window *pParent, SwWrtShell *pShell, bool bSetAutoFormat=true, const SwTableAutoFormat *pSelFormat=nullptr)=0
std::unique_ptr< weld::Button > m_xAutoFormatBtn
Definition: convert.hxx:49
std::unique_ptr< weld::RadioButton > m_xTabBtn
Definition: convert.hxx:33
std::unique_ptr< SwTableAutoFormat > mxTAutoFormat
Definition: convert.hxx:51
void GetValues(sal_Unicode &rDelim, SwInsertTableOptions &rInsTableOpts, SwTableAutoFormat const *&prTAFormat)
Definition: convert.cxx:39
std::unique_ptr< weld::CheckButton > m_xDontSplitCB
Definition: convert.hxx:48
std::unique_ptr< weld::RadioButton > m_xOtherBtn
Definition: convert.hxx:36
std::unique_ptr< weld::CheckButton > m_xHeaderCB
Definition: convert.hxx:42
std::unique_ptr< weld::SpinButton > m_xRepeatHeaderNF
Definition: convert.hxx:46
std::unique_ptr< weld::CheckButton > m_xKeepColumn
Definition: convert.hxx:38
std::unique_ptr< weld::RadioButton > m_xSemiBtn
Definition: convert.hxx:34
std::unique_ptr< weld::RadioButton > m_xParaBtn
Definition: convert.hxx:35
std::unique_ptr< weld::Entry > m_xOtherEd
Definition: convert.hxx:37
SwConvertTableDlg(SwView &rView, bool bToTable)
Definition: convert.cxx:87
std::unique_ptr< weld::Container > m_xOptions
Definition: convert.hxx:40
std::unique_ptr< weld::CheckButton > m_xRepeatHeaderCB
Definition: convert.hxx:43
const SwInsertTableOptions & GetInsTableFlags(bool bHTML) const
Definition: modcfg.hxx:303
Definition: view.hxx:146
SwDocShell * GetDocShell()
Definition: view.cxx:1161
IMPL_LINK_NOARG(SwConvertTableDlg, AutoFormatHdl, weld::Button &, void)
Definition: convert.cxx:165
IMPL_LINK(SwConvertTableDlg, BtnHdl, weld::Toggleable &, rButton, void)
Definition: convert.cxx:175
static sal_Unicode uOther
Definition: convert.cxx:37
static int nSaveButtonState
Definition: convert.cxx:35
static bool bIsKeepColumn
Definition: convert.cxx:36
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
HTMLMODE_ON
Shell * m_pShell
SwInsertTableFlags
Definition: itabenum.hxx:26
SwAbstractDialogFactory & GetFactory()
Definition: swuiexp.cxx:26
sal_uInt16 mnRowsToRepeat
Definition: itabenum.hxx:41
SwInsertTableFlags mnInsMode
Definition: itabenum.hxx:40
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
#define SW_MOD()
Definition: swmodule.hxx:256
const char cParaDelim
Definition: tablemgr.hxx:40
sal_uInt16 sal_Unicode
RET_OK
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:332