1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
27 #include <cusshow.hxx>
29 #include <customshowlist.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/weld.hxx>
32 #include <svtools/treelistentry.hxx>
35 SdCustomShowDlg::SdCustomShowDlg(weld::Window
* pWindow
, SdDrawDocument
& rDrawDoc
)
36 : GenericDialogController(pWindow
, "modules/simpress/ui/customslideshows.ui", "CustomSlideShows")
38 , pCustomShowList(nullptr)
39 , pCustomShow(nullptr)
41 , m_xLbCustomShows(m_xBuilder
->weld_tree_view("customshowlist"))
42 , m_xCbxUseCustomShow(m_xBuilder
->weld_check_button("usecustomshows"))
43 , m_xBtnNew(m_xBuilder
->weld_button("new"))
44 , m_xBtnEdit(m_xBuilder
->weld_button("edit"))
45 , m_xBtnRemove(m_xBuilder
->weld_button("delete"))
46 , m_xBtnCopy(m_xBuilder
->weld_button("copy"))
47 , m_xBtnHelp(m_xBuilder
->weld_button("help"))
48 , m_xBtnStartShow(m_xBuilder
->weld_button("startshow"))
49 , m_xBtnOK(m_xBuilder
->weld_button("ok"))
51 m_xLbCustomShows
->set_size_request(m_xLbCustomShows
->get_approximate_digit_width() * 32,
52 m_xLbCustomShows
->get_height_rows(8));
54 Link
<weld::Button
&,void> aLink( LINK( this, SdCustomShowDlg
, ClickButtonHdl
) );
55 m_xBtnNew
->connect_clicked( aLink
);
56 m_xBtnEdit
->connect_clicked( aLink
);
57 m_xBtnRemove
->connect_clicked( aLink
);
58 m_xBtnCopy
->connect_clicked( aLink
);
59 m_xCbxUseCustomShow
->connect_clicked( aLink
);
60 m_xLbCustomShows
->connect_changed( LINK( this, SdCustomShowDlg
, SelectListBoxHdl
) );
62 m_xBtnStartShow
->connect_clicked( LINK( this, SdCustomShowDlg
, StartShowHdl
) ); // for test
64 // get CustomShow list of docs
65 pCustomShowList
= rDoc
.GetCustomShowList();
68 long nPosToSelect
= pCustomShowList
->GetCurPos();
69 // fill ListBox with CustomShows
70 for( pCustomShow
= pCustomShowList
->First();
71 pCustomShow
!= nullptr;
72 pCustomShow
= pCustomShowList
->Next() )
74 m_xLbCustomShows
->append_text(pCustomShow
->GetName());
76 m_xLbCustomShows
->select(nPosToSelect
);
77 pCustomShowList
->Seek( nPosToSelect
);
80 m_xCbxUseCustomShow
->set_active(pCustomShowList
&& rDoc
.getPresentationSettings().mbCustomShow
);
85 SdCustomShowDlg::~SdCustomShowDlg()
89 void SdCustomShowDlg::CheckState()
91 int nPos
= m_xLbCustomShows
->get_selected_index();
93 bool bEnable
= nPos
!= -1;
94 m_xBtnEdit
->set_sensitive( bEnable
);
95 m_xBtnRemove
->set_sensitive( bEnable
);
96 m_xBtnCopy
->set_sensitive( bEnable
);
97 m_xCbxUseCustomShow
->set_sensitive( bEnable
);
98 m_xBtnStartShow
->set_sensitive(true);
100 if (bEnable
&& pCustomShowList
)
101 pCustomShowList
->Seek( nPos
);
104 IMPL_LINK( SdCustomShowDlg
, ClickButtonHdl
, weld::Button
&, r
, void )
109 IMPL_LINK( SdCustomShowDlg
, SelectListBoxHdl
, weld::TreeView
&, rListBox
, void )
111 SelectHdl(&rListBox
);
114 void SdCustomShowDlg::SelectHdl(void const *p
)
117 if (p
== m_xBtnNew
.get())
119 pCustomShow
= nullptr;
120 SdDefineCustomShowDlg
aDlg(m_xDialog
.get(), rDoc
, pCustomShow
);
121 if (aDlg
.run() == RET_OK
)
125 if( !pCustomShowList
)
126 pCustomShowList
= rDoc
.GetCustomShowList( true );
128 pCustomShowList
->push_back( pCustomShow
);
129 pCustomShowList
->Last();
130 m_xLbCustomShows
->append_text( pCustomShow
->GetName() );
131 m_xLbCustomShows
->select_text( pCustomShow
->GetName() );
134 if (aDlg
.IsModified())
137 else if( pCustomShow
)
138 DELETEZ( pCustomShow
);
141 else if( p
== m_xBtnEdit
.get() )
143 int nPos
= m_xLbCustomShows
->get_selected_index();
146 DBG_ASSERT( pCustomShowList
, "pCustomShowList does not exist" );
147 pCustomShow
= (*pCustomShowList
)[ nPos
];
148 SdDefineCustomShowDlg
aDlg(m_xDialog
.get(), rDoc
, pCustomShow
);
150 if (aDlg
.run() == RET_OK
)
154 (*pCustomShowList
)[nPos
] = pCustomShow
;
155 pCustomShowList
->Seek(nPos
);
156 m_xLbCustomShows
->remove(nPos
);
157 m_xLbCustomShows
->insert_text(pCustomShow
->GetName(), nPos
);
158 m_xLbCustomShows
->select(nPos
);
160 if (aDlg
.IsModified())
166 else if( p
== m_xBtnRemove
.get() )
168 int nPos
= m_xLbCustomShows
->get_selected_index();
171 delete (*pCustomShowList
)[nPos
];
172 pCustomShowList
->erase( pCustomShowList
->begin() + nPos
);
173 m_xLbCustomShows
->remove(nPos
);
174 m_xLbCustomShows
->select(nPos
== 0 ? nPos
: nPos
- 1);
179 else if( p
== m_xBtnCopy
.get() )
181 int nPos
= m_xLbCustomShows
->get_selected_index();
184 SdCustomShow
* pShow
= new SdCustomShow( *(*pCustomShowList
)[nPos
] );
185 OUString
aStr( pShow
->GetName() );
186 OUString
aStrCopy( SdResId( STR_COPY_CUSTOMSHOW
) );
188 sal_Int32 nStrPos
= aStr
.indexOf( aStrCopy
);
192 aStr
= aStr
+ " (" + aStrCopy
+ OUString::number( nNum
) + ")";
193 nStrPos
= aStr
.indexOf( aStrCopy
);
195 nStrPos
= nStrPos
+ aStrCopy
.getLength();
196 // that we do not access into the nirvana (--> endless loop)
197 if( nStrPos
>= aStr
.getLength() )
199 aStr
= aStr
+ " " + OUString::number( nNum
);
203 bool bDifferent
= false;
204 //long nPosToSelect = pCustomShowList->GetCurPos();
208 for( pCustomShow
= pCustomShowList
->First();
209 pCustomShow
!= nullptr && bDifferent
;
210 pCustomShow
= pCustomShowList
->Next() )
212 if( aStr
== pCustomShow
->GetName() )
217 // replace number by a number increased by 1
219 const CharClass
* pCharClass
= rDoc
.GetCharClass();
220 while( pCharClass
->isDigit( aStr
, nStrPos
) )
221 aStr
= aStr
.replaceAt( nStrPos
, 1, "" );
222 aStr
= aStr
.copy( 0, nStrPos
) + OUString::number( ++nNum
) + aStr
.copy( nStrPos
);
226 //pCustomShowList->Seek( nPosToSelect );
227 pShow
->SetName( aStr
);
229 pCustomShowList
->push_back( pShow
);
230 pCustomShowList
->Last();
231 m_xLbCustomShows
->append_text(pShow
->GetName());
232 m_xLbCustomShows
->select_text(pShow
->GetName());
237 else if( p
== m_xLbCustomShows
.get() )
239 int nPos
= m_xLbCustomShows
->get_selected_index();
241 pCustomShowList
->Seek(nPos
);
245 else if( p
== m_xCbxUseCustomShow
.get() )
254 IMPL_LINK_NOARG(SdCustomShowDlg
, StartShowHdl
, weld::Button
&, void)
256 m_xDialog
->response(RET_YES
);
260 bool SdCustomShowDlg::IsCustomShow() const
262 return (m_xCbxUseCustomShow
->get_sensitive() && m_xCbxUseCustomShow
->get_active());
265 // SdDefineCustomShowDlg
266 SdDefineCustomShowDlg::SdDefineCustomShowDlg(weld::Window
* pWindow
, SdDrawDocument
& rDrawDoc
, SdCustomShow
*& rpCS
)
267 : GenericDialogController(pWindow
, "modules/simpress/ui/definecustomslideshow.ui", "DefineCustomSlideShow")
271 , m_xEdtName(m_xBuilder
->weld_entry("customname"))
272 , m_xLbPages(m_xBuilder
->weld_tree_view("pages"))
273 , m_xBtnAdd(m_xBuilder
->weld_button("add"))
274 , m_xBtnRemove(m_xBuilder
->weld_button("remove"))
275 , m_xLbCustomPages(m_xBuilder
->weld_tree_view("custompages"))
276 , m_xBtnOK(m_xBuilder
->weld_button("ok"))
277 , m_xBtnCancel(m_xBuilder
->weld_button("cancel"))
278 , m_xBtnHelp(m_xBuilder
->weld_button("help"))
280 Link
<weld::Button
&,void> aLink
= LINK( this, SdDefineCustomShowDlg
, ClickButtonHdl
);
281 m_xBtnAdd
->connect_clicked( aLink
);
282 m_xBtnRemove
->connect_clicked( aLink
);
283 m_xEdtName
->connect_changed( LINK( this, SdDefineCustomShowDlg
, ClickButtonEditHdl
) );
284 m_xLbPages
->connect_changed( LINK( this, SdDefineCustomShowDlg
, ClickButtonHdl4
) ); // because of status
285 m_xLbCustomPages
->connect_changed( LINK( this, SdDefineCustomShowDlg
, ClickButtonHdl3
) ); // because of status
287 m_xBtnOK
->connect_clicked( LINK( this, SdDefineCustomShowDlg
, OKHdl
) );
289 m_xLbPages
->set_selection_mode(true);
292 m_xLbPages
->set_size_request(m_xLbPages
->get_approximate_digit_width() * 24, m_xLbPages
->get_height_rows(10));
293 m_xLbCustomPages
->set_size_request(m_xLbPages
->get_approximate_digit_width() * 24, m_xLbCustomPages
->get_height_rows(10));
295 // fill Listbox with page names of Docs
297 nPage
< rDoc
.GetSdPageCount( PageKind::Standard
);
300 SdPage
* pPage
= rDoc
.GetSdPage( static_cast<sal_uInt16
>(nPage
), PageKind::Standard
);
301 m_xLbPages
->append_text(pPage
->GetName());
303 // aLbPages.SelectEntryPos( 0 );
307 aOldName
= rpCustomShow
->GetName();
308 m_xEdtName
->set_text( aOldName
);
310 // fill ListBox with CustomShow pages
311 for( SdCustomShow::PageVec::iterator it
= rpCustomShow
->PagesVector().begin();
312 it
!= rpCustomShow
->PagesVector().end(); ++it
)
314 m_xLbCustomPages
->append(OUString::number(reinterpret_cast<sal_uInt64
>(*it
)) ,(*it
)->GetName(), "");
319 rpCustomShow
= new SdCustomShow
;
320 m_xEdtName
->set_text( SdResId( STR_NEW_CUSTOMSHOW
) );
321 m_xEdtName
->select_region(0, -1);
322 rpCustomShow
->SetName( m_xEdtName
->get_text() );
325 m_xBtnOK
->set_sensitive( false );
329 SdDefineCustomShowDlg::~SdDefineCustomShowDlg()
334 void SdDefineCustomShowDlg::CheckState()
336 bool bPages
= m_xLbPages
->count_selected_rows() > 0;
337 bool bCSPages
= m_xLbCustomPages
->get_selected_index() != -1;
338 bool bCount
= m_xLbCustomPages
->n_children() > 0;
340 m_xBtnOK
->set_sensitive( bCount
);
341 m_xBtnAdd
->set_sensitive( bPages
);
342 m_xBtnRemove
->set_sensitive( bCSPages
);
345 IMPL_LINK( SdDefineCustomShowDlg
, ClickButtonHdl
, weld::Button
&, rWidget
, void )
347 ClickButtonHdl2(&rWidget
);
350 IMPL_LINK( SdDefineCustomShowDlg
, ClickButtonHdl3
, weld::TreeView
&, rWidget
, void )
352 ClickButtonHdl2(&rWidget
);
355 IMPL_LINK( SdDefineCustomShowDlg
, ClickButtonHdl4
, weld::TreeView
&, rListBox
, void )
357 ClickButtonHdl2(&rListBox
);
360 IMPL_LINK( SdDefineCustomShowDlg
, ClickButtonEditHdl
, weld::Entry
&, rEdit
, void )
362 ClickButtonHdl2(&rEdit
);
366 void SdDefineCustomShowDlg::ClickButtonHdl2(void const * p
)
368 if( p
== m_xBtnAdd
.get() )
370 auto aRows
= m_xLbPages
->get_selected_rows();
373 int nPosCP
= m_xLbCustomPages
->get_selected_index();
379 OUString aStr
= m_xLbPages
->get_text(i
);
380 SdPage
* pPage
= rDoc
.GetSdPage(i
, PageKind::Standard
);
381 m_xLbCustomPages
->insert(nPosCP
, OUString::number(reinterpret_cast<sal_uInt64
>(pPage
)), aStr
, "");
382 m_xLbCustomPages
->select(nPosCP
!= -1 ? nPosCP
: m_xLbCustomPages
->n_children() - 1);
390 else if (p
== m_xBtnRemove
.get())
392 int nPos
= m_xLbCustomPages
->get_selected_index();
395 m_xLbCustomPages
->remove(nPos
);
396 m_xLbCustomPages
->select(nPos
== 0 ? nPos
: nPos
- 1);
400 else if( p
== m_xEdtName
.get() )
409 * Checks the page pointer of the Show since entries can be moved and copied
412 void SdDefineCustomShowDlg::CheckCustomShow()
414 bool bDifferent
= false;
417 size_t nCount
= m_xLbCustomPages
->n_children();
418 if (rpCustomShow
->PagesVector().size() != nCount
)
420 rpCustomShow
->PagesVector().clear();
424 // compare page pointer
427 SdCustomShow::PageVec::iterator it1
= rpCustomShow
->PagesVector().begin();
429 for( ; it1
!= rpCustomShow
->PagesVector().end() && i
< nCount
&& !bDifferent
;
432 SdPage
* pPage
= reinterpret_cast<SdPage
*>(m_xLbCustomPages
->get_id(i
).toUInt64());
435 rpCustomShow
->PagesVector().clear();
441 // set new page pointer
444 for (size_t i
= 0; i
< nCount
; ++i
)
446 SdPage
* pPage
= reinterpret_cast<SdPage
*>(m_xLbCustomPages
->get_id(i
).toUInt64());
447 rpCustomShow
->PagesVector().push_back(pPage
);
452 // compare name and set name if necessary
453 OUString
aStr( m_xEdtName
->get_text() );
454 if( rpCustomShow
->GetName() != aStr
)
456 rpCustomShow
->SetName( aStr
);
462 IMPL_LINK_NOARG(SdDefineCustomShowDlg
, OKHdl
, weld::Button
&, void)
465 bool bDifferent
= true;
466 SdCustomShowList
* pCustomShowList
= rDoc
.GetCustomShowList();
467 if( pCustomShowList
)
469 OUString
aName( m_xEdtName
->get_text() );
470 SdCustomShow
* pCustomShow
;
472 long nPosToSelect
= pCustomShowList
->GetCurPos();
473 for( pCustomShow
= pCustomShowList
->First();
474 pCustomShow
!= nullptr;
475 pCustomShow
= pCustomShowList
->Next() )
477 if( aName
== pCustomShow
->GetName() && aName
!= aOldName
)
480 pCustomShowList
->Seek( nPosToSelect
);
487 m_xDialog
->response(RET_OK
);
491 std::unique_ptr
<weld::MessageDialog
> xWarn(Application::CreateMessageDialog(m_xDialog
.get(),
492 VclMessageType::Warning
, VclButtonsType::Ok
,
493 SdResId(STR_WARN_NAME_DUPLICATE
)));
495 m_xEdtName
->grab_focus();
499 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */