bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / table / instable.cxx
blob6b00aac8ec725c18e18334b43de785d62e87fafb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/string.hxx>
21 #include <vcl/msgbox.hxx>
23 #include "wrtsh.hxx"
24 #include "view.hxx"
25 #include "itabenum.hxx"
26 #include "instable.hxx"
27 #include "tblafmt.hxx"
28 #include "modcfg.hxx"
29 #include "swmodule.hxx"
30 #include <sfx2/htmlmode.hxx>
31 #include <viewopt.hxx>
33 #include "table.hrc"
34 #include "instable.hrc"
36 #include "swabstdlg.hxx"
38 namespace swui
40 SwAbstractDialogFactory * GetFactory();
43 #define ROW_COL_PROD 16384
45 void SwInsTableDlg::GetValues( String& rName, sal_uInt16& rRow, sal_uInt16& rCol,
46 SwInsertTableOptions& rInsTblOpts, String& rAutoName,
47 SwTableAutoFmt *& prTAFmt )
49 sal_uInt16 nInsMode = 0;
50 rName = m_pNameEdit->GetText();
51 rRow = (sal_uInt16)m_pRowNF->GetValue();
52 rCol = (sal_uInt16)m_pColNF->GetValue();
54 if (m_pBorderCB->IsChecked())
55 nInsMode |= tabopts::DEFAULT_BORDER;
56 if (m_pHeaderCB->IsChecked())
57 nInsMode |= tabopts::HEADLINE;
58 if (m_pRepeatHeaderCB->IsEnabled() && m_pRepeatHeaderCB->IsChecked())
59 rInsTblOpts.mnRowsToRepeat = sal_uInt16( m_pRepeatHeaderNF->GetValue() );
60 else
61 rInsTblOpts.mnRowsToRepeat = 0;
62 if (!m_pDontSplitCB->IsChecked())
63 nInsMode |= tabopts::SPLIT_LAYOUT;
64 if( pTAutoFmt )
66 prTAFmt = new SwTableAutoFmt( *pTAutoFmt );
67 rAutoName = prTAFmt->GetName();
70 rInsTblOpts.mnInsMode = nInsMode;
73 SwInsTableDlg::SwInsTableDlg( SwView& rView )
74 : SfxModalDialog(rView.GetWindow(), "InsertTableDialog", "modules/swriter/ui/inserttable.ui")
75 , pShell(&rView.GetWrtShell())
76 , pTAutoFmt(0)
77 , nEnteredValRepeatHeaderNF(-1)
79 get(m_pNameEdit, "nameedit");
80 get(m_pColNF, "colspin");
81 get(m_pRowNF, "rowspin");
82 get(m_pHeaderCB, "headercb");
83 get(m_pRepeatHeaderCB, "repeatcb");
84 get(m_pDontSplitCB, "dontsplitcb");
85 get(m_pBorderCB, "bordercb");
86 get(m_pAutoFmtBtn, "autoformat");
87 get(m_pInsertBtn, "ok");
88 get(m_pRepeatGroup, "repeatgroup");
89 get(m_pRepeatHeaderNF, "repeatheaderspin");
91 m_pNameEdit->SetText(pShell->GetUniqueTblName());
92 m_pNameEdit->SetModifyHdl(LINK(this, SwInsTableDlg, ModifyName));
93 m_pColNF->SetModifyHdl(LINK(this, SwInsTableDlg, ModifyRowCol));
94 m_pRowNF->SetModifyHdl(LINK(this, SwInsTableDlg, ModifyRowCol));
96 m_pRowNF->SetMax(ROW_COL_PROD/m_pColNF->GetValue());
97 m_pColNF->SetMax(ROW_COL_PROD/m_pRowNF->GetValue());
98 m_pAutoFmtBtn->SetClickHdl(LINK(this, SwInsTableDlg, AutoFmtHdl));
100 m_pInsertBtn->SetClickHdl(LINK(this, SwInsTableDlg, OKHdl));
102 sal_Bool bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell())&HTMLMODE_ON);
103 const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
105 SwInsertTableOptions aInsOpts = pModOpt->GetInsTblFlags(bHTMLMode);
106 sal_uInt16 nInsTblFlags = aInsOpts.mnInsMode;
108 m_pHeaderCB->Check( 0 != (nInsTblFlags & tabopts::HEADLINE) );
109 m_pRepeatHeaderCB->Check(aInsOpts.mnRowsToRepeat > 0);
110 if(bHTMLMode)
112 m_pDontSplitCB->Hide();
113 m_pBorderCB->SetPosPixel(m_pDontSplitCB->GetPosPixel());
115 else
117 m_pDontSplitCB->Check( 0 == (nInsTblFlags & tabopts::SPLIT_LAYOUT) );
119 m_pBorderCB->Check( 0 != (nInsTblFlags & tabopts::DEFAULT_BORDER) );
121 m_pRepeatHeaderNF->SetModifyHdl( LINK( this, SwInsTableDlg, ModifyRepeatHeaderNF_Hdl ) );
122 m_pHeaderCB->SetClickHdl(LINK(this, SwInsTableDlg, CheckBoxHdl));
123 m_pRepeatHeaderCB->SetClickHdl(LINK(this, SwInsTableDlg, ReapeatHeaderCheckBoxHdl));
124 ReapeatHeaderCheckBoxHdl();
125 CheckBoxHdl();
127 sal_Int64 nMax = m_pRowNF->GetValue();
128 if( nMax <= 1 )
129 nMax = 1;
130 else
131 --nMax;
132 m_pRepeatHeaderNF->SetMax( nMax );
135 IMPL_LINK_NOARG(SwInsTableDlg, OKHdl)
137 EndDialog(RET_OK);
138 return 0;
141 SwInsTableDlg::~SwInsTableDlg()
143 delete pTAutoFmt;
146 IMPL_LINK_INLINE_START( SwInsTableDlg, ModifyName, Edit *, pEdit )
148 String sTblName = pEdit->GetText();
149 if(sTblName.Search(' ') != STRING_NOTFOUND)
151 sTblName = comphelper::string::remove(sTblName, ' ');
152 pEdit->SetText(sTblName);
155 m_pInsertBtn->Enable(pShell->GetTblStyle( sTblName ) == 0);
156 return 0;
158 IMPL_LINK_INLINE_END( SwInsTableDlg, ModifyName, Edit *, pEdit )
160 IMPL_LINK( SwInsTableDlg, ModifyRowCol, NumericField *, pField )
162 if(pField == m_pColNF)
164 sal_Int64 nCol = m_pColNF->GetValue();
165 if(!nCol)
166 nCol = 1;
167 m_pRowNF->SetMax(ROW_COL_PROD/nCol);
169 else
171 sal_Int64 nRow = m_pRowNF->GetValue();
172 if(!nRow)
173 nRow = 1;
174 m_pColNF->SetMax(ROW_COL_PROD/nRow);
176 // adjust depending NF for repeated rows
177 sal_Int64 nMax = ( nRow == 1 )? 1 : nRow - 1 ;
178 sal_Int64 nActVal = m_pRepeatHeaderNF->GetValue();
180 m_pRepeatHeaderNF->SetMax( nMax );
182 if( nActVal > nMax )
183 m_pRepeatHeaderNF->SetValue( nMax );
184 else if( nActVal < nEnteredValRepeatHeaderNF )
185 m_pRepeatHeaderNF->SetValue( ( nEnteredValRepeatHeaderNF < nMax )? nEnteredValRepeatHeaderNF : nMax );
187 return 0;
190 IMPL_LINK( SwInsTableDlg, AutoFmtHdl, PushButton*, pButton )
192 SwAbstractDialogFactory* pFact = swui::GetFactory();
193 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
195 AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton,pShell, sal_False, pTAutoFmt);
196 OSL_ENSURE(pDlg, "Dialogdiet fail!");
197 if( RET_OK == pDlg->Execute())
198 pDlg->FillAutoFmtOfIndex( pTAutoFmt );
199 delete pDlg;
200 return 0;
203 IMPL_LINK_NOARG(SwInsTableDlg, CheckBoxHdl)
205 m_pRepeatHeaderCB->Enable(m_pHeaderCB->IsChecked());
206 ReapeatHeaderCheckBoxHdl();
208 return 0;
211 IMPL_LINK_NOARG(SwInsTableDlg, ReapeatHeaderCheckBoxHdl)
213 m_pRepeatGroup->Enable(m_pHeaderCB->IsChecked() && m_pRepeatHeaderCB->IsChecked());
215 return 0;
218 IMPL_LINK_NOARG(SwInsTableDlg, ModifyRepeatHeaderNF_Hdl)
220 nEnteredValRepeatHeaderNF = m_pRepeatHeaderNF->GetValue();
221 return 0;
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */