Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / sidebar / CellLineStyleControl.cxx
blobe3af22d8f17a8ef208604ad7879fdf77ee30b8b1
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 <CellLineStyleControl.hxx>
21 #include "sc.hrc"
22 #include "scresid.hxx"
23 #include <CellAppearancePropertyPanel.hrc>
24 #include <CellLineStyleValueSet.hxx>
25 #include <vcl/i18nhelp.hxx>
26 #include <editeng/boxitem.hxx>
27 #include <editeng/borderline.hxx>
28 #include <editeng/lineitem.hxx>
29 #include <CellAppearancePropertyPanel.hxx>
30 #include <sfx2/bindings.hxx>
31 #include <sfx2/dispatch.hxx>
33 namespace sc { namespace sidebar {
35 CellLineStyleControl::CellLineStyleControl(Window* pParent, CellAppearancePropertyPanel& rPanel)
36 : svx::sidebar::PopupControl(pParent, ScResId(RID_POPUPPANEL_APPEARANCE_CELL_LINESTYLE)),
37 mrCellAppearancePropertyPanel(rPanel),
38 maPushButtonMoreOptions(this, ScResId(PB_OPTIONS)),
39 maCellLineStyleValueSet(this, ScResId(VS_STYLE)),
40 mbVSfocus(true)
42 Initialize();
43 FreeResource();
46 void CellLineStyleControl::Initialize()
48 //maPushButtonMoreOptions.SetIcoPosX(2);
49 Link aLink = LINK(this, CellLineStyleControl, PBClickHdl);
50 maPushButtonMoreOptions.SetClickHdl(aLink);
52 maCellLineStyleValueSet.SetStyle(maCellLineStyleValueSet.GetStyle()| WB_3DLOOK | WB_NO_DIRECTSELECT);
53 maCellLineStyleValueSet.SetControlBackground(GetSettings().GetStyleSettings().GetMenuColor());
54 maCellLineStyleValueSet.SetColor(GetSettings().GetStyleSettings().GetMenuColor());
56 for(sal_uInt16 i = 1 ; i <= 9 ; i++)
58 maCellLineStyleValueSet.InsertItem(i);
61 maStr[0] = GetSettings().GetLocaleI18nHelper().GetNum( 5, 2 ) + "pt";
62 maStr[1] = GetSettings().GetLocaleI18nHelper().GetNum( 250, 2 ) + "pt";
63 maStr[2] = GetSettings().GetLocaleI18nHelper().GetNum( 400, 2 ) + "pt";
64 maStr[3] = GetSettings().GetLocaleI18nHelper().GetNum( 500, 2 ) + "pt";
65 maStr[4] = GetSettings().GetLocaleI18nHelper().GetNum( 110, 2 ) + "pt";
66 maStr[5] = GetSettings().GetLocaleI18nHelper().GetNum( 260, 2 ) + "pt";
67 maStr[6] = GetSettings().GetLocaleI18nHelper().GetNum( 450, 2 ) + "pt";
68 maStr[7] = GetSettings().GetLocaleI18nHelper().GetNum( 505, 2 ) + "pt";
69 maStr[8] = GetSettings().GetLocaleI18nHelper().GetNum( 750, 2 ) + "pt";
70 maCellLineStyleValueSet.SetUnit(&maStr[0]);
72 for (sal_uInt16 i = 1; i <= CELL_LINE_STYLE_ENTRIES; ++i)
74 maCellLineStyleValueSet.SetItemText(i, maStr[i-1]);
77 SetAllNoSel();
78 aLink = LINK(this, CellLineStyleControl, VSSelectHdl);
79 maCellLineStyleValueSet.SetSelectHdl(aLink);
80 maCellLineStyleValueSet.StartSelection();
81 maCellLineStyleValueSet.Show();
84 void CellLineStyleControl::GetFocus()
86 if(!mbVSfocus)
88 maPushButtonMoreOptions.GrabFocus();
90 else
92 maCellLineStyleValueSet.GrabFocus();
96 void CellLineStyleControl::SetAllNoSel()
98 maCellLineStyleValueSet.SelectItem(0);
99 maCellLineStyleValueSet.SetNoSelection();
100 maCellLineStyleValueSet.Format();
101 Invalidate();
102 maCellLineStyleValueSet.StartSelection();
105 IMPL_LINK(CellLineStyleControl, VSSelectHdl, void *, pControl)
107 if(pControl == &maCellLineStyleValueSet)
109 const sal_uInt16 iPos(maCellLineStyleValueSet.GetSelectItemId());
110 SvxLineItem aLineItem(SID_FRAME_LINESTYLE);
111 using namespace ::com::sun::star::table::BorderLineStyle;
112 editeng::SvxBorderStyle nStyle = SOLID;
113 sal_uInt16 n1 = 0;
114 sal_uInt16 n2 = 0;
115 sal_uInt16 n3 = 0;
117 //FIXME: fully for new border line possibilities
119 switch(iPos)
121 case 1:
122 n1 = DEF_LINE_WIDTH_0;
123 break;
124 case 2:
125 n1 = DEF_LINE_WIDTH_2;
126 break;
127 case 3:
128 n1 = DEF_LINE_WIDTH_3;
129 break;
130 case 4:
131 n1 = DEF_LINE_WIDTH_4;
132 break;
133 case 5:
134 n1 = DEF_LINE_WIDTH_0;
135 n2 = DEF_LINE_WIDTH_0;
136 n3 = DEF_LINE_WIDTH_1;
137 nStyle = DOUBLE;
138 break;
139 case 6:
140 n1 = DEF_LINE_WIDTH_0;
141 n2 = DEF_LINE_WIDTH_0;
142 n3 = DEF_LINE_WIDTH_2;
143 nStyle = DOUBLE;
144 break;
145 case 7:
146 n1 = DEF_LINE_WIDTH_1;
147 n2 = DEF_LINE_WIDTH_2;
148 n3 = DEF_LINE_WIDTH_1;
149 nStyle = DOUBLE;
150 break;
151 case 8:
152 n1 = DEF_LINE_WIDTH_2;
153 n2 = DEF_LINE_WIDTH_0;
154 n3 = DEF_LINE_WIDTH_2;
155 nStyle = DOUBLE;
156 break;
157 case 9:
158 n1 = DEF_LINE_WIDTH_2;
159 n2 = DEF_LINE_WIDTH_2;
160 n3 = DEF_LINE_WIDTH_2;
161 nStyle = DOUBLE;
162 break;
163 default:
164 break;
167 editeng::SvxBorderLine aTmp;
168 aTmp.GuessLinesWidths(nStyle, n1, n2, n3);
169 aLineItem.SetLine( &aTmp );
170 mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_FRAME_LINESTYLE, SFX_CALLMODE_RECORD, &aLineItem, 0L);
171 SetAllNoSel();
172 mrCellAppearancePropertyPanel.EndCellLineStylePopupMode();
175 return(0L);
178 IMPL_LINK(CellLineStyleControl, PBClickHdl, PushButton *, pPBtn)
180 if(pPBtn == &maPushButtonMoreOptions)
182 if(mrCellAppearancePropertyPanel.GetBindings())
184 mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_CELL_FORMAT_BORDER, SFX_CALLMODE_ASYNCHRON);
187 mrCellAppearancePropertyPanel.EndCellLineStylePopupMode();
190 return 0;
193 void CellLineStyleControl::SetLineStyleSelect(sal_uInt16 out, sal_uInt16 in, sal_uInt16 dis)
195 SetAllNoSel();
196 mbVSfocus = true;
198 //FIXME: fully for new border line possibilities
200 if(out == DEF_LINE_WIDTH_0 && in == 0 && dis == 0) //1
202 maCellLineStyleValueSet.SetSelItem(1);
204 else if(out == DEF_LINE_WIDTH_2 && in == 0 && dis == 0) //2
206 maCellLineStyleValueSet.SetSelItem(2);
208 else if(out == DEF_LINE_WIDTH_3 && in == 0 && dis == 0) //3
210 maCellLineStyleValueSet.SetSelItem(3);
212 else if(out == DEF_LINE_WIDTH_4 && in == 0 && dis == 0) //4
214 maCellLineStyleValueSet.SetSelItem(4);
216 else if(out == DEF_LINE_WIDTH_0 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_1) //5
218 maCellLineStyleValueSet.SetSelItem(5);
220 else if(out == DEF_LINE_WIDTH_0 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_2) //6
222 maCellLineStyleValueSet.SetSelItem(6);
224 else if(out == DEF_LINE_WIDTH_1 && in == DEF_LINE_WIDTH_2 && dis == DEF_LINE_WIDTH_1) //7
226 maCellLineStyleValueSet.SetSelItem(7);
228 else if(out == DEF_LINE_WIDTH_2 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_2) //8
230 maCellLineStyleValueSet.SetSelItem(8);
232 else if(out == DEF_LINE_WIDTH_2 && in == DEF_LINE_WIDTH_2 && dis == DEF_LINE_WIDTH_2) //9
234 maCellLineStyleValueSet.SetSelItem(9);
236 else
238 maCellLineStyleValueSet.SetSelItem(0);
239 mbVSfocus = false;
242 maCellLineStyleValueSet.Format();
243 maCellLineStyleValueSet.StartSelection();
246 } } // end of namespace svx::sidebar
248 // eof
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */