1 /* AbiSource
2 *
3 * Copyright (C) 2005 INdT
4 * Author: Daniel d'Andrada T. de Carvalho <daniel.carvalho@indt.org.br>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301 USA.
20 */
21
22 // Class definition include
23 #include "ODe_Note_Listener.h"
24
25 // Internal includes
26 #include "ODe_AuxiliaryData.h"
27 #include "ODe_Common.h"
28 #include "ODe_ListenerAction.h"
29 #include "ODe_Text_Listener.h"
30
31 // AbiWord includes
32 #include <pp_AttrProp.h>
33
34
35 /**
36 * Constructor
37 */
ODe_Note_Listener(ODe_Styles & rStyles,ODe_AutomaticStyles & rAutomatiStyles,GsfOutput * pTextOutput,ODe_AuxiliaryData & rAuxiliaryData,UT_uint8 spacesOffset)38 ODe_Note_Listener::ODe_Note_Listener(ODe_Styles& rStyles,
39 ODe_AutomaticStyles& rAutomatiStyles,
40 GsfOutput* pTextOutput,
41 ODe_AuxiliaryData& rAuxiliaryData,
42 UT_uint8 spacesOffset)
43 :
44 ODe_AbiDocListenerImpl(spacesOffset),
45 m_rStyles(rStyles),
46 m_rAutomatiStyles(rAutomatiStyles),
47 m_pTextOutput(pTextOutput),
48 m_rAuxiliaryData(rAuxiliaryData)
49 {
50 }
51
52
53 /**
54 *
55 */
openFootnote(const PP_AttrProp * pAP,ODe_ListenerAction & rAction)56 void ODe_Note_Listener::openFootnote(const PP_AttrProp* pAP,
57 ODe_ListenerAction& rAction) {
58 bool ok;
59 const gchar* pValue = NULL;
60 UT_UTF8String str;
61
62 ok = pAP->getAttribute("footnote-id", pValue);
63
64 if (ok && pValue)
65 _openNote("footnote", pValue, rAction);
66 }
67
68
69 /**
70 *
71 */
closeFootnote(ODe_ListenerAction & rAction)72 void ODe_Note_Listener::closeFootnote(ODe_ListenerAction& rAction) {
73 _closeNote(rAction);
74 }
75
76
77 /**
78 *
79 */
openEndnote(const PP_AttrProp * pAP,ODe_ListenerAction & rAction)80 void ODe_Note_Listener::openEndnote(const PP_AttrProp* pAP,
81 ODe_ListenerAction& rAction) {
82 bool ok;
83 const gchar* pValue = NULL;
84 UT_UTF8String str;
85
86 ok = pAP->getAttribute("endnote-id", pValue);
87
88 if (ok && pValue)
89 _openNote("endnote", pValue, rAction);
90 }
91
92
93 /**
94 *
95 */
closeEndnote(ODe_ListenerAction & rAction)96 void ODe_Note_Listener::closeEndnote(ODe_ListenerAction& rAction) {
97 _closeNote(rAction);
98 }
99
100
101 /**
102 *
103 */
openBlock(const PP_AttrProp *,ODe_ListenerAction & rAction)104 void ODe_Note_Listener::openBlock(const PP_AttrProp* /*pAP*/,
105 ODe_ListenerAction& rAction) {
106 ODe_Text_Listener* pTextListener;
107 pTextListener = new ODe_Text_Listener(m_rStyles,
108 m_rAutomatiStyles,
109 m_pTextOutput,
110 m_rAuxiliaryData,
111 0,
112 m_spacesOffset);
113 rAction.pushListenerImpl(pTextListener, true);
114 pTextListener->setIgnoreFirstTab(true);
115 }
116
117
118 /**
119 *
120 */
_openNote(const gchar * pNoteClass,const gchar * pNoteId,ODe_ListenerAction &)121 void ODe_Note_Listener::_openNote(const gchar* pNoteClass,
122 const gchar* pNoteId,
123 ODe_ListenerAction& /*rAction*/) {
124 UT_uint32 noteCitation;
125 UT_UTF8String str;
126 UT_UTF8String output;
127
128 UT_return_if_fail(pNoteId);
129
130 // The note citation will be id+1
131 // So id=0 will have a citation "1", and so on.
132 noteCitation = atoi(pNoteId) + 1;
133
134 output += "<text:note text:id=\"note";
135
136 UT_UTF8String_sprintf(str, "%u", m_rAuxiliaryData.m_noteCount+1);
137 output += str;
138
139 output += "\" text:note-class=\"";
140 output += pNoteClass;
141 output += "\"><text:note-citation>";
142
143 UT_UTF8String_sprintf(str, "%u", noteCitation);
144 output += str;
145
146 output += "</text:note-citation><text:note-body>";
147
148 ODe_writeUTF8String(m_pTextOutput, output);
149
150 m_rAuxiliaryData.m_noteCount++;
151 }
152
153
154 /**
155 *
156 */
_closeNote(ODe_ListenerAction & rAction)157 void ODe_Note_Listener::_closeNote(ODe_ListenerAction& rAction) {
158 ODe_writeUTF8String(m_pTextOutput, "</text:note-body></text:note>");
159 rAction.popListenerImpl();
160 }
161