LibreOffice Module cui (master) 1
tpgradnt.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 <memory>
21#include <tools/urlobj.hxx>
22#include <vcl/svapp.hxx>
23#include <vcl/weld.hxx>
24#include <sfx2/dialoghelper.hxx>
25
26#include <strings.hrc>
27#include <svx/xfillit0.hxx>
28#include <svx/xflgrit.hxx>
29#include <svx/colorbox.hxx>
30#include <svx/xtable.hxx>
31#include <svx/xgrscit.hxx>
32#include <cuitabarea.hxx>
33#include <svx/svxdlg.hxx>
34#include <dialmgr.hxx>
35#include <svx/dialmgr.hxx>
36#include <svx/strings.hrc>
38#include <sal/log.hxx>
39
40using namespace com::sun::star;
41
43 : SfxTabPage(pPage, pController, "cui/ui/gradientpage.ui", "GradientPage", &rInAttrs)
44 , m_rOutAttrs(rInAttrs)
45 , m_pnGradientListState(nullptr)
46 , m_pnColorListState(nullptr)
47 , m_aXFillAttr(rInAttrs.GetPool())
48 , m_rXFSet(m_aXFillAttr.GetItemSet())
49 , m_xLbGradientType(m_xBuilder->weld_combo_box("gradienttypelb"))
50 , m_xFtCenter(m_xBuilder->weld_label("centerft"))
51 , m_xMtrCenterX(m_xBuilder->weld_metric_spin_button("centerxmtr", FieldUnit::PERCENT))
52 , m_xMtrCenterY(m_xBuilder->weld_metric_spin_button("centerymtr", FieldUnit::PERCENT))
53 , m_xFtAngle(m_xBuilder->weld_label("angleft"))
54 , m_xMtrAngle(m_xBuilder->weld_metric_spin_button("anglemtr", FieldUnit::DEGREE))
55 , m_xSliderAngle(m_xBuilder->weld_scale("angleslider"))
56 , m_xMtrBorder(m_xBuilder->weld_metric_spin_button("bordermtr", FieldUnit::PERCENT))
57 , m_xSliderBorder(m_xBuilder->weld_scale("borderslider"))
58 , m_xLbColorFrom(new ColorListBox(m_xBuilder->weld_menu_button("colorfromlb"),
59 [this]{ return GetDialogController()->getDialog(); }))
60 , m_xMtrColorFrom(m_xBuilder->weld_metric_spin_button("colorfrommtr", FieldUnit::PERCENT))
61 , m_xLbColorTo(new ColorListBox(m_xBuilder->weld_menu_button("colortolb"),
62 [this]{ return GetDialogController()->getDialog(); }))
63 , m_xMtrColorTo(m_xBuilder->weld_metric_spin_button("colortomtr", FieldUnit::PERCENT))
64 , m_xGradientLB(new SvxPresetListBox(m_xBuilder->weld_scrolled_window("gradientpresetlistwin", true)))
65 , m_xMtrIncrement(m_xBuilder->weld_spin_button("incrementmtr"))
66 , m_xCbIncrement(m_xBuilder->weld_check_button("autoincrement"))
67 , m_xBtnAdd(m_xBuilder->weld_button("add"))
68 , m_xBtnModify(m_xBuilder->weld_button("modify"))
69 , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder, "previewctl", m_aCtlPreview))
70 , m_xGradientLBWin(new weld::CustomWeld(*m_xBuilder, "gradientpresetlist", *m_xGradientLB))
71{
72 Size aSize = getDrawPreviewOptimalSize(m_aCtlPreview.GetDrawingArea()->get_ref_device());
73 m_xGradientLB->set_size_request(aSize.Width(), aSize.Height());
74 m_xCtlPreview->set_size_request(aSize.Width(), aSize.Height());
75 // this page needs ExchangeSupport
76 SetExchangeSupport();
77
78 // as long as NOT supported by the item
79
80 m_xMtrColorTo->set_value(100, FieldUnit::PERCENT);
81 m_xMtrColorFrom->set_value(100, FieldUnit::PERCENT);
82
83 // setting the output device
84 m_rXFSet.Put( XFillStyleItem(drawing::FillStyle_GRADIENT) );
85 m_rXFSet.Put( XFillGradientItem(OUString(), basegfx::BGradient()));
86 m_aCtlPreview.SetAttributes(m_aXFillAttr.GetItemSet());
87
88 // set handler
89 m_xGradientLB->SetSelectHdl( LINK( this, SvxGradientTabPage, ChangeGradientHdl ) );
90 m_xGradientLB->SetRenameHdl( LINK( this, SvxGradientTabPage, ClickRenameHdl_Impl ) );
91 m_xGradientLB->SetDeleteHdl( LINK( this, SvxGradientTabPage, ClickDeleteHdl_Impl ) );
92 m_xBtnAdd->connect_clicked(LINK(this, SvxGradientTabPage, ClickAddHdl_Impl));
93 m_xBtnModify->connect_clicked(LINK(this, SvxGradientTabPage, ClickModifyHdl_Impl));
94
95 Link<weld::MetricSpinButton&,void> aLink = LINK( this, SvxGradientTabPage, ModifiedMetricHdl_Impl );
96 Link<weld::ComboBox&,void> aLink2 = LINK( this, SvxGradientTabPage, ModifiedListBoxHdl_Impl );
97 m_xLbGradientType->connect_changed( aLink2 );
98 m_xCbIncrement->connect_toggled(LINK(this, SvxGradientTabPage, ChangeAutoStepHdl_Impl));
99 m_xMtrIncrement->connect_value_changed(LINK(this, SvxGradientTabPage, ModifiedEditHdl_Impl));
100 m_xMtrCenterX->connect_value_changed( aLink );
101 m_xMtrCenterY->connect_value_changed( aLink );
102 m_xMtrAngle->connect_value_changed( aLink );
103 m_xSliderAngle->connect_value_changed(LINK(this, SvxGradientTabPage, ModifiedSliderHdl_Impl));
104 m_xMtrBorder->connect_value_changed( aLink );
105 m_xSliderBorder->connect_value_changed(LINK(this, SvxGradientTabPage, ModifiedSliderHdl_Impl));
106 m_xMtrColorFrom->connect_value_changed( aLink );
107 Link<ColorListBox&,void> aLink3 = LINK( this, SvxGradientTabPage, ModifiedColorListBoxHdl_Impl );
108 m_xLbColorFrom->SetSelectHdl( aLink3 );
109 m_xMtrColorTo->connect_value_changed( aLink );
110 m_xLbColorTo->SetSelectHdl( aLink3 );
111
112 m_xGradientLB->SetStyle(WB_FLATVALUESET | WB_NO_DIRECTSELECT | WB_TABSTOP);
113
114 // #i76307# always paint the preview in LTR, because this is what the document does
115 m_aCtlPreview.EnableRTL(false);
116}
117
119{
120 m_xCtlPreview.reset();
121 m_xGradientLBWin.reset();
122 m_xGradientLB.reset();
123 m_xLbColorTo.reset();
124 m_xLbColorFrom.reset();
125}
126
128{
129 m_xGradientLB->FillPresetListBox( *m_pGradientList );
130}
131
133{
134 if( !m_pColorList.is() )
135 return;
136
137 // ColorList
138 if( *m_pnColorListState & ChangeType::CHANGED ||
139 *m_pnColorListState & ChangeType::MODIFIED )
140 {
141 SvxAreaTabDialog* pArea = (*m_pnColorListState & ChangeType::CHANGED) ?
142 dynamic_cast<SvxAreaTabDialog*>(GetDialogController()) : nullptr;
143 if (pArea)
144 m_pColorList = pArea->GetNewColorList();
145
146 ModifiedHdl_Impl( this );
147 }
148
149 // determining (and possibly cutting) the name and
150 // displaying it in the GroupBox
151 OUString aString = CuiResId( RID_CUISTR_TABLE ) + ": ";
152 INetURLObject aURL( m_pGradientList->GetPath() );
153
154 aURL.Append( m_pGradientList->GetName() );
155 SAL_WARN_IF( aURL.GetProtocol() == INetProtocol::NotValid, "cui.tabpages", "invalid URL" );
156
157 if ( aURL.getBase().getLength() > 18 )
158 {
159 aString += OUString::Concat(aURL.getBase().subView( 0, 15 )) + "...";
160 }
161 else
162 aString += aURL.getBase();
163
164 sal_Int32 nPos = SearchGradientList( rSet.Get(XATTR_FILLGRADIENT).GetName() );
165 if ( nPos != -1)
166 {
167 sal_uInt16 nId = m_xGradientLB->GetItemId( static_cast<size_t>( nPos ) );
168 m_xGradientLB->SelectItem( nId );
169 }
170 // colors could have been deleted
172}
173
174
176{
177 if( _pSet )
178 FillItemSet( _pSet );
179
180 return DeactivateRC::LeavePage;
181}
182
184{
185 std::unique_ptr<basegfx::BGradient> pBGradient;
186 size_t nPos = m_xGradientLB->IsNoSelection() ? VALUESET_ITEM_NOTFOUND : m_xGradientLB->GetSelectItemPos();
187
188 sal_uInt16 nValue = 0; // automatic step count
189 if (!m_xCbIncrement->get_active())
190 nValue = m_xMtrIncrement->get_value();
191
193 {
194 pBGradient.reset(new basegfx::BGradient( m_pGradientList->GetGradient( static_cast<sal_uInt16>(nPos) )->GetGradient() ));
195 OUString aString = m_xGradientLB->GetItemText( m_xGradientLB->GetSelectedItemId() );
196 // update StepCount to current value to be in sync with FillGradientStepCount
197 pBGradient->SetSteps(nValue);
198 rSet->Put( XFillGradientItem( aString, *pBGradient ) );
199 }
200 else
201 // gradient was passed (unidentified)
202 {
203 pBGradient.reset(new basegfx::BGradient(
205 static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active()),
206 Degree10(static_cast<sal_Int16>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10)), // should be changed in resource
207 static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
208 static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
209 static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
210 static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
211 static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
212 nValue));
213 rSet->Put( XFillGradientItem( OUString(), *pBGradient ) );
214 }
215
216 assert( pBGradient && "basegfx::BGradient could not be created" );
217 rSet->Put( XFillStyleItem( drawing::FillStyle_GRADIENT ) );
219 return true;
220}
221
223{
224 ChangeGradientHdl_Impl(); // includes setting m_xCbIncrement and m_xMtrIncrement
225
226 // determine state of the buttons
227 if( m_pGradientList->Count() )
228 m_xBtnModify->set_sensitive(true);
229 else
230 m_xBtnModify->set_sensitive(false);
231}
232
233std::unique_ptr<SfxTabPage> SvxGradientTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
234 const SfxItemSet* rOutAttrs )
235{
236 return std::make_unique<SvxGradientTabPage>(pPage, pController, *rOutAttrs);
237}
238
239IMPL_LINK( SvxGradientTabPage, ModifiedListBoxHdl_Impl, weld::ComboBox&, rListBox, void )
240{
241 ModifiedHdl_Impl(&rListBox);
242 // gradient params changed, it is no longer one of the presets
243 m_xGradientLB->SetNoSelection();
244}
245
246IMPL_LINK( SvxGradientTabPage, ModifiedColorListBoxHdl_Impl, ColorListBox&, rListBox, void )
247{
248 ModifiedHdl_Impl(&rListBox);
249 m_xGradientLB->SetNoSelection();
250}
251
252IMPL_LINK( SvxGradientTabPage, ModifiedEditHdl_Impl, weld::SpinButton&, rBox, void )
253{
254 ModifiedHdl_Impl(&rBox);
255 m_xGradientLB->SetNoSelection();
256}
257
258IMPL_LINK( SvxGradientTabPage, ModifiedMetricHdl_Impl, weld::MetricSpinButton&, rBox, void )
259{
260 ModifiedHdl_Impl(&rBox);
261 m_xGradientLB->SetNoSelection();
262}
263
264IMPL_LINK( SvxGradientTabPage, ModifiedSliderHdl_Impl, weld::Scale&, rSlider, void )
265{
266 ModifiedHdl_Impl(&rSlider);
267 m_xGradientLB->SetNoSelection();
268}
269
270IMPL_LINK_NOARG( SvxGradientTabPage, ChangeAutoStepHdl_Impl, weld::Toggleable&, void )
271{
272 if (m_xCbIncrement->get_active())
273 {
274 m_xMtrIncrement->set_sensitive(false);
275 }
276 else
277 {
278 m_xMtrIncrement->set_sensitive(true);
279 }
280 ModifiedHdl_Impl(m_xMtrIncrement.get());
281}
282
283void SvxGradientTabPage::ModifiedHdl_Impl( void const * pControl )
284{
285 if (pControl == m_xMtrBorder.get())
286 m_xSliderBorder->set_value(m_xMtrBorder->get_value(FieldUnit::NONE));
287 if (pControl == m_xSliderBorder.get())
288 m_xMtrBorder->set_value(m_xSliderBorder->get_value(), FieldUnit::NONE);
289 if (pControl == m_xMtrAngle.get())
290 m_xSliderAngle->set_value(m_xMtrAngle->get_value(FieldUnit::NONE));
291 if (pControl == m_xSliderAngle.get())
292 m_xMtrAngle->set_value(m_xSliderAngle->get_value(), FieldUnit::NONE);
293
294 css::awt::GradientStyle eXGS = static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active());
295
296 sal_uInt16 nValue = 0; // automatic
297 if (!m_xCbIncrement->get_active())
298 nValue = static_cast<sal_uInt16>(m_xMtrIncrement->get_value());
299
300 basegfx::BGradient aBGradient(
302 eXGS,
303 Degree10(static_cast<sal_Int16>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10)), // should be changed in resource
304 static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
305 static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
306 static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
307 static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
308 static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
309 nValue);
310
311 // enable/disable controls
312 if (pControl == m_xLbGradientType.get() || pControl == this)
313 SetControlState_Impl( eXGS );
314
316
317 // displaying in XOutDev
318 m_rXFSet.Put( XFillGradientItem( OUString(), aBGradient ) );
320 m_aCtlPreview.Invalidate();
321}
322
324{
325 OUString aNewName( SvxResId( RID_SVXSTR_GRADIENT ) );
326 OUString aDesc( CuiResId( RID_CUISTR_DESC_GRADIENT ) );
327 OUString aName;
328
329 tools::Long nCount = m_pGradientList->Count();
330 tools::Long j = 1;
331 bool bValidGradientName = false;
332
333 while( !bValidGradientName )
334 {
335 aName = aNewName + " " + OUString::number( j++ );
336 bValidGradientName = (SearchGradientList(aName) == -1);
337 }
338
341 sal_uInt16 nError = 1;
342
343 while (pDlg->Execute() == RET_OK)
344 {
345 pDlg->GetName( aName );
346
347 bValidGradientName = (SearchGradientList(aName) == -1);
348
349 if (bValidGradientName)
350 {
351 nError = 0;
352 break;
353 }
354
355 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
356 std::unique_ptr<weld::MessageDialog> xWarnBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
357 if (xWarnBox->run() != RET_OK)
358 break;
359 }
360 pDlg.disposeAndClear();
361
362 if( !nError )
363 {
364 sal_uInt16 nValue = 0; // automatic step count
365 if (!m_xCbIncrement->get_active())
366 nValue = m_xMtrIncrement->get_value();
367 basegfx::BGradient aBGradient(
368 createColorStops(),
369 static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active()),
370 Degree10(static_cast<sal_Int16>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10)), // should be changed in resource
371 static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
372 static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
373 static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
374 static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
375 static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
376 nValue);
377
378 m_pGradientList->Insert(std::make_unique<XGradientEntry>(aBGradient, aName), nCount);
379
380 sal_Int32 nId = m_xGradientLB->GetItemId(nCount - 1); //calculate the last ID
381 BitmapEx aBitmap = m_pGradientList->GetBitmapForPreview( nCount, m_xGradientLB->GetIconSize() );
382 m_xGradientLB->InsertItem( nId + 1, Image(aBitmap), aName );
383 m_xGradientLB->SelectItem( nId + 1 );
384 m_xGradientLB->Resize();
385
386 *m_pnGradientListState |= ChangeType::MODIFIED;
387
388 ChangeGradientHdl_Impl();
389 }
390
391 // determine button state
392 if (m_pGradientList->Count())
393 m_xBtnModify->set_sensitive(true);
394}
395
396
398{
399 sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
400 size_t nPos = m_xGradientLB->GetSelectItemPos();
401
403 return;
404
405 OUString aName( m_pGradientList->GetGradient( static_cast<sal_uInt16>(nPos) )->GetName() );
406
407 sal_uInt16 nValue = 0; // automatic step count
408 if (!m_xCbIncrement->get_active())
409 nValue = m_xMtrIncrement->get_value();
410
411 basegfx::BGradient aBGradient(
412 createColorStops(),
413 static_cast<css::awt::GradientStyle>(m_xLbGradientType->get_active()),
414 Degree10(static_cast<sal_Int16>(m_xMtrAngle->get_value(FieldUnit::NONE) * 10)), // should be changed in resource
415 static_cast<sal_uInt16>(m_xMtrCenterX->get_value(FieldUnit::NONE)),
416 static_cast<sal_uInt16>(m_xMtrCenterY->get_value(FieldUnit::NONE)),
417 static_cast<sal_uInt16>(m_xMtrBorder->get_value(FieldUnit::NONE)),
418 static_cast<sal_uInt16>(m_xMtrColorFrom->get_value(FieldUnit::NONE)),
419 static_cast<sal_uInt16>(m_xMtrColorTo->get_value(FieldUnit::NONE)),
420 nValue);
421
422 m_pGradientList->Replace(std::make_unique<XGradientEntry>(aBGradient, aName), nPos);
423
424 BitmapEx aBitmap = m_pGradientList->GetBitmapForPreview( static_cast<sal_uInt16>(nPos), m_xGradientLB->GetIconSize() );
425 m_xGradientLB->RemoveItem( nId );
426 m_xGradientLB->InsertItem( nId, Image(aBitmap), aName, static_cast<sal_uInt16>(nPos) );
427 m_xGradientLB->SelectItem( nId );
428
429 *m_pnGradientListState |= ChangeType::MODIFIED;
430}
431
433{
434 sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
435 size_t nPos = m_xGradientLB->GetSelectItemPos();
436
438 {
439 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/querydeletegradientdialog.ui"));
440 std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("AskDelGradientDialog"));
441 if (xQueryBox->run() == RET_YES)
442 {
443 m_pGradientList->Remove(nPos);
444 m_xGradientLB->RemoveItem( nId );
445 nId = m_xGradientLB->GetItemId( 0 );
446 m_xGradientLB->SelectItem( nId );
447 m_xGradientLB->Resize();
448
449 m_aCtlPreview.Invalidate();
450
451 ChangeGradientHdl_Impl();
452
453 *m_pnGradientListState |= ChangeType::MODIFIED;
454 }
455 }
456 // determine button state
457 if( !m_pGradientList->Count() )
458 m_xBtnModify->set_sensitive(false);
459}
460
462{
463 sal_uInt16 nId = m_xGradientLB->GetSelectedItemId();
464 size_t nPos = m_xGradientLB->GetSelectItemPos();
465
467 return;
468
469 OUString aDesc( CuiResId( RID_CUISTR_DESC_GRADIENT ) );
470 OUString aName( m_pGradientList->GetGradient( nPos )->GetName() );
471
474
475 bool bLoop = true;
476 while( bLoop && pDlg->Execute() == RET_OK )
477 {
478 pDlg->GetName( aName );
479 sal_Int32 nGradientPos = SearchGradientList(aName);
480 bool bValidGradientName = (nGradientPos == static_cast<sal_Int32>(nPos) ) || (nGradientPos == -1);
481
482 if( bValidGradientName )
483 {
484 bLoop = false;
485 m_pGradientList->GetGradient(nPos)->SetName(aName);
486
487 m_xGradientLB->SetItemText( nId, aName );
488 m_xGradientLB->SelectItem( nId );
489
490 *m_pnGradientListState |= ChangeType::MODIFIED;
491 }
492 else
493 {
494 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "cui/ui/queryduplicatedialog.ui"));
495 std::unique_ptr<weld::MessageDialog> xBox(xBuilder->weld_message_dialog("DuplicateNameDialog"));
496 xBox->run();
497 }
498 }
499}
500
501IMPL_LINK_NOARG(SvxGradientTabPage, ChangeGradientHdl, ValueSet*, void)
502{
503 ChangeGradientHdl_Impl();
504}
505
507{
508 std::unique_ptr<basegfx::BGradient> pGradient;
509 size_t nPos = m_xGradientLB->GetSelectItemPos();
510
512 pGradient.reset(new basegfx::BGradient( m_pGradientList->GetGradient( static_cast<sal_uInt16>( nPos ) )->GetGradient() ));
513 else
514 {
515 if( const XFillStyleItem* pFillStyleItem = m_rOutAttrs.GetItemIfSet( GetWhich( XATTR_FILLSTYLE ) ) )
516 {
517 const XFillGradientItem* pGradientItem;
518 if( ( drawing::FillStyle_GRADIENT == pFillStyleItem->GetValue() ) &&
519 ( pGradientItem = m_rOutAttrs.GetItemIfSet( GetWhich( XATTR_FILLGRADIENT ) ) ) )
520 {
521 pGradient.reset(new basegfx::BGradient( pGradientItem->GetGradientValue() ));
522 }
523 }
524 if( !pGradient )
525 {
526 sal_uInt16 nPosition = m_xGradientLB->GetItemId(0);
527 m_xGradientLB->SelectItem( nPosition );
528 if( nPosition != 0 )
529 pGradient.reset(new basegfx::BGradient( m_pGradientList->GetGradient( 0 )->GetGradient() ));
530 }
531 }
532
533 if( !pGradient )
534 return;
535
536 css::awt::GradientStyle eXGS = pGradient->GetGradientStyle();
537 sal_uInt16 nValue = pGradient->GetSteps();
539 {
540 nValue = pGradientStepCountItem->GetValue();
541 }
542 if( nValue == 0 )
543 {
544 m_xCbIncrement->set_state(TRISTATE_TRUE);
545 m_xMtrIncrement->set_sensitive(false);
546 }
547 else
548 {
549 m_xCbIncrement->set_state(TRISTATE_FALSE);
550 m_xMtrIncrement->set_sensitive(true);
551 m_xMtrIncrement->set_value( nValue );
552 }
553 m_xLbGradientType->set_active(
554 sal::static_int_cast< sal_Int32 >( eXGS ) );
555 // if the entry is not in the listbox,
556 // colors are added temporarily
557 m_xLbColorFrom->SetNoSelection();
558 m_xLbColorFrom->SelectEntry(Color(pGradient->GetColorStops().front().getStopColor()));
559
560 m_xLbColorTo->SetNoSelection();
561 m_xLbColorTo->SelectEntry(Color(pGradient->GetColorStops().back().getStopColor()));
562
563 // MCGR: preserve ColorStops if given.
564 // tdf#155901 We need offset of first and last stop, so include them.
565 if (pGradient->GetColorStops().size() >= 2)
566 m_aColorStops = pGradient->GetColorStops();
567 else
568 m_aColorStops.clear();
569
570 m_xMtrAngle->set_value(pGradient->GetAngle().get() / 10, FieldUnit::NONE); // should be changed in resource
571 m_xSliderAngle->set_value(pGradient->GetAngle().get() / 10);
572 m_xMtrBorder->set_value(pGradient->GetBorder(), FieldUnit::NONE);
573 m_xSliderBorder->set_value(pGradient->GetBorder());
574 m_xMtrCenterX->set_value(pGradient->GetXOffset(), FieldUnit::NONE);
575 m_xMtrCenterY->set_value(pGradient->GetYOffset(), FieldUnit::NONE);
576 m_xMtrColorFrom->set_value(pGradient->GetStartIntens(), FieldUnit::NONE);
577 m_xMtrColorTo->set_value(pGradient->GetEndIntens(), FieldUnit::NONE);
578
579 // disable/enable controls
580 SetControlState_Impl( eXGS );
581
582 // fill ItemSet and pass it on to aCtlPreview
583 m_rXFSet.Put( XFillGradientItem( OUString(), *pGradient ) );
586
587 m_aCtlPreview.Invalidate();
588}
589
590void SvxGradientTabPage::SetControlState_Impl( css::awt::GradientStyle eXGS )
591{
592 switch( eXGS )
593 {
594 case css::awt::GradientStyle_LINEAR:
595 case css::awt::GradientStyle_AXIAL:
596 m_xFtCenter->set_sensitive(false);
597 m_xMtrCenterX->set_sensitive(false);
598 m_xMtrCenterY->set_sensitive(false);
599 m_xFtAngle->set_sensitive(true);
600 m_xMtrAngle->set_sensitive(true);
601 m_xSliderAngle->set_sensitive(true);
602 break;
603
604 case css::awt::GradientStyle_RADIAL:
605 m_xFtCenter->set_sensitive(true);
606 m_xMtrCenterX->set_sensitive(true);
607 m_xMtrCenterY->set_sensitive(true);
608 m_xFtAngle->set_sensitive(false);
609 m_xMtrAngle->set_sensitive(false);
610 m_xSliderAngle->set_sensitive(false);
611 break;
612
613 case css::awt::GradientStyle_ELLIPTICAL:
614 m_xFtCenter->set_sensitive(true);
615 m_xMtrCenterX->set_sensitive(true);
616 m_xMtrCenterY->set_sensitive(true);
617 m_xFtAngle->set_sensitive(true);
618 m_xMtrAngle->set_sensitive(true);
619 m_xSliderAngle->set_sensitive(true);
620 break;
621
622 case css::awt::GradientStyle_SQUARE:
623 case css::awt::GradientStyle_RECT:
624 m_xFtCenter->set_sensitive(true);
625 m_xMtrCenterX->set_sensitive(true);
626 m_xMtrCenterY->set_sensitive(true);
627 m_xFtAngle->set_sensitive(true);
628 m_xMtrAngle->set_sensitive(true);
629 m_xSliderAngle->set_sensitive(true);
630 break;
631 default:
632 break;
633 }
634}
635
636sal_Int32 SvxGradientTabPage::SearchGradientList(std::u16string_view rGradientName)
637{
639 bool bValidGradientName = true;
640 sal_Int32 nPos = -1;
641
642 for(tools::Long i = 0;i < nCount && bValidGradientName;i++)
643 {
644 if(rGradientName == m_pGradientList->GetGradient( i )->GetName())
645 {
646 nPos = i;
647 bValidGradientName = false;
648 }
649 }
650 return nPos;
651}
652
654{
655 basegfx::BColorStops aColorStops;
656
657 if(m_aColorStops.size() >= 2)
658 {
659 aColorStops = m_aColorStops;
660 aColorStops.front() = basegfx::BColorStop(m_aColorStops.front().getStopOffset(),
661 m_xLbColorFrom->GetSelectEntryColor().getBColor());
662 aColorStops.back() = basegfx::BColorStop(m_aColorStops.back().getStopOffset(),
663 m_xLbColorTo->GetSelectEntryColor().getBColor());
664 }
665 else
666 {
667 aColorStops.emplace_back(0.0, m_xLbColorFrom->GetSelectEntryColor().getBColor());
668 aColorStops.emplace_back(1.0, m_xLbColorTo->GetSelectEntryColor().getBColor());
669 }
670
671 return aColorStops;
672}
673
674/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
SfxOkDialogController * GetDialogController() const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
virtual VclPtr< AbstractSvxNameDialog > CreateSvxNameDialog(weld::Window *pParent, const OUString &rName, const OUString &rDesc)=0
static SvxAbstractDialogFactory * Create()
const XColorListRef & GetNewColorList() const
Definition: cuitabarea.hxx:123
std::unique_ptr< weld::SpinButton > m_xMtrIncrement
Definition: cuitabarea.hxx:388
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: tpgradnt.cxx:233
basegfx::BColorStops createColorStops()
Definition: tpgradnt.cxx:653
virtual void Reset(const SfxItemSet *) override
Definition: tpgradnt.cxx:222
std::unique_ptr< ColorListBox > m_xLbColorFrom
Definition: cuitabarea.hxx:383
std::unique_ptr< weld::MetricSpinButton > m_xMtrCenterX
Definition: cuitabarea.hxx:376
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpgradnt.cxx:132
std::unique_ptr< weld::CustomWeld > m_xGradientLBWin
Definition: cuitabarea.hxx:393
std::unique_ptr< weld::Label > m_xFtAngle
Definition: cuitabarea.hxx:378
std::unique_ptr< weld::MetricSpinButton > m_xMtrColorFrom
Definition: cuitabarea.hxx:384
void SetControlState_Impl(css::awt::GradientStyle eXGS)
Definition: tpgradnt.cxx:590
std::unique_ptr< weld::CheckButton > m_xCbIncrement
Definition: cuitabarea.hxx:389
std::unique_ptr< weld::ComboBox > m_xLbGradientType
Definition: cuitabarea.hxx:374
SvxXRectPreview m_aCtlPreview
Definition: cuitabarea.hxx:373
void ChangeGradientHdl_Impl()
Definition: tpgradnt.cxx:506
XFillAttrSetItem m_aXFillAttr
Definition: cuitabarea.hxx:367
void ModifiedHdl_Impl(void const *)
Definition: tpgradnt.cxx:283
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpgradnt.cxx:175
std::unique_ptr< weld::Button > m_xBtnModify
Definition: cuitabarea.hxx:391
std::unique_ptr< weld::CustomWeld > m_xCtlPreview
Definition: cuitabarea.hxx:392
std::unique_ptr< ColorListBox > m_xLbColorTo
Definition: cuitabarea.hxx:385
sal_Int32 SearchGradientList(std::u16string_view rGradientName)
Definition: tpgradnt.cxx:636
std::unique_ptr< weld::Scale > m_xSliderAngle
Definition: cuitabarea.hxx:380
std::unique_ptr< weld::Scale > m_xSliderBorder
Definition: cuitabarea.hxx:382
XGradientListRef m_pGradientList
Definition: cuitabarea.hxx:362
SvxGradientTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: tpgradnt.cxx:42
virtual bool FillItemSet(SfxItemSet *) override
Definition: tpgradnt.cxx:183
virtual ~SvxGradientTabPage() override
Definition: tpgradnt.cxx:118
std::unique_ptr< SvxPresetListBox > m_xGradientLB
Definition: cuitabarea.hxx:387
std::unique_ptr< weld::Label > m_xFtCenter
Definition: cuitabarea.hxx:375
ChangeType * m_pnColorListState
Definition: cuitabarea.hxx:365
XColorListRef m_pColorList
Definition: cuitabarea.hxx:361
std::unique_ptr< weld::MetricSpinButton > m_xMtrColorTo
Definition: cuitabarea.hxx:386
basegfx::BColorStops m_aColorStops
Definition: cuitabarea.hxx:371
const SfxItemSet & m_rOutAttrs
Definition: cuitabarea.hxx:359
std::unique_ptr< weld::MetricSpinButton > m_xMtrBorder
Definition: cuitabarea.hxx:381
std::unique_ptr< weld::MetricSpinButton > m_xMtrCenterY
Definition: cuitabarea.hxx:377
SfxItemSet & m_rXFSet
Definition: cuitabarea.hxx:368
std::unique_ptr< weld::MetricSpinButton > m_xMtrAngle
Definition: cuitabarea.hxx:379
void SetAttributes(const SfxItemSet &rItemSet)
void disposeAndClear()
const basegfx::BGradient & GetGradientValue() const
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
int nCount
SVXCORE_DLLPUBLIC OUString SvxResId(TranslateId aId)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Size SFX2_DLLPUBLIC getDrawPreviewOptimalSize(const OutputDevice &rReference)
URL aURL
FieldUnit
sal_Int16 nValue
TRISTATE_FALSE
TRISTATE_TRUE
OUString aName
sal_uInt16 nPos
#define SAL_WARN_IF(condition, area, stream)
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
int i
long Long
sal_Int16 nId
static SfxItemSet & rSet
DeactivateRC
IMPL_LINK(SvxGradientTabPage, ModifiedListBoxHdl_Impl, weld::ComboBox &, rListBox, void)
Definition: tpgradnt.cxx:239
IMPL_LINK_NOARG(SvxGradientTabPage, ChangeAutoStepHdl_Impl, weld::Toggleable &, void)
Definition: tpgradnt.cxx:270
#define VALUESET_ITEM_NOTFOUND
constexpr OUStringLiteral PERCENT(u"Percent")
RET_OK
RET_YES
constexpr TypedWhichId< XGradientStepCountItem > XATTR_GRADIENTSTEPCOUNT(XATTR_FILL_FIRST+6)
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)
constexpr TypedWhichId< XFillGradientItem > XATTR_FILLGRADIENT(XATTR_FILL_FIRST+2)