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 "precompiled_sc.hxx" 23 24 #include <CellBorderStyleControl.hxx> 25 #include "sc.hrc" 26 #include "scresid.hxx" 27 #include <CellAppearancePropertyPanel.hrc> 28 #include <editeng/boxitem.hxx> 29 #include <editeng/bolnitem.hxx> 30 #include <CellAppearancePropertyPanel.hxx> 31 #include <sfx2/bindings.hxx> 32 #include <sfx2/dispatch.hxx> 33 #include <vcl/svapp.hxx> 34 35 namespace sc { namespace sidebar { 36 37 #define FRM_VALID_LEFT 0x01 38 #define FRM_VALID_RIGHT 0x02 39 #define FRM_VALID_TOP 0x04 40 #define FRM_VALID_BOTTOM 0x08 41 #define FRM_VALID_HINNER 0x10 42 #define FRM_VALID_VINNER 0x20 43 #define FRM_VALID_OUTER 0x0f 44 #define FRM_VALID_ALL 0xff 45 46 CellBorderStyleControl::CellBorderStyleControl(Window* pParent, CellAppearancePropertyPanel& rPanel) 47 : svx::sidebar::PopupControl(pParent, ScResId(RID_POPUPPANEL_APPEARANCE_CELL_BORDERSTYLE)), 48 mrCellAppearancePropertyPanel(rPanel), 49 maTBBorder1(this, ScResId(TB_BORDER1)), 50 maTBBorder2(this, ScResId(TB_BORDER2)), 51 maTBBorder3(this, ScResId(TB_BORDER3)), 52 maFL1(this, ScResId(FL_1)), 53 maFL2(this, ScResId(FL_2)), 54 mpImageList(0), 55 mpImageListH(0) 56 { 57 Initialize(); 58 FreeResource(); 59 } 60 61 CellBorderStyleControl::~CellBorderStyleControl(void) 62 { 63 delete[] mpImageList; 64 delete[] mpImageListH; 65 } 66 67 void CellBorderStyleControl::Initialize() 68 { 69 mpImageList = new Image[16]; 70 mpImageList[0] = Image(ScResId(IMG_BORDER1)); 71 mpImageList[1] = Image(ScResId(IMG_BORDER2)); 72 mpImageList[2] = Image(ScResId(IMG_BORDER3)); 73 mpImageList[3] = Image(ScResId(IMG_BORDER4)); 74 mpImageList[4] = Image(ScResId(IMG_BORDER5)); 75 mpImageList[5] = Image(ScResId(IMG_BORDER6)); 76 mpImageList[6] = Image(ScResId(IMG_BORDER7)); 77 mpImageList[7] = Image(ScResId(IMG_BORDER8)); 78 mpImageList[8] = Image(ScResId(IMG_BORDER9)); 79 mpImageList[9] = Image(ScResId(IMG_BORDER10)); 80 mpImageList[10] = Image(ScResId(IMG_BORDER11)); 81 mpImageList[11] = Image(ScResId(IMG_BORDER12)); 82 mpImageList[12] = Image(ScResId(IMG_BORDER13)); 83 mpImageList[13] = Image(ScResId(IMG_BORDER14)); 84 mpImageList[14] = Image(ScResId(IMG_BORDER15)); 85 mpImageList[15] = Image(ScResId(IMG_BORDER16)); 86 87 //high contrast 88 mpImageListH = new Image[16]; 89 mpImageListH[0] = Image(ScResId(IMG_BORDER1_H)); 90 mpImageListH[1] = Image(ScResId(IMG_BORDER2_H)); 91 mpImageListH[2] = Image(ScResId(IMG_BORDER3_H)); 92 mpImageListH[3] = Image(ScResId(IMG_BORDER4_H)); 93 mpImageListH[4] = Image(ScResId(IMG_BORDER5_H)); 94 mpImageListH[5] = Image(ScResId(IMG_BORDER6_H)); 95 mpImageListH[6] = Image(ScResId(IMG_BORDER7_H)); 96 mpImageListH[7] = Image(ScResId(IMG_BORDER8_H)); 97 mpImageListH[8] = Image(ScResId(IMG_BORDER9_H)); 98 mpImageListH[9] = Image(ScResId(IMG_BORDER10_H)); 99 mpImageListH[10] = Image(ScResId(IMG_BORDER11_H)); 100 mpImageListH[11] = Image(ScResId(IMG_BORDER12_H)); 101 mpImageListH[12] = Image(ScResId(IMG_BORDER13_H)); 102 mpImageListH[13] = Image(ScResId(IMG_BORDER14_H)); 103 mpImageListH[14] = Image(ScResId(IMG_BORDER15_H)); 104 mpImageListH[15] = Image(ScResId(IMG_BORDER16_H)); 105 106 maTBBorder1.SetItemImage(TBI_BORDER1_NONE, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[0] : mpImageList[0]); 107 maTBBorder1.SetItemImage(TBI_BORDER1_ALL, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[1] : mpImageList[1]); 108 maTBBorder1.SetItemImage(TBI_BORDER1_OUTER, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[2] : mpImageList[2]); 109 maTBBorder1.SetItemImage(TBI_BORDER1_OUTERBOLD, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[3] : mpImageList[3]); 110 maTBBorder1.SetBackground(Wallpaper()); 111 maTBBorder1.SetPaintTransparent(true); 112 Size aTbxSize( maTBBorder1.CalcWindowSizePixel() ); 113 maTBBorder1.SetOutputSizePixel( aTbxSize ); 114 Link aLink = LINK(this, CellBorderStyleControl, TB1SelectHdl); 115 maTBBorder1.SetSelectHdl ( aLink ); 116 117 maTBBorder2.SetLineCount(2); 118 maTBBorder2.InsertItem(TBI_BORDER2_LEFT, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[4] : mpImageList[4]); 119 maTBBorder2.InsertItem(TBI_BORDER2_RIGHT, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[5] : mpImageList[5]); 120 maTBBorder2.InsertItem(TBI_BORDER2_TOP, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[6] : mpImageList[6]); 121 maTBBorder2.InsertItem(TBI_BORDER2_BOT, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[7] : mpImageList[7]); 122 maTBBorder2.InsertBreak(); 123 maTBBorder2.InsertItem(TBI_BORDER2_BLTR, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[8] : mpImageList[8]); 124 maTBBorder2.InsertItem(TBI_BORDER2_TLBR, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[9] : mpImageList[9]); 125 maTBBorder2.InsertItem(TBI_BORDER2_TOPBOT, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[10] : mpImageList[10]); 126 maTBBorder2.InsertItem(TBI_BORDER2_LEFTRIGHT, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[11] : mpImageList[11]); 127 maTBBorder2.SetBackground(Wallpaper()); 128 maTBBorder2.SetPaintTransparent(true); 129 aTbxSize = maTBBorder2.CalcWindowSizePixel() ; 130 maTBBorder2.SetOutputSizePixel( aTbxSize ); 131 maTBBorder2.SetHelpId(TBI_BORDER2_LEFT, HID_PROPERTYPANEL_SC_BORDER_TBI_LEFT); 132 maTBBorder2.SetHelpId(TBI_BORDER2_RIGHT, HID_PROPERTYPANEL_SC_BORDER_TBI_RIGHT); 133 maTBBorder2.SetHelpId(TBI_BORDER2_TOP, HID_PROPERTYPANEL_SC_BORDER_TBI_TOP); 134 maTBBorder2.SetHelpId(TBI_BORDER2_BOT, HID_PROPERTYPANEL_SC_BORDER_TBI_BOT); 135 maTBBorder2.SetHelpId(TBI_BORDER2_BLTR, HID_PROPERTYPANEL_SC_BORDER_TBI_BLTR); 136 maTBBorder2.SetHelpId(TBI_BORDER2_TLBR, HID_PROPERTYPANEL_SC_BORDER_TBI_TLBR); 137 maTBBorder2.SetHelpId(TBI_BORDER2_TOPBOT, HID_PROPERTYPANEL_SC_BORDER_TBI_TOPBOT); 138 maTBBorder2.SetHelpId(TBI_BORDER2_LEFTRIGHT, HID_PROPERTYPANEL_SC_BORDER_TBI_LEFTRIGHT); 139 maTBBorder2.SetItemText(TBI_BORDER2_LEFT, ScResId(STR_BORDER_1)); 140 maTBBorder2.SetItemText(TBI_BORDER2_RIGHT, ScResId(STR_BORDER_2)); 141 maTBBorder2.SetItemText(TBI_BORDER2_TOP, ScResId(STR_BORDER_3)); 142 maTBBorder2.SetItemText(TBI_BORDER2_BOT, ScResId(STR_BORDER_4)); 143 maTBBorder2.SetItemText(TBI_BORDER2_BLTR, ScResId(STR_BORDER_5)); 144 maTBBorder2.SetItemText(TBI_BORDER2_TLBR, ScResId(STR_BORDER_6)); 145 maTBBorder2.SetItemText(TBI_BORDER2_TOPBOT, ScResId(STR_BORDER_7)); 146 maTBBorder2.SetItemText(TBI_BORDER2_LEFTRIGHT, ScResId(STR_BORDER_8)); 147 aLink = LINK(this, CellBorderStyleControl, TB2SelectHdl); 148 maTBBorder2.SetSelectHdl ( aLink ); 149 150 maTBBorder3.SetItemImage(TBI_BORDER3_S1, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[12] : mpImageList[12]); 151 maTBBorder3.SetItemImage(TBI_BORDER3_S2, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[13] : mpImageList[13]); 152 maTBBorder3.SetItemImage(TBI_BORDER3_S3, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[14] : mpImageList[14]); 153 maTBBorder3.SetItemImage(TBI_BORDER3_S4, GetDisplayBackground().GetColor().IsDark() ? mpImageListH[15] : mpImageList[15]); 154 maTBBorder3.SetBackground(Wallpaper()); 155 maTBBorder3.SetPaintTransparent(true); 156 aTbxSize = maTBBorder3.CalcWindowSizePixel() ; 157 maTBBorder3.SetOutputSizePixel( aTbxSize ); 158 aLink = LINK(this, CellBorderStyleControl, TB3SelectHdl); 159 maTBBorder3.SetSelectHdl ( aLink ); 160 } 161 162 IMPL_LINK(CellBorderStyleControl, TB1SelectHdl, ToolBox*, pToolBox) 163 { 164 sal_uInt16 nId = pToolBox->GetCurItemId(); 165 ::Color aColBlack( COL_BLACK ); 166 SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER ); 167 SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER ); 168 SvxBorderLine theDefLine(NULL,1, 0, 0); 169 SvxBorderLine *pLeft = 0, *pRight = 0, *pTop = 0, *pBottom = 0; 170 sal_uInt8 nValidFlags = 0; 171 switch ( nId ) 172 { 173 case TBI_BORDER1_NONE: 174 { 175 nValidFlags |= FRM_VALID_ALL; 176 SvxLineItem aLineItem1( SID_ATTR_BORDER_DIAG_BLTR ); 177 SvxLineItem aLineItem2( SID_ATTR_BORDER_DIAG_TLBR ); 178 aLineItem1.SetLine( NULL ); //modify 179 aLineItem2.SetLine( NULL ); //modify 180 mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_BLTR, SFX_CALLMODE_RECORD, &aLineItem1, 0L); 181 mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_TLBR, SFX_CALLMODE_RECORD, &aLineItem2, 0L); 182 } 183 break; 184 case TBI_BORDER1_ALL: 185 pLeft = pRight = pTop = pBottom = &theDefLine; 186 aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_HORI ); 187 aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_VERT ); 188 nValidFlags |= FRM_VALID_ALL; 189 break; 190 case TBI_BORDER1_OUTER: 191 pLeft = pRight = pTop = pBottom = &theDefLine; 192 nValidFlags |= FRM_VALID_OUTER; 193 break; 194 case TBI_BORDER1_OUTERBOLD: 195 theDefLine.SetOutWidth(DEF_LINE_WIDTH_2); 196 pLeft = pRight = pTop = pBottom = &theDefLine; 197 nValidFlags |= FRM_VALID_OUTER; 198 break; 199 } 200 201 aBorderOuter.SetLine( pLeft, BOX_LINE_LEFT ); 202 aBorderOuter.SetLine( pRight, BOX_LINE_RIGHT ); 203 aBorderOuter.SetLine( pTop, BOX_LINE_TOP ); 204 aBorderOuter.SetLine( pBottom, BOX_LINE_BOTTOM ); 205 206 aBorderInner.SetValid( VALID_TOP, 0 != (nValidFlags&FRM_VALID_TOP )); 207 aBorderInner.SetValid( VALID_BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM )); 208 aBorderInner.SetValid( VALID_LEFT, 0 != (nValidFlags&FRM_VALID_LEFT)); 209 aBorderInner.SetValid( VALID_RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT )); 210 aBorderInner.SetValid( VALID_HORI, 0 != (nValidFlags&FRM_VALID_HINNER )); 211 aBorderInner.SetValid( VALID_VERT, 0 != (nValidFlags&FRM_VALID_VINNER)); 212 aBorderInner.SetValid( VALID_DISTANCE, true ); 213 aBorderInner.SetValid( VALID_DISABLE, false ); 214 215 mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER, SFX_CALLMODE_RECORD, &aBorderOuter, &aBorderInner, 0L); 216 mrCellAppearancePropertyPanel.EndCellBorderStylePopupMode(); 217 return 0; 218 } 219 220 IMPL_LINK(CellBorderStyleControl, TB2SelectHdl, ToolBox *, pToolBox) 221 { 222 sal_uInt16 nId = pToolBox->GetCurItemId(); 223 224 if( nId != TBI_BORDER2_BLTR && nId != TBI_BORDER2_TLBR ) 225 { 226 ::Color aColBlack( COL_BLACK ); 227 SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER ); 228 SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER ); 229 SvxBorderLine theDefLine(NULL, 1, 0, 0); 230 SvxBorderLine *pLeft = 0, 231 *pRight = 0, 232 *pTop = 0, 233 *pBottom = 0; 234 sal_uInt8 nValidFlags = 0; 235 switch ( nId ) 236 { 237 case TBI_BORDER2_LEFT: 238 pLeft = &theDefLine; 239 nValidFlags |= FRM_VALID_LEFT; 240 break; 241 case TBI_BORDER2_RIGHT: 242 // 243 if(!Application::GetSettings().GetLayoutRTL()) 244 { 245 pRight = &theDefLine; 246 nValidFlags |= FRM_VALID_RIGHT; 247 } 248 else 249 { 250 pLeft = &theDefLine; 251 nValidFlags |= FRM_VALID_LEFT; 252 } 253 break; 254 case TBI_BORDER2_TOP: 255 pTop = &theDefLine; 256 nValidFlags |= FRM_VALID_TOP; 257 break; 258 case TBI_BORDER2_BOT: 259 pBottom = &theDefLine; 260 nValidFlags |= FRM_VALID_BOTTOM; 261 break; 262 case TBI_BORDER2_TOPBOT: 263 pTop = pBottom = &theDefLine; 264 nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP; 265 break; 266 case TBI_BORDER2_LEFTRIGHT: 267 pLeft = pRight = &theDefLine; 268 nValidFlags |= FRM_VALID_RIGHT|FRM_VALID_LEFT; 269 break; 270 } 271 aBorderOuter.SetLine( pLeft, BOX_LINE_LEFT ); 272 aBorderOuter.SetLine( pRight, BOX_LINE_RIGHT ); 273 aBorderOuter.SetLine( pTop, BOX_LINE_TOP ); 274 aBorderOuter.SetLine( pBottom, BOX_LINE_BOTTOM ); 275 276 aBorderInner.SetValid( VALID_TOP, 0 != (nValidFlags&FRM_VALID_TOP )); 277 aBorderInner.SetValid( VALID_BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM )); 278 aBorderInner.SetValid( VALID_LEFT, 0 != (nValidFlags&FRM_VALID_LEFT)); 279 aBorderInner.SetValid( VALID_RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT )); 280 aBorderInner.SetValid( VALID_HORI, 0 != (nValidFlags&FRM_VALID_HINNER )); 281 aBorderInner.SetValid( VALID_VERT, 0 != (nValidFlags&FRM_VALID_VINNER)); 282 aBorderInner.SetValid( VALID_DISTANCE, true ); 283 aBorderInner.SetValid( VALID_DISABLE, false ); 284 285 mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER, SFX_CALLMODE_RECORD, &aBorderOuter, &aBorderInner, 0L); 286 } 287 else if(nId == TBI_BORDER2_BLTR) 288 { 289 SvxBorderLine aTmp( NULL, 1, 0, 0 ); 290 SvxLineItem aLineItem( SID_ATTR_BORDER_DIAG_BLTR ); 291 aLineItem.SetLine( &aTmp ); 292 mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_BLTR, SFX_CALLMODE_RECORD, &aLineItem, 0L); 293 } 294 else if(nId == TBI_BORDER2_TLBR) 295 { 296 SvxBorderLine aTmp( NULL, 1, 0, 0 ); 297 SvxLineItem aLineItem( SID_ATTR_BORDER_DIAG_TLBR ); 298 aLineItem.SetLine( &aTmp ); 299 mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_TLBR, SFX_CALLMODE_RECORD, &aLineItem, 0L); 300 } 301 302 mrCellAppearancePropertyPanel.EndCellBorderStylePopupMode(); 303 return 0; 304 } 305 306 IMPL_LINK(CellBorderStyleControl, TB3SelectHdl, ToolBox *, pToolBox) 307 { 308 sal_uInt16 nId = pToolBox->GetCurItemId(); 309 310 ::Color aColBlack( COL_BLACK ); 311 SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER ); 312 SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER ); 313 SvxBorderLine *pTop = 0 , 314 *pBottom = 0 ; 315 sal_uInt8 nValidFlags = 0; 316 317 switch ( nId ) 318 { 319 case TBI_BORDER3_S1: 320 pBottom = new SvxBorderLine(NULL, DEF_LINE_WIDTH_2, 0, 0); 321 nValidFlags |= FRM_VALID_BOTTOM; 322 break; 323 case TBI_BORDER3_S2: 324 pBottom = new SvxBorderLine(NULL, DEF_DOUBLE_LINE0_OUT, DEF_DOUBLE_LINE0_IN, DEF_DOUBLE_LINE0_DIST); 325 nValidFlags |= FRM_VALID_BOTTOM; 326 break; 327 case TBI_BORDER3_S3: 328 pBottom = new SvxBorderLine(NULL, DEF_LINE_WIDTH_2, 0, 0); 329 pTop = new SvxBorderLine(NULL, 1, 0, 0); 330 nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP; 331 break; 332 case TBI_BORDER3_S4: 333 pBottom = new SvxBorderLine(NULL, DEF_DOUBLE_LINE0_OUT, DEF_DOUBLE_LINE0_IN, DEF_DOUBLE_LINE0_DIST); 334 pTop = new SvxBorderLine(NULL, 1, 0, 0); 335 nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP; 336 break; 337 } 338 339 aBorderOuter.SetLine( pTop, BOX_LINE_TOP ); 340 aBorderOuter.SetLine( pBottom, BOX_LINE_BOTTOM ); 341 aBorderOuter.SetLine( NULL, BOX_LINE_LEFT ); 342 aBorderOuter.SetLine( NULL, BOX_LINE_RIGHT ); 343 344 aBorderInner.SetValid( VALID_TOP, 0 != (nValidFlags&FRM_VALID_TOP )); 345 aBorderInner.SetValid( VALID_BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM )); 346 aBorderInner.SetValid( VALID_LEFT, 0 != (nValidFlags&FRM_VALID_LEFT )); 347 aBorderInner.SetValid( VALID_RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT )); 348 aBorderInner.SetValid( VALID_HORI, 0 != (nValidFlags&FRM_VALID_HINNER )); 349 aBorderInner.SetValid( VALID_VERT, 0 != (nValidFlags&FRM_VALID_VINNER)); 350 aBorderInner.SetValid( VALID_DISTANCE, true ); 351 aBorderInner.SetValid( VALID_DISABLE, false ); 352 353 mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER, SFX_CALLMODE_RECORD, &aBorderOuter, &aBorderInner, 0L); 354 355 delete pTop; 356 delete pBottom; 357 358 mrCellAppearancePropertyPanel.EndCellBorderStylePopupMode(); 359 return 0; 360 } 361 362 } } // end of namespace svx::sidebar 363 364 // eof 365