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