summaryrefslogtreecommitdiff
path: root/sc/source/ui/sidebar/CellBorderStyleControl.cxx
blob: 88f3883bae6b7f7b63038c4eb27d689d694ba270 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <CellBorderStyleControl.hxx>
#include "sc.hrc"
#include "scresid.hxx"
#include <CellAppearancePropertyPanel.hrc>
#include <editeng/boxitem.hxx>
#include <editeng/borderline.hxx>
#include <CellAppearancePropertyPanel.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/dispatch.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <editeng/lineitem.hxx>

namespace sc { namespace sidebar {

#define FRM_VALID_LEFT      0x01
#define FRM_VALID_RIGHT     0x02
#define FRM_VALID_TOP       0x04
#define FRM_VALID_BOTTOM    0x08
#define FRM_VALID_HINNER    0x10
#define FRM_VALID_VINNER    0x20
#define FRM_VALID_OUTER     0x0f
#define FRM_VALID_ALL       0xff

CellBorderStyleControl::CellBorderStyleControl(Window* pParent, CellAppearancePropertyPanel& rPanel)
:   svx::sidebar::PopupControl(pParent, ScResId(RID_POPUPPANEL_APPEARANCE_CELL_BORDERSTYLE)),
    mrCellAppearancePropertyPanel(rPanel),
    maTBBorder1(this, ScResId(TB_BORDER1)),
    maTBBorder2(this, ScResId(TB_BORDER2)),
    maTBBorder3(this, ScResId(TB_BORDER3)),
    maFL1(this, ScResId(FL_1)),
    maFL2(this, ScResId(FL_2)),
    mpImageList(0)
{
    Initialize();
    FreeResource();
}

CellBorderStyleControl::~CellBorderStyleControl(void)
{
    delete[] mpImageList;
}

void CellBorderStyleControl::Initialize()
{
    mpImageList = new Image[16];
    mpImageList[0] = Image(ScResId(IMG_BORDER1));
    mpImageList[1] = Image(ScResId(IMG_BORDER2));
    mpImageList[2] = Image(ScResId(IMG_BORDER3));
    mpImageList[3] = Image(ScResId(IMG_BORDER4));
    mpImageList[4] = Image(ScResId(IMG_BORDER5));
    mpImageList[5] = Image(ScResId(IMG_BORDER6));
    mpImageList[6] = Image(ScResId(IMG_BORDER7));
    mpImageList[7] = Image(ScResId(IMG_BORDER8));
    mpImageList[8] = Image(ScResId(IMG_BORDER9));
    mpImageList[9] = Image(ScResId(IMG_BORDER10));
    mpImageList[10] = Image(ScResId(IMG_BORDER11));
    mpImageList[11] = Image(ScResId(IMG_BORDER12));
    mpImageList[12] = Image(ScResId(IMG_BORDER13));
    mpImageList[13] = Image(ScResId(IMG_BORDER14));
    mpImageList[14] = Image(ScResId(IMG_BORDER15));
    mpImageList[15] = Image(ScResId(IMG_BORDER16));

    maTBBorder1.SetItemImage(TBI_BORDER1_NONE, mpImageList[0]);
    maTBBorder1.SetItemImage(TBI_BORDER1_ALL, mpImageList[1]);
    maTBBorder1.SetItemImage(TBI_BORDER1_OUTER, mpImageList[2]);
    maTBBorder1.SetItemImage(TBI_BORDER1_OUTERBOLD, mpImageList[3]);
    maTBBorder1.SetBackground(Wallpaper());
    maTBBorder1.SetPaintTransparent(true);
    Size aTbxSize( maTBBorder1.CalcWindowSizePixel() );
    maTBBorder1.SetOutputSizePixel( aTbxSize );
    Link aLink  = LINK(this, CellBorderStyleControl, TB1SelectHdl);
    maTBBorder1.SetSelectHdl ( aLink );

    maTBBorder2.SetLineCount(2);
    maTBBorder2.InsertItem(TBI_BORDER2_LEFT, mpImageList[4]);
    maTBBorder2.InsertItem(TBI_BORDER2_RIGHT, mpImageList[5]);
    maTBBorder2.InsertItem(TBI_BORDER2_TOP, mpImageList[6]);
    maTBBorder2.InsertItem(TBI_BORDER2_BOT, mpImageList[7]);
    maTBBorder2.InsertBreak();
    maTBBorder2.InsertItem(TBI_BORDER2_BLTR, mpImageList[8]);
    maTBBorder2.InsertItem(TBI_BORDER2_TLBR, mpImageList[9]);
    maTBBorder2.InsertItem(TBI_BORDER2_TOPBOT, mpImageList[10]);
    maTBBorder2.InsertItem(TBI_BORDER2_LEFTRIGHT, mpImageList[11]);
    maTBBorder2.SetBackground(Wallpaper());
    maTBBorder2.SetPaintTransparent(true);
    aTbxSize = maTBBorder2.CalcWindowSizePixel() ;
    maTBBorder2.SetOutputSizePixel( aTbxSize );
    maTBBorder2.SetHelpId(TBI_BORDER2_LEFT, HID_PROPERTYPANEL_SC_BORDER_TBI_LEFT);
    maTBBorder2.SetHelpId(TBI_BORDER2_RIGHT, HID_PROPERTYPANEL_SC_BORDER_TBI_RIGHT);
    maTBBorder2.SetHelpId(TBI_BORDER2_TOP, HID_PROPERTYPANEL_SC_BORDER_TBI_TOP);
    maTBBorder2.SetHelpId(TBI_BORDER2_BOT, HID_PROPERTYPANEL_SC_BORDER_TBI_BOT);
    maTBBorder2.SetHelpId(TBI_BORDER2_BLTR, HID_PROPERTYPANEL_SC_BORDER_TBI_BLTR);
    maTBBorder2.SetHelpId(TBI_BORDER2_TLBR, HID_PROPERTYPANEL_SC_BORDER_TBI_TLBR);
    maTBBorder2.SetHelpId(TBI_BORDER2_TOPBOT, HID_PROPERTYPANEL_SC_BORDER_TBI_TOPBOT);
    maTBBorder2.SetHelpId(TBI_BORDER2_LEFTRIGHT, HID_PROPERTYPANEL_SC_BORDER_TBI_LEFTRIGHT);
    maTBBorder2.SetItemText(TBI_BORDER2_LEFT, ScResId(STR_BORDER_1));
    maTBBorder2.SetItemText(TBI_BORDER2_RIGHT, ScResId(STR_BORDER_2));
    maTBBorder2.SetItemText(TBI_BORDER2_TOP, ScResId(STR_BORDER_3));
    maTBBorder2.SetItemText(TBI_BORDER2_BOT, ScResId(STR_BORDER_4));
    maTBBorder2.SetItemText(TBI_BORDER2_BLTR, ScResId(STR_BORDER_5));
    maTBBorder2.SetItemText(TBI_BORDER2_TLBR, ScResId(STR_BORDER_6));
    maTBBorder2.SetItemText(TBI_BORDER2_TOPBOT, ScResId(STR_BORDER_7));
    maTBBorder2.SetItemText(TBI_BORDER2_LEFTRIGHT, ScResId(STR_BORDER_8));
    aLink  = LINK(this, CellBorderStyleControl, TB2SelectHdl);
    maTBBorder2.SetSelectHdl ( aLink );

    maTBBorder3.SetItemImage(TBI_BORDER3_S1, mpImageList[12]);
    maTBBorder3.SetItemImage(TBI_BORDER3_S2, mpImageList[13]);
    maTBBorder3.SetItemImage(TBI_BORDER3_S3, mpImageList[14]);
    maTBBorder3.SetItemImage(TBI_BORDER3_S4, mpImageList[15]);
    maTBBorder3.SetBackground(Wallpaper());
    maTBBorder3.SetPaintTransparent(true);
    aTbxSize = maTBBorder3.CalcWindowSizePixel() ;
    maTBBorder3.SetOutputSizePixel( aTbxSize );
    aLink  = LINK(this, CellBorderStyleControl, TB3SelectHdl);
    maTBBorder3.SetSelectHdl ( aLink );
}

IMPL_LINK(CellBorderStyleControl, TB1SelectHdl, ToolBox*, pToolBox)
{
    sal_uInt16 nId = pToolBox->GetCurItemId();
    SvxBoxItem          aBorderOuter( SID_ATTR_BORDER_OUTER );
    SvxBoxInfoItem      aBorderInner( SID_ATTR_BORDER_INNER );
    editeng::SvxBorderLine theDefLine(NULL, 1);
    editeng::SvxBorderLine *pLeft = 0, *pRight = 0, *pTop = 0, *pBottom = 0;
    sal_uInt8 nValidFlags = 0;
    switch ( nId )
    {
    case TBI_BORDER1_NONE:
        {
         nValidFlags |= FRM_VALID_ALL;
        SvxLineItem     aLineItem1( SID_ATTR_BORDER_DIAG_BLTR );
        SvxLineItem     aLineItem2( SID_ATTR_BORDER_DIAG_TLBR );
        aLineItem1.SetLine( NULL );     //modify
        aLineItem2.SetLine( NULL );     //modify
        mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_BLTR, SFX_CALLMODE_RECORD, &aLineItem1, 0L);
        mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_TLBR, SFX_CALLMODE_RECORD, &aLineItem2, 0L);
        }
        break;
    case TBI_BORDER1_ALL:
        pLeft = pRight = pTop = pBottom = &theDefLine;
        aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_HORI );
        aBorderInner.SetLine( &theDefLine, BOXINFO_LINE_VERT );
        nValidFlags |= FRM_VALID_ALL;
        break;
    case TBI_BORDER1_OUTER:
        pLeft = pRight = pTop = pBottom = &theDefLine;
        nValidFlags |= FRM_VALID_OUTER;
        break;
    case TBI_BORDER1_OUTERBOLD:
        theDefLine.SetWidth(DEF_LINE_WIDTH_2);
        pLeft = pRight = pTop = pBottom = &theDefLine;
        nValidFlags |= FRM_VALID_OUTER;
        break;
    }

    aBorderOuter.SetLine( pLeft, BOX_LINE_LEFT );
    aBorderOuter.SetLine( pRight, BOX_LINE_RIGHT );
    aBorderOuter.SetLine( pTop, BOX_LINE_TOP );
    aBorderOuter.SetLine( pBottom, BOX_LINE_BOTTOM );

    aBorderInner.SetValid( VALID_TOP,       0 != (nValidFlags&FRM_VALID_TOP ));
    aBorderInner.SetValid( VALID_BOTTOM,    0 != (nValidFlags&FRM_VALID_BOTTOM ));
    aBorderInner.SetValid( VALID_LEFT,      0 != (nValidFlags&FRM_VALID_LEFT));
    aBorderInner.SetValid( VALID_RIGHT,     0 != (nValidFlags&FRM_VALID_RIGHT ));
    aBorderInner.SetValid( VALID_HORI,      0 != (nValidFlags&FRM_VALID_HINNER ));
    aBorderInner.SetValid( VALID_VERT,      0 != (nValidFlags&FRM_VALID_VINNER));
    aBorderInner.SetValid( VALID_DISTANCE, true );
    aBorderInner.SetValid( VALID_DISABLE, false );

    mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER, SFX_CALLMODE_RECORD, &aBorderOuter, &aBorderInner, 0L);
    mrCellAppearancePropertyPanel.EndCellBorderStylePopupMode();
    return 0;
}

