Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / sidebar / area / AreaTransparencyGradientControl.cxx
blob9b5a94648b61288cd82972ef1eb3d5425aa6cba8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 (
56 Window* pParent,
57 AreaPropertyPanel& rPanel)
58 : PopupControl( pParent,SVX_RES(RID_POPUPPANEL_AREAPAGE_TRGR)),
59 maFtTrgrCenterX(this, SVX_RES(FT_TRGR_CENTER_X)),
60 maMtrTrgrCenterX(this, SVX_RES(MTR_TRGR_CENTER_X)),
61 maFtTrgrCenterY(this, SVX_RES(FT_TRGR_CENTER_Y)),
62 maMtrTrgrCenterY(this, SVX_RES(MTR_TRGR_CENTER_Y)),
63 maFtTrgrAngle(this, SVX_RES(FT_TRGR_ANGLE)),
64 maMtrTrgrAngle(this, SVX_RES(MTR_TRGR_ANGLE)),
65 maBtnLeft45(this, SVX_RES(BTN_LEFT_SECOND)),
66 maBtnRight45(this, SVX_RES(BTN_RIGHT_FIRST)),
67 maFtTrgrStartValue(this, SVX_RES(FT_TRGR_START_VALUE)),
68 maMtrTrgrStartValue(this, SVX_RES(MTR_TRGR_START_VALUE)),
69 maFtTrgrEndValue(this, SVX_RES(FT_TRGR_END_VALUE)),
70 maMtrTrgrEndValue(this, SVX_RES(MTR_TRGR_END_VALUE)),
71 maFtTrgrBorder(this, SVX_RES(FT_TRGR_BORDER)),
72 maMtrTrgrBorder(this, SVX_RES(MTR_TRGR_BORDER)),
73 maRotLeft( SVX_RES(IMG_ROT_LEFT)),
74 maRotRight( SVX_RES(IMG_ROT_RIGHT)),
75 mrAreaPropertyPanel(rPanel),
76 mpBindings(NULL)
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 aLink = LINK( this, AreaTransparencyGradientControl, Left_Click45_Impl);
86 maBtnLeft45.SetSelectHdl( aLink );
87 aLink = LINK( this, AreaTransparencyGradientControl, Right_Click45_Impl);
88 maBtnRight45.SetSelectHdl( aLink );
89 maBtnLeft45.SetItemImage(1,maRotLeft);
90 Size aTbxSize = maBtnLeft45.CalcWindowSizePixel();
91 maBtnLeft45.SetOutputSizePixel( aTbxSize );
92 maBtnLeft45.SetQuickHelpText(1, SVX_RESSTR(STR_HELP_LEFT)); //acc wj
94 maBtnRight45.SetItemImage(1,maRotRight);
95 aTbxSize = maBtnRight45.CalcWindowSizePixel();
96 maBtnRight45.SetOutputSizePixel( aTbxSize );
97 maBtnRight45.SetQuickHelpText(1, SVX_RESSTR(STR_HELP_RIGHT)); //acc wj
99 maBtnLeft45.SetBackground(Wallpaper());
100 maBtnLeft45.SetPaintTransparent(true);
101 maBtnRight45.SetBackground(Wallpaper());
102 maBtnRight45.SetPaintTransparent(true);
104 FreeResource();
105 mpBindings = mrAreaPropertyPanel.GetBindings();
111 AreaTransparencyGradientControl::~AreaTransparencyGradientControl (void)
115 void AreaTransparencyGradientControl::Rearrange(XFillFloatTransparenceItem* pGradientItem)
117 InitStatus(pGradientItem);
118 const XGradient& rGradient = pGradientItem->GetGradientValue();
119 XGradientStyle eXGS(rGradient.GetGradientStyle());
120 Size aSize(POP_WIDTH,POP_HEIGHT);
121 aSize = LogicToPixel( aSize, MapMode(MAP_APPFONT) );
122 Size aSize2(POP_WIDTH,POP_HEIGHT2);
123 aSize2 = LogicToPixel( aSize2, MapMode(MAP_APPFONT) );
124 long aPosY = 0;
125 Point aPointAngle;
126 Size aSizeAngle = maMtrTrgrAngle.GetSizePixel();
127 Size aTbxSize = maBtnLeft45.CalcWindowSizePixel();
129 switch(eXGS)
131 case XGRAD_LINEAR:
132 case XGRAD_AXIAL:
133 maFtTrgrCenterX.Hide();
134 maMtrTrgrCenterX.Hide();
135 maFtTrgrCenterY.Hide();
136 maMtrTrgrCenterY.Hide();
137 maFtTrgrAngle.Show();
138 maFtTrgrAngle.SetPosPixel(APOS1_1);
139 maMtrTrgrAngle.Show();
140 maMtrTrgrAngle.SetPosPixel(APOS2_1);
141 maFtTrgrStartValue.SetPosPixel(APOS1_3);
142 maMtrTrgrStartValue.SetPosPixel(APOS1_4);
143 maFtTrgrEndValue.SetPosPixel(APOS2_3);
144 maMtrTrgrEndValue.SetPosPixel(APOS2_4);
145 maFtTrgrBorder.SetPosPixel(APOS1_5);
146 maMtrTrgrBorder.SetPosPixel(APOS1_6);
148 maBtnLeft45.Show();
149 maBtnRight45.Show();
151 aPointAngle = maMtrTrgrAngle.GetPosPixel();
152 aPosY = aPointAngle.getY() + aSizeAngle.getHeight() - aTbxSize.getHeight();
154 maBtnLeft45.SetPosPixel(Point(APOS_Left_Right_1.getX(), aPosY));
155 maBtnRight45.SetPosPixel(Point(APOS_Left_Right_2.getX(), aPosY));
157 SetSizePixel(aSize2);
158 break;
160 case XGRAD_RADIAL:
161 maFtTrgrCenterX.Show();
162 maFtTrgrCenterX.SetPosPixel(APOS1_1);
163 maMtrTrgrCenterX.Show();
164 maMtrTrgrCenterX.SetPosPixel(APOS2_1);
165 maFtTrgrCenterY.Show();
166 maFtTrgrCenterY.SetPosPixel(APOS1_2);
167 maMtrTrgrCenterY.Show();
168 maMtrTrgrCenterY.SetPosPixel(APOS2_2);
169 maFtTrgrAngle.Hide();
170 maMtrTrgrAngle.Hide();
171 maFtTrgrStartValue.SetPosPixel(APOS1_3);
172 maMtrTrgrStartValue.SetPosPixel(APOS1_4);
173 maFtTrgrEndValue.SetPosPixel(APOS2_3);
174 maMtrTrgrEndValue.SetPosPixel(APOS2_4);
175 maFtTrgrBorder.SetPosPixel(APOS1_5);
176 maMtrTrgrBorder.SetPosPixel(APOS1_6);
178 maBtnLeft45.Hide();
179 maBtnRight45.Hide();
181 SetSizePixel(aSize2);
183 break;
185 case XGRAD_ELLIPTICAL:
186 case XGRAD_SQUARE:
187 case XGRAD_RECT:
188 maFtTrgrCenterX.Show();
189 maFtTrgrCenterX.SetPosPixel(APOS1_1);
190 maMtrTrgrCenterX.Show();
191 maMtrTrgrCenterX.SetPosPixel(APOS2_1);
192 maFtTrgrCenterY.Show();
193 maFtTrgrCenterY.SetPosPixel(APOS1_2);
194 maMtrTrgrCenterY.Show();
195 maMtrTrgrCenterY.SetPosPixel(APOS2_2);
196 maFtTrgrAngle.Show();
197 maFtTrgrAngle.SetPosPixel(APOS1_3);
198 maMtrTrgrAngle.Show();
199 maMtrTrgrAngle.SetPosPixel(APOS1_4);
201 maFtTrgrStartValue.SetPosPixel(APOS1_5);
202 maMtrTrgrStartValue.SetPosPixel(APOS1_6);
203 maFtTrgrEndValue.SetPosPixel(APOS2_5);
204 maMtrTrgrEndValue.SetPosPixel(APOS2_6);
205 maFtTrgrBorder.SetPosPixel(APOS1_7);
206 maMtrTrgrBorder.SetPosPixel(APOS1_8);
208 maBtnLeft45.Show();
209 maBtnRight45.Show();
211 aPointAngle = maMtrTrgrAngle.GetPosPixel();
212 aPosY = aPointAngle.getY() + aSizeAngle.getHeight() - aTbxSize.getHeight();
214 maBtnLeft45.SetPosPixel(Point(APOS_Left_Right_3.getX(), aPosY));
215 maBtnRight45.SetPosPixel(Point(APOS_Left_Right_4.getX(), aPosY));
217 SetSizePixel(aSize);
219 break;
226 void AreaTransparencyGradientControl::InitStatus(XFillFloatTransparenceItem* pGradientItem)
228 const XGradient& rGradient = pGradientItem->GetGradientValue();
230 XGradient aGradient;
232 if (rGradient.GetXOffset() == AreaPropertyPanel::DEFAULT_CENTERX
233 && rGradient.GetYOffset() == AreaPropertyPanel::DEFAULT_CENTERY
234 && (rGradient.GetAngle() / 10) == AreaPropertyPanel::DEFAULT_ANGLE
235 && ((sal_uInt16)((((sal_uInt16)rGradient.GetStartColor().GetRed() + 1) * 100) / 255))
236 == AreaPropertyPanel::DEFAULT_STARTVALUE
237 && ((sal_uInt16)((((sal_uInt16)rGradient.GetEndColor().GetRed() + 1) * 100) / 255))
238 == AreaPropertyPanel::DEFAULT_ENDVALUE
239 && rGradient.GetBorder() == AreaPropertyPanel::DEFAULT_BORDER)
241 aGradient = mrAreaPropertyPanel.GetGradient(rGradient.GetGradientStyle());
243 else
245 aGradient = rGradient;
247 maMtrTrgrCenterX.SetValue(aGradient.GetXOffset());
248 maMtrTrgrCenterY.SetValue(aGradient.GetYOffset());
249 maMtrTrgrAngle.SetValue(aGradient.GetAngle() / 10);
250 maMtrTrgrStartValue.SetValue((sal_uInt16)((((sal_uInt16)aGradient.GetStartColor().GetRed() + 1) * 100) / 255));
251 maMtrTrgrEndValue.SetValue((sal_uInt16)((((sal_uInt16)aGradient.GetEndColor().GetRed() + 1) * 100) / 255));
252 maMtrTrgrBorder.SetValue(aGradient.GetBorder());
258 void AreaTransparencyGradientControl::ExecuteValueModify( sal_uInt8 nStartCol, sal_uInt8 nEndCol )
260 //Added
261 sal_Int16 aMtrValue = (sal_Int16)maMtrTrgrAngle.GetValue();
262 while(aMtrValue<0)
263 aMtrValue += 360;
264 sal_uInt16 nVal = aMtrValue/360;
265 nVal = aMtrValue - nVal*360;
266 maMtrTrgrAngle.SetValue(nVal);
267 //End of new code
268 XGradient aTmpGradient(
269 Color(nStartCol, nStartCol, nStartCol),
270 Color(nEndCol, nEndCol, nEndCol),
271 (XGradientStyle)(mrAreaPropertyPanel.GetSelectedTransparencyTypeIndex()-2),
272 (sal_uInt16)maMtrTrgrAngle.GetValue() * 10,
273 (sal_uInt16)maMtrTrgrCenterX.GetValue(),
274 (sal_uInt16)maMtrTrgrCenterY.GetValue(),
275 (sal_uInt16)maMtrTrgrBorder.GetValue(),
276 100, 100);
278 mrAreaPropertyPanel.SetGradient(aTmpGradient);
280 SfxItemPool* pPool = NULL;
281 bool bEnable = true;
282 XFillFloatTransparenceItem aGradientItem(pPool,aTmpGradient, bEnable );
284 mpBindings->GetDispatcher()->Execute( SID_ATTR_FILL_FLOATTRANSPARENCE, SFX_CALLMODE_RECORD, &aGradientItem, 0L );
290 IMPL_LINK_NOARG(AreaTransparencyGradientControl, ModifiedTrgrHdl_Impl)
292 sal_uInt8 nStartCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrStartValue.GetValue() * 255) / 100);
293 sal_uInt8 nEndCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrEndValue.GetValue() * 255) / 100);
294 ExecuteValueModify( nStartCol, nEndCol );
295 return( 0L );
301 IMPL_LINK_NOARG(AreaTransparencyGradientControl, Left_Click45_Impl)
303 sal_uInt8 nStartCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrStartValue.GetValue() * 255) / 100);
304 sal_uInt8 nEndCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrEndValue.GetValue() * 255) / 100);
305 sal_uInt16 aTemp = (sal_uInt16)maMtrTrgrAngle.GetValue();
306 if(aTemp>=315)
307 aTemp -= 360;
308 aTemp += 45;
309 maMtrTrgrAngle.SetValue(aTemp);
310 ExecuteValueModify( nStartCol, nEndCol );
311 return( 0L );
317 IMPL_LINK_NOARG(AreaTransparencyGradientControl, Right_Click45_Impl)
319 sal_uInt8 nStartCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrStartValue.GetValue() * 255) / 100);
320 sal_uInt8 nEndCol = (sal_uInt8)(((sal_uInt16)maMtrTrgrEndValue.GetValue() * 255) / 100);
321 sal_uInt16 aTemp = (sal_uInt16)maMtrTrgrAngle.GetValue();
322 if(aTemp<45)
323 aTemp += 360;
324 aTemp -= 45;
325 maMtrTrgrAngle.SetValue(aTemp);
326 ExecuteValueModify( nStartCol, nEndCol );
327 return( 0L );
330 } } // end of namespace svx::sidebar
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */