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