Ejemplo n.º 1
0
        // I've isolated the layout specific code to this region. If you want to do something other than tiling, this is
        // where you'll make your changes

        /// <summary>
        /// Calculate the extent of the view based on the available size
        /// </summary>
        /// <param name="availableSize">available size</param>
        /// <param name="itemCount">number of data items</param>
        /// <returns></returns>
        private Size CalculateExtent(Size availableSize)
        {
            if (totalHeight > 0)
            {
                return(new Size(availableSize.Width, totalHeight));
            }
            // Die Gesamtgröße der Liste berechnen.
            ItemsControl itemsControl = ItemsControl.GetItemsOwner(this);

            // We need to access InternalChildren before the generator to work around a bug
            UIElementCollection     children  = this.InternalChildren;
            IItemContainerGenerator generator = this.ItemContainerGenerator;

            // Get the generator position of the first visible data item
            GeneratorPosition startPos = generator.GeneratorPositionFromIndex(0);

            using (generator.StartAt(startPos, GeneratorDirection.Forward, true))
            {
                for (int itemIndex = 0; itemIndex < itemsControl.Items.Count; ++itemIndex)
                {
                    itemsTopPosition.Add(totalHeight);

                    // Get or create the child
                    bool newlyRealized;
                    // UIElement child = generator.GenerateNext(out newlyRealized) as UIElement;

                    // generator.PrepareItemContainer(child);

                    // Measurements will depend on layout algorithm
                    //child.Measure(GetChildSize());
                    AlbumViewItem avi = itemsControl.Items[itemIndex] as AlbumViewItem;
                    if (avi != null)
                    {
                        double height = Math.Max((avi.Tracks.Count * 18) + 10, 110);        // Minimale Höhe eines Albums
                        height       = Math.Min(height, 367);                               // Maximale Höhe eines Albums
                        totalHeight += height;
                        itemsHeight.Add(height);
                    }
                    AlbumViewTitle title = itemsControl.Items[itemIndex] as AlbumViewTitle;
                    if (title != null)
                    {
                        double height = 18;
                        totalHeight += height;
                        itemsHeight.Add(height);
                    }
                }
            }

            generator.RemoveAll();

            // See how big we are
            return(new Size(this.ActualWidth, totalHeight));
        }
Ejemplo n.º 2
0
        void bwAlbumView_DoWork(object sender, DoWorkEventArgs e)
        {
            FieldCollection fc = new FieldCollection();

            fc.AddRange(new Field[] { Field.CDID, Field.Title, Field.ArchiveNumber, Field.CDCoverFront, Field.YearRecorded,
                                      Field.TrackNumber, Field.TrackTitle, Field.TrackLength, Field.TrackRating, Field.TrackSoundFile,
                                      Field.ArtistCDName, Field.ArtistCDSaveAs, Field.ArtistTrackName, Field.Category, Field.ComposerTrackName });

            int count = 0;

            SortFieldCollection sfc = new SortFieldCollection();

            sfc.Add(Field.ArtistCDSaveAs);
            sfc.Add(Field.Title);
            sfc.Add(Field.CDID);
            // Die Verzeichnisansicht immer sortiert nach Dateiname
            if (this.ShowItemType == ShowItemType.Directory)
            {
                sfc.Add(Field.TrackSoundFile);
            }
            else
            {
                sfc.Add(Field.TrackNumber);
            }

            SafeObservableCollection <AlbumViewItemBase> items = new SafeObservableCollection <AlbumViewItemBase>();

            AlbumViewItem newItem         = null;
            string        lastArtist      = "";
            string        lastArtistTitle = "";
            string        lastTitle       = "";
            int           lastcdid        = 0;

            Big3.Hitbase.DataBaseEngine.Condition searchCondition = Big3.Hitbase.DataBaseEngine.Condition.Combine(Condition, ConditionFromTree);

            using (DataBaseView view = TrackView.CreateView(DataBase, fc, sfc, 0, searchCondition))
            {
                // Überall auf die Indizes 1 addieren, da die erste Spalte die TrackID ist.
                int colArtistName     = fc.IndexOf(Field.ArtistCDName) + 1;
                int colArtistSaveAs   = fc.IndexOf(Field.ArtistCDSaveAs) + 1;
                int colTitle          = fc.IndexOf(Field.Title) + 1;
                int colCDID           = fc.IndexOf(Field.CDID) + 1;
                int colFrontCover     = fc.IndexOf(Field.CDCoverFront) + 1;
                int colCategory       = fc.IndexOf(Field.Category) + 1;
                int colArchiveNumber  = fc.IndexOf(Field.ArchiveNumber) + 1;
                int colYearRecorded   = fc.IndexOf(Field.YearRecorded) + 1;
                int colTrackNumber    = fc.IndexOf(Field.TrackNumber) + 1;
                int colTrackTitle     = fc.IndexOf(Field.TrackTitle) + 1;
                int colTrackLength    = fc.IndexOf(Field.TrackLength) + 1;
                int colTrackRating    = fc.IndexOf(Field.TrackRating) + 1;
                int colTrackArtist    = fc.IndexOf(Field.ArtistTrackName) + 1;
                int colTrackComposer  = fc.IndexOf(Field.ComposerTrackName) + 1;
                int colTrackSoundFile = fc.IndexOf(Field.TrackSoundFile) + 1;
                int colTrackID        = 0;

                object[] values;

                while ((values = view.Read()) != null)
                {
                    string artistDisplay = values[colArtistName] is DBNull ? "" : (string)values[colArtistName];
                    string artist        = values[colArtistSaveAs] is DBNull ? "" : (string)values[colArtistSaveAs];
                    string title         = values[colTitle] is DBNull ? "" : (string)values[colTitle];
                    int    cdid          = (int)values[colCDID];

                    if (cdid != lastcdid)
                    {
                        if (newItem != null)
                        {
                            if (newItem.Artist != lastArtistTitle)
                            {
                                AlbumViewTitle albumTitle = new AlbumViewTitle();
                                albumTitle.Title = newItem.Artist;
                                items.Add(albumTitle);

                                lastArtistTitle = newItem.Artist;
                            }

                            items.Add(newItem);
                        }

                        newItem               = new AlbumViewItem();
                        newItem.ID            = cdid;
                        newItem.Artist        = artistDisplay;
                        newItem.Title         = title;
                        newItem.ImageFilename = values[colFrontCover] is DBNull ? "" : (string)values[colFrontCover];
                        newItem.Genre         = values[colCategory] is DBNull ? "" : (string)values[colCategory];
                        newItem.ArchiveNumber = values[colArchiveNumber] is DBNull ? "" : (string)values[colArchiveNumber];
                        int yearRecorded = values[colYearRecorded] is DBNull ? 0 : (int)values[colYearRecorded];
                        if (yearRecorded > 0)
                        {
                            newItem.Year = yearRecorded.ToString();
                        }

                        newItem.Tracks = new SafeObservableCollection <Track>();
                        lastArtist     = artist;
                        lastTitle      = title;
                    }

                    if (newItem != null)
                    {
                        Track track = new Track();
                        track.TrackNumber = (int)values[colTrackNumber];
                        track.Title       = values[colTrackTitle] is DBNull ? "" : (string)values[colTrackTitle];
                        track.Length      = (int)values[colTrackLength];
                        track.Rating      = values[colTrackRating] is DBNull ? 0 : (int)values[colTrackRating];
                        track.Artist      = values[colTrackArtist] is DBNull ? "" : (string)values[colTrackArtist];
                        track.Composer    = values[colTrackComposer] is DBNull ? "" : (string)values[colTrackComposer];
                        track.Soundfile   = values[colTrackSoundFile] is DBNull ? "" : (string)values[colTrackSoundFile];
                        track.CDID        = cdid;
                        track.ID          = (int)values[colTrackID];

                        newItem.Tracks.Add(track);
                    }

                    //toolStripStatusProgressBar.Value = (int)(100.0 / TrackView.Rows.Count * count);

                    count++;

                    lastcdid = cdid;
                }
            }


            if (newItem != null)
            {
                if (newItem.Artist != lastArtistTitle)
                {
                    AlbumViewTitle albumTitle = new AlbumViewTitle();
                    albumTitle.Title = newItem.Artist;
                    items.Add(albumTitle);
                }

                items.Add(newItem);
            }

            e.Result = items;
        }