1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "CellBorderStyleControl.hxx"
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>
34 namespace sc
{ namespace sidebar
{
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
45 CellBorderStyleControl::CellBorderStyleControl(vcl::Window
* pParent
, CellAppearancePropertyPanel
& rPanel
)
46 : svx::sidebar::PopupControl(pParent
, ScResId(RID_POPUPPANEL_APPEARANCE_CELL_BORDERSTYLE
)),
47 mrCellAppearancePropertyPanel(rPanel
),
48 maTBBorder1(VclPtr
<ToolBox
>::Create(this, ScResId(TB_BORDER1
))),
49 maTBBorder2(VclPtr
<ToolBox
>::Create(this, ScResId(TB_BORDER2
))),
50 maTBBorder3(VclPtr
<ToolBox
>::Create(this, ScResId(TB_BORDER3
))),
51 maFL1(VclPtr
<FixedLine
>::Create(this, ScResId(FL_1
))),
52 maFL2(VclPtr
<FixedLine
>::Create(this, ScResId(FL_2
))),
59 CellBorderStyleControl::~CellBorderStyleControl()
64 void CellBorderStyleControl::dispose()
67 maTBBorder1
.disposeAndClear();
68 maTBBorder2
.disposeAndClear();
69 maTBBorder3
.disposeAndClear();
70 maFL1
.disposeAndClear();
71 maFL2
.disposeAndClear();
72 svx::sidebar::PopupControl::dispose();
75 void CellBorderStyleControl::Initialize()
77 mpImageList
= new Image
[16];
78 mpImageList
[0] = Image(ScResId(IMG_BORDER1
));
79 mpImageList
[1] = Image(ScResId(IMG_BORDER2
));
80 mpImageList
[2] = Image(ScResId(IMG_BORDER3
));
81 mpImageList
[3] = Image(ScResId(IMG_BORDER4
));
82 mpImageList
[4] = Image(ScResId(IMG_BORDER5
));
83 mpImageList
[5] = Image(ScResId(IMG_BORDER6
));
84 mpImageList
[6] = Image(ScResId(IMG_BORDER7
));
85 mpImageList
[7] = Image(ScResId(IMG_BORDER8
));
86 mpImageList
[8] = Image(ScResId(IMG_BORDER9
));
87 mpImageList
[9] = Image(ScResId(IMG_BORDER10
));
88 mpImageList
[10] = Image(ScResId(IMG_BORDER11
));
89 mpImageList
[11] = Image(ScResId(IMG_BORDER12
));
90 mpImageList
[12] = Image(ScResId(IMG_BORDER13
));
91 mpImageList
[13] = Image(ScResId(IMG_BORDER14
));
92 mpImageList
[14] = Image(ScResId(IMG_BORDER15
));
93 mpImageList
[15] = Image(ScResId(IMG_BORDER16
));
95 maTBBorder1
->SetItemImage(TBI_BORDER1_NONE
, mpImageList
[0]);
96 maTBBorder1
->SetItemImage(TBI_BORDER1_ALL
, mpImageList
[1]);
97 maTBBorder1
->SetItemImage(TBI_BORDER1_OUTER
, mpImageList
[2]);
98 maTBBorder1
->SetItemImage(TBI_BORDER1_OUTERBOLD
, mpImageList
[3]);
99 maTBBorder1
->SetBackground(Wallpaper());
100 maTBBorder1
->SetPaintTransparent(true);
101 Size
aTbxSize( maTBBorder1
->CalcWindowSizePixel() );
102 maTBBorder1
->SetOutputSizePixel( aTbxSize
);
103 maTBBorder1
->SetSelectHdl ( LINK(this, CellBorderStyleControl
, TB1SelectHdl
) );
105 maTBBorder2
->SetLineCount(2);
106 maTBBorder2
->InsertItem(TBI_BORDER2_LEFT
, mpImageList
[4]);
107 maTBBorder2
->InsertItem(TBI_BORDER2_RIGHT
, mpImageList
[5]);
108 maTBBorder2
->InsertItem(TBI_BORDER2_TOP
, mpImageList
[6]);
109 maTBBorder2
->InsertItem(TBI_BORDER2_BOT
, mpImageList
[7]);
110 maTBBorder2
->InsertBreak();
111 maTBBorder2
->InsertItem(TBI_BORDER2_BLTR
, mpImageList
[8]);
112 maTBBorder2
->InsertItem(TBI_BORDER2_TLBR
, mpImageList
[9]);
113 maTBBorder2
->InsertItem(TBI_BORDER2_TOPBOT
, mpImageList
[10]);
114 maTBBorder2
->InsertItem(TBI_BORDER2_LEFTRIGHT
, mpImageList
[11]);
115 maTBBorder2
->SetBackground(Wallpaper());
116 maTBBorder2
->SetPaintTransparent(true);
117 aTbxSize
= maTBBorder2
->CalcWindowSizePixel() ;
118 maTBBorder2
->SetOutputSizePixel( aTbxSize
);
119 maTBBorder2
->SetHelpId(TBI_BORDER2_LEFT
, HID_PROPERTYPANEL_SC_BORDER_TBI_LEFT
);
120 maTBBorder2
->SetHelpId(TBI_BORDER2_RIGHT
, HID_PROPERTYPANEL_SC_BORDER_TBI_RIGHT
);
121 maTBBorder2
->SetHelpId(TBI_BORDER2_TOP
, HID_PROPERTYPANEL_SC_BORDER_TBI_TOP
);
122 maTBBorder2
->SetHelpId(TBI_BORDER2_BOT
, HID_PROPERTYPANEL_SC_BORDER_TBI_BOT
);
123 maTBBorder2
->SetHelpId(TBI_BORDER2_BLTR
, HID_PROPERTYPANEL_SC_BORDER_TBI_BLTR
);
124 maTBBorder2
->SetHelpId(TBI_BORDER2_TLBR
, HID_PROPERTYPANEL_SC_BORDER_TBI_TLBR
);
125 maTBBorder2
->SetHelpId(TBI_BORDER2_TOPBOT
, HID_PROPERTYPANEL_SC_BORDER_TBI_TOPBOT
);
126 maTBBorder2
->SetHelpId(TBI_BORDER2_LEFTRIGHT
, HID_PROPERTYPANEL_SC_BORDER_TBI_LEFTRIGHT
);
127 maTBBorder2
->SetItemText(TBI_BORDER2_LEFT
, ScResId(STR_BORDER_1
));
128 maTBBorder2
->SetItemText(TBI_BORDER2_RIGHT
, ScResId(STR_BORDER_2
));
129 maTBBorder2
->SetItemText(TBI_BORDER2_TOP
, ScResId(STR_BORDER_3
));
130 maTBBorder2
->SetItemText(TBI_BORDER2_BOT
, ScResId(STR_BORDER_4
));
131 maTBBorder2
->SetItemText(TBI_BORDER2_BLTR
, ScResId(STR_BORDER_5
));
132 maTBBorder2
->SetItemText(TBI_BORDER2_TLBR
, ScResId(STR_BORDER_6
));
133 maTBBorder2
->SetItemText(TBI_BORDER2_TOPBOT
, ScResId(STR_BORDER_7
));
134 maTBBorder2
->SetItemText(TBI_BORDER2_LEFTRIGHT
, ScResId(STR_BORDER_8
));
135 maTBBorder2
->SetSelectHdl ( LINK(this, CellBorderStyleControl
, TB2SelectHdl
) );
137 maTBBorder3
->SetItemImage(TBI_BORDER3_S1
, mpImageList
[12]);
138 maTBBorder3
->SetItemImage(TBI_BORDER3_S2
, mpImageList
[13]);
139 maTBBorder3
->SetItemImage(TBI_BORDER3_S3
, mpImageList
[14]);
140 maTBBorder3
->SetItemImage(TBI_BORDER3_S4
, mpImageList
[15]);
141 maTBBorder3
->SetBackground(Wallpaper());
142 maTBBorder3
->SetPaintTransparent(true);
143 aTbxSize
= maTBBorder3
->CalcWindowSizePixel() ;
144 maTBBorder3
->SetOutputSizePixel( aTbxSize
);
145 maTBBorder3
->SetSelectHdl ( LINK(this, CellBorderStyleControl
, TB3SelectHdl
) );
148 IMPL_LINK_TYPED(CellBorderStyleControl
, TB1SelectHdl
, ToolBox
*, pToolBox
, void)
150 sal_uInt16 nId
= pToolBox
->GetCurItemId();
151 SvxBoxItem
aBorderOuter( SID_ATTR_BORDER_OUTER
);
152 SvxBoxInfoItem
aBorderInner( SID_ATTR_BORDER_INNER
);
153 editeng::SvxBorderLine
theDefLine(NULL
, 1);
154 editeng::SvxBorderLine
*pLeft
= 0, *pRight
= 0, *pTop
= 0, *pBottom
= 0;
155 sal_uInt8 nValidFlags
= 0;
158 case TBI_BORDER1_NONE
:
160 nValidFlags
|= FRM_VALID_ALL
;
161 SvxLineItem
aLineItem1( SID_ATTR_BORDER_DIAG_BLTR
);
162 SvxLineItem
aLineItem2( SID_ATTR_BORDER_DIAG_TLBR
);
163 aLineItem1
.SetLine( NULL
); //modify
164 aLineItem2
.SetLine( NULL
); //modify
165 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_BLTR
, SfxCallMode::RECORD
, &aLineItem1
, 0L);
166 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_TLBR
, SfxCallMode::RECORD
, &aLineItem2
, 0L);
169 case TBI_BORDER1_ALL
:
170 pLeft
= pRight
= pTop
= pBottom
= &theDefLine
;
171 aBorderInner
.SetLine( &theDefLine
, SvxBoxInfoItemLine::HORI
);
172 aBorderInner
.SetLine( &theDefLine
, SvxBoxInfoItemLine::VERT
);
173 nValidFlags
|= FRM_VALID_ALL
;
175 case TBI_BORDER1_OUTER
:
176 pLeft
= pRight
= pTop
= pBottom
= &theDefLine
;
177 nValidFlags
|= FRM_VALID_OUTER
;
179 case TBI_BORDER1_OUTERBOLD
:
180 theDefLine
.SetWidth(DEF_LINE_WIDTH_2
);
181 pLeft
= pRight
= pTop
= pBottom
= &theDefLine
;
182 nValidFlags
|= FRM_VALID_OUTER
;
186 aBorderOuter
.SetLine( pLeft
, SvxBoxItemLine::LEFT
);
187 aBorderOuter
.SetLine( pRight
, SvxBoxItemLine::RIGHT
);
188 aBorderOuter
.SetLine( pTop
, SvxBoxItemLine::TOP
);
189 aBorderOuter
.SetLine( pBottom
, SvxBoxItemLine::BOTTOM
);
191 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::TOP
, 0 != (nValidFlags
&FRM_VALID_TOP
));
192 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::BOTTOM
, 0 != (nValidFlags
&FRM_VALID_BOTTOM
));
193 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::LEFT
, 0 != (nValidFlags
&FRM_VALID_LEFT
));
194 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::RIGHT
, 0 != (nValidFlags
&FRM_VALID_RIGHT
));
195 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::HORI
, 0 != (nValidFlags
&FRM_VALID_HINNER
));
196 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::VERT
, 0 != (nValidFlags
&FRM_VALID_VINNER
));
197 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::DISTANCE
, true );
198 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::DISABLE
, false );
200 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER
, SfxCallMode::RECORD
, &aBorderOuter
, &aBorderInner
, 0L);
201 mrCellAppearancePropertyPanel
.EndCellBorderStylePopupMode();
204 IMPL_LINK_TYPED(CellBorderStyleControl
, TB2SelectHdl
, ToolBox
*, pToolBox
, void)
206 sal_uInt16 nId
= pToolBox
->GetCurItemId();
208 if( nId
!= TBI_BORDER2_BLTR
&& nId
!= TBI_BORDER2_TLBR
)
210 SvxBoxItem
aBorderOuter( SID_ATTR_BORDER_OUTER
);
211 SvxBoxInfoItem
aBorderInner( SID_ATTR_BORDER_INNER
);
212 editeng::SvxBorderLine
theDefLine(NULL
, 1);
213 editeng::SvxBorderLine
*pLeft
= 0,
217 sal_uInt8 nValidFlags
= 0;
220 case TBI_BORDER2_LEFT
:
222 nValidFlags
|= FRM_VALID_LEFT
;
224 case TBI_BORDER2_RIGHT
:
226 if(!AllSettings::GetLayoutRTL())
228 pRight
= &theDefLine
;
229 nValidFlags
|= FRM_VALID_RIGHT
;
234 nValidFlags
|= FRM_VALID_LEFT
;
237 case TBI_BORDER2_TOP
:
239 nValidFlags
|= FRM_VALID_TOP
;
241 case TBI_BORDER2_BOT
:
242 pBottom
= &theDefLine
;
243 nValidFlags
|= FRM_VALID_BOTTOM
;
245 case TBI_BORDER2_TOPBOT
:
246 pTop
= pBottom
= &theDefLine
;
247 nValidFlags
|= FRM_VALID_BOTTOM
|FRM_VALID_TOP
;
249 case TBI_BORDER2_LEFTRIGHT
:
250 pLeft
= pRight
= &theDefLine
;
251 nValidFlags
|= FRM_VALID_RIGHT
|FRM_VALID_LEFT
;
254 aBorderOuter
.SetLine( pLeft
, SvxBoxItemLine::LEFT
);
255 aBorderOuter
.SetLine( pRight
, SvxBoxItemLine::RIGHT
);
256 aBorderOuter
.SetLine( pTop
, SvxBoxItemLine::TOP
);
257 aBorderOuter
.SetLine( pBottom
, SvxBoxItemLine::BOTTOM
);
259 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::TOP
, 0 != (nValidFlags
&FRM_VALID_TOP
));
260 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::BOTTOM
, 0 != (nValidFlags
&FRM_VALID_BOTTOM
));
261 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::LEFT
, 0 != (nValidFlags
&FRM_VALID_LEFT
));
262 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::RIGHT
, 0 != (nValidFlags
&FRM_VALID_RIGHT
));
263 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::HORI
, 0 != (nValidFlags
&FRM_VALID_HINNER
));
264 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::VERT
, 0 != (nValidFlags
&FRM_VALID_VINNER
));
265 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::DISTANCE
, true );
266 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::DISABLE
, false );
268 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER
, SfxCallMode::RECORD
, &aBorderOuter
, &aBorderInner
, 0L);
270 else if(nId
== TBI_BORDER2_BLTR
)
272 editeng::SvxBorderLine
aTmp( NULL
, 1 );
273 SvxLineItem
aLineItem( SID_ATTR_BORDER_DIAG_BLTR
);
274 aLineItem
.SetLine( &aTmp
);
275 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_BLTR
, SfxCallMode::RECORD
, &aLineItem
, 0L);
277 else if(nId
== TBI_BORDER2_TLBR
)
279 editeng::SvxBorderLine
aTmp( NULL
, 1 );
280 SvxLineItem
aLineItem( SID_ATTR_BORDER_DIAG_TLBR
);
281 aLineItem
.SetLine( &aTmp
);
282 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_TLBR
, SfxCallMode::RECORD
, &aLineItem
, 0L);
285 mrCellAppearancePropertyPanel
.EndCellBorderStylePopupMode();
288 IMPL_LINK_TYPED(CellBorderStyleControl
, TB3SelectHdl
, ToolBox
*, pToolBox
, void)
290 sal_uInt16 nId
= pToolBox
->GetCurItemId();
292 SvxBoxItem
aBorderOuter( SID_ATTR_BORDER_OUTER
);
293 SvxBoxInfoItem
aBorderInner( SID_ATTR_BORDER_INNER
);
294 boost::scoped_ptr
<editeng::SvxBorderLine
> pTop
;
295 boost::scoped_ptr
<editeng::SvxBorderLine
> pBottom
;
296 sal_uInt8 nValidFlags
= 0;
297 using namespace ::com::sun::star::table::BorderLineStyle
;
299 //FIXME: properly adapt to new line border model
304 pBottom
.reset(new editeng::SvxBorderLine(NULL
, DEF_LINE_WIDTH_2
));
305 nValidFlags
|= FRM_VALID_BOTTOM
;
308 pBottom
.reset(new editeng::SvxBorderLine(NULL
));
309 pBottom
->GuessLinesWidths(DOUBLE
, DEF_LINE_WIDTH_0
, DEF_LINE_WIDTH_0
, DEF_LINE_WIDTH_1
);
310 nValidFlags
|= FRM_VALID_BOTTOM
;
313 pBottom
.reset(new editeng::SvxBorderLine(NULL
, DEF_LINE_WIDTH_2
));
314 pTop
.reset(new editeng::SvxBorderLine(NULL
, 1));
315 nValidFlags
|= FRM_VALID_BOTTOM
|FRM_VALID_TOP
;
318 pBottom
.reset(new editeng::SvxBorderLine(NULL
));
319 pBottom
->GuessLinesWidths(DOUBLE
, DEF_LINE_WIDTH_0
, DEF_LINE_WIDTH_0
, DEF_LINE_WIDTH_1
);
320 pTop
.reset(new editeng::SvxBorderLine(NULL
, 1));
321 nValidFlags
|= FRM_VALID_BOTTOM
|FRM_VALID_TOP
;
325 aBorderOuter
.SetLine( pTop
.get(), SvxBoxItemLine::TOP
);
326 aBorderOuter
.SetLine( pBottom
.get(), SvxBoxItemLine::BOTTOM
);
327 aBorderOuter
.SetLine( NULL
, SvxBoxItemLine::LEFT
);
328 aBorderOuter
.SetLine( NULL
, SvxBoxItemLine::RIGHT
);
330 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::TOP
, 0 != (nValidFlags
&FRM_VALID_TOP
));
331 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::BOTTOM
, 0 != (nValidFlags
&FRM_VALID_BOTTOM
));
332 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::LEFT
, 0 != (nValidFlags
&FRM_VALID_LEFT
));
333 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::RIGHT
, 0 != (nValidFlags
&FRM_VALID_RIGHT
));
334 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::HORI
, 0 != (nValidFlags
&FRM_VALID_HINNER
));
335 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::VERT
, 0 != (nValidFlags
&FRM_VALID_VINNER
));
336 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::DISTANCE
, true );
337 aBorderInner
.SetValid( SvxBoxInfoItemValidFlags::DISABLE
, false );
339 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER
, SfxCallMode::RECORD
, &aBorderOuter
, &aBorderInner
, 0L);
344 mrCellAppearancePropertyPanel
.EndCellBorderStylePopupMode();
347 } } // end of namespace svx::sidebar
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */