// Constructor
 public CCreatorRecordSource( CGedcom gedcom, IProgressCallback progress, string w3cfile, CSourceRecord sr )
     : base(gedcom, progress, w3cfile)
 {
     m_sr = sr;
 }
        // Attaches sub-items to a list item (before the list item is added to the list)
        private void SetSourceSubItems(CListableBool lbItem, CSourceRecord sr, bool bFirstColumnIsCheckbox)
        {
            // Store checkbox value because SubItems.Clear() clears item.Text and item.Checked as well!
            bool bWasChecked = lbItem.Checked;
            lbItem.SubItems.Clear();
            lbItem.Checked = bWasChecked;

            if (bFirstColumnIsCheckbox)
            {
                // First nColumn (ie. item) is checkbox, so first sub-item is title.
                lbItem.SubItems.Add(new CListableSource(sr));
            }

            string sRepositories = "";
            foreach (CSourceRepositoryCitation src in sr.m_alSourceRepositoryCitations)
            {
                CRepositoryRecord rr = m_gedcom.GetRepositoryRecord(src.m_xrefRepo);
                if (rr != null)
                {
                    if (rr.m_sNameOfRepository != null && rr.m_sNameOfRepository != "")
                    {
                        if (sRepositories != "")
                        {
                            sRepositories += ", ";
                        }
                        sRepositories += rr.m_sNameOfRepository;
                    }
                }
            }
            lbItem.SubItems.Add(new ListViewItem.ListViewSubItem(lbItem, sRepositories));

            int nBirths = 0;
            int nMarriages = 0;
            int nDeaths = 0;
            int nIndis = 0;
            int nFamilies = 0;
            int nNotes = 0;
            int nOther = 0;
            int nCitations = 0;
            if (sr.m_alBackreferences.Count > 0)
            {
                foreach (CBackReference br in sr.m_alBackreferences)
                {
                    switch (br.m_sEventType)
                    {
                        case "BIRT":
                            nBirths++;
                            nCitations++;
                            break;
                        case "MARR":
                            nMarriages++;
                            nCitations++;
                            break;
                        case "DEAT":
                            nCitations++;
                            nDeaths++;
                            break;
                        default:
                            switch (br.m_ertRecordType)
                            {
                                case ERecordType.Individual:
                                    nCitations++;
                                    nIndis++;
                                    break;
                                case ERecordType.Family:
                                    // Strictly this should be plus 2 if husb & wife both known, otherwise 1 or 0.
                                    nCitations++;
                                    nFamilies++;
                                    break;
                                case ERecordType.Note:
                                    nNotes++;
                                    break;
                                default:
                                    nOther++;
                                    break;
                            }
                            break;
                    }
                }
            }

            lbItem.SubItems.Add(new ListViewItem.ListViewSubItem(lbItem, nCitations.ToString()));
            lbItem.SubItems.Add(new ListViewItem.ListViewSubItem(lbItem, nBirths.ToString()));
            lbItem.SubItems.Add(new ListViewItem.ListViewSubItem(lbItem, nMarriages.ToString()));
            lbItem.SubItems.Add(new ListViewItem.ListViewSubItem(lbItem, nDeaths.ToString()));
            lbItem.SubItems.Add(new CListableString(sr.m_xref));

            int nVisiblePics = sr.CountVisibleMFRs();
            int nTotalPics = sr.CountAllMFRs();

            if (nVisiblePics != nTotalPics)
            {
                lbItem.SubItems.Add(new CListableNumber(nVisiblePics, String.Format("{0}/{1}", nVisiblePics, nTotalPics)));
            }
            else
            {
                lbItem.SubItems.Add(new CListableNumber(nTotalPics, String.Format("{0}", nTotalPics)));
            }
            lbItem.Checked = bWasChecked;
        }
 // Constructor
 public CListableSource( CSourceRecord sr )
 {
     m_sr = sr;
     base.Text = ToString();
 }
        // Parser
        public static CSourceRecord Parse( CGedcom gedcom, int nLevel )
        {
            CGedcomLine gedcomLine;
            bool bParsingFinished;

            // Temporary holders for class members.
            CEventRecorded er;
            CSourceRepositoryCitation src;
            CNoteStructure ns;
            CMultimediaLink ml;

            // Without an xref header, we can't continue
            if ((gedcomLine = gedcom.GetLine(nLevel, "SOUR")) == null)
            {
                // Not one of us
                return null;
            }

            CSourceRecord sr = new CSourceRecord( gedcom );

            System.Text.StringBuilder sbTextFromSource = new System.Text.StringBuilder( 64 );

            sr.m_xref = gedcomLine.XrefID;
            gedcom.IncrementLineIndex(1);

            do
            {
                bParsingFinished = true;

                // Let Record have a go at parsing the rest
                if( sr.ParseRecord( gedcom, nLevel ) )
                {
                    bParsingFinished = false;
                    continue;
                }
                else if( (gedcomLine = gedcom.GetLine(nLevel+1, "DATA")) != null )
                {
                    gedcom.IncrementLineIndex(1);
                    bool bParsingFinished2;
                    do
                    {
                        bParsingFinished2 = true;
                        if( (er = CEventRecorded.Parse( gedcom, nLevel+2)) != null )
                        {
                            sr.m_alEventsRecorded.Add( er );
                            bParsingFinished2 = false;
                        }
                        else if( (gedcomLine = gedcom.GetLine(nLevel+2, "AGNC")) != null )
                        {
                            sr.m_sResponsibleAgency = gedcomLine.LineItem;
                            gedcom.IncrementLineIndex(1);
                            bParsingFinished2 = false;
                        }
                        else if( (ns = CNoteStructure.Parse( gedcom, nLevel+2 )) != null )
                        {
                            sr.m_alDataNoteStructures.Add( ns );
                            bParsingFinished2 = false;
                        }
                    }
                    while( !bParsingFinished2 );
                    bParsingFinished = false;
                }
                else if( (gedcomLine = gedcom.GetLine(nLevel+1, "AUTH")) != null )
                {
                    sr.m_sSourceOriginator = gedcomLine.LineItem;
                    gedcom.IncrementLineIndex(1);
                    bool bParsingFinished2;
                    do
                    {
                        bParsingFinished2 = true;
                        if( (gedcomLine = gedcom.GetLine(nLevel+2, "CONC")) != null )
                        {
                            sr.m_sSourceOriginator += gedcomLine.LineItem;
                            gedcom.IncrementLineIndex(1);
                            bParsingFinished2 = false;
                        }
                        else if( (gedcomLine = gedcom.GetLine(nLevel+2, "CONT")) != null )
                        {
                            sr.m_sSourceOriginator += "\n" + gedcomLine.LineItem;
                            gedcom.IncrementLineIndex(1);
                            bParsingFinished2 = false;
                        }
                    }
                    while( !bParsingFinished2 );
                    bParsingFinished = false;
                }
                else if( ((gedcomLine = gedcom.GetLine(nLevel+1, "TITL")) != null) || ((gedcomLine = gedcom.GetLine(nLevel+1, "NAME")) != null) )
                {
                    sr.m_sSourceDescriptiveTitle = gedcomLine.LineItem;
                    gedcom.IncrementLineIndex(1);
                    bool bParsingFinished2;
                    do
                    {
                        bParsingFinished2 = true;
                        if( (gedcomLine = gedcom.GetLine(nLevel+2, "CONC")) != null )
                        {
                            sr.m_sSourceDescriptiveTitle += gedcomLine.LineItem;
                            gedcom.IncrementLineIndex(1);
                            bParsingFinished2 = false;
                        }
                        else if( (gedcomLine = gedcom.GetLine(nLevel+2, "CONT")) != null )
                        {
                            sr.m_sSourceDescriptiveTitle += "\n" + gedcomLine.LineItem;
                            gedcom.IncrementLineIndex(1);
                            bParsingFinished2 = false;
                        }
                    }
                    while( !bParsingFinished2 );
                    bParsingFinished = false;
                }
                else if( (gedcomLine = gedcom.GetLine(nLevel+1, "ABBR")) != null )
                {
                    sr.m_sSourceFiledByEntry = gedcomLine.LineItem;
                    gedcom.IncrementLineIndex(1);
                    bParsingFinished = false;
                }
                else if( (gedcomLine = gedcom.GetLine(nLevel+1, "PUBL")) != null )
                {
                    sr.m_sSourcePublicationFacts = gedcomLine.LineItem;
                    gedcom.IncrementLineIndex(1);
                    bool bParsingFinished2;
                    do
                    {
                        bParsingFinished2 = true;
                        if( (gedcomLine = gedcom.GetLine(nLevel+2, "CONC")) != null )
                        {
                            sr.m_sSourcePublicationFacts += gedcomLine.LineItem;
                            gedcom.IncrementLineIndex(1);
                            bParsingFinished2 = false;
                        }
                        else if( (gedcomLine = gedcom.GetLine(nLevel+2, "CONT")) != null )
                        {
                            sr.m_sSourcePublicationFacts += "\n" + gedcomLine.LineItem;
                            gedcom.IncrementLineIndex(1);
                            bParsingFinished2 = false;
                        }
                    }
                    while( !bParsingFinished2 );
                    bParsingFinished = false;
                }
                else if( (gedcomLine = gedcom.GetLine(nLevel+1, "TEXT")) != null )
                {
                    // Actually want strcpy equiv here.
                    sbTextFromSource.Append( gedcomLine.LineItem );
                    gedcom.IncrementLineIndex(1);
                    bool bParsingFinished2;
                    do
                    {
                        bParsingFinished2 = true;
                        if( (gedcomLine = gedcom.GetLine(nLevel+2, "CONC")) != null )
                        {
                            sbTextFromSource.Append( gedcomLine.LineItem );
                            gedcom.IncrementLineIndex(1);
                            bParsingFinished2 = false;
                        }
                        else if( (gedcomLine = gedcom.GetLine(nLevel+2, "CONT")) != null )
                        {
                            sbTextFromSource.Append( "\n" + gedcomLine.LineItem );
                            gedcom.IncrementLineIndex(1);
                            bParsingFinished2 = false;
                        }
                    }
                    while( !bParsingFinished2 );
                    bParsingFinished = false;
                }
                else if( (src = CSourceRepositoryCitation.Parse( gedcom, nLevel+1 )) != null )
                {
                    sr.m_alSourceRepositoryCitations.Add( src );
                    bParsingFinished = false;
                }
                else if( (ml = CMultimediaLink.Parse( gedcom, nLevel+1 )) != null )
                {
                    sr.m_alMultimediaLinks.Add( ml );
                    bParsingFinished = false;
                }
                else if( (ns = CNoteStructure.Parse( gedcom, nLevel+1 )) != null )
                {
                    sr.m_alNoteStructures.Add( ns );
                    bParsingFinished = false;
                }
                else if( ( gedcomLine = gedcom.GetLine()).Level > nLevel )
                {
                    LogFile.TheLogFile.WriteLine( LogFile.DT_GEDCOM, LogFile.EDebugLevel.Warning, "Unknown tag :" );
                    LogFile.TheLogFile.WriteLine( LogFile.DT_GEDCOM, LogFile.EDebugLevel.Warning, gedcomLine.ToString() );
                    gedcom.IncrementLineIndex(1);
                    bParsingFinished = false;
                }
            }
            while( !bParsingFinished );

            sr.m_sTextFromSource = sbTextFromSource.ToString();

            return sr;
        }