LibreOffice Module dbaccess (master) 1
AppIconControl.cxx
Go to the documentation of this file.
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 "AppIconControl.hxx"
21#include <core_resource.hxx>
22#include <strings.hrc>
23#include <bitmaps.hlst>
25#include <vcl/bitmapex.hxx>
26#include <vcl/event.hxx>
27#include <vcl/i18nhelp.hxx>
28#include <vcl/mnemonic.hxx>
29#include <vcl/settings.hxx>
30#include <vcl/svapp.hxx>
31#include <callbacks.hxx>
32#include <AppElementType.hxx>
33
34namespace dbaui
35{
36class OApplicationIconControlDropTarget final : public DropTargetHelper
37{
38private:
40
41public:
43 : DropTargetHelper(rControl.GetDrawingArea()->get_drop_target())
44 , m_rControl(rControl)
45 {
46 }
47
48 virtual sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt) override
49 {
50 return m_rControl.AcceptDrop(rEvt);
51 }
52
53 virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt) override
54 {
55 return m_rControl.ExecuteDrop(rEvt);
56 }
57};
58
59OApplicationIconControl::OApplicationIconControl(std::unique_ptr<weld::ScrolledWindow> xScroll)
60 : ThumbnailView(std::move(xScroll), nullptr)
61 , m_pActionListener(nullptr)
62 , m_nMaxWidth(0)
63 , m_nMaxHeight(0)
64{
65 mnVItemSpace = 6; // row spacing
66 mbSelectOnFocus = false;
67 DrawMnemonics(true);
68}
69
71{
72 static const struct CategoryDescriptor
73 {
74 TranslateId pLabelResId;
76 rtl::OUStringConstExpr aImageResId;
77 } aCategories[] = { { RID_STR_TABLES_CONTAINER, E_TABLE, BMP_TABLEFOLDER_TREE_L },
78 { RID_STR_QUERIES_CONTAINER, E_QUERY, BMP_QUERYFOLDER_TREE_L },
79 { RID_STR_FORMS_CONTAINER, E_FORM, BMP_FORMFOLDER_TREE_L },
80 { RID_STR_REPORTS_CONTAINER, E_REPORT, BMP_REPORTFOLDER_TREE_L } };
81
82 for (const CategoryDescriptor& aCategorie : aCategories)
83 {
84 // E_TABLE is 0, but 0 means void so use id of enum + 1
85 std::unique_ptr<ThumbnailViewItem> xItem(
86 new ThumbnailViewItem(*this, aCategorie.eType + 1));
87 xItem->mbBorder = false;
88 xItem->maPreview1 = BitmapEx(aCategorie.aImageResId);
89 const Size& rSize = xItem->maPreview1.GetSizePixel();
90 m_nMaxWidth = std::max(m_nMaxWidth, rSize.Width());
91 m_nMaxHeight = std::max(m_nMaxHeight, rSize.Height());
92 xItem->maTitle = DBA_RES(aCategorie.pLabelResId);
93 m_nMaxWidth = std::max<tools::Long>(m_nMaxWidth, GetTextWidth(xItem->maTitle));
94 AppendItem(std::move(xItem));
95 }
96
97 const int nMargin = 12;
98 const int nWidthRequest = m_nMaxWidth + 2 * nMargin;
99 set_size_request(nWidthRequest, -1);
100 // we expect a Resize at which point we'll set the item sizes based on our final size
101}
102
104{
105 for (const auto& rItem : mItemList)
106 {
107 if (!rItem->mbSelected)
108 continue;
109 return static_cast<ElementType>(rItem->mnId - 1);
110 }
111 return E_NONE;
112}
113
115{
116 for (const auto& rItem : mItemList)
117 rMnemonics.RegisterMnemonic(rItem->maTitle);
118
119 // exchange texts with generated mnemonics
120 for (auto& rItem : mItemList)
121 rItem->maTitle = rMnemonics.CreateMnemonic(rItem->maTitle);
122}
123
125{
126 // fill the full width of the allocated area and give two lines of space to
127 // center the title in
128 setItemDimensions(GetOutputSizePixel().Width(), m_nMaxHeight, GetTextHeight() * 2, 0);
130}
131
133{
134 bool bRet = false;
135
137 for (const auto& rItem : mItemList)
138 {
139 if (rI18nHelper.MatchMnemonic(rItem->maTitle, cChar))
140 {
141 bRet = true;
142 rType = static_cast<ElementType>(rItem->mnId - 1);
143 break;
144 }
145 }
146
147 return bRet;
148}
149
151{
152 bool bMod2 = rKEvt.GetKeyCode().IsMod2();
153 sal_Unicode cChar = rKEvt.GetCharCode();
155 if (bMod2 && cChar && IsMnemonicChar(cChar, eType))
156 {
157 // shortcut is clicked
159 SelectItem(eType + 1);
160 return true;
161 }
162
163 return false;
164}
165
167{
168 return DoKeyShortCut(rKEvt) || ThumbnailView::KeyInput(rKEvt);
169}
170
172{
173 ThumbnailView::SetDrawingArea(pDrawingArea);
175}
176
178{
179 sal_Int8 nDropOption = DND_ACTION_NONE;
181 {
182 sal_uInt16 nEntry = GetItemId(rEvt.maPosPixel);
183 if (nEntry)
184 {
186 SelectItem(nEntry);
187 nDropOption
188 = m_pActionListener->queryDrop(rEvt, m_xDropTarget->GetDataFlavorExVector());
189 }
190 }
191 return nDropOption;
192}
193
195{
198 return DND_ACTION_NONE;
199}
200
202
204{
206 Invalidate(); // redraw focus rect
207}
208
210{
212 Invalidate(); // redraw focus rect
213}
214
216{
217 if (HasFocus())
218 {
219 // Get the last selected item in the list
220 for (tools::Long i = mFilteredItemList.size() - 1; i >= 0; --i)
221 {
223 if (pItem->isSelected())
224 {
225 tools::Rectangle aRet(pItem->getDrawArea());
227 aRet.AdjustTop(1);
229 aRet.AdjustBottom(-2);
230 return aRet;
231 }
232 }
233 }
234 return tools::Rectangle();
235}
236}
237
238/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const vcl::I18nHelper & GetUILocaleI18nHelper() const
static const AllSettings & GetSettings()
sal_Unicode GetCharCode() const
const vcl::KeyCode & GetKeyCode() const
void RegisterMnemonic(const OUString &rKey)
OUString CreateMnemonic(const OUString &rKey)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
bool isSelected() const
const tools::Rectangle & getDrawArea() const
void deselectItems()
tools::Long mnVItemSpace
sal_uInt16 GetItemId(size_t nPos) const
virtual bool KeyInput(const KeyEvent &rKEvt) override
virtual void Resize() override
bool mbSelectOnFocus
void AppendItem(std::unique_ptr< ThumbnailViewItem > pItem)
void setItemDimensions(tools::Long ItemWidth, tools::Long ThumbnailHeight, tools::Long DisplayHeight, int itemPadding)
virtual void LoseFocus() override
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
virtual void GetFocus() override
void DrawMnemonics(bool bDrawMnemonics)
void SelectItem(sal_uInt16 nItemId)
std::vector< std::unique_ptr< ThumbnailViewItem > > mItemList
ThumbnailValueItemList mFilteredItemList
virtual sal_Int8 queryDrop(const AcceptDropEvent &_rEvt, const DataFlavorExVector &_rFlavors)=0
check whether or not a drop request should be accepted
virtual sal_Int8 executeDrop(const ExecuteDropEvent &_rEvt)=0
execute a drop request
OApplicationIconControlDropTarget(OApplicationIconControl &rControl)
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
std::unique_ptr< OApplicationIconControlDropTarget > m_xDropTarget
IControlActionListener * m_pActionListener
virtual void LoseFocus() override
ElementType GetSelectedItem() const
bool DoKeyShortCut(const KeyEvent &rKEvt)
virtual void GetFocus() override
void createIconAutoMnemonics(MnemonicGenerator &rMnemonics)
OApplicationIconControl(std::unique_ptr< weld::ScrolledWindow > xScroll)
sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt)
virtual tools::Rectangle GetFocusRect() override
virtual void Resize() override
virtual ~OApplicationIconControl() override
sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt)
virtual bool KeyInput(const KeyEvent &rKEvt) override
bool IsMnemonicChar(sal_Unicode cChar, ElementType &rType) const
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
tools::Long AdjustTop(tools::Long nVertMoveDelta)
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
bool MatchMnemonic(std::u16string_view rString, sal_Unicode cMnemonicChar) const
bool IsMod2() const
#define DBA_RES(id)
OUString eType
Definition: generalpage.cxx:78
int i
long Long
const int THUMBNAILVIEW_ITEM_CORNER
#define DND_ACTION_NONE
sal_uInt16 sal_Unicode
signed char sal_Int8