Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <comphelper/string.hxx>
30 : : #include <vcl/msgbox.hxx>
31 : :
32 : : #include "wrtsh.hxx"
33 : : #include "view.hxx"
34 : : #include "itabenum.hxx"
35 : : #include "instable.hxx"
36 : : #include "tblafmt.hxx"
37 : : #include "modcfg.hxx"
38 : : #include "swmodule.hxx"
39 : : #include <svx/htmlmode.hxx>
40 : : #include <viewopt.hxx>
41 : :
42 : : #include "table.hrc"
43 : : #include "instable.hrc"
44 : :
45 : : #include "swabstdlg.hxx"
46 : :
47 : : namespace swui
48 : : {
49 : : SwAbstractDialogFactory * GetFactory();
50 : : }
51 : :
52 : : #define ROW_COL_PROD 16384
53 : :
54 : 0 : void SwInsTableDlg::GetValues( String& rName, sal_uInt16& rRow, sal_uInt16& rCol,
55 : : SwInsertTableOptions& rInsTblOpts, String& rAutoName,
56 : : SwTableAutoFmt *& prTAFmt )
57 : : {
58 : 0 : sal_uInt16 nInsMode = 0;
59 : 0 : rName = aNameEdit.GetText();
60 : 0 : rRow = (sal_uInt16)aRowEdit.GetValue();
61 : 0 : rCol = (sal_uInt16)aColEdit.GetValue();
62 : :
63 : 0 : if (aBorderCB.IsChecked())
64 : 0 : nInsMode |= tabopts::DEFAULT_BORDER;
65 : 0 : if (aHeaderCB.IsChecked())
66 : 0 : nInsMode |= tabopts::HEADLINE;
67 : 0 : if (aRepeatHeaderCB.IsEnabled() && aRepeatHeaderCB.IsChecked())
68 : 0 : rInsTblOpts.mnRowsToRepeat = sal_uInt16( aRepeatHeaderNF.GetValue() );
69 : : else
70 : 0 : rInsTblOpts.mnRowsToRepeat = 0;
71 : 0 : if (!aDontSplitCB.IsChecked())
72 : 0 : nInsMode |= tabopts::SPLIT_LAYOUT;
73 : 0 : if( pTAutoFmt )
74 : : {
75 : 0 : prTAFmt = new SwTableAutoFmt( *pTAutoFmt );
76 : 0 : rAutoName = prTAFmt->GetName();
77 : : }
78 : :
79 : 0 : rInsTblOpts.mnInsMode = nInsMode;
80 : 0 : }
81 : :
82 : : // CTOR / DTOR -----------------------------------------------------------
83 : :
84 : :
85 : 0 : SwInsTableDlg::SwInsTableDlg( SwView& rView )
86 : : : SfxModalDialog( rView.GetWindow(), SW_RES(DLG_INSERT_TABLE) ),
87 : : aNameFT (this, SW_RES(FT_NAME)),
88 : : aNameEdit (this, SW_RES(ED_NAME)),
89 : :
90 : : aFL (this, SW_RES(FL_TABLE)),
91 : : aColLbl (this, SW_RES(FT_COL)),
92 : : aColEdit (this, SW_RES(ED_COL)),
93 : : aRowLbl (this, SW_RES(FT_ROW)),
94 : : aRowEdit (this, SW_RES(ED_ROW)),
95 : :
96 : : aOptionsFL (this, SW_RES(FL_OPTIONS)),
97 : : aHeaderCB (this, SW_RES(CB_HEADER)),
98 : : aRepeatHeaderCB (this, SW_RES(CB_REPEAT_HEADER)),
99 : : aRepeatHeaderFT (this, SW_RES(FT_REPEAT_HEADER)),
100 : : aRepeatHeaderBeforeFT (this),
101 : : aRepeatHeaderNF (this, SW_RES(NF_REPEAT_HEADER)),
102 : : aRepeatHeaderAfterFT (this),
103 : : aRepeatHeaderCombo (this, SW_RES(WIN_REPEAT_HEADER), aRepeatHeaderNF, aRepeatHeaderBeforeFT, aRepeatHeaderAfterFT),
104 : :
105 : : aDontSplitCB (this, SW_RES(CB_DONT_SPLIT)),
106 : : aBorderCB (this, SW_RES(CB_BORDER)),
107 : :
108 : : aOkBtn (this, SW_RES(BT_OK)),
109 : : aCancelBtn (this, SW_RES(BT_CANCEL)),
110 : : aHelpBtn (this, SW_RES(BT_HELP)),
111 : : aAutoFmtBtn (this, SW_RES(BT_AUTOFORMAT)),
112 : :
113 : 0 : pShell(&rView.GetWrtShell()),
114 : : pTAutoFmt( 0 ),
115 : 0 : nEnteredValRepeatHeaderNF( -1 )
116 : : {
117 : 0 : FreeResource();
118 : 0 : aNameEdit.SetText(pShell->GetUniqueTblName());
119 : 0 : aNameEdit.SetModifyHdl(LINK(this, SwInsTableDlg, ModifyName));
120 : 0 : aColEdit.SetModifyHdl(LINK(this, SwInsTableDlg, ModifyRowCol));
121 : 0 : aRowEdit.SetModifyHdl(LINK(this, SwInsTableDlg, ModifyRowCol));
122 : :
123 : 0 : aRowEdit.SetMax(ROW_COL_PROD/aColEdit.GetValue());
124 : 0 : aColEdit.SetMax(ROW_COL_PROD/aRowEdit.GetValue());
125 : 0 : aAutoFmtBtn.SetClickHdl(LINK(this, SwInsTableDlg, AutoFmtHdl));
126 : :
127 : 0 : sal_Bool bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell())&HTMLMODE_ON);
128 : 0 : const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
129 : :
130 : 0 : SwInsertTableOptions aInsOpts = pModOpt->GetInsTblFlags(bHTMLMode);
131 : 0 : sal_uInt16 nInsTblFlags = aInsOpts.mnInsMode;
132 : :
133 : 0 : aHeaderCB.Check( 0 != (nInsTblFlags & tabopts::HEADLINE) );
134 : 0 : aRepeatHeaderCB.Check(aInsOpts.mnRowsToRepeat > 0);
135 : 0 : if(bHTMLMode)
136 : : {
137 : 0 : aDontSplitCB.Hide();
138 : 0 : aBorderCB.SetPosPixel(aDontSplitCB.GetPosPixel());
139 : : }
140 : : else
141 : : {
142 : 0 : aDontSplitCB.Check( 0 == (nInsTblFlags & tabopts::SPLIT_LAYOUT) );
143 : : }
144 : 0 : aBorderCB.Check( 0 != (nInsTblFlags & tabopts::DEFAULT_BORDER) );
145 : :
146 : 0 : aRepeatHeaderNF.SetModifyHdl( LINK( this, SwInsTableDlg, ModifyRepeatHeaderNF_Hdl ) );
147 : 0 : aHeaderCB.SetClickHdl(LINK(this, SwInsTableDlg, CheckBoxHdl));
148 : 0 : aRepeatHeaderCB.SetClickHdl(LINK(this, SwInsTableDlg, ReapeatHeaderCheckBoxHdl));
149 : 0 : ReapeatHeaderCheckBoxHdl();
150 : 0 : CheckBoxHdl();
151 : :
152 : 0 : sal_Int64 nMax = aRowEdit.GetValue();
153 : 0 : if( nMax <= 1 )
154 : 0 : nMax = 1;
155 : : else
156 : 0 : --nMax;
157 : 0 : aRepeatHeaderNF.SetMax( nMax );
158 : :
159 : 0 : aRepeatHeaderCombo.Arrange( aRepeatHeaderFT );
160 : 0 : }
161 : :
162 : 0 : SwInsTableDlg::~SwInsTableDlg()
163 : : {
164 : 0 : delete pTAutoFmt;
165 : 0 : }
166 : :
167 : 0 : IMPL_LINK_INLINE_START( SwInsTableDlg, ModifyName, Edit *, pEdit )
168 : : {
169 : 0 : String sTblName = pEdit->GetText();
170 : 0 : if(sTblName.Search(' ') != STRING_NOTFOUND)
171 : : {
172 : 0 : sTblName = comphelper::string::remove(sTblName, ' ');
173 : 0 : pEdit->SetText(sTblName);
174 : : }
175 : :
176 : 0 : aOkBtn.Enable(pShell->GetTblStyle( sTblName ) == 0);
177 : 0 : return 0;
178 : : }
179 : 0 : IMPL_LINK_INLINE_END( SwInsTableDlg, ModifyName, Edit *, pEdit )
180 : :
181 : 0 : IMPL_LINK( SwInsTableDlg, ModifyRowCol, NumericField *, pField )
182 : : {
183 : 0 : if(pField == &aColEdit)
184 : : {
185 : 0 : sal_Int64 nCol = aColEdit.GetValue();
186 : 0 : if(!nCol)
187 : 0 : nCol = 1;
188 : 0 : aRowEdit.SetMax(ROW_COL_PROD/nCol);
189 : : }
190 : : else
191 : : {
192 : 0 : sal_Int64 nRow = aRowEdit.GetValue();
193 : 0 : if(!nRow)
194 : 0 : nRow = 1;
195 : 0 : aColEdit.SetMax(ROW_COL_PROD/nRow);
196 : :
197 : : // adjust depending NF for repeated rows
198 : 0 : sal_Int64 nMax = ( nRow == 1 )? 1 : nRow - 1 ;
199 : 0 : sal_Int64 nActVal = aRepeatHeaderNF.GetValue();
200 : :
201 : 0 : aRepeatHeaderNF.SetMax( nMax );
202 : :
203 : 0 : if( nActVal > nMax )
204 : 0 : aRepeatHeaderNF.SetValue( nMax );
205 : 0 : else if( nActVal < nEnteredValRepeatHeaderNF )
206 : 0 : aRepeatHeaderNF.SetValue( ( nEnteredValRepeatHeaderNF < nMax )? nEnteredValRepeatHeaderNF : nMax );
207 : : }
208 : 0 : return 0;
209 : : }
210 : :
211 : 0 : IMPL_LINK( SwInsTableDlg, AutoFmtHdl, PushButton*, pButton )
212 : : {
213 : 0 : SwAbstractDialogFactory* pFact = swui::GetFactory();
214 : : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
215 : :
216 : 0 : AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton,pShell, DLG_AUTOFMT_TABLE, sal_False, pTAutoFmt );
217 : : OSL_ENSURE(pDlg, "Dialogdiet fail!");
218 : 0 : if( RET_OK == pDlg->Execute())
219 : 0 : pDlg->FillAutoFmtOfIndex( pTAutoFmt );
220 : 0 : delete pDlg;
221 : 0 : return 0;
222 : : }
223 : :
224 : 0 : IMPL_LINK_NOARG(SwInsTableDlg, CheckBoxHdl)
225 : : {
226 : 0 : aRepeatHeaderCB.Enable(aHeaderCB.IsChecked());
227 : 0 : ReapeatHeaderCheckBoxHdl();
228 : :
229 : 0 : return 0;
230 : : }
231 : :
232 : 0 : IMPL_LINK_NOARG(SwInsTableDlg, ReapeatHeaderCheckBoxHdl)
233 : : {
234 : 0 : aRepeatHeaderCombo.Enable(aHeaderCB.IsChecked() && aRepeatHeaderCB.IsChecked());
235 : :
236 : 0 : return 0;
237 : : }
238 : :
239 : 0 : IMPL_LINK_NOARG(SwInsTableDlg, ModifyRepeatHeaderNF_Hdl)
240 : : {
241 : 0 : nEnteredValRepeatHeaderNF = aRepeatHeaderNF.GetValue();
242 : 0 : return 0;
243 : : }
244 : :
245 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|