Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / sidebar / CellLineStyleValueSet.cxx
blobfbc1ff73480efb74df43c98f9af914a45858b75b
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>
23 namespace sc { namespace sidebar {
25 CellLineStyleValueSet::CellLineStyleValueSet( Window* pParent, const ResId& rResId)
26 : ValueSet( pParent, rResId ),
27 pVDev(NULL),
28 nSelItem(0)
30 SetColCount( 1 );
31 SetLineCount( 9);
34 CellLineStyleValueSet::~CellLineStyleValueSet()
36 delete pVDev;
39 void CellLineStyleValueSet::SetUnit(const OUString* str)
41 for (int i = 0; i < CELL_LINE_STYLE_ENTRIES; ++i)
43 maStrUnit[i] = str[i];
47 void CellLineStyleValueSet::SetSelItem(sal_uInt16 nSel)
49 nSelItem = nSel;
50 if(nSel == 0)
52 SelectItem(1);
53 SetNoSelection();
55 else
57 SelectItem(nSelItem);
58 GrabFocus();
62 void CellLineStyleValueSet::SetImage(Image img)
64 imgCus = img;
67 void CellLineStyleValueSet::UserDraw( const UserDrawEvent& rUDEvt )
69 Rectangle aRect = rUDEvt.GetRect();
70 OutputDevice* pDev = rUDEvt.GetDevice();
71 sal_uInt16 nItemId = rUDEvt.GetItemId();
73 long nRectHeight = aRect.GetHeight();
74 long nRectWidth = aRect.GetWidth();
75 Point aBLPos = aRect.TopLeft();
77 Font aOldFont = pDev->GetFont();
78 Color aOldColor = pDev->GetLineColor();
79 Color aOldFillColor = pDev->GetFillColor();
81 Font aFont(OutputDevice::GetDefaultFont(DEFAULTFONT_UI_SANS, MsLangId::getSystemLanguage(), DEFAULTFONT_FLAGS_ONLYONE));
82 Size aSize = aFont.GetSize();
83 aSize.Height() = nRectHeight*3/5;
84 aFont.SetSize( aSize );
86 long nTLX = aBLPos.X() + 5, nTLY = aBLPos.Y() + ( nRectHeight - nItemId )/2;
87 long nTRX = aBLPos.X() + nRectWidth * 7 / 9 - 15, nTRY = aBLPos.Y() + ( nRectHeight - nItemId )/2;
89 if( nSelItem == nItemId )
91 Color aBackColor(50,107,197);
92 Rectangle aBackRect = aRect;
93 aBackRect.Top() += 3;
94 aBackRect.Bottom() -= 2;
95 pDev->SetFillColor(aBackColor);
96 pDev->DrawRect(aBackRect);
98 else
100 pDev->SetFillColor( COL_TRANSPARENT );
101 pDev->DrawRect(aRect);
104 //draw text
105 if(nSelItem == nItemId )
106 aFont.SetColor(COL_WHITE);
107 else
108 aFont.SetColor(GetSettings().GetStyleSettings().GetFieldTextColor()); //high contrast
110 pDev->SetFont(aFont);
111 Point aStart(aBLPos.X() + nRectWidth * 7 / 9 - 5 , aBLPos.Y() + nRectHeight/6);
112 pDev->DrawText(aStart, maStrUnit[nItemId - 1]); //can't set TEXT_DRAW_ENDELLIPSIS here, or the text will disapear
114 //draw line
115 if( nSelItem == nItemId )
117 pDev->SetFillColor(COL_WHITE);
118 pDev->SetLineColor(COL_WHITE);
120 else
122 pDev->SetFillColor(GetSettings().GetStyleSettings().GetFieldTextColor()); //high contrast
123 pDev->SetLineColor(GetSettings().GetStyleSettings().GetFieldTextColor()); //high contrast
126 switch( nItemId )
128 case 1:
129 case 2:
130 case 3:
131 case 4:
132 pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + nItemId * 2 - 1 ));
133 break;
134 case 5:
135 pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
136 pDev->DrawRect(Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 4 ));
137 break;
138 case 6:
139 pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
140 pDev->DrawRect(Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 ));
141 break;
142 case 7:
143 pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
144 pDev->DrawRect(Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 6 ));
145 break;
146 case 8:
147 pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 3 ));
148 pDev->DrawRect(Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 ));
149 break;
150 case 9:
151 pDev->DrawRect(Rectangle(nTLX, nTLY , nTRX, nTRY + 3 ));
152 pDev->DrawRect(Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 8 ));
153 break;
156 Invalidate( aRect );
157 pDev->SetLineColor(aOldColor);
158 pDev->SetFillColor(aOldFillColor);
159 pDev->SetFont(aOldFont);
163 } } // end of namespace svx::sidebar
165 // eof
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */