diff options
Diffstat (limited to 'dbaccess/source/ui/app/AppIconControl.cxx')
-rw-r--r-- | dbaccess/source/ui/app/AppIconControl.cxx | 224 |
1 files changed, 178 insertions, 46 deletions
diff --git a/dbaccess/source/ui/app/AppIconControl.cxx b/dbaccess/source/ui/app/AppIconControl.cxx index 514580014f79..bd94d52c564b 100644 --- a/dbaccess/source/ui/app/AppIconControl.cxx +++ b/dbaccess/source/ui/app/AppIconControl.cxx @@ -21,86 +21,218 @@ #include <core_resource.hxx> #include <strings.hrc> #include <bitmaps.hlst> -#include <vcl/image.hxx> +#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> -using namespace ::dbaui; -OApplicationIconControl::OApplicationIconControl(vcl::Window* _pParent) - : SvtIconChoiceCtrl(_pParent,WB_ICON | WB_NOCOLUMNHEADER | WB_HIGHLIGHTFRAME | /*!WB_NOSELECTION |*/ - WB_TABSTOP | WB_CLIPCHILDREN | WB_NOVSCROLL | WB_SMART_ARRANGE | WB_NOHSCROLL | WB_CENTER) - ,DropTargetHelper(this) - ,m_pActionListener(nullptr) +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); + } - static const struct CategoryDescriptor + 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 constexpr struct CategoryDescriptor { - const char* pLabelResId; + TranslateId pLabelResId; ElementType eType; - const char* 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 } - }; + OUString 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) { - SvxIconChoiceCtrlEntry* pEntry = InsertEntry( - DBA_RES(aCategorie.pLabelResId) , - Image(StockImage::Yes, OUString::createFromAscii(aCategorie.aImageResId))); - if ( pEntry ) - pEntry->SetUserData( new ElementType( aCategorie.eType ) ); + // 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); - SetChoiceWithCursor(); - SetSelectionMode(SelectionMode::Single); + // exchange texts with generated mnemonics + for (auto& rItem : mItemList) + rItem->maTitle = rMnemonics.CreateMnemonic(rItem->maTitle); } -OApplicationIconControl::~OApplicationIconControl() +void OApplicationIconControl::Resize() { - disposeOnce(); + // 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(); } -void OApplicationIconControl::dispose() +bool OApplicationIconControl::IsMnemonicChar(sal_Unicode cChar, ElementType& rType) const { - sal_Int32 nCount = GetEntryCount(); - for ( sal_Int32 i = 0; i < nCount; ++i ) + bool bRet = false; + + const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper(); + for (const auto& rItem : mItemList) { - SvxIconChoiceCtrlEntry* pEntry = GetEntry( i ); - if ( pEntry ) + if (rI18nHelper.MatchMnemonic(rItem->maTitle, cChar)) { - delete static_cast<ElementType*>(pEntry->GetUserData()); - pEntry->SetUserData(nullptr); + bRet = true; + rType = static_cast<ElementType>(rItem->mnId - 1); + break; } } - DropTargetHelper::dispose(); - SvtIconChoiceCtrl::dispose(); + + return bRet; } -sal_Int8 OApplicationIconControl::AcceptDrop( const AcceptDropEvent& _rEvt ) +bool OApplicationIconControl::DoKeyShortCut(const KeyEvent& rKEvt) { - sal_Int8 nDropOption = DND_ACTION_NONE; - if ( m_pActionListener ) + 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; + } - SvxIconChoiceCtrlEntry* pEntry = GetEntry(_rEvt.maPosPixel); - if ( pEntry ) + 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) { - SetCursor(pEntry); - nDropOption = m_pActionListener->queryDrop( _rEvt, GetDataFlavorExVector() ); + deselectItems(); + SelectItem(nEntry); + nDropOption + = m_pActionListener->queryDrop(rEvt, m_xDropTarget->GetDataFlavorExVector()); } } - return nDropOption; } -sal_Int8 OApplicationIconControl::ExecuteDrop( const ExecuteDropEvent& _rEvt ) +sal_Int8 OApplicationIconControl::ExecuteDrop(const ExecuteDropEvent& rEvt) { - if ( m_pActionListener ) - return m_pActionListener->executeDrop( _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: */ |