<commit_before>/*
 *  RBDecorators.cpp
 *  golf
 *
 *  Created by Robert Rose on 4/20/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#include "RBDecorators.h"

#include "RudeDebug.h"
#include "RudeFile.h"
#include "RudeTextureManager.h"
#include "RudeTweaker.h"

bool gRenderDecos = true;
RUDE_TWEAK(RenderDecos, kBool, gRenderDecos);

RBDecoratorInstance::RBDecoratorInstance()
{
	m_pos[0] = 0.0f;
	m_pos[1] = 0.0f;
	m_pos[2] = 0.0f;
}

void RBDecoratorInstance::Set(float x, float y, float z)
{
	m_pos[0] = x;
	m_pos[1] = y;
	m_pos[2] = z;
}

RBDecorator::RBDecorator()
: m_textureid(0)
, m_numInstances(0)
, m_size(16.0f)
, m_texturesize(128.0f)
{
	SetSize(16.0f);

}

void RBDecorator::SetTexture(const char *file)
{
	m_textureid = RudeTextureManager::GetInstance()->LoadTextureFromPVRTFile(file);
	m_texturesize = RudeTextureManager::GetInstance()->GetTexture(m_textureid)->GetHeight();
}

void RBDecorator::SetSize(float size)
{
	m_size = size;
	float hsize = 0.5f * m_size;

	float uvoffset = 1.0f / m_texturesize;

	// bottom left
	m_verts[0].m_pos[0] = -hsize;
	m_verts[0].m_pos[1] = 0;
	m_verts[0].m_pos[2] = 0;
	m_verts[0].m_uv[0] = 0;
	m_verts[0].m_uv[1] = 0;

	// bottom right
	m_verts[1].m_pos[0] = hsize;
	m_verts[1].m_pos[1] = 0;
	m_verts[1].m_pos[2] = 0;
	m_verts[1].m_uv[0] = 1 - uvoffset;
	m_verts[1].m_uv[1] = 0;

	// top left
	m_verts[2].m_pos[0] = -hsize;
	m_verts[2].m_pos[1] = size;
	m_verts[2].m_pos[2] = 0;
	m_verts[2].m_uv[0] = 0;
	m_verts[2].m_uv[1] = 1 - uvoffset;

	// top left
	m_verts[3].m_pos[0] = -hsize;
	m_verts[3].m_pos[1] = size;
	m_verts[3].m_pos[2] = 0;
	m_verts[3].m_uv[0] = 0;
	m_verts[3].m_uv[1] = 1 - uvoffset;

	// bottom right
	m_verts[4].m_pos[0] = hsize;
	m_verts[4].m_pos[1] = 0;
	m_verts[4].m_pos[2] = 0;
	m_verts[4].m_uv[0] = 1 - uvoffset;
	m_verts[4].m_uv[1] = 0;

	// top right
	m_verts[5].m_pos[0] = hsize;
	m_verts[5].m_pos[1] = size;
	m_verts[5].m_pos[2] = 0;
	m_verts[5].m_uv[0] = 1 - uvoffset;
	m_verts[5].m_uv[1] = 1 - uvoffset;
}

bool RBDecorator::AddInstance(float x, float y, float z)
{
	if(m_numInstances < kMaxInstances)
	{
		m_instances[m_numInstances].Set(x, y, z);

		m_numInstances++;

		return true;
	}
	else
		return false;
}

void RBDecorator::Print()
{
	RUDE_REPORT("\nDECORATOR %s %f\n\n", RudeTextureManager::GetInstance()->GetTexture(m_textureid)->GetName(), m_size);

	for(int i = 0; i < m_numInstances; i++)
	{
		RUDE_REPORT("%f %f %f\n", m_instances[i].m_pos[0], m_instances[i].m_pos[1], m_instances[i].m_pos[2]);
	}
}

void RBDecorator::Render()
{
	glVertexPointer(3, GL_FLOAT, sizeof(RBDecoratorVert), &m_verts[0].m_pos);
	glTexCoordPointer(2, GL_FLOAT, sizeof(RBDecoratorVert), &m_verts[0].m_uv);

	RudeTextureManager::GetInstance()->SetTexture(m_textureid);

	float M[16];

	for(int i = 0; i < m_numInstances; i++)
	{
		glPushMatrix();
		glTranslatef(m_instances[i].m_pos[0], m_instances[i].m_pos[1], m_instances[i].m_pos[2]);

		glGetFloatv(GL_MODELVIEW_MATRIX, M);

		M[0] = 1.0;
		M[1] = 0.0f;
		M[2] = 0.0f;

		M[8] = 0.0f;
		M[9] = 0.0f;
		M[10] = 1.0f;

		/*
		for(int i=0; i<3; i+=2 )
			for(int j=0; j<3; j++ ) {
				if ( i==j )
					M[i*4+j] = 1.0;
				else
					M[i*4+j] = 0.0;
			}*/

		glLoadMatrixf(M);

		glDrawArrays(GL_TRIANGLES, 0, 6);

		glPopMatrix();
	}
}

RBDecoratorCollection::RBDecoratorCollection()
: m_dropTextureNum(0)
{
}

void RBDecoratorCollection::Load(const char *deco)
{
	char filename[512];
	sprintf(filename, "%s.deco", deco);

	char path[512];
	bool found = RudeFileGetFile(filename, path, 512, true);

	if(!found)
		return;

	RUDE_REPORT("RBDecoratorCollection loading %s\n", filename);

	FILE *file = fopen(path, "r");
	RUDE_ASSERT(file, "Could not open file %s", path);

	char buf[256];
	char *line = fgets(buf, 256, file);

	RBDecorator *curdeco = 0;

	while(line)
	{
		char texturename[256];
		float size = 8.0f;

		int result = sscanf(line, "DECORATOR %s %f\n", texturename, &size);

		if(result == 2)
		{
			RUDE_REPORT("  DECORATOR: texture=%s size=%f\n", texturename, size);

			RBDecorator decorator;
			decorator.SetTexture(texturename);
			decorator.SetSize(size);

			m_decorators.push_back(decorator);

			curdeco = &m_decorators[m_decorators.size() - 1];

			AddTexture(texturename);
		}
		else
		{
			float pos[3];
			result = sscanf(line, "%f %f %f\n", &pos[0], &pos[1], &pos[2]);

			if(result == 3)
			{
				RUDE_ASSERT(curdeco, "Failed to parse decorators, DECORATOR not defined");

				RUDE_REPORT("    %f %f %f\n", pos[0], pos[1], pos[2]);
				bool added = curdeco->AddInstance(pos[0], pos[1], pos[2]);

				RUDE_ASSERT(added, "Failed to add decorator instance");

#ifndef NO_DECO_EDITOR
				m_droppedDecorators.push_back(btVector3(pos[0], pos[1], pos[2]));
#endif
			}
		}

		line = fgets(buf, 256, file);
	}

	fclose(file);

}

#ifndef NO_DECO_EDITOR
void RBDecoratorCollection::Drop(const btVector3 &pos, float size)
{
	RUDE_ASSERT(m_textureNames.size() > 0, "No decorators have been loaded so there are no textures to drop with");

	m_dropTextureNum++;
	if(m_dropTextureNum >= m_textureNames.size())
		m_dropTextureNum = 0;

	// Check to make sure there's no already a decorator at this position
	for(unsigned int i = 0; i < m_droppedDecorators.size(); i++)
	{
		if(m_droppedDecorators[i] == pos)
			return;
	}

	m_droppedDecorators.push_back(pos);

	// Check to see if we already have a decorator of the same size and texture
	int curTextureID = RudeTextureManager::GetInstance()->LoadTextureFromPVRTFile(m_textureNames[m_dropTextureNum].c_str());
	for(unsigned int i = 0; i < m_decorators.size(); i++)
	{
		RBDecorator &deco = m_decorators[i];

		if(deco.GetTextureID() == curTextureID)
		{
			if(deco.GetSize() == size)
			{
				bool added = deco.AddInstance(pos.x(), pos.y(), pos.z());

				if(added == false)
				{
					Print();
					RUDE_ASSERT(added, "Failed to add decorator instance");
				}
				return;
			}
		}
	}

	RBDecorator deco;
	deco.SetTexture(m_textureNames[m_dropTextureNum].c_str());
	deco.SetSize(size);
	deco.AddInstance(pos.x(), pos.y(), pos.z());

	m_decorators.push_back(deco);

}
#endif

void RBDecoratorCollection::Print()
{
	RUDE_REPORT("\n\n# Decorator Collection\n#\n#\n#\n");

	for(unsigned int i = 0; i < m_decorators.size(); i++)
	{
		m_decorators[i].Print();
	}
}

void RBDecoratorCollection::Render()
{
	unsigned int numdecos = m_decorators.size();

	if(numdecos == 0 || gRenderDecos == false)
		return;

	// set up draw state

	RGL.Enable(kBackfaceCull, false);

	RGL.EnableClient(kVertexArray, true);
	RGL.EnableClient(kColorArray, false);
	RGL.EnableClient(kTextureCoordArray, true);

	glAlphaFunc(GL_GREATER, 0.5);
    glEnable(GL_ALPHA_TEST);

	// set up GL matrix

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();

	float w = RGL.GetHalfWidth();
	float h = RGL.GetHalfHeight();
	RGL.Frustum(0.0f, 0.0f, w * 2.0f, h * 2.0f, 4.0f, 2000.0f);

	btVector3 eye = RGL.GetEye();
	btVector3 forward = RGL.GetForward();

	btVector3 inup(0, 1, 0);
	btVector3 side = inup.cross(forward);
	side.normalize();

	btVector3 up = forward.cross(side);

	float M[] =
	{
		side.x(), up.x(), forward.x(), 0,
		side.y(), up.y(), forward.y(), 0,
		side.z(), up.z(), forward.z(), 0,
		0, 0, 0, 1
	};

	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(M);
	glTranslatef (-eye.x(), -eye.y(), -eye.z());

	for(unsigned int i = 0; i < numdecos; i++)
	{
		m_decorators[i].Render();
	}

	// restore GL matrix

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	RGL.LoadIdentity();

	// restore draw state
	glDisable(GL_ALPHA_TEST);

}

void RBDecoratorCollection::AddTexture(const char *textureName)
{
	unsigned int size = m_textureNames.size();
	bool found = false;

	for(int i = 0; i < size; i++)
	{
		if(m_textureNames[i] == std::string(textureName))
			found = true;
	}

	if(!found)
		m_textureNames.push_back(std::string(textureName));
}

<commit_msg>extended decorator far plane out to 2500<commit_after>/*
 *  RBDecorators.cpp
 *  golf
 *
 *  Created by Robert Rose on 4/20/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#include "RBDecorators.h"

#include "RudeDebug.h"
#include "RudeFile.h"
#include "RudeTextureManager.h"
#include "RudeTweaker.h"

bool gRenderDecos = true;
RUDE_TWEAK(RenderDecos, kBool, gRenderDecos);

RBDecoratorInstance::RBDecoratorInstance()
{
	m_pos[0] = 0.0f;
	m_pos[1] = 0.0f;
	m_pos[2] = 0.0f;
}

void RBDecoratorInstance::Set(float x, float y, float z)
{
	m_pos[0] = x;
	m_pos[1] = y;
	m_pos[2] = z;
}

RBDecorator::RBDecorator()
: m_textureid(0)
, m_numInstances(0)
, m_size(16.0f)
, m_texturesize(128.0f)
{
	SetSize(16.0f);

}

void RBDecorator::SetTexture(const char *file)
{
	m_textureid = RudeTextureManager::GetInstance()->LoadTextureFromPVRTFile(file);
	m_texturesize = RudeTextureManager::GetInstance()->GetTexture(m_textureid)->GetHeight();
}

void RBDecorator::SetSize(float size)
{
	m_size = size;
	float hsize = 0.5f * m_size;

	float uvoffset = 1.0f / m_texturesize;

	// bottom left
	m_verts[0].m_pos[0] = -hsize;
	m_verts[0].m_pos[1] = 0;
	m_verts[0].m_pos[2] = 0;
	m_verts[0].m_uv[0] = 0;
	m_verts[0].m_uv[1] = 0;

	// bottom right
	m_verts[1].m_pos[0] = hsize;
	m_verts[1].m_pos[1] = 0;
	m_verts[1].m_pos[2] = 0;
	m_verts[1].m_uv[0] = 1 - uvoffset;
	m_verts[1].m_uv[1] = 0;

	// top left
	m_verts[2].m_pos[0] = -hsize;
	m_verts[2].m_pos[1] = size;
	m_verts[2].m_pos[2] = 0;
	m_verts[2].m_uv[0] = 0;
	m_verts[2].m_uv[1] = 1 - uvoffset;

	// top left
	m_verts[3].m_pos[0] = -hsize;
	m_verts[3].m_pos[1] = size;
	m_verts[3].m_pos[2] = 0;
	m_verts[3].m_uv[0] = 0;
	m_verts[3].m_uv[1] = 1 - uvoffset;

	// bottom right
	m_verts[4].m_pos[0] = hsize;
	m_verts[4].m_pos[1] = 0;
	m_verts[4].m_pos[2] = 0;
	m_verts[4].m_uv[0] = 1 - uvoffset;
	m_verts[4].m_uv[1] = 0;

	// top right
	m_verts[5].m_pos[0] = hsize;
	m_verts[5].m_pos[1] = size;
	m_verts[5].m_pos[2] = 0;
	m_verts[5].m_uv[0] = 1 - uvoffset;
	m_verts[5].m_uv[1] = 1 - uvoffset;
}

bool RBDecorator::AddInstance(float x, float y, float z)
{
	if(m_numInstances < kMaxInstances)
	{
		m_instances[m_numInstances].Set(x, y, z);

		m_numInstances++;

		return true;
	}
	else
		return false;
}

void RBDecorator::Print()
{
	RUDE_REPORT("\nDECORATOR %s %f\n\n", RudeTextureManager::GetInstance()->GetTexture(m_textureid)->GetName(), m_size);

	for(int i = 0; i < m_numInstances; i++)
	{
		RUDE_REPORT("%f %f %f\n", m_instances[i].m_pos[0], m_instances[i].m_pos[1], m_instances[i].m_pos[2]);
	}
}

void RBDecorator::Render()
{
	glVertexPointer(3, GL_FLOAT, sizeof(RBDecoratorVert), &m_verts[0].m_pos);
	glTexCoordPointer(2, GL_FLOAT, sizeof(RBDecoratorVert), &m_verts[0].m_uv);

	RudeTextureManager::GetInstance()->SetTexture(m_textureid);

	float M[16];

	for(int i = 0; i < m_numInstances; i++)
	{
		glPushMatrix();
		glTranslatef(m_instances[i].m_pos[0], m_instances[i].m_pos[1], m_instances[i].m_pos[2]);

		glGetFloatv(GL_MODELVIEW_MATRIX, M);

		M[0] = 1.0;
		M[1] = 0.0f;
		M[2] = 0.0f;

		M[8] = 0.0f;
		M[9] = 0.0f;
		M[10] = 1.0f;

		/*
		for(int i=0; i<3; i+=2 )
			for(int j=0; j<3; j++ ) {
				if ( i==j )
					M[i*4+j] = 1.0;
				else
					M[i*4+j] = 0.0;
			}*/

		glLoadMatrixf(M);

		glDrawArrays(GL_TRIANGLES, 0, 6);

		glPopMatrix();
	}
}

RBDecoratorCollection::RBDecoratorCollection()
: m_dropTextureNum(0)
{
}

void RBDecoratorCollection::Load(const char *deco)
{
	char filename[512];
	sprintf(filename, "%s.deco", deco);

	char path[512];
	bool found = RudeFileGetFile(filename, path, 512, true);

	if(!found)
		return;

	RUDE_REPORT("RBDecoratorCollection loading %s\n", filename);

	FILE *file = fopen(path, "r");
	RUDE_ASSERT(file, "Could not open file %s", path);

	char buf[256];
	char *line = fgets(buf, 256, file);

	RBDecorator *curdeco = 0;

	while(line)
	{
		char texturename[256];
		float size = 8.0f;

		int result = sscanf(line, "DECORATOR %s %f\n", texturename, &size);

		if(result == 2)
		{
			RUDE_REPORT("  DECORATOR: texture=%s size=%f\n", texturename, size);

			RBDecorator decorator;
			decorator.SetTexture(texturename);
			decorator.SetSize(size);

			m_decorators.push_back(decorator);

			curdeco = &m_decorators[m_decorators.size() - 1];

			AddTexture(texturename);
		}
		else
		{
			float pos[3];
			result = sscanf(line, "%f %f %f\n", &pos[0], &pos[1], &pos[2]);

			if(result == 3)
			{
				RUDE_ASSERT(curdeco, "Failed to parse decorators, DECORATOR not defined");

				RUDE_REPORT("    %f %f %f\n", pos[0], pos[1], pos[2]);
				bool added = curdeco->AddInstance(pos[0], pos[1], pos[2]);

				RUDE_ASSERT(added, "Failed to add decorator instance");

#ifndef NO_DECO_EDITOR
				m_droppedDecorators.push_back(btVector3(pos[0], pos[1], pos[2]));
#endif
			}
		}

		line = fgets(buf, 256, file);
	}

	fclose(file);

}

#ifndef NO_DECO_EDITOR
void RBDecoratorCollection::Drop(const btVector3 &pos, float size)
{
	RUDE_ASSERT(m_textureNames.size() > 0, "No decorators have been loaded so there are no textures to drop with");

	m_dropTextureNum++;
	if(m_dropTextureNum >= m_textureNames.size())
		m_dropTextureNum = 0;

	// Check to make sure there's no already a decorator at this position
	for(unsigned int i = 0; i < m_droppedDecorators.size(); i++)
	{
		if(m_droppedDecorators[i] == pos)
			return;
	}

	m_droppedDecorators.push_back(pos);

	// Check to see if we already have a decorator of the same size and texture
	int curTextureID = RudeTextureManager::GetInstance()->LoadTextureFromPVRTFile(m_textureNames[m_dropTextureNum].c_str());
	for(unsigned int i = 0; i < m_decorators.size(); i++)
	{
		RBDecorator &deco = m_decorators[i];

		if(deco.GetTextureID() == curTextureID)
		{
			if(deco.GetSize() == size)
			{
				bool added = deco.AddInstance(pos.x(), pos.y(), pos.z());

				if(added == false)
				{
					Print();
					RUDE_ASSERT(added, "Failed to add decorator instance");
				}
				return;
			}
		}
	}

	RBDecorator deco;
	deco.SetTexture(m_textureNames[m_dropTextureNum].c_str());
	deco.SetSize(size);
	deco.AddInstance(pos.x(), pos.y(), pos.z());

	m_decorators.push_back(deco);

}
#endif

void RBDecoratorCollection::Print()
{
	RUDE_REPORT("\n\n# Decorator Collection\n#\n#\n#\n");

	for(unsigned int i = 0; i < m_decorators.size(); i++)
	{
		m_decorators[i].Print();
	}
}

void RBDecoratorCollection::Render()
{
	unsigned int numdecos = m_decorators.size();

	if(numdecos == 0 || gRenderDecos == false)
		return;

	// set up draw state

	RGL.Enable(kBackfaceCull, false);

	RGL.EnableClient(kVertexArray, true);
	RGL.EnableClient(kColorArray, false);
	RGL.EnableClient(kTextureCoordArray, true);

	glAlphaFunc(GL_GREATER, 0.5);
    glEnable(GL_ALPHA_TEST);

	// set up GL matrix

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();

	float w = RGL.GetHalfWidth();
	float h = RGL.GetHalfHeight();
	RGL.Frustum(0.0f, 0.0f, w * 2.0f, h * 2.0f, 4.0f, 2500.0f);

	btVector3 eye = RGL.GetEye();
	btVector3 forward = RGL.GetForward();

	btVector3 inup(0, 1, 0);
	btVector3 side = inup.cross(forward);
	side.normalize();

	btVector3 up = forward.cross(side);

	float M[] =
	{
		side.x(), up.x(), forward.x(), 0,
		side.y(), up.y(), forward.y(), 0,
		side.z(), up.z(), forward.z(), 0,
		0, 0, 0, 1
	};

	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(M);
	glTranslatef (-eye.x(), -eye.y(), -eye.z());

	for(unsigned int i = 0; i < numdecos; i++)
	{
		m_decorators[i].Render();
	}

	// restore GL matrix

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	RGL.LoadIdentity();

	// restore draw state
	glDisable(GL_ALPHA_TEST);

}

