Exemplo n.º 1
0
        private void AddOneBook(Book.BookInfo bookInfo, FlowLayoutPanel flowLayoutPanel)
        {
            var button = new Button()
            {
                Size = new Size(90, 110)
            };

            button.Text = ShortenTitleIfNeeded(bookInfo.QuickTitleUserDisplay);
            button.TextImageRelation         = TextImageRelation.ImageAboveText;
            button.ImageAlign                = ContentAlignment.TopCenter;
            button.TextAlign                 = ContentAlignment.BottomCenter;
            button.FlatStyle                 = FlatStyle.Flat;
            button.ForeColor                 = Palette.TextAgainstDarkBackground;
            button.FlatAppearance.BorderSize = 0;
            button.ContextMenuStrip          = _bookContextMenu;
            button.MouseDown                += OnClickBook; //we need this for right-click menu selection, which needs to 1st select the book
            //doesn't work: item.DoubleClick += (sender,arg)=>_model.DoubleClickedBook();

            button.Font = bookInfo.IsEditable ? _editableBookFont : _collectionBookFont;


            button.Tag = bookInfo;


            Image thumbnail = Resources.PagePlaceHolder;;

            _bookThumbnails.Images.Add(bookInfo.Id, thumbnail);
            button.ImageIndex = _bookThumbnails.Images.Count - 1;
            flowLayoutPanel.Controls.Add(button);

            Image img;

            //review: we could do this at idle time, too:
            if (bookInfo.TryGetPremadeThumbnail(out img))
            {
                RefreshOneThumbnail(bookInfo, img);
            }
            else
            {
                //show this one for now, in the background someone will do the slow work of getting us a better one
                RefreshOneThumbnail(bookInfo, Resources.placeHolderBookThumbnail);
                //hack to signal that we need to make a real one when get a chance
                button.ImageIndex = 999;
            }
            _buttonsNeedingSlowUpdate.Enqueue(button);

//			bookInfo.GetThumbNailOfBookCoverAsync(bookInfo.Type != Book.Book.BookType.Publication,
//				                                  image => RefreshOneThumbnail(bookInfo, image),
//												  error=> RefreshOneThumbnail(bookInfo, Resources.Error70x70));
        }
        private void AddOneBook(Book.BookInfo bookInfo, FlowLayoutPanel flowLayoutPanel, bool localizeTitle)
        {
            var button = new Button()
            {
                Size = new Size(90, 110)
            };
            string title = bookInfo.QuickTitleUserDisplay;

            if (localizeTitle)
            {
                title = LocalizationManager.GetDynamicString("Bloom", "Template." + title, title);
            }

            button.Text = ShortenTitleIfNeeded(title);
            button.TextImageRelation         = TextImageRelation.ImageAboveText;
            button.ImageAlign                = ContentAlignment.TopCenter;
            button.TextAlign                 = ContentAlignment.BottomCenter;
            button.FlatStyle                 = FlatStyle.Flat;
            button.ForeColor                 = Palette.TextAgainstDarkBackground;
            button.FlatAppearance.BorderSize = 0;
            button.UseMnemonic               = false;       //otherwise, it tries to interpret '&' as a shortcut
            button.ContextMenuStrip          = _bookContextMenu;
            button.MouseDown                += OnClickBook; //we need this for right-click menu selection, which needs to 1st select the book
            //doesn't work: item.DoubleClick += (sender,arg)=>_model.DoubleClickedBook();

            button.Font = bookInfo.IsEditable ? _editableBookFont : _collectionBookFont;

            // Setting the AutoEllipsis property is strange but makes it behave the same on
            // Windows and Linux. Despite its name it won't show an ellipsis but wrap the line
            // at a word boundary if the text is too long (at least if the height is large
            // enough - didn't try what happens if the text doesn't fit in multiple lines)
            button.AutoEllipsis = true;
            button.AutoSize     = false;

            button.Tag = bookInfo;


            Image thumbnail = Resources.PagePlaceHolder;;

            _bookThumbnails.Images.Add(bookInfo.Id, thumbnail);
            button.ImageIndex = _bookThumbnails.Images.Count - 1;
            flowLayoutPanel.Controls.Add(button);

            Image img;

            //review: we could do this at idle time, too:
            if (bookInfo.TryGetPremadeThumbnail(out img))
            {
                RefreshOneThumbnail(bookInfo, img);
            }
            else
            {
                //show this one for now, in the background someone will do the slow work of getting us a better one
                RefreshOneThumbnail(bookInfo, Resources.placeHolderBookThumbnail);
                //hack to signal that we need to make a real one when get a chance
                button.ImageIndex = 999;
            }
            _buttonsNeedingSlowUpdate.Enqueue(button);

//			bookInfo.GetThumbNailOfBookCoverAsync(bookInfo.Type != Book.Book.BookType.Publication,
//				                                  image => RefreshOneThumbnail(bookInfo, image),
//												  error=> RefreshOneThumbnail(bookInfo, Resources.Error70x70));
        }