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