void RBDecoratorCollection::AddTexture(const char *textureName)
{
	unsigned int size = m_textureNames.size();
	bool found = false;

	for(int i = 0; i < size; i++)
	{
		if(m_textureNames[i] == std::string(textureName))
			found = true;
	}

	if(!found)
		m_textureNames.push_back(std::string(textureName));
}

<|endoftext|>


<commit_before>#include<stdio.h>
#include<stdlib.h>

int main()

{
	int a;
	a = 20161107;

	printf_s("%d\n", a);

	system("pause");
	return(0);

}<commit_msg>Update Source.cpp<commit_after>#include<stdio.h>
#include<stdlib.h>

int main()

{
	int b;
	b = 20161107;

	printf_s("%d\n", b);

	system("pause");
	return(0);

}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: sortparam.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: rt $ $Date: 2008-01-29 15:20:06 $
 *
 *  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_sc.hxx"

#include "sortparam.hxx"
#include "global.hxx"
#include "address.hxx"

#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif

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

ScSortParam::ScSortParam()
{
    Clear();
}

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

ScSortParam::ScSortParam( const ScSortParam& r ) :
        nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),
        bHasHeader(r.bHasHeader),bByRow(r.bByRow),bCaseSens(r.bCaseSens),
        bUserDef(r.bUserDef),nUserIndex(r.nUserIndex),bIncludePattern(r.bIncludePattern),
        bInplace(r.bInplace),
        nDestTab(r.nDestTab),nDestCol(r.nDestCol),nDestRow(r.nDestRow),
        aCollatorLocale( r.aCollatorLocale ), aCollatorAlgorithm( r.aCollatorAlgorithm )
{
    for (USHORT i=0; i<MAXSORT; i++)
    {
        bDoSort[i]    = r.bDoSort[i];
        nField[i]     = r.nField[i];
        bAscending[i] = r.bAscending[i];
    }
}

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

void ScSortParam::Clear()
{
    nCol1=nCol2=nDestCol = 0;
    nRow1=nRow2=nDestRow = 0;
    nCompatHeader = 2;
    nDestTab = 0;
    nUserIndex = 0;
    bHasHeader=bCaseSens=bUserDef = FALSE;
    bByRow=bIncludePattern=bInplace = TRUE;
    aCollatorLocale = ::com::sun::star::lang::Locale();
    aCollatorAlgorithm.Erase();

    for (USHORT i=0; i<MAXSORT; i++)
    {
        bDoSort[i]    = FALSE;
        nField[i]     = 0;
        bAscending[i] = TRUE;
    }
}

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

ScSortParam& ScSortParam::operator=( const ScSortParam& r )
{
    nCol1           = r.nCol1;
    nRow1           = r.nRow1;
    nCol2           = r.nCol2;
    nRow2           = r.nRow2;
    bHasHeader      = r.bHasHeader;
    bCaseSens       = r.bCaseSens;
    bByRow          = r.bByRow;
    bUserDef        = r.bUserDef;
    nUserIndex      = r.nUserIndex;
    bIncludePattern = r.bIncludePattern;
    bInplace        = r.bInplace;
    nDestTab        = r.nDestTab;
    nDestCol        = r.nDestCol;
    nDestRow        = r.nDestRow;
    aCollatorLocale         = r.aCollatorLocale;
    aCollatorAlgorithm      = r.aCollatorAlgorithm;

    for (USHORT i=0; i<MAXSORT; i++)
    {
        bDoSort[i]    = r.bDoSort[i];
        nField[i]     = r.nField[i];
        bAscending[i] = r.bAscending[i];
    }

    return *this;
}

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

BOOL ScSortParam::operator==( const ScSortParam& rOther ) const
{
    BOOL bEqual = FALSE;
    // Anzahl der Sorts gleich?
    USHORT nLast      = 0;
    USHORT nOtherLast = 0;
    while ( bDoSort[nLast++] && nLast < MAXSORT );
    while ( rOther.bDoSort[nOtherLast++] && nOtherLast < MAXSORT );
    nLast--;
    nOtherLast--;
    if (   (nLast           == nOtherLast)
        && (nCol1           == rOther.nCol1)
        && (nRow1           == rOther.nRow1)
        && (nCol2           == rOther.nCol2)
        && (nRow2           == rOther.nRow2)
        && (bHasHeader      == rOther.bHasHeader)
        && (bByRow          == rOther.bByRow)
        && (bCaseSens       == rOther.bCaseSens)
        && (bUserDef        == rOther.bUserDef)
        && (nUserIndex      == rOther.nUserIndex)
        && (bIncludePattern == rOther.bIncludePattern)
        && (bInplace        == rOther.bInplace)
        && (nDestTab        == rOther.nDestTab)
        && (nDestCol        == rOther.nDestCol)
        && (nDestRow        == rOther.nDestRow)
        && (aCollatorLocale.Language    == rOther.aCollatorLocale.Language)
        && (aCollatorLocale.Country     == rOther.aCollatorLocale.Country)
        && (aCollatorLocale.Variant     == rOther.aCollatorLocale.Variant)
        && (aCollatorAlgorithm          == rOther.aCollatorAlgorithm)
        )
    {
        bEqual = TRUE;
        for ( USHORT i=0; i<=nLast && bEqual; i++ )
        {
            bEqual = (nField[i] == rOther.nField[i]) && (bAscending[i]  == rOther.bAscending[i]);
        }
    }
    return bEqual;
}

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

ScSortParam::ScSortParam( const ScSubTotalParam& rSub, const ScSortParam& rOld ) :
        nCol1(rSub.nCol1),nRow1(rSub.nRow1),nCol2(rSub.nCol2),nRow2(rSub.nRow2),
        bHasHeader(TRUE),bByRow(TRUE),bCaseSens(rSub.bCaseSens),
        bUserDef(rSub.bUserDef),nUserIndex(rSub.nUserIndex),bIncludePattern(rSub.bIncludePattern),
        bInplace(TRUE),
        nDestTab(0),nDestCol(0),nDestRow(0),
        aCollatorLocale( rOld.aCollatorLocale ), aCollatorAlgorithm( rOld.aCollatorAlgorithm )
{
    USHORT nNewCount = 0;
    USHORT i;

    //  zuerst die Gruppen aus den Teilergebnissen
    if (rSub.bDoSort)
        for (i=0; i<MAXSUBTOTAL; i++)
            if (rSub.bGroupActive[i])
            {
                if (nNewCount < MAXSORT)
                {
                    bDoSort[nNewCount]    = TRUE;
                    nField[nNewCount]     = rSub.nField[i];
                    bAscending[nNewCount] = rSub.bAscending;
                    ++nNewCount;
                }
            }

    //  dann dahinter die alten Einstellungen
    for (i=0; i<MAXSORT; i++)
        if (rOld.bDoSort[i])
        {
            SCCOLROW nThisField = rOld.nField[i];
            BOOL bDouble = FALSE;
            for (USHORT j=0; j<nNewCount; j++)
                if ( nField[j] == nThisField )
                    bDouble = TRUE;
            if (!bDouble)               // ein Feld nicht zweimal eintragen
            {
                if (nNewCount < MAXSORT)
                {
                    bDoSort[nNewCount]    = TRUE;
                    nField[nNewCount]     = nThisField;
                    bAscending[nNewCount] = rOld.bAscending[i];
                    ++nNewCount;
                }
            }
        }

    for (i=nNewCount; i<MAXSORT; i++)       // Rest loeschen
    {
        bDoSort[i]    = FALSE;
        nField[i]     = 0;
        bAscending[i] = TRUE;
    }
}

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

ScSortParam::ScSortParam( const ScQueryParam& rParam, SCCOL nCol ) :
        nCol1(nCol),nRow1(rParam.nRow1),nCol2(nCol),nRow2(rParam.nRow2),
        bHasHeader(rParam.bHasHeader),bByRow(TRUE),bCaseSens(rParam.bCaseSens),
//! TODO: what about Locale and Algorithm?
        bUserDef(FALSE),nUserIndex(0),bIncludePattern(FALSE),
        bInplace(TRUE),
        nDestTab(0),nDestCol(0),nDestRow(0)
{
    bDoSort[0] = TRUE;
    nField[0] = nCol;
    bAscending[0] = TRUE;
    for (USHORT i=1; i<MAXSORT; i++)
    {
        bDoSort[i]    = FALSE;
        nField[i]     = 0;
        bAscending[i] = TRUE;
    }
}

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

void ScSortParam::MoveToDest()
{
    if (!bInplace)
    {
        SCsCOL nDifX = ((SCsCOL) nDestCol) - ((SCsCOL) nCol1);
        SCsROW nDifY = ((SCsROW) nDestRow) - ((SCsROW) nRow1);

        nCol1 = sal::static_int_cast<SCCOL>( nCol1 + nDifX );
        nRow1 = sal::static_int_cast<SCROW>( nRow1 + nDifY );
        nCol2 = sal::static_int_cast<SCCOL>( nCol2 + nDifX );
        nRow2 = sal::static_int_cast<SCROW>( nRow2 + nDifY );
        for (USHORT i=0; i<MAXSORT; i++)
            if (bByRow)
                nField[i] += nDifX;
            else
                nField[i] += nDifY;

        bInplace = TRUE;
    }
    else
    {
        DBG_ERROR("MoveToDest, bInplace == TRUE");
    }
}

<commit_msg>INTEGRATION: CWS changefileheader (1.7.88); FILE MERGED 2008/04/01 15:29:54 thb 1.7.88.2: #i85898# Stripping all external header guards 2008/03/31 17:13:53 rt 1.7.88.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: sortparam.cxx,v $
 * $Revision: 1.8 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

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

#include "sortparam.hxx"
#include "global.hxx"
#include "address.hxx"
#include <tools/debug.hxx>

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

ScSortParam::ScSortParam()
{
    Clear();
}

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

ScSortParam::ScSortParam( const ScSortParam& r ) :
        nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),
        bHasHeader(r.bHasHeader),bByRow(r.bByRow),bCaseSens(r.bCaseSens),
        bUserDef(r.bUserDef),nUserIndex(r.nUserIndex),bIncludePattern(r.bIncludePattern),
        bInplace(r.bInplace),
        nDestTab(r.nDestTab),nDestCol(r.nDestCol),nDestRow(r.nDestRow),
        aCollatorLocale( r.aCollatorLocale ), aCollatorAlgorithm( r.aCollatorAlgorithm )
{
    for (USHORT i=0; i<MAXSORT; i++)
    {
        bDoSort[i]    = r.bDoSort[i];
        nField[i]     = r.nField[i];
        bAscending[i] = r.bAscending[i];
    }
}

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

