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