Aspose::Words::NodeChangingArgs Class Reference

Detailed Description

Provides data for methods of the INodeChangingCallback interface.

See also
Aspose::Words::DocumentBase
Aspose::Words::INodeChangingCallback
Aspose::Words::NodeChangingAction
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/NodeChangingArgs.h>

+ Inheritance diagram for Aspose::Words::NodeChangingArgs:

Public Member Functions

NodeChangingAction get_Action () const
 Gets a value indicating what type of node change event is occurring. More...
 
SharedPtr< Nodeget_NewParent () const
 Gets the node's parent that will be set after the operation completes. More...
 
SharedPtr< Nodeget_Node () const
 Gets the Node that is being added or removed. More...
 
SharedPtr< Nodeget_OldParent () const
 Gets the node's parent before the operation began. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ get_Action()

Aspose::Words::NodeChangingAction Aspose::Words::NodeChangingArgs::get_Action ( ) const

Gets a value indicating what type of node change event is occurring.

Examples

Shows how to use a NodeChangingCallback to monitor changes to the document tree in real-time as we edit it.

void NodeChangingCallback()
{
auto doc = MakeObject<Document>();
doc->set_NodeChangingCallback(MakeObject<ExNode::NodeChangingPrinter>());
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
builder->StartTable();
builder->InsertCell();
builder->Write(u"Cell 1");
builder->InsertCell();
builder->Write(u"Cell 2");
builder->EndTable();
builder->InsertImage(System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg"));
builder->get_CurrentParagraph()->get_ParentNode()->RemoveAllChildren();
}
class NodeChangingPrinter : public INodeChangingCallback
{
private:
void NodeInserting(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Insert, args->get_Action());
ASPOSE_ASSERT_EQ(nullptr, args->get_OldParent());
}
void NodeInserted(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Insert, args->get_Action());
ASSERT_FALSE(args->get_NewParent() == nullptr);
std::cout << "Inserted node:" << std::endl;
std::cout << String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()) << std::endl;
if (args->get_Node()->GetText().Trim() != u"")
{
std::cout << "\tText:\t\"" << args->get_Node()->GetText().Trim() << "\"" << std::endl;
}
std::cout << "\tHash:\t" << System::ObjectExt::GetHashCode(args->get_Node()) << std::endl;
std::cout << String::Format(u"\tParent:\t{0} ({1})", args->get_NewParent()->get_NodeType(), System::ObjectExt::GetHashCode(args->get_NewParent()))
<< std::endl;
}
void NodeRemoving(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Remove, args->get_Action());
}
void NodeRemoved(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Remove, args->get_Action());
ASSERT_TRUE(args->get_NewParent() == nullptr);
std::cout << String::Format(u"Removed node: {0} ({1})", args->get_Node()->get_NodeType(), System::ObjectExt::GetHashCode(args->get_Node()))
<< std::endl;
}
};

◆ get_NewParent()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::NodeChangingArgs::get_NewParent ( ) const

Gets the node's parent that will be set after the operation completes.

Examples

Shows how to use a NodeChangingCallback to monitor changes to the document tree in real-time as we edit it.

void NodeChangingCallback()
{
auto doc = MakeObject<Document>();
doc->set_NodeChangingCallback(MakeObject<ExNode::NodeChangingPrinter>());
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
builder->StartTable();
builder->InsertCell();
builder->Write(u"Cell 1");
builder->InsertCell();
builder->Write(u"Cell 2");
builder->EndTable();
builder->InsertImage(System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg"));
builder->get_CurrentParagraph()->get_ParentNode()->RemoveAllChildren();
}
class NodeChangingPrinter : public INodeChangingCallback
{
private:
void NodeInserting(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Insert, args->get_Action());
ASPOSE_ASSERT_EQ(nullptr, args->get_OldParent());
}
void NodeInserted(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Insert, args->get_Action());
ASSERT_FALSE(args->get_NewParent() == nullptr);
std::cout << "Inserted node:" << std::endl;
std::cout << String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()) << std::endl;
if (args->get_Node()->GetText().Trim() != u"")
{
std::cout << "\tText:\t\"" << args->get_Node()->GetText().Trim() << "\"" << std::endl;
}
std::cout << "\tHash:\t" << System::ObjectExt::GetHashCode(args->get_Node()) << std::endl;
std::cout << String::Format(u"\tParent:\t{0} ({1})", args->get_NewParent()->get_NodeType(), System::ObjectExt::GetHashCode(args->get_NewParent()))
<< std::endl;
}
void NodeRemoving(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Remove, args->get_Action());
}
void NodeRemoved(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Remove, args->get_Action());
ASSERT_TRUE(args->get_NewParent() == nullptr);
std::cout << String::Format(u"Removed node: {0} ({1})", args->get_Node()->get_NodeType(), System::ObjectExt::GetHashCode(args->get_Node()))
<< std::endl;
}
};

◆ get_Node()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::NodeChangingArgs::get_Node ( ) const

Gets the Node that is being added or removed.

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()));
}
};

◆ get_OldParent()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::NodeChangingArgs::get_OldParent ( ) const

Gets the node's parent before the operation began.

Examples

Shows how to use a NodeChangingCallback to monitor changes to the document tree in real-time as we edit it.

void NodeChangingCallback()
{
auto doc = MakeObject<Document>();
doc->set_NodeChangingCallback(MakeObject<ExNode::NodeChangingPrinter>());
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
builder->StartTable();
builder->InsertCell();
builder->Write(u"Cell 1");
builder->InsertCell();
builder->Write(u"Cell 2");
builder->EndTable();
builder->InsertImage(System::Drawing::Image::FromFile(ImageDir + u"Logo.jpg"));
builder->get_CurrentParagraph()->get_ParentNode()->RemoveAllChildren();
}
class NodeChangingPrinter : public INodeChangingCallback
{
private:
void NodeInserting(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Insert, args->get_Action());
ASPOSE_ASSERT_EQ(nullptr, args->get_OldParent());
}
void NodeInserted(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Insert, args->get_Action());
ASSERT_FALSE(args->get_NewParent() == nullptr);
std::cout << "Inserted node:" << std::endl;
std::cout << String::Format(u"\tType:\t{0}", args->get_Node()->get_NodeType()) << std::endl;
if (args->get_Node()->GetText().Trim() != u"")
{
std::cout << "\tText:\t\"" << args->get_Node()->GetText().Trim() << "\"" << std::endl;
}
std::cout << "\tHash:\t" << System::ObjectExt::GetHashCode(args->get_Node()) << std::endl;
std::cout << String::Format(u"\tParent:\t{0} ({1})", args->get_NewParent()->get_NodeType(), System::ObjectExt::GetHashCode(args->get_NewParent()))
<< std::endl;
}
void NodeRemoving(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Remove, args->get_Action());
}
void NodeRemoved(SharedPtr<NodeChangingArgs> args) override
{
ASSERT_EQ(NodeChangingAction::Remove, args->get_Action());
ASSERT_TRUE(args->get_NewParent() == nullptr);
std::cout << String::Format(u"Removed node: {0} ({1})", args->get_Node()->get_NodeType(), System::ObjectExt::GetHashCode(args->get_Node()))
<< std::endl;
}
};

◆ GetType()

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

Reimplemented from System::Object.

◆ Is()

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

Reimplemented from System::Object.

◆ Type()

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