Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : *
8 : * This file incorporates work covered by the following license notice:
9 : *
10 : * Licensed to the Apache Software Foundation (ASF) under one or more
11 : * contributor license agreements. See the NOTICE file distributed
12 : * with this work for additional information regarding copyright
13 : * ownership. The ASF licenses this file to you under the Apache
14 : * License, Version 2.0 (the "License"); you may not use this file
15 : * except in compliance with the License. You may obtain a copy of
16 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 : */
18 :
19 : #include <CellLineStyleValueSet.hxx>
20 : #include <i18nlangtag/mslangid.hxx>
21 :
22 : namespace sc { namespace sidebar {
23 :
24 0 : CellLineStyleValueSet::CellLineStyleValueSet( Window* pParent, const ResId& rResId)
25 : : ValueSet( pParent, rResId ),
26 : pVDev(NULL),
27 : nSelItem(0),
28 0 : bCusEnable(false)
29 : {
30 0 : strUnit = new XubString[9];
31 0 : SetColCount( 1 );
32 0 : SetLineCount( 9);
33 0 : }
34 :
35 0 : CellLineStyleValueSet::~CellLineStyleValueSet()
36 : {
37 0 : delete pVDev;
38 0 : delete[] strUnit;
39 0 : }
40 :
41 0 : void CellLineStyleValueSet::SetUnit(XubString* str)
42 : {
43 0 : for(int i = 0; i < 9; i++)
44 : {
45 0 : strUnit[i] = str[i];
46 : }
47 0 : }
48 :
49 0 : void CellLineStyleValueSet::SetSelItem(sal_uInt16 nSel)
50 : {
51 0 : nSelItem = nSel;
52 0 : if(nSel == 0)
53 : {
54 0 : SelectItem(1);
55 0 : SetNoSelection();
56 : }
57 : else
58 : {
59 0 : SelectItem(nSelItem);
60 0 : GrabFocus();
61 : }
62 0 : }
63 :
64 0 : sal_uInt16 CellLineStyleValueSet::GetSelItem()
65 : {
66 0 : return nSelItem;
67 : }
68 :
69 0 : void CellLineStyleValueSet::SetImage(Image img)
70 : {
71 0 : imgCus = img;
72 0 : }
73 :
74 0 : void CellLineStyleValueSet::SetCusEnable(bool bEnable)
75 : {
76 0 : bCusEnable = bEnable;
77 0 : }
78 :
79 0 : void CellLineStyleValueSet::UserDraw( const UserDrawEvent& rUDEvt )
80 : {
81 0 : Rectangle aRect = rUDEvt.GetRect();
82 0 : OutputDevice* pDev = rUDEvt.GetDevice();
83 0 : sal_uInt16 nItemId = rUDEvt.GetItemId();
84 :
85 0 : long nRectHeight = aRect.GetHeight();
86 0 : long nRectWidth = aRect.GetWidth();
87 0 : Point aBLPos = aRect.TopLeft();
88 :
89 0 : Font aOldFont = pDev->GetFont();
90 0 : Color aOldColor = pDev->GetLineColor();
91 0 : Color aOldFillColor = pDev->GetFillColor();
92 :
93 0 : Font aFont(OutputDevice::GetDefaultFont(DEFAULTFONT_UI_SANS, MsLangId::getSystemLanguage(), DEFAULTFONT_FLAGS_ONLYONE));
94 0 : Size aSize = aFont.GetSize();
95 0 : aSize.Height() = nRectHeight*3/5;
96 0 : aFont.SetSize( aSize );
97 :
98 0 : long nTLX = aBLPos.X() + 5, nTLY = aBLPos.Y() + ( nRectHeight - nItemId )/2;
99 0 : long nTRX = aBLPos.X() + nRectWidth * 7 / 9 - 15, nTRY = aBLPos.Y() + ( nRectHeight - nItemId )/2;
100 :
101 0 : if( nSelItem == nItemId )
102 : {
103 0 : Color aBackColor(50,107,197);
104 0 : Rectangle aBackRect = aRect;
105 0 : aBackRect.Top() += 3;
106 0 : aBackRect.Bottom() -= 2;
107 0 : pDev->SetFillColor(aBackColor);
108 0 : pDev->DrawRect(aBackRect);
109 : }
110 : else
111 : {
112 0 : pDev->SetFillColor( COL_TRANSPARENT );
113 0 : pDev->DrawRect(aRect);
114 : }
115 :
116 : //draw text
117 0 : if(nSelItem == nItemId )
118 0 : aFont.SetColor(COL_WHITE);
119 : else
120 0 : aFont.SetColor(GetSettings().GetStyleSettings().GetFieldTextColor()); //high contrast
121 :
122 0 : pDev->SetFont(aFont);
123 0 : Point aStart(aBLPos.X() + nRectWidth * 7 / 9 - 5 , aBLPos.Y() + nRectHeight/6);
124 0 : pDev->DrawText(aStart, strUnit[ nItemId - 1 ]); //can't set TEXT_DRAW_ENDELLIPSIS here, or the text will disapear
125 :
126 : //draw line
127 0 : if( nSelItem == nItemId )
128 : {
129 0 : pDev->SetFillColor(COL_WHITE);
130 0 : pDev->SetLineColor(COL_WHITE);
131 : }
132 : else
133 : {
134 0 : pDev->SetFillColor(GetSettings().GetStyleSettings().GetFieldTextColor()); //high contrast
135 0 : pDev->SetLineColor(GetSettings().GetStyleSettings().GetFieldTextColor()); //high contrast
136 : }
137 :
138 0 : switch( nItemId )
139 : {
140 : case 1:
141 : case 2:
142 : case 3:
143 : case 4:
144 0 : pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + nItemId * 2 - 1 ));
145 0 : break;
146 : case 5:
147 0 : pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
148 0 : pDev->DrawRect(Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 4 ));
149 0 : break;
150 : case 6:
151 0 : pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
152 0 : pDev->DrawRect(Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 ));
153 0 : break;
154 : case 7:
155 0 : pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
156 0 : pDev->DrawRect(Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 6 ));
157 0 : break;
158 : case 8:
159 0 : pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 3 ));
160 0 : pDev->DrawRect(Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 ));
161 0 : break;
162 : case 9:
163 0 : pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 3 ));
164 0 : pDev->DrawRect(Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 8 ));
165 0 : break;
166 : }
167 :
168 0 : Invalidate( aRect );
169 0 : pDev->SetLineColor(aOldColor);
170 0 : pDev->SetFillColor(aOldFillColor);
171 0 : pDev->SetFont(aOldFont);
172 :
173 0 : }
174 :
175 93 : } } // end of namespace svx::sidebar
176 :
177 : // eof
|