bump product version to 6.4.0.3
[LibreOffice.git] / cui / source / tabpages / tphatch.cxx
blobaeb5d9c85fcb00b582605794a2704d0083ae6687
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <memory>
21 #include <tools/urlobj.hxx>
22 #include <vcl/settings.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/weld.hxx>
25 #include <sfx2/dialoghelper.hxx>
27 #include <strings.hrc>
28 #include <svx/xfillit0.hxx>
29 #include <svx/xflhtit.hxx>
30 #include <svx/xflclit.hxx>
31 #include <svx/colorbox.hxx>
32 #include <svx/xtable.hxx>
33 #include <svx/xflbckit.hxx>
34 #include <cuitabarea.hxx>
35 #include <svx/svxdlg.hxx>
36 #include <dialmgr.hxx>
37 #include <svx/dlgutil.hxx>
38 #include <svx/dialmgr.hxx>
39 #include <svx/strings.hrc>
40 #include <svx/svxids.hrc>
41 #include <sal/log.hxx>
42 #include <svtools/unitconv.hxx>
44 using namespace com::sun::star;
46 SvxHatchTabPage::SvxHatchTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
47 : SfxTabPage(pPage, pController, "cui/ui/hatchpage.ui", "HatchPage", &rInAttrs)
48 , m_rOutAttrs(rInAttrs)
49 , m_pnHatchingListState(nullptr)
50 , m_pnColorListState(nullptr)
51 , m_aXFillAttr(rInAttrs.GetPool())
52 , m_rXFSet(m_aXFillAttr.GetItemSet())
53 , m_xMtrDistance(m_xBuilder->weld_metric_spin_button("distancemtr", FieldUnit::MM))
54 , m_xMtrAngle(m_xBuilder->weld_metric_spin_button("anglemtr", FieldUnit::DEGREE))
55 , m_xSliderAngle(m_xBuilder->weld_scale("angleslider"))
56 , m_xLbLineType(m_xBuilder->weld_combo_box("linetypelb"))
57 , m_xLbLineColor(new ColorListBox(m_xBuilder->weld_menu_button("linecolorlb"), pController->getDialog()))
58 , m_xCbBackgroundColor(m_xBuilder->weld_check_button("backgroundcolor"))
59 , m_xLbBackgroundColor(new ColorListBox(m_xBuilder->weld_menu_button("backgroundcolorlb"), pController->getDialog()))
60 , m_xHatchLB(new SvxPresetListBox(m_xBuilder->weld_scrolled_window("hatchpresetlistwin")))
61 , m_xBtnAdd(m_xBuilder->weld_button("add"))
62 , m_xBtnModify(m_xBuilder->weld_button("modify"))
63 , m_xHatchLBWin(new weld::CustomWeld(*m_xBuilder, "hatchpresetlist", *m_xHatchLB))
64 , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder, "previewctl", m_aCtlPreview))
66 Size aSize = getDrawPreviewOptimalSize(m_aCtlPreview.GetDrawingArea()->get_ref_device());
67 m_xHatchLBWin->set_size_request(aSize.Width(), aSize.Height());
68 m_xCtlPreview->set_size_request(aSize.Width(), aSize.Height());
70 // this page needs ExchangeSupport
71 SetExchangeSupport();
73 // adjust metric
74 FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
76 switch ( eFUnit )
78 case FieldUnit::M:
79 case FieldUnit::KM:
80 eFUnit = FieldUnit::MM;
81 break;
82 default: ;//prevent warning
84 SetFieldUnit( *m_xMtrDistance, eFUnit );
86 // determine PoolUnit
87 SfxItemPool* pPool = m_rOutAttrs.GetPool();
88 assert( pPool && "Where is the pool?" );
89 m_ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
91 // setting the output device
92 m_rXFSet.Put( XFillStyleItem(drawing::FillStyle_HATCH) );
93 m_rXFSet.Put( XFillHatchItem(OUString(), XHatch()) );
94 m_aCtlPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
95 m_xHatchLB->SetSelectHdl( LINK( this, SvxHatchTabPage, ChangeHatchHdl ) );
96 m_xHatchLB->SetRenameHdl( LINK( this, SvxHatchTabPage, ClickRenameHdl_Impl ) );
97 m_xHatchLB->SetDeleteHdl( LINK( this, SvxHatchTabPage, ClickDeleteHdl_Impl ) );
99 Link<weld::MetricSpinButton&,void> aLink = LINK( this, SvxHatchTabPage, ModifiedEditHdl_Impl );
100 Link<weld::ComboBox&,void> aLink2 = LINK( this, SvxHatchTabPage, ModifiedListBoxHdl_Impl );
101 m_xMtrDistance->connect_value_changed( aLink );
102 m_xMtrAngle->connect_value_changed( aLink );
103 m_xSliderAngle->connect_value_changed(LINK(this, SvxHatchTabPage, ModifiedSliderHdl_Impl));
104 m_xLbLineType->connect_changed( aLink2 );
105 Link<ColorListBox&,void> aLink3 = LINK( this, SvxHatchTabPage, ModifiedColorListBoxHdl_Impl );
106 m_xLbLineColor->SetSelectHdl( aLink3 );
107 m_xCbBackgroundColor->connect_toggled( LINK( this, SvxHatchTabPage, ToggleHatchBackgroundColor_Impl ) );
108 m_xLbBackgroundColor->SetSelectHdl( LINK( this, SvxHatchTabPage, ModifiedBackgroundHdl_Impl ) );
110 m_xBtnAdd->connect_clicked( LINK( this, SvxHatchTabPage, ClickAddHdl_Impl ) );
111 m_xBtnModify->connect_clicked( LINK( this, SvxHatchTabPage, ClickModifyHdl_Impl ) );
113 m_aCtlPreview.SetDrawMode(Application::GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR);
116 SvxHatchTabPage::~SvxHatchTabPage()
118 m_xCtlPreview.reset();
119 m_xHatchLBWin.reset();
120 m_xHatchLB.reset();
121 m_xLbBackgroundColor.reset();
122 m_xLbLineColor.reset();
125 void SvxHatchTabPage::Construct()
127 m_xHatchLB->FillPresetListBox(*m_pHatchingList);
130 void SvxHatchTabPage::ActivatePage( const SfxItemSet& rSet )
132 if( m_pColorList.is() )
134 // ColorList
135 if( *m_pnColorListState & ChangeType::CHANGED ||
136 *m_pnColorListState & ChangeType::MODIFIED )
138 SvxAreaTabDialog* pArea = (*m_pnColorListState & ChangeType::CHANGED) ?
139 dynamic_cast<SvxAreaTabDialog*>(GetDialogController()) : nullptr;
140 if (pArea)
141 m_pColorList = pArea->GetNewColorList();
143 ModifiedHdl_Impl( this );
146 // determining (possibly cutting) the name
147 // and displaying it in the GroupBox
148 OUString aString = CuiResId( RID_SVXSTR_TABLE ) + ": ";
149 INetURLObject aURL( m_pHatchingList->GetPath() );
151 aURL.Append( m_pHatchingList->GetName() );
152 SAL_WARN_IF( aURL.GetProtocol() == INetProtocol::NotValid, "cui.tabpages", "invalid URL" );
154 if ( aURL.getBase().getLength() > 18 )
156 aString += aURL.getBase().copy( 0, 15 ) + "...";
158 else
159 aString += aURL.getBase();
161 sal_Int32 nPos = SearchHatchList( rSet.Get(XATTR_FILLHATCH).GetName() );
162 if( nPos != LISTBOX_ENTRY_NOTFOUND )
164 sal_uInt16 nId = m_xHatchLB->GetItemId( static_cast<size_t>( nPos ) );
165 m_xHatchLB->SelectItem( nId );
167 // colors could have been deleted
168 ChangeHatchHdl_Impl();
171 XFillBackgroundItem aBckItem( rSet.Get(XATTR_FILLBACKGROUND));
172 m_rXFSet.Put( aBckItem );
174 if (aBckItem.GetValue())
176 m_xCbBackgroundColor->set_state(TRISTATE_TRUE);
177 XFillColorItem aColorItem( rSet.Get(XATTR_FILLCOLOR) );
178 Color aColor(aColorItem.GetColorValue());
179 m_xLbBackgroundColor->SelectEntry(aColor);
180 m_xLbBackgroundColor->set_sensitive(true);
181 m_rXFSet.Put( aColorItem );
183 else
185 m_xCbBackgroundColor->set_state(TRISTATE_FALSE);
186 m_xLbBackgroundColor->SelectEntry(COL_AUTO);
187 m_xLbBackgroundColor->set_sensitive(false);
190 m_aCtlPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
191 m_aCtlPreview.Invalidate();
194 DeactivateRC SvxHatchTabPage::DeactivatePage( SfxItemSet* _pSet )
196 if( _pSet )
197 FillItemSet( _pSet );
199 return DeactivateRC::LeavePage;
202 sal_Int32 SvxHatchTabPage::SearchHatchList(const OUString& rHatchName)
204 long nCount = m_pHatchingList->Count();
205 bool bValidHatchName = true;
206 sal_Int32 nPos = LISTBOX_ENTRY_NOTFOUND;
208 for(long i = 0;i < nCount && bValidHatchName;i++)
210 if(rHatchName == m_pHatchingList->GetHatch( i )->GetName())
212 nPos = i;
213 bValidHatchName = false;
216 return nPos;
219 bool SvxHatchTabPage::FillItemSet( SfxItemSet* rSet )
221 std::unique_ptr<XHatch> pXHatch;
222 OUString aString;
223 size_t nPos = m_xHatchLB->IsNoSelection() ? VALUESET_ITEM_NOTFOUND : m_xHatchLB->GetSelectItemPos();
224 if( nPos != VALUESET_ITEM_NOTFOUND )
226 pXHatch.reset(new XHatch( m_pHatchingList->GetHatch( static_cast<sal_uInt16>(nPos) )->GetHatch() ));
227 aString = m_xHatchLB->GetItemText( m_xHatchLB->GetSelectedItemId() );
229 // unidentified hatch has been passed
230 else
232 pXHatch.reset(new XHatch( m_xLbLineColor->GetSelectEntryColor(),
233 static_cast<css::drawing::HatchStyle>(m_xLbLineType->get_active()),
234 GetCoreValue( *m_xMtrDistance, m_ePoolUnit ),
235 static_cast<long>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10) ));
237 assert( pXHatch && "XHatch couldn't be created" );
238 rSet->Put( XFillStyleItem( drawing::FillStyle_HATCH ) );
239 rSet->Put( XFillHatchItem( aString, *pXHatch ) );
240 rSet->Put( XFillBackgroundItem( m_xCbBackgroundColor->get_active() ) );
241 if (m_xCbBackgroundColor->get_active())
243 NamedColor aColor = m_xLbBackgroundColor->GetSelectedEntry();
244 rSet->Put(XFillColorItem(aColor.second, aColor.first));
246 return true;
249 void SvxHatchTabPage::Reset( const SfxItemSet* rSet )
251 ChangeHatchHdl_Impl();
253 XFillColorItem aColItem( rSet->Get(XATTR_FILLCOLOR) );
254 m_xLbBackgroundColor->SelectEntry(aColItem.GetColorValue());
255 m_rXFSet.Put( aColItem );
257 XFillBackgroundItem aBckItem( rSet->Get(XATTR_FILLBACKGROUND) );
258 if(aBckItem.GetValue())
259 m_xCbBackgroundColor->set_state(TRISTATE_TRUE);
260 else
261 m_xCbBackgroundColor->set_state(TRISTATE_FALSE);
262 m_rXFSet.Put( aBckItem );
264 m_aCtlPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
265 m_aCtlPreview.Invalidate();
268 std::unique_ptr<SfxTabPage> SvxHatchTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
269 const SfxItemSet* rSet )
271 return std::make_unique<SvxHatchTabPage>(pPage, pController, *rSet);
274 IMPL_LINK( SvxHatchTabPage, ModifiedListBoxHdl_Impl, weld::ComboBox&, rListBox, void )
276 ModifiedHdl_Impl(&rListBox);
277 // hatch params have changed, it is no longer one of the presets
278 m_xHatchLB->SetNoSelection();
281 IMPL_LINK( SvxHatchTabPage, ModifiedColorListBoxHdl_Impl, ColorListBox&, rListBox, void )
283 ModifiedHdl_Impl(&rListBox);
284 m_xHatchLB->SetNoSelection();
287 IMPL_LINK_NOARG( SvxHatchTabPage, ToggleHatchBackgroundColor_Impl, weld::ToggleButton&, void )
289 if (m_xCbBackgroundColor->get_active())
290 m_xLbBackgroundColor->set_sensitive(true);
291 else
292 m_xLbBackgroundColor->set_sensitive(false);
293 m_rXFSet.Put( XFillBackgroundItem( m_xCbBackgroundColor->get_active() ) );
294 ModifiedBackgroundHdl_Impl(*m_xLbBackgroundColor);
297 IMPL_LINK_NOARG( SvxHatchTabPage, ModifiedBackgroundHdl_Impl, ColorListBox&, void )
299 Color aColor(COL_TRANSPARENT);
300 if (m_xCbBackgroundColor->get_active())
302 aColor = m_xLbBackgroundColor->GetSelectEntryColor();
303 m_aCtlPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
304 m_aCtlPreview.Invalidate();
306 m_rXFSet.Put(XFillColorItem( OUString(), aColor ));
308 m_aCtlPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
309 m_aCtlPreview.Invalidate();
312 IMPL_LINK( SvxHatchTabPage, ModifiedEditHdl_Impl, weld::MetricSpinButton&, rEdit, void )
314 ModifiedHdl_Impl(&rEdit);
315 m_xHatchLB->SetNoSelection();
318 IMPL_LINK( SvxHatchTabPage, ModifiedSliderHdl_Impl, weld::Scale&, rSlider, void )
320 ModifiedHdl_Impl(&rSlider);
321 m_xHatchLB->SetNoSelection();
324 void SvxHatchTabPage::ModifiedHdl_Impl( void const * p )
326 if (p == m_xMtrAngle.get())
327 m_xSliderAngle->set_value(m_xMtrAngle->get_value(FieldUnit::NONE));
329 if (p == m_xSliderAngle.get())
330 m_xMtrAngle->set_value(m_xSliderAngle->get_value(), FieldUnit::NONE);
332 XHatch aXHatch( m_xLbLineColor->GetSelectEntryColor(),
333 static_cast<css::drawing::HatchStyle>(m_xLbLineType->get_active()),
334 GetCoreValue( *m_xMtrDistance, m_ePoolUnit ),
335 static_cast<long>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10) );
337 m_rXFSet.Put( XFillHatchItem( OUString(), aXHatch ) );
339 m_aCtlPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
340 m_aCtlPreview.Invalidate();
343 IMPL_LINK_NOARG(SvxHatchTabPage, ChangeHatchHdl, SvtValueSet*, void)
345 ChangeHatchHdl_Impl();
348 void SvxHatchTabPage::ChangeHatchHdl_Impl()
350 std::unique_ptr<XHatch> pHatch;
351 size_t nPos = m_xHatchLB->GetSelectItemPos();
353 if( nPos != VALUESET_ITEM_NOTFOUND )
354 pHatch.reset(new XHatch( m_pHatchingList->GetHatch( static_cast<sal_uInt16>(nPos) )->GetHatch() ));
355 else
357 const SfxPoolItem* pPoolItem = nullptr;
358 if( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLSTYLE ), true, &pPoolItem ) )
360 if( ( drawing::FillStyle_HATCH == static_cast<const XFillStyleItem*>( pPoolItem )->GetValue() ) &&
361 ( SfxItemState::SET == m_rOutAttrs.GetItemState( GetWhich( XATTR_FILLHATCH ), true, &pPoolItem ) ) )
363 pHatch.reset(new XHatch( static_cast<const XFillHatchItem*>( pPoolItem )->GetHatchValue() ));
366 if( !pHatch )
368 sal_uInt16 nPosition = m_xHatchLB->GetItemId( 0 );
369 m_xHatchLB->SelectItem( nPosition );
370 if( nPosition != 0 )
371 pHatch.reset( new XHatch( m_pHatchingList->GetHatch( 0 )->GetHatch() ) );
374 if( pHatch )
376 m_xLbLineType->set_active(
377 sal::static_int_cast< sal_Int32 >( pHatch->GetHatchStyle() ) );
378 m_xLbLineColor->SetNoSelection();
379 m_xLbLineColor->SelectEntry( pHatch->GetColor() );
380 SetMetricValue( *m_xMtrDistance, pHatch->GetDistance(), m_ePoolUnit );
381 long nHatchAngle = pHatch->GetAngle() / 10;
382 m_xMtrAngle->set_value(nHatchAngle, FieldUnit::NONE);
383 m_xSliderAngle->set_value(nHatchAngle);
385 // fill ItemSet and pass it on to m_aCtlPreview
386 m_rXFSet.Put( XFillHatchItem( OUString(), *pHatch ) );
387 m_aCtlPreview.SetAttributes( m_aXFillAttr.GetItemSet() );
389 m_aCtlPreview.Invalidate();
390 pHatch.reset();
392 m_xMtrDistance->save_value();
393 m_xMtrAngle->save_value();
394 m_xLbLineType->save_value();
395 m_xLbLineColor->SaveValue();
396 m_xLbBackgroundColor->SaveValue();
399 IMPL_LINK_NOARG(SvxHatchTabPage, ClickAddHdl_Impl, weld::Button&, void)
401 OUString aNewName( SvxResId( RID_SVXSTR_HATCH ) );
402 OUString aDesc( CuiResId( RID_SVXSTR_DESC_HATCH ) );
403 OUString aName;
405 long nCount = m_pHatchingList->Count();
406 long j = 1;
407 bool bValidHatchName = false;
409 while( !bValidHatchName )
411 aName = aNewName + " " + OUString::number( j++ );
412 bValidHatchName = (SearchHatchList(aName) == LISTBOX_ENTRY_NOTFOUND);
415 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
416 ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetFrameWeld(), aName, aDesc));
417 sal_uInt16 nError = 1;
419 while( pDlg->Execute() == RET_OK )
421 pDlg->GetName( aName );
423 bValidHatchName = (SearchHatchList(aName) == LISTBOX_ENTRY_NOTFOUND);
424 if( bValidHatchName )
426 nError = 0;
427 break;
430 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
431 std::unique_ptr<weld::MessageDialog> xWarnBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
432 if (xWarnBox->run() != RET_OK)
433 break;
435 pDlg.disposeAndClear();
437 if( !nError )
439 XHatch aXHatch( m_xLbLineColor->GetSelectEntryColor(),
440 static_cast<css::drawing::HatchStyle>(m_xLbLineType->get_active()),
441 GetCoreValue( *m_xMtrDistance, m_ePoolUnit ),
442 static_cast<long>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10) );
444 m_pHatchingList->Insert(std::make_unique<XHatchEntry>(aXHatch, aName), nCount);
446 sal_Int32 nId = m_xHatchLB->GetItemId(nCount - 1); // calculate the last ID
447 BitmapEx aBitmap = m_pHatchingList->GetBitmapForPreview( nCount, m_xHatchLB->GetIconSize() );
448 // Insert the new entry at the next ID
449 m_xHatchLB->InsertItem( nId + 1, Image(aBitmap), aName );
450 m_xHatchLB->SelectItem( nId + 1 );
451 m_xHatchLB->Resize();
453 *m_pnHatchingListState |= ChangeType::MODIFIED;
455 ChangeHatchHdl_Impl();
459 IMPL_LINK_NOARG(SvxHatchTabPage, ClickModifyHdl_Impl, weld::Button&, void)
461 sal_uInt16 nId = m_xHatchLB->GetSelectedItemId();
462 size_t nPos = m_xHatchLB->GetSelectItemPos();
464 if( nPos != VALUESET_ITEM_NOTFOUND )
466 OUString aName( m_pHatchingList->GetHatch( static_cast<sal_uInt16>(nPos) )->GetName() );
468 XHatch aXHatch( m_xLbLineColor->GetSelectEntryColor(),
469 static_cast<css::drawing::HatchStyle>(m_xLbLineType->get_active()),
470 GetCoreValue( *m_xMtrDistance, m_ePoolUnit ),
471 static_cast<long>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10) );
473 m_pHatchingList->Replace(std::make_unique<XHatchEntry>(aXHatch, aName), nPos);
475 BitmapEx aBitmap = m_pHatchingList->GetBitmapForPreview( static_cast<sal_uInt16>(nPos), m_xHatchLB->GetIconSize() );
476 m_xHatchLB->RemoveItem( nId );
477 m_xHatchLB->InsertItem( nId, Image(aBitmap), aName, static_cast<sal_uInt16>(nPos) );
478 m_xHatchLB->SelectItem( nId );
480 // save values for changes recognition (-> method)
481 m_xMtrDistance->save_value();
482 m_xMtrAngle->save_value();
483 m_xLbLineType->save_value();
484 m_xLbLineColor->SaveValue();
485 m_xLbBackgroundColor->SaveValue();
487 *m_pnHatchingListState |= ChangeType::MODIFIED;
491 IMPL_LINK_NOARG(SvxHatchTabPage, ClickDeleteHdl_Impl, SvxPresetListBox*, void)
493 sal_uInt16 nId = m_xHatchLB->GetSelectedItemId();
494 size_t nPos = m_xHatchLB->GetSelectItemPos();
496 if( nPos != VALUESET_ITEM_NOTFOUND )
498 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletehatchdialog.ui"));
499 std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("AskDelHatchDialog"));
500 if (xQueryBox->run() == RET_YES)
502 m_pHatchingList->Remove(nPos);
503 m_xHatchLB->RemoveItem( nId );
504 nId = m_xHatchLB->GetItemId(0);
505 m_xHatchLB->SelectItem( nId );
506 m_xHatchLB->Resize();
508 m_aCtlPreview.Invalidate();
510 ChangeHatchHdl_Impl();
512 *m_pnHatchingListState |= ChangeType::MODIFIED;
517 IMPL_LINK_NOARG(SvxHatchTabPage, ClickRenameHdl_Impl, SvxPresetListBox*, void )
519 sal_uInt16 nId = m_xHatchLB->GetSelectedItemId();
520 size_t nPos = m_xHatchLB->GetSelectItemPos();
522 if( nPos != VALUESET_ITEM_NOTFOUND )
524 OUString aDesc( CuiResId( RID_SVXSTR_DESC_HATCH ) );
525 OUString aName( m_pHatchingList->GetHatch( nPos )->GetName() );
527 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
528 ScopedVclPtr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog(GetFrameWeld(), aName, aDesc));
530 bool bLoop = true;
531 while( bLoop && pDlg->Execute() == RET_OK )
533 pDlg->GetName( aName );
534 sal_Int32 nHatchPos = SearchHatchList( aName );
535 bool bValidHatchName = (nHatchPos == static_cast<sal_Int32>(nPos) ) || (nHatchPos == LISTBOX_ENTRY_NOTFOUND);
537 if(bValidHatchName)
539 bLoop = false;
540 m_pHatchingList->GetHatch(nPos)->SetName(aName);
542 m_xHatchLB->SetItemText(nId, aName);
543 m_xHatchLB->SelectItem( nId );
545 *m_pnHatchingListState |= ChangeType::MODIFIED;
547 else
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();
558 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */