Aspose::Words::INodeChangingCallback Interface Referenceabstract

Detailed Description

Implement this interface if you want to receive notifications when nodes are inserted or removed in the document.

Examples

Shows how customize node changing with a callback.

void FontChangeViaCallback()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Set the node changing callback to custom implementation,
// then add/remove nodes to get it to generate a log.
auto callback = MakeObject<ExDocument::HandleNodeChangingFontChanger>();
doc->set_NodeChangingCallback(callback);
builder->Writeln(u"Hello world!");
builder->Writeln(u"Hello again!");
builder->InsertField(u" HYPERLINK \"https://www.google.com/\" ");
builder->InsertShape(ShapeType::Rectangle, 300, 300);
doc->get_Range()->get_Fields()->idx_get(0)->Remove();
std::cout << callback->GetLog() << std::endl;
}
class HandleNodeChangingFontChanger : public INodeChangingCallback
{
public:
String GetLog()
{
return mLog->ToString();
}
HandleNodeChangingFontChanger() : mLog(MakeObject<System::Text::StringBuilder>())
{
}
private:
SharedPtr<System::Text::StringBuilder> mLog;
void NodeInserted(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()));
mLog->AppendLine(String::Format(u"\tHash:\t{0}", System::ObjectExt::GetHashCode(args->get_Node())));
if (args->get_Node()->get_NodeType() == NodeType::Run)
{
SharedPtr<Aspose::Words::Font> font = (System::DynamicCast<Run>(args->get_Node()))->get_Font();
mLog->Append(String::Format(u"\tFont:\tChanged from \"{0}\" {1}pt", font->get_Name(), font->get_Size()));
font->set_Size(24);
font->set_Name(u"Arial");
mLog->AppendLine(String::Format(u" to \"{0}\" {1}pt", font->get_Name(), font->get_Size()));
mLog->AppendLine(String::Format(u"\tContents:\n\t\t\"{0}\"", args->get_Node()->GetText()));
}
}
void NodeInserting(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\n{0:dd/MM/yyyy HH:mm:ss:fff}\tNode insertion:", System::DateTime::get_Now()));
}
void NodeRemoved(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()));
mLog->AppendLine(String::Format(u"\tHash code:\t{0}", System::ObjectExt::GetHashCode(args->get_Node())));
}
void NodeRemoving(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\n{0:dd/MM/yyyy HH:mm:ss:fff}\tNode removal:", System::DateTime::get_Now()));
}
};

#include <Aspose.Words.Cpp/INodeChangingCallback.h>

+ Inheritance diagram for Aspose::Words::INodeChangingCallback:

Public Member Functions

virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
virtual void NodeInserted (SharedPtr< NodeChangingArgs > args)=0
 Called when a node belonging to this document has been inserted into another node. More...
 
virtual void NodeInserting (SharedPtr< NodeChangingArgs > args)=0
 Called just before a node belonging to this document is about to be inserted into another node. More...
 
virtual void NodeRemoved (SharedPtr< NodeChangingArgs > args)=0
 Called when a node belonging to this document has been removed from its parent. More...
 
virtual void NodeRemoving (SharedPtr< NodeChangingArgs > args)=0
 Called just before a node belonging to this document is about to be removed from the document. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ GetType()

virtual const System::TypeInfo & Aspose::Words::INodeChangingCallback::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ Is()

virtual bool Aspose::Words::INodeChangingCallback::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ NodeInserted()

virtual void Aspose::Words::INodeChangingCallback::NodeInserted ( System::SharedPtr< Aspose::Words::NodeChangingArgs args)
pure virtual

Called when a node belonging to this document has been inserted into another node.

Examples

Shows how customize node changing with a callback.

