1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "AreaTransparencyGradientControl.hxx"
23 #include "AreaPropertyPanel.hxx"
24 #include "AreaPropertyPanel.hrc"
25 
26 #include <svx/dialogs.hrc>
27 #include <svx/dialmgr.hxx>
28 #include <svx/xflftrit.hxx>
29 #include <sfx2/sidebar/propertypanel.hrc>
30 #include <sfx2/bindings.hxx>
31 #include <sfx2/dispatch.hxx>
32 
33 namespace svx { namespace sidebar {
34 
35 // positioning helpers
36 #define APOS1_1 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL), MAP_APPFONT))
37 #define APOS2_1 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL + FIXED_TEXT_HEIGHT + TEXT_CONTROL_SPACING_VERTICAL), MAP_APPFONT))
38 #define APOS1_2 Point(LogicToPixel(Point(POPUPPANEL_MARGIN_HORIZONTAL+CONTROL_WIDTH+CONTROL_SPACING_HORIZONTAL,POPUPPANEL_MARGIN_VERTICAL), MAP_APPFONT))
39 #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))
40 #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))
41 #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))
42 #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))
43 #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))
44 #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))
45 #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))
46 #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))
47 #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))
48 #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))
49 #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))
50 #define APOS_Left_Right_1 Point(LogicToPixel(Point(LEFT_RIGHT_X1,LEFT_RIGHT_Y1), MAP_APPFONT))
51 #define APOS_Left_Right_2 Point(LogicToPixel(Point(LEFT_RIGHT_X2,LEFT_RIGHT_Y1), MAP_APPFONT))
52 #define APOS_Left_Right_3 Point(LogicToPixel(Point(LEFT_RIGHT_X1,LEFT_RIGHT_Y2), MAP_APPFONT))
53 #define APOS_Left_Right_4 Point(LogicToPixel(Point(LEFT_RIGHT_X2,LEFT_RIGHT_Y2), MAP_APPFONT))
54 
55 
56 
57 
58 AreaTransparencyGradientControl::AreaTransparencyGradientControl (
59     Window* pParent,
60     AreaPropertyPanel& rPanel)
61     : PopupControl( pParent,SVX_RES(RID_POPUPPANEL_AREAPAGE_TRGR)),
62       maFtTrgrCenterX(this, SVX_RES(FT_TRGR_CENTER_X)),
63       maMtrTrgrCenterX(this, SVX_RES(MTR_TRGR_CENTER_X)),
64       maFtTrgrCenterY(this, SVX_RES(FT_TRGR_CENTER_Y)),
65       maMtrTrgrCenterY(this, SVX_RES(MTR_TRGR_CENTER_Y)),
66       maFtTrgrAngle(this, SVX_RES(FT_TRGR_ANGLE)),
67       maMtrTrgrAngle(this, SVX_RES(MTR_TRGR_ANGLE)),
68       maBtnLeft45(this, SVX_RES(BTN_LEFT_SECOND)),
69       maBtnRight45(this, SVX_RES(BTN_RIGHT_FIRST)),
70       maFtTrgrStartValue(this, SVX_RES(FT_TRGR_START_VALUE)),
71       maMtrTrgrStartValue(this, SVX_RES(MTR_TRGR_START_VALUE)),
72       maFtTrgrEndValue(this, SVX_RES(FT_TRGR_END_VALUE)),
73       maMtrTrgrEndValue(this, SVX_RES(MTR_TRGR_END_VALUE)),
74       maFtTrgrBorder(this, SVX_RES(FT_TRGR_BORDER)),
75       maMtrTrgrBorder(this, SVX_RES(MTR_TRGR_BORDER)),
76       maRotLeft( SVX_RES(IMG_ROT_LEFT)),
77       maRotRight( SVX_RES(IMG_ROT_RIGHT)),
78       mrAreaPropertyPanel(rPanel),
79       mpBindings(NULL)
80 {
81 	Link aLink = LINK( this, AreaTransparencyGradientControl, ModifiedTrgrHdl_Impl);
82 	maMtrTrgrCenterX.SetModifyHdl( aLink );
83 	maMtrTrgrCenterY.SetModifyHdl( aLink );
84 	maMtrTrgrAngle.SetModifyHdl( aLink );
85 	maMtrTrgrBorder.SetModifyHdl( aLink );
86 	maMtrTrgrStartValue.SetModifyHdl( aLink );
87 	maMtrTrgrEndValue.SetModifyHdl( aLink );
88 	aLink = LINK( this, AreaTransparencyGradientControl, Left_Click45_Impl);
89 	maBtnLeft45.SetSelectHdl( aLink );
90 	aLink = LINK( this, AreaTransparencyGradientControl, Right_Click45_Impl);
91 	maBtnRight45.SetSelectHdl( aLink );
92 	maBtnLeft45.SetItemImage(1,maRotLeft);
93 	Size aTbxSize = maBtnLeft45.CalcWindowSizePixel();
94 	maBtnLeft45.SetOutputSizePixel( aTbxSize );
95 	maBtnLeft45.SetQuickHelpText(1, String(SVX_RES(STR_HELP_LEFT)));	//acc wj
96 
97 	maBtnRight45.SetItemImage(1,maRotRight);
98 	aTbxSize = maBtnRight45.CalcWindowSizePixel();
99 	maBtnRight45.SetOutputSizePixel( aTbxSize );
100 	maBtnRight45.SetQuickHelpText(1, String(SVX_RES(STR_HELP_RIGHT)));	//acc wj
101 
102 	maBtnLeft45.SetBackground(Wallpaper());
103 	maBtnLeft45.SetPaintTransparent(true);
104 	maBtnRight45.SetBackground(Wallpaper());
105 	maBtnRight45.SetPaintTransparent(true);
106 
107 	FreeResource();
108     mpBindings = mrAreaPropertyPanel.GetBindings();
109 }
110 
111 
112 
113 
114 AreaTransparencyGradientControl::~AreaTransparencyGradientControl (void)
115 {
116 }
117 
118 
119 
120 
121 void AreaTransparencyGradientControl::ToGetFocus()
122 {
123 	if(maMtrTrgrCenterX.IsVisible())
124 		maMtrTrgrCenterX.GrabFocus();
125 	else
126 		maMtrTrgrAngle.GrabFocus();
127 }
128 
129 
130 
131 
132 void AreaTransparencyGradientControl::Rearrange(XFillFloatTransparenceItem* pGradientItem)
133 {
134 	InitStatus(pGradientItem);
135 	const XGradient& rGradient = pGradientItem->GetGradientValue();
136 	XGradientStyle eXGS(rGradient.GetGradientStyle());
137 	Size aSize(POP_WIDTH,POP_HEIGHT);
138 	aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
139 	Size aSize2(POP_WIDTH,POP_HEIGHT2);
140 	aSize2 = LogicToPixel( aSize2, MapMode(MAP_APPFONT) );
141 	long aPosY = 0;
142 	Point aPointAngle;
143 	Size aSizeAngle = maMtrTrgrAngle.GetSizePixel();
144 	Size aTbxSize = maBtnLeft45.CalcWindowSizePixel();
145 
146 	switch(eXGS)
147 	{
148 	case XGRAD_LINEAR:
149 	case XGRAD_AXIAL:
150 		maFtTrgrCenterX.Hide();
151 		maMtrTrgrCenterX.Hide();
152 		maFtTrgrCenterY.Hide();
153 		maMtrTrgrCenterY.Hide();
154 		maFtTrgrAngle.Show();
155 		maFtTrgrAngle.SetPosPixel(APOS1_1);
156 		maMtrTrgrAngle.Show();
157 		maMtrTrgrAngle.SetPosPixel(APOS2_1);
158 		maFtTrgrStartValue.SetPosPixel(APOS1_3);
159 		maMtrTrgrStartValue.SetPosPixel(APOS1_4);
160 		maFtTrgrEndValue.SetPosPixel(APOS2_3);
161 		maMtrTrgrEndValue.SetPosPixel(APOS2_4);
162 		maFtTrgrBorder.SetPosPixel(APOS1_5);
163 		maMtrTrgrBorder.SetPosPixel(APOS1_6);
164 
165 		maBtnLeft45.Show();
166 		maBtnRight45.Show();
167 
168 		aPointAngle = maMtrTrgrAngle.GetPosPixel();
169 		aPosY = aPointAngle.getY() + aSizeAngle.getHeight() - aTbxSize.getHeight();
170 
171 		maBtnLeft45.SetPosPixel(Point(APOS_Left_Right_1.getX(), aPosY));
172 		maBtnRight45.SetPosPixel(Point(APOS_Left_Right_2.getX(), aPosY));
173 
174 		SetSizePixel(aSize2);
175 		break;
176 
177 	case XGRAD_RADIAL:
178 		maFtTrgrCenterX.Show();
179 		maFtTrgrCenterX.SetPosPixel(APOS1_1);
180 		maMtrTrgrCenterX.Show();
181 		maMtrTrgrCenterX.SetPosPixel(APOS2_1);
182 		maFtTrgrCenterY.Show();
183 		maFtTrgrCenterY.SetPosPixel(APOS1_2);
184 		maMtrTrgrCenterY.Show();
185 		maMtrTrgrCenterY.SetPosPixel(APOS2_2);
186 		maFtTrgrAngle.Hide();
187 		maMtrTrgrAngle.Hide();
188 		maFtTrgrStartValue.SetPosPixel(APOS1_3);
189 		maMtrTrgrStartValue.SetPosPixel(APOS1_4);
190 		maFtTrgrEndValue.SetPosPixel(APOS2_3);
191 		maMtrTrgrEndValue.SetPosPixel(APOS2_4);
192 		maFtTrgrBorder.SetPosPixel(APOS1_5);
193 		maMtrTrgrBorder.SetPosPixel(APOS1_6);
194 
195 		maBtnLeft45.Hide();
196 		maBtnRight45.Hide();
197 
198 		SetSizePixel(aSize2);
199 
200 		break;
201 
202 	case XGRAD_ELLIPTICAL:
203 	case XGRAD_SQUARE:
204 	case XGRAD_RECT:
205 		maFtTrgrCenterX.Show();
206 		maFtTrgrCenterX.SetPosPixel(APOS1_1);
207 		maMtrTrgrCenterX.Show();
208 		maMtrTrgrCenterX.SetPosPixel(APOS2_1);
209 		maFtTrgrCenterY.Show();
210 		maFtTrgrCenterY.SetPosPixel(APOS1_2);
211 		maMtrTrgrCenterY.Show();
212 		maMtrTrgrCenterY.SetPosPixel(APOS2_2);
213 		maFtTrgrAngle.Show();
214 		maFtTrgrAngle.SetPosPixel(APOS1_3);
215 		maMtrTrgrAngle.Show();
216 		maMtrTrgrAngle.SetPosPixel(APOS1_4);
217 
218 		maFtTrgrStartValue.SetPosPixel(APOS1_5);
219 		maMtrTrgrStartValue.SetPosPixel(APOS1_6);
220 		maFtTrgrEndValue.SetPosPixel(APOS2_5);
221 		maMtrTrgrEndValue.SetPosPixel(APOS2_6);
222 		maFtTrgrBorder.SetPosPixel(APOS1_7);
223 		maMtrTrgrBorder.SetPosPixel(APOS1_8);
224 
225 		maBtnLeft45.Show();
226 		maBtnRight45.Show();
227 
228 		aPointAngle = maMtrTrgrAngle.GetPosPixel();
229 		aPosY = aPointAngle.getY() + aSizeAngle.getHeight() - aTbxSize.getHeight();
230 
231 		maBtnLeft45.SetPosPixel(Point(APOS_Left_Right_3.getX(), aPosY));
232 		maBtnRight45.SetPosPixel(Point(APOS_Left_Right_4.getX(), aPosY));
233 
234 		SetSizePixel(aSize);
235 
236 		break;
237 	}
238 }
239 
240 
241 
242 
243 void AreaTransparencyGradientControl::InitStatus(XFillFloatTransparenceItem* pGradientItem)
244 {
245 	const XGradient& rGradient = pGradientItem->GetGradientValue();
246 
247 	XGradient aGradient;
248 
249 	if (rGradient.GetXOffset() == AreaPropertyPanel::DEFAULT_CENTERX
250         && rGradient.GetYOffset() == AreaPropertyPanel::DEFAULT_CENTERY
251         && (rGradient.GetAngle() / 10) == AreaPropertyPanel::DEFAULT_ANGLE
252         && ((sal_uInt16)((((sal_uInt16)rGradient.GetStartColor().GetRed() + 1) * 100) / 255))
253             == AreaPropertyPanel::DEFAULT_STARTVALUE
254         && ((sal_uInt16)((((sal_uInt16)rGradient.GetEndColor().GetRed() + 1) * 100) / 255))
255             == AreaPropertyPanel::DEFAULT_ENDVALUE
256         && rGradient.GetBorder() == AreaPropertyPanel::DEFAULT_BORDER)
257 	{
258         aGradient = mrAreaPropertyPanel.GetGradient(rGradient.GetGradientStyle());
259 	}
260 	else
261     {
262 		aGradient = rGradient;
263     }
264 	maMtrTrgrCenterX.SetValue(aGradient.GetXOffset());
265 	maMtrTrgrCenterY.SetValue(aGradient.GetYOffset());
266 	maMtrTrgrAngle.SetValue(aGradient.GetAngle() / 10);
267 	maMtrTrgrStartValue.SetValue((sal_uInt16)((((sal_uInt16)aGradient.GetStartColor().GetRed() + 1) * 100) / 255));
268 	maMtrTrgrEndValue.SetValue((sal_uInt16)((((sal_uInt16)aGradient.GetEndColor().GetRed() + 1) * 100) / 255));
269 	maMtrTrgrBorder.SetValue(aGradient.GetBorder());
270 }
271 
272 
273 
274 
275 void AreaTransparencyGradientControl::ExecuteValueModify( sal_uInt8 nStartCol, sal_uInt8 nEndCol )
276 {
277 	//Added
278 	sal_Int16 aMtrValue = (sal_Int16)maMtrTrgrAngle.GetValue();
279 	while(aMtrValue<0)
280 		aMtrValue += 360;
281 	sal_uInt16 nVal = aMtrValue/360;
282 	nVal = aMtrValue - nVal*360;
283 	maMtrTrgrAngle.SetValue(nVal);
284 	//End of new code
285 	XGradient aTmpGradient(
286 		Color(nStartCol, nStartCol, nStartCol),
287 		Color(nEndCol, nEndCol, nEndCol),
288 		(XGradientStyle)(mrAreaPropertyPanel.GetSelectedTransparencyTypeIndex()-2),
289 		(sal_uInt16)maMtrTrgrAngle.GetValue() * 10,
290 		(sal_uInt16)maMtrTrgrCenterX.GetValue(),
291 		(sal_uInt16)maMtrTrgrCenterY.GetValue(),
292 		(sal_uInt16)maMtrTrgrBorder.GetValue(),
293 		100, 100);
294 
295     mrAreaPropertyPanel.SetGradient(aTmpGradient);
296 
297 	SfxItemPool* pPool = NULL;
298 	bool bEnable = true;
299 	XFillFloatTransparenceItem aGradientItem(pPool,aTmpGradient, bEnable );
300 
301 	mpBindings->GetDispatcher()->Execute( SID_ATTR_FILL_FLOATTRANSPARENCE, SFX_CALLMODE_RECORD, &aGradientItem, 0L );
302 }
303 
304 
305 
306 
307 IMPL_LINK(AreaTransparencyGradientControl, ModifiedTrgrHdl_Impl, void *, /* pControl */)
308 {
309 	sal_uInt8 nStartCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrStartValue.GetValue() * 255) / 100);
310 	sal_uInt8 nEndCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrEndValue.GetValue() * 255) / 100);
311 	ExecuteValueModify( nStartCol, nEndCol );
312 	return( 0L );
313 }
314 
315 
316 
317 
318 IMPL_LINK(AreaTransparencyGradientControl, Left_Click45_Impl, void *, /* pControl */)
319 {
320 	sal_uInt8 nStartCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrStartValue.GetValue() * 255) / 100);
321 	sal_uInt8 nEndCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrEndValue.GetValue() * 255) / 100);
322 	sal_uInt16 aTemp = (sal_uInt16)maMtrTrgrAngle.GetValue();
323 	if(aTemp>=315)
324 		aTemp -= 360;
325 	aTemp += 45;
326 	maMtrTrgrAngle.SetValue(aTemp);
327 	ExecuteValueModify( nStartCol, nEndCol );
328 	return( 0L );
329 }
330 
331 
332 
333 
334 IMPL_LINK(AreaTransparencyGradientControl, Right_Click45_Impl, void *, /* pControl */)
335 {
336 	sal_uInt8 nStartCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrStartValue.GetValue() * 255) / 100);
337 	sal_uInt8 nEndCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrEndValue.GetValue() * 255) / 100);
338 	sal_uInt16 aTemp = (sal_uInt16)maMtrTrgrAngle.GetValue();
339 	if(aTemp<45)
340 		aTemp += 360;
341 	aTemp -= 45;
342 	maMtrTrgrAngle.SetValue(aTemp);
343 	ExecuteValueModify( nStartCol, nEndCol );
344 	return( 0L );
345 }
346 
347 } } // end of namespace svx::sidebar
348 
349 // eof
350