/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) Yeico S. A. de C. V. * xlsLib -- A multiplatform, C++ library for dynamic generation of Excel (TM) * files. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Source: /cvsroot/xlslib/xlslib/src/oledoc/oledoc.cpp,v $ * $Revision: 1.2 $ * $Author: darioglz $ * $Date: 2004/09/01 00:47:04 $ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * File description: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "oledoc.h" using namespace std; using namespace xlslib_core; /* *********************************** COleDoc class implementation *********************************** */ const unsigned8_t COleDoc::OLE_FILETYPE[] = { 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1}; COleDoc::COleDoc() { } /* COleDoc::COleDoc(const string& file_name) { Open(file_name); } */ COleDoc::~COleDoc() { } /* *********************************** *********************************** */ int COleDoc::DumpHeader(signed32_t bat_count, unsigned32_t total_data_size) { int errcode = NO_ERRORS; int i; // [00]FILETYPE WriteByteArray(COleDoc::OLE_FILETYPE, /*(unsigned32_t)*/sizeof(COleDoc::OLE_FILETYPE)); // [08]UK1 WriteSigned32(HEADVAL_DFLT_UK1); // [0c]UK2 WriteSigned32(HEADVAL_DFLT_UK2); // [10]UK2b WriteSigned32(HEADVAL_DFLT_UK2b); // [14]UK3 WriteSigned32(HEADVAL_DFLT_UK3); // [18]UK4 WriteSigned16(HEADVAL_DFLT_UK4); // [1a]UK5 WriteSigned16(HEADVAL_DFLT_UK5); // [1c]UK6 WriteSigned16(HEADVAL_DFLT_UK6); // [1e]LOG_2_BIG_BLOCK WriteSigned16(HEADVAL_DFLT_LOG2_BIGBLOCK); // [20]LOG_2_SMALL_BLOCK WriteSigned32(HEADVAL_DFLT_LOG2_SMALLBLOCK); // [24]UK7 WriteSigned32(HEADVAL_DFLT_UK7); // [28]UK8 WriteSigned32(HEADVAL_DFLT_UK8); // [2c] BAT_COUNT (BBDEPOT NUM BLOCKS) WriteSigned32(bat_count); //[30] PROPERTIES_START_BLOCK // Since the big block depot will go immediately after the data, I need // to know the size of the data and the size of the BAT in blocks (prev) WriteSigned32(bat_count+total_data_size/(BIG_BLOCK_SIZE)); // [34] UK9 WriteSigned32(HEADVAL_DFLT_UK9); // [38] UK10 WriteSigned32(HEADVAL_DFLT_UK10); // [3c] SBAT_START // No small blocks will be used, so this is set to the default empty value WriteSigned32(HEADVAL_DFLT_SBAT_START); // [40] SBAT_BLOCKCOUNT_NUMBER // Use the default value WriteSigned32(HEADVAL_DFLT_SBAT_COUNT); // [44] XBAT_START // No extended BAT neither WriteSigned32(HEADVAL_DFLT_XBAT_START); // [48] XBAT_COUNT WriteSigned32(HEADVAL_DFLT_XBAT_COUNT); // [4C] BAT_ARRAY // The BAT_ARRAY shall be calculated from the number of BAT blocks and their position for(i=0; iGetType() == PTYPE_FILE) { for(DataList_Itor_t j = (*i)->GetDataPointer()->begin(); j != (*i)->GetDataPointer()->end(); j++) { WriteByteArray((*j)->GetBuffer(), (*j)->GetDataSize()); } } } return errcode; } /* *********************************** *********************************** */ int COleDoc::DumpDepots(unsigned32_t bat_blocks_count) { int errcode = NO_ERRORS; NodeList_t node_list; GetAllNodes(node_list); unsigned32_t bat_index = 0; for(NodeList_Itor_t node = node_list.begin(); node != node_list.end(); node++) { // The start block is set in the node. (*node)->SetStartBlock(bat_index); // Write the chain for this node element for(unsigned32_t i = 0; i < ((*node)->GetDataPointer()->GetDataSize()/BIG_BLOCK_SIZE - 1); i++) { WriteSigned32(++bat_index); } // Set the terminator number ++bat_index; WriteSigned32(BAT_END_CHAIN); } // Write the -3 number for every index in the BAT that references to some BAT block (uh!?) for(unsigned16_t i=0; i PROPERTY_MAX_NAME_LENGTH) name_size = PROPERTY_MAX_NAME_LENGTH; unsigned8_t size_unicode = (name_size+1)*2; if(*ppname_unicode != NULL) delete[] *ppname_unicode; *ppname_unicode = (char*)new unsigned8_t[size_unicode]; memset(*ppname_unicode, 0x00, size_unicode); for(int i=0; i<(size_unicode/2-1); i++) (*ppname_unicode)[2*i] = name[i]; return size_unicode; } /* *********************************** *********************************** */ int COleDoc::DumpNode(COleProp& node) { int errcode = NO_ERRORS; char* name_unicode = NULL; // Get the unicode name and its size signed16_t size_name = GetUnicodeName(node.GetName().c_str(), &name_unicode); // [00] PROPERTY_NAME WriteByteArray((const unsigned8_t*)name_unicode, size_name); // Fill the rest of the name field with 0x00 SerializeFixedArray(PROPERTY_DFLT_NOTUSED, PPTPOS_NAMELENGTH - size_name); // [40] NAME_SIZE WriteSigned16(size_name); // [42] PROPERTY_TYPE WriteByte(node.GetType()); // [43] NODE_COLOR WriteByte(node.GetColor()); // [44] PREVIOUS_PROP WriteSigned32(node.GetPreviousIndex()); // [48] NEXT_PROP WriteSigned32(node.GetNextIndex()); // [4c] CHILD_PROP WriteSigned32(node.GetChildIndex()); // Fill empty block SerializeFixedArray(PROPERTY_DFLT_NOTUSED, (PPTPOS_SECS1 - PPTPOS_UNUSED_EMPTY0)); //[64]...[70] // SECONDS_1, DAYS_2, SECONDS_2, DAYS_2 WriteSigned32(node.GetCreatedSecs()); WriteSigned32(node.GetCreatedDays()); WriteSigned32(node.GetModifiedDays()); WriteSigned32(node.GetModifiedSecs()); // [74] START_BLOCK WriteSigned32(node.GetStartBlock()); // [74] SIZE if(node.GetType() == PTYPE_FILE) WriteSigned32(node.GetSize()); else WriteSigned32(0); // A unused space: WriteSigned32(PROPERTY_DFLT_NOTUSED); delete[] name_unicode; name_unicode = NULL; return errcode; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * $Log: oledoc.cpp,v $ * Revision 1.2 2004/09/01 00:47:04 darioglz * + Modified to gain independence of target * * Revision 1.1.1.1 2004/08/27 16:31:43 darioglz * Initial Import. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */