Files
libreoffice/vcl/inc/jsdialog/jsdialogregister.hxx
Szymon Kłos 969f242f2e jsdialog: share code for widget registry
- move all helpers for widgets registration into
  separate file
- share code for Widgets, Menu and Popup register

Change-Id: I3449721d7e436ff4459edb7990c1af860b78054f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177738
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178205
Tested-by: Jenkins
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
2024-12-10 12:15:42 +01:00

53 lines
1.3 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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/.
*/
#pragma once
#include <map>
#include <rtl/ustring.hxx>
namespace jsdialog
{
template <class T> class WidgetRegister
{
// Map to remember the LOKWindowId <-> widget binding.
std::map<OUString, T> m_aWidgetMap;
std::map<OUString, T>& Map() { return m_aWidgetMap; }
public:
void Remember(const OUString& rId, T pWidget);
void Forget(const OUString& rId);
T Find(const OUString& rId);
};
template <class T> void WidgetRegister<T>::Remember(const OUString& nWindowId, T pMenu)
{
Map()[nWindowId] = pMenu;
}
template <class T> void WidgetRegister<T>::Forget(const OUString& nWindowId)
{
auto it = Map().find(nWindowId);
if (it != Map().end())
Map().erase(it);
}
template <class T> T WidgetRegister<T>::Find(const OUString& nWindowId)
{
const auto it = Map().find(nWindowId);
if (it != Map().end())
return it->second;
return nullptr;
}
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */