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 m_lbIndex = 0;
152 m_xLbFormat->select( m_lbIndex );
154
155 SelFormatHdl( *m_xLbFormat );
156}
157
159{
161 minTableIndexInLb <= listboxIndex &&
162 listboxIndex < maxTableIndexInLb )
163 {
164 return listboxIndex - minTableIndexInLb;
165 }
166
167 return 255;
168}
169
170static void lcl_SetProperties( SwTableAutoFormat* pTableAutoFormat, bool bVal )
171{
172 pTableAutoFormat->SetFont( bVal );
173 pTableAutoFormat->SetJustify( bVal );
174 pTableAutoFormat->SetFrame( bVal );
175 pTableAutoFormat->SetBackground( bVal );
176 pTableAutoFormat->SetValueFormat( bVal );
177 pTableAutoFormat->SetWidthHeight( bVal );
178}
179
181{
182 // Get index of selected item from the listbox
183 m_lbIndex = static_cast<sal_uInt8>(m_xLbFormat->get_selected_index());
184 m_tbIndex = lbIndexToTableIndex( m_lbIndex );
185
186 // To understand this index mapping, look InitAutoTableFormat function to
187 // see how listbox item is implemented.
188 if( m_tbIndex < 255 )
189 m_aWndPreview.NotifyChange( (*m_xTableTable)[m_tbIndex] );
190 else
191 {
193 lcl_SetProperties( &aTmp, false );
194
195 m_aWndPreview.NotifyChange( aTmp );
196 }
197}
198
200{
201 if( m_tbIndex < 255 )
202 m_pShell->SetTableStyle((*m_xTableTable)[m_tbIndex]);
203
204 if( m_tbIndex < 255 )
205 {
206 if( m_xTAutoFormat )
207 *m_xTAutoFormat = (*m_xTableTable)[ m_tbIndex ];
208 else
209 m_xTAutoFormat.reset(new SwTableAutoFormat( (*m_xTableTable)[ m_tbIndex ] ));
210 }
211 else
212 {
213 m_xTAutoFormat.reset(new SwTableAutoFormat( SwViewShell::GetShellRes()->aStrNone ));
214 lcl_SetProperties( m_xTAutoFormat.get(), false );
215 }
216
217 m_xDialog->response(RET_OK);
218}
219
220IMPL_LINK( SwInsTableDlg, ModifyName, weld::Entry&, rEdit, void )
221{
222 OUString sTableName = rEdit.get_text();
223 m_xInsertBtn->set_sensitive(m_pShell->GetTableStyle(sTableName) == nullptr);
224}
225
226// We use weld::Entry's "changed" notification here, not weld::SpinButton's "value_changed", because
227// the latter only fires after the control looses focus; so the notification would not fire during
228// typing a big number, so that user typing it and immediately clicking "Insert" would not see the
229// warning.
230// Since the notification is called in weld::Entry context, we can only rely on what's available for
231// used weld::Entry's notification; specifically, we have to call spin buttons' get_text() instead
232// of get_value(), because the latter is not guaranteed to return an up-to-date value at this point
233// (depends on vcl plugin used).
234IMPL_LINK( SwInsTableDlg, ModifyRowCol, weld::Entry&, rEdit, void )
235{
236 sal_Int64 nRow = m_xRowSpinButton->get_text().toInt64();
237 sal_Int64 nCol = m_xColSpinButton->get_text().toInt64();
238 if (nRow > 255)
239 {
240 m_xRowSpinButton->set_message_type(weld::EntryMessageType::Warning);
241 m_xWarning->set_visible(true);
242 }
243 else
244 {
245 m_xRowSpinButton->set_message_type(weld::EntryMessageType::Normal);
246 }
247 if (nCol > 63)
248 {
249 m_xColSpinButton->set_message_type(weld::EntryMessageType::Warning);
250 m_xWarning->set_visible(true);
251 }
252 else
253 {
254 m_xColSpinButton->set_message_type(weld::EntryMessageType::Normal);
255 }
256 if (nRow <= 255 && nCol <= 63)
257 {
258 m_xWarning->set_visible(false);
259 }
260 if (&rEdit == m_xColSpinButton.get())
261 return;
262
263 if(!nRow)
264 nRow = 1;
265
266 // adjust depending NF for repeated rows
267 sal_Int64 nMax = ( nRow == 1 )? 1 : nRow - 1 ;
268 sal_Int64 nActVal = m_xRepeatHeaderNF->get_value();
269
270 m_xRepeatHeaderNF->set_max( nMax );
271
272 if( nActVal > nMax )
273 m_xRepeatHeaderNF->set_value( nMax );
274 else if( nActVal < m_nEnteredValRepeatHeaderNF )
275 m_xRepeatHeaderNF->set_value(std::min(m_nEnteredValRepeatHeaderNF, nMax));
276}
277
279{
280 m_xRepeatHeaderCB->set_sensitive(m_xHeaderCB->get_active());
281 RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
282}
283
284IMPL_LINK_NOARG(SwInsTableDlg, RepeatHeaderCheckBoxHdl, weld::Toggleable&, void)
285{
286 m_xRepeatGroup->set_sensitive(m_xHeaderCB->get_active() && m_xRepeatHeaderCB->get_active());
287}
288
289IMPL_LINK_NOARG(SwInsTableDlg, ModifyRepeatHeaderNF_Hdl, weld::SpinButton&, void)
290{
291 m_nEnteredValRepeatHeaderNF = m_xRepeatHeaderNF->get_value();
292}
293
294/* 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:158
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:227
void SetWidthHeight(const bool bNew)
Definition: tblafmt.hxx:229
void SetFrame(const bool bNew)
Definition: tblafmt.hxx:226
void SetValueFormat(const bool bNew)
Definition: tblafmt.hxx:228
const OUString & GetName() const
Definition: tblafmt.hxx:202
void SetJustify(const bool bNew)
Definition: tblafmt.hxx:225
void SetFont(const bool bNew)
Definition: tblafmt.hxx:224
static ShellResource * GetShellRes()
Definition: viewsh.cxx:2650
Definition: view.hxx:146
SwDocShell * GetDocShell()
Definition: view.cxx:1160
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:180
static void lcl_SetProperties(SwTableAutoFormat *pTableAutoFormat, bool bVal)
Definition: instable.cxx:170
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:256
unsigned char sal_uInt8
RET_OK
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:332