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 "svx/sidebar/ValueSetWithTextControl.hxx" 23 24 #include <sfx2/sidebar/Theme.hxx> 25 26 #include <i18npool/mslangid.hxx> 27 28 namespace svx { namespace sidebar { 29 30 ValueSetWithTextControl::ValueSetWithTextControl( 31 const tControlType eControlType, 32 Window* pParent, 33 const ResId& rResId) 34 : ValueSet( pParent, rResId ) 35 , meControlType( eControlType ) 36 , maItems() 37 , bHaveCus(false) 38 , bCusEnable(false) 39 { 40 SetColCount( 1 ); 41 } 42 43 44 ValueSetWithTextControl::~ValueSetWithTextControl(void) 45 { 46 } 47 48 void ValueSetWithTextControl::InsertCustom(Image imgEnable, Image imgDisable, XubString str) 49 { 50 bHaveCus = true; 51 imgCusEnable = imgEnable; 52 imgCusDisable = imgDisable; 53 strLastCustom = str; 54 InsertItem(maItems.size() + 1); 55 } 56 57 void ValueSetWithTextControl::SetDefaultTip(XubString* pStrList, sal_Bool bRealTip) 58 { 59 for(sal_uInt16 i=1; i <= maItems.size(); i++) 60 { 61 //if (bRealTip) 62 // SetItemHelpText(i, pStrList[i-1]); 63 //else 64 SetItemText(i, pStrList[i-1]); 65 } 66 } 67 68 void ValueSetWithTextControl::SetCustomTip(XubString str, sal_Bool bRealTip) 69 { 70 if(bHaveCus) 71 { 72 //if (bRealTip) 73 // SetItemHelpText(GetItemCount() + 1 , str); 74 //else 75 SetItemText(maItems.size()+ 1 , str); 76 } 77 } 78 79 void ValueSetWithTextControl::SetCusEnable(bool bEnable) 80 { 81 bCusEnable = bEnable; 82 } 83 84 void ValueSetWithTextControl::SetSelItem(sal_uInt16 nSel) 85 { 86 //nSelItem = nSel; 87 //add by wj for sym2_5397 88 if(nSel == 0) 89 { 90 SelectItem(1); 91 SetNoSelection(); 92 } 93 else 94 { 95 SelectItem(nSel); 96 GrabFocus(); 97 } 98 } 99 100 101 void ValueSetWithTextControl::AddItem( 102 const Image& rItemImage, 103 const Image* pSelectedItemImage, 104 const XubString& rItemText, 105 const XubString* pItemHelpText ) 106 { 107 if ( meControlType != IMAGE_TEXT ) 108 { 109 return; 110 } 111 112 ValueSetWithTextItem aItem; 113 aItem.maItemImage = rItemImage; 114 aItem.maSelectedItemImage = (pSelectedItemImage != 0) 115 ? *pSelectedItemImage 116 : rItemImage; 117 aItem.maItemText = rItemText; 118 119 maItems.push_back( aItem ); 120 121 InsertItem( maItems.size() ); 122 SetItemText( maItems.size(), 123 (pItemHelpText != 0) ? *pItemHelpText : rItemText ); 124 } 125 126 127 void ValueSetWithTextControl::AddItem( 128 const XubString& rItemText, 129 const XubString& rItemText2, 130 const XubString* pItemHelpText ) 131 { 132 if ( meControlType != TEXT_TEXT ) 133 { 134 return; 135 } 136 137 ValueSetWithTextItem aItem; 138 aItem.maItemText = rItemText; 139 aItem.maItemText2 = rItemText2; 140 141 maItems.push_back( aItem ); 142 143 InsertItem( maItems.size() ); 144 SetItemText( maItems.size(), 145 (pItemHelpText != 0) ? *pItemHelpText : rItemText ); 146 } 147 148 149 void ValueSetWithTextControl::ReplaceItemImages( 150 const sal_uInt16 nItemId, 151 const Image& rItemImage, 152 const Image* pSelectedItemImage ) 153 { 154 if ( meControlType != IMAGE_TEXT ) 155 { 156 return; 157 } 158 159 if ( nItemId == 0 || 160 nItemId > maItems.size() ) 161 { 162 return; 163 } 164 165 maItems[nItemId-1].maItemImage = rItemImage; 166 maItems[nItemId-1].maSelectedItemImage = (pSelectedItemImage != 0) 167 ? *pSelectedItemImage 168 : rItemImage; 169 } 170 171 172 void ValueSetWithTextControl::UserDraw( const UserDrawEvent& rUDEvt ) 173 { 174 const Rectangle aRect = rUDEvt.GetRect(); 175 OutputDevice* pDev = rUDEvt.GetDevice(); 176 pDev->Push( PUSH_ALL ); 177 const sal_uInt16 nItemId = rUDEvt.GetItemId(); 178 179 const long nRectHeight = aRect.GetHeight(); 180 const Point aBLPos = aRect.TopLeft(); 181 182 Font aFont(OutputDevice::GetDefaultFont(DEFAULTFONT_UI_SANS, MsLangId::getSystemLanguage(), DEFAULTFONT_FLAGS_ONLYONE)); 183 { 184 Size aSize = aFont.GetSize(); 185 aSize.Height() = (nRectHeight*4)/9; 186 aFont.SetSize( aSize ); 187 } 188 if(nItemId == (maItems.size() + 1) && bHaveCus) 189 { 190 //Point aStrStart(aBLPos.X() + imgCusEnable.GetSizePixel().Width() + 20 , aBLPos.Y() + nRectHeight/6); 191 Rectangle aStrRect = aRect; 192 aStrRect.Top() += nRectHeight/6; 193 aStrRect.Bottom() -= nRectHeight/6; 194 aStrRect.Left() += imgCusEnable.GetSizePixel().Width() + 20; 195 196 pDev->SetFillColor( COL_TRANSPARENT ); 197 pDev->DrawRect(aRect); 198 199 if(bCusEnable) 200 { 201 Point aImgStart(aBLPos.X() + 5, aBLPos.Y() + ( nRectHeight - imgCusEnable.GetSizePixel().Height() ) / 2); 202 pDev->DrawImage(aImgStart, imgCusEnable); 203 aFont.SetColor(GetSettings().GetStyleSettings().GetFieldTextColor()); //GetSettings().GetStyleSettings().GetHighContrastMode() ? COL_WHITE : COL_BLACKadd for sym2_7246 for high contrast 204 } 205 else 206 { 207 Point aImgStart(aBLPos.X() + 5, aBLPos.Y() + ( nRectHeight - imgCusDisable.GetSizePixel().Height() ) / 2); 208 pDev->DrawImage(aImgStart, imgCusDisable); 209 //Color aCol(155,155,155); 210 aFont.SetColor(GetSettings().GetStyleSettings().GetDisableColor()); 211 } 212 pDev->SetFont(aFont); 213 pDev->DrawText(aStrRect, strLastCustom, TEXT_DRAW_ENDELLIPSIS); //add by wj for sym2_4049 214 } 215 else 216 { 217 //draw backgroud 218 if ( GetSelectItemId() == nItemId ) 219 { 220 Rectangle aBackRect = aRect; 221 aBackRect.Top() += 3; 222 aBackRect.Bottom() -= 2; 223 pDev->SetFillColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_Highlight ) ); 224 pDev->DrawRect(aBackRect); 225 } 226 else 227 { 228 pDev->SetFillColor( COL_TRANSPARENT ); 229 pDev->DrawRect(aRect); 230 } 231 232 //draw image + text resp. text + text 233 Image* pImage = 0; 234 if ( GetSelectItemId() == nItemId ) 235 { 236 aFont.SetColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_HighlightText ) ); 237 pImage = &maItems[nItemId-1].maSelectedItemImage; 238 } 239 else 240 { 241 aFont.SetColor( GetSettings().GetStyleSettings().GetFieldTextColor() ); 242 pImage = &maItems[nItemId-1].maItemImage; 243 } 244 245 Rectangle aStrRect = aRect; 246 aStrRect.Top() += nRectHeight/4; 247 aStrRect.Bottom() -= nRectHeight/4; 248 249 switch ( meControlType ) 250 { 251 case IMAGE_TEXT: 252 { 253 Point aImgStart( 254 aBLPos.X() + 4, 255 aBLPos.Y() + ( ( nRectHeight - pImage->GetSizePixel().Height() ) / 2 ) ); 256 pDev->DrawImage( aImgStart, *pImage ); 257 258 aStrRect.Left() += pImage->GetSizePixel().Width() + 12; 259 pDev->SetFont(aFont); 260 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, TEXT_DRAW_ENDELLIPSIS); 261 } 262 break; 263 case TEXT_TEXT: 264 { 265 const long nRectWidth = aRect.GetWidth(); 266 aStrRect.Left() += 8; 267 aStrRect.Right() -= (nRectWidth*2)/3; 268 pDev->SetFont(aFont); 269 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, TEXT_DRAW_ENDELLIPSIS); 270 aStrRect.Left() += nRectWidth/3; 271 aStrRect.Right() += (nRectWidth*2)/3; 272 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText2, TEXT_DRAW_ENDELLIPSIS); 273 } 274 break; 275 } 276 } 277 278 Invalidate( aRect ); 279 pDev->Pop(); 280 } 281 282 } } // end of namespace svx::sidebar 283