1c718a697SOliver-Rainer Wittmann /**************************************************************
2c718a697SOliver-Rainer Wittmann  *
3c718a697SOliver-Rainer Wittmann  * Licensed to the Apache Software Foundation (ASF) under one
4c718a697SOliver-Rainer Wittmann  * or more contributor license agreements.  See the NOTICE file
5c718a697SOliver-Rainer Wittmann  * distributed with this work for additional information
6c718a697SOliver-Rainer Wittmann  * regarding copyright ownership.  The ASF licenses this file
7c718a697SOliver-Rainer Wittmann  * to you under the Apache License, Version 2.0 (the
8c718a697SOliver-Rainer Wittmann  * "License"); you may not use this file except in compliance
9c718a697SOliver-Rainer Wittmann  * with the License.  You may obtain a copy of the License at
10c718a697SOliver-Rainer Wittmann  *
11c718a697SOliver-Rainer Wittmann  *   http://www.apache.org/licenses/LICENSE-2.0
12c718a697SOliver-Rainer Wittmann  *
13c718a697SOliver-Rainer Wittmann  * Unless required by applicable law or agreed to in writing,
14c718a697SOliver-Rainer Wittmann  * software distributed under the License is distributed on an
15c718a697SOliver-Rainer Wittmann  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c718a697SOliver-Rainer Wittmann  * KIND, either express or implied.  See the License for the
17c718a697SOliver-Rainer Wittmann  * specific language governing permissions and limitations
18c718a697SOliver-Rainer Wittmann  * under the License.
19c718a697SOliver-Rainer Wittmann  *
20c718a697SOliver-Rainer Wittmann  *************************************************************/
21c718a697SOliver-Rainer Wittmann 
22c718a697SOliver-Rainer Wittmann #include "svx/sidebar/ValueSetWithTextControl.hxx"
232055df08SOliver-Rainer Wittmann 
242055df08SOliver-Rainer Wittmann #include <sfx2/sidebar/Theme.hxx>
25c718a697SOliver-Rainer Wittmann 
262055df08SOliver-Rainer Wittmann #include <i18npool/mslangid.hxx>
27c718a697SOliver-Rainer Wittmann 
28c718a697SOliver-Rainer Wittmann namespace svx { namespace sidebar {
29c718a697SOliver-Rainer Wittmann 
302055df08SOliver-Rainer Wittmann ValueSetWithTextControl::ValueSetWithTextControl(
312055df08SOliver-Rainer Wittmann     const tControlType eControlType,
322055df08SOliver-Rainer Wittmann     Window* pParent,
332055df08SOliver-Rainer Wittmann     const ResId& rResId)
342055df08SOliver-Rainer Wittmann     : ValueSet( pParent, rResId )
352055df08SOliver-Rainer Wittmann     , meControlType( eControlType )
362055df08SOliver-Rainer Wittmann     , maItems()
372055df08SOliver-Rainer Wittmann {
382055df08SOliver-Rainer Wittmann     SetColCount( 1 );
392055df08SOliver-Rainer Wittmann }
402055df08SOliver-Rainer Wittmann 
41*ccdbcfa9SOliver-Rainer Wittmann 
422055df08SOliver-Rainer Wittmann ValueSetWithTextControl::~ValueSetWithTextControl(void)
432055df08SOliver-Rainer Wittmann {
442055df08SOliver-Rainer Wittmann }
452055df08SOliver-Rainer Wittmann 
46*ccdbcfa9SOliver-Rainer Wittmann 
472055df08SOliver-Rainer Wittmann void ValueSetWithTextControl::AddItem(
482055df08SOliver-Rainer Wittmann     const Image& rItemImage,
492055df08SOliver-Rainer Wittmann     const Image* pSelectedItemImage,
502055df08SOliver-Rainer Wittmann     const XubString& rItemText,
512055df08SOliver-Rainer Wittmann     const XubString* pItemHelpText )
522055df08SOliver-Rainer Wittmann {
532055df08SOliver-Rainer Wittmann     if ( meControlType != IMAGE_TEXT )
542055df08SOliver-Rainer Wittmann     {
552055df08SOliver-Rainer Wittmann         return;
562055df08SOliver-Rainer Wittmann     }
572055df08SOliver-Rainer Wittmann 
582055df08SOliver-Rainer Wittmann     ValueSetWithTextItem aItem;
592055df08SOliver-Rainer Wittmann     aItem.maItemImage = rItemImage;
602055df08SOliver-Rainer Wittmann     aItem.maSelectedItemImage = (pSelectedItemImage != 0)
612055df08SOliver-Rainer Wittmann                                 ? *pSelectedItemImage
622055df08SOliver-Rainer Wittmann                                 : rItemImage;
632055df08SOliver-Rainer Wittmann     aItem.maItemText = rItemText;
642055df08SOliver-Rainer Wittmann 
652055df08SOliver-Rainer Wittmann     maItems.push_back( aItem );
662055df08SOliver-Rainer Wittmann 
672055df08SOliver-Rainer Wittmann     InsertItem( maItems.size() );
682055df08SOliver-Rainer Wittmann     SetItemText( maItems.size(),
692055df08SOliver-Rainer Wittmann                     (pItemHelpText != 0) ? *pItemHelpText : rItemText );
702055df08SOliver-Rainer Wittmann }
712055df08SOliver-Rainer Wittmann 
72*ccdbcfa9SOliver-Rainer Wittmann 
732055df08SOliver-Rainer Wittmann void ValueSetWithTextControl::AddItem(
742055df08SOliver-Rainer Wittmann     const XubString& rItemText,
752055df08SOliver-Rainer Wittmann     const XubString& rItemText2,
762055df08SOliver-Rainer Wittmann     const XubString* pItemHelpText )
772055df08SOliver-Rainer Wittmann {
782055df08SOliver-Rainer Wittmann     if ( meControlType != TEXT_TEXT )
792055df08SOliver-Rainer Wittmann     {
802055df08SOliver-Rainer Wittmann         return;
812055df08SOliver-Rainer Wittmann     }
822055df08SOliver-Rainer Wittmann 
832055df08SOliver-Rainer Wittmann     ValueSetWithTextItem aItem;
842055df08SOliver-Rainer Wittmann     aItem.maItemText = rItemText;
852055df08SOliver-Rainer Wittmann     aItem.maItemText2 = rItemText2;
862055df08SOliver-Rainer Wittmann 
872055df08SOliver-Rainer Wittmann     maItems.push_back( aItem );
882055df08SOliver-Rainer Wittmann 
892055df08SOliver-Rainer Wittmann     InsertItem( maItems.size() );
902055df08SOliver-Rainer Wittmann     SetItemText( maItems.size(),
912055df08SOliver-Rainer Wittmann                     (pItemHelpText != 0) ? *pItemHelpText : rItemText );
922055df08SOliver-Rainer Wittmann }
932055df08SOliver-Rainer Wittmann 
94*ccdbcfa9SOliver-Rainer Wittmann 
95*ccdbcfa9SOliver-Rainer Wittmann void ValueSetWithTextControl::ReplaceItemImages(
96*ccdbcfa9SOliver-Rainer Wittmann     const sal_uInt16 nItemId,
97*ccdbcfa9SOliver-Rainer Wittmann     const Image& rItemImage,
98*ccdbcfa9SOliver-Rainer Wittmann     const Image* pSelectedItemImage )
99*ccdbcfa9SOliver-Rainer Wittmann {
100*ccdbcfa9SOliver-Rainer Wittmann     if ( meControlType != IMAGE_TEXT )
101*ccdbcfa9SOliver-Rainer Wittmann     {
102*ccdbcfa9SOliver-Rainer Wittmann         return;
103*ccdbcfa9SOliver-Rainer Wittmann     }
104*ccdbcfa9SOliver-Rainer Wittmann 
105*ccdbcfa9SOliver-Rainer Wittmann     if ( nItemId == 0 ||
106*ccdbcfa9SOliver-Rainer Wittmann          nItemId > maItems.size() )
107*ccdbcfa9SOliver-Rainer Wittmann     {
108*ccdbcfa9SOliver-Rainer Wittmann         return;
109*ccdbcfa9SOliver-Rainer Wittmann     }
110*ccdbcfa9SOliver-Rainer Wittmann 
111*ccdbcfa9SOliver-Rainer Wittmann     maItems[nItemId-1].maItemImage = rItemImage;
112*ccdbcfa9SOliver-Rainer Wittmann     maItems[nItemId-1].maSelectedItemImage = (pSelectedItemImage != 0)
113*ccdbcfa9SOliver-Rainer Wittmann                                              ? *pSelectedItemImage
114*ccdbcfa9SOliver-Rainer Wittmann                                              : rItemImage;
115*ccdbcfa9SOliver-Rainer Wittmann }
116*ccdbcfa9SOliver-Rainer Wittmann 
117*ccdbcfa9SOliver-Rainer Wittmann 
1182055df08SOliver-Rainer Wittmann void ValueSetWithTextControl::UserDraw( const UserDrawEvent& rUDEvt )
1192055df08SOliver-Rainer Wittmann {
1202055df08SOliver-Rainer Wittmann     const Rectangle aRect = rUDEvt.GetRect();
1212055df08SOliver-Rainer Wittmann     OutputDevice* pDev = rUDEvt.GetDevice();
1222055df08SOliver-Rainer Wittmann     pDev->Push( PUSH_ALL );
1232055df08SOliver-Rainer Wittmann     const sal_uInt16 nItemId = rUDEvt.GetItemId();
1242055df08SOliver-Rainer Wittmann 
1252055df08SOliver-Rainer Wittmann     const long nRectHeight = aRect.GetHeight();
1262055df08SOliver-Rainer Wittmann     const Point aBLPos = aRect.TopLeft();
1272055df08SOliver-Rainer Wittmann 
1282055df08SOliver-Rainer Wittmann     Font aFont(OutputDevice::GetDefaultFont(DEFAULTFONT_UI_SANS, MsLangId::getSystemLanguage(), DEFAULTFONT_FLAGS_ONLYONE));
1292055df08SOliver-Rainer Wittmann     {
1302055df08SOliver-Rainer Wittmann         Size aSize = aFont.GetSize();
1312055df08SOliver-Rainer Wittmann         aSize.Height() = (nRectHeight*4)/9;
1322055df08SOliver-Rainer Wittmann         aFont.SetSize( aSize );
1332055df08SOliver-Rainer Wittmann     }
1342055df08SOliver-Rainer Wittmann 
1352055df08SOliver-Rainer Wittmann     {
1362055df08SOliver-Rainer Wittmann         //draw backgroud
1372055df08SOliver-Rainer Wittmann         if ( GetSelectItemId() == nItemId )
1382055df08SOliver-Rainer Wittmann         {
1392055df08SOliver-Rainer Wittmann             Rectangle aBackRect = aRect;
1402055df08SOliver-Rainer Wittmann             aBackRect.Top() += 3;
1412055df08SOliver-Rainer Wittmann             aBackRect.Bottom() -= 2;
1422055df08SOliver-Rainer Wittmann             pDev->SetFillColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_Highlight ) );
1432055df08SOliver-Rainer Wittmann             pDev->DrawRect(aBackRect);
1442055df08SOliver-Rainer Wittmann         }
1452055df08SOliver-Rainer Wittmann         else
1462055df08SOliver-Rainer Wittmann         {
1472055df08SOliver-Rainer Wittmann             pDev->SetFillColor( COL_TRANSPARENT );
1482055df08SOliver-Rainer Wittmann             pDev->DrawRect(aRect);
1492055df08SOliver-Rainer Wittmann         }
1502055df08SOliver-Rainer Wittmann 
1512055df08SOliver-Rainer Wittmann         //draw image + text resp. text + text
1522055df08SOliver-Rainer Wittmann         Image* pImage = 0;
1532055df08SOliver-Rainer Wittmann         if ( GetSelectItemId() == nItemId )
1542055df08SOliver-Rainer Wittmann         {
1552055df08SOliver-Rainer Wittmann             aFont.SetColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_HighlightText ) );
1562055df08SOliver-Rainer Wittmann             pImage = &maItems[nItemId-1].maSelectedItemImage;
1572055df08SOliver-Rainer Wittmann         }
1582055df08SOliver-Rainer Wittmann         else
1592055df08SOliver-Rainer Wittmann         {
1602055df08SOliver-Rainer Wittmann             aFont.SetColor( GetSettings().GetStyleSettings().GetFieldTextColor() );
1612055df08SOliver-Rainer Wittmann             pImage = &maItems[nItemId-1].maItemImage;
1622055df08SOliver-Rainer Wittmann         }
1632055df08SOliver-Rainer Wittmann 
1642055df08SOliver-Rainer Wittmann         Rectangle aStrRect = aRect;
1652055df08SOliver-Rainer Wittmann         aStrRect.Top() += nRectHeight/4;
1662055df08SOliver-Rainer Wittmann         aStrRect.Bottom() -= nRectHeight/4;
1672055df08SOliver-Rainer Wittmann 
1682055df08SOliver-Rainer Wittmann         switch ( meControlType )
1692055df08SOliver-Rainer Wittmann         {
1702055df08SOliver-Rainer Wittmann         case IMAGE_TEXT:
1712055df08SOliver-Rainer Wittmann             {
1722055df08SOliver-Rainer Wittmann                 Point aImgStart(
1732055df08SOliver-Rainer Wittmann                     aBLPos.X() + 4,
1742055df08SOliver-Rainer Wittmann                     aBLPos.Y() + ( ( nRectHeight - pImage->GetSizePixel().Height() ) / 2 ) );
1752055df08SOliver-Rainer Wittmann                 pDev->DrawImage( aImgStart, *pImage );
1762055df08SOliver-Rainer Wittmann 
1772055df08SOliver-Rainer Wittmann                 aStrRect.Left() += pImage->GetSizePixel().Width() + 12;
1782055df08SOliver-Rainer Wittmann                 pDev->SetFont(aFont);
1792055df08SOliver-Rainer Wittmann                 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, TEXT_DRAW_ENDELLIPSIS);
1802055df08SOliver-Rainer Wittmann             }
1812055df08SOliver-Rainer Wittmann             break;
1822055df08SOliver-Rainer Wittmann         case TEXT_TEXT:
1832055df08SOliver-Rainer Wittmann             {
1842055df08SOliver-Rainer Wittmann                 const long nRectWidth = aRect.GetWidth();
1852055df08SOliver-Rainer Wittmann                 aStrRect.Left() += 8;
1862055df08SOliver-Rainer Wittmann                 aStrRect.Right() -= (nRectWidth*2)/3;
1872055df08SOliver-Rainer Wittmann                 pDev->SetFont(aFont);
1882055df08SOliver-Rainer Wittmann                 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, TEXT_DRAW_ENDELLIPSIS);
1892055df08SOliver-Rainer Wittmann                 aStrRect.Left() += nRectWidth/3;
1902055df08SOliver-Rainer Wittmann                 aStrRect.Right() += (nRectWidth*2)/3;
1912055df08SOliver-Rainer Wittmann                 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText2, TEXT_DRAW_ENDELLIPSIS);
1922055df08SOliver-Rainer Wittmann             }
1932055df08SOliver-Rainer Wittmann             break;
1942055df08SOliver-Rainer Wittmann         }
1952055df08SOliver-Rainer Wittmann     }
1962055df08SOliver-Rainer Wittmann 
1972055df08SOliver-Rainer Wittmann     Invalidate( aRect );
1982055df08SOliver-Rainer Wittmann     pDev->Pop();
1992055df08SOliver-Rainer Wittmann }
200c718a697SOliver-Rainer Wittmann 
201c718a697SOliver-Rainer Wittmann } } // end of namespace svx::sidebar
202