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