LibreOffice Module sd (master) 1
custsdlg.cxx
Go to the documentation of this file.
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 <customshowlist.hxx>
29#include <vcl/svapp.hxx>
30#include <vcl/weld.hxx>
32#include <tools/debug.hxx>
33
34// SdCustomShowDlg
36 : GenericDialogController(pWindow, "modules/simpress/ui/customslideshows.ui", "CustomSlideShows")
37 , rDoc(rDrawDoc)
38 , pCustomShowList(nullptr)
39 , m_xLbCustomShows(m_xBuilder->weld_tree_view("customshowlist"))
40 , m_xBtnNew(m_xBuilder->weld_button("new"))
41 , m_xBtnEdit(m_xBuilder->weld_button("edit"))
42 , m_xBtnRemove(m_xBuilder->weld_button("delete"))
43 , m_xBtnCopy(m_xBuilder->weld_button("copy"))
44 , m_xBtnStartShow(m_xBuilder->weld_button("startshow"))
45{
46 m_xLbCustomShows->set_size_request(m_xLbCustomShows->get_approximate_digit_width() * 32,
47 m_xLbCustomShows->get_height_rows(8));
48
49 Link<weld::Button&,void> aLink( LINK( this, SdCustomShowDlg, ClickButtonHdl ) );
50 m_xBtnNew->connect_clicked( aLink );
51 m_xBtnEdit->connect_clicked( aLink );
52 m_xBtnRemove->connect_clicked( aLink );
53 m_xBtnCopy->connect_clicked( aLink );
54 m_xLbCustomShows->connect_changed( LINK( this, SdCustomShowDlg, SelectListBoxHdl ) );
55
56 m_xBtnStartShow->connect_clicked( LINK( this, SdCustomShowDlg, StartShowHdl ) ); // for test
57
58 // get CustomShow list of docs
60 if( pCustomShowList )
61 {
62 tools::Long nPosToSelect = pCustomShowList->GetCurPos();
63 // fill ListBox with CustomShows
64 for( SdCustomShow* pCustomShow = pCustomShowList->First();
65 pCustomShow != nullptr;
66 pCustomShow = pCustomShowList->Next() )
67 {
68 m_xLbCustomShows->append_text(pCustomShow->GetName());
69 }
70 m_xLbCustomShows->select(nPosToSelect);
71 pCustomShowList->Seek( nPosToSelect );
72 }
73
74 CheckState();
75}
76
78{
79}
80
82{
83 int nPos = m_xLbCustomShows->get_selected_index();
84
85 bool bEnable = nPos != -1;
86 m_xBtnEdit->set_sensitive( bEnable );
87 m_xBtnRemove->set_sensitive( bEnable );
88 m_xBtnCopy->set_sensitive( bEnable );
89 m_xBtnStartShow->set_sensitive(bEnable);
90
91 if (bEnable && pCustomShowList)
93}
94
95IMPL_LINK( SdCustomShowDlg, ClickButtonHdl, weld::Button&, r, void )
96{
97 SelectHdl(&r);
98}
99
100IMPL_LINK( SdCustomShowDlg, SelectListBoxHdl, weld::TreeView&, rListBox, void )
101{
102 SelectHdl(&rListBox);
103}
104
105void SdCustomShowDlg::SelectHdl(void const *p)
106{
107 // new CustomShow
108 if (p == m_xBtnNew.get())
109 {
110 std::unique_ptr<SdCustomShow> pCustomShow;
111 SdDefineCustomShowDlg aDlg(m_xDialog.get(), rDoc, pCustomShow);
112 if (aDlg.run() == RET_OK)
113 {
114 if( pCustomShow )
115 {
116 if( !pCustomShowList )
118
119 SdCustomShow* pCustomShowTmp = pCustomShow.get();
120 pCustomShowList->push_back( std::move(pCustomShow) );
122 m_xLbCustomShows->append_text( pCustomShowTmp->GetName() );
123 m_xLbCustomShows->select_text( pCustomShowTmp->GetName() );
124 }
125 }
126 }
127 // edit CustomShow
128 else if( p == m_xBtnEdit.get() )
129 {
130 int nPos = m_xLbCustomShows->get_selected_index();
131 if (nPos != -1)
132 {
133 DBG_ASSERT( pCustomShowList, "pCustomShowList does not exist" );
134 std::unique_ptr<SdCustomShow>& pCustomShow = (*pCustomShowList)[ nPos ];
135 SdDefineCustomShowDlg aDlg(m_xDialog.get(), rDoc, pCustomShow);
136
137 if (aDlg.run() == RET_OK)
138 {
140 m_xLbCustomShows->remove(nPos);
141 m_xLbCustomShows->insert_text(nPos, pCustomShow->GetName());
142 m_xLbCustomShows->select(nPos);
143 }
144 }
145 }
146 // delete CustomShow
147 else if( p == m_xBtnRemove.get() )
148 {
149 int nPos = m_xLbCustomShows->get_selected_index();
150 if (nPos != -1)
151 {
153 m_xLbCustomShows->remove(nPos);
154 m_xLbCustomShows->select(nPos == 0 ? nPos : nPos - 1);
155 }
156 }
157 // copy CustomShow
158 else if( p == m_xBtnCopy.get() )
159 {
160 int nPos = m_xLbCustomShows->get_selected_index();
161 if (nPos != -1)
162 {
163 std::unique_ptr<SdCustomShow> pShow(new SdCustomShow( *(*pCustomShowList)[nPos] ));
164 OUString aStr( pShow->GetName() );
165 OUString aStrCopy( SdResId( STR_COPY_CUSTOMSHOW ) );
166
167 sal_Int32 nStrPos = aStr.indexOf( aStrCopy );
168 sal_Int32 nNum = 1;
169 if( nStrPos < 0 )
170 {
171 aStr += " (" + aStrCopy + OUString::number( nNum ) + ")";
172 nStrPos = aStr.indexOf( aStrCopy );
173 }
174 nStrPos = nStrPos + aStrCopy.getLength();
175 // that we do not access into the nirvana (--> endless loop)
176 if( nStrPos >= aStr.getLength() )
177 {
178 aStr += " " + OUString::number( nNum );
179 }
180
181 // check name...
182 bool bDifferent = false;
183 //long nPosToSelect = pCustomShowList->GetCurPos();
184 while( !bDifferent )
185 {
186 bDifferent = true;
187 for( SdCustomShow* pCustomShow = pCustomShowList->First();
188 pCustomShow != nullptr && bDifferent;
189 pCustomShow = pCustomShowList->Next() )
190 {
191 if( aStr == pCustomShow->GetName() )
192 bDifferent = false;
193 }
194 if( !bDifferent )
195 {
196 // replace number by a number increased by 1
197
198 const std::optional<CharClass>& pCharClass = rDoc.GetCharClass();
199 while( pCharClass->isDigit( aStr, nStrPos ) )
200 aStr = aStr.replaceAt( nStrPos, 1, u"" );
201 aStr = aStr.subView( 0, nStrPos) + OUString::number( ++nNum ) + aStr.subView( nStrPos);
202 }
203
204 }
205 //pCustomShowList->Seek( nPosToSelect );
206 pShow->SetName( aStr );
207
208 auto pShowTmp = pShow.get();
209 pCustomShowList->push_back( std::move(pShow) );
211 m_xLbCustomShows->append_text(pShowTmp->GetName());
212 m_xLbCustomShows->select_text(pShowTmp->GetName());
213 }
214 }
215 else if( p == m_xLbCustomShows.get() )
216 {
217 int nPos = m_xLbCustomShows->get_selected_index();
218 if (nPos != -1)
220 }
221
222 CheckState();
223}
224
225// StartShow-Hdl
227{
228 m_xDialog->response(RET_YES);
229}
230
231// CheckState
233{
234 if (!pCustomShowList->empty())
235 return true;
236 else
237 return false;
238}
239
240// SdDefineCustomShowDlg
241SdDefineCustomShowDlg::SdDefineCustomShowDlg(weld::Window* pWindow, SdDrawDocument& rDrawDoc, std::unique_ptr<SdCustomShow>& rpCS)
242 : GenericDialogController(pWindow, "modules/simpress/ui/definecustomslideshow.ui", "DefineCustomSlideShow")
243 , rDoc(rDrawDoc)
244 , rpCustomShow(rpCS)
245 , bModified(false)
246 , m_xEdtName(m_xBuilder->weld_entry("customname"))
247 , m_xLbPages(m_xBuilder->weld_tree_view("pages"))
248 , m_xBtnAdd(m_xBuilder->weld_button("add"))
249 , m_xBtnRemove(m_xBuilder->weld_button("remove"))
250 , m_xLbCustomPages(m_xBuilder->weld_tree_view("custompages"))
251 , m_xDropTargetHelper(new weld::ReorderingDropTarget(*m_xLbCustomPages))
252 , m_xBtnOK(m_xBuilder->weld_button("ok"))
253{
254 Link<weld::Button&,void> aLink = LINK( this, SdDefineCustomShowDlg, ClickButtonHdl );
255 m_xBtnAdd->connect_clicked( aLink );
256 m_xBtnRemove->connect_clicked( aLink );
257 m_xEdtName->connect_changed( LINK( this, SdDefineCustomShowDlg, ClickButtonEditHdl ) );
258 m_xLbPages->connect_changed( LINK( this, SdDefineCustomShowDlg, ClickButtonHdl4 ) ); // because of status
259 m_xLbCustomPages->connect_changed( LINK( this, SdDefineCustomShowDlg, ClickButtonHdl3 ) ); // because of status
260
261 m_xBtnOK->connect_clicked( LINK( this, SdDefineCustomShowDlg, OKHdl ) );
262
263 m_xLbPages->set_selection_mode(SelectionMode::Multiple);
264
265 // shape 'em a bit
266 m_xLbPages->set_size_request(m_xLbPages->get_approximate_digit_width() * 24, m_xLbPages->get_height_rows(10));
267 m_xLbCustomPages->set_size_request(m_xLbPages->get_approximate_digit_width() * 24, m_xLbCustomPages->get_height_rows(10));
268
269 // fill Listbox with page names of Docs
270 for( tools::Long nPage = 0;
272 nPage++ )
273 {
274 SdPage* pPage = rDoc.GetSdPage( static_cast<sal_uInt16>(nPage), PageKind::Standard );
275 m_xLbPages->append_text(pPage->GetName());
276 }
277 // aLbPages.SelectEntryPos( 0 );
278
279 if( rpCustomShow )
280 {
281 aOldName = rpCustomShow->GetName();
282 m_xEdtName->set_text( aOldName );
283
284 // fill ListBox with CustomShow pages
285 for( const auto& rpPage : rpCustomShow->PagesVector() )
286 {
287 m_xLbCustomPages->append(weld::toId(rpPage), rpPage->GetName(), "");
288 }
289 }
290 else
291 {
292 rpCustomShow.reset(new SdCustomShow);
293 m_xEdtName->set_text( SdResId( STR_NEW_CUSTOMSHOW ) );
294 m_xEdtName->select_region(0, -1);
295 rpCustomShow->SetName( m_xEdtName->get_text() );
296 }
297
298 m_xBtnOK->set_sensitive( false );
299 CheckState();
300}
301
303{
304}
305
306// CheckState
308{
309 bool bPages = m_xLbPages->count_selected_rows() > 0;
310 bool bCSPages = m_xLbCustomPages->get_selected_index() != -1;
311 bool bCount = m_xLbCustomPages->n_children() > 0;
312
313 m_xBtnOK->set_sensitive( bCount );
314 m_xBtnAdd->set_sensitive( bPages );
315 m_xBtnRemove->set_sensitive( bCSPages );
316}
317
318IMPL_LINK( SdDefineCustomShowDlg, ClickButtonHdl, weld::Button&, rWidget, void )
319{
320 ClickButtonHdl2(&rWidget);
321}
322
323IMPL_LINK( SdDefineCustomShowDlg, ClickButtonHdl3, weld::TreeView&, rWidget, void )
324{
325 ClickButtonHdl2(&rWidget);
326}
327
328IMPL_LINK( SdDefineCustomShowDlg, ClickButtonHdl4, weld::TreeView&, rListBox, void )
329{
330 ClickButtonHdl2(&rListBox);
331}
332
333IMPL_LINK( SdDefineCustomShowDlg, ClickButtonEditHdl, weld::Entry&, rEdit, void )
334{
335 ClickButtonHdl2(&rEdit);
336}
337
338// ButtonHdl()
340{
341 if( p == m_xBtnAdd.get() )
342 {
343 auto aRows = m_xLbPages->get_selected_rows();
344 if (!aRows.empty())
345 {
346 int nPosCP = m_xLbCustomPages->get_selected_index();
347 if (nPosCP != -1)
348 ++nPosCP;
349
350 for (auto i : aRows)
351 {
352 OUString aStr = m_xLbPages->get_text(i);
354 OUString sId(weld::toId(pPage));
355 m_xLbCustomPages->insert(nPosCP, aStr, &sId, nullptr, nullptr);
356 m_xLbCustomPages->select(nPosCP != -1 ? nPosCP : m_xLbCustomPages->n_children() - 1);
357
358 if (nPosCP != -1)
359 ++nPosCP;
360 }
361 bModified = true;
362 }
363 }
364 else if (p == m_xBtnRemove.get())
365 {
366 int nPos = m_xLbCustomPages->get_selected_index();
367 if (nPos != -1)
368 {
369 m_xLbCustomPages->remove(nPos);
370 m_xLbCustomPages->select(nPos == 0 ? nPos : nPos - 1);
371 bModified = true;
372 }
373 }
374 else if( p == m_xEdtName.get() )
375 {
376 bModified = true;
377 }
378
379 CheckState();
380}
381
387{
388 bool bDifferent = false;
389
390 // compare count
391 size_t nCount = m_xLbCustomPages->n_children();
392 if (rpCustomShow->PagesVector().size() != nCount)
393 {
394 rpCustomShow->PagesVector().clear();
395 bDifferent = true;
396 }
397
398 // compare page pointer
399 if( !bDifferent )
400 {
401 size_t i = 0;
402 for (const auto& rpPage : rpCustomShow->PagesVector())
403 {
404 SdPage* pPage = weld::fromId<SdPage*>(m_xLbCustomPages->get_id(i));
405 if (rpPage != pPage)
406 {
407 rpCustomShow->PagesVector().clear();
408 bDifferent = true;
409 break;
410 }
411
412 ++i;
413 }
414 }
415
416 // set new page pointer
417 if( bDifferent )
418 {
419 for (size_t i = 0; i < nCount; ++i)
420 {
421 SdPage* pPage = weld::fromId<SdPage*>(m_xLbCustomPages->get_id(i));
422 rpCustomShow->PagesVector().push_back(pPage);
423 }
424 bModified = true;
425 }
426
427 // compare name and set name if necessary
428 OUString aStr( m_xEdtName->get_text() );
429 if( rpCustomShow->GetName() != aStr )
430 {
431 rpCustomShow->SetName( aStr );
432 bModified = true;
433 }
434}
435
436// OK-Hdl
438{
439 // check name...
440 bool bDifferent = true;
441 SdCustomShowList* pCustomShowList = rDoc.GetCustomShowList();
442 if( pCustomShowList )
443 {
444 OUString aName( m_xEdtName->get_text() );
445 SdCustomShow* pCustomShow;
446
447 tools::Long nPosToSelect = pCustomShowList->GetCurPos();
448 for( pCustomShow = pCustomShowList->First();
449 pCustomShow != nullptr;
450 pCustomShow = pCustomShowList->Next() )
451 {
452 if( aName == pCustomShow->GetName() && aName != aOldName )
453 bDifferent = false;
454 }
455 pCustomShowList->Seek( nPosToSelect );
456 }
457
458 if( bDifferent )
459 {
460 CheckCustomShow();
461
462 m_xDialog->response(RET_OK);
463 }
464 else
465 {
466 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(m_xDialog.get(),
467 VclMessageType::Warning, VclButtonsType::Ok,
468 SdResId(STR_WARN_NAME_DUPLICATE)));
469 xWarn->run();
470 m_xEdtName->grab_focus();
471 }
472}
473
474/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
std::unique_ptr< weld::Button > m_xBtnEdit
Definition: custsdlg.hxx:37
bool IsCustomShow() const
Definition: custsdlg.cxx:232
std::unique_ptr< weld::Button > m_xBtnRemove
Definition: custsdlg.hxx:38
SdCustomShowDlg(weld::Window *pWindow, SdDrawDocument &rDrawDoc)
Definition: custsdlg.cxx:35
SdDrawDocument & rDoc
Definition: custsdlg.hxx:32
std::unique_ptr< weld::Button > m_xBtnCopy
Definition: custsdlg.hxx:39
std::unique_ptr< weld::TreeView > m_xLbCustomShows
Definition: custsdlg.hxx:35
std::unique_ptr< weld::Button > m_xBtnStartShow
Definition: custsdlg.hxx:40
void CheckState()
Definition: custsdlg.cxx:81
void SelectHdl(void const *)
Definition: custsdlg.cxx:105
SdCustomShowList * pCustomShowList
Definition: custsdlg.hxx:33
virtual ~SdCustomShowDlg() override
Definition: custsdlg.cxx:77
std::unique_ptr< weld::Button > m_xBtnNew
Definition: custsdlg.hxx:36
bool empty() const
void push_back(std::unique_ptr< SdCustomShow > p)
sal_uInt16 GetCurPos() const
SdCustomShow * Next()
void erase(std::vector< std::unique_ptr< SdCustomShow > >::iterator it)
Definition: cusshow.cxx:96
void Seek(sal_uInt16 nNewPos)
SdCustomShow * First()
std::vector< std::unique_ptr< SdCustomShow > >::iterator begin()
const OUString & GetName() const
Definition: cusshow.hxx:60
SdDefineCustomShowDlg(weld::Window *pWindow, SdDrawDocument &rDrawDoc, std::unique_ptr< SdCustomShow > &rpCS)
Definition: custsdlg.cxx:241
std::unique_ptr< weld::TreeView > m_xLbPages
Definition: custsdlg.hxx:64
SdDrawDocument & rDoc
Definition: custsdlg.hxx:58
std::unique_ptr< weld::Button > m_xBtnOK
Definition: custsdlg.hxx:69
std::unique_ptr< SdCustomShow > & rpCustomShow
Definition: custsdlg.hxx:59
std::unique_ptr< weld::Entry > m_xEdtName
Definition: custsdlg.hxx:63
std::unique_ptr< weld::Button > m_xBtnAdd
Definition: custsdlg.hxx:65
void ClickButtonHdl2(void const *)
Definition: custsdlg.cxx:339
std::unique_ptr< weld::Button > m_xBtnRemove
Definition: custsdlg.hxx:66
void CheckCustomShow()
Checks the page pointer of the Show since entries can be moved and copied by TreeLB.
Definition: custsdlg.cxx:386
std::unique_ptr< weld::TreeView > m_xLbCustomPages
Definition: custsdlg.hxx:67
virtual ~SdDefineCustomShowDlg() override
Definition: custsdlg.cxx:302
SdPage * GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
Definition: drawdoc2.cxx:207
SdCustomShowList * GetCustomShowList(bool bCreate=false)
Definition: drawdoc3.cxx:1161
SAL_DLLPRIVATE const std::optional< CharClass > & GetCharClass() const
Definition: drawdoc.hxx:468
sal_uInt16 GetSdPageCount(PageKind ePgKind) const
Definition: drawdoc2.cxx:212
const OUString & GetName() const
Definition: sdpage.cxx:2505
virtual short run()
std::shared_ptr< weld::Dialog > m_xDialog
int nCount
IMPL_LINK_NOARG(SdCustomShowDlg, StartShowHdl, weld::Button &, void)
Definition: custsdlg.cxx:226
IMPL_LINK(SdCustomShowDlg, ClickButtonHdl, weld::Button &, r, void)
Definition: custsdlg.cxx:95
#define DBG_ASSERT(sCon, aError)
float u
OUString aName
void * p
sal_uInt16 nPos
aStr
int i
long Long
OUString toId(const void *pValue)
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
OUString sId
RET_OK
RET_YES