This project has moved. For the latest updates, please go here.
1

Closed

Add XtraTabbedMdiWorkSpace

description

Rather than adopting MdiWorkspace in sample Bank project and attaching it XtratabbedMdiManager, it would be better to introduce dedicated XtraTabbedMdiWorkSpace.
 
This will be inline with CAB philosophy and will sove many issues.
 
For instances, in former onClose, onClosing will never get fired when tabs removed. Which will result in workItems not being removed and many other side effects.
 
Thanks.

file attachments

Closed Jun 12, 2009 at 6:20 PM by husayt
Implemented in revision:34599

comments

husayt wrote Apr 15, 2009 at 12:10 PM

Here is the proposed solution. Which is more elegant than the one currently used in demo application. Analogous to MdiWorkspace in Cab UI we add XtraTabbedMdiWorkspace.

It will be nice if this code could be added to library.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Forms;
using CABDevExpress.SmartPartInfos;
using DevExpress.XtraTab;
using DevExpress.XtraTab.ViewInfo;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.CompositeUI.SmartParts;
using Microsoft.Practices.CompositeUI.Utility;
using Microsoft.Practices.CompositeUI.WinForms;
using DevExpress.XtraTabbedMdi;

namespace CABDevExpress.Workspaces
{
/// 
/// A workspace that displays smart parts within a 
/// 
/// 
/// 
[Description("XtraTabbedMdi Workspace")]
public class XtraTabbedMdiWorkspace : XtraWindowWorkspace
{
    private readonly XtraTabbedMdiManager tabbedMdiManager = new XtraTabbedMdiManager();
    private MdiMode mdiMode = MdiMode.Tabbed;
    private readonly Form parentMdiForm;

    public enum MdiMode
    {
        Tabbed,
        Windowed
    }

    /// 
    /// Initializes a new 
    /// 
    public XtraTabbedMdiWorkspace()
        : base()
    {
        Initialize();
    }

    /// 
    /// Initializes a new 
    /// 
    public XtraTabbedMdiWorkspace(Form parentForm)
        : base(parentForm)
    {
        tabbedMdiManager.MdiParent = parentForm;
        parentMdiForm = parentForm;
        parentMdiForm.IsMdiContainer = true;
        Initialize();
        SetMdiMode();

    }

    /// 
    /// Gets the parent MDI form.
    /// 
    public Form ParentMdiForm
    {
        get { return parentMdiForm; }
    }


    public void Initialize()
    {
        // 
        // tabbedMdiManager
        // 
        TabbedMdiManager.AllowDragDrop = DevExpress.Utils.DefaultBoolean.True;
        TabbedMdiManager.ClosePageButtonShowMode = DevExpress.XtraTab.ClosePageButtonShowMode.InActiveTabPageHeader;
        //tabbedMdiManager.Controller = this.barAndDockingController1;
        TabbedMdiManager.HeaderButtons = ((DevExpress.XtraTab.TabButtons)(((DevExpress.XtraTab.TabButtons.Next | DevExpress.XtraTab.TabButtons.Close)
                    | DevExpress.XtraTab.TabButtons.Default)));
        TabbedMdiManager.HeaderButtonsShowMode = DevExpress.XtraTab.TabButtonShowMode.Always;

        tabbedMdiManager.SelectedPageChanged += new System.EventHandler(this.xtraTabbedMdiManager_SelectedPageChanged);
        // tabbedMdiManager.PageRemoved += new DevExpress.XtraTabbedMdi.MdiTabPageEventHandler(this.xtraTabbedMdiManager_PageRemoved);
        tabbedMdiManager.PageAdded += new MdiTabPageEventHandler(tabbedMdiManager_PageAdded);

    }



    /// 
    /// Shows the form as a child of the specified .
    /// 
    /// 
The to show in the workspace.
    /// 
The information to use to show the smart part.
    protected override void OnShow(Control smartPart, XtraWindowSmartPartInfo smartPartInfo)
    {
        Form mdiChild = this.GetOrCreateForm(smartPart);

        SetWindowProperties(mdiChild, smartPartInfo);

        SetWindowLocation(mdiChild, smartPartInfo);

            mdiChild.Show();
            mdiChild.BringToFront();
            mdiChild.MdiParent = parentMdiForm;
    }

    /// 
    /// 
    /// 
    public XtraTabbedMdiManager TabbedMdiManager
    {
        get { return tabbedMdiManager; }
    }

    private void xtraTabbedMdiManager_SelectedPageChanged(object sender, EventArgs e)
    {
        XtraMdiTabPage page = tabbedMdiManager.SelectedPage;
        if (page != null)
            page.Image = page.MdiChild.Icon.ToBitmap();
    }

    void tabbedMdiManager_PageAdded(object sender, MdiTabPageEventArgs e)
    {
        e.Page.Image = e.Page.MdiChild.Icon.ToBitmap();
    }

