/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of xlslib -- A multiplatform, C/C++ library
* for dynamic generation of Excel(TM) files.
*
* xlslib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* xlslib 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 xlslib. If not, see .
*
* Copyright 2004 Yeico S. A. de C. V.
* Copyright 2008 David Hoerl
*
* $Source: /cvsroot/xlslib/xlslib/src/xlslib/extformat.cpp,v $
* $Revision: 1.2 $
* $Author: dhoerl $
* $Date: 2008/10/25 18:39:54 $
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* File description:
*
*
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include
#include
/*
**********************************
CExtFormat class implementation
**********************************
*/
using namespace std;
using namespace xlslib_core;
CExtFormat::CExtFormat(bool is_cell)
{
SetRecordType(RECTYPE_XF);
InitDummy(is_cell);
SetRecordLength(GetDataSize()-4);
}
CExtFormat::CExtFormat(xf_t* xfdef)
{
SetRecordType(RECTYPE_XF);
InitDummy(xfdef->IsCell());
SetRecordLength(GetDataSize()-4);
// Here initialize the record with the values from the input structure
SetFontIndex(xfdef->GetFontIndex());
SetFormatIndex(xfdef->GetFormatIndex());
SetHorizAlign(xfdef->GetHAlign());
SetVertAlign(xfdef->GetVAlign());
SetIndent(xfdef->GetIndent());
SetTxtOrientation(xfdef->GetTxtOrientation());
SetFGColorIndex(xfdef->GetFillFGColor());
SetBGColorIndex(xfdef->GetFillBGColor());
SetFillPattern(xfdef->GetFillStyle());
if(xfdef->IsLocked()) SetLocked();
if(xfdef->IsHidden()) SetHidden();
if(xfdef->IsWrap()) SetWrap();
SetBorder(BORDER_BOTTOM, xfdef->GetBorderStyle(BORDER_BOTTOM),
xfdef->GetBorderColor(BORDER_BOTTOM));
SetBorder(BORDER_TOP, xfdef->GetBorderStyle(BORDER_TOP),
xfdef->GetBorderColor(BORDER_TOP));
SetBorder(BORDER_LEFT, xfdef->GetBorderStyle(BORDER_LEFT),
xfdef->GetBorderColor(BORDER_LEFT));
SetBorder(BORDER_RIGHT, xfdef->GetBorderStyle(BORDER_RIGHT),
xfdef->GetBorderColor(BORDER_RIGHT));
}
CExtFormat::~CExtFormat()
{
}
/*
**********************************
**********************************
*/
void CExtFormat::InitDummy(bool is_cell)
{
// An style-XF record is set by default.
// Each field has to be modified individually before use it
//The default style is a dummy. The flags that indicate what the style affects (byte 11)
// are disabled (set to 1).
unsigned8_t xfdefault[] = {
#if VERSION_BIFF == VERSION_BIFF5
/*
Open Office offsets
0 2 4 6 8 10 12 14 16 18 20
0x00,0x00,0x00,0x00,0xf4,0xff,0x20,0xf0,0xc0,0x00,0x01,0x00,0x00,0x00,0x00,0x00 <- ORIGINAL
*/
0x00,0x00,0x00,0x00,0xf4,0xff,0x20,0xf0,0xc0,0x20,0x01,0x00,0x00,0x00,0x00,0x00,
// STYLE_XF | INDEX=0xFFF -> Style
// HALIGN -> General, VALIGN -> BOTTOM
// IGNORE TOP 4 bits (style issue)
// 0x40 Pattern Color, then lowest bit of 0x41 (next)
// 0x41 Pattern background color right shifted one bit
// Fill Pattern -> 1 Black (well, fully colored, not a pattern)
#else
0x00,0x00,0x00,0x00,0xf4,0xff,0x20,0x00,0x00,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0xc0,0x20
// STYLE_XF | INDEX=0xFFF -> Style
// HALIGN -> General, VALIGN -> BOTTOM
// IGNORE TOP 4 bits (style issue)
// Fill Pattern -> 1 Black, left shifted 2 bits
// 0x40 Pattern Color, then lowest bit of 0x41 (next)
// 0x41 Pattern background color right shifted one bit
#endif
};
AddDataArray(xfdefault, sizeof(xfdefault));
if(is_cell)
{
unsigned16_t value;
// Get the field where options are set
GetValue16From((signed16_t*)&value, XF_OFFSET_PROP);
// Set the cell's style parent to Normal
value &= (~XF_PROP_XFPARENT);
// Set the style = cell.
value &= (~XF_PROP_STYLE);
SetValueAt((signed16_t)value, XF_OFFSET_PROP);
// The cell doesn't heritage anything from its parent style
GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);
value &= (~(XF_ALIGN_ATRFONT|XF_ALIGN_ATRALC|XF_ALIGN_ATRBDR|XF_ALIGN_ATRPAT|XF_ALIGN_ATRPROT));
SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);
}
}
/*
**********************************
**********************************
*/
bool CExtFormat::IsCell()
{
unsigned16_t val;
GetValue16From((signed16_t*)&val, XF_OFFSET_PROP);
return(val&XF_PROP_STYLE?true:false);
}
/*
**********************************
**********************************
*/
void CExtFormat::SetFlag(unsigned16_t flag)
{
unsigned16_t value;
GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);
if(IsCell())
{
// Cells indicate that a characteristic is not equal
// from its parent with the flag set.
value |= flag;
}
else
{
// Styles indicate that a characteristic is
// being implemented with the flag cleared.
value &= (~flag);
}
SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);
}
/*
**********************************
**********************************
*/
void CExtFormat::ClearFlag(unsigned16_t flag)
{
unsigned16_t value;
GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);
if(!IsCell())
{
// Cells indicate that a characteristic is not equal
// from its parent with the flag set.
value |= flag;
}
else
{
// Styles indicate that a characteristic is
// being implemented with the flag cleared.
value &= (~flag);
}
SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);
}
/*
**********************************
**********************************
*/
int CExtFormat::SetFontIndex(unsigned16_t fontindex)
{
// Set the index value
int errcode = SetValueAt((signed16_t)fontindex, XF_OFFSET_FONT);
// Set the related flag.
SetFlag(XF_ALIGN_ATRFONT);
return errcode;
}
/*
**********************************
**********************************
*/
unsigned16_t CExtFormat::GetFontIndex(void)
{
unsigned16_t fontval;
GetValue16From((signed16_t*)&fontval, XF_OFFSET_FONT);
return(fontval);
}
/*
**********************************
**********************************
*/
int CExtFormat::SetFormatIndex(unsigned16_t formatindex)
{
// Set the index value
int errcode = SetValueAt((signed16_t)formatindex, XF_OFFSET_FORMAT);
// Set the related flag.
SetFlag(XF_ALIGN_ATRNUM);
return errcode;
}
/*
**********************************
**********************************
*/
unsigned16_t CExtFormat::GetFormatIndex(void)
{
unsigned16_t formatval;
GetValue16From((signed16_t*)&formatval, XF_OFFSET_FORMAT);
return(formatval);
}
/*
**********************************
**********************************
*/
void CExtFormat::SetLocked()
{
unsigned16_t value;
GetValue16From((signed16_t*)&value, XF_OFFSET_PROP);
value |= XF_PROP_LOCKED;
SetValueAt((signed16_t)value, XF_OFFSET_PROP);
SetFlag(XF_ALIGN_ATRPROT);
}
/*
**********************************
**********************************
*/
void CExtFormat::SetHidden()
{
unsigned16_t value;
GetValue16From((signed16_t*)&value, XF_OFFSET_PROP);
value |= XF_PROP_HIDDEN;
SetValueAt((signed16_t)value, XF_OFFSET_PROP);
SetFlag(XF_ALIGN_ATRPROT);
}
/*
**********************************
**********************************
*/
void CExtFormat::SetHorizAlign(unsigned8_t alignval)
{
unsigned16_t value;
GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);
value = (value&(~XF_ALIGN_HORIZONTAL))|(alignval & XF_ALIGN_HORIZONTAL);
SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);
SetFlag(XF_ALIGN_ATRALC);
}
/*
**********************************
**********************************
*/
void CExtFormat::SetWrap()
{
unsigned16_t value;
GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);
value |= XF_ALIGN_WRAP;
SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);
SetFlag(XF_ALIGN_ATRALC);
}
#if VERSION_BIFF == VERSION_BIFF8
/*
**********************************
**********************************
*/
void CExtFormat::SetIndent(unsigned8_t indentval)
{
unsigned32_t value, mask;
if(indentval & XF_INDENT_LVL) {
mask = XF_INDENT_LVL;
} else
if(indentval & XF_INDENT_SHRINK2FIT) {
mask = XF_INDENT_SHRINK2FIT;
} else
if(indentval & (XF_INDENT_CONTEXT|XF_INDENT_L2R|XF_INDENT_R2L)) {
mask = XF_INDENT_DIR;
} else {
mask = XF_INDENT_LVL | XF_INDENT_SHRINK2FIT | XF_INDENT_DIR;
}
mask <<= XF_INDENT_SHIFTPOS;
GetValue32From((signed32_t*)&value, XF_OFFSET_ALIGN);
unsigned32_t indentval32 = (unsigned32_t)indentval << XF_INDENT_SHIFTPOS; // Place the option at the right bit position
value = (value&(~mask))|(indentval32 & mask);
SetValueAt((signed32_t)value, XF_OFFSET_ALIGN);
}
#endif
/*
**********************************
**********************************
*/
void CExtFormat::SetVertAlign(unsigned8_t alignval)
{
unsigned16_t value;
GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);
unsigned16_t alignval16 = alignval << XF_ALIGN_SHIFTPOS_VALIGN; // Place the option at the right bit position
value = (value&(~XF_ALIGN_VERTICAL))|(alignval16 & XF_ALIGN_VERTICAL);
SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);
SetFlag(XF_ALIGN_ATRALC);
}
/*
**********************************
**********************************
*/
void CExtFormat::SetTxtOrientation(unsigned8_t alignval)
{
unsigned16_t value;
GetValue16From((signed16_t*)&value, XF_OFFSET_ALIGN);
unsigned16_t alignval16 = alignval << XF_ORI_SHIFTPOS; // Place the option at the right bit position
value = (value&(~XF_ALIGN_ORIENTATION))|(alignval16 & XF_ALIGN_ORIENTATION);
SetValueAt((signed16_t)value, XF_OFFSET_ALIGN);
}
/*
**********************************
**********************************
*/
void CExtFormat::SetFGColorIndex(unsigned8_t color)
{
unsigned16_t value;
GetValue16From((signed16_t*)&value, XF_OFFSET_COLOR);
// value = (value&(~XF_COLOR_FOREGROUND))|(color & XF_COLOR_FOREGROUND);
// Clear the field for Foreground color
value &= (~XF_COLOR_FOREGROUND);
// Set the new color
value |= (color & XF_COLOR_FOREGROUND);
SetValueAt((signed16_t)value, XF_OFFSET_COLOR);
SetFlag(XF_ALIGN_ATRPAT);
}
/*
**********************************
**********************************
*/
void CExtFormat::SetBGColorIndex(unsigned8_t color)
{
unsigned16_t value;
GetValue16From((signed16_t*)&value, XF_OFFSET_COLOR);
unsigned16_t color16 = color << XF_COLOR_SHIFTPOS_BG;
// value = (value&(~XF_COLOR_FOREGROUND))|(color16 & XF_COLOR_FOREGROUND);
// Clear the field for Foreground color
value &= (~XF_COLOR_BACKGROUND);
// Set the new color
value |= (color16 & XF_COLOR_BACKGROUND);
SetValueAt((signed16_t)value, XF_OFFSET_COLOR);
SetFlag(XF_ALIGN_ATRPAT);
}
/*
**********************************
**********************************
*/
void CExtFormat::SetFillPattern(unsigned8_t pattern)
{
#if VERSION_BIFF == VERSION_BIFF5
unsigned16_t value;
GetValue16From((signed16_t*)&value, XF_OFFSET_BORDER0);
value = (value&(~XF_BORDER_FILLPATTERN))|(pattern & XF_BORDER_FILLPATTERN);
SetValueAt((signed16_t)value, XF_OFFSET_BORDER0);
SetFlag(XF_ALIGN_ATRPAT);
#else
unsigned32_t value, pattern32 = pattern;
GetValue32From((signed32_t*)&value, XF_OFFSET_BORDERB);
value &= ~XF_BORDER_FILLPATTERN;
pattern32 <<= XF_SHIFTPOS_FILLPATTERN;
value |= (pattern32 & XF_BORDER_FILLPATTERN);
SetValueAt((signed16_t)value, XF_OFFSET_BORDERB);
SetFlag(XF_ALIGN_ATRPAT);
#endif
}
/*
**********************************
**********************************
*/
void CExtFormat::SetBorder(border_side_t border, unsigned16_t style, unsigned16_t color)
{
switch(border)
{
case BORDER_BOTTOM:
{
#if VERSION_BIFF == VERSION_BIFF5
unsigned16_t value, color16 = color;
GetValue16From((signed16_t*)&value, XF_OFFSET_BORDER0);
value = (value&(~XF_BORDER_BOTTOMSTYLE))|
((style<= sizeof(unsigned64_t)) {
// xfcrc<<(unsigned64_t)font;
// } else {
xfcrc<<(unsigned64_t)font;
// }
xfcrc<<(unsigned32_t)format;
xfcrc<MarkUsed();
}
/*
**********************************
**********************************
*/
bool xf_t::IsUsed(void)
{
return(m_usage_counter != 0);
}
/*
**********************************
**********************************
*/
void xf_t::SetFont(font_t* fontidx)
{
if(fontidx != NULL)
fontidx->MarkUsed();
font = fontidx;
m_sigchanged = true;
}
font_t* xf_t::GetFont(void)
{
return font;
}
unsigned16_t xf_t::GetFontIndex(void)
{
if(font != NULL)
return font->GetIndex();
else
return 0x0000;
}
/*
**********************************
**********************************
*/
void xf_t::SetFormat(format_number_t formatidx){
format = formatidx;
m_sigchanged = true;
};
unsigned16_t xf_t::GetFormatIndex(void)
{
return xf_t::FORMAT_NUM_OPTIONS_TABLE[format];
};
format_number_t xf_t::GetFormat(void)
{
return format;
}
/*
**********************************
**********************************
*/
/* Cell option wrappers*/
void xf_t::SetBorderStyle(border_side_t side,
border_style_t style,
color_name_t color)
{
switch (side)
{
case BORDER_BOTTOM:
bottom_border_style = BORDERSTYLE_OPTIONS_TABLE[style];
bottom_border_color = COLOR_OPTIONS_TABLE[color];
break;
case BORDER_TOP:
top_border_style = BORDERSTYLE_OPTIONS_TABLE[style];
top_border_color = COLOR_OPTIONS_TABLE[color];
break;
case BORDER_LEFT:
left_border_style = BORDERSTYLE_OPTIONS_TABLE[style];
left_border_color = COLOR_OPTIONS_TABLE[color];
break;
case BORDER_RIGHT:
right_border_style = BORDERSTYLE_OPTIONS_TABLE[style];
right_border_color = COLOR_OPTIONS_TABLE[color];
break;
default:
// It cannot get here
break;
}
m_sigchanged = true;
}
/*
**********************************
**********************************
*/
unsigned8_t xf_t::GetBorderStyle(border_side_t side)
{
unsigned8_t ret_style = XF_BRDOPTION_NONE;
switch (side)
{
case BORDER_BOTTOM:
ret_style = bottom_border_style;
break;
case BORDER_TOP:
ret_style = top_border_style;
break;
case BORDER_LEFT:
ret_style = left_border_style;
break;
case BORDER_RIGHT:
ret_style = right_border_style;
break;
default:
// It cannot get here
break;
}
return ret_style;
}
/*
**********************************
**********************************
*/
unsigned8_t xf_t::GetBorderColor(border_side_t side)
{
unsigned8_t ret_color = XF_COLOR_CODE_BLACK;
switch (side)
{
case BORDER_BOTTOM:
ret_color = bottom_border_color;
break;
case BORDER_TOP:
ret_color = top_border_color;
break;
case BORDER_LEFT:
ret_color = left_border_color;
break;
case BORDER_RIGHT:
ret_color = right_border_color;
break;
default:
// It cannot get here
break;
}
return ret_color;
}
void xf_t::operator=(xf_t& right)
{
index = 0x0000;
font = right.font;
format = right.format;
halign = right.halign;
valign = right.valign;
indent = right.indent;
txtorientation = right.txtorientation;
fill_fgcolor = right.fill_fgcolor;
fill_bgcolor = right.fill_bgcolor;
fillstyle = right.fillstyle;
locked = right.locked;
hidden = right.hidden;
wrap = right.wrap;
is_cell = right.is_cell;
top_border_style = right.top_border_style;
top_border_color = right.top_border_color;
bottom_border_style = right.bottom_border_style;
bottom_border_color = right.bottom_border_color;
left_border_style = right.left_border_style;
left_border_color = right.left_border_color;
right_border_style = right.right_border_style;
right_border_color = right.right_border_color;
m_sigchanged = true;
}
/* Horizontal Align option wrappers*/
void xf_t::SetHAlign(halign_option_t ha_option)
{
halign = xf_t::HALIGN_OPTIONS_TABLE[ha_option];
m_sigchanged = true;
}
unsigned8_t xf_t::GetHAlign(void)
{
return halign;
}
/* Vertical Align option wrappers*/
void xf_t::SetVAlign(valign_option_t va_option)
{
valign = xf_t::VALIGN_OPTIONS_TABLE[va_option];
m_sigchanged = true;
}
unsigned8_t xf_t::GetVAlign(void)
{
return valign;
}
void xf_t::SetIndent(indent_option_t indent_option)
{
indent = xf_t::INDENT_OPTIONS_TABLE[indent_option];
m_sigchanged = true;
}
unsigned8_t xf_t::GetIndent(void)
{
return indent;
}
/* Text orientation option wrappers*/
void xf_t::SetTxtOrientation(txtori_option_t ori_option)
{
txtorientation = xf_t::TXTORI_OPTIONS_TABLE[ori_option];
m_sigchanged = true;
}
unsigned8_t xf_t::GetTxtOrientation(void)
{
return txtorientation;
}
/* Fill Foreground color option wrappers*/
void xf_t::SetFillFGColor(color_name_t color)
{
fill_fgcolor = xf_t::COLOR_OPTIONS_TABLE[color];
m_sigchanged = true;
}
unsigned8_t xf_t::GetFillFGColor(void)
{
return fill_fgcolor;
}
/* Fill Background color option wrappers*/
void xf_t::SetFillBGColor(color_name_t color)
{
fill_bgcolor = xf_t::COLOR_OPTIONS_TABLE[color];
m_sigchanged = true;
}
unsigned8_t xf_t::GetFillBGColor(void)
{
return fill_bgcolor;
}
/* Fill Style option wrappers*/
void xf_t::SetFillStyle(fill_option_t fill)
{
fillstyle = xf_t::FILL_OPTIONS_TABLE[fill];
m_sigchanged = true;
}
unsigned8_t xf_t::GetFillStyle(void)
{
return fillstyle;
}
/* Locked option wrappers*/
void xf_t::SetLocked(bool locked_opt)
{
locked = locked_opt;
m_sigchanged = true;
}
bool xf_t::IsLocked(void)
{
return locked;
}
/* Hidden option wrappers*/
void xf_t::SetHidden(bool hidden_opt)
{
hidden = hidden_opt;
m_sigchanged = true;
}
bool xf_t::IsHidden(void)
{
return hidden;
}
/* Wrap option wrappers*/
void xf_t::SetWrap(bool wrap_opt)
{
wrap = wrap_opt;
m_sigchanged = true;
};
bool xf_t::IsWrap(void)
{
return wrap;
};
/* Cell option wrappers*/
void xf_t::SetCellMode(bool cellmode)
{
is_cell = cellmode;
m_sigchanged = true;
}
bool xf_t::IsCell(void)
{
return is_cell;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* $Log: extformat.cpp,v $
* Revision 1.2 2008/10/25 18:39:54 dhoerl
* 2008
*
* Revision 1.1.1.1 2004/08/27 16:31:48 darioglz
* Initial Import.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */