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