Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / sc / source / ui / sidebar / CellLineStyleControl.cxx
blob32455bfb046701966065c52eb7c731c9fd59d57a
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 <vcl/settings.hxx>
27 #include <editeng/boxitem.hxx>
28 #include <editeng/borderline.hxx>
29 #include <editeng/lineitem.hxx>
30 #include "CellAppearancePropertyPanel.hxx"
31 #include <sfx2/bindings.hxx>
32 #include <sfx2/dispatch.hxx>
34 namespace sc { namespace sidebar {
36 CellLineStyleControl::CellLineStyleControl(Window* pParent, CellAppearancePropertyPanel& rPanel)
37 : svx::sidebar::PopupControl(pParent, ScResId(RID_POPUPPANEL_APPEARANCE_CELL_LINESTYLE)),
38 mrCellAppearancePropertyPanel(rPanel),
39 maPushButtonMoreOptions(this, ScResId(PB_OPTIONS)),
40 maCellLineStyleValueSet(this, ScResId(VS_STYLE)),
41 mbVSfocus(true)
43 Initialize();
44 FreeResource();
47 void CellLineStyleControl::Initialize()
49 //maPushButtonMoreOptions.SetIcoPosX(2);
50 Link aLink = LINK(this, CellLineStyleControl, PBClickHdl);
51 maPushButtonMoreOptions.SetClickHdl(aLink);
53 maCellLineStyleValueSet.SetStyle(maCellLineStyleValueSet.GetStyle()| WB_3DLOOK | WB_NO_DIRECTSELECT);
54 maCellLineStyleValueSet.SetControlBackground(GetSettings().GetStyleSettings().GetMenuColor());
55 maCellLineStyleValueSet.SetColor(GetSettings().GetStyleSettings().GetMenuColor());
57 for(sal_uInt16 i = 1 ; i <= 9 ; i++)
59 maCellLineStyleValueSet.InsertItem(i);
62 maStr[0] = GetSettings().GetLocaleI18nHelper().GetNum( 5, 2 ) + "pt";
63 maStr[1] = GetSettings().GetLocaleI18nHelper().GetNum( 250, 2 ) + "pt";
64 maStr[2] = GetSettings().GetLocaleI18nHelper().GetNum( 400, 2 ) + "pt";
65 maStr[3] = GetSettings().GetLocaleI18nHelper().GetNum( 500, 2 ) + "pt";
66 maStr[4] = GetSettings().GetLocaleI18nHelper().GetNum( 110, 2 ) + "pt";
67 maStr[5] = GetSettings().GetLocaleI18nHelper().GetNum( 260, 2 ) + "pt";
68 maStr[6] = GetSettings().GetLocaleI18nHelper().GetNum( 450, 2 ) + "pt";
69 maStr[7] = GetSettings().GetLocaleI18nHelper().GetNum( 505, 2 ) + "pt";
70 maStr[8] = GetSettings().GetLocaleI18nHelper().GetNum( 750, 2 ) + "pt";
71 maCellLineStyleValueSet.SetUnit(&maStr[0]);
73 for (sal_uInt16 i = 1; i <= CELL_LINE_STYLE_ENTRIES; ++i)
75 maCellLineStyleValueSet.SetItemText(i, maStr[i-1]);
78 SetAllNoSel();
79 aLink = LINK(this, CellLineStyleControl, VSSelectHdl);
80 maCellLineStyleValueSet.SetSelectHdl(aLink);
81 maCellLineStyleValueSet.StartSelection();
82 maCellLineStyleValueSet.Show();
85 void CellLineStyleControl::GetFocus()
87 if(!mbVSfocus)
89 maPushButtonMoreOptions.GrabFocus();
91 else
93 maCellLineStyleValueSet.GrabFocus();
97 void CellLineStyleControl::SetAllNoSel()
99 maCellLineStyleValueSet.SelectItem(0);
100 maCellLineStyleValueSet.SetNoSelection();
101 maCellLineStyleValueSet.Format();
102 Invalidate();
103 maCellLineStyleValueSet.StartSelection();
106 IMPL_LINK(CellLineStyleControl, VSSelectHdl, void *, pControl)
108 if(pControl == &maCellLineStyleValueSet)
110 const sal_uInt16 iPos(maCellLineStyleValueSet.GetSelectItemId());
111 SvxLineItem aLineItem(SID_FRAME_LINESTYLE);
112 using namespace ::com::sun::star::table::BorderLineStyle;
113 editeng::SvxBorderStyle nStyle = SOLID;
114 sal_uInt16 n1 = 0;
115 sal_uInt16 n2 = 0;
116 sal_uInt16 n3 = 0;
118 //FIXME: fully for new border line possibilities
120 switch(iPos)
122 case 1:
123 n1 = DEF_LINE_WIDTH_0;
124 break;
125 case 2:
126 n1 = DEF_LINE_WIDTH_2;
127 break;
128 case 3:
129 n1 = DEF_LINE_WIDTH_3;
130 break;
131 case 4:
132 n1 = DEF_LINE_WIDTH_4;
133 break;
134 case 5:
135 n1 = DEF_LINE_WIDTH_0;
136 n2 = DEF_LINE_WIDTH_0;
137 n3 = DEF_LINE_WIDTH_1;
138 nStyle = DOUBLE;
139 break;
140 case 6:
141 n1 = DEF_LINE_WIDTH_0;
142 n2 = DEF_LINE_WIDTH_0;
143 n3 = DEF_LINE_WIDTH_2;
144 nStyle = DOUBLE;
145 break;
146 case 7:
147 n1 = DEF_LINE_WIDTH_1;
148 n2 = DEF_LINE_WIDTH_2;
149 n3 = DEF_LINE_WIDTH_1;
150 nStyle = DOUBLE;
151 break;
152 case 8:
153 n1 = DEF_LINE_WIDTH_2;
154 n2 = DEF_LINE_WIDTH_0;
155 n3 = DEF_LINE_WIDTH_2;
156 nStyle = DOUBLE;
157 break;
158 case 9:
159 n1 = DEF_LINE_WIDTH_2;
160 n2 = DEF_LINE_WIDTH_2;
161 n3 = DEF_LINE_WIDTH_2;
162 nStyle = DOUBLE;
163 break;
164 default:
165 break;
168 editeng::SvxBorderLine aTmp;
169 aTmp.GuessLinesWidths(nStyle, n1, n2, n3);
170 aLineItem.SetLine( &aTmp );
171 mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_FRAME_LINESTYLE, SFX_CALLMODE_RECORD, &aLineItem, 0L);
172 SetAllNoSel();
173 mrCellAppearancePropertyPanel.EndCellLineStylePopupMode();
176 return(0L);
179 IMPL_LINK(CellLineStyleControl, PBClickHdl, PushButton *, pPBtn)
181 if(pPBtn == &maPushButtonMoreOptions)
183 if(mrCellAppearancePropertyPanel.GetBindings())
185 mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_CELL_FORMAT_BORDER, SFX_CALLMODE_ASYNCHRON);
188 mrCellAppearancePropertyPanel.EndCellLineStylePopupMode();
191 return 0;
194 void CellLineStyleControl::SetLineStyleSelect(sal_uInt16 out, sal_uInt16 in, sal_uInt16 dis)
196 SetAllNoSel();
197 mbVSfocus = true;
199 //FIXME: fully for new border line possibilities
201 if(out == DEF_LINE_WIDTH_0 && in == 0 && dis == 0) //1
203 maCellLineStyleValueSet.SetSelItem(1);
205 else if(out == DEF_LINE_WIDTH_2 && in == 0 && dis == 0) //2
207 maCellLineStyleValueSet.SetSelItem(2);
209 else if(out == DEF_LINE_WIDTH_3 && in == 0 && dis == 0) //3
211 maCellLineStyleValueSet.SetSelItem(3);
213 else if(out == DEF_LINE_WIDTH_4 && in == 0 && dis == 0) //4
215 maCellLineStyleValueSet.SetSelItem(4);
217 else if(out == DEF_LINE_WIDTH_0 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_1) //5
219 maCellLineStyleValueSet.SetSelItem(5);
221 else if(out == DEF_LINE_WIDTH_0 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_2) //6
223 maCellLineStyleValueSet.SetSelItem(6);
225 else if(out == DEF_LINE_WIDTH_1 && in == DEF_LINE_WIDTH_2 && dis == DEF_LINE_WIDTH_1) //7
227 maCellLineStyleValueSet.SetSelItem(7);
229 else if(out == DEF_LINE_WIDTH_2 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_2) //8
231 maCellLineStyleValueSet.SetSelItem(8);
233 else if(out == DEF_LINE_WIDTH_2 && in == DEF_LINE_WIDTH_2 && dis == DEF_LINE_WIDTH_2) //9
235 maCellLineStyleValueSet.SetSelItem(9);
237 else
239 maCellLineStyleValueSet.SetSelItem(0);
240 mbVSfocus = false;
243 maCellLineStyleValueSet.Format();
244 maCellLineStyleValueSet.StartSelection();
247 } } // end of namespace svx::sidebar
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */