LibreOffice Module cui (master)  1
tplnedef.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 <tools/urlobj.hxx>
21 #include <vcl/settings.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/weld.hxx>
24 #include <unotools/pathoptions.hxx>
25 #include <sfx2/app.hxx>
26 #include <sfx2/module.hxx>
27 #include <sfx2/filedlghelper.hxx>
28 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
29 
30 #include <strings.hrc>
31 
32 #include <svx/xlineit0.hxx>
33 #include <svx/xlnwtit.hxx>
34 #include <svx/xlndsit.hxx>
35 #include <svx/xlnclit.hxx>
36 #include <svx/xpool.hxx>
37 #include <svx/xtable.hxx>
38 
39 #include <svx/dlgctrl.hxx>
40 #include <svx/drawitem.hxx>
41 #include <cuitabline.hxx>
42 #include <dlgname.hxx>
43 #include <defdlgname.hxx>
44 #include <svx/svxdlg.hxx>
45 #include <dialmgr.hxx>
46 #include <svx/dlgutil.hxx>
47 #include <svx/dialmgr.hxx>
48 #include <svx/dialogs.hrc>
49 #include <svx/strings.hrc>
50 #include <svx/svxids.hrc>
51 #include <cuitabarea.hxx>
52 #include <svtools/unitconv.hxx>
53 
54 #define XOUT_WIDTH 150
55 
56 using namespace com::sun::star;
57 
58 
60  : SfxTabPage(pParent, "cui/ui/linestyletabpage.ui", "LineStylePage", &rInAttrs)
61  , rOutAttrs(rInAttrs)
62  , aXLineAttr(rInAttrs.GetPool())
63  , rXLSet(aXLineAttr.GetItemSet())
64  , pnDashListState(nullptr)
65  , pPageType(nullptr)
66  , nDlgType(0)
67  , pPosDashLb(nullptr)
68  , m_xLbLineStyles(new SvxLineLB(m_xBuilder->weld_combo_box("LB_LINESTYLES")))
69  , m_xLbType1(m_xBuilder->weld_combo_box("LB_TYPE_1"))
70  , m_xLbType2(m_xBuilder->weld_combo_box("LB_TYPE_2"))
71  , m_xNumFldNumber1(m_xBuilder->weld_spin_button("NUM_FLD_1"))
72  , m_xNumFldNumber2(m_xBuilder->weld_spin_button("NUM_FLD_2"))
73  , m_xMtrLength1(m_xBuilder->weld_metric_spin_button("MTR_FLD_LENGTH_1", FieldUnit::CM))
74  , m_xMtrLength2(m_xBuilder->weld_metric_spin_button("MTR_FLD_LENGTH_2", FieldUnit::CM))
75  , m_xMtrDistance(m_xBuilder->weld_metric_spin_button("MTR_FLD_DISTANCE", FieldUnit::CM))
76  , m_xCbxSynchronize(m_xBuilder->weld_check_button("CBX_SYNCHRONIZE"))
77  , m_xBtnAdd(m_xBuilder->weld_button("BTN_ADD"))
78  , m_xBtnModify(m_xBuilder->weld_button("BTN_MODIFY"))
79  , m_xBtnDelete(m_xBuilder->weld_button("BTN_DELETE"))
80  , m_xBtnLoad(m_xBuilder->weld_button("BTN_LOAD"))
81  , m_xBtnSave(m_xBuilder->weld_button("BTN_SAVE"))
82  , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder, "CTL_PREVIEW", m_aCtlPreview))
83 {
84  // this page needs ExchangeSupport
86 
87  // adjust metric
88  eFUnit = GetModuleFieldUnit( rInAttrs );
89 
90  switch ( eFUnit )
91  {
92  case FieldUnit::M:
93  case FieldUnit::KM:
94  eFUnit = FieldUnit::MM;
95  break;
96  default: ; //prevent warning
97  }
101 
102  // determine PoolUnit
103  SfxItemPool* pPool = rOutAttrs.GetPool();
104  DBG_ASSERT( pPool, "Where is the pool?" );
105  ePoolUnit = pPool->GetMetric( SID_ATTR_LINE_WIDTH );
106 
107  rXLSet.Put( XLineStyleItem(drawing::LineStyle_DASH) );
109  rXLSet.Put( XLineDashItem( OUString(), XDash( css::drawing::DashStyle_RECT, 3, 7, 2, 40, 15 ) ) );
110  rXLSet.Put( XLineColorItem(OUString(), COL_BLACK) );
111 
112  // #i34740#
114 
115  m_xBtnAdd->connect_clicked(LINK(this, SvxLineDefTabPage, ClickAddHdl_Impl));
116  m_xBtnModify->connect_clicked(LINK(this, SvxLineDefTabPage, ClickModifyHdl_Impl));
117  m_xBtnDelete->connect_clicked(LINK(this, SvxLineDefTabPage, ClickDeleteHdl_Impl));
118  m_xBtnLoad->connect_clicked(LINK(this, SvxLineDefTabPage, ClickLoadHdl_Impl));
119  m_xBtnSave->connect_clicked(LINK(this, SvxLineDefTabPage, ClickSaveHdl_Impl));
120 
121  m_xNumFldNumber1->connect_value_changed(LINK(this, SvxLineDefTabPage, ChangeNumber1Hdl_Impl));
122  m_xNumFldNumber2->connect_value_changed(LINK(this, SvxLineDefTabPage, ChangeNumber2Hdl_Impl));
123  m_xLbLineStyles->connect_changed(LINK(this, SvxLineDefTabPage, SelectLinestyleListBoxHdl_Impl));
124 
125  // #i122042# switch off default adding of 'none' and 'solid' entries
126  // for this ListBox; we want to select only editable/dashed styles
127  m_xLbLineStyles->setAddStandardFields(false);
128 
129  // absolute (in mm) or relative (in %)
131 
132  // preview must be updated when there's something changed
133  Link<weld::ComboBox&, void> aLink = LINK(this, SvxLineDefTabPage, SelectTypeListBoxHdl_Impl);
134  m_xLbType1->connect_changed(aLink);
135  m_xLbType2->connect_changed(aLink);
136  Link<weld::MetricSpinButton&,void> aLink2 = LINK( this, SvxLineDefTabPage, ChangePreviewHdl_Impl );
137  m_xMtrLength1->connect_value_changed(aLink2);
138  m_xMtrLength2->connect_value_changed(aLink2);
139  m_xMtrDistance->connect_value_changed(aLink2);
140 
141  pDashList = nullptr;
142 }
143 
145 {
146  disposeOnce();
147 }
148 
150 {
151  m_xCtlPreview.reset();
152  m_xLbLineStyles.reset();
154 }
155 
157 {
158  // Line style fill; do *not* add default fields here
159  m_xLbLineStyles->Fill( pDashList );
160 }
161 
163 {
164  if( nDlgType == 0 ) // area dialog
165  {
166  // ActivatePage() is called before the dialog receives PageCreated() !!!
167  if( pDashList.is() )
168  {
169  if (*pPageType == PageType::Gradient &&
170  *pPosDashLb != -1)
171  {
172  m_xLbLineStyles->set_active(*pPosDashLb);
173  }
174  // so that a possibly existing line style is discarded
175  SelectLinestyleHdl_Impl( nullptr );
176 
177  // determining (and possibly cutting) the name
178  // and displaying it in the GroupBox
179 // OUString aString( CuiResId( RID_SVXSTR_TABLE ) );
180 // aString += ": ";
181  INetURLObject aURL( pDashList->GetPath() );
182 
183  aURL.Append( pDashList->GetName() );
184  DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
185 
186  *pPageType = PageType::Area; // 2
188  }
189  }
190 }
191 
192 
194 {
196 
197  if( _pSet )
198  FillItemSet( _pSet );
199 
200  return DeactivateRC::LeavePage;
201 }
202 
204 {
205  // is here used to NOT lose changes
206  //css::drawing::DashStyle eXDS;
207 
208  if( m_xNumFldNumber1->get_value_changed_from_saved() ||
209  m_xMtrLength1->get_value_changed_from_saved() ||
210  m_xLbType1->get_value_changed_from_saved() ||
211  m_xNumFldNumber2->get_value_changed_from_saved() ||
212  m_xMtrLength2->get_value_changed_from_saved() ||
213  m_xLbType2->get_value_changed_from_saved() ||
214  m_xMtrDistance->get_value_changed_from_saved() )
215  {
216  std::unique_ptr<weld::MessageDialog> xMessDlg(Application::CreateMessageDialog(GetDialogFrameWeld(),
217  VclMessageType::Warning, VclButtonsType::Cancel,
218  CuiResId(RID_SVXSTR_ASK_CHANGE_LINESTYLE)));
219  xMessDlg->set_title(SvxResId(RID_SVXSTR_LINESTYLE));
220  xMessDlg->add_button(CuiResId(RID_SVXSTR_CHANGE), RET_BTN_1);
221  xMessDlg->add_button(CuiResId(RID_SVXSTR_ADD), RET_BTN_2);
222 
223  short nRet = xMessDlg->run();
224 
225  switch( nRet )
226  {
227  case RET_BTN_1:
228  {
229  ClickModifyHdl_Impl(*m_xBtnModify);
230  }
231  break;
232 
233  case RET_BTN_2:
234  {
235  ClickAddHdl_Impl(*m_xBtnAdd);
236  }
237  break;
238 
239  case RET_CANCEL:
240  break;
241  }
242  }
243 
244  int nPos = m_xLbLineStyles->get_active();
245  if (nPos != -1)
246  {
247  *pPosDashLb = nPos;
248  }
249 }
250 
251 
253 {
254  if( nDlgType == 0 ) // line dialog
255  {
256  if( *pPageType == PageType::Hatch )
257  {
258  FillDash_Impl();
259 
260  OUString aString(m_xLbLineStyles->get_active_text());
261  rAttrs->Put( XLineStyleItem( drawing::LineStyle_DASH ) );
262  rAttrs->Put( XLineDashItem( aString, aDash ) );
263  }
264  }
265  return true;
266 }
267 
268 
270 {
271  if( rAttrs->GetItemState( GetWhich( XATTR_LINESTYLE ) ) != SfxItemState::DONTCARE )
272  {
273  drawing::LineStyle eXLS = static_cast<const XLineStyleItem&>( rAttrs->Get( GetWhich( XATTR_LINESTYLE ) ) ).GetValue();
274 
275  switch( eXLS )
276  {
277  case drawing::LineStyle_NONE:
278  case drawing::LineStyle_SOLID:
279  m_xLbLineStyles->set_active(0);
280  break;
281  case drawing::LineStyle_DASH:
282  {
283  const XLineDashItem& rDashItem = rAttrs->Get( XATTR_LINEDASH );
284  aDash = rDashItem.GetDashValue();
285 
286  m_xLbLineStyles->set_active(-1);
287  m_xLbLineStyles->set_active_text(rDashItem.GetName());
288  break;
289  }
290  default:
291  break;
292  }
293  }
294  SelectLinestyleHdl_Impl( nullptr );
295 
296  // determine button state
297  if( pDashList->Count() )
298  {
299  m_xBtnModify->set_sensitive(true);
300  m_xBtnDelete->set_sensitive(true);
301  m_xBtnSave->set_sensitive(true);
302  }
303  else
304  {
305  m_xBtnModify->set_sensitive(false);
306  m_xBtnDelete->set_sensitive(false);
307  m_xBtnSave->set_sensitive(false);
308  }
309 }
310 
312 {
313  return VclPtr<SvxLineDefTabPage>::Create(pParent, *rOutAttrs);
314 }
315 
316 IMPL_LINK(SvxLineDefTabPage, SelectLinestyleListBoxHdl_Impl, weld::ComboBox&, rListBox, void)
317 {
318  SelectLinestyleHdl_Impl(&rListBox);
319 }
320 
322 {
323  if(pDashList->Count())
324  {
325  int nTmp = m_xLbLineStyles->get_active();
326  if (nTmp == -1)
327  {
328  OSL_ENSURE(false, "OOps, non-existent LineDash selected (!)");
329  nTmp = 1;
330  }
331 
332  aDash = pDashList->GetDash( nTmp )->GetDash();
333 
334  FillDialog_Impl();
335 
336  rXLSet.Put( XLineDashItem( OUString(), aDash ) );
337 
338  // #i34740#
340  m_aCtlPreview.Invalidate();
341 
342  // Is not set before, in order to take the new style
343  // only if there was an entry selected in the ListBox.
344  // If it was called via Reset(), then p is == NULL
345  if( p )
347  }
348 }
349 
351 {
352  FillDash_Impl();
353  m_aCtlPreview.Invalidate();
354 }
355 
356 IMPL_LINK_NOARG(SvxLineDefTabPage, ChangeNumber1Hdl_Impl, weld::SpinButton&, void)
357 {
358  if (m_xNumFldNumber1->get_value() == 0)
359  {
360  m_xNumFldNumber2->set_min(1);
361  }
362  else
363  {
364  m_xNumFldNumber2->set_min(0);
365  }
366 
367  ChangePreviewHdl_Impl(*m_xMtrLength1);
368 }
369 
370 IMPL_LINK_NOARG(SvxLineDefTabPage, ChangeNumber2Hdl_Impl, weld::SpinButton&, void)
371 {
372  if (m_xNumFldNumber2->get_value() == 0)
373  {
374  m_xNumFldNumber1->set_min(1);
375  }
376  else
377  {
378  m_xNumFldNumber1->set_min(0);
379  }
380 
381  ChangePreviewHdl_Impl(*m_xMtrLength1);
382 }
383 
384 IMPL_LINK( SvxLineDefTabPage, ChangeMetricHdl_Impl, weld::ToggleButton&, r, void)
385 {
386  ChangeMetricHdl_Impl(&r);
387 }
388 
390 {
391  if( !m_xCbxSynchronize->get_active() && m_xMtrLength1->get_unit() != eFUnit )
392  {
393  long nTmp1, nTmp2, nTmp3;
394 
395  // was changed with Control
396  if( p )
397  {
398  nTmp1 = GetCoreValue( *m_xMtrLength1, ePoolUnit ) * XOUT_WIDTH / 100;
399  nTmp2 = GetCoreValue( *m_xMtrLength2, ePoolUnit ) * XOUT_WIDTH / 100;
400  nTmp3 = GetCoreValue( *m_xMtrDistance, ePoolUnit ) * XOUT_WIDTH / 100;
401  }
402  else
403  {
404  nTmp1 = GetCoreValue( *m_xMtrLength1, ePoolUnit );
405  nTmp2 = GetCoreValue( *m_xMtrLength2, ePoolUnit );
407  }
408  m_xMtrLength1->set_digits(2);
409  m_xMtrLength2->set_digits(2);
410  m_xMtrDistance->set_digits(2);
411 
412  // adjust metric
413  m_xMtrLength1->set_unit(eFUnit);
414  m_xMtrLength2->set_unit(eFUnit);
415  m_xMtrDistance->set_unit(eFUnit);
416 
417  // tdf#126736 max 5cm
418  m_xMtrLength1->set_range(0, 500, FieldUnit::CM);
419  m_xMtrLength2->set_range(0, 500, FieldUnit::CM);
420  m_xMtrDistance->set_range(0, 500, FieldUnit::CM);
421 
425  }
426  else if( m_xCbxSynchronize->get_active() && m_xMtrLength1->get_unit() != FieldUnit::PERCENT )
427  {
428  long nTmp1, nTmp2, nTmp3;
429 
430  // was changed with Control
431  if( p )
432  {
433  nTmp1 = GetCoreValue( *m_xMtrLength1, ePoolUnit ) * 100 / XOUT_WIDTH;
434  nTmp2 = GetCoreValue( *m_xMtrLength2, ePoolUnit ) * 100 / XOUT_WIDTH;
435  nTmp3 = GetCoreValue( *m_xMtrDistance, ePoolUnit ) * 100 / XOUT_WIDTH;
436  }
437  else
438  {
439  nTmp1 = GetCoreValue( *m_xMtrLength1, ePoolUnit );
440  nTmp2 = GetCoreValue( *m_xMtrLength2, ePoolUnit );
442  }
443 
444  m_xMtrLength1->set_digits(0);
445  m_xMtrLength2->set_digits(0);
446  m_xMtrDistance->set_digits(0);
447 
448  m_xMtrLength1->set_unit(FieldUnit::PERCENT);
449  m_xMtrLength2->set_unit(FieldUnit::PERCENT);
450  m_xMtrDistance->set_unit(FieldUnit::PERCENT);
451 
452  // tdf#126736 800%
453  m_xMtrLength1->set_range(0, 800, FieldUnit::PERCENT);
454  m_xMtrLength2->set_range(0, 800, FieldUnit::PERCENT);
455  m_xMtrDistance->set_range(0, 800, FieldUnit::PERCENT);
456 
457  m_xMtrLength1->set_value(nTmp1, FieldUnit::PERCENT);
458  m_xMtrLength2->set_value(nTmp2, FieldUnit::PERCENT);
459  m_xMtrDistance->set_value(nTmp3, FieldUnit::PERCENT);
460  }
461  SelectTypeHdl_Impl( nullptr );
462 }
463 
464 IMPL_LINK( SvxLineDefTabPage, SelectTypeListBoxHdl_Impl, weld::ComboBox&, rListBox, void )
465 {
466  SelectTypeHdl_Impl(&rListBox);
467 }
468 
470 {
471  if (p == m_xLbType1.get() || !p)
472  {
473  if (m_xLbType1->get_active() == 0)
474  {
475  m_xMtrLength1->set_sensitive(false);
476  m_xMtrLength1->set_text("");
477  }
478  else if (!m_xMtrLength1->get_sensitive())
479  {
480  m_xMtrLength1->set_sensitive(true);
481  m_xMtrLength1->reformat();
482  }
483  }
484 
485  if (p == m_xLbType2.get() || !p)
486  {
487  if (m_xLbType2->get_active() == 0)
488  {
489  m_xMtrLength2->set_sensitive(false);
490  m_xMtrLength2->set_text("");
491  }
492  else if (!m_xMtrLength2->get_sensitive())
493  {
494  m_xMtrLength2->set_sensitive(true);
495  m_xMtrLength2->reformat();
496  }
497  }
498  ChangePreviewHdl_Impl(*m_xMtrLength1);
499 }
500 
502 {
503  OUString aNewName(SvxResId(RID_SVXSTR_LINESTYLE));
504  OUString aDesc(CuiResId(RID_SVXSTR_DESC_LINESTYLE));
505  OUString aName;
506 
507  long nCount = pDashList->Count();
508  long j = 1;
509  bool bDifferent = false;
510 
511  while ( !bDifferent )
512  {
513  aName = aNewName + " " + OUString::number( j++ );
514  bDifferent = true;
515 
516  for ( long i = 0; i < nCount && bDifferent; i++ )
517  if ( aName == pDashList->GetDash( i )->GetName() )
518  bDifferent = false;
519  }
520 
522  ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetDialogFrameWeld(), aName, aDesc));
523  bool bLoop = true;
524 
525  while ( bLoop && pDlg->Execute() == RET_OK )
526  {
527  pDlg->GetName( aName );
528  bDifferent = true;
529 
530  for( long i = 0; i < nCount && bDifferent; i++ )
531  {
532  if( aName == pDashList->GetDash( i )->GetName() )
533  bDifferent = false;
534  }
535 
536  if( bDifferent )
537  {
538  bLoop = false;
539  FillDash_Impl();
540 
541  long nDashCount = pDashList->Count();
542  pDashList->Insert( std::make_unique<XDashEntry>(aDash, aName), nDashCount );
543  m_xLbLineStyles->Append( *pDashList->GetDash(nDashCount), pDashList->GetUiBitmap(nDashCount) );
544 
545  m_xLbLineStyles->set_active(m_xLbLineStyles->get_count() - 1);
546 
547  *pnDashListState |= ChangeType::MODIFIED;
548 
549  *pPageType = PageType::Hatch;
550 
551  // save values for changes recognition (-> method)
552  m_xNumFldNumber1->save_value();
553  m_xMtrLength1->save_value();
554  m_xLbType1->save_value();
555  m_xNumFldNumber2->save_value();
556  m_xMtrLength2->save_value();
557  m_xLbType2->save_value();
558  m_xMtrDistance->save_value();
559  }
560  else
561  {
562  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
563  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
564  xBox->run();
565  }
566  }
567  pDlg.disposeAndClear();
568 
569  // determine button state
570  if ( pDashList->Count() )
571  {
572  m_xBtnModify->set_sensitive(true);
573  m_xBtnDelete->set_sensitive(true);
574  m_xBtnSave->set_sensitive(true);
575  }
576 }
577 
578 IMPL_LINK_NOARG(SvxLineDefTabPage, ClickModifyHdl_Impl, weld::Button&, void)
579 {
580  int nPos = m_xLbLineStyles->get_active();
581  if (nPos != -1)
582  {
583  OUString aDesc(CuiResId(RID_SVXSTR_DESC_LINESTYLE));
584  OUString aName( pDashList->GetDash( nPos )->GetName() );
585  OUString aOldName = aName;
586 
588  ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetDialogFrameWeld(), aName, aDesc));
589 
590  long nCount = pDashList->Count();
591  bool bLoop = true;
592 
593  while ( bLoop && pDlg->Execute() == RET_OK )
594  {
595  pDlg->GetName( aName );
596  bool bDifferent = true;
597 
598  for( long i = 0; i < nCount && bDifferent; i++ )
599  {
600  if( aName == pDashList->GetDash( i )->GetName() &&
601  aName != aOldName )
602  bDifferent = false;
603  }
604 
605  if ( bDifferent )
606  {
607  bLoop = false;
608  FillDash_Impl();
609 
610  pDashList->Replace(std::make_unique<XDashEntry>(aDash, aName), nPos);
611  m_xLbLineStyles->Modify(*pDashList->GetDash(nPos), nPos, pDashList->GetUiBitmap(nPos));
612 
613  m_xLbLineStyles->set_active(nPos);
614 
615  *pnDashListState |= ChangeType::MODIFIED;
616 
617  *pPageType = PageType::Hatch;
618 
619  // save values for changes recognition (-> method)
620  m_xNumFldNumber1->save_value();
621  m_xMtrLength1->save_value();
622  m_xLbType1->save_value();
623  m_xNumFldNumber2->save_value();
624  m_xMtrLength2->save_value();
625  m_xLbType2->save_value();
626  m_xMtrDistance->save_value();
627  }
628  else
629  {
630  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
631  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
632  xBox->run();
633  }
634  }
635  }
636 }
637 
638 IMPL_LINK_NOARG(SvxLineDefTabPage, ClickDeleteHdl_Impl, weld::Button&, void)
639 {
640  int nPos = m_xLbLineStyles->get_active();
641  if (nPos != -1)
642  {
643  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/querydeletelinestyledialog.ui"));
644  std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("AskDelLineStyleDialog"));
645  if (xQueryBox->run() == RET_YES)
646  {
647  pDashList->Remove(nPos);
648  m_xLbLineStyles->remove(nPos);
649  m_xLbLineStyles->set_active(0);
650 
651  SelectLinestyleHdl_Impl( nullptr );
652  *pPageType = PageType::Area; // style should not be taken
653 
654  *pnDashListState |= ChangeType::MODIFIED;
655 
656  ChangePreviewHdl_Impl( *m_xMtrLength1 );
657  }
658  }
659 
660  // determine button state
661  if ( !pDashList->Count() )
662  {
663  m_xBtnModify->set_sensitive(false);
664  m_xBtnDelete->set_sensitive(false);
665  m_xBtnSave->set_sensitive(false);
666  }
667 }
668 
669 IMPL_LINK_NOARG(SvxLineDefTabPage, ClickLoadHdl_Impl, weld::Button&, void)
670 {
671  sal_uInt16 nReturn = RET_YES;
672 
673  if ( *pnDashListState & ChangeType::MODIFIED )
674  {
675  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/querysavelistdialog.ui"));
676  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("AskSaveList"));
677 
678  nReturn = xBox->run();
679 
680  if ( nReturn == RET_YES )
681  pDashList->Save();
682  }
683 
684  if ( nReturn != RET_CANCEL )
685  {
686  ::sfx2::FileDialogHelper aDlg(css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
687  FileDialogFlags::NONE, GetDialogFrameWeld());
688  OUString aStrFilterType( "*.sod" );
689  aDlg.AddFilter( aStrFilterType, aStrFilterType );
690  OUString aPalettePath(SvtPathOptions().GetPalettePath());
691  OUString aLastDir;
692  sal_Int32 nIndex = 0;
693  do
694  {
695  aLastDir = aPalettePath.getToken(0, ';', nIndex);
696  }
697  while (nIndex >= 0);
698 
699  INetURLObject aFile(aLastDir);
701 
702  if( aDlg.Execute() == ERRCODE_NONE )
703  {
704  INetURLObject aURL( aDlg.GetPath() );
705  INetURLObject aPathURL( aURL );
706 
707  aPathURL.removeSegment();
708  aPathURL.removeFinalSlash();
709 
710  XDashListRef pDshLst = XPropertyList::AsDashList(XPropertyList::CreatePropertyList( XPropertyListType::Dash, aPathURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), "" ));
711  pDshLst->SetName( aURL.getName() );
712 
713  if( pDshLst->Load() )
714  {
715  pDashList = pDshLst;
716  static_cast<SvxLineTabDialog*>(GetDialogController())->SetNewDashList( pDashList );
717 
718  m_xLbLineStyles->clear();
719  m_xLbLineStyles->Fill( pDashList );
720  Reset( &rOutAttrs );
721 
722  pDashList->SetName( aURL.getName() );
723 
724  *pnDashListState |= ChangeType::CHANGED;
725  *pnDashListState &= ~ChangeType::MODIFIED;
726  }
727  else
728  {
729  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/querynoloadedfiledialog.ui"));
730  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("NoLoadedFileDialog"));
731  xBox->run();
732  }
733  }
734  }
735 
736  // determine button state
737  if ( pDashList->Count() )
738  {
739  m_xBtnModify->set_sensitive(true);
740  m_xBtnDelete->set_sensitive(true);
741  m_xBtnSave->set_sensitive(true);
742  }
743  else
744  {
745  m_xBtnModify->set_sensitive(false);
746  m_xBtnDelete->set_sensitive(false);
747  m_xBtnSave->set_sensitive(false);
748  }
749 }
750 
751 IMPL_LINK_NOARG(SvxLineDefTabPage, ClickSaveHdl_Impl, weld::Button&, void)
752 {
753  ::sfx2::FileDialogHelper aDlg(css::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, FileDialogFlags::NONE, GetDialogFrameWeld());
754  OUString aStrFilterType( "*.sod" );
755  aDlg.AddFilter( aStrFilterType, aStrFilterType );
756 
757  OUString aPalettePath(SvtPathOptions().GetPalettePath());
758  OUString aLastDir;
759  sal_Int32 nIndex = 0;
760  do
761  {
762  aLastDir = aPalettePath.getToken(0, ';', nIndex);
763  }
764  while (nIndex >= 0);
765 
766  INetURLObject aFile(aLastDir);
767  DBG_ASSERT( aFile.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
768 
769  if( !pDashList->GetName().isEmpty() )
770  {
771  aFile.Append( pDashList->GetName() );
772 
773  if( aFile.getExtension().isEmpty() )
774  aFile.SetExtension( "sod" );
775  }
776 
778  if ( aDlg.Execute() == ERRCODE_NONE )
779  {
780  INetURLObject aURL( aDlg.GetPath() );
781  INetURLObject aPathURL( aURL );
782 
783  aPathURL.removeSegment();
784  aPathURL.removeFinalSlash();
785 
786  pDashList->SetName( aURL.getName() );
787  pDashList->SetPath( aPathURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
788 
789  if( pDashList->Save() )
790  {
791  *pnDashListState &= ~ChangeType::MODIFIED;
792  }
793  else
794  {
795  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "cui/ui/querynosavefiledialog.ui"));
796  std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("NoSaveFileDialog"));
797  xBox->run();
798  }
799  }
800 }
801 
803 {
804  css::drawing::DashStyle eXDS;
805 
806  if (m_xCbxSynchronize->get_active())
807  eXDS = css::drawing::DashStyle_RECTRELATIVE;
808  else
809  eXDS = css::drawing::DashStyle_RECT;
810 
811  aDash.SetDashStyle( eXDS );
812  aDash.SetDots( static_cast<sal_uInt8>(m_xNumFldNumber1->get_value()) );
813  aDash.SetDotLen( m_xLbType1->get_active() == 0 ? 0 : GetCoreValue( *m_xMtrLength1, ePoolUnit ) );
814  aDash.SetDashes( static_cast<sal_uInt8>(m_xNumFldNumber2->get_value()) );
815  aDash.SetDashLen( m_xLbType2->get_active() == 0 ? 0 : GetCoreValue( *m_xMtrLength2, ePoolUnit ) );
817 
818  rXLSet.Put( XLineDashItem( OUString(), aDash ) );
819 
820  // #i34740#
822 }
823 
825 {
826  css::drawing::DashStyle eXDS = aDash.GetDashStyle(); // css::drawing::DashStyle_RECT, css::drawing::DashStyle_ROUND
827  if( eXDS == css::drawing::DashStyle_RECTRELATIVE )
828  m_xCbxSynchronize->set_active(true);
829  else
830  m_xCbxSynchronize->set_active(false);
831 
832  m_xNumFldNumber1->set_value(aDash.GetDots());
834  m_xLbType1->set_active(aDash.GetDotLen() == 0 ? 0 : 1);
835  m_xNumFldNumber2->set_value(aDash.GetDashes());
837  m_xLbType2->set_active(aDash.GetDashLen() == 0 ? 0 : 1);
839 
840  ChangeMetricHdl_Impl(nullptr);
841 
842  // save values for changes recognition (-> method)
843  m_xNumFldNumber1->save_value();
844  m_xMtrLength1->save_value();
845  m_xLbType1->save_value();
846  m_xNumFldNumber2->save_value();
847  m_xMtrLength2->save_value();
848  m_xLbType2->save_value();
849  m_xMtrDistance->save_value();
850 }
851 
853 {
854  SfxTabPage::DataChanged( rDCEvt );
855 
856  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
857  {
858  auto nOldSelect = m_xLbLineStyles->get_active();
859  m_xLbLineStyles->clear();
860  m_xLbLineStyles->Fill(pDashList);
861  m_xLbLineStyles->set_active(nOldSelect);
862  }
863 }
864 
865 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 * pPosDashLb
Definition: cuitabline.hxx:257
void ChangeMetricHdl_Impl(const weld::ToggleButton *)
Definition: tplnedef.cxx:389
SfxItemSet & rXLSet
Definition: cuitabline.hxx:250
void SetFieldUnit(weld::MetricSpinButton &rField, FieldUnit eUnit, bool bAll)
FieldUnit
std::unique_ptr< weld::Button > m_xBtnModify
Definition: cuitabline.hxx:273
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
const short RET_BTN_1
Definition: defdlgname.hxx:25
void AddFilter(const OUString &rFilterName, const OUString &rExtension)
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tplnedef.cxx:162
void SetDotLen(sal_uInt32 nNewDotLen)
static VclPtr< SfxTabPage > Create(TabPageParent, const SfxItemSet *)
Definition: tplnedef.cxx:311
std::string GetValue
OUString GetPath() const
XDashListRef pDashList
Definition: cuitabline.hxx:252
static SvxAbstractDialogFactory * Create()
void SetDots(sal_uInt16 nNewDots)
SvxLineDefTabPage(TabPageParent pParent, const SfxItemSet &rInAttrs)
Definition: tplnedef.cxx:59
sal_uInt32 GetDistance() const
IMPL_LINK_NOARG(SvxLineDefTabPage, ChangePreviewHdl_Impl, weld::MetricSpinButton &, void)
Definition: tplnedef.cxx:350
std::unique_ptr< weld::SpinButton > m_xNumFldNumber2
Definition: cuitabline.hxx:267
#define XOUT_WIDTH
Definition: tplnedef.cxx:54
void SetDashLen(sal_uInt32 nNewDashLen)
void CheckChanges_Impl()
Definition: tplnedef.cxx:203
sal_uInt16 nDlgType
Definition: cuitabline.hxx:256
DataChangedEventType GetType() const
std::unique_ptr< weld::MetricSpinButton > m_xMtrDistance
Definition: cuitabline.hxx:270
void SetLineAttributes(const SfxItemSet &rItemSet)
void SetDisplayDirectory(const OUString &rPath)
std::unique_ptr< weld::Button > m_xBtnLoad
Definition: cuitabline.hxx:275
RET_CANCEL
void SetDistance(sal_uInt32 nNewDistance)
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: tplnedef.cxx:852
#define LISTBOX_ENTRY_NOTFOUND
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
virtual VclPtr< AbstractSvxNameDialog > CreateSvxNameDialog(weld::Window *pParent, const OUString &rName, const OUString &rDesc)=0
std::unique_ptr< weld::ComboBox > m_xLbType2
Definition: cuitabline.hxx:265
RET_YES
void SelectTypeHdl_Impl(const weld::ComboBox *)
Definition: tplnedef.cxx:469
OUString SvxResId(const char *pId)
std::unique_ptr< weld::ComboBox > m_xLbType1
Definition: cuitabline.hxx:264
void SetExchangeSupport()
AllSettingsFlags GetFlags() const
void SetExtension(OUString const &rTheExtension)
sal_uInt16 GetDots() const
css::drawing::DashStyle GetDashStyle() const
virtual void dispose() override
ChangeType
weld::Window * GetDialogFrameWeld() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define DBG_ASSERT(sCon, aError)
std::unique_ptr< SvxLineLB > m_xLbLineStyles
Definition: cuitabline.hxx:263
bool Append(OUString const &rTheSegment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
const SfxItemSet & rOutAttrs
Definition: cuitabline.hxx:246
virtual void Reset(const SfxItemSet *) override
Definition: tplnedef.cxx:269
const short RET_BTN_2
Definition: defdlgname.hxx:26
int i
int GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
void SetDashStyle(css::drawing::DashStyle eNewStyle)
virtual bool FillItemSet(SfxItemSet *) override
Definition: tplnedef.cxx:252
#define XATTR_LINESTYLE
static XPropertyListRef CreatePropertyList(XPropertyListType t, const OUString &rPath, const OUString &rReferer)
const XDash & GetDashValue() const
void FillDialog_Impl()
Definition: tplnedef.cxx:824
void SetMetricValue(weld::MetricSpinButton &rField, int nCoreValue, MapUnit eUnit)
SfxItemPool * GetPool() const
#define XATTR_LINEDASH
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
SvxXLinePreview m_aCtlPreview
Definition: cuitabline.hxx:262
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
virtual ~SvxLineDefTabPage() override
Definition: tplnedef.cxx:144
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void SetDashes(sal_uInt16 nNewDashes)
std::unique_ptr< weld::MetricSpinButton > m_xMtrLength1
Definition: cuitabline.hxx:268
std::unique_ptr< weld::Button > m_xBtnAdd
Definition: cuitabline.hxx:272
sal_uInt32 GetDotLen() const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
#define ERRCODE_NONE
std::unique_ptr< weld::CustomWeld > m_xCtlPreview
Definition: cuitabline.hxx:277
XLineAttrSetItem aXLineAttr
Definition: cuitabline.hxx:249
INetProtocol GetProtocol() const
IMPL_LINK(SvxLineDefTabPage, SelectLinestyleListBoxHdl_Impl, weld::ComboBox &, rListBox, void)
Definition: tplnedef.cxx:316
std::unique_ptr< weld::MetricSpinButton > m_xMtrLength2
Definition: cuitabline.hxx:269
RET_OK
static VclPtr< reference_type > Create(Arg &&...arg)
std::unique_ptr< weld::Button > m_xBtnSave
Definition: cuitabline.hxx:276
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)
static XDashListRef AsDashList(rtl::Reference< XPropertyList > const &plist)
DeactivateRC
OString const aName
void SelectLinestyleHdl_Impl(const weld::ComboBox *)
Definition: tplnedef.cxx:321
virtual void dispose() override
Definition: tplnedef.cxx:149
OUString const & GetName() const
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile)
std::unique_ptr< weld::Button > m_xBtnDelete
Definition: cuitabline.hxx:274
void FillDash_Impl()
Definition: tplnedef.cxx:802
PageType * pPageType
Definition: cuitabline.hxx:255
sal_uInt32 GetDashLen() const
sal_Int32 nPos
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tplnedef.cxx:193
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
OUString getExtension(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
std::unique_ptr< weld::CheckButton > m_xCbxSynchronize
Definition: cuitabline.hxx:271
sal_uInt16 GetDashes() const
std::unique_ptr< weld::SpinButton > m_xNumFldNumber1
Definition: cuitabline.hxx:266