void ScSortParam::Clear()
{
    nCol1=nCol2=nDestCol = 0;
    nRow1=nRow2=nDestRow = 0;
    nCompatHeader = 2;
    nDestTab = 0;
    nUserIndex = 0;
    bHasHeader=bCaseSens=bUserDef = FALSE;
    bByRow=bIncludePattern=bInplace = TRUE;
    aCollatorLocale = ::com::sun::star::lang::Locale();
    aCollatorAlgorithm.Erase();

    for (USHORT i=0; i<MAXSORT; i++)
    {
        bDoSort[i]    = FALSE;
        nField[i]     = 0;
        bAscending[i] = TRUE;
    }
}

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

ScSortParam& ScSortParam::operator=( const ScSortParam& r )
{
    nCol1           = r.nCol1;
    nRow1           = r.nRow1;
    nCol2           = r.nCol2;
    nRow2           = r.nRow2;
    bHasHeader      = r.bHasHeader;
    bCaseSens       = r.bCaseSens;
    bByRow          = r.bByRow;
    bUserDef        = r.bUserDef;
    nUserIndex      = r.nUserIndex;
    bIncludePattern = r.bIncludePattern;
    bInplace        = r.bInplace;
    nDestTab        = r.nDestTab;
    nDestCol        = r.nDestCol;
    nDestRow        = r.nDestRow;
    aCollatorLocale         = r.aCollatorLocale;
    aCollatorAlgorithm      = r.aCollatorAlgorithm;

    for (USHORT i=0; i<MAXSORT; i++)
    {
        bDoSort[i]    = r.bDoSort[i];
        nField[i]     = r.nField[i];
        bAscending[i] = r.bAscending[i];
    }

    return *this;
}

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

BOOL ScSortParam::operator==( const ScSortParam& rOther ) const
{
    BOOL bEqual = FALSE;
    // Anzahl der Sorts gleich?
    USHORT nLast      = 0;
    USHORT nOtherLast = 0;
    while ( bDoSort[nLast++] && nLast < MAXSORT );
    while ( rOther.bDoSort[nOtherLast++] && nOtherLast < MAXSORT );
    nLast--;
    nOtherLast--;
    if (   (nLast           == nOtherLast)
        && (nCol1           == rOther.nCol1)
        && (nRow1           == rOther.nRow1)
        && (nCol2           == rOther.nCol2)
        && (nRow2           == rOther.nRow2)
        && (bHasHeader      == rOther.bHasHeader)
        && (bByRow          == rOther.bByRow)
        && (bCaseSens       == rOther.bCaseSens)
        && (bUserDef        == rOther.bUserDef)
        && (nUserIndex      == rOther.nUserIndex)
        && (bIncludePattern == rOther.bIncludePattern)
        && (bInplace        == rOther.bInplace)
        && (nDestTab        == rOther.nDestTab)
        && (nDestCol        == rOther.nDestCol)
        && (nDestRow        == rOther.nDestRow)
        && (aCollatorLocale.Language    == rOther.aCollatorLocale.Language)
        && (aCollatorLocale.Country     == rOther.aCollatorLocale.Country)
        && (aCollatorLocale.Variant     == rOther.aCollatorLocale.Variant)
        && (aCollatorAlgorithm          == rOther.aCollatorAlgorithm)
        )
    {
        bEqual = TRUE;
        for ( USHORT i=0; i<=nLast && bEqual; i++ )
        {
            bEqual = (nField[i] == rOther.nField[i]) && (bAscending[i]  == rOther.bAscending[i]);
        }
    }
    return bEqual;
}

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

ScSortParam::ScSortParam( const ScSubTotalParam& rSub, const ScSortParam& rOld ) :
        nCol1(rSub.nCol1),nRow1(rSub.nRow1),nCol2(rSub.nCol2),nRow2(rSub.nRow2),
        bHasHeader(TRUE),bByRow(TRUE),bCaseSens(rSub.bCaseSens),
        bUserDef(rSub.bUserDef),nUserIndex(rSub.nUserIndex),bIncludePattern(rSub.bIncludePattern),
        bInplace(TRUE),
        nDestTab(0),nDestCol(0),nDestRow(0),
        aCollatorLocale( rOld.aCollatorLocale ), aCollatorAlgorithm( rOld.aCollatorAlgorithm )
{
    USHORT nNewCount = 0;
    USHORT i;

    //  zuerst die Gruppen aus den Teilergebnissen
    if (rSub.bDoSort)
        for (i=0; i<MAXSUBTOTAL; i++)
            if (rSub.bGroupActive[i])
            {
                if (nNewCount < MAXSORT)
                {
                    bDoSort[nNewCount]    = TRUE;
                    nField[nNewCount]     = rSub.nField[i];
                    bAscending[nNewCount] = rSub.bAscending;
                    ++nNewCount;
                }
            }

    //  dann dahinter die alten Einstellungen
    for (i=0; i<MAXSORT; i++)
        if (rOld.bDoSort[i])
        {
            SCCOLROW nThisField = rOld.nField[i];
            BOOL bDouble = FALSE;
            for (USHORT j=0; j<nNewCount; j++)
                if ( nField[j] == nThisField )
                    bDouble = TRUE;
            if (!bDouble)               // ein Feld nicht zweimal eintragen
            {
                if (nNewCount < MAXSORT)
                {
                    bDoSort[nNewCount]    = TRUE;
                    nField[nNewCount]     = nThisField;
                    bAscending[nNewCount] = rOld.bAscending[i];
                    ++nNewCount;
                }
            }
        }

    for (i=nNewCount; i<MAXSORT; i++)       // Rest loeschen
    {
        bDoSort[i]    = FALSE;
        nField[i]     = 0;
        bAscending[i] = TRUE;
    }
}

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

ScSortParam::ScSortParam( const ScQueryParam& rParam, SCCOL nCol ) :
        nCol1(nCol),nRow1(rParam.nRow1),nCol2(nCol),nRow2(rParam.nRow2),
        bHasHeader(rParam.bHasHeader),bByRow(TRUE),bCaseSens(rParam.bCaseSens),
//! TODO: what about Locale and Algorithm?
        bUserDef(FALSE),nUserIndex(0),bIncludePattern(FALSE),
        bInplace(TRUE),
        nDestTab(0),nDestCol(0),nDestRow(0)
{
    bDoSort[0] = TRUE;
    nField[0] = nCol;
    bAscending[0] = TRUE;
    for (USHORT i=1; i<MAXSORT; i++)
    {
        bDoSort[i]    = FALSE;
        nField[i]     = 0;
        bAscending[i] = TRUE;
    }
}

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

void ScSortParam::MoveToDest()
{
    if (!bInplace)
    {
        SCsCOL nDifX = ((SCsCOL) nDestCol) - ((SCsCOL) nCol1);
        SCsROW nDifY = ((SCsROW) nDestRow) - ((SCsROW) nRow1);

        nCol1 = sal::static_int_cast<SCCOL>( nCol1 + nDifX );
        nRow1 = sal::static_int_cast<SCROW>( nRow1 + nDifY );
        nCol2 = sal::static_int_cast<SCCOL>( nCol2 + nDifX );
        nRow2 = sal::static_int_cast<SCROW>( nRow2 + nDifY );
        for (USHORT i=0; i<MAXSORT; i++)
            if (bByRow)
                nField[i] += nDifX;
            else
                nField[i] += nDifY;

        bInplace = TRUE;
    }
    else
    {
        DBG_ERROR("MoveToDest, bInplace == TRUE");
    }
}

<|endoftext|>


<commit_before><commit_msg>GPU Calc: Fixed accuracy bug of BitAnd<commit_after><|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sc.hxx"
#include "xiname.hxx"
#include "rangenam.hxx"
#include "xistream.hxx"

// for formula compiler
#include "excform.hxx"
// for filter manager
#include "excimp8.hxx"
#include "scextopt.hxx"
#include "document.hxx"
// ============================================================================
// *** Implementation ***
// ============================================================================

