1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <ShadowPropertyPanel.hxx>
#include <comphelper/string.hxx>
#include <sfx2/sidebar/ControlFactory.hxx>
#include <svx/colorbox.hxx>
#include <svx/strings.hrc>
#include <svx/svxids.hrc>
#include <svx/dialmgr.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/dispatch.hxx>
#include <svx/xlineit0.hxx>
#include <svx/xtable.hxx>
#include <svtools/valueset.hxx>
#include <unotools/pathoptions.hxx>
#include <svx/xattr.hxx>
#include <svx/svddef.hxx>
#include <svx/sdooitm.hxx>
#include <svx/sdshitm.hxx>
#include <svx/sdshtitm.hxx>
#include <svx/sdprcitm.hxx>
#include <svx/sdsxyitm.hxx>
#include <svx/svdmodel.hxx>
#include <svx/drawitem.hxx>
#include <svx/sdshcitm.hxx>
using namespace css;
using namespace css::uno;
namespace {
sal_uInt32 ParseText(OUString const & sTmp)
{
if (sTmp.isEmpty())
return 0;
sal_Unicode nChar = sTmp[0];
if( nChar == '-' )
{
if (sTmp.getLength() < 2)
return 0;
nChar = sTmp[1];
}
if( (nChar < '0') || (nChar > '9') )
return 0;
const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
rtl_math_ConversionStatus eStatus;
double fTmp = rtl::math::stringToDouble( sTmp, cSep, 0, &eStatus);
if (eStatus != rtl_math_ConversionStatus_Ok)
return 0;
return fTmp;
}
}
namespace svx { namespace sidebar {
ShadowPropertyPanel::ShadowPropertyPanel(
vcl::Window* pParent,
const uno::Reference<css::frame::XFrame>& rxFrame,
SfxBindings* pBindings)
: PanelLayout(pParent, "ShadowPropertyPanel", "svx/ui/sidebarshadow.ui", rxFrame),
maShadowController(SID_ATTR_FILL_SHADOW, *pBindings, *this),
maShadowTransController(SID_ATTR_SHADOW_TRANSPARENCE, *pBindings, *this),
maShadowColorController(SID_ATTR_SHADOW_COLOR, *pBindings, *this),
maShadowXDistanceController(SID_ATTR_SHADOW_XDISTANCE, *pBindings, *this),
maShadowYDistanceController(SID_ATTR_SHADOW_YDISTANCE, *pBindings, *this),
mpBindings(pBindings),
nX(0),
nY(0),
nXY(0)
{
get(mpShowShadow,"SHOW_SHADOW");
get(mpFTAngle,"angle");
get(mpShadowAngle,"LB_ANGLE");
get(mpFTDistance,"distance");
get(mpShadowDistance,"LB_DISTANCE");
get(mpFTTransparency,"transparency_label");
get(mpShadowTransSlider,"transparency_slider");
get(mpShadowTransMetric,"FIELD_TRANSPARENCY");
get(mpFTColor,"color");
get(mpLBShadowColor,"LB_SHADOW_COLOR");
Initialize();
}
ShadowPropertyPanel::~ShadowPropertyPanel()
{
disposeOnce();
}
void ShadowPropertyPanel::dispose()
{
mpShowShadow.clear();
mpFTAngle.clear();
mpShadowAngle.clear();
mpFTDistance.clear();
mpShadowDistance.clear();
mpFTTransparency.clear();
mpShadowTransSlider.clear();
mpShadowTransMetric.clear();
mpFTColor.clear();
mpLBShadowColor.clear();
maShadowController.dispose();
maShadowTransController.dispose();
maShadowColorController.dispose();
maShadowXDistanceController.dispose();
maShadowYDistanceController.dispose();
PanelLayout::dispose();
}
void ShadowPropertyPanel::Initialize()
{
mpShowShadow->SetState( TRISTATE_FALSE );
mpShowShadow->SetClickHdl( LINK(this, ShadowPropertyPanel, ClickShadowHdl ) );
mpShadowTransMetric->SetModifyHdl( LINK(this, ShadowPropertyPanel, ModifyShadowTransMetricHdl) );
mpLBShadowColor->SetSelectHdl( LINK( this, ShadowPropertyPanel, ModifyShadowColorHdl ) );
mpShadowAngle->SetModifyHdl( LINK(this, ShadowPropertyPanel, ModifyShadowDistanceHdl) );
mpShadowDistance->SetModifyHdl( LINK(this, ShadowPropertyPanel, ModifyShadowDistanceHdl) );
mpShadowTransSlider->SetRange(Range(0,100));
mpShadowTransSlider->SetUpdateMode(true);
mpShadowTransSlider->SetSlideHdl( LINK(this, ShadowPropertyPanel, ModifyShadowTransSliderHdl) );
for(sal_uInt16 i = 0; i <= 20 ; i++)
mpShadowDistance->InsertValue(i*2,FUNIT_POINT);
InsertAngleValues();
}
IMPL_LINK_NOARG(ShadowPropertyPanel, ClickShadowHdl, Button*, void)
{
if( mpShowShadow->GetState() == TRISTATE_FALSE )
{
SdrOnOffItem aItem(makeSdrShadowItem(false));
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_FILL_SHADOW,
SfxCallMode::RECORD, { &aItem });
}
else
{
SdrOnOffItem aItem(makeSdrShadowItem(true));
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_FILL_SHADOW,
SfxCallMode::RECORD, { &aItem });
}
}
IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowColorHdl, SvxColorListBox&, void)
{
XColorItem aItem(makeSdrShadowColorItem(mpLBShadowColor->GetSelectEntryColor()));
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_COLOR,
SfxCallMode::RECORD, { &aItem });
}
IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowTransMetricHdl, Edit&, void)
{
sal_uInt16 nVal = mpShadowTransMetric->GetValue();
SetTransparencyValue(nVal);
SdrPercentItem aItem( makeSdrShadowTransparenceItem(nVal) );
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_TRANSPARENCE,
SfxCallMode::RECORD, { &aItem });
}
IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowTransSliderHdl, Slider*, void)
{
sal_uInt16 nVal = mpShadowTransSlider->GetThumbPos();
SetTransparencyValue(nVal);
SdrPercentItem aItem( makeSdrShadowTransparenceItem(nVal) );
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_TRANSPARENCE,
SfxCallMode::RECORD, { &aItem });
}
IMPL_LINK_NOARG(ShadowPropertyPanel, ModifyShadowDistanceHdl, Edit&, void)
{
OUString sAngle = mpShadowAngle->GetText();
nXY = mpShadowDistance->GetValue(FUNIT_100TH_MM);
switch(ParseText(sAngle))
{
case 0: nX = nXY; nY = 0; break;
case 45: nX = nXY; nY = -nXY; break;
case 90: nX = 0; nY = - nXY; break;
case 135: nX = nY = -nXY; break;
case 180: nX = -nXY; nY = 0; break;
case 225: nX = -nXY; nY = nXY; break;
case 270: nX = 0; nY = nXY; break;
case 315: nX = nY = nXY; break;
}
SdrMetricItem aXItem(makeSdrShadowXDistItem(nX));
SdrMetricItem aYItem(makeSdrShadowYDistItem(nY));
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_XDISTANCE,
SfxCallMode::RECORD, { &aXItem });
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_SHADOW_YDISTANCE,
SfxCallMode::RECORD, { &aYItem });
}
void ShadowPropertyPanel::UpdateControls()
{
if(mpShowShadow->GetState() == TRISTATE_FALSE)
{
mpShadowDistance->Disable();
mpLBShadowColor->Disable();
mpShadowAngle->Disable();
mpFTAngle->Disable();
mpFTDistance->Disable();
mpFTTransparency->Disable();
mpFTColor->Disable();
mpShadowTransSlider->Disable();
mpShadowTransMetric->Disable();
return;
}
else
{
mpShadowDistance->Enable();
mpLBShadowColor->Enable();
mpShadowAngle->Enable();
mpFTAngle->Enable();
mpFTDistance->Enable();
mpFTTransparency->Enable();
mpFTColor->Enable();
mpShadowTransSlider->Enable();
mpShadowTransMetric->Enable();
}
if(nX > 0 && nY == 0) { mpShadowAngle->SelectEntryPos(0); nXY = nX; }
else if( nX > 0 && nY < 0 ) { mpShadowAngle->SelectEntryPos(1); nXY = nX; }
else if( nX == 0 && nY < 0 ) { mpShadowAngle->SelectEntryPos(2); nXY = -nY; }
else if( nX < 0 && nY < 0 ) { mpShadowAngle->SelectEntryPos(3); nXY = -nY; }
else if( nX < 0 && nY == 0 ) { mpShadowAngle->SelectEntryPos(4); nXY = -nX; }
else if( nX < 0 && nY > 0 ) { mpShadowAngle->SelectEntryPos(5); nXY = nY; }
else if( nX == 0 && nY > 0 ) { mpShadowAngle->SelectEntryPos(6); nXY = nY; }
else if( nX > 0 && nY > 0 ) { mpShadowAngle->SelectEntryPos(7); nXY = nX; }
else { nXY = 0; }
mpShadowDistance->SetValue(nXY, FUNIT_100TH_MM);
}
void ShadowPropertyPanel::SetTransparencyValue(long nVal)
{
mpShadowTransSlider->SetThumbPos(nVal);
mpShadowTransMetric->SetValue(nVal);
}
void ShadowPropertyPanel::DataChanged(const DataChangedEvent& /*rEvent*/)
{
}
void ShadowPropertyPanel::InsertAngleValues()
{
mpShadowAngle->InsertValue(0, FUNIT_CUSTOM);
mpShadowAngle->InsertValue(45, FUNIT_CUSTOM);
mpShadowAngle->InsertValue(90, FUNIT_CUSTOM);
mpShadowAngle->InsertValue(135, FUNIT_CUSTOM);
mpShadowAngle->InsertValue(180, FUNIT_CUSTOM);
mpShadowAngle->InsertValue(225,FUNIT_CUSTOM);
mpShadowAngle->InsertValue(270, FUNIT_CUSTOM);
mpShadowAngle->InsertValue(315,FUNIT_CUSTOM);
}
void ShadowPropertyPanel::NotifyItemUpdate(
sal_uInt16 nSID,
SfxItemState eState,
const SfxPoolItem* pState,
const bool /*bIsEnabled*/)
{
switch(nSID)
{
case SID_ATTR_FILL_SHADOW:
{
if(eState >= SfxItemState::DEFAULT)
{
const SdrOnOffItem* pItem = dynamic_cast< const SdrOnOffItem* >(pState);
if(pItem)
{
if(pItem->GetValue())
mpShowShadow->SetState( TRISTATE_TRUE );
else
mpShowShadow->SetState( TRISTATE_FALSE );
}
else
mpShowShadow.reset();
}
}
break;
case SID_ATTR_SHADOW_TRANSPARENCE:
{
if(eState >= SfxItemState::DEFAULT)
{
const SdrPercentItem* pTransparencyItem = dynamic_cast< const SdrPercentItem* >(pState);
if(pTransparencyItem)
{
const sal_uInt16 nVal = pTransparencyItem->GetValue();
SetTransparencyValue(nVal);
}
else
SetTransparencyValue(0);
}
}
break;
case SID_ATTR_SHADOW_COLOR:
{
if(eState >= SfxItemState::DEFAULT)
{
const XColorItem* pColorItem = dynamic_cast< const XColorItem* >(pState);
if(pColorItem)
{
mpLBShadowColor->SelectEntry(pColorItem->GetColorValue());
}
}
}
break;
case SID_ATTR_SHADOW_XDISTANCE:
{
if(eState >= SfxItemState::DEFAULT)
{
const SdrMetricItem* pXDistItem = dynamic_cast< const SdrMetricItem* >(pState);
if(pXDistItem)
{
nX = pXDistItem->GetValue();
}
}
}
break;
case SID_ATTR_SHADOW_YDISTANCE:
{
if(eState >= SfxItemState::DEFAULT)
{
const SdrMetricItem* pYDistItem = dynamic_cast< const SdrMetricItem* >(pState);
if(pYDistItem)
{
nY = pYDistItem->GetValue();
}
}
}
break;
}
UpdateControls();
}
VclPtr<vcl::Window> ShadowPropertyPanel::Create (
vcl::Window* pParent,
const uno::Reference<css::frame::XFrame>& rxFrame,
SfxBindings* pBindings)
{
if(pParent == nullptr)
throw lang::IllegalArgumentException("no parent Window given to ShadowPropertyPanel::Create", nullptr, 0);
if( !rxFrame.is() )
throw lang::IllegalArgumentException("no XFrame given to ShadowPropertyPanel::Create", nullptr, 1);
if(pBindings == nullptr)
throw lang::IllegalArgumentException("no SfxBindings given to ShadowPropertyPanel::Create", nullptr, 2);
return VclPtr<ShadowPropertyPanel>::Create(pParent, rxFrame, pBindings);
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|