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