    /// 
    /// 
    /// 
    public void MdiChangeMode()
    {
        mdiMode = (mdiMode == MdiMode.Tabbed) ? MdiMode.Windowed : MdiMode.Tabbed; // Toggle
        SetMdiMode(mdiMode);
    }

    private void SetMdiMode()
    {
        SetMdiMode(mdiMode);
    }

    private void SetMdiMode(MdiMode mode)
    {
        TabbedMdiManager.MdiParent = (mode == MdiMode.Tabbed) ? parentMdiForm : null;
    }

    /// 
    /// Set's Layout of Mdi Mode
    /// 
    /// 
one of the values of enum
    public void LayoutMdi(MdiLayout layout)
    {
        SetMdiMode(MdiMode.Windowed);
        TabbedMdiManager.MdiParent = null;
        parentMdiForm.LayoutMdi(layout);
    }


}
}

DevLynx wrote Apr 16, 2009 at 12:33 AM

That's a can do! Thanks for the code. No promises, but I'll attempt to incorporate this code this weekend. dlx

husayt wrote Apr 16, 2009 at 10:46 AM

Another positive effect of the change, that with it icons are displayed on tabs and they look much better then.

Also i forgot to attach the changed WindowMenuHelper class (find it below)
here is the change to BankShellApplication.cs :
        XtraTabbedMdiWorkspace ContentWorkspace = new XtraTabbedMdiWorkspace(Shell);
        RootWorkItem.Items.Add(ContentWorkspace, WorkspaceNames.ShellContentWorkspace);
       // RootWorkItem.Items.Add(Shell.NavBarWorkspace, WorkspaceNames.ShellNavBarWorkspace);
....
         RibbonWindowsMenu.Add(RootWorkItem, ContentWorkspace, Shell);
Don't forget to remove XtraTabbedMdi control from the main form, it is now a part of the workspace.


using System;
using System.Windows.Forms;
using CABDevExpress.Workspaces;
using DevExpress.XtraTabbedMdi;

namespace DCRMShell
{
internal class WindowMenuHelper
{
    private XtraTabbedMdiWorkspace mdiWorkspace;

    internal WindowMenuHelper() { }

    internal WindowMenuHelper(XtraTabbedMdiWorkspace mdiManager)
    {
        mdiWorkspace = mdiManager;
    }

    public XtraTabbedMdiWorkspace MdiManager
    {
        get { return mdiWorkspace; }
        set { mdiWorkspace = value; }
    }


    public void MdiChangeMode(object sender, EventArgs e)
    {
        mdiWorkspace.MdiChangeMode();
    }


    public void MdiLayoutCascade(object sender, EventArgs e)
    {
        mdiWorkspace.LayoutMdi(MdiLayout.Cascade);
    }

    public void MdiLayoutTileHorizontal(object sender, EventArgs e)
    {
        mdiWorkspace.LayoutMdi(MdiLayout.TileHorizontal);
    }

    public void MdiLayoutTileVertical(object sender, EventArgs e)
    {
        mdiWorkspace.LayoutMdi(MdiLayout.TileVertical);
    }

    public void MdiLayoutArrangeIcons(object sender, EventArgs e)
    {
        mdiWorkspace.LayoutMdi(MdiLayout.ArrangeIcons);
    }

}
}

DevLynx wrote Apr 18, 2009 at 3:27 PM

husayt, I'm having problems getting this to work, probably something I'm missing. Would it be possible for you to send a zipped copy of your CAB DevExpress Extension Kit source with these modifications so I can see what I might be missing? If so, you can send that to mreith {at} tetzel {dot} com

Thanks,
dlx

husayt wrote Apr 18, 2009 at 10:33 PM

Sure I will do it on monday. I don't have access to code now . meanwhile, could you tell me what is the problem you have. maybe I am indeed missing something.
Thanks
Huseyn

husayt wrote Apr 20, 2009 at 2:13 PM

Hi, see the patch attached. Along with mentioned workspace this patch solves, number of related issues occuring on tab switch, item removal and others.

Let me know if any issues.

Huseyn

husayt wrote Apr 20, 2009 at 2:28 PM

Sorry, forgot to mention that it was subversion patch file. you can easily apply it to your code with TortoiseSVN/Apply Patch menu item.

also better use this version.

DevLynx wrote Apr 21, 2009 at 12:37 PM

I got the patch and it appears to be working fine. I need to do a little more investigation and testing before I post the code. Thanks for your efforts.

dlx

husayt wrote Apr 21, 2009 at 2:19 PM

I am also very keen on this project being stable. Let me know if there are outstanding issues, where I can be helpful.

Thanks
Best. Huseyn

husayt wrote Jun 6, 2009 at 6:08 AM

Hi,
can you please apply this patch to repository.

So that others can also benefit from this.

Thanks.