void FontChangeViaCallback()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Set the node changing callback to custom implementation,
// then add/remove nodes to get it to generate a log.
auto callback = MakeObject<ExDocument::HandleNodeChangingFontChanger>();
doc->set_NodeChangingCallback(callback);
builder->Writeln(u"Hello world!");
builder->Writeln(u"Hello again!");
builder->InsertField(u" HYPERLINK \"https://www.google.com/\" ");
builder->InsertShape(ShapeType::Rectangle, 300, 300);
doc->get_Range()->get_Fields()->idx_get(0)->Remove();
std::cout << callback->GetLog() << std::endl;
}
class HandleNodeChangingFontChanger : public INodeChangingCallback
{
public:
String GetLog()
{
return mLog->ToString();
}
HandleNodeChangingFontChanger() : mLog(MakeObject<System::Text::StringBuilder>())
{
}
private:
SharedPtr<System::Text::StringBuilder> mLog;
void NodeInserted(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()));
mLog->AppendLine(String::Format(u"\tHash:\t{0}", System::ObjectExt::GetHashCode(args->get_Node())));
if (args->get_Node()->get_NodeType() == NodeType::Run)
{
SharedPtr<Aspose::Words::Font> font = (System::DynamicCast<Run>(args->get_Node()))->get_Font();
mLog->Append(String::Format(u"\tFont:\tChanged from \"{0}\" {1}pt", font->get_Name(), font->get_Size()));
font->set_Size(24);
font->set_Name(u"Arial");
mLog->AppendLine(String::Format(u" to \"{0}\" {1}pt", font->get_Name(), font->get_Size()));
mLog->AppendLine(String::Format(u"\tContents:\n\t\t\"{0}\"", args->get_Node()->GetText()));
}
}
void NodeInserting(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\n{0:dd/MM/yyyy HH:mm:ss:fff}\tNode insertion:", System::DateTime::get_Now()));
}
void NodeRemoved(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()));
mLog->AppendLine(String::Format(u"\tHash code:\t{0}", System::ObjectExt::GetHashCode(args->get_Node())));
}
void NodeRemoving(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\n{0:dd/MM/yyyy HH:mm:ss:fff}\tNode removal:", System::DateTime::get_Now()));
}
};

◆ NodeInserting()

virtual void Aspose::Words::INodeChangingCallback::NodeInserting ( System::SharedPtr< Aspose::Words::NodeChangingArgs args)
pure virtual

Called just before a node belonging to this document is about to be inserted into another node.

Examples

Shows how customize node changing with a callback.

void FontChangeViaCallback()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Set the node changing callback to custom implementation,
// then add/remove nodes to get it to generate a log.
auto callback = MakeObject<ExDocument::HandleNodeChangingFontChanger>();
doc->set_NodeChangingCallback(callback);
builder->Writeln(u"Hello world!");
builder->Writeln(u"Hello again!");
builder->InsertField(u" HYPERLINK \"https://www.google.com/\" ");
builder->InsertShape(ShapeType::Rectangle, 300, 300);
doc->get_Range()->get_Fields()->idx_get(0)->Remove();
std::cout << callback->GetLog() << std::endl;
}
class HandleNodeChangingFontChanger : public INodeChangingCallback
{
public:
String GetLog()
{
return mLog->ToString();
}
HandleNodeChangingFontChanger() : mLog(MakeObject<System::Text::StringBuilder>())
{
}
private:
SharedPtr<System::Text::StringBuilder> mLog;
void NodeInserted(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()));
mLog->AppendLine(String::Format(u"\tHash:\t{0}", System::ObjectExt::GetHashCode(args->get_Node())));
if (args->get_Node()->get_NodeType() == NodeType::Run)
{
SharedPtr<Aspose::Words::Font> font = (System::DynamicCast<Run>(args->get_Node()))->get_Font();
mLog->Append(String::Format(u"\tFont:\tChanged from \"{0}\" {1}pt", font->get_Name(), font->get_Size()));
font->set_Size(24);
font->set_Name(u"Arial");
mLog->AppendLine(String::Format(u" to \"{0}\" {1}pt", font->get_Name(), font->get_Size()));
mLog->AppendLine(String::Format(u"\tContents:\n\t\t\"{0}\"", args->get_Node()->GetText()));
}
}
void NodeInserting(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\n{0:dd/MM/yyyy HH:mm:ss:fff}\tNode insertion:", System::DateTime::get_Now()));
}
void NodeRemoved(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()));
mLog->AppendLine(String::Format(u"\tHash code:\t{0}", System::ObjectExt::GetHashCode(args->get_Node())));
}
void NodeRemoving(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\n{0:dd/MM/yyyy HH:mm:ss:fff}\tNode removal:", System::DateTime::get_Now()));
}
};

◆ NodeRemoved()

virtual void Aspose::Words::INodeChangingCallback::NodeRemoved ( System::SharedPtr< Aspose::Words::NodeChangingArgs args)
pure virtual

Called when a node belonging to this document has been removed from its parent.

Examples

Shows how customize node changing with a callback.

void FontChangeViaCallback()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Set the node changing callback to custom implementation,
// then add/remove nodes to get it to generate a log.
auto callback = MakeObject<ExDocument::HandleNodeChangingFontChanger>();
doc->set_NodeChangingCallback(callback);
builder->Writeln(u"Hello world!");
builder->Writeln(u"Hello again!");
builder->InsertField(u" HYPERLINK \"https://www.google.com/\" ");
builder->InsertShape(ShapeType::Rectangle, 300, 300);
doc->get_Range()->get_Fields()->idx_get(0)->Remove();
std::cout << callback->GetLog() << std::endl;
}
class HandleNodeChangingFontChanger : public INodeChangingCallback
{
public:
String GetLog()
{
return mLog->ToString();
}
HandleNodeChangingFontChanger() : mLog(MakeObject<System::Text::StringBuilder>())
{
}
private:
SharedPtr<System::Text::StringBuilder> mLog;
void NodeInserted(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()));
mLog->AppendLine(String::Format(u"\tHash:\t{0}", System::ObjectExt::GetHashCode(args->get_Node())));
if (args->get_Node()->get_NodeType() == NodeType::Run)
{
SharedPtr<Aspose::Words::Font> font = (System::DynamicCast<Run>(args->get_Node()))->get_Font();
mLog->Append(String::Format(u"\tFont:\tChanged from \"{0}\" {1}pt", font->get_Name(), font->get_Size()));
font->set_Size(24);
font->set_Name(u"Arial");
mLog->AppendLine(String::Format(u" to \"{0}\" {1}pt", font->get_Name(), font->get_Size()));
mLog->AppendLine(String::Format(u"\tContents:\n\t\t\"{0}\"", args->get_Node()->GetText()));
}
}
void NodeInserting(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\n{0:dd/MM/yyyy HH:mm:ss:fff}\tNode insertion:", System::DateTime::get_Now()));
}
void NodeRemoved(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()));
mLog->AppendLine(String::Format(u"\tHash code:\t{0}", System::ObjectExt::GetHashCode(args->get_Node())));
}
void NodeRemoving(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\n{0:dd/MM/yyyy HH:mm:ss:fff}\tNode removal:", System::DateTime::get_Now()));
}
};

◆ NodeRemoving()

virtual void Aspose::Words::INodeChangingCallback::NodeRemoving ( System::SharedPtr< Aspose::Words::NodeChangingArgs args)
pure virtual

Called just before a node belonging to this document is about to be removed from the document.

Examples

Shows how customize node changing with a callback.

void FontChangeViaCallback()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Set the node changing callback to custom implementation,
// then add/remove nodes to get it to generate a log.
auto callback = MakeObject<ExDocument::HandleNodeChangingFontChanger>();
doc->set_NodeChangingCallback(callback);
builder->Writeln(u"Hello world!");
builder->Writeln(u"Hello again!");
builder->InsertField(u" HYPERLINK \"https://www.google.com/\" ");
builder->InsertShape(ShapeType::Rectangle, 300, 300);
doc->get_Range()->get_Fields()->idx_get(0)->Remove();
std::cout << callback->GetLog() << std::endl;
}
class HandleNodeChangingFontChanger : public INodeChangingCallback
{
public:
String GetLog()
{
return mLog->ToString();
}
HandleNodeChangingFontChanger() : mLog(MakeObject<System::Text::StringBuilder>())
{
}
private:
SharedPtr<System::Text::StringBuilder> mLog;
void NodeInserted(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()));
mLog->AppendLine(String::Format(u"\tHash:\t{0}", System::ObjectExt::GetHashCode(args->get_Node())));
if (args->get_Node()->get_NodeType() == NodeType::Run)
{
SharedPtr<Aspose::Words::Font> font = (System::DynamicCast<Run>(args->get_Node()))->get_Font();
mLog->Append(String::Format(u"\tFont:\tChanged from \"{0}\" {1}pt", font->get_Name(), font->get_Size()));
font->set_Size(24);
font->set_Name(u"Arial");
mLog->AppendLine(String::Format(u" to \"{0}\" {1}pt", font->get_Name(), font->get_Size()));
mLog->AppendLine(String::Format(u"\tContents:\n\t\t\"{0}\"", args->get_Node()->GetText()));
}
}
void NodeInserting(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\n{0:dd/MM/yyyy HH:mm:ss:fff}\tNode insertion:", System::DateTime::get_Now()));
}
void NodeRemoved(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()));
mLog->AppendLine(String::Format(u"\tHash code:\t{0}", System::ObjectExt::GetHashCode(args->get_Node())));
}
void NodeRemoving(SharedPtr<NodeChangingArgs> args) override
{
mLog->AppendLine(String::Format(u"\n{0:dd/MM/yyyy HH:mm:ss:fff}\tNode removal:", System::DateTime::get_Now()));
}
};

◆ Type()

static const System::TypeInfo & Aspose::Words::INodeChangingCallback::Type ( )
static