Ejemplo n.º 1
0
 public void Add(FuncItem funcItem)
 {
     int oldSize = _funcItems.Count * _sizeFuncItem;
     _funcItems.Add(funcItem);
     int newSize = _funcItems.Count * _sizeFuncItem;
     IntPtr newPointer = Marshal.AllocHGlobal(newSize);
     if (_nativePointer != IntPtr.Zero) {
         RtlMoveMemory(newPointer, _nativePointer, oldSize);
         Marshal.FreeHGlobal(_nativePointer);
     }
     IntPtr ptrPosNewItem = (IntPtr)((int)newPointer + oldSize);
     byte[] aB = Encoding.Unicode.GetBytes(funcItem._itemName + "\0");
     Marshal.Copy(aB, 0, ptrPosNewItem, aB.Length);
     ptrPosNewItem = (IntPtr)((int)ptrPosNewItem + 128);
     IntPtr p = (funcItem._pFunc != null) ? Marshal.GetFunctionPointerForDelegate(funcItem._pFunc) : IntPtr.Zero;
     Marshal.WriteIntPtr(ptrPosNewItem, p);
     ptrPosNewItem = (IntPtr)((int)ptrPosNewItem + IntPtr.Size);
     Marshal.WriteInt32(ptrPosNewItem, funcItem._cmdID);
     ptrPosNewItem = (IntPtr)((int)ptrPosNewItem + 4);
     Marshal.WriteInt32(ptrPosNewItem, Convert.ToInt32(funcItem._init2Check));
     ptrPosNewItem = (IntPtr)((int)ptrPosNewItem + 4);
     if (funcItem._pShKey._key != 0) {
         IntPtr newShortCutKey = Marshal.AllocHGlobal(4);
         Marshal.StructureToPtr(funcItem._pShKey, newShortCutKey, false);
         Marshal.WriteIntPtr(ptrPosNewItem, newShortCutKey);
     } else Marshal.WriteIntPtr(ptrPosNewItem, IntPtr.Zero);
     _nativePointer = newPointer;
 }
Ejemplo n.º 2
0
 public void RefreshItems()
 {
     IntPtr ptrPosItem = _nativePointer;
     for (int i = 0; i < _funcItems.Count; i++) {
         FuncItem updatedItem = new FuncItem();
         updatedItem._itemName = _funcItems[i]._itemName;
         ptrPosItem = (IntPtr)((int)ptrPosItem + 128);
         updatedItem._pFunc = _funcItems[i]._pFunc;
         ptrPosItem = (IntPtr)((int)ptrPosItem + IntPtr.Size);
         updatedItem._cmdID = Marshal.ReadInt32(ptrPosItem);
         ptrPosItem = (IntPtr)((int)ptrPosItem + 4);
         updatedItem._init2Check = _funcItems[i]._init2Check;
         ptrPosItem = (IntPtr)((int)ptrPosItem + 4);
         updatedItem._pShKey = _funcItems[i]._pShKey;
         ptrPosItem = (IntPtr)((int)ptrPosItem + IntPtr.Size);
         _funcItems[i] = updatedItem;
     }
 }
Ejemplo n.º 3
0
Archivo: Npp.cs Proyecto: jcaillon/3P
 /// <summary>
 /// Creates entry in the FuncItems list, which list the menu entry displayed in Npp's plugin menu
 /// </summary>
 public static void SetCommand(int index, string commandName, Action functionPointer, ShortcutKey shortcut = new ShortcutKey(), bool checkOnInit = false)
 {
     var funcItem = new FuncItem {
         _cmdID = index,
         _itemName = commandName
     };
     if (functionPointer != null)
         funcItem._pFunc = functionPointer;
     if (shortcut._key != 0)
         funcItem._pShKey = shortcut;
     funcItem._init2Check = checkOnInit;
     UnmanagedExports.FuncItems.Add(funcItem);
 }