Update ooo320-m1
[ooovba.git] / autodoc / source / display / html / opageenv.cxx
blob126d853a0fd43be3781aad77613dbb0e6037298e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: opageenv.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include "opageenv.hxx"
35 // NOT FULLY DEFINED SERVICES
36 #include <cosv/ploc_dir.hxx>
37 #include <ary/cpp/c_ce.hxx>
38 #include <ary/cpp/c_class.hxx>
39 #include <ary/cpp/c_enum.hxx>
40 #include <ary/cpp/c_gate.hxx>
41 #include <ary/cpp/c_namesp.hxx>
42 #include <ary/cpp/c_tydef.hxx>
43 #include <ary/cpp/cp_ce.hxx>
44 #include <ary/loc/loc_file.hxx>
45 #include <udm/html/htmlitem.hxx>
46 #include <estack.hxx>
47 #include "hdimpl.hxx"
48 #include "strconst.hxx"
51 const String C_sCppDir( "names" );
52 const String C_sIndexDir( "ix" );
55 //************************ Implementation ********************//
57 namespace
60 void CreateDirectory( const csv::ploc::Path & i_rPath );
62 void
63 CreateDirectory( const csv::ploc::Path & i_rPath )
65 csv::ploc::Directory aDirectory(i_rPath);
66 if (NOT aDirectory.Exists())
67 aDirectory.PhysicalCreate();
70 //************************ CheshireCat ********************//
72 struct InNamespaceTree
74 enum E_Type
76 t_unknown,
77 t_namespace,
78 t_type,
79 t_operations,
80 t_data
83 EStack< const ary::cpp::Namespace * >
84 aNamespaces; /// never empty.
85 EStack< const ary::cpp::Class * >
86 aClasses; /// maybe empty.
87 const ary::cpp::CodeEntity *
88 pCe; /// CurFileCe, maybe 0
89 E_Type eType;
91 InNamespaceTree(
92 const ary::cpp::Namespace &
93 i_rNsp );
94 ~InNamespaceTree();
95 void GoDown(
96 const ary::cpp::Namespace &
97 i_rNsp );
98 void GoDown(
99 const ary::cpp::Class &
100 i_rClass );
101 void GoUp();
104 InNamespaceTree::InNamespaceTree( const ary::cpp::Namespace & i_rNsp )
105 : // aNamespaces,
106 // aClasses,
107 pCe(0),
108 eType(t_unknown)
110 aNamespaces.push( &i_rNsp );
113 InNamespaceTree::~InNamespaceTree()
117 void
118 InNamespaceTree::GoDown( const ary::cpp::Namespace & i_rNsp )
120 aNamespaces.push(&i_rNsp);
121 aClasses.erase_all();
122 pCe = 0;
123 eType = t_unknown;
126 void
127 InNamespaceTree::GoDown( const ary::cpp::Class & i_rClass )
129 aClasses.push(&i_rClass);
130 pCe = 0;
131 eType = t_unknown;
134 void
135 InNamespaceTree::GoUp()
137 if ( NOT aClasses.empty() )
138 aClasses.pop();
139 else
140 aNamespaces.pop();
141 pCe = 0;
142 eType = t_unknown;
145 struct InIndex
147 char cLetter;
149 InIndex() : cLetter('A') {}
153 } // anonymous namespace
159 struct OuputPage_Environment::CheshireCat
161 csv::ploc::Path aOutputRoot;
162 csv::ploc::Path aMyPath;
163 csv::StreamStr aFileName;
165 const ary::cpp::Gate *
166 pGate;
167 const display::CorporateFrame *
168 pLayout;
169 intt nDepth;
171 Dyn<InNamespaceTree>
172 pInNamespace;
173 Dyn<InIndex> pInIndex;
175 CheshireCat(
176 const csv::ploc::Path &
177 io_rOutputDir,
178 const ary::cpp::Gate &
179 i_rGate,
180 const display::CorporateFrame &
181 i_rLayout );
182 ~CheshireCat();
183 void AddQualifiedName2Path(
184 const ary::cpp::CodeEntity &
185 i_rCe,
186 bool i_bIncludeLocalName );
188 const Dyn<InNamespaceTree> &
189 NspEnv() const { return pInNamespace; }
190 Dyn<InNamespaceTree> &
191 NspEnv() { return pInNamespace; }
192 const ary::cpp::Namespace *
193 Namespace() const { return pInNamespace ? pInNamespace->aNamespaces.top() : 0; }
194 const ary::cpp::Class *
195 Class() const { return pInNamespace ? (pInNamespace->aClasses.empty() ? 0 : pInNamespace->aClasses.top()) : 0; }
198 OuputPage_Environment::
199 CheshireCat::CheshireCat( const csv::ploc::Path & io_rOutputDir,
200 const ary::cpp::Gate & i_rGate,
201 const display::CorporateFrame & i_rLayout )
202 : aOutputRoot(io_rOutputDir),
203 aMyPath(io_rOutputDir),
204 aFileName(500),
205 pGate(&i_rGate),
206 pLayout(&i_rLayout),
207 nDepth(0),
208 pInNamespace(),
209 pInIndex()
213 OuputPage_Environment::
214 CheshireCat::~CheshireCat()
218 void
219 OuputPage_Environment::
220 CheshireCat::AddQualifiedName2Path( const ary::cpp::CodeEntity & i_rCe,
221 bool i_bIncludeLocalName )
223 if (NOT i_rCe.Owner().IsValid())
225 aMyPath.DirChain().PushBack( C_sCppDir );
226 return;
229 const ary::cpp::CodeEntity &
230 rParent = pGate->Ces().Find_Ce( i_rCe.Owner() );
231 AddQualifiedName2Path( rParent, true );
233 if ( i_bIncludeLocalName )
234 aMyPath.DirChain().PushBack( i_rCe.LocalName() );
239 //************************ OuputPage_Environment ********************//
241 OuputPage_Environment::OuputPage_Environment( const csv::ploc::Path & io_rOutputDir,
242 const ary::cpp::Gate & i_rGate,
243 const display::CorporateFrame & i_rLayout )
244 : pi( new CheshireCat(io_rOutputDir, i_rGate, i_rLayout) )
248 OuputPage_Environment::~OuputPage_Environment()
252 void
253 OuputPage_Environment::MoveDir_2Root()
255 pi->NspEnv() = 0;
256 pi->pInIndex = 0;
257 pi->nDepth = 0;
258 while ( pi->aMyPath.DirChain().Size() > pi->aOutputRoot.DirChain().Size() )
259 pi->aMyPath.DirChain().PopBack();
260 pi->aMyPath.SetFile(String ::Null_());
263 void
264 OuputPage_Environment::MoveDir_2Names()
266 pi->NspEnv() = new InNamespaceTree( Gate().Ces().GlobalNamespace() );
267 pi->aMyPath.DirChain().PushBack( C_sCppDir );
268 pi->aMyPath.SetFile(String ::Null_());
269 ++pi->nDepth;
271 CreateDirectory( pi->aMyPath );
274 void
275 OuputPage_Environment::MoveDir_Down2( const ary::cpp::Namespace & i_rNsp )
277 csv_assert(i_rNsp.Depth() > 0);
278 csv_assert( pi->NspEnv() );
279 csv_assert( pi->Namespace()->CeId() == i_rNsp.Owner() );
281 pi->NspEnv()->GoDown( i_rNsp );
282 pi->aMyPath.DirChain().PushBack(i_rNsp.LocalName());
283 ++pi->nDepth;
284 pi->aMyPath.SetFile(String ::Null_());
286 CreateDirectory( pi->aMyPath );
289 void
290 OuputPage_Environment::MoveDir_Down2( const ary::cpp::Class & i_rClass )
292 csv_assert( pi->NspEnv() );
293 if ( i_rClass.Protection() == ary::cpp::PROTECT_global )
295 csv_assert( pi->Namespace()->CeId() == i_rClass.Owner() );
297 else
299 csv_assert( pi->Class() != 0 );
300 csv_assert( pi->Class()->CeId() == i_rClass.Owner() );
303 pi->NspEnv()->GoDown(i_rClass);
304 pi->aMyPath.DirChain().PushBack(i_rClass.LocalName());
305 pi->aMyPath.SetFile(String ::Null_());
306 ++pi->nDepth;
308 CreateDirectory( pi->aMyPath );
311 void
312 OuputPage_Environment::MoveDir_2Index()
314 MoveDir_2Root();
315 pi->pInIndex = new InIndex;
316 pi->aMyPath.DirChain().PushBack( String (C_sDIR_Index) );
317 pi->aMyPath.SetFile(String ::Null_());
318 pi->nDepth = 1;
320 CreateDirectory( pi->aMyPath );
323 void
324 OuputPage_Environment::MoveDir_Up()
326 if ( pi->nDepth == 1 )
328 MoveDir_2Root();
329 return;
331 else if ( pi->NspEnv() )
333 pi->NspEnv()->GoUp();
334 pi->aMyPath.DirChain().PopBack();
335 pi->aMyPath.SetFile(String ::Null_());
336 --pi->nDepth;
340 void
341 OuputPage_Environment::SetFile_Css()
343 pi->aMyPath.SetFile( C_sHFN_Css );
346 void
347 OuputPage_Environment::SetFile_Overview()
349 pi->aMyPath.SetFile( C_sHFN_Overview );
352 void
353 OuputPage_Environment::SetFile_AllDefs()
355 // Provisorium
356 pi->aMyPath.SetFile("def-all.html");
359 void
360 OuputPage_Environment::SetFile_Index( char i_cLetter )
362 csv_assert( 'A' <= i_cLetter AND i_cLetter <= 'Z' OR i_cLetter == '_' );
364 static StreamStr sIndexFileName(40);
365 sIndexFileName.seekp(0);
366 sIndexFileName << "index-";
367 if ( i_cLetter == '_' )
369 sIndexFileName << "27";
371 else
373 sIndexFileName << int(i_cLetter -'A' + 1);
375 sIndexFileName << ".html";
377 pi->aMyPath.SetFile( sIndexFileName.c_str() );
380 void
381 OuputPage_Environment::SetFile_Help()
383 pi->aMyPath.SetFile( C_sHFN_Help );
386 void
387 OuputPage_Environment::SetFile_CurNamespace()
389 csv_assert( pi->NspEnv() );
390 pi->aMyPath.SetFile("index.html");
391 pi->NspEnv()->pCe = pi->Namespace();
392 pi->NspEnv()->eType = InNamespaceTree::t_namespace;
395 void
396 OuputPage_Environment::SetFile_Class( const ary::cpp::Class & i_rClass )
398 csv_assert( pi->NspEnv() );
399 pi->aMyPath.SetFile( ClassFileName(i_rClass.LocalName()) );
400 pi->NspEnv()->pCe = &i_rClass;
401 pi->NspEnv()->eType = InNamespaceTree::t_type;
404 void
405 OuputPage_Environment::SetFile_Enum( const ary::cpp::Enum & i_rEnum )
407 csv_assert( pi->NspEnv() );
408 pi->aMyPath.SetFile( EnumFileName(i_rEnum.LocalName()) );
409 pi->NspEnv()->pCe = &i_rEnum;
410 pi->NspEnv()->eType = InNamespaceTree::t_type;
413 void
414 OuputPage_Environment::SetFile_Typedef( const ary::cpp::Typedef & i_rTypedef )
416 csv_assert( pi->NspEnv() );
417 pi->aMyPath.SetFile( TypedefFileName(i_rTypedef.LocalName()) );
418 pi->NspEnv()->pCe = &i_rTypedef;
419 pi->NspEnv()->eType = InNamespaceTree::t_type;
422 void
423 OuputPage_Environment::SetFile_Operations( const ary::loc::File * i_pFile )
425 csv_assert( pi->NspEnv() );
426 if ( CurClass() != 0 )
427 pi->aMyPath.SetFile( "o.html" );
428 else
430 csv_assert( i_pFile != 0 );
431 pi->aMyPath.SetFile( HtmlFileName("o-", i_pFile->LocalName()) );
433 pi->NspEnv()->pCe = 0;
434 pi->NspEnv()->eType = InNamespaceTree::t_operations;
437 void
438 OuputPage_Environment::SetFile_Data( const ary::loc::File * i_pFile )
440 csv_assert( pi->NspEnv() );
441 if ( CurClass() != 0 )
442 pi->aMyPath.SetFile( "d.html" );
443 else
445 csv_assert( i_pFile != 0 );
446 pi->aMyPath.SetFile( HtmlFileName("d-", i_pFile->LocalName()) );
448 pi->NspEnv()->pCe = 0;
449 pi->NspEnv()->eType = InNamespaceTree::t_data;
452 const ary::cpp::Namespace *
453 OuputPage_Environment::CurNamespace() const
455 return pi->Namespace();
458 const ary::cpp::Class *
459 OuputPage_Environment::CurClass() const
461 return pi->Class();
464 const csv::ploc::Path &
465 OuputPage_Environment::CurPath() const
467 return pi->aMyPath;
470 const ary::cpp::Gate &
471 OuputPage_Environment::Gate() const
473 return *pi->pGate;
476 const display::CorporateFrame &
477 OuputPage_Environment::Layout() const
479 return *pi->pLayout;
482 uintt
483 OuputPage_Environment::Depth() const
485 return static_cast<uintt>(pi->nDepth);
488 const String &
489 OuputPage_Environment::RepositoryTitle() const
491 return Gate().RepositoryTitle();