⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fcustomizebuttons.pas

📁 siMail, siMail, siMail, siMail
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    finally
      Free;
    end;

    TBXUpdateToolbarDisplay(Toolbar, ButtonList, CaptionState, ImageListID);

    // todo: I don't know reason why VisibilityToggleItem's caption
    // doesn't show up on start-up if 'Caption on Left' mode is on.
    // Strangely enough it appears correctly if TBXUpdateToolbarDisplay(..)
    // called for a second time:
    TBXUpdateToolbarDisplay(Toolbar, ButtonList, CaptionState, ImageListID);

    If (ButtonList <> Nil) Then ButtonList.Free;
end;

procedure TfrmToolbarEdit.AddSeparatorImage;
var
  TempImage: TBitmap;
begin

  TempImage := TBitmap.Create;
  TempImage.Width := imgButtons.Width;
  TempImage.Height := imgButtons.Height;
  TempImage.Canvas.CopyMode := cmSrcCopy;

  TempImage.Canvas.Brush.Color := TempImage.TransparentColor;
  TempImage.Canvas.FillRect( Rect(0,0,TempImage.Width,TempImage.Height) );
  TempImage.Canvas.Brush.Color := clBlack;
  TempImage.Canvas.MoveTo(Trunc(TempImage.Width / 2), 2);
  TempImage.Canvas.LineTo(Trunc(TempImage.Width / 2), TempImage.Height - 2);

  // insert Separator Image at the beginning
  imgButtons.InsertMasked(0, TempImage, TempImage.TransparentColor);

  TempImage.Free;
end;

procedure TfrmToolbarEdit.SetAvailableList;
var
  i : integer;
  BtnItem : TListItem;
begin

  lstAvailable.Items.BeginUpdate;

  lstAvailable.Items.Clear;

  AddSeparatorImage;
  BtnItem := lstAvailable.Items.Add; // Start with Separator
  BtnItem.Caption := 'Separator';
  BtnItem.ImageIndex := 0;

  For I := 0 to tbxToolbar.Items.Count - 1 Do begin
    if (tbxToolbar.Items[I] is TTBXItem)
    or (tbxToolbar.Items[I] is TTBXSubmenuItem)
    or (tbxToolbar.Items[I] is TTBXVisibilityToggleItem) then
    begin
      // Add item to the Available list with its image from the imagelist.
      BtnItem := lstAvailable.Items.Add;
      BtnItem.Caption := tbxToolbar.Items[I].Caption;
      BtnItem.ImageIndex := tbxToolbar.Items[i].ImageIndex + 1; //all shifted by 1 due to separator
    end;
  end;

  lstAvailable.Items.EndUpdate;

end;

procedure TBXInitializeToolbar(Toolbar: TTBXToolbar; RegistryKey, IniFileName: String; HelpContextID: LongInt);
var
  CaptionState, ImageListID : Integer;

  procedure CheckToolbarButtonDefaultSettings;
  var i : Integer;
  begin
    Toolbar.Options := [tboImageAboveCaption];

    for i:=0 to Toolbar.Items.Count-1 do begin
      Toolbar.Items[i].DisplayMode:=nbdmDefault;
      // set tboImageAboveCaption:=False for each button
      Toolbar.Items[i].Options:=Toolbar.Items[i].Options - [tboImageAboveCaption];

      // and pleeease set Layout to tbxlAuto whenever possible...!!!
      // this mess arises because TBXVisibiliyToggleItem has no Layout property
      If (tbxToolbar.Items[I] is TTBXItem) then
        (tbxToolbar.Items[I] as TTBXItem).Layout := tbxlAuto
      else
      if (tbxToolbar.Items[I] is TTBXSubmenuItem) then begin
        (tbxToolbar.Items[I] as TTBXSubmenuItem).Layout := tbxlAuto;

        {todo: I have to set Layout it to tbxlGlyphTop because 'Views'
         arrow looks ugly in vertical dock. But this approach does not
         work if no text label present in Horiz Dock. You have to apply
         Layout to tbxlGlyphTop in Vertical dock and return back to tbxlAuto
         in Horiz Dock on the fly when Dock changed}
