<commit_before>

#include <iostream>

#include "storage/Devices/PartitionImpl.h"
#include "storage/Devices/DiskImpl.h"
#include "storage/Devicegraph.h"
#include "storage/SystemInfo/SystemInfo.h"
#include "storage/Utils/SystemCmd.h"
#include "storage/Utils/StorageDefines.h"
#include "storage/Utils/StorageTmpl.h"

namespace storage
{

    using namespace std;

    const char* DeviceTraits<Partition>::classname = "Partition";

    Partition::Impl::Impl(const string& name, const Region& region, PartitionType type)
	: BlkDevice::Impl(name, region.to_kb(region.get_length())), region(region), type(type),
	  id(ID_LINUX), boot(false)
    {
    }

    Partition::Impl::Impl(const xmlNode* node)
	: BlkDevice::Impl(node), region(), type(PRIMARY), id(ID_LINUX), boot(false)
    {
	string tmp;

	getChildValue(node, "region", region);
	if (getChildValue(node, "type", tmp))
	    type = toValueWithFallback(tmp, PRIMARY);
	getChildValue(node, "id", id);
	getChildValue(node, "boot", boot);
    }

    void
    Partition::Impl::probe(SystemInfo& systeminfo)
    {
	BlkDevice::Impl::probe(systeminfo);

	const Devicegraph* g = get_devicegraph();

	Devicegraph::Impl::vertex_descriptor v1 = g->get_impl().parent(get_vertex());
	Devicegraph::Impl::vertex_descriptor v2 = g->get_impl().parent(v1);

	string pp_name = dynamic_cast<const BlkDevice*>(g->get_impl()[v2])->get_name();

	const Parted& parted = systeminfo.getParted(pp_name);
	Parted::Entry entry;
	if (!parted.getEntry(get_number(), entry))
	    throw;

	id = entry.id;
	boot = entry.boot;
    }

    void
    Partition::Impl::save(xmlNode* node) const
    {
	BlkDevice::Impl::save(node);

	setChildValue(node, "region", region);
	setChildValue(node, "type", toString(type));
	setChildValueIf(node, "id", id, id != 0);
	setChildValueIf(node, "boot", boot, boot);
    }

    unsigned int
    Partition::Impl::get_number() const
    {
	string::size_type pos = get_name().find_last_not_of("0123456789");
	return atoi(get_name().substr(pos + 1).c_str());
    }

    void
    Partition::Impl::set_size_k(unsigned long long size_k)
    {
	BlkDevice::Impl::set_size_k(size_k);

	const PartitionTable* partitiontable = get_partition_table();

	const Disk* disk = partitiontable->get_disk();

	region.set_length(get_size_k() * 1024 / disk->get_impl().get_geometry().cylinderSize());
    }

    void
    Partition::Impl::set_region(const Region& region)
    {
	Impl::region = region;

	const PartitionTable* partitiontable = get_partition_table();

	const Disk* disk = partitiontable->get_disk();

	const Geometry& geometry = disk->get_impl().get_geometry();
	if (region.get_block_size() != geometry.cylinderSize())
	    ST_THROW(DifferentBlockSizes(region.get_block_size(), geometry.cylinderSize()));

	set_size_k(region.get_length() * disk->get_impl().get_geometry().cylinderSize() / 1024);
    }

    const PartitionTable*
    Partition::Impl::get_partition_table() const
    {
	Devicegraph::Impl::vertex_descriptor v = get_devicegraph()->get_impl().parent(get_vertex());

	return to_partition_table(get_devicegraph()->get_impl()[v]);
    }

    void
    Partition::Impl::add_create_actions(Actiongraph::Impl& actiongraph) const
    {
	vector<Action::Base*> actions;

	actions.push_back(new Action::Create(get_sid()));
	actions.push_back(new Action::SetPartitionId(get_sid()));

	actiongraph.add_chain(actions);
    }

    void
    Partition::Impl::add_modify_actions(Actiongraph::Impl& actiongraph, const Device* lhs_base) const
    {
	const Impl& lhs = dynamic_cast<const Impl&>(lhs_base->get_impl());

	if (get_type() != lhs.get_type())
	{
	    throw runtime_error("cannot change partition type");
	}

	if (get_region().get_start() != lhs.get_region().get_start())
	{
	    throw runtime_error("cannot move partition");
	}

	if (get_id() != lhs.get_id())
	{
	    Action::Base* action = new Action::SetPartitionId(get_sid());
	    actiongraph.add_vertex(action);
	}
    }

    void
    Partition::Impl::add_delete_actions(Actiongraph::Impl& actiongraph) const
    {
	vector<Action::Base*> actions;

	actions.push_back(new Action::Delete(get_sid()));

	actiongraph.add_chain(actions);
    }

    bool
    Partition::Impl::equal(const Device::Impl& rhs_base) const
    {
	const Impl& rhs = dynamic_cast<const Impl&>(rhs_base);

	if (!BlkDevice::Impl::equal(rhs))
	    return false;

	return region == rhs.region && type == rhs.type && id == rhs.id && boot == rhs.boot;
    }

    void
    Partition::Impl::log_diff(std::ostream& log, const Device::Impl& rhs_base) const
    {
	const Impl& rhs = dynamic_cast<const Impl&>(rhs_base);

	BlkDevice::Impl::log_diff(log, rhs);

	storage::log_diff(log, "region", region, rhs.region);
	storage::log_diff_enum(log, "type", type, rhs.type);
	storage::log_diff_hex(log, "id", id, rhs.id);
	storage::log_diff(log, "boot", boot, rhs.boot);
    }

    void
    Partition::Impl::print(std::ostream& out) const
    {
	BlkDevice::Impl::print(out);

	out << " region:" << get_region();
    }

    void
    Partition::Impl::process_udev_ids(vector<string>& udev_ids) const
    {
	const Devicegraph* g = get_devicegraph();

	Devicegraph::Impl::vertex_descriptor v1 = g->get_impl().parent(get_vertex());
	Devicegraph::Impl::vertex_descriptor v2 = g->get_impl().parent(v1);

	const Disk* disk = dynamic_cast<const Disk*>(g->get_impl()[v2]);

	disk->get_impl().process_udev_ids(udev_ids);
    }

    bool
    Partition::Impl::cmp_lt_number(const Partition* lhs, const Partition* rhs)
    {
	return lhs->get_number() < rhs->get_number();
    }

    Text
    Partition::Impl::do_create_text(bool doing) const
    {
	return sformat(_("Create partition %1$s (%2$s)"), get_name().c_str(), get_size_string().c_str());
    }

    void
    Partition::Impl::do_create() const
    {
	const PartitionTable* partitiontable = get_partition_table();

	const Disk* disk = partitiontable->get_disk();

	string cmd_line = PARTEDBIN " -s " + quote(disk->get_name()) + " unit cyl mkpart " +
	    toString(get_type()) + " ";

	if (get_type() != EXTENDED)
	{
	    // TODO look at id
	    cmd_line += "ext2 ";
	}

	cmd_line += to_string(get_region().get_start()) + " " + to_string(get_region().get_end());

	cout << cmd_line << endl;

	SystemCmd cmd(cmd_line);
	if (cmd.retcode() != 0)
	    throw runtime_error("create partition failed");
    }

    Text
    Partition::Impl::do_set_id_text(bool doing) const
    {
	string tmp = id_to_string(get_id());

	if (tmp.empty())
	    return sformat(_("Set id of partition %1$s to 0x%2$02X"), get_name().c_str(), get_id());
	else
	    return sformat(_("Set id of partition %1$s to %2$s (0x%3$02X)"), get_name().c_str(),
			   tmp.c_str(), get_id());
    }

    void
    Partition::Impl::do_set_id() const
    {
	const PartitionTable* partitiontable = get_partition_table();

	const Disk* disk = partitiontable->get_disk();

	string cmd_line = PARTEDBIN " -s " + quote(disk->get_name()) + " set " +
	    to_string(get_number()) + " type " + to_string(get_id());
	cout << cmd_line << endl;

	SystemCmd cmd(cmd_line);
	if (cmd.retcode() != 0)
	    throw runtime_error("set partition id failed");
    }

    Text
    Partition::Impl::do_delete_text(bool doing) const
    {
	return sformat(_("Delete partition %1$s (%2$s)"), get_name().c_str(),
		       get_size_string().c_str());
    }

    void
    Partition::Impl::do_delete() const
    {
	const PartitionTable* partitiontable = get_partition_table();

	const Disk* disk = partitiontable->get_disk();

	string cmd_line = PARTEDBIN " -s " + disk->get_name() + " rm " + to_string(get_number());
	cout << cmd_line << endl;

	SystemCmd cmd(cmd_line);
	if (cmd.retcode() != 0)
	    throw runtime_error("delete partition failed");
    }

    namespace Action
    {

	Text
	SetPartitionId::text(const Actiongraph::Impl& actiongraph, bool doing) const
	{
	    const Partition* partition = to_partition(device_rhs(actiongraph));
	    return partition->get_impl().do_set_id_text(doing);
	}

	void
	SetPartitionId::commit(const Actiongraph::Impl& actiongraph) const
	{
	    const Partition* partition = to_partition(device_rhs(actiongraph));
	    partition->get_impl().do_set_id();
	}

    }

    string
    id_to_string(unsigned int id)
    {
	switch (id)
	{
	    case ID_SWAP: return "Linux Swap";
	    case ID_LINUX: return "Linux";
	    case ID_LVM: return "Linux LVM";
	    case ID_RAID: return "Linux RAID";
	}

	return "";
    }

}
<commit_msg>- use new ST_THROW macro<commit_after>

#include <iostream>

#include "storage/Devices/PartitionImpl.h"
#include "storage/Devices/DiskImpl.h"
#include "storage/Devicegraph.h"
#include "storage/SystemInfo/SystemInfo.h"
#include "storage/Utils/SystemCmd.h"
#include "storage/Utils/StorageDefines.h"
#include "storage/Utils/StorageTmpl.h"

namespace storage
{

    using namespace std;

