[mapguide-commits] r4867 - in sandbox/maestro-2.5/Maestro.Base: .
Properties Resources UI
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Thu May 13 03:49:04 EDT 2010
Author: jng
Date: 2010-05-13 03:49:03 -0400 (Thu, 13 May 2010)
New Revision: 4867
Added:
sandbox/maestro-2.5/Maestro.Base/Resources/cross-small.png
Modified:
sandbox/maestro-2.5/Maestro.Base/Maestro.Base.csproj
sandbox/maestro-2.5/Maestro.Base/Properties/Resources.Designer.cs
sandbox/maestro-2.5/Maestro.Base/Properties/Resources.resx
sandbox/maestro-2.5/Maestro.Base/TabFactory.cs
sandbox/maestro-2.5/Maestro.Base/UI/MessageViewer.cs
sandbox/maestro-2.5/Maestro.Base/UI/SiteExplorer.cs
sandbox/maestro-2.5/Maestro.Base/ZonedContainer.Designer.cs
sandbox/maestro-2.5/Maestro.Base/ZonedContainer.cs
Log:
This submission adds support for closing of individual tabs. Only tabs where AllowUserClose = true are closeable and will have close buttons on their tabs.
Modified: sandbox/maestro-2.5/Maestro.Base/Maestro.Base.csproj
===================================================================
--- sandbox/maestro-2.5/Maestro.Base/Maestro.Base.csproj 2010-05-13 06:19:47 UTC (rev 4866)
+++ sandbox/maestro-2.5/Maestro.Base/Maestro.Base.csproj 2010-05-13 07:49:03 UTC (rev 4867)
@@ -123,6 +123,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="Maestro.Base.addin" />
+ <None Include="Resources\cross-small.png" />
<None Include="Resources\tick.png" />
<None Include="Resources\clock.png" />
<None Include="Resources\document-code.png" />
Modified: sandbox/maestro-2.5/Maestro.Base/Properties/Resources.Designer.cs
===================================================================
--- sandbox/maestro-2.5/Maestro.Base/Properties/Resources.Designer.cs 2010-05-13 06:19:47 UTC (rev 4866)
+++ sandbox/maestro-2.5/Maestro.Base/Properties/Resources.Designer.cs 2010-05-13 07:49:03 UTC (rev 4867)
@@ -188,6 +188,13 @@
}
}
+ internal static System.Drawing.Bitmap cross_small {
+ get {
+ object obj = ResourceManager.GetObject("cross_small", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
internal static System.Drawing.Bitmap disk {
get {
object obj = ResourceManager.GetObject("disk", resourceCulture);
Modified: sandbox/maestro-2.5/Maestro.Base/Properties/Resources.resx
===================================================================
--- sandbox/maestro-2.5/Maestro.Base/Properties/Resources.resx 2010-05-13 06:19:47 UTC (rev 4866)
+++ sandbox/maestro-2.5/Maestro.Base/Properties/Resources.resx 2010-05-13 07:49:03 UTC (rev 4867)
@@ -280,4 +280,7 @@
<data name="tick" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\tick.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
+ <data name="cross_small" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\cross-small.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
</root>
\ No newline at end of file
Added: sandbox/maestro-2.5/Maestro.Base/Resources/cross-small.png
===================================================================
(Binary files differ)
Property changes on: sandbox/maestro-2.5/Maestro.Base/Resources/cross-small.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: sandbox/maestro-2.5/Maestro.Base/TabFactory.cs
===================================================================
--- sandbox/maestro-2.5/Maestro.Base/TabFactory.cs 2010-05-13 06:19:47 UTC (rev 4866)
+++ sandbox/maestro-2.5/Maestro.Base/TabFactory.cs 2010-05-13 07:49:03 UTC (rev 4867)
@@ -26,16 +26,18 @@
{
internal static class TabFactory
{
+ const string SPACE_HACK = ""; //HACK: Give enough space for a close button to be drawn
+
internal static TabPage CreateTab(IViewContent content, string imgKey)
{
TabPage page = new TabPage();
page.ImageKey = imgKey;
- page.Text = content.Title;
- page.ToolTipText = content.Title;
+ page.Text = content.Title + SPACE_HACK;
+ page.ToolTipText = content.Description;
page.Tag = content.AllowUserClose;
content.TitleChanged += (sender, e) =>
- {
- page.Text = content.Title;
+ {
+ page.Text = content.Title + SPACE_HACK; //HACK: Give enough space for a close button to be drawn
};
content.DescriptionChanged += (sender, e) =>
{
Modified: sandbox/maestro-2.5/Maestro.Base/UI/MessageViewer.cs
===================================================================
--- sandbox/maestro-2.5/Maestro.Base/UI/MessageViewer.cs 2010-05-13 06:19:47 UTC (rev 4866)
+++ sandbox/maestro-2.5/Maestro.Base/UI/MessageViewer.cs 2010-05-13 07:49:03 UTC (rev 4867)
@@ -54,5 +54,13 @@
{
_messages.Add(msg);
}
+
+ public override bool AllowUserClose
+ {
+ get
+ {
+ return true;
+ }
+ }
}
}
Modified: sandbox/maestro-2.5/Maestro.Base/UI/SiteExplorer.cs
===================================================================
--- sandbox/maestro-2.5/Maestro.Base/UI/SiteExplorer.cs 2010-05-13 06:19:47 UTC (rev 4866)
+++ sandbox/maestro-2.5/Maestro.Base/UI/SiteExplorer.cs 2010-05-13 07:49:03 UTC (rev 4867)
@@ -63,5 +63,13 @@
this.Controls.Add(trvResources);
this.Controls.Add(toolStrip);
}
+
+ public override bool AllowUserClose
+ {
+ get
+ {
+ return false;
+ }
+ }
}
}
Modified: sandbox/maestro-2.5/Maestro.Base/ZonedContainer.Designer.cs
===================================================================
--- sandbox/maestro-2.5/Maestro.Base/ZonedContainer.Designer.cs 2010-05-13 06:19:47 UTC (rev 4866)
+++ sandbox/maestro-2.5/Maestro.Base/ZonedContainer.Designer.cs 2010-05-13 07:49:03 UTC (rev 4867)
@@ -73,13 +73,18 @@
// leftZone
//
this.leftZone.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.leftZone.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
+ this.leftZone.HotTrack = true;
this.leftZone.ImageList = this.leftImgList;
this.leftZone.Location = new System.Drawing.Point(0, 0);
this.leftZone.Name = "leftZone";
+ this.leftZone.Padding = new System.Drawing.Point(12, 3);
this.leftZone.SelectedIndex = 0;
this.leftZone.ShowToolTips = true;
this.leftZone.Size = new System.Drawing.Size(240, 444);
this.leftZone.TabIndex = 0;
+ this.leftZone.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ZoneDrawItem);
+ this.leftZone.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ZoneMouseClick);
//
// leftImgList
//
@@ -134,13 +139,18 @@
// documentTabs
//
this.documentTabs.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.documentTabs.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
+ this.documentTabs.HotTrack = true;
this.documentTabs.ImageList = this.docImgList;
this.documentTabs.Location = new System.Drawing.Point(0, 0);
this.documentTabs.Name = "documentTabs";
+ this.documentTabs.Padding = new System.Drawing.Point(12, 3);
this.documentTabs.SelectedIndex = 0;
this.documentTabs.ShowToolTips = true;
this.documentTabs.Size = new System.Drawing.Size(240, 259);
this.documentTabs.TabIndex = 0;
+ this.documentTabs.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ZoneDrawItem);
+ this.documentTabs.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ZoneMouseClick);
//
// docImgList
//
@@ -151,13 +161,18 @@
// bottomZone
//
this.bottomZone.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.bottomZone.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
+ this.bottomZone.HotTrack = true;
this.bottomZone.ImageList = this.bottomImgList;
this.bottomZone.Location = new System.Drawing.Point(0, 0);
this.bottomZone.Name = "bottomZone";
+ this.bottomZone.Padding = new System.Drawing.Point(12, 3);
this.bottomZone.SelectedIndex = 0;
this.bottomZone.ShowToolTips = true;
this.bottomZone.Size = new System.Drawing.Size(240, 181);
this.bottomZone.TabIndex = 0;
+ this.bottomZone.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ZoneDrawItem);
+ this.bottomZone.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ZoneMouseClick);
//
// bottomImgList
//
@@ -168,13 +183,18 @@
// rightZone
//
this.rightZone.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.rightZone.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
+ this.rightZone.HotTrack = true;
this.rightZone.ImageList = this.rightImgList;
this.rightZone.Location = new System.Drawing.Point(0, 0);
this.rightZone.Name = "rightZone";
+ this.rightZone.Padding = new System.Drawing.Point(12, 3);
this.rightZone.SelectedIndex = 0;
this.rightZone.ShowToolTips = true;
this.rightZone.Size = new System.Drawing.Size(138, 444);
this.rightZone.TabIndex = 0;
+ this.rightZone.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ZoneDrawItem);
+ this.rightZone.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ZoneMouseClick);
//
// rightImgList
//
Modified: sandbox/maestro-2.5/Maestro.Base/ZonedContainer.cs
===================================================================
--- sandbox/maestro-2.5/Maestro.Base/ZonedContainer.cs 2010-05-13 06:19:47 UTC (rev 4866)
+++ sandbox/maestro-2.5/Maestro.Base/ZonedContainer.cs 2010-05-13 07:49:03 UTC (rev 4867)
@@ -24,6 +24,7 @@
using System.Data;
using System.Text;
using System.Windows.Forms;
+using System.Windows.Forms.VisualStyles;
namespace Maestro.Base
{
@@ -51,7 +52,6 @@
{
TabControl zone = null;
ImageList zoneImgList = null;
- string key = null;
switch (region)
{
case ViewRegion.Bottom:
@@ -79,5 +79,80 @@
zone.SelectedTab = page;
CheckContainerStatus();
}
+
+ //
+ // http://blog.bitsabound.com/2009/05/19/DrawingCaptionButtonsOnTabPages.aspx
+ //
+ private void DrawTabCloseButton(System.Windows.Forms.DrawItemEventArgs e, Rectangle rect, VisualStyleElement style, ButtonState state)
+ {
+ if (VisualStyleRenderer.IsSupported)
+ {
+ if (VisualStyleRenderer.IsElementDefined(style))
+ {
+ VisualStyleRenderer renderer = new VisualStyleRenderer(style);
+ renderer.DrawBackground(e.Graphics, rect);
+ return;
+ }
+ }
+ ControlPaint.DrawCaptionButton(e.Graphics, rect, CaptionButton.Close, state);
+ }
+
+ // Close button on tabs implementation
+ //
+ // http://www.dotnetspider.com/resources/29206-Custom-drawn-Close-button-TabControl.aspx
+
+ private Point _imageLocation = new Point(17, 4);
+ private Point _imgHitArea = new Point(15, 2);
+
+ private void ZoneDrawItem(object sender, DrawItemEventArgs e)
+ {
+ TabControl tab = (TabControl)sender;
+ //The tag specifies whether the user can manually close this tab
+ bool draw = (bool)tab.TabPages[e.Index].Tag;
+
+ try
+ {
+ Rectangle r = e.Bounds;
+ r = tab.GetTabRect(e.Index);
+ r.Offset(2, 2);
+
+ Brush TitleBrush = new SolidBrush(Color.Black);
+ Font f = this.Font;
+
+ string title = tab.TabPages[e.Index].Text;
+
+ var tabRect = tab.GetTabRect(e.Index);
+
+ e.Graphics.FillRectangle(new SolidBrush(SystemColors.ControlLightLight), tabRect);
+ e.Graphics.DrawString(title, f, TitleBrush, new Point(r.X, r.Y));
+
+ if (draw)
+ {
+ //Close Image to draw
+ Image img = Properties.Resources.cross_small;
+ e.Graphics.DrawImage(img, new Point(r.X + (tab.GetTabRect(e.Index).Width - _imageLocation.X), _imageLocation.Y));
+ }
+ }
+ catch { }
+ }
+
+ private void ZoneMouseClick(object sender, MouseEventArgs e)
+ {
+ TabControl tc = (TabControl)sender;
+ Point p = e.Location;
+ int _tabWidth = 0;
+ _tabWidth = tc.GetTabRect(tc.SelectedIndex).Width - (_imgHitArea.X);
+ Rectangle r = tc.GetTabRect(tc.SelectedIndex);
+ r.Offset(_tabWidth, _imgHitArea.Y);
+ r.Width = 16;
+ r.Height = 16;
+ if (r.Contains(p))
+ {
+ TabPage page = (TabPage)tc.TabPages[tc.SelectedIndex];
+ //The tag specifies whether the user can manually close this tab
+ if ((bool)page.Tag)
+ tc.TabPages.Remove(page);
+ }
+ }
}
}
More information about the mapguide-commits
mailing list