1 /*
2  * This file is part of Office 2007 Filters for Calligra
3  *
4  * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Suresh Chande suresh.chande@nokia.com
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23 
24 #ifndef MSOOXMLTHEMESREADER_H
25 #define MSOOXMLTHEMESREADER_H
26 
27 #include <QHash>
28 #include <QColor>
29 #include <QMap>
30 
31 #include <KoGenStyles.h>
32 
33 #include "MsooXmlCommonReader.h"
34 #include "MsooXmlImport.h"
35 #include "MsooXmlTheme.h"
36 
37 namespace MSOOXML
38 {
39 
40 //! Context for MsooXmlThemesReader::read()
41 class KOMSOOXML_EXPORT MsooXmlThemesReaderContext : public MsooXmlReaderContext
42 {
43 public:
44     MsooXmlThemesReaderContext(DrawingMLTheme& t, MSOOXML::MsooXmlRelationships* rel,
45 			       MSOOXML::MsooXmlImport* imp,
46 			       const QString &pathName, const QString &fileName);
47     DrawingMLTheme * const theme;
48     MSOOXML::MsooXmlRelationships *relationships;
49     MSOOXML::MsooXmlImport        *import;
50     QString path;
51     QString file;
52 };
53 
54 //! A class reading MSOOXML themes markup - theme/theme1.xml.
55 /*! @todo generalize for other MSOOXML subformats.
56  */
57 class KOMSOOXML_EXPORT MsooXmlThemesReader : public MSOOXML::MsooXmlCommonReader
58 {
59 public:
60     //! Creates MsooXmlThemesReader object.
61     //! On successful reading, @a theme will be written with theme definition.
62     explicit MsooXmlThemesReader(KoOdfWriters *writers);
63 
64     ~MsooXmlThemesReader() override;
65 
66     //! Reads/parses the file. The output goes mainly to KoGenStyles* KoOdfWriters::mainStyles
67     KoFilter::ConversionStatus read(MsooXmlReaderContext* context = 0) override;
68 
69 protected:
70     KoFilter::ConversionStatus readInternal();
71     KoFilter::ConversionStatus read_theme();
72     KoFilter::ConversionStatus read_themeElements();
73     //! @todo no CASE
74     KoFilter::ConversionStatus read_objectDefaults();
75     KoFilter::ConversionStatus read_custClrLst();
76     KoFilter::ConversionStatus read_extraClrSchemeLst();
77     KoFilter::ConversionStatus read_extraClrScheme();
78 
79     KoFilter::ConversionStatus read_clrScheme();
80     KoFilter::ConversionStatus read_color(); //!< helper
81     DrawingMLColorSchemeItemBase* m_currentColor_local; //!< used by *Clr()
82 
83     KoFilter::ConversionStatus read_fmtScheme();
84     KoFilter::ConversionStatus read_fontScheme();
85     KoFilter::ConversionStatus read_clrMap();
86 
87     KoFilter::ConversionStatus fillStyleReadHelper(int& index);
88     KoFilter::ConversionStatus read_bgFillStyleLst();
89     KoFilter::ConversionStatus read_fillStyleLst();
90     KoFilter::ConversionStatus read_majorFont();
91     KoFilter::ConversionStatus read_minorFont();
92     KoFilter::ConversionStatus read_lnStyleLst();
93 
94     //! Used for skipping a subtree - just reads and shows each element.
95     //! called by BIND_READ_SKIP() macro.
96     KoFilter::ConversionStatus read_SKIP();
97 
98 #include "MsooXmlDrawingMLShared.h"
99 
100     KoFilter::ConversionStatus read_srgbClr_local();
101     KoFilter::ConversionStatus read_sysClr_local();
102 
103 private:
104     void init();
105 
106     MsooXmlThemesReaderContext* m_context;
107 
108     typedef KoFilter::ConversionStatus(MsooXmlThemesReader::*ReadMethod)();
109     QHash<QString, ReadMethod> m_readMethods;
110     QHash<QString, QString> m_colorSchemeIndices;
111     bool m_clrScheme_initialized;
112     bool m_color_initialized;
113 
114     MSOOXML::MsooXmlRelationships* m_relationships;
115     MSOOXML::MsooXmlImport* m_import;
116     QString m_path;
117     QString m_file;
118 };
119 
120 } // namespace MSOOXML
121 
122 #endif //MSOOXMLTHEMESREADER_H
123