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_sd.hxx" 30 31 #ifdef SD_DLLIMPLEMENTATION 32 #undef SD_DLLIMPLEMENTATION 33 #endif 34 35 #include "custsdlg.hxx" 36 #include "custsdlg.hrc" 37 38 #include "strings.hrc" 39 #include "sdresid.hxx" 40 41 #include "drawdoc.hxx" 42 #include "sdpage.hxx" 43 #include "cusshow.hxx" 44 #include "app.hxx" 45 #include <vcl/msgbox.hxx> 46 47 48 ///////////////////// 49 // SdCustomShowDlg // 50 ///////////////////// 51 52 53 /************************************************************************* 54 |* Konstruktor 55 \************************************************************************/ 56 SdCustomShowDlg::SdCustomShowDlg( Window* pWindow, 57 SdDrawDocument& rDrawDoc ) : 58 ModalDialog ( pWindow, SdResId( DLG_CUSTOMSHOW ) ), 59 60 aLbCustomShows ( this, SdResId( LB_CUSTOMSHOWS ) ), 61 aCbxUseCustomShow( this, SdResId( CBX_USE_CUSTOMSHOW ) ), 62 aBtnNew ( this, SdResId( BTN_NEW ) ), 63 aBtnEdit ( this, SdResId( BTN_EDIT ) ), 64 aBtnRemove ( this, SdResId( BTN_REMOVE ) ), 65 aBtnCopy ( this, SdResId( BTN_COPY ) ), 66 aBtnHelp ( this, SdResId( BTN_HELP ) ), 67 aBtnStartShow ( this, SdResId( BTN_STARTSHOW ) ), 68 aBtnOK ( this, SdResId( BTN_OK ) ), 69 70 rDoc ( rDrawDoc ), 71 pCustomShowList ( NULL ), 72 pCustomShow ( NULL ), 73 bModified ( sal_False ) 74 { 75 FreeResource(); 76 77 Link aLink( LINK( this, SdCustomShowDlg, ClickButtonHdl ) ); 78 aBtnNew.SetClickHdl( aLink ); 79 aBtnEdit.SetClickHdl( aLink ); 80 aBtnRemove.SetClickHdl( aLink ); 81 aBtnCopy.SetClickHdl( aLink ); 82 aCbxUseCustomShow.SetClickHdl( aLink ); 83 aLbCustomShows.SetSelectHdl( aLink ); 84 85 aBtnStartShow.SetClickHdl( LINK( this, SdCustomShowDlg, StartShowHdl ) ); // Testweise 86 87 // CustomShow-Liste des Docs abrufen 88 pCustomShowList = rDoc.GetCustomShowList(); 89 if( pCustomShowList ) 90 { 91 long nPosToSelect = pCustomShowList->GetCurPos(); 92 // ListBox mit CustomShows fuellen 93 for( pCustomShow = (SdCustomShow*) pCustomShowList->First(); 94 pCustomShow != NULL; 95 pCustomShow = (SdCustomShow*) pCustomShowList->Next() ) 96 { 97 aLbCustomShows.InsertEntry( pCustomShow->GetName() ); 98 } 99 aLbCustomShows.SelectEntryPos( (sal_uInt16)nPosToSelect ); 100 pCustomShowList->Seek( nPosToSelect ); 101 } 102 103 aCbxUseCustomShow.Check( pCustomShowList && rDoc.getPresentationSettings().mbCustomShow ); 104 105 CheckState(); 106 } 107 108 /************************************************************************* 109 |* Dtor 110 \************************************************************************/ 111 SdCustomShowDlg::~SdCustomShowDlg() 112 { 113 } 114 115 /************************************************************************* 116 |* CheckState 117 \************************************************************************/ 118 void SdCustomShowDlg::CheckState() 119 { 120 sal_uInt16 nPos = aLbCustomShows.GetSelectEntryPos(); 121 122 sal_Bool bEnable = nPos != LISTBOX_ENTRY_NOTFOUND; 123 aBtnEdit.Enable( bEnable ); 124 aBtnRemove.Enable( bEnable ); 125 aBtnCopy.Enable( bEnable ); 126 aCbxUseCustomShow.Enable( bEnable ); 127 aBtnStartShow.Enable( true ); 128 129 if( bEnable ) 130 pCustomShowList->Seek( nPos ); 131 } 132 133 /************************************************************************* 134 |* ButtonHdl() 135 \************************************************************************/ 136 IMPL_LINK( SdCustomShowDlg, ClickButtonHdl, void *, p ) 137 { 138 // Neue CustomShow 139 if( p == &aBtnNew ) 140 { 141 pCustomShow = NULL; 142 SdDefineCustomShowDlg aDlg( this, rDoc, pCustomShow ); 143 if( aDlg.Execute() == RET_OK ) 144 { 145 if( pCustomShow ) 146 { 147 if( !pCustomShowList ) 148 pCustomShowList = rDoc.GetCustomShowList( sal_True ); 149 150 pCustomShowList->Insert( pCustomShow, LIST_APPEND ); 151 pCustomShowList->Last(); 152 aLbCustomShows.InsertEntry( pCustomShow->GetName() ); 153 aLbCustomShows.SelectEntry( pCustomShow->GetName() ); 154 } 155 156 if( aDlg.IsModified() ) 157 bModified = sal_True; 158 } 159 else if( pCustomShow ) 160 DELETEZ( pCustomShow ); 161 } 162 // CustomShow bearbeiten 163 else if( p == &aBtnEdit ) 164 { 165 sal_uInt16 nPos = aLbCustomShows.GetSelectEntryPos(); 166 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 167 { 168 DBG_ASSERT( pCustomShowList, "pCustomShowList existiert nicht" ); 169 pCustomShow = (SdCustomShow*) pCustomShowList->GetObject( nPos ); 170 SdDefineCustomShowDlg aDlg( this, rDoc, pCustomShow ); 171 172 if( aDlg.Execute() == RET_OK ) 173 { 174 if( pCustomShow ) 175 { 176 pCustomShowList->Replace( pCustomShow, nPos ); 177 pCustomShowList->Seek( nPos ); 178 aLbCustomShows.RemoveEntry( nPos ); 179 aLbCustomShows.InsertEntry( pCustomShow->GetName(), nPos ); 180 aLbCustomShows.SelectEntryPos( nPos ); 181 } 182 if( aDlg.IsModified() ) 183 bModified = sal_True; 184 } 185 } 186 } 187 // CustomShow loeschen 188 else if( p == &aBtnRemove ) 189 { 190 sal_uInt16 nPos = aLbCustomShows.GetSelectEntryPos(); 191 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 192 { 193 delete (SdCustomShow*) pCustomShowList->Remove( nPos ); 194 aLbCustomShows.RemoveEntry( nPos ); 195 aLbCustomShows.SelectEntryPos( nPos == 0 ? nPos : nPos - 1 ); 196 bModified = sal_True; 197 } 198 } 199 // CustomShow kopieren 200 else if( p == &aBtnCopy ) 201 { 202 sal_uInt16 nPos = aLbCustomShows.GetSelectEntryPos(); 203 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 204 { 205 SdCustomShow* pShow = new SdCustomShow( *(SdCustomShow*) pCustomShowList->GetObject( nPos ) ); 206 String aStr( pShow->GetName() ); 207 String aStrCopy( SdResId( STR_COPY_CUSTOMSHOW ) ); 208 209 sal_uInt16 nStrPos = aStr.Search( aStrCopy ); 210 sal_uInt16 nNum = 1; 211 if( nStrPos == STRING_NOTFOUND ) 212 { 213 aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " (" ) ); 214 aStr.Append( aStrCopy ); 215 aStr.Append( UniString::CreateFromInt32( nNum ) ); 216 aStr.Append( sal_Unicode(')') ); 217 nStrPos = aStr.Search( aStrCopy ); 218 } 219 nStrPos = nStrPos + (sal_uInt16)aStrCopy.Len(); 220 // Um nicht ins Nirvana zu greifen (--> Endlosschleife) 221 if( nStrPos >= aStr.Len() ) 222 { 223 aStr.Append( sal_Unicode(' ') ); 224 aStr.Append( UniString::CreateFromInt32( nNum ) ); 225 } 226 227 // Name ueberpruefen... 228 sal_Bool bDifferent = sal_False; 229 //long nPosToSelect = pCustomShowList->GetCurPos(); 230 while( !bDifferent ) 231 { 232 bDifferent = sal_True; 233 for( pCustomShow = (SdCustomShow*) pCustomShowList->First(); 234 pCustomShow != NULL && bDifferent; 235 pCustomShow = (SdCustomShow*) pCustomShowList->Next() ) 236 { 237 if( aStr == pCustomShow->GetName() ) 238 bDifferent = sal_False; 239 } 240 if( !bDifferent ) 241 { 242 // Nummer entfernen und durch um 1 erhoehte ersetzen 243 244 const CharClass* pCharClass = rDoc.GetCharClass(); 245 while( pCharClass->isDigit( aStr, nStrPos ) ) 246 aStr.Erase( nStrPos, 1 ); 247 aStr.Insert( UniString::CreateFromInt32( ++nNum ), nStrPos); 248 } 249 250 } 251 //pCustomShowList->Seek( nPosToSelect ); 252 pShow->SetName( aStr ); 253 254 pCustomShowList->Insert( pShow, LIST_APPEND ); 255 pCustomShowList->Last(); 256 aLbCustomShows.InsertEntry( pShow->GetName() ); 257 aLbCustomShows.SelectEntry( pShow->GetName() ); 258 259 260 bModified = sal_True; 261 } 262 } 263 else if( p == &aLbCustomShows ) 264 { 265 sal_uInt16 nPos = aLbCustomShows.GetSelectEntryPos(); 266 if( nPos != LISTBOX_ENTRY_NOTFOUND ) 267 pCustomShowList->Seek( nPos ); 268 269 bModified = sal_True; 270 } 271 else if( p == &aCbxUseCustomShow ) 272 { 273 bModified = sal_True; 274 } 275 276 CheckState(); 277 278 return( 0L ); 279 } 280 281 /************************************************************************* 282 |* StartShow-Hdl 283 \************************************************************************/ 284 IMPL_LINK( SdCustomShowDlg, StartShowHdl, Button *, EMPTYARG ) 285 { 286 EndDialog( RET_YES ); 287 288 return 0; 289 } 290 291 /************************************************************************* 292 |* CheckState 293 \************************************************************************/ 294 sal_Bool SdCustomShowDlg::IsCustomShow() const 295 { 296 return( aCbxUseCustomShow.IsEnabled() && aCbxUseCustomShow.IsChecked() ); 297 } 298 299 300 301 /////////////////////////// 302 // SdDefineCustomShowDlg // 303 /////////////////////////// 304 305 306 /************************************************************************* 307 |* 308 |* Konstruktor 309 |* 310 \************************************************************************/ 311 SdDefineCustomShowDlg::SdDefineCustomShowDlg( Window* pWindow, 312 SdDrawDocument& rDrawDoc, SdCustomShow*& rpCS ) : 313 ModalDialog ( pWindow, SdResId( DLG_DEFINE_CUSTOMSHOW ) ), 314 315 aFtName ( this, SdResId( FT_NAME ) ), 316 aEdtName ( this, SdResId( EDT_NAME ) ), 317 aFtPages ( this, SdResId( FT_PAGES ) ), 318 aLbPages ( this, SdResId( LB_PAGES ) ), 319 aBtnAdd ( this, SdResId( BTN_ADD ) ), 320 aBtnRemove ( this, SdResId( BTN_REMOVE ) ), 321 aFtCustomPages ( this, SdResId( FT_CUSTOM_PAGES ) ), 322 aLbCustomPages ( this, SdResId( LB_CUSTOM_PAGES ) ), 323 aBtnOK ( this, SdResId( BTN_OK ) ), 324 aBtnCancel ( this, SdResId( BTN_CANCEL ) ), 325 aBtnHelp ( this, SdResId( BTN_HELP ) ), 326 327 rDoc ( rDrawDoc ), 328 rpCustomShow ( rpCS ), 329 bModified ( sal_False ) 330 { 331 FreeResource(); 332 333 Link aLink = LINK( this, SdDefineCustomShowDlg, ClickButtonHdl ); 334 aBtnAdd.SetClickHdl( aLink ); 335 aBtnRemove.SetClickHdl( aLink ); 336 aEdtName.SetModifyHdl( aLink ); 337 aLbPages.SetSelectHdl( aLink ); // wegen Status 338 aLbCustomPages.SetSelectHdl( aLink ); // wegen Status 339 340 aBtnOK.SetClickHdl( LINK( this, SdDefineCustomShowDlg, OKHdl ) ); 341 342 SdPage* pPage; 343 // Listbox mit Seitennamen des Docs fuellen 344 for( long nPage = 0L; 345 nPage < rDoc.GetSdPageCount( PK_STANDARD ); 346 nPage++ ) 347 { 348 pPage = rDoc.GetSdPage( (sal_uInt16) nPage, PK_STANDARD ); 349 String aStr( pPage->GetName() ); 350 aLbPages.InsertEntry( aStr ); 351 } 352 //aLbPages.SelectEntryPos( 0 ); 353 354 if( rpCustomShow ) 355 { 356 aOldName = rpCustomShow->GetName(); 357 aEdtName.SetText( aOldName ); 358 359 // ListBox mit CustomShow-Seiten fuellen 360 for( pPage = (SdPage*) rpCustomShow->First(); 361 pPage != NULL; 362 pPage = (SdPage*) rpCustomShow->Next() ) 363 { 364 SvLBoxEntry* pEntry = aLbCustomPages.InsertEntry( pPage->GetName() ); 365 pEntry->SetUserData( pPage ); 366 } 367 } 368 else 369 { 370 rpCustomShow = new SdCustomShow( &rDoc ); 371 aEdtName.SetText( String( SdResId( STR_NEW_CUSTOMSHOW ) ) ); 372 aEdtName.SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) ); 373 rpCustomShow->SetName( aEdtName.GetText() ); 374 } 375 376 aLbCustomPages.SetDragDropMode( SV_DRAGDROP_CTRL_MOVE ); 377 aLbCustomPages.SetHighlightRange(); 378 379 aBtnOK.Enable( sal_False ); 380 CheckState(); 381 } 382 383 /************************************************************************* 384 |* 385 |* Dtor 386 |* 387 \************************************************************************/ 388 SdDefineCustomShowDlg::~SdDefineCustomShowDlg() 389 { 390 } 391 392 /************************************************************************* 393 |* CheckState 394 \************************************************************************/ 395 void SdDefineCustomShowDlg::CheckState() 396 { 397 sal_Bool bPages = aLbPages.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND; 398 //sal_Bool bCSPages = aLbCustomPages.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND; 399 sal_Bool bCSPages = aLbCustomPages.FirstSelected() != NULL; 400 sal_Bool bCount = aLbCustomPages.GetEntryCount() > 0; 401 402 aBtnOK.Enable( bCount ); 403 aBtnAdd.Enable( bPages ); 404 aBtnRemove.Enable( bCSPages ); 405 } 406 407 /************************************************************************* 408 |* ButtonHdl() 409 \************************************************************************/ 410 IMPL_LINK( SdDefineCustomShowDlg, ClickButtonHdl, void *, p ) 411 { 412 if( p == &aBtnAdd ) 413 { 414 sal_uInt16 nCount = aLbPages.GetSelectEntryCount(); 415 if( nCount > 0 ) 416 { 417 sal_uLong nPosCP = LIST_APPEND; 418 SvLBoxEntry* pEntry = aLbCustomPages.FirstSelected(); 419 if( pEntry ) 420 nPosCP = aLbCustomPages.GetModel()->GetAbsPos( pEntry ) + 1L; 421 422 for( sal_uInt16 i = 0; i < nCount; i++ ) 423 { 424 String aStr = aLbPages.GetSelectEntry( i ); 425 pEntry = aLbCustomPages.InsertEntry( aStr, 426 0, sal_False, nPosCP ); 427 428 aLbCustomPages.Select( pEntry ); 429 SdPage* pPage = rDoc.GetSdPage( (sal_uInt16) aLbPages. 430 GetSelectEntryPos( i ), PK_STANDARD ); 431 pEntry->SetUserData( pPage ); 432 433 if( nPosCP != LIST_APPEND ) 434 nPosCP++; 435 } 436 bModified = sal_True; 437 } 438 } 439 else if( p == &aBtnRemove ) 440 { 441 //sal_uInt16 nPos = aLbCustomPages.GetSelectEntryPos(); 442 SvLBoxEntry* pEntry = aLbCustomPages.FirstSelected(); 443 if( pEntry ) 444 { 445 sal_uLong nPos = aLbCustomPages.GetModel()->GetAbsPos( pEntry ); 446 //rpCustomShow->Remove( nPos ); 447 //aLbCustomPages.RemoveEntry( nPos ); 448 aLbCustomPages.GetModel()->Remove( aLbCustomPages.GetModel()->GetEntryAtAbsPos( nPos ) ); 449 450 bModified = sal_True; 451 } 452 } 453 else if( p == &aEdtName ) 454 { 455 //rpCustomShow->SetName( aEdtName.GetText() ); 456 457 bModified = sal_True; 458 } 459 460 CheckState(); 461 462 return( 0L ); 463 } 464 465 /************************************************************************* 466 |* CheckCustomShow(): 467 |* Ueberprueft die Page-Pointer der Show, da die Eintraege ueber die 468 |* TreeLB verschoben und kopiert werden k�nnen 469 \************************************************************************/ 470 void SdDefineCustomShowDlg::CheckCustomShow() 471 { 472 sal_Bool bDifferent = sal_False; 473 SdPage* pPage = NULL; 474 SvLBoxEntry* pEntry = NULL; 475 476 // Anzahl vergleichen 477 if( rpCustomShow->Count() != aLbCustomPages.GetEntryCount() ) 478 { 479 rpCustomShow->Clear(); 480 bDifferent = sal_True; 481 } 482 483 // Seiten-Pointer vergleichen 484 if( !bDifferent ) 485 { 486 for( pPage = (SdPage*) rpCustomShow->First(), pEntry = aLbCustomPages.First(); 487 pPage != NULL && pEntry != NULL && !bDifferent; 488 pPage = (SdPage*) rpCustomShow->Next(), pEntry = aLbCustomPages.Next( pEntry ) ) 489 { 490 if( pPage != pEntry->GetUserData() ) 491 { 492 rpCustomShow->Clear(); 493 bDifferent = sal_True; 494 } 495 } 496 } 497 498 // Seiten-Pointer neu setzen 499 if( bDifferent ) 500 { 501 for( pEntry = aLbCustomPages.First(); 502 pEntry != NULL; 503 pEntry = aLbCustomPages.Next( pEntry ) ) 504 { 505 pPage = (SdPage*) pEntry->GetUserData(); 506 rpCustomShow->Insert( pPage, LIST_APPEND ); 507 } 508 bModified = sal_True; 509 } 510 511 // Name vergleichen und ggfs. setzen 512 String aStr( aEdtName.GetText() ); 513 if( rpCustomShow->GetName() != aStr ) 514 { 515 rpCustomShow->SetName( aStr ); 516 bModified = sal_True; 517 } 518 } 519 520 /************************************************************************* 521 |* OK-Hdl 522 \************************************************************************/ 523 IMPL_LINK( SdDefineCustomShowDlg, OKHdl, Button *, EMPTYARG ) 524 { 525 // Name ueberpruefen... 526 sal_Bool bDifferent = sal_True; 527 List* pCustomShowList = rDoc.GetCustomShowList(); 528 if( pCustomShowList ) 529 { 530 String aName( aEdtName.GetText() ); 531 SdCustomShow* pCustomShow; 532 533 long nPosToSelect = pCustomShowList->GetCurPos(); 534 for( pCustomShow = (SdCustomShow*) pCustomShowList->First(); 535 pCustomShow != NULL; 536 pCustomShow = (SdCustomShow*) pCustomShowList->Next() ) 537 { 538 if( aName == pCustomShow->GetName() && aName != aOldName ) 539 bDifferent = sal_False; 540 } 541 pCustomShowList->Seek( nPosToSelect ); 542 } 543 544 if( bDifferent ) 545 { 546 CheckCustomShow(); 547 548 EndDialog( RET_OK ); 549 } 550 else 551 { 552 WarningBox( this, WinBits( WB_OK ), 553 String( SdResId( STR_WARN_NAME_DUPLICATE ) ) ).Execute(); 554 555 aEdtName.GrabFocus(); 556 } 557 558 return 0; 559 } 560 561