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