Kaydet (Commit) 470db78e authored tarafından Miklos Vajna's avatar Miklos Vajna

lok::Document: add get/setView()

Change-Id: Ic3bce8f01d7e048e853c063c4bce1255845c60d0
(cherry picked from commit 46588c42)
üst a0b7695a
......@@ -139,6 +139,12 @@ void DesktopLOKTest::testCreateView()
int nId = pDocument->m_pDocumentClass->createView(pDocument);
CPPUNIT_ASSERT_EQUAL(2, SfxLokHelper::getViews());
// Make sure the created view is the active one, then switch to the old
// one.
CPPUNIT_ASSERT_EQUAL(1, pDocument->m_pDocumentClass->getView(pDocument));
pDocument->m_pDocumentClass->setView(pDocument, 0);
CPPUNIT_ASSERT_EQUAL(0, pDocument->m_pDocumentClass->getView(pDocument));
pDocument->m_pDocumentClass->destroyView(pDocument, nId);
CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
closeDoc();
......
......@@ -252,6 +252,8 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
static int doc_createView(LibreOfficeKitDocument* pThis);
static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId);
static void doc_setView(LibreOfficeKitDocument* pThis, int nId);
static int doc_getView(LibreOfficeKitDocument* pThis);
LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) :
mxComponent( xComponent )
......@@ -285,6 +287,8 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->createView = doc_createView;
m_pDocumentClass->destroyView = doc_destroyView;
m_pDocumentClass->setView = doc_setView;
m_pDocumentClass->getView = doc_getView;
gDocumentClass = m_pDocumentClass;
}
......@@ -1067,6 +1071,20 @@ static void doc_destroyView(LibreOfficeKitDocument* /*pThis*/, int nId)
SfxLokHelper::destroyView(nId);
}
static void doc_setView(LibreOfficeKitDocument* /*pThis*/, int nId)
{
SolarMutexGuard aGuard;
SfxLokHelper::setView(nId);
}
static int doc_getView(LibreOfficeKitDocument* /*pThis*/)
{
SolarMutexGuard aGuard;
return SfxLokHelper::getView();
}
static char* lo_getError (LibreOfficeKit *pThis)
{
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
......
......@@ -170,6 +170,10 @@ struct _LibreOfficeKitDocumentClass
int (*createView) (LibreOfficeKitDocument* pThis);
/// @see lok::Document::destroyView().
void (*destroyView) (LibreOfficeKitDocument* pThis, int nId);
/// @see lok::Document::setView().
void (*setView) (LibreOfficeKitDocument* pThis, int nId);
/// @see lok::Document::getView().
int (*getView) (LibreOfficeKitDocument* pThis);
#endif // LOK_USE_UNSTABLE_API
};
......
......@@ -269,13 +269,31 @@ public:
}
/**
* Destroy a view of an existring document.
* Destroy a view of an existing document.
* @param nId a view ID, returned by createView().
*/
void destroyView(int nId)
{
mpDoc->pClass->destroyView(mpDoc, nId);
}
/**
* Set an existing view of an existing document as current.
* @param nId a view ID, returned by createView().
*/
void setView(int nId)
{
mpDoc->pClass->setView(mpDoc, nId);
}
/**
* Get the current view.
* @return a view ID, previously returned by createView().
*/
int getView()
{
return mpDoc->pClass->getView(mpDoc);
}
#endif // LOK_USE_UNSTABLE_API
};
......
......@@ -21,6 +21,10 @@ public:
static int createView(SfxViewShell* pViewShell);
/// Destroy a view shell from the global shell list.
static void destroyView(size_t nId);
/// Set a view shell as current one.
static void setView(size_t nId);
/// Get the currently active view.
static size_t getView();
/// Total number of view shells.
static int getViews();
......
......@@ -38,6 +38,30 @@ void SfxLokHelper::destroyView(size_t nId)
pViewFrame->Exec_Impl(aRequest);
}
void SfxLokHelper::setView(size_t nId)
{
SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
if (nId > rViewArr.size() - 1)
return;
SfxViewShell* pViewShell = rViewArr[nId];
if (SfxViewFrame* pViewFrame = pViewShell->GetViewFrame())
pViewFrame->GetWindow().GrabFocus();
}
size_t SfxLokHelper::getView()
{
SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
SfxViewFrame* pViewFrame = SfxViewFrame::Current();
for (size_t i = 0; i < rViewArr.size(); ++i)
{
if (rViewArr[i]->GetViewFrame() == pViewFrame)
return i;
}
assert(false);
return 0;
}
int SfxLokHelper::getViews()
{
SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
......
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