svnno****@sourc*****
svnno****@sourc*****
2011年 10月 22日 (土) 09:07:43 JST
Revision: 1636 http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1636 Author: f_swallow Date: 2011-10-22 09:07:42 +0900 (Sat, 22 Oct 2011) Log Message: ----------- GrowlCallbackイベント対応パッチを取り込み thanks @blueberrystream Modified Paths: -------------- trunk/Tween/Growl.vb trunk/Tween/Tween.vb -------------- next part -------------- Modified: trunk/Tween/Growl.vb =================================================================== --- trunk/Tween/Growl.vb 2011-10-19 00:14:49 UTC (rev 1635) +++ trunk/Tween/Growl.vb 2011-10-22 00:07:42 UTC (rev 1636) @@ -20,6 +20,8 @@ Private _appName As String = "" Dim _initialized As Boolean = False + Public Event Callback(ByVal sender As Object, ByVal e As EventArgs) + Public ReadOnly Property AppName As String Get Return _appName @@ -174,6 +176,16 @@ mi.Invoke(_targetConnector, New Object() {_growlApp, arglist.ToArray(_t)}) + ' コールバックメソッドの登録 + Dim tGrowlConnector As Type = _connector.GetType("Growl.Connector.GrowlConnector") + Dim evNotificationCallback As EventInfo = tGrowlConnector.GetEvent("NotificationCallback") + Dim tDelegate As Type = evNotificationCallback.EventHandlerType + Dim miHandler As MethodInfo = GetType(GrowlHelper).GetMethod("GrowlCallbackHandler", BindingFlags.NonPublic Or BindingFlags.Instance) + Dim d As [Delegate] = [Delegate].CreateDelegate(tDelegate, Me, miHandler) + Dim miAddHandler As MethodInfo = evNotificationCallback.GetAddMethod() + Dim addHandlerArgs() As Object = {d} + miAddHandler.Invoke(_targetConnector, addHandlerArgs) + _initialized = True Catch ex As Exception @@ -209,6 +221,33 @@ id, title, text}) - _targetConnector.GetType.InvokeMember("Notify", BindingFlags.InvokeMethod, Nothing, _targetConnector, New Object() {n}) + '_targetConnector.GetType.InvokeMember("Notify", BindingFlags.InvokeMethod, Nothing, _targetConnector, New Object() {n}) + Dim cc As Object = _connector.GetType("Growl.Connector.CallbackContext").InvokeMember( + Nothing, BindingFlags.CreateInstance, Nothing, _connector, + New Object() {"some fake information", "fake data"}) + _targetConnector.GetType.InvokeMember("Notify", BindingFlags.InvokeMethod, Nothing, _targetConnector, New Object() {n, cc}) End Sub + + Private Sub GrowlCallbackHandler(ByVal response As Object, ByVal callbackData As Object, ByVal state As Object) + Try + ' 定数取得 + Dim vCLICK As Object = + _core.GetType("Growl.CoreLibrary.CallbackResult").GetField( + "CLICK", + BindingFlags.Public Or BindingFlags.Static).GetRawConstantValue() + ' 実際の値 + Dim vResult As Object = callbackData.GetType.GetProperty( + "Result", + BindingFlags.Public Or BindingFlags.Instance). + GetGetMethod. + Invoke(callbackData, Nothing) + vResult = CType(vResult, Integer) + + If vCLICK.Equals(vResult) Then + RaiseEvent Callback(Me, New EventArgs) + End If + Catch ex As Exception + Exit Sub + End Try + End Sub End Class Modified: trunk/Tween/Tween.vb =================================================================== --- trunk/Tween/Tween.vb 2011-10-19 00:14:49 UTC (rev 1635) +++ trunk/Tween/Tween.vb 2011-10-22 00:07:42 UTC (rev 1636) @@ -90,7 +90,7 @@ Private tw As New Twitter 'Growl呼び出し部 - Private gh As New GrowlHelper("Tween") + Private WithEvents gh As New GrowlHelper("Tween") 'サブ画面インスタンス Private WithEvents SettingDialog As AppendSettingDialog = AppendSettingDialog.Instance '設定画面インスタンス @@ -10813,4 +10813,16 @@ SourceUrlCopyMenuItem.Enabled = True End If End Sub + + Private Sub GrowlHelper_Callback(ByVal sender As Object, ByVal e As EventArgs) Handles gh.Callback + If Form.ActiveForm Is Nothing Then + Me.BeginInvoke(Sub() + Me.Visible = True + If Me.WindowState = FormWindowState.Minimized Then Me.WindowState = FormWindowState.Normal + Me.Activate() + Me.StatusText.Focus() + End Sub) + End If + End Sub + End Class