XclImpName::XclImpName( XclImpStream& rStrm, sal_uInt16 nXclNameIdx ) :
    XclImpRoot( rStrm.GetRoot() ),
    mpScData( 0 ),
    mcBuiltIn( EXC_BUILTIN_UNKNOWN ),
    mnScTab( SCTAB_MAX ),
    mbFunction( false ),
    mbVBName( false )
{
    ExcelToSc& rFmlaConv = GetOldFmlaConverter();

    // 1) *** read data from stream *** ---------------------------------------

    sal_uInt16 nFlags = 0, nFmlaSize = 0, nExtSheet = EXC_NAME_GLOBAL, nXclTab = EXC_NAME_GLOBAL;
    sal_uInt8 nNameLen = 0, nShortCut;

    switch( GetBiff() )
    {
        case EXC_BIFF2:
        {
            sal_uInt8 nFlagsBiff2;
            rStrm >> nFlagsBiff2;
            rStrm.Ignore( 1 );
            rStrm >> nShortCut >> nNameLen;
            nFmlaSize = rStrm.ReaduInt8();
            ::set_flag( nFlags, EXC_NAME_FUNC, ::get_flag( nFlagsBiff2, EXC_NAME2_FUNC ) );
        }
        break;

        case EXC_BIFF3:
        case EXC_BIFF4:
        {
            rStrm >> nFlags >> nShortCut >> nNameLen >> nFmlaSize;
        }
        break;

        case EXC_BIFF5:
        case EXC_BIFF8:
        {
            rStrm >> nFlags >> nShortCut >> nNameLen >> nFmlaSize >> nExtSheet >> nXclTab;
            rStrm.Ignore( 4 );
        }
        break;

        default: DBG_ERROR_BIFF();
    }

    if( GetBiff() <= EXC_BIFF5 )
        maXclName = rStrm.ReadRawByteString( nNameLen );
    else
        maXclName = rStrm.ReadUniString( nNameLen );

    // 2) *** convert sheet index and name *** --------------------------------

    // functions and VBA
    mbFunction = ::get_flag( nFlags, EXC_NAME_FUNC );
    mbVBName = ::get_flag( nFlags, EXC_NAME_VB );

    // get built-in name, or convert characters invalid in Calc
    bool bBuiltIn = ::get_flag( nFlags, EXC_NAME_BUILTIN );

    // special case for BIFF5 filter range - name appears as plain text without built-in flag
    if( (GetBiff() == EXC_BIFF5) && (maXclName == XclTools::GetXclBuiltInDefName( EXC_BUILTIN_FILTERDATABASE )) )
    {
        bBuiltIn = true;
        maXclName.Assign( EXC_BUILTIN_FILTERDATABASE );
    }

    // convert Excel name to Calc name
    if( mbVBName )
    {
        // VB macro name
        maScName = maXclName;
    }
    else if( bBuiltIn )
    {
        // built-in name
        if( maXclName.Len() )
            mcBuiltIn = maXclName.GetChar( 0 );
        if( mcBuiltIn == '?' )      // NUL character is imported as '?'
            mcBuiltIn = '\0';
        maScName = XclTools::GetBuiltInDefName( mcBuiltIn );
    }
    else
    {
        // any other name
        maScName = maXclName;
        ScfTools::ConvertToScDefinedName( maScName );
    }
    rtl::OUString aRealOrigName = maScName;

    // add index for local names
    if( nXclTab != EXC_NAME_GLOBAL )
    {
        sal_uInt16 nUsedTab = (GetBiff() == EXC_BIFF8) ? nXclTab : nExtSheet;
        // do not rename sheet-local names by default, this breaks VBA scripts
//        maScName.Append( '_' ).Append( String::CreateFromInt32( nUsedTab ) );
        // TODO: may not work for BIFF5, handle skipped sheets (all BIFF)
        mnScTab = static_cast< SCTAB >( nUsedTab - 1 );
    }

    // 3) *** convert the name definition formula *** -------------------------

    rFmlaConv.Reset();
    const ScTokenArray* pTokArr = 0; // pointer to token array, owned by rFmlaConv
    RangeType nNameType = RT_NAME;

    if( ::get_flag( nFlags, EXC_NAME_BIG ) )
    {
        // special, unsupported name
        rFmlaConv.GetDummy( pTokArr );
    }
    else if( bBuiltIn )
    {
        SCsTAB const nLocalTab = (nXclTab == EXC_NAME_GLOBAL) ? SCTAB_MAX : (nXclTab - 1);

        // --- print ranges or title ranges ---
        rStrm.PushPosition();
        switch( mcBuiltIn )
        {
            case EXC_BUILTIN_PRINTAREA:
                if( rFmlaConv.Convert( GetPrintAreaBuffer(), rStrm, nFmlaSize, nLocalTab, FT_RangeName ) == ConvOK )
                    nNameType |= RT_PRINTAREA;
            break;
            case EXC_BUILTIN_PRINTTITLES:
                if( rFmlaConv.Convert( GetTitleAreaBuffer(), rStrm, nFmlaSize, nLocalTab, FT_RangeName ) == ConvOK )
                    nNameType |= RT_COLHEADER | RT_ROWHEADER;
            break;
        }
        rStrm.PopPosition();

        // --- name formula ---
        // JEG : double check this.  It is clearly false for normal names
        //  but some of the builtins (sheettitle?) might be able to handle arrays
        rFmlaConv.Convert( pTokArr, rStrm, nFmlaSize, false, FT_RangeName );

        // --- auto or advanced filter ---
        if( (GetBiff() == EXC_BIFF8) && pTokArr && bBuiltIn )
        {
            ScRange aRange;
            if( pTokArr->IsReference( aRange ) )
            {
                switch( mcBuiltIn )
                {
                    case EXC_BUILTIN_FILTERDATABASE:
                        GetFilterManager().Insert( &GetOldRoot(), aRange);
                    break;
                    case EXC_BUILTIN_CRITERIA:
                        GetFilterManager().AddAdvancedRange( aRange );
                        nNameType |= RT_CRITERIA;
                    break;
                    case EXC_BUILTIN_EXTRACT:
                        if( pTokArr->IsValidReference( aRange ) )
                            GetFilterManager().AddExtractPos( aRange );
                    break;
                }
            }
        }
    }
    else if( nFmlaSize > 0 )
    {
        // regular defined name
        rFmlaConv.Convert( pTokArr, rStrm, nFmlaSize, true, FT_RangeName );
    }

    // 4) *** create a defined name in the Calc document *** ------------------

    // do not ignore hidden names (may be regular names created by VBA scripts)
    if( pTokArr /*&& (bBuiltIn || !::get_flag( nFlags, EXC_NAME_HIDDEN ))*/ && !mbFunction && !mbVBName )
    {
        // create the Calc name data
        ScRangeData* pData = new ScRangeData( GetDocPtr(), maScName, *pTokArr, ScAddress(), nNameType );
        pData->GuessPosition();             // calculate base position for relative refs
        pData->SetIndex( nXclNameIdx );     // used as unique identifier in formulas
        if (nXclTab == EXC_NAME_GLOBAL)
            GetDoc().GetRangeName()->insert(pData);
        else
        {
            ScRangeName* pLocalNames = GetDoc().GetRangeName(mnScTab);
            if (pLocalNames)
                pLocalNames->insert(pData);

            if (GetBiff() == EXC_BIFF8)
            {
                ScRange aRange;
                // discard deleted ranges ( for the moment at least )
                if ( pData->IsValidReference( aRange ) )
                {
                    GetExtDocOptions().GetOrCreateTabSettings( nXclTab );
                }
            }
        }
        mpScData = pData;                   // cache for later use
    }
}

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

XclImpNameManager::XclImpNameManager( const XclImpRoot& rRoot ) :
    XclImpRoot( rRoot )
{
}

void XclImpNameManager::ReadName( XclImpStream& rStrm )
{
    sal_uLong nCount = maNameList.size();
    if( nCount < 0xFFFF )
        maNameList.push_back( new XclImpName( rStrm, static_cast< sal_uInt16 >( nCount + 1 ) ) );
}

const XclImpName* XclImpNameManager::FindName( const String& rXclName, SCTAB nScTab ) const
{
    const XclImpName* pGlobalName = 0;   // a found global name
    const XclImpName* pLocalName = 0;    // a found local name
    for( XclImpNameList::const_iterator itName = maNameList.begin(); itName != maNameList.end() && !pLocalName; ++itName )
    {
        if( itName->GetXclName() == rXclName )
        {
            if( itName->GetScTab() == nScTab )
                pLocalName = &(*itName);
            else if( itName->IsGlobal() )
                pGlobalName = &(*itName);
        }
    }
    return pLocalName ? pLocalName : pGlobalName;
}

const XclImpName* XclImpNameManager::GetName( sal_uInt16 nXclNameIdx ) const
{
    OSL_ENSURE( nXclNameIdx > 0, "XclImpNameManager::GetName - index must be >0" );
    return ( nXclNameIdx >= maNameList.size() ) ? NULL : &(maNameList.at( nXclNameIdx - 1 ));
}

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

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>fix for fdo#38204: formulas with range names were not imported correctly<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sc.hxx"
#include "xiname.hxx"
#include "rangenam.hxx"
#include "xistream.hxx"

// for formula compiler
#include "excform.hxx"
// for filter manager
#include "excimp8.hxx"
#include "scextopt.hxx"
#include "document.hxx"
// ============================================================================
// *** Implementation ***
// ============================================================================

