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