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