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 <CellBorderStyleControl.hxx>
21 : #include "sc.hrc"
22 : #include "scresid.hxx"
23 : #include <CellAppearancePropertyPanel.hrc>
24 : #include <editeng/boxitem.hxx>
25 : #include <editeng/borderline.hxx>
26 : #include <CellAppearancePropertyPanel.hxx>
27 : #include <sfx2/bindings.hxx>
28 : #include <sfx2/dispatch.hxx>
29 : #include <vcl/svapp.hxx>
30 : #include <vcl/settings.hxx>
31 : #include <editeng/lineitem.hxx>
32 :
33 : namespace sc { namespace sidebar {
34 :
35 : #define FRM_VALID_LEFT 0x01
36 : #define FRM_VALID_RIGHT 0x02
37 : #define FRM_VALID_TOP 0x04
38 : #define FRM_VALID_BOTTOM 0x08
39 : #define FRM_VALID_HINNER 0x10
40 : #define FRM_VALID_VINNER 0x20
41 : #define FRM_VALID_OUTER 0x0f
42 : #define FRM_VALID_ALL 0xff
43 :
44 0 : CellBorderStyleControl::CellBorderStyleControl(Window* pParent, CellAppearancePropertyPanel& rPanel)
45 : : svx::sidebar::PopupControl(pParent, ScResId(RID_POPUPPANEL_APPEARANCE_CELL_BORDERSTYLE)),
46 : mrCellAppearancePropertyPanel(rPanel),
47 : maTBBorder1(this, ScResId(TB_BORDER1)),
48 : maTBBorder2(this, ScResId(TB_BORDER2)),
49 : maTBBorder3(this, ScResId(TB_BORDER3)),
50 : maFL1(this, ScResId(FL_1)),
51 : maFL2(this, ScResId(FL_2)),
52 0 : mpImageList(0)
53 : {
54 0 : Initialize();
55 0 : FreeResource();
56 0 : }
57 :
58 0 : CellBorderStyleControl::~CellBorderStyleControl(void)
59 : {
60 0 : delete[] mpImageList;
61 0 : }
62 :
63 0 : void CellBorderStyleControl::Initialize()
64 : {
65 0 : mpImageList = new Image[16];
66 0 : mpImageList[0] = Image(ScResId(IMG_BORDER1));
67 0 : mpImageList[1] = Image(ScResId(IMG_BORDER2));
68 0 : mpImageList[2] = Image(ScResId(IMG_BORDER3));
69 0 : mpImageList[3] = Image(ScResId(IMG_BORDER4));
70 0 : mpImageList[4] = Image(ScResId(IMG_BORDER5));
71 0 : mpImageList[5] = Image(ScResId(IMG_BORDER6));
72 0 : mpImageList[6] = Image(ScResId(IMG_BORDER7));
73 0 : mpImageList[7] = Image(ScResId(IMG_BORDER8));
74 0 : mpImageList[8] = Image(ScResId(IMG_BORDER9));
75 0 : mpImageList[9] = Image(ScResId(IMG_BORDER10));
76 0 : mpImageList[10] = Image(ScResId(IMG_BORDER11));
77 0 : mpImageList[11] = Image(ScResId(IMG_BORDER12));
78 0 : mpImageList[12] = Image(ScResId(IMG_BORDER13));
79 0 : mpImageList[13] = Image(ScResId(IMG_BORDER14));
80 0 : mpImageList[14] = Image(ScResId(IMG_BORDER15));
81 0 : mpImageList[15] = Image(ScResId(IMG_BORDER16));
82 :
83 0 : maTBBorder1.SetItemImage(TBI_BORDER1_NONE, mpImageList[0]);
84 0 : maTBBorder1.SetItemImage(TBI_BORDER1_ALL, mpImageList[1]);
85 0 : maTBBorder1.SetItemImage(TBI_BORDER1_OUTER, mpImageList[2]);
86 0 : maTBBorder1.SetItemImage(TBI_BORDER1_OUTERBOLD, mpImageList[3]);
87 0 : maTBBorder1.SetBackground(Wallpaper());
88 0 : maTBBorder1.SetPaintTransparent(true);
89 0 : Size aTbxSize( maTBBorder1.CalcWindowSizePixel() );
90 0 : maTBBorder1.SetOutputSizePixel( aTbxSize );
91 0 : Link aLink = LINK(this, CellBorderStyleControl, TB1SelectHdl);
92 0 : maTBBorder1.SetSelectHdl ( aLink );
93 :
94 0 : maTBBorder2.SetLineCount(2);
95 0 : maTBBorder2.InsertItem(TBI_BORDER2_LEFT, mpImageList[4]);
96 0 : maTBBorder2.InsertItem(TBI_BORDER2_RIGHT, mpImageList[5]);
97 0 : maTBBorder2.InsertItem(TBI_BORDER2_TOP, mpImageList[6]);
98 0 : maTBBorder2.InsertItem(TBI_BORDER2_BOT, mpImageList[7]);
99 0 : maTBBorder2.InsertBreak();
100 0 : maTBBorder2.InsertItem(TBI_BORDER2_BLTR, mpImageList[8]);
101 0 : maTBBorder2.InsertItem(TBI_BORDER2_TLBR, mpImageList[9]);
102 0 : maTBBorder2.InsertItem(TBI_BORDER2_TOPBOT, mpImageList[10]);
103 0 : maTBBorder2.InsertItem(TBI_BORDER2_LEFTRIGHT, mpImageList[11]);
104 0 : maTBBorder2.SetBackground(Wallpaper());
105 0 : maTBBorder2.SetPaintTransparent(true);
106 0 : aTbxSize = maTBBorder2.CalcWindowSizePixel() ;
107 0 : maTBBorder2.SetOutputSizePixel( aTbxSize );
108 0 : maTBBorder2.SetHelpId(TBI_BORDER2_LEFT, HID_PROPERTYPANEL_SC_BORDER_TBI_LEFT);
109 0 : maTBBorder2.SetHelpId(TBI_BORDER2_RIGHT, HID_PROPERTYPANEL_SC_BORDER_TBI_RIGHT);
110 0 : maTBBorder2.SetHelpId(TBI_BORDER2_TOP, HID_PROPERTYPANEL_SC_BORDER_TBI_TOP);
111 0 : maTBBorder2.SetHelpId(TBI_BORDER2_BOT, HID_PROPERTYPANEL_SC_BORDER_TBI_BOT);
112 0 : maTBBorder2.SetHelpId(TBI_BORDER2_BLTR, HID_PROPERTYPANEL_SC_BORDER_TBI_BLTR);
113 0 : maTBBorder2.SetHelpId(TBI_BORDER2_TLBR, HID_PROPERTYPANEL_SC_BORDER_TBI_TLBR);
114 0 : maTBBorder2.SetHelpId(TBI_BORDER2_TOPBOT, HID_PROPERTYPANEL_SC_BORDER_TBI_TOPBOT);
115 0 : maTBBorder2.SetHelpId(TBI_BORDER2_LEFTRIGHT, HID_PROPERTYPANEL_SC_BORDER_TBI_LEFTRIGHT);
116 0 : maTBBorder2.SetItemText(TBI_BORDER2_LEFT, ScResId(STR_BORDER_1));
117 0 : maTBBorder2.SetItemText(TBI_BORDER2_RIGHT, ScResId(STR_BORDER_2));
118 0 : maTBBorder2.SetItemText(TBI_BORDER2_TOP, ScResId(STR_BORDER_3));
119 0 : maTBBorder2.SetItemText(TBI_BORDER2_BOT, ScResId(STR_BORDER_4));
120 0 : maTBBorder2.SetItemText(TBI_BORDER2_BLTR, ScResId(STR_BORDER_5));
121 0 : maTBBorder2.SetItemText(TBI_BORDER2_TLBR, ScResId(STR_BORDER_6));
122 0 : maTBBorder2.SetItemText(TBI_BORDER2_TOPBOT, ScResId(STR_BORDER_7));
123 0 : maTBBorder2.SetItemText(TBI_BORDER2_LEFTRIGHT, ScResId(STR_BORDER_8));
124 0 : aLink = LINK(this, CellBorderStyleControl, TB2SelectHdl);
125 0 : maTBBorder2.SetSelectHdl ( aLink );
126 :
127 0 : maTBBorder3.SetItemImage(TBI_BORDER3_S1, mpImageList[12]);
128 0 : maTBBorder3.SetItemImage(TBI_BORDER3_S2, mpImageList[13]);
129 0 : maTBBorder3.SetItemImage(TBI_BORDER3_S3, mpImageList[14]);
130 0 : maTBBorder3.SetItemImage(TBI_BORDER3_S4, mpImageList[15]);
131 0 : maTBBorder3.SetBackground(Wallpaper());
132 0 : maTBBorder3.SetPaintTransparent(true);
133 0 : aTbxSize = maTBBorder3.CalcWindowSizePixel() ;
134 0 : maTBBorder3.SetOutputSizePixel( aTbxSize );
135 0 : aLink = LINK(this, CellBorderStyleControl, TB3SelectHdl);
136 0 : maTBBorder3.SetSelectHdl ( aLink );
137 0 : }
138 :
139 0 : IMPL_LINK(CellBorderStyleControl, TB1SelectHdl, ToolBox*, pToolBox)
140 : {
141 0 : sal_uInt16 nId = pToolBox->GetCurItemId();
142 0 : SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER );
143 0 : SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER );
144 0 : editeng::SvxBorderLine theDefLine(NULL, 1);
145 0 : editeng::SvxBorderLine *pLeft = 0, *pRight = 0, *pTop = 0, *pBottom = 0;
146 0 : sal_uInt8 nValidFlags = 0;
147 0 : switch ( nId )
148 : {
149 : case TBI_BORDER1_NONE:
150 : {
151 0 : nValidFlags |= FRM_VALID_ALL;
152 0 : SvxLineItem aLineItem1( SID_ATTR_BORDER_DIAG_BLTR );
153 0 : SvxLineItem aLineItem2( SID_ATTR_BORDER_DIAG_TLBR );
154 0 : aLineItem1.SetLine( NULL ); //modify
155 0 : aLineItem2.SetLine( NULL ); //modify
156 0 : mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_BLTR, SFX_CALLMODE_RECORD, &aLineItem1, 0L);
157 0 : mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_TLBR, SFX_CALLMODE_RECORD, &aLineItem2, 0L);
158 : }
159 0 : break;
160 : case TBI_BORDER1_ALL:
161 0 : pLeft = pRight = pTop = pBottom = &theDefLine;
162 0 : aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_HORI );
163 0 : aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_VERT );
164 0 : nValidFlags |= FRM_VALID_ALL;
165 0 : break;
166 : case TBI_BORDER1_OUTER:
167 0 : pLeft = pRight = pTop = pBottom = &theDefLine;
168 0 : nValidFlags |= FRM_VALID_OUTER;
169 0 : break;
170 : case TBI_BORDER1_OUTERBOLD:
171 0 : theDefLine.SetWidth(DEF_LINE_WIDTH_2);
172 0 : pLeft = pRight = pTop = pBottom = &theDefLine;
173 0 : nValidFlags |= FRM_VALID_OUTER;
174 0 : break;
175 : }
176 :
177 0 : aBorderOuter.SetLine( pLeft, BOX_LINE_LEFT );
178 0 : aBorderOuter.SetLine( pRight, BOX_LINE_RIGHT );
179 0 : aBorderOuter.SetLine( pTop, BOX_LINE_TOP );
180 0 : aBorderOuter.SetLine( pBottom, BOX_LINE_BOTTOM );
181 :
182 0 : aBorderInner.SetValid( VALID_TOP, 0 != (nValidFlags&FRM_VALID_TOP ));
183 0 : aBorderInner.SetValid( VALID_BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM ));
184 0 : aBorderInner.SetValid( VALID_LEFT, 0 != (nValidFlags&FRM_VALID_LEFT));
185 0 : aBorderInner.SetValid( VALID_RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT ));
186 0 : aBorderInner.SetValid( VALID_HORI, 0 != (nValidFlags&FRM_VALID_HINNER ));
187 0 : aBorderInner.SetValid( VALID_VERT, 0 != (nValidFlags&FRM_VALID_VINNER));
188 0 : aBorderInner.SetValid( VALID_DISTANCE, true );
189 0 : aBorderInner.SetValid( VALID_DISABLE, false );
190 :
191 0 : mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER, SFX_CALLMODE_RECORD, &aBorderOuter, &aBorderInner, 0L);
192 0 : mrCellAppearancePropertyPanel.EndCellBorderStylePopupMode();
193 0 : return 0;
194 : }
195 :
196 0 : IMPL_LINK(CellBorderStyleControl, TB2SelectHdl, ToolBox *, pToolBox)
197 : {
198 0 : sal_uInt16 nId = pToolBox->GetCurItemId();
199 :
200 0 : if( nId != TBI_BORDER2_BLTR && nId != TBI_BORDER2_TLBR )
201 : {
202 0 : SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER );
203 0 : SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER );
204 0 : editeng::SvxBorderLine theDefLine(NULL, 1);
205 0 : editeng::SvxBorderLine *pLeft = 0,
206 0 : *pRight = 0,
207 0 : *pTop = 0,
208 0 : *pBottom = 0;
209 0 : sal_uInt8 nValidFlags = 0;
210 0 : switch ( nId )
211 : {
212 : case TBI_BORDER2_LEFT:
213 0 : pLeft = &theDefLine;
214 0 : nValidFlags |= FRM_VALID_LEFT;
215 0 : break;
216 : case TBI_BORDER2_RIGHT:
217 :
218 0 : if(!Application::GetSettings().GetLayoutRTL())
219 : {
220 0 : pRight = &theDefLine;
221 0 : nValidFlags |= FRM_VALID_RIGHT;
222 : }
223 : else
224 : {
225 0 : pLeft = &theDefLine;
226 0 : nValidFlags |= FRM_VALID_LEFT;
227 : }
228 0 : break;
229 : case TBI_BORDER2_TOP:
230 0 : pTop = &theDefLine;
231 0 : nValidFlags |= FRM_VALID_TOP;
232 0 : break;
233 : case TBI_BORDER2_BOT:
234 0 : pBottom = &theDefLine;
235 0 : nValidFlags |= FRM_VALID_BOTTOM;
236 0 : break;
237 : case TBI_BORDER2_TOPBOT:
238 0 : pTop = pBottom = &theDefLine;
239 0 : nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
240 0 : break;
241 : case TBI_BORDER2_LEFTRIGHT:
242 0 : pLeft = pRight = &theDefLine;
243 0 : nValidFlags |= FRM_VALID_RIGHT|FRM_VALID_LEFT;
244 0 : break;
245 : }
246 0 : aBorderOuter.SetLine( pLeft, BOX_LINE_LEFT );
247 0 : aBorderOuter.SetLine( pRight, BOX_LINE_RIGHT );
248 0 : aBorderOuter.SetLine( pTop, BOX_LINE_TOP );
249 0 : aBorderOuter.SetLine( pBottom, BOX_LINE_BOTTOM );
250 :
251 0 : aBorderInner.SetValid( VALID_TOP, 0 != (nValidFlags&FRM_VALID_TOP ));
252 0 : aBorderInner.SetValid( VALID_BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM ));
253 0 : aBorderInner.SetValid( VALID_LEFT, 0 != (nValidFlags&FRM_VALID_LEFT));
254 0 : aBorderInner.SetValid( VALID_RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT ));
255 0 : aBorderInner.SetValid( VALID_HORI, 0 != (nValidFlags&FRM_VALID_HINNER ));
256 0 : aBorderInner.SetValid( VALID_VERT, 0 != (nValidFlags&FRM_VALID_VINNER));
257 0 : aBorderInner.SetValid( VALID_DISTANCE, true );
258 0 : aBorderInner.SetValid( VALID_DISABLE, false );
259 :
260 0 : mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER, SFX_CALLMODE_RECORD, &aBorderOuter, &aBorderInner, 0L);
261 : }
262 0 : else if(nId == TBI_BORDER2_BLTR)
263 : {
264 0 : editeng::SvxBorderLine aTmp( NULL, 1 );
265 0 : SvxLineItem aLineItem( SID_ATTR_BORDER_DIAG_BLTR );
266 0 : aLineItem.SetLine( &aTmp );
267 0 : mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_BLTR, SFX_CALLMODE_RECORD, &aLineItem, 0L);
268 : }
269 0 : else if(nId == TBI_BORDER2_TLBR)
270 : {
271 0 : editeng::SvxBorderLine aTmp( NULL, 1 );
272 0 : SvxLineItem aLineItem( SID_ATTR_BORDER_DIAG_TLBR );
273 0 : aLineItem.SetLine( &aTmp );
274 0 : mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_TLBR, SFX_CALLMODE_RECORD, &aLineItem, 0L);
275 : }
276 :
277 0 : mrCellAppearancePropertyPanel.EndCellBorderStylePopupMode();
278 0 : return 0;
279 : }
280 :
281 0 : IMPL_LINK(CellBorderStyleControl, TB3SelectHdl, ToolBox *, pToolBox)
282 : {
283 0 : sal_uInt16 nId = pToolBox->GetCurItemId();
284 :
285 0 : SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER );
286 0 : SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER );
287 0 : editeng::SvxBorderLine *pTop = 0 ,
288 0 : *pBottom = 0 ;
289 0 : sal_uInt8 nValidFlags = 0;
290 : using namespace ::com::sun::star::table::BorderLineStyle;
291 :
292 : //FIXME: properly adapt to new line border model
293 :
294 0 : switch ( nId )
295 : {
296 : case TBI_BORDER3_S1:
297 0 : pBottom = new editeng::SvxBorderLine(NULL, DEF_LINE_WIDTH_2 );
298 0 : nValidFlags |= FRM_VALID_BOTTOM;
299 0 : break;
300 : case TBI_BORDER3_S2:
301 0 : pBottom = new editeng::SvxBorderLine(NULL);
302 0 : pBottom->GuessLinesWidths(DOUBLE, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_1);
303 0 : nValidFlags |= FRM_VALID_BOTTOM;
304 0 : break;
305 : case TBI_BORDER3_S3:
306 0 : pBottom = new editeng::SvxBorderLine(NULL, DEF_LINE_WIDTH_2 );
307 0 : pTop = new editeng::SvxBorderLine(NULL, 1);
308 0 : nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
309 0 : break;
310 : case TBI_BORDER3_S4:
311 0 : pBottom = new editeng::SvxBorderLine(NULL);
312 0 : pBottom->GuessLinesWidths(DOUBLE, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_1);
313 0 : pTop = new editeng::SvxBorderLine(NULL, 1);
314 0 : nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
315 0 : break;
316 : }
317 :
318 0 : aBorderOuter.SetLine( pTop, BOX_LINE_TOP );
319 0 : aBorderOuter.SetLine( pBottom, BOX_LINE_BOTTOM );
320 0 : aBorderOuter.SetLine( NULL, BOX_LINE_LEFT );
321 0 : aBorderOuter.SetLine( NULL, BOX_LINE_RIGHT );
322 :
323 0 : aBorderInner.SetValid( VALID_TOP, 0 != (nValidFlags&FRM_VALID_TOP ));
324 0 : aBorderInner.SetValid( VALID_BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM ));
325 0 : aBorderInner.SetValid( VALID_LEFT, 0 != (nValidFlags&FRM_VALID_LEFT ));
326 0 : aBorderInner.SetValid( VALID_RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT ));
327 0 : aBorderInner.SetValid( VALID_HORI, 0 != (nValidFlags&FRM_VALID_HINNER ));
328 0 : aBorderInner.SetValid( VALID_VERT, 0 != (nValidFlags&FRM_VALID_VINNER));
329 0 : aBorderInner.SetValid( VALID_DISTANCE, true );
330 0 : aBorderInner.SetValid( VALID_DISABLE, false );
331 :
332 0 : mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER, SFX_CALLMODE_RECORD, &aBorderOuter, &aBorderInner, 0L);
333 :
334 0 : delete pTop;
335 0 : delete pBottom;
336 :
337 0 : mrCellAppearancePropertyPanel.EndCellBorderStylePopupMode();
338 0 : return 0;
339 : }
340 :
341 : } } // end of namespace svx::sidebar
342 :
343 : // eof
344 :
345 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|