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