Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/06/21 13:13:32 (4 years ago)
Author:
dpiringe
Message:

#3026

  • merged trunk into branch
Location:
branches/3026_IntegrationIntoSymSpace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace

  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs

    r17180 r17928  
    2525namespace HeuristicLab.MainForm.WindowsForms {
    2626  internal sealed partial class ProgressView : UserControl {
    27     private readonly Control control;
    28     public Control Control {
    29       get { return control; }
    30     }
    31 
    32     private readonly IProgress content;
    33     public IProgress Content {
    34       get { return content; }
    35     }
    36 
    37     public ProgressView(Control control, IProgress content)
     27    public Control TargetControl { get; }
     28    public IProgress Content { get; }
     29
     30    public ProgressView(Control targetControl, IProgress content)
    3831      : base() {
    39       if (control == null) throw new ArgumentNullException("control");
    40       if (control.Parent == null) throw new InvalidOperationException("A Progress can only be shown on controls that have a Parent-control. Therefore, Dialogs and Forms cannot have an associated ProgressView.");
    41       if (content == null) throw new ArgumentNullException("content");
     32      if (targetControl == null) throw new ArgumentNullException(nameof(targetControl));
     33      if (targetControl.Parent == null) throw new InvalidOperationException("A Progress can only be shown on controls that have a Parent-control. Therefore, Dialogs and Forms cannot have an associated ProgressView.");
     34      if (content == null) throw new ArgumentNullException(nameof(content));
    4235      InitializeComponent();
    4336
    44       this.control = control;
    45       this.content = content;
     37      this.TargetControl = targetControl;
     38      this.Content = content;
    4639
    4740      if (content.ProgressState != ProgressState.Finished)
     
    5245    protected override void Dispose(bool disposing) {
    5346      DeregisterContentEvents();
    54       HideProgress();
    55 
    56       if (disposing && (components != null)) {
     47
     48      if (!TargetControl.IsDisposed)
     49        HideProgress();
     50
     51      if (disposing && components != null) {
    5752        components.Dispose();
    5853      }
     
    10196
    10297    private void ShowProgress() {
    103       if (Control.InvokeRequired) {
    104         Control.Invoke((Action)ShowProgress);
     98      if (TargetControl.InvokeRequired) {
     99        TargetControl.Invoke((Action)ShowProgress);
    105100        return;
    106101      }
    107102      if (Parent != null) return;
    108103
    109       Left = (Control.ClientRectangle.Width / 2) - (Width / 2);
    110       Top = (Control.ClientRectangle.Height / 2) - (Height / 2);
     104      Left = (TargetControl.ClientRectangle.Width / 2) - (Width / 2);
     105      Top = (TargetControl.ClientRectangle.Height / 2) - (Height / 2);
    111106      Anchor = AnchorStyles.None;
    112107
     
    115110      UpdateButtonsState();
    116111
    117       Control.SuspendRepaint();
    118       Control.Enabled = false;
    119       Parent = Control.Parent;
     112      TargetControl.SuspendRepaint();
     113      TargetControl.Enabled = false;
     114      RegisterTargetControlEvents();
     115      Parent = TargetControl.Parent;
    120116      BringToFront();
    121       Control.ResumeRepaint(true);
     117      TargetControl.ResumeRepaint(true);
    122118      Visible = true;
    123119    }
    124120
    125121    private void HideProgress() {
    126       if (Control.InvokeRequired) {
    127         Control.Invoke((Action)HideProgress);
     122      if (TargetControl.InvokeRequired) {
     123        TargetControl.Invoke((Action)HideProgress);
    128124        return;
    129125      }
     
    131127
    132128      Visible = false;
    133       Control.SuspendRepaint();
    134       Control.Enabled = true;
    135       Control.ResumeRepaint(true);
     129      TargetControl.SuspendRepaint();
     130      TargetControl.Enabled = true;
     131      DeregisterTargetControlEvents();
    136132      Parent = null;
     133      TargetControl.ResumeRepaint(TargetControl.Visible);
     134    }
     135
     136
     137    private void RegisterTargetControlEvents() {
     138      TargetControl.Disposed += TargetControl_Disposed;
     139      TargetControl.VisibleChanged += TargetControl_VisibleChanged;
     140      TargetControl.ParentChanged += TargetControl_ParentChanged;
     141    }
     142
     143    private void DeregisterTargetControlEvents() {
     144      TargetControl.Disposed -= TargetControl_Disposed;
     145      TargetControl.VisibleChanged -= TargetControl_VisibleChanged;
     146      TargetControl.ParentChanged -= TargetControl_ParentChanged;
     147    }
     148
     149    private void TargetControl_Disposed(object sender, EventArgs e) {
     150      Dispose();
     151    }
     152    private void TargetControl_VisibleChanged(object sender, EventArgs e) {
     153      Visible = TargetControl.Visible;
     154    }
     155    private void TargetControl_ParentChanged(object sender, EventArgs e) {
     156      Parent = TargetControl.Parent;
    137157    }
    138158
    139159    private void UpdateProgressState() {
    140       if (Control.InvokeRequired) {
    141         Control.Invoke((Action)UpdateProgressState);
     160      if (TargetControl.InvokeRequired) {
     161        TargetControl.Invoke((Action)UpdateProgressState);
    142162        return;
    143163      }
     
    150170
    151171    private void UpdateProgressMessage() {
    152       if (Control.InvokeRequired) {
    153         Control.Invoke((Action)UpdateProgressMessage);
    154         return;
    155       }
    156 
    157       messageLabel.Text = content.Message;
     172      if (TargetControl.InvokeRequired) {
     173        TargetControl.Invoke((Action)UpdateProgressMessage);
     174        return;
     175      }
     176
     177      messageLabel.Text = Content.Message;
    158178    }
    159179
    160180    private void UpdateProgressValue() {
     181      if (Disposing || IsDisposed) return;
    161182      if (InvokeRequired) {
    162183        Invoke((Action)UpdateProgressValue);
     
    167188        case ProgressMode.Determinate:
    168189          progressBar.Style = ProgressBarStyle.Continuous;
    169           progressBar.Value = (int)Math.Round(progressBar.Minimum + content.ProgressValue * (progressBar.Maximum - progressBar.Minimum));
     190          progressBar.Value = (int)Math.Round(progressBar.Minimum + Content.ProgressValue * (progressBar.Maximum - progressBar.Minimum));
    170191          break;
    171192        case ProgressMode.Indeterminate:
     
    174195          break;
    175196        default:
    176           throw new NotImplementedException($"Invalid Progress Mode: {content.ProgressMode}");
     197          throw new NotImplementedException($"Invalid Progress Mode: {Content.ProgressMode}");
    177198      }
    178199    }
    179200
    180201    private void UpdateButtonsState() {
    181       if (Control.InvokeRequired) {
    182         Control.Invoke((Action)UpdateButtonsState);
     202      if (TargetControl.InvokeRequired) {
     203        TargetControl.Invoke((Action)UpdateButtonsState);
    183204        return;
    184205      }
    185206
    186207      stopButton.Visible = Content.CanBeStopped;
    187       stopButton.Enabled = Content.CanBeStopped && content.ProgressState == ProgressState.Started;
     208      stopButton.Enabled = Content.CanBeStopped && Content.ProgressState == ProgressState.Started;
    188209
    189210      cancelButton.Visible = Content.CanBeCanceled;
    190       cancelButton.Enabled = Content.CanBeCanceled && content.ProgressState == ProgressState.Started;
     211      cancelButton.Enabled = Content.CanBeCanceled && Content.ProgressState == ProgressState.Started;
    191212    }
    192213
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewHost.cs

    r17180 r17928  
    170170    }
    171171
     172
    172173    private void OnViewTypeChanged() {
    173       if (viewType != null) {
    174         if (!ViewCanShowContent(viewType, Content))
    175           throw new InvalidOperationException(string.Format("View \"{0}\" cannot display content \"{1}\".",
    176                                                             viewType, Content.GetType()));
    177         IContentView view = MainFormManager.CreateView(viewType);
    178         view.Locked = Locked;
    179         view.ReadOnly = ReadOnly;
    180         ActiveView = view; //necessary to allow the views to change the status of the viewhost
    181         view.Content = Content;
    182 
    183         UpdateActiveMenuItem();
    184       }
     174      if (viewType == null) return;
     175      if (!ViewCanShowContent(viewType, Content))
     176        throw new InvalidOperationException(string.Format("View \"{0}\" cannot display content \"{1}\".", viewType, Content.GetType()));
     177
     178      IContentView view = MainFormManager.CreateView(viewType);
     179      view.Locked = Locked;
     180      view.ReadOnly = ReadOnly;
     181      ActiveView = view; //necessary to allow the views to change the status of the viewhost
     182      view.Content = Content;
     183
     184      UpdateActiveMenuItem();
     185
    185186    }
    186187
     
    188189      activeView.CaptionChanged += new EventHandler(activeView_CaptionChanged);
    189190      activeView.LockedChanged += new EventHandler(activeView_LockedChanged);
     191      activeView.ReadOnlyChanged += new EventHandler(activeView_ReadOnlyChanged);
    190192      activeView.Changed += new EventHandler(activeView_Changed);
    191193    }
     
    193195      activeView.CaptionChanged -= new EventHandler(activeView_CaptionChanged);
    194196      activeView.LockedChanged -= new EventHandler(activeView_LockedChanged);
     197      activeView.ReadOnlyChanged -= new EventHandler(activeView_ReadOnlyChanged);
    195198      activeView.Changed -= new EventHandler(activeView_Changed);
    196199    }
     
    202205      configurationLabel.Enabled = !activeView.Locked;
    203206    }
     207    private void activeView_ReadOnlyChanged(object sender, EventArgs e) {
     208      ReadOnly = activeView.ReadOnly;
     209    }
     210
    204211    private void activeView_Changed(object sender, EventArgs e) {
    205212      OnChanged();
     
    228235
    229236    #region forwarding of view events
    230     internal protected override void OnShown(ViewShownEventArgs e) {
     237    protected internal override void OnShown(ViewShownEventArgs e) {
    231238      base.OnShown(e);
    232239      View view = ActiveView as View;
     
    234241        view.OnShown(e);
    235242    }
    236     internal protected override void OnHidden(EventArgs e) {
     243    protected internal override void OnHidden(EventArgs e) {
    237244      base.OnHidden(e);
    238245      View view = ActiveView as View;
     
    240247        view.OnHidden(e);
    241248    }
    242     internal protected override void OnClosing(FormClosingEventArgs e) {
     249    protected internal override void OnClosing(FormClosingEventArgs e) {
    243250      base.OnClosing(e);
    244251      View view = ActiveView as View;
     
    246253        view.OnClosing(e);
    247254    }
    248     internal protected override void OnClosed(FormClosedEventArgs e) {
     255    protected internal override void OnClosed(FormClosedEventArgs e) {
    249256      base.OnClosed(e);
    250257      View view = ActiveView as View;
Note: See TracChangeset for help on using the changeset viewer.