Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
33 :
34 : namespace sc { namespace sidebar {
35 :
36 0 : CellLineStyleControl::CellLineStyleControl(vcl::Window* pParent, CellAppearancePropertyPanel& rPanel)
37 : : svx::sidebar::PopupControl(pParent, ScResId(RID_POPUPPANEL_APPEARANCE_CELL_LINESTYLE)),
38 : mrCellAppearancePropertyPanel(rPanel),
39 : maPushButtonMoreOptions(VclPtr<PushButton>::Create(this, ScResId(PB_OPTIONS))),
40 : maCellLineStyleValueSet(VclPtr<sc::sidebar::CellLineStyleValueSet>::Create(this, ScResId(VS_STYLE))),
41 0 : mbVSfocus(true)
42 : {
43 0 : Initialize();
44 0 : FreeResource();
45 0 : }
46 :
47 0 : CellLineStyleControl::~CellLineStyleControl()
48 : {
49 0 : disposeOnce();
50 0 : }
51 :
52 0 : void CellLineStyleControl::dispose()
53 : {
54 0 : maPushButtonMoreOptions.disposeAndClear();
55 0 : maCellLineStyleValueSet.disposeAndClear();
56 0 : svx::sidebar::PopupControl::dispose();
57 0 : }
58 :
59 0 : void CellLineStyleControl::Initialize()
60 : {
61 : //maPushButtonMoreOptions->SetIcoPosX(2);
62 0 : Link<> aLink = LINK(this, CellLineStyleControl, PBClickHdl);
63 0 : maPushButtonMoreOptions->SetClickHdl(aLink);
64 :
65 0 : maCellLineStyleValueSet->SetStyle(maCellLineStyleValueSet->GetStyle()| WB_3DLOOK | WB_NO_DIRECTSELECT);
66 0 : maCellLineStyleValueSet->SetControlBackground(GetSettings().GetStyleSettings().GetMenuColor());
67 0 : maCellLineStyleValueSet->SetColor(GetSettings().GetStyleSettings().GetMenuColor());
68 :
69 0 : for(sal_uInt16 i = 1 ; i <= 9 ; i++)
70 : {
71 0 : maCellLineStyleValueSet->InsertItem(i);
72 : }
73 :
74 0 : maStr[0] = GetSettings().GetLocaleI18nHelper().GetNum( 5, 2 ) + "pt";
75 0 : maStr[1] = GetSettings().GetLocaleI18nHelper().GetNum( 250, 2 ) + "pt";
76 0 : maStr[2] = GetSettings().GetLocaleI18nHelper().GetNum( 400, 2 ) + "pt";
77 0 : maStr[3] = GetSettings().GetLocaleI18nHelper().GetNum( 500, 2 ) + "pt";
78 0 : maStr[4] = GetSettings().GetLocaleI18nHelper().GetNum( 110, 2 ) + "pt";
79 0 : maStr[5] = GetSettings().GetLocaleI18nHelper().GetNum( 260, 2 ) + "pt";
80 0 : maStr[6] = GetSettings().GetLocaleI18nHelper().GetNum( 450, 2 ) + "pt";
81 0 : maStr[7] = GetSettings().GetLocaleI18nHelper().GetNum( 505, 2 ) + "pt";
82 0 : maStr[8] = GetSettings().GetLocaleI18nHelper().GetNum( 750, 2 ) + "pt";
83 0 : maCellLineStyleValueSet->SetUnit(&maStr[0]);
84 :
85 0 : for (sal_uInt16 i = 1; i <= CELL_LINE_STYLE_ENTRIES; ++i)
86 : {
87 0 : maCellLineStyleValueSet->SetItemText(i, maStr[i-1]);
88 : }
89 :
90 0 : SetAllNoSel();
91 0 : aLink = LINK(this, CellLineStyleControl, VSSelectHdl);
92 0 : maCellLineStyleValueSet->SetSelectHdl(aLink);
93 0 : maCellLineStyleValueSet->StartSelection();
94 0 : maCellLineStyleValueSet->Show();
95 0 : }
96 :
97 0 : void CellLineStyleControl::GetFocus()
98 : {
99 0 : if(!mbVSfocus)
100 : {
101 0 : maPushButtonMoreOptions->GrabFocus();
102 : }
103 : else
104 : {
105 0 : maCellLineStyleValueSet->GrabFocus();
106 : }
107 0 : }
108 :
109 0 : void CellLineStyleControl::SetAllNoSel()
110 : {
111 0 : maCellLineStyleValueSet->SelectItem(0);
112 0 : maCellLineStyleValueSet->SetNoSelection();
113 0 : maCellLineStyleValueSet->SetFormat();
114 0 : maCellLineStyleValueSet->Invalidate();
115 0 : Invalidate();
116 0 : maCellLineStyleValueSet->StartSelection();
117 0 : }
118 :
119 0 : IMPL_LINK(CellLineStyleControl, VSSelectHdl, void *, pControl)
120 : {
121 0 : if(pControl == maCellLineStyleValueSet.get())
122 : {
123 0 : const sal_uInt16 iPos(maCellLineStyleValueSet->GetSelectItemId());
124 0 : SvxLineItem aLineItem(SID_FRAME_LINESTYLE);
125 : using namespace ::com::sun::star::table::BorderLineStyle;
126 0 : editeng::SvxBorderStyle nStyle = SOLID;
127 0 : sal_uInt16 n1 = 0;
128 0 : sal_uInt16 n2 = 0;
129 0 : sal_uInt16 n3 = 0;
130 :
131 : //FIXME: fully for new border line possibilities
132 :
133 0 : switch(iPos)
134 : {
135 : case 1:
136 0 : n1 = DEF_LINE_WIDTH_0;
137 0 : break;
138 : case 2:
139 0 : n1 = DEF_LINE_WIDTH_2;
140 0 : break;
141 : case 3:
142 0 : n1 = DEF_LINE_WIDTH_3;
143 0 : break;
144 : case 4:
145 0 : n1 = DEF_LINE_WIDTH_4;
146 0 : break;
147 : case 5:
148 0 : n1 = DEF_LINE_WIDTH_0;
149 0 : n2 = DEF_LINE_WIDTH_0;
150 0 : n3 = DEF_LINE_WIDTH_1;
151 0 : nStyle = DOUBLE;
152 0 : break;
153 : case 6:
154 0 : n1 = DEF_LINE_WIDTH_0;
155 0 : n2 = DEF_LINE_WIDTH_0;
156 0 : n3 = DEF_LINE_WIDTH_2;
157 0 : nStyle = DOUBLE;
158 0 : break;
159 : case 7:
160 0 : n1 = DEF_LINE_WIDTH_1;
161 0 : n2 = DEF_LINE_WIDTH_2;
162 0 : n3 = DEF_LINE_WIDTH_1;
163 0 : nStyle = DOUBLE;
164 0 : break;
165 : case 8:
166 0 : n1 = DEF_LINE_WIDTH_2;
167 0 : n2 = DEF_LINE_WIDTH_0;
168 0 : n3 = DEF_LINE_WIDTH_2;
169 0 : nStyle = DOUBLE;
170 0 : break;
171 : case 9:
172 0 : n1 = DEF_LINE_WIDTH_2;
173 0 : n2 = DEF_LINE_WIDTH_2;
174 0 : n3 = DEF_LINE_WIDTH_2;
175 0 : nStyle = DOUBLE;
176 0 : break;
177 : default:
178 0 : break;
179 : }
180 :
181 0 : editeng::SvxBorderLine aTmp;
182 0 : aTmp.GuessLinesWidths(nStyle, n1, n2, n3);
183 0 : aLineItem.SetLine( &aTmp );
184 0 : mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_FRAME_LINESTYLE, SfxCallMode::RECORD, &aLineItem, 0L);
185 0 : SetAllNoSel();
186 0 : mrCellAppearancePropertyPanel.EndCellLineStylePopupMode();
187 : }
188 :
189 0 : return 0L;
190 : }
191 :
192 0 : IMPL_LINK(CellLineStyleControl, PBClickHdl, PushButton *, pPBtn)
193 : {
194 0 : if(pPBtn == maPushButtonMoreOptions.get())
195 : {
196 0 : if(mrCellAppearancePropertyPanel.GetBindings())
197 : {
198 0 : mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_CELL_FORMAT_BORDER, SfxCallMode::ASYNCHRON);
199 : }
200 :
201 0 : mrCellAppearancePropertyPanel.EndCellLineStylePopupMode();
202 : }
203 :
204 0 : return 0;
205 : }
206 :
207 0 : void CellLineStyleControl::SetLineStyleSelect(sal_uInt16 out, sal_uInt16 in, sal_uInt16 dis)
208 : {
209 0 : SetAllNoSel();
210 0 : mbVSfocus = true;
211 :
212 : //FIXME: fully for new border line possibilities
213 :
214 0 : if(out == DEF_LINE_WIDTH_0 && in == 0 && dis == 0) //1
215 : {
216 0 : maCellLineStyleValueSet->SetSelItem(1);
217 : }
218 0 : else if(out == DEF_LINE_WIDTH_2 && in == 0 && dis == 0) //2
219 : {
220 0 : maCellLineStyleValueSet->SetSelItem(2);
221 : }
222 0 : else if(out == DEF_LINE_WIDTH_3 && in == 0 && dis == 0) //3
223 : {
224 0 : maCellLineStyleValueSet->SetSelItem(3);
225 : }
226 0 : else if(out == DEF_LINE_WIDTH_4 && in == 0 && dis == 0) //4
227 : {
228 0 : maCellLineStyleValueSet->SetSelItem(4);
229 : }
230 0 : else if(out == DEF_LINE_WIDTH_0 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_1) //5
231 : {
232 0 : maCellLineStyleValueSet->SetSelItem(5);
233 : }
234 0 : else if(out == DEF_LINE_WIDTH_0 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_2) //6
235 : {
236 0 : maCellLineStyleValueSet->SetSelItem(6);
237 : }
238 0 : else if(out == DEF_LINE_WIDTH_1 && in == DEF_LINE_WIDTH_2 && dis == DEF_LINE_WIDTH_1) //7
239 : {
240 0 : maCellLineStyleValueSet->SetSelItem(7);
241 : }
242 0 : else if(out == DEF_LINE_WIDTH_2 && in == DEF_LINE_WIDTH_0 && dis == DEF_LINE_WIDTH_2) //8
243 : {
244 0 : maCellLineStyleValueSet->SetSelItem(8);
245 : }
246 0 : else if(out == DEF_LINE_WIDTH_2 && in == DEF_LINE_WIDTH_2 && dis == DEF_LINE_WIDTH_2) //9
247 : {
248 0 : maCellLineStyleValueSet->SetSelItem(9);
249 : }
250 : else
251 : {
252 0 : maCellLineStyleValueSet->SetSelItem(0);
253 0 : mbVSfocus = false;
254 : }
255 0 : maCellLineStyleValueSet->SetFormat();
256 0 : maCellLineStyleValueSet->Invalidate();
257 0 : maCellLineStyleValueSet->StartSelection();
258 0 : }
259 :
260 156 : } } // end of namespace svx::sidebar
261 :
262 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|