OSDN Git Service

C# の言語バージョンを C# 8.0 に変更
[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 using System;
23 using System.Windows.Forms;
24 using System.Collections.Generic;
25 using System.Linq;
26 using System.ComponentModel;
27
28 namespace OpenTween
29 {
30     public class OTSplitContainer : SplitContainer
31     {
32         /// <summary>
33         /// Panel1 と Panel2 の中身が入れ替わった状態かどうかを取得または設定する。
34         /// true が設定された場合、Panel に関連するプロパティの処理内容も入れ替わるので注意。
35         /// </summary>
36         [Browsable(false)]
37         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
38         public bool IsPanelInverted
39         {
40             get => this._isPanelInverted;
41             set
42             {
43                 if (_isPanelInverted == value)
44                     return;
45                 _isPanelInverted = value;
46
47                 // Panel1 と Panel2 の中身を入れ替え
48                 using (ControlTransaction.Layout(this, false))
49                 using (ControlTransaction.Layout(base.Panel1, false))
50                 using (ControlTransaction.Layout(base.Panel2, false))
51                 {
52                     var cont1 = new List<Control>(base.Panel1.Controls.Cast<Control>());
53                     var cont2 = new List<Control>(base.Panel2.Controls.Cast<Control>());
54                     base.Panel1.Controls.Clear();
55                     base.Panel2.Controls.Clear();
56
57                     // 関連するプロパティを反転させる
58                     if (base.FixedPanel != FixedPanel.None)
59                         base.FixedPanel = (base.FixedPanel == FixedPanel.Panel1) ? FixedPanel.Panel2 : FixedPanel.Panel1;
60
61                     base.SplitterDistance = SplitterTotalWidth - (base.SplitterDistance + SplitterWidth);
62
63                     var tmpMinSize = base.Panel1MinSize;
64                     base.Panel1MinSize = base.Panel2MinSize;
65                     base.Panel2MinSize = tmpMinSize;
66
67                     var tmpCollapsed = base.Panel1Collapsed;
68                     base.Panel1Collapsed = base.Panel2Collapsed;
69                     base.Panel2Collapsed = tmpCollapsed;
70
71                     base.Panel1.Controls.AddRange(cont2.ToArray());
72                     base.Panel2.Controls.AddRange(cont1.ToArray());
73                 }
74             }
75         }
76         private bool _isPanelInverted = false;
77
78         /// <summary>
79         /// SplitContainer.Orientation プロパティの設定に応じて、スプリッタが移動する方向の幅を返す。
80         /// </summary>
81         private int SplitterTotalWidth
82             => (base.Orientation == Orientation.Horizontal) ? base.Height : base.Width;
83
84         /// <summary>
85         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1 または SplitContainer.Panel2 を返す。
86         /// </summary>
87         public new SplitterPanel Panel1
88             => IsPanelInverted ? base.Panel2 : base.Panel1;
89
90         /// <summary>
91         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1 または SplitContainer.Panel2 を返す。
92         /// </summary>
93         public new SplitterPanel Panel2
94             => IsPanelInverted ? base.Panel1 : base.Panel2;
95
96         /// <summary>
97         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.FixedPanel を返す。
98         /// </summary>
99         public new FixedPanel FixedPanel
100         {
101             get
102             {
103                 if (base.FixedPanel != FixedPanel.None && IsPanelInverted)
104                     return (base.FixedPanel == FixedPanel.Panel1) ? FixedPanel.Panel2 : FixedPanel.Panel1;
105                 else
106                     return base.FixedPanel;
107             }
108             set
109             {
110                 if (value != FixedPanel.None && IsPanelInverted)
111                     base.FixedPanel = (value == FixedPanel.Panel1) ? FixedPanel.Panel2 : FixedPanel.Panel1;
112                 else
113                     base.FixedPanel = value;
114             }
115         }
116
117         /// <summary>
118         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.SplitterDistance を返す。
119         /// </summary>
120         public new int SplitterDistance
121         {
122             get
123             {
124                 if (IsPanelInverted)
125                     return SplitterTotalWidth - (base.SplitterDistance + SplitterWidth);
126                 else
127                     return base.SplitterDistance;
128             }
129             set
130             {
131                 if (IsPanelInverted)
132                     base.SplitterDistance = SplitterTotalWidth - (value + SplitterWidth);
133                 else
134                     base.SplitterDistance = value;
135             }
136         }
137
138         /// <summary>
139         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1MinSize または SplitContainer.Panel2MinSize を返す。
140         /// </summary>
141         public new int Panel1MinSize
142         {
143             get => IsPanelInverted ? base.Panel2MinSize : base.Panel1MinSize;
144             set
145             {
146                 if (IsPanelInverted)
147                     base.Panel2MinSize = value;
148                 else
149                     base.Panel1MinSize = value;
150             }
151         }
152
153         /// <summary>
154         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1MinSize または SplitContainer.Panel2MinSize を返す。
155         /// </summary>
156         public new int Panel2MinSize
157         {
158             get => IsPanelInverted ? base.Panel1MinSize : base.Panel2MinSize;
159             set
160             {
161                 if (IsPanelInverted)
162                     base.Panel1MinSize = value;
163                 else
164                     base.Panel2MinSize = value;
165             }
166         }
167
168         /// <summary>
169         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1Collapsed または SplitContainer.Panel2Collapsed を返す。
170         /// </summary>
171         public new bool Panel1Collapsed
172         {
173             get => IsPanelInverted ? base.Panel2Collapsed : base.Panel1Collapsed;
174             set
175             {
176                 if (IsPanelInverted)
177                     base.Panel2Collapsed = value;
178                 else
179                     base.Panel1Collapsed = value;
180             }
181         }
182
183         /// <summary>
184         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1Collapsed または SplitContainer.Panel2Collapsed を返す。
185         /// </summary>
186         public new bool Panel2Collapsed
187         {
188             get => IsPanelInverted ? base.Panel1Collapsed : base.Panel2Collapsed;
189             set
190             {
191                 if (IsPanelInverted)
192                     base.Panel1Collapsed = value;
193                 else
194                     base.Panel2Collapsed = value;
195             }
196         }
197     }
198 }