XclImpName::XclImpName( XclImpStream& rStrm, sal_uInt16 nXclNameIdx ) :
    XclImpRoot( rStrm.GetRoot() ),
    mpScData( 0 ),
    mcBuiltIn( EXC_BUILTIN_UNKNOWN ),
    mnScTab( SCTAB_MAX ),
    mbFunction( false ),
    mbVBName( false )
{
    ExcelToSc& rFmlaConv = GetOldFmlaConverter();

    // 1) *** read data from stream *** ---------------------------------------

    sal_uInt16 nFlags = 0, nFmlaSize = 0, nExtSheet = EXC_NAME_GLOBAL, nXclTab = EXC_NAME_GLOBAL;
    sal_uInt8 nNameLen = 0, nShortCut;

    switch( GetBiff() )
    {
        case EXC_BIFF2:
        {
            sal_uInt8 nFlagsBiff2;
            rStrm >> nFlagsBiff2;
            rStrm.Ignore( 1 );
            rStrm >> nShortCut >> nNameLen;
            nFmlaSize = rStrm.ReaduInt8();
            ::set_flag( nFlags, EXC_NAME_FUNC, ::get_flag( nFlagsBiff2, EXC_NAME2_FUNC ) );
        }
        break;

        case EXC_BIFF3:
        case EXC_BIFF4:
        {
            rStrm >> nFlags >> nShortCut >> nNameLen >> nFmlaSize;
        }
        break;

        case EXC_BIFF5:
        case EXC_BIFF8:
        {
            rStrm >> nFlags >> nShortCut >> nNameLen >> nFmlaSize >> nExtSheet >> nXclTab;
            rStrm.Ignore( 4 );
        }
        break;

        default: DBG_ERROR_BIFF();
    }

    if( GetBiff() <= EXC_BIFF5 )
        maXclName = rStrm.ReadRawByteString( nNameLen );
    else
        maXclName = rStrm.ReadUniString( nNameLen );

    // 2) *** convert sheet index and name *** --------------------------------

    // functions and VBA
    mbFunction = ::get_flag( nFlags, EXC_NAME_FUNC );
    mbVBName = ::get_flag( nFlags, EXC_NAME_VB );

    // get built-in name, or convert characters invalid in Calc
    bool bBuiltIn = ::get_flag( nFlags, EXC_NAME_BUILTIN );

    // special case for BIFF5 filter range - name appears as plain text without built-in flag
    if( (GetBiff() == EXC_BIFF5) && (maXclName == XclTools::GetXclBuiltInDefName( EXC_BUILTIN_FILTERDATABASE )) )
    {
        bBuiltIn = true;
        maXclName.Assign( EXC_BUILTIN_FILTERDATABASE );
    }

    // convert Excel name to Calc name
    if( mbVBName )
    {
        // VB macro name
        maScName = maXclName;
    }
    else if( bBuiltIn )
    {
        // built-in name
        if( maXclName.Len() )
            mcBuiltIn = maXclName.GetChar( 0 );
        if( mcBuiltIn == '?' )      // NUL character is imported as '?'
            mcBuiltIn = '\0';
        maScName = XclTools::GetBuiltInDefName( mcBuiltIn );
    }
    else
    {
        // any other name
        maScName = maXclName;
        ScfTools::ConvertToScDefinedName( maScName );
    }
    rtl::OUString aRealOrigName = maScName;

    // add index for local names
    if( nXclTab != EXC_NAME_GLOBAL )
    {
        sal_uInt16 nUsedTab = (GetBiff() == EXC_BIFF8) ? nXclTab : nExtSheet;
        // do not rename sheet-local names by default, this breaks VBA scripts
//        maScName.Append( '_' ).Append( String::CreateFromInt32( nUsedTab ) );
        // TODO: may not work for BIFF5, handle skipped sheets (all BIFF)
        mnScTab = static_cast< SCTAB >( nUsedTab - 1 );
    }

    // 3) *** convert the name definition formula *** -------------------------

    rFmlaConv.Reset();
    const ScTokenArray* pTokArr = 0; // pointer to token array, owned by rFmlaConv
    RangeType nNameType = RT_NAME;

    if( ::get_flag( nFlags, EXC_NAME_BIG ) )
    {
        // special, unsupported name
        rFmlaConv.GetDummy( pTokArr );
    }
    else if( bBuiltIn )
    {
        SCsTAB const nLocalTab = (nXclTab == EXC_NAME_GLOBAL) ? SCTAB_MAX : (nXclTab - 1);

        // --- print ranges or title ranges ---
        rStrm.PushPosition();
        switch( mcBuiltIn )
        {
            case EXC_BUILTIN_PRINTAREA:
                if( rFmlaConv.Convert( GetPrintAreaBuffer(), rStrm, nFmlaSize, nLocalTab, FT_RangeName ) == ConvOK )
                    nNameType |= RT_PRINTAREA;
            break;
            case EXC_BUILTIN_PRINTTITLES:
                if( rFmlaConv.Convert( GetTitleAreaBuffer(), rStrm, nFmlaSize, nLocalTab, FT_RangeName ) == ConvOK )
                    nNameType |= RT_COLHEADER | RT_ROWHEADER;
            break;
        }
        rStrm.PopPosition();

        // --- name formula ---
        // JEG : double check this.  It is clearly false for normal names
        //  but some of the builtins (sheettitle?) might be able to handle arrays
        rFmlaConv.Convert( pTokArr, rStrm, nFmlaSize, false, FT_RangeName );

        // --- auto or advanced filter ---
        if( (GetBiff() == EXC_BIFF8) && pTokArr && bBuiltIn )
        {
            ScRange aRange;
            if( pTokArr->IsReference( aRange ) )
            {
                switch( mcBuiltIn )
                {
                    case EXC_BUILTIN_FILTERDATABASE:
                        GetFilterManager().Insert( &GetOldRoot(), aRange);
                    break;
                    case EXC_BUILTIN_CRITERIA:
                        GetFilterManager().AddAdvancedRange( aRange );
                        nNameType |= RT_CRITERIA;
                    break;
                    case EXC_BUILTIN_EXTRACT:
                        if( pTokArr->IsValidReference( aRange ) )
                            GetFilterManager().AddExtractPos( aRange );
                    break;
                }
            }
        }
    }
    else if( nFmlaSize > 0 )
    {
        // regular defined name
        rFmlaConv.Convert( pTokArr, rStrm, nFmlaSize, true, FT_RangeName );
    }

    // 4) *** create a defined name in the Calc document *** ------------------

    // do not ignore hidden names (may be regular names created by VBA scripts)
    if( pTokArr /*&& (bBuiltIn || !::get_flag( nFlags, EXC_NAME_HIDDEN ))*/ && !mbFunction && !mbVBName )
    {
        // create the Calc name data
        ScRangeData* pData = new ScRangeData( GetDocPtr(), maScName, *pTokArr, ScAddress(), nNameType );
        pData->GuessPosition();             // calculate base position for relative refs
        pData->SetIndex( nXclNameIdx );     // used as unique identifier in formulas
        if (nXclTab == EXC_NAME_GLOBAL)
            GetDoc().GetRangeName()->insert(pData);
        else
        {
            ScRangeName* pLocalNames = GetDoc().GetRangeName(mnScTab);
            if (pLocalNames)
                pLocalNames->insert(pData);

            if (GetBiff() == EXC_BIFF8)
            {
                ScRange aRange;
                // discard deleted ranges ( for the moment at least )
                if ( pData->IsValidReference( aRange ) )
                {
                    GetExtDocOptions().GetOrCreateTabSettings( nXclTab );
                }
            }
        }
        mpScData = pData;                   // cache for later use
    }
}

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

XclImpNameManager::XclImpNameManager( const XclImpRoot& rRoot ) :
    XclImpRoot( rRoot )
{
}

void XclImpNameManager::ReadName( XclImpStream& rStrm )
{
    sal_uLong nCount = maNameList.size();
    if( nCount < 0xFFFF )
        maNameList.push_back( new XclImpName( rStrm, static_cast< sal_uInt16 >( nCount + 1 ) ) );
}

const XclImpName* XclImpNameManager::FindName( const String& rXclName, SCTAB nScTab ) const
{
    const XclImpName* pGlobalName = 0;   // a found global name
    const XclImpName* pLocalName = 0;    // a found local name
    for( XclImpNameList::const_iterator itName = maNameList.begin(); itName != maNameList.end() && !pLocalName; ++itName )
    {
        if( itName->GetXclName() == rXclName )
        {
            if( itName->GetScTab() == nScTab )
                pLocalName = &(*itName);
            else if( itName->IsGlobal() )
                pGlobalName = &(*itName);
        }
    }
    return pLocalName ? pLocalName : pGlobalName;
}

const XclImpName* XclImpNameManager::GetName( sal_uInt16 nXclNameIdx ) const
{
    OSL_ENSURE( nXclNameIdx > 0, "XclImpNameManager::GetName - index must be >0" );
    return ( nXclNameIdx > maNameList.size() ) ? NULL : &(maNameList.at( nXclNameIdx - 1 ));
}

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

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: xeescher.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: kz $ $Date: 2005-01-14 12:09:01 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef SC_XEESCHER_HXX
#define SC_XEESCHER_HXX

#ifndef SC_XLESCHER_HXX
#include "xlescher.hxx"
#endif

#include "xcl97rec.hxx"

namespace com { namespace sun { namespace star {
    namespace script { struct ScriptEventDescriptor; }
} } }

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

class XclExpTokenArray;

/** Helper to manage controls linked to the sheet. */
class XclExpCtrlLinkHelper : protected XclExpRoot
{
public:
    explicit            XclExpCtrlLinkHelper( const XclExpRoot& rRoot );
    virtual             ~XclExpCtrlLinkHelper();

    /** Sets the address of the control's linked cell. */
    void                SetCellLink( const ScAddress& rCellLink );
    /** Sets the address of the control's linked source cell range. */
    void                SetSourceRange( const ScRange& rSrcRange );

protected:
    /** Returns the Excel token array of the cell link, or 0, if no link present. */
    inline const XclExpTokenArray* GetCellLinkTokArr() const { return mxCellLink.get(); }
    /** Returns the Excel token array of the source range, or 0, if no link present. */
    inline const XclExpTokenArray* GetSourceRangeTokArr() const { return mxSrcRange.get(); }
    /** Returns the number of entries in the source range, or 0, if no source set. */
    inline sal_uInt16   GetSourceEntryCount() const { return mnEntryCount; }

    /** Writes a formula with special style only valid in OBJ records. */
    void                WriteFormula( XclExpStream& rStrm, const XclExpTokenArray& rTokArr ) const;
    /** Writes a formula subrecord with special style only valid in OBJ records. */
    void                WriteFormulaSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId, const XclExpTokenArray& rTokArr ) const;

private:
    XclExpTokenArrayRef mxCellLink;     /// Formula for linked cell.
    XclExpTokenArrayRef mxSrcRange;     /// Formula for source data range.
    sal_uInt16          mnEntryCount;   /// Number of entries in source range.
};

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

#if EXC_EXP_OCX_CTRL

/** Represents an OBJ record for an OCX form control. */
class XclExpObjOcxCtrl : public XclObj, public XclExpCtrlLinkHelper
{
public:
    explicit            XclExpObjOcxCtrl(
                            const XclExpRoot& rRoot,
                            const ::com::sun::star::uno::Reference<
                                ::com::sun::star::drawing::XShape >& rxShape,
                            const ::com::sun::star::uno::Reference<
                                ::com::sun::star::awt::XControlModel >& rxCtrlModel,
                            const String& rClassName,
                            sal_uInt32 nStrmStart, sal_uInt32 nStrmSize );

private:
    virtual void        WriteSubRecs( XclExpStream& rStrm );

private:
    String              maClassName;        /// Class name of the control.
    sal_uInt32          mnStrmStart;        /// Start position in 'Ctls' stream.
    sal_uInt32          mnStrmSize;         /// Size in 'Ctls' stream.
};

#else

/** Represents an OBJ record for an TBX form control. */
class XclExpObjTbxCtrl : public XclObj, public XclExpCtrlLinkHelper
{
public:
    explicit            XclExpObjTbxCtrl(
                            const XclExpRoot& rRoot,
                            const ::com::sun::star::uno::Reference<
                                ::com::sun::star::drawing::XShape >& rxShape,
                            const ::com::sun::star::uno::Reference<
                                ::com::sun::star::awt::XControlModel >& rxCtrlModel );

    /** Sets the name of a macro attached to this control.
        @return  true = The passed event descriptor was valid, macro name has been found. */
    bool                SetMacroLink( const ::com::sun::star::script::ScriptEventDescriptor& rEvent );

private:
    virtual void        WriteSubRecs( XclExpStream& rStrm );

    /** Writes an ftMacro subrecord containing a macro link, or nothing, if no macro present. */
    void                WriteMacroSubRec( XclExpStream& rStrm );
    /** Writes a subrecord containing a cell link, or nothing, if no link present. */
    void                WriteCellLinkSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId );
    /** Writes the ftSbs sub structure containing scrollbar data. */
    void                WriteSbs( XclExpStream& rStrm );

private:
    ScfInt16Vec         maMultiSel;     /// Indexes of all selected entries in a multi selection.
    XclExpTokenArrayRef mxMacroLink;    /// Token array containing a link to an attached macro.
    sal_Int32           mnHeight;       /// Height of the control.
    sal_uInt16          mnState;        /// Checked/unchecked state.
    sal_Int16           mnLineCount;    /// Combobox dropdown line count.
    sal_Int16           mnSelEntry;     /// Selected entry in combobox (1-based).
    sal_Int16           mnScrollValue;  /// Scrollbar: Current value.
    sal_Int16           mnScrollMin;    /// Scrollbar: Minimum value.
    sal_Int16           mnScrollMax;    /// Scrollbar: Maximum value.
    sal_Int16           mnScrollStep;   /// Scrollbar: Single step.
    sal_Int16           mnScrollPage;   /// Scrollbar: Page step.
    bool                mbFlatButton;   /// False = 3D button style; True = Flat button style.
    bool                mbFlatBorder;   /// False = 3D border style; True = Flat border style.
    bool                mbMultiSel;     /// true = Multi selection in listbox.
    bool                mbScrollHor;    /// Scrollbar: true = horizontal.
};

#endif

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

/** Represents a NOTE record containing the relevant data of a cell note.

    NOTE records differ significantly in various BIFF versions. This class
    encapsulates all needed actions for each supported BIFF version.
    BIFF5/BIFF7: Stores the note text and generates a single or multiple NOTE
    records on saving.
    BIFF8: Creates the Escher object containing the drawing information and the
    note text.
 */
class XclExpNote : public XclExpRecord
{
public:
    /** Constructs a NOTE record from the passed note object and/or the text.
        @descr  The additional text will be separated from the note text with
            an empty line.
        @param rScPos  The Calc cell address of the note.
        @param pScNote  The Calc note object. May be 0 to create a note from rAddText only.
        @param rAddText  Additional text appended to the note text. */
    explicit            XclExpNote(
                            const XclExpRoot& rRoot,
                            const ScAddress& rScPos,
                            const ScPostIt* pScNote,
                            const String& rAddText );

    /** Writes the NOTE record, if the respective Escher object is present. */
    virtual void        Save( XclExpStream& rStrm );

private:
    /** Writes the body of the NOTE record. */
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclExpString        maAuthor;       /// Name of the author.
    ByteString          maNoteText;     /// Main text of the note (<=BIFF7).
    ScAddress           maScPos;        /// Calc cell address of the note.
    sal_uInt16          mnObjId;        /// Escher object ID (BIFF8).
    bool                mbVisible;      /// true = permanently visible.
};

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

#endif

<commit_msg>INTEGRATION: CWS ooo19126 (1.5.192); FILE MERGED 2005/09/05 15:02:50 rt 1.5.192.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: xeescher.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 19:27:52 $
 *
 *  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 SC_XEESCHER_HXX
#define SC_XEESCHER_HXX

#ifndef SC_XLESCHER_HXX
#include "xlescher.hxx"
#endif

#include "xcl97rec.hxx"

namespace com { namespace sun { namespace star {
    namespace script { struct ScriptEventDescriptor; }
} } }

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

class XclExpTokenArray;

/** Helper to manage controls linked to the sheet. */
class XclExpCtrlLinkHelper : protected XclExpRoot
{
public:
    explicit            XclExpCtrlLinkHelper( const XclExpRoot& rRoot );
    virtual             ~XclExpCtrlLinkHelper();

    /** Sets the address of the control's linked cell. */
    void                SetCellLink( const ScAddress& rCellLink );
    /** Sets the address of the control's linked source cell range. */
    void                SetSourceRange( const ScRange& rSrcRange );

protected:
    /** Returns the Excel token array of the cell link, or 0, if no link present. */
    inline const XclExpTokenArray* GetCellLinkTokArr() const { return mxCellLink.get(); }
    /** Returns the Excel token array of the source range, or 0, if no link present. */
    inline const XclExpTokenArray* GetSourceRangeTokArr() const { return mxSrcRange.get(); }
    /** Returns the number of entries in the source range, or 0, if no source set. */
    inline sal_uInt16   GetSourceEntryCount() const { return mnEntryCount; }

    /** Writes a formula with special style only valid in OBJ records. */
    void                WriteFormula( XclExpStream& rStrm, const XclExpTokenArray& rTokArr ) const;
    /** Writes a formula subrecord with special style only valid in OBJ records. */
    void                WriteFormulaSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId, const XclExpTokenArray& rTokArr ) const;

private:
    XclExpTokenArrayRef mxCellLink;     /// Formula for linked cell.
    XclExpTokenArrayRef mxSrcRange;     /// Formula for source data range.
    sal_uInt16          mnEntryCount;   /// Number of entries in source range.
};

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

#if EXC_EXP_OCX_CTRL

/** Represents an OBJ record for an OCX form control. */
class XclExpObjOcxCtrl : public XclObj, public XclExpCtrlLinkHelper
{
public:
    explicit            XclExpObjOcxCtrl(
                            const XclExpRoot& rRoot,
                            const ::com::sun::star::uno::Reference<
                                ::com::sun::star::drawing::XShape >& rxShape,
                            const ::com::sun::star::uno::Reference<
                                ::com::sun::star::awt::XControlModel >& rxCtrlModel,
                            const String& rClassName,
                            sal_uInt32 nStrmStart, sal_uInt32 nStrmSize );

private:
    virtual void        WriteSubRecs( XclExpStream& rStrm );

private:
    String              maClassName;        /// Class name of the control.
    sal_uInt32          mnStrmStart;        /// Start position in 'Ctls' stream.
    sal_uInt32          mnStrmSize;         /// Size in 'Ctls' stream.
};

#else

/** Represents an OBJ record for an TBX form control. */
class XclExpObjTbxCtrl : public XclObj, public XclExpCtrlLinkHelper
{
public:
    explicit            XclExpObjTbxCtrl(
                            const XclExpRoot& rRoot,
                            const ::com::sun::star::uno::Reference<
                                ::com::sun::star::drawing::XShape >& rxShape,
                            const ::com::sun::star::uno::Reference<
                                ::com::sun::star::awt::XControlModel >& rxCtrlModel );

    /** Sets the name of a macro attached to this control.
        @return  true = The passed event descriptor was valid, macro name has been found. */
    bool                SetMacroLink( const ::com::sun::star::script::ScriptEventDescriptor& rEvent );

private:
    virtual void        WriteSubRecs( XclExpStream& rStrm );

    /** Writes an ftMacro subrecord containing a macro link, or nothing, if no macro present. */
    void                WriteMacroSubRec( XclExpStream& rStrm );
    /** Writes a subrecord containing a cell link, or nothing, if no link present. */
    void                WriteCellLinkSubRec( XclExpStream& rStrm, sal_uInt16 nSubRecId );
    /** Writes the ftSbs sub structure containing scrollbar data. */
    void                WriteSbs( XclExpStream& rStrm );

private:
    ScfInt16Vec         maMultiSel;     /// Indexes of all selected entries in a multi selection.
    XclExpTokenArrayRef mxMacroLink;    /// Token array containing a link to an attached macro.
    sal_Int32           mnHeight;       /// Height of the control.
    sal_uInt16          mnState;        /// Checked/unchecked state.
    sal_Int16           mnLineCount;    /// Combobox dropdown line count.
    sal_Int16           mnSelEntry;     /// Selected entry in combobox (1-based).
    sal_Int16           mnScrollValue;  /// Scrollbar: Current value.
    sal_Int16           mnScrollMin;    /// Scrollbar: Minimum value.
    sal_Int16           mnScrollMax;    /// Scrollbar: Maximum value.
    sal_Int16           mnScrollStep;   /// Scrollbar: Single step.
    sal_Int16           mnScrollPage;   /// Scrollbar: Page step.
    bool                mbFlatButton;   /// False = 3D button style; True = Flat button style.
    bool                mbFlatBorder;   /// False = 3D border style; True = Flat border style.
    bool                mbMultiSel;     /// true = Multi selection in listbox.
    bool                mbScrollHor;    /// Scrollbar: true = horizontal.
};

#endif

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

/** Represents a NOTE record containing the relevant data of a cell note.

    NOTE records differ significantly in various BIFF versions. This class
    encapsulates all needed actions for each supported BIFF version.
    BIFF5/BIFF7: Stores the note text and generates a single or multiple NOTE
    records on saving.
    BIFF8: Creates the Escher object containing the drawing information and the
    note text.
 */
class XclExpNote : public XclExpRecord
{
public:
    /** Constructs a NOTE record from the passed note object and/or the text.
        @descr  The additional text will be separated from the note text with
            an empty line.
        @param rScPos  The Calc cell address of the note.
        @param pScNote  The Calc note object. May be 0 to create a note from rAddText only.
        @param rAddText  Additional text appended to the note text. */
    explicit            XclExpNote(
                            const XclExpRoot& rRoot,
                            const ScAddress& rScPos,
                            const ScPostIt* pScNote,
                            const String& rAddText );

    /** Writes the NOTE record, if the respective Escher object is present. */
    virtual void        Save( XclExpStream& rStrm );

private:
    /** Writes the body of the NOTE record. */
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclExpString        maAuthor;       /// Name of the author.
    ByteString          maNoteText;     /// Main text of the note (<=BIFF7).
    ScAddress           maScPos;        /// Calc cell address of the note.
    sal_uInt16          mnObjId;        /// Escher object ID (BIFF8).
    bool                mbVisible;      /// true = permanently visible.
};

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

#endif

<|endoftext|>


<commit_before>/*
 BSD 3-Clause License

Copyright (c) 2019-2020, bitsofcotton
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#if !defined(_P0_)

template <typename T> class P0 {
public:
  typedef SimpleVector<T> Vec;
  typedef SimpleVector<complex<T> > VecU;
  typedef SimpleMatrix<T> Mat;
  typedef SimpleMatrix<complex<T> > MatU;
  inline P0();
  inline P0(const int& range);
  inline ~P0();
  inline T next(const Vec& in);
  const Mat&  lpf(const int& size);
private:
  Vec pred;
  const MatU& seed(const int& size, const bool& idft);
  const Mat&  diff(const int& size);
  const Vec&  nextTaylor(const int& size, const int& step);
  const T&    Pi() const;
  const complex<T>& J() const;
};

template <typename T> inline P0<T>::P0() {
  ;
}

template <typename T> inline P0<T>::P0(const int& range) {
  assert(1 < range);
  const auto  look(1);
  // with convolution meaning, exchange diff and integrate.
  const auto& reverse(nextTaylor(range, - look));
  pred.resize(reverse.size());
  for(int i = 0; i < reverse.size(); i ++)
    pred[i] = reverse[reverse.size() - 1 - i];
  pred = lpf(range).transpose() * ((pred + nextTaylor(range, look)) / T(2));
}

template <typename T> inline P0<T>::~P0() {
  ;
}

template <typename T> inline T P0<T>::next(const Vec& in) {
  assert(pred.size() == in.size());
  return pred.dot(in);
}

template <typename T> const T& P0<T>::Pi() const {
  const static auto pi(atan2(T(1), T(1)) * T(4));
  return pi;
}

template <typename T> const complex<T>& P0<T>::J() const {
  const static auto i(complex<T>(T(0), T(1)));
  return i;
}

template <typename T> const typename P0<T>::MatU& P0<T>::seed(const int& size, const bool& f_idft) {
  assert(0 < size);
  static vector<MatU> dft;
  static vector<MatU> idft;
  if(dft.size() <= size)
    dft.resize(size + 1, MatU());
  if(idft.size() <= size)
    idft.resize(size + 1, MatU());
  if((!f_idft) &&  dft[size].rows() == size &&  dft[size].cols() == size)
    return dft[size];
  if(  f_idft  && idft[size].rows() == size && idft[size].cols() == size)
    return idft[size];
  auto& edft( dft[size]);
  auto& eidft(idft[size]);
  edft.resize(size, size);
  eidft.resize(size, size);
  for(int i = 0; i < edft.rows(); i ++)
    for(int j = 0; j < edft.cols(); j ++) {
      const auto theta(- T(2) * Pi() * T(i) * T(j) / T(edft.rows()));
      edft(i, j)  = complex<T>(cos(  theta), sin(  theta));
      eidft(i, j) = complex<T>(cos(- theta), sin(- theta)) / complex<T>(T(size));
    }
  if(f_idft)
    return eidft;
  return edft;
}

template <typename T> const typename P0<T>::Mat& P0<T>::diff(const int& size) {
  assert(0 < size);
  static vector<Mat> D;
  if(D.size() <= size)
    D.resize(size + 1, Mat());
  if(D[size].rows() == size && D[size].cols() == size)
    return D[size];
  auto& d(D[size]);
  d.resize(size, size);
  auto  DD(seed(size, false));
  DD.row(0) *= complex<T>(T(0));
  T nd(0);
  T ni(0);
  for(int i = 1; i < DD.rows(); i ++) {
    const auto phase(- J() * T(2) * Pi() * T(i) / T(DD.rows()));
    const auto phase2(complex<T>(T(1)) / phase);
    DD.row(i) *= phase;
    nd += abs(phase)  * abs(phase);
    ni += abs(phase2) * abs(phase2);
  }
  return d = (seed(size, true) * DD).template real<T>() * sqrt(sqrt(T(DD.rows() - 1) / (nd * ni)));
}

template <typename T> const typename P0<T>::Mat& P0<T>::lpf(const int& size) {
  assert(0 < size);
  static vector<Mat> L;
  if(L.size() <= size)
    L.resize(size + 1, Mat());
  if(L[size].rows() == size && L[size].cols() == size)
    return L[size];
  auto& l(L[size]);
  auto  ll(seed(size, false));
  for(int i = size / 2; i < size; i ++)
    ll.row(i) *= complex<T>(T(0));
  return l = (seed(size, true) * ll).template real<T>();
}

template <typename T> const typename P0<T>::Vec& P0<T>::nextTaylor(const int& size, const int& step) {
  assert(0 < size && (step == 1 || step == - 1));
  static vector<Vec> P;
  static vector<Vec> M;
  if(P.size() <= size)
    P.resize(size + 1, Vec());
  if(M.size() <= size)
    M.resize(size + 1, Vec());
  if(0 < step && P[size].size() == size)
    return P[size];
  if(step < 0 && M[size].size() == size)
    return M[size];
        auto& p(P[size]);
        auto& m(M[size]);
  const auto& D(diff(size));
        auto  ddm(D);
        auto  ddp(D);
  p.resize(size);
  for(int i = 0; i < p.size(); i ++)
    p[i] = T(0);
  m = p;
  p[p.size() - 1] = T(1);
  m[0] = T(1);
  for(int i = 2; 0 <= i; i ++) {
    const auto bp(p);
    const auto bm(m);
    p += ddp.row(ddp.rows() - 1);
    m += ddm.row(0);
    if(bm == m && bp == p)
      break;
    ddp = (D * ddp) * (  T(1) / T(i));
    ddm = (D * ddm) * (- T(1) / T(i));
  }
  if(0 < step)
    return p;
  return m;
}

#define _P0_
#endif

<commit_msg>fix last up.<commit_after>/*
 BSD 3-Clause License

Copyright (c) 2019-2020, bitsofcotton
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#if !defined(_P0_)

template <typename T> class P0 {
public:
  typedef SimpleVector<T> Vec;
  typedef SimpleVector<complex<T> > VecU;
  typedef SimpleMatrix<T> Mat;
  typedef SimpleMatrix<complex<T> > MatU;
  inline P0();
  inline P0(const int& range);
  inline ~P0();
  inline T next(const Vec& in);
  const Mat&  lpf(const int& size);
private:
  Vec pred;
  const MatU& seed(const int& size, const bool& idft);
  const Mat&  diff(const int& size);
  const Vec&  nextTaylor(const int& size, const int& step);
  const T&    Pi() const;
  const complex<T>& J() const;
};

template <typename T> inline P0<T>::P0() {
  ;
}

template <typename T> inline P0<T>::P0(const int& range) {
  assert(1 < range);
  const auto  look(1);
  // with convolution meaning, exchange diff and integrate.
  const auto& reverse(nextTaylor(range, - look));
  pred.resize(reverse.size());
  for(int i = 0; i < reverse.size(); i ++)
    pred[i] = reverse[reverse.size() - 1 - i];
  pred = lpf(range).transpose() * ((pred + nextTaylor(range, look)) / T(2));
}

template <typename T> inline P0<T>::~P0() {
  ;
}

template <typename T> inline T P0<T>::next(const Vec& in) {
  assert(pred.size() == in.size());
  return pred.dot(in);
}

template <typename T> const T& P0<T>::Pi() const {
  const static auto pi(atan2(T(1), T(1)) * T(4));
  return pi;
}

template <typename T> const complex<T>& P0<T>::J() const {
  const static auto i(complex<T>(T(0), T(1)));
  return i;
}

template <typename T> const typename P0<T>::MatU& P0<T>::seed(const int& size, const bool& f_idft) {
  assert(0 < size);
  static vector<MatU> dft;
  static vector<MatU> idft;
  if(dft.size() <= size)
    dft.resize(size + 1, MatU());
  if(idft.size() <= size)
    idft.resize(size + 1, MatU());
  if((!f_idft) &&  dft[size].rows() == size &&  dft[size].cols() == size)
    return dft[size];
  if(  f_idft  && idft[size].rows() == size && idft[size].cols() == size)
    return idft[size];
  auto& edft( dft[size]);
  auto& eidft(idft[size]);
  edft.resize(size, size);
  eidft.resize(size, size);
  for(int i = 0; i < edft.rows(); i ++)
    for(int j = 0; j < edft.cols(); j ++) {
      const auto theta(- T(2) * Pi() * T(i) * T(j) / T(edft.rows()));
      edft(i, j)  = complex<T>(cos(  theta), sin(  theta));
      eidft(i, j) = complex<T>(cos(- theta), sin(- theta)) / complex<T>(T(size));
    }
  if(f_idft)
    return eidft;
  return edft;
}

template <typename T> const typename P0<T>::Mat& P0<T>::diff(const int& size) {
  assert(0 < size);
  static vector<Mat> D;
  if(D.size() <= size)
    D.resize(size + 1, Mat());
  if(D[size].rows() == size && D[size].cols() == size)
    return D[size];
  auto& d(D[size]);
  d.resize(size, size);
  auto  DD(seed(size, false));
  DD.row(0) *= complex<T>(T(0));
  T nd(0);
  T ni(0);
  for(int i = 1; i < DD.rows(); i ++) {
    const auto phase(- J() * T(2) * Pi() * T(i) / T(DD.rows()));
    const auto phase2(complex<T>(T(1)) / phase);
    DD.row(i) *= phase;
    nd += abs(phase)  * abs(phase);
    ni += abs(phase2) * abs(phase2);
  }
  return d = (seed(size, true) * DD).template real<T>() * sqrt(sqrt(T(DD.rows() - 1) / (nd * ni)));
}

template <typename T> const typename P0<T>::Mat& P0<T>::lpf(const int& size) {
  assert(0 < size);
  static vector<Mat> L;
  if(L.size() <= size)
    L.resize(size + 1, Mat());
  if(L[size].rows() == size && L[size].cols() == size)
    return L[size];
  auto& l(L[size]);
  auto  ll(seed(size, false));
  for(int i = size / 2; i < size; i ++)
    ll.row(i) *= complex<T>(T(0));
  return l = (seed(size, true) * ll).template real<T>();
}

template <typename T> const typename P0<T>::Vec& P0<T>::nextTaylor(const int& size, const int& step) {
  assert(0 < size && (step == 1 || step == - 1));
  static vector<Vec> P;
  static vector<Vec> M;
  if(P.size() <= size)
    P.resize(size + 1, Vec());
  if(M.size() <= size)
    M.resize(size + 1, Vec());
  if(0 < step && P[size].size() == size)
    return P[size];
  if(step < 0 && M[size].size() == size)
    return M[size];
        auto& p(P[size]);
        auto& m(M[size]);
  const auto& D(diff(size));
        auto  ddp(  D);
        auto  ddm(- D);
  p.resize(size);
  for(int i = 0; i < p.size(); i ++)
    p[i] = T(0);
  m = p;
  p[p.size() - 1] = T(1);
  m[0] = T(1);
  for(int i = 2; 0 <= i; i ++) {
    const auto bp(p);
    const auto bm(m);
    p += ddp.row(ddp.rows() - 1);
    m += ddm.row(0);
    if(bm == m && bp == p)
      break;
    ddp = (D * ddp) * (  T(1) / T(i));
    ddm = (D * ddm) * (- T(1) / T(i));
  }
  if(0 < step)
    return p;
  return m;
}

#define _P0_
#endif

<|endoftext|>


<commit_before><commit_msg>sc: refactor ScDrawTextObjectBar::ExecuteAttr<commit_after><|endoftext|>


<commit_before>int main()
{

	//show message
    return 0;
}
<commit_msg>Update ex1_1.cpp<commit_after>int main()
{
    return 0;
}
<|endoftext|>