OSDN Git Service

FavoriteTweet/UnfavoriteTweetを使用したFav追加・削除に対応
[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.Collections.Generic;
26 using System.ComponentModel;
27 using System.Linq;
28 using System.Windows.Forms;
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 (this.isPanelInverted == value)
46                     return;
47                 this.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 = this.SplitterTotalWidth - (base.SplitterDistance + this.SplitterWidth);
64
65                     (base.Panel2MinSize, base.Panel1MinSize) = (base.Panel1MinSize, base.Panel2MinSize);
66                     (base.Panel2Collapsed, base.Panel1Collapsed) = (base.Panel1Collapsed, base.Panel2Collapsed);
67
68                     base.Panel1.Controls.AddRange(cont2.ToArray());
69                     base.Panel2.Controls.AddRange(cont1.ToArray());
70                 }
71             }
72         }
73
74         private bool isPanelInverted = false;
75
76         /// <summary>
77         /// SplitContainer.Orientation プロパティの設定に応じて、スプリッタが移動する方向の幅を返す。
78         /// </summary>
79         private int SplitterTotalWidth
80             => (base.Orientation == Orientation.Horizontal) ? base.Height : base.Width;
81
82         /// <summary>
83         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1 または SplitContainer.Panel2 を返す。
84         /// </summary>
85         public new SplitterPanel Panel1
86             => this.IsPanelInverted ? base.Panel2 : base.Panel1;
87
88         /// <summary>
89         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.Panel1 または SplitContainer.Panel2 を返す。
90         /// </summary>
91         public new SplitterPanel Panel2
92             => this.IsPanelInverted ? base.Panel1 : base.Panel2;
93
94         /// <summary>
95         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.FixedPanel を返す。
96         /// </summary>
97         public new FixedPanel FixedPanel
98         {
99             get
100             {
101                 if (base.FixedPanel != FixedPanel.None && this.IsPanelInverted)
102                     return (base.FixedPanel == FixedPanel.Panel1) ? FixedPanel.Panel2 : FixedPanel.Panel1;
103                 else
104                     return base.FixedPanel;
105             }
106
107             set
108             {
109                 if (value != FixedPanel.None && this.IsPanelInverted)
110                     base.FixedPanel = (value == FixedPanel.Panel1) ? FixedPanel.Panel2 : FixedPanel.Panel1;
111                 else
112                     base.FixedPanel = value;
113             }
114         }
115
116         /// <summary>
117         /// IsPanelInverted プロパティの設定に応じて、SplitContainer.SplitterDistance を返す。
118         /// </summary>
119         public new int SplitterDistance
120         {
121             get
122             {
123                 if (this.IsPanelInverted)
124                     return this.SplitterTotalWidth - (base.SplitterDistance + this.SplitterWidth);
125                 else
126                     return base.SplitterDistance;
127             }
128
129             set
130             {
131                 if (this.IsPanelInverted)
132                     base.SplitterDistance = this.SplitterTotalWidth - (value + this.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 => this.IsPanelInverted ? base.Panel2MinSize : base.Panel1MinSize;
144             set
145             {
146                 if (this.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 => this.IsPanelInverted ? base.Panel1MinSize : base.Panel2MinSize;
159             set
160             {
161                 if (this.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 => this.IsPanelInverted ? base.Panel2Collapsed : base.Panel1Collapsed;
174             set
175             {
176                 if (this.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 => this.IsPanelInverted ? base.Panel1Collapsed : base.Panel2Collapsed;
189             set
190             {
191                 if (this.IsPanelInverted)
192                     base.Panel1Collapsed = value;
193                 else
194                     base.Panel2Collapsed = value;
195             }
196         }
197     }
198 }