Rich c34c604c11 Fixed DSO Framer:
1. Open Properly if all tabs are closed
2. Open to a full window view
3. Set Current Item in the Tab Control
Fixed Display Panel so that when you click on an item in an inactive panel, the item clicked-on become the selected item.
2008-01-11 22:00:54 +00:00

177 lines
4.8 KiB
C#

using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using VEPROMS.CSLA.Library;
using Volian.Controls.Library;
namespace Volian.Controls.Library
{
public partial class DSOTabPanel : DevComponents.DotNetBar.PanelDockContainer
{
private DisplayTabControl _MyTabControl;
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private AxDSOFramer.AxFramerControl _MyDSOFramer;
private static int _Count = 0;
private DocumentInfo _MyDocument;
private int _MyCount;
public static int Count
{
get { return _Count; }
set { _Count = value; }
}
private DisplayTabItem _TabItem;
public DisplayTabItem TabItem
{
get { return _TabItem; }
set { _TabItem = value; }
}
public DSOTabPanel(DocumentInfo documentInfo, DisplayTabControl myTabControl)
{
_MyTabControl = myTabControl;
InitializeComponent();
SetupDSOTabPanel();
_MyDocument = documentInfo;
SetupDSO();
}
private void SetupDSOTabPanel()
{
Dock = System.Windows.Forms.DockStyle.Fill;
}
public DocumentInfo DocumentInfo
{
get { return _MyDocument; }
}
private DSOFile _DSOFile;
internal DSOFile DSOFile
{
get
{
if (_DSOFile == null)
_DSOFile = new DSOFile(_MyDocument);
return _DSOFile;
}
}
public bool IsDirty
{
get { return _MyDSOFramer.IsDirty; }
}
private void SetupDSO()
{
_Count++;
_MyCount = _Count;
this._MyDSOFramer = new AxDSOFramer.AxFramerControl();
((System.ComponentModel.ISupportInitialize)(this._MyDSOFramer)).BeginInit();
this.Controls.Add(this._MyDSOFramer);
this.components.Add(this._MyDSOFramer);
this._MyDSOFramer.Dock = System.Windows.Forms.DockStyle.Fill;
//System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WordDSOTab));
//this._DSOFramer.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("_FC.OcxState")));
((System.ComponentModel.ISupportInitialize)(this._MyDSOFramer)).EndInit();
this._MyDSOFramer.Open(DSOFile.MyFile.FullName);
this._MyDSOFramer.Menubar = false;
this._MyDSOFramer.Titlebar = false;
//if (_MyCount < 20)
// this._MyDSOFramer.FrameHookPolicy = DSOFramer.dsoFrameHookPolicy.dsoResetNow;
this._MyDSOFramer.BeforeDocumentClosed += new AxDSOFramer._DFramerCtlEvents_BeforeDocumentClosedEventHandler(_MyDSOFramer_BeforeDocumentClosed);
this._MyDSOFramer.OnSaveCompleted += new AxDSOFramer._DFramerCtlEvents_OnSaveCompletedEventHandler(_MyDSOFramer_OnSaveCompleted);
this.Enter += new EventHandler(DSOTabPanel_Enter);
}
void _MyDSOFramer_OnSaveCompleted(object sender, AxDSOFramer._DFramerCtlEvents_OnSaveCompletedEvent e)
{
DSOFile.SaveFile();
}
void _MyDSOFramer_BeforeDocumentClosed(object sender, AxDSOFramer._DFramerCtlEvents_BeforeDocumentClosedEvent e)
{
try
{
SaveDirty();
}
catch (Exception ex)
{
_MyLog.Warn("Before Closing Document ", ex);
}
}
void DSOTabPanel_Enter(object sender, EventArgs e)
{
try
{
_MyDSOFramer.EventsEnabled = true;
_MyDSOFramer.FrameHookPolicy = DSOFramer.dsoFrameHookPolicy.dsoResetNow;
_MyTabControl.OnItemSelectedChanged(this, null);
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.ErrorFormat("DSOTabPage_Enter", ex);
}
}
public bool SaveDSO()
{
bool result = true;
try
{
_MyDSOFramer.Save();
DSOFile.SaveFile();
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("SaveDSO", ex);
result = false;
}
return result;
}
public bool SaveDirty()
{
if (_MyDSOFramer.IsDirty)
{
// TODO: Should be based upon Item rather than Document.
if (MessageBox.Show("Save changes to " + _TabItem.MyItem.TabTitle + "\r\n" + _TabItem.MyItem.TabToolTip, "Document has Changed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
return SaveDSO();
return false;
}
return true;
}
public bool CloseDSO()
{
return CloseDSO(false);
}
public bool CloseDSO(bool force)
{
_MyLog.Debug("CloseDSO");
bool result = true;
try
{
_MyDSOFramer.Close();
Controls.Remove(_MyDSOFramer);
components.Remove(_MyDSOFramer);
_MyDSOFramer.Dispose();
_MyDSOFramer = null;
_Count--;
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("SaveDSO - " + this.Name, ex);
result = false;
}
return result;
}
public void Activate()
{
try
{
this._MyDSOFramer.Activate();
if (_MyCount < 20)
this._MyDSOFramer.FrameHookPolicy = DSOFramer.dsoFrameHookPolicy.dsoResetNow;
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Activate", ex);
}
}
}
}