1*efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*efeef26fSAndrew Rist * distributed with this work for additional information 6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*efeef26fSAndrew Rist * software distributed under the License is distributed on an 15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17*efeef26fSAndrew Rist * specific language governing permissions and limitations 18*efeef26fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*efeef26fSAndrew Rist *************************************************************/ 21*efeef26fSAndrew Rist 22*efeef26fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sw.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION 28cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <vcl/msgbox.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include "wrtsh.hxx" 35cdf0e10cSrcweir #include "view.hxx" 36cdf0e10cSrcweir #include "itabenum.hxx" 37cdf0e10cSrcweir #include "instable.hxx" 38cdf0e10cSrcweir #include "tblafmt.hxx" 39cdf0e10cSrcweir #include "modcfg.hxx" 40cdf0e10cSrcweir #include "swmodule.hxx" 41cdf0e10cSrcweir #include <svx/htmlmode.hxx> 42cdf0e10cSrcweir #include <viewopt.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include "table.hrc" 45cdf0e10cSrcweir #include "instable.hrc" 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include "swabstdlg.hxx" 48cdf0e10cSrcweir 49cdf0e10cSrcweir namespace swui 50cdf0e10cSrcweir { 51cdf0e10cSrcweir SwAbstractDialogFactory * GetFactory(); 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir #define ROW_COL_PROD 16384 55cdf0e10cSrcweir 56cdf0e10cSrcweir void SwInsTableDlg::GetValues( String& rName, sal_uInt16& rRow, sal_uInt16& rCol, 57cdf0e10cSrcweir SwInsertTableOptions& rInsTblOpts, String& rAutoName, 58cdf0e10cSrcweir SwTableAutoFmt *& prTAFmt ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir sal_uInt16 nInsMode = 0; 61cdf0e10cSrcweir rName = aNameEdit.GetText(); 62cdf0e10cSrcweir rRow = (sal_uInt16)aRowEdit.GetValue(); 63cdf0e10cSrcweir rCol = (sal_uInt16)aColEdit.GetValue(); 64cdf0e10cSrcweir 65cdf0e10cSrcweir if (aBorderCB.IsChecked()) 66cdf0e10cSrcweir nInsMode |= tabopts::DEFAULT_BORDER; 67cdf0e10cSrcweir if (aHeaderCB.IsChecked()) 68cdf0e10cSrcweir nInsMode |= tabopts::HEADLINE; 69cdf0e10cSrcweir if (aRepeatHeaderCB.IsEnabled() && aRepeatHeaderCB.IsChecked()) 70cdf0e10cSrcweir rInsTblOpts.mnRowsToRepeat = sal_uInt16( aRepeatHeaderNF.GetValue() ); 71cdf0e10cSrcweir else 72cdf0e10cSrcweir rInsTblOpts.mnRowsToRepeat = 0; 73cdf0e10cSrcweir if (!aDontSplitCB.IsChecked()) 74cdf0e10cSrcweir nInsMode |= tabopts::SPLIT_LAYOUT; 75cdf0e10cSrcweir if( pTAutoFmt ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir prTAFmt = new SwTableAutoFmt( *pTAutoFmt ); 78cdf0e10cSrcweir rAutoName = prTAFmt->GetName(); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir rInsTblOpts.mnInsMode = nInsMode; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir // CTOR / DTOR ----------------------------------------------------------- 85cdf0e10cSrcweir 86cdf0e10cSrcweir 87cdf0e10cSrcweir SwInsTableDlg::SwInsTableDlg( SwView& rView ) 88cdf0e10cSrcweir : SfxModalDialog( rView.GetWindow(), SW_RES(DLG_INSERT_TABLE) ), 89cdf0e10cSrcweir aNameFT (this, SW_RES(FT_NAME)), 90cdf0e10cSrcweir aNameEdit (this, SW_RES(ED_NAME)), 91cdf0e10cSrcweir 92cdf0e10cSrcweir aFL (this, SW_RES(FL_TABLE)), 93cdf0e10cSrcweir aColLbl (this, SW_RES(FT_COL)), 94cdf0e10cSrcweir aColEdit (this, SW_RES(ED_COL)), 95cdf0e10cSrcweir aRowLbl (this, SW_RES(FT_ROW)), 96cdf0e10cSrcweir aRowEdit (this, SW_RES(ED_ROW)), 97cdf0e10cSrcweir 98cdf0e10cSrcweir aOptionsFL (this, SW_RES(FL_OPTIONS)), 99cdf0e10cSrcweir aHeaderCB (this, SW_RES(CB_HEADER)), 100cdf0e10cSrcweir aRepeatHeaderCB (this, SW_RES(CB_REPEAT_HEADER)), 101cdf0e10cSrcweir aRepeatHeaderFT (this, SW_RES(FT_REPEAT_HEADER)), 102cdf0e10cSrcweir aRepeatHeaderBeforeFT (this), 103cdf0e10cSrcweir aRepeatHeaderNF (this, SW_RES(NF_REPEAT_HEADER)), 104cdf0e10cSrcweir aRepeatHeaderAfterFT (this), 105cdf0e10cSrcweir aRepeatHeaderCombo (this, SW_RES(WIN_REPEAT_HEADER), aRepeatHeaderNF, aRepeatHeaderBeforeFT, aRepeatHeaderAfterFT), 106cdf0e10cSrcweir 107cdf0e10cSrcweir aDontSplitCB (this, SW_RES(CB_DONT_SPLIT)), 108cdf0e10cSrcweir aBorderCB (this, SW_RES(CB_BORDER)), 109cdf0e10cSrcweir 110cdf0e10cSrcweir aOkBtn (this, SW_RES(BT_OK)), 111cdf0e10cSrcweir aCancelBtn (this, SW_RES(BT_CANCEL)), 112cdf0e10cSrcweir aHelpBtn (this, SW_RES(BT_HELP)), 113cdf0e10cSrcweir aAutoFmtBtn (this, SW_RES(BT_AUTOFORMAT)), 114cdf0e10cSrcweir 115cdf0e10cSrcweir pShell(&rView.GetWrtShell()), 116cdf0e10cSrcweir pTAutoFmt( 0 ), 117cdf0e10cSrcweir nEnteredValRepeatHeaderNF( -1 ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir FreeResource(); 120cdf0e10cSrcweir aNameEdit.SetText(pShell->GetUniqueTblName()); 121cdf0e10cSrcweir aNameEdit.SetModifyHdl(LINK(this, SwInsTableDlg, ModifyName)); 122cdf0e10cSrcweir aColEdit.SetModifyHdl(LINK(this, SwInsTableDlg, ModifyRowCol)); 123cdf0e10cSrcweir aRowEdit.SetModifyHdl(LINK(this, SwInsTableDlg, ModifyRowCol)); 124cdf0e10cSrcweir 125cdf0e10cSrcweir aRowEdit.SetMax(ROW_COL_PROD/aColEdit.GetValue()); 126cdf0e10cSrcweir aColEdit.SetMax(ROW_COL_PROD/aRowEdit.GetValue()); 127cdf0e10cSrcweir aAutoFmtBtn.SetClickHdl(LINK(this, SwInsTableDlg, AutoFmtHdl)); 128cdf0e10cSrcweir 129cdf0e10cSrcweir sal_Bool bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell())&HTMLMODE_ON); 130cdf0e10cSrcweir const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig(); 131cdf0e10cSrcweir 132cdf0e10cSrcweir SwInsertTableOptions aInsOpts = pModOpt->GetInsTblFlags(bHTMLMode); 133cdf0e10cSrcweir sal_uInt16 nInsTblFlags = aInsOpts.mnInsMode; 134cdf0e10cSrcweir 135cdf0e10cSrcweir aHeaderCB.Check( 0 != (nInsTblFlags & tabopts::HEADLINE) ); 136cdf0e10cSrcweir aRepeatHeaderCB.Check(aInsOpts.mnRowsToRepeat > 0); 137cdf0e10cSrcweir if(bHTMLMode) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir aDontSplitCB.Hide(); 140cdf0e10cSrcweir aBorderCB.SetPosPixel(aDontSplitCB.GetPosPixel()); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir else 143cdf0e10cSrcweir { 144cdf0e10cSrcweir aDontSplitCB.Check( 0 == (nInsTblFlags & tabopts::SPLIT_LAYOUT) ); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir aBorderCB.Check( 0 != (nInsTblFlags & tabopts::DEFAULT_BORDER) ); 147cdf0e10cSrcweir 148cdf0e10cSrcweir aRepeatHeaderNF.SetModifyHdl( LINK( this, SwInsTableDlg, ModifyRepeatHeaderNF_Hdl ) ); 149cdf0e10cSrcweir aHeaderCB.SetClickHdl(LINK(this, SwInsTableDlg, CheckBoxHdl)); 150cdf0e10cSrcweir aRepeatHeaderCB.SetClickHdl(LINK(this, SwInsTableDlg, ReapeatHeaderCheckBoxHdl)); 151cdf0e10cSrcweir ReapeatHeaderCheckBoxHdl(); 152cdf0e10cSrcweir CheckBoxHdl(); 153cdf0e10cSrcweir 154cdf0e10cSrcweir sal_Int64 nMax = aRowEdit.GetValue(); 155cdf0e10cSrcweir if( nMax <= 1 ) 156cdf0e10cSrcweir nMax = 1; 157cdf0e10cSrcweir else 158cdf0e10cSrcweir --nMax; 159cdf0e10cSrcweir aRepeatHeaderNF.SetMax( nMax ); 160cdf0e10cSrcweir 161cdf0e10cSrcweir aRepeatHeaderCombo.Arrange( aRepeatHeaderFT ); 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir SwInsTableDlg::~SwInsTableDlg() 165cdf0e10cSrcweir { 166cdf0e10cSrcweir delete pTAutoFmt; 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir IMPL_LINK_INLINE_START( SwInsTableDlg, ModifyName, Edit *, pEdit ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir String sTblName = pEdit->GetText(); 172cdf0e10cSrcweir if(sTblName.Search(' ') != STRING_NOTFOUND) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir sTblName.EraseAllChars( ); 175cdf0e10cSrcweir pEdit->SetText(sTblName); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir aOkBtn.Enable(pShell->GetTblStyle( sTblName ) == 0); 179cdf0e10cSrcweir return 0; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir IMPL_LINK_INLINE_END( SwInsTableDlg, ModifyName, Edit *, EMPTYARG ) 182cdf0e10cSrcweir 183cdf0e10cSrcweir /*-----------------15.04.98 11:36------------------- 184cdf0e10cSrcweir 185cdf0e10cSrcweir --------------------------------------------------*/ 186cdf0e10cSrcweir IMPL_LINK( SwInsTableDlg, ModifyRowCol, NumericField *, pField ) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir if(pField == &aColEdit) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir sal_Int64 nCol = aColEdit.GetValue(); 191cdf0e10cSrcweir if(!nCol) 192cdf0e10cSrcweir nCol = 1; 193cdf0e10cSrcweir aRowEdit.SetMax(ROW_COL_PROD/nCol); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir else 196cdf0e10cSrcweir { 197cdf0e10cSrcweir sal_Int64 nRow = aRowEdit.GetValue(); 198cdf0e10cSrcweir if(!nRow) 199cdf0e10cSrcweir nRow = 1; 200cdf0e10cSrcweir aColEdit.SetMax(ROW_COL_PROD/nRow); 201cdf0e10cSrcweir 202cdf0e10cSrcweir // adjust depending NF for repeated rows 203cdf0e10cSrcweir sal_Int64 nMax = ( nRow == 1 )? 1 : nRow - 1 ; 204cdf0e10cSrcweir sal_Int64 nActVal = aRepeatHeaderNF.GetValue(); 205cdf0e10cSrcweir 206cdf0e10cSrcweir aRepeatHeaderNF.SetMax( nMax ); 207cdf0e10cSrcweir 208cdf0e10cSrcweir if( nActVal > nMax ) 209cdf0e10cSrcweir aRepeatHeaderNF.SetValue( nMax ); 210cdf0e10cSrcweir else if( nActVal < nEnteredValRepeatHeaderNF ) 211cdf0e10cSrcweir aRepeatHeaderNF.SetValue( ( nEnteredValRepeatHeaderNF < nMax )? nEnteredValRepeatHeaderNF : nMax ); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir return 0; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir IMPL_LINK( SwInsTableDlg, AutoFmtHdl, PushButton*, pButton ) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir SwAbstractDialogFactory* pFact = swui::GetFactory(); 219cdf0e10cSrcweir DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!"); 220cdf0e10cSrcweir 221cdf0e10cSrcweir AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton,pShell, DLG_AUTOFMT_TABLE, sal_False, pTAutoFmt ); 222cdf0e10cSrcweir DBG_ASSERT(pDlg, "Dialogdiet fail!"); 223cdf0e10cSrcweir if( RET_OK == pDlg->Execute()) 224cdf0e10cSrcweir pDlg->FillAutoFmtOfIndex( pTAutoFmt ); 225cdf0e10cSrcweir delete pDlg; 226cdf0e10cSrcweir return 0; 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir IMPL_LINK(SwInsTableDlg, CheckBoxHdl, CheckBox*, EMPTYARG) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir aRepeatHeaderCB.Enable(aHeaderCB.IsChecked()); 232cdf0e10cSrcweir ReapeatHeaderCheckBoxHdl(); 233cdf0e10cSrcweir 234cdf0e10cSrcweir return 0; 235cdf0e10cSrcweir } 236cdf0e10cSrcweir 237cdf0e10cSrcweir IMPL_LINK(SwInsTableDlg, ReapeatHeaderCheckBoxHdl, void*, EMPTYARG) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir aRepeatHeaderCombo.Enable(aHeaderCB.IsChecked() && aRepeatHeaderCB.IsChecked()); 240cdf0e10cSrcweir 241cdf0e10cSrcweir return 0; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir IMPL_LINK(SwInsTableDlg, ModifyRepeatHeaderNF_Hdl, void*, EMPTYARG) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir nEnteredValRepeatHeaderNF = aRepeatHeaderNF.GetValue(); 247cdf0e10cSrcweir return 0; 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250