Kaydet (Commit) 0632f77e authored tarafından Siqi Liu's avatar Siqi Liu

LOK_STATE_CHANGED callback implemented with sfx events interception.

üst cc54da22
...@@ -4,6 +4,7 @@ import android.content.Intent; ...@@ -4,6 +4,7 @@ import android.content.Intent;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.RectF; import android.graphics.RectF;
import android.net.Uri; import android.net.Uri;
import android.util.Log;
import org.libreoffice.canvas.SelectionHandle; import org.libreoffice.canvas.SelectionHandle;
import org.libreoffice.kit.Document; import org.libreoffice.kit.Document;
...@@ -73,19 +74,26 @@ public class InvalidationHandler implements Document.MessageCallback { ...@@ -73,19 +74,26 @@ public class InvalidationHandler implements Document.MessageCallback {
LibreOfficeMainActivity.mAppContext.startActivity(urlIntent); LibreOfficeMainActivity.mAppContext.startActivity(urlIntent);
break; break;
case Document.CALLBACK_STATE_CHANGED: case Document.CALLBACK_STATE_CHANGED:
Log.d("Document.CALLBACK_STATE_CHANGED: " + payload); stateChanged(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);
}
break; 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);
} }
} }
......
...@@ -72,7 +72,13 @@ public class ToolbarController { ...@@ -72,7 +72,13 @@ public class ToolbarController {
icon = ImageUtils.bitmapToPressed(icon); 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) { public void setOptionMenu(Menu menu) {
......
...@@ -102,7 +102,14 @@ typedef enum ...@@ -102,7 +102,14 @@ typedef enum
* User clicked on an hyperlink that should be handled by other * User clicked on an hyperlink that should be handled by other
* applications accordingly. * 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; LibreOfficeKitCallbackType;
......
...@@ -49,6 +49,9 @@ ...@@ -49,6 +49,9 @@
#include <set> #include <set>
#include <o3tl/typed_flags_set.hxx> #include <o3tl/typed_flags_set.hxx>
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKitTypes.h>
class SbxValue; class SbxValue;
class SvxMacro; class SvxMacro;
class SbxArray; class SbxArray;
...@@ -708,6 +711,14 @@ public: ...@@ -708,6 +711,14 @@ public:
SAL_DLLPRIVATE void CancelCheckOut( ); SAL_DLLPRIVATE void CancelCheckOut( );
SAL_DLLPRIVATE void CheckIn( ); SAL_DLLPRIVATE void CheckIn( );
SAL_DLLPRIVATE ::com::sun::star::uno::Sequence< ::com::sun::star::document::CmisVersion > GetCmisVersions(); 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 \ #define SFX_GLOBAL_CLASSID \
......
...@@ -175,6 +175,8 @@ public: ...@@ -175,6 +175,8 @@ public:
void UnBindController(); void UnBindController();
SfxDispatcher* GetDispatcher(); SfxDispatcher* GetDispatcher();
void SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame); 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 #endif
......
...@@ -857,6 +857,8 @@ const char* LOKDocView_Impl::callbackTypeToString(int nType) ...@@ -857,6 +857,8 @@ const char* LOKDocView_Impl::callbackTypeToString(int nType)
return "LOK_CALLBACK_GRAPHIC_SELECTION"; return "LOK_CALLBACK_GRAPHIC_SELECTION";
case LOK_CALLBACK_HYPERLINK_CLICKED: case LOK_CALLBACK_HYPERLINK_CLICKED:
return "LOK_CALLBACK_HYPERLINK_CLICKED"; return "LOK_CALLBACK_HYPERLINK_CLICKED";
case LOK_CALLBACK_STATE_CHANGED:
return "LOK_CALLBACK_STATE_CHANGED";
} }
return 0; return 0;
} }
...@@ -937,6 +939,10 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback) ...@@ -937,6 +939,10 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
gtk_show_uri(NULL, pCallback->m_aPayload.c_str(), GDK_CURRENT_TIME, &pError); gtk_show_uri(NULL, pCallback->m_aPayload.c_str(), GDK_CURRENT_TIME, &pError);
#endif #endif
} }
case LOK_CALLBACK_STATE_CHANGED:
{
g_info(pCallback->m_aPayload.c_str());
}
break; break;
default: default:
g_assert(false); g_assert(false);
......
...@@ -68,6 +68,9 @@ ...@@ -68,6 +68,9 @@
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <sal/log.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util; using namespace ::com::sun::star::util;
...@@ -973,8 +976,7 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt ...@@ -973,8 +976,7 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt
pLastState = pState; pLastState = pState;
} }
::cppu::OInterfaceContainerHelper* pContnr = pDispatch->GetListeners().getContainer ( aDispatchURL.Complete ); if (bNotify)
if ( bNotify && pContnr )
{ {
::com::sun::star::uno::Any aState; ::com::sun::star::uno::Any aState;
if ( ( eState >= SfxItemState::DEFAULT ) && pState && !IsInvalidItem( pState ) && !pState->ISA(SfxVoidItem) ) if ( ( eState >= SfxItemState::DEFAULT ) && pState && !IsInvalidItem( pState ) && !pState->ISA(SfxVoidItem) )
...@@ -1015,16 +1017,24 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt ...@@ -1015,16 +1017,24 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt
aEvent.Requery = sal_False; aEvent.Requery = sal_False;
aEvent.State = aState; aEvent.State = aState;
::cppu::OInterfaceIteratorHelper aIt( *pContnr ); if (pDispatcher && pDispatcher->GetFrame()) {
while( aIt.hasMoreElements() ) InterceptLOKStateChangeEvent(
{ pDispatcher->GetFrame()->GetObjectShell(), aEvent);
try }
{
static_cast< ::com::sun::star::frame::XStatusListener *>(aIt.next())->statusChanged( aEvent ); ::cppu::OInterfaceContainerHelper* pContnr = pDispatch->GetListeners().getContainer ( aDispatchURL.Complete );
} if (pContnr) {
catch (const ::com::sun::star::uno::RuntimeException&) ::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 ...@@ -1035,4 +1045,27 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt
StateChanged( nSID, eState, pState, 0 ); 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -76,6 +76,10 @@ ...@@ -76,6 +76,10 @@
#include "querytemplate.hxx" #include "querytemplate.hxx"
#include <boost/scoped_array.hpp> #include <boost/scoped_array.hpp>
#include <LibreOfficeKit/LibreOfficeKitTypes.h>
#include <typeinfo>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
...@@ -639,4 +643,12 @@ bool SfxObjectShell::IsModifyPasswordEntered() ...@@ -639,4 +643,12 @@ bool SfxObjectShell::IsModifyPasswordEntered()
return pImp->m_bModifyPasswordEntered; 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include <svl/lstner.hxx> #include <svl/lstner.hxx>
#include <svtools/embedhlp.hxx> #include <svtools/embedhlp.hxx>
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKitTypes.h>
class SwDoc; class SwDoc;
class SfxDocumentInfoDialog; class SfxDocumentInfoDialog;
...@@ -311,6 +313,9 @@ public: ...@@ -311,6 +313,9 @@ public:
virtual void SetChangeRecording( bool bActivate ) SAL_OVERRIDE; virtual void SetChangeRecording( bool bActivate ) SAL_OVERRIDE;
virtual bool SetProtectionPassword( const OUString &rPassword ) 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 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: /** Find the right DocShell and create a new one:
......
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
#include <docstyle.hxx> #include <docstyle.hxx>
#include <doc.hxx> #include <doc.hxx>
#include <docfunc.hxx> #include <docfunc.hxx>
#include <drawdoc.hxx>
#include <IDocumentUndoRedo.hxx> #include <IDocumentUndoRedo.hxx>
#include <IDocumentSettingAccess.hxx> #include <IDocumentSettingAccess.hxx>
#include <IDocumentLinksAdministration.hxx> #include <IDocumentLinksAdministration.hxx>
...@@ -121,6 +122,9 @@ ...@@ -121,6 +122,9 @@
#include <sfx2/Metadatable.hxx> #include <sfx2/Metadatable.hxx>
#include <calbck.hxx> #include <calbck.hxx>
#include <sal/log.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::script; using namespace ::com::sun::star::script;
...@@ -1296,4 +1300,19 @@ bool SwDocShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal ...@@ -1296,4 +1300,19 @@ bool SwDocShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal
return bRes; 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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