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