Skip to content

Commit 0499556

Browse files
committed
Correction of typo and reordering of classes in DockableWindowHost
1 parent fadcf62 commit 0499556

File tree

1 file changed

+98
-98
lines changed

1 file changed

+98
-98
lines changed

RetailCoder.VBE/UI/DockableWindowHost.cs

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -55,84 +55,6 @@ namespace Rubberduck.UI
5555
//
5656

5757

58-
// ExposedUserControl - wrapper for UserControl that also exposes the underlying
59-
// IOleObject and IOleInPlaceObject COM interfaces implemented by it
60-
public class ExposedUserControl : UserControl
61-
{
62-
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
63-
64-
public COM_IOleObject _IOleObject; // cached interface obtained from UserConrol
65-
public COM_IOleInPlaceObject _IOleInPlaceObject; // cached interface obtained from UserConrol
66-
67-
public ExposedUserControl()
68-
{
69-
_logger.Log(LogLevel.Trace, "ExposedUserControl constructor called");
70-
71-
// Gain access to the IOleObject and IOleInPlaceObject interfaces implemented by the UserControl
72-
_IOleObject = (COM_IOleObject)AggregationHelper.ObtainInternalInterface(this, GetType().GetInterface("IOleObject"));
73-
_IOleInPlaceObject = (COM_IOleInPlaceObject)AggregationHelper.ObtainInternalInterface(this, GetType().GetInterface("IOleInPlaceObject"));
74-
}
75-
76-
protected override void Dispose(bool disposing)
77-
{
78-
if (_IOleObject != null)
79-
{
80-
Marshal.ReleaseComObject(_IOleObject);
81-
_IOleObject = null;
82-
}
83-
84-
if (_IOleInPlaceObject != null)
85-
{
86-
Marshal.ReleaseComObject(_IOleInPlaceObject);
87-
_IOleInPlaceObject = null;
88-
}
89-
90-
base.Dispose(disposing);
91-
}
92-
93-
protected override bool ProcessKeyPreview(ref Message m)
94-
{
95-
const int wmKeydown = 0x100;
96-
var result = false;
97-
98-
var hostedUserControl = (UserControl)Controls[0];
99-
100-
if (m.Msg == wmKeydown)
101-
{
102-
var pressedKey = (Keys)m.WParam;
103-
switch (pressedKey)
104-
{
105-
case Keys.Tab:
106-
switch (ModifierKeys)
107-
{
108-
case Keys.None:
109-
SelectNextControl(hostedUserControl.ActiveControl, true, true, true, true);
110-
result = true;
111-
break;
112-
case Keys.Shift:
113-
SelectNextControl(hostedUserControl.ActiveControl, false, true, true, true);
114-
result = true;
115-
break;
116-
}
117-
break;
118-
case Keys.Return:
119-
if (hostedUserControl.ActiveControl.GetType() == typeof(Button))
120-
{
121-
var activeButton = (Button)hostedUserControl.ActiveControl;
122-
activeButton.PerformClick();
123-
}
124-
break;
125-
}
126-
}
127-
128-
if (!result)
129-
{
130-
result = base.ProcessKeyPreview(ref m);
131-
}
132-
return result;
133-
}
134-
}
135-
13658
[ComVisible(true)]
13759
[Guid(RubberduckGuid.DockableWindowHostGuid)]
13860
[ProgId(RubberduckProgId.DockableWindowHostProgId)]
@@ -178,7 +100,7 @@ private void RemoveChildControlsFromExposedControl()
178100
if (pClientSite != IntPtr.Zero)
179101
{
180102
_cachedClientSite = new Wrapper_IOleClientSite(pClientSite);
181-
return _userControl._IOleObject.SetClientSite(_cachedClientSite.PeekAggregatedReference()); // callee will take its own reference
103+
return _userControl.IOleObject.SetClientSite(_cachedClientSite.PeekAggregatedReference()); // callee will take its own reference
182104
}
183105
return (int)COMConstants.S_OK;
184106
}
@@ -193,13 +115,13 @@ private void RemoveChildControlsFromExposedControl()
193115
public int /* IOleObject:: */ SetHostNames([In, MarshalAs(UnmanagedType.LPWStr)] string szContainerApp, [In, MarshalAs(UnmanagedType.LPWStr)] string szContainerObj)
194116
{
195117
_logger.Log(LogLevel.Trace, "IOleObject::SetHostNames() called");
196-
return _userControl._IOleObject.SetHostNames(szContainerApp, szContainerObj);
118+
return _userControl.IOleObject.SetHostNames(szContainerApp, szContainerObj);
197119
}
198120

