xref: /trunk/main/sw/source/ui/table/convert.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 
32 #ifdef SW_DLLIMPLEMENTATION
33 #undef SW_DLLIMPLEMENTATION
34 #endif
35 
36 
37 #include <vcl/msgbox.hxx>
38 #include <svl/stritem.hxx>
39 #include <sfx2/viewfrm.hxx>
40 #include <modcfg.hxx>
41 #include <svx/htmlmode.hxx>
42 #include <viewopt.hxx>
43 #include "swmodule.hxx"
44 #include "cmdid.h"
45 #include "convert.hxx"
46 #include "tablemgr.hxx"
47 #include "wrtsh.hxx"
48 #include "view.hxx"
49 #include "tblafmt.hxx"
50 
51 #include "table.hrc"
52 #include "convert.hrc"
53 #include "swabstdlg.hxx"
54 
55 namespace swui
56 {
57 	SwAbstractDialogFactory * GetFactory();
58 }
59 
60 //keep the state of the buttons on runtime
61 static int nSaveButtonState = -1; // 0: tab, 1: semicolon, 2: paragraph, 3: other, -1: not yet used
62 static sal_Bool bIsKeepColumn = sal_True;
63 static sal_Unicode uOther = ',';
64 
65 void SwConvertTableDlg::GetValues(  sal_Unicode& rDelim,
66 									SwInsertTableOptions& rInsTblOpts,
67 									SwTableAutoFmt *& prTAFmt )
68 {
69 	if( aTabBtn.IsChecked() )
70     {
71         //0x0b mustn't be set when re-converting table into text
72         bIsKeepColumn = !aKeepColumn.IsVisible() || aKeepColumn.IsChecked();
73         rDelim = bIsKeepColumn ? 0x09 : 0x0b;
74         nSaveButtonState = 0;
75     }
76 	else if( aSemiBtn.IsChecked() )
77     {
78 		rDelim = ';';
79         nSaveButtonState = 1;
80     }
81     else if( aOtherBtn.IsChecked() && aOtherEd.GetText().Len() )
82     {
83         uOther = aOtherEd.GetText().GetChar( 0 );
84         rDelim = uOther;
85         nSaveButtonState = 3;
86     }
87 	else
88     {
89         nSaveButtonState = 2;
90         rDelim = cParaDelim;
91         if(aOtherBtn.IsChecked())
92         {
93             nSaveButtonState = 3;
94             uOther = 0;
95         }
96     }
97 
98 
99 	sal_uInt16 nInsMode = 0;
100 	if (aBorderCB.IsChecked())
101         nInsMode |= tabopts::DEFAULT_BORDER;
102 	if (aHeaderCB.IsChecked())
103         nInsMode |= tabopts::HEADLINE;
104 	if (aRepeatHeaderCB.IsEnabled() && aRepeatHeaderCB.IsChecked())
105         rInsTblOpts.mnRowsToRepeat = sal_uInt16( aRepeatHeaderNF.GetValue() );
106 	else
107 		rInsTblOpts.mnRowsToRepeat = 0;
108 	if (!aDontSplitCB.IsChecked())
109         nInsMode |= tabopts::SPLIT_LAYOUT;
110 
111 	if( pTAutoFmt )
112 		prTAFmt = new SwTableAutoFmt( *pTAutoFmt );
113 
114 	rInsTblOpts.mnInsMode = nInsMode;
115 }
116 
117 
118 SwConvertTableDlg::SwConvertTableDlg( SwView& rView, bool bToTable )
119 
120 	: SfxModalDialog( &rView.GetViewFrame()->GetWindow(), SW_RES(DLG_CONV_TEXT_TABLE)),
121 #ifdef MSC
122 #pragma warning (disable : 4355)
123 #endif
124     aTabBtn         (this, SW_RES(CB_TAB)),
125 	aSemiBtn		(this, SW_RES(CB_SEMI)),
126 	aParaBtn		(this, SW_RES(CB_PARA)),
127     aOtherBtn       (this, SW_RES(RB_OTHER)),
128     aOtherEd        (this, SW_RES(ED_OTHER)),
129     aKeepColumn     (this, SW_RES(CB_KEEPCOLUMN)),
130     aDelimFL       (this, SW_RES(FL_DELIM)),
131 
132     aHeaderCB       (this, SW_RES(CB_HEADER)),
133 	aRepeatHeaderCB	(this, SW_RES(CB_REPEAT_HEADER)),
134 
135     aRepeatHeaderFT         (this, SW_RES(FT_REPEAT_HEADER)),
136     aRepeatHeaderBeforeFT   (this),
137     aRepeatHeaderNF         (this, SW_RES(NF_REPEAT_HEADER)),
138     aRepeatHeaderAfterFT    (this),
139     aRepeatHeaderCombo      (this, SW_RES(WIN_REPEAT_HEADER), aRepeatHeaderNF, aRepeatHeaderBeforeFT, aRepeatHeaderAfterFT),
140 
141     aOptionsFL      (this, SW_RES(FL_OPTIONS)),
142 	aDontSplitCB	(this, SW_RES(CB_DONT_SPLIT)),
143 	aBorderCB		(this, SW_RES(CB_BORDER)),
144     aAutoFmtBtn(this,SW_RES(BT_AUTOFORMAT)),
145 
146 	aOkBtn(this,SW_RES(BT_OK)),
147 	aCancelBtn(this,SW_RES(BT_CANCEL)),
148 	aHelpBtn(this, SW_RES(BT_HELP)),
149 #ifdef MSC
150 #pragma warning (default : 4355)
151 #endif
152     sConvertTextTable(SW_RES(STR_CONVERT_TEXT_TABLE)),
153 	pTAutoFmt( 0 ),
154     pShell( &rView.GetWrtShell() )
155 {
156 	aOtherEd.SetAccessibleName(String(SW_RES(STR_SYMBOL)));
157 	aOtherEd.SetAccessibleRelationLabeledBy(&aOtherBtn);
158 	FreeResource();
159     if(nSaveButtonState > -1)
160     {
161         switch (nSaveButtonState)
162         {
163             case 0:
164                 aTabBtn.Check();
165                 aKeepColumn.Check(bIsKeepColumn);
166             break;
167             case 1: aSemiBtn.Check();break;
168             case 2: aParaBtn.Check();break;
169             case 3:
170                 aOtherBtn.Check();
171                 if(uOther)
172                     aOtherEd.SetText(uOther);
173             break;
174         }
175 
176     }
177     if( bToTable )
178 	{
179 		SetText( sConvertTextTable );
180 		aAutoFmtBtn.SetClickHdl(LINK(this, SwConvertTableDlg, AutoFmtHdl));
181 		aAutoFmtBtn.Show();
182 		aKeepColumn.Show();
183 		aKeepColumn.Enable( aTabBtn.IsChecked() );
184         aRepeatHeaderCombo.Arrange( aRepeatHeaderFT );
185 	}
186 	else
187 	{
188 		//Einfuege-Optionen verstecken
189 		aHeaderCB		   .Show(sal_False);
190 		aRepeatHeaderCB	   .Show(sal_False);
191 		aDontSplitCB	   .Show(sal_False);
192 		aBorderCB		   .Show(sal_False);
193         aOptionsFL         .Show(sal_False);
194         aRepeatHeaderCombo.Show(sal_False);
195 
196 		//Groesse anpassen
197         Size aSize(GetSizePixel());
198         aSize.Height() = 8 + aHelpBtn.GetSizePixel().Height() + aHelpBtn.GetPosPixel().Y();
199         SetOutputSizePixel(aSize);
200 	}
201 	aKeepColumn.SaveValue();
202 
203 	Link aLk( LINK(this, SwConvertTableDlg, BtnHdl) );
204 	aTabBtn.SetClickHdl( aLk );
205 	aSemiBtn.SetClickHdl( aLk );
206 	aParaBtn.SetClickHdl( aLk );
207 	aOtherBtn.SetClickHdl(aLk );
208 	aOtherEd.Enable( aOtherBtn.IsChecked() );
209 
210 	const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
211 
212 	sal_Bool bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell())&HTMLMODE_ON);
213 
214 	SwInsertTableOptions aInsOpts = pModOpt->GetInsTblFlags(bHTMLMode);
215 	sal_uInt16 nInsTblFlags = aInsOpts.mnInsMode;
216 
217     aHeaderCB.Check( 0 != (nInsTblFlags & tabopts::HEADLINE) );
218     aRepeatHeaderCB.Check(aInsOpts.mnRowsToRepeat > 0);
219     aDontSplitCB.Check( 0 == (nInsTblFlags & tabopts::SPLIT_LAYOUT));
220     aBorderCB.Check( 0!= (nInsTblFlags & tabopts::DEFAULT_BORDER) );
221 
222 	aHeaderCB.SetClickHdl(LINK(this, SwConvertTableDlg, CheckBoxHdl));
223 	aRepeatHeaderCB.SetClickHdl(LINK(this, SwConvertTableDlg, ReapeatHeaderCheckBoxHdl));
224 	ReapeatHeaderCheckBoxHdl();
225 	CheckBoxHdl();
226 }
227 
228 SwConvertTableDlg::	~SwConvertTableDlg()
229 {
230 	delete pTAutoFmt;
231 }
232 
233 IMPL_LINK( SwConvertTableDlg, AutoFmtHdl, PushButton*, pButton )
234 {
235     SwAbstractDialogFactory* pFact = swui::GetFactory();
236     DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
237 
238     AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton, pShell, DLG_AUTOFMT_TABLE, sal_False, pTAutoFmt);
239     DBG_ASSERT(pDlg, "Dialogdiet fail!");
240     if( RET_OK == pDlg->Execute())
241         pDlg->FillAutoFmtOfIndex( pTAutoFmt );
242     delete pDlg;
243 	return 0;
244 }
245 
246 IMPL_LINK( SwConvertTableDlg, BtnHdl, Button*, pButton )
247 {
248 	if( pButton == &aTabBtn )
249 		aKeepColumn.SetState( aKeepColumn.GetSavedValue() );
250 	else
251 	{
252 		if( aKeepColumn.IsEnabled() )
253 			aKeepColumn.SaveValue();
254 		aKeepColumn.Check( sal_True );
255 	}
256 	aKeepColumn.Enable( aTabBtn.IsChecked() );
257 	aOtherEd.Enable( aOtherBtn.IsChecked() );
258 	return 0;
259 }
260 
261 /*********************************************************************/
262 /*                                                                   */
263 /*********************************************************************/
264 
265 IMPL_LINK(SwConvertTableDlg, CheckBoxHdl, CheckBox*, EMPTYARG)
266 {
267 	aRepeatHeaderCB.Enable(aHeaderCB.IsChecked());
268 	ReapeatHeaderCheckBoxHdl();
269 
270 	return 0;
271 }
272 
273 IMPL_LINK(SwConvertTableDlg, ReapeatHeaderCheckBoxHdl, void*, EMPTYARG)
274 {
275     sal_Bool bEnable = aHeaderCB.IsChecked() && aRepeatHeaderCB.IsChecked();
276     aRepeatHeaderBeforeFT.Enable(bEnable);
277     aRepeatHeaderAfterFT.Enable(bEnable);
278     aRepeatHeaderNF.Enable(bEnable);
279 
280 	return 0;
281 }
282