public int Add(OutlookBarBand band) { if (Contains(band)) return -1; int index = InnerList.Add(band); RaiseChanged(); return index; }
public void Remove(OutlookBarBand band) { // Make sure currentBandIndex is always valid int currentBandIndex = parentBar.GetCurrentBand(); bool updateCurrentIndex = currentBandIndex != -1 && currentBandIndex == Count - 1; InnerList.Remove(band); if ( updateCurrentIndex ) { // Since we just removed the currently selected band, // set the new selected band to last band if ( Count > 0 ) parentBar.SetCurrentBand(Count-1); } RaiseChanged(); }
public int IndexOf(OutlookBarBand band) { return InnerList.IndexOf(band); }
void DrawItem(Graphics g, int index, Rectangle itemRect, bool hot, bool pressed, Rectangle targetRect, OutlookBarBand drawingBand) { OutlookBarBand band = bands[currentBandIndex]; if (drawingBand != null) band = drawingBand; Point pt = new Point(0, 0); // Set clip region so that we don't draw outside the viewport Rectangle viewPortRect = GetViewPortRect(); if (targetRect != Rectangle.Empty) viewPortRect = targetRect; using (Region clippingRegion = new Region(viewPortRect)) { g.Clip = clippingRegion; // Clip the arrow buttons g.ExcludeClip(downArrowRect); g.ExcludeClip(upArrowRect); Color textColor = band.TextColor; Color backColor = band.Background; Color highLight = band.Background; if (ColorUtil.UsingCustomColor) { backColor = ColorUtil.VSNetControlColor; highLight = ColorUtil.VSNetControlColor; } if (hot) { backColor = ColorUtil.VSNetSelectionColor; highLight = ColorUtil.VSNetBorderColor; } if (pressed) backColor = ColorUtil.VSNetPressedColor; //john hatton jdh if (band.Items[index].Selected) highLight = Color.Blue; if (band.IconView == IconView.Large && band.LargeImageList != null) { Size largeImageSize = band.LargeImageList.ImageSize; pt.X = itemRect.Left + (viewPortRect.Width - largeImageSize.Width) / 2; pt.Y = itemRect.Top; Rectangle iconRect = new Rectangle(pt, largeImageSize); using (Brush b = new SolidBrush(backColor)) { iconRect.Inflate(2, 2); if (backgroundBitmap != null) { g.DrawImage(backgroundBitmap, iconRect, iconRect, GraphicsUnit.Pixel); // If we have a background bitmap, draw the item background // only during the hot state if (hot) { g.FillRectangle(b, iconRect.Left, iconRect.Top, iconRect.Width, iconRect.Height); } } else { // If we don't have a background, always draw the // item backgound g.FillRectangle(b, iconRect.Left, iconRect.Top, iconRect.Width, iconRect.Height); } using (Pen p = new Pen(highLight)) { if (backgroundBitmap == null || hot == true) { g.DrawRectangle(p, iconRect.Left, iconRect.Top, iconRect.Width - 1, iconRect.Height - 1); } } } // I dont' use the image list to do the drawing because cliping does not work if (band.Items[index].ImageIndex != -1 && band.LargeImageList != null) { // Only if we have a valid image index g.SmoothingMode = SmoothingMode.HighQuality; g.DrawImage(band.LargeImageList.Images[band.Items[index].ImageIndex], pt); g.SmoothingMode = SmoothingMode.Default; } // Draw the label int top = itemRect.Top + largeImageSize.Height + Y_LARGEICON_LABEL_OFFSET; Size textSize = GetLabelSize(g, band, index); int left = itemRect.Left + (viewPortRect.Width - textSize.Width) / 2; using (Brush b = new SolidBrush(textColor)) { g.DrawString(band.Items[index].Text, Font, b, new Point(left, top)); } // Reset clip region to the whole rectangle so that the arrows can be painted g.Clip = new Region(viewPortRect); } else if (band.IconView == IconView.Small && band.SmallImageList != null) { Size smallImageSize = band.SmallImageList.ImageSize; pt.X = itemRect.Left; pt.Y = itemRect.Top + (itemRect.Height - smallImageSize.Height) / 2; Rectangle iconRect = new Rectangle(pt, smallImageSize); using (Brush b = new SolidBrush(backColor)) { iconRect.Inflate(1, 1); if (backgroundBitmap != null) { g.DrawImage(backgroundBitmap, iconRect, iconRect, GraphicsUnit.Pixel); // If we have a background bitmap, draw the item background // only during the hot state if (hot) { g.FillRectangle(b, iconRect.Left, iconRect.Top, iconRect.Width, iconRect.Height); } } else { // If we don't have a background, always draw the // item backgound g.FillRectangle(b, iconRect.Left, iconRect.Top, iconRect.Width, iconRect.Height); } using (Pen p = new Pen(highLight)) { if (backgroundBitmap == null || hot == true) { g.DrawRectangle(p, iconRect.Left, iconRect.Top, iconRect.Width - 1, iconRect.Height - 1); } } } // I dont' use the image list to do the drawing because cliping does not work if (band.Items[index].ImageIndex != -1 && band.SmallImageList != null) { // Only if we have a valid image index g.DrawImage(band.SmallImageList.Images[band.Items[index].ImageIndex], pt); } // Draw the label Size labelSize = GetLabelSize(g, band, index); pt.X = pt.X + smallImageSize.Width + X_SMALLICON_LABEL_OFFSET; pt.Y = itemRect.Top + (itemRect.Height - labelSize.Height) / 2; using (Brush b = new SolidBrush(textColor)) { g.DrawString(band.Items[index].Text, Font, b, pt); } } } }
public Rectangle GetItemRect(Graphics g, OutlookBarBand band, int index, Rectangle targetRect) { Rectangle rc = GetViewPortRect(); if ( targetRect != Rectangle.Empty ) rc = targetRect; Size itemSize = new Size(0,0); int top = rc.Top; int y = 0; for ( int i = 0; i < index; i++ ) { itemSize = GetItemSize(g, band, i, ItemSizeType.All); top += itemSize.Height; if ( band.IconView == IconView.Small ) top += Y_SMALLICON_SPACING; else top += Y_LARGEICON_SPACING; if ( i == (firstItem - 1) ) { // Subtract the hidden items height y = top - rc.Top; } } itemSize = GetItemSize(g, band, index, ItemSizeType.All); int margin = SMALL_TOP_MARGIN; if ( band.IconView == IconView.Large ) margin = LARGE_TOP_MARGIN; // Work with Windows Rect is easier to change settings RECT rcItem = new RECT(); rcItem.left = rc.Left; rcItem.top = top; rcItem.right = rc.Left + itemSize.Width; rcItem.bottom = top + itemSize.Height; // Adjust rectangle rcItem.top -= y; rcItem.bottom -= y; rcItem.top += margin; rcItem.bottom += margin; if ( band.IconView == IconView.Small ) { rcItem.left = rc.Left + LEFT_MARGIN; rcItem.right = rc.Right; } // Construct final rectangle Rectangle actualRect = new Rectangle(rcItem.left, rcItem.top, rcItem.right - rcItem.left, rcItem.bottom - rcItem.top); return actualRect; }
public bool Contains(OutlookBarBand band) { return InnerList.Contains(band); }
Size GetItemSize(Graphics g, OutlookBarBand band, int itemIndex, ItemSizeType itemSizeType) { Size iconSize = new Size(0,0); Size labelSize = new Size(0,0); if ( itemSizeType == ItemSizeType.Icon || itemSizeType == ItemSizeType.All ) { iconSize = GetIconSize(band); if (itemSizeType == ItemSizeType.Icon) return iconSize; } if ( itemSizeType == ItemSizeType.Label || itemSizeType == ItemSizeType.All ) { labelSize = GetLabelSize(g, band, itemIndex); if ( itemSizeType == ItemSizeType.Label ) return labelSize; } if ( itemSizeType == ItemSizeType.All ) { if ( band.IconView == IconView.Small ) return new Size(iconSize.Width + labelSize.Width + X_SMALLICON_LABEL_OFFSET, iconSize.Height > labelSize.Height?iconSize.Height:labelSize.Height); else return new Size(iconSize.Width>labelSize.Width?iconSize.Width:labelSize.Width, iconSize.Height + labelSize.Height + Y_LARGEICON_LABEL_OFFSET + Y_LARGEICON_SPACING); } return new Size(0,0); }
Size GetLabelSize(Graphics g, OutlookBarBand band, int itemIndex) { Size textSize = new Size(0,0); if ( band.IconView == IconView.Large ) { // Calculate text rectangle including word breaks if needed Rectangle rect = GetViewPortRect(); Rectangle textRect = Rectangle.FromLTRB(rect.Left, rect.Top, rect.Width, rect.Top); // The TextUtil function is going to call GDI, but the Graphics object // is already being used by GDI+. Pass a null reference so that the TextUtil // function uses the Screen Device to calculate the text size if ( band.Items[itemIndex].Text != null ) { textSize = TextUtil.GetTextSize(null, band.Items[itemIndex].Text, Font, ref textRect, DrawTextFormatFlags.DT_CALCRECT | DrawTextFormatFlags.DT_CENTER|DrawTextFormatFlags.DT_WORDBREAK); } return textSize; } else { // Same as above // Calculate text rectangle single line if ( band.Items[itemIndex].Text != null ) { textSize = TextUtil.GetTextSize(null, band.Items[itemIndex].Text, Font); } return textSize; } }
void DrawItems(Graphics g, Rectangle targetRect, OutlookBarBand drawBand) { // If we don't have any bands just return if ( bands.Count == 0 ) return; Rectangle rc = GetViewPortRect(); OutlookBarBand band = bands[currentBandIndex]; if ( drawBand != null ) band = drawBand; Debug.Assert(band != null); for ( int i = firstItem; i < band.Items.Count; i++ ) { Rectangle itemRect = GetItemRect(g, band, i, targetRect); if ( itemRect.Top > rc.Bottom ) break; else DrawItem(g, i, itemRect, false, false, targetRect, drawBand); } }
Size GetIconSize(OutlookBarBand band) { if ( band.IconView == IconView.Large && band.LargeImageList != null ) return band.LargeImageList.ImageSize; else if ( band.IconView == IconView.Small && band.SmallImageList != null ) return band.SmallImageList.ImageSize; return new Size(0,0); }
void DrawBandBitmap(IntPtr hDC, OutlookBarBand band, int bandIndex, Rectangle drawingRect) { // Don't do GDI+ calls since you cannot mix them with GDI calls if ( !HasChild(bandIndex)) { Color cb = band.Background; IntPtr brush = WindowsAPI.CreateSolidBrush(ColorUtil.RGB(cb.R, cb.G, cb.B)); RECT rect; rect.left = drawingRect.Left; rect.top = drawingRect.Top; rect.right = drawingRect.Left + drawingRect.Width; rect.bottom = drawingRect.Top + drawingRect.Height; WindowsAPI.FillRect(hDC, ref rect, brush); WindowsAPI.DeleteObject(brush); } if ( HasChild(bandIndex) ) { // Paint child control into memory device context Control child = bands[bandIndex].ChildControl; bool visible = child.Visible; child.Visible = true; // Change viewport if needed WindowsAPI.SendMessage( child.Handle, (int)Msg.WM_ERASEBKGND, (int)hDC, 0); WindowsAPI.SendMessage( child.Handle, (int)Msg.WM_PAINT, (int)hDC, 0); if ( !visible) child.Visible = false; } else { DrawItems(Graphics.FromHdc(hDC), drawingRect, bands[bandIndex]); } }
/// <summary> /// The OutlookBar calls this when one of its properties changes, specifically, a different band is opened. /// </summary> /// <param name="band"></param> /// <param name="property"></param> public void PropertyChanged(OutlookBarBand band, OutlookBarProperty property) { if (property == OutlookBarProperty.CurrentBandChanged) { //int index =m_bar.GetCurrentBand(); //OutlookBarBand band = m_bar.Bands[index]; ChoiceGroup group = (ChoiceGroup) band.Tag; Debug.Assert(group != null); group.OnDisplay(this, null); } }
public void OnItemClicked(OutlookBarBand band, OutlookBarItem item) { ChoiceBase control = (ChoiceBase)item.Tag; control.OnClick(item, null); }
public void TabOpened(OutlookBarBand band, OutlookBarItem item) { Debug.WriteLine("opened"); }
protected void MakeButton(OutlookBarBand band , ChoiceBase control) { UIItemDisplayProperties display = control.GetDisplayProperties(); display.Text = display.Text.Replace("_", ""); OutlookBarItem button; // if(m_images!=null && m_images.ImageList.Images.Count>0) // { // button = new OutlookBarItem(display.Text,0,control); // } // else //no images have been supplied to us! button = new OutlookBarItem(); button.Tag = control; control.ReferenceWidget = button; if(band.IconView == SidebarLibrary.WinControls.IconView.Large) { if(m_largeImages.ImageList.Images.Count>0) button.ImageIndex = m_largeImages.GetImageIndex(display.ImageLabel); } else { if(m_smallImages.ImageList.Images.Count>0) button.ImageIndex = m_smallImages.GetImageIndex(display.ImageLabel); } button.Selected = display.Checked; button.Text = display.Text; // if(display.Checked) // button.Text = button.Text + " (X)"; if(!display.Enabled) button.Text = button.Text + " NA"; //note that this sidebar library we are using does not provide click events on individual items. //So we cannot wire them up here. band.Items.Add (button); }
private void MakeTree(ChoiceGroupCollection groupCollection, string label, out OutlookBarBand band) { TreeView tree = new TreeView(); tree.Tag=groupCollection; tree.AfterSelect += new TreeViewEventHandler(OnTreeNodeSelected); band = new OutlookBarBand(label, tree); }
public void CreateUIForChoiceGroupCollection(ChoiceGroupCollection groupCollection) { foreach(ChoiceGroup group in groupCollection) { // make band string label = group.Label; label = label.Replace("_", ""); OutlookBarBand band; if (group.HasSubGroups()) { MakeTree(groupCollection, label, out band); } else { band = new OutlookBarBand(label); } band.Tag=group; group.ReferenceWidget = band; // band.GotFocus += new System.EventHandler(group.OnDisplay); m_bar.Bands.Add(band); band.SmallImageList = m_smallImages.ImageList; band.LargeImageList = m_largeImages.ImageList; object s = m_mediator.PropertyTable.GetValue("SidebarSize"); if (s ==null || (string)s=="small") band.IconView= SidebarLibrary.WinControls.IconView.Small; else band.IconView= SidebarLibrary.WinControls.IconView.Large; band.Background = SystemColors.AppWorkspace; band.TextColor = Color.White; //note that I had to fix the outlook bar code I downloaded to make this work. //so if we download a new one and it stops working, go fix it again. band.Font = new Font("Microsoft Sans Serif", 12); } }