bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / dlg / custsdlg.cxx
blob75e91aa7918284b03dd0e14b26c34b4e4824fdb3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "custsdlg.hxx"
22 #include "strings.hrc"
23 #include "sdresid.hxx"
25 #include "drawdoc.hxx"
26 #include "sdpage.hxx"
27 #include "cusshow.hxx"
28 #include "sdmod.hxx"
29 #include "customshowlist.hxx"
30 #include <vcl/msgbox.hxx>
31 #include "svtools/treelistentry.hxx"
34 /////////////////////
35 // SdCustomShowDlg //
36 /////////////////////
39 SdCustomShowDlg::SdCustomShowDlg( Window* pWindow,
40 SdDrawDocument& rDrawDoc ) :
41 ModalDialog ( pWindow, "CustomSlideShows", "modules/simpress/ui/customslideshows.ui" ),
42 rDoc ( rDrawDoc ),
43 pCustomShowList ( NULL ),
44 pCustomShow ( NULL ),
45 bModified ( sal_False )
47 get( m_pBtnNew, "new" );
48 get( m_pBtnEdit, "edit" );
49 get( m_pBtnRemove, "delete" );
50 get( m_pBtnCopy, "copy" );
51 get( m_pBtnHelp, "help" );
52 get( m_pBtnStartShow, "startshow" );
53 get( m_pBtnOK, "ok" );
54 get( m_pLbCustomShows, "customshowlist");
55 get( m_pCbxUseCustomShow, "usecustomshows" );
57 m_pLbCustomShows->set_width_request(m_pLbCustomShows->approximate_char_width() * 32);
58 m_pLbCustomShows->SetDropDownLineCount(8);
60 Link aLink( LINK( this, SdCustomShowDlg, ClickButtonHdl ) );
61 m_pBtnNew->SetClickHdl( aLink );
62 m_pBtnEdit->SetClickHdl( aLink );
63 m_pBtnRemove->SetClickHdl( aLink );
64 m_pBtnCopy->SetClickHdl( aLink );
65 m_pCbxUseCustomShow->SetClickHdl( aLink );
66 m_pLbCustomShows->SetSelectHdl( aLink );
68 m_pBtnStartShow->SetClickHdl( LINK( this, SdCustomShowDlg, StartShowHdl ) ); // for test
70 // get CustomShow list of docs
71 pCustomShowList = rDoc.GetCustomShowList();
72 if( pCustomShowList )
74 long nPosToSelect = pCustomShowList->GetCurPos();
75 // fill ListBox with CustomShows
76 for( pCustomShow = pCustomShowList->First();
77 pCustomShow != NULL;
78 pCustomShow = pCustomShowList->Next() )
80 m_pLbCustomShows->InsertEntry( pCustomShow->GetName() );
82 m_pLbCustomShows->SelectEntryPos( (sal_uInt16)nPosToSelect );
83 pCustomShowList->Seek( nPosToSelect );
86 m_pCbxUseCustomShow->Check( pCustomShowList && rDoc.getPresentationSettings().mbCustomShow );
88 CheckState();
91 SdCustomShowDlg::~SdCustomShowDlg()
95 void SdCustomShowDlg::CheckState()
97 sal_uInt16 nPos = m_pLbCustomShows->GetSelectEntryPos();
99 sal_Bool bEnable = nPos != LISTBOX_ENTRY_NOTFOUND;
100 m_pBtnEdit->Enable( bEnable );
101 m_pBtnRemove->Enable( bEnable );
102 m_pBtnCopy->Enable( bEnable );
103 m_pCbxUseCustomShow->Enable( bEnable );
104 m_pBtnStartShow->Enable( true );
106 if( bEnable )
107 pCustomShowList->Seek( nPos );
111 * ButtonHdl()
113 IMPL_LINK( SdCustomShowDlg, ClickButtonHdl, void *, p )
115 // new CustomShow
116 if( p == m_pBtnNew )
118 pCustomShow = NULL;
119 SdDefineCustomShowDlg aDlg( this, rDoc, pCustomShow );
120 if( aDlg.Execute() == RET_OK )
122 if( pCustomShow )
124 if( !pCustomShowList )
125 pCustomShowList = rDoc.GetCustomShowList( sal_True );
127 pCustomShowList->push_back( pCustomShow );
128 pCustomShowList->Last();
129 m_pLbCustomShows->InsertEntry( pCustomShow->GetName() );
130 m_pLbCustomShows->SelectEntry( pCustomShow->GetName() );
133 if( aDlg.IsModified() )
134 bModified = sal_True;
136 else if( pCustomShow )
137 DELETEZ( pCustomShow );
139 // edit CustomShow
140 else if( p == m_pBtnEdit )
142 sal_uInt16 nPos = m_pLbCustomShows->GetSelectEntryPos();
143 if( nPos != LISTBOX_ENTRY_NOTFOUND )
145 DBG_ASSERT( pCustomShowList, "pCustomShowList does not exist" );
146 pCustomShow = (*pCustomShowList)[ nPos ];
147 SdDefineCustomShowDlg aDlg( this, rDoc, pCustomShow );
149 if( aDlg.Execute() == RET_OK )
151 if( pCustomShow )
153 (*pCustomShowList)[nPos] = pCustomShow;
154 pCustomShowList->Seek( nPos );
155 m_pLbCustomShows->RemoveEntry( nPos );
156 m_pLbCustomShows->InsertEntry( pCustomShow->GetName(), nPos );
157 m_pLbCustomShows->SelectEntryPos( nPos );
159 if( aDlg.IsModified() )
160 bModified = sal_True;
164 // delete CustomShow
165 else if( p == m_pBtnRemove )
167 sal_uInt16 nPos = m_pLbCustomShows->GetSelectEntryPos();
168 if( nPos != LISTBOX_ENTRY_NOTFOUND )
170 delete (*pCustomShowList)[nPos];
171 pCustomShowList->erase( pCustomShowList->begin() + nPos );
172 m_pLbCustomShows->RemoveEntry( nPos );
173 m_pLbCustomShows->SelectEntryPos( nPos == 0 ? nPos : nPos - 1 );
174 bModified = sal_True;
177 // copy CustomShow
178 else if( p == m_pBtnCopy )
180 sal_uInt16 nPos = m_pLbCustomShows->GetSelectEntryPos();
181 if( nPos != LISTBOX_ENTRY_NOTFOUND )
183 SdCustomShow* pShow = new SdCustomShow( *(*pCustomShowList)[nPos] );
184 OUString aStr( pShow->GetName() );
185 OUString aStrCopy( SdResId( STR_COPY_CUSTOMSHOW ) );
187 sal_Int32 nStrPos = aStr.indexOf( aStrCopy );
188 sal_Int32 nNum = 1;
189 if( nStrPos < 0 )
191 aStr = aStr + " (" + aStrCopy + OUString::valueOf( nNum ) + ")";
192 nStrPos = aStr.indexOf( aStrCopy );
194 nStrPos = nStrPos + aStrCopy.getLength();
195 // that we do not access into the nirvana (--> endless loop)
196 if( nStrPos >= aStr.getLength() )
198 aStr = aStr + " " + OUString::valueOf( nNum );
201 // check name...
202 sal_Bool bDifferent = sal_False;
203 //long nPosToSelect = pCustomShowList->GetCurPos();
204 while( !bDifferent )
206 bDifferent = sal_True;
207 for( pCustomShow = (SdCustomShow*) pCustomShowList->First();
208 pCustomShow != NULL && bDifferent;
209 pCustomShow = (SdCustomShow*) pCustomShowList->Next() )
211 if( aStr == OUString( pCustomShow->GetName() ) )
212 bDifferent = sal_False;
214 if( !bDifferent )
216 // replace number by a number increased by 1
218 const CharClass* pCharClass = rDoc.GetCharClass();
219 while( pCharClass->isDigit( aStr, nStrPos ) )
220 aStr = aStr.replaceAt( nStrPos, 1, "" );
221 aStr = aStr.copy( 0, nStrPos) + OUString::valueOf( ++nNum ) + aStr.copy( nStrPos);
225 //pCustomShowList->Seek( nPosToSelect );
226 pShow->SetName( aStr );
228 pCustomShowList->push_back( pShow );
229 pCustomShowList->Last();
230 m_pLbCustomShows->InsertEntry( pShow->GetName() );
231 m_pLbCustomShows->SelectEntry( pShow->GetName() );
234 bModified = sal_True;
237 else if( p == m_pLbCustomShows )
239 sal_uInt16 nPos = m_pLbCustomShows->GetSelectEntryPos();
240 if( nPos != LISTBOX_ENTRY_NOTFOUND )
241 pCustomShowList->Seek( nPos );
243 bModified = sal_True;
245 else if( p == m_pCbxUseCustomShow )
247 bModified = sal_True;
250 CheckState();
252 return( 0L );
256 * StartShow-Hdl
258 IMPL_LINK_NOARG(SdCustomShowDlg, StartShowHdl)
260 EndDialog( RET_YES );
262 return 0;
266 * CheckState
268 sal_Bool SdCustomShowDlg::IsCustomShow() const
270 return( m_pCbxUseCustomShow->IsEnabled() && m_pCbxUseCustomShow->IsChecked() );
275 ///////////////////////////
276 // SdDefineCustomShowDlg //
277 ///////////////////////////
280 SdDefineCustomShowDlg::SdDefineCustomShowDlg( Window* pWindow,
281 SdDrawDocument& rDrawDoc, SdCustomShow*& rpCS ) :
282 ModalDialog ( pWindow, "DefineCustomSlideShow", "modules/simpress/ui/definecustomslideshow.ui" ),
283 rDoc ( rDrawDoc ),
284 rpCustomShow ( rpCS ),
285 bModified ( sal_False )
287 get( m_pEdtName, "customname" );
288 get( m_pLbPages, "pages" );
289 get( m_pBtnAdd, "add" );
290 get( m_pBtnRemove, "remove" );
291 get( m_pLbCustomPages, "custompages" );
292 get( m_pBtnOK, "ok" );
293 get( m_pBtnCancel, "cancel" );
294 get( m_pBtnHelp, "help" );
296 Link aLink = LINK( this, SdDefineCustomShowDlg, ClickButtonHdl );
297 m_pBtnAdd->SetClickHdl( aLink );
298 m_pBtnRemove->SetClickHdl( aLink );
299 m_pEdtName->SetModifyHdl( aLink );
300 m_pLbPages->SetSelectHdl( aLink ); // because of status
301 m_pLbCustomPages->SetSelectHdl( aLink ); // because of status
303 m_pBtnOK->SetClickHdl( LINK( this, SdDefineCustomShowDlg, OKHdl ) );
305 // Hack: m_pLbPages used to be MultiLB. We don't have VCL builder equivalent
306 // of it yet. So enable selecting multiple items here
307 m_pLbPages->EnableMultiSelection( sal_True );
309 // shape 'em a bit
310 m_pLbPages->set_width_request(m_pLbPages->approximate_char_width() * 16);
311 m_pLbCustomPages->set_width_request(m_pLbPages->approximate_char_width() * 16);
312 m_pLbPages->SetDropDownLineCount(10);
314 SdPage* pPage;
315 // fill Listbox with page names of Docs
316 for( long nPage = 0L;
317 nPage < rDoc.GetSdPageCount( PK_STANDARD );
318 nPage++ )
320 pPage = rDoc.GetSdPage( (sal_uInt16) nPage, PK_STANDARD );
321 OUString aStr( pPage->GetName() );
322 m_pLbPages->InsertEntry( aStr );
324 //aLbPages.SelectEntryPos( 0 );
326 if( rpCustomShow )
328 aOldName = rpCustomShow->GetName();
329 m_pEdtName->SetText( aOldName );
331 // fill ListBox with CustomShow pages
332 for( SdCustomShow::PageVec::iterator it = rpCustomShow->PagesVector().begin();
333 it != rpCustomShow->PagesVector().end(); ++it )
335 SvTreeListEntry* pEntry = m_pLbCustomPages->InsertEntry( (*it)->GetName() );
336 pEntry->SetUserData( (SdPage*) (*it) );
339 else
341 rpCustomShow = new SdCustomShow( &rDoc );
342 m_pEdtName->SetText( OUString( SdResId( STR_NEW_CUSTOMSHOW ) ) );
343 m_pEdtName->SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
344 rpCustomShow->SetName( m_pEdtName->GetText() );
347 m_pLbCustomPages->SetDragDropMode( SV_DRAGDROP_CTRL_MOVE );
348 m_pLbCustomPages->SetHighlightRange();
350 m_pBtnOK->Enable( sal_False );
351 CheckState();
354 SdDefineCustomShowDlg::~SdDefineCustomShowDlg()
359 * CheckState
361 void SdDefineCustomShowDlg::CheckState()
363 sal_Bool bPages = m_pLbPages->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND;
364 //sal_Bool bCSPages = aLbCustomPages.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND;
365 sal_Bool bCSPages = m_pLbCustomPages->FirstSelected() != NULL;
366 sal_Bool bCount = m_pLbCustomPages->GetEntryCount() > 0;
368 m_pBtnOK->Enable( bCount );
369 m_pBtnAdd->Enable( bPages );
370 m_pBtnRemove->Enable( bCSPages );
374 * ButtonHdl()
376 IMPL_LINK( SdDefineCustomShowDlg, ClickButtonHdl, void *, p )
378 if( p == m_pBtnAdd )
380 sal_uInt16 nCount = m_pLbPages->GetSelectEntryCount();
381 if( nCount > 0 )
383 sal_uLong nPosCP = LIST_APPEND;
384 SvTreeListEntry* pEntry = m_pLbCustomPages->FirstSelected();
385 if( pEntry )
386 nPosCP = m_pLbCustomPages->GetModel()->GetAbsPos( pEntry ) + 1L;
388 for( sal_uInt16 i = 0; i < nCount; i++ )
390 OUString aStr = m_pLbPages->GetSelectEntry( i );
391 pEntry = m_pLbCustomPages->InsertEntry( aStr,
392 0, sal_False, nPosCP );
394 m_pLbCustomPages->Select( pEntry );
395 SdPage* pPage = rDoc.GetSdPage( (sal_uInt16) m_pLbPages->
396 GetSelectEntryPos( i ), PK_STANDARD );
397 pEntry->SetUserData( pPage );
399 if( nPosCP != LIST_APPEND )
400 nPosCP++;
402 bModified = sal_True;
405 else if( p == m_pBtnRemove )
407 //sal_uInt16 nPos = aLbCustomPages.GetSelectEntryPos();
408 SvTreeListEntry* pEntry = m_pLbCustomPages->FirstSelected();
409 if( pEntry )
411 sal_uLong nPos = m_pLbCustomPages->GetModel()->GetAbsPos( pEntry );
412 //rpCustomShow->Remove( nPos );
413 //aLbCustomPages.RemoveEntry( nPos );
414 m_pLbCustomPages->GetModel()->Remove( m_pLbCustomPages->GetModel()->GetEntryAtAbsPos( nPos ) );
416 bModified = sal_True;
419 else if( p == m_pEdtName )
421 //rpCustomShow->SetName( aEdtName.GetText() );
423 bModified = sal_True;
426 CheckState();
428 return( 0L );
432 * Checks the page pointer of the Show since entries can be moved and copied
433 * by TreeLB.
435 void SdDefineCustomShowDlg::CheckCustomShow()
437 sal_Bool bDifferent = sal_False;
438 SvTreeListEntry* pEntry = NULL;
440 // compare count
441 if( rpCustomShow->PagesVector().size() != m_pLbCustomPages->GetEntryCount() )
443 rpCustomShow->PagesVector().clear();
444 bDifferent = sal_True;
447 // compare page pointer
448 if( !bDifferent )
450 SdCustomShow::PageVec::iterator it1 = rpCustomShow->PagesVector().begin();
451 pEntry = m_pLbCustomPages->First();
452 for( ; it1 != rpCustomShow->PagesVector().end() && pEntry != NULL && !bDifferent;
453 ++it1, pEntry = m_pLbCustomPages->Next( pEntry ) )
455 if( *it1 != pEntry->GetUserData() )
457 rpCustomShow->PagesVector().clear();
458 bDifferent = sal_True;
463 // set new page pointer
464 if( bDifferent )
466 SdPage* pPage = NULL;
467 for( pEntry = m_pLbCustomPages->First();
468 pEntry != NULL;
469 pEntry = m_pLbCustomPages->Next( pEntry ) )
471 pPage = (SdPage*) pEntry->GetUserData();
472 rpCustomShow->PagesVector().push_back( pPage );
474 bModified = sal_True;
477 // compare name and set name if necessary
478 String aStr( m_pEdtName->GetText() );
479 if( rpCustomShow->GetName() != aStr )
481 rpCustomShow->SetName( aStr );
482 bModified = sal_True;
487 * OK-Hdl
489 IMPL_LINK_NOARG(SdDefineCustomShowDlg, OKHdl)
491 // check name...
492 sal_Bool bDifferent = sal_True;
493 SdCustomShowList* pCustomShowList = rDoc.GetCustomShowList();
494 if( pCustomShowList )
496 String aName( m_pEdtName->GetText() );
497 SdCustomShow* pCustomShow;
499 long nPosToSelect = pCustomShowList->GetCurPos();
500 for( pCustomShow = pCustomShowList->First();
501 pCustomShow != NULL;
502 pCustomShow = pCustomShowList->Next() )
504 if( aName == pCustomShow->GetName() && aName != aOldName )
505 bDifferent = sal_False;
507 pCustomShowList->Seek( nPosToSelect );
510 if( bDifferent )
512 CheckCustomShow();
514 EndDialog( RET_OK );
516 else
518 WarningBox( this, WinBits( WB_OK ),
519 String( SdResId( STR_WARN_NAME_DUPLICATE ) ) ).Execute();
521 m_pEdtName->GrabFocus();
524 return 0;
527 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */