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 <swabstdlg.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 {
80  const int nWidth = m_xLbFormat->get_approximate_digit_width() * 32;
81  const int nHeight = m_xLbFormat->get_height_rows(8);
82  m_xLbFormat->set_size_request(nWidth, nHeight);
83  m_xWndPreview->set_size_request(nWidth, nHeight);
84 
85  m_xNameEdit->connect_insert_text(LINK(this, SwInsTableDlg, TextFilterHdl));
87  m_xNameEdit->connect_changed(LINK(this, SwInsTableDlg, ModifyName));
88  m_xColNF->connect_value_changed(LINK(this, SwInsTableDlg, ModifyRowCol));
89  m_xRowNF->connect_value_changed(LINK(this, SwInsTableDlg, ModifyRowCol));
90 
91  m_xRowNF->set_max(ROW_COL_PROD/m_xColNF->get_value());
92  m_xColNF->set_max(ROW_COL_PROD/m_xRowNF->get_value());
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_xRowNF->get_value();
116  if( nMax <= 1 )
117  nMax = 1;
118  else
119  --nMax;
120  m_xRepeatHeaderNF->set_max( nMax );
121 
123 }
124 
126 {
128 
129  m_xLbFormat->connect_changed(LINK(this, SwInsTableDlg, SelFormatHdl));
130 
132  pTableTable->Load();
133 
134  // Add "- none -" style autoformat table.
135  m_xLbFormat->append_text(SwViewShell::GetShellRes()->aStrNone); // Insert to listbox
136 
137  // Add other styles of autoformat tables.
138  for (sal_uInt8 i = 0, nCount = static_cast<sal_uInt8>(pTableTable->size());
139  i < nCount; i++)
140  {
141  SwTableAutoFormat const& rFormat = (*pTableTable)[ i ];
142  m_xLbFormat->append_text(rFormat.GetName());
143  if (pTAutoFormat && rFormat.GetName() == pTAutoFormat->GetName())
144  lbIndex = i;
145  }
146 
147  // Change this min variable if you add autotable manually.
148  minTableIndexInLb = 1;
150  lbIndex = 1;
151  m_xLbFormat->select( lbIndex );
152  tbIndex = lbIndexToTableIndex(lbIndex);
153 
154  SelFormatHdl( *m_xLbFormat );
155 }
156 
158 {
160  minTableIndexInLb <= listboxIndex &&
161  listboxIndex < maxTableIndexInLb )
162  {
163  return listboxIndex - minTableIndexInLb;
164  }
165 
166  return 255;
167 }
168 
169 static void lcl_SetProperties( SwTableAutoFormat* pTableAutoFormat, bool bVal )
170 {
171  pTableAutoFormat->SetFont( bVal );
172  pTableAutoFormat->SetJustify( bVal );
173  pTableAutoFormat->SetFrame( bVal );
174  pTableAutoFormat->SetBackground( bVal );
175  pTableAutoFormat->SetValueFormat( bVal );
176  pTableAutoFormat->SetWidthHeight( bVal );
177 }
178 
180 {
181  // Get index of selected item from the listbox
182  lbIndex = static_cast<sal_uInt8>(m_xLbFormat->get_selected_index());
183  tbIndex = lbIndexToTableIndex( lbIndex );
184 
185  // To understand this index mapping, look InitAutoTableFormat function to
186  // see how listbox item is implemented.
187  if( tbIndex < 255 )
188  m_aWndPreview.NotifyChange( (*pTableTable)[tbIndex] );
189  else
190  {
191  SwTableAutoFormat aTmp( SwViewShell::GetShellRes()->aStrNone );
192  lcl_SetProperties( &aTmp, false );
193 
194  m_aWndPreview.NotifyChange( aTmp );
195  }
196 }
197 
199 {
200  if( tbIndex < 255 )
201  pShell->SetTableStyle((*pTableTable)[tbIndex]);
202 
203  if( tbIndex < 255 )
204  {
205  if( pTAutoFormat )
206  *pTAutoFormat = (*pTableTable)[ tbIndex ];
207  else
208  pTAutoFormat = new SwTableAutoFormat( (*pTableTable)[ tbIndex ] );
209  }
210  else
211  {
212  delete pTAutoFormat;
213  pTAutoFormat = new SwTableAutoFormat( SwViewShell::GetShellRes()->aStrNone );
214  lcl_SetProperties( pTAutoFormat, false );
215  }
216 
217  m_xDialog->response(RET_OK);
218 }
219 
220 IMPL_LINK( SwInsTableDlg, ModifyName, weld::Entry&, rEdit, void )
221 {
222  OUString sTableName = rEdit.get_text();
223  m_xInsertBtn->set_sensitive(pShell->GetTableStyle(sTableName) == nullptr);
224 }
225 
226 IMPL_LINK( SwInsTableDlg, ModifyRowCol, weld::SpinButton&, rEdit, void )
227 {
228  if(&rEdit == m_xColNF.get())
229  {
230  sal_Int64 nCol = m_xColNF->get_value();
231  if(!nCol)
232  nCol = 1;
233  m_xRowNF->set_max(ROW_COL_PROD/nCol);
234  }
235  else
236  {
237  sal_Int64 nRow = m_xRowNF->get_value();
238  if(!nRow)
239  nRow = 1;
240  m_xColNF->set_max(ROW_COL_PROD/nRow);
241 
242  // adjust depending NF for repeated rows
243  sal_Int64 nMax = ( nRow == 1 )? 1 : nRow - 1 ;
244  sal_Int64 nActVal = m_xRepeatHeaderNF->get_value();
245 
246  m_xRepeatHeaderNF->set_max( nMax );
247 
248  if( nActVal > nMax )
249  m_xRepeatHeaderNF->set_value( nMax );
250  else if( nActVal < nEnteredValRepeatHeaderNF )
251  m_xRepeatHeaderNF->set_value(std::min(nEnteredValRepeatHeaderNF, nMax));
252  }
253 }
254 
256 {
257  m_xRepeatHeaderCB->set_sensitive(m_xHeaderCB->get_active());
258  RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB);
259 }
260 
261 IMPL_LINK_NOARG(SwInsTableDlg, RepeatHeaderCheckBoxHdl, weld::ToggleButton&, void)
262 {
263  m_xRepeatGroup->set_sensitive(m_xHeaderCB->get_active() && m_xRepeatHeaderCB->get_active());
264 }
265 
266 IMPL_LINK_NOARG(SwInsTableDlg, ModifyRepeatHeaderNF_Hdl, weld::SpinButton&, void)
267 {
268  nEnteredValRepeatHeaderNF = m_xRepeatHeaderNF->get_value();
269 }
270 
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 lbIndexToTableIndex(const sal_uInt8 listboxIndex)
Definition: instable.cxx:157
void SetValueFormat(const bool bNew)
Definition: tblafmt.hxx:250
std::unique_ptr< weld::SpinButton > m_xColNF
Definition: instable.hxx:51
sal_uInt8 minTableIndexInLb
Definition: instable.hxx:44
static ShellResource * GetShellRes()
Definition: viewsh.cxx:2490
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:248
SwInsertTableFlags mnInsMode
Definition: itabenum.hxx:40
static void lcl_SetProperties(SwTableAutoFormat *pTableAutoFormat, bool bVal)
Definition: instable.cxx:169
sal_uInt16 mnRowsToRepeat
Definition: itabenum.hxx:41
SwInsertTableFlags
Definition: itabenum.hxx:25
void InitAutoTableFormat()
Definition: instable.cxx:125
void DetectRTL(SwWrtShell const *pWrtShell)
void SetFont(const bool bNew)
Definition: tblafmt.hxx:246
std::unique_ptr< weld::CheckButton > m_xRepeatHeaderCB
Definition: instable.hxx:54
void SetJustify(const bool bNew)
Definition: tblafmt.hxx:247
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
#define SW_MOD()
Definition: swmodule.hxx:255
std::unique_ptr< weld::SpinButton > m_xRepeatHeaderNF
Definition: instable.hxx:55
IMPL_LINK_NOARG(SwInsTableDlg, SelFormatHdl, weld::TreeView &, void)
Definition: instable.cxx:179
int i
HTMLMODE_ON
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:339
size_t size() const
Definition: tblafmt.cxx:900
weld::Window * GetFrameWeld(SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
OUString GetUniqueTableName() const
Definition: edfmt.cxx:113
SwTableAutoFormatTable * pTableTable
Definition: instable.hxx:39
void SetWidthHeight(const bool bNew)
Definition: tblafmt.hxx:251
void SetBackground(const bool bNew)
Definition: tblafmt.hxx:249
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:1115
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:225
weld::Entry & rEdit
SwInsTableDlg(SwView &rView)
Definition: instable.cxx:62
SwTableAutoFormat * pTAutoFormat
Definition: instable.hxx:40
unsigned char sal_uInt8
RET_OK
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:300
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:30
SAL_DLLPRIVATE bool Load(SvStream &rStream)
Definition: tblafmt.cxx:1031