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