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 "dsply_da.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_vari.hxx>
36 #include <ary/doc/d_docu.hxx>
37 #include <ary/loc/loc_file.hxx>
38 #include <ary/loc/locp_le.hxx>
39 #include <udm/html/htmlitem.hxx>
40 #include "hd_docu.hxx"
41 #include "hdimpl.hxx"
42 #include "html_kit.hxx"
43 #include "opageenv.hxx"
44 #include "pagemake.hxx"
45 
46 
47 using namespace csi;
48 
49 
50 
51 DataDisplay::DataDisplay( OuputPage_Environment & io_rEnv )
52     :   aMap_GlobalDataDisplay(),
53         pClassMembersDisplay(0),
54         pEnv( &io_rEnv ),
55         pDocuShow( new Docu_Display(io_rEnv) )
56 {
57 }
58 
59 DataDisplay::~DataDisplay()
60 {
61     csv::erase_map_of_heap_ptrs( aMap_GlobalDataDisplay );
62 }
63 
64 void
65 DataDisplay::PrepareForConstants()
66 {
67     if (pClassMembersDisplay)
68         pClassMembersDisplay = 0;
69 
70     csv::erase_map_of_heap_ptrs( aMap_GlobalDataDisplay );
71 }
72 
73 void
74 DataDisplay::PrepareForVariables()
75 {
76     // Doesn't need to do anything yet.
77 }
78 
79 void
80 DataDisplay::PrepareForStdMembers()
81 {
82     csv::erase_map_of_heap_ptrs( aMap_GlobalDataDisplay );
83 
84     pClassMembersDisplay = new PageDisplay(*pEnv);
85     const ary::cpp::Class * pClass = pEnv->CurClass();
86     csv_assert( pClass != 0 );
87     pClassMembersDisplay->Setup_DataFile_for(*pClass);
88 }
89 
90 void
91 DataDisplay::PrepareForStaticMembers()
92 {
93     // Doesn't need to do anything yet.
94 }
95 
96 void
97 DataDisplay::Create_Files()
98 {
99     if (pClassMembersDisplay)
100     {
101         pClassMembersDisplay->Create_File();
102         pClassMembersDisplay = 0;
103     }
104     else
105     {
106      	for ( Map_FileId2PagePtr::const_iterator it = aMap_GlobalDataDisplay.begin();
107               it != aMap_GlobalDataDisplay.end();
108               ++it )
109         {
110          	(*it).second->Create_File();
111         }
112         csv::erase_map_of_heap_ptrs( aMap_GlobalDataDisplay );
113     }
114 }
115 
116 void
117 DataDisplay::do_Process( const ary::cpp::Variable & i_rData )
118 {
119     if ( Ce_IsInternal(i_rData) )
120         return;
121 
122     PageDisplay & rPage = FindPage_for( i_rData );
123 
124     csi::xml::Element & rOut = rPage.CurOut();
125     Display_SglDatum( rOut, i_rData );
126 }
127 
128 const ary::cpp::Gate *
129 DataDisplay::inq_Get_ReFinder() const
130 {
131     return & pEnv->Gate();
132 }
133 
134 PageDisplay &
135 DataDisplay::FindPage_for( const ary::cpp::Variable & i_rData )
136 {
137     if ( pClassMembersDisplay )
138         return *pClassMembersDisplay;
139 
140     SourceFileId
141             nSourceFile = i_rData.Location();
142     PageDisplay *
143             pFound = csv::value_from_map( aMap_GlobalDataDisplay, nSourceFile, (PageDisplay*)0 );
144     if ( pFound == 0 )
145     {
146      	pFound = new PageDisplay( *pEnv );
147         const ary::loc::File &
148                 rFile = pEnv->Gate().Locations().Find_File( nSourceFile );
149         pFound->Setup_DataFile_for(rFile);
150         aMap_GlobalDataDisplay[nSourceFile] = pFound;
151     }
152 
153     return *pFound;
154 }
155 
156 void
157 DataDisplay::Display_SglDatum( csi::xml::Element &        rOut,
158                                const ary::cpp::Variable & i_rData )
159 {
160     adcdisp::ExplanationList aDocu(rOut, true);
161     aDocu.AddEntry( 0 );
162 
163     aDocu.Term()
164         >> *new html::Label( DataLabel(i_rData.LocalName()) )
165             << " ";
166     aDocu.Term()
167         << i_rData.LocalName();
168 
169     dshelp::Get_LinkedTypeText( aDocu.Def(), *pEnv, i_rData.Type() );
170     aDocu.Def()
171         << " "
172         >> *new html::Strong
173             << i_rData.LocalName();
174     if ( i_rData.ArraySize().length() > 0 )
175     {
176         aDocu.Def()
177             << "["
178             << i_rData.ArraySize()
179             << "]";
180     }
181     if ( i_rData.Initialisation().length() > 0 )
182     {
183         aDocu.Def()
184             << " = "
185             << i_rData.Initialisation();
186     }
187     aDocu.Def()
188         << ";"
189         << new html::LineBreak
190         << new html::LineBreak;
191 
192     aDocu.AddEntry_NoTerm();
193 
194     pDocuShow->Assign_Out(aDocu.Def());
195     pDocuShow->Process(i_rData.Docu());
196     pDocuShow->Unassign_Out();
197 
198     rOut << new html::HorizontalLine;
199 }
200