context: //    This file is part of QTTabBar, a shell extension for Microsoft
  //    Windows Explorer.
  //    Copyright (C) 2007-2010  Quizo, Paul Accisano
  //
  //    QTTabBar is free software: you can redistribute it and/or modify
  //    it under the terms of the GNU General Public License as published by
  //    the Free Software Foundation, either version 3 of the License, or
  //    (at your option) any later version.
  //
  //    QTTabBar is distributed in the hope that it will be useful,
  //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  //    GNU General Public License for more details.
  //
  //    You should have received a copy of the GNU General Public License
  //    along with QTTabBar.  If not, see <http://www.gnu.org/licenses/>.
  
  using System;
  using System.Windows.Forms;
  
  namespace QTTabBarLib {
      internal class QMenuItem : ToolStripMenuItem {
          private string extension;
          private bool fCut;
          private bool fExistsAsserted;
          private bool fForceToolTip;
          private bool fHasIcon;
          private bool fImageLoaded;
          private bool fVirtualQueried;
          private byte[] idl;
          private byte[] idlChild;
          private ImageReservationKey imageReservationKey;
          private MenuGenre menuGenre;
          private MenuTarget menuTarget;
          private MenuItemArguments mia;
          private string originalImageKey;
          private string originalTitle;
          private string path;
          private string pathChild;
          private string targetPath;
  
          public event EventHandler QueryVirtualMenu;
  
          public QMenuItem(string title, MenuGenre menuGenre)
              : base(title) {
              this.menuGenre = menuGenre;
          }
  
          public QMenuItem(string title, MenuItemArguments mia)
              : base(title) {
              if(mia != null) {
                  path = mia.Path;
                  this.mia = mia;
                  menuTarget = mia.Target;
                  menuGenre = mia.Genre;
              }
          }
  
          public QMenuItem(string title, MenuTarget menuTarget, MenuGenre menuGenre)
              : base(title) {
              this.menuTarget = menuTarget;
              this.menuGenre = menuGenre;
          }
  
          protected override void Dispose(bool disposing) {
              base.Dispose(disposing);
              if((disposing && base.HasDropDownItems) && !DropDown.IsAutoGenerated) {
                  DropDown.Dispose();
                  DropDown = null;
              }
          }
  
          protected override void OnMouseHover(EventArgs e) {
              if(!string.IsNullOrEmpty(ToolTipText)) {
                  DropDownMenuBase parent = Parent as DropDownMenuBase;
                  if((parent != null) && parent.UpdateToolTip_OnTheEdge(this)) {
                      return;
                  }
              }
              base.OnMouseHover(e);
          }
  
          protected override void OnPaint(PaintEventArgs e) {
              if(!fImageLoaded) {
                  fImageLoaded = true;
                  if(imageReservationKey != null) {
                      QTUtility.LoadReservedImage(imageReservationKey);
                  }
              }
              if(!fVirtualQueried) {
                  fVirtualQueried = true;
                  if(QueryVirtualMenu != null) {
                      QueryVirtualMenu(this, EventArgs.Empty);
                      QueryVirtualMenu = null;
                  }
              }
              base.OnPaint(e);
          }
  
          internal void RestoreOriginalImage() {
              if(!base.ImageKey.Equals(originalImageKey)) {
                  base.ImageKey = originalImageKey;
              }
          }
  
          internal void RestoreOriginalImage(bool changeImageSelected, bool fForceSelectedImage) {
              if((mia != null) && (fForceSelectedImage || (changeImageSelected && Selected))) {
                  if(mia.IsBack) {
                      if(mia.Index == 0) {
                          base.ImageKey = "current";
                      }
                      else {
                          base.ImageKey = "back";
                      }
                  }
                  else {
                      base.ImageKey = "forward";
                  }
              }
              else if(!base.ImageKey.Equals(originalImageKey)) {
                  base.ImageKey = originalImageKey;
              }
          }
  
          public void SetImageReservationKey(string path, string ext) {
              imageReservationKey = QTUtility.ReserveImageKey(this, path, ext);
              ImageKey = imageReservationKey.ImageKey;
              fImageLoaded = imageReservationKey.ImageKey == "folder";
          }
  
          public bool Exists {
              get {
                  return fExistsAsserted;
              }
              set {
                  fExistsAsserted = value;
              }
          }
  
          public virtual string Extension {
              get {
                  return extension;
              }
              set {
                  extension = value;
              }
          }
  
          public bool ForceToolTip {
              get {
                  return fForceToolTip;
              }
              set {
                  fForceToolTip = value;
              }
          }
  
          public MenuGenre Genre {
              get {
                  return menuGenre;
              }
          }
  
          public bool HasIcon {
              get {
                  return fHasIcon;
              }
              set {
                  fHasIcon = value;
              }
          }
  
          public byte[] IDLData {
              get {
                  return idl;
              }
              set {
                  idl = value;
              }
          }
  
          public byte[] IDLDataChild {
              get {
                  return idlChild;
              }
              set {
                  idlChild = value;
              }
          }
  
          new public string ImageKey {
              get {
                  return base.ImageKey;
              }
              set {
                  if(base.ImageKey.Length == 0) {
                      originalImageKey = value;
                  }
                  base.ImageKey = value;
              }
          }
  
          public bool IsCut {
              get {
                  return fCut;
              }
              set {
  
gt:                 if(fCut ^ value) {