LibreOffice Module sw (master) 1
instable.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 <instable.hxx>
21#include <shellres.hxx>
22#include <modcfg.hxx>
23#include <swmodule.hxx>
24#include <sfx2/htmlmode.hxx>
25#include <viewopt.hxx>
26#include <comphelper/lok.hxx>
27
28
29void SwInsTableDlg::GetValues( OUString& rName, sal_uInt16& rRow, sal_uInt16& rCol,
30 SwInsertTableOptions& rInsTableOpts, OUString& rAutoName,
31 std::unique_ptr<SwTableAutoFormat>& prTAFormat )
32{
34 rName = m_xNameEdit->get_text();
35 rRow = m_xRowSpinButton->get_value();
36 rCol = m_xColSpinButton->get_value();
37
38 if (m_xHeaderCB->get_active())
40 if (m_xRepeatHeaderCB->get_sensitive() && m_xRepeatHeaderCB->get_active())
41 rInsTableOpts.mnRowsToRepeat = m_xRepeatHeaderNF->get_value();
42 else
43 rInsTableOpts.mnRowsToRepeat = 0;
44 if (!m_xDontSplitCB->get_active())
46 if( m_xTAutoFormat )
47 {
48 prTAFormat.reset(new SwTableAutoFormat( *m_xTAutoFormat ));
49 rAutoName = prTAFormat->GetName();
50 }
51
52 rInsTableOpts.mnInsMode = nInsMode;
53}
54
55IMPL_LINK(SwInsTableDlg, TextFilterHdl, OUString&, rTest, bool)
56{
57 rTest = m_aTextFilter.filter(rTest);
58 return true;
59}
60
62 : SfxDialogController(rView.GetFrameWeld(), "modules/swriter/ui/inserttable.ui", "InsertTableDialog")
63 , m_aTextFilter(" .<>")
64 , m_pShell(&rView.GetWrtShell())
65 , m_nEnteredValRepeatHeaderNF(-1)
66 , m_xNameEdit(m_xBuilder->weld_entry("nameedit"))
67 , m_xWarning(m_xBuilder->weld_label("lbwarning"))
68 , m_xColSpinButton(m_xBuilder->weld_spin_button("colspin"))
69 , m_xRowSpinButton(m_xBuilder->weld_spin_button("rowspin"))
70 , m_xHeaderCB(m_xBuilder->weld_check_button("headercb"))
71 , m_xRepeatHeaderCB(m_xBuilder->weld_check_button("repeatcb"))
72 , m_xRepeatHeaderNF(m_xBuilder->weld_spin_button("repeatheaderspin"))
73 , m_xRepeatGroup(m_xBuilder->weld_widget("repeatgroup"))
74 , m_xDontSplitCB(m_xBuilder->weld_check_button("dontsplitcb"))
75 , m_xInsertBtn(m_xBuilder->weld_button("ok"))
76 , m_xLbFormat(m_xBuilder->weld_tree_view("formatlbinstable"))
77 , m_xWndPreview(new weld::CustomWeld(*m_xBuilder, "previewinstable", m_aWndPreview))
78 , m_xStyleFrame(m_xBuilder->weld_frame("stylesframe"))
79{
81 m_xStyleFrame->hide();
82
83 const int nWidth = m_xLbFormat->get_approximate_digit_width() * 32;
84 const int nHeight = m_xLbFormat->get_height_rows(8);
85 m_xLbFormat->set_size_request(nWidth, nHeight);
86 m_xWndPreview->set_size_request(nWidth, nHeight);
87
88 m_xNameEdit->connect_insert_text(LINK(this, SwInsTableDlg, TextFilterHdl));
90 m_xNameEdit->connect_changed(LINK(this, SwInsTableDlg, ModifyName));
91 m_xRowSpinButton->connect_changed(LINK(this, SwInsTableDlg, ModifyRowCol));
92 m_xColSpinButton->connect_changed(LINK(this, SwInsTableDlg, ModifyRowCol));
93
94 m_xInsertBtn->connect_clicked(LINK(this, SwInsTableDlg, OKHdl));
95
96 bool bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell())&HTMLMODE_ON);
97 const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
98
99 SwInsertTableOptions aInsOpts = pModOpt->GetInsTableFlags(bHTMLMode);
100 SwInsertTableFlags nInsTableFlags = aInsOpts.mnInsMode;
101
102 m_xHeaderCB->set_active(bool(nInsTableFlags & SwInsertTableFlags::Headline));
103 m_xRepeatHeaderCB->set_active(aInsOpts.mnRowsToRepeat > 0);
104 if (bHTMLMode)
105 m_xDontSplitCB->hide();
106 else
107 m_xDontSplitCB->set_active(!(nInsTableFlags & SwInsertTableFlags::SplitLayout));
108
109 m_xRepeatHeaderNF->connect_value_changed( LINK( this, SwInsTableDlg, ModifyRepeatHeaderNF_Hdl ) );
110 m_xHeaderCB->connect_toggled( LINK( this, SwInsTableDlg, CheckBoxHdl ) );
111 m_xRepeatHeaderCB->connect_toggled( LINK( this, SwInsTableDlg, RepeatHeaderCheckBoxHdl ) );
112 RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
113 CheckBoxHdl(*m_xHeaderCB);
114
115 sal_Int64 nMax = m_xRowSpinButton->get_value();
116 if( nMax <= 1 )
117 nMax = 1;
118 else
119 --nMax;
120 m_xRepeatHeaderNF->set_max( nMax );
121
123 m_xWarning->set_label_type(weld::LabelType::Warning);
124}
125
127{
129
130 m_xLbFormat->connect_changed(LINK(this, SwInsTableDlg, SelFormatHdl));
131
133 m_xTableTable->Load();
134
135 // Add "- none -" style autoformat table.
136 m_xLbFormat->append_text(SwViewShell::GetShellRes()->aStrNone); // Insert to listbox
137
138 // Add other styles of autoformat tables.
139 for (sal_uInt8 i = 0, nCount = static_cast<sal_uInt8>(m_xTableTable->size());
140 i < nCount; i++)
141 {
142 SwTableAutoFormat const& rFormat = (*m_xTableTable)[ i ];
143 m_xLbFormat->append_text(rFormat.GetName());
144 if (m_xTAutoFormat && rFormat.GetName() == m_xTAutoFormat->GetName())
145 m_lbIndex = i;
146 }
147
148 // Change this min variable if you add autotable manually.
151 // 1 means default table style
152 // unfortunately when the table has a style sw/qa/uitest/writer_tests4/tdf115573.py fails
153 // because tables that have pre-applied style resets the style of the elements in their cells
154 // when a new row is inserted and the ui test above relies on that. For now this is LOK only
156 m_xLbFormat->select(m_lbIndex);
158
159 SelFormatHdl( *m_xLbFormat );
160}
161
163{
165 minTableIndexInLb <= listboxIndex &&
166 listboxIndex < maxTableIndexInLb )
167 {
168 return listboxIndex - minTableIndexInLb;
169 }
170
171 return 255;
172}
173
174static void lcl_SetProperties( SwTableAutoFormat* pTableAutoFormat, bool bVal )
175{
176 pTableAutoFormat->SetFont( bVal );
177 pTableAutoFormat->SetJustify( bVal );
178 pTableAutoFormat->SetFrame( bVal );
179 pTableAutoFormat->SetBackground( bVal );
180 pTableAutoFormat->SetValueFormat( bVal );
181 pTableAutoFormat->SetWidthHeight( bVal );
182}
183
185{
186 // Get index of selected item from the listbox
187 m_lbIndex = static_cast<sal_uInt8>(m_xLbFormat->get_selected_index());
188 m_tbIndex = lbIndexToTableIndex( m_lbIndex );
189
190 // To understand this index mapping, look InitAutoTableFormat function to
191 // see how listbox item is implemented.
192 if( m_tbIndex < 255 )
193 m_aWndPreview.NotifyChange( (*m_xTableTable)[m_tbIndex] );
194 else
195 {
197 lcl_SetProperties( &aTmp, false );
198
199 m_aWndPreview.NotifyChange( aTmp );
200 }
201}
202
204{
205 if( m_tbIndex < 255 )
206 m_pShell->SetTableStyle((*m_xTableTable)[m_tbIndex]);
207
208 if( m_tbIndex < 255 )
209 {
210 if( m_xTAutoFormat )
211 *m_xTAutoFormat = (*m_xTableTable)[ m_tbIndex ];
212 else
213 m_xTAutoFormat.reset(new SwTableAutoFormat( (*m_xTableTable)[ m_tbIndex ] ));
214 }
215 else
216 {
217 m_xTAutoFormat.reset(new SwTableAutoFormat( SwViewShell::GetShellRes()->aStrNone ));
218 lcl_SetProperties( m_xTAutoFormat.get(), false );
219 }
220
221 m_xDialog->response(RET_OK);
222}
223
224IMPL_LINK( SwInsTableDlg, ModifyName, weld::Entry&, rEdit, void )
225{
226 OUString sTableName = rEdit.get_text();
227 m_xInsertBtn->set_sensitive(m_pShell->GetTableStyle(sTableName) == nullptr);
228}
229
230// We use weld::Entry's "changed" notification here, not weld::SpinButton's "value_changed", because
231// the latter only fires after the control looses focus; so the notification would not fire during
232// typing a big number, so that user typing it and immediately clicking "Insert" would not see the
233// warning.
234// Since the notification is called in weld::Entry context, we can only rely on what's available for
235// used weld::Entry's notification; specifically, we have to call spin buttons' get_text() instead
236// of get_value(), because the latter is not guaranteed to return an up-to-date value at this point
237// (depends on vcl plugin used).
238IMPL_LINK( SwInsTableDlg, ModifyRowCol, weld::Entry&, rEdit, void )
239{
240 sal_Int64 nRow = m_xRowSpinButton->get_text().toInt64();
241 sal_Int64 nCol = m_xColSpinButton->get_text().toInt64();
242 if (nRow > 255)
243 {
244 m_xRowSpinButton->set_message_type(weld::EntryMessageType::Warning);
245 m_xWarning->set_visible(true);
246 }
247 else
248 {
249 m_xRowSpinButton->set_message_type(weld::EntryMessageType::Normal);
250 }
251 if (nCol > 63)
252 {
253 m_xColSpinButton->set_message_type(weld::EntryMessageType::Warning);
254 m_xWarning->set_visible(true);
255 }
256 else
257 {
258 m_xColSpinButton->set_message_type(weld::EntryMessageType::Normal);
259 }
260 if (nRow <= 255 && nCol <= 63)
261 {
262 m_xWarning->set_visible(false);
263 }
264 if (&rEdit == m_xColSpinButton.get())
265 return;
266
267 if(!nRow)
268 nRow = 1;
269
270 // adjust depending NF for repeated rows
271 sal_Int64 nMax = ( nRow == 1 )? 1 : nRow - 1 ;
272 sal_Int64 nActVal = m_xRepeatHeaderNF->get_value();
273
274 m_xRepeatHeaderNF->set_max( nMax );
275
276 if( nActVal > nMax )
277 m_xRepeatHeaderNF->set_value( nMax );
278 else if( nActVal < m_nEnteredValRepeatHeaderNF )
279 m_xRepeatHeaderNF->set_value(std::min(m_nEnteredValRepeatHeaderNF, nMax));
280}
281
283{
284 m_xRepeatHeaderCB->set_sensitive(m_xHeaderCB->get_active());
285 RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
286}
287
288IMPL_LINK_NOARG(SwInsTableDlg, RepeatHeaderCheckBoxHdl, weld::Toggleable&, void)
289{
290 m_xRepeatGroup->set_sensitive(m_xHeaderCB->get_active() && m_xRepeatHeaderCB->get_active());
291}
292
293IMPL_LINK_NOARG(SwInsTableDlg, ModifyRepeatHeaderNF_Hdl, weld::SpinButton&, void)
294{
295 m_nEnteredValRepeatHeaderNF = m_xRepeatHeaderNF->get_value();
296}
297
298/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
void DetectRTL(SwWrtShell const *pWrtShell)
OUString GetUniqueTableName() const
Definition: edfmt.cxx:109
std::unique_ptr< weld::SpinButton > m_xRowSpinButton
Definition: instable.hxx:54
sal_uInt8 minTableIndexInLb
Definition: instable.hxx:45
std::unique_ptr< weld::Entry > m_xNameEdit
Definition: instable.hxx:51
std::unique_ptr< weld::Label > m_xWarning
Definition: instable.hxx:52
std::unique_ptr< weld::SpinButton > m_xColSpinButton
Definition: instable.hxx:53
sal_uInt8 m_tbIndex
Definition: instable.hxx:44
std::unique_ptr< weld::CheckButton > m_xDontSplitCB
Definition: instable.hxx:59
std::unique_ptr< weld::CustomWeld > m_xWndPreview
Definition: instable.hxx:62
std::unique_ptr< weld::CheckButton > m_xHeaderCB
Definition: instable.hxx:55
SwInsTableDlg(SwView &rView)
Definition: instable.cxx:61
std::unique_ptr< weld::Button > m_xInsertBtn
Definition: instable.hxx:60
std::unique_ptr< weld::SpinButton > m_xRepeatHeaderNF
Definition: instable.hxx:57
std::unique_ptr< SwTableAutoFormat > m_xTAutoFormat
Definition: instable.hxx:41
std::unique_ptr< weld::Frame > m_xStyleFrame
Definition: instable.hxx:63
sal_uInt8 maxTableIndexInLb
Definition: instable.hxx:46
AutoFormatPreview m_aWndPreview
Definition: instable.hxx:49
std::unique_ptr< SwTableAutoFormatTable > m_xTableTable
Definition: instable.hxx:40
void InitAutoTableFormat()
Definition: instable.cxx:126
SwWrtShell * m_pShell
Definition: instable.hxx:39
std::unique_ptr< weld::CheckButton > m_xRepeatHeaderCB
Definition: instable.hxx:56
sal_uInt8 lbIndexToTableIndex(const sal_uInt8 listboxIndex)
Definition: instable.cxx:162
void GetValues(OUString &rName, sal_uInt16 &rRow, sal_uInt16 &rCol, SwInsertTableOptions &rInsTableOpts, OUString &rTableAutoFormatName, std::unique_ptr< SwTableAutoFormat > &prTAFormat)
Definition: instable.cxx:29
std::unique_ptr< weld::TreeView > m_xLbFormat
Definition: instable.hxx:61
sal_uInt8 m_lbIndex
Definition: instable.hxx:43
const SwInsertTableOptions & GetInsTableFlags(bool bHTML) const
Definition: modcfg.hxx:303
void SetBackground(const bool bNew)
Definition: tblafmt.hxx:231
void SetWidthHeight(const bool bNew)
Definition: tblafmt.hxx:233
void SetFrame(const bool bNew)
Definition: tblafmt.hxx:230
void SetValueFormat(const bool bNew)
Definition: tblafmt.hxx:232
const OUString & GetName() const
Definition: tblafmt.hxx:206
void SetJustify(const bool bNew)
Definition: tblafmt.hxx:229
void SetFont(const bool bNew)
Definition: tblafmt.hxx:228
static ShellResource * GetShellRes()
Definition: viewsh.cxx:2664
Definition: view.hxx:146
SwDocShell * GetDocShell()
Definition: view.cxx:1193
int nCount
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
HTMLMODE_ON
Shell * m_pShell
IMPL_LINK(SwInsTableDlg, TextFilterHdl, OUString &, rTest, bool)
Definition: instable.cxx:55
IMPL_LINK_NOARG(SwInsTableDlg, SelFormatHdl, weld::TreeView &, void)
Definition: instable.cxx:184
static void lcl_SetProperties(SwTableAutoFormat *pTableAutoFormat, bool bVal)
Definition: instable.cxx:174
SwInsertTableFlags
Definition: itabenum.hxx:26
int i
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
sal_uInt16 mnRowsToRepeat
Definition: itabenum.hxx:41
SwInsertTableFlags mnInsMode
Definition: itabenum.hxx:40
#define SW_MOD()
Definition: swmodule.hxx:254
unsigned char sal_uInt8
RET_OK
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:415