1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: custsdlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #ifdef SD_DLLIMPLEMENTATION
35 #undef SD_DLLIMPLEMENTATION
38 #include "custsdlg.hxx"
39 #include "custsdlg.hrc"
41 #include "strings.hrc"
42 #include "sdresid.hxx"
44 #include "drawdoc.hxx"
46 #include "cusshow.hxx"
48 #include "optsitem.hxx"
49 #include <vcl/msgbox.hxx>
57 /*************************************************************************
59 \************************************************************************/
60 SdCustomShowDlg::SdCustomShowDlg( Window
* pWindow
,
61 SdDrawDocument
& rDrawDoc
) :
62 ModalDialog ( pWindow
, SdResId( DLG_CUSTOMSHOW
) ),
64 aLbCustomShows ( this, SdResId( LB_CUSTOMSHOWS
) ),
65 aCbxUseCustomShow( this, SdResId( CBX_USE_CUSTOMSHOW
) ),
66 aBtnNew ( this, SdResId( BTN_NEW
) ),
67 aBtnEdit ( this, SdResId( BTN_EDIT
) ),
68 aBtnRemove ( this, SdResId( BTN_REMOVE
) ),
69 aBtnCopy ( this, SdResId( BTN_COPY
) ),
70 aBtnHelp ( this, SdResId( BTN_HELP
) ),
71 aBtnStartShow ( this, SdResId( BTN_STARTSHOW
) ),
72 aBtnOK ( this, SdResId( BTN_OK
) ),
75 pCustomShowList ( NULL
),
81 Link
aLink( LINK( this, SdCustomShowDlg
, ClickButtonHdl
) );
82 aBtnNew
.SetClickHdl( aLink
);
83 aBtnEdit
.SetClickHdl( aLink
);
84 aBtnRemove
.SetClickHdl( aLink
);
85 aBtnCopy
.SetClickHdl( aLink
);
86 aCbxUseCustomShow
.SetClickHdl( aLink
);
87 aLbCustomShows
.SetSelectHdl( aLink
);
89 aBtnStartShow
.SetClickHdl( LINK( this, SdCustomShowDlg
, StartShowHdl
) ); // Testweise
91 // CustomShow-Liste des Docs abrufen
92 pCustomShowList
= rDoc
.GetCustomShowList();
95 long nPosToSelect
= pCustomShowList
->GetCurPos();
96 // ListBox mit CustomShows fuellen
97 for( pCustomShow
= (SdCustomShow
*) pCustomShowList
->First();
99 pCustomShow
= (SdCustomShow
*) pCustomShowList
->Next() )
101 aLbCustomShows
.InsertEntry( pCustomShow
->GetName() );
103 aLbCustomShows
.SelectEntryPos( (USHORT
)nPosToSelect
);
104 pCustomShowList
->Seek( nPosToSelect
);
107 aCbxUseCustomShow
.Check( pCustomShowList
&& rDoc
.getPresentationSettings().mbCustomShow
);
112 /*************************************************************************
114 \************************************************************************/
115 SdCustomShowDlg::~SdCustomShowDlg()
119 /*************************************************************************
121 \************************************************************************/
122 void SdCustomShowDlg::CheckState()
124 USHORT nPos
= aLbCustomShows
.GetSelectEntryPos();
126 BOOL bEnable
= nPos
!= LISTBOX_ENTRY_NOTFOUND
;
127 aBtnEdit
.Enable( bEnable
);
128 aBtnRemove
.Enable( bEnable
);
129 aBtnCopy
.Enable( bEnable
);
130 aCbxUseCustomShow
.Enable( bEnable
);
131 aBtnStartShow
.Enable( true );
134 pCustomShowList
->Seek( nPos
);
137 /*************************************************************************
139 \************************************************************************/
140 IMPL_LINK( SdCustomShowDlg
, ClickButtonHdl
, void *, p
)
146 SdDefineCustomShowDlg
aDlg( this, rDoc
, pCustomShow
);
147 if( aDlg
.Execute() == RET_OK
)
151 if( !pCustomShowList
)
152 pCustomShowList
= rDoc
.GetCustomShowList( TRUE
);
154 pCustomShowList
->Insert( pCustomShow
, LIST_APPEND
);
155 pCustomShowList
->Last();
156 aLbCustomShows
.InsertEntry( pCustomShow
->GetName() );
157 aLbCustomShows
.SelectEntry( pCustomShow
->GetName() );
160 if( aDlg
.IsModified() )
163 else if( pCustomShow
)
164 DELETEZ( pCustomShow
);
166 // CustomShow bearbeiten
167 else if( p
== &aBtnEdit
)
169 USHORT nPos
= aLbCustomShows
.GetSelectEntryPos();
170 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
172 DBG_ASSERT( pCustomShowList
, "pCustomShowList existiert nicht" );
173 pCustomShow
= (SdCustomShow
*) pCustomShowList
->GetObject( nPos
);
174 SdDefineCustomShowDlg
aDlg( this, rDoc
, pCustomShow
);
176 if( aDlg
.Execute() == RET_OK
)
180 pCustomShowList
->Replace( pCustomShow
, nPos
);
181 pCustomShowList
->Seek( nPos
);
182 aLbCustomShows
.RemoveEntry( nPos
);
183 aLbCustomShows
.InsertEntry( pCustomShow
->GetName(), nPos
);
184 aLbCustomShows
.SelectEntryPos( nPos
);
186 if( aDlg
.IsModified() )
191 // CustomShow loeschen
192 else if( p
== &aBtnRemove
)
194 USHORT nPos
= aLbCustomShows
.GetSelectEntryPos();
195 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
197 delete (SdCustomShow
*) pCustomShowList
->Remove( nPos
);
198 aLbCustomShows
.RemoveEntry( nPos
);
199 aLbCustomShows
.SelectEntryPos( nPos
== 0 ? nPos
: nPos
- 1 );
203 // CustomShow kopieren
204 else if( p
== &aBtnCopy
)
206 USHORT nPos
= aLbCustomShows
.GetSelectEntryPos();
207 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
209 SdCustomShow
* pShow
= new SdCustomShow( *(SdCustomShow
*) pCustomShowList
->GetObject( nPos
) );
210 String
aStr( pShow
->GetName() );
211 String
aStrCopy( SdResId( STR_COPY_CUSTOMSHOW
) );
213 USHORT nStrPos
= aStr
.Search( aStrCopy
);
215 if( nStrPos
== STRING_NOTFOUND
)
217 aStr
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " (" ) );
218 aStr
.Append( aStrCopy
);
219 aStr
.Append( UniString::CreateFromInt32( nNum
) );
220 aStr
.Append( sal_Unicode(')') );
221 nStrPos
= aStr
.Search( aStrCopy
);
223 nStrPos
= nStrPos
+ (USHORT
)aStrCopy
.Len();
224 // Um nicht ins Nirvana zu greifen (--> Endlosschleife)
225 if( nStrPos
>= aStr
.Len() )
227 aStr
.Append( sal_Unicode(' ') );
228 aStr
.Append( UniString::CreateFromInt32( nNum
) );
231 // Name ueberpruefen...
232 BOOL bDifferent
= FALSE
;
233 //long nPosToSelect = pCustomShowList->GetCurPos();
237 for( pCustomShow
= (SdCustomShow
*) pCustomShowList
->First();
238 pCustomShow
!= NULL
&& bDifferent
;
239 pCustomShow
= (SdCustomShow
*) pCustomShowList
->Next() )
241 if( aStr
== pCustomShow
->GetName() )
246 // Nummer entfernen und durch um 1 erhoehte ersetzen
248 const CharClass
* pCharClass
= rDoc
.GetCharClass();
249 while( pCharClass
->isDigit( aStr
, nStrPos
) )
250 aStr
.Erase( nStrPos
, 1 );
251 aStr
.Insert( UniString::CreateFromInt32( ++nNum
), nStrPos
);
255 //pCustomShowList->Seek( nPosToSelect );
256 pShow
->SetName( aStr
);
258 pCustomShowList
->Insert( pShow
, LIST_APPEND
);
259 pCustomShowList
->Last();
260 aLbCustomShows
.InsertEntry( pShow
->GetName() );
261 aLbCustomShows
.SelectEntry( pShow
->GetName() );
267 else if( p
== &aLbCustomShows
)
269 USHORT nPos
= aLbCustomShows
.GetSelectEntryPos();
270 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
271 pCustomShowList
->Seek( nPos
);
275 else if( p
== &aCbxUseCustomShow
)
285 /*************************************************************************
287 \************************************************************************/
288 IMPL_LINK( SdCustomShowDlg
, StartShowHdl
, Button
*, EMPTYARG
)
290 EndDialog( RET_YES
);
295 /*************************************************************************
297 \************************************************************************/
298 BOOL
SdCustomShowDlg::IsCustomShow() const
300 return( aCbxUseCustomShow
.IsEnabled() && aCbxUseCustomShow
.IsChecked() );
305 ///////////////////////////
306 // SdDefineCustomShowDlg //
307 ///////////////////////////
310 /*************************************************************************
314 \************************************************************************/
315 SdDefineCustomShowDlg::SdDefineCustomShowDlg( Window
* pWindow
,
316 SdDrawDocument
& rDrawDoc
, SdCustomShow
*& rpCS
) :
317 ModalDialog ( pWindow
, SdResId( DLG_DEFINE_CUSTOMSHOW
) ),
319 aFtName ( this, SdResId( FT_NAME
) ),
320 aEdtName ( this, SdResId( EDT_NAME
) ),
321 aFtPages ( this, SdResId( FT_PAGES
) ),
322 aLbPages ( this, SdResId( LB_PAGES
) ),
323 aBtnAdd ( this, SdResId( BTN_ADD
) ),
324 aBtnRemove ( this, SdResId( BTN_REMOVE
) ),
325 aFtCustomPages ( this, SdResId( FT_CUSTOM_PAGES
) ),
326 aLbCustomPages ( this, SdResId( LB_CUSTOM_PAGES
) ),
327 aBtnOK ( this, SdResId( BTN_OK
) ),
328 aBtnCancel ( this, SdResId( BTN_CANCEL
) ),
329 aBtnHelp ( this, SdResId( BTN_HELP
) ),
332 rpCustomShow ( rpCS
),
337 Link aLink
= LINK( this, SdDefineCustomShowDlg
, ClickButtonHdl
);
338 aBtnAdd
.SetClickHdl( aLink
);
339 aBtnRemove
.SetClickHdl( aLink
);
340 aEdtName
.SetModifyHdl( aLink
);
341 aLbPages
.SetSelectHdl( aLink
); // wegen Status
342 aLbCustomPages
.SetSelectHdl( aLink
); // wegen Status
344 aBtnOK
.SetClickHdl( LINK( this, SdDefineCustomShowDlg
, OKHdl
) );
347 // Listbox mit Seitennamen des Docs fuellen
348 for( long nPage
= 0L;
349 nPage
< rDoc
.GetSdPageCount( PK_STANDARD
);
352 pPage
= rDoc
.GetSdPage( (USHORT
) nPage
, PK_STANDARD
);
353 String
aStr( pPage
->GetName() );
354 aLbPages
.InsertEntry( aStr
);
356 //aLbPages.SelectEntryPos( 0 );
360 aOldName
= rpCustomShow
->GetName();
361 aEdtName
.SetText( aOldName
);
363 // ListBox mit CustomShow-Seiten fuellen
364 for( pPage
= (SdPage
*) rpCustomShow
->First();
366 pPage
= (SdPage
*) rpCustomShow
->Next() )
368 SvLBoxEntry
* pEntry
= aLbCustomPages
.InsertEntry( pPage
->GetName() );
369 pEntry
->SetUserData( pPage
);
374 rpCustomShow
= new SdCustomShow( &rDoc
);
375 aEdtName
.SetText( String( SdResId( STR_NEW_CUSTOMSHOW
) ) );
376 aEdtName
.SetSelection( Selection( SELECTION_MIN
, SELECTION_MAX
) );
377 rpCustomShow
->SetName( aEdtName
.GetText() );
380 aLbCustomPages
.SetDragDropMode( SV_DRAGDROP_CTRL_MOVE
);
381 aLbCustomPages
.SetHighlightRange();
383 aBtnOK
.Enable( FALSE
);
387 /*************************************************************************
391 \************************************************************************/
392 SdDefineCustomShowDlg::~SdDefineCustomShowDlg()
396 /*************************************************************************
398 \************************************************************************/
399 void SdDefineCustomShowDlg::CheckState()
401 BOOL bPages
= aLbPages
.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
;
402 //BOOL bCSPages = aLbCustomPages.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND;
403 BOOL bCSPages
= aLbCustomPages
.FirstSelected() != NULL
;
404 BOOL bCount
= aLbCustomPages
.GetEntryCount() > 0;
406 aBtnOK
.Enable( bCount
);
407 aBtnAdd
.Enable( bPages
);
408 aBtnRemove
.Enable( bCSPages
);
411 /*************************************************************************
413 \************************************************************************/
414 IMPL_LINK( SdDefineCustomShowDlg
, ClickButtonHdl
, void *, p
)
418 USHORT nCount
= aLbPages
.GetSelectEntryCount();
421 ULONG nPosCP
= LIST_APPEND
;
422 SvLBoxEntry
* pEntry
= aLbCustomPages
.FirstSelected();
424 nPosCP
= aLbCustomPages
.GetModel()->GetAbsPos( pEntry
) + 1L;
426 for( USHORT i
= 0; i
< nCount
; i
++ )
428 String aStr
= aLbPages
.GetSelectEntry( i
);
429 pEntry
= aLbCustomPages
.InsertEntry( aStr
,
432 aLbCustomPages
.Select( pEntry
);
433 SdPage
* pPage
= rDoc
.GetSdPage( (USHORT
) aLbPages
.
434 GetSelectEntryPos( i
), PK_STANDARD
);
435 pEntry
->SetUserData( pPage
);
437 if( nPosCP
!= LIST_APPEND
)
443 else if( p
== &aBtnRemove
)
445 //USHORT nPos = aLbCustomPages.GetSelectEntryPos();
446 SvLBoxEntry
* pEntry
= aLbCustomPages
.FirstSelected();
449 ULONG nPos
= aLbCustomPages
.GetModel()->GetAbsPos( pEntry
);
450 //rpCustomShow->Remove( nPos );
451 //aLbCustomPages.RemoveEntry( nPos );
452 aLbCustomPages
.GetModel()->Remove( aLbCustomPages
.GetModel()->GetEntryAtAbsPos( nPos
) );
457 else if( p
== &aEdtName
)
459 //rpCustomShow->SetName( aEdtName.GetText() );
469 /*************************************************************************
470 |* CheckCustomShow():
471 |* Ueberprueft die Page-Pointer der Show, da die Eintraege ueber die
472 |* TreeLB verschoben und kopiert werden k”nnen
473 \************************************************************************/
474 void SdDefineCustomShowDlg::CheckCustomShow()
476 BOOL bDifferent
= FALSE
;
477 SdPage
* pPage
= NULL
;
478 SvLBoxEntry
* pEntry
= NULL
;
480 // Anzahl vergleichen
481 if( rpCustomShow
->Count() != aLbCustomPages
.GetEntryCount() )
483 rpCustomShow
->Clear();
487 // Seiten-Pointer vergleichen
490 for( pPage
= (SdPage
*) rpCustomShow
->First(), pEntry
= aLbCustomPages
.First();
491 pPage
!= NULL
&& pEntry
!= NULL
&& !bDifferent
;
492 pPage
= (SdPage
*) rpCustomShow
->Next(), pEntry
= aLbCustomPages
.Next( pEntry
) )
494 if( pPage
!= pEntry
->GetUserData() )
496 rpCustomShow
->Clear();
502 // Seiten-Pointer neu setzen
505 for( pEntry
= aLbCustomPages
.First();
507 pEntry
= aLbCustomPages
.Next( pEntry
) )
509 pPage
= (SdPage
*) pEntry
->GetUserData();
510 rpCustomShow
->Insert( pPage
, LIST_APPEND
);
515 // Name vergleichen und ggfs. setzen
516 String
aStr( aEdtName
.GetText() );
517 if( rpCustomShow
->GetName() != aStr
)
519 rpCustomShow
->SetName( aStr
);
524 /*************************************************************************
526 \************************************************************************/
527 IMPL_LINK( SdDefineCustomShowDlg
, OKHdl
, Button
*, EMPTYARG
)
529 // Name ueberpruefen...
530 BOOL bDifferent
= TRUE
;
531 List
* pCustomShowList
= rDoc
.GetCustomShowList();
532 if( pCustomShowList
)
534 String
aName( aEdtName
.GetText() );
535 SdCustomShow
* pCustomShow
;
537 long nPosToSelect
= pCustomShowList
->GetCurPos();
538 for( pCustomShow
= (SdCustomShow
*) pCustomShowList
->First();
540 pCustomShow
= (SdCustomShow
*) pCustomShowList
->Next() )
542 if( aName
== pCustomShow
->GetName() && aName
!= aOldName
)
545 pCustomShowList
->Seek( nPosToSelect
);
556 WarningBox( this, WinBits( WB_OK
),
557 String( SdResId( STR_WARN_NAME_DUPLICATE
) ) ).Execute();
559 aEdtName
.GrabFocus();