1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <precomp.h>
29 #include "pm_aldef.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <cosv/tpl/tpltools.hxx>
34 #include <ary/cpp/c_gate.hxx>
35 #include <ary/cpp/c_define.hxx>
36 #include <ary/cpp/c_macro.hxx>
37 #include <ary/cpp/cp_def.hxx>
38 #include <ary/loc/loc_file.hxx>
39 #include <ary/loc/locp_le.hxx>
40 #include <ary/getncast.hxx>
41 #include "hd_docu.hxx"
42 #include "html_kit.hxx"
43 #include "navibar.hxx"
44 #include "opageenv.hxx"
45 #include "pagemake.hxx"
46 #include "strconst.hxx"
47 
48 
49 using namespace csi;
50 using csi::html::HorizontalLine;
51 using csi::html::Link;
52 using csi::html::Label;
53 using csi::html::AlignAttr;
54 
55 
56 
57 PageMaker_AllDefs::PageMaker_AllDefs( PageDisplay & io_rPage )
58     :   SpecializedPageMaker(io_rPage),
59         pDocuDisplay( new Docu_Display(io_rPage.Env()) ),
60         pNavi(0)
61 {
62 }
63 
64 PageMaker_AllDefs::~PageMaker_AllDefs()
65 {
66 }
67 
68 void
69 PageMaker_AllDefs::MakePage()
70 {
71     pNavi = new NavigationBar( Env(), NavigationBar::LOC_AllDefs );
72     Write_NavBar();
73 
74     Write_TopArea();
75 
76     Write_DefinesList();
77     Write_MacrosList();
78 
79     pNavi->Write_SubRows();
80 }
81 
82 void
83 PageMaker_AllDefs::Write_NavBar()
84 {
85     pNavi->MakeSubRow( "" );
86     pNavi->AddItem( "Defines", "defines", true );
87     pNavi->AddItem( "Macros", "macros", true );
88     pNavi->Write( CurOut() );
89     CurOut() << new HorizontalLine;
90 }
91 
92 void
93 PageMaker_AllDefs::Write_TopArea()
94 {
95     adcdisp::PageTitle_Std fTitle;
96     fTitle( CurOut(), "Defines and ", "Macros" );
97 
98     CurOut() << new HorizontalLine;
99 }
100 
101 void
102 PageMaker_AllDefs::Write_DocuArea()
103 {
104     // Not needed.
105 }
106 
107 void
108 PageMaker_AllDefs::Write_DefinesList()
109 {
110     CurOut()
111         << new html::LineBreak
112         << new html::LineBreak
113         >> *new xml::AnElement("div")
114             << new html::ClassAttr("define")
115             >> *new html::Label("defines")
116                 >> *new html::Headline(3)
117                     << "Defines";
118 
119     ary::cpp::DefsResultList
120         aAllDefines =  Env().Gate().Defs().AllDefines();
121     ary::cpp::DefsConstIterator
122         itEnd = aAllDefines.end();
123 
124     if (aAllDefines.begin() != itEnd)
125     {
126         for ( ary::cpp::DefsConstIterator it = aAllDefines.begin();
127               it != itEnd;
128               ++it )
129         {
130             Write_Define(*it);
131         }
132     }
133     else
134     {
135         CurOut() << "None.";
136     }
137 
138     CurOut() << new HorizontalLine;
139 }
140 
141 void
142 PageMaker_AllDefs::Write_MacrosList()
143 
144 {
145     CurOut()
146         << new html::LineBreak
147         << new html::LineBreak
148         >> *new xml::AnElement("div")
149             << new html::ClassAttr("define")
150             >> *new html::Label("macros")
151                 >> *new html::Headline(3)
152                     << "Macros";
153 
154     ary::cpp::DefsResultList
155         aAllMacros =  Env().Gate().Defs().AllMacros();
156     ary::cpp::DefsConstIterator
157         itEnd = aAllMacros.end();
158 
159     if (aAllMacros.begin() != itEnd)
160     {
161         for ( ary::cpp::DefsConstIterator it = aAllMacros.begin();
162               it != itEnd;
163               ++it )
164         {
165             Write_Macro(*it);
166         }
167     }
168     else
169     {
170         CurOut() << "None.";
171     }
172 
173     CurOut() << new HorizontalLine;
174 }
175 
176 void
177 PageMaker_AllDefs::Write_Define(De_id  i_nId)
178 {
179     csv_assert( ary::is_type<ary::cpp::Define>( Env().Gate().Defs().Find_Def(i_nId)) );
180     const ary::cpp::Define &
181         rDef = static_cast< const ary::cpp::Define& >( Env().Gate().Defs().Find_Def(i_nId) );
182 
183     CurOut() << new html::HorizontalLine;
184 
185     adcdisp::ExplanationList aDocu( CurOut(), true );
186     aDocu.AddEntry();
187 
188     aDocu.Term()
189         >> *new html::Label( rDef.LocalName() )
190             << " ";
191     aDocu.Term()
192         << rDef.LocalName();
193 
194     Write_DefsDocu( aDocu.Def(), rDef );
195 }
196 
197 void
198 PageMaker_AllDefs::Write_Macro(De_id  i_nId)
199 {
200     csv_assert( Env().Gate().Defs().Find_Def(i_nId).AryClass() == ary::cpp::Macro::class_id );
201     const ary::cpp::Macro &
202         rDef = static_cast< const ary::cpp::Macro& >( Env().Gate().Defs().Find_Def(i_nId) );
203 
204     CurOut() << new html::HorizontalLine;
205 
206     adcdisp::ExplanationList aDocu( CurOut(), true );
207     aDocu.AddEntry();
208 
209     aDocu.Term()
210         >> *new html::Label( rDef.LocalName() )
211             << " ";
212     aDocu.Term()
213         << rDef.LocalName()
214         << "(";
215     WriteOut_TokenList( aDocu.Term(), rDef.Params(), ", " );
216     aDocu.Term()
217         << ")";
218 
219     Write_DefsDocu( aDocu.Def(), rDef );
220 }
221 
222 
223 void
224 PageMaker_AllDefs::Write_DefsDocu( csi::xml::Element &              o_rOut,
225                                    const ary::cpp::DefineEntity &  i_rTextReplacement )
226 {
227     if ( i_rTextReplacement.DefinitionText().size() > 0 )
228     {
229         EraseLeadingSpace( *const_cast< String * >(
230                                 &(*i_rTextReplacement.DefinitionText().begin())
231                          ) );
232     }
233 
234     adcdisp::ExplanationTable rList( o_rOut );
235 
236     rList.AddEntry( "Defined As" );
237     WriteOut_TokenList( rList.Def(), i_rTextReplacement.DefinitionText(), " " );
238 
239     const ary::loc::File &
240         rFile = Env().Gate().Locations().Find_File( i_rTextReplacement.Location() );
241     rList.AddEntry( "In File" );
242     rList.Def() << rFile.LocalName();
243 
244     ShowDocu_On( o_rOut, *pDocuDisplay, i_rTextReplacement );
245 }
246