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 23 24 #include "precompiled_sc.hxx" 25 26 #include <CellLineStyleValueSet.hxx> 27 #include <i18npool/mslangid.hxx> 28 29 namespace sc { namespace sidebar { 30 31 CellLineStyleValueSet::CellLineStyleValueSet( Window* pParent, const ResId& rResId) 32 : ValueSet( pParent, rResId ), 33 pVDev(NULL), 34 nSelItem(0), 35 bCusEnable(false) 36 { 37 strUnit = new XubString[9]; 38 SetColCount( 1 ); 39 SetLineCount( 9); 40 } 41 42 CellLineStyleValueSet::~CellLineStyleValueSet() 43 { 44 delete pVDev; 45 delete[] strUnit; 46 } 47 48 void CellLineStyleValueSet::SetUnit(XubString* str) 49 { 50 for(int i = 0; i < 9; i++) 51 { 52 strUnit[i] = str[i]; 53 } 54 } 55 56 void CellLineStyleValueSet::SetSelItem(sal_uInt16 nSel) 57 { 58 nSelItem = nSel; 59 if(nSel == 0) 60 { 61 SelectItem(1); 62 SetNoSelection(); 63 } 64 else 65 { 66 SelectItem(nSelItem); 67 GrabFocus(); 68 } 69 } 70 71 sal_uInt16 CellLineStyleValueSet::GetSelItem() 72 { 73 return nSelItem; 74 } 75 76 void CellLineStyleValueSet::SetImage(Image img) 77 { 78 imgCus = img; 79 } 80 81 void CellLineStyleValueSet::SetCusEnable(bool bEnable) 82 { 83 bCusEnable = bEnable; 84 } 85 86 void CellLineStyleValueSet::UserDraw( const UserDrawEvent& rUDEvt ) 87 { 88 Rectangle aRect = rUDEvt.GetRect(); 89 OutputDevice* pDev = rUDEvt.GetDevice(); 90 sal_uInt16 nItemId = rUDEvt.GetItemId(); 91 92 long nRectHeight = aRect.GetHeight(); 93 long nRectWidth = aRect.GetWidth(); 94 Point aBLPos = aRect.TopLeft(); 95 96 Font aOldFont = pDev->GetFont(); 97 Color aOldColor = pDev->GetLineColor(); 98 Color aOldFillColor = pDev->GetFillColor(); 99 100 Font aFont(OutputDevice::GetDefaultFont(DEFAULTFONT_UI_SANS, MsLangId::getSystemLanguage(), DEFAULTFONT_FLAGS_ONLYONE)); 101 Size aSize = aFont.GetSize(); 102 aSize.Height() = nRectHeight * 3 / 5; 103 aFont.SetSize( aSize ); 104 105 Point aLineStart(aBLPos.X() + 5, aBLPos.Y() + ( nRectHeight - nItemId ) / 2); 106 Point aLineEnd(aBLPos.X() + nRectWidth * 7 / 9 - 15, aBLPos.Y() + ( nRectHeight - nItemId ) / 2); 107 long nTLX = aBLPos.X() + 5, nTLY = aBLPos.Y() + ( nRectHeight - nItemId )/2; 108 long nTRX = aBLPos.X() + nRectWidth * 7 / 9 - 15, nTRY = aBLPos.Y() + ( nRectHeight - nItemId ) / 2; 109 110 if( nSelItem == nItemId ) 111 { 112 Color aBackColor(50,107,197); 113 Rectangle aBackRect = aRect; 114 aBackRect.Top() += 3; 115 aBackRect.Bottom() -= 2; 116 pDev->SetFillColor(aBackColor); 117 pDev->DrawRect(aBackRect); 118 } 119 else 120 { 121 pDev->SetFillColor( COL_TRANSPARENT ); 122 pDev->DrawRect(aRect); 123 } 124 125 // draw text 126 if(nSelItem == nItemId ) 127 aFont.SetColor(COL_WHITE); 128 else 129 aFont.SetColor(GetSettings().GetStyleSettings().GetFieldTextColor()); // high contrast 130 131 pDev->SetFont(aFont); 132 Point aStart(aBLPos.X() + nRectWidth * 7 / 9 - 5 , aBLPos.Y() + nRectHeight / 6); 133 pDev->DrawText(aStart, strUnit[ nItemId - 1 ]); // can't set TEXT_DRAW_ENDELLIPSIS here, or the text will disappear 134 135 // draw line 136 if( nSelItem == nItemId ) 137 { 138 pDev->SetFillColor(COL_WHITE); 139 pDev->SetLineColor(COL_WHITE); 140 } 141 else 142 { 143 pDev->SetFillColor(GetSettings().GetStyleSettings().GetFieldTextColor()); // high contrast 144 pDev->SetLineColor(GetSettings().GetStyleSettings().GetFieldTextColor()); // high contrast 145 } 146 147 switch( nItemId ) 148 { 149 case 1: 150 case 2: 151 case 3: 152 case 4: 153 pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + nItemId * 2 - 1 )); 154 break; 155 case 5: 156 pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 1 )); 157 pDev->DrawRect(Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 4 )); 158 break; 159 case 6: 160 pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 1 )); 161 pDev->DrawRect(Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 )); 162 break; 163 case 7: 164 pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 1 )); 165 pDev->DrawRect(Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 6 )); 166 break; 167 case 8: 168 pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 3 )); 169 pDev->DrawRect(Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 )); 170 break; 171 case 9: 172 pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 3 )); 173 pDev->DrawRect(Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 8 )); 174 break; 175 } 176 177 Invalidate( aRect ); 178 pDev->SetLineColor(aOldColor); 179 pDev->SetFillColor(aOldFillColor); 180 pDev->SetFont(aOldFont); 181 182 } 183 184 } } // end of namespace svx::sidebar 185 186 /* vim: set noet sw=4 ts=4: */ 187