Index: src/Common/DelftTools.Controls.Swf/WizardDialog.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/DelftTools.Controls.Swf/WizardDialog.cs (.../WizardDialog.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/DelftTools.Controls.Swf/WizardDialog.cs (.../WizardDialog.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -12,7 +12,6 @@ public partial class WizardDialog : Form, IWizardDialog, IView { private readonly IDictionary wizardPages = new Dictionary(); - public IList Pages { get; private set; } public WizardDialog() { @@ -24,266 +23,183 @@ wizardControl1.CancelClick += WizardControl1CancelClick; wizardControl1.NextClick += WizardControl1NextClick; wizardControl1.PrevClick += WizardControl1PrevClick; - + KeyPreview = true; //catch key events in pages KeyUp += OnPageModified; updateButtonsTimer.Interval = 300; updateButtonsTimer.Tick += UpdateNavigationButtonsTimerTick; } - #region Auto Updates + public virtual object Data { get; set; } - void OnPageModified(object sender, object e) + public Image Image { get; set; } + public ViewInfo ViewInfo { get; set; } + public IList Pages { get; private set; } + + public IList PageTitles { - updateButtonsTimer.Start(); //delayed refresh + get + { + return Enumerable.OfType(wizardControl1.Pages).Select(p => p.Text).ToList(); + } } - protected override void WndProc(ref Message m) + public IList PageDescriptions { - const int WM_PARENTNOTIFY = 0x0210; - const int WM_SETFOCUS = 0x0007; - const int WM_LBUTTONDOWN = 0x0201; - - if (m.Msg == WM_SETFOCUS) //called after child (file) dialog is closed + get { - OnPageModified(null,null); + return Enumerable.OfType(wizardControl1.Pages).Select(p => p.DescriptionText).ToList(); } - else if (m.Msg == WM_PARENTNOTIFY) + } + + public IComponent CurrentPage + { + get { - var subEvent = m.WParam.ToInt32() & 0xFFFF; //LOWORD - if (subEvent == WM_LBUTTONDOWN) //called after mouse down anywhere in dialog + if ((wizardControl1.SelectedPageIndex == 0) || + (wizardControl1.SelectedPageIndex == wizardControl1.Pages.Count - 1)) { - OnPageModified(null,null); + return wizardControl1.Pages[wizardControl1.SelectedPageIndex]; } + return Pages[wizardControl1.SelectedPageIndex - 1]; } - base.WndProc(ref m); + set + { + wizardControl1.SelectedPageIndex = Pages.IndexOf(value) + 1; + } } - void UpdateNavigationButtonsTimerTick(object sender, EventArgs e) + public string WelcomeMessage { - UpdateNavigationButtons(); //refresh - updateButtonsTimer.Stop(); - } - - #endregion - - void WizardControl1SelectedPageChanged(object sender, WizardPageChangedEventArgs e) - { - UpdateNavigationButtons(); - } - - public virtual void UpdateNavigationButtons() - { - if (!(CurrentPage is IWizardPage) || wizardPages == null || !wizardPages.ContainsKey(CurrentPage)) + get { - return; + return welcomeWizardPage1.IntroductionText; } - - var wizardPage = CurrentPage as IWizardPage; - var containerPage = wizardPages[CurrentPage]; - - if (containerPage != null) + set { - containerPage.AllowBack = wizardPage.CanDoPrevious(); - containerPage.AllowNext = wizardPage.CanDoNext(); + welcomeWizardPage1.IntroductionText = value; + richTextBoxWelcome.Text = value; } } - void WizardControl1PrevClick(object sender, DevExpress.XtraWizard.WizardCommandButtonClickEventArgs e) + public string FinishedPageMessage { - if (CurrentPage is IWizardPage) + get { - IWizardPage wizardPage = (IWizardPage)CurrentPage; - if (!wizardPage.CanDoPrevious()) - { - // setting handled to true will prevent default handling - e.Handled = true; - } - else - { - try - { - OnPageReverted(wizardPage); - } - catch (Exception ee) - { - MessageBox.Show("An error occurred, please verify your input. \n\nError: \n" + ee.Message, "Error occurred", MessageBoxButtons.OK, MessageBoxIcon.Warning); - e.Handled = true; - } - } + return completionWizardPage1.FinishText; } + set + { + completionWizardPage1.FinishText = value; + richTextBoxFinished.Text = value; + } } - void WizardControl1NextClick(object sender, DevExpress.XtraWizard.WizardCommandButtonClickEventArgs e) + public string Title { - if (CurrentPage is IWizardPage) + get { - var wizardPage = (IWizardPage) CurrentPage; - if (!wizardPage.CanDoNext()) - { - // setting handled to true will prevent default handling - e.Handled = true; - } - else - { - try - { - OnPageCompleted(wizardPage); - } - catch (Exception ee) - { - MessageBox.Show("An error occurred, please verify your input. \n\nError: \n" + ee.Message, "Error occurred",MessageBoxButtons.OK, MessageBoxIcon.Warning); - e.Handled = true; - } - } + return wizardControl1.Text; } + set + { + wizardControl1.Text = value; + } } - protected virtual void OnPageReverted(IWizardPage page) - { + public void EnsureVisible(object item) {} - } - - protected virtual void OnPageCompleted(IWizardPage page) + public virtual void UpdateNavigationButtons() { - - } + if (!(CurrentPage is IWizardPage) || wizardPages == null || !wizardPages.ContainsKey(CurrentPage)) + { + return; + } - void WizardControl1CancelClick(object sender, CancelEventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } + var wizardPage = CurrentPage as IWizardPage; + var containerPage = wizardPages[CurrentPage]; - void WizardControl1FinishClick(object sender, CancelEventArgs e) - { - if (CurrentPage is IWizardPage) + if (containerPage != null) { - IWizardPage wizardPage = (IWizardPage)CurrentPage; - if (!wizardPage.CanFinish()) - { - return; - } + containerPage.AllowBack = wizardPage.CanDoPrevious(); + containerPage.AllowNext = wizardPage.CanDoNext(); } - - OnDialogFinished(); - DialogResult = DialogResult.OK; - Close(); } - protected virtual void OnDialogFinished() - { - - } - public void AddPage(IComponent page, string title, string description) { var pageControl = (Control) page; pageControl.Dock = DockStyle.Fill; - var wizardPage = new WizardPage {Text = title, DescriptionText = description, Dock = DockStyle.Fill}; + var wizardPage = new WizardPage + { + Text = title, DescriptionText = description, Dock = DockStyle.Fill + }; wizardPage.Controls.Add(pageControl); wizardControl1.Controls.Add(wizardPage); wizardControl1.Pages.Insert(wizardControl1.Pages.Count - 1, wizardPage); - + wizardPages[page] = wizardPage; Pages.Add(page); } public void RemovePage(IComponent page) { var wizardPage = wizardControl1.Controls.OfType().FirstOrDefault(p => p.Controls.Contains((Control) page)); - if (wizardPage == null) return; + if (wizardPage == null) + { + return; + } wizardControl1.Controls.Remove(wizardPage); wizardControl1.Pages.Remove(wizardPage); wizardPages.Remove(page); Pages.Remove(page); } - - public IList PageTitles - { - get { return Enumerable.OfType(wizardControl1.Pages).Select(p => p.Text).ToList(); } - } - public IList PageDescriptions + public DelftDialogResult ShowModal() { - get { return Enumerable.OfType(wizardControl1.Pages).Select(p => p.DescriptionText).ToList(); } + if (ShowDialog() == DialogResult.OK) + { + return DelftDialogResult.OK; + } + return DelftDialogResult.Cancel; } - public IComponent CurrentPage + public DelftDialogResult ShowModal(object owner) { - get + if (ShowDialog((IWin32Window) owner) == DialogResult.OK) { - if ((wizardControl1.SelectedPageIndex == 0) || - (wizardControl1.SelectedPageIndex == wizardControl1.Pages.Count - 1)) - { - return wizardControl1.Pages[wizardControl1.SelectedPageIndex]; - } - return Pages[wizardControl1.SelectedPageIndex - 1]; + return DelftDialogResult.OK; } - set { wizardControl1.SelectedPageIndex = Pages.IndexOf(value) + 1; } + return DelftDialogResult.Cancel; } protected bool WelcomePageVisible { - set { welcomeWizardPage1.Visible = value; } - } - - protected bool CompletionPageVisible - { - set { completionWizardPage1.Visible = value; } - } - - public string WelcomeMessage - { - get { return welcomeWizardPage1.IntroductionText; } set { - welcomeWizardPage1.IntroductionText = value; - richTextBoxWelcome.Text = value; + welcomeWizardPage1.Visible = value; } } - public string FinishedPageMessage + protected bool CompletionPageVisible { - get { return completionWizardPage1.FinishText; } set { - completionWizardPage1.FinishText = value; - richTextBoxFinished.Text = value; + completionWizardPage1.Visible = value; } } - public string Title - { - get { return wizardControl1.Text; } - set { wizardControl1.Text = value; } - } + protected virtual void OnPageReverted(IWizardPage page) {} - public DelftDialogResult ShowModal() - { - if (ShowDialog() == DialogResult.OK) - return DelftDialogResult.OK; - return DelftDialogResult.Cancel; - } + protected virtual void OnPageCompleted(IWizardPage page) {} - public DelftDialogResult ShowModal(object owner) - { - if (ShowDialog((IWin32Window)owner) == DialogResult.OK) - return DelftDialogResult.OK; - return DelftDialogResult.Cancel; - } + protected virtual void OnDialogFinished() {} - public virtual object Data { get; set; } - - public Image Image { get; set; } - public void EnsureVisible(object item) { } - public ViewInfo ViewInfo { get; set; } - /// /// Override this method if you want to choose the next page on basis of choices that were made in one of the pages /// The direction is forward @@ -306,6 +222,92 @@ return -1; } + protected virtual void WizardControl1SelectedPageChanging(object sender, WizardPageChangingEventArgs e) + { + var nextPageIndex = EvaluateNextPageIndex(wizardControl1.SelectedPageIndex, e.Direction); + if (nextPageIndex > 0) + { + e.Page = wizardControl1.Pages[nextPageIndex]; + } + } + + private void WizardControl1SelectedPageChanged(object sender, WizardPageChangedEventArgs e) + { + UpdateNavigationButtons(); + } + + private void WizardControl1PrevClick(object sender, WizardCommandButtonClickEventArgs e) + { + if (CurrentPage is IWizardPage) + { + IWizardPage wizardPage = (IWizardPage) CurrentPage; + if (!wizardPage.CanDoPrevious()) + { + // setting handled to true will prevent default handling + e.Handled = true; + } + else + { + try + { + OnPageReverted(wizardPage); + } + catch (Exception ee) + { + MessageBox.Show("An error occurred, please verify your input. \n\nError: \n" + ee.Message, "Error occurred", MessageBoxButtons.OK, MessageBoxIcon.Warning); + e.Handled = true; + } + } + } + } + + private void WizardControl1NextClick(object sender, WizardCommandButtonClickEventArgs e) + { + if (CurrentPage is IWizardPage) + { + var wizardPage = (IWizardPage) CurrentPage; + if (!wizardPage.CanDoNext()) + { + // setting handled to true will prevent default handling + e.Handled = true; + } + else + { + try + { + OnPageCompleted(wizardPage); + } + catch (Exception ee) + { + MessageBox.Show("An error occurred, please verify your input. \n\nError: \n" + ee.Message, "Error occurred", MessageBoxButtons.OK, MessageBoxIcon.Warning); + e.Handled = true; + } + } + } + } + + private void WizardControl1CancelClick(object sender, CancelEventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void WizardControl1FinishClick(object sender, CancelEventArgs e) + { + if (CurrentPage is IWizardPage) + { + IWizardPage wizardPage = (IWizardPage) CurrentPage; + if (!wizardPage.CanFinish()) + { + return; + } + } + + OnDialogFinished(); + DialogResult = DialogResult.OK; + Close(); + } + /// /// Sometimes you want hide a page depending on choices in other pages /// Use this method to determine the index of the page you want to go to @@ -319,13 +321,40 @@ return (direction == Direction.Forward) ? FindNextPageIndexMovingForward(previousPageIndex) : FindNextPageIndexMovingBackward(previousPageIndex); } - protected virtual void WizardControl1SelectedPageChanging(object sender, WizardPageChangingEventArgs e) + #region Auto Updates + + private void OnPageModified(object sender, object e) { - var nextPageIndex = EvaluateNextPageIndex(wizardControl1.SelectedPageIndex, e.Direction); - if (nextPageIndex > 0) + updateButtonsTimer.Start(); //delayed refresh + } + + protected override void WndProc(ref Message m) + { + const int WM_PARENTNOTIFY = 0x0210; + const int WM_SETFOCUS = 0x0007; + const int WM_LBUTTONDOWN = 0x0201; + + if (m.Msg == WM_SETFOCUS) //called after child (file) dialog is closed { - e.Page = wizardControl1.Pages[nextPageIndex]; + OnPageModified(null, null); } + else if (m.Msg == WM_PARENTNOTIFY) + { + var subEvent = m.WParam.ToInt32() & 0xFFFF; //LOWORD + if (subEvent == WM_LBUTTONDOWN) //called after mouse down anywhere in dialog + { + OnPageModified(null, null); + } + } + base.WndProc(ref m); } + + private void UpdateNavigationButtonsTimerTick(object sender, EventArgs e) + { + UpdateNavigationButtons(); //refresh + updateButtonsTimer.Stop(); + } + + #endregion } } \ No newline at end of file