ImageEn, unit iesettings

TIEGlobalSettings.OnAddCustomPopupMenuItem

TIEGlobalSettings.OnAddCustomPopupMenuItem


Declaration

property OnAddCustomPopupMenuItem: TIEAddCustomButtonEvent;


Description

Event used to add extra items to in-built popup menus, such as the TImageEnView and TImageEnMView Popup Menus.
This event is called for each item that is added to the menu, allowing you to position your new button(s) before a specific button.
To add an extra item set AddButton and specify the properties of the popup menu item.

Value Description
Sender The popup menu
BeforeButtonID Specifies the ID of an item being added. Your custom item will be positioned to BELOW this item. 0: Specifies the very top of the menu. -1 specifies the very bottom of the menu
AddButton Set to true if you are adding a button at this position
BtnID Your own ID to recognize this item. It should be IECustom_Button_ID + n
BtnCaption A caption for the item. This is only used if ShowCaptions is true
BtnHint Not used for popup menu items
BtnImgID Specify one of the Toolbar Button Image Constants. If you need to customize the images, use OnAddToolbarButtonImage

To enable or disable the menu item use the OnToolbarButtonUpdate event.
To handle the clicking of the menu item use the OnToolbarButtonExecute event.

Note:
Custom items cannot be added to sub-menus
Specify caption as '-' to add a separator
Ensure you reset this event before destroying your form, e.g. IEGlobalSettings().OnAddCustomPopupMenuItem := nil;


Demo

Demo  Demos\Other\ImageEnViewToolbar\IEToolbar.dpr


Example

IEGlobalSettings().OnAddCustomPopupMenuItem := Form1AddCustomPopupMenuItem;
IEGlobalSettings().OnToolbarButtonExecute   := Form1CustomButtonExecute;

// Add a custom open button, and two other buttons to the bottom of the menu
const
  MY_HOME_BUTTON_ID       = IECustom_Button_ID + 1;
  MY_IMAGEINFO_BUTTON_ID  = IECustom_Button_ID + 2;
  MY_LOADRECENT_BUTTON_ID = IECustom_Button_ID + 3;

procedure TMainForm.Form1CustomButtonExecute(Sender: TObject; ButtonID: Integer; var Handled: Boolean);
begin
  // Button Clicked
  case ButtonID of
    MY_HOME_BUTTON_ID       : ShellExecute(Handle, nil, PChar('http://www.imageen.com'), nil,  nil, SW_SHOWNORMAL);
    MY_IMAGEINFO_BUTTON_ID  : ShowMessage( Format( 'Image Size: %d x %d', [ ImageEnView1.IEBitmap.Width, ImageEnView1.IEBitmap.Height ]));
    MY_LOADRECENT_BUTTON_ID : ImageEnView1.IO.LoadFromFile( fLastUsedFile );
  end;
end;

procedure TMainForm.Form1AddCustomPopupMenuItem(Sender: TObject;
    BeforeButtonID: Integer; var AddButton: Boolean; var BtnID: Integer; var
    BtnCaption, BtnHint: string; var BtnImgID: Integer);
begin
  // NOTE: For popup menus, items are added AFTER the item of BeforeButtonID

  if BeforeButtonID = -1 then  // Bottom of menu
  begin
    AddButton := True;

    BtnID      := MY_HOME_BUTTON_ID;
    BtnCaption := 'Home Page';
    BtnImgID   := ITBRES_HOMEOUTLINE_24;
  end
  else
  if ( ImageEnView1.IsEmpty = False ) and ( BeforeButtonID = MY_HOME_BUTTON_ID ) then  // Below "Home" item
  begin
    AddButton := True;

    BtnID      := MY_IMAGEINFO_BUTTON_ID;
    BtnCaption := 'About this Image';
    BtnImgID   := ITBRES_INFORMATIONOUTLINE_24;
  end
  else
  if ( fLastUsedFile <> '' ) and ( BeforeButtonID = IEViewSave_Button_ID ) then  // Below "Save" item
  begin
    AddButton := True;

    BtnID      := MY_LOADRECENT_BUTTON_ID;
    BtnCaption := 'Open Last File';
    BtnImgID   := ITBRES_FOLDERIMAGE_24;
  end;
end;


See Also

OnAddCustomToolbarButton