OSDN Git Service

操作メニューの「タブ振り分けルール作成」から新規タブを作成するとエラーが発生する不具合を修正
[opentween/open-tween.git] / OpenTween / OTSplitContainer.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2014 spx (@5px)
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
10 // any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
21
22 #nullable enable
23
24 using System;
25 using System.Windows.Forms;
26 using System.Collections.Generic;
27 using System.Linq;
28 using System.ComponentModel;
29
30 namespace OpenTween
31 {
32     public class OTSplitContainer : SplitContainer
33     {
34         /// <summary>
35         /// Panel1 と Panel2 の中身が入れ替わった状態かどうかを取得または設定する。
36         /// true が設定された場合、Panel に関連するプロパティの処理内容も入れ替わるので注意。
37         /// </summary>
38         [Browsable(false)]
39         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
40         public bool IsPanelInverted
41         {
42             get => this._isPanelInverted;
43             set
44             {
45                 if (_isPanelInverted == value)
46                     return;
47                 _isPanelInverted = value;
48
49                 // Panel1 と Panel2 の中身を入れ替え
50                 using (ControlTransaction.Layout(this, false))
51                 using (ControlTransaction.Layout(base.Panel1, false))
52                 using (ControlTransaction.Layout(base.Panel2, false))
53                 {
54                     var cont1 = new List<Control>(base.Panel1.Controls.Cast<Control>());
55                     var cont2 = new List<Control>(base.Panel2.Controls.Cast<Control>());
56                     base.Panel1.Controls.Clear();
57                     base.Panel2.Controls.Clear();
58
59                     // 関連するプロパティを反転させる
60                     if (base.FixedPanel != FixedPanel.None)
61                         base.FixedPanel = (base.FixedPanel == FixedPanel.Panel1) ? FixedPanel.Panel2 : FixedPanel.Panel1;
62
63                     base.SplitterDistance = SplitterTotalWidth - (base.SplitterDistance + SplitterWidth);
64
65                     var tmpMinSize = base.Panel1MinSize;
66                     base.Panel1MinSize = base.Panel2MinSize;
67                     base.Panel2MinSize = tmpMinSize;
68
69                     var tmpCollapsed = base.Panel1Collapsed;
70                     base.Panel1Collapsed = base.Panel2Collapsed;
71                     base.Panel2Collapsed = tmpCollapsed;
72
73                     base.Panel1.Controls.AddRange(cont2.ToArray());
74                     base.Panel2.Controls.AddRange(cont1.ToArray());
75                 }
76             }
77         }
78         private bool _isPanelInverted = false;
79
80         /// <summary>
81         /// SplitContainer.Orientation プロパティの設定に応じて、スプリッタが移動する方向の幅を返す。
82         /// </summary>
83         private int SplitterTotalWidth
84             => (base.Orientation == Orientation.Horizontal) ? base.Height : base.Width;
85
86         /// <summary>
87         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1 または SplitContainer.Panel2 を返す。
88         /// </summary>
89         public new SplitterPanel Panel1
90             => IsPanelInverted ? base.Panel2 : base.Panel1;
91
92         /// <summary>
93         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1 または SplitContainer.Panel2 を返す。
94         /// </summary>
95         public new SplitterPanel Panel2
96             => IsPanelInverted ? base.Panel1 : base.Panel2;
97
98         /// <summary>
99         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.FixedPanel を返す。
100         /// </summary>
101         public new FixedPanel FixedPanel
102         {
103             get
104             {
105                 if (base.FixedPanel != FixedPanel.None && IsPanelInverted)
106                     return (base.FixedPanel == FixedPanel.Panel1) ? FixedPanel.Panel2 : FixedPanel.Panel1;
107                 else
108                     return base.FixedPanel;
109             }
110             set
111             {
112                 if (value != FixedPanel.None && IsPanelInverted)
113                     base.FixedPanel = (value == FixedPanel.Panel1) ? FixedPanel.Panel2 : FixedPanel.Panel1;
114                 else
115                     base.FixedPanel = value;
116             }
117         }
118
119         /// <summary>
120         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.SplitterDistance を返す。
121         /// </summary>
122         public new int SplitterDistance
123         {
124             get
125             {
126                 if (IsPanelInverted)
127                     return SplitterTotalWidth - (base.SplitterDistance + SplitterWidth);
128                 else
129                     return base.SplitterDistance;
130             }
131             set
132             {
133                 if (IsPanelInverted)
134                     base.SplitterDistance = SplitterTotalWidth - (value + SplitterWidth);
135                 else
136                     base.SplitterDistance = value;
137             }
138         }
139
140         /// <summary>
141         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1MinSize または SplitContainer.Panel2MinSize を返す。
142         /// </summary>
143         public new int Panel1MinSize
144         {
145             get => IsPanelInverted ? base.Panel2MinSize : base.Panel1MinSize;
146             set
147             {
148                 if (IsPanelInverted)
149                     base.Panel2MinSize = value;
150                 else
151                     base.Panel1MinSize = value;
152             }
153         }
154
155         /// <summary>
156         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1MinSize または SplitContainer.Panel2MinSize を返す。
157         /// </summary>
158         public new int Panel2MinSize
159         {
160             get => IsPanelInverted ? base.Panel1MinSize : base.Panel2MinSize;
161             set
162             {
163                 if (IsPanelInverted)
164                     base.Panel1MinSize = value;
165                 else
166                     base.Panel2MinSize = value;
167             }
168         }
169
170         /// <summary>
171         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1Collapsed または SplitContainer.Panel2Collapsed を返す。
172         /// </summary>
173         public new bool Panel1Collapsed
174         {
175             get => IsPanelInverted ? base.Panel2Collapsed : base.Panel1Collapsed;
176             set
177             {
178                 if (IsPanelInverted)
179                     base.Panel2Collapsed = value;
180                 else
181                     base.Panel1Collapsed = value;
182             }
183         }
184
185         /// <summary>
186         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1Collapsed または SplitContainer.Panel2Collapsed を返す。
187         /// </summary>
188         public new bool Panel2Collapsed
189         {
190             get => IsPanelInverted ? base.Panel1Collapsed : base.Panel2Collapsed;
191             set
192             {
193                 if (IsPanelInverted)
194                     base.Panel1Collapsed = value;
195                 else
196                     base.Panel2Collapsed = value;
197             }
198         }
199     }
200 }