    const char* DeviceTraits<Partition>::classname = "Partition";

    Partition::Impl::Impl(const string& name, const Region& region, PartitionType type)
	: BlkDevice::Impl(name, region.to_kb(region.get_length())), region(region), type(type),
	  id(ID_LINUX), boot(false)
    {
    }

    Partition::Impl::Impl(const xmlNode* node)
	: BlkDevice::Impl(node), region(), type(PRIMARY), id(ID_LINUX), boot(false)
    {
	string tmp;

	getChildValue(node, "region", region);
	if (getChildValue(node, "type", tmp))
	    type = toValueWithFallback(tmp, PRIMARY);
	getChildValue(node, "id", id);
	getChildValue(node, "boot", boot);
    }

    void
    Partition::Impl::probe(SystemInfo& systeminfo)
    {
	BlkDevice::Impl::probe(systeminfo);

	const Devicegraph* g = get_devicegraph();

	Devicegraph::Impl::vertex_descriptor v1 = g->get_impl().parent(get_vertex());
	Devicegraph::Impl::vertex_descriptor v2 = g->get_impl().parent(v1);

	string pp_name = dynamic_cast<const BlkDevice*>(g->get_impl()[v2])->get_name();

	const Parted& parted = systeminfo.getParted(pp_name);
	Parted::Entry entry;
	if (!parted.getEntry(get_number(), entry))
	    throw;

	id = entry.id;
	boot = entry.boot;
    }

    void
    Partition::Impl::save(xmlNode* node) const
    {
	BlkDevice::Impl::save(node);

	setChildValue(node, "region", region);
	setChildValue(node, "type", toString(type));
	setChildValueIf(node, "id", id, id != 0);
	setChildValueIf(node, "boot", boot, boot);
    }

    unsigned int
    Partition::Impl::get_number() const
    {
	string::size_type pos = get_name().find_last_not_of("0123456789");
	return atoi(get_name().substr(pos + 1).c_str());
    }

    void
    Partition::Impl::set_size_k(unsigned long long size_k)
    {
	BlkDevice::Impl::set_size_k(size_k);

	const PartitionTable* partitiontable = get_partition_table();

	const Disk* disk = partitiontable->get_disk();

	region.set_length(get_size_k() * 1024 / disk->get_impl().get_geometry().cylinderSize());
    }

    void
    Partition::Impl::set_region(const Region& region)
    {
	Impl::region = region;

	const PartitionTable* partitiontable = get_partition_table();

	const Disk* disk = partitiontable->get_disk();

	const Geometry& geometry = disk->get_impl().get_geometry();
	if (region.get_block_size() != geometry.cylinderSize())
	    ST_THROW(DifferentBlockSizes(region.get_block_size(), geometry.cylinderSize()));

	set_size_k(region.get_length() * disk->get_impl().get_geometry().cylinderSize() / 1024);
    }

    const PartitionTable*
    Partition::Impl::get_partition_table() const
    {
	Devicegraph::Impl::vertex_descriptor v = get_devicegraph()->get_impl().parent(get_vertex());

	return to_partition_table(get_devicegraph()->get_impl()[v]);
    }

    void
    Partition::Impl::add_create_actions(Actiongraph::Impl& actiongraph) const
    {
	vector<Action::Base*> actions;

	actions.push_back(new Action::Create(get_sid()));
	actions.push_back(new Action::SetPartitionId(get_sid()));

	actiongraph.add_chain(actions);
    }

    void
    Partition::Impl::add_modify_actions(Actiongraph::Impl& actiongraph, const Device* lhs_base) const
    {
	const Impl& lhs = dynamic_cast<const Impl&>(lhs_base->get_impl());

	if (get_type() != lhs.get_type())
	{
	    throw runtime_error("cannot change partition type");
	}

	if (get_region().get_start() != lhs.get_region().get_start())
	{
	    throw runtime_error("cannot move partition");
	}

	if (get_id() != lhs.get_id())
	{
	    Action::Base* action = new Action::SetPartitionId(get_sid());
	    actiongraph.add_vertex(action);
	}
    }

    void
    Partition::Impl::add_delete_actions(Actiongraph::Impl& actiongraph) const
    {
	vector<Action::Base*> actions;

	actions.push_back(new Action::Delete(get_sid()));

	actiongraph.add_chain(actions);
    }

    bool
    Partition::Impl::equal(const Device::Impl& rhs_base) const
    {
	const Impl& rhs = dynamic_cast<const Impl&>(rhs_base);

	if (!BlkDevice::Impl::equal(rhs))
	    return false;

	return region == rhs.region && type == rhs.type && id == rhs.id && boot == rhs.boot;
    }

    void
    Partition::Impl::log_diff(std::ostream& log, const Device::Impl& rhs_base) const
    {
	const Impl& rhs = dynamic_cast<const Impl&>(rhs_base);

	BlkDevice::Impl::log_diff(log, rhs);

	storage::log_diff(log, "region", region, rhs.region);
	storage::log_diff_enum(log, "type", type, rhs.type);
	storage::log_diff_hex(log, "id", id, rhs.id);
	storage::log_diff(log, "boot", boot, rhs.boot);
    }

    void
    Partition::Impl::print(std::ostream& out) const
    {
	BlkDevice::Impl::print(out);

	out << " region:" << get_region();
    }

    void
    Partition::Impl::process_udev_ids(vector<string>& udev_ids) const
    {
	const Devicegraph* g = get_devicegraph();

	Devicegraph::Impl::vertex_descriptor v1 = g->get_impl().parent(get_vertex());
	Devicegraph::Impl::vertex_descriptor v2 = g->get_impl().parent(v1);

	const Disk* disk = dynamic_cast<const Disk*>(g->get_impl()[v2]);

	disk->get_impl().process_udev_ids(udev_ids);
    }

    bool
    Partition::Impl::cmp_lt_number(const Partition* lhs, const Partition* rhs)
    {
	return lhs->get_number() < rhs->get_number();
    }

    Text
    Partition::Impl::do_create_text(bool doing) const
    {
	return sformat(_("Create partition %1$s (%2$s)"), get_name().c_str(), get_size_string().c_str());
    }

    void
    Partition::Impl::do_create() const
    {
	const PartitionTable* partitiontable = get_partition_table();

	const Disk* disk = partitiontable->get_disk();

	string cmd_line = PARTEDBIN " -s " + quote(disk->get_name()) + " unit cyl mkpart " +
	    toString(get_type()) + " ";

	if (get_type() != EXTENDED)
	{
	    // TODO look at id
	    cmd_line += "ext2 ";
	}

	cmd_line += to_string(get_region().get_start()) + " " + to_string(get_region().get_end());

	cout << cmd_line << endl;

	SystemCmd cmd(cmd_line);
	if (cmd.retcode() != 0)
	    ST_THROW(Exception("create partition failed"));
    }

    Text
    Partition::Impl::do_set_id_text(bool doing) const
    {
	string tmp = id_to_string(get_id());

	if (tmp.empty())
	    return sformat(_("Set id of partition %1$s to 0x%2$02X"), get_name().c_str(), get_id());
	else
	    return sformat(_("Set id of partition %1$s to %2$s (0x%3$02X)"), get_name().c_str(),
			   tmp.c_str(), get_id());
    }

    void
    Partition::Impl::do_set_id() const
    {
	const PartitionTable* partitiontable = get_partition_table();

	const Disk* disk = partitiontable->get_disk();

	string cmd_line = PARTEDBIN " -s " + quote(disk->get_name()) + " set " +
	    to_string(get_number()) + " type " + to_string(get_id());
	cout << cmd_line << endl;

	SystemCmd cmd(cmd_line);
	if (cmd.retcode() != 0)
	    ST_THROW(Exception("set partition id failed"));
    }

    Text
    Partition::Impl::do_delete_text(bool doing) const
    {
	return sformat(_("Delete partition %1$s (%2$s)"), get_name().c_str(),
		       get_size_string().c_str());
    }

    void
    Partition::Impl::do_delete() const
    {
	const PartitionTable* partitiontable = get_partition_table();

	const Disk* disk = partitiontable->get_disk();

	string cmd_line = PARTEDBIN " -s " + disk->get_name() + " rm " + to_string(get_number());
	cout << cmd_line << endl;

	SystemCmd cmd(cmd_line);
	if (cmd.retcode() != 0)
	    ST_THROW(Exception("delete partition failed"));
    }

    namespace Action
    {

	Text
	SetPartitionId::text(const Actiongraph::Impl& actiongraph, bool doing) const
	{
	    const Partition* partition = to_partition(device_rhs(actiongraph));
	    return partition->get_impl().do_set_id_text(doing);
	}

	void
	SetPartitionId::commit(const Actiongraph::Impl& actiongraph) const
	{
	    const Partition* partition = to_partition(device_rhs(actiongraph));
	    partition->get_impl().do_set_id();
	}

    }

    string
    id_to_string(unsigned int id)
    {
	switch (id)
	{
	    case ID_SWAP: return "Linux Swap";
	    case ID_LINUX: return "Linux";
	    case ID_LVM: return "Linux LVM";
	    case ID_RAID: return "Linux RAID";
	}

	return "";
    }

}
<|endoftext|>


<commit_before>#include <pddlparse/detail/normalization/Reduction.h>

#include <pddlparse/AST.h>
#include <pddlparse/Exception.h>
#include <pddlparse/NormalizedAST.h>
#include <pddlparse/detail/normalization/AtomicFormula.h>
#include <pddlparse/detail/normalization/CollectFreeVariables.h>

