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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
/* -*- 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/.
*/
#include <basegfx/polygon/b2dpolygon.hxx>
#include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
#include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
#include <drawinglayer/processor2d/baseprocessor2d.hxx>
#include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/infobar.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/sfx.hrc>
#include <sfx2/viewsh.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
using namespace std;
using namespace drawinglayer::geometry;
using namespace drawinglayer::processor2d;
using namespace drawinglayer::primitive2d;
using namespace drawinglayer::attribute;
using namespace drawinglayer::geometry;
using namespace basegfx;
namespace
{
const long INFO_BAR_BASE_HEIGHT = 40;
const BColor constLightColor(1.0, 1.0, 191.0 / 255.0);
const BColor constDarkColor(217.0 / 255.0, 217.0 / 255.0, 78.0 / 255.0);
void lclDetermineLightDarkColor(BColor& rLightColor, BColor& rDarkColor)
{
const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
if (rSettings.GetHighContrastMode())
{
rLightColor = rSettings.GetLightColor().getBColor();
rDarkColor = rSettings.GetDialogTextColor().getBColor();
}
else
{
rLightColor = constLightColor;
rDarkColor = constDarkColor;
}
}
class SfxCloseButton : public PushButton
{
public:
explicit SfxCloseButton(vcl::Window* pParent) : PushButton(pParent, 0)
{}
virtual ~SfxCloseButton() {}
virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
};
void SfxCloseButton::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
{
const ViewInformation2D aNewViewInfos;
const unique_ptr<BaseProcessor2D> pProcessor(
createBaseProcessor2DFromOutputDevice(rRenderContext, aNewViewInfos));
const Rectangle aRect(Point(0, 0), PixelToLogic(GetSizePixel()));
drawinglayer::primitive2d::Primitive2DSequence aSeq(2);
BColor aLightColor;
BColor aDarkColor;
lclDetermineLightDarkColor(aLightColor, aDarkColor);
// Light background
B2DPolygon aPolygon;
aPolygon.append(B2DPoint(aRect.Left(), aRect.Top()));
aPolygon.append(B2DPoint(aRect.Right(), aRect.Top()));
aPolygon.append(B2DPoint(aRect.Right(), aRect.Bottom()));
aPolygon.append(B2DPoint(aRect.Left(), aRect.Bottom()));
aPolygon.setClosed(true);
PolyPolygonColorPrimitive2D* pBack =
new PolyPolygonColorPrimitive2D(B2DPolyPolygon(aPolygon), aLightColor);
aSeq[0] = pBack;
LineAttribute aLineAttribute(aDarkColor, 2.0);
// Cross
B2DPolyPolygon aCross;
B2DPolygon aLine1;
aLine1.append(B2DPoint(aRect.Left(), aRect.Top()));
aLine1.append(B2DPoint(aRect.Right(), aRect.Bottom()));
aCross.append(aLine1);
B2DPolygon aLine2;
aLine2.append(B2DPoint(aRect.Right(), aRect.Top()));
aLine2.append(B2DPoint(aRect.Left(), aRect.Bottom()));
aCross.append(aLine2);
PolyPolygonStrokePrimitive2D* pCross =
new PolyPolygonStrokePrimitive2D(aCross, aLineAttribute, StrokeAttribute());
aSeq[1] = pCross;
pProcessor->process(aSeq);
}
} // anonymous namespace
SfxInfoBarWindow::SfxInfoBarWindow(vcl::Window* pParent, const OUString& sId,
const OUString& sMessage) :
Window(pParent, 0),
m_sId(sId),
m_pMessage(VclPtr<FixedText>::Create(this, 0)),
m_pCloseBtn(VclPtr<SfxCloseButton>::Create(this)),
m_aActionBtns()
{
sal_Int32 nScaleFactor = GetDPIScaleFactor();
long nWidth = pParent->GetSizePixel().getWidth();
SetPosSizePixel(Point(0, 0), Size(nWidth, INFO_BAR_BASE_HEIGHT * nScaleFactor));
m_pMessage->SetText(sMessage);
m_pMessage->SetBackground(Wallpaper(Color(constLightColor)));
m_pMessage->Show();
m_pCloseBtn->SetClickHdl(LINK(this, SfxInfoBarWindow, CloseHandler));
m_pCloseBtn->Show();
Resize();
}
void SfxInfoBarWindow::addButton(PushButton* pButton) {
pButton->SetParent(this);
pButton->Show();
m_aActionBtns.push_back(pButton);
Resize();
}
SfxInfoBarWindow::~SfxInfoBarWindow()
{
disposeOnce();
}
void SfxInfoBarWindow::dispose()
{
for ( auto it = m_aActionBtns.begin( ); it != m_aActionBtns.end( ); ++it )
it->disposeAndClear();
m_pMessage.disposeAndClear();
m_pCloseBtn.disposeAndClear();
m_aActionBtns.clear( );
vcl::Window::dispose();
}
void SfxInfoBarWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rPaintRect)
{
const ViewInformation2D aNewViewInfos;
const unique_ptr<BaseProcessor2D> pProcessor(
createBaseProcessor2DFromOutputDevice(rRenderContext, aNewViewInfos));
const Rectangle aRect(Point(0, 0), PixelToLogic(GetSizePixel()));
drawinglayer::primitive2d::Primitive2DSequence aSeq(2);
BColor aLightColor;
BColor aDarkColor;
lclDetermineLightDarkColor(aLightColor, aDarkColor);
// Update the label background color
m_pMessage->SetBackground(Wallpaper(Color(aLightColor)));
// Light background
B2DPolygon aPolygon;
aPolygon.append(B2DPoint(aRect.Left(), aRect.Top()));
aPolygon.append(B2DPoint(aRect.Right(), aRect.Top()));
aPolygon.append(B2DPoint(aRect.Right(), aRect.Bottom()));
aPolygon.append(B2DPoint(aRect.Left(), aRect.Bottom()));
aPolygon.setClosed(true);
PolyPolygonColorPrimitive2D* pBack =
new PolyPolygonColorPrimitive2D(B2DPolyPolygon(aPolygon), aLightColor);
aSeq[0] = pBack;
LineAttribute aLineAttribute(aDarkColor, 1.0);
// Bottom dark line
B2DPolygon aPolygonBottom;
aPolygonBottom.append(B2DPoint(aRect.Left(), aRect.Bottom()));
aPolygonBottom.append(B2DPoint(aRect.Right(), aRect.Bottom()));
PolygonStrokePrimitive2D* pLineBottom =
new PolygonStrokePrimitive2D (aPolygonBottom, aLineAttribute);
aSeq[1] = pLineBottom;
pProcessor->process(aSeq);
Window::Paint(rRenderContext, rPaintRect);
}
void SfxInfoBarWindow::Resize()
{
sal_Int32 nScaleFactor = GetDPIScaleFactor();
long nWidth = GetSizePixel().getWidth();
m_pCloseBtn->SetPosSizePixel(Point(nWidth - 25 * nScaleFactor, 15 * nScaleFactor), Size(10 * nScaleFactor, 10 * nScaleFactor));
// Reparent the buttons and place them on the right of the bar
long nX = m_pCloseBtn->GetPosPixel().getX() - 15 * nScaleFactor;
long nButtonGap = 5 * nScaleFactor;
for (auto it = m_aActionBtns.begin(); it != m_aActionBtns.end(); ++it)
{
long nButtonWidth = (*it)->GetSizePixel().getWidth();
nX -= nButtonWidth;
(*it)->SetPosSizePixel(Point(nX, 5 * nScaleFactor), Size(nButtonWidth, 30 * nScaleFactor));
nX -= nButtonGap;
}
Point aMessagePosition(10 * nScaleFactor, 10 * nScaleFactor);
Size aMessageSize(nX - 20 * nScaleFactor, 20 * nScaleFactor);
m_pMessage->SetPosSizePixel(aMessagePosition, aMessageSize);
}
IMPL_LINK_NOARG(SfxInfoBarWindow, CloseHandler)
{
static_cast<SfxInfoBarContainerWindow*>(GetParent())->removeInfoBar(this);
return 0;
}
SfxInfoBarContainerWindow::SfxInfoBarContainerWindow(SfxInfoBarContainerChild* pChildWin ) :
Window(pChildWin->GetParent(), 0),
m_pChildWin(pChildWin),
m_pInfoBars()
{
}
SfxInfoBarContainerWindow::~SfxInfoBarContainerWindow()
{
disposeOnce();
}
void SfxInfoBarContainerWindow::dispose()
{
for ( auto it = m_pInfoBars.begin( ); it != m_pInfoBars.end( ); ++it )
it->disposeAndClear();
m_pInfoBars.clear( );
Window::dispose();
}
SfxInfoBarWindow* SfxInfoBarContainerWindow::appendInfoBar(const OUString& sId, const OUString& sMessage)
{
Size aSize = GetSizePixel();
VclPtrInstance<SfxInfoBarWindow> pInfoBar(this, sId, sMessage);
pInfoBar->SetPosPixel(Point(0, aSize.getHeight()));
pInfoBar->Show();
m_pInfoBars.push_back(pInfoBar);
long nHeight = pInfoBar->GetSizePixel().getHeight();
aSize.setHeight(aSize.getHeight() + nHeight);
SetSizePixel(aSize);
return pInfoBar;
}
SfxInfoBarWindow* SfxInfoBarContainerWindow::getInfoBar(const OUString& sId)
{
for (auto it = m_pInfoBars.begin(); it != m_pInfoBars.end(); ++it)
{
if ((*it)->getId() == sId)
return it->get();
}
return NULL;
}
void SfxInfoBarContainerWindow::removeInfoBar(SfxInfoBarWindow* pInfoBar)
{
// Store a VclPtr to the pInfoBar while we remove it from m_pInfoBars
ScopedVclPtr<SfxInfoBarWindow> pTmp(pInfoBar);
// Remove
for (auto it = m_pInfoBars.begin(); it != m_pInfoBars.end(); ++it)
{
if (pInfoBar == it->get())
{
it->disposeAndClear();
m_pInfoBars.erase(it);
break;
}
}
// Resize
long nY = 0;
for (auto it = m_pInfoBars.begin(); it != m_pInfoBars.end(); ++it)
{
(*it)->SetPosPixel(Point(0, nY));
nY += (*it)->GetSizePixel().getHeight();
}
Size aSize = GetSizePixel();
aSize.setHeight(nY);
SetSizePixel(aSize);
m_pChildWin->Update();
}
void SfxInfoBarContainerWindow::Resize()
{
// Only need to change the width of the infobars
long nWidth = GetSizePixel().getWidth();
for (auto it = m_pInfoBars.begin(); it != m_pInfoBars.end(); ++it)
{
Size aSize = (*it)->GetSizePixel();
aSize.setWidth(nWidth);
(*it)->SetSizePixel(aSize);
(*it)->Resize();
}
}
SFX_IMPL_POS_CHILDWINDOW_WITHID(SfxInfoBarContainerChild, SID_INFOBAR, SFX_OBJECTBAR_OBJECT);
SfxInfoBarContainerChild::SfxInfoBarContainerChild( vcl::Window* _pParent, sal_uInt16 nId, SfxBindings* pBindings, SfxChildWinInfo* ) :
SfxChildWindow(_pParent, nId),
m_pBindings(pBindings)
{
SetWindow( VclPtr<SfxInfoBarContainerWindow>::Create(this) );
GetWindow()->SetPosSizePixel(Point(0, 0), Size(_pParent->GetSizePixel().getWidth(), 0));
GetWindow()->Show();
SetAlignment(SfxChildAlignment::LOWESTTOP);
}
SfxInfoBarContainerChild::~SfxInfoBarContainerChild()
{
}
SfxChildWinInfo SfxInfoBarContainerChild::GetInfo() const
{
SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
return aInfo;
}
void SfxInfoBarContainerChild::Update()
{
// Refresh the frame to take the infobars container height change into account
const sal_uInt16 nId = GetChildWindowId();
SfxViewFrame* pVFrame = m_pBindings->GetDispatcher()->GetFrame();
pVFrame->ShowChildWindow(nId);
// Give the focus to the document view
pVFrame->GetWindow().GrabFocusToDocument();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|