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 
27 #define ROW_COL_PROD 16384
28 
29 void 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_xRowNF->get_value();
36  rCol = m_xColNF->get_value();
37 
38  if (m_xHeaderCB->get_active())
39  nInsMode |= SwInsertTableFlags::Headline;
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( pTAutoFormat )
47  {
48  prTAFormat.reset(new SwTableAutoFormat( *pTAutoFormat ));
49  rAutoName = prTAFormat->GetName();
50  }
51 
52  rInsTableOpts.mnInsMode = nInsMode;
53 }
54 
55 IMPL_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  , pShell(&rView.GetWrtShell())
65  , pTAutoFormat(nullptr)
66  , nEnteredValRepeatHeaderNF(-1)
67  , m_xNameEdit(m_xBuilder->weld_entry("nameedit"))
68  , m_xColNF(m_xBuilder->weld_spin_button("colspin"))
69  , m_xRowNF(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 {
79  const int nWidth = m_xLbFormat->get_approximate_digit_width() * 32;
80  const int nHeight = m_xLbFormat->get_height_rows(8);
81  m_xLbFormat->set_size_request(nWidth, nHeight);
82  m_xWndPreview->set_size_request(nWidth, nHeight);
83 
84  m_xNameEdit->connect_insert_text(LINK(this, SwInsTableDlg, TextFilterHdl));
86  m_xNameEdit->connect_changed(LINK(this, SwInsTableDlg, ModifyName));
87  m_xColNF->connect_value_changed(LINK(this, SwInsTableDlg, ModifyRowCol));
88  m_xRowNF->connect_value_changed(LINK(this, SwInsTableDlg, ModifyRowCol));
89 
90  m_xRowNF->set_max(ROW_COL_PROD/m_xColNF->get_value());
91  m_xColNF->set_max(ROW_COL_PROD/m_xRowNF->get_value());
92 
93  m_xInsertBtn->connect_clicked(LINK(this, SwInsTableDlg, OKHdl));
94 
95  bool bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell())&HTMLMODE_ON);
96  const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
97 
98  SwInsertTableOptions aInsOpts = pModOpt->GetInsTableFlags(bHTMLMode);
99  SwInsertTableFlags nInsTableFlags = aInsOpts.mnInsMode;
100 
101  m_xHeaderCB->set_active(bool(nInsTableFlags & SwInsertTableFlags::Headline));
102  m_xRepeatHeaderCB->set_active(aInsOpts.mnRowsToRepeat > 0);
103  if (bHTMLMode)
104  m_xDontSplitCB->hide();
105  else
106  m_xDontSplitCB->set_active(!(nInsTableFlags & SwInsertTableFlags::SplitLayout));
107 
108  m_xRepeatHeaderNF->connect_value_changed( LINK( this, SwInsTableDlg, ModifyRepeatHeaderNF_Hdl ) );
109  m_xHeaderCB->connect_toggled( LINK( this, SwInsTableDlg, CheckBoxHdl ) );
110  m_xRepeatHeaderCB->connect_toggled( LINK( this, SwInsTableDlg, RepeatHeaderCheckBoxHdl ) );
111  RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
112  CheckBoxHdl(*m_xHeaderCB);
113 
114  sal_Int64 nMax = m_xRowNF->get_value();
115  if( nMax <= 1 )
116  nMax = 1;
117  else
118  --nMax;
119  m_xRepeatHeaderNF->set_max( nMax );
120 
122 }
123 
125 {
127 
128  m_xLbFormat->connect_changed(LINK(this, SwInsTableDlg, SelFormatHdl));
129 
131  pTableTable->Load();
132 
133  // Add "- none -" style autoformat table.
134  m_xLbFormat->append_text(SwViewShell::GetShellRes()->aStrNone); // Insert to listbox
135 
136  // Add other styles of autoformat tables.
137  for (sal_uInt8 i = 0, nCount = static_cast<sal_uInt8>(pTableTable->size());
138  i < nCount; i++)
139  {
140  SwTableAutoFormat const& rFormat = (*pTableTable)[ i ];
141  m_xLbFormat->append_text(rFormat.GetName());
142  if (pTAutoFormat && rFormat.GetName() == pTAutoFormat->GetName())
143  lbIndex = i;
144  }
145 
146  // Change this min variable if you add autotable manually.
147  minTableIndexInLb = 1;
149  lbIndex = 0;
150  m_xLbFormat->select( lbIndex );
151  tbIndex = lbIndexToTableIndex(lbIndex);
152 
153  SelFormatHdl( *m_xLbFormat );
154 }
155 
157 {
159  minTableIndexInLb <= listboxIndex &&
160  listboxIndex < maxTableIndexInLb )
161  {
162  return listboxIndex - minTableIndexInLb;
163  }
164 
165  return 255;
166 }
167 
168 static void lcl_SetProperties( SwTableAutoFormat* pTableAutoFormat, bool bVal )
169 {
170  pTableAutoFormat->SetFont( bVal );
171  pTableAutoFormat->SetJustify( bVal );
172  pTableAutoFormat->SetFrame( bVal );
173  pTableAutoFormat->SetBackground( bVal );
174  pTableAutoFormat->SetValueFormat( bVal );
175  pTableAutoFormat->SetWidthHeight( bVal );
176 }
177 
179 {
180  // Get index of selected item from the listbox
181  lbIndex = static_cast<sal_uInt8>(m_xLbFormat->get_selected_index());
182  tbIndex = lbIndexToTableIndex( lbIndex );
183 
184  // To understand this index mapping, look InitAutoTableFormat function to
185  // see how listbox item is implemented.
186  if( tbIndex < 255 )
187  m_aWndPreview.NotifyChange( (*pTableTable)[tbIndex] );
188  else
189  {
190  SwTableAutoFormat aTmp( SwViewShell::GetShellRes()->aStrNone );
191  lcl_SetProperties( &aTmp, false );
192 
193  m_aWndPreview.NotifyChange( aTmp );
194  }
195 }
196 
198 {
199  if( tbIndex < 255 )
200  pShell->SetTableStyle((*pTableTable)[tbIndex]);
201 
202  if( tbIndex < 255 )
203  {
204  if( pTAutoFormat )
205  *pTAutoFormat = (*pTableTable)[ tbIndex ];
206  else
207  pTAutoFormat = new SwTableAutoFormat( (*pTableTable)[ tbIndex ] );
208  }
209  else
210  {
211  delete pTAutoFormat;
212  pTAutoFormat = new SwTableAutoFormat( SwViewShell::GetShellRes()->aStrNone );
213  lcl_SetProperties( pTAutoFormat, false );
214  }
215 
216  m_xDialog->response(RET_OK);
217 }
218 
219 IMPL_LINK( SwInsTableDlg, ModifyName, weld::Entry&, rEdit, void )
220 {
221  OUString sTableName = rEdit.get_text();
222  m_xInsertBtn->set_sensitive(pShell->GetTableStyle(sTableName) == nullptr);
223 }
224 
225 IMPL_LINK( SwInsTableDlg, ModifyRowCol, weld::SpinButton&, rEdit, void )
226 {
227  if(&rEdit == m_xColNF.get())
228  {
229  sal_Int64 nCol = m_xColNF->get_value();
230  if(!nCol)
231  nCol = 1;
232  m_xRowNF->set_max(ROW_COL_PROD/nCol);
233  }
234  else
235  {
236  sal_Int64 nRow = m_xRowNF->get_value();
237  if(!nRow)
238  nRow = 1;
239  m_xColNF->set_max(ROW_COL_PROD/nRow);
240 
241  // adjust depending NF for repeated rows
242  sal_Int64 nMax = ( nRow == 1 )? 1 : nRow - 1 ;
243  sal_Int64 nActVal = m_xRepeatHeaderNF->get_value();
244 
245  m_xRepeatHeaderNF->set_max( nMax );
246 
247  if( nActVal > nMax )
248  m_xRepeatHeaderNF->set_value( nMax );
249  else if( nActVal < nEnteredValRepeatHeaderNF )
250  m_xRepeatHeaderNF->set_value(std::min(nEnteredValRepeatHeaderNF, nMax));
251  }
252 }
253 
255 {
256  m_xRepeatHeaderCB->set_sensitive(m_xHeaderCB->get_active());
257  RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
258 }
259 
260 IMPL_LINK_NOARG(SwInsTableDlg, RepeatHeaderCheckBoxHdl, weld::ToggleButton&, void)
261 {
262  m_xRepeatGroup->set_sensitive(m_xHeaderCB->get_active() && m_xRepeatHeaderCB->get_active());
263 }
264 
265 IMPL_LINK_NOARG(SwInsTableDlg, ModifyRepeatHeaderNF_Hdl, weld::SpinButton&, void)
266 {
267  nEnteredValRepeatHeaderNF = m_xRepeatHeaderNF->get_value();
268 }
269 
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 lbIndexToTableIndex(const sal_uInt8 listboxIndex)
Definition: instable.cxx:156
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:2487
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:168
sal_uInt16 mnRowsToRepeat
Definition: itabenum.hxx:41
SwInsertTableFlags
Definition: itabenum.hxx:25
void InitAutoTableFormat()
Definition: instable.cxx:124
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:256
std::unique_ptr< weld::SpinButton > m_xRepeatHeaderNF
Definition: instable.hxx:55
int i
IMPL_LINK_NOARG(SwInsTableDlg, SelFormatHdl, weld::TreeView &, void)
Definition: instable.cxx:178
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:55
#define ROW_COL_PROD
Definition: instable.cxx:27
SwDocShell * GetDocShell()
Definition: view.cxx:1107
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:61
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
const SwInsertTableOptions & GetInsTableFlags(bool bHTML) const
Definition: modcfg.hxx:301
sal_uInt8 tbIndex
Definition: instable.hxx:43
sal_uInt8 lbIndex
Definition: instable.hxx:42
Definition: view.hxx:146
void GetValues(OUString &rName, sal_uInt16 &rRow, sal_uInt16 &rCol, SwInsertTableOptions &rInsTableOpts, OUString &rTableAutoFormatName, std::unique_ptr< SwTableAutoFormat > &prTAFormat)
Definition: instable.cxx:29
SAL_DLLPRIVATE bool Load(SvStream &rStream)
Definition: tblafmt.cxx:1061