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