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