1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #include "AreaTransparencyGradientControl.hxx"
20 #include "AreaPropertyPanel.hxx"
21 #include "AreaPropertyPanel.hrc"
23 #include <svx/dialogs.hrc>
24 #include <svx/dialmgr.hxx>
25 #include <svx/xflftrit.hxx>
26 #include <sfx2/sidebar/ResourceDefinitions.hrc>
27 #include <sfx2/bindings.hxx>
28 #include <sfx2/dispatch.hxx>
30 namespace svx
{ namespace sidebar
{
32 // positioning helpers
33 #define APOS1_1 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL), MAP_APPFONT))
34 #define APOS2_1 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL), MAP_APPFONT))
35 #define APOS1_2 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL+CONTROL_WIDTH+CONTROL_SPACING_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL), MAP_APPFONT))
36 #define APOS2_2 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL+CONTROL_WIDTH+CONTROL_SPACING_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL), MAP_APPFONT))
37 #define APOS1_3 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL+MBOX_HEIGHT+CONTROL_SPACING_VERTICAL), MAP_APPFONT))
38 #define APOS1_4 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + 2*(FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL)+MBOX_HEIGHT+CONTROL_SPACING_VERTICAL), MAP_APPFONT))
39 #define APOS2_3 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL+CONTROL_WIDTH+CONTROL_SPACING_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL+MBOX_HEIGHT+CONTROL_SPACING_VERTICAL), MAP_APPFONT))
40 #define APOS2_4 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL+CONTROL_WIDTH+CONTROL_SPACING_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + 2*(FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL)+MBOX_HEIGHT+CONTROL_SPACING_VERTICAL), MAP_APPFONT))
41 #define APOS1_5 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + 2*(FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL+MBOX_HEIGHT+CONTROL_SPACING_VERTICAL)), MAP_APPFONT))
42 #define APOS1_6 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + 3*(FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL)+2*(MBOX_HEIGHT+CONTROL_SPACING_VERTICAL)), MAP_APPFONT))
43 #define APOS2_5 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL+CONTROL_WIDTH+CONTROL_SPACING_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + 2*(FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL+MBOX_HEIGHT+CONTROL_SPACING_VERTICAL)), MAP_APPFONT))
44 #define APOS2_6 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL+CONTROL_WIDTH+CONTROL_SPACING_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + 3*(FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL)+2*(MBOX_HEIGHT+CONTROL_SPACING_VERTICAL)), MAP_APPFONT))
45 #define APOS1_7 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + 3*(FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL+MBOX_HEIGHT+CONTROL_SPACING_VERTICAL)), MAP_APPFONT))
46 #define APOS1_8 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + 4*(FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL)+3*(MBOX_HEIGHT+CONTROL_SPACING_VERTICAL)), MAP_APPFONT))
47 #define APOS_Left_Right_1 Point(LogicToPixel(Point(LEFT_RIGHT_X1,LEFT_RIGHT_Y1), MAP_APPFONT))
48 #define APOS_Left_Right_2 Point(LogicToPixel(Point(LEFT_RIGHT_X2,LEFT_RIGHT_Y1), MAP_APPFONT))
49 #define APOS_Left_Right_3 Point(LogicToPixel(Point(LEFT_RIGHT_X1,LEFT_RIGHT_Y2), MAP_APPFONT))
50 #define APOS_Left_Right_4 Point(LogicToPixel(Point(LEFT_RIGHT_X2,LEFT_RIGHT_Y2), MAP_APPFONT))
55 AreaTransparencyGradientControl::AreaTransparencyGradientControl (
57 AreaPropertyPanel
& rPanel
)
58 : PopupControl( pParent
,SVX_RES(RID_POPUPPANEL_AREAPAGE_TRGR
)),
59 maFtTrgrCenterX(VclPtr
<FixedText
>::Create(this, SVX_RES(FT_TRGR_CENTER_X
))),
60 maMtrTrgrCenterX(VclPtr
<MetricField
>::Create(this, SVX_RES(MTR_TRGR_CENTER_X
))),
61 maFtTrgrCenterY(VclPtr
<FixedText
>::Create(this, SVX_RES(FT_TRGR_CENTER_Y
))),
62 maMtrTrgrCenterY(VclPtr
<MetricField
>::Create(this, SVX_RES(MTR_TRGR_CENTER_Y
))),
63 maFtTrgrAngle(VclPtr
<FixedText
>::Create(this, SVX_RES(FT_TRGR_ANGLE
))),
64 maMtrTrgrAngle(VclPtr
<MetricField
>::Create(this, SVX_RES(MTR_TRGR_ANGLE
))),
65 maBtnLeft45(VclPtr
<ToolBox
>::Create(this, SVX_RES(BTN_LEFT_SECOND
))),
66 maBtnRight45(VclPtr
<ToolBox
>::Create(this, SVX_RES(BTN_RIGHT_FIRST
))),
67 maFtTrgrStartValue(VclPtr
<FixedText
>::Create(this, SVX_RES(FT_TRGR_START_VALUE
))),
68 maMtrTrgrStartValue(VclPtr
<MetricField
>::Create(this, SVX_RES(MTR_TRGR_START_VALUE
))),
69 maFtTrgrEndValue(VclPtr
<FixedText
>::Create(this, SVX_RES(FT_TRGR_END_VALUE
))),
70 maMtrTrgrEndValue(VclPtr
<MetricField
>::Create(this, SVX_RES(MTR_TRGR_END_VALUE
))),
71 maFtTrgrBorder(VclPtr
<FixedText
>::Create(this, SVX_RES(FT_TRGR_BORDER
))),
72 maMtrTrgrBorder(VclPtr
<MetricField
>::Create(this, SVX_RES(MTR_TRGR_BORDER
))),
73 maRotLeft( SVX_RES(IMG_ROT_LEFT
)),
74 maRotRight( SVX_RES(IMG_ROT_RIGHT
)),
75 mrAreaPropertyPanel(rPanel
),
78 Link
<> aLink
= LINK( this, AreaTransparencyGradientControl
, ModifiedTrgrHdl_Impl
);
79 maMtrTrgrCenterX
->SetModifyHdl( aLink
);
80 maMtrTrgrCenterY
->SetModifyHdl( aLink
);
81 maMtrTrgrAngle
->SetModifyHdl( aLink
);
82 maMtrTrgrBorder
->SetModifyHdl( aLink
);
83 maMtrTrgrStartValue
->SetModifyHdl( aLink
);
84 maMtrTrgrEndValue
->SetModifyHdl( aLink
);
85 maBtnLeft45
->SetSelectHdl( LINK( this, AreaTransparencyGradientControl
, Left_Click45_Impl
) );
86 maBtnRight45
->SetSelectHdl( LINK( this, AreaTransparencyGradientControl
, Right_Click45_Impl
) );
87 maBtnLeft45
->SetItemImage(1,maRotLeft
);
88 Size aTbxSize
= maBtnLeft45
->CalcWindowSizePixel();
89 maBtnLeft45
->SetOutputSizePixel( aTbxSize
);
90 maBtnLeft45
->SetQuickHelpText(1, SVX_RESSTR(STR_HELP_LEFT
)); //acc wj
92 maBtnRight45
->SetItemImage(1,maRotRight
);
93 aTbxSize
= maBtnRight45
->CalcWindowSizePixel();
94 maBtnRight45
->SetOutputSizePixel( aTbxSize
);
95 maBtnRight45
->SetQuickHelpText(1, SVX_RESSTR(STR_HELP_RIGHT
)); //acc wj
97 maBtnLeft45
->SetBackground(Wallpaper());
98 maBtnLeft45
->SetPaintTransparent(true);
99 maBtnRight45
->SetBackground(Wallpaper());
100 maBtnRight45
->SetPaintTransparent(true);
103 mpBindings
= mrAreaPropertyPanel
.GetBindings();
107 AreaTransparencyGradientControl::~AreaTransparencyGradientControl()
112 void AreaTransparencyGradientControl::dispose()
114 maFtTrgrCenterX
.disposeAndClear();
115 maMtrTrgrCenterX
.disposeAndClear();
116 maFtTrgrCenterY
.disposeAndClear();
117 maMtrTrgrCenterY
.disposeAndClear();
118 maFtTrgrAngle
.disposeAndClear();
119 maMtrTrgrAngle
.disposeAndClear();
120 maBtnLeft45
.disposeAndClear();
121 maBtnRight45
.disposeAndClear();
122 maFtTrgrStartValue
.disposeAndClear();
123 maMtrTrgrStartValue
.disposeAndClear();
124 maFtTrgrEndValue
.disposeAndClear();
125 maMtrTrgrEndValue
.disposeAndClear();
126 maFtTrgrBorder
.disposeAndClear();
127 maMtrTrgrBorder
.disposeAndClear();
128 PopupControl::dispose();
131 void AreaTransparencyGradientControl::Rearrange(XFillFloatTransparenceItem
* pGradientItem
)
133 InitStatus(pGradientItem
);
134 const XGradient
& rGradient
= pGradientItem
->GetGradientValue();
135 css::awt::GradientStyle
eXGS(rGradient
.GetGradientStyle());
136 Size
aSize(POP_WIDTH
,POP_HEIGHT
);
137 aSize
= LogicToPixel( aSize
, MapMode(MAP_APPFONT
) );
138 Size
aSize2(POP_WIDTH
,POP_HEIGHT2
);
139 aSize2
= LogicToPixel( aSize2
, MapMode(MAP_APPFONT
) );
142 Size aSizeAngle
= maMtrTrgrAngle
->GetSizePixel();
143 Size aTbxSize
= maBtnLeft45
->CalcWindowSizePixel();
147 case css::awt::GradientStyle_LINEAR
:
148 case css::awt::GradientStyle_AXIAL
:
149 maFtTrgrCenterX
->Hide();
150 maMtrTrgrCenterX
->Hide();
151 maFtTrgrCenterY
->Hide();
152 maMtrTrgrCenterY
->Hide();
153 maFtTrgrAngle
->Show();
154 maFtTrgrAngle
->SetPosPixel(APOS1_1
);
155 maMtrTrgrAngle
->Show();
156 maMtrTrgrAngle
->SetPosPixel(APOS2_1
);
157 maFtTrgrStartValue
->SetPosPixel(APOS1_3
);
158 maMtrTrgrStartValue
->SetPosPixel(APOS1_4
);
159 maFtTrgrEndValue
->SetPosPixel(APOS2_3
);
160 maMtrTrgrEndValue
->SetPosPixel(APOS2_4
);
161 maFtTrgrBorder
->SetPosPixel(APOS1_5
);
162 maMtrTrgrBorder
->SetPosPixel(APOS1_6
);
165 maBtnRight45
->Show();
167 aPointAngle
= maMtrTrgrAngle
->GetPosPixel();
168 aPosY
= aPointAngle
.getY() + aSizeAngle
.getHeight() - aTbxSize
.getHeight();
170 maBtnLeft45
->SetPosPixel(Point(APOS_Left_Right_1
.getX(), aPosY
));
171 maBtnRight45
->SetPosPixel(Point(APOS_Left_Right_2
.getX(), aPosY
));
173 SetSizePixel(aSize2
);
176 case css::awt::GradientStyle_RADIAL
:
177 maFtTrgrCenterX
->Show();
178 maFtTrgrCenterX
->SetPosPixel(APOS1_1
);
179 maMtrTrgrCenterX
->Show();
180 maMtrTrgrCenterX
->SetPosPixel(APOS2_1
);
181 maFtTrgrCenterY
->Show();
182 maFtTrgrCenterY
->SetPosPixel(APOS1_2
);
183 maMtrTrgrCenterY
->Show();
184 maMtrTrgrCenterY
->SetPosPixel(APOS2_2
);
185 maFtTrgrAngle
->Hide();
186 maMtrTrgrAngle
->Hide();
187 maFtTrgrStartValue
->SetPosPixel(APOS1_3
);
188 maMtrTrgrStartValue
->SetPosPixel(APOS1_4
);
189 maFtTrgrEndValue
->SetPosPixel(APOS2_3
);
190 maMtrTrgrEndValue
->SetPosPixel(APOS2_4
);
191 maFtTrgrBorder
->SetPosPixel(APOS1_5
);
192 maMtrTrgrBorder
->SetPosPixel(APOS1_6
);
195 maBtnRight45
->Hide();
197 SetSizePixel(aSize2
);
201 case css::awt::GradientStyle_ELLIPTICAL
:
202 case css::awt::GradientStyle_SQUARE
:
203 case css::awt::GradientStyle_RECT
:
204 maFtTrgrCenterX
->Show();
205 maFtTrgrCenterX
->SetPosPixel(APOS1_1
);
206 maMtrTrgrCenterX
->Show();
207 maMtrTrgrCenterX
->SetPosPixel(APOS2_1
);
208 maFtTrgrCenterY
->Show();
209 maFtTrgrCenterY
->SetPosPixel(APOS1_2
);
210 maMtrTrgrCenterY
->Show();
211 maMtrTrgrCenterY
->SetPosPixel(APOS2_2
);
212 maFtTrgrAngle
->Show();
213 maFtTrgrAngle
->SetPosPixel(APOS1_3
);
214 maMtrTrgrAngle
->Show();
215 maMtrTrgrAngle
->SetPosPixel(APOS1_4
);
217 maFtTrgrStartValue
->SetPosPixel(APOS1_5
);
218 maMtrTrgrStartValue
->SetPosPixel(APOS1_6
);
219 maFtTrgrEndValue
->SetPosPixel(APOS2_5
);
220 maMtrTrgrEndValue
->SetPosPixel(APOS2_6
);
221 maFtTrgrBorder
->SetPosPixel(APOS1_7
);
222 maMtrTrgrBorder
->SetPosPixel(APOS1_8
);
225 maBtnRight45
->Show();
227 aPointAngle
= maMtrTrgrAngle
->GetPosPixel();
228 aPosY
= aPointAngle
.getY() + aSizeAngle
.getHeight() - aTbxSize
.getHeight();
230 maBtnLeft45
->SetPosPixel(Point(APOS_Left_Right_3
.getX(), aPosY
));
231 maBtnRight45
->SetPosPixel(Point(APOS_Left_Right_4
.getX(), aPosY
));
245 void AreaTransparencyGradientControl::InitStatus(XFillFloatTransparenceItem
* pGradientItem
)
247 const XGradient
& rGradient
= pGradientItem
->GetGradientValue();
251 if (rGradient
.GetXOffset() == AreaPropertyPanel::DEFAULT_CENTERX
252 && rGradient
.GetYOffset() == AreaPropertyPanel::DEFAULT_CENTERY
253 && (rGradient
.GetAngle() / 10) == AreaPropertyPanel::DEFAULT_ANGLE
254 && ((sal_uInt16
)((((sal_uInt16
)rGradient
.GetStartColor().GetRed() + 1) * 100) / 255))
255 == AreaPropertyPanel::DEFAULT_STARTVALUE
256 && ((sal_uInt16
)((((sal_uInt16
)rGradient
.GetEndColor().GetRed() + 1) * 100) / 255))
257 == AreaPropertyPanel::DEFAULT_ENDVALUE
258 && rGradient
.GetBorder() == AreaPropertyPanel::DEFAULT_BORDER
)
260 aGradient
= mrAreaPropertyPanel
.GetGradient(rGradient
.GetGradientStyle());
264 aGradient
= rGradient
;
266 maMtrTrgrCenterX
->SetValue(aGradient
.GetXOffset());
267 maMtrTrgrCenterY
->SetValue(aGradient
.GetYOffset());
268 maMtrTrgrAngle
->SetValue(aGradient
.GetAngle() / 10);
269 maMtrTrgrStartValue
->SetValue((sal_uInt16
)((((sal_uInt16
)aGradient
.GetStartColor().GetRed() + 1) * 100) / 255));
270 maMtrTrgrEndValue
->SetValue((sal_uInt16
)((((sal_uInt16
)aGradient
.GetEndColor().GetRed() + 1) * 100) / 255));
271 maMtrTrgrBorder
->SetValue(aGradient
.GetBorder());
277 void AreaTransparencyGradientControl::ExecuteValueModify( sal_uInt8 nStartCol
, sal_uInt8 nEndCol
)
280 sal_Int16 aMtrValue
= (sal_Int16
)maMtrTrgrAngle
->GetValue();
283 sal_uInt16 nVal
= aMtrValue
/360;
284 nVal
= aMtrValue
- nVal
*360;
285 maMtrTrgrAngle
->SetValue(nVal
);
287 XGradient
aTmpGradient(
288 Color(nStartCol
, nStartCol
, nStartCol
),
289 Color(nEndCol
, nEndCol
, nEndCol
),
290 (css::awt::GradientStyle
)(mrAreaPropertyPanel
.GetSelectedTransparencyTypeIndex()-2),
291 (sal_uInt16
)maMtrTrgrAngle
->GetValue() * 10,
292 (sal_uInt16
)maMtrTrgrCenterX
->GetValue(),
293 (sal_uInt16
)maMtrTrgrCenterY
->GetValue(),
294 (sal_uInt16
)maMtrTrgrBorder
->GetValue(),
297 mrAreaPropertyPanel
.SetGradient(aTmpGradient
);
299 SfxItemPool
* pPool
= NULL
;
301 XFillFloatTransparenceItem
aGradientItem(pPool
,aTmpGradient
, bEnable
);
303 mpBindings
->GetDispatcher()->Execute( SID_ATTR_FILL_FLOATTRANSPARENCE
, SfxCallMode::RECORD
, &aGradientItem
, 0L );
309 IMPL_LINK_NOARG(AreaTransparencyGradientControl
, ModifiedTrgrHdl_Impl
)
311 sal_uInt8 nStartCol
= (sal_uInt8
)(((sal_uInt16
)maMtrTrgrStartValue
->GetValue() * 255) / 100);
312 sal_uInt8 nEndCol
= (sal_uInt8
)(((sal_uInt16
)maMtrTrgrEndValue
->GetValue() * 255) / 100);
313 ExecuteValueModify( nStartCol
, nEndCol
);
320 IMPL_LINK_NOARG_TYPED(AreaTransparencyGradientControl
, Left_Click45_Impl
, ToolBox
*, void)
322 sal_uInt8 nStartCol
= (sal_uInt8
)(((sal_uInt16
)maMtrTrgrStartValue
->GetValue() * 255) / 100);
323 sal_uInt8 nEndCol
= (sal_uInt8
)(((sal_uInt16
)maMtrTrgrEndValue
->GetValue() * 255) / 100);
324 sal_uInt16 aTemp
= (sal_uInt16
)maMtrTrgrAngle
->GetValue();
328 maMtrTrgrAngle
->SetValue(aTemp
);
329 ExecuteValueModify( nStartCol
, nEndCol
);
335 IMPL_LINK_NOARG_TYPED(AreaTransparencyGradientControl
, Right_Click45_Impl
, ToolBox
*, void)
337 sal_uInt8 nStartCol
= (sal_uInt8
)(((sal_uInt16
)maMtrTrgrStartValue
->GetValue() * 255) / 100);
338 sal_uInt8 nEndCol
= (sal_uInt8
)(((sal_uInt16
)maMtrTrgrEndValue
->GetValue() * 255) / 100);
339 sal_uInt16 aTemp
= (sal_uInt16
)maMtrTrgrAngle
->GetValue();
343 maMtrTrgrAngle
->SetValue(aTemp
);
344 ExecuteValueModify( nStartCol
, nEndCol
);
347 } } // end of namespace svx::sidebar
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */