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 #include <vcl/svapp.hxx>
35 #include <vcl/weld.hxx>
36 #include <sal/log.hxx>
37 #include <shellres.hxx>
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
= ',';
44 void SwConvertTableDlg::GetValues(sal_Unicode
& rDelim
, SwInsertTableOptions
& rInsTableOpts
,
45 SwTableAutoFormat
const*& prTAFormat
)
47 if (m_xTabBtn
->get_active())
49 //0x0b mustn't be set when re-converting table into text
50 bIsKeepColumn
= !m_xKeepColumn
->get_visible() || m_xKeepColumn
->get_active();
51 rDelim
= bIsKeepColumn
? 0x09 : 0x0b;
54 else if (m_xSemiBtn
->get_active())
59 else if (m_xOtherBtn
->get_active() && !m_xOtherEd
->get_text().isEmpty())
61 uOther
= m_xOtherEd
->get_text()[0];
69 if (m_xOtherBtn
->get_active())
76 SwInsertTableFlags nInsMode
= SwInsertTableFlags::NONE
;
77 if (m_xHeaderCB
->get_active())
78 nInsMode
|= SwInsertTableFlags::Headline
;
79 if (m_xRepeatHeaderCB
->get_sensitive() && m_xRepeatHeaderCB
->get_active())
80 rInsTableOpts
.mnRowsToRepeat
= m_xRepeatHeaderNF
->get_value();
82 rInsTableOpts
.mnRowsToRepeat
= 0;
83 if (!m_xDontSplitCB
->get_active())
84 nInsMode
|= SwInsertTableFlags::SplitLayout
;
87 prTAFormat
= new SwTableAutoFormat(*mxTAutoFormat
);
89 rInsTableOpts
.mnInsMode
= nInsMode
;
92 SwConvertTableDlg::SwConvertTableDlg(SwView
& rView
, bool bToTable
)
93 : SfxDialogController(rView
.GetFrameWeld(), u
"modules/swriter/ui/converttexttable.ui"_ustr
,
94 u
"ConvertTextTableDialog"_ustr
)
97 , m_bCoreDataChanged(false)
98 , m_xTableTable(new SwTableAutoFormatTable
)
99 , m_xTabBtn(m_xBuilder
->weld_radio_button(u
"tabs"_ustr
))
100 , m_xSemiBtn(m_xBuilder
->weld_radio_button(u
"semicolons"_ustr
))
101 , m_xParaBtn(m_xBuilder
->weld_radio_button(u
"paragraph"_ustr
))
102 , m_xOtherBtn(m_xBuilder
->weld_radio_button(u
"other"_ustr
))
103 , m_xOtherEd(m_xBuilder
->weld_entry(u
"othered"_ustr
))
104 , m_xKeepColumn(m_xBuilder
->weld_check_button(u
"keepcolumn"_ustr
))
105 , m_xOptions(m_xBuilder
->weld_container(u
"options"_ustr
))
106 , m_xHeaderCB(m_xBuilder
->weld_check_button(u
"headingcb"_ustr
))
107 , m_xRepeatHeaderCB(m_xBuilder
->weld_check_button(u
"repeatheading"_ustr
))
108 , m_xRepeatRows(m_xBuilder
->weld_container(u
"repeatrows"_ustr
))
109 , m_xRepeatHeaderNF(m_xBuilder
->weld_spin_button(u
"repeatheadersb"_ustr
))
110 , m_xDontSplitCB(m_xBuilder
->weld_check_button(u
"dontsplitcb"_ustr
))
111 , m_xLbFormat(m_xBuilder
->weld_tree_view(u
"formatlb"_ustr
))
112 , m_xBtnNumFormat(m_xBuilder
->weld_check_button(u
"numformatcb"_ustr
))
113 , m_xBtnBorder(m_xBuilder
->weld_check_button(u
"bordercb"_ustr
))
114 , m_xBtnFont(m_xBuilder
->weld_check_button(u
"fontcb"_ustr
))
115 , m_xBtnPattern(m_xBuilder
->weld_check_button(u
"patterncb"_ustr
))
116 , m_xBtnAlignment(m_xBuilder
->weld_check_button(u
"alignmentcb"_ustr
))
117 , m_xWndPreview(new weld::CustomWeld(*m_xBuilder
, u
"preview"_ustr
, m_aWndPreview
))
119 m_aWndPreview
.DetectRTL(&rView
.GetWrtShell());
120 m_xTableTable
->Load();
122 const int nWidth
= m_xLbFormat
->get_approximate_digit_width() * 32;
123 const int nHeight
= m_xLbFormat
->get_height_rows(8);
124 m_xLbFormat
->set_size_request(nWidth
, nHeight
);
125 m_xWndPreview
->set_size_request(nWidth
, nHeight
);
127 if (nSaveButtonState
> -1)
129 switch (nSaveButtonState
)
132 m_xTabBtn
->set_active(true);
133 m_xKeepColumn
->set_active(bIsKeepColumn
);
136 m_xSemiBtn
->set_active(true);
139 m_xParaBtn
->set_active(true);
142 m_xOtherBtn
->set_active(true);
144 m_xOtherEd
->set_text(OUString(uOther
));
150 m_xDialog
->set_title(SwResId(STR_CONVERT_TEXT_TABLE
));
151 m_xKeepColumn
->show();
152 m_xKeepColumn
->set_sensitive(m_xTabBtn
->get_active());
156 //hide insert options
159 m_xKeepColumn
->save_state();
161 Link
<weld::Toggleable
&, void> aLk(LINK(this, SwConvertTableDlg
, BtnHdl
));
162 m_xTabBtn
->connect_toggled(aLk
);
163 m_xSemiBtn
->connect_toggled(aLk
);
164 m_xParaBtn
->connect_toggled(aLk
);
165 m_xOtherBtn
->connect_toggled(aLk
);
166 m_xOtherEd
->set_sensitive(m_xOtherBtn
->get_active());
168 const SwModuleOptions
* pModOpt
= SwModule::get()->GetModuleConfig();
170 bool bHTMLMode
= 0 != (::GetHtmlMode(rView
.GetDocShell()) & HTMLMODE_ON
);
172 SwInsertTableOptions aInsOpts
= pModOpt
->GetInsTableFlags(bHTMLMode
);
173 SwInsertTableFlags nInsTableFlags
= aInsOpts
.mnInsMode
;
175 m_xHeaderCB
->set_active(bool(nInsTableFlags
& SwInsertTableFlags::Headline
));
176 m_xRepeatHeaderCB
->set_active(aInsOpts
.mnRowsToRepeat
> 0);
177 m_xDontSplitCB
->set_active(!(nInsTableFlags
& SwInsertTableFlags::SplitLayout
));
179 m_xHeaderCB
->connect_toggled(LINK(this, SwConvertTableDlg
, CheckBoxHdl
));
180 m_xRepeatHeaderCB
->connect_toggled(LINK(this, SwConvertTableDlg
, RepeatHeaderCheckBoxHdl
));
181 RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB
);
182 CheckBoxHdl(*m_xHeaderCB
);
186 SwConvertTableDlg::~SwConvertTableDlg()
190 if (m_bCoreDataChanged
)
191 m_xTableTable
->Save();
196 m_xTableTable
.reset();
199 void SwConvertTableDlg::Init()
201 const SwTableAutoFormat
* pSelFormat
= mxTAutoFormat
.get();
202 Link
<weld::Toggleable
&, void> aLk(LINK(this, SwConvertTableDlg
, CheckHdl
));
203 m_xBtnBorder
->connect_toggled(aLk
);
204 m_xBtnFont
->connect_toggled(aLk
);
205 m_xBtnPattern
->connect_toggled(aLk
);
206 m_xBtnAlignment
->connect_toggled(aLk
);
207 m_xBtnNumFormat
->connect_toggled(aLk
);
209 m_xLbFormat
->connect_selection_changed(LINK(this, SwConvertTableDlg
, SelFormatHdl
));
211 // Then the list to be expanded by the entry "- none -".
212 m_xLbFormat
->append_text(SwViewShell::GetShellRes()->aStrNone
);
216 for (sal_uInt8 i
= 0, nCount
= static_cast<sal_uInt8
>(m_xTableTable
->size()); i
< nCount
; i
++)
218 SwTableAutoFormat
const& rFormat
= (*m_xTableTable
)[i
];
219 m_xLbFormat
->append_text(rFormat
.GetName());
220 if (pSelFormat
&& rFormat
.GetName() == pSelFormat
->GetName())
224 m_xLbFormat
->select(255 != m_nIndex
? (m_nDfltStylePos
+ m_nIndex
) : 0);
225 SelFormatHdl(*m_xLbFormat
);
228 void SwConvertTableDlg::UpdateChecks(const SwTableAutoFormat
& rFormat
, bool bEnable
)
230 m_xBtnNumFormat
->set_sensitive(bEnable
);
231 m_xBtnNumFormat
->set_active(rFormat
.IsValueFormat());
233 m_xBtnBorder
->set_sensitive(bEnable
);
234 m_xBtnBorder
->set_active(rFormat
.IsFrame());
236 m_xBtnFont
->set_sensitive(bEnable
);
237 m_xBtnFont
->set_active(rFormat
.IsFont());
239 m_xBtnPattern
->set_sensitive(bEnable
);
240 m_xBtnPattern
->set_active(rFormat
.IsBackground());
242 m_xBtnAlignment
->set_sensitive(bEnable
);
243 m_xBtnAlignment
->set_active(rFormat
.IsJustify());
246 std::unique_ptr
<SwTableAutoFormat
> SwConvertTableDlg::FillAutoFormatOfIndex() const
250 return std::make_unique
<SwTableAutoFormat
>((*m_xTableTable
)[m_nIndex
]);
256 IMPL_LINK(SwConvertTableDlg
, CheckHdl
, weld::Toggleable
&, rBtn
, void)
261 SwTableAutoFormat
& rData
= (*m_xTableTable
)[m_nIndex
];
262 bool bCheck
= rBtn
.get_active(), bDataChgd
= true;
264 if (&rBtn
== m_xBtnNumFormat
.get())
265 rData
.SetValueFormat(bCheck
);
266 else if (&rBtn
== m_xBtnBorder
.get())
267 rData
.SetFrame(bCheck
);
268 else if (&rBtn
== m_xBtnFont
.get())
269 rData
.SetFont(bCheck
);
270 else if (&rBtn
== m_xBtnPattern
.get())
271 rData
.SetBackground(bCheck
);
272 else if (&rBtn
== m_xBtnAlignment
.get())
273 rData
.SetJustify(bCheck
);
279 if (!m_bCoreDataChanged
)
281 m_bCoreDataChanged
= true;
284 m_aWndPreview
.NotifyChange(rData
);
285 mxTAutoFormat
= FillAutoFormatOfIndex();
289 IMPL_LINK_NOARG(SwConvertTableDlg
, SelFormatHdl
, weld::TreeView
&, void)
291 sal_uInt8 nOldIdx
= m_nIndex
;
292 int nSelPos
= m_xLbFormat
->get_selected_index();
293 if (nSelPos
>= m_nDfltStylePos
)
295 m_nIndex
= nSelPos
- m_nDfltStylePos
;
296 m_aWndPreview
.NotifyChange((*m_xTableTable
)[m_nIndex
]);
297 UpdateChecks((*m_xTableTable
)[m_nIndex
], true);
298 mxTAutoFormat
= FillAutoFormatOfIndex();
304 SwTableAutoFormat
aTmp(SwViewShell::GetShellRes()->aStrNone
);
306 aTmp
.SetJustify(false);
307 aTmp
.SetFrame(false);
308 aTmp
.SetBackground(false);
309 aTmp
.SetValueFormat(false);
310 aTmp
.SetWidthHeight(false);
312 if (nOldIdx
!= m_nIndex
)
313 m_aWndPreview
.NotifyChange(aTmp
);
314 UpdateChecks(aTmp
, false);
318 IMPL_LINK(SwConvertTableDlg
, BtnHdl
, weld::Toggleable
&, rButton
, void)
320 if (!rButton
.get_active())
322 if (m_xTabBtn
->get_active())
323 m_xKeepColumn
->set_state(m_xKeepColumn
->get_saved_state());
326 if (m_xKeepColumn
->get_sensitive())
327 m_xKeepColumn
->save_state();
328 m_xKeepColumn
->set_active(true);
330 m_xKeepColumn
->set_sensitive(m_xTabBtn
->get_active());
331 m_xOtherEd
->set_sensitive(m_xOtherBtn
->get_active());
334 IMPL_LINK_NOARG(SwConvertTableDlg
, CheckBoxHdl
, weld::Toggleable
&, void)
336 m_xRepeatHeaderCB
->set_sensitive(m_xHeaderCB
->get_active());
337 RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB
);
340 IMPL_LINK_NOARG(SwConvertTableDlg
, RepeatHeaderCheckBoxHdl
, weld::Toggleable
&, void)
342 bool bEnable
= m_xHeaderCB
->get_active() && m_xRepeatHeaderCB
->get_active();
343 m_xRepeatRows
->set_sensitive(bEnable
);
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */