Line data Source code
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 <comphelper/string.hxx>
21 : #include <vcl/msgbox.hxx>
22 :
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>
32 :
33 : #include "table.hrc"
34 : #include "instable.hrc"
35 :
36 : #include "swabstdlg.hxx"
37 :
38 : namespace swui
39 : {
40 : SwAbstractDialogFactory * GetFactory();
41 : }
42 :
43 : #define ROW_COL_PROD 16384
44 :
45 0 : void SwInsTableDlg::GetValues( String& rName, sal_uInt16& rRow, sal_uInt16& rCol,
46 : SwInsertTableOptions& rInsTblOpts, String& rAutoName,
47 : SwTableAutoFmt *& prTAFmt )
48 : {
49 0 : sal_uInt16 nInsMode = 0;
50 0 : rName = m_pNameEdit->GetText();
51 0 : rRow = (sal_uInt16)m_pRowNF->GetValue();
52 0 : rCol = (sal_uInt16)m_pColNF->GetValue();
53 :
54 0 : if (m_pBorderCB->IsChecked())
55 0 : nInsMode |= tabopts::DEFAULT_BORDER;
56 0 : if (m_pHeaderCB->IsChecked())
57 0 : nInsMode |= tabopts::HEADLINE;
58 0 : if (m_pRepeatHeaderCB->IsEnabled() && m_pRepeatHeaderCB->IsChecked())
59 0 : rInsTblOpts.mnRowsToRepeat = sal_uInt16( m_pRepeatHeaderNF->GetValue() );
60 : else
61 0 : rInsTblOpts.mnRowsToRepeat = 0;
62 0 : if (!m_pDontSplitCB->IsChecked())
63 0 : nInsMode |= tabopts::SPLIT_LAYOUT;
64 0 : if( pTAutoFmt )
65 : {
66 0 : prTAFmt = new SwTableAutoFmt( *pTAutoFmt );
67 0 : rAutoName = prTAFmt->GetName();
68 : }
69 :
70 0 : rInsTblOpts.mnInsMode = nInsMode;
71 0 : }
72 :
73 0 : SwInsTableDlg::SwInsTableDlg( SwView& rView )
74 : : SfxModalDialog(rView.GetWindow(), "InsertTableDialog", "modules/swriter/ui/inserttable.ui")
75 0 : , pShell(&rView.GetWrtShell())
76 : , pTAutoFmt(0)
77 0 : , nEnteredValRepeatHeaderNF(-1)
78 : {
79 0 : get(m_pNameEdit, "nameedit");
80 0 : get(m_pColNF, "colspin");
81 0 : get(m_pRowNF, "rowspin");
82 0 : get(m_pHeaderCB, "headercb");
83 0 : get(m_pRepeatHeaderCB, "repeatcb");
84 0 : get(m_pDontSplitCB, "dontsplitcb");
85 0 : get(m_pBorderCB, "bordercb");
86 0 : get(m_pAutoFmtBtn, "autoformat");
87 0 : get(m_pInsertBtn, "ok");
88 0 : get(m_pRepeatGroup, "repeatgroup");
89 0 : get(m_pRepeatHeaderNF, "repeatheaderspin");
90 :
91 0 : m_pNameEdit->SetText(pShell->GetUniqueTblName());
92 0 : m_pNameEdit->SetModifyHdl(LINK(this, SwInsTableDlg, ModifyName));
93 0 : m_pColNF->SetModifyHdl(LINK(this, SwInsTableDlg, ModifyRowCol));
94 0 : m_pRowNF->SetModifyHdl(LINK(this, SwInsTableDlg, ModifyRowCol));
95 :
96 0 : m_pRowNF->SetMax(ROW_COL_PROD/m_pColNF->GetValue());
97 0 : m_pColNF->SetMax(ROW_COL_PROD/m_pRowNF->GetValue());
98 0 : m_pAutoFmtBtn->SetClickHdl(LINK(this, SwInsTableDlg, AutoFmtHdl));
99 :
100 0 : m_pInsertBtn->SetClickHdl(LINK(this, SwInsTableDlg, OKHdl));
101 :
102 0 : sal_Bool bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell())&HTMLMODE_ON);
103 0 : const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
104 :
105 0 : SwInsertTableOptions aInsOpts = pModOpt->GetInsTblFlags(bHTMLMode);
106 0 : sal_uInt16 nInsTblFlags = aInsOpts.mnInsMode;
107 :
108 0 : m_pHeaderCB->Check( 0 != (nInsTblFlags & tabopts::HEADLINE) );
109 0 : m_pRepeatHeaderCB->Check(aInsOpts.mnRowsToRepeat > 0);
110 0 : if(bHTMLMode)
111 : {
112 0 : m_pDontSplitCB->Hide();
113 0 : m_pBorderCB->SetPosPixel(m_pDontSplitCB->GetPosPixel());
114 : }
115 : else
116 : {
117 0 : m_pDontSplitCB->Check( 0 == (nInsTblFlags & tabopts::SPLIT_LAYOUT) );
118 : }
119 0 : m_pBorderCB->Check( 0 != (nInsTblFlags & tabopts::DEFAULT_BORDER) );
120 :
121 0 : m_pRepeatHeaderNF->SetModifyHdl( LINK( this, SwInsTableDlg, ModifyRepeatHeaderNF_Hdl ) );
122 0 : m_pHeaderCB->SetClickHdl(LINK(this, SwInsTableDlg, CheckBoxHdl));
123 0 : m_pRepeatHeaderCB->SetClickHdl(LINK(this, SwInsTableDlg, ReapeatHeaderCheckBoxHdl));
124 0 : ReapeatHeaderCheckBoxHdl();
125 0 : CheckBoxHdl();
126 :
127 0 : sal_Int64 nMax = m_pRowNF->GetValue();
128 0 : if( nMax <= 1 )
129 0 : nMax = 1;
130 : else
131 0 : --nMax;
132 0 : m_pRepeatHeaderNF->SetMax( nMax );
133 0 : }
134 :
135 0 : IMPL_LINK_NOARG(SwInsTableDlg, OKHdl)
136 : {
137 0 : EndDialog(RET_OK);
138 0 : return 0;
139 : }
140 :
141 0 : SwInsTableDlg::~SwInsTableDlg()
142 : {
143 0 : delete pTAutoFmt;
144 0 : }
145 :
146 0 : IMPL_LINK_INLINE_START( SwInsTableDlg, ModifyName, Edit *, pEdit )
147 : {
148 0 : String sTblName = pEdit->GetText();
149 0 : if(sTblName.Search(' ') != STRING_NOTFOUND)
150 : {
151 0 : sTblName = comphelper::string::remove(sTblName, ' ');
152 0 : pEdit->SetText(sTblName);
153 : }
154 :
155 0 : m_pInsertBtn->Enable(pShell->GetTblStyle( sTblName ) == 0);
156 0 : return 0;
157 : }
158 0 : IMPL_LINK_INLINE_END( SwInsTableDlg, ModifyName, Edit *, pEdit )
159 :
160 0 : IMPL_LINK( SwInsTableDlg, ModifyRowCol, NumericField *, pField )
161 : {
162 0 : if(pField == m_pColNF)
163 : {
164 0 : sal_Int64 nCol = m_pColNF->GetValue();
165 0 : if(!nCol)
166 0 : nCol = 1;
167 0 : m_pRowNF->SetMax(ROW_COL_PROD/nCol);
168 : }
169 : else
170 : {
171 0 : sal_Int64 nRow = m_pRowNF->GetValue();
172 0 : if(!nRow)
173 0 : nRow = 1;
174 0 : m_pColNF->SetMax(ROW_COL_PROD/nRow);
175 :
176 : // adjust depending NF for repeated rows
177 0 : sal_Int64 nMax = ( nRow == 1 )? 1 : nRow - 1 ;
178 0 : sal_Int64 nActVal = m_pRepeatHeaderNF->GetValue();
179 :
180 0 : m_pRepeatHeaderNF->SetMax( nMax );
181 :
182 0 : if( nActVal > nMax )
183 0 : m_pRepeatHeaderNF->SetValue( nMax );
184 0 : else if( nActVal < nEnteredValRepeatHeaderNF )
185 0 : m_pRepeatHeaderNF->SetValue( ( nEnteredValRepeatHeaderNF < nMax )? nEnteredValRepeatHeaderNF : nMax );
186 : }
187 0 : return 0;
188 : }
189 :
190 0 : IMPL_LINK( SwInsTableDlg, AutoFmtHdl, PushButton*, pButton )
191 : {
192 0 : SwAbstractDialogFactory* pFact = swui::GetFactory();
193 : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
194 :
195 0 : AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton,pShell, sal_False, pTAutoFmt);
196 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
197 0 : if( RET_OK == pDlg->Execute())
198 0 : pDlg->FillAutoFmtOfIndex( pTAutoFmt );
199 0 : delete pDlg;
200 0 : return 0;
201 : }
202 :
203 0 : IMPL_LINK_NOARG(SwInsTableDlg, CheckBoxHdl)
204 : {
205 0 : m_pRepeatHeaderCB->Enable(m_pHeaderCB->IsChecked());
206 0 : ReapeatHeaderCheckBoxHdl();
207 :
208 0 : return 0;
209 : }
210 :
211 0 : IMPL_LINK_NOARG(SwInsTableDlg, ReapeatHeaderCheckBoxHdl)
212 : {
213 0 : m_pRepeatGroup->Enable(m_pHeaderCB->IsChecked() && m_pRepeatHeaderCB->IsChecked());
214 :
215 0 : return 0;
216 : }
217 :
218 0 : IMPL_LINK_NOARG(SwInsTableDlg, ModifyRepeatHeaderNF_Hdl)
219 : {
220 0 : nEnteredValRepeatHeaderNF = m_pRepeatHeaderNF->GetValue();
221 0 : return 0;
222 0 : }
223 :
224 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|