ImageEn, unit iexToolbars

TIEAddCustomButtonEvent


Declaration

TIEAddCustomButtonEvent = procedure(Sender: TObject;
                                    BeforeButtonID: Integer;
                                    var AddButton: Boolean;
                                    var BtnID: Integer;
                                    var BtnCaption: string;
                                    var BtnHint: string;
                                    var BtnImgID: Integer) of object;

Description

Event that allows addition of extra buttons to the toolbar.
This event is called for each button that is added to the toolbar, allowing you to position your new button(s) before a specific button.
To add an extra button set AddButton and specify the properties of the button.

Value Description
Sender This toolbar
BeforeButtonID Specifies the ID of a button being added. Your custom button will be positioned to the left of this button. 0: Specifies the very left of the toolbar. -1 specifies the very right of the toolbar.
AddButton Set to true if you are adding a button at this position
BtnID Your own ID to recognize this button. It should be IECustom_Button_ID + n
BtnCaption A caption for the button. This is only used if ShowCaptions is true
BtnHint A hover hint for the button
BtnImgID Specify one of the Toolbar Button Image Constants. If you need to customize the buttons, use OnAddButtonImage

To enable or disable the button use the OnActionUpdate event.
To handle the clicking of the button use the OnActionExecute event.


Demos

Demo  Demos\Other\ImageEnViewToolbar\IEToolbar.dpr
Demo  Demos\PDF\PDFViewerToolbar\PdfViewerToolbar.dpr


Example

// Add a custom open button, and two other buttons to the right side of the toolbar
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.ImageEnViewToolbar1ActionExecute(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.ImageEnViewToolbar1ActionUpdate(Sender: TObject; ButtonID:
    Integer; var Handled: Boolean);
begin
  // Set status of button
  case ButtonID of
    MY_IMAGEINFO_BUTTON_ID  : TControl( Sender).Enabled := not ImageEnView1.IsEmpty;
    MY_LOADRECENT_BUTTON_ID : TControl( Sender).Enabled := fLastUsedFile <> '';
  end;
end;

procedure TMainForm.ImageEnViewToolbar1AddCustomButton(Sender: TObject;
    BeforeButtonID: Integer; var AddButton: Boolean; var BtnID: Integer; var
    BtnCaption, BtnHint: string; var BtnImgID: Integer);
begin
  if BeforeButtonID = -1 then  // Right-side of toolbar
  begin
    AddButton := True;

    BtnID      := MY_HOME_BUTTON_ID;
    BtnCaption := 'Home';       // Not usually used
    BtnHint    := 'Visit www.imageEn.com';
    BtnImgID   := ITBRES_HOMEOUTLINE_24;
  end
  else
  if BeforeButtonID = MY_HOME_BUTTON_ID then  // To Left of MY_HOME_BUTTON_ID
  begin
    AddButton := True;

    BtnID      := MY_IMAGEINFO_BUTTON_ID;
    BtnCaption := 'About';       // Not usually used
    BtnHint    := 'About this Image';
    BtnImgID   := ITBRES_INFORMATIONOUTLINE_24;
  end
  else
  if BeforeButtonID = IEViewSave_Button_ID then  // To Left of "Save" button  (after open)
  begin
    AddButton := True;

    BtnID      := MY_LOADRECENT_BUTTON_ID;
    BtnCaption := 'Open Last File';       // Not usually used
    BtnHint    := 'Open Last File';
    BtnImgID   := ITBRES_FOLDERIMAGE_24;
  end;
end;