//        (tbxToolbar.Items[I] as TTBXSubmenuItem).Layout := tbxlGlyphTop;
      end;
    end;

    // set Stretched=True for all Toolbar Buttons
    // to display them equal width when in vertical TBXDock(s)
    for i:=0 to Toolbar.Items.Count-1 do
    if tbxToolbar.Items[I] is TTBXItem then
      TTBXItem(tbxToolbar.Items[I]).Stretch:=True
    else
    if tbxToolbar.Items[I] is TTBXSubmenuItem then
      TTBXSubmenuItem(tbxToolbar.Items[I]).Stretch:=True
    else
    if tbxToolbar.Items[I] is TTBXVisibilityToggleItem then
      TTBXVisibilityToggleItem(tbxToolbar.Items[I]).Stretch:=True;

  end;

begin

  //set global variables
  tbxToolbar := Toolbar;
  sRegistryKey := RegistryKey;
  sIniFileName := IniFileName;

  // I found that it is easy to mess with Toolbar button's options.
  // You may set button's options manually, but if you messed with
  // settings then here is a good place to restore them right.
  // Note - if you want Selective Caption on Right to be visible
  // then manually set Tag for the button to some value >0 (say, 1).
  // By default (no INI file) Toolbar Buttons will appear with
  // Captions below Images. See other options after the code end.

  CheckToolbarButtonDefaultSettings;

  // set some default values
  CaptionState:=0; // put Captions below Images
  ImageListID :=0; // use ImageListWin2k20bold (Win2k style, 20x20)
  TBXRestoreToolbarButtons(tbxToolbar, CaptionState, ImageListID);

  // set any other parameters of your application,
  // which might depend on CaptionState and ImageListID
  UpdateOtherApplicationSettings(CaptionState, ImageListID);

end;

procedure UpdateOtherApplicationSettings(CaptionState, ImageListID: integer);
begin
  // here is place to set any other parameters of your application,
  // which might depend on CaptionState and ImageListID

  //set Main menu and ListView popup menu images
  (*with Form1 do
  case ImageListID of
  0,1: begin
//         TBXToolbar1.Images   := ImageListWin2k16bold; //set Main menu images
//         TBXPopupMenu2.Images := ImageListWin2k16bold; //set ListView popup menu images
       end;
  2,3: begin
//         TBXToolbar1.Images   := TBImageListWinXP16; //set Main menu images
//         TBXPopupMenu2.Images := TBImageListWinXP16; //set ListView popup menu images
       end;
  end;

     Form1.Label1.Caption:='Text options: '+IntToStr(CaptionState);
     Form1.Label2.Caption:='Icon options: '+IntToStr(ImageListID);
*)
end;

procedure TfrmToolbarEdit.FormCreate(Sender: TObject);
begin
     HelpContext := lHelpContextID;

     SelectedCommands := TStringList.Create;
     SelectedCommands.Clear;

     // This is to backup start-up button options
     TBXGetDefaultToolbarButtons(tbxToolbar);
end;

procedure TfrmToolbarEdit.FormDestroy(Sender: TObject);
begin
//B.T.
     BakImageList.Free;
     if (BakCommands <> nil) then BakCommands.Free;
//     BakCommands := nil;
//B.T.
     If (SelectedCommands <> Nil) Then SelectedCommands.Free;
//     SelectedCommands := Nil;
end;

procedure TfrmToolbarEdit.FormActivate(Sender: TObject);
begin
     // set-up ComboBoxes
     ComboBox1.ItemIndex := BakCaptionState;
     ComboBox2.ItemIndex := BakImageListID;

     // fill imgButtons (TLimageList) used to draw Available/Selected items
     imgButtons.Assign(tbxToolbar.Images);

     SetAvailableList;
     SetSelectedList;

     // disable editor buttons
//     btnOK.Enabled:=False;
     btnRestore.Enabled := False;
     btnApply.Enabled := False;

     // to adjust column width to match the client area (no horis. scrollbar)
     lstAvailable.Update;
     lstSelected.Update;
     lstAvailable.Columns[0].Width:= lstAvailable.ClientWidth;
     lstSelected.Columns[0].Width := lstSelected.ClientWidth;

     if lstSelected.Items.Count > 0 then begin
       lstSelected.Items[0].Selected:=True;
       lstSelected.Items[0].Focused:=True;
       lstSelected.Items[0].MakeVisible(False); //bring ino view
     end;

     //select first item (separator)
     with lstAvailable do if Items.Count > 0 then ItemIndex := 0;
     lstAvailable.SetFocus;

     CheckButtonsState;

