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
|
/* -*- 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 "AppIconControl.hxx"
#include <core_resource.hxx>
#include <strings.hrc>
#include <bitmaps.hlst>
#include <sfx2/thumbnailviewitem.hxx>
#include <vcl/bitmapex.hxx>
#include <vcl/event.hxx>
#include <vcl/i18nhelp.hxx>
#include <vcl/mnemonic.hxx>
#include <vcl/settings.hxx>
#include <vcl/svapp.hxx>
#include <callbacks.hxx>
#include <AppElementType.hxx>
namespace dbaui
{
class OApplicationIconControlDropTarget final : public DropTargetHelper
{
private:
OApplicationIconControl& m_rControl;
public:
OApplicationIconControlDropTarget(OApplicationIconControl& rControl)
: DropTargetHelper(rControl.GetDrawingArea()->get_drop_target())
, m_rControl(rControl)
{
}
virtual sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt) override
{
return m_rControl.AcceptDrop(rEvt);
}
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt) override
{
return m_rControl.ExecuteDrop(rEvt);
}
};
OApplicationIconControl::OApplicationIconControl(std::unique_ptr<weld::ScrolledWindow> xScroll)
: ThumbnailView(std::move(xScroll), nullptr)
, m_pActionListener(nullptr)
, m_nMaxWidth(0)
, m_nMaxHeight(0)
{
mnVItemSpace = 6; // row spacing
mbSelectOnFocus = false;
DrawMnemonics(true);
}
void OApplicationIconControl::Fill()
{
static const struct CategoryDescriptor
{
TranslateId pLabelResId;
ElementType eType;
rtl::OUStringConstExpr aImageResId;
} aCategories[] = { { RID_STR_TABLES_CONTAINER, E_TABLE, BMP_TABLEFOLDER_TREE_L },
{ RID_STR_QUERIES_CONTAINER, E_QUERY, BMP_QUERYFOLDER_TREE_L },
{ RID_STR_FORMS_CONTAINER, E_FORM, BMP_FORMFOLDER_TREE_L },
{ RID_STR_REPORTS_CONTAINER, E_REPORT, BMP_REPORTFOLDER_TREE_L } };
for (const CategoryDescriptor& aCategorie : aCategories)
{
// E_TABLE is 0, but 0 means void so use id of enum + 1
std::unique_ptr<ThumbnailViewItem> xItem(
new ThumbnailViewItem(*this, aCategorie.eType + 1));
xItem->mbBorder = false;
xItem->maPreview1 = BitmapEx(aCategorie.aImageResId);
const Size& rSize = xItem->maPreview1.GetSizePixel();
m_nMaxWidth = std::max(m_nMaxWidth, rSize.Width());
m_nMaxHeight = std::max(m_nMaxHeight, rSize.Height());
xItem->maTitle = DBA_RES(aCategorie.pLabelResId);
m_nMaxWidth = std::max<tools::Long>(m_nMaxWidth, GetTextWidth(xItem->maTitle));
AppendItem(std::move(xItem));
}
const int nMargin = 12;
const int nWidthRequest = m_nMaxWidth + 2 * nMargin;
set_size_request(nWidthRequest, -1);
// we expect a Resize at which point we'll set the item sizes based on our final size
}
ElementType OApplicationIconControl::GetSelectedItem() const
{
for (const auto& rItem : mItemList)
{
if (!rItem->mbSelected)
continue;
return static_cast<ElementType>(rItem->mnId - 1);
}
return E_NONE;
}
void OApplicationIconControl::createIconAutoMnemonics(MnemonicGenerator& rMnemonics)
{
for (const auto& rItem : mItemList)
rMnemonics.RegisterMnemonic(rItem->maTitle);
// exchange texts with generated mnemonics
for (auto& rItem : mItemList)
rItem->maTitle = rMnemonics.CreateMnemonic(rItem->maTitle);
}
void OApplicationIconControl::Resize()
{
// fill the full width of the allocated area and give two lines of space to
// center the title in
setItemDimensions(GetOutputSizePixel().Width(), m_nMaxHeight, GetTextHeight() * 2, 0);
ThumbnailView::Resize();
}
bool OApplicationIconControl::IsMnemonicChar(sal_Unicode cChar, ElementType& rType) const
{
bool bRet = false;
const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
for (const auto& rItem : mItemList)
{
if (rI18nHelper.MatchMnemonic(rItem->maTitle, cChar))
{
bRet = true;
rType = static_cast<ElementType>(rItem->mnId - 1);
break;
}
}
return bRet;
}
bool OApplicationIconControl::DoKeyShortCut(const KeyEvent& rKEvt)
{
bool bMod2 = rKEvt.GetKeyCode().IsMod2();
sal_Unicode cChar = rKEvt.GetCharCode();
ElementType eType(E_NONE);
if (bMod2 && cChar && IsMnemonicChar(cChar, eType))
{
// shortcut is clicked
deselectItems();
SelectItem(eType + 1);
return true;
}
return false;
}
bool OApplicationIconControl::KeyInput(const KeyEvent& rKEvt)
{
return DoKeyShortCut(rKEvt) || ThumbnailView::KeyInput(rKEvt);
}
void OApplicationIconControl::SetDrawingArea(weld::DrawingArea* pDrawingArea)
{
ThumbnailView::SetDrawingArea(pDrawingArea);
m_xDropTarget.reset(new OApplicationIconControlDropTarget(*this));
}
sal_Int8 OApplicationIconControl::AcceptDrop(const AcceptDropEvent& rEvt)
{
sal_Int8 nDropOption = DND_ACTION_NONE;
if (m_pActionListener)
{
sal_uInt16 nEntry = GetItemId(rEvt.maPosPixel);
if (nEntry)
{
deselectItems();
SelectItem(nEntry);
nDropOption
= m_pActionListener->queryDrop(rEvt, m_xDropTarget->GetDataFlavorExVector());
}
}
return nDropOption;
}
sal_Int8 OApplicationIconControl::ExecuteDrop(const ExecuteDropEvent& rEvt)
{
if (m_pActionListener)
m_pActionListener->executeDrop(rEvt);
return DND_ACTION_NONE;
}
OApplicationIconControl::~OApplicationIconControl() {}
void OApplicationIconControl::GetFocus()
{
ThumbnailView::GetFocus();
Invalidate(); // redraw focus rect
}
void OApplicationIconControl::LoseFocus()
{
ThumbnailView::LoseFocus();
Invalidate(); // redraw focus rect
}
tools::Rectangle OApplicationIconControl::GetFocusRect()
{
if (HasFocus())
{
// Get the last selected item in the list
for (tools::Long i = mFilteredItemList.size() - 1; i >= 0; --i)
{
ThumbnailViewItem* pItem = mFilteredItemList[i];
if (pItem->isSelected())
{
tools::Rectangle aRet(pItem->getDrawArea());
aRet.AdjustLeft(THUMBNAILVIEW_ITEM_CORNER);
aRet.AdjustTop(1);
aRet.AdjustRight(-THUMBNAILVIEW_ITEM_CORNER);
aRet.AdjustBottom(-2);
return aRet;
}
}
}
return tools::Rectangle();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|