merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / table / instable.cxx
blob7ba412363f59933456d0dbe3b39445960871e539
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: instable.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
39 #include <vcl/msgbox.hxx>
41 #include "wrtsh.hxx"
42 #include "view.hxx"
43 #include "itabenum.hxx"
44 #include "instable.hxx"
45 #include "tblafmt.hxx"
46 #include "modcfg.hxx"
47 #include "swmodule.hxx"
48 #include <svx/htmlmode.hxx>
49 #include <viewopt.hxx>
51 #include "table.hrc"
52 #include "instable.hrc"
54 #include "swabstdlg.hxx"
56 namespace swui
58 SwAbstractDialogFactory * GetFactory();
61 #define ROW_COL_PROD 16384
63 void SwInsTableDlg::GetValues( String& rName, USHORT& rRow, USHORT& rCol,
64 SwInsertTableOptions& rInsTblOpts, String& rAutoName,
65 SwTableAutoFmt *& prTAFmt )
67 USHORT nInsMode = 0;
68 rName = aNameEdit.GetText();
69 rRow = (USHORT)aRowEdit.GetValue();
70 rCol = (USHORT)aColEdit.GetValue();
72 if (aBorderCB.IsChecked())
73 nInsMode |= tabopts::DEFAULT_BORDER;
74 if (aHeaderCB.IsChecked())
75 nInsMode |= tabopts::HEADLINE;
76 if (aRepeatHeaderCB.IsEnabled() && aRepeatHeaderCB.IsChecked())
77 rInsTblOpts.mnRowsToRepeat = USHORT( aRepeatHeaderNF.GetValue() );
78 else
79 rInsTblOpts.mnRowsToRepeat = 0;
80 if (!aDontSplitCB.IsChecked())
81 nInsMode |= tabopts::SPLIT_LAYOUT;
82 if( pTAutoFmt )
84 prTAFmt = new SwTableAutoFmt( *pTAutoFmt );
85 rAutoName = prTAFmt->GetName();
88 rInsTblOpts.mnInsMode = nInsMode;
91 // CTOR / DTOR -----------------------------------------------------------
94 SwInsTableDlg::SwInsTableDlg( SwView& rView )
95 : SfxModalDialog( rView.GetWindow(), SW_RES(DLG_INSERT_TABLE) ),
96 aNameFT (this, SW_RES(FT_NAME)),
97 aNameEdit (this, SW_RES(ED_NAME)),
99 aFL (this, SW_RES(FL_TABLE)),
100 aColLbl (this, SW_RES(FT_COL)),
101 aColEdit (this, SW_RES(ED_COL)),
102 aRowLbl (this, SW_RES(FT_ROW)),
103 aRowEdit (this, SW_RES(ED_ROW)),
105 aOptionsFL (this, SW_RES(FL_OPTIONS)),
106 aHeaderCB (this, SW_RES(CB_HEADER)),
107 aRepeatHeaderCB (this, SW_RES(CB_REPEAT_HEADER)),
108 aRepeatHeaderFT (this, SW_RES(FT_REPEAT_HEADER)),
109 aRepeatHeaderBeforeFT (this),
110 aRepeatHeaderNF (this, SW_RES(NF_REPEAT_HEADER)),
111 aRepeatHeaderAfterFT (this),
112 aRepeatHeaderCombo (this, SW_RES(WIN_REPEAT_HEADER), aRepeatHeaderNF, aRepeatHeaderBeforeFT, aRepeatHeaderAfterFT),
114 aDontSplitCB (this, SW_RES(CB_DONT_SPLIT)),
115 aBorderCB (this, SW_RES(CB_BORDER)),
117 aOkBtn (this, SW_RES(BT_OK)),
118 aCancelBtn (this, SW_RES(BT_CANCEL)),
119 aHelpBtn (this, SW_RES(BT_HELP)),
120 aAutoFmtBtn (this, SW_RES(BT_AUTOFORMAT)),
122 pShell(&rView.GetWrtShell()),
123 pTAutoFmt( 0 ),
124 nEnteredValRepeatHeaderNF( -1 )
126 FreeResource();
127 aNameEdit.SetText(pShell->GetUniqueTblName());
128 aNameEdit.SetModifyHdl(LINK(this, SwInsTableDlg, ModifyName));
129 aColEdit.SetModifyHdl(LINK(this, SwInsTableDlg, ModifyRowCol));
130 aRowEdit.SetModifyHdl(LINK(this, SwInsTableDlg, ModifyRowCol));
132 aRowEdit.SetMax(ROW_COL_PROD/aColEdit.GetValue());
133 aColEdit.SetMax(ROW_COL_PROD/aRowEdit.GetValue());
134 aAutoFmtBtn.SetClickHdl(LINK(this, SwInsTableDlg, AutoFmtHdl));
136 BOOL bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell())&HTMLMODE_ON);
137 const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
139 SwInsertTableOptions aInsOpts = pModOpt->GetInsTblFlags(bHTMLMode);
140 USHORT nInsTblFlags = aInsOpts.mnInsMode;
142 aHeaderCB.Check( 0 != (nInsTblFlags & tabopts::HEADLINE) );
143 aRepeatHeaderCB.Check(aInsOpts.mnRowsToRepeat > 0);
144 if(bHTMLMode)
146 aDontSplitCB.Hide();
147 aBorderCB.SetPosPixel(aDontSplitCB.GetPosPixel());
149 else
151 aDontSplitCB.Check( 0 == (nInsTblFlags & tabopts::SPLIT_LAYOUT) );
153 aBorderCB.Check( 0 != (nInsTblFlags & tabopts::DEFAULT_BORDER) );
155 aRepeatHeaderNF.SetModifyHdl( LINK( this, SwInsTableDlg, ModifyRepeatHeaderNF_Hdl ) );
156 aHeaderCB.SetClickHdl(LINK(this, SwInsTableDlg, CheckBoxHdl));
157 aRepeatHeaderCB.SetClickHdl(LINK(this, SwInsTableDlg, ReapeatHeaderCheckBoxHdl));
158 ReapeatHeaderCheckBoxHdl();
159 CheckBoxHdl();
161 sal_Int64 nMax = aRowEdit.GetValue();
162 if( nMax <= 1 )
163 nMax = 1;
164 else
165 --nMax;
166 aRepeatHeaderNF.SetMax( nMax );
168 aRepeatHeaderCombo.Arrange( aRepeatHeaderFT );
171 SwInsTableDlg::~SwInsTableDlg()
173 delete pTAutoFmt;
176 IMPL_LINK_INLINE_START( SwInsTableDlg, ModifyName, Edit *, pEdit )
178 String sTblName = pEdit->GetText();
179 if(sTblName.Search(' ') != STRING_NOTFOUND)
181 sTblName.EraseAllChars( );
182 pEdit->SetText(sTblName);
185 aOkBtn.Enable(pShell->GetTblStyle( sTblName ) == 0);
186 return 0;
188 IMPL_LINK_INLINE_END( SwInsTableDlg, ModifyName, Edit *, EMPTYARG )
190 /*-----------------15.04.98 11:36-------------------
192 --------------------------------------------------*/
193 IMPL_LINK( SwInsTableDlg, ModifyRowCol, NumericField *, pField )
195 if(pField == &aColEdit)
197 sal_Int64 nCol = aColEdit.GetValue();
198 if(!nCol)
199 nCol = 1;
200 aRowEdit.SetMax(ROW_COL_PROD/nCol);
202 else
204 sal_Int64 nRow = aRowEdit.GetValue();
205 if(!nRow)
206 nRow = 1;
207 aColEdit.SetMax(ROW_COL_PROD/nRow);
209 // adjust depending NF for repeated rows
210 sal_Int64 nMax = ( nRow == 1 )? 1 : nRow - 1 ;
211 sal_Int64 nActVal = aRepeatHeaderNF.GetValue();
213 aRepeatHeaderNF.SetMax( nMax );
215 if( nActVal > nMax )
216 aRepeatHeaderNF.SetValue( nMax );
217 else if( nActVal < nEnteredValRepeatHeaderNF )
218 aRepeatHeaderNF.SetValue( ( nEnteredValRepeatHeaderNF < nMax )? nEnteredValRepeatHeaderNF : nMax );
220 return 0;
223 IMPL_LINK( SwInsTableDlg, AutoFmtHdl, PushButton*, pButton )
225 SwAbstractDialogFactory* pFact = swui::GetFactory();
226 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
228 AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton,pShell, DLG_AUTOFMT_TABLE, FALSE, pTAutoFmt );
229 DBG_ASSERT(pDlg, "Dialogdiet fail!");
230 if( RET_OK == pDlg->Execute())
231 pDlg->FillAutoFmtOfIndex( pTAutoFmt );
232 delete pDlg;
233 return 0;
236 IMPL_LINK(SwInsTableDlg, CheckBoxHdl, CheckBox*, EMPTYARG)
238 aRepeatHeaderCB.Enable(aHeaderCB.IsChecked());
239 ReapeatHeaderCheckBoxHdl();
241 return 0;
244 IMPL_LINK(SwInsTableDlg, ReapeatHeaderCheckBoxHdl, void*, EMPTYARG)
246 aRepeatHeaderCombo.Enable(aHeaderCB.IsChecked() && aRepeatHeaderCB.IsChecked());
248 return 0;
251 IMPL_LINK(SwInsTableDlg, ModifyRepeatHeaderNF_Hdl, void*, EMPTYARG)
253 nEnteredValRepeatHeaderNF = aRepeatHeaderNF.GetValue();
254 return 0;