end;

procedure TfrmToolbarEdit.btnApplyClick(Sender: TObject);
var
  i : integer;
  CaptionState, ImageListID: integer;
begin
     SelectedCommands.Clear;
     for i := 0 to lstSelected.Items.Count - 1 do
       SelectedCommands.Add(lstSelected.Items[i].Caption);

     CaptionState := ComboBox1.ItemIndex;
     ImageListID  := ComboBox2.ItemIndex;

     //refresh icons on Toolbar
     TBXUpdateToolbarDisplay(tbxToolbar, SelectedCommands, CaptionState, ImageListID);

     CheckButtonsState;
end;

procedure TfrmToolbarEdit.ComboBox1Change(Sender: TObject);
begin
//     btnOK.Enabled:=True;
     btnRestore.Enabled:=True;
     btnApply.Enabled:=True;
end;

procedure TfrmToolbarEdit.ComboBox2Change(Sender: TObject);
begin
//     btnOK.Enabled:=True;
     btnRestore.Enabled:=True;
     btnApply.Enabled:=True;

     // update Available & Selected icons
     UpdateAvailableList;
end;

procedure TfrmToolbarEdit.UpdateAvailableList;//todo: Change procedure name
begin
     lstAvailable.Items.BeginUpdate;
     lstSelected.Items.BeginUpdate;

     // 1. correct Index[0] top adjustment bug when changing IconsSize
     if lstSelected.Items.Count > 0 then
       lstSelected.Items[0].MakeVisible(False); //scroll to top

     // Image Count must be the same for all ImageLists!
     (*case ComboBox2.ItemIndex of
     0: imgButtons.Assign(Form1.ImageList1);
     1: imgButtons.Assign(Form1.ImageList2);
     2: imgButtons.Assign(Form1.ImageList3);
     3: imgButtons.Assign(Form1.ImageList4);
     else
     end;*)

     AddSeparatorImage;

     // then update Selected list icons
     lstSelected.SmallImages:=imgButtons;

     // 2. correct Index[0] top adjustment bug when changing IconsSize
     if lstSelected.Selected <> nil then
       lstSelected.Selected.MakeVisible(False); //bring ino view

     lstSelected.Items.EndUpdate;
     lstAvailable.Items.EndUpdate;

     // to adjust column width to match the clien area (no horis. scrollbar)
     lstAvailable.Columns[0].Width:= lstAvailable.ClientWidth;
     lstSelected.Columns[0].Width := lstSelected.ClientWidth;
end;

procedure TfrmToolbarEdit.CheckButtonsState;
begin
     // enable Insert/Remove buttons if Selection is visible
     btnInsert.Enabled := lstAvailable.Focused and (lstAvailable.SelCount > 0);
     btnRemove.Enabled := lstSelected.Focused  and (lstSelected.SelCount >0);
end;

procedure TfrmToolbarEdit.lstSelectedEnter(Sender: TObject);
begin
     CheckButtonsState;
end;

procedure TfrmToolbarEdit.lstSelectedExit(Sender: TObject);
begin
     CheckButtonsState;
end;

procedure TfrmToolbarEdit.lstSelectedChange(Sender: TObject;
  Item: TListItem; Change: TItemChange);
begin
     CheckButtonsState;
end;

end.

{  //Captions below icon
  Toolbar.Options:=[tboImageAboveCaption]
  Toolbar.Items[i].Options:=[];
  Toolbar.Items[i].DisplayMode:=nbdmDefault;

  //Caption on the right
  Toolbar.Options:=[]
  Toolbar.Items[i].Options:=[];
  Toolbar.Items[i].DisplayMode:=nbdmImageAndText;

  //No Captions
  Toolbar.Options:=[]
  Toolbar.Items[i].Options:=[];
  Toolbar.Items[i].DisplayMode:=nbdmDefault;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -