Update ooo320-m1
[ooovba.git] / sw / source / ui / table / convert.cxx
blob8b80758df6c8aba3f89698e3da8176dd7125a042
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: convert.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #ifdef SW_DLLIMPLEMENTATION
36 #undef SW_DLLIMPLEMENTATION
37 #endif
40 #include <vcl/msgbox.hxx>
41 #include <svtools/stritem.hxx>
42 #include <sfx2/viewfrm.hxx>
43 #include <modcfg.hxx>
44 #include <svx/htmlmode.hxx>
45 #include <viewopt.hxx>
46 #include "swmodule.hxx"
47 #include "cmdid.h"
48 #include "convert.hxx"
49 #include "tablemgr.hxx"
50 #include "wrtsh.hxx"
51 #include "view.hxx"
52 #include "tblafmt.hxx"
54 #include "table.hrc"
55 #include "convert.hrc"
56 #include "swabstdlg.hxx"
58 namespace swui
60 SwAbstractDialogFactory * GetFactory();
63 //keep the state of the buttons on runtime
64 static int nSaveButtonState = -1; // 0: tab, 1: semicolon, 2: paragraph, 3: other, -1: not yet used
65 static sal_Bool bIsKeepColumn = sal_True;
66 static sal_Unicode uOther = ',';
68 void SwConvertTableDlg::GetValues( sal_Unicode& rDelim,
69 SwInsertTableOptions& rInsTblOpts,
70 SwTableAutoFmt *& prTAFmt )
72 if( aTabBtn.IsChecked() )
74 //0x0b mustn't be set when re-converting table into text
75 bIsKeepColumn = !aKeepColumn.IsVisible() || aKeepColumn.IsChecked();
76 rDelim = bIsKeepColumn ? 0x09 : 0x0b;
77 nSaveButtonState = 0;
79 else if( aSemiBtn.IsChecked() )
81 rDelim = ';';
82 nSaveButtonState = 1;
84 else if( aOtherBtn.IsChecked() && aOtherEd.GetText().Len() )
86 uOther = aOtherEd.GetText().GetChar( 0 );
87 rDelim = uOther;
88 nSaveButtonState = 3;
90 else
92 nSaveButtonState = 2;
93 rDelim = cParaDelim;
94 if(aOtherBtn.IsChecked())
96 nSaveButtonState = 3;
97 uOther = 0;
102 USHORT nInsMode = 0;
103 if (aBorderCB.IsChecked())
104 nInsMode |= tabopts::DEFAULT_BORDER;
105 if (aHeaderCB.IsChecked())
106 nInsMode |= tabopts::HEADLINE;
107 if (aRepeatHeaderCB.IsEnabled() && aRepeatHeaderCB.IsChecked())
108 rInsTblOpts.mnRowsToRepeat = USHORT( aRepeatHeaderNF.GetValue() );
109 else
110 rInsTblOpts.mnRowsToRepeat = 0;
111 if (!aDontSplitCB.IsChecked())
112 nInsMode |= tabopts::SPLIT_LAYOUT;
114 if( pTAutoFmt )
115 prTAFmt = new SwTableAutoFmt( *pTAutoFmt );
117 rInsTblOpts.mnInsMode = nInsMode;
121 SwConvertTableDlg::SwConvertTableDlg( SwView& rView, bool bToTable )
123 : SfxModalDialog( &rView.GetViewFrame()->GetWindow(), SW_RES(DLG_CONV_TEXT_TABLE)),
124 #ifdef MSC
125 #pragma warning (disable : 4355)
126 #endif
127 aTabBtn (this, SW_RES(CB_TAB)),
128 aSemiBtn (this, SW_RES(CB_SEMI)),
129 aParaBtn (this, SW_RES(CB_PARA)),
130 aOtherBtn (this, SW_RES(RB_OTHER)),
131 aOtherEd (this, SW_RES(ED_OTHER)),
132 aKeepColumn (this, SW_RES(CB_KEEPCOLUMN)),
133 aDelimFL (this, SW_RES(FL_DELIM)),
135 aHeaderCB (this, SW_RES(CB_HEADER)),
136 aRepeatHeaderCB (this, SW_RES(CB_REPEAT_HEADER)),
138 aRepeatHeaderFT (this, SW_RES(FT_REPEAT_HEADER)),
139 aRepeatHeaderBeforeFT (this),
140 aRepeatHeaderNF (this, SW_RES(NF_REPEAT_HEADER)),
141 aRepeatHeaderAfterFT (this),
142 aRepeatHeaderCombo (this, SW_RES(WIN_REPEAT_HEADER), aRepeatHeaderNF, aRepeatHeaderBeforeFT, aRepeatHeaderAfterFT),
144 aOptionsFL (this, SW_RES(FL_OPTIONS)),
145 aDontSplitCB (this, SW_RES(CB_DONT_SPLIT)),
146 aBorderCB (this, SW_RES(CB_BORDER)),
147 aAutoFmtBtn(this,SW_RES(BT_AUTOFORMAT)),
149 aOkBtn(this,SW_RES(BT_OK)),
150 aCancelBtn(this,SW_RES(BT_CANCEL)),
151 aHelpBtn(this, SW_RES(BT_HELP)),
152 #ifdef MSC
153 #pragma warning (default : 4355)
154 #endif
155 sConvertTextTable(SW_RES(STR_CONVERT_TEXT_TABLE)),
156 pTAutoFmt( 0 ),
157 pShell( &rView.GetWrtShell() )
159 FreeResource();
160 if(nSaveButtonState > -1)
162 switch (nSaveButtonState)
164 case 0:
165 aTabBtn.Check();
166 aKeepColumn.Check(bIsKeepColumn);
167 break;
168 case 1: aSemiBtn.Check();break;
169 case 2: aParaBtn.Check();break;
170 case 3:
171 aOtherBtn.Check();
172 if(uOther)
173 aOtherEd.SetText(uOther);
174 break;
178 if( bToTable )
180 SetText( sConvertTextTable );
181 aAutoFmtBtn.SetClickHdl(LINK(this, SwConvertTableDlg, AutoFmtHdl));
182 aAutoFmtBtn.Show();
183 aKeepColumn.Show();
184 aKeepColumn.Enable( aTabBtn.IsChecked() );
185 aRepeatHeaderCombo.Arrange( aRepeatHeaderFT );
187 else
189 //Einfuege-Optionen verstecken
190 aHeaderCB .Show(FALSE);
191 aRepeatHeaderCB .Show(FALSE);
192 aDontSplitCB .Show(FALSE);
193 aBorderCB .Show(FALSE);
194 aOptionsFL .Show(FALSE);
195 aRepeatHeaderCombo.Show(FALSE);
197 //Groesse anpassen
198 Size aSize(GetSizePixel());
199 aSize.Height() = 8 + aHelpBtn.GetSizePixel().Height() + aHelpBtn.GetPosPixel().Y();
200 SetOutputSizePixel(aSize);
202 aKeepColumn.SaveValue();
204 Link aLk( LINK(this, SwConvertTableDlg, BtnHdl) );
205 aTabBtn.SetClickHdl( aLk );
206 aSemiBtn.SetClickHdl( aLk );
207 aParaBtn.SetClickHdl( aLk );
208 aOtherBtn.SetClickHdl(aLk );
209 aOtherEd.Enable( aOtherBtn.IsChecked() );
211 const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
213 BOOL bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell())&HTMLMODE_ON);
215 SwInsertTableOptions aInsOpts = pModOpt->GetInsTblFlags(bHTMLMode);
216 USHORT nInsTblFlags = aInsOpts.mnInsMode;
218 aHeaderCB.Check( 0 != (nInsTblFlags & tabopts::HEADLINE) );
219 aRepeatHeaderCB.Check(aInsOpts.mnRowsToRepeat > 0);
220 aDontSplitCB.Check( 0 == (nInsTblFlags & tabopts::SPLIT_LAYOUT));
221 aBorderCB.Check( 0!= (nInsTblFlags & tabopts::DEFAULT_BORDER) );
223 aHeaderCB.SetClickHdl(LINK(this, SwConvertTableDlg, CheckBoxHdl));
224 aRepeatHeaderCB.SetClickHdl(LINK(this, SwConvertTableDlg, ReapeatHeaderCheckBoxHdl));
225 ReapeatHeaderCheckBoxHdl();
226 CheckBoxHdl();
229 SwConvertTableDlg:: ~SwConvertTableDlg()
231 delete pTAutoFmt;
234 IMPL_LINK( SwConvertTableDlg, AutoFmtHdl, PushButton*, pButton )
236 SwAbstractDialogFactory* pFact = swui::GetFactory();
237 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
239 AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton, pShell, DLG_AUTOFMT_TABLE, FALSE, pTAutoFmt);
240 DBG_ASSERT(pDlg, "Dialogdiet fail!");
241 if( RET_OK == pDlg->Execute())
242 pDlg->FillAutoFmtOfIndex( pTAutoFmt );
243 delete pDlg;
244 return 0;
247 IMPL_LINK( SwConvertTableDlg, BtnHdl, Button*, pButton )
249 if( pButton == &aTabBtn )
250 aKeepColumn.SetState( aKeepColumn.GetSavedValue() );
251 else
253 if( aKeepColumn.IsEnabled() )
254 aKeepColumn.SaveValue();
255 aKeepColumn.Check( TRUE );
257 aKeepColumn.Enable( aTabBtn.IsChecked() );
258 aOtherEd.Enable( aOtherBtn.IsChecked() );
259 return 0;
262 /*********************************************************************/
263 /* */
264 /*********************************************************************/
266 IMPL_LINK(SwConvertTableDlg, CheckBoxHdl, CheckBox*, EMPTYARG)
268 aRepeatHeaderCB.Enable(aHeaderCB.IsChecked());
269 ReapeatHeaderCheckBoxHdl();
271 return 0;
274 IMPL_LINK(SwConvertTableDlg, ReapeatHeaderCheckBoxHdl, void*, EMPTYARG)
276 sal_Bool bEnable = aHeaderCB.IsChecked() && aRepeatHeaderCB.IsChecked();
277 aRepeatHeaderBeforeFT.Enable(bEnable);
278 aRepeatHeaderAfterFT.Enable(bEnable);
279 aRepeatHeaderNF.Enable(bEnable);
281 return 0;