IMPL_LINK(CellBorderStyleControl, TB2SelectHdl, ToolBox *, pToolBox)
{
    sal_uInt16 nId = pToolBox->GetCurItemId();

    if( nId != TBI_BORDER2_BLTR && nId != TBI_BORDER2_TLBR )
    {
        SvxBoxItem          aBorderOuter( SID_ATTR_BORDER_OUTER );
        SvxBoxInfoItem      aBorderInner( SID_ATTR_BORDER_INNER );
        editeng::SvxBorderLine theDefLine(NULL, 1);
        editeng::SvxBorderLine       *pLeft = 0,
                            *pRight = 0,
                            *pTop = 0,
                            *pBottom = 0;
        sal_uInt8               nValidFlags = 0;
        switch ( nId )
        {
        case TBI_BORDER2_LEFT:
            pLeft = &theDefLine;
            nValidFlags |= FRM_VALID_LEFT;
            break;
        case TBI_BORDER2_RIGHT:
            //
            if(!Application::GetSettings().GetLayoutRTL())
            {
                pRight = &theDefLine;
                nValidFlags |= FRM_VALID_RIGHT;
            }
            else
            {
                pLeft = &theDefLine;
                nValidFlags |= FRM_VALID_LEFT;
            }
            break;
        case TBI_BORDER2_TOP:
            pTop = &theDefLine;
            nValidFlags |= FRM_VALID_TOP;
            break;
        case TBI_BORDER2_BOT:
            pBottom = &theDefLine;
            nValidFlags |= FRM_VALID_BOTTOM;
            break;
        case TBI_BORDER2_TOPBOT:
            pTop =  pBottom = &theDefLine;
            nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
            break;
        case TBI_BORDER2_LEFTRIGHT:
            pLeft = pRight = &theDefLine;
            nValidFlags |=  FRM_VALID_RIGHT|FRM_VALID_LEFT;
            break;
        }
        aBorderOuter.SetLine( pLeft, BOX_LINE_LEFT );
        aBorderOuter.SetLine( pRight, BOX_LINE_RIGHT );
        aBorderOuter.SetLine( pTop, BOX_LINE_TOP );
        aBorderOuter.SetLine( pBottom, BOX_LINE_BOTTOM );

        aBorderInner.SetValid( VALID_TOP,       0 != (nValidFlags&FRM_VALID_TOP ));
        aBorderInner.SetValid( VALID_BOTTOM,    0 != (nValidFlags&FRM_VALID_BOTTOM ));
        aBorderInner.SetValid( VALID_LEFT,      0 != (nValidFlags&FRM_VALID_LEFT));
        aBorderInner.SetValid( VALID_RIGHT,     0 != (nValidFlags&FRM_VALID_RIGHT ));
        aBorderInner.SetValid( VALID_HORI,      0 != (nValidFlags&FRM_VALID_HINNER ));
        aBorderInner.SetValid( VALID_VERT,      0 != (nValidFlags&FRM_VALID_VINNER));
        aBorderInner.SetValid( VALID_DISTANCE, true );
        aBorderInner.SetValid( VALID_DISABLE, false );

        mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER, SFX_CALLMODE_RECORD, &aBorderOuter, &aBorderInner, 0L);
    }
    else if(nId == TBI_BORDER2_BLTR)
    {
        editeng::SvxBorderLine aTmp( NULL, 1 );
        SvxLineItem     aLineItem( SID_ATTR_BORDER_DIAG_BLTR );
        aLineItem.SetLine( &aTmp );
        mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_BLTR, SFX_CALLMODE_RECORD, &aLineItem, 0L);
    }
    else if(nId == TBI_BORDER2_TLBR)
    {
        editeng::SvxBorderLine aTmp( NULL, 1 );
        SvxLineItem     aLineItem( SID_ATTR_BORDER_DIAG_TLBR );
        aLineItem.SetLine( &aTmp );
        mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER_DIAG_TLBR, SFX_CALLMODE_RECORD, &aLineItem, 0L);
    }

    mrCellAppearancePropertyPanel.EndCellBorderStylePopupMode();
    return 0;
}

