1
1
using System ;
2
2
using System . Linq ;
3
+ using System . Runtime . InteropServices ;
4
+ using System . Text ;
3
5
using Rubberduck . VBEditor . Application ;
4
6
using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
7
+ using Rubberduck . VBEditor . SafeComWrappers . Office . Core ;
5
8
using Rubberduck . VBEditor . SafeComWrappers . Office . Core . Abstract ;
9
+ using Rubberduck . VBEditor . WindowsApi ;
6
10
using VB = Microsoft . VB6 . Interop . VBIDE ;
7
11
8
12
namespace Rubberduck . VBEditor . SafeComWrappers . VB6
@@ -21,59 +25,70 @@ public object HardReference
21
25
22
26
public string Version
23
27
{
24
- get { return IsWrappingNullReference ? string . Empty : Target . get_Version ( ) ; }
28
+ get { return IsWrappingNullReference ? string . Empty : Target . Version ; }
25
29
}
26
30
27
31
public ICodePane ActiveCodePane
28
32
{
29
- get { throw new NotImplementedException ( ) ; }
30
- set { throw new NotImplementedException ( ) ; }
33
+ get { return new CodePane ( IsWrappingNullReference ? null : Target . ActiveCodePane ) ; }
34
+ set { if ( ! IsWrappingNullReference ) Target . ActiveCodePane = ( VB . CodePane ) value . Target ; }
31
35
}
32
36
33
37
public IVBProject ActiveVBProject
34
38
{
35
- get { throw new NotImplementedException ( ) ; }
36
- set { throw new NotImplementedException ( ) ; }
39
+ get { return new VBProject ( IsWrappingNullReference ? null : Target . ActiveVBProject ) ; }
40
+ set { if ( ! IsWrappingNullReference ) Target . ActiveVBProject = ( VB . VBProject ) value . Target ; }
37
41
}
38
42
39
43
public IWindow ActiveWindow
40
44
{
41
- get { throw new NotImplementedException ( ) ; }
45
+ get { return new Window ( IsWrappingNullReference ? null : Target . ActiveWindow ) ; }
42
46
}
43
47
44
48
public IAddIns AddIns
45
49
{
46
- get { throw new NotImplementedException ( ) ; }
50
+ get { return new AddIns ( IsWrappingNullReference ? null : Target . Addins ) ; }
47
51
}
48
52
49
53
public ICodePanes CodePanes
50
54
{
51
- get { throw new NotImplementedException ( ) ; }
55
+ get { return new CodePanes ( IsWrappingNullReference ? null : Target . CodePanes ) ; }
52
56
}
53
57
54
58
public ICommandBars CommandBars
55
59
{
56
- get { throw new NotImplementedException ( ) ; }
60
+ get { return new CommandBars ( IsWrappingNullReference ? null : Target . CommandBars ) ; }
57
61
}
58
62
59
63
public IWindow MainWindow
60
64
{
61
- get { throw new NotImplementedException ( ) ; }
65
+ get
66
+ {
67
+ try
68
+ {
69
+ return new Window ( IsWrappingNullReference ? null : Target . MainWindow ) ;
70
+ }
71
+ catch ( InvalidComObjectException )
72
+ {
73
+ return null ;
74
+ }
75
+ }
62
76
}
63
77
64
78
public IVBComponent SelectedVBComponent
65
79
{
66
- get { throw new NotImplementedException ( ) ; }
80
+ get { return new VBComponent ( IsWrappingNullReference ? null : Target . SelectedVBComponent ) ; }
67
81
}
68
82
69
83
public IVBProjects VBProjects
70
84
{
71
- get { return new VBProjects ( IsWrappingNullReference ? null : Target . get_VBProjects ( ) ) ; }
85
+ get { return new VBProjects ( IsWrappingNullReference ? null : Target . VBProjects ) ; }
72
86
}
73
87
74
88
public IWindows Windows
75
89
{
76
- get { throw new NotImplementedException ( ) ; }
90
+ get { return new Windows ( IsWrappingNullReference ? null : Target . Windows ) ; }
91
+
77
92
}
78
93
79
94
//public override void Release(bool final = false)
@@ -91,7 +106,7 @@ public IWindows Windows
91
106
92
107
public override bool Equals ( ISafeComWrapper < VB . VBE > other )
93
108
{
94
- return IsEqualIfNull ( other ) || ( other != null && other . Target . get_Version ( ) == Version ) ;
109
+ return IsEqualIfNull ( other ) || ( other != null && other . Target . Version == Version ) ;
95
110
}
96
111
97
112
public bool Equals ( IVBE other )
@@ -111,7 +126,28 @@ public IHostApplication HostApplication()
111
126
112
127
public IWindow ActiveMDIChild ( )
113
128
{
114
- throw new NotImplementedException ( ) ;
129
+ const string mdiClientClass = "MDIClient" ;
130
+ const int maxCaptionLength = 512 ;
131
+
132
+ IntPtr mainWindow = ( IntPtr ) MainWindow . HWnd ;
133
+
134
+ IntPtr mdiClient = NativeMethods . FindWindowEx ( mainWindow , IntPtr . Zero , mdiClientClass , string . Empty ) ;
135
+
136
+ IntPtr mdiChild = NativeMethods . GetTopWindow ( mdiClient ) ;
137
+ StringBuilder mdiChildCaption = new StringBuilder ( ) ;
138
+ int captionLength = NativeMethods . GetWindowText ( mdiChild , mdiChildCaption , maxCaptionLength ) ;
139
+
140
+ if ( captionLength > 0 )
141
+ {
142
+ try
143
+ {
144
+ return Windows . FirstOrDefault ( win => win . Caption == mdiChildCaption . ToString ( ) ) ;
145
+ }
146
+ catch
147
+ {
148
+ }
149
+ }
150
+ return null ;
115
151
}
116
152
117
153
public bool IsInDesignMode
0 commit comments