namespace pddl
{
namespace detail
{

////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Reduction
//
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
// Forward declarations
////////////////////////////////////////////////////////////////////////////////////////////////////

void eliminateImply(ast::Precondition &precondition);
void negationNormalize(ast::Precondition &precondition);
void eliminateForAll(ast::Precondition &precondition);
void eliminateDoubleNegations(ast::Precondition &precondition);

////////////////////////////////////////////////////////////////////////////////////////////////////

void eliminateImply(ast::Precondition &precondition)
{
	const auto handleAtomicFormula =
		[](ast::AtomicFormula &)
		{
		};

	const auto handleAnd =
		[](ast::AndPointer<ast::Precondition> &and_)
		{
			for (auto &argument : and_->arguments)
				eliminateImply(argument);
		};

	const auto handleExists =
		[](ast::ExistsPointer<ast::Precondition> &exists)
		{
			eliminateImply(exists->argument);
		};

	const auto handleForAll =
		[](ast::ForAllPointer<ast::Precondition> &forAll)
		{
			eliminateImply(forAll->argument);
		};

	const auto handleImply =
		[&](ast::ImplyPointer<ast::Precondition> &imply)
		{
			eliminateImply(imply->argumentLeft);
			eliminateImply(imply->argumentRight);

			ast::Or<ast::Precondition>::Arguments arguments;
			arguments.reserve(2);
			arguments.emplace_back(std::make_unique<ast::Not<ast::Precondition>>(std::move(imply->argumentLeft)));
			arguments.emplace_back(std::move(imply->argumentRight));

			precondition = std::make_unique<ast::Or<ast::Precondition>>(std::move(arguments));
		};

	const auto handleNot =
		[](ast::NotPointer<ast::Precondition> &not_)
		{
			eliminateImply(not_->argument);
		};

	const auto handleOr =
		[](ast::OrPointer<ast::Precondition> &or_)
		{
			for (auto &argument : or_->arguments)
				eliminateImply(argument);
		};

	precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

// Negation-normalize an expression whose parent is a “not” expression
void negationNormalizeNegated(ast::Precondition &precondition, ast::Precondition &parent)
{
	const auto handleAtomicFormula =
		[](ast::AtomicFormula &)
		{
		};

	const auto handleAnd =
		[&](ast::AndPointer<ast::Precondition> &and_)
		{
			ast::Or<ast::Precondition>::Arguments arguments;
			arguments.reserve(and_->arguments.size());

			// Apply De Morgan
			for (auto &argument : and_->arguments)
				arguments.emplace_back(std::make_unique<ast::Not<ast::Precondition>>(std::move(argument)));

			// Finally, negation-normalize each argument
			for (auto &argument : arguments)
				negationNormalize(argument);

			// Replace the parent “not” containing this “and” with an “or” over the negated arguments
			parent = std::make_unique<ast::Or<ast::Precondition>>(std::move(arguments));
		};

	const auto handleExists =
		[](ast::ExistsPointer<ast::Precondition> &exists)
		{
			negationNormalize(exists->argument);
		};

	const auto handleForAll =
		[](ast::ForAllPointer<ast::Precondition> &forAll)
		{
			negationNormalize(forAll->argument);
		};

	const auto handleImply =
		[](ast::ImplyPointer<ast::Precondition> &)
		{
			throw std::logic_error("precondition not ready for negation normalization (imply), please report to the bug tracker");
		};

	const auto handleNot =
		[&](ast::NotPointer<ast::Precondition> &not_)
		{
			negationNormalize(not_->argument);

			// As the parent contains the argument, the argument needs to be saved before overwriting the parent
			// TODO: check whether this workaround can be avoided
			auto argument = std::move(not_->argument);
			parent = std::move(argument);
		};

	const auto handleOr =
		[&](ast::OrPointer<ast::Precondition> &or_)
		{
			ast::And<ast::Precondition>::Arguments arguments;
			arguments.reserve(or_->arguments.size());

			// Apply De Morgan
			for (auto &argument : or_->arguments)
				arguments.emplace_back(std::make_unique<ast::Not<ast::Precondition>>(std::move(argument)));

			// Finally, negation-normalize each argument
			for (auto &argument : arguments)
				negationNormalize(argument);

			// Replace the parent “not” containing this “or” with an “and” over the negated arguments
			parent = std::make_unique<ast::And<ast::Precondition>>(std::move(arguments));
		};

	precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void negationNormalize(ast::Precondition &precondition)
{
	const auto handleAtomicFormula =
		[](ast::AtomicFormula &)
		{
		};

	const auto handleAnd =
		[](ast::AndPointer<ast::Precondition> &and_)
		{
			for (auto &argument : and_->arguments)
				negationNormalize(argument);
		};

	const auto handleExists =
		[](ast::ExistsPointer<ast::Precondition> &exists)
		{
			negationNormalize(exists->argument);
		};

	const auto handleForAll =
		[](ast::ForAllPointer<ast::Precondition> &forAll)
		{
			negationNormalize(forAll->argument);
		};

	const auto handleImply =
		[](ast::ImplyPointer<ast::Precondition> &)
		{
			throw std::logic_error("precondition not ready for negation normalization (imply), please report to the bug tracker");
		};

	const auto handleNot =
		[&](ast::NotPointer<ast::Precondition> &not_)
		{
			negationNormalizeNegated(not_->argument, precondition);
		};

	const auto handleOr =
		[](ast::OrPointer<ast::Precondition> &or_)
		{
			for (auto &argument : or_->arguments)
				negationNormalize(argument);
		};

	precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void eliminateForAll(ast::Precondition &precondition)
{
	const auto handleAtomicFormula =
		[](ast::AtomicFormula &)
		{
		};

	const auto handleAnd =
		[](ast::AndPointer<ast::Precondition> &and_)
		{
			for (auto &argument : and_->arguments)
				eliminateForAll(argument);
		};

	const auto handleExists =
		[](ast::ExistsPointer<ast::Precondition> &exists)
		{
			eliminateForAll(exists->argument);
		};

	const auto handleForAll =
		[&](ast::ForAllPointer<ast::Precondition> &forAll)
		{
			auto negatedArgument = std::make_unique<ast::Not<ast::Precondition>>(std::move(forAll->argument));
			auto exists = std::make_unique<ast::Exists<ast::Precondition>>(std::move(forAll->parameters), std::move(negatedArgument));

			precondition = std::make_unique<ast::Not<ast::Precondition>>(std::move(exists));
		};

	const auto handleImply =
		[&](ast::ImplyPointer<ast::Precondition> &imply)
		{
			eliminateForAll(imply->argumentLeft);
			eliminateForAll(imply->argumentRight);
		};

	const auto handleNot =
		[](ast::NotPointer<ast::Precondition> &not_)
		{
			eliminateForAll(not_->argument);
		};

	const auto handleOr =
		[](ast::OrPointer<ast::Precondition> &or_)
		{
			for (auto &argument : or_->arguments)
				eliminateForAll(argument);
		};

	precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void eliminateDoubleNegations(ast::Precondition &precondition)
{
	const auto handleAtomicFormula =
		[](ast::AtomicFormula &)
		{
		};

	const auto handleAnd =
		[](ast::AndPointer<ast::Precondition> &and_)
		{
			for (auto &argument : and_->arguments)
				eliminateDoubleNegations(argument);
		};

	const auto handleExists =
		[](ast::ExistsPointer<ast::Precondition> &exists)
		{
			eliminateDoubleNegations(exists->argument);
		};

	const auto handleForAll =
		[&](ast::ForAllPointer<ast::Precondition> &forAll)
		{
			eliminateDoubleNegations(forAll->argument);
		};

	const auto handleImply =
		[&](ast::ImplyPointer<ast::Precondition> &imply)
		{
			eliminateDoubleNegations(imply->argumentLeft);
			eliminateDoubleNegations(imply->argumentRight);
		};

	const auto handleNot =
		[&](ast::NotPointer<ast::Precondition> &not_)
		{
			eliminateDoubleNegations(not_->argument);

			if (not_->argument.is<ast::NotPointer<ast::Precondition>>())
			{
				// As the parent contains the argument, the argument needs to be saved before overwriting the parent
				// TODO: check whether this workaround can be avoided
				auto argument = std::move(not_->argument.get<ast::NotPointer<ast::Precondition>>());
				precondition = std::move(argument);
			}
		};

	const auto handleOr =
		[](ast::OrPointer<ast::Precondition> &or_)
		{
			for (auto &argument : or_->arguments)
				eliminateDoubleNegations(argument);
		};

	precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void reduce(ast::Precondition &precondition)
{
	// Replace “imply” statements with disjunctions
	eliminateImply(precondition);

	// Negation-normalize the precondition
	negationNormalize(precondition);

	// Eliminate “forall” statements
	eliminateForAll(precondition);

	// Eliminate double negations introduced by eliminating “forall” statements
	eliminateDoubleNegations(precondition);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

}
}
<commit_msg>Added missing recursion step in PDDL reduction.<commit_after>#include <pddlparse/detail/normalization/Reduction.h>

#include <pddlparse/AST.h>
#include <pddlparse/Exception.h>
#include <pddlparse/NormalizedAST.h>
#include <pddlparse/detail/normalization/AtomicFormula.h>
#include <pddlparse/detail/normalization/CollectFreeVariables.h>

namespace pddl
{
namespace detail
{

////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Reduction
//
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
// Forward declarations
////////////////////////////////////////////////////////////////////////////////////////////////////

void eliminateImply(ast::Precondition &precondition);
void negationNormalize(ast::Precondition &precondition);
void eliminateForAll(ast::Precondition &precondition);
void eliminateDoubleNegations(ast::Precondition &precondition);

////////////////////////////////////////////////////////////////////////////////////////////////////

void eliminateImply(ast::Precondition &precondition)
{
	const auto handleAtomicFormula =
		[](ast::AtomicFormula &)
		{
		};

	const auto handleAnd =
		[](ast::AndPointer<ast::Precondition> &and_)
		{
			for (auto &argument : and_->arguments)
				eliminateImply(argument);
		};

	const auto handleExists =
		[](ast::ExistsPointer<ast::Precondition> &exists)
		{
			eliminateImply(exists->argument);
		};

	const auto handleForAll =
		[](ast::ForAllPointer<ast::Precondition> &forAll)
		{
			eliminateImply(forAll->argument);
		};

	const auto handleImply =
		[&](ast::ImplyPointer<ast::Precondition> &imply)
		{
			eliminateImply(imply->argumentLeft);
			eliminateImply(imply->argumentRight);

			ast::Or<ast::Precondition>::Arguments arguments;
			arguments.reserve(2);
			arguments.emplace_back(std::make_unique<ast::Not<ast::Precondition>>(std::move(imply->argumentLeft)));
			arguments.emplace_back(std::move(imply->argumentRight));

			precondition = std::make_unique<ast::Or<ast::Precondition>>(std::move(arguments));
		};

	const auto handleNot =
		[](ast::NotPointer<ast::Precondition> &not_)
		{
			eliminateImply(not_->argument);
		};

	const auto handleOr =
		[](ast::OrPointer<ast::Precondition> &or_)
		{
			for (auto &argument : or_->arguments)
				eliminateImply(argument);
		};

	precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

// Negation-normalize an expression whose parent is a “not” expression
void negationNormalizeNegated(ast::Precondition &precondition, ast::Precondition &parent)
{
	const auto handleAtomicFormula =
		[](ast::AtomicFormula &)
		{
		};

	const auto handleAnd =
		[&](ast::AndPointer<ast::Precondition> &and_)
		{
			ast::Or<ast::Precondition>::Arguments arguments;
			arguments.reserve(and_->arguments.size());

			// Apply De Morgan
			for (auto &argument : and_->arguments)
				arguments.emplace_back(std::make_unique<ast::Not<ast::Precondition>>(std::move(argument)));

			// Finally, negation-normalize each argument
			for (auto &argument : arguments)
				negationNormalize(argument);

			// Replace the parent “not” containing this “and” with an “or” over the negated arguments
			parent = std::make_unique<ast::Or<ast::Precondition>>(std::move(arguments));
		};

	const auto handleExists =
		[](ast::ExistsPointer<ast::Precondition> &exists)
		{
			negationNormalize(exists->argument);
		};

	const auto handleForAll =
		[](ast::ForAllPointer<ast::Precondition> &forAll)
		{
			negationNormalize(forAll->argument);
		};

	const auto handleImply =
		[](ast::ImplyPointer<ast::Precondition> &)
		{
			throw std::logic_error("precondition not ready for negation normalization (imply), please report to the bug tracker");
		};

	const auto handleNot =
		[&](ast::NotPointer<ast::Precondition> &not_)
		{
			negationNormalize(not_->argument);

			// As the parent contains the argument, the argument needs to be saved before overwriting the parent
			// TODO: check whether this workaround can be avoided
			auto argument = std::move(not_->argument);
			parent = std::move(argument);
		};

	const auto handleOr =
		[&](ast::OrPointer<ast::Precondition> &or_)
		{
			ast::And<ast::Precondition>::Arguments arguments;
			arguments.reserve(or_->arguments.size());

			// Apply De Morgan
			for (auto &argument : or_->arguments)
				arguments.emplace_back(std::make_unique<ast::Not<ast::Precondition>>(std::move(argument)));

			// Finally, negation-normalize each argument
			for (auto &argument : arguments)
				negationNormalize(argument);

			// Replace the parent “not” containing this “or” with an “and” over the negated arguments
			parent = std::make_unique<ast::And<ast::Precondition>>(std::move(arguments));
		};

	precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void negationNormalize(ast::Precondition &precondition)
{
	const auto handleAtomicFormula =
		[](ast::AtomicFormula &)
		{
		};

	const auto handleAnd =
		[](ast::AndPointer<ast::Precondition> &and_)
		{
			for (auto &argument : and_->arguments)
				negationNormalize(argument);
		};

	const auto handleExists =
		[](ast::ExistsPointer<ast::Precondition> &exists)
		{
			negationNormalize(exists->argument);
		};

	const auto handleForAll =
		[](ast::ForAllPointer<ast::Precondition> &forAll)
		{
			negationNormalize(forAll->argument);
		};

	const auto handleImply =
		[](ast::ImplyPointer<ast::Precondition> &)
		{
			throw std::logic_error("precondition not ready for negation normalization (imply), please report to the bug tracker");
		};

	const auto handleNot =
		[&](ast::NotPointer<ast::Precondition> &not_)
		{
			negationNormalizeNegated(not_->argument, precondition);
		};

	const auto handleOr =
		[](ast::OrPointer<ast::Precondition> &or_)
		{
			for (auto &argument : or_->arguments)
				negationNormalize(argument);
		};

	precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void eliminateForAll(ast::Precondition &precondition)
{
	const auto handleAtomicFormula =
		[](ast::AtomicFormula &)
		{
		};

	const auto handleAnd =
		[](ast::AndPointer<ast::Precondition> &and_)
		{
			for (auto &argument : and_->arguments)
				eliminateForAll(argument);
		};

	const auto handleExists =
		[](ast::ExistsPointer<ast::Precondition> &exists)
		{
			eliminateForAll(exists->argument);
		};

	const auto handleForAll =
		[&](ast::ForAllPointer<ast::Precondition> &forAll)
		{
			eliminateForAll(forAll->argument);

			auto negatedArgument = std::make_unique<ast::Not<ast::Precondition>>(std::move(forAll->argument));
			auto exists = std::make_unique<ast::Exists<ast::Precondition>>(std::move(forAll->parameters), std::move(negatedArgument));
			precondition = std::make_unique<ast::Not<ast::Precondition>>(std::move(exists));
		};

	const auto handleImply =
		[&](ast::ImplyPointer<ast::Precondition> &imply)
		{
			eliminateForAll(imply->argumentLeft);
			eliminateForAll(imply->argumentRight);
		};

	const auto handleNot =
		[](ast::NotPointer<ast::Precondition> &not_)
		{
			eliminateForAll(not_->argument);
		};

	const auto handleOr =
		[](ast::OrPointer<ast::Precondition> &or_)
		{
			for (auto &argument : or_->arguments)
				eliminateForAll(argument);
		};

	precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void eliminateDoubleNegations(ast::Precondition &precondition)
{
	const auto handleAtomicFormula =
		[](ast::AtomicFormula &)
		{
		};

	const auto handleAnd =
		[](ast::AndPointer<ast::Precondition> &and_)
		{
			for (auto &argument : and_->arguments)
				eliminateDoubleNegations(argument);
		};

	const auto handleExists =
		[](ast::ExistsPointer<ast::Precondition> &exists)
		{
			eliminateDoubleNegations(exists->argument);
		};

	const auto handleForAll =
		[&](ast::ForAllPointer<ast::Precondition> &forAll)
		{
			eliminateDoubleNegations(forAll->argument);
		};

	const auto handleImply =
		[&](ast::ImplyPointer<ast::Precondition> &imply)
		{
			eliminateDoubleNegations(imply->argumentLeft);
			eliminateDoubleNegations(imply->argumentRight);
		};

	const auto handleNot =
		[&](ast::NotPointer<ast::Precondition> &not_)
		{
			eliminateDoubleNegations(not_->argument);

			if (not_->argument.is<ast::NotPointer<ast::Precondition>>())
			{
				// As the parent contains the argument, the argument needs to be saved before overwriting the parent
				// TODO: check whether this workaround can be avoided
				auto argument = std::move(not_->argument.get<ast::NotPointer<ast::Precondition>>());
				precondition = std::move(argument);
			}
		};

	const auto handleOr =
		[](ast::OrPointer<ast::Precondition> &or_)
		{
			for (auto &argument : or_->arguments)
				eliminateDoubleNegations(argument);
		};

	precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void reduce(ast::Precondition &precondition)
{
	// Replace “imply” statements with disjunctions
	eliminateImply(precondition);

	// Negation-normalize the precondition
	negationNormalize(precondition);

	// Eliminate “forall” statements
	eliminateForAll(precondition);

	// Eliminate double negations introduced by eliminating “forall” statements
	eliminateDoubleNegations(precondition);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

}
}
<|endoftext|>


<commit_before><commit_msg>svl: convert DBG_ASSERTs in SvtCJKOptions<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: datwin.hxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 14:30:22 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _SFXDATWIN_HXX
#define _SFXDATWIN_HXX

#ifndef _BRWBOX_HXX
#include <brwbox.hxx>
#endif

#ifndef _BRWHEAD_HXX
#include <brwhead.hxx>
#endif

#ifndef _TIMER_HXX //autogen
#include <vcl/timer.hxx>
#endif
#ifndef _IMAGE_HXX //autogen
#include <vcl/image.hxx>
#endif
#ifndef _LIST_HXX //autogen
#include <tools/list.hxx>
#endif
#ifndef _TRANSFER_HXX
#include "transfer.hxx"
#endif

//===================================================================

#define MIN_COLUMNWIDTH  2
#define DRAG_CRITICAL    4

DECLARE_LIST( RectangleList, Rectangle* );

//===================================================================

class ButtonFrame
{
    Rectangle   aRect;
    Rectangle   aInnerRect;
    String      aText;
    BOOL        bPressed;
    BOOL        bCurs;
    BOOL        bAbbr;
    BOOL        m_bDrawDisabled;

public:
               ButtonFrame( const Point& rPt, const Size& rSz,
                            const String &rText,
                            BOOL bPress = FALSE,
                            BOOL bCursor = FALSE,
                            BOOL bAbbreviate = TRUE,
                            BOOL _bDrawDisabled = FALSE)
                :aRect( rPt, rSz )
                ,aInnerRect( Point( aRect.Left()+1, aRect.Top()+1 ),
                            Size( aRect.GetWidth()-2, aRect.GetHeight()-2 ) )
                ,aText(rText)
                ,bPressed(bPress)
                ,bCurs(bCursor)
                ,bAbbr(bAbbreviate)
                ,m_bDrawDisabled(_bDrawDisabled)
            {
            }

    void    Draw( OutputDevice& rDev );
};

//===================================================================

class BrowserColumn
{
    USHORT              _nId;
    ULONG               _nOriginalWidth;
    ULONG               _nWidth;
    Image               _aImage;
    String              _aTitle;
    BOOL                _bFrozen;
    HeaderBarItemBits   _nFlags;

public:
                        BrowserColumn( USHORT nItemId, const Image &rImage,
                                        const String& rTitle, ULONG nWidthPixel, const Fraction& rCurrentZoom,
                                        HeaderBarItemBits nFlags );

    USHORT              GetId() const { return _nId; }

    ULONG               Width() { return _nWidth; }
    Image&              GetImage() { return _aImage; }
    String&             Title() { return _aTitle; }
    HeaderBarItemBits&  Flags() { return _nFlags; }

    BOOL                IsFrozen() const { return _bFrozen; }
    void                Freeze( BOOL bFreeze = TRUE ) { _bFrozen = bFreeze; }

    virtual void        Draw( BrowseBox& rBox, OutputDevice& rDev,
                              const Point& rPos, BOOL bCurs  );

    void                SetWidth(ULONG nNewWidthPixel, const Fraction& rCurrentZoom);
    void                ZoomChanged(const Fraction& rNewZoom);
};

//===================================================================

class BrowserDataWin
            :public Control
            ,public DragSourceHelper
            ,public DropTargetHelper
{
friend class BrowseBox;
    BrowserHeader*  pHeaderBar;     // only for BROWSER_HEADERBAR_NEW
    Window*         pEventWin;      // Window of forwarded events
    ScrollBarBox*   pCornerWin;     // Window in the corner btw the ScrollBars
    BOOL*           pDtorNotify;
    AutoTimer       aMouseTimer;    // recalls MouseMove on dragging out
    MouseEvent      aRepeatEvt;     // a MouseEvent to repeat
    Point           aLastMousePos;  // verhindert pseudo-MouseMoves

    String          aRealRowCount;  // zur Anzeige im VScrollBar

    RectangleList   aInvalidRegion; // invalidated Rectangles during !UpdateMode
    FASTBOOL        bInPaint;       // TRUE while in Paint
    FASTBOOL        bInCommand;     // TRUE while in Command
    FASTBOOL        bNoScrollBack;  // nur vorwaerts scrollen
    FASTBOOL        bNoHScroll;     // kein horizontaler Scrollbar
    FASTBOOL        bNoVScroll;     // no vertical scrollbar
    FASTBOOL        bAutoHScroll;   // autohide horizontaler Scrollbar
    FASTBOOL        bAutoVScroll;   // autohide horizontaler Scrollbar
    FASTBOOL        bUpdateMode;    // nicht SV-UpdateMode wegen Invalidate()
    FASTBOOL        bAutoSizeLastCol;// last column always fills up window
    FASTBOOL        bHighlightAuto; // new auto-highlight by SetFont() etc.
    FASTBOOL        bResizeOnPaint; // outstanding resize-event
    FASTBOOL        bUpdateOnUnlock;    // Update() while locked
    FASTBOOL        bInUpdateScrollbars;    // Rekursionsschutz
    FASTBOOL        bHadRecursion;          // Rekursion war aufgetreten
    FASTBOOL        bOwnDataChangedHdl;     // dont change colors in DataChanged
    FASTBOOL        bCallingDropCallback;   // we're in a callback to AcceptDrop or ExecuteDrop curently
    USHORT          nUpdateLock;    // lock count, dont call Control::Update()!
    short           nCursorHidden;  // new conuter for DoHide/ShowCursor

    long            m_nDragRowDividerLimit;
    long            m_nDragRowDividerOffset;

public:
                    BrowserDataWin( BrowseBox* pParent );
                    ~BrowserDataWin();

    virtual void    DataChanged( const DataChangedEvent& rDCEvt );
    virtual void    Paint( const Rectangle& rRect );
    virtual void    RequestHelp( const HelpEvent& rHEvt );
    virtual void    Command( const CommandEvent& rEvt );
    virtual void    MouseButtonDown( const MouseEvent& rEvt );
    virtual void    MouseMove( const MouseEvent& rEvt );
                    DECL_LINK( RepeatedMouseMove, void * );

    virtual void    MouseButtonUp( const MouseEvent& rEvt );
    virtual void    KeyInput( const KeyEvent& rEvt );
    virtual void    Tracking( const TrackingEvent& rTEvt );

    // DropTargetHelper overridables
    virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
    virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );

    // DragSourceHelper overridables
    virtual void    StartDrag( sal_Int8 _nAction, const Point& _rPosPixel );

    BrowseEvent     CreateBrowseEvent( const Point& rPosPixel );
    void            Repaint();
    BrowseBox*      GetParent() const
                         { return (BrowseBox*) Window::GetParent(); }
    const String&   GetRealRowCount() const { return aRealRowCount; }

    void            SetUpdateMode( BOOL bMode );
    FASTBOOL        GetUpdateMode() const { return bUpdateMode; }
    void            EnterUpdateLock() { ++nUpdateLock; }
    void            LeaveUpdateLock();
    void            Update();
    void            DoOutstandingInvalidations();
    void            Invalidate();
    void            Invalidate( const Rectangle& rRect );

protected:
    void            StartRowDividerDrag( const Point& _rStartPos );
    BOOL            ImplRowDividerHitTest( const BrowserMouseEvent& _rEvent );
};

//-------------------------------------------------------------------

inline void BrowserDataWin::Repaint()
{
    if ( GetUpdateMode() )
        Update();
    Paint( Rectangle( Point(), GetOutputSizePixel() ) );
}

//===================================================================

class BrowserScrollBar: public ScrollBar
{
    ULONG           _nTip;
    ULONG           _nLastPos;
    BrowserDataWin* _pDataWin;

public:
                    BrowserScrollBar( Window* pParent, WinBits nStyle,
                                      BrowserDataWin *pDataWin )
                    :   ScrollBar( pParent, nStyle ),
                        _nTip( 0 ),
                        _nLastPos( ULONG_MAX ),
                        _pDataWin( pDataWin )
                    {}
                    //ScrollBar( Window* pParent, const ResId& rResId );

    virtual void    Tracking( const TrackingEvent& rTEvt );
    virtual void    EndScroll();
};

//===================================================================

void InitSettings_Impl( Window *pWin,
         BOOL bFont = TRUE, BOOL bForeground = TRUE, BOOL bBackground = TRUE );

//===================================================================

#ifdef DBG_MI

void DoLog_Impl( const BrowseBox *pThis, const char *pWhat, const char *pWho );
#define LOG(pThis,what,who) DoLog_Impl(pThis,what,who)

#else

#define LOG(pThis,what,who)

#endif

#endif

<commit_msg>INTEGRATION: CWS warnings01 (1.10.62); FILE MERGED 2005/11/14 14:43:40 pl 1.10.62.2: #i55991# removed warnings 2005/10/25 17:37:23 pl 1.10.62.1: #i55991# removed warnings for linux platform<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: datwin.hxx,v $
 *
 *  $Revision: 1.11 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-19 20:40:19 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _SFXDATWIN_HXX
#define _SFXDATWIN_HXX

#ifndef _BRWBOX_HXX
#include <brwbox.hxx>
#endif

#ifndef _BRWHEAD_HXX
#include <brwhead.hxx>
#endif

#ifndef _TIMER_HXX //autogen
#include <vcl/timer.hxx>
#endif
#ifndef _IMAGE_HXX //autogen
#include <vcl/image.hxx>
#endif
#ifndef _LIST_HXX //autogen
#include <tools/list.hxx>
#endif
#ifndef _TRANSFER_HXX
#include "transfer.hxx"
#endif

//===================================================================

#define MIN_COLUMNWIDTH  2
#define DRAG_CRITICAL    4

DECLARE_LIST( RectangleList, Rectangle* )

//===================================================================

class ButtonFrame
{
    Rectangle   aRect;
    Rectangle   aInnerRect;
    String      aText;
    BOOL        bPressed;
    BOOL        bCurs;
    BOOL        bAbbr;
    BOOL        m_bDrawDisabled;

public:
               ButtonFrame( const Point& rPt, const Size& rSz,
                            const String &rText,
                            BOOL bPress = FALSE,
                            BOOL bCursor = FALSE,
                            BOOL bAbbreviate = TRUE,
                            BOOL _bDrawDisabled = FALSE)
                :aRect( rPt, rSz )
                ,aInnerRect( Point( aRect.Left()+1, aRect.Top()+1 ),
                            Size( aRect.GetWidth()-2, aRect.GetHeight()-2 ) )
                ,aText(rText)
                ,bPressed(bPress)
                ,bCurs(bCursor)
                ,bAbbr(bAbbreviate)
                ,m_bDrawDisabled(_bDrawDisabled)
            {
            }

    void    Draw( OutputDevice& rDev );
};

//===================================================================

class BrowserColumn
{
    USHORT              _nId;
    ULONG               _nOriginalWidth;
    ULONG               _nWidth;
    Image               _aImage;
    String              _aTitle;
    BOOL                _bFrozen;
    HeaderBarItemBits   _nFlags;

public:
                        BrowserColumn( USHORT nItemId, const Image &rImage,
                                        const String& rTitle, ULONG nWidthPixel, const Fraction& rCurrentZoom,
                                        HeaderBarItemBits nFlags );
    virtual            ~BrowserColumn();

    USHORT              GetId() const { return _nId; }

    ULONG               Width() { return _nWidth; }
    Image&              GetImage() { return _aImage; }
    String&             Title() { return _aTitle; }
    HeaderBarItemBits&  Flags() { return _nFlags; }

    BOOL                IsFrozen() const { return _bFrozen; }
    void                Freeze( BOOL bFreeze = TRUE ) { _bFrozen = bFreeze; }

    virtual void        Draw( BrowseBox& rBox, OutputDevice& rDev,
                              const Point& rPos, BOOL bCurs  );

    void                SetWidth(ULONG nNewWidthPixel, const Fraction& rCurrentZoom);
    void                ZoomChanged(const Fraction& rNewZoom);
};

//===================================================================

class BrowserDataWin
            :public Control
            ,public DragSourceHelper
            ,public DropTargetHelper
{
public:
    BrowserHeader*  pHeaderBar;     // only for BROWSER_HEADERBAR_NEW
    Window*         pEventWin;      // Window of forwarded events
    ScrollBarBox*   pCornerWin;     // Window in the corner btw the ScrollBars
    BOOL*           pDtorNotify;
    AutoTimer       aMouseTimer;    // recalls MouseMove on dragging out
    MouseEvent      aRepeatEvt;     // a MouseEvent to repeat
    Point           aLastMousePos;  // verhindert pseudo-MouseMoves

    String          aRealRowCount;  // zur Anzeige im VScrollBar

    RectangleList   aInvalidRegion; // invalidated Rectangles during !UpdateMode
    FASTBOOL        bInPaint;       // TRUE while in Paint
    FASTBOOL        bInCommand;     // TRUE while in Command
    FASTBOOL        bNoScrollBack;  // nur vorwaerts scrollen
    FASTBOOL        bNoHScroll;     // kein horizontaler Scrollbar
    FASTBOOL        bNoVScroll;     // no vertical scrollbar
    FASTBOOL        bAutoHScroll;   // autohide horizontaler Scrollbar
    FASTBOOL        bAutoVScroll;   // autohide horizontaler Scrollbar
    FASTBOOL        bUpdateMode;    // nicht SV-UpdateMode wegen Invalidate()
    FASTBOOL        bAutoSizeLastCol;// last column always fills up window
    FASTBOOL        bHighlightAuto; // new auto-highlight by SetFont() etc.
    FASTBOOL        bResizeOnPaint; // outstanding resize-event
    FASTBOOL        bUpdateOnUnlock;    // Update() while locked
    FASTBOOL        bInUpdateScrollbars;    // Rekursionsschutz
    FASTBOOL        bHadRecursion;          // Rekursion war aufgetreten
    FASTBOOL        bOwnDataChangedHdl;     // dont change colors in DataChanged
    FASTBOOL        bCallingDropCallback;   // we're in a callback to AcceptDrop or ExecuteDrop curently
    USHORT          nUpdateLock;    // lock count, dont call Control::Update()!
    short           nCursorHidden;  // new conuter for DoHide/ShowCursor

    long            m_nDragRowDividerLimit;
    long            m_nDragRowDividerOffset;

public:
                    BrowserDataWin( BrowseBox* pParent );
                    ~BrowserDataWin();

    virtual void    DataChanged( const DataChangedEvent& rDCEvt );
    virtual void    Paint( const Rectangle& rRect );
    virtual void    RequestHelp( const HelpEvent& rHEvt );
    virtual void    Command( const CommandEvent& rEvt );
    virtual void    MouseButtonDown( const MouseEvent& rEvt );
    virtual void    MouseMove( const MouseEvent& rEvt );
                    DECL_LINK( RepeatedMouseMove, void * );

    virtual void    MouseButtonUp( const MouseEvent& rEvt );
    virtual void    KeyInput( const KeyEvent& rEvt );
    virtual void    Tracking( const TrackingEvent& rTEvt );

    // DropTargetHelper overridables
    virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
    virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );

    // DragSourceHelper overridables
    virtual void    StartDrag( sal_Int8 _nAction, const Point& _rPosPixel );

    BrowseEvent     CreateBrowseEvent( const Point& rPosPixel );
    void            Repaint();
    BrowseBox*      GetParent() const
                         { return (BrowseBox*) Window::GetParent(); }
    const String&   GetRealRowCount() const { return aRealRowCount; }

    void            SetUpdateMode( BOOL bMode );
    FASTBOOL        GetUpdateMode() const { return bUpdateMode; }
    void            EnterUpdateLock() { ++nUpdateLock; }
    void            LeaveUpdateLock();
    void            Update();
    void            DoOutstandingInvalidations();
    void            Invalidate( USHORT nFlags = 0 );
    void            Invalidate( const Rectangle& rRect, USHORT nFlags = 0 );
    void            Invalidate( const Region& rRegion, USHORT nFlags = 0 )
                    { Control::Invalidate( rRegion, nFlags ); }

protected:
    void            StartRowDividerDrag( const Point& _rStartPos );
    BOOL            ImplRowDividerHitTest( const BrowserMouseEvent& _rEvent );
};

//-------------------------------------------------------------------

inline void BrowserDataWin::Repaint()
{
    if ( GetUpdateMode() )
        Update();
    Paint( Rectangle( Point(), GetOutputSizePixel() ) );
}

//===================================================================

class BrowserScrollBar: public ScrollBar
{
    ULONG           _nTip;
    ULONG           _nLastPos;
    BrowserDataWin* _pDataWin;

public:
                    BrowserScrollBar( Window* pParent, WinBits nStyle,
                                      BrowserDataWin *pDataWin )
                    :   ScrollBar( pParent, nStyle ),
                        _nTip( 0 ),
                        _nLastPos( ULONG_MAX ),
                        _pDataWin( pDataWin )
                    {}
                    //ScrollBar( Window* pParent, const ResId& rResId );

    virtual void    Tracking( const TrackingEvent& rTEvt );
    virtual void    EndScroll();
};

//===================================================================

void InitSettings_Impl( Window *pWin,
         BOOL bFont = TRUE, BOOL bForeground = TRUE, BOOL bBackground = TRUE );

//===================================================================

#ifdef DBG_MI

void DoLog_Impl( const BrowseBox *pThis, const char *pWhat, const char *pWho );
#define LOG(pThis,what,who) DoLog_Impl(pThis,what,who)

#else

#define LOG(pThis,what,who)

#endif

#endif

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: macitem.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 15:59:16 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _STREAM_HXX //autogen
#include <tools/stream.hxx>
#endif

#ifndef GCC
#pragma hdrstop
#endif
#define ITEMID_MACRO 0

#include "macitem.hxx"

// STATIC DATA -----------------------------------------------------------

DBG_NAME(SvxMacroItem);

// -----------------------------------------------------------------------

TYPEINIT1_AUTOFACTORY(SvxMacroItem, SfxPoolItem);

// -----------------------------------------------------------------------

SjJSbxObjectBase::~SjJSbxObjectBase()
{
}

SjJSbxObjectBase* SjJSbxObjectBase::Clone( void )
{
    return NULL;
}

SvxMacro::SvxMacro( const String &rMacName, const String &rLanguage)
    : aMacName( rMacName ), aLibName( rLanguage),
      pFunctionObject(NULL), eType( EXTENDED_STYPE)
{
    if (rLanguage.EqualsAscii(SVX_MACRO_LANGUAGE_STARBASIC))
        eType=STARBASIC;
    else if (rLanguage.EqualsAscii(SVX_MACRO_LANGUAGE_JAVASCRIPT))
        eType=JAVASCRIPT;
}

SvxMacro::~SvxMacro()
{
    delete pFunctionObject;
}

String SvxMacro::GetLanguage()const
{
    if(eType==STARBASIC)
    {
        return UniString::CreateFromAscii(
                   RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_STARBASIC));
    }
    else if(eType==JAVASCRIPT)
    {
        return UniString::CreateFromAscii(
                   RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_JAVASCRIPT));
    }
    else if(eType==EXTENDED_STYPE)
    {
        return UniString::CreateFromAscii(
                   RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_SF));

    }
    return aLibName;
}

SvxMacro& SvxMacro::operator=( const SvxMacro& rBase )
{
    if( this != &rBase )
    {
        aMacName = rBase.aMacName;
        aLibName = rBase.aLibName;
        delete pFunctionObject;
        pFunctionObject = rBase.pFunctionObject ? rBase.pFunctionObject->Clone() : NULL;
        eType = rBase.eType;
    }
    return *this;
}

SvxMacroTableDtor& SvxMacroTableDtor::operator=( const SvxMacroTableDtor& rTbl )
{
    DelDtor();
    SvxMacro* pTmp = ((SvxMacroTableDtor&)rTbl).First();
    while( pTmp )
    {
        SvxMacro *pNew = new SvxMacro( *pTmp );
        Insert( rTbl.GetCurKey(), pNew );
        pTmp = ((SvxMacroTableDtor&)rTbl).Next();
    }
    return *this;
}

SvStream& SvxMacroTableDtor::Read( SvStream& rStrm, USHORT nVersion )
{
    if( SVX_MACROTBL_VERSION40 <= nVersion )
        rStrm >> nVersion;
    short nMacro;
    rStrm >> nMacro;

    for( short i = 0; i < nMacro; ++i )
    {
        USHORT nCurKey, eType = STARBASIC;
        String aLibName, aMacName;
        rStrm >> nCurKey;
        SfxPoolItem::readByteString(rStrm, aLibName);
        SfxPoolItem::readByteString(rStrm, aMacName);

        if( SVX_MACROTBL_VERSION40 <= nVersion )
            rStrm >> eType;

        SvxMacro* pNew = new SvxMacro( aMacName, aLibName, (ScriptType)eType );

        SvxMacro *pOld = Get( nCurKey );
        if( pOld )
        {
            delete pOld;
            Replace( nCurKey, pNew );
        }
        else
            Insert( nCurKey, pNew );
    }
    return rStrm;
}

SvStream& SvxMacroTableDtor::Write( SvStream& rStream ) const
{
    USHORT nVersion = SOFFICE_FILEFORMAT_31 == rStream.GetVersion()
                                    ? SVX_MACROTBL_VERSION31
                                    : SVX_MACROTBL_AKTVERSION;

    if( SVX_MACROTBL_VERSION40 <= nVersion )
        rStream << nVersion;

    rStream << (USHORT)Count();

    SvxMacro* pMac = ((SvxMacroTableDtor*)this)->First();
    while( pMac && rStream.GetError() == SVSTREAM_OK )
    {
        rStream << (short)GetCurKey();
        SfxPoolItem::writeByteString(rStream, pMac->GetLibName());
        SfxPoolItem::writeByteString(rStream, pMac->GetMacName());

        if( SVX_MACROTBL_VERSION40 <= nVersion )
            rStream << (USHORT)pMac->GetScriptType();
        pMac = ((SvxMacroTableDtor*)this)->Next();
    }
    return rStream;
}

// -----------------------------------------------------------------------

void SvxMacroTableDtor::DelDtor()
{
    SvxMacro* pTmp = First();
    while( pTmp )
    {
        delete pTmp;
        pTmp = Next();
    }
    Clear();
}

// -----------------------------------------------------------------------

int SvxMacroItem::operator==( const SfxPoolItem& rAttr ) const
{
    DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );

    const SvxMacroTableDtor& rOwn = aMacroTable;
    const SvxMacroTableDtor& rOther = ( (SvxMacroItem&) rAttr ).aMacroTable;

    // Anzahl unterschiedlich => auf jeden Fall ungleich
    if ( rOwn.Count() != rOther.Count() )
        return FALSE;

    // einzeln verleichen; wegen Performance ist die Reihenfolge wichtig
    for ( USHORT nNo = 0; nNo < rOwn.Count(); ++nNo )
    {
        const SvxMacro *pOwnMac = rOwn.GetObject(nNo);
        const SvxMacro *pOtherMac = rOther.GetObject(nNo);
        if (    rOwn.GetKey(pOwnMac) != rOther.GetKey(pOtherMac)  ||
                pOwnMac->GetLibName() != pOtherMac->GetLibName() ||
                pOwnMac->GetMacName() != pOtherMac->GetMacName() )
            return FALSE;
    }

    return TRUE;
}

// -----------------------------------------------------------------------

SfxPoolItem* SvxMacroItem::Clone( SfxItemPool* ) const
{
    return new SvxMacroItem( *this );
}

//------------------------------------------------------------------------

SfxItemPresentation SvxMacroItem::GetPresentation
(
    SfxItemPresentation ePres,
    SfxMapUnit          eCoreUnit,
    SfxMapUnit          ePresUnit,
    XubString&          rText,
    const IntlWrapper *
)   const
{
/*!!!
    SvxMacroTableDtor& rTbl = (SvxMacroTableDtor&)GetMacroTable();
    SvxMacro* pMac = rTbl.First();

    while ( pMac )
    {
        rText += pMac->GetLibName();
        rText += cpDelim;
        rText += pMac->GetMacName();
        pMac = rTbl.Next();
        if ( pMac )
            rText += cpDelim;
    }
*/
    rText.Erase();
    return SFX_ITEM_PRESENTATION_NONE;
}

// -----------------------------------------------------------------------

SvStream& SvxMacroItem::Store( SvStream& rStrm , USHORT nItemVersion ) const
{
    return aMacroTable.Write( rStrm );
}

// -----------------------------------------------------------------------

SfxPoolItem* SvxMacroItem::Create( SvStream& rStrm, USHORT nVersion ) const
{
    SvxMacroItem* pAttr = new SvxMacroItem( Which() );
    pAttr->aMacroTable.Read( rStrm, nVersion );
    return pAttr;
}

// -----------------------------------------------------------------------

void SvxMacroItem::SetMacro( USHORT nEvent, const SvxMacro& rMacro )
{
    SvxMacro *pMacro;
    if ( 0 != (pMacro=aMacroTable.Get(nEvent)) )
    {
        delete pMacro;
        aMacroTable.Replace(nEvent, new SvxMacro( rMacro ) );
    }
    else
        aMacroTable.Insert(nEvent, new SvxMacro( rMacro ) );
}

// -----------------------------------------------------------------------

USHORT SvxMacroItem::GetVersion( USHORT nFileFormatVersion ) const
{
    return SOFFICE_FILEFORMAT_31 == nFileFormatVersion
                ? 0 : aMacroTable.GetVersion();
}

<commit_msg>INTEGRATION: CWS warnings01 (1.5.60); FILE MERGED 2005/11/15 17:54:41 pl 1.5.60.1: #i55991# removed warnings<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: macitem.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-19 21:12:30 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _STREAM_HXX //autogen
#include <tools/stream.hxx>
#endif

#ifndef GCC
#pragma hdrstop
#endif
#define ITEMID_MACRO 0

#include "macitem.hxx"

// STATIC DATA -----------------------------------------------------------

DBG_NAME(SvxMacroItem);

// -----------------------------------------------------------------------

TYPEINIT1_AUTOFACTORY(SvxMacroItem, SfxPoolItem);

// -----------------------------------------------------------------------

SjJSbxObjectBase::~SjJSbxObjectBase()
{
}

SjJSbxObjectBase* SjJSbxObjectBase::Clone( void )
{
    return NULL;
}

SvxMacro::SvxMacro( const String &rMacName, const String &rLanguage)
    : aMacName( rMacName ), aLibName( rLanguage),
      pFunctionObject(NULL), eType( EXTENDED_STYPE)
{
    if (rLanguage.EqualsAscii(SVX_MACRO_LANGUAGE_STARBASIC))
        eType=STARBASIC;
    else if (rLanguage.EqualsAscii(SVX_MACRO_LANGUAGE_JAVASCRIPT))
        eType=JAVASCRIPT;
}

SvxMacro::~SvxMacro()
{
    delete pFunctionObject;
}

String SvxMacro::GetLanguage()const
{
    if(eType==STARBASIC)
    {
        return UniString::CreateFromAscii(
                   RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_STARBASIC));
    }
    else if(eType==JAVASCRIPT)
    {
        return UniString::CreateFromAscii(
                   RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_JAVASCRIPT));
    }
    else if(eType==EXTENDED_STYPE)
    {
        return UniString::CreateFromAscii(
                   RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_SF));

    }
    return aLibName;
}

SvxMacro& SvxMacro::operator=( const SvxMacro& rBase )
{
    if( this != &rBase )
    {
        aMacName = rBase.aMacName;
        aLibName = rBase.aLibName;
        delete pFunctionObject;
        pFunctionObject = rBase.pFunctionObject ? rBase.pFunctionObject->Clone() : NULL;
        eType = rBase.eType;
    }
    return *this;
}

SvxMacroTableDtor& SvxMacroTableDtor::operator=( const SvxMacroTableDtor& rTbl )
{
    DelDtor();
    SvxMacro* pTmp = ((SvxMacroTableDtor&)rTbl).First();
    while( pTmp )
    {
        SvxMacro *pNew = new SvxMacro( *pTmp );
        Insert( rTbl.GetCurKey(), pNew );
        pTmp = ((SvxMacroTableDtor&)rTbl).Next();
    }
    return *this;
}

SvStream& SvxMacroTableDtor::Read( SvStream& rStrm, USHORT nVersion )
{
    if( SVX_MACROTBL_VERSION40 <= nVersion )
        rStrm >> nVersion;
    short nMacro;
    rStrm >> nMacro;

    for( short i = 0; i < nMacro; ++i )
    {
        USHORT nCurKey, eType = STARBASIC;
        String aLibName, aMacName;
        rStrm >> nCurKey;
        SfxPoolItem::readByteString(rStrm, aLibName);
        SfxPoolItem::readByteString(rStrm, aMacName);

        if( SVX_MACROTBL_VERSION40 <= nVersion )
            rStrm >> eType;

        SvxMacro* pNew = new SvxMacro( aMacName, aLibName, (ScriptType)eType );

        SvxMacro *pOld = Get( nCurKey );
        if( pOld )
        {
            delete pOld;
            Replace( nCurKey, pNew );
        }
        else
            Insert( nCurKey, pNew );
    }
    return rStrm;
}

SvStream& SvxMacroTableDtor::Write( SvStream& rStream ) const
{
    USHORT nVersion = SOFFICE_FILEFORMAT_31 == rStream.GetVersion()
                                    ? SVX_MACROTBL_VERSION31
                                    : SVX_MACROTBL_AKTVERSION;

    if( SVX_MACROTBL_VERSION40 <= nVersion )
        rStream << nVersion;

    rStream << (USHORT)Count();

    SvxMacro* pMac = ((SvxMacroTableDtor*)this)->First();
    while( pMac && rStream.GetError() == SVSTREAM_OK )
    {
        rStream << (short)GetCurKey();
        SfxPoolItem::writeByteString(rStream, pMac->GetLibName());
        SfxPoolItem::writeByteString(rStream, pMac->GetMacName());

        if( SVX_MACROTBL_VERSION40 <= nVersion )
            rStream << (USHORT)pMac->GetScriptType();
        pMac = ((SvxMacroTableDtor*)this)->Next();
    }
    return rStream;
}

// -----------------------------------------------------------------------

void SvxMacroTableDtor::DelDtor()
{
    SvxMacro* pTmp = First();
    while( pTmp )
    {
        delete pTmp;
        pTmp = Next();
    }
    Clear();
}

// -----------------------------------------------------------------------

int SvxMacroItem::operator==( const SfxPoolItem& rAttr ) const
{
    DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );

    const SvxMacroTableDtor& rOwn = aMacroTable;
    const SvxMacroTableDtor& rOther = ( (SvxMacroItem&) rAttr ).aMacroTable;

    // Anzahl unterschiedlich => auf jeden Fall ungleich
    if ( rOwn.Count() != rOther.Count() )
        return FALSE;

    // einzeln verleichen; wegen Performance ist die Reihenfolge wichtig
    for ( USHORT nNo = 0; nNo < rOwn.Count(); ++nNo )
    {
        const SvxMacro *pOwnMac = rOwn.GetObject(nNo);
        const SvxMacro *pOtherMac = rOther.GetObject(nNo);
        if (    rOwn.GetKey(pOwnMac) != rOther.GetKey(pOtherMac)  ||
                pOwnMac->GetLibName() != pOtherMac->GetLibName() ||
                pOwnMac->GetMacName() != pOtherMac->GetMacName() )
            return FALSE;
    }

    return TRUE;
}

// -----------------------------------------------------------------------

SfxPoolItem* SvxMacroItem::Clone( SfxItemPool* ) const
{
    return new SvxMacroItem( *this );
}

//------------------------------------------------------------------------

SfxItemPresentation SvxMacroItem::GetPresentation
(
    SfxItemPresentation /*ePres*/,
    SfxMapUnit          /*eCoreUnit*/,
    SfxMapUnit          /*ePresUnit*/,
    XubString&          rText,
    const IntlWrapper *
)   const
{
/*!!!
    SvxMacroTableDtor& rTbl = (SvxMacroTableDtor&)GetMacroTable();
    SvxMacro* pMac = rTbl.First();

    while ( pMac )
    {
        rText += pMac->GetLibName();
        rText += cpDelim;
        rText += pMac->GetMacName();
        pMac = rTbl.Next();
        if ( pMac )
            rText += cpDelim;
    }
*/
    rText.Erase();
    return SFX_ITEM_PRESENTATION_NONE;
}

// -----------------------------------------------------------------------

SvStream& SvxMacroItem::Store( SvStream& rStrm , USHORT ) const
{
    return aMacroTable.Write( rStrm );
}

// -----------------------------------------------------------------------

SfxPoolItem* SvxMacroItem::Create( SvStream& rStrm, USHORT nVersion ) const
{
    SvxMacroItem* pAttr = new SvxMacroItem( Which() );
    pAttr->aMacroTable.Read( rStrm, nVersion );
    return pAttr;
}

// -----------------------------------------------------------------------

void SvxMacroItem::SetMacro( USHORT nEvent, const SvxMacro& rMacro )
{
    SvxMacro *pMacro;
    if ( 0 != (pMacro=aMacroTable.Get(nEvent)) )
    {
        delete pMacro;
        aMacroTable.Replace(nEvent, new SvxMacro( rMacro ) );
    }
    else
        aMacroTable.Insert(nEvent, new SvxMacro( rMacro ) );
}

// -----------------------------------------------------------------------

USHORT SvxMacroItem::GetVersion( USHORT nFileFormatVersion ) const
{
    return SOFFICE_FILEFORMAT_31 == nFileFormatVersion
                ? 0 : aMacroTable.GetVersion();
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: cuiimapwnd.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: kz $ $Date: 2007-05-10 14:36:20 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"

#ifdef SVX_DLLIMPLEMENTATION
#undef SVX_DLLIMPLEMENTATION
#endif

#ifndef _URLOBJ_HXX //autogen
#include <tools/urlobj.hxx>
#endif
#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef _SV_HELP_HXX //autogen
#include <vcl/help.hxx>
#endif

#ifndef _SFXSIDS_HRC
#include <sfx2/sfxsids.hrc>     // SID_ATTR_MACROITEM
#endif
#define _ANIMATION

#ifndef _MACROPG_HXX //autogen
#include <sfx2/macropg.hxx>
#endif
#ifndef _GOODIES_IMAPRECT_HXX //autogen
#include <svtools/imaprect.hxx>
#endif
#ifndef _GOODIES_IMAPCIRC_HXX //autogen
#include <svtools/imapcirc.hxx>
#endif
#ifndef _GOODIES_IMAPPOLY_HXX //autogen
#include <svtools/imappoly.hxx>
#endif
#ifndef _URLBMK_HXX //autogen
#include <svtools/urlbmk.hxx>
#endif

#include <xoutbmp.hxx>
#include <dialmgr.hxx>
#include <dialogs.hrc>
#include <svxids.hrc>
#include <imapdlg.hrc>
#include <imapwnd.hxx>
#include "svdpage.hxx"
#include "svdorect.hxx"
#include "svdocirc.hxx"
#include "svdopath.hxx"
#include "xfltrit.hxx"
#include "svdpagv.hxx"

#ifndef SVTOOLS_URIHELPER_HXX
#include <svtools/urihelper.hxx>
#endif
#ifndef _SVX_FILLITEM_HXX //autogen
#include <xfillit.hxx>
#endif
#ifndef _SVX_XLINIIT_HXX //autogen
#include <xlineit.hxx>
#endif

#include <sot/formats.hxx>

#include "cuiimapwnd.hxx" //CHINA001

#ifdef MAC
#define TRANSCOL Color( COL_LIGHTGRAY )
#else
#define TRANSCOL Color( COL_WHITE )
#endif

/*************************************************************************
|*
|*  URLDlg
|*
\************************************************************************/

URLDlg::URLDlg( Window* pWindow, const String& rURL,
                const String& rDescription, const String& rTarget,
                const String& rName, TargetList& rTargetList ) :

    ModalDialog         ( pWindow, SVX_RES( RID_SVXDLG_IMAPURL ) ),

    aFlURL              ( this, SVX_RES( FL_URL ) ),
    aFtURL1             ( this, SVX_RES( FT_URL1 ) ),
    aEdtURL             ( this, SVX_RES( EDT_URL ) ),
    aFtURLDescription   ( this, SVX_RES( FT_URLDESCRIPTION ) ),
    aEdtURLDescription  ( this, SVX_RES( EDT_URLDESCRIPTION ) ),
    aFtTarget           ( this, SVX_RES( FT_TARGET ) ),
    aCbbTargets         ( this, SVX_RES( CBB_TARGETS ) ),
    aFtName             ( this, SVX_RES( FT_NAME ) ),
    aEdtName            ( this, SVX_RES( EDT_NAME ) ),
    aBtnOk              ( this, SVX_RES( BTN_OK ) ),
    aBtnCancel          ( this, SVX_RES( BTN_CANCEL1 ) )

{
    FreeResource();

    aEdtURL.SetText( rURL );
    aEdtURLDescription.SetText( rDescription );
    aEdtName.SetText( rName );

    for( String* pStr = rTargetList.First(); pStr; pStr = rTargetList.Next() )
        aCbbTargets.InsertEntry( *pStr );

    if( !rTarget.Len() )
        aCbbTargets.SetText( String::CreateFromAscii( "_self" ) );
    else
        aCbbTargets.SetText( rTarget );
}
<commit_msg>INTEGRATION: CWS impressalternativtext (1.8.6); FILE MERGED 2007/05/25 10:37:43 cl 1.8.6.2: #i68099# added description to ImageMapObj's 2007/05/24 13:38:17 cl 1.8.6.1: #i68099# added description to ImageMapObj's<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: cuiimapwnd.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: hr $ $Date: 2007-06-26 13:49:48 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"

#ifdef SVX_DLLIMPLEMENTATION
#undef SVX_DLLIMPLEMENTATION
#endif

#ifndef _URLOBJ_HXX //autogen
#include <tools/urlobj.hxx>
#endif
#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef _SV_HELP_HXX //autogen
#include <vcl/help.hxx>
#endif

#ifndef _SFXSIDS_HRC
#include <sfx2/sfxsids.hrc>     // SID_ATTR_MACROITEM
#endif
#define _ANIMATION

#ifndef _MACROPG_HXX //autogen
#include <sfx2/macropg.hxx>
#endif
#ifndef _GOODIES_IMAPRECT_HXX //autogen
#include <svtools/imaprect.hxx>
#endif
#ifndef _GOODIES_IMAPCIRC_HXX //autogen
#include <svtools/imapcirc.hxx>
#endif
#ifndef _GOODIES_IMAPPOLY_HXX //autogen
#include <svtools/imappoly.hxx>
#endif
#ifndef _URLBMK_HXX //autogen
#include <svtools/urlbmk.hxx>
#endif

#include <xoutbmp.hxx>
#include <dialmgr.hxx>
#include <dialogs.hrc>
#include <svxids.hrc>
#include <imapdlg.hrc>
#include <imapwnd.hxx>
#include "svdpage.hxx"
#include "svdorect.hxx"
#include "svdocirc.hxx"
#include "svdopath.hxx"
#include "xfltrit.hxx"
#include "svdpagv.hxx"

#ifndef SVTOOLS_URIHELPER_HXX
#include <svtools/urihelper.hxx>
#endif
#ifndef _SVX_FILLITEM_HXX //autogen
#include <xfillit.hxx>
#endif
#ifndef _SVX_XLINIIT_HXX //autogen
#include <xlineit.hxx>
#endif

#include <sot/formats.hxx>

#include "cuiimapwnd.hxx" //CHINA001

#ifdef MAC
#define TRANSCOL Color( COL_LIGHTGRAY )
#else
#define TRANSCOL Color( COL_WHITE )
#endif

/*************************************************************************
|*
|*  URLDlg
|*
\************************************************************************/

URLDlg::URLDlg( Window* pWindow, const String& rURL, const String& rAlternativeText, const String& rDescription, const String& rTarget, const String& rName, TargetList& rTargetList )
: ModalDialog( pWindow, SVX_RES( RID_SVXDLG_IMAPURL ) )
, maFtURL( this, SVX_RES( FT_URL1 ) )
, maEdtURL( this, SVX_RES( EDT_URL ) )
, maFtTarget( this, SVX_RES( FT_TARGET ) )
, maCbbTargets( this, SVX_RES( CBB_TARGETS ) )
, maFtName( this, SVX_RES( FT_NAME ) )
, maEdtName( this, SVX_RES( EDT_NAME ) )
, maFtAlternativeText( this, SVX_RES( FT_URLDESCRIPTION ) )
, maEdtAlternativeText( this, SVX_RES( EDT_URLDESCRIPTION ) )
, maFtDescription( this, SVX_RES( FT_DESCRIPTION ) )
, maEdtDescription( this, SVX_RES( EDT_DESCRIPTION ) )
, maFlURL( this, SVX_RES( FL_URL ) )
, maBtnHelp( this, SVX_RES( BTN_HELP1 ) )
, maBtnOk( this, SVX_RES( BTN_OK1 ) )
, maBtnCancel( this, SVX_RES( BTN_CANCEL1 ) )
{
    FreeResource();

    maEdtURL.SetText( rURL );
    maEdtAlternativeText.SetText( rAlternativeText );
    maEdtDescription.SetText( rDescription );
    maEdtName.SetText( rName );

    for( String* pStr = rTargetList.First(); pStr; pStr = rTargetList.Next() )
        maCbbTargets.InsertEntry( *pStr );

    if( !rTarget.Len() )
        maCbbTargets.SetText( String::CreateFromAscii( "_self" ) );
    else
        maCbbTargets.SetText( rTarget );
}
<|endoftext|>