/src/libreoffice/sc/source/ui/sidebar/CellBorderStyleControl.cxx
Line | Count | Source |
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 <editeng/boxitem.hxx> |
22 | | #include <editeng/borderline.hxx> |
23 | | #include <sfx2/bindings.hxx> |
24 | | #include <sfx2/dispatch.hxx> |
25 | | #include <svx/dialmgr.hxx> |
26 | | #include <svx/strings.hrc> |
27 | | #include <svx/svxids.hrc> |
28 | | #include <vcl/settings.hxx> |
29 | | #include <editeng/lineitem.hxx> |
30 | | #include <svl/itemset.hxx> |
31 | | #include <memory> |
32 | | |
33 | | namespace sc::sidebar { |
34 | | |
35 | 0 | #define FRM_VALID_LEFT 0x01 |
36 | 0 | #define FRM_VALID_RIGHT 0x02 |
37 | 0 | #define FRM_VALID_TOP 0x04 |
38 | 0 | #define FRM_VALID_BOTTOM 0x08 |
39 | 0 | #define FRM_VALID_HINNER 0x10 |
40 | 0 | #define FRM_VALID_VINNER 0x20 |
41 | 0 | #define FRM_VALID_OUTER 0x0f |
42 | 0 | #define FRM_VALID_ALL 0xff |
43 | | |
44 | | CellBorderStylePopup::CellBorderStylePopup(weld::Toolbar* pParent, const OUString& rId, SfxDispatcher* pDispatcher) |
45 | 0 | : WeldToolbarPopup(nullptr, pParent, u"modules/scalc/ui/floatingborderstyle.ui"_ustr, u"FloatingBorderStyle"_ustr) |
46 | 0 | , maToolButton(pParent, rId) |
47 | 0 | , mpDispatcher(pDispatcher) |
48 | 0 | , mxTBBorder1(m_xBuilder->weld_toolbar(u"border1"_ustr)) |
49 | 0 | , mxTBBorder2(m_xBuilder->weld_toolbar(u"border2"_ustr)) |
50 | 0 | , mxTBBorder3(m_xBuilder->weld_toolbar(u"border3"_ustr)) |
51 | 0 | { |
52 | 0 | Initialize(); |
53 | 0 | } |
54 | | |
55 | | void CellBorderStylePopup::GrabFocus() |
56 | 0 | { |
57 | 0 | mxTBBorder1->grab_focus(); |
58 | 0 | } |
59 | | |
60 | | CellBorderStylePopup::~CellBorderStylePopup() |
61 | 0 | { |
62 | 0 | } |
63 | | |
64 | | void CellBorderStylePopup::Initialize() |
65 | 0 | { |
66 | 0 | mxTBBorder1->connect_clicked ( LINK(this, CellBorderStylePopup, TB1SelectHdl) ); |
67 | 0 | mxTBBorder1->set_item_tooltip_text(0, SvxResId(RID_SVXSTR_TABLE_PRESET_NONE)); |
68 | 0 | mxTBBorder1->set_item_accessible_name(0, SvxResId(RID_SVXSTR_TABLE_PRESET_NONE)); |
69 | 0 | mxTBBorder1->set_item_tooltip_text(1, SvxResId(RID_SVXSTR_TABLE_PRESET_OUTER)); |
70 | 0 | mxTBBorder1->set_item_accessible_name(1, SvxResId(RID_SVXSTR_TABLE_PRESET_OUTER)); |
71 | 0 | mxTBBorder1->set_item_tooltip_text(2, SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERALL)); |
72 | 0 | mxTBBorder1->set_item_accessible_name(2, SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERALL)); |
73 | 0 | mxTBBorder1->set_item_tooltip_text(3, SvxResId(RID_SVXSTR_PARA_PRESET_CRISSCROSS)); |
74 | 0 | mxTBBorder1->set_item_accessible_name(3, SvxResId(RID_SVXSTR_PARA_PRESET_CRISSCROSS)); |
75 | |
|
76 | 0 | mxTBBorder2->connect_clicked ( LINK(this, CellBorderStylePopup, TB2and3SelectHdl) ); |
77 | 0 | mxTBBorder2->set_item_tooltip_text(0, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYLEFT)); |
78 | 0 | mxTBBorder2->set_item_accessible_name(0, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYLEFT)); |
79 | 0 | mxTBBorder2->set_item_tooltip_text(1, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYRIGHT)); |
80 | 0 | mxTBBorder2->set_item_accessible_name(1, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYRIGHT)); |
81 | 0 | mxTBBorder2->set_item_tooltip_text(2, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTOP)); |
82 | 0 | mxTBBorder2->set_item_accessible_name(2, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTOP)); |
83 | 0 | mxTBBorder2->set_item_tooltip_text(3, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYBOTTOM)); |
84 | 0 | mxTBBorder2->set_item_accessible_name(3, SvxResId(RID_SVXSTR_PARA_PRESET_ONLYBOTTOM)); |
85 | |
|
86 | 0 | mxTBBorder3->connect_clicked ( LINK(this, CellBorderStylePopup, TB2and3SelectHdl) ); |
87 | 0 | mxTBBorder3->set_item_tooltip_text(0, SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALDOWN)); |
88 | 0 | mxTBBorder3->set_item_accessible_name(0, SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALDOWN)); |
89 | 0 | mxTBBorder3->set_item_tooltip_text(1, SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALUP)); |
90 | 0 | mxTBBorder3->set_item_accessible_name(1, SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALUP)); |
91 | 0 | mxTBBorder3->set_item_tooltip_text(2, SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOM)); |
92 | 0 | mxTBBorder3->set_item_accessible_name(2, SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOM)); |
93 | 0 | mxTBBorder3->set_item_tooltip_text(3, SvxResId(RID_SVXSTR_PARA_PRESET_LEFTRIGHT)); |
94 | 0 | mxTBBorder3->set_item_accessible_name(3, SvxResId(RID_SVXSTR_PARA_PRESET_LEFTRIGHT)); |
95 | 0 | } |
96 | | |
97 | | IMPL_LINK(CellBorderStylePopup, TB1SelectHdl, const OUString&, rId, void) |
98 | 0 | { |
99 | 0 | SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER ); |
100 | 0 | SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER ); |
101 | 0 | editeng::SvxBorderLine theDefLine(nullptr, SvxBorderLineWidth::Thin); |
102 | 0 | editeng::SvxBorderLine *pLeft = nullptr, *pRight = nullptr, *pTop = nullptr, *pBottom = nullptr; |
103 | 0 | sal_uInt8 nValidFlags = 0; |
104 | |
|
105 | 0 | if (rId == "none") |
106 | 0 | { |
107 | 0 | nValidFlags |= FRM_VALID_ALL; |
108 | 0 | SvxLineItem aLineItem1( SID_ATTR_BORDER_DIAG_BLTR ); |
109 | 0 | SvxLineItem aLineItem2( SID_ATTR_BORDER_DIAG_TLBR ); |
110 | 0 | aLineItem1.SetLine( nullptr ); //modify |
111 | 0 | aLineItem2.SetLine( nullptr ); //modify |
112 | 0 | mpDispatcher->ExecuteList( |
113 | 0 | SID_ATTR_BORDER_DIAG_BLTR, SfxCallMode::RECORD, { &aLineItem1 }); |
114 | 0 | mpDispatcher->ExecuteList( |
115 | 0 | SID_ATTR_BORDER_DIAG_TLBR, SfxCallMode::RECORD, { &aLineItem2 }); |
116 | 0 | } |
117 | 0 | else if (rId == "all") |
118 | 0 | { |
119 | 0 | pLeft = pRight = pTop = pBottom = &theDefLine; |
120 | 0 | aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI ); |
121 | 0 | aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::VERT ); |
122 | 0 | nValidFlags |= FRM_VALID_ALL; |
123 | 0 | } |
124 | 0 | else if (rId == "outside") |
125 | 0 | { |
126 | 0 | pLeft = pRight = pTop = pBottom = &theDefLine; |
127 | 0 | nValidFlags |= FRM_VALID_OUTER; |
128 | 0 | } |
129 | 0 | else if (rId == "crisscross") |
130 | 0 | { |
131 | 0 | editeng::SvxBorderLine aThinLine(nullptr, SvxBorderLineWidth::Thin); |
132 | 0 | SvxLineItem aDiagUpItem(SID_ATTR_BORDER_DIAG_BLTR); |
133 | 0 | aDiagUpItem.SetLine(&aThinLine); |
134 | 0 | SvxLineItem aDiagDownItem(SID_ATTR_BORDER_DIAG_TLBR); |
135 | 0 | aDiagDownItem.SetLine(&aThinLine); |
136 | 0 | mpDispatcher->ExecuteList(SID_ATTR_BORDER_DIAG_BLTR, SfxCallMode::RECORD, { &aDiagUpItem }); |
137 | 0 | mpDispatcher->ExecuteList(SID_ATTR_BORDER_DIAG_TLBR, SfxCallMode::RECORD, |
138 | 0 | { &aDiagDownItem }); |
139 | 0 | } |
140 | |
|
141 | 0 | aBorderOuter.SetLine( pLeft, SvxBoxItemLine::LEFT ); |
142 | 0 | aBorderOuter.SetLine( pRight, SvxBoxItemLine::RIGHT ); |
143 | 0 | aBorderOuter.SetLine( pTop, SvxBoxItemLine::TOP ); |
144 | 0 | aBorderOuter.SetLine( pBottom, SvxBoxItemLine::BOTTOM ); |
145 | |
|
146 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::TOP, 0 != (nValidFlags&FRM_VALID_TOP )); |
147 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM )); |
148 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::LEFT, 0 != (nValidFlags&FRM_VALID_LEFT)); |
149 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT )); |
150 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::HORI, 0 != (nValidFlags&FRM_VALID_HINNER )); |
151 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::VERT, 0 != (nValidFlags&FRM_VALID_VINNER)); |
152 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISTANCE ); |
153 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISABLE, false ); |
154 | |
|
155 | 0 | mpDispatcher->ExecuteList( |
156 | 0 | SID_ATTR_BORDER, SfxCallMode::RECORD, { &aBorderOuter, &aBorderInner }); |
157 | |
|
158 | 0 | maToolButton.set_inactive(); |
159 | 0 | } |
160 | | |
161 | | IMPL_LINK(CellBorderStylePopup, TB2and3SelectHdl, const OUString&, rId, void) |
162 | 0 | { |
163 | 0 | if (rId == "diagup") |
164 | 0 | { |
165 | 0 | editeng::SvxBorderLine aTmp( nullptr, SvxBorderLineWidth::Thin ); |
166 | 0 | SvxLineItem aLineItem( SID_ATTR_BORDER_DIAG_BLTR ); |
167 | 0 | aLineItem.SetLine( &aTmp ); |
168 | 0 | mpDispatcher->ExecuteList( |
169 | 0 | SID_ATTR_BORDER_DIAG_BLTR, SfxCallMode::RECORD, { &aLineItem }); |
170 | 0 | } |
171 | 0 | else if (rId == "diagdown") |
172 | 0 | { |
173 | 0 | editeng::SvxBorderLine aTmp( nullptr, SvxBorderLineWidth::Thin ); |
174 | 0 | SvxLineItem aLineItem( SID_ATTR_BORDER_DIAG_TLBR ); |
175 | 0 | aLineItem.SetLine( &aTmp ); |
176 | 0 | mpDispatcher->ExecuteList( |
177 | 0 | SID_ATTR_BORDER_DIAG_TLBR, SfxCallMode::RECORD, { &aLineItem }); |
178 | 0 | } |
179 | 0 | else |
180 | 0 | { |
181 | 0 | SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER ); |
182 | 0 | SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER ); |
183 | 0 | editeng::SvxBorderLine theDefLine(nullptr, SvxBorderLineWidth::Thin); |
184 | 0 | editeng::SvxBorderLine *pLeft = nullptr, |
185 | 0 | *pRight = nullptr, |
186 | 0 | *pTop = nullptr, |
187 | 0 | *pBottom = nullptr; |
188 | 0 | sal_uInt8 nValidFlags = 0; |
189 | 0 | if (rId == "left") |
190 | 0 | { |
191 | 0 | pLeft = &theDefLine; |
192 | 0 | nValidFlags |= FRM_VALID_LEFT; |
193 | 0 | } |
194 | 0 | else if (rId == "right") |
195 | 0 | { |
196 | 0 | if(!AllSettings::GetLayoutRTL()) |
197 | 0 | { |
198 | 0 | pRight = &theDefLine; |
199 | 0 | nValidFlags |= FRM_VALID_RIGHT; |
200 | 0 | } |
201 | 0 | else |
202 | 0 | { |
203 | 0 | pLeft = &theDefLine; |
204 | 0 | nValidFlags |= FRM_VALID_LEFT; |
205 | 0 | } |
206 | 0 | } |
207 | 0 | else if (rId == "top") |
208 | 0 | { |
209 | 0 | pTop = &theDefLine; |
210 | 0 | nValidFlags |= FRM_VALID_TOP; |
211 | 0 | } |
212 | 0 | else if (rId == "bottom") |
213 | 0 | { |
214 | 0 | pBottom = &theDefLine; |
215 | 0 | nValidFlags |= FRM_VALID_BOTTOM; |
216 | 0 | } |
217 | 0 | else if (rId == "topbottom") |
218 | 0 | { |
219 | 0 | pTop = pBottom = &theDefLine; |
220 | 0 | nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP; |
221 | 0 | } |
222 | 0 | else if (rId == "leftright") |
223 | 0 | { |
224 | 0 | pLeft = pRight = &theDefLine; |
225 | 0 | nValidFlags |= FRM_VALID_RIGHT|FRM_VALID_LEFT; |
226 | 0 | } |
227 | 0 | aBorderOuter.SetLine( pLeft, SvxBoxItemLine::LEFT ); |
228 | 0 | aBorderOuter.SetLine( pRight, SvxBoxItemLine::RIGHT ); |
229 | 0 | aBorderOuter.SetLine( pTop, SvxBoxItemLine::TOP ); |
230 | 0 | aBorderOuter.SetLine( pBottom, SvxBoxItemLine::BOTTOM ); |
231 | |
|
232 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::TOP, 0 != (nValidFlags&FRM_VALID_TOP )); |
233 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::BOTTOM, 0 != (nValidFlags&FRM_VALID_BOTTOM )); |
234 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::LEFT, 0 != (nValidFlags&FRM_VALID_LEFT)); |
235 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT, 0 != (nValidFlags&FRM_VALID_RIGHT )); |
236 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::HORI, 0 != (nValidFlags&FRM_VALID_HINNER )); |
237 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::VERT, 0 != (nValidFlags&FRM_VALID_VINNER)); |
238 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISTANCE ); |
239 | 0 | aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISABLE, false ); |
240 | |
|
241 | 0 | mpDispatcher->ExecuteList( |
242 | 0 | SID_ATTR_BORDER, SfxCallMode::RECORD, { &aBorderOuter, &aBorderInner}); |
243 | 0 | } |
244 | |
|
245 | 0 | maToolButton.set_inactive(); |
246 | 0 | } |
247 | | |
248 | | } // end of namespace sc::sidebar |
249 | | |
250 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |