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 <editeng/lineitem.hxx>
32 namespace sc
{ namespace sidebar
{
34 #define FRM_VALID_LEFT 0x01
35 #define FRM_VALID_RIGHT 0x02
36 #define FRM_VALID_TOP 0x04
37 #define FRM_VALID_BOTTOM 0x08
38 #define FRM_VALID_HINNER 0x10
39 #define FRM_VALID_VINNER 0x20
40 #define FRM_VALID_OUTER 0x0f
41 #define FRM_VALID_ALL 0xff
43 CellBorderStyleControl::CellBorderStyleControl(Window
* pParent
, CellAppearancePropertyPanel
& rPanel
)
44 : svx::sidebar::PopupControl(pParent
, ScResId(RID_POPUPPANEL_APPEARANCE_CELL_BORDERSTYLE
)),
45 mrCellAppearancePropertyPanel(rPanel
),
46 maTBBorder1(this, ScResId(TB_BORDER1
)),
47 maTBBorder2(this, ScResId(TB_BORDER2
)),
48 maTBBorder3(this, ScResId(TB_BORDER3
)),
49 maFL1(this, ScResId(FL_1
)),
50 maFL2(this, ScResId(FL_2
)),
57 CellBorderStyleControl::~CellBorderStyleControl(void)
62 void CellBorderStyleControl::Initialize()
64 mpImageList
= new Image
[16];
65 mpImageList
[0] = Image(ScResId(IMG_BORDER1
));
66 mpImageList
[1] = Image(ScResId(IMG_BORDER2
));
67 mpImageList
[2] = Image(ScResId(IMG_BORDER3
));
68 mpImageList
[3] = Image(ScResId(IMG_BORDER4
));
69 mpImageList
[4] = Image(ScResId(IMG_BORDER5
));
70 mpImageList
[5] = Image(ScResId(IMG_BORDER6
));
71 mpImageList
[6] = Image(ScResId(IMG_BORDER7
));
72 mpImageList
[7] = Image(ScResId(IMG_BORDER8
));
73 mpImageList
[8] = Image(ScResId(IMG_BORDER9
));
74 mpImageList
[9] = Image(ScResId(IMG_BORDER10
));
75 mpImageList
[10] = Image(ScResId(IMG_BORDER11
));
76 mpImageList
[11] = Image(ScResId(IMG_BORDER12
));
77 mpImageList
[12] = Image(ScResId(IMG_BORDER13
));
78 mpImageList
[13] = Image(ScResId(IMG_BORDER14
));
79 mpImageList
[14] = Image(ScResId(IMG_BORDER15
));
80 mpImageList
[15] = Image(ScResId(IMG_BORDER16
));
82 maTBBorder1
.SetItemImage(TBI_BORDER1_NONE
, mpImageList
[0]);
83 maTBBorder1
.SetItemImage(TBI_BORDER1_ALL
, mpImageList
[1]);
84 maTBBorder1
.SetItemImage(TBI_BORDER1_OUTER
, mpImageList
[2]);
85 maTBBorder1
.SetItemImage(TBI_BORDER1_OUTERBOLD
, mpImageList
[3]);
86 maTBBorder1
.SetBackground(Wallpaper());
87 maTBBorder1
.SetPaintTransparent(true);
88 Size
aTbxSize( maTBBorder1
.CalcWindowSizePixel() );
89 maTBBorder1
.SetOutputSizePixel( aTbxSize
);
90 Link aLink
= LINK(this, CellBorderStyleControl
, TB1SelectHdl
);
91 maTBBorder1
.SetSelectHdl ( aLink
);
93 maTBBorder2
.SetLineCount(2);
94 maTBBorder2
.InsertItem(TBI_BORDER2_LEFT
, mpImageList
[4]);
95 maTBBorder2
.InsertItem(TBI_BORDER2_RIGHT
, mpImageList
[5]);
96 maTBBorder2
.InsertItem(TBI_BORDER2_TOP
, mpImageList
[6]);
97 maTBBorder2
.InsertItem(TBI_BORDER2_BOT
, mpImageList
[7]);
98 maTBBorder2
.InsertBreak();
99 maTBBorder2
.InsertItem(TBI_BORDER2_BLTR
, mpImageList
[8]);
100 maTBBorder2
.InsertItem(TBI_BORDER2_TLBR
, mpImageList
[9]);
101 maTBBorder2
.InsertItem(TBI_BORDER2_TOPBOT
, mpImageList
[10]);
102 maTBBorder2
.InsertItem(TBI_BORDER2_LEFTRIGHT
, mpImageList
[11]);
103 maTBBorder2
.SetBackground(Wallpaper());
104 maTBBorder2
.SetPaintTransparent(true);
105 aTbxSize
= maTBBorder2
.CalcWindowSizePixel() ;
106 maTBBorder2
.SetOutputSizePixel( aTbxSize
);
107 maTBBorder2
.SetHelpId(TBI_BORDER2_LEFT
, HID_PROPERTYPANEL_SC_BORDER_TBI_LEFT
);
108 maTBBorder2
.SetHelpId(TBI_BORDER2_RIGHT
, HID_PROPERTYPANEL_SC_BORDER_TBI_RIGHT
);
109 maTBBorder2
.SetHelpId(TBI_BORDER2_TOP
, HID_PROPERTYPANEL_SC_BORDER_TBI_TOP
);
110 maTBBorder2
.SetHelpId(TBI_BORDER2_BOT
, HID_PROPERTYPANEL_SC_BORDER_TBI_BOT
);
111 maTBBorder2
.SetHelpId(TBI_BORDER2_BLTR
, HID_PROPERTYPANEL_SC_BORDER_TBI_BLTR
);
112 maTBBorder2
.SetHelpId(TBI_BORDER2_TLBR
, HID_PROPERTYPANEL_SC_BORDER_TBI_TLBR
);
113 maTBBorder2
.SetHelpId(TBI_BORDER2_TOPBOT
, HID_PROPERTYPANEL_SC_BORDER_TBI_TOPBOT
);
114 maTBBorder2
.SetHelpId(TBI_BORDER2_LEFTRIGHT
, HID_PROPERTYPANEL_SC_BORDER_TBI_LEFTRIGHT
);
115 maTBBorder2
.SetItemText(TBI_BORDER2_LEFT
, ScResId(STR_BORDER_1
));
116 maTBBorder2
.SetItemText(TBI_BORDER2_RIGHT
, ScResId(STR_BORDER_2
));
117 maTBBorder2
.SetItemText(TBI_BORDER2_TOP
, ScResId(STR_BORDER_3
));
118 maTBBorder2
.SetItemText(TBI_BORDER2_BOT
, ScResId(STR_BORDER_4
));
119 maTBBorder2
.SetItemText(TBI_BORDER2_BLTR
, ScResId(STR_BORDER_5
));
120 maTBBorder2
.SetItemText(TBI_BORDER2_TLBR
, ScResId(STR_BORDER_6
));
121 maTBBorder2
.SetItemText(TBI_BORDER2_TOPBOT
, ScResId(STR_BORDER_7
));
122 maTBBorder2
.SetItemText(TBI_BORDER2_LEFTRIGHT
, ScResId(STR_BORDER_8
));
123 aLink
= LINK(this, CellBorderStyleControl
, TB2SelectHdl
);
124 maTBBorder2
.SetSelectHdl ( aLink
);
126 maTBBorder3
.SetItemImage(TBI_BORDER3_S1
, mpImageList
[12]);
127 maTBBorder3
.SetItemImage(TBI_BORDER3_S2
, mpImageList
[13]);
128 maTBBorder3
.SetItemImage(TBI_BORDER3_S3
, mpImageList
[14]);
129 maTBBorder3
.SetItemImage(TBI_BORDER3_S4
, mpImageList
[15]);
130 maTBBorder3
.SetBackground(Wallpaper());
131 maTBBorder3
.SetPaintTransparent(true);
132 aTbxSize
= maTBBorder3
.CalcWindowSizePixel() ;
133 maTBBorder3
.SetOutputSizePixel( aTbxSize
);
134 aLink
= LINK(this, CellBorderStyleControl
, TB3SelectHdl
);
135 maTBBorder3
.SetSelectHdl ( aLink
);
138 IMPL_LINK(CellBorderStyleControl
, TB1SelectHdl
, ToolBox
*, pToolBox
)
140 sal_uInt16 nId
= pToolBox
->GetCurItemId();
141 SvxBoxItem
aBorderOuter( SID_ATTR_BORDER_OUTER
);
142 SvxBoxInfoItem
aBorderInner( SID_ATTR_BORDER_INNER
);
143 editeng::SvxBorderLine
theDefLine(NULL
, 1);
144 editeng::SvxBorderLine
*pLeft
= 0, *pRight
= 0, *pTop
= 0, *pBottom
= 0;
145 sal_uInt8 nValidFlags
= 0;
148 case TBI_BORDER1_NONE
:
150 nValidFlags
|= FRM_VALID_ALL
;
151 SvxLineItem
aLineItem1( SID_ATTR_BORDER_DIAG_BLTR
);
152 SvxLineItem
aLineItem2( SID_ATTR_BORDER_DIAG_TLBR
);
153 aLineItem1
.SetLine( NULL
); //modify
154 aLineItem2
.SetLine( NULL
); //modify
155 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_BLTR
, SFX_CALLMODE_RECORD
, &aLineItem1
, 0L);
156 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_TLBR
, SFX_CALLMODE_RECORD
, &aLineItem2
, 0L);
159 case TBI_BORDER1_ALL
:
160 pLeft
= pRight
= pTop
= pBottom
= &theDefLine
;
161 aBorderInner
.SetLine( &theDefLine
, BOXINFO_LINE_HORI
);
162 aBorderInner
.SetLine( &theDefLine
, BOXINFO_LINE_VERT
);
163 nValidFlags
|= FRM_VALID_ALL
;
165 case TBI_BORDER1_OUTER
:
166 pLeft
= pRight
= pTop
= pBottom
= &theDefLine
;
167 nValidFlags
|= FRM_VALID_OUTER
;
169 case TBI_BORDER1_OUTERBOLD
:
170 theDefLine
.SetWidth(DEF_LINE_WIDTH_2
);
171 pLeft
= pRight
= pTop
= pBottom
= &theDefLine
;
172 nValidFlags
|= FRM_VALID_OUTER
;
176 aBorderOuter
.SetLine( pLeft
, BOX_LINE_LEFT
);
177 aBorderOuter
.SetLine( pRight
, BOX_LINE_RIGHT
);
178 aBorderOuter
.SetLine( pTop
, BOX_LINE_TOP
);
179 aBorderOuter
.SetLine( pBottom
, BOX_LINE_BOTTOM
);
181 aBorderInner
.SetValid( VALID_TOP
, 0 != (nValidFlags
&FRM_VALID_TOP
));
182 aBorderInner
.SetValid( VALID_BOTTOM
, 0 != (nValidFlags
&FRM_VALID_BOTTOM
));
183 aBorderInner
.SetValid( VALID_LEFT
, 0 != (nValidFlags
&FRM_VALID_LEFT
));
184 aBorderInner
.SetValid( VALID_RIGHT
, 0 != (nValidFlags
&FRM_VALID_RIGHT
));
185 aBorderInner
.SetValid( VALID_HORI
, 0 != (nValidFlags
&FRM_VALID_HINNER
));
186 aBorderInner
.SetValid( VALID_VERT
, 0 != (nValidFlags
&FRM_VALID_VINNER
));
187 aBorderInner
.SetValid( VALID_DISTANCE
, true );
188 aBorderInner
.SetValid( VALID_DISABLE
, false );
190 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER
, SFX_CALLMODE_RECORD
, &aBorderOuter
, &aBorderInner
, 0L);
191 mrCellAppearancePropertyPanel
.EndCellBorderStylePopupMode();
195 IMPL_LINK(CellBorderStyleControl
, TB2SelectHdl
, ToolBox
*, pToolBox
)
197 sal_uInt16 nId
= pToolBox
->GetCurItemId();
199 if( nId
!= TBI_BORDER2_BLTR
&& nId
!= TBI_BORDER2_TLBR
)
201 SvxBoxItem
aBorderOuter( SID_ATTR_BORDER_OUTER
);
202 SvxBoxInfoItem
aBorderInner( SID_ATTR_BORDER_INNER
);
203 editeng::SvxBorderLine
theDefLine(NULL
, 1);
204 editeng::SvxBorderLine
*pLeft
= 0,
208 sal_uInt8 nValidFlags
= 0;
211 case TBI_BORDER2_LEFT
:
213 nValidFlags
|= FRM_VALID_LEFT
;
215 case TBI_BORDER2_RIGHT
:
217 if(!Application::GetSettings().GetLayoutRTL())
219 pRight
= &theDefLine
;
220 nValidFlags
|= FRM_VALID_RIGHT
;
225 nValidFlags
|= FRM_VALID_LEFT
;
228 case TBI_BORDER2_TOP
:
230 nValidFlags
|= FRM_VALID_TOP
;
232 case TBI_BORDER2_BOT
:
233 pBottom
= &theDefLine
;
234 nValidFlags
|= FRM_VALID_BOTTOM
;
236 case TBI_BORDER2_TOPBOT
:
237 pTop
= pBottom
= &theDefLine
;
238 nValidFlags
|= FRM_VALID_BOTTOM
|FRM_VALID_TOP
;
240 case TBI_BORDER2_LEFTRIGHT
:
241 pLeft
= pRight
= &theDefLine
;
242 nValidFlags
|= FRM_VALID_RIGHT
|FRM_VALID_LEFT
;
245 aBorderOuter
.SetLine( pLeft
, BOX_LINE_LEFT
);
246 aBorderOuter
.SetLine( pRight
, BOX_LINE_RIGHT
);
247 aBorderOuter
.SetLine( pTop
, BOX_LINE_TOP
);
248 aBorderOuter
.SetLine( pBottom
, BOX_LINE_BOTTOM
);
250 aBorderInner
.SetValid( VALID_TOP
, 0 != (nValidFlags
&FRM_VALID_TOP
));
251 aBorderInner
.SetValid( VALID_BOTTOM
, 0 != (nValidFlags
&FRM_VALID_BOTTOM
));
252 aBorderInner
.SetValid( VALID_LEFT
, 0 != (nValidFlags
&FRM_VALID_LEFT
));
253 aBorderInner
.SetValid( VALID_RIGHT
, 0 != (nValidFlags
&FRM_VALID_RIGHT
));
254 aBorderInner
.SetValid( VALID_HORI
, 0 != (nValidFlags
&FRM_VALID_HINNER
));
255 aBorderInner
.SetValid( VALID_VERT
, 0 != (nValidFlags
&FRM_VALID_VINNER
));
256 aBorderInner
.SetValid( VALID_DISTANCE
, true );
257 aBorderInner
.SetValid( VALID_DISABLE
, false );
259 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER
, SFX_CALLMODE_RECORD
, &aBorderOuter
, &aBorderInner
, 0L);
261 else if(nId
== TBI_BORDER2_BLTR
)
263 editeng::SvxBorderLine
aTmp( NULL
, 1 );
264 SvxLineItem
aLineItem( SID_ATTR_BORDER_DIAG_BLTR
);
265 aLineItem
.SetLine( &aTmp
);
266 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_BLTR
, SFX_CALLMODE_RECORD
, &aLineItem
, 0L);
268 else if(nId
== TBI_BORDER2_TLBR
)
270 editeng::SvxBorderLine
aTmp( NULL
, 1 );
271 SvxLineItem
aLineItem( SID_ATTR_BORDER_DIAG_TLBR
);
272 aLineItem
.SetLine( &aTmp
);
273 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_TLBR
, SFX_CALLMODE_RECORD
, &aLineItem
, 0L);
276 mrCellAppearancePropertyPanel
.EndCellBorderStylePopupMode();
280 IMPL_LINK(CellBorderStyleControl
, TB3SelectHdl
, ToolBox
*, pToolBox
)
282 sal_uInt16 nId
= pToolBox
->GetCurItemId();
284 SvxBoxItem
aBorderOuter( SID_ATTR_BORDER_OUTER
);
285 SvxBoxInfoItem
aBorderInner( SID_ATTR_BORDER_INNER
);
286 editeng::SvxBorderLine
*pTop
= 0 ,
288 sal_uInt8 nValidFlags
= 0;
289 using namespace ::com::sun::star::table::BorderLineStyle
;
291 //FIXME: properly adapt to new line border model
296 pBottom
= new editeng::SvxBorderLine(NULL
, DEF_LINE_WIDTH_2
);
297 nValidFlags
|= FRM_VALID_BOTTOM
;
300 pBottom
= new editeng::SvxBorderLine(NULL
);
301 pBottom
->GuessLinesWidths(DOUBLE
, DEF_LINE_WIDTH_0
, DEF_LINE_WIDTH_0
, DEF_LINE_WIDTH_1
);
302 nValidFlags
|= FRM_VALID_BOTTOM
;
305 pBottom
= new editeng::SvxBorderLine(NULL
, DEF_LINE_WIDTH_2
);
306 pTop
= new editeng::SvxBorderLine(NULL
, 1);
307 nValidFlags
|= FRM_VALID_BOTTOM
|FRM_VALID_TOP
;
310 pBottom
= new editeng::SvxBorderLine(NULL
);
311 pBottom
->GuessLinesWidths(DOUBLE
, DEF_LINE_WIDTH_0
, DEF_LINE_WIDTH_0
, DEF_LINE_WIDTH_1
);
312 pTop
= new editeng::SvxBorderLine(NULL
, 1);
313 nValidFlags
|= FRM_VALID_BOTTOM
|FRM_VALID_TOP
;
317 aBorderOuter
.SetLine( pTop
, BOX_LINE_TOP
);
318 aBorderOuter
.SetLine( pBottom
, BOX_LINE_BOTTOM
);
319 aBorderOuter
.SetLine( NULL
, BOX_LINE_LEFT
);
320 aBorderOuter
.SetLine( NULL
, BOX_LINE_RIGHT
);
322 aBorderInner
.SetValid( VALID_TOP
, 0 != (nValidFlags
&FRM_VALID_TOP
));
323 aBorderInner
.SetValid( VALID_BOTTOM
, 0 != (nValidFlags
&FRM_VALID_BOTTOM
));
324 aBorderInner
.SetValid( VALID_LEFT
, 0 != (nValidFlags
&FRM_VALID_LEFT
));
325 aBorderInner
.SetValid( VALID_RIGHT
, 0 != (nValidFlags
&FRM_VALID_RIGHT
));
326 aBorderInner
.SetValid( VALID_HORI
, 0 != (nValidFlags
&FRM_VALID_HINNER
));
327 aBorderInner
.SetValid( VALID_VERT
, 0 != (nValidFlags
&FRM_VALID_VINNER
));
328 aBorderInner
.SetValid( VALID_DISTANCE
, true );
329 aBorderInner
.SetValid( VALID_DISABLE
, false );
331 mrCellAppearancePropertyPanel
.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER
, SFX_CALLMODE_RECORD
, &aBorderOuter
, &aBorderInner
, 0L);
336 mrCellAppearancePropertyPanel
.EndCellBorderStylePopupMode();
340 } } // end of namespace svx::sidebar
344 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */