1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: instable.cxx,v $
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"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
39 #include <vcl/msgbox.hxx>
43 #include "itabenum.hxx"
44 #include "instable.hxx"
45 #include "tblafmt.hxx"
47 #include "swmodule.hxx"
48 #include <svx/htmlmode.hxx>
49 #include <viewopt.hxx>
52 #include "instable.hrc"
54 #include "swabstdlg.hxx"
58 SwAbstractDialogFactory
* GetFactory();
61 #define ROW_COL_PROD 16384
63 void SwInsTableDlg::GetValues( String
& rName
, USHORT
& rRow
, USHORT
& rCol
,
64 SwInsertTableOptions
& rInsTblOpts
, String
& rAutoName
,
65 SwTableAutoFmt
*& prTAFmt
)
68 rName
= aNameEdit
.GetText();
69 rRow
= (USHORT
)aRowEdit
.GetValue();
70 rCol
= (USHORT
)aColEdit
.GetValue();
72 if (aBorderCB
.IsChecked())
73 nInsMode
|= tabopts::DEFAULT_BORDER
;
74 if (aHeaderCB
.IsChecked())
75 nInsMode
|= tabopts::HEADLINE
;
76 if (aRepeatHeaderCB
.IsEnabled() && aRepeatHeaderCB
.IsChecked())
77 rInsTblOpts
.mnRowsToRepeat
= USHORT( aRepeatHeaderNF
.GetValue() );
79 rInsTblOpts
.mnRowsToRepeat
= 0;
80 if (!aDontSplitCB
.IsChecked())
81 nInsMode
|= tabopts::SPLIT_LAYOUT
;
84 prTAFmt
= new SwTableAutoFmt( *pTAutoFmt
);
85 rAutoName
= prTAFmt
->GetName();
88 rInsTblOpts
.mnInsMode
= nInsMode
;
91 // CTOR / DTOR -----------------------------------------------------------
94 SwInsTableDlg::SwInsTableDlg( SwView
& rView
)
95 : SfxModalDialog( rView
.GetWindow(), SW_RES(DLG_INSERT_TABLE
) ),
96 aNameFT (this, SW_RES(FT_NAME
)),
97 aNameEdit (this, SW_RES(ED_NAME
)),
99 aFL (this, SW_RES(FL_TABLE
)),
100 aColLbl (this, SW_RES(FT_COL
)),
101 aColEdit (this, SW_RES(ED_COL
)),
102 aRowLbl (this, SW_RES(FT_ROW
)),
103 aRowEdit (this, SW_RES(ED_ROW
)),
105 aOptionsFL (this, SW_RES(FL_OPTIONS
)),
106 aHeaderCB (this, SW_RES(CB_HEADER
)),
107 aRepeatHeaderCB (this, SW_RES(CB_REPEAT_HEADER
)),
108 aRepeatHeaderFT (this, SW_RES(FT_REPEAT_HEADER
)),
109 aRepeatHeaderBeforeFT (this),
110 aRepeatHeaderNF (this, SW_RES(NF_REPEAT_HEADER
)),
111 aRepeatHeaderAfterFT (this),
112 aRepeatHeaderCombo (this, SW_RES(WIN_REPEAT_HEADER
), aRepeatHeaderNF
, aRepeatHeaderBeforeFT
, aRepeatHeaderAfterFT
),
114 aDontSplitCB (this, SW_RES(CB_DONT_SPLIT
)),
115 aBorderCB (this, SW_RES(CB_BORDER
)),
117 aOkBtn (this, SW_RES(BT_OK
)),
118 aCancelBtn (this, SW_RES(BT_CANCEL
)),
119 aHelpBtn (this, SW_RES(BT_HELP
)),
120 aAutoFmtBtn (this, SW_RES(BT_AUTOFORMAT
)),
122 pShell(&rView
.GetWrtShell()),
124 nEnteredValRepeatHeaderNF( -1 )
127 aNameEdit
.SetText(pShell
->GetUniqueTblName());
128 aNameEdit
.SetModifyHdl(LINK(this, SwInsTableDlg
, ModifyName
));
129 aColEdit
.SetModifyHdl(LINK(this, SwInsTableDlg
, ModifyRowCol
));
130 aRowEdit
.SetModifyHdl(LINK(this, SwInsTableDlg
, ModifyRowCol
));
132 aRowEdit
.SetMax(ROW_COL_PROD
/aColEdit
.GetValue());
133 aColEdit
.SetMax(ROW_COL_PROD
/aRowEdit
.GetValue());
134 aAutoFmtBtn
.SetClickHdl(LINK(this, SwInsTableDlg
, AutoFmtHdl
));
136 BOOL bHTMLMode
= 0 != (::GetHtmlMode(rView
.GetDocShell())&HTMLMODE_ON
);
137 const SwModuleOptions
* pModOpt
= SW_MOD()->GetModuleConfig();
139 SwInsertTableOptions aInsOpts
= pModOpt
->GetInsTblFlags(bHTMLMode
);
140 USHORT nInsTblFlags
= aInsOpts
.mnInsMode
;
142 aHeaderCB
.Check( 0 != (nInsTblFlags
& tabopts::HEADLINE
) );
143 aRepeatHeaderCB
.Check(aInsOpts
.mnRowsToRepeat
> 0);
147 aBorderCB
.SetPosPixel(aDontSplitCB
.GetPosPixel());
151 aDontSplitCB
.Check( 0 == (nInsTblFlags
& tabopts::SPLIT_LAYOUT
) );
153 aBorderCB
.Check( 0 != (nInsTblFlags
& tabopts::DEFAULT_BORDER
) );
155 aRepeatHeaderNF
.SetModifyHdl( LINK( this, SwInsTableDlg
, ModifyRepeatHeaderNF_Hdl
) );
156 aHeaderCB
.SetClickHdl(LINK(this, SwInsTableDlg
, CheckBoxHdl
));
157 aRepeatHeaderCB
.SetClickHdl(LINK(this, SwInsTableDlg
, ReapeatHeaderCheckBoxHdl
));
158 ReapeatHeaderCheckBoxHdl();
161 sal_Int64 nMax
= aRowEdit
.GetValue();
166 aRepeatHeaderNF
.SetMax( nMax
);
168 aRepeatHeaderCombo
.Arrange( aRepeatHeaderFT
);
171 SwInsTableDlg::~SwInsTableDlg()
176 IMPL_LINK_INLINE_START( SwInsTableDlg
, ModifyName
, Edit
*, pEdit
)
178 String sTblName
= pEdit
->GetText();
179 if(sTblName
.Search(' ') != STRING_NOTFOUND
)
181 sTblName
.EraseAllChars( );
182 pEdit
->SetText(sTblName
);
185 aOkBtn
.Enable(pShell
->GetTblStyle( sTblName
) == 0);
188 IMPL_LINK_INLINE_END( SwInsTableDlg
, ModifyName
, Edit
*, EMPTYARG
)
190 /*-----------------15.04.98 11:36-------------------
192 --------------------------------------------------*/
193 IMPL_LINK( SwInsTableDlg
, ModifyRowCol
, NumericField
*, pField
)
195 if(pField
== &aColEdit
)
197 sal_Int64 nCol
= aColEdit
.GetValue();
200 aRowEdit
.SetMax(ROW_COL_PROD
/nCol
);
204 sal_Int64 nRow
= aRowEdit
.GetValue();
207 aColEdit
.SetMax(ROW_COL_PROD
/nRow
);
209 // adjust depending NF for repeated rows
210 sal_Int64 nMax
= ( nRow
== 1 )? 1 : nRow
- 1 ;
211 sal_Int64 nActVal
= aRepeatHeaderNF
.GetValue();
213 aRepeatHeaderNF
.SetMax( nMax
);
216 aRepeatHeaderNF
.SetValue( nMax
);
217 else if( nActVal
< nEnteredValRepeatHeaderNF
)
218 aRepeatHeaderNF
.SetValue( ( nEnteredValRepeatHeaderNF
< nMax
)? nEnteredValRepeatHeaderNF
: nMax
);
223 IMPL_LINK( SwInsTableDlg
, AutoFmtHdl
, PushButton
*, pButton
)
225 SwAbstractDialogFactory
* pFact
= swui::GetFactory();
226 DBG_ASSERT(pFact
, "SwAbstractDialogFactory fail!");
228 AbstractSwAutoFormatDlg
* pDlg
= pFact
->CreateSwAutoFormatDlg(pButton
,pShell
, DLG_AUTOFMT_TABLE
, FALSE
, pTAutoFmt
);
229 DBG_ASSERT(pDlg
, "Dialogdiet fail!");
230 if( RET_OK
== pDlg
->Execute())
231 pDlg
->FillAutoFmtOfIndex( pTAutoFmt
);
236 IMPL_LINK(SwInsTableDlg
, CheckBoxHdl
, CheckBox
*, EMPTYARG
)
238 aRepeatHeaderCB
.Enable(aHeaderCB
.IsChecked());
239 ReapeatHeaderCheckBoxHdl();
244 IMPL_LINK(SwInsTableDlg
, ReapeatHeaderCheckBoxHdl
, void*, EMPTYARG
)
246 aRepeatHeaderCombo
.Enable(aHeaderCB
.IsChecked() && aRepeatHeaderCB
.IsChecked());
251 IMPL_LINK(SwInsTableDlg
, ModifyRepeatHeaderNF_Hdl
, void*, EMPTYARG
)
253 nEnteredValRepeatHeaderNF
= aRepeatHeaderNF
.GetValue();