199121
public int /* IOleObject:: */ Close([In] uint dwSaveOption)
200122
{
201123
_logger.Log(LogLevel.Trace, "IOleObject::Close() called");
202-
int hr = _userControl._IOleObject.Close(dwSaveOption);
124+
int hr = _userControl.IOleObject.Close(dwSaveOption);
203125

204126
// IOleObject::SetClientSite is typically called with pClientSite = null just before calling IOleObject::Close()
205127
// If it didn't, we release all host COM objects here instead,
@@ -213,7 +135,7 @@ private void RemoveChildControlsFromExposedControl()
213135

214136
private void PerformUserControlShutdown()
215137
{
216-
ReleaseCOMReferenceOfSctiveXControl();
138+
ReleaseActiveXControlComReference();
217139
ReleasedExposedControl();
218140
UnsubclassParent();
219141

@@ -235,7 +157,7 @@ private void ReleasedExposedControl()
235157
_userControl = null;
236158
}
237159

238-
private void ReleaseCOMReferenceOfSctiveXControl()
160+
private void ReleaseActiveXControlComReference()
239161
{
240162
_logger.Log(LogLevel.Trace, "IOleObject::Close() ... closing down host COM references");
241163
_cachedClientSite?.Dispose();
@@ -285,7 +207,7 @@ private void ReleaseCOMReferenceOfSctiveXControl()
285207
_logger.Log(LogLevel.Trace, "IOleObject::DoVerb() called");
286208
// pActiveSite is not used by the UserControl implementation. Either wrap it or pass null instead
287209
pActiveSite = IntPtr.Zero;
288-
return _userControl._IOleObject.DoVerb(iVerb, lpmsg, pActiveSite, lindex, hwndParent, lprcPosRect);
210+
return _userControl.IOleObject.DoVerb(iVerb, lpmsg, pActiveSite, lindex, hwndParent, lprcPosRect);
289211
}
290212

291213
public int /* IOleObject:: */ EnumVerbs([Out] out IntPtr /* IEnumOLEVERB */ ppEnumOleVerb)
@@ -301,37 +223,37 @@ private void ReleaseCOMReferenceOfSctiveXControl()
301223
public int /* IOleObject:: */ Update()
302224
{
303225
_logger.Log(LogLevel.Trace, "IOleObject::Update() called");
304-
return _userControl._IOleObject.Update();
226+
return _userControl.IOleObject.Update();
305227
}
306228

307229
public int /* IOleObject:: */ IsUpToDate()
308230
{
309231
_logger.Log(LogLevel.Trace, "IOleObject::IsUpToDate() called");
310-
return _userControl._IOleObject.IsUpToDate();
232+
return _userControl.IOleObject.IsUpToDate();
311233
}
312234

313235
public int /* IOleObject:: */ GetUserClassID([Out] out Guid pClsid)
314236
{
315237
_logger.Log(LogLevel.Trace, "IOleObject::GetUserClassID() called");
316-
return _userControl._IOleObject.GetUserClassID(out pClsid);
238+
return _userControl.IOleObject.GetUserClassID(out pClsid);
317239
}
318240

319241
public int /* IOleObject:: */ GetUserType([In] uint dwFormOfType, [Out, MarshalAs(UnmanagedType.LPWStr)] out string pszUserType)
320242
{
321243
_logger.Log(LogLevel.Trace, "IOleObject::GetUserType() called");
322-
return _userControl._IOleObject.GetUserType(dwFormOfType, out pszUserType);
244+
return _userControl.IOleObject.GetUserType(dwFormOfType, out pszUserType);
323245
}
324246

325247
public int /* IOleObject:: */ SetExtent([In] uint dwDrawAspect, [In] IntPtr /* tagSIZE */ psizel)
326248
{
327249
_logger.Log(LogLevel.Trace, "IOleObject::SetExtent() called");
328-
return _userControl._IOleObject.SetExtent(dwDrawAspect, psizel);
250+
return _userControl.IOleObject.SetExtent(dwDrawAspect, psizel);
329251
}
330252

331253
public int /* IOleObject:: */ GetExtent([In] uint dwDrawAspect, [Out] out IntPtr /* tagSIZE */ psizel)
332254
{
333255
_logger.Log(LogLevel.Trace, "IOleObject::GetExtent() called");
334-
return _userControl._IOleObject.GetExtent(dwDrawAspect, out psizel);
256+
return _userControl.IOleObject.GetExtent(dwDrawAspect, out psizel);
335257
}
336258

337259
public int /* IOleObject:: */ Advise([In] IntPtr /* IAdviseSink */ pAdvSink, [Out] out uint pdwConnection)
@@ -363,51 +285,51 @@ private void ReleaseCOMReferenceOfSctiveXControl()
363285
public int /* IOleObject:: */ GetMiscStatus([In] uint dwAspect, [Out] out uint pdwStatus)
364286
{
365287
_logger.Log(LogLevel.Trace, "IOleObject::GetMiscStatus() called");
366-
return _userControl._IOleObject.GetMiscStatus(dwAspect, out pdwStatus);
288+
return _userControl.IOleObject.GetMiscStatus(dwAspect, out pdwStatus);
367289
}
368290

369291
public int /* IOleObject:: */ SetColorScheme([In] IntPtr /* tagLOGPALETTE */ pLogpal)
370292
{
371293
_logger.Log(LogLevel.Trace, "IOleObject::SetColorScheme() called");
372-
return _userControl._IOleObject.SetColorScheme(pLogpal);
294+
return _userControl.IOleObject.SetColorScheme(pLogpal);
373295
}
374296

375297
// --------------------------------------------------------------------
376298

377299
public int /* IOleInPlaceObject:: */ GetWindow([Out] out IntPtr hwnd)
378300
{
379301
_logger.Log(LogLevel.Trace, "IOleInPlaceObject::GetWindow() called");
380-
return _userControl._IOleInPlaceObject.GetWindow(out hwnd);
302+
return _userControl.IOleInPlaceObject.GetWindow(out hwnd);
381303
}
382304

383305
public int /* IOleInPlaceObject:: */ ContextSensitiveHelp([In] int fEnterMode)
384306
{
385307
_logger.Log(LogLevel.Trace, "IOleInPlaceObject::ContextSensitiveHelp() called");
386-
return _userControl._IOleInPlaceObject.ContextSensitiveHelp(fEnterMode);
308+
return _userControl.IOleInPlaceObject.ContextSensitiveHelp(fEnterMode);
387309
}
388310

389311
public int /* IOleInPlaceObject:: */ InPlaceDeactivate()
390312
{
391313
_logger.Log(LogLevel.Trace, "IOleInPlaceObject::InPlaceDeactivate() called");
392-
return _userControl._IOleInPlaceObject.InPlaceDeactivate();
314+
return _userControl.IOleInPlaceObject.InPlaceDeactivate();
393315
}
394316

395317
public int /* IOleInPlaceObject:: */ UIDeactivate()
396318
{
397319
_logger.Log(LogLevel.Trace, "IOleInPlaceObject::UIDeactivate() called");
398-
return _userControl._IOleInPlaceObject.UIDeactivate();
320+
return _userControl.IOleInPlaceObject.UIDeactivate();
399321
}
400322

401323
public int /* IOleInPlaceObject:: */ SetObjectRects([In] IntPtr lprcPosRect, [In] IntPtr lprcClipRect)
402324
{
403325
_logger.Log(LogLevel.Trace, "IOleInPlaceObject::SetObjectRects() called");
404-
return _userControl._IOleInPlaceObject.SetObjectRects(lprcPosRect, lprcClipRect);
326+
return _userControl.IOleInPlaceObject.SetObjectRects(lprcPosRect, lprcClipRect);
405327
}
406328

407329
public int /* IOleInPlaceObject:: */ ReactivateAndUndo()
408330
{
409331
_logger.Log(LogLevel.Trace, "IOleInPlaceObject::ReactivateAndUndo() called");
410-
return _userControl._IOleInPlaceObject.ReactivateAndUndo();
332+
return _userControl.IOleInPlaceObject.ReactivateAndUndo();
411333
}
412334

413335
// old stuff from old _DockableWindowHost --------------------------------------- [START]
@@ -526,5 +448,83 @@ protected override void Dispose(bool disposing)
526448
}
527449

