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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
|
/* -*- 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 "TabBar.hxx"
#include "TabItem.hxx"
#include <sfx2/sidebar/ControlFactory.hxx>
#include "DeckDescriptor.hxx"
#include "Paint.hxx"
#include <sfx2/sidebar/Theme.hxx>
#include <sfx2/sidebar/Tools.hxx>
#include "FocusManager.hxx"
#include <vcl/gradient.hxx>
#include <vcl/image.hxx>
#include <vcl/wrkwin.hxx>
#include <comphelper/processfactory.hxx>
#include <tools/svborder.hxx>
#include <com/sun/star/graphic/XGraphicProvider.hpp>
using namespace css;
using namespace css::uno;
namespace sfx2 { namespace sidebar {
TabBar::TabBar (
vcl::Window* pParentWindow,
const Reference<frame::XFrame>& rxFrame,
const ::boost::function<void(const ::rtl::OUString&)>& rDeckActivationFunctor,
const PopupMenuProvider& rPopupMenuProvider)
: Window(pParentWindow, WB_DIALOGCONTROL),
mxFrame(rxFrame),
mpMenuButton(ControlFactory::CreateMenuButton(this)),
maItems(),
maDeckActivationFunctor(rDeckActivationFunctor),
maPopupMenuProvider(rPopupMenuProvider)
{
SetBackground(Theme::GetPaint(Theme::Paint_TabBarBackground).GetWallpaper());
mpMenuButton->SetModeImage(Theme::GetImage(Theme::Image_TabBarMenu));
mpMenuButton->SetClickHdl(LINK(this, TabBar, OnToolboxClicked));
Layout();
#ifdef DEBUG
SetText(OUString("TabBar"));
#endif
}
TabBar::~TabBar (void)
{
}
void TabBar::Paint (const Rectangle& rUpdateArea)
{
Window::Paint(rUpdateArea);
const sal_Int32 nHorizontalPadding (Theme::GetInteger(Theme::Int_TabMenuSeparatorPadding));
SetLineColor(Theme::GetColor(Theme::Color_TabMenuSeparator));
DrawLine(
Point(nHorizontalPadding, mnMenuSeparatorY),
Point(GetSizePixel().Width()-nHorizontalPadding, mnMenuSeparatorY));
}
sal_Int32 TabBar::GetDefaultWidth (void)
{
return Theme::GetInteger(Theme::Int_TabItemWidth)
+ Theme::GetInteger(Theme::Int_TabBarLeftPadding)
+ Theme::GetInteger(Theme::Int_TabBarRightPadding);
}
void TabBar::SetDecks (
const ResourceManager::DeckContextDescriptorContainer& rDecks)
{
// Remove the current buttons.
{
for(ItemContainer::iterator
iItem(maItems.begin()), iEnd(maItems.end());
iItem!=iEnd;
++iItem)
{
iItem->mpButton.reset();
}
maItems.clear();
}
maItems.resize(rDecks.size());
sal_Int32 nIndex (0);
for (ResourceManager::DeckContextDescriptorContainer::const_iterator
iDeck(rDecks.begin()),
iEnd(rDecks.end());
iDeck!=iEnd;
++iDeck)
{
const DeckDescriptor* pDescriptor = ResourceManager::Instance().GetDeckDescriptor(iDeck->msId);
if (pDescriptor == NULL)
{
OSL_ASSERT(pDescriptor!=NULL);
continue;
}
Item& rItem (maItems[nIndex++]);
rItem.msDeckId = pDescriptor->msId;
rItem.mpButton.reset(CreateTabItem(*pDescriptor));
rItem.mpButton->SetClickHdl(LINK(&rItem, TabBar::Item, HandleClick));
rItem.maDeckActivationFunctor = maDeckActivationFunctor;
rItem.mbIsHiddenByDefault = false;
rItem.mbIsHidden = ! pDescriptor->mbIsEnabled;
rItem.mpButton->Enable(iDeck->mbIsEnabled);
}
UpdateButtonIcons();
Layout();
}
void TabBar::UpdateButtonIcons (void)
{
Image aImage = Theme::GetImage(Theme::Image_TabBarMenu);
if ( mpMenuButton->GetDPIScaleFactor() > 1 )
{
BitmapEx b = aImage.GetBitmapEx();
b.Scale(mpMenuButton->GetDPIScaleFactor(), mpMenuButton->GetDPIScaleFactor(), BMP_SCALE_FAST);
aImage = Image(b);
}
mpMenuButton->SetModeImage(aImage);
for(ItemContainer::const_iterator
iItem(maItems.begin()), iEnd(maItems.end());
iItem!=iEnd;
++iItem)
{
const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(iItem->msDeckId);
if (pDeckDescriptor != NULL)
{
aImage = GetItemImage(*pDeckDescriptor);
if ( mpMenuButton->GetDPIScaleFactor() > 1 )
{
BitmapEx b = aImage.GetBitmapEx();
b.Scale(mpMenuButton->GetDPIScaleFactor(), mpMenuButton->GetDPIScaleFactor(), BMP_SCALE_FAST);
aImage = Image(b);
}
iItem->mpButton->SetModeImage(aImage);
}
}
Invalidate();
}
void TabBar::Layout (void)
{
const SvBorder aPadding (
Theme::GetInteger(Theme::Int_TabBarLeftPadding),
Theme::GetInteger(Theme::Int_TabBarTopPadding),
Theme::GetInteger(Theme::Int_TabBarRightPadding),
Theme::GetInteger(Theme::Int_TabBarBottomPadding));
sal_Int32 nX (aPadding.Top());
sal_Int32 nY (aPadding.Left());
const Size aTabItemSize (
Theme::GetInteger(Theme::Int_TabItemWidth) * GetDPIScaleFactor(),
Theme::GetInteger(Theme::Int_TabItemHeight) * GetDPIScaleFactor());
// Place the menu button and the separator.
if (mpMenuButton != 0)
{
mpMenuButton->SetPosSizePixel(
Point(nX,nY),
aTabItemSize);
mpMenuButton->Show();
nY += mpMenuButton->GetSizePixel().Height() + 1 + Theme::GetInteger(Theme::Int_TabMenuPadding);
mnMenuSeparatorY = nY - Theme::GetInteger(Theme::Int_TabMenuPadding)/2 - 1;
}
// Place the deck selection buttons.
for(ItemContainer::const_iterator
iItem(maItems.begin()), iEnd(maItems.end());
iItem!=iEnd;
++iItem)
{
Button& rButton (*iItem->mpButton);
rButton.Show( ! iItem->mbIsHidden);
if (iItem->mbIsHidden)
continue;
// Place and size the icon.
rButton.SetPosSizePixel(
Point(nX,nY),
aTabItemSize);
rButton.Show();
nY += rButton.GetSizePixel().Height() + 1 + aPadding.Bottom();
}
Invalidate();
}
void TabBar::HighlightDeck (const ::rtl::OUString& rsDeckId)
{
for (ItemContainer::iterator iItem(maItems.begin()),iEnd(maItems.end());
iItem!=iEnd;
++iItem)
{
if (iItem->msDeckId.equals(rsDeckId))
iItem->mpButton->Check(true);
else
iItem->mpButton->Check(false);
}
}
void TabBar::RemoveDeckHighlight ()
{
for (ItemContainer::iterator iItem(maItems.begin()),iEnd(maItems.end());
iItem!=iEnd;
++iItem)
{
iItem->mpButton->Check(false);
}
}
void TabBar::DataChanged (const DataChangedEvent& rDataChangedEvent)
{
SetBackground(Theme::GetPaint(Theme::Paint_TabBarBackground).GetWallpaper());
UpdateButtonIcons();
Window::DataChanged(rDataChangedEvent);
}
bool TabBar::Notify (NotifyEvent&)
{
return false;
}
RadioButton* TabBar::CreateTabItem (const DeckDescriptor& rDeckDescriptor)
{
RadioButton* pItem = ControlFactory::CreateTabItem(this);
pItem->SetHelpText(rDeckDescriptor.msHelpText);
pItem->SetQuickHelpText(rDeckDescriptor.msHelpText);
return pItem;
}
Image TabBar::GetItemImage (const DeckDescriptor& rDeckDescriptor) const
{
return Tools::GetImage(
rDeckDescriptor.msIconURL,
rDeckDescriptor.msHighContrastIconURL,
mxFrame);
}
IMPL_LINK(TabBar::Item, HandleClick, Button*, EMPTYARG)
{
try
{
maDeckActivationFunctor(msDeckId);
}
catch( const ::com::sun::star::uno::Exception&) {} // workaround for #i123198#
return 1;
}
const ::rtl::OUString TabBar::GetDeckIdForIndex (const sal_Int32 nIndex) const
{
if (nIndex<0 || static_cast<size_t>(nIndex)>=maItems.size())
throw RuntimeException();
else
return maItems[nIndex].msDeckId;
}
void TabBar::ToggleHideFlag (const sal_Int32 nIndex)
{
if (nIndex<0 || static_cast<size_t>(nIndex)>=maItems.size())
throw RuntimeException();
else
{
maItems[nIndex].mbIsHidden = ! maItems[nIndex].mbIsHidden;
ResourceManager::Instance().SetIsDeckEnabled(
maItems[nIndex].msDeckId,
maItems[nIndex].mbIsHidden);
Layout();
}
}
void TabBar::RestoreHideFlags (void)
{
bool bNeedsLayout (false);
for(ItemContainer::iterator iItem(maItems.begin()),iEnd(maItems.end());
iItem!=iEnd;
++iItem)
{
if (iItem->mbIsHidden != iItem->mbIsHiddenByDefault)
{
iItem->mbIsHidden = iItem->mbIsHiddenByDefault;
bNeedsLayout = true;
}
}
if (bNeedsLayout)
Layout();
}
void TabBar::UpdateFocusManager (FocusManager& rFocusManager)
{
::std::vector<Button*> aButtons;
aButtons.reserve(maItems.size()+1);
aButtons.push_back(mpMenuButton.get());
for(ItemContainer::const_iterator
iItem(maItems.begin()), iEnd(maItems.end());
iItem!=iEnd;
++iItem)
{
aButtons.push_back(iItem->mpButton.get());
}
rFocusManager.SetButtons(aButtons);
}
IMPL_LINK(TabBar, OnToolboxClicked, void*, EMPTYARG)
{
if ( ! mpMenuButton)
return 0;
::std::vector<DeckMenuData> aMenuData;
for(ItemContainer::const_iterator iItem(maItems.begin()),iEnd(maItems.end());
iItem!=iEnd;
++iItem)
{
const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(iItem->msDeckId);
if (pDeckDescriptor != NULL)
{
DeckMenuData aData;
aData.msDisplayName = pDeckDescriptor->msTitle;
aData.msDeckId = pDeckDescriptor->msId;
aData.mbIsCurrentDeck = iItem->mpButton->IsChecked();
aData.mbIsActive = !iItem->mbIsHidden;
aData.mbIsEnabled = iItem->mpButton->IsEnabled();
aMenuData.push_back(aData);
}
}
maPopupMenuProvider(
Rectangle(
mpMenuButton->GetPosPixel(),
mpMenuButton->GetSizePixel()),
aMenuData);
mpMenuButton->Check(false);
return 0;
}
} } // end of namespace sfx2::sidebar
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|