internal bool GetMessageLoop(bool mustBeActive)
 {
     if (this.messageLoopCount > ((mustBeActive && this.externalComponentManager) ? 1 : 0))
     {
         return true;
     }
     if ((this.ComponentManager != null) && this.externalComponentManager)
     {
         if (!mustBeActive)
         {
             return true;
         }
         System.Windows.Forms.UnsafeNativeMethods.IMsoComponent[] ppic = new System.Windows.Forms.UnsafeNativeMethods.IMsoComponent[1];
         if (this.ComponentManager.FGetActiveComponent(0, ppic, null, 0) && (ppic[0] == this))
         {
             return true;
         }
     }
     Application.MessageLoopCallback messageLoopCallback = this.messageLoopCallback;
     return ((messageLoopCallback != null) && messageLoopCallback());
 }
 bool System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FSetTrackingComponent(IntPtr dwComponentID, bool fTrack)
 {
     int num = (int) ((long) dwComponentID);
     ComponentHashtableEntry entry = (ComponentHashtableEntry) this.OleComponents[num];
     if (entry == null)
     {
         return false;
     }
     if ((entry.component == this.trackingComponent) ^ fTrack)
     {
         return false;
     }
     if (fTrack)
     {
         this.trackingComponent = entry.component;
     }
     else
     {
         this.trackingComponent = null;
     }
     return true;
 }
 bool System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FRevokeComponent(IntPtr dwComponentID)
 {
     int key = (int) ((long) dwComponentID);
     ComponentHashtableEntry entry = (ComponentHashtableEntry) this.OleComponents[key];
     if (entry == null)
     {
         return false;
     }
     if (entry.component == this.activeComponent)
     {
         this.activeComponent = null;
     }
     if (entry.component == this.trackingComponent)
     {
         this.trackingComponent = null;
     }
     this.OleComponents.Remove(key);
     return true;
 }
 bool System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, int reason, int pvLoopData)
 {
     int key = (int) ((long) dwComponentID);
     int currentState = this.currentState;
     bool flag = true;
     if (!this.OleComponents.ContainsKey(key))
     {
         return false;
     }
     System.Windows.Forms.UnsafeNativeMethods.IMsoComponent activeComponent = this.activeComponent;
     try
     {
         System.Windows.Forms.NativeMethods.MSG msg = new System.Windows.Forms.NativeMethods.MSG();
         System.Windows.Forms.NativeMethods.MSG[] pMsgPeeked = new System.Windows.Forms.NativeMethods.MSG[] { msg };
         bool flag2 = false;
         ComponentHashtableEntry entry = (ComponentHashtableEntry) this.OleComponents[key];
         if (entry == null)
         {
             return false;
         }
         System.Windows.Forms.UnsafeNativeMethods.IMsoComponent component = entry.component;
         this.activeComponent = component;
         while (flag)
         {
             System.Windows.Forms.UnsafeNativeMethods.IMsoComponent trackingComponent;
             if (this.trackingComponent != null)
             {
                 trackingComponent = this.trackingComponent;
             }
             else if (this.activeComponent != null)
             {
                 trackingComponent = this.activeComponent;
             }
             else
             {
                 trackingComponent = component;
             }
             if (System.Windows.Forms.UnsafeNativeMethods.PeekMessage(ref msg, System.Windows.Forms.NativeMethods.NullHandleRef, 0, 0, 0))
             {
                 pMsgPeeked[0] = msg;
                 flag = trackingComponent.FContinueMessageLoop(reason, pvLoopData, pMsgPeeked);
                 if (flag)
                 {
                     if ((msg.hwnd != IntPtr.Zero) && System.Windows.Forms.SafeNativeMethods.IsWindowUnicode(new HandleRef(null, msg.hwnd)))
                     {
                         flag2 = true;
                         System.Windows.Forms.UnsafeNativeMethods.GetMessageW(ref msg, System.Windows.Forms.NativeMethods.NullHandleRef, 0, 0);
                     }
                     else
                     {
                         flag2 = false;
                         System.Windows.Forms.UnsafeNativeMethods.GetMessageA(ref msg, System.Windows.Forms.NativeMethods.NullHandleRef, 0, 0);
                     }
                     if (msg.message == 0x12)
                     {
                         Application.ThreadContext.FromCurrent().DisposeThreadWindows();
                         if (reason != -1)
                         {
                             System.Windows.Forms.UnsafeNativeMethods.PostQuitMessage((int) msg.wParam);
                         }
                         flag = false;
                         goto Label_024C;
                     }
                     if (!trackingComponent.FPreTranslateMessage(ref msg))
                     {
                         System.Windows.Forms.UnsafeNativeMethods.TranslateMessage(ref msg);
                         if (flag2)
                         {
                             System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(ref msg);
                         }
                         else
                         {
                             System.Windows.Forms.UnsafeNativeMethods.DispatchMessageA(ref msg);
                         }
                     }
                 }
             }
             else
             {
                 if ((reason == 2) || (reason == -2))
                 {
                     goto Label_024C;
                 }
                 bool flag4 = false;
                 if (this.OleComponents != null)
                 {
                     IEnumerator enumerator = this.OleComponents.Values.GetEnumerator();
                     while (enumerator.MoveNext())
                     {
                         ComponentHashtableEntry current = (ComponentHashtableEntry) enumerator.Current;
                         flag4 |= current.component.FDoIdle(-1);
                     }
                 }
                 flag = trackingComponent.FContinueMessageLoop(reason, pvLoopData, null);
                 if (flag)
                 {
                     if (flag4)
                     {
                         System.Windows.Forms.UnsafeNativeMethods.MsgWaitForMultipleObjectsEx(0, IntPtr.Zero, 100, 0xff, 4);
                     }
                     else if (!System.Windows.Forms.UnsafeNativeMethods.PeekMessage(ref msg, System.Windows.Forms.NativeMethods.NullHandleRef, 0, 0, 0))
                     {
                         System.Windows.Forms.UnsafeNativeMethods.WaitMessage();
                     }
                 }
             }
         }
     }
     finally
     {
         this.currentState = currentState;
         this.activeComponent = activeComponent;
     }
 Label_024C:
     return !flag;
 }
 bool System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FOnComponentActivate(IntPtr dwComponentID)
 {
     int num = (int) ((long) dwComponentID);
     ComponentHashtableEntry entry = (ComponentHashtableEntry) this.OleComponents[num];
     if (entry == null)
     {
         return false;
     }
     this.activeComponent = entry.component;
     return true;
 }
 bool System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FGetActiveComponent(int dwgac, System.Windows.Forms.UnsafeNativeMethods.IMsoComponent[] ppic, System.Windows.Forms.NativeMethods.MSOCRINFOSTRUCT info, int dwReserved)
 {
     System.Windows.Forms.UnsafeNativeMethods.IMsoComponent activeComponent = null;
     if (dwgac == 0)
     {
         activeComponent = this.activeComponent;
     }
     else if (dwgac == 1)
     {
         activeComponent = this.trackingComponent;
     }
     else if (dwgac == 2)
     {
         if (this.trackingComponent != null)
         {
             activeComponent = this.trackingComponent;
         }
         else
         {
             activeComponent = this.activeComponent;
         }
     }
     if (ppic != null)
     {
         ppic[0] = activeComponent;
     }
     if ((info != null) && (activeComponent != null))
     {
         foreach (ComponentHashtableEntry entry in this.OleComponents.Values)
         {
             if (entry.component == activeComponent)
             {
                 info = entry.componentInfo;
                 break;
             }
         }
     }
     return (activeComponent != null);
 }