include/LibreOfficeKit/LibreOfficeKitInit.h | 9 ++- libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 47 +++++++++++++------- sw/inc/IDocumentUndoRedo.hxx | 9 ++- sw/inc/editsh.hxx | 7 ++ sw/qa/extras/tiledrendering/tiledrendering.cxx | 28 +++++++++++ sw/source/core/edit/edws.cxx | 14 ++++- sw/source/core/inc/UndoManager.hxx | 6 +- sw/source/core/undo/docundo.cxx | 22 ++++++++- sw/source/uibase/shells/basesh.cxx | 4 - sw/source/uibase/wrtsh/wrtundo.cxx | 4 - 10 files changed, 114 insertions(+), 36 deletions(-)
New commits: commit 4fbc3dbe44857b52677844c47a750abc40713d60 Author: Miklos Vajna <[email protected]> Date: Tue Aug 9 18:13:37 2016 +0200 sw lok: limit undo/redo access to undo actions created by the same view So one view can't undo the changes of an other view by accident. If this is found to be useful in the desktop case, perhaps a dedicated config option can be added for it; for now the behavior is LOK-only. Change-Id: I7ff505d021bd6f6be36953ecc8f8bb971ce8927e Reviewed-on: https://gerrit.libreoffice.org/28007 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins <[email protected]> (cherry picked from commit 5d8639aaf2f60157c99c3ee3a8bfa78e4efd010a) diff --git a/sw/inc/IDocumentUndoRedo.hxx b/sw/inc/IDocumentUndoRedo.hxx index d30d4c3..6c044f6 100644 --- a/sw/inc/IDocumentUndoRedo.hxx +++ b/sw/inc/IDocumentUndoRedo.hxx @@ -27,6 +27,7 @@ class SwRewriter; class SwNodes; class SwUndo; +class SwView; namespace sw { class RepeatContext; @@ -135,10 +136,12 @@ public: /** Get Id and comment of last Undo action. @param o_pStr if not 0, receives comment of last Undo action. @param o_pId if not 0, receives Id of last Undo action. + @param pView if not nullptr, get the info for this view @return true if there is a Undo action, false if none */ virtual bool GetLastUndoInfo(OUString *const o_pStr, - SwUndoId *const o_pId) const = 0; + SwUndoId *const o_pId, + const SwView* pView = nullptr) const = 0; /** Get comments of Undo actions. @return comments of all top-level Undo actions. @@ -154,10 +157,12 @@ public: /** Get Id and comment of first Redo action. @param o_pStr if not 0, receives comment of first Redo action. @param o_pId if not 0, receives Id of first Redo action. + @param pView if not nullptr, get the info for this view @return true if there is a Redo action, false if none */ virtual bool GetFirstRedoInfo(OUString *const o_pStr, - SwUndoId *const o_pId = nullptr) const = 0; + SwUndoId *const o_pId = nullptr, + const SwView* pView = nullptr) const = 0; /** Get comments of Redo actions. @return comments of all top-level Redo actions. diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index 7c2dd0e..e0ab5c7 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -97,6 +97,7 @@ class SwEndNoteInfo; class SwLineNumberInfo; class SwAuthEntry; class SwRewriter; +class SwView; struct SwConversionArgs; enum class SvtScriptType; enum class SfxClassificationPolicyType; @@ -561,8 +562,10 @@ public: SwUndoId EndUndo( SwUndoId eUndoId = UNDO_EMPTY, const SwRewriter * pRewriter = nullptr ); bool GetLastUndoInfo(OUString *const o_pStr, - SwUndoId *const o_pId) const; - bool GetFirstRedoInfo(OUString *const o_pStr) const; + SwUndoId *const o_pId, + const SwView* pView = nullptr) const; + bool GetFirstRedoInfo(OUString *const o_pStr, + const SwView* pView = nullptr) const; SwUndoId GetRepeatInfo(OUString *const o_pStr) const; /// is it forbidden to modify cursors via API calls? diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 340473d..cba7997 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -61,6 +61,7 @@ public: void testViewLock(); void testTextEditViewInvalidations(); void testUndoInvalidations(); + void testUndoLimiting(); void testShapeTextUndoShells(); void testShapeTextUndoGroupShells(); @@ -88,6 +89,7 @@ public: CPPUNIT_TEST(testViewLock); CPPUNIT_TEST(testTextEditViewInvalidations); CPPUNIT_TEST(testUndoInvalidations); + CPPUNIT_TEST(testUndoLimiting); CPPUNIT_TEST(testShapeTextUndoShells); CPPUNIT_TEST(testShapeTextUndoGroupShells); CPPUNIT_TEST_SUITE_END(); @@ -869,10 +871,12 @@ void SwTiledRenderingTest::testUndoInvalidations() SwXTextDocument* pXTextDocument = createDoc("dummy.fodt"); ViewCallback aView1; SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1); + int nView1 = SfxLokHelper::getView(); SfxLokHelper::createView(); pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>()); ViewCallback aView2; SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2); + SfxLokHelper::setView(nView1); // Insert a character the end of the document. SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); @@ -896,6 +900,30 @@ void SwTiledRenderingTest::testUndoInvalidations() comphelper::LibreOfficeKit::setActive(false); } +void SwTiledRenderingTest::testUndoLimiting() +{ + // Load a document and create two views. + comphelper::LibreOfficeKit::setActive(); + SwXTextDocument* pXTextDocument = createDoc("dummy.fodt"); + SwWrtShell* pWrtShell1 = pXTextDocument->GetDocShell()->GetWrtShell(); + SfxLokHelper::createView(); + pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>()); + + // Insert a character the end of the document in the second view. + SwWrtShell* pWrtShell2 = pXTextDocument->GetDocShell()->GetWrtShell(); + pWrtShell2->EndDoc(); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'c', 0); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'c', 0); + SwShellCursor* pShellCursor = pWrtShell2->getShellCursor(false); + CPPUNIT_ASSERT_EQUAL(OUString("Aaa bbb.c"), pShellCursor->GetPoint()->nNode.GetNode().GetTextNode()->GetText()); + + // Assert that the first view can't undo, but the second view can. + CPPUNIT_ASSERT(!pWrtShell1->GetLastUndoInfo(nullptr, nullptr, &pWrtShell1->GetView())); + CPPUNIT_ASSERT(pWrtShell2->GetLastUndoInfo(nullptr, nullptr, &pWrtShell2->GetView())); + + comphelper::LibreOfficeKit::setActive(false); +} + void SwTiledRenderingTest::testShapeTextUndoShells() { // Load a document and create a view. diff --git a/sw/source/core/edit/edws.cxx b/sw/source/core/edit/edws.cxx index e2376ea..6ef43e1 100644 --- a/sw/source/core/edit/edws.cxx +++ b/sw/source/core/edit/edws.cxx @@ -224,11 +224,17 @@ SwUndoId SwEditShell::EndUndo(SwUndoId eUndoId, const SwRewriter *pRewriter) { return GetDoc()->GetIDocumentUndoRedo().EndUndo(eUndoId, pRewriter); } bool SwEditShell::GetLastUndoInfo(OUString *const o_pStr, - SwUndoId *const o_pId) const -{ return GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(o_pStr, o_pId); } + SwUndoId *const o_pId, + const SwView* pView) const +{ + return GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(o_pStr, o_pId, pView); +} -bool SwEditShell::GetFirstRedoInfo(OUString *const o_pStr) const -{ return GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(o_pStr); } +bool SwEditShell::GetFirstRedoInfo(OUString *const o_pStr, + const SwView* pView) const +{ + return GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(o_pStr, nullptr, pView); +} SwUndoId SwEditShell::GetRepeatInfo(OUString *const o_pStr) const { return GetDoc()->GetIDocumentUndoRedo().GetRepeatInfo(o_pStr); } diff --git a/sw/source/core/inc/UndoManager.hxx b/sw/source/core/inc/UndoManager.hxx index 68774c4..5092e95 100644 --- a/sw/source/core/inc/UndoManager.hxx +++ b/sw/source/core/inc/UndoManager.hxx @@ -61,10 +61,12 @@ public: SwRewriter const*const pRewriter) override; virtual void DelAllUndoObj() override; virtual bool GetLastUndoInfo(OUString *const o_pStr, - SwUndoId *const o_pId) const override; + SwUndoId *const o_pId, + const SwView* pView = nullptr) const override; virtual SwUndoComments_t GetUndoComments() const override; virtual bool GetFirstRedoInfo(OUString *const o_pStr, - SwUndoId *const o_pId = nullptr) const override; + SwUndoId *const o_pId = nullptr, + const SwView* pView = nullptr) const override; virtual SwUndoComments_t GetRedoComments() const override; virtual bool Repeat(::sw::RepeatContext & rContext, sal_uInt16 const nRepeatCnt) override; diff --git a/sw/source/core/undo/docundo.cxx b/sw/source/core/undo/docundo.cxx index f59f3dd..46a6693 100644 --- a/sw/source/core/undo/docundo.cxx +++ b/sw/source/core/undo/docundo.cxx @@ -39,6 +39,7 @@ #include <IDocumentDrawModelAccess.hxx> #include <IDocumentRedlineAccess.hxx> #include <IDocumentState.hxx> +#include <comphelper/lok.hxx> using namespace ::com::sun::star; @@ -296,7 +297,7 @@ UndoManager::EndUndo(SwUndoId const i_eUndoId, SwRewriter const*const pRewriter) bool UndoManager::GetLastUndoInfo( - OUString *const o_pStr, SwUndoId *const o_pId) const + OUString *const o_pStr, SwUndoId *const o_pId, const SwView* pView) const { // this is actually expected to work on the current level, // but that was really not obvious from the previous implementation... @@ -307,6 +308,14 @@ UndoManager::GetLastUndoInfo( SfxUndoAction *const pAction( SdrUndoManager::GetUndoAction() ); + if (comphelper::LibreOfficeKit::isActive()) + { + // If an other view created the undo action, prevent undoing it from this view. + sal_Int32 nViewShellId = pView ? pView->GetViewShellId() : m_pDocShell->GetView()->GetViewShellId(); + if (pAction->GetViewShellId() != nViewShellId) + return false; + } + if (o_pStr) { *o_pStr = pAction->GetComment(); @@ -338,7 +347,8 @@ SwUndoComments_t UndoManager::GetUndoComments() const } bool UndoManager::GetFirstRedoInfo(OUString *const o_pStr, - SwUndoId *const o_pId) const + SwUndoId *const o_pId, + const SwView* pView) const { if (!SdrUndoManager::GetRedoActionCount()) { @@ -351,6 +361,14 @@ bool UndoManager::GetFirstRedoInfo(OUString *const o_pStr, return false; } + if (comphelper::LibreOfficeKit::isActive()) + { + // If an other view created the undo action, prevent redoing it from this view. + sal_Int32 nViewShellId = pView ? pView->GetViewShellId() : m_pDocShell->GetView()->GetViewShellId(); + if (pAction->GetViewShellId() != nViewShellId) + return false; + } + if (o_pStr) { *o_pStr = pAction->GetComment(); diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx index 0b8fb13..4d3b743 100644 --- a/sw/source/uibase/shells/basesh.cxx +++ b/sw/source/uibase/shells/basesh.cxx @@ -526,7 +526,7 @@ void SwBaseShell::StateUndo(SfxItemSet &rSet) { case SID_UNDO: { - if (rSh.GetLastUndoInfo(nullptr, nullptr)) + if (rSh.GetLastUndoInfo(nullptr, nullptr, &rSh.GetView())) { rSet.Put( SfxStringItem(nWhich, rSh.GetDoString(SwWrtShell::UNDO))); @@ -537,7 +537,7 @@ void SwBaseShell::StateUndo(SfxItemSet &rSet) } case SID_REDO: { - if (rSh.GetFirstRedoInfo(nullptr)) + if (rSh.GetFirstRedoInfo(nullptr, &rSh.GetView())) { rSet.Put(SfxStringItem(nWhich, rSh.GetDoString(SwWrtShell::REDO))); diff --git a/sw/source/uibase/wrtsh/wrtundo.cxx b/sw/source/uibase/wrtsh/wrtundo.cxx index d8e7ed8..d7da499 100644 --- a/sw/source/uibase/wrtsh/wrtundo.cxx +++ b/sw/source/uibase/wrtsh/wrtundo.cxx @@ -102,11 +102,11 @@ OUString SwWrtShell::GetDoString( DoType eDoType ) const { case UNDO: nResStr = STR_UNDO; - (void)GetLastUndoInfo(&aUndoStr, nullptr); + (void)GetLastUndoInfo(&aUndoStr, nullptr, &m_rView); break; case REDO: nResStr = STR_REDO; - (void)GetFirstRedoInfo(&aUndoStr); + (void)GetFirstRedoInfo(&aUndoStr, &m_rView); break; default:;//prevent warning } commit e980542150085b65567ffe85c6acb72aa5f6e13a Author: Miklos Vajna <[email protected]> Date: Tue Aug 9 12:10:26 2016 +0200 gtktiledviewer: fix incorrect undo/redo state Edit state = false disabled undo, then edit state = true enabled the undo button, even the last LOK callback was '.uno:Undo=disabled'. Fix this by storing the LOK state in a map, and using it when edit is enabled. With this, clicking on the Edit button right after loading a document results disabled undo/redo buttons as expected. Change-Id: Id6023f976f135555a43486f71603c823e59d8d60 Reviewed-on: https://gerrit.libreoffice.org/28003 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins <[email protected]> (cherry picked from commit 5cb52cf97d04859c0c730cf03430254041d6388b) diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx index 71572ab..5b95e35 100644 --- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx @@ -120,6 +120,9 @@ public: GtkWidget* m_pScrolledWindow; std::map<GtkToolItem*, std::string> m_aToolItemCommandNames; std::map<std::string, GtkToolItem*> m_aCommandNameToolItems; + /// Sensitivity (enabled or disabled) or each tool item, ignoring edit + /// state. + std::map<GtkToolItem*, bool> m_aToolItemSensitivities; bool m_bToolItemBroadcast; GtkWidget* m_pVBox; GtkComboBoxText* m_pPartSelector; @@ -386,6 +389,7 @@ static void lcl_registerToolItem(TiledWindow& rWindow, GtkToolItem* pItem, const { rWindow.m_aToolItemCommandNames[pItem] = rName; rWindow.m_aCommandNameToolItems[rName] = pItem; + rWindow.m_aToolItemSensitivities[pItem] = true; } const float fZooms[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 5.0 }; @@ -958,6 +962,13 @@ static gboolean signalFormulabar(GtkWidget* /*pWidget*/, GdkEventKey* /*pEvent*/ return TRUE; } +/// Set sensitivity based on rWindow.m_aToolItemSensitivities, taking edit +/// state into account. +static void setSensitiveIfInEdit(GtkToolItem* pItem, gboolean bEdit, TiledWindow& rWindow) +{ + gtk_widget_set_sensitive(GTK_WIDGET(pItem), bEdit && rWindow.m_aToolItemSensitivities[pItem]); +} + /// LOKDocView changed edit state -> inform the tool button. static void signalEdit(LOKDocView* pLOKDocView, gboolean bWasEdit, gpointer /*pData*/) { @@ -966,22 +977,22 @@ static void signalEdit(LOKDocView* pLOKDocView, gboolean bWasEdit, gpointer /*pD g_info("signalEdit: %d -> %d", bWasEdit, bEdit); // Set toggle button sensitivity - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pBold), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pItalic), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pUnderline), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pStrikethrough), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pSuperscript), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pSubscript), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pLeftpara), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pCenterpara), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pRightpara), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pJustifypara), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pInsertAnnotation), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pDeleteComment), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pUndo), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pRedo), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pPasteButton), bEdit); - gtk_widget_set_sensitive(GTK_WIDGET(rWindow.m_pSaveButton), bEdit); + setSensitiveIfInEdit(rWindow.m_pBold, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pItalic, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pUnderline, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pStrikethrough, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pSuperscript, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pSubscript, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pLeftpara, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pCenterpara, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pRightpara, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pJustifypara, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pInsertAnnotation, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pDeleteComment, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pUndo, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pRedo, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pPasteButton, bEdit, rWindow); + setSensitiveIfInEdit(rWindow.m_pSaveButton, bEdit, rWindow); } /// LOKDocView changed command state -> inform the tool button. @@ -1010,6 +1021,10 @@ static void signalCommand(LOKDocView* pLOKDocView, char* pPayload, gpointer /*pD } else if (aValue == "enabled" || aValue == "disabled") { gboolean bSensitive = aValue == "enabled"; gtk_widget_set_sensitive(GTK_WIDGET(pItem), bSensitive); + + // Remember state, so in case edit is disable and enabled + // later, the correct sensitivity can be restored. + rWindow.m_aToolItemSensitivities[pItem] = bSensitive; } } } commit 0b027e9cd0e456945a2190735dcff1c84b5671a2 Author: Miklos Vajna <[email protected]> Date: Tue Aug 9 09:37:29 2016 +0200 LOK init: strcpy() -> strncpy() 'strcpy' is insecure as it does not provide bounding of the memory buffer in general, so let's avoid it even here. Change-Id: If39319a2df7ddd9297938bc0be67fe5f8a2af962 Reviewed-on: https://gerrit.libreoffice.org/27999 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins <[email protected]> (cherry picked from commit 60cfbcf9e77d4d88aae94226d74300e2490f8549) diff --git a/include/LibreOfficeKit/LibreOfficeKitInit.h b/include/LibreOfficeKit/LibreOfficeKitInit.h index 6190d72..4f745fc 100644 --- a/include/LibreOfficeKit/LibreOfficeKitInit.h +++ b/include/LibreOfficeKit/LibreOfficeKitInit.h @@ -164,19 +164,20 @@ static void *lok_dlopen( const char *install_path, char ** _imp_lib ) // allocate large enough buffer partial_length = strlen(install_path); - imp_lib = (char *) malloc(partial_length + sizeof(TARGET_LIB) + sizeof(TARGET_MERGED_LIB) + 2); + size_t imp_lib_size = partial_length + sizeof(TARGET_LIB) + sizeof(TARGET_MERGED_LIB) + 2; + imp_lib = (char *) malloc(imp_lib_size); if (!imp_lib) { fprintf( stderr, "failed to open library : not enough memory\n"); return NULL; } - strcpy(imp_lib, install_path); + strncpy(imp_lib, install_path, imp_lib_size); extendUnoPath(install_path); imp_lib[partial_length++] = SEPARATOR; - strcpy(imp_lib + partial_length, TARGET_LIB); + strncpy(imp_lib + partial_length, TARGET_LIB, imp_lib_size - partial_length); dlhandle = lok_loadlib(imp_lib); if (!dlhandle) @@ -194,7 +195,7 @@ static void *lok_dlopen( const char *install_path, char ** _imp_lib ) return NULL; } - strcpy(imp_lib + partial_length, TARGET_MERGED_LIB); + strncpy(imp_lib + partial_length, TARGET_MERGED_LIB, imp_lib_size - partial_length); dlhandle = lok_loadlib(imp_lib); if (!dlhandle) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
