1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 // (c) 2008-2011 Moz (@syo68k)
4 // (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 // (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 // (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 // (c) 2011 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
10 // This file is part of OpenTween.
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General public License
22 // You should have received a copy of the GNU General public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
28 using System.Collections.Generic;
29 using System.ComponentModel;
34 using System.Windows.Forms;
35 using System.Threading;
43 ///重要:BackGroundWorkerコンポーネントが実際のタスクサービスを行うため、DoWorkでコントロールを触ることはできない。
44 ///また、Twitterへの通信を必要とする場合は引数にTwitterInstanceを含めそれを使用すること。
45 /// 1.class生成 2.コンストラクタの引数としてサービス登録(Dowork RunWorkerCompletedも同様 使用しない場合null)
46 /// 3.Instance.Argumentへ,あるいはコンストラクタ引数へ引数セット
47 /// 4.Instance.InfoMessage、またはコンストラクタ引数へ表示メッセージ設定 5.Instance.ShowDialog()により表示
48 /// 6. 必要な場合はInstance.Result(=Servicerのe.Result)を参照し戻り値を得る
49 /// 7.Dispose タスクサービスが正常終了した場合は自分自身をCloseするので最後にDisposeすること。
51 public partial class FormInfo : OTBaseForm
53 private class BackgroundWorkerServicer : BackgroundWorker
55 public object Result = null;
57 protected override void OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
59 this.Result = e.Result;
60 base.OnRunWorkerCompleted(e);
65 private object _arg = null;
67 private BackgroundWorkerServicer Servicer = new BackgroundWorkerServicer();
69 public FormInfo(Form owner,
71 DoWorkEventHandler DoWork)
73 doInitialize(owner, Message, DoWork, null, null);
76 public FormInfo(Form owner,
78 DoWorkEventHandler DoWork,
79 RunWorkerCompletedEventHandler RunWorkerCompleted)
81 doInitialize(owner, Message, DoWork, RunWorkerCompleted, null);
84 public FormInfo(Form owner,
86 DoWorkEventHandler DoWork,
87 RunWorkerCompletedEventHandler RunWorkerCompleted,
90 doInitialize(owner, Message, DoWork, RunWorkerCompleted, Argument);
93 private void doInitialize(Form owner,
95 DoWorkEventHandler DoWork,
96 RunWorkerCompletedEventHandler RunWorkerCompleted,
100 InitializeComponent();
102 // InitializeComponent() 呼び出しの後で初期化を追加します。
105 this.InfoMessage = Message;
106 this.Servicer.DoWork += DoWork;
108 if (RunWorkerCompleted != null)
110 this.Servicer.RunWorkerCompleted += RunWorkerCompleted;
113 this.Argument = Argument;
116 private void LabelInformation_TextChanged(object sender, EventArgs e)
118 LabelInformation.Refresh();
122 /// ダイアログに表示されるユーザー向けメッセージを設定あるいは取得する
124 /// <returns>現在設定されているメッセージ</returns>
125 public string InfoMessage
131 LabelInformation.Text = _msg;
138 /// <returns>現在設定されているServicerへ渡すパラメータ</returns>
139 public object Argument
142 set { _arg = value; }
148 ///<returns>Servicerのe.Result</returns>
151 get { return Servicer.Result; }
154 private void FormInfo_Shown(object sender, EventArgs e)
156 Servicer.RunWorkerAsync(_arg);
157 while (Servicer.IsBusy)
160 Application.DoEvents();
162 this.TopMost = false; // MessageBoxが裏に隠れる問題に対応
166 // フォームを閉じたあとに親フォームが最前面にならない問題に対応
168 private void FormInfo_FormClosed(object sender, FormClosedEventArgs e)
170 if (Owner != null && Owner.Created)
172 Owner.TopMost = !Owner.TopMost;
173 Owner.TopMost = !Owner.TopMost;