1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sfx2/htmlmode.hxx>
22 #include <viewopt.hxx>
23 #include <swmodule.hxx>
24 #include <convert.hxx>
25 #include <tablemgr.hxx>
27 #include <tblafmt.hxx>
29 #include <strings.hrc>
30 #include <swabstdlg.hxx>
31 #include <swuiexp.hxx>
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
= ',';
39 void SwConvertTableDlg::GetValues(sal_Unicode
& rDelim
, SwInsertTableOptions
& rInsTableOpts
,
40 SwTableAutoFormat
const*& prTAFormat
)
42 if (m_xTabBtn
->get_active())
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;
49 else if (m_xSemiBtn
->get_active())
54 else if (m_xOtherBtn
->get_active() && !m_xOtherEd
->get_text().isEmpty())
56 uOther
= m_xOtherEd
->get_text()[0];
64 if (m_xOtherBtn
->get_active())
71 SwInsertTableFlags nInsMode
= SwInsertTableFlags::NONE
;
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();
77 rInsTableOpts
.mnRowsToRepeat
= 0;
78 if (!m_xDontSplitCB
->get_active())
79 nInsMode
|= SwInsertTableFlags::SplitLayout
;
82 prTAFormat
= new SwTableAutoFormat(*mxTAutoFormat
);
84 rInsTableOpts
.mnInsMode
= nInsMode
;
87 SwConvertTableDlg::SwConvertTableDlg(SwView
& rView
, bool bToTable
)
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())
105 if (nSaveButtonState
> -1)
107 switch (nSaveButtonState
)
110 m_xTabBtn
->set_active(true);
111 m_xKeepColumn
->set_active(bIsKeepColumn
);
114 m_xSemiBtn
->set_active(true);
117 m_xParaBtn
->set_active(true);
120 m_xOtherBtn
->set_active(true);
122 m_xOtherEd
->set_text(OUString(uOther
));
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());
136 //hide insert options
139 m_xKeepColumn
->save_state();
141 Link
<weld::Toggleable
&, void> aLk(LINK(this, SwConvertTableDlg
, BtnHdl
));
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());
148 const SwModuleOptions
* pModOpt
= SW_MOD()->GetModuleConfig();
150 bool bHTMLMode
= 0 != (::GetHtmlMode(rView
.GetDocShell()) & HTMLMODE_ON
);
152 SwInsertTableOptions aInsOpts
= pModOpt
->GetInsTableFlags(bHTMLMode
);
153 SwInsertTableFlags nInsTableFlags
= aInsOpts
.mnInsMode
;
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
));
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
);
165 IMPL_LINK_NOARG(SwConvertTableDlg
, AutoFormatHdl
, weld::Button
&, void)
167 SwAbstractDialogFactory
& rFact
= swui::GetFactory();
169 ScopedVclPtr
<AbstractSwAutoFormatDlg
> pDlg(
170 rFact
.CreateSwAutoFormatDlg(m_xDialog
.get(), m_pShell
, false, mxTAutoFormat
.get()));
171 if (RET_OK
== pDlg
->Execute())
172 mxTAutoFormat
= pDlg
->FillAutoFormatOfIndex();
175 IMPL_LINK(SwConvertTableDlg
, BtnHdl
, weld::Toggleable
&, rButton
, void)
177 if (!rButton
.get_active())
179 if (m_xTabBtn
->get_active())
180 m_xKeepColumn
->set_state(m_xKeepColumn
->get_saved_state());
183 if (m_xKeepColumn
->get_sensitive())
184 m_xKeepColumn
->save_state();
185 m_xKeepColumn
->set_active(true);
187 m_xKeepColumn
->set_sensitive(m_xTabBtn
->get_active());
188 m_xOtherEd
->set_sensitive(m_xOtherBtn
->get_active());
191 IMPL_LINK_NOARG(SwConvertTableDlg
, CheckBoxHdl
, weld::Toggleable
&, void)
193 m_xRepeatHeaderCB
->set_sensitive(m_xHeaderCB
->get_active());
194 RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB
);
197 IMPL_LINK_NOARG(SwConvertTableDlg
, RepeatHeaderCheckBoxHdl
, weld::Toggleable
&, void)
199 bool bEnable
= m_xHeaderCB
->get_active() && m_xRepeatHeaderCB
->get_active();
200 m_xRepeatRows
->set_sensitive(bEnable
);
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */