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