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 #define ROW_COL_PROD 16384
29 
30 void SwInsTableDlg::GetValues( OUString& rName, sal_uInt16& rRow, sal_uInt16& rCol,
31  SwInsertTableOptions& rInsTableOpts, OUString& rAutoName,
32  std::unique_ptr<SwTableAutoFormat>& prTAFormat )
33 {
35  rName = m_xNameEdit->get_text();
36  rRow = m_xRowNF->get_value();
37  rCol = m_xColNF->get_value();
38 
39  if (m_xHeaderCB->get_active())
40  nInsMode |= SwInsertTableFlags::Headline;
41  if (m_xRepeatHeaderCB->get_sensitive() && m_xRepeatHeaderCB->get_active())
42  rInsTableOpts.mnRowsToRepeat = m_xRepeatHeaderNF->get_value();
43  else
44  rInsTableOpts.mnRowsToRepeat = 0;
45  if (!m_xDontSplitCB->get_active())
47  if( pTAutoFormat )
48  {
49  prTAFormat.reset(new SwTableAutoFormat( *pTAutoFormat ));
50  rAutoName = prTAFormat->GetName();
51  }
52 
53  rInsTableOpts.mnInsMode = nInsMode;
54 }
55 
56 IMPL_LINK(SwInsTableDlg, TextFilterHdl, OUString&, rTest, bool)
57 {
58  rTest = m_aTextFilter.filter(rTest);
59  return true;
60 }
61 
63  : SfxDialogController(rView.GetFrameWeld(), "modules/swriter/ui/inserttable.ui", "InsertTableDialog")
64  , m_aTextFilter(" .<>")
65  , pShell(&rView.GetWrtShell())
66  , pTAutoFormat(nullptr)
67  , nEnteredValRepeatHeaderNF(-1)
68  , m_xNameEdit(m_xBuilder->weld_entry("nameedit"))
69  , m_xColNF(m_xBuilder->weld_spin_button("colspin"))
70  , m_xRowNF(m_xBuilder->weld_spin_button("rowspin"))
71  , m_xHeaderCB(m_xBuilder->weld_check_button("headercb"))
72  , m_xRepeatHeaderCB(m_xBuilder->weld_check_button("repeatcb"))
73  , m_xRepeatHeaderNF(m_xBuilder->weld_spin_button("repeatheaderspin"))
74  , m_xRepeatGroup(m_xBuilder->weld_widget("repeatgroup"))
75  , m_xDontSplitCB(m_xBuilder->weld_check_button("dontsplitcb"))
76  , m_xInsertBtn(m_xBuilder->weld_button("ok"))
77  , m_xLbFormat(m_xBuilder->weld_tree_view("formatlbinstable"))
78  , m_xWndPreview(new weld::CustomWeld(*m_xBuilder, "previewinstable", m_aWndPreview))
79  , m_xStyleFrame(m_xBuilder->weld_frame("stylesframe"))
80 {
82  m_xStyleFrame->hide();
83 
84  const int nWidth = m_xLbFormat->get_approximate_digit_width() * 32;
85  const int nHeight = m_xLbFormat->get_height_rows(8);
86  m_xLbFormat->set_size_request(nWidth, nHeight);
87  m_xWndPreview->set_size_request(nWidth, nHeight);
88 
89  m_xNameEdit->connect_insert_text(LINK(this, SwInsTableDlg, TextFilterHdl));
91  m_xNameEdit->connect_changed(LINK(this, SwInsTableDlg, ModifyName));
92  m_xColNF->connect_value_changed(LINK(this, SwInsTableDlg, ModifyRowCol));
93  m_xRowNF->connect_value_changed(LINK(this, SwInsTableDlg, ModifyRowCol));
94 
95  m_xRowNF->set_max(ROW_COL_PROD/m_xColNF->get_value());
96  m_xColNF->set_max(ROW_COL_PROD/m_xRowNF->get_value());
97 
98  m_xInsertBtn->connect_clicked(LINK(this, SwInsTableDlg, OKHdl));
99 
100  bool bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell())&HTMLMODE_ON);
101  const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
102 
103  SwInsertTableOptions aInsOpts = pModOpt->GetInsTableFlags(bHTMLMode);
104  SwInsertTableFlags nInsTableFlags = aInsOpts.mnInsMode;
105 
106  m_xHeaderCB->set_active(bool(nInsTableFlags & SwInsertTableFlags::Headline));
107  m_xRepeatHeaderCB->set_active(aInsOpts.mnRowsToRepeat > 0);
108  if (bHTMLMode)
109  m_xDontSplitCB->hide();
110  else
111  m_xDontSplitCB->set_active(!(nInsTableFlags & SwInsertTableFlags::SplitLayout));
112 
113  m_xRepeatHeaderNF->connect_value_changed( LINK( this, SwInsTableDlg, ModifyRepeatHeaderNF_Hdl ) );
114  m_xHeaderCB->connect_toggled( LINK( this, SwInsTableDlg, CheckBoxHdl ) );
115  m_xRepeatHeaderCB->connect_toggled( LINK( this, SwInsTableDlg, RepeatHeaderCheckBoxHdl ) );
116  RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
117  CheckBoxHdl(*m_xHeaderCB);
118 
119  sal_Int64 nMax = m_xRowNF->get_value();
120  if( nMax <= 1 )
121  nMax = 1;
122  else
123  --nMax;
124  m_xRepeatHeaderNF->set_max( nMax );
125 
127 }
128 
130 {
132 
133  m_xLbFormat->connect_changed(LINK(this, SwInsTableDlg, SelFormatHdl));
134 
136  pTableTable->Load();
137 
138  // Add "- none -" style autoformat table.
139  m_xLbFormat->append_text(SwViewShell::GetShellRes()->aStrNone); // Insert to listbox
140 
141  // Add other styles of autoformat tables.
142  for (sal_uInt8 i = 0, nCount = static_cast<sal_uInt8>(pTableTable->size());
143  i < nCount; i++)
144  {
145  SwTableAutoFormat const& rFormat = (*pTableTable)[ i ];
146  m_xLbFormat->append_text(rFormat.GetName());
147  if (pTAutoFormat && rFormat.GetName() == pTAutoFormat->GetName())
148  lbIndex = i;
149  }
150 
151  // Change this min variable if you add autotable manually.
152  minTableIndexInLb = 1;
154  lbIndex = 0;
155  m_xLbFormat->select( lbIndex );
156  tbIndex = lbIndexToTableIndex(lbIndex);
157 
158  SelFormatHdl( *m_xLbFormat );
159 }
160 
162 {
164  minTableIndexInLb <= listboxIndex &&
165  listboxIndex < maxTableIndexInLb )
166  {
167  return listboxIndex - minTableIndexInLb;
168  }
169 
170  return 255;
171 }
172 
173 static void lcl_SetProperties( SwTableAutoFormat* pTableAutoFormat, bool bVal )
174 {
175  pTableAutoFormat->SetFont( bVal );
176  pTableAutoFormat->SetJustify( bVal );
177  pTableAutoFormat->SetFrame( bVal );
178  pTableAutoFormat->SetBackground( bVal );
179  pTableAutoFormat->SetValueFormat( bVal );
180  pTableAutoFormat->SetWidthHeight( bVal );
181 }
182 
184 {
185  // Get index of selected item from the listbox
186  lbIndex = static_cast<sal_uInt8>(m_xLbFormat->get_selected_index());
187  tbIndex = lbIndexToTableIndex( lbIndex );
188 
189  // To understand this index mapping, look InitAutoTableFormat function to
190  // see how listbox item is implemented.
191  if( tbIndex < 255 )
192  m_aWndPreview.NotifyChange( (*pTableTable)[tbIndex] );
193  else
194  {
195  SwTableAutoFormat aTmp( SwViewShell::GetShellRes()->aStrNone );
196  lcl_SetProperties( &aTmp, false );
197 
198  m_aWndPreview.NotifyChange( aTmp );
199  }
200 }
201 
203 {
204  if( tbIndex < 255 )
205  pShell->SetTableStyle((*pTableTable)[tbIndex]);
206 
207  if( tbIndex < 255 )
208  {
209  if( pTAutoFormat )
210  *pTAutoFormat = (*pTableTable)[ tbIndex ];
211  else
212  pTAutoFormat = new SwTableAutoFormat( (*pTableTable)[ tbIndex ] );
213  }
214  else
215  {
216  delete pTAutoFormat;
217  pTAutoFormat = new SwTableAutoFormat( SwViewShell::GetShellRes()->aStrNone );
218  lcl_SetProperties( pTAutoFormat, false );
219  }
220 
221  m_xDialog->response(RET_OK);
222 }
223 
224 IMPL_LINK( SwInsTableDlg, ModifyName, weld::Entry&, rEdit, void )
225 {
226  OUString sTableName = rEdit.get_text();
227  m_xInsertBtn->set_sensitive(pShell->GetTableStyle(sTableName) == nullptr);
228 }
229 
230 IMPL_LINK( SwInsTableDlg, ModifyRowCol, weld::SpinButton&, rEdit, void )
231 {
232  if(&rEdit == m_xColNF.get())
233  {
234  sal_Int64 nCol = m_xColNF->get_value();
235  if(!nCol)
236  nCol = 1;
237  m_xRowNF->set_max(ROW_COL_PROD/nCol);
238  }
239  else
240  {
241  sal_Int64 nRow = m_xRowNF->get_value();
242  if(!nRow)
243  nRow = 1;
244  m_xColNF->set_max(ROW_COL_PROD/nRow);
245 
246  // adjust depending NF for repeated rows
247  sal_Int64 nMax = ( nRow == 1 )? 1 : nRow - 1 ;
248  sal_Int64 nActVal = m_xRepeatHeaderNF->get_value();
249 
250  m_xRepeatHeaderNF->set_max( nMax );
251 
252  if( nActVal > nMax )
253  m_xRepeatHeaderNF->set_value( nMax );
254  else if( nActVal < nEnteredValRepeatHeaderNF )
255  m_xRepeatHeaderNF->set_value(std::min(nEnteredValRepeatHeaderNF, nMax));
256  }
257 }
258 
260 {
261  m_xRepeatHeaderCB->set_sensitive(m_xHeaderCB->get_active());
262  RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
263 }
264 
265 IMPL_LINK_NOARG(SwInsTableDlg, RepeatHeaderCheckBoxHdl, weld::ToggleButton&, void)
266 {
267  m_xRepeatGroup->set_sensitive(m_xHeaderCB->get_active() && m_xRepeatHeaderCB->get_active());
268 }
269 
270 IMPL_LINK_NOARG(SwInsTableDlg, ModifyRepeatHeaderNF_Hdl, weld::SpinButton&, void)
271 {
272  nEnteredValRepeatHeaderNF = m_xRepeatHeaderNF->get_value();
273 }
274 
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 lbIndexToTableIndex(const sal_uInt8 listboxIndex)
Definition: instable.cxx:161
void SetValueFormat(const bool bNew)
Definition: tblafmt.hxx:234
std::unique_ptr< weld::SpinButton > m_xColNF
Definition: instable.hxx:51
sal_uInt8 minTableIndexInLb
Definition: instable.hxx:44
static ShellResource * GetShellRes()
Definition: viewsh.cxx:2485
std::unique_ptr< weld::Entry > m_xNameEdit
Definition: instable.hxx:50
SwWrtShell * pShell
Definition: instable.hxx:38
void SetFrame(const bool bNew)
Definition: tblafmt.hxx:232
SwInsertTableFlags mnInsMode
Definition: itabenum.hxx:40
static void lcl_SetProperties(SwTableAutoFormat *pTableAutoFormat, bool bVal)
Definition: instable.cxx:173
sal_uInt16 mnRowsToRepeat
Definition: itabenum.hxx:41
SwInsertTableFlags
Definition: itabenum.hxx:25
void InitAutoTableFormat()
Definition: instable.cxx:129
void DetectRTL(SwWrtShell const *pWrtShell)
void SetFont(const bool bNew)
Definition: tblafmt.hxx:230
int nCount
std::unique_ptr< weld::CheckButton > m_xRepeatHeaderCB
Definition: instable.hxx:54
void SetJustify(const bool bNew)
Definition: tblafmt.hxx:231
std::unique_ptr< weld::SpinButton > m_xRowNF
Definition: instable.hxx:52
std::unique_ptr< weld::TreeView > m_xLbFormat
Definition: instable.hxx:59
AutoFormatPreview m_aWndPreview
Definition: instable.hxx:48
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
#define SW_MOD()
Definition: swmodule.hxx:255
std::unique_ptr< weld::SpinButton > m_xRepeatHeaderNF
Definition: instable.hxx:55
int i
IMPL_LINK_NOARG(SwInsTableDlg, SelFormatHdl, weld::TreeView &, void)
Definition: instable.cxx:183
HTMLMODE_ON
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:337
size_t size() const
Definition: tblafmt.cxx:930
OUString GetUniqueTableName() const
Definition: edfmt.cxx:111
SwTableAutoFormatTable * pTableTable
Definition: instable.hxx:39
void SetWidthHeight(const bool bNew)
Definition: tblafmt.hxx:235
void SetBackground(const bool bNew)
Definition: tblafmt.hxx:233
std::unique_ptr< weld::CheckButton > m_xHeaderCB
Definition: instable.hxx:53
IMPL_LINK(SwInsTableDlg, TextFilterHdl, OUString &, rTest, bool)
Definition: instable.cxx:56
#define ROW_COL_PROD
Definition: instable.cxx:28
SwDocShell * GetDocShell()
Definition: view.cxx:1108
virtual OUString get_text() const =0
std::unique_ptr< weld::CustomWeld > m_xWndPreview
Definition: instable.hxx:60
sal_uInt8 maxTableIndexInLb
Definition: instable.hxx:45
const OUString & GetName() const
Definition: tblafmt.hxx:208
weld::Entry & rEdit
SwInsTableDlg(SwView &rView)
Definition: instable.cxx:62
SwTableAutoFormat * pTAutoFormat
Definition: instable.hxx:40
unsigned char sal_uInt8
RET_OK
Reference< XExecutableDialog > m_xDialog
std::unique_ptr< weld::CheckButton > m_xDontSplitCB
Definition: instable.hxx:57
std::unique_ptr< weld::Button > m_xInsertBtn
Definition: instable.hxx:58
std::unique_ptr< weld::Frame > m_xStyleFrame
Definition: instable.hxx:61
const SwInsertTableOptions & GetInsTableFlags(bool bHTML) const
Definition: modcfg.hxx:303
sal_uInt8 tbIndex
Definition: instable.hxx:43
sal_uInt8 lbIndex
Definition: instable.hxx:42
Definition: view.hxx:144
void GetValues(OUString &rName, sal_uInt16 &rRow, sal_uInt16 &rCol, SwInsertTableOptions &rInsTableOpts, OUString &rTableAutoFormatName, std::unique_ptr< SwTableAutoFormat > &prTAFormat)
Definition: instable.cxx:30
SAL_DLLPRIVATE bool Load(SvStream &rStream)
Definition: tblafmt.cxx:1061