OSDN Git Service

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