Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "custsdlg.hxx"
21 :
22 : #include "strings.hrc"
23 : #include "sdresid.hxx"
24 :
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"
32 :
33 : // SdCustomShowDlg
34 0 : SdCustomShowDlg::SdCustomShowDlg( vcl::Window* pWindow,
35 : SdDrawDocument& rDrawDoc ) :
36 : ModalDialog ( pWindow, "CustomSlideShows", "modules/simpress/ui/customslideshows.ui" ),
37 : rDoc ( rDrawDoc ),
38 : pCustomShowList ( NULL ),
39 : pCustomShow ( NULL ),
40 0 : bModified ( false )
41 : {
42 0 : get( m_pBtnNew, "new" );
43 0 : get( m_pBtnEdit, "edit" );
44 0 : get( m_pBtnRemove, "delete" );
45 0 : get( m_pBtnCopy, "copy" );
46 0 : get( m_pBtnHelp, "help" );
47 0 : get( m_pBtnStartShow, "startshow" );
48 0 : get( m_pBtnOK, "ok" );
49 0 : get( m_pLbCustomShows, "customshowlist");
50 0 : get( m_pCbxUseCustomShow, "usecustomshows" );
51 :
52 0 : m_pLbCustomShows->set_width_request(m_pLbCustomShows->approximate_char_width() * 32);
53 0 : m_pLbCustomShows->SetDropDownLineCount(8);
54 :
55 0 : Link<> aLink( LINK( this, SdCustomShowDlg, ClickButtonHdl ) );
56 0 : m_pBtnNew->SetClickHdl( aLink );
57 0 : m_pBtnEdit->SetClickHdl( aLink );
58 0 : m_pBtnRemove->SetClickHdl( aLink );
59 0 : m_pBtnCopy->SetClickHdl( aLink );
60 0 : m_pCbxUseCustomShow->SetClickHdl( aLink );
61 0 : m_pLbCustomShows->SetSelectHdl( aLink );
62 :
63 0 : m_pBtnStartShow->SetClickHdl( LINK( this, SdCustomShowDlg, StartShowHdl ) ); // for test
64 :
65 : // get CustomShow list of docs
66 0 : pCustomShowList = rDoc.GetCustomShowList();
67 0 : if( pCustomShowList )
68 : {
69 0 : long nPosToSelect = pCustomShowList->GetCurPos();
70 : // fill ListBox with CustomShows
71 0 : for( pCustomShow = pCustomShowList->First();
72 0 : pCustomShow != NULL;
73 0 : pCustomShow = pCustomShowList->Next() )
74 : {
75 0 : m_pLbCustomShows->InsertEntry( pCustomShow->GetName() );
76 : }
77 0 : m_pLbCustomShows->SelectEntryPos( (sal_Int32)nPosToSelect );
78 0 : pCustomShowList->Seek( nPosToSelect );
79 : }
80 :
81 0 : m_pCbxUseCustomShow->Check( pCustomShowList && rDoc.getPresentationSettings().mbCustomShow );
82 :
83 0 : CheckState();
84 0 : }
85 :
86 0 : SdCustomShowDlg::~SdCustomShowDlg()
87 : {
88 0 : disposeOnce();
89 0 : }
90 :
91 0 : void SdCustomShowDlg::dispose()
92 : {
93 0 : m_pLbCustomShows.clear();
94 0 : m_pCbxUseCustomShow.clear();
95 0 : m_pBtnNew.clear();
96 0 : m_pBtnEdit.clear();
97 0 : m_pBtnRemove.clear();
98 0 : m_pBtnCopy.clear();
99 0 : m_pBtnHelp.clear();
100 0 : m_pBtnStartShow.clear();
101 0 : m_pBtnOK.clear();
102 0 : ModalDialog::dispose();
103 0 : }
104 :
105 0 : void SdCustomShowDlg::CheckState()
106 : {
107 0 : sal_Int32 nPos = m_pLbCustomShows->GetSelectEntryPos();
108 :
109 0 : bool bEnable = nPos != LISTBOX_ENTRY_NOTFOUND;
110 0 : m_pBtnEdit->Enable( bEnable );
111 0 : m_pBtnRemove->Enable( bEnable );
112 0 : m_pBtnCopy->Enable( bEnable );
113 0 : m_pCbxUseCustomShow->Enable( bEnable );
114 0 : m_pBtnStartShow->Enable( true );
115 :
116 0 : if (bEnable && pCustomShowList)
117 0 : pCustomShowList->Seek( nPos );
118 0 : }
119 :
120 : /**
121 : * ButtonHdl()
122 : */
123 0 : IMPL_LINK( SdCustomShowDlg, ClickButtonHdl, void *, p )
124 : {
125 : // new CustomShow
126 0 : if( p == m_pBtnNew )
127 : {
128 0 : pCustomShow = NULL;
129 0 : ScopedVclPtrInstance< SdDefineCustomShowDlg > aDlg( this, rDoc, pCustomShow );
130 0 : if( aDlg->Execute() == RET_OK )
131 : {
132 0 : if( pCustomShow )
133 : {
134 0 : if( !pCustomShowList )
135 0 : pCustomShowList = rDoc.GetCustomShowList( true );
136 :
137 0 : pCustomShowList->push_back( pCustomShow );
138 0 : pCustomShowList->Last();
139 0 : m_pLbCustomShows->InsertEntry( pCustomShow->GetName() );
140 0 : m_pLbCustomShows->SelectEntry( pCustomShow->GetName() );
141 : }
142 :
143 0 : if( aDlg->IsModified() )
144 0 : bModified = true;
145 : }
146 0 : else if( pCustomShow )
147 0 : DELETEZ( pCustomShow );
148 : }
149 : // edit CustomShow
150 0 : else if( p == m_pBtnEdit )
151 : {
152 0 : sal_Int32 nPos = m_pLbCustomShows->GetSelectEntryPos();
153 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
154 : {
155 : DBG_ASSERT( pCustomShowList, "pCustomShowList does not exist" );
156 0 : pCustomShow = (*pCustomShowList)[ nPos ];
157 0 : ScopedVclPtrInstance< SdDefineCustomShowDlg > aDlg( this, rDoc, pCustomShow );
158 :
159 0 : if( aDlg->Execute() == RET_OK )
160 : {
161 0 : if( pCustomShow )
162 : {
163 0 : (*pCustomShowList)[nPos] = pCustomShow;
164 0 : pCustomShowList->Seek( nPos );
165 0 : m_pLbCustomShows->RemoveEntry( nPos );
166 0 : m_pLbCustomShows->InsertEntry( pCustomShow->GetName(), nPos );
167 0 : m_pLbCustomShows->SelectEntryPos( nPos );
168 : }
169 0 : if( aDlg->IsModified() )
170 0 : bModified = true;
171 0 : }
172 : }
173 : }
174 : // delete CustomShow
175 0 : else if( p == m_pBtnRemove )
176 : {
177 0 : sal_Int32 nPos = m_pLbCustomShows->GetSelectEntryPos();
178 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
179 : {
180 0 : delete (*pCustomShowList)[nPos];
181 0 : pCustomShowList->erase( pCustomShowList->begin() + nPos );
182 0 : m_pLbCustomShows->RemoveEntry( nPos );
183 0 : m_pLbCustomShows->SelectEntryPos( nPos == 0 ? nPos : nPos - 1 );
184 0 : bModified = true;
185 : }
186 : }
187 : // copy CustomShow
188 0 : else if( p == m_pBtnCopy )
189 : {
190 0 : sal_Int32 nPos = m_pLbCustomShows->GetSelectEntryPos();
191 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
192 : {
193 0 : SdCustomShow* pShow = new SdCustomShow( *(*pCustomShowList)[nPos] );
194 0 : OUString aStr( pShow->GetName() );
195 0 : OUString aStrCopy( SdResId( STR_COPY_CUSTOMSHOW ) );
196 :
197 0 : sal_Int32 nStrPos = aStr.indexOf( aStrCopy );
198 0 : sal_Int32 nNum = 1;
199 0 : if( nStrPos < 0 )
200 : {
201 0 : aStr = aStr + " (" + aStrCopy + OUString::number( nNum ) + ")";
202 0 : nStrPos = aStr.indexOf( aStrCopy );
203 : }
204 0 : nStrPos = nStrPos + aStrCopy.getLength();
205 : // that we do not access into the nirvana (--> endless loop)
206 0 : if( nStrPos >= aStr.getLength() )
207 : {
208 0 : aStr = aStr + " " + OUString::number( nNum );
209 : }
210 :
211 : // check name...
212 0 : bool bDifferent = false;
213 : //long nPosToSelect = pCustomShowList->GetCurPos();
214 0 : while( !bDifferent )
215 : {
216 0 : bDifferent = true;
217 0 : for( pCustomShow = pCustomShowList->First();
218 0 : pCustomShow != NULL && bDifferent;
219 0 : pCustomShow = pCustomShowList->Next() )
220 : {
221 0 : if( aStr == pCustomShow->GetName() )
222 0 : bDifferent = false;
223 : }
224 0 : if( !bDifferent )
225 : {
226 : // replace number by a number increased by 1
227 :
228 0 : const CharClass* pCharClass = rDoc.GetCharClass();
229 0 : while( pCharClass->isDigit( aStr, nStrPos ) )
230 0 : aStr = aStr.replaceAt( nStrPos, 1, "" );
231 0 : aStr = aStr.copy( 0, nStrPos) + OUString::number( ++nNum ) + aStr.copy( nStrPos);
232 : }
233 :
234 : }
235 : //pCustomShowList->Seek( nPosToSelect );
236 0 : pShow->SetName( aStr );
237 :
238 0 : pCustomShowList->push_back( pShow );
239 0 : pCustomShowList->Last();
240 0 : m_pLbCustomShows->InsertEntry( pShow->GetName() );
241 0 : m_pLbCustomShows->SelectEntry( pShow->GetName() );
242 :
243 0 : bModified = true;
244 : }
245 : }
246 0 : else if( p == m_pLbCustomShows )
247 : {
248 0 : sal_Int32 nPos = m_pLbCustomShows->GetSelectEntryPos();
249 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
250 0 : pCustomShowList->Seek( nPos );
251 :
252 0 : bModified = true;
253 : }
254 0 : else if( p == m_pCbxUseCustomShow )
255 : {
256 0 : bModified = true;
257 : }
258 :
259 0 : CheckState();
260 :
261 0 : return 0L;
262 : }
263 :
264 : // StartShow-Hdl
265 0 : IMPL_LINK_NOARG(SdCustomShowDlg, StartShowHdl)
266 : {
267 0 : EndDialog( RET_YES );
268 :
269 0 : return 0;
270 : }
271 :
272 : // CheckState
273 0 : bool SdCustomShowDlg::IsCustomShow() const
274 : {
275 0 : return( m_pCbxUseCustomShow->IsEnabled() && m_pCbxUseCustomShow->IsChecked() );
276 : }
277 :
278 : // SdDefineCustomShowDlg
279 0 : SdDefineCustomShowDlg::SdDefineCustomShowDlg( vcl::Window* pWindow,
280 : SdDrawDocument& rDrawDoc, SdCustomShow*& rpCS ) :
281 : ModalDialog ( pWindow, "DefineCustomSlideShow", "modules/simpress/ui/definecustomslideshow.ui" ),
282 : rDoc ( rDrawDoc ),
283 : rpCustomShow ( rpCS ),
284 0 : bModified ( false )
285 : {
286 0 : get( m_pEdtName, "customname" );
287 0 : get( m_pLbPages, "pages" );
288 0 : get( m_pBtnAdd, "add" );
289 0 : get( m_pBtnRemove, "remove" );
290 0 : get( m_pLbCustomPages, "custompages" );
291 0 : get( m_pBtnOK, "ok" );
292 0 : get( m_pBtnCancel, "cancel" );
293 0 : get( m_pBtnHelp, "help" );
294 :
295 0 : Link<> aLink = LINK( this, SdDefineCustomShowDlg, ClickButtonHdl );
296 0 : m_pBtnAdd->SetClickHdl( aLink );
297 0 : m_pBtnRemove->SetClickHdl( aLink );
298 0 : m_pEdtName->SetModifyHdl( aLink );
299 0 : m_pLbPages->SetSelectHdl( aLink ); // because of status
300 0 : m_pLbCustomPages->SetSelectHdl( aLink ); // because of status
301 :
302 0 : m_pBtnOK->SetClickHdl( LINK( this, SdDefineCustomShowDlg, OKHdl ) );
303 :
304 : // Hack: m_pLbPages used to be MultiLB. We don't have VCL builder equivalent
305 : // of it yet. So enable selecting multiple items here
306 0 : m_pLbPages->EnableMultiSelection( true );
307 :
308 : // shape 'em a bit
309 0 : m_pLbPages->set_width_request(m_pLbPages->approximate_char_width() * 16);
310 0 : m_pLbCustomPages->set_width_request(m_pLbPages->approximate_char_width() * 16);
311 0 : m_pLbPages->SetDropDownLineCount(10);
312 :
313 : // fill Listbox with page names of Docs
314 0 : for( long nPage = 0L;
315 0 : nPage < rDoc.GetSdPageCount( PK_STANDARD );
316 : nPage++ )
317 : {
318 0 : SdPage* pPage = rDoc.GetSdPage( (sal_uInt16) nPage, PK_STANDARD );
319 0 : OUString aStr( pPage->GetName() );
320 0 : m_pLbPages->InsertEntry( aStr );
321 0 : }
322 : // aLbPages.SelectEntryPos( 0 );
323 :
324 0 : if( rpCustomShow )
325 : {
326 0 : aOldName = rpCustomShow->GetName();
327 0 : m_pEdtName->SetText( aOldName );
328 :
329 : // fill ListBox with CustomShow pages
330 0 : for( SdCustomShow::PageVec::iterator it = rpCustomShow->PagesVector().begin();
331 0 : it != rpCustomShow->PagesVector().end(); ++it )
332 : {
333 0 : SvTreeListEntry* pEntry = m_pLbCustomPages->InsertEntry( (*it)->GetName() );
334 0 : pEntry->SetUserData( const_cast<SdPage*>(*it) );
335 : }
336 : }
337 : else
338 : {
339 0 : rpCustomShow = new SdCustomShow( &rDoc );
340 0 : m_pEdtName->SetText( OUString( SdResId( STR_NEW_CUSTOMSHOW ) ) );
341 0 : m_pEdtName->SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
342 0 : rpCustomShow->SetName( m_pEdtName->GetText() );
343 : }
344 :
345 0 : m_pLbCustomPages->SetDragDropMode( DragDropMode::CTRL_MOVE );
346 0 : m_pLbCustomPages->SetHighlightRange();
347 :
348 0 : m_pBtnOK->Enable( false );
349 0 : CheckState();
350 0 : }
351 :
352 0 : SdDefineCustomShowDlg::~SdDefineCustomShowDlg()
353 : {
354 0 : disposeOnce();
355 0 : }
356 :
357 0 : void SdDefineCustomShowDlg::dispose()
358 : {
359 0 : m_pEdtName.clear();
360 0 : m_pLbPages.clear();
361 0 : m_pBtnAdd.clear();
362 0 : m_pBtnRemove.clear();
363 0 : m_pLbCustomPages.clear();
364 0 : m_pBtnOK.clear();
365 0 : m_pBtnCancel.clear();
366 0 : m_pBtnHelp.clear();
367 0 : ModalDialog::dispose();
368 0 : }
369 :
370 : // CheckState
371 0 : void SdDefineCustomShowDlg::CheckState()
372 : {
373 0 : bool bPages = m_pLbPages->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND;
374 : //sal_Bool bCSPages = aLbCustomPages.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND;
375 0 : bool bCSPages = m_pLbCustomPages->FirstSelected() != NULL;
376 0 : bool bCount = m_pLbCustomPages->GetEntryCount() > 0;
377 :
378 0 : m_pBtnOK->Enable( bCount );
379 0 : m_pBtnAdd->Enable( bPages );
380 0 : m_pBtnRemove->Enable( bCSPages );
381 0 : }
382 :
383 : // ButtonHdl()
384 0 : IMPL_LINK( SdDefineCustomShowDlg, ClickButtonHdl, void *, p )
385 : {
386 0 : if( p == m_pBtnAdd )
387 : {
388 0 : sal_Int32 nCount = m_pLbPages->GetSelectEntryCount();
389 0 : if( nCount > 0 )
390 : {
391 0 : sal_uLong nPosCP = TREELIST_APPEND;
392 0 : SvTreeListEntry* pEntry = m_pLbCustomPages->FirstSelected();
393 0 : if( pEntry )
394 0 : nPosCP = m_pLbCustomPages->GetModel()->GetAbsPos( pEntry ) + 1L;
395 :
396 0 : for( sal_Int32 i = 0; i < nCount; i++ )
397 : {
398 0 : OUString aStr = m_pLbPages->GetSelectEntry( i );
399 0 : pEntry = m_pLbCustomPages->InsertEntry( aStr,
400 0 : 0, false, nPosCP );
401 :
402 0 : m_pLbCustomPages->Select( pEntry );
403 : SdPage* pPage = rDoc.GetSdPage( (sal_uInt16) m_pLbPages->
404 0 : GetSelectEntryPos( i ), PK_STANDARD );
405 0 : pEntry->SetUserData( pPage );
406 :
407 0 : if( nPosCP != TREELIST_APPEND )
408 0 : nPosCP++;
409 0 : }
410 0 : bModified = true;
411 : }
412 : }
413 0 : else if( p == m_pBtnRemove )
414 : {
415 0 : SvTreeListEntry* pEntry = m_pLbCustomPages->FirstSelected();
416 0 : if( pEntry )
417 : {
418 0 : sal_uLong nPos = m_pLbCustomPages->GetModel()->GetAbsPos( pEntry );
419 0 : m_pLbCustomPages->GetModel()->Remove( m_pLbCustomPages->GetModel()->GetEntryAtAbsPos( nPos ) );
420 :
421 0 : bModified = true;
422 : }
423 : }
424 0 : else if( p == m_pEdtName )
425 : {
426 0 : bModified = true;
427 : }
428 :
429 0 : CheckState();
430 :
431 0 : return 0L;
432 : }
433 :
434 : /**
435 : * Checks the page pointer of the Show since entries can be moved and copied
436 : * by TreeLB.
437 : */
438 0 : void SdDefineCustomShowDlg::CheckCustomShow()
439 : {
440 0 : bool bDifferent = false;
441 0 : SvTreeListEntry* pEntry = NULL;
442 :
443 : // compare count
444 0 : if( rpCustomShow->PagesVector().size() != m_pLbCustomPages->GetEntryCount() )
445 : {
446 0 : rpCustomShow->PagesVector().clear();
447 0 : bDifferent = true;
448 : }
449 :
450 : // compare page pointer
451 0 : if( !bDifferent )
452 : {
453 0 : SdCustomShow::PageVec::iterator it1 = rpCustomShow->PagesVector().begin();
454 0 : pEntry = m_pLbCustomPages->First();
455 0 : for( ; it1 != rpCustomShow->PagesVector().end() && pEntry != NULL && !bDifferent;
456 0 : ++it1, pEntry = m_pLbCustomPages->Next( pEntry ) )
457 : {
458 0 : if( *it1 != pEntry->GetUserData() )
459 : {
460 0 : rpCustomShow->PagesVector().clear();
461 0 : bDifferent = true;
462 : }
463 : }
464 : }
465 :
466 : // set new page pointer
467 0 : if( bDifferent )
468 : {
469 0 : for( pEntry = m_pLbCustomPages->First();
470 : pEntry != NULL;
471 0 : pEntry = m_pLbCustomPages->Next( pEntry ) )
472 : {
473 0 : SdPage* pPage = static_cast<SdPage*>(pEntry->GetUserData());
474 0 : rpCustomShow->PagesVector().push_back( pPage );
475 : }
476 0 : bModified = true;
477 : }
478 :
479 : // compare name and set name if necessary
480 0 : OUString aStr( m_pEdtName->GetText() );
481 0 : if( rpCustomShow->GetName() != aStr )
482 : {
483 0 : rpCustomShow->SetName( aStr );
484 0 : bModified = true;
485 0 : }
486 0 : }
487 :
488 : // OK-Hdl
489 0 : IMPL_LINK_NOARG(SdDefineCustomShowDlg, OKHdl)
490 : {
491 : // check name...
492 0 : bool bDifferent = true;
493 0 : SdCustomShowList* pCustomShowList = rDoc.GetCustomShowList();
494 0 : if( pCustomShowList )
495 : {
496 0 : OUString aName( m_pEdtName->GetText() );
497 : SdCustomShow* pCustomShow;
498 :
499 0 : long nPosToSelect = pCustomShowList->GetCurPos();
500 0 : for( pCustomShow = pCustomShowList->First();
501 : pCustomShow != NULL;
502 : pCustomShow = pCustomShowList->Next() )
503 : {
504 0 : if( aName == pCustomShow->GetName() && aName != aOldName )
505 0 : bDifferent = false;
506 : }
507 0 : pCustomShowList->Seek( nPosToSelect );
508 : }
509 :
510 0 : if( bDifferent )
511 : {
512 0 : CheckCustomShow();
513 :
514 0 : EndDialog( RET_OK );
515 : }
516 : else
517 : {
518 : ScopedVclPtr<WarningBox>::Create( this, WinBits( WB_OK ),
519 0 : SD_RESSTR( STR_WARN_NAME_DUPLICATE ) )->Execute();
520 :
521 0 : m_pEdtName->GrabFocus();
522 : }
523 :
524 0 : return 0;
525 0 : }
526 :
527 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|