diff options
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java | 32 | ||||
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java | 8 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKitEnums.h | 9 | ||||
-rw-r--r-- | include/sfx2/objsh.hxx | 11 | ||||
-rw-r--r-- | include/sfx2/unoctitm.hxx | 2 | ||||
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 6 | ||||
-rw-r--r-- | sfx2/source/control/unoctitm.cxx | 55 | ||||
-rw-r--r-- | sfx2/source/doc/objcont.cxx | 12 | ||||
-rw-r--r-- | sw/inc/docsh.hxx | 5 | ||||
-rw-r--r-- | sw/source/uibase/app/docsh.cxx | 19 |
10 files changed, 134 insertions, 25 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java index 385fab5123ba..26ab856be1fd 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.graphics.PointF; import android.graphics.RectF; import android.net.Uri; +import android.util.Log; import org.libreoffice.canvas.SelectionHandle; import org.libreoffice.kit.Document; @@ -73,19 +74,26 @@ public class InvalidationHandler implements Document.MessageCallback { LibreOfficeMainActivity.mAppContext.startActivity(urlIntent); break; case Document.CALLBACK_STATE_CHANGED: - Log.d("Document.CALLBACK_STATE_CHANGED: " + payload); - String[] parts = payload.split(":"); - boolean pressed = Boolean.parseBoolean(parts[1]); - if (parts[0].equals("Bold")) { - LOKitShell.getToolbarController().onToggleStateChanged(Document.BOLD, pressed); - } else if (parts[0].equals("Italic")) { - LOKitShell.getToolbarController().onToggleStateChanged(Document.ITALIC, pressed); - } else if (parts[0].equals("Underline")) { - LOKitShell.getToolbarController().onToggleStateChanged(Document.UNDERLINE, pressed); - } else if (parts[0].equals("Strikeout")) { - LOKitShell.getToolbarController().onToggleStateChanged(Document.STRIKEOUT, pressed); - } + stateChanged(payload); break; + default: + Log.d(LOGTAG, "LOK_CALLBACK uncatched: " + messageID + " : " + payload); + } + } + + private void stateChanged(String payload) { + String[] parts = payload.split("="); + boolean pressed = Boolean.parseBoolean(parts[1]); + if (parts[0].equals(".uno:Bold")) { + LOKitShell.getToolbarController().onToggleStateChanged(Document.BOLD, pressed); + } else if (parts[0].equals(".uno:Italic")) { + LOKitShell.getToolbarController().onToggleStateChanged(Document.ITALIC, pressed); + } else if (parts[0].equals(".uno:Underline")) { + LOKitShell.getToolbarController().onToggleStateChanged(Document.UNDERLINE, pressed); + } else if (parts[0].equals(".uno:StrikeOut")) { + LOKitShell.getToolbarController().onToggleStateChanged(Document.STRIKEOUT, pressed); + } else { + Log.d(LOGTAG, "LOK_CALLBACK_STATE_CHANGED type uncatched: " + payload); } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java index 34eff3fc3d9c..1201b40bafa4 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java @@ -72,7 +72,13 @@ public class ToolbarController { icon = ImageUtils.bitmapToPressed(icon); } - menuItem.setIcon(new BitmapDrawable(mContext.getResources(), icon)); + final MenuItem fMenuItem = menuItem; + final Bitmap fIcon = icon; + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + fMenuItem.setIcon(new BitmapDrawable(mContext.getResources(), fIcon)); + } + }); } public void setOptionMenu(Menu menu) { diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index e8d2b59dec45..d4d1b4c4fc3b 100644 --- a/include/LibreOfficeKit/LibreOfficeKitEnums.h +++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h @@ -102,7 +102,14 @@ typedef enum * User clicked on an hyperlink that should be handled by other * applications accordingly. */ - LOK_CALLBACK_HYPERLINK_CLICKED + LOK_CALLBACK_HYPERLINK_CLICKED, + + /** + * Emit state update to the client. + * For example, when cursor is on bold text, this callback is triggered + * with payload: ".uno:Bold=true" + */ + LOK_CALLBACK_STATE_CHANGED } LibreOfficeKitCallbackType; diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index 8b82d767e45a..7e235d99ef82 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -49,6 +49,9 @@ #include <set> #include <o3tl/typed_flags_set.hxx> +#define LOK_USE_UNSTABLE_API +#include <LibreOfficeKit/LibreOfficeKitTypes.h> + class SbxValue; class SvxMacro; class SbxArray; @@ -708,6 +711,14 @@ public: SAL_DLLPRIVATE void CancelCheckOut( ); SAL_DLLPRIVATE void CheckIn( ); SAL_DLLPRIVATE ::com::sun::star::uno::Sequence< ::com::sun::star::document::CmisVersion > GetCmisVersions(); + + /** + * Interface shared by document shell. Allow LOK calls from sfx. + * Default behavior doesn't do anything. relevant SfxObjectShells should override + * the default behavior and implements LOK calls. + */ + virtual void libreOfficeKitCallback(int nType, const char* pPayload) const; + virtual bool isTiledRendering() const; }; #define SFX_GLOBAL_CLASSID \ diff --git a/include/sfx2/unoctitm.hxx b/include/sfx2/unoctitm.hxx index 97d12dacf9fe..70122ee2d3d4 100644 --- a/include/sfx2/unoctitm.hxx +++ b/include/sfx2/unoctitm.hxx @@ -175,6 +175,8 @@ public: void UnBindController(); SfxDispatcher* GetDispatcher(); void SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame); + + void InterceptLOKStateChangeEvent(const SfxObjectShell* objSh, const ::com::sun::star::frame::FeatureStateEvent& aEvent) const; }; #endif diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 7430511bac5d..ac94f15ae663 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -857,6 +857,8 @@ const char* LOKDocView_Impl::callbackTypeToString(int nType) return "LOK_CALLBACK_GRAPHIC_SELECTION"; case LOK_CALLBACK_HYPERLINK_CLICKED: return "LOK_CALLBACK_HYPERLINK_CLICKED"; + case LOK_CALLBACK_STATE_CHANGED: + return "LOK_CALLBACK_STATE_CHANGED"; } return 0; } @@ -937,6 +939,10 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback) gtk_show_uri(NULL, pCallback->m_aPayload.c_str(), GDK_CURRENT_TIME, &pError); #endif } + case LOK_CALLBACK_STATE_CHANGED: + { + g_info(pCallback->m_aPayload.c_str()); + } break; default: g_assert(false); diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index 0d98a2584b15..41a20fe38a8e 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -68,6 +68,9 @@ #include <iostream> #include <map> +#include <sal/log.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> + using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::util; @@ -973,8 +976,7 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt pLastState = pState; } - ::cppu::OInterfaceContainerHelper* pContnr = pDispatch->GetListeners().getContainer ( aDispatchURL.Complete ); - if ( bNotify && pContnr ) + if (bNotify) { ::com::sun::star::uno::Any aState; if ( ( eState >= SfxItemState::DEFAULT ) && pState && !IsInvalidItem( pState ) && !pState->ISA(SfxVoidItem) ) @@ -1015,16 +1017,24 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt aEvent.Requery = sal_False; aEvent.State = aState; - ::cppu::OInterfaceIteratorHelper aIt( *pContnr ); - while( aIt.hasMoreElements() ) - { - try - { - static_cast< ::com::sun::star::frame::XStatusListener *>(aIt.next())->statusChanged( aEvent ); - } - catch (const ::com::sun::star::uno::RuntimeException&) + if (pDispatcher && pDispatcher->GetFrame()) { + InterceptLOKStateChangeEvent( + pDispatcher->GetFrame()->GetObjectShell(), aEvent); + } + + ::cppu::OInterfaceContainerHelper* pContnr = pDispatch->GetListeners().getContainer ( aDispatchURL.Complete ); + if (pContnr) { + ::cppu::OInterfaceIteratorHelper aIt( *pContnr ); + while( aIt.hasMoreElements() ) { - aIt.remove(); + try + { + static_cast< ::com::sun::star::frame::XStatusListener *>(aIt.next())->statusChanged( aEvent ); + } + catch (const ::com::sun::star::uno::RuntimeException&) + { + aIt.remove(); + } } } } @@ -1035,4 +1045,27 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt StateChanged( nSID, eState, pState, 0 ); } +void SfxDispatchController_Impl::InterceptLOKStateChangeEvent(const SfxObjectShell* objSh, const ::com::sun::star::frame::FeatureStateEvent& aEvent) const +{ + if (!objSh || !objSh->isTiledRendering()) { + return; + } + + if (aEvent.FeatureURL.Path == "Bold" || + aEvent.FeatureURL.Path == "Italic" || + aEvent.FeatureURL.Path == "Underline" || + aEvent.FeatureURL.Path == "StrikeOut") { + + OUStringBuffer aBuffer; + aBuffer.append(aEvent.FeatureURL.Complete); + aBuffer.append("="); + bool bTemp = false; + aEvent.State >>= bTemp; + aBuffer.append(bTemp); + + OUString payload = aBuffer.makeStringAndClear(); + objSh->libreOfficeKitCallback(LOK_CALLBACK_STATE_CHANGED, payload.toUtf8().getStr()); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx index 95fd6b83e1dc..40d1e195e0a5 100644 --- a/sfx2/source/doc/objcont.cxx +++ b/sfx2/source/doc/objcont.cxx @@ -76,6 +76,10 @@ #include "querytemplate.hxx" #include <boost/scoped_array.hpp> +#include <LibreOfficeKit/LibreOfficeKitTypes.h> + +#include <typeinfo> + using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -639,4 +643,12 @@ bool SfxObjectShell::IsModifyPasswordEntered() return pImp->m_bModifyPasswordEntered; } +void SfxObjectShell::libreOfficeKitCallback(SAL_UNUSED_PARAMETER int nType, SAL_UNUSED_PARAMETER const char* pPayload) const { + SAL_WARN("tiled-rendering", "LOK callback interface not overridden for SfxObjectShell subclass typeId: " << typeid(*this).name()); +} +bool SfxObjectShell::isTiledRendering() const { + SAL_WARN("tiled-rendering", "LOK callback interface not overridden for SfxObjectShell subclass typeId: " << typeid(*this).name()); + return false; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx index fa2f5478e7b5..704d0667f681 100644 --- a/sw/inc/docsh.hxx +++ b/sw/inc/docsh.hxx @@ -29,6 +29,8 @@ #include <svl/lstner.hxx> #include <svtools/embedhlp.hxx> +#define LOK_USE_UNSTABLE_API +#include <LibreOfficeKit/LibreOfficeKitTypes.h> class SwDoc; class SfxDocumentInfoDialog; @@ -311,6 +313,9 @@ public: virtual void SetChangeRecording( bool bActivate ) SAL_OVERRIDE; virtual bool SetProtectionPassword( const OUString &rPassword ) SAL_OVERRIDE; virtual bool GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash ) SAL_OVERRIDE; + + virtual void libreOfficeKitCallback(int nType, const char* pPayload) const SAL_OVERRIDE; + virtual bool isTiledRendering() const SAL_OVERRIDE; }; /** Find the right DocShell and create a new one: diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx index 71e825104479..9df4e546bdaa 100644 --- a/sw/source/uibase/app/docsh.cxx +++ b/sw/source/uibase/app/docsh.cxx @@ -72,6 +72,7 @@ #include <docstyle.hxx> #include <doc.hxx> #include <docfunc.hxx> +#include <drawdoc.hxx> #include <IDocumentUndoRedo.hxx> #include <IDocumentSettingAccess.hxx> #include <IDocumentLinksAdministration.hxx> @@ -121,6 +122,9 @@ #include <sfx2/Metadatable.hxx> #include <calbck.hxx> +#include <sal/log.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> + using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::script; @@ -1296,4 +1300,19 @@ bool SwDocShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal return bRes; } +void SwDocShell::libreOfficeKitCallback(int nType, const char* pPayload) const +{ + if (!m_pDoc) { + return; + } + + SwDrawModel* pDrawModel = m_pDoc->getIDocumentDrawModelAccess().GetDrawModel(); + pDrawModel->libreOfficeKitCallback(nType, pPayload); +} + +bool SwDocShell::isTiledRendering() const { + SwDrawModel* pDrawModel = m_pDoc->getIDocumentDrawModelAccess().GetDrawModel(); + return pDrawModel->isTiledRendering(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |