1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
/* AbiSource
*
* Copyright (C) 2005 INdT
* Author: Daniel d'Andrada T. de Carvalho <daniel.carvalho@indt.org.br>
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*/
// Class definition include
#include "ODe_AutomaticStyles.h"
// Internal includes
#include "ODe_Common.h"
// Internal classes
#include "ODe_Style_Style.h"
#include "ODe_Style_PageLayout.h"
#include "ODe_Style_List.h"
/**
* Destructor
*/
ODe_AutomaticStyles::~ODe_AutomaticStyles() {
UT_GenericVector<ODe_Style_Style*>* pStyleVector;
UT_GenericVector<ODe_Style_PageLayout*>* pPageLayoutVector;
UT_GenericVector<ODe_Style_List*>* pListStyleVector;
pStyleVector = m_textStyles.enumerate();
UT_VECTOR_PURGEALL(ODe_Style_Style*, (*pStyleVector));
DELETEP(pStyleVector);
pStyleVector = m_paragraphStyles.enumerate();
UT_VECTOR_PURGEALL(ODe_Style_Style*, (*pStyleVector));
DELETEP(pStyleVector);
pStyleVector = m_sectionStyles.enumerate();
UT_VECTOR_PURGEALL(ODe_Style_Style*, (*pStyleVector));
DELETEP(pStyleVector);
pStyleVector = m_tableStyles.enumerate();
UT_VECTOR_PURGEALL(ODe_Style_Style*, (*pStyleVector));
DELETEP(pStyleVector);
pStyleVector = m_tableColumnStyles.enumerate();
UT_VECTOR_PURGEALL(ODe_Style_Style*, (*pStyleVector));
DELETEP(pStyleVector);
pStyleVector = m_tableRowStyles.enumerate();
UT_VECTOR_PURGEALL(ODe_Style_Style*, (*pStyleVector));
DELETEP(pStyleVector);
pStyleVector = m_tableCellStyles.enumerate();
UT_VECTOR_PURGEALL(ODe_Style_Style*, (*pStyleVector));
DELETEP(pStyleVector);
pStyleVector = m_graphicStyles.enumerate();
UT_VECTOR_PURGEALL(ODe_Style_Style*, (*pStyleVector));
DELETEP(pStyleVector);
pPageLayoutVector = m_pageLayouts.enumerate();
UT_VECTOR_PURGEALL(ODe_Style_PageLayout*, (*pPageLayoutVector));
DELETEP(pPageLayoutVector);
pListStyleVector = m_listStyles.enumerate();
UT_VECTOR_PURGEALL(ODe_Style_List*, (*pListStyleVector));
DELETEP(pListStyleVector);
}
/**
* See ODe_AutomaticStyles::_storeStyle
*/
void ODe_AutomaticStyles::storeTextStyle(ODe_Style_Style*& rpTextStyle) {
_storeStyle(rpTextStyle, m_textStyles, "T");
}
/**
* See ODe_AutomaticStyles::_storeStyle
*/
void ODe_AutomaticStyles::storeParagraphStyle(ODe_Style_Style*& rpParagraphStyle) {
_storeStyle(rpParagraphStyle, m_paragraphStyles, "P");
}
/**
* See ODe_AutomaticStyles::_storeStyle
*/
void ODe_AutomaticStyles::storeSectionStyle(ODe_Style_Style*& rpSectionStyle) {
_storeStyle(rpSectionStyle, m_sectionStyles, "Sect");
}
/**
* See ODe_AutomaticStyles::_storeStyle
*/
void ODe_AutomaticStyles::storeGraphicStyle(ODe_Style_Style*& rpGraphicStyle) {
_storeStyle(rpGraphicStyle, m_graphicStyles, "graphic");
}
/**
*
*/
ODe_Style_Style* ODe_AutomaticStyles::addTableStyle(
const UT_UTF8String& rStyleName) {
ODe_Style_Style* pStyle;
pStyle = new ODe_Style_Style();
pStyle->setStyleName(rStyleName);
pStyle->setFamily("table");
m_tableStyles.insert(rStyleName.utf8_str(), pStyle);
return pStyle;
}
/**
*
*/
ODe_Style_Style* ODe_AutomaticStyles::addTableColumnStyle(
const UT_UTF8String& rStyleName) {
ODe_Style_Style* pStyle;
pStyle = new ODe_Style_Style();
pStyle->setStyleName(rStyleName);
pStyle->setFamily("table-column");
m_tableColumnStyles.insert(rStyleName.utf8_str(), pStyle);
return pStyle;
}
/**
*
*/
ODe_Style_Style* ODe_AutomaticStyles::addTableRowStyle(
const UT_UTF8String& rStyleName) {
ODe_Style_Style* pStyle;
pStyle = new ODe_Style_Style();
pStyle->setStyleName(rStyleName);
pStyle->setFamily("table-row");
m_tableRowStyles.insert(rStyleName.utf8_str(), pStyle);
return pStyle;
}
/**
*
*/
ODe_Style_Style* ODe_AutomaticStyles::addTableCellStyle(
const UT_UTF8String& rStyleName) {
ODe_Style_Style* pStyle;
pStyle = new ODe_Style_Style();
pStyle->setStyleName(rStyleName);
pStyle->setFamily("table-cell");
m_tableCellStyles.insert(rStyleName.utf8_str(), pStyle);
return pStyle;
}
/**
*
*/
ODe_Style_PageLayout* ODe_AutomaticStyles::addPageLayout() {
ODe_Style_PageLayout* pStyle;
UT_UTF8String styleName;
UT_UTF8String_sprintf(styleName, "PLayout%d", m_pageLayouts.size() + 1);
pStyle = new ODe_Style_PageLayout();
pStyle->setName(styleName);
m_pageLayouts.insert(styleName.utf8_str(), pStyle);
return pStyle;
}
/**
*
*/
ODe_Style_List* ODe_AutomaticStyles::addListStyle() {
ODe_Style_List* pStyle;
UT_UTF8String styleName;
UT_UTF8String_sprintf(styleName, "L%d", m_listStyles.size() + 1);
pStyle = new ODe_Style_List();
pStyle->setName(styleName);
m_listStyles.insert(styleName.utf8_str(), pStyle);
return pStyle;
}
/**
*
*/
void ODe_AutomaticStyles::addPageLayout(ODe_Style_PageLayout*& pPageLayout) {
m_pageLayouts.insert(pPageLayout->getName(), pPageLayout);
}
/**
* Writes <office:automatic-styles> element.
*/
void ODe_AutomaticStyles::write(GsfOutput* pContentStream) const {
UT_GenericVector<ODe_Style_Style*>* pStyleVector;
UT_GenericVector<ODe_Style_PageLayout*>* pPageLayoutVector;
UT_GenericVector<ODe_Style_List*>* pListStyleVector;
UT_uint32 i, count;
UT_UTF8String spacesOffset = " ";
ODe_writeUTF8String(pContentStream, " <office:automatic-styles>\n");
#define ODE_WRITE_STYLES(styleMap) \
pStyleVector = styleMap.enumerate(); \
count = pStyleVector->getItemCount(); \
for (i=0; i<count; i++) { \
(*pStyleVector)[i]->write(pContentStream, spacesOffset); \
} \
DELETEP(pStyleVector);
ODE_WRITE_STYLES (m_textStyles);
ODE_WRITE_STYLES (m_paragraphStyles);
ODE_WRITE_STYLES (m_sectionStyles);
ODE_WRITE_STYLES (m_tableStyles);
ODE_WRITE_STYLES (m_tableColumnStyles);
ODE_WRITE_STYLES (m_tableRowStyles);
ODE_WRITE_STYLES (m_tableCellStyles);
ODE_WRITE_STYLES (m_graphicStyles);
#undef ODE_WRITE_STYLES
pPageLayoutVector = m_pageLayouts.enumerate();
count = pPageLayoutVector->getItemCount();
for (i=0; i<count; i++) {
(*pPageLayoutVector)[i]->write(pContentStream, spacesOffset);
}
DELETEP(pPageLayoutVector);
pListStyleVector = m_listStyles.enumerate();
count = pListStyleVector->getItemCount();
for (i=0; i<count; i++) {
(*pListStyleVector)[i]->write(pContentStream, spacesOffset);
}
DELETEP(pListStyleVector);
ODe_writeUTF8String(pContentStream, " </office:automatic-styles>\n");
}
/**
* Store the style in this automatic styles holder. As the specified
* style get's stored here, this class takes care of freeing its memory later, so
* you don't have to worry about freeing the memory of the stored style.
*
* The style also get's it's unique name on this method.
*
* After calling this method you may end up with your style pointer pointing to
* a different style. It happens when there is already a stored style equivalent
* to the one that you sent to be stored. The one that was passed is deleted.
*/
void ODe_AutomaticStyles::_storeStyle(ODe_Style_Style*& rpStyle,
UT_GenericStringMap<ODe_Style_Style*>& rStyles,
const char* pNamingPrefix) {
UT_GenericVector<ODe_Style_Style*>* pStyleVector;
ODe_Style_Style* pStyle;
bool isDuplicated;
UT_uint32 i, count;
pStyleVector = rStyles.enumerate();
count = pStyleVector->getItemCount();
for (i=0, isDuplicated=false; i<count && isDuplicated==false; i++) {
pStyle = pStyleVector->getNthItem(i);
if ( pStyle->isEquivalentTo(*rpStyle) ) {
isDuplicated = true; // exit the loop
delete rpStyle; // We don't want a duplicated style.
rpStyle = pStyle;
}
}
DELETEP(pStyleVector);
if (!isDuplicated) {
// Let's name and store this style.
UT_UTF8String styleName;
UT_UTF8String_sprintf(styleName, "%s%d", pNamingPrefix, count+1);
rpStyle->setStyleName(styleName);
rStyles.insert(styleName.utf8_str(), rpStyle);
}
}
|