File size: 7,342 Bytes
e26fba6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using System.Linq;
using MovieTube.Client.Scraper;
namespace MovieTube.Viewer.Controls
{
public partial class BrowseGalleryWidget : GalleryWidgetBase
{
public BrowseGalleryWidget()
{
InitializeComponent();
}
#region Methods
protected override void OnAddItems(MoviePage page)
{
this.flowLayoutPanel.SuspendLayout();
var rand = new Random(DateTime.Now.Minute);
var next = 4;
for (var i = 0; i < Constants.GetMaxDisplayCount(page.Videos.Count); i++)
{
var movie = page.Videos[i];
var widget = new WebViewWidget(movie,
Properties.Resources.TestHtml.Replace("{0}", movie.Url)
.Replace("{1}", String.IsNullOrEmpty(movie.ImageUrl) ? "no_image.gif" : movie.ImageUrl)
.Replace("{2}", movie.Name)
.Replace("{3}", movie.ReleaseDate.Year.ToString())
.Replace("{4}", movie.Description)
.Replace("{5}", movie.LanguageText));
this.flowLayoutPanel.Controls.Add(widget);
widget.ViewSelected += delegate(object sender, GalleryItemSelectedEventArgs e)
{
OnItemSelected(sender, e);
};
widget.Favourited += delegate(object sender, GalleryItemFavouriteEventArgs e)
{
OnItemFavourited(sender, e);
};
if (Constants.ShowAds )
{
if (next == 0)
{
var ad = CreateAdWidget(Constants.HorizontalAdId);
this.flowLayoutPanel.Controls.Add(ad);
next = rand.Next(4, 8);
}
else
next--;
}
}
flowLayoutPanel_Resize(this, null);
// AddLinks();
this.flowLayoutPanel.ResumeLayout();
base.OnAddItems(page);
}
protected override Control WidgetContainer
{
get
{
return this.flowLayoutPanel;
}
}
#endregion
private void flowLayoutPanel_Resize(object sender, EventArgs e)
{
this.flowLayoutPanel.SuspendLayout();
if (this.flowLayoutPanel.Controls.Count > 0)
{
var width = this.flowLayoutPanel.Controls[0].Width;
this.flowLayoutPanel.ColumnCount = this.flowLayoutPanel.ClientRectangle.Width / this.flowLayoutPanel.Controls[0].Width;
if (this.flowLayoutPanel.ColumnCount > 0)
{
var freeWidth = (this.flowLayoutPanel.ClientRectangle.Width -
(this.flowLayoutPanel.Controls[0].Width * this.flowLayoutPanel.ColumnCount)) /
this.flowLayoutPanel.ColumnCount;
if (freeWidth > 0)
{
foreach (Control c in this.flowLayoutPanel.Controls)
c.Margin = new Padding(freeWidth / 2, 10, freeWidth / 2, 0);
}
}
}
ResizePageLinks();
this.flowLayoutPanel.ResumeLayout();
}
private void AddLinks()
{
//this.flowLayoutPanelPaging.Controls.Clear();
//if (base.currentPage == null || base.currentPage.Links.Count == 0)
// return;
//this.flowLayoutPanelPaging.Padding = new Padding(0);
//var totalWidth = 0;
//foreach (var p in base.currentPage.Links)
//{
// if (totalWidth >= this.flowLayoutPanelPaging.ClientSize.Width)
// break;
// var b = CreatePageLink(p);
// totalWidth += b.Width;
// this.flowLayoutPanelPaging.Controls.Add(b);
//}
//ResizePageLinks();
}
private void ResizePageLinks()
{
//var totalWidth = 0;
//foreach (Control b in this.flowLayoutPanelPaging.Controls)
// totalWidth += b.Width;
//if (totalWidth < this.flowLayoutPanelPaging.ClientSize.Width)
//{
// var freeWidth = this.flowLayoutPanelPaging.ClientSize.Width - totalWidth;
// this.flowLayoutPanelPaging.Padding = new Padding(freeWidth / 2, 0, freeWidth / 2, 0);
//}
//else
// this.flowLayoutPanelPaging.Padding = new Padding(0);
}
private void UpdatePagingButtons(KryptonCheckButton button)
{
//foreach (KryptonCheckButton b in this.flowLayoutPanelPaging.Controls)
// b.Checked = b == button ? true : false;
}
private KryptonCheckButton CreatePageLink( PagingLink link)
{
var button = new KryptonCheckButton();
button.ButtonStyle = ComponentFactory.Krypton.Toolkit.ButtonStyle.LowProfile;
button.Cursor = System.Windows.Forms.Cursors.Hand;
button.Location = new System.Drawing.Point(0, 0);
button.Margin = new System.Windows.Forms.Padding(0);
button.Size = link.Text.Length == 1 ? new System.Drawing.Size(29, 25) : new System.Drawing.Size(10 + ( link.Text.Length * 10), 25);
button.StateCommon.Border.DrawBorders = ((ComponentFactory.Krypton.Toolkit.PaletteDrawBorders)((((ComponentFactory.Krypton.Toolkit.PaletteDrawBorders.Top | ComponentFactory.Krypton.Toolkit.PaletteDrawBorders.Bottom)
| ComponentFactory.Krypton.Toolkit.PaletteDrawBorders.Left)
| ComponentFactory.Krypton.Toolkit.PaletteDrawBorders.Right)));
button.StateCommon.Border.Width = 1;
button.StateCommon.Content.ShortText.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
button.Values.Text = link.Text;
button.Tag = link;
button.Checked = link.IsSelected;
button.CheckedChanged += delegate(object sender, EventArgs e)
{
var b = (KryptonCheckButton)sender;
if (b.Checked)
{
OnPageSelected(this, new GalleryPageSelectedEventArgs(link));
UpdatePagingButtons(b);
}
};
return button;
}
public bool ShowHeader
{
get
{
return this.kryptonLabel1.Visible;
}
set
{
this.kryptonLabel1.Visible = value;
this.splitContainer.SplitterDistance = 0;
}
}
}
}
|