1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 31 32 #include <sfx2/dispatch.hxx> 33 #include <svl/stritem.hxx> 34 35 #include "tabvwsh.hxx" 36 #include "reffact.hxx" 37 #include "conditio.hxx" 38 #include "stlpool.hxx" 39 #include "uiitems.hxx" 40 #include "document.hxx" 41 #include "scresid.hxx" 42 43 #include "condfrmt.hrc" 44 #include "globstr.hrc" 45 46 #define _CONDFRMT_CXX 47 #include "condfrmt.hxx" 48 #undef _CONDFRMT_CXX 49 50 51 //============================================================================ 52 // class ScConditionalFormat 53 54 //---------------------------------------------------------------------------- 55 // Konstruktor 56 57 ScConditionalFormatDlg::ScConditionalFormatDlg( 58 SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, 59 ScDocument* pCurDoc, 60 const ScConditionalFormat* pCurrentFormat ) 61 : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_CONDFORMAT ), 62 63 aCbxCond1 ( this, ScResId( CBX_COND1 ) ), 64 aLbCond11 ( this, ScResId( LB_COND1_1 ) ), 65 aLbCond12 ( this, ScResId( LB_COND1_2 ) ), 66 aEdtCond11 ( this, this, ScResId( EDT_COND1_1 ) ), 67 aRbCond11 ( this, ScResId( RB_COND1_1 ), &aEdtCond11,this ), 68 aFtCond1And ( this, ScResId( FT_COND1_AND ) ), 69 aEdtCond12 ( this, this, ScResId( EDT_COND1_2 ) ), 70 aRbCond12 ( this, ScResId( RB_COND1_2 ), &aEdtCond12,this ), 71 aFtCond1Template ( this, ScResId( FT_COND1_TEMPLATE ) ), 72 aLbCond1Template ( this, ScResId( LB_COND1_TEMPLATE ) ), 73 aBtnNew1 ( this, ScResId( BTN_COND1_NEW ) ), 74 75 aCbxCond2 ( this, ScResId( CBX_COND2 ) ), 76 aLbCond21 ( this, ScResId( LB_COND2_1 ) ), 77 aLbCond22 ( this, ScResId( LB_COND2_2 ) ), 78 aEdtCond21 ( this, this, ScResId( EDT_COND2_1 ) ), 79 aRbCond21 ( this, ScResId( RB_COND2_1 ), &aEdtCond21,this ), 80 aFtCond2And ( this, ScResId( FT_COND2_AND ) ), 81 aEdtCond22 ( this, this, ScResId( EDT_COND2_2 ) ), 82 aRbCond22 ( this, ScResId( RB_COND2_2 ), &aEdtCond22,this ), 83 aFtCond2Template ( this, ScResId( FT_COND2_TEMPLATE ) ), 84 aLbCond2Template ( this, ScResId( LB_COND2_TEMPLATE ) ), 85 aBtnNew2 ( this, ScResId( BTN_COND2_NEW ) ), 86 87 aCbxCond3 ( this, ScResId( CBX_COND3 ) ), 88 aLbCond31 ( this, ScResId( LB_COND3_1 ) ), 89 aLbCond32 ( this, ScResId( LB_COND3_2 ) ), 90 aEdtCond31 ( this, this, ScResId( EDT_COND3_1 ) ), 91 aRbCond31 ( this, ScResId( RB_COND3_1 ), &aEdtCond31,this ), 92 aFtCond3And ( this, ScResId( FT_COND3_AND ) ), 93 aEdtCond32 ( this, this, ScResId( EDT_COND3_2 ) ), 94 aRbCond32 ( this, ScResId( RB_COND3_2 ), &aEdtCond32,this ), 95 aFtCond3Template ( this, ScResId( FT_COND3_TEMPLATE ) ), 96 aLbCond3Template ( this, ScResId( LB_COND3_TEMPLATE ) ), 97 aBtnNew3 ( this, ScResId( BTN_COND3_NEW ) ), 98 99 aBtnOk ( this, ScResId( BTN_OK ) ), 100 aBtnCancel ( this, ScResId( BTN_CANCEL ) ), 101 aBtnHelp ( this, ScResId( BTN_HELP ) ), 102 aFlSep2 ( this, ScResId( FL_SEP2 ) ), 103 aFlSep1 ( this, ScResId( FL_SEP1 ) ), 104 pEdActive ( NULL ), 105 bDlgLostFocus ( sal_False ), 106 107 pDoc ( pCurDoc ) 108 { 109 Point aPos; 110 String aName; 111 SfxStyleSheetBase* pStyle; 112 113 FreeResource(); 114 115 // Handler setzen 116 aCbxCond1.SetClickHdl ( LINK( this, ScConditionalFormatDlg, ClickCond1Hdl ) ); 117 aLbCond11.SetSelectHdl( LINK( this, ScConditionalFormatDlg, ChangeCond11Hdl ) ); 118 aLbCond12.SetSelectHdl( LINK( this, ScConditionalFormatDlg, ChangeCond12Hdl ) ); 119 120 aCbxCond2.SetClickHdl ( LINK( this, ScConditionalFormatDlg, ClickCond2Hdl ) ); 121 aLbCond21.SetSelectHdl( LINK( this, ScConditionalFormatDlg, ChangeCond21Hdl ) ); 122 aLbCond22.SetSelectHdl( LINK( this, ScConditionalFormatDlg, ChangeCond22Hdl ) ); 123 124 aCbxCond3.SetClickHdl ( LINK( this, ScConditionalFormatDlg, ClickCond3Hdl ) ); 125 aLbCond31.SetSelectHdl( LINK( this, ScConditionalFormatDlg, ChangeCond31Hdl ) ); 126 aLbCond32.SetSelectHdl( LINK( this, ScConditionalFormatDlg, ChangeCond32Hdl ) ); 127 128 aBtnOk.SetClickHdl ( LINK( this, ScConditionalFormatDlg, BtnHdl ) ); 129 //? aBtnCancel.SetClickHdl( LINK( this, ScConditionalFormatDlg, BtnHdl ) ); 130 131 Link aLink = LINK( this, ScConditionalFormatDlg, NewBtnHdl ); 132 aBtnNew1.SetClickHdl( aLink ); 133 aBtnNew2.SetClickHdl( aLink ); 134 aBtnNew3.SetClickHdl( aLink ); 135 136 aLink = LINK( this, ScConditionalFormatDlg, GetFocusHdl ); 137 aEdtCond11.SetGetFocusHdl( aLink ); 138 aEdtCond12.SetGetFocusHdl( aLink ); 139 aEdtCond21.SetGetFocusHdl( aLink ); 140 aEdtCond22.SetGetFocusHdl( aLink ); 141 aEdtCond31.SetGetFocusHdl( aLink ); 142 aEdtCond32.SetGetFocusHdl( aLink ); 143 aRbCond11.SetGetFocusHdl( aLink ); 144 aRbCond12.SetGetFocusHdl( aLink ); 145 aRbCond21.SetGetFocusHdl( aLink ); 146 aRbCond22.SetGetFocusHdl( aLink ); 147 aRbCond31.SetGetFocusHdl( aLink ); 148 aRbCond32.SetGetFocusHdl( aLink ); 149 150 aLink = LINK( this, ScConditionalFormatDlg, LoseFocusHdl ); 151 aEdtCond11.SetLoseFocusHdl( aLink ); 152 aEdtCond12.SetLoseFocusHdl( aLink ); 153 aEdtCond21.SetLoseFocusHdl( aLink ); 154 aEdtCond22.SetLoseFocusHdl( aLink ); 155 aEdtCond31.SetLoseFocusHdl( aLink ); 156 aEdtCond32.SetLoseFocusHdl( aLink ); 157 aRbCond11.SetLoseFocusHdl( aLink ); 158 aRbCond12.SetLoseFocusHdl( aLink ); 159 aRbCond21.SetLoseFocusHdl( aLink ); 160 aRbCond22.SetLoseFocusHdl( aLink ); 161 aRbCond31.SetLoseFocusHdl( aLink ); 162 aRbCond32.SetLoseFocusHdl( aLink ); 163 164 // Condition 1 165 aCond1Pos1 = aLbCond12.GetPosPixel(); // Position Edit ohne Listbox 166 aCond1Pos2 = aEdtCond11.GetPosPixel(); // Position Edit mit Listbox 167 aRBtn1Pos1 = aRbCond11.GetPosPixel(); 168 aRBtn1Pos2 = aRbCond12.GetPosPixel(); 169 aPos = aEdtCond12.GetPosPixel(); 170 aPos.X() += aEdtCond12.GetSizePixel().Width(); // rechter Rand 171 aCond1Size3 = aEdtCond11.GetSizePixel(); 172 aCond1Size2 = Size( aPos.X() - aCond1Pos2.X(), aCond1Size3.Height() ); 173 aCond1Size1 = Size( aPos.X() - aCond1Pos1.X(), aCond1Size3.Height() ); 174 175 aCbxCond1.Check(); 176 aLbCond11.SelectEntryPos( 0 ); 177 aLbCond12.SelectEntryPos( 0 ); 178 179 // Condition 2 180 aCond2Pos1 = aLbCond22.GetPosPixel(); // Position Edit ohne Listbox 181 aCond2Pos2 = aEdtCond21.GetPosPixel(); // Position Edit mit Listbox 182 aRBtn2Pos1 = aRbCond21.GetPosPixel(); 183 aRBtn2Pos2 = aRbCond22.GetPosPixel(); 184 aPos = aEdtCond22.GetPosPixel(); 185 aPos.X() += aEdtCond22.GetSizePixel().Width(); // rechter Rand 186 aCond2Size3 = aEdtCond21.GetSizePixel(); 187 aCond2Size2 = Size( aPos.X() - aCond2Pos2.X(), aCond2Size3.Height() ); 188 aCond2Size1 = Size( aPos.X() - aCond2Pos1.X(), aCond2Size3.Height() ); 189 190 aCbxCond2.Check( sal_False ); 191 aLbCond21.SelectEntryPos( 0 ); 192 aLbCond22.SelectEntryPos( 0 ); 193 194 // Condition 3 195 aCond3Pos1 = aLbCond32.GetPosPixel(); // Position Edit ohne Listbox 196 aCond3Pos2 = aEdtCond31.GetPosPixel(); // Position Edit mit Listbox 197 aRBtn3Pos1 = aRbCond31.GetPosPixel(); 198 aRBtn3Pos2 = aRbCond32.GetPosPixel(); 199 aPos = aEdtCond32.GetPosPixel(); 200 aPos.X() += aEdtCond32.GetSizePixel().Width(); // rechter Rand 201 aCond3Size3 = aEdtCond31.GetSizePixel(); 202 aCond3Size2 = Size( aPos.X() - aCond3Pos2.X(), aCond3Size3.Height() ); 203 aCond3Size1 = Size( aPos.X() - aCond3Pos1.X(), aCond3Size3.Height() ); 204 205 aCbxCond3.Check( sal_False ); 206 aLbCond31.SelectEntryPos( 0 ); 207 aLbCond32.SelectEntryPos( 0 ); 208 209 // Vorlagen aus pDoc holen 210 SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA ); 211 for ( pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() ) 212 { 213 aName = pStyle->GetName(); 214 aLbCond1Template.InsertEntry( aName ); 215 aLbCond2Template.InsertEntry( aName ); 216 aLbCond3Template.InsertEntry( aName ); 217 } 218 219 // Vorlagen eintragen 220 //! pStyle = pDoc->GetSelectionStyle( /* ??? const ScMarkData& rMark ??? */ ); 221 pStyle = NULL; //! 222 if (pStyle) 223 aName = pStyle->GetName(); 224 else 225 aName = ScGlobal::GetRscString(STR_STYLENAME_STANDARD); 226 aLbCond1Template.SelectEntry( aName ); 227 aLbCond2Template.SelectEntry( aName ); 228 aLbCond3Template.SelectEntry( aName ); 229 230 ScAddress aCurPos; 231 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); 232 if (pViewShell) 233 { 234 ScViewData* pData = pViewShell->GetViewData(); 235 aCurPos = ScAddress( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() ); 236 } 237 238 // Inhalt aus ConditionalFormat holen 239 if ( pCurrentFormat ) 240 { 241 const ScCondFormatEntry* pEntry; 242 if ( pCurrentFormat->Count() > 0 ) 243 { 244 pEntry= pCurrentFormat->GetEntry( 0 ); 245 aEdtCond11.SetText( pEntry->GetExpression( aCurPos, 0 ) ); 246 aLbCond1Template.SelectEntry( pEntry->GetStyle() ); 247 248 ScConditionMode eMode = pEntry->GetOperation(); 249 if ( eMode == SC_COND_DIRECT ) // via Formel 250 { 251 aLbCond11.SelectEntryPos( 1 ); 252 ChangeCond11Hdl( NULL ); 253 } 254 else if ( eMode == SC_COND_NONE ) // ??? 255 ; 256 else // via Werte 257 { 258 aLbCond12.SelectEntryPos( sal::static_int_cast<sal_uInt16>( eMode ) ); 259 if ( ( eMode == SC_COND_BETWEEN ) || ( eMode == SC_COND_NOTBETWEEN ) ) 260 aEdtCond12.SetText( pEntry->GetExpression( aCurPos, 1 ) ); 261 } 262 } 263 264 265 if ( pCurrentFormat->Count() > 1 ) 266 { 267 aCbxCond2.Check( sal_True ); 268 pEntry= pCurrentFormat->GetEntry( 1 ); 269 aEdtCond21.SetText( pEntry->GetExpression( aCurPos, 0 ) ); 270 aLbCond2Template.SelectEntry( pEntry->GetStyle() ); 271 272 ScConditionMode eMode = pEntry->GetOperation(); 273 if ( eMode == SC_COND_DIRECT ) // via Formel 274 { 275 aLbCond21.SelectEntryPos( 1 ); 276 ChangeCond21Hdl( NULL ); 277 } 278 else if ( eMode == SC_COND_NONE ) // ??? 279 ; 280 else // via Werte 281 { 282 aLbCond22.SelectEntryPos( sal::static_int_cast<sal_uInt16>( eMode ) ); 283 if ( ( eMode == SC_COND_BETWEEN ) || ( eMode == SC_COND_NOTBETWEEN ) ) 284 aEdtCond22.SetText( pEntry->GetExpression( aCurPos, 1 ) ); 285 } 286 } 287 288 if ( pCurrentFormat->Count() > 2 ) 289 { 290 aCbxCond3.Check( sal_True ); 291 pEntry= pCurrentFormat->GetEntry( 2 ); 292 aEdtCond31.SetText( pEntry->GetExpression( aCurPos, 0 ) ); 293 aLbCond3Template.SelectEntry( pEntry->GetStyle() ); 294 295 ScConditionMode eMode = pEntry->GetOperation(); 296 if ( eMode == SC_COND_DIRECT ) // via Formel 297 { 298 aLbCond31.SelectEntryPos( 1 ); 299 ChangeCond31Hdl( NULL ); 300 } 301 else if ( eMode == SC_COND_NONE ) // ??? 302 ; 303 else // via Werte 304 { 305 aLbCond32.SelectEntryPos( sal::static_int_cast<sal_uInt16>( eMode ) ); 306 if ( ( eMode == SC_COND_BETWEEN ) || ( eMode == SC_COND_NOTBETWEEN ) ) 307 aEdtCond32.SetText( pEntry->GetExpression( aCurPos, 1 ) ); 308 } 309 } 310 } 311 312 ClickCond1Hdl( NULL ); 313 ClickCond2Hdl( NULL ); 314 ClickCond3Hdl( NULL ); 315 316 ChangeCond12Hdl( NULL ); 317 ChangeCond22Hdl( NULL ); 318 ChangeCond32Hdl( NULL ); 319 320 aEdtCond11.GrabFocus(); 321 pEdActive = &aEdtCond11; 322 //@BugID 54702 Enablen/Disablen nur noch in Basisklasse 323 //SFX_APPWINDOW->Enable(); // Ref-Feld hat Focus 324 // SFX_APPWINDOW->Disable(); 325 326 aLbCond11.SetAccessibleRelationLabeledBy( &aCbxCond1 ); 327 aLbCond12.SetAccessibleRelationLabeledBy( &aCbxCond1 ); 328 aEdtCond11.SetAccessibleRelationLabeledBy( &aCbxCond1 ); 329 aRbCond11.SetAccessibleRelationLabeledBy( &aCbxCond1 ); 330 331 aLbCond21.SetAccessibleRelationLabeledBy( &aCbxCond2 ); 332 aLbCond22.SetAccessibleRelationLabeledBy( &aCbxCond2 ); 333 aEdtCond21.SetAccessibleRelationLabeledBy( &aCbxCond2 ); 334 aRbCond21.SetAccessibleRelationLabeledBy( &aCbxCond2 ); 335 336 aLbCond31.SetAccessibleRelationLabeledBy( &aCbxCond3 ); 337 aLbCond32.SetAccessibleRelationLabeledBy( &aCbxCond3 ); 338 aEdtCond31.SetAccessibleRelationLabeledBy( &aCbxCond3 ); 339 aRbCond31.SetAccessibleRelationLabeledBy( &aCbxCond3 ); 340 aLbCond11.SetAccessibleName( ScResId(LABEL_FORMARTTING_CONDITIONS) ); 341 aLbCond12.SetAccessibleName( ScResId(LABEL_CONDITIONS) ); 342 aEdtCond11.SetAccessibleName( ScResId(LABEL_CONDITION_VALUE) ); 343 344 aLbCond21.SetAccessibleName( ScResId(LABEL_FORMARTTING_CONDITIONS) ); 345 aLbCond22.SetAccessibleName( ScResId(LABEL_CONDITIONS) ); 346 aEdtCond21.SetAccessibleName( ScResId(LABEL_CONDITION_VALUE) ); 347 348 aLbCond31.SetAccessibleName( ScResId(LABEL_FORMARTTING_CONDITIONS) ); 349 aLbCond32.SetAccessibleName( ScResId(LABEL_CONDITIONS) ); 350 aEdtCond31.SetAccessibleName( ScResId(LABEL_CONDITION_VALUE) ); 351 } 352 353 354 //---------------------------------------------------------------------------- 355 // Destruktor 356 357 __EXPORT ScConditionalFormatDlg::~ScConditionalFormatDlg() 358 { 359 } 360 361 362 //---------------------------------------------------------------------------- 363 364 void ScConditionalFormatDlg::SetReference( const ScRange& rRef, ScDocument* pDocP ) 365 { 366 if ( pEdActive ) 367 { 368 if ( rRef.aStart != rRef.aEnd ) 369 RefInputStart(pEdActive); 370 371 String aStr; 372 rRef.Format( aStr, SCR_ABS_3D, pDocP, pDocP->GetAddressConvention () ); 373 String aVal( pEdActive->GetText() ); 374 Selection aSel( pEdActive->GetSelection() ); 375 aSel.Justify(); 376 aVal.Erase( (xub_StrLen)aSel.Min(), (xub_StrLen)aSel.Len() ); 377 aVal.Insert( aStr, (xub_StrLen)aSel.Min() ); 378 Selection aNewSel( aSel.Min(), aSel.Min()+aStr.Len() ); 379 pEdActive->SetRefString( aVal ); 380 pEdActive->SetSelection( aNewSel ); 381 // pEdActive->SetModifyFlag(); 382 } 383 } 384 385 //---------------------------------------------------------------------------- 386 387 void ScConditionalFormatDlg::AddRefEntry() 388 { 389 if ( pEdActive ) 390 { 391 String aVal = pEdActive->GetText(); 392 aVal += ';'; 393 pEdActive->SetText(aVal); 394 395 xub_StrLen nLen = aVal.Len(); 396 pEdActive->SetSelection( Selection( nLen, nLen ) ); 397 // pEdActive->SetModifyFlag(); 398 } 399 } 400 401 //---------------------------------------------------------------------------- 402 403 sal_Bool ScConditionalFormatDlg::IsRefInputMode() const 404 { 405 return (pEdActive != NULL); 406 } 407 408 409 //---------------------------------------------------------------------------- 410 411 void ScConditionalFormatDlg::SetActive() 412 { 413 if ( bDlgLostFocus ) 414 { 415 bDlgLostFocus = sal_False; 416 if( pEdActive ) 417 pEdActive->GrabFocus(); 418 } 419 else 420 GrabFocus(); 421 422 RefInputDone(); 423 } 424 425 426 //---------------------------------------------------------------------------- 427 // Holt die ausgewaehlte bedingte Formatierung ab 428 429 void ScConditionalFormatDlg::GetConditionalFormat( ScConditionalFormat& rCndFmt ) 430 { 431 ScConditionMode eOper; 432 String sExpr1; 433 String sExpr2; 434 String sStyle; 435 ScAddress aCurPos; 436 437 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); 438 if (pViewShell) 439 { 440 ScViewData* pData = pViewShell->GetViewData(); 441 aCurPos = ScAddress( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() ); 442 } 443 444 if ( aCbxCond1.IsChecked() ) 445 { 446 if ( aLbCond11.GetSelectEntryPos() == 1 ) // via Formel 447 eOper = SC_COND_DIRECT; 448 else 449 eOper = (ScConditionMode)aLbCond12.GetSelectEntryPos(); 450 sExpr1 = aEdtCond11.GetText(); 451 sExpr2 = aEdtCond12.GetText(); 452 sStyle = aLbCond1Template.GetSelectEntry(); 453 ScCondFormatEntry aNewEntry( eOper, sExpr1, sExpr2, pDoc, aCurPos, sStyle ); 454 rCndFmt.AddEntry( aNewEntry ); 455 } 456 457 if ( aCbxCond2.IsChecked() ) 458 { 459 if ( aLbCond21.GetSelectEntryPos() == 1 ) // via Formel??? 460 eOper = SC_COND_DIRECT; 461 else 462 eOper = (ScConditionMode)aLbCond22.GetSelectEntryPos(); 463 sExpr1 = aEdtCond21.GetText(); 464 sExpr2 = aEdtCond22.GetText(); 465 sStyle = aLbCond2Template.GetSelectEntry(); 466 ScCondFormatEntry aNewEntry( eOper, sExpr1, sExpr2, pDoc, aCurPos, sStyle ); 467 rCndFmt.AddEntry( aNewEntry ); 468 } 469 470 if ( aCbxCond3.IsChecked() ) 471 { 472 if ( aLbCond31.GetSelectEntryPos() == 1 ) // via Formel??? 473 eOper = SC_COND_DIRECT; 474 else 475 eOper = (ScConditionMode)aLbCond32.GetSelectEntryPos(); 476 sExpr1 = aEdtCond31.GetText(); 477 sExpr2 = aEdtCond32.GetText(); 478 sStyle = aLbCond3Template.GetSelectEntry(); 479 ScCondFormatEntry aNewEntry( eOper, sExpr1, sExpr2, pDoc, aCurPos, sStyle ); 480 rCndFmt.AddEntry( aNewEntry ); 481 } 482 } 483 484 485 //---------------------------------------------------------------------------- 486 // Zerstoert den Dialog 487 488 sal_Bool ScConditionalFormatDlg::Close() 489 { 490 return DoClose( ScCondFormatDlgWrapper::GetChildWindowId() ); 491 } 492 493 494 //---------------------------------------------------------------------------- 495 // Handler: 496 497 //---------------------------------------------------------------------------- 498 // Enabled/Disabled Condition1-Controls 499 500 IMPL_LINK( ScConditionalFormatDlg, ClickCond1Hdl, void *, EMPTYARG ) 501 { 502 sal_Bool bChecked = aCbxCond1.IsChecked(); 503 504 aLbCond11.Enable( bChecked ); 505 aLbCond12.Enable( bChecked ); 506 aEdtCond11.Enable( bChecked ); 507 aRbCond11.Enable( bChecked ); 508 aFtCond1And.Enable( bChecked ); 509 aEdtCond12.Enable( bChecked ); 510 aRbCond12.Enable( bChecked ); 511 aFtCond1Template.Enable( bChecked ); 512 aLbCond1Template.Enable( bChecked ); 513 aBtnNew1.Enable( bChecked ); 514 515 return( 0L ); 516 } 517 518 519 //---------------------------------------------------------------------------- 520 // Zellwert/Formel 521 522 IMPL_LINK( ScConditionalFormatDlg, ChangeCond11Hdl, void *, EMPTYARG ) 523 { 524 sal_uInt16 nPos = aLbCond11.GetSelectEntryPos(); 525 526 if( nPos == 0 ) // Zellwert 527 { 528 aLbCond12.Show(); 529 aEdtCond11.SetPosPixel( aCond1Pos2 ); 530 } 531 else // Formel 532 { 533 aLbCond12.Hide(); 534 aFtCond1And.Hide(); 535 aEdtCond12.Hide(); 536 aRbCond12.Hide(); 537 aRbCond11.SetPosPixel( aRBtn1Pos2 ); 538 aEdtCond11.SetPosSizePixel( aCond1Pos1, aCond1Size1 ); 539 } 540 541 ChangeCond12Hdl( NULL ); 542 543 return( 0L ); 544 } 545 546 547 //---------------------------------------------------------------------------- 548 // zwischen, gleich, groesser, ... 549 550 IMPL_LINK( ScConditionalFormatDlg, ChangeCond12Hdl, void *, EMPTYARG ) 551 { 552 if( aLbCond12.IsVisible() ) 553 { 554 sal_uInt16 nPos = aLbCond12.GetSelectEntryPos(); 555 556 if( nPos == 6 || nPos == 7 ) // zwischen, n. zwischen 557 { 558 aEdtCond11.SetSizePixel( aCond1Size3 ); 559 aRbCond11.SetPosPixel( aRBtn1Pos1 ); 560 aFtCond1And.Show(); 561 aEdtCond12.Show(); 562 aRbCond12.Show(); 563 } 564 else // gleich, n. gleich ... 565 { 566 aEdtCond12.Hide(); 567 aRbCond12.Hide(); 568 aFtCond1And.Hide(); 569 aRbCond11.SetPosPixel( aRBtn1Pos2 ); 570 aEdtCond11.SetSizePixel( aCond1Size2 ); 571 } 572 } 573 574 return( 0L ); 575 } 576 577 578 //---------------------------------------------------------------------------- 579 // Enabled/Disabled Condition2-Controls 580 581 IMPL_LINK( ScConditionalFormatDlg, ClickCond2Hdl, void *, EMPTYARG ) 582 { 583 sal_Bool bChecked = aCbxCond2.IsChecked(); 584 585 aLbCond21.Enable( bChecked ); 586 aLbCond22.Enable( bChecked ); 587 aEdtCond21.Enable( bChecked ); 588 aRbCond21.Enable( bChecked ); 589 aFtCond2And.Enable( bChecked ); 590 aEdtCond22.Enable( bChecked ); 591 aRbCond22.Enable( bChecked ); 592 aFtCond2Template.Enable( bChecked ); 593 aLbCond2Template.Enable( bChecked ); 594 aBtnNew2.Enable( bChecked ); 595 596 return( 0L ); 597 } 598 599 600 //---------------------------------------------------------------------------- 601 // Zellwert/Formel 602 603 IMPL_LINK( ScConditionalFormatDlg, ChangeCond21Hdl, void *, EMPTYARG ) 604 { 605 sal_uInt16 nPos = aLbCond21.GetSelectEntryPos(); 606 607 if( nPos == 0 ) // Zellwert 608 { 609 aLbCond22.Show(); 610 aEdtCond21.SetPosPixel( aCond2Pos2 ); 611 } 612 else // Formel 613 { 614 aLbCond22.Hide(); 615 aFtCond2And.Hide(); 616 aEdtCond22.Hide(); 617 aRbCond22.Hide(); 618 aRbCond21.SetPosPixel( aRBtn2Pos2 ); 619 aEdtCond21.SetPosSizePixel( aCond2Pos1, aCond2Size1 ); 620 } 621 622 ChangeCond22Hdl( NULL ); 623 624 return( 0L ); 625 } 626 627 628 //---------------------------------------------------------------------------- 629 // zwischen, gleich, groesser, ... 630 631 IMPL_LINK( ScConditionalFormatDlg, ChangeCond22Hdl, void *, EMPTYARG ) 632 { 633 if( aLbCond22.IsVisible() ) 634 { 635 sal_uInt16 nPos = aLbCond22.GetSelectEntryPos(); 636 637 if( nPos == 6 || nPos == 7 ) // zwischen, n. zwischen 638 { 639 aEdtCond21.SetSizePixel( aCond2Size3 ); 640 aRbCond21.SetPosPixel( aRBtn2Pos1 ); 641 aFtCond2And.Show(); 642 aEdtCond22.Show(); 643 aRbCond22.Show(); 644 } 645 else // gleich, n. gleich ... 646 { 647 aEdtCond22.Hide(); 648 aRbCond22.Hide(); 649 aFtCond2And.Hide(); 650 aRbCond21.SetPosPixel( aRBtn2Pos2 ); 651 aEdtCond21.SetSizePixel( aCond2Size2 ); 652 } 653 } 654 655 return( 0L ); 656 } 657 658 659 //---------------------------------------------------------------------------- 660 // Enabled/Disabled Condition3-Controls 661 662 IMPL_LINK( ScConditionalFormatDlg, ClickCond3Hdl, void *, EMPTYARG ) 663 { 664 sal_Bool bChecked = aCbxCond3.IsChecked(); 665 666 aLbCond31.Enable( bChecked ); 667 aLbCond32.Enable( bChecked ); 668 aEdtCond31.Enable( bChecked ); 669 aRbCond31.Enable( bChecked ); 670 aFtCond3And.Enable( bChecked ); 671 aEdtCond32.Enable( bChecked ); 672 aRbCond32.Enable( bChecked ); 673 aFtCond3Template.Enable( bChecked ); 674 aLbCond3Template.Enable( bChecked ); 675 aBtnNew3.Enable( bChecked ); 676 677 return( 0L ); 678 } 679 680 681 //---------------------------------------------------------------------------- 682 // Zellwert/Formel 683 684 IMPL_LINK( ScConditionalFormatDlg, ChangeCond31Hdl, void *, EMPTYARG ) 685 { 686 sal_uInt16 nPos = aLbCond31.GetSelectEntryPos(); 687 688 if( nPos == 0 ) // Zellwert 689 { 690 aLbCond32.Show(); 691 aEdtCond31.SetPosPixel( aCond3Pos2 ); 692 } 693 else // Formel 694 { 695 aLbCond32.Hide(); 696 aFtCond3And.Hide(); 697 aEdtCond32.Hide(); 698 aRbCond32.Hide(); 699 aRbCond31.SetPosPixel( aRBtn3Pos2 ); 700 aEdtCond31.SetPosSizePixel( aCond3Pos1, aCond3Size1 ); 701 } 702 703 ChangeCond32Hdl( NULL ); 704 705 return( 0L ); 706 } 707 708 709 //---------------------------------------------------------------------------- 710 // zwischen, gleich, groesser, ... 711 712 IMPL_LINK( ScConditionalFormatDlg, ChangeCond32Hdl, void *, EMPTYARG ) 713 { 714 if( aLbCond32.IsVisible() ) 715 { 716 sal_uInt16 nPos = aLbCond32.GetSelectEntryPos(); 717 718 if( nPos == 6 || nPos == 7 ) // zwischen, n. zwischen 719 { 720 aEdtCond31.SetSizePixel( aCond3Size3 ); 721 aRbCond31.SetPosPixel( aRBtn3Pos1 ); 722 aFtCond3And.Show(); 723 aEdtCond32.Show(); 724 aRbCond32.Show(); 725 } 726 else // gleich, n. gleich ... 727 { 728 aEdtCond32.Hide(); 729 aRbCond32.Hide(); 730 aFtCond3And.Hide(); 731 aRbCond31.SetPosPixel( aRBtn3Pos2 ); 732 aEdtCond31.SetSizePixel( aCond3Size2 ); 733 } 734 } 735 736 return( 0L ); 737 } 738 739 740 //---------------------------------------------------------------------------- 741 742 IMPL_LINK( ScConditionalFormatDlg, GetFocusHdl, Control*, pCtrl ) 743 { 744 if( (pCtrl == (Control*)&aEdtCond11) || (pCtrl == (Control*)&aRbCond11) ) 745 pEdActive = &aEdtCond11; 746 else if( (pCtrl == (Control*)&aEdtCond12) || (pCtrl == (Control*)&aRbCond12) ) 747 pEdActive = &aEdtCond12; 748 else if( (pCtrl == (Control*)&aEdtCond21) || (pCtrl == (Control*)&aRbCond21) ) 749 pEdActive = &aEdtCond21; 750 else if( (pCtrl == (Control*)&aEdtCond22) || (pCtrl == (Control*)&aRbCond22) ) 751 pEdActive = &aEdtCond22; 752 else if( (pCtrl == (Control*)&aEdtCond31) || (pCtrl == (Control*)&aRbCond31) ) 753 pEdActive = &aEdtCond31; 754 else if( (pCtrl == (Control*)&aEdtCond32) || (pCtrl == (Control*)&aRbCond32) ) 755 pEdActive = &aEdtCond32; 756 else 757 pEdActive = NULL; 758 759 if( pEdActive ) 760 pEdActive->SetSelection( Selection( 0, SELECTION_MAX ) ); 761 762 return 0; 763 } 764 765 766 //---------------------------------------------------------------------------- 767 768 IMPL_LINK( ScConditionalFormatDlg, LoseFocusHdl, Control*, EMPTYARG ) 769 { 770 bDlgLostFocus = !IsActive(); 771 return 0; 772 } 773 774 775 //---------------------------------------------------------------------------- 776 // [OK], [Cancel] 777 778 IMPL_LINK( ScConditionalFormatDlg, BtnHdl, PushButton*, pBtn ) 779 { 780 if ( pBtn == &aBtnOk ) 781 { 782 ScConditionalFormat aCondFrmt( 0, pDoc ); 783 GetConditionalFormat( aCondFrmt ); 784 ScCondFrmtItem aOutItem( FID_CONDITIONAL_FORMAT, aCondFrmt ); 785 786 SetDispatcherLock( sal_False ); 787 SwitchToDocument(); 788 GetBindings().GetDispatcher()->Execute( FID_CONDITIONAL_FORMAT, 789 SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, 790 &aOutItem, 0L, 0L ); 791 Close(); 792 } 793 else if ( pBtn == &aBtnCancel ) 794 Close(); 795 796 return( 0L ); 797 } 798 799 800 //---------------------------------------------------------------------------- 801 802 IMPL_LINK( ScConditionalFormatDlg, NewBtnHdl, PushButton*, pBtn ) 803 { 804 SfxUInt16Item aFamilyItem( SID_STYLE_FAMILY, SFX_STYLE_FAMILY_PARA ); 805 SfxStringItem aRefItem( SID_STYLE_REFERENCE, ScGlobal::GetRscString(STR_STYLENAME_STANDARD) ); 806 807 // unlock the dispatcher so SID_STYLE_NEW can be executed 808 // (SetDispatcherLock would affect all Calc documents) 809 SfxDispatcher* pDisp = GetBindings().GetDispatcher(); 810 sal_Bool bLocked = pDisp->IsLocked(); 811 if (bLocked) 812 pDisp->Lock(sal_False); 813 814 // Execute the "new style" slot, complete with undo and all necessary updates. 815 // The return value (SfxUInt16Item) is ignored, look for new styles instead. 816 pDisp->Execute( SID_STYLE_NEW, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD | SFX_CALLMODE_MODAL, 817 &aFamilyItem, 818 &aRefItem, 819 0L ); 820 821 if (bLocked) 822 pDisp->Lock(sal_True); 823 824 // Find the new style and add it into the style list boxes 825 String aNewStyle; 826 SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA ); 827 for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() ) 828 { 829 String aName = pStyle->GetName(); 830 if ( aLbCond1Template.GetEntryPos(aName) == LISTBOX_ENTRY_NOTFOUND ) // all lists contain the same entries 831 { 832 aLbCond1Template.InsertEntry( aName ); 833 aLbCond2Template.InsertEntry( aName ); 834 aLbCond3Template.InsertEntry( aName ); 835 // if there are several new styles (from API or a different view), 836 // assume the last one is the result of the dialog 837 aNewStyle = aName; 838 } 839 } 840 841 // select the new style in the list box for which the button was pressed 842 if ( aNewStyle.Len() ) 843 { 844 ListBox* pListBox = &aLbCond1Template; 845 if ( pBtn == &aBtnNew2 ) 846 pListBox = &aLbCond2Template; 847 else if ( pBtn == &aBtnNew3 ) 848 pListBox = &aLbCond3Template; 849 850 pListBox->SelectEntry( aNewStyle ); 851 } 852 853 return 0; 854 } 855 856