Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : *
8 : * This file incorporates work covered by the following license notice:
9 : *
10 : * Licensed to the Apache Software Foundation (ASF) under one or more
11 : * contributor license agreements. See the NOTICE file distributed
12 : * with this work for additional information regarding copyright
13 : * ownership. The ASF licenses this file to you under the Apache
14 : * License, Version 2.0 (the "License"); you may not use this file
15 : * except in compliance with the License. You may obtain a copy of
16 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 : */
18 :
19 : #include <CellLineStyleControl.hxx>
20 : #include "sc.hrc"
21 : #include "scresid.hxx"
22 : #include <CellAppearancePropertyPanel.hrc>
23 : #include <CellLineStyleValueSet.hxx>
24 : #include <vcl/i18nhelp.hxx>
25 : #include <editeng/boxitem.hxx>
26 : #include <editeng/borderline.hxx>
27 : #include <editeng/lineitem.hxx>
28 : #include <CellAppearancePropertyPanel.hxx>
29 : #include <sfx2/bindings.hxx>
30 : #include <sfx2/dispatch.hxx>
31 :
32 : namespace sc { namespace sidebar {
33 :
34 0 : CellLineStyleControl::CellLineStyleControl(Window* pParent, CellAppearancePropertyPanel& rPanel)
35 : : svx::sidebar::PopupControl(pParent, ScResId(RID_POPUPPANEL_APPEARANCE_CELL_LINESTYLE)),
36 : mrCellAppearancePropertyPanel(rPanel),
37 : maPushButtonMoreOptions(this, ScResId(PB_OPTIONS)),
38 : maCellLineStyleValueSet(this, ScResId(VS_STYLE)),
39 : mpStr(0),
40 0 : mbVSfocus(true)
41 : {
42 0 : Initialize();
43 0 : FreeResource();
44 0 : }
45 :
46 0 : CellLineStyleControl::~CellLineStyleControl(void)
47 : {
48 0 : delete[] mpStr;
49 0 : }
50 :
51 0 : void CellLineStyleControl::Initialize()
52 : {
53 : //maPushButtonMoreOptions.SetIcoPosX(2);
54 0 : Link aLink = LINK(this, CellLineStyleControl, PBClickHdl);
55 0 : maPushButtonMoreOptions.SetClickHdl(aLink);
56 :
57 0 : maCellLineStyleValueSet.SetStyle(maCellLineStyleValueSet.GetStyle()| WB_3DLOOK | WB_NO_DIRECTSELECT);
58 0 : maCellLineStyleValueSet.SetControlBackground(GetSettings().GetStyleSettings().GetMenuColor());
59 0 : maCellLineStyleValueSet.SetColor(GetSettings().GetStyleSettings().GetMenuColor());
60 :
61 0 : for(sal_uInt16 i = 1 ; i <= 9 ; i++)
62 : {
63 0 : maCellLineStyleValueSet.InsertItem(i);
64 : }
65 :
66 0 : mpStr = new XubString[9];
67 0 : mpStr[0] = GetSettings().GetLocaleI18nHelper().GetNum( 5, 2 ).AppendAscii("pt");
68 0 : mpStr[1] = GetSettings().GetLocaleI18nHelper().GetNum( 250, 2 ).AppendAscii("pt");
69 0 : mpStr[2] = GetSettings().GetLocaleI18nHelper().GetNum( 400, 2 ).AppendAscii("pt");
70 0 : mpStr[3] = GetSettings().GetLocaleI18nHelper().GetNum( 500, 2 ).AppendAscii("pt");
71 0 : mpStr[4] = GetSettings().GetLocaleI18nHelper().GetNum( 110, 2 ).AppendAscii("pt");
72 0 : mpStr[5] = GetSettings().GetLocaleI18nHelper().GetNum( 260, 2 ).AppendAscii("pt");
73 0 : mpStr[6] = GetSettings().GetLocaleI18nHelper().GetNum( 450, 2 ).AppendAscii("pt");
74 0 : mpStr[7] = GetSettings().GetLocaleI18nHelper().GetNum( 505, 2 ).AppendAscii("pt");
75 0 : mpStr[8] = GetSettings().GetLocaleI18nHelper().GetNum( 750, 2 ).AppendAscii("pt");
76 0 : maCellLineStyleValueSet.SetUnit(mpStr);
77 :
78 0 : for(sal_uInt16 i = 1 ; i <= 9 ; i++)
79 : {
80 0 : maCellLineStyleValueSet.SetItemText(i, mpStr[i-1]);
81 : }
82 :
83 0 : SetAllNoSel();
84 0 : aLink = LINK(this, CellLineStyleControl, VSSelectHdl);
85 0 : maCellLineStyleValueSet.SetSelectHdl(aLink);
86 0 : maCellLineStyleValueSet.StartSelection();
87 0 : maCellLineStyleValueSet.Show();
88 0 : }
89 :
90 0 : void CellLineStyleControl::GetFocus()
91 : {
92 0 : if(!mbVSfocus)
93 : {
94 0 : maPushButtonMoreOptions.GrabFocus();
95 : }
96 : else
97 : {
98 0 : maCellLineStyleValueSet.GrabFocus();
99 : }
100 0 : }
101 :
102 0 : void CellLineStyleControl::SetAllNoSel()
103 : {
104 0 : maCellLineStyleValueSet.SelectItem(0);
105 0 : maCellLineStyleValueSet.SetNoSelection();
106 0 : maCellLineStyleValueSet.Format();
107 0 : Invalidate();
108 0 : maCellLineStyleValueSet.StartSelection();
109 0 : }
110 :
111 0 : IMPL_LINK(CellLineStyleControl, VSSelectHdl, void *, pControl)
112 : {
113 0 : if(pControl == &maCellLineStyleValueSet)
114 : {
115 0 : const sal_uInt16 iPos(maCellLineStyleValueSet.GetSelectItemId());
116 0 : SvxLineItem aLineItem(SID_FRAME_LINESTYLE);
117 : using namespace ::com::sun::star::table::BorderLineStyle;
118 0 : editeng::SvxBorderStyle nStyle = SOLID;
119 0 : sal_uInt16 n1 = 0;
120 0 : sal_uInt16 n2 = 0;
121 0 : sal_uInt16 n3 = 0;
122 :
123 : //FIXME: fully for new border line possibilities
124 :
125 0 : switch(iPos)
126 : {
127 : case 1:
128 0 : n1 = DEF_LINE_WIDTH_0;
129 0 : break;
130 : case 2:
131 0 : n1 = DEF_LINE_WIDTH_2;
132 0 : break;
133 : case 3:
134 0 : n1 = DEF_LINE_WIDTH_3;
135 0 : break;
136 : case 4:
137 0 : n1 = DEF_LINE_WIDTH_4;
138 0 : break;
139 : case 5:
140 0 : n1 = DEF_LINE_WIDTH_0;
141 0 : n2 = DEF_LINE_WIDTH_0;
142 0 : n3 = DEF_LINE_WIDTH_1;
143 0 : nStyle = DOUBLE;
144 0 : break;
145 : case 6:
146 0 : n1 = DEF_LINE_WIDTH_0;
147 0 : n2 = DEF_LINE_WIDTH_0;
148 0 : n3 = DEF_LINE_WIDTH_2;
149 0 : nStyle = DOUBLE;
150 0 : break;
151 : case 7:
152 0 : n1 = DEF_LINE_WIDTH_1;
153 0 : n2 = DEF_LINE_WIDTH_2;
154 0 : n3 = DEF_LINE_WIDTH_1;
155 0 : nStyle = DOUBLE;
156 0 : break;
157 : case 8:
158 0 : n1 = DEF_LINE_WIDTH_2;
159 0 : n2 = DEF_LINE_WIDTH_0;
160 0 : n3 = DEF_LINE_WIDTH_2;
161 0 : nStyle = DOUBLE;
162 0 : break;
163 : case 9:
164 0 : n1 = DEF_LINE_WIDTH_2;
165 0 : n2 = DEF_LINE_WIDTH_2;
166 0 : n3 = DEF_LINE_WIDTH_2;
167 0 : nStyle = DOUBLE;
168 0 : break;
169 : default:
170 0 : break;
171 : }
172 :
173 0 : editeng::SvxBorderLine aTmp;
174 0 : aTmp.GuessLinesWidths(nStyle, n1, n2, n3);
175 0 : aLineItem.SetLine( &aTmp );
176 0 : mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_FRAME_LINESTYLE, SFX_CALLMODE_RECORD, &aLineItem, 0L);
177 0 : SetAllNoSel();
178 0 : mrCellAppearancePropertyPanel.EndCellLineStylePopupMode();
179 : }
180 :
181 0 : return(0L);
182 : }
183 :
184 0 : IMPL_LINK(CellLineStyleControl, PBClickHdl, PushButton *, pPBtn)
185 : {
186 0 : if(pPBtn == &maPushButtonMoreOptions)
187 : {
188 0 : if(mrCellAppearancePropertyPanel.GetBindings())
189 : {
190 0 : mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_CELL_FORMAT_BORDER, SFX_CALLMODE_ASYNCHRON);
191 : }
192 :
193 0 : mrCellAppearancePropertyPanel.EndCellLineStylePopupMode();
194 : }
195 :
196 0 : return 0;
197 : }
198 :
199 0 : void CellLineStyleControl::SetLineStyleSelect(sal_uInt16 out, sal_uInt16 in, sal_uInt16 dis)
200 : {
201 0 : SetAllNoSel();
202 0 : mbVSfocus = true;
203 :
204 : //FIXME: fully for new border line possibilities
205 :
206 0 : if(out == DEF_LINE_WIDTH_0 && in == 0 && dis == 0) //1
207 : {
208 0 : maCellLineStyleValueSet.SetSelItem(1);
209 : }
210 0 : else if(out == DEF_LINE_WIDTH_2 && in == 0 && dis == 0) //2
211 : {
212 0 : maCellLineStyleValueSet.SetSelItem(2);
213 : }
214 0 : else if(out == DEF_LINE_WIDTH_3 && in == 0 && dis == 0) //3
215 : {
216 0 : maCellLineStyleValueSet.SetSelItem(3);
217 : }
218 0 : else if(out == DEF_LINE_WIDTH_4 && in == 0 && dis == 0) //4
219 : {
220 0 : maCellLineStyleValueSet.SetSelItem(4);
221 : }
222 0 : else if(out == DEF_LINE_WIDTH_0 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_1) //5
223 : {
224 0 : maCellLineStyleValueSet.SetSelItem(5);
225 : }
226 0 : else if(out == DEF_LINE_WIDTH_0 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_2) //6
227 : {
228 0 : maCellLineStyleValueSet.SetSelItem(6);
229 : }
230 0 : else if(out == DEF_LINE_WIDTH_1 && in == DEF_LINE_WIDTH_2 && dis == DEF_LINE_WIDTH_1) //7
231 : {
232 0 : maCellLineStyleValueSet.SetSelItem(7);
233 : }
234 0 : else if(out == DEF_LINE_WIDTH_2 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_2) //8
235 : {
236 0 : maCellLineStyleValueSet.SetSelItem(8);
237 : }
238 0 : else if(out == DEF_LINE_WIDTH_2 && in == DEF_LINE_WIDTH_2 && dis == DEF_LINE_WIDTH_2) //9
239 : {
240 0 : maCellLineStyleValueSet.SetSelItem(9);
241 : }
242 : else
243 : {
244 0 : maCellLineStyleValueSet.SetSelItem(0);
245 0 : mbVSfocus = false;
246 : }
247 :
248 0 : maCellLineStyleValueSet.Format();
249 0 : maCellLineStyleValueSet.StartSelection();
250 0 : }
251 :
252 93 : } } // end of namespace svx::sidebar
253 :
254 : // eof
|