IMPL_LINK(CellBorderStyleControl, TB3SelectHdl, ToolBox *, pToolBox)
{
    sal_uInt16 nId = pToolBox->GetCurItemId();

    SvxBoxItem          aBorderOuter( SID_ATTR_BORDER_OUTER );
    SvxBoxInfoItem      aBorderInner( SID_ATTR_BORDER_INNER );
    editeng::SvxBorderLine *pTop = 0 ,
                        *pBottom = 0 ;
    sal_uInt8               nValidFlags = 0;
    using namespace ::com::sun::star::table::BorderLineStyle;

    //FIXME: properly adapt to new line border model

    switch ( nId )
    {
    case TBI_BORDER3_S1:
        pBottom = new editeng::SvxBorderLine(NULL, DEF_LINE_WIDTH_2 );
        nValidFlags |= FRM_VALID_BOTTOM;
        break;
    case TBI_BORDER3_S2:
        pBottom = new editeng::SvxBorderLine(NULL);
        pBottom->GuessLinesWidths(DOUBLE, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_1);
        nValidFlags |= FRM_VALID_BOTTOM;
        break;
    case TBI_BORDER3_S3:
        pBottom = new editeng::SvxBorderLine(NULL, DEF_LINE_WIDTH_2 );
        pTop = new editeng::SvxBorderLine(NULL, 1);
        nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
        break;
    case TBI_BORDER3_S4:
        pBottom = new editeng::SvxBorderLine(NULL);
        pBottom->GuessLinesWidths(DOUBLE, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_1);
        pTop = new editeng::SvxBorderLine(NULL, 1);
        nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
        break;
    }

    aBorderOuter.SetLine( pTop, BOX_LINE_TOP );
    aBorderOuter.SetLine( pBottom, BOX_LINE_BOTTOM );
    aBorderOuter.SetLine( NULL, BOX_LINE_LEFT );
    aBorderOuter.SetLine( NULL, BOX_LINE_RIGHT );

    aBorderInner.SetValid( VALID_TOP,       0 != (nValidFlags&FRM_VALID_TOP ));
    aBorderInner.SetValid( VALID_BOTTOM,    0 != (nValidFlags&FRM_VALID_BOTTOM ));
    aBorderInner.SetValid( VALID_LEFT,      0 != (nValidFlags&FRM_VALID_LEFT ));
    aBorderInner.SetValid( VALID_RIGHT,     0 != (nValidFlags&FRM_VALID_RIGHT ));
    aBorderInner.SetValid( VALID_HORI,      0 != (nValidFlags&FRM_VALID_HINNER ));
    aBorderInner.SetValid( VALID_VERT,      0 != (nValidFlags&FRM_VALID_VINNER));
    aBorderInner.SetValid( VALID_DISTANCE, true );
    aBorderInner.SetValid( VALID_DISABLE, false );

    mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER, SFX_CALLMODE_RECORD, &aBorderOuter, &aBorderInner, 0L);

    delete pTop;
    delete pBottom;

    mrCellAppearancePropertyPanel.EndCellBorderStylePopupMode();
    return 0;
}

} } // end of namespace svx::sidebar

// eof

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */