Kaydet (Commit) d64a7f4b authored tarafından Aditya Dewan's avatar Aditya Dewan Kaydeden (comit) pranavk

implementing callback for ruler invalidation

adding commands to fetch and changee ruler state
'.uno:RulerState' and '.uno:RulerStateChange'

Change-Id: I66107039a7ae5893691feb45c8ab2e4aa476ea76
Reviewed-on: https://gerrit.libreoffice.org/40727Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarpranavk <pranavk@collabora.co.uk>
üst ea43e0e3
......@@ -65,6 +65,7 @@
#include <svx/dialmgr.hxx>
#include <svx/dialogs.hrc>
#include <svx/strings.hrc>
#include <svx/ruler.hxx>
#include <svx/svxids.hrc>
#include <svx/ucsubset.hxx>
#include <vcl/svapp.hxx>
......@@ -805,6 +806,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
case LOK_CALLBACK_CURSOR_VISIBLE:
case LOK_CALLBACK_SET_PART:
case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE:
case LOK_CALLBACK_RULER_UPDATE:
{
removeAll([type] (const queue_type::value_type& elem) { return (elem.first == type); });
}
......@@ -2044,6 +2046,18 @@ static char* getPostItsPos(LibreOfficeKitDocument* pThis)
return strdup(aComments.toUtf8().getStr());
}
static char* getRulerState(LibreOfficeKitDocument* pThis)
{
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
return nullptr;
}
OUString state = pDoc->getRulerState();
return strdup(state.toUtf8().getStr());
}
static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nCharCode, int nKeyCode)
{
SolarMutexGuard aGuard;
......@@ -2651,6 +2665,10 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
{
return getPostItsPos(pThis);
}
else if (aCommand == ".uno:RulerState")
{
return getRulerState(pThis);
}
else if (aCommand.startsWith(aViewRowColumnHeaders))
{
ITiledRenderable* pDoc = getTiledRenderable(pThis);
......
......@@ -504,7 +504,24 @@ typedef enum
/**
* The text content of the address field in Calc.
*/
LOK_CALLBACK_CELL_ADDRESS = 34
LOK_CALLBACK_CELL_ADDRESS = 34,
/**
* The key ruler related properties on change are reported by this.
*
* The payload format is:
*
* {
* "margin1": "...",
* "margin2": "...",
* "leftOffset": "...",
* "pageOffset": "...",
* "pageWidth": "...",
* "unit": "..."
* }
*
* Here all aproperties are same as described in svxruler.
*/
LOK_CALLBACK_RULER_UPDATE = 35
}
LibreOfficeKitCallbackType;
......
......@@ -541,6 +541,8 @@
#define SID_COMP_BIBLIOGRAPHY (SID_SVX_START + 880)
#define SID_ADDRESS_DATA_SOURCE (SID_SVX_START + 934)
#define SID_OPEN_SMARTTAGOPTIONS (SID_SVX_START + 1062)
#define SID_RULER_MARGIN1 (SID_SVX_START + 1063)
#define SID_RULER_MARGIN2 (SID_SVX_START + 1064)
#define FID_SVX_START (SID_LIB_START + 500)
#define FID_SEARCH_NOW (FID_SVX_START + 2)
......
......@@ -773,6 +773,7 @@ public:
void SetMargin2() { SetMargin2( 0, RulerMarginStyle::Invisible ); }
void SetMargin2( long nPos, RulerMarginStyle nMarginStyle = RulerMarginStyle::Sizeable );
long GetMargin2() const;
long GetPageWidth() const;
void SetLeftFrameMargin( long nPos );
void SetRightFrameMargin( long nPos );
......
......@@ -41,6 +41,12 @@ class SvxObjectItem;
class SfxBoolItem;
struct SvxRuler_Impl;
enum class RulerChangeType
{
MARGIN1,
MARGIN2
};
enum class SvxRulerDragFlags
{
NONE = 0x00,
......@@ -250,7 +256,6 @@ protected:
bool bForceDontConsiderHidden = false,
sal_uInt16 nAct=USHRT_MAX ) const;
long CalcPropMaxRight(sal_uInt16 nCol = USHRT_MAX) const;
long GetPageWidth() const;
public:
......@@ -273,6 +278,8 @@ public:
//#i24363# tab stops relative to indent
void SetTabsRelativeToIndent( bool bRel );
void SetValues(RulerChangeType type, long value);
long GetPageWidth() const;
};
#endif
......
......@@ -234,6 +234,7 @@
// CAUTION! Range <64 .. 67> used by EditEngine (!)
#define SID_RULER_CHANGE_STATE ( SID_SVX_START + 78 )
#define SID_RULER_NULL_OFFSET ( SID_SVX_START + 79 )
#define SID_RULER_BORDERS ( SID_SVX_START + 80 )
#define SID_RULER_OBJECT ( SID_SVX_START + 81 )
......
......@@ -13,6 +13,7 @@
#include <LibreOfficeKit/LibreOfficeKitTypes.h>
#include <tools/gen.hxx>
#include <svx/ruler.hxx>
#include <vcl/pointr.hxx>
#include <vcl/virdev.hxx>
#include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp>
......@@ -220,8 +221,14 @@ public:
{
return OUString();
}
};
/// Implementation for
/// lok::Document::getCommandValues(".uno:RulerState");
virtual OUString getRulerState()
{
return OUString();
}
};
} // namespace vcl
#endif // INCLUDED_VCL_ITILEDRENDERABLE_HXX
......
......@@ -103,6 +103,7 @@ gtv_main_toolbar_init(GtvMainToolbar* toolbar)
gtk_builder_add_callback_symbol(builder.get(), "doCopy", G_CALLBACK(doCopy));
gtk_builder_add_callback_symbol(builder.get(), "doPaste", G_CALLBACK(doPaste));
gtk_builder_add_callback_symbol(builder.get(), "createView", G_CALLBACK(createView));
gtk_builder_add_callback_symbol(builder.get(), "getRulerState", G_CALLBACK(getRulerState));
gtk_builder_add_callback_symbol(builder.get(), "unoCommandDebugger", G_CALLBACK(unoCommandDebugger));
gtk_builder_add_callback_symbol(builder.get(), "toggleEditing", G_CALLBACK(toggleEditing));
gtk_builder_add_callback_symbol(builder.get(), "changePartMode", G_CALLBACK(changePartMode));
......
......@@ -133,6 +133,14 @@ void createView(GtkWidget* pButton, gpointer /*pItem*/)
gtv_application_window_create_view_from_window(GTV_APPLICATION_WINDOW(window));
}
void getRulerState(GtkWidget* pButton, gpointer /*pItem*/)
{
const std::string type = ".uno:RulerState";
GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_widget_get_toplevel(pButton));
LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview));
pDocument->pClass->getCommandValues(pDocument, type.c_str());
}
static void removeUnoParam(GtkWidget* pWidget, gpointer userdata)
{
GtkWidget* pParamAreaBox = GTK_WIDGET(userdata);
......
......@@ -20,6 +20,8 @@ void doPaste(GtkWidget* pButton, gpointer /*pItem*/);
void createView(GtkWidget* pButton, gpointer /*pItem*/);
void getRulerState(GtkWidget* pButton, gpointer /*pItem*/);
void unoCommandDebugger(GtkWidget* pButton, gpointer /* pItem */);
void toggleEditing(GtkWidget* pButton, gpointer /*pItem*/);
......
......@@ -486,6 +486,20 @@
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="btn_rulerstate">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">.uno:UpdateRuler</property>
<property name="use_underline">True</property>
<property name="icon_name">text-x-generic</property>
<signal name="clicked" handler="getRulerState" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
<object class="GtkToolbar" id="toolbar2">
<property name="visible">True</property>
......
......@@ -278,6 +278,7 @@ enum
TEXT_SELECTION,
PASSWORD_REQUIRED,
COMMENT,
RULER,
LAST_SIGNAL
};
......@@ -433,6 +434,8 @@ callbackTypeToString (int nType)
return "LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED";
case LOK_CALLBACK_COMMENT:
return "LOK_CALLBACK_COMMENT";
case LOK_CALLBACK_RULER_UPDATE:
return "LOK_CALLBACK_RULER_UPDATE";
}
g_assert(false);
return nullptr;
......@@ -1422,6 +1425,9 @@ callback (gpointer pData)
case LOK_CALLBACK_COMMENT:
g_signal_emit(pCallback->m_pDocView, doc_view_signals[COMMENT], 0, pCallback->m_aPayload.c_str());
break;
case LOK_CALLBACK_RULER_UPDATE:
g_signal_emit(pCallback->m_pDocView, doc_view_signals[RULER], 0, pCallback->m_aPayload.c_str());
break;
default:
g_assert(false);
break;
......@@ -3208,6 +3214,16 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
g_cclosure_marshal_generic,
G_TYPE_NONE, 1,
G_TYPE_STRING);
doc_view_signals[RULER] =
g_signal_new("ruler",
G_TYPE_FROM_CLASS(pGObjectClass),
G_SIGNAL_RUN_FIRST,
0,
nullptr, nullptr,
g_cclosure_marshal_generic,
G_TYPE_NONE, 1,
G_TYPE_STRING);
}
SAL_DLLPUBLIC_EXPORT GtkWidget*
......
......@@ -88,6 +88,8 @@ SfxFormalArgument const aFormalArgs[] = {
{ reinterpret_cast<SfxType*>(&aSfxBoolItem_Impl), "VersionMajor", SID_DOCINFO_MAJOR },
{ reinterpret_cast<SfxType*>(&aSfxStringItem_Impl), "FilterOptions", SID_FILE_FILTEROPTIONS },
{ reinterpret_cast<SfxType*>(&aSfxStringItem_Impl), "FilterName", SID_FILTER_NAME },
{ reinterpret_cast<SfxType*>(&aSfxStringItem_Impl), "Margin1", SID_RULER_MARGIN1 },
{ reinterpret_cast<SfxType*>(&aSfxStringItem_Impl), "Margin2", SID_RULER_MARGIN2 },
// { reinterpret_cast<SfxType*>(&aSfxStringItem_Impl), "FileName", SID_FILE_NAME },
{ reinterpret_cast<SfxType*>(&aSfxStringItem_Impl), "URL", SID_FILE_NAME },
{ reinterpret_cast<SfxType*>(&aSfxStringItem_Impl), "OpenFlags", SID_OPTIONS },
......
......@@ -2678,6 +2678,11 @@ void Ruler::SetTextRTL(bool bRTL)
}
long Ruler::GetPageWidth() const
{
return mpData->nPageWidth;
}
long Ruler::GetPageOffset() const
{
return mpData->nPageOff;
......
......@@ -7101,6 +7101,24 @@ SvxProtectItem RulerProtect SID_RULER_PROTECT
GroupId = SfxGroupId::View;
]
SfxVoidItem RulerChangeState SID_RULER_CHANGE_STATE
(SfxStringItem Margin1 SID_RULER_MARGIN1, SfxStringItem Margin2 SID_RULER_MARGIN2)
[
AutoUpdate = FALSE,
FastCall = TRUE,
ReadOnlyDoc = TRUE,
Toggle = FALSE,
Container = FALSE,
RecordAbsolute = FALSE,
RecordPerSet;
AccelConfig = FALSE,
MenuConfig = FALSE,
ToolBoxConfig = FALSE,
GroupId = ;
]
SfxVoidItem SbaExecuteSql SID_FM_EXECUTE
()
......
......@@ -37,6 +37,7 @@
#include <editeng/tstpitem.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/protitem.hxx>
#include <comphelper/lok.hxx>
#include <svx/svdtrans.hxx>
......@@ -3613,4 +3614,14 @@ void SvxRuler::SetTabsRelativeToIndent( bool bRel )
mxRulerImpl->bIsTabsRelativeToIndent = bRel;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SvxRuler::SetValues(RulerChangeType type, long diffValue)
{
if (diffValue == 0)
return;
if (type == RulerChangeType::MARGIN1)
AdjustMargin1(diffValue);
else if (type == RulerChangeType::MARGIN2)
SetMargin2( GetMargin2() - diffValue);
ApplyMargins();
}
\ No newline at end of file
......@@ -64,6 +64,7 @@
#include <rtl/ref.hxx>
#include <svl/itemprop.hxx>
#include <svx/fmdmod.hxx>
#include <svx/ruler.hxx>
#include <editeng/UnoForbiddenCharsTable.hxx>
#include <cppuhelper/weak.hxx>
#include <cppuhelper/implbase.hxx>
......@@ -423,6 +424,8 @@ public:
OUString getTrackedChanges() override;
/// @see vcl::ITiledRenderable::getTrackedChangeAuthors().
OUString getTrackedChangeAuthors() override;
OUString getRulerState() override;
/// @see vcl::ITiledRenderable::getPostIts().
OUString getPostIts() override;
// css::tiledrendering::XTiledRenderable
......
......@@ -235,6 +235,10 @@ interface BaseTextEditView
StateMethod = StateTabWin ;
DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
]
SID_RULER_CHANGE_STATE
[
ExecMethod = ExecTabWin ;
]
SID_RULER_BORDERS // status()
[
ExecMethod = ExecTabWin ;
......
......@@ -41,6 +41,7 @@ public:
* \param rRect ignored
*/
virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
const std::string CreateJsonNotification();
protected:
SwViewShell * mpViewShell; //< Shell to check if there is any comments on doc and their visibility
......@@ -50,6 +51,7 @@ protected:
int mnFadeRate; //< From 0 to 100. 0 means not highlighted.
ScopedVclPtr<VirtualDevice> maVirDev; //< VirtualDevice of this window. Just for convenience.
void NotifyKit();
/**
* Callback function to handle a mouse button down event.
*
......
......@@ -24,9 +24,11 @@
#include <vcl/window.hxx>
#include <vcl/settings.hxx>
#include "strings.hrc"
#include <comphelper/lok.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <boost/property_tree/json_parser.hpp>
#define CONTROL_BORDER_WIDTH 1
#define CONTROL_LEFT_OFFSET 6
#define CONTROL_RIGHT_OFFSET 3
#define CONTROL_TOP_OFFSET 4
......@@ -246,12 +248,41 @@ void SwCommentRuler::MouseButtonDown( const MouseEvent& rMEvt )
Invalidate();
}
const std::string SwCommentRuler::CreateJsonNotification()
{
boost::property_tree::ptree jsonNotif;
jsonNotif.put("margin1", convertTwipToMm100(GetMargin1()));
jsonNotif.put("margin2", convertTwipToMm100(GetMargin2()));
jsonNotif.put("leftOffset", convertTwipToMm100(GetNullOffset()));
jsonNotif.put("pageOffset", convertTwipToMm100(GetPageOffset()));
jsonNotif.put("pageWidth", convertTwipToMm100(GetPageWidth()));
RulerUnitData aUnitData = GetCurrentRulerUnit();
jsonNotif.put("unit", aUnitData.aUnitStr);
std::stringstream aStream;
boost::property_tree::write_json(aStream, jsonNotif);
std::string aPayload = aStream.str();
return aPayload;
}
void SwCommentRuler::NotifyKit()
{
if (!comphelper::LibreOfficeKit::isActive())
return;
const std::string test = CreateJsonNotification();
mpViewShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_RULER_UPDATE, test.c_str());
}
void SwCommentRuler::Update()
{
tools::Rectangle aPreviousControlRect = GetCommentControlRegion();
SvxRuler::Update();
if (aPreviousControlRect != GetCommentControlRegion())
Invalidate();
NotifyKit();
}
void SwCommentRuler::UpdateCommentHelpText()
......
......@@ -52,6 +52,7 @@
#include "wview.hxx"
#include "fmtcol.hxx"
#include "section.hxx"
#include "swruler.hxx"
#include "ndtxt.hxx"
#include "pam.hxx"
......@@ -801,6 +802,24 @@ void SwView::ExecTabWin( SfxRequest const & rReq )
rSh.SetAttrItem( aULSpace );
}
break;
case SID_RULER_CHANGE_STATE:
{
const SfxPoolItem *pMargin1, *pMargin2;
if ( pReqArgs &&
pReqArgs->GetItemState(SID_RULER_MARGIN1,true,&pMargin1) == SfxItemState::SET )
{
const OUString ratio = static_cast<const SfxStringItem*>(pMargin1)->GetValue();
GetHRuler().SetValues(RulerChangeType::MARGIN1, GetHRuler().GetPageWidth() * ratio.toFloat());
}
else if ( pReqArgs &&
pReqArgs->GetItemState(SID_RULER_MARGIN2,true,&pMargin2) == SfxItemState::SET )
{
const OUString ratio = static_cast<const SfxStringItem*>(pMargin2)->GetValue();
GetHRuler().SetValues(RulerChangeType::MARGIN2, GetHRuler().GetPageWidth() * ratio.toFloat());
}
}
break;
case SID_RULER_BORDERS_VERTICAL:
case SID_RULER_BORDERS:
if ( pReqArgs )
......
......@@ -130,6 +130,8 @@
#include <comphelper/storagehelper.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <unotools/saveopt.hxx>
#include "swruler.hxx"
#include <EnhancedPDFExportHelper.hxx>
#include <numrule.hxx>
......@@ -3255,6 +3257,12 @@ OUString SwXTextDocument::getTrackedChangeAuthors()
return SW_MOD()->GetRedlineAuthorInfo();
}
OUString SwXTextDocument::getRulerState()
{
SwView* pView = pDocShell->GetView();
return OUString::fromUtf8((dynamic_cast<SwCommentRuler&>(pView->GetHRuler())).CreateJsonNotification().c_str());
}
OUString SwXTextDocument::getPostIts()
{
SolarMutexGuard aGuard;
......
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