528450
// old stuff from old _DockableWindowHost --------------------------------------- [END]
451+
452+
// ExposedUserControl - wrapper for UserControl that also exposes the underlying
453+
// IOleObject and IOleInPlaceObject COM interfaces implemented by it
454+
public class ExposedUserControl : UserControl
455+
{
456+
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
457+
458+
public COM_IOleObject IOleObject; // cached interface obtained from UserConrol
459+
public COM_IOleInPlaceObject IOleInPlaceObject; // cached interface obtained from UserConrol
460+
461+
public ExposedUserControl()
462+
{
463+
_logger.Log(LogLevel.Trace, "ExposedUserControl constructor called");
464+
465+
// Gain access to the IOleObject and IOleInPlaceObject interfaces implemented by the UserControl
466+
IOleObject = (COM_IOleObject)AggregationHelper.ObtainInternalInterface(this, GetType().GetInterface("IOleObject"));
467+
IOleInPlaceObject = (COM_IOleInPlaceObject)AggregationHelper.ObtainInternalInterface(this, GetType().GetInterface("IOleInPlaceObject"));
468+
}
469+
470+
protected override void Dispose(bool disposing)
471+
{
472+
if (IOleObject != null)
473+
{
474+
Marshal.ReleaseComObject(IOleObject);
475+
IOleObject = null;
476+
}
477+
478+
if (IOleInPlaceObject != null)
479+
{
480+
Marshal.ReleaseComObject(IOleInPlaceObject);
481+
IOleInPlaceObject = null;
482+
}
483+
484+
base.Dispose(disposing);
485+
}
486+
487+
protected override bool ProcessKeyPreview(ref Message m)
488+
{
489+
const int wmKeydown = 0x100;
490+
var result = false;
491+
492+
var hostedUserControl = (UserControl)Controls[0];
493+
494+
if (m.Msg == wmKeydown)
495+
{
496+
var pressedKey = (Keys)m.WParam;
497+
switch (pressedKey)
498+
{
499+
case Keys.Tab:
500+
switch (ModifierKeys)
501+
{
502+
case Keys.None:
503+
SelectNextControl(hostedUserControl.ActiveControl, true, true, true, true);
504+
result = true;
505+
break;
506+
case Keys.Shift:
507+
SelectNextControl(hostedUserControl.ActiveControl, false, true, true, true);
508+
result = true;
509+
break;
510+
}
511+
break;
512+
case Keys.Return:
513+
if (hostedUserControl.ActiveControl.GetType() == typeof(Button))
514+
{
515+
var activeButton = (Button)hostedUserControl.ActiveControl;
516+
activeButton.PerformClick();
517+
}
518+
break;
519+
}
520+
}
521+
522+
if (!result)
523+
{
524+
result = base.ProcessKeyPreview(ref m);
525+
}
526+
return result;
527+
}
528+
}
529529
}
530530
}

0 commit comments

Comments
 (0)