calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / sc / source / ui / sidebar / CellLineStyleValueSet.cxx
blobd7c9e9b3ced52d1efda3899c57c72528524654ed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "CellLineStyleValueSet.hxx"
21 #include <i18nlangtag/mslangid.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/svapp.hxx>
26 namespace sc::sidebar {
28 CellLineStyleValueSet::CellLineStyleValueSet()
29 : ValueSet(nullptr)
30 , mnMaxTextWidth(0)
31 , nSelItem(0)
35 CellLineStyleValueSet::~CellLineStyleValueSet()
39 void CellLineStyleValueSet::SetDrawingArea(weld::DrawingArea* pDrawingArea)
41 ValueSet::SetDrawingArea(pDrawingArea);
42 Size aSize = pDrawingArea->get_ref_device().LogicToPixel(Size(120, 12 * CELL_LINE_STYLE_ENTRIES),
43 MapMode(MapUnit::MapAppFont));
44 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
45 SetOutputSizePixel(aSize);
47 SetColCount();
48 SetLineCount(CELL_LINE_STYLE_ENTRIES);
51 void CellLineStyleValueSet::SetUnit(const OUString* str)
53 for (int i = 0; i < CELL_LINE_STYLE_ENTRIES; ++i)
55 maStrUnit[i] = str[i];
59 void CellLineStyleValueSet::SetSelItem(sal_uInt16 nSel)
61 nSelItem = nSel;
62 if(nSel == 0)
64 SelectItem(1);
65 SetNoSelection();
67 else
69 SelectItem(nSelItem);
70 GrabFocus();
74 tools::Long CellLineStyleValueSet::GetMaxTextWidth(const vcl::RenderContext* pDev)
76 if (mnMaxTextWidth > 0)
77 return mnMaxTextWidth;
79 for (int i = 0; i < CELL_LINE_STYLE_ENTRIES; ++i)
81 mnMaxTextWidth = std::max(pDev->GetTextWidth(maStrUnit[i]), mnMaxTextWidth);
83 return mnMaxTextWidth;
86 void CellLineStyleValueSet::UserDraw( const UserDrawEvent& rUDEvt )
88 tools::Rectangle aRect = rUDEvt.GetRect();
89 vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
90 sal_uInt16 nItemId = rUDEvt.GetItemId();
92 tools::Long nRectHeight = aRect.GetHeight();
93 tools::Long nRectWidth = aRect.GetWidth();
94 Point aBLPos = aRect.TopLeft();
96 vcl::Font aOldFont = pDev->GetFont();
97 Color aOldColor = pDev->GetLineColor();
98 Color aOldFillColor = pDev->GetFillColor();
100 vcl::Font aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, MsLangId::getConfiguredSystemLanguage(), GetDefaultFontFlags::OnlyOne));
101 Size aSize = aFont.GetFontSize();
102 aSize.setHeight( nRectHeight*3/5 );
103 aFont.SetFontSize( aSize );
105 if( nSelItem == nItemId )
107 tools::Rectangle aBackRect = aRect;
108 aBackRect.AdjustTop(3 );
109 aBackRect.AdjustBottom( -2 );
110 pDev->SetFillColor(Color(50,107,197));
111 pDev->DrawRect(aBackRect);
113 else
115 pDev->SetFillColor( COL_TRANSPARENT );
116 pDev->DrawRect(aRect);
119 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
121 //draw text
122 if (nSelItem == nItemId )
123 aFont.SetColor(COL_WHITE);
124 else
125 aFont.SetColor(rStyleSettings.GetFieldTextColor()); //high contrast
127 pDev->SetFont(aFont);
128 tools::Long nTextWidth = GetMaxTextWidth(pDev);
129 tools::Long nTLX = aBLPos.X() + 5, nTLY = aBLPos.Y() + ( nRectHeight - nItemId )/2;
130 tools::Long nTRX = aBLPos.X() + nRectWidth - nTextWidth - 15, nTRY = aBLPos.Y() + ( nRectHeight - nItemId )/2;
131 Point aStart(aBLPos.X() + nRectWidth - nTextWidth - 5 , aBLPos.Y() + nRectHeight/6);
132 pDev->DrawText(aStart, maStrUnit[nItemId - 1]); //can't set DrawTextFlags::EndEllipsis here, or the text will disappear
134 //draw line
135 if( nSelItem == nItemId )
137 pDev->SetFillColor(COL_WHITE);
138 pDev->SetLineColor(COL_WHITE);
140 else
142 pDev->SetFillColor(rStyleSettings.GetFieldTextColor()); //high contrast
143 pDev->SetLineColor(rStyleSettings.GetFieldTextColor()); //high contrast
146 switch( nItemId )
148 case 1:
149 case 2:
150 case 3:
151 case 4:
152 case 5:
153 case 6:
154 pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + nItemId * 2 - 1 ));
155 break;
156 case 7:
157 pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
158 pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 4 ));
159 break;
160 case 8:
161 pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
162 pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 ));
163 break;
164 case 9:
165 pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
166 pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 6 ));
167 break;
168 case 10:
169 pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 3 ));
170 pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 ));
171 break;
172 case 11:
173 pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 3 ));
174 pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 8 ));
175 break;
178 Invalidate( aRect );
179 pDev->SetLineColor(aOldColor);
180 pDev->SetFillColor(aOldFillColor);
181 pDev->SetFont(aOldFont);
185 } // end of namespace sc::sidebar
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */