Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #include "AreaTransparencyGradientControl.hxx"
20 : #include "AreaPropertyPanel.hxx"
21 : #include "AreaPropertyPanel.hrc"
22 :
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>
29 :
30 : namespace svx { namespace sidebar {
31 :
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))
51 :
52 :
53 :
54 :
55 0 : AreaTransparencyGradientControl::AreaTransparencyGradientControl (
56 : vcl::Window* pParent,
57 : AreaPropertyPanel& rPanel)
58 0 : : PopupControl( pParent,SVX_RES(RID_POPUPPANEL_AREAPAGE_TRGR)),
59 0 : maFtTrgrCenterX(this, SVX_RES(FT_TRGR_CENTER_X)),
60 0 : maMtrTrgrCenterX(this, SVX_RES(MTR_TRGR_CENTER_X)),
61 0 : maFtTrgrCenterY(this, SVX_RES(FT_TRGR_CENTER_Y)),
62 0 : maMtrTrgrCenterY(this, SVX_RES(MTR_TRGR_CENTER_Y)),
63 0 : maFtTrgrAngle(this, SVX_RES(FT_TRGR_ANGLE)),
64 0 : maMtrTrgrAngle(this, SVX_RES(MTR_TRGR_ANGLE)),
65 0 : maBtnLeft45(this, SVX_RES(BTN_LEFT_SECOND)),
66 0 : maBtnRight45(this, SVX_RES(BTN_RIGHT_FIRST)),
67 0 : maFtTrgrStartValue(this, SVX_RES(FT_TRGR_START_VALUE)),
68 0 : maMtrTrgrStartValue(this, SVX_RES(MTR_TRGR_START_VALUE)),
69 0 : maFtTrgrEndValue(this, SVX_RES(FT_TRGR_END_VALUE)),
70 0 : maMtrTrgrEndValue(this, SVX_RES(MTR_TRGR_END_VALUE)),
71 0 : maFtTrgrBorder(this, SVX_RES(FT_TRGR_BORDER)),
72 0 : maMtrTrgrBorder(this, SVX_RES(MTR_TRGR_BORDER)),
73 0 : maRotLeft( SVX_RES(IMG_ROT_LEFT)),
74 0 : maRotRight( SVX_RES(IMG_ROT_RIGHT)),
75 : mrAreaPropertyPanel(rPanel),
76 0 : mpBindings(NULL)
77 : {
78 0 : Link aLink = LINK( this, AreaTransparencyGradientControl, ModifiedTrgrHdl_Impl);
79 0 : maMtrTrgrCenterX.SetModifyHdl( aLink );
80 0 : maMtrTrgrCenterY.SetModifyHdl( aLink );
81 0 : maMtrTrgrAngle.SetModifyHdl( aLink );
82 0 : maMtrTrgrBorder.SetModifyHdl( aLink );
83 0 : maMtrTrgrStartValue.SetModifyHdl( aLink );
84 0 : maMtrTrgrEndValue.SetModifyHdl( aLink );
85 0 : aLink = LINK( this, AreaTransparencyGradientControl, Left_Click45_Impl);
86 0 : maBtnLeft45.SetSelectHdl( aLink );
87 0 : aLink = LINK( this, AreaTransparencyGradientControl, Right_Click45_Impl);
88 0 : maBtnRight45.SetSelectHdl( aLink );
89 0 : maBtnLeft45.SetItemImage(1,maRotLeft);
90 0 : Size aTbxSize = maBtnLeft45.CalcWindowSizePixel();
91 0 : maBtnLeft45.SetOutputSizePixel( aTbxSize );
92 0 : maBtnLeft45.SetQuickHelpText(1, SVX_RESSTR(STR_HELP_LEFT)); //acc wj
93 :
94 0 : maBtnRight45.SetItemImage(1,maRotRight);
95 0 : aTbxSize = maBtnRight45.CalcWindowSizePixel();
96 0 : maBtnRight45.SetOutputSizePixel( aTbxSize );
97 0 : maBtnRight45.SetQuickHelpText(1, SVX_RESSTR(STR_HELP_RIGHT)); //acc wj
98 :
99 0 : maBtnLeft45.SetBackground(Wallpaper());
100 0 : maBtnLeft45.SetPaintTransparent(true);
101 0 : maBtnRight45.SetBackground(Wallpaper());
102 0 : maBtnRight45.SetPaintTransparent(true);
103 :
104 0 : FreeResource();
105 0 : mpBindings = mrAreaPropertyPanel.GetBindings();
106 0 : }
107 :
108 :
109 :
110 :
111 0 : AreaTransparencyGradientControl::~AreaTransparencyGradientControl (void)
112 : {
113 0 : }
114 :
115 0 : void AreaTransparencyGradientControl::Rearrange(XFillFloatTransparenceItem* pGradientItem)
116 : {
117 0 : InitStatus(pGradientItem);
118 0 : const XGradient& rGradient = pGradientItem->GetGradientValue();
119 0 : XGradientStyle eXGS(rGradient.GetGradientStyle());
120 0 : Size aSize(POP_WIDTH,POP_HEIGHT);
121 0 : aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
122 0 : Size aSize2(POP_WIDTH,POP_HEIGHT2);
123 0 : aSize2 = LogicToPixel( aSize2, MapMode(MAP_APPFONT) );
124 0 : long aPosY = 0;
125 0 : Point aPointAngle;
126 0 : Size aSizeAngle = maMtrTrgrAngle.GetSizePixel();
127 0 : Size aTbxSize = maBtnLeft45.CalcWindowSizePixel();
128 :
129 0 : switch(eXGS)
130 : {
131 : case XGRAD_LINEAR:
132 : case XGRAD_AXIAL:
133 0 : maFtTrgrCenterX.Hide();
134 0 : maMtrTrgrCenterX.Hide();
135 0 : maFtTrgrCenterY.Hide();
136 0 : maMtrTrgrCenterY.Hide();
137 0 : maFtTrgrAngle.Show();
138 0 : maFtTrgrAngle.SetPosPixel(APOS1_1);
139 0 : maMtrTrgrAngle.Show();
140 0 : maMtrTrgrAngle.SetPosPixel(APOS2_1);
141 0 : maFtTrgrStartValue.SetPosPixel(APOS1_3);
142 0 : maMtrTrgrStartValue.SetPosPixel(APOS1_4);
143 0 : maFtTrgrEndValue.SetPosPixel(APOS2_3);
144 0 : maMtrTrgrEndValue.SetPosPixel(APOS2_4);
145 0 : maFtTrgrBorder.SetPosPixel(APOS1_5);
146 0 : maMtrTrgrBorder.SetPosPixel(APOS1_6);
147 :
148 0 : maBtnLeft45.Show();
149 0 : maBtnRight45.Show();
150 :
151 0 : aPointAngle = maMtrTrgrAngle.GetPosPixel();
152 0 : aPosY = aPointAngle.getY() + aSizeAngle.getHeight() - aTbxSize.getHeight();
153 :
154 0 : maBtnLeft45.SetPosPixel(Point(APOS_Left_Right_1.getX(), aPosY));
155 0 : maBtnRight45.SetPosPixel(Point(APOS_Left_Right_2.getX(), aPosY));
156 :
157 0 : SetSizePixel(aSize2);
158 0 : break;
159 :
160 : case XGRAD_RADIAL:
161 0 : maFtTrgrCenterX.Show();
162 0 : maFtTrgrCenterX.SetPosPixel(APOS1_1);
163 0 : maMtrTrgrCenterX.Show();
164 0 : maMtrTrgrCenterX.SetPosPixel(APOS2_1);
165 0 : maFtTrgrCenterY.Show();
166 0 : maFtTrgrCenterY.SetPosPixel(APOS1_2);
167 0 : maMtrTrgrCenterY.Show();
168 0 : maMtrTrgrCenterY.SetPosPixel(APOS2_2);
169 0 : maFtTrgrAngle.Hide();
170 0 : maMtrTrgrAngle.Hide();
171 0 : maFtTrgrStartValue.SetPosPixel(APOS1_3);
172 0 : maMtrTrgrStartValue.SetPosPixel(APOS1_4);
173 0 : maFtTrgrEndValue.SetPosPixel(APOS2_3);
174 0 : maMtrTrgrEndValue.SetPosPixel(APOS2_4);
175 0 : maFtTrgrBorder.SetPosPixel(APOS1_5);
176 0 : maMtrTrgrBorder.SetPosPixel(APOS1_6);
177 :
178 0 : maBtnLeft45.Hide();
179 0 : maBtnRight45.Hide();
180 :
181 0 : SetSizePixel(aSize2);
182 :
183 0 : break;
184 :
185 : case XGRAD_ELLIPTICAL:
186 : case XGRAD_SQUARE:
187 : case XGRAD_RECT:
188 0 : maFtTrgrCenterX.Show();
189 0 : maFtTrgrCenterX.SetPosPixel(APOS1_1);
190 0 : maMtrTrgrCenterX.Show();
191 0 : maMtrTrgrCenterX.SetPosPixel(APOS2_1);
192 0 : maFtTrgrCenterY.Show();
193 0 : maFtTrgrCenterY.SetPosPixel(APOS1_2);
194 0 : maMtrTrgrCenterY.Show();
195 0 : maMtrTrgrCenterY.SetPosPixel(APOS2_2);
196 0 : maFtTrgrAngle.Show();
197 0 : maFtTrgrAngle.SetPosPixel(APOS1_3);
198 0 : maMtrTrgrAngle.Show();
199 0 : maMtrTrgrAngle.SetPosPixel(APOS1_4);
200 :
201 0 : maFtTrgrStartValue.SetPosPixel(APOS1_5);
202 0 : maMtrTrgrStartValue.SetPosPixel(APOS1_6);
203 0 : maFtTrgrEndValue.SetPosPixel(APOS2_5);
204 0 : maMtrTrgrEndValue.SetPosPixel(APOS2_6);
205 0 : maFtTrgrBorder.SetPosPixel(APOS1_7);
206 0 : maMtrTrgrBorder.SetPosPixel(APOS1_8);
207 :
208 0 : maBtnLeft45.Show();
209 0 : maBtnRight45.Show();
210 :
211 0 : aPointAngle = maMtrTrgrAngle.GetPosPixel();
212 0 : aPosY = aPointAngle.getY() + aSizeAngle.getHeight() - aTbxSize.getHeight();
213 :
214 0 : maBtnLeft45.SetPosPixel(Point(APOS_Left_Right_3.getX(), aPosY));
215 0 : maBtnRight45.SetPosPixel(Point(APOS_Left_Right_4.getX(), aPosY));
216 :
217 0 : SetSizePixel(aSize);
218 :
219 0 : break;
220 : }
221 0 : }
222 :
223 :
224 :
225 :
226 0 : void AreaTransparencyGradientControl::InitStatus(XFillFloatTransparenceItem* pGradientItem)
227 : {
228 0 : const XGradient& rGradient = pGradientItem->GetGradientValue();
229 :
230 0 : XGradient aGradient;
231 :
232 0 : if (rGradient.GetXOffset() == AreaPropertyPanel::DEFAULT_CENTERX
233 0 : && rGradient.GetYOffset() == AreaPropertyPanel::DEFAULT_CENTERY
234 0 : && (rGradient.GetAngle() / 10) == AreaPropertyPanel::DEFAULT_ANGLE
235 0 : && ((sal_uInt16)((((sal_uInt16)rGradient.GetStartColor().GetRed() + 1) * 100) / 255))
236 0 : == AreaPropertyPanel::DEFAULT_STARTVALUE
237 0 : && ((sal_uInt16)((((sal_uInt16)rGradient.GetEndColor().GetRed() + 1) * 100) / 255))
238 0 : == AreaPropertyPanel::DEFAULT_ENDVALUE
239 0 : && rGradient.GetBorder() == AreaPropertyPanel::DEFAULT_BORDER)
240 : {
241 0 : aGradient = mrAreaPropertyPanel.GetGradient(rGradient.GetGradientStyle());
242 : }
243 : else
244 : {
245 0 : aGradient = rGradient;
246 : }
247 0 : maMtrTrgrCenterX.SetValue(aGradient.GetXOffset());
248 0 : maMtrTrgrCenterY.SetValue(aGradient.GetYOffset());
249 0 : maMtrTrgrAngle.SetValue(aGradient.GetAngle() / 10);
250 0 : maMtrTrgrStartValue.SetValue((sal_uInt16)((((sal_uInt16)aGradient.GetStartColor().GetRed() + 1) * 100) / 255));
251 0 : maMtrTrgrEndValue.SetValue((sal_uInt16)((((sal_uInt16)aGradient.GetEndColor().GetRed() + 1) * 100) / 255));
252 0 : maMtrTrgrBorder.SetValue(aGradient.GetBorder());
253 0 : }
254 :
255 :
256 :
257 :
258 0 : void AreaTransparencyGradientControl::ExecuteValueModify( sal_uInt8 nStartCol, sal_uInt8 nEndCol )
259 : {
260 : //Added
261 0 : sal_Int16 aMtrValue = (sal_Int16)maMtrTrgrAngle.GetValue();
262 0 : while(aMtrValue<0)
263 0 : aMtrValue += 360;
264 0 : sal_uInt16 nVal = aMtrValue/360;
265 0 : nVal = aMtrValue - nVal*360;
266 0 : maMtrTrgrAngle.SetValue(nVal);
267 : //End of new code
268 : XGradient aTmpGradient(
269 : Color(nStartCol, nStartCol, nStartCol),
270 : Color(nEndCol, nEndCol, nEndCol),
271 0 : (XGradientStyle)(mrAreaPropertyPanel.GetSelectedTransparencyTypeIndex()-2),
272 0 : (sal_uInt16)maMtrTrgrAngle.GetValue() * 10,
273 0 : (sal_uInt16)maMtrTrgrCenterX.GetValue(),
274 0 : (sal_uInt16)maMtrTrgrCenterY.GetValue(),
275 0 : (sal_uInt16)maMtrTrgrBorder.GetValue(),
276 0 : 100, 100);
277 :
278 0 : mrAreaPropertyPanel.SetGradient(aTmpGradient);
279 :
280 0 : SfxItemPool* pPool = NULL;
281 0 : bool bEnable = true;
282 0 : XFillFloatTransparenceItem aGradientItem(pPool,aTmpGradient, bEnable );
283 :
284 0 : mpBindings->GetDispatcher()->Execute( SID_ATTR_FILL_FLOATTRANSPARENCE, SfxCallMode::RECORD, &aGradientItem, 0L );
285 0 : }
286 :
287 :
288 :
289 :
290 0 : IMPL_LINK_NOARG(AreaTransparencyGradientControl, ModifiedTrgrHdl_Impl)
291 : {
292 0 : sal_uInt8 nStartCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrStartValue.GetValue() * 255) / 100);
293 0 : sal_uInt8 nEndCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrEndValue.GetValue() * 255) / 100);
294 0 : ExecuteValueModify( nStartCol, nEndCol );
295 0 : return( 0L );
296 : }
297 :
298 :
299 :
300 :
301 0 : IMPL_LINK_NOARG(AreaTransparencyGradientControl, Left_Click45_Impl)
302 : {
303 0 : sal_uInt8 nStartCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrStartValue.GetValue() * 255) / 100);
304 0 : sal_uInt8 nEndCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrEndValue.GetValue() * 255) / 100);
305 0 : sal_uInt16 aTemp = (sal_uInt16)maMtrTrgrAngle.GetValue();
306 0 : if(aTemp>=315)
307 0 : aTemp -= 360;
308 0 : aTemp += 45;
309 0 : maMtrTrgrAngle.SetValue(aTemp);
310 0 : ExecuteValueModify( nStartCol, nEndCol );
311 0 : return( 0L );
312 : }
313 :
314 :
315 :
316 :
317 0 : IMPL_LINK_NOARG(AreaTransparencyGradientControl, Right_Click45_Impl)
318 : {
319 0 : sal_uInt8 nStartCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrStartValue.GetValue() * 255) / 100);
320 0 : sal_uInt8 nEndCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrEndValue.GetValue() * 255) / 100);
321 0 : sal_uInt16 aTemp = (sal_uInt16)maMtrTrgrAngle.GetValue();
322 0 : if(aTemp<45)
323 0 : aTemp += 360;
324 0 : aTemp -= 45;
325 0 : maMtrTrgrAngle.SetValue(aTemp);
326 0 : ExecuteValueModify( nStartCol, nEndCol );
327 0 : return( 0L );
328 : }
329 :
330 594 : } } // end of namespace svx::sidebar
331 :
332 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|