Kaydet (Commit) 389d4d41 authored tarafından Miklos Vajna's avatar Miklos Vajna

sfx2: introduce SfxViewShell::GetViewShellId()

This is quite similar to SwFrame::GetFrameId(), i.e. it assigns a
numeric identifier to each instance to help debugging, as those
identifiers are stable accross runs.

Change-Id: I9cc57e316435f0284a1d481a956a703be859d67e
Reviewed-on: https://gerrit.libreoffice.org/27669Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 4b90c9dc
......@@ -150,9 +150,6 @@ public:
// ScAddInAsync* keys if that set is not empty at exit
|| name == "g_aWindowList"
//vcl/unx/gtk/a11y/atkutil.cxx, asserted empty at exit
|| name=="aViewMap"
// sfx2/source/view/lokhelper.cxx, not owning, leaked by
// (mis-)design
) // these variables appear unproblematic
{
return true;
......
......@@ -334,6 +334,7 @@ public:
/// See lok::Document::getPart().
virtual int getPart() const;
virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const;
sal_uInt32 GetViewShellId() const;
};
......
......@@ -17,42 +17,24 @@
#include <shellimpl.hxx>
namespace
{
/// Assigns a view ID to a view shell.
int shellToView(SfxViewShell* pViewShell)
{
// Deleted view shells are not removed from this map, so view IDs are not
// reused when deleting, then creating a view.
static std::map<SfxViewShell*, int> aViewMap;
auto it = aViewMap.find(pViewShell);
if (it != aViewMap.end())
return it->second;
int nViewId = aViewMap.size();
aViewMap[pViewShell] = nViewId;
return nViewId;
}
}
int SfxLokHelper::createView()
{
SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
SfxRequest aRequest(pViewFrame, SID_NEWWINDOW);
pViewFrame->ExecView_Impl(aRequest);
return shellToView(SfxViewShell::Current());
return SfxViewShell::Current()->GetViewShellId();
}
void SfxLokHelper::destroyView(int nId)
{
unsigned nViewShellId = nId;
SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
for (std::size_t i = 0; i < rViewArr.size(); ++i)
{
SfxViewShell* pViewShell = rViewArr[i];
if (shellToView(pViewShell) == nId)
if (pViewShell->GetViewShellId() == nViewShellId)
{
SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
SfxRequest aRequest(pViewFrame, SID_CLOSEWIN);
......@@ -64,12 +46,13 @@ void SfxLokHelper::destroyView(int nId)
void SfxLokHelper::setView(int nId)
{
unsigned nViewShellId = nId;
SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
for (std::size_t i = 0; i < rViewArr.size(); ++i)
{
SfxViewShell* pViewShell = rViewArr[i];
if (shellToView(pViewShell) == nId)
if (pViewShell->GetViewShellId() == nViewShellId)
{
if (pViewShell == SfxViewShell::Current())
return;
......@@ -86,7 +69,7 @@ int SfxLokHelper::getView(SfxViewShell* pViewShell)
{
if (!pViewShell)
pViewShell = SfxViewShell::Current();
return shellToView(pViewShell);
return pViewShell->GetViewShellId();
}
std::size_t SfxLokHelper::getViews()
......
......@@ -62,6 +62,8 @@ struct SfxViewShell_Impl
void* m_pLibreOfficeKitViewData;
/// Set if we are in the middle of a tiled search.
bool m_bTiledSearching;
static sal_uInt32 m_nLastViewShellId;
const sal_uInt32 m_nViewShellId;
explicit SfxViewShell_Impl(SfxViewShellFlags const nFlags);
~SfxViewShell_Impl();
......
......@@ -238,6 +238,8 @@ public:
size_t size() const { return maData.size(); }
};
sal_uInt32 SfxViewShell_Impl::m_nLastViewShellId = 0;
SfxViewShell_Impl::SfxViewShell_Impl(SfxViewShellFlags const nFlags)
: aInterceptorContainer( aMutex )
, m_bControllerSet(false)
......@@ -252,6 +254,7 @@ SfxViewShell_Impl::SfxViewShell_Impl(SfxViewShellFlags const nFlags)
, m_pLibreOfficeKitViewCallback(nullptr)
, m_pLibreOfficeKitViewData(nullptr)
, m_bTiledSearching(false)
, m_nViewShellId(SfxViewShell_Impl::m_nLastViewShellId++)
{}
SfxViewShell_Impl::~SfxViewShell_Impl()
......@@ -1502,10 +1505,16 @@ int SfxViewShell::getPart() const
return 0;
}
sal_uInt32 SfxViewShell::GetViewShellId() const
{
return pImpl->m_nViewShellId;
}
void SfxViewShell::dumpAsXml(xmlTextWriterPtr pWriter) const
{
xmlTextWriterStartElement(pWriter, BAD_CAST("sfxViewShell"));
xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("id"), BAD_CAST(OString::number(GetViewShellId()).getStr()));
xmlTextWriterEndElement(pWriter);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment