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