ImageEn, unit iesettings

TIEGlobalSettings.OnToolbarButtonUpdate

TIEGlobalSettings.OnToolbarButtonUpdate


Declaration

property OnToolbarButtonUpdate: TIEActionEvent;


Description

Occurs when the state of the button action is updated (i.e. needs to be set visible or enabled) for in-built toolbars and popup menus. The default behaviour can be overriden by setting Handled to true.
It also handles the state for custom buttons and popup menu items.

Parameter Description
Sender The action or control being updated. See details below
ButtonImageID The ID of the affected control
Handled When False the default state behaviour occurs. Set to true to apply your own state setting code

The Sender type will be one of the following:
- TToolButton for custom buttons
- TMenuItem for custom popup menu items
- TComboBox showing a shape (IELayerShapeBox_Button_ID)
- TPaintBox for colors, fonts, sizes, etc (IELayerFontColorSelect_Button_ID, IELayerFontBox_Button_ID, IELayerFillBox_Button_ID, IELayerBorderSizeBox_Button_ID, IELayerBorderColorBox_Button_ID, IEViewToolBrushSizeBox_Button_ID, IEViewToolColor_Button_ID, IEViewZoomBox_Button_ID, IERichEditFontColor_Button_ID, IERichEditFontBox_Button_ID)
- TAction from the ImageEn Actions Classes (all other types)

Notes:
- This method is called frequently, so avoid slow code
- Ensure you reset this event before destroying your form, e.g. IEGlobalSettings().OnAddToolbarButtonUpdate := nil;


Example

IEGlobalSettings().OnToolbarButtonExecute   := Form1CustomButtonExecute;
IEGlobalSettings().OnToolbarButtonUpdate    := Form1CustomButtonUpdate;
IEGlobalSettings().OnAddCustomToolbarButton := Form1AddCustomToolbarButton;

// 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.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.Form1CustomButtonUpdate(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.Form1AddCustomToolbarButton(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;


See Also

- OnToolbarButtonExecute
- OnActionUpdate