Logo Search packages:      
Sourcecode: xchm version File versions

bool ContentTagHandler::HandleTag ( const wxHtmlTag &  tag  ) 

Does the bulk of the work, constructing the tree.

Parameters:
tag The current tag to handle.
Returns:
true if we've parsed inner tags also, false otherwise.

Definition at line 44 of file contenttaghandler.cpp.

References CHMListCtrl::AddPairItem().

{
      if(!_treeCtrl && !_listCtrl)
            return FALSE;

      if (tag.GetName() == wxT("UL"))
      {
            if(_treeCtrl && _level >= TREE_BUF_SIZE)
                  return FALSE;

            bool inc = _level >= 0 
                  && (long)_parents[_level] != 0;
            
            if(inc)
                  ++_level;
            ParseInner(tag);
            
            if(inc)
                  --_level;

            return TRUE;

      } else if(!tag.GetName().CmpNoCase(wxT("OBJECT"))) {
        
            /* 
               Valid HHW's file may contain only two object tags: 
 
               <OBJECT type="text/site properties"> 
               <param name="ImageType" value="Folder"> 
               </OBJECT> 
 
               or 
 
               <OBJECT type="text/sitemap"> 
               <param name="Name" value="main page"> 
               <param name="Local" value="another.htm"> 
               </OBJECT> 
 
               We're interested in the latter.
            */
            
            if(!tag.GetParam(wxT("TYPE")).CmpNoCase(wxT("text/sitemap"))) {

                  // handle broken <UL> tags that would
                  // otherwise SEGFAULT by trying to access
                  // _parents[-1].
                  int parentIndex = _level ? _level - 1 : 0;

                  _title = _url = wxEmptyString;
                  ParseInner(tag);

                  if(_treeCtrl && !_title.IsEmpty()) {

                        _parents[_level] = 
                              _treeCtrl->AppendItem(
                                    _parents[parentIndex],
                                    _title, -1, -1,
                                    new URLTreeItem(_url));
                        if(!_level)
                              _parents[0] = _treeCtrl->GetRootItem();
                  }

                  return TRUE;
            }
            
            return FALSE;
      } else { // "PARAM"

            if(!tag.GetParam(wxT("NAME")).CmpNoCase(wxT("Name"))) {

                  if(_title.IsEmpty()) {
                        if(_useEnc) {
                              wxCSConv cv(wxFontMapper::Get()->
                                        GetEncodingName(_enc));

                              const wxString s = 
                                    tag.GetParam(wxT("VALUE"));
                              const size_t len = s.length();
                              wxCharBuffer buf(len);
                              char *p = buf.data();
                        
                              for ( size_t n = 0; n < len; n++ ) {
                                    wxASSERT_MSG(s[n] < 0x100, 
                                               wxT("non ASCII"
                                                 " char?") );
                                    *p++ = s[n];
                              }

                              _title = wxString(buf, cv);
                        } else 
                              _title = tag.GetParam(wxT("VALUE"));
                  }
            }

            if(!tag.GetParam(wxT("NAME")).CmpNoCase(wxT("Local"))) {
                  _url = tag.GetParam(wxT("VALUE"));
            }

            if(_listCtrl && !_url.IsEmpty() && !_title.IsEmpty()) {
                  _listCtrl->AddPairItem(_title, _url);
                  _title = _url = wxEmptyString;
            }

            return FALSE;
      }
}


Generated by  Doxygen 1.6.0   Back to index